]> git.pld-linux.org Git - packages/kernel.git/blob - kernel-vserver-2.3.patch
- vserver patch updated to patch-3.9.4-vs2.3.6.2.diff
[packages/kernel.git] / kernel-vserver-2.3.patch
1 diff -NurpP --minimal linux-3.9.4/Documentation/vserver/debug.txt linux-3.9.4-vs2.3.6.2/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.2/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.2/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.2/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.2/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.2/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.2/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.2/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.2/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.2/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.2/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.2/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.2/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.2/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.2/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.2/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.2/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.2/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.2/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.2/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.2/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.2/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.2/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.2/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.2/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.2/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.2/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.2/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.2/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.2/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.2/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.2/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.2/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.2/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.2/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.2/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.2/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.2/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.2/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.2/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.2/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.2/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.2/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.2/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.2/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.2/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.2/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.2/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.2/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.2/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.2/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.2/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.2/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.2/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.2/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.2/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.2/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.2/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.2/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.2/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.2/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.2/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.2/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.2/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.2/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.2/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.2/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.2/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.2/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.2/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.2/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.2/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.2/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.2/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.2/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.2/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.2/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.2/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.2/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.2/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.2/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.2/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.2/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.2/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.2/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.2/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.2/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.2/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.2/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.2/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.2/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.2/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.2/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.2/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.2/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.2/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.2/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.2/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.2/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.2/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.2/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.2/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.2/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.2/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.2/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.2/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.2/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.2/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.2/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.2/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.2/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.2/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.2/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.2/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.2/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.2/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.2/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.2/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.2/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.2/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.2/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.2/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.2/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.2/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.2/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.2/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.2/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.2/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.2/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.2/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.2/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.2/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.2/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.2/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.2/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.2/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.2/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.2/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.2/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.2/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.2/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.2/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.2/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.2/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.2/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.2/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.2/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.2/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.2/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.2/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.2/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.2/fs/ext2/ialloc.c      2013-06-01 09:31:28.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,8 @@ got:
2315                 inode->i_mode = mode;
2316                 inode->i_uid = current_fsuid();
2317                 inode->i_gid = dir->i_gid;
2318 +               inode->i_tag = make_ktag(&init_user_ns,
2319 +                       dx_current_fstag(sb));
2320         } else
2321                 inode_init_owner(inode, dir, mode);
2322  
2323 diff -NurpP --minimal linux-3.9.4/fs/ext2/inode.c linux-3.9.4-vs2.3.6.2/fs/ext2/inode.c
2324 --- linux-3.9.4/fs/ext2/inode.c 2013-05-31 13:45:23.000000000 +0000
2325 +++ linux-3.9.4-vs2.3.6.2/fs/ext2/inode.c       2013-05-31 14:47:11.000000000 +0000
2326 @@ -31,6 +31,7 @@
2327  #include <linux/mpage.h>
2328  #include <linux/fiemap.h>
2329  #include <linux/namei.h>
2330 +#include <linux/vs_tag.h>
2331  #include "ext2.h"
2332  #include "acl.h"
2333  #include "xip.h"
2334 @@ -1179,7 +1180,7 @@ static void ext2_truncate_blocks(struct
2335                 return;
2336         if (ext2_inode_is_fast_symlink(inode))
2337                 return;
2338 -       if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
2339 +       if (IS_APPEND(inode) || IS_IXORUNLINK(inode))
2340                 return;
2341         __ext2_truncate_blocks(inode, offset);
2342  }
2343 @@ -1270,36 +1271,61 @@ void ext2_set_inode_flags(struct inode *
2344  {
2345         unsigned int flags = EXT2_I(inode)->i_flags;
2346  
2347 -       inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
2348 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
2349 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
2350 +
2351 +
2352 +       if (flags & EXT2_IMMUTABLE_FL)
2353 +               inode->i_flags |= S_IMMUTABLE;
2354 +       if (flags & EXT2_IXUNLINK_FL)
2355 +               inode->i_flags |= S_IXUNLINK;
2356 +
2357         if (flags & EXT2_SYNC_FL)
2358                 inode->i_flags |= S_SYNC;
2359         if (flags & EXT2_APPEND_FL)
2360                 inode->i_flags |= S_APPEND;
2361 -       if (flags & EXT2_IMMUTABLE_FL)
2362 -               inode->i_flags |= S_IMMUTABLE;
2363         if (flags & EXT2_NOATIME_FL)
2364                 inode->i_flags |= S_NOATIME;
2365         if (flags & EXT2_DIRSYNC_FL)
2366                 inode->i_flags |= S_DIRSYNC;
2367 +
2368 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
2369 +
2370 +       if (flags & EXT2_BARRIER_FL)
2371 +               inode->i_vflags |= V_BARRIER;
2372 +       if (flags & EXT2_COW_FL)
2373 +               inode->i_vflags |= V_COW;
2374  }
2375  
2376  /* Propagate flags from i_flags to EXT2_I(inode)->i_flags */
2377  void ext2_get_inode_flags(struct ext2_inode_info *ei)
2378  {
2379         unsigned int flags = ei->vfs_inode.i_flags;
2380 +       unsigned int vflags = ei->vfs_inode.i_vflags;
2381 +
2382 +       ei->i_flags &= ~(EXT2_SYNC_FL | EXT2_APPEND_FL |
2383 +                       EXT2_IMMUTABLE_FL | EXT2_IXUNLINK_FL |
2384 +                       EXT2_NOATIME_FL | EXT2_DIRSYNC_FL |
2385 +                       EXT2_BARRIER_FL | EXT2_COW_FL);
2386 +
2387 +       if (flags & S_IMMUTABLE)
2388 +               ei->i_flags |= EXT2_IMMUTABLE_FL;
2389 +       if (flags & S_IXUNLINK)
2390 +               ei->i_flags |= EXT2_IXUNLINK_FL;
2391  
2392 -       ei->i_flags &= ~(EXT2_SYNC_FL|EXT2_APPEND_FL|
2393 -                       EXT2_IMMUTABLE_FL|EXT2_NOATIME_FL|EXT2_DIRSYNC_FL);
2394         if (flags & S_SYNC)
2395                 ei->i_flags |= EXT2_SYNC_FL;
2396         if (flags & S_APPEND)
2397                 ei->i_flags |= EXT2_APPEND_FL;
2398 -       if (flags & S_IMMUTABLE)
2399 -               ei->i_flags |= EXT2_IMMUTABLE_FL;
2400         if (flags & S_NOATIME)
2401                 ei->i_flags |= EXT2_NOATIME_FL;
2402         if (flags & S_DIRSYNC)
2403                 ei->i_flags |= EXT2_DIRSYNC_FL;
2404 +
2405 +       if (vflags & V_BARRIER)
2406 +               ei->i_flags |= EXT2_BARRIER_FL;
2407 +       if (vflags & V_COW)
2408 +               ei->i_flags |= EXT2_COW_FL;
2409  }
2410  
2411  struct inode *ext2_iget (struct super_block *sb, unsigned long ino)
2412 @@ -1335,8 +1361,10 @@ struct inode *ext2_iget (struct super_bl
2413                 i_uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
2414                 i_gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
2415         }
2416 -       i_uid_write(inode, i_uid);
2417 -       i_gid_write(inode, i_gid);
2418 +       i_uid_write(inode, INOTAG_UID(DX_TAG(inode), i_uid, i_gid));
2419 +       i_gid_write(inode, INOTAG_GID(DX_TAG(inode), i_uid, i_gid));
2420 +       i_tag_write(inode, INOTAG_TAG(DX_TAG(inode), i_uid, i_gid,
2421 +               le16_to_cpu(raw_inode->i_raw_tag)));
2422         set_nlink(inode, le16_to_cpu(raw_inode->i_links_count));
2423         inode->i_size = le32_to_cpu(raw_inode->i_size);
2424         inode->i_atime.tv_sec = (signed)le32_to_cpu(raw_inode->i_atime);
2425 @@ -1434,8 +1462,10 @@ static int __ext2_write_inode(struct ino
2426         struct ext2_inode_info *ei = EXT2_I(inode);
2427         struct super_block *sb = inode->i_sb;
2428         ino_t ino = inode->i_ino;
2429 -       uid_t uid = i_uid_read(inode);
2430 -       gid_t gid = i_gid_read(inode);
2431 +       uid_t uid = TAGINO_UID(DX_TAG(inode),
2432 +               i_uid_read(inode), i_tag_read(inode));
2433 +       gid_t gid = TAGINO_GID(DX_TAG(inode),
2434 +               i_gid_read(inode), i_tag_read(inode));
2435         struct buffer_head * bh;
2436         struct ext2_inode * raw_inode = ext2_get_inode(sb, ino, &bh);
2437         int n;
2438 @@ -1471,6 +1501,9 @@ static int __ext2_write_inode(struct ino
2439                 raw_inode->i_uid_high = 0;
2440                 raw_inode->i_gid_high = 0;
2441         }
2442 +#ifdef CONFIG_TAGGING_INTERN
2443 +       raw_inode->i_raw_tag = cpu_to_le16(i_tag_read(inode));
2444 +#endif
2445         raw_inode->i_links_count = cpu_to_le16(inode->i_nlink);
2446         raw_inode->i_size = cpu_to_le32(inode->i_size);
2447         raw_inode->i_atime = cpu_to_le32(inode->i_atime.tv_sec);
2448 @@ -1551,7 +1584,8 @@ int ext2_setattr(struct dentry *dentry,
2449         if (is_quota_modification(inode, iattr))
2450                 dquot_initialize(inode);
2451         if ((iattr->ia_valid & ATTR_UID && !uid_eq(iattr->ia_uid, inode->i_uid)) ||
2452 -           (iattr->ia_valid & ATTR_GID && !gid_eq(iattr->ia_gid, inode->i_gid))) {
2453 +           (iattr->ia_valid & ATTR_GID && !gid_eq(iattr->ia_gid, inode->i_gid)) ||
2454 +           (iattr->ia_valid & ATTR_TAG && !tag_eq(iattr->ia_tag, inode->i_tag))) {
2455                 error = dquot_transfer(inode, iattr);
2456                 if (error)
2457                         return error;
2458 diff -NurpP --minimal linux-3.9.4/fs/ext2/ioctl.c linux-3.9.4-vs2.3.6.2/fs/ext2/ioctl.c
2459 --- linux-3.9.4/fs/ext2/ioctl.c 2013-05-31 13:45:23.000000000 +0000
2460 +++ linux-3.9.4-vs2.3.6.2/fs/ext2/ioctl.c       2013-05-31 14:47:11.000000000 +0000
2461 @@ -17,6 +17,16 @@
2462  #include <asm/uaccess.h>
2463  
2464  
2465 +int ext2_sync_flags(struct inode *inode, int flags, int vflags)
2466 +{
2467 +       inode->i_flags = flags;
2468 +       inode->i_vflags = vflags;
2469 +       ext2_get_inode_flags(EXT2_I(inode));
2470 +       inode->i_ctime = CURRENT_TIME_SEC;
2471 +       mark_inode_dirty(inode);
2472 +       return 0;
2473 +}
2474 +
2475  long ext2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
2476  {
2477         struct inode *inode = file_inode(filp);
2478 @@ -51,6 +61,11 @@ long ext2_ioctl(struct file *filp, unsig
2479  
2480                 flags = ext2_mask_flags(inode->i_mode, flags);
2481  
2482 +               if (IS_BARRIER(inode)) {
2483 +                       vxwprintk_task(1, "messing with the barrier.");
2484 +                       return -EACCES;
2485 +               }
2486 +
2487                 mutex_lock(&inode->i_mutex);
2488                 /* Is it quota file? Do not allow user to mess with it */
2489                 if (IS_NOQUOTA(inode)) {
2490 @@ -66,7 +81,9 @@ long ext2_ioctl(struct file *filp, unsig
2491                  *
2492                  * This test looks nicer. Thanks to Pauline Middelink
2493                  */
2494 -               if ((flags ^ oldflags) & (EXT2_APPEND_FL | EXT2_IMMUTABLE_FL)) {
2495 +               if ((oldflags & EXT2_IMMUTABLE_FL) ||
2496 +                       ((flags ^ oldflags) & (EXT2_APPEND_FL |
2497 +                       EXT2_IMMUTABLE_FL | EXT2_IXUNLINK_FL))) {
2498                         if (!capable(CAP_LINUX_IMMUTABLE)) {
2499                                 mutex_unlock(&inode->i_mutex);
2500                                 ret = -EPERM;
2501 @@ -74,7 +91,7 @@ long ext2_ioctl(struct file *filp, unsig
2502                         }
2503                 }
2504  
2505 -               flags = flags & EXT2_FL_USER_MODIFIABLE;
2506 +               flags &= EXT2_FL_USER_MODIFIABLE;
2507                 flags |= oldflags & ~EXT2_FL_USER_MODIFIABLE;
2508                 ei->i_flags = flags;
2509  
2510 diff -NurpP --minimal linux-3.9.4/fs/ext2/namei.c linux-3.9.4-vs2.3.6.2/fs/ext2/namei.c
2511 --- linux-3.9.4/fs/ext2/namei.c 2012-12-11 03:30:57.000000000 +0000
2512 +++ linux-3.9.4-vs2.3.6.2/fs/ext2/namei.c       2013-05-31 14:47:11.000000000 +0000
2513 @@ -32,6 +32,7 @@
2514  
2515  #include <linux/pagemap.h>
2516  #include <linux/quotaops.h>
2517 +#include <linux/vs_tag.h>
2518  #include "ext2.h"
2519  #include "xattr.h"
2520  #include "acl.h"
2521 @@ -73,6 +74,7 @@ static struct dentry *ext2_lookup(struct
2522                                         (unsigned long) ino);
2523                         return ERR_PTR(-EIO);
2524                 }
2525 +               dx_propagate_tag(nd, inode);
2526         }
2527         return d_splice_alias(inode, dentry);
2528  }
2529 @@ -397,6 +399,7 @@ const struct inode_operations ext2_dir_i
2530         .removexattr    = generic_removexattr,
2531  #endif
2532         .setattr        = ext2_setattr,
2533 +       .sync_flags     = ext2_sync_flags,
2534         .get_acl        = ext2_get_acl,
2535  };
2536  
2537 diff -NurpP --minimal linux-3.9.4/fs/ext2/super.c linux-3.9.4-vs2.3.6.2/fs/ext2/super.c
2538 --- linux-3.9.4/fs/ext2/super.c 2013-05-31 13:45:23.000000000 +0000
2539 +++ linux-3.9.4-vs2.3.6.2/fs/ext2/super.c       2013-05-31 14:47:11.000000000 +0000
2540 @@ -395,7 +395,8 @@ enum {
2541         Opt_err_ro, Opt_nouid32, Opt_nocheck, Opt_debug,
2542         Opt_oldalloc, Opt_orlov, Opt_nobh, Opt_user_xattr, Opt_nouser_xattr,
2543         Opt_acl, Opt_noacl, Opt_xip, Opt_ignore, Opt_err, Opt_quota,
2544 -       Opt_usrquota, Opt_grpquota, Opt_reservation, Opt_noreservation
2545 +       Opt_usrquota, Opt_grpquota, Opt_reservation, Opt_noreservation,
2546 +       Opt_tag, Opt_notag, Opt_tagid
2547  };
2548  
2549  static const match_table_t tokens = {
2550 @@ -423,6 +424,9 @@ static const match_table_t tokens = {
2551         {Opt_acl, "acl"},
2552         {Opt_noacl, "noacl"},
2553         {Opt_xip, "xip"},
2554 +       {Opt_tag, "tag"},
2555 +       {Opt_notag, "notag"},
2556 +       {Opt_tagid, "tagid=%u"},
2557         {Opt_grpquota, "grpquota"},
2558         {Opt_ignore, "noquota"},
2559         {Opt_quota, "quota"},
2560 @@ -506,6 +510,20 @@ static int parse_options(char *options,
2561                 case Opt_nouid32:
2562                         set_opt (sbi->s_mount_opt, NO_UID32);
2563                         break;
2564 +#ifndef CONFIG_TAGGING_NONE
2565 +               case Opt_tag:
2566 +                       set_opt (sbi->s_mount_opt, TAGGED);
2567 +                       break;
2568 +               case Opt_notag:
2569 +                       clear_opt (sbi->s_mount_opt, TAGGED);
2570 +                       break;
2571 +#endif
2572 +#ifdef CONFIG_PROPAGATE
2573 +               case Opt_tagid:
2574 +                       /* use args[0] */
2575 +                       set_opt (sbi->s_mount_opt, TAGGED);
2576 +                       break;
2577 +#endif
2578                 case Opt_nocheck:
2579                         clear_opt (sbi->s_mount_opt, CHECK);
2580                         break;
2581 @@ -864,6 +882,8 @@ static int ext2_fill_super(struct super_
2582         if (!parse_options((char *) data, sb))
2583                 goto failed_mount;
2584  
2585 +       if (EXT2_SB(sb)->s_mount_opt & EXT2_MOUNT_TAGGED)
2586 +               sb->s_flags |= MS_TAGGED;
2587         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
2588                 ((EXT2_SB(sb)->s_mount_opt & EXT2_MOUNT_POSIX_ACL) ?
2589                  MS_POSIXACL : 0);
2590 @@ -1269,6 +1289,14 @@ static int ext2_remount (struct super_bl
2591                 err = -EINVAL;
2592                 goto restore_opts;
2593         }
2594 +
2595 +       if ((sbi->s_mount_opt & EXT2_MOUNT_TAGGED) &&
2596 +               !(sb->s_flags & MS_TAGGED)) {
2597 +               printk("EXT2-fs: %s: tagging not permitted on remount.\n",
2598 +                      sb->s_id);
2599 +               err = -EINVAL;
2600 +               goto restore_opts;
2601 +       }
2602  
2603         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
2604                 ((sbi->s_mount_opt & EXT2_MOUNT_POSIX_ACL) ? MS_POSIXACL : 0);
2605 diff -NurpP --minimal linux-3.9.4/fs/ext3/ext3.h linux-3.9.4-vs2.3.6.2/fs/ext3/ext3.h
2606 --- linux-3.9.4/fs/ext3/ext3.h  2012-12-11 03:30:57.000000000 +0000
2607 +++ linux-3.9.4-vs2.3.6.2/fs/ext3/ext3.h        2013-05-31 14:47:11.000000000 +0000
2608 @@ -151,10 +151,14 @@ struct ext3_group_desc
2609  #define EXT3_NOTAIL_FL                 0x00008000 /* file tail should not be merged */
2610  #define EXT3_DIRSYNC_FL                        0x00010000 /* dirsync behaviour (directories only) */
2611  #define EXT3_TOPDIR_FL                 0x00020000 /* Top of directory hierarchies*/
2612 +#define EXT3_IXUNLINK_FL               0x08000000 /* Immutable invert on unlink */
2613  #define EXT3_RESERVED_FL               0x80000000 /* reserved for ext3 lib */
2614  
2615 -#define EXT3_FL_USER_VISIBLE           0x0003DFFF /* User visible flags */
2616 -#define EXT3_FL_USER_MODIFIABLE                0x000380FF /* User modifiable flags */
2617 +#define EXT3_BARRIER_FL                        0x04000000 /* Barrier for chroot() */
2618 +#define EXT3_COW_FL                    0x20000000 /* Copy on Write marker */
2619 +
2620 +#define EXT3_FL_USER_VISIBLE           0x0103DFFF /* User visible flags */
2621 +#define EXT3_FL_USER_MODIFIABLE                0x010380FF /* User modifiable flags */
2622  
2623  /* Flags that should be inherited by new inodes from their parent. */
2624  #define EXT3_FL_INHERITED (EXT3_SECRM_FL | EXT3_UNRM_FL | EXT3_COMPR_FL |\
2625 @@ -290,7 +294,8 @@ struct ext3_inode {
2626                         __u16   i_pad1;
2627                         __le16  l_i_uid_high;   /* these 2 fields    */
2628                         __le16  l_i_gid_high;   /* were reserved2[0] */
2629 -                       __u32   l_i_reserved2;
2630 +                       __le16  l_i_tag;        /* Context Tag */
2631 +                       __u16   l_i_reserved2;
2632                 } linux2;
2633                 struct {
2634                         __u8    h_i_frag;       /* Fragment number */
2635 @@ -320,6 +325,7 @@ struct ext3_inode {
2636  #define i_gid_low      i_gid
2637  #define i_uid_high     osd2.linux2.l_i_uid_high
2638  #define i_gid_high     osd2.linux2.l_i_gid_high
2639 +#define i_raw_tag      osd2.linux2.l_i_tag
2640  #define i_reserved2    osd2.linux2.l_i_reserved2
2641  
2642  /*
2643 @@ -364,6 +370,7 @@ struct ext3_inode {
2644  #define EXT3_MOUNT_GRPQUOTA            0x200000 /* "old" group quota */
2645  #define EXT3_MOUNT_DATA_ERR_ABORT      0x400000 /* Abort on file data write
2646                                                   * error in ordered mode */
2647 +#define EXT3_MOUNT_TAGGED              (1<<24) /* Enable Context Tags */
2648  
2649  /* Compatibility, for having both ext2_fs.h and ext3_fs.h included at once */
2650  #ifndef _LINUX_EXT2_FS_H
2651 @@ -1061,6 +1068,7 @@ extern void ext3_get_inode_flags(struct
2652  extern void ext3_set_aops(struct inode *inode);
2653  extern int ext3_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
2654                        u64 start, u64 len);
2655 +extern int ext3_sync_flags(struct inode *, int, int);
2656  
2657  /* ioctl.c */
2658  extern long ext3_ioctl(struct file *, unsigned int, unsigned long);
2659 diff -NurpP --minimal linux-3.9.4/fs/ext3/file.c linux-3.9.4-vs2.3.6.2/fs/ext3/file.c
2660 --- linux-3.9.4/fs/ext3/file.c  2012-12-11 03:30:57.000000000 +0000
2661 +++ linux-3.9.4-vs2.3.6.2/fs/ext3/file.c        2013-05-31 14:47:11.000000000 +0000
2662 @@ -76,5 +76,6 @@ const struct inode_operations ext3_file_
2663  #endif
2664         .get_acl        = ext3_get_acl,
2665         .fiemap         = ext3_fiemap,
2666 +       .sync_flags     = ext3_sync_flags,
2667  };
2668  
2669 diff -NurpP --minimal linux-3.9.4/fs/ext3/ialloc.c linux-3.9.4-vs2.3.6.2/fs/ext3/ialloc.c
2670 --- linux-3.9.4/fs/ext3/ialloc.c        2012-12-11 03:30:57.000000000 +0000
2671 +++ linux-3.9.4-vs2.3.6.2/fs/ext3/ialloc.c      2013-06-01 09:40:15.000000000 +0000
2672 @@ -14,6 +14,7 @@
2673  
2674  #include <linux/quotaops.h>
2675  #include <linux/random.h>
2676 +#include <linux/vs_tag.h>
2677  
2678  #include "ext3.h"
2679  #include "xattr.h"
2680 @@ -469,6 +470,8 @@ got:
2681                 inode->i_mode = mode;
2682                 inode->i_uid = current_fsuid();
2683                 inode->i_gid = dir->i_gid;
2684 +               inode->i_tag = make_ktag(&init_user_ns,
2685 +                       dx_current_fstag(sb));
2686         } else
2687                 inode_init_owner(inode, dir, mode);
2688  
2689 diff -NurpP --minimal linux-3.9.4/fs/ext3/inode.c linux-3.9.4-vs2.3.6.2/fs/ext3/inode.c
2690 --- linux-3.9.4/fs/ext3/inode.c 2013-05-31 13:45:23.000000000 +0000
2691 +++ linux-3.9.4-vs2.3.6.2/fs/ext3/inode.c       2013-05-31 14:47:11.000000000 +0000
2692 @@ -27,6 +27,8 @@
2693  #include <linux/writeback.h>
2694  #include <linux/mpage.h>
2695  #include <linux/namei.h>
2696 +#include <linux/vs_tag.h>
2697 +
2698  #include "ext3.h"
2699  #include "xattr.h"
2700  #include "acl.h"
2701 @@ -2851,36 +2853,60 @@ void ext3_set_inode_flags(struct inode *
2702  {
2703         unsigned int flags = EXT3_I(inode)->i_flags;
2704  
2705 -       inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
2706 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
2707 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
2708 +
2709 +       if (flags & EXT3_IMMUTABLE_FL)
2710 +               inode->i_flags |= S_IMMUTABLE;
2711 +       if (flags & EXT3_IXUNLINK_FL)
2712 +               inode->i_flags |= S_IXUNLINK;
2713 +
2714         if (flags & EXT3_SYNC_FL)
2715                 inode->i_flags |= S_SYNC;
2716         if (flags & EXT3_APPEND_FL)
2717                 inode->i_flags |= S_APPEND;
2718 -       if (flags & EXT3_IMMUTABLE_FL)
2719 -               inode->i_flags |= S_IMMUTABLE;
2720         if (flags & EXT3_NOATIME_FL)
2721                 inode->i_flags |= S_NOATIME;
2722         if (flags & EXT3_DIRSYNC_FL)
2723                 inode->i_flags |= S_DIRSYNC;
2724 +
2725 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
2726 +
2727 +       if (flags & EXT3_BARRIER_FL)
2728 +               inode->i_vflags |= V_BARRIER;
2729 +       if (flags & EXT3_COW_FL)
2730 +               inode->i_vflags |= V_COW;
2731  }
2732  
2733  /* Propagate flags from i_flags to EXT3_I(inode)->i_flags */
2734  void ext3_get_inode_flags(struct ext3_inode_info *ei)
2735  {
2736         unsigned int flags = ei->vfs_inode.i_flags;
2737 +       unsigned int vflags = ei->vfs_inode.i_vflags;
2738 +
2739 +       ei->i_flags &= ~(EXT3_SYNC_FL | EXT3_APPEND_FL |
2740 +                       EXT3_IMMUTABLE_FL | EXT3_IXUNLINK_FL |
2741 +                       EXT3_NOATIME_FL | EXT3_DIRSYNC_FL |
2742 +                       EXT3_BARRIER_FL | EXT3_COW_FL);
2743 +
2744 +       if (flags & S_IMMUTABLE)
2745 +               ei->i_flags |= EXT3_IMMUTABLE_FL;
2746 +       if (flags & S_IXUNLINK)
2747 +               ei->i_flags |= EXT3_IXUNLINK_FL;
2748  
2749 -       ei->i_flags &= ~(EXT3_SYNC_FL|EXT3_APPEND_FL|
2750 -                       EXT3_IMMUTABLE_FL|EXT3_NOATIME_FL|EXT3_DIRSYNC_FL);
2751         if (flags & S_SYNC)
2752                 ei->i_flags |= EXT3_SYNC_FL;
2753         if (flags & S_APPEND)
2754                 ei->i_flags |= EXT3_APPEND_FL;
2755 -       if (flags & S_IMMUTABLE)
2756 -               ei->i_flags |= EXT3_IMMUTABLE_FL;
2757         if (flags & S_NOATIME)
2758                 ei->i_flags |= EXT3_NOATIME_FL;
2759         if (flags & S_DIRSYNC)
2760                 ei->i_flags |= EXT3_DIRSYNC_FL;
2761 +
2762 +       if (vflags & V_BARRIER)
2763 +               ei->i_flags |= EXT3_BARRIER_FL;
2764 +       if (vflags & V_COW)
2765 +               ei->i_flags |= EXT3_COW_FL;
2766  }
2767  
2768  struct inode *ext3_iget(struct super_block *sb, unsigned long ino)
2769 @@ -2918,8 +2944,10 @@ struct inode *ext3_iget(struct super_blo
2770                 i_uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
2771                 i_gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
2772         }
2773 -       i_uid_write(inode, i_uid);
2774 -       i_gid_write(inode, i_gid);
2775 +       i_uid_write(inode, INOTAG_UID(DX_TAG(inode), i_uid, i_gid));
2776 +       i_gid_write(inode, INOTAG_GID(DX_TAG(inode), i_uid, i_gid));
2777 +       i_tag_write(inode, INOTAG_TAG(DX_TAG(inode), i_uid, i_gid,
2778 +               le16_to_cpu(raw_inode->i_raw_tag)));
2779         set_nlink(inode, le16_to_cpu(raw_inode->i_links_count));
2780         inode->i_size = le32_to_cpu(raw_inode->i_size);
2781         inode->i_atime.tv_sec = (signed)le32_to_cpu(raw_inode->i_atime);
2782 @@ -3091,8 +3119,10 @@ again:
2783  
2784         ext3_get_inode_flags(ei);
2785         raw_inode->i_mode = cpu_to_le16(inode->i_mode);
2786 -       i_uid = i_uid_read(inode);
2787 -       i_gid = i_gid_read(inode);
2788 +       i_uid = TAGINO_UID(DX_TAG(inode),
2789 +               i_uid_read(inode), i_tag_read(inode));
2790 +       i_gid = TAGINO_GID(DX_TAG(inode),
2791 +               i_gid_read(inode), i_tag_read(inode));
2792         if(!(test_opt(inode->i_sb, NO_UID32))) {
2793                 raw_inode->i_uid_low = cpu_to_le16(low_16_bits(i_uid));
2794                 raw_inode->i_gid_low = cpu_to_le16(low_16_bits(i_gid));
2795 @@ -3117,6 +3147,9 @@ again:
2796                 raw_inode->i_uid_high = 0;
2797                 raw_inode->i_gid_high = 0;
2798         }
2799 +#ifdef CONFIG_TAGGING_INTERN
2800 +       raw_inode->i_raw_tag = cpu_to_le16(i_tag_read(inode));
2801 +#endif
2802         raw_inode->i_links_count = cpu_to_le16(inode->i_nlink);
2803         disksize = cpu_to_le32(ei->i_disksize);
2804         if (disksize != raw_inode->i_size) {
2805 @@ -3285,7 +3318,8 @@ int ext3_setattr(struct dentry *dentry,
2806         if (is_quota_modification(inode, attr))
2807                 dquot_initialize(inode);
2808         if ((ia_valid & ATTR_UID && !uid_eq(attr->ia_uid, inode->i_uid)) ||
2809 -           (ia_valid & ATTR_GID && !gid_eq(attr->ia_gid, inode->i_gid))) {
2810 +           (ia_valid & ATTR_GID && !gid_eq(attr->ia_gid, inode->i_gid)) ||
2811 +           (ia_valid & ATTR_TAG && !tag_eq(attr->ia_tag, inode->i_tag))) {
2812                 handle_t *handle;
2813  
2814                 /* (user+group)*(old+new) structure, inode write (sb,
2815 @@ -3307,6 +3341,8 @@ int ext3_setattr(struct dentry *dentry,
2816                         inode->i_uid = attr->ia_uid;
2817                 if (attr->ia_valid & ATTR_GID)
2818                         inode->i_gid = attr->ia_gid;
2819 +               if ((attr->ia_valid & ATTR_TAG) && IS_TAGGED(inode))
2820 +                       inode->i_tag = attr->ia_tag;
2821                 error = ext3_mark_inode_dirty(handle, inode);
2822                 ext3_journal_stop(handle);
2823         }
2824 diff -NurpP --minimal linux-3.9.4/fs/ext3/ioctl.c linux-3.9.4-vs2.3.6.2/fs/ext3/ioctl.c
2825 --- linux-3.9.4/fs/ext3/ioctl.c 2013-05-31 13:45:23.000000000 +0000
2826 +++ linux-3.9.4-vs2.3.6.2/fs/ext3/ioctl.c       2013-05-31 14:47:11.000000000 +0000
2827 @@ -12,6 +12,34 @@
2828  #include <asm/uaccess.h>
2829  #include "ext3.h"
2830  
2831 +
2832 +int ext3_sync_flags(struct inode *inode, int flags, int vflags)
2833 +{
2834 +       handle_t *handle = NULL;
2835 +       struct ext3_iloc iloc;
2836 +       int err;
2837 +
2838 +       handle = ext3_journal_start(inode, 1);
2839 +       if (IS_ERR(handle))
2840 +               return PTR_ERR(handle);
2841 +
2842 +       if (IS_SYNC(inode))
2843 +               handle->h_sync = 1;
2844 +       err = ext3_reserve_inode_write(handle, inode, &iloc);
2845 +       if (err)
2846 +               goto flags_err;
2847 +
2848 +       inode->i_flags = flags;
2849 +       inode->i_vflags = vflags;
2850 +       ext3_get_inode_flags(EXT3_I(inode));
2851 +       inode->i_ctime = CURRENT_TIME_SEC;
2852 +
2853 +       err = ext3_mark_iloc_dirty(handle, inode, &iloc);
2854 +flags_err:
2855 +       ext3_journal_stop(handle);
2856 +       return err;
2857 +}
2858 +
2859  long ext3_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
2860  {
2861         struct inode *inode = file_inode(filp);
2862 @@ -45,6 +73,11 @@ long ext3_ioctl(struct file *filp, unsig
2863  
2864                 flags = ext3_mask_flags(inode->i_mode, flags);
2865  
2866 +               if (IS_BARRIER(inode)) {
2867 +                       vxwprintk_task(1, "messing with the barrier.");
2868 +                       return -EACCES;
2869 +               }
2870 +
2871                 mutex_lock(&inode->i_mutex);
2872  
2873                 /* Is it quota file? Do not allow user to mess with it */
2874 @@ -63,7 +96,9 @@ long ext3_ioctl(struct file *filp, unsig
2875                  *
2876                  * This test looks nicer. Thanks to Pauline Middelink
2877                  */
2878 -               if ((flags ^ oldflags) & (EXT3_APPEND_FL | EXT3_IMMUTABLE_FL)) {
2879 +               if ((oldflags & EXT3_IMMUTABLE_FL) ||
2880 +                       ((flags ^ oldflags) & (EXT3_APPEND_FL |
2881 +                       EXT3_IMMUTABLE_FL | EXT3_IXUNLINK_FL))) {
2882                         if (!capable(CAP_LINUX_IMMUTABLE))
2883                                 goto flags_out;
2884                 }
2885 @@ -88,7 +123,7 @@ long ext3_ioctl(struct file *filp, unsig
2886                 if (err)
2887                         goto flags_err;
2888  
2889 -               flags = flags & EXT3_FL_USER_MODIFIABLE;
2890 +               flags &= EXT3_FL_USER_MODIFIABLE;
2891                 flags |= oldflags & ~EXT3_FL_USER_MODIFIABLE;
2892                 ei->i_flags = flags;
2893  
2894 diff -NurpP --minimal linux-3.9.4/fs/ext3/namei.c linux-3.9.4-vs2.3.6.2/fs/ext3/namei.c
2895 --- linux-3.9.4/fs/ext3/namei.c 2013-05-31 13:45:23.000000000 +0000
2896 +++ linux-3.9.4-vs2.3.6.2/fs/ext3/namei.c       2013-05-31 14:47:11.000000000 +0000
2897 @@ -25,6 +25,8 @@
2898   */
2899  
2900  #include <linux/quotaops.h>
2901 +#include <linux/vs_tag.h>
2902 +
2903  #include "ext3.h"
2904  #include "namei.h"
2905  #include "xattr.h"
2906 @@ -918,6 +920,7 @@ restart:
2907                                         submit_bh(READ | REQ_META | REQ_PRIO,
2908                                                   bh);
2909                                 }
2910 +               dx_propagate_tag(nd, inode);
2911                         }
2912                 }
2913                 if ((bh = bh_use[ra_ptr++]) == NULL)
2914 @@ -2527,6 +2530,7 @@ const struct inode_operations ext3_dir_i
2915         .listxattr      = ext3_listxattr,
2916         .removexattr    = generic_removexattr,
2917  #endif
2918 +       .sync_flags     = ext3_sync_flags,
2919         .get_acl        = ext3_get_acl,
2920  };
2921  
2922 diff -NurpP --minimal linux-3.9.4/fs/ext3/super.c linux-3.9.4-vs2.3.6.2/fs/ext3/super.c
2923 --- linux-3.9.4/fs/ext3/super.c 2013-05-31 13:45:23.000000000 +0000
2924 +++ linux-3.9.4-vs2.3.6.2/fs/ext3/super.c       2013-05-31 14:47:11.000000000 +0000
2925 @@ -816,7 +816,8 @@ enum {
2926         Opt_usrjquota, Opt_grpjquota, Opt_offusrjquota, Opt_offgrpjquota,
2927         Opt_jqfmt_vfsold, Opt_jqfmt_vfsv0, Opt_jqfmt_vfsv1, Opt_quota,
2928         Opt_noquota, Opt_ignore, Opt_barrier, Opt_nobarrier, Opt_err,
2929 -       Opt_resize, Opt_usrquota, Opt_grpquota
2930 +       Opt_resize, Opt_usrquota, Opt_grpquota,
2931 +       Opt_tag, Opt_notag, Opt_tagid
2932  };
2933  
2934  static const match_table_t tokens = {
2935 @@ -873,6 +874,9 @@ static const match_table_t tokens = {
2936         {Opt_barrier, "barrier"},
2937         {Opt_nobarrier, "nobarrier"},
2938         {Opt_resize, "resize"},
2939 +       {Opt_tag, "tag"},
2940 +       {Opt_notag, "notag"},
2941 +       {Opt_tagid, "tagid=%u"},
2942         {Opt_err, NULL},
2943  };
2944  
2945 @@ -1040,6 +1044,20 @@ static int parse_options (char *options,
2946                 case Opt_nouid32:
2947                         set_opt (sbi->s_mount_opt, NO_UID32);
2948                         break;
2949 +#ifndef CONFIG_TAGGING_NONE
2950 +               case Opt_tag:
2951 +                       set_opt (sbi->s_mount_opt, TAGGED);
2952 +                       break;
2953 +               case Opt_notag:
2954 +                       clear_opt (sbi->s_mount_opt, TAGGED);
2955 +                       break;
2956 +#endif
2957 +#ifdef CONFIG_PROPAGATE
2958 +               case Opt_tagid:
2959 +                       /* use args[0] */
2960 +                       set_opt (sbi->s_mount_opt, TAGGED);
2961 +                       break;
2962 +#endif
2963                 case Opt_nocheck:
2964                         clear_opt (sbi->s_mount_opt, CHECK);
2965                         break;
2966 @@ -1737,6 +1755,9 @@ static int ext3_fill_super (struct super
2967                             NULL, 0))
2968                 goto failed_mount;
2969  
2970 +       if (EXT3_SB(sb)->s_mount_opt & EXT3_MOUNT_TAGGED)
2971 +               sb->s_flags |= MS_TAGGED;
2972 +
2973         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
2974                 (test_opt(sb, POSIX_ACL) ? MS_POSIXACL : 0);
2975  
2976 @@ -2633,6 +2654,14 @@ static int ext3_remount (struct super_bl
2977         if (test_opt(sb, ABORT))
2978                 ext3_abort(sb, __func__, "Abort forced by user");
2979  
2980 +       if ((sbi->s_mount_opt & EXT3_MOUNT_TAGGED) &&
2981 +               !(sb->s_flags & MS_TAGGED)) {
2982 +               printk("EXT3-fs: %s: tagging not permitted on remount.\n",
2983 +                       sb->s_id);
2984 +               err = -EINVAL;
2985 +               goto restore_opts;
2986 +       }
2987 +
2988         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
2989                 (test_opt(sb, POSIX_ACL) ? MS_POSIXACL : 0);
2990  
2991 diff -NurpP --minimal linux-3.9.4/fs/ext4/ext4.h linux-3.9.4-vs2.3.6.2/fs/ext4/ext4.h
2992 --- linux-3.9.4/fs/ext4/ext4.h  2013-05-31 13:45:23.000000000 +0000
2993 +++ linux-3.9.4-vs2.3.6.2/fs/ext4/ext4.h        2013-05-31 16:22:49.000000000 +0000
2994 @@ -399,7 +399,10 @@ struct flex_groups {
2995  #define EXT4_EXTENTS_FL                        0x00080000 /* Inode uses extents */
2996  #define EXT4_EA_INODE_FL               0x00200000 /* Inode used for large EA */
2997  #define EXT4_EOFBLOCKS_FL              0x00400000 /* Blocks allocated beyond EOF */
2998 +#define EXT4_BARRIER_FL                        0x04000000 /* Barrier for chroot() */
2999 +#define EXT4_IXUNLINK_FL               0x08000000 /* Immutable invert on unlink */
3000  #define EXT4_INLINE_DATA_FL            0x10000000 /* Inode has inline data. */
3001 +#define EXT4_COW_FL                    0x20000000 /* Copy on Write marker */
3002  #define EXT4_RESERVED_FL               0x80000000 /* reserved for ext4 lib */
3003  
3004  #define EXT4_FL_USER_VISIBLE           0x004BDFFF /* User visible flags */
3005 @@ -674,7 +677,7 @@ struct ext4_inode {
3006                         __le16  l_i_uid_high;   /* these 2 fields */
3007                         __le16  l_i_gid_high;   /* were reserved2[0] */
3008                         __le16  l_i_checksum_lo;/* crc32c(uuid+inum+inode) LE */
3009 -                       __le16  l_i_reserved;
3010 +                       __le16  l_i_tag;        /* Context Tag */
3011                 } linux2;
3012                 struct {
3013                         __le16  h_i_reserved1;  /* Obsoleted fragment number/size which are removed in ext4 */
3014 @@ -792,6 +795,7 @@ do {                                                                               \
3015  #define i_gid_low      i_gid
3016  #define i_uid_high     osd2.linux2.l_i_uid_high
3017  #define i_gid_high     osd2.linux2.l_i_gid_high
3018 +#define i_raw_tag      osd2.linux2.l_i_tag
3019  #define i_checksum_lo  osd2.linux2.l_i_checksum_lo
3020  
3021  #elif defined(__GNU__)
3022 @@ -969,6 +973,7 @@ struct ext4_inode_info {
3023  #define EXT4_MOUNT_POSIX_ACL           0x08000 /* POSIX Access Control Lists */
3024  #define EXT4_MOUNT_NO_AUTO_DA_ALLOC    0x10000 /* No auto delalloc mapping */
3025  #define EXT4_MOUNT_BARRIER             0x20000 /* Use block barriers */
3026 +#define EXT4_MOUNT_TAGGED              0x40000 /* Enable Context Tags */
3027  #define EXT4_MOUNT_QUOTA               0x80000 /* Some quota option set */
3028  #define EXT4_MOUNT_USRQUOTA            0x100000 /* "old" user quota */
3029  #define EXT4_MOUNT_GRPQUOTA            0x200000 /* "old" group quota */
3030 @@ -2527,6 +2532,7 @@ extern struct buffer_head *ext4_get_firs
3031  extern int ext4_inline_data_fiemap(struct inode *inode,
3032                                    struct fiemap_extent_info *fieinfo,
3033                                    int *has_inline);
3034 +extern int ext4_sync_flags(struct inode *, int, int);
3035  extern int ext4_try_to_evict_inline_data(handle_t *handle,
3036                                          struct inode *inode,
3037                                          int needed);
3038 diff -NurpP --minimal linux-3.9.4/fs/ext4/file.c linux-3.9.4-vs2.3.6.2/fs/ext4/file.c
3039 --- linux-3.9.4/fs/ext4/file.c  2013-05-31 13:45:23.000000000 +0000
3040 +++ linux-3.9.4-vs2.3.6.2/fs/ext4/file.c        2013-05-31 14:47:11.000000000 +0000
3041 @@ -650,5 +650,6 @@ const struct inode_operations ext4_file_
3042         .removexattr    = generic_removexattr,
3043         .get_acl        = ext4_get_acl,
3044         .fiemap         = ext4_fiemap,
3045 +       .sync_flags     = ext4_sync_flags,
3046  };
3047  
3048 diff -NurpP --minimal linux-3.9.4/fs/ext4/ialloc.c linux-3.9.4-vs2.3.6.2/fs/ext4/ialloc.c
3049 --- linux-3.9.4/fs/ext4/ialloc.c        2013-05-31 13:45:23.000000000 +0000
3050 +++ linux-3.9.4-vs2.3.6.2/fs/ext4/ialloc.c      2013-06-01 09:46:49.000000000 +0000
3051 @@ -22,6 +22,7 @@
3052  #include <linux/random.h>
3053  #include <linux/bitops.h>
3054  #include <linux/blkdev.h>
3055 +#include <linux/vs_tag.h>
3056  #include <asm/byteorder.h>
3057  
3058  #include "ext4.h"
3059 @@ -859,6 +860,8 @@ got:
3060                 inode->i_mode = mode;
3061                 inode->i_uid = current_fsuid();
3062                 inode->i_gid = dir->i_gid;
3063 +               inode->i_tag = make_ktag(&init_user_ns,
3064 +                       dx_current_fstag(sb));
3065         } else
3066                 inode_init_owner(inode, dir, mode);
3067  
3068 diff -NurpP --minimal linux-3.9.4/fs/ext4/inode.c linux-3.9.4-vs2.3.6.2/fs/ext4/inode.c
3069 --- linux-3.9.4/fs/ext4/inode.c 2013-05-31 14:22:27.000000000 +0000
3070 +++ linux-3.9.4-vs2.3.6.2/fs/ext4/inode.c       2013-05-31 14:47:11.000000000 +0000
3071 @@ -37,6 +37,7 @@
3072  #include <linux/printk.h>
3073  #include <linux/slab.h>
3074  #include <linux/ratelimit.h>
3075 +#include <linux/vs_tag.h>
3076  
3077  #include "ext4_jbd2.h"
3078  #include "xattr.h"
3079 @@ -3870,41 +3871,64 @@ void ext4_set_inode_flags(struct inode *
3080  {
3081         unsigned int flags = EXT4_I(inode)->i_flags;
3082  
3083 -       inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
3084 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
3085 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
3086 +
3087 +       if (flags & EXT4_IMMUTABLE_FL)
3088 +               inode->i_flags |= S_IMMUTABLE;
3089 +       if (flags & EXT4_IXUNLINK_FL)
3090 +               inode->i_flags |= S_IXUNLINK;
3091 +
3092         if (flags & EXT4_SYNC_FL)
3093                 inode->i_flags |= S_SYNC;
3094         if (flags & EXT4_APPEND_FL)
3095                 inode->i_flags |= S_APPEND;
3096 -       if (flags & EXT4_IMMUTABLE_FL)
3097 -               inode->i_flags |= S_IMMUTABLE;
3098         if (flags & EXT4_NOATIME_FL)
3099                 inode->i_flags |= S_NOATIME;
3100         if (flags & EXT4_DIRSYNC_FL)
3101                 inode->i_flags |= S_DIRSYNC;
3102 +
3103 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
3104 +
3105 +       if (flags & EXT4_BARRIER_FL)
3106 +               inode->i_vflags |= V_BARRIER;
3107 +       if (flags & EXT4_COW_FL)
3108 +               inode->i_vflags |= V_COW;
3109  }
3110  
3111  /* Propagate flags from i_flags to EXT4_I(inode)->i_flags */
3112  void ext4_get_inode_flags(struct ext4_inode_info *ei)
3113  {
3114 -       unsigned int vfs_fl;
3115 +       unsigned int vfs_fl, vfs_vf;
3116         unsigned long old_fl, new_fl;
3117  
3118         do {
3119                 vfs_fl = ei->vfs_inode.i_flags;
3120 +               vfs_vf = ei->vfs_inode.i_vflags;
3121                 old_fl = ei->i_flags;
3122                 new_fl = old_fl & ~(EXT4_SYNC_FL|EXT4_APPEND_FL|
3123                                 EXT4_IMMUTABLE_FL|EXT4_NOATIME_FL|
3124 -                               EXT4_DIRSYNC_FL);
3125 +                               EXT4_DIRSYNC_FL|EXT4_BARRIER_FL|
3126 +                               EXT4_COW_FL);
3127 +
3128 +               if (vfs_fl & S_IMMUTABLE)
3129 +                       new_fl |= EXT4_IMMUTABLE_FL;
3130 +               if (vfs_fl & S_IXUNLINK)
3131 +                       new_fl |= EXT4_IXUNLINK_FL;
3132 +
3133                 if (vfs_fl & S_SYNC)
3134                         new_fl |= EXT4_SYNC_FL;
3135                 if (vfs_fl & S_APPEND)
3136                         new_fl |= EXT4_APPEND_FL;
3137 -               if (vfs_fl & S_IMMUTABLE)
3138 -                       new_fl |= EXT4_IMMUTABLE_FL;
3139                 if (vfs_fl & S_NOATIME)
3140                         new_fl |= EXT4_NOATIME_FL;
3141                 if (vfs_fl & S_DIRSYNC)
3142                         new_fl |= EXT4_DIRSYNC_FL;
3143 +
3144 +               if (vfs_vf & V_BARRIER)
3145 +                       new_fl |= EXT4_BARRIER_FL;
3146 +               if (vfs_vf & V_COW)
3147 +                       new_fl |= EXT4_COW_FL;
3148         } while (cmpxchg(&ei->i_flags, old_fl, new_fl) != old_fl);
3149  }
3150  
3151 @@ -4009,8 +4033,10 @@ struct inode *ext4_iget(struct super_blo
3152                 i_uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
3153                 i_gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
3154         }
3155 -       i_uid_write(inode, i_uid);
3156 -       i_gid_write(inode, i_gid);
3157 +       i_uid_write(inode, INOTAG_UID(DX_TAG(inode), i_uid, i_gid));
3158 +       i_gid_write(inode, INOTAG_GID(DX_TAG(inode), i_uid, i_gid));
3159 +       i_tag_write(inode, INOTAG_TAG(DX_TAG(inode), i_uid, i_gid,
3160 +               le16_to_cpu(raw_inode->i_raw_tag)));
3161         set_nlink(inode, le16_to_cpu(raw_inode->i_links_count));
3162  
3163         ext4_clear_state_flags(ei);     /* Only relevant on 32-bit archs */
3164 @@ -4233,8 +4259,10 @@ static int ext4_do_update_inode(handle_t
3165  
3166         ext4_get_inode_flags(ei);
3167         raw_inode->i_mode = cpu_to_le16(inode->i_mode);
3168 -       i_uid = i_uid_read(inode);
3169 -       i_gid = i_gid_read(inode);
3170 +       i_uid = TAGINO_UID(DX_TAG(inode),
3171 +               i_uid_read(inode), i_tag_read(inode));
3172 +       i_gid = TAGINO_GID(DX_TAG(inode),
3173 +               i_gid_read(inode), i_tag_read(inode));
3174         if (!(test_opt(inode->i_sb, NO_UID32))) {
3175                 raw_inode->i_uid_low = cpu_to_le16(low_16_bits(i_uid));
3176                 raw_inode->i_gid_low = cpu_to_le16(low_16_bits(i_gid));
3177 @@ -4257,6 +4285,9 @@ static int ext4_do_update_inode(handle_t
3178                 raw_inode->i_uid_high = 0;
3179                 raw_inode->i_gid_high = 0;
3180         }
3181 +#ifdef CONFIG_TAGGING_INTERN
3182 +       raw_inode->i_raw_tag = cpu_to_le16(i_tag_read(inode));
3183 +#endif
3184         raw_inode->i_links_count = cpu_to_le16(inode->i_nlink);
3185  
3186         EXT4_INODE_SET_XTIME(i_ctime, inode, raw_inode);
3187 @@ -4487,7 +4518,8 @@ int ext4_setattr(struct dentry *dentry,
3188         if (is_quota_modification(inode, attr))
3189                 dquot_initialize(inode);
3190         if ((ia_valid & ATTR_UID && !uid_eq(attr->ia_uid, inode->i_uid)) ||
3191 -           (ia_valid & ATTR_GID && !gid_eq(attr->ia_gid, inode->i_gid))) {
3192 +           (ia_valid & ATTR_GID && !gid_eq(attr->ia_gid, inode->i_gid)) ||
3193 +           (ia_valid & ATTR_TAG && !tag_eq(attr->ia_tag, inode->i_tag))) {
3194                 handle_t *handle;
3195  
3196                 /* (user+group)*(old+new) structure, inode write (sb,
3197 @@ -4510,6 +4542,8 @@ int ext4_setattr(struct dentry *dentry,
3198                         inode->i_uid = attr->ia_uid;
3199                 if (attr->ia_valid & ATTR_GID)
3200                         inode->i_gid = attr->ia_gid;
3201 +               if ((attr->ia_valid & ATTR_TAG) && IS_TAGGED(inode))
3202 +                       inode->i_tag = attr->ia_tag;
3203                 error = ext4_mark_inode_dirty(handle, inode);
3204                 ext4_journal_stop(handle);
3205         }
3206 diff -NurpP --minimal linux-3.9.4/fs/ext4/ioctl.c linux-3.9.4-vs2.3.6.2/fs/ext4/ioctl.c
3207 --- linux-3.9.4/fs/ext4/ioctl.c 2013-05-31 13:45:23.000000000 +0000
3208 +++ linux-3.9.4-vs2.3.6.2/fs/ext4/ioctl.c       2013-05-31 19:50:08.000000000 +0000
3209 @@ -14,12 +14,40 @@
3210  #include <linux/compat.h>
3211  #include <linux/mount.h>
3212  #include <linux/file.h>
3213 +#include <linux/vs_tag.h>
3214  #include <asm/uaccess.h>
3215  #include "ext4_jbd2.h"
3216  #include "ext4.h"
3217  
3218  #define MAX_32_NUM ((((unsigned long long) 1) << 32) - 1)
3219  
3220 +int ext4_sync_flags(struct inode *inode, int flags, int vflags)
3221 +{
3222 +       handle_t *handle = NULL;
3223 +       struct ext4_iloc iloc;
3224 +       int err;
3225 +
3226 +       handle = ext4_journal_start(inode, EXT4_HT_INODE, 1);
3227 +       if (IS_ERR(handle))
3228 +               return PTR_ERR(handle);
3229 +
3230 +       if (IS_SYNC(inode))
3231 +               ext4_handle_sync(handle);
3232 +       err = ext4_reserve_inode_write(handle, inode, &iloc);
3233 +       if (err)
3234 +               goto flags_err;
3235 +
3236 +       inode->i_flags = flags;
3237 +       inode->i_vflags = vflags;
3238 +       ext4_get_inode_flags(EXT4_I(inode));
3239 +       inode->i_ctime = ext4_current_time(inode);
3240 +
3241 +       err = ext4_mark_iloc_dirty(handle, inode, &iloc);
3242 +flags_err:
3243 +       ext4_journal_stop(handle);
3244 +       return err;
3245 +}
3246 +
3247  long ext4_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
3248  {
3249         struct inode *inode = file_inode(filp);
3250 @@ -53,6 +81,11 @@ long ext4_ioctl(struct file *filp, unsig
3251  
3252                 flags = ext4_mask_flags(inode->i_mode, flags);
3253  
3254 +               if (IS_BARRIER(inode)) {
3255 +                       vxwprintk_task(1, "messing with the barrier.");
3256 +                       return -EACCES;
3257 +               }
3258 +
3259                 err = -EPERM;
3260                 mutex_lock(&inode->i_mutex);
3261                 /* Is it quota file? Do not allow user to mess with it */
3262 @@ -70,7 +103,9 @@ long ext4_ioctl(struct file *filp, unsig
3263                  *
3264                  * This test looks nicer. Thanks to Pauline Middelink
3265                  */
3266 -               if ((flags ^ oldflags) & (EXT4_APPEND_FL | EXT4_IMMUTABLE_FL)) {
3267 +               if ((oldflags & EXT4_IMMUTABLE_FL) ||
3268 +                       ((flags ^ oldflags) & (EXT4_APPEND_FL |
3269 +                       EXT4_IMMUTABLE_FL | EXT4_IXUNLINK_FL))) {
3270                         if (!capable(CAP_LINUX_IMMUTABLE))
3271                                 goto flags_out;
3272                 }
3273 diff -NurpP --minimal linux-3.9.4/fs/ext4/namei.c linux-3.9.4-vs2.3.6.2/fs/ext4/namei.c
3274 --- linux-3.9.4/fs/ext4/namei.c 2013-05-31 13:45:23.000000000 +0000
3275 +++ linux-3.9.4-vs2.3.6.2/fs/ext4/namei.c       2013-05-31 14:47:11.000000000 +0000
3276 @@ -34,6 +34,7 @@
3277  #include <linux/quotaops.h>
3278  #include <linux/buffer_head.h>
3279  #include <linux/bio.h>
3280 +#include <linux/vs_tag.h>
3281  #include "ext4.h"
3282  #include "ext4_jbd2.h"
3283  
3284 @@ -1290,6 +1291,7 @@ restart:
3285                                         ll_rw_block(READ | REQ_META | REQ_PRIO,
3286                                                     1, &bh);
3287                         }
3288 +               dx_propagate_tag(nd, inode);
3289                 }
3290                 if ((bh = bh_use[ra_ptr++]) == NULL)
3291                         goto next;
3292 @@ -3190,6 +3192,7 @@ const struct inode_operations ext4_dir_i
3293         .removexattr    = generic_removexattr,
3294         .get_acl        = ext4_get_acl,
3295         .fiemap         = ext4_fiemap,
3296 +       .sync_flags     = ext4_sync_flags,
3297  };
3298  
3299  const struct inode_operations ext4_special_inode_operations = {
3300 diff -NurpP --minimal linux-3.9.4/fs/ext4/super.c linux-3.9.4-vs2.3.6.2/fs/ext4/super.c
3301 --- linux-3.9.4/fs/ext4/super.c 2013-05-31 14:22:27.000000000 +0000
3302 +++ linux-3.9.4-vs2.3.6.2/fs/ext4/super.c       2013-05-31 14:47:11.000000000 +0000
3303 @@ -1131,7 +1131,7 @@ enum {
3304         Opt_inode_readahead_blks, Opt_journal_ioprio,
3305         Opt_dioread_nolock, Opt_dioread_lock,
3306         Opt_discard, Opt_nodiscard, Opt_init_itable, Opt_noinit_itable,
3307 -       Opt_max_dir_size_kb,
3308 +       Opt_max_dir_size_kb, Opt_tag, Opt_notag, Opt_tagid
3309  };
3310  
3311  static const match_table_t tokens = {
3312 @@ -1211,6 +1211,9 @@ static const match_table_t tokens = {
3313         {Opt_removed, "reservation"},   /* mount option from ext2/3 */
3314         {Opt_removed, "noreservation"}, /* mount option from ext2/3 */
3315         {Opt_removed, "journal=%u"},    /* mount option from ext2/3 */
3316 +       {Opt_tag, "tag"},
3317 +       {Opt_notag, "notag"},
3318 +       {Opt_tagid, "tagid=%u"},
3319         {Opt_err, NULL},
3320  };
3321  
3322 @@ -1441,6 +1444,20 @@ static int handle_mount_opt(struct super
3323         case Opt_i_version:
3324                 sb->s_flags |= MS_I_VERSION;
3325                 return 1;
3326 +#ifndef CONFIG_TAGGING_NONE
3327 +       case Opt_tag:
3328 +               set_opt(sb, TAGGED);
3329 +               return 1;
3330 +       case Opt_notag:
3331 +               clear_opt(sb, TAGGED);
3332 +               return 1;
3333 +#endif
3334 +#ifdef CONFIG_PROPAGATE
3335 +       case Opt_tagid:
3336 +               /* use args[0] */
3337 +               set_opt(sb, TAGGED);
3338 +               return 1;
3339 +#endif
3340         }
3341  
3342         for (m = ext4_mount_opts; m->token != Opt_err; m++)
3343 @@ -3401,6 +3418,9 @@ static int ext4_fill_super(struct super_
3344                         clear_opt(sb, DELALLOC);
3345         }
3346  
3347 +       if (EXT4_SB(sb)->s_mount_opt & EXT4_MOUNT_TAGGED)
3348 +               sb->s_flags |= MS_TAGGED;
3349 +
3350         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
3351                 (test_opt(sb, POSIX_ACL) ? MS_POSIXACL : 0);
3352  
3353 @@ -4587,6 +4607,14 @@ static int ext4_remount(struct super_blo
3354         if (sbi->s_mount_flags & EXT4_MF_FS_ABORTED)
3355                 ext4_abort(sb, "Abort forced by user");
3356  
3357 +       if ((sbi->s_mount_opt & EXT4_MOUNT_TAGGED) &&
3358 +               !(sb->s_flags & MS_TAGGED)) {
3359 +               printk("EXT4-fs: %s: tagging not permitted on remount.\n",
3360 +                       sb->s_id);
3361 +               err = -EINVAL;
3362 +               goto restore_opts;
3363 +       }
3364 +
3365         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
3366                 (test_opt(sb, POSIX_ACL) ? MS_POSIXACL : 0);
3367  
3368 diff -NurpP --minimal linux-3.9.4/fs/fcntl.c linux-3.9.4-vs2.3.6.2/fs/fcntl.c
3369 --- linux-3.9.4/fs/fcntl.c      2013-05-31 13:45:23.000000000 +0000
3370 +++ linux-3.9.4-vs2.3.6.2/fs/fcntl.c    2013-05-31 14:47:11.000000000 +0000
3371 @@ -21,6 +21,7 @@
3372  #include <linux/rcupdate.h>
3373  #include <linux/pid_namespace.h>
3374  #include <linux/user_namespace.h>
3375 +#include <linux/vs_limit.h>
3376  
3377  #include <asm/poll.h>
3378  #include <asm/siginfo.h>
3379 @@ -378,6 +379,8 @@ SYSCALL_DEFINE3(fcntl64, unsigned int, f
3380  
3381         if (!f.file)
3382                 goto out;
3383 +       if (!vx_files_avail(1))
3384 +               goto out;
3385  
3386         if (unlikely(f.file->f_mode & FMODE_PATH)) {
3387                 if (!check_fcntl_cmd(cmd))
3388 diff -NurpP --minimal linux-3.9.4/fs/file.c linux-3.9.4-vs2.3.6.2/fs/file.c
3389 --- linux-3.9.4/fs/file.c       2013-05-31 13:45:23.000000000 +0000
3390 +++ linux-3.9.4-vs2.3.6.2/fs/file.c     2013-05-31 14:47:11.000000000 +0000
3391 @@ -22,6 +22,7 @@
3392  #include <linux/spinlock.h>
3393  #include <linux/rcupdate.h>
3394  #include <linux/workqueue.h>
3395 +#include <linux/vs_limit.h>
3396  
3397  struct fdtable_defer {
3398         spinlock_t lock;
3399 @@ -364,6 +365,8 @@ struct files_struct *dup_fd(struct files
3400                 struct file *f = *old_fds++;
3401                 if (f) {
3402                         get_file(f);
3403 +                       /* TODO: sum it first for check and performance */
3404 +                       vx_openfd_inc(open_files - i);
3405                 } else {
3406                         /*
3407                          * The fd may be claimed in the fd bitmap but not yet
3408 @@ -429,9 +432,11 @@ static void close_files(struct files_str
3409                                         filp_close(file, files);
3410                                         cond_resched();
3411                                 }
3412 +                               vx_openfd_dec(i);
3413                         }
3414                         i++;
3415                         set >>= 1;
3416 +                       cond_resched();
3417                 }
3418         }
3419  }
3420 @@ -567,6 +572,7 @@ repeat:
3421         else
3422                 __clear_close_on_exec(fd, fdt);
3423         error = fd;
3424 +       vx_openfd_inc(fd);
3425  #if 1
3426         /* Sanity check */
3427         if (rcu_dereference_raw(fdt->fd[fd]) != NULL) {
3428 @@ -597,6 +603,7 @@ static void __put_unused_fd(struct files
3429         __clear_open_fd(fd, fdt);
3430         if (fd < files->next_fd)
3431                 files->next_fd = fd;
3432 +       vx_openfd_dec(fd);
3433  }
3434  
3435  void put_unused_fd(unsigned int fd)
3436 @@ -876,6 +883,8 @@ static int do_dup2(struct files_struct *
3437  
3438         if (tofree)
3439                 filp_close(tofree, files);
3440 +       else
3441 +               vx_openfd_inc(fd);      /* fd was unused */
3442  
3443         return fd;
3444  
3445 diff -NurpP --minimal linux-3.9.4/fs/file_table.c linux-3.9.4-vs2.3.6.2/fs/file_table.c
3446 --- linux-3.9.4/fs/file_table.c 2013-05-31 13:45:23.000000000 +0000
3447 +++ linux-3.9.4-vs2.3.6.2/fs/file_table.c       2013-05-31 14:47:11.000000000 +0000
3448 @@ -26,6 +26,8 @@
3449  #include <linux/hardirq.h>
3450  #include <linux/task_work.h>
3451  #include <linux/ima.h>
3452 +#include <linux/vs_limit.h>
3453 +#include <linux/vs_context.h>
3454  
3455  #include <linux/atomic.h>
3456  
3457 @@ -140,6 +142,8 @@ struct file *get_empty_filp(void)
3458         spin_lock_init(&f->f_lock);
3459         eventpoll_init_file(f);
3460         /* f->f_version: 0 */
3461 +       f->f_xid = vx_current_xid();
3462 +       vx_files_inc(f);
3463         return f;
3464  
3465  over:
3466 @@ -257,6 +261,8 @@ static void __fput(struct file *file)
3467                 i_readcount_dec(inode);
3468         if (file->f_mode & FMODE_WRITE)
3469                 drop_file_write_access(file);
3470 +       vx_files_dec(file);
3471 +       file->f_xid = 0;
3472         file->f_path.dentry = NULL;
3473         file->f_path.mnt = NULL;
3474         file->f_inode = NULL;
3475 @@ -344,6 +350,8 @@ void put_filp(struct file *file)
3476  {
3477         if (atomic_long_dec_and_test(&file->f_count)) {
3478                 security_file_free(file);
3479 +               vx_files_dec(file);
3480 +               file->f_xid = 0;
3481                 file_sb_list_del(file);
3482                 file_free(file);
3483         }
3484 diff -NurpP --minimal linux-3.9.4/fs/fs_struct.c linux-3.9.4-vs2.3.6.2/fs/fs_struct.c
3485 --- linux-3.9.4/fs/fs_struct.c  2013-05-31 13:45:23.000000000 +0000
3486 +++ linux-3.9.4-vs2.3.6.2/fs/fs_struct.c        2013-05-31 14:47:11.000000000 +0000
3487 @@ -4,6 +4,7 @@
3488  #include <linux/path.h>
3489  #include <linux/slab.h>
3490  #include <linux/fs_struct.h>
3491 +#include <linux/vserver/global.h>
3492  #include "internal.h"
3493  
3494  /*
3495 @@ -87,6 +88,7 @@ void free_fs_struct(struct fs_struct *fs
3496  {
3497         path_put(&fs->root);
3498         path_put(&fs->pwd);
3499 +       atomic_dec(&vs_global_fs);
3500         kmem_cache_free(fs_cachep, fs);
3501  }
3502  
3503 @@ -124,6 +126,7 @@ struct fs_struct *copy_fs_struct(struct
3504                 fs->pwd = old->pwd;
3505                 path_get(&fs->pwd);
3506                 spin_unlock(&old->lock);
3507 +               atomic_inc(&vs_global_fs);
3508         }
3509         return fs;
3510  }
3511 diff -NurpP --minimal linux-3.9.4/fs/gfs2/file.c linux-3.9.4-vs2.3.6.2/fs/gfs2/file.c
3512 --- linux-3.9.4/fs/gfs2/file.c  2013-05-31 13:45:23.000000000 +0000
3513 +++ linux-3.9.4-vs2.3.6.2/fs/gfs2/file.c        2013-05-31 19:54:27.000000000 +0000
3514 @@ -143,6 +143,9 @@ static const u32 fsflags_to_gfs2[32] = {
3515         [12] = GFS2_DIF_EXHASH,
3516         [14] = GFS2_DIF_INHERIT_JDATA,
3517         [17] = GFS2_DIF_TOPDIR,
3518 +       [27] = GFS2_DIF_IXUNLINK,
3519 +       [26] = GFS2_DIF_BARRIER,
3520 +       [29] = GFS2_DIF_COW,
3521  };
3522  
3523  static const u32 gfs2_to_fsflags[32] = {
3524 @@ -153,6 +156,9 @@ static const u32 gfs2_to_fsflags[32] = {
3525         [gfs2fl_ExHash] = FS_INDEX_FL,
3526         [gfs2fl_TopLevel] = FS_TOPDIR_FL,
3527         [gfs2fl_InheritJdata] = FS_JOURNAL_DATA_FL,
3528 +       [gfs2fl_IXUnlink] = FS_IXUNLINK_FL,
3529 +       [gfs2fl_Barrier] = FS_BARRIER_FL,
3530 +       [gfs2fl_Cow] = FS_COW_FL,
3531  };
3532  
3533  static int gfs2_get_flags(struct file *filp, u32 __user *ptr)
3534 @@ -183,12 +189,18 @@ void gfs2_set_inode_flags(struct inode *
3535  {
3536         struct gfs2_inode *ip = GFS2_I(inode);
3537         unsigned int flags = inode->i_flags;
3538 +       unsigned int vflags = inode->i_vflags;
3539 +
3540 +       flags &= ~(S_IMMUTABLE | S_IXUNLINK |
3541 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC | S_NOSEC);
3542  
3543 -       flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC|S_NOSEC);
3544         if ((ip->i_eattr == 0) && !is_sxid(inode->i_mode))
3545                 inode->i_flags |= S_NOSEC;
3546         if (ip->i_diskflags & GFS2_DIF_IMMUTABLE)
3547                 flags |= S_IMMUTABLE;
3548 +       if (ip->i_diskflags & GFS2_DIF_IXUNLINK)
3549 +               flags |= S_IXUNLINK;
3550 +
3551         if (ip->i_diskflags & GFS2_DIF_APPENDONLY)
3552                 flags |= S_APPEND;
3553         if (ip->i_diskflags & GFS2_DIF_NOATIME)
3554 @@ -196,6 +208,43 @@ void gfs2_set_inode_flags(struct inode *
3555         if (ip->i_diskflags & GFS2_DIF_SYNC)
3556                 flags |= S_SYNC;
3557         inode->i_flags = flags;
3558 +
3559 +       vflags &= ~(V_BARRIER | V_COW);
3560 +
3561 +       if (ip->i_diskflags & GFS2_DIF_BARRIER)
3562 +               vflags |= V_BARRIER;
3563 +       if (ip->i_diskflags & GFS2_DIF_COW)
3564 +               vflags |= V_COW;
3565 +       inode->i_vflags = vflags;
3566 +}
3567 +
3568 +void gfs2_get_inode_flags(struct inode *inode)
3569 +{
3570 +       struct gfs2_inode *ip = GFS2_I(inode);
3571 +       unsigned int flags = inode->i_flags;
3572 +       unsigned int vflags = inode->i_vflags;
3573 +
3574 +       ip->i_diskflags &= ~(GFS2_DIF_APPENDONLY |
3575 +                       GFS2_DIF_NOATIME | GFS2_DIF_SYNC |
3576 +                       GFS2_DIF_IMMUTABLE | GFS2_DIF_IXUNLINK |
3577 +                       GFS2_DIF_BARRIER | GFS2_DIF_COW);
3578 +
3579 +       if (flags & S_IMMUTABLE)
3580 +               ip->i_diskflags |= GFS2_DIF_IMMUTABLE;
3581 +       if (flags & S_IXUNLINK)
3582 +               ip->i_diskflags |= GFS2_DIF_IXUNLINK;
3583 +
3584 +       if (flags & S_APPEND)
3585 +               ip->i_diskflags |= GFS2_DIF_APPENDONLY;
3586 +       if (flags & S_NOATIME)
3587 +               ip->i_diskflags |= GFS2_DIF_NOATIME;
3588 +       if (flags & S_SYNC)
3589 +               ip->i_diskflags |= GFS2_DIF_SYNC;
3590 +
3591 +       if (vflags & V_BARRIER)
3592 +               ip->i_diskflags |= GFS2_DIF_BARRIER;
3593 +       if (vflags & V_COW)
3594 +               ip->i_diskflags |= GFS2_DIF_COW;
3595  }
3596  
3597  /* Flags that can be set by user space */
3598 @@ -309,6 +358,37 @@ static int gfs2_set_flags(struct file *f
3599         return do_gfs2_set_flags(filp, gfsflags, ~GFS2_DIF_JDATA);
3600  }
3601  
3602 +int gfs2_sync_flags(struct inode *inode, int flags, int vflags)
3603 +{
3604 +       struct gfs2_inode *ip = GFS2_I(inode);
3605 +       struct gfs2_sbd *sdp = GFS2_SB(inode);
3606 +       struct buffer_head *bh;
3607 +       struct gfs2_holder gh;
3608 +       int error;
3609 +
3610 +       error = gfs2_glock_nq_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &gh);
3611 +       if (error)
3612 +               return error;
3613 +       error = gfs2_trans_begin(sdp, RES_DINODE, 0);
3614 +       if (error)
3615 +               goto out;
3616 +       error = gfs2_meta_inode_buffer(ip, &bh);
3617 +       if (error)
3618 +               goto out_trans_end;
3619 +       gfs2_trans_add_meta(ip->i_gl, bh);
3620 +       inode->i_flags = flags;
3621 +       inode->i_vflags = vflags;
3622 +       gfs2_get_inode_flags(inode);
3623 +       gfs2_dinode_out(ip, bh->b_data);
3624 +       brelse(bh);
3625 +       gfs2_set_aops(inode);
3626 +out_trans_end:
3627 +       gfs2_trans_end(sdp);
3628 +out:
3629 +       gfs2_glock_dq_uninit(&gh);
3630 +       return error;
3631 +}
3632 +
3633  static long gfs2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
3634  {
3635         switch(cmd) {
3636 diff -NurpP --minimal linux-3.9.4/fs/gfs2/inode.h linux-3.9.4-vs2.3.6.2/fs/gfs2/inode.h
3637 --- linux-3.9.4/fs/gfs2/inode.h 2012-12-11 03:30:57.000000000 +0000
3638 +++ linux-3.9.4-vs2.3.6.2/fs/gfs2/inode.h       2013-05-31 14:47:11.000000000 +0000
3639 @@ -117,6 +117,7 @@ extern const struct file_operations gfs2
3640  extern const struct file_operations gfs2_dir_fops_nolock;
3641  
3642  extern void gfs2_set_inode_flags(struct inode *inode);
3643 +extern int gfs2_sync_flags(struct inode *inode, int flags, int vflags);
3644   
3645  #ifdef CONFIG_GFS2_FS_LOCKING_DLM
3646  extern const struct file_operations gfs2_file_fops;
3647 diff -NurpP --minimal linux-3.9.4/fs/hostfs/hostfs.h linux-3.9.4-vs2.3.6.2/fs/hostfs/hostfs.h
3648 --- linux-3.9.4/fs/hostfs/hostfs.h      2012-12-11 03:30:57.000000000 +0000
3649 +++ linux-3.9.4-vs2.3.6.2/fs/hostfs/hostfs.h    2013-05-31 14:47:11.000000000 +0000
3650 @@ -42,6 +42,7 @@ struct hostfs_iattr {
3651         unsigned short  ia_mode;
3652         uid_t           ia_uid;
3653         gid_t           ia_gid;
3654 +       tag_t           ia_tag;
3655         loff_t          ia_size;
3656         struct timespec ia_atime;
3657         struct timespec ia_mtime;
3658 diff -NurpP --minimal linux-3.9.4/fs/inode.c linux-3.9.4-vs2.3.6.2/fs/inode.c
3659 --- linux-3.9.4/fs/inode.c      2013-05-31 13:45:24.000000000 +0000
3660 +++ linux-3.9.4-vs2.3.6.2/fs/inode.c    2013-06-01 09:01:48.000000000 +0000
3661 @@ -17,6 +17,7 @@
3662  #include <linux/prefetch.h>
3663  #include <linux/buffer_head.h> /* for inode_has_buffers */
3664  #include <linux/ratelimit.h>
3665 +#include <linux/vs_tag.h>
3666  #include "internal.h"
3667  
3668  /*
3669 @@ -128,6 +129,8 @@ int inode_init_always(struct super_block
3670         struct address_space *const mapping = &inode->i_data;
3671  
3672         inode->i_sb = sb;
3673 +
3674 +       /* essential because of inode slab reuse */
3675         inode->i_blkbits = sb->s_blocksize_bits;
3676         inode->i_flags = 0;
3677         atomic_set(&inode->i_count, 1);
3678 @@ -137,6 +140,7 @@ int inode_init_always(struct super_block
3679         inode->i_opflags = 0;
3680         i_uid_write(inode, 0);
3681         i_gid_write(inode, 0);
3682 +       i_tag_write(inode, 0);
3683         atomic_set(&inode->i_writecount, 0);
3684         inode->i_size = 0;
3685         inode->i_blocks = 0;
3686 @@ -149,6 +153,7 @@ int inode_init_always(struct super_block
3687         inode->i_bdev = NULL;
3688         inode->i_cdev = NULL;
3689         inode->i_rdev = 0;
3690 +       inode->i_mdev = 0;
3691         inode->dirtied_when = 0;
3692  
3693         if (security_inode_alloc(inode))
3694 @@ -483,6 +488,8 @@ void __insert_inode_hash(struct inode *i
3695  }
3696  EXPORT_SYMBOL(__insert_inode_hash);
3697  
3698 +EXPORT_SYMBOL_GPL(__iget);
3699 +
3700  /**
3701   *     __remove_inode_hash - remove an inode from the hash
3702   *     @inode: inode to unhash
3703 @@ -1799,9 +1806,11 @@ void init_special_inode(struct inode *in
3704         if (S_ISCHR(mode)) {
3705                 inode->i_fop = &def_chr_fops;
3706                 inode->i_rdev = rdev;
3707 +               inode->i_mdev = rdev;
3708         } else if (S_ISBLK(mode)) {
3709                 inode->i_fop = &def_blk_fops;
3710                 inode->i_rdev = rdev;
3711 +               inode->i_mdev = rdev;
3712         } else if (S_ISFIFO(mode))
3713                 inode->i_fop = &def_fifo_fops;
3714         else if (S_ISSOCK(mode))
3715 @@ -1830,6 +1839,7 @@ void inode_init_owner(struct inode *inod
3716         } else
3717                 inode->i_gid = current_fsgid();
3718         inode->i_mode = mode;
3719 +       i_tag_write(inode, dx_current_fstag(inode->i_sb));
3720  }
3721  EXPORT_SYMBOL(inode_init_owner);
3722  
3723 diff -NurpP --minimal linux-3.9.4/fs/ioctl.c linux-3.9.4-vs2.3.6.2/fs/ioctl.c
3724 --- linux-3.9.4/fs/ioctl.c      2013-05-31 13:45:24.000000000 +0000
3725 +++ linux-3.9.4-vs2.3.6.2/fs/ioctl.c    2013-05-31 14:47:11.000000000 +0000
3726 @@ -15,6 +15,9 @@
3727  #include <linux/writeback.h>
3728  #include <linux/buffer_head.h>
3729  #include <linux/falloc.h>
3730 +#include <linux/proc_fs.h>
3731 +#include <linux/vserver/inode.h>
3732 +#include <linux/vs_tag.h>
3733  
3734  #include <asm/ioctls.h>
3735  
3736 diff -NurpP --minimal linux-3.9.4/fs/ioprio.c linux-3.9.4-vs2.3.6.2/fs/ioprio.c
3737 --- linux-3.9.4/fs/ioprio.c     2012-12-11 03:30:57.000000000 +0000
3738 +++ linux-3.9.4-vs2.3.6.2/fs/ioprio.c   2013-05-31 14:47:11.000000000 +0000
3739 @@ -28,6 +28,7 @@
3740  #include <linux/syscalls.h>
3741  #include <linux/security.h>
3742  #include <linux/pid_namespace.h>
3743 +#include <linux/vs_base.h>
3744  
3745  int set_task_ioprio(struct task_struct *task, int ioprio)
3746  {
3747 @@ -105,6 +106,8 @@ SYSCALL_DEFINE3(ioprio_set, int, which,
3748                         else
3749                                 pgrp = find_vpid(who);
3750                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
3751 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
3752 +                                       continue;
3753                                 ret = set_task_ioprio(p, ioprio);
3754                                 if (ret)
3755                                         break;
3756 @@ -198,6 +201,8 @@ SYSCALL_DEFINE2(ioprio_get, int, which,
3757                         else
3758                                 pgrp = find_vpid(who);
3759                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
3760 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
3761 +                                       continue;
3762                                 tmpio = get_task_ioprio(p);
3763                                 if (tmpio < 0)
3764                                         continue;
3765 diff -NurpP --minimal linux-3.9.4/fs/jfs/file.c linux-3.9.4-vs2.3.6.2/fs/jfs/file.c
3766 --- linux-3.9.4/fs/jfs/file.c   2013-02-19 13:58:48.000000000 +0000
3767 +++ linux-3.9.4-vs2.3.6.2/fs/jfs/file.c 2013-05-31 14:47:11.000000000 +0000
3768 @@ -109,7 +109,8 @@ int jfs_setattr(struct dentry *dentry, s
3769         if (is_quota_modification(inode, iattr))
3770                 dquot_initialize(inode);
3771         if ((iattr->ia_valid & ATTR_UID && !uid_eq(iattr->ia_uid, inode->i_uid)) ||
3772 -           (iattr->ia_valid & ATTR_GID && !gid_eq(iattr->ia_gid, inode->i_gid))) {
3773 +           (iattr->ia_valid & ATTR_GID && !gid_eq(iattr->ia_gid, inode->i_gid)) ||
3774 +           (iattr->ia_valid & ATTR_TAG && !tag_eq(iattr->ia_tag, inode->i_tag))) {
3775                 rc = dquot_transfer(inode, iattr);
3776                 if (rc)
3777                         return rc;
3778 @@ -144,6 +145,7 @@ const struct inode_operations jfs_file_i
3779  #ifdef CONFIG_JFS_POSIX_ACL
3780         .get_acl        = jfs_get_acl,
3781  #endif
3782 +       .sync_flags     = jfs_sync_flags,
3783  };
3784  
3785  const struct file_operations jfs_file_operations = {
3786 diff -NurpP --minimal linux-3.9.4/fs/jfs/ioctl.c linux-3.9.4-vs2.3.6.2/fs/jfs/ioctl.c
3787 --- linux-3.9.4/fs/jfs/ioctl.c  2013-05-31 13:45:24.000000000 +0000
3788 +++ linux-3.9.4-vs2.3.6.2/fs/jfs/ioctl.c        2013-05-31 14:47:11.000000000 +0000
3789 @@ -12,6 +12,7 @@
3790  #include <linux/time.h>
3791  #include <linux/sched.h>
3792  #include <linux/blkdev.h>
3793 +#include <linux/mount.h>
3794  #include <asm/current.h>
3795  #include <asm/uaccess.h>
3796  
3797 @@ -56,6 +57,16 @@ static long jfs_map_ext2(unsigned long f
3798  }
3799  
3800  
3801 +int jfs_sync_flags(struct inode *inode, int flags, int vflags)
3802 +{
3803 +       inode->i_flags = flags;
3804 +       inode->i_vflags = vflags;
3805 +       jfs_get_inode_flags(JFS_IP(inode));
3806 +       inode->i_ctime = CURRENT_TIME_SEC;
3807 +       mark_inode_dirty(inode);
3808 +       return 0;
3809 +}
3810 +
3811  long jfs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
3812  {
3813         struct inode *inode = file_inode(filp);
3814 @@ -89,6 +100,11 @@ long jfs_ioctl(struct file *filp, unsign
3815                 if (!S_ISDIR(inode->i_mode))
3816                         flags &= ~JFS_DIRSYNC_FL;
3817  
3818 +               if (IS_BARRIER(inode)) {
3819 +                       vxwprintk_task(1, "messing with the barrier.");
3820 +                       return -EACCES;
3821 +               }
3822 +
3823                 /* Is it quota file? Do not allow user to mess with it */
3824                 if (IS_NOQUOTA(inode)) {
3825                         err = -EPERM;
3826 @@ -106,8 +122,8 @@ long jfs_ioctl(struct file *filp, unsign
3827                  * the relevant capability.
3828                  */
3829                 if ((oldflags & JFS_IMMUTABLE_FL) ||
3830 -                       ((flags ^ oldflags) &
3831 -                       (JFS_APPEND_FL | JFS_IMMUTABLE_FL))) {
3832 +                       ((flags ^ oldflags) & (JFS_APPEND_FL |
3833 +                       JFS_IMMUTABLE_FL | JFS_IXUNLINK_FL))) {
3834                         if (!capable(CAP_LINUX_IMMUTABLE)) {
3835                                 mutex_unlock(&inode->i_mutex);
3836                                 err = -EPERM;
3837 @@ -115,7 +131,7 @@ long jfs_ioctl(struct file *filp, unsign
3838                         }
3839                 }
3840  
3841 -               flags = flags & JFS_FL_USER_MODIFIABLE;
3842 +               flags &= JFS_FL_USER_MODIFIABLE;
3843                 flags |= oldflags & ~JFS_FL_USER_MODIFIABLE;
3844                 jfs_inode->mode2 = flags;
3845  
3846 diff -NurpP --minimal linux-3.9.4/fs/jfs/jfs_dinode.h linux-3.9.4-vs2.3.6.2/fs/jfs/jfs_dinode.h
3847 --- linux-3.9.4/fs/jfs/jfs_dinode.h     2012-12-11 03:30:57.000000000 +0000
3848 +++ linux-3.9.4-vs2.3.6.2/fs/jfs/jfs_dinode.h   2013-05-31 14:47:11.000000000 +0000
3849 @@ -161,9 +161,13 @@ struct dinode {
3850  
3851  #define JFS_APPEND_FL          0x01000000 /* writes to file may only append */
3852  #define JFS_IMMUTABLE_FL       0x02000000 /* Immutable file */
3853 +#define JFS_IXUNLINK_FL                0x08000000 /* Immutable invert on unlink */
3854  
3855 -#define JFS_FL_USER_VISIBLE    0x03F80000
3856 -#define JFS_FL_USER_MODIFIABLE 0x03F80000
3857 +#define JFS_BARRIER_FL         0x04000000 /* Barrier for chroot() */
3858 +#define JFS_COW_FL             0x20000000 /* Copy on Write marker */
3859 +
3860 +#define JFS_FL_USER_VISIBLE    0x07F80000
3861 +#define JFS_FL_USER_MODIFIABLE 0x07F80000
3862  #define JFS_FL_INHERIT         0x03C80000
3863  
3864  /* These are identical to EXT[23]_IOC_GETFLAGS/SETFLAGS */
3865 diff -NurpP --minimal linux-3.9.4/fs/jfs/jfs_filsys.h linux-3.9.4-vs2.3.6.2/fs/jfs/jfs_filsys.h
3866 --- linux-3.9.4/fs/jfs/jfs_filsys.h     2012-12-11 03:30:57.000000000 +0000
3867 +++ linux-3.9.4-vs2.3.6.2/fs/jfs/jfs_filsys.h   2013-05-31 14:47:11.000000000 +0000
3868 @@ -266,6 +266,7 @@
3869  #define JFS_NAME_MAX   255
3870  #define JFS_PATH_MAX   BPSIZE
3871  
3872 +#define JFS_TAGGED             0x00800000      /* Context Tagging */
3873  
3874  /*
3875   *     file system state (superblock state)
3876 diff -NurpP --minimal linux-3.9.4/fs/jfs/jfs_imap.c linux-3.9.4-vs2.3.6.2/fs/jfs/jfs_imap.c
3877 --- linux-3.9.4/fs/jfs/jfs_imap.c       2012-12-11 03:30:57.000000000 +0000
3878 +++ linux-3.9.4-vs2.3.6.2/fs/jfs/jfs_imap.c     2013-05-31 14:47:11.000000000 +0000
3879 @@ -46,6 +46,7 @@
3880  #include <linux/pagemap.h>
3881  #include <linux/quotaops.h>
3882  #include <linux/slab.h>
3883 +#include <linux/vs_tag.h>
3884  
3885  #include "jfs_incore.h"
3886  #include "jfs_inode.h"
3887 @@ -3058,6 +3059,8 @@ static int copy_from_dinode(struct dinod
3888  {
3889         struct jfs_inode_info *jfs_ip = JFS_IP(ip);
3890         struct jfs_sb_info *sbi = JFS_SBI(ip->i_sb);
3891 +       kuid_t uid;
3892 +       kgid_t gid;
3893  
3894         jfs_ip->fileset = le32_to_cpu(dip->di_fileset);
3895         jfs_ip->mode2 = le32_to_cpu(dip->di_mode);
3896 @@ -3078,14 +3081,19 @@ static int copy_from_dinode(struct dinod
3897         }
3898         set_nlink(ip, le32_to_cpu(dip->di_nlink));
3899  
3900 -       jfs_ip->saved_uid = make_kuid(&init_user_ns, le32_to_cpu(dip->di_uid));
3901 +       uid = make_kuid(&init_user_ns, le32_to_cpu(dip->di_uid));
3902 +       gid = make_kgid(&init_user_ns, le32_to_cpu(dip->di_gid));
3903 +       ip->i_tag = make_ktag(&init_user_ns,
3904 +               INOTAG_TAG(DX_TAG(ip), uid, gid, 0));
3905 +
3906 +       jfs_ip->saved_uid = INOTAG_UID(DX_TAG(ip), uid, gid);
3907         if (!uid_valid(sbi->uid))
3908                 ip->i_uid = jfs_ip->saved_uid;
3909         else {
3910                 ip->i_uid = sbi->uid;
3911         }
3912  
3913 -       jfs_ip->saved_gid = make_kgid(&init_user_ns, le32_to_cpu(dip->di_gid));
3914 +       jfs_ip->saved_gid = INOTAG_GID(DX_TAG(ip), uid, gid);
3915         if (!gid_valid(sbi->gid))
3916                 ip->i_gid = jfs_ip->saved_gid;
3917         else {
3918 @@ -3150,16 +3158,14 @@ static void copy_to_dinode(struct dinode
3919         dip->di_size = cpu_to_le64(ip->i_size);
3920         dip->di_nblocks = cpu_to_le64(PBLK2LBLK(ip->i_sb, ip->i_blocks));
3921         dip->di_nlink = cpu_to_le32(ip->i_nlink);
3922 -       if (!uid_valid(sbi->uid))
3923 -               dip->di_uid = cpu_to_le32(i_uid_read(ip));
3924 -       else
3925 -               dip->di_uid =cpu_to_le32(from_kuid(&init_user_ns,
3926 -                                                  jfs_ip->saved_uid));
3927 -       if (!gid_valid(sbi->gid))
3928 -               dip->di_gid = cpu_to_le32(i_gid_read(ip));
3929 -       else
3930 -               dip->di_gid = cpu_to_le32(from_kgid(&init_user_ns,
3931 -                                                   jfs_ip->saved_gid));
3932 +       dip->di_uid = cpu_to_le32(from_kuid(&init_user_ns,
3933 +               TAGINO_UID(DX_TAG(ip),
3934 +               !uid_valid(sbi->uid) ? ip->i_uid : jfs_ip->saved_uid,
3935 +               ip->i_tag)));
3936 +       dip->di_gid = cpu_to_le32(from_kuid(&init_user_ns,
3937 +               TAGINO_GID(DX_TAG(ip),
3938 +               !gid_valid(sbi->gid) ? ip->i_gid : jfs_ip->saved_gid,
3939 +               ip->i_tag)));
3940         jfs_get_inode_flags(jfs_ip);
3941         /*
3942          * mode2 is only needed for storing the higher order bits.
3943 diff -NurpP --minimal linux-3.9.4/fs/jfs/jfs_inode.c linux-3.9.4-vs2.3.6.2/fs/jfs/jfs_inode.c
3944 --- linux-3.9.4/fs/jfs/jfs_inode.c      2012-12-11 03:30:57.000000000 +0000
3945 +++ linux-3.9.4-vs2.3.6.2/fs/jfs/jfs_inode.c    2013-05-31 14:47:11.000000000 +0000
3946 @@ -18,6 +18,7 @@
3947  
3948  #include <linux/fs.h>
3949  #include <linux/quotaops.h>
3950 +#include <linux/vs_tag.h>
3951  #include "jfs_incore.h"
3952  #include "jfs_inode.h"
3953  #include "jfs_filsys.h"
3954 @@ -30,29 +31,46 @@ void jfs_set_inode_flags(struct inode *i
3955  {
3956         unsigned int flags = JFS_IP(inode)->mode2;
3957  
3958 -       inode->i_flags &= ~(S_IMMUTABLE | S_APPEND |
3959 -               S_NOATIME | S_DIRSYNC | S_SYNC);
3960 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
3961 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
3962  
3963         if (flags & JFS_IMMUTABLE_FL)
3964                 inode->i_flags |= S_IMMUTABLE;
3965 +       if (flags & JFS_IXUNLINK_FL)
3966 +               inode->i_flags |= S_IXUNLINK;
3967 +
3968 +       if (flags & JFS_SYNC_FL)
3969 +               inode->i_flags |= S_SYNC;
3970         if (flags & JFS_APPEND_FL)
3971                 inode->i_flags |= S_APPEND;
3972         if (flags & JFS_NOATIME_FL)
3973                 inode->i_flags |= S_NOATIME;
3974         if (flags & JFS_DIRSYNC_FL)
3975                 inode->i_flags |= S_DIRSYNC;
3976 -       if (flags & JFS_SYNC_FL)
3977 -               inode->i_flags |= S_SYNC;
3978 +
3979 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
3980 +
3981 +       if (flags & JFS_BARRIER_FL)
3982 +               inode->i_vflags |= V_BARRIER;
3983 +       if (flags & JFS_COW_FL)
3984 +               inode->i_vflags |= V_COW;
3985  }
3986  
3987  void jfs_get_inode_flags(struct jfs_inode_info *jfs_ip)
3988  {
3989         unsigned int flags = jfs_ip->vfs_inode.i_flags;
3990 +       unsigned int vflags = jfs_ip->vfs_inode.i_vflags;
3991 +
3992 +       jfs_ip->mode2 &= ~(JFS_IMMUTABLE_FL | JFS_IXUNLINK_FL |
3993 +                          JFS_APPEND_FL | JFS_NOATIME_FL |
3994 +                          JFS_DIRSYNC_FL | JFS_SYNC_FL |
3995 +                          JFS_BARRIER_FL | JFS_COW_FL);
3996  
3997 -       jfs_ip->mode2 &= ~(JFS_IMMUTABLE_FL | JFS_APPEND_FL | JFS_NOATIME_FL |
3998 -                          JFS_DIRSYNC_FL | JFS_SYNC_FL);
3999         if (flags & S_IMMUTABLE)
4000                 jfs_ip->mode2 |= JFS_IMMUTABLE_FL;
4001 +       if (flags & S_IXUNLINK)
4002 +               jfs_ip->mode2 |= JFS_IXUNLINK_FL;
4003 +
4004         if (flags & S_APPEND)
4005                 jfs_ip->mode2 |= JFS_APPEND_FL;
4006         if (flags & S_NOATIME)
4007 @@ -61,6 +79,11 @@ void jfs_get_inode_flags(struct jfs_inod
4008                 jfs_ip->mode2 |= JFS_DIRSYNC_FL;
4009         if (flags & S_SYNC)
4010                 jfs_ip->mode2 |= JFS_SYNC_FL;
4011 +
4012 +       if (vflags & V_BARRIER)
4013 +               jfs_ip->mode2 |= JFS_BARRIER_FL;
4014 +       if (vflags & V_COW)
4015 +               jfs_ip->mode2 |= JFS_COW_FL;
4016  }
4017  
4018  /*
4019 diff -NurpP --minimal linux-3.9.4/fs/jfs/jfs_inode.h linux-3.9.4-vs2.3.6.2/fs/jfs/jfs_inode.h
4020 --- linux-3.9.4/fs/jfs/jfs_inode.h      2012-12-11 03:30:57.000000000 +0000
4021 +++ linux-3.9.4-vs2.3.6.2/fs/jfs/jfs_inode.h    2013-05-31 14:47:11.000000000 +0000
4022 @@ -39,6 +39,7 @@ extern struct dentry *jfs_fh_to_dentry(s
4023  extern struct dentry *jfs_fh_to_parent(struct super_block *sb, struct fid *fid,
4024         int fh_len, int fh_type);
4025  extern void jfs_set_inode_flags(struct inode *);
4026 +extern int jfs_sync_flags(struct inode *, int, int);
4027  extern int jfs_get_block(struct inode *, sector_t, struct buffer_head *, int);
4028  extern int jfs_setattr(struct dentry *, struct iattr *);
4029  
4030 diff -NurpP --minimal linux-3.9.4/fs/jfs/namei.c linux-3.9.4-vs2.3.6.2/fs/jfs/namei.c
4031 --- linux-3.9.4/fs/jfs/namei.c  2012-12-11 03:30:57.000000000 +0000
4032 +++ linux-3.9.4-vs2.3.6.2/fs/jfs/namei.c        2013-05-31 14:47:11.000000000 +0000
4033 @@ -22,6 +22,7 @@
4034  #include <linux/ctype.h>
4035  #include <linux/quotaops.h>
4036  #include <linux/exportfs.h>
4037 +#include <linux/vs_tag.h>
4038  #include "jfs_incore.h"
4039  #include "jfs_superblock.h"
4040  #include "jfs_inode.h"
4041 @@ -1461,6 +1462,7 @@ static struct dentry *jfs_lookup(struct
4042                         jfs_err("jfs_lookup: iget failed on inum %d", (uint)inum);
4043         }
4044  
4045 +       dx_propagate_tag(nd, ip);
4046         return d_splice_alias(ip, dentry);
4047  }
4048  
4049 @@ -1525,6 +1527,7 @@ const struct inode_operations jfs_dir_in
4050  #ifdef CONFIG_JFS_POSIX_ACL
4051         .get_acl        = jfs_get_acl,
4052  #endif
4053 +       .sync_flags     = jfs_sync_flags,
4054  };
4055  
4056  const struct file_operations jfs_dir_operations = {
4057 diff -NurpP --minimal linux-3.9.4/fs/jfs/super.c linux-3.9.4-vs2.3.6.2/fs/jfs/super.c
4058 --- linux-3.9.4/fs/jfs/super.c  2013-05-31 13:45:24.000000000 +0000
4059 +++ linux-3.9.4-vs2.3.6.2/fs/jfs/super.c        2013-05-31 14:47:11.000000000 +0000
4060 @@ -199,7 +199,8 @@ enum {
4061         Opt_integrity, Opt_nointegrity, Opt_iocharset, Opt_resize,
4062         Opt_resize_nosize, Opt_errors, Opt_ignore, Opt_err, Opt_quota,
4063         Opt_usrquota, Opt_grpquota, Opt_uid, Opt_gid, Opt_umask,
4064 -       Opt_discard, Opt_nodiscard, Opt_discard_minblk
4065 +       Opt_discard, Opt_nodiscard, Opt_discard_minblk,
4066 +       Opt_tag, Opt_notag, Opt_tagid
4067  };
4068  
4069  static const match_table_t tokens = {
4070 @@ -209,6 +210,10 @@ static const match_table_t tokens = {
4071         {Opt_resize, "resize=%u"},
4072         {Opt_resize_nosize, "resize"},
4073         {Opt_errors, "errors=%s"},
4074 +       {Opt_tag, "tag"},
4075 +       {Opt_notag, "notag"},
4076 +       {Opt_tagid, "tagid=%u"},
4077 +       {Opt_tag, "tagxid"},
4078         {Opt_ignore, "noquota"},
4079         {Opt_ignore, "quota"},
4080         {Opt_usrquota, "usrquota"},
4081 @@ -385,7 +390,20 @@ static int parse_options(char *options,
4082                         }
4083                         break;
4084                 }
4085 -
4086 +#ifndef CONFIG_TAGGING_NONE
4087 +               case Opt_tag:
4088 +                       *flag |= JFS_TAGGED;
4089 +                       break;
4090 +               case Opt_notag:
4091 +                       *flag &= JFS_TAGGED;
4092 +                       break;
4093 +#endif
4094 +#ifdef CONFIG_PROPAGATE
4095 +               case Opt_tagid:
4096 +                       /* use args[0] */
4097 +                       *flag |= JFS_TAGGED;
4098 +                       break;
4099 +#endif
4100                 default:
4101                         printk("jfs: Unrecognized mount option \"%s\" "
4102                                         " or missing value\n", p);
4103 @@ -417,6 +435,12 @@ static int jfs_remount(struct super_bloc
4104                 return -EINVAL;
4105         }
4106  
4107 +       if ((flag & JFS_TAGGED) && !(sb->s_flags & MS_TAGGED)) {
4108 +               printk(KERN_ERR "JFS: %s: tagging not permitted on remount.\n",
4109 +                       sb->s_id);
4110 +               return -EINVAL;
4111 +       }
4112 +
4113         if (newLVSize) {
4114                 if (sb->s_flags & MS_RDONLY) {
4115                         pr_err("JFS: resize requires volume" \
4116 @@ -502,6 +526,9 @@ static int jfs_fill_super(struct super_b
4117  #ifdef CONFIG_JFS_POSIX_ACL
4118         sb->s_flags |= MS_POSIXACL;
4119  #endif
4120 +       /* map mount option tagxid */
4121 +       if (sbi->flag & JFS_TAGGED)
4122 +               sb->s_flags |= MS_TAGGED;
4123  
4124         if (newLVSize) {
4125                 pr_err("resize option for remount only\n");
4126 diff -NurpP --minimal linux-3.9.4/fs/libfs.c linux-3.9.4-vs2.3.6.2/fs/libfs.c
4127 --- linux-3.9.4/fs/libfs.c      2013-02-19 13:58:48.000000000 +0000
4128 +++ linux-3.9.4-vs2.3.6.2/fs/libfs.c    2013-05-31 14:47:11.000000000 +0000
4129 @@ -135,7 +135,8 @@ static inline unsigned char dt_type(stru
4130   * both impossible due to the lock on directory.
4131   */
4132  
4133 -int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
4134 +static inline int do_dcache_readdir_filter(struct file *filp,
4135 +       void *dirent, filldir_t filldir, int (*filter)(struct dentry *dentry))
4136  {
4137         struct dentry *dentry = filp->f_path.dentry;
4138         struct dentry *cursor = filp->private_data;
4139 @@ -166,6 +167,8 @@ int dcache_readdir(struct file * filp, v
4140                         for (p=q->next; p != &dentry->d_subdirs; p=p->next) {
4141                                 struct dentry *next;
4142                                 next = list_entry(p, struct dentry, d_u.d_child);
4143 +                               if (filter && !filter(next))
4144 +                                       continue;
4145                                 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
4146                                 if (!simple_positive(next)) {
4147                                         spin_unlock(&next->d_lock);
4148 @@ -192,6 +195,17 @@ int dcache_readdir(struct file * filp, v
4149         return 0;
4150  }
4151  
4152 +int dcache_readdir(struct file *filp, void *dirent, filldir_t filldir)
4153 +{
4154 +       return do_dcache_readdir_filter(filp, dirent, filldir, NULL);
4155 +}
4156 +
4157 +int dcache_readdir_filter(struct file *filp, void *dirent, filldir_t filldir,
4158 +       int (*filter)(struct dentry *))
4159 +{
4160 +       return do_dcache_readdir_filter(filp, dirent, filldir, filter);
4161 +}
4162 +
4163  ssize_t generic_read_dir(struct file *filp, char __user *buf, size_t siz, loff_t *ppos)
4164  {
4165         return -EISDIR;
4166 @@ -981,6 +995,7 @@ EXPORT_SYMBOL(dcache_dir_close);
4167  EXPORT_SYMBOL(dcache_dir_lseek);
4168  EXPORT_SYMBOL(dcache_dir_open);
4169  EXPORT_SYMBOL(dcache_readdir);
4170 +EXPORT_SYMBOL(dcache_readdir_filter);
4171  EXPORT_SYMBOL(generic_read_dir);
4172  EXPORT_SYMBOL(mount_pseudo);
4173  EXPORT_SYMBOL(simple_write_begin);
4174 diff -NurpP --minimal linux-3.9.4/fs/locks.c linux-3.9.4-vs2.3.6.2/fs/locks.c
4175 --- linux-3.9.4/fs/locks.c      2013-05-31 13:45:24.000000000 +0000
4176 +++ linux-3.9.4-vs2.3.6.2/fs/locks.c    2013-05-31 15:53:57.000000000 +0000
4177 @@ -126,6 +126,8 @@
4178  #include <linux/time.h>
4179  #include <linux/rcupdate.h>
4180  #include <linux/pid_namespace.h>
4181 +#include <linux/vs_base.h>
4182 +#include <linux/vs_limit.h>
4183  
4184  #include <asm/uaccess.h>
4185  
4186 @@ -184,11 +186,17 @@ static void locks_init_lock_heads(struct
4187  /* Allocate an empty lock structure. */
4188  struct file_lock *locks_alloc_lock(void)
4189  {
4190 -       struct file_lock *fl = kmem_cache_zalloc(filelock_cache, GFP_KERNEL);
4191 +       struct file_lock *fl;
4192  
4193 -       if (fl)
4194 -               locks_init_lock_heads(fl);
4195 +       if (!vx_locks_avail(1))
4196 +               return NULL;
4197  
4198 +       fl = kmem_cache_zalloc(filelock_cache, GFP_KERNEL);
4199 +
4200 +       if (fl) {
4201 +               locks_init_lock_heads(fl);
4202 +               fl->fl_xid = -1;
4203 +       }
4204         return fl;
4205  }
4206  EXPORT_SYMBOL_GPL(locks_alloc_lock);
4207 @@ -212,6 +220,7 @@ void locks_free_lock(struct file_lock *f
4208         BUG_ON(!list_empty(&fl->fl_block));
4209         BUG_ON(!list_empty(&fl->fl_link));
4210  
4211 +       vx_locks_dec(fl);
4212         locks_release_private(fl);
4213         kmem_cache_free(filelock_cache, fl);
4214  }
4215 @@ -221,6 +230,7 @@ void locks_init_lock(struct file_lock *f
4216  {
4217         memset(fl, 0, sizeof(struct file_lock));
4218         locks_init_lock_heads(fl);
4219 +       fl->fl_xid = -1;
4220  }
4221  
4222  EXPORT_SYMBOL(locks_init_lock);
4223 @@ -261,6 +271,7 @@ void locks_copy_lock(struct file_lock *n
4224         new->fl_file = fl->fl_file;
4225         new->fl_ops = fl->fl_ops;
4226         new->fl_lmops = fl->fl_lmops;
4227 +       new->fl_xid = fl->fl_xid;
4228  
4229         locks_copy_private(new, fl);
4230  }
4231 @@ -299,6 +310,11 @@ static int flock_make_lock(struct file *
4232         fl->fl_flags = FL_FLOCK;
4233         fl->fl_type = type;
4234         fl->fl_end = OFFSET_MAX;
4235 +
4236 +       vxd_assert(filp->f_xid == vx_current_xid(),
4237 +               "f_xid(%d) == current(%d)", filp->f_xid, vx_current_xid());
4238 +       fl->fl_xid = filp->f_xid;
4239 +       vx_locks_inc(fl);
4240         
4241         *lock = fl;
4242         return 0;
4243 @@ -438,6 +454,7 @@ static int lease_init(struct file *filp,
4244  
4245         fl->fl_owner = current->files;
4246         fl->fl_pid = current->tgid;
4247 +       fl->fl_xid = vx_current_xid();
4248  
4249         fl->fl_file = filp;
4250         fl->fl_flags = FL_LEASE;
4251 @@ -457,6 +474,11 @@ static struct file_lock *lease_alloc(str
4252         if (fl == NULL)
4253                 return ERR_PTR(error);
4254  
4255 +       fl->fl_xid = vx_current_xid();
4256 +       if (filp)
4257 +               vxd_assert(filp->f_xid == fl->fl_xid,
4258 +                       "f_xid(%d) == fl_xid(%d)", filp->f_xid, fl->fl_xid);
4259 +       vx_locks_inc(fl);
4260         error = lease_init(filp, type, fl);
4261         if (error) {
4262                 locks_free_lock(fl);
4263 @@ -753,6 +775,7 @@ static int flock_lock_file(struct file *
4264                 lock_flocks();
4265         }
4266  
4267 +       new_fl->fl_xid = -1;
4268  find_conflict:
4269         for_each_lock(inode, before) {
4270                 struct file_lock *fl = *before;
4271 @@ -773,6 +796,7 @@ find_conflict:
4272                 goto out;
4273         locks_copy_lock(new_fl, request);
4274         locks_insert_lock(before, new_fl);
4275 +       vx_locks_inc(new_fl);
4276         new_fl = NULL;
4277         error = 0;
4278  
4279 @@ -783,7 +807,8 @@ out:
4280         return error;
4281  }
4282  
4283 -static int __posix_lock_file(struct inode *inode, struct file_lock *request, struct file_lock *conflock)
4284 +static int __posix_lock_file(struct inode *inode, struct file_lock *request,
4285 +       struct file_lock *conflock, xid_t xid)
4286  {
4287         struct file_lock *fl;
4288         struct file_lock *new_fl = NULL;
4289 @@ -793,6 +818,8 @@ static int __posix_lock_file(struct inod
4290         struct file_lock **before;
4291         int error, added = 0;
4292  
4293 +       vxd_assert(xid == vx_current_xid(),
4294 +               "xid(%d) == current(%d)", xid, vx_current_xid());
4295         /*
4296          * We may need two file_lock structures for this operation,
4297          * so we get them in advance to avoid races.
4298 @@ -803,7 +830,11 @@ static int __posix_lock_file(struct inod
4299             (request->fl_type != F_UNLCK ||
4300              request->fl_start != 0 || request->fl_end != OFFSET_MAX)) {
4301                 new_fl = locks_alloc_lock();
4302 +               new_fl->fl_xid = xid;
4303 +               vx_locks_inc(new_fl);
4304                 new_fl2 = locks_alloc_lock();
4305 +               new_fl2->fl_xid = xid;
4306 +               vx_locks_inc(new_fl2);
4307         }
4308  
4309         lock_flocks();
4310 @@ -1002,7 +1033,8 @@ static int __posix_lock_file(struct inod
4311  int posix_lock_file(struct file *filp, struct file_lock *fl,
4312                         struct file_lock *conflock)
4313  {
4314 -       return __posix_lock_file(file_inode(filp), fl, conflock);
4315 +       return __posix_lock_file(file_inode(filp),
4316 +               fl, conflock, filp->f_xid);
4317  }
4318  EXPORT_SYMBOL(posix_lock_file);
4319  
4320 @@ -1092,7 +1124,7 @@ int locks_mandatory_area(int read_write,
4321         fl.fl_end = offset + count - 1;
4322  
4323         for (;;) {
4324 -               error = __posix_lock_file(inode, &fl, NULL);
4325 +               error = __posix_lock_file(inode, &fl, NULL, filp->f_xid);
4326                 if (error != FILE_LOCK_DEFERRED)
4327                         break;
4328                 error = wait_event_interruptible(fl.fl_wait, !fl.fl_next);
4329 @@ -1397,6 +1429,7 @@ int generic_add_lease(struct file *filp,
4330                 goto out;
4331  
4332         locks_insert_lock(before, lease);
4333 +       vx_locks_inc(lease);
4334         return 0;
4335  
4336  out:
4337 @@ -1836,6 +1869,11 @@ int fcntl_setlk(unsigned int fd, struct
4338         if (file_lock == NULL)
4339                 return -ENOLCK;
4340  
4341 +       vxd_assert(filp->f_xid == vx_current_xid(),
4342 +               "f_xid(%d) == current(%d)", filp->f_xid, vx_current_xid());
4343 +       file_lock->fl_xid = filp->f_xid;
4344 +       vx_locks_inc(file_lock);
4345 +
4346         /*
4347          * This might block, so we do it before checking the inode.
4348          */
4349 @@ -1954,6 +1992,11 @@ int fcntl_setlk64(unsigned int fd, struc
4350         if (file_lock == NULL)
4351                 return -ENOLCK;
4352  
4353 +       vxd_assert(filp->f_xid == vx_current_xid(),
4354 +               "f_xid(%d) == current(%d)", filp->f_xid, vx_current_xid());
4355 +       file_lock->fl_xid = filp->f_xid;
4356 +       vx_locks_inc(file_lock);
4357 +
4358         /*
4359          * This might block, so we do it before checking the inode.
4360          */
4361 @@ -2219,8 +2262,11 @@ static int locks_show(struct seq_file *f
4362  
4363         lock_get_status(f, fl, *((loff_t *)f->private), "");
4364  
4365 -       list_for_each_entry(bfl, &fl->fl_block, fl_block)
4366 +       list_for_each_entry(bfl, &fl->fl_block, fl_block) {
4367 +               if (!vx_check(fl->fl_xid, VS_WATCH_P | VS_IDENT))
4368 +                       continue;
4369                 lock_get_status(f, bfl, *((loff_t *)f->private), " ->");
4370 +       }
4371  
4372         return 0;
4373  }
4374 diff -NurpP --minimal linux-3.9.4/fs/mount.h linux-3.9.4-vs2.3.6.2/fs/mount.h
4375 --- linux-3.9.4/fs/mount.h      2013-02-19 13:58:48.000000000 +0000
4376 +++ linux-3.9.4-vs2.3.6.2/fs/mount.h    2013-05-31 14:47:11.000000000 +0000
4377 @@ -49,6 +49,7 @@ struct mount {
4378         int mnt_expiry_mark;            /* true if marked for expiry */
4379         int mnt_pinned;
4380         int mnt_ghosts;
4381 +       tag_t mnt_tag;                  /* tagging used for vfsmount */
4382  };
4383  
4384  #define MNT_NS_INTERNAL ERR_PTR(-EINVAL) /* distinct from any mnt_namespace */
4385 diff -NurpP --minimal linux-3.9.4/fs/namei.c linux-3.9.4-vs2.3.6.2/fs/namei.c
4386 --- linux-3.9.4/fs/namei.c      2013-05-31 14:22:27.000000000 +0000
4387 +++ linux-3.9.4-vs2.3.6.2/fs/namei.c    2013-06-01 09:00:16.000000000 +0000
4388 @@ -34,6 +34,14 @@
4389  #include <linux/device_cgroup.h>
4390  #include <linux/fs_struct.h>
4391  #include <linux/posix_acl.h>
4392 +#include <linux/proc_fs.h>
4393 +#include <linux/vserver/inode.h>
4394 +#include <linux/vs_base.h>
4395 +#include <linux/vs_tag.h>
4396 +#include <linux/vs_cowbl.h>
4397 +#include <linux/vs_device.h>
4398 +#include <linux/vs_context.h>
4399 +#include <linux/pid_namespace.h>
4400  #include <asm/uaccess.h>
4401  
4402  #include "internal.h"
4403 @@ -266,6 +274,89 @@ static int check_acl(struct inode *inode
4404         return -EAGAIN;
4405  }
4406  
4407 +static inline int dx_barrier(const struct inode *inode)
4408 +{
4409 +       if (IS_BARRIER(inode) && !vx_check(0, VS_ADMIN | VS_WATCH)) {
4410 +               vxwprintk_task(1, "did hit the barrier.");
4411 +               return 1;
4412 +       }
4413 +       return 0;
4414 +}
4415 +
4416 +static int __dx_permission(const struct inode *inode, int mask)
4417 +{
4418 +       if (dx_barrier(inode))
4419 +               return -EACCES;
4420 +
4421 +       if (inode->i_sb->s_magic == DEVPTS_SUPER_MAGIC) {
4422 +               /* devpts is xid tagged */
4423 +               if (S_ISDIR(inode->i_mode) ||
4424 +                   vx_check((xid_t)i_tag_read(inode), VS_IDENT | VS_WATCH_P))
4425 +                       return 0;
4426 +
4427 +               /* just pretend we didn't find anything */
4428 +               return -ENOENT;
4429 +       }
4430 +       else if (inode->i_sb->s_magic == PROC_SUPER_MAGIC) {
4431 +               struct proc_dir_entry *de = PDE(inode);
4432 +
4433 +               if (de && !vx_hide_check(0, de->vx_flags))
4434 +                       goto out;
4435 +
4436 +               if ((mask & (MAY_WRITE | MAY_APPEND))) {
4437 +                       struct pid *pid;
4438 +                       struct task_struct *tsk;
4439 +
4440 +                       if (vx_check(0, VS_ADMIN | VS_WATCH_P) ||
4441 +                           vx_flags(VXF_STATE_SETUP, 0))
4442 +                               return 0;
4443 +
4444 +                       pid = PROC_I(inode)->pid;
4445 +                       if (!pid)
4446 +                               goto out;
4447 +
4448 +                       rcu_read_lock();
4449 +                       tsk = pid_task(pid, PIDTYPE_PID);
4450 +                       vxdprintk(VXD_CBIT(tag, 0), "accessing %p[#%u]",
4451 +                                 tsk, (tsk ? vx_task_xid(tsk) : 0));
4452 +                       if (tsk &&
4453 +                               vx_check(vx_task_xid(tsk), VS_IDENT | VS_WATCH_P)) {
4454 +                               rcu_read_unlock();
4455 +                               return 0;
4456 +                       }
4457 +                       rcu_read_unlock();
4458 +               }
4459 +               else {
4460 +                       /* FIXME: Should we block some entries here? */
4461 +                       return 0;
4462 +               }
4463 +       }
4464 +       else {
4465 +               if (dx_notagcheck(inode->i_sb) ||
4466 +                   dx_check((xid_t)i_tag_read(inode),
4467 +                       DX_HOSTID | DX_ADMIN | DX_WATCH | DX_IDENT))
4468 +                       return 0;
4469 +       }
4470 +
4471 +out:
4472 +       return -EACCES;
4473 +}
4474 +
4475 +int dx_permission(const struct inode *inode, int mask)
4476 +{
4477 +       int ret = __dx_permission(inode, mask);
4478 +       if (unlikely(ret)) {
4479 +#ifndef        CONFIG_VSERVER_WARN_DEVPTS
4480 +               if (inode->i_sb->s_magic != DEVPTS_SUPER_MAGIC)
4481 +#endif
4482 +                   vxwprintk_task(1,
4483 +                       "denied [0x%x] access to inode %s:%p[#%d,%lu]",
4484 +                       mask, inode->i_sb->s_id, inode,
4485 +                       i_tag_read(inode), inode->i_ino);
4486 +       }
4487 +       return ret;
4488 +}
4489 +
4490  /*
4491   * This does the basic permission checking
4492   */
4493 @@ -388,10 +479,14 @@ int __inode_permission(struct inode *ino
4494                 /*
4495                  * Nobody gets write access to an immutable file.
4496                  */
4497 -               if (IS_IMMUTABLE(inode))
4498 +               if (IS_IMMUTABLE(inode) && !IS_COW(inode))
4499                         return -EACCES;
4500         }
4501  
4502 +       retval = dx_permission(inode, mask);
4503 +       if (retval)
4504 +               return retval;
4505 +
4506         retval = do_inode_permission(inode, mask);
4507         if (retval)
4508                 return retval;
4509 @@ -1238,7 +1333,8 @@ static void follow_dotdot(struct nameida
4510  
4511                 if (nd->path.dentry == nd->root.dentry &&
4512                     nd->path.mnt == nd->root.mnt) {
4513 -                       break;
4514 +                       /* for sane '/' avoid follow_mount() */
4515 +                       return;
4516                 }
4517                 if (nd->path.dentry != nd->path.mnt->mnt_root) {
4518                         /* rare case of legitimate dget_parent()... */
4519 @@ -1383,6 +1479,9 @@ static int lookup_fast(struct nameidata
4520                                 goto unlazy;
4521                         }
4522                 }
4523 +
4524 +               /* FIXME: check dx permission */
4525 +
4526                 path->mnt = mnt;
4527                 path->dentry = dentry;
4528                 if (unlikely(!__follow_mount_rcu(nd, path, inode)))
4529 @@ -1413,6 +1512,8 @@ unlazy:
4530                 }
4531         }
4532  
4533 +       /* FIXME: check dx permission */
4534 +
4535         path->mnt = mnt;
4536         path->dentry = dentry;
4537         err = follow_managed(path, nd->flags);
4538 @@ -2237,7 +2338,7 @@ static int may_delete(struct inode *dir,
4539         if (IS_APPEND(dir))
4540                 return -EPERM;
4541         if (check_sticky(dir, victim->d_inode)||IS_APPEND(victim->d_inode)||
4542 -           IS_IMMUTABLE(victim->d_inode) || IS_SWAPFILE(victim->d_inode))
4543 +               IS_IXORUNLINK(victim->d_inode) || IS_SWAPFILE(victim->d_inode))
4544                 return -EPERM;
4545         if (isdir) {
4546                 if (!S_ISDIR(victim->d_inode->i_mode))
4547 @@ -2316,19 +2417,25 @@ int vfs_create(struct inode *dir, struct
4548                 bool want_excl)
4549  {
4550         int error = may_create(dir, dentry);
4551 -       if (error)
4552 +       if (error) {
4553 +               vxdprintk(VXD_CBIT(misc, 3), "may_create failed with %d", error);
4554                 return error;
4555 +       }
4556  
4557         if (!dir->i_op->create)
4558                 return -EACCES; /* shouldn't it be ENOSYS? */
4559         mode &= S_IALLUGO;
4560         mode |= S_IFREG;
4561         error = security_inode_create(dir, dentry, mode);
4562 -       if (error)
4563 +       if (error) {
4564 +               vxdprintk(VXD_CBIT(misc, 3), "security_inode_create failed with %d", error);
4565                 return error;
4566 +       }
4567         error = dir->i_op->create(dir, dentry, mode, want_excl);
4568         if (!error)
4569                 fsnotify_create(dir, dentry);
4570 +       else
4571 +               vxdprintk(VXD_CBIT(misc, 3), "i_op->create failed with %d", error);
4572         return error;
4573  }
4574  
4575 @@ -2363,6 +2470,15 @@ static int may_open(struct path *path, i
4576                 break;
4577         }
4578  
4579 +#ifdef CONFIG_VSERVER_COWBL
4580 +       if (IS_COW(inode) &&
4581 +               ((flag & O_ACCMODE) != O_RDONLY)) {
4582 +               if (IS_COW_LINK(inode))
4583 +                       return -EMLINK;
4584 +               inode->i_flags &= ~(S_IXUNLINK|S_IMMUTABLE);
4585 +               mark_inode_dirty(inode);
4586 +       }
4587 +#endif
4588         error = inode_permission(inode, acc_mode);
4589         if (error)
4590                 return error;
4591 @@ -2865,6 +2981,16 @@ finish_open:
4592         }
4593  finish_open_created:
4594         error = may_open(&nd->path, acc_mode, open_flag);
4595 +#ifdef CONFIG_VSERVER_COWBL
4596 +       if (error == -EMLINK) {
4597 +               struct dentry *dentry;
4598 +               dentry = cow_break_link(name->name);
4599 +               if (IS_ERR(dentry))
4600 +                       error = PTR_ERR(dentry);
4601 +               else
4602 +                       dput(dentry);
4603 +       }
4604 +#endif
4605         if (error)
4606                 goto out;
4607         file->f_path.mnt = nd->path.mnt;
4608 @@ -2929,6 +3055,7 @@ static struct file *path_openat(int dfd,
4609         int opened = 0;
4610         int error;
4611  
4612 +restart:
4613         file = get_empty_filp();
4614         if (IS_ERR(file))
4615                 return file;
4616 @@ -2965,6 +3092,16 @@ static struct file *path_openat(int dfd,
4617                 error = do_last(nd, &path, file, op, &opened, pathname);
4618                 put_link(nd, &link, cookie);
4619         }
4620 +
4621 +#ifdef CONFIG_VSERVER_COWBL
4622 +       if (error == -EMLINK) {
4623 +               if (nd->root.mnt && !(nd->flags & LOOKUP_ROOT))
4624 +                       path_put(&nd->root);
4625 +               if (base)
4626 +                       fput(base);
4627 +               goto restart;
4628 +       }
4629 +#endif
4630  out:
4631         if (nd->root.mnt && !(nd->flags & LOOKUP_ROOT))
4632                 path_put(&nd->root);
4633 @@ -3079,6 +3216,11 @@ struct dentry *kern_path_create(int dfd,
4634                 goto fail;
4635         }
4636         *path = nd.path;
4637 +       vxdprintk(VXD_CBIT(misc, 3), "kern_path_create path.dentry = %p (%.*s), dentry = %p (%.*s), d_inode = %p",
4638 +               path->dentry, path->dentry->d_name.len,
4639 +               path->dentry->d_name.name, dentry,
4640 +               dentry->d_name.len, dentry->d_name.name,
4641 +               path->dentry->d_inode);
4642         return dentry;
4643  fail:
4644         dput(dentry);
4645 @@ -3573,7 +3715,7 @@ int vfs_link(struct dentry *old_dentry,
4646         /*
4647          * A link to an append-only or immutable file cannot be created.
4648          */
4649 -       if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
4650 +       if (IS_APPEND(inode) || IS_IXORUNLINK(inode))
4651                 return -EPERM;
4652         if (!dir->i_op->link)
4653                 return -EPERM;
4654 @@ -3976,6 +4118,286 @@ int vfs_follow_link(struct nameidata *nd
4655         return __vfs_follow_link(nd, link);
4656  }
4657  
4658 +
4659 +#ifdef CONFIG_VSERVER_COWBL
4660 +
4661 +static inline
4662 +long do_cow_splice(struct file *in, struct file *out, size_t len)
4663 +{
4664 +       loff_t ppos = 0;
4665 +
4666 +       return do_splice_direct(in, &ppos, out, len, 0);
4667 +}
4668 +
4669 +struct dentry *cow_break_link(const char *pathname)
4670 +{
4671 +       int ret, mode, pathlen, redo = 0, drop = 1;
4672 +       struct nameidata old_nd, dir_nd;
4673 +       struct path dir_path, *old_path, *new_path;
4674 +       struct dentry *dir, *old_dentry, *new_dentry = NULL;
4675 +       struct file *old_file;
4676 +       struct file *new_file;
4677 +       char *to, *path, pad='\251';
4678 +       loff_t size;
4679 +
4680 +       vxdprintk(VXD_CBIT(misc, 1),
4681 +               "cow_break_link(" VS_Q("%s") ")", pathname);
4682 +
4683 +       path = kmalloc(PATH_MAX, GFP_KERNEL);
4684 +       ret = -ENOMEM;
4685 +       if (!path)
4686 +               goto out;
4687 +
4688 +       /* old_nd.path will have refs to dentry and mnt */
4689 +       ret = do_path_lookup(AT_FDCWD, pathname, LOOKUP_FOLLOW, &old_nd);
4690 +       vxdprintk(VXD_CBIT(misc, 2),
4691 +               "do_path_lookup(old): %d", ret);
4692 +       if (ret < 0)
4693 +               goto out_free_path;
4694 +
4695 +       /* dentry/mnt refs handed over to old_path */
4696 +       old_path = &old_nd.path;
4697 +       /* no explicit reference for old_dentry here */
4698 +       old_dentry = old_path->dentry;
4699 +
4700 +       mode = old_dentry->d_inode->i_mode;
4701 +       to = d_path(old_path, path, PATH_MAX-2);
4702 +       pathlen = strlen(to);
4703 +       vxdprintk(VXD_CBIT(misc, 2),
4704 +               "old path " VS_Q("%s") " [%p:" VS_Q("%.*s") ":%d]", to,
4705 +               old_dentry,
4706 +               old_dentry->d_name.len, old_dentry->d_name.name,
4707 +               old_dentry->d_name.len);
4708 +
4709 +       to[pathlen + 1] = 0;
4710 +retry:
4711 +       new_dentry = NULL;
4712 +       to[pathlen] = pad--;
4713 +       ret = -ELOOP;
4714 +       if (pad <= '\240')
4715 +               goto out_rel_old;
4716 +
4717 +       vxdprintk(VXD_CBIT(misc, 1), "temp copy " VS_Q("%s"), to);
4718 +
4719 +       /* dir_nd.path will have refs to dentry and mnt */
4720 +       ret = do_path_lookup(AT_FDCWD, to,
4721 +               LOOKUP_PARENT | LOOKUP_OPEN | LOOKUP_CREATE, &dir_nd);
4722 +       vxdprintk(VXD_CBIT(misc, 2), "do_path_lookup(new): %d", ret);
4723 +       if (ret < 0)
4724 +               goto retry;
4725 +
4726 +       /* this puppy downs the dir inode mutex if successful.
4727 +          dir_path will hold refs to dentry and mnt and
4728 +          we'll have write access to the mnt */
4729 +       new_dentry = kern_path_create(AT_FDCWD, to, &dir_path, 0);
4730 +       if (!new_dentry || IS_ERR(new_dentry)) {
4731 +               path_put(&dir_nd.path);
4732 +               vxdprintk(VXD_CBIT(misc, 2),
4733 +                       "kern_path_create(new) failed with %ld",
4734 +                       PTR_ERR(new_dentry));
4735 +               goto retry;
4736 +       }
4737 +       vxdprintk(VXD_CBIT(misc, 2),
4738 +               "kern_path_create(new): %p [" VS_Q("%.*s") ":%d]",
4739 +               new_dentry,
4740 +               new_dentry->d_name.len, new_dentry->d_name.name,
4741 +               new_dentry->d_name.len);
4742 +
4743 +       /* take a reference on new_dentry */
4744 +       dget(new_dentry);
4745 +
4746 +       /* dentry/mnt refs handed over to new_path */
4747 +       new_path = &dir_path;
4748 +
4749 +       /* dentry for old/new dir */
4750 +       dir = dir_nd.path.dentry;
4751 +
4752 +       /* give up reference on dir */
4753 +       dput(new_path->dentry);
4754 +
4755 +       /* new_dentry already has a reference */
4756 +       new_path->dentry = new_dentry;
4757 +
4758 +       ret = vfs_create(dir->d_inode, new_dentry, mode, 1);
4759 +       vxdprintk(VXD_CBIT(misc, 2),
4760 +               "vfs_create(new): %d", ret);
4761 +       if (ret == -EEXIST) {
4762 +               path_put(&dir_nd.path);
4763 +               mutex_unlock(&dir->d_inode->i_mutex);
4764 +               mnt_drop_write(new_path->mnt);
4765 +               path_put(new_path);
4766 +               new_dentry = NULL;
4767 +               goto retry;
4768 +       }
4769 +       else if (ret < 0)
4770 +               goto out_unlock_new;
4771 +
4772 +       /* drop out early, ret passes ENOENT */
4773 +       ret = -ENOENT;
4774 +       if ((redo = d_unhashed(old_dentry)))
4775 +               goto out_unlock_new;
4776 +
4777 +       /* doesn't change refs for old_path */
4778 +       old_file = dentry_open(old_path, O_RDONLY, current_cred());
4779 +       vxdprintk(VXD_CBIT(misc, 2),
4780 +               "dentry_open(old): %p", old_file);
4781 +       if (IS_ERR(old_file)) {
4782 +               ret = PTR_ERR(old_file);
4783 +               goto out_unlock_new;
4784 +       }
4785 +
4786 +       /* doesn't change refs for new_path */
4787 +       new_file = dentry_open(new_path, O_WRONLY, current_cred());
4788 +       vxdprintk(VXD_CBIT(misc, 2),
4789 +               "dentry_open(new): %p", new_file);
4790 +       if (IS_ERR(new_file)) {
4791 +               ret = PTR_ERR(new_file);
4792 +               goto out_fput_old;
4793 +       }
4794 +
4795 +       /* unlock the inode mutex from kern_path_create() */
4796 +       mutex_unlock(&dir->d_inode->i_mutex);
4797 +
4798 +       /* drop write access to mnt */
4799 +       mnt_drop_write(new_path->mnt);
4800 +
4801 +       drop = 0;
4802 +
4803 +       size = i_size_read(old_file->f_dentry->d_inode);
4804 +       ret = do_cow_splice(old_file, new_file, size);
4805 +       vxdprintk(VXD_CBIT(misc, 2), "do_splice_direct: %d", ret);
4806 +       if (ret < 0) {
4807 +               goto out_fput_both;
4808 +       } else if (ret < size) {
4809 +               ret = -ENOSPC;
4810 +               goto out_fput_both;
4811 +       } else {
4812 +               struct inode *old_inode = old_dentry->d_inode;
4813 +               struct inode *new_inode = new_dentry->d_inode;
4814 +               struct iattr attr = {
4815 +                       .ia_uid = old_inode->i_uid,
4816 +                       .ia_gid = old_inode->i_gid,
4817 +                       .ia_valid = ATTR_UID | ATTR_GID
4818 +                       };
4819 +
4820 +               setattr_copy(new_inode, &attr);
4821 +               mark_inode_dirty(new_inode);
4822 +       }
4823 +
4824 +       /* lock rename mutex */
4825 +       mutex_lock(&old_dentry->d_inode->i_sb->s_vfs_rename_mutex);
4826 +
4827 +       /* drop out late */
4828 +       ret = -ENOENT;
4829 +       if ((redo = d_unhashed(old_dentry)))
4830 +               goto out_unlock;
4831 +
4832 +       vxdprintk(VXD_CBIT(misc, 2),
4833 +               "vfs_rename: [" VS_Q("%*s") ":%d] -> [" VS_Q("%*s") ":%d]",
4834 +               new_dentry->d_name.len, new_dentry->d_name.name,
4835 +               new_dentry->d_name.len,
4836 +               old_dentry->d_name.len, old_dentry->d_name.name,
4837 +               old_dentry->d_name.len);
4838 +       ret = vfs_rename(dir_nd.path.dentry->d_inode, new_dentry,
4839 +               old_dentry->d_parent->d_inode, old_dentry);
4840 +       vxdprintk(VXD_CBIT(misc, 2), "vfs_rename: %d", ret);
4841 +
4842 +out_unlock:
4843 +       mutex_unlock(&old_dentry->d_inode->i_sb->s_vfs_rename_mutex);
4844 +
4845 +out_fput_both:
4846 +       vxdprintk(VXD_CBIT(misc, 3),
4847 +               "fput(new_file=%p[#%ld])", new_file,
4848 +               atomic_long_read(&new_file->f_count));
4849 +       fput(new_file);
4850 +
4851 +out_fput_old:
4852 +       vxdprintk(VXD_CBIT(misc, 3),
4853 +               "fput(old_file=%p[#%ld])", old_file,
4854 +               atomic_long_read(&old_file->f_count));
4855 +       fput(old_file);
4856 +
4857 +out_unlock_new:
4858 +       /* drop references from dir_nd.path */
4859 +       path_put(&dir_nd.path);
4860 +
4861 +       if (drop) {
4862 +               /* unlock the inode mutex from kern_path_create() */
4863 +               mutex_unlock(&dir->d_inode->i_mutex);
4864 +
4865 +               /* drop write access to mnt */
4866 +               mnt_drop_write(new_path->mnt);
4867 +       }
4868 +
4869 +       if (!ret)
4870 +               goto out_redo;
4871 +
4872 +       /* error path cleanup */
4873 +       vfs_unlink(dir->d_inode, new_dentry);
4874 +
4875 +out_redo:
4876 +       if (!redo)
4877 +               goto out_rel_both;
4878 +
4879 +       /* lookup dentry once again
4880 +          old_nd.path will be freed as old_path in out_rel_old */
4881 +       ret = do_path_lookup(AT_FDCWD, pathname, LOOKUP_FOLLOW, &old_nd);
4882 +       if (ret)
4883 +               goto out_rel_both;
4884 +
4885 +       /* drop reference on new_dentry */
4886 +       dput(new_dentry);
4887 +       new_dentry = old_path->dentry;
4888 +       dget(new_dentry);
4889 +       vxdprintk(VXD_CBIT(misc, 2),
4890 +               "do_path_lookup(redo): %p [" VS_Q("%.*s") ":%d]",
4891 +               new_dentry,
4892 +               new_dentry->d_name.len, new_dentry->d_name.name,
4893 +               new_dentry->d_name.len);
4894 +
4895 +out_rel_both:
4896 +       if (new_path)
4897 +               path_put(new_path);
4898 +out_rel_old:
4899 +       path_put(old_path);
4900 +out_free_path:
4901 +       kfree(path);
4902 +out:
4903 +       if (ret) {
4904 +               dput(new_dentry);
4905 +               new_dentry = ERR_PTR(ret);
4906 +       }
4907 +       vxdprintk(VXD_CBIT(misc, 3),
4908 +               "cow_break_link returning with %p", new_dentry);
4909 +       return new_dentry;
4910 +}
4911 +
4912 +#endif
4913 +
4914 +int    vx_info_mnt_namespace(struct mnt_namespace *ns, char *buffer)
4915 +{
4916 +       struct path path;
4917 +       struct vfsmount *vmnt;
4918 +       char *pstr, *root;
4919 +       int length = 0;
4920 +
4921 +       pstr = kmalloc(PATH_MAX, GFP_KERNEL);
4922 +       if (!pstr)
4923 +               return 0;
4924 +
4925 +       vmnt = &ns->root->mnt;
4926 +       path.mnt = vmnt;
4927 +       path.dentry = vmnt->mnt_root;
4928 +       root = d_path(&path, pstr, PATH_MAX - 2);
4929 +       length = sprintf(buffer + length,
4930 +               "Namespace:\t%p [#%u]\n"
4931 +               "RootPath:\t%s\n",
4932 +               ns, atomic_read(&ns->count),
4933 +               root);
4934 +       kfree(pstr);
4935 +       return length;
4936 +}
4937 +
4938  /* get the link contents into pagecache */
4939  static char *page_getlink(struct dentry * dentry, struct page **ppage)
4940  {
4941 @@ -4099,3 +4521,4 @@ EXPORT_SYMBOL(vfs_symlink);
4942  EXPORT_SYMBOL(vfs_unlink);
4943  EXPORT_SYMBOL(dentry_unhash);
4944  EXPORT_SYMBOL(generic_readlink);
4945 +EXPORT_SYMBOL(vx_info_mnt_namespace);
4946 diff -NurpP --minimal linux-3.9.4/fs/namespace.c linux-3.9.4-vs2.3.6.2/fs/namespace.c
4947 --- linux-3.9.4/fs/namespace.c  2013-05-31 14:22:27.000000000 +0000
4948 +++ linux-3.9.4-vs2.3.6.2/fs/namespace.c        2013-05-31 18:47:18.000000000 +0000
4949 @@ -22,6 +22,11 @@
4950  #include <linux/fsnotify.h>    /* fsnotify_vfsmount_delete */
4951  #include <linux/uaccess.h>
4952  #include <linux/proc_fs.h>
4953 +#include <linux/vs_base.h>
4954 +#include <linux/vs_context.h>
4955 +#include <linux/vs_tag.h>
4956 +#include <linux/vserver/space.h>
4957 +#include <linux/vserver/global.h>
4958  #include "pnode.h"
4959  #include "internal.h"
4960  
4961 @@ -751,6 +756,10 @@ vfs_kern_mount(struct file_system_type *
4962         if (!type)
4963                 return ERR_PTR(-ENODEV);
4964  
4965 +       if ((type->fs_flags & FS_BINARY_MOUNTDATA) &&
4966 +               !vx_capable(CAP_SYS_ADMIN, VXC_BINARY_MOUNT))
4967 +               return ERR_PTR(-EPERM);
4968 +
4969         mnt = alloc_vfsmnt(name);
4970         if (!mnt)
4971                 return ERR_PTR(-ENOMEM);
4972 @@ -807,6 +816,7 @@ static struct mount *clone_mnt(struct mo
4973         mnt->mnt.mnt_root = dget(root);
4974         mnt->mnt_mountpoint = mnt->mnt.mnt_root;
4975         mnt->mnt_parent = mnt;
4976 +               mnt->mnt_tag = old->mnt_tag;
4977         br_write_lock(&vfsmount_lock);
4978         list_add_tail(&mnt->mnt_instance, &sb->s_mounts);
4979         br_write_unlock(&vfsmount_lock);
4980 @@ -1639,6 +1649,7 @@ static int do_change_type(struct path *p
4981                 if (err)
4982                         goto out_unlock;
4983         }
4984 +       // mnt->mnt_flags = mnt_flags;
4985  
4986         br_write_lock(&vfsmount_lock);
4987         for (m = mnt; m; m = (recurse ? next_mnt(m, mnt) : NULL))
4988 @@ -1654,12 +1665,14 @@ static int do_change_type(struct path *p
4989   * do loopback mount.
4990   */
4991  static int do_loopback(struct path *path, const char *old_name,
4992 -                               int recurse)
4993 +       tag_t tag, unsigned long flags, int mnt_flags)
4994  {
4995         LIST_HEAD(umount_list);
4996         struct path old_path;
4997         struct mount *mnt = NULL, *old;
4998 +       int recurse = flags & MS_REC;
4999         int err;
5000 +
5001         if (!old_name || !*old_name)
5002                 return -EINVAL;
5003         err = kern_path(old_name, LOOKUP_FOLLOW|LOOKUP_AUTOMOUNT, &old_path);
5004 @@ -1733,7 +1746,7 @@ static int change_mount_flags(struct vfs
5005   * on it - tough luck.
5006   */
5007  static int do_remount(struct path *path, int flags, int mnt_flags,
5008 -                     void *data)
5009 +       void *data, xid_t xid)
5010  {
5011         int err;
5012         struct super_block *sb = path->mnt->mnt_sb;
5013 @@ -2046,7 +2059,6 @@ void mark_mounts_for_expiry(struct list_
5014         }
5015         br_write_unlock(&vfsmount_lock);
5016         up_write(&namespace_sem);
5017 -
5018         release_mounts(&umounts);
5019  }
5020  
5021 @@ -2218,6 +2230,7 @@ long do_mount(const char *dev_name, cons
5022         struct path path;
5023         int retval = 0;
5024         int mnt_flags = 0;
5025 +       tag_t tag = 0;
5026  
5027         /* Discard magic */
5028         if ((flags & MS_MGC_MSK) == MS_MGC_VAL)
5029 @@ -2247,6 +2260,12 @@ long do_mount(const char *dev_name, cons
5030         if (!(flags & MS_NOATIME))
5031                 mnt_flags |= MNT_RELATIME;
5032  
5033 +       if (dx_parse_tag(data_page, &tag, 1, &mnt_flags, &flags)) {
5034 +               /* FIXME: bind and re-mounts get the tag flag? */
5035 +               if (flags & (MS_BIND|MS_REMOUNT))
5036 +                       flags |= MS_TAGID;
5037 +       }
5038 +
5039         /* Separate the per-mountpoint flags */
5040         if (flags & MS_NOSUID)
5041                 mnt_flags |= MNT_NOSUID;
5042 @@ -2263,15 +2282,17 @@ long do_mount(const char *dev_name, cons
5043         if (flags & MS_RDONLY)
5044                 mnt_flags |= MNT_READONLY;
5045  
5046 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_DEV_MOUNT))
5047 +               mnt_flags |= MNT_NODEV;
5048         flags &= ~(MS_NOSUID | MS_NOEXEC | MS_NODEV | MS_ACTIVE | MS_BORN |
5049                    MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
5050                    MS_STRICTATIME);
5051  
5052         if (flags & MS_REMOUNT)
5053                 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
5054 -                                   data_page);
5055 +                                   data_page, tag);
5056         else if (flags & MS_BIND)
5057 -               retval = do_loopback(&path, dev_name, flags & MS_REC);
5058 +               retval = do_loopback(&path, dev_name, tag, flags, mnt_flags);
5059         else if (flags & (MS_SHARED | MS_PRIVATE | MS_SLAVE | MS_UNBINDABLE))
5060                 retval = do_change_type(&path, flags);
5061         else if (flags & MS_MOVE)
5062 @@ -2380,6 +2401,7 @@ static struct mnt_namespace *dup_mnt_ns(
5063                 q = next_mnt(q, new);
5064         }
5065         up_write(&namespace_sem);
5066 +       atomic_inc(&vs_global_mnt_ns);
5067  
5068         if (rootmnt)
5069                 mntput(rootmnt);
5070 @@ -2575,9 +2597,10 @@ SYSCALL_DEFINE2(pivot_root, const char _
5071         error = -EINVAL;
5072         new_mnt = real_mount(new.mnt);
5073         root_mnt = real_mount(root.mnt);
5074 -       if (IS_MNT_SHARED(real_mount(old.mnt)) ||
5075 +       if ((IS_MNT_SHARED(real_mount(old.mnt)) ||
5076                 IS_MNT_SHARED(new_mnt->mnt_parent) ||
5077 -               IS_MNT_SHARED(root_mnt->mnt_parent))
5078 +               IS_MNT_SHARED(root_mnt->mnt_parent)) &&
5079 +               !vx_flags(VXF_STATE_SETUP, 0))
5080                 goto out4;
5081         if (!check_mnt(root_mnt) || !check_mnt(new_mnt))
5082                 goto out4;
5083 @@ -2703,6 +2726,7 @@ void put_mnt_ns(struct mnt_namespace *ns
5084         br_write_unlock(&vfsmount_lock);
5085         up_write(&namespace_sem);
5086         release_mounts(&umount_list);
5087 +       atomic_dec(&vs_global_mnt_ns);
5088         free_mnt_ns(ns);
5089  }
5090  
5091 diff -NurpP --minimal linux-3.9.4/fs/nfs/client.c linux-3.9.4-vs2.3.6.2/fs/nfs/client.c
5092 --- linux-3.9.4/fs/nfs/client.c 2013-05-31 13:45:24.000000000 +0000
5093 +++ linux-3.9.4-vs2.3.6.2/fs/nfs/client.c       2013-05-31 14:47:11.000000000 +0000
5094 @@ -682,6 +682,9 @@ int nfs_init_server_rpcclient(struct nfs
5095         if (server->flags & NFS_MOUNT_SOFT)
5096                 server->client->cl_softrtry = 1;
5097  
5098 +       server->client->cl_tag = 0;
5099 +       if (server->flags & NFS_MOUNT_TAGGED)
5100 +               server->client->cl_tag = 1;
5101         return 0;
5102  }
5103  EXPORT_SYMBOL_GPL(nfs_init_server_rpcclient);
5104 @@ -861,6 +864,10 @@ static void nfs_server_set_fsinfo(struct
5105                 server->acdirmin = server->acdirmax = 0;
5106         }
5107  
5108 +       /* FIXME: needs fsinfo
5109 +       if (server->flags & NFS_MOUNT_TAGGED)
5110 +               sb->s_flags |= MS_TAGGED;       */
5111 +
5112         server->maxfilesize = fsinfo->maxfilesize;
5113  
5114         server->time_delta = fsinfo->time_delta;
5115 diff -NurpP --minimal linux-3.9.4/fs/nfs/dir.c linux-3.9.4-vs2.3.6.2/fs/nfs/dir.c
5116 --- linux-3.9.4/fs/nfs/dir.c    2013-05-31 13:45:24.000000000 +0000
5117 +++ linux-3.9.4-vs2.3.6.2/fs/nfs/dir.c  2013-05-31 14:47:11.000000000 +0000
5118 @@ -36,6 +36,7 @@
5119  #include <linux/sched.h>
5120  #include <linux/kmemleak.h>
5121  #include <linux/xattr.h>
5122 +#include <linux/vs_tag.h>
5123  
5124  #include "delegation.h"
5125  #include "iostat.h"
5126 @@ -1300,6 +1301,7 @@ struct dentry *nfs_lookup(struct inode *
5127         /* Success: notify readdir to use READDIRPLUS */
5128         nfs_advise_use_readdirplus(dir);
5129  
5130 +       dx_propagate_tag(nd, inode);
5131  no_entry:
5132         res = d_materialise_unique(dentry, inode);
5133         if (res != NULL) {
5134 diff -NurpP --minimal linux-3.9.4/fs/nfs/inode.c linux-3.9.4-vs2.3.6.2/fs/nfs/inode.c
5135 --- linux-3.9.4/fs/nfs/inode.c  2013-05-31 13:45:24.000000000 +0000
5136 +++ linux-3.9.4-vs2.3.6.2/fs/nfs/inode.c        2013-05-31 20:37:45.000000000 +0000
5137 @@ -39,6 +39,7 @@
5138  #include <linux/compat.h>
5139  #include <linux/freezer.h>
5140  #include <linux/crc32.h>
5141 +#include <linux/vs_tag.h>
5142  
5143  #include <asm/uaccess.h>
5144  
5145 @@ -290,6 +291,8 @@ nfs_fhget(struct super_block *sb, struct
5146         if (inode->i_state & I_NEW) {
5147                 struct nfs_inode *nfsi = NFS_I(inode);
5148                 unsigned long now = jiffies;
5149 +               uid_t uid;
5150 +               gid_t gid;
5151  
5152                 /* We set i_ino for the few things that still rely on it,
5153                  * such as stat(2) */
5154 @@ -334,8 +337,8 @@ nfs_fhget(struct super_block *sb, struct
5155                 inode->i_version = 0;
5156                 inode->i_size = 0;
5157                 clear_nlink(inode);
5158 -               inode->i_uid = make_kuid(&init_user_ns, -2);
5159 -               inode->i_gid = make_kgid(&init_user_ns, -2);
5160 +               uid = make_kuid(&init_user_ns, -2);
5161 +               gid = make_kgid(&init_user_ns, -2);
5162                 inode->i_blocks = 0;
5163                 memset(nfsi->cookieverf, 0, sizeof(nfsi->cookieverf));
5164                 nfsi->write_io = 0;
5165 @@ -369,11 +372,11 @@ nfs_fhget(struct super_block *sb, struct
5166                 else if (nfs_server_capable(inode, NFS_CAP_NLINK))
5167                         nfsi->cache_validity |= NFS_INO_INVALID_ATTR;
5168                 if (fattr->valid & NFS_ATTR_FATTR_OWNER)
5169 -                       inode->i_uid = fattr->uid;
5170 +                       uid = fattr->uid;
5171                 else if (nfs_server_capable(inode, NFS_CAP_OWNER))
5172                         nfsi->cache_validity |= NFS_INO_INVALID_ATTR;
5173                 if (fattr->valid & NFS_ATTR_FATTR_GROUP)
5174 -                       inode->i_gid = fattr->gid;
5175 +                       gid = fattr->gid;
5176                 else if (nfs_server_capable(inode, NFS_CAP_OWNER_GROUP))
5177                         nfsi->cache_validity |= NFS_INO_INVALID_ATTR;
5178                 if (fattr->valid & NFS_ATTR_FATTR_BLOCKS_USED)
5179 @@ -384,6 +387,11 @@ nfs_fhget(struct super_block *sb, struct
5180                          */
5181                         inode->i_blocks = nfs_calc_block_size(fattr->du.nfs3.used);
5182                 }
5183 +               inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
5184 +               inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
5185 +               inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid, 0);
5186 +                               /* maybe fattr->xid someday */
5187 +
5188                 nfsi->attrtimeo = NFS_MINATTRTIMEO(inode);
5189                 nfsi->attrtimeo_timestamp = now;
5190                 nfsi->access_cache = RB_ROOT;
5191 @@ -505,6 +513,8 @@ void nfs_setattr_update_inode(struct ino
5192                         inode->i_uid = attr->ia_uid;
5193                 if ((attr->ia_valid & ATTR_GID) != 0)
5194                         inode->i_gid = attr->ia_gid;
5195 +               if ((attr->ia_valid & ATTR_TAG) && IS_TAGGED(inode))
5196 +                       inode->i_tag = attr->ia_tag;
5197                 NFS_I(inode)->cache_validity |= NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL;
5198                 spin_unlock(&inode->i_lock);
5199         }
5200 @@ -980,6 +990,11 @@ static int nfs_check_inode_attributes(st
5201         struct nfs_inode *nfsi = NFS_I(inode);
5202         loff_t cur_size, new_isize;
5203         unsigned long invalid = 0;
5204 +       kuid_t kuid;
5205 +       kgid_t kgid;
5206 +       ktag_t ktag;
5207 +       uid_t uid;
5208 +       gid_t gid;
5209  
5210  
5211         if (nfs_have_delegated_attributes(inode))
5212 @@ -1005,13 +1020,21 @@ static int nfs_check_inode_attributes(st
5213                         invalid |= NFS_INO_INVALID_ATTR|NFS_INO_REVAL_PAGECACHE;
5214         }
5215  
5216 +       uid = from_kuid(&init_user_ns, fattr->uid);
5217 +       gid = from_kgid(&init_user_ns, fattr->gid);
5218 +
5219 +       kuid = make_kuid(&init_user_ns, INOTAG_UID(DX_TAG(inode), uid, gid));
5220 +       kgid = make_kgid(&init_user_ns, INOTAG_GID(DX_TAG(inode), uid, gid));
5221 +       ktag = make_ktag(&init_user_ns, INOTAG_TAG(DX_TAG(inode), uid, gid, 0));
5222 +
5223         /* Have any file permissions changed? */
5224         if ((fattr->valid & NFS_ATTR_FATTR_MODE) && (inode->i_mode & S_IALLUGO) != (fattr->mode & S_IALLUGO))
5225                 invalid |= NFS_INO_INVALID_ATTR | NFS_INO_INVALID_ACCESS | NFS_INO_INVALID_ACL;
5226 -       if ((fattr->valid & NFS_ATTR_FATTR_OWNER) && !uid_eq(inode->i_uid, fattr->uid))
5227 +       if ((fattr->valid & NFS_ATTR_FATTR_OWNER) && !uid_eq(inode->i_uid, kuid))
5228                 invalid |= NFS_INO_INVALID_ATTR | NFS_INO_INVALID_ACCESS | NFS_INO_INVALID_ACL;
5229 -       if ((fattr->valid & NFS_ATTR_FATTR_GROUP) && !gid_eq(inode->i_gid, fattr->gid))
5230 +       if ((fattr->valid & NFS_ATTR_FATTR_GROUP) && !gid_eq(inode->i_gid, kgid))
5231                 invalid |= NFS_INO_INVALID_ATTR | NFS_INO_INVALID_ACCESS | NFS_INO_INVALID_ACL;
5232 +               /* maybe check for tag too? */
5233  
5234         /* Has the link count changed? */
5235         if ((fattr->valid & NFS_ATTR_FATTR_NLINK) && inode->i_nlink != fattr->nlink)
5236 @@ -1317,6 +1340,9 @@ static int nfs_update_inode(struct inode
5237         unsigned long invalid = 0;
5238         unsigned long now = jiffies;
5239         unsigned long save_cache_validity;
5240 +       uid_t uid;
5241 +       gid_t gid;
5242 +       tag_t tag;
5243  
5244         dfprintk(VFS, "NFS: %s(%s/%ld fh_crc=0x%08x ct=%d info=0x%x)\n",
5245                         __func__, inode->i_sb->s_id, inode->i_ino,
5246 @@ -1418,6 +1444,9 @@ static int nfs_update_inode(struct inode
5247                                 | NFS_INO_REVAL_PAGECACHE
5248                                 | NFS_INO_REVAL_FORCED);
5249  
5250 +       uid = TAGINO_UID(DX_TAG(inode), inode->i_uid, inode->i_tag);
5251 +       gid = TAGINO_GID(DX_TAG(inode), inode->i_gid, inode->i_tag);
5252 +       tag = inode->i_tag;
5253  
5254         if (fattr->valid & NFS_ATTR_FATTR_ATIME)
5255                 memcpy(&inode->i_atime, &fattr->atime, sizeof(inode->i_atime));
5256 @@ -1460,6 +1489,10 @@ static int nfs_update_inode(struct inode
5257                                 | NFS_INO_INVALID_ACL
5258                                 | NFS_INO_REVAL_FORCED);
5259  
5260 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
5261 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
5262 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid, tag);
5263 +
5264         if (fattr->valid & NFS_ATTR_FATTR_NLINK) {
5265                 if (inode->i_nlink != fattr->nlink) {
5266                         invalid |= NFS_INO_INVALID_ATTR;
5267 diff -NurpP --minimal linux-3.9.4/fs/nfs/nfs3xdr.c linux-3.9.4-vs2.3.6.2/fs/nfs/nfs3xdr.c
5268 --- linux-3.9.4/fs/nfs/nfs3xdr.c        2013-05-31 13:45:24.000000000 +0000
5269 +++ linux-3.9.4-vs2.3.6.2/fs/nfs/nfs3xdr.c      2013-05-31 15:33:48.000000000 +0000
5270 @@ -20,6 +20,7 @@
5271  #include <linux/nfs3.h>
5272  #include <linux/nfs_fs.h>
5273  #include <linux/nfsacl.h>
5274 +#include <linux/vs_tag.h>
5275  #include "internal.h"
5276  
5277  #define NFSDBG_FACILITY                NFSDBG_XDR
5278 @@ -558,7 +559,8 @@ static __be32 *xdr_decode_nfstime3(__be3
5279   *             set_mtime       mtime;
5280   *     };
5281   */
5282 -static void encode_sattr3(struct xdr_stream *xdr, const struct iattr *attr)
5283 +static void encode_sattr3(struct xdr_stream *xdr,
5284 +       const struct iattr *attr, int tag)
5285  {
5286         u32 nbytes;
5287         __be32 *p;
5288 @@ -590,15 +592,19 @@ static void encode_sattr3(struct xdr_str
5289         } else
5290                 *p++ = xdr_zero;
5291  
5292 -       if (attr->ia_valid & ATTR_UID) {
5293 +       if (attr->ia_valid & ATTR_UID ||
5294 +               (tag && (attr->ia_valid & ATTR_TAG))) {
5295                 *p++ = xdr_one;
5296 -               *p++ = cpu_to_be32(from_kuid(&init_user_ns, attr->ia_uid));
5297 +               *p++ = cpu_to_be32(TAGINO_UID(tag,
5298 +                       from_kuid(&init_user_ns, attr->ia_uid), attr->ia_tag));
5299         } else
5300                 *p++ = xdr_zero;
5301  
5302 -       if (attr->ia_valid & ATTR_GID) {
5303 +       if (attr->ia_valid & ATTR_GID ||
5304 +               (tag && (attr->ia_valid & ATTR_TAG))) {
5305                 *p++ = xdr_one;
5306 -               *p++ = cpu_to_be32(from_kgid(&init_user_ns, attr->ia_gid));
5307 +               *p++ = cpu_to_be32(TAGINO_GID(tag,
5308 +                       from_kgid(&init_user_ns, attr->ia_gid), attr->ia_tag));
5309         } else
5310                 *p++ = xdr_zero;
5311  
5312 @@ -887,7 +893,7 @@ static void nfs3_xdr_enc_setattr3args(st
5313                                       const struct nfs3_sattrargs *args)
5314  {
5315         encode_nfs_fh3(xdr, args->fh);
5316 -       encode_sattr3(xdr, args->sattr);
5317 +       encode_sattr3(xdr, args->sattr, req->rq_task->tk_client->cl_tag);
5318         encode_sattrguard3(xdr, args);
5319  }
5320  
5321 @@ -1037,13 +1043,13 @@ static void nfs3_xdr_enc_write3args(stru
5322   *     };
5323   */
5324  static void encode_createhow3(struct xdr_stream *xdr,
5325 -                             const struct nfs3_createargs *args)
5326 +       const struct nfs3_createargs *args, int tag)
5327  {
5328         encode_uint32(xdr, args->createmode);
5329         switch (args->createmode) {
5330         case NFS3_CREATE_UNCHECKED:
5331         case NFS3_CREATE_GUARDED:
5332 -               encode_sattr3(xdr, args->sattr);
5333 +               encode_sattr3(xdr, args->sattr, tag);
5334                 break;
5335         case NFS3_CREATE_EXCLUSIVE:
5336                 encode_createverf3(xdr, args->verifier);
5337 @@ -1058,7 +1064,7 @@ static void nfs3_xdr_enc_create3args(str
5338                                      const struct nfs3_createargs *args)
5339  {
5340         encode_diropargs3(xdr, args->fh, args->name, args->len);
5341 -       encode_createhow3(xdr, args);
5342 +       encode_createhow3(xdr, args, req->rq_task->tk_client->cl_tag);
5343  }
5344  
5345  /*
5346 @@ -1074,7 +1080,7 @@ static void nfs3_xdr_enc_mkdir3args(stru
5347                                     const struct nfs3_mkdirargs *args)
5348  {
5349         encode_diropargs3(xdr, args->fh, args->name, args->len);
5350 -       encode_sattr3(xdr, args->sattr);
5351 +       encode_sattr3(xdr, args->sattr, req->rq_task->tk_client->cl_tag);
5352  }
5353  
5354  /*
5355 @@ -1091,9 +1097,9 @@ static void nfs3_xdr_enc_mkdir3args(stru
5356   *     };
5357   */
5358  static void encode_symlinkdata3(struct xdr_stream *xdr,
5359 -                               const struct nfs3_symlinkargs *args)
5360 +       const struct nfs3_symlinkargs *args, int tag)
5361  {
5362 -       encode_sattr3(xdr, args->sattr);
5363 +       encode_sattr3(xdr, args->sattr, tag);
5364         encode_nfspath3(xdr, args->pages, args->pathlen);
5365  }
5366  
5367 @@ -1102,7 +1108,7 @@ static void nfs3_xdr_enc_symlink3args(st
5368                                       const struct nfs3_symlinkargs *args)
5369  {
5370         encode_diropargs3(xdr, args->fromfh, args->fromname, args->fromlen);
5371 -       encode_symlinkdata3(xdr, args);
5372 +       encode_symlinkdata3(xdr, args, req->rq_task->tk_client->cl_tag);
5373  }
5374  
5375  /*
5376 @@ -1130,24 +1136,24 @@ static void nfs3_xdr_enc_symlink3args(st
5377   *     };
5378   */
5379  static void encode_devicedata3(struct xdr_stream *xdr,
5380 -                              const struct nfs3_mknodargs *args)
5381 +       const struct nfs3_mknodargs *args, int tag)
5382  {
5383 -       encode_sattr3(xdr, args->sattr);
5384 +       encode_sattr3(xdr, args->sattr, tag);
5385         encode_specdata3(xdr, args->rdev);
5386  }
5387  
5388  static void encode_mknoddata3(struct xdr_stream *xdr,
5389 -                             const struct nfs3_mknodargs *args)
5390 +       const struct nfs3_mknodargs *args, int tag)
5391  {
5392         encode_ftype3(xdr, args->type);
5393         switch (args->type) {
5394         case NF3CHR:
5395         case NF3BLK:
5396 -               encode_devicedata3(xdr, args);
5397 +               encode_devicedata3(xdr, args, tag);
5398                 break;
5399         case NF3SOCK:
5400         case NF3FIFO:
5401 -               encode_sattr3(xdr, args->sattr);
5402 +               encode_sattr3(xdr, args->sattr, tag);
5403                 break;
5404         case NF3REG:
5405         case NF3DIR:
5406 @@ -1162,7 +1168,7 @@ static void nfs3_xdr_enc_mknod3args(stru
5407                                     const struct nfs3_mknodargs *args)
5408  {
5409         encode_diropargs3(xdr, args->fh, args->name, args->len);
5410 -       encode_mknoddata3(xdr, args);
5411 +       encode_mknoddata3(xdr, args, req->rq_task->tk_client->cl_tag);
5412  }
5413  
5414  /*
5415 diff -NurpP --minimal linux-3.9.4/fs/nfs/super.c linux-3.9.4-vs2.3.6.2/fs/nfs/super.c
5416 --- linux-3.9.4/fs/nfs/super.c  2013-05-31 13:45:24.000000000 +0000
5417 +++ linux-3.9.4-vs2.3.6.2/fs/nfs/super.c        2013-05-31 15:41:34.000000000 +0000
5418 @@ -55,6 +55,7 @@
5419  #include <linux/parser.h>
5420  #include <linux/nsproxy.h>
5421  #include <linux/rcupdate.h>
5422 +#include <linux/vs_tag.h>
5423  
5424  #include <asm/uaccess.h>
5425  
5426 @@ -103,6 +104,7 @@ enum {
5427         Opt_mountport,
5428         Opt_mountvers,
5429         Opt_minorversion,
5430 +       Opt_tagid,
5431  
5432         /* Mount options that take string arguments */
5433         Opt_nfsvers,
5434 @@ -115,6 +117,9 @@ enum {
5435         /* Special mount options */
5436         Opt_userspace, Opt_deprecated, Opt_sloppy,
5437  
5438 +       /* Linux-VServer tagging options */
5439 +       Opt_tag, Opt_notag,
5440 +
5441         Opt_err
5442  };
5443  
5444 @@ -184,6 +189,10 @@ static const match_table_t nfs_mount_opt
5445         { Opt_fscache_uniq, "fsc=%s" },
5446         { Opt_local_lock, "local_lock=%s" },
5447  
5448 +       { Opt_tag, "tag" },
5449 +       { Opt_notag, "notag" },
5450 +       { Opt_tagid, "tagid=%u" },
5451 +
5452         /* The following needs to be listed after all other options */
5453         { Opt_nfsvers, "v%s" },
5454  
5455 @@ -635,6 +644,7 @@ static void nfs_show_mount_options(struc
5456                 { NFS_MOUNT_NORDIRPLUS, ",nordirplus", "" },
5457                 { NFS_MOUNT_UNSHARED, ",nosharecache", "" },
5458                 { NFS_MOUNT_NORESVPORT, ",noresvport", "" },
5459 +               { NFS_MOUNT_TAGGED, ",tag", "" },
5460                 { 0, NULL, NULL }
5461         };
5462         const struct proc_nfs_info *nfs_infop;
5463 @@ -1261,6 +1271,14 @@ static int nfs_parse_mount_options(char
5464                 case Opt_nomigration:
5465                         mnt->options &= NFS_OPTION_MIGRATION;
5466                         break;
5467 +#ifndef CONFIG_TAGGING_NONE
5468 +               case Opt_tag:
5469 +                       mnt->flags |= NFS_MOUNT_TAGGED;
5470 +                       break;
5471 +               case Opt_notag:
5472 +                       mnt->flags &= ~NFS_MOUNT_TAGGED;
5473 +                       break;
5474 +#endif
5475  
5476                 /*
5477                  * options that take numeric values
5478 @@ -1347,6 +1365,12 @@ static int nfs_parse_mount_options(char
5479                                 goto out_invalid_value;
5480                         mnt->minorversion = option;
5481                         break;
5482 +#ifdef CONFIG_PROPAGATE
5483 +               case Opt_tagid:
5484 +                       /* use args[0] */
5485 +                       nfs_data.flags |= NFS_MOUNT_TAGGED;
5486 +                       break;
5487 +#endif
5488  
5489                 /*
5490                  * options that take text values
5491 diff -NurpP --minimal linux-3.9.4/fs/nfsd/auth.c linux-3.9.4-vs2.3.6.2/fs/nfsd/auth.c
5492 --- linux-3.9.4/fs/nfsd/auth.c  2013-05-31 13:45:24.000000000 +0000
5493 +++ linux-3.9.4-vs2.3.6.2/fs/nfsd/auth.c        2013-05-31 14:47:11.000000000 +0000
5494 @@ -2,6 +2,7 @@
5495  
5496  #include <linux/sched.h>
5497  #include <linux/user_namespace.h>
5498 +#include <linux/vs_tag.h>
5499  #include "nfsd.h"
5500  #include "auth.h"
5501  
5502 @@ -37,6 +38,9 @@ int nfsd_setuser(struct svc_rqst *rqstp,
5503  
5504         new->fsuid = rqstp->rq_cred.cr_uid;
5505         new->fsgid = rqstp->rq_cred.cr_gid;
5506 +       /* FIXME: this desperately needs a tag :)
5507 +       new->xid = (xid_t)INOTAG_TAG(DX_TAG_NFSD, cred.cr_uid, cred.cr_gid, 0);
5508 +                       */
5509  
5510         rqgi = rqstp->rq_cred.cr_group_info;
5511  
5512 diff -NurpP --minimal linux-3.9.4/fs/nfsd/nfs3xdr.c linux-3.9.4-vs2.3.6.2/fs/nfsd/nfs3xdr.c
5513 --- linux-3.9.4/fs/nfsd/nfs3xdr.c       2013-05-31 13:45:24.000000000 +0000
5514 +++ linux-3.9.4-vs2.3.6.2/fs/nfsd/nfs3xdr.c     2013-05-31 16:17:38.000000000 +0000
5515 @@ -8,6 +8,7 @@
5516  
5517  #include <linux/namei.h>
5518  #include <linux/sunrpc/svc_xprt.h>
5519 +#include <linux/vs_tag.h>
5520  #include "xdr3.h"
5521  #include "auth.h"
5522  #include "netns.h"
5523 @@ -98,6 +99,8 @@ static __be32 *
5524  decode_sattr3(__be32 *p, struct iattr *iap)
5525  {
5526         u32     tmp;
5527 +       uid_t   uid = 0;
5528 +       gid_t   gid = 0;
5529  
5530         iap->ia_valid = 0;
5531  
5532 @@ -106,15 +109,18 @@ decode_sattr3(__be32 *p, struct iattr *i
5533                 iap->ia_mode = ntohl(*p++);
5534         }
5535         if (*p++) {
5536 -               iap->ia_uid = make_kuid(&init_user_ns, ntohl(*p++));
5537 +               uid = make_kuid(&init_user_ns, ntohl(*p++));
5538                 if (uid_valid(iap->ia_uid))
5539                         iap->ia_valid |= ATTR_UID;
5540         }
5541         if (*p++) {
5542 -               iap->ia_gid = make_kgid(&init_user_ns, ntohl(*p++));
5543 +               gid = make_kgid(&init_user_ns, ntohl(*p++));
5544                 if (gid_valid(iap->ia_gid))
5545                         iap->ia_valid |= ATTR_GID;
5546         }
5547 +       iap->ia_uid = INOTAG_UID(DX_TAG_NFSD, uid, gid);
5548 +       iap->ia_gid = INOTAG_GID(DX_TAG_NFSD, uid, gid);
5549 +       iap->ia_tag = INOTAG_TAG(DX_TAG_NFSD, uid, gid, 0);
5550         if (*p++) {
5551                 u64     newsize;
5552  
5553 @@ -170,8 +176,12 @@ encode_fattr3(struct svc_rqst *rqstp, __
5554         *p++ = htonl(nfs3_ftypes[(stat->mode & S_IFMT) >> 12]);
5555         *p++ = htonl((u32) stat->mode);
5556         *p++ = htonl((u32) stat->nlink);
5557 -       *p++ = htonl((u32) from_kuid(&init_user_ns, stat->uid));
5558 -       *p++ = htonl((u32) from_kgid(&init_user_ns, stat->gid));
5559 +       *p++ = htonl((u32) from_kuid(&init_user_ns,
5560 +               TAGINO_UID(0 /* FIXME: DX_TAG(dentry->d_inode) */,
5561 +               stat->uid, stat->tag)));
5562 +       *p++ = htonl((u32) from_kgid(&init_user_ns,
5563 +               TAGINO_GID(0 /* FIXME: DX_TAG(dentry->d_inode) */,
5564 +               stat->gid, stat->tag)));
5565         if (S_ISLNK(stat->mode) && stat->size > NFS3_MAXPATHLEN) {
5566                 p = xdr_encode_hyper(p, (u64) NFS3_MAXPATHLEN);
5567         } else {
5568 diff -NurpP --minimal linux-3.9.4/fs/nfsd/nfs4xdr.c linux-3.9.4-vs2.3.6.2/fs/nfsd/nfs4xdr.c
5569 --- linux-3.9.4/fs/nfsd/nfs4xdr.c       2013-05-31 14:22:27.000000000 +0000
5570 +++ linux-3.9.4-vs2.3.6.2/fs/nfsd/nfs4xdr.c     2013-05-31 14:47:11.000000000 +0000
5571 @@ -46,6 +46,7 @@
5572  #include <linux/utsname.h>
5573  #include <linux/pagemap.h>
5574  #include <linux/sunrpc/svcauth_gss.h>
5575 +#include <linux/vs_tag.h>
5576  
5577  #include "idmap.h"
5578  #include "acl.h"
5579 @@ -2349,14 +2350,18 @@ out_acl:
5580                 WRITE32(stat.nlink);
5581         }
5582         if (bmval1 & FATTR4_WORD1_OWNER) {
5583 -               status = nfsd4_encode_user(rqstp, stat.uid, &p, &buflen);
5584 +               status = nfsd4_encode_user(rqstp,
5585 +                       TAGINO_UID(DX_TAG(dentry->d_inode),
5586 +                       stat.uid, stat.tag), &p, &buflen);
5587                 if (status == nfserr_resource)
5588                         goto out_resource;
5589                 if (status)
5590                         goto out;
5591         }
5592         if (bmval1 & FATTR4_WORD1_OWNER_GROUP) {
5593 -               status = nfsd4_encode_group(rqstp, stat.gid, &p, &buflen);
5594 +               status = nfsd4_encode_group(rqstp,
5595 +                       TAGINO_GID(DX_TAG(dentry->d_inode),
5596 +                       stat.gid, stat.tag), &p, &buflen);
5597                 if (status == nfserr_resource)
5598                         goto out_resource;
5599                 if (status)
5600 diff -NurpP --minimal linux-3.9.4/fs/nfsd/nfsxdr.c linux-3.9.4-vs2.3.6.2/fs/nfsd/nfsxdr.c
5601 --- linux-3.9.4/fs/nfsd/nfsxdr.c        2013-05-31 13:45:24.000000000 +0000
5602 +++ linux-3.9.4-vs2.3.6.2/fs/nfsd/nfsxdr.c      2013-05-31 16:20:53.000000000 +0000
5603 @@ -7,6 +7,7 @@
5604  #include "vfs.h"
5605  #include "xdr.h"
5606  #include "auth.h"
5607 +#include <linux/vs_tag.h>
5608  
5609  #define NFSDDBG_FACILITY               NFSDDBG_XDR
5610  
5611 @@ -89,6 +90,8 @@ static __be32 *
5612  decode_sattr(__be32 *p, struct iattr *iap)
5613  {
5614         u32     tmp, tmp1;
5615 +       uid_t   uid = 0;
5616 +       gid_t   gid = 0;
5617  
5618         iap->ia_valid = 0;
5619  
5620 @@ -101,15 +104,18 @@ decode_sattr(__be32 *p, struct iattr *ia
5621                 iap->ia_mode = tmp;
5622         }
5623         if ((tmp = ntohl(*p++)) != (u32)-1) {
5624 -               iap->ia_uid = make_kuid(&init_user_ns, tmp);
5625 +               uid = make_kuid(&init_user_ns, tmp);
5626                 if (uid_valid(iap->ia_uid))
5627                         iap->ia_valid |= ATTR_UID;
5628         }
5629         if ((tmp = ntohl(*p++)) != (u32)-1) {
5630 -               iap->ia_gid = make_kgid(&init_user_ns, tmp);
5631 +               gid = make_kgid(&init_user_ns, tmp);
5632                 if (gid_valid(iap->ia_gid))
5633                         iap->ia_valid |= ATTR_GID;
5634         }
5635 +       iap->ia_uid = INOTAG_UID(DX_TAG_NFSD, uid, gid);
5636 +       iap->ia_gid = INOTAG_GID(DX_TAG_NFSD, uid, gid);
5637 +       iap->ia_tag = INOTAG_TAG(DX_TAG_NFSD, uid, gid, 0);
5638         if ((tmp = ntohl(*p++)) != (u32)-1) {
5639                 iap->ia_valid |= ATTR_SIZE;
5640                 iap->ia_size = tmp;
5641 @@ -154,8 +160,10 @@ encode_fattr(struct svc_rqst *rqstp, __b
5642         *p++ = htonl(nfs_ftypes[type >> 12]);
5643         *p++ = htonl((u32) stat->mode);
5644         *p++ = htonl((u32) stat->nlink);
5645 -       *p++ = htonl((u32) from_kuid(&init_user_ns, stat->uid));
5646 -       *p++ = htonl((u32) from_kgid(&init_user_ns, stat->gid));
5647 +       *p++ = htonl((u32) from_kuid(&init_user_ns,
5648 +               TAGINO_UID(DX_TAG(dentry->d_inode), stat->uid, stat->tag)));
5649 +       *p++ = htonl((u32) from_kgid(&init_user_ns,
5650 +               TAGINO_GID(DX_TAG(dentry->d_inode), stat->gid, stat->tag)));
5651  
5652         if (S_ISLNK(type) && stat->size > NFS_MAXPATHLEN) {
5653                 *p++ = htonl(NFS_MAXPATHLEN);
5654 diff -NurpP --minimal linux-3.9.4/fs/ocfs2/dlmglue.c linux-3.9.4-vs2.3.6.2/fs/ocfs2/dlmglue.c
5655 --- linux-3.9.4/fs/ocfs2/dlmglue.c      2013-05-31 13:45:24.000000000 +0000
5656 +++ linux-3.9.4-vs2.3.6.2/fs/ocfs2/dlmglue.c    2013-05-31 15:47:29.000000000 +0000
5657 @@ -2047,6 +2047,7 @@ static void __ocfs2_stuff_meta_lvb(struc
5658         lvb->lvb_iclusters = cpu_to_be32(oi->ip_clusters);
5659         lvb->lvb_iuid      = cpu_to_be32(i_uid_read(inode));
5660         lvb->lvb_igid      = cpu_to_be32(i_gid_read(inode));
5661 +       lvb->lvb_itag      = cpu_to_be16(inode->i_tag);
5662         lvb->lvb_imode     = cpu_to_be16(inode->i_mode);
5663         lvb->lvb_inlink    = cpu_to_be16(inode->i_nlink);
5664         lvb->lvb_iatime_packed  =
5665 @@ -2097,6 +2098,7 @@ static void ocfs2_refresh_inode_from_lvb
5666  
5667         i_uid_write(inode, be32_to_cpu(lvb->lvb_iuid));
5668         i_gid_write(inode, be32_to_cpu(lvb->lvb_igid));
5669 +       i_tag_write(inode, be16_to_cpu(lvb->lvb_itag));
5670         inode->i_mode    = be16_to_cpu(lvb->lvb_imode);
5671         set_nlink(inode, be16_to_cpu(lvb->lvb_inlink));
5672         ocfs2_unpack_timespec(&inode->i_atime,
5673 diff -NurpP --minimal linux-3.9.4/fs/ocfs2/dlmglue.h linux-3.9.4-vs2.3.6.2/fs/ocfs2/dlmglue.h
5674 --- linux-3.9.4/fs/ocfs2/dlmglue.h      2012-12-11 03:30:57.000000000 +0000
5675 +++ linux-3.9.4-vs2.3.6.2/fs/ocfs2/dlmglue.h    2013-05-31 14:47:11.000000000 +0000
5676 @@ -46,7 +46,8 @@ struct ocfs2_meta_lvb {
5677         __be16       lvb_inlink;
5678         __be32       lvb_iattr;
5679         __be32       lvb_igeneration;
5680 -       __be32       lvb_reserved2;
5681 +       __be16       lvb_itag;
5682 +       __be16       lvb_reserved2;
5683  };
5684  
5685  #define OCFS2_QINFO_LVB_VERSION 1
5686 diff -NurpP --minimal linux-3.9.4/fs/ocfs2/file.c linux-3.9.4-vs2.3.6.2/fs/ocfs2/file.c
5687 --- linux-3.9.4/fs/ocfs2/file.c 2013-05-31 13:45:24.000000000 +0000
5688 +++ linux-3.9.4-vs2.3.6.2/fs/ocfs2/file.c       2013-05-31 14:47:11.000000000 +0000
5689 @@ -1124,7 +1124,7 @@ int ocfs2_setattr(struct dentry *dentry,
5690                 attr->ia_valid &= ~ATTR_SIZE;
5691  
5692  #define OCFS2_VALID_ATTRS (ATTR_ATIME | ATTR_MTIME | ATTR_CTIME | ATTR_SIZE \
5693 -                          | ATTR_GID | ATTR_UID | ATTR_MODE)
5694 +                          | ATTR_GID | ATTR_UID | ATTR_TAG | ATTR_MODE)
5695         if (!(attr->ia_valid & OCFS2_VALID_ATTRS))
5696                 return 0;
5697  
5698 diff -NurpP --minimal linux-3.9.4/fs/ocfs2/inode.c linux-3.9.4-vs2.3.6.2/fs/ocfs2/inode.c
5699 --- linux-3.9.4/fs/ocfs2/inode.c        2013-05-31 13:45:24.000000000 +0000
5700 +++ linux-3.9.4-vs2.3.6.2/fs/ocfs2/inode.c      2013-05-31 20:39:47.000000000 +0000
5701 @@ -28,6 +28,7 @@
5702  #include <linux/highmem.h>
5703  #include <linux/pagemap.h>
5704  #include <linux/quotaops.h>
5705 +#include <linux/vs_tag.h>
5706  
5707  #include <asm/byteorder.h>
5708  
5709 @@ -78,11 +79,13 @@ void ocfs2_set_inode_flags(struct inode
5710  {
5711         unsigned int flags = OCFS2_I(inode)->ip_attr;
5712  
5713 -       inode->i_flags &= ~(S_IMMUTABLE |
5714 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
5715                 S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
5716  
5717         if (flags & OCFS2_IMMUTABLE_FL)
5718                 inode->i_flags |= S_IMMUTABLE;
5719 +       if (flags & OCFS2_IXUNLINK_FL)
5720 +               inode->i_flags |= S_IXUNLINK;
5721  
5722         if (flags & OCFS2_SYNC_FL)
5723                 inode->i_flags |= S_SYNC;
5724 @@ -92,25 +95,44 @@ void ocfs2_set_inode_flags(struct inode
5725                 inode->i_flags |= S_NOATIME;
5726         if (flags & OCFS2_DIRSYNC_FL)
5727                 inode->i_flags |= S_DIRSYNC;
5728 +
5729 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
5730 +
5731 +       if (flags & OCFS2_BARRIER_FL)
5732 +               inode->i_vflags |= V_BARRIER;
5733 +       if (flags & OCFS2_COW_FL)
5734 +               inode->i_vflags |= V_COW;
5735  }
5736  
5737  /* Propagate flags from i_flags to OCFS2_I(inode)->ip_attr */
5738  void ocfs2_get_inode_flags(struct ocfs2_inode_info *oi)
5739  {
5740         unsigned int flags = oi->vfs_inode.i_flags;
5741 +       unsigned int vflags = oi->vfs_inode.i_vflags;
5742 +
5743 +       oi->ip_attr &= ~(OCFS2_SYNC_FL | OCFS2_APPEND_FL |
5744 +                       OCFS2_IMMUTABLE_FL | OCFS2_IXUNLINK_FL |
5745 +                       OCFS2_NOATIME_FL | OCFS2_DIRSYNC_FL |
5746 +                       OCFS2_BARRIER_FL | OCFS2_COW_FL);
5747 +
5748 +       if (flags & S_IMMUTABLE)
5749 +               oi->ip_attr |= OCFS2_IMMUTABLE_FL;
5750 +       if (flags & S_IXUNLINK)
5751 +               oi->ip_attr |= OCFS2_IXUNLINK_FL;
5752  
5753 -       oi->ip_attr &= ~(OCFS2_SYNC_FL|OCFS2_APPEND_FL|
5754 -                       OCFS2_IMMUTABLE_FL|OCFS2_NOATIME_FL|OCFS2_DIRSYNC_FL);
5755         if (flags & S_SYNC)
5756                 oi->ip_attr |= OCFS2_SYNC_FL;
5757         if (flags & S_APPEND)
5758                 oi->ip_attr |= OCFS2_APPEND_FL;
5759 -       if (flags & S_IMMUTABLE)
5760 -               oi->ip_attr |= OCFS2_IMMUTABLE_FL;
5761         if (flags & S_NOATIME)
5762                 oi->ip_attr |= OCFS2_NOATIME_FL;
5763         if (flags & S_DIRSYNC)
5764                 oi->ip_attr |= OCFS2_DIRSYNC_FL;
5765 +
5766 +       if (vflags & V_BARRIER)
5767 +               oi->ip_attr |= OCFS2_BARRIER_FL;
5768 +       if (vflags & V_COW)
5769 +               oi->ip_attr |= OCFS2_COW_FL;
5770  }
5771  
5772  struct inode *ocfs2_ilookup(struct super_block *sb, u64 blkno)
5773 @@ -241,6 +263,8 @@ void ocfs2_populate_inode(struct inode *
5774         struct super_block *sb;
5775         struct ocfs2_super *osb;
5776         int use_plocks = 1;
5777 +       uid_t uid;
5778 +       gid_t gid;
5779  
5780         sb = inode->i_sb;
5781         osb = OCFS2_SB(sb);
5782 @@ -269,8 +293,12 @@ void ocfs2_populate_inode(struct inode *
5783         inode->i_generation = le32_to_cpu(fe->i_generation);
5784         inode->i_rdev = huge_decode_dev(le64_to_cpu(fe->id1.dev1.i_rdev));
5785         inode->i_mode = le16_to_cpu(fe->i_mode);
5786 -       i_uid_write(inode, le32_to_cpu(fe->i_uid));
5787 -       i_gid_write(inode, le32_to_cpu(fe->i_gid));
5788 +       uid = le32_to_cpu(fe->i_uid);
5789 +       gid = le32_to_cpu(fe->i_gid);
5790 +       i_uid_write(inode, INOTAG_UID(DX_TAG(inode), uid, gid));
5791 +       i_gid_write(inode, INOTAG_GID(DX_TAG(inode), uid, gid));
5792 +       i_tag_write(inode, INOTAG_TAG(DX_TAG(inode), uid, gid,
5793 +               /* le16_to_cpu(raw_inode->i_raw_tag) */ 0));
5794  
5795         /* Fast symlinks will have i_size but no allocated clusters. */
5796         if (S_ISLNK(inode->i_mode) && !fe->i_clusters) {
5797 diff -NurpP --minimal linux-3.9.4/fs/ocfs2/inode.h linux-3.9.4-vs2.3.6.2/fs/ocfs2/inode.h
5798 --- linux-3.9.4/fs/ocfs2/inode.h        2012-12-11 03:30:57.000000000 +0000
5799 +++ linux-3.9.4-vs2.3.6.2/fs/ocfs2/inode.h      2013-05-31 14:47:11.000000000 +0000
5800 @@ -154,6 +154,7 @@ struct buffer_head *ocfs2_bread(struct i
5801  
5802  void ocfs2_set_inode_flags(struct inode *inode);
5803  void ocfs2_get_inode_flags(struct ocfs2_inode_info *oi);
5804 +int ocfs2_sync_flags(struct inode *inode, int, int);
5805  
5806  static inline blkcnt_t ocfs2_inode_sector_count(struct inode *inode)
5807  {
5808 diff -NurpP --minimal linux-3.9.4/fs/ocfs2/ioctl.c linux-3.9.4-vs2.3.6.2/fs/ocfs2/ioctl.c
5809 --- linux-3.9.4/fs/ocfs2/ioctl.c        2013-05-31 13:45:24.000000000 +0000
5810 +++ linux-3.9.4-vs2.3.6.2/fs/ocfs2/ioctl.c      2013-05-31 14:47:11.000000000 +0000
5811 @@ -76,7 +76,41 @@ static int ocfs2_get_inode_attr(struct i
5812         return status;
5813  }
5814  
5815 -static int ocfs2_set_inode_attr(struct inode *inode, unsigned flags,
5816 +int ocfs2_sync_flags(struct inode *inode, int flags, int vflags)
5817 +{
5818 +       struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
5819 +       struct buffer_head *bh = NULL;
5820 +       handle_t *handle = NULL;
5821 +       int status;
5822 +
5823 +       status = ocfs2_inode_lock(inode, &bh, 1);
5824 +       if (status < 0) {
5825 +               mlog_errno(status);
5826 +               return status;
5827 +       }
5828 +       handle = ocfs2_start_trans(osb, OCFS2_INODE_UPDATE_CREDITS);
5829 +       if (IS_ERR(handle)) {
5830 +               status = PTR_ERR(handle);
5831 +               mlog_errno(status);
5832 +               goto bail_unlock;
5833 +       }
5834 +
5835 +       inode->i_flags = flags;
5836 +       inode->i_vflags = vflags;
5837 +       ocfs2_get_inode_flags(OCFS2_I(inode));
5838 +
5839 +       status = ocfs2_mark_inode_dirty(handle, inode, bh);
5840 +       if (status < 0)
5841 +               mlog_errno(status);
5842 +
5843 +       ocfs2_commit_trans(osb, handle);
5844 +bail_unlock:
5845 +       ocfs2_inode_unlock(inode, 1);
5846 +       brelse(bh);
5847 +       return status;
5848 +}
5849 +
5850 +int ocfs2_set_inode_attr(struct inode *inode, unsigned flags,
5851                                 unsigned mask)
5852  {
5853         struct ocfs2_inode_info *ocfs2_inode = OCFS2_I(inode);
5854 @@ -101,6 +135,11 @@ static int ocfs2_set_inode_attr(struct i
5855         if (!S_ISDIR(inode->i_mode))
5856                 flags &= ~OCFS2_DIRSYNC_FL;
5857  
5858 +       if (IS_BARRIER(inode)) {
5859 +               vxwprintk_task(1, "messing with the barrier.");
5860 +               goto bail_unlock;
5861 +       }
5862 +
5863         handle = ocfs2_start_trans(osb, OCFS2_INODE_UPDATE_CREDITS);
5864         if (IS_ERR(handle)) {
5865                 status = PTR_ERR(handle);
5866 @@ -879,6 +918,7 @@ bail:
5867         return status;
5868  }
5869  
5870 +
5871  long ocfs2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
5872  {
5873         struct inode *inode = file_inode(filp);
5874 diff -NurpP --minimal linux-3.9.4/fs/ocfs2/namei.c linux-3.9.4-vs2.3.6.2/fs/ocfs2/namei.c
5875 --- linux-3.9.4/fs/ocfs2/namei.c        2013-05-31 13:45:24.000000000 +0000
5876 +++ linux-3.9.4-vs2.3.6.2/fs/ocfs2/namei.c      2013-05-31 15:52:25.000000000 +0000
5877 @@ -41,6 +41,7 @@
5878  #include <linux/slab.h>
5879  #include <linux/highmem.h>
5880  #include <linux/quotaops.h>
5881 +#include <linux/vs_tag.h>
5882  
5883  #include <cluster/masklog.h>
5884  
5885 @@ -475,6 +476,7 @@ static int __ocfs2_mknod_locked(struct i
5886         struct ocfs2_dinode *fe = NULL;
5887         struct ocfs2_extent_list *fel;
5888         u16 feat;
5889 +       tag_t tag;
5890  
5891         *new_fe_bh = NULL;
5892  
5893 @@ -512,8 +514,11 @@ static int __ocfs2_mknod_locked(struct i
5894         fe->i_suballoc_loc = cpu_to_le64(suballoc_loc);
5895         fe->i_suballoc_bit = cpu_to_le16(suballoc_bit);
5896         fe->i_suballoc_slot = cpu_to_le16(inode_ac->ac_alloc_slot);
5897 -       fe->i_uid = cpu_to_le32(i_uid_read(inode));
5898 -       fe->i_gid = cpu_to_le32(i_gid_read(inode));
5899 +
5900 +       tag = dx_current_fstag(osb->sb);
5901 +       fe->i_uid = cpu_to_le32(TAGINO_UID(DX_TAG(inode), i_uid_read(inode), tag));
5902 +       fe->i_gid = cpu_to_le32(TAGINO_GID(DX_TAG(inode), i_gid_read(inode), tag));
5903 +       inode->i_tag = tag; /* is this correct? */
5904         fe->i_mode = cpu_to_le16(inode->i_mode);
5905         if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode))
5906                 fe->id1.dev1.i_rdev = cpu_to_le64(huge_encode_dev(dev));
5907 diff -NurpP --minimal linux-3.9.4/fs/ocfs2/ocfs2.h linux-3.9.4-vs2.3.6.2/fs/ocfs2/ocfs2.h
5908 --- linux-3.9.4/fs/ocfs2/ocfs2.h        2012-12-11 03:30:57.000000000 +0000
5909 +++ linux-3.9.4-vs2.3.6.2/fs/ocfs2/ocfs2.h      2013-05-31 14:47:11.000000000 +0000
5910 @@ -272,6 +272,7 @@ enum ocfs2_mount_options
5911                                                      writes */
5912         OCFS2_MOUNT_HB_NONE = 1 << 13, /* No heartbeat */
5913         OCFS2_MOUNT_HB_GLOBAL = 1 << 14, /* Global heartbeat */
5914 +       OCFS2_MOUNT_TAGGED = 1 << 15, /* use tagging */
5915  };
5916  
5917  #define OCFS2_OSB_SOFT_RO                      0x0001
5918 diff -NurpP --minimal linux-3.9.4/fs/ocfs2/ocfs2_fs.h linux-3.9.4-vs2.3.6.2/fs/ocfs2/ocfs2_fs.h
5919 --- linux-3.9.4/fs/ocfs2/ocfs2_fs.h     2012-12-11 03:30:57.000000000 +0000
5920 +++ linux-3.9.4-vs2.3.6.2/fs/ocfs2/ocfs2_fs.h   2013-05-31 14:47:11.000000000 +0000
5921 @@ -266,6 +266,11 @@
5922  #define OCFS2_TOPDIR_FL                        FS_TOPDIR_FL    /* Top of directory hierarchies*/
5923  #define OCFS2_RESERVED_FL              FS_RESERVED_FL  /* reserved for ext2 lib */
5924  
5925 +#define OCFS2_IXUNLINK_FL              FS_IXUNLINK_FL  /* Immutable invert on unlink */
5926 +
5927 +#define OCFS2_BARRIER_FL               FS_BARRIER_FL   /* Barrier for chroot() */
5928 +#define OCFS2_COW_FL                   FS_COW_FL       /* Copy on Write marker */
5929 +
5930  #define OCFS2_FL_VISIBLE               FS_FL_USER_VISIBLE      /* User visible flags */
5931  #define OCFS2_FL_MODIFIABLE            FS_FL_USER_MODIFIABLE   /* User modifiable flags */
5932  
5933 diff -NurpP --minimal linux-3.9.4/fs/ocfs2/super.c linux-3.9.4-vs2.3.6.2/fs/ocfs2/super.c
5934 --- linux-3.9.4/fs/ocfs2/super.c        2013-05-31 13:45:25.000000000 +0000
5935 +++ linux-3.9.4-vs2.3.6.2/fs/ocfs2/super.c      2013-05-31 14:47:11.000000000 +0000
5936 @@ -185,6 +185,7 @@ enum {
5937         Opt_coherency_full,
5938         Opt_resv_level,
5939         Opt_dir_resv_level,
5940 +       Opt_tag, Opt_notag, Opt_tagid,
5941         Opt_err,
5942  };
5943  
5944 @@ -216,6 +217,9 @@ static const match_table_t tokens = {
5945         {Opt_coherency_full, "coherency=full"},
5946         {Opt_resv_level, "resv_level=%u"},
5947         {Opt_dir_resv_level, "dir_resv_level=%u"},
5948 +       {Opt_tag, "tag"},
5949 +       {Opt_notag, "notag"},
5950 +       {Opt_tagid, "tagid=%u"},
5951         {Opt_err, NULL}
5952  };
5953  
5954 @@ -662,6 +666,13 @@ static int ocfs2_remount(struct super_bl
5955                 goto out;
5956         }
5957  
5958 +       if ((osb->s_mount_opt & OCFS2_MOUNT_TAGGED) !=
5959 +           (parsed_options.mount_opt & OCFS2_MOUNT_TAGGED)) {
5960 +               ret = -EINVAL;
5961 +               mlog(ML_ERROR, "Cannot change tagging on remount\n");
5962 +               goto out;
5963 +       }
5964 +
5965         /* We're going to/from readonly mode. */
5966         if ((*flags & MS_RDONLY) != (sb->s_flags & MS_RDONLY)) {
5967                 /* Disable quota accounting before remounting RO */
5968 @@ -1177,6 +1188,9 @@ static int ocfs2_fill_super(struct super
5969  
5970         ocfs2_complete_mount_recovery(osb);
5971  
5972 +       if (osb->s_mount_opt & OCFS2_MOUNT_TAGGED)
5973 +               sb->s_flags |= MS_TAGGED;
5974 +
5975         if (ocfs2_mount_local(osb))
5976                 snprintf(nodestr, sizeof(nodestr), "local");
5977         else
5978 @@ -1504,6 +1518,20 @@ static int ocfs2_parse_options(struct su
5979                             option < OCFS2_MAX_RESV_LEVEL)
5980                                 mopt->dir_resv_level = option;
5981                         break;
5982 +#ifndef CONFIG_TAGGING_NONE
5983 +               case Opt_tag:
5984 +                       mopt->mount_opt |= OCFS2_MOUNT_TAGGED;
5985 +                       break;
5986 +               case Opt_notag:
5987 +                       mopt->mount_opt &= ~OCFS2_MOUNT_TAGGED;
5988 +                       break;
5989 +#endif
5990 +#ifdef CONFIG_PROPAGATE
5991 +               case Opt_tagid:
5992 +                       /* use args[0] */
5993 +                       mopt->mount_opt |= OCFS2_MOUNT_TAGGED;
5994 +                       break;
5995 +#endif
5996                 default:
5997                         mlog(ML_ERROR,
5998                              "Unrecognized mount option \"%s\" "
5999 diff -NurpP --minimal linux-3.9.4/fs/open.c linux-3.9.4-vs2.3.6.2/fs/open.c
6000 --- linux-3.9.4/fs/open.c       2013-05-31 13:45:25.000000000 +0000
6001 +++ linux-3.9.4-vs2.3.6.2/fs/open.c     2013-06-01 08:41:29.000000000 +0000
6002 @@ -31,6 +31,11 @@
6003  #include <linux/ima.h>
6004  #include <linux/dnotify.h>
6005  #include <linux/compat.h>
6006 +#include <linux/vs_base.h>
6007 +#include <linux/vs_limit.h>
6008 +#include <linux/vs_tag.h>
6009 +#include <linux/vs_cowbl.h>
6010 +#include <linux/vserver/dlimit.h>
6011  
6012  #include "internal.h"
6013  
6014 @@ -67,6 +72,11 @@ long vfs_truncate(struct path *path, lof
6015         struct inode *inode;
6016         long error;
6017  
6018 +#ifdef CONFIG_VSERVER_COWBL
6019 +       error = cow_check_and_break(path);
6020 +       if (error)
6021 +               goto out;
6022 +#endif
6023         inode = path->dentry->d_inode;
6024  
6025         /* For directories it's -EISDIR, for other non-regulars - -EINVAL */
6026 @@ -532,6 +542,13 @@ SYSCALL_DEFINE3(fchmodat, int, dfd, cons
6027         unsigned int lookup_flags = LOOKUP_FOLLOW;
6028  retry:
6029         error = user_path_at(dfd, filename, lookup_flags, &path);
6030 +#ifdef CONFIG_VSERVER_COWBL
6031 +       if (!error) {
6032 +               error = cow_check_and_break(&path);
6033 +               if (error)
6034 +                       path_put(&path);
6035 +       }
6036 +#endif
6037         if (!error) {
6038                 error = chmod_common(&path, mode);
6039                 path_put(&path);
6040 @@ -564,13 +581,15 @@ static int chown_common(struct path *pat
6041                 if (!uid_valid(uid))
6042                         return -EINVAL;
6043                 newattrs.ia_valid |= ATTR_UID;
6044 -               newattrs.ia_uid = uid;
6045 +               newattrs.ia_uid = make_kuid(&init_user_ns,
6046 +                       dx_map_uid(user));
6047         }
6048         if (group != (gid_t) -1) {
6049                 if (!gid_valid(gid))
6050                         return -EINVAL;
6051                 newattrs.ia_valid |= ATTR_GID;
6052 -               newattrs.ia_gid = gid;
6053 +               newattrs.ia_gid = make_kgid(&init_user_ns,
6054 +                       dx_map_gid(group));
6055         }
6056         if (!S_ISDIR(inode->i_mode))
6057                 newattrs.ia_valid |=
6058 @@ -604,6 +623,18 @@ retry:
6059         error = mnt_want_write(path.mnt);
6060         if (error)
6061                 goto out_release;
6062 +#ifdef CONFIG_VSERVER_COWBL
6063 +       error = cow_check_and_break(&path);
6064 +       if (!error)
6065 +#endif
6066 +#ifdef CONFIG_VSERVER_COWBL
6067 +       error = cow_check_and_break(&path);
6068 +       if (!error)
6069 +#endif
6070 +#ifdef CONFIG_VSERVER_COWBL
6071 +       error = cow_check_and_break(&path);
6072 +       if (!error)
6073 +#endif
6074         error = chown_common(&path, user, group);
6075         mnt_drop_write(path.mnt);
6076  out_release:
6077 diff -NurpP --minimal linux-3.9.4/fs/proc/array.c linux-3.9.4-vs2.3.6.2/fs/proc/array.c
6078 --- linux-3.9.4/fs/proc/array.c 2013-05-31 13:45:25.000000000 +0000
6079 +++ linux-3.9.4-vs2.3.6.2/fs/proc/array.c       2013-05-31 14:47:11.000000000 +0000
6080 @@ -82,6 +82,8 @@
6081  #include <linux/ptrace.h>
6082  #include <linux/tracehook.h>
6083  #include <linux/user_namespace.h>
6084 +#include <linux/vs_context.h>
6085 +#include <linux/vs_network.h>
6086  
6087  #include <asm/pgtable.h>
6088  #include <asm/processor.h>
6089 @@ -173,6 +175,9 @@ static inline void task_state(struct seq
6090         rcu_read_lock();
6091         ppid = pid_alive(p) ?
6092                 task_tgid_nr_ns(rcu_dereference(p->real_parent), ns) : 0;
6093 +       if (unlikely(vx_current_initpid(p->pid)))
6094 +               ppid = 0;
6095 +
6096         tpid = 0;
6097         if (pid_alive(p)) {
6098                 struct task_struct *tracer = ptrace_parent(p);
6099 @@ -297,7 +302,7 @@ static inline void task_sig(struct seq_f
6100  }
6101  
6102  static void render_cap_t(struct seq_file *m, const char *header,
6103 -                       kernel_cap_t *a)
6104 +                       struct vx_info *vxi, kernel_cap_t *a)
6105  {
6106         unsigned __capi;
6107  
6108 @@ -331,10 +336,11 @@ static inline void task_cap(struct seq_f
6109         NORM_CAPS(cap_effective);
6110         NORM_CAPS(cap_bset);
6111  
6112 -       render_cap_t(m, "CapInh:\t", &cap_inheritable);
6113 -       render_cap_t(m, "CapPrm:\t", &cap_permitted);
6114 -       render_cap_t(m, "CapEff:\t", &cap_effective);
6115 -       render_cap_t(m, "CapBnd:\t", &cap_bset);
6116 +       /* FIXME: maybe move the p->vx_info masking to __task_cred() ? */
6117 +       render_cap_t(m, "CapInh:\t", p->vx_info, &cap_inheritable);
6118 +       render_cap_t(m, "CapPrm:\t", p->vx_info, &cap_permitted);
6119 +       render_cap_t(m, "CapEff:\t", p->vx_info, &cap_effective);
6120 +       render_cap_t(m, "CapBnd:\t", p->vx_info, &cap_bset);
6121  }
6122  
6123  static inline void task_seccomp(struct seq_file *m, struct task_struct *p)
6124 @@ -363,6 +369,42 @@ static void task_cpus_allowed(struct seq
6125         seq_putc(m, '\n');
6126  }
6127  
6128 +int proc_pid_nsproxy(struct seq_file *m, struct pid_namespace *ns,
6129 +                       struct pid *pid, struct task_struct *task)
6130 +{
6131 +       seq_printf(m,   "Proxy:\t%p(%c)\n"
6132 +                       "Count:\t%u\n"
6133 +                       "uts:\t%p(%c)\n"
6134 +                       "ipc:\t%p(%c)\n"
6135 +                       "mnt:\t%p(%c)\n"
6136 +                       "pid:\t%p(%c)\n"
6137 +                       "net:\t%p(%c)\n",
6138 +                       task->nsproxy,
6139 +                       (task->nsproxy == init_task.nsproxy ? 'I' : '-'),
6140 +                       atomic_read(&task->nsproxy->count),
6141 +                       task->nsproxy->uts_ns,
6142 +                       (task->nsproxy->uts_ns == init_task.nsproxy->uts_ns ? 'I' : '-'),
6143 +                       task->nsproxy->ipc_ns,
6144 +                       (task->nsproxy->ipc_ns == init_task.nsproxy->ipc_ns ? 'I' : '-'),
6145 +                       task->nsproxy->mnt_ns,
6146 +                       (task->nsproxy->mnt_ns == init_task.nsproxy->mnt_ns ? 'I' : '-'),
6147 +                       task->nsproxy->pid_ns,
6148 +                       (task->nsproxy->pid_ns == init_task.nsproxy->pid_ns ? 'I' : '-'),
6149 +                       task->nsproxy->net_ns,
6150 +                       (task->nsproxy->net_ns == init_task.nsproxy->net_ns ? 'I' : '-'));
6151 +       return 0;
6152 +}
6153 +
6154 +void task_vs_id(struct seq_file *m, struct task_struct *task)
6155 +{
6156 +       if (task_vx_flags(task, VXF_HIDE_VINFO, 0))
6157 +               return;
6158 +
6159 +       seq_printf(m, "VxID: %d\n", vx_task_xid(task));
6160 +       seq_printf(m, "NxID: %d\n", nx_task_nid(task));
6161 +}
6162 +
6163 +
6164  int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
6165                         struct pid *pid, struct task_struct *task)
6166  {
6167 @@ -380,6 +422,7 @@ int proc_pid_status(struct seq_file *m,
6168         task_seccomp(m, task);
6169         task_cpus_allowed(m, task);
6170         cpuset_task_status_allowed(m, task);
6171 +       task_vs_id(m, task);
6172         task_context_switch_counts(m, task);
6173         return 0;
6174  }
6175 @@ -489,6 +532,17 @@ static int do_task_stat(struct seq_file
6176         /* convert nsec -> ticks */
6177         start_time = nsec_to_clock_t(start_time);
6178  
6179 +       /* fixup start time for virt uptime */
6180 +       if (vx_flags(VXF_VIRT_UPTIME, 0)) {
6181 +               unsigned long long bias =
6182 +                       current->vx_info->cvirt.bias_clock;
6183 +
6184 +               if (start_time > bias)
6185 +                       start_time -= bias;
6186 +               else
6187 +                       start_time = 0;
6188 +       }
6189 +
6190         seq_printf(m, "%d (%s) %c", pid_nr_ns(pid, ns), tcomm, state);
6191         seq_put_decimal_ll(m, ' ', ppid);
6192         seq_put_decimal_ll(m, ' ', pgid);
6193 diff -NurpP --minimal linux-3.9.4/fs/proc/base.c linux-3.9.4-vs2.3.6.2/fs/proc/base.c
6194 --- linux-3.9.4/fs/proc/base.c  2013-05-31 13:45:25.000000000 +0000
6195 +++ linux-3.9.4-vs2.3.6.2/fs/proc/base.c        2013-05-31 14:47:11.000000000 +0000
6196 @@ -86,6 +86,8 @@
6197  #include <linux/fs_struct.h>
6198  #include <linux/slab.h>
6199  #include <linux/flex_array.h>
6200 +#include <linux/vs_context.h>
6201 +#include <linux/vs_network.h>
6202  #ifdef CONFIG_HARDWALL
6203  #include <asm/hardwall.h>
6204  #endif
6205 @@ -944,11 +946,15 @@ static ssize_t oom_adj_write(struct file
6206                 oom_adj = (oom_adj * OOM_SCORE_ADJ_MAX) / -OOM_DISABLE;
6207  
6208         if (oom_adj < task->signal->oom_score_adj &&
6209 -           !capable(CAP_SYS_RESOURCE)) {
6210 +           !vx_capable(CAP_SYS_RESOURCE, VXC_OOM_ADJUST)) {
6211                 err = -EACCES;
6212                 goto err_sighand;
6213         }
6214  
6215 +       /* prevent guest processes from circumventing the oom killer */
6216 +       if (vx_current_xid() && (oom_adj == OOM_DISABLE))
6217 +               oom_adj = OOM_ADJUST_MIN;
6218 +
6219         /*
6220          * /proc/pid/oom_adj is provided for legacy purposes, ask users to use
6221          * /proc/pid/oom_score_adj instead.
6222 @@ -1528,6 +1534,8 @@ struct inode *proc_pid_make_inode(struct
6223                 inode->i_gid = cred->egid;
6224                 rcu_read_unlock();
6225         }
6226 +       /* procfs is xid tagged */
6227 +       i_tag_write(inode, (tag_t)vx_task_xid(task));
6228         security_task_to_inode(task, inode);
6229  
6230  out:
6231 @@ -1573,6 +1581,8 @@ int pid_getattr(struct vfsmount *mnt, st
6232  
6233  /* dentry stuff */
6234  
6235 +static unsigned name_to_int(struct dentry *dentry);
6236 +
6237  /*
6238   *     Exceptional case: normally we are not allowed to unhash a busy
6239   * directory. In this case, however, we can do it - no aliasing problems
6240 @@ -1601,6 +1611,12 @@ int pid_revalidate(struct dentry *dentry
6241         task = get_proc_task(inode);
6242  
6243         if (task) {
6244 +               unsigned pid = name_to_int(dentry);
6245 +
6246 +               if (pid != ~0U && pid != vx_map_pid(task->pid)) {
6247 +                       put_task_struct(task);
6248 +                       goto drop;
6249 +               }
6250                 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
6251                     task_dumpable(task)) {
6252                         rcu_read_lock();
6253 @@ -1617,6 +1633,7 @@ int pid_revalidate(struct dentry *dentry
6254                 put_task_struct(task);
6255                 return 1;
6256         }
6257 +drop:
6258         d_drop(dentry);
6259         return 0;
6260  }
6261 @@ -2059,6 +2076,13 @@ static struct dentry *proc_pident_lookup
6262         if (!task)
6263                 goto out_no_task;
6264  
6265 +       /* TODO: maybe we can come up with a generic approach? */
6266 +       if (task_vx_flags(task, VXF_HIDE_VINFO, 0) &&
6267 +               (dentry->d_name.len == 5) &&
6268 +               (!memcmp(dentry->d_name.name, "vinfo", 5) ||
6269 +               !memcmp(dentry->d_name.name, "ninfo", 5)))
6270 +               goto out;
6271 +
6272         /*
6273          * Yes, it does not scale. And it should not. Don't add
6274          * new entries into /proc/<tgid>/ without very good reasons.
6275 @@ -2493,6 +2517,9 @@ static int proc_pid_personality(struct s
6276  static const struct file_operations proc_task_operations;
6277  static const struct inode_operations proc_task_inode_operations;
6278  
6279 +extern int proc_pid_vx_info(struct task_struct *, char *);
6280 +extern int proc_pid_nx_info(struct task_struct *, char *);
6281 +
6282  static const struct pid_entry tgid_base_stuff[] = {
6283         DIR("task",       S_IRUGO|S_IXUGO, proc_task_inode_operations, proc_task_operations),
6284         DIR("fd",         S_IRUSR|S_IXUSR, proc_fd_inode_operations, proc_fd_operations),
6285 @@ -2559,6 +2586,8 @@ static const struct pid_entry tgid_base_
6286  #ifdef CONFIG_CGROUPS
6287         REG("cgroup",  S_IRUGO, proc_cgroup_operations),
6288  #endif
6289 +       INF("vinfo",      S_IRUGO, proc_pid_vx_info),
6290 +       INF("ninfo",      S_IRUGO, proc_pid_nx_info),
6291         INF("oom_score",  S_IRUGO, proc_oom_score),
6292         REG("oom_adj",    S_IRUGO|S_IWUSR, proc_oom_adj_operations),
6293         REG("oom_score_adj", S_IRUGO|S_IWUSR, proc_oom_score_adj_operations),
6294 @@ -2583,6 +2612,7 @@ static const struct pid_entry tgid_base_
6295         REG("gid_map",    S_IRUGO|S_IWUSR, proc_gid_map_operations),
6296         REG("projid_map", S_IRUGO|S_IWUSR, proc_projid_map_operations),
6297  #endif
6298 +       ONE("nsproxy",  S_IRUGO, proc_pid_nsproxy),
6299  };
6300  
6301  static int proc_tgid_base_readdir(struct file * filp,
6302 @@ -2770,7 +2800,7 @@ retry:
6303         iter.task = NULL;
6304         pid = find_ge_pid(iter.tgid, ns);
6305         if (pid) {
6306 -               iter.tgid = pid_nr_ns(pid, ns);
6307 +               iter.tgid = pid_unmapped_nr_ns(pid, ns);
6308                 iter.task = pid_task(pid, PIDTYPE_PID);
6309                 /* What we to know is if the pid we have find is the
6310                  * pid of a thread_group_leader.  Testing for task
6311 @@ -2800,7 +2830,7 @@ static int proc_pid_fill_cache(struct fi
6312         struct tgid_iter iter)
6313  {
6314         char name[PROC_NUMBUF];
6315 -       int len = snprintf(name, sizeof(name), "%d", iter.tgid);
6316 +       int len = snprintf(name, sizeof(name), "%d", vx_map_tgid(iter.tgid));
6317         return proc_fill_cache(filp, dirent, filldir, name, len,
6318                                 proc_pid_instantiate, iter.task, NULL);
6319  }
6320 @@ -2833,6 +2863,8 @@ int proc_pid_readdir(struct file * filp,
6321                         __filldir = fake_filldir;
6322  
6323                 filp->f_pos = iter.tgid + TGID_OFFSET;
6324 +               if (!vx_proc_task_visible(iter.task))
6325 +                       continue;
6326                 if (proc_pid_fill_cache(filp, dirent, __filldir, iter) < 0) {
6327                         put_task_struct(iter.task);
6328                         goto out;
6329 @@ -2993,6 +3025,8 @@ static struct dentry *proc_task_lookup(s
6330         tid = name_to_int(dentry);
6331         if (tid == ~0U)
6332                 goto out;
6333 +       if (vx_current_initpid(tid))
6334 +               goto out;
6335  
6336         ns = dentry->d_sb->s_fs_info;
6337         rcu_read_lock();
6338 diff -NurpP --minimal linux-3.9.4/fs/proc/generic.c linux-3.9.4-vs2.3.6.2/fs/proc/generic.c
6339 --- linux-3.9.4/fs/proc/generic.c       2013-05-31 13:45:25.000000000 +0000
6340 +++ linux-3.9.4-vs2.3.6.2/fs/proc/generic.c     2013-05-31 16:13:42.000000000 +0000
6341 @@ -23,6 +23,7 @@
6342  #include <linux/bitops.h>
6343  #include <linux/spinlock.h>
6344  #include <linux/completion.h>
6345 +#include <linux/vserver/inode.h>
6346  #include <asm/uaccess.h>
6347  
6348  #include "internal.h"
6349 @@ -409,6 +410,8 @@ struct dentry *proc_lookup_de(struct pro
6350         for (de = de->subdir; de ; de = de->next) {
6351                 if (de->namelen != dentry->d_name.len)
6352                         continue;
6353 +               if (!vx_hide_check(0, de->vx_flags))
6354 +                       continue;
6355                 if (!memcmp(dentry->d_name.name, de->name, de->namelen)) {
6356                         pde_get(de);
6357                         spin_unlock(&proc_subdir_lock);
6358 @@ -417,6 +420,8 @@ struct dentry *proc_lookup_de(struct pro
6359                                 return ERR_PTR(-ENOMEM);
6360                         d_set_d_op(dentry, &proc_dentry_operations);
6361                         d_add(dentry, inode);
6362 +                       /* generic proc entries belong to the host */
6363 +                       i_tag_write(inode, 0);
6364                         return NULL;
6365                 }
6366         }
6367 @@ -485,6 +490,8 @@ int proc_readdir_de(struct proc_dir_entr
6368  
6369                                 /* filldir passes info to user space */
6370                                 pde_get(de);
6371 +                               if (!vx_hide_check(0, de->vx_flags))
6372 +                                       goto skip;
6373                                 spin_unlock(&proc_subdir_lock);
6374                                 if (filldir(dirent, de->name, de->namelen, filp->f_pos,
6375                                             de->low_ino, de->mode >> 12) < 0) {
6376 @@ -492,6 +499,7 @@ int proc_readdir_de(struct proc_dir_entr
6377                                         goto out;
6378                                 }
6379                                 spin_lock(&proc_subdir_lock);
6380 +                       skip:
6381                                 filp->f_pos++;
6382                                 next = de->next;
6383                                 pde_put(de);
6384 @@ -603,6 +611,7 @@ static struct proc_dir_entry *__proc_cre
6385         ent->namelen = len;
6386         ent->mode = mode;
6387         ent->nlink = nlink;
6388 +       ent->vx_flags = IATTR_PROC_DEFAULT;
6389         atomic_set(&ent->count, 1);
6390         spin_lock_init(&ent->pde_unload_lock);
6391         INIT_LIST_HEAD(&ent->pde_openers);
6392 @@ -626,7 +635,8 @@ struct proc_dir_entry *proc_symlink(cons
6393                                 kfree(ent->data);
6394                                 kfree(ent);
6395                                 ent = NULL;
6396 -                       }
6397 +                       } else
6398 +                               ent->vx_flags = IATTR_PROC_SYMLINK;
6399                 } else {
6400                         kfree(ent);
6401                         ent = NULL;
6402 diff -NurpP --minimal linux-3.9.4/fs/proc/inode.c linux-3.9.4-vs2.3.6.2/fs/proc/inode.c
6403 --- linux-3.9.4/fs/proc/inode.c 2013-05-31 13:45:25.000000000 +0000
6404 +++ linux-3.9.4-vs2.3.6.2/fs/proc/inode.c       2013-05-31 14:47:11.000000000 +0000
6405 @@ -458,6 +458,8 @@ struct inode *proc_get_inode(struct supe
6406                         inode->i_uid = de->uid;
6407                         inode->i_gid = de->gid;
6408                 }
6409 +               if (de->vx_flags)
6410 +                       PROC_I(inode)->vx_flags = de->vx_flags;
6411                 if (de->size)
6412                         inode->i_size = de->size;
6413                 if (de->nlink)
6414 diff -NurpP --minimal linux-3.9.4/fs/proc/internal.h linux-3.9.4-vs2.3.6.2/fs/proc/internal.h
6415 --- linux-3.9.4/fs/proc/internal.h      2013-05-31 13:45:25.000000000 +0000
6416 +++ linux-3.9.4-vs2.3.6.2/fs/proc/internal.h    2013-05-31 16:04:34.000000000 +0000
6417 @@ -12,6 +12,8 @@
6418  #include <linux/sched.h>
6419  #include <linux/proc_fs.h>
6420  #include <linux/binfmts.h>
6421 +#include <linux/vs_pid.h>
6422 +
6423  struct  ctl_table_header;
6424  struct  mempolicy;
6425  
6426 @@ -56,6 +58,9 @@ extern int proc_pid_status(struct seq_fi
6427                                 struct pid *pid, struct task_struct *task);
6428  extern int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
6429                                 struct pid *pid, struct task_struct *task);
6430 +extern int proc_pid_nsproxy(struct seq_file *m, struct pid_namespace *ns,
6431 +                               struct pid *pid, struct task_struct *task);
6432 +
6433  extern loff_t mem_lseek(struct file *file, loff_t offset, int orig);
6434  
6435  extern const struct file_operations proc_tid_children_operations;
6436 @@ -89,11 +94,16 @@ static inline struct pid *proc_pid(struc
6437         return PROC_I(inode)->pid;
6438  }
6439  
6440 -static inline struct task_struct *get_proc_task(struct inode *inode)
6441 +static inline struct task_struct *get_proc_task_real(struct inode *inode)
6442  {
6443         return get_pid_task(proc_pid(inode), PIDTYPE_PID);
6444  }
6445  
6446 +static inline struct task_struct *get_proc_task(struct inode *inode)
6447 +{
6448 +       return vx_get_proc_task(inode, proc_pid(inode));
6449 +}
6450 +
6451  static inline int proc_fd(struct inode *inode)
6452  {
6453         return PROC_I(inode)->fd;
6454 diff -NurpP --minimal linux-3.9.4/fs/proc/loadavg.c linux-3.9.4-vs2.3.6.2/fs/proc/loadavg.c
6455 --- linux-3.9.4/fs/proc/loadavg.c       2012-12-11 03:30:57.000000000 +0000
6456 +++ linux-3.9.4-vs2.3.6.2/fs/proc/loadavg.c     2013-05-31 14:47:11.000000000 +0000
6457 @@ -12,15 +12,27 @@
6458  
6459  static int loadavg_proc_show(struct seq_file *m, void *v)
6460  {
6461 +       unsigned long running;
6462 +       unsigned int threads;
6463         unsigned long avnrun[3];
6464  
6465         get_avenrun(avnrun, FIXED_1/200, 0);
6466  
6467 +       if (vx_flags(VXF_VIRT_LOAD, 0)) {
6468 +               struct vx_info *vxi = current_vx_info();
6469 +
6470 +               running = atomic_read(&vxi->cvirt.nr_running);
6471 +               threads = atomic_read(&vxi->cvirt.nr_threads);
6472 +       } else {
6473 +               running = nr_running();
6474 +               threads = nr_threads;
6475 +       }
6476 +
6477         seq_printf(m, "%lu.%02lu %lu.%02lu %lu.%02lu %ld/%d %d\n",
6478                 LOAD_INT(avnrun[0]), LOAD_FRAC(avnrun[0]),
6479                 LOAD_INT(avnrun[1]), LOAD_FRAC(avnrun[1]),
6480                 LOAD_INT(avnrun[2]), LOAD_FRAC(avnrun[2]),
6481 -               nr_running(), nr_threads,
6482 +               running, threads,
6483                 task_active_pid_ns(current)->last_pid);
6484         return 0;
6485  }
6486 diff -NurpP --minimal linux-3.9.4/fs/proc/meminfo.c linux-3.9.4-vs2.3.6.2/fs/proc/meminfo.c
6487 --- linux-3.9.4/fs/proc/meminfo.c       2013-05-31 13:45:25.000000000 +0000
6488 +++ linux-3.9.4-vs2.3.6.2/fs/proc/meminfo.c     2013-05-31 16:05:39.000000000 +0000
6489 @@ -39,7 +39,8 @@ static int meminfo_proc_show(struct seq_
6490         allowed = ((totalram_pages - hugetlb_total_pages())
6491                 * sysctl_overcommit_ratio / 100) + total_swap_pages;
6492  
6493 -       cached = global_page_state(NR_FILE_PAGES) -
6494 +       cached = vx_flags(VXF_VIRT_MEM, 0) ?
6495 +               vx_vsi_cached(&i) : global_page_state(NR_FILE_PAGES) -
6496                         total_swapcache_pages() - i.bufferram;
6497         if (cached < 0)
6498                 cached = 0;
6499 diff -NurpP --minimal linux-3.9.4/fs/proc/root.c linux-3.9.4-vs2.3.6.2/fs/proc/root.c
6500 --- linux-3.9.4/fs/proc/root.c  2013-05-31 13:45:25.000000000 +0000
6501 +++ linux-3.9.4-vs2.3.6.2/fs/proc/root.c        2013-05-31 14:47:11.000000000 +0000
6502 @@ -20,9 +20,14 @@
6503  #include <linux/mount.h>
6504  #include <linux/pid_namespace.h>
6505  #include <linux/parser.h>
6506 +#include <linux/vserver/inode.h>
6507  
6508  #include "internal.h"
6509  
6510 +struct proc_dir_entry *proc_virtual;
6511 +
6512 +extern void proc_vx_init(void);
6513 +
6514  static int proc_test_super(struct super_block *sb, void *data)
6515  {
6516         return sb->s_fs_info == data;
6517 @@ -182,6 +187,7 @@ void __init proc_root_init(void)
6518  #endif
6519         proc_mkdir("bus", NULL);
6520         proc_sys_init();
6521 +       proc_vx_init();
6522  }
6523  
6524  static int proc_root_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat
6525 @@ -248,6 +254,7 @@ struct proc_dir_entry proc_root = {
6526         .proc_iops      = &proc_root_inode_operations, 
6527         .proc_fops      = &proc_root_operations,
6528         .parent         = &proc_root,
6529 +       .vx_flags       = IATTR_ADMIN | IATTR_WATCH,
6530         .name           = "/proc",
6531  };
6532  
6533 diff -NurpP --minimal linux-3.9.4/fs/proc/self.c linux-3.9.4-vs2.3.6.2/fs/proc/self.c
6534 --- linux-3.9.4/fs/proc/self.c  2013-02-19 13:58:49.000000000 +0000
6535 +++ linux-3.9.4-vs2.3.6.2/fs/proc/self.c        2013-05-31 20:57:54.000000000 +0000
6536 @@ -1,6 +1,7 @@
6537  #include <linux/proc_fs.h>
6538  #include <linux/sched.h>
6539  #include <linux/namei.h>
6540 +#include <linux/vserver/inode.h>
6541  
6542  /*
6543   * /proc/self:
6544 @@ -56,4 +57,5 @@ void __init proc_self_init(void)
6545         mode = S_IFLNK | S_IRWXUGO;
6546         proc_self_symlink = proc_create("self", mode, NULL, NULL );
6547         proc_self_symlink->proc_iops = &proc_self_inode_operations;
6548 +       proc_self_symlink->vx_flags = IATTR_PROC_SYMLINK;
6549  }
6550 diff -NurpP --minimal linux-3.9.4/fs/proc/stat.c linux-3.9.4-vs2.3.6.2/fs/proc/stat.c
6551 --- linux-3.9.4/fs/proc/stat.c  2012-12-11 03:30:57.000000000 +0000
6552 +++ linux-3.9.4-vs2.3.6.2/fs/proc/stat.c        2013-05-31 14:47:11.000000000 +0000
6553 @@ -9,8 +9,10 @@
6554  #include <linux/slab.h>
6555  #include <linux/time.h>
6556  #include <linux/irqnr.h>
6557 +#include <linux/vserver/cvirt.h>
6558  #include <asm/cputime.h>
6559  #include <linux/tick.h>
6560 +#include <linux/cpuset.h>
6561  
6562  #ifndef arch_irq_stat_cpu
6563  #define arch_irq_stat_cpu(cpu) 0
6564 @@ -87,14 +89,26 @@ static int show_stat(struct seq_file *p,
6565         u64 sum_softirq = 0;
6566         unsigned int per_softirq_sums[NR_SOFTIRQS] = {0};
6567         struct timespec boottime;
6568 +       cpumask_var_t cpus_allowed;
6569 +       bool virt_cpu = vx_flags(VXF_VIRT_CPU, 0);
6570  
6571         user = nice = system = idle = iowait =
6572                 irq = softirq = steal = 0;
6573         guest = guest_nice = 0;
6574         getboottime(&boottime);
6575 +
6576 +       if (vx_flags(VXF_VIRT_UPTIME, 0))
6577 +               vx_vsi_boottime(&boottime);
6578 +
6579 +       if (virt_cpu)
6580 +               cpuset_cpus_allowed(current, cpus_allowed);
6581 +
6582         jif = boottime.tv_sec;
6583  
6584         for_each_possible_cpu(i) {
6585 +               if (virt_cpu && !cpumask_test_cpu(i, cpus_allowed))
6586 +                       continue;
6587 +
6588                 user += kcpustat_cpu(i).cpustat[CPUTIME_USER];
6589                 nice += kcpustat_cpu(i).cpustat[CPUTIME_NICE];
6590                 system += kcpustat_cpu(i).cpustat[CPUTIME_SYSTEM];
6591 @@ -131,6 +145,9 @@ static int show_stat(struct seq_file *p,
6592         seq_putc(p, '\n');
6593  
6594         for_each_online_cpu(i) {
6595 +               if (virt_cpu && !cpumask_test_cpu(i, cpus_allowed))
6596 +                       continue;
6597 +
6598                 /* Copy values here to work around gcc-2.95.3, gcc-2.96 */
6599                 user = kcpustat_cpu(i).cpustat[CPUTIME_USER];
6600                 nice = kcpustat_cpu(i).cpustat[CPUTIME_NICE];
6601 diff -NurpP --minimal linux-3.9.4/fs/proc/uptime.c linux-3.9.4-vs2.3.6.2/fs/proc/uptime.c
6602 --- linux-3.9.4/fs/proc/uptime.c        2012-12-11 03:30:57.000000000 +0000
6603 +++ linux-3.9.4-vs2.3.6.2/fs/proc/uptime.c      2013-05-31 14:47:11.000000000 +0000
6604 @@ -5,6 +5,7 @@
6605  #include <linux/seq_file.h>
6606  #include <linux/time.h>
6607  #include <linux/kernel_stat.h>
6608 +#include <linux/vserver/cvirt.h>
6609  #include <asm/cputime.h>
6610  
6611  static int uptime_proc_show(struct seq_file *m, void *v)
6612 @@ -25,6 +26,10 @@ static int uptime_proc_show(struct seq_f
6613         nsec = cputime64_to_jiffies64(idletime) * TICK_NSEC;
6614         idle.tv_sec = div_u64_rem(nsec, NSEC_PER_SEC, &rem);
6615         idle.tv_nsec = rem;
6616 +
6617 +       if (vx_flags(VXF_VIRT_UPTIME, 0))
6618 +               vx_vsi_uptime(&uptime, &idle);
6619 +
6620         seq_printf(m, "%lu.%02lu %lu.%02lu\n",
6621                         (unsigned long) uptime.tv_sec,
6622                         (uptime.tv_nsec / (NSEC_PER_SEC / 100)),
6623 diff -NurpP --minimal linux-3.9.4/fs/proc_namespace.c linux-3.9.4-vs2.3.6.2/fs/proc_namespace.c
6624 --- linux-3.9.4/fs/proc_namespace.c     2012-12-11 03:30:57.000000000 +0000
6625 +++ linux-3.9.4-vs2.3.6.2/fs/proc_namespace.c   2013-05-31 17:17:53.000000000 +0000
6626 @@ -44,6 +44,8 @@ static int show_sb_opts(struct seq_file
6627                 { MS_SYNCHRONOUS, ",sync" },
6628                 { MS_DIRSYNC, ",dirsync" },
6629                 { MS_MANDLOCK, ",mand" },
6630 +               { MS_TAGGED, ",tag" },
6631 +               { MS_NOTAGCHECK, ",notagcheck" },
6632                 { 0, NULL }
6633         };
6634         const struct proc_fs_info *fs_infop;
6635 @@ -80,6 +82,40 @@ static inline void mangle(struct seq_fil
6636         seq_escape(m, s, " \t\n\\");
6637  }
6638  
6639 +#ifdef CONFIG_VSERVER_EXTRA_MNT_CHECK
6640 +
6641 +static int mnt_is_reachable(struct vfsmount *vfsmnt)
6642 +{
6643 +       struct path root;
6644 +       struct dentry *point;
6645 +       struct mount *mnt = real_mount(vfsmnt);
6646 +       struct mount *root_mnt;
6647 +       int ret;
6648 +
6649 +       if (mnt == mnt->mnt_ns->root)
6650 +               return 1;
6651 +
6652 +       br_read_lock(&vfsmount_lock);
6653 +       root = current->fs->root;
6654 +       root_mnt = real_mount(root.mnt);
6655 +       point = root.dentry;
6656 +
6657 +       while ((mnt != mnt->mnt_parent) && (mnt != root_mnt)) {
6658 +               point = mnt->mnt_mountpoint;
6659 +               mnt = mnt->mnt_parent;
6660 +       }
6661 +
6662 +       ret = (mnt == root_mnt) && is_subdir(point, root.dentry);
6663 +
6664 +       br_read_unlock(&vfsmount_lock);
6665 +
6666 +       return ret;
6667 +}
6668 +
6669 +#else
6670 +#define        mnt_is_reachable(v)     (1)
6671 +#endif
6672 +
6673  static void show_type(struct seq_file *m, struct super_block *sb)
6674  {
6675         mangle(m, sb->s_type->name);
6676 @@ -96,6 +132,17 @@ static int show_vfsmnt(struct seq_file *
6677         struct path mnt_path = { .dentry = mnt->mnt_root, .mnt = mnt };
6678         struct super_block *sb = mnt_path.dentry->d_sb;
6679  
6680 +       if (vx_flags(VXF_HIDE_MOUNT, 0))
6681 +               return SEQ_SKIP;
6682 +       if (!mnt_is_reachable(mnt) && !vx_check(0, VS_WATCH_P))
6683 +               return SEQ_SKIP;
6684 +
6685 +       if (!vx_check(0, VS_ADMIN|VS_WATCH) &&
6686 +               mnt == current->fs->root.mnt) {
6687 +               seq_puts(m, "/dev/root / ");
6688 +               goto type;
6689 +       }
6690 +
6691         if (sb->s_op->show_devname) {
6692                 err = sb->s_op->show_devname(m, mnt_path.dentry);
6693                 if (err)
6694 @@ -106,6 +153,7 @@ static int show_vfsmnt(struct seq_file *
6695         seq_putc(m, ' ');
6696         seq_path(m, &mnt_path, " \t\n\\");
6697         seq_putc(m, ' ');
6698 +type:
6699         show_type(m, sb);
6700         seq_puts(m, __mnt_is_readonly(mnt) ? " ro" : " rw");
6701         err = show_sb_opts(m, sb);
6702 @@ -128,6 +176,11 @@ static int show_mountinfo(struct seq_fil
6703         struct path root = p->root;
6704         int err = 0;
6705  
6706 +       if (vx_flags(VXF_HIDE_MOUNT, 0))
6707 +               return SEQ_SKIP;
6708 +       if (!mnt_is_reachable(mnt) && !vx_check(0, VS_WATCH_P))
6709 +               return SEQ_SKIP;
6710 +
6711         seq_printf(m, "%i %i %u:%u ", r->mnt_id, r->mnt_parent->mnt_id,
6712                    MAJOR(sb->s_dev), MINOR(sb->s_dev));
6713         if (sb->s_op->show_path)
6714 @@ -187,6 +240,17 @@ static int show_vfsstat(struct seq_file
6715         struct super_block *sb = mnt_path.dentry->d_sb;
6716         int err = 0;
6717  
6718 +       if (vx_flags(VXF_HIDE_MOUNT, 0))
6719 +               return SEQ_SKIP;
6720 +       if (!mnt_is_reachable(mnt) && !vx_check(0, VS_WATCH_P))
6721 +               return SEQ_SKIP;
6722 +
6723 +       if (!vx_check(0, VS_ADMIN|VS_WATCH) &&
6724 +               mnt == current->fs->root.mnt) {
6725 +               seq_puts(m, "device /dev/root mounted on / ");
6726 +               goto type;
6727 +       }
6728 +
6729         /* device */
6730         if (sb->s_op->show_devname) {
6731                 seq_puts(m, "device ");
6732 @@ -203,7 +267,7 @@ static int show_vfsstat(struct seq_file
6733         seq_puts(m, " mounted on ");
6734         seq_path(m, &mnt_path, " \t\n\\");
6735         seq_putc(m, ' ');
6736 -
6737 +type:
6738         /* file system type */
6739         seq_puts(m, "with fstype ");
6740         show_type(m, sb);
6741 diff -NurpP --minimal linux-3.9.4/fs/quota/dquot.c linux-3.9.4-vs2.3.6.2/fs/quota/dquot.c
6742 --- linux-3.9.4/fs/quota/dquot.c        2013-05-31 13:45:25.000000000 +0000
6743 +++ linux-3.9.4-vs2.3.6.2/fs/quota/dquot.c      2013-05-31 14:47:11.000000000 +0000
6744 @@ -1585,6 +1585,9 @@ int __dquot_alloc_space(struct inode *in
6745         struct dquot **dquots = inode->i_dquot;
6746         int reserve = flags & DQUOT_SPACE_RESERVE;
6747  
6748 +       if ((ret = dl_alloc_space(inode, number)))
6749 +               return ret;
6750 +
6751         /*
6752          * First test before acquiring mutex - solves deadlocks when we
6753          * re-enter the quota code and are already holding the mutex
6754 @@ -1640,6 +1643,9 @@ int dquot_alloc_inode(const struct inode
6755         struct dquot_warn warn[MAXQUOTAS];
6756         struct dquot * const *dquots = inode->i_dquot;
6757  
6758 +       if ((ret = dl_alloc_inode(inode)))
6759 +               return ret;
6760 +
6761         /* First test before acquiring mutex - solves deadlocks when we
6762           * re-enter the quota code and are already holding the mutex */
6763         if (!dquot_active(inode))
6764 @@ -1711,6 +1717,8 @@ void __dquot_free_space(struct inode *in
6765         struct dquot **dquots = inode->i_dquot;
6766         int reserve = flags & DQUOT_SPACE_RESERVE;
6767  
6768 +       dl_free_space(inode, number);
6769 +
6770         /* First test before acquiring mutex - solves deadlocks when we
6771           * re-enter the quota code and are already holding the mutex */
6772         if (!dquot_active(inode)) {
6773 @@ -1755,6 +1763,8 @@ void dquot_free_inode(const struct inode
6774         struct dquot_warn warn[MAXQUOTAS];
6775         struct dquot * const *dquots = inode->i_dquot;
6776  
6777 +       dl_free_inode(inode);
6778 +
6779         /* First test before acquiring mutex - solves deadlocks when we
6780           * re-enter the quota code and are already holding the mutex */
6781         if (!dquot_active(inode))
6782 diff -NurpP --minimal linux-3.9.4/fs/quota/quota.c linux-3.9.4-vs2.3.6.2/fs/quota/quota.c
6783 --- linux-3.9.4/fs/quota/quota.c        2013-02-19 13:58:49.000000000 +0000
6784 +++ linux-3.9.4-vs2.3.6.2/fs/quota/quota.c      2013-05-31 14:47:11.000000000 +0000
6785 @@ -8,6 +8,7 @@
6786  #include <linux/fs.h>
6787  #include <linux/namei.h>
6788  #include <linux/slab.h>
6789 +#include <linux/vs_context.h>
6790  #include <asm/current.h>
6791  #include <linux/uaccess.h>
6792  #include <linux/kernel.h>
6793 @@ -37,7 +38,7 @@ static int check_quotactl_permission(str
6794                         break;
6795                 /*FALLTHROUGH*/
6796         default:
6797 -               if (!capable(CAP_SYS_ADMIN))
6798 +               if (!vx_capable(CAP_SYS_ADMIN, VXC_QUOTA_CTL))
6799                         return -EPERM;
6800         }
6801  
6802 @@ -309,6 +310,46 @@ static int do_quotactl(struct super_bloc
6803  
6804  #ifdef CONFIG_BLOCK
6805  
6806 +#if defined(CONFIG_BLK_DEV_VROOT) || defined(CONFIG_BLK_DEV_VROOT_MODULE)
6807 +
6808 +#include <linux/vroot.h>
6809 +#include <linux/major.h>
6810 +#include <linux/module.h>
6811 +#include <linux/kallsyms.h>
6812 +#include <linux/vserver/debug.h>
6813 +
6814 +static vroot_grb_func *vroot_get_real_bdev = NULL;
6815 +
6816 +static DEFINE_SPINLOCK(vroot_grb_lock);
6817 +
6818 +int register_vroot_grb(vroot_grb_func *func) {
6819 +       int ret = -EBUSY;
6820 +
6821 +       spin_lock(&vroot_grb_lock);
6822 +       if (!vroot_get_real_bdev) {
6823 +               vroot_get_real_bdev = func;
6824 +               ret = 0;
6825 +       }
6826 +       spin_unlock(&vroot_grb_lock);
6827 +       return ret;
6828 +}
6829 +EXPORT_SYMBOL(register_vroot_grb);
6830 +
6831 +int unregister_vroot_grb(vroot_grb_func *func) {
6832 +       int ret = -EINVAL;
6833 +
6834 +       spin_lock(&vroot_grb_lock);
6835 +       if (vroot_get_real_bdev) {
6836 +               vroot_get_real_bdev = NULL;
6837 +               ret = 0;
6838 +       }
6839 +       spin_unlock(&vroot_grb_lock);
6840 +       return ret;
6841 +}
6842 +EXPORT_SYMBOL(unregister_vroot_grb);
6843 +
6844 +#endif
6845 +
6846  /* Return 1 if 'cmd' will block on frozen filesystem */
6847  static int quotactl_cmd_write(int cmd)
6848  {
6849 @@ -343,6 +384,22 @@ static struct super_block *quotactl_bloc
6850         putname(tmp);
6851         if (IS_ERR(bdev))
6852                 return ERR_CAST(bdev);
6853 +#if defined(CONFIG_BLK_DEV_VROOT) || defined(CONFIG_BLK_DEV_VROOT_MODULE)
6854 +       if (bdev && bdev->bd_inode &&
6855 +               imajor(bdev->bd_inode) == VROOT_MAJOR) {
6856 +               struct block_device *bdnew = (void *)-EINVAL;
6857 +
6858 +               if (vroot_get_real_bdev)
6859 +                       bdnew = vroot_get_real_bdev(bdev);
6860 +               else
6861 +                       vxdprintk(VXD_CBIT(misc, 0),
6862 +                                       "vroot_get_real_bdev not set");
6863 +               bdput(bdev);
6864 +               if (IS_ERR(bdnew))
6865 +                       return ERR_PTR(PTR_ERR(bdnew));
6866 +               bdev = bdnew;
6867 +       }
6868 +#endif
6869         if (quotactl_cmd_write(cmd))
6870                 sb = get_super_thawed(bdev);
6871         else
6872 diff -NurpP --minimal linux-3.9.4/fs/stat.c linux-3.9.4-vs2.3.6.2/fs/stat.c
6873 --- linux-3.9.4/fs/stat.c       2013-05-31 13:45:25.000000000 +0000
6874 +++ linux-3.9.4-vs2.3.6.2/fs/stat.c     2013-06-01 08:53:01.000000000 +0000
6875 @@ -26,6 +26,7 @@ void generic_fillattr(struct inode *inod
6876         stat->nlink = inode->i_nlink;
6877         stat->uid = inode->i_uid;
6878         stat->gid = inode->i_gid;
6879 +       stat->tag = inode->i_tag;
6880         stat->rdev = inode->i_rdev;
6881         stat->size = i_size_read(inode);
6882         stat->atime = inode->i_atime;
6883 diff -NurpP --minimal linux-3.9.4/fs/statfs.c linux-3.9.4-vs2.3.6.2/fs/statfs.c
6884 --- linux-3.9.4/fs/statfs.c     2013-02-19 13:58:49.000000000 +0000
6885 +++ linux-3.9.4-vs2.3.6.2/fs/statfs.c   2013-05-31 14:47:11.000000000 +0000
6886 @@ -7,6 +7,8 @@
6887  #include <linux/statfs.h>
6888  #include <linux/security.h>
6889  #include <linux/uaccess.h>
6890 +#include <linux/vs_base.h>
6891 +#include <linux/vs_dlimit.h>
6892  #include "internal.h"
6893  
6894  static int flags_by_mnt(int mnt_flags)
6895 @@ -60,6 +62,8 @@ static int statfs_by_dentry(struct dentr
6896         retval = dentry->d_sb->s_op->statfs(dentry, buf);
6897         if (retval == 0 && buf->f_frsize == 0)
6898                 buf->f_frsize = buf->f_bsize;
6899 +       if (!vx_check(0, VS_ADMIN|VS_WATCH))
6900 +               vx_vsi_statfs(dentry->d_sb, buf);
6901         return retval;
6902  }
6903  
6904 diff -NurpP --minimal linux-3.9.4/fs/super.c linux-3.9.4-vs2.3.6.2/fs/super.c
6905 --- linux-3.9.4/fs/super.c      2013-05-31 13:45:25.000000000 +0000
6906 +++ linux-3.9.4-vs2.3.6.2/fs/super.c    2013-05-31 14:47:11.000000000 +0000
6907 @@ -34,6 +34,8 @@
6908  #include <linux/cleancache.h>
6909  #include <linux/fsnotify.h>
6910  #include <linux/lockdep.h>
6911 +#include <linux/magic.h>
6912 +#include <linux/vs_context.h>
6913  #include "internal.h"
6914  
6915  
6916 @@ -1117,6 +1119,13 @@ mount_fs(struct file_system_type *type,
6917         WARN_ON(sb->s_bdi == &default_backing_dev_info);
6918         sb->s_flags |= MS_BORN;
6919  
6920 +       error = -EPERM;
6921 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_BINARY_MOUNT) &&
6922 +               !sb->s_bdev &&
6923 +               (sb->s_magic != PROC_SUPER_MAGIC) &&
6924 +               (sb->s_magic != DEVPTS_SUPER_MAGIC))
6925 +               goto out_sb;
6926 +
6927         error = security_sb_kern_mount(sb, flags, secdata);
6928         if (error)
6929                 goto out_sb;
6930 diff -NurpP --minimal linux-3.9.4/fs/sysfs/mount.c linux-3.9.4-vs2.3.6.2/fs/sysfs/mount.c
6931 --- linux-3.9.4/fs/sysfs/mount.c        2013-05-31 13:45:25.000000000 +0000
6932 +++ linux-3.9.4-vs2.3.6.2/fs/sysfs/mount.c      2013-05-31 14:47:11.000000000 +0000
6933 @@ -48,7 +48,7 @@ static int sysfs_fill_super(struct super
6934  
6935         sb->s_blocksize = PAGE_CACHE_SIZE;
6936         sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
6937 -       sb->s_magic = SYSFS_MAGIC;
6938 +       sb->s_magic = SYSFS_SUPER_MAGIC;
6939         sb->s_op = &sysfs_ops;
6940         sb->s_time_gran = 1;
6941  
6942 diff -NurpP --minimal linux-3.9.4/fs/utimes.c linux-3.9.4-vs2.3.6.2/fs/utimes.c
6943 --- linux-3.9.4/fs/utimes.c     2013-02-19 13:58:49.000000000 +0000
6944 +++ linux-3.9.4-vs2.3.6.2/fs/utimes.c   2013-05-31 22:40:16.000000000 +0000
6945 @@ -8,6 +8,8 @@
6946  #include <linux/stat.h>
6947  #include <linux/utime.h>
6948  #include <linux/syscalls.h>
6949 +#include <linux/mount.h>
6950 +#include <linux/vs_cowbl.h>
6951  #include <asm/uaccess.h>
6952  #include <asm/unistd.h>
6953  
6954 @@ -52,12 +54,18 @@ static int utimes_common(struct path *pa
6955  {
6956         int error;
6957         struct iattr newattrs;
6958 -       struct inode *inode = path->dentry->d_inode;
6959 +       struct inode *inode;
6960 +
6961 +       error = cow_check_and_break(path);
6962 +       if (error)
6963 +               goto out;
6964  
6965         error = mnt_want_write(path->mnt);
6966         if (error)
6967                 goto out;
6968  
6969 +       inode = path->dentry->d_inode;
6970 +
6971         if (times && times[0].tv_nsec == UTIME_NOW &&
6972                      times[1].tv_nsec == UTIME_NOW)
6973                 times = NULL;
6974 diff -NurpP --minimal linux-3.9.4/fs/xattr.c linux-3.9.4-vs2.3.6.2/fs/xattr.c
6975 --- linux-3.9.4/fs/xattr.c      2013-02-19 13:58:49.000000000 +0000
6976 +++ linux-3.9.4-vs2.3.6.2/fs/xattr.c    2013-05-31 14:47:11.000000000 +0000
6977 @@ -21,6 +21,7 @@
6978  #include <linux/audit.h>
6979  #include <linux/vmalloc.h>
6980  #include <linux/posix_acl_xattr.h>
6981 +#include <linux/mount.h>
6982  
6983  #include <asm/uaccess.h>
6984  
6985 @@ -52,7 +53,7 @@ xattr_permission(struct inode *inode, co
6986          * The trusted.* namespace can only be accessed by privileged users.
6987          */
6988         if (!strncmp(name, XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN)) {
6989 -               if (!capable(CAP_SYS_ADMIN))
6990 +               if (!vx_capable(CAP_SYS_ADMIN, VXC_FS_TRUSTED))
6991                         return (mask & MAY_WRITE) ? -EPERM : -ENODATA;
6992                 return 0;
6993         }
6994 diff -NurpP --minimal linux-3.9.4/fs/xfs/xfs_dinode.h linux-3.9.4-vs2.3.6.2/fs/xfs/xfs_dinode.h
6995 --- linux-3.9.4/fs/xfs/xfs_dinode.h     2012-12-11 03:30:57.000000000 +0000
6996 +++ linux-3.9.4-vs2.3.6.2/fs/xfs/xfs_dinode.h   2013-05-31 14:47:11.000000000 +0000
6997 @@ -51,7 +51,9 @@ typedef struct xfs_dinode {
6998         __be32          di_nlink;       /* number of links to file */
6999         __be16          di_projid_lo;   /* lower part of owner's project id */
7000         __be16          di_projid_hi;   /* higher part owner's project id */
7001 -       __u8            di_pad[6];      /* unused, zeroed space */
7002 +       __u8            di_pad[2];      /* unused, zeroed space */
7003 +       __be16          di_tag;         /* context tagging */
7004 +       __be16          di_vflags;      /* vserver specific flags */
7005         __be16          di_flushiter;   /* incremented on flush */
7006         xfs_timestamp_t di_atime;       /* time last accessed */
7007         xfs_timestamp_t di_mtime;       /* time last modified */
7008 @@ -184,6 +186,8 @@ static inline void xfs_dinode_put_rdev(s
7009  #define XFS_DIFLAG_EXTSZINHERIT_BIT 12 /* inherit inode extent size */
7010  #define XFS_DIFLAG_NODEFRAG_BIT     13 /* do not reorganize/defragment */
7011  #define XFS_DIFLAG_FILESTREAM_BIT   14  /* use filestream allocator */
7012 +#define XFS_DIFLAG_IXUNLINK_BIT     15 /* Immutable inver on unlink */
7013 +
7014  #define XFS_DIFLAG_REALTIME      (1 << XFS_DIFLAG_REALTIME_BIT)
7015  #define XFS_DIFLAG_PREALLOC      (1 << XFS_DIFLAG_PREALLOC_BIT)
7016  #define XFS_DIFLAG_NEWRTBM       (1 << XFS_DIFLAG_NEWRTBM_BIT)
7017 @@ -199,6 +203,7 @@ static inline void xfs_dinode_put_rdev(s
7018  #define XFS_DIFLAG_EXTSZINHERIT  (1 << XFS_DIFLAG_EXTSZINHERIT_BIT)
7019  #define XFS_DIFLAG_NODEFRAG      (1 << XFS_DIFLAG_NODEFRAG_BIT)
7020  #define XFS_DIFLAG_FILESTREAM    (1 << XFS_DIFLAG_FILESTREAM_BIT)
7021 +#define XFS_DIFLAG_IXUNLINK      (1 << XFS_DIFLAG_IXUNLINK_BIT)
7022  
7023  #ifdef CONFIG_XFS_RT
7024  #define XFS_IS_REALTIME_INODE(ip) ((ip)->i_d.di_flags & XFS_DIFLAG_REALTIME)
7025 @@ -211,6 +216,10 @@ static inline void xfs_dinode_put_rdev(s
7026          XFS_DIFLAG_IMMUTABLE | XFS_DIFLAG_APPEND | XFS_DIFLAG_SYNC | \
7027          XFS_DIFLAG_NOATIME | XFS_DIFLAG_NODUMP | XFS_DIFLAG_RTINHERIT | \
7028          XFS_DIFLAG_PROJINHERIT | XFS_DIFLAG_NOSYMLINKS | XFS_DIFLAG_EXTSIZE | \
7029 -        XFS_DIFLAG_EXTSZINHERIT | XFS_DIFLAG_NODEFRAG | XFS_DIFLAG_FILESTREAM)
7030 +        XFS_DIFLAG_EXTSZINHERIT | XFS_DIFLAG_NODEFRAG | XFS_DIFLAG_FILESTREAM | \
7031 +        XFS_DIFLAG_IXUNLINK)
7032 +
7033 +#define XFS_DIVFLAG_BARRIER    0x01
7034 +#define XFS_DIVFLAG_COW                0x02
7035  
7036  #endif /* __XFS_DINODE_H__ */
7037 diff -NurpP --minimal linux-3.9.4/fs/xfs/xfs_fs.h linux-3.9.4-vs2.3.6.2/fs/xfs/xfs_fs.h
7038 --- linux-3.9.4/fs/xfs/xfs_fs.h 2013-02-19 13:58:49.000000000 +0000
7039 +++ linux-3.9.4-vs2.3.6.2/fs/xfs/xfs_fs.h       2013-05-31 14:47:11.000000000 +0000
7040 @@ -67,6 +67,9 @@ struct fsxattr {
7041  #define XFS_XFLAG_EXTSZINHERIT 0x00001000      /* inherit inode extent size */
7042  #define XFS_XFLAG_NODEFRAG     0x00002000      /* do not defragment */
7043  #define XFS_XFLAG_FILESTREAM   0x00004000      /* use filestream allocator */
7044 +#define XFS_XFLAG_IXUNLINK     0x00008000      /* immutable invert on unlink */
7045 +#define XFS_XFLAG_BARRIER      0x10000000      /* chroot() barrier */
7046 +#define XFS_XFLAG_COW          0x20000000      /* copy on write mark */
7047  #define XFS_XFLAG_HASATTR      0x80000000      /* no DIFLAG for this   */
7048  
7049  /*
7050 @@ -303,7 +306,8 @@ typedef struct xfs_bstat {
7051  #define        bs_projid       bs_projid_lo    /* (previously just bs_projid)  */
7052         __u16           bs_forkoff;     /* inode fork offset in bytes   */
7053         __u16           bs_projid_hi;   /* higher part of project id    */
7054 -       unsigned char   bs_pad[10];     /* pad space, unused            */
7055 +       unsigned char   bs_pad[8];      /* pad space, unused            */
7056 +       __u16           bs_tag;         /* context tagging              */
7057         __u32           bs_dmevmask;    /* DMIG event mask              */
7058         __u16           bs_dmstate;     /* DMIG state info              */
7059         __u16           bs_aextents;    /* attribute number of extents  */
7060 diff -NurpP --minimal linux-3.9.4/fs/xfs/xfs_ialloc.c linux-3.9.4-vs2.3.6.2/fs/xfs/xfs_ialloc.c
7061 --- linux-3.9.4/fs/xfs/xfs_ialloc.c     2013-05-31 13:45:25.000000000 +0000
7062 +++ linux-3.9.4-vs2.3.6.2/fs/xfs/xfs_ialloc.c   2013-05-31 14:47:11.000000000 +0000
7063 @@ -37,7 +37,6 @@
7064  #include "xfs_error.h"
7065  #include "xfs_bmap.h"
7066  
7067 -
7068  /*
7069   * Allocation group level functions.
7070   */
7071 diff -NurpP --minimal linux-3.9.4/fs/xfs/xfs_inode.c linux-3.9.4-vs2.3.6.2/fs/xfs/xfs_inode.c
7072 --- linux-3.9.4/fs/xfs/xfs_inode.c      2013-05-31 13:45:25.000000000 +0000
7073 +++ linux-3.9.4-vs2.3.6.2/fs/xfs/xfs_inode.c    2013-05-31 14:47:11.000000000 +0000
7074 @@ -16,6 +16,7 @@
7075   * Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
7076   */
7077  #include <linux/log2.h>
7078 +#include <linux/vs_tag.h>
7079  
7080  #include "xfs.h"
7081  #include "xfs_fs.h"
7082 @@ -835,15 +836,25 @@ xfs_iformat_btree(
7083  STATIC void
7084  xfs_dinode_from_disk(
7085         xfs_icdinode_t          *to,
7086 -       xfs_dinode_t            *from)
7087 +       xfs_dinode_t            *from,
7088 +       int                     tagged)
7089  {
7090 +       uint32_t uid, gid, tag;
7091 +
7092         to->di_magic = be16_to_cpu(from->di_magic);
7093         to->di_mode = be16_to_cpu(from->di_mode);
7094         to->di_version = from ->di_version;
7095         to->di_format = from->di_format;
7096         to->di_onlink = be16_to_cpu(from->di_onlink);
7097 -       to->di_uid = be32_to_cpu(from->di_uid);
7098 -       to->di_gid = be32_to_cpu(from->di_gid);
7099 +
7100 +       uid = be32_to_cpu(from->di_uid);
7101 +       gid = be32_to_cpu(from->di_gid);
7102 +       tag = be16_to_cpu(from->di_tag);
7103 +
7104 +       to->di_uid = INOTAG_UID(tagged, uid, gid);
7105 +       to->di_gid = INOTAG_GID(tagged, uid, gid);
7106 +       to->di_tag = INOTAG_TAG(tagged, uid, gid, tag);
7107 +
7108         to->di_nlink = be32_to_cpu(from->di_nlink);
7109         to->di_projid_lo = be16_to_cpu(from->di_projid_lo);
7110         to->di_projid_hi = be16_to_cpu(from->di_projid_hi);
7111 @@ -865,21 +876,26 @@ xfs_dinode_from_disk(
7112         to->di_dmevmask = be32_to_cpu(from->di_dmevmask);
7113         to->di_dmstate  = be16_to_cpu(from->di_dmstate);
7114         to->di_flags    = be16_to_cpu(from->di_flags);
7115 +       to->di_vflags   = be16_to_cpu(from->di_vflags);
7116         to->di_gen      = be32_to_cpu(from->di_gen);
7117  }
7118  
7119  void
7120  xfs_dinode_to_disk(
7121         xfs_dinode_t            *to,
7122 -       xfs_icdinode_t          *from)
7123 +       xfs_icdinode_t          *from,
7124 +       int                     tagged)
7125  {
7126         to->di_magic = cpu_to_be16(from->di_magic);
7127         to->di_mode = cpu_to_be16(from->di_mode);
7128         to->di_version = from ->di_version;
7129         to->di_format = from->di_format;
7130         to->di_onlink = cpu_to_be16(from->di_onlink);
7131 -       to->di_uid = cpu_to_be32(from->di_uid);
7132 -       to->di_gid = cpu_to_be32(from->di_gid);
7133 +
7134 +       to->di_uid = cpu_to_be32(TAGINO_UID(tagged, from->di_uid, from->di_tag));
7135 +       to->di_gid = cpu_to_be32(TAGINO_GID(tagged, from->di_gid, from->di_tag));
7136 +       to->di_tag = cpu_to_be16(TAGINO_TAG(tagged, from->di_tag));
7137 +
7138         to->di_nlink = cpu_to_be32(from->di_nlink);
7139         to->di_projid_lo = cpu_to_be16(from->di_projid_lo);
7140         to->di_projid_hi = cpu_to_be16(from->di_projid_hi);
7141 @@ -901,12 +917,14 @@ xfs_dinode_to_disk(
7142         to->di_dmevmask = cpu_to_be32(from->di_dmevmask);
7143         to->di_dmstate = cpu_to_be16(from->di_dmstate);
7144         to->di_flags = cpu_to_be16(from->di_flags);
7145 +       to->di_vflags = cpu_to_be16(from->di_vflags);
7146         to->di_gen = cpu_to_be32(from->di_gen);
7147  }
7148  
7149  STATIC uint
7150  _xfs_dic2xflags(
7151 -       __uint16_t              di_flags)
7152 +       __uint16_t              di_flags,
7153 +       __uint16_t              di_vflags)
7154  {
7155         uint                    flags = 0;
7156  
7157 @@ -917,6 +935,8 @@ _xfs_dic2xflags(
7158                         flags |= XFS_XFLAG_PREALLOC;
7159                 if (di_flags & XFS_DIFLAG_IMMUTABLE)
7160                         flags |= XFS_XFLAG_IMMUTABLE;
7161 +               if (di_flags & XFS_DIFLAG_IXUNLINK)
7162 +                       flags |= XFS_XFLAG_IXUNLINK;
7163                 if (di_flags & XFS_DIFLAG_APPEND)
7164                         flags |= XFS_XFLAG_APPEND;
7165                 if (di_flags & XFS_DIFLAG_SYNC)
7166 @@ -941,6 +961,10 @@ _xfs_dic2xflags(
7167                         flags |= XFS_XFLAG_FILESTREAM;
7168         }
7169  
7170 +       if (di_vflags & XFS_DIVFLAG_BARRIER)
7171 +               flags |= FS_BARRIER_FL;
7172 +       if (di_vflags & XFS_DIVFLAG_COW)
7173 +               flags |= FS_COW_FL;
7174         return flags;
7175  }
7176  
7177 @@ -950,7 +974,7 @@ xfs_ip2xflags(
7178  {
7179         xfs_icdinode_t          *dic = &ip->i_d;
7180  
7181 -       return _xfs_dic2xflags(dic->di_flags) |
7182 +       return _xfs_dic2xflags(dic->di_flags, dic->di_vflags) |
7183                                 (XFS_IFORK_Q(ip) ? XFS_XFLAG_HASATTR : 0);
7184  }
7185  
7186 @@ -958,7 +982,8 @@ uint
7187  xfs_dic2xflags(
7188         xfs_dinode_t            *dip)
7189  {
7190 -       return _xfs_dic2xflags(be16_to_cpu(dip->di_flags)) |
7191 +       return _xfs_dic2xflags(be16_to_cpu(dip->di_flags),
7192 +                               be16_to_cpu(dip->di_vflags)) |
7193                                 (XFS_DFORK_Q(dip) ? XFS_XFLAG_HASATTR : 0);
7194  }
7195  
7196 @@ -1012,7 +1037,8 @@ xfs_iread(
7197          * Otherwise, just get the truly permanent information.
7198          */
7199         if (dip->di_mode) {
7200 -               xfs_dinode_from_disk(&ip->i_d, dip);
7201 +               xfs_dinode_from_disk(&ip->i_d, dip,
7202 +                       mp->m_flags & XFS_MOUNT_TAGGED);
7203                 error = xfs_iformat(ip, dip);
7204                 if (error)  {
7205  #ifdef DEBUG
7206 @@ -1199,6 +1225,7 @@ xfs_ialloc(
7207         ASSERT(ip->i_d.di_nlink == nlink);
7208         ip->i_d.di_uid = current_fsuid();
7209         ip->i_d.di_gid = current_fsgid();
7210 +       ip->i_d.di_tag = current_fstag(&ip->i_vnode);
7211         xfs_set_projid(ip, prid);
7212         memset(&(ip->i_d.di_pad[0]), 0, sizeof(ip->i_d.di_pad));
7213  
7214 @@ -1258,6 +1285,7 @@ xfs_ialloc(
7215         ip->i_d.di_dmevmask = 0;
7216         ip->i_d.di_dmstate = 0;
7217         ip->i_d.di_flags = 0;
7218 +       ip->i_d.di_vflags = 0;
7219         flags = XFS_ILOG_CORE;
7220         switch (mode & S_IFMT) {
7221         case S_IFIFO:
7222 @@ -1952,6 +1980,7 @@ xfs_ifree(
7223         }
7224         ip->i_d.di_mode = 0;            /* mark incore inode as free */
7225         ip->i_d.di_flags = 0;
7226 +       ip->i_d.di_vflags = 0;
7227         ip->i_d.di_dmevmask = 0;
7228         ip->i_d.di_forkoff = 0;         /* mark the attr fork not in use */
7229         ip->i_d.di_format = XFS_DINODE_FMT_EXTENTS;
7230 @@ -2118,7 +2147,6 @@ xfs_iroot_realloc(
7231         return;
7232  }
7233  
7234 -
7235  /*
7236   * This is called when the amount of space needed for if_data
7237   * is increased or decreased.  The change in size is indicated by
7238 @@ -2800,7 +2828,8 @@ xfs_iflush_int(
7239          * because if the inode is dirty at all the core must
7240          * be.
7241          */
7242 -       xfs_dinode_to_disk(dip, &ip->i_d);
7243 +       xfs_dinode_to_disk(dip, &ip->i_d,
7244 +               mp->m_flags & XFS_MOUNT_TAGGED);
7245  
7246         /* Wrap, we never let the log put out DI_MAX_FLUSH */
7247         if (ip->i_d.di_flushiter == DI_MAX_FLUSH)
7248 diff -NurpP --minimal linux-3.9.4/fs/xfs/xfs_inode.h linux-3.9.4-vs2.3.6.2/fs/xfs/xfs_inode.h
7249 --- linux-3.9.4/fs/xfs/xfs_inode.h      2013-05-31 13:45:25.000000000 +0000
7250 +++ linux-3.9.4-vs2.3.6.2/fs/xfs/xfs_inode.h    2013-05-31 14:47:11.000000000 +0000
7251 @@ -134,7 +134,9 @@ typedef struct xfs_icdinode {
7252         __uint32_t      di_nlink;       /* number of links to file */
7253         __uint16_t      di_projid_lo;   /* lower part of owner's project id */
7254         __uint16_t      di_projid_hi;   /* higher part of owner's project id */
7255 -       __uint8_t       di_pad[6];      /* unused, zeroed space */
7256 +       __uint8_t       di_pad[2];      /* unused, zeroed space */
7257 +       __uint16_t      di_tag;         /* context tagging */
7258 +       __uint16_t      di_vflags;      /* vserver specific flags */
7259         __uint16_t      di_flushiter;   /* incremented on flush */
7260         xfs_ictimestamp_t di_atime;     /* time last accessed */
7261         xfs_ictimestamp_t di_mtime;     /* time last modified */
7262 @@ -556,7 +558,7 @@ int         xfs_imap_to_bp(struct xfs_mount *,
7263  int            xfs_iread(struct xfs_mount *, struct xfs_trans *,
7264                           struct xfs_inode *, uint);
7265  void           xfs_dinode_to_disk(struct xfs_dinode *,
7266 -                                  struct xfs_icdinode *);
7267 +                                  struct xfs_icdinode *, int);
7268  void           xfs_idestroy_fork(struct xfs_inode *, int);
7269  void           xfs_idata_realloc(struct xfs_inode *, int, int);
7270  void           xfs_iroot_realloc(struct xfs_inode *, int, int);
7271 diff -NurpP --minimal linux-3.9.4/fs/xfs/xfs_ioctl.c linux-3.9.4-vs2.3.6.2/fs/xfs/xfs_ioctl.c
7272 --- linux-3.9.4/fs/xfs/xfs_ioctl.c      2013-05-31 13:45:25.000000000 +0000
7273 +++ linux-3.9.4-vs2.3.6.2/fs/xfs/xfs_ioctl.c    2013-05-31 14:47:11.000000000 +0000
7274 @@ -26,7 +26,7 @@
7275  #include "xfs_bmap_btree.h"
7276  #include "xfs_dinode.h"
7277  #include "xfs_inode.h"
7278 -#include "xfs_ioctl.h"
7279 +// #include "xfs_ioctl.h"
7280  #include "xfs_rtalloc.h"
7281  #include "xfs_itable.h"
7282  #include "xfs_error.h"
7283 @@ -763,6 +763,10 @@ xfs_merge_ioc_xflags(
7284                 xflags |= XFS_XFLAG_IMMUTABLE;
7285         else
7286                 xflags &= ~XFS_XFLAG_IMMUTABLE;
7287 +       if (flags & FS_IXUNLINK_FL)
7288 +               xflags |= XFS_XFLAG_IXUNLINK;
7289 +       else
7290 +               xflags &= ~XFS_XFLAG_IXUNLINK;
7291         if (flags & FS_APPEND_FL)
7292                 xflags |= XFS_XFLAG_APPEND;
7293         else
7294 @@ -791,6 +795,8 @@ xfs_di2lxflags(
7295  
7296         if (di_flags & XFS_DIFLAG_IMMUTABLE)
7297                 flags |= FS_IMMUTABLE_FL;
7298 +       if (di_flags & XFS_DIFLAG_IXUNLINK)
7299 +               flags |= FS_IXUNLINK_FL;
7300         if (di_flags & XFS_DIFLAG_APPEND)
7301                 flags |= FS_APPEND_FL;
7302         if (di_flags & XFS_DIFLAG_SYNC)
7303 @@ -851,6 +857,8 @@ xfs_set_diflags(
7304         di_flags = (ip->i_d.di_flags & XFS_DIFLAG_PREALLOC);
7305         if (xflags & XFS_XFLAG_IMMUTABLE)
7306                 di_flags |= XFS_DIFLAG_IMMUTABLE;
7307 +       if (xflags & XFS_XFLAG_IXUNLINK)
7308 +               di_flags |= XFS_DIFLAG_IXUNLINK;
7309         if (xflags & XFS_XFLAG_APPEND)
7310                 di_flags |= XFS_DIFLAG_APPEND;
7311         if (xflags & XFS_XFLAG_SYNC)
7312 @@ -893,6 +901,10 @@ xfs_diflags_to_linux(
7313                 inode->i_flags |= S_IMMUTABLE;
7314         else
7315                 inode->i_flags &= ~S_IMMUTABLE;
7316 +       if (xflags & XFS_XFLAG_IXUNLINK)
7317 +               inode->i_flags |= S_IXUNLINK;
7318 +       else
7319 +               inode->i_flags &= ~S_IXUNLINK;
7320         if (xflags & XFS_XFLAG_APPEND)
7321                 inode->i_flags |= S_APPEND;
7322         else
7323 @@ -1397,10 +1409,18 @@ xfs_file_ioctl(
7324         case XFS_IOC_FSGETXATTRA:
7325                 return xfs_ioc_fsgetxattr(ip, 1, arg);
7326         case XFS_IOC_FSSETXATTR:
7327 +               if (IS_BARRIER(inode)) {
7328 +                       vxwprintk_task(1, "messing with the barrier.");
7329 +                       return -XFS_ERROR(EACCES);
7330 +               }
7331                 return xfs_ioc_fssetxattr(ip, filp, arg);
7332         case XFS_IOC_GETXFLAGS:
7333                 return xfs_ioc_getxflags(ip, arg);
7334         case XFS_IOC_SETXFLAGS:
7335 +               if (IS_BARRIER(inode)) {
7336 +                       vxwprintk_task(1, "messing with the barrier.");
7337 +                       return -XFS_ERROR(EACCES);
7338 +               }
7339                 return xfs_ioc_setxflags(ip, filp, arg);
7340  
7341         case XFS_IOC_FSSETDM: {
7342 diff -NurpP --minimal linux-3.9.4/fs/xfs/xfs_ioctl.h linux-3.9.4-vs2.3.6.2/fs/xfs/xfs_ioctl.h
7343 --- linux-3.9.4/fs/xfs/xfs_ioctl.h      2012-12-11 03:30:57.000000000 +0000
7344 +++ linux-3.9.4-vs2.3.6.2/fs/xfs/xfs_ioctl.h    2013-05-31 14:47:11.000000000 +0000
7345 @@ -70,6 +70,12 @@ xfs_handle_to_dentry(
7346         void __user             *uhandle,
7347         u32                     hlen);
7348  
7349 +extern int
7350 +xfs_sync_flags(
7351 +       struct inode            *inode,
7352 +       int                     flags,
7353 +       int                     vflags);
7354 +
7355  extern long
7356  xfs_file_ioctl(
7357         struct file             *filp,
7358 diff -NurpP --minimal linux-3.9.4/fs/xfs/xfs_iops.c linux-3.9.4-vs2.3.6.2/fs/xfs/xfs_iops.c
7359 --- linux-3.9.4/fs/xfs/xfs_iops.c       2013-02-19 13:58:49.000000000 +0000
7360 +++ linux-3.9.4-vs2.3.6.2/fs/xfs/xfs_iops.c     2013-05-31 14:47:11.000000000 +0000
7361 @@ -28,6 +28,7 @@
7362  #include "xfs_bmap_btree.h"
7363  #include "xfs_dinode.h"
7364  #include "xfs_inode.h"
7365 +#include "xfs_ioctl.h"
7366  #include "xfs_bmap.h"
7367  #include "xfs_rtalloc.h"
7368  #include "xfs_error.h"
7369 @@ -47,6 +48,7 @@
7370  #include <linux/security.h>
7371  #include <linux/fiemap.h>
7372  #include <linux/slab.h>
7373 +#include <linux/vs_tag.h>
7374  
7375  static int
7376  xfs_initxattrs(
7377 @@ -422,6 +424,7 @@ xfs_vn_getattr(
7378         stat->nlink = ip->i_d.di_nlink;
7379         stat->uid = ip->i_d.di_uid;
7380         stat->gid = ip->i_d.di_gid;
7381 +       stat->tag = ip->i_d.di_tag;
7382         stat->ino = ip->i_ino;
7383         stat->atime = inode->i_atime;
7384         stat->mtime = inode->i_mtime;
7385 @@ -1037,6 +1040,7 @@ static const struct inode_operations xfs
7386         .listxattr              = xfs_vn_listxattr,
7387         .fiemap                 = xfs_vn_fiemap,
7388         .update_time            = xfs_vn_update_time,
7389 +       .sync_flags             = xfs_sync_flags,
7390  };
7391  
7392  static const struct inode_operations xfs_dir_inode_operations = {
7393 @@ -1063,6 +1067,7 @@ static const struct inode_operations xfs
7394         .removexattr            = generic_removexattr,
7395         .listxattr              = xfs_vn_listxattr,
7396         .update_time            = xfs_vn_update_time,
7397 +       .sync_flags             = xfs_sync_flags,
7398  };
7399  
7400  static const struct inode_operations xfs_dir_ci_inode_operations = {
7401 @@ -1114,6 +1119,10 @@ xfs_diflags_to_iflags(
7402                 inode->i_flags |= S_IMMUTABLE;
7403         else
7404                 inode->i_flags &= ~S_IMMUTABLE;
7405 +       if (ip->i_d.di_flags & XFS_DIFLAG_IXUNLINK)
7406 +               inode->i_flags |= S_IXUNLINK;
7407 +       else
7408 +               inode->i_flags &= ~S_IXUNLINK;
7409         if (ip->i_d.di_flags & XFS_DIFLAG_APPEND)
7410                 inode->i_flags |= S_APPEND;
7411         else
7412 @@ -1126,6 +1135,15 @@ xfs_diflags_to_iflags(
7413                 inode->i_flags |= S_NOATIME;
7414         else
7415                 inode->i_flags &= ~S_NOATIME;
7416 +
7417 +       if (ip->i_d.di_vflags & XFS_DIVFLAG_BARRIER)
7418 +               inode->i_vflags |= V_BARRIER;
7419 +       else
7420 +               inode->i_vflags &= ~V_BARRIER;
7421 +       if (ip->i_d.di_vflags & XFS_DIVFLAG_COW)
7422 +               inode->i_vflags |= V_COW;
7423 +       else
7424 +               inode->i_vflags &= ~V_COW;
7425  }
7426  
7427  /*
7428 @@ -1157,6 +1175,7 @@ xfs_setup_inode(
7429         set_nlink(inode, ip->i_d.di_nlink);
7430         inode->i_uid    = ip->i_d.di_uid;
7431         inode->i_gid    = ip->i_d.di_gid;
7432 +       inode->i_tag    = ip->i_d.di_tag;
7433  
7434         switch (inode->i_mode & S_IFMT) {
7435         case S_IFBLK:
7436 diff -NurpP --minimal linux-3.9.4/fs/xfs/xfs_itable.c linux-3.9.4-vs2.3.6.2/fs/xfs/xfs_itable.c
7437 --- linux-3.9.4/fs/xfs/xfs_itable.c     2013-02-19 13:58:49.000000000 +0000
7438 +++ linux-3.9.4-vs2.3.6.2/fs/xfs/xfs_itable.c   2013-05-31 14:47:11.000000000 +0000
7439 @@ -97,6 +97,7 @@ xfs_bulkstat_one_int(
7440         buf->bs_mode = dic->di_mode;
7441         buf->bs_uid = dic->di_uid;
7442         buf->bs_gid = dic->di_gid;
7443 +       buf->bs_tag = dic->di_tag;
7444         buf->bs_size = dic->di_size;
7445         buf->bs_atime.tv_sec = dic->di_atime.t_sec;
7446         buf->bs_atime.tv_nsec = dic->di_atime.t_nsec;
7447 diff -NurpP --minimal linux-3.9.4/fs/xfs/xfs_linux.h linux-3.9.4-vs2.3.6.2/fs/xfs/xfs_linux.h
7448 --- linux-3.9.4/fs/xfs/xfs_linux.h      2013-02-19 13:58:49.000000000 +0000
7449 +++ linux-3.9.4-vs2.3.6.2/fs/xfs/xfs_linux.h    2013-05-31 14:47:11.000000000 +0000
7450 @@ -123,6 +123,7 @@
7451  
7452  #define current_cpu()          (raw_smp_processor_id())
7453  #define current_pid()          (current->pid)
7454 +#define current_fstag(vp)      (dx_current_fstag((vp)->i_sb))
7455  #define current_test_flags(f)  (current->flags & (f))
7456  #define current_set_flags_nested(sp, f)                \
7457                 (*(sp) = current->flags, current->flags |= (f))
7458 diff -NurpP --minimal linux-3.9.4/fs/xfs/xfs_log_recover.c linux-3.9.4-vs2.3.6.2/fs/xfs/xfs_log_recover.c
7459 --- linux-3.9.4/fs/xfs/xfs_log_recover.c        2013-05-31 13:45:25.000000000 +0000
7460 +++ linux-3.9.4-vs2.3.6.2/fs/xfs/xfs_log_recover.c      2013-05-31 14:47:11.000000000 +0000
7461 @@ -2361,7 +2361,8 @@ xlog_recover_inode_pass2(
7462         }
7463  
7464         /* The core is in in-core format */
7465 -       xfs_dinode_to_disk(dip, item->ri_buf[1].i_addr);
7466 +       xfs_dinode_to_disk(dip, item->ri_buf[1].i_addr,
7467 +               mp->m_flags & XFS_MOUNT_TAGGED);
7468  
7469         /* the rest is in on-disk format */
7470         if (item->ri_buf[1].i_len > sizeof(struct xfs_icdinode)) {
7471 diff -NurpP --minimal linux-3.9.4/fs/xfs/xfs_mount.h linux-3.9.4-vs2.3.6.2/fs/xfs/xfs_mount.h
7472 --- linux-3.9.4/fs/xfs/xfs_mount.h      2013-05-31 13:45:25.000000000 +0000
7473 +++ linux-3.9.4-vs2.3.6.2/fs/xfs/xfs_mount.h    2013-05-31 14:47:11.000000000 +0000
7474 @@ -254,6 +254,7 @@ typedef struct xfs_mount {
7475                                                    allocator */
7476  #define XFS_MOUNT_NOATTR2      (1ULL << 25)    /* disable use of attr2 format */
7477  
7478 +#define XFS_MOUNT_TAGGED       (1ULL << 31)    /* context tagging */
7479  
7480  /*
7481   * Default minimum read and write sizes.
7482 diff -NurpP --minimal linux-3.9.4/fs/xfs/xfs_super.c linux-3.9.4-vs2.3.6.2/fs/xfs/xfs_super.c
7483 --- linux-3.9.4/fs/xfs/xfs_super.c      2013-05-31 13:45:25.000000000 +0000
7484 +++ linux-3.9.4-vs2.3.6.2/fs/xfs/xfs_super.c    2013-05-31 14:47:11.000000000 +0000
7485 @@ -114,6 +114,9 @@ mempool_t *xfs_ioend_pool;
7486  #define MNTOPT_NODELAYLOG  "nodelaylog"        /* Delayed logging disabled */
7487  #define MNTOPT_DISCARD    "discard"    /* Discard unused blocks */
7488  #define MNTOPT_NODISCARD   "nodiscard" /* Do not discard unused blocks */
7489 +#define MNTOPT_TAGXID  "tagxid"        /* context tagging for inodes */
7490 +#define MNTOPT_TAGGED  "tag"           /* context tagging for inodes */
7491 +#define MNTOPT_NOTAGTAG        "notag"         /* do not use context tagging */
7492  
7493  /*
7494   * Table driven mount option parser.
7495 @@ -126,6 +129,8 @@ enum {
7496         Opt_nobarrier,
7497         Opt_inode64,
7498         Opt_inode32,
7499 +       Opt_tag,
7500 +       Opt_notag,
7501         Opt_err
7502  };
7503  
7504 @@ -134,6 +139,9 @@ static const match_table_t tokens = {
7505         {Opt_nobarrier, "nobarrier"},
7506         {Opt_inode64, "inode64"},
7507         {Opt_inode32, "inode32"},
7508 +       {Opt_tag, "tagxid"},
7509 +       {Opt_tag, "tag"},
7510 +       {Opt_notag, "notag"},
7511         {Opt_err, NULL}
7512  };
7513  
7514 @@ -392,6 +400,19 @@ xfs_parseargs(
7515                 } else if (!strcmp(this_char, "irixsgid")) {
7516                         xfs_warn(mp,
7517         "irixsgid is now a sysctl(2) variable, option is deprecated.");
7518 +#ifndef CONFIG_TAGGING_NONE
7519 +               } else if (!strcmp(this_char, MNTOPT_TAGGED)) {
7520 +                       mp->m_flags |= XFS_MOUNT_TAGGED;
7521 +               } else if (!strcmp(this_char, MNTOPT_NOTAGTAG)) {
7522 +                       mp->m_flags &= ~XFS_MOUNT_TAGGED;
7523 +               } else if (!strcmp(this_char, MNTOPT_TAGXID)) {
7524 +                       mp->m_flags |= XFS_MOUNT_TAGGED;
7525 +#endif
7526 +#ifdef CONFIG_PROPAGATE
7527 +               } else if (!strcmp(this_char, MNTOPT_TAGGED)) {
7528 +                       /* use value */
7529 +                       mp->m_flags |= XFS_MOUNT_TAGGED;
7530 +#endif
7531                 } else {
7532                         xfs_warn(mp, "unknown mount option [%s].", this_char);
7533                         return EINVAL;
7534 @@ -1238,6 +1259,16 @@ xfs_fs_remount(
7535                 case Opt_inode32:
7536                         mp->m_maxagi = xfs_set_inode32(mp);
7537                         break;
7538 +               case Opt_tag:
7539 +                       if (!(sb->s_flags & MS_TAGGED)) {
7540 +                               printk(KERN_INFO
7541 +                                       "XFS: %s: tagging not permitted on remount.\n",
7542 +                                       sb->s_id);
7543 +                               return -EINVAL;
7544 +                       }
7545 +                       break;
7546 +               case Opt_notag:
7547 +                       break;
7548                 default:
7549                         /*
7550                          * Logically we would return an error here to prevent
7551 @@ -1458,6 +1489,9 @@ xfs_fs_fill_super(
7552         if (error)
7553                 goto out_free_sb;
7554  
7555 +       if (mp->m_flags & XFS_MOUNT_TAGGED)
7556 +               sb->s_flags |= MS_TAGGED;
7557 +
7558         /*
7559          * we must configure the block size in the superblock before we run the
7560          * full mount process as the mount process can lookup and cache inodes.
7561 diff -NurpP --minimal linux-3.9.4/fs/xfs/xfs_vnodeops.c linux-3.9.4-vs2.3.6.2/fs/xfs/xfs_vnodeops.c
7562 --- linux-3.9.4/fs/xfs/xfs_vnodeops.c   2013-05-31 13:45:25.000000000 +0000
7563 +++ linux-3.9.4-vs2.3.6.2/fs/xfs/xfs_vnodeops.c 2013-05-31 14:47:11.000000000 +0000
7564 @@ -104,6 +104,77 @@ xfs_readlink_bmap(
7565         return error;
7566  }
7567  
7568 +
7569 +STATIC void
7570 +xfs_get_inode_flags(
7571 +       xfs_inode_t     *ip)
7572 +{
7573 +       struct inode    *inode = VFS_I(ip);
7574 +       unsigned int    flags = inode->i_flags;
7575 +       unsigned int    vflags = inode->i_vflags;
7576 +
7577 +       if (flags & S_IMMUTABLE)
7578 +               ip->i_d.di_flags |= XFS_DIFLAG_IMMUTABLE;
7579 +       else
7580 +               ip->i_d.di_flags &= ~XFS_DIFLAG_IMMUTABLE;
7581 +       if (flags & S_IXUNLINK)
7582 +               ip->i_d.di_flags |= XFS_DIFLAG_IXUNLINK;
7583 +       else
7584 +               ip->i_d.di_flags &= ~XFS_DIFLAG_IXUNLINK;
7585 +
7586 +       if (vflags & V_BARRIER)
7587 +               ip->i_d.di_vflags |= XFS_DIVFLAG_BARRIER;
7588 +       else
7589 +               ip->i_d.di_vflags &= ~XFS_DIVFLAG_BARRIER;
7590 +       if (vflags & V_COW)
7591 +               ip->i_d.di_vflags |= XFS_DIVFLAG_COW;
7592 +       else
7593 +               ip->i_d.di_vflags &= ~XFS_DIVFLAG_COW;
7594 +}
7595 +
7596 +int
7597 +xfs_sync_flags(
7598 +       struct inode            *inode,
7599 +       int                     flags,
7600 +       int                     vflags)
7601 +{
7602 +       struct xfs_inode        *ip = XFS_I(inode);
7603 +       struct xfs_mount        *mp = ip->i_mount;
7604 +       struct xfs_trans        *tp;
7605 +       unsigned int            lock_flags = 0;
7606 +       int                     code;
7607 +
7608 +       tp = xfs_trans_alloc(mp, XFS_TRANS_SETATTR_NOT_SIZE);
7609 +       code = xfs_trans_reserve(tp, 0, XFS_ICHANGE_LOG_RES(mp), 0, 0, 0);
7610 +       if (code)
7611 +               goto error_out;
7612 +
7613 +       xfs_ilock(ip, XFS_ILOCK_EXCL);
7614 +       xfs_trans_ijoin(tp, ip, 0);
7615 +
7616 +       inode->i_flags = flags;
7617 +       inode->i_vflags = vflags;
7618 +       xfs_get_inode_flags(ip);
7619 +
7620 +       xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE);
7621 +       xfs_trans_ichgtime(tp, ip, XFS_ICHGTIME_CHG);
7622 +
7623 +       XFS_STATS_INC(xs_ig_attrchg);
7624 +
7625 +       if (mp->m_flags & XFS_MOUNT_WSYNC)
7626 +               xfs_trans_set_sync(tp);
7627 +       code = xfs_trans_commit(tp, 0);
7628 +       xfs_iunlock(ip, XFS_ILOCK_EXCL);
7629 +       return code;
7630 +
7631 +error_out:
7632 +       xfs_trans_cancel(tp, 0);
7633 +       if (lock_flags)
7634 +               xfs_iunlock(ip, XFS_ILOCK_EXCL);
7635 +       return code;
7636 +}
7637 +
7638 +
7639  int
7640  xfs_readlink(
7641         xfs_inode_t     *ip,
7642 diff -NurpP --minimal linux-3.9.4/include/linux/cred.h linux-3.9.4-vs2.3.6.2/include/linux/cred.h
7643 --- linux-3.9.4/include/linux/cred.h    2013-02-19 13:58:50.000000000 +0000
7644 +++ linux-3.9.4-vs2.3.6.2/include/linux/cred.h  2013-05-31 14:47:11.000000000 +0000
7645 @@ -143,6 +143,7 @@ extern void exit_creds(struct task_struc
7646  extern int copy_creds(struct task_struct *, unsigned long);
7647  extern const struct cred *get_task_cred(struct task_struct *);
7648  extern struct cred *cred_alloc_blank(void);
7649 +extern struct cred *__prepare_creds(const struct cred *);
7650  extern struct cred *prepare_creds(void);
7651  extern struct cred *prepare_exec_creds(void);
7652  extern int commit_creds(struct cred *);
7653 @@ -196,6 +197,31 @@ static inline void validate_process_cred
7654  }
7655  #endif
7656  
7657 +static inline void set_cred_subscribers(struct cred *cred, int n)
7658 +{
7659 +#ifdef CONFIG_DEBUG_CREDENTIALS
7660 +       atomic_set(&cred->subscribers, n);
7661 +#endif
7662 +}
7663 +
7664 +static inline int read_cred_subscribers(const struct cred *cred)
7665 +{
7666 +#ifdef CONFIG_DEBUG_CREDENTIALS
7667 +       return atomic_read(&cred->subscribers);
7668 +#else
7669 +       return 0;
7670 +#endif
7671 +}
7672 +
7673 +static inline void alter_cred_subscribers(const struct cred *_cred, int n)
7674 +{
7675 +#ifdef CONFIG_DEBUG_CREDENTIALS
7676 +       struct cred *cred = (struct cred *) _cred;
7677 +
7678 +       atomic_add(n, &cred->subscribers);
7679 +#endif
7680 +}
7681 +
7682  /**
7683   * get_new_cred - Get a reference on a new set of credentials
7684   * @cred: The new credentials to reference
7685 diff -NurpP --minimal linux-3.9.4/include/linux/devpts_fs.h linux-3.9.4-vs2.3.6.2/include/linux/devpts_fs.h
7686 --- linux-3.9.4/include/linux/devpts_fs.h       2013-02-19 13:58:50.000000000 +0000
7687 +++ linux-3.9.4-vs2.3.6.2/include/linux/devpts_fs.h     2013-05-31 14:47:11.000000000 +0000
7688 @@ -45,5 +45,4 @@ static inline void devpts_pty_kill(struc
7689  
7690  #endif
7691  
7692 -
7693  #endif /* _LINUX_DEVPTS_FS_H */
7694 diff -NurpP --minimal linux-3.9.4/include/linux/fs.h linux-3.9.4-vs2.3.6.2/include/linux/fs.h
7695 --- linux-3.9.4/include/linux/fs.h      2013-05-31 13:45:27.000000000 +0000
7696 +++ linux-3.9.4-vs2.3.6.2/include/linux/fs.h    2013-05-31 14:47:11.000000000 +0000
7697 @@ -211,6 +211,7 @@ typedef void (dio_iodone_t)(struct kiocb
7698  #define ATTR_KILL_PRIV (1 << 14)
7699  #define ATTR_OPEN      (1 << 15) /* Truncating from open(O_TRUNC) */
7700  #define ATTR_TIMES_SET (1 << 16)
7701 +#define ATTR_TAG       (1 << 17)
7702  
7703  /*
7704   * This is the Inode Attributes structure, used for notify_change().  It
7705 @@ -226,6 +227,7 @@ struct iattr {
7706         umode_t         ia_mode;
7707         kuid_t          ia_uid;
7708         kgid_t          ia_gid;
7709 +       ktag_t          ia_tag;
7710         loff_t          ia_size;
7711         struct timespec ia_atime;
7712         struct timespec ia_mtime;
7713 @@ -523,7 +525,9 @@ struct inode {
7714         unsigned short          i_opflags;
7715         kuid_t                  i_uid;
7716         kgid_t                  i_gid;
7717 -       unsigned int            i_flags;
7718 +       ktag_t                  i_tag;
7719 +       unsigned short          i_flags;
7720 +       unsigned short          i_vflags;
7721  
7722  #ifdef CONFIG_FS_POSIX_ACL
7723         struct posix_acl        *i_acl;
7724 @@ -552,6 +556,7 @@ struct inode {
7725                 unsigned int __i_nlink;
7726         };
7727         dev_t                   i_rdev;
7728 +       dev_t                   i_mdev;
7729         loff_t                  i_size;
7730         struct timespec         i_atime;
7731         struct timespec         i_mtime;
7732 @@ -702,6 +707,11 @@ static inline gid_t i_gid_read(const str
7733         return from_kgid(&init_user_ns, inode->i_gid);
7734  }
7735  
7736 +static inline tag_t i_tag_read(const struct inode *inode)
7737 +{
7738 +       return from_ktag(&init_user_ns, inode->i_tag);
7739 +}
7740 +
7741  static inline void i_uid_write(struct inode *inode, uid_t uid)
7742  {
7743         inode->i_uid = make_kuid(&init_user_ns, uid);
7744 @@ -712,14 +722,19 @@ static inline void i_gid_write(struct in
7745         inode->i_gid = make_kgid(&init_user_ns, gid);
7746  }
7747  
7748 +static inline void i_tag_write(struct inode *inode, tag_t tag)
7749 +{
7750 +       inode->i_tag = make_ktag(&init_user_ns, tag);
7751 +}
7752 +
7753  static inline unsigned iminor(const struct inode *inode)
7754  {
7755 -       return MINOR(inode->i_rdev);
7756 +       return MINOR(inode->i_mdev);
7757  }
7758  
7759  static inline unsigned imajor(const struct inode *inode)
7760  {
7761 -       return MAJOR(inode->i_rdev);
7762 +       return MAJOR(inode->i_mdev);
7763  }
7764  
7765  extern struct block_device *I_BDEV(struct inode *inode);
7766 @@ -786,6 +801,7 @@ struct file {
7767         loff_t                  f_pos;
7768         struct fown_struct      f_owner;
7769         const struct cred       *f_cred;
7770 +       xid_t                   f_xid;
7771         struct file_ra_state    f_ra;
7772  
7773         u64                     f_version;
7774 @@ -937,6 +953,7 @@ struct file_lock {
7775         struct file *fl_file;
7776         loff_t fl_start;
7777         loff_t fl_end;
7778 +       xid_t fl_xid;
7779  
7780         struct fasync_struct *  fl_fasync; /* for lease break notifications */
7781         /* for lease breaks: */
7782 @@ -1567,6 +1584,7 @@ struct inode_operations {
7783         ssize_t (*getxattr) (struct dentry *, const char *, void *, size_t);
7784         ssize_t (*listxattr) (struct dentry *, char *, size_t);
7785         int (*removexattr) (struct dentry *, const char *);
7786 +       int (*sync_flags) (struct inode *, int, int);
7787         int (*fiemap)(struct inode *, struct fiemap_extent_info *, u64 start,
7788                       u64 len);
7789         int (*update_time)(struct inode *, struct timespec *, int);
7790 @@ -1579,6 +1597,7 @@ ssize_t rw_copy_check_uvector(int type,
7791                               unsigned long nr_segs, unsigned long fast_segs,
7792                               struct iovec *fast_pointer,
7793                               struct iovec **ret_pointer);
7794 +ssize_t vfs_sendfile(struct file *, struct file *, loff_t *, size_t, loff_t);
7795  
7796  extern ssize_t vfs_read(struct file *, char __user *, size_t, loff_t *);
7797  extern ssize_t vfs_write(struct file *, const char __user *, size_t, loff_t *);
7798 @@ -1632,6 +1651,14 @@ struct super_operations {
7799  #define S_IMA          1024    /* Inode has an associated IMA struct */
7800  #define S_AUTOMOUNT    2048    /* Automount/referral quasi-directory */
7801  #define S_NOSEC                4096    /* no suid or xattr security attributes */
7802 +#define S_IXUNLINK     8192    /* Immutable Invert on unlink */
7803 +
7804 +/* Linux-VServer related Inode flags */
7805 +
7806 +#define V_VALID                1
7807 +#define V_XATTR                2
7808 +#define V_BARRIER      4       /* Barrier for chroot() */
7809 +#define V_COW          8       /* Copy on Write */
7810  
7811  /*
7812   * Note that nosuid etc flags are inode-specific: setting some file-system
7813 @@ -1656,10 +1683,13 @@ struct super_operations {
7814  #define IS_MANDLOCK(inode)     __IS_FLG(inode, MS_MANDLOCK)
7815  #define IS_NOATIME(inode)      __IS_FLG(inode, MS_RDONLY|MS_NOATIME)
7816  #define IS_I_VERSION(inode)    __IS_FLG(inode, MS_I_VERSION)
7817 +#define IS_TAGGED(inode)       __IS_FLG(inode, MS_TAGGED)
7818  
7819  #define IS_NOQUOTA(inode)      ((inode)->i_flags & S_NOQUOTA)
7820  #define IS_APPEND(inode)       ((inode)->i_flags & S_APPEND)
7821  #define IS_IMMUTABLE(inode)    ((inode)->i_flags & S_IMMUTABLE)
7822 +#define IS_IXUNLINK(inode)     ((inode)->i_flags & S_IXUNLINK)
7823 +#define IS_IXORUNLINK(inode)   ((IS_IXUNLINK(inode) ? S_IMMUTABLE : 0) ^ IS_IMMUTABLE(inode))
7824  #define IS_POSIXACL(inode)     __IS_FLG(inode, MS_POSIXACL)
7825  
7826  #define IS_DEADDIR(inode)      ((inode)->i_flags & S_DEAD)
7827 @@ -1670,6 +1700,16 @@ struct super_operations {
7828  #define IS_AUTOMOUNT(inode)    ((inode)->i_flags & S_AUTOMOUNT)
7829  #define IS_NOSEC(inode)                ((inode)->i_flags & S_NOSEC)
7830  
7831 +#define IS_BARRIER(inode)      (S_ISDIR((inode)->i_mode) && ((inode)->i_vflags & V_BARRIER))
7832 +
7833 +#ifdef CONFIG_VSERVER_COWBL
7834 +#  define IS_COW(inode)                (IS_IXUNLINK(inode) && IS_IMMUTABLE(inode))
7835 +#  define IS_COW_LINK(inode)   (S_ISREG((inode)->i_mode) && ((inode)->i_nlink > 1))
7836 +#else
7837 +#  define IS_COW(inode)                (0)
7838 +#  define IS_COW_LINK(inode)   (0)
7839 +#endif
7840 +
7841  /*
7842   * Inode state bits.  Protected by inode->i_lock
7843   *
7844 @@ -1898,6 +1938,9 @@ extern int rw_verify_area(int, struct fi
7845  extern int locks_mandatory_locked(struct inode *);
7846  extern int locks_mandatory_area(int, struct inode *, struct file *, loff_t, size_t);
7847  
7848 +#define ATTR_FLAG_BARRIER      512     /* Barrier for chroot() */
7849 +#define ATTR_FLAG_IXUNLINK     1024    /* Immutable invert on unlink */
7850 +
7851  /*
7852   * Candidates for mandatory locking have the setgid bit set
7853   * but no group execute bit -  an otherwise meaningless combination.
7854 @@ -2509,6 +2552,7 @@ extern int dcache_dir_open(struct inode
7855  extern int dcache_dir_close(struct inode *, struct file *);
7856  extern loff_t dcache_dir_lseek(struct file *, loff_t, int);
7857  extern int dcache_readdir(struct file *, void *, filldir_t);
7858 +extern int dcache_readdir_filter(struct file *, void *, filldir_t, int (*)(struct dentry *));
7859  extern int simple_setattr(struct dentry *, struct iattr *);
7860  extern int simple_getattr(struct vfsmount *, struct dentry *, struct kstat *);
7861  extern int simple_statfs(struct dentry *, struct kstatfs *);
7862 diff -NurpP --minimal linux-3.9.4/include/linux/init_task.h linux-3.9.4-vs2.3.6.2/include/linux/init_task.h
7863 --- linux-3.9.4/include/linux/init_task.h       2013-05-31 13:45:27.000000000 +0000
7864 +++ linux-3.9.4-vs2.3.6.2/include/linux/init_task.h     2013-05-31 14:53:41.000000000 +0000
7865 @@ -222,6 +222,10 @@ extern struct task_group root_task_group
7866         INIT_TASK_RCU_PREEMPT(tsk)                                      \
7867         INIT_CPUSET_SEQ                                                 \
7868         INIT_VTIME(tsk)                                                 \
7869 +       .xid            = 0,                                            \
7870 +       .vx_info        = NULL,                                         \
7871 +       .nid            = 0,                                            \
7872 +       .nx_info        = NULL,                                         \
7873  }
7874  
7875  
7876 diff -NurpP --minimal linux-3.9.4/include/linux/ipc.h linux-3.9.4-vs2.3.6.2/include/linux/ipc.h
7877 --- linux-3.9.4/include/linux/ipc.h     2012-12-11 03:30:57.000000000 +0000
7878 +++ linux-3.9.4-vs2.3.6.2/include/linux/ipc.h   2013-05-31 14:47:11.000000000 +0000
7879 @@ -16,6 +16,7 @@ struct kern_ipc_perm
7880         key_t           key;
7881         kuid_t          uid;
7882         kgid_t          gid;
7883 +       xid_t           xid;
7884         kuid_t          cuid;
7885         kgid_t          cgid;
7886         umode_t         mode; 
7887 diff -NurpP --minimal linux-3.9.4/include/linux/loop.h linux-3.9.4-vs2.3.6.2/include/linux/loop.h
7888 --- linux-3.9.4/include/linux/loop.h    2013-02-19 13:58:51.000000000 +0000
7889 +++ linux-3.9.4-vs2.3.6.2/include/linux/loop.h  2013-05-31 14:47:11.000000000 +0000
7890 @@ -41,6 +41,7 @@ struct loop_device {
7891         struct loop_func_table *lo_encryption;
7892         __u32           lo_init[2];
7893         kuid_t          lo_key_owner;   /* Who set the key */
7894 +       xid_t           lo_xid;
7895         int             (*ioctl)(struct loop_device *, int cmd, 
7896                                  unsigned long arg); 
7897  
7898 diff -NurpP --minimal linux-3.9.4/include/linux/memcontrol.h linux-3.9.4-vs2.3.6.2/include/linux/memcontrol.h
7899 --- linux-3.9.4/include/linux/memcontrol.h      2013-05-31 13:45:28.000000000 +0000
7900 +++ linux-3.9.4-vs2.3.6.2/include/linux/memcontrol.h    2013-05-31 14:47:11.000000000 +0000
7901 @@ -86,6 +86,13 @@ extern struct mem_cgroup *try_get_mem_cg
7902  extern struct mem_cgroup *parent_mem_cgroup(struct mem_cgroup *memcg);
7903  extern struct mem_cgroup *mem_cgroup_from_cont(struct cgroup *cont);
7904  
7905 +extern u64 mem_cgroup_res_read_u64(struct mem_cgroup *mem, int member);
7906 +extern u64 mem_cgroup_memsw_read_u64(struct mem_cgroup *mem, int member);
7907 +
7908 +extern s64 mem_cgroup_stat_read_cache(struct mem_cgroup *mem);
7909 +extern s64 mem_cgroup_stat_read_anon(struct mem_cgroup *mem);
7910 +extern s64 mem_cgroup_stat_read_mapped(struct mem_cgroup *mem);
7911 +
7912  static inline
7913  bool mm_match_cgroup(const struct mm_struct *mm, const struct mem_cgroup *memcg)
7914  {
7915 diff -NurpP --minimal linux-3.9.4/include/linux/mm_types.h linux-3.9.4-vs2.3.6.2/include/linux/mm_types.h
7916 --- linux-3.9.4/include/linux/mm_types.h        2013-05-31 13:45:28.000000000 +0000
7917 +++ linux-3.9.4-vs2.3.6.2/include/linux/mm_types.h      2013-05-31 14:47:11.000000000 +0000
7918 @@ -380,6 +380,7 @@ struct mm_struct {
7919  
7920         /* Architecture-specific MM context */
7921         mm_context_t context;
7922 +       struct vx_info *mm_vx_info;
7923  
7924         unsigned long flags; /* Must use atomic bitops to access the bits */
7925  
7926 diff -NurpP --minimal linux-3.9.4/include/linux/mount.h linux-3.9.4-vs2.3.6.2/include/linux/mount.h
7927 --- linux-3.9.4/include/linux/mount.h   2013-05-31 13:45:28.000000000 +0000
7928 +++ linux-3.9.4-vs2.3.6.2/include/linux/mount.h 2013-05-31 14:47:11.000000000 +0000
7929 @@ -49,6 +49,9 @@ struct mnt_namespace;
7930  
7931  #define MNT_LOCK_READONLY      0x400000
7932  
7933 +#define MNT_TAGID      0x10000
7934 +#define MNT_NOTAG      0x20000
7935 +
7936  struct vfsmount {
7937         struct dentry *mnt_root;        /* root of the mounted tree */
7938         struct super_block *mnt_sb;     /* pointer to superblock */
7939 diff -NurpP --minimal linux-3.9.4/include/linux/net.h linux-3.9.4-vs2.3.6.2/include/linux/net.h
7940 --- linux-3.9.4/include/linux/net.h     2012-12-11 03:30:57.000000000 +0000
7941 +++ linux-3.9.4-vs2.3.6.2/include/linux/net.h   2013-05-31 14:47:11.000000000 +0000
7942 @@ -38,6 +38,7 @@ struct net;
7943  #define SOCK_PASSCRED          3
7944  #define SOCK_PASSSEC           4
7945  #define SOCK_EXTERNALLY_ALLOCATED 5
7946 +#define SOCK_USER_SOCKET       6
7947  
7948  #ifndef ARCH_HAS_SOCKET_TYPES
7949  /**
7950 diff -NurpP --minimal linux-3.9.4/include/linux/netdevice.h linux-3.9.4-vs2.3.6.2/include/linux/netdevice.h
7951 --- linux-3.9.4/include/linux/netdevice.h       2013-05-31 13:45:28.000000000 +0000
7952 +++ linux-3.9.4-vs2.3.6.2/include/linux/netdevice.h     2013-05-31 14:47:11.000000000 +0000
7953 @@ -1688,6 +1688,7 @@ extern void               netdev_resync_ops(struct ne
7954  
7955  extern struct net_device       *dev_get_by_index(struct net *net, int ifindex);
7956  extern struct net_device       *__dev_get_by_index(struct net *net, int ifindex);
7957 +extern struct net_device       *dev_get_by_index_real_rcu(struct net *net, int ifindex);
7958  extern struct net_device       *dev_get_by_index_rcu(struct net *net, int ifindex);
7959  extern int             dev_restart(struct net_device *dev);
7960  #ifdef CONFIG_NETPOLL_TRAP
7961 diff -NurpP --minimal linux-3.9.4/include/linux/nsproxy.h linux-3.9.4-vs2.3.6.2/include/linux/nsproxy.h
7962 --- linux-3.9.4/include/linux/nsproxy.h 2013-02-19 13:58:51.000000000 +0000
7963 +++ linux-3.9.4-vs2.3.6.2/include/linux/nsproxy.h       2013-05-31 17:17:53.000000000 +0000
7964 @@ -3,6 +3,7 @@
7965  
7966  #include <linux/spinlock.h>
7967  #include <linux/sched.h>
7968 +#include <linux/vserver/debug.h>
7969  
7970  struct mnt_namespace;
7971  struct uts_namespace;
7972 @@ -63,6 +64,7 @@ static inline struct nsproxy *task_nspro
7973  }
7974  
7975  int copy_namespaces(unsigned long flags, struct task_struct *tsk);
7976 +struct nsproxy *copy_nsproxy(struct nsproxy *orig);
7977  void exit_task_namespaces(struct task_struct *tsk);
7978  void switch_task_namespaces(struct task_struct *tsk, struct nsproxy *new);
7979  void free_nsproxy(struct nsproxy *ns);
7980 @@ -70,16 +72,26 @@ int unshare_nsproxy_namespaces(unsigned
7981         struct cred *, struct fs_struct *);
7982  int __init nsproxy_cache_init(void);
7983  
7984 -static inline void put_nsproxy(struct nsproxy *ns)
7985 +#define        get_nsproxy(n)  __get_nsproxy(n, __FILE__, __LINE__)
7986 +
7987 +static inline void __get_nsproxy(struct nsproxy *ns,
7988 +       const char *_file, int _line)
7989  {
7990 -       if (atomic_dec_and_test(&ns->count)) {
7991 -               free_nsproxy(ns);
7992 -       }
7993 +       vxlprintk(VXD_CBIT(space, 0), "get_nsproxy(%p[%u])",
7994 +               ns, atomic_read(&ns->count), _file, _line);
7995 +       atomic_inc(&ns->count);
7996  }
7997  
7998 -static inline void get_nsproxy(struct nsproxy *ns)
7999 +#define        put_nsproxy(n)  __put_nsproxy(n, __FILE__, __LINE__)
8000 +
8001 +static inline void __put_nsproxy(struct nsproxy *ns,
8002 +       const char *_file, int _line)
8003  {
8004 -       atomic_inc(&ns->count);
8005 +       vxlprintk(VXD_CBIT(space, 0), "put_nsproxy(%p[%u])",
8006 +               ns, atomic_read(&ns->count), _file, _line);
8007 +       if (atomic_dec_and_test(&ns->count)) {
8008 +               free_nsproxy(ns);
8009 +       }
8010  }
8011  
8012  #endif
8013 diff -NurpP --minimal linux-3.9.4/include/linux/pid.h linux-3.9.4-vs2.3.6.2/include/linux/pid.h
8014 --- linux-3.9.4/include/linux/pid.h     2013-05-31 13:45:28.000000000 +0000
8015 +++ linux-3.9.4-vs2.3.6.2/include/linux/pid.h   2013-05-31 14:47:11.000000000 +0000
8016 @@ -8,7 +8,8 @@ enum pid_type
8017         PIDTYPE_PID,
8018         PIDTYPE_PGID,
8019         PIDTYPE_SID,
8020 -       PIDTYPE_MAX
8021 +       PIDTYPE_MAX,
8022 +       PIDTYPE_REALPID
8023  };
8024  
8025  /*
8026 @@ -172,6 +173,7 @@ static inline pid_t pid_nr(struct pid *p
8027  }
8028  
8029  pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns);
8030 +pid_t pid_unmapped_nr_ns(struct pid *pid, struct pid_namespace *ns);
8031  pid_t pid_vnr(struct pid *pid);
8032  
8033  #define do_each_pid_task(pid, type, task)                              \
8034 diff -NurpP --minimal linux-3.9.4/include/linux/proc_fs.h linux-3.9.4-vs2.3.6.2/include/linux/proc_fs.h
8035 --- linux-3.9.4/include/linux/proc_fs.h 2013-05-31 13:45:28.000000000 +0000
8036 +++ linux-3.9.4-vs2.3.6.2/include/linux/proc_fs.h       2013-05-31 14:47:11.000000000 +0000
8037 @@ -58,6 +58,7 @@ struct proc_dir_entry {
8038         nlink_t nlink;
8039         kuid_t uid;
8040         kgid_t gid;
8041 +       int vx_flags;
8042         loff_t size;
8043         const struct inode_operations *proc_iops;
8044         /*
8045 @@ -274,12 +275,18 @@ extern const struct proc_ns_operations p
8046  extern const struct proc_ns_operations userns_operations;
8047  extern const struct proc_ns_operations mntns_operations;
8048  
8049 +struct vx_info;
8050 +struct nx_info;
8051 +
8052  union proc_op {
8053         int (*proc_get_link)(struct dentry *, struct path *);
8054         int (*proc_read)(struct task_struct *task, char *page);
8055         int (*proc_show)(struct seq_file *m,
8056                 struct pid_namespace *ns, struct pid *pid,
8057                 struct task_struct *task);
8058 +       int (*proc_vs_read)(char *page);
8059 +       int (*proc_vxi_read)(struct vx_info *vxi, char *page);
8060 +       int (*proc_nxi_read)(struct nx_info *nxi, char *page);
8061  };
8062  
8063  struct ctl_table_header;
8064 @@ -287,6 +294,7 @@ struct ctl_table;
8065  
8066  struct proc_inode {
8067         struct pid *pid;
8068 +       int vx_flags;
8069         int fd;
8070         union proc_op op;
8071         struct proc_dir_entry *pde;
8072 diff -NurpP --minimal linux-3.9.4/include/linux/quotaops.h linux-3.9.4-vs2.3.6.2/include/linux/quotaops.h
8073 --- linux-3.9.4/include/linux/quotaops.h        2012-12-11 03:30:57.000000000 +0000
8074 +++ linux-3.9.4-vs2.3.6.2/include/linux/quotaops.h      2013-05-31 14:47:11.000000000 +0000
8075 @@ -8,6 +8,7 @@
8076  #define _LINUX_QUOTAOPS_
8077  
8078  #include <linux/fs.h>
8079 +#include <linux/vs_dlimit.h>
8080  
8081  #define DQUOT_SPACE_WARN       0x1
8082  #define DQUOT_SPACE_RESERVE    0x2
8083 @@ -205,11 +206,12 @@ static inline void dquot_drop(struct ino
8084  
8085  static inline int dquot_alloc_inode(const struct inode *inode)
8086  {
8087 -       return 0;
8088 +       return dl_alloc_inode(inode);
8089  }
8090  
8091  static inline void dquot_free_inode(const struct inode *inode)
8092  {
8093 +       dl_free_inode(inode);
8094  }
8095  
8096  static inline int dquot_transfer(struct inode *inode, struct iattr *iattr)
8097 @@ -220,6 +222,10 @@ static inline int dquot_transfer(struct
8098  static inline int __dquot_alloc_space(struct inode *inode, qsize_t number,
8099                 int flags)
8100  {
8101 +       int ret = 0;
8102 +
8103 +       if ((ret = dl_alloc_space(inode, number)))
8104 +               return ret;
8105         if (!(flags & DQUOT_SPACE_RESERVE))
8106                 inode_add_bytes(inode, number);
8107         return 0;
8108 @@ -230,6 +236,7 @@ static inline void __dquot_free_space(st
8109  {
8110         if (!(flags & DQUOT_SPACE_RESERVE))
8111                 inode_sub_bytes(inode, number);
8112 +       dl_free_space(inode, number);
8113  }
8114  
8115  static inline int dquot_claim_space_nodirty(struct inode *inode, qsize_t number)
8116 diff -NurpP --minimal linux-3.9.4/include/linux/sched.h linux-3.9.4-vs2.3.6.2/include/linux/sched.h
8117 --- linux-3.9.4/include/linux/sched.h   2013-05-31 14:22:27.000000000 +0000
8118 +++ linux-3.9.4-vs2.3.6.2/include/linux/sched.h 2013-05-31 14:47:11.000000000 +0000
8119 @@ -1398,6 +1398,14 @@ struct task_struct {
8120  #endif
8121         struct seccomp seccomp;
8122  
8123 +/* vserver context data */
8124 +       struct vx_info *vx_info;
8125 +       struct nx_info *nx_info;
8126 +
8127 +       xid_t xid;
8128 +       nid_t nid;
8129 +       tag_t tag;
8130 +
8131  /* Thread group tracking */
8132         u32 parent_exec_id;
8133         u32 self_exec_id;
8134 @@ -1637,6 +1645,11 @@ struct pid_namespace;
8135  pid_t __task_pid_nr_ns(struct task_struct *task, enum pid_type type,
8136                         struct pid_namespace *ns);
8137  
8138 +#include <linux/vserver/base.h>
8139 +#include <linux/vserver/context.h>
8140 +#include <linux/vserver/debug.h>
8141 +#include <linux/vserver/pid.h>
8142 +
8143  static inline pid_t task_pid_nr(struct task_struct *tsk)
8144  {
8145         return tsk->pid;
8146 @@ -1650,7 +1663,8 @@ static inline pid_t task_pid_nr_ns(struc
8147  
8148  static inline pid_t task_pid_vnr(struct task_struct *tsk)
8149  {
8150 -       return __task_pid_nr_ns(tsk, PIDTYPE_PID, NULL);
8151 +       // return __task_pid_nr_ns(tsk, PIDTYPE_PID, NULL);
8152 +       return vx_map_pid(__task_pid_nr_ns(tsk, PIDTYPE_PID, NULL));
8153  }
8154  
8155  
8156 @@ -1663,7 +1677,7 @@ pid_t task_tgid_nr_ns(struct task_struct
8157  
8158  static inline pid_t task_tgid_vnr(struct task_struct *tsk)
8159  {
8160 -       return pid_vnr(task_tgid(tsk));
8161 +       return vx_map_tgid(pid_vnr(task_tgid(tsk)));
8162  }
8163  
8164  
8165 diff -NurpP --minimal linux-3.9.4/include/linux/shmem_fs.h linux-3.9.4-vs2.3.6.2/include/linux/shmem_fs.h
8166 --- linux-3.9.4/include/linux/shmem_fs.h        2012-12-11 03:30:57.000000000 +0000
8167 +++ linux-3.9.4-vs2.3.6.2/include/linux/shmem_fs.h      2013-05-31 14:47:11.000000000 +0000
8168 @@ -9,6 +9,9 @@
8169  
8170  /* inode in-kernel data */
8171  
8172 +#define TMPFS_SUPER_MAGIC      0x01021994
8173 +
8174 +
8175  struct shmem_inode_info {
8176         spinlock_t              lock;
8177         unsigned long           flags;
8178 diff -NurpP --minimal linux-3.9.4/include/linux/stat.h linux-3.9.4-vs2.3.6.2/include/linux/stat.h
8179 --- linux-3.9.4/include/linux/stat.h    2012-12-11 03:30:57.000000000 +0000
8180 +++ linux-3.9.4-vs2.3.6.2/include/linux/stat.h  2013-06-01 08:53:13.000000000 +0000
8181 @@ -25,6 +25,7 @@ struct kstat {
8182         unsigned int    nlink;
8183         kuid_t          uid;
8184         kgid_t          gid;
8185 +       ktag_t          tag;
8186         dev_t           rdev;
8187         loff_t          size;
8188         struct timespec  atime;
8189 diff -NurpP --minimal linux-3.9.4/include/linux/sunrpc/auth.h linux-3.9.4-vs2.3.6.2/include/linux/sunrpc/auth.h
8190 --- linux-3.9.4/include/linux/sunrpc/auth.h     2013-05-31 13:45:28.000000000 +0000
8191 +++ linux-3.9.4-vs2.3.6.2/include/linux/sunrpc/auth.h   2013-05-31 14:52:57.000000000 +0000
8192 @@ -26,6 +26,7 @@
8193  struct auth_cred {
8194         kuid_t  uid;
8195         kgid_t  gid;
8196 +       ktag_t  tag;
8197         struct group_info *group_info;
8198         const char *principal;
8199         unsigned char machine_cred : 1;
8200 diff -NurpP --minimal linux-3.9.4/include/linux/sunrpc/clnt.h linux-3.9.4-vs2.3.6.2/include/linux/sunrpc/clnt.h
8201 --- linux-3.9.4/include/linux/sunrpc/clnt.h     2013-05-31 13:45:28.000000000 +0000
8202 +++ linux-3.9.4-vs2.3.6.2/include/linux/sunrpc/clnt.h   2013-05-31 14:47:11.000000000 +0000
8203 @@ -49,7 +49,8 @@ struct rpc_clnt {
8204         unsigned int            cl_softrtry : 1,/* soft timeouts */
8205                                 cl_discrtry : 1,/* disconnect before retry */
8206                                 cl_autobind : 1,/* use getport() */
8207 -                               cl_chatty   : 1;/* be verbose */
8208 +                               cl_chatty   : 1,/* be verbose */
8209 +                               cl_tag      : 1;/* context tagging */
8210  
8211         struct rpc_rtt *        cl_rtt;         /* RTO estimator data */
8212         const struct rpc_timeout *cl_timeout;   /* Timeout strategy */
8213 diff -NurpP --minimal linux-3.9.4/include/linux/sysfs.h linux-3.9.4-vs2.3.6.2/include/linux/sysfs.h
8214 --- linux-3.9.4/include/linux/sysfs.h   2013-05-31 13:45:28.000000000 +0000
8215 +++ linux-3.9.4-vs2.3.6.2/include/linux/sysfs.h 2013-05-31 14:47:11.000000000 +0000
8216 @@ -19,6 +19,8 @@
8217  #include <linux/kobject_ns.h>
8218  #include <linux/atomic.h>
8219  
8220 +#define SYSFS_SUPER_MAGIC      0x62656572
8221 +
8222  struct kobject;
8223  struct module;
8224  enum kobj_ns_type;
8225 diff -NurpP --minimal linux-3.9.4/include/linux/types.h linux-3.9.4-vs2.3.6.2/include/linux/types.h
8226 --- linux-3.9.4/include/linux/types.h   2013-02-19 13:58:52.000000000 +0000
8227 +++ linux-3.9.4-vs2.3.6.2/include/linux/types.h 2013-05-31 14:47:11.000000000 +0000
8228 @@ -32,6 +32,9 @@ typedef __kernel_uid32_t      uid_t;
8229  typedef __kernel_gid32_t       gid_t;
8230  typedef __kernel_uid16_t        uid16_t;
8231  typedef __kernel_gid16_t        gid16_t;
8232 +typedef unsigned int           xid_t;
8233 +typedef unsigned int           nid_t;
8234 +typedef unsigned int           tag_t;
8235  
8236  typedef unsigned long          uintptr_t;
8237  
8238 diff -NurpP --minimal linux-3.9.4/include/linux/uidgid.h linux-3.9.4-vs2.3.6.2/include/linux/uidgid.h
8239 --- linux-3.9.4/include/linux/uidgid.h  2012-12-11 03:30:57.000000000 +0000
8240 +++ linux-3.9.4-vs2.3.6.2/include/linux/uidgid.h        2013-05-31 14:47:11.000000000 +0000
8241 @@ -23,13 +23,17 @@ typedef struct {
8242         uid_t val;
8243  } kuid_t;
8244  
8245 -
8246  typedef struct {
8247         gid_t val;
8248  } kgid_t;
8249  
8250 +typedef struct {
8251 +       tag_t val;
8252 +} ktag_t;
8253 +
8254  #define KUIDT_INIT(value) (kuid_t){ value }
8255  #define KGIDT_INIT(value) (kgid_t){ value }
8256 +#define KTAGT_INIT(value) (ktag_t){ value }
8257  
8258  static inline uid_t __kuid_val(kuid_t uid)
8259  {
8260 @@ -41,10 +45,16 @@ static inline gid_t __kgid_val(kgid_t gi
8261         return gid.val;
8262  }
8263  
8264 +static inline tag_t __ktag_val(ktag_t tag)
8265 +{
8266 +       return tag.val;
8267 +}
8268 +
8269  #else
8270  
8271  typedef uid_t kuid_t;
8272  typedef gid_t kgid_t;
8273 +typedef tag_t ktag_t;
8274  
8275  static inline uid_t __kuid_val(kuid_t uid)
8276  {
8277 @@ -56,16 +66,24 @@ static inline gid_t __kgid_val(kgid_t gi
8278         return gid;
8279  }
8280  
8281 +static inline tag_t __ktag_val(ktag_t tag)
8282 +{
8283 +       return tag;
8284 +}
8285 +
8286  #define KUIDT_INIT(value) ((kuid_t) value )
8287  #define KGIDT_INIT(value) ((kgid_t) value )
8288 +#define KTAGT_INIT(value) ((ktag_t) value )
8289  
8290  #endif
8291  
8292  #define GLOBAL_ROOT_UID KUIDT_INIT(0)
8293  #define GLOBAL_ROOT_GID KGIDT_INIT(0)
8294 +#define GLOBAL_ROOT_TAG KTAGT_INIT(0)
8295  
8296  #define INVALID_UID KUIDT_INIT(-1)
8297  #define INVALID_GID KGIDT_INIT(-1)
8298 +#define INVALID_TAG KTAGT_INIT(-1)
8299  
8300  static inline bool uid_eq(kuid_t left, kuid_t right)
8301  {
8302 @@ -77,6 +95,11 @@ static inline bool gid_eq(kgid_t left, k
8303         return __kgid_val(left) == __kgid_val(right);
8304  }
8305  
8306 +static inline bool tag_eq(ktag_t left, ktag_t right)
8307 +{
8308 +       return __ktag_val(left) == __ktag_val(right);
8309 +}
8310 +
8311  static inline bool uid_gt(kuid_t left, kuid_t right)
8312  {
8313         return __kuid_val(left) > __kuid_val(right);
8314 @@ -127,13 +150,21 @@ static inline bool gid_valid(kgid_t gid)
8315         return !gid_eq(gid, INVALID_GID);
8316  }
8317  
8318 +static inline bool tag_valid(ktag_t tag)
8319 +{
8320 +       return !tag_eq(tag, INVALID_TAG);
8321 +}
8322 +
8323  #ifdef CONFIG_USER_NS
8324  
8325  extern kuid_t make_kuid(struct user_namespace *from, uid_t uid);
8326  extern kgid_t make_kgid(struct user_namespace *from, gid_t gid);
8327 +extern krag_t make_ktag(struct user_namespace *from, gid_t gid);
8328  
8329  extern uid_t from_kuid(struct user_namespace *to, kuid_t uid);
8330  extern gid_t from_kgid(struct user_namespace *to, kgid_t gid);
8331 +extern tag_t from_ktag(struct user_namespace *to, ktag_t tag);
8332 +
8333  extern uid_t from_kuid_munged(struct user_namespace *to, kuid_t uid);
8334  extern gid_t from_kgid_munged(struct user_namespace *to, kgid_t gid);
8335  
8336 @@ -159,6 +190,11 @@ static inline kgid_t make_kgid(struct us
8337         return KGIDT_INIT(gid);
8338  }
8339  
8340 +static inline ktag_t make_ktag(struct user_namespace *from, tag_t tag)
8341 +{
8342 +       return KTAGT_INIT(tag);
8343 +}
8344 +
8345  static inline uid_t from_kuid(struct user_namespace *to, kuid_t kuid)
8346  {
8347         return __kuid_val(kuid);
8348 @@ -169,6 +205,11 @@ static inline gid_t from_kgid(struct use
8349         return __kgid_val(kgid);
8350  }
8351  
8352 +static inline tag_t from_ktag(struct user_namespace *to, ktag_t ktag)
8353 +{
8354 +       return __ktag_val(ktag);
8355 +}
8356 +
8357  static inline uid_t from_kuid_munged(struct user_namespace *to, kuid_t kuid)
8358  {
8359         uid_t uid = from_kuid(to, kuid);
8360 diff -NurpP --minimal linux-3.9.4/include/linux/vroot.h linux-3.9.4-vs2.3.6.2/include/linux/vroot.h
8361 --- linux-3.9.4/include/linux/vroot.h   1970-01-01 00:00:00.000000000 +0000
8362 +++ linux-3.9.4-vs2.3.6.2/include/linux/vroot.h 2013-05-31 14:47:11.000000000 +0000
8363 @@ -0,0 +1,51 @@
8364 +
8365 +/*
8366 + * include/linux/vroot.h
8367 + *
8368 + * written by Herbert Pötzl, 9/11/2002
8369 + * ported to 2.6 by Herbert Pötzl, 30/12/2004
8370 + *
8371 + * Copyright (C) 2002-2007 by Herbert Pötzl.
8372 + * Redistribution of this file is permitted under the
8373 + * GNU General Public License.
8374 + */
8375 +
8376 +#ifndef _LINUX_VROOT_H
8377 +#define _LINUX_VROOT_H
8378 +
8379 +
8380 +#ifdef __KERNEL__
8381 +
8382 +/* Possible states of device */
8383 +enum {
8384 +       Vr_unbound,
8385 +       Vr_bound,
8386 +};
8387 +
8388 +struct vroot_device {
8389 +       int             vr_number;
8390 +       int             vr_refcnt;
8391 +
8392 +       struct semaphore        vr_ctl_mutex;
8393 +       struct block_device    *vr_device;
8394 +       int                     vr_state;
8395 +};
8396 +
8397 +
8398 +typedef struct block_device *(vroot_grb_func)(struct block_device *);
8399 +
8400 +extern int register_vroot_grb(vroot_grb_func *);
8401 +extern int unregister_vroot_grb(vroot_grb_func *);
8402 +
8403 +#endif /* __KERNEL__ */
8404 +
8405 +#define MAX_VROOT_DEFAULT      8
8406 +
8407 +/*
8408 + * IOCTL commands --- we will commandeer 0x56 ('V')
8409 + */
8410 +
8411 +#define VROOT_SET_DEV          0x5600
8412 +#define VROOT_CLR_DEV          0x5601
8413 +
8414 +#endif /* _LINUX_VROOT_H */
8415 diff -NurpP --minimal linux-3.9.4/include/linux/vs_base.h linux-3.9.4-vs2.3.6.2/include/linux/vs_base.h
8416 --- linux-3.9.4/include/linux/vs_base.h 1970-01-01 00:00:00.000000000 +0000
8417 +++ linux-3.9.4-vs2.3.6.2/include/linux/vs_base.h       2013-05-31 14:47:11.000000000 +0000
8418 @@ -0,0 +1,10 @@
8419 +#ifndef _VS_BASE_H
8420 +#define _VS_BASE_H
8421 +
8422 +#include "vserver/base.h"
8423 +#include "vserver/check.h"
8424 +#include "vserver/debug.h"
8425 +
8426 +#else
8427 +#warning duplicate inclusion
8428 +#endif
8429 diff -NurpP --minimal linux-3.9.4/include/linux/vs_context.h linux-3.9.4-vs2.3.6.2/include/linux/vs_context.h
8430 --- linux-3.9.4/include/linux/vs_context.h      1970-01-01 00:00:00.000000000 +0000
8431 +++ linux-3.9.4-vs2.3.6.2/include/linux/vs_context.h    2013-05-31 14:47:11.000000000 +0000
8432 @@ -0,0 +1,242 @@
8433 +#ifndef _VS_CONTEXT_H
8434 +#define _VS_CONTEXT_H
8435 +
8436 +#include "vserver/base.h"
8437 +#include "vserver/check.h"
8438 +#include "vserver/context.h"
8439 +#include "vserver/history.h"
8440 +#include "vserver/debug.h"
8441 +
8442 +#include <linux/sched.h>
8443 +
8444 +
8445 +#define get_vx_info(i) __get_vx_info(i, __FILE__, __LINE__, __HERE__)
8446 +
8447 +static inline struct vx_info *__get_vx_info(struct vx_info *vxi,
8448 +       const char *_file, int _line, void *_here)
8449 +{
8450 +       if (!vxi)
8451 +               return NULL;
8452 +
8453 +       vxlprintk(VXD_CBIT(xid, 2), "get_vx_info(%p[#%d.%d])",
8454 +               vxi, vxi ? vxi->vx_id : 0,
8455 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
8456 +               _file, _line);
8457 +       __vxh_get_vx_info(vxi, _here);
8458 +
8459 +       atomic_inc(&vxi->vx_usecnt);
8460 +       return vxi;
8461 +}
8462 +
8463 +
8464 +extern void free_vx_info(struct vx_info *);
8465 +
8466 +#define put_vx_info(i) __put_vx_info(i, __FILE__, __LINE__, __HERE__)
8467 +
8468 +static inline void __put_vx_info(struct vx_info *vxi,
8469 +       const char *_file, int _line, void *_here)
8470 +{
8471 +       if (!vxi)
8472 +               return;
8473 +
8474 +       vxlprintk(VXD_CBIT(xid, 2), "put_vx_info(%p[#%d.%d])",
8475 +               vxi, vxi ? vxi->vx_id : 0,
8476 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
8477 +               _file, _line);
8478 +       __vxh_put_vx_info(vxi, _here);
8479 +
8480 +       if (atomic_dec_and_test(&vxi->vx_usecnt))
8481 +               free_vx_info(vxi);
8482 +}
8483 +
8484 +
8485 +#define init_vx_info(p, i) \
8486 +       __init_vx_info(p, i, __FILE__, __LINE__, __HERE__)
8487 +
8488 +static inline void __init_vx_info(struct vx_info **vxp, struct vx_info *vxi,
8489 +       const char *_file, int _line, void *_here)
8490 +{
8491 +       if (vxi) {
8492 +               vxlprintk(VXD_CBIT(xid, 3),
8493 +                       "init_vx_info(%p[#%d.%d])",
8494 +                       vxi, vxi ? vxi->vx_id : 0,
8495 +                       vxi ? atomic_read(&vxi->vx_usecnt) : 0,
8496 +                       _file, _line);
8497 +               __vxh_init_vx_info(vxi, vxp, _here);
8498 +
8499 +               atomic_inc(&vxi->vx_usecnt);
8500 +       }
8501 +       *vxp = vxi;
8502 +}
8503 +
8504 +
8505 +#define set_vx_info(p, i) \
8506 +       __set_vx_info(p, i, __FILE__, __LINE__, __HERE__)
8507 +
8508 +static inline void __set_vx_info(struct vx_info **vxp, struct vx_info *vxi,
8509 +       const char *_file, int _line, void *_here)
8510 +{
8511 +       struct vx_info *vxo;
8512 +
8513 +       if (!vxi)
8514 +               return;
8515 +
8516 +       vxlprintk(VXD_CBIT(xid, 3), "set_vx_info(%p[#%d.%d])",
8517 +               vxi, vxi ? vxi->vx_id : 0,
8518 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
8519 +               _file, _line);
8520 +       __vxh_set_vx_info(vxi, vxp, _here);
8521 +
8522 +       atomic_inc(&vxi->vx_usecnt);
8523 +       vxo = xchg(vxp, vxi);
8524 +       BUG_ON(vxo);
8525 +}
8526 +
8527 +
8528 +#define clr_vx_info(p) __clr_vx_info(p, __FILE__, __LINE__, __HERE__)
8529 +
8530 +static inline void __clr_vx_info(struct vx_info **vxp,
8531 +       const char *_file, int _line, void *_here)
8532 +{
8533 +       struct vx_info *vxo;
8534 +
8535 +       vxo = xchg(vxp, NULL);
8536 +       if (!vxo)
8537 +               return;
8538 +
8539 +       vxlprintk(VXD_CBIT(xid, 3), "clr_vx_info(%p[#%d.%d])",
8540 +               vxo, vxo ? vxo->vx_id : 0,
8541 +               vxo ? atomic_read(&vxo->vx_usecnt) : 0,
8542 +               _file, _line);
8543 +       __vxh_clr_vx_info(vxo, vxp, _here);
8544 +
8545 +       if (atomic_dec_and_test(&vxo->vx_usecnt))
8546 +               free_vx_info(vxo);
8547 +}
8548 +
8549 +
8550 +#define claim_vx_info(v, p) \
8551 +       __claim_vx_info(v, p, __FILE__, __LINE__, __HERE__)
8552 +
8553 +static inline void __claim_vx_info(struct vx_info *vxi,
8554 +       struct task_struct *task,
8555 +       const char *_file, int _line, void *_here)
8556 +{
8557 +       vxlprintk(VXD_CBIT(xid, 3), "claim_vx_info(%p[#%d.%d.%d]) %p",
8558 +               vxi, vxi ? vxi->vx_id : 0,
8559 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
8560 +               vxi ? atomic_read(&vxi->vx_tasks) : 0,
8561 +               task, _file, _line);
8562 +       __vxh_claim_vx_info(vxi, task, _here);
8563 +
8564 +       atomic_inc(&vxi->vx_tasks);
8565 +}
8566 +
8567 +
8568 +extern void unhash_vx_info(struct vx_info *);
8569 +
8570 +#define release_vx_info(v, p) \
8571 +       __release_vx_info(v, p, __FILE__, __LINE__, __HERE__)
8572 +
8573 +static inline void __release_vx_info(struct vx_info *vxi,
8574 +       struct task_struct *task,
8575 +       const char *_file, int _line, void *_here)
8576 +{
8577 +       vxlprintk(VXD_CBIT(xid, 3), "release_vx_info(%p[#%d.%d.%d]) %p",
8578 +               vxi, vxi ? vxi->vx_id : 0,
8579 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
8580 +               vxi ? atomic_read(&vxi->vx_tasks) : 0,
8581 +               task, _file, _line);
8582 +       __vxh_release_vx_info(vxi, task, _here);
8583 +
8584 +       might_sleep();
8585 +
8586 +       if (atomic_dec_and_test(&vxi->vx_tasks))
8587 +               unhash_vx_info(vxi);
8588 +}
8589 +
8590 +
8591 +#define task_get_vx_info(p) \
8592 +       __task_get_vx_info(p, __FILE__, __LINE__, __HERE__)
8593 +
8594 +static inline struct vx_info *__task_get_vx_info(struct task_struct *p,
8595 +       const char *_file, int _line, void *_here)
8596 +{
8597 +       struct vx_info *vxi;
8598 +
8599 +       task_lock(p);
8600 +       vxlprintk(VXD_CBIT(xid, 5), "task_get_vx_info(%p)",
8601 +               p, _file, _line);
8602 +       vxi = __get_vx_info(p->vx_info, _file, _line, _here);
8603 +       task_unlock(p);
8604 +       return vxi;
8605 +}
8606 +
8607 +
8608 +static inline void __wakeup_vx_info(struct vx_info *vxi)
8609 +{
8610 +       if (waitqueue_active(&vxi->vx_wait))
8611 +               wake_up_interruptible(&vxi->vx_wait);
8612 +}
8613 +
8614 +
8615 +#define enter_vx_info(v, s) __enter_vx_info(v, s, __FILE__, __LINE__)
8616 +
8617 +static inline void __enter_vx_info(struct vx_info *vxi,
8618 +       struct vx_info_save *vxis, const char *_file, int _line)
8619 +{
8620 +       vxlprintk(VXD_CBIT(xid, 5), "enter_vx_info(%p[#%d],%p) %p[#%d,%p]",
8621 +               vxi, vxi ? vxi->vx_id : 0, vxis, current,
8622 +               current->xid, current->vx_info, _file, _line);
8623 +       vxis->vxi = xchg(&current->vx_info, vxi);
8624 +       vxis->xid = current->xid;
8625 +       current->xid = vxi ? vxi->vx_id : 0;
8626 +}
8627 +
8628 +#define leave_vx_info(s) __leave_vx_info(s, __FILE__, __LINE__)
8629 +
8630 +static inline void __leave_vx_info(struct vx_info_save *vxis,
8631 +       const char *_file, int _line)
8632 +{
8633 +       vxlprintk(VXD_CBIT(xid, 5), "leave_vx_info(%p[#%d,%p]) %p[#%d,%p]",
8634 +               vxis, vxis->xid, vxis->vxi, current,
8635 +               current->xid, current->vx_info, _file, _line);
8636 +       (void)xchg(&current->vx_info, vxis->vxi);
8637 +       current->xid = vxis->xid;
8638 +}
8639 +
8640 +
8641 +static inline void __enter_vx_admin(struct vx_info_save *vxis)
8642 +{
8643 +       vxis->vxi = xchg(&current->vx_info, NULL);
8644 +       vxis->xid = xchg(&current->xid, (xid_t)0);
8645 +}
8646 +
8647 +static inline void __leave_vx_admin(struct vx_info_save *vxis)
8648 +{
8649 +       (void)xchg(&current->xid, vxis->xid);
8650 +       (void)xchg(&current->vx_info, vxis->vxi);
8651 +}
8652 +
8653 +#define task_is_init(p) \
8654 +       __task_is_init(p, __FILE__, __LINE__, __HERE__)
8655 +
8656 +static inline int __task_is_init(struct task_struct *p,
8657 +       const char *_file, int _line, void *_here)
8658 +{
8659 +       int is_init = is_global_init(p);
8660 +
8661 +       task_lock(p);
8662 +       if (p->vx_info)
8663 +               is_init = p->vx_info->vx_initpid == p->pid;
8664 +       task_unlock(p);
8665 +       return is_init;
8666 +}
8667 +
8668 +extern void exit_vx_info(struct task_struct *, int);
8669 +extern void exit_vx_info_early(struct task_struct *, int);
8670 +
8671 +
8672 +#else
8673 +#warning duplicate inclusion
8674 +#endif
8675 diff -NurpP --minimal linux-3.9.4/include/linux/vs_cowbl.h linux-3.9.4-vs2.3.6.2/include/linux/vs_cowbl.h
8676 --- linux-3.9.4/include/linux/vs_cowbl.h        1970-01-01 00:00:00.000000000 +0000
8677 +++ linux-3.9.4-vs2.3.6.2/include/linux/vs_cowbl.h      2013-05-31 14:47:11.000000000 +0000
8678 @@ -0,0 +1,48 @@
8679 +#ifndef _VS_COWBL_H
8680 +#define _VS_COWBL_H
8681 +
8682 +#include <linux/fs.h>
8683 +#include <linux/dcache.h>
8684 +#include <linux/namei.h>
8685 +#include <linux/slab.h>
8686 +
8687 +extern struct dentry *cow_break_link(const char *pathname);
8688 +
8689 +static inline int cow_check_and_break(struct path *path)
8690 +{
8691 +       struct inode *inode = path->dentry->d_inode;
8692 +       int error = 0;
8693 +
8694 +       /* do we need this check? */
8695 +       if (IS_RDONLY(inode))
8696 +               return -EROFS;
8697 +
8698 +       if (IS_COW(inode)) {
8699 +               if (IS_COW_LINK(inode)) {
8700 +                       struct dentry *new_dentry, *old_dentry = path->dentry;
8701 +                       char *pp, *buf;
8702 +
8703 +                       buf = kmalloc(PATH_MAX, GFP_KERNEL);
8704 +                       if (!buf) {
8705 +                               return -ENOMEM;
8706 +                       }
8707 +                       pp = d_path(path, buf, PATH_MAX);
8708 +                       new_dentry = cow_break_link(pp);
8709 +                       kfree(buf);
8710 +                       if (!IS_ERR(new_dentry)) {
8711 +                               path->dentry = new_dentry;
8712 +                               dput(old_dentry);
8713 +                       } else
8714 +                               error = PTR_ERR(new_dentry);
8715 +               } else {
8716 +                       inode->i_flags &= ~(S_IXUNLINK | S_IMMUTABLE);
8717 +                       inode->i_ctime = CURRENT_TIME;
8718 +                       mark_inode_dirty(inode);
8719 +               }
8720 +       }
8721 +       return error;
8722 +}
8723 +
8724 +#else
8725 +#warning duplicate inclusion
8726 +#endif
8727 diff -NurpP --minimal linux-3.9.4/include/linux/vs_cvirt.h linux-3.9.4-vs2.3.6.2/include/linux/vs_cvirt.h
8728 --- linux-3.9.4/include/linux/vs_cvirt.h        1970-01-01 00:00:00.000000000 +0000
8729 +++ linux-3.9.4-vs2.3.6.2/include/linux/vs_cvirt.h      2013-05-31 14:47:11.000000000 +0000
8730 @@ -0,0 +1,50 @@
8731 +#ifndef _VS_CVIRT_H
8732 +#define _VS_CVIRT_H
8733 +
8734 +#include "vserver/cvirt.h"
8735 +#include "vserver/context.h"
8736 +#include "vserver/base.h"
8737 +#include "vserver/check.h"
8738 +#include "vserver/debug.h"
8739 +
8740 +
8741 +static inline void vx_activate_task(struct task_struct *p)
8742 +{
8743 +       struct vx_info *vxi;
8744 +
8745 +       if ((vxi = p->vx_info)) {
8746 +               vx_update_load(vxi);
8747 +               atomic_inc(&vxi->cvirt.nr_running);
8748 +       }
8749 +}
8750 +
8751 +static inline void vx_deactivate_task(struct task_struct *p)
8752 +{
8753 +       struct vx_info *vxi;
8754 +
8755 +       if ((vxi = p->vx_info)) {
8756 +               vx_update_load(vxi);
8757 +               atomic_dec(&vxi->cvirt.nr_running);
8758 +       }
8759 +}
8760 +
8761 +static inline void vx_uninterruptible_inc(struct task_struct *p)
8762 +{
8763 +       struct vx_info *vxi;
8764 +
8765 +       if ((vxi = p->vx_info))
8766 +               atomic_inc(&vxi->cvirt.nr_uninterruptible);
8767 +}
8768 +
8769 +static inline void vx_uninterruptible_dec(struct task_struct *p)
8770 +{
8771 +       struct vx_info *vxi;
8772 +
8773 +       if ((vxi = p->vx_info))
8774 +               atomic_dec(&vxi->cvirt.nr_uninterruptible);
8775 +}
8776 +
8777 +
8778 +#else
8779 +#warning duplicate inclusion
8780 +#endif
8781 diff -NurpP --minimal linux-3.9.4/include/linux/vs_device.h linux-3.9.4-vs2.3.6.2/include/linux/vs_device.h
8782 --- linux-3.9.4/include/linux/vs_device.h       1970-01-01 00:00:00.000000000 +0000
8783 +++ linux-3.9.4-vs2.3.6.2/include/linux/vs_device.h     2013-05-31 14:47:11.000000000 +0000
8784 @@ -0,0 +1,45 @@
8785 +#ifndef _VS_DEVICE_H
8786 +#define _VS_DEVICE_H
8787 +
8788 +#include "vserver/base.h"
8789 +#include "vserver/device.h"
8790 +#include "vserver/debug.h"
8791 +
8792 +
8793 +#ifdef CONFIG_VSERVER_DEVICE
8794 +
8795 +int vs_map_device(struct vx_info *, dev_t, dev_t *, umode_t);
8796 +
8797 +#define vs_device_perm(v, d, m, p) \
8798 +       ((vs_map_device(current_vx_info(), d, NULL, m) & (p)) == (p))
8799 +
8800 +#else
8801 +
8802 +static inline
8803 +int vs_map_device(struct vx_info *vxi,
8804 +       dev_t device, dev_t *target, umode_t mode)
8805 +{
8806 +       if (target)
8807 +               *target = device;
8808 +       return ~0;
8809 +}
8810 +
8811 +#define vs_device_perm(v, d, m, p) ((p) == (p))
8812 +
8813 +#endif
8814 +
8815 +
8816 +#define vs_map_chrdev(d, t, p) \
8817 +       ((vs_map_device(current_vx_info(), d, t, S_IFCHR) & (p)) == (p))
8818 +#define vs_map_blkdev(d, t, p) \
8819 +       ((vs_map_device(current_vx_info(), d, t, S_IFBLK) & (p)) == (p))
8820 +
8821 +#define vs_chrdev_perm(d, p) \
8822 +       vs_device_perm(current_vx_info(), d, S_IFCHR, p)
8823 +#define vs_blkdev_perm(d, p) \
8824 +       vs_device_perm(current_vx_info(), d, S_IFBLK, p)
8825 +
8826 +
8827 +#else
8828 +#warning duplicate inclusion
8829 +#endif
8830 diff -NurpP --minimal linux-3.9.4/include/linux/vs_dlimit.h linux-3.9.4-vs2.3.6.2/include/linux/vs_dlimit.h
8831 --- linux-3.9.4/include/linux/vs_dlimit.h       1970-01-01 00:00:00.000000000 +0000
8832 +++ linux-3.9.4-vs2.3.6.2/include/linux/vs_dlimit.h     2013-05-31 14:47:11.000000000 +0000
8833 @@ -0,0 +1,215 @@
8834 +#ifndef _VS_DLIMIT_H
8835 +#define _VS_DLIMIT_H
8836 +
8837 +#include <linux/fs.h>
8838 +
8839 +#include "vserver/dlimit.h"
8840 +#include "vserver/base.h"
8841 +#include "vserver/debug.h"
8842 +
8843 +
8844 +#define get_dl_info(i) __get_dl_info(i, __FILE__, __LINE__)
8845 +
8846 +static inline struct dl_info *__get_dl_info(struct dl_info *dli,
8847 +       const char *_file, int _line)
8848 +{
8849 +       if (!dli)
8850 +               return NULL;
8851 +       vxlprintk(VXD_CBIT(dlim, 4), "get_dl_info(%p[#%d.%d])",
8852 +               dli, dli ? dli->dl_tag : 0,
8853 +               dli ? atomic_read(&dli->dl_usecnt) : 0,
8854 +               _file, _line);
8855 +       atomic_inc(&dli->dl_usecnt);
8856 +       return dli;
8857 +}
8858 +
8859 +
8860 +#define free_dl_info(i) \
8861 +       call_rcu(&(i)->dl_rcu, rcu_free_dl_info)
8862 +
8863 +#define put_dl_info(i) __put_dl_info(i, __FILE__, __LINE__)
8864 +
8865 +static inline void __put_dl_info(struct dl_info *dli,
8866 +       const char *_file, int _line)
8867 +{
8868 +       if (!dli)
8869 +               return;
8870 +       vxlprintk(VXD_CBIT(dlim, 4), "put_dl_info(%p[#%d.%d])",
8871 +               dli, dli ? dli->dl_tag : 0,
8872 +               dli ? atomic_read(&dli->dl_usecnt) : 0,
8873 +               _file, _line);
8874 +       if (atomic_dec_and_test(&dli->dl_usecnt))
8875 +               free_dl_info(dli);
8876 +}
8877 +
8878 +
8879 +#define __dlimit_char(d)       ((d) ? '*' : ' ')
8880 +
8881 +static inline int __dl_alloc_space(struct super_block *sb,
8882 +       tag_t tag, dlsize_t nr, const char *file, int line)
8883 +{
8884 +       struct dl_info *dli = NULL;
8885 +       int ret = 0;
8886 +
8887 +       if (nr == 0)
8888 +               goto out;
8889 +       dli = locate_dl_info(sb, tag);
8890 +       if (!dli)
8891 +               goto out;
8892 +
8893 +       spin_lock(&dli->dl_lock);
8894 +       ret = (dli->dl_space_used + nr > dli->dl_space_total);
8895 +       if (!ret)
8896 +               dli->dl_space_used += nr;
8897 +       spin_unlock(&dli->dl_lock);
8898 +       put_dl_info(dli);
8899 +out:
8900 +       vxlprintk(VXD_CBIT(dlim, 1),
8901 +               "ALLOC (%p,#%d)%c %lld bytes (%d)",
8902 +               sb, tag, __dlimit_char(dli), (long long)nr,
8903 +               ret, file, line);
8904 +       return ret ? -ENOSPC : 0;
8905 +}
8906 +
8907 +static inline void __dl_free_space(struct super_block *sb,
8908 +       tag_t tag, dlsize_t nr, const char *_file, int _line)
8909 +{
8910 +       struct dl_info *dli = NULL;
8911 +
8912 +       if (nr == 0)
8913 +               goto out;
8914 +       dli = locate_dl_info(sb, tag);
8915 +       if (!dli)
8916 +               goto out;
8917 +
8918 +       spin_lock(&dli->dl_lock);
8919 +       if (dli->dl_space_used > nr)
8920 +               dli->dl_space_used -= nr;
8921 +       else
8922 +               dli->dl_space_used = 0;
8923 +       spin_unlock(&dli->dl_lock);
8924 +       put_dl_info(dli);
8925 +out:
8926 +       vxlprintk(VXD_CBIT(dlim, 1),
8927 +               "FREE  (%p,#%d)%c %lld bytes",
8928 +               sb, tag, __dlimit_char(dli), (long long)nr,
8929 +               _file, _line);
8930 +}
8931 +
8932 +static inline int __dl_alloc_inode(struct super_block *sb,
8933 +       tag_t tag, const char *_file, int _line)
8934 +{
8935 +       struct dl_info *dli;
8936 +       int ret = 0;
8937 +
8938 +       dli = locate_dl_info(sb, tag);
8939 +       if (!dli)
8940 +               goto out;
8941 +
8942 +       spin_lock(&dli->dl_lock);
8943 +       dli->dl_inodes_used++;
8944 +       ret = (dli->dl_inodes_used > dli->dl_inodes_total);
8945 +       spin_unlock(&dli->dl_lock);
8946 +       put_dl_info(dli);
8947 +out:
8948 +       vxlprintk(VXD_CBIT(dlim, 0),
8949 +               "ALLOC (%p,#%d)%c inode (%d)",
8950 +               sb, tag, __dlimit_char(dli), ret, _file, _line);
8951 +       return ret ? -ENOSPC : 0;
8952 +}
8953 +
8954 +static inline void __dl_free_inode(struct super_block *sb,
8955 +       tag_t tag, const char *_file, int _line)
8956 +{
8957 +       struct dl_info *dli;
8958 +
8959 +       dli = locate_dl_info(sb, tag);
8960 +       if (!dli)
8961 +               goto out;
8962 +
8963 +       spin_lock(&dli->dl_lock);
8964 +       if (dli->dl_inodes_used > 1)
8965 +               dli->dl_inodes_used--;
8966 +       else
8967 +               dli->dl_inodes_used = 0;
8968 +       spin_unlock(&dli->dl_lock);
8969 +       put_dl_info(dli);
8970 +out:
8971 +       vxlprintk(VXD_CBIT(dlim, 0),
8972 +               "FREE  (%p,#%d)%c inode",
8973 +               sb, tag, __dlimit_char(dli), _file, _line);
8974 +}
8975 +
8976 +static inline void __dl_adjust_block(struct super_block *sb, tag_t tag,
8977 +       unsigned long long *free_blocks, unsigned long long *root_blocks,
8978 +       const char *_file, int _line)
8979 +{
8980 +       struct dl_info *dli;
8981 +       uint64_t broot, bfree;
8982 +
8983 +       dli = locate_dl_info(sb, tag);
8984 +       if (!dli)
8985 +               return;
8986 +
8987 +       spin_lock(&dli->dl_lock);
8988 +       broot = (dli->dl_space_total -
8989 +               (dli->dl_space_total >> 10) * dli->dl_nrlmult)
8990 +               >> sb->s_blocksize_bits;
8991 +       bfree = (dli->dl_space_total - dli->dl_space_used)
8992 +                       >> sb->s_blocksize_bits;
8993 +       spin_unlock(&dli->dl_lock);
8994 +
8995 +       vxlprintk(VXD_CBIT(dlim, 2),
8996 +               "ADJUST: %lld,%lld on %lld,%lld [mult=%d]",
8997 +               (long long)bfree, (long long)broot,
8998 +               *free_blocks, *root_blocks, dli->dl_nrlmult,
8999 +               _file, _line);
9000 +       if (free_blocks) {
9001 +               if (*free_blocks > bfree)
9002 +                       *free_blocks = bfree;
9003 +       }
9004 +       if (root_blocks) {
9005 +               if (*root_blocks > broot)
9006 +                       *root_blocks = broot;
9007 +       }
9008 +       put_dl_info(dli);
9009 +}
9010 +
9011 +#define dl_prealloc_space(in, bytes) \
9012 +       __dl_alloc_space((in)->i_sb, i_tag_read(in), (dlsize_t)(bytes), \
9013 +               __FILE__, __LINE__ )
9014 +
9015 +#define dl_alloc_space(in, bytes) \
9016 +       __dl_alloc_space((in)->i_sb, i_tag_read(in), (dlsize_t)(bytes), \
9017 +               __FILE__, __LINE__ )
9018 +
9019 +#define dl_reserve_space(in, bytes) \
9020 +       __dl_alloc_space((in)->i_sb, i_tag_read(in), (dlsize_t)(bytes), \
9021 +               __FILE__, __LINE__ )
9022 +
9023 +#define dl_claim_space(in, bytes) (0)
9024 +
9025 +#define dl_release_space(in, bytes) \
9026 +       __dl_free_space((in)->i_sb, i_tag_read(in), (dlsize_t)(bytes), \
9027 +               __FILE__, __LINE__ )
9028 +
9029 +#define dl_free_space(in, bytes) \
9030 +       __dl_free_space((in)->i_sb, i_tag_read(in), (dlsize_t)(bytes), \
9031 +               __FILE__, __LINE__ )
9032 +
9033 +
9034 +
9035 +#define dl_alloc_inode(in) \
9036 +       __dl_alloc_inode((in)->i_sb, i_tag_read(in), __FILE__, __LINE__ )
9037 +
9038 +#define dl_free_inode(in) \
9039 +       __dl_free_inode((in)->i_sb, i_tag_read(in), __FILE__, __LINE__ )
9040 +
9041 +
9042 +#define dl_adjust_block(sb, tag, fb, rb) \
9043 +       __dl_adjust_block(sb, tag, fb, rb, __FILE__, __LINE__ )
9044 +
9045 +
9046 +#else
9047 +#warning duplicate inclusion
9048 +#endif
9049 diff -NurpP --minimal linux-3.9.4/include/linux/vs_inet.h linux-3.9.4-vs2.3.6.2/include/linux/vs_inet.h
9050 --- linux-3.9.4/include/linux/vs_inet.h 1970-01-01 00:00:00.000000000 +0000
9051 +++ linux-3.9.4-vs2.3.6.2/include/linux/vs_inet.h       2013-05-31 14:47:11.000000000 +0000
9052 @@ -0,0 +1,364 @@
9053 +#ifndef _VS_INET_H
9054 +#define _VS_INET_H
9055 +
9056 +#include "vserver/base.h"
9057 +#include "vserver/network.h"
9058 +#include "vserver/debug.h"
9059 +
9060 +#define IPI_LOOPBACK   htonl(INADDR_LOOPBACK)
9061 +
9062 +#define NXAV4(a)       NIPQUAD((a)->ip[0]), NIPQUAD((a)->ip[1]), \
9063 +                       NIPQUAD((a)->mask), (a)->type
9064 +#define NXAV4_FMT      "[" NIPQUAD_FMT "-" NIPQUAD_FMT "/" NIPQUAD_FMT ":%04x]"
9065 +
9066 +#define NIPQUAD(addr) \
9067 +       ((unsigned char *)&addr)[0], \
9068 +       ((unsigned char *)&addr)[1], \
9069 +       ((unsigned char *)&addr)[2], \
9070 +       ((unsigned char *)&addr)[3]
9071 +
9072 +#define NIPQUAD_FMT "%u.%u.%u.%u"
9073 +
9074 +
9075 +static inline
9076 +int v4_addr_match(struct nx_addr_v4 *nxa, __be32 addr, uint16_t tmask)
9077 +{
9078 +       __be32 ip = nxa->ip[0].s_addr;
9079 +       __be32 mask = nxa->mask.s_addr;
9080 +       __be32 bcast = ip | ~mask;
9081 +       int ret = 0;
9082 +
9083 +       switch (nxa->type & tmask) {
9084 +       case NXA_TYPE_MASK:
9085 +               ret = (ip == (addr & mask));
9086 +               break;
9087 +       case NXA_TYPE_ADDR:
9088 +               ret = 3;
9089 +               if (addr == ip)
9090 +                       break;
9091 +               /* fall through to broadcast */
9092 +       case NXA_MOD_BCAST:
9093 +               ret = ((tmask & NXA_MOD_BCAST) && (addr == bcast));
9094 +               break;
9095 +       case NXA_TYPE_RANGE:
9096 +               ret = ((nxa->ip[0].s_addr <= addr) &&
9097 +                       (nxa->ip[1].s_addr > addr));
9098 +               break;
9099 +       case NXA_TYPE_ANY:
9100 +               ret = 2;
9101 +               break;
9102 +       }
9103 +
9104 +       vxdprintk(VXD_CBIT(net, 0),
9105 +               "v4_addr_match(%p" NXAV4_FMT "," NIPQUAD_FMT ",%04x) = %d",
9106 +               nxa, NXAV4(nxa), NIPQUAD(addr), tmask, ret);
9107 +       return ret;
9108 +}
9109 +
9110 +static inline
9111 +int v4_addr_in_nx_info(struct nx_info *nxi, __be32 addr, uint16_t tmask)
9112 +{
9113 +       struct nx_addr_v4 *nxa;
9114 +       unsigned long irqflags;
9115 +       int ret = 1;
9116 +
9117 +       if (!nxi)
9118 +               goto out;
9119 +
9120 +       ret = 2;
9121 +       /* allow 127.0.0.1 when remapping lback */
9122 +       if ((tmask & NXA_LOOPBACK) &&
9123 +               (addr == IPI_LOOPBACK) &&
9124 +               nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
9125 +               goto out;
9126 +       ret = 3;
9127 +       /* check for lback address */
9128 +       if ((tmask & NXA_MOD_LBACK) &&
9129 +               (nxi->v4_lback.s_addr == addr))
9130 +               goto out;
9131 +       ret = 4;
9132 +       /* check for broadcast address */
9133 +       if ((tmask & NXA_MOD_BCAST) &&
9134 +               (nxi->v4_bcast.s_addr == addr))
9135 +               goto out;
9136 +       ret = 5;
9137 +
9138 +       /* check for v4 addresses */
9139 +       spin_lock_irqsave(&nxi->addr_lock, irqflags);
9140 +       for (nxa = &nxi->v4; nxa; nxa = nxa->next)
9141 +               if (v4_addr_match(nxa, addr, tmask))
9142 +                       goto out_unlock;
9143 +       ret = 0;
9144 +out_unlock:
9145 +       spin_unlock_irqrestore(&nxi->addr_lock, irqflags);
9146 +out:
9147 +       vxdprintk(VXD_CBIT(net, 0),
9148 +               "v4_addr_in_nx_info(%p[#%u]," NIPQUAD_FMT ",%04x) = %d",
9149 +               nxi, nxi ? nxi->nx_id : 0, NIPQUAD(addr), tmask, ret);
9150 +       return ret;
9151 +}
9152 +
9153 +static inline
9154 +int v4_nx_addr_match(struct nx_addr_v4 *nxa, struct nx_addr_v4 *addr, uint16_t mask)
9155 +{
9156 +       /* FIXME: needs full range checks */
9157 +       return v4_addr_match(nxa, addr->ip[0].s_addr, mask);
9158 +}
9159 +
9160 +static inline
9161 +int v4_nx_addr_in_nx_info(struct nx_info *nxi, struct nx_addr_v4 *nxa, uint16_t mask)
9162 +{
9163 +       struct nx_addr_v4 *ptr;
9164 +       unsigned long irqflags;
9165 +       int ret = 1;
9166 +
9167 +       spin_lock_irqsave(&nxi->addr_lock, irqflags);
9168 +       for (ptr = &nxi->v4; ptr; ptr = ptr->next)
9169 +               if (v4_nx_addr_match(ptr, nxa, mask))
9170 +                       goto out_unlock;
9171 +       ret = 0;
9172 +out_unlock:
9173 +       spin_unlock_irqrestore(&nxi->addr_lock, irqflags);
9174 +       return ret;
9175 +}
9176 +
9177 +#include <net/inet_sock.h>
9178 +
9179 +/*
9180 + *     Check if a given address matches for a socket
9181 + *
9182 + *     nxi:            the socket's nx_info if any
9183 + *     addr:           to be verified address
9184 + */
9185 +static inline
9186 +int v4_sock_addr_match (
9187 +       struct nx_info *nxi,
9188 +       struct inet_sock *inet,
9189 +       __be32 addr)
9190 +{
9191 +       __be32 saddr = inet->inet_rcv_saddr;
9192 +       __be32 bcast = nxi ? nxi->v4_bcast.s_addr : INADDR_BROADCAST;
9193 +
9194 +       if (addr && (saddr == addr || bcast == addr))
9195 +               return 1;
9196 +       if (!saddr)
9197 +               return v4_addr_in_nx_info(nxi, addr, NXA_MASK_BIND);
9198 +       return 0;
9199 +}
9200 +
9201 +
9202 +/* inet related checks and helpers */
9203 +
9204 +
9205 +struct in_ifaddr;
9206 +struct net_device;
9207 +struct sock;
9208 +
9209 +#ifdef CONFIG_INET
9210 +
9211 +#include <linux/netdevice.h>
9212 +#include <linux/inetdevice.h>
9213 +#include <net/inet_sock.h>
9214 +#include <net/inet_timewait_sock.h>
9215 +
9216 +
9217 +int dev_in_nx_info(struct net_device *, struct nx_info *);
9218 +int v4_dev_in_nx_info(struct net_device *, struct nx_info *);
9219 +int nx_v4_addr_conflict(struct nx_info *, struct nx_info *);
9220 +
9221 +
9222 +/*
9223 + *     check if address is covered by socket
9224 + *
9225 + *     sk:     the socket to check against
9226 + *     addr:   the address in question (must be != 0)
9227 + */
9228 +
9229 +static inline
9230 +int __v4_addr_match_socket(const struct sock *sk, struct nx_addr_v4 *nxa)
9231 +{
9232 +       struct nx_info *nxi = sk->sk_nx_info;
9233 +       __be32 saddr = sk_rcv_saddr(sk);
9234 +
9235 +       vxdprintk(VXD_CBIT(net, 5),
9236 +               "__v4_addr_in_socket(%p," NXAV4_FMT ") %p:" NIPQUAD_FMT " %p;%lx",
9237 +               sk, NXAV4(nxa), nxi, NIPQUAD(saddr), sk->sk_socket,
9238 +               (sk->sk_socket?sk->sk_socket->flags:0));
9239 +
9240 +       if (saddr) {            /* direct address match */
9241 +               return v4_addr_match(nxa, saddr, -1);
9242 +       } else if (nxi) {       /* match against nx_info */
9243 +               return v4_nx_addr_in_nx_info(nxi, nxa, -1);
9244 +       } else {                /* unrestricted any socket */
9245 +               return 1;
9246 +       }
9247 +}
9248 +
9249 +
9250 +
9251 +static inline
9252 +int nx_dev_visible(struct nx_info *nxi, struct net_device *dev)
9253 +{
9254 +       vxdprintk(VXD_CBIT(net, 1),
9255 +               "nx_dev_visible(%p[#%u],%p " VS_Q("%s") ") %d",
9256 +               nxi, nxi ? nxi->nx_id : 0, dev, dev->name,
9257 +               nxi ? dev_in_nx_info(dev, nxi) : 0);
9258 +
9259 +       if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
9260 +               return 1;
9261 +       if (dev_in_nx_info(dev, nxi))
9262 +               return 1;
9263 +       return 0;
9264 +}
9265 +
9266 +
9267 +static inline
9268 +int v4_ifa_in_nx_info(struct in_ifaddr *ifa, struct nx_info *nxi)
9269 +{
9270 +       if (!nxi)
9271 +               return 1;
9272 +       if (!ifa)
9273 +               return 0;
9274 +       return v4_addr_in_nx_info(nxi, ifa->ifa_local, NXA_MASK_SHOW);
9275 +}
9276 +
9277 +static inline
9278 +int nx_v4_ifa_visible(struct nx_info *nxi, struct in_ifaddr *ifa)
9279 +{
9280 +       vxdprintk(VXD_CBIT(net, 1), "nx_v4_ifa_visible(%p[#%u],%p) %d",
9281 +               nxi, nxi ? nxi->nx_id : 0, ifa,
9282 +               nxi ? v4_ifa_in_nx_info(ifa, nxi) : 0);
9283 +
9284 +       if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
9285 +               return 1;
9286 +       if (v4_ifa_in_nx_info(ifa, nxi))
9287 +               return 1;
9288 +       return 0;
9289 +}
9290 +
9291 +
9292 +struct nx_v4_sock_addr {
9293 +       __be32 saddr;   /* Address used for validation */
9294 +       __be32 baddr;   /* Address used for socket bind */
9295 +};
9296 +
9297 +static inline
9298 +int v4_map_sock_addr(struct inet_sock *inet, struct sockaddr_in *addr,
9299 +       struct nx_v4_sock_addr *nsa)
9300 +{
9301 +       struct sock *sk = &inet->sk;
9302 +       struct nx_info *nxi = sk->sk_nx_info;
9303 +       __be32 saddr = addr->sin_addr.s_addr;
9304 +       __be32 baddr = saddr;
9305 +
9306 +       vxdprintk(VXD_CBIT(net, 3),
9307 +               "inet_bind(%p)* %p,%p;%lx " NIPQUAD_FMT,
9308 +               sk, sk->sk_nx_info, sk->sk_socket,
9309 +               (sk->sk_socket ? sk->sk_socket->flags : 0),
9310 +               NIPQUAD(saddr));
9311 +
9312 +       if (nxi) {
9313 +               if (saddr == INADDR_ANY) {
9314 +                       if (nx_info_flags(nxi, NXF_SINGLE_IP, 0))
9315 +                               baddr = nxi->v4.ip[0].s_addr;
9316 +               } else if (saddr == IPI_LOOPBACK) {
9317 +                       if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
9318 +                               baddr = nxi->v4_lback.s_addr;
9319 +               } else if (!ipv4_is_multicast(saddr) ||
9320 +                       !nx_info_ncaps(nxi, NXC_MULTICAST)) {
9321 +                       /* normal address bind */
9322 +                       if (!v4_addr_in_nx_info(nxi, saddr, NXA_MASK_BIND))
9323 +                               return -EADDRNOTAVAIL;
9324 +               }
9325 +       }
9326 +
9327 +       vxdprintk(VXD_CBIT(net, 3),
9328 +               "inet_bind(%p) " NIPQUAD_FMT ", " NIPQUAD_FMT,
9329 +               sk, NIPQUAD(saddr), NIPQUAD(baddr));
9330 +
9331 +       nsa->saddr = saddr;
9332 +       nsa->baddr = baddr;
9333 +       return 0;
9334 +}
9335 +
9336 +static inline
9337 +void v4_set_sock_addr(struct inet_sock *inet, struct nx_v4_sock_addr *nsa)
9338 +{
9339 +       inet->inet_saddr = nsa->baddr;
9340 +       inet->inet_rcv_saddr = nsa->baddr;
9341 +}
9342 +
9343 +
9344 +/*
9345 + *      helper to simplify inet_lookup_listener
9346 + *
9347 + *      nxi:   the socket's nx_info if any
9348 + *      addr:  to be verified address
9349 + *      saddr: socket address
9350 + */
9351 +static inline int v4_inet_addr_match (
9352 +       struct nx_info *nxi,
9353 +       __be32 addr,
9354 +       __be32 saddr)
9355 +{
9356 +       if (addr && (saddr == addr))
9357 +               return 1;
9358 +       if (!saddr)
9359 +               return nxi ? v4_addr_in_nx_info(nxi, addr, NXA_MASK_BIND) : 1;
9360 +       return 0;
9361 +}
9362 +
9363 +static inline __be32 nx_map_sock_lback(struct nx_info *nxi, __be32 addr)
9364 +{
9365 +       if (nx_info_flags(nxi, NXF_HIDE_LBACK, 0) &&
9366 +               (addr == nxi->v4_lback.s_addr))
9367 +               return IPI_LOOPBACK;
9368 +       return addr;
9369 +}
9370 +
9371 +static inline
9372 +int nx_info_has_v4(struct nx_info *nxi)
9373 +{
9374 +       if (!nxi)
9375 +               return 1;
9376 +       if (NX_IPV4(nxi))
9377 +               return 1;
9378 +       if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
9379 +               return 1;
9380 +       return 0;
9381 +}
9382 +
9383 +#else /* CONFIG_INET */
9384 +
9385 +static inline
9386 +int nx_dev_visible(struct nx_info *n, struct net_device *d)
9387 +{
9388 +       return 1;
9389 +}
9390 +
9391 +static inline
9392 +int nx_v4_addr_conflict(struct nx_info *n, uint32_t a, const struct sock *s)
9393 +{
9394 +       return 1;
9395 +}
9396 +
9397 +static inline
9398 +int v4_ifa_in_nx_info(struct in_ifaddr *a, struct nx_info *n)
9399 +{
9400 +       return 1;
9401 +}
9402 +
9403 +static inline
9404 +int nx_info_has_v4(struct nx_info *nxi)
9405 +{
9406 +       return 0;
9407 +}
9408 +
9409 +#endif /* CONFIG_INET */
9410 +
9411 +#define current_nx_info_has_v4() \
9412 +       nx_info_has_v4(current_nx_info())
9413 +
9414 +#else
9415 +// #warning duplicate inclusion
9416 +#endif
9417 diff -NurpP --minimal linux-3.9.4/include/linux/vs_inet6.h linux-3.9.4-vs2.3.6.2/include/linux/vs_inet6.h
9418 --- linux-3.9.4/include/linux/vs_inet6.h        1970-01-01 00:00:00.000000000 +0000
9419 +++ linux-3.9.4-vs2.3.6.2/include/linux/vs_inet6.h      2013-05-31 14:47:11.000000000 +0000
9420 @@ -0,0 +1,257 @@
9421 +#ifndef _VS_INET6_H
9422 +#define _VS_INET6_H
9423 +
9424 +#include "vserver/base.h"
9425 +#include "vserver/network.h"
9426 +#include "vserver/debug.h"
9427 +
9428 +#include <net/ipv6.h>
9429 +
9430 +#define NXAV6(a)       &(a)->ip, &(a)->mask, (a)->prefix, (a)->type
9431 +#define NXAV6_FMT      "[%pI6/%pI6/%d:%04x]"
9432 +
9433 +
9434 +#ifdef CONFIG_IPV6
9435 +
9436 +static inline
9437 +int v6_addr_match(struct nx_addr_v6 *nxa,
9438 +       const struct in6_addr *addr, uint16_t mask)
9439 +{
9440 +       int ret = 0;
9441 +
9442 +       switch (nxa->type & mask) {
9443 +       case NXA_TYPE_MASK:
9444 +               ret = ipv6_masked_addr_cmp(&nxa->ip, &nxa->mask, addr);
9445 +               break;
9446 +       case NXA_TYPE_ADDR:
9447 +               ret = ipv6_addr_equal(&nxa->ip, addr);
9448 +               break;
9449 +       case NXA_TYPE_ANY:
9450 +               ret = 1;
9451 +               break;
9452 +       }
9453 +       vxdprintk(VXD_CBIT(net, 0),
9454 +               "v6_addr_match(%p" NXAV6_FMT ",%pI6,%04x) = %d",
9455 +               nxa, NXAV6(nxa), addr, mask, ret);
9456 +       return ret;
9457 +}
9458 +
9459 +static inline
9460 +int v6_addr_in_nx_info(struct nx_info *nxi,
9461 +       const struct in6_addr *addr, uint16_t mask)
9462 +{
9463 +       struct nx_addr_v6 *nxa;
9464 +       unsigned long irqflags;
9465 +       int ret = 1;
9466 +
9467 +       if (!nxi)
9468 +               goto out;
9469 +
9470 +       spin_lock_irqsave(&nxi->addr_lock, irqflags);
9471 +       for (nxa = &nxi->v6; nxa; nxa = nxa->next)
9472 +               if (v6_addr_match(nxa, addr, mask))
9473 +                       goto out_unlock;
9474 +       ret = 0;
9475 +out_unlock:
9476 +       spin_unlock_irqrestore(&nxi->addr_lock, irqflags);
9477 +out:
9478 +       vxdprintk(VXD_CBIT(net, 0),
9479 +               "v6_addr_in_nx_info(%p[#%u],%pI6,%04x) = %d",
9480 +               nxi, nxi ? nxi->nx_id : 0, addr, mask, ret);
9481 +       return ret;
9482 +}
9483 +
9484 +static inline
9485 +int v6_nx_addr_match(struct nx_addr_v6 *nxa, struct nx_addr_v6 *addr, uint16_t mask)
9486 +{
9487 +       /* FIXME: needs full range checks */
9488 +       return v6_addr_match(nxa, &addr->ip, mask);
9489 +}
9490 +
9491 +static inline
9492 +int v6_nx_addr_in_nx_info(struct nx_info *nxi, struct nx_addr_v6 *nxa, uint16_t mask)
9493 +{
9494 +       struct nx_addr_v6 *ptr;
9495 +       unsigned long irqflags;
9496 +       int ret = 1;
9497 +
9498 +       spin_lock_irqsave(&nxi->addr_lock, irqflags);
9499 +       for (ptr = &nxi->v6; ptr; ptr = ptr->next)
9500 +               if (v6_nx_addr_match(ptr, nxa, mask))
9501 +                       goto out_unlock;
9502 +       ret = 0;
9503 +out_unlock:
9504 +       spin_unlock_irqrestore(&nxi->addr_lock, irqflags);
9505 +       return ret;
9506 +}
9507 +
9508 +
9509 +/*
9510 + *     Check if a given address matches for a socket
9511 + *
9512 + *     nxi:            the socket's nx_info if any
9513 + *     addr:           to be verified address
9514 + */
9515 +static inline
9516 +int v6_sock_addr_match (
9517 +       struct nx_info *nxi,
9518 +       struct inet_sock *inet,
9519 +       struct in6_addr *addr)
9520 +{
9521 +       struct sock *sk = &inet->sk;
9522 +       struct in6_addr *saddr = inet6_rcv_saddr(sk);
9523 +
9524 +       if (!ipv6_addr_any(addr) &&
9525 +               ipv6_addr_equal(saddr, addr))
9526 +               return 1;
9527 +       if (ipv6_addr_any(saddr))
9528 +               return v6_addr_in_nx_info(nxi, addr, -1);
9529 +       return 0;
9530 +}
9531 +
9532 +/*
9533 + *     check if address is covered by socket
9534 + *
9535 + *     sk:     the socket to check against
9536 + *     addr:   the address in question (must be != 0)
9537 + */
9538 +
9539 +static inline
9540 +int __v6_addr_match_socket(const struct sock *sk, struct nx_addr_v6 *nxa)
9541 +{
9542 +       struct nx_info *nxi = sk->sk_nx_info;
9543 +       struct in6_addr *saddr = inet6_rcv_saddr(sk);
9544 +
9545 +       vxdprintk(VXD_CBIT(net, 5),
9546 +               "__v6_addr_in_socket(%p," NXAV6_FMT ") %p:%pI6 %p;%lx",
9547 +               sk, NXAV6(nxa), nxi, saddr, sk->sk_socket,
9548 +               (sk->sk_socket?sk->sk_socket->flags:0));
9549 +
9550 +       if (!ipv6_addr_any(saddr)) {    /* direct address match */
9551 +               return v6_addr_match(nxa, saddr, -1);
9552 +       } else if (nxi) {               /* match against nx_info */
9553 +               return v6_nx_addr_in_nx_info(nxi, nxa, -1);
9554 +       } else {                        /* unrestricted any socket */
9555 +               return 1;
9556 +       }
9557 +}
9558 +
9559 +
9560 +/* inet related checks and helpers */
9561 +
9562 +
9563 +struct in_ifaddr;
9564 +struct net_device;
9565 +struct sock;
9566 +
9567 +
9568 +#include <linux/netdevice.h>
9569 +#include <linux/inetdevice.h>
9570 +#include <net/inet_timewait_sock.h>
9571 +
9572 +
9573 +int dev_in_nx_info(struct net_device *, struct nx_info *);
9574 +int v6_dev_in_nx_info(struct net_device *, struct nx_info *);
9575 +int nx_v6_addr_conflict(struct nx_info *, struct nx_info *);
9576 +
9577 +
9578 +
9579 +static inline
9580 +int v6_ifa_in_nx_info(struct inet6_ifaddr *ifa, struct nx_info *nxi)
9581 +{
9582 +       if (!nxi)
9583 +               return 1;
9584 +       if (!ifa)
9585 +               return 0;
9586 +       return v6_addr_in_nx_info(nxi, &ifa->addr, -1);
9587 +}
9588 +
9589 +static inline
9590 +int nx_v6_ifa_visible(struct nx_info *nxi, struct inet6_ifaddr *ifa)
9591 +{
9592 +       vxdprintk(VXD_CBIT(net, 1), "nx_v6_ifa_visible(%p[#%u],%p) %d",
9593 +               nxi, nxi ? nxi->nx_id : 0, ifa,
9594 +               nxi ? v6_ifa_in_nx_info(ifa, nxi) : 0);
9595 +
9596 +       if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
9597 +               return 1;
9598 +       if (v6_ifa_in_nx_info(ifa, nxi))
9599 +               return 1;
9600 +       return 0;
9601 +}
9602 +
9603 +
9604 +struct nx_v6_sock_addr {
9605 +       struct in6_addr saddr;  /* Address used for validation */
9606 +       struct in6_addr baddr;  /* Address used for socket bind */
9607 +};
9608 +
9609 +static inline
9610 +int v6_map_sock_addr(struct inet_sock *inet, struct sockaddr_in6 *addr,
9611 +       struct nx_v6_sock_addr *nsa)
9612 +{
9613 +       // struct sock *sk = &inet->sk;
9614 +       // struct nx_info *nxi = sk->sk_nx_info;
9615 +       struct in6_addr saddr = addr->sin6_addr;
9616 +       struct in6_addr baddr = saddr;
9617 +
9618 +       nsa->saddr = saddr;
9619 +       nsa->baddr = baddr;
9620 +       return 0;
9621 +}
9622 +
9623 +static inline
9624 +void v6_set_sock_addr(struct inet_sock *inet, struct nx_v6_sock_addr *nsa)
9625 +{
9626 +       // struct sock *sk = &inet->sk;
9627 +       // struct in6_addr *saddr = inet6_rcv_saddr(sk);
9628 +
9629 +       // *saddr = nsa->baddr;
9630 +       // inet->inet_saddr = nsa->baddr;
9631 +}
9632 +
9633 +static inline
9634 +int nx_info_has_v6(struct nx_info *nxi)
9635 +{
9636 +       if (!nxi)
9637 +               return 1;
9638 +       if (NX_IPV6(nxi))
9639 +               return 1;
9640 +       return 0;
9641 +}
9642 +
9643 +#else /* CONFIG_IPV6 */
9644 +
9645 +static inline
9646 +int nx_v6_dev_visible(struct nx_info *n, struct net_device *d)
9647 +{
9648 +       return 1;
9649 +}
9650 +
9651 +
9652 +static inline
9653 +int nx_v6_addr_conflict(struct nx_info *n, uint32_t a, const struct sock *s)
9654 +{
9655 +       return 1;
9656 +}
9657 +
9658 +static inline
9659 +int v6_ifa_in_nx_info(struct in_ifaddr *a, struct nx_info *n)
9660 +{
9661 +       return 1;
9662 +}
9663 +
9664 +static inline
9665 +int nx_info_has_v6(struct nx_info *nxi)
9666 +{
9667 +       return 0;
9668 +}
9669 +
9670 +#endif /* CONFIG_IPV6 */
9671 +
9672 +#define current_nx_info_has_v6() \
9673 +       nx_info_has_v6(current_nx_info())
9674 +
9675 +#else
9676 +#warning duplicate inclusion
9677 +#endif
9678 diff -NurpP --minimal linux-3.9.4/include/linux/vs_limit.h linux-3.9.4-vs2.3.6.2/include/linux/vs_limit.h
9679 --- linux-3.9.4/include/linux/vs_limit.h        1970-01-01 00:00:00.000000000 +0000
9680 +++ linux-3.9.4-vs2.3.6.2/include/linux/vs_limit.h      2013-05-31 14:47:11.000000000 +0000
9681 @@ -0,0 +1,140 @@
9682 +#ifndef _VS_LIMIT_H
9683 +#define _VS_LIMIT_H
9684 +
9685 +#include "vserver/limit.h"
9686 +#include "vserver/base.h"
9687 +#include "vserver/context.h"
9688 +#include "vserver/debug.h"
9689 +#include "vserver/context.h"
9690 +#include "vserver/limit_int.h"
9691 +
9692 +
9693 +#define vx_acc_cres(v, d, p, r) \
9694 +       __vx_acc_cres(v, r, d, p, __FILE__, __LINE__)
9695 +
9696 +#define vx_acc_cres_cond(x, d, p, r) \
9697 +       __vx_acc_cres(((x) == vx_current_xid()) ? current_vx_info() : 0, \
9698 +       r, d, p, __FILE__, __LINE__)
9699 +
9700 +
9701 +#define vx_add_cres(v, a, p, r) \
9702 +       __vx_add_cres(v, r, a, p, __FILE__, __LINE__)
9703 +#define vx_sub_cres(v, a, p, r)                vx_add_cres(v, -(a), p, r)
9704 +
9705 +#define vx_add_cres_cond(x, a, p, r) \
9706 +       __vx_add_cres(((x) == vx_current_xid()) ? current_vx_info() : 0, \
9707 +       r, a, p, __FILE__, __LINE__)
9708 +#define vx_sub_cres_cond(x, a, p, r)   vx_add_cres_cond(x, -(a), p, r)
9709 +
9710 +
9711 +/* process and file limits */
9712 +
9713 +#define vx_nproc_inc(p) \
9714 +       vx_acc_cres((p)->vx_info, 1, p, RLIMIT_NPROC)
9715 +
9716 +#define vx_nproc_dec(p) \
9717 +       vx_acc_cres((p)->vx_info,-1, p, RLIMIT_NPROC)
9718 +
9719 +#define vx_files_inc(f) \
9720 +       vx_acc_cres_cond((f)->f_xid, 1, f, RLIMIT_NOFILE)
9721 +
9722 +#define vx_files_dec(f) \
9723 +       vx_acc_cres_cond((f)->f_xid,-1, f, RLIMIT_NOFILE)
9724 +
9725 +#define vx_locks_inc(l) \
9726 +       vx_acc_cres_cond((l)->fl_xid, 1, l, RLIMIT_LOCKS)
9727 +
9728 +#define vx_locks_dec(l) \
9729 +       vx_acc_cres_cond((l)->fl_xid,-1, l, RLIMIT_LOCKS)
9730 +
9731 +#define vx_openfd_inc(f) \
9732 +       vx_acc_cres(current_vx_info(), 1, (void *)(long)(f), VLIMIT_OPENFD)
9733 +
9734 +#define vx_openfd_dec(f) \
9735 +       vx_acc_cres(current_vx_info(),-1, (void *)(long)(f), VLIMIT_OPENFD)
9736 +
9737 +
9738 +#define vx_cres_avail(v, n, r) \
9739 +       __vx_cres_avail(v, r, n, __FILE__, __LINE__)
9740 +
9741 +
9742 +#define vx_nproc_avail(n) \
9743 +       vx_cres_avail(current_vx_info(), n, RLIMIT_NPROC)
9744 +
9745 +#define vx_files_avail(n) \
9746 +       vx_cres_avail(current_vx_info(), n, RLIMIT_NOFILE)
9747 +
9748 +#define vx_locks_avail(n) \
9749 +       vx_cres_avail(current_vx_info(), n, RLIMIT_LOCKS)
9750 +
9751 +#define vx_openfd_avail(n) \
9752 +       vx_cres_avail(current_vx_info(), n, VLIMIT_OPENFD)
9753 +
9754 +
9755 +/* dentry limits */
9756 +
9757 +#define vx_dentry_inc(d) do {                                          \
9758 +       if ((d)->d_count == 1)                                          \
9759 +               vx_acc_cres(current_vx_info(), 1, d, VLIMIT_DENTRY);    \
9760 +       } while (0)
9761 +
9762 +#define vx_dentry_dec(d) do {                                          \
9763 +       if ((d)->d_count == 0)                                          \
9764 +               vx_acc_cres(current_vx_info(),-1, d, VLIMIT_DENTRY);    \
9765 +       } while (0)
9766 +
9767 +#define vx_dentry_avail(n) \
9768 +       vx_cres_avail(current_vx_info(), n, VLIMIT_DENTRY)
9769 +
9770 +
9771 +/* socket limits */
9772 +
9773 +#define vx_sock_inc(s) \
9774 +       vx_acc_cres((s)->sk_vx_info, 1, s, VLIMIT_NSOCK)
9775 +
9776 +#define vx_sock_dec(s) \
9777 +       vx_acc_cres((s)->sk_vx_info,-1, s, VLIMIT_NSOCK)
9778 +
9779 +#define vx_sock_avail(n) \
9780 +       vx_cres_avail(current_vx_info(), n, VLIMIT_NSOCK)
9781 +
9782 +
9783 +/* ipc resource limits */
9784 +
9785 +#define vx_ipcmsg_add(v, u, a) \
9786 +       vx_add_cres(v, a, u, RLIMIT_MSGQUEUE)
9787 +
9788 +#define vx_ipcmsg_sub(v, u, a) \
9789 +       vx_sub_cres(v, a, u, RLIMIT_MSGQUEUE)
9790 +
9791 +#define vx_ipcmsg_avail(v, a) \
9792 +       vx_cres_avail(v, a, RLIMIT_MSGQUEUE)
9793 +
9794 +
9795 +#define vx_ipcshm_add(v, k, a) \
9796 +       vx_add_cres(v, a, (void *)(long)(k), VLIMIT_SHMEM)
9797 +
9798 +#define vx_ipcshm_sub(v, k, a) \
9799 +       vx_sub_cres(v, a, (void *)(long)(k), VLIMIT_SHMEM)
9800 +
9801 +#define vx_ipcshm_avail(v, a) \
9802 +       vx_cres_avail(v, a, VLIMIT_SHMEM)
9803 +
9804 +
9805 +#define vx_semary_inc(a) \
9806 +       vx_acc_cres(current_vx_info(), 1, a, VLIMIT_SEMARY)
9807 +
9808 +#define vx_semary_dec(a) \
9809 +       vx_acc_cres(current_vx_info(), -1, a, VLIMIT_SEMARY)
9810 +
9811 +
9812 +#define vx_nsems_add(a,n) \
9813 +       vx_add_cres(current_vx_info(), n, a, VLIMIT_NSEMS)
9814 +
9815 +#define vx_nsems_sub(a,n) \
9816 +       vx_sub_cres(current_vx_info(), n, a, VLIMIT_NSEMS)
9817 +
9818 +
9819 +#else
9820 +#warning duplicate inclusion
9821 +#endif
9822 diff -NurpP --minimal linux-3.9.4/include/linux/vs_network.h linux-3.9.4-vs2.3.6.2/include/linux/vs_network.h
9823 --- linux-3.9.4/include/linux/vs_network.h      1970-01-01 00:00:00.000000000 +0000
9824 +++ linux-3.9.4-vs2.3.6.2/include/linux/vs_network.h    2013-05-31 14:47:11.000000000 +0000
9825 @@ -0,0 +1,169 @@
9826 +#ifndef _NX_VS_NETWORK_H
9827 +#define _NX_VS_NETWORK_H
9828 +
9829 +#include "vserver/context.h"
9830 +#include "vserver/network.h"
9831 +#include "vserver/base.h"
9832 +#include "vserver/check.h"
9833 +#include "vserver/debug.h"
9834 +
9835 +#include <linux/sched.h>
9836 +
9837 +
9838 +#define get_nx_info(i) __get_nx_info(i, __FILE__, __LINE__)
9839 +
9840 +static inline struct nx_info *__get_nx_info(struct nx_info *nxi,
9841 +       const char *_file, int _line)
9842 +{
9843 +       if (!nxi)
9844 +               return NULL;
9845 +
9846 +       vxlprintk(VXD_CBIT(nid, 2), "get_nx_info(%p[#%d.%d])",
9847 +               nxi, nxi ? nxi->nx_id : 0,
9848 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
9849 +               _file, _line);
9850 +
9851 +       atomic_inc(&nxi->nx_usecnt);
9852 +       return nxi;
9853 +}
9854 +
9855 +
9856 +extern void free_nx_info(struct nx_info *);
9857 +
9858 +#define put_nx_info(i) __put_nx_info(i, __FILE__, __LINE__)
9859 +
9860 +static inline void __put_nx_info(struct nx_info *nxi, const char *_file, int _line)
9861 +{
9862 +       if (!nxi)
9863 +               return;
9864 +
9865 +       vxlprintk(VXD_CBIT(nid, 2), "put_nx_info(%p[#%d.%d])",
9866 +               nxi, nxi ? nxi->nx_id : 0,
9867 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
9868 +               _file, _line);
9869 +
9870 +       if (atomic_dec_and_test(&nxi->nx_usecnt))
9871 +               free_nx_info(nxi);
9872 +}
9873 +
9874 +
9875 +#define init_nx_info(p, i) __init_nx_info(p, i, __FILE__, __LINE__)
9876 +
9877 +static inline void __init_nx_info(struct nx_info **nxp, struct nx_info *nxi,
9878 +               const char *_file, int _line)
9879 +{
9880 +       if (nxi) {
9881 +               vxlprintk(VXD_CBIT(nid, 3),
9882 +                       "init_nx_info(%p[#%d.%d])",
9883 +                       nxi, nxi ? nxi->nx_id : 0,
9884 +                       nxi ? atomic_read(&nxi->nx_usecnt) : 0,
9885 +                       _file, _line);
9886 +
9887 +               atomic_inc(&nxi->nx_usecnt);
9888 +       }
9889 +       *nxp = nxi;
9890 +}
9891 +
9892 +
9893 +#define set_nx_info(p, i) __set_nx_info(p, i, __FILE__, __LINE__)
9894 +
9895 +static inline void __set_nx_info(struct nx_info **nxp, struct nx_info *nxi,
9896 +       const char *_file, int _line)
9897 +{
9898 +       struct nx_info *nxo;
9899 +
9900 +       if (!nxi)
9901 +               return;
9902 +
9903 +       vxlprintk(VXD_CBIT(nid, 3), "set_nx_info(%p[#%d.%d])",
9904 +               nxi, nxi ? nxi->nx_id : 0,
9905 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
9906 +               _file, _line);
9907 +
9908 +       atomic_inc(&nxi->nx_usecnt);
9909 +       nxo = xchg(nxp, nxi);
9910 +       BUG_ON(nxo);
9911 +}
9912 +
9913 +#define clr_nx_info(p) __clr_nx_info(p, __FILE__, __LINE__)
9914 +
9915 +static inline void __clr_nx_info(struct nx_info **nxp,
9916 +       const char *_file, int _line)
9917 +{
9918 +       struct nx_info *nxo;
9919 +
9920 +       nxo = xchg(nxp, NULL);
9921 +       if (!nxo)
9922 +               return;
9923 +
9924 +       vxlprintk(VXD_CBIT(nid, 3), "clr_nx_info(%p[#%d.%d])",
9925 +               nxo, nxo ? nxo->nx_id : 0,
9926 +               nxo ? atomic_read(&nxo->nx_usecnt) : 0,
9927 +               _file, _line);
9928 +
9929 +       if (atomic_dec_and_test(&nxo->nx_usecnt))
9930 +               free_nx_info(nxo);
9931 +}
9932 +
9933 +
9934 +#define claim_nx_info(v, p) __claim_nx_info(v, p, __FILE__, __LINE__)
9935 +
9936 +static inline void __claim_nx_info(struct nx_info *nxi,
9937 +       struct task_struct *task, const char *_file, int _line)
9938 +{
9939 +       vxlprintk(VXD_CBIT(nid, 3), "claim_nx_info(%p[#%d.%d.%d]) %p",
9940 +               nxi, nxi ? nxi->nx_id : 0,
9941 +               nxi?atomic_read(&nxi->nx_usecnt):0,
9942 +               nxi?atomic_read(&nxi->nx_tasks):0,
9943 +               task, _file, _line);
9944 +
9945 +       atomic_inc(&nxi->nx_tasks);
9946 +}
9947 +
9948 +
9949 +extern void unhash_nx_info(struct nx_info *);
9950 +
9951 +#define release_nx_info(v, p) __release_nx_info(v, p, __FILE__, __LINE__)
9952 +
9953 +static inline void __release_nx_info(struct nx_info *nxi,
9954 +       struct task_struct *task, const char *_file, int _line)
9955 +{
9956 +       vxlprintk(VXD_CBIT(nid, 3), "release_nx_info(%p[#%d.%d.%d]) %p",
9957 +               nxi, nxi ? nxi->nx_id : 0,
9958 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
9959 +               nxi ? atomic_read(&nxi->nx_tasks) : 0,
9960 +               task, _file, _line);
9961 +
9962 +       might_sleep();
9963 +
9964 +       if (atomic_dec_and_test(&nxi->nx_tasks))
9965 +               unhash_nx_info(nxi);
9966 +}
9967 +
9968 +
9969 +#define task_get_nx_info(i)    __task_get_nx_info(i, __FILE__, __LINE__)
9970 +
9971 +static __inline__ struct nx_info *__task_get_nx_info(struct task_struct *p,
9972 +       const char *_file, int _line)
9973 +{
9974 +       struct nx_info *nxi;
9975 +
9976 +       task_lock(p);
9977 +       vxlprintk(VXD_CBIT(nid, 5), "task_get_nx_info(%p)",
9978 +               p, _file, _line);
9979 +       nxi = __get_nx_info(p->nx_info, _file, _line);
9980 +       task_unlock(p);
9981 +       return nxi;
9982 +}
9983 +
9984 +
9985 +static inline void exit_nx_info(struct task_struct *p)
9986 +{
9987 +       if (p->nx_info)
9988 +               release_nx_info(p->nx_info, p);
9989 +}
9990 +
9991 +
9992 +#else
9993 +#warning duplicate inclusion
9994 +#endif
9995 diff -NurpP --minimal linux-3.9.4/include/linux/vs_pid.h linux-3.9.4-vs2.3.6.2/include/linux/vs_pid.h
9996 --- linux-3.9.4/include/linux/vs_pid.h  1970-01-01 00:00:00.000000000 +0000
9997 +++ linux-3.9.4-vs2.3.6.2/include/linux/vs_pid.h        2013-05-31 14:47:11.000000000 +0000
9998 @@ -0,0 +1,50 @@
9999 +#ifndef _VS_PID_H
10000 +#define _VS_PID_H
10001 +
10002 +#include "vserver/base.h"
10003 +#include "vserver/check.h"
10004 +#include "vserver/context.h"
10005 +#include "vserver/debug.h"
10006 +#include "vserver/pid.h"
10007 +#include <linux/pid_namespace.h>
10008 +
10009 +
10010 +#define VXF_FAKE_INIT  (VXF_INFO_INIT | VXF_STATE_INIT)
10011 +
10012 +static inline
10013 +int vx_proc_task_visible(struct task_struct *task)
10014 +{
10015 +       if ((task->pid == 1) &&
10016 +               !vx_flags(VXF_FAKE_INIT, VXF_FAKE_INIT))
10017 +               /* show a blend through init */
10018 +               goto visible;
10019 +       if (vx_check(vx_task_xid(task), VS_WATCH | VS_IDENT))
10020 +               goto visible;
10021 +       return 0;
10022 +visible:
10023 +       return 1;
10024 +}
10025 +
10026 +#define find_task_by_real_pid(pid) find_task_by_pid_ns(pid, &init_pid_ns)
10027 +
10028 +
10029 +static inline
10030 +struct task_struct *vx_get_proc_task(struct inode *inode, struct pid *pid)
10031 +{
10032 +       struct task_struct *task = get_pid_task(pid, PIDTYPE_PID);
10033 +
10034 +       if (task && !vx_proc_task_visible(task)) {
10035 +               vxdprintk(VXD_CBIT(misc, 6),
10036 +                       "dropping task (get) %p[#%u,%u] for %p[#%u,%u]",
10037 +                       task, task->xid, task->pid,
10038 +                       current, current->xid, current->pid);
10039 +               put_task_struct(task);
10040 +               task = NULL;
10041 +       }
10042 +       return task;
10043 +}
10044 +
10045 +
10046 +#else
10047 +#warning duplicate inclusion
10048 +#endif
10049 diff -NurpP --minimal linux-3.9.4/include/linux/vs_sched.h linux-3.9.4-vs2.3.6.2/include/linux/vs_sched.h
10050 --- linux-3.9.4/include/linux/vs_sched.h        1970-01-01 00:00:00.000000000 +0000
10051 +++ linux-3.9.4-vs2.3.6.2/include/linux/vs_sched.h      2013-05-31 14:47:11.000000000 +0000
10052 @@ -0,0 +1,40 @@
10053 +#ifndef _VS_SCHED_H
10054 +#define _VS_SCHED_H
10055 +
10056 +#include "vserver/base.h"
10057 +#include "vserver/context.h"
10058 +#include "vserver/sched.h"
10059 +
10060 +
10061 +#define MAX_PRIO_BIAS           20
10062 +#define MIN_PRIO_BIAS          -20
10063 +
10064 +static inline
10065 +int vx_adjust_prio(struct task_struct *p, int prio, int max_user)
10066 +{
10067 +       struct vx_info *vxi = p->vx_info;
10068 +
10069 +       if (vxi)
10070 +               prio += vx_cpu(vxi, sched_pc).prio_bias;
10071 +       return prio;
10072 +}
10073 +
10074 +static inline void vx_account_user(struct vx_info *vxi,
10075 +       cputime_t cputime, int nice)
10076 +{
10077 +       if (!vxi)
10078 +               return;
10079 +       vx_cpu(vxi, sched_pc).user_ticks += cputime;
10080 +}
10081 +
10082 +static inline void vx_account_system(struct vx_info *vxi,
10083 +       cputime_t cputime, int idle)
10084 +{
10085 +       if (!vxi)
10086 +               return;
10087 +       vx_cpu(vxi, sched_pc).sys_ticks += cputime;
10088 +}
10089 +
10090 +#else
10091 +#warning duplicate inclusion
10092 +#endif
10093 diff -NurpP --minimal linux-3.9.4/include/linux/vs_socket.h linux-3.9.4-vs2.3.6.2/include/linux/vs_socket.h
10094 --- linux-3.9.4/include/linux/vs_socket.h       1970-01-01 00:00:00.000000000 +0000
10095 +++ linux-3.9.4-vs2.3.6.2/include/linux/vs_socket.h     2013-05-31 14:47:11.000000000 +0000
10096 @@ -0,0 +1,67 @@
10097 +#ifndef _VS_SOCKET_H
10098 +#define _VS_SOCKET_H
10099 +
10100 +#include "vserver/debug.h"
10101 +#include "vserver/base.h"
10102 +#include "vserver/cacct.h"
10103 +#include "vserver/context.h"
10104 +#include "vserver/tag.h"
10105 +
10106 +
10107 +/* socket accounting */
10108 +
10109 +#include <linux/socket.h>
10110 +
10111 +static inline int vx_sock_type(int family)
10112 +{
10113 +       switch (family) {
10114 +       case PF_UNSPEC:
10115 +               return VXA_SOCK_UNSPEC;
10116 +       case PF_UNIX:
10117 +               return VXA_SOCK_UNIX;
10118 +       case PF_INET:
10119 +               return VXA_SOCK_INET;
10120 +       case PF_INET6:
10121 +               return VXA_SOCK_INET6;
10122 +       case PF_PACKET:
10123 +               return VXA_SOCK_PACKET;
10124 +       default:
10125 +               return VXA_SOCK_OTHER;
10126 +       }
10127 +}
10128 +
10129 +#define vx_acc_sock(v, f, p, s) \
10130 +       __vx_acc_sock(v, f, p, s, __FILE__, __LINE__)
10131 +
10132 +static inline void __vx_acc_sock(struct vx_info *vxi,
10133 +       int family, int pos, int size, char *file, int line)
10134 +{
10135 +       if (vxi) {
10136 +               int type = vx_sock_type(family);
10137 +
10138 +               atomic_long_inc(&vxi->cacct.sock[type][pos].count);
10139 +               atomic_long_add(size, &vxi->cacct.sock[type][pos].total);
10140 +       }
10141 +}
10142 +
10143 +#define vx_sock_recv(sk, s) \
10144 +       vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 0, s)
10145 +#define vx_sock_send(sk, s) \
10146 +       vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 1, s)
10147 +#define vx_sock_fail(sk, s) \
10148 +       vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 2, s)
10149 +
10150 +
10151 +#define sock_vx_init(s) do {           \
10152 +       (s)->sk_xid = 0;                \
10153 +       (s)->sk_vx_info = NULL;         \
10154 +       } while (0)
10155 +
10156 +#define sock_nx_init(s) do {           \
10157 +       (s)->sk_nid = 0;                \
10158 +       (s)->sk_nx_info = NULL;         \
10159 +       } while (0)
10160 +
10161 +#else
10162 +#warning duplicate inclusion
10163 +#endif
10164 diff -NurpP --minimal linux-3.9.4/include/linux/vs_tag.h linux-3.9.4-vs2.3.6.2/include/linux/vs_tag.h
10165 --- linux-3.9.4/include/linux/vs_tag.h  1970-01-01 00:00:00.000000000 +0000
10166 +++ linux-3.9.4-vs2.3.6.2/include/linux/vs_tag.h        2013-05-31 14:47:11.000000000 +0000
10167 @@ -0,0 +1,47 @@
10168 +#ifndef _VS_TAG_H
10169 +#define _VS_TAG_H
10170 +
10171 +#include <linux/vserver/tag.h>
10172 +
10173 +/* check conditions */
10174 +
10175 +#define DX_ADMIN       0x0001
10176 +#define DX_WATCH       0x0002
10177 +#define DX_HOSTID      0x0008
10178 +
10179 +#define DX_IDENT       0x0010
10180 +
10181 +#define DX_ARG_MASK    0x0010
10182 +
10183 +
10184 +#define dx_task_tag(t) ((t)->tag)
10185 +
10186 +#define dx_current_tag() dx_task_tag(current)
10187 +
10188 +#define dx_check(c, m) __dx_check(dx_current_tag(), c, m)
10189 +
10190 +#define dx_weak_check(c, m)    ((m) ? dx_check(c, m) : 1)
10191 +
10192 +
10193 +/*
10194 + * check current context for ADMIN/WATCH and
10195 + * optionally against supplied argument
10196 + */
10197 +static inline int __dx_check(tag_t cid, tag_t id, unsigned int mode)
10198 +{
10199 +       if (mode & DX_ARG_MASK) {
10200 +               if ((mode & DX_IDENT) && (id == cid))
10201 +                       return 1;
10202 +       }
10203 +       return (((mode & DX_ADMIN) && (cid == 0)) ||
10204 +               ((mode & DX_WATCH) && (cid == 1)) ||
10205 +               ((mode & DX_HOSTID) && (id == 0)));
10206 +}
10207 +
10208 +struct inode;
10209 +int dx_permission(const struct inode *inode, int mask);
10210 +
10211 +
10212 +#else
10213 +#warning duplicate inclusion
10214 +#endif
10215 diff -NurpP --minimal linux-3.9.4/include/linux/vs_time.h linux-3.9.4-vs2.3.6.2/include/linux/vs_time.h
10216 --- linux-3.9.4/include/linux/vs_time.h 1970-01-01 00:00:00.000000000 +0000
10217 +++ linux-3.9.4-vs2.3.6.2/include/linux/vs_time.h       2013-05-31 14:47:11.000000000 +0000
10218 @@ -0,0 +1,19 @@
10219 +#ifndef _VS_TIME_H
10220 +#define _VS_TIME_H
10221 +
10222 +
10223 +/* time faking stuff */
10224 +
10225 +#ifdef CONFIG_VSERVER_VTIME
10226 +
10227 +extern void vx_adjust_timespec(struct timespec *ts);
10228 +extern int vx_settimeofday(const struct timespec *ts);
10229 +
10230 +#else
10231 +#define        vx_adjust_timespec(t)   do { } while (0)
10232 +#define        vx_settimeofday(t)      do_settimeofday(t)
10233 +#endif
10234 +
10235 +#else
10236 +#warning duplicate inclusion
10237 +#endif
10238 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/base.h linux-3.9.4-vs2.3.6.2/include/linux/vserver/base.h
10239 --- linux-3.9.4/include/linux/vserver/base.h    1970-01-01 00:00:00.000000000 +0000
10240 +++ linux-3.9.4-vs2.3.6.2/include/linux/vserver/base.h  2013-05-31 17:55:09.000000000 +0000
10241 @@ -0,0 +1,181 @@
10242 +#ifndef _VSERVER_BASE_H
10243 +#define _VSERVER_BASE_H
10244 +
10245 +
10246 +/* context state changes */
10247 +
10248 +enum {
10249 +       VSC_STARTUP = 1,
10250 +       VSC_SHUTDOWN,
10251 +
10252 +       VSC_NETUP,
10253 +       VSC_NETDOWN,
10254 +};
10255 +
10256 +
10257 +
10258 +#define vx_task_xid(t) ((t)->xid)
10259 +
10260 +#define vx_current_xid() vx_task_xid(current)
10261 +
10262 +#define current_vx_info() (current->vx_info)
10263 +
10264 +
10265 +#define nx_task_nid(t) ((t)->nid)
10266 +
10267 +#define nx_current_nid() nx_task_nid(current)
10268 +
10269 +#define current_nx_info() (current->nx_info)
10270 +
10271 +
10272 +/* generic flag merging */
10273 +
10274 +#define vs_check_flags(v, m, f)        (((v) & (m)) ^ (f))
10275 +
10276 +#define vs_mask_flags(v, f, m) (((v) & ~(m)) | ((f) & (m)))
10277 +
10278 +#define vs_mask_mask(v, f, m)  (((v) & ~(m)) | ((v) & (f) & (m)))
10279 +
10280 +#define vs_check_bit(v, n)     ((v) & (1LL << (n)))
10281 +
10282 +
10283 +/* context flags */
10284 +
10285 +#define __vx_flags(v)  ((v) ? (v)->vx_flags : 0)
10286 +
10287 +#define vx_current_flags()     __vx_flags(current_vx_info())
10288 +
10289 +#define vx_info_flags(v, m, f) \
10290 +       vs_check_flags(__vx_flags(v), m, f)
10291 +
10292 +#define task_vx_flags(t, m, f) \
10293 +       ((t) && vx_info_flags((t)->vx_info, m, f))
10294 +
10295 +#define vx_flags(m, f) vx_info_flags(current_vx_info(), m, f)
10296 +
10297 +
10298 +/* context caps */
10299 +
10300 +#define __vx_ccaps(v)  ((v) ? (v)->vx_ccaps : 0)
10301 +
10302 +#define vx_current_ccaps()     __vx_ccaps(current_vx_info())
10303 +
10304 +#define vx_info_ccaps(v, c)    (__vx_ccaps(v) & (c))
10305 +
10306 +#define vx_ccaps(c)    vx_info_ccaps(current_vx_info(), (c))
10307 +
10308 +
10309 +
10310 +/* network flags */
10311 +
10312 +#define __nx_flags(n)  ((n) ? (n)->nx_flags : 0)
10313 +
10314 +#define nx_current_flags()     __nx_flags(current_nx_info())
10315 +
10316 +#define nx_info_flags(n, m, f) \
10317 +       vs_check_flags(__nx_flags(n), m, f)
10318 +
10319 +#define task_nx_flags(t, m, f) \
10320 +       ((t) && nx_info_flags((t)->nx_info, m, f))
10321 +
10322 +#define nx_flags(m, f) nx_info_flags(current_nx_info(), m, f)
10323 +
10324 +
10325 +/* network caps */
10326 +
10327 +#define __nx_ncaps(n)  ((n) ? (n)->nx_ncaps : 0)
10328 +
10329 +#define nx_current_ncaps()     __nx_ncaps(current_nx_info())
10330 +
10331 +#define nx_info_ncaps(n, c)    (__nx_ncaps(n) & (c))
10332 +
10333 +#define nx_ncaps(c)    nx_info_ncaps(current_nx_info(), c)
10334 +
10335 +
10336 +/* context mask capabilities */
10337 +
10338 +#define __vx_mcaps(v)  ((v) ? (v)->vx_ccaps >> 32UL : ~0 )
10339 +
10340 +#define vx_info_mcaps(v, c)    (__vx_mcaps(v) & (c))
10341 +
10342 +#define vx_mcaps(c)    vx_info_mcaps(current_vx_info(), c)
10343 +
10344 +
10345 +/* context bcap mask */
10346 +
10347 +#define __vx_bcaps(v)          ((v)->vx_bcaps)
10348 +
10349 +#define vx_current_bcaps()     __vx_bcaps(current_vx_info())
10350 +
10351 +
10352 +/* mask given bcaps */
10353 +
10354 +#define vx_info_mbcaps(v, c)   ((v) ? cap_intersect(__vx_bcaps(v), c) : c)
10355 +
10356 +#define vx_mbcaps(c)           vx_info_mbcaps(current_vx_info(), c)
10357 +
10358 +
10359 +/* masked cap_bset */
10360 +
10361 +#define vx_info_cap_bset(v)    vx_info_mbcaps(v, current->cap_bset)
10362 +
10363 +#define vx_current_cap_bset()  vx_info_cap_bset(current_vx_info())
10364 +
10365 +#if 0
10366 +#define vx_info_mbcap(v, b) \
10367 +       (!vx_info_flags(v, VXF_STATE_SETUP, 0) ? \
10368 +       vx_info_bcaps(v, b) : (b))
10369 +
10370 +#define task_vx_mbcap(t, b) \
10371 +       vx_info_mbcap((t)->vx_info, (t)->b)
10372 +
10373 +#define vx_mbcap(b)    task_vx_mbcap(current, b)
10374 +#endif
10375 +
10376 +#define vx_cap_raised(v, c, f) cap_raised(vx_info_mbcaps(v, c), f)
10377 +
10378 +#define vx_capable(b, c) (capable(b) || \
10379 +       (cap_raised(current_cap(), b) && vx_ccaps(c)))
10380 +
10381 +#define vx_ns_capable(n, b, c) (ns_capable(n, b) || \
10382 +       (cap_raised(current_cap(), b) && vx_ccaps(c)))
10383 +
10384 +#define nx_capable(b, c) (capable(b) || \
10385 +       (cap_raised(current_cap(), b) && nx_ncaps(c)))
10386 +
10387 +#define vx_task_initpid(t, n) \
10388 +       ((t)->vx_info && \
10389 +       ((t)->vx_info->vx_initpid == (n)))
10390 +
10391 +#define vx_current_initpid(n)  vx_task_initpid(current, n)
10392 +
10393 +
10394 +/* context unshare mask */
10395 +
10396 +#define __vx_umask(v)          ((v)->vx_umask)
10397 +
10398 +#define vx_current_umask()     __vx_umask(current_vx_info())
10399 +
10400 +#define vx_can_unshare(b, f) (capable(b) || \
10401 +       (cap_raised(current_cap(), b) && \
10402 +       !((f) & ~vx_current_umask())))
10403 +
10404 +#define vx_ns_can_unshare(n, b, f) (ns_capable(n, b) || \
10405 +       (cap_raised(current_cap(), b) && \
10406 +       !((f) & ~vx_current_umask())))
10407 +
10408 +#define __vx_wmask(v)          ((v)->vx_wmask)
10409 +
10410 +#define vx_current_wmask()     __vx_wmask(current_vx_info())
10411 +
10412 +
10413 +#define __vx_state(v)  ((v) ? ((v)->vx_state) : 0)
10414 +
10415 +#define vx_info_state(v, m)    (__vx_state(v) & (m))
10416 +
10417 +
10418 +#define __nx_state(n)  ((n) ? ((n)->nx_state) : 0)
10419 +
10420 +#define nx_info_state(n, m)    (__nx_state(n) & (m))
10421 +
10422 +#endif
10423 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/cacct.h linux-3.9.4-vs2.3.6.2/include/linux/vserver/cacct.h
10424 --- linux-3.9.4/include/linux/vserver/cacct.h   1970-01-01 00:00:00.000000000 +0000
10425 +++ linux-3.9.4-vs2.3.6.2/include/linux/vserver/cacct.h 2013-05-31 14:47:11.000000000 +0000
10426 @@ -0,0 +1,15 @@
10427 +#ifndef _VSERVER_CACCT_H
10428 +#define _VSERVER_CACCT_H
10429 +
10430 +
10431 +enum sock_acc_field {
10432 +       VXA_SOCK_UNSPEC = 0,
10433 +       VXA_SOCK_UNIX,
10434 +       VXA_SOCK_INET,
10435 +       VXA_SOCK_INET6,
10436 +       VXA_SOCK_PACKET,
10437 +       VXA_SOCK_OTHER,
10438 +       VXA_SOCK_SIZE   /* array size */
10439 +};
10440 +
10441 +#endif /* _VSERVER_CACCT_H */
10442 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/cacct_cmd.h linux-3.9.4-vs2.3.6.2/include/linux/vserver/cacct_cmd.h
10443 --- linux-3.9.4/include/linux/vserver/cacct_cmd.h       1970-01-01 00:00:00.000000000 +0000
10444 +++ linux-3.9.4-vs2.3.6.2/include/linux/vserver/cacct_cmd.h     2013-05-31 14:47:11.000000000 +0000
10445 @@ -0,0 +1,10 @@
10446 +#ifndef _VSERVER_CACCT_CMD_H
10447 +#define _VSERVER_CACCT_CMD_H
10448 +
10449 +
10450 +#include <linux/compiler.h>
10451 +#include <uapi/vserver/cacct_cmd.h>
10452 +
10453 +extern int vc_sock_stat(struct vx_info *, void __user *);
10454 +
10455 +#endif /* _VSERVER_CACCT_CMD_H */
10456 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/cacct_def.h linux-3.9.4-vs2.3.6.2/include/linux/vserver/cacct_def.h
10457 --- linux-3.9.4/include/linux/vserver/cacct_def.h       1970-01-01 00:00:00.000000000 +0000
10458 +++ linux-3.9.4-vs2.3.6.2/include/linux/vserver/cacct_def.h     2013-05-31 14:47:11.000000000 +0000
10459 @@ -0,0 +1,43 @@
10460 +#ifndef _VSERVER_CACCT_DEF_H
10461 +#define _VSERVER_CACCT_DEF_H
10462 +
10463 +#include <asm/atomic.h>
10464 +#include <linux/vserver/cacct.h>
10465 +
10466 +
10467 +struct _vx_sock_acc {
10468 +       atomic_long_t count;
10469 +       atomic_long_t total;
10470 +};
10471 +
10472 +/* context sub struct */
10473 +
10474 +struct _vx_cacct {
10475 +       struct _vx_sock_acc sock[VXA_SOCK_SIZE][3];
10476 +       atomic_t slab[8];
10477 +       atomic_t page[6][8];
10478 +};
10479 +
10480 +#ifdef CONFIG_VSERVER_DEBUG
10481 +
10482 +static inline void __dump_vx_cacct(struct _vx_cacct *cacct)
10483 +{
10484 +       int i, j;
10485 +
10486 +       printk("\t_vx_cacct:");
10487 +       for (i = 0; i < 6; i++) {
10488 +               struct _vx_sock_acc *ptr = cacct->sock[i];
10489 +
10490 +               printk("\t [%d] =", i);
10491 +               for (j = 0; j < 3; j++) {
10492 +                       printk(" [%d] = %8lu, %8lu", j,
10493 +                               atomic_long_read(&ptr[j].count),
10494 +                               atomic_long_read(&ptr[j].total));
10495 +               }
10496 +               printk("\n");
10497 +       }
10498 +}
10499 +
10500 +#endif
10501 +
10502 +#endif /* _VSERVER_CACCT_DEF_H */
10503 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/cacct_int.h linux-3.9.4-vs2.3.6.2/include/linux/vserver/cacct_int.h
10504 --- linux-3.9.4/include/linux/vserver/cacct_int.h       1970-01-01 00:00:00.000000000 +0000
10505 +++ linux-3.9.4-vs2.3.6.2/include/linux/vserver/cacct_int.h     2013-05-31 14:47:11.000000000 +0000
10506 @@ -0,0 +1,17 @@
10507 +#ifndef _VSERVER_CACCT_INT_H
10508 +#define _VSERVER_CACCT_INT_H
10509 +
10510 +static inline
10511 +unsigned long vx_sock_count(struct _vx_cacct *cacct, int type, int pos)
10512 +{
10513 +       return atomic_long_read(&cacct->sock[type][pos].count);
10514 +}
10515 +
10516 +
10517 +static inline
10518 +unsigned long vx_sock_total(struct _vx_cacct *cacct, int type, int pos)
10519 +{
10520 +       return atomic_long_read(&cacct->sock[type][pos].total);
10521 +}
10522 +
10523 +#endif /* _VSERVER_CACCT_INT_H */
10524 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/check.h linux-3.9.4-vs2.3.6.2/include/linux/vserver/check.h
10525 --- linux-3.9.4/include/linux/vserver/check.h   1970-01-01 00:00:00.000000000 +0000
10526 +++ linux-3.9.4-vs2.3.6.2/include/linux/vserver/check.h 2013-05-31 14:47:11.000000000 +0000
10527 @@ -0,0 +1,89 @@
10528 +#ifndef _VSERVER_CHECK_H
10529 +#define _VSERVER_CHECK_H
10530 +
10531 +
10532 +#define MAX_S_CONTEXT  65535   /* Arbitrary limit */
10533 +
10534 +#ifdef CONFIG_VSERVER_DYNAMIC_IDS
10535 +#define MIN_D_CONTEXT  49152   /* dynamic contexts start here */
10536 +#else
10537 +#define MIN_D_CONTEXT  65536
10538 +#endif
10539 +
10540 +/* check conditions */
10541 +
10542 +#define VS_ADMIN       0x0001
10543 +#define VS_WATCH       0x0002
10544 +#define VS_HIDE                0x0004
10545 +#define VS_HOSTID      0x0008
10546 +
10547 +#define VS_IDENT       0x0010
10548 +#define VS_EQUIV       0x0020
10549 +#define VS_PARENT      0x0040
10550 +#define VS_CHILD       0x0080
10551 +
10552 +#define VS_ARG_MASK    0x00F0
10553 +
10554 +#define VS_DYNAMIC     0x0100
10555 +#define VS_STATIC      0x0200
10556 +
10557 +#define VS_ATR_MASK    0x0F00
10558 +
10559 +#ifdef CONFIG_VSERVER_PRIVACY
10560 +#define VS_ADMIN_P     (0)
10561 +#define VS_WATCH_P     (0)
10562 +#else
10563 +#define VS_ADMIN_P     VS_ADMIN
10564 +#define VS_WATCH_P     VS_WATCH
10565 +#endif
10566 +
10567 +#define VS_HARDIRQ     0x1000
10568 +#define VS_SOFTIRQ     0x2000
10569 +#define VS_IRQ         0x4000
10570 +
10571 +#define VS_IRQ_MASK    0xF000
10572 +
10573 +#include <linux/hardirq.h>
10574 +
10575 +/*
10576 + * check current context for ADMIN/WATCH and
10577 + * optionally against supplied argument
10578 + */
10579 +static inline int __vs_check(int cid, int id, unsigned int mode)
10580 +{
10581 +       if (mode & VS_ARG_MASK) {
10582 +               if ((mode & VS_IDENT) && (id == cid))
10583 +                       return 1;
10584 +       }
10585 +       if (mode & VS_ATR_MASK) {
10586 +               if ((mode & VS_DYNAMIC) &&
10587 +                       (id >= MIN_D_CONTEXT) &&
10588 +                       (id <= MAX_S_CONTEXT))
10589 +                       return 1;
10590 +               if ((mode & VS_STATIC) &&
10591 +                       (id > 1) && (id < MIN_D_CONTEXT))
10592 +                       return 1;
10593 +       }
10594 +       if (mode & VS_IRQ_MASK) {
10595 +               if ((mode & VS_IRQ) && unlikely(in_interrupt()))
10596 +                       return 1;
10597 +               if ((mode & VS_HARDIRQ) && unlikely(in_irq()))
10598 +                       return 1;
10599 +               if ((mode & VS_SOFTIRQ) && unlikely(in_softirq()))
10600 +                       return 1;
10601 +       }
10602 +       return (((mode & VS_ADMIN) && (cid == 0)) ||
10603 +               ((mode & VS_WATCH) && (cid == 1)) ||
10604 +               ((mode & VS_HOSTID) && (id == 0)));
10605 +}
10606 +
10607 +#define vx_check(c, m) __vs_check(vx_current_xid(), c, (m) | VS_IRQ)
10608 +
10609 +#define vx_weak_check(c, m)    ((m) ? vx_check(c, m) : 1)
10610 +
10611 +
10612 +#define nx_check(c, m) __vs_check(nx_current_nid(), c, m)
10613 +
10614 +#define nx_weak_check(c, m)    ((m) ? nx_check(c, m) : 1)
10615 +
10616 +#endif
10617 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/context.h linux-3.9.4-vs2.3.6.2/include/linux/vserver/context.h
10618 --- linux-3.9.4/include/linux/vserver/context.h 1970-01-01 00:00:00.000000000 +0000
10619 +++ linux-3.9.4-vs2.3.6.2/include/linux/vserver/context.h       2013-05-31 14:47:11.000000000 +0000
10620 @@ -0,0 +1,110 @@
10621 +#ifndef _VSERVER_CONTEXT_H
10622 +#define _VSERVER_CONTEXT_H
10623 +
10624 +
10625 +#include <linux/list.h>
10626 +#include <linux/spinlock.h>
10627 +#include <linux/rcupdate.h>
10628 +#include <uapi/vserver/context.h>
10629 +
10630 +#include "limit_def.h"
10631 +#include "sched_def.h"
10632 +#include "cvirt_def.h"
10633 +#include "cacct_def.h"
10634 +#include "device_def.h"
10635 +
10636 +#define VX_SPACES      2
10637 +
10638 +struct _vx_info_pc {
10639 +       struct _vx_sched_pc sched_pc;
10640 +       struct _vx_cvirt_pc cvirt_pc;
10641 +};
10642 +
10643 +struct _vx_space {
10644 +       unsigned long vx_nsmask;                /* assignment mask */
10645 +       struct nsproxy *vx_nsproxy;             /* private namespaces */
10646 +       struct fs_struct *vx_fs;                /* private namespace fs */
10647 +       const struct cred *vx_cred;             /* task credentials */
10648 +};
10649 +
10650 +struct vx_info {
10651 +       struct hlist_node vx_hlist;             /* linked list of contexts */
10652 +       xid_t vx_id;                            /* context id */
10653 +       atomic_t vx_usecnt;                     /* usage count */
10654 +       atomic_t vx_tasks;                      /* tasks count */
10655 +       struct vx_info *vx_parent;              /* parent context */
10656 +       int vx_state;                           /* context state */
10657 +
10658 +       struct _vx_space space[VX_SPACES];      /* namespace store */
10659 +
10660 +       uint64_t vx_flags;                      /* context flags */
10661 +       uint64_t vx_ccaps;                      /* context caps (vserver) */
10662 +       uint64_t vx_umask;                      /* unshare mask (guest) */
10663 +       uint64_t vx_wmask;                      /* warn mask (guest) */
10664 +       kernel_cap_t vx_bcaps;                  /* bounding caps (system) */
10665 +
10666 +       struct task_struct *vx_reaper;          /* guest reaper process */
10667 +       pid_t vx_initpid;                       /* PID of guest init */
10668 +       int64_t vx_badness_bias;                /* OOM points bias */
10669 +
10670 +       struct _vx_limit limit;                 /* vserver limits */
10671 +       struct _vx_sched sched;                 /* vserver scheduler */
10672 +       struct _vx_cvirt cvirt;                 /* virtual/bias stuff */
10673 +       struct _vx_cacct cacct;                 /* context accounting */
10674 +
10675 +       struct _vx_device dmap;                 /* default device map targets */
10676 +
10677 +#ifndef CONFIG_SMP
10678 +       struct _vx_info_pc info_pc;             /* per cpu data */
10679 +#else
10680 +       struct _vx_info_pc *ptr_pc;             /* per cpu array */
10681 +#endif
10682 +
10683 +       wait_queue_head_t vx_wait;              /* context exit waitqueue */
10684 +       int reboot_cmd;                         /* last sys_reboot() cmd */
10685 +       int exit_code;                          /* last process exit code */
10686 +
10687 +       char vx_name[65];                       /* vserver name */
10688 +};
10689 +
10690 +#ifndef CONFIG_SMP
10691 +#define        vx_ptr_pc(vxi)          (&(vxi)->info_pc)
10692 +#define        vx_per_cpu(vxi, v, id)  vx_ptr_pc(vxi)->v
10693 +#else
10694 +#define        vx_ptr_pc(vxi)          ((vxi)->ptr_pc)
10695 +#define        vx_per_cpu(vxi, v, id)  per_cpu_ptr(vx_ptr_pc(vxi), id)->v
10696 +#endif
10697 +
10698 +#define        vx_cpu(vxi, v)          vx_per_cpu(vxi, v, smp_processor_id())
10699 +
10700 +
10701 +struct vx_info_save {
10702 +       struct vx_info *vxi;
10703 +       xid_t xid;
10704 +};
10705 +
10706 +
10707 +/* status flags */
10708 +
10709 +#define VXS_HASHED     0x0001
10710 +#define VXS_PAUSED     0x0010
10711 +#define VXS_SHUTDOWN   0x0100
10712 +#define VXS_HELPER     0x1000
10713 +#define VXS_RELEASED   0x8000
10714 +
10715 +
10716 +extern void claim_vx_info(struct vx_info *, struct task_struct *);
10717 +extern void release_vx_info(struct vx_info *, struct task_struct *);
10718 +
10719 +extern struct vx_info *lookup_vx_info(int);
10720 +extern struct vx_info *lookup_or_create_vx_info(int);
10721 +
10722 +extern int get_xid_list(int, unsigned int *, int);
10723 +extern int xid_is_hashed(xid_t);
10724 +
10725 +extern int vx_migrate_task(struct task_struct *, struct vx_info *, int);
10726 +
10727 +extern long vs_state_change(struct vx_info *, unsigned int);
10728 +
10729 +
10730 +#endif /* _VSERVER_CONTEXT_H */
10731 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/context_cmd.h linux-3.9.4-vs2.3.6.2/include/linux/vserver/context_cmd.h
10732 --- linux-3.9.4/include/linux/vserver/context_cmd.h     1970-01-01 00:00:00.000000000 +0000
10733 +++ linux-3.9.4-vs2.3.6.2/include/linux/vserver/context_cmd.h   2013-05-31 14:47:11.000000000 +0000
10734 @@ -0,0 +1,33 @@
10735 +#ifndef _VSERVER_CONTEXT_CMD_H
10736 +#define _VSERVER_CONTEXT_CMD_H
10737 +
10738 +#include <uapi/vserver/context_cmd.h>
10739 +
10740 +extern int vc_task_xid(uint32_t);
10741 +
10742 +extern int vc_vx_info(struct vx_info *, void __user *);
10743 +
10744 +extern int vc_ctx_stat(struct vx_info *, void __user *);
10745 +
10746 +extern int vc_ctx_create(uint32_t, void __user *);
10747 +extern int vc_ctx_migrate(struct vx_info *, void __user *);
10748 +
10749 +extern int vc_get_cflags(struct vx_info *, void __user *);
10750 +extern int vc_set_cflags(struct vx_info *, void __user *);
10751 +
10752 +extern int vc_get_ccaps(struct vx_info *, void __user *);
10753 +extern int vc_set_ccaps(struct vx_info *, void __user *);
10754 +
10755 +extern int vc_get_bcaps(struct vx_info *, void __user *);
10756 +extern int vc_set_bcaps(struct vx_info *, void __user *);
10757 +
10758 +extern int vc_get_umask(struct vx_info *, void __user *);
10759 +extern int vc_set_umask(struct vx_info *, void __user *);
10760 +
10761 +extern int vc_get_wmask(struct vx_info *, void __user *);
10762 +extern int vc_set_wmask(struct vx_info *, void __user *);
10763 +
10764 +extern int vc_get_badness(struct vx_info *, void __user *);
10765 +extern int vc_set_badness(struct vx_info *, void __user *);
10766 +
10767 +#endif /* _VSERVER_CONTEXT_CMD_H */
10768 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/cvirt.h linux-3.9.4-vs2.3.6.2/include/linux/vserver/cvirt.h
10769 --- linux-3.9.4/include/linux/vserver/cvirt.h   1970-01-01 00:00:00.000000000 +0000
10770 +++ linux-3.9.4-vs2.3.6.2/include/linux/vserver/cvirt.h 2013-05-31 14:47:11.000000000 +0000
10771 @@ -0,0 +1,18 @@
10772 +#ifndef _VSERVER_CVIRT_H
10773 +#define _VSERVER_CVIRT_H
10774 +
10775 +struct timespec;
10776 +
10777 +void vx_vsi_boottime(struct timespec *);
10778 +
10779 +void vx_vsi_uptime(struct timespec *, struct timespec *);
10780 +
10781 +
10782 +struct vx_info;
10783 +
10784 +void vx_update_load(struct vx_info *);
10785 +
10786 +
10787 +int vx_do_syslog(int, char __user *, int);
10788 +
10789 +#endif /* _VSERVER_CVIRT_H */
10790 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/cvirt_cmd.h linux-3.9.4-vs2.3.6.2/include/linux/vserver/cvirt_cmd.h
10791 --- linux-3.9.4/include/linux/vserver/cvirt_cmd.h       1970-01-01 00:00:00.000000000 +0000
10792 +++ linux-3.9.4-vs2.3.6.2/include/linux/vserver/cvirt_cmd.h     2013-05-31 14:47:11.000000000 +0000
10793 @@ -0,0 +1,13 @@
10794 +#ifndef _VSERVER_CVIRT_CMD_H
10795 +#define _VSERVER_CVIRT_CMD_H
10796 +
10797 +
10798 +#include <linux/compiler.h>
10799 +#include <uapi/vserver/cvirt_cmd.h>
10800 +
10801 +extern int vc_set_vhi_name(struct vx_info *, void __user *);
10802 +extern int vc_get_vhi_name(struct vx_info *, void __user *);
10803 +
10804 +extern int vc_virt_stat(struct vx_info *, void __user *);
10805 +
10806 +#endif /* _VSERVER_CVIRT_CMD_H */
10807 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/cvirt_def.h linux-3.9.4-vs2.3.6.2/include/linux/vserver/cvirt_def.h
10808 --- linux-3.9.4/include/linux/vserver/cvirt_def.h       1970-01-01 00:00:00.000000000 +0000
10809 +++ linux-3.9.4-vs2.3.6.2/include/linux/vserver/cvirt_def.h     2013-05-31 14:47:11.000000000 +0000
10810 @@ -0,0 +1,80 @@
10811 +#ifndef _VSERVER_CVIRT_DEF_H
10812 +#define _VSERVER_CVIRT_DEF_H
10813 +
10814 +#include <linux/jiffies.h>
10815 +#include <linux/spinlock.h>
10816 +#include <linux/wait.h>
10817 +#include <linux/time.h>
10818 +#include <asm/atomic.h>
10819 +
10820 +
10821 +struct _vx_usage_stat {
10822 +       uint64_t user;
10823 +       uint64_t nice;
10824 +       uint64_t system;
10825 +       uint64_t softirq;
10826 +       uint64_t irq;
10827 +       uint64_t idle;
10828 +       uint64_t iowait;
10829 +};
10830 +
10831 +struct _vx_syslog {
10832 +       wait_queue_head_t log_wait;
10833 +       spinlock_t logbuf_lock;         /* lock for the log buffer */
10834 +
10835 +       unsigned long log_start;        /* next char to be read by syslog() */
10836 +       unsigned long con_start;        /* next char to be sent to consoles */
10837 +       unsigned long log_end;  /* most-recently-written-char + 1 */
10838 +       unsigned long logged_chars;     /* #chars since last read+clear operation */
10839 +
10840 +       char log_buf[1024];
10841 +};
10842 +
10843 +
10844 +/* context sub struct */
10845 +
10846 +struct _vx_cvirt {
10847 +       atomic_t nr_threads;            /* number of current threads */
10848 +       atomic_t nr_running;            /* number of running threads */
10849 +       atomic_t nr_uninterruptible;    /* number of uninterruptible threads */
10850 +
10851 +       atomic_t nr_onhold;             /* processes on hold */
10852 +       uint32_t onhold_last;           /* jiffies when put on hold */
10853 +
10854 +       struct timespec bias_ts;        /* time offset to the host */
10855 +       struct timespec bias_idle;
10856 +       struct timespec bias_uptime;    /* context creation point */
10857 +       uint64_t bias_clock;            /* offset in clock_t */
10858 +
10859 +       spinlock_t load_lock;           /* lock for the load averages */
10860 +       atomic_t load_updates;          /* nr of load updates done so far */
10861 +       uint32_t load_last;             /* last time load was calculated */
10862 +       uint32_t load[3];               /* load averages 1,5,15 */
10863 +
10864 +       atomic_t total_forks;           /* number of forks so far */
10865 +
10866 +       struct _vx_syslog syslog;
10867 +};
10868 +
10869 +struct _vx_cvirt_pc {
10870 +       struct _vx_usage_stat cpustat;
10871 +};
10872 +
10873 +
10874 +#ifdef CONFIG_VSERVER_DEBUG
10875 +
10876 +static inline void __dump_vx_cvirt(struct _vx_cvirt *cvirt)
10877 +{
10878 +       printk("\t_vx_cvirt:\n");
10879 +       printk("\t threads: %4d, %4d, %4d, %4d\n",
10880 +               atomic_read(&cvirt->nr_threads),
10881 +               atomic_read(&cvirt->nr_running),
10882 +               atomic_read(&cvirt->nr_uninterruptible),
10883 +               atomic_read(&cvirt->nr_onhold));
10884 +       /* add rest here */
10885 +       printk("\t total_forks = %d\n", atomic_read(&cvirt->total_forks));
10886 +}
10887 +
10888 +#endif
10889 +
10890 +#endif /* _VSERVER_CVIRT_DEF_H */
10891 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/debug.h linux-3.9.4-vs2.3.6.2/include/linux/vserver/debug.h
10892 --- linux-3.9.4/include/linux/vserver/debug.h   1970-01-01 00:00:00.000000000 +0000
10893 +++ linux-3.9.4-vs2.3.6.2/include/linux/vserver/debug.h 2013-05-31 14:47:11.000000000 +0000
10894 @@ -0,0 +1,145 @@
10895 +#ifndef _VSERVER_DEBUG_H
10896 +#define _VSERVER_DEBUG_H
10897 +
10898 +
10899 +#define VXD_CBIT(n, m) (vs_debug_ ## n & (1 << (m)))
10900 +#define VXD_CMIN(n, m) (vs_debug_ ## n > (m))
10901 +#define VXD_MASK(n, m) (vs_debug_ ## n & (m))
10902 +
10903 +#define VXD_DEV(d)     (d), (d)->bd_inode->i_ino,              \
10904 +                       imajor((d)->bd_inode), iminor((d)->bd_inode)
10905 +#define VXF_DEV                "%p[%lu,%d:%d]"
10906 +
10907 +#if    defined(CONFIG_QUOTES_UTF8)
10908 +#define        VS_Q_LQM        "\xc2\xbb"
10909 +#define        VS_Q_RQM        "\xc2\xab"
10910 +#elif  defined(CONFIG_QUOTES_ASCII)
10911 +#define        VS_Q_LQM        "\x27"
10912 +#define        VS_Q_RQM        "\x27"
10913 +#else
10914 +#define        VS_Q_LQM        "\xbb"
10915 +#define        VS_Q_RQM        "\xab"
10916 +#endif
10917 +
10918 +#define        VS_Q(f)         VS_Q_LQM f VS_Q_RQM
10919 +
10920 +
10921 +#define vxd_path(p)                                            \
10922 +       ({ static char _buffer[PATH_MAX];                       \
10923 +          d_path(p, _buffer, sizeof(_buffer)); })
10924 +
10925 +#define vxd_cond_path(n)                                       \
10926 +       ((n) ? vxd_path(&(n)->path) : "<null>" )
10927 +
10928 +
10929 +#ifdef CONFIG_VSERVER_DEBUG
10930 +
10931 +extern unsigned int vs_debug_switch;
10932 +extern unsigned int vs_debug_xid;
10933 +extern unsigned int vs_debug_nid;
10934 +extern unsigned int vs_debug_tag;
10935 +extern unsigned int vs_debug_net;
10936 +extern unsigned int vs_debug_limit;
10937 +extern unsigned int vs_debug_cres;
10938 +extern unsigned int vs_debug_dlim;
10939 +extern unsigned int vs_debug_quota;
10940 +extern unsigned int vs_debug_cvirt;
10941 +extern unsigned int vs_debug_space;
10942 +extern unsigned int vs_debug_perm;
10943 +extern unsigned int vs_debug_misc;
10944 +
10945 +
10946 +#define VX_LOGLEVEL    "vxD: "
10947 +#define VX_PROC_FMT    "%p: "
10948 +#define VX_PROCESS     current
10949 +
10950 +#define vxdprintk(c, f, x...)                                  \
10951 +       do {                                                    \
10952 +               if (c)                                          \
10953 +                       printk(VX_LOGLEVEL VX_PROC_FMT f "\n",  \
10954 +                               VX_PROCESS , ##x);              \
10955 +       } while (0)
10956 +
10957 +#define vxlprintk(c, f, x...)                                  \
10958 +       do {                                                    \
10959 +               if (c)                                          \
10960 +                       printk(VX_LOGLEVEL f " @%s:%d\n", x);   \
10961 +       } while (0)
10962 +
10963 +#define vxfprintk(c, f, x...)                                  \
10964 +       do {                                                    \
10965 +               if (c)                                          \
10966 +                       printk(VX_LOGLEVEL f " %s@%s:%d\n", x); \
10967 +       } while (0)
10968 +
10969 +
10970 +struct vx_info;
10971 +
10972 +void dump_vx_info(struct vx_info *, int);
10973 +void dump_vx_info_inactive(int);
10974 +
10975 +#else  /* CONFIG_VSERVER_DEBUG */
10976 +
10977 +#define vs_debug_switch        0
10978 +#define vs_debug_xid   0
10979 +#define vs_debug_nid   0
10980 +#define vs_debug_tag   0
10981 +#define vs_debug_net   0
10982 +#define vs_debug_limit 0
10983 +#define vs_debug_cres  0
10984 +#define vs_debug_dlim  0
10985 +#define vs_debug_quota 0
10986 +#define vs_debug_cvirt 0
10987 +#define vs_debug_space 0
10988 +#define vs_debug_perm  0
10989 +#define vs_debug_misc  0
10990 +
10991 +#define vxdprintk(x...) do { } while (0)
10992 +#define vxlprintk(x...) do { } while (0)
10993 +#define vxfprintk(x...) do { } while (0)
10994 +
10995 +#endif /* CONFIG_VSERVER_DEBUG */
10996 +
10997 +
10998 +#ifdef CONFIG_VSERVER_WARN
10999 +
11000 +#define VX_WARNLEVEL   KERN_WARNING "vxW: "
11001 +#define VX_WARN_TASK   "[" VS_Q("%s") ",%u:#%u|%u|%u] "
11002 +#define VX_WARN_XID    "[xid #%u] "
11003 +#define VX_WARN_NID    "[nid #%u] "
11004 +#define VX_WARN_TAG    "[tag #%u] "
11005 +
11006 +#define vxwprintk(c, f, x...)                                  \
11007 +       do {                                                    \
11008 +               if (c)                                          \
11009 +                       printk(VX_WARNLEVEL f "\n", ##x);       \
11010 +       } while (0)
11011 +
11012 +#else  /* CONFIG_VSERVER_WARN */
11013 +
11014 +#define vxwprintk(x...) do { } while (0)
11015 +
11016 +#endif /* CONFIG_VSERVER_WARN */
11017 +
11018 +#define vxwprintk_task(c, f, x...)                             \
11019 +       vxwprintk(c, VX_WARN_TASK f,                            \
11020 +               current->comm, current->pid,                    \
11021 +               current->xid, current->nid, current->tag, ##x)
11022 +#define vxwprintk_xid(c, f, x...)                              \
11023 +       vxwprintk(c, VX_WARN_XID f, current->xid, x)
11024 +#define vxwprintk_nid(c, f, x...)                              \
11025 +       vxwprintk(c, VX_WARN_NID f, current->nid, x)
11026 +#define vxwprintk_tag(c, f, x...)                              \
11027 +       vxwprintk(c, VX_WARN_TAG f, current->tag, x)
11028 +
11029 +#ifdef CONFIG_VSERVER_DEBUG
11030 +#define vxd_assert_lock(l)     assert_spin_locked(l)
11031 +#define vxd_assert(c, f, x...) vxlprintk(!(c), \
11032 +       "assertion [" f "] failed.", ##x, __FILE__, __LINE__)
11033 +#else
11034 +#define vxd_assert_lock(l)     do { } while (0)
11035 +#define vxd_assert(c, f, x...) do { } while (0)
11036 +#endif
11037 +
11038 +
11039 +#endif /* _VSERVER_DEBUG_H */
11040 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/debug_cmd.h linux-3.9.4-vs2.3.6.2/include/linux/vserver/debug_cmd.h
11041 --- linux-3.9.4/include/linux/vserver/debug_cmd.h       1970-01-01 00:00:00.000000000 +0000
11042 +++ linux-3.9.4-vs2.3.6.2/include/linux/vserver/debug_cmd.h     2013-05-31 14:47:11.000000000 +0000
11043 @@ -0,0 +1,37 @@
11044 +#ifndef _VSERVER_DEBUG_CMD_H
11045 +#define _VSERVER_DEBUG_CMD_H
11046 +
11047 +#include <uapi/vserver/debug_cmd.h>
11048 +
11049 +
11050 +#ifdef CONFIG_COMPAT
11051 +
11052 +#include <asm/compat.h>
11053 +
11054 +struct vcmd_read_history_v0_x32 {
11055 +       uint32_t index;
11056 +       uint32_t count;
11057 +       compat_uptr_t data_ptr;
11058 +};
11059 +
11060 +struct vcmd_read_monitor_v0_x32 {
11061 +       uint32_t index;
11062 +       uint32_t count;
11063 +       compat_uptr_t data_ptr;
11064 +};
11065 +
11066 +#endif  /* CONFIG_COMPAT */
11067 +
11068 +extern int vc_dump_history(uint32_t);
11069 +
11070 +extern int vc_read_history(uint32_t, void __user *);
11071 +extern int vc_read_monitor(uint32_t, void __user *);
11072 +
11073 +#ifdef CONFIG_COMPAT
11074 +
11075 +extern int vc_read_history_x32(uint32_t, void __user *);
11076 +extern int vc_read_monitor_x32(uint32_t, void __user *);
11077 +
11078 +#endif  /* CONFIG_COMPAT */
11079 +
11080 +#endif /* _VSERVER_DEBUG_CMD_H */
11081 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/device.h linux-3.9.4-vs2.3.6.2/include/linux/vserver/device.h
11082 --- linux-3.9.4/include/linux/vserver/device.h  1970-01-01 00:00:00.000000000 +0000
11083 +++ linux-3.9.4-vs2.3.6.2/include/linux/vserver/device.h        2013-05-31 14:47:11.000000000 +0000
11084 @@ -0,0 +1,9 @@
11085 +#ifndef _VSERVER_DEVICE_H
11086 +#define _VSERVER_DEVICE_H
11087 +
11088 +
11089 +#include <uapi/vserver/device.h>
11090 +
11091 +#else  /* _VSERVER_DEVICE_H */
11092 +#warning duplicate inclusion
11093 +#endif /* _VSERVER_DEVICE_H */
11094 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/device_cmd.h linux-3.9.4-vs2.3.6.2/include/linux/vserver/device_cmd.h
11095 --- linux-3.9.4/include/linux/vserver/device_cmd.h      1970-01-01 00:00:00.000000000 +0000
11096 +++ linux-3.9.4-vs2.3.6.2/include/linux/vserver/device_cmd.h    2013-05-31 14:47:11.000000000 +0000
11097 @@ -0,0 +1,31 @@
11098 +#ifndef _VSERVER_DEVICE_CMD_H
11099 +#define _VSERVER_DEVICE_CMD_H
11100 +
11101 +#include <uapi/vserver/device_cmd.h>
11102 +
11103 +
11104 +#ifdef CONFIG_COMPAT
11105 +
11106 +#include <asm/compat.h>
11107 +
11108 +struct vcmd_set_mapping_v0_x32 {
11109 +       compat_uptr_t device_ptr;
11110 +       compat_uptr_t target_ptr;
11111 +       uint32_t flags;
11112 +};
11113 +
11114 +#endif /* CONFIG_COMPAT */
11115 +
11116 +#include <linux/compiler.h>
11117 +
11118 +extern int vc_set_mapping(struct vx_info *, void __user *);
11119 +extern int vc_unset_mapping(struct vx_info *, void __user *);
11120 +
11121 +#ifdef CONFIG_COMPAT
11122 +
11123 +extern int vc_set_mapping_x32(struct vx_info *, void __user *);
11124 +extern int vc_unset_mapping_x32(struct vx_info *, void __user *);
11125 +
11126 +#endif /* CONFIG_COMPAT */
11127 +
11128 +#endif /* _VSERVER_DEVICE_CMD_H */
11129 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/device_def.h linux-3.9.4-vs2.3.6.2/include/linux/vserver/device_def.h
11130 --- linux-3.9.4/include/linux/vserver/device_def.h      1970-01-01 00:00:00.000000000 +0000
11131 +++ linux-3.9.4-vs2.3.6.2/include/linux/vserver/device_def.h    2013-05-31 14:47:11.000000000 +0000
11132 @@ -0,0 +1,17 @@
11133 +#ifndef _VSERVER_DEVICE_DEF_H
11134 +#define _VSERVER_DEVICE_DEF_H
11135 +
11136 +#include <linux/types.h>
11137 +
11138 +struct vx_dmap_target {
11139 +       dev_t target;
11140 +       uint32_t flags;
11141 +};
11142 +
11143 +struct _vx_device {
11144 +#ifdef CONFIG_VSERVER_DEVICE
11145 +       struct vx_dmap_target targets[2];
11146 +#endif
11147 +};
11148 +
11149 +#endif /* _VSERVER_DEVICE_DEF_H */
11150 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/dlimit.h linux-3.9.4-vs2.3.6.2/include/linux/vserver/dlimit.h
11151 --- linux-3.9.4/include/linux/vserver/dlimit.h  1970-01-01 00:00:00.000000000 +0000
11152 +++ linux-3.9.4-vs2.3.6.2/include/linux/vserver/dlimit.h        2013-05-31 14:47:11.000000000 +0000
11153 @@ -0,0 +1,54 @@
11154 +#ifndef _VSERVER_DLIMIT_H
11155 +#define _VSERVER_DLIMIT_H
11156 +
11157 +#include "switch.h"
11158 +
11159 +
11160 +#ifdef __KERNEL__
11161 +
11162 +/*      keep in sync with CDLIM_INFINITY       */
11163 +
11164 +#define DLIM_INFINITY          (~0ULL)
11165 +
11166 +#include <linux/spinlock.h>
11167 +#include <linux/rcupdate.h>
11168 +
11169 +struct super_block;
11170 +
11171 +struct dl_info {
11172 +       struct hlist_node dl_hlist;             /* linked list of contexts */
11173 +       struct rcu_head dl_rcu;                 /* the rcu head */
11174 +       tag_t dl_tag;                           /* context tag */
11175 +       atomic_t dl_usecnt;                     /* usage count */
11176 +       atomic_t dl_refcnt;                     /* reference count */
11177 +
11178 +       struct super_block *dl_sb;              /* associated superblock */
11179 +
11180 +       spinlock_t dl_lock;                     /* protect the values */
11181 +
11182 +       unsigned long long dl_space_used;       /* used space in bytes */
11183 +       unsigned long long dl_space_total;      /* maximum space in bytes */
11184 +       unsigned long dl_inodes_used;           /* used inodes */
11185 +       unsigned long dl_inodes_total;          /* maximum inodes */
11186 +
11187 +       unsigned int dl_nrlmult;                /* non root limit mult */
11188 +};
11189 +
11190 +struct rcu_head;
11191 +
11192 +extern void rcu_free_dl_info(struct rcu_head *);
11193 +extern void unhash_dl_info(struct dl_info *);
11194 +
11195 +extern struct dl_info *locate_dl_info(struct super_block *, tag_t);
11196 +
11197 +
11198 +struct kstatfs;
11199 +
11200 +extern void vx_vsi_statfs(struct super_block *, struct kstatfs *);
11201 +
11202 +typedef uint64_t dlsize_t;
11203 +
11204 +#endif /* __KERNEL__ */
11205 +#else  /* _VSERVER_DLIMIT_H */
11206 +#warning duplicate inclusion
11207 +#endif /* _VSERVER_DLIMIT_H */
11208 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/dlimit_cmd.h linux-3.9.4-vs2.3.6.2/include/linux/vserver/dlimit_cmd.h
11209 --- linux-3.9.4/include/linux/vserver/dlimit_cmd.h      1970-01-01 00:00:00.000000000 +0000
11210 +++ linux-3.9.4-vs2.3.6.2/include/linux/vserver/dlimit_cmd.h    2013-05-31 14:47:11.000000000 +0000
11211 @@ -0,0 +1,46 @@
11212 +#ifndef _VSERVER_DLIMIT_CMD_H
11213 +#define _VSERVER_DLIMIT_CMD_H
11214 +
11215 +#include <uapi/vserver/dlimit_cmd.h>
11216 +
11217 +
11218 +#ifdef CONFIG_COMPAT
11219 +
11220 +#include <asm/compat.h>
11221 +
11222 +struct vcmd_ctx_dlimit_base_v0_x32 {
11223 +       compat_uptr_t name_ptr;
11224 +       uint32_t flags;
11225 +};
11226 +
11227 +struct vcmd_ctx_dlimit_v0_x32 {
11228 +       compat_uptr_t name_ptr;
11229 +       uint32_t space_used;                    /* used space in kbytes */
11230 +       uint32_t space_total;                   /* maximum space in kbytes */
11231 +       uint32_t inodes_used;                   /* used inodes */
11232 +       uint32_t inodes_total;                  /* maximum inodes */
11233 +       uint32_t reserved;                      /* reserved for root in % */
11234 +       uint32_t flags;
11235 +};
11236 +
11237 +#endif /* CONFIG_COMPAT */
11238 +
11239 +#include <linux/compiler.h>
11240 +
11241 +extern int vc_add_dlimit(uint32_t, void __user *);
11242 +extern int vc_rem_dlimit(uint32_t, void __user *);
11243 +
11244 +extern int vc_set_dlimit(uint32_t, void __user *);
11245 +extern int vc_get_dlimit(uint32_t, void __user *);
11246 +
11247 +#ifdef CONFIG_COMPAT
11248 +
11249 +extern int vc_add_dlimit_x32(uint32_t, void __user *);
11250 +extern int vc_rem_dlimit_x32(uint32_t, void __user *);
11251 +
11252 +extern int vc_set_dlimit_x32(uint32_t, void __user *);
11253 +extern int vc_get_dlimit_x32(uint32_t, void __user *);
11254 +
11255 +#endif /* CONFIG_COMPAT */
11256 +
11257 +#endif /* _VSERVER_DLIMIT_CMD_H */
11258 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/global.h linux-3.9.4-vs2.3.6.2/include/linux/vserver/global.h
11259 --- linux-3.9.4/include/linux/vserver/global.h  1970-01-01 00:00:00.000000000 +0000
11260 +++ linux-3.9.4-vs2.3.6.2/include/linux/vserver/global.h        2013-05-31 14:47:11.000000000 +0000
11261 @@ -0,0 +1,19 @@
11262 +#ifndef _VSERVER_GLOBAL_H
11263 +#define _VSERVER_GLOBAL_H
11264 +
11265 +
11266 +extern atomic_t vx_global_ctotal;
11267 +extern atomic_t vx_global_cactive;
11268 +
11269 +extern atomic_t nx_global_ctotal;
11270 +extern atomic_t nx_global_cactive;
11271 +
11272 +extern atomic_t vs_global_nsproxy;
11273 +extern atomic_t vs_global_fs;
11274 +extern atomic_t vs_global_mnt_ns;
11275 +extern atomic_t vs_global_uts_ns;
11276 +extern atomic_t vs_global_user_ns;
11277 +extern atomic_t vs_global_pid_ns;
11278 +
11279 +
11280 +#endif /* _VSERVER_GLOBAL_H */
11281 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/history.h linux-3.9.4-vs2.3.6.2/include/linux/vserver/history.h
11282 --- linux-3.9.4/include/linux/vserver/history.h 1970-01-01 00:00:00.000000000 +0000
11283 +++ linux-3.9.4-vs2.3.6.2/include/linux/vserver/history.h       2013-05-31 14:47:11.000000000 +0000
11284 @@ -0,0 +1,197 @@
11285 +#ifndef _VSERVER_HISTORY_H
11286 +#define _VSERVER_HISTORY_H
11287 +
11288 +
11289 +enum {
11290 +       VXH_UNUSED = 0,
11291 +       VXH_THROW_OOPS = 1,
11292 +
11293 +       VXH_GET_VX_INFO,
11294 +       VXH_PUT_VX_INFO,
11295 +       VXH_INIT_VX_INFO,
11296 +       VXH_SET_VX_INFO,
11297 +       VXH_CLR_VX_INFO,
11298 +       VXH_CLAIM_VX_INFO,
11299 +       VXH_RELEASE_VX_INFO,
11300 +       VXH_ALLOC_VX_INFO,
11301 +       VXH_DEALLOC_VX_INFO,
11302 +       VXH_HASH_VX_INFO,
11303 +       VXH_UNHASH_VX_INFO,
11304 +       VXH_LOC_VX_INFO,
11305 +       VXH_LOOKUP_VX_INFO,
11306 +       VXH_CREATE_VX_INFO,
11307 +};
11308 +
11309 +struct _vxhe_vxi {
11310 +       struct vx_info *ptr;
11311 +       unsigned xid;
11312 +       unsigned usecnt;
11313 +       unsigned tasks;
11314 +};
11315 +
11316 +struct _vxhe_set_clr {
11317 +       void *data;
11318 +};
11319 +
11320 +struct _vxhe_loc_lookup {
11321 +       unsigned arg;
11322 +};
11323 +
11324 +struct _vx_hist_entry {
11325 +       void *loc;
11326 +       unsigned short seq;
11327 +       unsigned short type;
11328 +       struct _vxhe_vxi vxi;
11329 +       union {
11330 +               struct _vxhe_set_clr sc;
11331 +               struct _vxhe_loc_lookup ll;
11332 +       };
11333 +};
11334 +
11335 +#ifdef CONFIG_VSERVER_HISTORY
11336 +
11337 +extern unsigned volatile int vxh_active;
11338 +
11339 +struct _vx_hist_entry *vxh_advance(void *loc);
11340 +
11341 +
11342 +static inline
11343 +void   __vxh_copy_vxi(struct _vx_hist_entry *entry, struct vx_info *vxi)
11344 +{
11345 +       entry->vxi.ptr = vxi;
11346 +       if (vxi) {
11347 +               entry->vxi.usecnt = atomic_read(&vxi->vx_usecnt);
11348 +               entry->vxi.tasks = atomic_read(&vxi->vx_tasks);
11349 +               entry->vxi.xid = vxi->vx_id;
11350 +       }
11351 +}
11352 +
11353 +
11354 +#define        __HERE__ current_text_addr()
11355 +
11356 +#define __VXH_BODY(__type, __data, __here)     \
11357 +       struct _vx_hist_entry *entry;           \
11358 +                                               \
11359 +       preempt_disable();                      \
11360 +       entry = vxh_advance(__here);            \
11361 +       __data;                                 \
11362 +       entry->type = __type;                   \
11363 +       preempt_enable();
11364 +
11365 +
11366 +       /* pass vxi only */
11367 +
11368 +#define __VXH_SMPL                             \
11369 +       __vxh_copy_vxi(entry, vxi)
11370 +
11371 +static inline
11372 +void   __vxh_smpl(struct vx_info *vxi, int __type, void *__here)
11373 +{
11374 +       __VXH_BODY(__type, __VXH_SMPL, __here)
11375 +}
11376 +
11377 +       /* pass vxi and data (void *) */
11378 +
11379 +#define __VXH_DATA                             \
11380 +       __vxh_copy_vxi(entry, vxi);             \
11381 +       entry->sc.data = data
11382 +
11383 +static inline
11384 +void   __vxh_data(struct vx_info *vxi, void *data,
11385 +                       int __type, void *__here)
11386 +{
11387 +       __VXH_BODY(__type, __VXH_DATA, __here)
11388 +}
11389 +
11390 +       /* pass vxi and arg (long) */
11391 +
11392 +#define __VXH_LONG                             \
11393 +       __vxh_copy_vxi(entry, vxi);             \
11394 +       entry->ll.arg = arg
11395 +
11396 +static inline
11397 +void   __vxh_long(struct vx_info *vxi, long arg,
11398 +                       int __type, void *__here)
11399 +{
11400 +       __VXH_BODY(__type, __VXH_LONG, __here)
11401 +}
11402 +
11403 +
11404 +static inline
11405 +void   __vxh_throw_oops(void *__here)
11406 +{
11407 +       __VXH_BODY(VXH_THROW_OOPS, {}, __here);
11408 +       /* prevent further acquisition */
11409 +       vxh_active = 0;
11410 +}
11411 +
11412 +
11413 +#define vxh_throw_oops()       __vxh_throw_oops(__HERE__);
11414 +
11415 +#define __vxh_get_vx_info(v, h)        __vxh_smpl(v, VXH_GET_VX_INFO, h);
11416 +#define __vxh_put_vx_info(v, h)        __vxh_smpl(v, VXH_PUT_VX_INFO, h);
11417 +
11418 +#define __vxh_init_vx_info(v, d, h) \
11419 +       __vxh_data(v, d, VXH_INIT_VX_INFO, h);
11420 +#define __vxh_set_vx_info(v, d, h) \
11421 +       __vxh_data(v, d, VXH_SET_VX_INFO, h);
11422 +#define __vxh_clr_vx_info(v, d, h) \
11423 +       __vxh_data(v, d, VXH_CLR_VX_INFO, h);
11424 +
11425 +#define __vxh_claim_vx_info(v, d, h) \
11426 +       __vxh_data(v, d, VXH_CLAIM_VX_INFO, h);
11427 +#define __vxh_release_vx_info(v, d, h) \
11428 +       __vxh_data(v, d, VXH_RELEASE_VX_INFO, h);
11429 +
11430 +#define vxh_alloc_vx_info(v) \
11431 +       __vxh_smpl(v, VXH_ALLOC_VX_INFO, __HERE__);
11432 +#define vxh_dealloc_vx_info(v) \
11433 +       __vxh_smpl(v, VXH_DEALLOC_VX_INFO, __HERE__);
11434 +
11435 +#define vxh_hash_vx_info(v) \
11436 +       __vxh_smpl(v, VXH_HASH_VX_INFO, __HERE__);
11437 +#define vxh_unhash_vx_info(v) \
11438 +       __vxh_smpl(v, VXH_UNHASH_VX_INFO, __HERE__);
11439 +
11440 +#define vxh_loc_vx_info(v, l) \
11441 +       __vxh_long(v, l, VXH_LOC_VX_INFO, __HERE__);
11442 +#define vxh_lookup_vx_info(v, l) \
11443 +       __vxh_long(v, l, VXH_LOOKUP_VX_INFO, __HERE__);
11444 +#define vxh_create_vx_info(v, l) \
11445 +       __vxh_long(v, l, VXH_CREATE_VX_INFO, __HERE__);
11446 +
11447 +extern void vxh_dump_history(void);
11448 +
11449 +
11450 +#else  /* CONFIG_VSERVER_HISTORY */
11451 +
11452 +#define        __HERE__        0
11453 +
11454 +#define vxh_throw_oops()               do { } while (0)
11455 +
11456 +#define __vxh_get_vx_info(v, h)                do { } while (0)
11457 +#define __vxh_put_vx_info(v, h)                do { } while (0)
11458 +
11459 +#define __vxh_init_vx_info(v, d, h)    do { } while (0)
11460 +#define __vxh_set_vx_info(v, d, h)     do { } while (0)
11461 +#define __vxh_clr_vx_info(v, d, h)     do { } while (0)
11462 +
11463 +#define __vxh_claim_vx_info(v, d, h)   do { } while (0)
11464 +#define __vxh_release_vx_info(v, d, h) do { } while (0)
11465 +
11466 +#define vxh_alloc_vx_info(v)           do { } while (0)
11467 +#define vxh_dealloc_vx_info(v)         do { } while (0)
11468 +
11469 +#define vxh_hash_vx_info(v)            do { } while (0)
11470 +#define vxh_unhash_vx_info(v)          do { } while (0)
11471 +
11472 +#define vxh_loc_vx_info(v, l)          do { } while (0)
11473 +#define vxh_lookup_vx_info(v, l)       do { } while (0)
11474 +#define vxh_create_vx_info(v, l)       do { } while (0)
11475 +
11476 +#define vxh_dump_history()             do { } while (0)
11477 +
11478 +
11479 +#endif /* CONFIG_VSERVER_HISTORY */
11480 +
11481 +#endif /* _VSERVER_HISTORY_H */
11482 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/inode.h linux-3.9.4-vs2.3.6.2/include/linux/vserver/inode.h
11483 --- linux-3.9.4/include/linux/vserver/inode.h   1970-01-01 00:00:00.000000000 +0000
11484 +++ linux-3.9.4-vs2.3.6.2/include/linux/vserver/inode.h 2013-05-31 14:47:11.000000000 +0000
11485 @@ -0,0 +1,19 @@
11486 +#ifndef _VSERVER_INODE_H
11487 +#define _VSERVER_INODE_H
11488 +
11489 +#include <uapi/vserver/inode.h>
11490 +
11491 +
11492 +#ifdef CONFIG_VSERVER_PROC_SECURE
11493 +#define IATTR_PROC_DEFAULT     ( IATTR_ADMIN | IATTR_HIDE )
11494 +#define IATTR_PROC_SYMLINK     ( IATTR_ADMIN )
11495 +#else
11496 +#define IATTR_PROC_DEFAULT     ( IATTR_ADMIN )
11497 +#define IATTR_PROC_SYMLINK     ( IATTR_ADMIN )
11498 +#endif
11499 +
11500 +#define vx_hide_check(c, m)    (((m) & IATTR_HIDE) ? vx_check(c, m) : 1)
11501 +
11502 +#else  /* _VSERVER_INODE_H */
11503 +#warning duplicate inclusion
11504 +#endif /* _VSERVER_INODE_H */
11505 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/inode_cmd.h linux-3.9.4-vs2.3.6.2/include/linux/vserver/inode_cmd.h
11506 --- linux-3.9.4/include/linux/vserver/inode_cmd.h       1970-01-01 00:00:00.000000000 +0000
11507 +++ linux-3.9.4-vs2.3.6.2/include/linux/vserver/inode_cmd.h     2013-05-31 14:47:11.000000000 +0000
11508 @@ -0,0 +1,36 @@
11509 +#ifndef _VSERVER_INODE_CMD_H
11510 +#define _VSERVER_INODE_CMD_H
11511 +
11512 +#include <uapi/vserver/inode_cmd.h>
11513 +
11514 +
11515 +
11516 +#ifdef CONFIG_COMPAT
11517 +
11518 +#include <asm/compat.h>
11519 +
11520 +struct vcmd_ctx_iattr_v1_x32 {
11521 +       compat_uptr_t name_ptr;
11522 +       uint32_t tag;
11523 +       uint32_t flags;
11524 +       uint32_t mask;
11525 +};
11526 +
11527 +#endif /* CONFIG_COMPAT */
11528 +
11529 +#include <linux/compiler.h>
11530 +
11531 +extern int vc_get_iattr(void __user *);
11532 +extern int vc_set_iattr(void __user *);
11533 +
11534 +extern int vc_fget_iattr(uint32_t, void __user *);
11535 +extern int vc_fset_iattr(uint32_t, void __user *);
11536 +
11537 +#ifdef CONFIG_COMPAT
11538 +
11539 +extern int vc_get_iattr_x32(void __user *);
11540 +extern int vc_set_iattr_x32(void __user *);
11541 +
11542 +#endif /* CONFIG_COMPAT */
11543 +
11544 +#endif /* _VSERVER_INODE_CMD_H */
11545 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/limit.h linux-3.9.4-vs2.3.6.2/include/linux/vserver/limit.h
11546 --- linux-3.9.4/include/linux/vserver/limit.h   1970-01-01 00:00:00.000000000 +0000
11547 +++ linux-3.9.4-vs2.3.6.2/include/linux/vserver/limit.h 2013-05-31 14:47:11.000000000 +0000
11548 @@ -0,0 +1,61 @@
11549 +#ifndef _VSERVER_LIMIT_H
11550 +#define _VSERVER_LIMIT_H
11551 +
11552 +#include <uapi/vserver/limit.h>
11553 +
11554 +
11555 +#define        VLIM_NOCHECK    ((1L << VLIMIT_DENTRY) | (1L << RLIMIT_RSS))
11556 +
11557 +/*     keep in sync with CRLIM_INFINITY */
11558 +
11559 +#define        VLIM_INFINITY   (~0ULL)
11560 +
11561 +#include <asm/atomic.h>
11562 +#include <asm/resource.h>
11563 +
11564 +#ifndef RLIM_INFINITY
11565 +#warning RLIM_INFINITY is undefined
11566 +#endif
11567 +
11568 +#define __rlim_val(l, r, v)    ((l)->res[r].v)
11569 +
11570 +#define __rlim_soft(l, r)      __rlim_val(l, r, soft)
11571 +#define __rlim_hard(l, r)      __rlim_val(l, r, hard)
11572 +
11573 +#define __rlim_rcur(l, r)      __rlim_val(l, r, rcur)
11574 +#define __rlim_rmin(l, r)      __rlim_val(l, r, rmin)
11575 +#define __rlim_rmax(l, r)      __rlim_val(l, r, rmax)
11576 +
11577 +#define __rlim_lhit(l, r)      __rlim_val(l, r, lhit)
11578 +#define __rlim_hit(l, r)       atomic_inc(&__rlim_lhit(l, r))
11579 +
11580 +typedef atomic_long_t rlim_atomic_t;
11581 +typedef unsigned long rlim_t;
11582 +
11583 +#define __rlim_get(l, r)       atomic_long_read(&__rlim_rcur(l, r))
11584 +#define __rlim_set(l, r, v)    atomic_long_set(&__rlim_rcur(l, r), v)
11585 +#define __rlim_inc(l, r)       atomic_long_inc(&__rlim_rcur(l, r))
11586 +#define __rlim_dec(l, r)       atomic_long_dec(&__rlim_rcur(l, r))
11587 +#define __rlim_add(l, r, v)    atomic_long_add(v, &__rlim_rcur(l, r))
11588 +#define __rlim_sub(l, r, v)    atomic_long_sub(v, &__rlim_rcur(l, r))
11589 +
11590 +
11591 +#if    (RLIM_INFINITY == VLIM_INFINITY)
11592 +#define        VX_VLIM(r) ((long long)(long)(r))
11593 +#define        VX_RLIM(v) ((rlim_t)(v))
11594 +#else
11595 +#define        VX_VLIM(r) (((r) == RLIM_INFINITY) \
11596 +               ? VLIM_INFINITY : (long long)(r))
11597 +#define        VX_RLIM(v) (((v) == VLIM_INFINITY) \
11598 +               ? RLIM_INFINITY : (rlim_t)(v))
11599 +#endif
11600 +
11601 +struct sysinfo;
11602 +
11603 +void vx_vsi_meminfo(struct sysinfo *);
11604 +void vx_vsi_swapinfo(struct sysinfo *);
11605 +long vx_vsi_cached(struct sysinfo *);
11606 +
11607 +#define NUM_LIMITS     24
11608 +
11609 +#endif /* _VSERVER_LIMIT_H */
11610 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/limit_cmd.h linux-3.9.4-vs2.3.6.2/include/linux/vserver/limit_cmd.h
11611 --- linux-3.9.4/include/linux/vserver/limit_cmd.h       1970-01-01 00:00:00.000000000 +0000
11612 +++ linux-3.9.4-vs2.3.6.2/include/linux/vserver/limit_cmd.h     2013-05-31 14:47:11.000000000 +0000
11613 @@ -0,0 +1,35 @@
11614 +#ifndef _VSERVER_LIMIT_CMD_H
11615 +#define _VSERVER_LIMIT_CMD_H
11616 +
11617 +#include <uapi/vserver/limit_cmd.h>
11618 +
11619 +
11620 +#ifdef CONFIG_IA32_EMULATION
11621 +
11622 +struct vcmd_ctx_rlimit_v0_x32 {
11623 +       uint32_t id;
11624 +       uint64_t minimum;
11625 +       uint64_t softlimit;
11626 +       uint64_t maximum;
11627 +} __attribute__ ((packed));
11628 +
11629 +#endif /* CONFIG_IA32_EMULATION */
11630 +
11631 +#include <linux/compiler.h>
11632 +
11633 +extern int vc_get_rlimit_mask(uint32_t, void __user *);
11634 +extern int vc_get_rlimit(struct vx_info *, void __user *);
11635 +extern int vc_set_rlimit(struct vx_info *, void __user *);
11636 +extern int vc_reset_hits(struct vx_info *, void __user *);
11637 +extern int vc_reset_minmax(struct vx_info *, void __user *);
11638 +
11639 +extern int vc_rlimit_stat(struct vx_info *, void __user *);
11640 +
11641 +#ifdef CONFIG_IA32_EMULATION
11642 +
11643 +extern int vc_get_rlimit_x32(struct vx_info *, void __user *);
11644 +extern int vc_set_rlimit_x32(struct vx_info *, void __user *);
11645 +
11646 +#endif /* CONFIG_IA32_EMULATION */
11647 +
11648 +#endif /* _VSERVER_LIMIT_CMD_H */
11649 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/limit_def.h linux-3.9.4-vs2.3.6.2/include/linux/vserver/limit_def.h
11650 --- linux-3.9.4/include/linux/vserver/limit_def.h       1970-01-01 00:00:00.000000000 +0000
11651 +++ linux-3.9.4-vs2.3.6.2/include/linux/vserver/limit_def.h     2013-05-31 14:47:11.000000000 +0000
11652 @@ -0,0 +1,47 @@
11653 +#ifndef _VSERVER_LIMIT_DEF_H
11654 +#define _VSERVER_LIMIT_DEF_H
11655 +
11656 +#include <asm/atomic.h>
11657 +#include <asm/resource.h>
11658 +
11659 +#include "limit.h"
11660 +
11661 +
11662 +struct _vx_res_limit {
11663 +       rlim_t soft;            /* Context soft limit */
11664 +       rlim_t hard;            /* Context hard limit */
11665 +
11666 +       rlim_atomic_t rcur;     /* Current value */
11667 +       rlim_t rmin;            /* Context minimum */
11668 +       rlim_t rmax;            /* Context maximum */
11669 +
11670 +       atomic_t lhit;          /* Limit hits */
11671 +};
11672 +
11673 +/* context sub struct */
11674 +
11675 +struct _vx_limit {
11676 +       struct _vx_res_limit res[NUM_LIMITS];
11677 +};
11678 +
11679 +#ifdef CONFIG_VSERVER_DEBUG
11680 +
11681 +static inline void __dump_vx_limit(struct _vx_limit *limit)
11682 +{
11683 +       int i;
11684 +
11685 +       printk("\t_vx_limit:");
11686 +       for (i = 0; i < NUM_LIMITS; i++) {
11687 +               printk("\t [%2d] = %8lu %8lu/%8lu, %8ld/%8ld, %8d\n",
11688 +                       i, (unsigned long)__rlim_get(limit, i),
11689 +                       (unsigned long)__rlim_rmin(limit, i),
11690 +                       (unsigned long)__rlim_rmax(limit, i),
11691 +                       (long)__rlim_soft(limit, i),
11692 +                       (long)__rlim_hard(limit, i),
11693 +                       atomic_read(&__rlim_lhit(limit, i)));
11694 +       }
11695 +}
11696 +
11697 +#endif
11698 +
11699 +#endif /* _VSERVER_LIMIT_DEF_H */
11700 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/limit_int.h linux-3.9.4-vs2.3.6.2/include/linux/vserver/limit_int.h
11701 --- linux-3.9.4/include/linux/vserver/limit_int.h       1970-01-01 00:00:00.000000000 +0000
11702 +++ linux-3.9.4-vs2.3.6.2/include/linux/vserver/limit_int.h     2013-05-31 14:47:11.000000000 +0000
11703 @@ -0,0 +1,193 @@
11704 +#ifndef _VSERVER_LIMIT_INT_H
11705 +#define _VSERVER_LIMIT_INT_H
11706 +
11707 +#define VXD_RCRES_COND(r)      VXD_CBIT(cres, r)
11708 +#define VXD_RLIMIT_COND(r)     VXD_CBIT(limit, r)
11709 +
11710 +extern const char *vlimit_name[NUM_LIMITS];
11711 +
11712 +static inline void __vx_acc_cres(struct vx_info *vxi,
11713 +       int res, int dir, void *_data, char *_file, int _line)
11714 +{
11715 +       if (VXD_RCRES_COND(res))
11716 +               vxlprintk(1, "vx_acc_cres[%5d,%s,%2d]: %5ld%s (%p)",
11717 +                       (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
11718 +                       (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
11719 +                       (dir > 0) ? "++" : "--", _data, _file, _line);
11720 +       if (!vxi)
11721 +               return;
11722 +
11723 +       if (dir > 0)
11724 +               __rlim_inc(&vxi->limit, res);
11725 +       else
11726 +               __rlim_dec(&vxi->limit, res);
11727 +}
11728 +
11729 +static inline void __vx_add_cres(struct vx_info *vxi,
11730 +       int res, int amount, void *_data, char *_file, int _line)
11731 +{
11732 +       if (VXD_RCRES_COND(res))
11733 +               vxlprintk(1, "vx_add_cres[%5d,%s,%2d]: %5ld += %5d (%p)",
11734 +                       (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
11735 +                       (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
11736 +                       amount, _data, _file, _line);
11737 +       if (amount == 0)
11738 +               return;
11739 +       if (!vxi)
11740 +               return;
11741 +       __rlim_add(&vxi->limit, res, amount);
11742 +}
11743 +
11744 +static inline
11745 +int __vx_cres_adjust_max(struct _vx_limit *limit, int res, rlim_t value)
11746 +{
11747 +       int cond = (value > __rlim_rmax(limit, res));
11748 +
11749 +       if (cond)
11750 +               __rlim_rmax(limit, res) = value;
11751 +       return cond;
11752 +}
11753 +
11754 +static inline
11755 +int __vx_cres_adjust_min(struct _vx_limit *limit, int res, rlim_t value)
11756 +{
11757 +       int cond = (value < __rlim_rmin(limit, res));
11758 +
11759 +       if (cond)
11760 +               __rlim_rmin(limit, res) = value;
11761 +       return cond;
11762 +}
11763 +
11764 +static inline
11765 +void __vx_cres_fixup(struct _vx_limit *limit, int res, rlim_t value)
11766 +{
11767 +       if (!__vx_cres_adjust_max(limit, res, value))
11768 +               __vx_cres_adjust_min(limit, res, value);
11769 +}
11770 +
11771 +
11772 +/*     return values:
11773 +        +1 ... no limit hit
11774 +        -1 ... over soft limit
11775 +         0 ... over hard limit         */
11776 +
11777 +static inline int __vx_cres_avail(struct vx_info *vxi,
11778 +       int res, int num, char *_file, int _line)
11779 +{
11780 +       struct _vx_limit *limit;
11781 +       rlim_t value;
11782 +
11783 +       if (VXD_RLIMIT_COND(res))
11784 +               vxlprintk(1, "vx_cres_avail[%5d,%s,%2d]: %5ld/%5ld > %5ld + %5d",
11785 +                       (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
11786 +                       (vxi ? (long)__rlim_soft(&vxi->limit, res) : -1),
11787 +                       (vxi ? (long)__rlim_hard(&vxi->limit, res) : -1),
11788 +                       (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
11789 +                       num, _file, _line);
11790 +       if (!vxi)
11791 +               return 1;
11792 +
11793 +       limit = &vxi->limit;
11794 +       value = __rlim_get(limit, res);
11795 +
11796 +       if (!__vx_cres_adjust_max(limit, res, value))
11797 +               __vx_cres_adjust_min(limit, res, value);
11798 +
11799 +       if (num == 0)
11800 +               return 1;
11801 +
11802 +       if (__rlim_soft(limit, res) == RLIM_INFINITY)
11803 +               return -1;
11804 +       if (value + num <= __rlim_soft(limit, res))
11805 +               return -1;
11806 +
11807 +       if (__rlim_hard(limit, res) == RLIM_INFINITY)
11808 +               return 1;
11809 +       if (value + num <= __rlim_hard(limit, res))
11810 +               return 1;
11811 +
11812 +       __rlim_hit(limit, res);
11813 +       return 0;
11814 +}
11815 +
11816 +
11817 +static const int VLA_RSS[] = { RLIMIT_RSS, VLIMIT_ANON, VLIMIT_MAPPED, 0 };
11818 +
11819 +static inline
11820 +rlim_t __vx_cres_array_sum(struct _vx_limit *limit, const int *array)
11821 +{
11822 +       rlim_t value, sum = 0;
11823 +       int res;
11824 +
11825 +       while ((res = *array++)) {
11826 +               value = __rlim_get(limit, res);
11827 +               __vx_cres_fixup(limit, res, value);
11828 +               sum += value;
11829 +       }
11830 +       return sum;
11831 +}
11832 +
11833 +static inline
11834 +rlim_t __vx_cres_array_fixup(struct _vx_limit *limit, const int *array)
11835 +{
11836 +       rlim_t value = __vx_cres_array_sum(limit, array + 1);
11837 +       int res = *array;
11838 +
11839 +       if (value == __rlim_get(limit, res))
11840 +               return value;
11841 +
11842 +       __rlim_set(limit, res, value);
11843 +       /* now adjust min/max */
11844 +       if (!__vx_cres_adjust_max(limit, res, value))
11845 +               __vx_cres_adjust_min(limit, res, value);
11846 +
11847 +       return value;
11848 +}
11849 +
11850 +static inline int __vx_cres_array_avail(struct vx_info *vxi,
11851 +       const int *array, int num, char *_file, int _line)
11852 +{
11853 +       struct _vx_limit *limit;
11854 +       rlim_t value = 0;
11855 +       int res;
11856 +
11857 +       if (num == 0)
11858 +               return 1;
11859 +       if (!vxi)
11860 +               return 1;
11861 +
11862 +       limit = &vxi->limit;
11863 +       res = *array;
11864 +       value = __vx_cres_array_sum(limit, array + 1);
11865 +
11866 +       __rlim_set(limit, res, value);
11867 +       __vx_cres_fixup(limit, res, value);
11868 +
11869 +       return __vx_cres_avail(vxi, res, num, _file, _line);
11870 +}
11871 +
11872 +
11873 +static inline void vx_limit_fixup(struct _vx_limit *limit, int id)
11874 +{
11875 +       rlim_t value;
11876 +       int res;
11877 +
11878 +       /* complex resources first */
11879 +       if ((id < 0) || (id == RLIMIT_RSS))
11880 +               __vx_cres_array_fixup(limit, VLA_RSS);
11881 +
11882 +       for (res = 0; res < NUM_LIMITS; res++) {
11883 +               if ((id > 0) && (res != id))
11884 +                       continue;
11885 +
11886 +               value = __rlim_get(limit, res);
11887 +               __vx_cres_fixup(limit, res, value);
11888 +
11889 +               /* not supposed to happen, maybe warn? */
11890 +               if (__rlim_rmax(limit, res) > __rlim_hard(limit, res))
11891 +                       __rlim_rmax(limit, res) = __rlim_hard(limit, res);
11892 +       }
11893 +}
11894 +
11895 +
11896 +#endif /* _VSERVER_LIMIT_INT_H */
11897 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/monitor.h linux-3.9.4-vs2.3.6.2/include/linux/vserver/monitor.h
11898 --- linux-3.9.4/include/linux/vserver/monitor.h 1970-01-01 00:00:00.000000000 +0000
11899 +++ linux-3.9.4-vs2.3.6.2/include/linux/vserver/monitor.h       2013-05-31 14:47:11.000000000 +0000
11900 @@ -0,0 +1,6 @@
11901 +#ifndef _VSERVER_MONITOR_H
11902 +#define _VSERVER_MONITOR_H
11903 +
11904 +#include <uapi/vserver/monitor.h>
11905 +
11906 +#endif /* _VSERVER_MONITOR_H */
11907 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/network.h linux-3.9.4-vs2.3.6.2/include/linux/vserver/network.h
11908 --- linux-3.9.4/include/linux/vserver/network.h 1970-01-01 00:00:00.000000000 +0000
11909 +++ linux-3.9.4-vs2.3.6.2/include/linux/vserver/network.h       2013-05-31 14:47:11.000000000 +0000
11910 @@ -0,0 +1,76 @@
11911 +#ifndef _VSERVER_NETWORK_H
11912 +#define _VSERVER_NETWORK_H
11913 +
11914 +
11915 +#include <linux/list.h>
11916 +#include <linux/spinlock.h>
11917 +#include <linux/rcupdate.h>
11918 +#include <linux/in.h>
11919 +#include <linux/in6.h>
11920 +#include <asm/atomic.h>
11921 +#include <uapi/vserver/network.h>
11922 +
11923 +struct nx_addr_v4 {
11924 +       struct nx_addr_v4 *next;
11925 +       struct in_addr ip[2];
11926 +       struct in_addr mask;
11927 +       uint16_t type;
11928 +       uint16_t flags;
11929 +};
11930 +
11931 +struct nx_addr_v6 {
11932 +       struct nx_addr_v6 *next;
11933 +       struct in6_addr ip;
11934 +       struct in6_addr mask;
11935 +       uint32_t prefix;
11936 +       uint16_t type;
11937 +       uint16_t flags;
11938 +};
11939 +
11940 +struct nx_info {
11941 +       struct hlist_node nx_hlist;     /* linked list of nxinfos */
11942 +       nid_t nx_id;                    /* vnet id */
11943 +       atomic_t nx_usecnt;             /* usage count */
11944 +       atomic_t nx_tasks;              /* tasks count */
11945 +       int nx_state;                   /* context state */
11946 +
11947 +       uint64_t nx_flags;              /* network flag word */
11948 +       uint64_t nx_ncaps;              /* network capabilities */
11949 +
11950 +       spinlock_t addr_lock;           /* protect address changes */
11951 +       struct in_addr v4_lback;        /* Loopback address */
11952 +       struct in_addr v4_bcast;        /* Broadcast address */
11953 +       struct nx_addr_v4 v4;           /* First/Single ipv4 address */
11954 +#ifdef CONFIG_IPV6
11955 +       struct nx_addr_v6 v6;           /* First/Single ipv6 address */
11956 +#endif
11957 +       char nx_name[65];               /* network context name */
11958 +};
11959 +
11960 +
11961 +/* status flags */
11962 +
11963 +#define NXS_HASHED      0x0001
11964 +#define NXS_SHUTDOWN    0x0100
11965 +#define NXS_RELEASED    0x8000
11966 +
11967 +extern struct nx_info *lookup_nx_info(int);
11968 +
11969 +extern int get_nid_list(int, unsigned int *, int);
11970 +extern int nid_is_hashed(nid_t);
11971 +
11972 +extern int nx_migrate_task(struct task_struct *, struct nx_info *);
11973 +
11974 +extern long vs_net_change(struct nx_info *, unsigned int);
11975 +
11976 +struct sock;
11977 +
11978 +
11979 +#define NX_IPV4(n)     ((n)->v4.type != NXA_TYPE_NONE)
11980 +#ifdef  CONFIG_IPV6
11981 +#define NX_IPV6(n)     ((n)->v6.type != NXA_TYPE_NONE)
11982 +#else
11983 +#define NX_IPV6(n)     (0)
11984 +#endif
11985 +
11986 +#endif /* _VSERVER_NETWORK_H */
11987 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/network_cmd.h linux-3.9.4-vs2.3.6.2/include/linux/vserver/network_cmd.h
11988 --- linux-3.9.4/include/linux/vserver/network_cmd.h     1970-01-01 00:00:00.000000000 +0000
11989 +++ linux-3.9.4-vs2.3.6.2/include/linux/vserver/network_cmd.h   2013-05-31 14:47:11.000000000 +0000
11990 @@ -0,0 +1,37 @@
11991 +#ifndef _VSERVER_NETWORK_CMD_H
11992 +#define _VSERVER_NETWORK_CMD_H
11993 +
11994 +#include <uapi/vserver/network_cmd.h>
11995 +
11996 +extern int vc_task_nid(uint32_t);
11997 +
11998 +extern int vc_nx_info(struct nx_info *, void __user *);
11999 +
12000 +extern int vc_net_create(uint32_t, void __user *);
12001 +extern int vc_net_migrate(struct nx_info *, void __user *);
12002 +
12003 +extern int vc_net_add(struct nx_info *, void __user *);
12004 +extern int vc_net_remove(struct nx_info *, void __user *);
12005 +
12006 +extern int vc_net_add_ipv4_v1(struct nx_info *, void __user *);
12007 +extern int vc_net_add_ipv4(struct nx_info *, void __user *);
12008 +
12009 +extern int vc_net_rem_ipv4_v1(struct nx_info *, void __user *);
12010 +extern int vc_net_rem_ipv4(struct nx_info *, void __user *);
12011 +
12012 +extern int vc_net_add_ipv6(struct nx_info *, void __user *);
12013 +extern int vc_net_remove_ipv6(struct nx_info *, void __user *);
12014 +
12015 +extern int vc_add_match_ipv4(struct nx_info *, void __user *);
12016 +extern int vc_get_match_ipv4(struct nx_info *, void __user *);
12017 +
12018 +extern int vc_add_match_ipv6(struct nx_info *, void __user *);
12019 +extern int vc_get_match_ipv6(struct nx_info *, void __user *);
12020 +
12021 +extern int vc_get_nflags(struct nx_info *, void __user *);
12022 +extern int vc_set_nflags(struct nx_info *, void __user *);
12023 +
12024 +extern int vc_get_ncaps(struct nx_info *, void __user *);
12025 +extern int vc_set_ncaps(struct nx_info *, void __user *);
12026 +
12027 +#endif /* _VSERVER_CONTEXT_CMD_H */
12028 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/percpu.h linux-3.9.4-vs2.3.6.2/include/linux/vserver/percpu.h
12029 --- linux-3.9.4/include/linux/vserver/percpu.h  1970-01-01 00:00:00.000000000 +0000
12030 +++ linux-3.9.4-vs2.3.6.2/include/linux/vserver/percpu.h        2013-05-31 14:47:11.000000000 +0000
12031 @@ -0,0 +1,14 @@
12032 +#ifndef _VSERVER_PERCPU_H
12033 +#define _VSERVER_PERCPU_H
12034 +
12035 +#include "cvirt_def.h"
12036 +#include "sched_def.h"
12037 +
12038 +struct _vx_percpu {
12039 +       struct _vx_cvirt_pc cvirt;
12040 +       struct _vx_sched_pc sched;
12041 +};
12042 +
12043 +#define        PERCPU_PERCTX   (sizeof(struct _vx_percpu))
12044 +
12045 +#endif /* _VSERVER_PERCPU_H */
12046 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/pid.h linux-3.9.4-vs2.3.6.2/include/linux/vserver/pid.h
12047 --- linux-3.9.4/include/linux/vserver/pid.h     1970-01-01 00:00:00.000000000 +0000
12048 +++ linux-3.9.4-vs2.3.6.2/include/linux/vserver/pid.h   2013-05-31 14:47:11.000000000 +0000
12049 @@ -0,0 +1,51 @@
12050 +#ifndef _VSERVER_PID_H
12051 +#define _VSERVER_PID_H
12052 +
12053 +/* pid faking stuff */
12054 +
12055 +#define vx_info_map_pid(v, p) \
12056 +       __vx_info_map_pid((v), (p), __func__, __FILE__, __LINE__)
12057 +#define vx_info_map_tgid(v,p)  vx_info_map_pid(v,p)
12058 +#define vx_map_pid(p) vx_info_map_pid(current_vx_info(), p)
12059 +#define vx_map_tgid(p) vx_map_pid(p)
12060 +
12061 +static inline int __vx_info_map_pid(struct vx_info *vxi, int pid,
12062 +       const char *func, const char *file, int line)
12063 +{
12064 +       if (vx_info_flags(vxi, VXF_INFO_INIT, 0)) {
12065 +               vxfprintk(VXD_CBIT(cvirt, 2),
12066 +                       "vx_map_tgid: %p/%llx: %d -> %d",
12067 +                       vxi, (long long)vxi->vx_flags, pid,
12068 +                       (pid && pid == vxi->vx_initpid) ? 1 : pid,
12069 +                       func, file, line);
12070 +               if (pid == 0)
12071 +                       return 0;
12072 +               if (pid == vxi->vx_initpid)
12073 +                       return 1;
12074 +       }
12075 +       return pid;
12076 +}
12077 +
12078 +#define vx_info_rmap_pid(v, p) \
12079 +       __vx_info_rmap_pid((v), (p), __func__, __FILE__, __LINE__)
12080 +#define vx_rmap_pid(p) vx_info_rmap_pid(current_vx_info(), p)
12081 +#define vx_rmap_tgid(p) vx_rmap_pid(p)
12082 +
12083 +static inline int __vx_info_rmap_pid(struct vx_info *vxi, int pid,
12084 +       const char *func, const char *file, int line)
12085 +{
12086 +       if (vx_info_flags(vxi, VXF_INFO_INIT, 0)) {
12087 +               vxfprintk(VXD_CBIT(cvirt, 2),
12088 +                       "vx_rmap_tgid: %p/%llx: %d -> %d",
12089 +                       vxi, (long long)vxi->vx_flags, pid,
12090 +                       (pid == 1) ? vxi->vx_initpid : pid,
12091 +                       func, file, line);
12092 +               if ((pid == 1) && vxi->vx_initpid)
12093 +                       return vxi->vx_initpid;
12094 +               if (pid == vxi->vx_initpid)
12095 +                       return ~0U;
12096 +       }
12097 +       return pid;
12098 +}
12099 +
12100 +#endif
12101 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/sched.h linux-3.9.4-vs2.3.6.2/include/linux/vserver/sched.h
12102 --- linux-3.9.4/include/linux/vserver/sched.h   1970-01-01 00:00:00.000000000 +0000
12103 +++ linux-3.9.4-vs2.3.6.2/include/linux/vserver/sched.h 2013-05-31 14:47:11.000000000 +0000
12104 @@ -0,0 +1,23 @@
12105 +#ifndef _VSERVER_SCHED_H
12106 +#define _VSERVER_SCHED_H
12107 +
12108 +
12109 +#ifdef __KERNEL__
12110 +
12111 +struct timespec;
12112 +
12113 +void vx_vsi_uptime(struct timespec *, struct timespec *);
12114 +
12115 +
12116 +struct vx_info;
12117 +
12118 +void vx_update_load(struct vx_info *);
12119 +
12120 +
12121 +void vx_update_sched_param(struct _vx_sched *sched,
12122 +       struct _vx_sched_pc *sched_pc);
12123 +
12124 +#endif /* __KERNEL__ */
12125 +#else  /* _VSERVER_SCHED_H */
12126 +#warning duplicate inclusion
12127 +#endif /* _VSERVER_SCHED_H */
12128 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/sched_cmd.h linux-3.9.4-vs2.3.6.2/include/linux/vserver/sched_cmd.h
12129 --- linux-3.9.4/include/linux/vserver/sched_cmd.h       1970-01-01 00:00:00.000000000 +0000
12130 +++ linux-3.9.4-vs2.3.6.2/include/linux/vserver/sched_cmd.h     2013-05-31 14:47:11.000000000 +0000
12131 @@ -0,0 +1,11 @@
12132 +#ifndef _VSERVER_SCHED_CMD_H
12133 +#define _VSERVER_SCHED_CMD_H
12134 +
12135 +
12136 +#include <linux/compiler.h>
12137 +#include <uapi/vserver/sched_cmd.h>
12138 +
12139 +extern int vc_set_prio_bias(struct vx_info *, void __user *);
12140 +extern int vc_get_prio_bias(struct vx_info *, void __user *);
12141 +
12142 +#endif /* _VSERVER_SCHED_CMD_H */
12143 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/sched_def.h linux-3.9.4-vs2.3.6.2/include/linux/vserver/sched_def.h
12144 --- linux-3.9.4/include/linux/vserver/sched_def.h       1970-01-01 00:00:00.000000000 +0000
12145 +++ linux-3.9.4-vs2.3.6.2/include/linux/vserver/sched_def.h     2013-05-31 14:47:11.000000000 +0000
12146 @@ -0,0 +1,38 @@
12147 +#ifndef _VSERVER_SCHED_DEF_H
12148 +#define _VSERVER_SCHED_DEF_H
12149 +
12150 +#include <linux/spinlock.h>
12151 +#include <linux/jiffies.h>
12152 +#include <linux/cpumask.h>
12153 +#include <asm/atomic.h>
12154 +#include <asm/param.h>
12155 +
12156 +
12157 +/* context sub struct */
12158 +
12159 +struct _vx_sched {
12160 +       int prio_bias;                  /* bias offset for priority */
12161 +
12162 +       cpumask_t update;               /* CPUs which should update */
12163 +};
12164 +
12165 +struct _vx_sched_pc {
12166 +       int prio_bias;                  /* bias offset for priority */
12167 +
12168 +       uint64_t user_ticks;            /* token tick events */
12169 +       uint64_t sys_ticks;             /* token tick events */
12170 +       uint64_t hold_ticks;            /* token ticks paused */
12171 +};
12172 +
12173 +
12174 +#ifdef CONFIG_VSERVER_DEBUG
12175 +
12176 +static inline void __dump_vx_sched(struct _vx_sched *sched)
12177 +{
12178 +       printk("\t_vx_sched:\n");
12179 +       printk("\t priority = %4d\n", sched->prio_bias);
12180 +}
12181 +
12182 +#endif
12183 +
12184 +#endif /* _VSERVER_SCHED_DEF_H */
12185 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/signal.h linux-3.9.4-vs2.3.6.2/include/linux/vserver/signal.h
12186 --- linux-3.9.4/include/linux/vserver/signal.h  1970-01-01 00:00:00.000000000 +0000
12187 +++ linux-3.9.4-vs2.3.6.2/include/linux/vserver/signal.h        2013-05-31 14:47:11.000000000 +0000
12188 @@ -0,0 +1,14 @@
12189 +#ifndef _VSERVER_SIGNAL_H
12190 +#define _VSERVER_SIGNAL_H
12191 +
12192 +
12193 +#ifdef __KERNEL__
12194 +
12195 +struct vx_info;
12196 +
12197 +int vx_info_kill(struct vx_info *, int, int);
12198 +
12199 +#endif /* __KERNEL__ */
12200 +#else  /* _VSERVER_SIGNAL_H */
12201 +#warning duplicate inclusion
12202 +#endif /* _VSERVER_SIGNAL_H */
12203 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/signal_cmd.h linux-3.9.4-vs2.3.6.2/include/linux/vserver/signal_cmd.h
12204 --- linux-3.9.4/include/linux/vserver/signal_cmd.h      1970-01-01 00:00:00.000000000 +0000
12205 +++ linux-3.9.4-vs2.3.6.2/include/linux/vserver/signal_cmd.h    2013-05-31 14:47:11.000000000 +0000
12206 @@ -0,0 +1,14 @@
12207 +#ifndef _VSERVER_SIGNAL_CMD_H
12208 +#define _VSERVER_SIGNAL_CMD_H
12209 +
12210 +#include <uapi/vserver/signal_cmd.h>
12211 +
12212 +
12213 +extern int vc_ctx_kill(struct vx_info *, void __user *);
12214 +extern int vc_wait_exit(struct vx_info *, void __user *);
12215 +
12216 +
12217 +extern int vc_get_pflags(uint32_t pid, void __user *);
12218 +extern int vc_set_pflags(uint32_t pid, void __user *);
12219 +
12220 +#endif /* _VSERVER_SIGNAL_CMD_H */
12221 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/space.h linux-3.9.4-vs2.3.6.2/include/linux/vserver/space.h
12222 --- linux-3.9.4/include/linux/vserver/space.h   1970-01-01 00:00:00.000000000 +0000
12223 +++ linux-3.9.4-vs2.3.6.2/include/linux/vserver/space.h 2013-05-31 14:47:11.000000000 +0000
12224 @@ -0,0 +1,12 @@
12225 +#ifndef _VSERVER_SPACE_H
12226 +#define _VSERVER_SPACE_H
12227 +
12228 +#include <linux/types.h>
12229 +
12230 +struct vx_info;
12231 +
12232 +int vx_set_space(struct vx_info *vxi, unsigned long mask, unsigned index);
12233 +
12234 +#else  /* _VSERVER_SPACE_H */
12235 +#warning duplicate inclusion
12236 +#endif /* _VSERVER_SPACE_H */
12237 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/space_cmd.h linux-3.9.4-vs2.3.6.2/include/linux/vserver/space_cmd.h
12238 --- linux-3.9.4/include/linux/vserver/space_cmd.h       1970-01-01 00:00:00.000000000 +0000
12239 +++ linux-3.9.4-vs2.3.6.2/include/linux/vserver/space_cmd.h     2013-05-31 14:47:11.000000000 +0000
12240 @@ -0,0 +1,13 @@
12241 +#ifndef _VSERVER_SPACE_CMD_H
12242 +#define _VSERVER_SPACE_CMD_H
12243 +
12244 +#include <uapi/vserver/space_cmd.h>
12245 +
12246 +
12247 +extern int vc_enter_space_v1(struct vx_info *, void __user *);
12248 +extern int vc_set_space_v1(struct vx_info *, void __user *);
12249 +extern int vc_enter_space(struct vx_info *, void __user *);
12250 +extern int vc_set_space(struct vx_info *, void __user *);
12251 +extern int vc_get_space_mask(void __user *, int);
12252 +
12253 +#endif /* _VSERVER_SPACE_CMD_H */
12254 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/switch.h linux-3.9.4-vs2.3.6.2/include/linux/vserver/switch.h
12255 --- linux-3.9.4/include/linux/vserver/switch.h  1970-01-01 00:00:00.000000000 +0000
12256 +++ linux-3.9.4-vs2.3.6.2/include/linux/vserver/switch.h        2013-05-31 14:47:11.000000000 +0000
12257 @@ -0,0 +1,8 @@
12258 +#ifndef _VSERVER_SWITCH_H
12259 +#define _VSERVER_SWITCH_H
12260 +
12261 +
12262 +#include <linux/errno.h>
12263 +#include <uapi/vserver/switch.h>
12264 +
12265 +#endif /* _VSERVER_SWITCH_H */
12266 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/tag.h linux-3.9.4-vs2.3.6.2/include/linux/vserver/tag.h
12267 --- linux-3.9.4/include/linux/vserver/tag.h     1970-01-01 00:00:00.000000000 +0000
12268 +++ linux-3.9.4-vs2.3.6.2/include/linux/vserver/tag.h   2013-06-01 08:36:17.000000000 +0000
12269 @@ -0,0 +1,149 @@
12270 +#ifndef _DX_TAG_H
12271 +#define _DX_TAG_H
12272 +
12273 +#include <linux/types.h>
12274 +
12275 +
12276 +#define DX_TAG(in)     (IS_TAGGED(in))
12277 +
12278 +
12279 +#ifdef CONFIG_TAG_NFSD
12280 +#define DX_TAG_NFSD    1
12281 +#else
12282 +#define DX_TAG_NFSD    0
12283 +#endif
12284 +
12285 +
12286 +#ifdef CONFIG_TAGGING_NONE
12287 +
12288 +#define MAX_UID                0xFFFFFFFF
12289 +#define MAX_GID                0xFFFFFFFF
12290 +
12291 +#define INOTAG_TAG(cond, uid, gid, tag)        (0)
12292 +
12293 +#define TAGINO_UID(cond, uid, tag)     (uid)
12294 +#define TAGINO_GID(cond, gid, tag)     (gid)
12295 +
12296 +#endif
12297 +
12298 +
12299 +#ifdef CONFIG_TAGGING_GID16
12300 +
12301 +#define MAX_UID                0xFFFFFFFF
12302 +#define MAX_GID                0x0000FFFF
12303 +
12304 +#define INOTAG_TAG(cond, uid, gid, tag)        \
12305 +       ((cond) ? (((gid) >> 16) & 0xFFFF) : 0)
12306 +
12307 +#define TAGINO_UID(cond, uid, tag)     (uid)
12308 +#define TAGINO_GID(cond, gid, tag)     \
12309 +       ((cond) ? (((gid) & 0xFFFF) | ((tag) << 16)) : (gid))
12310 +
12311 +#endif
12312 +
12313 +
12314 +#ifdef CONFIG_TAGGING_ID24
12315 +
12316 +#define MAX_UID                0x00FFFFFF
12317 +#define MAX_GID                0x00FFFFFF
12318 +
12319 +#define INOTAG_TAG(cond, uid, gid, tag)        \
12320 +       ((cond) ? ((((uid) >> 16) & 0xFF00) | (((gid) >> 24) & 0xFF)) : 0)
12321 +
12322 +#define TAGINO_UID(cond, uid, tag)     \
12323 +       ((cond) ? (((uid) & 0xFFFFFF) | (((tag) & 0xFF00) << 16)) : (uid))
12324 +#define TAGINO_GID(cond, gid, tag)     \
12325 +       ((cond) ? (((gid) & 0xFFFFFF) | (((tag) & 0x00FF) << 24)) : (gid))
12326 +
12327 +#endif
12328 +
12329 +
12330 +#ifdef CONFIG_TAGGING_UID16
12331 +
12332 +#define MAX_UID                0x0000FFFF
12333 +#define MAX_GID                0xFFFFFFFF
12334 +
12335 +#define INOTAG_TAG(cond, uid, gid, tag)        \
12336 +       ((cond) ? (((uid) >> 16) & 0xFFFF) : 0)
12337 +
12338 +#define TAGINO_UID(cond, uid, tag)     \
12339 +       ((cond) ? (((uid) & 0xFFFF) | ((tag) << 16)) : (uid))
12340 +#define TAGINO_GID(cond, gid, tag)     (gid)
12341 +
12342 +#endif
12343 +
12344 +
12345 +#ifdef CONFIG_TAGGING_INTERN
12346 +
12347 +#define MAX_UID                0xFFFFFFFF
12348 +#define MAX_GID                0xFFFFFFFF
12349 +
12350 +#define INOTAG_TAG(cond, uid, gid, tag)        \
12351 +       ((cond) ? (tag) : 0)
12352 +
12353 +#define TAGINO_UID(cond, uid, tag)     (uid)
12354 +#define TAGINO_GID(cond, gid, tag)     (gid)
12355 +
12356 +#endif
12357 +
12358 +
12359 +#ifndef CONFIG_TAGGING_NONE
12360 +#define dx_current_fstag(sb)   \
12361 +       ((sb)->s_flags & MS_TAGGED ? dx_current_tag() : 0)
12362 +#else
12363 +#define dx_current_fstag(sb)   (0)
12364 +#endif
12365 +
12366 +#ifndef CONFIG_TAGGING_INTERN
12367 +#define TAGINO_TAG(cond, tag)  (0)
12368 +#else
12369 +#define TAGINO_TAG(cond, tag)  ((cond) ? (tag) : 0)
12370 +#endif
12371 +
12372 +#define INOTAG_UID(cond, uid, gid)     \
12373 +       ((cond) ? ((uid) & MAX_UID) : (uid))
12374 +#define INOTAG_GID(cond, uid, gid)     \
12375 +       ((cond) ? ((gid) & MAX_GID) : (gid))
12376 +
12377 +
12378 +static inline uid_t dx_map_uid(uid_t uid)
12379 +{
12380 +       if ((uid > MAX_UID) && (uid != -1))
12381 +               uid = -2;
12382 +       return (uid & MAX_UID);
12383 +}
12384 +
12385 +#define        dx_map_kuid(n, u) \
12386 +       make_kuid(n, dx_map_uid(from_kuid(n, u)))
12387 +
12388 +static inline gid_t dx_map_gid(gid_t gid)
12389 +{
12390 +       if ((gid > MAX_GID) && (gid != -1))
12391 +               gid = -2;
12392 +       return (gid & MAX_GID);
12393 +}
12394 +
12395 +#define        dx_map_kgid(n, u) \
12396 +       make_kgid(n, dx_map_gid(from_kgid(n, u)))
12397 +
12398 +struct peer_tag {
12399 +       int32_t xid;
12400 +       int32_t nid;
12401 +};
12402 +
12403 +#define dx_notagcheck(sb) ((sb) && ((sb)->s_flags & MS_NOTAGCHECK))
12404 +
12405 +int dx_parse_tag(char *string, tag_t *tag, int remove, int *mnt_flags,
12406 +                unsigned long *flags);
12407 +
12408 +#ifdef CONFIG_PROPAGATE
12409 +
12410 +void __dx_propagate_tag(struct nameidata *nd, struct inode *inode);
12411 +
12412 +#define dx_propagate_tag(n, i) __dx_propagate_tag(n, i)
12413 +
12414 +#else
12415 +#define dx_propagate_tag(n, i) do { } while (0)
12416 +#endif
12417 +
12418 +#endif /* _DX_TAG_H */
12419 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/tag_cmd.h linux-3.9.4-vs2.3.6.2/include/linux/vserver/tag_cmd.h
12420 --- linux-3.9.4/include/linux/vserver/tag_cmd.h 1970-01-01 00:00:00.000000000 +0000
12421 +++ linux-3.9.4-vs2.3.6.2/include/linux/vserver/tag_cmd.h       2013-05-31 14:47:11.000000000 +0000
12422 @@ -0,0 +1,10 @@
12423 +#ifndef _VSERVER_TAG_CMD_H
12424 +#define _VSERVER_TAG_CMD_H
12425 +
12426 +#include <uapi/vserver/tag_cmd.h>
12427 +
12428 +extern int vc_task_tag(uint32_t);
12429 +
12430 +extern int vc_tag_migrate(uint32_t);
12431 +
12432 +#endif /* _VSERVER_TAG_CMD_H */
12433 diff -NurpP --minimal linux-3.9.4/include/net/addrconf.h linux-3.9.4-vs2.3.6.2/include/net/addrconf.h
12434 --- linux-3.9.4/include/net/addrconf.h  2013-05-31 13:45:28.000000000 +0000
12435 +++ linux-3.9.4-vs2.3.6.2/include/net/addrconf.h        2013-05-31 17:17:53.000000000 +0000
12436 @@ -85,7 +85,8 @@ extern int                    ipv6_dev_get_saddr(struct n
12437                                                const struct net_device *dev,
12438                                                const struct in6_addr *daddr,
12439                                                unsigned int srcprefs,
12440 -                                              struct in6_addr *saddr);
12441 +                                              struct in6_addr *saddr,
12442 +                                              struct nx_info *nxi);
12443  extern int                     ipv6_get_lladdr(struct net_device *dev,
12444                                                 struct in6_addr *addr,
12445                                                 unsigned char banned_flags);
12446 diff -NurpP --minimal linux-3.9.4/include/net/af_unix.h linux-3.9.4-vs2.3.6.2/include/net/af_unix.h
12447 --- linux-3.9.4/include/net/af_unix.h   2013-02-19 13:58:52.000000000 +0000
12448 +++ linux-3.9.4-vs2.3.6.2/include/net/af_unix.h 2013-05-31 17:17:53.000000000 +0000
12449 @@ -4,6 +4,7 @@
12450  #include <linux/socket.h>
12451  #include <linux/un.h>
12452  #include <linux/mutex.h>
12453 +#include <linux/vs_base.h>
12454  #include <net/sock.h>
12455  
12456  extern void unix_inflight(struct file *fp);
12457 diff -NurpP --minimal linux-3.9.4/include/net/inet_timewait_sock.h linux-3.9.4-vs2.3.6.2/include/net/inet_timewait_sock.h
12458 --- linux-3.9.4/include/net/inet_timewait_sock.h        2013-05-31 13:45:28.000000000 +0000
12459 +++ linux-3.9.4-vs2.3.6.2/include/net/inet_timewait_sock.h      2013-05-31 17:18:34.000000000 +0000
12460 @@ -116,6 +116,10 @@ struct inet_timewait_sock {
12461  #define tw_dport               __tw_common.skc_dport
12462  #define tw_num                 __tw_common.skc_num
12463  #define tw_portpair            __tw_common.skc_portpair
12464 +#define tw_xid                 __tw_common.skc_xid
12465 +#define tw_vx_info             __tw_common.skc_vx_info
12466 +#define tw_nid                 __tw_common.skc_nid
12467 +#define tw_nx_info             __tw_common.skc_nx_info
12468  
12469         int                     tw_timeout;
12470         volatile unsigned char  tw_substate;
12471 diff -NurpP --minimal linux-3.9.4/include/net/ip6_route.h linux-3.9.4-vs2.3.6.2/include/net/ip6_route.h
12472 --- linux-3.9.4/include/net/ip6_route.h 2013-05-31 13:45:28.000000000 +0000
12473 +++ linux-3.9.4-vs2.3.6.2/include/net/ip6_route.h       2013-05-31 17:17:53.000000000 +0000
12474 @@ -95,7 +95,8 @@ extern int                    ip6_route_get_saddr(struct
12475                                                     struct rt6_info *rt,
12476                                                     const struct in6_addr *daddr,
12477                                                     unsigned int prefs,
12478 -                                                   struct in6_addr *saddr);
12479 +                                                   struct in6_addr *saddr,
12480 +                                                   struct nx_info *nxi);
12481  
12482  extern struct rt6_info         *rt6_lookup(struct net *net,
12483                                             const struct in6_addr *daddr,
12484 diff -NurpP --minimal linux-3.9.4/include/net/route.h linux-3.9.4-vs2.3.6.2/include/net/route.h
12485 --- linux-3.9.4/include/net/route.h     2013-02-19 13:58:52.000000000 +0000
12486 +++ linux-3.9.4-vs2.3.6.2/include/net/route.h   2013-05-31 17:17:53.000000000 +0000
12487 @@ -207,6 +207,9 @@ static inline void ip_rt_put(struct rtab
12488         dst_release(&rt->dst);
12489  }
12490  
12491 +#include <linux/vs_base.h>
12492 +#include <linux/vs_inet.h>
12493 +
12494  #define IPTOS_RT_MASK  (IPTOS_TOS_MASK & ~3)
12495  
12496  extern const __u8 ip_tos2prio[16];
12497 @@ -256,6 +259,9 @@ static inline void ip_route_connect_init
12498                            protocol, flow_flags, dst, src, dport, sport);
12499  }
12500  
12501 +extern struct rtable *ip_v4_find_src(struct net *net, struct nx_info *,
12502 +       struct flowi4 *);
12503 +
12504  static inline struct rtable *ip_route_connect(struct flowi4 *fl4,
12505                                               __be32 dst, __be32 src, u32 tos,
12506                                               int oif, u8 protocol,
12507 @@ -264,11 +270,25 @@ static inline struct rtable *ip_route_co
12508  {
12509         struct net *net = sock_net(sk);
12510         struct rtable *rt;
12511 +       struct nx_info *nx_info = current_nx_info();
12512  
12513         ip_route_connect_init(fl4, dst, src, tos, oif, protocol,
12514                               sport, dport, sk, can_sleep);
12515  
12516 -       if (!dst || !src) {
12517 +       if (sk)
12518 +               nx_info = sk->sk_nx_info;
12519 +
12520 +       vxdprintk(VXD_CBIT(net, 4),
12521 +               "ip_route_connect(%p) %p,%p;%lx",
12522 +               sk, nx_info, sk->sk_socket,
12523 +               (sk->sk_socket?sk->sk_socket->flags:0));
12524 +
12525 +       rt = ip_v4_find_src(net, nx_info, fl4);
12526 +       if (IS_ERR(rt))
12527 +               return rt;
12528 +       ip_rt_put(rt);
12529 +
12530 +       if (!fl4->daddr || !fl4->saddr) {
12531                 rt = __ip_route_output_key(net, fl4);
12532                 if (IS_ERR(rt))
12533                         return rt;
12534 diff -NurpP --minimal linux-3.9.4/include/net/sock.h linux-3.9.4-vs2.3.6.2/include/net/sock.h
12535 --- linux-3.9.4/include/net/sock.h      2013-05-31 14:22:27.000000000 +0000
12536 +++ linux-3.9.4-vs2.3.6.2/include/net/sock.h    2013-05-31 17:17:53.000000000 +0000
12537 @@ -191,6 +191,10 @@ struct sock_common {
12538  #ifdef CONFIG_NET_NS
12539         struct net              *skc_net;
12540  #endif
12541 +       xid_t                   skc_xid;
12542 +       struct vx_info          *skc_vx_info;
12543 +       nid_t                   skc_nid;
12544 +       struct nx_info          *skc_nx_info;
12545         /*
12546          * fields between dontcopy_begin/dontcopy_end
12547          * are not copied in sock_copy()
12548 @@ -304,6 +308,10 @@ struct sock {
12549  #define sk_bind_node           __sk_common.skc_bind_node
12550  #define sk_prot                        __sk_common.skc_prot
12551  #define sk_net                 __sk_common.skc_net
12552 +#define sk_xid                 __sk_common.skc_xid
12553 +#define sk_vx_info             __sk_common.skc_vx_info
12554 +#define sk_nid                 __sk_common.skc_nid
12555 +#define sk_nx_info             __sk_common.skc_nx_info
12556         socket_lock_t           sk_lock;
12557         struct sk_buff_head     sk_receive_queue;
12558         /*
12559 diff -NurpP --minimal linux-3.9.4/include/uapi/Kbuild linux-3.9.4-vs2.3.6.2/include/uapi/Kbuild
12560 --- linux-3.9.4/include/uapi/Kbuild     2012-12-11 03:30:57.000000000 +0000
12561 +++ linux-3.9.4-vs2.3.6.2/include/uapi/Kbuild   2013-05-31 14:47:11.000000000 +0000
12562 @@ -12,3 +12,4 @@ header-y += video/
12563  header-y += drm/
12564  header-y += xen/
12565  header-y += scsi/
12566 +header-y += vserver/
12567 diff -NurpP --minimal linux-3.9.4/include/uapi/linux/capability.h linux-3.9.4-vs2.3.6.2/include/uapi/linux/capability.h
12568 --- linux-3.9.4/include/uapi/linux/capability.h 2012-12-11 03:30:57.000000000 +0000
12569 +++ linux-3.9.4-vs2.3.6.2/include/uapi/linux/capability.h       2013-05-31 14:47:11.000000000 +0000
12570 @@ -259,6 +259,7 @@ struct vfs_cap_data {
12571     arbitrary SCSI commands */
12572  /* Allow setting encryption key on loopback filesystem */
12573  /* Allow setting zone reclaim policy */
12574 +/* Allow the selection of a security context */
12575  
12576  #define CAP_SYS_ADMIN        21
12577  
12578 @@ -345,7 +346,12 @@ struct vfs_cap_data {
12579  
12580  #define CAP_LAST_CAP         CAP_BLOCK_SUSPEND
12581  
12582 -#define cap_valid(x) ((x) >= 0 && (x) <= CAP_LAST_CAP)
12583 +/* Allow context manipulations */
12584 +/* Allow changing context info on files */
12585 +
12586 +#define CAP_CONTEXT         63
12587 +
12588 +#define cap_valid(x) ((x) >= 0 && ((x) <= CAP_LAST_CAP || (x) == CAP_CONTEXT))
12589  
12590  /*
12591   * Bit location of each capability (used by user-space library and kernel)
12592 diff -NurpP --minimal linux-3.9.4/include/uapi/linux/fs.h linux-3.9.4-vs2.3.6.2/include/uapi/linux/fs.h
12593 --- linux-3.9.4/include/uapi/linux/fs.h 2013-05-31 13:45:29.000000000 +0000
12594 +++ linux-3.9.4-vs2.3.6.2/include/uapi/linux/fs.h       2013-05-31 23:07:43.000000000 +0000
12595 @@ -86,6 +86,9 @@ struct inodes_stat_t {
12596  #define MS_KERNMOUNT   (1<<22) /* this is a kern_mount call */
12597  #define MS_I_VERSION   (1<<23) /* Update inode I_version field */
12598  #define MS_STRICTATIME (1<<24) /* Always perform atime updates */
12599 +#define MS_TAGGED      (1<<8)  /* use generic inode tagging */
12600 +#define MS_NOTAGCHECK  (1<<9)  /* don't check tags */
12601 +#define MS_TAGID       (1<<25) /* use specific tag for this mount */
12602  
12603  /* These sb flags are internal to the kernel */
12604  #define MS_SNAP_STABLE (1<<27) /* Snapshot pages during writeback, if needed */
12605 @@ -192,11 +195,14 @@ struct inodes_stat_t {
12606  #define FS_EXTENT_FL                   0x00080000 /* Extents */
12607  #define FS_DIRECTIO_FL                 0x00100000 /* Use direct i/o */
12608  #define FS_NOCOW_FL                    0x00800000 /* Do not cow file */
12609 +#define FS_IXUNLINK_FL                 0x08000000 /* Immutable invert on unlink */
12610  #define FS_RESERVED_FL                 0x80000000 /* reserved for ext2 lib */
12611  
12612 -#define FS_FL_USER_VISIBLE             0x0003DFFF /* User visible flags */
12613 -#define FS_FL_USER_MODIFIABLE          0x000380FF /* User modifiable flags */
12614 +#define FS_BARRIER_FL                  0x04000000 /* Barrier for chroot() */
12615 +#define FS_COW_FL                      0x20000000 /* Copy on Write marker */
12616  
12617 +#define FS_FL_USER_VISIBLE             0x0103DFFF /* User visible flags */
12618 +#define FS_FL_USER_MODIFIABLE          0x010380FF /* User modifiable flags */
12619  
12620  #define SYNC_FILE_RANGE_WAIT_BEFORE    1
12621  #define SYNC_FILE_RANGE_WRITE          2
12622 diff -NurpP --minimal linux-3.9.4/include/uapi/linux/gfs2_ondisk.h linux-3.9.4-vs2.3.6.2/include/uapi/linux/gfs2_ondisk.h
12623 --- linux-3.9.4/include/uapi/linux/gfs2_ondisk.h        2012-12-11 03:30:57.000000000 +0000
12624 +++ linux-3.9.4-vs2.3.6.2/include/uapi/linux/gfs2_ondisk.h      2013-05-31 14:47:11.000000000 +0000
12625 @@ -225,6 +225,9 @@ enum {
12626         gfs2fl_Sync             = 8,
12627         gfs2fl_System           = 9,
12628         gfs2fl_TopLevel         = 10,
12629 +       gfs2fl_IXUnlink         = 16,
12630 +       gfs2fl_Barrier          = 17,
12631 +       gfs2fl_Cow              = 18,
12632         gfs2fl_TruncInProg      = 29,
12633         gfs2fl_InheritDirectio  = 30,
12634         gfs2fl_InheritJdata     = 31,
12635 @@ -242,6 +245,9 @@ enum {
12636  #define GFS2_DIF_SYNC                  0x00000100
12637  #define GFS2_DIF_SYSTEM                        0x00000200 /* New in gfs2 */
12638  #define GFS2_DIF_TOPDIR                        0x00000400 /* New in gfs2 */
12639 +#define GFS2_DIF_IXUNLINK               0x00010000
12640 +#define GFS2_DIF_BARRIER                0x00020000
12641 +#define GFS2_DIF_COW                    0x00040000
12642  #define GFS2_DIF_TRUNC_IN_PROG         0x20000000 /* New in gfs2 */
12643  #define GFS2_DIF_INHERIT_DIRECTIO      0x40000000 /* only in gfs1 */
12644  #define GFS2_DIF_INHERIT_JDATA         0x80000000
12645 diff -NurpP --minimal linux-3.9.4/include/uapi/linux/if_tun.h linux-3.9.4-vs2.3.6.2/include/uapi/linux/if_tun.h
12646 --- linux-3.9.4/include/uapi/linux/if_tun.h     2013-02-19 13:58:55.000000000 +0000
12647 +++ linux-3.9.4-vs2.3.6.2/include/uapi/linux/if_tun.h   2013-05-31 15:00:16.000000000 +0000
12648 @@ -56,6 +56,7 @@
12649  #define TUNGETVNETHDRSZ _IOR('T', 215, int)
12650  #define TUNSETVNETHDRSZ _IOW('T', 216, int)
12651  #define TUNSETQUEUE  _IOW('T', 217, int)
12652 +#define TUNSETNID     _IOW('T', 218, int)
12653  
12654  /* TUNSETIFF ifr flags */
12655  #define IFF_TUN                0x0001
12656 diff -NurpP --minimal linux-3.9.4/include/uapi/linux/major.h linux-3.9.4-vs2.3.6.2/include/uapi/linux/major.h
12657 --- linux-3.9.4/include/uapi/linux/major.h      2012-12-11 03:30:57.000000000 +0000
12658 +++ linux-3.9.4-vs2.3.6.2/include/uapi/linux/major.h    2013-05-31 14:47:11.000000000 +0000
12659 @@ -15,6 +15,7 @@
12660  #define HD_MAJOR               IDE0_MAJOR
12661  #define PTY_SLAVE_MAJOR                3
12662  #define TTY_MAJOR              4
12663 +#define VROOT_MAJOR            4
12664  #define TTYAUX_MAJOR           5
12665  #define LP_MAJOR               6
12666  #define VCS_MAJOR              7
12667 diff -NurpP --minimal linux-3.9.4/include/uapi/linux/nfs_mount.h linux-3.9.4-vs2.3.6.2/include/uapi/linux/nfs_mount.h
12668 --- linux-3.9.4/include/uapi/linux/nfs_mount.h  2012-12-11 03:30:57.000000000 +0000
12669 +++ linux-3.9.4-vs2.3.6.2/include/uapi/linux/nfs_mount.h        2013-05-31 14:47:11.000000000 +0000
12670 @@ -63,7 +63,8 @@ struct nfs_mount_data {
12671  #define NFS_MOUNT_SECFLAVOUR   0x2000  /* 5 */
12672  #define NFS_MOUNT_NORDIRPLUS   0x4000  /* 5 */
12673  #define NFS_MOUNT_UNSHARED     0x8000  /* 5 */
12674 -#define NFS_MOUNT_FLAGMASK     0xFFFF
12675 +#define NFS_MOUNT_TAGGED       0x10000 /* context tagging */
12676 +#define NFS_MOUNT_FLAGMASK     0x1FFFF
12677  
12678  /* The following are for internal use only */
12679  #define NFS_MOUNT_LOOKUP_CACHE_NONEG   0x10000
12680 diff -NurpP --minimal linux-3.9.4/include/uapi/linux/reboot.h linux-3.9.4-vs2.3.6.2/include/uapi/linux/reboot.h
12681 --- linux-3.9.4/include/uapi/linux/reboot.h     2012-12-11 03:30:57.000000000 +0000
12682 +++ linux-3.9.4-vs2.3.6.2/include/uapi/linux/reboot.h   2013-05-31 14:47:11.000000000 +0000
12683 @@ -33,7 +33,7 @@
12684  #define        LINUX_REBOOT_CMD_RESTART2       0xA1B2C3D4
12685  #define        LINUX_REBOOT_CMD_SW_SUSPEND     0xD000FCE2
12686  #define        LINUX_REBOOT_CMD_KEXEC          0x45584543
12687 -
12688 +#define        LINUX_REBOOT_CMD_OOM            0xDEADBEEF
12689  
12690  
12691  #endif /* _UAPI_LINUX_REBOOT_H */
12692 diff -NurpP --minimal linux-3.9.4/include/uapi/linux/sysctl.h linux-3.9.4-vs2.3.6.2/include/uapi/linux/sysctl.h
12693 --- linux-3.9.4/include/uapi/linux/sysctl.h     2012-12-11 03:30:57.000000000 +0000
12694 +++ linux-3.9.4-vs2.3.6.2/include/uapi/linux/sysctl.h   2013-05-31 14:47:11.000000000 +0000
12695 @@ -60,6 +60,7 @@ enum
12696         CTL_ABI=9,              /* Binary emulation */
12697         CTL_CPU=10,             /* CPU stuff (speed scaling, etc) */
12698         CTL_ARLAN=254,          /* arlan wireless driver */
12699 +       CTL_VSERVER=4242,       /* Linux-VServer debug */
12700         CTL_S390DBF=5677,       /* s390 debug */
12701         CTL_SUNRPC=7249,        /* sunrpc debug */
12702         CTL_PM=9899,            /* frv power management */
12703 @@ -94,6 +95,7 @@ enum
12704  
12705         KERN_PANIC=15,          /* int: panic timeout */
12706         KERN_REALROOTDEV=16,    /* real root device to mount after initrd */
12707 +       KERN_VSHELPER=17,       /* string: path to vshelper policy agent */
12708  
12709         KERN_SPARC_REBOOT=21,   /* reboot command on Sparc */
12710         KERN_CTLALTDEL=22,      /* int: allow ctl-alt-del to reboot */
12711 diff -NurpP --minimal linux-3.9.4/include/uapi/vserver/Kbuild linux-3.9.4-vs2.3.6.2/include/uapi/vserver/Kbuild
12712 --- linux-3.9.4/include/uapi/vserver/Kbuild     1970-01-01 00:00:00.000000000 +0000
12713 +++ linux-3.9.4-vs2.3.6.2/include/uapi/vserver/Kbuild   2013-05-31 14:47:11.000000000 +0000
12714 @@ -0,0 +1,9 @@
12715 +
12716 +header-y += context_cmd.h network_cmd.h space_cmd.h \
12717 +       cacct_cmd.h cvirt_cmd.h limit_cmd.h dlimit_cmd.h \
12718 +       inode_cmd.h tag_cmd.h sched_cmd.h signal_cmd.h \
12719 +       debug_cmd.h device_cmd.h
12720 +
12721 +header-y += switch.h context.h network.h monitor.h \
12722 +       limit.h inode.h device.h
12723 +
12724 diff -NurpP --minimal linux-3.9.4/include/uapi/vserver/cacct_cmd.h linux-3.9.4-vs2.3.6.2/include/uapi/vserver/cacct_cmd.h
12725 --- linux-3.9.4/include/uapi/vserver/cacct_cmd.h        1970-01-01 00:00:00.000000000 +0000
12726 +++ linux-3.9.4-vs2.3.6.2/include/uapi/vserver/cacct_cmd.h      2013-05-31 14:47:11.000000000 +0000
12727 @@ -0,0 +1,15 @@
12728 +#ifndef _UAPI_VS_CACCT_CMD_H
12729 +#define _UAPI_VS_CACCT_CMD_H
12730 +
12731 +
12732 +/* virtual host info name commands */
12733 +
12734 +#define VCMD_sock_stat         VC_CMD(VSTAT, 5, 0)
12735 +
12736 +struct vcmd_sock_stat_v0 {
12737 +       uint32_t field;
12738 +       uint32_t count[3];
12739 +       uint64_t total[3];
12740 +};
12741 +
12742 +#endif /* _UAPI_VS_CACCT_CMD_H */
12743 diff -NurpP --minimal linux-3.9.4/include/uapi/vserver/context.h linux-3.9.4-vs2.3.6.2/include/uapi/vserver/context.h
12744 --- linux-3.9.4/include/uapi/vserver/context.h  1970-01-01 00:00:00.000000000 +0000
12745 +++ linux-3.9.4-vs2.3.6.2/include/uapi/vserver/context.h        2013-05-31 19:44:13.000000000 +0000
12746 @@ -0,0 +1,81 @@
12747 +#ifndef _UAPI_VS_CONTEXT_H
12748 +#define _UAPI_VS_CONTEXT_H
12749 +
12750 +#include <linux/types.h>
12751 +#include <linux/capability.h>
12752 +
12753 +
12754 +/* context flags */
12755 +
12756 +#define VXF_INFO_SCHED         0x00000002
12757 +#define VXF_INFO_NPROC         0x00000004
12758 +#define VXF_INFO_PRIVATE       0x00000008
12759 +
12760 +#define VXF_INFO_INIT          0x00000010
12761 +#define VXF_INFO_HIDE          0x00000020
12762 +#define VXF_INFO_ULIMIT                0x00000040
12763 +#define VXF_INFO_NSPACE                0x00000080
12764 +
12765 +#define VXF_SCHED_HARD         0x00000100
12766 +#define VXF_SCHED_PRIO         0x00000200
12767 +#define VXF_SCHED_PAUSE                0x00000400
12768 +
12769 +#define VXF_VIRT_MEM           0x00010000
12770 +#define VXF_VIRT_UPTIME                0x00020000
12771 +#define VXF_VIRT_CPU           0x00040000
12772 +#define VXF_VIRT_LOAD          0x00080000
12773 +#define VXF_VIRT_TIME          0x00100000
12774 +
12775 +#define VXF_HIDE_MOUNT         0x01000000
12776 +/* was VXF_HIDE_NETIF          0x02000000 */
12777 +#define VXF_HIDE_VINFO         0x04000000
12778 +
12779 +#define VXF_STATE_SETUP                (1ULL << 32)
12780 +#define VXF_STATE_INIT         (1ULL << 33)
12781 +#define VXF_STATE_ADMIN                (1ULL << 34)
12782 +
12783 +#define VXF_SC_HELPER          (1ULL << 36)
12784 +#define VXF_REBOOT_KILL                (1ULL << 37)
12785 +#define VXF_PERSISTENT         (1ULL << 38)
12786 +
12787 +#define VXF_FORK_RSS           (1ULL << 48)
12788 +#define VXF_PROLIFIC           (1ULL << 49)
12789 +
12790 +#define VXF_IGNEG_NICE         (1ULL << 52)
12791 +
12792 +#define VXF_ONE_TIME           (0x0007ULL << 32)
12793 +
12794 +#define VXF_INIT_SET           (VXF_STATE_SETUP | VXF_STATE_INIT | VXF_STATE_ADMIN)
12795 +
12796 +
12797 +/* context migration */
12798 +
12799 +#define VXM_SET_INIT           0x00000001
12800 +#define VXM_SET_REAPER         0x00000002
12801 +
12802 +/* context caps */
12803 +
12804 +#define VXC_SET_UTSNAME                0x00000001
12805 +#define VXC_SET_RLIMIT         0x00000002
12806 +#define VXC_FS_SECURITY                0x00000004
12807 +#define VXC_FS_TRUSTED         0x00000008
12808 +#define VXC_TIOCSTI            0x00000010
12809 +
12810 +/* was VXC_RAW_ICMP            0x00000100 */
12811 +#define VXC_SYSLOG             0x00001000
12812 +#define VXC_OOM_ADJUST         0x00002000
12813 +#define VXC_AUDIT_CONTROL      0x00004000
12814 +
12815 +/* #define VXC_SECURE_MOUNT    0x00010000
12816 +#define VXC_SECURE_REMOUNT     0x00020000 */
12817 +#define VXC_BINARY_MOUNT       0x00040000
12818 +#define VXC_DEV_MOUNT          0x00080000
12819 +
12820 +#define VXC_QUOTA_CTL          0x00100000
12821 +#define VXC_ADMIN_MAPPER       0x00200000
12822 +#define VXC_ADMIN_CLOOP                0x00400000
12823 +
12824 +#define VXC_KTHREAD            0x01000000
12825 +#define VXC_NAMESPACE          0x02000000
12826 +
12827 +#endif /* _UAPI_VS_CONTEXT_H */
12828 diff -NurpP --minimal linux-3.9.4/include/uapi/vserver/context_cmd.h linux-3.9.4-vs2.3.6.2/include/uapi/vserver/context_cmd.h
12829 --- linux-3.9.4/include/uapi/vserver/context_cmd.h      1970-01-01 00:00:00.000000000 +0000
12830 +++ linux-3.9.4-vs2.3.6.2/include/uapi/vserver/context_cmd.h    2013-05-31 14:47:11.000000000 +0000
12831 @@ -0,0 +1,115 @@
12832 +#ifndef _UAPI_VS_CONTEXT_CMD_H
12833 +#define _UAPI_VS_CONTEXT_CMD_H
12834 +
12835 +
12836 +/* vinfo commands */
12837 +
12838 +#define VCMD_task_xid          VC_CMD(VINFO, 1, 0)
12839 +
12840 +
12841 +#define VCMD_vx_info           VC_CMD(VINFO, 5, 0)
12842 +
12843 +struct vcmd_vx_info_v0 {
12844 +       uint32_t xid;
12845 +       uint32_t initpid;
12846 +       /* more to come */
12847 +};
12848 +
12849 +
12850 +#define VCMD_ctx_stat          VC_CMD(VSTAT, 0, 0)
12851 +
12852 +struct vcmd_ctx_stat_v0 {
12853 +       uint32_t usecnt;
12854 +       uint32_t tasks;
12855 +       /* more to come */
12856 +};
12857 +
12858 +
12859 +/* context commands */
12860 +
12861 +#define VCMD_ctx_create_v0     VC_CMD(VPROC, 1, 0)
12862 +#define VCMD_ctx_create                VC_CMD(VPROC, 1, 1)
12863 +
12864 +struct vcmd_ctx_create {
12865 +       uint64_t flagword;
12866 +};
12867 +
12868 +#define VCMD_ctx_migrate_v0    VC_CMD(PROCMIG, 1, 0)
12869 +#define VCMD_ctx_migrate       VC_CMD(PROCMIG, 1, 1)
12870 +
12871 +struct vcmd_ctx_migrate {
12872 +       uint64_t flagword;
12873 +};
12874 +
12875 +
12876 +
12877 +/* flag commands */
12878 +
12879 +#define VCMD_get_cflags                VC_CMD(FLAGS, 1, 0)
12880 +#define VCMD_set_cflags                VC_CMD(FLAGS, 2, 0)
12881 +
12882 +struct vcmd_ctx_flags_v0 {
12883 +       uint64_t flagword;
12884 +       uint64_t mask;
12885 +};
12886 +
12887 +
12888 +
12889 +/* context caps commands */
12890 +
12891 +#define VCMD_get_ccaps         VC_CMD(FLAGS, 3, 1)
12892 +#define VCMD_set_ccaps         VC_CMD(FLAGS, 4, 1)
12893 +
12894 +struct vcmd_ctx_caps_v1 {
12895 +       uint64_t ccaps;
12896 +       uint64_t cmask;
12897 +};
12898 +
12899 +
12900 +
12901 +/* bcaps commands */
12902 +
12903 +#define VCMD_get_bcaps         VC_CMD(FLAGS, 9, 0)
12904 +#define VCMD_set_bcaps         VC_CMD(FLAGS, 10, 0)
12905 +
12906 +struct vcmd_bcaps {
12907 +       uint64_t bcaps;
12908 +       uint64_t bmask;
12909 +};
12910 +
12911 +
12912 +
12913 +/* umask commands */
12914 +
12915 +#define VCMD_get_umask         VC_CMD(FLAGS, 13, 0)
12916 +#define VCMD_set_umask         VC_CMD(FLAGS, 14, 0)
12917 +
12918 +struct vcmd_umask {
12919 +       uint64_t umask;
12920 +       uint64_t mask;
12921 +};
12922 +
12923 +
12924 +
12925 +/* wmask commands */
12926 +
12927 +#define VCMD_get_wmask         VC_CMD(FLAGS, 15, 0)
12928 +#define VCMD_set_wmask         VC_CMD(FLAGS, 16, 0)
12929 +
12930 +struct vcmd_wmask {
12931 +       uint64_t wmask;
12932 +       uint64_t mask;
12933 +};
12934 +
12935 +
12936 +
12937 +/* OOM badness */
12938 +
12939 +#define VCMD_get_badness       VC_CMD(MEMCTRL, 5, 0)
12940 +#define VCMD_set_badness       VC_CMD(MEMCTRL, 6, 0)
12941 +
12942 +struct vcmd_badness_v0 {
12943 +       int64_t bias;
12944 +};
12945 +
12946 +#endif /* _UAPI_VS_CONTEXT_CMD_H */
12947 diff -NurpP --minimal linux-3.9.4/include/uapi/vserver/cvirt_cmd.h linux-3.9.4-vs2.3.6.2/include/uapi/vserver/cvirt_cmd.h
12948 --- linux-3.9.4/include/uapi/vserver/cvirt_cmd.h        1970-01-01 00:00:00.000000000 +0000
12949 +++ linux-3.9.4-vs2.3.6.2/include/uapi/vserver/cvirt_cmd.h      2013-05-31 14:47:11.000000000 +0000
12950 @@ -0,0 +1,41 @@
12951 +#ifndef _UAPI_VS_CVIRT_CMD_H
12952 +#define _UAPI_VS_CVIRT_CMD_H
12953 +
12954 +
12955 +/* virtual host info name commands */
12956 +
12957 +#define VCMD_set_vhi_name      VC_CMD(VHOST, 1, 0)
12958 +#define VCMD_get_vhi_name      VC_CMD(VHOST, 2, 0)
12959 +
12960 +struct vcmd_vhi_name_v0 {
12961 +       uint32_t field;
12962 +       char name[65];
12963 +};
12964 +
12965 +
12966 +enum vhi_name_field {
12967 +       VHIN_CONTEXT = 0,
12968 +       VHIN_SYSNAME,
12969 +       VHIN_NODENAME,
12970 +       VHIN_RELEASE,
12971 +       VHIN_VERSION,
12972 +       VHIN_MACHINE,
12973 +       VHIN_DOMAINNAME,
12974 +};
12975 +
12976 +
12977 +
12978 +#define VCMD_virt_stat         VC_CMD(VSTAT, 3, 0)
12979 +
12980 +struct vcmd_virt_stat_v0 {
12981 +       uint64_t offset;
12982 +       uint64_t uptime;
12983 +       uint32_t nr_threads;
12984 +       uint32_t nr_running;
12985 +       uint32_t nr_uninterruptible;
12986 +       uint32_t nr_onhold;
12987 +       uint32_t nr_forks;
12988 +       uint32_t load[3];
12989 +};
12990 +
12991 +#endif /* _UAPI_VS_CVIRT_CMD_H */
12992 diff -NurpP --minimal linux-3.9.4/include/uapi/vserver/debug_cmd.h linux-3.9.4-vs2.3.6.2/include/uapi/vserver/debug_cmd.h
12993 --- linux-3.9.4/include/uapi/vserver/debug_cmd.h        1970-01-01 00:00:00.000000000 +0000
12994 +++ linux-3.9.4-vs2.3.6.2/include/uapi/vserver/debug_cmd.h      2013-05-31 14:47:11.000000000 +0000
12995 @@ -0,0 +1,24 @@
12996 +#ifndef _UAPI_VS_DEBUG_CMD_H
12997 +#define _UAPI_VS_DEBUG_CMD_H
12998 +
12999 +
13000 +/* debug commands */
13001 +
13002 +#define VCMD_dump_history      VC_CMD(DEBUG, 1, 0)
13003 +
13004 +#define VCMD_read_history      VC_CMD(DEBUG, 5, 0)
13005 +#define VCMD_read_monitor      VC_CMD(DEBUG, 6, 0)
13006 +
13007 +struct  vcmd_read_history_v0 {
13008 +       uint32_t index;
13009 +       uint32_t count;
13010 +       char __user *data;
13011 +};
13012 +
13013 +struct  vcmd_read_monitor_v0 {
13014 +       uint32_t index;
13015 +       uint32_t count;
13016 +       char __user *data;
13017 +};
13018 +
13019 +#endif /* _UAPI_VS_DEBUG_CMD_H */
13020 diff -NurpP --minimal linux-3.9.4/include/uapi/vserver/device.h linux-3.9.4-vs2.3.6.2/include/uapi/vserver/device.h
13021 --- linux-3.9.4/include/uapi/vserver/device.h   1970-01-01 00:00:00.000000000 +0000
13022 +++ linux-3.9.4-vs2.3.6.2/include/uapi/vserver/device.h 2013-05-31 14:47:11.000000000 +0000
13023 @@ -0,0 +1,12 @@
13024 +#ifndef _UAPI_VS_DEVICE_H
13025 +#define _UAPI_VS_DEVICE_H
13026 +
13027 +
13028 +#define DATTR_CREATE   0x00000001
13029 +#define DATTR_OPEN     0x00000002
13030 +
13031 +#define DATTR_REMAP    0x00000010
13032 +
13033 +#define DATTR_MASK     0x00000013
13034 +
13035 +#endif /* _UAPI_VS_DEVICE_H */
13036 diff -NurpP --minimal linux-3.9.4/include/uapi/vserver/device_cmd.h linux-3.9.4-vs2.3.6.2/include/uapi/vserver/device_cmd.h
13037 --- linux-3.9.4/include/uapi/vserver/device_cmd.h       1970-01-01 00:00:00.000000000 +0000
13038 +++ linux-3.9.4-vs2.3.6.2/include/uapi/vserver/device_cmd.h     2013-05-31 14:47:11.000000000 +0000
13039 @@ -0,0 +1,16 @@
13040 +#ifndef _UAPI_VS_DEVICE_CMD_H
13041 +#define _UAPI_VS_DEVICE_CMD_H
13042 +
13043 +
13044 +/*  device vserver commands */
13045 +
13046 +#define VCMD_set_mapping       VC_CMD(DEVICE, 1, 0)
13047 +#define VCMD_unset_mapping     VC_CMD(DEVICE, 2, 0)
13048 +
13049 +struct vcmd_set_mapping_v0 {
13050 +       const char __user *device;
13051 +       const char __user *target;
13052 +       uint32_t flags;
13053 +};
13054 +
13055 +#endif /* _UAPI_VS_DEVICE_CMD_H */
13056 diff -NurpP --minimal linux-3.9.4/include/uapi/vserver/dlimit_cmd.h linux-3.9.4-vs2.3.6.2/include/uapi/vserver/dlimit_cmd.h
13057 --- linux-3.9.4/include/uapi/vserver/dlimit_cmd.h       1970-01-01 00:00:00.000000000 +0000
13058 +++ linux-3.9.4-vs2.3.6.2/include/uapi/vserver/dlimit_cmd.h     2013-05-31 14:47:11.000000000 +0000
13059 @@ -0,0 +1,67 @@
13060 +#ifndef _UAPI_VS_DLIMIT_CMD_H
13061 +#define _UAPI_VS_DLIMIT_CMD_H
13062 +
13063 +
13064 +/*  dlimit vserver commands */
13065 +
13066 +#define VCMD_add_dlimit                VC_CMD(DLIMIT, 1, 0)
13067 +#define VCMD_rem_dlimit                VC_CMD(DLIMIT, 2, 0)
13068 +
13069 +#define VCMD_set_dlimit                VC_CMD(DLIMIT, 5, 0)
13070 +#define VCMD_get_dlimit                VC_CMD(DLIMIT, 6, 0)
13071 +
13072 +struct vcmd_ctx_dlimit_base_v0 {
13073 +       const char __user *name;
13074 +       uint32_t flags;
13075 +};
13076 +
13077 +struct vcmd_ctx_dlimit_v0 {
13078 +       const char __user *name;
13079 +       uint32_t space_used;                    /* used space in kbytes */
13080 +       uint32_t space_total;                   /* maximum space in kbytes */
13081 +       uint32_t inodes_used;                   /* used inodes */
13082 +       uint32_t inodes_total;                  /* maximum inodes */
13083 +       uint32_t reserved;                      /* reserved for root in % */
13084 +       uint32_t flags;
13085 +};
13086 +
13087 +#define CDLIM_UNSET            ((uint32_t)0UL)
13088 +#define CDLIM_INFINITY         ((uint32_t)~0UL)
13089 +#define CDLIM_KEEP             ((uint32_t)~1UL)
13090 +
13091 +#define DLIME_UNIT     0
13092 +#define DLIME_KILO     1
13093 +#define DLIME_MEGA     2
13094 +#define DLIME_GIGA     3
13095 +
13096 +#define DLIMF_SHIFT    0x10
13097 +
13098 +#define DLIMS_USED     0
13099 +#define DLIMS_TOTAL    2
13100 +
13101 +static inline
13102 +uint64_t dlimit_space_32to64(uint32_t val, uint32_t flags, int shift)
13103 +{
13104 +       int exp = (flags & DLIMF_SHIFT) ?
13105 +               (flags >> shift) & DLIME_GIGA : DLIME_KILO;
13106 +       return ((uint64_t)val) << (10 * exp);
13107 +}
13108 +
13109 +static inline
13110 +uint32_t dlimit_space_64to32(uint64_t val, uint32_t *flags, int shift)
13111 +{
13112 +       int exp = 0;
13113 +
13114 +       if (*flags & DLIMF_SHIFT) {
13115 +               while (val > (1LL << 32) && (exp < 3)) {
13116 +                       val >>= 10;
13117 +                       exp++;
13118 +               }
13119 +               *flags &= ~(DLIME_GIGA << shift);
13120 +               *flags |= exp << shift;
13121 +       } else
13122 +               val >>= 10;
13123 +       return val;
13124 +}
13125 +
13126 +#endif /* _UAPI_VS_DLIMIT_CMD_H */
13127 diff -NurpP --minimal linux-3.9.4/include/uapi/vserver/inode.h linux-3.9.4-vs2.3.6.2/include/uapi/vserver/inode.h
13128 --- linux-3.9.4/include/uapi/vserver/inode.h    1970-01-01 00:00:00.000000000 +0000
13129 +++ linux-3.9.4-vs2.3.6.2/include/uapi/vserver/inode.h  2013-05-31 14:47:11.000000000 +0000
13130 @@ -0,0 +1,23 @@
13131 +#ifndef _UAPI_VS_INODE_H
13132 +#define _UAPI_VS_INODE_H
13133 +
13134 +
13135 +#define IATTR_TAG      0x01000000
13136 +
13137 +#define IATTR_ADMIN    0x00000001
13138 +#define IATTR_WATCH    0x00000002
13139 +#define IATTR_HIDE     0x00000004
13140 +#define IATTR_FLAGS    0x00000007
13141 +
13142 +#define IATTR_BARRIER  0x00010000
13143 +#define IATTR_IXUNLINK 0x00020000
13144 +#define IATTR_IMMUTABLE 0x00040000
13145 +#define IATTR_COW      0x00080000
13146 +
13147 +
13148 +/* inode ioctls */
13149 +
13150 +#define FIOC_GETXFLG   _IOR('x', 5, long)
13151 +#define FIOC_SETXFLG   _IOW('x', 6, long)
13152 +
13153 +#endif /* _UAPI_VS_INODE_H */
13154 diff -NurpP --minimal linux-3.9.4/include/uapi/vserver/inode_cmd.h linux-3.9.4-vs2.3.6.2/include/uapi/vserver/inode_cmd.h
13155 --- linux-3.9.4/include/uapi/vserver/inode_cmd.h        1970-01-01 00:00:00.000000000 +0000
13156 +++ linux-3.9.4-vs2.3.6.2/include/uapi/vserver/inode_cmd.h      2013-05-31 14:47:11.000000000 +0000
13157 @@ -0,0 +1,26 @@
13158 +#ifndef _UAPI_VS_INODE_CMD_H
13159 +#define _UAPI_VS_INODE_CMD_H
13160 +
13161 +
13162 +/*  inode vserver commands */
13163 +
13164 +#define VCMD_get_iattr         VC_CMD(INODE, 1, 1)
13165 +#define VCMD_set_iattr         VC_CMD(INODE, 2, 1)
13166 +
13167 +#define VCMD_fget_iattr                VC_CMD(INODE, 3, 0)
13168 +#define VCMD_fset_iattr                VC_CMD(INODE, 4, 0)
13169 +
13170 +struct vcmd_ctx_iattr_v1 {
13171 +       const char __user *name;
13172 +       uint32_t tag;
13173 +       uint32_t flags;
13174 +       uint32_t mask;
13175 +};
13176 +
13177 +struct vcmd_ctx_fiattr_v0 {
13178 +       uint32_t tag;
13179 +       uint32_t flags;
13180 +       uint32_t mask;
13181 +};
13182 +
13183 +#endif /* _UAPI_VS_INODE_CMD_H */
13184 diff -NurpP --minimal linux-3.9.4/include/uapi/vserver/limit.h linux-3.9.4-vs2.3.6.2/include/uapi/vserver/limit.h
13185 --- linux-3.9.4/include/uapi/vserver/limit.h    1970-01-01 00:00:00.000000000 +0000
13186 +++ linux-3.9.4-vs2.3.6.2/include/uapi/vserver/limit.h  2013-05-31 14:47:11.000000000 +0000
13187 @@ -0,0 +1,14 @@
13188 +#ifndef _UAPI_VS_LIMIT_H
13189 +#define _UAPI_VS_LIMIT_H
13190 +
13191 +
13192 +#define VLIMIT_NSOCK   16
13193 +#define VLIMIT_OPENFD  17
13194 +#define VLIMIT_ANON    18
13195 +#define VLIMIT_SHMEM   19
13196 +#define VLIMIT_SEMARY  20
13197 +#define VLIMIT_NSEMS   21
13198 +#define VLIMIT_DENTRY  22
13199 +#define VLIMIT_MAPPED  23
13200 +
13201 +#endif /* _UAPI_VS_LIMIT_H */
13202 diff -NurpP --minimal linux-3.9.4/include/uapi/vserver/limit_cmd.h linux-3.9.4-vs2.3.6.2/include/uapi/vserver/limit_cmd.h
13203 --- linux-3.9.4/include/uapi/vserver/limit_cmd.h        1970-01-01 00:00:00.000000000 +0000
13204 +++ linux-3.9.4-vs2.3.6.2/include/uapi/vserver/limit_cmd.h      2013-05-31 14:47:11.000000000 +0000
13205 @@ -0,0 +1,40 @@
13206 +#ifndef _UAPI_VS_LIMIT_CMD_H
13207 +#define _UAPI_VS_LIMIT_CMD_H
13208 +
13209 +
13210 +/*  rlimit vserver commands */
13211 +
13212 +#define VCMD_get_rlimit                VC_CMD(RLIMIT, 1, 0)
13213 +#define VCMD_set_rlimit                VC_CMD(RLIMIT, 2, 0)
13214 +#define VCMD_get_rlimit_mask   VC_CMD(RLIMIT, 3, 0)
13215 +#define VCMD_reset_hits                VC_CMD(RLIMIT, 7, 0)
13216 +#define VCMD_reset_minmax      VC_CMD(RLIMIT, 9, 0)
13217 +
13218 +struct vcmd_ctx_rlimit_v0 {
13219 +       uint32_t id;
13220 +       uint64_t minimum;
13221 +       uint64_t softlimit;
13222 +       uint64_t maximum;
13223 +};
13224 +
13225 +struct vcmd_ctx_rlimit_mask_v0 {
13226 +       uint32_t minimum;
13227 +       uint32_t softlimit;
13228 +       uint32_t maximum;
13229 +};
13230 +
13231 +#define VCMD_rlimit_stat       VC_CMD(VSTAT, 1, 0)
13232 +
13233 +struct vcmd_rlimit_stat_v0 {
13234 +       uint32_t id;
13235 +       uint32_t hits;
13236 +       uint64_t value;
13237 +       uint64_t minimum;
13238 +       uint64_t maximum;
13239 +};
13240 +
13241 +#define CRLIM_UNSET            (0ULL)
13242 +#define CRLIM_INFINITY         (~0ULL)
13243 +#define CRLIM_KEEP             (~1ULL)
13244 +
13245 +#endif /* _UAPI_VS_LIMIT_CMD_H */
13246 diff -NurpP --minimal linux-3.9.4/include/uapi/vserver/monitor.h linux-3.9.4-vs2.3.6.2/include/uapi/vserver/monitor.h
13247 --- linux-3.9.4/include/uapi/vserver/monitor.h  1970-01-01 00:00:00.000000000 +0000
13248 +++ linux-3.9.4-vs2.3.6.2/include/uapi/vserver/monitor.h        2013-05-31 14:47:11.000000000 +0000
13249 @@ -0,0 +1,96 @@
13250 +#ifndef _UAPI_VS_MONITOR_H
13251 +#define _UAPI_VS_MONITOR_H
13252 +
13253 +#include <linux/types.h>
13254 +
13255 +
13256 +enum {
13257 +       VXM_UNUSED = 0,
13258 +
13259 +       VXM_SYNC = 0x10,
13260 +
13261 +       VXM_UPDATE = 0x20,
13262 +       VXM_UPDATE_1,
13263 +       VXM_UPDATE_2,
13264 +
13265 +       VXM_RQINFO_1 = 0x24,
13266 +       VXM_RQINFO_2,
13267 +
13268 +       VXM_ACTIVATE = 0x40,
13269 +       VXM_DEACTIVATE,
13270 +       VXM_IDLE,
13271 +
13272 +       VXM_HOLD = 0x44,
13273 +       VXM_UNHOLD,
13274 +
13275 +       VXM_MIGRATE = 0x48,
13276 +       VXM_RESCHED,
13277 +
13278 +       /* all other bits are flags */
13279 +       VXM_SCHED = 0x80,
13280 +};
13281 +
13282 +struct _vxm_update_1 {
13283 +       uint32_t tokens_max;
13284 +       uint32_t fill_rate;
13285 +       uint32_t interval;
13286 +};
13287 +
13288 +struct _vxm_update_2 {
13289 +       uint32_t tokens_min;
13290 +       uint32_t fill_rate;
13291 +       uint32_t interval;
13292 +};
13293 +
13294 +struct _vxm_rqinfo_1 {
13295 +       uint16_t running;
13296 +       uint16_t onhold;
13297 +       uint16_t iowait;
13298 +       uint16_t uintr;
13299 +       uint32_t idle_tokens;
13300 +};
13301 +
13302 +struct _vxm_rqinfo_2 {
13303 +       uint32_t norm_time;
13304 +       uint32_t idle_time;
13305 +       uint32_t idle_skip;
13306 +};
13307 +
13308 +struct _vxm_sched {
13309 +       uint32_t tokens;
13310 +       uint32_t norm_time;
13311 +       uint32_t idle_time;
13312 +};
13313 +
13314 +struct _vxm_task {
13315 +       uint16_t pid;
13316 +       uint16_t state;
13317 +};
13318 +
13319 +struct _vxm_event {
13320 +       uint32_t jif;
13321 +       union {
13322 +               uint32_t seq;
13323 +               uint32_t sec;
13324 +       };
13325 +       union {
13326 +               uint32_t tokens;
13327 +               uint32_t nsec;
13328 +               struct _vxm_task tsk;
13329 +       };
13330 +};
13331 +
13332 +struct _vx_mon_entry {
13333 +       uint16_t type;
13334 +       uint16_t xid;
13335 +       union {
13336 +               struct _vxm_event ev;
13337 +               struct _vxm_sched sd;
13338 +               struct _vxm_update_1 u1;
13339 +               struct _vxm_update_2 u2;
13340 +               struct _vxm_rqinfo_1 q1;
13341 +               struct _vxm_rqinfo_2 q2;
13342 +       };
13343 +};
13344 +
13345 +#endif /* _UAPI_VS_MONITOR_H */
13346 diff -NurpP --minimal linux-3.9.4/include/uapi/vserver/network.h linux-3.9.4-vs2.3.6.2/include/uapi/vserver/network.h
13347 --- linux-3.9.4/include/uapi/vserver/network.h  1970-01-01 00:00:00.000000000 +0000
13348 +++ linux-3.9.4-vs2.3.6.2/include/uapi/vserver/network.h        2013-05-31 14:47:11.000000000 +0000
13349 @@ -0,0 +1,76 @@
13350 +#ifndef _UAPI_VS_NETWORK_H
13351 +#define _UAPI_VS_NETWORK_H
13352 +
13353 +#include <linux/types.h>
13354 +
13355 +
13356 +#define MAX_N_CONTEXT  65535   /* Arbitrary limit */
13357 +
13358 +
13359 +/* network flags */
13360 +
13361 +#define NXF_INFO_PRIVATE       0x00000008
13362 +
13363 +#define NXF_SINGLE_IP          0x00000100
13364 +#define NXF_LBACK_REMAP                0x00000200
13365 +#define NXF_LBACK_ALLOW                0x00000400
13366 +
13367 +#define NXF_HIDE_NETIF         0x02000000
13368 +#define NXF_HIDE_LBACK         0x04000000
13369 +
13370 +#define NXF_STATE_SETUP                (1ULL << 32)
13371 +#define NXF_STATE_ADMIN                (1ULL << 34)
13372 +
13373 +#define NXF_SC_HELPER          (1ULL << 36)
13374 +#define NXF_PERSISTENT         (1ULL << 38)
13375 +
13376 +#define NXF_ONE_TIME           (0x0005ULL << 32)
13377 +
13378 +
13379 +#define        NXF_INIT_SET            (__nxf_init_set())
13380 +
13381 +static inline uint64_t __nxf_init_set(void) {
13382 +       return    NXF_STATE_ADMIN
13383 +#ifdef CONFIG_VSERVER_AUTO_LBACK
13384 +               | NXF_LBACK_REMAP
13385 +               | NXF_HIDE_LBACK
13386 +#endif
13387 +#ifdef CONFIG_VSERVER_AUTO_SINGLE
13388 +               | NXF_SINGLE_IP
13389 +#endif
13390 +               | NXF_HIDE_NETIF;
13391 +}
13392 +
13393 +
13394 +/* network caps */
13395 +
13396 +#define NXC_TUN_CREATE         0x00000001
13397 +
13398 +#define NXC_RAW_ICMP           0x00000100
13399 +
13400 +#define NXC_MULTICAST          0x00001000
13401 +
13402 +
13403 +/* address types */
13404 +
13405 +#define NXA_TYPE_IPV4          0x0001
13406 +#define NXA_TYPE_IPV6          0x0002
13407 +
13408 +#define NXA_TYPE_NONE          0x0000
13409 +#define NXA_TYPE_ANY           0x00FF
13410 +
13411 +#define NXA_TYPE_ADDR          0x0010
13412 +#define NXA_TYPE_MASK          0x0020
13413 +#define NXA_TYPE_RANGE         0x0040
13414 +
13415 +#define NXA_MASK_ALL           (NXA_TYPE_ADDR | NXA_TYPE_MASK | NXA_TYPE_RANGE)
13416 +
13417 +#define NXA_MOD_BCAST          0x0100
13418 +#define NXA_MOD_LBACK          0x0200
13419 +
13420 +#define NXA_LOOPBACK           0x1000
13421 +
13422 +#define NXA_MASK_BIND          (NXA_MASK_ALL | NXA_MOD_BCAST | NXA_MOD_LBACK)
13423 +#define NXA_MASK_SHOW          (NXA_MASK_ALL | NXA_LOOPBACK)
13424 +
13425 +#endif /* _UAPI_VS_NETWORK_H */
13426 diff -NurpP --minimal linux-3.9.4/include/uapi/vserver/network_cmd.h linux-3.9.4-vs2.3.6.2/include/uapi/vserver/network_cmd.h
13427 --- linux-3.9.4/include/uapi/vserver/network_cmd.h      1970-01-01 00:00:00.000000000 +0000
13428 +++ linux-3.9.4-vs2.3.6.2/include/uapi/vserver/network_cmd.h    2013-05-31 14:47:11.000000000 +0000
13429 @@ -0,0 +1,123 @@
13430 +#ifndef _UAPI_VS_NETWORK_CMD_H
13431 +#define _UAPI_VS_NETWORK_CMD_H
13432 +
13433 +
13434 +/* vinfo commands */
13435 +
13436 +#define VCMD_task_nid          VC_CMD(VINFO, 2, 0)
13437 +
13438 +
13439 +#define VCMD_nx_info           VC_CMD(VINFO, 6, 0)
13440 +
13441 +struct vcmd_nx_info_v0 {
13442 +       uint32_t nid;
13443 +       /* more to come */
13444 +};
13445 +
13446 +
13447 +#include <linux/in.h>
13448 +#include <linux/in6.h>
13449 +
13450 +#define VCMD_net_create_v0     VC_CMD(VNET, 1, 0)
13451 +#define VCMD_net_create                VC_CMD(VNET, 1, 1)
13452 +
13453 +struct  vcmd_net_create {
13454 +       uint64_t flagword;
13455 +};
13456 +
13457 +#define VCMD_net_migrate       VC_CMD(NETMIG, 1, 0)
13458 +
13459 +#define VCMD_net_add           VC_CMD(NETALT, 1, 0)
13460 +#define VCMD_net_remove                VC_CMD(NETALT, 2, 0)
13461 +
13462 +struct vcmd_net_addr_v0 {
13463 +       uint16_t type;
13464 +       uint16_t count;
13465 +       struct in_addr ip[4];
13466 +       struct in_addr mask[4];
13467 +};
13468 +
13469 +#define VCMD_net_add_ipv4_v1   VC_CMD(NETALT, 1, 1)
13470 +#define VCMD_net_rem_ipv4_v1   VC_CMD(NETALT, 2, 1)
13471 +
13472 +struct vcmd_net_addr_ipv4_v1 {
13473 +       uint16_t type;
13474 +       uint16_t flags;
13475 +       struct in_addr ip;
13476 +       struct in_addr mask;
13477 +};
13478 +
13479 +#define VCMD_net_add_ipv4      VC_CMD(NETALT, 1, 2)
13480 +#define VCMD_net_rem_ipv4      VC_CMD(NETALT, 2, 2)
13481 +
13482 +struct vcmd_net_addr_ipv4_v2 {
13483 +       uint16_t type;
13484 +       uint16_t flags;
13485 +       struct in_addr ip;
13486 +       struct in_addr ip2;
13487 +       struct in_addr mask;
13488 +};
13489 +
13490 +#define VCMD_net_add_ipv6      VC_CMD(NETALT, 3, 1)
13491 +#define VCMD_net_remove_ipv6   VC_CMD(NETALT, 4, 1)
13492 +
13493 +struct vcmd_net_addr_ipv6_v1 {
13494 +       uint16_t type;
13495 +       uint16_t flags;
13496 +       uint32_t prefix;
13497 +       struct in6_addr ip;
13498 +       struct in6_addr mask;
13499 +};
13500 +
13501 +#define VCMD_add_match_ipv4    VC_CMD(NETALT, 5, 0)
13502 +#define VCMD_get_match_ipv4    VC_CMD(NETALT, 6, 0)
13503 +
13504 +struct vcmd_match_ipv4_v0 {
13505 +       uint16_t type;
13506 +       uint16_t flags;
13507 +       uint16_t parent;
13508 +       uint16_t prefix;
13509 +       struct in_addr ip;
13510 +       struct in_addr ip2;
13511 +       struct in_addr mask;
13512 +};
13513 +
13514 +#define VCMD_add_match_ipv6    VC_CMD(NETALT, 7, 0)
13515 +#define VCMD_get_match_ipv6    VC_CMD(NETALT, 8, 0)
13516 +
13517 +struct vcmd_match_ipv6_v0 {
13518 +       uint16_t type;
13519 +       uint16_t flags;
13520 +       uint16_t parent;
13521 +       uint16_t prefix;
13522 +       struct in6_addr ip;
13523 +       struct in6_addr ip2;
13524 +       struct in6_addr mask;
13525 +};
13526 +
13527 +
13528 +
13529 +
13530 +/* flag commands */
13531 +
13532 +#define VCMD_get_nflags                VC_CMD(FLAGS, 5, 0)
13533 +#define VCMD_set_nflags                VC_CMD(FLAGS, 6, 0)
13534 +
13535 +struct vcmd_net_flags_v0 {
13536 +       uint64_t flagword;
13537 +       uint64_t mask;
13538 +};
13539 +
13540 +
13541 +
13542 +/* network caps commands */
13543 +
13544 +#define VCMD_get_ncaps         VC_CMD(FLAGS, 7, 0)
13545 +#define VCMD_set_ncaps         VC_CMD(FLAGS, 8, 0)
13546 +
13547 +struct vcmd_net_caps_v0 {
13548 +       uint64_t ncaps;
13549 +       uint64_t cmask;
13550 +};
13551 +
13552 +#endif /* _UAPI_VS_NETWORK_CMD_H */
13553 diff -NurpP --minimal linux-3.9.4/include/uapi/vserver/sched_cmd.h linux-3.9.4-vs2.3.6.2/include/uapi/vserver/sched_cmd.h
13554 --- linux-3.9.4/include/uapi/vserver/sched_cmd.h        1970-01-01 00:00:00.000000000 +0000
13555 +++ linux-3.9.4-vs2.3.6.2/include/uapi/vserver/sched_cmd.h      2013-05-31 14:47:11.000000000 +0000
13556 @@ -0,0 +1,13 @@
13557 +#ifndef _UAPI_VS_SCHED_CMD_H
13558 +#define _UAPI_VS_SCHED_CMD_H
13559 +
13560 +
13561 +struct vcmd_prio_bias {
13562 +       int32_t cpu_id;
13563 +       int32_t prio_bias;
13564 +};
13565 +
13566 +#define VCMD_set_prio_bias     VC_CMD(SCHED, 4, 0)
13567 +#define VCMD_get_prio_bias     VC_CMD(SCHED, 5, 0)
13568 +
13569 +#endif /* _UAPI_VS_SCHED_CMD_H */
13570 diff -NurpP --minimal linux-3.9.4/include/uapi/vserver/signal_cmd.h linux-3.9.4-vs2.3.6.2/include/uapi/vserver/signal_cmd.h
13571 --- linux-3.9.4/include/uapi/vserver/signal_cmd.h       1970-01-01 00:00:00.000000000 +0000
13572 +++ linux-3.9.4-vs2.3.6.2/include/uapi/vserver/signal_cmd.h     2013-05-31 14:47:11.000000000 +0000
13573 @@ -0,0 +1,31 @@
13574 +#ifndef _UAPI_VS_SIGNAL_CMD_H
13575 +#define _UAPI_VS_SIGNAL_CMD_H
13576 +
13577 +
13578 +/*  signalling vserver commands */
13579 +
13580 +#define VCMD_ctx_kill          VC_CMD(PROCTRL, 1, 0)
13581 +#define VCMD_wait_exit         VC_CMD(EVENT, 99, 0)
13582 +
13583 +struct vcmd_ctx_kill_v0 {
13584 +       int32_t pid;
13585 +       int32_t sig;
13586 +};
13587 +
13588 +struct vcmd_wait_exit_v0 {
13589 +       int32_t reboot_cmd;
13590 +       int32_t exit_code;
13591 +};
13592 +
13593 +
13594 +/*  process alteration commands */
13595 +
13596 +#define VCMD_get_pflags                VC_CMD(PROCALT, 5, 0)
13597 +#define VCMD_set_pflags                VC_CMD(PROCALT, 6, 0)
13598 +
13599 +struct vcmd_pflags_v0 {
13600 +       uint32_t flagword;
13601 +       uint32_t mask;
13602 +};
13603 +
13604 +#endif /* _UAPI_VS_SIGNAL_CMD_H */
13605 diff -NurpP --minimal linux-3.9.4/include/uapi/vserver/space_cmd.h linux-3.9.4-vs2.3.6.2/include/uapi/vserver/space_cmd.h
13606 --- linux-3.9.4/include/uapi/vserver/space_cmd.h        1970-01-01 00:00:00.000000000 +0000
13607 +++ linux-3.9.4-vs2.3.6.2/include/uapi/vserver/space_cmd.h      2013-05-31 14:47:11.000000000 +0000
13608 @@ -0,0 +1,28 @@
13609 +#ifndef _UAPI_VS_SPACE_CMD_H
13610 +#define _UAPI_VS_SPACE_CMD_H
13611 +
13612 +
13613 +#define VCMD_enter_space_v0    VC_CMD(PROCALT, 1, 0)
13614 +#define VCMD_enter_space_v1    VC_CMD(PROCALT, 1, 1)
13615 +#define VCMD_enter_space       VC_CMD(PROCALT, 1, 2)
13616 +
13617 +#define VCMD_set_space_v0      VC_CMD(PROCALT, 3, 0)
13618 +#define VCMD_set_space_v1      VC_CMD(PROCALT, 3, 1)
13619 +#define VCMD_set_space         VC_CMD(PROCALT, 3, 2)
13620 +
13621 +#define VCMD_get_space_mask_v0 VC_CMD(PROCALT, 4, 0)
13622 +
13623 +#define VCMD_get_space_mask    VC_CMD(VSPACE, 0, 1)
13624 +#define VCMD_get_space_default VC_CMD(VSPACE, 1, 0)
13625 +
13626 +
13627 +struct vcmd_space_mask_v1 {
13628 +       uint64_t mask;
13629 +};
13630 +
13631 +struct vcmd_space_mask_v2 {
13632 +       uint64_t mask;
13633 +       uint32_t index;
13634 +};
13635 +
13636 +#endif /* _UAPI_VS_SPACE_CMD_H */
13637 diff -NurpP --minimal linux-3.9.4/include/uapi/vserver/switch.h linux-3.9.4-vs2.3.6.2/include/uapi/vserver/switch.h
13638 --- linux-3.9.4/include/uapi/vserver/switch.h   1970-01-01 00:00:00.000000000 +0000
13639 +++ linux-3.9.4-vs2.3.6.2/include/uapi/vserver/switch.h 2013-05-31 14:47:11.000000000 +0000
13640 @@ -0,0 +1,90 @@
13641 +#ifndef _UAPI_VS_SWITCH_H
13642 +#define _UAPI_VS_SWITCH_H
13643 +
13644 +#include <linux/types.h>
13645 +
13646 +
13647 +#define VC_CATEGORY(c)         (((c) >> 24) & 0x3F)
13648 +#define VC_COMMAND(c)          (((c) >> 16) & 0xFF)
13649 +#define VC_VERSION(c)          ((c) & 0xFFF)
13650 +
13651 +#define VC_CMD(c, i, v)                ((((VC_CAT_ ## c) & 0x3F) << 24) \
13652 +                               | (((i) & 0xFF) << 16) | ((v) & 0xFFF))
13653 +
13654 +/*
13655 +
13656 +  Syscall Matrix V2.8
13657 +
13658 +        |VERSION|CREATE |MODIFY |MIGRATE|CONTROL|EXPERIM| |SPECIAL|SPECIAL|
13659 +        |STATS  |DESTROY|ALTER  |CHANGE |LIMIT  |TEST   | |       |       |
13660 +        |INFO   |SETUP  |       |MOVE   |       |       | |       |       |
13661 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13662 +  SYSTEM |VERSION|VSETUP |VHOST  |       |       |       | |DEVICE |       |
13663 +  HOST   |     00|     01|     02|     03|     04|     05| |     06|     07|
13664 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13665 +  CPU    |       |VPROC  |PROCALT|PROCMIG|PROCTRL|       | |SCHED. |       |
13666 +  PROCESS|     08|     09|     10|     11|     12|     13| |     14|     15|
13667 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13668 +  MEMORY |       |       |       |       |MEMCTRL|       | |SWAP   |       |
13669 +        |     16|     17|     18|     19|     20|     21| |     22|     23|
13670 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13671 +  NETWORK|       |VNET   |NETALT |NETMIG |NETCTL |       | |SERIAL |       |
13672 +        |     24|     25|     26|     27|     28|     29| |     30|     31|
13673 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13674 +  DISK   |       |       |       |TAGMIG |DLIMIT |       | |INODE  |       |
13675 +  VFS    |     32|     33|     34|     35|     36|     37| |     38|     39|
13676 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13677 +  OTHER  |VSTAT  |       |       |       |       |       | |VINFO  |       |
13678 +        |     40|     41|     42|     43|     44|     45| |     46|     47|
13679 +  =======+=======+=======+=======+=======+=======+=======+ +=======+=======+
13680 +  SPECIAL|EVENT  |       |       |       |FLAGS  |       | |VSPACE |       |
13681 +        |     48|     49|     50|     51|     52|     53| |     54|     55|
13682 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13683 +  SPECIAL|DEBUG  |       |       |       |RLIMIT |SYSCALL| |       |COMPAT |
13684 +        |     56|     57|     58|     59|     60|TEST 61| |     62|     63|
13685 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13686 +
13687 +*/
13688 +
13689 +#define VC_CAT_VERSION         0
13690 +
13691 +#define VC_CAT_VSETUP          1
13692 +#define VC_CAT_VHOST           2
13693 +
13694 +#define VC_CAT_DEVICE          6
13695 +
13696 +#define VC_CAT_VPROC           9
13697 +#define VC_CAT_PROCALT         10
13698 +#define VC_CAT_PROCMIG         11
13699 +#define VC_CAT_PROCTRL         12
13700 +
13701 +#define VC_CAT_SCHED           14
13702 +#define VC_CAT_MEMCTRL         20
13703 +
13704 +#define VC_CAT_VNET            25
13705 +#define VC_CAT_NETALT          26
13706 +#define VC_CAT_NETMIG          27
13707 +#define VC_CAT_NETCTRL         28
13708 +
13709 +#define VC_CAT_TAGMIG          35
13710 +#define VC_CAT_DLIMIT          36
13711 +#define VC_CAT_INODE           38
13712 +
13713 +#define VC_CAT_VSTAT           40
13714 +#define VC_CAT_VINFO           46
13715 +#define VC_CAT_EVENT           48
13716 +
13717 +#define VC_CAT_FLAGS           52
13718 +#define VC_CAT_VSPACE          54
13719 +#define VC_CAT_DEBUG           56
13720 +#define VC_CAT_RLIMIT          60
13721 +
13722 +#define VC_CAT_SYSTEST         61
13723 +#define VC_CAT_COMPAT          63
13724 +
13725 +/*  query version */
13726 +
13727 +#define VCMD_get_version       VC_CMD(VERSION, 0, 0)
13728 +#define VCMD_get_vci           VC_CMD(VERSION, 1, 0)
13729 +
13730 +#endif /* _UAPI_VS_SWITCH_H */
13731 diff -NurpP --minimal linux-3.9.4/include/uapi/vserver/tag_cmd.h linux-3.9.4-vs2.3.6.2/include/uapi/vserver/tag_cmd.h
13732 --- linux-3.9.4/include/uapi/vserver/tag_cmd.h  1970-01-01 00:00:00.000000000 +0000
13733 +++ linux-3.9.4-vs2.3.6.2/include/uapi/vserver/tag_cmd.h        2013-05-31 14:47:11.000000000 +0000
13734 @@ -0,0 +1,14 @@
13735 +#ifndef _UAPI_VS_TAG_CMD_H
13736 +#define _UAPI_VS_TAG_CMD_H
13737 +
13738 +
13739 +/* vinfo commands */
13740 +
13741 +#define VCMD_task_tag          VC_CMD(VINFO, 3, 0)
13742 +
13743 +
13744 +/* context commands */
13745 +
13746 +#define VCMD_tag_migrate       VC_CMD(TAGMIG, 1, 0)
13747 +
13748 +#endif /* _UAPI_VS_TAG_CMD_H */
13749 diff -NurpP --minimal linux-3.9.4/init/Kconfig linux-3.9.4-vs2.3.6.2/init/Kconfig
13750 --- linux-3.9.4/init/Kconfig    2013-05-31 13:45:29.000000000 +0000
13751 +++ linux-3.9.4-vs2.3.6.2/init/Kconfig  2013-05-31 14:47:11.000000000 +0000
13752 @@ -760,6 +760,7 @@ config NUMA_BALANCING
13753  menuconfig CGROUPS
13754         boolean "Control Group support"
13755         depends on EVENTFD
13756 +       default y
13757         help
13758           This option adds support for grouping sets of processes together, for
13759           use with process control subsystems such as Cpusets, CFS, memory
13760 @@ -1022,6 +1023,7 @@ config IPC_NS
13761  config USER_NS
13762         bool "User namespace"
13763         depends on UIDGID_CONVERTED
13764 +       depends on VSERVER_DISABLED
13765         select UIDGID_STRICT_TYPE_CHECKS
13766  
13767         default n
13768 diff -NurpP --minimal linux-3.9.4/init/main.c linux-3.9.4-vs2.3.6.2/init/main.c
13769 --- linux-3.9.4/init/main.c     2013-05-31 13:45:29.000000000 +0000
13770 +++ linux-3.9.4-vs2.3.6.2/init/main.c   2013-05-31 15:09:17.000000000 +0000
13771 @@ -72,6 +72,7 @@
13772  #include <linux/ptrace.h>
13773  #include <linux/blkdev.h>
13774  #include <linux/elevator.h>
13775 +#include <linux/vserver/percpu.h>
13776  
13777  #include <asm/io.h>
13778  #include <asm/bugs.h>
13779 diff -NurpP --minimal linux-3.9.4/ipc/mqueue.c linux-3.9.4-vs2.3.6.2/ipc/mqueue.c
13780 --- linux-3.9.4/ipc/mqueue.c    2013-05-31 13:45:29.000000000 +0000
13781 +++ linux-3.9.4-vs2.3.6.2/ipc/mqueue.c  2013-05-31 14:47:11.000000000 +0000
13782 @@ -35,6 +35,8 @@
13783  #include <linux/ipc_namespace.h>
13784  #include <linux/user_namespace.h>
13785  #include <linux/slab.h>
13786 +#include <linux/vs_context.h>
13787 +#include <linux/vs_limit.h>
13788  
13789  #include <net/sock.h>
13790  #include "util.h"
13791 @@ -76,6 +78,7 @@ struct mqueue_inode_info {
13792         struct pid* notify_owner;
13793         struct user_namespace *notify_user_ns;
13794         struct user_struct *user;       /* user who created, for accounting */
13795 +       struct vx_info *vxi;
13796         struct sock *notify_sock;
13797         struct sk_buff *notify_cookie;
13798  
13799 @@ -234,6 +237,7 @@ static struct inode *mqueue_get_inode(st
13800         if (S_ISREG(mode)) {
13801                 struct mqueue_inode_info *info;
13802                 unsigned long mq_bytes, mq_treesize;
13803 +               struct vx_info *vxi = current_vx_info();
13804  
13805                 inode->i_fop = &mqueue_file_operations;
13806                 inode->i_size = FILENT_SIZE;
13807 @@ -247,6 +251,7 @@ static struct inode *mqueue_get_inode(st
13808                 info->notify_user_ns = NULL;
13809                 info->qsize = 0;
13810                 info->user = NULL;      /* set when all is ok */
13811 +               info->vxi = NULL;
13812                 info->msg_tree = RB_ROOT;
13813                 info->node_cache = NULL;
13814                 memset(&info->attr, 0, sizeof(info->attr));
13815 @@ -280,17 +285,20 @@ static struct inode *mqueue_get_inode(st
13816  
13817                 spin_lock(&mq_lock);
13818                 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
13819 -                   u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE)) {
13820 +                   u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE) ||
13821 +                   !vx_ipcmsg_avail(vxi, mq_bytes)) {
13822                         spin_unlock(&mq_lock);
13823                         /* mqueue_evict_inode() releases info->messages */
13824                         ret = -EMFILE;
13825                         goto out_inode;
13826                 }
13827                 u->mq_bytes += mq_bytes;
13828 +               vx_ipcmsg_add(vxi, u, mq_bytes);
13829                 spin_unlock(&mq_lock);
13830  
13831                 /* all is ok */
13832                 info->user = get_uid(u);
13833 +               info->vxi = get_vx_info(vxi);
13834         } else if (S_ISDIR(mode)) {
13835                 inc_nlink(inode);
13836                 /* Some things misbehave if size == 0 on a directory */
13837 @@ -402,8 +410,11 @@ static void mqueue_evict_inode(struct in
13838  
13839         user = info->user;
13840         if (user) {
13841 +               struct vx_info *vxi = info->vxi;
13842 +
13843                 spin_lock(&mq_lock);
13844                 user->mq_bytes -= mq_bytes;
13845 +               vx_ipcmsg_sub(vxi, user, mq_bytes);
13846                 /*
13847                  * get_ns_from_inode() ensures that the
13848                  * (ipc_ns = sb->s_fs_info) is either a valid ipc_ns
13849 @@ -413,6 +424,7 @@ static void mqueue_evict_inode(struct in
13850                 if (ipc_ns)
13851                         ipc_ns->mq_queues_count--;
13852                 spin_unlock(&mq_lock);
13853 +               put_vx_info(vxi);
13854                 free_uid(user);
13855         }
13856         if (ipc_ns)
13857 diff -NurpP --minimal linux-3.9.4/ipc/msg.c linux-3.9.4-vs2.3.6.2/ipc/msg.c
13858 --- linux-3.9.4/ipc/msg.c       2013-05-31 13:45:29.000000000 +0000
13859 +++ linux-3.9.4-vs2.3.6.2/ipc/msg.c     2013-05-31 14:47:11.000000000 +0000
13860 @@ -37,6 +37,7 @@
13861  #include <linux/rwsem.h>
13862  #include <linux/nsproxy.h>
13863  #include <linux/ipc_namespace.h>
13864 +#include <linux/vs_base.h>
13865  
13866  #include <asm/current.h>
13867  #include <asm/uaccess.h>
13868 @@ -190,6 +191,7 @@ static int newque(struct ipc_namespace *
13869  
13870         msq->q_perm.mode = msgflg & S_IRWXUGO;
13871         msq->q_perm.key = key;
13872 +       msq->q_perm.xid = vx_current_xid();
13873  
13874         msq->q_perm.security = NULL;
13875         retval = security_msg_queue_alloc(msq);
13876 diff -NurpP --minimal linux-3.9.4/ipc/sem.c linux-3.9.4-vs2.3.6.2/ipc/sem.c
13877 --- linux-3.9.4/ipc/sem.c       2012-12-11 03:30:57.000000000 +0000
13878 +++ linux-3.9.4-vs2.3.6.2/ipc/sem.c     2013-05-31 14:47:11.000000000 +0000
13879 @@ -86,6 +86,8 @@
13880  #include <linux/rwsem.h>
13881  #include <linux/nsproxy.h>
13882  #include <linux/ipc_namespace.h>
13883 +#include <linux/vs_base.h>
13884 +#include <linux/vs_limit.h>
13885  
13886  #include <asm/uaccess.h>
13887  #include "util.h"
13888 @@ -306,6 +308,7 @@ static int newary(struct ipc_namespace *
13889  
13890         sma->sem_perm.mode = (semflg & S_IRWXUGO);
13891         sma->sem_perm.key = key;
13892 +       sma->sem_perm.xid = vx_current_xid();
13893  
13894         sma->sem_perm.security = NULL;
13895         retval = security_sem_alloc(sma);
13896 @@ -321,6 +324,9 @@ static int newary(struct ipc_namespace *
13897                 return id;
13898         }
13899         ns->used_sems += nsems;
13900 +       /* FIXME: obsoleted? */
13901 +       vx_semary_inc(sma);
13902 +       vx_nsems_add(sma, nsems);
13903  
13904         sma->sem_base = (struct sem *) &sma[1];
13905  
13906 @@ -770,6 +776,9 @@ static void freeary(struct ipc_namespace
13907  
13908         wake_up_sem_queue_do(&tasks);
13909         ns->used_sems -= sma->sem_nsems;
13910 +       /* FIXME: obsoleted? */
13911 +       vx_nsems_sub(sma, sma->sem_nsems);
13912 +       vx_semary_dec(sma);
13913         security_sem_free(sma);
13914         ipc_rcu_putref(sma);
13915  }
13916 diff -NurpP --minimal linux-3.9.4/ipc/shm.c linux-3.9.4-vs2.3.6.2/ipc/shm.c
13917 --- linux-3.9.4/ipc/shm.c       2013-05-31 14:22:27.000000000 +0000
13918 +++ linux-3.9.4-vs2.3.6.2/ipc/shm.c     2013-05-31 14:47:11.000000000 +0000
13919 @@ -39,6 +39,8 @@
13920  #include <linux/nsproxy.h>
13921  #include <linux/mount.h>
13922  #include <linux/ipc_namespace.h>
13923 +#include <linux/vs_context.h>
13924 +#include <linux/vs_limit.h>
13925  
13926  #include <asm/uaccess.h>
13927  
13928 @@ -187,7 +189,12 @@ static void shm_open(struct vm_area_stru
13929   */
13930  static void shm_destroy(struct ipc_namespace *ns, struct shmid_kernel *shp)
13931  {
13932 -       ns->shm_tot -= (shp->shm_segsz + PAGE_SIZE - 1) >> PAGE_SHIFT;
13933 +       struct vx_info *vxi = lookup_vx_info(shp->shm_perm.xid);
13934 +       int numpages = (shp->shm_segsz + PAGE_SIZE - 1) >> PAGE_SHIFT;
13935 +
13936 +       vx_ipcshm_sub(vxi, shp, numpages);
13937 +       ns->shm_tot -= numpages;
13938 +
13939         shm_rmid(ns, shp);
13940         shm_unlock(shp);
13941         if (!is_file_hugepages(shp->shm_file))
13942 @@ -197,6 +204,7 @@ static void shm_destroy(struct ipc_names
13943                                                 shp->mlock_user);
13944         fput (shp->shm_file);
13945         security_shm_free(shp);
13946 +       put_vx_info(vxi);
13947         ipc_rcu_putref(shp);
13948  }
13949  
13950 @@ -474,11 +482,15 @@ static int newseg(struct ipc_namespace *
13951         if (ns->shm_tot + numpages > ns->shm_ctlall)
13952                 return -ENOSPC;
13953  
13954 +       if (!vx_ipcshm_avail(current_vx_info(), numpages))
13955 +               return -ENOSPC;
13956 +
13957         shp = ipc_rcu_alloc(sizeof(*shp));
13958         if (!shp)
13959                 return -ENOMEM;
13960  
13961         shp->shm_perm.key = key;
13962 +       shp->shm_perm.xid = vx_current_xid();
13963         shp->shm_perm.mode = (shmflg & S_IRWXUGO);
13964         shp->mlock_user = NULL;
13965  
13966 @@ -544,6 +556,7 @@ static int newseg(struct ipc_namespace *
13967         ns->shm_tot += numpages;
13968         error = shp->shm_perm.id;
13969         shm_unlock(shp);
13970 +       vx_ipcshm_add(current_vx_info(), key, numpages);
13971         return error;
13972  
13973  no_id:
13974 diff -NurpP --minimal linux-3.9.4/kernel/Makefile linux-3.9.4-vs2.3.6.2/kernel/Makefile
13975 --- linux-3.9.4/kernel/Makefile 2013-05-31 14:22:27.000000000 +0000
13976 +++ linux-3.9.4-vs2.3.6.2/kernel/Makefile       2013-05-31 14:47:11.000000000 +0000
13977 @@ -24,6 +24,7 @@ endif
13978  
13979  obj-y += sched/
13980  obj-y += power/
13981 +obj-y += vserver/
13982  
13983  obj-$(CONFIG_CHECKPOINT_RESTORE) += kcmp.o
13984  obj-$(CONFIG_FREEZER) += freezer.o
13985 diff -NurpP --minimal linux-3.9.4/kernel/auditsc.c linux-3.9.4-vs2.3.6.2/kernel/auditsc.c
13986 --- linux-3.9.4/kernel/auditsc.c        2013-05-31 14:22:27.000000000 +0000
13987 +++ linux-3.9.4-vs2.3.6.2/kernel/auditsc.c      2013-05-31 14:47:11.000000000 +0000
13988 @@ -2315,7 +2315,7 @@ int audit_set_loginuid(kuid_t loginuid)
13989         if (audit_loginuid_set(task))
13990                 return -EPERM;
13991  #else /* CONFIG_AUDIT_LOGINUID_IMMUTABLE */
13992 -       if (!capable(CAP_AUDIT_CONTROL))
13993 +       if (!vx_capable(CAP_AUDIT_CONTROL, VXC_AUDIT_CONTROL))
13994                 return -EPERM;
13995  #endif  /* CONFIG_AUDIT_LOGINUID_IMMUTABLE */
13996  
13997 diff -NurpP --minimal linux-3.9.4/kernel/capability.c linux-3.9.4-vs2.3.6.2/kernel/capability.c
13998 --- linux-3.9.4/kernel/capability.c     2013-05-31 13:45:29.000000000 +0000
13999 +++ linux-3.9.4-vs2.3.6.2/kernel/capability.c   2013-05-31 14:47:11.000000000 +0000
14000 @@ -15,6 +15,7 @@
14001  #include <linux/syscalls.h>
14002  #include <linux/pid_namespace.h>
14003  #include <linux/user_namespace.h>
14004 +#include <linux/vs_context.h>
14005  #include <asm/uaccess.h>
14006  
14007  /*
14008 @@ -116,6 +117,7 @@ static int cap_validate_magic(cap_user_h
14009         return 0;
14010  }
14011  
14012 +
14013  /*
14014   * The only thing that can change the capabilities of the current
14015   * process is the current process. As such, we can't be in this code
14016 @@ -349,6 +351,8 @@ bool has_ns_capability_noaudit(struct ta
14017         return (ret == 0);
14018  }
14019  
14020 +#include <linux/vserver/base.h>
14021 +
14022  /**
14023   * has_capability_noaudit - Does a task have a capability (unaudited) in the
14024   * initial user ns
14025 diff -NurpP --minimal linux-3.9.4/kernel/compat.c linux-3.9.4-vs2.3.6.2/kernel/compat.c
14026 --- linux-3.9.4/kernel/compat.c 2013-05-31 13:45:29.000000000 +0000
14027 +++ linux-3.9.4-vs2.3.6.2/kernel/compat.c       2013-05-31 14:47:11.000000000 +0000
14028 @@ -27,6 +27,7 @@
14029  #include <linux/times.h>
14030  #include <linux/ptrace.h>
14031  #include <linux/gfp.h>
14032 +#include <linux/vs_time.h>
14033  
14034  #include <asm/uaccess.h>
14035  
14036 @@ -1059,7 +1060,7 @@ asmlinkage long compat_sys_stime(compat_
14037         if (err)
14038                 return err;
14039  
14040 -       do_settimeofday(&tv);
14041 +       vx_settimeofday(&tv);
14042         return 0;
14043  }
14044  
14045 diff -NurpP --minimal linux-3.9.4/kernel/cred.c linux-3.9.4-vs2.3.6.2/kernel/cred.c
14046 --- linux-3.9.4/kernel/cred.c   2013-02-19 13:58:56.000000000 +0000
14047 +++ linux-3.9.4-vs2.3.6.2/kernel/cred.c 2013-05-31 14:47:11.000000000 +0000
14048 @@ -56,31 +56,6 @@ struct cred init_cred = {
14049         .group_info             = &init_groups,
14050  };
14051  
14052 -static inline void set_cred_subscribers(struct cred *cred, int n)
14053 -{
14054 -#ifdef CONFIG_DEBUG_CREDENTIALS
14055 -       atomic_set(&cred->subscribers, n);
14056 -#endif
14057 -}
14058 -
14059 -static inline int read_cred_subscribers(const struct cred *cred)
14060 -{
14061 -#ifdef CONFIG_DEBUG_CREDENTIALS
14062 -       return atomic_read(&cred->subscribers);
14063 -#else
14064 -       return 0;
14065 -#endif
14066 -}
14067 -
14068 -static inline void alter_cred_subscribers(const struct cred *_cred, int n)
14069 -{
14070 -#ifdef CONFIG_DEBUG_CREDENTIALS
14071 -       struct cred *cred = (struct cred *) _cred;
14072 -
14073 -       atomic_add(n, &cred->subscribers);
14074 -#endif
14075 -}
14076 -
14077  /*
14078   * The RCU callback to actually dispose of a set of credentials
14079   */
14080 @@ -232,21 +207,16 @@ error:
14081   *
14082   * Call commit_creds() or abort_creds() to clean up.
14083   */
14084 -struct cred *prepare_creds(void)
14085 +struct cred *__prepare_creds(const struct cred *old)
14086  {
14087 -       struct task_struct *task = current;
14088 -       const struct cred *old;
14089         struct cred *new;
14090  
14091 -       validate_process_creds();
14092 -
14093         new = kmem_cache_alloc(cred_jar, GFP_KERNEL);
14094         if (!new)
14095                 return NULL;
14096  
14097         kdebug("prepare_creds() alloc %p", new);
14098  
14099 -       old = task->cred;
14100         memcpy(new, old, sizeof(struct cred));
14101  
14102         atomic_set(&new->usage, 1);
14103 @@ -275,6 +245,13 @@ error:
14104         abort_creds(new);
14105         return NULL;
14106  }
14107 +
14108 +struct cred *prepare_creds(void)
14109 +{
14110 +       validate_process_creds();
14111 +
14112 +       return __prepare_creds(current->cred);
14113 +}
14114  EXPORT_SYMBOL(prepare_creds);
14115  
14116  /*
14117 diff -NurpP --minimal linux-3.9.4/kernel/exit.c linux-3.9.4-vs2.3.6.2/kernel/exit.c
14118 --- linux-3.9.4/kernel/exit.c   2013-05-31 13:45:29.000000000 +0000
14119 +++ linux-3.9.4-vs2.3.6.2/kernel/exit.c 2013-05-31 14:47:11.000000000 +0000
14120 @@ -48,6 +48,10 @@
14121  #include <linux/fs_struct.h>
14122  #include <linux/init_task.h>
14123  #include <linux/perf_event.h>
14124 +#include <linux/vs_limit.h>
14125 +#include <linux/vs_context.h>
14126 +#include <linux/vs_network.h>
14127 +#include <linux/vs_pid.h>
14128  #include <trace/events/sched.h>
14129  #include <linux/hw_breakpoint.h>
14130  #include <linux/oom.h>
14131 @@ -514,15 +518,25 @@ static struct task_struct *find_new_reap
14132         __acquires(&tasklist_lock)
14133  {
14134         struct pid_namespace *pid_ns = task_active_pid_ns(father);
14135 -       struct task_struct *thread;
14136 +       struct vx_info *vxi = task_get_vx_info(father);
14137 +       struct task_struct *thread = father;
14138 +       struct task_struct *reaper;
14139  
14140 -       thread = father;
14141         while_each_thread(father, thread) {
14142                 if (thread->flags & PF_EXITING)
14143                         continue;
14144                 if (unlikely(pid_ns->child_reaper == father))
14145                         pid_ns->child_reaper = thread;
14146 -               return thread;
14147 +               reaper = thread;
14148 +               goto out_put;
14149 +       }
14150 +
14151 +       reaper = pid_ns->child_reaper;
14152 +       if (vxi) {
14153 +               BUG_ON(!vxi->vx_reaper);
14154 +               if (vxi->vx_reaper != init_pid_ns.child_reaper &&
14155 +                   vxi->vx_reaper != father)
14156 +                       reaper = vxi->vx_reaper;
14157         }
14158  
14159         if (unlikely(pid_ns->child_reaper == father)) {
14160 @@ -560,7 +574,9 @@ static struct task_struct *find_new_reap
14161                 }
14162         }
14163  
14164 -       return pid_ns->child_reaper;
14165 +out_put:
14166 +       put_vx_info(vxi);
14167 +       return reaper;
14168  }
14169  
14170  /*
14171 @@ -611,10 +627,15 @@ static void forget_original_parent(struc
14172         list_for_each_entry_safe(p, n, &father->children, sibling) {
14173                 struct task_struct *t = p;
14174                 do {
14175 -                       t->real_parent = reaper;
14176 +                       struct task_struct *new_parent = reaper;
14177 +
14178 +                       if (unlikely(p == reaper))
14179 +                               new_parent = task_active_pid_ns(p)->child_reaper;
14180 +
14181 +                       t->real_parent = new_parent;
14182                         if (t->parent == father) {
14183                                 BUG_ON(t->ptrace);
14184 -                               t->parent = t->real_parent;
14185 +                               t->parent = new_parent;
14186                         }
14187                         if (t->pdeath_signal)
14188                                 group_send_sig_info(t->pdeath_signal,
14189 @@ -821,6 +842,9 @@ void do_exit(long code)
14190          */
14191         ptrace_put_breakpoints(tsk);
14192  
14193 +       /* needs to stay before exit_notify() */
14194 +       exit_vx_info_early(tsk, code);
14195 +
14196         exit_notify(tsk, group_dead);
14197  #ifdef CONFIG_NUMA
14198         task_lock(tsk);
14199 @@ -874,10 +898,15 @@ void do_exit(long code)
14200         smp_mb();
14201         raw_spin_unlock_wait(&tsk->pi_lock);
14202  
14203 +       /* needs to stay after exit_notify() */
14204 +       exit_vx_info(tsk, code);
14205 +       exit_nx_info(tsk);
14206 +
14207         /* causes final put_task_struct in finish_task_switch(). */
14208         tsk->state = TASK_DEAD;
14209         tsk->flags |= PF_NOFREEZE;      /* tell freezer to ignore us */
14210         schedule();
14211 +       printk("bad task: %p [%lx]\n", current, current->state);
14212         BUG();
14213         /* Avoid "noreturn function does return".  */
14214         for (;;)
14215 diff -NurpP --minimal linux-3.9.4/kernel/fork.c linux-3.9.4-vs2.3.6.2/kernel/fork.c
14216 --- linux-3.9.4/kernel/fork.c   2013-05-31 13:45:29.000000000 +0000
14217 +++ linux-3.9.4-vs2.3.6.2/kernel/fork.c 2013-05-31 14:47:11.000000000 +0000
14218 @@ -70,6 +70,9 @@
14219  #include <linux/khugepaged.h>
14220  #include <linux/signalfd.h>
14221  #include <linux/uprobes.h>
14222 +#include <linux/vs_context.h>
14223 +#include <linux/vs_network.h>
14224 +#include <linux/vs_limit.h>
14225  
14226  #include <asm/pgtable.h>
14227  #include <asm/pgalloc.h>
14228 @@ -210,6 +213,8 @@ void free_task(struct task_struct *tsk)
14229         arch_release_thread_info(tsk->stack);
14230         free_thread_info(tsk->stack);
14231         rt_mutex_debug_task_free(tsk);
14232 +       clr_vx_info(&tsk->vx_info);
14233 +       clr_nx_info(&tsk->nx_info);
14234         ftrace_graph_exit_task(tsk);
14235         put_seccomp_filter(tsk);
14236         arch_release_task_struct(tsk);
14237 @@ -547,6 +552,7 @@ static struct mm_struct *mm_init(struct
14238         if (likely(!mm_alloc_pgd(mm))) {
14239                 mm->def_flags = 0;
14240                 mmu_notifier_mm_init(mm);
14241 +               set_vx_info(&mm->mm_vx_info, p->vx_info);
14242                 return mm;
14243         }
14244  
14245 @@ -599,6 +605,7 @@ void __mmdrop(struct mm_struct *mm)
14246         destroy_context(mm);
14247         mmu_notifier_mm_destroy(mm);
14248         check_mm(mm);
14249 +       clr_vx_info(&mm->mm_vx_info);
14250         free_mm(mm);
14251  }
14252  EXPORT_SYMBOL_GPL(__mmdrop);
14253 @@ -818,6 +825,7 @@ struct mm_struct *dup_mm(struct task_str
14254                 goto fail_nomem;
14255  
14256         memcpy(mm, oldmm, sizeof(*mm));
14257 +       mm->mm_vx_info = NULL;
14258         mm_init_cpumask(mm);
14259  
14260  #ifdef CONFIG_TRANSPARENT_HUGEPAGE
14261 @@ -859,6 +867,7 @@ fail_nocontext:
14262          * If init_new_context() failed, we cannot use mmput() to free the mm
14263          * because it calls destroy_context()
14264          */
14265 +       clr_vx_info(&mm->mm_vx_info);
14266         mm_free_pgd(mm);
14267         free_mm(mm);
14268         return NULL;
14269 @@ -1137,6 +1146,8 @@ static struct task_struct *copy_process(
14270  {
14271         int retval;
14272         struct task_struct *p;
14273 +       struct vx_info *vxi;
14274 +       struct nx_info *nxi;
14275  
14276         if ((clone_flags & (CLONE_NEWNS|CLONE_FS)) == (CLONE_NEWNS|CLONE_FS))
14277                 return ERR_PTR(-EINVAL);
14278 @@ -1195,7 +1206,12 @@ static struct task_struct *copy_process(
14279         DEBUG_LOCKS_WARN_ON(!p->hardirqs_enabled);
14280         DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
14281  #endif
14282 +       init_vx_info(&p->vx_info, current_vx_info());
14283 +       init_nx_info(&p->nx_info, current_nx_info());
14284 +
14285         retval = -EAGAIN;
14286 +       if (!vx_nproc_avail(1))
14287 +               goto bad_fork_free;
14288         if (atomic_read(&p->real_cred->user->processes) >=
14289                         task_rlimit(p, RLIMIT_NPROC)) {
14290                 if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE) &&
14291 @@ -1472,6 +1488,18 @@ static struct task_struct *copy_process(
14292  
14293         total_forks++;
14294         spin_unlock(&current->sighand->siglock);
14295 +
14296 +       /* p is copy of current */
14297 +       vxi = p->vx_info;
14298 +       if (vxi) {
14299 +               claim_vx_info(vxi, p);
14300 +               atomic_inc(&vxi->cvirt.nr_threads);
14301 +               atomic_inc(&vxi->cvirt.total_forks);
14302 +               vx_nproc_inc(p);
14303 +       }
14304 +       nxi = p->nx_info;
14305 +       if (nxi)
14306 +               claim_nx_info(nxi, p);
14307         write_unlock_irq(&tasklist_lock);
14308         proc_fork_connector(p);
14309         cgroup_post_fork(p);
14310 diff -NurpP --minimal linux-3.9.4/kernel/kthread.c linux-3.9.4-vs2.3.6.2/kernel/kthread.c
14311 --- linux-3.9.4/kernel/kthread.c        2013-05-31 13:45:30.000000000 +0000
14312 +++ linux-3.9.4-vs2.3.6.2/kernel/kthread.c      2013-05-31 14:47:11.000000000 +0000
14313 @@ -17,6 +17,7 @@
14314  #include <linux/slab.h>
14315  #include <linux/freezer.h>
14316  #include <linux/ptrace.h>
14317 +#include <linux/vs_pid.h>
14318  #include <trace/events/sched.h>
14319  
14320  static DEFINE_SPINLOCK(kthread_create_lock);
14321 diff -NurpP --minimal linux-3.9.4/kernel/nsproxy.c linux-3.9.4-vs2.3.6.2/kernel/nsproxy.c
14322 --- linux-3.9.4/kernel/nsproxy.c        2013-05-31 13:45:30.000000000 +0000
14323 +++ linux-3.9.4-vs2.3.6.2/kernel/nsproxy.c      2013-05-31 19:28:43.000000000 +0000
14324 @@ -20,11 +20,14 @@
14325  #include <linux/mnt_namespace.h>
14326  #include <linux/utsname.h>
14327  #include <linux/pid_namespace.h>
14328 +#include <linux/vserver/global.h>
14329 +#include <linux/vserver/debug.h>
14330  #include <net/net_namespace.h>
14331  #include <linux/ipc_namespace.h>
14332  #include <linux/proc_fs.h>
14333  #include <linux/file.h>
14334  #include <linux/syscalls.h>
14335 +#include "../fs/mount.h"
14336  
14337  static struct kmem_cache *nsproxy_cachep;
14338  
14339 @@ -46,8 +49,11 @@ static inline struct nsproxy *create_nsp
14340         struct nsproxy *nsproxy;
14341  
14342         nsproxy = kmem_cache_alloc(nsproxy_cachep, GFP_KERNEL);
14343 -       if (nsproxy)
14344 +       if (nsproxy) {
14345                 atomic_set(&nsproxy->count, 1);
14346 +               atomic_inc(&vs_global_nsproxy);
14347 +       }
14348 +       vxdprintk(VXD_CBIT(space, 2), "create_nsproxy = %p[1]", nsproxy);
14349         return nsproxy;
14350  }
14351  
14352 @@ -56,9 +62,12 @@ static inline struct nsproxy *create_nsp
14353   * Return the newly created nsproxy.  Do not attach this to the task,
14354   * leave it to the caller to do proper locking and attach it to task.
14355   */
14356 -static struct nsproxy *create_new_namespaces(unsigned long flags,
14357 -       struct task_struct *tsk, struct user_namespace *user_ns,
14358 -       struct fs_struct *new_fs)
14359 +static struct nsproxy *unshare_namespaces(
14360 +       unsigned long flags,
14361 +       struct nsproxy *orig,
14362 +       struct fs_struct *new_fs,
14363 +       struct user_namespace *new_user,
14364 +       struct pid_namespace *new_pid)
14365  {
14366         struct nsproxy *new_nsp;
14367         int err;
14368 @@ -67,31 +76,31 @@ static struct nsproxy *create_new_namesp
14369         if (!new_nsp)
14370                 return ERR_PTR(-ENOMEM);
14371  
14372 -       new_nsp->mnt_ns = copy_mnt_ns(flags, tsk->nsproxy->mnt_ns, user_ns, new_fs);
14373 +       new_nsp->mnt_ns = copy_mnt_ns(flags, orig->mnt_ns, new_user, new_fs);
14374         if (IS_ERR(new_nsp->mnt_ns)) {
14375                 err = PTR_ERR(new_nsp->mnt_ns);
14376                 goto out_ns;
14377         }
14378  
14379 -       new_nsp->uts_ns = copy_utsname(flags, user_ns, tsk->nsproxy->uts_ns);
14380 +       new_nsp->uts_ns = copy_utsname(flags, new_user, orig->uts_ns);
14381         if (IS_ERR(new_nsp->uts_ns)) {
14382                 err = PTR_ERR(new_nsp->uts_ns);
14383                 goto out_uts;
14384         }
14385  
14386 -       new_nsp->ipc_ns = copy_ipcs(flags, user_ns, tsk->nsproxy->ipc_ns);
14387 +       new_nsp->ipc_ns = copy_ipcs(flags, new_user, orig->ipc_ns);
14388         if (IS_ERR(new_nsp->ipc_ns)) {
14389                 err = PTR_ERR(new_nsp->ipc_ns);
14390                 goto out_ipc;
14391         }
14392  
14393 -       new_nsp->pid_ns = copy_pid_ns(flags, user_ns, tsk->nsproxy->pid_ns);
14394 +       new_nsp->pid_ns = copy_pid_ns(flags, new_user, new_pid);
14395         if (IS_ERR(new_nsp->pid_ns)) {
14396                 err = PTR_ERR(new_nsp->pid_ns);
14397                 goto out_pid;
14398         }
14399  
14400 -       new_nsp->net_ns = copy_net_ns(flags, user_ns, tsk->nsproxy->net_ns);
14401 +       new_nsp->net_ns = copy_net_ns(flags, new_user, orig->net_ns);
14402         if (IS_ERR(new_nsp->net_ns)) {
14403                 err = PTR_ERR(new_nsp->net_ns);
14404                 goto out_net;
14405 @@ -116,6 +125,41 @@ out_ns:
14406         return ERR_PTR(err);
14407  }
14408  
14409 +static struct nsproxy *create_new_namespaces(unsigned long flags,
14410 +       struct task_struct *tsk, struct user_namespace *user_ns,
14411 +       struct fs_struct *new_fs)
14412 +
14413 +{
14414 +       return unshare_namespaces(flags, tsk->nsproxy,
14415 +               new_fs, user_ns, task_active_pid_ns(tsk));
14416 +}
14417 +
14418 +/*
14419 + * copies the nsproxy, setting refcount to 1, and grabbing a
14420 + * reference to all contained namespaces.
14421 + */
14422 +struct nsproxy *copy_nsproxy(struct nsproxy *orig)
14423 +{
14424 +       struct nsproxy *ns = create_nsproxy();
14425 +
14426 +       if (ns) {
14427 +               memcpy(ns, orig, sizeof(struct nsproxy));
14428 +               atomic_set(&ns->count, 1);
14429 +
14430 +               if (ns->mnt_ns)
14431 +                       get_mnt_ns(ns->mnt_ns);
14432 +               if (ns->uts_ns)
14433 +                       get_uts_ns(ns->uts_ns);
14434 +               if (ns->ipc_ns)
14435 +                       get_ipc_ns(ns->ipc_ns);
14436 +               if (ns->pid_ns)
14437 +                       get_pid_ns(ns->pid_ns);
14438 +               if (ns->net_ns)
14439 +                       get_net(ns->net_ns);
14440 +       }
14441 +       return ns;
14442 +}
14443 +
14444  /*
14445   * called from clone.  This now handles copy for nsproxy and all
14446   * namespaces therein.
14447 @@ -124,9 +168,12 @@ int copy_namespaces(unsigned long flags,
14448  {
14449         struct nsproxy *old_ns = tsk->nsproxy;
14450         struct user_namespace *user_ns = task_cred_xxx(tsk, user_ns);
14451 -       struct nsproxy *new_ns;
14452 +       struct nsproxy *new_ns = NULL;
14453         int err = 0;
14454  
14455 +       vxdprintk(VXD_CBIT(space, 7), "copy_namespaces(0x%08lx,%p[%p])",
14456 +               flags, tsk, old_ns);
14457 +
14458         if (!old_ns)
14459                 return 0;
14460  
14461 @@ -136,7 +183,7 @@ int copy_namespaces(unsigned long flags,
14462                                 CLONE_NEWPID | CLONE_NEWNET)))
14463                 return 0;
14464  
14465 -       if (!ns_capable(user_ns, CAP_SYS_ADMIN)) {
14466 +       if (!vx_ns_can_unshare(user_ns, CAP_SYS_ADMIN, flags)) {
14467                 err = -EPERM;
14468                 goto out;
14469         }
14470 @@ -163,6 +210,9 @@ int copy_namespaces(unsigned long flags,
14471  
14472  out:
14473         put_nsproxy(old_ns);
14474 +       vxdprintk(VXD_CBIT(space, 3),
14475 +               "copy_namespaces(0x%08lx,%p[%p]) = %d [%p]",
14476 +               flags, tsk, old_ns, err, new_ns);
14477         return err;
14478  }
14479  
14480 @@ -176,7 +226,9 @@ void free_nsproxy(struct nsproxy *ns)
14481                 put_ipc_ns(ns->ipc_ns);
14482         if (ns->pid_ns)
14483                 put_pid_ns(ns->pid_ns);
14484 -       put_net(ns->net_ns);
14485 +       if (ns->net_ns)
14486 +               put_net(ns->net_ns);
14487 +       atomic_dec(&vs_global_nsproxy);
14488         kmem_cache_free(nsproxy_cachep, ns);
14489  }
14490  
14491 @@ -190,12 +242,16 @@ int unshare_nsproxy_namespaces(unsigned
14492         struct user_namespace *user_ns;
14493         int err = 0;
14494  
14495 +       vxdprintk(VXD_CBIT(space, 4),
14496 +               "unshare_nsproxy_namespaces(0x%08lx,[%p])",
14497 +               unshare_flags, current->nsproxy);
14498 +
14499         if (!(unshare_flags & (CLONE_NEWNS | CLONE_NEWUTS | CLONE_NEWIPC |
14500                                CLONE_NEWNET | CLONE_NEWPID)))
14501                 return 0;
14502  
14503         user_ns = new_cred ? new_cred->user_ns : current_user_ns();
14504 -       if (!ns_capable(user_ns, CAP_SYS_ADMIN))
14505 +       if (!vx_ns_can_unshare(user_ns, CAP_SYS_ADMIN, unshare_flags))
14506                 return -EPERM;
14507  
14508         *new_nsp = create_new_namespaces(unshare_flags, current, user_ns,
14509 diff -NurpP --minimal linux-3.9.4/kernel/pid.c linux-3.9.4-vs2.3.6.2/kernel/pid.c
14510 --- linux-3.9.4/kernel/pid.c    2013-05-31 13:45:30.000000000 +0000
14511 +++ linux-3.9.4-vs2.3.6.2/kernel/pid.c  2013-05-31 15:24:34.000000000 +0000
14512 @@ -37,6 +37,7 @@
14513  #include <linux/init_task.h>
14514  #include <linux/syscalls.h>
14515  #include <linux/proc_fs.h>
14516 +#include <linux/vs_pid.h>
14517  
14518  #define pid_hashfn(nr, ns)     \
14519         hash_long((unsigned long)nr + (unsigned long)ns, pidhash_shift)
14520 @@ -364,7 +365,7 @@ EXPORT_SYMBOL_GPL(find_pid_ns);
14521  
14522  struct pid *find_vpid(int nr)
14523  {
14524 -       return find_pid_ns(nr, task_active_pid_ns(current));
14525 +       return find_pid_ns(vx_rmap_pid(nr), task_active_pid_ns(current));
14526  }
14527  EXPORT_SYMBOL_GPL(find_vpid);
14528  
14529 @@ -424,6 +425,9 @@ void transfer_pid(struct task_struct *ol
14530  struct task_struct *pid_task(struct pid *pid, enum pid_type type)
14531  {
14532         struct task_struct *result = NULL;
14533 +
14534 +       if (type == PIDTYPE_REALPID)
14535 +               type = PIDTYPE_PID;
14536         if (pid) {
14537                 struct hlist_node *first;
14538                 first = rcu_dereference_check(hlist_first_rcu(&pid->tasks[type]),
14539 @@ -443,7 +447,7 @@ struct task_struct *find_task_by_pid_ns(
14540         rcu_lockdep_assert(rcu_read_lock_held(),
14541                            "find_task_by_pid_ns() needs rcu_read_lock()"
14542                            " protection");
14543 -       return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
14544 +       return pid_task(find_pid_ns(vx_rmap_pid(nr), ns), PIDTYPE_PID);
14545  }
14546  
14547  struct task_struct *find_task_by_vpid(pid_t vnr)
14548 @@ -487,7 +491,7 @@ struct pid *find_get_pid(pid_t nr)
14549  }
14550  EXPORT_SYMBOL_GPL(find_get_pid);
14551  
14552 -pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns)
14553 +pid_t pid_unmapped_nr_ns(struct pid *pid, struct pid_namespace *ns)
14554  {
14555         struct upid *upid;
14556         pid_t nr = 0;
14557 @@ -501,6 +505,11 @@ pid_t pid_nr_ns(struct pid *pid, struct
14558  }
14559  EXPORT_SYMBOL_GPL(pid_nr_ns);
14560  
14561 +pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns)
14562 +{
14563 +       return vx_map_pid(pid_unmapped_nr_ns(pid, ns));
14564 +}
14565 +
14566  pid_t pid_vnr(struct pid *pid)
14567  {
14568         return pid_nr_ns(pid, task_active_pid_ns(current));
14569 diff -NurpP --minimal linux-3.9.4/kernel/pid_namespace.c linux-3.9.4-vs2.3.6.2/kernel/pid_namespace.c
14570 --- linux-3.9.4/kernel/pid_namespace.c  2013-05-31 13:45:30.000000000 +0000
14571 +++ linux-3.9.4-vs2.3.6.2/kernel/pid_namespace.c        2013-05-31 17:59:48.000000000 +0000
14572 @@ -18,6 +18,7 @@
14573  #include <linux/proc_fs.h>
14574  #include <linux/reboot.h>
14575  #include <linux/export.h>
14576 +#include <linux/vserver/global.h>
14577  
14578  #define BITS_PER_PAGE          (PAGE_SIZE*8)
14579  
14580 @@ -112,6 +113,7 @@ static struct pid_namespace *create_pid_
14581                 goto out_free_map;
14582  
14583         kref_init(&ns->kref);
14584 +       atomic_inc(&vs_global_pid_ns);
14585         ns->level = level;
14586         ns->parent = get_pid_ns(parent_pid_ns);
14587         ns->user_ns = get_user_ns(user_ns);
14588 @@ -142,6 +144,7 @@ static void destroy_pid_namespace(struct
14589         for (i = 0; i < PIDMAP_ENTRIES; i++)
14590                 kfree(ns->pidmap[i].page);
14591         put_user_ns(ns->user_ns);
14592 +       atomic_dec(&vs_global_pid_ns);
14593         kmem_cache_free(pid_ns_cachep, ns);
14594  }
14595  
14596 diff -NurpP --minimal linux-3.9.4/kernel/posix-timers.c linux-3.9.4-vs2.3.6.2/kernel/posix-timers.c
14597 --- linux-3.9.4/kernel/posix-timers.c   2013-05-31 13:45:30.000000000 +0000
14598 +++ linux-3.9.4-vs2.3.6.2/kernel/posix-timers.c 2013-05-31 14:47:11.000000000 +0000
14599 @@ -47,6 +47,7 @@
14600  #include <linux/wait.h>
14601  #include <linux/workqueue.h>
14602  #include <linux/export.h>
14603 +#include <linux/vs_context.h>
14604  
14605  /*
14606   * Management arrays for POSIX timers.  Timers are kept in slab memory
14607 @@ -340,6 +341,7 @@ int posix_timer_event(struct k_itimer *t
14608  {
14609         struct task_struct *task;
14610         int shared, ret = -1;
14611 +
14612         /*
14613          * FIXME: if ->sigq is queued we can race with
14614          * dequeue_signal()->do_schedule_next_timer().
14615 @@ -356,10 +358,18 @@ int posix_timer_event(struct k_itimer *t
14616         rcu_read_lock();
14617         task = pid_task(timr->it_pid, PIDTYPE_PID);
14618         if (task) {
14619 +               struct vx_info_save vxis;
14620 +               struct vx_info *vxi;
14621 +
14622 +               vxi = get_vx_info(task->vx_info);
14623 +               enter_vx_info(vxi, &vxis);
14624                 shared = !(timr->it_sigev_notify & SIGEV_THREAD_ID);
14625                 ret = send_sigqueue(timr->sigq, task, shared);
14626 +               leave_vx_info(&vxis);
14627 +               put_vx_info(vxi);
14628         }
14629         rcu_read_unlock();
14630 +
14631         /* If we failed to send the signal the timer stops. */
14632         return ret > 0;
14633  }
14634 diff -NurpP --minimal linux-3.9.4/kernel/printk.c linux-3.9.4-vs2.3.6.2/kernel/printk.c
14635 --- linux-3.9.4/kernel/printk.c 2013-05-31 13:45:30.000000000 +0000
14636 +++ linux-3.9.4-vs2.3.6.2/kernel/printk.c       2013-05-31 15:23:35.000000000 +0000
14637 @@ -43,6 +43,7 @@
14638  #include <linux/rculist.h>
14639  #include <linux/poll.h>
14640  #include <linux/irq_work.h>
14641 +#include <linux/vs_cvirt.h>
14642  
14643  #include <asm/uaccess.h>
14644  
14645 @@ -841,7 +842,7 @@ static int check_syslog_permissions(int
14646                 return 0;
14647  
14648         if (syslog_action_restricted(type)) {
14649 -               if (capable(CAP_SYSLOG))
14650 +               if (vx_capable(CAP_SYSLOG, VXC_SYSLOG))
14651                         return 0;
14652                 /* For historical reasons, accept CAP_SYS_ADMIN too, with a warning */
14653                 if (capable(CAP_SYS_ADMIN)) {
14654 @@ -1135,12 +1136,9 @@ int do_syslog(int type, char __user *buf
14655         if (error)
14656                 return error;
14657  
14658 -       switch (type) {
14659 -       case SYSLOG_ACTION_CLOSE:       /* Close log */
14660 -               break;
14661 -       case SYSLOG_ACTION_OPEN:        /* Open log */
14662 -               break;
14663 -       case SYSLOG_ACTION_READ:        /* Read from log */
14664 +       if ((type == SYSLOG_ACTION_READ) ||
14665 +           (type == SYSLOG_ACTION_READ_ALL) ||
14666 +           (type == SYSLOG_ACTION_READ_CLEAR)) {
14667                 error = -EINVAL;
14668                 if (!buf || len < 0)
14669                         goto out;
14670 @@ -1151,6 +1149,16 @@ int do_syslog(int type, char __user *buf
14671                         error = -EFAULT;
14672                         goto out;
14673                 }
14674 +       }
14675 +       if (!vx_check(0, VS_ADMIN|VS_WATCH))
14676 +               return vx_do_syslog(type, buf, len);
14677 +
14678 +       switch (type) {
14679 +       case SYSLOG_ACTION_CLOSE:       /* Close log */
14680 +               break;
14681 +       case SYSLOG_ACTION_OPEN:        /* Open log */
14682 +               break;
14683 +       case SYSLOG_ACTION_READ:        /* Read from log */
14684                 error = wait_event_interruptible(log_wait,
14685                                                  syslog_seq != log_next_seq);
14686                 if (error)
14687 @@ -1163,16 +1171,6 @@ int do_syslog(int type, char __user *buf
14688                 /* FALL THRU */
14689         /* Read last kernel messages */
14690         case SYSLOG_ACTION_READ_ALL:
14691 -               error = -EINVAL;
14692 -               if (!buf || len < 0)
14693 -                       goto out;
14694 -               error = 0;
14695 -               if (!len)
14696 -                       goto out;
14697 -               if (!access_ok(VERIFY_WRITE, buf, len)) {
14698 -                       error = -EFAULT;
14699 -                       goto out;
14700 -               }
14701                 error = syslog_print_all(buf, len, clear);
14702                 break;
14703         /* Clear ring buffer */
14704 diff -NurpP --minimal linux-3.9.4/kernel/ptrace.c linux-3.9.4-vs2.3.6.2/kernel/ptrace.c
14705 --- linux-3.9.4/kernel/ptrace.c 2013-05-31 13:45:30.000000000 +0000
14706 +++ linux-3.9.4-vs2.3.6.2/kernel/ptrace.c       2013-05-31 15:22:34.000000000 +0000
14707 @@ -22,6 +22,7 @@
14708  #include <linux/syscalls.h>
14709  #include <linux/uaccess.h>
14710  #include <linux/regset.h>
14711 +#include <linux/vs_context.h>
14712  #include <linux/hw_breakpoint.h>
14713  #include <linux/cn_proc.h>
14714  
14715 @@ -261,6 +262,11 @@ ok:
14716         }
14717         rcu_read_unlock();
14718  
14719 +       if (!vx_check(task->xid, VS_ADMIN_P|VS_WATCH_P|VS_IDENT))
14720 +               return -EPERM;
14721 +       if (!vx_check(task->xid, VS_IDENT) &&
14722 +               !task_vx_flags(task, VXF_STATE_ADMIN, 0))
14723 +               return -EACCES;
14724         return security_ptrace_access_check(task, mode);
14725  }
14726  
14727 diff -NurpP --minimal linux-3.9.4/kernel/sched/core.c linux-3.9.4-vs2.3.6.2/kernel/sched/core.c
14728 --- linux-3.9.4/kernel/sched/core.c     2013-05-31 13:45:30.000000000 +0000
14729 +++ linux-3.9.4-vs2.3.6.2/kernel/sched/core.c   2013-05-31 15:17:22.000000000 +0000
14730 @@ -73,6 +73,8 @@
14731  #include <linux/init_task.h>
14732  #include <linux/binfmts.h>
14733  #include <linux/context_tracking.h>
14734 +#include <linux/vs_sched.h>
14735 +#include <linux/vs_cvirt.h>
14736  
14737  #include <asm/switch_to.h>
14738  #include <asm/tlb.h>
14739 @@ -2091,9 +2093,17 @@ EXPORT_SYMBOL(avenrun); /* should be rem
14740   */
14741  void get_avenrun(unsigned long *loads, unsigned long offset, int shift)
14742  {
14743 -       loads[0] = (avenrun[0] + offset) << shift;
14744 -       loads[1] = (avenrun[1] + offset) << shift;
14745 -       loads[2] = (avenrun[2] + offset) << shift;
14746 +       if (vx_flags(VXF_VIRT_LOAD, 0)) {
14747 +               struct vx_info *vxi = current_vx_info();
14748 +
14749 +               loads[0] = (vxi->cvirt.load[0] + offset) << shift;
14750 +               loads[1] = (vxi->cvirt.load[1] + offset) << shift;
14751 +               loads[2] = (vxi->cvirt.load[2] + offset) << shift;
14752 +       } else {
14753 +               loads[0] = (avenrun[0] + offset) << shift;
14754 +               loads[1] = (avenrun[1] + offset) << shift;
14755 +               loads[2] = (avenrun[2] + offset) << shift;
14756 +       }
14757  }
14758  
14759  static long calc_load_fold_active(struct rq *this_rq)
14760 @@ -3704,7 +3714,7 @@ SYSCALL_DEFINE1(nice, int, increment)
14761                 nice = 19;
14762  
14763         if (increment < 0 && !can_nice(current, nice))
14764 -               return -EPERM;
14765 +               return vx_flags(VXF_IGNEG_NICE, 0) ? 0 : -EPERM;
14766  
14767         retval = security_task_setnice(current, nice);
14768         if (retval)
14769 diff -NurpP --minimal linux-3.9.4/kernel/sched/cputime.c linux-3.9.4-vs2.3.6.2/kernel/sched/cputime.c
14770 --- linux-3.9.4/kernel/sched/cputime.c  2013-05-31 14:22:27.000000000 +0000
14771 +++ linux-3.9.4-vs2.3.6.2/kernel/sched/cputime.c        2013-05-31 15:17:55.000000000 +0000
14772 @@ -4,6 +4,7 @@
14773  #include <linux/kernel_stat.h>
14774  #include <linux/static_key.h>
14775  #include <linux/context_tracking.h>
14776 +#include <linux/vs_sched.h>
14777  #include "sched.h"
14778  
14779  
14780 @@ -151,14 +152,17 @@ static inline void task_group_account_fi
14781  void account_user_time(struct task_struct *p, cputime_t cputime,
14782                        cputime_t cputime_scaled)
14783  {
14784 +       struct vx_info *vxi = p->vx_info;  /* p is _always_ current */
14785 +       int nice = (TASK_NICE(p) > 0);
14786         int index;
14787  
14788         /* Add user time to process. */
14789         p->utime += cputime;
14790         p->utimescaled += cputime_scaled;
14791 +       vx_account_user(vxi, cputime, nice);
14792         account_group_user_time(p, cputime);
14793  
14794 -       index = (TASK_NICE(p) > 0) ? CPUTIME_NICE : CPUTIME_USER;
14795 +       index = (nice) ? CPUTIME_NICE : CPUTIME_USER;
14796  
14797         /* Add user time to cpustat. */
14798         task_group_account_field(p, index, (__force u64) cputime);
14799 @@ -205,9 +209,12 @@ static inline
14800  void __account_system_time(struct task_struct *p, cputime_t cputime,
14801                         cputime_t cputime_scaled, int index)
14802  {
14803 +       struct vx_info *vxi = p->vx_info;  /* p is _always_ current */
14804 +
14805         /* Add system time to process. */
14806         p->stime += cputime;
14807         p->stimescaled += cputime_scaled;
14808 +       vx_account_system(vxi, cputime, 0 /* do we have idle time? */);
14809         account_group_system_time(p, cputime);
14810  
14811         /* Add system time to cpustat. */
14812 diff -NurpP --minimal linux-3.9.4/kernel/sched/fair.c linux-3.9.4-vs2.3.6.2/kernel/sched/fair.c
14813 --- linux-3.9.4/kernel/sched/fair.c     2013-05-31 13:45:30.000000000 +0000
14814 +++ linux-3.9.4-vs2.3.6.2/kernel/sched/fair.c   2013-05-31 15:19:37.000000000 +0000
14815 @@ -29,6 +29,7 @@
14816  #include <linux/mempolicy.h>
14817  #include <linux/migrate.h>
14818  #include <linux/task_work.h>
14819 +#include <linux/vs_cvirt.h>
14820  
14821  #include <trace/events/sched.h>
14822  
14823 @@ -1714,6 +1715,8 @@ enqueue_entity(struct cfs_rq *cfs_rq, st
14824                 __enqueue_entity(cfs_rq, se);
14825         se->on_rq = 1;
14826  
14827 +       if (entity_is_task(se))
14828 +               vx_activate_task(task_of(se));
14829         if (cfs_rq->nr_running == 1) {
14830                 list_add_leaf_cfs_rq(cfs_rq);
14831                 check_enqueue_throttle(cfs_rq);
14832 @@ -1795,6 +1798,8 @@ dequeue_entity(struct cfs_rq *cfs_rq, st
14833         if (se != cfs_rq->curr)
14834                 __dequeue_entity(cfs_rq, se);
14835         se->on_rq = 0;
14836 +       if (entity_is_task(se))
14837 +               vx_deactivate_task(task_of(se));
14838         account_entity_dequeue(cfs_rq, se);
14839  
14840         /*
14841 diff -NurpP --minimal linux-3.9.4/kernel/signal.c linux-3.9.4-vs2.3.6.2/kernel/signal.c
14842 --- linux-3.9.4/kernel/signal.c 2013-05-31 13:45:30.000000000 +0000
14843 +++ linux-3.9.4-vs2.3.6.2/kernel/signal.c       2013-05-31 15:20:05.000000000 +0000
14844 @@ -32,6 +32,8 @@
14845  #include <linux/user_namespace.h>
14846  #include <linux/uprobes.h>
14847  #include <linux/compat.h>
14848 +#include <linux/vs_context.h>
14849 +#include <linux/vs_pid.h>
14850  #define CREATE_TRACE_POINTS
14851  #include <trace/events/signal.h>
14852  
14853 @@ -789,9 +791,18 @@ static int check_kill_permission(int sig
14854         struct pid *sid;
14855         int error;
14856  
14857 +       vxdprintk(VXD_CBIT(misc, 7),
14858 +               "check_kill_permission(%d,%p,%p[#%u,%u])",
14859 +               sig, info, t, vx_task_xid(t), t->pid);
14860 +
14861         if (!valid_signal(sig))
14862                 return -EINVAL;
14863  
14864 +/*     FIXME: needed? if so, why?
14865 +       if ((info != SEND_SIG_NOINFO) &&
14866 +               (is_si_special(info) || !si_fromuser(info)))
14867 +               goto skip;      */
14868 +
14869         if (!si_fromuser(info))
14870                 return 0;
14871  
14872 @@ -815,6 +826,20 @@ static int check_kill_permission(int sig
14873                 }
14874         }
14875  
14876 +       error = -EPERM;
14877 +       if (t->pid == 1 && current->xid)
14878 +               return error;
14879 +
14880 +       error = -ESRCH;
14881 +       /* FIXME: we shouldn't return ESRCH ever, to avoid
14882 +                 loops, maybe ENOENT or EACCES? */
14883 +       if (!vx_check(vx_task_xid(t), VS_WATCH_P | VS_IDENT)) {
14884 +               vxdprintk(current->xid || VXD_CBIT(misc, 7),
14885 +                       "signal %d[%p] xid mismatch %p[#%u,%u] xid=#%u",
14886 +                       sig, info, t, vx_task_xid(t), t->pid, current->xid);
14887 +               return error;
14888 +       }
14889 +/* skip: */
14890         return security_task_kill(t, info, sig, 0);
14891  }
14892  
14893 @@ -1351,7 +1376,7 @@ int kill_pid_info(int sig, struct siginf
14894         rcu_read_lock();
14895  retry:
14896         p = pid_task(pid, PIDTYPE_PID);
14897 -       if (p) {
14898 +       if (p && vx_check(vx_task_xid(p), VS_IDENT)) {
14899                 error = group_send_sig_info(sig, info, p);
14900                 if (unlikely(error == -ESRCH))
14901                         /*
14902 @@ -1399,7 +1424,7 @@ int kill_pid_info_as_cred(int sig, struc
14903  
14904         rcu_read_lock();
14905         p = pid_task(pid, PIDTYPE_PID);
14906 -       if (!p) {
14907 +       if (!p || !vx_check(vx_task_xid(p), VS_IDENT)) {
14908                 ret = -ESRCH;
14909                 goto out_unlock;
14910         }
14911 @@ -1451,8 +1476,10 @@ static int kill_something_info(int sig,
14912                 struct task_struct * p;
14913  
14914                 for_each_process(p) {
14915 -                       if (task_pid_vnr(p) > 1 &&
14916 -                                       !same_thread_group(p, current)) {
14917 +                       if (vx_check(vx_task_xid(p), VS_ADMIN|VS_IDENT) &&
14918 +                               task_pid_vnr(p) > 1 &&
14919 +                               !same_thread_group(p, current) &&
14920 +                               !vx_current_initpid(p->pid)) {
14921                                 int err = group_send_sig_info(sig, info, p);
14922                                 ++count;
14923                                 if (err != -EPERM)
14924 @@ -2306,6 +2333,11 @@ relock:
14925                                 !sig_kernel_only(signr))
14926                         continue;
14927  
14928 +               /* virtual init is protected against user signals */
14929 +               if ((info->si_code == SI_USER) &&
14930 +                       vx_current_initpid(current->pid))
14931 +                       continue;
14932 +
14933                 if (sig_kernel_stop(signr)) {
14934                         /*
14935                          * The default action is to stop all threads in
14936 diff -NurpP --minimal linux-3.9.4/kernel/softirq.c linux-3.9.4-vs2.3.6.2/kernel/softirq.c
14937 --- linux-3.9.4/kernel/softirq.c        2013-05-31 13:45:30.000000000 +0000
14938 +++ linux-3.9.4-vs2.3.6.2/kernel/softirq.c      2013-05-31 14:47:11.000000000 +0000
14939 @@ -25,6 +25,7 @@
14940  #include <linux/smp.h>
14941  #include <linux/smpboot.h>
14942  #include <linux/tick.h>
14943 +#include <linux/vs_context.h>
14944  
14945  #define CREATE_TRACE_POINTS
14946  #include <trace/events/irq.h>
14947 diff -NurpP --minimal linux-3.9.4/kernel/sys.c linux-3.9.4-vs2.3.6.2/kernel/sys.c
14948 --- linux-3.9.4/kernel/sys.c    2013-05-31 13:45:30.000000000 +0000
14949 +++ linux-3.9.4-vs2.3.6.2/kernel/sys.c  2013-05-31 15:23:14.000000000 +0000
14950 @@ -50,6 +50,7 @@
14951  #include <linux/binfmts.h>
14952  
14953  #include <linux/kmsg_dump.h>
14954 +#include <linux/vs_pid.h>
14955  /* Move somewhere else to avoid recompiling? */
14956  #include <generated/utsrelease.h>
14957  
14958 @@ -155,7 +156,10 @@ static int set_one_prio(struct task_stru
14959                 goto out;
14960         }
14961         if (niceval < task_nice(p) && !can_nice(p, niceval)) {
14962 -               error = -EACCES;
14963 +               if (vx_flags(VXF_IGNEG_NICE, 0))
14964 +                       error = 0;
14965 +               else
14966 +                       error = -EACCES;
14967                 goto out;
14968         }
14969         no_nice = security_task_setnice(p, niceval);
14970 @@ -206,6 +210,8 @@ SYSCALL_DEFINE3(setpriority, int, which,
14971                         else
14972                                 pgrp = task_pgrp(current);
14973                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
14974 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
14975 +                                       continue;
14976                                 error = set_one_prio(p, niceval, error);
14977                         } while_each_pid_thread(pgrp, PIDTYPE_PGID, p);
14978                         break;
14979 @@ -271,6 +277,8 @@ SYSCALL_DEFINE2(getpriority, int, which,
14980                         else
14981                                 pgrp = task_pgrp(current);
14982                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
14983 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
14984 +                                       continue;
14985                                 niceval = 20 - task_nice(p);
14986                                 if (niceval > retval)
14987                                         retval = niceval;
14988 @@ -424,6 +432,8 @@ EXPORT_SYMBOL_GPL(kernel_power_off);
14989  
14990  static DEFINE_MUTEX(reboot_mutex);
14991  
14992 +long vs_reboot(unsigned int, void __user *);
14993 +
14994  /*
14995   * Reboot system call: for obvious reasons only root may call it,
14996   * and even root needs to set up some magic numbers in the registers
14997 @@ -466,6 +476,9 @@ SYSCALL_DEFINE4(reboot, int, magic1, int
14998         if ((cmd == LINUX_REBOOT_CMD_POWER_OFF) && !pm_power_off)
14999                 cmd = LINUX_REBOOT_CMD_HALT;
15000  
15001 +       if (!vx_check(0, VS_ADMIN|VS_WATCH))
15002 +               return vs_reboot(cmd, arg);
15003 +
15004         mutex_lock(&reboot_mutex);
15005         switch (cmd) {
15006         case LINUX_REBOOT_CMD_RESTART:
15007 @@ -1373,7 +1386,8 @@ SYSCALL_DEFINE2(sethostname, char __user
15008         int errno;
15009         char tmp[__NEW_UTS_LEN];
15010  
15011 -       if (!ns_capable(current->nsproxy->uts_ns->user_ns, CAP_SYS_ADMIN))
15012 +       if (!vx_ns_capable(current->nsproxy->uts_ns->user_ns,
15013 +               CAP_SYS_ADMIN, VXC_SET_UTSNAME))
15014                 return -EPERM;
15015  
15016         if (len < 0 || len > __NEW_UTS_LEN)
15017 @@ -1424,7 +1438,8 @@ SYSCALL_DEFINE2(setdomainname, char __us
15018         int errno;
15019         char tmp[__NEW_UTS_LEN];
15020  
15021 -       if (!ns_capable(current->nsproxy->uts_ns->user_ns, CAP_SYS_ADMIN))
15022 +       if (!vx_ns_capable(current->nsproxy->uts_ns->user_ns,
15023 +               CAP_SYS_ADMIN, VXC_SET_UTSNAME))
15024                 return -EPERM;
15025         if (len < 0 || len > __NEW_UTS_LEN)
15026                 return -EINVAL;
15027 @@ -1543,7 +1558,7 @@ int do_prlimit(struct task_struct *tsk,
15028                 /* Keep the capable check against init_user_ns until
15029                    cgroups can contain all limits */
15030                 if (new_rlim->rlim_max > rlim->rlim_max &&
15031 -                               !capable(CAP_SYS_RESOURCE))
15032 +                       !vx_capable(CAP_SYS_RESOURCE, VXC_SET_RLIMIT))
15033                         retval = -EPERM;
15034                 if (!retval)
15035                         retval = security_task_setrlimit(tsk->group_leader,
15036 @@ -1596,7 +1611,8 @@ static int check_prlimit_permission(stru
15037             gid_eq(cred->gid, tcred->sgid) &&
15038             gid_eq(cred->gid, tcred->gid))
15039                 return 0;
15040 -       if (ns_capable(tcred->user_ns, CAP_SYS_RESOURCE))
15041 +       if (vx_ns_capable(tcred->user_ns,
15042 +               CAP_SYS_RESOURCE, VXC_SET_RLIMIT))
15043                 return 0;
15044  
15045         return -EPERM;
15046 diff -NurpP --minimal linux-3.9.4/kernel/sysctl.c linux-3.9.4-vs2.3.6.2/kernel/sysctl.c
15047 --- linux-3.9.4/kernel/sysctl.c 2013-05-31 13:45:30.000000000 +0000
15048 +++ linux-3.9.4-vs2.3.6.2/kernel/sysctl.c       2013-05-31 15:28:39.000000000 +0000
15049 @@ -83,6 +83,7 @@
15050  #if defined(CONFIG_PROVE_LOCKING) || defined(CONFIG_LOCK_STAT)
15051  #include <linux/lockdep.h>
15052  #endif
15053 +extern char vshelper_path[];
15054  #ifdef CONFIG_CHR_DEV_SG
15055  #include <scsi/sg.h>
15056  #endif
15057 @@ -629,6 +630,13 @@ static struct ctl_table kern_table[] = {
15058                 .mode           = 0644,
15059                 .proc_handler   = proc_dostring,
15060         },
15061 +       {
15062 +               .procname       = "vshelper",
15063 +               .data           = &vshelper_path,
15064 +               .maxlen         = 256,
15065 +               .mode           = 0644,
15066 +               .proc_handler   = &proc_dostring,
15067 +       },
15068  
15069  #ifdef CONFIG_CHR_DEV_SG
15070         {
15071 diff -NurpP --minimal linux-3.9.4/kernel/sysctl_binary.c linux-3.9.4-vs2.3.6.2/kernel/sysctl_binary.c
15072 --- linux-3.9.4/kernel/sysctl_binary.c  2013-05-31 13:45:30.000000000 +0000
15073 +++ linux-3.9.4-vs2.3.6.2/kernel/sysctl_binary.c        2013-05-31 14:47:11.000000000 +0000
15074 @@ -73,6 +73,7 @@ static const struct bin_table bin_kern_t
15075  
15076         { CTL_INT,      KERN_PANIC,                     "panic" },
15077         { CTL_INT,      KERN_REALROOTDEV,               "real-root-dev" },
15078 +       { CTL_STR,      KERN_VSHELPER,                  "vshelper" },
15079  
15080         { CTL_STR,      KERN_SPARC_REBOOT,              "reboot-cmd" },
15081         { CTL_INT,      KERN_CTLALTDEL,                 "ctrl-alt-del" },
15082 diff -NurpP --minimal linux-3.9.4/kernel/time/timekeeping.c linux-3.9.4-vs2.3.6.2/kernel/time/timekeeping.c
15083 --- linux-3.9.4/kernel/time/timekeeping.c       2013-05-31 13:45:30.000000000 +0000
15084 +++ linux-3.9.4-vs2.3.6.2/kernel/time/timekeeping.c     2013-05-31 15:24:55.000000000 +0000
15085 @@ -22,6 +22,7 @@
15086  #include <linux/tick.h>
15087  #include <linux/stop_machine.h>
15088  #include <linux/pvclock_gtod.h>
15089 +#include <linux/vs_time.h>
15090  
15091  
15092  static struct timekeeper timekeeper;
15093 @@ -594,6 +595,7 @@ void getrawmonotonic(struct timespec *ts
15094         } while (read_seqretry(&tk->lock, seq));
15095  
15096         timespec_add_ns(ts, nsecs);
15097 +       vx_adjust_timespec(ts);
15098  }
15099  EXPORT_SYMBOL(getrawmonotonic);
15100  
15101 diff -NurpP --minimal linux-3.9.4/kernel/time.c linux-3.9.4-vs2.3.6.2/kernel/time.c
15102 --- linux-3.9.4/kernel/time.c   2013-05-31 13:45:30.000000000 +0000
15103 +++ linux-3.9.4-vs2.3.6.2/kernel/time.c 2013-05-31 14:47:11.000000000 +0000
15104 @@ -37,6 +37,7 @@
15105  #include <linux/fs.h>
15106  #include <linux/math64.h>
15107  #include <linux/ptrace.h>
15108 +#include <linux/vs_time.h>
15109  
15110  #include <asm/uaccess.h>
15111  #include <asm/unistd.h>
15112 @@ -92,7 +93,7 @@ SYSCALL_DEFINE1(stime, time_t __user *,
15113         if (err)
15114                 return err;
15115  
15116 -       do_settimeofday(&tv);
15117 +       vx_settimeofday(&tv);
15118         return 0;
15119  }
15120  
15121 @@ -180,7 +181,7 @@ int do_sys_settimeofday(const struct tim
15122                 }
15123         }
15124         if (tv)
15125 -               return do_settimeofday(tv);
15126 +               return vx_settimeofday(tv);
15127         return 0;
15128  }
15129  
15130 diff -NurpP --minimal linux-3.9.4/kernel/timer.c linux-3.9.4-vs2.3.6.2/kernel/timer.c
15131 --- linux-3.9.4/kernel/timer.c  2013-05-31 14:22:27.000000000 +0000
15132 +++ linux-3.9.4-vs2.3.6.2/kernel/timer.c        2013-05-31 14:47:11.000000000 +0000
15133 @@ -41,6 +41,10 @@
15134  #include <linux/sched.h>
15135  #include <linux/sched/sysctl.h>
15136  #include <linux/slab.h>
15137 +#include <linux/vs_base.h>
15138 +#include <linux/vs_cvirt.h>
15139 +#include <linux/vs_pid.h>
15140 +#include <linux/vserver/sched.h>
15141  
15142  #include <asm/uaccess.h>
15143  #include <asm/unistd.h>
15144 diff -NurpP --minimal linux-3.9.4/kernel/user_namespace.c linux-3.9.4-vs2.3.6.2/kernel/user_namespace.c
15145 --- linux-3.9.4/kernel/user_namespace.c 2013-05-31 13:45:30.000000000 +0000
15146 +++ linux-3.9.4-vs2.3.6.2/kernel/user_namespace.c       2013-05-31 17:44:56.000000000 +0000
15147 @@ -22,6 +22,7 @@
15148  #include <linux/ctype.h>
15149  #include <linux/projid.h>
15150  #include <linux/fs_struct.h>
15151 +#include <linux/vserver/global.h>
15152  
15153  static struct kmem_cache *user_ns_cachep __read_mostly;
15154  
15155 @@ -91,6 +92,7 @@ int create_user_ns(struct cred *new)
15156  
15157         atomic_set(&ns->count, 1);
15158         /* Leave the new->user_ns reference with the new user namespace. */
15159 +       atomic_inc(&vs_global_user_ns);
15160         ns->parent = parent_ns;
15161         ns->owner = owner;
15162         ns->group = group;
15163 @@ -835,6 +837,8 @@ static void *userns_get(struct task_stru
15164  
15165  static void userns_put(void *ns)
15166  {
15167 +       /* FIXME: maybe move into destroyer? */
15168 +       atomic_dec(&vs_global_user_ns);
15169         put_user_ns(ns);
15170  }
15171  
15172 diff -NurpP --minimal linux-3.9.4/kernel/utsname.c linux-3.9.4-vs2.3.6.2/kernel/utsname.c
15173 --- linux-3.9.4/kernel/utsname.c        2013-05-31 13:45:30.000000000 +0000
15174 +++ linux-3.9.4-vs2.3.6.2/kernel/utsname.c      2013-05-31 15:15:55.000000000 +0000
15175 @@ -16,14 +16,17 @@
15176  #include <linux/slab.h>
15177  #include <linux/user_namespace.h>
15178  #include <linux/proc_fs.h>
15179 +#include <linux/vserver/global.h>
15180  
15181  static struct uts_namespace *create_uts_ns(void)
15182  {
15183         struct uts_namespace *uts_ns;
15184  
15185         uts_ns = kmalloc(sizeof(struct uts_namespace), GFP_KERNEL);
15186 -       if (uts_ns)
15187 +       if (uts_ns) {
15188                 kref_init(&uts_ns->kref);
15189 +               atomic_inc(&vs_global_uts_ns);
15190 +       }
15191         return uts_ns;
15192  }
15193  
15194 @@ -85,6 +88,7 @@ void free_uts_ns(struct kref *kref)
15195         ns = container_of(kref, struct uts_namespace, kref);
15196         put_user_ns(ns->user_ns);
15197         proc_free_inum(ns->proc_inum);
15198 +       atomic_dec(&vs_global_uts_ns);
15199         kfree(ns);
15200  }
15201  
15202 diff -NurpP --minimal linux-3.9.4/kernel/vserver/Kconfig linux-3.9.4-vs2.3.6.2/kernel/vserver/Kconfig
15203 --- linux-3.9.4/kernel/vserver/Kconfig  1970-01-01 00:00:00.000000000 +0000
15204 +++ linux-3.9.4-vs2.3.6.2/kernel/vserver/Kconfig        2013-05-31 14:47:11.000000000 +0000
15205 @@ -0,0 +1,233 @@
15206 +#
15207 +# Linux VServer configuration
15208 +#
15209 +
15210 +menu "Linux VServer"
15211 +
15212 +config VSERVER_AUTO_LBACK
15213 +       bool    "Automatically Assign Loopback IP"
15214 +       default y
15215 +       help
15216 +         Automatically assign a guest specific loopback
15217 +         IP and add it to the kernel network stack on
15218 +         startup.
15219 +
15220 +config VSERVER_AUTO_SINGLE
15221 +       bool    "Automatic Single IP Special Casing"
15222 +       depends on EXPERIMENTAL
15223 +       default y
15224 +       help
15225 +         This allows network contexts with a single IP to
15226 +         automatically remap 0.0.0.0 bindings to that IP,
15227 +         avoiding further network checks and improving
15228 +         performance.
15229 +
15230 +         (note: such guests do not allow to change the ip
15231 +          on the fly and do not show loopback addresses)
15232 +
15233 +config VSERVER_COWBL
15234 +       bool    "Enable COW Immutable Link Breaking"
15235 +       default y
15236 +       help
15237 +         This enables the COW (Copy-On-Write) link break code.
15238 +         It allows you to treat unified files like normal files
15239 +         when writing to them (which will implicitely break the
15240 +         link and create a copy of the unified file)
15241 +
15242 +config VSERVER_VTIME
15243 +       bool    "Enable Virtualized Guest Time"
15244 +       depends on EXPERIMENTAL
15245 +       default n
15246 +       help
15247 +         This enables per guest time offsets to allow for
15248 +         adjusting the system clock individually per guest.
15249 +         this adds some overhead to the time functions and
15250 +         therefore should not be enabled without good reason.
15251 +
15252 +config VSERVER_DEVICE
15253 +       bool    "Enable Guest Device Mapping"
15254 +       depends on EXPERIMENTAL
15255 +       default n
15256 +       help
15257 +         This enables generic device remapping.
15258 +
15259 +config VSERVER_PROC_SECURE
15260 +       bool    "Enable Proc Security"
15261 +       depends on PROC_FS
15262 +       default y
15263 +       help
15264 +         This configures ProcFS security to initially hide
15265 +         non-process entries for all contexts except the main and
15266 +         spectator context (i.e. for all guests), which is a secure
15267 +         default.
15268 +
15269 +         (note: on 1.2x the entries were visible by default)
15270 +
15271 +choice
15272 +       prompt  "Persistent Inode Tagging"
15273 +       default TAGGING_ID24
15274 +       help
15275 +         This adds persistent context information to filesystems
15276 +         mounted with the tagxid option. Tagging is a requirement
15277 +         for per-context disk limits and per-context quota.
15278 +
15279 +
15280 +config TAGGING_NONE
15281 +       bool    "Disabled"
15282 +       help
15283 +         do not store per-context information in inodes.
15284 +
15285 +config TAGGING_UID16
15286 +       bool    "UID16/GID32"
15287 +       help
15288 +         reduces UID to 16 bit, but leaves GID at 32 bit.
15289 +
15290 +config TAGGING_GID16
15291 +       bool    "UID32/GID16"
15292 +       help
15293 +         reduces GID to 16 bit, but leaves UID at 32 bit.
15294 +
15295 +config TAGGING_ID24
15296 +       bool    "UID24/GID24"
15297 +       help
15298 +         uses the upper 8bit from UID and GID for XID tagging
15299 +         which leaves 24bit for UID/GID each, which should be
15300 +         more than sufficient for normal use.
15301 +
15302 +config TAGGING_INTERN
15303 +       bool    "UID32/GID32"
15304 +       help
15305 +         this uses otherwise reserved inode fields in the on
15306 +         disk representation, which limits the use to a few
15307 +         filesystems (currently ext2 and ext3)
15308 +
15309 +endchoice
15310 +
15311 +config TAG_NFSD
15312 +       bool    "Tag NFSD User Auth and Files"
15313 +       default n
15314 +       help
15315 +         Enable this if you do want the in-kernel NFS
15316 +         Server to use the tagging specified above.
15317 +         (will require patched clients too)
15318 +
15319 +config VSERVER_PRIVACY
15320 +       bool    "Honor Privacy Aspects of Guests"
15321 +       default n
15322 +       help
15323 +         When enabled, most context checks will disallow
15324 +         access to structures assigned to a specific context,
15325 +         like ptys or loop devices.
15326 +
15327 +config VSERVER_CONTEXTS
15328 +       int     "Maximum number of Contexts (1-65533)"  if EMBEDDED
15329 +       range 1 65533
15330 +       default "768"   if 64BIT
15331 +       default "256"
15332 +       help
15333 +         This setting will optimize certain data structures
15334 +         and memory allocations according to the expected
15335 +         maximum.
15336 +
15337 +         note: this is not a strict upper limit.
15338 +
15339 +config VSERVER_WARN
15340 +       bool    "VServer Warnings"
15341 +       default y
15342 +       help
15343 +         This enables various runtime warnings, which will
15344 +         notify about potential manipulation attempts or
15345 +         resource shortage. It is generally considered to
15346 +         be a good idea to have that enabled.
15347 +
15348 +config VSERVER_WARN_DEVPTS
15349 +       bool    "VServer DevPTS Warnings"
15350 +       depends on VSERVER_WARN
15351 +       default y
15352 +       help
15353 +         This enables DevPTS related warnings, issued when a
15354 +         process inside a context tries to lookup or access
15355 +         a dynamic pts from the host or a different context.
15356 +
15357 +config VSERVER_DEBUG
15358 +       bool    "VServer Debugging Code"
15359 +       default n
15360 +       help
15361 +         Set this to yes if you want to be able to activate
15362 +         debugging output at runtime. It adds a very small
15363 +         overhead to all vserver related functions and
15364 +         increases the kernel size by about 20k.
15365 +
15366 +config VSERVER_HISTORY
15367 +       bool    "VServer History Tracing"
15368 +       depends on VSERVER_DEBUG
15369 +       default n
15370 +       help
15371 +         Set this to yes if you want to record the history of
15372 +         linux-vserver activities, so they can be replayed in
15373 +         the event of a kernel panic or oops.
15374 +
15375 +config VSERVER_HISTORY_SIZE
15376 +       int     "Per-CPU History Size (32-65536)"
15377 +       depends on VSERVER_HISTORY
15378 +       range 32 65536
15379 +       default 64
15380 +       help
15381 +         This allows you to specify the number of entries in
15382 +         the per-CPU history buffer.
15383 +
15384 +config VSERVER_EXTRA_MNT_CHECK
15385 +       bool    "Extra Checks for Reachability"
15386 +       default n
15387 +       help
15388 +         Set this to yes if you want to do extra checks for
15389 +         vfsmount reachability in the proc filesystem code.
15390 +         This shouldn't be required on any setup utilizing
15391 +         mnt namespaces.
15392 +
15393 +choice
15394 +       prompt  "Quotes used in debug and warn messages"
15395 +       default QUOTES_ISO8859
15396 +
15397 +config QUOTES_ISO8859
15398 +       bool    "Extended ASCII (ISO 8859) angle quotes"
15399 +       help
15400 +         This uses the extended ASCII characters \xbb
15401 +         and \xab for quoting file and process names.
15402 +
15403 +config QUOTES_UTF8
15404 +       bool    "UTF-8 angle quotes"
15405 +       help
15406 +         This uses the the UTF-8 sequences for angle
15407 +         quotes to quote file and process names.
15408 +
15409 +config QUOTES_ASCII
15410 +       bool    "ASCII single quotes"
15411 +       help
15412 +         This uses the ASCII single quote character
15413 +         (\x27) to quote file and process names.
15414 +
15415 +endchoice
15416 +
15417 +endmenu
15418 +
15419 +
15420 +config VSERVER
15421 +       bool
15422 +       default y
15423 +       select NAMESPACES
15424 +       select UTS_NS
15425 +       select IPC_NS
15426 +#      select USER_NS
15427 +       select SYSVIPC
15428 +
15429 +config VSERVER_SECURITY
15430 +       bool
15431 +       depends on SECURITY
15432 +       default y
15433 +       select SECURITY_CAPABILITIES
15434 +
15435 +config VSERVER_DISABLED
15436 +       bool
15437 +       default n
15438 +
15439 diff -NurpP --minimal linux-3.9.4/kernel/vserver/Makefile linux-3.9.4-vs2.3.6.2/kernel/vserver/Makefile
15440 --- linux-3.9.4/kernel/vserver/Makefile 1970-01-01 00:00:00.000000000 +0000
15441 +++ linux-3.9.4-vs2.3.6.2/kernel/vserver/Makefile       2013-05-31 14:47:11.000000000 +0000
15442 @@ -0,0 +1,18 @@
15443 +#
15444 +# Makefile for the Linux vserver routines.
15445 +#
15446 +
15447 +
15448 +obj-y          += vserver.o
15449 +
15450 +vserver-y      := switch.o context.o space.o sched.o network.o inode.o \
15451 +                  limit.o cvirt.o cacct.o signal.o helper.o init.o \
15452 +                  dlimit.o tag.o
15453 +
15454 +vserver-$(CONFIG_INET) += inet.o
15455 +vserver-$(CONFIG_PROC_FS) += proc.o
15456 +vserver-$(CONFIG_VSERVER_DEBUG) += sysctl.o debug.o
15457 +vserver-$(CONFIG_VSERVER_HISTORY) += history.o
15458 +vserver-$(CONFIG_VSERVER_MONITOR) += monitor.o
15459 +vserver-$(CONFIG_VSERVER_DEVICE) += device.o
15460 +
15461 diff -NurpP --minimal linux-3.9.4/kernel/vserver/cacct.c linux-3.9.4-vs2.3.6.2/kernel/vserver/cacct.c
15462 --- linux-3.9.4/kernel/vserver/cacct.c  1970-01-01 00:00:00.000000000 +0000
15463 +++ linux-3.9.4-vs2.3.6.2/kernel/vserver/cacct.c        2013-05-31 14:47:11.000000000 +0000
15464 @@ -0,0 +1,42 @@
15465 +/*
15466 + *  linux/kernel/vserver/cacct.c
15467 + *
15468 + *  Virtual Server: Context Accounting
15469 + *
15470 + *  Copyright (C) 2006-2007 Herbert Pötzl
15471 + *
15472 + *  V0.01  added accounting stats
15473 + *
15474 + */
15475 +
15476 +#include <linux/types.h>
15477 +#include <linux/vs_context.h>
15478 +#include <linux/vserver/cacct_cmd.h>
15479 +#include <linux/vserver/cacct_int.h>
15480 +
15481 +#include <asm/errno.h>
15482 +#include <asm/uaccess.h>
15483 +
15484 +
15485 +int vc_sock_stat(struct vx_info *vxi, void __user *data)
15486 +{
15487 +       struct vcmd_sock_stat_v0 vc_data;
15488 +       int j, field;
15489 +
15490 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
15491 +               return -EFAULT;
15492 +
15493 +       field = vc_data.field;
15494 +       if ((field < 0) || (field >= VXA_SOCK_SIZE))
15495 +               return -EINVAL;
15496 +
15497 +       for (j = 0; j < 3; j++) {
15498 +               vc_data.count[j] = vx_sock_count(&vxi->cacct, field, j);
15499 +               vc_data.total[j] = vx_sock_total(&vxi->cacct, field, j);
15500 +       }
15501 +
15502 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
15503 +               return -EFAULT;
15504 +       return 0;
15505 +}
15506 +
15507 diff -NurpP --minimal linux-3.9.4/kernel/vserver/cacct_init.h linux-3.9.4-vs2.3.6.2/kernel/vserver/cacct_init.h
15508 --- linux-3.9.4/kernel/vserver/cacct_init.h     1970-01-01 00:00:00.000000000 +0000
15509 +++ linux-3.9.4-vs2.3.6.2/kernel/vserver/cacct_init.h   2013-05-31 14:47:11.000000000 +0000
15510 @@ -0,0 +1,25 @@
15511 +
15512 +
15513 +static inline void vx_info_init_cacct(struct _vx_cacct *cacct)
15514 +{
15515 +       int i, j;
15516 +
15517 +
15518 +       for (i = 0; i < VXA_SOCK_SIZE; i++) {
15519 +               for (j = 0; j < 3; j++) {
15520 +                       atomic_long_set(&cacct->sock[i][j].count, 0);
15521 +                       atomic_long_set(&cacct->sock[i][j].total, 0);
15522 +               }
15523 +       }
15524 +       for (i = 0; i < 8; i++)
15525 +               atomic_set(&cacct->slab[i], 0);
15526 +       for (i = 0; i < 5; i++)
15527 +               for (j = 0; j < 4; j++)
15528 +                       atomic_set(&cacct->page[i][j], 0);
15529 +}
15530 +
15531 +static inline void vx_info_exit_cacct(struct _vx_cacct *cacct)
15532 +{
15533 +       return;
15534 +}
15535 +
15536 diff -NurpP --minimal linux-3.9.4/kernel/vserver/cacct_proc.h linux-3.9.4-vs2.3.6.2/kernel/vserver/cacct_proc.h
15537 --- linux-3.9.4/kernel/vserver/cacct_proc.h     1970-01-01 00:00:00.000000000 +0000
15538 +++ linux-3.9.4-vs2.3.6.2/kernel/vserver/cacct_proc.h   2013-05-31 14:47:11.000000000 +0000
15539 @@ -0,0 +1,53 @@
15540 +#ifndef _VX_CACCT_PROC_H
15541 +#define _VX_CACCT_PROC_H
15542 +
15543 +#include <linux/vserver/cacct_int.h>
15544 +
15545 +
15546 +#define VX_SOCKA_TOP   \
15547 +       "Type\t    recv #/bytes\t\t   send #/bytes\t\t    fail #/bytes\n"
15548 +
15549 +static inline int vx_info_proc_cacct(struct _vx_cacct *cacct, char *buffer)
15550 +{
15551 +       int i, j, length = 0;
15552 +       static char *type[VXA_SOCK_SIZE] = {
15553 +               "UNSPEC", "UNIX", "INET", "INET6", "PACKET", "OTHER"
15554 +       };
15555 +
15556 +       length += sprintf(buffer + length, VX_SOCKA_TOP);
15557 +       for (i = 0; i < VXA_SOCK_SIZE; i++) {
15558 +               length += sprintf(buffer + length, "%s:", type[i]);
15559 +               for (j = 0; j < 3; j++) {
15560 +                       length += sprintf(buffer + length,
15561 +                               "\t%10lu/%-10lu",
15562 +                               vx_sock_count(cacct, i, j),
15563 +                               vx_sock_total(cacct, i, j));
15564 +               }
15565 +               buffer[length++] = '\n';
15566 +       }
15567 +
15568 +       length += sprintf(buffer + length, "\n");
15569 +       length += sprintf(buffer + length,
15570 +               "slab:\t %8u %8u %8u %8u\n",
15571 +               atomic_read(&cacct->slab[1]),
15572 +               atomic_read(&cacct->slab[4]),
15573 +               atomic_read(&cacct->slab[0]),
15574 +               atomic_read(&cacct->slab[2]));
15575 +
15576 +       length += sprintf(buffer + length, "\n");
15577 +       for (i = 0; i < 5; i++) {
15578 +               length += sprintf(buffer + length,
15579 +                       "page[%d]: %8u %8u %8u %8u\t %8u %8u %8u %8u\n", i,
15580 +                       atomic_read(&cacct->page[i][0]),
15581 +                       atomic_read(&cacct->page[i][1]),
15582 +                       atomic_read(&cacct->page[i][2]),
15583 +                       atomic_read(&cacct->page[i][3]),
15584 +                       atomic_read(&cacct->page[i][4]),
15585 +                       atomic_read(&cacct->page[i][5]),
15586 +                       atomic_read(&cacct->page[i][6]),
15587 +                       atomic_read(&cacct->page[i][7]));
15588 +       }
15589 +       return length;
15590 +}
15591 +
15592 +#endif /* _VX_CACCT_PROC_H */
15593 diff -NurpP --minimal linux-3.9.4/kernel/vserver/context.c linux-3.9.4-vs2.3.6.2/kernel/vserver/context.c
15594 --- linux-3.9.4/kernel/vserver/context.c        1970-01-01 00:00:00.000000000 +0000
15595 +++ linux-3.9.4-vs2.3.6.2/kernel/vserver/context.c      2013-05-31 19:34:32.000000000 +0000
15596 @@ -0,0 +1,1119 @@
15597 +/*
15598 + *  linux/kernel/vserver/context.c
15599 + *
15600 + *  Virtual Server: Context Support
15601 + *
15602 + *  Copyright (C) 2003-2011  Herbert Pötzl
15603 + *
15604 + *  V0.01  context helper
15605 + *  V0.02  vx_ctx_kill syscall command
15606 + *  V0.03  replaced context_info calls
15607 + *  V0.04  redesign of struct (de)alloc
15608 + *  V0.05  rlimit basic implementation
15609 + *  V0.06  task_xid and info commands
15610 + *  V0.07  context flags and caps
15611 + *  V0.08  switch to RCU based hash
15612 + *  V0.09  revert to non RCU for now
15613 + *  V0.10  and back to working RCU hash
15614 + *  V0.11  and back to locking again
15615 + *  V0.12  referenced context store
15616 + *  V0.13  separate per cpu data
15617 + *  V0.14  changed vcmds to vxi arg
15618 + *  V0.15  added context stat
15619 + *  V0.16  have __create claim() the vxi
15620 + *  V0.17  removed older and legacy stuff
15621 + *  V0.18  added user credentials
15622 + *  V0.19  added warn mask
15623 + *
15624 + */
15625 +
15626 +#include <linux/slab.h>
15627 +#include <linux/types.h>
15628 +#include <linux/security.h>
15629 +#include <linux/pid_namespace.h>
15630 +#include <linux/capability.h>
15631 +
15632 +#include <linux/vserver/context.h>
15633 +#include <linux/vserver/network.h>
15634 +#include <linux/vserver/debug.h>
15635 +#include <linux/vserver/limit.h>
15636 +#include <linux/vserver/limit_int.h>
15637 +#include <linux/vserver/space.h>
15638 +#include <linux/init_task.h>
15639 +#include <linux/fs_struct.h>
15640 +#include <linux/cred.h>
15641 +
15642 +#include <linux/vs_context.h>
15643 +#include <linux/vs_limit.h>
15644 +#include <linux/vs_pid.h>
15645 +#include <linux/vserver/context_cmd.h>
15646 +
15647 +#include "cvirt_init.h"
15648 +#include "cacct_init.h"
15649 +#include "limit_init.h"
15650 +#include "sched_init.h"
15651 +
15652 +
15653 +atomic_t vx_global_ctotal      = ATOMIC_INIT(0);
15654 +atomic_t vx_global_cactive     = ATOMIC_INIT(0);
15655 +
15656 +
15657 +/*     now inactive context structures */
15658 +
15659 +static struct hlist_head vx_info_inactive = HLIST_HEAD_INIT;
15660 +
15661 +static DEFINE_SPINLOCK(vx_info_inactive_lock);
15662 +
15663 +
15664 +/*     __alloc_vx_info()
15665 +
15666 +       * allocate an initialized vx_info struct
15667 +       * doesn't make it visible (hash)                        */
15668 +
15669 +static struct vx_info *__alloc_vx_info(xid_t xid)
15670 +{
15671 +       struct vx_info *new = NULL;
15672 +       int cpu, index;
15673 +
15674 +       vxdprintk(VXD_CBIT(xid, 0), "alloc_vx_info(%d)*", xid);
15675 +
15676 +       /* would this benefit from a slab cache? */
15677 +       new = kmalloc(sizeof(struct vx_info), GFP_KERNEL);
15678 +       if (!new)
15679 +               return 0;
15680 +
15681 +       memset(new, 0, sizeof(struct vx_info));
15682 +#ifdef CONFIG_SMP
15683 +       new->ptr_pc = alloc_percpu(struct _vx_info_pc);
15684 +       if (!new->ptr_pc)
15685 +               goto error;
15686 +#endif
15687 +       new->vx_id = xid;
15688 +       INIT_HLIST_NODE(&new->vx_hlist);
15689 +       atomic_set(&new->vx_usecnt, 0);
15690 +       atomic_set(&new->vx_tasks, 0);
15691 +       new->vx_parent = NULL;
15692 +       new->vx_state = 0;
15693 +       init_waitqueue_head(&new->vx_wait);
15694 +
15695 +       /* prepare reaper */
15696 +       get_task_struct(init_pid_ns.child_reaper);
15697 +       new->vx_reaper = init_pid_ns.child_reaper;
15698 +       new->vx_badness_bias = 0;
15699 +
15700 +       /* rest of init goes here */
15701 +       vx_info_init_limit(&new->limit);
15702 +       vx_info_init_sched(&new->sched);
15703 +       vx_info_init_cvirt(&new->cvirt);
15704 +       vx_info_init_cacct(&new->cacct);
15705 +
15706 +       /* per cpu data structures */
15707 +       for_each_possible_cpu(cpu) {
15708 +               vx_info_init_sched_pc(
15709 +                       &vx_per_cpu(new, sched_pc, cpu), cpu);
15710 +               vx_info_init_cvirt_pc(
15711 +                       &vx_per_cpu(new, cvirt_pc, cpu), cpu);
15712 +       }
15713 +
15714 +       new->vx_flags = VXF_INIT_SET;
15715 +       new->vx_bcaps = CAP_FULL_SET;   // maybe ~CAP_SETPCAP
15716 +       new->vx_ccaps = 0;
15717 +       new->vx_umask = 0;
15718 +       new->vx_wmask = 0;
15719 +
15720 +       new->reboot_cmd = 0;
15721 +       new->exit_code = 0;
15722 +
15723 +       // preconfig spaces
15724 +       for (index = 0; index < VX_SPACES; index++) {
15725 +               struct _vx_space *space = &new->space[index];
15726 +
15727 +               // filesystem
15728 +               spin_lock(&init_fs.lock);
15729 +               init_fs.users++;
15730 +               spin_unlock(&init_fs.lock);
15731 +               space->vx_fs = &init_fs;
15732 +
15733 +               /* FIXME: do we want defaults? */
15734 +               // space->vx_real_cred = 0;
15735 +               // space->vx_cred = 0;
15736 +       }
15737 +
15738 +
15739 +       vxdprintk(VXD_CBIT(xid, 0),
15740 +               "alloc_vx_info(%d) = %p", xid, new);
15741 +       vxh_alloc_vx_info(new);
15742 +       atomic_inc(&vx_global_ctotal);
15743 +       return new;
15744 +#ifdef CONFIG_SMP
15745 +error:
15746 +       kfree(new);
15747 +       return 0;
15748 +#endif
15749 +}
15750 +
15751 +/*     __dealloc_vx_info()
15752 +
15753 +       * final disposal of vx_info                             */
15754 +
15755 +static void __dealloc_vx_info(struct vx_info *vxi)
15756 +{
15757 +#ifdef CONFIG_VSERVER_WARN
15758 +       struct vx_info_save vxis;
15759 +       int cpu;
15760 +#endif
15761 +       vxdprintk(VXD_CBIT(xid, 0),
15762 +               "dealloc_vx_info(%p)", vxi);
15763 +       vxh_dealloc_vx_info(vxi);
15764 +
15765 +#ifdef CONFIG_VSERVER_WARN
15766 +       enter_vx_info(vxi, &vxis);
15767 +       vx_info_exit_limit(&vxi->limit);
15768 +       vx_info_exit_sched(&vxi->sched);
15769 +       vx_info_exit_cvirt(&vxi->cvirt);
15770 +       vx_info_exit_cacct(&vxi->cacct);
15771 +
15772 +       for_each_possible_cpu(cpu) {
15773 +               vx_info_exit_sched_pc(
15774 +                       &vx_per_cpu(vxi, sched_pc, cpu), cpu);
15775 +               vx_info_exit_cvirt_pc(
15776 +                       &vx_per_cpu(vxi, cvirt_pc, cpu), cpu);
15777 +       }
15778 +       leave_vx_info(&vxis);
15779 +#endif
15780 +
15781 +       vxi->vx_id = -1;
15782 +       vxi->vx_state |= VXS_RELEASED;
15783 +
15784 +#ifdef CONFIG_SMP
15785 +       free_percpu(vxi->ptr_pc);
15786 +#endif
15787 +       kfree(vxi);
15788 +       atomic_dec(&vx_global_ctotal);
15789 +}
15790 +
15791 +static void __shutdown_vx_info(struct vx_info *vxi)
15792 +{
15793 +       struct nsproxy *nsproxy;
15794 +       struct fs_struct *fs;
15795 +       struct cred *cred;
15796 +       int index, kill;
15797 +
15798 +       might_sleep();
15799 +
15800 +       vxi->vx_state |= VXS_SHUTDOWN;
15801 +       vs_state_change(vxi, VSC_SHUTDOWN);
15802 +
15803 +       for (index = 0; index < VX_SPACES; index++) {
15804 +               struct _vx_space *space = &vxi->space[index];
15805 +
15806 +               nsproxy = xchg(&space->vx_nsproxy, NULL);
15807 +               if (nsproxy)
15808 +                       put_nsproxy(nsproxy);
15809 +
15810 +               fs = xchg(&space->vx_fs, NULL);
15811 +               spin_lock(&fs->lock);
15812 +               kill = !--fs->users;
15813 +               spin_unlock(&fs->lock);
15814 +               if (kill)
15815 +                       free_fs_struct(fs);
15816 +
15817 +               cred = (struct cred *)xchg(&space->vx_cred, NULL);
15818 +               if (cred)
15819 +                       abort_creds(cred);
15820 +       }
15821 +}
15822 +
15823 +/* exported stuff */
15824 +
15825 +void free_vx_info(struct vx_info *vxi)
15826 +{
15827 +       unsigned long flags;
15828 +       unsigned index;
15829 +
15830 +       /* check for reference counts first */
15831 +       BUG_ON(atomic_read(&vxi->vx_usecnt));
15832 +       BUG_ON(atomic_read(&vxi->vx_tasks));
15833 +
15834 +       /* context must not be hashed */
15835 +       BUG_ON(vx_info_state(vxi, VXS_HASHED));
15836 +
15837 +       /* context shutdown is mandatory */
15838 +       BUG_ON(!vx_info_state(vxi, VXS_SHUTDOWN));
15839 +
15840 +       /* spaces check */
15841 +       for (index = 0; index < VX_SPACES; index++) {
15842 +               struct _vx_space *space = &vxi->space[index];
15843 +
15844 +               BUG_ON(space->vx_nsproxy);
15845 +               BUG_ON(space->vx_fs);
15846 +               // BUG_ON(space->vx_real_cred);
15847 +               // BUG_ON(space->vx_cred);
15848 +       }
15849 +
15850 +       spin_lock_irqsave(&vx_info_inactive_lock, flags);
15851 +       hlist_del(&vxi->vx_hlist);
15852 +       spin_unlock_irqrestore(&vx_info_inactive_lock, flags);
15853 +
15854 +       __dealloc_vx_info(vxi);
15855 +}
15856 +
15857 +
15858 +/*     hash table for vx_info hash */
15859 +
15860 +#define VX_HASH_SIZE   13
15861 +
15862 +static struct hlist_head vx_info_hash[VX_HASH_SIZE] =
15863 +       { [0 ... VX_HASH_SIZE-1] = HLIST_HEAD_INIT };
15864 +
15865 +static DEFINE_SPINLOCK(vx_info_hash_lock);
15866 +
15867 +
15868 +static inline unsigned int __hashval(xid_t xid)
15869 +{
15870 +       return (xid % VX_HASH_SIZE);
15871 +}
15872 +
15873 +
15874 +
15875 +/*     __hash_vx_info()
15876 +
15877 +       * add the vxi to the global hash table
15878 +       * requires the hash_lock to be held                     */
15879 +
15880 +static inline void __hash_vx_info(struct vx_info *vxi)
15881 +{
15882 +       struct hlist_head *head;
15883 +
15884 +       vxd_assert_lock(&vx_info_hash_lock);
15885 +       vxdprintk(VXD_CBIT(xid, 4),
15886 +               "__hash_vx_info: %p[#%d]", vxi, vxi->vx_id);
15887 +       vxh_hash_vx_info(vxi);
15888 +
15889 +       /* context must not be hashed */
15890 +       BUG_ON(vx_info_state(vxi, VXS_HASHED));
15891 +
15892 +       vxi->vx_state |= VXS_HASHED;
15893 +       head = &vx_info_hash[__hashval(vxi->vx_id)];
15894 +       hlist_add_head(&vxi->vx_hlist, head);
15895 +       atomic_inc(&vx_global_cactive);
15896 +}
15897 +
15898 +/*     __unhash_vx_info()
15899 +
15900 +       * remove the vxi from the global hash table
15901 +       * requires the hash_lock to be held                     */
15902 +
15903 +static inline void __unhash_vx_info(struct vx_info *vxi)
15904 +{
15905 +       unsigned long flags;
15906 +
15907 +       vxd_assert_lock(&vx_info_hash_lock);
15908 +       vxdprintk(VXD_CBIT(xid, 4),
15909 +               "__unhash_vx_info: %p[#%d.%d.%d]", vxi, vxi->vx_id,
15910 +               atomic_read(&vxi->vx_usecnt), atomic_read(&vxi->vx_tasks));
15911 +       vxh_unhash_vx_info(vxi);
15912 +
15913 +       /* context must be hashed */
15914 +       BUG_ON(!vx_info_state(vxi, VXS_HASHED));
15915 +       /* but without tasks */
15916 +       BUG_ON(atomic_read(&vxi->vx_tasks));
15917 +
15918 +       vxi->vx_state &= ~VXS_HASHED;
15919 +       hlist_del_init(&vxi->vx_hlist);
15920 +       spin_lock_irqsave(&vx_info_inactive_lock, flags);
15921 +       hlist_add_head(&vxi->vx_hlist, &vx_info_inactive);
15922 +       spin_unlock_irqrestore(&vx_info_inactive_lock, flags);
15923 +       atomic_dec(&vx_global_cactive);
15924 +}
15925 +
15926 +
15927 +/*     __lookup_vx_info()
15928 +
15929 +       * requires the hash_lock to be held
15930 +       * doesn't increment the vx_refcnt                       */
15931 +
15932 +static inline struct vx_info *__lookup_vx_info(xid_t xid)
15933 +{
15934 +       struct hlist_head *head = &vx_info_hash[__hashval(xid)];
15935 +       struct hlist_node *pos;
15936 +       struct vx_info *vxi;
15937 +
15938 +       vxd_assert_lock(&vx_info_hash_lock);
15939 +       hlist_for_each(pos, head) {
15940 +               vxi = hlist_entry(pos, struct vx_info, vx_hlist);
15941 +
15942 +               if (vxi->vx_id == xid)
15943 +                       goto found;
15944 +       }
15945 +       vxi = NULL;
15946 +found:
15947 +       vxdprintk(VXD_CBIT(xid, 0),
15948 +               "__lookup_vx_info(#%u): %p[#%u]",
15949 +               xid, vxi, vxi ? vxi->vx_id : 0);
15950 +       vxh_lookup_vx_info(vxi, xid);
15951 +       return vxi;
15952 +}
15953 +
15954 +
15955 +/*     __create_vx_info()
15956 +
15957 +       * create the requested context
15958 +       * get(), claim() and hash it                            */
15959 +
15960 +static struct vx_info *__create_vx_info(int id)
15961 +{
15962 +       struct vx_info *new, *vxi = NULL;
15963 +
15964 +       vxdprintk(VXD_CBIT(xid, 1), "create_vx_info(%d)*", id);
15965 +
15966 +       if (!(new = __alloc_vx_info(id)))
15967 +               return ERR_PTR(-ENOMEM);
15968 +
15969 +       /* required to make dynamic xids unique */
15970 +       spin_lock(&vx_info_hash_lock);
15971 +
15972 +       /* static context requested */
15973 +       if ((vxi = __lookup_vx_info(id))) {
15974 +               vxdprintk(VXD_CBIT(xid, 0),
15975 +                       "create_vx_info(%d) = %p (already there)", id, vxi);
15976 +               if (vx_info_flags(vxi, VXF_STATE_SETUP, 0))
15977 +                       vxi = ERR_PTR(-EBUSY);
15978 +               else
15979 +                       vxi = ERR_PTR(-EEXIST);
15980 +               goto out_unlock;
15981 +       }
15982 +       /* new context */
15983 +       vxdprintk(VXD_CBIT(xid, 0),
15984 +               "create_vx_info(%d) = %p (new)", id, new);
15985 +       claim_vx_info(new, NULL);
15986 +       __hash_vx_info(get_vx_info(new));
15987 +       vxi = new, new = NULL;
15988 +
15989 +out_unlock:
15990 +       spin_unlock(&vx_info_hash_lock);
15991 +       vxh_create_vx_info(IS_ERR(vxi) ? NULL : vxi, id);
15992 +       if (new)
15993 +               __dealloc_vx_info(new);
15994 +       return vxi;
15995 +}
15996 +
15997 +
15998 +/*     exported stuff                                          */
15999 +
16000 +
16001 +void unhash_vx_info(struct vx_info *vxi)
16002 +{
16003 +       spin_lock(&vx_info_hash_lock);
16004 +       __unhash_vx_info(vxi);
16005 +       spin_unlock(&vx_info_hash_lock);
16006 +       __shutdown_vx_info(vxi);
16007 +       __wakeup_vx_info(vxi);
16008 +}
16009 +
16010 +
16011 +/*     lookup_vx_info()
16012 +
16013 +       * search for a vx_info and get() it
16014 +       * negative id means current                             */
16015 +
16016 +struct vx_info *lookup_vx_info(int id)
16017 +{
16018 +       struct vx_info *vxi = NULL;
16019 +
16020 +       if (id < 0) {
16021 +               vxi = get_vx_info(current_vx_info());
16022 +       } else if (id > 1) {
16023 +               spin_lock(&vx_info_hash_lock);
16024 +               vxi = get_vx_info(__lookup_vx_info(id));
16025 +               spin_unlock(&vx_info_hash_lock);
16026 +       }
16027 +       return vxi;
16028 +}
16029 +
16030 +/*     xid_is_hashed()
16031 +
16032 +       * verify that xid is still hashed                       */
16033 +
16034 +int xid_is_hashed(xid_t xid)
16035 +{
16036 +       int hashed;
16037 +
16038 +       spin_lock(&vx_info_hash_lock);
16039 +       hashed = (__lookup_vx_info(xid) != NULL);
16040 +       spin_unlock(&vx_info_hash_lock);
16041 +       return hashed;
16042 +}
16043 +
16044 +#ifdef CONFIG_PROC_FS
16045 +
16046 +/*     get_xid_list()
16047 +
16048 +       * get a subset of hashed xids for proc
16049 +       * assumes size is at least one                          */
16050 +
16051 +int get_xid_list(int index, unsigned int *xids, int size)
16052 +{
16053 +       int hindex, nr_xids = 0;
16054 +
16055 +       /* only show current and children */
16056 +       if (!vx_check(0, VS_ADMIN | VS_WATCH)) {
16057 +               if (index > 0)
16058 +                       return 0;
16059 +               xids[nr_xids] = vx_current_xid();
16060 +               return 1;
16061 +       }
16062 +
16063 +       for (hindex = 0; hindex < VX_HASH_SIZE; hindex++) {
16064 +               struct hlist_head *head = &vx_info_hash[hindex];
16065 +               struct hlist_node *pos;
16066 +
16067 +               spin_lock(&vx_info_hash_lock);
16068 +               hlist_for_each(pos, head) {
16069 +                       struct vx_info *vxi;
16070 +
16071 +                       if (--index > 0)
16072 +                               continue;
16073 +
16074 +                       vxi = hlist_entry(pos, struct vx_info, vx_hlist);
16075 +                       xids[nr_xids] = vxi->vx_id;
16076 +                       if (++nr_xids >= size) {
16077 +                               spin_unlock(&vx_info_hash_lock);
16078 +                               goto out;
16079 +                       }
16080 +               }
16081 +               /* keep the lock time short */
16082 +               spin_unlock(&vx_info_hash_lock);
16083 +       }
16084 +out:
16085 +       return nr_xids;
16086 +}
16087 +#endif
16088 +
16089 +#ifdef CONFIG_VSERVER_DEBUG
16090 +
16091 +void   dump_vx_info_inactive(int level)
16092 +{
16093 +       struct hlist_node *entry, *next;
16094 +
16095 +       hlist_for_each_safe(entry, next, &vx_info_inactive) {
16096 +               struct vx_info *vxi =
16097 +                       list_entry(entry, struct vx_info, vx_hlist);
16098 +
16099 +               dump_vx_info(vxi, level);
16100 +       }
16101 +}
16102 +
16103 +#endif
16104 +
16105 +#if 0
16106 +int vx_migrate_user(struct task_struct *p, struct vx_info *vxi)
16107 +{
16108 +       struct user_struct *new_user, *old_user;
16109 +
16110 +       if (!p || !vxi)
16111 +               BUG();
16112 +
16113 +       if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0))
16114 +               return -EACCES;
16115 +
16116 +       new_user = alloc_uid(vxi->vx_id, p->uid);
16117 +       if (!new_user)
16118 +               return -ENOMEM;
16119 +
16120 +       old_user = p->user;
16121 +       if (new_user != old_user) {
16122 +               atomic_inc(&new_user->processes);
16123 +               atomic_dec(&old_user->processes);
16124 +               p->user = new_user;
16125 +       }
16126 +       free_uid(old_user);
16127 +       return 0;
16128 +}
16129 +#endif
16130 +
16131 +#if 0
16132 +void vx_mask_cap_bset(struct vx_info *vxi, struct task_struct *p)
16133 +{
16134 +       // p->cap_effective &= vxi->vx_cap_bset;
16135 +       p->cap_effective =
16136 +               cap_intersect(p->cap_effective, vxi->cap_bset);
16137 +       // p->cap_inheritable &= vxi->vx_cap_bset;
16138 +       p->cap_inheritable =
16139 +               cap_intersect(p->cap_inheritable, vxi->cap_bset);
16140 +       // p->cap_permitted &= vxi->vx_cap_bset;
16141 +       p->cap_permitted =
16142 +               cap_intersect(p->cap_permitted, vxi->cap_bset);
16143 +}
16144 +#endif
16145 +
16146 +
16147 +#include <linux/file.h>
16148 +#include <linux/fdtable.h>
16149 +
16150 +static int vx_openfd_task(struct task_struct *tsk)
16151 +{
16152 +       struct files_struct *files = tsk->files;
16153 +       struct fdtable *fdt;
16154 +       const unsigned long *bptr;
16155 +       int count, total;
16156 +
16157 +       /* no rcu_read_lock() because of spin_lock() */
16158 +       spin_lock(&files->file_lock);
16159 +       fdt = files_fdtable(files);
16160 +       bptr = fdt->open_fds;
16161 +       count = fdt->max_fds / (sizeof(unsigned long) * 8);
16162 +       for (total = 0; count > 0; count--) {
16163 +               if (*bptr)
16164 +                       total += hweight_long(*bptr);
16165 +               bptr++;
16166 +       }
16167 +       spin_unlock(&files->file_lock);
16168 +       return total;
16169 +}
16170 +
16171 +
16172 +/*     for *space compatibility */
16173 +
16174 +asmlinkage long sys_unshare(unsigned long);
16175 +
16176 +/*
16177 + *     migrate task to new context
16178 + *     gets vxi, puts old_vxi on change
16179 + *     optionally unshares namespaces (hack)
16180 + */
16181 +
16182 +int vx_migrate_task(struct task_struct *p, struct vx_info *vxi, int unshare)
16183 +{
16184 +       struct vx_info *old_vxi;
16185 +       int ret = 0;
16186 +
16187 +       if (!p || !vxi)
16188 +               BUG();
16189 +
16190 +       vxdprintk(VXD_CBIT(xid, 5),
16191 +               "vx_migrate_task(%p,%p[#%d.%d])", p, vxi,
16192 +               vxi->vx_id, atomic_read(&vxi->vx_usecnt));
16193 +
16194 +       if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0) &&
16195 +               !vx_info_flags(vxi, VXF_STATE_SETUP, 0))
16196 +               return -EACCES;
16197 +
16198 +       if (vx_info_state(vxi, VXS_SHUTDOWN))
16199 +               return -EFAULT;
16200 +
16201 +       old_vxi = task_get_vx_info(p);
16202 +       if (old_vxi == vxi)
16203 +               goto out;
16204 +
16205 +//     if (!(ret = vx_migrate_user(p, vxi))) {
16206 +       {
16207 +               int openfd;
16208 +
16209 +               task_lock(p);
16210 +               openfd = vx_openfd_task(p);
16211 +
16212 +               if (old_vxi) {
16213 +                       atomic_dec(&old_vxi->cvirt.nr_threads);
16214 +                       atomic_dec(&old_vxi->cvirt.nr_running);
16215 +                       __rlim_dec(&old_vxi->limit, RLIMIT_NPROC);
16216 +                       /* FIXME: what about the struct files here? */
16217 +                       __rlim_sub(&old_vxi->limit, VLIMIT_OPENFD, openfd);
16218 +                       /* account for the executable */
16219 +                       __rlim_dec(&old_vxi->limit, VLIMIT_DENTRY);
16220 +               }
16221 +               atomic_inc(&vxi->cvirt.nr_threads);
16222 +               atomic_inc(&vxi->cvirt.nr_running);
16223 +               __rlim_inc(&vxi->limit, RLIMIT_NPROC);
16224 +               /* FIXME: what about the struct files here? */
16225 +               __rlim_add(&vxi->limit, VLIMIT_OPENFD, openfd);
16226 +               /* account for the executable */
16227 +               __rlim_inc(&vxi->limit, VLIMIT_DENTRY);
16228 +
16229 +               if (old_vxi) {
16230 +                       release_vx_info(old_vxi, p);
16231 +                       clr_vx_info(&p->vx_info);
16232 +               }
16233 +               claim_vx_info(vxi, p);
16234 +               set_vx_info(&p->vx_info, vxi);
16235 +               p->xid = vxi->vx_id;
16236 +
16237 +               vxdprintk(VXD_CBIT(xid, 5),
16238 +                       "moved task %p into vxi:%p[#%d]",
16239 +                       p, vxi, vxi->vx_id);
16240 +
16241 +               // vx_mask_cap_bset(vxi, p);
16242 +               task_unlock(p);
16243 +
16244 +               /* hack for *spaces to provide compatibility */
16245 +               if (unshare) {
16246 +                       struct nsproxy *old_nsp, *new_nsp;
16247 +
16248 +                       ret = unshare_nsproxy_namespaces(
16249 +                               CLONE_NEWUTS | CLONE_NEWIPC | CLONE_NEWUSER,
16250 +                               &new_nsp, NULL, NULL);
16251 +                       if (ret)
16252 +                               goto out;
16253 +
16254 +                       old_nsp = xchg(&p->nsproxy, new_nsp);
16255 +                       vx_set_space(vxi,
16256 +                               CLONE_NEWUTS | CLONE_NEWIPC | CLONE_NEWUSER, 0);
16257 +                       put_nsproxy(old_nsp);
16258 +               }
16259 +       }
16260 +out:
16261 +       put_vx_info(old_vxi);
16262 +       return ret;
16263 +}
16264 +
16265 +int vx_set_reaper(struct vx_info *vxi, struct task_struct *p)
16266 +{
16267 +       struct task_struct *old_reaper;
16268 +       struct vx_info *reaper_vxi;
16269 +
16270 +       if (!vxi)
16271 +               return -EINVAL;
16272 +
16273 +       vxdprintk(VXD_CBIT(xid, 6),
16274 +               "vx_set_reaper(%p[#%d],%p[#%d,%d])",
16275 +               vxi, vxi->vx_id, p, p->xid, p->pid);
16276 +
16277 +       old_reaper = vxi->vx_reaper;
16278 +       if (old_reaper == p)
16279 +               return 0;
16280 +
16281 +       reaper_vxi = task_get_vx_info(p);
16282 +       if (reaper_vxi && reaper_vxi != vxi) {
16283 +               vxwprintk(1,
16284 +                       "Unsuitable reaper [" VS_Q("%s") ",%u:#%u] "
16285 +                       "for [xid #%u]",
16286 +                       p->comm, p->pid, p->xid, vx_current_xid());
16287 +               goto out;
16288 +       }
16289 +
16290 +       /* set new child reaper */
16291 +       get_task_struct(p);
16292 +       vxi->vx_reaper = p;
16293 +       put_task_struct(old_reaper);
16294 +out:
16295 +       put_vx_info(reaper_vxi);
16296 +       return 0;
16297 +}
16298 +
16299 +int vx_set_init(struct vx_info *vxi, struct task_struct *p)
16300 +{
16301 +       if (!vxi)
16302 +               return -EINVAL;
16303 +
16304 +       vxdprintk(VXD_CBIT(xid, 6),
16305 +               "vx_set_init(%p[#%d],%p[#%d,%d,%d])",
16306 +               vxi, vxi->vx_id, p, p->xid, p->pid, p->tgid);
16307 +
16308 +       vxi->vx_flags &= ~VXF_STATE_INIT;
16309 +       // vxi->vx_initpid = p->tgid;
16310 +       vxi->vx_initpid = p->pid;
16311 +       return 0;
16312 +}
16313 +
16314 +void vx_exit_init(struct vx_info *vxi, struct task_struct *p, int code)
16315 +{
16316 +       vxdprintk(VXD_CBIT(xid, 6),
16317 +               "vx_exit_init(%p[#%d],%p[#%d,%d,%d])",
16318 +               vxi, vxi->vx_id, p, p->xid, p->pid, p->tgid);
16319 +
16320 +       vxi->exit_code = code;
16321 +       vxi->vx_initpid = 0;
16322 +}
16323 +
16324 +
16325 +void vx_set_persistent(struct vx_info *vxi)
16326 +{
16327 +       vxdprintk(VXD_CBIT(xid, 6),
16328 +               "vx_set_persistent(%p[#%d])", vxi, vxi->vx_id);
16329 +
16330 +       get_vx_info(vxi);
16331 +       claim_vx_info(vxi, NULL);
16332 +}
16333 +
16334 +void vx_clear_persistent(struct vx_info *vxi)
16335 +{
16336 +       vxdprintk(VXD_CBIT(xid, 6),
16337 +               "vx_clear_persistent(%p[#%d])", vxi, vxi->vx_id);
16338 +
16339 +       release_vx_info(vxi, NULL);
16340 +       put_vx_info(vxi);
16341 +}
16342 +
16343 +void vx_update_persistent(struct vx_info *vxi)
16344 +{
16345 +       if (vx_info_flags(vxi, VXF_PERSISTENT, 0))
16346 +               vx_set_persistent(vxi);
16347 +       else
16348 +               vx_clear_persistent(vxi);
16349 +}
16350 +
16351 +
16352 +/*     task must be current or locked          */
16353 +
16354 +void   exit_vx_info(struct task_struct *p, int code)
16355 +{
16356 +       struct vx_info *vxi = p->vx_info;
16357 +
16358 +       if (vxi) {
16359 +               atomic_dec(&vxi->cvirt.nr_threads);
16360 +               vx_nproc_dec(p);
16361 +
16362 +               vxi->exit_code = code;
16363 +               release_vx_info(vxi, p);
16364 +       }
16365 +}
16366 +
16367 +void   exit_vx_info_early(struct task_struct *p, int code)
16368 +{
16369 +       struct vx_info *vxi = p->vx_info;
16370 +
16371 +       if (vxi) {
16372 +               if (vxi->vx_initpid == p->pid)
16373 +                       vx_exit_init(vxi, p, code);
16374 +               if (vxi->vx_reaper == p)
16375 +                       vx_set_reaper(vxi, init_pid_ns.child_reaper);
16376 +       }
16377 +}
16378 +
16379 +
16380 +/* vserver syscall commands below here */
16381 +
16382 +/* taks xid and vx_info functions */
16383 +
16384 +#include <asm/uaccess.h>
16385 +
16386 +
16387 +int vc_task_xid(uint32_t id)
16388 +{
16389 +       xid_t xid;
16390 +
16391 +       if (id) {
16392 +               struct task_struct *tsk;
16393 +
16394 +               rcu_read_lock();
16395 +               tsk = find_task_by_real_pid(id);
16396 +               xid = (tsk) ? tsk->xid : -ESRCH;
16397 +               rcu_read_unlock();
16398 +       } else
16399 +               xid = vx_current_xid();
16400 +       return xid;
16401 +}
16402 +
16403 +
16404 +int vc_vx_info(struct vx_info *vxi, void __user *data)
16405 +{
16406 +       struct vcmd_vx_info_v0 vc_data;
16407 +
16408 +       vc_data.xid = vxi->vx_id;
16409 +       vc_data.initpid = vxi->vx_initpid;
16410 +
16411 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16412 +               return -EFAULT;
16413 +       return 0;
16414 +}
16415 +
16416 +
16417 +int vc_ctx_stat(struct vx_info *vxi, void __user *data)
16418 +{
16419 +       struct vcmd_ctx_stat_v0 vc_data;
16420 +
16421 +       vc_data.usecnt = atomic_read(&vxi->vx_usecnt);
16422 +       vc_data.tasks = atomic_read(&vxi->vx_tasks);
16423 +
16424 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16425 +               return -EFAULT;
16426 +       return 0;
16427 +}
16428 +
16429 +
16430 +/* context functions */
16431 +
16432 +int vc_ctx_create(uint32_t xid, void __user *data)
16433 +{
16434 +       struct vcmd_ctx_create vc_data = { .flagword = VXF_INIT_SET };
16435 +       struct vx_info *new_vxi;
16436 +       int ret;
16437 +
16438 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
16439 +               return -EFAULT;
16440 +
16441 +       if ((xid > MAX_S_CONTEXT) || (xid < 2))
16442 +               return -EINVAL;
16443 +
16444 +       new_vxi = __create_vx_info(xid);
16445 +       if (IS_ERR(new_vxi))
16446 +               return PTR_ERR(new_vxi);
16447 +
16448 +       /* initial flags */
16449 +       new_vxi->vx_flags = vc_data.flagword;
16450 +
16451 +       ret = -ENOEXEC;
16452 +       if (vs_state_change(new_vxi, VSC_STARTUP))
16453 +               goto out;
16454 +
16455 +       ret = vx_migrate_task(current, new_vxi, (!data));
16456 +       if (ret)
16457 +               goto out;
16458 +
16459 +       /* return context id on success */
16460 +       ret = new_vxi->vx_id;
16461 +
16462 +       /* get a reference for persistent contexts */
16463 +       if ((vc_data.flagword & VXF_PERSISTENT))
16464 +               vx_set_persistent(new_vxi);
16465 +out:
16466 +       release_vx_info(new_vxi, NULL);
16467 +       put_vx_info(new_vxi);
16468 +       return ret;
16469 +}
16470 +
16471 +
16472 +int vc_ctx_migrate(struct vx_info *vxi, void __user *data)
16473 +{
16474 +       struct vcmd_ctx_migrate vc_data = { .flagword = 0 };
16475 +       int ret;
16476 +
16477 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
16478 +               return -EFAULT;
16479 +
16480 +       ret = vx_migrate_task(current, vxi, 0);
16481 +       if (ret)
16482 +               return ret;
16483 +       if (vc_data.flagword & VXM_SET_INIT)
16484 +               ret = vx_set_init(vxi, current);
16485 +       if (ret)
16486 +               return ret;
16487 +       if (vc_data.flagword & VXM_SET_REAPER)
16488 +               ret = vx_set_reaper(vxi, current);
16489 +       return ret;
16490 +}
16491 +
16492 +
16493 +int vc_get_cflags(struct vx_info *vxi, void __user *data)
16494 +{
16495 +       struct vcmd_ctx_flags_v0 vc_data;
16496 +
16497 +       vc_data.flagword = vxi->vx_flags;
16498 +
16499 +       /* special STATE flag handling */
16500 +       vc_data.mask = vs_mask_flags(~0ULL, vxi->vx_flags, VXF_ONE_TIME);
16501 +
16502 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16503 +               return -EFAULT;
16504 +       return 0;
16505 +}
16506 +
16507 +int vc_set_cflags(struct vx_info *vxi, void __user *data)
16508 +{
16509 +       struct vcmd_ctx_flags_v0 vc_data;
16510 +       uint64_t mask, trigger;
16511 +
16512 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16513 +               return -EFAULT;
16514 +
16515 +       /* special STATE flag handling */
16516 +       mask = vs_mask_mask(vc_data.mask, vxi->vx_flags, VXF_ONE_TIME);
16517 +       trigger = (mask & vxi->vx_flags) ^ (mask & vc_data.flagword);
16518 +
16519 +       if (vxi == current_vx_info()) {
16520 +               /* if (trigger & VXF_STATE_SETUP)
16521 +                       vx_mask_cap_bset(vxi, current); */
16522 +               if (trigger & VXF_STATE_INIT) {
16523 +                       int ret;
16524 +
16525 +                       ret = vx_set_init(vxi, current);
16526 +                       if (ret)
16527 +                               return ret;
16528 +                       ret = vx_set_reaper(vxi, current);
16529 +                       if (ret)
16530 +                               return ret;
16531 +               }
16532 +       }
16533 +
16534 +       vxi->vx_flags = vs_mask_flags(vxi->vx_flags,
16535 +               vc_data.flagword, mask);
16536 +       if (trigger & VXF_PERSISTENT)
16537 +               vx_update_persistent(vxi);
16538 +
16539 +       return 0;
16540 +}
16541 +
16542 +
16543 +static inline uint64_t caps_from_cap_t(kernel_cap_t c)
16544 +{
16545 +       uint64_t v = c.cap[0] | ((uint64_t)c.cap[1] << 32);
16546 +
16547 +       // printk("caps_from_cap_t(%08x:%08x) = %016llx\n", c.cap[1], c.cap[0], v);
16548 +       return v;
16549 +}
16550 +
16551 +static inline kernel_cap_t cap_t_from_caps(uint64_t v)
16552 +{
16553 +       kernel_cap_t c = __cap_empty_set;
16554 +
16555 +       c.cap[0] = v & 0xFFFFFFFF;
16556 +       c.cap[1] = (v >> 32) & 0xFFFFFFFF;
16557 +
16558 +       // printk("cap_t_from_caps(%016llx) = %08x:%08x\n", v, c.cap[1], c.cap[0]);
16559 +       return c;
16560 +}
16561 +
16562 +
16563 +static int do_get_caps(struct vx_info *vxi, uint64_t *bcaps, uint64_t *ccaps)
16564 +{
16565 +       if (bcaps)
16566 +               *bcaps = caps_from_cap_t(vxi->vx_bcaps);
16567 +       if (ccaps)
16568 +               *ccaps = vxi->vx_ccaps;
16569 +
16570 +       return 0;
16571 +}
16572 +
16573 +int vc_get_ccaps(struct vx_info *vxi, void __user *data)
16574 +{
16575 +       struct vcmd_ctx_caps_v1 vc_data;
16576 +       int ret;
16577 +
16578 +       ret = do_get_caps(vxi, NULL, &vc_data.ccaps);
16579 +       if (ret)
16580 +               return ret;
16581 +       vc_data.cmask = ~0ULL;
16582 +
16583 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16584 +               return -EFAULT;
16585 +       return 0;
16586 +}
16587 +
16588 +static int do_set_caps(struct vx_info *vxi,
16589 +       uint64_t bcaps, uint64_t bmask, uint64_t ccaps, uint64_t cmask)
16590 +{
16591 +       uint64_t bcold = caps_from_cap_t(vxi->vx_bcaps);
16592 +
16593 +#if 0
16594 +       printk("do_set_caps(%16llx, %16llx, %16llx, %16llx)\n",
16595 +               bcaps, bmask, ccaps, cmask);
16596 +#endif
16597 +       vxi->vx_bcaps = cap_t_from_caps(
16598 +               vs_mask_flags(bcold, bcaps, bmask));
16599 +       vxi->vx_ccaps = vs_mask_flags(vxi->vx_ccaps, ccaps, cmask);
16600 +
16601 +       return 0;
16602 +}
16603 +
16604 +int vc_set_ccaps(struct vx_info *vxi, void __user *data)
16605 +{
16606 +       struct vcmd_ctx_caps_v1 vc_data;
16607 +
16608 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16609 +               return -EFAULT;
16610 +
16611 +       return do_set_caps(vxi, 0, 0, vc_data.ccaps, vc_data.cmask);
16612 +}
16613 +
16614 +int vc_get_bcaps(struct vx_info *vxi, void __user *data)
16615 +{
16616 +       struct vcmd_bcaps vc_data;
16617 +       int ret;
16618 +
16619 +       ret = do_get_caps(vxi, &vc_data.bcaps, NULL);
16620 +       if (ret)
16621 +               return ret;
16622 +       vc_data.bmask = ~0ULL;
16623 +
16624 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16625 +               return -EFAULT;
16626 +       return 0;
16627 +}
16628 +
16629 +int vc_set_bcaps(struct vx_info *vxi, void __user *data)
16630 +{
16631 +       struct vcmd_bcaps vc_data;
16632 +
16633 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16634 +               return -EFAULT;
16635 +
16636 +       return do_set_caps(vxi, vc_data.bcaps, vc_data.bmask, 0, 0);
16637 +}
16638 +
16639 +
16640 +int vc_get_umask(struct vx_info *vxi, void __user *data)
16641 +{
16642 +       struct vcmd_umask vc_data;
16643 +
16644 +       vc_data.umask = vxi->vx_umask;
16645 +       vc_data.mask = ~0ULL;
16646 +
16647 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16648 +               return -EFAULT;
16649 +       return 0;
16650 +}
16651 +
16652 +int vc_set_umask(struct vx_info *vxi, void __user *data)
16653 +{
16654 +       struct vcmd_umask vc_data;
16655 +
16656 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16657 +               return -EFAULT;
16658 +
16659 +       vxi->vx_umask = vs_mask_flags(vxi->vx_umask,
16660 +               vc_data.umask, vc_data.mask);
16661 +       return 0;
16662 +}
16663 +
16664 +
16665 +int vc_get_wmask(struct vx_info *vxi, void __user *data)
16666 +{
16667 +       struct vcmd_wmask vc_data;
16668 +
16669 +       vc_data.wmask = vxi->vx_wmask;
16670 +       vc_data.mask = ~0ULL;
16671 +
16672 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16673 +               return -EFAULT;
16674 +       return 0;
16675 +}
16676 +
16677 +int vc_set_wmask(struct vx_info *vxi, void __user *data)
16678 +{
16679 +       struct vcmd_wmask vc_data;
16680 +
16681 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16682 +               return -EFAULT;
16683 +
16684 +       vxi->vx_wmask = vs_mask_flags(vxi->vx_wmask,
16685 +               vc_data.wmask, vc_data.mask);
16686 +       return 0;
16687 +}
16688 +
16689 +
16690 +int vc_get_badness(struct vx_info *vxi, void __user *data)
16691 +{
16692 +       struct vcmd_badness_v0 vc_data;
16693 +
16694 +       vc_data.bias = vxi->vx_badness_bias;
16695 +
16696 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16697 +               return -EFAULT;
16698 +       return 0;
16699 +}
16700 +
16701 +int vc_set_badness(struct vx_info *vxi, void __user *data)
16702 +{
16703 +       struct vcmd_badness_v0 vc_data;
16704 +
16705 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16706 +               return -EFAULT;
16707 +
16708 +       vxi->vx_badness_bias = vc_data.bias;
16709 +       return 0;
16710 +}
16711 +
16712 +#include <linux/module.h>
16713 +
16714 +EXPORT_SYMBOL_GPL(free_vx_info);
16715 +
16716 diff -NurpP --minimal linux-3.9.4/kernel/vserver/cvirt.c linux-3.9.4-vs2.3.6.2/kernel/vserver/cvirt.c
16717 --- linux-3.9.4/kernel/vserver/cvirt.c  1970-01-01 00:00:00.000000000 +0000
16718 +++ linux-3.9.4-vs2.3.6.2/kernel/vserver/cvirt.c        2013-05-31 14:47:11.000000000 +0000
16719 @@ -0,0 +1,313 @@
16720 +/*
16721 + *  linux/kernel/vserver/cvirt.c
16722 + *
16723 + *  Virtual Server: Context Virtualization
16724 + *
16725 + *  Copyright (C) 2004-2007  Herbert Pötzl
16726 + *
16727 + *  V0.01  broken out from limit.c
16728 + *  V0.02  added utsname stuff
16729 + *  V0.03  changed vcmds to vxi arg
16730 + *
16731 + */
16732 +
16733 +#include <linux/types.h>
16734 +#include <linux/utsname.h>
16735 +#include <linux/vs_cvirt.h>
16736 +#include <linux/vserver/switch.h>
16737 +#include <linux/vserver/cvirt_cmd.h>
16738 +
16739 +#include <asm/uaccess.h>
16740 +
16741 +
16742 +void vx_vsi_boottime(struct timespec *boottime)
16743 +{
16744 +       struct vx_info *vxi = current_vx_info();
16745 +
16746 +       set_normalized_timespec(boottime,
16747 +               boottime->tv_sec + vxi->cvirt.bias_uptime.tv_sec,
16748 +               boottime->tv_nsec + vxi->cvirt.bias_uptime.tv_nsec);
16749 +       return;
16750 +}
16751 +
16752 +void vx_vsi_uptime(struct timespec *uptime, struct timespec *idle)
16753 +{
16754 +       struct vx_info *vxi = current_vx_info();
16755 +
16756 +       set_normalized_timespec(uptime,
16757 +               uptime->tv_sec - vxi->cvirt.bias_uptime.tv_sec,
16758 +               uptime->tv_nsec - vxi->cvirt.bias_uptime.tv_nsec);
16759 +       if (!idle)
16760 +               return;
16761 +       set_normalized_timespec(idle,
16762 +               idle->tv_sec - vxi->cvirt.bias_idle.tv_sec,
16763 +               idle->tv_nsec - vxi->cvirt.bias_idle.tv_nsec);
16764 +       return;
16765 +}
16766 +
16767 +uint64_t vx_idle_jiffies(void)
16768 +{
16769 +       return init_task.utime + init_task.stime;
16770 +}
16771 +
16772 +
16773 +
16774 +static inline uint32_t __update_loadavg(uint32_t load,
16775 +       int wsize, int delta, int n)
16776 +{
16777 +       unsigned long long calc, prev;
16778 +
16779 +       /* just set it to n */
16780 +       if (unlikely(delta >= wsize))
16781 +               return (n << FSHIFT);
16782 +
16783 +       calc = delta * n;
16784 +       calc <<= FSHIFT;
16785 +       prev = (wsize - delta);
16786 +       prev *= load;
16787 +       calc += prev;
16788 +       do_div(calc, wsize);
16789 +       return calc;
16790 +}
16791 +
16792 +
16793 +void vx_update_load(struct vx_info *vxi)
16794 +{
16795 +       uint32_t now, last, delta;
16796 +       unsigned int nr_running, nr_uninterruptible;
16797 +       unsigned int total;
16798 +       unsigned long flags;
16799 +
16800 +       spin_lock_irqsave(&vxi->cvirt.load_lock, flags);
16801 +
16802 +       now = jiffies;
16803 +       last = vxi->cvirt.load_last;
16804 +       delta = now - last;
16805 +
16806 +       if (delta < 5*HZ)
16807 +               goto out;
16808 +
16809 +       nr_running = atomic_read(&vxi->cvirt.nr_running);
16810 +       nr_uninterruptible = atomic_read(&vxi->cvirt.nr_uninterruptible);
16811 +       total = nr_running + nr_uninterruptible;
16812 +
16813 +       vxi->cvirt.load[0] = __update_loadavg(vxi->cvirt.load[0],
16814 +               60*HZ, delta, total);
16815 +       vxi->cvirt.load[1] = __update_loadavg(vxi->cvirt.load[1],
16816 +               5*60*HZ, delta, total);
16817 +       vxi->cvirt.load[2] = __update_loadavg(vxi->cvirt.load[2],
16818 +               15*60*HZ, delta, total);
16819 +
16820 +       vxi->cvirt.load_last = now;
16821 +out:
16822 +       atomic_inc(&vxi->cvirt.load_updates);
16823 +       spin_unlock_irqrestore(&vxi->cvirt.load_lock, flags);
16824 +}
16825 +
16826 +
16827 +/*
16828 + * Commands to do_syslog:
16829 + *
16830 + *      0 -- Close the log.  Currently a NOP.
16831 + *      1 -- Open the log. Currently a NOP.
16832 + *      2 -- Read from the log.
16833 + *      3 -- Read all messages remaining in the ring buffer.
16834 + *      4 -- Read and clear all messages remaining in the ring buffer
16835 + *      5 -- Clear ring buffer.
16836 + *      6 -- Disable printk's to console
16837 + *      7 -- Enable printk's to console
16838 + *      8 -- Set level of messages printed to console
16839 + *      9 -- Return number of unread characters in the log buffer
16840 + *     10 -- Return size of the log buffer
16841 + */
16842 +int vx_do_syslog(int type, char __user *buf, int len)
16843 +{
16844 +       int error = 0;
16845 +       int do_clear = 0;
16846 +       struct vx_info *vxi = current_vx_info();
16847 +       struct _vx_syslog *log;
16848 +
16849 +       if (!vxi)
16850 +               return -EINVAL;
16851 +       log = &vxi->cvirt.syslog;
16852 +
16853 +       switch (type) {
16854 +       case 0:         /* Close log */
16855 +       case 1:         /* Open log */
16856 +               break;
16857 +       case 2:         /* Read from log */
16858 +               error = wait_event_interruptible(log->log_wait,
16859 +                       (log->log_start - log->log_end));
16860 +               if (error)
16861 +                       break;
16862 +               spin_lock_irq(&log->logbuf_lock);
16863 +               spin_unlock_irq(&log->logbuf_lock);
16864 +               break;
16865 +       case 4:         /* Read/clear last kernel messages */
16866 +               do_clear = 1;
16867 +               /* fall through */
16868 +       case 3:         /* Read last kernel messages */
16869 +               return 0;
16870 +
16871 +       case 5:         /* Clear ring buffer */
16872 +               return 0;
16873 +
16874 +       case 6:         /* Disable logging to console */
16875 +       case 7:         /* Enable logging to console */
16876 +       case 8:         /* Set level of messages printed to console */
16877 +               break;
16878 +
16879 +       case 9:         /* Number of chars in the log buffer */
16880 +               return 0;
16881 +       case 10:        /* Size of the log buffer */
16882 +               return 0;
16883 +       default:
16884 +               error = -EINVAL;
16885 +               break;
16886 +       }
16887 +       return error;
16888 +}
16889 +
16890 +
16891 +/* virtual host info names */
16892 +
16893 +static char *vx_vhi_name(struct vx_info *vxi, int id)
16894 +{
16895 +       struct nsproxy *nsproxy;
16896 +       struct uts_namespace *uts;
16897 +
16898 +       if (id == VHIN_CONTEXT)
16899 +               return vxi->vx_name;
16900 +
16901 +       nsproxy = vxi->space[0].vx_nsproxy;
16902 +       if (!nsproxy)
16903 +               return NULL;
16904 +
16905 +       uts = nsproxy->uts_ns;
16906 +       if (!uts)
16907 +               return NULL;
16908 +
16909 +       switch (id) {
16910 +       case VHIN_SYSNAME:
16911 +               return uts->name.sysname;
16912 +       case VHIN_NODENAME:
16913 +               return uts->name.nodename;
16914 +       case VHIN_RELEASE:
16915 +               return uts->name.release;
16916 +       case VHIN_VERSION:
16917 +               return uts->name.version;
16918 +       case VHIN_MACHINE:
16919 +               return uts->name.machine;
16920 +       case VHIN_DOMAINNAME:
16921 +               return uts->name.domainname;
16922 +       default:
16923 +               return NULL;
16924 +       }
16925 +       return NULL;
16926 +}
16927 +
16928 +int vc_set_vhi_name(struct vx_info *vxi, void __user *data)
16929 +{
16930 +       struct vcmd_vhi_name_v0 vc_data;
16931 +       char *name;
16932 +
16933 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16934 +               return -EFAULT;
16935 +
16936 +       name = vx_vhi_name(vxi, vc_data.field);
16937 +       if (!name)
16938 +               return -EINVAL;
16939 +
16940 +       memcpy(name, vc_data.name, 65);
16941 +       return 0;
16942 +}
16943 +
16944 +int vc_get_vhi_name(struct vx_info *vxi, void __user *data)
16945 +{
16946 +       struct vcmd_vhi_name_v0 vc_data;
16947 +       char *name;
16948 +
16949 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16950 +               return -EFAULT;
16951 +
16952 +       name = vx_vhi_name(vxi, vc_data.field);
16953 +       if (!name)
16954 +               return -EINVAL;
16955 +
16956 +       memcpy(vc_data.name, name, 65);
16957 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16958 +               return -EFAULT;
16959 +       return 0;
16960 +}
16961 +
16962 +
16963 +int vc_virt_stat(struct vx_info *vxi, void __user *data)
16964 +{
16965 +       struct vcmd_virt_stat_v0 vc_data;
16966 +       struct _vx_cvirt *cvirt = &vxi->cvirt;
16967 +       struct timespec uptime;
16968 +
16969 +       do_posix_clock_monotonic_gettime(&uptime);
16970 +       set_normalized_timespec(&uptime,
16971 +               uptime.tv_sec - cvirt->bias_uptime.tv_sec,
16972 +               uptime.tv_nsec - cvirt->bias_uptime.tv_nsec);
16973 +
16974 +       vc_data.offset = timespec_to_ns(&cvirt->bias_ts);
16975 +       vc_data.uptime = timespec_to_ns(&uptime);
16976 +       vc_data.nr_threads = atomic_read(&cvirt->nr_threads);
16977 +       vc_data.nr_running = atomic_read(&cvirt->nr_running);
16978 +       vc_data.nr_uninterruptible = atomic_read(&cvirt->nr_uninterruptible);
16979 +       vc_data.nr_onhold = atomic_read(&cvirt->nr_onhold);
16980 +       vc_data.nr_forks = atomic_read(&cvirt->total_forks);
16981 +       vc_data.load[0] = cvirt->load[0];
16982 +       vc_data.load[1] = cvirt->load[1];
16983 +       vc_data.load[2] = cvirt->load[2];
16984 +
16985 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16986 +               return -EFAULT;
16987 +       return 0;
16988 +}
16989 +
16990 +
16991 +#ifdef CONFIG_VSERVER_VTIME
16992 +
16993 +/* virtualized time base */
16994 +
16995 +void vx_adjust_timespec(struct timespec *ts)
16996 +{
16997 +       struct vx_info *vxi;
16998 +
16999 +       if (!vx_flags(VXF_VIRT_TIME, 0))
17000 +               return;
17001 +
17002 +       vxi = current_vx_info();
17003 +       ts->tv_sec += vxi->cvirt.bias_ts.tv_sec;
17004 +       ts->tv_nsec += vxi->cvirt.bias_ts.tv_nsec;
17005 +
17006 +       if (ts->tv_nsec >= NSEC_PER_SEC) {
17007 +               ts->tv_sec++;
17008 +               ts->tv_nsec -= NSEC_PER_SEC;
17009 +       } else if (ts->tv_nsec < 0) {
17010 +               ts->tv_sec--;
17011 +               ts->tv_nsec += NSEC_PER_SEC;
17012 +       }
17013 +}
17014 +
17015 +int vx_settimeofday(const struct timespec *ts)
17016 +{
17017 +       struct timespec ats, delta;
17018 +       struct vx_info *vxi;
17019 +
17020 +       if (!vx_flags(VXF_VIRT_TIME, 0))
17021 +               return do_settimeofday(ts);
17022 +
17023 +       getnstimeofday(&ats);
17024 +       delta = timespec_sub(*ts, ats);
17025 +
17026 +       vxi = current_vx_info();
17027 +       vxi->cvirt.bias_ts = timespec_add(vxi->cvirt.bias_ts, delta);
17028 +       return 0;
17029 +}
17030 +
17031 +#endif
17032 +
17033 diff -NurpP --minimal linux-3.9.4/kernel/vserver/cvirt_init.h linux-3.9.4-vs2.3.6.2/kernel/vserver/cvirt_init.h
17034 --- linux-3.9.4/kernel/vserver/cvirt_init.h     1970-01-01 00:00:00.000000000 +0000
17035 +++ linux-3.9.4-vs2.3.6.2/kernel/vserver/cvirt_init.h   2013-05-31 14:47:11.000000000 +0000
17036 @@ -0,0 +1,70 @@
17037 +
17038 +
17039 +extern uint64_t vx_idle_jiffies(void);
17040 +
17041 +static inline void vx_info_init_cvirt(struct _vx_cvirt *cvirt)
17042 +{
17043 +       uint64_t idle_jiffies = vx_idle_jiffies();
17044 +       uint64_t nsuptime;
17045 +
17046 +       do_posix_clock_monotonic_gettime(&cvirt->bias_uptime);
17047 +       nsuptime = (unsigned long long)cvirt->bias_uptime.tv_sec
17048 +               * NSEC_PER_SEC + cvirt->bias_uptime.tv_nsec;
17049 +       cvirt->bias_clock = nsec_to_clock_t(nsuptime);
17050 +       cvirt->bias_ts.tv_sec = 0;
17051 +       cvirt->bias_ts.tv_nsec = 0;
17052 +
17053 +       jiffies_to_timespec(idle_jiffies, &cvirt->bias_idle);
17054 +       atomic_set(&cvirt->nr_threads, 0);
17055 +       atomic_set(&cvirt->nr_running, 0);
17056 +       atomic_set(&cvirt->nr_uninterruptible, 0);
17057 +       atomic_set(&cvirt->nr_onhold, 0);
17058 +
17059 +       spin_lock_init(&cvirt->load_lock);
17060 +       cvirt->load_last = jiffies;
17061 +       atomic_set(&cvirt->load_updates, 0);
17062 +       cvirt->load[0] = 0;
17063 +       cvirt->load[1] = 0;
17064 +       cvirt->load[2] = 0;
17065 +       atomic_set(&cvirt->total_forks, 0);
17066 +
17067 +       spin_lock_init(&cvirt->syslog.logbuf_lock);
17068 +       init_waitqueue_head(&cvirt->syslog.log_wait);
17069 +       cvirt->syslog.log_start = 0;
17070 +       cvirt->syslog.log_end = 0;
17071 +       cvirt->syslog.con_start = 0;
17072 +       cvirt->syslog.logged_chars = 0;
17073 +}
17074 +
17075 +static inline
17076 +void vx_info_init_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc, int cpu)
17077 +{
17078 +       // cvirt_pc->cpustat = { 0 };
17079 +}
17080 +
17081 +static inline void vx_info_exit_cvirt(struct _vx_cvirt *cvirt)
17082 +{
17083 +#ifdef CONFIG_VSERVER_WARN
17084 +       int value;
17085 +#endif
17086 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_threads)),
17087 +               "!!! cvirt: %p[nr_threads] = %d on exit.",
17088 +               cvirt, value);
17089 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_running)),
17090 +               "!!! cvirt: %p[nr_running] = %d on exit.",
17091 +               cvirt, value);
17092 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_uninterruptible)),
17093 +               "!!! cvirt: %p[nr_uninterruptible] = %d on exit.",
17094 +               cvirt, value);
17095 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_onhold)),
17096 +               "!!! cvirt: %p[nr_onhold] = %d on exit.",
17097 +               cvirt, value);
17098 +       return;
17099 +}
17100 +
17101 +static inline
17102 +void vx_info_exit_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc, int cpu)
17103 +{
17104 +       return;
17105 +}
17106 +
17107 diff -NurpP --minimal linux-3.9.4/kernel/vserver/cvirt_proc.h linux-3.9.4-vs2.3.6.2/kernel/vserver/cvirt_proc.h
17108 --- linux-3.9.4/kernel/vserver/cvirt_proc.h     1970-01-01 00:00:00.000000000 +0000
17109 +++ linux-3.9.4-vs2.3.6.2/kernel/vserver/cvirt_proc.h   2013-05-31 19:38:26.000000000 +0000
17110 @@ -0,0 +1,123 @@
17111 +#ifndef _VX_CVIRT_PROC_H
17112 +#define _VX_CVIRT_PROC_H
17113 +
17114 +#include <linux/nsproxy.h>
17115 +#include <linux/mnt_namespace.h>
17116 +#include <linux/ipc_namespace.h>
17117 +#include <linux/utsname.h>
17118 +#include <linux/ipc.h>
17119 +
17120 +extern int vx_info_mnt_namespace(struct mnt_namespace *, char *);
17121 +
17122 +static inline
17123 +int vx_info_proc_nsproxy(struct nsproxy *nsproxy, char *buffer)
17124 +{
17125 +       struct mnt_namespace *ns;
17126 +       struct uts_namespace *uts;
17127 +       struct ipc_namespace *ipc;
17128 +       int length = 0;
17129 +
17130 +       if (!nsproxy)
17131 +               goto out;
17132 +
17133 +       length += sprintf(buffer + length,
17134 +               "NSProxy:\t%p [%p,%p,%p]\n",
17135 +               nsproxy, nsproxy->mnt_ns,
17136 +               nsproxy->uts_ns, nsproxy->ipc_ns);
17137 +
17138 +       ns = nsproxy->mnt_ns;
17139 +       if (!ns)
17140 +               goto skip_ns;
17141 +
17142 +       length += vx_info_mnt_namespace(ns, buffer + length);
17143 +
17144 +skip_ns:
17145 +
17146 +       uts = nsproxy->uts_ns;
17147 +       if (!uts)
17148 +               goto skip_uts;
17149 +
17150 +       length += sprintf(buffer + length,
17151 +               "SysName:\t%.*s\n"
17152 +               "NodeName:\t%.*s\n"
17153 +               "Release:\t%.*s\n"
17154 +               "Version:\t%.*s\n"
17155 +               "Machine:\t%.*s\n"
17156 +               "DomainName:\t%.*s\n",
17157 +               __NEW_UTS_LEN, uts->name.sysname,
17158 +               __NEW_UTS_LEN, uts->name.nodename,
17159 +               __NEW_UTS_LEN, uts->name.release,
17160 +               __NEW_UTS_LEN, uts->name.version,
17161 +               __NEW_UTS_LEN, uts->name.machine,
17162 +               __NEW_UTS_LEN, uts->name.domainname);
17163 +skip_uts:
17164 +
17165 +       ipc = nsproxy->ipc_ns;
17166 +       if (!ipc)
17167 +               goto skip_ipc;
17168 +
17169 +       length += sprintf(buffer + length,
17170 +               "SEMS:\t\t%d %d %d %d  %d\n"
17171 +               "MSG:\t\t%d %d %d\n"
17172 +               "SHM:\t\t%lu %lu  %d %ld\n",
17173 +               ipc->sem_ctls[0], ipc->sem_ctls[1],
17174 +               ipc->sem_ctls[2], ipc->sem_ctls[3],
17175 +               ipc->used_sems,
17176 +               ipc->msg_ctlmax, ipc->msg_ctlmnb, ipc->msg_ctlmni,
17177 +               (unsigned long)ipc->shm_ctlmax,
17178 +               (unsigned long)ipc->shm_ctlall,
17179 +               ipc->shm_ctlmni, ipc->shm_tot);
17180 +skip_ipc:
17181 +out:
17182 +       return length;
17183 +}
17184 +
17185 +
17186 +#include <linux/sched.h>
17187 +
17188 +#define LOAD_INT(x) ((x) >> FSHIFT)
17189 +#define LOAD_FRAC(x) LOAD_INT(((x) & (FIXED_1 - 1)) * 100)
17190 +
17191 +static inline
17192 +int vx_info_proc_cvirt(struct _vx_cvirt *cvirt, char *buffer)
17193 +{
17194 +       int length = 0;
17195 +       int a, b, c;
17196 +
17197 +       length += sprintf(buffer + length,
17198 +               "BiasUptime:\t%lu.%02lu\n",
17199 +               (unsigned long)cvirt->bias_uptime.tv_sec,
17200 +               (cvirt->bias_uptime.tv_nsec / (NSEC_PER_SEC / 100)));
17201 +
17202 +       a = cvirt->load[0] + (FIXED_1 / 200);
17203 +       b = cvirt->load[1] + (FIXED_1 / 200);
17204 +       c = cvirt->load[2] + (FIXED_1 / 200);
17205 +       length += sprintf(buffer + length,
17206 +               "nr_threads:\t%d\n"
17207 +               "nr_running:\t%d\n"
17208 +               "nr_unintr:\t%d\n"
17209 +               "nr_onhold:\t%d\n"
17210 +               "load_updates:\t%d\n"
17211 +               "loadavg:\t%d.%02d %d.%02d %d.%02d\n"
17212 +               "total_forks:\t%d\n",
17213 +               atomic_read(&cvirt->nr_threads),
17214 +               atomic_read(&cvirt->nr_running),
17215 +               atomic_read(&cvirt->nr_uninterruptible),
17216 +               atomic_read(&cvirt->nr_onhold),
17217 +               atomic_read(&cvirt->load_updates),
17218 +               LOAD_INT(a), LOAD_FRAC(a),
17219 +               LOAD_INT(b), LOAD_FRAC(b),
17220 +               LOAD_INT(c), LOAD_FRAC(c),
17221 +               atomic_read(&cvirt->total_forks));
17222 +       return length;
17223 +}
17224 +
17225 +static inline
17226 +int vx_info_proc_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc,
17227 +       char *buffer, int cpu)
17228 +{
17229 +       int length = 0;
17230 +       return length;
17231 +}
17232 +
17233 +#endif /* _VX_CVIRT_PROC_H */
17234 diff -NurpP --minimal linux-3.9.4/kernel/vserver/debug.c linux-3.9.4-vs2.3.6.2/kernel/vserver/debug.c
17235 --- linux-3.9.4/kernel/vserver/debug.c  1970-01-01 00:00:00.000000000 +0000
17236 +++ linux-3.9.4-vs2.3.6.2/kernel/vserver/debug.c        2013-05-31 14:47:11.000000000 +0000
17237 @@ -0,0 +1,32 @@
17238 +/*
17239 + *  kernel/vserver/debug.c
17240 + *
17241 + *  Copyright (C) 2005-2007 Herbert Pötzl
17242 + *
17243 + *  V0.01  vx_info dump support
17244 + *
17245 + */
17246 +
17247 +#include <linux/module.h>
17248 +
17249 +#include <linux/vserver/context.h>
17250 +
17251 +
17252 +void   dump_vx_info(struct vx_info *vxi, int level)
17253 +{
17254 +       printk("vx_info %p[#%d, %d.%d, %4x]\n", vxi, vxi->vx_id,
17255 +               atomic_read(&vxi->vx_usecnt),
17256 +               atomic_read(&vxi->vx_tasks),
17257 +               vxi->vx_state);
17258 +       if (level > 0) {
17259 +               __dump_vx_limit(&vxi->limit);
17260 +               __dump_vx_sched(&vxi->sched);
17261 +               __dump_vx_cvirt(&vxi->cvirt);
17262 +               __dump_vx_cacct(&vxi->cacct);
17263 +       }
17264 +       printk("---\n");
17265 +}
17266 +
17267 +
17268 +EXPORT_SYMBOL_GPL(dump_vx_info);
17269 +
17270 diff -NurpP --minimal linux-3.9.4/kernel/vserver/device.c linux-3.9.4-vs2.3.6.2/kernel/vserver/device.c
17271 --- linux-3.9.4/kernel/vserver/device.c 1970-01-01 00:00:00.000000000 +0000
17272 +++ linux-3.9.4-vs2.3.6.2/kernel/vserver/device.c       2013-05-31 14:47:11.000000000 +0000
17273 @@ -0,0 +1,443 @@
17274 +/*
17275 + *  linux/kernel/vserver/device.c
17276 + *
17277 + *  Linux-VServer: Device Support
17278 + *
17279 + *  Copyright (C) 2006  Herbert Pötzl
17280 + *  Copyright (C) 2007  Daniel Hokka Zakrisson
17281 + *
17282 + *  V0.01  device mapping basics
17283 + *  V0.02  added defaults
17284 + *
17285 + */
17286 +
17287 +#include <linux/slab.h>
17288 +#include <linux/rcupdate.h>
17289 +#include <linux/fs.h>
17290 +#include <linux/namei.h>
17291 +#include <linux/hash.h>
17292 +
17293 +#include <asm/errno.h>
17294 +#include <asm/uaccess.h>
17295 +#include <linux/vserver/base.h>
17296 +#include <linux/vserver/debug.h>
17297 +#include <linux/vserver/context.h>
17298 +#include <linux/vserver/device.h>
17299 +#include <linux/vserver/device_cmd.h>
17300 +
17301 +
17302 +#define DMAP_HASH_BITS 4
17303 +
17304 +
17305 +struct vs_mapping {
17306 +       union {
17307 +               struct hlist_node hlist;
17308 +               struct list_head list;
17309 +       } u;
17310 +#define dm_hlist       u.hlist
17311 +#define dm_list                u.list
17312 +       xid_t xid;
17313 +       dev_t device;
17314 +       struct vx_dmap_target target;
17315 +};
17316 +
17317 +
17318 +static struct hlist_head dmap_main_hash[1 << DMAP_HASH_BITS];
17319 +
17320 +static DEFINE_SPINLOCK(dmap_main_hash_lock);
17321 +
17322 +static struct vx_dmap_target dmap_defaults[2] = {
17323 +       { .flags = DATTR_OPEN },
17324 +       { .flags = DATTR_OPEN },
17325 +};
17326 +
17327 +
17328 +struct kmem_cache *dmap_cachep __read_mostly;
17329 +
17330 +int __init dmap_cache_init(void)
17331 +{
17332 +       dmap_cachep = kmem_cache_create("dmap_cache",
17333 +               sizeof(struct vs_mapping), 0,
17334 +               SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
17335 +       return 0;
17336 +}
17337 +
17338 +__initcall(dmap_cache_init);
17339 +
17340 +
17341 +static inline unsigned int __hashval(dev_t dev, int bits)
17342 +{
17343 +       return hash_long((unsigned long)dev, bits);
17344 +}
17345 +
17346 +
17347 +/*     __hash_mapping()
17348 + *     add the mapping to the hash table
17349 + */
17350 +static inline void __hash_mapping(struct vx_info *vxi, struct vs_mapping *vdm)
17351 +{
17352 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
17353 +       struct hlist_head *head, *hash = dmap_main_hash;
17354 +       int device = vdm->device;
17355 +
17356 +       spin_lock(hash_lock);
17357 +       vxdprintk(VXD_CBIT(misc, 8), "__hash_mapping: %p[#%d] %08x:%08x",
17358 +               vxi, vxi ? vxi->vx_id : 0, device, vdm->target.target);
17359 +
17360 +       head = &hash[__hashval(device, DMAP_HASH_BITS)];
17361 +       hlist_add_head(&vdm->dm_hlist, head);
17362 +       spin_unlock(hash_lock);
17363 +}
17364 +
17365 +
17366 +static inline int __mode_to_default(umode_t mode)
17367 +{
17368 +       switch (mode) {
17369 +       case S_IFBLK:
17370 +               return 0;
17371 +       case S_IFCHR:
17372 +               return 1;
17373 +       default:
17374 +               BUG();
17375 +       }
17376 +}
17377 +
17378 +
17379 +/*     __set_default()
17380 + *     set a default
17381 + */
17382 +static inline void __set_default(struct vx_info *vxi, umode_t mode,
17383 +       struct vx_dmap_target *vdmt)
17384 +{
17385 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
17386 +       spin_lock(hash_lock);
17387 +
17388 +       if (vxi)
17389 +               vxi->dmap.targets[__mode_to_default(mode)] = *vdmt;
17390 +       else
17391 +               dmap_defaults[__mode_to_default(mode)] = *vdmt;
17392 +
17393 +
17394 +       spin_unlock(hash_lock);
17395 +
17396 +       vxdprintk(VXD_CBIT(misc, 8), "__set_default: %p[#%u] %08x %04x",
17397 +                 vxi, vxi ? vxi->vx_id : 0, vdmt->target, vdmt->flags);
17398 +}
17399 +
17400 +
17401 +/*     __remove_default()
17402 + *     remove a default
17403 + */
17404 +static inline int __remove_default(struct vx_info *vxi, umode_t mode)
17405 +{
17406 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
17407 +       spin_lock(hash_lock);
17408 +
17409 +       if (vxi)
17410 +               vxi->dmap.targets[__mode_to_default(mode)].flags = 0;
17411 +       else    /* remove == reset */
17412 +               dmap_defaults[__mode_to_default(mode)].flags = DATTR_OPEN | mode;
17413 +
17414 +       spin_unlock(hash_lock);
17415 +       return 0;
17416 +}
17417 +
17418 +
17419 +/*     __find_mapping()
17420 + *     find a mapping in the hash table
17421 + *
17422 + *     caller must hold hash_lock
17423 + */
17424 +static inline int __find_mapping(xid_t xid, dev_t device, umode_t mode,
17425 +       struct vs_mapping **local, struct vs_mapping **global)
17426 +{
17427 +       struct hlist_head *hash = dmap_main_hash;
17428 +       struct hlist_head *head = &hash[__hashval(device, DMAP_HASH_BITS)];
17429 +       struct hlist_node *pos;
17430 +       struct vs_mapping *vdm;
17431 +
17432 +       *local = NULL;
17433 +       if (global)
17434 +               *global = NULL;
17435 +
17436 +       hlist_for_each(pos, head) {
17437 +               vdm = hlist_entry(pos, struct vs_mapping, dm_hlist);
17438 +
17439 +               if ((vdm->device == device) &&
17440 +                       !((vdm->target.flags ^ mode) & S_IFMT)) {
17441 +                       if (vdm->xid == xid) {
17442 +                               *local = vdm;
17443 +                               return 1;
17444 +                       } else if (global && vdm->xid == 0)
17445 +                               *global = vdm;
17446 +               }
17447 +       }
17448 +
17449 +       if (global && *global)
17450 +               return 0;
17451 +       else
17452 +               return -ENOENT;
17453 +}
17454 +
17455 +
17456 +/*     __lookup_mapping()
17457 + *     find a mapping and store the result in target and flags
17458 + */
17459 +static inline int __lookup_mapping(struct vx_info *vxi,
17460 +       dev_t device, dev_t *target, int *flags, umode_t mode)
17461 +{
17462 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
17463 +       struct vs_mapping *vdm, *global;
17464 +       struct vx_dmap_target *vdmt;
17465 +       int ret = 0;
17466 +       xid_t xid = vxi->vx_id;
17467 +       int index;
17468 +
17469 +       spin_lock(hash_lock);
17470 +       if (__find_mapping(xid, device, mode, &vdm, &global) > 0) {
17471 +               ret = 1;
17472 +               vdmt = &vdm->target;
17473 +               goto found;
17474 +       }
17475 +
17476 +       index = __mode_to_default(mode);
17477 +       if (vxi && vxi->dmap.targets[index].flags) {
17478 +               ret = 2;
17479 +               vdmt = &vxi->dmap.targets[index];
17480 +       } else if (global) {
17481 +               ret = 3;
17482 +               vdmt = &global->target;
17483 +               goto found;
17484 +       } else {
17485 +               ret = 4;
17486 +               vdmt = &dmap_defaults[index];
17487 +       }
17488 +
17489 +found:
17490 +       if (target && (vdmt->flags & DATTR_REMAP))
17491 +               *target = vdmt->target;
17492 +       else if (target)
17493 +               *target = device;
17494 +       if (flags)
17495 +               *flags = vdmt->flags;
17496 +
17497 +       spin_unlock(hash_lock);
17498 +
17499 +       return ret;
17500 +}
17501 +
17502 +
17503 +/*     __remove_mapping()
17504 + *     remove a mapping from the hash table
17505 + */
17506 +static inline int __remove_mapping(struct vx_info *vxi, dev_t device,
17507 +       umode_t mode)
17508 +{
17509 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
17510 +       struct vs_mapping *vdm = NULL;
17511 +       int ret = 0;
17512 +
17513 +       spin_lock(hash_lock);
17514 +
17515 +       ret = __find_mapping((vxi ? vxi->vx_id : 0), device, mode, &vdm,
17516 +               NULL);
17517 +       vxdprintk(VXD_CBIT(misc, 8), "__remove_mapping: %p[#%d] %08x %04x",
17518 +               vxi, vxi ? vxi->vx_id : 0, device, mode);
17519 +       if (ret < 0)
17520 +               goto out;
17521 +       hlist_del(&vdm->dm_hlist);
17522 +
17523 +out:
17524 +       spin_unlock(hash_lock);
17525 +       if (vdm)
17526 +               kmem_cache_free(dmap_cachep, vdm);
17527 +       return ret;
17528 +}
17529 +
17530 +
17531 +
17532 +int vs_map_device(struct vx_info *vxi,
17533 +       dev_t device, dev_t *target, umode_t mode)
17534 +{
17535 +       int ret, flags = DATTR_MASK;
17536 +
17537 +       if (!vxi) {
17538 +               if (target)
17539 +                       *target = device;
17540 +               goto out;
17541 +       }
17542 +       ret = __lookup_mapping(vxi, device, target, &flags, mode);
17543 +       vxdprintk(VXD_CBIT(misc, 8), "vs_map_device: %08x target: %08x flags: %04x mode: %04x mapped=%d",
17544 +               device, target ? *target : 0, flags, mode, ret);
17545 +out:
17546 +       return (flags & DATTR_MASK);
17547 +}
17548 +
17549 +
17550 +
17551 +static int do_set_mapping(struct vx_info *vxi,
17552 +       dev_t device, dev_t target, int flags, umode_t mode)
17553 +{
17554 +       if (device) {
17555 +               struct vs_mapping *new;
17556 +
17557 +               new = kmem_cache_alloc(dmap_cachep, GFP_KERNEL);
17558 +               if (!new)
17559 +                       return -ENOMEM;
17560 +
17561 +               INIT_HLIST_NODE(&new->dm_hlist);
17562 +               new->device = device;
17563 +               new->target.target = target;
17564 +               new->target.flags = flags | mode;
17565 +               new->xid = (vxi ? vxi->vx_id : 0);
17566 +
17567 +               vxdprintk(VXD_CBIT(misc, 8), "do_set_mapping: %08x target: %08x flags: %04x", device, target, flags);
17568 +               __hash_mapping(vxi, new);
17569 +       } else {
17570 +               struct vx_dmap_target new = {
17571 +                       .target = target,
17572 +                       .flags = flags | mode,
17573 +               };
17574 +               __set_default(vxi, mode, &new);
17575 +       }
17576 +       return 0;
17577 +}
17578 +
17579 +
17580 +static int do_unset_mapping(struct vx_info *vxi,
17581 +       dev_t device, dev_t target, int flags, umode_t mode)
17582 +{
17583 +       int ret = -EINVAL;
17584 +
17585 +       if (device) {
17586 +               ret = __remove_mapping(vxi, device, mode);
17587 +               if (ret < 0)
17588 +                       goto out;
17589 +       } else {
17590 +               ret = __remove_default(vxi, mode);
17591 +               if (ret < 0)
17592 +                       goto out;
17593 +       }
17594 +
17595 +out:
17596 +       return ret;
17597 +}
17598 +
17599 +
17600 +static inline int __user_device(const char __user *name, dev_t *dev,
17601 +       umode_t *mode)
17602 +{
17603 +       struct nameidata nd;
17604 +       int ret;
17605 +
17606 +       if (!name) {
17607 +               *dev = 0;
17608 +               return 0;
17609 +       }
17610 +       ret = user_lpath(name, &nd.path);
17611 +       if (ret)
17612 +               return ret;
17613 +       if (nd.path.dentry->d_inode) {
17614 +               *dev = nd.path.dentry->d_inode->i_rdev;
17615 +               *mode = nd.path.dentry->d_inode->i_mode;
17616 +       }
17617 +       path_put(&nd.path);
17618 +       return 0;
17619 +}
17620 +
17621 +static inline int __mapping_mode(dev_t device, dev_t target,
17622 +       umode_t device_mode, umode_t target_mode, umode_t *mode)
17623 +{
17624 +       if (device)
17625 +               *mode = device_mode & S_IFMT;
17626 +       else if (target)
17627 +               *mode = target_mode & S_IFMT;
17628 +       else
17629 +               return -EINVAL;
17630 +
17631 +       /* if both given, device and target mode have to match */
17632 +       if (device && target &&
17633 +               ((device_mode ^ target_mode) & S_IFMT))
17634 +               return -EINVAL;
17635 +       return 0;
17636 +}
17637 +
17638 +
17639 +static inline int do_mapping(struct vx_info *vxi, const char __user *device_path,
17640 +       const char __user *target_path, int flags, int set)
17641 +{
17642 +       dev_t device = ~0, target = ~0;
17643 +       umode_t device_mode = 0, target_mode = 0, mode;
17644 +       int ret;
17645 +
17646 +       ret = __user_device(device_path, &device, &device_mode);
17647 +       if (ret)
17648 +               return ret;
17649 +       ret = __user_device(target_path, &target, &target_mode);
17650 +       if (ret)
17651 +               return ret;
17652 +
17653 +       ret = __mapping_mode(device, target,
17654 +               device_mode, target_mode, &mode);
17655 +       if (ret)
17656 +               return ret;
17657 +
17658 +       if (set)
17659 +               return do_set_mapping(vxi, device, target,
17660 +                       flags, mode);
17661 +       else
17662 +               return do_unset_mapping(vxi, device, target,
17663 +                       flags, mode);
17664 +}
17665 +
17666 +
17667 +int vc_set_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, 1);
17676 +}
17677 +
17678 +int vc_unset_mapping(struct vx_info *vxi, void __user *data)
17679 +{
17680 +       struct vcmd_set_mapping_v0 vc_data;
17681 +
17682 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17683 +               return -EFAULT;
17684 +
17685 +       return do_mapping(vxi, vc_data.device, vc_data.target,
17686 +               vc_data.flags, 0);
17687 +}
17688 +
17689 +
17690 +#ifdef CONFIG_COMPAT
17691 +
17692 +int vc_set_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, 1);
17701 +}
17702 +
17703 +int vc_unset_mapping_x32(struct vx_info *vxi, void __user *data)
17704 +{
17705 +       struct vcmd_set_mapping_v0_x32 vc_data;
17706 +
17707 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17708 +               return -EFAULT;
17709 +
17710 +       return do_mapping(vxi, compat_ptr(vc_data.device_ptr),
17711 +               compat_ptr(vc_data.target_ptr), vc_data.flags, 0);
17712 +}
17713 +
17714 +#endif /* CONFIG_COMPAT */
17715 +
17716 +
17717 diff -NurpP --minimal linux-3.9.4/kernel/vserver/dlimit.c linux-3.9.4-vs2.3.6.2/kernel/vserver/dlimit.c
17718 --- linux-3.9.4/kernel/vserver/dlimit.c 1970-01-01 00:00:00.000000000 +0000
17719 +++ linux-3.9.4-vs2.3.6.2/kernel/vserver/dlimit.c       2013-05-31 19:37:39.000000000 +0000
17720 @@ -0,0 +1,528 @@
17721 +/*
17722 + *  linux/kernel/vserver/dlimit.c
17723 + *
17724 + *  Virtual Server: Context Disk Limits
17725 + *
17726 + *  Copyright (C) 2004-2009  Herbert Pötzl
17727 + *
17728 + *  V0.01  initial version
17729 + *  V0.02  compat32 splitup
17730 + *  V0.03  extended interface
17731 + *
17732 + */
17733 +
17734 +#include <linux/statfs.h>
17735 +#include <linux/sched.h>
17736 +#include <linux/namei.h>
17737 +#include <linux/vs_tag.h>
17738 +#include <linux/vs_dlimit.h>
17739 +#include <linux/vserver/dlimit_cmd.h>
17740 +#include <linux/slab.h>
17741 +// #include <linux/gfp.h>
17742 +
17743 +#include <asm/uaccess.h>
17744 +
17745 +/*     __alloc_dl_info()
17746 +
17747 +       * allocate an initialized dl_info struct
17748 +       * doesn't make it visible (hash)                        */
17749 +
17750 +static struct dl_info *__alloc_dl_info(struct super_block *sb, tag_t tag)
17751 +{
17752 +       struct dl_info *new = NULL;
17753 +
17754 +       vxdprintk(VXD_CBIT(dlim, 5),
17755 +               "alloc_dl_info(%p,%d)*", sb, tag);
17756 +
17757 +       /* would this benefit from a slab cache? */
17758 +       new = kmalloc(sizeof(struct dl_info), GFP_KERNEL);
17759 +       if (!new)
17760 +               return 0;
17761 +
17762 +       memset(new, 0, sizeof(struct dl_info));
17763 +       new->dl_tag = tag;
17764 +       new->dl_sb = sb;
17765 +       // INIT_RCU_HEAD(&new->dl_rcu);
17766 +       INIT_HLIST_NODE(&new->dl_hlist);
17767 +       spin_lock_init(&new->dl_lock);
17768 +       atomic_set(&new->dl_refcnt, 0);
17769 +       atomic_set(&new->dl_usecnt, 0);
17770 +
17771 +       /* rest of init goes here */
17772 +
17773 +       vxdprintk(VXD_CBIT(dlim, 4),
17774 +               "alloc_dl_info(%p,%d) = %p", sb, tag, new);
17775 +       return new;
17776 +}
17777 +
17778 +/*     __dealloc_dl_info()
17779 +
17780 +       * final disposal of dl_info                             */
17781 +
17782 +static void __dealloc_dl_info(struct dl_info *dli)
17783 +{
17784 +       vxdprintk(VXD_CBIT(dlim, 4),
17785 +               "dealloc_dl_info(%p)", dli);
17786 +
17787 +       dli->dl_hlist.next = LIST_POISON1;
17788 +       dli->dl_tag = -1;
17789 +       dli->dl_sb = 0;
17790 +
17791 +       BUG_ON(atomic_read(&dli->dl_usecnt));
17792 +       BUG_ON(atomic_read(&dli->dl_refcnt));
17793 +
17794 +       kfree(dli);
17795 +}
17796 +
17797 +
17798 +/*     hash table for dl_info hash */
17799 +
17800 +#define DL_HASH_SIZE   13
17801 +
17802 +struct hlist_head dl_info_hash[DL_HASH_SIZE];
17803 +
17804 +static DEFINE_SPINLOCK(dl_info_hash_lock);
17805 +
17806 +
17807 +static inline unsigned int __hashval(struct super_block *sb, tag_t tag)
17808 +{
17809 +       return ((tag ^ (unsigned long)sb) % DL_HASH_SIZE);
17810 +}
17811 +
17812 +
17813 +
17814 +/*     __hash_dl_info()
17815 +
17816 +       * add the dli to the global hash table
17817 +       * requires the hash_lock to be held                     */
17818 +
17819 +static inline void __hash_dl_info(struct dl_info *dli)
17820 +{
17821 +       struct hlist_head *head;
17822 +
17823 +       vxdprintk(VXD_CBIT(dlim, 6),
17824 +               "__hash_dl_info: %p[#%d]", dli, dli->dl_tag);
17825 +       get_dl_info(dli);
17826 +       head = &dl_info_hash[__hashval(dli->dl_sb, dli->dl_tag)];
17827 +       hlist_add_head_rcu(&dli->dl_hlist, head);
17828 +}
17829 +
17830 +/*     __unhash_dl_info()
17831 +
17832 +       * remove the dli from the global hash table
17833 +       * requires the hash_lock to be held                     */
17834 +
17835 +static inline void __unhash_dl_info(struct dl_info *dli)
17836 +{
17837 +       vxdprintk(VXD_CBIT(dlim, 6),
17838 +               "__unhash_dl_info: %p[#%d]", dli, dli->dl_tag);
17839 +       hlist_del_rcu(&dli->dl_hlist);
17840 +       put_dl_info(dli);
17841 +}
17842 +
17843 +
17844 +/*     __lookup_dl_info()
17845 +
17846 +       * requires the rcu_read_lock()
17847 +       * doesn't increment the dl_refcnt                       */
17848 +
17849 +static inline struct dl_info *__lookup_dl_info(struct super_block *sb, tag_t tag)
17850 +{
17851 +       struct hlist_head *head = &dl_info_hash[__hashval(sb, tag)];
17852 +       struct dl_info *dli;
17853 +
17854 +       hlist_for_each_entry_rcu(dli, head, dl_hlist) {
17855 +               if (dli->dl_tag == tag && dli->dl_sb == sb)
17856 +                       return dli;
17857 +       }
17858 +       return NULL;
17859 +}
17860 +
17861 +
17862 +struct dl_info *locate_dl_info(struct super_block *sb, tag_t tag)
17863 +{
17864 +       struct dl_info *dli;
17865 +
17866 +       rcu_read_lock();
17867 +       dli = get_dl_info(__lookup_dl_info(sb, tag));
17868 +       vxdprintk(VXD_CBIT(dlim, 7),
17869 +               "locate_dl_info(%p,#%d) = %p", sb, tag, dli);
17870 +       rcu_read_unlock();
17871 +       return dli;
17872 +}
17873 +
17874 +void rcu_free_dl_info(struct rcu_head *head)
17875 +{
17876 +       struct dl_info *dli = container_of(head, struct dl_info, dl_rcu);
17877 +       int usecnt, refcnt;
17878 +
17879 +       BUG_ON(!dli || !head);
17880 +
17881 +       usecnt = atomic_read(&dli->dl_usecnt);
17882 +       BUG_ON(usecnt < 0);
17883 +
17884 +       refcnt = atomic_read(&dli->dl_refcnt);
17885 +       BUG_ON(refcnt < 0);
17886 +
17887 +       vxdprintk(VXD_CBIT(dlim, 3),
17888 +               "rcu_free_dl_info(%p)", dli);
17889 +       if (!usecnt)
17890 +               __dealloc_dl_info(dli);
17891 +       else
17892 +               printk("!!! rcu didn't free\n");
17893 +}
17894 +
17895 +
17896 +
17897 +
17898 +static int do_addrem_dlimit(uint32_t id, const char __user *name,
17899 +       uint32_t flags, int add)
17900 +{
17901 +       struct path path;
17902 +       int ret;
17903 +
17904 +       ret = user_lpath(name, &path);
17905 +       if (!ret) {
17906 +               struct super_block *sb;
17907 +               struct dl_info *dli;
17908 +
17909 +               ret = -EINVAL;
17910 +               if (!path.dentry->d_inode)
17911 +                       goto out_release;
17912 +               if (!(sb = path.dentry->d_inode->i_sb))
17913 +                       goto out_release;
17914 +
17915 +               if (add) {
17916 +                       dli = __alloc_dl_info(sb, id);
17917 +                       spin_lock(&dl_info_hash_lock);
17918 +
17919 +                       ret = -EEXIST;
17920 +                       if (__lookup_dl_info(sb, id))
17921 +                               goto out_unlock;
17922 +                       __hash_dl_info(dli);
17923 +                       dli = NULL;
17924 +               } else {
17925 +                       spin_lock(&dl_info_hash_lock);
17926 +                       dli = __lookup_dl_info(sb, id);
17927 +
17928 +                       ret = -ESRCH;
17929 +                       if (!dli)
17930 +                               goto out_unlock;
17931 +                       __unhash_dl_info(dli);
17932 +               }
17933 +               ret = 0;
17934 +       out_unlock:
17935 +               spin_unlock(&dl_info_hash_lock);
17936 +               if (add && dli)
17937 +                       __dealloc_dl_info(dli);
17938 +       out_release:
17939 +               path_put(&path);
17940 +       }
17941 +       return ret;
17942 +}
17943 +
17944 +int vc_add_dlimit(uint32_t id, void __user *data)
17945 +{
17946 +       struct vcmd_ctx_dlimit_base_v0 vc_data;
17947 +
17948 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17949 +               return -EFAULT;
17950 +
17951 +       return do_addrem_dlimit(id, vc_data.name, vc_data.flags, 1);
17952 +}
17953 +
17954 +int vc_rem_dlimit(uint32_t id, void __user *data)
17955 +{
17956 +       struct vcmd_ctx_dlimit_base_v0 vc_data;
17957 +
17958 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17959 +               return -EFAULT;
17960 +
17961 +       return do_addrem_dlimit(id, vc_data.name, vc_data.flags, 0);
17962 +}
17963 +
17964 +#ifdef CONFIG_COMPAT
17965 +
17966 +int vc_add_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, 1);
17975 +}
17976 +
17977 +int vc_rem_dlimit_x32(uint32_t id, void __user *data)
17978 +{
17979 +       struct vcmd_ctx_dlimit_base_v0_x32 vc_data;
17980 +
17981 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17982 +               return -EFAULT;
17983 +
17984 +       return do_addrem_dlimit(id,
17985 +               compat_ptr(vc_data.name_ptr), vc_data.flags, 0);
17986 +}
17987 +
17988 +#endif /* CONFIG_COMPAT */
17989 +
17990 +
17991 +static inline
17992 +int do_set_dlimit(uint32_t id, const char __user *name,
17993 +       uint32_t space_used, uint32_t space_total,
17994 +       uint32_t inodes_used, uint32_t inodes_total,
17995 +       uint32_t reserved, uint32_t flags)
17996 +{
17997 +       struct path path;
17998 +       int ret;
17999 +
18000 +       ret = user_lpath(name, &path);
18001 +       if (!ret) {
18002 +               struct super_block *sb;
18003 +               struct dl_info *dli;
18004 +
18005 +               ret = -EINVAL;
18006 +               if (!path.dentry->d_inode)
18007 +                       goto out_release;
18008 +               if (!(sb = path.dentry->d_inode->i_sb))
18009 +                       goto out_release;
18010 +
18011 +               /* sanity checks */
18012 +               if ((reserved != CDLIM_KEEP &&
18013 +                       reserved > 100) ||
18014 +                       (inodes_used != CDLIM_KEEP &&
18015 +                       inodes_used > inodes_total) ||
18016 +                       (space_used != CDLIM_KEEP &&
18017 +                       space_used > space_total))
18018 +                       goto out_release;
18019 +
18020 +               ret = -ESRCH;
18021 +               dli = locate_dl_info(sb, id);
18022 +               if (!dli)
18023 +                       goto out_release;
18024 +
18025 +               spin_lock(&dli->dl_lock);
18026 +
18027 +               if (inodes_used != CDLIM_KEEP)
18028 +                       dli->dl_inodes_used = inodes_used;
18029 +               if (inodes_total != CDLIM_KEEP)
18030 +                       dli->dl_inodes_total = inodes_total;
18031 +               if (space_used != CDLIM_KEEP)
18032 +                       dli->dl_space_used = dlimit_space_32to64(
18033 +                               space_used, flags, DLIMS_USED);
18034 +
18035 +               if (space_total == CDLIM_INFINITY)
18036 +                       dli->dl_space_total = DLIM_INFINITY;
18037 +               else if (space_total != CDLIM_KEEP)
18038 +                       dli->dl_space_total = dlimit_space_32to64(
18039 +                               space_total, flags, DLIMS_TOTAL);
18040 +
18041 +               if (reserved != CDLIM_KEEP)
18042 +                       dli->dl_nrlmult = (1 << 10) * (100 - reserved) / 100;
18043 +
18044 +               spin_unlock(&dli->dl_lock);
18045 +
18046 +               put_dl_info(dli);
18047 +               ret = 0;
18048 +
18049 +       out_release:
18050 +               path_put(&path);
18051 +       }
18052 +       return ret;
18053 +}
18054 +
18055 +int vc_set_dlimit(uint32_t id, void __user *data)
18056 +{
18057 +       struct vcmd_ctx_dlimit_v0 vc_data;
18058 +
18059 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18060 +               return -EFAULT;
18061 +
18062 +       return do_set_dlimit(id, vc_data.name,
18063 +               vc_data.space_used, vc_data.space_total,
18064 +               vc_data.inodes_used, vc_data.inodes_total,
18065 +               vc_data.reserved, vc_data.flags);
18066 +}
18067 +
18068 +#ifdef CONFIG_COMPAT
18069 +
18070 +int vc_set_dlimit_x32(uint32_t id, void __user *data)
18071 +{
18072 +       struct vcmd_ctx_dlimit_v0_x32 vc_data;
18073 +
18074 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18075 +               return -EFAULT;
18076 +
18077 +       return do_set_dlimit(id, compat_ptr(vc_data.name_ptr),
18078 +               vc_data.space_used, vc_data.space_total,
18079 +               vc_data.inodes_used, vc_data.inodes_total,
18080 +               vc_data.reserved, vc_data.flags);
18081 +}
18082 +
18083 +#endif /* CONFIG_COMPAT */
18084 +
18085 +
18086 +static inline
18087 +int do_get_dlimit(uint32_t id, const char __user *name,
18088 +       uint32_t *space_used, uint32_t *space_total,
18089 +       uint32_t *inodes_used, uint32_t *inodes_total,
18090 +       uint32_t *reserved, uint32_t *flags)
18091 +{
18092 +       struct path path;
18093 +       int ret;
18094 +
18095 +       ret = user_lpath(name, &path);
18096 +       if (!ret) {
18097 +               struct super_block *sb;
18098 +               struct dl_info *dli;
18099 +
18100 +               ret = -EINVAL;
18101 +               if (!path.dentry->d_inode)
18102 +                       goto out_release;
18103 +               if (!(sb = path.dentry->d_inode->i_sb))
18104 +                       goto out_release;
18105 +
18106 +               ret = -ESRCH;
18107 +               dli = locate_dl_info(sb, id);
18108 +               if (!dli)
18109 +                       goto out_release;
18110 +
18111 +               spin_lock(&dli->dl_lock);
18112 +               *inodes_used = dli->dl_inodes_used;
18113 +               *inodes_total = dli->dl_inodes_total;
18114 +
18115 +               *space_used = dlimit_space_64to32(
18116 +                       dli->dl_space_used, flags, DLIMS_USED);
18117 +
18118 +               if (dli->dl_space_total == DLIM_INFINITY)
18119 +                       *space_total = CDLIM_INFINITY;
18120 +               else
18121 +                       *space_total = dlimit_space_64to32(
18122 +                               dli->dl_space_total, flags, DLIMS_TOTAL);
18123 +
18124 +               *reserved = 100 - ((dli->dl_nrlmult * 100 + 512) >> 10);
18125 +               spin_unlock(&dli->dl_lock);
18126 +
18127 +               put_dl_info(dli);
18128 +               ret = -EFAULT;
18129 +
18130 +               ret = 0;
18131 +       out_release:
18132 +               path_put(&path);
18133 +       }
18134 +       return ret;
18135 +}
18136 +
18137 +
18138 +int vc_get_dlimit(uint32_t id, void __user *data)
18139 +{
18140 +       struct vcmd_ctx_dlimit_v0 vc_data;
18141 +       int ret;
18142 +
18143 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18144 +               return -EFAULT;
18145 +
18146 +       ret = do_get_dlimit(id, vc_data.name,
18147 +               &vc_data.space_used, &vc_data.space_total,
18148 +               &vc_data.inodes_used, &vc_data.inodes_total,
18149 +               &vc_data.reserved, &vc_data.flags);
18150 +       if (ret)
18151 +               return ret;
18152 +
18153 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18154 +               return -EFAULT;
18155 +       return 0;
18156 +}
18157 +
18158 +#ifdef CONFIG_COMPAT
18159 +
18160 +int vc_get_dlimit_x32(uint32_t id, void __user *data)
18161 +{
18162 +       struct vcmd_ctx_dlimit_v0_x32 vc_data;
18163 +       int ret;
18164 +
18165 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18166 +               return -EFAULT;
18167 +
18168 +       ret = do_get_dlimit(id, compat_ptr(vc_data.name_ptr),
18169 +               &vc_data.space_used, &vc_data.space_total,
18170 +               &vc_data.inodes_used, &vc_data.inodes_total,
18171 +               &vc_data.reserved, &vc_data.flags);
18172 +       if (ret)
18173 +               return ret;
18174 +
18175 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18176 +               return -EFAULT;
18177 +       return 0;
18178 +}
18179 +
18180 +#endif /* CONFIG_COMPAT */
18181 +
18182 +
18183 +void vx_vsi_statfs(struct super_block *sb, struct kstatfs *buf)
18184 +{
18185 +       struct dl_info *dli;
18186 +       __u64 blimit, bfree, bavail;
18187 +       __u32 ifree;
18188 +
18189 +       dli = locate_dl_info(sb, dx_current_tag());
18190 +       if (!dli)
18191 +               return;
18192 +
18193 +       spin_lock(&dli->dl_lock);
18194 +       if (dli->dl_inodes_total == (unsigned long)DLIM_INFINITY)
18195 +               goto no_ilim;
18196 +
18197 +       /* reduce max inodes available to limit */
18198 +       if (buf->f_files > dli->dl_inodes_total)
18199 +               buf->f_files = dli->dl_inodes_total;
18200 +
18201 +       ifree = dli->dl_inodes_total - dli->dl_inodes_used;
18202 +       /* reduce free inodes to min */
18203 +       if (ifree < buf->f_ffree)
18204 +               buf->f_ffree = ifree;
18205 +
18206 +no_ilim:
18207 +       if (dli->dl_space_total == DLIM_INFINITY)
18208 +               goto no_blim;
18209 +
18210 +       blimit = dli->dl_space_total >> sb->s_blocksize_bits;
18211 +
18212 +       if (dli->dl_space_total < dli->dl_space_used)
18213 +               bfree = 0;
18214 +       else
18215 +               bfree = (dli->dl_space_total - dli->dl_space_used)
18216 +                       >> sb->s_blocksize_bits;
18217 +
18218 +       bavail = ((dli->dl_space_total >> 10) * dli->dl_nrlmult);
18219 +       if (bavail < dli->dl_space_used)
18220 +               bavail = 0;
18221 +       else
18222 +               bavail = (bavail - dli->dl_space_used)
18223 +                       >> sb->s_blocksize_bits;
18224 +
18225 +       /* reduce max space available to limit */
18226 +       if (buf->f_blocks > blimit)
18227 +               buf->f_blocks = blimit;
18228 +
18229 +       /* reduce free space to min */
18230 +       if (bfree < buf->f_bfree)
18231 +               buf->f_bfree = bfree;
18232 +
18233 +       /* reduce avail space to min */
18234 +       if (bavail < buf->f_bavail)
18235 +               buf->f_bavail = bavail;
18236 +
18237 +no_blim:
18238 +       spin_unlock(&dli->dl_lock);
18239 +       put_dl_info(dli);
18240 +
18241 +       return;
18242 +}
18243 +
18244 +#include <linux/module.h>
18245 +
18246 +EXPORT_SYMBOL_GPL(locate_dl_info);
18247 +EXPORT_SYMBOL_GPL(rcu_free_dl_info);
18248 +
18249 diff -NurpP --minimal linux-3.9.4/kernel/vserver/helper.c linux-3.9.4-vs2.3.6.2/kernel/vserver/helper.c
18250 --- linux-3.9.4/kernel/vserver/helper.c 1970-01-01 00:00:00.000000000 +0000
18251 +++ linux-3.9.4-vs2.3.6.2/kernel/vserver/helper.c       2013-06-01 08:27:59.000000000 +0000
18252 @@ -0,0 +1,230 @@
18253 +/*
18254 + *  linux/kernel/vserver/helper.c
18255 + *
18256 + *  Virtual Context Support
18257 + *
18258 + *  Copyright (C) 2004-2007  Herbert Pötzl
18259 + *
18260 + *  V0.01  basic helper
18261 + *
18262 + */
18263 +
18264 +#include <linux/kmod.h>
18265 +#include <linux/reboot.h>
18266 +#include <linux/vs_context.h>
18267 +#include <linux/vs_network.h>
18268 +#include <linux/vserver/signal.h>
18269 +
18270 +
18271 +char vshelper_path[255] = "/sbin/vshelper";
18272 +
18273 +static int vshelper_init(struct subprocess_info *info, struct cred *new_cred)
18274 +{
18275 +       current->flags &= ~PF_THREAD_BOUND;
18276 +       return 0;
18277 +}
18278 +
18279 +static int do_vshelper(char *name, char *argv[], char *envp[], int sync)
18280 +{
18281 +       int ret;
18282 +
18283 +       if ((ret = call_usermodehelper_fns(name, argv, envp,
18284 +               sync ? UMH_WAIT_PROC : UMH_WAIT_EXEC,
18285 +               vshelper_init, NULL, NULL))) {
18286 +               printk(KERN_WARNING "%s: (%s %s) returned %s with %d\n",
18287 +                       name, argv[1], argv[2],
18288 +                       sync ? "sync" : "async", ret);
18289 +       }
18290 +       vxdprintk(VXD_CBIT(switch, 4),
18291 +               "%s: (%s %s) returned %s with %d",
18292 +               name, argv[1], argv[2], sync ? "sync" : "async", ret);
18293 +       return ret;
18294 +}
18295 +
18296 +/*
18297 + *      vshelper path is set via /proc/sys
18298 + *      invoked by vserver sys_reboot(), with
18299 + *      the following arguments
18300 + *
18301 + *      argv [0] = vshelper_path;
18302 + *      argv [1] = action: "restart", "halt", "poweroff", ...
18303 + *      argv [2] = context identifier
18304 + *
18305 + *      envp [*] = type-specific parameters
18306 + */
18307 +
18308 +long vs_reboot_helper(struct vx_info *vxi, int cmd, void __user *arg)
18309 +{
18310 +       char id_buf[8], cmd_buf[16];
18311 +       char uid_buf[16], pid_buf[16];
18312 +       int ret;
18313 +
18314 +       char *argv[] = {vshelper_path, NULL, id_buf, 0};
18315 +       char *envp[] = {"HOME=/", "TERM=linux",
18316 +                       "PATH=/sbin:/usr/sbin:/bin:/usr/bin",
18317 +                       uid_buf, pid_buf, cmd_buf, 0};
18318 +
18319 +       if (vx_info_state(vxi, VXS_HELPER))
18320 +               return -EAGAIN;
18321 +       vxi->vx_state |= VXS_HELPER;
18322 +
18323 +       snprintf(id_buf, sizeof(id_buf), "%d", vxi->vx_id);
18324 +
18325 +       snprintf(cmd_buf, sizeof(cmd_buf), "VS_CMD=%08x", cmd);
18326 +       snprintf(uid_buf, sizeof(uid_buf), "VS_UID=%d",
18327 +               from_kuid(&init_user_ns, current_uid()));
18328 +       snprintf(pid_buf, sizeof(pid_buf), "VS_PID=%d", current->pid);
18329 +
18330 +       switch (cmd) {
18331 +       case LINUX_REBOOT_CMD_RESTART:
18332 +               argv[1] = "restart";
18333 +               break;
18334 +
18335 +       case LINUX_REBOOT_CMD_HALT:
18336 +               argv[1] = "halt";
18337 +               break;
18338 +
18339 +       case LINUX_REBOOT_CMD_POWER_OFF:
18340 +               argv[1] = "poweroff";
18341 +               break;
18342 +
18343 +       case LINUX_REBOOT_CMD_SW_SUSPEND:
18344 +               argv[1] = "swsusp";
18345 +               break;
18346 +
18347 +       case LINUX_REBOOT_CMD_OOM:
18348 +               argv[1] = "oom";
18349 +               break;
18350 +
18351 +       default:
18352 +               vxi->vx_state &= ~VXS_HELPER;
18353 +               return 0;
18354 +       }
18355 +
18356 +       ret = do_vshelper(vshelper_path, argv, envp, 0);
18357 +       vxi->vx_state &= ~VXS_HELPER;
18358 +       __wakeup_vx_info(vxi);
18359 +       return (ret) ? -EPERM : 0;
18360 +}
18361 +
18362 +
18363 +long vs_reboot(unsigned int cmd, void __user *arg)
18364 +{
18365 +       struct vx_info *vxi = current_vx_info();
18366 +       long ret = 0;
18367 +
18368 +       vxdprintk(VXD_CBIT(misc, 5),
18369 +               "vs_reboot(%p[#%d],%u)",
18370 +               vxi, vxi ? vxi->vx_id : 0, cmd);
18371 +
18372 +       ret = vs_reboot_helper(vxi, cmd, arg);
18373 +       if (ret)
18374 +               return ret;
18375 +
18376 +       vxi->reboot_cmd = cmd;
18377 +       if (vx_info_flags(vxi, VXF_REBOOT_KILL, 0)) {
18378 +               switch (cmd) {
18379 +               case LINUX_REBOOT_CMD_RESTART:
18380 +               case LINUX_REBOOT_CMD_HALT:
18381 +               case LINUX_REBOOT_CMD_POWER_OFF:
18382 +                       vx_info_kill(vxi, 0, SIGKILL);
18383 +                       vx_info_kill(vxi, 1, SIGKILL);
18384 +               default:
18385 +                       break;
18386 +               }
18387 +       }
18388 +       return 0;
18389 +}
18390 +
18391 +long vs_oom_action(unsigned int cmd)
18392 +{
18393 +       struct vx_info *vxi = current_vx_info();
18394 +       long ret = 0;
18395 +
18396 +       vxdprintk(VXD_CBIT(misc, 5),
18397 +               "vs_oom_action(%p[#%d],%u)",
18398 +               vxi, vxi ? vxi->vx_id : 0, cmd);
18399 +
18400 +       ret = vs_reboot_helper(vxi, cmd, NULL);
18401 +       if (ret)
18402 +               return ret;
18403 +
18404 +       vxi->reboot_cmd = cmd;
18405 +       if (vx_info_flags(vxi, VXF_REBOOT_KILL, 0)) {
18406 +               vx_info_kill(vxi, 0, SIGKILL);
18407 +               vx_info_kill(vxi, 1, SIGKILL);
18408 +       }
18409 +       return 0;
18410 +}
18411 +
18412 +/*
18413 + *      argv [0] = vshelper_path;
18414 + *      argv [1] = action: "startup", "shutdown"
18415 + *      argv [2] = context identifier
18416 + *
18417 + *      envp [*] = type-specific parameters
18418 + */
18419 +
18420 +long vs_state_change(struct vx_info *vxi, unsigned int cmd)
18421 +{
18422 +       char id_buf[8], cmd_buf[16];
18423 +       char *argv[] = {vshelper_path, NULL, id_buf, 0};
18424 +       char *envp[] = {"HOME=/", "TERM=linux",
18425 +                       "PATH=/sbin:/usr/sbin:/bin:/usr/bin", cmd_buf, 0};
18426 +
18427 +       if (!vx_info_flags(vxi, VXF_SC_HELPER, 0))
18428 +               return 0;
18429 +
18430 +       snprintf(id_buf, sizeof(id_buf), "%d", vxi->vx_id);
18431 +       snprintf(cmd_buf, sizeof(cmd_buf), "VS_CMD=%08x", cmd);
18432 +
18433 +       switch (cmd) {
18434 +       case VSC_STARTUP:
18435 +               argv[1] = "startup";
18436 +               break;
18437 +       case VSC_SHUTDOWN:
18438 +               argv[1] = "shutdown";
18439 +               break;
18440 +       default:
18441 +               return 0;
18442 +       }
18443 +
18444 +       return do_vshelper(vshelper_path, argv, envp, 1);
18445 +}
18446 +
18447 +
18448 +/*
18449 + *      argv [0] = vshelper_path;
18450 + *      argv [1] = action: "netup", "netdown"
18451 + *      argv [2] = context identifier
18452 + *
18453 + *      envp [*] = type-specific parameters
18454 + */
18455 +
18456 +long vs_net_change(struct nx_info *nxi, unsigned int cmd)
18457 +{
18458 +       char id_buf[8], cmd_buf[16];
18459 +       char *argv[] = {vshelper_path, NULL, id_buf, 0};
18460 +       char *envp[] = {"HOME=/", "TERM=linux",
18461 +                       "PATH=/sbin:/usr/sbin:/bin:/usr/bin", cmd_buf, 0};
18462 +
18463 +       if (!nx_info_flags(nxi, NXF_SC_HELPER, 0))
18464 +               return 0;
18465 +
18466 +       snprintf(id_buf, sizeof(id_buf), "%d", nxi->nx_id);
18467 +       snprintf(cmd_buf, sizeof(cmd_buf), "VS_CMD=%08x", cmd);
18468 +
18469 +       switch (cmd) {
18470 +       case VSC_NETUP:
18471 +               argv[1] = "netup";
18472 +               break;
18473 +       case VSC_NETDOWN:
18474 +               argv[1] = "netdown";
18475 +               break;
18476 +       default:
18477 +               return 0;
18478 +       }
18479 +
18480 +       return do_vshelper(vshelper_path, argv, envp, 1);
18481 +}
18482 +
18483 diff -NurpP --minimal linux-3.9.4/kernel/vserver/history.c linux-3.9.4-vs2.3.6.2/kernel/vserver/history.c
18484 --- linux-3.9.4/kernel/vserver/history.c        1970-01-01 00:00:00.000000000 +0000
18485 +++ linux-3.9.4-vs2.3.6.2/kernel/vserver/history.c      2013-05-31 14:47:11.000000000 +0000
18486 @@ -0,0 +1,258 @@
18487 +/*
18488 + *  kernel/vserver/history.c
18489 + *
18490 + *  Virtual Context History Backtrace
18491 + *
18492 + *  Copyright (C) 2004-2007  Herbert Pötzl
18493 + *
18494 + *  V0.01  basic structure
18495 + *  V0.02  hash/unhash and trace
18496 + *  V0.03  preemption fixes
18497 + *
18498 + */
18499 +
18500 +#include <linux/module.h>
18501 +#include <asm/uaccess.h>
18502 +
18503 +#include <linux/vserver/context.h>
18504 +#include <linux/vserver/debug.h>
18505 +#include <linux/vserver/debug_cmd.h>
18506 +#include <linux/vserver/history.h>
18507 +
18508 +
18509 +#ifdef CONFIG_VSERVER_HISTORY
18510 +#define VXH_SIZE       CONFIG_VSERVER_HISTORY_SIZE
18511 +#else
18512 +#define VXH_SIZE       64
18513 +#endif
18514 +
18515 +struct _vx_history {
18516 +       unsigned int counter;
18517 +
18518 +       struct _vx_hist_entry entry[VXH_SIZE + 1];
18519 +};
18520 +
18521 +
18522 +DEFINE_PER_CPU(struct _vx_history, vx_history_buffer);
18523 +
18524 +unsigned volatile int vxh_active = 1;
18525 +
18526 +static atomic_t sequence = ATOMIC_INIT(0);
18527 +
18528 +
18529 +/*     vxh_advance()
18530 +
18531 +       * requires disabled preemption                          */
18532 +
18533 +struct _vx_hist_entry *vxh_advance(void *loc)
18534 +{
18535 +       unsigned int cpu = smp_processor_id();
18536 +       struct _vx_history *hist = &per_cpu(vx_history_buffer, cpu);
18537 +       struct _vx_hist_entry *entry;
18538 +       unsigned int index;
18539 +
18540 +       index = vxh_active ? (hist->counter++ % VXH_SIZE) : VXH_SIZE;
18541 +       entry = &hist->entry[index];
18542 +
18543 +       entry->seq = atomic_inc_return(&sequence);
18544 +       entry->loc = loc;
18545 +       return entry;
18546 +}
18547 +
18548 +EXPORT_SYMBOL_GPL(vxh_advance);
18549 +
18550 +
18551 +#define VXH_LOC_FMTS   "(#%04x,*%d):%p"
18552 +
18553 +#define VXH_LOC_ARGS(e)        (e)->seq, cpu, (e)->loc
18554 +
18555 +
18556 +#define VXH_VXI_FMTS   "%p[#%d,%d.%d]"
18557 +
18558 +#define VXH_VXI_ARGS(e)        (e)->vxi.ptr,                           \
18559 +                       (e)->vxi.ptr ? (e)->vxi.xid : 0,        \
18560 +                       (e)->vxi.ptr ? (e)->vxi.usecnt : 0,     \
18561 +                       (e)->vxi.ptr ? (e)->vxi.tasks : 0
18562 +
18563 +void   vxh_dump_entry(struct _vx_hist_entry *e, unsigned cpu)
18564 +{
18565 +       switch (e->type) {
18566 +       case VXH_THROW_OOPS:
18567 +               printk( VXH_LOC_FMTS " oops \n", VXH_LOC_ARGS(e));
18568 +               break;
18569 +
18570 +       case VXH_GET_VX_INFO:
18571 +       case VXH_PUT_VX_INFO:
18572 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS "\n",
18573 +                       VXH_LOC_ARGS(e),
18574 +                       (e->type == VXH_GET_VX_INFO) ? "get" : "put",
18575 +                       VXH_VXI_ARGS(e));
18576 +               break;
18577 +
18578 +       case VXH_INIT_VX_INFO:
18579 +       case VXH_SET_VX_INFO:
18580 +       case VXH_CLR_VX_INFO:
18581 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS " @%p\n",
18582 +                       VXH_LOC_ARGS(e),
18583 +                       (e->type == VXH_INIT_VX_INFO) ? "init" :
18584 +                       ((e->type == VXH_SET_VX_INFO) ? "set" : "clr"),
18585 +                       VXH_VXI_ARGS(e), e->sc.data);
18586 +               break;
18587 +
18588 +       case VXH_CLAIM_VX_INFO:
18589 +       case VXH_RELEASE_VX_INFO:
18590 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS " @%p\n",
18591 +                       VXH_LOC_ARGS(e),
18592 +                       (e->type == VXH_CLAIM_VX_INFO) ? "claim" : "release",
18593 +                       VXH_VXI_ARGS(e), e->sc.data);
18594 +               break;
18595 +
18596 +       case VXH_ALLOC_VX_INFO:
18597 +       case VXH_DEALLOC_VX_INFO:
18598 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS "\n",
18599 +                       VXH_LOC_ARGS(e),
18600 +                       (e->type == VXH_ALLOC_VX_INFO) ? "alloc" : "dealloc",
18601 +                       VXH_VXI_ARGS(e));
18602 +               break;
18603 +
18604 +       case VXH_HASH_VX_INFO:
18605 +       case VXH_UNHASH_VX_INFO:
18606 +               printk( VXH_LOC_FMTS " __%s_vx_info " VXH_VXI_FMTS "\n",
18607 +                       VXH_LOC_ARGS(e),
18608 +                       (e->type == VXH_HASH_VX_INFO) ? "hash" : "unhash",
18609 +                       VXH_VXI_ARGS(e));
18610 +               break;
18611 +
18612 +       case VXH_LOC_VX_INFO:
18613 +       case VXH_LOOKUP_VX_INFO:
18614 +       case VXH_CREATE_VX_INFO:
18615 +               printk( VXH_LOC_FMTS " __%s_vx_info [#%d] -> " VXH_VXI_FMTS "\n",
18616 +                       VXH_LOC_ARGS(e),
18617 +                       (e->type == VXH_CREATE_VX_INFO) ? "create" :
18618 +                       ((e->type == VXH_LOC_VX_INFO) ? "loc" : "lookup"),
18619 +                       e->ll.arg, VXH_VXI_ARGS(e));
18620 +               break;
18621 +       }
18622 +}
18623 +
18624 +static void __vxh_dump_history(void)
18625 +{
18626 +       unsigned int i, cpu;
18627 +
18628 +       printk("History:\tSEQ: %8x\tNR_CPUS: %d\n",
18629 +               atomic_read(&sequence), NR_CPUS);
18630 +
18631 +       for (i = 0; i < VXH_SIZE; i++) {
18632 +               for_each_online_cpu(cpu) {
18633 +                       struct _vx_history *hist =
18634 +                               &per_cpu(vx_history_buffer, cpu);
18635 +                       unsigned int index = (hist->counter - i) % VXH_SIZE;
18636 +                       struct _vx_hist_entry *entry = &hist->entry[index];
18637 +
18638 +                       vxh_dump_entry(entry, cpu);
18639 +               }
18640 +       }
18641 +}
18642 +
18643 +void   vxh_dump_history(void)
18644 +{
18645 +       vxh_active = 0;
18646 +#ifdef CONFIG_SMP
18647 +       local_irq_enable();
18648 +       smp_send_stop();
18649 +       local_irq_disable();
18650 +#endif
18651 +       __vxh_dump_history();
18652 +}
18653 +
18654 +
18655 +/* vserver syscall commands below here */
18656 +
18657 +
18658 +int vc_dump_history(uint32_t id)
18659 +{
18660 +       vxh_active = 0;
18661 +       __vxh_dump_history();
18662 +       vxh_active = 1;
18663 +
18664 +       return 0;
18665 +}
18666 +
18667 +
18668 +int do_read_history(struct __user _vx_hist_entry *data,
18669 +       int cpu, uint32_t *index, uint32_t *count)
18670 +{
18671 +       int pos, ret = 0;
18672 +       struct _vx_history *hist = &per_cpu(vx_history_buffer, cpu);
18673 +       int end = hist->counter;
18674 +       int start = end - VXH_SIZE + 2;
18675 +       int idx = *index;
18676 +
18677 +       /* special case: get current pos */
18678 +       if (!*count) {
18679 +               *index = end;
18680 +               return 0;
18681 +       }
18682 +
18683 +       /* have we lost some data? */
18684 +       if (idx < start)
18685 +               idx = start;
18686 +
18687 +       for (pos = 0; (pos < *count) && (idx < end); pos++, idx++) {
18688 +               struct _vx_hist_entry *entry =
18689 +                       &hist->entry[idx % VXH_SIZE];
18690 +
18691 +               /* send entry to userspace */
18692 +               ret = copy_to_user(&data[pos], entry, sizeof(*entry));
18693 +               if (ret)
18694 +                       break;
18695 +       }
18696 +       /* save new index and count */
18697 +       *index = idx;
18698 +       *count = pos;
18699 +       return ret ? ret : (*index < end);
18700 +}
18701 +
18702 +int vc_read_history(uint32_t id, void __user *data)
18703 +{
18704 +       struct vcmd_read_history_v0 vc_data;
18705 +       int ret;
18706 +
18707 +       if (id >= NR_CPUS)
18708 +               return -EINVAL;
18709 +
18710 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18711 +               return -EFAULT;
18712 +
18713 +       ret = do_read_history((struct __user _vx_hist_entry *)vc_data.data,
18714 +               id, &vc_data.index, &vc_data.count);
18715 +
18716 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18717 +               return -EFAULT;
18718 +       return ret;
18719 +}
18720 +
18721 +#ifdef CONFIG_COMPAT
18722 +
18723 +int vc_read_history_x32(uint32_t id, void __user *data)
18724 +{
18725 +       struct vcmd_read_history_v0_x32 vc_data;
18726 +       int ret;
18727 +
18728 +       if (id >= NR_CPUS)
18729 +               return -EINVAL;
18730 +
18731 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18732 +               return -EFAULT;
18733 +
18734 +       ret = do_read_history((struct __user _vx_hist_entry *)
18735 +               compat_ptr(vc_data.data_ptr),
18736 +               id, &vc_data.index, &vc_data.count);
18737 +
18738 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18739 +               return -EFAULT;
18740 +       return ret;
18741 +}
18742 +
18743 +#endif /* CONFIG_COMPAT */
18744 +
18745 diff -NurpP --minimal linux-3.9.4/kernel/vserver/inet.c linux-3.9.4-vs2.3.6.2/kernel/vserver/inet.c
18746 --- linux-3.9.4/kernel/vserver/inet.c   1970-01-01 00:00:00.000000000 +0000
18747 +++ linux-3.9.4-vs2.3.6.2/kernel/vserver/inet.c 2013-05-31 22:43:05.000000000 +0000
18748 @@ -0,0 +1,236 @@
18749 +
18750 +#include <linux/in.h>
18751 +#include <linux/inetdevice.h>
18752 +#include <linux/export.h>
18753 +#include <linux/vs_inet.h>
18754 +#include <linux/vs_inet6.h>
18755 +#include <linux/vserver/debug.h>
18756 +#include <net/route.h>
18757 +#include <net/addrconf.h>
18758 +
18759 +
18760 +int nx_v4_addr_conflict(struct nx_info *nxi1, struct nx_info *nxi2)
18761 +{
18762 +       int ret = 0;
18763 +
18764 +       if (!nxi1 || !nxi2 || nxi1 == nxi2)
18765 +               ret = 1;
18766 +       else {
18767 +               struct nx_addr_v4 *ptr;
18768 +               unsigned long irqflags;
18769 +
18770 +               spin_lock_irqsave(&nxi1->addr_lock, irqflags);
18771 +               for (ptr = &nxi1->v4; ptr; ptr = ptr->next) {
18772 +                       if (v4_nx_addr_in_nx_info(nxi2, ptr, -1)) {
18773 +                               ret = 1;
18774 +                               break;
18775 +                       }
18776 +               }
18777 +               spin_unlock_irqrestore(&nxi1->addr_lock, irqflags);
18778 +       }
18779 +
18780 +       vxdprintk(VXD_CBIT(net, 2),
18781 +               "nx_v4_addr_conflict(%p,%p): %d",
18782 +               nxi1, nxi2, ret);
18783 +
18784 +       return ret;
18785 +}
18786 +
18787 +
18788 +#ifdef CONFIG_IPV6
18789 +
18790 +int nx_v6_addr_conflict(struct nx_info *nxi1, struct nx_info *nxi2)
18791 +{
18792 +       int ret = 0;
18793 +
18794 +       if (!nxi1 || !nxi2 || nxi1 == nxi2)
18795 +               ret = 1;
18796 +       else {
18797 +               struct nx_addr_v6 *ptr;
18798 +               unsigned long irqflags;
18799 +
18800 +               spin_lock_irqsave(&nxi1->addr_lock, irqflags);
18801 +               for (ptr = &nxi1->v6; ptr; ptr = ptr->next) {
18802 +                       if (v6_nx_addr_in_nx_info(nxi2, ptr, -1)) {
18803 +                               ret = 1;
18804 +                               break;
18805 +                       }
18806 +               }
18807 +               spin_unlock_irqrestore(&nxi1->addr_lock, irqflags);
18808 +       }
18809 +
18810 +       vxdprintk(VXD_CBIT(net, 2),
18811 +               "nx_v6_addr_conflict(%p,%p): %d",
18812 +               nxi1, nxi2, ret);
18813 +
18814 +       return ret;
18815 +}
18816 +
18817 +#endif
18818 +
18819 +int v4_dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
18820 +{
18821 +       struct in_device *in_dev;
18822 +       struct in_ifaddr **ifap;
18823 +       struct in_ifaddr *ifa;
18824 +       int ret = 0;
18825 +
18826 +       if (!dev)
18827 +               goto out;
18828 +       in_dev = in_dev_get(dev);
18829 +       if (!in_dev)
18830 +               goto out;
18831 +
18832 +       for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
18833 +               ifap = &ifa->ifa_next) {
18834 +               if (v4_addr_in_nx_info(nxi, ifa->ifa_local, NXA_MASK_SHOW)) {
18835 +                       ret = 1;
18836 +                       break;
18837 +               }
18838 +       }
18839 +       in_dev_put(in_dev);
18840 +out:
18841 +       return ret;
18842 +}
18843 +
18844 +
18845 +#ifdef CONFIG_IPV6
18846 +
18847 +int v6_dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
18848 +{
18849 +       struct inet6_dev *in_dev;
18850 +       struct inet6_ifaddr *ifa;
18851 +       int ret = 0;
18852 +
18853 +       if (!dev)
18854 +               goto out;
18855 +       in_dev = in6_dev_get(dev);
18856 +       if (!in_dev)
18857 +               goto out;
18858 +
18859 +       // for (ifap = &in_dev->addr_list; (ifa = *ifap) != NULL;
18860 +       list_for_each_entry(ifa, &in_dev->addr_list, if_list) {
18861 +               if (v6_addr_in_nx_info(nxi, &ifa->addr, -1)) {
18862 +                       ret = 1;
18863 +                       break;
18864 +               }
18865 +       }
18866 +       in6_dev_put(in_dev);
18867 +out:
18868 +       return ret;
18869 +}
18870 +
18871 +#endif
18872 +
18873 +int dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
18874 +{
18875 +       int ret = 1;
18876 +
18877 +       if (!nxi)
18878 +               goto out;
18879 +       if (nxi->v4.type && v4_dev_in_nx_info(dev, nxi))
18880 +               goto out;
18881 +#ifdef CONFIG_IPV6
18882 +       ret = 2;
18883 +       if (nxi->v6.type && v6_dev_in_nx_info(dev, nxi))
18884 +               goto out;
18885 +#endif
18886 +       ret = 0;
18887 +out:
18888 +       vxdprintk(VXD_CBIT(net, 3),
18889 +               "dev_in_nx_info(%p,%p[#%d]) = %d",
18890 +               dev, nxi, nxi ? nxi->nx_id : 0, ret);
18891 +       return ret;
18892 +}
18893 +
18894 +struct rtable *ip_v4_find_src(struct net *net, struct nx_info *nxi,
18895 +       struct flowi4 *fl4)
18896 +{
18897 +       struct rtable *rt;
18898 +
18899 +       if (!nxi)
18900 +               return NULL;
18901 +
18902 +       /* FIXME: handle lback only case */
18903 +       if (!NX_IPV4(nxi))
18904 +               return ERR_PTR(-EPERM);
18905 +
18906 +       vxdprintk(VXD_CBIT(net, 4),
18907 +               "ip_v4_find_src(%p[#%u]) " NIPQUAD_FMT " -> " NIPQUAD_FMT,
18908 +               nxi, nxi ? nxi->nx_id : 0,
18909 +               NIPQUAD(fl4->saddr), NIPQUAD(fl4->daddr));
18910 +
18911 +       /* single IP is unconditional */
18912 +       if (nx_info_flags(nxi, NXF_SINGLE_IP, 0) &&
18913 +               (fl4->saddr == INADDR_ANY))
18914 +               fl4->saddr = nxi->v4.ip[0].s_addr;
18915 +
18916 +       if (fl4->saddr == INADDR_ANY) {
18917 +               struct nx_addr_v4 *ptr;
18918 +               __be32 found = 0;
18919 +
18920 +               rt = __ip_route_output_key(net, fl4);
18921 +               if (!IS_ERR(rt)) {
18922 +                       found = fl4->saddr;
18923 +                       ip_rt_put(rt);
18924 +                       vxdprintk(VXD_CBIT(net, 4),
18925 +                               "ip_v4_find_src(%p[#%u]) rok[%u]: " NIPQUAD_FMT,
18926 +                               nxi, nxi ? nxi->nx_id : 0, fl4->flowi4_oif, NIPQUAD(found));
18927 +                       if (v4_addr_in_nx_info(nxi, found, NXA_MASK_BIND))
18928 +                               goto found;
18929 +               }
18930 +
18931 +               WARN_ON_ONCE(in_irq());
18932 +               spin_lock_bh(&nxi->addr_lock);
18933 +               for (ptr = &nxi->v4; ptr; ptr = ptr->next) {
18934 +                       __be32 primary = ptr->ip[0].s_addr;
18935 +                       __be32 mask = ptr->mask.s_addr;
18936 +                       __be32 neta = primary & mask;
18937 +
18938 +                       vxdprintk(VXD_CBIT(net, 4), "ip_v4_find_src(%p[#%u]) chk: "
18939 +                               NIPQUAD_FMT "/" NIPQUAD_FMT "/" NIPQUAD_FMT,
18940 +                               nxi, nxi ? nxi->nx_id : 0, NIPQUAD(primary),
18941 +                               NIPQUAD(mask), NIPQUAD(neta));
18942 +                       if ((found & mask) != neta)
18943 +                               continue;
18944 +
18945 +                       fl4->saddr = primary;
18946 +                       rt = __ip_route_output_key(net, fl4);
18947 +                       vxdprintk(VXD_CBIT(net, 4),
18948 +                               "ip_v4_find_src(%p[#%u]) rok[%u]: " NIPQUAD_FMT,
18949 +                               nxi, nxi ? nxi->nx_id : 0, fl4->flowi4_oif, NIPQUAD(primary));
18950 +                       if (!IS_ERR(rt)) {
18951 +                               found = fl4->saddr;
18952 +                               ip_rt_put(rt);
18953 +                               if (found == primary)
18954 +                                       goto found_unlock;
18955 +                       }
18956 +               }
18957 +               /* still no source ip? */
18958 +               found = ipv4_is_loopback(fl4->daddr)
18959 +                       ? IPI_LOOPBACK : nxi->v4.ip[0].s_addr;
18960 +       found_unlock:
18961 +               spin_unlock_bh(&nxi->addr_lock);
18962 +       found:
18963 +               /* assign src ip to flow */
18964 +               fl4->saddr = found;
18965 +
18966 +       } else {
18967 +               if (!v4_addr_in_nx_info(nxi, fl4->saddr, NXA_MASK_BIND))
18968 +                       return ERR_PTR(-EPERM);
18969 +       }
18970 +
18971 +       if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0)) {
18972 +               if (ipv4_is_loopback(fl4->daddr))
18973 +                       fl4->daddr = nxi->v4_lback.s_addr;
18974 +               if (ipv4_is_loopback(fl4->saddr))
18975 +                       fl4->saddr = nxi->v4_lback.s_addr;
18976 +       } else if (ipv4_is_loopback(fl4->daddr) &&
18977 +               !nx_info_flags(nxi, NXF_LBACK_ALLOW, 0))
18978 +               return ERR_PTR(-EPERM);
18979 +
18980 +       return NULL;
18981 +}
18982 +
18983 +EXPORT_SYMBOL_GPL(ip_v4_find_src);
18984 +
18985 diff -NurpP --minimal linux-3.9.4/kernel/vserver/init.c linux-3.9.4-vs2.3.6.2/kernel/vserver/init.c
18986 --- linux-3.9.4/kernel/vserver/init.c   1970-01-01 00:00:00.000000000 +0000
18987 +++ linux-3.9.4-vs2.3.6.2/kernel/vserver/init.c 2013-05-31 14:47:11.000000000 +0000
18988 @@ -0,0 +1,45 @@
18989 +/*
18990 + *  linux/kernel/init.c
18991 + *
18992 + *  Virtual Server Init
18993 + *
18994 + *  Copyright (C) 2004-2007  Herbert Pötzl
18995 + *
18996 + *  V0.01  basic structure
18997 + *
18998 + */
18999 +
19000 +#include <linux/init.h>
19001 +
19002 +int    vserver_register_sysctl(void);
19003 +void   vserver_unregister_sysctl(void);
19004 +
19005 +
19006 +static int __init init_vserver(void)
19007 +{
19008 +       int ret = 0;
19009 +
19010 +#ifdef CONFIG_VSERVER_DEBUG
19011 +       vserver_register_sysctl();
19012 +#endif
19013 +       return ret;
19014 +}
19015 +
19016 +
19017 +static void __exit exit_vserver(void)
19018 +{
19019 +
19020 +#ifdef CONFIG_VSERVER_DEBUG
19021 +       vserver_unregister_sysctl();
19022 +#endif
19023 +       return;
19024 +}
19025 +
19026 +/* FIXME: GFP_ZONETYPES gone
19027 +long vx_slab[GFP_ZONETYPES]; */
19028 +long vx_area;
19029 +
19030 +
19031 +module_init(init_vserver);
19032 +module_exit(exit_vserver);
19033 +
19034 diff -NurpP --minimal linux-3.9.4/kernel/vserver/inode.c linux-3.9.4-vs2.3.6.2/kernel/vserver/inode.c
19035 --- linux-3.9.4/kernel/vserver/inode.c  1970-01-01 00:00:00.000000000 +0000
19036 +++ linux-3.9.4-vs2.3.6.2/kernel/vserver/inode.c        2013-06-01 08:26:06.000000000 +0000
19037 @@ -0,0 +1,437 @@
19038 +/*
19039 + *  linux/kernel/vserver/inode.c
19040 + *
19041 + *  Virtual Server: File System Support
19042 + *
19043 + *  Copyright (C) 2004-2007  Herbert Pötzl
19044 + *
19045 + *  V0.01  separated from vcontext V0.05
19046 + *  V0.02  moved to tag (instead of xid)
19047 + *
19048 + */
19049 +
19050 +#include <linux/tty.h>
19051 +#include <linux/proc_fs.h>
19052 +#include <linux/devpts_fs.h>
19053 +#include <linux/fs.h>
19054 +#include <linux/file.h>
19055 +#include <linux/mount.h>
19056 +#include <linux/parser.h>
19057 +#include <linux/namei.h>
19058 +#include <linux/vserver/inode.h>
19059 +#include <linux/vserver/inode_cmd.h>
19060 +#include <linux/vs_base.h>
19061 +#include <linux/vs_tag.h>
19062 +
19063 +#include <asm/uaccess.h>
19064 +
19065 +
19066 +static int __vc_get_iattr(struct inode *in, uint32_t *tag, uint32_t *flags, uint32_t *mask)
19067 +{
19068 +       struct proc_dir_entry *entry;
19069 +
19070 +       if (!in || !in->i_sb)
19071 +               return -ESRCH;
19072 +
19073 +       *flags = IATTR_TAG
19074 +               | (IS_IMMUTABLE(in) ? IATTR_IMMUTABLE : 0)
19075 +               | (IS_IXUNLINK(in) ? IATTR_IXUNLINK : 0)
19076 +               | (IS_BARRIER(in) ? IATTR_BARRIER : 0)
19077 +               | (IS_COW(in) ? IATTR_COW : 0);
19078 +       *mask = IATTR_IXUNLINK | IATTR_IMMUTABLE | IATTR_COW;
19079 +
19080 +       if (S_ISDIR(in->i_mode))
19081 +               *mask |= IATTR_BARRIER;
19082 +
19083 +       if (IS_TAGGED(in)) {
19084 +               *tag = i_tag_read(in);
19085 +               *mask |= IATTR_TAG;
19086 +       }
19087 +
19088 +       switch (in->i_sb->s_magic) {
19089 +       case PROC_SUPER_MAGIC:
19090 +               entry = PROC_I(in)->pde;
19091 +
19092 +               /* check for specific inodes? */
19093 +               if (entry)
19094 +                       *mask |= IATTR_FLAGS;
19095 +               if (entry)
19096 +                       *flags |= (entry->vx_flags & IATTR_FLAGS);
19097 +               else
19098 +                       *flags |= (PROC_I(in)->vx_flags & IATTR_FLAGS);
19099 +               break;
19100 +
19101 +       case DEVPTS_SUPER_MAGIC:
19102 +               *tag = i_tag_read(in);
19103 +               *mask |= IATTR_TAG;
19104 +               break;
19105 +
19106 +       default:
19107 +               break;
19108 +       }
19109 +       return 0;
19110 +}
19111 +
19112 +int vc_get_iattr(void __user *data)
19113 +{
19114 +       struct path path;
19115 +       struct vcmd_ctx_iattr_v1 vc_data = { .tag = -1 };
19116 +       int ret;
19117 +
19118 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19119 +               return -EFAULT;
19120 +
19121 +       ret = user_lpath(vc_data.name, &path);
19122 +       if (!ret) {
19123 +               ret = __vc_get_iattr(path.dentry->d_inode,
19124 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
19125 +               path_put(&path);
19126 +       }
19127 +       if (ret)
19128 +               return ret;
19129 +
19130 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19131 +               ret = -EFAULT;
19132 +       return ret;
19133 +}
19134 +
19135 +#ifdef CONFIG_COMPAT
19136 +
19137 +int vc_get_iattr_x32(void __user *data)
19138 +{
19139 +       struct path path;
19140 +       struct vcmd_ctx_iattr_v1_x32 vc_data = { .tag = -1 };
19141 +       int ret;
19142 +
19143 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19144 +               return -EFAULT;
19145 +
19146 +       ret = user_lpath(compat_ptr(vc_data.name_ptr), &path);
19147 +       if (!ret) {
19148 +               ret = __vc_get_iattr(path.dentry->d_inode,
19149 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
19150 +               path_put(&path);
19151 +       }
19152 +       if (ret)
19153 +               return ret;
19154 +
19155 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19156 +               ret = -EFAULT;
19157 +       return ret;
19158 +}
19159 +
19160 +#endif /* CONFIG_COMPAT */
19161 +
19162 +
19163 +int vc_fget_iattr(uint32_t fd, void __user *data)
19164 +{
19165 +       struct file *filp;
19166 +       struct vcmd_ctx_fiattr_v0 vc_data = { .tag = -1 };
19167 +       int ret;
19168 +
19169 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19170 +               return -EFAULT;
19171 +
19172 +       filp = fget(fd);
19173 +       if (!filp || !filp->f_dentry || !filp->f_dentry->d_inode)
19174 +               return -EBADF;
19175 +
19176 +       ret = __vc_get_iattr(filp->f_dentry->d_inode,
19177 +               &vc_data.tag, &vc_data.flags, &vc_data.mask);
19178 +
19179 +       fput(filp);
19180 +
19181 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19182 +               ret = -EFAULT;
19183 +       return ret;
19184 +}
19185 +
19186 +
19187 +static int __vc_set_iattr(struct dentry *de, uint32_t *tag, uint32_t *flags, uint32_t *mask)
19188 +{
19189 +       struct inode *in = de->d_inode;
19190 +       int error = 0, is_proc = 0, has_tag = 0;
19191 +       struct iattr attr = { 0 };
19192 +
19193 +       if (!in || !in->i_sb)
19194 +               return -ESRCH;
19195 +
19196 +       is_proc = (in->i_sb->s_magic == PROC_SUPER_MAGIC);
19197 +       if ((*mask & IATTR_FLAGS) && !is_proc)
19198 +               return -EINVAL;
19199 +
19200 +       has_tag = IS_TAGGED(in) ||
19201 +               (in->i_sb->s_magic == DEVPTS_SUPER_MAGIC);
19202 +       if ((*mask & IATTR_TAG) && !has_tag)
19203 +               return -EINVAL;
19204 +
19205 +       mutex_lock(&in->i_mutex);
19206 +       if (*mask & IATTR_TAG) {
19207 +               attr.ia_tag = make_ktag(&init_user_ns, *tag);
19208 +               attr.ia_valid |= ATTR_TAG;
19209 +       }
19210 +
19211 +       if (*mask & IATTR_FLAGS) {
19212 +               struct proc_dir_entry *entry = PROC_I(in)->pde;
19213 +               unsigned int iflags = PROC_I(in)->vx_flags;
19214 +
19215 +               iflags = (iflags & ~(*mask & IATTR_FLAGS))
19216 +                       | (*flags & IATTR_FLAGS);
19217 +               PROC_I(in)->vx_flags = iflags;
19218 +               if (entry)
19219 +                       entry->vx_flags = iflags;
19220 +       }
19221 +
19222 +       if (*mask & (IATTR_IMMUTABLE | IATTR_IXUNLINK |
19223 +               IATTR_BARRIER | IATTR_COW)) {
19224 +               int iflags = in->i_flags;
19225 +               int vflags = in->i_vflags;
19226 +
19227 +               if (*mask & IATTR_IMMUTABLE) {
19228 +                       if (*flags & IATTR_IMMUTABLE)
19229 +                               iflags |= S_IMMUTABLE;
19230 +                       else
19231 +                               iflags &= ~S_IMMUTABLE;
19232 +               }
19233 +               if (*mask & IATTR_IXUNLINK) {
19234 +                       if (*flags & IATTR_IXUNLINK)
19235 +                               iflags |= S_IXUNLINK;
19236 +                       else
19237 +                               iflags &= ~S_IXUNLINK;
19238 +               }
19239 +               if (S_ISDIR(in->i_mode) && (*mask & IATTR_BARRIER)) {
19240 +                       if (*flags & IATTR_BARRIER)
19241 +                               vflags |= V_BARRIER;
19242 +                       else
19243 +                               vflags &= ~V_BARRIER;
19244 +               }
19245 +               if (S_ISREG(in->i_mode) && (*mask & IATTR_COW)) {
19246 +                       if (*flags & IATTR_COW)
19247 +                               vflags |= V_COW;
19248 +                       else
19249 +                               vflags &= ~V_COW;
19250 +               }
19251 +               if (in->i_op && in->i_op->sync_flags) {
19252 +                       error = in->i_op->sync_flags(in, iflags, vflags);
19253 +                       if (error)
19254 +                               goto out;
19255 +               }
19256 +       }
19257 +
19258 +       if (attr.ia_valid) {
19259 +               if (in->i_op && in->i_op->setattr)
19260 +                       error = in->i_op->setattr(de, &attr);
19261 +               else {
19262 +                       error = inode_change_ok(in, &attr);
19263 +                       if (!error) {
19264 +                               setattr_copy(in, &attr);
19265 +                               mark_inode_dirty(in);
19266 +                       }
19267 +               }
19268 +       }
19269 +
19270 +out:
19271 +       mutex_unlock(&in->i_mutex);
19272 +       return error;
19273 +}
19274 +
19275 +int vc_set_iattr(void __user *data)
19276 +{
19277 +       struct path path;
19278 +       struct vcmd_ctx_iattr_v1 vc_data;
19279 +       int ret;
19280 +
19281 +       if (!capable(CAP_LINUX_IMMUTABLE))
19282 +               return -EPERM;
19283 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19284 +               return -EFAULT;
19285 +
19286 +       ret = user_lpath(vc_data.name, &path);
19287 +       if (!ret) {
19288 +               ret = __vc_set_iattr(path.dentry,
19289 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
19290 +               path_put(&path);
19291 +       }
19292 +
19293 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19294 +               ret = -EFAULT;
19295 +       return ret;
19296 +}
19297 +
19298 +#ifdef CONFIG_COMPAT
19299 +
19300 +int vc_set_iattr_x32(void __user *data)
19301 +{
19302 +       struct path path;
19303 +       struct vcmd_ctx_iattr_v1_x32 vc_data;
19304 +       int ret;
19305 +
19306 +       if (!capable(CAP_LINUX_IMMUTABLE))
19307 +               return -EPERM;
19308 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19309 +               return -EFAULT;
19310 +
19311 +       ret = user_lpath(compat_ptr(vc_data.name_ptr), &path);
19312 +       if (!ret) {
19313 +               ret = __vc_set_iattr(path.dentry,
19314 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
19315 +               path_put(&path);
19316 +       }
19317 +
19318 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19319 +               ret = -EFAULT;
19320 +       return ret;
19321 +}
19322 +
19323 +#endif /* CONFIG_COMPAT */
19324 +
19325 +int vc_fset_iattr(uint32_t fd, void __user *data)
19326 +{
19327 +       struct file *filp;
19328 +       struct vcmd_ctx_fiattr_v0 vc_data;
19329 +       int ret;
19330 +
19331 +       if (!capable(CAP_LINUX_IMMUTABLE))
19332 +               return -EPERM;
19333 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19334 +               return -EFAULT;
19335 +
19336 +       filp = fget(fd);
19337 +       if (!filp || !filp->f_dentry || !filp->f_dentry->d_inode)
19338 +               return -EBADF;
19339 +
19340 +       ret = __vc_set_iattr(filp->f_dentry, &vc_data.tag,
19341 +               &vc_data.flags, &vc_data.mask);
19342 +
19343 +       fput(filp);
19344 +
19345 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19346 +               return -EFAULT;
19347 +       return ret;
19348 +}
19349 +
19350 +
19351 +enum { Opt_notagcheck, Opt_tag, Opt_notag, Opt_tagid, Opt_err };
19352 +
19353 +static match_table_t tokens = {
19354 +       {Opt_notagcheck, "notagcheck"},
19355 +#ifdef CONFIG_PROPAGATE
19356 +       {Opt_notag, "notag"},
19357 +       {Opt_tag, "tag"},
19358 +       {Opt_tagid, "tagid=%u"},
19359 +#endif
19360 +       {Opt_err, NULL}
19361 +};
19362 +
19363 +
19364 +static void __dx_parse_remove(char *string, char *opt)
19365 +{
19366 +       char *p = strstr(string, opt);
19367 +       char *q = p;
19368 +
19369 +       if (p) {
19370 +               while (*q != '\0' && *q != ',')
19371 +                       q++;
19372 +               while (*q)
19373 +                       *p++ = *q++;
19374 +               while (*p)
19375 +                       *p++ = '\0';
19376 +       }
19377 +}
19378 +
19379 +int dx_parse_tag(char *string, tag_t *tag, int remove, int *mnt_flags,
19380 +                unsigned long *flags)
19381 +{
19382 +       int set = 0;
19383 +       substring_t args[MAX_OPT_ARGS];
19384 +       int token;
19385 +       char *s, *p, *opts;
19386 +#if defined(CONFIG_PROPAGATE) || defined(CONFIG_VSERVER_DEBUG)
19387 +       int option = 0;
19388 +#endif
19389 +
19390 +       if (!string)
19391 +               return 0;
19392 +       s = kstrdup(string, GFP_KERNEL | GFP_ATOMIC);
19393 +       if (!s)
19394 +               return 0;
19395 +
19396 +       opts = s;
19397 +       while ((p = strsep(&opts, ",")) != NULL) {
19398 +               token = match_token(p, tokens, args);
19399 +
19400 +               switch (token) {
19401 +#ifdef CONFIG_PROPAGATE
19402 +               case Opt_tag:
19403 +                       if (tag)
19404 +                               *tag = 0;
19405 +                       if (remove)
19406 +                               __dx_parse_remove(s, "tag");
19407 +                       *mnt_flags |= MNT_TAGID;
19408 +                       set |= MNT_TAGID;
19409 +                       break;
19410 +               case Opt_notag:
19411 +                       if (remove)
19412 +                               __dx_parse_remove(s, "notag");
19413 +                       *mnt_flags |= MNT_NOTAG;
19414 +                       set |= MNT_NOTAG;
19415 +                       break;
19416 +               case Opt_tagid:
19417 +                       if (tag && !match_int(args, &option))
19418 +                               *tag = option;
19419 +                       if (remove)
19420 +                               __dx_parse_remove(s, "tagid");
19421 +                       *mnt_flags |= MNT_TAGID;
19422 +                       set |= MNT_TAGID;
19423 +                       break;
19424 +#endif /* CONFIG_PROPAGATE */
19425 +               case Opt_notagcheck:
19426 +                       if (remove)
19427 +                               __dx_parse_remove(s, "notagcheck");
19428 +                       *flags |= MS_NOTAGCHECK;
19429 +                       set |= MS_NOTAGCHECK;
19430 +                       break;
19431 +               }
19432 +               vxdprintk(VXD_CBIT(tag, 7),
19433 +                       "dx_parse_tag(" VS_Q("%s") "): %d:#%d",
19434 +                       p, token, option);
19435 +       }
19436 +       if (set)
19437 +               strcpy(string, s);
19438 +       kfree(s);
19439 +       return set;
19440 +}
19441 +
19442 +#ifdef CONFIG_PROPAGATE
19443 +
19444 +void __dx_propagate_tag(struct nameidata *nd, struct inode *inode)
19445 +{
19446 +       tag_t new_tag = 0;
19447 +       struct vfsmount *mnt;
19448 +       int propagate;
19449 +
19450 +       if (!nd)
19451 +               return;
19452 +       mnt = nd->path.mnt;
19453 +       if (!mnt)
19454 +               return;
19455 +
19456 +       propagate = (mnt->mnt_flags & MNT_TAGID);
19457 +       if (propagate)
19458 +               new_tag = mnt->mnt_tag;
19459 +
19460 +       vxdprintk(VXD_CBIT(tag, 7),
19461 +               "dx_propagate_tag(%p[#%lu.%d]): %d,%d",
19462 +               inode, inode->i_ino, inode->i_tag,
19463 +               new_tag, (propagate) ? 1 : 0);
19464 +
19465 +       if (propagate)
19466 +               i_tag_write(inode, new_tag);
19467 +}
19468 +
19469 +#include <linux/module.h>
19470 +
19471 +EXPORT_SYMBOL_GPL(__dx_propagate_tag);
19472 +
19473 +#endif /* CONFIG_PROPAGATE */
19474 +
19475 diff -NurpP --minimal linux-3.9.4/kernel/vserver/limit.c linux-3.9.4-vs2.3.6.2/kernel/vserver/limit.c
19476 --- linux-3.9.4/kernel/vserver/limit.c  1970-01-01 00:00:00.000000000 +0000
19477 +++ linux-3.9.4-vs2.3.6.2/kernel/vserver/limit.c        2013-05-31 14:47:11.000000000 +0000
19478 @@ -0,0 +1,345 @@
19479 +/*
19480 + *  linux/kernel/vserver/limit.c
19481 + *
19482 + *  Virtual Server: Context Limits
19483 + *
19484 + *  Copyright (C) 2004-2010  Herbert Pötzl
19485 + *
19486 + *  V0.01  broken out from vcontext V0.05
19487 + *  V0.02  changed vcmds to vxi arg
19488 + *  V0.03  added memory cgroup support
19489 + *
19490 + */
19491 +
19492 +#include <linux/sched.h>
19493 +#include <linux/module.h>
19494 +#include <linux/memcontrol.h>
19495 +#include <linux/res_counter.h>
19496 +#include <linux/vs_limit.h>
19497 +#include <linux/vserver/limit.h>
19498 +#include <linux/vserver/limit_cmd.h>
19499 +
19500 +#include <asm/uaccess.h>
19501 +
19502 +
19503 +const char *vlimit_name[NUM_LIMITS] = {
19504 +       [RLIMIT_CPU]            = "CPU",
19505 +       [RLIMIT_NPROC]          = "NPROC",
19506 +       [RLIMIT_NOFILE]         = "NOFILE",
19507 +       [RLIMIT_LOCKS]          = "LOCKS",
19508 +       [RLIMIT_SIGPENDING]     = "SIGP",
19509 +       [RLIMIT_MSGQUEUE]       = "MSGQ",
19510 +
19511 +       [VLIMIT_NSOCK]          = "NSOCK",
19512 +       [VLIMIT_OPENFD]         = "OPENFD",
19513 +       [VLIMIT_SHMEM]          = "SHMEM",
19514 +       [VLIMIT_DENTRY]         = "DENTRY",
19515 +};
19516 +
19517 +EXPORT_SYMBOL_GPL(vlimit_name);
19518 +
19519 +#define MASK_ENTRY(x)  (1 << (x))
19520 +
19521 +const struct vcmd_ctx_rlimit_mask_v0 vlimit_mask = {
19522 +               /* minimum */
19523 +       0
19524 +       ,       /* softlimit */
19525 +       0
19526 +       ,       /* maximum */
19527 +       MASK_ENTRY( RLIMIT_NPROC        ) |
19528 +       MASK_ENTRY( RLIMIT_NOFILE       ) |
19529 +       MASK_ENTRY( RLIMIT_LOCKS        ) |
19530 +       MASK_ENTRY( RLIMIT_MSGQUEUE     ) |
19531 +
19532 +       MASK_ENTRY( VLIMIT_NSOCK        ) |
19533 +       MASK_ENTRY( VLIMIT_OPENFD       ) |
19534 +       MASK_ENTRY( VLIMIT_SHMEM        ) |
19535 +       MASK_ENTRY( VLIMIT_DENTRY       ) |
19536 +       0
19537 +};
19538 +               /* accounting only */
19539 +uint32_t account_mask =
19540 +       MASK_ENTRY( VLIMIT_SEMARY       ) |
19541 +       MASK_ENTRY( VLIMIT_NSEMS        ) |
19542 +       MASK_ENTRY( VLIMIT_MAPPED       ) |
19543 +       0;
19544 +
19545 +
19546 +static int is_valid_vlimit(int id)
19547 +{
19548 +       uint32_t mask = vlimit_mask.minimum |
19549 +               vlimit_mask.softlimit | vlimit_mask.maximum;
19550 +       return mask & (1 << id);
19551 +}
19552 +
19553 +static int is_accounted_vlimit(int id)
19554 +{
19555 +       if (is_valid_vlimit(id))
19556 +               return 1;
19557 +       return account_mask & (1 << id);
19558 +}
19559 +
19560 +
19561 +static inline uint64_t vc_get_soft(struct vx_info *vxi, int id)
19562 +{
19563 +       rlim_t limit = __rlim_soft(&vxi->limit, id);
19564 +       return VX_VLIM(limit);
19565 +}
19566 +
19567 +static inline uint64_t vc_get_hard(struct vx_info *vxi, int id)
19568 +{
19569 +       rlim_t limit = __rlim_hard(&vxi->limit, id);
19570 +       return VX_VLIM(limit);
19571 +}
19572 +
19573 +static int do_get_rlimit(struct vx_info *vxi, uint32_t id,
19574 +       uint64_t *minimum, uint64_t *softlimit, uint64_t *maximum)
19575 +{
19576 +       if (!is_valid_vlimit(id))
19577 +               return -EINVAL;
19578 +
19579 +       if (minimum)
19580 +               *minimum = CRLIM_UNSET;
19581 +       if (softlimit)
19582 +               *softlimit = vc_get_soft(vxi, id);
19583 +       if (maximum)
19584 +               *maximum = vc_get_hard(vxi, id);
19585 +       return 0;
19586 +}
19587 +
19588 +int vc_get_rlimit(struct vx_info *vxi, void __user *data)
19589 +{
19590 +       struct vcmd_ctx_rlimit_v0 vc_data;
19591 +       int ret;
19592 +
19593 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19594 +               return -EFAULT;
19595 +
19596 +       ret = do_get_rlimit(vxi, vc_data.id,
19597 +               &vc_data.minimum, &vc_data.softlimit, &vc_data.maximum);
19598 +       if (ret)
19599 +               return ret;
19600 +
19601 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19602 +               return -EFAULT;
19603 +       return 0;
19604 +}
19605 +
19606 +static int do_set_rlimit(struct vx_info *vxi, uint32_t id,
19607 +       uint64_t minimum, uint64_t softlimit, uint64_t maximum)
19608 +{
19609 +       if (!is_valid_vlimit(id))
19610 +               return -EINVAL;
19611 +
19612 +       if (maximum != CRLIM_KEEP)
19613 +               __rlim_hard(&vxi->limit, id) = VX_RLIM(maximum);
19614 +       if (softlimit != CRLIM_KEEP)
19615 +               __rlim_soft(&vxi->limit, id) = VX_RLIM(softlimit);
19616 +
19617 +       /* clamp soft limit */
19618 +       if (__rlim_soft(&vxi->limit, id) > __rlim_hard(&vxi->limit, id))
19619 +               __rlim_soft(&vxi->limit, id) = __rlim_hard(&vxi->limit, id);
19620 +
19621 +       return 0;
19622 +}
19623 +
19624 +int vc_set_rlimit(struct vx_info *vxi, void __user *data)
19625 +{
19626 +       struct vcmd_ctx_rlimit_v0 vc_data;
19627 +
19628 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19629 +               return -EFAULT;
19630 +
19631 +       return do_set_rlimit(vxi, vc_data.id,
19632 +               vc_data.minimum, vc_data.softlimit, vc_data.maximum);
19633 +}
19634 +
19635 +#ifdef CONFIG_IA32_EMULATION
19636 +
19637 +int vc_set_rlimit_x32(struct vx_info *vxi, void __user *data)
19638 +{
19639 +       struct vcmd_ctx_rlimit_v0_x32 vc_data;
19640 +
19641 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19642 +               return -EFAULT;
19643 +
19644 +       return do_set_rlimit(vxi, vc_data.id,
19645 +               vc_data.minimum, vc_data.softlimit, vc_data.maximum);
19646 +}
19647 +
19648 +int vc_get_rlimit_x32(struct vx_info *vxi, void __user *data)
19649 +{
19650 +       struct vcmd_ctx_rlimit_v0_x32 vc_data;
19651 +       int ret;
19652 +
19653 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19654 +               return -EFAULT;
19655 +
19656 +       ret = do_get_rlimit(vxi, vc_data.id,
19657 +               &vc_data.minimum, &vc_data.softlimit, &vc_data.maximum);
19658 +       if (ret)
19659 +               return ret;
19660 +
19661 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19662 +               return -EFAULT;
19663 +       return 0;
19664 +}
19665 +
19666 +#endif /* CONFIG_IA32_EMULATION */
19667 +
19668 +
19669 +int vc_get_rlimit_mask(uint32_t id, void __user *data)
19670 +{
19671 +       if (copy_to_user(data, &vlimit_mask, sizeof(vlimit_mask)))
19672 +               return -EFAULT;
19673 +       return 0;
19674 +}
19675 +
19676 +
19677 +static inline void vx_reset_hits(struct _vx_limit *limit)
19678 +{
19679 +       int lim;
19680 +
19681 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
19682 +               atomic_set(&__rlim_lhit(limit, lim), 0);
19683 +       }
19684 +}
19685 +
19686 +int vc_reset_hits(struct vx_info *vxi, void __user *data)
19687 +{
19688 +       vx_reset_hits(&vxi->limit);
19689 +       return 0;
19690 +}
19691 +
19692 +static inline void vx_reset_minmax(struct _vx_limit *limit)
19693 +{
19694 +       rlim_t value;
19695 +       int lim;
19696 +
19697 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
19698 +               value = __rlim_get(limit, lim);
19699 +               __rlim_rmax(limit, lim) = value;
19700 +               __rlim_rmin(limit, lim) = value;
19701 +       }
19702 +}
19703 +
19704 +int vc_reset_minmax(struct vx_info *vxi, void __user *data)
19705 +{
19706 +       vx_reset_minmax(&vxi->limit);
19707 +       return 0;
19708 +}
19709 +
19710 +
19711 +int vc_rlimit_stat(struct vx_info *vxi, void __user *data)
19712 +{
19713 +       struct vcmd_rlimit_stat_v0 vc_data;
19714 +       struct _vx_limit *limit = &vxi->limit;
19715 +       int id;
19716 +
19717 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19718 +               return -EFAULT;
19719 +
19720 +       id = vc_data.id;
19721 +       if (!is_accounted_vlimit(id))
19722 +               return -EINVAL;
19723 +
19724 +       vx_limit_fixup(limit, id);
19725 +       vc_data.hits = atomic_read(&__rlim_lhit(limit, id));
19726 +       vc_data.value = __rlim_get(limit, id);
19727 +       vc_data.minimum = __rlim_rmin(limit, id);
19728 +       vc_data.maximum = __rlim_rmax(limit, id);
19729 +
19730 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19731 +               return -EFAULT;
19732 +       return 0;
19733 +}
19734 +
19735 +
19736 +void vx_vsi_meminfo(struct sysinfo *val)
19737 +{
19738 +#ifdef CONFIG_MEMCG
19739 +       struct mem_cgroup *mcg;
19740 +       u64 res_limit, res_usage;
19741 +
19742 +       rcu_read_lock();
19743 +       mcg = mem_cgroup_from_task(current);
19744 +       rcu_read_unlock();
19745 +       if (!mcg)
19746 +               goto out;
19747 +
19748 +       res_limit = mem_cgroup_res_read_u64(mcg, RES_LIMIT);
19749 +       res_usage = mem_cgroup_res_read_u64(mcg, RES_USAGE);
19750 +
19751 +       if (res_limit != RESOURCE_MAX)
19752 +               val->totalram = (res_limit >> PAGE_SHIFT);
19753 +       val->freeram = val->totalram - (res_usage >> PAGE_SHIFT);
19754 +       val->bufferram = 0;
19755 +       val->totalhigh = 0;
19756 +       val->freehigh = 0;
19757 +out:
19758 +#endif /* CONFIG_MEMCG */
19759 +       return;
19760 +}
19761 +
19762 +void vx_vsi_swapinfo(struct sysinfo *val)
19763 +{
19764 +#ifdef CONFIG_MEMCG
19765 +#ifdef CONFIG_MEMCG_SWAP
19766 +       struct mem_cgroup *mcg;
19767 +       u64 res_limit, res_usage, memsw_limit, memsw_usage;
19768 +       s64 swap_limit, swap_usage;
19769 +
19770 +       rcu_read_lock();
19771 +       mcg = mem_cgroup_from_task(current);
19772 +       rcu_read_unlock();
19773 +       if (!mcg)
19774 +               goto out;
19775 +
19776 +       res_limit = mem_cgroup_res_read_u64(mcg, RES_LIMIT);
19777 +       res_usage = mem_cgroup_res_read_u64(mcg, RES_USAGE);
19778 +       memsw_limit = mem_cgroup_memsw_read_u64(mcg, RES_LIMIT);
19779 +       memsw_usage = mem_cgroup_memsw_read_u64(mcg, RES_USAGE);
19780 +
19781 +       /* memory unlimited */
19782 +       if (res_limit == RESOURCE_MAX)
19783 +               goto out;
19784 +
19785 +       swap_limit = memsw_limit - res_limit;
19786 +       /* we have a swap limit? */
19787 +       if (memsw_limit != RESOURCE_MAX)
19788 +               val->totalswap = swap_limit >> PAGE_SHIFT;
19789 +
19790 +       /* calculate swap part */
19791 +       swap_usage = (memsw_usage > res_usage) ?
19792 +               memsw_usage - res_usage : 0;
19793 +
19794 +       /* total shown minus usage gives free swap */
19795 +       val->freeswap = (swap_usage < swap_limit) ?
19796 +               val->totalswap - (swap_usage >> PAGE_SHIFT) : 0;
19797 +out:
19798 +#else  /* !CONFIG_MEMCG_SWAP */
19799 +       val->totalswap = 0;
19800 +       val->freeswap = 0;
19801 +#endif /* !CONFIG_MEMCG_SWAP */
19802 +#endif /* CONFIG_MEMCG */
19803 +       return;
19804 +}
19805 +
19806 +long vx_vsi_cached(struct sysinfo *val)
19807 +{
19808 +       long cache = 0;
19809 +#ifdef CONFIG_MEMCG
19810 +       struct mem_cgroup *mcg;
19811 +
19812 +       rcu_read_lock();
19813 +       mcg = mem_cgroup_from_task(current);
19814 +       rcu_read_unlock();
19815 +       if (!mcg)
19816 +               goto out;
19817 +
19818 +       cache = mem_cgroup_stat_read_cache(mcg);
19819 +out:
19820 +#endif
19821 +       return cache;
19822 +}
19823 +
19824 diff -NurpP --minimal linux-3.9.4/kernel/vserver/limit_init.h linux-3.9.4-vs2.3.6.2/kernel/vserver/limit_init.h
19825 --- linux-3.9.4/kernel/vserver/limit_init.h     1970-01-01 00:00:00.000000000 +0000
19826 +++ linux-3.9.4-vs2.3.6.2/kernel/vserver/limit_init.h   2013-05-31 14:47:11.000000000 +0000
19827 @@ -0,0 +1,31 @@
19828 +
19829 +
19830 +static inline void vx_info_init_limit(struct _vx_limit *limit)
19831 +{
19832 +       int lim;
19833 +
19834 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
19835 +               __rlim_soft(limit, lim) = RLIM_INFINITY;
19836 +               __rlim_hard(limit, lim) = RLIM_INFINITY;
19837 +               __rlim_set(limit, lim, 0);
19838 +               atomic_set(&__rlim_lhit(limit, lim), 0);
19839 +               __rlim_rmin(limit, lim) = 0;
19840 +               __rlim_rmax(limit, lim) = 0;
19841 +       }
19842 +}
19843 +
19844 +static inline void vx_info_exit_limit(struct _vx_limit *limit)
19845 +{
19846 +       rlim_t value;
19847 +       int lim;
19848 +
19849 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
19850 +               if ((1 << lim) & VLIM_NOCHECK)
19851 +                       continue;
19852 +               value = __rlim_get(limit, lim);
19853 +               vxwprintk_xid(value,
19854 +                       "!!! limit: %p[%s,%d] = %ld on exit.",
19855 +                       limit, vlimit_name[lim], lim, (long)value);
19856 +       }
19857 +}
19858 +
19859 diff -NurpP --minimal linux-3.9.4/kernel/vserver/limit_proc.h linux-3.9.4-vs2.3.6.2/kernel/vserver/limit_proc.h
19860 --- linux-3.9.4/kernel/vserver/limit_proc.h     1970-01-01 00:00:00.000000000 +0000
19861 +++ linux-3.9.4-vs2.3.6.2/kernel/vserver/limit_proc.h   2013-05-31 14:47:11.000000000 +0000
19862 @@ -0,0 +1,57 @@
19863 +#ifndef _VX_LIMIT_PROC_H
19864 +#define _VX_LIMIT_PROC_H
19865 +
19866 +#include <linux/vserver/limit_int.h>
19867 +
19868 +
19869 +#define VX_LIMIT_FMT   ":\t%8ld\t%8ld/%8ld\t%8lld/%8lld\t%6d\n"
19870 +#define VX_LIMIT_TOP   \
19871 +       "Limit\t current\t     min/max\t\t    soft/hard\t\thits\n"
19872 +
19873 +#define VX_LIMIT_ARG(r)                                \
19874 +       (unsigned long)__rlim_get(limit, r),    \
19875 +       (unsigned long)__rlim_rmin(limit, r),   \
19876 +       (unsigned long)__rlim_rmax(limit, r),   \
19877 +       VX_VLIM(__rlim_soft(limit, r)),         \
19878 +       VX_VLIM(__rlim_hard(limit, r)),         \
19879 +       atomic_read(&__rlim_lhit(limit, r))
19880 +
19881 +static inline int vx_info_proc_limit(struct _vx_limit *limit, char *buffer)
19882 +{
19883 +       vx_limit_fixup(limit, -1);
19884 +       return sprintf(buffer, VX_LIMIT_TOP
19885 +               "PROC"  VX_LIMIT_FMT
19886 +               "VM"    VX_LIMIT_FMT
19887 +               "VML"   VX_LIMIT_FMT
19888 +               "RSS"   VX_LIMIT_FMT
19889 +               "ANON"  VX_LIMIT_FMT
19890 +               "RMAP"  VX_LIMIT_FMT
19891 +               "FILES" VX_LIMIT_FMT
19892 +               "OFD"   VX_LIMIT_FMT
19893 +               "LOCKS" VX_LIMIT_FMT
19894 +               "SOCK"  VX_LIMIT_FMT
19895 +               "MSGQ"  VX_LIMIT_FMT
19896 +               "SHM"   VX_LIMIT_FMT
19897 +               "SEMA"  VX_LIMIT_FMT
19898 +               "SEMS"  VX_LIMIT_FMT
19899 +               "DENT"  VX_LIMIT_FMT,
19900 +               VX_LIMIT_ARG(RLIMIT_NPROC),
19901 +               VX_LIMIT_ARG(RLIMIT_AS),
19902 +               VX_LIMIT_ARG(RLIMIT_MEMLOCK),
19903 +               VX_LIMIT_ARG(RLIMIT_RSS),
19904 +               VX_LIMIT_ARG(VLIMIT_ANON),
19905 +               VX_LIMIT_ARG(VLIMIT_MAPPED),
19906 +               VX_LIMIT_ARG(RLIMIT_NOFILE),
19907 +               VX_LIMIT_ARG(VLIMIT_OPENFD),
19908 +               VX_LIMIT_ARG(RLIMIT_LOCKS),
19909 +               VX_LIMIT_ARG(VLIMIT_NSOCK),
19910 +               VX_LIMIT_ARG(RLIMIT_MSGQUEUE),
19911 +               VX_LIMIT_ARG(VLIMIT_SHMEM),
19912 +               VX_LIMIT_ARG(VLIMIT_SEMARY),
19913 +               VX_LIMIT_ARG(VLIMIT_NSEMS),
19914 +               VX_LIMIT_ARG(VLIMIT_DENTRY));
19915 +}
19916 +
19917 +#endif /* _VX_LIMIT_PROC_H */
19918 +
19919 +
19920 diff -NurpP --minimal linux-3.9.4/kernel/vserver/network.c linux-3.9.4-vs2.3.6.2/kernel/vserver/network.c
19921 --- linux-3.9.4/kernel/vserver/network.c        1970-01-01 00:00:00.000000000 +0000
19922 +++ linux-3.9.4-vs2.3.6.2/kernel/vserver/network.c      2013-05-31 14:47:11.000000000 +0000
19923 @@ -0,0 +1,1053 @@
19924 +/*
19925 + *  linux/kernel/vserver/network.c
19926 + *
19927 + *  Virtual Server: Network Support
19928 + *
19929 + *  Copyright (C) 2003-2007  Herbert Pötzl
19930 + *
19931 + *  V0.01  broken out from vcontext V0.05
19932 + *  V0.02  cleaned up implementation
19933 + *  V0.03  added equiv nx commands
19934 + *  V0.04  switch to RCU based hash
19935 + *  V0.05  and back to locking again
19936 + *  V0.06  changed vcmds to nxi arg
19937 + *  V0.07  have __create claim() the nxi
19938 + *
19939 + */
19940 +
19941 +#include <linux/err.h>
19942 +#include <linux/slab.h>
19943 +#include <linux/rcupdate.h>
19944 +#include <net/ipv6.h>
19945 +
19946 +#include <linux/vs_network.h>
19947 +#include <linux/vs_pid.h>
19948 +#include <linux/vserver/network_cmd.h>
19949 +
19950 +
19951 +atomic_t nx_global_ctotal      = ATOMIC_INIT(0);
19952 +atomic_t nx_global_cactive     = ATOMIC_INIT(0);
19953 +
19954 +static struct kmem_cache *nx_addr_v4_cachep = NULL;
19955 +static struct kmem_cache *nx_addr_v6_cachep = NULL;
19956 +
19957 +
19958 +static int __init init_network(void)
19959 +{
19960 +       nx_addr_v4_cachep = kmem_cache_create("nx_v4_addr_cache",
19961 +               sizeof(struct nx_addr_v4), 0,
19962 +               SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
19963 +       nx_addr_v6_cachep = kmem_cache_create("nx_v6_addr_cache",
19964 +               sizeof(struct nx_addr_v6), 0,
19965 +               SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
19966 +       return 0;
19967 +}
19968 +
19969 +
19970 +/*     __alloc_nx_addr_v4()                                    */
19971 +
19972 +static inline struct nx_addr_v4 *__alloc_nx_addr_v4(void)
19973 +{
19974 +       struct nx_addr_v4 *nxa = kmem_cache_alloc(
19975 +               nx_addr_v4_cachep, GFP_KERNEL);
19976 +
19977 +       if (!IS_ERR(nxa))
19978 +               memset(nxa, 0, sizeof(*nxa));
19979 +       return nxa;
19980 +}
19981 +
19982 +/*     __dealloc_nx_addr_v4()                                  */
19983 +
19984 +static inline void __dealloc_nx_addr_v4(struct nx_addr_v4 *nxa)
19985 +{
19986 +       kmem_cache_free(nx_addr_v4_cachep, nxa);
19987 +}
19988 +
19989 +/*     __dealloc_nx_addr_v4_all()                              */
19990 +
19991 +static inline void __dealloc_nx_addr_v4_all(struct nx_addr_v4 *nxa)
19992 +{
19993 +       while (nxa) {
19994 +               struct nx_addr_v4 *next = nxa->next;
19995 +
19996 +               __dealloc_nx_addr_v4(nxa);
19997 +               nxa = next;
19998 +       }
19999 +}
20000 +
20001 +
20002 +#ifdef CONFIG_IPV6
20003 +
20004 +/*     __alloc_nx_addr_v6()                                    */
20005 +
20006 +static inline struct nx_addr_v6 *__alloc_nx_addr_v6(void)
20007 +{
20008 +       struct nx_addr_v6 *nxa = kmem_cache_alloc(
20009 +               nx_addr_v6_cachep, GFP_KERNEL);
20010 +
20011 +       if (!IS_ERR(nxa))
20012 +               memset(nxa, 0, sizeof(*nxa));
20013 +       return nxa;
20014 +}
20015 +
20016 +/*     __dealloc_nx_addr_v6()                                  */
20017 +
20018 +static inline void __dealloc_nx_addr_v6(struct nx_addr_v6 *nxa)
20019 +{
20020 +       kmem_cache_free(nx_addr_v6_cachep, nxa);
20021 +}
20022 +
20023 +/*     __dealloc_nx_addr_v6_all()                              */
20024 +
20025 +static inline void __dealloc_nx_addr_v6_all(struct nx_addr_v6 *nxa)
20026 +{
20027 +       while (nxa) {
20028 +               struct nx_addr_v6 *next = nxa->next;
20029 +
20030 +               __dealloc_nx_addr_v6(nxa);
20031 +               nxa = next;
20032 +       }
20033 +}
20034 +
20035 +#endif /* CONFIG_IPV6 */
20036 +
20037 +/*     __alloc_nx_info()
20038 +
20039 +       * allocate an initialized nx_info struct
20040 +       * doesn't make it visible (hash)                        */
20041 +
20042 +static struct nx_info *__alloc_nx_info(nid_t nid)
20043 +{
20044 +       struct nx_info *new = NULL;
20045 +
20046 +       vxdprintk(VXD_CBIT(nid, 1), "alloc_nx_info(%d)*", nid);
20047 +
20048 +       /* would this benefit from a slab cache? */
20049 +       new = kmalloc(sizeof(struct nx_info), GFP_KERNEL);
20050 +       if (!new)
20051 +               return 0;
20052 +
20053 +       memset(new, 0, sizeof(struct nx_info));
20054 +       new->nx_id = nid;
20055 +       INIT_HLIST_NODE(&new->nx_hlist);
20056 +       atomic_set(&new->nx_usecnt, 0);
20057 +       atomic_set(&new->nx_tasks, 0);
20058 +       spin_lock_init(&new->addr_lock);
20059 +       new->nx_state = 0;
20060 +
20061 +       new->nx_flags = NXF_INIT_SET;
20062 +
20063 +       /* rest of init goes here */
20064 +
20065 +       new->v4_lback.s_addr = htonl(INADDR_LOOPBACK);
20066 +       new->v4_bcast.s_addr = htonl(INADDR_BROADCAST);
20067 +
20068 +       vxdprintk(VXD_CBIT(nid, 0),
20069 +               "alloc_nx_info(%d) = %p", nid, new);
20070 +       atomic_inc(&nx_global_ctotal);
20071 +       return new;
20072 +}
20073 +
20074 +/*     __dealloc_nx_info()
20075 +
20076 +       * final disposal of nx_info                             */
20077 +
20078 +static void __dealloc_nx_info(struct nx_info *nxi)
20079 +{
20080 +       vxdprintk(VXD_CBIT(nid, 0),
20081 +               "dealloc_nx_info(%p)", nxi);
20082 +
20083 +       nxi->nx_hlist.next = LIST_POISON1;
20084 +       nxi->nx_id = -1;
20085 +
20086 +       BUG_ON(atomic_read(&nxi->nx_usecnt));
20087 +       BUG_ON(atomic_read(&nxi->nx_tasks));
20088 +
20089 +       __dealloc_nx_addr_v4_all(nxi->v4.next);
20090 +#ifdef CONFIG_IPV6
20091 +       __dealloc_nx_addr_v6_all(nxi->v6.next);
20092 +#endif
20093 +
20094 +       nxi->nx_state |= NXS_RELEASED;
20095 +       kfree(nxi);
20096 +       atomic_dec(&nx_global_ctotal);
20097 +}
20098 +
20099 +static void __shutdown_nx_info(struct nx_info *nxi)
20100 +{
20101 +       nxi->nx_state |= NXS_SHUTDOWN;
20102 +       vs_net_change(nxi, VSC_NETDOWN);
20103 +}
20104 +
20105 +/*     exported stuff                                          */
20106 +
20107 +void free_nx_info(struct nx_info *nxi)
20108 +{
20109 +       /* context shutdown is mandatory */
20110 +       BUG_ON(nxi->nx_state != NXS_SHUTDOWN);
20111 +
20112 +       /* context must not be hashed */
20113 +       BUG_ON(nxi->nx_state & NXS_HASHED);
20114 +
20115 +       BUG_ON(atomic_read(&nxi->nx_usecnt));
20116 +       BUG_ON(atomic_read(&nxi->nx_tasks));
20117 +
20118 +       __dealloc_nx_info(nxi);
20119 +}
20120 +
20121 +
20122 +void __nx_set_lback(struct nx_info *nxi)
20123 +{
20124 +       int nid = nxi->nx_id;
20125 +       __be32 lback = htonl(INADDR_LOOPBACK ^ ((nid & 0xFFFF) << 8));
20126 +
20127 +       nxi->v4_lback.s_addr = lback;
20128 +}
20129 +
20130 +extern int __nx_inet_add_lback(__be32 addr);
20131 +extern int __nx_inet_del_lback(__be32 addr);
20132 +
20133 +
20134 +/*     hash table for nx_info hash */
20135 +
20136 +#define NX_HASH_SIZE   13
20137 +
20138 +struct hlist_head nx_info_hash[NX_HASH_SIZE];
20139 +
20140 +static DEFINE_SPINLOCK(nx_info_hash_lock);
20141 +
20142 +
20143 +static inline unsigned int __hashval(nid_t nid)
20144 +{
20145 +       return (nid % NX_HASH_SIZE);
20146 +}
20147 +
20148 +
20149 +
20150 +/*     __hash_nx_info()
20151 +
20152 +       * add the nxi to the global hash table
20153 +       * requires the hash_lock to be held                     */
20154 +
20155 +static inline void __hash_nx_info(struct nx_info *nxi)
20156 +{
20157 +       struct hlist_head *head;
20158 +
20159 +       vxd_assert_lock(&nx_info_hash_lock);
20160 +       vxdprintk(VXD_CBIT(nid, 4),
20161 +               "__hash_nx_info: %p[#%d]", nxi, nxi->nx_id);
20162 +
20163 +       /* context must not be hashed */
20164 +       BUG_ON(nx_info_state(nxi, NXS_HASHED));
20165 +
20166 +       nxi->nx_state |= NXS_HASHED;
20167 +       head = &nx_info_hash[__hashval(nxi->nx_id)];
20168 +       hlist_add_head(&nxi->nx_hlist, head);
20169 +       atomic_inc(&nx_global_cactive);
20170 +}
20171 +
20172 +/*     __unhash_nx_info()
20173 +
20174 +       * remove the nxi from the global hash table
20175 +       * requires the hash_lock to be held                     */
20176 +
20177 +static inline void __unhash_nx_info(struct nx_info *nxi)
20178 +{
20179 +       vxd_assert_lock(&nx_info_hash_lock);
20180 +       vxdprintk(VXD_CBIT(nid, 4),
20181 +               "__unhash_nx_info: %p[#%d.%d.%d]", nxi, nxi->nx_id,
20182 +               atomic_read(&nxi->nx_usecnt), atomic_read(&nxi->nx_tasks));
20183 +
20184 +       /* context must be hashed */
20185 +       BUG_ON(!nx_info_state(nxi, NXS_HASHED));
20186 +       /* but without tasks */
20187 +       BUG_ON(atomic_read(&nxi->nx_tasks));
20188 +
20189 +       nxi->nx_state &= ~NXS_HASHED;
20190 +       hlist_del(&nxi->nx_hlist);
20191 +       atomic_dec(&nx_global_cactive);
20192 +}
20193 +
20194 +
20195 +/*     __lookup_nx_info()
20196 +
20197 +       * requires the hash_lock to be held
20198 +       * doesn't increment the nx_refcnt                       */
20199 +
20200 +static inline struct nx_info *__lookup_nx_info(nid_t nid)
20201 +{
20202 +       struct hlist_head *head = &nx_info_hash[__hashval(nid)];
20203 +       struct hlist_node *pos;
20204 +       struct nx_info *nxi;
20205 +
20206 +       vxd_assert_lock(&nx_info_hash_lock);
20207 +       hlist_for_each(pos, head) {
20208 +               nxi = hlist_entry(pos, struct nx_info, nx_hlist);
20209 +
20210 +               if (nxi->nx_id == nid)
20211 +                       goto found;
20212 +       }
20213 +       nxi = NULL;
20214 +found:
20215 +       vxdprintk(VXD_CBIT(nid, 0),
20216 +               "__lookup_nx_info(#%u): %p[#%u]",
20217 +               nid, nxi, nxi ? nxi->nx_id : 0);
20218 +       return nxi;
20219 +}
20220 +
20221 +
20222 +/*     __create_nx_info()
20223 +
20224 +       * create the requested context
20225 +       * get(), claim() and hash it                            */
20226 +
20227 +static struct nx_info *__create_nx_info(int id)
20228 +{
20229 +       struct nx_info *new, *nxi = NULL;
20230 +
20231 +       vxdprintk(VXD_CBIT(nid, 1), "create_nx_info(%d)*", id);
20232 +
20233 +       if (!(new = __alloc_nx_info(id)))
20234 +               return ERR_PTR(-ENOMEM);
20235 +
20236 +       /* required to make dynamic xids unique */
20237 +       spin_lock(&nx_info_hash_lock);
20238 +
20239 +       /* static context requested */
20240 +       if ((nxi = __lookup_nx_info(id))) {
20241 +               vxdprintk(VXD_CBIT(nid, 0),
20242 +                       "create_nx_info(%d) = %p (already there)", id, nxi);
20243 +               if (nx_info_flags(nxi, NXF_STATE_SETUP, 0))
20244 +                       nxi = ERR_PTR(-EBUSY);
20245 +               else
20246 +                       nxi = ERR_PTR(-EEXIST);
20247 +               goto out_unlock;
20248 +       }
20249 +       /* new context */
20250 +       vxdprintk(VXD_CBIT(nid, 0),
20251 +               "create_nx_info(%d) = %p (new)", id, new);
20252 +       claim_nx_info(new, NULL);
20253 +       __nx_set_lback(new);
20254 +       __hash_nx_info(get_nx_info(new));
20255 +       nxi = new, new = NULL;
20256 +
20257 +out_unlock:
20258 +       spin_unlock(&nx_info_hash_lock);
20259 +       if (new)
20260 +               __dealloc_nx_info(new);
20261 +       return nxi;
20262 +}
20263 +
20264 +
20265 +
20266 +/*     exported stuff                                          */
20267 +
20268 +
20269 +void unhash_nx_info(struct nx_info *nxi)
20270 +{
20271 +       __shutdown_nx_info(nxi);
20272 +       spin_lock(&nx_info_hash_lock);
20273 +       __unhash_nx_info(nxi);
20274 +       spin_unlock(&nx_info_hash_lock);
20275 +}
20276 +
20277 +/*     lookup_nx_info()
20278 +
20279 +       * search for a nx_info and get() it
20280 +       * negative id means current                             */
20281 +
20282 +struct nx_info *lookup_nx_info(int id)
20283 +{
20284 +       struct nx_info *nxi = NULL;
20285 +
20286 +       if (id < 0) {
20287 +               nxi = get_nx_info(current_nx_info());
20288 +       } else if (id > 1) {
20289 +               spin_lock(&nx_info_hash_lock);
20290 +               nxi = get_nx_info(__lookup_nx_info(id));
20291 +               spin_unlock(&nx_info_hash_lock);
20292 +       }
20293 +       return nxi;
20294 +}
20295 +
20296 +/*     nid_is_hashed()
20297 +
20298 +       * verify that nid is still hashed                       */
20299 +
20300 +int nid_is_hashed(nid_t nid)
20301 +{
20302 +       int hashed;
20303 +
20304 +       spin_lock(&nx_info_hash_lock);
20305 +       hashed = (__lookup_nx_info(nid) != NULL);
20306 +       spin_unlock(&nx_info_hash_lock);
20307 +       return hashed;
20308 +}
20309 +
20310 +
20311 +#ifdef CONFIG_PROC_FS
20312 +
20313 +/*     get_nid_list()
20314 +
20315 +       * get a subset of hashed nids for proc
20316 +       * assumes size is at least one                          */
20317 +
20318 +int get_nid_list(int index, unsigned int *nids, int size)
20319 +{
20320 +       int hindex, nr_nids = 0;
20321 +
20322 +       /* only show current and children */
20323 +       if (!nx_check(0, VS_ADMIN | VS_WATCH)) {
20324 +               if (index > 0)
20325 +                       return 0;
20326 +               nids[nr_nids] = nx_current_nid();
20327 +               return 1;
20328 +       }
20329 +
20330 +       for (hindex = 0; hindex < NX_HASH_SIZE; hindex++) {
20331 +               struct hlist_head *head = &nx_info_hash[hindex];
20332 +               struct hlist_node *pos;
20333 +
20334 +               spin_lock(&nx_info_hash_lock);
20335 +               hlist_for_each(pos, head) {
20336 +                       struct nx_info *nxi;
20337 +
20338 +                       if (--index > 0)
20339 +                               continue;
20340 +
20341 +                       nxi = hlist_entry(pos, struct nx_info, nx_hlist);
20342 +                       nids[nr_nids] = nxi->nx_id;
20343 +                       if (++nr_nids >= size) {
20344 +                               spin_unlock(&nx_info_hash_lock);
20345 +                               goto out;
20346 +                       }
20347 +               }
20348 +               /* keep the lock time short */
20349 +               spin_unlock(&nx_info_hash_lock);
20350 +       }
20351 +out:
20352 +       return nr_nids;
20353 +}
20354 +#endif
20355 +
20356 +
20357 +/*
20358 + *     migrate task to new network
20359 + *     gets nxi, puts old_nxi on change
20360 + */
20361 +
20362 +int nx_migrate_task(struct task_struct *p, struct nx_info *nxi)
20363 +{
20364 +       struct nx_info *old_nxi;
20365 +       int ret = 0;
20366 +
20367 +       if (!p || !nxi)
20368 +               BUG();
20369 +
20370 +       vxdprintk(VXD_CBIT(nid, 5),
20371 +               "nx_migrate_task(%p,%p[#%d.%d.%d])",
20372 +               p, nxi, nxi->nx_id,
20373 +               atomic_read(&nxi->nx_usecnt),
20374 +               atomic_read(&nxi->nx_tasks));
20375 +
20376 +       if (nx_info_flags(nxi, NXF_INFO_PRIVATE, 0) &&
20377 +               !nx_info_flags(nxi, NXF_STATE_SETUP, 0))
20378 +               return -EACCES;
20379 +
20380 +       if (nx_info_state(nxi, NXS_SHUTDOWN))
20381 +               return -EFAULT;
20382 +
20383 +       /* maybe disallow this completely? */
20384 +       old_nxi = task_get_nx_info(p);
20385 +       if (old_nxi == nxi)
20386 +               goto out;
20387 +
20388 +       task_lock(p);
20389 +       if (old_nxi)
20390 +               clr_nx_info(&p->nx_info);
20391 +       claim_nx_info(nxi, p);
20392 +       set_nx_info(&p->nx_info, nxi);
20393 +       p->nid = nxi->nx_id;
20394 +       task_unlock(p);
20395 +
20396 +       vxdprintk(VXD_CBIT(nid, 5),
20397 +               "moved task %p into nxi:%p[#%d]",
20398 +               p, nxi, nxi->nx_id);
20399 +
20400 +       if (old_nxi)
20401 +               release_nx_info(old_nxi, p);
20402 +       ret = 0;
20403 +out:
20404 +       put_nx_info(old_nxi);
20405 +       return ret;
20406 +}
20407 +
20408 +
20409 +void nx_set_persistent(struct nx_info *nxi)
20410 +{
20411 +       vxdprintk(VXD_CBIT(nid, 6),
20412 +               "nx_set_persistent(%p[#%d])", nxi, nxi->nx_id);
20413 +
20414 +       get_nx_info(nxi);
20415 +       claim_nx_info(nxi, NULL);
20416 +}
20417 +
20418 +void nx_clear_persistent(struct nx_info *nxi)
20419 +{
20420 +       vxdprintk(VXD_CBIT(nid, 6),
20421 +               "nx_clear_persistent(%p[#%d])", nxi, nxi->nx_id);
20422 +
20423 +       release_nx_info(nxi, NULL);
20424 +       put_nx_info(nxi);
20425 +}
20426 +
20427 +void nx_update_persistent(struct nx_info *nxi)
20428 +{
20429 +       if (nx_info_flags(nxi, NXF_PERSISTENT, 0))
20430 +               nx_set_persistent(nxi);
20431 +       else
20432 +               nx_clear_persistent(nxi);
20433 +}
20434 +
20435 +/* vserver syscall commands below here */
20436 +
20437 +/* taks nid and nx_info functions */
20438 +
20439 +#include <asm/uaccess.h>
20440 +
20441 +
20442 +int vc_task_nid(uint32_t id)
20443 +{
20444 +       nid_t nid;
20445 +
20446 +       if (id) {
20447 +               struct task_struct *tsk;
20448 +
20449 +               rcu_read_lock();
20450 +               tsk = find_task_by_real_pid(id);
20451 +               nid = (tsk) ? tsk->nid : -ESRCH;
20452 +               rcu_read_unlock();
20453 +       } else
20454 +               nid = nx_current_nid();
20455 +       return nid;
20456 +}
20457 +
20458 +
20459 +int vc_nx_info(struct nx_info *nxi, void __user *data)
20460 +{
20461 +       struct vcmd_nx_info_v0 vc_data;
20462 +
20463 +       vc_data.nid = nxi->nx_id;
20464 +
20465 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20466 +               return -EFAULT;
20467 +       return 0;
20468 +}
20469 +
20470 +
20471 +/* network functions */
20472 +
20473 +int vc_net_create(uint32_t nid, void __user *data)
20474 +{
20475 +       struct vcmd_net_create vc_data = { .flagword = NXF_INIT_SET };
20476 +       struct nx_info *new_nxi;
20477 +       int ret;
20478 +
20479 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20480 +               return -EFAULT;
20481 +
20482 +       if ((nid > MAX_S_CONTEXT) || (nid < 2))
20483 +               return -EINVAL;
20484 +
20485 +       new_nxi = __create_nx_info(nid);
20486 +       if (IS_ERR(new_nxi))
20487 +               return PTR_ERR(new_nxi);
20488 +
20489 +       /* initial flags */
20490 +       new_nxi->nx_flags = vc_data.flagword;
20491 +
20492 +       ret = -ENOEXEC;
20493 +       if (vs_net_change(new_nxi, VSC_NETUP))
20494 +               goto out;
20495 +
20496 +       ret = nx_migrate_task(current, new_nxi);
20497 +       if (ret)
20498 +               goto out;
20499 +
20500 +       /* return context id on success */
20501 +       ret = new_nxi->nx_id;
20502 +
20503 +       /* get a reference for persistent contexts */
20504 +       if ((vc_data.flagword & NXF_PERSISTENT))
20505 +               nx_set_persistent(new_nxi);
20506 +out:
20507 +       release_nx_info(new_nxi, NULL);
20508 +       put_nx_info(new_nxi);
20509 +       return ret;
20510 +}
20511 +
20512 +
20513 +int vc_net_migrate(struct nx_info *nxi, void __user *data)
20514 +{
20515 +       return nx_migrate_task(current, nxi);
20516 +}
20517 +
20518 +
20519 +static inline
20520 +struct nx_addr_v4 *__find_v4_addr(struct nx_info *nxi,
20521 +       __be32 ip, __be32 ip2, __be32 mask, uint16_t type, uint16_t flags,
20522 +       struct nx_addr_v4 **prev)
20523 +{
20524 +       struct nx_addr_v4 *nxa = &nxi->v4;
20525 +
20526 +       for (; nxa; nxa = nxa->next) {
20527 +               if ((nxa->ip[0].s_addr == ip) &&
20528 +                   (nxa->ip[1].s_addr == ip2) &&
20529 +                   (nxa->mask.s_addr == mask) &&
20530 +                   (nxa->type == type) &&
20531 +                   (nxa->flags == flags))
20532 +                   return nxa;
20533 +
20534 +               /* save previous entry */
20535 +               if (prev)
20536 +                       *prev = nxa;
20537 +       }
20538 +       return NULL;
20539 +}
20540 +
20541 +int do_add_v4_addr(struct nx_info *nxi, __be32 ip, __be32 ip2, __be32 mask,
20542 +       uint16_t type, uint16_t flags)
20543 +{
20544 +       struct nx_addr_v4 *nxa = NULL;
20545 +       struct nx_addr_v4 *new = __alloc_nx_addr_v4();
20546 +       unsigned long irqflags;
20547 +       int ret = -EEXIST;
20548 +
20549 +       if (IS_ERR(new))
20550 +               return PTR_ERR(new);
20551 +
20552 +       spin_lock_irqsave(&nxi->addr_lock, irqflags);
20553 +       if (__find_v4_addr(nxi, ip, ip2, mask, type, flags, &nxa))
20554 +               goto out_unlock;
20555 +
20556 +       if (NX_IPV4(nxi)) {
20557 +               nxa->next = new;
20558 +               nxa = new;
20559 +               new = NULL;
20560 +
20561 +               /* remove single ip for ip list */
20562 +               nxi->nx_flags &= ~NXF_SINGLE_IP;
20563 +       }
20564 +
20565 +       nxa->ip[0].s_addr = ip;
20566 +       nxa->ip[1].s_addr = ip2;
20567 +       nxa->mask.s_addr = mask;
20568 +       nxa->type = type;
20569 +       nxa->flags = flags;
20570 +       ret = 0;
20571 +out_unlock:
20572 +       spin_unlock_irqrestore(&nxi->addr_lock, irqflags);
20573 +       if (new)
20574 +               __dealloc_nx_addr_v4(new);
20575 +       return ret;
20576 +}
20577 +
20578 +int do_remove_v4_addr(struct nx_info *nxi, __be32 ip, __be32 ip2, __be32 mask,
20579 +       uint16_t type, uint16_t flags)
20580 +{
20581 +       struct nx_addr_v4 *nxa = NULL;
20582 +       struct nx_addr_v4 *old = NULL;
20583 +       unsigned long irqflags;
20584 +       int ret = 0;
20585 +
20586 +       spin_lock_irqsave(&nxi->addr_lock, irqflags);
20587 +       switch (type) {
20588 +       case NXA_TYPE_ADDR:
20589 +               old = __find_v4_addr(nxi, ip, ip2, mask, type, flags, &nxa);
20590 +               if (old) {
20591 +                       if (nxa) {
20592 +                               nxa->next = old->next;
20593 +                               old->next = NULL;
20594 +                       } else {
20595 +                               if (old->next) {
20596 +                                       nxa = old;
20597 +                                       old = old->next;
20598 +                                       *nxa = *old;
20599 +                                       old->next = NULL;
20600 +                               } else {
20601 +                                       memset(old, 0, sizeof(*old));
20602 +                                       old = NULL;
20603 +                               }
20604 +                       }
20605 +               } else
20606 +                       ret = -ESRCH;
20607 +               break;
20608 +
20609 +       case NXA_TYPE_ANY:
20610 +               nxa = &nxi->v4;
20611 +               old = nxa->next;
20612 +               memset(nxa, 0, sizeof(*nxa));
20613 +               break;
20614 +
20615 +       default:
20616 +               ret = -EINVAL;
20617 +       }
20618 +       spin_unlock_irqrestore(&nxi->addr_lock, irqflags);
20619 +       __dealloc_nx_addr_v4_all(old);
20620 +       return ret;
20621 +}
20622 +
20623 +
20624 +int vc_net_add(struct nx_info *nxi, void __user *data)
20625 +{
20626 +       struct vcmd_net_addr_v0 vc_data;
20627 +       int index, ret = 0;
20628 +
20629 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20630 +               return -EFAULT;
20631 +
20632 +       switch (vc_data.type) {
20633 +       case NXA_TYPE_IPV4:
20634 +               if ((vc_data.count < 1) || (vc_data.count > 4))
20635 +                       return -EINVAL;
20636 +
20637 +               index = 0;
20638 +               while (index < vc_data.count) {
20639 +                       ret = do_add_v4_addr(nxi, vc_data.ip[index].s_addr, 0,
20640 +                               vc_data.mask[index].s_addr, NXA_TYPE_ADDR, 0);
20641 +                       if (ret)
20642 +                               return ret;
20643 +                       index++;
20644 +               }
20645 +               ret = index;
20646 +               break;
20647 +
20648 +       case NXA_TYPE_IPV4|NXA_MOD_BCAST:
20649 +               nxi->v4_bcast = vc_data.ip[0];
20650 +               ret = 1;
20651 +               break;
20652 +
20653 +       case NXA_TYPE_IPV4|NXA_MOD_LBACK:
20654 +               nxi->v4_lback = vc_data.ip[0];
20655 +               ret = 1;
20656 +               break;
20657 +
20658 +       default:
20659 +               ret = -EINVAL;
20660 +               break;
20661 +       }
20662 +       return ret;
20663 +}
20664 +
20665 +int vc_net_remove(struct nx_info *nxi, void __user *data)
20666 +{
20667 +       struct vcmd_net_addr_v0 vc_data;
20668 +
20669 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20670 +               return -EFAULT;
20671 +
20672 +       switch (vc_data.type) {
20673 +       case NXA_TYPE_ANY:
20674 +               return do_remove_v4_addr(nxi, 0, 0, 0, vc_data.type, 0);
20675 +       default:
20676 +               return -EINVAL;
20677 +       }
20678 +       return 0;
20679 +}
20680 +
20681 +
20682 +int vc_net_add_ipv4_v1(struct nx_info *nxi, void __user *data)
20683 +{
20684 +       struct vcmd_net_addr_ipv4_v1 vc_data;
20685 +
20686 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20687 +               return -EFAULT;
20688 +
20689 +       switch (vc_data.type) {
20690 +       case NXA_TYPE_ADDR:
20691 +       case NXA_TYPE_MASK:
20692 +               return do_add_v4_addr(nxi, vc_data.ip.s_addr, 0,
20693 +                       vc_data.mask.s_addr, vc_data.type, vc_data.flags);
20694 +
20695 +       case NXA_TYPE_ADDR | NXA_MOD_BCAST:
20696 +               nxi->v4_bcast = vc_data.ip;
20697 +               break;
20698 +
20699 +       case NXA_TYPE_ADDR | NXA_MOD_LBACK:
20700 +               nxi->v4_lback = vc_data.ip;
20701 +               break;
20702 +
20703 +       default:
20704 +               return -EINVAL;
20705 +       }
20706 +       return 0;
20707 +}
20708 +
20709 +int vc_net_add_ipv4(struct nx_info *nxi, void __user *data)
20710 +{
20711 +       struct vcmd_net_addr_ipv4_v2 vc_data;
20712 +
20713 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20714 +               return -EFAULT;
20715 +
20716 +       switch (vc_data.type) {
20717 +       case NXA_TYPE_ADDR:
20718 +       case NXA_TYPE_MASK:
20719 +       case NXA_TYPE_RANGE:
20720 +               return do_add_v4_addr(nxi, vc_data.ip.s_addr, vc_data.ip2.s_addr,
20721 +                       vc_data.mask.s_addr, vc_data.type, vc_data.flags);
20722 +
20723 +       case NXA_TYPE_ADDR | NXA_MOD_BCAST:
20724 +               nxi->v4_bcast = vc_data.ip;
20725 +               break;
20726 +
20727 +       case NXA_TYPE_ADDR | NXA_MOD_LBACK:
20728 +               nxi->v4_lback = vc_data.ip;
20729 +               break;
20730 +
20731 +       default:
20732 +               return -EINVAL;
20733 +       }
20734 +       return 0;
20735 +}
20736 +
20737 +int vc_net_rem_ipv4_v1(struct nx_info *nxi, void __user *data)
20738 +{
20739 +       struct vcmd_net_addr_ipv4_v1 vc_data;
20740 +
20741 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20742 +               return -EFAULT;
20743 +
20744 +       return do_remove_v4_addr(nxi, vc_data.ip.s_addr, 0,
20745 +               vc_data.mask.s_addr, vc_data.type, vc_data.flags);
20746 +}
20747 +
20748 +int vc_net_rem_ipv4(struct nx_info *nxi, void __user *data)
20749 +{
20750 +       struct vcmd_net_addr_ipv4_v2 vc_data;
20751 +
20752 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20753 +               return -EFAULT;
20754 +
20755 +       return do_remove_v4_addr(nxi, vc_data.ip.s_addr, vc_data.ip2.s_addr,
20756 +               vc_data.mask.s_addr, vc_data.type, vc_data.flags);
20757 +}
20758 +
20759 +#ifdef CONFIG_IPV6
20760 +
20761 +static inline
20762 +struct nx_addr_v6 *__find_v6_addr(struct nx_info *nxi,
20763 +       struct in6_addr *ip, struct in6_addr *mask,
20764 +       uint32_t prefix, uint16_t type, uint16_t flags,
20765 +       struct nx_addr_v6 **prev)
20766 +{
20767 +       struct nx_addr_v6 *nxa = &nxi->v6;
20768 +
20769 +       for (; nxa; nxa = nxa->next) {
20770 +               if (ipv6_addr_equal(&nxa->ip, ip) &&
20771 +                   ipv6_addr_equal(&nxa->mask, mask) &&
20772 +                   (nxa->prefix == prefix) &&
20773 +                   (nxa->type == type) &&
20774 +                   (nxa->flags == flags))
20775 +                   return nxa;
20776 +
20777 +               /* save previous entry */
20778 +               if (prev)
20779 +                       *prev = nxa;
20780 +       }
20781 +       return NULL;
20782 +}
20783 +
20784 +
20785 +int do_add_v6_addr(struct nx_info *nxi,
20786 +       struct in6_addr *ip, struct in6_addr *mask,
20787 +       uint32_t prefix, uint16_t type, uint16_t flags)
20788 +{
20789 +       struct nx_addr_v6 *nxa = NULL;
20790 +       struct nx_addr_v6 *new = __alloc_nx_addr_v6();
20791 +       unsigned long irqflags;
20792 +       int ret = -EEXIST;
20793 +
20794 +       if (IS_ERR(new))
20795 +               return PTR_ERR(new);
20796 +
20797 +       spin_lock_irqsave(&nxi->addr_lock, irqflags);
20798 +       if (__find_v6_addr(nxi, ip, mask, prefix, type, flags, &nxa))
20799 +               goto out_unlock;
20800 +
20801 +       if (NX_IPV6(nxi)) {
20802 +               nxa->next = new;
20803 +               nxa = new;
20804 +               new = NULL;
20805 +       }
20806 +
20807 +       nxa->ip = *ip;
20808 +       nxa->mask = *mask;
20809 +       nxa->prefix = prefix;
20810 +       nxa->type = type;
20811 +       nxa->flags = flags;
20812 +       ret = 0;
20813 +out_unlock:
20814 +       spin_unlock_irqrestore(&nxi->addr_lock, irqflags);
20815 +       if (new)
20816 +               __dealloc_nx_addr_v6(new);
20817 +       return ret;
20818 +}
20819 +
20820 +int do_remove_v6_addr(struct nx_info *nxi,
20821 +       struct in6_addr *ip, struct in6_addr *mask,
20822 +       uint32_t prefix, uint16_t type, uint16_t flags)
20823 +{
20824 +       struct nx_addr_v6 *nxa = NULL;
20825 +       struct nx_addr_v6 *old = NULL;
20826 +       unsigned long irqflags;
20827 +       int ret = 0;
20828 +
20829 +       spin_lock_irqsave(&nxi->addr_lock, irqflags);
20830 +       switch (type) {
20831 +       case NXA_TYPE_ADDR:
20832 +               old = __find_v6_addr(nxi, ip, mask, prefix, type, flags, &nxa);
20833 +               if (old) {
20834 +                       if (nxa) {
20835 +                               nxa->next = old->next;
20836 +                               old->next = NULL;
20837 +                       } else {
20838 +                               if (old->next) {
20839 +                                       nxa = old;
20840 +                                       old = old->next;
20841 +                                       *nxa = *old;
20842 +                                       old->next = NULL;
20843 +                               } else {
20844 +                                       memset(old, 0, sizeof(*old));
20845 +                                       old = NULL;
20846 +                               }
20847 +                       }
20848 +               } else
20849 +                       ret = -ESRCH;
20850 +               break;
20851 +
20852 +       case NXA_TYPE_ANY:
20853 +               nxa = &nxi->v6;
20854 +               old = nxa->next;
20855 +               memset(nxa, 0, sizeof(*nxa));
20856 +               break;
20857 +
20858 +       default:
20859 +               ret = -EINVAL;
20860 +       }
20861 +       spin_unlock_irqrestore(&nxi->addr_lock, irqflags);
20862 +       __dealloc_nx_addr_v6_all(old);
20863 +       return ret;
20864 +}
20865 +
20866 +int vc_net_add_ipv6(struct nx_info *nxi, void __user *data)
20867 +{
20868 +       struct vcmd_net_addr_ipv6_v1 vc_data;
20869 +
20870 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20871 +               return -EFAULT;
20872 +
20873 +       switch (vc_data.type) {
20874 +       case NXA_TYPE_ADDR:
20875 +               memset(&vc_data.mask, ~0, sizeof(vc_data.mask));
20876 +               /* fallthrough */
20877 +       case NXA_TYPE_MASK:
20878 +               return do_add_v6_addr(nxi, &vc_data.ip, &vc_data.mask,
20879 +                       vc_data.prefix, vc_data.type, vc_data.flags);
20880 +       default:
20881 +               return -EINVAL;
20882 +       }
20883 +       return 0;
20884 +}
20885 +
20886 +int vc_net_remove_ipv6(struct nx_info *nxi, void __user *data)
20887 +{
20888 +       struct vcmd_net_addr_ipv6_v1 vc_data;
20889 +
20890 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20891 +               return -EFAULT;
20892 +
20893 +       switch (vc_data.type) {
20894 +       case NXA_TYPE_ADDR:
20895 +               memset(&vc_data.mask, ~0, sizeof(vc_data.mask));
20896 +               /* fallthrough */
20897 +       case NXA_TYPE_MASK:
20898 +               return do_remove_v6_addr(nxi, &vc_data.ip, &vc_data.mask,
20899 +                       vc_data.prefix, vc_data.type, vc_data.flags);
20900 +       case NXA_TYPE_ANY:
20901 +               return do_remove_v6_addr(nxi, NULL, NULL, 0, vc_data.type, 0);
20902 +       default:
20903 +               return -EINVAL;
20904 +       }
20905 +       return 0;
20906 +}
20907 +
20908 +#endif /* CONFIG_IPV6 */
20909 +
20910 +
20911 +int vc_get_nflags(struct nx_info *nxi, void __user *data)
20912 +{
20913 +       struct vcmd_net_flags_v0 vc_data;
20914 +
20915 +       vc_data.flagword = nxi->nx_flags;
20916 +
20917 +       /* special STATE flag handling */
20918 +       vc_data.mask = vs_mask_flags(~0ULL, nxi->nx_flags, NXF_ONE_TIME);
20919 +
20920 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20921 +               return -EFAULT;
20922 +       return 0;
20923 +}
20924 +
20925 +int vc_set_nflags(struct nx_info *nxi, void __user *data)
20926 +{
20927 +       struct vcmd_net_flags_v0 vc_data;
20928 +       uint64_t mask, trigger;
20929 +
20930 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20931 +               return -EFAULT;
20932 +
20933 +       /* special STATE flag handling */
20934 +       mask = vs_mask_mask(vc_data.mask, nxi->nx_flags, NXF_ONE_TIME);
20935 +       trigger = (mask & nxi->nx_flags) ^ (mask & vc_data.flagword);
20936 +
20937 +       nxi->nx_flags = vs_mask_flags(nxi->nx_flags,
20938 +               vc_data.flagword, mask);
20939 +       if (trigger & NXF_PERSISTENT)
20940 +               nx_update_persistent(nxi);
20941 +
20942 +       return 0;
20943 +}
20944 +
20945 +int vc_get_ncaps(struct nx_info *nxi, void __user *data)
20946 +{
20947 +       struct vcmd_net_caps_v0 vc_data;
20948 +
20949 +       vc_data.ncaps = nxi->nx_ncaps;
20950 +       vc_data.cmask = ~0ULL;
20951 +
20952 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20953 +               return -EFAULT;
20954 +       return 0;
20955 +}
20956 +
20957 +int vc_set_ncaps(struct nx_info *nxi, void __user *data)
20958 +{
20959 +       struct vcmd_net_caps_v0 vc_data;
20960 +
20961 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20962 +               return -EFAULT;
20963 +
20964 +       nxi->nx_ncaps = vs_mask_flags(nxi->nx_ncaps,
20965 +               vc_data.ncaps, vc_data.cmask);
20966 +       return 0;
20967 +}
20968 +
20969 +
20970 +#include <linux/module.h>
20971 +
20972 +module_init(init_network);
20973 +
20974 +EXPORT_SYMBOL_GPL(free_nx_info);
20975 +EXPORT_SYMBOL_GPL(unhash_nx_info);
20976 +
20977 diff -NurpP --minimal linux-3.9.4/kernel/vserver/proc.c linux-3.9.4-vs2.3.6.2/kernel/vserver/proc.c
20978 --- linux-3.9.4/kernel/vserver/proc.c   1970-01-01 00:00:00.000000000 +0000
20979 +++ linux-3.9.4-vs2.3.6.2/kernel/vserver/proc.c 2013-06-01 08:30:38.000000000 +0000
20980 @@ -0,0 +1,1110 @@
20981 +/*
20982 + *  linux/kernel/vserver/proc.c
20983 + *
20984 + *  Virtual Context Support
20985 + *
20986 + *  Copyright (C) 2003-2011  Herbert Pötzl
20987 + *
20988 + *  V0.01  basic structure
20989 + *  V0.02  adaptation vs1.3.0
20990 + *  V0.03  proc permissions
20991 + *  V0.04  locking/generic
20992 + *  V0.05  next generation procfs
20993 + *  V0.06  inode validation
20994 + *  V0.07  generic rewrite vid
20995 + *  V0.08  remove inode type
20996 + *  V0.09  added u/wmask info
20997 + *
20998 + */
20999 +
21000 +#include <linux/proc_fs.h>
21001 +#include <linux/fs_struct.h>
21002 +#include <linux/mount.h>
21003 +#include <linux/namei.h>
21004 +#include <asm/unistd.h>
21005 +
21006 +#include <linux/vs_context.h>
21007 +#include <linux/vs_network.h>
21008 +#include <linux/vs_cvirt.h>
21009 +
21010 +#include <linux/in.h>
21011 +#include <linux/inetdevice.h>
21012 +#include <linux/vs_inet.h>
21013 +#include <linux/vs_inet6.h>
21014 +
21015 +#include <linux/vserver/global.h>
21016 +
21017 +#include "cvirt_proc.h"
21018 +#include "cacct_proc.h"
21019 +#include "limit_proc.h"
21020 +#include "sched_proc.h"
21021 +#include "vci_config.h"
21022 +
21023 +
21024 +static inline char *print_cap_t(char *buffer, kernel_cap_t *c)
21025 +{
21026 +       unsigned __capi;
21027 +
21028 +       CAP_FOR_EACH_U32(__capi) {
21029 +               buffer += sprintf(buffer, "%08x",
21030 +                       c->cap[(_KERNEL_CAPABILITY_U32S-1) - __capi]);
21031 +       }
21032 +       return buffer;
21033 +}
21034 +
21035 +
21036 +static struct proc_dir_entry *proc_virtual;
21037 +
21038 +static struct proc_dir_entry *proc_virtnet;
21039 +
21040 +
21041 +/* first the actual feeds */
21042 +
21043 +
21044 +static int proc_vci(char *buffer)
21045 +{
21046 +       return sprintf(buffer,
21047 +               "VCIVersion:\t%04x:%04x\n"
21048 +               "VCISyscall:\t%d\n"
21049 +               "VCIKernel:\t%08x\n",
21050 +               VCI_VERSION >> 16,
21051 +               VCI_VERSION & 0xFFFF,
21052 +               __NR_vserver,
21053 +               vci_kernel_config());
21054 +}
21055 +
21056 +static int proc_virtual_info(char *buffer)
21057 +{
21058 +       return proc_vci(buffer);
21059 +}
21060 +
21061 +static int proc_virtual_status(char *buffer)
21062 +{
21063 +       return sprintf(buffer,
21064 +               "#CTotal:\t%d\n"
21065 +               "#CActive:\t%d\n"
21066 +               "#NSProxy:\t%d\t%d %d %d %d %d %d\n"
21067 +               "#InitTask:\t%d\t%d %d\n",
21068 +               atomic_read(&vx_global_ctotal),
21069 +               atomic_read(&vx_global_cactive),
21070 +               atomic_read(&vs_global_nsproxy),
21071 +               atomic_read(&vs_global_fs),
21072 +               atomic_read(&vs_global_mnt_ns),
21073 +               atomic_read(&vs_global_uts_ns),
21074 +               atomic_read(&nr_ipc_ns),
21075 +               atomic_read(&vs_global_user_ns),
21076 +               atomic_read(&vs_global_pid_ns),
21077 +               atomic_read(&init_task.usage),
21078 +               atomic_read(&init_task.nsproxy->count),
21079 +               init_task.fs->users);
21080 +}
21081 +
21082 +
21083 +int proc_vxi_info(struct vx_info *vxi, char *buffer)
21084 +{
21085 +       int length;
21086 +
21087 +       length = sprintf(buffer,
21088 +               "ID:\t%d\n"
21089 +               "Info:\t%p\n"
21090 +               "Init:\t%d\n"
21091 +               "OOM:\t%lld\n",
21092 +               vxi->vx_id,
21093 +               vxi,
21094 +               vxi->vx_initpid,
21095 +               vxi->vx_badness_bias);
21096 +       return length;
21097 +}
21098 +
21099 +int proc_vxi_status(struct vx_info *vxi, char *buffer)
21100 +{
21101 +       char *orig = buffer;
21102 +
21103 +       buffer += sprintf(buffer,
21104 +               "UseCnt:\t%d\n"
21105 +               "Tasks:\t%d\n"
21106 +               "Flags:\t%016llx\n",
21107 +               atomic_read(&vxi->vx_usecnt),
21108 +               atomic_read(&vxi->vx_tasks),
21109 +               (unsigned long long)vxi->vx_flags);
21110 +
21111 +       buffer += sprintf(buffer, "BCaps:\t");
21112 +       buffer = print_cap_t(buffer, &vxi->vx_bcaps);
21113 +       buffer += sprintf(buffer, "\n");
21114 +
21115 +       buffer += sprintf(buffer,
21116 +               "CCaps:\t%016llx\n"
21117 +               "Umask:\t%16llx\n"
21118 +               "Wmask:\t%16llx\n"
21119 +               "Spaces:\t%08lx %08lx\n",
21120 +               (unsigned long long)vxi->vx_ccaps,
21121 +               (unsigned long long)vxi->vx_umask,
21122 +               (unsigned long long)vxi->vx_wmask,
21123 +               vxi->space[0].vx_nsmask, vxi->space[1].vx_nsmask);
21124 +       return buffer - orig;
21125 +}
21126 +
21127 +int proc_vxi_limit(struct vx_info *vxi, char *buffer)
21128 +{
21129 +       return vx_info_proc_limit(&vxi->limit, buffer);
21130 +}
21131 +
21132 +int proc_vxi_sched(struct vx_info *vxi, char *buffer)
21133 +{
21134 +       int cpu, length;
21135 +
21136 +       length = vx_info_proc_sched(&vxi->sched, buffer);
21137 +       for_each_online_cpu(cpu) {
21138 +               length += vx_info_proc_sched_pc(
21139 +                       &vx_per_cpu(vxi, sched_pc, cpu),
21140 +                       buffer + length, cpu);
21141 +       }
21142 +       return length;
21143 +}
21144 +
21145 +int proc_vxi_nsproxy0(struct vx_info *vxi, char *buffer)
21146 +{
21147 +       return vx_info_proc_nsproxy(vxi->space[0].vx_nsproxy, buffer);
21148 +}
21149 +
21150 +int proc_vxi_nsproxy1(struct vx_info *vxi, char *buffer)
21151 +{
21152 +       return vx_info_proc_nsproxy(vxi->space[1].vx_nsproxy, buffer);
21153 +}
21154 +
21155 +int proc_vxi_cvirt(struct vx_info *vxi, char *buffer)
21156 +{
21157 +       int cpu, length;
21158 +
21159 +       vx_update_load(vxi);
21160 +       length = vx_info_proc_cvirt(&vxi->cvirt, buffer);
21161 +       for_each_online_cpu(cpu) {
21162 +               length += vx_info_proc_cvirt_pc(
21163 +                       &vx_per_cpu(vxi, cvirt_pc, cpu),
21164 +                       buffer + length, cpu);
21165 +       }
21166 +       return length;
21167 +}
21168 +
21169 +int proc_vxi_cacct(struct vx_info *vxi, char *buffer)
21170 +{
21171 +       return vx_info_proc_cacct(&vxi->cacct, buffer);
21172 +}
21173 +
21174 +
21175 +static int proc_virtnet_info(char *buffer)
21176 +{
21177 +       return proc_vci(buffer);
21178 +}
21179 +
21180 +static int proc_virtnet_status(char *buffer)
21181 +{
21182 +       return sprintf(buffer,
21183 +               "#CTotal:\t%d\n"
21184 +               "#CActive:\t%d\n",
21185 +               atomic_read(&nx_global_ctotal),
21186 +               atomic_read(&nx_global_cactive));
21187 +}
21188 +
21189 +int proc_nxi_info(struct nx_info *nxi, char *buffer)
21190 +{
21191 +       struct nx_addr_v4 *v4a;
21192 +#ifdef CONFIG_IPV6
21193 +       struct nx_addr_v6 *v6a;
21194 +#endif
21195 +       int length, i;
21196 +
21197 +       length = sprintf(buffer,
21198 +               "ID:\t%d\n"
21199 +               "Info:\t%p\n"
21200 +               "Bcast:\t" NIPQUAD_FMT "\n"
21201 +               "Lback:\t" NIPQUAD_FMT "\n",
21202 +               nxi->nx_id,
21203 +               nxi,
21204 +               NIPQUAD(nxi->v4_bcast.s_addr),
21205 +               NIPQUAD(nxi->v4_lback.s_addr));
21206 +
21207 +       if (!NX_IPV4(nxi))
21208 +               goto skip_v4;
21209 +       for (i = 0, v4a = &nxi->v4; v4a; i++, v4a = v4a->next)
21210 +               length += sprintf(buffer + length, "%d:\t" NXAV4_FMT "\n",
21211 +                       i, NXAV4(v4a));
21212 +skip_v4:
21213 +#ifdef CONFIG_IPV6
21214 +       if (!NX_IPV6(nxi))
21215 +               goto skip_v6;
21216 +       for (i = 0, v6a = &nxi->v6; v6a; i++, v6a = v6a->next)
21217 +               length += sprintf(buffer + length, "%d:\t" NXAV6_FMT "\n",
21218 +                       i, NXAV6(v6a));
21219 +skip_v6:
21220 +#endif
21221 +       return length;
21222 +}
21223 +
21224 +int proc_nxi_status(struct nx_info *nxi, char *buffer)
21225 +{
21226 +       int length;
21227 +
21228 +       length = sprintf(buffer,
21229 +               "UseCnt:\t%d\n"
21230 +               "Tasks:\t%d\n"
21231 +               "Flags:\t%016llx\n"
21232 +               "NCaps:\t%016llx\n",
21233 +               atomic_read(&nxi->nx_usecnt),
21234 +               atomic_read(&nxi->nx_tasks),
21235 +               (unsigned long long)nxi->nx_flags,
21236 +               (unsigned long long)nxi->nx_ncaps);
21237 +       return length;
21238 +}
21239 +
21240 +
21241 +
21242 +/* here the inode helpers */
21243 +
21244 +struct vs_entry {
21245 +       int len;
21246 +       char *name;
21247 +       mode_t mode;
21248 +       struct inode_operations *iop;
21249 +       struct file_operations *fop;
21250 +       union proc_op op;
21251 +};
21252 +
21253 +static struct inode *vs_proc_make_inode(struct super_block *sb, struct vs_entry *p)
21254 +{
21255 +       struct inode *inode = new_inode(sb);
21256 +
21257 +       if (!inode)
21258 +               goto out;
21259 +
21260 +       inode->i_mode = p->mode;
21261 +       if (p->iop)
21262 +               inode->i_op = p->iop;
21263 +       if (p->fop)
21264 +               inode->i_fop = p->fop;
21265 +
21266 +       set_nlink(inode, (p->mode & S_IFDIR) ? 2 : 1);
21267 +       inode->i_flags |= S_IMMUTABLE;
21268 +
21269 +       inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
21270 +
21271 +       i_uid_write(inode, 0);
21272 +       i_gid_write(inode, 0);
21273 +       i_tag_write(inode, 0);
21274 +out:
21275 +       return inode;
21276 +}
21277 +
21278 +static struct dentry *vs_proc_instantiate(struct inode *dir,
21279 +       struct dentry *dentry, int id, void *ptr)
21280 +{
21281 +       struct vs_entry *p = ptr;
21282 +       struct inode *inode = vs_proc_make_inode(dir->i_sb, p);
21283 +       struct dentry *error = ERR_PTR(-EINVAL);
21284 +
21285 +       if (!inode)
21286 +               goto out;
21287 +
21288 +       PROC_I(inode)->op = p->op;
21289 +       PROC_I(inode)->fd = id;
21290 +       d_add(dentry, inode);
21291 +       error = NULL;
21292 +out:
21293 +       return error;
21294 +}
21295 +
21296 +/* Lookups */
21297 +
21298 +typedef struct dentry *instantiate_t(struct inode *, struct dentry *, int, void *);
21299 +
21300 +/*
21301 + * Fill a directory entry.
21302 + *
21303 + * If possible create the dcache entry and derive our inode number and
21304 + * file type from dcache entry.
21305 + *
21306 + * Since all of the proc inode numbers are dynamically generated, the inode
21307 + * numbers do not exist until the inode is cache.  This means creating the
21308 + * the dcache entry in readdir is necessary to keep the inode numbers
21309 + * reported by readdir in sync with the inode numbers reported
21310 + * by stat.
21311 + */
21312 +static int proc_fill_cache(struct file *filp, void *dirent, filldir_t filldir,
21313 +       char *name, int len, instantiate_t instantiate, int id, void *ptr)
21314 +{
21315 +       struct dentry *child, *dir = filp->f_dentry;
21316 +       struct inode *inode;
21317 +       struct qstr qname;
21318 +       ino_t ino = 0;
21319 +       unsigned type = DT_UNKNOWN;
21320 +
21321 +       qname.name = name;
21322 +       qname.len  = len;
21323 +       qname.hash = full_name_hash(name, len);
21324 +
21325 +       child = d_lookup(dir, &qname);
21326 +       if (!child) {
21327 +               struct dentry *new;
21328 +               new = d_alloc(dir, &qname);
21329 +               if (new) {
21330 +                       child = instantiate(dir->d_inode, new, id, ptr);
21331 +                       if (child)
21332 +                               dput(new);
21333 +                       else
21334 +                               child = new;
21335 +               }
21336 +       }
21337 +       if (!child || IS_ERR(child) || !child->d_inode)
21338 +               goto end_instantiate;
21339 +       inode = child->d_inode;
21340 +       if (inode) {
21341 +               ino = inode->i_ino;
21342 +               type = inode->i_mode >> 12;
21343 +       }
21344 +       dput(child);
21345 +end_instantiate:
21346 +       if (!ino)
21347 +               ino = find_inode_number(dir, &qname);
21348 +       if (!ino)
21349 +               ino = 1;
21350 +       return filldir(dirent, name, len, filp->f_pos, ino, type);
21351 +}
21352 +
21353 +
21354 +
21355 +/* get and revalidate vx_info/xid */
21356 +
21357 +static inline
21358 +struct vx_info *get_proc_vx_info(struct inode *inode)
21359 +{
21360 +       return lookup_vx_info(PROC_I(inode)->fd);
21361 +}
21362 +
21363 +static int proc_xid_revalidate(struct dentry *dentry, unsigned int flags)
21364 +{
21365 +       struct inode *inode = dentry->d_inode;
21366 +       xid_t xid = PROC_I(inode)->fd;
21367 +
21368 +       if (flags & LOOKUP_RCU) /* FIXME: can be dropped? */
21369 +               return -ECHILD;
21370 +
21371 +       if (!xid || xid_is_hashed(xid))
21372 +               return 1;
21373 +       d_drop(dentry);
21374 +       return 0;
21375 +}
21376 +
21377 +
21378 +/* get and revalidate nx_info/nid */
21379 +
21380 +static int proc_nid_revalidate(struct dentry *dentry, unsigned int flags)
21381 +{
21382 +       struct inode *inode = dentry->d_inode;
21383 +       nid_t nid = PROC_I(inode)->fd;
21384 +
21385 +       if (flags & LOOKUP_RCU) /* FIXME: can be dropped? */
21386 +               return -ECHILD;
21387 +
21388 +       if (!nid || nid_is_hashed(nid))
21389 +               return 1;
21390 +       d_drop(dentry);
21391 +       return 0;
21392 +}
21393 +
21394 +
21395 +
21396 +#define PROC_BLOCK_SIZE (PAGE_SIZE - 1024)
21397 +
21398 +static ssize_t proc_vs_info_read(struct file *file, char __user *buf,
21399 +                         size_t count, loff_t *ppos)
21400 +{
21401 +       struct inode *inode = file->f_dentry->d_inode;
21402 +       unsigned long page;
21403 +       ssize_t length = 0;
21404 +
21405 +       if (count > PROC_BLOCK_SIZE)
21406 +               count = PROC_BLOCK_SIZE;
21407 +
21408 +       /* fade that out as soon as stable */
21409 +       WARN_ON(PROC_I(inode)->fd);
21410 +
21411 +       if (!(page = __get_free_page(GFP_KERNEL)))
21412 +               return -ENOMEM;
21413 +
21414 +       BUG_ON(!PROC_I(inode)->op.proc_vs_read);
21415 +       length = PROC_I(inode)->op.proc_vs_read((char *)page);
21416 +
21417 +       if (length >= 0)
21418 +               length = simple_read_from_buffer(buf, count, ppos,
21419 +                       (char *)page, length);
21420 +
21421 +       free_page(page);
21422 +       return length;
21423 +}
21424 +
21425 +static ssize_t proc_vx_info_read(struct file *file, char __user *buf,
21426 +                         size_t count, loff_t *ppos)
21427 +{
21428 +       struct inode *inode = file->f_dentry->d_inode;
21429 +       struct vx_info *vxi = NULL;
21430 +       xid_t xid = PROC_I(inode)->fd;
21431 +       unsigned long page;
21432 +       ssize_t length = 0;
21433 +
21434 +       if (count > PROC_BLOCK_SIZE)
21435 +               count = PROC_BLOCK_SIZE;
21436 +
21437 +       /* fade that out as soon as stable */
21438 +       WARN_ON(!xid);
21439 +       vxi = lookup_vx_info(xid);
21440 +       if (!vxi)
21441 +               goto out;
21442 +
21443 +       length = -ENOMEM;
21444 +       if (!(page = __get_free_page(GFP_KERNEL)))
21445 +               goto out_put;
21446 +
21447 +       BUG_ON(!PROC_I(inode)->op.proc_vxi_read);
21448 +       length = PROC_I(inode)->op.proc_vxi_read(vxi, (char *)page);
21449 +
21450 +       if (length >= 0)
21451 +               length = simple_read_from_buffer(buf, count, ppos,
21452 +                       (char *)page, length);
21453 +
21454 +       free_page(page);
21455 +out_put:
21456 +       put_vx_info(vxi);
21457 +out:
21458 +       return length;
21459 +}
21460 +
21461 +static ssize_t proc_nx_info_read(struct file *file, char __user *buf,
21462 +                         size_t count, loff_t *ppos)
21463 +{
21464 +       struct inode *inode = file->f_dentry->d_inode;
21465 +       struct nx_info *nxi = NULL;
21466 +       nid_t nid = PROC_I(inode)->fd;
21467 +       unsigned long page;
21468 +       ssize_t length = 0;
21469 +
21470 +       if (count > PROC_BLOCK_SIZE)
21471 +               count = PROC_BLOCK_SIZE;
21472 +
21473 +       /* fade that out as soon as stable */
21474 +       WARN_ON(!nid);
21475 +       nxi = lookup_nx_info(nid);
21476 +       if (!nxi)
21477 +               goto out;
21478 +
21479 +       length = -ENOMEM;
21480 +       if (!(page = __get_free_page(GFP_KERNEL)))
21481 +               goto out_put;
21482 +
21483 +       BUG_ON(!PROC_I(inode)->op.proc_nxi_read);
21484 +       length = PROC_I(inode)->op.proc_nxi_read(nxi, (char *)page);
21485 +
21486 +       if (length >= 0)
21487 +               length = simple_read_from_buffer(buf, count, ppos,
21488 +                       (char *)page, length);
21489 +
21490 +       free_page(page);
21491 +out_put:
21492 +       put_nx_info(nxi);
21493 +out:
21494 +       return length;
21495 +}
21496 +
21497 +
21498 +
21499 +/* here comes the lower level */
21500 +
21501 +
21502 +#define NOD(NAME, MODE, IOP, FOP, OP) {        \
21503 +       .len  = sizeof(NAME) - 1,       \
21504 +       .name = (NAME),                 \
21505 +       .mode = MODE,                   \
21506 +       .iop  = IOP,                    \
21507 +       .fop  = FOP,                    \
21508 +       .op   = OP,                     \
21509 +}
21510 +
21511 +
21512 +#define DIR(NAME, MODE, OTYPE)                         \
21513 +       NOD(NAME, (S_IFDIR | (MODE)),                   \
21514 +               &proc_ ## OTYPE ## _inode_operations,   \
21515 +               &proc_ ## OTYPE ## _file_operations, { } )
21516 +
21517 +#define INF(NAME, MODE, OTYPE)                         \
21518 +       NOD(NAME, (S_IFREG | (MODE)), NULL,             \
21519 +               &proc_vs_info_file_operations,          \
21520 +               { .proc_vs_read = &proc_##OTYPE } )
21521 +
21522 +#define VINF(NAME, MODE, OTYPE)                                \
21523 +       NOD(NAME, (S_IFREG | (MODE)), NULL,             \
21524 +               &proc_vx_info_file_operations,          \
21525 +               { .proc_vxi_read = &proc_##OTYPE } )
21526 +
21527 +#define NINF(NAME, MODE, OTYPE)                                \
21528 +       NOD(NAME, (S_IFREG | (MODE)), NULL,             \
21529 +               &proc_nx_info_file_operations,          \
21530 +               { .proc_nxi_read = &proc_##OTYPE } )
21531 +
21532 +
21533 +static struct file_operations proc_vs_info_file_operations = {
21534 +       .read =         proc_vs_info_read,
21535 +};
21536 +
21537 +static struct file_operations proc_vx_info_file_operations = {
21538 +       .read =         proc_vx_info_read,
21539 +};
21540 +
21541 +static struct dentry_operations proc_xid_dentry_operations = {
21542 +       .d_revalidate = proc_xid_revalidate,
21543 +};
21544 +
21545 +static struct vs_entry vx_base_stuff[] = {
21546 +       VINF("info",    S_IRUGO, vxi_info),
21547 +       VINF("status",  S_IRUGO, vxi_status),
21548 +       VINF("limit",   S_IRUGO, vxi_limit),
21549 +       VINF("sched",   S_IRUGO, vxi_sched),
21550 +       VINF("nsproxy", S_IRUGO, vxi_nsproxy0),
21551 +       VINF("nsproxy1",S_IRUGO, vxi_nsproxy1),
21552 +       VINF("cvirt",   S_IRUGO, vxi_cvirt),
21553 +       VINF("cacct",   S_IRUGO, vxi_cacct),
21554 +       {}
21555 +};
21556 +
21557 +
21558 +
21559 +
21560 +static struct dentry *proc_xid_instantiate(struct inode *dir,
21561 +       struct dentry *dentry, int id, void *ptr)
21562 +{
21563 +       dentry->d_op = &proc_xid_dentry_operations;
21564 +       return vs_proc_instantiate(dir, dentry, id, ptr);
21565 +}
21566 +
21567 +static struct dentry *proc_xid_lookup(struct inode *dir,
21568 +       struct dentry *dentry, unsigned int flags)
21569 +{
21570 +       struct vs_entry *p = vx_base_stuff;
21571 +       struct dentry *error = ERR_PTR(-ENOENT);
21572 +
21573 +       for (; p->name; p++) {
21574 +               if (p->len != dentry->d_name.len)
21575 +                       continue;
21576 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
21577 +                       break;
21578 +       }
21579 +       if (!p->name)
21580 +               goto out;
21581 +
21582 +       error = proc_xid_instantiate(dir, dentry, PROC_I(dir)->fd, p);
21583 +out:
21584 +       return error;
21585 +}
21586 +
21587 +static int proc_xid_readdir(struct file *filp,
21588 +       void *dirent, filldir_t filldir)
21589 +{
21590 +       struct dentry *dentry = filp->f_dentry;
21591 +       struct inode *inode = dentry->d_inode;
21592 +       struct vs_entry *p = vx_base_stuff;
21593 +       int size = sizeof(vx_base_stuff) / sizeof(struct vs_entry);
21594 +       int pos, index;
21595 +       u64 ino;
21596 +
21597 +       pos = filp->f_pos;
21598 +       switch (pos) {
21599 +       case 0:
21600 +               ino = inode->i_ino;
21601 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
21602 +                       goto out;
21603 +               pos++;
21604 +               /* fall through */
21605 +       case 1:
21606 +               ino = parent_ino(dentry);
21607 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
21608 +                       goto out;
21609 +               pos++;
21610 +               /* fall through */
21611 +       default:
21612 +               index = pos - 2;
21613 +               if (index >= size)
21614 +                       goto out;
21615 +               for (p += index; p->name; p++) {
21616 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
21617 +                               vs_proc_instantiate, PROC_I(inode)->fd, p))
21618 +                               goto out;
21619 +                       pos++;
21620 +               }
21621 +       }
21622 +out:
21623 +       filp->f_pos = pos;
21624 +       return 1;
21625 +}
21626 +
21627 +
21628 +
21629 +static struct file_operations proc_nx_info_file_operations = {
21630 +       .read =         proc_nx_info_read,
21631 +};
21632 +
21633 +static struct dentry_operations proc_nid_dentry_operations = {
21634 +       .d_revalidate = proc_nid_revalidate,
21635 +};
21636 +
21637 +static struct vs_entry nx_base_stuff[] = {
21638 +       NINF("info",    S_IRUGO, nxi_info),
21639 +       NINF("status",  S_IRUGO, nxi_status),
21640 +       {}
21641 +};
21642 +
21643 +
21644 +static struct dentry *proc_nid_instantiate(struct inode *dir,
21645 +       struct dentry *dentry, int id, void *ptr)
21646 +{
21647 +       dentry->d_op = &proc_nid_dentry_operations;
21648 +       return vs_proc_instantiate(dir, dentry, id, ptr);
21649 +}
21650 +
21651 +static struct dentry *proc_nid_lookup(struct inode *dir,
21652 +       struct dentry *dentry, unsigned int flags)
21653 +{
21654 +       struct vs_entry *p = nx_base_stuff;
21655 +       struct dentry *error = ERR_PTR(-ENOENT);
21656 +
21657 +       for (; p->name; p++) {
21658 +               if (p->len != dentry->d_name.len)
21659 +                       continue;
21660 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
21661 +                       break;
21662 +       }
21663 +       if (!p->name)
21664 +               goto out;
21665 +
21666 +       error = proc_nid_instantiate(dir, dentry, PROC_I(dir)->fd, p);
21667 +out:
21668 +       return error;
21669 +}
21670 +
21671 +static int proc_nid_readdir(struct file *filp,
21672 +       void *dirent, filldir_t filldir)
21673 +{
21674 +       struct dentry *dentry = filp->f_dentry;
21675 +       struct inode *inode = dentry->d_inode;
21676 +       struct vs_entry *p = nx_base_stuff;
21677 +       int size = sizeof(nx_base_stuff) / sizeof(struct vs_entry);
21678 +       int pos, index;
21679 +       u64 ino;
21680 +
21681 +       pos = filp->f_pos;
21682 +       switch (pos) {
21683 +       case 0:
21684 +               ino = inode->i_ino;
21685 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
21686 +                       goto out;
21687 +               pos++;
21688 +               /* fall through */
21689 +       case 1:
21690 +               ino = parent_ino(dentry);
21691 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
21692 +                       goto out;
21693 +               pos++;
21694 +               /* fall through */
21695 +       default:
21696 +               index = pos - 2;
21697 +               if (index >= size)
21698 +                       goto out;
21699 +               for (p += index; p->name; p++) {
21700 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
21701 +                               vs_proc_instantiate, PROC_I(inode)->fd, p))
21702 +                               goto out;
21703 +                       pos++;
21704 +               }
21705 +       }
21706 +out:
21707 +       filp->f_pos = pos;
21708 +       return 1;
21709 +}
21710 +
21711 +
21712 +#define MAX_MULBY10    ((~0U - 9) / 10)
21713 +
21714 +static inline int atovid(const char *str, int len)
21715 +{
21716 +       int vid, c;
21717 +
21718 +       vid = 0;
21719 +       while (len-- > 0) {
21720 +               c = *str - '0';
21721 +               str++;
21722 +               if (c > 9)
21723 +                       return -1;
21724 +               if (vid >= MAX_MULBY10)
21725 +                       return -1;
21726 +               vid *= 10;
21727 +               vid += c;
21728 +               if (!vid)
21729 +                       return -1;
21730 +       }
21731 +       return vid;
21732 +}
21733 +
21734 +/* now the upper level (virtual) */
21735 +
21736 +
21737 +static struct file_operations proc_xid_file_operations = {
21738 +       .read =         generic_read_dir,
21739 +       .readdir =      proc_xid_readdir,
21740 +};
21741 +
21742 +static struct inode_operations proc_xid_inode_operations = {
21743 +       .lookup =       proc_xid_lookup,
21744 +};
21745 +
21746 +static struct vs_entry vx_virtual_stuff[] = {
21747 +       INF("info",     S_IRUGO, virtual_info),
21748 +       INF("status",   S_IRUGO, virtual_status),
21749 +       DIR(NULL,       S_IRUGO | S_IXUGO, xid),
21750 +};
21751 +
21752 +
21753 +static struct dentry *proc_virtual_lookup(struct inode *dir,
21754 +       struct dentry *dentry, unsigned int flags)
21755 +{
21756 +       struct vs_entry *p = vx_virtual_stuff;
21757 +       struct dentry *error = ERR_PTR(-ENOENT);
21758 +       int id = 0;
21759 +
21760 +       for (; p->name; p++) {
21761 +               if (p->len != dentry->d_name.len)
21762 +                       continue;
21763 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
21764 +                       break;
21765 +       }
21766 +       if (p->name)
21767 +               goto instantiate;
21768 +
21769 +       id = atovid(dentry->d_name.name, dentry->d_name.len);
21770 +       if ((id < 0) || !xid_is_hashed(id))
21771 +               goto out;
21772 +
21773 +instantiate:
21774 +       error = proc_xid_instantiate(dir, dentry, id, p);
21775 +out:
21776 +       return error;
21777 +}
21778 +
21779 +static struct file_operations proc_nid_file_operations = {
21780 +       .read =         generic_read_dir,
21781 +       .readdir =      proc_nid_readdir,
21782 +};
21783 +
21784 +static struct inode_operations proc_nid_inode_operations = {
21785 +       .lookup =       proc_nid_lookup,
21786 +};
21787 +
21788 +static struct vs_entry nx_virtnet_stuff[] = {
21789 +       INF("info",     S_IRUGO, virtnet_info),
21790 +       INF("status",   S_IRUGO, virtnet_status),
21791 +       DIR(NULL,       S_IRUGO | S_IXUGO, nid),
21792 +};
21793 +
21794 +
21795 +static struct dentry *proc_virtnet_lookup(struct inode *dir,
21796 +       struct dentry *dentry, unsigned int flags)
21797 +{
21798 +       struct vs_entry *p = nx_virtnet_stuff;
21799 +       struct dentry *error = ERR_PTR(-ENOENT);
21800 +       int id = 0;
21801 +
21802 +       for (; p->name; p++) {
21803 +               if (p->len != dentry->d_name.len)
21804 +                       continue;
21805 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
21806 +                       break;
21807 +       }
21808 +       if (p->name)
21809 +               goto instantiate;
21810 +
21811 +       id = atovid(dentry->d_name.name, dentry->d_name.len);
21812 +       if ((id < 0) || !nid_is_hashed(id))
21813 +               goto out;
21814 +
21815 +instantiate:
21816 +       error = proc_nid_instantiate(dir, dentry, id, p);
21817 +out:
21818 +       return error;
21819 +}
21820 +
21821 +
21822 +#define PROC_MAXVIDS 32
21823 +
21824 +int proc_virtual_readdir(struct file *filp,
21825 +       void *dirent, filldir_t filldir)
21826 +{
21827 +       struct dentry *dentry = filp->f_dentry;
21828 +       struct inode *inode = dentry->d_inode;
21829 +       struct vs_entry *p = vx_virtual_stuff;
21830 +       int size = sizeof(vx_virtual_stuff) / sizeof(struct vs_entry);
21831 +       int pos, index;
21832 +       unsigned int xid_array[PROC_MAXVIDS];
21833 +       char buf[PROC_NUMBUF];
21834 +       unsigned int nr_xids, i;
21835 +       u64 ino;
21836 +
21837 +       pos = filp->f_pos;
21838 +       switch (pos) {
21839 +       case 0:
21840 +               ino = inode->i_ino;
21841 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
21842 +                       goto out;
21843 +               pos++;
21844 +               /* fall through */
21845 +       case 1:
21846 +               ino = parent_ino(dentry);
21847 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
21848 +                       goto out;
21849 +               pos++;
21850 +               /* fall through */
21851 +       default:
21852 +               index = pos - 2;
21853 +               if (index >= size)
21854 +                       goto entries;
21855 +               for (p += index; p->name; p++) {
21856 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
21857 +                               vs_proc_instantiate, 0, p))
21858 +                               goto out;
21859 +                       pos++;
21860 +               }
21861 +       entries:
21862 +               index = pos - size;
21863 +               p = &vx_virtual_stuff[size - 1];
21864 +               nr_xids = get_xid_list(index, xid_array, PROC_MAXVIDS);
21865 +               for (i = 0; i < nr_xids; i++) {
21866 +                       int n, xid = xid_array[i];
21867 +                       unsigned int j = PROC_NUMBUF;
21868 +
21869 +                       n = xid;
21870 +                       do
21871 +                               buf[--j] = '0' + (n % 10);
21872 +                       while (n /= 10);
21873 +
21874 +                       if (proc_fill_cache(filp, dirent, filldir,
21875 +                               buf + j, PROC_NUMBUF - j,
21876 +                               vs_proc_instantiate, xid, p))
21877 +                               goto out;
21878 +                       pos++;
21879 +               }
21880 +       }
21881 +out:
21882 +       filp->f_pos = pos;
21883 +       return 0;
21884 +}
21885 +
21886 +static int proc_virtual_getattr(struct vfsmount *mnt,
21887 +       struct dentry *dentry, struct kstat *stat)
21888 +{
21889 +       struct inode *inode = dentry->d_inode;
21890 +
21891 +       generic_fillattr(inode, stat);
21892 +       stat->nlink = 2 + atomic_read(&vx_global_cactive);
21893 +       return 0;
21894 +}
21895 +
21896 +static struct file_operations proc_virtual_dir_operations = {
21897 +       .read =         generic_read_dir,
21898 +       .readdir =      proc_virtual_readdir,
21899 +};
21900 +
21901 +static struct inode_operations proc_virtual_dir_inode_operations = {
21902 +       .getattr =      proc_virtual_getattr,
21903 +       .lookup =       proc_virtual_lookup,
21904 +};
21905 +
21906 +
21907 +
21908 +
21909 +
21910 +int proc_virtnet_readdir(struct file *filp,
21911 +       void *dirent, filldir_t filldir)
21912 +{
21913 +       struct dentry *dentry = filp->f_dentry;
21914 +       struct inode *inode = dentry->d_inode;
21915 +       struct vs_entry *p = nx_virtnet_stuff;
21916 +       int size = sizeof(nx_virtnet_stuff) / sizeof(struct vs_entry);
21917 +       int pos, index;
21918 +       unsigned int nid_array[PROC_MAXVIDS];
21919 +       char buf[PROC_NUMBUF];
21920 +       unsigned int nr_nids, i;
21921 +       u64 ino;
21922 +
21923 +       pos = filp->f_pos;
21924 +       switch (pos) {
21925 +       case 0:
21926 +               ino = inode->i_ino;
21927 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
21928 +                       goto out;
21929 +               pos++;
21930 +               /* fall through */
21931 +       case 1:
21932 +               ino = parent_ino(dentry);
21933 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
21934 +                       goto out;
21935 +               pos++;
21936 +               /* fall through */
21937 +       default:
21938 +               index = pos - 2;
21939 +               if (index >= size)
21940 +                       goto entries;
21941 +               for (p += index; p->name; p++) {
21942 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
21943 +                               vs_proc_instantiate, 0, p))
21944 +                               goto out;
21945 +                       pos++;
21946 +               }
21947 +       entries:
21948 +               index = pos - size;
21949 +               p = &nx_virtnet_stuff[size - 1];
21950 +               nr_nids = get_nid_list(index, nid_array, PROC_MAXVIDS);
21951 +               for (i = 0; i < nr_nids; i++) {
21952 +                       int n, nid = nid_array[i];
21953 +                       unsigned int j = PROC_NUMBUF;
21954 +
21955 +                       n = nid;
21956 +                       do
21957 +                               buf[--j] = '0' + (n % 10);
21958 +                       while (n /= 10);
21959 +
21960 +                       if (proc_fill_cache(filp, dirent, filldir,
21961 +                               buf + j, PROC_NUMBUF - j,
21962 +                               vs_proc_instantiate, nid, p))
21963 +                               goto out;
21964 +                       pos++;
21965 +               }
21966 +       }
21967 +out:
21968 +       filp->f_pos = pos;
21969 +       return 0;
21970 +}
21971 +
21972 +static int proc_virtnet_getattr(struct vfsmount *mnt,
21973 +       struct dentry *dentry, struct kstat *stat)
21974 +{
21975 +       struct inode *inode = dentry->d_inode;
21976 +
21977 +       generic_fillattr(inode, stat);
21978 +       stat->nlink = 2 + atomic_read(&nx_global_cactive);
21979 +       return 0;
21980 +}
21981 +
21982 +static struct file_operations proc_virtnet_dir_operations = {
21983 +       .read =         generic_read_dir,
21984 +       .readdir =      proc_virtnet_readdir,
21985 +};
21986 +
21987 +static struct inode_operations proc_virtnet_dir_inode_operations = {
21988 +       .getattr =      proc_virtnet_getattr,
21989 +       .lookup =       proc_virtnet_lookup,
21990 +};
21991 +
21992 +
21993 +
21994 +void proc_vx_init(void)
21995 +{
21996 +       struct proc_dir_entry *ent;
21997 +
21998 +       ent = proc_mkdir("virtual", 0);
21999 +       if (ent) {
22000 +               ent->proc_fops = &proc_virtual_dir_operations;
22001 +               ent->proc_iops = &proc_virtual_dir_inode_operations;
22002 +       }
22003 +       proc_virtual = ent;
22004 +
22005 +       ent = proc_mkdir("virtnet", 0);
22006 +       if (ent) {
22007 +               ent->proc_fops = &proc_virtnet_dir_operations;
22008 +               ent->proc_iops = &proc_virtnet_dir_inode_operations;
22009 +       }
22010 +       proc_virtnet = ent;
22011 +}
22012 +
22013 +
22014 +
22015 +
22016 +/* per pid info */
22017 +
22018 +
22019 +int proc_pid_vx_info(struct task_struct *p, char *buffer)
22020 +{
22021 +       struct vx_info *vxi;
22022 +       char *orig = buffer;
22023 +
22024 +       buffer += sprintf(buffer, "XID:\t%d\n", vx_task_xid(p));
22025 +
22026 +       vxi = task_get_vx_info(p);
22027 +       if (!vxi)
22028 +               goto out;
22029 +
22030 +       buffer += sprintf(buffer, "BCaps:\t");
22031 +       buffer = print_cap_t(buffer, &vxi->vx_bcaps);
22032 +       buffer += sprintf(buffer, "\n");
22033 +       buffer += sprintf(buffer, "CCaps:\t%016llx\n",
22034 +               (unsigned long long)vxi->vx_ccaps);
22035 +       buffer += sprintf(buffer, "CFlags:\t%016llx\n",
22036 +               (unsigned long long)vxi->vx_flags);
22037 +       buffer += sprintf(buffer, "CIPid:\t%d\n", vxi->vx_initpid);
22038 +
22039 +       put_vx_info(vxi);
22040 +out:
22041 +       return buffer - orig;
22042 +}
22043 +
22044 +
22045 +int proc_pid_nx_info(struct task_struct *p, char *buffer)
22046 +{
22047 +       struct nx_info *nxi;
22048 +       struct nx_addr_v4 *v4a;
22049 +#ifdef CONFIG_IPV6
22050 +       struct nx_addr_v6 *v6a;
22051 +#endif
22052 +       char *orig = buffer;
22053 +       int i;
22054 +
22055 +       buffer += sprintf(buffer, "NID:\t%d\n", nx_task_nid(p));
22056 +
22057 +       nxi = task_get_nx_info(p);
22058 +       if (!nxi)
22059 +               goto out;
22060 +
22061 +       buffer += sprintf(buffer, "NCaps:\t%016llx\n",
22062 +               (unsigned long long)nxi->nx_ncaps);
22063 +       buffer += sprintf(buffer, "NFlags:\t%016llx\n",
22064 +               (unsigned long long)nxi->nx_flags);
22065 +
22066 +       buffer += sprintf(buffer,
22067 +               "V4Root[bcast]:\t" NIPQUAD_FMT "\n",
22068 +               NIPQUAD(nxi->v4_bcast.s_addr));
22069 +       buffer += sprintf (buffer,
22070 +               "V4Root[lback]:\t" NIPQUAD_FMT "\n",
22071 +               NIPQUAD(nxi->v4_lback.s_addr));
22072 +       if (!NX_IPV4(nxi))
22073 +               goto skip_v4;
22074 +       for (i = 0, v4a = &nxi->v4; v4a; i++, v4a = v4a->next)
22075 +               buffer += sprintf(buffer, "V4Root[%d]:\t" NXAV4_FMT "\n",
22076 +                       i, NXAV4(v4a));
22077 +skip_v4:
22078 +#ifdef CONFIG_IPV6
22079 +       if (!NX_IPV6(nxi))
22080 +               goto skip_v6;
22081 +       for (i = 0, v6a = &nxi->v6; v6a; i++, v6a = v6a->next)
22082 +               buffer += sprintf(buffer, "V6Root[%d]:\t" NXAV6_FMT "\n",
22083 +                       i, NXAV6(v6a));
22084 +skip_v6:
22085 +#endif
22086 +       put_nx_info(nxi);
22087 +out:
22088 +       return buffer - orig;
22089 +}
22090 +
22091 diff -NurpP --minimal linux-3.9.4/kernel/vserver/sched.c linux-3.9.4-vs2.3.6.2/kernel/vserver/sched.c
22092 --- linux-3.9.4/kernel/vserver/sched.c  1970-01-01 00:00:00.000000000 +0000
22093 +++ linux-3.9.4-vs2.3.6.2/kernel/vserver/sched.c        2013-05-31 14:47:11.000000000 +0000
22094 @@ -0,0 +1,83 @@
22095 +/*
22096 + *  linux/kernel/vserver/sched.c
22097 + *
22098 + *  Virtual Server: Scheduler Support
22099 + *
22100 + *  Copyright (C) 2004-2010  Herbert Pötzl
22101 + *
22102 + *  V0.01  adapted Sam Vilains version to 2.6.3
22103 + *  V0.02  removed legacy interface
22104 + *  V0.03  changed vcmds to vxi arg
22105 + *  V0.04  removed older and legacy interfaces
22106 + *  V0.05  removed scheduler code/commands
22107 + *
22108 + */
22109 +
22110 +#include <linux/vs_context.h>
22111 +#include <linux/vs_sched.h>
22112 +#include <linux/cpumask.h>
22113 +#include <linux/vserver/sched_cmd.h>
22114 +
22115 +#include <asm/uaccess.h>
22116 +
22117 +
22118 +void vx_update_sched_param(struct _vx_sched *sched,
22119 +       struct _vx_sched_pc *sched_pc)
22120 +{
22121 +       sched_pc->prio_bias = sched->prio_bias;
22122 +}
22123 +
22124 +static int do_set_prio_bias(struct vx_info *vxi, struct vcmd_prio_bias *data)
22125 +{
22126 +       int cpu;
22127 +
22128 +       if (data->prio_bias > MAX_PRIO_BIAS)
22129 +               data->prio_bias = MAX_PRIO_BIAS;
22130 +       if (data->prio_bias < MIN_PRIO_BIAS)
22131 +               data->prio_bias = MIN_PRIO_BIAS;
22132 +
22133 +       if (data->cpu_id != ~0) {
22134 +               vxi->sched.update = cpumask_of_cpu(data->cpu_id);
22135 +               cpumask_and(&vxi->sched.update, &vxi->sched.update,
22136 +                       cpu_online_mask);
22137 +       } else
22138 +               cpumask_copy(&vxi->sched.update, cpu_online_mask);
22139 +
22140 +       for_each_cpu_mask(cpu, vxi->sched.update)
22141 +               vx_update_sched_param(&vxi->sched,
22142 +                       &vx_per_cpu(vxi, sched_pc, cpu));
22143 +       return 0;
22144 +}
22145 +
22146 +int vc_set_prio_bias(struct vx_info *vxi, void __user *data)
22147 +{
22148 +       struct vcmd_prio_bias vc_data;
22149 +
22150 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
22151 +               return -EFAULT;
22152 +
22153 +       return do_set_prio_bias(vxi, &vc_data);
22154 +}
22155 +
22156 +int vc_get_prio_bias(struct vx_info *vxi, void __user *data)
22157 +{
22158 +       struct vcmd_prio_bias vc_data;
22159 +       struct _vx_sched_pc *pcd;
22160 +       int cpu;
22161 +
22162 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
22163 +               return -EFAULT;
22164 +
22165 +       cpu = vc_data.cpu_id;
22166 +
22167 +       if (!cpu_possible(cpu))
22168 +               return -EINVAL;
22169 +
22170 +       pcd = &vx_per_cpu(vxi, sched_pc, cpu);
22171 +       vc_data.prio_bias = pcd->prio_bias;
22172 +
22173 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
22174 +               return -EFAULT;
22175 +       return 0;
22176 +}
22177 +
22178 diff -NurpP --minimal linux-3.9.4/kernel/vserver/sched_init.h linux-3.9.4-vs2.3.6.2/kernel/vserver/sched_init.h
22179 --- linux-3.9.4/kernel/vserver/sched_init.h     1970-01-01 00:00:00.000000000 +0000
22180 +++ linux-3.9.4-vs2.3.6.2/kernel/vserver/sched_init.h   2013-05-31 14:47:11.000000000 +0000
22181 @@ -0,0 +1,27 @@
22182 +
22183 +static inline void vx_info_init_sched(struct _vx_sched *sched)
22184 +{
22185 +       /* scheduling; hard code starting values as constants */
22186 +       sched->prio_bias = 0;
22187 +}
22188 +
22189 +static inline
22190 +void vx_info_init_sched_pc(struct _vx_sched_pc *sched_pc, int cpu)
22191 +{
22192 +       sched_pc->prio_bias = 0;
22193 +
22194 +       sched_pc->user_ticks = 0;
22195 +       sched_pc->sys_ticks = 0;
22196 +       sched_pc->hold_ticks = 0;
22197 +}
22198 +
22199 +static inline void vx_info_exit_sched(struct _vx_sched *sched)
22200 +{
22201 +       return;
22202 +}
22203 +
22204 +static inline
22205 +void vx_info_exit_sched_pc(struct _vx_sched_pc *sched_pc, int cpu)
22206 +{
22207 +       return;
22208 +}
22209 diff -NurpP --minimal linux-3.9.4/kernel/vserver/sched_proc.h linux-3.9.4-vs2.3.6.2/kernel/vserver/sched_proc.h
22210 --- linux-3.9.4/kernel/vserver/sched_proc.h     1970-01-01 00:00:00.000000000 +0000
22211 +++ linux-3.9.4-vs2.3.6.2/kernel/vserver/sched_proc.h   2013-05-31 14:47:11.000000000 +0000
22212 @@ -0,0 +1,32 @@
22213 +#ifndef _VX_SCHED_PROC_H
22214 +#define _VX_SCHED_PROC_H
22215 +
22216 +
22217 +static inline
22218 +int vx_info_proc_sched(struct _vx_sched *sched, char *buffer)
22219 +{
22220 +       int length = 0;
22221 +
22222 +       length += sprintf(buffer,
22223 +               "PrioBias:\t%8d\n",
22224 +               sched->prio_bias);
22225 +       return length;
22226 +}
22227 +
22228 +static inline
22229 +int vx_info_proc_sched_pc(struct _vx_sched_pc *sched_pc,
22230 +       char *buffer, int cpu)
22231 +{
22232 +       int length = 0;
22233 +
22234 +       length += sprintf(buffer + length,
22235 +               "cpu %d: %lld %lld %lld", cpu,
22236 +               (unsigned long long)sched_pc->user_ticks,
22237 +               (unsigned long long)sched_pc->sys_ticks,
22238 +               (unsigned long long)sched_pc->hold_ticks);
22239 +       length += sprintf(buffer + length,
22240 +               " %d\n", sched_pc->prio_bias);
22241 +       return length;
22242 +}
22243 +
22244 +#endif /* _VX_SCHED_PROC_H */
22245 diff -NurpP --minimal linux-3.9.4/kernel/vserver/signal.c linux-3.9.4-vs2.3.6.2/kernel/vserver/signal.c
22246 --- linux-3.9.4/kernel/vserver/signal.c 1970-01-01 00:00:00.000000000 +0000
22247 +++ linux-3.9.4-vs2.3.6.2/kernel/vserver/signal.c       2013-05-31 14:47:11.000000000 +0000
22248 @@ -0,0 +1,134 @@
22249 +/*
22250 + *  linux/kernel/vserver/signal.c
22251 + *
22252 + *  Virtual Server: Signal Support
22253 + *
22254 + *  Copyright (C) 2003-2007  Herbert Pötzl
22255 + *
22256 + *  V0.01  broken out from vcontext V0.05
22257 + *  V0.02  changed vcmds to vxi arg
22258 + *  V0.03  adjusted siginfo for kill
22259 + *
22260 + */
22261 +
22262 +#include <asm/uaccess.h>
22263 +
22264 +#include <linux/vs_context.h>
22265 +#include <linux/vs_pid.h>
22266 +#include <linux/vserver/signal_cmd.h>
22267 +
22268 +
22269 +int vx_info_kill(struct vx_info *vxi, int pid, int sig)
22270 +{
22271 +       int retval, count = 0;
22272 +       struct task_struct *p;
22273 +       struct siginfo *sip = SEND_SIG_PRIV;
22274 +
22275 +       retval = -ESRCH;
22276 +       vxdprintk(VXD_CBIT(misc, 4),
22277 +               "vx_info_kill(%p[#%d],%d,%d)*",
22278 +               vxi, vxi->vx_id, pid, sig);
22279 +       read_lock(&tasklist_lock);
22280 +       switch (pid) {
22281 +       case  0:
22282 +       case -1:
22283 +               for_each_process(p) {
22284 +                       int err = 0;
22285 +
22286 +                       if (vx_task_xid(p) != vxi->vx_id || p->pid <= 1 ||
22287 +                               (pid && vxi->vx_initpid == p->pid))
22288 +                               continue;
22289 +
22290 +                       err = group_send_sig_info(sig, sip, p);
22291 +                       ++count;
22292 +                       if (err != -EPERM)
22293 +                               retval = err;
22294 +               }
22295 +               break;
22296 +
22297 +       case 1:
22298 +               if (vxi->vx_initpid) {
22299 +                       pid = vxi->vx_initpid;
22300 +                       /* for now, only SIGINT to private init ... */
22301 +                       if (!vx_info_flags(vxi, VXF_STATE_ADMIN, 0) &&
22302 +                               /* ... as long as there are tasks left */
22303 +                               (atomic_read(&vxi->vx_tasks) > 1))
22304 +                               sig = SIGINT;
22305 +               }
22306 +               /* fallthrough */
22307 +       default:
22308 +               rcu_read_lock();
22309 +               p = find_task_by_real_pid(pid);
22310 +               rcu_read_unlock();
22311 +               if (p) {
22312 +                       if (vx_task_xid(p) == vxi->vx_id)
22313 +                               retval = group_send_sig_info(sig, sip, p);
22314 +               }
22315 +               break;
22316 +       }
22317 +       read_unlock(&tasklist_lock);
22318 +       vxdprintk(VXD_CBIT(misc, 4),
22319 +               "vx_info_kill(%p[#%d],%d,%d,%ld) = %d",
22320 +               vxi, vxi->vx_id, pid, sig, (long)sip, retval);
22321 +       return retval;
22322 +}
22323 +
22324 +int vc_ctx_kill(struct vx_info *vxi, void __user *data)
22325 +{
22326 +       struct vcmd_ctx_kill_v0 vc_data;
22327 +
22328 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
22329 +               return -EFAULT;
22330 +
22331 +       /* special check to allow guest shutdown */
22332 +       if (!vx_info_flags(vxi, VXF_STATE_ADMIN, 0) &&
22333 +               /* forbid killall pid=0 when init is present */
22334 +               (((vc_data.pid < 1) && vxi->vx_initpid) ||
22335 +               (vc_data.pid > 1)))
22336 +               return -EACCES;
22337 +
22338 +       return vx_info_kill(vxi, vc_data.pid, vc_data.sig);
22339 +}
22340 +
22341 +
22342 +static int __wait_exit(struct vx_info *vxi)
22343 +{
22344 +       DECLARE_WAITQUEUE(wait, current);
22345 +       int ret = 0;
22346 +
22347 +       add_wait_queue(&vxi->vx_wait, &wait);
22348 +       set_current_state(TASK_INTERRUPTIBLE);
22349 +
22350 +wait:
22351 +       if (vx_info_state(vxi,
22352 +               VXS_SHUTDOWN | VXS_HASHED | VXS_HELPER) == VXS_SHUTDOWN)
22353 +               goto out;
22354 +       if (signal_pending(current)) {
22355 +               ret = -ERESTARTSYS;
22356 +               goto out;
22357 +       }
22358 +       schedule();
22359 +       goto wait;
22360 +
22361 +out:
22362 +       set_current_state(TASK_RUNNING);
22363 +       remove_wait_queue(&vxi->vx_wait, &wait);
22364 +       return ret;
22365 +}
22366 +
22367 +
22368 +
22369 +int vc_wait_exit(struct vx_info *vxi, void __user *data)
22370 +{
22371 +       struct vcmd_wait_exit_v0 vc_data;
22372 +       int ret;
22373 +
22374 +       ret = __wait_exit(vxi);
22375 +       vc_data.reboot_cmd = vxi->reboot_cmd;
22376 +       vc_data.exit_code = vxi->exit_code;
22377 +
22378 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
22379 +               ret = -EFAULT;
22380 +       return ret;
22381 +}
22382 +
22383 diff -NurpP --minimal linux-3.9.4/kernel/vserver/space.c linux-3.9.4-vs2.3.6.2/kernel/vserver/space.c
22384 --- linux-3.9.4/kernel/vserver/space.c  1970-01-01 00:00:00.000000000 +0000
22385 +++ linux-3.9.4-vs2.3.6.2/kernel/vserver/space.c        2013-05-31 14:47:11.000000000 +0000
22386 @@ -0,0 +1,436 @@
22387 +/*
22388 + *  linux/kernel/vserver/space.c
22389 + *
22390 + *  Virtual Server: Context Space Support
22391 + *
22392 + *  Copyright (C) 2003-2010  Herbert Pötzl
22393 + *
22394 + *  V0.01  broken out from context.c 0.07
22395 + *  V0.02  added task locking for namespace
22396 + *  V0.03  broken out vx_enter_namespace
22397 + *  V0.04  added *space support and commands
22398 + *  V0.05  added credential support
22399 + *
22400 + */
22401 +
22402 +#include <linux/utsname.h>
22403 +#include <linux/nsproxy.h>
22404 +#include <linux/err.h>
22405 +#include <linux/fs_struct.h>
22406 +#include <linux/cred.h>
22407 +#include <asm/uaccess.h>
22408 +
22409 +#include <linux/vs_context.h>
22410 +#include <linux/vserver/space.h>
22411 +#include <linux/vserver/space_cmd.h>
22412 +
22413 +atomic_t vs_global_nsproxy     = ATOMIC_INIT(0);
22414 +atomic_t vs_global_fs          = ATOMIC_INIT(0);
22415 +atomic_t vs_global_mnt_ns      = ATOMIC_INIT(0);
22416 +atomic_t vs_global_uts_ns      = ATOMIC_INIT(0);
22417 +atomic_t vs_global_user_ns     = ATOMIC_INIT(0);
22418 +atomic_t vs_global_pid_ns      = ATOMIC_INIT(0);
22419 +
22420 +
22421 +/* namespace functions */
22422 +
22423 +#include <linux/mnt_namespace.h>
22424 +#include <linux/user_namespace.h>
22425 +#include <linux/pid_namespace.h>
22426 +#include <linux/ipc_namespace.h>
22427 +#include <net/net_namespace.h>
22428 +#include "../fs/mount.h"
22429 +
22430 +
22431 +static const struct vcmd_space_mask_v1 space_mask_v0 = {
22432 +       .mask = CLONE_FS |
22433 +               CLONE_NEWNS |
22434 +#ifdef CONFIG_UTS_NS
22435 +               CLONE_NEWUTS |
22436 +#endif
22437 +#ifdef CONFIG_IPC_NS
22438 +               CLONE_NEWIPC |
22439 +#endif
22440 +#ifdef CONFIG_USER_NS
22441 +               CLONE_NEWUSER |
22442 +#endif
22443 +               0
22444 +};
22445 +
22446 +static const struct vcmd_space_mask_v1 space_mask = {
22447 +       .mask = CLONE_FS |
22448 +               CLONE_NEWNS |
22449 +#ifdef CONFIG_UTS_NS
22450 +               CLONE_NEWUTS |
22451 +#endif
22452 +#ifdef CONFIG_IPC_NS
22453 +               CLONE_NEWIPC |
22454 +#endif
22455 +#ifdef CONFIG_USER_NS
22456 +               CLONE_NEWUSER |
22457 +#endif
22458 +#ifdef CONFIG_PID_NS
22459 +               CLONE_NEWPID |
22460 +#endif
22461 +#ifdef CONFIG_NET_NS
22462 +               CLONE_NEWNET |
22463 +#endif
22464 +               0
22465 +};
22466 +
22467 +static const struct vcmd_space_mask_v1 default_space_mask = {
22468 +       .mask = CLONE_FS |
22469 +               CLONE_NEWNS |
22470 +#ifdef CONFIG_UTS_NS
22471 +               CLONE_NEWUTS |
22472 +#endif
22473 +#ifdef CONFIG_IPC_NS
22474 +               CLONE_NEWIPC |
22475 +#endif
22476 +#ifdef CONFIG_USER_NS
22477 +               CLONE_NEWUSER |
22478 +#endif
22479 +#ifdef CONFIG_PID_NS
22480 +//             CLONE_NEWPID |
22481 +#endif
22482 +               0
22483 +};
22484 +
22485 +/*
22486 + *     build a new nsproxy mix
22487 + *      assumes that both proxies are 'const'
22488 + *     does not touch nsproxy refcounts
22489 + *     will hold a reference on the result.
22490 + */
22491 +
22492 +struct nsproxy *vs_mix_nsproxy(struct nsproxy *old_nsproxy,
22493 +       struct nsproxy *new_nsproxy, unsigned long mask)
22494 +{
22495 +       struct mnt_namespace *old_ns;
22496 +       struct uts_namespace *old_uts;
22497 +       struct ipc_namespace *old_ipc;
22498 +#ifdef CONFIG_PID_NS
22499 +       struct pid_namespace *old_pid;
22500 +#endif
22501 +#ifdef CONFIG_NET_NS
22502 +       struct net *old_net;
22503 +#endif
22504 +       struct nsproxy *nsproxy;
22505 +
22506 +       nsproxy = copy_nsproxy(old_nsproxy);
22507 +       if (!nsproxy)
22508 +               goto out;
22509 +
22510 +       if (mask & CLONE_NEWNS) {
22511 +               old_ns = nsproxy->mnt_ns;
22512 +               nsproxy->mnt_ns = new_nsproxy->mnt_ns;
22513 +               if (nsproxy->mnt_ns)
22514 +                       get_mnt_ns(nsproxy->mnt_ns);
22515 +       } else
22516 +               old_ns = NULL;
22517 +
22518 +       if (mask & CLONE_NEWUTS) {
22519 +               old_uts = nsproxy->uts_ns;
22520 +               nsproxy->uts_ns = new_nsproxy->uts_ns;
22521 +               if (nsproxy->uts_ns)
22522 +                       get_uts_ns(nsproxy->uts_ns);
22523 +       } else
22524 +               old_uts = NULL;
22525 +
22526 +       if (mask & CLONE_NEWIPC) {
22527 +               old_ipc = nsproxy->ipc_ns;
22528 +               nsproxy->ipc_ns = new_nsproxy->ipc_ns;
22529 +               if (nsproxy->ipc_ns)
22530 +                       get_ipc_ns(nsproxy->ipc_ns);
22531 +       } else
22532 +               old_ipc = NULL;
22533 +
22534 +#ifdef CONFIG_PID_NS
22535 +       if (mask & CLONE_NEWPID) {
22536 +               old_pid = nsproxy->pid_ns;
22537 +               nsproxy->pid_ns = new_nsproxy->pid_ns;
22538 +               if (nsproxy->pid_ns)
22539 +                       get_pid_ns(nsproxy->pid_ns);
22540 +       } else
22541 +               old_pid = NULL;
22542 +#endif
22543 +#ifdef CONFIG_NET_NS
22544 +       if (mask & CLONE_NEWNET) {
22545 +               old_net = nsproxy->net_ns;
22546 +               nsproxy->net_ns = new_nsproxy->net_ns;
22547 +               if (nsproxy->net_ns)
22548 +                       get_net(nsproxy->net_ns);
22549 +       } else
22550 +               old_net = NULL;
22551 +#endif
22552 +       if (old_ns)
22553 +               put_mnt_ns(old_ns);
22554 +       if (old_uts)
22555 +               put_uts_ns(old_uts);
22556 +       if (old_ipc)
22557 +               put_ipc_ns(old_ipc);
22558 +#ifdef CONFIG_PID_NS
22559 +       if (old_pid)
22560 +               put_pid_ns(old_pid);
22561 +#endif
22562 +#ifdef CONFIG_NET_NS
22563 +       if (old_net)
22564 +               put_net(old_net);
22565 +#endif
22566 +out:
22567 +       return nsproxy;
22568 +}
22569 +
22570 +
22571 +/*
22572 + *     merge two nsproxy structs into a new one.
22573 + *     will hold a reference on the result.
22574 + */
22575 +
22576 +static inline
22577 +struct nsproxy *__vs_merge_nsproxy(struct nsproxy *old,
22578 +       struct nsproxy *proxy, unsigned long mask)
22579 +{
22580 +       struct nsproxy null_proxy = { .mnt_ns = NULL };
22581 +
22582 +       if (!proxy)
22583 +               return NULL;
22584 +
22585 +       if (mask) {
22586 +               /* vs_mix_nsproxy returns with reference */
22587 +               return vs_mix_nsproxy(old ? old : &null_proxy,
22588 +                       proxy, mask);
22589 +       }
22590 +       get_nsproxy(proxy);
22591 +       return proxy;
22592 +}
22593 +
22594 +
22595 +int vx_enter_space(struct vx_info *vxi, unsigned long mask, unsigned index)
22596 +{
22597 +       struct nsproxy *proxy, *proxy_cur, *proxy_new;
22598 +       struct fs_struct *fs_cur, *fs = NULL;
22599 +       struct _vx_space *space;
22600 +       int ret, kill = 0;
22601 +
22602 +       vxdprintk(VXD_CBIT(space, 8), "vx_enter_space(%p[#%u],0x%08lx,%d)",
22603 +               vxi, vxi->vx_id, mask, index);
22604 +
22605 +       if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0))
22606 +               return -EACCES;
22607 +
22608 +       if (index >= VX_SPACES)
22609 +               return -EINVAL;
22610 +
22611 +       space = &vxi->space[index];
22612 +
22613 +       if (!mask)
22614 +               mask = space->vx_nsmask;
22615 +
22616 +       if ((mask & space->vx_nsmask) != mask)
22617 +               return -EINVAL;
22618 +
22619 +       if (mask & CLONE_FS) {
22620 +               fs = copy_fs_struct(space->vx_fs);
22621 +               if (!fs)
22622 +                       return -ENOMEM;
22623 +       }
22624 +       proxy = space->vx_nsproxy;
22625 +
22626 +       vxdprintk(VXD_CBIT(space, 9),
22627 +               "vx_enter_space(%p[#%u],0x%08lx,%d) -> (%p,%p)",
22628 +               vxi, vxi->vx_id, mask, index, proxy, fs);
22629 +
22630 +       task_lock(current);
22631 +       fs_cur = current->fs;
22632 +
22633 +       if (mask & CLONE_FS) {
22634 +               spin_lock(&fs_cur->lock);
22635 +               current->fs = fs;
22636 +               kill = !--fs_cur->users;
22637 +               spin_unlock(&fs_cur->lock);
22638 +       }
22639 +
22640 +       proxy_cur = current->nsproxy;
22641 +       get_nsproxy(proxy_cur);
22642 +       task_unlock(current);
22643 +
22644 +       if (kill)
22645 +               free_fs_struct(fs_cur);
22646 +
22647 +       proxy_new = __vs_merge_nsproxy(proxy_cur, proxy, mask);
22648 +       if (IS_ERR(proxy_new)) {
22649 +               ret = PTR_ERR(proxy_new);
22650 +               goto out_put;
22651 +       }
22652 +
22653 +       proxy_new = xchg(&current->nsproxy, proxy_new);
22654 +
22655 +       if (mask & CLONE_NEWUSER) {
22656 +               struct cred *cred;
22657 +
22658 +               vxdprintk(VXD_CBIT(space, 10),
22659 +                       "vx_enter_space(%p[#%u],%p) cred (%p,%p)",
22660 +                       vxi, vxi->vx_id, space->vx_cred,
22661 +                       current->real_cred, current->cred);
22662 +
22663 +               if (space->vx_cred) {
22664 +                       cred = __prepare_creds(space->vx_cred);
22665 +                       if (cred)
22666 +                               commit_creds(cred);
22667 +               }
22668 +       }
22669 +
22670 +       ret = 0;
22671 +
22672 +       if (proxy_new)
22673 +               put_nsproxy(proxy_new);
22674 +out_put:
22675 +       if (proxy_cur)
22676 +               put_nsproxy(proxy_cur);
22677 +       return ret;
22678 +}
22679 +
22680 +
22681 +int vx_set_space(struct vx_info *vxi, unsigned long mask, unsigned index)
22682 +{
22683 +       struct nsproxy *proxy_vxi, *proxy_cur, *proxy_new;
22684 +       struct fs_struct *fs_vxi, *fs = NULL;
22685 +       struct _vx_space *space;
22686 +       int ret, kill = 0;
22687 +
22688 +       vxdprintk(VXD_CBIT(space, 8), "vx_set_space(%p[#%u],0x%08lx,%d)",
22689 +               vxi, vxi->vx_id, mask, index);
22690 +
22691 +       if ((mask & space_mask.mask) != mask)
22692 +               return -EINVAL;
22693 +
22694 +       if (index >= VX_SPACES)
22695 +               return -EINVAL;
22696 +
22697 +       space = &vxi->space[index];
22698 +
22699 +       proxy_vxi = space->vx_nsproxy;
22700 +       fs_vxi = space->vx_fs;
22701 +
22702 +       if (mask & CLONE_FS) {
22703 +               fs = copy_fs_struct(current->fs);
22704 +               if (!fs)
22705 +                       return -ENOMEM;
22706 +       }
22707 +
22708 +       task_lock(current);
22709 +
22710 +       if (mask & CLONE_FS) {
22711 +               spin_lock(&fs_vxi->lock);
22712 +               space->vx_fs = fs;
22713 +               kill = !--fs_vxi->users;
22714 +               spin_unlock(&fs_vxi->lock);
22715 +       }
22716 +
22717 +       proxy_cur = current->nsproxy;
22718 +       get_nsproxy(proxy_cur);
22719 +       task_unlock(current);
22720 +
22721 +       if (kill)
22722 +               free_fs_struct(fs_vxi);
22723 +
22724 +       proxy_new = __vs_merge_nsproxy(proxy_vxi, proxy_cur, mask);
22725 +       if (IS_ERR(proxy_new)) {
22726 +               ret = PTR_ERR(proxy_new);
22727 +               goto out_put;
22728 +       }
22729 +
22730 +       proxy_new = xchg(&space->vx_nsproxy, proxy_new);
22731 +       space->vx_nsmask |= mask;
22732 +
22733 +       if (mask & CLONE_NEWUSER) {
22734 +               struct cred *cred;
22735 +
22736 +               vxdprintk(VXD_CBIT(space, 10),
22737 +                       "vx_set_space(%p[#%u],%p) cred (%p,%p)",
22738 +                       vxi, vxi->vx_id, space->vx_cred,
22739 +                       current->real_cred, current->cred);
22740 +
22741 +               cred = prepare_creds();
22742 +               cred = (struct cred *)xchg(&space->vx_cred, cred);
22743 +               if (cred)
22744 +                       abort_creds(cred);
22745 +       }
22746 +
22747 +       ret = 0;
22748 +
22749 +       if (proxy_new)
22750 +               put_nsproxy(proxy_new);
22751 +out_put:
22752 +       if (proxy_cur)
22753 +               put_nsproxy(proxy_cur);
22754 +       return ret;
22755 +}
22756 +
22757 +
22758 +int vc_enter_space_v1(struct vx_info *vxi, void __user *data)
22759 +{
22760 +       struct vcmd_space_mask_v1 vc_data = { .mask = 0 };
22761 +
22762 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22763 +               return -EFAULT;
22764 +
22765 +       return vx_enter_space(vxi, vc_data.mask, 0);
22766 +}
22767 +
22768 +int vc_enter_space(struct vx_info *vxi, void __user *data)
22769 +{
22770 +       struct vcmd_space_mask_v2 vc_data = { .mask = 0 };
22771 +
22772 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22773 +               return -EFAULT;
22774 +
22775 +       if (vc_data.index >= VX_SPACES)
22776 +               return -EINVAL;
22777 +
22778 +       return vx_enter_space(vxi, vc_data.mask, vc_data.index);
22779 +}
22780 +
22781 +int vc_set_space_v1(struct vx_info *vxi, void __user *data)
22782 +{
22783 +       struct vcmd_space_mask_v1 vc_data = { .mask = 0 };
22784 +
22785 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22786 +               return -EFAULT;
22787 +
22788 +       return vx_set_space(vxi, vc_data.mask, 0);
22789 +}
22790 +
22791 +int vc_set_space(struct vx_info *vxi, void __user *data)
22792 +{
22793 +       struct vcmd_space_mask_v2 vc_data = { .mask = 0 };
22794 +
22795 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22796 +               return -EFAULT;
22797 +
22798 +       if (vc_data.index >= VX_SPACES)
22799 +               return -EINVAL;
22800 +
22801 +       return vx_set_space(vxi, vc_data.mask, vc_data.index);
22802 +}
22803 +
22804 +int vc_get_space_mask(void __user *data, int type)
22805 +{
22806 +       const struct vcmd_space_mask_v1 *mask;
22807 +
22808 +       if (type == 0)
22809 +               mask = &space_mask_v0;
22810 +       else if (type == 1)
22811 +               mask = &space_mask;
22812 +       else
22813 +               mask = &default_space_mask;
22814 +
22815 +       vxdprintk(VXD_CBIT(space, 10),
22816 +               "vc_get_space_mask(%d) = %08llx", type, mask->mask);
22817 +
22818 +       if (copy_to_user(data, mask, sizeof(*mask)))
22819 +               return -EFAULT;
22820 +       return 0;
22821 +}
22822 +
22823 diff -NurpP --minimal linux-3.9.4/kernel/vserver/switch.c linux-3.9.4-vs2.3.6.2/kernel/vserver/switch.c
22824 --- linux-3.9.4/kernel/vserver/switch.c 1970-01-01 00:00:00.000000000 +0000
22825 +++ linux-3.9.4-vs2.3.6.2/kernel/vserver/switch.c       2013-05-31 14:47:11.000000000 +0000
22826 @@ -0,0 +1,556 @@
22827 +/*
22828 + *  linux/kernel/vserver/switch.c
22829 + *
22830 + *  Virtual Server: Syscall Switch
22831 + *
22832 + *  Copyright (C) 2003-2011  Herbert Pötzl
22833 + *
22834 + *  V0.01  syscall switch
22835 + *  V0.02  added signal to context
22836 + *  V0.03  added rlimit functions
22837 + *  V0.04  added iattr, task/xid functions
22838 + *  V0.05  added debug/history stuff
22839 + *  V0.06  added compat32 layer
22840 + *  V0.07  vcmd args and perms
22841 + *  V0.08  added status commands
22842 + *  V0.09  added tag commands
22843 + *  V0.10  added oom bias
22844 + *  V0.11  added device commands
22845 + *  V0.12  added warn mask
22846 + *
22847 + */
22848 +
22849 +#include <linux/vs_context.h>
22850 +#include <linux/vs_network.h>
22851 +#include <linux/vserver/switch.h>
22852 +
22853 +#include "vci_config.h"
22854 +
22855 +
22856 +static inline
22857 +int vc_get_version(uint32_t id)
22858 +{
22859 +       return VCI_VERSION;
22860 +}
22861 +
22862 +static inline
22863 +int vc_get_vci(uint32_t id)
22864 +{
22865 +       return vci_kernel_config();
22866 +}
22867 +
22868 +#include <linux/vserver/context_cmd.h>
22869 +#include <linux/vserver/cvirt_cmd.h>
22870 +#include <linux/vserver/cacct_cmd.h>
22871 +#include <linux/vserver/limit_cmd.h>
22872 +#include <linux/vserver/network_cmd.h>
22873 +#include <linux/vserver/sched_cmd.h>
22874 +#include <linux/vserver/debug_cmd.h>
22875 +#include <linux/vserver/inode_cmd.h>
22876 +#include <linux/vserver/dlimit_cmd.h>
22877 +#include <linux/vserver/signal_cmd.h>
22878 +#include <linux/vserver/space_cmd.h>
22879 +#include <linux/vserver/tag_cmd.h>
22880 +#include <linux/vserver/device_cmd.h>
22881 +
22882 +#include <linux/vserver/inode.h>
22883 +#include <linux/vserver/dlimit.h>
22884 +
22885 +
22886 +#ifdef CONFIG_COMPAT
22887 +#define __COMPAT(name, id, data, compat)       \
22888 +       (compat) ? name ## _x32(id, data) : name(id, data)
22889 +#define __COMPAT_NO_ID(name, data, compat)     \
22890 +       (compat) ? name ## _x32(data) : name(data)
22891 +#else
22892 +#define __COMPAT(name, id, data, compat)       \
22893 +       name(id, data)
22894 +#define __COMPAT_NO_ID(name, data, compat)     \
22895 +       name(data)
22896 +#endif
22897 +
22898 +
22899 +static inline
22900 +long do_vcmd(uint32_t cmd, uint32_t id,
22901 +       struct vx_info *vxi, struct nx_info *nxi,
22902 +       void __user *data, int compat)
22903 +{
22904 +       switch (cmd) {
22905 +
22906 +       case VCMD_get_version:
22907 +               return vc_get_version(id);
22908 +       case VCMD_get_vci:
22909 +               return vc_get_vci(id);
22910 +
22911 +       case VCMD_task_xid:
22912 +               return vc_task_xid(id);
22913 +       case VCMD_vx_info:
22914 +               return vc_vx_info(vxi, data);
22915 +
22916 +       case VCMD_task_nid:
22917 +               return vc_task_nid(id);
22918 +       case VCMD_nx_info:
22919 +               return vc_nx_info(nxi, data);
22920 +
22921 +       case VCMD_task_tag:
22922 +               return vc_task_tag(id);
22923 +
22924 +       case VCMD_set_space_v1:
22925 +               return vc_set_space_v1(vxi, data);
22926 +       /* this is version 2 */
22927 +       case VCMD_set_space:
22928 +               return vc_set_space(vxi, data);
22929 +
22930 +       case VCMD_get_space_mask_v0:
22931 +               return vc_get_space_mask(data, 0);
22932 +       /* this is version 1 */
22933 +       case VCMD_get_space_mask:
22934 +               return vc_get_space_mask(data, 1);
22935 +
22936 +       case VCMD_get_space_default:
22937 +               return vc_get_space_mask(data, -1);
22938 +
22939 +       case VCMD_set_umask:
22940 +               return vc_set_umask(vxi, data);
22941 +
22942 +       case VCMD_get_umask:
22943 +               return vc_get_umask(vxi, data);
22944 +
22945 +       case VCMD_set_wmask:
22946 +               return vc_set_wmask(vxi, data);
22947 +
22948 +       case VCMD_get_wmask:
22949 +               return vc_get_wmask(vxi, data);
22950 +#ifdef CONFIG_IA32_EMULATION
22951 +       case VCMD_get_rlimit:
22952 +               return __COMPAT(vc_get_rlimit, vxi, data, compat);
22953 +       case VCMD_set_rlimit:
22954 +               return __COMPAT(vc_set_rlimit, vxi, data, compat);
22955 +#else
22956 +       case VCMD_get_rlimit:
22957 +               return vc_get_rlimit(vxi, data);
22958 +       case VCMD_set_rlimit:
22959 +               return vc_set_rlimit(vxi, data);
22960 +#endif
22961 +       case VCMD_get_rlimit_mask:
22962 +               return vc_get_rlimit_mask(id, data);
22963 +       case VCMD_reset_hits:
22964 +               return vc_reset_hits(vxi, data);
22965 +       case VCMD_reset_minmax:
22966 +               return vc_reset_minmax(vxi, data);
22967 +
22968 +       case VCMD_get_vhi_name:
22969 +               return vc_get_vhi_name(vxi, data);
22970 +       case VCMD_set_vhi_name:
22971 +               return vc_set_vhi_name(vxi, data);
22972 +
22973 +       case VCMD_ctx_stat:
22974 +               return vc_ctx_stat(vxi, data);
22975 +       case VCMD_virt_stat:
22976 +               return vc_virt_stat(vxi, data);
22977 +       case VCMD_sock_stat:
22978 +               return vc_sock_stat(vxi, data);
22979 +       case VCMD_rlimit_stat:
22980 +               return vc_rlimit_stat(vxi, data);
22981 +
22982 +       case VCMD_set_cflags:
22983 +               return vc_set_cflags(vxi, data);
22984 +       case VCMD_get_cflags:
22985 +               return vc_get_cflags(vxi, data);
22986 +
22987 +       /* this is version 1 */
22988 +       case VCMD_set_ccaps:
22989 +               return vc_set_ccaps(vxi, data);
22990 +       /* this is version 1 */
22991 +       case VCMD_get_ccaps:
22992 +               return vc_get_ccaps(vxi, data);
22993 +       case VCMD_set_bcaps:
22994 +               return vc_set_bcaps(vxi, data);
22995 +       case VCMD_get_bcaps:
22996 +               return vc_get_bcaps(vxi, data);
22997 +
22998 +       case VCMD_set_badness:
22999 +               return vc_set_badness(vxi, data);
23000 +       case VCMD_get_badness:
23001 +               return vc_get_badness(vxi, data);
23002 +
23003 +       case VCMD_set_nflags:
23004 +               return vc_set_nflags(nxi, data);
23005 +       case VCMD_get_nflags:
23006 +               return vc_get_nflags(nxi, data);
23007 +
23008 +       case VCMD_set_ncaps:
23009 +               return vc_set_ncaps(nxi, data);
23010 +       case VCMD_get_ncaps:
23011 +               return vc_get_ncaps(nxi, data);
23012 +
23013 +       case VCMD_set_prio_bias:
23014 +               return vc_set_prio_bias(vxi, data);
23015 +       case VCMD_get_prio_bias:
23016 +               return vc_get_prio_bias(vxi, data);
23017 +       case VCMD_add_dlimit:
23018 +               return __COMPAT(vc_add_dlimit, id, data, compat);
23019 +       case VCMD_rem_dlimit:
23020 +               return __COMPAT(vc_rem_dlimit, id, data, compat);
23021 +       case VCMD_set_dlimit:
23022 +               return __COMPAT(vc_set_dlimit, id, data, compat);
23023 +       case VCMD_get_dlimit:
23024 +               return __COMPAT(vc_get_dlimit, id, data, compat);
23025 +
23026 +       case VCMD_ctx_kill:
23027 +               return vc_ctx_kill(vxi, data);
23028 +
23029 +       case VCMD_wait_exit:
23030 +               return vc_wait_exit(vxi, data);
23031 +
23032 +       case VCMD_get_iattr:
23033 +               return __COMPAT_NO_ID(vc_get_iattr, data, compat);
23034 +       case VCMD_set_iattr:
23035 +               return __COMPAT_NO_ID(vc_set_iattr, data, compat);
23036 +
23037 +       case VCMD_fget_iattr:
23038 +               return vc_fget_iattr(id, data);
23039 +       case VCMD_fset_iattr:
23040 +               return vc_fset_iattr(id, data);
23041 +
23042 +       case VCMD_enter_space_v0:
23043 +               return vc_enter_space_v1(vxi, NULL);
23044 +       case VCMD_enter_space_v1:
23045 +               return vc_enter_space_v1(vxi, data);
23046 +       /* this is version 2 */
23047 +       case VCMD_enter_space:
23048 +               return vc_enter_space(vxi, data);
23049 +
23050 +       case VCMD_ctx_create_v0:
23051 +               return vc_ctx_create(id, NULL);
23052 +       case VCMD_ctx_create:
23053 +               return vc_ctx_create(id, data);
23054 +       case VCMD_ctx_migrate_v0:
23055 +               return vc_ctx_migrate(vxi, NULL);
23056 +       case VCMD_ctx_migrate:
23057 +               return vc_ctx_migrate(vxi, data);
23058 +
23059 +       case VCMD_net_create_v0:
23060 +               return vc_net_create(id, NULL);
23061 +       case VCMD_net_create:
23062 +               return vc_net_create(id, data);
23063 +       case VCMD_net_migrate:
23064 +               return vc_net_migrate(nxi, data);
23065 +
23066 +       case VCMD_tag_migrate:
23067 +               return vc_tag_migrate(id);
23068 +
23069 +       case VCMD_net_add:
23070 +               return vc_net_add(nxi, data);
23071 +       case VCMD_net_remove:
23072 +               return vc_net_remove(nxi, data);
23073 +
23074 +       case VCMD_net_add_ipv4_v1:
23075 +               return vc_net_add_ipv4_v1(nxi, data);
23076 +       /* this is version 2 */
23077 +       case VCMD_net_add_ipv4:
23078 +               return vc_net_add_ipv4(nxi, data);
23079 +
23080 +       case VCMD_net_rem_ipv4_v1:
23081 +               return vc_net_rem_ipv4_v1(nxi, data);
23082 +       /* this is version 2 */
23083 +       case VCMD_net_rem_ipv4:
23084 +               return vc_net_rem_ipv4(nxi, data);
23085 +#ifdef CONFIG_IPV6
23086 +       case VCMD_net_add_ipv6:
23087 +               return vc_net_add_ipv6(nxi, data);
23088 +       case VCMD_net_remove_ipv6:
23089 +               return vc_net_remove_ipv6(nxi, data);
23090 +#endif
23091 +/*     case VCMD_add_match_ipv4:
23092 +               return vc_add_match_ipv4(nxi, data);
23093 +       case VCMD_get_match_ipv4:
23094 +               return vc_get_match_ipv4(nxi, data);
23095 +#ifdef CONFIG_IPV6
23096 +       case VCMD_add_match_ipv6:
23097 +               return vc_add_match_ipv6(nxi, data);
23098 +       case VCMD_get_match_ipv6:
23099 +               return vc_get_match_ipv6(nxi, data);
23100 +#endif */
23101 +
23102 +#ifdef CONFIG_VSERVER_DEVICE
23103 +       case VCMD_set_mapping:
23104 +               return __COMPAT(vc_set_mapping, vxi, data, compat);
23105 +       case VCMD_unset_mapping:
23106 +               return __COMPAT(vc_unset_mapping, vxi, data, compat);
23107 +#endif
23108 +#ifdef CONFIG_VSERVER_HISTORY
23109 +       case VCMD_dump_history:
23110 +               return vc_dump_history(id);
23111 +       case VCMD_read_history:
23112 +               return __COMPAT(vc_read_history, id, data, compat);
23113 +#endif
23114 +       default:
23115 +               vxwprintk_task(1, "unimplemented VCMD_%02d_%d[%d]",
23116 +                       VC_CATEGORY(cmd), VC_COMMAND(cmd), VC_VERSION(cmd));
23117 +       }
23118 +       return -ENOSYS;
23119 +}
23120 +
23121 +
23122 +#define        __VCMD(vcmd, _perm, _args, _flags)              \
23123 +       case VCMD_ ## vcmd: perm = _perm;               \
23124 +               args = _args; flags = _flags; break
23125 +
23126 +
23127 +#define VCA_NONE       0x00
23128 +#define VCA_VXI                0x01
23129 +#define VCA_NXI                0x02
23130 +
23131 +#define VCF_NONE       0x00
23132 +#define VCF_INFO       0x01
23133 +#define VCF_ADMIN      0x02
23134 +#define VCF_ARES       0x06    /* includes admin */
23135 +#define VCF_SETUP      0x08
23136 +
23137 +#define VCF_ZIDOK      0x10    /* zero id okay */
23138 +
23139 +
23140 +static inline
23141 +long do_vserver(uint32_t cmd, uint32_t id, void __user *data, int compat)
23142 +{
23143 +       long ret;
23144 +       int permit = -1, state = 0;
23145 +       int perm = -1, args = 0, flags = 0;
23146 +       struct vx_info *vxi = NULL;
23147 +       struct nx_info *nxi = NULL;
23148 +
23149 +       switch (cmd) {
23150 +       /* unpriviledged commands */
23151 +       __VCMD(get_version,      0, VCA_NONE,   0);
23152 +       __VCMD(get_vci,          0, VCA_NONE,   0);
23153 +       __VCMD(get_rlimit_mask,  0, VCA_NONE,   0);
23154 +       __VCMD(get_space_mask_v0,0, VCA_NONE,   0);
23155 +       __VCMD(get_space_mask,   0, VCA_NONE,   0);
23156 +       __VCMD(get_space_default,0, VCA_NONE,   0);
23157 +
23158 +       /* info commands */
23159 +       __VCMD(task_xid,         2, VCA_NONE,   0);
23160 +       __VCMD(reset_hits,       2, VCA_VXI,    0);
23161 +       __VCMD(reset_minmax,     2, VCA_VXI,    0);
23162 +       __VCMD(vx_info,          3, VCA_VXI,    VCF_INFO);
23163 +       __VCMD(get_bcaps,        3, VCA_VXI,    VCF_INFO);
23164 +       __VCMD(get_ccaps,        3, VCA_VXI,    VCF_INFO);
23165 +       __VCMD(get_cflags,       3, VCA_VXI,    VCF_INFO);
23166 +       __VCMD(get_umask,        3, VCA_VXI,    VCF_INFO);
23167 +       __VCMD(get_wmask,        3, VCA_VXI,    VCF_INFO);
23168 +       __VCMD(get_badness,      3, VCA_VXI,    VCF_INFO);
23169 +       __VCMD(get_vhi_name,     3, VCA_VXI,    VCF_INFO);
23170 +       __VCMD(get_rlimit,       3, VCA_VXI,    VCF_INFO);
23171 +
23172 +       __VCMD(ctx_stat,         3, VCA_VXI,    VCF_INFO);
23173 +       __VCMD(virt_stat,        3, VCA_VXI,    VCF_INFO);
23174 +       __VCMD(sock_stat,        3, VCA_VXI,    VCF_INFO);
23175 +       __VCMD(rlimit_stat,      3, VCA_VXI,    VCF_INFO);
23176 +
23177 +       __VCMD(task_nid,         2, VCA_NONE,   0);
23178 +       __VCMD(nx_info,          3, VCA_NXI,    VCF_INFO);
23179 +       __VCMD(get_ncaps,        3, VCA_NXI,    VCF_INFO);
23180 +       __VCMD(get_nflags,       3, VCA_NXI,    VCF_INFO);
23181 +
23182 +       __VCMD(task_tag,         2, VCA_NONE,   0);
23183 +
23184 +       __VCMD(get_iattr,        2, VCA_NONE,   0);
23185 +       __VCMD(fget_iattr,       2, VCA_NONE,   0);
23186 +       __VCMD(get_dlimit,       3, VCA_NONE,   VCF_INFO);
23187 +       __VCMD(get_prio_bias,    3, VCA_VXI,    VCF_INFO);
23188 +
23189 +       /* lower admin commands */
23190 +       __VCMD(wait_exit,        4, VCA_VXI,    VCF_INFO);
23191 +       __VCMD(ctx_create_v0,    5, VCA_NONE,   0);
23192 +       __VCMD(ctx_create,       5, VCA_NONE,   0);
23193 +       __VCMD(ctx_migrate_v0,   5, VCA_VXI,    VCF_ADMIN);
23194 +       __VCMD(ctx_migrate,      5, VCA_VXI,    VCF_ADMIN);
23195 +       __VCMD(enter_space_v0,   5, VCA_VXI,    VCF_ADMIN);
23196 +       __VCMD(enter_space_v1,   5, VCA_VXI,    VCF_ADMIN);
23197 +       __VCMD(enter_space,      5, VCA_VXI,    VCF_ADMIN);
23198 +
23199 +       __VCMD(net_create_v0,    5, VCA_NONE,   0);
23200 +       __VCMD(net_create,       5, VCA_NONE,   0);
23201 +       __VCMD(net_migrate,      5, VCA_NXI,    VCF_ADMIN);
23202 +
23203 +       __VCMD(tag_migrate,      5, VCA_NONE,   VCF_ADMIN);
23204 +
23205 +       /* higher admin commands */
23206 +       __VCMD(ctx_kill,         6, VCA_VXI,    VCF_ARES);
23207 +       __VCMD(set_space_v1,     7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23208 +       __VCMD(set_space,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23209 +
23210 +       __VCMD(set_ccaps,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23211 +       __VCMD(set_bcaps,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23212 +       __VCMD(set_cflags,       7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23213 +       __VCMD(set_umask,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23214 +       __VCMD(set_wmask,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23215 +       __VCMD(set_badness,      7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23216 +
23217 +       __VCMD(set_vhi_name,     7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23218 +       __VCMD(set_rlimit,       7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23219 +       __VCMD(set_prio_bias,    7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23220 +
23221 +       __VCMD(set_ncaps,        7, VCA_NXI,    VCF_ARES | VCF_SETUP);
23222 +       __VCMD(set_nflags,       7, VCA_NXI,    VCF_ARES | VCF_SETUP);
23223 +       __VCMD(net_add,          8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23224 +       __VCMD(net_remove,       8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23225 +       __VCMD(net_add_ipv4_v1,  8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23226 +       __VCMD(net_rem_ipv4_v1,  8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23227 +       __VCMD(net_add_ipv4,     8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23228 +       __VCMD(net_rem_ipv4,     8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23229 +#ifdef CONFIG_IPV6
23230 +       __VCMD(net_add_ipv6,     8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23231 +       __VCMD(net_remove_ipv6,  8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23232 +#endif
23233 +       __VCMD(set_iattr,        7, VCA_NONE,   0);
23234 +       __VCMD(fset_iattr,       7, VCA_NONE,   0);
23235 +       __VCMD(set_dlimit,       7, VCA_NONE,   VCF_ARES);
23236 +       __VCMD(add_dlimit,       8, VCA_NONE,   VCF_ARES);
23237 +       __VCMD(rem_dlimit,       8, VCA_NONE,   VCF_ARES);
23238 +
23239 +#ifdef CONFIG_VSERVER_DEVICE
23240 +       __VCMD(set_mapping,      8, VCA_VXI,    VCF_ARES|VCF_ZIDOK);
23241 +       __VCMD(unset_mapping,    8, VCA_VXI,    VCF_ARES|VCF_ZIDOK);
23242 +#endif
23243 +       /* debug level admin commands */
23244 +#ifdef CONFIG_VSERVER_HISTORY
23245 +       __VCMD(dump_history,     9, VCA_NONE,   0);
23246 +       __VCMD(read_history,     9, VCA_NONE,   0);
23247 +#endif
23248 +
23249 +       default:
23250 +               perm = -1;
23251 +       }
23252 +
23253 +       vxdprintk(VXD_CBIT(switch, 0),
23254 +               "vc: VCMD_%02d_%d[%d], %d,%p [%d,%d,%x,%x]",
23255 +               VC_CATEGORY(cmd), VC_COMMAND(cmd),
23256 +               VC_VERSION(cmd), id, data, compat,
23257 +               perm, args, flags);
23258 +
23259 +       ret = -ENOSYS;
23260 +       if (perm < 0)
23261 +               goto out;
23262 +
23263 +       state = 1;
23264 +       if (!capable(CAP_CONTEXT))
23265 +               goto out;
23266 +
23267 +       state = 2;
23268 +       /* moved here from the individual commands */
23269 +       ret = -EPERM;
23270 +       if ((perm > 1) && !capable(CAP_SYS_ADMIN))
23271 +               goto out;
23272 +
23273 +       state = 3;
23274 +       /* vcmd involves resource management  */
23275 +       ret = -EPERM;
23276 +       if ((flags & VCF_ARES) && !capable(CAP_SYS_RESOURCE))
23277 +               goto out;
23278 +
23279 +       state = 4;
23280 +       /* various legacy exceptions */
23281 +       switch (cmd) {
23282 +       /* will go away when spectator is a cap */
23283 +       case VCMD_ctx_migrate_v0:
23284 +       case VCMD_ctx_migrate:
23285 +               if (id == 1) {
23286 +                       current->xid = 1;
23287 +                       ret = 1;
23288 +                       goto out;
23289 +               }
23290 +               break;
23291 +
23292 +       /* will go away when spectator is a cap */
23293 +       case VCMD_net_migrate:
23294 +               if (id == 1) {
23295 +                       current->nid = 1;
23296 +                       ret = 1;
23297 +                       goto out;
23298 +               }
23299 +               break;
23300 +       }
23301 +
23302 +       /* vcmds are fine by default */
23303 +       permit = 1;
23304 +
23305 +       /* admin type vcmds require admin ... */
23306 +       if (flags & VCF_ADMIN)
23307 +               permit = vx_check(0, VS_ADMIN) ? 1 : 0;
23308 +
23309 +       /* ... but setup type vcmds override that */
23310 +       if (!permit && (flags & VCF_SETUP))
23311 +               permit = vx_flags(VXF_STATE_SETUP, 0) ? 2 : 0;
23312 +
23313 +       state = 5;
23314 +       ret = -EPERM;
23315 +       if (!permit)
23316 +               goto out;
23317 +
23318 +       state = 6;
23319 +       if (!id && (flags & VCF_ZIDOK))
23320 +               goto skip_id;
23321 +
23322 +       ret = -ESRCH;
23323 +       if (args & VCA_VXI) {
23324 +               vxi = lookup_vx_info(id);
23325 +               if (!vxi)
23326 +                       goto out;
23327 +
23328 +               if ((flags & VCF_ADMIN) &&
23329 +                       /* special case kill for shutdown */
23330 +                       (cmd != VCMD_ctx_kill) &&
23331 +                       /* can context be administrated? */
23332 +                       !vx_info_flags(vxi, VXF_STATE_ADMIN, 0)) {
23333 +                       ret = -EACCES;
23334 +                       goto out_vxi;
23335 +               }
23336 +       }
23337 +       state = 7;
23338 +       if (args & VCA_NXI) {
23339 +               nxi = lookup_nx_info(id);
23340 +               if (!nxi)
23341 +                       goto out_vxi;
23342 +
23343 +               if ((flags & VCF_ADMIN) &&
23344 +                       /* can context be administrated? */
23345 +                       !nx_info_flags(nxi, NXF_STATE_ADMIN, 0)) {
23346 +                       ret = -EACCES;
23347 +                       goto out_nxi;
23348 +               }
23349 +       }
23350 +skip_id:
23351 +       state = 8;
23352 +       ret = do_vcmd(cmd, id, vxi, nxi, data, compat);
23353 +
23354 +out_nxi:
23355 +       if ((args & VCA_NXI) && nxi)
23356 +               put_nx_info(nxi);
23357 +out_vxi:
23358 +       if ((args & VCA_VXI) && vxi)
23359 +               put_vx_info(vxi);
23360 +out:
23361 +       vxdprintk(VXD_CBIT(switch, 1),
23362 +               "vc: VCMD_%02d_%d[%d] = %08lx(%ld) [%d,%d]",
23363 +               VC_CATEGORY(cmd), VC_COMMAND(cmd),
23364 +               VC_VERSION(cmd), ret, ret, state, permit);
23365 +       return ret;
23366 +}
23367 +
23368 +asmlinkage long
23369 +sys_vserver(uint32_t cmd, uint32_t id, void __user *data)
23370 +{
23371 +       return do_vserver(cmd, id, data, 0);
23372 +}
23373 +
23374 +#ifdef CONFIG_COMPAT
23375 +
23376 +asmlinkage long
23377 +sys32_vserver(uint32_t cmd, uint32_t id, void __user *data)
23378 +{
23379 +       return do_vserver(cmd, id, data, 1);
23380 +}
23381 +
23382 +#endif /* CONFIG_COMPAT */
23383 diff -NurpP --minimal linux-3.9.4/kernel/vserver/sysctl.c linux-3.9.4-vs2.3.6.2/kernel/vserver/sysctl.c
23384 --- linux-3.9.4/kernel/vserver/sysctl.c 1970-01-01 00:00:00.000000000 +0000
23385 +++ linux-3.9.4-vs2.3.6.2/kernel/vserver/sysctl.c       2013-05-31 14:47:11.000000000 +0000
23386 @@ -0,0 +1,247 @@
23387 +/*
23388 + *  kernel/vserver/sysctl.c
23389 + *
23390 + *  Virtual Context Support
23391 + *
23392 + *  Copyright (C) 2004-2007  Herbert Pötzl
23393 + *
23394 + *  V0.01  basic structure
23395 + *
23396 + */
23397 +
23398 +#include <linux/module.h>
23399 +#include <linux/ctype.h>
23400 +#include <linux/sysctl.h>
23401 +#include <linux/parser.h>
23402 +#include <asm/uaccess.h>
23403 +
23404 +enum {
23405 +       CTL_DEBUG_ERROR         = 0,
23406 +       CTL_DEBUG_SWITCH        = 1,
23407 +       CTL_DEBUG_XID,
23408 +       CTL_DEBUG_NID,
23409 +       CTL_DEBUG_TAG,
23410 +       CTL_DEBUG_NET,
23411 +       CTL_DEBUG_LIMIT,
23412 +       CTL_DEBUG_CRES,
23413 +       CTL_DEBUG_DLIM,
23414 +       CTL_DEBUG_QUOTA,
23415 +       CTL_DEBUG_CVIRT,
23416 +       CTL_DEBUG_SPACE,
23417 +       CTL_DEBUG_PERM,
23418 +       CTL_DEBUG_MISC,
23419 +};
23420 +
23421 +
23422 +unsigned int vs_debug_switch   = 0;
23423 +unsigned int vs_debug_xid      = 0;
23424 +unsigned int vs_debug_nid      = 0;
23425 +unsigned int vs_debug_tag      = 0;
23426 +unsigned int vs_debug_net      = 0;
23427 +unsigned int vs_debug_limit    = 0;
23428 +unsigned int vs_debug_cres     = 0;
23429 +unsigned int vs_debug_dlim     = 0;
23430 +unsigned int vs_debug_quota    = 0;
23431 +unsigned int vs_debug_cvirt    = 0;
23432 +unsigned int vs_debug_space    = 0;
23433 +unsigned int vs_debug_perm     = 0;
23434 +unsigned int vs_debug_misc     = 0;
23435 +
23436 +
23437 +static struct ctl_table_header *vserver_table_header;
23438 +static ctl_table vserver_root_table[];
23439 +
23440 +
23441 +void vserver_register_sysctl(void)
23442 +{
23443 +       if (!vserver_table_header) {
23444 +               vserver_table_header = register_sysctl_table(vserver_root_table);
23445 +       }
23446 +
23447 +}
23448 +
23449 +void vserver_unregister_sysctl(void)
23450 +{
23451 +       if (vserver_table_header) {
23452 +               unregister_sysctl_table(vserver_table_header);
23453 +               vserver_table_header = NULL;
23454 +       }
23455 +}
23456 +
23457 +
23458 +static int proc_dodebug(ctl_table *table, int write,
23459 +       void __user *buffer, size_t *lenp, loff_t *ppos)
23460 +{
23461 +       char            tmpbuf[20], *p, c;
23462 +       unsigned int    value;
23463 +       size_t          left, len;
23464 +
23465 +       if ((*ppos && !write) || !*lenp) {
23466 +               *lenp = 0;
23467 +               return 0;
23468 +       }
23469 +
23470 +       left = *lenp;
23471 +
23472 +       if (write) {
23473 +               if (!access_ok(VERIFY_READ, buffer, left))
23474 +                       return -EFAULT;
23475 +               p = (char *)buffer;
23476 +               while (left && __get_user(c, p) >= 0 && isspace(c))
23477 +                       left--, p++;
23478 +               if (!left)
23479 +                       goto done;
23480 +
23481 +               if (left > sizeof(tmpbuf) - 1)
23482 +                       return -EINVAL;
23483 +               if (copy_from_user(tmpbuf, p, left))
23484 +                       return -EFAULT;
23485 +               tmpbuf[left] = '\0';
23486 +
23487 +               for (p = tmpbuf, value = 0; '0' <= *p && *p <= '9'; p++, left--)
23488 +                       value = 10 * value + (*p - '0');
23489 +               if (*p && !isspace(*p))
23490 +                       return -EINVAL;
23491 +               while (left && isspace(*p))
23492 +                       left--, p++;
23493 +               *(unsigned int *)table->data = value;
23494 +       } else {
23495 +               if (!access_ok(VERIFY_WRITE, buffer, left))
23496 +                       return -EFAULT;
23497 +               len = sprintf(tmpbuf, "%d", *(unsigned int *)table->data);
23498 +               if (len > left)
23499 +                       len = left;
23500 +               if (__copy_to_user(buffer, tmpbuf, len))
23501 +                       return -EFAULT;
23502 +               if ((left -= len) > 0) {
23503 +                       if (put_user('\n', (char *)buffer + len))
23504 +                               return -EFAULT;
23505 +                       left--;
23506 +               }
23507 +       }
23508 +
23509 +done:
23510 +       *lenp -= left;
23511 +       *ppos += *lenp;
23512 +       return 0;
23513 +}
23514 +
23515 +static int zero;
23516 +
23517 +#define        CTL_ENTRY(ctl, name)                            \
23518 +       {                                               \
23519 +               .procname       = #name,                \
23520 +               .data           = &vs_ ## name,         \
23521 +               .maxlen         = sizeof(int),          \
23522 +               .mode           = 0644,                 \
23523 +               .proc_handler   = &proc_dodebug,        \
23524 +               .extra1         = &zero,                \
23525 +               .extra2         = &zero,                \
23526 +       }
23527 +
23528 +static ctl_table vserver_debug_table[] = {
23529 +       CTL_ENTRY(CTL_DEBUG_SWITCH,     debug_switch),
23530 +       CTL_ENTRY(CTL_DEBUG_XID,        debug_xid),
23531 +       CTL_ENTRY(CTL_DEBUG_NID,        debug_nid),
23532 +       CTL_ENTRY(CTL_DEBUG_TAG,        debug_tag),
23533 +       CTL_ENTRY(CTL_DEBUG_NET,        debug_net),
23534 +       CTL_ENTRY(CTL_DEBUG_LIMIT,      debug_limit),
23535 +       CTL_ENTRY(CTL_DEBUG_CRES,       debug_cres),
23536 +       CTL_ENTRY(CTL_DEBUG_DLIM,       debug_dlim),
23537 +       CTL_ENTRY(CTL_DEBUG_QUOTA,      debug_quota),
23538 +       CTL_ENTRY(CTL_DEBUG_CVIRT,      debug_cvirt),
23539 +       CTL_ENTRY(CTL_DEBUG_SPACE,      debug_space),
23540 +       CTL_ENTRY(CTL_DEBUG_PERM,       debug_perm),
23541 +       CTL_ENTRY(CTL_DEBUG_MISC,       debug_misc),
23542 +       { 0 }
23543 +};
23544 +
23545 +static ctl_table vserver_root_table[] = {
23546 +       {
23547 +               .procname       = "vserver",
23548 +               .mode           = 0555,
23549 +               .child          = vserver_debug_table
23550 +       },
23551 +       { 0 }
23552 +};
23553 +
23554 +
23555 +static match_table_t tokens = {
23556 +       { CTL_DEBUG_SWITCH,     "switch=%x"     },
23557 +       { CTL_DEBUG_XID,        "xid=%x"        },
23558 +       { CTL_DEBUG_NID,        "nid=%x"        },
23559 +       { CTL_DEBUG_TAG,        "tag=%x"        },
23560 +       { CTL_DEBUG_NET,        "net=%x"        },
23561 +       { CTL_DEBUG_LIMIT,      "limit=%x"      },
23562 +       { CTL_DEBUG_CRES,       "cres=%x"       },
23563 +       { CTL_DEBUG_DLIM,       "dlim=%x"       },
23564 +       { CTL_DEBUG_QUOTA,      "quota=%x"      },
23565 +       { CTL_DEBUG_CVIRT,      "cvirt=%x"      },
23566 +       { CTL_DEBUG_SPACE,      "space=%x"      },
23567 +       { CTL_DEBUG_PERM,       "perm=%x"       },
23568 +       { CTL_DEBUG_MISC,       "misc=%x"       },
23569 +       { CTL_DEBUG_ERROR,      NULL            }
23570 +};
23571 +
23572 +#define        HANDLE_CASE(id, name, val)                              \
23573 +       case CTL_DEBUG_ ## id:                                  \
23574 +               vs_debug_ ## name = val;                        \
23575 +               printk("vs_debug_" #name "=0x%x\n", val);       \
23576 +               break
23577 +
23578 +
23579 +static int __init vs_debug_setup(char *str)
23580 +{
23581 +       char *p;
23582 +       int token;
23583 +
23584 +       printk("vs_debug_setup(%s)\n", str);
23585 +       while ((p = strsep(&str, ",")) != NULL) {
23586 +               substring_t args[MAX_OPT_ARGS];
23587 +               unsigned int value;
23588 +
23589 +               if (!*p)
23590 +                       continue;
23591 +
23592 +               token = match_token(p, tokens, args);
23593 +               value = (token > 0) ? simple_strtoul(args[0].from, NULL, 0) : 0;
23594 +
23595 +               switch (token) {
23596 +               HANDLE_CASE(SWITCH, switch, value);
23597 +               HANDLE_CASE(XID,    xid,    value);
23598 +               HANDLE_CASE(NID,    nid,    value);
23599 +               HANDLE_CASE(TAG,    tag,    value);
23600 +               HANDLE_CASE(NET,    net,    value);
23601 +               HANDLE_CASE(LIMIT,  limit,  value);
23602 +               HANDLE_CASE(CRES,   cres,   value);
23603 +               HANDLE_CASE(DLIM,   dlim,   value);
23604 +               HANDLE_CASE(QUOTA,  quota,  value);
23605 +               HANDLE_CASE(CVIRT,  cvirt,  value);
23606 +               HANDLE_CASE(SPACE,  space,  value);
23607 +               HANDLE_CASE(PERM,   perm,   value);
23608 +               HANDLE_CASE(MISC,   misc,   value);
23609 +               default:
23610 +                       return -EINVAL;
23611 +                       break;
23612 +               }
23613 +       }
23614 +       return 1;
23615 +}
23616 +
23617 +__setup("vsdebug=", vs_debug_setup);
23618 +
23619 +
23620 +
23621 +EXPORT_SYMBOL_GPL(vs_debug_switch);
23622 +EXPORT_SYMBOL_GPL(vs_debug_xid);
23623 +EXPORT_SYMBOL_GPL(vs_debug_nid);
23624 +EXPORT_SYMBOL_GPL(vs_debug_net);
23625 +EXPORT_SYMBOL_GPL(vs_debug_limit);
23626 +EXPORT_SYMBOL_GPL(vs_debug_cres);
23627 +EXPORT_SYMBOL_GPL(vs_debug_dlim);
23628 +EXPORT_SYMBOL_GPL(vs_debug_quota);
23629 +EXPORT_SYMBOL_GPL(vs_debug_cvirt);
23630 +EXPORT_SYMBOL_GPL(vs_debug_space);
23631 +EXPORT_SYMBOL_GPL(vs_debug_perm);
23632 +EXPORT_SYMBOL_GPL(vs_debug_misc);
23633 +
23634 diff -NurpP --minimal linux-3.9.4/kernel/vserver/tag.c linux-3.9.4-vs2.3.6.2/kernel/vserver/tag.c
23635 --- linux-3.9.4/kernel/vserver/tag.c    1970-01-01 00:00:00.000000000 +0000
23636 +++ linux-3.9.4-vs2.3.6.2/kernel/vserver/tag.c  2013-05-31 14:47:11.000000000 +0000
23637 @@ -0,0 +1,63 @@
23638 +/*
23639 + *  linux/kernel/vserver/tag.c
23640 + *
23641 + *  Virtual Server: Shallow Tag Space
23642 + *
23643 + *  Copyright (C) 2007  Herbert Pötzl
23644 + *
23645 + *  V0.01  basic implementation
23646 + *
23647 + */
23648 +
23649 +#include <linux/sched.h>
23650 +#include <linux/vserver/debug.h>
23651 +#include <linux/vs_pid.h>
23652 +#include <linux/vs_tag.h>
23653 +
23654 +#include <linux/vserver/tag_cmd.h>
23655 +
23656 +
23657 +int dx_migrate_task(struct task_struct *p, tag_t tag)
23658 +{
23659 +       if (!p)
23660 +               BUG();
23661 +
23662 +       vxdprintk(VXD_CBIT(tag, 5),
23663 +               "dx_migrate_task(%p[#%d],#%d)", p, p->tag, tag);
23664 +
23665 +       task_lock(p);
23666 +       p->tag = tag;
23667 +       task_unlock(p);
23668 +
23669 +       vxdprintk(VXD_CBIT(tag, 5),
23670 +               "moved task %p into [#%d]", p, tag);
23671 +       return 0;
23672 +}
23673 +
23674 +/* vserver syscall commands below here */
23675 +
23676 +/* taks xid and vx_info functions */
23677 +
23678 +
23679 +int vc_task_tag(uint32_t id)
23680 +{
23681 +       tag_t tag;
23682 +
23683 +       if (id) {
23684 +               struct task_struct *tsk;
23685 +               rcu_read_lock();
23686 +               tsk = find_task_by_real_pid(id);
23687 +               tag = (tsk) ? tsk->tag : -ESRCH;
23688 +               rcu_read_unlock();
23689 +       } else
23690 +               tag = dx_current_tag();
23691 +       return tag;
23692 +}
23693 +
23694 +
23695 +int vc_tag_migrate(uint32_t tag)
23696 +{
23697 +       return dx_migrate_task(current, tag & 0xFFFF);
23698 +}
23699 +
23700 +
23701 diff -NurpP --minimal linux-3.9.4/kernel/vserver/vci_config.h linux-3.9.4-vs2.3.6.2/kernel/vserver/vci_config.h
23702 --- linux-3.9.4/kernel/vserver/vci_config.h     1970-01-01 00:00:00.000000000 +0000
23703 +++ linux-3.9.4-vs2.3.6.2/kernel/vserver/vci_config.h   2013-05-31 14:47:11.000000000 +0000
23704 @@ -0,0 +1,80 @@
23705 +
23706 +/*  interface version */
23707 +
23708 +#define VCI_VERSION            0x00020308
23709 +
23710 +
23711 +enum {
23712 +       VCI_KCBIT_NO_DYNAMIC = 0,
23713 +
23714 +       VCI_KCBIT_PROC_SECURE = 4,
23715 +       /* VCI_KCBIT_HARDCPU = 5, */
23716 +       /* VCI_KCBIT_IDLELIMIT = 6, */
23717 +       /* VCI_KCBIT_IDLETIME = 7, */
23718 +
23719 +       VCI_KCBIT_COWBL = 8,
23720 +       VCI_KCBIT_FULLCOWBL = 9,
23721 +       VCI_KCBIT_SPACES = 10,
23722 +       VCI_KCBIT_NETV2 = 11,
23723 +       VCI_KCBIT_MEMCG = 12,
23724 +       VCI_KCBIT_MEMCG_SWAP = 13,
23725 +
23726 +       VCI_KCBIT_DEBUG = 16,
23727 +       VCI_KCBIT_HISTORY = 20,
23728 +       VCI_KCBIT_TAGGED = 24,
23729 +       VCI_KCBIT_PPTAG = 28,
23730 +
23731 +       VCI_KCBIT_MORE = 31,
23732 +};
23733 +
23734 +
23735 +static inline uint32_t vci_kernel_config(void)
23736 +{
23737 +       return
23738 +       (1 << VCI_KCBIT_NO_DYNAMIC) |
23739 +
23740 +       /* configured features */
23741 +#ifdef CONFIG_VSERVER_PROC_SECURE
23742 +       (1 << VCI_KCBIT_PROC_SECURE) |
23743 +#endif
23744 +#ifdef CONFIG_VSERVER_COWBL
23745 +       (1 << VCI_KCBIT_COWBL) |
23746 +       (1 << VCI_KCBIT_FULLCOWBL) |
23747 +#endif
23748 +       (1 << VCI_KCBIT_SPACES) |
23749 +       (1 << VCI_KCBIT_NETV2) |
23750 +#ifdef CONFIG_MEMCG
23751 +       (1 << VCI_KCBIT_MEMCG) |
23752 +#endif
23753 +#ifdef CONFIG_MEMCG_SWAP
23754 +       (1 << VCI_KCBIT_MEMCG_SWAP) |
23755 +#endif
23756 +
23757 +       /* debug options */
23758 +#ifdef CONFIG_VSERVER_DEBUG
23759 +       (1 << VCI_KCBIT_DEBUG) |
23760 +#endif
23761 +#ifdef CONFIG_VSERVER_HISTORY
23762 +       (1 << VCI_KCBIT_HISTORY) |
23763 +#endif
23764 +
23765 +       /* inode context tagging */
23766 +#if    defined(CONFIG_TAGGING_NONE)
23767 +       (0 << VCI_KCBIT_TAGGED) |
23768 +#elif  defined(CONFIG_TAGGING_UID16)
23769 +       (1 << VCI_KCBIT_TAGGED) |
23770 +#elif  defined(CONFIG_TAGGING_GID16)
23771 +       (2 << VCI_KCBIT_TAGGED) |
23772 +#elif  defined(CONFIG_TAGGING_ID24)
23773 +       (3 << VCI_KCBIT_TAGGED) |
23774 +#elif  defined(CONFIG_TAGGING_INTERN)
23775 +       (4 << VCI_KCBIT_TAGGED) |
23776 +#elif  defined(CONFIG_TAGGING_RUNTIME)
23777 +       (5 << VCI_KCBIT_TAGGED) |
23778 +#else
23779 +       (7 << VCI_KCBIT_TAGGED) |
23780 +#endif
23781 +       (1 << VCI_KCBIT_PPTAG) |
23782 +       0;
23783 +}
23784 +
23785 diff -NurpP --minimal linux-3.9.4/mm/memcontrol.c linux-3.9.4-vs2.3.6.2/mm/memcontrol.c
23786 --- linux-3.9.4/mm/memcontrol.c 2013-05-31 13:45:31.000000000 +0000
23787 +++ linux-3.9.4-vs2.3.6.2/mm/memcontrol.c       2013-05-31 14:47:11.000000000 +0000
23788 @@ -1046,6 +1046,31 @@ struct mem_cgroup *mem_cgroup_from_task(
23789         return mem_cgroup_from_css(task_subsys_state(p, mem_cgroup_subsys_id));
23790  }
23791  
23792 +u64 mem_cgroup_res_read_u64(struct mem_cgroup *mem, int member)
23793 +{
23794 +       return res_counter_read_u64(&mem->res, member);
23795 +}
23796 +
23797 +u64 mem_cgroup_memsw_read_u64(struct mem_cgroup *mem, int member)
23798 +{
23799 +       return res_counter_read_u64(&mem->memsw, member);
23800 +}
23801 +
23802 +s64 mem_cgroup_stat_read_cache(struct mem_cgroup *mem)
23803 +{
23804 +       return mem_cgroup_read_stat(mem, MEM_CGROUP_STAT_CACHE);
23805 +}
23806 +
23807 +s64 mem_cgroup_stat_read_anon(struct mem_cgroup *mem)
23808 +{
23809 +       return mem_cgroup_read_stat(mem, MEM_CGROUP_STAT_RSS);
23810 +}
23811 +
23812 +s64 mem_cgroup_stat_read_mapped(struct mem_cgroup *mem)
23813 +{
23814 +       return mem_cgroup_read_stat(mem, MEM_CGROUP_STAT_FILE_MAPPED);
23815 +}
23816 +
23817  struct mem_cgroup *try_get_mem_cgroup_from_mm(struct mm_struct *mm)
23818  {
23819         struct mem_cgroup *memcg = NULL;
23820 diff -NurpP --minimal linux-3.9.4/mm/oom_kill.c linux-3.9.4-vs2.3.6.2/mm/oom_kill.c
23821 --- linux-3.9.4/mm/oom_kill.c   2013-05-31 13:45:31.000000000 +0000
23822 +++ linux-3.9.4-vs2.3.6.2/mm/oom_kill.c 2013-05-31 14:47:11.000000000 +0000
23823 @@ -35,6 +35,8 @@
23824  #include <linux/freezer.h>
23825  #include <linux/ftrace.h>
23826  #include <linux/ratelimit.h>
23827 +#include <linux/reboot.h>
23828 +#include <linux/vs_context.h>
23829  
23830  #define CREATE_TRACE_POINTS
23831  #include <trace/events/oom.h>
23832 @@ -113,11 +115,18 @@ struct task_struct *find_lock_task_mm(st
23833  static bool oom_unkillable_task(struct task_struct *p,
23834                 const struct mem_cgroup *memcg, const nodemask_t *nodemask)
23835  {
23836 -       if (is_global_init(p))
23837 +       unsigned xid = vx_current_xid();
23838 +
23839 +       /* skip the init task, global and per guest */
23840 +       if (task_is_init(p))
23841                 return true;
23842         if (p->flags & PF_KTHREAD)
23843                 return true;
23844  
23845 +       /* skip other guest and host processes if oom in guest */
23846 +       if (xid && vx_task_xid(p) != xid)
23847 +               return true;
23848 +
23849         /* When mem_cgroup_out_of_memory() and p is not member of the group */
23850         if (memcg && !task_in_mem_cgroup(p, memcg))
23851                 return true;
23852 @@ -426,8 +435,8 @@ void oom_kill_process(struct task_struct
23853                 dump_header(p, gfp_mask, order, memcg, nodemask);
23854  
23855         task_lock(p);
23856 -       pr_err("%s: Kill process %d (%s) score %d or sacrifice child\n",
23857 -               message, task_pid_nr(p), p->comm, points);
23858 +       pr_err("%s: Kill process %d:#%u (%s) score %d or sacrifice child\n",
23859 +               message, task_pid_nr(p), p->xid, p->comm, points);
23860         task_unlock(p);
23861  
23862         /*
23863 @@ -472,8 +481,8 @@ void oom_kill_process(struct task_struct
23864  
23865         /* mm cannot safely be dereferenced after task_unlock(victim) */
23866         mm = victim->mm;
23867 -       pr_err("Killed process %d (%s) total-vm:%lukB, anon-rss:%lukB, file-rss:%lukB\n",
23868 -               task_pid_nr(victim), victim->comm, K(victim->mm->total_vm),
23869 +       pr_err("Killed process %d:#%u (%s) total-vm:%lukB, anon-rss:%lukB, file-rss:%lukB\n",
23870 +               task_pid_nr(victim), victim->xid, victim->comm, K(victim->mm->total_vm),
23871                 K(get_mm_counter(victim->mm, MM_ANONPAGES)),
23872                 K(get_mm_counter(victim->mm, MM_FILEPAGES)));
23873         task_unlock(victim);
23874 @@ -543,6 +552,8 @@ int unregister_oom_notifier(struct notif
23875  }
23876  EXPORT_SYMBOL_GPL(unregister_oom_notifier);
23877  
23878 +long vs_oom_action(unsigned int);
23879 +
23880  /*
23881   * Try to acquire the OOM killer lock for the zones in zonelist.  Returns zero
23882   * if a parallel OOM killing is already taking place that includes a zone in
23883 @@ -655,7 +666,12 @@ void out_of_memory(struct zonelist *zone
23884         /* Found nothing?!?! Either we hang forever, or we panic. */
23885         if (!p) {
23886                 dump_header(NULL, gfp_mask, order, NULL, mpol_mask);
23887 -               panic("Out of memory and no killable processes...\n");
23888 +
23889 +               /* avoid panic for guest OOM */
23890 +               if (vx_current_xid())
23891 +                       vs_oom_action(LINUX_REBOOT_CMD_OOM);
23892 +               else
23893 +                       panic("Out of memory and no killable processes...\n");
23894         }
23895         if (PTR_ERR(p) != -1UL) {
23896                 oom_kill_process(p, gfp_mask, order, points, totalpages, NULL,
23897 diff -NurpP --minimal linux-3.9.4/mm/page_alloc.c linux-3.9.4-vs2.3.6.2/mm/page_alloc.c
23898 --- linux-3.9.4/mm/page_alloc.c 2013-05-31 13:45:31.000000000 +0000
23899 +++ linux-3.9.4-vs2.3.6.2/mm/page_alloc.c       2013-05-31 15:08:50.000000000 +0000
23900 @@ -59,6 +59,8 @@
23901  #include <linux/migrate.h>
23902  #include <linux/page-debug-flags.h>
23903  #include <linux/sched/rt.h>
23904 +#include <linux/vs_base.h>
23905 +#include <linux/vs_limit.h>
23906  
23907  #include <asm/tlbflush.h>
23908  #include <asm/div64.h>
23909 @@ -2873,6 +2875,9 @@ void si_meminfo(struct sysinfo *val)
23910         val->totalhigh = totalhigh_pages;
23911         val->freehigh = nr_free_highpages();
23912         val->mem_unit = PAGE_SIZE;
23913 +
23914 +       if (vx_flags(VXF_VIRT_MEM, 0))
23915 +               vx_vsi_meminfo(val);
23916  }
23917  
23918  EXPORT_SYMBOL(si_meminfo);
23919 @@ -2893,6 +2898,9 @@ void si_meminfo_node(struct sysinfo *val
23920         val->freehigh = 0;
23921  #endif
23922         val->mem_unit = PAGE_SIZE;
23923 +
23924 +       if (vx_flags(VXF_VIRT_MEM, 0))
23925 +               vx_vsi_meminfo(val);
23926  }
23927  #endif
23928  
23929 diff -NurpP --minimal linux-3.9.4/mm/pgtable-generic.c linux-3.9.4-vs2.3.6.2/mm/pgtable-generic.c
23930 --- linux-3.9.4/mm/pgtable-generic.c    2013-02-19 13:58:57.000000000 +0000
23931 +++ linux-3.9.4-vs2.3.6.2/mm/pgtable-generic.c  2013-05-31 14:47:11.000000000 +0000
23932 @@ -6,6 +6,8 @@
23933   *  Copyright (C) 2010  Linus Torvalds
23934   */
23935  
23936 +#include <linux/mm.h>
23937 +
23938  #include <linux/pagemap.h>
23939  #include <asm/tlb.h>
23940  #include <asm-generic/pgtable.h>
23941 diff -NurpP --minimal linux-3.9.4/mm/shmem.c linux-3.9.4-vs2.3.6.2/mm/shmem.c
23942 --- linux-3.9.4/mm/shmem.c      2013-05-31 13:45:31.000000000 +0000
23943 +++ linux-3.9.4-vs2.3.6.2/mm/shmem.c    2013-05-31 14:47:11.000000000 +0000
23944 @@ -1909,7 +1909,7 @@ static int shmem_statfs(struct dentry *d
23945  {
23946         struct shmem_sb_info *sbinfo = SHMEM_SB(dentry->d_sb);
23947  
23948 -       buf->f_type = TMPFS_MAGIC;
23949 +       buf->f_type = TMPFS_SUPER_MAGIC;
23950         buf->f_bsize = PAGE_CACHE_SIZE;
23951         buf->f_namelen = NAME_MAX;
23952         if (sbinfo->max_blocks) {
23953 @@ -2606,7 +2606,7 @@ int shmem_fill_super(struct super_block
23954         sb->s_maxbytes = MAX_LFS_FILESIZE;
23955         sb->s_blocksize = PAGE_CACHE_SIZE;
23956         sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
23957 -       sb->s_magic = TMPFS_MAGIC;
23958 +       sb->s_magic = TMPFS_SUPER_MAGIC;
23959         sb->s_op = &shmem_ops;
23960         sb->s_time_gran = 1;
23961  #ifdef CONFIG_TMPFS_XATTR
23962 diff -NurpP --minimal linux-3.9.4/mm/slab.c linux-3.9.4-vs2.3.6.2/mm/slab.c
23963 --- linux-3.9.4/mm/slab.c       2013-05-31 13:45:31.000000000 +0000
23964 +++ linux-3.9.4-vs2.3.6.2/mm/slab.c     2013-05-31 14:47:11.000000000 +0000
23965 @@ -429,6 +429,8 @@ static void kmem_list3_init(struct kmem_
23966  #define STATS_INC_FREEMISS(x)  do { } while (0)
23967  #endif
23968  
23969 +#include "slab_vs.h"
23970 +
23971  #if DEBUG
23972  
23973  /*
23974 @@ -3438,6 +3440,7 @@ retry:
23975  
23976         obj = slab_get_obj(cachep, slabp, nodeid);
23977         check_slabp(cachep, slabp);
23978 +       vx_slab_alloc(cachep, flags);
23979         l3->free_objects--;
23980         /* move slabp to correct slabp list: */
23981         list_del(&slabp->list);
23982 @@ -3517,6 +3520,7 @@ slab_alloc_node(struct kmem_cache *cache
23983         /* ___cache_alloc_node can fall back to other nodes */
23984         ptr = ____cache_alloc_node(cachep, flags, nodeid);
23985    out:
23986 +       vx_slab_alloc(cachep, flags);
23987         local_irq_restore(save_flags);
23988         ptr = cache_alloc_debugcheck_after(cachep, flags, ptr, caller);
23989         kmemleak_alloc_recursive(ptr, cachep->object_size, 1, cachep->flags,
23990 @@ -3709,6 +3713,7 @@ static inline void __cache_free(struct k
23991         check_irq_off();
23992         kmemleak_free_recursive(objp, cachep->flags);
23993         objp = cache_free_debugcheck(cachep, objp, caller);
23994 +       vx_slab_free(cachep);
23995  
23996         kmemcheck_slab_free(cachep, objp, cachep->object_size);
23997  
23998 diff -NurpP --minimal linux-3.9.4/mm/slab_vs.h linux-3.9.4-vs2.3.6.2/mm/slab_vs.h
23999 --- linux-3.9.4/mm/slab_vs.h    1970-01-01 00:00:00.000000000 +0000
24000 +++ linux-3.9.4-vs2.3.6.2/mm/slab_vs.h  2013-05-31 14:47:11.000000000 +0000
24001 @@ -0,0 +1,29 @@
24002 +
24003 +#include <linux/vserver/context.h>
24004 +
24005 +#include <linux/vs_context.h>
24006 +
24007 +static inline
24008 +void vx_slab_alloc(struct kmem_cache *cachep, gfp_t flags)
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_add(cachep->size, &vxi->cacct.slab[what]);
24017 +}
24018 +
24019 +static inline
24020 +void vx_slab_free(struct kmem_cache *cachep)
24021 +{
24022 +       int what = gfp_zone(cachep->allocflags);
24023 +       struct vx_info *vxi = current_vx_info();
24024 +
24025 +       if (!vxi)
24026 +               return;
24027 +
24028 +       atomic_sub(cachep->size, &vxi->cacct.slab[what]);
24029 +}
24030 +
24031 diff -NurpP --minimal linux-3.9.4/mm/swapfile.c linux-3.9.4-vs2.3.6.2/mm/swapfile.c
24032 --- linux-3.9.4/mm/swapfile.c   2013-05-31 13:45:31.000000000 +0000
24033 +++ linux-3.9.4-vs2.3.6.2/mm/swapfile.c 2013-05-31 14:47:11.000000000 +0000
24034 @@ -39,6 +39,7 @@
24035  #include <asm/tlbflush.h>
24036  #include <linux/swapops.h>
24037  #include <linux/page_cgroup.h>
24038 +#include <linux/vs_base.h>
24039  
24040  static bool swap_count_continued(struct swap_info_struct *, pgoff_t,
24041                                  unsigned char);
24042 @@ -1767,6 +1768,16 @@ static int swap_show(struct seq_file *sw
24043  
24044         if (si == SEQ_START_TOKEN) {
24045                 seq_puts(swap,"Filename\t\t\t\tType\t\tSize\tUsed\tPriority\n");
24046 +               if (vx_flags(VXF_VIRT_MEM, 0)) {
24047 +                       struct sysinfo si;
24048 +
24049 +                       vx_vsi_swapinfo(&si);
24050 +                       if (si.totalswap < (1 << 10))
24051 +                               return 0;
24052 +                       seq_printf(swap, "%s\t\t\t\t\t%s\t%lu\t%lu\t%d\n",
24053 +                               "hdv0", "partition", si.totalswap >> 10,
24054 +                               (si.totalswap - si.freeswap) >> 10, -1);
24055 +               }
24056                 return 0;
24057         }
24058  
24059 @@ -2195,6 +2206,8 @@ void si_swapinfo(struct sysinfo *val)
24060         val->freeswap = atomic_long_read(&nr_swap_pages) + nr_to_be_unused;
24061         val->totalswap = total_swap_pages + nr_to_be_unused;
24062         spin_unlock(&swap_lock);
24063 +       if (vx_flags(VXF_VIRT_MEM, 0))
24064 +               vx_vsi_swapinfo(val);
24065  }
24066  
24067  /*
24068 diff -NurpP --minimal linux-3.9.4/net/bridge/br_multicast.c linux-3.9.4-vs2.3.6.2/net/bridge/br_multicast.c
24069 --- linux-3.9.4/net/bridge/br_multicast.c       2013-05-31 13:45:31.000000000 +0000
24070 +++ linux-3.9.4-vs2.3.6.2/net/bridge/br_multicast.c     2013-05-31 17:17:53.000000000 +0000
24071 @@ -443,7 +443,7 @@ static struct sk_buff *br_ip6_multicast_
24072         ip6h->hop_limit = 1;
24073         ipv6_addr_set(&ip6h->daddr, htonl(0xff020000), 0, 0, htonl(1));
24074         if (ipv6_dev_get_saddr(dev_net(br->dev), br->dev, &ip6h->daddr, 0,
24075 -                              &ip6h->saddr)) {
24076 +                              &ip6h->saddr, NULL)) {
24077                 kfree_skb(skb);
24078                 return NULL;
24079         }
24080 diff -NurpP --minimal linux-3.9.4/net/core/dev.c linux-3.9.4-vs2.3.6.2/net/core/dev.c
24081 --- linux-3.9.4/net/core/dev.c  2013-05-31 14:22:27.000000000 +0000
24082 +++ linux-3.9.4-vs2.3.6.2/net/core/dev.c        2013-05-31 18:37:38.000000000 +0000
24083 @@ -122,6 +122,7 @@
24084  #include <linux/in.h>
24085  #include <linux/jhash.h>
24086  #include <linux/random.h>
24087 +#include <linux/vs_inet.h>
24088  #include <trace/events/napi.h>
24089  #include <trace/events/net.h>
24090  #include <trace/events/skb.h>
24091 @@ -662,7 +663,8 @@ struct net_device *__dev_get_by_name(str
24092         struct hlist_head *head = dev_name_hash(net, name);
24093  
24094         hlist_for_each_entry(dev, head, name_hlist)
24095 -               if (!strncmp(dev->name, name, IFNAMSIZ))
24096 +               if (!strncmp(dev->name, name, IFNAMSIZ) &&
24097 +                   nx_dev_visible(current_nx_info(), dev))
24098                         return dev;
24099  
24100         return NULL;
24101 @@ -687,7 +689,8 @@ struct net_device *dev_get_by_name_rcu(s
24102         struct hlist_head *head = dev_name_hash(net, name);
24103  
24104         hlist_for_each_entry_rcu(dev, head, name_hlist)
24105 -               if (!strncmp(dev->name, name, IFNAMSIZ))
24106 +               if (!strncmp(dev->name, name, IFNAMSIZ) &&
24107 +                   nx_dev_visible(current_nx_info(), dev))
24108                         return dev;
24109  
24110         return NULL;
24111 @@ -737,7 +740,8 @@ struct net_device *__dev_get_by_index(st
24112         struct hlist_head *head = dev_index_hash(net, ifindex);
24113  
24114         hlist_for_each_entry(dev, head, index_hlist)
24115 -               if (dev->ifindex == ifindex)
24116 +               if ((dev->ifindex == ifindex) &&
24117 +                   nx_dev_visible(current_nx_info(), dev))
24118                         return dev;
24119  
24120         return NULL;
24121 @@ -755,7 +759,7 @@ EXPORT_SYMBOL(__dev_get_by_index);
24122   *     about locking. The caller must hold RCU lock.
24123   */
24124  
24125 -struct net_device *dev_get_by_index_rcu(struct net *net, int ifindex)
24126 +struct net_device *dev_get_by_index_real_rcu(struct net *net, int ifindex)
24127  {
24128         struct net_device *dev;
24129         struct hlist_head *head = dev_index_hash(net, ifindex);
24130 @@ -766,6 +770,16 @@ struct net_device *dev_get_by_index_rcu(
24131  
24132         return NULL;
24133  }
24134 +EXPORT_SYMBOL(dev_get_by_index_real_rcu);
24135 +
24136 +struct net_device *dev_get_by_index_rcu(struct net *net, int ifindex)
24137 +{
24138 +       struct net_device *dev = dev_get_by_index_real_rcu(net, ifindex);
24139 +
24140 +       if (nx_dev_visible(current_nx_info(), dev))
24141 +               return dev;
24142 +       return NULL;
24143 +}
24144  EXPORT_SYMBOL(dev_get_by_index_rcu);
24145  
24146  
24147 @@ -814,7 +828,8 @@ struct net_device *dev_getbyhwaddr_rcu(s
24148  
24149         for_each_netdev_rcu(net, dev)
24150                 if (dev->type == type &&
24151 -                   !memcmp(dev->dev_addr, ha, dev->addr_len))
24152 +                   !memcmp(dev->dev_addr, ha, dev->addr_len) &&
24153 +                   nx_dev_visible(current_nx_info(), dev))
24154                         return dev;
24155  
24156         return NULL;
24157 @@ -826,9 +841,11 @@ struct net_device *__dev_getfirstbyhwtyp
24158         struct net_device *dev;
24159  
24160         ASSERT_RTNL();
24161 -       for_each_netdev(net, dev)
24162 -               if (dev->type == type)
24163 +       for_each_netdev(net, dev) {
24164 +               if ((dev->type == type) &&
24165 +                   nx_dev_visible(current_nx_info(), dev))
24166                         return dev;
24167 +       }
24168  
24169         return NULL;
24170  }
24171 @@ -840,7 +857,8 @@ struct net_device *dev_getfirstbyhwtype(
24172  
24173         rcu_read_lock();
24174         for_each_netdev_rcu(net, dev)
24175 -               if (dev->type == type) {
24176 +               if ((dev->type == type) &&
24177 +                   nx_dev_visible(current_nx_info(), dev)) {
24178                         dev_hold(dev);
24179                         ret = dev;
24180                         break;
24181 @@ -868,7 +886,8 @@ struct net_device *dev_get_by_flags_rcu(
24182  
24183         ret = NULL;
24184         for_each_netdev_rcu(net, dev) {
24185 -               if (((dev->flags ^ if_flags) & mask) == 0) {
24186 +               if ((((dev->flags ^ if_flags) & mask) == 0) &&
24187 +                       nx_dev_visible(current_nx_info(), dev)) {
24188                         ret = dev;
24189                         break;
24190                 }
24191 @@ -946,6 +965,8 @@ static int __dev_alloc_name(struct net *
24192                                 continue;
24193                         if (i < 0 || i >= max_netdevices)
24194                                 continue;
24195 +                       if (!nx_dev_visible(current_nx_info(), d))
24196 +                               continue;
24197  
24198                         /*  avoid cases where sscanf is not exact inverse of printf */
24199                         snprintf(buf, IFNAMSIZ, name, i);
24200 diff -NurpP --minimal linux-3.9.4/net/core/net-procfs.c linux-3.9.4-vs2.3.6.2/net/core/net-procfs.c
24201 --- linux-3.9.4/net/core/net-procfs.c   2013-05-31 13:45:32.000000000 +0000
24202 +++ linux-3.9.4-vs2.3.6.2/net/core/net-procfs.c 2013-06-01 10:40:52.000000000 +0000
24203 @@ -1,6 +1,7 @@
24204  #include <linux/netdevice.h>
24205  #include <linux/proc_fs.h>
24206  #include <linux/seq_file.h>
24207 +#include <linux/vs_inet.h>
24208  #include <net/wext.h>
24209  
24210  #define BUCKET_SPACE (32 - NETDEV_HASHBITS - 1)
24211 @@ -77,8 +78,13 @@ static void dev_seq_stop(struct seq_file
24212  static void dev_seq_printf_stats(struct seq_file *seq, struct net_device *dev)
24213  {
24214         struct rtnl_link_stats64 temp;
24215 -       const struct rtnl_link_stats64 *stats = dev_get_stats(dev, &temp);
24216 +       const struct rtnl_link_stats64 *stats;
24217 +
24218 +       /* device visible inside network context? */
24219 +       if (!nx_dev_visible(current_nx_info(), dev))
24220 +               return;
24221  
24222 +       stats = dev_get_stats(dev, &temp);
24223         seq_printf(seq, "%6s: %7llu %7llu %4llu %4llu %4llu %5llu %10llu %9llu "
24224                    "%8llu %7llu %4llu %4llu %4llu %5llu %7llu %10llu\n",
24225                    dev->name, stats->rx_bytes, stats->rx_packets,
24226 diff -NurpP --minimal linux-3.9.4/net/core/rtnetlink.c linux-3.9.4-vs2.3.6.2/net/core/rtnetlink.c
24227 --- linux-3.9.4/net/core/rtnetlink.c    2013-05-31 13:45:32.000000000 +0000
24228 +++ linux-3.9.4-vs2.3.6.2/net/core/rtnetlink.c  2013-05-31 17:17:54.000000000 +0000
24229 @@ -1085,6 +1085,8 @@ static int rtnl_dump_ifinfo(struct sk_bu
24230                 hlist_for_each_entry_rcu(dev, head, index_hlist) {
24231                         if (idx < s_idx)
24232                                 goto cont;
24233 +                       if (!nx_dev_visible(skb->sk->sk_nx_info, dev))
24234 +                               continue;
24235                         if (rtnl_fill_ifinfo(skb, dev, RTM_NEWLINK,
24236                                              NETLINK_CB(cb->skb).portid,
24237                                              cb->nlh->nlmsg_seq, 0,
24238 @@ -1974,6 +1976,9 @@ void rtmsg_ifinfo(int type, struct net_d
24239         int err = -ENOBUFS;
24240         size_t if_info_size;
24241  
24242 +       if (!nx_dev_visible(current_nx_info(), dev))
24243 +               return;
24244 +
24245         skb = nlmsg_new((if_info_size = if_nlmsg_size(dev, 0)), GFP_KERNEL);
24246         if (skb == NULL)
24247                 goto errout;
24248 diff -NurpP --minimal linux-3.9.4/net/core/sock.c linux-3.9.4-vs2.3.6.2/net/core/sock.c
24249 --- linux-3.9.4/net/core/sock.c 2013-05-31 14:22:27.000000000 +0000
24250 +++ linux-3.9.4-vs2.3.6.2/net/core/sock.c       2013-05-31 17:17:54.000000000 +0000
24251 @@ -132,6 +132,10 @@
24252  #include <net/netprio_cgroup.h>
24253  
24254  #include <linux/filter.h>
24255 +#include <linux/vs_socket.h>
24256 +#include <linux/vs_limit.h>
24257 +#include <linux/vs_context.h>
24258 +#include <linux/vs_network.h>
24259  
24260  #include <trace/events/sock.h>
24261  
24262 @@ -1257,6 +1261,8 @@ static struct sock *sk_prot_alloc(struct
24263                         goto out_free_sec;
24264                 sk_tx_queue_clear(sk);
24265         }
24266 +               sock_vx_init(sk);
24267 +               sock_nx_init(sk);
24268  
24269         return sk;
24270  
24271 @@ -1367,6 +1373,11 @@ static void __sk_free(struct sock *sk)
24272                 put_cred(sk->sk_peer_cred);
24273         put_pid(sk->sk_peer_pid);
24274         put_net(sock_net(sk));
24275 +       vx_sock_dec(sk);
24276 +       clr_vx_info(&sk->sk_vx_info);
24277 +       sk->sk_xid = -1;
24278 +       clr_nx_info(&sk->sk_nx_info);
24279 +       sk->sk_nid = -1;
24280         sk_prot_free(sk->sk_prot_creator, sk);
24281  }
24282  
24283 @@ -1427,6 +1438,8 @@ struct sock *sk_clone_lock(const struct
24284  
24285                 /* SANITY */
24286                 get_net(sock_net(newsk));
24287 +               sock_vx_init(newsk);
24288 +               sock_nx_init(newsk);
24289                 sk_node_init(&newsk->sk_node);
24290                 sock_lock_init(newsk);
24291                 bh_lock_sock(newsk);
24292 @@ -1483,6 +1496,12 @@ struct sock *sk_clone_lock(const struct
24293                 smp_wmb();
24294                 atomic_set(&newsk->sk_refcnt, 2);
24295  
24296 +               set_vx_info(&newsk->sk_vx_info, sk->sk_vx_info);
24297 +               newsk->sk_xid = sk->sk_xid;
24298 +               vx_sock_inc(newsk);
24299 +               set_nx_info(&newsk->sk_nx_info, sk->sk_nx_info);
24300 +               newsk->sk_nid = sk->sk_nid;
24301 +
24302                 /*
24303                  * Increment the counter in the same struct proto as the master
24304                  * sock (sk_refcnt_debug_inc uses newsk->sk_prot->socks, that
24305 @@ -2278,6 +2297,12 @@ void sock_init_data(struct socket *sock,
24306  
24307         sk->sk_stamp = ktime_set(-1L, 0);
24308  
24309 +       set_vx_info(&sk->sk_vx_info, current_vx_info());
24310 +       sk->sk_xid = vx_current_xid();
24311 +       vx_sock_inc(sk);
24312 +       set_nx_info(&sk->sk_nx_info, current_nx_info());
24313 +       sk->sk_nid = nx_current_nid();
24314 +
24315         /*
24316          * Before updating sk_refcnt, we must commit prior changes to memory
24317          * (Documentation/RCU/rculist_nulls.txt for details)
24318 diff -NurpP --minimal linux-3.9.4/net/ipv4/af_inet.c linux-3.9.4-vs2.3.6.2/net/ipv4/af_inet.c
24319 --- linux-3.9.4/net/ipv4/af_inet.c      2013-05-31 13:45:32.000000000 +0000
24320 +++ linux-3.9.4-vs2.3.6.2/net/ipv4/af_inet.c    2013-05-31 18:24:05.000000000 +0000
24321 @@ -118,6 +118,7 @@
24322  #ifdef CONFIG_IP_MROUTE
24323  #include <linux/mroute.h>
24324  #endif
24325 +#include <linux/vs_limit.h>
24326  
24327  
24328  /* The inetsw table contains everything that inet_create needs to
24329 @@ -336,6 +337,10 @@ lookup_protocol:
24330         }
24331  
24332         err = -EPERM;
24333 +       if ((protocol == IPPROTO_ICMP) &&
24334 +               nx_capable(CAP_NET_RAW, NXC_RAW_ICMP))
24335 +               goto override;
24336 +override:
24337         if (sock->type == SOCK_RAW && !kern &&
24338             !ns_capable(net->user_ns, CAP_NET_RAW))
24339                 goto out_rcu_unlock;
24340 @@ -460,6 +465,7 @@ int inet_bind(struct socket *sock, struc
24341         struct sockaddr_in *addr = (struct sockaddr_in *)uaddr;
24342         struct sock *sk = sock->sk;
24343         struct inet_sock *inet = inet_sk(sk);
24344 +       struct nx_v4_sock_addr nsa;
24345         struct net *net = sock_net(sk);
24346         unsigned short snum;
24347         int chk_addr_ret;
24348 @@ -484,7 +490,11 @@ int inet_bind(struct socket *sock, struc
24349                         goto out;
24350         }
24351  
24352 -       chk_addr_ret = inet_addr_type(net, addr->sin_addr.s_addr);
24353 +       err = v4_map_sock_addr(inet, addr, &nsa);
24354 +       if (err)
24355 +               goto out;
24356 +
24357 +       chk_addr_ret = inet_addr_type(net, nsa.saddr);
24358  
24359         /* Not specified by any standard per-se, however it breaks too
24360          * many applications when removed.  It is unfortunate since
24361 @@ -496,7 +506,7 @@ int inet_bind(struct socket *sock, struc
24362         err = -EADDRNOTAVAIL;
24363         if (!sysctl_ip_nonlocal_bind &&
24364             !(inet->freebind || inet->transparent) &&
24365 -           addr->sin_addr.s_addr != htonl(INADDR_ANY) &&
24366 +           nsa.saddr != htonl(INADDR_ANY) &&
24367             chk_addr_ret != RTN_LOCAL &&
24368             chk_addr_ret != RTN_MULTICAST &&
24369             chk_addr_ret != RTN_BROADCAST)
24370 @@ -522,7 +532,7 @@ int inet_bind(struct socket *sock, struc
24371         if (sk->sk_state != TCP_CLOSE || inet->inet_num)
24372                 goto out_release_sock;
24373  
24374 -       inet->inet_rcv_saddr = inet->inet_saddr = addr->sin_addr.s_addr;
24375 +       v4_set_sock_addr(inet, &nsa);
24376         if (chk_addr_ret == RTN_MULTICAST || chk_addr_ret == RTN_BROADCAST)
24377                 inet->inet_saddr = 0;  /* Use device */
24378  
24379 @@ -741,11 +751,13 @@ int inet_getname(struct socket *sock, st
24380                      peer == 1))
24381                         return -ENOTCONN;
24382                 sin->sin_port = inet->inet_dport;
24383 -               sin->sin_addr.s_addr = inet->inet_daddr;
24384 +               sin->sin_addr.s_addr =
24385 +                       nx_map_sock_lback(sk->sk_nx_info, inet->inet_daddr);
24386         } else {
24387                 __be32 addr = inet->inet_rcv_saddr;
24388                 if (!addr)
24389                         addr = inet->inet_saddr;
24390 +               addr = nx_map_sock_lback(sk->sk_nx_info, addr);
24391                 sin->sin_port = inet->inet_sport;
24392                 sin->sin_addr.s_addr = addr;
24393         }
24394 diff -NurpP --minimal linux-3.9.4/net/ipv4/arp.c linux-3.9.4-vs2.3.6.2/net/ipv4/arp.c
24395 --- linux-3.9.4/net/ipv4/arp.c  2013-05-31 13:45:32.000000000 +0000
24396 +++ linux-3.9.4-vs2.3.6.2/net/ipv4/arp.c        2013-05-31 17:17:54.000000000 +0000
24397 @@ -1317,6 +1317,7 @@ static void arp_format_neigh_entry(struc
24398         struct net_device *dev = n->dev;
24399         int hatype = dev->type;
24400  
24401 +       /* FIXME: check for network context */
24402         read_lock(&n->lock);
24403         /* Convert hardware address to XX:XX:XX:XX ... form. */
24404  #if IS_ENABLED(CONFIG_AX25)
24405 @@ -1348,6 +1349,7 @@ static void arp_format_pneigh_entry(stru
24406         int hatype = dev ? dev->type : 0;
24407         char tbuf[16];
24408  
24409 +       /* FIXME: check for network context */
24410         sprintf(tbuf, "%pI4", n->key);
24411         seq_printf(seq, "%-16s 0x%-10x0x%-10x%s     *        %s\n",
24412                    tbuf, hatype, ATF_PUBL | ATF_PERM, "00:00:00:00:00:00",
24413 diff -NurpP --minimal linux-3.9.4/net/ipv4/devinet.c linux-3.9.4-vs2.3.6.2/net/ipv4/devinet.c
24414 --- linux-3.9.4/net/ipv4/devinet.c      2013-05-31 13:45:32.000000000 +0000
24415 +++ linux-3.9.4-vs2.3.6.2/net/ipv4/devinet.c    2013-05-31 17:17:54.000000000 +0000
24416 @@ -522,6 +522,7 @@ struct in_device *inetdev_by_index(struc
24417  }
24418  EXPORT_SYMBOL(inetdev_by_index);
24419  
24420 +
24421  /* Called only from RTNL semaphored context. No locks. */
24422  
24423  struct in_ifaddr *inet_ifa_byprefix(struct in_device *in_dev, __be32 prefix,
24424 @@ -940,6 +941,8 @@ int devinet_ioctl(struct net *net, unsig
24425  
24426         in_dev = __in_dev_get_rtnl(dev);
24427         if (in_dev) {
24428 +               struct nx_info *nxi = current_nx_info();
24429 +
24430                 if (tryaddrmatch) {
24431                         /* Matthias Andree */
24432                         /* compare label and address (4.4BSD style) */
24433 @@ -948,6 +951,8 @@ int devinet_ioctl(struct net *net, unsig
24434                            This is checked above. */
24435                         for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
24436                              ifap = &ifa->ifa_next) {
24437 +                               if (!nx_v4_ifa_visible(nxi, ifa))
24438 +                                       continue;
24439                                 if (!strcmp(ifr.ifr_name, ifa->ifa_label) &&
24440                                     sin_orig.sin_addr.s_addr ==
24441                                                         ifa->ifa_local) {
24442 @@ -960,9 +965,12 @@ int devinet_ioctl(struct net *net, unsig
24443                    comparing just the label */
24444                 if (!ifa) {
24445                         for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
24446 -                            ifap = &ifa->ifa_next)
24447 +                            ifap = &ifa->ifa_next) {
24448 +                               if (!nx_v4_ifa_visible(nxi, ifa))
24449 +                                       continue;
24450                                 if (!strcmp(ifr.ifr_name, ifa->ifa_label))
24451                                         break;
24452 +                       }
24453                 }
24454         }
24455  
24456 @@ -1116,6 +1124,8 @@ static int inet_gifconf(struct net_devic
24457                 goto out;
24458  
24459         for (ifa = in_dev->ifa_list; ifa; ifa = ifa->ifa_next) {
24460 +               if (!nx_v4_ifa_visible(current_nx_info(), ifa))
24461 +                       continue;
24462                 if (!buf) {
24463                         done += sizeof(ifr);
24464                         continue;
24465 @@ -1519,6 +1529,7 @@ static int inet_dump_ifaddr(struct sk_bu
24466         struct net_device *dev;
24467         struct in_device *in_dev;
24468         struct in_ifaddr *ifa;
24469 +       struct sock *sk = skb->sk;
24470         struct hlist_head *head;
24471  
24472         s_h = cb->args[0];
24473 @@ -1540,6 +1551,8 @@ static int inet_dump_ifaddr(struct sk_bu
24474  
24475                         for (ifa = in_dev->ifa_list, ip_idx = 0; ifa;
24476                              ifa = ifa->ifa_next, ip_idx++) {
24477 +                       if (sk && !nx_v4_ifa_visible(sk->sk_nx_info, ifa))
24478 +                               continue;
24479                                 if (ip_idx < s_ip_idx)
24480                                         continue;
24481                                 if (inet_fill_ifaddr(skb, ifa,
24482 diff -NurpP --minimal linux-3.9.4/net/ipv4/fib_trie.c linux-3.9.4-vs2.3.6.2/net/ipv4/fib_trie.c
24483 --- linux-3.9.4/net/ipv4/fib_trie.c     2013-05-31 13:45:32.000000000 +0000
24484 +++ linux-3.9.4-vs2.3.6.2/net/ipv4/fib_trie.c   2013-05-31 17:17:54.000000000 +0000
24485 @@ -2548,6 +2548,7 @@ static int fib_route_seq_show(struct seq
24486                             || fa->fa_type == RTN_MULTICAST)
24487                                 continue;
24488  
24489 +                       /* FIXME: check for network context? */
24490                         if (fi)
24491                                 seq_printf(seq,
24492                                          "%s\t%08X\t%08X\t%04X\t%d\t%u\t"
24493 diff -NurpP --minimal linux-3.9.4/net/ipv4/inet_connection_sock.c linux-3.9.4-vs2.3.6.2/net/ipv4/inet_connection_sock.c
24494 --- linux-3.9.4/net/ipv4/inet_connection_sock.c 2013-05-31 13:45:32.000000000 +0000
24495 +++ linux-3.9.4-vs2.3.6.2/net/ipv4/inet_connection_sock.c       2013-05-31 18:29:56.000000000 +0000
24496 @@ -53,6 +53,37 @@ void inet_get_local_port_range(int *low,
24497  }
24498  EXPORT_SYMBOL(inet_get_local_port_range);
24499  
24500 +int ipv4_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2)
24501 +{
24502 +       __be32  sk1_rcv_saddr = sk_rcv_saddr(sk1),
24503 +               sk2_rcv_saddr = sk_rcv_saddr(sk2);
24504 +
24505 +       if (inet_v6_ipv6only(sk2))
24506 +               return 0;
24507 +
24508 +       if (sk1_rcv_saddr &&
24509 +           sk2_rcv_saddr &&
24510 +           sk1_rcv_saddr == sk2_rcv_saddr)
24511 +               return 1;
24512 +
24513 +       if (sk1_rcv_saddr &&
24514 +           !sk2_rcv_saddr &&
24515 +           v4_addr_in_nx_info(sk2->sk_nx_info, sk1_rcv_saddr, NXA_MASK_BIND))
24516 +               return 1;
24517 +
24518 +       if (sk2_rcv_saddr &&
24519 +           !sk1_rcv_saddr &&
24520 +           v4_addr_in_nx_info(sk1->sk_nx_info, sk2_rcv_saddr, NXA_MASK_BIND))
24521 +               return 1;
24522 +
24523 +       if (!sk1_rcv_saddr &&
24524 +           !sk2_rcv_saddr &&
24525 +           nx_v4_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info))
24526 +               return 1;
24527 +
24528 +       return 0;
24529 +}
24530 +
24531  int inet_csk_bind_conflict(const struct sock *sk,
24532                            const struct inet_bind_bucket *tb, bool relax)
24533  {
24534 @@ -79,17 +110,12 @@ int inet_csk_bind_conflict(const struct
24535                             (!reuseport || !sk2->sk_reuseport ||
24536                             (sk2->sk_state != TCP_TIME_WAIT &&
24537                              !uid_eq(uid, sock_i_uid(sk2))))) {
24538 -                               const __be32 sk2_rcv_saddr = sk_rcv_saddr(sk2);
24539 -                               if (!sk2_rcv_saddr || !sk_rcv_saddr(sk) ||
24540 -                                   sk2_rcv_saddr == sk_rcv_saddr(sk))
24541 +                               if (ipv4_rcv_saddr_equal(sk, sk2))
24542                                         break;
24543                         }
24544                         if (!relax && reuse && sk2->sk_reuse &&
24545                             sk2->sk_state != TCP_LISTEN) {
24546 -                               const __be32 sk2_rcv_saddr = sk_rcv_saddr(sk2);
24547 -
24548 -                               if (!sk2_rcv_saddr || !sk_rcv_saddr(sk) ||
24549 -                                   sk2_rcv_saddr == sk_rcv_saddr(sk))
24550 +                               if (ipv4_rcv_saddr_equal(sk, sk2))
24551                                         break;
24552                         }
24553                 }
24554 diff -NurpP --minimal linux-3.9.4/net/ipv4/inet_diag.c linux-3.9.4-vs2.3.6.2/net/ipv4/inet_diag.c
24555 --- linux-3.9.4/net/ipv4/inet_diag.c    2013-02-19 13:58:58.000000000 +0000
24556 +++ linux-3.9.4-vs2.3.6.2/net/ipv4/inet_diag.c  2013-05-31 17:17:54.000000000 +0000
24557 @@ -31,6 +31,8 @@
24558  
24559  #include <linux/inet.h>
24560  #include <linux/stddef.h>
24561 +#include <linux/vs_network.h>
24562 +#include <linux/vs_inet.h>
24563  
24564  #include <linux/inet_diag.h>
24565  #include <linux/sock_diag.h>
24566 @@ -106,8 +108,10 @@ int inet_sk_diag_fill(struct sock *sk, s
24567  
24568         r->id.idiag_sport = inet->inet_sport;
24569         r->id.idiag_dport = inet->inet_dport;
24570 -       r->id.idiag_src[0] = inet->inet_rcv_saddr;
24571 -       r->id.idiag_dst[0] = inet->inet_daddr;
24572 +       r->id.idiag_src[0] = nx_map_sock_lback(sk->sk_nx_info,
24573 +               inet->inet_rcv_saddr);
24574 +       r->id.idiag_dst[0] = nx_map_sock_lback(sk->sk_nx_info,
24575 +               inet->inet_daddr);
24576  
24577         if (nla_put_u8(skb, INET_DIAG_SHUTDOWN, sk->sk_shutdown))
24578                 goto errout;
24579 @@ -242,8 +246,8 @@ static int inet_twsk_diag_fill(struct in
24580         sock_diag_save_cookie(tw, r->id.idiag_cookie);
24581         r->id.idiag_sport     = tw->tw_sport;
24582         r->id.idiag_dport     = tw->tw_dport;
24583 -       r->id.idiag_src[0]    = tw->tw_rcv_saddr;
24584 -       r->id.idiag_dst[0]    = tw->tw_daddr;
24585 +       r->id.idiag_src[0]    = nx_map_sock_lback(tw->tw_nx_info, tw->tw_rcv_saddr);
24586 +       r->id.idiag_dst[0]    = nx_map_sock_lback(tw->tw_nx_info, tw->tw_daddr);
24587         r->idiag_state        = tw->tw_substate;
24588         r->idiag_timer        = 3;
24589         r->idiag_expires      = DIV_ROUND_UP(tmo * 1000, HZ);
24590 @@ -287,12 +291,14 @@ int inet_diag_dump_one_icsk(struct inet_
24591  
24592         err = -EINVAL;
24593         if (req->sdiag_family == AF_INET) {
24594 +               /* TODO: lback */
24595                 sk = inet_lookup(net, hashinfo, req->id.idiag_dst[0],
24596                                  req->id.idiag_dport, req->id.idiag_src[0],
24597                                  req->id.idiag_sport, req->id.idiag_if);
24598         }
24599  #if IS_ENABLED(CONFIG_IPV6)
24600         else if (req->sdiag_family == AF_INET6) {
24601 +               /* TODO: lback */
24602                 sk = inet6_lookup(net, hashinfo,
24603                                   (struct in6_addr *)req->id.idiag_dst,
24604                                   req->id.idiag_dport,
24605 @@ -494,6 +500,7 @@ int inet_diag_bc_sk(const struct nlattr
24606         } else
24607  #endif
24608         {
24609 +                       /* TODO: lback */
24610                 entry.saddr = &inet->inet_rcv_saddr;
24611                 entry.daddr = &inet->inet_daddr;
24612         }
24613 @@ -652,6 +659,7 @@ static int inet_twsk_diag_dump(struct in
24614                 } else
24615  #endif
24616                 {
24617 +                       /* TODO: lback */
24618                         entry.saddr = &tw->tw_rcv_saddr;
24619                         entry.daddr = &tw->tw_daddr;
24620                 }
24621 @@ -730,8 +738,8 @@ static int inet_diag_fill_req(struct sk_
24622  
24623         r->id.idiag_sport = inet->inet_sport;
24624         r->id.idiag_dport = ireq->rmt_port;
24625 -       r->id.idiag_src[0] = ireq->loc_addr;
24626 -       r->id.idiag_dst[0] = ireq->rmt_addr;
24627 +       r->id.idiag_src[0] = nx_map_sock_lback(sk->sk_nx_info, ireq->loc_addr);
24628 +       r->id.idiag_dst[0] = nx_map_sock_lback(sk->sk_nx_info, ireq->rmt_addr);
24629         r->idiag_expires = jiffies_to_msecs(tmo);
24630         r->idiag_rqueue = 0;
24631         r->idiag_wqueue = 0;
24632 @@ -794,6 +802,7 @@ static int inet_diag_dump_reqs(struct sk
24633                             r->id.idiag_dport)
24634                                 continue;
24635  
24636 +                       /* TODO: lback */
24637                         if (bc) {
24638                                 inet_diag_req_addrs(sk, req, &entry);
24639                                 entry.dport = ntohs(ireq->rmt_port);
24640 @@ -850,6 +859,8 @@ void inet_diag_dump_icsk(struct inet_has
24641                                 if (!net_eq(sock_net(sk), net))
24642                                         continue;
24643  
24644 +                               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
24645 +                                       continue;
24646                                 if (num < s_num) {
24647                                         num++;
24648                                         continue;
24649 @@ -922,6 +933,8 @@ skip_listen_ht:
24650  
24651                         if (!net_eq(sock_net(sk), net))
24652                                 continue;
24653 +                       if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
24654 +                               continue;
24655                         if (num < s_num)
24656                                 goto next_normal;
24657                         if (!(r->idiag_states & (1 << sk->sk_state)))
24658 @@ -950,7 +963,8 @@ next_normal:
24659                                     &head->twchain) {
24660                                 if (!net_eq(twsk_net(tw), net))
24661                                         continue;
24662 -
24663 +                               if (!nx_check(tw->tw_nid, VS_WATCH_P | VS_IDENT))
24664 +                                       continue;
24665                                 if (num < s_num)
24666                                         goto next_dying;
24667                                 if (r->sdiag_family != AF_UNSPEC &&
24668 diff -NurpP --minimal linux-3.9.4/net/ipv4/inet_hashtables.c linux-3.9.4-vs2.3.6.2/net/ipv4/inet_hashtables.c
24669 --- linux-3.9.4/net/ipv4/inet_hashtables.c      2013-05-31 13:45:32.000000000 +0000
24670 +++ linux-3.9.4-vs2.3.6.2/net/ipv4/inet_hashtables.c    2013-05-31 18:20:50.000000000 +0000
24671 @@ -22,6 +22,7 @@
24672  #include <net/inet_connection_sock.h>
24673  #include <net/inet_hashtables.h>
24674  #include <net/secure_seq.h>
24675 +#include <net/route.h>
24676  #include <net/ip.h>
24677  
24678  /*
24679 @@ -156,6 +157,11 @@ static inline int compute_score(struct s
24680                         if (rcv_saddr != daddr)
24681                                 return -1;
24682                         score += 4;
24683 +               } else {
24684 +                       /* block non nx_info ips */
24685 +                       if (!v4_addr_in_nx_info(sk->sk_nx_info,
24686 +                               daddr, NXA_MASK_BIND))
24687 +                               return -1;
24688                 }
24689                 if (sk->sk_bound_dev_if) {
24690                         if (sk->sk_bound_dev_if != dif)
24691 @@ -173,7 +179,6 @@ static inline int compute_score(struct s
24692   * wildcarded during the search since they can never be otherwise.
24693   */
24694  
24695 -
24696  struct sock *__inet_lookup_listener(struct net *net,
24697                                     struct inet_hashinfo *hashinfo,
24698                                     const __be32 saddr, __be16 sport,
24699 @@ -209,6 +214,7 @@ begin:
24700                         phash = next_pseudo_random32(phash);
24701                 }
24702         }
24703 +
24704         /*
24705          * if the nulls value we got at the end of this lookup is
24706          * not the expected one, we must restart lookup.
24707 diff -NurpP --minimal linux-3.9.4/net/ipv4/netfilter.c linux-3.9.4-vs2.3.6.2/net/ipv4/netfilter.c
24708 --- linux-3.9.4/net/ipv4/netfilter.c    2012-12-11 03:30:57.000000000 +0000
24709 +++ linux-3.9.4-vs2.3.6.2/net/ipv4/netfilter.c  2013-05-31 17:17:54.000000000 +0000
24710 @@ -6,7 +6,7 @@
24711  #include <linux/skbuff.h>
24712  #include <linux/gfp.h>
24713  #include <linux/export.h>
24714 -#include <net/route.h>
24715 +// #include <net/route.h>
24716  #include <net/xfrm.h>
24717  #include <net/ip.h>
24718  #include <net/netfilter/nf_queue.h>
24719 diff -NurpP --minimal linux-3.9.4/net/ipv4/raw.c linux-3.9.4-vs2.3.6.2/net/ipv4/raw.c
24720 --- linux-3.9.4/net/ipv4/raw.c  2013-05-31 13:45:32.000000000 +0000
24721 +++ linux-3.9.4-vs2.3.6.2/net/ipv4/raw.c        2013-05-31 18:19:38.000000000 +0000
24722 @@ -116,7 +116,7 @@ static struct sock *__raw_v4_lookup(stru
24723  
24724                 if (net_eq(sock_net(sk), net) && inet->inet_num == num  &&
24725                     !(inet->inet_daddr && inet->inet_daddr != raddr)    &&
24726 -                   !(inet->inet_rcv_saddr && inet->inet_rcv_saddr != laddr) &&
24727 +                   v4_sock_addr_match(sk->sk_nx_info, inet, laddr)     &&
24728                     !(sk->sk_bound_dev_if && sk->sk_bound_dev_if != dif))
24729                         goto found; /* gotcha */
24730         }
24731 @@ -395,6 +395,12 @@ static int raw_send_hdrinc(struct sock *
24732                 icmp_out_count(net, ((struct icmphdr *)
24733                         skb_transport_header(skb))->type);
24734  
24735 +       err = -EPERM;
24736 +       if (!nx_check(0, VS_ADMIN) && !capable(CAP_NET_RAW) &&
24737 +               sk->sk_nx_info &&
24738 +               !v4_addr_in_nx_info(sk->sk_nx_info, iph->saddr, NXA_MASK_BIND))
24739 +               goto error_free;
24740 +
24741         err = NF_HOOK(NFPROTO_IPV4, NF_INET_LOCAL_OUT, skb, NULL,
24742                       rt->dst.dev, dst_output);
24743         if (err > 0)
24744 @@ -580,6 +586,16 @@ static int raw_sendmsg(struct kiocb *ioc
24745                         goto done;
24746         }
24747  
24748 +       if (sk->sk_nx_info) {
24749 +               rt = ip_v4_find_src(sock_net(sk), sk->sk_nx_info, &fl4);
24750 +               if (IS_ERR(rt)) {
24751 +                       err = PTR_ERR(rt);
24752 +                       rt = NULL;
24753 +                       goto done;
24754 +               }
24755 +               ip_rt_put(rt);
24756 +       }
24757 +
24758         security_sk_classify_flow(sk, flowi4_to_flowi(&fl4));
24759         rt = ip_route_output_flow(sock_net(sk), &fl4, sk);
24760         if (IS_ERR(rt)) {
24761 @@ -656,17 +672,19 @@ static int raw_bind(struct sock *sk, str
24762  {
24763         struct inet_sock *inet = inet_sk(sk);
24764         struct sockaddr_in *addr = (struct sockaddr_in *) uaddr;
24765 +       struct nx_v4_sock_addr nsa = { 0 };
24766         int ret = -EINVAL;
24767         int chk_addr_ret;
24768  
24769         if (sk->sk_state != TCP_CLOSE || addr_len < sizeof(struct sockaddr_in))
24770                 goto out;
24771 -       chk_addr_ret = inet_addr_type(sock_net(sk), addr->sin_addr.s_addr);
24772 +       v4_map_sock_addr(inet, addr, &nsa);
24773 +       chk_addr_ret = inet_addr_type(sock_net(sk), nsa.saddr);
24774         ret = -EADDRNOTAVAIL;
24775 -       if (addr->sin_addr.s_addr && chk_addr_ret != RTN_LOCAL &&
24776 +       if (nsa.saddr && chk_addr_ret != RTN_LOCAL &&
24777             chk_addr_ret != RTN_MULTICAST && chk_addr_ret != RTN_BROADCAST)
24778                 goto out;
24779 -       inet->inet_rcv_saddr = inet->inet_saddr = addr->sin_addr.s_addr;
24780 +       v4_set_sock_addr(inet, &nsa);
24781         if (chk_addr_ret == RTN_MULTICAST || chk_addr_ret == RTN_BROADCAST)
24782                 inet->inet_saddr = 0;  /* Use device */
24783         sk_dst_reset(sk);
24784 @@ -718,7 +736,8 @@ static int raw_recvmsg(struct kiocb *ioc
24785         /* Copy the address. */
24786         if (sin) {
24787                 sin->sin_family = AF_INET;
24788 -               sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
24789 +               sin->sin_addr.s_addr =
24790 +                       nx_map_sock_lback(sk->sk_nx_info, ip_hdr(skb)->saddr);
24791                 sin->sin_port = 0;
24792                 memset(&sin->sin_zero, 0, sizeof(sin->sin_zero));
24793         }
24794 @@ -913,7 +932,8 @@ static struct sock *raw_get_first(struct
24795         for (state->bucket = 0; state->bucket < RAW_HTABLE_SIZE;
24796                         ++state->bucket) {
24797                 sk_for_each(sk, &state->h->ht[state->bucket])
24798 -                       if (sock_net(sk) == seq_file_net(seq))
24799 +                       if ((sock_net(sk) == seq_file_net(seq)) &&
24800 +                           nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
24801                                 goto found;
24802         }
24803         sk = NULL;
24804 @@ -929,7 +949,8 @@ static struct sock *raw_get_next(struct
24805                 sk = sk_next(sk);
24806  try_again:
24807                 ;
24808 -       } while (sk && sock_net(sk) != seq_file_net(seq));
24809 +       } while (sk && ((sock_net(sk) != seq_file_net(seq)) ||
24810 +               !nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT)));
24811  
24812         if (!sk && ++state->bucket < RAW_HTABLE_SIZE) {
24813                 sk = sk_head(&state->h->ht[state->bucket]);
24814 diff -NurpP --minimal linux-3.9.4/net/ipv4/route.c linux-3.9.4-vs2.3.6.2/net/ipv4/route.c
24815 --- linux-3.9.4/net/ipv4/route.c        2013-05-31 13:45:32.000000000 +0000
24816 +++ linux-3.9.4-vs2.3.6.2/net/ipv4/route.c      2013-05-31 17:17:54.000000000 +0000
24817 @@ -1998,7 +1998,7 @@ struct rtable *__ip_route_output_key(str
24818  
24819  
24820         if (fl4->flowi4_oif) {
24821 -               dev_out = dev_get_by_index_rcu(net, fl4->flowi4_oif);
24822 +               dev_out = dev_get_by_index_real_rcu(net, fl4->flowi4_oif);
24823                 rth = ERR_PTR(-ENODEV);
24824                 if (dev_out == NULL)
24825                         goto out;
24826 diff -NurpP --minimal linux-3.9.4/net/ipv4/tcp.c linux-3.9.4-vs2.3.6.2/net/ipv4/tcp.c
24827 --- linux-3.9.4/net/ipv4/tcp.c  2013-05-31 13:45:32.000000000 +0000
24828 +++ linux-3.9.4-vs2.3.6.2/net/ipv4/tcp.c        2013-05-31 17:17:54.000000000 +0000
24829 @@ -268,6 +268,7 @@
24830  #include <linux/crypto.h>
24831  #include <linux/time.h>
24832  #include <linux/slab.h>
24833 +#include <linux/in.h>
24834  
24835  #include <net/icmp.h>
24836  #include <net/inet_common.h>
24837 diff -NurpP --minimal linux-3.9.4/net/ipv4/tcp_ipv4.c linux-3.9.4-vs2.3.6.2/net/ipv4/tcp_ipv4.c
24838 --- linux-3.9.4/net/ipv4/tcp_ipv4.c     2013-05-31 13:45:32.000000000 +0000
24839 +++ linux-3.9.4-vs2.3.6.2/net/ipv4/tcp_ipv4.c   2013-05-31 17:17:54.000000000 +0000
24840 @@ -2260,6 +2260,12 @@ static void *listening_get_next(struct s
24841                 req = req->dl_next;
24842                 while (1) {
24843                         while (req) {
24844 +                               vxdprintk(VXD_CBIT(net, 6),
24845 +                                       "sk,req: %p [#%d] (from %d)", req->sk,
24846 +                                       (req->sk)?req->sk->sk_nid:0, nx_current_nid());
24847 +                               if (req->sk &&
24848 +                                       !nx_check(req->sk->sk_nid, VS_WATCH_P | VS_IDENT))
24849 +                                       continue;
24850                                 if (req->rsk_ops->family == st->family) {
24851                                         cur = req;
24852                                         goto out;
24853 @@ -2284,6 +2290,10 @@ get_req:
24854         }
24855  get_sk:
24856         sk_nulls_for_each_from(sk, node) {
24857 +               vxdprintk(VXD_CBIT(net, 6), "sk: %p [#%d] (from %d)",
24858 +                       sk, sk->sk_nid, nx_current_nid());
24859 +               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
24860 +                       continue;
24861                 if (!net_eq(sock_net(sk), net))
24862                         continue;
24863                 if (sk->sk_family == st->family) {
24864 @@ -2360,6 +2370,11 @@ static void *established_get_first(struc
24865  
24866                 spin_lock_bh(lock);
24867                 sk_nulls_for_each(sk, node, &tcp_hashinfo.ehash[st->bucket].chain) {
24868 +                       vxdprintk(VXD_CBIT(net, 6),
24869 +                               "sk,egf: %p [#%d] (from %d)",
24870 +                               sk, sk->sk_nid, nx_current_nid());
24871 +                       if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
24872 +                               continue;
24873                         if (sk->sk_family != st->family ||
24874                             !net_eq(sock_net(sk), net)) {
24875                                 continue;
24876 @@ -2370,6 +2385,11 @@ static void *established_get_first(struc
24877                 st->state = TCP_SEQ_STATE_TIME_WAIT;
24878                 inet_twsk_for_each(tw, node,
24879                                    &tcp_hashinfo.ehash[st->bucket].twchain) {
24880 +                       vxdprintk(VXD_CBIT(net, 6),
24881 +                               "tw: %p [#%d] (from %d)",
24882 +                               tw, tw->tw_nid, nx_current_nid());
24883 +                       if (!nx_check(tw->tw_nid, VS_WATCH_P | VS_IDENT))
24884 +                               continue;
24885                         if (tw->tw_family != st->family ||
24886                             !net_eq(twsk_net(tw), net)) {
24887                                 continue;
24888 @@ -2399,7 +2419,9 @@ static void *established_get_next(struct
24889                 tw = cur;
24890                 tw = tw_next(tw);
24891  get_tw:
24892 -               while (tw && (tw->tw_family != st->family || !net_eq(twsk_net(tw), net))) {
24893 +               while (tw && (tw->tw_family != st->family ||
24894 +                       !net_eq(twsk_net(tw), net) ||
24895 +                       !nx_check(tw->tw_nid, VS_WATCH_P | VS_IDENT))) {
24896                         tw = tw_next(tw);
24897                 }
24898                 if (tw) {
24899 @@ -2423,6 +2445,11 @@ get_tw:
24900                 sk = sk_nulls_next(sk);
24901  
24902         sk_nulls_for_each_from(sk, node) {
24903 +               vxdprintk(VXD_CBIT(net, 6),
24904 +                       "sk,egn: %p [#%d] (from %d)",
24905 +                       sk, sk->sk_nid, nx_current_nid());
24906 +               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
24907 +                       continue;
24908                 if (sk->sk_family == st->family && net_eq(sock_net(sk), net))
24909                         goto found;
24910         }
24911 @@ -2628,9 +2655,9 @@ static void get_openreq4(const struct so
24912         seq_printf(f, "%4d: %08X:%04X %08X:%04X"
24913                 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %u %d %pK%n",
24914                 i,
24915 -               ireq->loc_addr,
24916 +               nx_map_sock_lback(current_nx_info(), ireq->loc_addr),
24917                 ntohs(inet_sk(sk)->inet_sport),
24918 -               ireq->rmt_addr,
24919 +               nx_map_sock_lback(current_nx_info(), ireq->rmt_addr),
24920                 ntohs(ireq->rmt_port),
24921                 TCP_SYN_RECV,
24922                 0, 0, /* could print option size, but that is af dependent. */
24923 @@ -2653,8 +2680,8 @@ static void get_tcp4_sock(struct sock *s
24924         const struct inet_connection_sock *icsk = inet_csk(sk);
24925         const struct inet_sock *inet = inet_sk(sk);
24926         struct fastopen_queue *fastopenq = icsk->icsk_accept_queue.fastopenq;
24927 -       __be32 dest = inet->inet_daddr;
24928 -       __be32 src = inet->inet_rcv_saddr;
24929 +       __be32 dest = nx_map_sock_lback(current_nx_info(), inet->inet_daddr);
24930 +       __be32 src = nx_map_sock_lback(current_nx_info(), inet->inet_rcv_saddr);
24931         __u16 destp = ntohs(inet->inet_dport);
24932         __u16 srcp = ntohs(inet->inet_sport);
24933         int rx_queue;
24934 @@ -2710,8 +2737,8 @@ static void get_timewait4_sock(const str
24935         __u16 destp, srcp;
24936         long delta = tw->tw_ttd - jiffies;
24937  
24938 -       dest  = tw->tw_daddr;
24939 -       src   = tw->tw_rcv_saddr;
24940 +       dest  = nx_map_sock_lback(current_nx_info(), tw->tw_daddr);
24941 +       src   = nx_map_sock_lback(current_nx_info(), tw->tw_rcv_saddr);
24942         destp = ntohs(tw->tw_dport);
24943         srcp  = ntohs(tw->tw_sport);
24944  
24945 diff -NurpP --minimal linux-3.9.4/net/ipv4/tcp_minisocks.c linux-3.9.4-vs2.3.6.2/net/ipv4/tcp_minisocks.c
24946 --- linux-3.9.4/net/ipv4/tcp_minisocks.c        2013-05-31 14:22:27.000000000 +0000
24947 +++ linux-3.9.4-vs2.3.6.2/net/ipv4/tcp_minisocks.c      2013-05-31 17:17:54.000000000 +0000
24948 @@ -23,6 +23,9 @@
24949  #include <linux/slab.h>
24950  #include <linux/sysctl.h>
24951  #include <linux/workqueue.h>
24952 +#include <linux/vs_limit.h>
24953 +#include <linux/vs_socket.h>
24954 +#include <linux/vs_context.h>
24955  #include <net/tcp.h>
24956  #include <net/inet_common.h>
24957  #include <net/xfrm.h>
24958 @@ -291,6 +294,11 @@ void tcp_time_wait(struct sock *sk, int
24959                 tcptw->tw_ts_recent_stamp = tp->rx_opt.ts_recent_stamp;
24960                 tcptw->tw_ts_offset     = tp->tsoffset;
24961  
24962 +               tw->tw_xid              = sk->sk_xid;
24963 +               tw->tw_vx_info          = NULL;
24964 +               tw->tw_nid              = sk->sk_nid;
24965 +               tw->tw_nx_info          = NULL;
24966 +
24967  #if IS_ENABLED(CONFIG_IPV6)
24968                 if (tw->tw_family == PF_INET6) {
24969                         struct ipv6_pinfo *np = inet6_sk(sk);
24970 diff -NurpP --minimal linux-3.9.4/net/ipv4/udp.c linux-3.9.4-vs2.3.6.2/net/ipv4/udp.c
24971 --- linux-3.9.4/net/ipv4/udp.c  2013-05-31 13:45:32.000000000 +0000
24972 +++ linux-3.9.4-vs2.3.6.2/net/ipv4/udp.c        2013-05-31 18:26:00.000000000 +0000
24973 @@ -306,14 +306,7 @@ fail:
24974  }
24975  EXPORT_SYMBOL(udp_lib_get_port);
24976  
24977 -static int ipv4_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2)
24978 -{
24979 -       struct inet_sock *inet1 = inet_sk(sk1), *inet2 = inet_sk(sk2);
24980 -
24981 -       return  (!ipv6_only_sock(sk2)  &&
24982 -                (!inet1->inet_rcv_saddr || !inet2->inet_rcv_saddr ||
24983 -                  inet1->inet_rcv_saddr == inet2->inet_rcv_saddr));
24984 -}
24985 +extern int ipv4_rcv_saddr_equal(const struct sock *, const struct sock *);
24986  
24987  static unsigned int udp4_portaddr_hash(struct net *net, __be32 saddr,
24988                                        unsigned int port)
24989 @@ -348,6 +341,11 @@ static inline int compute_score(struct s
24990                         if (inet->inet_rcv_saddr != daddr)
24991                                 return -1;
24992                         score += 4;
24993 +               } else {
24994 +                       /* block non nx_info ips */
24995 +                       if (!v4_addr_in_nx_info(sk->sk_nx_info,
24996 +                               daddr, NXA_MASK_BIND))
24997 +                               return -1;
24998                 }
24999                 if (inet->inet_daddr) {
25000                         if (inet->inet_daddr != saddr)
25001 @@ -458,6 +456,7 @@ begin:
25002         return result;
25003  }
25004  
25005 +
25006  /* UDP is nearly always wildcards out the wazoo, it makes no sense to try
25007   * harder than this. -DaveM
25008   */
25009 @@ -504,6 +503,11 @@ begin:
25010         sk_nulls_for_each_rcu(sk, node, &hslot->head) {
25011                 score = compute_score(sk, net, saddr, hnum, sport,
25012                                       daddr, dport, dif);
25013 +               /* FIXME: disabled?
25014 +               if (score == 9) {
25015 +                       result = sk;
25016 +                       break;
25017 +               } else */
25018                 if (score > badness) {
25019                         result = sk;
25020                         badness = score;
25021 @@ -528,6 +532,7 @@ begin:
25022         if (get_nulls_value(node) != slot)
25023                 goto begin;
25024  
25025 +
25026         if (result) {
25027                 if (unlikely(!atomic_inc_not_zero_hint(&result->sk_refcnt, 2)))
25028                         result = NULL;
25029 @@ -537,6 +542,7 @@ begin:
25030                         goto begin;
25031                 }
25032         }
25033 +
25034         rcu_read_unlock();
25035         return result;
25036  }
25037 @@ -580,8 +586,7 @@ static inline struct sock *udp_v4_mcast_
25038                     udp_sk(s)->udp_port_hash != hnum ||
25039                     (inet->inet_daddr && inet->inet_daddr != rmt_addr) ||
25040                     (inet->inet_dport != rmt_port && inet->inet_dport) ||
25041 -                   (inet->inet_rcv_saddr &&
25042 -                    inet->inet_rcv_saddr != loc_addr) ||
25043 +                   !v4_sock_addr_match(sk->sk_nx_info, inet, loc_addr) ||
25044                     ipv6_only_sock(s) ||
25045                     (s->sk_bound_dev_if && s->sk_bound_dev_if != dif))
25046                         continue;
25047 @@ -964,6 +969,16 @@ int udp_sendmsg(struct kiocb *iocb, stru
25048                                    inet_sk_flowi_flags(sk)|FLOWI_FLAG_CAN_SLEEP,
25049                                    faddr, saddr, dport, inet->inet_sport);
25050  
25051 +               if (sk->sk_nx_info) {
25052 +                       rt = ip_v4_find_src(net, sk->sk_nx_info, fl4);
25053 +                       if (IS_ERR(rt)) {
25054 +                               err = PTR_ERR(rt);
25055 +                               rt = NULL;
25056 +                               goto out;
25057 +                       }
25058 +                       ip_rt_put(rt);
25059 +               }
25060 +
25061                 security_sk_classify_flow(sk, flowi4_to_flowi(fl4));
25062                 rt = ip_route_output_flow(net, fl4, sk);
25063                 if (IS_ERR(rt)) {
25064 @@ -1269,7 +1284,8 @@ try_again:
25065         if (sin) {
25066                 sin->sin_family = AF_INET;
25067                 sin->sin_port = udp_hdr(skb)->source;
25068 -               sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
25069 +               sin->sin_addr.s_addr = nx_map_sock_lback(
25070 +                       skb->sk->sk_nx_info, ip_hdr(skb)->saddr);
25071                 memset(sin->sin_zero, 0, sizeof(sin->sin_zero));
25072         }
25073         if (inet->cmsg_flags)
25074 @@ -2025,6 +2041,8 @@ static struct sock *udp_get_first(struct
25075                 sk_nulls_for_each(sk, node, &hslot->head) {
25076                         if (!net_eq(sock_net(sk), net))
25077                                 continue;
25078 +                       if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
25079 +                               continue;
25080                         if (sk->sk_family == state->family)
25081                                 goto found;
25082                 }
25083 @@ -2042,7 +2060,9 @@ static struct sock *udp_get_next(struct
25084  
25085         do {
25086                 sk = sk_nulls_next(sk);
25087 -       } while (sk && (!net_eq(sock_net(sk), net) || sk->sk_family != state->family));
25088 +       } while (sk && (!net_eq(sock_net(sk), net) ||
25089 +               sk->sk_family != state->family ||
25090 +               !nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT)));
25091  
25092         if (!sk) {
25093                 if (state->bucket <= state->udp_table->mask)
25094 @@ -2138,8 +2158,8 @@ static void udp4_format_sock(struct sock
25095                 int bucket, int *len)
25096  {
25097         struct inet_sock *inet = inet_sk(sp);
25098 -       __be32 dest = inet->inet_daddr;
25099 -       __be32 src  = inet->inet_rcv_saddr;
25100 +       __be32 dest = nx_map_sock_lback(current_nx_info(), inet->inet_daddr);
25101 +       __be32 src = nx_map_sock_lback(current_nx_info(), inet->inet_rcv_saddr);
25102         __u16 destp       = ntohs(inet->inet_dport);
25103         __u16 srcp        = ntohs(inet->inet_sport);
25104  
25105 diff -NurpP --minimal linux-3.9.4/net/ipv6/Kconfig linux-3.9.4-vs2.3.6.2/net/ipv6/Kconfig
25106 --- linux-3.9.4/net/ipv6/Kconfig        2013-05-31 13:45:32.000000000 +0000
25107 +++ linux-3.9.4-vs2.3.6.2/net/ipv6/Kconfig      2013-05-31 17:17:54.000000000 +0000
25108 @@ -4,8 +4,8 @@
25109  
25110  #   IPv6 as module will cause a CRASH if you try to unload it
25111  menuconfig IPV6
25112 -       tristate "The IPv6 protocol"
25113 -       default m
25114 +       bool "The IPv6 protocol"
25115 +       default n
25116         ---help---
25117           This is complemental support for the IP version 6.
25118           You will still be able to do traditional IPv4 networking as well.
25119 diff -NurpP --minimal linux-3.9.4/net/ipv6/addrconf.c linux-3.9.4-vs2.3.6.2/net/ipv6/addrconf.c
25120 --- linux-3.9.4/net/ipv6/addrconf.c     2013-05-31 13:45:32.000000000 +0000
25121 +++ linux-3.9.4-vs2.3.6.2/net/ipv6/addrconf.c   2013-05-31 20:07:39.000000000 +0000
25122 @@ -93,6 +93,8 @@
25123  #include <linux/proc_fs.h>
25124  #include <linux/seq_file.h>
25125  #include <linux/export.h>
25126 +#include <linux/vs_network.h>
25127 +#include <linux/vs_inet6.h>
25128  
25129  /* Set to 3 to get tracing... */
25130  #define ACONF_DEBUG 2
25131 @@ -1250,7 +1252,7 @@ out:
25132  
25133  int ipv6_dev_get_saddr(struct net *net, const struct net_device *dst_dev,
25134                        const struct in6_addr *daddr, unsigned int prefs,
25135 -                      struct in6_addr *saddr)
25136 +                      struct in6_addr *saddr, struct nx_info *nxi)
25137  {
25138         struct ipv6_saddr_score scores[2],
25139                                 *score = &scores[0], *hiscore = &scores[1];
25140 @@ -1322,6 +1324,8 @@ int ipv6_dev_get_saddr(struct net *net,
25141                                                dev->name);
25142                                 continue;
25143                         }
25144 +                       if (!v6_addr_in_nx_info(nxi, &score->ifa->addr, -1))
25145 +                               continue;
25146  
25147                         score->rule = -1;
25148                         bitmap_zero(score->scorebits, IPV6_SADDR_RULE_MAX);
25149 @@ -3311,7 +3315,10 @@ static void if6_seq_stop(struct seq_file
25150  static int if6_seq_show(struct seq_file *seq, void *v)
25151  {
25152         struct inet6_ifaddr *ifp = (struct inet6_ifaddr *)v;
25153 -       seq_printf(seq, "%pi6 %02x %02x %02x %02x %8s\n",
25154 +
25155 +       if (nx_check(0, VS_ADMIN|VS_WATCH) ||
25156 +           v6_addr_in_nx_info(current_nx_info(), &ifp->addr, -1))
25157 +               seq_printf(seq, "%pi6 %02x %02x %02x %02x %8s\n",
25158                    &ifp->addr,
25159                    ifp->idev->dev->ifindex,
25160                    ifp->prefix_len,
25161 @@ -3815,6 +3822,11 @@ static int in6_dump_addrs(struct inet6_d
25162         struct ifacaddr6 *ifaca;
25163         int err = 1;
25164         int ip_idx = *p_ip_idx;
25165 +       struct nx_info *nxi = skb->sk ? skb->sk->sk_nx_info : NULL;
25166 +
25167 +       /* disable ipv6 on non v6 guests */
25168 +       if (nxi && !nx_info_has_v6(nxi))
25169 +               return skb->len;
25170  
25171         read_lock_bh(&idev->lock);
25172         switch (type) {
25173 @@ -3825,6 +3837,8 @@ static int in6_dump_addrs(struct inet6_d
25174                 list_for_each_entry(ifa, &idev->addr_list, if_list) {
25175                         if (++ip_idx < s_ip_idx)
25176                                 continue;
25177 +                               if (!v6_addr_in_nx_info(nxi, &ifa->addr, -1))
25178 +                                       continue;
25179                         err = inet6_fill_ifaddr(skb, ifa,
25180                                                 NETLINK_CB(cb->skb).portid,
25181                                                 cb->nlh->nlmsg_seq,
25182 @@ -3841,6 +3855,8 @@ static int in6_dump_addrs(struct inet6_d
25183                      ifmca = ifmca->next, ip_idx++) {
25184                         if (ip_idx < s_ip_idx)
25185                                 continue;
25186 +                               if (!v6_addr_in_nx_info(nxi, &ifmca->mca_addr, -1))
25187 +                                       continue;
25188                         err = inet6_fill_ifmcaddr(skb, ifmca,
25189                                                   NETLINK_CB(cb->skb).portid,
25190                                                   cb->nlh->nlmsg_seq,
25191 @@ -3856,6 +3872,8 @@ static int in6_dump_addrs(struct inet6_d
25192                      ifaca = ifaca->aca_next, ip_idx++) {
25193                         if (ip_idx < s_ip_idx)
25194                                 continue;
25195 +                               if (!v6_addr_in_nx_info(nxi, &ifaca->aca_addr, -1))
25196 +                                       continue;
25197                         err = inet6_fill_ifacaddr(skb, ifaca,
25198                                                   NETLINK_CB(cb->skb).portid,
25199                                                   cb->nlh->nlmsg_seq,
25200 @@ -3884,6 +3902,10 @@ static int inet6_dump_addr(struct sk_buf
25201         struct inet6_dev *idev;
25202         struct hlist_head *head;
25203  
25204 +       /* FIXME: maybe disable ipv6 on non v6 guests?
25205 +       if (skb->sk && skb->sk->sk_vx_info)
25206 +               return skb->len; */
25207 +
25208         s_h = cb->args[0];
25209         s_idx = idx = cb->args[1];
25210         s_ip_idx = ip_idx = cb->args[2];
25211 @@ -4238,6 +4260,7 @@ static int inet6_dump_ifinfo(struct sk_b
25212         struct net_device *dev;
25213         struct inet6_dev *idev;
25214         struct hlist_head *head;
25215 +       struct nx_info *nxi = skb->sk ? skb->sk->sk_nx_info : NULL;
25216  
25217         s_h = cb->args[0];
25218         s_idx = cb->args[1];
25219 @@ -4249,6 +4272,8 @@ static int inet6_dump_ifinfo(struct sk_b
25220                 hlist_for_each_entry_rcu(dev, head, index_hlist) {
25221                         if (idx < s_idx)
25222                                 goto cont;
25223 +                       if (!v6_dev_in_nx_info(dev, nxi))
25224 +                               goto cont;
25225                         idev = __in6_dev_get(dev);
25226                         if (!idev)
25227                                 goto cont;
25228 diff -NurpP --minimal linux-3.9.4/net/ipv6/af_inet6.c linux-3.9.4-vs2.3.6.2/net/ipv6/af_inet6.c
25229 --- linux-3.9.4/net/ipv6/af_inet6.c     2013-05-31 13:45:32.000000000 +0000
25230 +++ linux-3.9.4-vs2.3.6.2/net/ipv6/af_inet6.c   2013-05-31 20:04:41.000000000 +0000
25231 @@ -43,6 +43,8 @@
25232  #include <linux/netdevice.h>
25233  #include <linux/icmpv6.h>
25234  #include <linux/netfilter_ipv6.h>
25235 +#include <linux/vs_inet.h>
25236 +#include <linux/vs_inet6.h>
25237  
25238  #include <net/ip.h>
25239  #include <net/ipv6.h>
25240 @@ -160,10 +162,13 @@ lookup_protocol:
25241         }
25242  
25243         err = -EPERM;
25244 +       if ((protocol == IPPROTO_ICMPV6) &&
25245 +               nx_capable(CAP_NET_RAW, NXC_RAW_ICMP))
25246 +               goto override;
25247         if (sock->type == SOCK_RAW && !kern &&
25248             !ns_capable(net->user_ns, CAP_NET_RAW))
25249                 goto out_rcu_unlock;
25250 -
25251 +override:
25252         sock->ops = answer->ops;
25253         answer_prot = answer->prot;
25254         answer_no_check = answer->no_check;
25255 @@ -263,6 +268,7 @@ int inet6_bind(struct socket *sock, stru
25256         struct inet_sock *inet = inet_sk(sk);
25257         struct ipv6_pinfo *np = inet6_sk(sk);
25258         struct net *net = sock_net(sk);
25259 +       struct nx_v6_sock_addr nsa;
25260         __be32 v4addr = 0;
25261         unsigned short snum;
25262         int addr_type = 0;
25263 @@ -278,6 +284,10 @@ int inet6_bind(struct socket *sock, stru
25264         if (addr->sin6_family != AF_INET6)
25265                 return -EAFNOSUPPORT;
25266  
25267 +       err = v6_map_sock_addr(inet, addr, &nsa);
25268 +       if (err)
25269 +               return err;
25270 +
25271         addr_type = ipv6_addr_type(&addr->sin6_addr);
25272         if ((addr_type & IPV6_ADDR_MULTICAST) && sock->type == SOCK_STREAM)
25273                 return -EINVAL;
25274 @@ -309,6 +319,7 @@ int inet6_bind(struct socket *sock, stru
25275                 /* Reproduce AF_INET checks to make the bindings consistent */
25276                 v4addr = addr->sin6_addr.s6_addr32[3];
25277                 chk_addr_ret = inet_addr_type(net, v4addr);
25278 +
25279                 if (!sysctl_ip_nonlocal_bind &&
25280                     !(inet->freebind || inet->transparent) &&
25281                     v4addr != htonl(INADDR_ANY) &&
25282 @@ -318,6 +329,10 @@ int inet6_bind(struct socket *sock, stru
25283                         err = -EADDRNOTAVAIL;
25284                         goto out;
25285                 }
25286 +               if (!v4_addr_in_nx_info(sk->sk_nx_info, v4addr, NXA_MASK_BIND)) {
25287 +                       err = -EADDRNOTAVAIL;
25288 +                       goto out;
25289 +               }
25290         } else {
25291                 if (addr_type != IPV6_ADDR_ANY) {
25292                         struct net_device *dev = NULL;
25293 @@ -344,6 +359,11 @@ int inet6_bind(struct socket *sock, stru
25294                                 }
25295                         }
25296  
25297 +                       if (!v6_addr_in_nx_info(sk->sk_nx_info, &addr->sin6_addr, -1)) {
25298 +                               err = -EADDRNOTAVAIL;
25299 +                               goto out_unlock;
25300 +                       }
25301 +
25302                         /* ipv4 addr of the socket is invalid.  Only the
25303                          * unspecified and mapped address have a v4 equivalent.
25304                          */
25305 @@ -360,6 +380,9 @@ int inet6_bind(struct socket *sock, stru
25306                 }
25307         }
25308  
25309 +       /* what's that for? */
25310 +       v6_set_sock_addr(inet, &nsa);
25311 +
25312         inet->inet_rcv_saddr = v4addr;
25313         inet->inet_saddr = v4addr;
25314  
25315 @@ -461,9 +484,11 @@ int inet6_getname(struct socket *sock, s
25316                         return -ENOTCONN;
25317                 sin->sin6_port = inet->inet_dport;
25318                 sin->sin6_addr = np->daddr;
25319 +               /* FIXME: remap lback? */
25320                 if (np->sndflow)
25321                         sin->sin6_flowinfo = np->flow_label;
25322         } else {
25323 +               /* FIXME: remap lback? */
25324                 if (ipv6_addr_any(&np->rcv_saddr))
25325                         sin->sin6_addr = np->saddr;
25326                 else
25327 diff -NurpP --minimal linux-3.9.4/net/ipv6/datagram.c linux-3.9.4-vs2.3.6.2/net/ipv6/datagram.c
25328 --- linux-3.9.4/net/ipv6/datagram.c     2013-05-31 13:45:32.000000000 +0000
25329 +++ linux-3.9.4-vs2.3.6.2/net/ipv6/datagram.c   2013-05-31 17:17:54.000000000 +0000
25330 @@ -648,7 +648,7 @@ int ip6_datagram_send_ctl(struct net *ne
25331  
25332                         rcu_read_lock();
25333                         if (fl6->flowi6_oif) {
25334 -                               dev = dev_get_by_index_rcu(net, fl6->flowi6_oif);
25335 +                               dev = dev_get_by_index_real_rcu(net, fl6->flowi6_oif);
25336                                 if (!dev) {
25337                                         rcu_read_unlock();
25338                                         return -ENODEV;
25339 diff -NurpP --minimal linux-3.9.4/net/ipv6/fib6_rules.c linux-3.9.4-vs2.3.6.2/net/ipv6/fib6_rules.c
25340 --- linux-3.9.4/net/ipv6/fib6_rules.c   2013-02-19 13:58:58.000000000 +0000
25341 +++ linux-3.9.4-vs2.3.6.2/net/ipv6/fib6_rules.c 2013-05-31 17:17:54.000000000 +0000
25342 @@ -90,7 +90,7 @@ static int fib6_rule_action(struct fib_r
25343                                                ip6_dst_idev(&rt->dst)->dev,
25344                                                &flp6->daddr,
25345                                                rt6_flags2srcprefs(flags),
25346 -                                              &saddr))
25347 +                                              &saddr, NULL))
25348                                 goto again;
25349                         if (!ipv6_prefix_equal(&saddr, &r->src.addr,
25350                                                r->src.plen))
25351 diff -NurpP --minimal linux-3.9.4/net/ipv6/inet6_hashtables.c linux-3.9.4-vs2.3.6.2/net/ipv6/inet6_hashtables.c
25352 --- linux-3.9.4/net/ipv6/inet6_hashtables.c     2013-05-31 13:45:32.000000000 +0000
25353 +++ linux-3.9.4-vs2.3.6.2/net/ipv6/inet6_hashtables.c   2013-05-31 17:17:54.000000000 +0000
25354 @@ -16,6 +16,7 @@
25355  
25356  #include <linux/module.h>
25357  #include <linux/random.h>
25358 +#include <linux/vs_inet6.h>
25359  
25360  #include <net/inet_connection_sock.h>
25361  #include <net/inet_hashtables.h>
25362 @@ -83,7 +84,6 @@ struct sock *__inet6_lookup_established(
25363         unsigned int slot = hash & hashinfo->ehash_mask;
25364         struct inet_ehash_bucket *head = &hashinfo->ehash[slot];
25365  
25366 -
25367         rcu_read_lock();
25368  begin:
25369         sk_nulls_for_each_rcu(sk, node, &head->chain) {
25370 @@ -97,7 +97,7 @@ begin:
25371                                 sock_put(sk);
25372                                 goto begin;
25373                         }
25374 -               goto out;
25375 +                       goto out;
25376                 }
25377         }
25378         if (get_nulls_value(node) != slot)
25379 @@ -147,6 +147,9 @@ static inline int compute_score(struct s
25380                         if (!ipv6_addr_equal(&np->rcv_saddr, daddr))
25381                                 return -1;
25382                         score++;
25383 +               } else {
25384 +                       if (!v6_addr_in_nx_info(sk->sk_nx_info, daddr, -1))
25385 +                               return -1;
25386                 }
25387                 if (sk->sk_bound_dev_if) {
25388                         if (sk->sk_bound_dev_if != dif)
25389 diff -NurpP --minimal linux-3.9.4/net/ipv6/ip6_output.c linux-3.9.4-vs2.3.6.2/net/ipv6/ip6_output.c
25390 --- linux-3.9.4/net/ipv6/ip6_output.c   2013-05-31 13:45:32.000000000 +0000
25391 +++ linux-3.9.4-vs2.3.6.2/net/ipv6/ip6_output.c 2013-05-31 17:17:54.000000000 +0000
25392 @@ -877,7 +877,8 @@ static int ip6_dst_lookup_tail(struct so
25393                 struct rt6_info *rt = (struct rt6_info *) *dst;
25394                 err = ip6_route_get_saddr(net, rt, &fl6->daddr,
25395                                           sk ? inet6_sk(sk)->srcprefs : 0,
25396 -                                         &fl6->saddr);
25397 +                                         &fl6->saddr,
25398 +                                         sk ? sk->sk_nx_info : NULL);
25399                 if (err)
25400                         goto out_err_release;
25401         }
25402 diff -NurpP --minimal linux-3.9.4/net/ipv6/ndisc.c linux-3.9.4-vs2.3.6.2/net/ipv6/ndisc.c
25403 --- linux-3.9.4/net/ipv6/ndisc.c        2013-05-31 13:45:32.000000000 +0000
25404 +++ linux-3.9.4-vs2.3.6.2/net/ipv6/ndisc.c      2013-05-31 17:17:54.000000000 +0000
25405 @@ -485,7 +485,7 @@ static void ndisc_send_na(struct net_dev
25406         } else {
25407                 if (ipv6_dev_get_saddr(dev_net(dev), dev, daddr,
25408                                        inet6_sk(dev_net(dev)->ipv6.ndisc_sk)->srcprefs,
25409 -                                      &tmpaddr))
25410 +                                      &tmpaddr, NULL))
25411                         return;
25412                 src_addr = &tmpaddr;
25413         }
25414 diff -NurpP --minimal linux-3.9.4/net/ipv6/netfilter/ip6t_MASQUERADE.c linux-3.9.4-vs2.3.6.2/net/ipv6/netfilter/ip6t_MASQUERADE.c
25415 --- linux-3.9.4/net/ipv6/netfilter/ip6t_MASQUERADE.c    2012-12-11 03:30:57.000000000 +0000
25416 +++ linux-3.9.4-vs2.3.6.2/net/ipv6/netfilter/ip6t_MASQUERADE.c  2013-05-31 17:17:54.000000000 +0000
25417 @@ -34,7 +34,7 @@ masquerade_tg6(struct sk_buff *skb, cons
25418                             ctinfo == IP_CT_RELATED_REPLY));
25419  
25420         if (ipv6_dev_get_saddr(dev_net(par->out), par->out,
25421 -                              &ipv6_hdr(skb)->daddr, 0, &src) < 0)
25422 +                              &ipv6_hdr(skb)->daddr, 0, &src, NULL) < 0)
25423                 return NF_DROP;
25424  
25425         nfct_nat(ct)->masq_index = par->out->ifindex;
25426 diff -NurpP --minimal linux-3.9.4/net/ipv6/raw.c linux-3.9.4-vs2.3.6.2/net/ipv6/raw.c
25427 --- linux-3.9.4/net/ipv6/raw.c  2013-05-31 13:45:32.000000000 +0000
25428 +++ linux-3.9.4-vs2.3.6.2/net/ipv6/raw.c        2013-05-31 17:17:54.000000000 +0000
25429 @@ -30,6 +30,7 @@
25430  #include <linux/icmpv6.h>
25431  #include <linux/netfilter.h>
25432  #include <linux/netfilter_ipv6.h>
25433 +#include <linux/vs_inet6.h>
25434  #include <linux/skbuff.h>
25435  #include <linux/compat.h>
25436  #include <asm/uaccess.h>
25437 @@ -283,6 +284,13 @@ static int rawv6_bind(struct sock *sk, s
25438                                 goto out_unlock;
25439                 }
25440  
25441 +               if (!v6_addr_in_nx_info(sk->sk_nx_info, &addr->sin6_addr, -1)) {
25442 +                       err = -EADDRNOTAVAIL;
25443 +                       if (dev)
25444 +                               dev_put(dev);
25445 +                       goto out;
25446 +               }
25447 +
25448                 /* ipv4 addr of the socket is invalid.  Only the
25449                  * unspecified and mapped address have a v4 equivalent.
25450                  */
25451 diff -NurpP --minimal linux-3.9.4/net/ipv6/route.c linux-3.9.4-vs2.3.6.2/net/ipv6/route.c
25452 --- linux-3.9.4/net/ipv6/route.c        2013-05-31 13:45:32.000000000 +0000
25453 +++ linux-3.9.4-vs2.3.6.2/net/ipv6/route.c      2013-05-31 18:10:38.000000000 +0000
25454 @@ -58,6 +58,7 @@
25455  #include <net/netevent.h>
25456  #include <net/netlink.h>
25457  #include <net/nexthop.h>
25458 +#include <linux/vs_inet6.h>
25459  
25460  #include <asm/uaccess.h>
25461  
25462 @@ -2079,15 +2080,17 @@ int ip6_route_get_saddr(struct net *net,
25463                         struct rt6_info *rt,
25464                         const struct in6_addr *daddr,
25465                         unsigned int prefs,
25466 -                       struct in6_addr *saddr)
25467 +                       struct in6_addr *saddr,
25468 +                       struct nx_info *nxi)
25469  {
25470         struct inet6_dev *idev = ip6_dst_idev((struct dst_entry*)rt);
25471         int err = 0;
25472 -       if (rt->rt6i_prefsrc.plen)
25473 +       if (rt->rt6i_prefsrc.plen && (!nxi ||
25474 +           v6_addr_in_nx_info(nxi, &rt->rt6i_prefsrc.addr, NXA_TYPE_ADDR)))
25475                 *saddr = rt->rt6i_prefsrc.addr;
25476         else
25477                 err = ipv6_dev_get_saddr(net, idev ? idev->dev : NULL,
25478 -                                        daddr, prefs, saddr);
25479 +                                        daddr, prefs, saddr, nxi);
25480         return err;
25481  }
25482  
25483 @@ -2507,7 +2510,8 @@ static int rt6_fill_node(struct net *net
25484                                 goto nla_put_failure;
25485         } else if (dst) {
25486                 struct in6_addr saddr_buf;
25487 -               if (ip6_route_get_saddr(net, rt, dst, 0, &saddr_buf) == 0 &&
25488 +               if (ip6_route_get_saddr(net, rt, dst, 0, &saddr_buf,
25489 +                   (skb->sk ? skb->sk->sk_nx_info : NULL)) == 0 &&
25490                     nla_put(skb, RTA_PREFSRC, 16, &saddr_buf))
25491                         goto nla_put_failure;
25492         }
25493 @@ -2719,6 +2723,7 @@ static int rt6_info_route(struct rt6_inf
25494  {
25495         struct seq_file *m = p_arg;
25496  
25497 +       /* FIXME: check for network context? */
25498         seq_printf(m, "%pi6 %02x ", &rt->rt6i_dst.addr, rt->rt6i_dst.plen);
25499  
25500  #ifdef CONFIG_IPV6_SUBTREES
25501 diff -NurpP --minimal linux-3.9.4/net/ipv6/tcp_ipv6.c linux-3.9.4-vs2.3.6.2/net/ipv6/tcp_ipv6.c
25502 --- linux-3.9.4/net/ipv6/tcp_ipv6.c     2013-05-31 14:22:27.000000000 +0000
25503 +++ linux-3.9.4-vs2.3.6.2/net/ipv6/tcp_ipv6.c   2013-05-31 17:17:54.000000000 +0000
25504 @@ -71,6 +71,7 @@
25505  
25506  #include <linux/crypto.h>
25507  #include <linux/scatterlist.h>
25508 +#include <linux/vs_inet6.h>
25509  
25510  static void    tcp_v6_send_reset(struct sock *sk, struct sk_buff *skb);
25511  static void    tcp_v6_reqsk_send_ack(struct sock *sk, struct sk_buff *skb,
25512 @@ -164,8 +165,15 @@ static int tcp_v6_connect(struct sock *s
25513          *      connect() to INADDR_ANY means loopback (BSD'ism).
25514          */
25515  
25516 -       if(ipv6_addr_any(&usin->sin6_addr))
25517 -               usin->sin6_addr.s6_addr[15] = 0x1;
25518 +       if(ipv6_addr_any(&usin->sin6_addr)) {
25519 +               struct nx_info *nxi =  sk->sk_nx_info;
25520 +
25521 +               if (nxi && nx_info_has_v6(nxi))
25522 +                       /* FIXME: remap lback? */
25523 +                       usin->sin6_addr = nxi->v6.ip;
25524 +               else
25525 +                       usin->sin6_addr.s6_addr[15] = 0x1;
25526 +       }
25527  
25528         addr_type = ipv6_addr_type(&usin->sin6_addr);
25529  
25530 diff -NurpP --minimal linux-3.9.4/net/ipv6/udp.c linux-3.9.4-vs2.3.6.2/net/ipv6/udp.c
25531 --- linux-3.9.4/net/ipv6/udp.c  2013-05-31 14:22:27.000000000 +0000
25532 +++ linux-3.9.4-vs2.3.6.2/net/ipv6/udp.c        2013-05-31 18:16:01.000000000 +0000
25533 @@ -46,42 +46,68 @@
25534  #include <net/ip6_checksum.h>
25535  #include <net/xfrm.h>
25536  #include <net/inet6_hashtables.h>
25537 +#include <linux/vs_inet6.h>
25538  
25539  #include <linux/proc_fs.h>
25540  #include <linux/seq_file.h>
25541  #include <trace/events/skb.h>
25542  #include "udp_impl.h"
25543  
25544 -int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
25545 +int ipv6_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2)
25546  {
25547 -       const struct in6_addr *sk_rcv_saddr6 = &inet6_sk(sk)->rcv_saddr;
25548 +       const struct in6_addr *sk1_rcv_saddr6 = &inet6_sk(sk1)->rcv_saddr;
25549         const struct in6_addr *sk2_rcv_saddr6 = inet6_rcv_saddr(sk2);
25550 -       __be32 sk1_rcv_saddr = sk_rcv_saddr(sk);
25551 +       __be32 sk1_rcv_saddr = sk_rcv_saddr(sk1);
25552         __be32 sk2_rcv_saddr = sk_rcv_saddr(sk2);
25553 -       int sk_ipv6only = ipv6_only_sock(sk);
25554 +       int sk1_ipv6only = ipv6_only_sock(sk1);
25555         int sk2_ipv6only = inet_v6_ipv6only(sk2);
25556 -       int addr_type = ipv6_addr_type(sk_rcv_saddr6);
25557 +       int addr_type = ipv6_addr_type(sk1_rcv_saddr6);
25558         int addr_type2 = sk2_rcv_saddr6 ? ipv6_addr_type(sk2_rcv_saddr6) : IPV6_ADDR_MAPPED;
25559  
25560         /* if both are mapped, treat as IPv4 */
25561 -       if (addr_type == IPV6_ADDR_MAPPED && addr_type2 == IPV6_ADDR_MAPPED)
25562 -               return (!sk2_ipv6only &&
25563 +       if (addr_type == IPV6_ADDR_MAPPED && addr_type2 == IPV6_ADDR_MAPPED) {
25564 +               if (!sk2_ipv6only &&
25565                         (!sk1_rcv_saddr || !sk2_rcv_saddr ||
25566 -                         sk1_rcv_saddr == sk2_rcv_saddr));
25567 +                         sk1_rcv_saddr == sk2_rcv_saddr))
25568 +                       goto vs_v4;
25569 +               else
25570 +                       return 0;
25571 +       }
25572  
25573         if (addr_type2 == IPV6_ADDR_ANY &&
25574             !(sk2_ipv6only && addr_type == IPV6_ADDR_MAPPED))
25575 -               return 1;
25576 +               goto vs;
25577  
25578         if (addr_type == IPV6_ADDR_ANY &&
25579 -           !(sk_ipv6only && addr_type2 == IPV6_ADDR_MAPPED))
25580 -               return 1;
25581 +           !(sk1_ipv6only && addr_type2 == IPV6_ADDR_MAPPED))
25582 +               goto vs;
25583  
25584         if (sk2_rcv_saddr6 &&
25585 -           ipv6_addr_equal(sk_rcv_saddr6, sk2_rcv_saddr6))
25586 -               return 1;
25587 +           ipv6_addr_equal(sk1_rcv_saddr6, sk2_rcv_saddr6))
25588 +               goto vs;
25589  
25590         return 0;
25591 +
25592 +vs_v4:
25593 +       if (!sk1_rcv_saddr && !sk2_rcv_saddr)
25594 +               return nx_v4_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info);
25595 +       if (!sk2_rcv_saddr)
25596 +               return v4_addr_in_nx_info(sk1->sk_nx_info, sk2_rcv_saddr, -1);
25597 +       if (!sk1_rcv_saddr)
25598 +               return v4_addr_in_nx_info(sk2->sk_nx_info, sk1_rcv_saddr, -1);
25599 +       return 1;
25600 +vs:
25601 +       if (addr_type2 == IPV6_ADDR_ANY && addr_type == IPV6_ADDR_ANY)
25602 +               return nx_v6_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info);
25603 +       else if (addr_type2 == IPV6_ADDR_ANY)
25604 +               return v6_addr_in_nx_info(sk2->sk_nx_info, sk1_rcv_saddr6, -1);
25605 +       else if (addr_type == IPV6_ADDR_ANY) {
25606 +               if (addr_type2 == IPV6_ADDR_MAPPED)
25607 +                       return nx_v4_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info);
25608 +               else
25609 +                       return v6_addr_in_nx_info(sk1->sk_nx_info, sk2_rcv_saddr6, -1);
25610 +       }
25611 +       return 1;
25612  }
25613  
25614  static unsigned int udp6_portaddr_hash(struct net *net,
25615 @@ -145,6 +171,10 @@ static inline int compute_score(struct s
25616                         if (!ipv6_addr_equal(&np->rcv_saddr, daddr))
25617                                 return -1;
25618                         score++;
25619 +               } else {
25620 +                       /* block non nx_info ips */
25621 +                       if (!v6_addr_in_nx_info(sk->sk_nx_info, daddr, -1))
25622 +                               return -1;
25623                 }
25624                 if (!ipv6_addr_any(&np->daddr)) {
25625                         if (!ipv6_addr_equal(&np->daddr, saddr))
25626 diff -NurpP --minimal linux-3.9.4/net/ipv6/xfrm6_policy.c linux-3.9.4-vs2.3.6.2/net/ipv6/xfrm6_policy.c
25627 --- linux-3.9.4/net/ipv6/xfrm6_policy.c 2013-05-31 14:22:27.000000000 +0000
25628 +++ linux-3.9.4-vs2.3.6.2/net/ipv6/xfrm6_policy.c       2013-05-31 17:17:54.000000000 +0000
25629 @@ -63,7 +63,7 @@ static int xfrm6_get_saddr(struct net *n
25630         dev = ip6_dst_idev(dst)->dev;
25631         ipv6_dev_get_saddr(dev_net(dev), dev,
25632                            (struct in6_addr *)&daddr->a6, 0,
25633 -                          (struct in6_addr *)&saddr->a6);
25634 +                          (struct in6_addr *)&saddr->a6, NULL);
25635         dst_release(dst);
25636         return 0;
25637  }
25638 diff -NurpP --minimal linux-3.9.4/net/netfilter/ipvs/ip_vs_xmit.c linux-3.9.4-vs2.3.6.2/net/netfilter/ipvs/ip_vs_xmit.c
25639 --- linux-3.9.4/net/netfilter/ipvs/ip_vs_xmit.c 2013-02-19 13:58:59.000000000 +0000
25640 +++ linux-3.9.4-vs2.3.6.2/net/netfilter/ipvs/ip_vs_xmit.c       2013-05-31 17:17:54.000000000 +0000
25641 @@ -273,7 +273,7 @@ __ip_vs_route_output_v6(struct net *net,
25642                 return dst;
25643         if (ipv6_addr_any(&fl6.saddr) &&
25644             ipv6_dev_get_saddr(net, ip6_dst_idev(dst)->dev,
25645 -                              &fl6.daddr, 0, &fl6.saddr) < 0)
25646 +                              &fl6.daddr, 0, &fl6.saddr, NULL) < 0)
25647                 goto out_err;
25648         if (do_xfrm) {
25649                 dst = xfrm_lookup(net, dst, flowi6_to_flowi(&fl6), NULL, 0);
25650 diff -NurpP --minimal linux-3.9.4/net/netlink/af_netlink.c linux-3.9.4-vs2.3.6.2/net/netlink/af_netlink.c
25651 --- linux-3.9.4/net/netlink/af_netlink.c        2013-05-31 13:45:33.000000000 +0000
25652 +++ linux-3.9.4-vs2.3.6.2/net/netlink/af_netlink.c      2013-05-31 17:17:54.000000000 +0000
25653 @@ -55,6 +55,9 @@
25654  #include <linux/types.h>
25655  #include <linux/audit.h>
25656  #include <linux/mutex.h>
25657 +#include <linux/vs_context.h>
25658 +#include <linux/vs_network.h>
25659 +#include <linux/vs_limit.h>
25660  
25661  #include <net/net_namespace.h>
25662  #include <net/sock.h>
25663 @@ -1976,6 +1979,8 @@ static struct sock *netlink_seq_socket_i
25664                         sk_for_each(s, &hash->table[j]) {
25665                                 if (sock_net(s) != seq_file_net(seq))
25666                                         continue;
25667 +                               if (!nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT))
25668 +                                       continue;
25669                                 if (off == pos) {
25670                                         iter->link = i;
25671                                         iter->hash_idx = j;
25672 @@ -2010,7 +2015,8 @@ static void *netlink_seq_next(struct seq
25673         s = v;
25674         do {
25675                 s = sk_next(s);
25676 -       } while (s && sock_net(s) != seq_file_net(seq));
25677 +       } while (s && (sock_net(s) != seq_file_net(seq) ||
25678 +               !nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT)));
25679         if (s)
25680                 return s;
25681  
25682 @@ -2022,7 +2028,8 @@ static void *netlink_seq_next(struct seq
25683  
25684                 for (; j <= hash->mask; j++) {
25685                         s = sk_head(&hash->table[j]);
25686 -                       while (s && sock_net(s) != seq_file_net(seq))
25687 +                       while (s && (sock_net(s) != seq_file_net(seq) ||
25688 +                               !nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT)))
25689                                 s = sk_next(s);
25690                         if (s) {
25691                                 iter->link = i;
25692 diff -NurpP --minimal linux-3.9.4/net/socket.c linux-3.9.4-vs2.3.6.2/net/socket.c
25693 --- linux-3.9.4/net/socket.c    2013-05-31 13:45:33.000000000 +0000
25694 +++ linux-3.9.4-vs2.3.6.2/net/socket.c  2013-05-31 17:17:54.000000000 +0000
25695 @@ -98,6 +98,10 @@
25696  
25697  #include <net/sock.h>
25698  #include <linux/netfilter.h>
25699 +#include <linux/vs_base.h>
25700 +#include <linux/vs_socket.h>
25701 +#include <linux/vs_inet.h>
25702 +#include <linux/vs_inet6.h>
25703  
25704  #include <linux/if_tun.h>
25705  #include <linux/ipv6_route.h>
25706 @@ -617,13 +621,29 @@ static inline int __sock_sendmsg_nosec(s
25707                                        struct msghdr *msg, size_t size)
25708  {
25709         struct sock_iocb *si = kiocb_to_siocb(iocb);
25710 +       size_t len;
25711  
25712         si->sock = sock;
25713         si->scm = NULL;
25714         si->msg = msg;
25715         si->size = size;
25716  
25717 -       return sock->ops->sendmsg(iocb, sock, msg, size);
25718 +       len = sock->ops->sendmsg(iocb, sock, msg, size);
25719 +       if (sock->sk) {
25720 +               if (len == size)
25721 +                       vx_sock_send(sock->sk, size);
25722 +               else
25723 +                       vx_sock_fail(sock->sk, size);
25724 +       }
25725 +       vxdprintk(VXD_CBIT(net, 7),
25726 +               "__sock_sendmsg: %p[%p,%p,%p;%d/%d]:%d/%zu",
25727 +               sock, sock->sk,
25728 +               (sock->sk)?sock->sk->sk_nx_info:0,
25729 +               (sock->sk)?sock->sk->sk_vx_info:0,
25730 +               (sock->sk)?sock->sk->sk_xid:0,
25731 +               (sock->sk)?sock->sk->sk_nid:0,
25732 +               (unsigned int)size, len);
25733 +       return len;
25734  }
25735  
25736  static inline int __sock_sendmsg(struct kiocb *iocb, struct socket *sock,
25737 @@ -779,6 +799,7 @@ static inline int __sock_recvmsg_nosec(s
25738                                        struct msghdr *msg, size_t size, int flags)
25739  {
25740         struct sock_iocb *si = kiocb_to_siocb(iocb);
25741 +       int len;
25742  
25743         si->sock = sock;
25744         si->scm = NULL;
25745 @@ -786,7 +807,18 @@ static inline int __sock_recvmsg_nosec(s
25746         si->size = size;
25747         si->flags = flags;
25748  
25749 -       return sock->ops->recvmsg(iocb, sock, msg, size, flags);
25750 +       len = sock->ops->recvmsg(iocb, sock, msg, size, flags);
25751 +       if ((len >= 0) && sock->sk)
25752 +               vx_sock_recv(sock->sk, len);
25753 +       vxdprintk(VXD_CBIT(net, 7),
25754 +               "__sock_recvmsg: %p[%p,%p,%p;%d/%d]:%d/%d",
25755 +               sock, sock->sk,
25756 +               (sock->sk)?sock->sk->sk_nx_info:0,
25757 +               (sock->sk)?sock->sk->sk_vx_info:0,
25758 +               (sock->sk)?sock->sk->sk_xid:0,
25759 +               (sock->sk)?sock->sk->sk_nid:0,
25760 +               (unsigned int)size, len);
25761 +       return len;
25762  }
25763  
25764  static inline int __sock_recvmsg(struct kiocb *iocb, struct socket *sock,
25765 @@ -1269,6 +1301,13 @@ int __sock_create(struct net *net, int f
25766         if (type < 0 || type >= SOCK_MAX)
25767                 return -EINVAL;
25768  
25769 +       if (!nx_check(0, VS_ADMIN)) {
25770 +               if (family == PF_INET && !current_nx_info_has_v4())
25771 +                       return -EAFNOSUPPORT;
25772 +               if (family == PF_INET6 && !current_nx_info_has_v6())
25773 +                       return -EAFNOSUPPORT;
25774 +       }
25775 +
25776         /* Compatibility.
25777  
25778            This uglymoron is moved from INET layer to here to avoid
25779 @@ -1403,6 +1442,7 @@ SYSCALL_DEFINE3(socket, int, family, int
25780         if (retval < 0)
25781                 goto out;
25782  
25783 +       set_bit(SOCK_USER_SOCKET, &sock->flags);
25784         retval = sock_map_fd(sock, flags & (O_CLOEXEC | O_NONBLOCK));
25785         if (retval < 0)
25786                 goto out_release;
25787 @@ -1444,10 +1484,12 @@ SYSCALL_DEFINE4(socketpair, int, family,
25788         err = sock_create(family, type, protocol, &sock1);
25789         if (err < 0)
25790                 goto out;
25791 +       set_bit(SOCK_USER_SOCKET, &sock1->flags);
25792  
25793         err = sock_create(family, type, protocol, &sock2);
25794         if (err < 0)
25795                 goto out_release_1;
25796 +       set_bit(SOCK_USER_SOCKET, &sock2->flags);
25797  
25798         err = sock1->ops->socketpair(sock1, sock2);
25799         if (err < 0)
25800 diff -NurpP --minimal linux-3.9.4/net/sunrpc/auth.c linux-3.9.4-vs2.3.6.2/net/sunrpc/auth.c
25801 --- linux-3.9.4/net/sunrpc/auth.c       2013-05-31 13:45:33.000000000 +0000
25802 +++ linux-3.9.4-vs2.3.6.2/net/sunrpc/auth.c     2013-05-31 18:01:00.000000000 +0000
25803 @@ -15,6 +15,7 @@
25804  #include <linux/sunrpc/clnt.h>
25805  #include <linux/sunrpc/gss_api.h>
25806  #include <linux/spinlock.h>
25807 +#include <linux/vs_tag.h>
25808  
25809  #ifdef RPC_DEBUG
25810  # define RPCDBG_FACILITY       RPCDBG_AUTH
25811 @@ -480,6 +481,7 @@ rpcauth_lookupcred(struct rpc_auth *auth
25812         memset(&acred, 0, sizeof(acred));
25813         acred.uid = cred->fsuid;
25814         acred.gid = cred->fsgid;
25815 +       acred.tag = dx_current_tag();
25816         acred.group_info = get_group_info(((struct cred *)cred)->group_info);
25817  
25818         ret = auth->au_ops->lookup_cred(auth, &acred, flags);
25819 @@ -520,6 +522,7 @@ rpcauth_bind_root_cred(struct rpc_task *
25820         struct auth_cred acred = {
25821                 .uid = GLOBAL_ROOT_UID,
25822                 .gid = GLOBAL_ROOT_GID,
25823 +               .tag = dx_current_tag(),
25824         };
25825  
25826         dprintk("RPC: %5u looking up %s cred\n",
25827 diff -NurpP --minimal linux-3.9.4/net/sunrpc/auth_unix.c linux-3.9.4-vs2.3.6.2/net/sunrpc/auth_unix.c
25828 --- linux-3.9.4/net/sunrpc/auth_unix.c  2013-05-31 13:45:33.000000000 +0000
25829 +++ linux-3.9.4-vs2.3.6.2/net/sunrpc/auth_unix.c        2013-05-31 18:05:54.000000000 +0000
25830 @@ -13,11 +13,13 @@
25831  #include <linux/sunrpc/clnt.h>
25832  #include <linux/sunrpc/auth.h>
25833  #include <linux/user_namespace.h>
25834 +#include <linux/vs_tag.h>
25835  
25836  #define NFS_NGROUPS    16
25837  
25838  struct unx_cred {
25839         struct rpc_cred         uc_base;
25840 +       ktag_t                  uc_tag;
25841         kgid_t                  uc_gid;
25842         kgid_t                  uc_gids[NFS_NGROUPS];
25843  };
25844 @@ -80,6 +82,7 @@ unx_create_cred(struct rpc_auth *auth, s
25845                 groups = NFS_NGROUPS;
25846  
25847         cred->uc_gid = acred->gid;
25848 +       cred->uc_tag = acred->tag;
25849         for (i = 0; i < groups; i++)
25850                 cred->uc_gids[i] = GROUP_AT(acred->group_info, i);
25851         if (i < NFS_NGROUPS)
25852 @@ -121,7 +124,9 @@ unx_match(struct auth_cred *acred, struc
25853         unsigned int i;
25854  
25855  
25856 -       if (!uid_eq(cred->uc_uid, acred->uid) || !gid_eq(cred->uc_gid, acred->gid))
25857 +       if (!uid_eq(cred->uc_uid, acred->uid) ||
25858 +           !gid_eq(cred->uc_gid, acred->gid) ||
25859 +           !tag_eq(cred->uc_tag, acred->tag))
25860                 return 0;
25861  
25862         if (acred->group_info != NULL)
25863 @@ -146,7 +151,7 @@ unx_marshal(struct rpc_task *task, __be3
25864         struct rpc_clnt *clnt = task->tk_client;
25865         struct unx_cred *cred = container_of(task->tk_rqstp->rq_cred, struct unx_cred, uc_base);
25866         __be32          *base, *hold;
25867 -       int             i;
25868 +       int             i, tag;
25869  
25870         *p++ = htonl(RPC_AUTH_UNIX);
25871         base = p++;
25872 @@ -157,8 +162,13 @@ unx_marshal(struct rpc_task *task, __be3
25873          */
25874         p = xdr_encode_array(p, clnt->cl_nodename, clnt->cl_nodelen);
25875  
25876 -       *p++ = htonl((u32) from_kuid(&init_user_ns, cred->uc_uid));
25877 -       *p++ = htonl((u32) from_kgid(&init_user_ns, cred->uc_gid));
25878 +       tag = task->tk_client->cl_tag;
25879 +       *p++ = htonl((u32) TAGINO_UID(tag,
25880 +               from_kuid(&init_user_ns, cred->uc_uid),
25881 +               from_ktag(&init_user_ns, cred->uc_tag)));
25882 +       *p++ = htonl((u32) TAGINO_GID(tag,
25883 +               from_kgid(&init_user_ns, cred->uc_gid),
25884 +               from_ktag(&init_user_ns, cred->uc_tag)));
25885         hold = p++;
25886         for (i = 0; i < 16 && gid_valid(cred->uc_gids[i]); i++)
25887                 *p++ = htonl((u32) from_kgid(&init_user_ns, cred->uc_gids[i]));
25888 diff -NurpP --minimal linux-3.9.4/net/sunrpc/clnt.c linux-3.9.4-vs2.3.6.2/net/sunrpc/clnt.c
25889 --- linux-3.9.4/net/sunrpc/clnt.c       2013-05-31 13:45:33.000000000 +0000
25890 +++ linux-3.9.4-vs2.3.6.2/net/sunrpc/clnt.c     2013-05-31 17:17:54.000000000 +0000
25891 @@ -31,6 +31,7 @@
25892  #include <linux/in6.h>
25893  #include <linux/un.h>
25894  #include <linux/rcupdate.h>
25895 +#include <linux/vs_cvirt.h>
25896  
25897  #include <linux/sunrpc/clnt.h>
25898  #include <linux/sunrpc/addr.h>
25899 @@ -482,6 +483,9 @@ struct rpc_clnt *rpc_create(struct rpc_c
25900         if (!(args->flags & RPC_CLNT_CREATE_QUIET))
25901                 clnt->cl_chatty = 1;
25902  
25903 +       /* TODO: handle RPC_CLNT_CREATE_TAGGED
25904 +       if (args->flags & RPC_CLNT_CREATE_TAGGED)
25905 +               clnt->cl_tag = 1; */
25906         return clnt;
25907  }
25908  EXPORT_SYMBOL_GPL(rpc_create);
25909 diff -NurpP --minimal linux-3.9.4/net/unix/af_unix.c linux-3.9.4-vs2.3.6.2/net/unix/af_unix.c
25910 --- linux-3.9.4/net/unix/af_unix.c      2013-05-31 13:45:33.000000000 +0000
25911 +++ linux-3.9.4-vs2.3.6.2/net/unix/af_unix.c    2013-05-31 17:17:54.000000000 +0000
25912 @@ -114,6 +114,8 @@
25913  #include <linux/mount.h>
25914  #include <net/checksum.h>
25915  #include <linux/security.h>
25916 +#include <linux/vs_context.h>
25917 +#include <linux/vs_limit.h>
25918  
25919  struct hlist_head unix_socket_table[2 * UNIX_HASH_SIZE];
25920  EXPORT_SYMBOL_GPL(unix_socket_table);
25921 @@ -270,6 +272,8 @@ static struct sock *__unix_find_socket_b
25922                 if (!net_eq(sock_net(s), net))
25923                         continue;
25924  
25925 +               if (!nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT))
25926 +                       continue;
25927                 if (u->addr->len == len &&
25928                     !memcmp(u->addr->name, sunname, len))
25929                         goto found;
25930 @@ -2256,6 +2260,8 @@ static struct sock *unix_from_bucket(str
25931         for (sk = sk_head(&unix_socket_table[bucket]); sk; sk = sk_next(sk)) {
25932                 if (sock_net(sk) != seq_file_net(seq))
25933                         continue;
25934 +               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
25935 +                       continue;
25936                 if (++count == offset)
25937                         break;
25938         }
25939 @@ -2273,6 +2279,8 @@ static struct sock *unix_next_socket(str
25940                 sk = sk_next(sk);
25941                 if (!sk)
25942                         goto next_bucket;
25943 +               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
25944 +                       continue;
25945                 if (sock_net(sk) == seq_file_net(seq))
25946                         return sk;
25947         }
25948 diff -NurpP --minimal linux-3.9.4/scripts/checksyscalls.sh linux-3.9.4-vs2.3.6.2/scripts/checksyscalls.sh
25949 --- linux-3.9.4/scripts/checksyscalls.sh        2012-12-11 03:30:57.000000000 +0000
25950 +++ linux-3.9.4-vs2.3.6.2/scripts/checksyscalls.sh      2013-05-31 14:47:11.000000000 +0000
25951 @@ -193,7 +193,6 @@ cat << EOF
25952  #define __IGNORE_afs_syscall
25953  #define __IGNORE_getpmsg
25954  #define __IGNORE_putpmsg
25955 -#define __IGNORE_vserver
25956  EOF
25957  }
25958  
25959 diff -NurpP --minimal linux-3.9.4/scripts/mod/devicetable-offsets.h linux-3.9.4-vs2.3.6.2/scripts/mod/devicetable-offsets.h
25960 --- linux-3.9.4/scripts/mod/devicetable-offsets.h       1970-01-01 00:00:00.000000000 +0000
25961 +++ linux-3.9.4-vs2.3.6.2/scripts/mod/devicetable-offsets.h     2013-06-01 10:46:36.000000000 +0000
25962 @@ -0,0 +1,146 @@
25963 +#ifndef __DEVICEVTABLE_OFFSETS_H__
25964 +#define __DEVICEVTABLE_OFFSETS_H__
25965 +/*
25966 + * DO NOT MODIFY.
25967 + *
25968 + * This file was generated by Kbuild
25969 + *
25970 + */
25971 +
25972 +#define SIZE_usb_device_id 32 /* sizeof(struct usb_device_id)  # */
25973 +#define OFF_usb_device_id_match_flags 0 /* offsetof(struct usb_device_id, match_flags) # */
25974 +#define OFF_usb_device_id_idVendor 2 /* offsetof(struct usb_device_id, idVendor)       # */
25975 +#define OFF_usb_device_id_idProduct 4 /* offsetof(struct usb_device_id, idProduct)     # */
25976 +#define OFF_usb_device_id_bcdDevice_lo 6 /* offsetof(struct usb_device_id, bcdDevice_lo)       # */
25977 +#define OFF_usb_device_id_bcdDevice_hi 8 /* offsetof(struct usb_device_id, bcdDevice_hi)       # */
25978 +#define OFF_usb_device_id_bDeviceClass 10 /* offsetof(struct usb_device_id, bDeviceClass)      # */
25979 +#define OFF_usb_device_id_bDeviceSubClass 11 /* offsetof(struct usb_device_id, bDeviceSubClass)        # */
25980 +#define OFF_usb_device_id_bDeviceProtocol 12 /* offsetof(struct usb_device_id, bDeviceProtocol)        # */
25981 +#define OFF_usb_device_id_bInterfaceClass 13 /* offsetof(struct usb_device_id, bInterfaceClass)        # */
25982 +#define OFF_usb_device_id_bInterfaceSubClass 14 /* offsetof(struct usb_device_id, bInterfaceSubClass)  # */
25983 +#define OFF_usb_device_id_bInterfaceProtocol 15 /* offsetof(struct usb_device_id, bInterfaceProtocol)  # */
25984 +#define OFF_usb_device_id_bInterfaceNumber 16 /* offsetof(struct usb_device_id, bInterfaceNumber)      # */
25985 +#define SIZE_hid_device_id 24 /* sizeof(struct hid_device_id)  # */
25986 +#define OFF_hid_device_id_bus 0 /* offsetof(struct hid_device_id, bus) # */
25987 +#define OFF_hid_device_id_group 2 /* offsetof(struct hid_device_id, group)     # */
25988 +#define OFF_hid_device_id_vendor 4 /* offsetof(struct hid_device_id, vendor)   # */
25989 +#define OFF_hid_device_id_product 8 /* offsetof(struct hid_device_id, product) # */
25990 +#define SIZE_ieee1394_device_id 32 /* sizeof(struct ieee1394_device_id)        # */
25991 +#define OFF_ieee1394_device_id_match_flags 0 /* offsetof(struct ieee1394_device_id, match_flags)       # */
25992 +#define OFF_ieee1394_device_id_vendor_id 4 /* offsetof(struct ieee1394_device_id, vendor_id)   # */
25993 +#define OFF_ieee1394_device_id_model_id 8 /* offsetof(struct ieee1394_device_id, model_id)     # */
25994 +#define OFF_ieee1394_device_id_specifier_id 12 /* offsetof(struct ieee1394_device_id, specifier_id)    # */
25995 +#define OFF_ieee1394_device_id_version 16 /* offsetof(struct ieee1394_device_id, version)      # */
25996 +#define SIZE_pci_device_id 32 /* sizeof(struct pci_device_id)  # */
25997 +#define OFF_pci_device_id_vendor 0 /* offsetof(struct pci_device_id, vendor)   # */
25998 +#define OFF_pci_device_id_device 4 /* offsetof(struct pci_device_id, device)   # */
25999 +#define OFF_pci_device_id_subvendor 8 /* offsetof(struct pci_device_id, subvendor)     # */
26000 +#define OFF_pci_device_id_subdevice 12 /* offsetof(struct pci_device_id, subdevice)    # */
26001 +#define OFF_pci_device_id_class 16 /* offsetof(struct pci_device_id, class)    # */
26002 +#define OFF_pci_device_id_class_mask 20 /* offsetof(struct pci_device_id, class_mask)  # */
26003 +#define SIZE_ccw_device_id 16 /* sizeof(struct ccw_device_id)  # */
26004 +#define OFF_ccw_device_id_match_flags 0 /* offsetof(struct ccw_device_id, match_flags) # */
26005 +#define OFF_ccw_device_id_cu_type 2 /* offsetof(struct ccw_device_id, cu_type) # */
26006 +#define OFF_ccw_device_id_cu_model 6 /* offsetof(struct ccw_device_id, cu_model)       # */
26007 +#define OFF_ccw_device_id_dev_type 4 /* offsetof(struct ccw_device_id, dev_type)       # */
26008 +#define OFF_ccw_device_id_dev_model 7 /* offsetof(struct ccw_device_id, dev_model)     # */
26009 +#define SIZE_ap_device_id 16 /* sizeof(struct ap_device_id)    # */
26010 +#define OFF_ap_device_id_dev_type 2 /* offsetof(struct ap_device_id, dev_type) # */
26011 +#define SIZE_css_device_id 16 /* sizeof(struct css_device_id)  # */
26012 +#define OFF_css_device_id_type 1 /* offsetof(struct css_device_id, type)       # */
26013 +#define SIZE_serio_device_id 4 /* sizeof(struct serio_device_id)       # */
26014 +#define OFF_serio_device_id_type 0 /* offsetof(struct serio_device_id, type)   # */
26015 +#define OFF_serio_device_id_proto 3 /* offsetof(struct serio_device_id, proto) # */
26016 +#define OFF_serio_device_id_id 2 /* offsetof(struct serio_device_id, id)       # */
26017 +#define OFF_serio_device_id_extra 1 /* offsetof(struct serio_device_id, extra) # */
26018 +#define SIZE_acpi_device_id 24 /* sizeof(struct acpi_device_id)        # */
26019 +#define OFF_acpi_device_id_id 0 /* offsetof(struct acpi_device_id, id) # */
26020 +#define SIZE_pnp_device_id 16 /* sizeof(struct pnp_device_id)  # */
26021 +#define OFF_pnp_device_id_id 0 /* offsetof(struct pnp_device_id, id)   # */
26022 +#define SIZE_pnp_card_device_id 80 /* sizeof(struct pnp_card_device_id)        # */
26023 +#define OFF_pnp_card_device_id_devs 16 /* offsetof(struct pnp_card_device_id, devs)    # */
26024 +#define SIZE_pcmcia_device_id 80 /* sizeof(struct pcmcia_device_id)    # */
26025 +#define OFF_pcmcia_device_id_match_flags 0 /* offsetof(struct pcmcia_device_id, match_flags)   # */
26026 +#define OFF_pcmcia_device_id_manf_id 2 /* offsetof(struct pcmcia_device_id, manf_id)   # */
26027 +#define OFF_pcmcia_device_id_card_id 4 /* offsetof(struct pcmcia_device_id, card_id)   # */
26028 +#define OFF_pcmcia_device_id_func_id 6 /* offsetof(struct pcmcia_device_id, func_id)   # */
26029 +#define OFF_pcmcia_device_id_function 7 /* offsetof(struct pcmcia_device_id, function) # */
26030 +#define OFF_pcmcia_device_id_device_no 8 /* offsetof(struct pcmcia_device_id, device_no)       # */
26031 +#define OFF_pcmcia_device_id_prod_id_hash 12 /* offsetof(struct pcmcia_device_id, prod_id_hash)        # */
26032 +#define SIZE_of_device_id 200 /* sizeof(struct of_device_id)   # */
26033 +#define OFF_of_device_id_name 0 /* offsetof(struct of_device_id, name) # */
26034 +#define OFF_of_device_id_type 32 /* offsetof(struct of_device_id, type)        # */
26035 +#define OFF_of_device_id_compatible 64 /* offsetof(struct of_device_id, compatible)    # */
26036 +#define SIZE_vio_device_id 64 /* sizeof(struct vio_device_id)  # */
26037 +#define OFF_vio_device_id_type 0 /* offsetof(struct vio_device_id, type)       # */
26038 +#define OFF_vio_device_id_compat 32 /* offsetof(struct vio_device_id, compat)  # */
26039 +#define SIZE_input_device_id 192 /* sizeof(struct input_device_id)     # */
26040 +#define OFF_input_device_id_flags 0 /* offsetof(struct input_device_id, flags) # */
26041 +#define OFF_input_device_id_bustype 8 /* offsetof(struct input_device_id, bustype)     # */
26042 +#define OFF_input_device_id_vendor 10 /* offsetof(struct input_device_id, vendor)      # */
26043 +#define OFF_input_device_id_product 12 /* offsetof(struct input_device_id, product)    # */
26044 +#define OFF_input_device_id_version 14 /* offsetof(struct input_device_id, version)    # */
26045 +#define OFF_input_device_id_evbit 16 /* offsetof(struct input_device_id, evbit)        # */
26046 +#define OFF_input_device_id_keybit 24 /* offsetof(struct input_device_id, keybit)      # */
26047 +#define OFF_input_device_id_relbit 120 /* offsetof(struct input_device_id, relbit)     # */
26048 +#define OFF_input_device_id_absbit 128 /* offsetof(struct input_device_id, absbit)     # */
26049 +#define OFF_input_device_id_mscbit 136 /* offsetof(struct input_device_id, mscbit)     # */
26050 +#define OFF_input_device_id_ledbit 144 /* offsetof(struct input_device_id, ledbit)     # */
26051 +#define OFF_input_device_id_sndbit 152 /* offsetof(struct input_device_id, sndbit)     # */
26052 +#define OFF_input_device_id_ffbit 160 /* offsetof(struct input_device_id, ffbit)       # */
26053 +#define OFF_input_device_id_swbit 176 /* offsetof(struct input_device_id, swbit)       # */
26054 +#define SIZE_eisa_device_id 16 /* sizeof(struct eisa_device_id)        # */
26055 +#define OFF_eisa_device_id_sig 0 /* offsetof(struct eisa_device_id, sig)       # */
26056 +#define SIZE_parisc_device_id 8 /* sizeof(struct parisc_device_id)     # */
26057 +#define OFF_parisc_device_id_hw_type 0 /* offsetof(struct parisc_device_id, hw_type)   # */
26058 +#define OFF_parisc_device_id_hversion 2 /* offsetof(struct parisc_device_id, hversion) # */
26059 +#define OFF_parisc_device_id_hversion_rev 1 /* offsetof(struct parisc_device_id, hversion_rev) # */
26060 +#define OFF_parisc_device_id_sversion 4 /* offsetof(struct parisc_device_id, sversion) # */
26061 +#define SIZE_sdio_device_id 16 /* sizeof(struct sdio_device_id)        # */
26062 +#define OFF_sdio_device_id_class 0 /* offsetof(struct sdio_device_id, class)   # */
26063 +#define OFF_sdio_device_id_vendor 2 /* offsetof(struct sdio_device_id, vendor) # */
26064 +#define OFF_sdio_device_id_device 4 /* offsetof(struct sdio_device_id, device) # */
26065 +#define SIZE_ssb_device_id 6 /* sizeof(struct ssb_device_id)   # */
26066 +#define OFF_ssb_device_id_vendor 0 /* offsetof(struct ssb_device_id, vendor)   # */
26067 +#define OFF_ssb_device_id_coreid 2 /* offsetof(struct ssb_device_id, coreid)   # */
26068 +#define OFF_ssb_device_id_revision 4 /* offsetof(struct ssb_device_id, revision)       # */
26069 +#define SIZE_bcma_device_id 6 /* sizeof(struct bcma_device_id) # */
26070 +#define OFF_bcma_device_id_manuf 0 /* offsetof(struct bcma_device_id, manuf)   # */
26071 +#define OFF_bcma_device_id_id 2 /* offsetof(struct bcma_device_id, id) # */
26072 +#define OFF_bcma_device_id_rev 4 /* offsetof(struct bcma_device_id, rev)       # */
26073 +#define OFF_bcma_device_id_class 5 /* offsetof(struct bcma_device_id, class)   # */
26074 +#define SIZE_virtio_device_id 8 /* sizeof(struct virtio_device_id)     # */
26075 +#define OFF_virtio_device_id_device 0 /* offsetof(struct virtio_device_id, device)     # */
26076 +#define OFF_virtio_device_id_vendor 4 /* offsetof(struct virtio_device_id, vendor)     # */
26077 +#define SIZE_hv_vmbus_device_id 24 /* sizeof(struct hv_vmbus_device_id)        # */
26078 +#define OFF_hv_vmbus_device_id_guid 0 /* offsetof(struct hv_vmbus_device_id, guid)     # */
26079 +#define SIZE_i2c_device_id 32 /* sizeof(struct i2c_device_id)  # */
26080 +#define OFF_i2c_device_id_name 0 /* offsetof(struct i2c_device_id, name)       # */
26081 +#define SIZE_spi_device_id 40 /* sizeof(struct spi_device_id)  # */
26082 +#define OFF_spi_device_id_name 0 /* offsetof(struct spi_device_id, name)       # */
26083 +#define SIZE_dmi_system_id 344 /* sizeof(struct dmi_system_id) # */
26084 +#define OFF_dmi_system_id_matches 16 /* offsetof(struct dmi_system_id, matches)        # */
26085 +#define SIZE_platform_device_id 32 /* sizeof(struct platform_device_id)        # */
26086 +#define OFF_platform_device_id_name 0 /* offsetof(struct platform_device_id, name)     # */
26087 +#define SIZE_mdio_device_id 8 /* sizeof(struct mdio_device_id) # */
26088 +#define OFF_mdio_device_id_phy_id 0 /* offsetof(struct mdio_device_id, phy_id) # */
26089 +#define OFF_mdio_device_id_phy_id_mask 4 /* offsetof(struct mdio_device_id, phy_id_mask)       # */
26090 +#define SIZE_zorro_device_id 16 /* sizeof(struct zorro_device_id)      # */
26091 +#define OFF_zorro_device_id_id 0 /* offsetof(struct zorro_device_id, id)       # */
26092 +#define SIZE_isapnp_device_id 16 /* sizeof(struct isapnp_device_id)    # */
26093 +#define OFF_isapnp_device_id_vendor 4 /* offsetof(struct isapnp_device_id, vendor)     # */
26094 +#define OFF_isapnp_device_id_function 6 /* offsetof(struct isapnp_device_id, function) # */
26095 +#define SIZE_ipack_device_id 12 /* sizeof(struct ipack_device_id)      # */
26096 +#define OFF_ipack_device_id_format 0 /* offsetof(struct ipack_device_id, format)       # */
26097 +#define OFF_ipack_device_id_vendor 4 /* offsetof(struct ipack_device_id, vendor)       # */
26098 +#define OFF_ipack_device_id_device 8 /* offsetof(struct ipack_device_id, device)       # */
26099 +#define SIZE_amba_id 16 /* sizeof(struct amba_id)      # */
26100 +#define OFF_amba_id_id 0 /* offsetof(struct amba_id, id)       # */
26101 +#define OFF_amba_id_mask 4 /* offsetof(struct amba_id, mask)   # */
26102 +#define SIZE_x86_cpu_id 16 /* sizeof(struct x86_cpu_id)        # */
26103 +#define OFF_x86_cpu_id_feature 6 /* offsetof(struct x86_cpu_id, feature)       # */
26104 +#define OFF_x86_cpu_id_family 2 /* offsetof(struct x86_cpu_id, family) # */
26105 +#define OFF_x86_cpu_id_model 4 /* offsetof(struct x86_cpu_id, model)   # */
26106 +#define OFF_x86_cpu_id_vendor 0 /* offsetof(struct x86_cpu_id, vendor) # */
26107 +
26108 +#endif
26109 diff -NurpP --minimal linux-3.9.4/security/commoncap.c linux-3.9.4-vs2.3.6.2/security/commoncap.c
26110 --- linux-3.9.4/security/commoncap.c    2013-05-31 13:45:34.000000000 +0000
26111 +++ linux-3.9.4-vs2.3.6.2/security/commoncap.c  2013-05-31 15:07:02.000000000 +0000
26112 @@ -76,6 +76,7 @@ int cap_netlink_send(struct sock *sk, st
26113  int cap_capable(const struct cred *cred, struct user_namespace *targ_ns,
26114                 int cap, int audit)
26115  {
26116 +       struct vx_info *vxi = current_vx_info(); /* FIXME: get vxi from cred? */
26117         struct user_namespace *ns = targ_ns;
26118  
26119         /* See if cred has the capability in the target user namespace
26120 @@ -84,8 +85,12 @@ int cap_capable(const struct cred *cred,
26121          */
26122         for (;;) {
26123                 /* Do we have the necessary capabilities? */
26124 -               if (ns == cred->user_ns)
26125 -                       return cap_raised(cred->cap_effective, cap) ? 0 : -EPERM;
26126 +               if (ns == cred->user_ns) {
26127 +                       if (vx_info_flags(vxi, VXF_STATE_SETUP, 0) &&
26128 +                           cap_raised(cred->cap_effective, cap))
26129 +                               return 0;
26130 +                       return vx_cap_raised(vxi, cred->cap_effective, cap) ? 0 : -EPERM;
26131 +               }
26132  
26133                 /* Have we tried all of the parent namespaces? */
26134                 if (ns == &init_user_ns)
26135 @@ -628,7 +633,7 @@ int cap_inode_setxattr(struct dentry *de
26136  
26137         if (!strncmp(name, XATTR_SECURITY_PREFIX,
26138                      sizeof(XATTR_SECURITY_PREFIX) - 1) &&
26139 -           !capable(CAP_SYS_ADMIN))
26140 +               !vx_capable(CAP_SYS_ADMIN, VXC_FS_SECURITY))
26141                 return -EPERM;
26142         return 0;
26143  }
26144 @@ -654,7 +659,7 @@ int cap_inode_removexattr(struct dentry
26145  
26146         if (!strncmp(name, XATTR_SECURITY_PREFIX,
26147                      sizeof(XATTR_SECURITY_PREFIX) - 1) &&
26148 -           !capable(CAP_SYS_ADMIN))
26149 +               !vx_capable(CAP_SYS_ADMIN, VXC_FS_SECURITY))
26150                 return -EPERM;
26151         return 0;
26152  }
26153 diff -NurpP --minimal linux-3.9.4/security/selinux/hooks.c linux-3.9.4-vs2.3.6.2/security/selinux/hooks.c
26154 --- linux-3.9.4/security/selinux/hooks.c        2013-05-31 13:45:34.000000000 +0000
26155 +++ linux-3.9.4-vs2.3.6.2/security/selinux/hooks.c      2013-05-31 14:47:11.000000000 +0000
26156 @@ -67,7 +67,6 @@
26157  #include <linux/dccp.h>
26158  #include <linux/quota.h>
26159  #include <linux/un.h>          /* for Unix socket types */
26160 -#include <net/af_unix.h>       /* for Unix socket types */
26161  #include <linux/parser.h>
26162  #include <linux/nfs_mount.h>
26163  #include <net/ipv6.h>
This page took 1.964626 seconds and 4 git commands to generate.