]> git.pld-linux.org Git - packages/kernel.git/blob - kernel-vserver-2.3.patch
- rel 2; vserver patch did contain some autogenerated files which we don't want
[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/x86/Kconfig linux-3.9.4-vs2.3.6.2/arch/x86/Kconfig
742 --- linux-3.9.4/arch/x86/Kconfig        2013-05-31 14:22:26.000000000 +0000
743 +++ linux-3.9.4-vs2.3.6.2/arch/x86/Kconfig      2013-05-31 14:47:11.000000000 +0000
744 @@ -2341,6 +2341,8 @@ source "fs/Kconfig"
745  
746  source "arch/x86/Kconfig.debug"
747  
748 +source "kernel/vserver/Kconfig"
749 +
750  source "security/Kconfig"
751  
752  source "crypto/Kconfig"
753 diff -NurpP --minimal linux-3.9.4/arch/x86/syscalls/syscall_32.tbl linux-3.9.4-vs2.3.6.2/arch/x86/syscalls/syscall_32.tbl
754 --- linux-3.9.4/arch/x86/syscalls/syscall_32.tbl        2013-05-31 13:44:50.000000000 +0000
755 +++ linux-3.9.4-vs2.3.6.2/arch/x86/syscalls/syscall_32.tbl      2013-05-31 14:47:11.000000000 +0000
756 @@ -279,7 +279,7 @@
757  270    i386    tgkill                  sys_tgkill
758  271    i386    utimes                  sys_utimes                      compat_sys_utimes
759  272    i386    fadvise64_64            sys_fadvise64_64                sys32_fadvise64_64
760 -273    i386    vserver
761 +273    i386    vserver                 sys_vserver                     sys32_vserver
762  274    i386    mbind                   sys_mbind
763  275    i386    get_mempolicy           sys_get_mempolicy               compat_sys_get_mempolicy
764  276    i386    set_mempolicy           sys_set_mempolicy
765 diff -NurpP --minimal linux-3.9.4/arch/x86/syscalls/syscall_64.tbl linux-3.9.4-vs2.3.6.2/arch/x86/syscalls/syscall_64.tbl
766 --- linux-3.9.4/arch/x86/syscalls/syscall_64.tbl        2013-05-31 13:44:50.000000000 +0000
767 +++ linux-3.9.4-vs2.3.6.2/arch/x86/syscalls/syscall_64.tbl      2013-05-31 14:47:11.000000000 +0000
768 @@ -242,7 +242,7 @@
769  233    common  epoll_ctl               sys_epoll_ctl
770  234    common  tgkill                  sys_tgkill
771  235    common  utimes                  sys_utimes
772 -236    64      vserver
773 +236    64      vserver                 sys_vserver
774  237    common  mbind                   sys_mbind
775  238    common  set_mempolicy           sys_set_mempolicy
776  239    common  get_mempolicy           sys_get_mempolicy
777 diff -NurpP --minimal linux-3.9.4/drivers/block/Kconfig linux-3.9.4-vs2.3.6.2/drivers/block/Kconfig
778 --- linux-3.9.4/drivers/block/Kconfig   2013-05-31 13:44:51.000000000 +0000
779 +++ linux-3.9.4-vs2.3.6.2/drivers/block/Kconfig 2013-05-31 14:47:11.000000000 +0000
780 @@ -278,6 +278,13 @@ config BLK_DEV_CRYPTOLOOP
781  
782  source "drivers/block/drbd/Kconfig"
783  
784 +config BLK_DEV_VROOT
785 +       tristate "Virtual Root device support"
786 +       depends on QUOTACTL
787 +       ---help---
788 +         Saying Y here will allow you to use quota/fs ioctls on a shared
789 +         partition within a virtual server without compromising security.
790 +
791  config BLK_DEV_NBD
792         tristate "Network block device support"
793         depends on NET
794 diff -NurpP --minimal linux-3.9.4/drivers/block/Makefile linux-3.9.4-vs2.3.6.2/drivers/block/Makefile
795 --- linux-3.9.4/drivers/block/Makefile  2013-05-31 13:44:51.000000000 +0000
796 +++ linux-3.9.4-vs2.3.6.2/drivers/block/Makefile        2013-05-31 14:47:11.000000000 +0000
797 @@ -33,6 +33,7 @@ obj-$(CONFIG_VIRTIO_BLK)      += virtio_blk.o
798  obj-$(CONFIG_VIODASD)          += viodasd.o
799  obj-$(CONFIG_BLK_DEV_SX8)      += sx8.o
800  obj-$(CONFIG_BLK_DEV_HD)       += hd.o
801 +obj-$(CONFIG_BLK_DEV_VROOT)    += vroot.o
802  
803  obj-$(CONFIG_XEN_BLKDEV_FRONTEND)      += xen-blkfront.o
804  obj-$(CONFIG_XEN_BLKDEV_BACKEND)       += xen-blkback/
805 diff -NurpP --minimal linux-3.9.4/drivers/block/loop.c linux-3.9.4-vs2.3.6.2/drivers/block/loop.c
806 --- linux-3.9.4/drivers/block/loop.c    2013-05-31 13:44:51.000000000 +0000
807 +++ linux-3.9.4-vs2.3.6.2/drivers/block/loop.c  2013-05-31 14:47:11.000000000 +0000
808 @@ -76,6 +76,7 @@
809  #include <linux/sysfs.h>
810  #include <linux/miscdevice.h>
811  #include <linux/falloc.h>
812 +#include <linux/vs_context.h>
813  
814  #include <asm/uaccess.h>
815  
816 @@ -882,6 +883,7 @@ static int loop_set_fd(struct loop_devic
817         lo->lo_blocksize = lo_blocksize;
818         lo->lo_device = bdev;
819         lo->lo_flags = lo_flags;
820 +       lo->lo_xid = vx_current_xid();
821         lo->lo_backing_file = file;
822         lo->transfer = transfer_none;
823         lo->ioctl = NULL;
824 @@ -1033,6 +1035,7 @@ static int loop_clr_fd(struct loop_devic
825         lo->lo_sizelimit = 0;
826         lo->lo_encrypt_key_size = 0;
827         lo->lo_thread = NULL;
828 +       lo->lo_xid = 0;
829         memset(lo->lo_encrypt_key, 0, LO_KEY_SIZE);
830         memset(lo->lo_crypt_name, 0, LO_NAME_SIZE);
831         memset(lo->lo_file_name, 0, LO_NAME_SIZE);
832 @@ -1076,7 +1079,7 @@ loop_set_status(struct loop_device *lo,
833  
834         if (lo->lo_encrypt_key_size &&
835             !uid_eq(lo->lo_key_owner, uid) &&
836 -           !capable(CAP_SYS_ADMIN))
837 +           !vx_capable(CAP_SYS_ADMIN, VXC_ADMIN_CLOOP))
838                 return -EPERM;
839         if (lo->lo_state != Lo_bound)
840                 return -ENXIO;
841 @@ -1166,7 +1169,8 @@ loop_get_status(struct loop_device *lo,
842         memcpy(info->lo_crypt_name, lo->lo_crypt_name, LO_NAME_SIZE);
843         info->lo_encrypt_type =
844                 lo->lo_encryption ? lo->lo_encryption->number : 0;
845 -       if (lo->lo_encrypt_key_size && capable(CAP_SYS_ADMIN)) {
846 +       if (lo->lo_encrypt_key_size &&
847 +               vx_capable(CAP_SYS_ADMIN, VXC_ADMIN_CLOOP)) {
848                 info->lo_encrypt_key_size = lo->lo_encrypt_key_size;
849                 memcpy(info->lo_encrypt_key, lo->lo_encrypt_key,
850                        lo->lo_encrypt_key_size);
851 @@ -1508,6 +1512,11 @@ static int lo_open(struct block_device *
852                 goto out;
853         }
854  
855 +       if (!vx_check(lo->lo_xid, VS_IDENT|VS_HOSTID|VS_ADMIN_P)) {
856 +               err = -EACCES;
857 +               goto out;
858 +       }
859 +
860         mutex_lock(&lo->lo_ctl_mutex);
861         lo->lo_refcnt++;
862         mutex_unlock(&lo->lo_ctl_mutex);
863 diff -NurpP --minimal linux-3.9.4/drivers/block/vroot.c linux-3.9.4-vs2.3.6.2/drivers/block/vroot.c
864 --- linux-3.9.4/drivers/block/vroot.c   1970-01-01 00:00:00.000000000 +0000
865 +++ linux-3.9.4-vs2.3.6.2/drivers/block/vroot.c 2013-05-31 14:47:11.000000000 +0000
866 @@ -0,0 +1,291 @@
867 +/*
868 + *  linux/drivers/block/vroot.c
869 + *
870 + *  written by Herbert Pötzl, 9/11/2002
871 + *  ported to 2.6.10 by Herbert Pötzl, 30/12/2004
872 + *
873 + *  based on the loop.c code by Theodore Ts'o.
874 + *
875 + * Copyright (C) 2002-2007 by Herbert Pötzl.
876 + * Redistribution of this file is permitted under the
877 + * GNU General Public License.
878 + *
879 + */
880 +
881 +#include <linux/module.h>
882 +#include <linux/moduleparam.h>
883 +#include <linux/file.h>
884 +#include <linux/major.h>
885 +#include <linux/blkdev.h>
886 +#include <linux/slab.h>
887 +
888 +#include <linux/vroot.h>
889 +#include <linux/vs_context.h>
890 +
891 +
892 +static int max_vroot = 8;
893 +
894 +static struct vroot_device *vroot_dev;
895 +static struct gendisk **disks;
896 +
897 +
898 +static int vroot_set_dev(
899 +       struct vroot_device *vr,
900 +       struct block_device *bdev,
901 +       unsigned int arg)
902 +{
903 +       struct block_device *real_bdev;
904 +       struct file *file;
905 +       struct inode *inode;
906 +       int error;
907 +
908 +       error = -EBUSY;
909 +       if (vr->vr_state != Vr_unbound)
910 +               goto out;
911 +
912 +       error = -EBADF;
913 +       file = fget(arg);
914 +       if (!file)
915 +               goto out;
916 +
917 +       error = -EINVAL;
918 +       inode = file->f_dentry->d_inode;
919 +
920 +
921 +       if (S_ISBLK(inode->i_mode)) {
922 +               real_bdev = inode->i_bdev;
923 +               vr->vr_device = real_bdev;
924 +               __iget(real_bdev->bd_inode);
925 +       } else
926 +               goto out_fput;
927 +
928 +       vxdprintk(VXD_CBIT(misc, 0),
929 +               "vroot[%d]_set_dev: dev=" VXF_DEV,
930 +               vr->vr_number, VXD_DEV(real_bdev));
931 +
932 +       vr->vr_state = Vr_bound;
933 +       error = 0;
934 +
935 + out_fput:
936 +       fput(file);
937 + out:
938 +       return error;
939 +}
940 +
941 +static int vroot_clr_dev(
942 +       struct vroot_device *vr,
943 +       struct block_device *bdev)
944 +{
945 +       struct block_device *real_bdev;
946 +
947 +       if (vr->vr_state != Vr_bound)
948 +               return -ENXIO;
949 +       if (vr->vr_refcnt > 1)  /* we needed one fd for the ioctl */
950 +               return -EBUSY;
951 +
952 +       real_bdev = vr->vr_device;
953 +
954 +       vxdprintk(VXD_CBIT(misc, 0),
955 +               "vroot[%d]_clr_dev: dev=" VXF_DEV,
956 +               vr->vr_number, VXD_DEV(real_bdev));
957 +
958 +       bdput(real_bdev);
959 +       vr->vr_state = Vr_unbound;
960 +       vr->vr_device = NULL;
961 +       return 0;
962 +}
963 +
964 +
965 +static int vr_ioctl(struct block_device *bdev, fmode_t mode,
966 +       unsigned int cmd, unsigned long arg)
967 +{
968 +       struct vroot_device *vr = bdev->bd_disk->private_data;
969 +       int err;
970 +
971 +       down(&vr->vr_ctl_mutex);
972 +       switch (cmd) {
973 +       case VROOT_SET_DEV:
974 +               err = vroot_set_dev(vr, bdev, arg);
975 +               break;
976 +       case VROOT_CLR_DEV:
977 +               err = vroot_clr_dev(vr, bdev);
978 +               break;
979 +       default:
980 +               err = -EINVAL;
981 +               break;
982 +       }
983 +       up(&vr->vr_ctl_mutex);
984 +       return err;
985 +}
986 +
987 +static int vr_open(struct block_device *bdev, fmode_t mode)
988 +{
989 +       struct vroot_device *vr = bdev->bd_disk->private_data;
990 +
991 +       down(&vr->vr_ctl_mutex);
992 +       vr->vr_refcnt++;
993 +       up(&vr->vr_ctl_mutex);
994 +       return 0;
995 +}
996 +
997 +static int vr_release(struct gendisk *disk, fmode_t mode)
998 +{
999 +       struct vroot_device *vr = disk->private_data;
1000 +
1001 +       down(&vr->vr_ctl_mutex);
1002 +       --vr->vr_refcnt;
1003 +       up(&vr->vr_ctl_mutex);
1004 +       return 0;
1005 +}
1006 +
1007 +static struct block_device_operations vr_fops = {
1008 +       .owner =        THIS_MODULE,
1009 +       .open =         vr_open,
1010 +       .release =      vr_release,
1011 +       .ioctl =        vr_ioctl,
1012 +};
1013 +
1014 +static void vroot_make_request(struct request_queue *q, struct bio *bio)
1015 +{
1016 +       printk("vroot_make_request %p, %p\n", q, bio);
1017 +       bio_io_error(bio);
1018 +}
1019 +
1020 +struct block_device *__vroot_get_real_bdev(struct block_device *bdev)
1021 +{
1022 +       struct inode *inode = bdev->bd_inode;
1023 +       struct vroot_device *vr;
1024 +       struct block_device *real_bdev;
1025 +       int minor = iminor(inode);
1026 +
1027 +       vr = &vroot_dev[minor];
1028 +       real_bdev = vr->vr_device;
1029 +
1030 +       vxdprintk(VXD_CBIT(misc, 0),
1031 +               "vroot[%d]_get_real_bdev: dev=" VXF_DEV,
1032 +               vr->vr_number, VXD_DEV(real_bdev));
1033 +
1034 +       if (vr->vr_state != Vr_bound)
1035 +               return ERR_PTR(-ENXIO);
1036 +
1037 +       __iget(real_bdev->bd_inode);
1038 +       return real_bdev;
1039 +}
1040 +
1041 +
1042 +
1043 +/*
1044 + * And now the modules code and kernel interface.
1045 + */
1046 +
1047 +module_param(max_vroot, int, 0);
1048 +
1049 +MODULE_PARM_DESC(max_vroot, "Maximum number of vroot devices (1-256)");
1050 +MODULE_LICENSE("GPL");
1051 +MODULE_ALIAS_BLOCKDEV_MAJOR(VROOT_MAJOR);
1052 +
1053 +MODULE_AUTHOR ("Herbert Pötzl");
1054 +MODULE_DESCRIPTION ("Virtual Root Device Mapper");
1055 +
1056 +
1057 +int __init vroot_init(void)
1058 +{
1059 +       int err, i;
1060 +
1061 +       if (max_vroot < 1 || max_vroot > 256) {
1062 +               max_vroot = MAX_VROOT_DEFAULT;
1063 +               printk(KERN_WARNING "vroot: invalid max_vroot "
1064 +                       "(must be between 1 and 256), "
1065 +                       "using default (%d)\n", max_vroot);
1066 +       }
1067 +
1068 +       if (register_blkdev(VROOT_MAJOR, "vroot"))
1069 +               return -EIO;
1070 +
1071 +       err = -ENOMEM;
1072 +       vroot_dev = kmalloc(max_vroot * sizeof(struct vroot_device), GFP_KERNEL);
1073 +       if (!vroot_dev)
1074 +               goto out_mem1;
1075 +       memset(vroot_dev, 0, max_vroot * sizeof(struct vroot_device));
1076 +
1077 +       disks = kmalloc(max_vroot * sizeof(struct gendisk *), GFP_KERNEL);
1078 +       if (!disks)
1079 +               goto out_mem2;
1080 +
1081 +       for (i = 0; i < max_vroot; i++) {
1082 +               disks[i] = alloc_disk(1);
1083 +               if (!disks[i])
1084 +                       goto out_mem3;
1085 +               disks[i]->queue = blk_alloc_queue(GFP_KERNEL);
1086 +               if (!disks[i]->queue)
1087 +                       goto out_mem3;
1088 +               blk_queue_make_request(disks[i]->queue, vroot_make_request);
1089 +       }
1090 +
1091 +       for (i = 0; i < max_vroot; i++) {
1092 +               struct vroot_device *vr = &vroot_dev[i];
1093 +               struct gendisk *disk = disks[i];
1094 +
1095 +               memset(vr, 0, sizeof(*vr));
1096 +               sema_init(&vr->vr_ctl_mutex, 1);
1097 +               vr->vr_number = i;
1098 +               disk->major = VROOT_MAJOR;
1099 +               disk->first_minor = i;
1100 +               disk->fops = &vr_fops;
1101 +               sprintf(disk->disk_name, "vroot%d", i);
1102 +               disk->private_data = vr;
1103 +       }
1104 +
1105 +       err = register_vroot_grb(&__vroot_get_real_bdev);
1106 +       if (err)
1107 +               goto out_mem3;
1108 +
1109 +       for (i = 0; i < max_vroot; i++)
1110 +               add_disk(disks[i]);
1111 +       printk(KERN_INFO "vroot: loaded (max %d devices)\n", max_vroot);
1112 +       return 0;
1113 +
1114 +out_mem3:
1115 +       while (i--)
1116 +               put_disk(disks[i]);
1117 +       kfree(disks);
1118 +out_mem2:
1119 +       kfree(vroot_dev);
1120 +out_mem1:
1121 +       unregister_blkdev(VROOT_MAJOR, "vroot");
1122 +       printk(KERN_ERR "vroot: ran out of memory\n");
1123 +       return err;
1124 +}
1125 +
1126 +void vroot_exit(void)
1127 +{
1128 +       int i;
1129 +
1130 +       if (unregister_vroot_grb(&__vroot_get_real_bdev))
1131 +               printk(KERN_WARNING "vroot: cannot unregister grb\n");
1132 +
1133 +       for (i = 0; i < max_vroot; i++) {
1134 +               del_gendisk(disks[i]);
1135 +               put_disk(disks[i]);
1136 +       }
1137 +       unregister_blkdev(VROOT_MAJOR, "vroot");
1138 +
1139 +       kfree(disks);
1140 +       kfree(vroot_dev);
1141 +}
1142 +
1143 +module_init(vroot_init);
1144 +module_exit(vroot_exit);
1145 +
1146 +#ifndef MODULE
1147 +
1148 +static int __init max_vroot_setup(char *str)
1149 +{
1150 +       max_vroot = simple_strtol(str, NULL, 0);
1151 +       return 1;
1152 +}
1153 +
1154 +__setup("max_vroot=", max_vroot_setup);
1155 +
1156 +#endif
1157 +
1158 diff -NurpP --minimal linux-3.9.4/drivers/infiniband/Kconfig linux-3.9.4-vs2.3.6.2/drivers/infiniband/Kconfig
1159 --- linux-3.9.4/drivers/infiniband/Kconfig      2012-12-11 03:30:57.000000000 +0000
1160 +++ linux-3.9.4-vs2.3.6.2/drivers/infiniband/Kconfig    2013-05-31 14:47:11.000000000 +0000
1161 @@ -39,7 +39,7 @@ config INFINIBAND_USER_MEM
1162  config INFINIBAND_ADDR_TRANS
1163         bool
1164         depends on INET
1165 -       depends on !(INFINIBAND = y && IPV6 = m)
1166 +       depends on !(INFINIBAND = y && IPV6 = y)
1167         default y
1168  
1169  source "drivers/infiniband/hw/mthca/Kconfig"
1170 diff -NurpP --minimal linux-3.9.4/drivers/infiniband/core/addr.c linux-3.9.4-vs2.3.6.2/drivers/infiniband/core/addr.c
1171 --- linux-3.9.4/drivers/infiniband/core/addr.c  2012-12-11 03:30:57.000000000 +0000
1172 +++ linux-3.9.4-vs2.3.6.2/drivers/infiniband/core/addr.c        2013-05-31 14:47:11.000000000 +0000
1173 @@ -261,7 +261,7 @@ static int addr6_resolve(struct sockaddr
1174  
1175         if (ipv6_addr_any(&fl6.saddr)) {
1176                 ret = ipv6_dev_get_saddr(&init_net, ip6_dst_idev(dst)->dev,
1177 -                                        &fl6.daddr, 0, &fl6.saddr);
1178 +                                        &fl6.daddr, 0, &fl6.saddr, NULL);
1179                 if (ret)
1180                         goto put;
1181  
1182 diff -NurpP --minimal linux-3.9.4/drivers/md/dm-ioctl.c linux-3.9.4-vs2.3.6.2/drivers/md/dm-ioctl.c
1183 --- linux-3.9.4/drivers/md/dm-ioctl.c   2013-05-31 13:44:59.000000000 +0000
1184 +++ linux-3.9.4-vs2.3.6.2/drivers/md/dm-ioctl.c 2013-05-31 14:47:11.000000000 +0000
1185 @@ -16,6 +16,7 @@
1186  #include <linux/dm-ioctl.h>
1187  #include <linux/hdreg.h>
1188  #include <linux/compat.h>
1189 +#include <linux/vs_context.h>
1190  
1191  #include <asm/uaccess.h>
1192  
1193 @@ -106,7 +107,8 @@ static struct hash_cell *__get_name_cell
1194         unsigned int h = hash_str(str);
1195  
1196         list_for_each_entry (hc, _name_buckets + h, name_list)
1197 -               if (!strcmp(hc->name, str)) {
1198 +               if (vx_check(dm_get_xid(hc->md), VS_WATCH_P | VS_IDENT) &&
1199 +                       !strcmp(hc->name, str)) {
1200                         dm_get(hc->md);
1201                         return hc;
1202                 }
1203 @@ -120,7 +122,8 @@ static struct hash_cell *__get_uuid_cell
1204         unsigned int h = hash_str(str);
1205  
1206         list_for_each_entry (hc, _uuid_buckets + h, uuid_list)
1207 -               if (!strcmp(hc->uuid, str)) {
1208 +               if (vx_check(dm_get_xid(hc->md), VS_WATCH_P | VS_IDENT) &&
1209 +                       !strcmp(hc->uuid, str)) {
1210                         dm_get(hc->md);
1211                         return hc;
1212                 }
1213 @@ -131,13 +134,15 @@ static struct hash_cell *__get_uuid_cell
1214  static struct hash_cell *__get_dev_cell(uint64_t dev)
1215  {
1216         struct mapped_device *md;
1217 -       struct hash_cell *hc;
1218 +       struct hash_cell *hc = NULL;
1219  
1220         md = dm_get_md(huge_decode_dev(dev));
1221         if (!md)
1222                 return NULL;
1223  
1224 -       hc = dm_get_mdptr(md);
1225 +       if (vx_check(dm_get_xid(md), VS_WATCH_P | VS_IDENT))
1226 +               hc = dm_get_mdptr(md);
1227 +
1228         if (!hc) {
1229                 dm_put(md);
1230                 return NULL;
1231 @@ -445,6 +450,9 @@ typedef int (*ioctl_fn)(struct dm_ioctl
1232  
1233  static int remove_all(struct dm_ioctl *param, size_t param_size)
1234  {
1235 +       if (!vx_check(0, VS_ADMIN))
1236 +               return -EPERM;
1237 +
1238         dm_hash_remove_all(1);
1239         param->data_size = 0;
1240         return 0;
1241 @@ -492,6 +500,8 @@ static int list_devices(struct dm_ioctl
1242          */
1243         for (i = 0; i < NUM_BUCKETS; i++) {
1244                 list_for_each_entry (hc, _name_buckets + i, name_list) {
1245 +                       if (!vx_check(dm_get_xid(hc->md), VS_WATCH_P | VS_IDENT))
1246 +                               continue;
1247                         needed += sizeof(struct dm_name_list);
1248                         needed += strlen(hc->name) + 1;
1249                         needed += ALIGN_MASK;
1250 @@ -515,6 +525,8 @@ static int list_devices(struct dm_ioctl
1251          */
1252         for (i = 0; i < NUM_BUCKETS; i++) {
1253                 list_for_each_entry (hc, _name_buckets + i, name_list) {
1254 +                       if (!vx_check(dm_get_xid(hc->md), VS_WATCH_P | VS_IDENT))
1255 +                               continue;
1256                         if (old_nl)
1257                                 old_nl->next = (uint32_t) ((void *) nl -
1258                                                            (void *) old_nl);
1259 @@ -1722,8 +1734,8 @@ static int ctl_ioctl(uint command, struc
1260         size_t input_param_size;
1261         struct dm_ioctl param_kernel;
1262  
1263 -       /* only root can play with this */
1264 -       if (!capable(CAP_SYS_ADMIN))
1265 +       /* only root and certain contexts can play with this */
1266 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_ADMIN_MAPPER))
1267                 return -EACCES;
1268  
1269         if (_IOC_TYPE(command) != DM_IOCTL)
1270 diff -NurpP --minimal linux-3.9.4/drivers/md/dm.c linux-3.9.4-vs2.3.6.2/drivers/md/dm.c
1271 --- linux-3.9.4/drivers/md/dm.c 2013-05-31 13:44:59.000000000 +0000
1272 +++ linux-3.9.4-vs2.3.6.2/drivers/md/dm.c       2013-05-31 14:47:11.000000000 +0000
1273 @@ -19,6 +19,7 @@
1274  #include <linux/idr.h>
1275  #include <linux/hdreg.h>
1276  #include <linux/delay.h>
1277 +#include <linux/vs_base.h>
1278  
1279  #include <trace/events/block.h>
1280  
1281 @@ -125,6 +126,7 @@ struct mapped_device {
1282         rwlock_t map_lock;
1283         atomic_t holders;
1284         atomic_t open_count;
1285 +       xid_t xid;
1286  
1287         unsigned long flags;
1288  
1289 @@ -317,6 +319,7 @@ int dm_deleting_md(struct mapped_device
1290  static int dm_blk_open(struct block_device *bdev, fmode_t mode)
1291  {
1292         struct mapped_device *md;
1293 +       int ret = -ENXIO;
1294  
1295         spin_lock(&_minor_lock);
1296  
1297 @@ -325,18 +328,19 @@ static int dm_blk_open(struct block_devi
1298                 goto out;
1299  
1300         if (test_bit(DMF_FREEING, &md->flags) ||
1301 -           dm_deleting_md(md)) {
1302 -               md = NULL;
1303 +           dm_deleting_md(md))
1304 +               goto out;
1305 +
1306 +       ret = -EACCES;
1307 +       if (!vx_check(md->xid, VS_IDENT|VS_HOSTID))
1308                 goto out;
1309 -       }
1310  
1311         dm_get(md);
1312         atomic_inc(&md->open_count);
1313 -
1314 +       ret = 0;
1315  out:
1316         spin_unlock(&_minor_lock);
1317 -
1318 -       return md ? 0 : -ENXIO;
1319 +       return ret;
1320  }
1321  
1322  static int dm_blk_close(struct gendisk *disk, fmode_t mode)
1323 @@ -547,6 +551,14 @@ int dm_set_geometry(struct mapped_device
1324         return 0;
1325  }
1326  
1327 +/*
1328 + * Get the xid associated with a dm device
1329 + */
1330 +xid_t dm_get_xid(struct mapped_device *md)
1331 +{
1332 +       return md->xid;
1333 +}
1334 +
1335  /*-----------------------------------------------------------------
1336   * CRUD START:
1337   *   A more elegant soln is in the works that uses the queue
1338 @@ -1884,6 +1896,7 @@ static struct mapped_device *alloc_dev(i
1339         INIT_LIST_HEAD(&md->uevent_list);
1340         spin_lock_init(&md->uevent_lock);
1341  
1342 +       md->xid = vx_current_xid();
1343         md->queue = blk_alloc_queue(GFP_KERNEL);
1344         if (!md->queue)
1345                 goto bad_queue;
1346 diff -NurpP --minimal linux-3.9.4/drivers/md/dm.h linux-3.9.4-vs2.3.6.2/drivers/md/dm.h
1347 --- linux-3.9.4/drivers/md/dm.h 2013-02-19 13:57:51.000000000 +0000
1348 +++ linux-3.9.4-vs2.3.6.2/drivers/md/dm.h       2013-05-31 14:47:11.000000000 +0000
1349 @@ -46,6 +46,8 @@ struct dm_dev_internal {
1350  struct dm_table;
1351  struct dm_md_mempools;
1352  
1353 +xid_t dm_get_xid(struct mapped_device *md);
1354 +
1355  /*-----------------------------------------------------------------
1356   * Internal table functions.
1357   *---------------------------------------------------------------*/
1358 diff -NurpP --minimal linux-3.9.4/drivers/net/tun.c linux-3.9.4-vs2.3.6.2/drivers/net/tun.c
1359 --- linux-3.9.4/drivers/net/tun.c       2013-05-31 14:22:27.000000000 +0000
1360 +++ linux-3.9.4-vs2.3.6.2/drivers/net/tun.c     2013-05-31 20:01:45.000000000 +0000
1361 @@ -64,6 +64,7 @@
1362  #include <linux/nsproxy.h>
1363  #include <linux/virtio_net.h>
1364  #include <linux/rcupdate.h>
1365 +#include <linux/vs_network.h>
1366  #include <net/net_namespace.h>
1367  #include <net/netns/generic.h>
1368  #include <net/rtnetlink.h>
1369 @@ -164,6 +165,7 @@ struct tun_struct {
1370         unsigned int            flags;
1371         kuid_t                  owner;
1372         kgid_t                  group;
1373 +       nid_t                   nid;
1374  
1375         struct net_device       *dev;
1376         netdev_features_t       set_features;
1377 @@ -380,6 +382,7 @@ static inline bool tun_not_capable(struc
1378         return ((uid_valid(tun->owner) && !uid_eq(cred->euid, tun->owner)) ||
1379                   (gid_valid(tun->group) && !in_egroup_p(tun->group))) &&
1380                 !ns_capable(net->user_ns, CAP_NET_ADMIN);
1381 +               /* !cap_raised(current_cap(), CAP_NET_ADMIN) */
1382  }
1383  
1384  static void tun_set_real_num_queues(struct tun_struct *tun)
1385 @@ -1404,6 +1407,7 @@ static void tun_setup(struct net_device
1386  
1387         tun->owner = INVALID_UID;
1388         tun->group = INVALID_GID;
1389 +       tun->nid = nx_current_nid();
1390  
1391         dev->ethtool_ops = &tun_ethtool_ops;
1392         dev->destructor = tun_free_netdev;
1393 @@ -1591,6 +1595,9 @@ static int tun_set_iff(struct net *net,
1394                 if (err < 0)
1395                         return err;
1396  
1397 +               if (!nx_check(tun->nid, VS_IDENT | VS_HOSTID | VS_ADMIN_P))
1398 +                       return -EPERM;
1399 +
1400                 err = tun_attach(tun, file);
1401                 if (err < 0)
1402                         return err;
1403 @@ -1605,7 +1612,7 @@ static int tun_set_iff(struct net *net,
1404                 int queues = ifr->ifr_flags & IFF_MULTI_QUEUE ?
1405                              MAX_TAP_QUEUES : 1;
1406  
1407 -               if (!ns_capable(net->user_ns, CAP_NET_ADMIN))
1408 +               if (!vx_ns_capable(net->user_ns, CAP_NET_ADMIN, NXC_TUN_CREATE))
1409                         return -EPERM;
1410                 err = security_tun_dev_create();
1411                 if (err < 0)
1412 @@ -1950,6 +1957,16 @@ static long __tun_chr_ioctl(struct file
1413                           from_kgid(&init_user_ns, tun->group));
1414                 break;
1415  
1416 +       case TUNSETNID:
1417 +               if (!capable(CAP_CONTEXT))
1418 +                       return -EPERM;
1419 +
1420 +               /* Set nid owner of the device */
1421 +               tun->nid = (nid_t) arg;
1422 +
1423 +               tun_debug(KERN_INFO, tun, "nid owner set to %u\n", tun->nid);
1424 +               break;
1425 +
1426         case TUNSETLINK:
1427                 /* Only allow setting the type when the interface is down */
1428                 if (tun->dev->flags & IFF_UP) {
1429 diff -NurpP --minimal linux-3.9.4/drivers/staging/csr/csr_wifi_hip_xbv.c linux-3.9.4-vs2.3.6.2/drivers/staging/csr/csr_wifi_hip_xbv.c
1430 --- linux-3.9.4/drivers/staging/csr/csr_wifi_hip_xbv.c  2013-02-19 13:58:32.000000000 +0000
1431 +++ linux-3.9.4-vs2.3.6.2/drivers/staging/csr/csr_wifi_hip_xbv.c        2013-05-31 14:47:11.000000000 +0000
1432 @@ -55,7 +55,7 @@ typedef struct
1433  {
1434      char t_name[4];
1435      u32     t_len;
1436 -} tag_t;
1437 +} ctag_t;
1438  
1439  
1440  #define TAG_EQ(i, v)    (((i)[0] == (v)[0]) &&  \
1441 @@ -90,7 +90,7 @@ typedef struct
1442      u32 ptr;
1443  } xbv_stack_t;
1444  
1445 -static s32 read_tag(card_t *card, ct_t *ct, tag_t *tag);
1446 +static s32 read_tag(card_t *card, ct_t *ct, ctag_t *tag);
1447  static s32 read_bytes(card_t *card, ct_t *ct, void *buf, u32 len);
1448  static s32 read_uint(card_t *card, ct_t *ct, u32 *u, u32 len);
1449  static s32 xbv_check(xbv1_t *fwinfo, const xbv_stack_t *stack,
1450 @@ -160,7 +160,7 @@ static u32 write_fwdl_to_ptdl(void *buf,
1451  CsrResult xbv1_parse(card_t *card, fwreadfn_t readfn, void *dlpriv, xbv1_t *fwinfo)
1452  {
1453      ct_t ct;
1454 -    tag_t tag;
1455 +    ctag_t tag;
1456      xbv_stack_t stack;
1457  
1458      ct.dlpriv = dlpriv;
1459 @@ -505,7 +505,7 @@ static u32 xbv2uint(u8 *ptr, s32 len)
1460  }
1461  
1462  
1463 -static s32 read_tag(card_t *card, ct_t *ct, tag_t *tag)
1464 +static s32 read_tag(card_t *card, ct_t *ct, ctag_t *tag)
1465  {
1466      u8 buf[8];
1467      s32 n;
1468 diff -NurpP --minimal linux-3.9.4/drivers/tty/sysrq.c linux-3.9.4-vs2.3.6.2/drivers/tty/sysrq.c
1469 --- linux-3.9.4/drivers/tty/sysrq.c     2013-05-31 13:45:19.000000000 +0000
1470 +++ linux-3.9.4-vs2.3.6.2/drivers/tty/sysrq.c   2013-05-31 15:08:19.000000000 +0000
1471 @@ -43,6 +43,7 @@
1472  #include <linux/input.h>
1473  #include <linux/uaccess.h>
1474  #include <linux/moduleparam.h>
1475 +#include <linux/vserver/debug.h>
1476  
1477  #include <asm/ptrace.h>
1478  #include <asm/irq_regs.h>
1479 @@ -401,6 +402,21 @@ static struct sysrq_key_op sysrq_unrt_op
1480         .enable_mask    = SYSRQ_ENABLE_RTNICE,
1481  };
1482  
1483 +
1484 +#ifdef CONFIG_VSERVER_DEBUG
1485 +static void sysrq_handle_vxinfo(int key)
1486 +{
1487 +       dump_vx_info_inactive((key == 'x') ? 0 : 1);
1488 +}
1489 +
1490 +static struct sysrq_key_op sysrq_showvxinfo_op = {
1491 +       .handler        = sysrq_handle_vxinfo,
1492 +       .help_msg       = "conteXt",
1493 +       .action_msg     = "Show Context Info",
1494 +       .enable_mask    = SYSRQ_ENABLE_DUMP,
1495 +};
1496 +#endif
1497 +
1498  /* Key Operations table and lock */
1499  static DEFINE_SPINLOCK(sysrq_key_table_lock);
1500  
1501 @@ -456,7 +472,11 @@ static struct sysrq_key_op *sysrq_key_ta
1502         &sysrq_showstate_blocked_op,    /* w */
1503         /* x: May be registered on ppc/powerpc for xmon */
1504         /* x: May be registered on sparc64 for global PMU dump */
1505 +#ifdef CONFIG_VSERVER_DEBUG
1506 +       &sysrq_showvxinfo_op,           /* x */
1507 +#else
1508         NULL,                           /* x */
1509 +#endif
1510         /* y: May be registered on sparc64 for global register dump */
1511         NULL,                           /* y */
1512         &sysrq_ftrace_dump_op,          /* z */
1513 @@ -471,6 +491,8 @@ static int sysrq_key_table_key2index(int
1514                 retval = key - '0';
1515         else if ((key >= 'a') && (key <= 'z'))
1516                 retval = key + 10 - 'a';
1517 +       else if ((key >= 'A') && (key <= 'Z'))
1518 +               retval = key + 10 - 'A';
1519         else
1520                 retval = -1;
1521         return retval;
1522 diff -NurpP --minimal linux-3.9.4/drivers/tty/tty_io.c linux-3.9.4-vs2.3.6.2/drivers/tty/tty_io.c
1523 --- linux-3.9.4/drivers/tty/tty_io.c    2013-05-31 14:22:27.000000000 +0000
1524 +++ linux-3.9.4-vs2.3.6.2/drivers/tty/tty_io.c  2013-05-31 14:47:11.000000000 +0000
1525 @@ -104,6 +104,7 @@
1526  
1527  #include <linux/kmod.h>
1528  #include <linux/nsproxy.h>
1529 +#include <linux/vs_pid.h>
1530  
1531  #undef TTY_DEBUG_HANGUP
1532  
1533 @@ -2144,7 +2145,8 @@ static int tiocsti(struct tty_struct *tt
1534         char ch, mbz = 0;
1535         struct tty_ldisc *ld;
1536  
1537 -       if ((current->signal->tty != tty) && !capable(CAP_SYS_ADMIN))
1538 +       if (((current->signal->tty != tty) &&
1539 +               !vx_capable(CAP_SYS_ADMIN, VXC_TIOCSTI)))
1540                 return -EPERM;
1541         if (get_user(ch, p))
1542                 return -EFAULT;
1543 @@ -2432,6 +2434,7 @@ static int tiocspgrp(struct tty_struct *
1544                 return -ENOTTY;
1545         if (get_user(pgrp_nr, p))
1546                 return -EFAULT;
1547 +       pgrp_nr = vx_rmap_pid(pgrp_nr);
1548         if (pgrp_nr < 0)
1549                 return -EINVAL;
1550         rcu_read_lock();
1551 diff -NurpP --minimal linux-3.9.4/fs/attr.c linux-3.9.4-vs2.3.6.2/fs/attr.c
1552 --- linux-3.9.4/fs/attr.c       2013-02-19 13:58:46.000000000 +0000
1553 +++ linux-3.9.4-vs2.3.6.2/fs/attr.c     2013-05-31 14:47:11.000000000 +0000
1554 @@ -15,6 +15,9 @@
1555  #include <linux/security.h>
1556  #include <linux/evm.h>
1557  #include <linux/ima.h>
1558 +#include <linux/proc_fs.h>
1559 +#include <linux/devpts_fs.h>
1560 +#include <linux/vs_tag.h>
1561  
1562  /**
1563   * inode_change_ok - check if attribute changes to an inode are allowed
1564 @@ -77,6 +80,10 @@ int inode_change_ok(const struct inode *
1565                         return -EPERM;
1566         }
1567  
1568 +       /* check for inode tag permission */
1569 +       if (dx_permission(inode, MAY_WRITE))
1570 +               return -EACCES;
1571 +
1572         return 0;
1573  }
1574  EXPORT_SYMBOL(inode_change_ok);
1575 @@ -147,6 +154,8 @@ void setattr_copy(struct inode *inode, c
1576                 inode->i_uid = attr->ia_uid;
1577         if (ia_valid & ATTR_GID)
1578                 inode->i_gid = attr->ia_gid;
1579 +       if ((ia_valid & ATTR_TAG) && IS_TAGGED(inode))
1580 +               inode->i_tag = attr->ia_tag;
1581         if (ia_valid & ATTR_ATIME)
1582                 inode->i_atime = timespec_trunc(attr->ia_atime,
1583                                                 inode->i_sb->s_time_gran);
1584 @@ -177,7 +186,8 @@ int notify_change(struct dentry * dentry
1585  
1586         WARN_ON_ONCE(!mutex_is_locked(&inode->i_mutex));
1587  
1588 -       if (ia_valid & (ATTR_MODE | ATTR_UID | ATTR_GID | ATTR_TIMES_SET)) {
1589 +       if (ia_valid & (ATTR_MODE | ATTR_UID | ATTR_GID |
1590 +               ATTR_TAG | ATTR_TIMES_SET)) {
1591                 if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
1592                         return -EPERM;
1593         }
1594 diff -NurpP --minimal linux-3.9.4/fs/block_dev.c linux-3.9.4-vs2.3.6.2/fs/block_dev.c
1595 --- linux-3.9.4/fs/block_dev.c  2013-05-31 13:45:22.000000000 +0000
1596 +++ linux-3.9.4-vs2.3.6.2/fs/block_dev.c        2013-05-31 14:47:11.000000000 +0000
1597 @@ -27,6 +27,7 @@
1598  #include <linux/namei.h>
1599  #include <linux/log2.h>
1600  #include <linux/cleancache.h>
1601 +#include <linux/vs_device.h>
1602  #include <asm/uaccess.h>
1603  #include "internal.h"
1604  
1605 @@ -528,6 +529,7 @@ struct block_device *bdget(dev_t dev)
1606                 bdev->bd_invalidated = 0;
1607                 inode->i_mode = S_IFBLK;
1608                 inode->i_rdev = dev;
1609 +               inode->i_mdev = dev;
1610                 inode->i_bdev = bdev;
1611                 inode->i_data.a_ops = &def_blk_aops;
1612                 mapping_set_gfp_mask(&inode->i_data, GFP_USER);
1613 @@ -575,6 +577,11 @@ EXPORT_SYMBOL(bdput);
1614  static struct block_device *bd_acquire(struct inode *inode)
1615  {
1616         struct block_device *bdev;
1617 +       dev_t mdev;
1618 +
1619 +       if (!vs_map_blkdev(inode->i_rdev, &mdev, DATTR_OPEN))
1620 +               return NULL;
1621 +       inode->i_mdev = mdev;
1622  
1623         spin_lock(&bdev_lock);
1624         bdev = inode->i_bdev;
1625 @@ -585,7 +592,7 @@ static struct block_device *bd_acquire(s
1626         }
1627         spin_unlock(&bdev_lock);
1628  
1629 -       bdev = bdget(inode->i_rdev);
1630 +       bdev = bdget(mdev);
1631         if (bdev) {
1632                 spin_lock(&bdev_lock);
1633                 if (!inode->i_bdev) {
1634 diff -NurpP --minimal linux-3.9.4/fs/btrfs/ctree.h linux-3.9.4-vs2.3.6.2/fs/btrfs/ctree.h
1635 --- linux-3.9.4/fs/btrfs/ctree.h        2013-05-31 13:45:22.000000000 +0000
1636 +++ linux-3.9.4-vs2.3.6.2/fs/btrfs/ctree.h      2013-05-31 14:47:11.000000000 +0000
1637 @@ -705,11 +705,14 @@ struct btrfs_inode_item {
1638         /* modification sequence number for NFS */
1639         __le64 sequence;
1640  
1641 +       __le16 tag;
1642         /*
1643          * a little future expansion, for more than this we can
1644          * just grow the inode item and version it
1645          */
1646 -       __le64 reserved[4];
1647 +       __le16 reserved16;
1648 +       __le32 reserved32;
1649 +       __le64 reserved[3];
1650         struct btrfs_timespec atime;
1651         struct btrfs_timespec ctime;
1652         struct btrfs_timespec mtime;
1653 @@ -1901,6 +1904,8 @@ struct btrfs_ioctl_defrag_range_args {
1654  #define BTRFS_MOUNT_CHECK_INTEGRITY_INCLUDING_EXTENT_DATA (1 << 21)
1655  #define BTRFS_MOUNT_PANIC_ON_FATAL_ERROR       (1 << 22)
1656  
1657 +#define BTRFS_MOUNT_TAGGED             (1 << 24)
1658 +
1659  #define btrfs_clear_opt(o, opt)                ((o) &= ~BTRFS_MOUNT_##opt)
1660  #define btrfs_set_opt(o, opt)          ((o) |= BTRFS_MOUNT_##opt)
1661  #define btrfs_raw_test_opt(o, opt)     ((o) & BTRFS_MOUNT_##opt)
1662 @@ -2170,6 +2175,7 @@ BTRFS_SETGET_FUNCS(inode_block_group, st
1663  BTRFS_SETGET_FUNCS(inode_nlink, struct btrfs_inode_item, nlink, 32);
1664  BTRFS_SETGET_FUNCS(inode_uid, struct btrfs_inode_item, uid, 32);
1665  BTRFS_SETGET_FUNCS(inode_gid, struct btrfs_inode_item, gid, 32);
1666 +BTRFS_SETGET_FUNCS(inode_tag, struct btrfs_inode_item, tag, 16);
1667  BTRFS_SETGET_FUNCS(inode_mode, struct btrfs_inode_item, mode, 32);
1668  BTRFS_SETGET_FUNCS(inode_rdev, struct btrfs_inode_item, rdev, 64);
1669  BTRFS_SETGET_FUNCS(inode_flags, struct btrfs_inode_item, flags, 64);
1670 @@ -2223,6 +2229,10 @@ BTRFS_SETGET_FUNCS(extent_flags, struct
1671  
1672  BTRFS_SETGET_FUNCS(extent_refs_v0, struct btrfs_extent_item_v0, refs, 32);
1673  
1674 +#define BTRFS_INODE_IXUNLINK           (1 << 24)
1675 +#define BTRFS_INODE_BARRIER            (1 << 25)
1676 +#define BTRFS_INODE_COW                        (1 << 26)
1677 +
1678  
1679  BTRFS_SETGET_FUNCS(tree_block_level, struct btrfs_tree_block_info, level, 8);
1680  
1681 @@ -3581,6 +3591,7 @@ extern const struct dentry_operations bt
1682  long btrfs_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
1683  void btrfs_update_iflags(struct inode *inode);
1684  void btrfs_inherit_iflags(struct inode *inode, struct inode *dir);
1685 +int btrfs_sync_flags(struct inode *inode, int, int);
1686  int btrfs_defrag_file(struct inode *inode, struct file *file,
1687                       struct btrfs_ioctl_defrag_range_args *range,
1688                       u64 newer_than, unsigned long max_pages);
1689 diff -NurpP --minimal linux-3.9.4/fs/btrfs/disk-io.c linux-3.9.4-vs2.3.6.2/fs/btrfs/disk-io.c
1690 --- linux-3.9.4/fs/btrfs/disk-io.c      2013-05-31 13:45:22.000000000 +0000
1691 +++ linux-3.9.4-vs2.3.6.2/fs/btrfs/disk-io.c    2013-05-31 14:47:11.000000000 +0000
1692 @@ -2258,6 +2258,9 @@ int open_ctree(struct super_block *sb,
1693                 goto fail_alloc;
1694         }
1695  
1696 +       if (btrfs_test_opt(tree_root, TAGGED))
1697 +               sb->s_flags |= MS_TAGGED;
1698 +
1699         features = btrfs_super_incompat_flags(disk_super) &
1700                 ~BTRFS_FEATURE_INCOMPAT_SUPP;
1701         if (features) {
1702 diff -NurpP --minimal linux-3.9.4/fs/btrfs/inode.c linux-3.9.4-vs2.3.6.2/fs/btrfs/inode.c
1703 --- linux-3.9.4/fs/btrfs/inode.c        2013-05-31 14:22:27.000000000 +0000
1704 +++ linux-3.9.4-vs2.3.6.2/fs/btrfs/inode.c      2013-05-31 20:42:33.000000000 +0000
1705 @@ -41,6 +41,7 @@
1706  #include <linux/mount.h>
1707  #include <linux/btrfs.h>
1708  #include <linux/blkdev.h>
1709 +#include <linux/vs_tag.h>
1710  #include "compat.h"
1711  #include "ctree.h"
1712  #include "disk-io.h"
1713 @@ -3312,6 +3313,8 @@ static void btrfs_read_locked_inode(stru
1714         struct btrfs_key location;
1715         int maybe_acls;
1716         u32 rdev;
1717 +       uid_t uid;
1718 +       gid_t gid;
1719         int ret;
1720         bool filled = false;
1721  
1722 @@ -3339,8 +3342,13 @@ static void btrfs_read_locked_inode(stru
1723                                     struct btrfs_inode_item);
1724         inode->i_mode = btrfs_inode_mode(leaf, inode_item);
1725         set_nlink(inode, btrfs_inode_nlink(leaf, inode_item));
1726 -       i_uid_write(inode, btrfs_inode_uid(leaf, inode_item));
1727 -       i_gid_write(inode, btrfs_inode_gid(leaf, inode_item));
1728 +
1729 +       uid = btrfs_inode_uid(leaf, inode_item);
1730 +       gid = btrfs_inode_gid(leaf, inode_item);
1731 +       i_uid_write(inode, INOTAG_UID(DX_TAG(inode), uid, gid));
1732 +       i_gid_write(inode, INOTAG_GID(DX_TAG(inode), uid, gid));
1733 +       i_tag_write(inode, INOTAG_TAG(DX_TAG(inode), uid, gid,
1734 +               btrfs_inode_tag(leaf, inode_item)));
1735         btrfs_i_size_write(inode, btrfs_inode_size(leaf, inode_item));
1736  
1737         tspec = btrfs_inode_atime(inode_item);
1738 @@ -3431,11 +3439,18 @@ static void fill_inode_item(struct btrfs
1739                             struct inode *inode)
1740  {
1741         struct btrfs_map_token token;
1742 +       uid_t uid = TAGINO_UID(DX_TAG(inode),
1743 +               i_uid_read(inode), i_tag_read(inode));
1744 +       gid_t gid = TAGINO_GID(DX_TAG(inode),
1745 +               i_gid_read(inode), i_tag_read(inode));
1746  
1747         btrfs_init_map_token(&token);
1748  
1749 -       btrfs_set_token_inode_uid(leaf, item, i_uid_read(inode), &token);
1750 -       btrfs_set_token_inode_gid(leaf, item, i_gid_read(inode), &token);
1751 +       btrfs_set_token_inode_uid(leaf, item, uid, &token);
1752 +       btrfs_set_token_inode_gid(leaf, item, gid, &token);
1753 +#ifdef CONFIG_TAGGING_INTERN
1754 +       btrfs_set_token_inode_tag(leaf, item, i_tag_read(inode), &token);
1755 +#endif
1756         btrfs_set_token_inode_size(leaf, item, BTRFS_I(inode)->disk_i_size,
1757                                    &token);
1758         btrfs_set_token_inode_mode(leaf, item, inode->i_mode, &token);
1759 @@ -8683,11 +8698,13 @@ static const struct inode_operations btr
1760         .listxattr      = btrfs_listxattr,
1761         .removexattr    = btrfs_removexattr,
1762         .permission     = btrfs_permission,
1763 +       .sync_flags     = btrfs_sync_flags,
1764         .get_acl        = btrfs_get_acl,
1765  };
1766  static const struct inode_operations btrfs_dir_ro_inode_operations = {
1767         .lookup         = btrfs_lookup,
1768         .permission     = btrfs_permission,
1769 +       .sync_flags     = btrfs_sync_flags,
1770         .get_acl        = btrfs_get_acl,
1771  };
1772  
1773 diff -NurpP --minimal linux-3.9.4/fs/btrfs/ioctl.c linux-3.9.4-vs2.3.6.2/fs/btrfs/ioctl.c
1774 --- linux-3.9.4/fs/btrfs/ioctl.c        2013-05-31 14:22:27.000000000 +0000
1775 +++ linux-3.9.4-vs2.3.6.2/fs/btrfs/ioctl.c      2013-05-31 14:47:11.000000000 +0000
1776 @@ -75,10 +75,13 @@ static unsigned int btrfs_flags_to_ioctl
1777  {
1778         unsigned int iflags = 0;
1779  
1780 -       if (flags & BTRFS_INODE_SYNC)
1781 -               iflags |= FS_SYNC_FL;
1782         if (flags & BTRFS_INODE_IMMUTABLE)
1783                 iflags |= FS_IMMUTABLE_FL;
1784 +       if (flags & BTRFS_INODE_IXUNLINK)
1785 +               iflags |= FS_IXUNLINK_FL;
1786 +
1787 +       if (flags & BTRFS_INODE_SYNC)
1788 +               iflags |= FS_SYNC_FL;
1789         if (flags & BTRFS_INODE_APPEND)
1790                 iflags |= FS_APPEND_FL;
1791         if (flags & BTRFS_INODE_NODUMP)
1792 @@ -95,28 +98,78 @@ static unsigned int btrfs_flags_to_ioctl
1793         else if (flags & BTRFS_INODE_NOCOMPRESS)
1794                 iflags |= FS_NOCOMP_FL;
1795  
1796 +       if (flags & BTRFS_INODE_BARRIER)
1797 +               iflags |= FS_BARRIER_FL;
1798 +       if (flags & BTRFS_INODE_COW)
1799 +               iflags |= FS_COW_FL;
1800         return iflags;
1801  }
1802  
1803  /*
1804 - * Update inode->i_flags based on the btrfs internal flags.
1805 + * Update inode->i_(v)flags based on the btrfs internal flags.
1806   */
1807  void btrfs_update_iflags(struct inode *inode)
1808  {
1809         struct btrfs_inode *ip = BTRFS_I(inode);
1810  
1811 -       inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
1812 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
1813 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
1814  
1815 -       if (ip->flags & BTRFS_INODE_SYNC)
1816 -               inode->i_flags |= S_SYNC;
1817         if (ip->flags & BTRFS_INODE_IMMUTABLE)
1818                 inode->i_flags |= S_IMMUTABLE;
1819 +       if (ip->flags & BTRFS_INODE_IXUNLINK)
1820 +               inode->i_flags |= S_IXUNLINK;
1821 +
1822 +       if (ip->flags & BTRFS_INODE_SYNC)
1823 +               inode->i_flags |= S_SYNC;
1824         if (ip->flags & BTRFS_INODE_APPEND)
1825                 inode->i_flags |= S_APPEND;
1826         if (ip->flags & BTRFS_INODE_NOATIME)
1827                 inode->i_flags |= S_NOATIME;
1828         if (ip->flags & BTRFS_INODE_DIRSYNC)
1829                 inode->i_flags |= S_DIRSYNC;
1830 +
1831 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
1832 +
1833 +       if (ip->flags & BTRFS_INODE_BARRIER)
1834 +               inode->i_vflags |= V_BARRIER;
1835 +       if (ip->flags & BTRFS_INODE_COW)
1836 +               inode->i_vflags |= V_COW;
1837 +}
1838 +
1839 +/*
1840 + * Update btrfs internal flags from inode->i_(v)flags.
1841 + */
1842 +void btrfs_update_flags(struct inode *inode)
1843 +{
1844 +       struct btrfs_inode *ip = BTRFS_I(inode);
1845 +
1846 +       unsigned int flags = inode->i_flags;
1847 +       unsigned int vflags = inode->i_vflags;
1848 +
1849 +       ip->flags &= ~(BTRFS_INODE_SYNC | BTRFS_INODE_APPEND |
1850 +                       BTRFS_INODE_IMMUTABLE | BTRFS_INODE_IXUNLINK |
1851 +                       BTRFS_INODE_NOATIME | BTRFS_INODE_DIRSYNC |
1852 +                       BTRFS_INODE_BARRIER | BTRFS_INODE_COW);
1853 +
1854 +       if (flags & S_IMMUTABLE)
1855 +               ip->flags |= BTRFS_INODE_IMMUTABLE;
1856 +       if (flags & S_IXUNLINK)
1857 +               ip->flags |= BTRFS_INODE_IXUNLINK;
1858 +
1859 +       if (flags & S_SYNC)
1860 +               ip->flags |= BTRFS_INODE_SYNC;
1861 +       if (flags & S_APPEND)
1862 +               ip->flags |= BTRFS_INODE_APPEND;
1863 +       if (flags & S_NOATIME)
1864 +               ip->flags |= BTRFS_INODE_NOATIME;
1865 +       if (flags & S_DIRSYNC)
1866 +               ip->flags |= BTRFS_INODE_DIRSYNC;
1867 +
1868 +       if (vflags & V_BARRIER)
1869 +               ip->flags |= BTRFS_INODE_BARRIER;
1870 +       if (vflags & V_COW)
1871 +               ip->flags |= BTRFS_INODE_COW;
1872  }
1873  
1874  /*
1875 @@ -132,6 +185,7 @@ void btrfs_inherit_iflags(struct inode *
1876                 return;
1877  
1878         flags = BTRFS_I(dir)->flags;
1879 +       flags &= ~BTRFS_INODE_BARRIER;
1880  
1881         if (flags & BTRFS_INODE_NOCOMPRESS) {
1882                 BTRFS_I(inode)->flags &= ~BTRFS_INODE_COMPRESS;
1883 @@ -150,6 +204,30 @@ void btrfs_inherit_iflags(struct inode *
1884         btrfs_update_iflags(inode);
1885  }
1886  
1887 +int btrfs_sync_flags(struct inode *inode, int flags, int vflags)
1888 +{
1889 +       struct btrfs_inode *ip = BTRFS_I(inode);
1890 +       struct btrfs_root *root = ip->root;
1891 +       struct btrfs_trans_handle *trans;
1892 +       int ret;
1893 +
1894 +       trans = btrfs_join_transaction(root);
1895 +       BUG_ON(!trans);
1896 +
1897 +       inode->i_flags = flags;
1898 +       inode->i_vflags = vflags;
1899 +       btrfs_update_flags(inode);
1900 +
1901 +       ret = btrfs_update_inode(trans, root, inode);
1902 +       BUG_ON(ret);
1903 +
1904 +       btrfs_update_iflags(inode);
1905 +       inode->i_ctime = CURRENT_TIME;
1906 +       btrfs_end_transaction(trans, root);
1907 +
1908 +       return 0;
1909 +}
1910 +
1911  static int btrfs_ioctl_getflags(struct file *file, void __user *arg)
1912  {
1913         struct btrfs_inode *ip = BTRFS_I(file_inode(file));
1914 @@ -212,21 +290,27 @@ static int btrfs_ioctl_setflags(struct f
1915  
1916         flags = btrfs_mask_flags(inode->i_mode, flags);
1917         oldflags = btrfs_flags_to_ioctl(ip->flags);
1918 -       if ((flags ^ oldflags) & (FS_APPEND_FL | FS_IMMUTABLE_FL)) {
1919 +       if ((flags ^ oldflags) & (FS_APPEND_FL |
1920 +               FS_IMMUTABLE_FL | FS_IXUNLINK_FL)) {
1921                 if (!capable(CAP_LINUX_IMMUTABLE)) {
1922                         ret = -EPERM;
1923                         goto out_unlock;
1924                 }
1925         }
1926  
1927 -       if (flags & FS_SYNC_FL)
1928 -               ip->flags |= BTRFS_INODE_SYNC;
1929 -       else
1930 -               ip->flags &= ~BTRFS_INODE_SYNC;
1931         if (flags & FS_IMMUTABLE_FL)
1932                 ip->flags |= BTRFS_INODE_IMMUTABLE;
1933         else
1934                 ip->flags &= ~BTRFS_INODE_IMMUTABLE;
1935 +       if (flags & FS_IXUNLINK_FL)
1936 +               ip->flags |= BTRFS_INODE_IXUNLINK;
1937 +       else
1938 +               ip->flags &= ~BTRFS_INODE_IXUNLINK;
1939 +
1940 +       if (flags & FS_SYNC_FL)
1941 +               ip->flags |= BTRFS_INODE_SYNC;
1942 +       else
1943 +               ip->flags &= ~BTRFS_INODE_SYNC;
1944         if (flags & FS_APPEND_FL)
1945                 ip->flags |= BTRFS_INODE_APPEND;
1946         else
1947 diff -NurpP --minimal linux-3.9.4/fs/btrfs/super.c linux-3.9.4-vs2.3.6.2/fs/btrfs/super.c
1948 --- linux-3.9.4/fs/btrfs/super.c        2013-05-31 13:45:22.000000000 +0000
1949 +++ linux-3.9.4-vs2.3.6.2/fs/btrfs/super.c      2013-05-31 14:47:11.000000000 +0000
1950 @@ -321,7 +321,7 @@ enum {
1951         Opt_no_space_cache, Opt_recovery, Opt_skip_balance,
1952         Opt_check_integrity, Opt_check_integrity_including_extent_data,
1953         Opt_check_integrity_print_mask, Opt_fatal_errors,
1954 -       Opt_err,
1955 +       Opt_tag, Opt_notag, Opt_tagid, Opt_err,
1956  };
1957  
1958  static match_table_t tokens = {
1959 @@ -361,6 +361,9 @@ static match_table_t tokens = {
1960         {Opt_check_integrity_including_extent_data, "check_int_data"},
1961         {Opt_check_integrity_print_mask, "check_int_print_mask=%d"},
1962         {Opt_fatal_errors, "fatal_errors=%s"},
1963 +       {Opt_tag, "tag"},
1964 +       {Opt_notag, "notag"},
1965 +       {Opt_tagid, "tagid=%u"},
1966         {Opt_err, NULL},
1967  };
1968  
1969 @@ -626,6 +629,22 @@ int btrfs_parse_options(struct btrfs_roo
1970                                 goto out;
1971                         }
1972                         break;
1973 +#ifndef CONFIG_TAGGING_NONE
1974 +               case Opt_tag:
1975 +                       printk(KERN_INFO "btrfs: use tagging\n");
1976 +                       btrfs_set_opt(info->mount_opt, TAGGED);
1977 +                       break;
1978 +               case Opt_notag:
1979 +                       printk(KERN_INFO "btrfs: disabled tagging\n");
1980 +                       btrfs_clear_opt(info->mount_opt, TAGGED);
1981 +                       break;
1982 +#endif
1983 +#ifdef CONFIG_PROPAGATE
1984 +               case Opt_tagid:
1985 +                       /* use args[0] */
1986 +                       btrfs_set_opt(info->mount_opt, TAGGED);
1987 +                       break;
1988 +#endif
1989                 case Opt_err:
1990                         printk(KERN_INFO "btrfs: unrecognized mount option "
1991                                "'%s'\n", p);
1992 @@ -1258,6 +1277,12 @@ static int btrfs_remount(struct super_bl
1993         btrfs_resize_thread_pool(fs_info,
1994                 fs_info->thread_pool_size, old_thread_pool_size);
1995  
1996 +       if (btrfs_test_opt(root, TAGGED) && !(sb->s_flags & MS_TAGGED)) {
1997 +               printk("btrfs: %s: tagging not permitted on remount.\n",
1998 +                       sb->s_id);
1999 +               return -EINVAL;
2000 +       }
2001 +
2002         if ((*flags & MS_RDONLY) == (sb->s_flags & MS_RDONLY))
2003                 goto out;
2004  
2005 diff -NurpP --minimal linux-3.9.4/fs/char_dev.c linux-3.9.4-vs2.3.6.2/fs/char_dev.c
2006 --- linux-3.9.4/fs/char_dev.c   2012-12-11 03:30:57.000000000 +0000
2007 +++ linux-3.9.4-vs2.3.6.2/fs/char_dev.c 2013-05-31 14:47:11.000000000 +0000
2008 @@ -21,6 +21,8 @@
2009  #include <linux/mutex.h>
2010  #include <linux/backing-dev.h>
2011  #include <linux/tty.h>
2012 +#include <linux/vs_context.h>
2013 +#include <linux/vs_device.h>
2014  
2015  #include "internal.h"
2016  
2017 @@ -371,14 +373,21 @@ static int chrdev_open(struct inode *ino
2018         struct cdev *p;
2019         struct cdev *new = NULL;
2020         int ret = 0;
2021 +       dev_t mdev;
2022 +
2023 +       if (!vs_map_chrdev(inode->i_rdev, &mdev, DATTR_OPEN))
2024 +               return -EPERM;
2025 +       inode->i_mdev = mdev;
2026  
2027         spin_lock(&cdev_lock);
2028         p = inode->i_cdev;
2029         if (!p) {
2030                 struct kobject *kobj;
2031                 int idx;
2032 +
2033                 spin_unlock(&cdev_lock);
2034 -               kobj = kobj_lookup(cdev_map, inode->i_rdev, &idx);
2035 +
2036 +               kobj = kobj_lookup(cdev_map, mdev, &idx);
2037                 if (!kobj)
2038                         return -ENXIO;
2039                 new = container_of(kobj, struct cdev, kobj);
2040 diff -NurpP --minimal linux-3.9.4/fs/dcache.c linux-3.9.4-vs2.3.6.2/fs/dcache.c
2041 --- linux-3.9.4/fs/dcache.c     2013-05-31 14:22:27.000000000 +0000
2042 +++ linux-3.9.4-vs2.3.6.2/fs/dcache.c   2013-05-31 14:47:11.000000000 +0000
2043 @@ -37,6 +37,7 @@
2044  #include <linux/rculist_bl.h>
2045  #include <linux/prefetch.h>
2046  #include <linux/ratelimit.h>
2047 +#include <linux/vs_limit.h>
2048  #include "internal.h"
2049  #include "mount.h"
2050  
2051 @@ -593,6 +594,8 @@ int d_invalidate(struct dentry * dentry)
2052                 spin_lock(&dentry->d_lock);
2053         }
2054  
2055 +       vx_dentry_dec(dentry);
2056 +
2057         /*
2058          * Somebody else still using it?
2059          *
2060 @@ -622,6 +625,7 @@ EXPORT_SYMBOL(d_invalidate);
2061  static inline void __dget_dlock(struct dentry *dentry)
2062  {
2063         dentry->d_count++;
2064 +       vx_dentry_inc(dentry);
2065  }
2066  
2067  static inline void __dget(struct dentry *dentry)
2068 @@ -1252,6 +1256,9 @@ struct dentry *__d_alloc(struct super_bl
2069         struct dentry *dentry;
2070         char *dname;
2071  
2072 +       if (!vx_dentry_avail(1))
2073 +               return NULL;
2074 +
2075         dentry = kmem_cache_alloc(dentry_cache, GFP_KERNEL);
2076         if (!dentry)
2077                 return NULL;
2078 @@ -1284,6 +1291,7 @@ struct dentry *__d_alloc(struct super_bl
2079  
2080         dentry->d_count = 1;
2081         dentry->d_flags = 0;
2082 +       vx_dentry_inc(dentry);
2083         spin_lock_init(&dentry->d_lock);
2084         seqcount_init(&dentry->d_seq);
2085         dentry->d_inode = NULL;
2086 @@ -1984,6 +1992,7 @@ struct dentry *__d_lookup(const struct d
2087                 }
2088  
2089                 dentry->d_count++;
2090 +               vx_dentry_inc(dentry);
2091                 found = dentry;
2092                 spin_unlock(&dentry->d_lock);
2093                 break;
2094 diff -NurpP --minimal linux-3.9.4/fs/devpts/inode.c linux-3.9.4-vs2.3.6.2/fs/devpts/inode.c
2095 --- linux-3.9.4/fs/devpts/inode.c       2013-05-31 13:45:23.000000000 +0000
2096 +++ linux-3.9.4-vs2.3.6.2/fs/devpts/inode.c     2013-05-31 15:42:25.000000000 +0000
2097 @@ -25,6 +25,7 @@
2098  #include <linux/parser.h>
2099  #include <linux/fsnotify.h>
2100  #include <linux/seq_file.h>
2101 +#include <linux/vs_base.h>
2102  
2103  #define DEVPTS_DEFAULT_MODE 0600
2104  /*
2105 @@ -36,6 +37,21 @@
2106  #define DEVPTS_DEFAULT_PTMX_MODE 0000
2107  #define PTMX_MINOR     2
2108  
2109 +static int devpts_permission(struct inode *inode, int mask)
2110 +{
2111 +       int ret = -EACCES;
2112 +
2113 +       /* devpts is xid tagged */
2114 +       if (vx_check((xid_t)i_tag_read(inode), VS_WATCH_P | VS_IDENT))
2115 +               ret = generic_permission(inode, mask);
2116 +       return ret;
2117 +}
2118 +
2119 +static struct inode_operations devpts_file_inode_operations = {
2120 +       .permission     = devpts_permission,
2121 +};
2122 +
2123 +
2124  /*
2125   * sysctl support for setting limits on the number of Unix98 ptys allocated.
2126   * Otherwise one can eat up all kernel memory by opening /dev/ptmx repeatedly.
2127 @@ -345,6 +361,34 @@ static int devpts_show_options(struct se
2128         return 0;
2129  }
2130  
2131 +static int devpts_filter(struct dentry *de)
2132 +{
2133 +       xid_t xid = 0;
2134 +
2135 +       /* devpts is xid tagged */
2136 +       if (de && de->d_inode)
2137 +               xid = (xid_t)i_tag_read(de->d_inode);
2138 +#ifdef CONFIG_VSERVER_WARN_DEVPTS
2139 +       else
2140 +               vxwprintk_task(1, "devpts " VS_Q("%.*s") " without inode.",
2141 +                       de->d_name.len, de->d_name.name);
2142 +#endif
2143 +       return vx_check(xid, VS_WATCH_P | VS_IDENT);
2144 +}
2145 +
2146 +static int devpts_readdir(struct file * filp, void * dirent, filldir_t filldir)
2147 +{
2148 +       return dcache_readdir_filter(filp, dirent, filldir, devpts_filter);
2149 +}
2150 +
2151 +static struct file_operations devpts_dir_operations = {
2152 +       .open           = dcache_dir_open,
2153 +       .release        = dcache_dir_close,
2154 +       .llseek         = dcache_dir_lseek,
2155 +       .read           = generic_read_dir,
2156 +       .readdir        = devpts_readdir,
2157 +};
2158 +
2159  static const struct super_operations devpts_sops = {
2160         .statfs         = simple_statfs,
2161         .remount_fs     = devpts_remount,
2162 @@ -388,8 +432,10 @@ devpts_fill_super(struct super_block *s,
2163         inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
2164         inode->i_mode = S_IFDIR | S_IRUGO | S_IXUGO | S_IWUSR;
2165         inode->i_op = &simple_dir_inode_operations;
2166 -       inode->i_fop = &simple_dir_operations;
2167 +       inode->i_fop = &devpts_dir_operations;
2168         set_nlink(inode, 2);
2169 +       /* devpts is xid tagged */
2170 +       i_tag_write(inode, (tag_t)vx_current_xid());
2171  
2172         s->s_root = d_make_root(inode);
2173         if (s->s_root)
2174 @@ -592,6 +638,9 @@ struct inode *devpts_pty_new(struct inod
2175         inode->i_gid = opts->setgid ? opts->gid : current_fsgid();
2176         inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
2177         init_special_inode(inode, S_IFCHR|opts->mode, device);
2178 +       /* devpts is xid tagged */
2179 +       i_tag_write(inode, (tag_t)vx_current_xid());
2180 +       inode->i_op = &devpts_file_inode_operations;
2181         inode->i_private = priv;
2182  
2183         sprintf(s, "%d", index);
2184 diff -NurpP --minimal linux-3.9.4/fs/ext2/balloc.c linux-3.9.4-vs2.3.6.2/fs/ext2/balloc.c
2185 --- linux-3.9.4/fs/ext2/balloc.c        2013-05-31 13:45:23.000000000 +0000
2186 +++ linux-3.9.4-vs2.3.6.2/fs/ext2/balloc.c      2013-05-31 14:47:11.000000000 +0000
2187 @@ -693,7 +693,6 @@ ext2_try_to_allocate(struct super_block
2188                         start = 0;
2189                 end = EXT2_BLOCKS_PER_GROUP(sb);
2190         }
2191 -
2192         BUG_ON(start > EXT2_BLOCKS_PER_GROUP(sb));
2193  
2194  repeat:
2195 diff -NurpP --minimal linux-3.9.4/fs/ext2/ext2.h linux-3.9.4-vs2.3.6.2/fs/ext2/ext2.h
2196 --- linux-3.9.4/fs/ext2/ext2.h  2012-12-11 03:30:57.000000000 +0000
2197 +++ linux-3.9.4-vs2.3.6.2/fs/ext2/ext2.h        2013-05-31 14:47:11.000000000 +0000
2198 @@ -244,8 +244,12 @@ struct ext2_group_desc
2199  #define EXT2_NOTAIL_FL                 FS_NOTAIL_FL    /* file tail should not be merged */
2200  #define EXT2_DIRSYNC_FL                        FS_DIRSYNC_FL   /* dirsync behaviour (directories only) */
2201  #define EXT2_TOPDIR_FL                 FS_TOPDIR_FL    /* Top of directory hierarchies*/
2202 +#define EXT2_IXUNLINK_FL               FS_IXUNLINK_FL  /* Immutable invert on unlink */
2203  #define EXT2_RESERVED_FL               FS_RESERVED_FL  /* reserved for ext2 lib */
2204  
2205 +#define EXT2_BARRIER_FL                        FS_BARRIER_FL   /* Barrier for chroot() */
2206 +#define EXT2_COW_FL                    FS_COW_FL       /* Copy on Write marker */
2207 +
2208  #define EXT2_FL_USER_VISIBLE           FS_FL_USER_VISIBLE      /* User visible flags */
2209  #define EXT2_FL_USER_MODIFIABLE                FS_FL_USER_MODIFIABLE   /* User modifiable flags */
2210  
2211 @@ -329,7 +333,8 @@ struct ext2_inode {
2212                         __u16   i_pad1;
2213                         __le16  l_i_uid_high;   /* these 2 fields    */
2214                         __le16  l_i_gid_high;   /* were reserved2[0] */
2215 -                       __u32   l_i_reserved2;
2216 +                       __le16  l_i_tag;        /* Context Tag */
2217 +                       __u16   l_i_reserved2;
2218                 } linux2;
2219                 struct {
2220                         __u8    h_i_frag;       /* Fragment number */
2221 @@ -357,6 +362,7 @@ struct ext2_inode {
2222  #define i_gid_low      i_gid
2223  #define i_uid_high     osd2.linux2.l_i_uid_high
2224  #define i_gid_high     osd2.linux2.l_i_gid_high
2225 +#define i_raw_tag      osd2.linux2.l_i_tag
2226  #define i_reserved2    osd2.linux2.l_i_reserved2
2227  
2228  /*
2229 @@ -384,6 +390,7 @@ struct ext2_inode {
2230  #define EXT2_MOUNT_USRQUOTA            0x020000  /* user quota */
2231  #define EXT2_MOUNT_GRPQUOTA            0x040000  /* group quota */
2232  #define EXT2_MOUNT_RESERVATION         0x080000  /* Preallocation */
2233 +#define EXT2_MOUNT_TAGGED              (1<<24)   /* Enable Context Tags */
2234  
2235  
2236  #define clear_opt(o, opt)              o &= ~EXT2_MOUNT_##opt
2237 @@ -757,6 +764,7 @@ extern void ext2_set_inode_flags(struct
2238  extern void ext2_get_inode_flags(struct ext2_inode_info *);
2239  extern int ext2_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
2240                        u64 start, u64 len);
2241 +extern int ext2_sync_flags(struct inode *, int, int);
2242  
2243  /* ioctl.c */
2244  extern long ext2_ioctl(struct file *, unsigned int, unsigned long);
2245 diff -NurpP --minimal linux-3.9.4/fs/ext2/file.c linux-3.9.4-vs2.3.6.2/fs/ext2/file.c
2246 --- linux-3.9.4/fs/ext2/file.c  2012-12-11 03:30:57.000000000 +0000
2247 +++ linux-3.9.4-vs2.3.6.2/fs/ext2/file.c        2013-05-31 14:47:11.000000000 +0000
2248 @@ -104,4 +104,5 @@ const struct inode_operations ext2_file_
2249         .setattr        = ext2_setattr,
2250         .get_acl        = ext2_get_acl,
2251         .fiemap         = ext2_fiemap,
2252 +       .sync_flags     = ext2_sync_flags,
2253  };
2254 diff -NurpP --minimal linux-3.9.4/fs/ext2/ialloc.c linux-3.9.4-vs2.3.6.2/fs/ext2/ialloc.c
2255 --- linux-3.9.4/fs/ext2/ialloc.c        2013-05-31 13:45:23.000000000 +0000
2256 +++ linux-3.9.4-vs2.3.6.2/fs/ext2/ialloc.c      2013-06-01 09:31:28.000000000 +0000
2257 @@ -17,6 +17,7 @@
2258  #include <linux/backing-dev.h>
2259  #include <linux/buffer_head.h>
2260  #include <linux/random.h>
2261 +#include <linux/vs_tag.h>
2262  #include "ext2.h"
2263  #include "xattr.h"
2264  #include "acl.h"
2265 @@ -546,6 +547,8 @@ got:
2266                 inode->i_mode = mode;
2267                 inode->i_uid = current_fsuid();
2268                 inode->i_gid = dir->i_gid;
2269 +               inode->i_tag = make_ktag(&init_user_ns,
2270 +                       dx_current_fstag(sb));
2271         } else
2272                 inode_init_owner(inode, dir, mode);
2273  
2274 diff -NurpP --minimal linux-3.9.4/fs/ext2/inode.c linux-3.9.4-vs2.3.6.2/fs/ext2/inode.c
2275 --- linux-3.9.4/fs/ext2/inode.c 2013-05-31 13:45:23.000000000 +0000
2276 +++ linux-3.9.4-vs2.3.6.2/fs/ext2/inode.c       2013-05-31 14:47:11.000000000 +0000
2277 @@ -31,6 +31,7 @@
2278  #include <linux/mpage.h>
2279  #include <linux/fiemap.h>
2280  #include <linux/namei.h>
2281 +#include <linux/vs_tag.h>
2282  #include "ext2.h"
2283  #include "acl.h"
2284  #include "xip.h"
2285 @@ -1179,7 +1180,7 @@ static void ext2_truncate_blocks(struct
2286                 return;
2287         if (ext2_inode_is_fast_symlink(inode))
2288                 return;
2289 -       if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
2290 +       if (IS_APPEND(inode) || IS_IXORUNLINK(inode))
2291                 return;
2292         __ext2_truncate_blocks(inode, offset);
2293  }
2294 @@ -1270,36 +1271,61 @@ void ext2_set_inode_flags(struct inode *
2295  {
2296         unsigned int flags = EXT2_I(inode)->i_flags;
2297  
2298 -       inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
2299 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
2300 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
2301 +
2302 +
2303 +       if (flags & EXT2_IMMUTABLE_FL)
2304 +               inode->i_flags |= S_IMMUTABLE;
2305 +       if (flags & EXT2_IXUNLINK_FL)
2306 +               inode->i_flags |= S_IXUNLINK;
2307 +
2308         if (flags & EXT2_SYNC_FL)
2309                 inode->i_flags |= S_SYNC;
2310         if (flags & EXT2_APPEND_FL)
2311                 inode->i_flags |= S_APPEND;
2312 -       if (flags & EXT2_IMMUTABLE_FL)
2313 -               inode->i_flags |= S_IMMUTABLE;
2314         if (flags & EXT2_NOATIME_FL)
2315                 inode->i_flags |= S_NOATIME;
2316         if (flags & EXT2_DIRSYNC_FL)
2317                 inode->i_flags |= S_DIRSYNC;
2318 +
2319 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
2320 +
2321 +       if (flags & EXT2_BARRIER_FL)
2322 +               inode->i_vflags |= V_BARRIER;
2323 +       if (flags & EXT2_COW_FL)
2324 +               inode->i_vflags |= V_COW;
2325  }
2326  
2327  /* Propagate flags from i_flags to EXT2_I(inode)->i_flags */
2328  void ext2_get_inode_flags(struct ext2_inode_info *ei)
2329  {
2330         unsigned int flags = ei->vfs_inode.i_flags;
2331 +       unsigned int vflags = ei->vfs_inode.i_vflags;
2332 +
2333 +       ei->i_flags &= ~(EXT2_SYNC_FL | EXT2_APPEND_FL |
2334 +                       EXT2_IMMUTABLE_FL | EXT2_IXUNLINK_FL |
2335 +                       EXT2_NOATIME_FL | EXT2_DIRSYNC_FL |
2336 +                       EXT2_BARRIER_FL | EXT2_COW_FL);
2337 +
2338 +       if (flags & S_IMMUTABLE)
2339 +               ei->i_flags |= EXT2_IMMUTABLE_FL;
2340 +       if (flags & S_IXUNLINK)
2341 +               ei->i_flags |= EXT2_IXUNLINK_FL;
2342  
2343 -       ei->i_flags &= ~(EXT2_SYNC_FL|EXT2_APPEND_FL|
2344 -                       EXT2_IMMUTABLE_FL|EXT2_NOATIME_FL|EXT2_DIRSYNC_FL);
2345         if (flags & S_SYNC)
2346                 ei->i_flags |= EXT2_SYNC_FL;
2347         if (flags & S_APPEND)
2348                 ei->i_flags |= EXT2_APPEND_FL;
2349 -       if (flags & S_IMMUTABLE)
2350 -               ei->i_flags |= EXT2_IMMUTABLE_FL;
2351         if (flags & S_NOATIME)
2352                 ei->i_flags |= EXT2_NOATIME_FL;
2353         if (flags & S_DIRSYNC)
2354                 ei->i_flags |= EXT2_DIRSYNC_FL;
2355 +
2356 +       if (vflags & V_BARRIER)
2357 +               ei->i_flags |= EXT2_BARRIER_FL;
2358 +       if (vflags & V_COW)
2359 +               ei->i_flags |= EXT2_COW_FL;
2360  }
2361  
2362  struct inode *ext2_iget (struct super_block *sb, unsigned long ino)
2363 @@ -1335,8 +1361,10 @@ struct inode *ext2_iget (struct super_bl
2364                 i_uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
2365                 i_gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
2366         }
2367 -       i_uid_write(inode, i_uid);
2368 -       i_gid_write(inode, i_gid);
2369 +       i_uid_write(inode, INOTAG_UID(DX_TAG(inode), i_uid, i_gid));
2370 +       i_gid_write(inode, INOTAG_GID(DX_TAG(inode), i_uid, i_gid));
2371 +       i_tag_write(inode, INOTAG_TAG(DX_TAG(inode), i_uid, i_gid,
2372 +               le16_to_cpu(raw_inode->i_raw_tag)));
2373         set_nlink(inode, le16_to_cpu(raw_inode->i_links_count));
2374         inode->i_size = le32_to_cpu(raw_inode->i_size);
2375         inode->i_atime.tv_sec = (signed)le32_to_cpu(raw_inode->i_atime);
2376 @@ -1434,8 +1462,10 @@ static int __ext2_write_inode(struct ino
2377         struct ext2_inode_info *ei = EXT2_I(inode);
2378         struct super_block *sb = inode->i_sb;
2379         ino_t ino = inode->i_ino;
2380 -       uid_t uid = i_uid_read(inode);
2381 -       gid_t gid = i_gid_read(inode);
2382 +       uid_t uid = TAGINO_UID(DX_TAG(inode),
2383 +               i_uid_read(inode), i_tag_read(inode));
2384 +       gid_t gid = TAGINO_GID(DX_TAG(inode),
2385 +               i_gid_read(inode), i_tag_read(inode));
2386         struct buffer_head * bh;
2387         struct ext2_inode * raw_inode = ext2_get_inode(sb, ino, &bh);
2388         int n;
2389 @@ -1471,6 +1501,9 @@ static int __ext2_write_inode(struct ino
2390                 raw_inode->i_uid_high = 0;
2391                 raw_inode->i_gid_high = 0;
2392         }
2393 +#ifdef CONFIG_TAGGING_INTERN
2394 +       raw_inode->i_raw_tag = cpu_to_le16(i_tag_read(inode));
2395 +#endif
2396         raw_inode->i_links_count = cpu_to_le16(inode->i_nlink);
2397         raw_inode->i_size = cpu_to_le32(inode->i_size);
2398         raw_inode->i_atime = cpu_to_le32(inode->i_atime.tv_sec);
2399 @@ -1551,7 +1584,8 @@ int ext2_setattr(struct dentry *dentry,
2400         if (is_quota_modification(inode, iattr))
2401                 dquot_initialize(inode);
2402         if ((iattr->ia_valid & ATTR_UID && !uid_eq(iattr->ia_uid, inode->i_uid)) ||
2403 -           (iattr->ia_valid & ATTR_GID && !gid_eq(iattr->ia_gid, inode->i_gid))) {
2404 +           (iattr->ia_valid & ATTR_GID && !gid_eq(iattr->ia_gid, inode->i_gid)) ||
2405 +           (iattr->ia_valid & ATTR_TAG && !tag_eq(iattr->ia_tag, inode->i_tag))) {
2406                 error = dquot_transfer(inode, iattr);
2407                 if (error)
2408                         return error;
2409 diff -NurpP --minimal linux-3.9.4/fs/ext2/ioctl.c linux-3.9.4-vs2.3.6.2/fs/ext2/ioctl.c
2410 --- linux-3.9.4/fs/ext2/ioctl.c 2013-05-31 13:45:23.000000000 +0000
2411 +++ linux-3.9.4-vs2.3.6.2/fs/ext2/ioctl.c       2013-05-31 14:47:11.000000000 +0000
2412 @@ -17,6 +17,16 @@
2413  #include <asm/uaccess.h>
2414  
2415  
2416 +int ext2_sync_flags(struct inode *inode, int flags, int vflags)
2417 +{
2418 +       inode->i_flags = flags;
2419 +       inode->i_vflags = vflags;
2420 +       ext2_get_inode_flags(EXT2_I(inode));
2421 +       inode->i_ctime = CURRENT_TIME_SEC;
2422 +       mark_inode_dirty(inode);
2423 +       return 0;
2424 +}
2425 +
2426  long ext2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
2427  {
2428         struct inode *inode = file_inode(filp);
2429 @@ -51,6 +61,11 @@ long ext2_ioctl(struct file *filp, unsig
2430  
2431                 flags = ext2_mask_flags(inode->i_mode, flags);
2432  
2433 +               if (IS_BARRIER(inode)) {
2434 +                       vxwprintk_task(1, "messing with the barrier.");
2435 +                       return -EACCES;
2436 +               }
2437 +
2438                 mutex_lock(&inode->i_mutex);
2439                 /* Is it quota file? Do not allow user to mess with it */
2440                 if (IS_NOQUOTA(inode)) {
2441 @@ -66,7 +81,9 @@ long ext2_ioctl(struct file *filp, unsig
2442                  *
2443                  * This test looks nicer. Thanks to Pauline Middelink
2444                  */
2445 -               if ((flags ^ oldflags) & (EXT2_APPEND_FL | EXT2_IMMUTABLE_FL)) {
2446 +               if ((oldflags & EXT2_IMMUTABLE_FL) ||
2447 +                       ((flags ^ oldflags) & (EXT2_APPEND_FL |
2448 +                       EXT2_IMMUTABLE_FL | EXT2_IXUNLINK_FL))) {
2449                         if (!capable(CAP_LINUX_IMMUTABLE)) {
2450                                 mutex_unlock(&inode->i_mutex);
2451                                 ret = -EPERM;
2452 @@ -74,7 +91,7 @@ long ext2_ioctl(struct file *filp, unsig
2453                         }
2454                 }
2455  
2456 -               flags = flags & EXT2_FL_USER_MODIFIABLE;
2457 +               flags &= EXT2_FL_USER_MODIFIABLE;
2458                 flags |= oldflags & ~EXT2_FL_USER_MODIFIABLE;
2459                 ei->i_flags = flags;
2460  
2461 diff -NurpP --minimal linux-3.9.4/fs/ext2/namei.c linux-3.9.4-vs2.3.6.2/fs/ext2/namei.c
2462 --- linux-3.9.4/fs/ext2/namei.c 2012-12-11 03:30:57.000000000 +0000
2463 +++ linux-3.9.4-vs2.3.6.2/fs/ext2/namei.c       2013-05-31 14:47:11.000000000 +0000
2464 @@ -32,6 +32,7 @@
2465  
2466  #include <linux/pagemap.h>
2467  #include <linux/quotaops.h>
2468 +#include <linux/vs_tag.h>
2469  #include "ext2.h"
2470  #include "xattr.h"
2471  #include "acl.h"
2472 @@ -73,6 +74,7 @@ static struct dentry *ext2_lookup(struct
2473                                         (unsigned long) ino);
2474                         return ERR_PTR(-EIO);
2475                 }
2476 +               dx_propagate_tag(nd, inode);
2477         }
2478         return d_splice_alias(inode, dentry);
2479  }
2480 @@ -397,6 +399,7 @@ const struct inode_operations ext2_dir_i
2481         .removexattr    = generic_removexattr,
2482  #endif
2483         .setattr        = ext2_setattr,
2484 +       .sync_flags     = ext2_sync_flags,
2485         .get_acl        = ext2_get_acl,
2486  };
2487  
2488 diff -NurpP --minimal linux-3.9.4/fs/ext2/super.c linux-3.9.4-vs2.3.6.2/fs/ext2/super.c
2489 --- linux-3.9.4/fs/ext2/super.c 2013-05-31 13:45:23.000000000 +0000
2490 +++ linux-3.9.4-vs2.3.6.2/fs/ext2/super.c       2013-05-31 14:47:11.000000000 +0000
2491 @@ -395,7 +395,8 @@ enum {
2492         Opt_err_ro, Opt_nouid32, Opt_nocheck, Opt_debug,
2493         Opt_oldalloc, Opt_orlov, Opt_nobh, Opt_user_xattr, Opt_nouser_xattr,
2494         Opt_acl, Opt_noacl, Opt_xip, Opt_ignore, Opt_err, Opt_quota,
2495 -       Opt_usrquota, Opt_grpquota, Opt_reservation, Opt_noreservation
2496 +       Opt_usrquota, Opt_grpquota, Opt_reservation, Opt_noreservation,
2497 +       Opt_tag, Opt_notag, Opt_tagid
2498  };
2499  
2500  static const match_table_t tokens = {
2501 @@ -423,6 +424,9 @@ static const match_table_t tokens = {
2502         {Opt_acl, "acl"},
2503         {Opt_noacl, "noacl"},
2504         {Opt_xip, "xip"},
2505 +       {Opt_tag, "tag"},
2506 +       {Opt_notag, "notag"},
2507 +       {Opt_tagid, "tagid=%u"},
2508         {Opt_grpquota, "grpquota"},
2509         {Opt_ignore, "noquota"},
2510         {Opt_quota, "quota"},
2511 @@ -506,6 +510,20 @@ static int parse_options(char *options,
2512                 case Opt_nouid32:
2513                         set_opt (sbi->s_mount_opt, NO_UID32);
2514                         break;
2515 +#ifndef CONFIG_TAGGING_NONE
2516 +               case Opt_tag:
2517 +                       set_opt (sbi->s_mount_opt, TAGGED);
2518 +                       break;
2519 +               case Opt_notag:
2520 +                       clear_opt (sbi->s_mount_opt, TAGGED);
2521 +                       break;
2522 +#endif
2523 +#ifdef CONFIG_PROPAGATE
2524 +               case Opt_tagid:
2525 +                       /* use args[0] */
2526 +                       set_opt (sbi->s_mount_opt, TAGGED);
2527 +                       break;
2528 +#endif
2529                 case Opt_nocheck:
2530                         clear_opt (sbi->s_mount_opt, CHECK);
2531                         break;
2532 @@ -864,6 +882,8 @@ static int ext2_fill_super(struct super_
2533         if (!parse_options((char *) data, sb))
2534                 goto failed_mount;
2535  
2536 +       if (EXT2_SB(sb)->s_mount_opt & EXT2_MOUNT_TAGGED)
2537 +               sb->s_flags |= MS_TAGGED;
2538         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
2539                 ((EXT2_SB(sb)->s_mount_opt & EXT2_MOUNT_POSIX_ACL) ?
2540                  MS_POSIXACL : 0);
2541 @@ -1269,6 +1289,14 @@ static int ext2_remount (struct super_bl
2542                 err = -EINVAL;
2543                 goto restore_opts;
2544         }
2545 +
2546 +       if ((sbi->s_mount_opt & EXT2_MOUNT_TAGGED) &&
2547 +               !(sb->s_flags & MS_TAGGED)) {
2548 +               printk("EXT2-fs: %s: tagging not permitted on remount.\n",
2549 +                      sb->s_id);
2550 +               err = -EINVAL;
2551 +               goto restore_opts;
2552 +       }
2553  
2554         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
2555                 ((sbi->s_mount_opt & EXT2_MOUNT_POSIX_ACL) ? MS_POSIXACL : 0);
2556 diff -NurpP --minimal linux-3.9.4/fs/ext3/ext3.h linux-3.9.4-vs2.3.6.2/fs/ext3/ext3.h
2557 --- linux-3.9.4/fs/ext3/ext3.h  2012-12-11 03:30:57.000000000 +0000
2558 +++ linux-3.9.4-vs2.3.6.2/fs/ext3/ext3.h        2013-05-31 14:47:11.000000000 +0000
2559 @@ -151,10 +151,14 @@ struct ext3_group_desc
2560  #define EXT3_NOTAIL_FL                 0x00008000 /* file tail should not be merged */
2561  #define EXT3_DIRSYNC_FL                        0x00010000 /* dirsync behaviour (directories only) */
2562  #define EXT3_TOPDIR_FL                 0x00020000 /* Top of directory hierarchies*/
2563 +#define EXT3_IXUNLINK_FL               0x08000000 /* Immutable invert on unlink */
2564  #define EXT3_RESERVED_FL               0x80000000 /* reserved for ext3 lib */
2565  
2566 -#define EXT3_FL_USER_VISIBLE           0x0003DFFF /* User visible flags */
2567 -#define EXT3_FL_USER_MODIFIABLE                0x000380FF /* User modifiable flags */
2568 +#define EXT3_BARRIER_FL                        0x04000000 /* Barrier for chroot() */
2569 +#define EXT3_COW_FL                    0x20000000 /* Copy on Write marker */
2570 +
2571 +#define EXT3_FL_USER_VISIBLE           0x0103DFFF /* User visible flags */
2572 +#define EXT3_FL_USER_MODIFIABLE                0x010380FF /* User modifiable flags */
2573  
2574  /* Flags that should be inherited by new inodes from their parent. */
2575  #define EXT3_FL_INHERITED (EXT3_SECRM_FL | EXT3_UNRM_FL | EXT3_COMPR_FL |\
2576 @@ -290,7 +294,8 @@ struct ext3_inode {
2577                         __u16   i_pad1;
2578                         __le16  l_i_uid_high;   /* these 2 fields    */
2579                         __le16  l_i_gid_high;   /* were reserved2[0] */
2580 -                       __u32   l_i_reserved2;
2581 +                       __le16  l_i_tag;        /* Context Tag */
2582 +                       __u16   l_i_reserved2;
2583                 } linux2;
2584                 struct {
2585                         __u8    h_i_frag;       /* Fragment number */
2586 @@ -320,6 +325,7 @@ struct ext3_inode {
2587  #define i_gid_low      i_gid
2588  #define i_uid_high     osd2.linux2.l_i_uid_high
2589  #define i_gid_high     osd2.linux2.l_i_gid_high
2590 +#define i_raw_tag      osd2.linux2.l_i_tag
2591  #define i_reserved2    osd2.linux2.l_i_reserved2
2592  
2593  /*
2594 @@ -364,6 +370,7 @@ struct ext3_inode {
2595  #define EXT3_MOUNT_GRPQUOTA            0x200000 /* "old" group quota */
2596  #define EXT3_MOUNT_DATA_ERR_ABORT      0x400000 /* Abort on file data write
2597                                                   * error in ordered mode */
2598 +#define EXT3_MOUNT_TAGGED              (1<<24) /* Enable Context Tags */
2599  
2600  /* Compatibility, for having both ext2_fs.h and ext3_fs.h included at once */
2601  #ifndef _LINUX_EXT2_FS_H
2602 @@ -1061,6 +1068,7 @@ extern void ext3_get_inode_flags(struct
2603  extern void ext3_set_aops(struct inode *inode);
2604  extern int ext3_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
2605                        u64 start, u64 len);
2606 +extern int ext3_sync_flags(struct inode *, int, int);
2607  
2608  /* ioctl.c */
2609  extern long ext3_ioctl(struct file *, unsigned int, unsigned long);
2610 diff -NurpP --minimal linux-3.9.4/fs/ext3/file.c linux-3.9.4-vs2.3.6.2/fs/ext3/file.c
2611 --- linux-3.9.4/fs/ext3/file.c  2012-12-11 03:30:57.000000000 +0000
2612 +++ linux-3.9.4-vs2.3.6.2/fs/ext3/file.c        2013-05-31 14:47:11.000000000 +0000
2613 @@ -76,5 +76,6 @@ const struct inode_operations ext3_file_
2614  #endif
2615         .get_acl        = ext3_get_acl,
2616         .fiemap         = ext3_fiemap,
2617 +       .sync_flags     = ext3_sync_flags,
2618  };
2619  
2620 diff -NurpP --minimal linux-3.9.4/fs/ext3/ialloc.c linux-3.9.4-vs2.3.6.2/fs/ext3/ialloc.c
2621 --- linux-3.9.4/fs/ext3/ialloc.c        2012-12-11 03:30:57.000000000 +0000
2622 +++ linux-3.9.4-vs2.3.6.2/fs/ext3/ialloc.c      2013-06-01 09:40:15.000000000 +0000
2623 @@ -14,6 +14,7 @@
2624  
2625  #include <linux/quotaops.h>
2626  #include <linux/random.h>
2627 +#include <linux/vs_tag.h>
2628  
2629  #include "ext3.h"
2630  #include "xattr.h"
2631 @@ -469,6 +470,8 @@ got:
2632                 inode->i_mode = mode;
2633                 inode->i_uid = current_fsuid();
2634                 inode->i_gid = dir->i_gid;
2635 +               inode->i_tag = make_ktag(&init_user_ns,
2636 +                       dx_current_fstag(sb));
2637         } else
2638                 inode_init_owner(inode, dir, mode);
2639  
2640 diff -NurpP --minimal linux-3.9.4/fs/ext3/inode.c linux-3.9.4-vs2.3.6.2/fs/ext3/inode.c
2641 --- linux-3.9.4/fs/ext3/inode.c 2013-05-31 13:45:23.000000000 +0000
2642 +++ linux-3.9.4-vs2.3.6.2/fs/ext3/inode.c       2013-05-31 14:47:11.000000000 +0000
2643 @@ -27,6 +27,8 @@
2644  #include <linux/writeback.h>
2645  #include <linux/mpage.h>
2646  #include <linux/namei.h>
2647 +#include <linux/vs_tag.h>
2648 +
2649  #include "ext3.h"
2650  #include "xattr.h"
2651  #include "acl.h"
2652 @@ -2851,36 +2853,60 @@ void ext3_set_inode_flags(struct inode *
2653  {
2654         unsigned int flags = EXT3_I(inode)->i_flags;
2655  
2656 -       inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
2657 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
2658 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
2659 +
2660 +       if (flags & EXT3_IMMUTABLE_FL)
2661 +               inode->i_flags |= S_IMMUTABLE;
2662 +       if (flags & EXT3_IXUNLINK_FL)
2663 +               inode->i_flags |= S_IXUNLINK;
2664 +
2665         if (flags & EXT3_SYNC_FL)
2666                 inode->i_flags |= S_SYNC;
2667         if (flags & EXT3_APPEND_FL)
2668                 inode->i_flags |= S_APPEND;
2669 -       if (flags & EXT3_IMMUTABLE_FL)
2670 -               inode->i_flags |= S_IMMUTABLE;
2671         if (flags & EXT3_NOATIME_FL)
2672                 inode->i_flags |= S_NOATIME;
2673         if (flags & EXT3_DIRSYNC_FL)
2674                 inode->i_flags |= S_DIRSYNC;
2675 +
2676 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
2677 +
2678 +       if (flags & EXT3_BARRIER_FL)
2679 +               inode->i_vflags |= V_BARRIER;
2680 +       if (flags & EXT3_COW_FL)
2681 +               inode->i_vflags |= V_COW;
2682  }
2683  
2684  /* Propagate flags from i_flags to EXT3_I(inode)->i_flags */
2685  void ext3_get_inode_flags(struct ext3_inode_info *ei)
2686  {
2687         unsigned int flags = ei->vfs_inode.i_flags;
2688 +       unsigned int vflags = ei->vfs_inode.i_vflags;
2689 +
2690 +       ei->i_flags &= ~(EXT3_SYNC_FL | EXT3_APPEND_FL |
2691 +                       EXT3_IMMUTABLE_FL | EXT3_IXUNLINK_FL |
2692 +                       EXT3_NOATIME_FL | EXT3_DIRSYNC_FL |
2693 +                       EXT3_BARRIER_FL | EXT3_COW_FL);
2694 +
2695 +       if (flags & S_IMMUTABLE)
2696 +               ei->i_flags |= EXT3_IMMUTABLE_FL;
2697 +       if (flags & S_IXUNLINK)
2698 +               ei->i_flags |= EXT3_IXUNLINK_FL;
2699  
2700 -       ei->i_flags &= ~(EXT3_SYNC_FL|EXT3_APPEND_FL|
2701 -                       EXT3_IMMUTABLE_FL|EXT3_NOATIME_FL|EXT3_DIRSYNC_FL);
2702         if (flags & S_SYNC)
2703                 ei->i_flags |= EXT3_SYNC_FL;
2704         if (flags & S_APPEND)
2705                 ei->i_flags |= EXT3_APPEND_FL;
2706 -       if (flags & S_IMMUTABLE)
2707 -               ei->i_flags |= EXT3_IMMUTABLE_FL;
2708         if (flags & S_NOATIME)
2709                 ei->i_flags |= EXT3_NOATIME_FL;
2710         if (flags & S_DIRSYNC)
2711                 ei->i_flags |= EXT3_DIRSYNC_FL;
2712 +
2713 +       if (vflags & V_BARRIER)
2714 +               ei->i_flags |= EXT3_BARRIER_FL;
2715 +       if (vflags & V_COW)
2716 +               ei->i_flags |= EXT3_COW_FL;
2717  }
2718  
2719  struct inode *ext3_iget(struct super_block *sb, unsigned long ino)
2720 @@ -2918,8 +2944,10 @@ struct inode *ext3_iget(struct super_blo
2721                 i_uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
2722                 i_gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
2723         }
2724 -       i_uid_write(inode, i_uid);
2725 -       i_gid_write(inode, i_gid);
2726 +       i_uid_write(inode, INOTAG_UID(DX_TAG(inode), i_uid, i_gid));
2727 +       i_gid_write(inode, INOTAG_GID(DX_TAG(inode), i_uid, i_gid));
2728 +       i_tag_write(inode, INOTAG_TAG(DX_TAG(inode), i_uid, i_gid,
2729 +               le16_to_cpu(raw_inode->i_raw_tag)));
2730         set_nlink(inode, le16_to_cpu(raw_inode->i_links_count));
2731         inode->i_size = le32_to_cpu(raw_inode->i_size);
2732         inode->i_atime.tv_sec = (signed)le32_to_cpu(raw_inode->i_atime);
2733 @@ -3091,8 +3119,10 @@ again:
2734  
2735         ext3_get_inode_flags(ei);
2736         raw_inode->i_mode = cpu_to_le16(inode->i_mode);
2737 -       i_uid = i_uid_read(inode);
2738 -       i_gid = i_gid_read(inode);
2739 +       i_uid = TAGINO_UID(DX_TAG(inode),
2740 +               i_uid_read(inode), i_tag_read(inode));
2741 +       i_gid = TAGINO_GID(DX_TAG(inode),
2742 +               i_gid_read(inode), i_tag_read(inode));
2743         if(!(test_opt(inode->i_sb, NO_UID32))) {
2744                 raw_inode->i_uid_low = cpu_to_le16(low_16_bits(i_uid));
2745                 raw_inode->i_gid_low = cpu_to_le16(low_16_bits(i_gid));
2746 @@ -3117,6 +3147,9 @@ again:
2747                 raw_inode->i_uid_high = 0;
2748                 raw_inode->i_gid_high = 0;
2749         }
2750 +#ifdef CONFIG_TAGGING_INTERN
2751 +       raw_inode->i_raw_tag = cpu_to_le16(i_tag_read(inode));
2752 +#endif
2753         raw_inode->i_links_count = cpu_to_le16(inode->i_nlink);
2754         disksize = cpu_to_le32(ei->i_disksize);
2755         if (disksize != raw_inode->i_size) {
2756 @@ -3285,7 +3318,8 @@ int ext3_setattr(struct dentry *dentry,
2757         if (is_quota_modification(inode, attr))
2758                 dquot_initialize(inode);
2759         if ((ia_valid & ATTR_UID && !uid_eq(attr->ia_uid, inode->i_uid)) ||
2760 -           (ia_valid & ATTR_GID && !gid_eq(attr->ia_gid, inode->i_gid))) {
2761 +           (ia_valid & ATTR_GID && !gid_eq(attr->ia_gid, inode->i_gid)) ||
2762 +           (ia_valid & ATTR_TAG && !tag_eq(attr->ia_tag, inode->i_tag))) {
2763                 handle_t *handle;
2764  
2765                 /* (user+group)*(old+new) structure, inode write (sb,
2766 @@ -3307,6 +3341,8 @@ int ext3_setattr(struct dentry *dentry,
2767                         inode->i_uid = attr->ia_uid;
2768                 if (attr->ia_valid & ATTR_GID)
2769                         inode->i_gid = attr->ia_gid;
2770 +               if ((attr->ia_valid & ATTR_TAG) && IS_TAGGED(inode))
2771 +                       inode->i_tag = attr->ia_tag;
2772                 error = ext3_mark_inode_dirty(handle, inode);
2773                 ext3_journal_stop(handle);
2774         }
2775 diff -NurpP --minimal linux-3.9.4/fs/ext3/ioctl.c linux-3.9.4-vs2.3.6.2/fs/ext3/ioctl.c
2776 --- linux-3.9.4/fs/ext3/ioctl.c 2013-05-31 13:45:23.000000000 +0000
2777 +++ linux-3.9.4-vs2.3.6.2/fs/ext3/ioctl.c       2013-05-31 14:47:11.000000000 +0000
2778 @@ -12,6 +12,34 @@
2779  #include <asm/uaccess.h>
2780  #include "ext3.h"
2781  
2782 +
2783 +int ext3_sync_flags(struct inode *inode, int flags, int vflags)
2784 +{
2785 +       handle_t *handle = NULL;
2786 +       struct ext3_iloc iloc;
2787 +       int err;
2788 +
2789 +       handle = ext3_journal_start(inode, 1);
2790 +       if (IS_ERR(handle))
2791 +               return PTR_ERR(handle);
2792 +
2793 +       if (IS_SYNC(inode))
2794 +               handle->h_sync = 1;
2795 +       err = ext3_reserve_inode_write(handle, inode, &iloc);
2796 +       if (err)
2797 +               goto flags_err;
2798 +
2799 +       inode->i_flags = flags;
2800 +       inode->i_vflags = vflags;
2801 +       ext3_get_inode_flags(EXT3_I(inode));
2802 +       inode->i_ctime = CURRENT_TIME_SEC;
2803 +
2804 +       err = ext3_mark_iloc_dirty(handle, inode, &iloc);
2805 +flags_err:
2806 +       ext3_journal_stop(handle);
2807 +       return err;
2808 +}
2809 +
2810  long ext3_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
2811  {
2812         struct inode *inode = file_inode(filp);
2813 @@ -45,6 +73,11 @@ long ext3_ioctl(struct file *filp, unsig
2814  
2815                 flags = ext3_mask_flags(inode->i_mode, flags);
2816  
2817 +               if (IS_BARRIER(inode)) {
2818 +                       vxwprintk_task(1, "messing with the barrier.");
2819 +                       return -EACCES;
2820 +               }
2821 +
2822                 mutex_lock(&inode->i_mutex);
2823  
2824                 /* Is it quota file? Do not allow user to mess with it */
2825 @@ -63,7 +96,9 @@ long ext3_ioctl(struct file *filp, unsig
2826                  *
2827                  * This test looks nicer. Thanks to Pauline Middelink
2828                  */
2829 -               if ((flags ^ oldflags) & (EXT3_APPEND_FL | EXT3_IMMUTABLE_FL)) {
2830 +               if ((oldflags & EXT3_IMMUTABLE_FL) ||
2831 +                       ((flags ^ oldflags) & (EXT3_APPEND_FL |
2832 +                       EXT3_IMMUTABLE_FL | EXT3_IXUNLINK_FL))) {
2833                         if (!capable(CAP_LINUX_IMMUTABLE))
2834                                 goto flags_out;
2835                 }
2836 @@ -88,7 +123,7 @@ long ext3_ioctl(struct file *filp, unsig
2837                 if (err)
2838                         goto flags_err;
2839  
2840 -               flags = flags & EXT3_FL_USER_MODIFIABLE;
2841 +               flags &= EXT3_FL_USER_MODIFIABLE;
2842                 flags |= oldflags & ~EXT3_FL_USER_MODIFIABLE;
2843                 ei->i_flags = flags;
2844  
2845 diff -NurpP --minimal linux-3.9.4/fs/ext3/namei.c linux-3.9.4-vs2.3.6.2/fs/ext3/namei.c
2846 --- linux-3.9.4/fs/ext3/namei.c 2013-05-31 13:45:23.000000000 +0000
2847 +++ linux-3.9.4-vs2.3.6.2/fs/ext3/namei.c       2013-05-31 14:47:11.000000000 +0000
2848 @@ -25,6 +25,8 @@
2849   */
2850  
2851  #include <linux/quotaops.h>
2852 +#include <linux/vs_tag.h>
2853 +
2854  #include "ext3.h"
2855  #include "namei.h"
2856  #include "xattr.h"
2857 @@ -918,6 +920,7 @@ restart:
2858                                         submit_bh(READ | REQ_META | REQ_PRIO,
2859                                                   bh);
2860                                 }
2861 +               dx_propagate_tag(nd, inode);
2862                         }
2863                 }
2864                 if ((bh = bh_use[ra_ptr++]) == NULL)
2865 @@ -2527,6 +2530,7 @@ const struct inode_operations ext3_dir_i
2866         .listxattr      = ext3_listxattr,
2867         .removexattr    = generic_removexattr,
2868  #endif
2869 +       .sync_flags     = ext3_sync_flags,
2870         .get_acl        = ext3_get_acl,
2871  };
2872  
2873 diff -NurpP --minimal linux-3.9.4/fs/ext3/super.c linux-3.9.4-vs2.3.6.2/fs/ext3/super.c
2874 --- linux-3.9.4/fs/ext3/super.c 2013-05-31 13:45:23.000000000 +0000
2875 +++ linux-3.9.4-vs2.3.6.2/fs/ext3/super.c       2013-05-31 14:47:11.000000000 +0000
2876 @@ -816,7 +816,8 @@ enum {
2877         Opt_usrjquota, Opt_grpjquota, Opt_offusrjquota, Opt_offgrpjquota,
2878         Opt_jqfmt_vfsold, Opt_jqfmt_vfsv0, Opt_jqfmt_vfsv1, Opt_quota,
2879         Opt_noquota, Opt_ignore, Opt_barrier, Opt_nobarrier, Opt_err,
2880 -       Opt_resize, Opt_usrquota, Opt_grpquota
2881 +       Opt_resize, Opt_usrquota, Opt_grpquota,
2882 +       Opt_tag, Opt_notag, Opt_tagid
2883  };
2884  
2885  static const match_table_t tokens = {
2886 @@ -873,6 +874,9 @@ static const match_table_t tokens = {
2887         {Opt_barrier, "barrier"},
2888         {Opt_nobarrier, "nobarrier"},
2889         {Opt_resize, "resize"},
2890 +       {Opt_tag, "tag"},
2891 +       {Opt_notag, "notag"},
2892 +       {Opt_tagid, "tagid=%u"},
2893         {Opt_err, NULL},
2894  };
2895  
2896 @@ -1040,6 +1044,20 @@ static int parse_options (char *options,
2897                 case Opt_nouid32:
2898                         set_opt (sbi->s_mount_opt, NO_UID32);
2899                         break;
2900 +#ifndef CONFIG_TAGGING_NONE
2901 +               case Opt_tag:
2902 +                       set_opt (sbi->s_mount_opt, TAGGED);
2903 +                       break;
2904 +               case Opt_notag:
2905 +                       clear_opt (sbi->s_mount_opt, TAGGED);
2906 +                       break;
2907 +#endif
2908 +#ifdef CONFIG_PROPAGATE
2909 +               case Opt_tagid:
2910 +                       /* use args[0] */
2911 +                       set_opt (sbi->s_mount_opt, TAGGED);
2912 +                       break;
2913 +#endif
2914                 case Opt_nocheck:
2915                         clear_opt (sbi->s_mount_opt, CHECK);
2916                         break;
2917 @@ -1737,6 +1755,9 @@ static int ext3_fill_super (struct super
2918                             NULL, 0))
2919                 goto failed_mount;
2920  
2921 +       if (EXT3_SB(sb)->s_mount_opt & EXT3_MOUNT_TAGGED)
2922 +               sb->s_flags |= MS_TAGGED;
2923 +
2924         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
2925                 (test_opt(sb, POSIX_ACL) ? MS_POSIXACL : 0);
2926  
2927 @@ -2633,6 +2654,14 @@ static int ext3_remount (struct super_bl
2928         if (test_opt(sb, ABORT))
2929                 ext3_abort(sb, __func__, "Abort forced by user");
2930  
2931 +       if ((sbi->s_mount_opt & EXT3_MOUNT_TAGGED) &&
2932 +               !(sb->s_flags & MS_TAGGED)) {
2933 +               printk("EXT3-fs: %s: tagging not permitted on remount.\n",
2934 +                       sb->s_id);
2935 +               err = -EINVAL;
2936 +               goto restore_opts;
2937 +       }
2938 +
2939         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
2940                 (test_opt(sb, POSIX_ACL) ? MS_POSIXACL : 0);
2941  
2942 diff -NurpP --minimal linux-3.9.4/fs/ext4/ext4.h linux-3.9.4-vs2.3.6.2/fs/ext4/ext4.h
2943 --- linux-3.9.4/fs/ext4/ext4.h  2013-05-31 13:45:23.000000000 +0000
2944 +++ linux-3.9.4-vs2.3.6.2/fs/ext4/ext4.h        2013-05-31 16:22:49.000000000 +0000
2945 @@ -399,7 +399,10 @@ struct flex_groups {
2946  #define EXT4_EXTENTS_FL                        0x00080000 /* Inode uses extents */
2947  #define EXT4_EA_INODE_FL               0x00200000 /* Inode used for large EA */
2948  #define EXT4_EOFBLOCKS_FL              0x00400000 /* Blocks allocated beyond EOF */
2949 +#define EXT4_BARRIER_FL                        0x04000000 /* Barrier for chroot() */
2950 +#define EXT4_IXUNLINK_FL               0x08000000 /* Immutable invert on unlink */
2951  #define EXT4_INLINE_DATA_FL            0x10000000 /* Inode has inline data. */
2952 +#define EXT4_COW_FL                    0x20000000 /* Copy on Write marker */
2953  #define EXT4_RESERVED_FL               0x80000000 /* reserved for ext4 lib */
2954  
2955  #define EXT4_FL_USER_VISIBLE           0x004BDFFF /* User visible flags */
2956 @@ -674,7 +677,7 @@ struct ext4_inode {
2957                         __le16  l_i_uid_high;   /* these 2 fields */
2958                         __le16  l_i_gid_high;   /* were reserved2[0] */
2959                         __le16  l_i_checksum_lo;/* crc32c(uuid+inum+inode) LE */
2960 -                       __le16  l_i_reserved;
2961 +                       __le16  l_i_tag;        /* Context Tag */
2962                 } linux2;
2963                 struct {
2964                         __le16  h_i_reserved1;  /* Obsoleted fragment number/size which are removed in ext4 */
2965 @@ -792,6 +795,7 @@ do {                                                                               \
2966  #define i_gid_low      i_gid
2967  #define i_uid_high     osd2.linux2.l_i_uid_high
2968  #define i_gid_high     osd2.linux2.l_i_gid_high
2969 +#define i_raw_tag      osd2.linux2.l_i_tag
2970  #define i_checksum_lo  osd2.linux2.l_i_checksum_lo
2971  
2972  #elif defined(__GNU__)
2973 @@ -969,6 +973,7 @@ struct ext4_inode_info {
2974  #define EXT4_MOUNT_POSIX_ACL           0x08000 /* POSIX Access Control Lists */
2975  #define EXT4_MOUNT_NO_AUTO_DA_ALLOC    0x10000 /* No auto delalloc mapping */
2976  #define EXT4_MOUNT_BARRIER             0x20000 /* Use block barriers */
2977 +#define EXT4_MOUNT_TAGGED              0x40000 /* Enable Context Tags */
2978  #define EXT4_MOUNT_QUOTA               0x80000 /* Some quota option set */
2979  #define EXT4_MOUNT_USRQUOTA            0x100000 /* "old" user quota */
2980  #define EXT4_MOUNT_GRPQUOTA            0x200000 /* "old" group quota */
2981 @@ -2527,6 +2532,7 @@ extern struct buffer_head *ext4_get_firs
2982  extern int ext4_inline_data_fiemap(struct inode *inode,
2983                                    struct fiemap_extent_info *fieinfo,
2984                                    int *has_inline);
2985 +extern int ext4_sync_flags(struct inode *, int, int);
2986  extern int ext4_try_to_evict_inline_data(handle_t *handle,
2987                                          struct inode *inode,
2988                                          int needed);
2989 diff -NurpP --minimal linux-3.9.4/fs/ext4/file.c linux-3.9.4-vs2.3.6.2/fs/ext4/file.c
2990 --- linux-3.9.4/fs/ext4/file.c  2013-05-31 13:45:23.000000000 +0000
2991 +++ linux-3.9.4-vs2.3.6.2/fs/ext4/file.c        2013-05-31 14:47:11.000000000 +0000
2992 @@ -650,5 +650,6 @@ const struct inode_operations ext4_file_
2993         .removexattr    = generic_removexattr,
2994         .get_acl        = ext4_get_acl,
2995         .fiemap         = ext4_fiemap,
2996 +       .sync_flags     = ext4_sync_flags,
2997  };
2998  
2999 diff -NurpP --minimal linux-3.9.4/fs/ext4/ialloc.c linux-3.9.4-vs2.3.6.2/fs/ext4/ialloc.c
3000 --- linux-3.9.4/fs/ext4/ialloc.c        2013-05-31 13:45:23.000000000 +0000
3001 +++ linux-3.9.4-vs2.3.6.2/fs/ext4/ialloc.c      2013-06-01 09:46:49.000000000 +0000
3002 @@ -22,6 +22,7 @@
3003  #include <linux/random.h>
3004  #include <linux/bitops.h>
3005  #include <linux/blkdev.h>
3006 +#include <linux/vs_tag.h>
3007  #include <asm/byteorder.h>
3008  
3009  #include "ext4.h"
3010 @@ -859,6 +860,8 @@ got:
3011                 inode->i_mode = mode;
3012                 inode->i_uid = current_fsuid();
3013                 inode->i_gid = dir->i_gid;
3014 +               inode->i_tag = make_ktag(&init_user_ns,
3015 +                       dx_current_fstag(sb));
3016         } else
3017                 inode_init_owner(inode, dir, mode);
3018  
3019 diff -NurpP --minimal linux-3.9.4/fs/ext4/inode.c linux-3.9.4-vs2.3.6.2/fs/ext4/inode.c
3020 --- linux-3.9.4/fs/ext4/inode.c 2013-05-31 14:22:27.000000000 +0000
3021 +++ linux-3.9.4-vs2.3.6.2/fs/ext4/inode.c       2013-05-31 14:47:11.000000000 +0000
3022 @@ -37,6 +37,7 @@
3023  #include <linux/printk.h>
3024  #include <linux/slab.h>
3025  #include <linux/ratelimit.h>
3026 +#include <linux/vs_tag.h>
3027  
3028  #include "ext4_jbd2.h"
3029  #include "xattr.h"
3030 @@ -3870,41 +3871,64 @@ void ext4_set_inode_flags(struct inode *
3031  {
3032         unsigned int flags = EXT4_I(inode)->i_flags;
3033  
3034 -       inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
3035 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
3036 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
3037 +
3038 +       if (flags & EXT4_IMMUTABLE_FL)
3039 +               inode->i_flags |= S_IMMUTABLE;
3040 +       if (flags & EXT4_IXUNLINK_FL)
3041 +               inode->i_flags |= S_IXUNLINK;
3042 +
3043         if (flags & EXT4_SYNC_FL)
3044                 inode->i_flags |= S_SYNC;
3045         if (flags & EXT4_APPEND_FL)
3046                 inode->i_flags |= S_APPEND;
3047 -       if (flags & EXT4_IMMUTABLE_FL)
3048 -               inode->i_flags |= S_IMMUTABLE;
3049         if (flags & EXT4_NOATIME_FL)
3050                 inode->i_flags |= S_NOATIME;
3051         if (flags & EXT4_DIRSYNC_FL)
3052                 inode->i_flags |= S_DIRSYNC;
3053 +
3054 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
3055 +
3056 +       if (flags & EXT4_BARRIER_FL)
3057 +               inode->i_vflags |= V_BARRIER;
3058 +       if (flags & EXT4_COW_FL)
3059 +               inode->i_vflags |= V_COW;
3060  }
3061  
3062  /* Propagate flags from i_flags to EXT4_I(inode)->i_flags */
3063  void ext4_get_inode_flags(struct ext4_inode_info *ei)
3064  {
3065 -       unsigned int vfs_fl;
3066 +       unsigned int vfs_fl, vfs_vf;
3067         unsigned long old_fl, new_fl;
3068  
3069         do {
3070                 vfs_fl = ei->vfs_inode.i_flags;
3071 +               vfs_vf = ei->vfs_inode.i_vflags;
3072                 old_fl = ei->i_flags;
3073                 new_fl = old_fl & ~(EXT4_SYNC_FL|EXT4_APPEND_FL|
3074                                 EXT4_IMMUTABLE_FL|EXT4_NOATIME_FL|
3075 -                               EXT4_DIRSYNC_FL);
3076 +                               EXT4_DIRSYNC_FL|EXT4_BARRIER_FL|
3077 +                               EXT4_COW_FL);
3078 +
3079 +               if (vfs_fl & S_IMMUTABLE)
3080 +                       new_fl |= EXT4_IMMUTABLE_FL;
3081 +               if (vfs_fl & S_IXUNLINK)
3082 +                       new_fl |= EXT4_IXUNLINK_FL;
3083 +
3084                 if (vfs_fl & S_SYNC)
3085                         new_fl |= EXT4_SYNC_FL;
3086                 if (vfs_fl & S_APPEND)
3087                         new_fl |= EXT4_APPEND_FL;
3088 -               if (vfs_fl & S_IMMUTABLE)
3089 -                       new_fl |= EXT4_IMMUTABLE_FL;
3090                 if (vfs_fl & S_NOATIME)
3091                         new_fl |= EXT4_NOATIME_FL;
3092                 if (vfs_fl & S_DIRSYNC)
3093                         new_fl |= EXT4_DIRSYNC_FL;
3094 +
3095 +               if (vfs_vf & V_BARRIER)
3096 +                       new_fl |= EXT4_BARRIER_FL;
3097 +               if (vfs_vf & V_COW)
3098 +                       new_fl |= EXT4_COW_FL;
3099         } while (cmpxchg(&ei->i_flags, old_fl, new_fl) != old_fl);
3100  }
3101  
3102 @@ -4009,8 +4033,10 @@ struct inode *ext4_iget(struct super_blo
3103                 i_uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
3104                 i_gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
3105         }
3106 -       i_uid_write(inode, i_uid);
3107 -       i_gid_write(inode, i_gid);
3108 +       i_uid_write(inode, INOTAG_UID(DX_TAG(inode), i_uid, i_gid));
3109 +       i_gid_write(inode, INOTAG_GID(DX_TAG(inode), i_uid, i_gid));
3110 +       i_tag_write(inode, INOTAG_TAG(DX_TAG(inode), i_uid, i_gid,
3111 +               le16_to_cpu(raw_inode->i_raw_tag)));
3112         set_nlink(inode, le16_to_cpu(raw_inode->i_links_count));
3113  
3114         ext4_clear_state_flags(ei);     /* Only relevant on 32-bit archs */
3115 @@ -4233,8 +4259,10 @@ static int ext4_do_update_inode(handle_t
3116  
3117         ext4_get_inode_flags(ei);
3118         raw_inode->i_mode = cpu_to_le16(inode->i_mode);
3119 -       i_uid = i_uid_read(inode);
3120 -       i_gid = i_gid_read(inode);
3121 +       i_uid = TAGINO_UID(DX_TAG(inode),
3122 +               i_uid_read(inode), i_tag_read(inode));
3123 +       i_gid = TAGINO_GID(DX_TAG(inode),
3124 +               i_gid_read(inode), i_tag_read(inode));
3125         if (!(test_opt(inode->i_sb, NO_UID32))) {
3126                 raw_inode->i_uid_low = cpu_to_le16(low_16_bits(i_uid));
3127                 raw_inode->i_gid_low = cpu_to_le16(low_16_bits(i_gid));
3128 @@ -4257,6 +4285,9 @@ static int ext4_do_update_inode(handle_t
3129                 raw_inode->i_uid_high = 0;
3130                 raw_inode->i_gid_high = 0;
3131         }
3132 +#ifdef CONFIG_TAGGING_INTERN
3133 +       raw_inode->i_raw_tag = cpu_to_le16(i_tag_read(inode));
3134 +#endif
3135         raw_inode->i_links_count = cpu_to_le16(inode->i_nlink);
3136  
3137         EXT4_INODE_SET_XTIME(i_ctime, inode, raw_inode);
3138 @@ -4487,7 +4518,8 @@ int ext4_setattr(struct dentry *dentry,
3139         if (is_quota_modification(inode, attr))
3140                 dquot_initialize(inode);
3141         if ((ia_valid & ATTR_UID && !uid_eq(attr->ia_uid, inode->i_uid)) ||
3142 -           (ia_valid & ATTR_GID && !gid_eq(attr->ia_gid, inode->i_gid))) {
3143 +           (ia_valid & ATTR_GID && !gid_eq(attr->ia_gid, inode->i_gid)) ||
3144 +           (ia_valid & ATTR_TAG && !tag_eq(attr->ia_tag, inode->i_tag))) {
3145                 handle_t *handle;
3146  
3147                 /* (user+group)*(old+new) structure, inode write (sb,
3148 @@ -4510,6 +4542,8 @@ int ext4_setattr(struct dentry *dentry,
3149                         inode->i_uid = attr->ia_uid;
3150                 if (attr->ia_valid & ATTR_GID)
3151                         inode->i_gid = attr->ia_gid;
3152 +               if ((attr->ia_valid & ATTR_TAG) && IS_TAGGED(inode))
3153 +                       inode->i_tag = attr->ia_tag;
3154                 error = ext4_mark_inode_dirty(handle, inode);
3155                 ext4_journal_stop(handle);
3156         }
3157 diff -NurpP --minimal linux-3.9.4/fs/ext4/ioctl.c linux-3.9.4-vs2.3.6.2/fs/ext4/ioctl.c
3158 --- linux-3.9.4/fs/ext4/ioctl.c 2013-05-31 13:45:23.000000000 +0000
3159 +++ linux-3.9.4-vs2.3.6.2/fs/ext4/ioctl.c       2013-05-31 19:50:08.000000000 +0000
3160 @@ -14,12 +14,40 @@
3161  #include <linux/compat.h>
3162  #include <linux/mount.h>
3163  #include <linux/file.h>
3164 +#include <linux/vs_tag.h>
3165  #include <asm/uaccess.h>
3166  #include "ext4_jbd2.h"
3167  #include "ext4.h"
3168  
3169  #define MAX_32_NUM ((((unsigned long long) 1) << 32) - 1)
3170  
3171 +int ext4_sync_flags(struct inode *inode, int flags, int vflags)
3172 +{
3173 +       handle_t *handle = NULL;
3174 +       struct ext4_iloc iloc;
3175 +       int err;
3176 +
3177 +       handle = ext4_journal_start(inode, EXT4_HT_INODE, 1);
3178 +       if (IS_ERR(handle))
3179 +               return PTR_ERR(handle);
3180 +
3181 +       if (IS_SYNC(inode))
3182 +               ext4_handle_sync(handle);
3183 +       err = ext4_reserve_inode_write(handle, inode, &iloc);
3184 +       if (err)
3185 +               goto flags_err;
3186 +
3187 +       inode->i_flags = flags;
3188 +       inode->i_vflags = vflags;
3189 +       ext4_get_inode_flags(EXT4_I(inode));
3190 +       inode->i_ctime = ext4_current_time(inode);
3191 +
3192 +       err = ext4_mark_iloc_dirty(handle, inode, &iloc);
3193 +flags_err:
3194 +       ext4_journal_stop(handle);
3195 +       return err;
3196 +}
3197 +
3198  long ext4_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
3199  {
3200         struct inode *inode = file_inode(filp);
3201 @@ -53,6 +81,11 @@ long ext4_ioctl(struct file *filp, unsig
3202  
3203                 flags = ext4_mask_flags(inode->i_mode, flags);
3204  
3205 +               if (IS_BARRIER(inode)) {
3206 +                       vxwprintk_task(1, "messing with the barrier.");
3207 +                       return -EACCES;
3208 +               }
3209 +
3210                 err = -EPERM;
3211                 mutex_lock(&inode->i_mutex);
3212                 /* Is it quota file? Do not allow user to mess with it */
3213 @@ -70,7 +103,9 @@ long ext4_ioctl(struct file *filp, unsig
3214                  *
3215                  * This test looks nicer. Thanks to Pauline Middelink
3216                  */
3217 -               if ((flags ^ oldflags) & (EXT4_APPEND_FL | EXT4_IMMUTABLE_FL)) {
3218 +               if ((oldflags & EXT4_IMMUTABLE_FL) ||
3219 +                       ((flags ^ oldflags) & (EXT4_APPEND_FL |
3220 +                       EXT4_IMMUTABLE_FL | EXT4_IXUNLINK_FL))) {
3221                         if (!capable(CAP_LINUX_IMMUTABLE))
3222                                 goto flags_out;
3223                 }
3224 diff -NurpP --minimal linux-3.9.4/fs/ext4/namei.c linux-3.9.4-vs2.3.6.2/fs/ext4/namei.c
3225 --- linux-3.9.4/fs/ext4/namei.c 2013-05-31 13:45:23.000000000 +0000
3226 +++ linux-3.9.4-vs2.3.6.2/fs/ext4/namei.c       2013-05-31 14:47:11.000000000 +0000
3227 @@ -34,6 +34,7 @@
3228  #include <linux/quotaops.h>
3229  #include <linux/buffer_head.h>
3230  #include <linux/bio.h>
3231 +#include <linux/vs_tag.h>
3232  #include "ext4.h"
3233  #include "ext4_jbd2.h"
3234  
3235 @@ -1290,6 +1291,7 @@ restart:
3236                                         ll_rw_block(READ | REQ_META | REQ_PRIO,
3237                                                     1, &bh);
3238                         }
3239 +               dx_propagate_tag(nd, inode);
3240                 }
3241                 if ((bh = bh_use[ra_ptr++]) == NULL)
3242                         goto next;
3243 @@ -3190,6 +3192,7 @@ const struct inode_operations ext4_dir_i
3244         .removexattr    = generic_removexattr,
3245         .get_acl        = ext4_get_acl,
3246         .fiemap         = ext4_fiemap,
3247 +       .sync_flags     = ext4_sync_flags,
3248  };
3249  
3250  const struct inode_operations ext4_special_inode_operations = {
3251 diff -NurpP --minimal linux-3.9.4/fs/ext4/super.c linux-3.9.4-vs2.3.6.2/fs/ext4/super.c
3252 --- linux-3.9.4/fs/ext4/super.c 2013-05-31 14:22:27.000000000 +0000
3253 +++ linux-3.9.4-vs2.3.6.2/fs/ext4/super.c       2013-05-31 14:47:11.000000000 +0000
3254 @@ -1131,7 +1131,7 @@ enum {
3255         Opt_inode_readahead_blks, Opt_journal_ioprio,
3256         Opt_dioread_nolock, Opt_dioread_lock,
3257         Opt_discard, Opt_nodiscard, Opt_init_itable, Opt_noinit_itable,
3258 -       Opt_max_dir_size_kb,
3259 +       Opt_max_dir_size_kb, Opt_tag, Opt_notag, Opt_tagid
3260  };
3261  
3262  static const match_table_t tokens = {
3263 @@ -1211,6 +1211,9 @@ static const match_table_t tokens = {
3264         {Opt_removed, "reservation"},   /* mount option from ext2/3 */
3265         {Opt_removed, "noreservation"}, /* mount option from ext2/3 */
3266         {Opt_removed, "journal=%u"},    /* mount option from ext2/3 */
3267 +       {Opt_tag, "tag"},
3268 +       {Opt_notag, "notag"},
3269 +       {Opt_tagid, "tagid=%u"},
3270         {Opt_err, NULL},
3271  };
3272  
3273 @@ -1441,6 +1444,20 @@ static int handle_mount_opt(struct super
3274         case Opt_i_version:
3275                 sb->s_flags |= MS_I_VERSION;
3276                 return 1;
3277 +#ifndef CONFIG_TAGGING_NONE
3278 +       case Opt_tag:
3279 +               set_opt(sb, TAGGED);
3280 +               return 1;
3281 +       case Opt_notag:
3282 +               clear_opt(sb, TAGGED);
3283 +               return 1;
3284 +#endif
3285 +#ifdef CONFIG_PROPAGATE
3286 +       case Opt_tagid:
3287 +               /* use args[0] */
3288 +               set_opt(sb, TAGGED);
3289 +               return 1;
3290 +#endif
3291         }
3292  
3293         for (m = ext4_mount_opts; m->token != Opt_err; m++)
3294 @@ -3401,6 +3418,9 @@ static int ext4_fill_super(struct super_
3295                         clear_opt(sb, DELALLOC);
3296         }
3297  
3298 +       if (EXT4_SB(sb)->s_mount_opt & EXT4_MOUNT_TAGGED)
3299 +               sb->s_flags |= MS_TAGGED;
3300 +
3301         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
3302                 (test_opt(sb, POSIX_ACL) ? MS_POSIXACL : 0);
3303  
3304 @@ -4587,6 +4607,14 @@ static int ext4_remount(struct super_blo
3305         if (sbi->s_mount_flags & EXT4_MF_FS_ABORTED)
3306                 ext4_abort(sb, "Abort forced by user");
3307  
3308 +       if ((sbi->s_mount_opt & EXT4_MOUNT_TAGGED) &&
3309 +               !(sb->s_flags & MS_TAGGED)) {
3310 +               printk("EXT4-fs: %s: tagging not permitted on remount.\n",
3311 +                       sb->s_id);
3312 +               err = -EINVAL;
3313 +               goto restore_opts;
3314 +       }
3315 +
3316         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
3317                 (test_opt(sb, POSIX_ACL) ? MS_POSIXACL : 0);
3318  
3319 diff -NurpP --minimal linux-3.9.4/fs/fcntl.c linux-3.9.4-vs2.3.6.2/fs/fcntl.c
3320 --- linux-3.9.4/fs/fcntl.c      2013-05-31 13:45:23.000000000 +0000
3321 +++ linux-3.9.4-vs2.3.6.2/fs/fcntl.c    2013-05-31 14:47:11.000000000 +0000
3322 @@ -21,6 +21,7 @@
3323  #include <linux/rcupdate.h>
3324  #include <linux/pid_namespace.h>
3325  #include <linux/user_namespace.h>
3326 +#include <linux/vs_limit.h>
3327  
3328  #include <asm/poll.h>
3329  #include <asm/siginfo.h>
3330 @@ -378,6 +379,8 @@ SYSCALL_DEFINE3(fcntl64, unsigned int, f
3331  
3332         if (!f.file)
3333                 goto out;
3334 +       if (!vx_files_avail(1))
3335 +               goto out;
3336  
3337         if (unlikely(f.file->f_mode & FMODE_PATH)) {
3338                 if (!check_fcntl_cmd(cmd))
3339 diff -NurpP --minimal linux-3.9.4/fs/file.c linux-3.9.4-vs2.3.6.2/fs/file.c
3340 --- linux-3.9.4/fs/file.c       2013-05-31 13:45:23.000000000 +0000
3341 +++ linux-3.9.4-vs2.3.6.2/fs/file.c     2013-05-31 14:47:11.000000000 +0000
3342 @@ -22,6 +22,7 @@
3343  #include <linux/spinlock.h>
3344  #include <linux/rcupdate.h>
3345  #include <linux/workqueue.h>
3346 +#include <linux/vs_limit.h>
3347  
3348  struct fdtable_defer {
3349         spinlock_t lock;
3350 @@ -364,6 +365,8 @@ struct files_struct *dup_fd(struct files
3351                 struct file *f = *old_fds++;
3352                 if (f) {
3353                         get_file(f);
3354 +                       /* TODO: sum it first for check and performance */
3355 +                       vx_openfd_inc(open_files - i);
3356                 } else {
3357                         /*
3358                          * The fd may be claimed in the fd bitmap but not yet
3359 @@ -429,9 +432,11 @@ static void close_files(struct files_str
3360                                         filp_close(file, files);
3361                                         cond_resched();
3362                                 }
3363 +                               vx_openfd_dec(i);
3364                         }
3365                         i++;
3366                         set >>= 1;
3367 +                       cond_resched();
3368                 }
3369         }
3370  }
3371 @@ -567,6 +572,7 @@ repeat:
3372         else
3373                 __clear_close_on_exec(fd, fdt);
3374         error = fd;
3375 +       vx_openfd_inc(fd);
3376  #if 1
3377         /* Sanity check */
3378         if (rcu_dereference_raw(fdt->fd[fd]) != NULL) {
3379 @@ -597,6 +603,7 @@ static void __put_unused_fd(struct files
3380         __clear_open_fd(fd, fdt);
3381         if (fd < files->next_fd)
3382                 files->next_fd = fd;
3383 +       vx_openfd_dec(fd);
3384  }
3385  
3386  void put_unused_fd(unsigned int fd)
3387 @@ -876,6 +883,8 @@ static int do_dup2(struct files_struct *
3388  
3389         if (tofree)
3390                 filp_close(tofree, files);
3391 +       else
3392 +               vx_openfd_inc(fd);      /* fd was unused */
3393  
3394         return fd;
3395  
3396 diff -NurpP --minimal linux-3.9.4/fs/file_table.c linux-3.9.4-vs2.3.6.2/fs/file_table.c
3397 --- linux-3.9.4/fs/file_table.c 2013-05-31 13:45:23.000000000 +0000
3398 +++ linux-3.9.4-vs2.3.6.2/fs/file_table.c       2013-05-31 14:47:11.000000000 +0000
3399 @@ -26,6 +26,8 @@
3400  #include <linux/hardirq.h>
3401  #include <linux/task_work.h>
3402  #include <linux/ima.h>
3403 +#include <linux/vs_limit.h>
3404 +#include <linux/vs_context.h>
3405  
3406  #include <linux/atomic.h>
3407  
3408 @@ -140,6 +142,8 @@ struct file *get_empty_filp(void)
3409         spin_lock_init(&f->f_lock);
3410         eventpoll_init_file(f);
3411         /* f->f_version: 0 */
3412 +       f->f_xid = vx_current_xid();
3413 +       vx_files_inc(f);
3414         return f;
3415  
3416  over:
3417 @@ -257,6 +261,8 @@ static void __fput(struct file *file)
3418                 i_readcount_dec(inode);
3419         if (file->f_mode & FMODE_WRITE)
3420                 drop_file_write_access(file);
3421 +       vx_files_dec(file);
3422 +       file->f_xid = 0;
3423         file->f_path.dentry = NULL;
3424         file->f_path.mnt = NULL;
3425         file->f_inode = NULL;
3426 @@ -344,6 +350,8 @@ void put_filp(struct file *file)
3427  {
3428         if (atomic_long_dec_and_test(&file->f_count)) {
3429                 security_file_free(file);
3430 +               vx_files_dec(file);
3431 +               file->f_xid = 0;
3432                 file_sb_list_del(file);
3433                 file_free(file);
3434         }
3435 diff -NurpP --minimal linux-3.9.4/fs/fs_struct.c linux-3.9.4-vs2.3.6.2/fs/fs_struct.c
3436 --- linux-3.9.4/fs/fs_struct.c  2013-05-31 13:45:23.000000000 +0000
3437 +++ linux-3.9.4-vs2.3.6.2/fs/fs_struct.c        2013-05-31 14:47:11.000000000 +0000
3438 @@ -4,6 +4,7 @@
3439  #include <linux/path.h>
3440  #include <linux/slab.h>
3441  #include <linux/fs_struct.h>
3442 +#include <linux/vserver/global.h>
3443  #include "internal.h"
3444  
3445  /*
3446 @@ -87,6 +88,7 @@ void free_fs_struct(struct fs_struct *fs
3447  {
3448         path_put(&fs->root);
3449         path_put(&fs->pwd);
3450 +       atomic_dec(&vs_global_fs);
3451         kmem_cache_free(fs_cachep, fs);
3452  }
3453  
3454 @@ -124,6 +126,7 @@ struct fs_struct *copy_fs_struct(struct
3455                 fs->pwd = old->pwd;
3456                 path_get(&fs->pwd);
3457                 spin_unlock(&old->lock);
3458 +               atomic_inc(&vs_global_fs);
3459         }
3460         return fs;
3461  }
3462 diff -NurpP --minimal linux-3.9.4/fs/gfs2/file.c linux-3.9.4-vs2.3.6.2/fs/gfs2/file.c
3463 --- linux-3.9.4/fs/gfs2/file.c  2013-05-31 13:45:23.000000000 +0000
3464 +++ linux-3.9.4-vs2.3.6.2/fs/gfs2/file.c        2013-05-31 19:54:27.000000000 +0000
3465 @@ -143,6 +143,9 @@ static const u32 fsflags_to_gfs2[32] = {
3466         [12] = GFS2_DIF_EXHASH,
3467         [14] = GFS2_DIF_INHERIT_JDATA,
3468         [17] = GFS2_DIF_TOPDIR,
3469 +       [27] = GFS2_DIF_IXUNLINK,
3470 +       [26] = GFS2_DIF_BARRIER,
3471 +       [29] = GFS2_DIF_COW,
3472  };
3473  
3474  static const u32 gfs2_to_fsflags[32] = {
3475 @@ -153,6 +156,9 @@ static const u32 gfs2_to_fsflags[32] = {
3476         [gfs2fl_ExHash] = FS_INDEX_FL,
3477         [gfs2fl_TopLevel] = FS_TOPDIR_FL,
3478         [gfs2fl_InheritJdata] = FS_JOURNAL_DATA_FL,
3479 +       [gfs2fl_IXUnlink] = FS_IXUNLINK_FL,
3480 +       [gfs2fl_Barrier] = FS_BARRIER_FL,
3481 +       [gfs2fl_Cow] = FS_COW_FL,
3482  };
3483  
3484  static int gfs2_get_flags(struct file *filp, u32 __user *ptr)
3485 @@ -183,12 +189,18 @@ void gfs2_set_inode_flags(struct inode *
3486  {
3487         struct gfs2_inode *ip = GFS2_I(inode);
3488         unsigned int flags = inode->i_flags;
3489 +       unsigned int vflags = inode->i_vflags;
3490 +
3491 +       flags &= ~(S_IMMUTABLE | S_IXUNLINK |
3492 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC | S_NOSEC);
3493  
3494 -       flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC|S_NOSEC);
3495         if ((ip->i_eattr == 0) && !is_sxid(inode->i_mode))
3496                 inode->i_flags |= S_NOSEC;
3497         if (ip->i_diskflags & GFS2_DIF_IMMUTABLE)
3498                 flags |= S_IMMUTABLE;
3499 +       if (ip->i_diskflags & GFS2_DIF_IXUNLINK)
3500 +               flags |= S_IXUNLINK;
3501 +
3502         if (ip->i_diskflags & GFS2_DIF_APPENDONLY)
3503                 flags |= S_APPEND;
3504         if (ip->i_diskflags & GFS2_DIF_NOATIME)
3505 @@ -196,6 +208,43 @@ void gfs2_set_inode_flags(struct inode *
3506         if (ip->i_diskflags & GFS2_DIF_SYNC)
3507                 flags |= S_SYNC;
3508         inode->i_flags = flags;
3509 +
3510 +       vflags &= ~(V_BARRIER | V_COW);
3511 +
3512 +       if (ip->i_diskflags & GFS2_DIF_BARRIER)
3513 +               vflags |= V_BARRIER;
3514 +       if (ip->i_diskflags & GFS2_DIF_COW)
3515 +               vflags |= V_COW;
3516 +       inode->i_vflags = vflags;
3517 +}
3518 +
3519 +void gfs2_get_inode_flags(struct inode *inode)
3520 +{
3521 +       struct gfs2_inode *ip = GFS2_I(inode);
3522 +       unsigned int flags = inode->i_flags;
3523 +       unsigned int vflags = inode->i_vflags;
3524 +
3525 +       ip->i_diskflags &= ~(GFS2_DIF_APPENDONLY |
3526 +                       GFS2_DIF_NOATIME | GFS2_DIF_SYNC |
3527 +                       GFS2_DIF_IMMUTABLE | GFS2_DIF_IXUNLINK |
3528 +                       GFS2_DIF_BARRIER | GFS2_DIF_COW);
3529 +
3530 +       if (flags & S_IMMUTABLE)
3531 +               ip->i_diskflags |= GFS2_DIF_IMMUTABLE;
3532 +       if (flags & S_IXUNLINK)
3533 +               ip->i_diskflags |= GFS2_DIF_IXUNLINK;
3534 +
3535 +       if (flags & S_APPEND)
3536 +               ip->i_diskflags |= GFS2_DIF_APPENDONLY;
3537 +       if (flags & S_NOATIME)
3538 +               ip->i_diskflags |= GFS2_DIF_NOATIME;
3539 +       if (flags & S_SYNC)
3540 +               ip->i_diskflags |= GFS2_DIF_SYNC;
3541 +
3542 +       if (vflags & V_BARRIER)
3543 +               ip->i_diskflags |= GFS2_DIF_BARRIER;
3544 +       if (vflags & V_COW)
3545 +               ip->i_diskflags |= GFS2_DIF_COW;
3546  }
3547  
3548  /* Flags that can be set by user space */
3549 @@ -309,6 +358,37 @@ static int gfs2_set_flags(struct file *f
3550         return do_gfs2_set_flags(filp, gfsflags, ~GFS2_DIF_JDATA);
3551  }
3552  
3553 +int gfs2_sync_flags(struct inode *inode, int flags, int vflags)
3554 +{
3555 +       struct gfs2_inode *ip = GFS2_I(inode);
3556 +       struct gfs2_sbd *sdp = GFS2_SB(inode);
3557 +       struct buffer_head *bh;
3558 +       struct gfs2_holder gh;
3559 +       int error;
3560 +
3561 +       error = gfs2_glock_nq_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &gh);
3562 +       if (error)
3563 +               return error;
3564 +       error = gfs2_trans_begin(sdp, RES_DINODE, 0);
3565 +       if (error)
3566 +               goto out;
3567 +       error = gfs2_meta_inode_buffer(ip, &bh);
3568 +       if (error)
3569 +               goto out_trans_end;
3570 +       gfs2_trans_add_meta(ip->i_gl, bh);
3571 +       inode->i_flags = flags;
3572 +       inode->i_vflags = vflags;
3573 +       gfs2_get_inode_flags(inode);
3574 +       gfs2_dinode_out(ip, bh->b_data);
3575 +       brelse(bh);
3576 +       gfs2_set_aops(inode);
3577 +out_trans_end:
3578 +       gfs2_trans_end(sdp);
3579 +out:
3580 +       gfs2_glock_dq_uninit(&gh);
3581 +       return error;
3582 +}
3583 +
3584  static long gfs2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
3585  {
3586         switch(cmd) {
3587 diff -NurpP --minimal linux-3.9.4/fs/gfs2/inode.h linux-3.9.4-vs2.3.6.2/fs/gfs2/inode.h
3588 --- linux-3.9.4/fs/gfs2/inode.h 2012-12-11 03:30:57.000000000 +0000
3589 +++ linux-3.9.4-vs2.3.6.2/fs/gfs2/inode.h       2013-05-31 14:47:11.000000000 +0000
3590 @@ -117,6 +117,7 @@ extern const struct file_operations gfs2
3591  extern const struct file_operations gfs2_dir_fops_nolock;
3592  
3593  extern void gfs2_set_inode_flags(struct inode *inode);
3594 +extern int gfs2_sync_flags(struct inode *inode, int flags, int vflags);
3595   
3596  #ifdef CONFIG_GFS2_FS_LOCKING_DLM
3597  extern const struct file_operations gfs2_file_fops;
3598 diff -NurpP --minimal linux-3.9.4/fs/hostfs/hostfs.h linux-3.9.4-vs2.3.6.2/fs/hostfs/hostfs.h
3599 --- linux-3.9.4/fs/hostfs/hostfs.h      2012-12-11 03:30:57.000000000 +0000
3600 +++ linux-3.9.4-vs2.3.6.2/fs/hostfs/hostfs.h    2013-05-31 14:47:11.000000000 +0000
3601 @@ -42,6 +42,7 @@ struct hostfs_iattr {
3602         unsigned short  ia_mode;
3603         uid_t           ia_uid;
3604         gid_t           ia_gid;
3605 +       tag_t           ia_tag;
3606         loff_t          ia_size;
3607         struct timespec ia_atime;
3608         struct timespec ia_mtime;
3609 diff -NurpP --minimal linux-3.9.4/fs/inode.c linux-3.9.4-vs2.3.6.2/fs/inode.c
3610 --- linux-3.9.4/fs/inode.c      2013-05-31 13:45:24.000000000 +0000
3611 +++ linux-3.9.4-vs2.3.6.2/fs/inode.c    2013-06-01 09:01:48.000000000 +0000
3612 @@ -17,6 +17,7 @@
3613  #include <linux/prefetch.h>
3614  #include <linux/buffer_head.h> /* for inode_has_buffers */
3615  #include <linux/ratelimit.h>
3616 +#include <linux/vs_tag.h>
3617  #include "internal.h"
3618  
3619  /*
3620 @@ -128,6 +129,8 @@ int inode_init_always(struct super_block
3621         struct address_space *const mapping = &inode->i_data;
3622  
3623         inode->i_sb = sb;
3624 +
3625 +       /* essential because of inode slab reuse */
3626         inode->i_blkbits = sb->s_blocksize_bits;
3627         inode->i_flags = 0;
3628         atomic_set(&inode->i_count, 1);
3629 @@ -137,6 +140,7 @@ int inode_init_always(struct super_block
3630         inode->i_opflags = 0;
3631         i_uid_write(inode, 0);
3632         i_gid_write(inode, 0);
3633 +       i_tag_write(inode, 0);
3634         atomic_set(&inode->i_writecount, 0);
3635         inode->i_size = 0;
3636         inode->i_blocks = 0;
3637 @@ -149,6 +153,7 @@ int inode_init_always(struct super_block
3638         inode->i_bdev = NULL;
3639         inode->i_cdev = NULL;
3640         inode->i_rdev = 0;
3641 +       inode->i_mdev = 0;
3642         inode->dirtied_when = 0;
3643  
3644         if (security_inode_alloc(inode))
3645 @@ -483,6 +488,8 @@ void __insert_inode_hash(struct inode *i
3646  }
3647  EXPORT_SYMBOL(__insert_inode_hash);
3648  
3649 +EXPORT_SYMBOL_GPL(__iget);
3650 +
3651  /**
3652   *     __remove_inode_hash - remove an inode from the hash
3653   *     @inode: inode to unhash
3654 @@ -1799,9 +1806,11 @@ void init_special_inode(struct inode *in
3655         if (S_ISCHR(mode)) {
3656                 inode->i_fop = &def_chr_fops;
3657                 inode->i_rdev = rdev;
3658 +               inode->i_mdev = rdev;
3659         } else if (S_ISBLK(mode)) {
3660                 inode->i_fop = &def_blk_fops;
3661                 inode->i_rdev = rdev;
3662 +               inode->i_mdev = rdev;
3663         } else if (S_ISFIFO(mode))
3664                 inode->i_fop = &def_fifo_fops;
3665         else if (S_ISSOCK(mode))
3666 @@ -1830,6 +1839,7 @@ void inode_init_owner(struct inode *inod
3667         } else
3668                 inode->i_gid = current_fsgid();
3669         inode->i_mode = mode;
3670 +       i_tag_write(inode, dx_current_fstag(inode->i_sb));
3671  }
3672  EXPORT_SYMBOL(inode_init_owner);
3673  
3674 diff -NurpP --minimal linux-3.9.4/fs/ioctl.c linux-3.9.4-vs2.3.6.2/fs/ioctl.c
3675 --- linux-3.9.4/fs/ioctl.c      2013-05-31 13:45:24.000000000 +0000
3676 +++ linux-3.9.4-vs2.3.6.2/fs/ioctl.c    2013-05-31 14:47:11.000000000 +0000
3677 @@ -15,6 +15,9 @@
3678  #include <linux/writeback.h>
3679  #include <linux/buffer_head.h>
3680  #include <linux/falloc.h>
3681 +#include <linux/proc_fs.h>
3682 +#include <linux/vserver/inode.h>
3683 +#include <linux/vs_tag.h>
3684  
3685  #include <asm/ioctls.h>
3686  
3687 diff -NurpP --minimal linux-3.9.4/fs/ioprio.c linux-3.9.4-vs2.3.6.2/fs/ioprio.c
3688 --- linux-3.9.4/fs/ioprio.c     2012-12-11 03:30:57.000000000 +0000
3689 +++ linux-3.9.4-vs2.3.6.2/fs/ioprio.c   2013-05-31 14:47:11.000000000 +0000
3690 @@ -28,6 +28,7 @@
3691  #include <linux/syscalls.h>
3692  #include <linux/security.h>
3693  #include <linux/pid_namespace.h>
3694 +#include <linux/vs_base.h>
3695  
3696  int set_task_ioprio(struct task_struct *task, int ioprio)
3697  {
3698 @@ -105,6 +106,8 @@ SYSCALL_DEFINE3(ioprio_set, int, which,
3699                         else
3700                                 pgrp = find_vpid(who);
3701                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
3702 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
3703 +                                       continue;
3704                                 ret = set_task_ioprio(p, ioprio);
3705                                 if (ret)
3706                                         break;
3707 @@ -198,6 +201,8 @@ SYSCALL_DEFINE2(ioprio_get, int, which,
3708                         else
3709                                 pgrp = find_vpid(who);
3710                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
3711 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
3712 +                                       continue;
3713                                 tmpio = get_task_ioprio(p);
3714                                 if (tmpio < 0)
3715                                         continue;
3716 diff -NurpP --minimal linux-3.9.4/fs/jfs/file.c linux-3.9.4-vs2.3.6.2/fs/jfs/file.c
3717 --- linux-3.9.4/fs/jfs/file.c   2013-02-19 13:58:48.000000000 +0000
3718 +++ linux-3.9.4-vs2.3.6.2/fs/jfs/file.c 2013-05-31 14:47:11.000000000 +0000
3719 @@ -109,7 +109,8 @@ int jfs_setattr(struct dentry *dentry, s
3720         if (is_quota_modification(inode, iattr))
3721                 dquot_initialize(inode);
3722         if ((iattr->ia_valid & ATTR_UID && !uid_eq(iattr->ia_uid, inode->i_uid)) ||
3723 -           (iattr->ia_valid & ATTR_GID && !gid_eq(iattr->ia_gid, inode->i_gid))) {
3724 +           (iattr->ia_valid & ATTR_GID && !gid_eq(iattr->ia_gid, inode->i_gid)) ||
3725 +           (iattr->ia_valid & ATTR_TAG && !tag_eq(iattr->ia_tag, inode->i_tag))) {
3726                 rc = dquot_transfer(inode, iattr);
3727                 if (rc)
3728                         return rc;
3729 @@ -144,6 +145,7 @@ const struct inode_operations jfs_file_i
3730  #ifdef CONFIG_JFS_POSIX_ACL
3731         .get_acl        = jfs_get_acl,
3732  #endif
3733 +       .sync_flags     = jfs_sync_flags,
3734  };
3735  
3736  const struct file_operations jfs_file_operations = {
3737 diff -NurpP --minimal linux-3.9.4/fs/jfs/ioctl.c linux-3.9.4-vs2.3.6.2/fs/jfs/ioctl.c
3738 --- linux-3.9.4/fs/jfs/ioctl.c  2013-05-31 13:45:24.000000000 +0000
3739 +++ linux-3.9.4-vs2.3.6.2/fs/jfs/ioctl.c        2013-05-31 14:47:11.000000000 +0000
3740 @@ -12,6 +12,7 @@
3741  #include <linux/time.h>
3742  #include <linux/sched.h>
3743  #include <linux/blkdev.h>
3744 +#include <linux/mount.h>
3745  #include <asm/current.h>
3746  #include <asm/uaccess.h>
3747  
3748 @@ -56,6 +57,16 @@ static long jfs_map_ext2(unsigned long f
3749  }
3750  
3751  
3752 +int jfs_sync_flags(struct inode *inode, int flags, int vflags)
3753 +{
3754 +       inode->i_flags = flags;
3755 +       inode->i_vflags = vflags;
3756 +       jfs_get_inode_flags(JFS_IP(inode));
3757 +       inode->i_ctime = CURRENT_TIME_SEC;
3758 +       mark_inode_dirty(inode);
3759 +       return 0;
3760 +}
3761 +
3762  long jfs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
3763  {
3764         struct inode *inode = file_inode(filp);
3765 @@ -89,6 +100,11 @@ long jfs_ioctl(struct file *filp, unsign
3766                 if (!S_ISDIR(inode->i_mode))
3767                         flags &= ~JFS_DIRSYNC_FL;
3768  
3769 +               if (IS_BARRIER(inode)) {
3770 +                       vxwprintk_task(1, "messing with the barrier.");
3771 +                       return -EACCES;
3772 +               }
3773 +
3774                 /* Is it quota file? Do not allow user to mess with it */
3775                 if (IS_NOQUOTA(inode)) {
3776                         err = -EPERM;
3777 @@ -106,8 +122,8 @@ long jfs_ioctl(struct file *filp, unsign
3778                  * the relevant capability.
3779                  */
3780                 if ((oldflags & JFS_IMMUTABLE_FL) ||
3781 -                       ((flags ^ oldflags) &
3782 -                       (JFS_APPEND_FL | JFS_IMMUTABLE_FL))) {
3783 +                       ((flags ^ oldflags) & (JFS_APPEND_FL |
3784 +                       JFS_IMMUTABLE_FL | JFS_IXUNLINK_FL))) {
3785                         if (!capable(CAP_LINUX_IMMUTABLE)) {
3786                                 mutex_unlock(&inode->i_mutex);
3787                                 err = -EPERM;
3788 @@ -115,7 +131,7 @@ long jfs_ioctl(struct file *filp, unsign
3789                         }
3790                 }
3791  
3792 -               flags = flags & JFS_FL_USER_MODIFIABLE;
3793 +               flags &= JFS_FL_USER_MODIFIABLE;
3794                 flags |= oldflags & ~JFS_FL_USER_MODIFIABLE;
3795                 jfs_inode->mode2 = flags;
3796  
3797 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
3798 --- linux-3.9.4/fs/jfs/jfs_dinode.h     2012-12-11 03:30:57.000000000 +0000
3799 +++ linux-3.9.4-vs2.3.6.2/fs/jfs/jfs_dinode.h   2013-05-31 14:47:11.000000000 +0000
3800 @@ -161,9 +161,13 @@ struct dinode {
3801  
3802  #define JFS_APPEND_FL          0x01000000 /* writes to file may only append */
3803  #define JFS_IMMUTABLE_FL       0x02000000 /* Immutable file */
3804 +#define JFS_IXUNLINK_FL                0x08000000 /* Immutable invert on unlink */
3805  
3806 -#define JFS_FL_USER_VISIBLE    0x03F80000
3807 -#define JFS_FL_USER_MODIFIABLE 0x03F80000
3808 +#define JFS_BARRIER_FL         0x04000000 /* Barrier for chroot() */
3809 +#define JFS_COW_FL             0x20000000 /* Copy on Write marker */
3810 +
3811 +#define JFS_FL_USER_VISIBLE    0x07F80000
3812 +#define JFS_FL_USER_MODIFIABLE 0x07F80000
3813  #define JFS_FL_INHERIT         0x03C80000
3814  
3815  /* These are identical to EXT[23]_IOC_GETFLAGS/SETFLAGS */
3816 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
3817 --- linux-3.9.4/fs/jfs/jfs_filsys.h     2012-12-11 03:30:57.000000000 +0000
3818 +++ linux-3.9.4-vs2.3.6.2/fs/jfs/jfs_filsys.h   2013-05-31 14:47:11.000000000 +0000
3819 @@ -266,6 +266,7 @@
3820  #define JFS_NAME_MAX   255
3821  #define JFS_PATH_MAX   BPSIZE
3822  
3823 +#define JFS_TAGGED             0x00800000      /* Context Tagging */
3824  
3825  /*
3826   *     file system state (superblock state)
3827 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
3828 --- linux-3.9.4/fs/jfs/jfs_imap.c       2012-12-11 03:30:57.000000000 +0000
3829 +++ linux-3.9.4-vs2.3.6.2/fs/jfs/jfs_imap.c     2013-05-31 14:47:11.000000000 +0000
3830 @@ -46,6 +46,7 @@
3831  #include <linux/pagemap.h>
3832  #include <linux/quotaops.h>
3833  #include <linux/slab.h>
3834 +#include <linux/vs_tag.h>
3835  
3836  #include "jfs_incore.h"
3837  #include "jfs_inode.h"
3838 @@ -3058,6 +3059,8 @@ static int copy_from_dinode(struct dinod
3839  {
3840         struct jfs_inode_info *jfs_ip = JFS_IP(ip);
3841         struct jfs_sb_info *sbi = JFS_SBI(ip->i_sb);
3842 +       kuid_t uid;
3843 +       kgid_t gid;
3844  
3845         jfs_ip->fileset = le32_to_cpu(dip->di_fileset);
3846         jfs_ip->mode2 = le32_to_cpu(dip->di_mode);
3847 @@ -3078,14 +3081,19 @@ static int copy_from_dinode(struct dinod
3848         }
3849         set_nlink(ip, le32_to_cpu(dip->di_nlink));
3850  
3851 -       jfs_ip->saved_uid = make_kuid(&init_user_ns, le32_to_cpu(dip->di_uid));
3852 +       uid = make_kuid(&init_user_ns, le32_to_cpu(dip->di_uid));
3853 +       gid = make_kgid(&init_user_ns, le32_to_cpu(dip->di_gid));
3854 +       ip->i_tag = make_ktag(&init_user_ns,
3855 +               INOTAG_TAG(DX_TAG(ip), uid, gid, 0));
3856 +
3857 +       jfs_ip->saved_uid = INOTAG_UID(DX_TAG(ip), uid, gid);
3858         if (!uid_valid(sbi->uid))
3859                 ip->i_uid = jfs_ip->saved_uid;
3860         else {
3861                 ip->i_uid = sbi->uid;
3862         }
3863  
3864 -       jfs_ip->saved_gid = make_kgid(&init_user_ns, le32_to_cpu(dip->di_gid));
3865 +       jfs_ip->saved_gid = INOTAG_GID(DX_TAG(ip), uid, gid);
3866         if (!gid_valid(sbi->gid))
3867                 ip->i_gid = jfs_ip->saved_gid;
3868         else {
3869 @@ -3150,16 +3158,14 @@ static void copy_to_dinode(struct dinode
3870         dip->di_size = cpu_to_le64(ip->i_size);
3871         dip->di_nblocks = cpu_to_le64(PBLK2LBLK(ip->i_sb, ip->i_blocks));
3872         dip->di_nlink = cpu_to_le32(ip->i_nlink);
3873 -       if (!uid_valid(sbi->uid))
3874 -               dip->di_uid = cpu_to_le32(i_uid_read(ip));
3875 -       else
3876 -               dip->di_uid =cpu_to_le32(from_kuid(&init_user_ns,
3877 -                                                  jfs_ip->saved_uid));
3878 -       if (!gid_valid(sbi->gid))
3879 -               dip->di_gid = cpu_to_le32(i_gid_read(ip));
3880 -       else
3881 -               dip->di_gid = cpu_to_le32(from_kgid(&init_user_ns,
3882 -                                                   jfs_ip->saved_gid));
3883 +       dip->di_uid = cpu_to_le32(from_kuid(&init_user_ns,
3884 +               TAGINO_UID(DX_TAG(ip),
3885 +               !uid_valid(sbi->uid) ? ip->i_uid : jfs_ip->saved_uid,
3886 +               ip->i_tag)));
3887 +       dip->di_gid = cpu_to_le32(from_kuid(&init_user_ns,
3888 +               TAGINO_GID(DX_TAG(ip),
3889 +               !gid_valid(sbi->gid) ? ip->i_gid : jfs_ip->saved_gid,
3890 +               ip->i_tag)));
3891         jfs_get_inode_flags(jfs_ip);
3892         /*
3893          * mode2 is only needed for storing the higher order bits.
3894 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
3895 --- linux-3.9.4/fs/jfs/jfs_inode.c      2012-12-11 03:30:57.000000000 +0000
3896 +++ linux-3.9.4-vs2.3.6.2/fs/jfs/jfs_inode.c    2013-05-31 14:47:11.000000000 +0000
3897 @@ -18,6 +18,7 @@
3898  
3899  #include <linux/fs.h>
3900  #include <linux/quotaops.h>
3901 +#include <linux/vs_tag.h>
3902  #include "jfs_incore.h"
3903  #include "jfs_inode.h"
3904  #include "jfs_filsys.h"
3905 @@ -30,29 +31,46 @@ void jfs_set_inode_flags(struct inode *i
3906  {
3907         unsigned int flags = JFS_IP(inode)->mode2;
3908  
3909 -       inode->i_flags &= ~(S_IMMUTABLE | S_APPEND |
3910 -               S_NOATIME | S_DIRSYNC | S_SYNC);
3911 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
3912 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
3913  
3914         if (flags & JFS_IMMUTABLE_FL)
3915                 inode->i_flags |= S_IMMUTABLE;
3916 +       if (flags & JFS_IXUNLINK_FL)
3917 +               inode->i_flags |= S_IXUNLINK;
3918 +
3919 +       if (flags & JFS_SYNC_FL)
3920 +               inode->i_flags |= S_SYNC;
3921         if (flags & JFS_APPEND_FL)
3922                 inode->i_flags |= S_APPEND;
3923         if (flags & JFS_NOATIME_FL)
3924                 inode->i_flags |= S_NOATIME;
3925         if (flags & JFS_DIRSYNC_FL)
3926                 inode->i_flags |= S_DIRSYNC;
3927 -       if (flags & JFS_SYNC_FL)
3928 -               inode->i_flags |= S_SYNC;
3929 +
3930 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
3931 +
3932 +       if (flags & JFS_BARRIER_FL)
3933 +               inode->i_vflags |= V_BARRIER;
3934 +       if (flags & JFS_COW_FL)
3935 +               inode->i_vflags |= V_COW;
3936  }
3937  
3938  void jfs_get_inode_flags(struct jfs_inode_info *jfs_ip)
3939  {
3940         unsigned int flags = jfs_ip->vfs_inode.i_flags;
3941 +       unsigned int vflags = jfs_ip->vfs_inode.i_vflags;
3942 +
3943 +       jfs_ip->mode2 &= ~(JFS_IMMUTABLE_FL | JFS_IXUNLINK_FL |
3944 +                          JFS_APPEND_FL | JFS_NOATIME_FL |
3945 +                          JFS_DIRSYNC_FL | JFS_SYNC_FL |
3946 +                          JFS_BARRIER_FL | JFS_COW_FL);
3947  
3948 -       jfs_ip->mode2 &= ~(JFS_IMMUTABLE_FL | JFS_APPEND_FL | JFS_NOATIME_FL |
3949 -                          JFS_DIRSYNC_FL | JFS_SYNC_FL);
3950         if (flags & S_IMMUTABLE)
3951                 jfs_ip->mode2 |= JFS_IMMUTABLE_FL;
3952 +       if (flags & S_IXUNLINK)
3953 +               jfs_ip->mode2 |= JFS_IXUNLINK_FL;
3954 +
3955         if (flags & S_APPEND)
3956                 jfs_ip->mode2 |= JFS_APPEND_FL;
3957         if (flags & S_NOATIME)
3958 @@ -61,6 +79,11 @@ void jfs_get_inode_flags(struct jfs_inod
3959                 jfs_ip->mode2 |= JFS_DIRSYNC_FL;
3960         if (flags & S_SYNC)
3961                 jfs_ip->mode2 |= JFS_SYNC_FL;
3962 +
3963 +       if (vflags & V_BARRIER)
3964 +               jfs_ip->mode2 |= JFS_BARRIER_FL;
3965 +       if (vflags & V_COW)
3966 +               jfs_ip->mode2 |= JFS_COW_FL;
3967  }
3968  
3969  /*
3970 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
3971 --- linux-3.9.4/fs/jfs/jfs_inode.h      2012-12-11 03:30:57.000000000 +0000
3972 +++ linux-3.9.4-vs2.3.6.2/fs/jfs/jfs_inode.h    2013-05-31 14:47:11.000000000 +0000
3973 @@ -39,6 +39,7 @@ extern struct dentry *jfs_fh_to_dentry(s
3974  extern struct dentry *jfs_fh_to_parent(struct super_block *sb, struct fid *fid,
3975         int fh_len, int fh_type);
3976  extern void jfs_set_inode_flags(struct inode *);
3977 +extern int jfs_sync_flags(struct inode *, int, int);
3978  extern int jfs_get_block(struct inode *, sector_t, struct buffer_head *, int);
3979  extern int jfs_setattr(struct dentry *, struct iattr *);
3980  
3981 diff -NurpP --minimal linux-3.9.4/fs/jfs/namei.c linux-3.9.4-vs2.3.6.2/fs/jfs/namei.c
3982 --- linux-3.9.4/fs/jfs/namei.c  2012-12-11 03:30:57.000000000 +0000
3983 +++ linux-3.9.4-vs2.3.6.2/fs/jfs/namei.c        2013-05-31 14:47:11.000000000 +0000
3984 @@ -22,6 +22,7 @@
3985  #include <linux/ctype.h>
3986  #include <linux/quotaops.h>
3987  #include <linux/exportfs.h>
3988 +#include <linux/vs_tag.h>
3989  #include "jfs_incore.h"
3990  #include "jfs_superblock.h"
3991  #include "jfs_inode.h"
3992 @@ -1461,6 +1462,7 @@ static struct dentry *jfs_lookup(struct
3993                         jfs_err("jfs_lookup: iget failed on inum %d", (uint)inum);
3994         }
3995  
3996 +       dx_propagate_tag(nd, ip);
3997         return d_splice_alias(ip, dentry);
3998  }
3999  
4000 @@ -1525,6 +1527,7 @@ const struct inode_operations jfs_dir_in
4001  #ifdef CONFIG_JFS_POSIX_ACL
4002         .get_acl        = jfs_get_acl,
4003  #endif
4004 +       .sync_flags     = jfs_sync_flags,
4005  };
4006  
4007  const struct file_operations jfs_dir_operations = {
4008 diff -NurpP --minimal linux-3.9.4/fs/jfs/super.c linux-3.9.4-vs2.3.6.2/fs/jfs/super.c
4009 --- linux-3.9.4/fs/jfs/super.c  2013-05-31 13:45:24.000000000 +0000
4010 +++ linux-3.9.4-vs2.3.6.2/fs/jfs/super.c        2013-05-31 14:47:11.000000000 +0000
4011 @@ -199,7 +199,8 @@ enum {
4012         Opt_integrity, Opt_nointegrity, Opt_iocharset, Opt_resize,
4013         Opt_resize_nosize, Opt_errors, Opt_ignore, Opt_err, Opt_quota,
4014         Opt_usrquota, Opt_grpquota, Opt_uid, Opt_gid, Opt_umask,
4015 -       Opt_discard, Opt_nodiscard, Opt_discard_minblk
4016 +       Opt_discard, Opt_nodiscard, Opt_discard_minblk,
4017 +       Opt_tag, Opt_notag, Opt_tagid
4018  };
4019  
4020  static const match_table_t tokens = {
4021 @@ -209,6 +210,10 @@ static const match_table_t tokens = {
4022         {Opt_resize, "resize=%u"},
4023         {Opt_resize_nosize, "resize"},
4024         {Opt_errors, "errors=%s"},
4025 +       {Opt_tag, "tag"},
4026 +       {Opt_notag, "notag"},
4027 +       {Opt_tagid, "tagid=%u"},
4028 +       {Opt_tag, "tagxid"},
4029         {Opt_ignore, "noquota"},
4030         {Opt_ignore, "quota"},
4031         {Opt_usrquota, "usrquota"},
4032 @@ -385,7 +390,20 @@ static int parse_options(char *options,
4033                         }
4034                         break;
4035                 }
4036 -
4037 +#ifndef CONFIG_TAGGING_NONE
4038 +               case Opt_tag:
4039 +                       *flag |= JFS_TAGGED;
4040 +                       break;
4041 +               case Opt_notag:
4042 +                       *flag &= JFS_TAGGED;
4043 +                       break;
4044 +#endif
4045 +#ifdef CONFIG_PROPAGATE
4046 +               case Opt_tagid:
4047 +                       /* use args[0] */
4048 +                       *flag |= JFS_TAGGED;
4049 +                       break;
4050 +#endif
4051                 default:
4052                         printk("jfs: Unrecognized mount option \"%s\" "
4053                                         " or missing value\n", p);
4054 @@ -417,6 +435,12 @@ static int jfs_remount(struct super_bloc
4055                 return -EINVAL;
4056         }
4057  
4058 +       if ((flag & JFS_TAGGED) && !(sb->s_flags & MS_TAGGED)) {
4059 +               printk(KERN_ERR "JFS: %s: tagging not permitted on remount.\n",
4060 +                       sb->s_id);
4061 +               return -EINVAL;
4062 +       }
4063 +
4064         if (newLVSize) {
4065                 if (sb->s_flags & MS_RDONLY) {
4066                         pr_err("JFS: resize requires volume" \
4067 @@ -502,6 +526,9 @@ static int jfs_fill_super(struct super_b
4068  #ifdef CONFIG_JFS_POSIX_ACL
4069         sb->s_flags |= MS_POSIXACL;
4070  #endif
4071 +       /* map mount option tagxid */
4072 +       if (sbi->flag & JFS_TAGGED)
4073 +               sb->s_flags |= MS_TAGGED;
4074  
4075         if (newLVSize) {
4076                 pr_err("resize option for remount only\n");
4077 diff -NurpP --minimal linux-3.9.4/fs/libfs.c linux-3.9.4-vs2.3.6.2/fs/libfs.c
4078 --- linux-3.9.4/fs/libfs.c      2013-02-19 13:58:48.000000000 +0000
4079 +++ linux-3.9.4-vs2.3.6.2/fs/libfs.c    2013-05-31 14:47:11.000000000 +0000
4080 @@ -135,7 +135,8 @@ static inline unsigned char dt_type(stru
4081   * both impossible due to the lock on directory.
4082   */
4083  
4084 -int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
4085 +static inline int do_dcache_readdir_filter(struct file *filp,
4086 +       void *dirent, filldir_t filldir, int (*filter)(struct dentry *dentry))
4087  {
4088         struct dentry *dentry = filp->f_path.dentry;
4089         struct dentry *cursor = filp->private_data;
4090 @@ -166,6 +167,8 @@ int dcache_readdir(struct file * filp, v
4091                         for (p=q->next; p != &dentry->d_subdirs; p=p->next) {
4092                                 struct dentry *next;
4093                                 next = list_entry(p, struct dentry, d_u.d_child);
4094 +                               if (filter && !filter(next))
4095 +                                       continue;
4096                                 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
4097                                 if (!simple_positive(next)) {
4098                                         spin_unlock(&next->d_lock);
4099 @@ -192,6 +195,17 @@ int dcache_readdir(struct file * filp, v
4100         return 0;
4101  }
4102  
4103 +int dcache_readdir(struct file *filp, void *dirent, filldir_t filldir)
4104 +{
4105 +       return do_dcache_readdir_filter(filp, dirent, filldir, NULL);
4106 +}
4107 +
4108 +int dcache_readdir_filter(struct file *filp, void *dirent, filldir_t filldir,
4109 +       int (*filter)(struct dentry *))
4110 +{
4111 +       return do_dcache_readdir_filter(filp, dirent, filldir, filter);
4112 +}
4113 +
4114  ssize_t generic_read_dir(struct file *filp, char __user *buf, size_t siz, loff_t *ppos)
4115  {
4116         return -EISDIR;
4117 @@ -981,6 +995,7 @@ EXPORT_SYMBOL(dcache_dir_close);
4118  EXPORT_SYMBOL(dcache_dir_lseek);
4119  EXPORT_SYMBOL(dcache_dir_open);
4120  EXPORT_SYMBOL(dcache_readdir);
4121 +EXPORT_SYMBOL(dcache_readdir_filter);
4122  EXPORT_SYMBOL(generic_read_dir);
4123  EXPORT_SYMBOL(mount_pseudo);
4124  EXPORT_SYMBOL(simple_write_begin);
4125 diff -NurpP --minimal linux-3.9.4/fs/locks.c linux-3.9.4-vs2.3.6.2/fs/locks.c
4126 --- linux-3.9.4/fs/locks.c      2013-05-31 13:45:24.000000000 +0000
4127 +++ linux-3.9.4-vs2.3.6.2/fs/locks.c    2013-05-31 15:53:57.000000000 +0000
4128 @@ -126,6 +126,8 @@
4129  #include <linux/time.h>
4130  #include <linux/rcupdate.h>
4131  #include <linux/pid_namespace.h>
4132 +#include <linux/vs_base.h>
4133 +#include <linux/vs_limit.h>
4134  
4135  #include <asm/uaccess.h>
4136  
4137 @@ -184,11 +186,17 @@ static void locks_init_lock_heads(struct
4138  /* Allocate an empty lock structure. */
4139  struct file_lock *locks_alloc_lock(void)
4140  {
4141 -       struct file_lock *fl = kmem_cache_zalloc(filelock_cache, GFP_KERNEL);
4142 +       struct file_lock *fl;
4143  
4144 -       if (fl)
4145 -               locks_init_lock_heads(fl);
4146 +       if (!vx_locks_avail(1))
4147 +               return NULL;
4148  
4149 +       fl = kmem_cache_zalloc(filelock_cache, GFP_KERNEL);
4150 +
4151 +       if (fl) {
4152 +               locks_init_lock_heads(fl);
4153 +               fl->fl_xid = -1;
4154 +       }
4155         return fl;
4156  }
4157  EXPORT_SYMBOL_GPL(locks_alloc_lock);
4158 @@ -212,6 +220,7 @@ void locks_free_lock(struct file_lock *f
4159         BUG_ON(!list_empty(&fl->fl_block));
4160         BUG_ON(!list_empty(&fl->fl_link));
4161  
4162 +       vx_locks_dec(fl);
4163         locks_release_private(fl);
4164         kmem_cache_free(filelock_cache, fl);
4165  }
4166 @@ -221,6 +230,7 @@ void locks_init_lock(struct file_lock *f
4167  {
4168         memset(fl, 0, sizeof(struct file_lock));
4169         locks_init_lock_heads(fl);
4170 +       fl->fl_xid = -1;
4171  }
4172  
4173  EXPORT_SYMBOL(locks_init_lock);
4174 @@ -261,6 +271,7 @@ void locks_copy_lock(struct file_lock *n
4175         new->fl_file = fl->fl_file;
4176         new->fl_ops = fl->fl_ops;
4177         new->fl_lmops = fl->fl_lmops;
4178 +       new->fl_xid = fl->fl_xid;
4179  
4180         locks_copy_private(new, fl);
4181  }
4182 @@ -299,6 +310,11 @@ static int flock_make_lock(struct file *
4183         fl->fl_flags = FL_FLOCK;
4184         fl->fl_type = type;
4185         fl->fl_end = OFFSET_MAX;
4186 +
4187 +       vxd_assert(filp->f_xid == vx_current_xid(),
4188 +               "f_xid(%d) == current(%d)", filp->f_xid, vx_current_xid());
4189 +       fl->fl_xid = filp->f_xid;
4190 +       vx_locks_inc(fl);
4191         
4192         *lock = fl;
4193         return 0;
4194 @@ -438,6 +454,7 @@ static int lease_init(struct file *filp,
4195  
4196         fl->fl_owner = current->files;
4197         fl->fl_pid = current->tgid;
4198 +       fl->fl_xid = vx_current_xid();
4199  
4200         fl->fl_file = filp;
4201         fl->fl_flags = FL_LEASE;
4202 @@ -457,6 +474,11 @@ static struct file_lock *lease_alloc(str
4203         if (fl == NULL)
4204                 return ERR_PTR(error);
4205  
4206 +       fl->fl_xid = vx_current_xid();
4207 +       if (filp)
4208 +               vxd_assert(filp->f_xid == fl->fl_xid,
4209 +                       "f_xid(%d) == fl_xid(%d)", filp->f_xid, fl->fl_xid);
4210 +       vx_locks_inc(fl);
4211         error = lease_init(filp, type, fl);
4212         if (error) {
4213                 locks_free_lock(fl);
4214 @@ -753,6 +775,7 @@ static int flock_lock_file(struct file *
4215                 lock_flocks();
4216         }
4217  
4218 +       new_fl->fl_xid = -1;
4219  find_conflict:
4220         for_each_lock(inode, before) {
4221                 struct file_lock *fl = *before;
4222 @@ -773,6 +796,7 @@ find_conflict:
4223                 goto out;
4224         locks_copy_lock(new_fl, request);
4225         locks_insert_lock(before, new_fl);
4226 +       vx_locks_inc(new_fl);
4227         new_fl = NULL;
4228         error = 0;
4229  
4230 @@ -783,7 +807,8 @@ out:
4231         return error;
4232  }
4233  
4234 -static int __posix_lock_file(struct inode *inode, struct file_lock *request, struct file_lock *conflock)
4235 +static int __posix_lock_file(struct inode *inode, struct file_lock *request,
4236 +       struct file_lock *conflock, xid_t xid)
4237  {
4238         struct file_lock *fl;
4239         struct file_lock *new_fl = NULL;
4240 @@ -793,6 +818,8 @@ static int __posix_lock_file(struct inod
4241         struct file_lock **before;
4242         int error, added = 0;
4243  
4244 +       vxd_assert(xid == vx_current_xid(),
4245 +               "xid(%d) == current(%d)", xid, vx_current_xid());
4246         /*
4247          * We may need two file_lock structures for this operation,
4248          * so we get them in advance to avoid races.
4249 @@ -803,7 +830,11 @@ static int __posix_lock_file(struct inod
4250             (request->fl_type != F_UNLCK ||
4251              request->fl_start != 0 || request->fl_end != OFFSET_MAX)) {
4252                 new_fl = locks_alloc_lock();
4253 +               new_fl->fl_xid = xid;
4254 +               vx_locks_inc(new_fl);
4255                 new_fl2 = locks_alloc_lock();
4256 +               new_fl2->fl_xid = xid;
4257 +               vx_locks_inc(new_fl2);
4258         }
4259  
4260         lock_flocks();
4261 @@ -1002,7 +1033,8 @@ static int __posix_lock_file(struct inod
4262  int posix_lock_file(struct file *filp, struct file_lock *fl,
4263                         struct file_lock *conflock)
4264  {
4265 -       return __posix_lock_file(file_inode(filp), fl, conflock);
4266 +       return __posix_lock_file(file_inode(filp),
4267 +               fl, conflock, filp->f_xid);
4268  }
4269  EXPORT_SYMBOL(posix_lock_file);
4270  
4271 @@ -1092,7 +1124,7 @@ int locks_mandatory_area(int read_write,
4272         fl.fl_end = offset + count - 1;
4273  
4274         for (;;) {
4275 -               error = __posix_lock_file(inode, &fl, NULL);
4276 +               error = __posix_lock_file(inode, &fl, NULL, filp->f_xid);
4277                 if (error != FILE_LOCK_DEFERRED)
4278                         break;
4279                 error = wait_event_interruptible(fl.fl_wait, !fl.fl_next);
4280 @@ -1397,6 +1429,7 @@ int generic_add_lease(struct file *filp,
4281                 goto out;
4282  
4283         locks_insert_lock(before, lease);
4284 +       vx_locks_inc(lease);
4285         return 0;
4286  
4287  out:
4288 @@ -1836,6 +1869,11 @@ int fcntl_setlk(unsigned int fd, struct
4289         if (file_lock == NULL)
4290                 return -ENOLCK;
4291  
4292 +       vxd_assert(filp->f_xid == vx_current_xid(),
4293 +               "f_xid(%d) == current(%d)", filp->f_xid, vx_current_xid());
4294 +       file_lock->fl_xid = filp->f_xid;
4295 +       vx_locks_inc(file_lock);
4296 +
4297         /*
4298          * This might block, so we do it before checking the inode.
4299          */
4300 @@ -1954,6 +1992,11 @@ int fcntl_setlk64(unsigned int fd, struc
4301         if (file_lock == NULL)
4302                 return -ENOLCK;
4303  
4304 +       vxd_assert(filp->f_xid == vx_current_xid(),
4305 +               "f_xid(%d) == current(%d)", filp->f_xid, vx_current_xid());
4306 +       file_lock->fl_xid = filp->f_xid;
4307 +       vx_locks_inc(file_lock);
4308 +
4309         /*
4310          * This might block, so we do it before checking the inode.
4311          */
4312 @@ -2219,8 +2262,11 @@ static int locks_show(struct seq_file *f
4313  
4314         lock_get_status(f, fl, *((loff_t *)f->private), "");
4315  
4316 -       list_for_each_entry(bfl, &fl->fl_block, fl_block)
4317 +       list_for_each_entry(bfl, &fl->fl_block, fl_block) {
4318 +               if (!vx_check(fl->fl_xid, VS_WATCH_P | VS_IDENT))
4319 +                       continue;
4320                 lock_get_status(f, bfl, *((loff_t *)f->private), " ->");
4321 +       }
4322  
4323         return 0;
4324  }
4325 diff -NurpP --minimal linux-3.9.4/fs/mount.h linux-3.9.4-vs2.3.6.2/fs/mount.h
4326 --- linux-3.9.4/fs/mount.h      2013-02-19 13:58:48.000000000 +0000
4327 +++ linux-3.9.4-vs2.3.6.2/fs/mount.h    2013-05-31 14:47:11.000000000 +0000
4328 @@ -49,6 +49,7 @@ struct mount {
4329         int mnt_expiry_mark;            /* true if marked for expiry */
4330         int mnt_pinned;
4331         int mnt_ghosts;
4332 +       tag_t mnt_tag;                  /* tagging used for vfsmount */
4333  };
4334  
4335  #define MNT_NS_INTERNAL ERR_PTR(-EINVAL) /* distinct from any mnt_namespace */
4336 diff -NurpP --minimal linux-3.9.4/fs/namei.c linux-3.9.4-vs2.3.6.2/fs/namei.c
4337 --- linux-3.9.4/fs/namei.c      2013-05-31 14:22:27.000000000 +0000
4338 +++ linux-3.9.4-vs2.3.6.2/fs/namei.c    2013-06-01 09:00:16.000000000 +0000
4339 @@ -34,6 +34,14 @@
4340  #include <linux/device_cgroup.h>
4341  #include <linux/fs_struct.h>
4342  #include <linux/posix_acl.h>
4343 +#include <linux/proc_fs.h>
4344 +#include <linux/vserver/inode.h>
4345 +#include <linux/vs_base.h>
4346 +#include <linux/vs_tag.h>
4347 +#include <linux/vs_cowbl.h>
4348 +#include <linux/vs_device.h>
4349 +#include <linux/vs_context.h>
4350 +#include <linux/pid_namespace.h>
4351  #include <asm/uaccess.h>
4352  
4353  #include "internal.h"
4354 @@ -266,6 +274,89 @@ static int check_acl(struct inode *inode
4355         return -EAGAIN;
4356  }
4357  
4358 +static inline int dx_barrier(const struct inode *inode)
4359 +{
4360 +       if (IS_BARRIER(inode) && !vx_check(0, VS_ADMIN | VS_WATCH)) {
4361 +               vxwprintk_task(1, "did hit the barrier.");
4362 +               return 1;
4363 +       }
4364 +       return 0;
4365 +}
4366 +
4367 +static int __dx_permission(const struct inode *inode, int mask)
4368 +{
4369 +       if (dx_barrier(inode))
4370 +               return -EACCES;
4371 +
4372 +       if (inode->i_sb->s_magic == DEVPTS_SUPER_MAGIC) {
4373 +               /* devpts is xid tagged */
4374 +               if (S_ISDIR(inode->i_mode) ||
4375 +                   vx_check((xid_t)i_tag_read(inode), VS_IDENT | VS_WATCH_P))
4376 +                       return 0;
4377 +
4378 +               /* just pretend we didn't find anything */
4379 +               return -ENOENT;
4380 +       }
4381 +       else if (inode->i_sb->s_magic == PROC_SUPER_MAGIC) {
4382 +               struct proc_dir_entry *de = PDE(inode);
4383 +
4384 +               if (de && !vx_hide_check(0, de->vx_flags))
4385 +                       goto out;
4386 +
4387 +               if ((mask & (MAY_WRITE | MAY_APPEND))) {
4388 +                       struct pid *pid;
4389 +                       struct task_struct *tsk;
4390 +
4391 +                       if (vx_check(0, VS_ADMIN | VS_WATCH_P) ||
4392 +                           vx_flags(VXF_STATE_SETUP, 0))
4393 +                               return 0;
4394 +
4395 +                       pid = PROC_I(inode)->pid;
4396 +                       if (!pid)
4397 +                               goto out;
4398 +
4399 +                       rcu_read_lock();
4400 +                       tsk = pid_task(pid, PIDTYPE_PID);
4401 +                       vxdprintk(VXD_CBIT(tag, 0), "accessing %p[#%u]",
4402 +                                 tsk, (tsk ? vx_task_xid(tsk) : 0));
4403 +                       if (tsk &&
4404 +                               vx_check(vx_task_xid(tsk), VS_IDENT | VS_WATCH_P)) {
4405 +                               rcu_read_unlock();
4406 +                               return 0;
4407 +                       }
4408 +                       rcu_read_unlock();
4409 +               }
4410 +               else {
4411 +                       /* FIXME: Should we block some entries here? */
4412 +                       return 0;
4413 +               }
4414 +       }
4415 +       else {
4416 +               if (dx_notagcheck(inode->i_sb) ||
4417 +                   dx_check((xid_t)i_tag_read(inode),
4418 +                       DX_HOSTID | DX_ADMIN | DX_WATCH | DX_IDENT))
4419 +                       return 0;
4420 +       }
4421 +
4422 +out:
4423 +       return -EACCES;
4424 +}
4425 +
4426 +int dx_permission(const struct inode *inode, int mask)
4427 +{
4428 +       int ret = __dx_permission(inode, mask);
4429 +       if (unlikely(ret)) {
4430 +#ifndef        CONFIG_VSERVER_WARN_DEVPTS
4431 +               if (inode->i_sb->s_magic != DEVPTS_SUPER_MAGIC)
4432 +#endif
4433 +                   vxwprintk_task(1,
4434 +                       "denied [0x%x] access to inode %s:%p[#%d,%lu]",
4435 +                       mask, inode->i_sb->s_id, inode,
4436 +                       i_tag_read(inode), inode->i_ino);
4437 +       }
4438 +       return ret;
4439 +}
4440 +
4441  /*
4442   * This does the basic permission checking
4443   */
4444 @@ -388,10 +479,14 @@ int __inode_permission(struct inode *ino
4445                 /*
4446                  * Nobody gets write access to an immutable file.
4447                  */
4448 -               if (IS_IMMUTABLE(inode))
4449 +               if (IS_IMMUTABLE(inode) && !IS_COW(inode))
4450                         return -EACCES;
4451         }
4452  
4453 +       retval = dx_permission(inode, mask);
4454 +       if (retval)
4455 +               return retval;
4456 +
4457         retval = do_inode_permission(inode, mask);
4458         if (retval)
4459                 return retval;
4460 @@ -1238,7 +1333,8 @@ static void follow_dotdot(struct nameida
4461  
4462                 if (nd->path.dentry == nd->root.dentry &&
4463                     nd->path.mnt == nd->root.mnt) {
4464 -                       break;
4465 +                       /* for sane '/' avoid follow_mount() */
4466 +                       return;
4467                 }
4468                 if (nd->path.dentry != nd->path.mnt->mnt_root) {
4469                         /* rare case of legitimate dget_parent()... */
4470 @@ -1383,6 +1479,9 @@ static int lookup_fast(struct nameidata
4471                                 goto unlazy;
4472                         }
4473                 }
4474 +
4475 +               /* FIXME: check dx permission */
4476 +
4477                 path->mnt = mnt;
4478                 path->dentry = dentry;
4479                 if (unlikely(!__follow_mount_rcu(nd, path, inode)))
4480 @@ -1413,6 +1512,8 @@ unlazy:
4481                 }
4482         }
4483  
4484 +       /* FIXME: check dx permission */
4485 +
4486         path->mnt = mnt;
4487         path->dentry = dentry;
4488         err = follow_managed(path, nd->flags);
4489 @@ -2237,7 +2338,7 @@ static int may_delete(struct inode *dir,
4490         if (IS_APPEND(dir))
4491                 return -EPERM;
4492         if (check_sticky(dir, victim->d_inode)||IS_APPEND(victim->d_inode)||
4493 -           IS_IMMUTABLE(victim->d_inode) || IS_SWAPFILE(victim->d_inode))
4494 +               IS_IXORUNLINK(victim->d_inode) || IS_SWAPFILE(victim->d_inode))
4495                 return -EPERM;
4496         if (isdir) {
4497                 if (!S_ISDIR(victim->d_inode->i_mode))
4498 @@ -2316,19 +2417,25 @@ int vfs_create(struct inode *dir, struct
4499                 bool want_excl)
4500  {
4501         int error = may_create(dir, dentry);
4502 -       if (error)
4503 +       if (error) {
4504 +               vxdprintk(VXD_CBIT(misc, 3), "may_create failed with %d", error);
4505                 return error;
4506 +       }
4507  
4508         if (!dir->i_op->create)
4509                 return -EACCES; /* shouldn't it be ENOSYS? */
4510         mode &= S_IALLUGO;
4511         mode |= S_IFREG;
4512         error = security_inode_create(dir, dentry, mode);
4513 -       if (error)
4514 +       if (error) {
4515 +               vxdprintk(VXD_CBIT(misc, 3), "security_inode_create failed with %d", error);
4516                 return error;
4517 +       }
4518         error = dir->i_op->create(dir, dentry, mode, want_excl);
4519         if (!error)
4520                 fsnotify_create(dir, dentry);
4521 +       else
4522 +               vxdprintk(VXD_CBIT(misc, 3), "i_op->create failed with %d", error);
4523         return error;
4524  }
4525  
4526 @@ -2363,6 +2470,15 @@ static int may_open(struct path *path, i
4527                 break;
4528         }
4529  
4530 +#ifdef CONFIG_VSERVER_COWBL
4531 +       if (IS_COW(inode) &&
4532 +               ((flag & O_ACCMODE) != O_RDONLY)) {
4533 +               if (IS_COW_LINK(inode))
4534 +                       return -EMLINK;
4535 +               inode->i_flags &= ~(S_IXUNLINK|S_IMMUTABLE);
4536 +               mark_inode_dirty(inode);
4537 +       }
4538 +#endif
4539         error = inode_permission(inode, acc_mode);
4540         if (error)
4541                 return error;
4542 @@ -2865,6 +2981,16 @@ finish_open:
4543         }
4544  finish_open_created:
4545         error = may_open(&nd->path, acc_mode, open_flag);
4546 +#ifdef CONFIG_VSERVER_COWBL
4547 +       if (error == -EMLINK) {
4548 +               struct dentry *dentry;
4549 +               dentry = cow_break_link(name->name);
4550 +               if (IS_ERR(dentry))
4551 +                       error = PTR_ERR(dentry);
4552 +               else
4553 +                       dput(dentry);
4554 +       }
4555 +#endif
4556         if (error)
4557                 goto out;
4558         file->f_path.mnt = nd->path.mnt;
4559 @@ -2929,6 +3055,7 @@ static struct file *path_openat(int dfd,
4560         int opened = 0;
4561         int error;
4562  
4563 +restart:
4564         file = get_empty_filp();
4565         if (IS_ERR(file))
4566                 return file;
4567 @@ -2965,6 +3092,16 @@ static struct file *path_openat(int dfd,
4568                 error = do_last(nd, &path, file, op, &opened, pathname);
4569                 put_link(nd, &link, cookie);
4570         }
4571 +
4572 +#ifdef CONFIG_VSERVER_COWBL
4573 +       if (error == -EMLINK) {
4574 +               if (nd->root.mnt && !(nd->flags & LOOKUP_ROOT))
4575 +                       path_put(&nd->root);
4576 +               if (base)
4577 +                       fput(base);
4578 +               goto restart;
4579 +       }
4580 +#endif
4581  out:
4582         if (nd->root.mnt && !(nd->flags & LOOKUP_ROOT))
4583                 path_put(&nd->root);
4584 @@ -3079,6 +3216,11 @@ struct dentry *kern_path_create(int dfd,
4585                 goto fail;
4586         }
4587         *path = nd.path;
4588 +       vxdprintk(VXD_CBIT(misc, 3), "kern_path_create path.dentry = %p (%.*s), dentry = %p (%.*s), d_inode = %p",
4589 +               path->dentry, path->dentry->d_name.len,
4590 +               path->dentry->d_name.name, dentry,
4591 +               dentry->d_name.len, dentry->d_name.name,
4592 +               path->dentry->d_inode);
4593         return dentry;
4594  fail:
4595         dput(dentry);
4596 @@ -3573,7 +3715,7 @@ int vfs_link(struct dentry *old_dentry,
4597         /*
4598          * A link to an append-only or immutable file cannot be created.
4599          */
4600 -       if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
4601 +       if (IS_APPEND(inode) || IS_IXORUNLINK(inode))
4602                 return -EPERM;
4603         if (!dir->i_op->link)
4604                 return -EPERM;
4605 @@ -3976,6 +4118,286 @@ int vfs_follow_link(struct nameidata *nd
4606         return __vfs_follow_link(nd, link);
4607  }
4608  
4609 +
4610 +#ifdef CONFIG_VSERVER_COWBL
4611 +
4612 +static inline
4613 +long do_cow_splice(struct file *in, struct file *out, size_t len)
4614 +{
4615 +       loff_t ppos = 0;
4616 +
4617 +       return do_splice_direct(in, &ppos, out, len, 0);
4618 +}
4619 +
4620 +struct dentry *cow_break_link(const char *pathname)
4621 +{
4622 +       int ret, mode, pathlen, redo = 0, drop = 1;
4623 +       struct nameidata old_nd, dir_nd;
4624 +       struct path dir_path, *old_path, *new_path;
4625 +       struct dentry *dir, *old_dentry, *new_dentry = NULL;
4626 +       struct file *old_file;
4627 +       struct file *new_file;
4628 +       char *to, *path, pad='\251';
4629 +       loff_t size;
4630 +
4631 +       vxdprintk(VXD_CBIT(misc, 1),
4632 +               "cow_break_link(" VS_Q("%s") ")", pathname);
4633 +
4634 +       path = kmalloc(PATH_MAX, GFP_KERNEL);
4635 +       ret = -ENOMEM;
4636 +       if (!path)
4637 +               goto out;
4638 +
4639 +       /* old_nd.path will have refs to dentry and mnt */
4640 +       ret = do_path_lookup(AT_FDCWD, pathname, LOOKUP_FOLLOW, &old_nd);
4641 +       vxdprintk(VXD_CBIT(misc, 2),
4642 +               "do_path_lookup(old): %d", ret);
4643 +       if (ret < 0)
4644 +               goto out_free_path;
4645 +
4646 +       /* dentry/mnt refs handed over to old_path */
4647 +       old_path = &old_nd.path;
4648 +       /* no explicit reference for old_dentry here */
4649 +       old_dentry = old_path->dentry;
4650 +
4651 +       mode = old_dentry->d_inode->i_mode;
4652 +       to = d_path(old_path, path, PATH_MAX-2);
4653 +       pathlen = strlen(to);
4654 +       vxdprintk(VXD_CBIT(misc, 2),
4655 +               "old path " VS_Q("%s") " [%p:" VS_Q("%.*s") ":%d]", to,
4656 +               old_dentry,
4657 +               old_dentry->d_name.len, old_dentry->d_name.name,
4658 +               old_dentry->d_name.len);
4659 +
4660 +       to[pathlen + 1] = 0;
4661 +retry:
4662 +       new_dentry = NULL;
4663 +       to[pathlen] = pad--;
4664 +       ret = -ELOOP;
4665 +       if (pad <= '\240')
4666 +               goto out_rel_old;
4667 +
4668 +       vxdprintk(VXD_CBIT(misc, 1), "temp copy " VS_Q("%s"), to);
4669 +
4670 +       /* dir_nd.path will have refs to dentry and mnt */
4671 +       ret = do_path_lookup(AT_FDCWD, to,
4672 +               LOOKUP_PARENT | LOOKUP_OPEN | LOOKUP_CREATE, &dir_nd);
4673 +       vxdprintk(VXD_CBIT(misc, 2), "do_path_lookup(new): %d", ret);
4674 +       if (ret < 0)
4675 +               goto retry;
4676 +
4677 +       /* this puppy downs the dir inode mutex if successful.
4678 +          dir_path will hold refs to dentry and mnt and
4679 +          we'll have write access to the mnt */
4680 +       new_dentry = kern_path_create(AT_FDCWD, to, &dir_path, 0);
4681 +       if (!new_dentry || IS_ERR(new_dentry)) {
4682 +               path_put(&dir_nd.path);
4683 +               vxdprintk(VXD_CBIT(misc, 2),
4684 +                       "kern_path_create(new) failed with %ld",
4685 +                       PTR_ERR(new_dentry));
4686 +               goto retry;
4687 +       }
4688 +       vxdprintk(VXD_CBIT(misc, 2),
4689 +               "kern_path_create(new): %p [" VS_Q("%.*s") ":%d]",
4690 +               new_dentry,
4691 +               new_dentry->d_name.len, new_dentry->d_name.name,
4692 +               new_dentry->d_name.len);
4693 +
4694 +       /* take a reference on new_dentry */
4695 +       dget(new_dentry);
4696 +
4697 +       /* dentry/mnt refs handed over to new_path */
4698 +       new_path = &dir_path;
4699 +
4700 +       /* dentry for old/new dir */
4701 +       dir = dir_nd.path.dentry;
4702 +
4703 +       /* give up reference on dir */
4704 +       dput(new_path->dentry);
4705 +
4706 +       /* new_dentry already has a reference */
4707 +       new_path->dentry = new_dentry;
4708 +
4709 +       ret = vfs_create(dir->d_inode, new_dentry, mode, 1);
4710 +       vxdprintk(VXD_CBIT(misc, 2),
4711 +               "vfs_create(new): %d", ret);
4712 +       if (ret == -EEXIST) {
4713 +               path_put(&dir_nd.path);
4714 +               mutex_unlock(&dir->d_inode->i_mutex);
4715 +               mnt_drop_write(new_path->mnt);
4716 +               path_put(new_path);
4717 +               new_dentry = NULL;
4718 +               goto retry;
4719 +       }
4720 +       else if (ret < 0)
4721 +               goto out_unlock_new;
4722 +
4723 +       /* drop out early, ret passes ENOENT */
4724 +       ret = -ENOENT;
4725 +       if ((redo = d_unhashed(old_dentry)))
4726 +               goto out_unlock_new;
4727 +
4728 +       /* doesn't change refs for old_path */
4729 +       old_file = dentry_open(old_path, O_RDONLY, current_cred());
4730 +       vxdprintk(VXD_CBIT(misc, 2),
4731 +               "dentry_open(old): %p", old_file);
4732 +       if (IS_ERR(old_file)) {
4733 +               ret = PTR_ERR(old_file);
4734 +               goto out_unlock_new;
4735 +       }
4736 +
4737 +       /* doesn't change refs for new_path */
4738 +       new_file = dentry_open(new_path, O_WRONLY, current_cred());
4739 +       vxdprintk(VXD_CBIT(misc, 2),
4740 +               "dentry_open(new): %p", new_file);
4741 +       if (IS_ERR(new_file)) {
4742 +               ret = PTR_ERR(new_file);
4743 +               goto out_fput_old;
4744 +       }
4745 +
4746 +       /* unlock the inode mutex from kern_path_create() */
4747 +       mutex_unlock(&dir->d_inode->i_mutex);
4748 +
4749 +       /* drop write access to mnt */
4750 +       mnt_drop_write(new_path->mnt);
4751 +
4752 +       drop = 0;
4753 +
4754 +       size = i_size_read(old_file->f_dentry->d_inode);
4755 +       ret = do_cow_splice(old_file, new_file, size);
4756 +       vxdprintk(VXD_CBIT(misc, 2), "do_splice_direct: %d", ret);
4757 +       if (ret < 0) {
4758 +               goto out_fput_both;
4759 +       } else if (ret < size) {
4760 +               ret = -ENOSPC;
4761 +               goto out_fput_both;
4762 +       } else {
4763 +               struct inode *old_inode = old_dentry->d_inode;
4764 +               struct inode *new_inode = new_dentry->d_inode;
4765 +               struct iattr attr = {
4766 +                       .ia_uid = old_inode->i_uid,
4767 +                       .ia_gid = old_inode->i_gid,
4768 +                       .ia_valid = ATTR_UID | ATTR_GID
4769 +                       };
4770 +
4771 +               setattr_copy(new_inode, &attr);
4772 +               mark_inode_dirty(new_inode);
4773 +       }
4774 +
4775 +       /* lock rename mutex */
4776 +       mutex_lock(&old_dentry->d_inode->i_sb->s_vfs_rename_mutex);
4777 +
4778 +       /* drop out late */
4779 +       ret = -ENOENT;
4780 +       if ((redo = d_unhashed(old_dentry)))
4781 +               goto out_unlock;
4782 +
4783 +       vxdprintk(VXD_CBIT(misc, 2),
4784 +               "vfs_rename: [" VS_Q("%*s") ":%d] -> [" VS_Q("%*s") ":%d]",
4785 +               new_dentry->d_name.len, new_dentry->d_name.name,
4786 +               new_dentry->d_name.len,
4787 +               old_dentry->d_name.len, old_dentry->d_name.name,
4788 +               old_dentry->d_name.len);
4789 +       ret = vfs_rename(dir_nd.path.dentry->d_inode, new_dentry,
4790 +               old_dentry->d_parent->d_inode, old_dentry);
4791 +       vxdprintk(VXD_CBIT(misc, 2), "vfs_rename: %d", ret);
4792 +
4793 +out_unlock:
4794 +       mutex_unlock(&old_dentry->d_inode->i_sb->s_vfs_rename_mutex);
4795 +
4796 +out_fput_both:
4797 +       vxdprintk(VXD_CBIT(misc, 3),
4798 +               "fput(new_file=%p[#%ld])", new_file,
4799 +               atomic_long_read(&new_file->f_count));
4800 +       fput(new_file);
4801 +
4802 +out_fput_old:
4803 +       vxdprintk(VXD_CBIT(misc, 3),
4804 +               "fput(old_file=%p[#%ld])", old_file,
4805 +               atomic_long_read(&old_file->f_count));
4806 +       fput(old_file);
4807 +
4808 +out_unlock_new:
4809 +       /* drop references from dir_nd.path */
4810 +       path_put(&dir_nd.path);
4811 +
4812 +       if (drop) {
4813 +               /* unlock the inode mutex from kern_path_create() */
4814 +               mutex_unlock(&dir->d_inode->i_mutex);
4815 +
4816 +               /* drop write access to mnt */
4817 +               mnt_drop_write(new_path->mnt);
4818 +       }
4819 +
4820 +       if (!ret)
4821 +               goto out_redo;
4822 +
4823 +       /* error path cleanup */
4824 +       vfs_unlink(dir->d_inode, new_dentry);
4825 +
4826 +out_redo:
4827 +       if (!redo)
4828 +               goto out_rel_both;
4829 +
4830 +       /* lookup dentry once again
4831 +          old_nd.path will be freed as old_path in out_rel_old */
4832 +       ret = do_path_lookup(AT_FDCWD, pathname, LOOKUP_FOLLOW, &old_nd);
4833 +       if (ret)
4834 +               goto out_rel_both;
4835 +
4836 +       /* drop reference on new_dentry */
4837 +       dput(new_dentry);
4838 +       new_dentry = old_path->dentry;
4839 +       dget(new_dentry);
4840 +       vxdprintk(VXD_CBIT(misc, 2),
4841 +               "do_path_lookup(redo): %p [" VS_Q("%.*s") ":%d]",
4842 +               new_dentry,
4843 +               new_dentry->d_name.len, new_dentry->d_name.name,
4844 +               new_dentry->d_name.len);
4845 +
4846 +out_rel_both:
4847 +       if (new_path)
4848 +               path_put(new_path);
4849 +out_rel_old:
4850 +       path_put(old_path);
4851 +out_free_path:
4852 +       kfree(path);
4853 +out:
4854 +       if (ret) {
4855 +               dput(new_dentry);
4856 +               new_dentry = ERR_PTR(ret);
4857 +       }
4858 +       vxdprintk(VXD_CBIT(misc, 3),
4859 +               "cow_break_link returning with %p", new_dentry);
4860 +       return new_dentry;
4861 +}
4862 +
4863 +#endif
4864 +
4865 +int    vx_info_mnt_namespace(struct mnt_namespace *ns, char *buffer)
4866 +{
4867 +       struct path path;
4868 +       struct vfsmount *vmnt;
4869 +       char *pstr, *root;
4870 +       int length = 0;
4871 +
4872 +       pstr = kmalloc(PATH_MAX, GFP_KERNEL);
4873 +       if (!pstr)
4874 +               return 0;
4875 +
4876 +       vmnt = &ns->root->mnt;
4877 +       path.mnt = vmnt;
4878 +       path.dentry = vmnt->mnt_root;
4879 +       root = d_path(&path, pstr, PATH_MAX - 2);
4880 +       length = sprintf(buffer + length,
4881 +               "Namespace:\t%p [#%u]\n"
4882 +               "RootPath:\t%s\n",
4883 +               ns, atomic_read(&ns->count),
4884 +               root);
4885 +       kfree(pstr);
4886 +       return length;
4887 +}
4888 +
4889  /* get the link contents into pagecache */
4890  static char *page_getlink(struct dentry * dentry, struct page **ppage)
4891  {
4892 @@ -4099,3 +4521,4 @@ EXPORT_SYMBOL(vfs_symlink);
4893  EXPORT_SYMBOL(vfs_unlink);
4894  EXPORT_SYMBOL(dentry_unhash);
4895  EXPORT_SYMBOL(generic_readlink);
4896 +EXPORT_SYMBOL(vx_info_mnt_namespace);
4897 diff -NurpP --minimal linux-3.9.4/fs/namespace.c linux-3.9.4-vs2.3.6.2/fs/namespace.c
4898 --- linux-3.9.4/fs/namespace.c  2013-05-31 14:22:27.000000000 +0000
4899 +++ linux-3.9.4-vs2.3.6.2/fs/namespace.c        2013-05-31 18:47:18.000000000 +0000
4900 @@ -22,6 +22,11 @@
4901  #include <linux/fsnotify.h>    /* fsnotify_vfsmount_delete */
4902  #include <linux/uaccess.h>
4903  #include <linux/proc_fs.h>
4904 +#include <linux/vs_base.h>
4905 +#include <linux/vs_context.h>
4906 +#include <linux/vs_tag.h>
4907 +#include <linux/vserver/space.h>
4908 +#include <linux/vserver/global.h>
4909  #include "pnode.h"
4910  #include "internal.h"
4911  
4912 @@ -751,6 +756,10 @@ vfs_kern_mount(struct file_system_type *
4913         if (!type)
4914                 return ERR_PTR(-ENODEV);
4915  
4916 +       if ((type->fs_flags & FS_BINARY_MOUNTDATA) &&
4917 +               !vx_capable(CAP_SYS_ADMIN, VXC_BINARY_MOUNT))
4918 +               return ERR_PTR(-EPERM);
4919 +
4920         mnt = alloc_vfsmnt(name);
4921         if (!mnt)
4922                 return ERR_PTR(-ENOMEM);
4923 @@ -807,6 +816,7 @@ static struct mount *clone_mnt(struct mo
4924         mnt->mnt.mnt_root = dget(root);
4925         mnt->mnt_mountpoint = mnt->mnt.mnt_root;
4926         mnt->mnt_parent = mnt;
4927 +               mnt->mnt_tag = old->mnt_tag;
4928         br_write_lock(&vfsmount_lock);
4929         list_add_tail(&mnt->mnt_instance, &sb->s_mounts);
4930         br_write_unlock(&vfsmount_lock);
4931 @@ -1639,6 +1649,7 @@ static int do_change_type(struct path *p
4932                 if (err)
4933                         goto out_unlock;
4934         }
4935 +       // mnt->mnt_flags = mnt_flags;
4936  
4937         br_write_lock(&vfsmount_lock);
4938         for (m = mnt; m; m = (recurse ? next_mnt(m, mnt) : NULL))
4939 @@ -1654,12 +1665,14 @@ static int do_change_type(struct path *p
4940   * do loopback mount.
4941   */
4942  static int do_loopback(struct path *path, const char *old_name,
4943 -                               int recurse)
4944 +       tag_t tag, unsigned long flags, int mnt_flags)
4945  {
4946         LIST_HEAD(umount_list);
4947         struct path old_path;
4948         struct mount *mnt = NULL, *old;
4949 +       int recurse = flags & MS_REC;
4950         int err;
4951 +
4952         if (!old_name || !*old_name)
4953                 return -EINVAL;
4954         err = kern_path(old_name, LOOKUP_FOLLOW|LOOKUP_AUTOMOUNT, &old_path);
4955 @@ -1733,7 +1746,7 @@ static int change_mount_flags(struct vfs
4956   * on it - tough luck.
4957   */
4958  static int do_remount(struct path *path, int flags, int mnt_flags,
4959 -                     void *data)
4960 +       void *data, xid_t xid)
4961  {
4962         int err;
4963         struct super_block *sb = path->mnt->mnt_sb;
4964 @@ -2046,7 +2059,6 @@ void mark_mounts_for_expiry(struct list_
4965         }
4966         br_write_unlock(&vfsmount_lock);
4967         up_write(&namespace_sem);
4968 -
4969         release_mounts(&umounts);
4970  }
4971  
4972 @@ -2218,6 +2230,7 @@ long do_mount(const char *dev_name, cons
4973         struct path path;
4974         int retval = 0;
4975         int mnt_flags = 0;
4976 +       tag_t tag = 0;
4977  
4978         /* Discard magic */
4979         if ((flags & MS_MGC_MSK) == MS_MGC_VAL)
4980 @@ -2247,6 +2260,12 @@ long do_mount(const char *dev_name, cons
4981         if (!(flags & MS_NOATIME))
4982                 mnt_flags |= MNT_RELATIME;
4983  
4984 +       if (dx_parse_tag(data_page, &tag, 1, &mnt_flags, &flags)) {
4985 +               /* FIXME: bind and re-mounts get the tag flag? */
4986 +               if (flags & (MS_BIND|MS_REMOUNT))
4987 +                       flags |= MS_TAGID;
4988 +       }
4989 +
4990         /* Separate the per-mountpoint flags */
4991         if (flags & MS_NOSUID)
4992                 mnt_flags |= MNT_NOSUID;
4993 @@ -2263,15 +2282,17 @@ long do_mount(const char *dev_name, cons
4994         if (flags & MS_RDONLY)
4995                 mnt_flags |= MNT_READONLY;
4996  
4997 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_DEV_MOUNT))
4998 +               mnt_flags |= MNT_NODEV;
4999         flags &= ~(MS_NOSUID | MS_NOEXEC | MS_NODEV | MS_ACTIVE | MS_BORN |
5000                    MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
5001                    MS_STRICTATIME);
5002  
5003         if (flags & MS_REMOUNT)
5004                 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
5005 -                                   data_page);
5006 +                                   data_page, tag);
5007         else if (flags & MS_BIND)
5008 -               retval = do_loopback(&path, dev_name, flags & MS_REC);
5009 +               retval = do_loopback(&path, dev_name, tag, flags, mnt_flags);
5010         else if (flags & (MS_SHARED | MS_PRIVATE | MS_SLAVE | MS_UNBINDABLE))
5011                 retval = do_change_type(&path, flags);
5012         else if (flags & MS_MOVE)
5013 @@ -2380,6 +2401,7 @@ static struct mnt_namespace *dup_mnt_ns(
5014                 q = next_mnt(q, new);
5015         }
5016         up_write(&namespace_sem);
5017 +       atomic_inc(&vs_global_mnt_ns);
5018  
5019         if (rootmnt)
5020                 mntput(rootmnt);
5021 @@ -2575,9 +2597,10 @@ SYSCALL_DEFINE2(pivot_root, const char _
5022         error = -EINVAL;
5023         new_mnt = real_mount(new.mnt);
5024         root_mnt = real_mount(root.mnt);
5025 -       if (IS_MNT_SHARED(real_mount(old.mnt)) ||
5026 +       if ((IS_MNT_SHARED(real_mount(old.mnt)) ||
5027                 IS_MNT_SHARED(new_mnt->mnt_parent) ||
5028 -               IS_MNT_SHARED(root_mnt->mnt_parent))
5029 +               IS_MNT_SHARED(root_mnt->mnt_parent)) &&
5030 +               !vx_flags(VXF_STATE_SETUP, 0))
5031                 goto out4;
5032         if (!check_mnt(root_mnt) || !check_mnt(new_mnt))
5033                 goto out4;
5034 @@ -2703,6 +2726,7 @@ void put_mnt_ns(struct mnt_namespace *ns
5035         br_write_unlock(&vfsmount_lock);
5036         up_write(&namespace_sem);
5037         release_mounts(&umount_list);
5038 +       atomic_dec(&vs_global_mnt_ns);
5039         free_mnt_ns(ns);
5040  }
5041  
5042 diff -NurpP --minimal linux-3.9.4/fs/nfs/client.c linux-3.9.4-vs2.3.6.2/fs/nfs/client.c
5043 --- linux-3.9.4/fs/nfs/client.c 2013-05-31 13:45:24.000000000 +0000
5044 +++ linux-3.9.4-vs2.3.6.2/fs/nfs/client.c       2013-05-31 14:47:11.000000000 +0000
5045 @@ -682,6 +682,9 @@ int nfs_init_server_rpcclient(struct nfs
5046         if (server->flags & NFS_MOUNT_SOFT)
5047                 server->client->cl_softrtry = 1;
5048  
5049 +       server->client->cl_tag = 0;
5050 +       if (server->flags & NFS_MOUNT_TAGGED)
5051 +               server->client->cl_tag = 1;
5052         return 0;
5053  }
5054  EXPORT_SYMBOL_GPL(nfs_init_server_rpcclient);
5055 @@ -861,6 +864,10 @@ static void nfs_server_set_fsinfo(struct
5056                 server->acdirmin = server->acdirmax = 0;
5057         }
5058  
5059 +       /* FIXME: needs fsinfo
5060 +       if (server->flags & NFS_MOUNT_TAGGED)
5061 +               sb->s_flags |= MS_TAGGED;       */
5062 +
5063         server->maxfilesize = fsinfo->maxfilesize;
5064  
5065         server->time_delta = fsinfo->time_delta;
5066 diff -NurpP --minimal linux-3.9.4/fs/nfs/dir.c linux-3.9.4-vs2.3.6.2/fs/nfs/dir.c
5067 --- linux-3.9.4/fs/nfs/dir.c    2013-05-31 13:45:24.000000000 +0000
5068 +++ linux-3.9.4-vs2.3.6.2/fs/nfs/dir.c  2013-05-31 14:47:11.000000000 +0000
5069 @@ -36,6 +36,7 @@
5070  #include <linux/sched.h>
5071  #include <linux/kmemleak.h>
5072  #include <linux/xattr.h>
5073 +#include <linux/vs_tag.h>
5074  
5075  #include "delegation.h"
5076  #include "iostat.h"
5077 @@ -1300,6 +1301,7 @@ struct dentry *nfs_lookup(struct inode *
5078         /* Success: notify readdir to use READDIRPLUS */
5079         nfs_advise_use_readdirplus(dir);
5080  
5081 +       dx_propagate_tag(nd, inode);
5082  no_entry:
5083         res = d_materialise_unique(dentry, inode);
5084         if (res != NULL) {
5085 diff -NurpP --minimal linux-3.9.4/fs/nfs/inode.c linux-3.9.4-vs2.3.6.2/fs/nfs/inode.c
5086 --- linux-3.9.4/fs/nfs/inode.c  2013-05-31 13:45:24.000000000 +0000
5087 +++ linux-3.9.4-vs2.3.6.2/fs/nfs/inode.c        2013-05-31 20:37:45.000000000 +0000
5088 @@ -39,6 +39,7 @@
5089  #include <linux/compat.h>
5090  #include <linux/freezer.h>
5091  #include <linux/crc32.h>
5092 +#include <linux/vs_tag.h>
5093  
5094  #include <asm/uaccess.h>
5095  
5096 @@ -290,6 +291,8 @@ nfs_fhget(struct super_block *sb, struct
5097         if (inode->i_state & I_NEW) {
5098                 struct nfs_inode *nfsi = NFS_I(inode);
5099                 unsigned long now = jiffies;
5100 +               uid_t uid;
5101 +               gid_t gid;
5102  
5103                 /* We set i_ino for the few things that still rely on it,
5104                  * such as stat(2) */
5105 @@ -334,8 +337,8 @@ nfs_fhget(struct super_block *sb, struct
5106                 inode->i_version = 0;
5107                 inode->i_size = 0;
5108                 clear_nlink(inode);
5109 -               inode->i_uid = make_kuid(&init_user_ns, -2);
5110 -               inode->i_gid = make_kgid(&init_user_ns, -2);
5111 +               uid = make_kuid(&init_user_ns, -2);
5112 +               gid = make_kgid(&init_user_ns, -2);
5113                 inode->i_blocks = 0;
5114                 memset(nfsi->cookieverf, 0, sizeof(nfsi->cookieverf));
5115                 nfsi->write_io = 0;
5116 @@ -369,11 +372,11 @@ nfs_fhget(struct super_block *sb, struct
5117                 else if (nfs_server_capable(inode, NFS_CAP_NLINK))
5118                         nfsi->cache_validity |= NFS_INO_INVALID_ATTR;
5119                 if (fattr->valid & NFS_ATTR_FATTR_OWNER)
5120 -                       inode->i_uid = fattr->uid;
5121 +                       uid = fattr->uid;
5122                 else if (nfs_server_capable(inode, NFS_CAP_OWNER))
5123                         nfsi->cache_validity |= NFS_INO_INVALID_ATTR;
5124                 if (fattr->valid & NFS_ATTR_FATTR_GROUP)
5125 -                       inode->i_gid = fattr->gid;
5126 +                       gid = fattr->gid;
5127                 else if (nfs_server_capable(inode, NFS_CAP_OWNER_GROUP))
5128                         nfsi->cache_validity |= NFS_INO_INVALID_ATTR;
5129                 if (fattr->valid & NFS_ATTR_FATTR_BLOCKS_USED)
5130 @@ -384,6 +387,11 @@ nfs_fhget(struct super_block *sb, struct
5131                          */
5132                         inode->i_blocks = nfs_calc_block_size(fattr->du.nfs3.used);
5133                 }
5134 +               inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
5135 +               inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
5136 +               inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid, 0);
5137 +                               /* maybe fattr->xid someday */
5138 +
5139                 nfsi->attrtimeo = NFS_MINATTRTIMEO(inode);
5140                 nfsi->attrtimeo_timestamp = now;
5141                 nfsi->access_cache = RB_ROOT;
5142 @@ -505,6 +513,8 @@ void nfs_setattr_update_inode(struct ino
5143                         inode->i_uid = attr->ia_uid;
5144                 if ((attr->ia_valid & ATTR_GID) != 0)
5145                         inode->i_gid = attr->ia_gid;
5146 +               if ((attr->ia_valid & ATTR_TAG) && IS_TAGGED(inode))
5147 +                       inode->i_tag = attr->ia_tag;
5148                 NFS_I(inode)->cache_validity |= NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL;
5149                 spin_unlock(&inode->i_lock);
5150         }
5151 @@ -980,6 +990,11 @@ static int nfs_check_inode_attributes(st
5152         struct nfs_inode *nfsi = NFS_I(inode);
5153         loff_t cur_size, new_isize;
5154         unsigned long invalid = 0;
5155 +       kuid_t kuid;
5156 +       kgid_t kgid;
5157 +       ktag_t ktag;
5158 +       uid_t uid;
5159 +       gid_t gid;
5160  
5161  
5162         if (nfs_have_delegated_attributes(inode))
5163 @@ -1005,13 +1020,21 @@ static int nfs_check_inode_attributes(st
5164                         invalid |= NFS_INO_INVALID_ATTR|NFS_INO_REVAL_PAGECACHE;
5165         }
5166  
5167 +       uid = from_kuid(&init_user_ns, fattr->uid);
5168 +       gid = from_kgid(&init_user_ns, fattr->gid);
5169 +
5170 +       kuid = make_kuid(&init_user_ns, INOTAG_UID(DX_TAG(inode), uid, gid));
5171 +       kgid = make_kgid(&init_user_ns, INOTAG_GID(DX_TAG(inode), uid, gid));
5172 +       ktag = make_ktag(&init_user_ns, INOTAG_TAG(DX_TAG(inode), uid, gid, 0));
5173 +
5174         /* Have any file permissions changed? */
5175         if ((fattr->valid & NFS_ATTR_FATTR_MODE) && (inode->i_mode & S_IALLUGO) != (fattr->mode & S_IALLUGO))
5176                 invalid |= NFS_INO_INVALID_ATTR | NFS_INO_INVALID_ACCESS | NFS_INO_INVALID_ACL;
5177 -       if ((fattr->valid & NFS_ATTR_FATTR_OWNER) && !uid_eq(inode->i_uid, fattr->uid))
5178 +       if ((fattr->valid & NFS_ATTR_FATTR_OWNER) && !uid_eq(inode->i_uid, kuid))
5179                 invalid |= NFS_INO_INVALID_ATTR | NFS_INO_INVALID_ACCESS | NFS_INO_INVALID_ACL;
5180 -       if ((fattr->valid & NFS_ATTR_FATTR_GROUP) && !gid_eq(inode->i_gid, fattr->gid))
5181 +       if ((fattr->valid & NFS_ATTR_FATTR_GROUP) && !gid_eq(inode->i_gid, kgid))
5182                 invalid |= NFS_INO_INVALID_ATTR | NFS_INO_INVALID_ACCESS | NFS_INO_INVALID_ACL;
5183 +               /* maybe check for tag too? */
5184  
5185         /* Has the link count changed? */
5186         if ((fattr->valid & NFS_ATTR_FATTR_NLINK) && inode->i_nlink != fattr->nlink)
5187 @@ -1317,6 +1340,9 @@ static int nfs_update_inode(struct inode
5188         unsigned long invalid = 0;
5189         unsigned long now = jiffies;
5190         unsigned long save_cache_validity;
5191 +       uid_t uid;
5192 +       gid_t gid;
5193 +       tag_t tag;
5194  
5195         dfprintk(VFS, "NFS: %s(%s/%ld fh_crc=0x%08x ct=%d info=0x%x)\n",
5196                         __func__, inode->i_sb->s_id, inode->i_ino,
5197 @@ -1418,6 +1444,9 @@ static int nfs_update_inode(struct inode
5198                                 | NFS_INO_REVAL_PAGECACHE
5199                                 | NFS_INO_REVAL_FORCED);
5200  
5201 +       uid = TAGINO_UID(DX_TAG(inode), inode->i_uid, inode->i_tag);
5202 +       gid = TAGINO_GID(DX_TAG(inode), inode->i_gid, inode->i_tag);
5203 +       tag = inode->i_tag;
5204  
5205         if (fattr->valid & NFS_ATTR_FATTR_ATIME)
5206                 memcpy(&inode->i_atime, &fattr->atime, sizeof(inode->i_atime));
5207 @@ -1460,6 +1489,10 @@ static int nfs_update_inode(struct inode
5208                                 | NFS_INO_INVALID_ACL
5209                                 | NFS_INO_REVAL_FORCED);
5210  
5211 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
5212 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
5213 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid, tag);
5214 +
5215         if (fattr->valid & NFS_ATTR_FATTR_NLINK) {
5216                 if (inode->i_nlink != fattr->nlink) {
5217                         invalid |= NFS_INO_INVALID_ATTR;
5218 diff -NurpP --minimal linux-3.9.4/fs/nfs/nfs3xdr.c linux-3.9.4-vs2.3.6.2/fs/nfs/nfs3xdr.c
5219 --- linux-3.9.4/fs/nfs/nfs3xdr.c        2013-05-31 13:45:24.000000000 +0000
5220 +++ linux-3.9.4-vs2.3.6.2/fs/nfs/nfs3xdr.c      2013-05-31 15:33:48.000000000 +0000
5221 @@ -20,6 +20,7 @@
5222  #include <linux/nfs3.h>
5223  #include <linux/nfs_fs.h>
5224  #include <linux/nfsacl.h>
5225 +#include <linux/vs_tag.h>
5226  #include "internal.h"
5227  
5228  #define NFSDBG_FACILITY                NFSDBG_XDR
5229 @@ -558,7 +559,8 @@ static __be32 *xdr_decode_nfstime3(__be3
5230   *             set_mtime       mtime;
5231   *     };
5232   */
5233 -static void encode_sattr3(struct xdr_stream *xdr, const struct iattr *attr)
5234 +static void encode_sattr3(struct xdr_stream *xdr,
5235 +       const struct iattr *attr, int tag)
5236  {
5237         u32 nbytes;
5238         __be32 *p;
5239 @@ -590,15 +592,19 @@ static void encode_sattr3(struct xdr_str
5240         } else
5241                 *p++ = xdr_zero;
5242  
5243 -       if (attr->ia_valid & ATTR_UID) {
5244 +       if (attr->ia_valid & ATTR_UID ||
5245 +               (tag && (attr->ia_valid & ATTR_TAG))) {
5246                 *p++ = xdr_one;
5247 -               *p++ = cpu_to_be32(from_kuid(&init_user_ns, attr->ia_uid));
5248 +               *p++ = cpu_to_be32(TAGINO_UID(tag,
5249 +                       from_kuid(&init_user_ns, attr->ia_uid), attr->ia_tag));
5250         } else
5251                 *p++ = xdr_zero;
5252  
5253 -       if (attr->ia_valid & ATTR_GID) {
5254 +       if (attr->ia_valid & ATTR_GID ||
5255 +               (tag && (attr->ia_valid & ATTR_TAG))) {
5256                 *p++ = xdr_one;
5257 -               *p++ = cpu_to_be32(from_kgid(&init_user_ns, attr->ia_gid));
5258 +               *p++ = cpu_to_be32(TAGINO_GID(tag,
5259 +                       from_kgid(&init_user_ns, attr->ia_gid), attr->ia_tag));
5260         } else
5261                 *p++ = xdr_zero;
5262  
5263 @@ -887,7 +893,7 @@ static void nfs3_xdr_enc_setattr3args(st
5264                                       const struct nfs3_sattrargs *args)
5265  {
5266         encode_nfs_fh3(xdr, args->fh);
5267 -       encode_sattr3(xdr, args->sattr);
5268 +       encode_sattr3(xdr, args->sattr, req->rq_task->tk_client->cl_tag);
5269         encode_sattrguard3(xdr, args);
5270  }
5271  
5272 @@ -1037,13 +1043,13 @@ static void nfs3_xdr_enc_write3args(stru
5273   *     };
5274   */
5275  static void encode_createhow3(struct xdr_stream *xdr,
5276 -                             const struct nfs3_createargs *args)
5277 +       const struct nfs3_createargs *args, int tag)
5278  {
5279         encode_uint32(xdr, args->createmode);
5280         switch (args->createmode) {
5281         case NFS3_CREATE_UNCHECKED:
5282         case NFS3_CREATE_GUARDED:
5283 -               encode_sattr3(xdr, args->sattr);
5284 +               encode_sattr3(xdr, args->sattr, tag);
5285                 break;
5286         case NFS3_CREATE_EXCLUSIVE:
5287                 encode_createverf3(xdr, args->verifier);
5288 @@ -1058,7 +1064,7 @@ static void nfs3_xdr_enc_create3args(str
5289                                      const struct nfs3_createargs *args)
5290  {
5291         encode_diropargs3(xdr, args->fh, args->name, args->len);
5292 -       encode_createhow3(xdr, args);
5293 +       encode_createhow3(xdr, args, req->rq_task->tk_client->cl_tag);
5294  }
5295  
5296  /*
5297 @@ -1074,7 +1080,7 @@ static void nfs3_xdr_enc_mkdir3args(stru
5298                                     const struct nfs3_mkdirargs *args)
5299  {
5300         encode_diropargs3(xdr, args->fh, args->name, args->len);
5301 -       encode_sattr3(xdr, args->sattr);
5302 +       encode_sattr3(xdr, args->sattr, req->rq_task->tk_client->cl_tag);
5303  }
5304  
5305  /*
5306 @@ -1091,9 +1097,9 @@ static void nfs3_xdr_enc_mkdir3args(stru
5307   *     };
5308   */
5309  static void encode_symlinkdata3(struct xdr_stream *xdr,
5310 -                               const struct nfs3_symlinkargs *args)
5311 +       const struct nfs3_symlinkargs *args, int tag)
5312  {
5313 -       encode_sattr3(xdr, args->sattr);
5314 +       encode_sattr3(xdr, args->sattr, tag);
5315         encode_nfspath3(xdr, args->pages, args->pathlen);
5316  }
5317  
5318 @@ -1102,7 +1108,7 @@ static void nfs3_xdr_enc_symlink3args(st
5319                                       const struct nfs3_symlinkargs *args)
5320  {
5321         encode_diropargs3(xdr, args->fromfh, args->fromname, args->fromlen);
5322 -       encode_symlinkdata3(xdr, args);
5323 +       encode_symlinkdata3(xdr, args, req->rq_task->tk_client->cl_tag);
5324  }
5325  
5326  /*
5327 @@ -1130,24 +1136,24 @@ static void nfs3_xdr_enc_symlink3args(st
5328   *     };
5329   */
5330  static void encode_devicedata3(struct xdr_stream *xdr,
5331 -                              const struct nfs3_mknodargs *args)
5332 +       const struct nfs3_mknodargs *args, int tag)
5333  {
5334 -       encode_sattr3(xdr, args->sattr);
5335 +       encode_sattr3(xdr, args->sattr, tag);
5336         encode_specdata3(xdr, args->rdev);
5337  }
5338  
5339  static void encode_mknoddata3(struct xdr_stream *xdr,
5340 -                             const struct nfs3_mknodargs *args)
5341 +       const struct nfs3_mknodargs *args, int tag)
5342  {
5343         encode_ftype3(xdr, args->type);
5344         switch (args->type) {
5345         case NF3CHR:
5346         case NF3BLK:
5347 -               encode_devicedata3(xdr, args);
5348 +               encode_devicedata3(xdr, args, tag);
5349                 break;
5350         case NF3SOCK:
5351         case NF3FIFO:
5352 -               encode_sattr3(xdr, args->sattr);
5353 +               encode_sattr3(xdr, args->sattr, tag);
5354                 break;
5355         case NF3REG:
5356         case NF3DIR:
5357 @@ -1162,7 +1168,7 @@ static void nfs3_xdr_enc_mknod3args(stru
5358                                     const struct nfs3_mknodargs *args)
5359  {
5360         encode_diropargs3(xdr, args->fh, args->name, args->len);
5361 -       encode_mknoddata3(xdr, args);
5362 +       encode_mknoddata3(xdr, args, req->rq_task->tk_client->cl_tag);
5363  }
5364  
5365  /*
5366 diff -NurpP --minimal linux-3.9.4/fs/nfs/super.c linux-3.9.4-vs2.3.6.2/fs/nfs/super.c
5367 --- linux-3.9.4/fs/nfs/super.c  2013-05-31 13:45:24.000000000 +0000
5368 +++ linux-3.9.4-vs2.3.6.2/fs/nfs/super.c        2013-05-31 15:41:34.000000000 +0000
5369 @@ -55,6 +55,7 @@
5370  #include <linux/parser.h>
5371  #include <linux/nsproxy.h>
5372  #include <linux/rcupdate.h>
5373 +#include <linux/vs_tag.h>
5374  
5375  #include <asm/uaccess.h>
5376  
5377 @@ -103,6 +104,7 @@ enum {
5378         Opt_mountport,
5379         Opt_mountvers,
5380         Opt_minorversion,
5381 +       Opt_tagid,
5382  
5383         /* Mount options that take string arguments */
5384         Opt_nfsvers,
5385 @@ -115,6 +117,9 @@ enum {
5386         /* Special mount options */
5387         Opt_userspace, Opt_deprecated, Opt_sloppy,
5388  
5389 +       /* Linux-VServer tagging options */
5390 +       Opt_tag, Opt_notag,
5391 +
5392         Opt_err
5393  };
5394  
5395 @@ -184,6 +189,10 @@ static const match_table_t nfs_mount_opt
5396         { Opt_fscache_uniq, "fsc=%s" },
5397         { Opt_local_lock, "local_lock=%s" },
5398  
5399 +       { Opt_tag, "tag" },
5400 +       { Opt_notag, "notag" },
5401 +       { Opt_tagid, "tagid=%u" },
5402 +
5403         /* The following needs to be listed after all other options */
5404         { Opt_nfsvers, "v%s" },
5405  
5406 @@ -635,6 +644,7 @@ static void nfs_show_mount_options(struc
5407                 { NFS_MOUNT_NORDIRPLUS, ",nordirplus", "" },
5408                 { NFS_MOUNT_UNSHARED, ",nosharecache", "" },
5409                 { NFS_MOUNT_NORESVPORT, ",noresvport", "" },
5410 +               { NFS_MOUNT_TAGGED, ",tag", "" },
5411                 { 0, NULL, NULL }
5412         };
5413         const struct proc_nfs_info *nfs_infop;
5414 @@ -1261,6 +1271,14 @@ static int nfs_parse_mount_options(char
5415                 case Opt_nomigration:
5416                         mnt->options &= NFS_OPTION_MIGRATION;
5417                         break;
5418 +#ifndef CONFIG_TAGGING_NONE
5419 +               case Opt_tag:
5420 +                       mnt->flags |= NFS_MOUNT_TAGGED;
5421 +                       break;
5422 +               case Opt_notag:
5423 +                       mnt->flags &= ~NFS_MOUNT_TAGGED;
5424 +                       break;
5425 +#endif
5426  
5427                 /*
5428                  * options that take numeric values
5429 @@ -1347,6 +1365,12 @@ static int nfs_parse_mount_options(char
5430                                 goto out_invalid_value;
5431                         mnt->minorversion = option;
5432                         break;
5433 +#ifdef CONFIG_PROPAGATE
5434 +               case Opt_tagid:
5435 +                       /* use args[0] */
5436 +                       nfs_data.flags |= NFS_MOUNT_TAGGED;
5437 +                       break;
5438 +#endif
5439  
5440                 /*
5441                  * options that take text values
5442 diff -NurpP --minimal linux-3.9.4/fs/nfsd/auth.c linux-3.9.4-vs2.3.6.2/fs/nfsd/auth.c
5443 --- linux-3.9.4/fs/nfsd/auth.c  2013-05-31 13:45:24.000000000 +0000
5444 +++ linux-3.9.4-vs2.3.6.2/fs/nfsd/auth.c        2013-05-31 14:47:11.000000000 +0000
5445 @@ -2,6 +2,7 @@
5446  
5447  #include <linux/sched.h>
5448  #include <linux/user_namespace.h>
5449 +#include <linux/vs_tag.h>
5450  #include "nfsd.h"
5451  #include "auth.h"
5452  
5453 @@ -37,6 +38,9 @@ int nfsd_setuser(struct svc_rqst *rqstp,
5454  
5455         new->fsuid = rqstp->rq_cred.cr_uid;
5456         new->fsgid = rqstp->rq_cred.cr_gid;
5457 +       /* FIXME: this desperately needs a tag :)
5458 +       new->xid = (xid_t)INOTAG_TAG(DX_TAG_NFSD, cred.cr_uid, cred.cr_gid, 0);
5459 +                       */
5460  
5461         rqgi = rqstp->rq_cred.cr_group_info;
5462  
5463 diff -NurpP --minimal linux-3.9.4/fs/nfsd/nfs3xdr.c linux-3.9.4-vs2.3.6.2/fs/nfsd/nfs3xdr.c
5464 --- linux-3.9.4/fs/nfsd/nfs3xdr.c       2013-05-31 13:45:24.000000000 +0000
5465 +++ linux-3.9.4-vs2.3.6.2/fs/nfsd/nfs3xdr.c     2013-05-31 16:17:38.000000000 +0000
5466 @@ -8,6 +8,7 @@
5467  
5468  #include <linux/namei.h>
5469  #include <linux/sunrpc/svc_xprt.h>
5470 +#include <linux/vs_tag.h>
5471  #include "xdr3.h"
5472  #include "auth.h"
5473  #include "netns.h"
5474 @@ -98,6 +99,8 @@ static __be32 *
5475  decode_sattr3(__be32 *p, struct iattr *iap)
5476  {
5477         u32     tmp;
5478 +       uid_t   uid = 0;
5479 +       gid_t   gid = 0;
5480  
5481         iap->ia_valid = 0;
5482  
5483 @@ -106,15 +109,18 @@ decode_sattr3(__be32 *p, struct iattr *i
5484                 iap->ia_mode = ntohl(*p++);
5485         }
5486         if (*p++) {
5487 -               iap->ia_uid = make_kuid(&init_user_ns, ntohl(*p++));
5488 +               uid = make_kuid(&init_user_ns, ntohl(*p++));
5489                 if (uid_valid(iap->ia_uid))
5490                         iap->ia_valid |= ATTR_UID;
5491         }
5492         if (*p++) {
5493 -               iap->ia_gid = make_kgid(&init_user_ns, ntohl(*p++));
5494 +               gid = make_kgid(&init_user_ns, ntohl(*p++));
5495                 if (gid_valid(iap->ia_gid))
5496                         iap->ia_valid |= ATTR_GID;
5497         }
5498 +       iap->ia_uid = INOTAG_UID(DX_TAG_NFSD, uid, gid);
5499 +       iap->ia_gid = INOTAG_GID(DX_TAG_NFSD, uid, gid);
5500 +       iap->ia_tag = INOTAG_TAG(DX_TAG_NFSD, uid, gid, 0);
5501         if (*p++) {
5502                 u64     newsize;
5503  
5504 @@ -170,8 +176,12 @@ encode_fattr3(struct svc_rqst *rqstp, __
5505         *p++ = htonl(nfs3_ftypes[(stat->mode & S_IFMT) >> 12]);
5506         *p++ = htonl((u32) stat->mode);
5507         *p++ = htonl((u32) stat->nlink);
5508 -       *p++ = htonl((u32) from_kuid(&init_user_ns, stat->uid));
5509 -       *p++ = htonl((u32) from_kgid(&init_user_ns, stat->gid));
5510 +       *p++ = htonl((u32) from_kuid(&init_user_ns,
5511 +               TAGINO_UID(0 /* FIXME: DX_TAG(dentry->d_inode) */,
5512 +               stat->uid, stat->tag)));
5513 +       *p++ = htonl((u32) from_kgid(&init_user_ns,
5514 +               TAGINO_GID(0 /* FIXME: DX_TAG(dentry->d_inode) */,
5515 +               stat->gid, stat->tag)));
5516         if (S_ISLNK(stat->mode) && stat->size > NFS3_MAXPATHLEN) {
5517                 p = xdr_encode_hyper(p, (u64) NFS3_MAXPATHLEN);
5518         } else {
5519 diff -NurpP --minimal linux-3.9.4/fs/nfsd/nfs4xdr.c linux-3.9.4-vs2.3.6.2/fs/nfsd/nfs4xdr.c
5520 --- linux-3.9.4/fs/nfsd/nfs4xdr.c       2013-05-31 14:22:27.000000000 +0000
5521 +++ linux-3.9.4-vs2.3.6.2/fs/nfsd/nfs4xdr.c     2013-05-31 14:47:11.000000000 +0000
5522 @@ -46,6 +46,7 @@
5523  #include <linux/utsname.h>
5524  #include <linux/pagemap.h>
5525  #include <linux/sunrpc/svcauth_gss.h>
5526 +#include <linux/vs_tag.h>
5527  
5528  #include "idmap.h"
5529  #include "acl.h"
5530 @@ -2349,14 +2350,18 @@ out_acl:
5531                 WRITE32(stat.nlink);
5532         }
5533         if (bmval1 & FATTR4_WORD1_OWNER) {
5534 -               status = nfsd4_encode_user(rqstp, stat.uid, &p, &buflen);
5535 +               status = nfsd4_encode_user(rqstp,
5536 +                       TAGINO_UID(DX_TAG(dentry->d_inode),
5537 +                       stat.uid, stat.tag), &p, &buflen);
5538                 if (status == nfserr_resource)
5539                         goto out_resource;
5540                 if (status)
5541                         goto out;
5542         }
5543         if (bmval1 & FATTR4_WORD1_OWNER_GROUP) {
5544 -               status = nfsd4_encode_group(rqstp, stat.gid, &p, &buflen);
5545 +               status = nfsd4_encode_group(rqstp,
5546 +                       TAGINO_GID(DX_TAG(dentry->d_inode),
5547 +                       stat.gid, stat.tag), &p, &buflen);
5548                 if (status == nfserr_resource)
5549                         goto out_resource;
5550                 if (status)
5551 diff -NurpP --minimal linux-3.9.4/fs/nfsd/nfsxdr.c linux-3.9.4-vs2.3.6.2/fs/nfsd/nfsxdr.c
5552 --- linux-3.9.4/fs/nfsd/nfsxdr.c        2013-05-31 13:45:24.000000000 +0000
5553 +++ linux-3.9.4-vs2.3.6.2/fs/nfsd/nfsxdr.c      2013-05-31 16:20:53.000000000 +0000
5554 @@ -7,6 +7,7 @@
5555  #include "vfs.h"
5556  #include "xdr.h"
5557  #include "auth.h"
5558 +#include <linux/vs_tag.h>
5559  
5560  #define NFSDDBG_FACILITY               NFSDDBG_XDR
5561  
5562 @@ -89,6 +90,8 @@ static __be32 *
5563  decode_sattr(__be32 *p, struct iattr *iap)
5564  {
5565         u32     tmp, tmp1;
5566 +       uid_t   uid = 0;
5567 +       gid_t   gid = 0;
5568  
5569         iap->ia_valid = 0;
5570  
5571 @@ -101,15 +104,18 @@ decode_sattr(__be32 *p, struct iattr *ia
5572                 iap->ia_mode = tmp;
5573         }
5574         if ((tmp = ntohl(*p++)) != (u32)-1) {
5575 -               iap->ia_uid = make_kuid(&init_user_ns, tmp);
5576 +               uid = make_kuid(&init_user_ns, tmp);
5577                 if (uid_valid(iap->ia_uid))
5578                         iap->ia_valid |= ATTR_UID;
5579         }
5580         if ((tmp = ntohl(*p++)) != (u32)-1) {
5581 -               iap->ia_gid = make_kgid(&init_user_ns, tmp);
5582 +               gid = make_kgid(&init_user_ns, tmp);
5583                 if (gid_valid(iap->ia_gid))
5584                         iap->ia_valid |= ATTR_GID;
5585         }
5586 +       iap->ia_uid = INOTAG_UID(DX_TAG_NFSD, uid, gid);
5587 +       iap->ia_gid = INOTAG_GID(DX_TAG_NFSD, uid, gid);
5588 +       iap->ia_tag = INOTAG_TAG(DX_TAG_NFSD, uid, gid, 0);
5589         if ((tmp = ntohl(*p++)) != (u32)-1) {
5590                 iap->ia_valid |= ATTR_SIZE;
5591                 iap->ia_size = tmp;
5592 @@ -154,8 +160,10 @@ encode_fattr(struct svc_rqst *rqstp, __b
5593         *p++ = htonl(nfs_ftypes[type >> 12]);
5594         *p++ = htonl((u32) stat->mode);
5595         *p++ = htonl((u32) stat->nlink);
5596 -       *p++ = htonl((u32) from_kuid(&init_user_ns, stat->uid));
5597 -       *p++ = htonl((u32) from_kgid(&init_user_ns, stat->gid));
5598 +       *p++ = htonl((u32) from_kuid(&init_user_ns,
5599 +               TAGINO_UID(DX_TAG(dentry->d_inode), stat->uid, stat->tag)));
5600 +       *p++ = htonl((u32) from_kgid(&init_user_ns,
5601 +               TAGINO_GID(DX_TAG(dentry->d_inode), stat->gid, stat->tag)));
5602  
5603         if (S_ISLNK(type) && stat->size > NFS_MAXPATHLEN) {
5604                 *p++ = htonl(NFS_MAXPATHLEN);
5605 diff -NurpP --minimal linux-3.9.4/fs/ocfs2/dlmglue.c linux-3.9.4-vs2.3.6.2/fs/ocfs2/dlmglue.c
5606 --- linux-3.9.4/fs/ocfs2/dlmglue.c      2013-05-31 13:45:24.000000000 +0000
5607 +++ linux-3.9.4-vs2.3.6.2/fs/ocfs2/dlmglue.c    2013-05-31 15:47:29.000000000 +0000
5608 @@ -2047,6 +2047,7 @@ static void __ocfs2_stuff_meta_lvb(struc
5609         lvb->lvb_iclusters = cpu_to_be32(oi->ip_clusters);
5610         lvb->lvb_iuid      = cpu_to_be32(i_uid_read(inode));
5611         lvb->lvb_igid      = cpu_to_be32(i_gid_read(inode));
5612 +       lvb->lvb_itag      = cpu_to_be16(inode->i_tag);
5613         lvb->lvb_imode     = cpu_to_be16(inode->i_mode);
5614         lvb->lvb_inlink    = cpu_to_be16(inode->i_nlink);
5615         lvb->lvb_iatime_packed  =
5616 @@ -2097,6 +2098,7 @@ static void ocfs2_refresh_inode_from_lvb
5617  
5618         i_uid_write(inode, be32_to_cpu(lvb->lvb_iuid));
5619         i_gid_write(inode, be32_to_cpu(lvb->lvb_igid));
5620 +       i_tag_write(inode, be16_to_cpu(lvb->lvb_itag));
5621         inode->i_mode    = be16_to_cpu(lvb->lvb_imode);
5622         set_nlink(inode, be16_to_cpu(lvb->lvb_inlink));
5623         ocfs2_unpack_timespec(&inode->i_atime,
5624 diff -NurpP --minimal linux-3.9.4/fs/ocfs2/dlmglue.h linux-3.9.4-vs2.3.6.2/fs/ocfs2/dlmglue.h
5625 --- linux-3.9.4/fs/ocfs2/dlmglue.h      2012-12-11 03:30:57.000000000 +0000
5626 +++ linux-3.9.4-vs2.3.6.2/fs/ocfs2/dlmglue.h    2013-05-31 14:47:11.000000000 +0000
5627 @@ -46,7 +46,8 @@ struct ocfs2_meta_lvb {
5628         __be16       lvb_inlink;
5629         __be32       lvb_iattr;
5630         __be32       lvb_igeneration;
5631 -       __be32       lvb_reserved2;
5632 +       __be16       lvb_itag;
5633 +       __be16       lvb_reserved2;
5634  };
5635  
5636  #define OCFS2_QINFO_LVB_VERSION 1
5637 diff -NurpP --minimal linux-3.9.4/fs/ocfs2/file.c linux-3.9.4-vs2.3.6.2/fs/ocfs2/file.c
5638 --- linux-3.9.4/fs/ocfs2/file.c 2013-05-31 13:45:24.000000000 +0000
5639 +++ linux-3.9.4-vs2.3.6.2/fs/ocfs2/file.c       2013-05-31 14:47:11.000000000 +0000
5640 @@ -1124,7 +1124,7 @@ int ocfs2_setattr(struct dentry *dentry,
5641                 attr->ia_valid &= ~ATTR_SIZE;
5642  
5643  #define OCFS2_VALID_ATTRS (ATTR_ATIME | ATTR_MTIME | ATTR_CTIME | ATTR_SIZE \
5644 -                          | ATTR_GID | ATTR_UID | ATTR_MODE)
5645 +                          | ATTR_GID | ATTR_UID | ATTR_TAG | ATTR_MODE)
5646         if (!(attr->ia_valid & OCFS2_VALID_ATTRS))
5647                 return 0;
5648  
5649 diff -NurpP --minimal linux-3.9.4/fs/ocfs2/inode.c linux-3.9.4-vs2.3.6.2/fs/ocfs2/inode.c
5650 --- linux-3.9.4/fs/ocfs2/inode.c        2013-05-31 13:45:24.000000000 +0000
5651 +++ linux-3.9.4-vs2.3.6.2/fs/ocfs2/inode.c      2013-05-31 20:39:47.000000000 +0000
5652 @@ -28,6 +28,7 @@
5653  #include <linux/highmem.h>
5654  #include <linux/pagemap.h>
5655  #include <linux/quotaops.h>
5656 +#include <linux/vs_tag.h>
5657  
5658  #include <asm/byteorder.h>
5659  
5660 @@ -78,11 +79,13 @@ void ocfs2_set_inode_flags(struct inode
5661  {
5662         unsigned int flags = OCFS2_I(inode)->ip_attr;
5663  
5664 -       inode->i_flags &= ~(S_IMMUTABLE |
5665 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
5666                 S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
5667  
5668         if (flags & OCFS2_IMMUTABLE_FL)
5669                 inode->i_flags |= S_IMMUTABLE;
5670 +       if (flags & OCFS2_IXUNLINK_FL)
5671 +               inode->i_flags |= S_IXUNLINK;
5672  
5673         if (flags & OCFS2_SYNC_FL)
5674                 inode->i_flags |= S_SYNC;
5675 @@ -92,25 +95,44 @@ void ocfs2_set_inode_flags(struct inode
5676                 inode->i_flags |= S_NOATIME;
5677         if (flags & OCFS2_DIRSYNC_FL)
5678                 inode->i_flags |= S_DIRSYNC;
5679 +
5680 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
5681 +
5682 +       if (flags & OCFS2_BARRIER_FL)
5683 +               inode->i_vflags |= V_BARRIER;
5684 +       if (flags & OCFS2_COW_FL)
5685 +               inode->i_vflags |= V_COW;
5686  }
5687  
5688  /* Propagate flags from i_flags to OCFS2_I(inode)->ip_attr */
5689  void ocfs2_get_inode_flags(struct ocfs2_inode_info *oi)
5690  {
5691         unsigned int flags = oi->vfs_inode.i_flags;
5692 +       unsigned int vflags = oi->vfs_inode.i_vflags;
5693 +
5694 +       oi->ip_attr &= ~(OCFS2_SYNC_FL | OCFS2_APPEND_FL |
5695 +                       OCFS2_IMMUTABLE_FL | OCFS2_IXUNLINK_FL |
5696 +                       OCFS2_NOATIME_FL | OCFS2_DIRSYNC_FL |
5697 +                       OCFS2_BARRIER_FL | OCFS2_COW_FL);
5698 +
5699 +       if (flags & S_IMMUTABLE)
5700 +               oi->ip_attr |= OCFS2_IMMUTABLE_FL;
5701 +       if (flags & S_IXUNLINK)
5702 +               oi->ip_attr |= OCFS2_IXUNLINK_FL;
5703  
5704 -       oi->ip_attr &= ~(OCFS2_SYNC_FL|OCFS2_APPEND_FL|
5705 -                       OCFS2_IMMUTABLE_FL|OCFS2_NOATIME_FL|OCFS2_DIRSYNC_FL);
5706         if (flags & S_SYNC)
5707                 oi->ip_attr |= OCFS2_SYNC_FL;
5708         if (flags & S_APPEND)
5709                 oi->ip_attr |= OCFS2_APPEND_FL;
5710 -       if (flags & S_IMMUTABLE)
5711 -               oi->ip_attr |= OCFS2_IMMUTABLE_FL;
5712         if (flags & S_NOATIME)
5713                 oi->ip_attr |= OCFS2_NOATIME_FL;
5714         if (flags & S_DIRSYNC)
5715                 oi->ip_attr |= OCFS2_DIRSYNC_FL;
5716 +
5717 +       if (vflags & V_BARRIER)
5718 +               oi->ip_attr |= OCFS2_BARRIER_FL;
5719 +       if (vflags & V_COW)
5720 +               oi->ip_attr |= OCFS2_COW_FL;
5721  }
5722  
5723  struct inode *ocfs2_ilookup(struct super_block *sb, u64 blkno)
5724 @@ -241,6 +263,8 @@ void ocfs2_populate_inode(struct inode *
5725         struct super_block *sb;
5726         struct ocfs2_super *osb;
5727         int use_plocks = 1;
5728 +       uid_t uid;
5729 +       gid_t gid;
5730  
5731         sb = inode->i_sb;
5732         osb = OCFS2_SB(sb);
5733 @@ -269,8 +293,12 @@ void ocfs2_populate_inode(struct inode *
5734         inode->i_generation = le32_to_cpu(fe->i_generation);
5735         inode->i_rdev = huge_decode_dev(le64_to_cpu(fe->id1.dev1.i_rdev));
5736         inode->i_mode = le16_to_cpu(fe->i_mode);
5737 -       i_uid_write(inode, le32_to_cpu(fe->i_uid));
5738 -       i_gid_write(inode, le32_to_cpu(fe->i_gid));
5739 +       uid = le32_to_cpu(fe->i_uid);
5740 +       gid = le32_to_cpu(fe->i_gid);
5741 +       i_uid_write(inode, INOTAG_UID(DX_TAG(inode), uid, gid));
5742 +       i_gid_write(inode, INOTAG_GID(DX_TAG(inode), uid, gid));
5743 +       i_tag_write(inode, INOTAG_TAG(DX_TAG(inode), uid, gid,
5744 +               /* le16_to_cpu(raw_inode->i_raw_tag) */ 0));
5745  
5746         /* Fast symlinks will have i_size but no allocated clusters. */
5747         if (S_ISLNK(inode->i_mode) && !fe->i_clusters) {
5748 diff -NurpP --minimal linux-3.9.4/fs/ocfs2/inode.h linux-3.9.4-vs2.3.6.2/fs/ocfs2/inode.h
5749 --- linux-3.9.4/fs/ocfs2/inode.h        2012-12-11 03:30:57.000000000 +0000
5750 +++ linux-3.9.4-vs2.3.6.2/fs/ocfs2/inode.h      2013-05-31 14:47:11.000000000 +0000
5751 @@ -154,6 +154,7 @@ struct buffer_head *ocfs2_bread(struct i
5752  
5753  void ocfs2_set_inode_flags(struct inode *inode);
5754  void ocfs2_get_inode_flags(struct ocfs2_inode_info *oi);
5755 +int ocfs2_sync_flags(struct inode *inode, int, int);
5756  
5757  static inline blkcnt_t ocfs2_inode_sector_count(struct inode *inode)
5758  {
5759 diff -NurpP --minimal linux-3.9.4/fs/ocfs2/ioctl.c linux-3.9.4-vs2.3.6.2/fs/ocfs2/ioctl.c
5760 --- linux-3.9.4/fs/ocfs2/ioctl.c        2013-05-31 13:45:24.000000000 +0000
5761 +++ linux-3.9.4-vs2.3.6.2/fs/ocfs2/ioctl.c      2013-05-31 14:47:11.000000000 +0000
5762 @@ -76,7 +76,41 @@ static int ocfs2_get_inode_attr(struct i
5763         return status;
5764  }
5765  
5766 -static int ocfs2_set_inode_attr(struct inode *inode, unsigned flags,
5767 +int ocfs2_sync_flags(struct inode *inode, int flags, int vflags)
5768 +{
5769 +       struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
5770 +       struct buffer_head *bh = NULL;
5771 +       handle_t *handle = NULL;
5772 +       int status;
5773 +
5774 +       status = ocfs2_inode_lock(inode, &bh, 1);
5775 +       if (status < 0) {
5776 +               mlog_errno(status);
5777 +               return status;
5778 +       }
5779 +       handle = ocfs2_start_trans(osb, OCFS2_INODE_UPDATE_CREDITS);
5780 +       if (IS_ERR(handle)) {
5781 +               status = PTR_ERR(handle);
5782 +               mlog_errno(status);
5783 +               goto bail_unlock;
5784 +       }
5785 +
5786 +       inode->i_flags = flags;
5787 +       inode->i_vflags = vflags;
5788 +       ocfs2_get_inode_flags(OCFS2_I(inode));
5789 +
5790 +       status = ocfs2_mark_inode_dirty(handle, inode, bh);
5791 +       if (status < 0)
5792 +               mlog_errno(status);
5793 +
5794 +       ocfs2_commit_trans(osb, handle);
5795 +bail_unlock:
5796 +       ocfs2_inode_unlock(inode, 1);
5797 +       brelse(bh);
5798 +       return status;
5799 +}
5800 +
5801 +int ocfs2_set_inode_attr(struct inode *inode, unsigned flags,
5802                                 unsigned mask)
5803  {
5804         struct ocfs2_inode_info *ocfs2_inode = OCFS2_I(inode);
5805 @@ -101,6 +135,11 @@ static int ocfs2_set_inode_attr(struct i
5806         if (!S_ISDIR(inode->i_mode))
5807                 flags &= ~OCFS2_DIRSYNC_FL;
5808  
5809 +       if (IS_BARRIER(inode)) {
5810 +               vxwprintk_task(1, "messing with the barrier.");
5811 +               goto bail_unlock;
5812 +       }
5813 +
5814         handle = ocfs2_start_trans(osb, OCFS2_INODE_UPDATE_CREDITS);
5815         if (IS_ERR(handle)) {
5816                 status = PTR_ERR(handle);
5817 @@ -879,6 +918,7 @@ bail:
5818         return status;
5819  }
5820  
5821 +
5822  long ocfs2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
5823  {
5824         struct inode *inode = file_inode(filp);
5825 diff -NurpP --minimal linux-3.9.4/fs/ocfs2/namei.c linux-3.9.4-vs2.3.6.2/fs/ocfs2/namei.c
5826 --- linux-3.9.4/fs/ocfs2/namei.c        2013-05-31 13:45:24.000000000 +0000
5827 +++ linux-3.9.4-vs2.3.6.2/fs/ocfs2/namei.c      2013-05-31 15:52:25.000000000 +0000
5828 @@ -41,6 +41,7 @@
5829  #include <linux/slab.h>
5830  #include <linux/highmem.h>
5831  #include <linux/quotaops.h>
5832 +#include <linux/vs_tag.h>
5833  
5834  #include <cluster/masklog.h>
5835  
5836 @@ -475,6 +476,7 @@ static int __ocfs2_mknod_locked(struct i
5837         struct ocfs2_dinode *fe = NULL;
5838         struct ocfs2_extent_list *fel;
5839         u16 feat;
5840 +       tag_t tag;
5841  
5842         *new_fe_bh = NULL;
5843  
5844 @@ -512,8 +514,11 @@ static int __ocfs2_mknod_locked(struct i
5845         fe->i_suballoc_loc = cpu_to_le64(suballoc_loc);
5846         fe->i_suballoc_bit = cpu_to_le16(suballoc_bit);
5847         fe->i_suballoc_slot = cpu_to_le16(inode_ac->ac_alloc_slot);
5848 -       fe->i_uid = cpu_to_le32(i_uid_read(inode));
5849 -       fe->i_gid = cpu_to_le32(i_gid_read(inode));
5850 +
5851 +       tag = dx_current_fstag(osb->sb);
5852 +       fe->i_uid = cpu_to_le32(TAGINO_UID(DX_TAG(inode), i_uid_read(inode), tag));
5853 +       fe->i_gid = cpu_to_le32(TAGINO_GID(DX_TAG(inode), i_gid_read(inode), tag));
5854 +       inode->i_tag = tag; /* is this correct? */
5855         fe->i_mode = cpu_to_le16(inode->i_mode);
5856         if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode))
5857                 fe->id1.dev1.i_rdev = cpu_to_le64(huge_encode_dev(dev));
5858 diff -NurpP --minimal linux-3.9.4/fs/ocfs2/ocfs2.h linux-3.9.4-vs2.3.6.2/fs/ocfs2/ocfs2.h
5859 --- linux-3.9.4/fs/ocfs2/ocfs2.h        2012-12-11 03:30:57.000000000 +0000
5860 +++ linux-3.9.4-vs2.3.6.2/fs/ocfs2/ocfs2.h      2013-05-31 14:47:11.000000000 +0000
5861 @@ -272,6 +272,7 @@ enum ocfs2_mount_options
5862                                                      writes */
5863         OCFS2_MOUNT_HB_NONE = 1 << 13, /* No heartbeat */
5864         OCFS2_MOUNT_HB_GLOBAL = 1 << 14, /* Global heartbeat */
5865 +       OCFS2_MOUNT_TAGGED = 1 << 15, /* use tagging */
5866  };
5867  
5868  #define OCFS2_OSB_SOFT_RO                      0x0001
5869 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
5870 --- linux-3.9.4/fs/ocfs2/ocfs2_fs.h     2012-12-11 03:30:57.000000000 +0000
5871 +++ linux-3.9.4-vs2.3.6.2/fs/ocfs2/ocfs2_fs.h   2013-05-31 14:47:11.000000000 +0000
5872 @@ -266,6 +266,11 @@
5873  #define OCFS2_TOPDIR_FL                        FS_TOPDIR_FL    /* Top of directory hierarchies*/
5874  #define OCFS2_RESERVED_FL              FS_RESERVED_FL  /* reserved for ext2 lib */
5875  
5876 +#define OCFS2_IXUNLINK_FL              FS_IXUNLINK_FL  /* Immutable invert on unlink */
5877 +
5878 +#define OCFS2_BARRIER_FL               FS_BARRIER_FL   /* Barrier for chroot() */
5879 +#define OCFS2_COW_FL                   FS_COW_FL       /* Copy on Write marker */
5880 +
5881  #define OCFS2_FL_VISIBLE               FS_FL_USER_VISIBLE      /* User visible flags */
5882  #define OCFS2_FL_MODIFIABLE            FS_FL_USER_MODIFIABLE   /* User modifiable flags */
5883  
5884 diff -NurpP --minimal linux-3.9.4/fs/ocfs2/super.c linux-3.9.4-vs2.3.6.2/fs/ocfs2/super.c
5885 --- linux-3.9.4/fs/ocfs2/super.c        2013-05-31 13:45:25.000000000 +0000
5886 +++ linux-3.9.4-vs2.3.6.2/fs/ocfs2/super.c      2013-05-31 14:47:11.000000000 +0000
5887 @@ -185,6 +185,7 @@ enum {
5888         Opt_coherency_full,
5889         Opt_resv_level,
5890         Opt_dir_resv_level,
5891 +       Opt_tag, Opt_notag, Opt_tagid,
5892         Opt_err,
5893  };
5894  
5895 @@ -216,6 +217,9 @@ static const match_table_t tokens = {
5896         {Opt_coherency_full, "coherency=full"},
5897         {Opt_resv_level, "resv_level=%u"},
5898         {Opt_dir_resv_level, "dir_resv_level=%u"},
5899 +       {Opt_tag, "tag"},
5900 +       {Opt_notag, "notag"},
5901 +       {Opt_tagid, "tagid=%u"},
5902         {Opt_err, NULL}
5903  };
5904  
5905 @@ -662,6 +666,13 @@ static int ocfs2_remount(struct super_bl
5906                 goto out;
5907         }
5908  
5909 +       if ((osb->s_mount_opt & OCFS2_MOUNT_TAGGED) !=
5910 +           (parsed_options.mount_opt & OCFS2_MOUNT_TAGGED)) {
5911 +               ret = -EINVAL;
5912 +               mlog(ML_ERROR, "Cannot change tagging on remount\n");
5913 +               goto out;
5914 +       }
5915 +
5916         /* We're going to/from readonly mode. */
5917         if ((*flags & MS_RDONLY) != (sb->s_flags & MS_RDONLY)) {
5918                 /* Disable quota accounting before remounting RO */
5919 @@ -1177,6 +1188,9 @@ static int ocfs2_fill_super(struct super
5920  
5921         ocfs2_complete_mount_recovery(osb);
5922  
5923 +       if (osb->s_mount_opt & OCFS2_MOUNT_TAGGED)
5924 +               sb->s_flags |= MS_TAGGED;
5925 +
5926         if (ocfs2_mount_local(osb))
5927                 snprintf(nodestr, sizeof(nodestr), "local");
5928         else
5929 @@ -1504,6 +1518,20 @@ static int ocfs2_parse_options(struct su
5930                             option < OCFS2_MAX_RESV_LEVEL)
5931                                 mopt->dir_resv_level = option;
5932                         break;
5933 +#ifndef CONFIG_TAGGING_NONE
5934 +               case Opt_tag:
5935 +                       mopt->mount_opt |= OCFS2_MOUNT_TAGGED;
5936 +                       break;
5937 +               case Opt_notag:
5938 +                       mopt->mount_opt &= ~OCFS2_MOUNT_TAGGED;
5939 +                       break;
5940 +#endif
5941 +#ifdef CONFIG_PROPAGATE
5942 +               case Opt_tagid:
5943 +                       /* use args[0] */
5944 +                       mopt->mount_opt |= OCFS2_MOUNT_TAGGED;
5945 +                       break;
5946 +#endif
5947                 default:
5948                         mlog(ML_ERROR,
5949                              "Unrecognized mount option \"%s\" "
5950 diff -NurpP --minimal linux-3.9.4/fs/open.c linux-3.9.4-vs2.3.6.2/fs/open.c
5951 --- linux-3.9.4/fs/open.c       2013-05-31 13:45:25.000000000 +0000
5952 +++ linux-3.9.4-vs2.3.6.2/fs/open.c     2013-06-01 08:41:29.000000000 +0000
5953 @@ -31,6 +31,11 @@
5954  #include <linux/ima.h>
5955  #include <linux/dnotify.h>
5956  #include <linux/compat.h>
5957 +#include <linux/vs_base.h>
5958 +#include <linux/vs_limit.h>
5959 +#include <linux/vs_tag.h>
5960 +#include <linux/vs_cowbl.h>
5961 +#include <linux/vserver/dlimit.h>
5962  
5963  #include "internal.h"
5964  
5965 @@ -67,6 +72,11 @@ long vfs_truncate(struct path *path, lof
5966         struct inode *inode;
5967         long error;
5968  
5969 +#ifdef CONFIG_VSERVER_COWBL
5970 +       error = cow_check_and_break(path);
5971 +       if (error)
5972 +               goto out;
5973 +#endif
5974         inode = path->dentry->d_inode;
5975  
5976         /* For directories it's -EISDIR, for other non-regulars - -EINVAL */
5977 @@ -532,6 +542,13 @@ SYSCALL_DEFINE3(fchmodat, int, dfd, cons
5978         unsigned int lookup_flags = LOOKUP_FOLLOW;
5979  retry:
5980         error = user_path_at(dfd, filename, lookup_flags, &path);
5981 +#ifdef CONFIG_VSERVER_COWBL
5982 +       if (!error) {
5983 +               error = cow_check_and_break(&path);
5984 +               if (error)
5985 +                       path_put(&path);
5986 +       }
5987 +#endif
5988         if (!error) {
5989                 error = chmod_common(&path, mode);
5990                 path_put(&path);
5991 @@ -564,13 +581,15 @@ static int chown_common(struct path *pat
5992                 if (!uid_valid(uid))
5993                         return -EINVAL;
5994                 newattrs.ia_valid |= ATTR_UID;
5995 -               newattrs.ia_uid = uid;
5996 +               newattrs.ia_uid = make_kuid(&init_user_ns,
5997 +                       dx_map_uid(user));
5998         }
5999         if (group != (gid_t) -1) {
6000                 if (!gid_valid(gid))
6001                         return -EINVAL;
6002                 newattrs.ia_valid |= ATTR_GID;
6003 -               newattrs.ia_gid = gid;
6004 +               newattrs.ia_gid = make_kgid(&init_user_ns,
6005 +                       dx_map_gid(group));
6006         }
6007         if (!S_ISDIR(inode->i_mode))
6008                 newattrs.ia_valid |=
6009 @@ -604,6 +623,18 @@ retry:
6010         error = mnt_want_write(path.mnt);
6011         if (error)
6012                 goto out_release;
6013 +#ifdef CONFIG_VSERVER_COWBL
6014 +       error = cow_check_and_break(&path);
6015 +       if (!error)
6016 +#endif
6017 +#ifdef CONFIG_VSERVER_COWBL
6018 +       error = cow_check_and_break(&path);
6019 +       if (!error)
6020 +#endif
6021 +#ifdef CONFIG_VSERVER_COWBL
6022 +       error = cow_check_and_break(&path);
6023 +       if (!error)
6024 +#endif
6025         error = chown_common(&path, user, group);
6026         mnt_drop_write(path.mnt);
6027  out_release:
6028 diff -NurpP --minimal linux-3.9.4/fs/proc/array.c linux-3.9.4-vs2.3.6.2/fs/proc/array.c
6029 --- linux-3.9.4/fs/proc/array.c 2013-05-31 13:45:25.000000000 +0000
6030 +++ linux-3.9.4-vs2.3.6.2/fs/proc/array.c       2013-05-31 14:47:11.000000000 +0000
6031 @@ -82,6 +82,8 @@
6032  #include <linux/ptrace.h>
6033  #include <linux/tracehook.h>
6034  #include <linux/user_namespace.h>
6035 +#include <linux/vs_context.h>
6036 +#include <linux/vs_network.h>
6037  
6038  #include <asm/pgtable.h>
6039  #include <asm/processor.h>
6040 @@ -173,6 +175,9 @@ static inline void task_state(struct seq
6041         rcu_read_lock();
6042         ppid = pid_alive(p) ?
6043                 task_tgid_nr_ns(rcu_dereference(p->real_parent), ns) : 0;
6044 +       if (unlikely(vx_current_initpid(p->pid)))
6045 +               ppid = 0;
6046 +
6047         tpid = 0;
6048         if (pid_alive(p)) {
6049                 struct task_struct *tracer = ptrace_parent(p);
6050 @@ -297,7 +302,7 @@ static inline void task_sig(struct seq_f
6051  }
6052  
6053  static void render_cap_t(struct seq_file *m, const char *header,
6054 -                       kernel_cap_t *a)
6055 +                       struct vx_info *vxi, kernel_cap_t *a)
6056  {
6057         unsigned __capi;
6058  
6059 @@ -331,10 +336,11 @@ static inline void task_cap(struct seq_f
6060         NORM_CAPS(cap_effective);
6061         NORM_CAPS(cap_bset);
6062  
6063 -       render_cap_t(m, "CapInh:\t", &cap_inheritable);
6064 -       render_cap_t(m, "CapPrm:\t", &cap_permitted);
6065 -       render_cap_t(m, "CapEff:\t", &cap_effective);
6066 -       render_cap_t(m, "CapBnd:\t", &cap_bset);
6067 +       /* FIXME: maybe move the p->vx_info masking to __task_cred() ? */
6068 +       render_cap_t(m, "CapInh:\t", p->vx_info, &cap_inheritable);
6069 +       render_cap_t(m, "CapPrm:\t", p->vx_info, &cap_permitted);
6070 +       render_cap_t(m, "CapEff:\t", p->vx_info, &cap_effective);
6071 +       render_cap_t(m, "CapBnd:\t", p->vx_info, &cap_bset);
6072  }
6073  
6074  static inline void task_seccomp(struct seq_file *m, struct task_struct *p)
6075 @@ -363,6 +369,42 @@ static void task_cpus_allowed(struct seq
6076         seq_putc(m, '\n');
6077  }
6078  
6079 +int proc_pid_nsproxy(struct seq_file *m, struct pid_namespace *ns,
6080 +                       struct pid *pid, struct task_struct *task)
6081 +{
6082 +       seq_printf(m,   "Proxy:\t%p(%c)\n"
6083 +                       "Count:\t%u\n"
6084 +                       "uts:\t%p(%c)\n"
6085 +                       "ipc:\t%p(%c)\n"
6086 +                       "mnt:\t%p(%c)\n"
6087 +                       "pid:\t%p(%c)\n"
6088 +                       "net:\t%p(%c)\n",
6089 +                       task->nsproxy,
6090 +                       (task->nsproxy == init_task.nsproxy ? 'I' : '-'),
6091 +                       atomic_read(&task->nsproxy->count),
6092 +                       task->nsproxy->uts_ns,
6093 +                       (task->nsproxy->uts_ns == init_task.nsproxy->uts_ns ? 'I' : '-'),
6094 +                       task->nsproxy->ipc_ns,
6095 +                       (task->nsproxy->ipc_ns == init_task.nsproxy->ipc_ns ? 'I' : '-'),
6096 +                       task->nsproxy->mnt_ns,
6097 +                       (task->nsproxy->mnt_ns == init_task.nsproxy->mnt_ns ? 'I' : '-'),
6098 +                       task->nsproxy->pid_ns,
6099 +                       (task->nsproxy->pid_ns == init_task.nsproxy->pid_ns ? 'I' : '-'),
6100 +                       task->nsproxy->net_ns,
6101 +                       (task->nsproxy->net_ns == init_task.nsproxy->net_ns ? 'I' : '-'));
6102 +       return 0;
6103 +}
6104 +
6105 +void task_vs_id(struct seq_file *m, struct task_struct *task)
6106 +{
6107 +       if (task_vx_flags(task, VXF_HIDE_VINFO, 0))
6108 +               return;
6109 +
6110 +       seq_printf(m, "VxID: %d\n", vx_task_xid(task));
6111 +       seq_printf(m, "NxID: %d\n", nx_task_nid(task));
6112 +}
6113 +
6114 +
6115  int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
6116                         struct pid *pid, struct task_struct *task)
6117  {
6118 @@ -380,6 +422,7 @@ int proc_pid_status(struct seq_file *m,
6119         task_seccomp(m, task);
6120         task_cpus_allowed(m, task);
6121         cpuset_task_status_allowed(m, task);
6122 +       task_vs_id(m, task);
6123         task_context_switch_counts(m, task);
6124         return 0;
6125  }
6126 @@ -489,6 +532,17 @@ static int do_task_stat(struct seq_file
6127         /* convert nsec -> ticks */
6128         start_time = nsec_to_clock_t(start_time);
6129  
6130 +       /* fixup start time for virt uptime */
6131 +       if (vx_flags(VXF_VIRT_UPTIME, 0)) {
6132 +               unsigned long long bias =
6133 +                       current->vx_info->cvirt.bias_clock;
6134 +
6135 +               if (start_time > bias)
6136 +                       start_time -= bias;
6137 +               else
6138 +                       start_time = 0;
6139 +       }
6140 +
6141         seq_printf(m, "%d (%s) %c", pid_nr_ns(pid, ns), tcomm, state);
6142         seq_put_decimal_ll(m, ' ', ppid);
6143         seq_put_decimal_ll(m, ' ', pgid);
6144 diff -NurpP --minimal linux-3.9.4/fs/proc/base.c linux-3.9.4-vs2.3.6.2/fs/proc/base.c
6145 --- linux-3.9.4/fs/proc/base.c  2013-05-31 13:45:25.000000000 +0000
6146 +++ linux-3.9.4-vs2.3.6.2/fs/proc/base.c        2013-05-31 14:47:11.000000000 +0000
6147 @@ -86,6 +86,8 @@
6148  #include <linux/fs_struct.h>
6149  #include <linux/slab.h>
6150  #include <linux/flex_array.h>
6151 +#include <linux/vs_context.h>
6152 +#include <linux/vs_network.h>
6153  #ifdef CONFIG_HARDWALL
6154  #include <asm/hardwall.h>
6155  #endif
6156 @@ -944,11 +946,15 @@ static ssize_t oom_adj_write(struct file
6157                 oom_adj = (oom_adj * OOM_SCORE_ADJ_MAX) / -OOM_DISABLE;
6158  
6159         if (oom_adj < task->signal->oom_score_adj &&
6160 -           !capable(CAP_SYS_RESOURCE)) {
6161 +           !vx_capable(CAP_SYS_RESOURCE, VXC_OOM_ADJUST)) {
6162                 err = -EACCES;
6163                 goto err_sighand;
6164         }
6165  
6166 +       /* prevent guest processes from circumventing the oom killer */
6167 +       if (vx_current_xid() && (oom_adj == OOM_DISABLE))
6168 +               oom_adj = OOM_ADJUST_MIN;
6169 +
6170         /*
6171          * /proc/pid/oom_adj is provided for legacy purposes, ask users to use
6172          * /proc/pid/oom_score_adj instead.
6173 @@ -1528,6 +1534,8 @@ struct inode *proc_pid_make_inode(struct
6174                 inode->i_gid = cred->egid;
6175                 rcu_read_unlock();
6176         }
6177 +       /* procfs is xid tagged */
6178 +       i_tag_write(inode, (tag_t)vx_task_xid(task));
6179         security_task_to_inode(task, inode);
6180  
6181  out:
6182 @@ -1573,6 +1581,8 @@ int pid_getattr(struct vfsmount *mnt, st
6183  
6184  /* dentry stuff */
6185  
6186 +static unsigned name_to_int(struct dentry *dentry);
6187 +
6188  /*
6189   *     Exceptional case: normally we are not allowed to unhash a busy
6190   * directory. In this case, however, we can do it - no aliasing problems
6191 @@ -1601,6 +1611,12 @@ int pid_revalidate(struct dentry *dentry
6192         task = get_proc_task(inode);
6193  
6194         if (task) {
6195 +               unsigned pid = name_to_int(dentry);
6196 +
6197 +               if (pid != ~0U && pid != vx_map_pid(task->pid)) {
6198 +                       put_task_struct(task);
6199 +                       goto drop;
6200 +               }
6201                 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
6202                     task_dumpable(task)) {
6203                         rcu_read_lock();
6204 @@ -1617,6 +1633,7 @@ int pid_revalidate(struct dentry *dentry
6205                 put_task_struct(task);
6206                 return 1;
6207         }
6208 +drop:
6209         d_drop(dentry);
6210         return 0;
6211  }
6212 @@ -2059,6 +2076,13 @@ static struct dentry *proc_pident_lookup
6213         if (!task)
6214                 goto out_no_task;
6215  
6216 +       /* TODO: maybe we can come up with a generic approach? */
6217 +       if (task_vx_flags(task, VXF_HIDE_VINFO, 0) &&
6218 +               (dentry->d_name.len == 5) &&
6219 +               (!memcmp(dentry->d_name.name, "vinfo", 5) ||
6220 +               !memcmp(dentry->d_name.name, "ninfo", 5)))
6221 +               goto out;
6222 +
6223         /*
6224          * Yes, it does not scale. And it should not. Don't add
6225          * new entries into /proc/<tgid>/ without very good reasons.
6226 @@ -2493,6 +2517,9 @@ static int proc_pid_personality(struct s
6227  static const struct file_operations proc_task_operations;
6228  static const struct inode_operations proc_task_inode_operations;
6229  
6230 +extern int proc_pid_vx_info(struct task_struct *, char *);
6231 +extern int proc_pid_nx_info(struct task_struct *, char *);
6232 +
6233  static const struct pid_entry tgid_base_stuff[] = {
6234         DIR("task",       S_IRUGO|S_IXUGO, proc_task_inode_operations, proc_task_operations),
6235         DIR("fd",         S_IRUSR|S_IXUSR, proc_fd_inode_operations, proc_fd_operations),
6236 @@ -2559,6 +2586,8 @@ static const struct pid_entry tgid_base_
6237  #ifdef CONFIG_CGROUPS
6238         REG("cgroup",  S_IRUGO, proc_cgroup_operations),
6239  #endif
6240 +       INF("vinfo",      S_IRUGO, proc_pid_vx_info),
6241 +       INF("ninfo",      S_IRUGO, proc_pid_nx_info),
6242         INF("oom_score",  S_IRUGO, proc_oom_score),
6243         REG("oom_adj",    S_IRUGO|S_IWUSR, proc_oom_adj_operations),
6244         REG("oom_score_adj", S_IRUGO|S_IWUSR, proc_oom_score_adj_operations),
6245 @@ -2583,6 +2612,7 @@ static const struct pid_entry tgid_base_
6246         REG("gid_map",    S_IRUGO|S_IWUSR, proc_gid_map_operations),
6247         REG("projid_map", S_IRUGO|S_IWUSR, proc_projid_map_operations),
6248  #endif
6249 +       ONE("nsproxy",  S_IRUGO, proc_pid_nsproxy),
6250  };
6251  
6252  static int proc_tgid_base_readdir(struct file * filp,
6253 @@ -2770,7 +2800,7 @@ retry:
6254         iter.task = NULL;
6255         pid = find_ge_pid(iter.tgid, ns);
6256         if (pid) {
6257 -               iter.tgid = pid_nr_ns(pid, ns);
6258 +               iter.tgid = pid_unmapped_nr_ns(pid, ns);
6259                 iter.task = pid_task(pid, PIDTYPE_PID);
6260                 /* What we to know is if the pid we have find is the
6261                  * pid of a thread_group_leader.  Testing for task
6262 @@ -2800,7 +2830,7 @@ static int proc_pid_fill_cache(struct fi
6263         struct tgid_iter iter)
6264  {
6265         char name[PROC_NUMBUF];
6266 -       int len = snprintf(name, sizeof(name), "%d", iter.tgid);
6267 +       int len = snprintf(name, sizeof(name), "%d", vx_map_tgid(iter.tgid));
6268         return proc_fill_cache(filp, dirent, filldir, name, len,
6269                                 proc_pid_instantiate, iter.task, NULL);
6270  }
6271 @@ -2833,6 +2863,8 @@ int proc_pid_readdir(struct file * filp,
6272                         __filldir = fake_filldir;
6273  
6274                 filp->f_pos = iter.tgid + TGID_OFFSET;
6275 +               if (!vx_proc_task_visible(iter.task))
6276 +                       continue;
6277                 if (proc_pid_fill_cache(filp, dirent, __filldir, iter) < 0) {
6278                         put_task_struct(iter.task);
6279                         goto out;
6280 @@ -2993,6 +3025,8 @@ static struct dentry *proc_task_lookup(s
6281         tid = name_to_int(dentry);
6282         if (tid == ~0U)
6283                 goto out;
6284 +       if (vx_current_initpid(tid))
6285 +               goto out;
6286  
6287         ns = dentry->d_sb->s_fs_info;
6288         rcu_read_lock();
6289 diff -NurpP --minimal linux-3.9.4/fs/proc/generic.c linux-3.9.4-vs2.3.6.2/fs/proc/generic.c
6290 --- linux-3.9.4/fs/proc/generic.c       2013-05-31 13:45:25.000000000 +0000
6291 +++ linux-3.9.4-vs2.3.6.2/fs/proc/generic.c     2013-05-31 16:13:42.000000000 +0000
6292 @@ -23,6 +23,7 @@
6293  #include <linux/bitops.h>
6294  #include <linux/spinlock.h>
6295  #include <linux/completion.h>
6296 +#include <linux/vserver/inode.h>
6297  #include <asm/uaccess.h>
6298  
6299  #include "internal.h"
6300 @@ -409,6 +410,8 @@ struct dentry *proc_lookup_de(struct pro
6301         for (de = de->subdir; de ; de = de->next) {
6302                 if (de->namelen != dentry->d_name.len)
6303                         continue;
6304 +               if (!vx_hide_check(0, de->vx_flags))
6305 +                       continue;
6306                 if (!memcmp(dentry->d_name.name, de->name, de->namelen)) {
6307                         pde_get(de);
6308                         spin_unlock(&proc_subdir_lock);
6309 @@ -417,6 +420,8 @@ struct dentry *proc_lookup_de(struct pro
6310                                 return ERR_PTR(-ENOMEM);
6311                         d_set_d_op(dentry, &proc_dentry_operations);
6312                         d_add(dentry, inode);
6313 +                       /* generic proc entries belong to the host */
6314 +                       i_tag_write(inode, 0);
6315                         return NULL;
6316                 }
6317         }
6318 @@ -485,6 +490,8 @@ int proc_readdir_de(struct proc_dir_entr
6319  
6320                                 /* filldir passes info to user space */
6321                                 pde_get(de);
6322 +                               if (!vx_hide_check(0, de->vx_flags))
6323 +                                       goto skip;
6324                                 spin_unlock(&proc_subdir_lock);
6325                                 if (filldir(dirent, de->name, de->namelen, filp->f_pos,
6326                                             de->low_ino, de->mode >> 12) < 0) {
6327 @@ -492,6 +499,7 @@ int proc_readdir_de(struct proc_dir_entr
6328                                         goto out;
6329                                 }
6330                                 spin_lock(&proc_subdir_lock);
6331 +                       skip:
6332                                 filp->f_pos++;
6333                                 next = de->next;
6334                                 pde_put(de);
6335 @@ -603,6 +611,7 @@ static struct proc_dir_entry *__proc_cre
6336         ent->namelen = len;
6337         ent->mode = mode;
6338         ent->nlink = nlink;
6339 +       ent->vx_flags = IATTR_PROC_DEFAULT;
6340         atomic_set(&ent->count, 1);
6341         spin_lock_init(&ent->pde_unload_lock);
6342         INIT_LIST_HEAD(&ent->pde_openers);
6343 @@ -626,7 +635,8 @@ struct proc_dir_entry *proc_symlink(cons
6344                                 kfree(ent->data);
6345                                 kfree(ent);
6346                                 ent = NULL;
6347 -                       }
6348 +                       } else
6349 +                               ent->vx_flags = IATTR_PROC_SYMLINK;
6350                 } else {
6351                         kfree(ent);
6352                         ent = NULL;
6353 diff -NurpP --minimal linux-3.9.4/fs/proc/inode.c linux-3.9.4-vs2.3.6.2/fs/proc/inode.c
6354 --- linux-3.9.4/fs/proc/inode.c 2013-05-31 13:45:25.000000000 +0000
6355 +++ linux-3.9.4-vs2.3.6.2/fs/proc/inode.c       2013-05-31 14:47:11.000000000 +0000
6356 @@ -458,6 +458,8 @@ struct inode *proc_get_inode(struct supe
6357                         inode->i_uid = de->uid;
6358                         inode->i_gid = de->gid;
6359                 }
6360 +               if (de->vx_flags)
6361 +                       PROC_I(inode)->vx_flags = de->vx_flags;
6362                 if (de->size)
6363                         inode->i_size = de->size;
6364                 if (de->nlink)
6365 diff -NurpP --minimal linux-3.9.4/fs/proc/internal.h linux-3.9.4-vs2.3.6.2/fs/proc/internal.h
6366 --- linux-3.9.4/fs/proc/internal.h      2013-05-31 13:45:25.000000000 +0000
6367 +++ linux-3.9.4-vs2.3.6.2/fs/proc/internal.h    2013-05-31 16:04:34.000000000 +0000
6368 @@ -12,6 +12,8 @@
6369  #include <linux/sched.h>
6370  #include <linux/proc_fs.h>
6371  #include <linux/binfmts.h>
6372 +#include <linux/vs_pid.h>
6373 +
6374  struct  ctl_table_header;
6375  struct  mempolicy;
6376  
6377 @@ -56,6 +58,9 @@ extern int proc_pid_status(struct seq_fi
6378                                 struct pid *pid, struct task_struct *task);
6379  extern int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
6380                                 struct pid *pid, struct task_struct *task);
6381 +extern int proc_pid_nsproxy(struct seq_file *m, struct pid_namespace *ns,
6382 +                               struct pid *pid, struct task_struct *task);
6383 +
6384  extern loff_t mem_lseek(struct file *file, loff_t offset, int orig);
6385  
6386  extern const struct file_operations proc_tid_children_operations;
6387 @@ -89,11 +94,16 @@ static inline struct pid *proc_pid(struc
6388         return PROC_I(inode)->pid;
6389  }
6390  
6391 -static inline struct task_struct *get_proc_task(struct inode *inode)
6392 +static inline struct task_struct *get_proc_task_real(struct inode *inode)
6393  {
6394         return get_pid_task(proc_pid(inode), PIDTYPE_PID);
6395  }
6396  
6397 +static inline struct task_struct *get_proc_task(struct inode *inode)
6398 +{
6399 +       return vx_get_proc_task(inode, proc_pid(inode));
6400 +}
6401 +
6402  static inline int proc_fd(struct inode *inode)
6403  {
6404         return PROC_I(inode)->fd;
6405 diff -NurpP --minimal linux-3.9.4/fs/proc/loadavg.c linux-3.9.4-vs2.3.6.2/fs/proc/loadavg.c
6406 --- linux-3.9.4/fs/proc/loadavg.c       2012-12-11 03:30:57.000000000 +0000
6407 +++ linux-3.9.4-vs2.3.6.2/fs/proc/loadavg.c     2013-05-31 14:47:11.000000000 +0000
6408 @@ -12,15 +12,27 @@
6409  
6410  static int loadavg_proc_show(struct seq_file *m, void *v)
6411  {
6412 +       unsigned long running;
6413 +       unsigned int threads;
6414         unsigned long avnrun[3];
6415  
6416         get_avenrun(avnrun, FIXED_1/200, 0);
6417  
6418 +       if (vx_flags(VXF_VIRT_LOAD, 0)) {
6419 +               struct vx_info *vxi = current_vx_info();
6420 +
6421 +               running = atomic_read(&vxi->cvirt.nr_running);
6422 +               threads = atomic_read(&vxi->cvirt.nr_threads);
6423 +       } else {
6424 +               running = nr_running();
6425 +               threads = nr_threads;
6426 +       }
6427 +
6428         seq_printf(m, "%lu.%02lu %lu.%02lu %lu.%02lu %ld/%d %d\n",
6429                 LOAD_INT(avnrun[0]), LOAD_FRAC(avnrun[0]),
6430                 LOAD_INT(avnrun[1]), LOAD_FRAC(avnrun[1]),
6431                 LOAD_INT(avnrun[2]), LOAD_FRAC(avnrun[2]),
6432 -               nr_running(), nr_threads,
6433 +               running, threads,
6434                 task_active_pid_ns(current)->last_pid);
6435         return 0;
6436  }
6437 diff -NurpP --minimal linux-3.9.4/fs/proc/meminfo.c linux-3.9.4-vs2.3.6.2/fs/proc/meminfo.c
6438 --- linux-3.9.4/fs/proc/meminfo.c       2013-05-31 13:45:25.000000000 +0000
6439 +++ linux-3.9.4-vs2.3.6.2/fs/proc/meminfo.c     2013-05-31 16:05:39.000000000 +0000
6440 @@ -39,7 +39,8 @@ static int meminfo_proc_show(struct seq_
6441         allowed = ((totalram_pages - hugetlb_total_pages())
6442                 * sysctl_overcommit_ratio / 100) + total_swap_pages;
6443  
6444 -       cached = global_page_state(NR_FILE_PAGES) -
6445 +       cached = vx_flags(VXF_VIRT_MEM, 0) ?
6446 +               vx_vsi_cached(&i) : global_page_state(NR_FILE_PAGES) -
6447                         total_swapcache_pages() - i.bufferram;
6448         if (cached < 0)
6449                 cached = 0;
6450 diff -NurpP --minimal linux-3.9.4/fs/proc/root.c linux-3.9.4-vs2.3.6.2/fs/proc/root.c
6451 --- linux-3.9.4/fs/proc/root.c  2013-05-31 13:45:25.000000000 +0000
6452 +++ linux-3.9.4-vs2.3.6.2/fs/proc/root.c        2013-05-31 14:47:11.000000000 +0000
6453 @@ -20,9 +20,14 @@
6454  #include <linux/mount.h>
6455  #include <linux/pid_namespace.h>
6456  #include <linux/parser.h>
6457 +#include <linux/vserver/inode.h>
6458  
6459  #include "internal.h"
6460  
6461 +struct proc_dir_entry *proc_virtual;
6462 +
6463 +extern void proc_vx_init(void);
6464 +
6465  static int proc_test_super(struct super_block *sb, void *data)
6466  {
6467         return sb->s_fs_info == data;
6468 @@ -182,6 +187,7 @@ void __init proc_root_init(void)
6469  #endif
6470         proc_mkdir("bus", NULL);
6471         proc_sys_init();
6472 +       proc_vx_init();
6473  }
6474  
6475  static int proc_root_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat
6476 @@ -248,6 +254,7 @@ struct proc_dir_entry proc_root = {
6477         .proc_iops      = &proc_root_inode_operations, 
6478         .proc_fops      = &proc_root_operations,
6479         .parent         = &proc_root,
6480 +       .vx_flags       = IATTR_ADMIN | IATTR_WATCH,
6481         .name           = "/proc",
6482  };
6483  
6484 diff -NurpP --minimal linux-3.9.4/fs/proc/self.c linux-3.9.4-vs2.3.6.2/fs/proc/self.c
6485 --- linux-3.9.4/fs/proc/self.c  2013-02-19 13:58:49.000000000 +0000
6486 +++ linux-3.9.4-vs2.3.6.2/fs/proc/self.c        2013-05-31 20:57:54.000000000 +0000
6487 @@ -1,6 +1,7 @@
6488  #include <linux/proc_fs.h>
6489  #include <linux/sched.h>
6490  #include <linux/namei.h>
6491 +#include <linux/vserver/inode.h>
6492  
6493  /*
6494   * /proc/self:
6495 @@ -56,4 +57,5 @@ void __init proc_self_init(void)
6496         mode = S_IFLNK | S_IRWXUGO;
6497         proc_self_symlink = proc_create("self", mode, NULL, NULL );
6498         proc_self_symlink->proc_iops = &proc_self_inode_operations;
6499 +       proc_self_symlink->vx_flags = IATTR_PROC_SYMLINK;
6500  }
6501 diff -NurpP --minimal linux-3.9.4/fs/proc/stat.c linux-3.9.4-vs2.3.6.2/fs/proc/stat.c
6502 --- linux-3.9.4/fs/proc/stat.c  2012-12-11 03:30:57.000000000 +0000
6503 +++ linux-3.9.4-vs2.3.6.2/fs/proc/stat.c        2013-05-31 14:47:11.000000000 +0000
6504 @@ -9,8 +9,10 @@
6505  #include <linux/slab.h>
6506  #include <linux/time.h>
6507  #include <linux/irqnr.h>
6508 +#include <linux/vserver/cvirt.h>
6509  #include <asm/cputime.h>
6510  #include <linux/tick.h>
6511 +#include <linux/cpuset.h>
6512  
6513  #ifndef arch_irq_stat_cpu
6514  #define arch_irq_stat_cpu(cpu) 0
6515 @@ -87,14 +89,26 @@ static int show_stat(struct seq_file *p,
6516         u64 sum_softirq = 0;
6517         unsigned int per_softirq_sums[NR_SOFTIRQS] = {0};
6518         struct timespec boottime;
6519 +       cpumask_var_t cpus_allowed;
6520 +       bool virt_cpu = vx_flags(VXF_VIRT_CPU, 0);
6521  
6522         user = nice = system = idle = iowait =
6523                 irq = softirq = steal = 0;
6524         guest = guest_nice = 0;
6525         getboottime(&boottime);
6526 +
6527 +       if (vx_flags(VXF_VIRT_UPTIME, 0))
6528 +               vx_vsi_boottime(&boottime);
6529 +
6530 +       if (virt_cpu)
6531 +               cpuset_cpus_allowed(current, cpus_allowed);
6532 +
6533         jif = boottime.tv_sec;
6534  
6535         for_each_possible_cpu(i) {
6536 +               if (virt_cpu && !cpumask_test_cpu(i, cpus_allowed))
6537 +                       continue;
6538 +
6539                 user += kcpustat_cpu(i).cpustat[CPUTIME_USER];
6540                 nice += kcpustat_cpu(i).cpustat[CPUTIME_NICE];
6541                 system += kcpustat_cpu(i).cpustat[CPUTIME_SYSTEM];
6542 @@ -131,6 +145,9 @@ static int show_stat(struct seq_file *p,
6543         seq_putc(p, '\n');
6544  
6545         for_each_online_cpu(i) {
6546 +               if (virt_cpu && !cpumask_test_cpu(i, cpus_allowed))
6547 +                       continue;
6548 +
6549                 /* Copy values here to work around gcc-2.95.3, gcc-2.96 */
6550                 user = kcpustat_cpu(i).cpustat[CPUTIME_USER];
6551                 nice = kcpustat_cpu(i).cpustat[CPUTIME_NICE];
6552 diff -NurpP --minimal linux-3.9.4/fs/proc/uptime.c linux-3.9.4-vs2.3.6.2/fs/proc/uptime.c
6553 --- linux-3.9.4/fs/proc/uptime.c        2012-12-11 03:30:57.000000000 +0000
6554 +++ linux-3.9.4-vs2.3.6.2/fs/proc/uptime.c      2013-05-31 14:47:11.000000000 +0000
6555 @@ -5,6 +5,7 @@
6556  #include <linux/seq_file.h>
6557  #include <linux/time.h>
6558  #include <linux/kernel_stat.h>
6559 +#include <linux/vserver/cvirt.h>
6560  #include <asm/cputime.h>
6561  
6562  static int uptime_proc_show(struct seq_file *m, void *v)
6563 @@ -25,6 +26,10 @@ static int uptime_proc_show(struct seq_f
6564         nsec = cputime64_to_jiffies64(idletime) * TICK_NSEC;
6565         idle.tv_sec = div_u64_rem(nsec, NSEC_PER_SEC, &rem);
6566         idle.tv_nsec = rem;
6567 +
6568 +       if (vx_flags(VXF_VIRT_UPTIME, 0))
6569 +               vx_vsi_uptime(&uptime, &idle);
6570 +
6571         seq_printf(m, "%lu.%02lu %lu.%02lu\n",
6572                         (unsigned long) uptime.tv_sec,
6573                         (uptime.tv_nsec / (NSEC_PER_SEC / 100)),
6574 diff -NurpP --minimal linux-3.9.4/fs/proc_namespace.c linux-3.9.4-vs2.3.6.2/fs/proc_namespace.c
6575 --- linux-3.9.4/fs/proc_namespace.c     2012-12-11 03:30:57.000000000 +0000
6576 +++ linux-3.9.4-vs2.3.6.2/fs/proc_namespace.c   2013-05-31 17:17:53.000000000 +0000
6577 @@ -44,6 +44,8 @@ static int show_sb_opts(struct seq_file
6578                 { MS_SYNCHRONOUS, ",sync" },
6579                 { MS_DIRSYNC, ",dirsync" },
6580                 { MS_MANDLOCK, ",mand" },
6581 +               { MS_TAGGED, ",tag" },
6582 +               { MS_NOTAGCHECK, ",notagcheck" },
6583                 { 0, NULL }
6584         };
6585         const struct proc_fs_info *fs_infop;
6586 @@ -80,6 +82,40 @@ static inline void mangle(struct seq_fil
6587         seq_escape(m, s, " \t\n\\");
6588  }
6589  
6590 +#ifdef CONFIG_VSERVER_EXTRA_MNT_CHECK
6591 +
6592 +static int mnt_is_reachable(struct vfsmount *vfsmnt)
6593 +{
6594 +       struct path root;
6595 +       struct dentry *point;
6596 +       struct mount *mnt = real_mount(vfsmnt);
6597 +       struct mount *root_mnt;
6598 +       int ret;
6599 +
6600 +       if (mnt == mnt->mnt_ns->root)
6601 +               return 1;
6602 +
6603 +       br_read_lock(&vfsmount_lock);
6604 +       root = current->fs->root;
6605 +       root_mnt = real_mount(root.mnt);
6606 +       point = root.dentry;
6607 +
6608 +       while ((mnt != mnt->mnt_parent) && (mnt != root_mnt)) {
6609 +               point = mnt->mnt_mountpoint;
6610 +               mnt = mnt->mnt_parent;
6611 +       }
6612 +
6613 +       ret = (mnt == root_mnt) && is_subdir(point, root.dentry);
6614 +
6615 +       br_read_unlock(&vfsmount_lock);
6616 +
6617 +       return ret;
6618 +}
6619 +
6620 +#else
6621 +#define        mnt_is_reachable(v)     (1)
6622 +#endif
6623 +
6624  static void show_type(struct seq_file *m, struct super_block *sb)
6625  {
6626         mangle(m, sb->s_type->name);
6627 @@ -96,6 +132,17 @@ static int show_vfsmnt(struct seq_file *
6628         struct path mnt_path = { .dentry = mnt->mnt_root, .mnt = mnt };
6629         struct super_block *sb = mnt_path.dentry->d_sb;
6630  
6631 +       if (vx_flags(VXF_HIDE_MOUNT, 0))
6632 +               return SEQ_SKIP;
6633 +       if (!mnt_is_reachable(mnt) && !vx_check(0, VS_WATCH_P))
6634 +               return SEQ_SKIP;
6635 +
6636 +       if (!vx_check(0, VS_ADMIN|VS_WATCH) &&
6637 +               mnt == current->fs->root.mnt) {
6638 +               seq_puts(m, "/dev/root / ");
6639 +               goto type;
6640 +       }
6641 +
6642         if (sb->s_op->show_devname) {
6643                 err = sb->s_op->show_devname(m, mnt_path.dentry);
6644                 if (err)
6645 @@ -106,6 +153,7 @@ static int show_vfsmnt(struct seq_file *
6646         seq_putc(m, ' ');
6647         seq_path(m, &mnt_path, " \t\n\\");
6648         seq_putc(m, ' ');
6649 +type:
6650         show_type(m, sb);
6651         seq_puts(m, __mnt_is_readonly(mnt) ? " ro" : " rw");
6652         err = show_sb_opts(m, sb);
6653 @@ -128,6 +176,11 @@ static int show_mountinfo(struct seq_fil
6654         struct path root = p->root;
6655         int err = 0;
6656  
6657 +       if (vx_flags(VXF_HIDE_MOUNT, 0))
6658 +               return SEQ_SKIP;
6659 +       if (!mnt_is_reachable(mnt) && !vx_check(0, VS_WATCH_P))
6660 +               return SEQ_SKIP;
6661 +
6662         seq_printf(m, "%i %i %u:%u ", r->mnt_id, r->mnt_parent->mnt_id,
6663                    MAJOR(sb->s_dev), MINOR(sb->s_dev));
6664         if (sb->s_op->show_path)
6665 @@ -187,6 +240,17 @@ static int show_vfsstat(struct seq_file
6666         struct super_block *sb = mnt_path.dentry->d_sb;
6667         int err = 0;
6668  
6669 +       if (vx_flags(VXF_HIDE_MOUNT, 0))
6670 +               return SEQ_SKIP;
6671 +       if (!mnt_is_reachable(mnt) && !vx_check(0, VS_WATCH_P))
6672 +               return SEQ_SKIP;
6673 +
6674 +       if (!vx_check(0, VS_ADMIN|VS_WATCH) &&
6675 +               mnt == current->fs->root.mnt) {
6676 +               seq_puts(m, "device /dev/root mounted on / ");
6677 +               goto type;
6678 +       }
6679 +
6680         /* device */
6681         if (sb->s_op->show_devname) {
6682                 seq_puts(m, "device ");
6683 @@ -203,7 +267,7 @@ static int show_vfsstat(struct seq_file
6684         seq_puts(m, " mounted on ");
6685         seq_path(m, &mnt_path, " \t\n\\");
6686         seq_putc(m, ' ');
6687 -
6688 +type:
6689         /* file system type */
6690         seq_puts(m, "with fstype ");
6691         show_type(m, sb);
6692 diff -NurpP --minimal linux-3.9.4/fs/quota/dquot.c linux-3.9.4-vs2.3.6.2/fs/quota/dquot.c
6693 --- linux-3.9.4/fs/quota/dquot.c        2013-05-31 13:45:25.000000000 +0000
6694 +++ linux-3.9.4-vs2.3.6.2/fs/quota/dquot.c      2013-05-31 14:47:11.000000000 +0000
6695 @@ -1585,6 +1585,9 @@ int __dquot_alloc_space(struct inode *in
6696         struct dquot **dquots = inode->i_dquot;
6697         int reserve = flags & DQUOT_SPACE_RESERVE;
6698  
6699 +       if ((ret = dl_alloc_space(inode, number)))
6700 +               return ret;
6701 +
6702         /*
6703          * First test before acquiring mutex - solves deadlocks when we
6704          * re-enter the quota code and are already holding the mutex
6705 @@ -1640,6 +1643,9 @@ int dquot_alloc_inode(const struct inode
6706         struct dquot_warn warn[MAXQUOTAS];
6707         struct dquot * const *dquots = inode->i_dquot;
6708  
6709 +       if ((ret = dl_alloc_inode(inode)))
6710 +               return ret;
6711 +
6712         /* First test before acquiring mutex - solves deadlocks when we
6713           * re-enter the quota code and are already holding the mutex */
6714         if (!dquot_active(inode))
6715 @@ -1711,6 +1717,8 @@ void __dquot_free_space(struct inode *in
6716         struct dquot **dquots = inode->i_dquot;
6717         int reserve = flags & DQUOT_SPACE_RESERVE;
6718  
6719 +       dl_free_space(inode, number);
6720 +
6721         /* First test before acquiring mutex - solves deadlocks when we
6722           * re-enter the quota code and are already holding the mutex */
6723         if (!dquot_active(inode)) {
6724 @@ -1755,6 +1763,8 @@ void dquot_free_inode(const struct inode
6725         struct dquot_warn warn[MAXQUOTAS];
6726         struct dquot * const *dquots = inode->i_dquot;
6727  
6728 +       dl_free_inode(inode);
6729 +
6730         /* First test before acquiring mutex - solves deadlocks when we
6731           * re-enter the quota code and are already holding the mutex */
6732         if (!dquot_active(inode))
6733 diff -NurpP --minimal linux-3.9.4/fs/quota/quota.c linux-3.9.4-vs2.3.6.2/fs/quota/quota.c
6734 --- linux-3.9.4/fs/quota/quota.c        2013-02-19 13:58:49.000000000 +0000
6735 +++ linux-3.9.4-vs2.3.6.2/fs/quota/quota.c      2013-05-31 14:47:11.000000000 +0000
6736 @@ -8,6 +8,7 @@
6737  #include <linux/fs.h>
6738  #include <linux/namei.h>
6739  #include <linux/slab.h>
6740 +#include <linux/vs_context.h>
6741  #include <asm/current.h>
6742  #include <linux/uaccess.h>
6743  #include <linux/kernel.h>
6744 @@ -37,7 +38,7 @@ static int check_quotactl_permission(str
6745                         break;
6746                 /*FALLTHROUGH*/
6747         default:
6748 -               if (!capable(CAP_SYS_ADMIN))
6749 +               if (!vx_capable(CAP_SYS_ADMIN, VXC_QUOTA_CTL))
6750                         return -EPERM;
6751         }
6752  
6753 @@ -309,6 +310,46 @@ static int do_quotactl(struct super_bloc
6754  
6755  #ifdef CONFIG_BLOCK
6756  
6757 +#if defined(CONFIG_BLK_DEV_VROOT) || defined(CONFIG_BLK_DEV_VROOT_MODULE)
6758 +
6759 +#include <linux/vroot.h>
6760 +#include <linux/major.h>
6761 +#include <linux/module.h>
6762 +#include <linux/kallsyms.h>
6763 +#include <linux/vserver/debug.h>
6764 +
6765 +static vroot_grb_func *vroot_get_real_bdev = NULL;
6766 +
6767 +static DEFINE_SPINLOCK(vroot_grb_lock);
6768 +
6769 +int register_vroot_grb(vroot_grb_func *func) {
6770 +       int ret = -EBUSY;
6771 +
6772 +       spin_lock(&vroot_grb_lock);
6773 +       if (!vroot_get_real_bdev) {
6774 +               vroot_get_real_bdev = func;
6775 +               ret = 0;
6776 +       }
6777 +       spin_unlock(&vroot_grb_lock);
6778 +       return ret;
6779 +}
6780 +EXPORT_SYMBOL(register_vroot_grb);
6781 +
6782 +int unregister_vroot_grb(vroot_grb_func *func) {
6783 +       int ret = -EINVAL;
6784 +
6785 +       spin_lock(&vroot_grb_lock);
6786 +       if (vroot_get_real_bdev) {
6787 +               vroot_get_real_bdev = NULL;
6788 +               ret = 0;
6789 +       }
6790 +       spin_unlock(&vroot_grb_lock);
6791 +       return ret;
6792 +}
6793 +EXPORT_SYMBOL(unregister_vroot_grb);
6794 +
6795 +#endif
6796 +
6797  /* Return 1 if 'cmd' will block on frozen filesystem */
6798  static int quotactl_cmd_write(int cmd)
6799  {
6800 @@ -343,6 +384,22 @@ static struct super_block *quotactl_bloc
6801         putname(tmp);
6802         if (IS_ERR(bdev))
6803                 return ERR_CAST(bdev);
6804 +#if defined(CONFIG_BLK_DEV_VROOT) || defined(CONFIG_BLK_DEV_VROOT_MODULE)
6805 +       if (bdev && bdev->bd_inode &&
6806 +               imajor(bdev->bd_inode) == VROOT_MAJOR) {
6807 +               struct block_device *bdnew = (void *)-EINVAL;
6808 +
6809 +               if (vroot_get_real_bdev)
6810 +                       bdnew = vroot_get_real_bdev(bdev);
6811 +               else
6812 +                       vxdprintk(VXD_CBIT(misc, 0),
6813 +                                       "vroot_get_real_bdev not set");
6814 +               bdput(bdev);
6815 +               if (IS_ERR(bdnew))
6816 +                       return ERR_PTR(PTR_ERR(bdnew));
6817 +               bdev = bdnew;
6818 +       }
6819 +#endif
6820         if (quotactl_cmd_write(cmd))
6821                 sb = get_super_thawed(bdev);
6822         else
6823 diff -NurpP --minimal linux-3.9.4/fs/stat.c linux-3.9.4-vs2.3.6.2/fs/stat.c
6824 --- linux-3.9.4/fs/stat.c       2013-05-31 13:45:25.000000000 +0000
6825 +++ linux-3.9.4-vs2.3.6.2/fs/stat.c     2013-06-01 08:53:01.000000000 +0000
6826 @@ -26,6 +26,7 @@ void generic_fillattr(struct inode *inod
6827         stat->nlink = inode->i_nlink;
6828         stat->uid = inode->i_uid;
6829         stat->gid = inode->i_gid;
6830 +       stat->tag = inode->i_tag;
6831         stat->rdev = inode->i_rdev;
6832         stat->size = i_size_read(inode);
6833         stat->atime = inode->i_atime;
6834 diff -NurpP --minimal linux-3.9.4/fs/statfs.c linux-3.9.4-vs2.3.6.2/fs/statfs.c
6835 --- linux-3.9.4/fs/statfs.c     2013-02-19 13:58:49.000000000 +0000
6836 +++ linux-3.9.4-vs2.3.6.2/fs/statfs.c   2013-05-31 14:47:11.000000000 +0000
6837 @@ -7,6 +7,8 @@
6838  #include <linux/statfs.h>
6839  #include <linux/security.h>
6840  #include <linux/uaccess.h>
6841 +#include <linux/vs_base.h>
6842 +#include <linux/vs_dlimit.h>
6843  #include "internal.h"
6844  
6845  static int flags_by_mnt(int mnt_flags)
6846 @@ -60,6 +62,8 @@ static int statfs_by_dentry(struct dentr
6847         retval = dentry->d_sb->s_op->statfs(dentry, buf);
6848         if (retval == 0 && buf->f_frsize == 0)
6849                 buf->f_frsize = buf->f_bsize;
6850 +       if (!vx_check(0, VS_ADMIN|VS_WATCH))
6851 +               vx_vsi_statfs(dentry->d_sb, buf);
6852         return retval;
6853  }
6854  
6855 diff -NurpP --minimal linux-3.9.4/fs/super.c linux-3.9.4-vs2.3.6.2/fs/super.c
6856 --- linux-3.9.4/fs/super.c      2013-05-31 13:45:25.000000000 +0000
6857 +++ linux-3.9.4-vs2.3.6.2/fs/super.c    2013-05-31 14:47:11.000000000 +0000
6858 @@ -34,6 +34,8 @@
6859  #include <linux/cleancache.h>
6860  #include <linux/fsnotify.h>
6861  #include <linux/lockdep.h>
6862 +#include <linux/magic.h>
6863 +#include <linux/vs_context.h>
6864  #include "internal.h"
6865  
6866  
6867 @@ -1117,6 +1119,13 @@ mount_fs(struct file_system_type *type,
6868         WARN_ON(sb->s_bdi == &default_backing_dev_info);
6869         sb->s_flags |= MS_BORN;
6870  
6871 +       error = -EPERM;
6872 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_BINARY_MOUNT) &&
6873 +               !sb->s_bdev &&
6874 +               (sb->s_magic != PROC_SUPER_MAGIC) &&
6875 +               (sb->s_magic != DEVPTS_SUPER_MAGIC))
6876 +               goto out_sb;
6877 +
6878         error = security_sb_kern_mount(sb, flags, secdata);
6879         if (error)
6880                 goto out_sb;
6881 diff -NurpP --minimal linux-3.9.4/fs/sysfs/mount.c linux-3.9.4-vs2.3.6.2/fs/sysfs/mount.c
6882 --- linux-3.9.4/fs/sysfs/mount.c        2013-05-31 13:45:25.000000000 +0000
6883 +++ linux-3.9.4-vs2.3.6.2/fs/sysfs/mount.c      2013-05-31 14:47:11.000000000 +0000
6884 @@ -48,7 +48,7 @@ static int sysfs_fill_super(struct super
6885  
6886         sb->s_blocksize = PAGE_CACHE_SIZE;
6887         sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
6888 -       sb->s_magic = SYSFS_MAGIC;
6889 +       sb->s_magic = SYSFS_SUPER_MAGIC;
6890         sb->s_op = &sysfs_ops;
6891         sb->s_time_gran = 1;
6892  
6893 diff -NurpP --minimal linux-3.9.4/fs/utimes.c linux-3.9.4-vs2.3.6.2/fs/utimes.c
6894 --- linux-3.9.4/fs/utimes.c     2013-02-19 13:58:49.000000000 +0000
6895 +++ linux-3.9.4-vs2.3.6.2/fs/utimes.c   2013-05-31 22:40:16.000000000 +0000
6896 @@ -8,6 +8,8 @@
6897  #include <linux/stat.h>
6898  #include <linux/utime.h>
6899  #include <linux/syscalls.h>
6900 +#include <linux/mount.h>
6901 +#include <linux/vs_cowbl.h>
6902  #include <asm/uaccess.h>
6903  #include <asm/unistd.h>
6904  
6905 @@ -52,12 +54,18 @@ static int utimes_common(struct path *pa
6906  {
6907         int error;
6908         struct iattr newattrs;
6909 -       struct inode *inode = path->dentry->d_inode;
6910 +       struct inode *inode;
6911 +
6912 +       error = cow_check_and_break(path);
6913 +       if (error)
6914 +               goto out;
6915  
6916         error = mnt_want_write(path->mnt);
6917         if (error)
6918                 goto out;
6919  
6920 +       inode = path->dentry->d_inode;
6921 +
6922         if (times && times[0].tv_nsec == UTIME_NOW &&
6923                      times[1].tv_nsec == UTIME_NOW)
6924                 times = NULL;
6925 diff -NurpP --minimal linux-3.9.4/fs/xattr.c linux-3.9.4-vs2.3.6.2/fs/xattr.c
6926 --- linux-3.9.4/fs/xattr.c      2013-02-19 13:58:49.000000000 +0000
6927 +++ linux-3.9.4-vs2.3.6.2/fs/xattr.c    2013-05-31 14:47:11.000000000 +0000
6928 @@ -21,6 +21,7 @@
6929  #include <linux/audit.h>
6930  #include <linux/vmalloc.h>
6931  #include <linux/posix_acl_xattr.h>
6932 +#include <linux/mount.h>
6933  
6934  #include <asm/uaccess.h>
6935  
6936 @@ -52,7 +53,7 @@ xattr_permission(struct inode *inode, co
6937          * The trusted.* namespace can only be accessed by privileged users.
6938          */
6939         if (!strncmp(name, XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN)) {
6940 -               if (!capable(CAP_SYS_ADMIN))
6941 +               if (!vx_capable(CAP_SYS_ADMIN, VXC_FS_TRUSTED))
6942                         return (mask & MAY_WRITE) ? -EPERM : -ENODATA;
6943                 return 0;
6944         }
6945 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
6946 --- linux-3.9.4/fs/xfs/xfs_dinode.h     2012-12-11 03:30:57.000000000 +0000
6947 +++ linux-3.9.4-vs2.3.6.2/fs/xfs/xfs_dinode.h   2013-05-31 14:47:11.000000000 +0000
6948 @@ -51,7 +51,9 @@ typedef struct xfs_dinode {
6949         __be32          di_nlink;       /* number of links to file */
6950         __be16          di_projid_lo;   /* lower part of owner's project id */
6951         __be16          di_projid_hi;   /* higher part owner's project id */
6952 -       __u8            di_pad[6];      /* unused, zeroed space */
6953 +       __u8            di_pad[2];      /* unused, zeroed space */
6954 +       __be16          di_tag;         /* context tagging */
6955 +       __be16          di_vflags;      /* vserver specific flags */
6956         __be16          di_flushiter;   /* incremented on flush */
6957         xfs_timestamp_t di_atime;       /* time last accessed */
6958         xfs_timestamp_t di_mtime;       /* time last modified */
6959 @@ -184,6 +186,8 @@ static inline void xfs_dinode_put_rdev(s
6960  #define XFS_DIFLAG_EXTSZINHERIT_BIT 12 /* inherit inode extent size */
6961  #define XFS_DIFLAG_NODEFRAG_BIT     13 /* do not reorganize/defragment */
6962  #define XFS_DIFLAG_FILESTREAM_BIT   14  /* use filestream allocator */
6963 +#define XFS_DIFLAG_IXUNLINK_BIT     15 /* Immutable inver on unlink */
6964 +
6965  #define XFS_DIFLAG_REALTIME      (1 << XFS_DIFLAG_REALTIME_BIT)
6966  #define XFS_DIFLAG_PREALLOC      (1 << XFS_DIFLAG_PREALLOC_BIT)
6967  #define XFS_DIFLAG_NEWRTBM       (1 << XFS_DIFLAG_NEWRTBM_BIT)
6968 @@ -199,6 +203,7 @@ static inline void xfs_dinode_put_rdev(s
6969  #define XFS_DIFLAG_EXTSZINHERIT  (1 << XFS_DIFLAG_EXTSZINHERIT_BIT)
6970  #define XFS_DIFLAG_NODEFRAG      (1 << XFS_DIFLAG_NODEFRAG_BIT)
6971  #define XFS_DIFLAG_FILESTREAM    (1 << XFS_DIFLAG_FILESTREAM_BIT)
6972 +#define XFS_DIFLAG_IXUNLINK      (1 << XFS_DIFLAG_IXUNLINK_BIT)
6973  
6974  #ifdef CONFIG_XFS_RT
6975  #define XFS_IS_REALTIME_INODE(ip) ((ip)->i_d.di_flags & XFS_DIFLAG_REALTIME)
6976 @@ -211,6 +216,10 @@ static inline void xfs_dinode_put_rdev(s
6977          XFS_DIFLAG_IMMUTABLE | XFS_DIFLAG_APPEND | XFS_DIFLAG_SYNC | \
6978          XFS_DIFLAG_NOATIME | XFS_DIFLAG_NODUMP | XFS_DIFLAG_RTINHERIT | \
6979          XFS_DIFLAG_PROJINHERIT | XFS_DIFLAG_NOSYMLINKS | XFS_DIFLAG_EXTSIZE | \
6980 -        XFS_DIFLAG_EXTSZINHERIT | XFS_DIFLAG_NODEFRAG | XFS_DIFLAG_FILESTREAM)
6981 +        XFS_DIFLAG_EXTSZINHERIT | XFS_DIFLAG_NODEFRAG | XFS_DIFLAG_FILESTREAM | \
6982 +        XFS_DIFLAG_IXUNLINK)
6983 +
6984 +#define XFS_DIVFLAG_BARRIER    0x01
6985 +#define XFS_DIVFLAG_COW                0x02
6986  
6987  #endif /* __XFS_DINODE_H__ */
6988 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
6989 --- linux-3.9.4/fs/xfs/xfs_fs.h 2013-02-19 13:58:49.000000000 +0000
6990 +++ linux-3.9.4-vs2.3.6.2/fs/xfs/xfs_fs.h       2013-05-31 14:47:11.000000000 +0000
6991 @@ -67,6 +67,9 @@ struct fsxattr {
6992  #define XFS_XFLAG_EXTSZINHERIT 0x00001000      /* inherit inode extent size */
6993  #define XFS_XFLAG_NODEFRAG     0x00002000      /* do not defragment */
6994  #define XFS_XFLAG_FILESTREAM   0x00004000      /* use filestream allocator */
6995 +#define XFS_XFLAG_IXUNLINK     0x00008000      /* immutable invert on unlink */
6996 +#define XFS_XFLAG_BARRIER      0x10000000      /* chroot() barrier */
6997 +#define XFS_XFLAG_COW          0x20000000      /* copy on write mark */
6998  #define XFS_XFLAG_HASATTR      0x80000000      /* no DIFLAG for this   */
6999  
7000  /*
7001 @@ -303,7 +306,8 @@ typedef struct xfs_bstat {
7002  #define        bs_projid       bs_projid_lo    /* (previously just bs_projid)  */
7003         __u16           bs_forkoff;     /* inode fork offset in bytes   */
7004         __u16           bs_projid_hi;   /* higher part of project id    */
7005 -       unsigned char   bs_pad[10];     /* pad space, unused            */
7006 +       unsigned char   bs_pad[8];      /* pad space, unused            */
7007 +       __u16           bs_tag;         /* context tagging              */
7008         __u32           bs_dmevmask;    /* DMIG event mask              */
7009         __u16           bs_dmstate;     /* DMIG state info              */
7010         __u16           bs_aextents;    /* attribute number of extents  */
7011 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
7012 --- linux-3.9.4/fs/xfs/xfs_ialloc.c     2013-05-31 13:45:25.000000000 +0000
7013 +++ linux-3.9.4-vs2.3.6.2/fs/xfs/xfs_ialloc.c   2013-05-31 14:47:11.000000000 +0000
7014 @@ -37,7 +37,6 @@
7015  #include "xfs_error.h"
7016  #include "xfs_bmap.h"
7017  
7018 -
7019  /*
7020   * Allocation group level functions.
7021   */
7022 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
7023 --- linux-3.9.4/fs/xfs/xfs_inode.c      2013-05-31 13:45:25.000000000 +0000
7024 +++ linux-3.9.4-vs2.3.6.2/fs/xfs/xfs_inode.c    2013-05-31 14:47:11.000000000 +0000
7025 @@ -16,6 +16,7 @@
7026   * Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
7027   */
7028  #include <linux/log2.h>
7029 +#include <linux/vs_tag.h>
7030  
7031  #include "xfs.h"
7032  #include "xfs_fs.h"
7033 @@ -835,15 +836,25 @@ xfs_iformat_btree(
7034  STATIC void
7035  xfs_dinode_from_disk(
7036         xfs_icdinode_t          *to,
7037 -       xfs_dinode_t            *from)
7038 +       xfs_dinode_t            *from,
7039 +       int                     tagged)
7040  {
7041 +       uint32_t uid, gid, tag;
7042 +
7043         to->di_magic = be16_to_cpu(from->di_magic);
7044         to->di_mode = be16_to_cpu(from->di_mode);
7045         to->di_version = from ->di_version;
7046         to->di_format = from->di_format;
7047         to->di_onlink = be16_to_cpu(from->di_onlink);
7048 -       to->di_uid = be32_to_cpu(from->di_uid);
7049 -       to->di_gid = be32_to_cpu(from->di_gid);
7050 +
7051 +       uid = be32_to_cpu(from->di_uid);
7052 +       gid = be32_to_cpu(from->di_gid);
7053 +       tag = be16_to_cpu(from->di_tag);
7054 +
7055 +       to->di_uid = INOTAG_UID(tagged, uid, gid);
7056 +       to->di_gid = INOTAG_GID(tagged, uid, gid);
7057 +       to->di_tag = INOTAG_TAG(tagged, uid, gid, tag);
7058 +
7059         to->di_nlink = be32_to_cpu(from->di_nlink);
7060         to->di_projid_lo = be16_to_cpu(from->di_projid_lo);
7061         to->di_projid_hi = be16_to_cpu(from->di_projid_hi);
7062 @@ -865,21 +876,26 @@ xfs_dinode_from_disk(
7063         to->di_dmevmask = be32_to_cpu(from->di_dmevmask);
7064         to->di_dmstate  = be16_to_cpu(from->di_dmstate);
7065         to->di_flags    = be16_to_cpu(from->di_flags);
7066 +       to->di_vflags   = be16_to_cpu(from->di_vflags);
7067         to->di_gen      = be32_to_cpu(from->di_gen);
7068  }
7069  
7070  void
7071  xfs_dinode_to_disk(
7072         xfs_dinode_t            *to,
7073 -       xfs_icdinode_t          *from)
7074 +       xfs_icdinode_t          *from,
7075 +       int                     tagged)
7076  {
7077         to->di_magic = cpu_to_be16(from->di_magic);
7078         to->di_mode = cpu_to_be16(from->di_mode);
7079         to->di_version = from ->di_version;
7080         to->di_format = from->di_format;
7081         to->di_onlink = cpu_to_be16(from->di_onlink);
7082 -       to->di_uid = cpu_to_be32(from->di_uid);
7083 -       to->di_gid = cpu_to_be32(from->di_gid);
7084 +
7085 +       to->di_uid = cpu_to_be32(TAGINO_UID(tagged, from->di_uid, from->di_tag));
7086 +       to->di_gid = cpu_to_be32(TAGINO_GID(tagged, from->di_gid, from->di_tag));
7087 +       to->di_tag = cpu_to_be16(TAGINO_TAG(tagged, from->di_tag));
7088 +
7089         to->di_nlink = cpu_to_be32(from->di_nlink);
7090         to->di_projid_lo = cpu_to_be16(from->di_projid_lo);
7091         to->di_projid_hi = cpu_to_be16(from->di_projid_hi);
7092 @@ -901,12 +917,14 @@ xfs_dinode_to_disk(
7093         to->di_dmevmask = cpu_to_be32(from->di_dmevmask);
7094         to->di_dmstate = cpu_to_be16(from->di_dmstate);
7095         to->di_flags = cpu_to_be16(from->di_flags);
7096 +       to->di_vflags = cpu_to_be16(from->di_vflags);
7097         to->di_gen = cpu_to_be32(from->di_gen);
7098  }
7099  
7100  STATIC uint
7101  _xfs_dic2xflags(
7102 -       __uint16_t              di_flags)
7103 +       __uint16_t              di_flags,
7104 +       __uint16_t              di_vflags)
7105  {
7106         uint                    flags = 0;
7107  
7108 @@ -917,6 +935,8 @@ _xfs_dic2xflags(
7109                         flags |= XFS_XFLAG_PREALLOC;
7110                 if (di_flags & XFS_DIFLAG_IMMUTABLE)
7111                         flags |= XFS_XFLAG_IMMUTABLE;
7112 +               if (di_flags & XFS_DIFLAG_IXUNLINK)
7113 +                       flags |= XFS_XFLAG_IXUNLINK;
7114                 if (di_flags & XFS_DIFLAG_APPEND)
7115                         flags |= XFS_XFLAG_APPEND;
7116                 if (di_flags & XFS_DIFLAG_SYNC)
7117 @@ -941,6 +961,10 @@ _xfs_dic2xflags(
7118                         flags |= XFS_XFLAG_FILESTREAM;
7119         }
7120  
7121 +       if (di_vflags & XFS_DIVFLAG_BARRIER)
7122 +               flags |= FS_BARRIER_FL;
7123 +       if (di_vflags & XFS_DIVFLAG_COW)
7124 +               flags |= FS_COW_FL;
7125         return flags;
7126  }
7127  
7128 @@ -950,7 +974,7 @@ xfs_ip2xflags(
7129  {
7130         xfs_icdinode_t          *dic = &ip->i_d;
7131  
7132 -       return _xfs_dic2xflags(dic->di_flags) |
7133 +       return _xfs_dic2xflags(dic->di_flags, dic->di_vflags) |
7134                                 (XFS_IFORK_Q(ip) ? XFS_XFLAG_HASATTR : 0);
7135  }
7136  
7137 @@ -958,7 +982,8 @@ uint
7138  xfs_dic2xflags(
7139         xfs_dinode_t            *dip)
7140  {
7141 -       return _xfs_dic2xflags(be16_to_cpu(dip->di_flags)) |
7142 +       return _xfs_dic2xflags(be16_to_cpu(dip->di_flags),
7143 +                               be16_to_cpu(dip->di_vflags)) |
7144                                 (XFS_DFORK_Q(dip) ? XFS_XFLAG_HASATTR : 0);
7145  }
7146  
7147 @@ -1012,7 +1037,8 @@ xfs_iread(
7148          * Otherwise, just get the truly permanent information.
7149          */
7150         if (dip->di_mode) {
7151 -               xfs_dinode_from_disk(&ip->i_d, dip);
7152 +               xfs_dinode_from_disk(&ip->i_d, dip,
7153 +                       mp->m_flags & XFS_MOUNT_TAGGED);
7154                 error = xfs_iformat(ip, dip);
7155                 if (error)  {
7156  #ifdef DEBUG
7157 @@ -1199,6 +1225,7 @@ xfs_ialloc(
7158         ASSERT(ip->i_d.di_nlink == nlink);
7159         ip->i_d.di_uid = current_fsuid();
7160         ip->i_d.di_gid = current_fsgid();
7161 +       ip->i_d.di_tag = current_fstag(&ip->i_vnode);
7162         xfs_set_projid(ip, prid);
7163         memset(&(ip->i_d.di_pad[0]), 0, sizeof(ip->i_d.di_pad));
7164  
7165 @@ -1258,6 +1285,7 @@ xfs_ialloc(
7166         ip->i_d.di_dmevmask = 0;
7167         ip->i_d.di_dmstate = 0;
7168         ip->i_d.di_flags = 0;
7169 +       ip->i_d.di_vflags = 0;
7170         flags = XFS_ILOG_CORE;
7171         switch (mode & S_IFMT) {
7172         case S_IFIFO:
7173 @@ -1952,6 +1980,7 @@ xfs_ifree(
7174         }
7175         ip->i_d.di_mode = 0;            /* mark incore inode as free */
7176         ip->i_d.di_flags = 0;
7177 +       ip->i_d.di_vflags = 0;
7178         ip->i_d.di_dmevmask = 0;
7179         ip->i_d.di_forkoff = 0;         /* mark the attr fork not in use */
7180         ip->i_d.di_format = XFS_DINODE_FMT_EXTENTS;
7181 @@ -2118,7 +2147,6 @@ xfs_iroot_realloc(
7182         return;
7183  }
7184  
7185 -
7186  /*
7187   * This is called when the amount of space needed for if_data
7188   * is increased or decreased.  The change in size is indicated by
7189 @@ -2800,7 +2828,8 @@ xfs_iflush_int(
7190          * because if the inode is dirty at all the core must
7191          * be.
7192          */
7193 -       xfs_dinode_to_disk(dip, &ip->i_d);
7194 +       xfs_dinode_to_disk(dip, &ip->i_d,
7195 +               mp->m_flags & XFS_MOUNT_TAGGED);
7196  
7197         /* Wrap, we never let the log put out DI_MAX_FLUSH */
7198         if (ip->i_d.di_flushiter == DI_MAX_FLUSH)
7199 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
7200 --- linux-3.9.4/fs/xfs/xfs_inode.h      2013-05-31 13:45:25.000000000 +0000
7201 +++ linux-3.9.4-vs2.3.6.2/fs/xfs/xfs_inode.h    2013-05-31 14:47:11.000000000 +0000
7202 @@ -134,7 +134,9 @@ typedef struct xfs_icdinode {
7203         __uint32_t      di_nlink;       /* number of links to file */
7204         __uint16_t      di_projid_lo;   /* lower part of owner's project id */
7205         __uint16_t      di_projid_hi;   /* higher part of owner's project id */
7206 -       __uint8_t       di_pad[6];      /* unused, zeroed space */
7207 +       __uint8_t       di_pad[2];      /* unused, zeroed space */
7208 +       __uint16_t      di_tag;         /* context tagging */
7209 +       __uint16_t      di_vflags;      /* vserver specific flags */
7210         __uint16_t      di_flushiter;   /* incremented on flush */
7211         xfs_ictimestamp_t di_atime;     /* time last accessed */
7212         xfs_ictimestamp_t di_mtime;     /* time last modified */
7213 @@ -556,7 +558,7 @@ int         xfs_imap_to_bp(struct xfs_mount *,
7214  int            xfs_iread(struct xfs_mount *, struct xfs_trans *,
7215                           struct xfs_inode *, uint);
7216  void           xfs_dinode_to_disk(struct xfs_dinode *,
7217 -                                  struct xfs_icdinode *);
7218 +                                  struct xfs_icdinode *, int);
7219  void           xfs_idestroy_fork(struct xfs_inode *, int);
7220  void           xfs_idata_realloc(struct xfs_inode *, int, int);
7221  void           xfs_iroot_realloc(struct xfs_inode *, int, int);
7222 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
7223 --- linux-3.9.4/fs/xfs/xfs_ioctl.c      2013-05-31 13:45:25.000000000 +0000
7224 +++ linux-3.9.4-vs2.3.6.2/fs/xfs/xfs_ioctl.c    2013-05-31 14:47:11.000000000 +0000
7225 @@ -26,7 +26,7 @@
7226  #include "xfs_bmap_btree.h"
7227  #include "xfs_dinode.h"
7228  #include "xfs_inode.h"
7229 -#include "xfs_ioctl.h"
7230 +// #include "xfs_ioctl.h"
7231  #include "xfs_rtalloc.h"
7232  #include "xfs_itable.h"
7233  #include "xfs_error.h"
7234 @@ -763,6 +763,10 @@ xfs_merge_ioc_xflags(
7235                 xflags |= XFS_XFLAG_IMMUTABLE;
7236         else
7237                 xflags &= ~XFS_XFLAG_IMMUTABLE;
7238 +       if (flags & FS_IXUNLINK_FL)
7239 +               xflags |= XFS_XFLAG_IXUNLINK;
7240 +       else
7241 +               xflags &= ~XFS_XFLAG_IXUNLINK;
7242         if (flags & FS_APPEND_FL)
7243                 xflags |= XFS_XFLAG_APPEND;
7244         else
7245 @@ -791,6 +795,8 @@ xfs_di2lxflags(
7246  
7247         if (di_flags & XFS_DIFLAG_IMMUTABLE)
7248                 flags |= FS_IMMUTABLE_FL;
7249 +       if (di_flags & XFS_DIFLAG_IXUNLINK)
7250 +               flags |= FS_IXUNLINK_FL;
7251         if (di_flags & XFS_DIFLAG_APPEND)
7252                 flags |= FS_APPEND_FL;
7253         if (di_flags & XFS_DIFLAG_SYNC)
7254 @@ -851,6 +857,8 @@ xfs_set_diflags(
7255         di_flags = (ip->i_d.di_flags & XFS_DIFLAG_PREALLOC);
7256         if (xflags & XFS_XFLAG_IMMUTABLE)
7257                 di_flags |= XFS_DIFLAG_IMMUTABLE;
7258 +       if (xflags & XFS_XFLAG_IXUNLINK)
7259 +               di_flags |= XFS_DIFLAG_IXUNLINK;
7260         if (xflags & XFS_XFLAG_APPEND)
7261                 di_flags |= XFS_DIFLAG_APPEND;
7262         if (xflags & XFS_XFLAG_SYNC)
7263 @@ -893,6 +901,10 @@ xfs_diflags_to_linux(
7264                 inode->i_flags |= S_IMMUTABLE;
7265         else
7266                 inode->i_flags &= ~S_IMMUTABLE;
7267 +       if (xflags & XFS_XFLAG_IXUNLINK)
7268 +               inode->i_flags |= S_IXUNLINK;
7269 +       else
7270 +               inode->i_flags &= ~S_IXUNLINK;
7271         if (xflags & XFS_XFLAG_APPEND)
7272                 inode->i_flags |= S_APPEND;
7273         else
7274 @@ -1397,10 +1409,18 @@ xfs_file_ioctl(
7275         case XFS_IOC_FSGETXATTRA:
7276                 return xfs_ioc_fsgetxattr(ip, 1, arg);
7277         case XFS_IOC_FSSETXATTR:
7278 +               if (IS_BARRIER(inode)) {
7279 +                       vxwprintk_task(1, "messing with the barrier.");
7280 +                       return -XFS_ERROR(EACCES);
7281 +               }
7282                 return xfs_ioc_fssetxattr(ip, filp, arg);
7283         case XFS_IOC_GETXFLAGS:
7284                 return xfs_ioc_getxflags(ip, arg);
7285         case XFS_IOC_SETXFLAGS:
7286 +               if (IS_BARRIER(inode)) {
7287 +                       vxwprintk_task(1, "messing with the barrier.");
7288 +                       return -XFS_ERROR(EACCES);
7289 +               }
7290                 return xfs_ioc_setxflags(ip, filp, arg);
7291  
7292         case XFS_IOC_FSSETDM: {
7293 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
7294 --- linux-3.9.4/fs/xfs/xfs_ioctl.h      2012-12-11 03:30:57.000000000 +0000
7295 +++ linux-3.9.4-vs2.3.6.2/fs/xfs/xfs_ioctl.h    2013-05-31 14:47:11.000000000 +0000
7296 @@ -70,6 +70,12 @@ xfs_handle_to_dentry(
7297         void __user             *uhandle,
7298         u32                     hlen);
7299  
7300 +extern int
7301 +xfs_sync_flags(
7302 +       struct inode            *inode,
7303 +       int                     flags,
7304 +       int                     vflags);
7305 +
7306  extern long
7307  xfs_file_ioctl(
7308         struct file             *filp,
7309 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
7310 --- linux-3.9.4/fs/xfs/xfs_iops.c       2013-02-19 13:58:49.000000000 +0000
7311 +++ linux-3.9.4-vs2.3.6.2/fs/xfs/xfs_iops.c     2013-05-31 14:47:11.000000000 +0000
7312 @@ -28,6 +28,7 @@
7313  #include "xfs_bmap_btree.h"
7314  #include "xfs_dinode.h"
7315  #include "xfs_inode.h"
7316 +#include "xfs_ioctl.h"
7317  #include "xfs_bmap.h"
7318  #include "xfs_rtalloc.h"
7319  #include "xfs_error.h"
7320 @@ -47,6 +48,7 @@
7321  #include <linux/security.h>
7322  #include <linux/fiemap.h>
7323  #include <linux/slab.h>
7324 +#include <linux/vs_tag.h>
7325  
7326  static int
7327  xfs_initxattrs(
7328 @@ -422,6 +424,7 @@ xfs_vn_getattr(
7329         stat->nlink = ip->i_d.di_nlink;
7330         stat->uid = ip->i_d.di_uid;
7331         stat->gid = ip->i_d.di_gid;
7332 +       stat->tag = ip->i_d.di_tag;
7333         stat->ino = ip->i_ino;
7334         stat->atime = inode->i_atime;
7335         stat->mtime = inode->i_mtime;
7336 @@ -1037,6 +1040,7 @@ static const struct inode_operations xfs
7337         .listxattr              = xfs_vn_listxattr,
7338         .fiemap                 = xfs_vn_fiemap,
7339         .update_time            = xfs_vn_update_time,
7340 +       .sync_flags             = xfs_sync_flags,
7341  };
7342  
7343  static const struct inode_operations xfs_dir_inode_operations = {
7344 @@ -1063,6 +1067,7 @@ static const struct inode_operations xfs
7345         .removexattr            = generic_removexattr,
7346         .listxattr              = xfs_vn_listxattr,
7347         .update_time            = xfs_vn_update_time,
7348 +       .sync_flags             = xfs_sync_flags,
7349  };
7350  
7351  static const struct inode_operations xfs_dir_ci_inode_operations = {
7352 @@ -1114,6 +1119,10 @@ xfs_diflags_to_iflags(
7353                 inode->i_flags |= S_IMMUTABLE;
7354         else
7355                 inode->i_flags &= ~S_IMMUTABLE;
7356 +       if (ip->i_d.di_flags & XFS_DIFLAG_IXUNLINK)
7357 +               inode->i_flags |= S_IXUNLINK;
7358 +       else
7359 +               inode->i_flags &= ~S_IXUNLINK;
7360         if (ip->i_d.di_flags & XFS_DIFLAG_APPEND)
7361                 inode->i_flags |= S_APPEND;
7362         else
7363 @@ -1126,6 +1135,15 @@ xfs_diflags_to_iflags(
7364                 inode->i_flags |= S_NOATIME;
7365         else
7366                 inode->i_flags &= ~S_NOATIME;
7367 +
7368 +       if (ip->i_d.di_vflags & XFS_DIVFLAG_BARRIER)
7369 +               inode->i_vflags |= V_BARRIER;
7370 +       else
7371 +               inode->i_vflags &= ~V_BARRIER;
7372 +       if (ip->i_d.di_vflags & XFS_DIVFLAG_COW)
7373 +               inode->i_vflags |= V_COW;
7374 +       else
7375 +               inode->i_vflags &= ~V_COW;
7376  }
7377  
7378  /*
7379 @@ -1157,6 +1175,7 @@ xfs_setup_inode(
7380         set_nlink(inode, ip->i_d.di_nlink);
7381         inode->i_uid    = ip->i_d.di_uid;
7382         inode->i_gid    = ip->i_d.di_gid;
7383 +       inode->i_tag    = ip->i_d.di_tag;
7384  
7385         switch (inode->i_mode & S_IFMT) {
7386         case S_IFBLK:
7387 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
7388 --- linux-3.9.4/fs/xfs/xfs_itable.c     2013-02-19 13:58:49.000000000 +0000
7389 +++ linux-3.9.4-vs2.3.6.2/fs/xfs/xfs_itable.c   2013-05-31 14:47:11.000000000 +0000
7390 @@ -97,6 +97,7 @@ xfs_bulkstat_one_int(
7391         buf->bs_mode = dic->di_mode;
7392         buf->bs_uid = dic->di_uid;
7393         buf->bs_gid = dic->di_gid;
7394 +       buf->bs_tag = dic->di_tag;
7395         buf->bs_size = dic->di_size;
7396         buf->bs_atime.tv_sec = dic->di_atime.t_sec;
7397         buf->bs_atime.tv_nsec = dic->di_atime.t_nsec;
7398 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
7399 --- linux-3.9.4/fs/xfs/xfs_linux.h      2013-02-19 13:58:49.000000000 +0000
7400 +++ linux-3.9.4-vs2.3.6.2/fs/xfs/xfs_linux.h    2013-05-31 14:47:11.000000000 +0000
7401 @@ -123,6 +123,7 @@
7402  
7403  #define current_cpu()          (raw_smp_processor_id())
7404  #define current_pid()          (current->pid)
7405 +#define current_fstag(vp)      (dx_current_fstag((vp)->i_sb))
7406  #define current_test_flags(f)  (current->flags & (f))
7407  #define current_set_flags_nested(sp, f)                \
7408                 (*(sp) = current->flags, current->flags |= (f))
7409 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
7410 --- linux-3.9.4/fs/xfs/xfs_log_recover.c        2013-05-31 13:45:25.000000000 +0000
7411 +++ linux-3.9.4-vs2.3.6.2/fs/xfs/xfs_log_recover.c      2013-05-31 14:47:11.000000000 +0000
7412 @@ -2361,7 +2361,8 @@ xlog_recover_inode_pass2(
7413         }
7414  
7415         /* The core is in in-core format */
7416 -       xfs_dinode_to_disk(dip, item->ri_buf[1].i_addr);
7417 +       xfs_dinode_to_disk(dip, item->ri_buf[1].i_addr,
7418 +               mp->m_flags & XFS_MOUNT_TAGGED);
7419  
7420         /* the rest is in on-disk format */
7421         if (item->ri_buf[1].i_len > sizeof(struct xfs_icdinode)) {
7422 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
7423 --- linux-3.9.4/fs/xfs/xfs_mount.h      2013-05-31 13:45:25.000000000 +0000
7424 +++ linux-3.9.4-vs2.3.6.2/fs/xfs/xfs_mount.h    2013-05-31 14:47:11.000000000 +0000
7425 @@ -254,6 +254,7 @@ typedef struct xfs_mount {
7426                                                    allocator */
7427  #define XFS_MOUNT_NOATTR2      (1ULL << 25)    /* disable use of attr2 format */
7428  
7429 +#define XFS_MOUNT_TAGGED       (1ULL << 31)    /* context tagging */
7430  
7431  /*
7432   * Default minimum read and write sizes.
7433 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
7434 --- linux-3.9.4/fs/xfs/xfs_super.c      2013-05-31 13:45:25.000000000 +0000
7435 +++ linux-3.9.4-vs2.3.6.2/fs/xfs/xfs_super.c    2013-05-31 14:47:11.000000000 +0000
7436 @@ -114,6 +114,9 @@ mempool_t *xfs_ioend_pool;
7437  #define MNTOPT_NODELAYLOG  "nodelaylog"        /* Delayed logging disabled */
7438  #define MNTOPT_DISCARD    "discard"    /* Discard unused blocks */
7439  #define MNTOPT_NODISCARD   "nodiscard" /* Do not discard unused blocks */
7440 +#define MNTOPT_TAGXID  "tagxid"        /* context tagging for inodes */
7441 +#define MNTOPT_TAGGED  "tag"           /* context tagging for inodes */
7442 +#define MNTOPT_NOTAGTAG        "notag"         /* do not use context tagging */
7443  
7444  /*
7445   * Table driven mount option parser.
7446 @@ -126,6 +129,8 @@ enum {
7447         Opt_nobarrier,
7448         Opt_inode64,
7449         Opt_inode32,
7450 +       Opt_tag,
7451 +       Opt_notag,
7452         Opt_err
7453  };
7454  
7455 @@ -134,6 +139,9 @@ static const match_table_t tokens = {
7456         {Opt_nobarrier, "nobarrier"},
7457         {Opt_inode64, "inode64"},
7458         {Opt_inode32, "inode32"},
7459 +       {Opt_tag, "tagxid"},
7460 +       {Opt_tag, "tag"},
7461 +       {Opt_notag, "notag"},
7462         {Opt_err, NULL}
7463  };
7464  
7465 @@ -392,6 +400,19 @@ xfs_parseargs(
7466                 } else if (!strcmp(this_char, "irixsgid")) {
7467                         xfs_warn(mp,
7468         "irixsgid is now a sysctl(2) variable, option is deprecated.");
7469 +#ifndef CONFIG_TAGGING_NONE
7470 +               } else if (!strcmp(this_char, MNTOPT_TAGGED)) {
7471 +                       mp->m_flags |= XFS_MOUNT_TAGGED;
7472 +               } else if (!strcmp(this_char, MNTOPT_NOTAGTAG)) {
7473 +                       mp->m_flags &= ~XFS_MOUNT_TAGGED;
7474 +               } else if (!strcmp(this_char, MNTOPT_TAGXID)) {
7475 +                       mp->m_flags |= XFS_MOUNT_TAGGED;
7476 +#endif
7477 +#ifdef CONFIG_PROPAGATE
7478 +               } else if (!strcmp(this_char, MNTOPT_TAGGED)) {
7479 +                       /* use value */
7480 +                       mp->m_flags |= XFS_MOUNT_TAGGED;
7481 +#endif
7482                 } else {
7483                         xfs_warn(mp, "unknown mount option [%s].", this_char);
7484                         return EINVAL;
7485 @@ -1238,6 +1259,16 @@ xfs_fs_remount(
7486                 case Opt_inode32:
7487                         mp->m_maxagi = xfs_set_inode32(mp);
7488                         break;
7489 +               case Opt_tag:
7490 +                       if (!(sb->s_flags & MS_TAGGED)) {
7491 +                               printk(KERN_INFO
7492 +                                       "XFS: %s: tagging not permitted on remount.\n",
7493 +                                       sb->s_id);
7494 +                               return -EINVAL;
7495 +                       }
7496 +                       break;
7497 +               case Opt_notag:
7498 +                       break;
7499                 default:
7500                         /*
7501                          * Logically we would return an error here to prevent
7502 @@ -1458,6 +1489,9 @@ xfs_fs_fill_super(
7503         if (error)
7504                 goto out_free_sb;
7505  
7506 +       if (mp->m_flags & XFS_MOUNT_TAGGED)
7507 +               sb->s_flags |= MS_TAGGED;
7508 +
7509         /*
7510          * we must configure the block size in the superblock before we run the
7511          * full mount process as the mount process can lookup and cache inodes.
7512 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
7513 --- linux-3.9.4/fs/xfs/xfs_vnodeops.c   2013-05-31 13:45:25.000000000 +0000
7514 +++ linux-3.9.4-vs2.3.6.2/fs/xfs/xfs_vnodeops.c 2013-05-31 14:47:11.000000000 +0000
7515 @@ -104,6 +104,77 @@ xfs_readlink_bmap(
7516         return error;
7517  }
7518  
7519 +
7520 +STATIC void
7521 +xfs_get_inode_flags(
7522 +       xfs_inode_t     *ip)
7523 +{
7524 +       struct inode    *inode = VFS_I(ip);
7525 +       unsigned int    flags = inode->i_flags;
7526 +       unsigned int    vflags = inode->i_vflags;
7527 +
7528 +       if (flags & S_IMMUTABLE)
7529 +               ip->i_d.di_flags |= XFS_DIFLAG_IMMUTABLE;
7530 +       else
7531 +               ip->i_d.di_flags &= ~XFS_DIFLAG_IMMUTABLE;
7532 +       if (flags & S_IXUNLINK)
7533 +               ip->i_d.di_flags |= XFS_DIFLAG_IXUNLINK;
7534 +       else
7535 +               ip->i_d.di_flags &= ~XFS_DIFLAG_IXUNLINK;
7536 +
7537 +       if (vflags & V_BARRIER)
7538 +               ip->i_d.di_vflags |= XFS_DIVFLAG_BARRIER;
7539 +       else
7540 +               ip->i_d.di_vflags &= ~XFS_DIVFLAG_BARRIER;
7541 +       if (vflags & V_COW)
7542 +               ip->i_d.di_vflags |= XFS_DIVFLAG_COW;
7543 +       else
7544 +               ip->i_d.di_vflags &= ~XFS_DIVFLAG_COW;
7545 +}
7546 +
7547 +int
7548 +xfs_sync_flags(
7549 +       struct inode            *inode,
7550 +       int                     flags,
7551 +       int                     vflags)
7552 +{
7553 +       struct xfs_inode        *ip = XFS_I(inode);
7554 +       struct xfs_mount        *mp = ip->i_mount;
7555 +       struct xfs_trans        *tp;
7556 +       unsigned int            lock_flags = 0;
7557 +       int                     code;
7558 +
7559 +       tp = xfs_trans_alloc(mp, XFS_TRANS_SETATTR_NOT_SIZE);
7560 +       code = xfs_trans_reserve(tp, 0, XFS_ICHANGE_LOG_RES(mp), 0, 0, 0);
7561 +       if (code)
7562 +               goto error_out;
7563 +
7564 +       xfs_ilock(ip, XFS_ILOCK_EXCL);
7565 +       xfs_trans_ijoin(tp, ip, 0);
7566 +
7567 +       inode->i_flags = flags;
7568 +       inode->i_vflags = vflags;
7569 +       xfs_get_inode_flags(ip);
7570 +
7571 +       xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE);
7572 +       xfs_trans_ichgtime(tp, ip, XFS_ICHGTIME_CHG);
7573 +
7574 +       XFS_STATS_INC(xs_ig_attrchg);
7575 +
7576 +       if (mp->m_flags & XFS_MOUNT_WSYNC)
7577 +               xfs_trans_set_sync(tp);
7578 +       code = xfs_trans_commit(tp, 0);
7579 +       xfs_iunlock(ip, XFS_ILOCK_EXCL);
7580 +       return code;
7581 +
7582 +error_out:
7583 +       xfs_trans_cancel(tp, 0);
7584 +       if (lock_flags)
7585 +               xfs_iunlock(ip, XFS_ILOCK_EXCL);
7586 +       return code;
7587 +}
7588 +
7589 +
7590  int
7591  xfs_readlink(
7592         xfs_inode_t     *ip,
7593 diff -NurpP --minimal linux-3.9.4/include/linux/cred.h linux-3.9.4-vs2.3.6.2/include/linux/cred.h
7594 --- linux-3.9.4/include/linux/cred.h    2013-02-19 13:58:50.000000000 +0000
7595 +++ linux-3.9.4-vs2.3.6.2/include/linux/cred.h  2013-05-31 14:47:11.000000000 +0000
7596 @@ -143,6 +143,7 @@ extern void exit_creds(struct task_struc
7597  extern int copy_creds(struct task_struct *, unsigned long);
7598  extern const struct cred *get_task_cred(struct task_struct *);
7599  extern struct cred *cred_alloc_blank(void);
7600 +extern struct cred *__prepare_creds(const struct cred *);
7601  extern struct cred *prepare_creds(void);
7602  extern struct cred *prepare_exec_creds(void);
7603  extern int commit_creds(struct cred *);
7604 @@ -196,6 +197,31 @@ static inline void validate_process_cred
7605  }
7606  #endif
7607  
7608 +static inline void set_cred_subscribers(struct cred *cred, int n)
7609 +{
7610 +#ifdef CONFIG_DEBUG_CREDENTIALS
7611 +       atomic_set(&cred->subscribers, n);
7612 +#endif
7613 +}
7614 +
7615 +static inline int read_cred_subscribers(const struct cred *cred)
7616 +{
7617 +#ifdef CONFIG_DEBUG_CREDENTIALS
7618 +       return atomic_read(&cred->subscribers);
7619 +#else
7620 +       return 0;
7621 +#endif
7622 +}
7623 +
7624 +static inline void alter_cred_subscribers(const struct cred *_cred, int n)
7625 +{
7626 +#ifdef CONFIG_DEBUG_CREDENTIALS
7627 +       struct cred *cred = (struct cred *) _cred;
7628 +
7629 +       atomic_add(n, &cred->subscribers);
7630 +#endif
7631 +}
7632 +
7633  /**
7634   * get_new_cred - Get a reference on a new set of credentials
7635   * @cred: The new credentials to reference
7636 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
7637 --- linux-3.9.4/include/linux/devpts_fs.h       2013-02-19 13:58:50.000000000 +0000
7638 +++ linux-3.9.4-vs2.3.6.2/include/linux/devpts_fs.h     2013-05-31 14:47:11.000000000 +0000
7639 @@ -45,5 +45,4 @@ static inline void devpts_pty_kill(struc
7640  
7641  #endif
7642  
7643 -
7644  #endif /* _LINUX_DEVPTS_FS_H */
7645 diff -NurpP --minimal linux-3.9.4/include/linux/fs.h linux-3.9.4-vs2.3.6.2/include/linux/fs.h
7646 --- linux-3.9.4/include/linux/fs.h      2013-05-31 13:45:27.000000000 +0000
7647 +++ linux-3.9.4-vs2.3.6.2/include/linux/fs.h    2013-05-31 14:47:11.000000000 +0000
7648 @@ -211,6 +211,7 @@ typedef void (dio_iodone_t)(struct kiocb
7649  #define ATTR_KILL_PRIV (1 << 14)
7650  #define ATTR_OPEN      (1 << 15) /* Truncating from open(O_TRUNC) */
7651  #define ATTR_TIMES_SET (1 << 16)
7652 +#define ATTR_TAG       (1 << 17)
7653  
7654  /*
7655   * This is the Inode Attributes structure, used for notify_change().  It
7656 @@ -226,6 +227,7 @@ struct iattr {
7657         umode_t         ia_mode;
7658         kuid_t          ia_uid;
7659         kgid_t          ia_gid;
7660 +       ktag_t          ia_tag;
7661         loff_t          ia_size;
7662         struct timespec ia_atime;
7663         struct timespec ia_mtime;
7664 @@ -523,7 +525,9 @@ struct inode {
7665         unsigned short          i_opflags;
7666         kuid_t                  i_uid;
7667         kgid_t                  i_gid;
7668 -       unsigned int            i_flags;
7669 +       ktag_t                  i_tag;
7670 +       unsigned short          i_flags;
7671 +       unsigned short          i_vflags;
7672  
7673  #ifdef CONFIG_FS_POSIX_ACL
7674         struct posix_acl        *i_acl;
7675 @@ -552,6 +556,7 @@ struct inode {
7676                 unsigned int __i_nlink;
7677         };
7678         dev_t                   i_rdev;
7679 +       dev_t                   i_mdev;
7680         loff_t                  i_size;
7681         struct timespec         i_atime;
7682         struct timespec         i_mtime;
7683 @@ -702,6 +707,11 @@ static inline gid_t i_gid_read(const str
7684         return from_kgid(&init_user_ns, inode->i_gid);
7685  }
7686  
7687 +static inline tag_t i_tag_read(const struct inode *inode)
7688 +{
7689 +       return from_ktag(&init_user_ns, inode->i_tag);
7690 +}
7691 +
7692  static inline void i_uid_write(struct inode *inode, uid_t uid)
7693  {
7694         inode->i_uid = make_kuid(&init_user_ns, uid);
7695 @@ -712,14 +722,19 @@ static inline void i_gid_write(struct in
7696         inode->i_gid = make_kgid(&init_user_ns, gid);
7697  }
7698  
7699 +static inline void i_tag_write(struct inode *inode, tag_t tag)
7700 +{
7701 +       inode->i_tag = make_ktag(&init_user_ns, tag);
7702 +}
7703 +
7704  static inline unsigned iminor(const struct inode *inode)
7705  {
7706 -       return MINOR(inode->i_rdev);
7707 +       return MINOR(inode->i_mdev);
7708  }
7709  
7710  static inline unsigned imajor(const struct inode *inode)
7711  {
7712 -       return MAJOR(inode->i_rdev);
7713 +       return MAJOR(inode->i_mdev);
7714  }
7715  
7716  extern struct block_device *I_BDEV(struct inode *inode);
7717 @@ -786,6 +801,7 @@ struct file {
7718         loff_t                  f_pos;
7719         struct fown_struct      f_owner;
7720         const struct cred       *f_cred;
7721 +       xid_t                   f_xid;
7722         struct file_ra_state    f_ra;
7723  
7724         u64                     f_version;
7725 @@ -937,6 +953,7 @@ struct file_lock {
7726         struct file *fl_file;
7727         loff_t fl_start;
7728         loff_t fl_end;
7729 +       xid_t fl_xid;
7730  
7731         struct fasync_struct *  fl_fasync; /* for lease break notifications */
7732         /* for lease breaks: */
7733 @@ -1567,6 +1584,7 @@ struct inode_operations {
7734         ssize_t (*getxattr) (struct dentry *, const char *, void *, size_t);
7735         ssize_t (*listxattr) (struct dentry *, char *, size_t);
7736         int (*removexattr) (struct dentry *, const char *);
7737 +       int (*sync_flags) (struct inode *, int, int);
7738         int (*fiemap)(struct inode *, struct fiemap_extent_info *, u64 start,
7739                       u64 len);
7740         int (*update_time)(struct inode *, struct timespec *, int);
7741 @@ -1579,6 +1597,7 @@ ssize_t rw_copy_check_uvector(int type,
7742                               unsigned long nr_segs, unsigned long fast_segs,
7743                               struct iovec *fast_pointer,
7744                               struct iovec **ret_pointer);
7745 +ssize_t vfs_sendfile(struct file *, struct file *, loff_t *, size_t, loff_t);
7746  
7747  extern ssize_t vfs_read(struct file *, char __user *, size_t, loff_t *);
7748  extern ssize_t vfs_write(struct file *, const char __user *, size_t, loff_t *);
7749 @@ -1632,6 +1651,14 @@ struct super_operations {
7750  #define S_IMA          1024    /* Inode has an associated IMA struct */
7751  #define S_AUTOMOUNT    2048    /* Automount/referral quasi-directory */
7752  #define S_NOSEC                4096    /* no suid or xattr security attributes */
7753 +#define S_IXUNLINK     8192    /* Immutable Invert on unlink */
7754 +
7755 +/* Linux-VServer related Inode flags */
7756 +
7757 +#define V_VALID                1
7758 +#define V_XATTR                2
7759 +#define V_BARRIER      4       /* Barrier for chroot() */
7760 +#define V_COW          8       /* Copy on Write */
7761  
7762  /*
7763   * Note that nosuid etc flags are inode-specific: setting some file-system
7764 @@ -1656,10 +1683,13 @@ struct super_operations {
7765  #define IS_MANDLOCK(inode)     __IS_FLG(inode, MS_MANDLOCK)
7766  #define IS_NOATIME(inode)      __IS_FLG(inode, MS_RDONLY|MS_NOATIME)
7767  #define IS_I_VERSION(inode)    __IS_FLG(inode, MS_I_VERSION)
7768 +#define IS_TAGGED(inode)       __IS_FLG(inode, MS_TAGGED)
7769  
7770  #define IS_NOQUOTA(inode)      ((inode)->i_flags & S_NOQUOTA)
7771  #define IS_APPEND(inode)       ((inode)->i_flags & S_APPEND)
7772  #define IS_IMMUTABLE(inode)    ((inode)->i_flags & S_IMMUTABLE)
7773 +#define IS_IXUNLINK(inode)     ((inode)->i_flags & S_IXUNLINK)
7774 +#define IS_IXORUNLINK(inode)   ((IS_IXUNLINK(inode) ? S_IMMUTABLE : 0) ^ IS_IMMUTABLE(inode))
7775  #define IS_POSIXACL(inode)     __IS_FLG(inode, MS_POSIXACL)
7776  
7777  #define IS_DEADDIR(inode)      ((inode)->i_flags & S_DEAD)
7778 @@ -1670,6 +1700,16 @@ struct super_operations {
7779  #define IS_AUTOMOUNT(inode)    ((inode)->i_flags & S_AUTOMOUNT)
7780  #define IS_NOSEC(inode)                ((inode)->i_flags & S_NOSEC)
7781  
7782 +#define IS_BARRIER(inode)      (S_ISDIR((inode)->i_mode) && ((inode)->i_vflags & V_BARRIER))
7783 +
7784 +#ifdef CONFIG_VSERVER_COWBL
7785 +#  define IS_COW(inode)                (IS_IXUNLINK(inode) && IS_IMMUTABLE(inode))
7786 +#  define IS_COW_LINK(inode)   (S_ISREG((inode)->i_mode) && ((inode)->i_nlink > 1))
7787 +#else
7788 +#  define IS_COW(inode)                (0)
7789 +#  define IS_COW_LINK(inode)   (0)
7790 +#endif
7791 +
7792  /*
7793   * Inode state bits.  Protected by inode->i_lock
7794   *
7795 @@ -1898,6 +1938,9 @@ extern int rw_verify_area(int, struct fi
7796  extern int locks_mandatory_locked(struct inode *);
7797  extern int locks_mandatory_area(int, struct inode *, struct file *, loff_t, size_t);
7798  
7799 +#define ATTR_FLAG_BARRIER      512     /* Barrier for chroot() */
7800 +#define ATTR_FLAG_IXUNLINK     1024    /* Immutable invert on unlink */
7801 +
7802  /*
7803   * Candidates for mandatory locking have the setgid bit set
7804   * but no group execute bit -  an otherwise meaningless combination.
7805 @@ -2509,6 +2552,7 @@ extern int dcache_dir_open(struct inode
7806  extern int dcache_dir_close(struct inode *, struct file *);
7807  extern loff_t dcache_dir_lseek(struct file *, loff_t, int);
7808  extern int dcache_readdir(struct file *, void *, filldir_t);
7809 +extern int dcache_readdir_filter(struct file *, void *, filldir_t, int (*)(struct dentry *));
7810  extern int simple_setattr(struct dentry *, struct iattr *);
7811  extern int simple_getattr(struct vfsmount *, struct dentry *, struct kstat *);
7812  extern int simple_statfs(struct dentry *, struct kstatfs *);
7813 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
7814 --- linux-3.9.4/include/linux/init_task.h       2013-05-31 13:45:27.000000000 +0000
7815 +++ linux-3.9.4-vs2.3.6.2/include/linux/init_task.h     2013-05-31 14:53:41.000000000 +0000
7816 @@ -222,6 +222,10 @@ extern struct task_group root_task_group
7817         INIT_TASK_RCU_PREEMPT(tsk)                                      \
7818         INIT_CPUSET_SEQ                                                 \
7819         INIT_VTIME(tsk)                                                 \
7820 +       .xid            = 0,                                            \
7821 +       .vx_info        = NULL,                                         \
7822 +       .nid            = 0,                                            \
7823 +       .nx_info        = NULL,                                         \
7824  }
7825  
7826  
7827 diff -NurpP --minimal linux-3.9.4/include/linux/ipc.h linux-3.9.4-vs2.3.6.2/include/linux/ipc.h
7828 --- linux-3.9.4/include/linux/ipc.h     2012-12-11 03:30:57.000000000 +0000
7829 +++ linux-3.9.4-vs2.3.6.2/include/linux/ipc.h   2013-05-31 14:47:11.000000000 +0000
7830 @@ -16,6 +16,7 @@ struct kern_ipc_perm
7831         key_t           key;
7832         kuid_t          uid;
7833         kgid_t          gid;
7834 +       xid_t           xid;
7835         kuid_t          cuid;
7836         kgid_t          cgid;
7837         umode_t         mode; 
7838 diff -NurpP --minimal linux-3.9.4/include/linux/loop.h linux-3.9.4-vs2.3.6.2/include/linux/loop.h
7839 --- linux-3.9.4/include/linux/loop.h    2013-02-19 13:58:51.000000000 +0000
7840 +++ linux-3.9.4-vs2.3.6.2/include/linux/loop.h  2013-05-31 14:47:11.000000000 +0000
7841 @@ -41,6 +41,7 @@ struct loop_device {
7842         struct loop_func_table *lo_encryption;
7843         __u32           lo_init[2];
7844         kuid_t          lo_key_owner;   /* Who set the key */
7845 +       xid_t           lo_xid;
7846         int             (*ioctl)(struct loop_device *, int cmd, 
7847                                  unsigned long arg); 
7848  
7849 diff -NurpP --minimal linux-3.9.4/include/linux/memcontrol.h linux-3.9.4-vs2.3.6.2/include/linux/memcontrol.h
7850 --- linux-3.9.4/include/linux/memcontrol.h      2013-05-31 13:45:28.000000000 +0000
7851 +++ linux-3.9.4-vs2.3.6.2/include/linux/memcontrol.h    2013-05-31 14:47:11.000000000 +0000
7852 @@ -86,6 +86,13 @@ extern struct mem_cgroup *try_get_mem_cg
7853  extern struct mem_cgroup *parent_mem_cgroup(struct mem_cgroup *memcg);
7854  extern struct mem_cgroup *mem_cgroup_from_cont(struct cgroup *cont);
7855  
7856 +extern u64 mem_cgroup_res_read_u64(struct mem_cgroup *mem, int member);
7857 +extern u64 mem_cgroup_memsw_read_u64(struct mem_cgroup *mem, int member);
7858 +
7859 +extern s64 mem_cgroup_stat_read_cache(struct mem_cgroup *mem);
7860 +extern s64 mem_cgroup_stat_read_anon(struct mem_cgroup *mem);
7861 +extern s64 mem_cgroup_stat_read_mapped(struct mem_cgroup *mem);
7862 +
7863  static inline
7864  bool mm_match_cgroup(const struct mm_struct *mm, const struct mem_cgroup *memcg)
7865  {
7866 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
7867 --- linux-3.9.4/include/linux/mm_types.h        2013-05-31 13:45:28.000000000 +0000
7868 +++ linux-3.9.4-vs2.3.6.2/include/linux/mm_types.h      2013-05-31 14:47:11.000000000 +0000
7869 @@ -380,6 +380,7 @@ struct mm_struct {
7870  
7871         /* Architecture-specific MM context */
7872         mm_context_t context;
7873 +       struct vx_info *mm_vx_info;
7874  
7875         unsigned long flags; /* Must use atomic bitops to access the bits */
7876  
7877 diff -NurpP --minimal linux-3.9.4/include/linux/mount.h linux-3.9.4-vs2.3.6.2/include/linux/mount.h
7878 --- linux-3.9.4/include/linux/mount.h   2013-05-31 13:45:28.000000000 +0000
7879 +++ linux-3.9.4-vs2.3.6.2/include/linux/mount.h 2013-05-31 14:47:11.000000000 +0000
7880 @@ -49,6 +49,9 @@ struct mnt_namespace;
7881  
7882  #define MNT_LOCK_READONLY      0x400000
7883  
7884 +#define MNT_TAGID      0x10000
7885 +#define MNT_NOTAG      0x20000
7886 +
7887  struct vfsmount {
7888         struct dentry *mnt_root;        /* root of the mounted tree */
7889         struct super_block *mnt_sb;     /* pointer to superblock */
7890 diff -NurpP --minimal linux-3.9.4/include/linux/net.h linux-3.9.4-vs2.3.6.2/include/linux/net.h
7891 --- linux-3.9.4/include/linux/net.h     2012-12-11 03:30:57.000000000 +0000
7892 +++ linux-3.9.4-vs2.3.6.2/include/linux/net.h   2013-05-31 14:47:11.000000000 +0000
7893 @@ -38,6 +38,7 @@ struct net;
7894  #define SOCK_PASSCRED          3
7895  #define SOCK_PASSSEC           4
7896  #define SOCK_EXTERNALLY_ALLOCATED 5
7897 +#define SOCK_USER_SOCKET       6
7898  
7899  #ifndef ARCH_HAS_SOCKET_TYPES
7900  /**
7901 diff -NurpP --minimal linux-3.9.4/include/linux/netdevice.h linux-3.9.4-vs2.3.6.2/include/linux/netdevice.h
7902 --- linux-3.9.4/include/linux/netdevice.h       2013-05-31 13:45:28.000000000 +0000
7903 +++ linux-3.9.4-vs2.3.6.2/include/linux/netdevice.h     2013-05-31 14:47:11.000000000 +0000
7904 @@ -1688,6 +1688,7 @@ extern void               netdev_resync_ops(struct ne
7905  
7906  extern struct net_device       *dev_get_by_index(struct net *net, int ifindex);
7907  extern struct net_device       *__dev_get_by_index(struct net *net, int ifindex);
7908 +extern struct net_device       *dev_get_by_index_real_rcu(struct net *net, int ifindex);
7909  extern struct net_device       *dev_get_by_index_rcu(struct net *net, int ifindex);
7910  extern int             dev_restart(struct net_device *dev);
7911  #ifdef CONFIG_NETPOLL_TRAP
7912 diff -NurpP --minimal linux-3.9.4/include/linux/nsproxy.h linux-3.9.4-vs2.3.6.2/include/linux/nsproxy.h
7913 --- linux-3.9.4/include/linux/nsproxy.h 2013-02-19 13:58:51.000000000 +0000
7914 +++ linux-3.9.4-vs2.3.6.2/include/linux/nsproxy.h       2013-05-31 17:17:53.000000000 +0000
7915 @@ -3,6 +3,7 @@
7916  
7917  #include <linux/spinlock.h>
7918  #include <linux/sched.h>
7919 +#include <linux/vserver/debug.h>
7920  
7921  struct mnt_namespace;
7922  struct uts_namespace;
7923 @@ -63,6 +64,7 @@ static inline struct nsproxy *task_nspro
7924  }
7925  
7926  int copy_namespaces(unsigned long flags, struct task_struct *tsk);
7927 +struct nsproxy *copy_nsproxy(struct nsproxy *orig);
7928  void exit_task_namespaces(struct task_struct *tsk);
7929  void switch_task_namespaces(struct task_struct *tsk, struct nsproxy *new);
7930  void free_nsproxy(struct nsproxy *ns);
7931 @@ -70,16 +72,26 @@ int unshare_nsproxy_namespaces(unsigned
7932         struct cred *, struct fs_struct *);
7933  int __init nsproxy_cache_init(void);
7934  
7935 -static inline void put_nsproxy(struct nsproxy *ns)
7936 +#define        get_nsproxy(n)  __get_nsproxy(n, __FILE__, __LINE__)
7937 +
7938 +static inline void __get_nsproxy(struct nsproxy *ns,
7939 +       const char *_file, int _line)
7940  {
7941 -       if (atomic_dec_and_test(&ns->count)) {
7942 -               free_nsproxy(ns);
7943 -       }
7944 +       vxlprintk(VXD_CBIT(space, 0), "get_nsproxy(%p[%u])",
7945 +               ns, atomic_read(&ns->count), _file, _line);
7946 +       atomic_inc(&ns->count);
7947  }
7948  
7949 -static inline void get_nsproxy(struct nsproxy *ns)
7950 +#define        put_nsproxy(n)  __put_nsproxy(n, __FILE__, __LINE__)
7951 +
7952 +static inline void __put_nsproxy(struct nsproxy *ns,
7953 +       const char *_file, int _line)
7954  {
7955 -       atomic_inc(&ns->count);
7956 +       vxlprintk(VXD_CBIT(space, 0), "put_nsproxy(%p[%u])",
7957 +               ns, atomic_read(&ns->count), _file, _line);
7958 +       if (atomic_dec_and_test(&ns->count)) {
7959 +               free_nsproxy(ns);
7960 +       }
7961  }
7962  
7963  #endif
7964 diff -NurpP --minimal linux-3.9.4/include/linux/pid.h linux-3.9.4-vs2.3.6.2/include/linux/pid.h
7965 --- linux-3.9.4/include/linux/pid.h     2013-05-31 13:45:28.000000000 +0000
7966 +++ linux-3.9.4-vs2.3.6.2/include/linux/pid.h   2013-05-31 14:47:11.000000000 +0000
7967 @@ -8,7 +8,8 @@ enum pid_type
7968         PIDTYPE_PID,
7969         PIDTYPE_PGID,
7970         PIDTYPE_SID,
7971 -       PIDTYPE_MAX
7972 +       PIDTYPE_MAX,
7973 +       PIDTYPE_REALPID
7974  };
7975  
7976  /*
7977 @@ -172,6 +173,7 @@ static inline pid_t pid_nr(struct pid *p
7978  }
7979  
7980  pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns);
7981 +pid_t pid_unmapped_nr_ns(struct pid *pid, struct pid_namespace *ns);
7982  pid_t pid_vnr(struct pid *pid);
7983  
7984  #define do_each_pid_task(pid, type, task)                              \
7985 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
7986 --- linux-3.9.4/include/linux/proc_fs.h 2013-05-31 13:45:28.000000000 +0000
7987 +++ linux-3.9.4-vs2.3.6.2/include/linux/proc_fs.h       2013-05-31 14:47:11.000000000 +0000
7988 @@ -58,6 +58,7 @@ struct proc_dir_entry {
7989         nlink_t nlink;
7990         kuid_t uid;
7991         kgid_t gid;
7992 +       int vx_flags;
7993         loff_t size;
7994         const struct inode_operations *proc_iops;
7995         /*
7996 @@ -274,12 +275,18 @@ extern const struct proc_ns_operations p
7997  extern const struct proc_ns_operations userns_operations;
7998  extern const struct proc_ns_operations mntns_operations;
7999  
8000 +struct vx_info;
8001 +struct nx_info;
8002 +
8003  union proc_op {
8004         int (*proc_get_link)(struct dentry *, struct path *);
8005         int (*proc_read)(struct task_struct *task, char *page);
8006         int (*proc_show)(struct seq_file *m,
8007                 struct pid_namespace *ns, struct pid *pid,
8008                 struct task_struct *task);
8009 +       int (*proc_vs_read)(char *page);
8010 +       int (*proc_vxi_read)(struct vx_info *vxi, char *page);
8011 +       int (*proc_nxi_read)(struct nx_info *nxi, char *page);
8012  };
8013  
8014  struct ctl_table_header;
8015 @@ -287,6 +294,7 @@ struct ctl_table;
8016  
8017  struct proc_inode {
8018         struct pid *pid;
8019 +       int vx_flags;
8020         int fd;
8021         union proc_op op;
8022         struct proc_dir_entry *pde;
8023 diff -NurpP --minimal linux-3.9.4/include/linux/quotaops.h linux-3.9.4-vs2.3.6.2/include/linux/quotaops.h
8024 --- linux-3.9.4/include/linux/quotaops.h        2012-12-11 03:30:57.000000000 +0000
8025 +++ linux-3.9.4-vs2.3.6.2/include/linux/quotaops.h      2013-05-31 14:47:11.000000000 +0000
8026 @@ -8,6 +8,7 @@
8027  #define _LINUX_QUOTAOPS_
8028  
8029  #include <linux/fs.h>
8030 +#include <linux/vs_dlimit.h>
8031  
8032  #define DQUOT_SPACE_WARN       0x1
8033  #define DQUOT_SPACE_RESERVE    0x2
8034 @@ -205,11 +206,12 @@ static inline void dquot_drop(struct ino
8035  
8036  static inline int dquot_alloc_inode(const struct inode *inode)
8037  {
8038 -       return 0;
8039 +       return dl_alloc_inode(inode);
8040  }
8041  
8042  static inline void dquot_free_inode(const struct inode *inode)
8043  {
8044 +       dl_free_inode(inode);
8045  }
8046  
8047  static inline int dquot_transfer(struct inode *inode, struct iattr *iattr)
8048 @@ -220,6 +222,10 @@ static inline int dquot_transfer(struct
8049  static inline int __dquot_alloc_space(struct inode *inode, qsize_t number,
8050                 int flags)
8051  {
8052 +       int ret = 0;
8053 +
8054 +       if ((ret = dl_alloc_space(inode, number)))
8055 +               return ret;
8056         if (!(flags & DQUOT_SPACE_RESERVE))
8057                 inode_add_bytes(inode, number);
8058         return 0;
8059 @@ -230,6 +236,7 @@ static inline void __dquot_free_space(st
8060  {
8061         if (!(flags & DQUOT_SPACE_RESERVE))
8062                 inode_sub_bytes(inode, number);
8063 +       dl_free_space(inode, number);
8064  }
8065  
8066  static inline int dquot_claim_space_nodirty(struct inode *inode, qsize_t number)
8067 diff -NurpP --minimal linux-3.9.4/include/linux/sched.h linux-3.9.4-vs2.3.6.2/include/linux/sched.h
8068 --- linux-3.9.4/include/linux/sched.h   2013-05-31 14:22:27.000000000 +0000
8069 +++ linux-3.9.4-vs2.3.6.2/include/linux/sched.h 2013-05-31 14:47:11.000000000 +0000
8070 @@ -1398,6 +1398,14 @@ struct task_struct {
8071  #endif
8072         struct seccomp seccomp;
8073  
8074 +/* vserver context data */
8075 +       struct vx_info *vx_info;
8076 +       struct nx_info *nx_info;
8077 +
8078 +       xid_t xid;
8079 +       nid_t nid;
8080 +       tag_t tag;
8081 +
8082  /* Thread group tracking */
8083         u32 parent_exec_id;
8084         u32 self_exec_id;
8085 @@ -1637,6 +1645,11 @@ struct pid_namespace;
8086  pid_t __task_pid_nr_ns(struct task_struct *task, enum pid_type type,
8087                         struct pid_namespace *ns);
8088  
8089 +#include <linux/vserver/base.h>
8090 +#include <linux/vserver/context.h>
8091 +#include <linux/vserver/debug.h>
8092 +#include <linux/vserver/pid.h>
8093 +
8094  static inline pid_t task_pid_nr(struct task_struct *tsk)
8095  {
8096         return tsk->pid;
8097 @@ -1650,7 +1663,8 @@ static inline pid_t task_pid_nr_ns(struc
8098  
8099  static inline pid_t task_pid_vnr(struct task_struct *tsk)
8100  {
8101 -       return __task_pid_nr_ns(tsk, PIDTYPE_PID, NULL);
8102 +       // return __task_pid_nr_ns(tsk, PIDTYPE_PID, NULL);
8103 +       return vx_map_pid(__task_pid_nr_ns(tsk, PIDTYPE_PID, NULL));
8104  }
8105  
8106  
8107 @@ -1663,7 +1677,7 @@ pid_t task_tgid_nr_ns(struct task_struct
8108  
8109  static inline pid_t task_tgid_vnr(struct task_struct *tsk)
8110  {
8111 -       return pid_vnr(task_tgid(tsk));
8112 +       return vx_map_tgid(pid_vnr(task_tgid(tsk)));
8113  }
8114  
8115  
8116 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
8117 --- linux-3.9.4/include/linux/shmem_fs.h        2012-12-11 03:30:57.000000000 +0000
8118 +++ linux-3.9.4-vs2.3.6.2/include/linux/shmem_fs.h      2013-05-31 14:47:11.000000000 +0000
8119 @@ -9,6 +9,9 @@
8120  
8121  /* inode in-kernel data */
8122  
8123 +#define TMPFS_SUPER_MAGIC      0x01021994
8124 +
8125 +
8126  struct shmem_inode_info {
8127         spinlock_t              lock;
8128         unsigned long           flags;
8129 diff -NurpP --minimal linux-3.9.4/include/linux/stat.h linux-3.9.4-vs2.3.6.2/include/linux/stat.h
8130 --- linux-3.9.4/include/linux/stat.h    2012-12-11 03:30:57.000000000 +0000
8131 +++ linux-3.9.4-vs2.3.6.2/include/linux/stat.h  2013-06-01 08:53:13.000000000 +0000
8132 @@ -25,6 +25,7 @@ struct kstat {
8133         unsigned int    nlink;
8134         kuid_t          uid;
8135         kgid_t          gid;
8136 +       ktag_t          tag;
8137         dev_t           rdev;
8138         loff_t          size;
8139         struct timespec  atime;
8140 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
8141 --- linux-3.9.4/include/linux/sunrpc/auth.h     2013-05-31 13:45:28.000000000 +0000
8142 +++ linux-3.9.4-vs2.3.6.2/include/linux/sunrpc/auth.h   2013-05-31 14:52:57.000000000 +0000
8143 @@ -26,6 +26,7 @@
8144  struct auth_cred {
8145         kuid_t  uid;
8146         kgid_t  gid;
8147 +       ktag_t  tag;
8148         struct group_info *group_info;
8149         const char *principal;
8150         unsigned char machine_cred : 1;
8151 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
8152 --- linux-3.9.4/include/linux/sunrpc/clnt.h     2013-05-31 13:45:28.000000000 +0000
8153 +++ linux-3.9.4-vs2.3.6.2/include/linux/sunrpc/clnt.h   2013-05-31 14:47:11.000000000 +0000
8154 @@ -49,7 +49,8 @@ struct rpc_clnt {
8155         unsigned int            cl_softrtry : 1,/* soft timeouts */
8156                                 cl_discrtry : 1,/* disconnect before retry */
8157                                 cl_autobind : 1,/* use getport() */
8158 -                               cl_chatty   : 1;/* be verbose */
8159 +                               cl_chatty   : 1,/* be verbose */
8160 +                               cl_tag      : 1;/* context tagging */
8161  
8162         struct rpc_rtt *        cl_rtt;         /* RTO estimator data */
8163         const struct rpc_timeout *cl_timeout;   /* Timeout strategy */
8164 diff -NurpP --minimal linux-3.9.4/include/linux/sysfs.h linux-3.9.4-vs2.3.6.2/include/linux/sysfs.h
8165 --- linux-3.9.4/include/linux/sysfs.h   2013-05-31 13:45:28.000000000 +0000
8166 +++ linux-3.9.4-vs2.3.6.2/include/linux/sysfs.h 2013-05-31 14:47:11.000000000 +0000
8167 @@ -19,6 +19,8 @@
8168  #include <linux/kobject_ns.h>
8169  #include <linux/atomic.h>
8170  
8171 +#define SYSFS_SUPER_MAGIC      0x62656572
8172 +
8173  struct kobject;
8174  struct module;
8175  enum kobj_ns_type;
8176 diff -NurpP --minimal linux-3.9.4/include/linux/types.h linux-3.9.4-vs2.3.6.2/include/linux/types.h
8177 --- linux-3.9.4/include/linux/types.h   2013-02-19 13:58:52.000000000 +0000
8178 +++ linux-3.9.4-vs2.3.6.2/include/linux/types.h 2013-05-31 14:47:11.000000000 +0000
8179 @@ -32,6 +32,9 @@ typedef __kernel_uid32_t      uid_t;
8180  typedef __kernel_gid32_t       gid_t;
8181  typedef __kernel_uid16_t        uid16_t;
8182  typedef __kernel_gid16_t        gid16_t;
8183 +typedef unsigned int           xid_t;
8184 +typedef unsigned int           nid_t;
8185 +typedef unsigned int           tag_t;
8186  
8187  typedef unsigned long          uintptr_t;
8188  
8189 diff -NurpP --minimal linux-3.9.4/include/linux/uidgid.h linux-3.9.4-vs2.3.6.2/include/linux/uidgid.h
8190 --- linux-3.9.4/include/linux/uidgid.h  2012-12-11 03:30:57.000000000 +0000
8191 +++ linux-3.9.4-vs2.3.6.2/include/linux/uidgid.h        2013-05-31 14:47:11.000000000 +0000
8192 @@ -23,13 +23,17 @@ typedef struct {
8193         uid_t val;
8194  } kuid_t;
8195  
8196 -
8197  typedef struct {
8198         gid_t val;
8199  } kgid_t;
8200  
8201 +typedef struct {
8202 +       tag_t val;
8203 +} ktag_t;
8204 +
8205  #define KUIDT_INIT(value) (kuid_t){ value }
8206  #define KGIDT_INIT(value) (kgid_t){ value }
8207 +#define KTAGT_INIT(value) (ktag_t){ value }
8208  
8209  static inline uid_t __kuid_val(kuid_t uid)
8210  {
8211 @@ -41,10 +45,16 @@ static inline gid_t __kgid_val(kgid_t gi
8212         return gid.val;
8213  }
8214  
8215 +static inline tag_t __ktag_val(ktag_t tag)
8216 +{
8217 +       return tag.val;
8218 +}
8219 +
8220  #else
8221  
8222  typedef uid_t kuid_t;
8223  typedef gid_t kgid_t;
8224 +typedef tag_t ktag_t;
8225  
8226  static inline uid_t __kuid_val(kuid_t uid)
8227  {
8228 @@ -56,16 +66,24 @@ static inline gid_t __kgid_val(kgid_t gi
8229         return gid;
8230  }
8231  
8232 +static inline tag_t __ktag_val(ktag_t tag)
8233 +{
8234 +       return tag;
8235 +}
8236 +
8237  #define KUIDT_INIT(value) ((kuid_t) value )
8238  #define KGIDT_INIT(value) ((kgid_t) value )
8239 +#define KTAGT_INIT(value) ((ktag_t) value )
8240  
8241  #endif
8242  
8243  #define GLOBAL_ROOT_UID KUIDT_INIT(0)
8244  #define GLOBAL_ROOT_GID KGIDT_INIT(0)
8245 +#define GLOBAL_ROOT_TAG KTAGT_INIT(0)
8246  
8247  #define INVALID_UID KUIDT_INIT(-1)
8248  #define INVALID_GID KGIDT_INIT(-1)
8249 +#define INVALID_TAG KTAGT_INIT(-1)
8250  
8251  static inline bool uid_eq(kuid_t left, kuid_t right)
8252  {
8253 @@ -77,6 +95,11 @@ static inline bool gid_eq(kgid_t left, k
8254         return __kgid_val(left) == __kgid_val(right);
8255  }
8256  
8257 +static inline bool tag_eq(ktag_t left, ktag_t right)
8258 +{
8259 +       return __ktag_val(left) == __ktag_val(right);
8260 +}
8261 +
8262  static inline bool uid_gt(kuid_t left, kuid_t right)
8263  {
8264         return __kuid_val(left) > __kuid_val(right);
8265 @@ -127,13 +150,21 @@ static inline bool gid_valid(kgid_t gid)
8266         return !gid_eq(gid, INVALID_GID);
8267  }
8268  
8269 +static inline bool tag_valid(ktag_t tag)
8270 +{
8271 +       return !tag_eq(tag, INVALID_TAG);
8272 +}
8273 +
8274  #ifdef CONFIG_USER_NS
8275  
8276  extern kuid_t make_kuid(struct user_namespace *from, uid_t uid);
8277  extern kgid_t make_kgid(struct user_namespace *from, gid_t gid);
8278 +extern krag_t make_ktag(struct user_namespace *from, gid_t gid);
8279  
8280  extern uid_t from_kuid(struct user_namespace *to, kuid_t uid);
8281  extern gid_t from_kgid(struct user_namespace *to, kgid_t gid);
8282 +extern tag_t from_ktag(struct user_namespace *to, ktag_t tag);
8283 +
8284  extern uid_t from_kuid_munged(struct user_namespace *to, kuid_t uid);
8285  extern gid_t from_kgid_munged(struct user_namespace *to, kgid_t gid);
8286  
8287 @@ -159,6 +190,11 @@ static inline kgid_t make_kgid(struct us
8288         return KGIDT_INIT(gid);
8289  }
8290  
8291 +static inline ktag_t make_ktag(struct user_namespace *from, tag_t tag)
8292 +{
8293 +       return KTAGT_INIT(tag);
8294 +}
8295 +
8296  static inline uid_t from_kuid(struct user_namespace *to, kuid_t kuid)
8297  {
8298         return __kuid_val(kuid);
8299 @@ -169,6 +205,11 @@ static inline gid_t from_kgid(struct use
8300         return __kgid_val(kgid);
8301  }
8302  
8303 +static inline tag_t from_ktag(struct user_namespace *to, ktag_t ktag)
8304 +{
8305 +       return __ktag_val(ktag);
8306 +}
8307 +
8308  static inline uid_t from_kuid_munged(struct user_namespace *to, kuid_t kuid)
8309  {
8310         uid_t uid = from_kuid(to, kuid);
8311 diff -NurpP --minimal linux-3.9.4/include/linux/vroot.h linux-3.9.4-vs2.3.6.2/include/linux/vroot.h
8312 --- linux-3.9.4/include/linux/vroot.h   1970-01-01 00:00:00.000000000 +0000
8313 +++ linux-3.9.4-vs2.3.6.2/include/linux/vroot.h 2013-05-31 14:47:11.000000000 +0000
8314 @@ -0,0 +1,51 @@
8315 +
8316 +/*
8317 + * include/linux/vroot.h
8318 + *
8319 + * written by Herbert Pötzl, 9/11/2002
8320 + * ported to 2.6 by Herbert Pötzl, 30/12/2004
8321 + *
8322 + * Copyright (C) 2002-2007 by Herbert Pötzl.
8323 + * Redistribution of this file is permitted under the
8324 + * GNU General Public License.
8325 + */
8326 +
8327 +#ifndef _LINUX_VROOT_H
8328 +#define _LINUX_VROOT_H
8329 +
8330 +
8331 +#ifdef __KERNEL__
8332 +
8333 +/* Possible states of device */
8334 +enum {
8335 +       Vr_unbound,
8336 +       Vr_bound,
8337 +};
8338 +
8339 +struct vroot_device {
8340 +       int             vr_number;
8341 +       int             vr_refcnt;
8342 +
8343 +       struct semaphore        vr_ctl_mutex;
8344 +       struct block_device    *vr_device;
8345 +       int                     vr_state;
8346 +};
8347 +
8348 +
8349 +typedef struct block_device *(vroot_grb_func)(struct block_device *);
8350 +
8351 +extern int register_vroot_grb(vroot_grb_func *);
8352 +extern int unregister_vroot_grb(vroot_grb_func *);
8353 +
8354 +#endif /* __KERNEL__ */
8355 +
8356 +#define MAX_VROOT_DEFAULT      8
8357 +
8358 +/*
8359 + * IOCTL commands --- we will commandeer 0x56 ('V')
8360 + */
8361 +
8362 +#define VROOT_SET_DEV          0x5600
8363 +#define VROOT_CLR_DEV          0x5601
8364 +
8365 +#endif /* _LINUX_VROOT_H */
8366 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
8367 --- linux-3.9.4/include/linux/vs_base.h 1970-01-01 00:00:00.000000000 +0000
8368 +++ linux-3.9.4-vs2.3.6.2/include/linux/vs_base.h       2013-05-31 14:47:11.000000000 +0000
8369 @@ -0,0 +1,10 @@
8370 +#ifndef _VS_BASE_H
8371 +#define _VS_BASE_H
8372 +
8373 +#include "vserver/base.h"
8374 +#include "vserver/check.h"
8375 +#include "vserver/debug.h"
8376 +
8377 +#else
8378 +#warning duplicate inclusion
8379 +#endif
8380 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
8381 --- linux-3.9.4/include/linux/vs_context.h      1970-01-01 00:00:00.000000000 +0000
8382 +++ linux-3.9.4-vs2.3.6.2/include/linux/vs_context.h    2013-05-31 14:47:11.000000000 +0000
8383 @@ -0,0 +1,242 @@
8384 +#ifndef _VS_CONTEXT_H
8385 +#define _VS_CONTEXT_H
8386 +
8387 +#include "vserver/base.h"
8388 +#include "vserver/check.h"
8389 +#include "vserver/context.h"
8390 +#include "vserver/history.h"
8391 +#include "vserver/debug.h"
8392 +
8393 +#include <linux/sched.h>
8394 +
8395 +
8396 +#define get_vx_info(i) __get_vx_info(i, __FILE__, __LINE__, __HERE__)
8397 +
8398 +static inline struct vx_info *__get_vx_info(struct vx_info *vxi,
8399 +       const char *_file, int _line, void *_here)
8400 +{
8401 +       if (!vxi)
8402 +               return NULL;
8403 +
8404 +       vxlprintk(VXD_CBIT(xid, 2), "get_vx_info(%p[#%d.%d])",
8405 +               vxi, vxi ? vxi->vx_id : 0,
8406 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
8407 +               _file, _line);
8408 +       __vxh_get_vx_info(vxi, _here);
8409 +
8410 +       atomic_inc(&vxi->vx_usecnt);
8411 +       return vxi;
8412 +}
8413 +
8414 +
8415 +extern void free_vx_info(struct vx_info *);
8416 +
8417 +#define put_vx_info(i) __put_vx_info(i, __FILE__, __LINE__, __HERE__)
8418 +
8419 +static inline void __put_vx_info(struct vx_info *vxi,
8420 +       const char *_file, int _line, void *_here)
8421 +{
8422 +       if (!vxi)
8423 +               return;
8424 +
8425 +       vxlprintk(VXD_CBIT(xid, 2), "put_vx_info(%p[#%d.%d])",
8426 +               vxi, vxi ? vxi->vx_id : 0,
8427 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
8428 +               _file, _line);
8429 +       __vxh_put_vx_info(vxi, _here);
8430 +
8431 +       if (atomic_dec_and_test(&vxi->vx_usecnt))
8432 +               free_vx_info(vxi);
8433 +}
8434 +
8435 +
8436 +#define init_vx_info(p, i) \
8437 +       __init_vx_info(p, i, __FILE__, __LINE__, __HERE__)
8438 +
8439 +static inline void __init_vx_info(struct vx_info **vxp, struct vx_info *vxi,
8440 +       const char *_file, int _line, void *_here)
8441 +{
8442 +       if (vxi) {
8443 +               vxlprintk(VXD_CBIT(xid, 3),
8444 +                       "init_vx_info(%p[#%d.%d])",
8445 +                       vxi, vxi ? vxi->vx_id : 0,
8446 +                       vxi ? atomic_read(&vxi->vx_usecnt) : 0,
8447 +                       _file, _line);
8448 +               __vxh_init_vx_info(vxi, vxp, _here);
8449 +
8450 +               atomic_inc(&vxi->vx_usecnt);
8451 +       }
8452 +       *vxp = vxi;
8453 +}
8454 +
8455 +
8456 +#define set_vx_info(p, i) \
8457 +       __set_vx_info(p, i, __FILE__, __LINE__, __HERE__)
8458 +
8459 +static inline void __set_vx_info(struct vx_info **vxp, struct vx_info *vxi,
8460 +       const char *_file, int _line, void *_here)
8461 +{
8462 +       struct vx_info *vxo;
8463 +
8464 +       if (!vxi)
8465 +               return;
8466 +
8467 +       vxlprintk(VXD_CBIT(xid, 3), "set_vx_info(%p[#%d.%d])",
8468 +               vxi, vxi ? vxi->vx_id : 0,
8469 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
8470 +               _file, _line);
8471 +       __vxh_set_vx_info(vxi, vxp, _here);
8472 +
8473 +       atomic_inc(&vxi->vx_usecnt);
8474 +       vxo = xchg(vxp, vxi);
8475 +       BUG_ON(vxo);
8476 +}
8477 +
8478 +
8479 +#define clr_vx_info(p) __clr_vx_info(p, __FILE__, __LINE__, __HERE__)
8480 +
8481 +static inline void __clr_vx_info(struct vx_info **vxp,
8482 +       const char *_file, int _line, void *_here)
8483 +{
8484 +       struct vx_info *vxo;
8485 +
8486 +       vxo = xchg(vxp, NULL);
8487 +       if (!vxo)
8488 +               return;
8489 +
8490 +       vxlprintk(VXD_CBIT(xid, 3), "clr_vx_info(%p[#%d.%d])",
8491 +               vxo, vxo ? vxo->vx_id : 0,
8492 +               vxo ? atomic_read(&vxo->vx_usecnt) : 0,
8493 +               _file, _line);
8494 +       __vxh_clr_vx_info(vxo, vxp, _here);
8495 +
8496 +       if (atomic_dec_and_test(&vxo->vx_usecnt))
8497 +               free_vx_info(vxo);
8498 +}
8499 +
8500 +
8501 +#define claim_vx_info(v, p) \
8502 +       __claim_vx_info(v, p, __FILE__, __LINE__, __HERE__)
8503 +
8504 +static inline void __claim_vx_info(struct vx_info *vxi,
8505 +       struct task_struct *task,
8506 +       const char *_file, int _line, void *_here)
8507 +{
8508 +       vxlprintk(VXD_CBIT(xid, 3), "claim_vx_info(%p[#%d.%d.%d]) %p",
8509 +               vxi, vxi ? vxi->vx_id : 0,
8510 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
8511 +               vxi ? atomic_read(&vxi->vx_tasks) : 0,
8512 +               task, _file, _line);
8513 +       __vxh_claim_vx_info(vxi, task, _here);
8514 +
8515 +       atomic_inc(&vxi->vx_tasks);
8516 +}
8517 +
8518 +
8519 +extern void unhash_vx_info(struct vx_info *);
8520 +
8521 +#define release_vx_info(v, p) \
8522 +       __release_vx_info(v, p, __FILE__, __LINE__, __HERE__)
8523 +
8524 +static inline void __release_vx_info(struct vx_info *vxi,
8525 +       struct task_struct *task,
8526 +       const char *_file, int _line, void *_here)
8527 +{
8528 +       vxlprintk(VXD_CBIT(xid, 3), "release_vx_info(%p[#%d.%d.%d]) %p",
8529 +               vxi, vxi ? vxi->vx_id : 0,
8530 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
8531 +               vxi ? atomic_read(&vxi->vx_tasks) : 0,
8532 +               task, _file, _line);
8533 +       __vxh_release_vx_info(vxi, task, _here);
8534 +
8535 +       might_sleep();
8536 +
8537 +       if (atomic_dec_and_test(&vxi->vx_tasks))
8538 +               unhash_vx_info(vxi);
8539 +}
8540 +
8541 +
8542 +#define task_get_vx_info(p) \
8543 +       __task_get_vx_info(p, __FILE__, __LINE__, __HERE__)
8544 +
8545 +static inline struct vx_info *__task_get_vx_info(struct task_struct *p,
8546 +       const char *_file, int _line, void *_here)
8547 +{
8548 +       struct vx_info *vxi;
8549 +
8550 +       task_lock(p);
8551 +       vxlprintk(VXD_CBIT(xid, 5), "task_get_vx_info(%p)",
8552 +               p, _file, _line);
8553 +       vxi = __get_vx_info(p->vx_info, _file, _line, _here);
8554 +       task_unlock(p);
8555 +       return vxi;
8556 +}
8557 +
8558 +
8559 +static inline void __wakeup_vx_info(struct vx_info *vxi)
8560 +{
8561 +       if (waitqueue_active(&vxi->vx_wait))
8562 +               wake_up_interruptible(&vxi->vx_wait);
8563 +}
8564 +
8565 +
8566 +#define enter_vx_info(v, s) __enter_vx_info(v, s, __FILE__, __LINE__)
8567 +
8568 +static inline void __enter_vx_info(struct vx_info *vxi,
8569 +       struct vx_info_save *vxis, const char *_file, int _line)
8570 +{
8571 +       vxlprintk(VXD_CBIT(xid, 5), "enter_vx_info(%p[#%d],%p) %p[#%d,%p]",
8572 +               vxi, vxi ? vxi->vx_id : 0, vxis, current,
8573 +               current->xid, current->vx_info, _file, _line);
8574 +       vxis->vxi = xchg(&current->vx_info, vxi);
8575 +       vxis->xid = current->xid;
8576 +       current->xid = vxi ? vxi->vx_id : 0;
8577 +}
8578 +
8579 +#define leave_vx_info(s) __leave_vx_info(s, __FILE__, __LINE__)
8580 +
8581 +static inline void __leave_vx_info(struct vx_info_save *vxis,
8582 +       const char *_file, int _line)
8583 +{
8584 +       vxlprintk(VXD_CBIT(xid, 5), "leave_vx_info(%p[#%d,%p]) %p[#%d,%p]",
8585 +               vxis, vxis->xid, vxis->vxi, current,
8586 +               current->xid, current->vx_info, _file, _line);
8587 +       (void)xchg(&current->vx_info, vxis->vxi);
8588 +       current->xid = vxis->xid;
8589 +}
8590 +
8591 +
8592 +static inline void __enter_vx_admin(struct vx_info_save *vxis)
8593 +{
8594 +       vxis->vxi = xchg(&current->vx_info, NULL);
8595 +       vxis->xid = xchg(&current->xid, (xid_t)0);
8596 +}
8597 +
8598 +static inline void __leave_vx_admin(struct vx_info_save *vxis)
8599 +{
8600 +       (void)xchg(&current->xid, vxis->xid);
8601 +       (void)xchg(&current->vx_info, vxis->vxi);
8602 +}
8603 +
8604 +#define task_is_init(p) \
8605 +       __task_is_init(p, __FILE__, __LINE__, __HERE__)
8606 +
8607 +static inline int __task_is_init(struct task_struct *p,
8608 +       const char *_file, int _line, void *_here)
8609 +{
8610 +       int is_init = is_global_init(p);
8611 +
8612 +       task_lock(p);
8613 +       if (p->vx_info)
8614 +               is_init = p->vx_info->vx_initpid == p->pid;
8615 +       task_unlock(p);
8616 +       return is_init;
8617 +}
8618 +
8619 +extern void exit_vx_info(struct task_struct *, int);
8620 +extern void exit_vx_info_early(struct task_struct *, int);
8621 +
8622 +
8623 +#else
8624 +#warning duplicate inclusion
8625 +#endif
8626 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
8627 --- linux-3.9.4/include/linux/vs_cowbl.h        1970-01-01 00:00:00.000000000 +0000
8628 +++ linux-3.9.4-vs2.3.6.2/include/linux/vs_cowbl.h      2013-05-31 14:47:11.000000000 +0000
8629 @@ -0,0 +1,48 @@
8630 +#ifndef _VS_COWBL_H
8631 +#define _VS_COWBL_H
8632 +
8633 +#include <linux/fs.h>
8634 +#include <linux/dcache.h>
8635 +#include <linux/namei.h>
8636 +#include <linux/slab.h>
8637 +
8638 +extern struct dentry *cow_break_link(const char *pathname);
8639 +
8640 +static inline int cow_check_and_break(struct path *path)
8641 +{
8642 +       struct inode *inode = path->dentry->d_inode;
8643 +       int error = 0;
8644 +
8645 +       /* do we need this check? */
8646 +       if (IS_RDONLY(inode))
8647 +               return -EROFS;
8648 +
8649 +       if (IS_COW(inode)) {
8650 +               if (IS_COW_LINK(inode)) {
8651 +                       struct dentry *new_dentry, *old_dentry = path->dentry;
8652 +                       char *pp, *buf;
8653 +
8654 +                       buf = kmalloc(PATH_MAX, GFP_KERNEL);
8655 +                       if (!buf) {
8656 +                               return -ENOMEM;
8657 +                       }
8658 +                       pp = d_path(path, buf, PATH_MAX);
8659 +                       new_dentry = cow_break_link(pp);
8660 +                       kfree(buf);
8661 +                       if (!IS_ERR(new_dentry)) {
8662 +                               path->dentry = new_dentry;
8663 +                               dput(old_dentry);
8664 +                       } else
8665 +                               error = PTR_ERR(new_dentry);
8666 +               } else {
8667 +                       inode->i_flags &= ~(S_IXUNLINK | S_IMMUTABLE);
8668 +                       inode->i_ctime = CURRENT_TIME;
8669 +                       mark_inode_dirty(inode);
8670 +               }
8671 +       }
8672 +       return error;
8673 +}
8674 +
8675 +#else
8676 +#warning duplicate inclusion
8677 +#endif
8678 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
8679 --- linux-3.9.4/include/linux/vs_cvirt.h        1970-01-01 00:00:00.000000000 +0000
8680 +++ linux-3.9.4-vs2.3.6.2/include/linux/vs_cvirt.h      2013-05-31 14:47:11.000000000 +0000
8681 @@ -0,0 +1,50 @@
8682 +#ifndef _VS_CVIRT_H
8683 +#define _VS_CVIRT_H
8684 +
8685 +#include "vserver/cvirt.h"
8686 +#include "vserver/context.h"
8687 +#include "vserver/base.h"
8688 +#include "vserver/check.h"
8689 +#include "vserver/debug.h"
8690 +
8691 +
8692 +static inline void vx_activate_task(struct task_struct *p)
8693 +{
8694 +       struct vx_info *vxi;
8695 +
8696 +       if ((vxi = p->vx_info)) {
8697 +               vx_update_load(vxi);
8698 +               atomic_inc(&vxi->cvirt.nr_running);
8699 +       }
8700 +}
8701 +
8702 +static inline void vx_deactivate_task(struct task_struct *p)
8703 +{
8704 +       struct vx_info *vxi;
8705 +
8706 +       if ((vxi = p->vx_info)) {
8707 +               vx_update_load(vxi);
8708 +               atomic_dec(&vxi->cvirt.nr_running);
8709 +       }
8710 +}
8711 +
8712 +static inline void vx_uninterruptible_inc(struct task_struct *p)
8713 +{
8714 +       struct vx_info *vxi;
8715 +
8716 +       if ((vxi = p->vx_info))
8717 +               atomic_inc(&vxi->cvirt.nr_uninterruptible);
8718 +}
8719 +
8720 +static inline void vx_uninterruptible_dec(struct task_struct *p)
8721 +{
8722 +       struct vx_info *vxi;
8723 +
8724 +       if ((vxi = p->vx_info))
8725 +               atomic_dec(&vxi->cvirt.nr_uninterruptible);
8726 +}
8727 +
8728 +
8729 +#else
8730 +#warning duplicate inclusion
8731 +#endif
8732 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
8733 --- linux-3.9.4/include/linux/vs_device.h       1970-01-01 00:00:00.000000000 +0000
8734 +++ linux-3.9.4-vs2.3.6.2/include/linux/vs_device.h     2013-05-31 14:47:11.000000000 +0000
8735 @@ -0,0 +1,45 @@
8736 +#ifndef _VS_DEVICE_H
8737 +#define _VS_DEVICE_H
8738 +
8739 +#include "vserver/base.h"
8740 +#include "vserver/device.h"
8741 +#include "vserver/debug.h"
8742 +
8743 +
8744 +#ifdef CONFIG_VSERVER_DEVICE
8745 +
8746 +int vs_map_device(struct vx_info *, dev_t, dev_t *, umode_t);
8747 +
8748 +#define vs_device_perm(v, d, m, p) \
8749 +       ((vs_map_device(current_vx_info(), d, NULL, m) & (p)) == (p))
8750 +
8751 +#else
8752 +
8753 +static inline
8754 +int vs_map_device(struct vx_info *vxi,
8755 +       dev_t device, dev_t *target, umode_t mode)
8756 +{
8757 +       if (target)
8758 +               *target = device;
8759 +       return ~0;
8760 +}
8761 +
8762 +#define vs_device_perm(v, d, m, p) ((p) == (p))
8763 +
8764 +#endif
8765 +
8766 +
8767 +#define vs_map_chrdev(d, t, p) \
8768 +       ((vs_map_device(current_vx_info(), d, t, S_IFCHR) & (p)) == (p))
8769 +#define vs_map_blkdev(d, t, p) \
8770 +       ((vs_map_device(current_vx_info(), d, t, S_IFBLK) & (p)) == (p))
8771 +
8772 +#define vs_chrdev_perm(d, p) \
8773 +       vs_device_perm(current_vx_info(), d, S_IFCHR, p)
8774 +#define vs_blkdev_perm(d, p) \
8775 +       vs_device_perm(current_vx_info(), d, S_IFBLK, p)
8776 +
8777 +
8778 +#else
8779 +#warning duplicate inclusion
8780 +#endif
8781 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
8782 --- linux-3.9.4/include/linux/vs_dlimit.h       1970-01-01 00:00:00.000000000 +0000
8783 +++ linux-3.9.4-vs2.3.6.2/include/linux/vs_dlimit.h     2013-05-31 14:47:11.000000000 +0000
8784 @@ -0,0 +1,215 @@
8785 +#ifndef _VS_DLIMIT_H
8786 +#define _VS_DLIMIT_H
8787 +
8788 +#include <linux/fs.h>
8789 +
8790 +#include "vserver/dlimit.h"
8791 +#include "vserver/base.h"
8792 +#include "vserver/debug.h"
8793 +
8794 +
8795 +#define get_dl_info(i) __get_dl_info(i, __FILE__, __LINE__)
8796 +
8797 +static inline struct dl_info *__get_dl_info(struct dl_info *dli,
8798 +       const char *_file, int _line)
8799 +{
8800 +       if (!dli)
8801 +               return NULL;
8802 +       vxlprintk(VXD_CBIT(dlim, 4), "get_dl_info(%p[#%d.%d])",
8803 +               dli, dli ? dli->dl_tag : 0,
8804 +               dli ? atomic_read(&dli->dl_usecnt) : 0,
8805 +               _file, _line);
8806 +       atomic_inc(&dli->dl_usecnt);
8807 +       return dli;
8808 +}
8809 +
8810 +
8811 +#define free_dl_info(i) \
8812 +       call_rcu(&(i)->dl_rcu, rcu_free_dl_info)
8813 +
8814 +#define put_dl_info(i) __put_dl_info(i, __FILE__, __LINE__)
8815 +
8816 +static inline void __put_dl_info(struct dl_info *dli,
8817 +       const char *_file, int _line)
8818 +{
8819 +       if (!dli)
8820 +               return;
8821 +       vxlprintk(VXD_CBIT(dlim, 4), "put_dl_info(%p[#%d.%d])",
8822 +               dli, dli ? dli->dl_tag : 0,
8823 +               dli ? atomic_read(&dli->dl_usecnt) : 0,
8824 +               _file, _line);
8825 +       if (atomic_dec_and_test(&dli->dl_usecnt))
8826 +               free_dl_info(dli);
8827 +}
8828 +
8829 +
8830 +#define __dlimit_char(d)       ((d) ? '*' : ' ')
8831 +
8832 +static inline int __dl_alloc_space(struct super_block *sb,
8833 +       tag_t tag, dlsize_t nr, const char *file, int line)
8834 +{
8835 +       struct dl_info *dli = NULL;
8836 +       int ret = 0;
8837 +
8838 +       if (nr == 0)
8839 +               goto out;
8840 +       dli = locate_dl_info(sb, tag);
8841 +       if (!dli)
8842 +               goto out;
8843 +
8844 +       spin_lock(&dli->dl_lock);
8845 +       ret = (dli->dl_space_used + nr > dli->dl_space_total);
8846 +       if (!ret)
8847 +               dli->dl_space_used += nr;
8848 +       spin_unlock(&dli->dl_lock);
8849 +       put_dl_info(dli);
8850 +out:
8851 +       vxlprintk(VXD_CBIT(dlim, 1),
8852 +               "ALLOC (%p,#%d)%c %lld bytes (%d)",
8853 +               sb, tag, __dlimit_char(dli), (long long)nr,
8854 +               ret, file, line);
8855 +       return ret ? -ENOSPC : 0;
8856 +}
8857 +
8858 +static inline void __dl_free_space(struct super_block *sb,
8859 +       tag_t tag, dlsize_t nr, const char *_file, int _line)
8860 +{
8861 +       struct dl_info *dli = NULL;
8862 +
8863 +       if (nr == 0)
8864 +               goto out;
8865 +       dli = locate_dl_info(sb, tag);
8866 +       if (!dli)
8867 +               goto out;
8868 +
8869 +       spin_lock(&dli->dl_lock);
8870 +       if (dli->dl_space_used > nr)
8871 +               dli->dl_space_used -= nr;
8872 +       else
8873 +               dli->dl_space_used = 0;
8874 +       spin_unlock(&dli->dl_lock);
8875 +       put_dl_info(dli);
8876 +out:
8877 +       vxlprintk(VXD_CBIT(dlim, 1),
8878 +               "FREE  (%p,#%d)%c %lld bytes",
8879 +               sb, tag, __dlimit_char(dli), (long long)nr,
8880 +               _file, _line);
8881 +}
8882 +
8883 +static inline int __dl_alloc_inode(struct super_block *sb,
8884 +       tag_t tag, const char *_file, int _line)
8885 +{
8886 +       struct dl_info *dli;
8887 +       int ret = 0;
8888 +
8889 +       dli = locate_dl_info(sb, tag);
8890 +       if (!dli)
8891 +               goto out;
8892 +
8893 +       spin_lock(&dli->dl_lock);
8894 +       dli->dl_inodes_used++;
8895 +       ret = (dli->dl_inodes_used > dli->dl_inodes_total);
8896 +       spin_unlock(&dli->dl_lock);
8897 +       put_dl_info(dli);
8898 +out:
8899 +       vxlprintk(VXD_CBIT(dlim, 0),
8900 +               "ALLOC (%p,#%d)%c inode (%d)",
8901 +               sb, tag, __dlimit_char(dli), ret, _file, _line);
8902 +       return ret ? -ENOSPC : 0;
8903 +}
8904 +
8905 +static inline void __dl_free_inode(struct super_block *sb,
8906 +       tag_t tag, const char *_file, int _line)
8907 +{
8908 +       struct dl_info *dli;
8909 +
8910 +       dli = locate_dl_info(sb, tag);
8911 +       if (!dli)
8912 +               goto out;
8913 +
8914 +       spin_lock(&dli->dl_lock);
8915 +       if (dli->dl_inodes_used > 1)
8916 +               dli->dl_inodes_used--;
8917 +       else
8918 +               dli->dl_inodes_used = 0;
8919 +       spin_unlock(&dli->dl_lock);
8920 +       put_dl_info(dli);
8921 +out:
8922 +       vxlprintk(VXD_CBIT(dlim, 0),
8923 +               "FREE  (%p,#%d)%c inode",
8924 +               sb, tag, __dlimit_char(dli), _file, _line);
8925 +}
8926 +
8927 +static inline void __dl_adjust_block(struct super_block *sb, tag_t tag,
8928 +       unsigned long long *free_blocks, unsigned long long *root_blocks,
8929 +       const char *_file, int _line)
8930 +{
8931 +       struct dl_info *dli;
8932 +       uint64_t broot, bfree;
8933 +
8934 +       dli = locate_dl_info(sb, tag);
8935 +       if (!dli)
8936 +               return;
8937 +
8938 +       spin_lock(&dli->dl_lock);
8939 +       broot = (dli->dl_space_total -
8940 +               (dli->dl_space_total >> 10) * dli->dl_nrlmult)
8941 +               >> sb->s_blocksize_bits;
8942 +       bfree = (dli->dl_space_total - dli->dl_space_used)
8943 +                       >> sb->s_blocksize_bits;
8944 +       spin_unlock(&dli->dl_lock);
8945 +
8946 +       vxlprintk(VXD_CBIT(dlim, 2),
8947 +               "ADJUST: %lld,%lld on %lld,%lld [mult=%d]",
8948 +               (long long)bfree, (long long)broot,
8949 +               *free_blocks, *root_blocks, dli->dl_nrlmult,
8950 +               _file, _line);
8951 +       if (free_blocks) {
8952 +               if (*free_blocks > bfree)
8953 +                       *free_blocks = bfree;
8954 +       }
8955 +       if (root_blocks) {
8956 +               if (*root_blocks > broot)
8957 +                       *root_blocks = broot;
8958 +       }
8959 +       put_dl_info(dli);
8960 +}
8961 +
8962 +#define dl_prealloc_space(in, bytes) \
8963 +       __dl_alloc_space((in)->i_sb, i_tag_read(in), (dlsize_t)(bytes), \
8964 +               __FILE__, __LINE__ )
8965 +
8966 +#define dl_alloc_space(in, bytes) \
8967 +       __dl_alloc_space((in)->i_sb, i_tag_read(in), (dlsize_t)(bytes), \
8968 +               __FILE__, __LINE__ )
8969 +
8970 +#define dl_reserve_space(in, bytes) \
8971 +       __dl_alloc_space((in)->i_sb, i_tag_read(in), (dlsize_t)(bytes), \
8972 +               __FILE__, __LINE__ )
8973 +
8974 +#define dl_claim_space(in, bytes) (0)
8975 +
8976 +#define dl_release_space(in, bytes) \
8977 +       __dl_free_space((in)->i_sb, i_tag_read(in), (dlsize_t)(bytes), \
8978 +               __FILE__, __LINE__ )
8979 +
8980 +#define dl_free_space(in, bytes) \
8981 +       __dl_free_space((in)->i_sb, i_tag_read(in), (dlsize_t)(bytes), \
8982 +               __FILE__, __LINE__ )
8983 +
8984 +
8985 +
8986 +#define dl_alloc_inode(in) \
8987 +       __dl_alloc_inode((in)->i_sb, i_tag_read(in), __FILE__, __LINE__ )
8988 +
8989 +#define dl_free_inode(in) \
8990 +       __dl_free_inode((in)->i_sb, i_tag_read(in), __FILE__, __LINE__ )
8991 +
8992 +
8993 +#define dl_adjust_block(sb, tag, fb, rb) \
8994 +       __dl_adjust_block(sb, tag, fb, rb, __FILE__, __LINE__ )
8995 +
8996 +
8997 +#else
8998 +#warning duplicate inclusion
8999 +#endif
9000 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
9001 --- linux-3.9.4/include/linux/vs_inet.h 1970-01-01 00:00:00.000000000 +0000
9002 +++ linux-3.9.4-vs2.3.6.2/include/linux/vs_inet.h       2013-05-31 14:47:11.000000000 +0000
9003 @@ -0,0 +1,364 @@
9004 +#ifndef _VS_INET_H
9005 +#define _VS_INET_H
9006 +
9007 +#include "vserver/base.h"
9008 +#include "vserver/network.h"
9009 +#include "vserver/debug.h"
9010 +
9011 +#define IPI_LOOPBACK   htonl(INADDR_LOOPBACK)
9012 +
9013 +#define NXAV4(a)       NIPQUAD((a)->ip[0]), NIPQUAD((a)->ip[1]), \
9014 +                       NIPQUAD((a)->mask), (a)->type
9015 +#define NXAV4_FMT      "[" NIPQUAD_FMT "-" NIPQUAD_FMT "/" NIPQUAD_FMT ":%04x]"
9016 +
9017 +#define NIPQUAD(addr) \
9018 +       ((unsigned char *)&addr)[0], \
9019 +       ((unsigned char *)&addr)[1], \
9020 +       ((unsigned char *)&addr)[2], \
9021 +       ((unsigned char *)&addr)[3]
9022 +
9023 +#define NIPQUAD_FMT "%u.%u.%u.%u"
9024 +
9025 +
9026 +static inline
9027 +int v4_addr_match(struct nx_addr_v4 *nxa, __be32 addr, uint16_t tmask)
9028 +{
9029 +       __be32 ip = nxa->ip[0].s_addr;
9030 +       __be32 mask = nxa->mask.s_addr;
9031 +       __be32 bcast = ip | ~mask;
9032 +       int ret = 0;
9033 +
9034 +       switch (nxa->type & tmask) {
9035 +       case NXA_TYPE_MASK:
9036 +               ret = (ip == (addr & mask));
9037 +               break;
9038 +       case NXA_TYPE_ADDR:
9039 +               ret = 3;
9040 +               if (addr == ip)
9041 +                       break;
9042 +               /* fall through to broadcast */
9043 +       case NXA_MOD_BCAST:
9044 +               ret = ((tmask & NXA_MOD_BCAST) && (addr == bcast));
9045 +               break;
9046 +       case NXA_TYPE_RANGE:
9047 +               ret = ((nxa->ip[0].s_addr <= addr) &&
9048 +                       (nxa->ip[1].s_addr > addr));
9049 +               break;
9050 +       case NXA_TYPE_ANY:
9051 +               ret = 2;
9052 +               break;
9053 +       }
9054 +
9055 +       vxdprintk(VXD_CBIT(net, 0),
9056 +               "v4_addr_match(%p" NXAV4_FMT "," NIPQUAD_FMT ",%04x) = %d",
9057 +               nxa, NXAV4(nxa), NIPQUAD(addr), tmask, ret);
9058 +       return ret;
9059 +}
9060 +
9061 +static inline
9062 +int v4_addr_in_nx_info(struct nx_info *nxi, __be32 addr, uint16_t tmask)
9063 +{
9064 +       struct nx_addr_v4 *nxa;
9065 +       unsigned long irqflags;
9066 +       int ret = 1;
9067 +
9068 +       if (!nxi)
9069 +               goto out;
9070 +
9071 +       ret = 2;
9072 +       /* allow 127.0.0.1 when remapping lback */
9073 +       if ((tmask & NXA_LOOPBACK) &&
9074 +               (addr == IPI_LOOPBACK) &&
9075 +               nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
9076 +               goto out;
9077 +       ret = 3;
9078 +       /* check for lback address */
9079 +       if ((tmask & NXA_MOD_LBACK) &&
9080 +               (nxi->v4_lback.s_addr == addr))
9081 +               goto out;
9082 +       ret = 4;
9083 +       /* check for broadcast address */
9084 +       if ((tmask & NXA_MOD_BCAST) &&
9085 +               (nxi->v4_bcast.s_addr == addr))
9086 +               goto out;
9087 +       ret = 5;
9088 +
9089 +       /* check for v4 addresses */
9090 +       spin_lock_irqsave(&nxi->addr_lock, irqflags);
9091 +       for (nxa = &nxi->v4; nxa; nxa = nxa->next)
9092 +               if (v4_addr_match(nxa, addr, tmask))
9093 +                       goto out_unlock;
9094 +       ret = 0;
9095 +out_unlock:
9096 +       spin_unlock_irqrestore(&nxi->addr_lock, irqflags);
9097 +out:
9098 +       vxdprintk(VXD_CBIT(net, 0),
9099 +               "v4_addr_in_nx_info(%p[#%u]," NIPQUAD_FMT ",%04x) = %d",
9100 +               nxi, nxi ? nxi->nx_id : 0, NIPQUAD(addr), tmask, ret);
9101 +       return ret;
9102 +}
9103 +
9104 +static inline
9105 +int v4_nx_addr_match(struct nx_addr_v4 *nxa, struct nx_addr_v4 *addr, uint16_t mask)
9106 +{
9107 +       /* FIXME: needs full range checks */
9108 +       return v4_addr_match(nxa, addr->ip[0].s_addr, mask);
9109 +}
9110 +
9111 +static inline
9112 +int v4_nx_addr_in_nx_info(struct nx_info *nxi, struct nx_addr_v4 *nxa, uint16_t mask)
9113 +{
9114 +       struct nx_addr_v4 *ptr;
9115 +       unsigned long irqflags;
9116 +       int ret = 1;
9117 +
9118 +       spin_lock_irqsave(&nxi->addr_lock, irqflags);
9119 +       for (ptr = &nxi->v4; ptr; ptr = ptr->next)
9120 +               if (v4_nx_addr_match(ptr, nxa, mask))
9121 +                       goto out_unlock;
9122 +       ret = 0;
9123 +out_unlock:
9124 +       spin_unlock_irqrestore(&nxi->addr_lock, irqflags);
9125 +       return ret;
9126 +}
9127 +
9128 +#include <net/inet_sock.h>
9129 +
9130 +/*
9131 + *     Check if a given address matches for a socket
9132 + *
9133 + *     nxi:            the socket's nx_info if any
9134 + *     addr:           to be verified address
9135 + */
9136 +static inline
9137 +int v4_sock_addr_match (
9138 +       struct nx_info *nxi,
9139 +       struct inet_sock *inet,
9140 +       __be32 addr)
9141 +{
9142 +       __be32 saddr = inet->inet_rcv_saddr;
9143 +       __be32 bcast = nxi ? nxi->v4_bcast.s_addr : INADDR_BROADCAST;
9144 +
9145 +       if (addr && (saddr == addr || bcast == addr))
9146 +               return 1;
9147 +       if (!saddr)
9148 +               return v4_addr_in_nx_info(nxi, addr, NXA_MASK_BIND);
9149 +       return 0;
9150 +}
9151 +
9152 +
9153 +/* inet related checks and helpers */
9154 +
9155 +
9156 +struct in_ifaddr;
9157 +struct net_device;
9158 +struct sock;
9159 +
9160 +#ifdef CONFIG_INET
9161 +
9162 +#include <linux/netdevice.h>
9163 +#include <linux/inetdevice.h>
9164 +#include <net/inet_sock.h>
9165 +#include <net/inet_timewait_sock.h>
9166 +
9167 +
9168 +int dev_in_nx_info(struct net_device *, struct nx_info *);
9169 +int v4_dev_in_nx_info(struct net_device *, struct nx_info *);
9170 +int nx_v4_addr_conflict(struct nx_info *, struct nx_info *);
9171 +
9172 +
9173 +/*
9174 + *     check if address is covered by socket
9175 + *
9176 + *     sk:     the socket to check against
9177 + *     addr:   the address in question (must be != 0)
9178 + */
9179 +
9180 +static inline
9181 +int __v4_addr_match_socket(const struct sock *sk, struct nx_addr_v4 *nxa)
9182 +{
9183 +       struct nx_info *nxi = sk->sk_nx_info;
9184 +       __be32 saddr = sk_rcv_saddr(sk);
9185 +
9186 +       vxdprintk(VXD_CBIT(net, 5),
9187 +               "__v4_addr_in_socket(%p," NXAV4_FMT ") %p:" NIPQUAD_FMT " %p;%lx",
9188 +               sk, NXAV4(nxa), nxi, NIPQUAD(saddr), sk->sk_socket,
9189 +               (sk->sk_socket?sk->sk_socket->flags:0));
9190 +
9191 +       if (saddr) {            /* direct address match */
9192 +               return v4_addr_match(nxa, saddr, -1);
9193 +       } else if (nxi) {       /* match against nx_info */
9194 +               return v4_nx_addr_in_nx_info(nxi, nxa, -1);
9195 +       } else {                /* unrestricted any socket */
9196 +               return 1;
9197 +       }
9198 +}
9199 +
9200 +
9201 +
9202 +static inline
9203 +int nx_dev_visible(struct nx_info *nxi, struct net_device *dev)
9204 +{
9205 +       vxdprintk(VXD_CBIT(net, 1),
9206 +               "nx_dev_visible(%p[#%u],%p " VS_Q("%s") ") %d",
9207 +               nxi, nxi ? nxi->nx_id : 0, dev, dev->name,
9208 +               nxi ? dev_in_nx_info(dev, nxi) : 0);
9209 +
9210 +       if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
9211 +               return 1;
9212 +       if (dev_in_nx_info(dev, nxi))
9213 +               return 1;
9214 +       return 0;
9215 +}
9216 +
9217 +
9218 +static inline
9219 +int v4_ifa_in_nx_info(struct in_ifaddr *ifa, struct nx_info *nxi)
9220 +{
9221 +       if (!nxi)
9222 +               return 1;
9223 +       if (!ifa)
9224 +               return 0;
9225 +       return v4_addr_in_nx_info(nxi, ifa->ifa_local, NXA_MASK_SHOW);
9226 +}
9227 +
9228 +static inline
9229 +int nx_v4_ifa_visible(struct nx_info *nxi, struct in_ifaddr *ifa)
9230 +{
9231 +       vxdprintk(VXD_CBIT(net, 1), "nx_v4_ifa_visible(%p[#%u],%p) %d",
9232 +               nxi, nxi ? nxi->nx_id : 0, ifa,
9233 +               nxi ? v4_ifa_in_nx_info(ifa, nxi) : 0);
9234 +
9235 +       if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
9236 +               return 1;
9237 +       if (v4_ifa_in_nx_info(ifa, nxi))
9238 +               return 1;
9239 +       return 0;
9240 +}
9241 +
9242 +
9243 +struct nx_v4_sock_addr {
9244 +       __be32 saddr;   /* Address used for validation */
9245 +       __be32 baddr;   /* Address used for socket bind */
9246 +};
9247 +
9248 +static inline
9249 +int v4_map_sock_addr(struct inet_sock *inet, struct sockaddr_in *addr,
9250 +       struct nx_v4_sock_addr *nsa)
9251 +{
9252 +       struct sock *sk = &inet->sk;
9253 +       struct nx_info *nxi = sk->sk_nx_info;
9254 +       __be32 saddr = addr->sin_addr.s_addr;
9255 +       __be32 baddr = saddr;
9256 +
9257 +       vxdprintk(VXD_CBIT(net, 3),
9258 +               "inet_bind(%p)* %p,%p;%lx " NIPQUAD_FMT,
9259 +               sk, sk->sk_nx_info, sk->sk_socket,
9260 +               (sk->sk_socket ? sk->sk_socket->flags : 0),
9261 +               NIPQUAD(saddr));
9262 +
9263 +       if (nxi) {
9264 +               if (saddr == INADDR_ANY) {
9265 +                       if (nx_info_flags(nxi, NXF_SINGLE_IP, 0))
9266 +                               baddr = nxi->v4.ip[0].s_addr;
9267 +               } else if (saddr == IPI_LOOPBACK) {
9268 +                       if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
9269 +                               baddr = nxi->v4_lback.s_addr;
9270 +               } else if (!ipv4_is_multicast(saddr) ||
9271 +                       !nx_info_ncaps(nxi, NXC_MULTICAST)) {
9272 +                       /* normal address bind */
9273 +                       if (!v4_addr_in_nx_info(nxi, saddr, NXA_MASK_BIND))
9274 +                               return -EADDRNOTAVAIL;
9275 +               }
9276 +       }
9277 +
9278 +       vxdprintk(VXD_CBIT(net, 3),
9279 +               "inet_bind(%p) " NIPQUAD_FMT ", " NIPQUAD_FMT,
9280 +               sk, NIPQUAD(saddr), NIPQUAD(baddr));
9281 +
9282 +       nsa->saddr = saddr;
9283 +       nsa->baddr = baddr;
9284 +       return 0;
9285 +}
9286 +
9287 +static inline
9288 +void v4_set_sock_addr(struct inet_sock *inet, struct nx_v4_sock_addr *nsa)
9289 +{
9290 +       inet->inet_saddr = nsa->baddr;
9291 +       inet->inet_rcv_saddr = nsa->baddr;
9292 +}
9293 +
9294 +
9295 +/*
9296 + *      helper to simplify inet_lookup_listener
9297 + *
9298 + *      nxi:   the socket's nx_info if any
9299 + *      addr:  to be verified address
9300 + *      saddr: socket address
9301 + */
9302 +static inline int v4_inet_addr_match (
9303 +       struct nx_info *nxi,
9304 +       __be32 addr,
9305 +       __be32 saddr)
9306 +{
9307 +       if (addr && (saddr == addr))
9308 +               return 1;
9309 +       if (!saddr)
9310 +               return nxi ? v4_addr_in_nx_info(nxi, addr, NXA_MASK_BIND) : 1;
9311 +       return 0;
9312 +}
9313 +
9314 +static inline __be32 nx_map_sock_lback(struct nx_info *nxi, __be32 addr)
9315 +{
9316 +       if (nx_info_flags(nxi, NXF_HIDE_LBACK, 0) &&
9317 +               (addr == nxi->v4_lback.s_addr))
9318 +               return IPI_LOOPBACK;
9319 +       return addr;
9320 +}
9321 +
9322 +static inline
9323 +int nx_info_has_v4(struct nx_info *nxi)
9324 +{
9325 +       if (!nxi)
9326 +               return 1;
9327 +       if (NX_IPV4(nxi))
9328 +               return 1;
9329 +       if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
9330 +               return 1;
9331 +       return 0;
9332 +}
9333 +
9334 +#else /* CONFIG_INET */
9335 +
9336 +static inline
9337 +int nx_dev_visible(struct nx_info *n, struct net_device *d)
9338 +{
9339 +       return 1;
9340 +}
9341 +
9342 +static inline
9343 +int nx_v4_addr_conflict(struct nx_info *n, uint32_t a, const struct sock *s)
9344 +{
9345 +       return 1;
9346 +}
9347 +
9348 +static inline
9349 +int v4_ifa_in_nx_info(struct in_ifaddr *a, struct nx_info *n)
9350 +{
9351 +       return 1;
9352 +}
9353 +
9354 +static inline
9355 +int nx_info_has_v4(struct nx_info *nxi)
9356 +{
9357 +       return 0;
9358 +}
9359 +
9360 +#endif /* CONFIG_INET */
9361 +
9362 +#define current_nx_info_has_v4() \
9363 +       nx_info_has_v4(current_nx_info())
9364 +
9365 +#else
9366 +// #warning duplicate inclusion
9367 +#endif
9368 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
9369 --- linux-3.9.4/include/linux/vs_inet6.h        1970-01-01 00:00:00.000000000 +0000
9370 +++ linux-3.9.4-vs2.3.6.2/include/linux/vs_inet6.h      2013-05-31 14:47:11.000000000 +0000
9371 @@ -0,0 +1,257 @@
9372 +#ifndef _VS_INET6_H
9373 +#define _VS_INET6_H
9374 +
9375 +#include "vserver/base.h"
9376 +#include "vserver/network.h"
9377 +#include "vserver/debug.h"
9378 +
9379 +#include <net/ipv6.h>
9380 +
9381 +#define NXAV6(a)       &(a)->ip, &(a)->mask, (a)->prefix, (a)->type
9382 +#define NXAV6_FMT      "[%pI6/%pI6/%d:%04x]"
9383 +
9384 +
9385 +#ifdef CONFIG_IPV6
9386 +
9387 +static inline
9388 +int v6_addr_match(struct nx_addr_v6 *nxa,
9389 +       const struct in6_addr *addr, uint16_t mask)
9390 +{
9391 +       int ret = 0;
9392 +
9393 +       switch (nxa->type & mask) {
9394 +       case NXA_TYPE_MASK:
9395 +               ret = ipv6_masked_addr_cmp(&nxa->ip, &nxa->mask, addr);
9396 +               break;
9397 +       case NXA_TYPE_ADDR:
9398 +               ret = ipv6_addr_equal(&nxa->ip, addr);
9399 +               break;
9400 +       case NXA_TYPE_ANY:
9401 +               ret = 1;
9402 +               break;
9403 +       }
9404 +       vxdprintk(VXD_CBIT(net, 0),
9405 +               "v6_addr_match(%p" NXAV6_FMT ",%pI6,%04x) = %d",
9406 +               nxa, NXAV6(nxa), addr, mask, ret);
9407 +       return ret;
9408 +}
9409 +
9410 +static inline
9411 +int v6_addr_in_nx_info(struct nx_info *nxi,
9412 +       const struct in6_addr *addr, uint16_t mask)
9413 +{
9414 +       struct nx_addr_v6 *nxa;
9415 +       unsigned long irqflags;
9416 +       int ret = 1;
9417 +
9418 +       if (!nxi)
9419 +               goto out;
9420 +
9421 +       spin_lock_irqsave(&nxi->addr_lock, irqflags);
9422 +       for (nxa = &nxi->v6; nxa; nxa = nxa->next)
9423 +               if (v6_addr_match(nxa, addr, mask))
9424 +                       goto out_unlock;
9425 +       ret = 0;
9426 +out_unlock:
9427 +       spin_unlock_irqrestore(&nxi->addr_lock, irqflags);
9428 +out:
9429 +       vxdprintk(VXD_CBIT(net, 0),
9430 +               "v6_addr_in_nx_info(%p[#%u],%pI6,%04x) = %d",
9431 +               nxi, nxi ? nxi->nx_id : 0, addr, mask, ret);
9432 +       return ret;
9433 +}
9434 +
9435 +static inline
9436 +int v6_nx_addr_match(struct nx_addr_v6 *nxa, struct nx_addr_v6 *addr, uint16_t mask)
9437 +{
9438 +       /* FIXME: needs full range checks */
9439 +       return v6_addr_match(nxa, &addr->ip, mask);
9440 +}
9441 +
9442 +static inline
9443 +int v6_nx_addr_in_nx_info(struct nx_info *nxi, struct nx_addr_v6 *nxa, uint16_t mask)
9444 +{
9445 +       struct nx_addr_v6 *ptr;
9446 +       unsigned long irqflags;
9447 +       int ret = 1;
9448 +
9449 +       spin_lock_irqsave(&nxi->addr_lock, irqflags);
9450 +       for (ptr = &nxi->v6; ptr; ptr = ptr->next)
9451 +               if (v6_nx_addr_match(ptr, nxa, mask))
9452 +                       goto out_unlock;
9453 +       ret = 0;
9454 +out_unlock:
9455 +       spin_unlock_irqrestore(&nxi->addr_lock, irqflags);
9456 +       return ret;
9457 +}
9458 +
9459 +
9460 +/*
9461 + *     Check if a given address matches for a socket
9462 + *
9463 + *     nxi:            the socket's nx_info if any
9464 + *     addr:           to be verified address
9465 + */
9466 +static inline
9467 +int v6_sock_addr_match (
9468 +       struct nx_info *nxi,
9469 +       struct inet_sock *inet,
9470 +       struct in6_addr *addr)
9471 +{
9472 +       struct sock *sk = &inet->sk;
9473 +       struct in6_addr *saddr = inet6_rcv_saddr(sk);
9474 +
9475 +       if (!ipv6_addr_any(addr) &&
9476 +               ipv6_addr_equal(saddr, addr))
9477 +               return 1;
9478 +       if (ipv6_addr_any(saddr))
9479 +               return v6_addr_in_nx_info(nxi, addr, -1);
9480 +       return 0;
9481 +}
9482 +
9483 +/*
9484 + *     check if address is covered by socket
9485 + *
9486 + *     sk:     the socket to check against
9487 + *     addr:   the address in question (must be != 0)
9488 + */
9489 +
9490 +static inline
9491 +int __v6_addr_match_socket(const struct sock *sk, struct nx_addr_v6 *nxa)
9492 +{
9493 +       struct nx_info *nxi = sk->sk_nx_info;
9494 +       struct in6_addr *saddr = inet6_rcv_saddr(sk);
9495 +
9496 +       vxdprintk(VXD_CBIT(net, 5),
9497 +               "__v6_addr_in_socket(%p," NXAV6_FMT ") %p:%pI6 %p;%lx",
9498 +               sk, NXAV6(nxa), nxi, saddr, sk->sk_socket,
9499 +               (sk->sk_socket?sk->sk_socket->flags:0));
9500 +
9501 +       if (!ipv6_addr_any(saddr)) {    /* direct address match */
9502 +               return v6_addr_match(nxa, saddr, -1);
9503 +       } else if (nxi) {               /* match against nx_info */
9504 +               return v6_nx_addr_in_nx_info(nxi, nxa, -1);
9505 +       } else {                        /* unrestricted any socket */
9506 +               return 1;
9507 +       }
9508 +}
9509 +
9510 +
9511 +/* inet related checks and helpers */
9512 +
9513 +
9514 +struct in_ifaddr;
9515 +struct net_device;
9516 +struct sock;
9517 +
9518 +
9519 +#include <linux/netdevice.h>
9520 +#include <linux/inetdevice.h>
9521 +#include <net/inet_timewait_sock.h>
9522 +
9523 +
9524 +int dev_in_nx_info(struct net_device *, struct nx_info *);
9525 +int v6_dev_in_nx_info(struct net_device *, struct nx_info *);
9526 +int nx_v6_addr_conflict(struct nx_info *, struct nx_info *);
9527 +
9528 +
9529 +
9530 +static inline
9531 +int v6_ifa_in_nx_info(struct inet6_ifaddr *ifa, struct nx_info *nxi)
9532 +{
9533 +       if (!nxi)
9534 +               return 1;
9535 +       if (!ifa)
9536 +               return 0;
9537 +       return v6_addr_in_nx_info(nxi, &ifa->addr, -1);
9538 +}
9539 +
9540 +static inline
9541 +int nx_v6_ifa_visible(struct nx_info *nxi, struct inet6_ifaddr *ifa)
9542 +{
9543 +       vxdprintk(VXD_CBIT(net, 1), "nx_v6_ifa_visible(%p[#%u],%p) %d",
9544 +               nxi, nxi ? nxi->nx_id : 0, ifa,
9545 +               nxi ? v6_ifa_in_nx_info(ifa, nxi) : 0);
9546 +
9547 +       if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
9548 +               return 1;
9549 +       if (v6_ifa_in_nx_info(ifa, nxi))
9550 +               return 1;
9551 +       return 0;
9552 +}
9553 +
9554 +
9555 +struct nx_v6_sock_addr {
9556 +       struct in6_addr saddr;  /* Address used for validation */
9557 +       struct in6_addr baddr;  /* Address used for socket bind */
9558 +};
9559 +
9560 +static inline
9561 +int v6_map_sock_addr(struct inet_sock *inet, struct sockaddr_in6 *addr,
9562 +       struct nx_v6_sock_addr *nsa)
9563 +{
9564 +       // struct sock *sk = &inet->sk;
9565 +       // struct nx_info *nxi = sk->sk_nx_info;
9566 +       struct in6_addr saddr = addr->sin6_addr;
9567 +       struct in6_addr baddr = saddr;
9568 +
9569 +       nsa->saddr = saddr;
9570 +       nsa->baddr = baddr;
9571 +       return 0;
9572 +}
9573 +
9574 +static inline
9575 +void v6_set_sock_addr(struct inet_sock *inet, struct nx_v6_sock_addr *nsa)
9576 +{
9577 +       // struct sock *sk = &inet->sk;
9578 +       // struct in6_addr *saddr = inet6_rcv_saddr(sk);
9579 +
9580 +       // *saddr = nsa->baddr;
9581 +       // inet->inet_saddr = nsa->baddr;
9582 +}
9583 +
9584 +static inline
9585 +int nx_info_has_v6(struct nx_info *nxi)
9586 +{
9587 +       if (!nxi)
9588 +               return 1;
9589 +       if (NX_IPV6(nxi))
9590 +               return 1;
9591 +       return 0;
9592 +}
9593 +
9594 +#else /* CONFIG_IPV6 */
9595 +
9596 +static inline
9597 +int nx_v6_dev_visible(struct nx_info *n, struct net_device *d)
9598 +{
9599 +       return 1;
9600 +}
9601 +
9602 +
9603 +static inline
9604 +int nx_v6_addr_conflict(struct nx_info *n, uint32_t a, const struct sock *s)
9605 +{
9606 +       return 1;
9607 +}
9608 +
9609 +static inline
9610 +int v6_ifa_in_nx_info(struct in_ifaddr *a, struct nx_info *n)
9611 +{
9612 +       return 1;
9613 +}
9614 +
9615 +static inline
9616 +int nx_info_has_v6(struct nx_info *nxi)
9617 +{
9618 +       return 0;
9619 +}
9620 +
9621 +#endif /* CONFIG_IPV6 */
9622 +
9623 +#define current_nx_info_has_v6() \
9624 +       nx_info_has_v6(current_nx_info())
9625 +
9626 +#else
9627 +#warning duplicate inclusion
9628 +#endif
9629 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
9630 --- linux-3.9.4/include/linux/vs_limit.h        1970-01-01 00:00:00.000000000 +0000
9631 +++ linux-3.9.4-vs2.3.6.2/include/linux/vs_limit.h      2013-05-31 14:47:11.000000000 +0000
9632 @@ -0,0 +1,140 @@
9633 +#ifndef _VS_LIMIT_H
9634 +#define _VS_LIMIT_H
9635 +
9636 +#include "vserver/limit.h"
9637 +#include "vserver/base.h"
9638 +#include "vserver/context.h"
9639 +#include "vserver/debug.h"
9640 +#include "vserver/context.h"
9641 +#include "vserver/limit_int.h"
9642 +
9643 +
9644 +#define vx_acc_cres(v, d, p, r) \
9645 +       __vx_acc_cres(v, r, d, p, __FILE__, __LINE__)
9646 +
9647 +#define vx_acc_cres_cond(x, d, p, r) \
9648 +       __vx_acc_cres(((x) == vx_current_xid()) ? current_vx_info() : 0, \
9649 +       r, d, p, __FILE__, __LINE__)
9650 +
9651 +
9652 +#define vx_add_cres(v, a, p, r) \
9653 +       __vx_add_cres(v, r, a, p, __FILE__, __LINE__)
9654 +#define vx_sub_cres(v, a, p, r)                vx_add_cres(v, -(a), p, r)
9655 +
9656 +#define vx_add_cres_cond(x, a, p, r) \
9657 +       __vx_add_cres(((x) == vx_current_xid()) ? current_vx_info() : 0, \
9658 +       r, a, p, __FILE__, __LINE__)
9659 +#define vx_sub_cres_cond(x, a, p, r)   vx_add_cres_cond(x, -(a), p, r)
9660 +
9661 +
9662 +/* process and file limits */
9663 +
9664 +#define vx_nproc_inc(p) \
9665 +       vx_acc_cres((p)->vx_info, 1, p, RLIMIT_NPROC)
9666 +
9667 +#define vx_nproc_dec(p) \
9668 +       vx_acc_cres((p)->vx_info,-1, p, RLIMIT_NPROC)
9669 +
9670 +#define vx_files_inc(f) \
9671 +       vx_acc_cres_cond((f)->f_xid, 1, f, RLIMIT_NOFILE)
9672 +
9673 +#define vx_files_dec(f) \
9674 +       vx_acc_cres_cond((f)->f_xid,-1, f, RLIMIT_NOFILE)
9675 +
9676 +#define vx_locks_inc(l) \
9677 +       vx_acc_cres_cond((l)->fl_xid, 1, l, RLIMIT_LOCKS)
9678 +
9679 +#define vx_locks_dec(l) \
9680 +       vx_acc_cres_cond((l)->fl_xid,-1, l, RLIMIT_LOCKS)
9681 +
9682 +#define vx_openfd_inc(f) \
9683 +       vx_acc_cres(current_vx_info(), 1, (void *)(long)(f), VLIMIT_OPENFD)
9684 +
9685 +#define vx_openfd_dec(f) \
9686 +       vx_acc_cres(current_vx_info(),-1, (void *)(long)(f), VLIMIT_OPENFD)
9687 +
9688 +
9689 +#define vx_cres_avail(v, n, r) \
9690 +       __vx_cres_avail(v, r, n, __FILE__, __LINE__)
9691 +
9692 +
9693 +#define vx_nproc_avail(n) \
9694 +       vx_cres_avail(current_vx_info(), n, RLIMIT_NPROC)
9695 +
9696 +#define vx_files_avail(n) \
9697 +       vx_cres_avail(current_vx_info(), n, RLIMIT_NOFILE)
9698 +
9699 +#define vx_locks_avail(n) \
9700 +       vx_cres_avail(current_vx_info(), n, RLIMIT_LOCKS)
9701 +
9702 +#define vx_openfd_avail(n) \
9703 +       vx_cres_avail(current_vx_info(), n, VLIMIT_OPENFD)
9704 +
9705 +
9706 +/* dentry limits */
9707 +
9708 +#define vx_dentry_inc(d) do {                                          \
9709 +       if ((d)->d_count == 1)                                          \
9710 +               vx_acc_cres(current_vx_info(), 1, d, VLIMIT_DENTRY);    \
9711 +       } while (0)
9712 +
9713 +#define vx_dentry_dec(d) do {                                          \
9714 +       if ((d)->d_count == 0)                                          \
9715 +               vx_acc_cres(current_vx_info(),-1, d, VLIMIT_DENTRY);    \
9716 +       } while (0)
9717 +
9718 +#define vx_dentry_avail(n) \
9719 +       vx_cres_avail(current_vx_info(), n, VLIMIT_DENTRY)
9720 +
9721 +
9722 +/* socket limits */
9723 +
9724 +#define vx_sock_inc(s) \
9725 +       vx_acc_cres((s)->sk_vx_info, 1, s, VLIMIT_NSOCK)
9726 +
9727 +#define vx_sock_dec(s) \
9728 +       vx_acc_cres((s)->sk_vx_info,-1, s, VLIMIT_NSOCK)
9729 +
9730 +#define vx_sock_avail(n) \
9731 +       vx_cres_avail(current_vx_info(), n, VLIMIT_NSOCK)
9732 +
9733 +
9734 +/* ipc resource limits */
9735 +
9736 +#define vx_ipcmsg_add(v, u, a) \
9737 +       vx_add_cres(v, a, u, RLIMIT_MSGQUEUE)
9738 +
9739 +#define vx_ipcmsg_sub(v, u, a) \
9740 +       vx_sub_cres(v, a, u, RLIMIT_MSGQUEUE)
9741 +
9742 +#define vx_ipcmsg_avail(v, a) \
9743 +       vx_cres_avail(v, a, RLIMIT_MSGQUEUE)
9744 +
9745 +
9746 +#define vx_ipcshm_add(v, k, a) \
9747 +       vx_add_cres(v, a, (void *)(long)(k), VLIMIT_SHMEM)
9748 +
9749 +#define vx_ipcshm_sub(v, k, a) \
9750 +       vx_sub_cres(v, a, (void *)(long)(k), VLIMIT_SHMEM)
9751 +
9752 +#define vx_ipcshm_avail(v, a) \
9753 +       vx_cres_avail(v, a, VLIMIT_SHMEM)
9754 +
9755 +
9756 +#define vx_semary_inc(a) \
9757 +       vx_acc_cres(current_vx_info(), 1, a, VLIMIT_SEMARY)
9758 +
9759 +#define vx_semary_dec(a) \
9760 +       vx_acc_cres(current_vx_info(), -1, a, VLIMIT_SEMARY)
9761 +
9762 +
9763 +#define vx_nsems_add(a,n) \
9764 +       vx_add_cres(current_vx_info(), n, a, VLIMIT_NSEMS)
9765 +
9766 +#define vx_nsems_sub(a,n) \
9767 +       vx_sub_cres(current_vx_info(), n, a, VLIMIT_NSEMS)
9768 +
9769 +
9770 +#else
9771 +#warning duplicate inclusion
9772 +#endif
9773 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
9774 --- linux-3.9.4/include/linux/vs_network.h      1970-01-01 00:00:00.000000000 +0000
9775 +++ linux-3.9.4-vs2.3.6.2/include/linux/vs_network.h    2013-05-31 14:47:11.000000000 +0000
9776 @@ -0,0 +1,169 @@
9777 +#ifndef _NX_VS_NETWORK_H
9778 +#define _NX_VS_NETWORK_H
9779 +
9780 +#include "vserver/context.h"
9781 +#include "vserver/network.h"
9782 +#include "vserver/base.h"
9783 +#include "vserver/check.h"
9784 +#include "vserver/debug.h"
9785 +
9786 +#include <linux/sched.h>
9787 +
9788 +
9789 +#define get_nx_info(i) __get_nx_info(i, __FILE__, __LINE__)
9790 +
9791 +static inline struct nx_info *__get_nx_info(struct nx_info *nxi,
9792 +       const char *_file, int _line)
9793 +{
9794 +       if (!nxi)
9795 +               return NULL;
9796 +
9797 +       vxlprintk(VXD_CBIT(nid, 2), "get_nx_info(%p[#%d.%d])",
9798 +               nxi, nxi ? nxi->nx_id : 0,
9799 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
9800 +               _file, _line);
9801 +
9802 +       atomic_inc(&nxi->nx_usecnt);
9803 +       return nxi;
9804 +}
9805 +
9806 +
9807 +extern void free_nx_info(struct nx_info *);
9808 +
9809 +#define put_nx_info(i) __put_nx_info(i, __FILE__, __LINE__)
9810 +
9811 +static inline void __put_nx_info(struct nx_info *nxi, const char *_file, int _line)
9812 +{
9813 +       if (!nxi)
9814 +               return;
9815 +
9816 +       vxlprintk(VXD_CBIT(nid, 2), "put_nx_info(%p[#%d.%d])",
9817 +               nxi, nxi ? nxi->nx_id : 0,
9818 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
9819 +               _file, _line);
9820 +
9821 +       if (atomic_dec_and_test(&nxi->nx_usecnt))
9822 +               free_nx_info(nxi);
9823 +}
9824 +
9825 +
9826 +#define init_nx_info(p, i) __init_nx_info(p, i, __FILE__, __LINE__)
9827 +
9828 +static inline void __init_nx_info(struct nx_info **nxp, struct nx_info *nxi,
9829 +               const char *_file, int _line)
9830 +{
9831 +       if (nxi) {
9832 +               vxlprintk(VXD_CBIT(nid, 3),
9833 +                       "init_nx_info(%p[#%d.%d])",
9834 +                       nxi, nxi ? nxi->nx_id : 0,
9835 +                       nxi ? atomic_read(&nxi->nx_usecnt) : 0,
9836 +                       _file, _line);
9837 +
9838 +               atomic_inc(&nxi->nx_usecnt);
9839 +       }
9840 +       *nxp = nxi;
9841 +}
9842 +
9843 +
9844 +#define set_nx_info(p, i) __set_nx_info(p, i, __FILE__, __LINE__)
9845 +
9846 +static inline void __set_nx_info(struct nx_info **nxp, struct nx_info *nxi,
9847 +       const char *_file, int _line)
9848 +{
9849 +       struct nx_info *nxo;
9850 +
9851 +       if (!nxi)
9852 +               return;
9853 +
9854 +       vxlprintk(VXD_CBIT(nid, 3), "set_nx_info(%p[#%d.%d])",
9855 +               nxi, nxi ? nxi->nx_id : 0,
9856 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
9857 +               _file, _line);
9858 +
9859 +       atomic_inc(&nxi->nx_usecnt);
9860 +       nxo = xchg(nxp, nxi);
9861 +       BUG_ON(nxo);
9862 +}
9863 +
9864 +#define clr_nx_info(p) __clr_nx_info(p, __FILE__, __LINE__)
9865 +
9866 +static inline void __clr_nx_info(struct nx_info **nxp,
9867 +       const char *_file, int _line)
9868 +{
9869 +       struct nx_info *nxo;
9870 +
9871 +       nxo = xchg(nxp, NULL);
9872 +       if (!nxo)
9873 +               return;
9874 +
9875 +       vxlprintk(VXD_CBIT(nid, 3), "clr_nx_info(%p[#%d.%d])",
9876 +               nxo, nxo ? nxo->nx_id : 0,
9877 +               nxo ? atomic_read(&nxo->nx_usecnt) : 0,
9878 +               _file, _line);
9879 +
9880 +       if (atomic_dec_and_test(&nxo->nx_usecnt))
9881 +               free_nx_info(nxo);
9882 +}
9883 +
9884 +
9885 +#define claim_nx_info(v, p) __claim_nx_info(v, p, __FILE__, __LINE__)
9886 +
9887 +static inline void __claim_nx_info(struct nx_info *nxi,
9888 +       struct task_struct *task, const char *_file, int _line)
9889 +{
9890 +       vxlprintk(VXD_CBIT(nid, 3), "claim_nx_info(%p[#%d.%d.%d]) %p",
9891 +               nxi, nxi ? nxi->nx_id : 0,
9892 +               nxi?atomic_read(&nxi->nx_usecnt):0,
9893 +               nxi?atomic_read(&nxi->nx_tasks):0,
9894 +               task, _file, _line);
9895 +
9896 +       atomic_inc(&nxi->nx_tasks);
9897 +}
9898 +
9899 +
9900 +extern void unhash_nx_info(struct nx_info *);
9901 +
9902 +#define release_nx_info(v, p) __release_nx_info(v, p, __FILE__, __LINE__)
9903 +
9904 +static inline void __release_nx_info(struct nx_info *nxi,
9905 +       struct task_struct *task, const char *_file, int _line)
9906 +{
9907 +       vxlprintk(VXD_CBIT(nid, 3), "release_nx_info(%p[#%d.%d.%d]) %p",
9908 +               nxi, nxi ? nxi->nx_id : 0,
9909 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
9910 +               nxi ? atomic_read(&nxi->nx_tasks) : 0,
9911 +               task, _file, _line);
9912 +
9913 +       might_sleep();
9914 +
9915 +       if (atomic_dec_and_test(&nxi->nx_tasks))
9916 +               unhash_nx_info(nxi);
9917 +}
9918 +
9919 +
9920 +#define task_get_nx_info(i)    __task_get_nx_info(i, __FILE__, __LINE__)
9921 +
9922 +static __inline__ struct nx_info *__task_get_nx_info(struct task_struct *p,
9923 +       const char *_file, int _line)
9924 +{
9925 +       struct nx_info *nxi;
9926 +
9927 +       task_lock(p);
9928 +       vxlprintk(VXD_CBIT(nid, 5), "task_get_nx_info(%p)",
9929 +               p, _file, _line);
9930 +       nxi = __get_nx_info(p->nx_info, _file, _line);
9931 +       task_unlock(p);
9932 +       return nxi;
9933 +}
9934 +
9935 +
9936 +static inline void exit_nx_info(struct task_struct *p)
9937 +{
9938 +       if (p->nx_info)
9939 +               release_nx_info(p->nx_info, p);
9940 +}
9941 +
9942 +
9943 +#else
9944 +#warning duplicate inclusion
9945 +#endif
9946 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
9947 --- linux-3.9.4/include/linux/vs_pid.h  1970-01-01 00:00:00.000000000 +0000
9948 +++ linux-3.9.4-vs2.3.6.2/include/linux/vs_pid.h        2013-05-31 14:47:11.000000000 +0000
9949 @@ -0,0 +1,50 @@
9950 +#ifndef _VS_PID_H
9951 +#define _VS_PID_H
9952 +
9953 +#include "vserver/base.h"
9954 +#include "vserver/check.h"
9955 +#include "vserver/context.h"
9956 +#include "vserver/debug.h"
9957 +#include "vserver/pid.h"
9958 +#include <linux/pid_namespace.h>
9959 +
9960 +
9961 +#define VXF_FAKE_INIT  (VXF_INFO_INIT | VXF_STATE_INIT)
9962 +
9963 +static inline
9964 +int vx_proc_task_visible(struct task_struct *task)
9965 +{
9966 +       if ((task->pid == 1) &&
9967 +               !vx_flags(VXF_FAKE_INIT, VXF_FAKE_INIT))
9968 +               /* show a blend through init */
9969 +               goto visible;
9970 +       if (vx_check(vx_task_xid(task), VS_WATCH | VS_IDENT))
9971 +               goto visible;
9972 +       return 0;
9973 +visible:
9974 +       return 1;
9975 +}
9976 +
9977 +#define find_task_by_real_pid(pid) find_task_by_pid_ns(pid, &init_pid_ns)
9978 +
9979 +
9980 +static inline
9981 +struct task_struct *vx_get_proc_task(struct inode *inode, struct pid *pid)
9982 +{
9983 +       struct task_struct *task = get_pid_task(pid, PIDTYPE_PID);
9984 +
9985 +       if (task && !vx_proc_task_visible(task)) {
9986 +               vxdprintk(VXD_CBIT(misc, 6),
9987 +                       "dropping task (get) %p[#%u,%u] for %p[#%u,%u]",
9988 +                       task, task->xid, task->pid,
9989 +                       current, current->xid, current->pid);
9990 +               put_task_struct(task);
9991 +               task = NULL;
9992 +       }
9993 +       return task;
9994 +}
9995 +
9996 +
9997 +#else
9998 +#warning duplicate inclusion
9999 +#endif
10000 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
10001 --- linux-3.9.4/include/linux/vs_sched.h        1970-01-01 00:00:00.000000000 +0000
10002 +++ linux-3.9.4-vs2.3.6.2/include/linux/vs_sched.h      2013-05-31 14:47:11.000000000 +0000
10003 @@ -0,0 +1,40 @@
10004 +#ifndef _VS_SCHED_H
10005 +#define _VS_SCHED_H
10006 +
10007 +#include "vserver/base.h"
10008 +#include "vserver/context.h"
10009 +#include "vserver/sched.h"
10010 +
10011 +
10012 +#define MAX_PRIO_BIAS           20
10013 +#define MIN_PRIO_BIAS          -20
10014 +
10015 +static inline
10016 +int vx_adjust_prio(struct task_struct *p, int prio, int max_user)
10017 +{
10018 +       struct vx_info *vxi = p->vx_info;
10019 +
10020 +       if (vxi)
10021 +               prio += vx_cpu(vxi, sched_pc).prio_bias;
10022 +       return prio;
10023 +}
10024 +
10025 +static inline void vx_account_user(struct vx_info *vxi,
10026 +       cputime_t cputime, int nice)
10027 +{
10028 +       if (!vxi)
10029 +               return;
10030 +       vx_cpu(vxi, sched_pc).user_ticks += cputime;
10031 +}
10032 +
10033 +static inline void vx_account_system(struct vx_info *vxi,
10034 +       cputime_t cputime, int idle)
10035 +{
10036 +       if (!vxi)
10037 +               return;
10038 +       vx_cpu(vxi, sched_pc).sys_ticks += cputime;
10039 +}
10040 +
10041 +#else
10042 +#warning duplicate inclusion
10043 +#endif
10044 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
10045 --- linux-3.9.4/include/linux/vs_socket.h       1970-01-01 00:00:00.000000000 +0000
10046 +++ linux-3.9.4-vs2.3.6.2/include/linux/vs_socket.h     2013-05-31 14:47:11.000000000 +0000
10047 @@ -0,0 +1,67 @@
10048 +#ifndef _VS_SOCKET_H
10049 +#define _VS_SOCKET_H
10050 +
10051 +#include "vserver/debug.h"
10052 +#include "vserver/base.h"
10053 +#include "vserver/cacct.h"
10054 +#include "vserver/context.h"
10055 +#include "vserver/tag.h"
10056 +
10057 +
10058 +/* socket accounting */
10059 +
10060 +#include <linux/socket.h>
10061 +
10062 +static inline int vx_sock_type(int family)
10063 +{
10064 +       switch (family) {
10065 +       case PF_UNSPEC:
10066 +               return VXA_SOCK_UNSPEC;
10067 +       case PF_UNIX:
10068 +               return VXA_SOCK_UNIX;
10069 +       case PF_INET:
10070 +               return VXA_SOCK_INET;
10071 +       case PF_INET6:
10072 +               return VXA_SOCK_INET6;
10073 +       case PF_PACKET:
10074 +               return VXA_SOCK_PACKET;
10075 +       default:
10076 +               return VXA_SOCK_OTHER;
10077 +       }
10078 +}
10079 +
10080 +#define vx_acc_sock(v, f, p, s) \
10081 +       __vx_acc_sock(v, f, p, s, __FILE__, __LINE__)
10082 +
10083 +static inline void __vx_acc_sock(struct vx_info *vxi,
10084 +       int family, int pos, int size, char *file, int line)
10085 +{
10086 +       if (vxi) {
10087 +               int type = vx_sock_type(family);
10088 +
10089 +               atomic_long_inc(&vxi->cacct.sock[type][pos].count);
10090 +               atomic_long_add(size, &vxi->cacct.sock[type][pos].total);
10091 +       }
10092 +}
10093 +
10094 +#define vx_sock_recv(sk, s) \
10095 +       vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 0, s)
10096 +#define vx_sock_send(sk, s) \
10097 +       vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 1, s)
10098 +#define vx_sock_fail(sk, s) \
10099 +       vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 2, s)
10100 +
10101 +
10102 +#define sock_vx_init(s) do {           \
10103 +       (s)->sk_xid = 0;                \
10104 +       (s)->sk_vx_info = NULL;         \
10105 +       } while (0)
10106 +
10107 +#define sock_nx_init(s) do {           \
10108 +       (s)->sk_nid = 0;                \
10109 +       (s)->sk_nx_info = NULL;         \
10110 +       } while (0)
10111 +
10112 +#else
10113 +#warning duplicate inclusion
10114 +#endif
10115 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
10116 --- linux-3.9.4/include/linux/vs_tag.h  1970-01-01 00:00:00.000000000 +0000
10117 +++ linux-3.9.4-vs2.3.6.2/include/linux/vs_tag.h        2013-05-31 14:47:11.000000000 +0000
10118 @@ -0,0 +1,47 @@
10119 +#ifndef _VS_TAG_H
10120 +#define _VS_TAG_H
10121 +
10122 +#include <linux/vserver/tag.h>
10123 +
10124 +/* check conditions */
10125 +
10126 +#define DX_ADMIN       0x0001
10127 +#define DX_WATCH       0x0002
10128 +#define DX_HOSTID      0x0008
10129 +
10130 +#define DX_IDENT       0x0010
10131 +
10132 +#define DX_ARG_MASK    0x0010
10133 +
10134 +
10135 +#define dx_task_tag(t) ((t)->tag)
10136 +
10137 +#define dx_current_tag() dx_task_tag(current)
10138 +
10139 +#define dx_check(c, m) __dx_check(dx_current_tag(), c, m)
10140 +
10141 +#define dx_weak_check(c, m)    ((m) ? dx_check(c, m) : 1)
10142 +
10143 +
10144 +/*
10145 + * check current context for ADMIN/WATCH and
10146 + * optionally against supplied argument
10147 + */
10148 +static inline int __dx_check(tag_t cid, tag_t id, unsigned int mode)
10149 +{
10150 +       if (mode & DX_ARG_MASK) {
10151 +               if ((mode & DX_IDENT) && (id == cid))
10152 +                       return 1;
10153 +       }
10154 +       return (((mode & DX_ADMIN) && (cid == 0)) ||
10155 +               ((mode & DX_WATCH) && (cid == 1)) ||
10156 +               ((mode & DX_HOSTID) && (id == 0)));
10157 +}
10158 +
10159 +struct inode;
10160 +int dx_permission(const struct inode *inode, int mask);
10161 +
10162 +
10163 +#else
10164 +#warning duplicate inclusion
10165 +#endif
10166 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
10167 --- linux-3.9.4/include/linux/vs_time.h 1970-01-01 00:00:00.000000000 +0000
10168 +++ linux-3.9.4-vs2.3.6.2/include/linux/vs_time.h       2013-05-31 14:47:11.000000000 +0000
10169 @@ -0,0 +1,19 @@
10170 +#ifndef _VS_TIME_H
10171 +#define _VS_TIME_H
10172 +
10173 +
10174 +/* time faking stuff */
10175 +
10176 +#ifdef CONFIG_VSERVER_VTIME
10177 +
10178 +extern void vx_adjust_timespec(struct timespec *ts);
10179 +extern int vx_settimeofday(const struct timespec *ts);
10180 +
10181 +#else
10182 +#define        vx_adjust_timespec(t)   do { } while (0)
10183 +#define        vx_settimeofday(t)      do_settimeofday(t)
10184 +#endif
10185 +
10186 +#else
10187 +#warning duplicate inclusion
10188 +#endif
10189 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
10190 --- linux-3.9.4/include/linux/vserver/base.h    1970-01-01 00:00:00.000000000 +0000
10191 +++ linux-3.9.4-vs2.3.6.2/include/linux/vserver/base.h  2013-05-31 17:55:09.000000000 +0000
10192 @@ -0,0 +1,181 @@
10193 +#ifndef _VSERVER_BASE_H
10194 +#define _VSERVER_BASE_H
10195 +
10196 +
10197 +/* context state changes */
10198 +
10199 +enum {
10200 +       VSC_STARTUP = 1,
10201 +       VSC_SHUTDOWN,
10202 +
10203 +       VSC_NETUP,
10204 +       VSC_NETDOWN,
10205 +};
10206 +
10207 +
10208 +
10209 +#define vx_task_xid(t) ((t)->xid)
10210 +
10211 +#define vx_current_xid() vx_task_xid(current)
10212 +
10213 +#define current_vx_info() (current->vx_info)
10214 +
10215 +
10216 +#define nx_task_nid(t) ((t)->nid)
10217 +
10218 +#define nx_current_nid() nx_task_nid(current)
10219 +
10220 +#define current_nx_info() (current->nx_info)
10221 +
10222 +
10223 +/* generic flag merging */
10224 +
10225 +#define vs_check_flags(v, m, f)        (((v) & (m)) ^ (f))
10226 +
10227 +#define vs_mask_flags(v, f, m) (((v) & ~(m)) | ((f) & (m)))
10228 +
10229 +#define vs_mask_mask(v, f, m)  (((v) & ~(m)) | ((v) & (f) & (m)))
10230 +
10231 +#define vs_check_bit(v, n)     ((v) & (1LL << (n)))
10232 +
10233 +
10234 +/* context flags */
10235 +
10236 +#define __vx_flags(v)  ((v) ? (v)->vx_flags : 0)
10237 +
10238 +#define vx_current_flags()     __vx_flags(current_vx_info())
10239 +
10240 +#define vx_info_flags(v, m, f) \
10241 +       vs_check_flags(__vx_flags(v), m, f)
10242 +
10243 +#define task_vx_flags(t, m, f) \
10244 +       ((t) && vx_info_flags((t)->vx_info, m, f))
10245 +
10246 +#define vx_flags(m, f) vx_info_flags(current_vx_info(), m, f)
10247 +
10248 +
10249 +/* context caps */
10250 +
10251 +#define __vx_ccaps(v)  ((v) ? (v)->vx_ccaps : 0)
10252 +
10253 +#define vx_current_ccaps()     __vx_ccaps(current_vx_info())
10254 +
10255 +#define vx_info_ccaps(v, c)    (__vx_ccaps(v) & (c))
10256 +
10257 +#define vx_ccaps(c)    vx_info_ccaps(current_vx_info(), (c))
10258 +
10259 +
10260 +
10261 +/* network flags */
10262 +
10263 +#define __nx_flags(n)  ((n) ? (n)->nx_flags : 0)
10264 +
10265 +#define nx_current_flags()     __nx_flags(current_nx_info())
10266 +
10267 +#define nx_info_flags(n, m, f) \
10268 +       vs_check_flags(__nx_flags(n), m, f)
10269 +
10270 +#define task_nx_flags(t, m, f) \
10271 +       ((t) && nx_info_flags((t)->nx_info, m, f))
10272 +
10273 +#define nx_flags(m, f) nx_info_flags(current_nx_info(), m, f)
10274 +
10275 +
10276 +/* network caps */
10277 +
10278 +#define __nx_ncaps(n)  ((n) ? (n)->nx_ncaps : 0)
10279 +
10280 +#define nx_current_ncaps()     __nx_ncaps(current_nx_info())
10281 +
10282 +#define nx_info_ncaps(n, c)    (__nx_ncaps(n) & (c))
10283 +
10284 +#define nx_ncaps(c)    nx_info_ncaps(current_nx_info(), c)
10285 +
10286 +
10287 +/* context mask capabilities */
10288 +
10289 +#define __vx_mcaps(v)  ((v) ? (v)->vx_ccaps >> 32UL : ~0 )
10290 +
10291 +#define vx_info_mcaps(v, c)    (__vx_mcaps(v) & (c))
10292 +
10293 +#define vx_mcaps(c)    vx_info_mcaps(current_vx_info(), c)
10294 +
10295 +
10296 +/* context bcap mask */
10297 +
10298 +#define __vx_bcaps(v)          ((v)->vx_bcaps)
10299 +
10300 +#define vx_current_bcaps()     __vx_bcaps(current_vx_info())
10301 +
10302 +
10303 +/* mask given bcaps */
10304 +
10305 +#define vx_info_mbcaps(v, c)   ((v) ? cap_intersect(__vx_bcaps(v), c) : c)
10306 +
10307 +#define vx_mbcaps(c)           vx_info_mbcaps(current_vx_info(), c)
10308 +
10309 +
10310 +/* masked cap_bset */
10311 +
10312 +#define vx_info_cap_bset(v)    vx_info_mbcaps(v, current->cap_bset)
10313 +
10314 +#define vx_current_cap_bset()  vx_info_cap_bset(current_vx_info())
10315 +
10316 +#if 0
10317 +#define vx_info_mbcap(v, b) \
10318 +       (!vx_info_flags(v, VXF_STATE_SETUP, 0) ? \
10319 +       vx_info_bcaps(v, b) : (b))
10320 +
10321 +#define task_vx_mbcap(t, b) \
10322 +       vx_info_mbcap((t)->vx_info, (t)->b)
10323 +
10324 +#define vx_mbcap(b)    task_vx_mbcap(current, b)
10325 +#endif
10326 +
10327 +#define vx_cap_raised(v, c, f) cap_raised(vx_info_mbcaps(v, c), f)
10328 +
10329 +#define vx_capable(b, c) (capable(b) || \
10330 +       (cap_raised(current_cap(), b) && vx_ccaps(c)))
10331 +
10332 +#define vx_ns_capable(n, b, c) (ns_capable(n, b) || \
10333 +       (cap_raised(current_cap(), b) && vx_ccaps(c)))
10334 +
10335 +#define nx_capable(b, c) (capable(b) || \
10336 +       (cap_raised(current_cap(), b) && nx_ncaps(c)))
10337 +
10338 +#define vx_task_initpid(t, n) \
10339 +       ((t)->vx_info && \
10340 +       ((t)->vx_info->vx_initpid == (n)))
10341 +
10342 +#define vx_current_initpid(n)  vx_task_initpid(current, n)
10343 +
10344 +
10345 +/* context unshare mask */
10346 +
10347 +#define __vx_umask(v)          ((v)->vx_umask)
10348 +
10349 +#define vx_current_umask()     __vx_umask(current_vx_info())
10350 +
10351 +#define vx_can_unshare(b, f) (capable(b) || \
10352 +       (cap_raised(current_cap(), b) && \
10353 +       !((f) & ~vx_current_umask())))
10354 +
10355 +#define vx_ns_can_unshare(n, b, f) (ns_capable(n, b) || \
10356 +       (cap_raised(current_cap(), b) && \
10357 +       !((f) & ~vx_current_umask())))
10358 +
10359 +#define __vx_wmask(v)          ((v)->vx_wmask)
10360 +
10361 +#define vx_current_wmask()     __vx_wmask(current_vx_info())
10362 +
10363 +
10364 +#define __vx_state(v)  ((v) ? ((v)->vx_state) : 0)
10365 +
10366 +#define vx_info_state(v, m)    (__vx_state(v) & (m))
10367 +
10368 +
10369 +#define __nx_state(n)  ((n) ? ((n)->nx_state) : 0)
10370 +
10371 +#define nx_info_state(n, m)    (__nx_state(n) & (m))
10372 +
10373 +#endif
10374 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
10375 --- linux-3.9.4/include/linux/vserver/cacct.h   1970-01-01 00:00:00.000000000 +0000
10376 +++ linux-3.9.4-vs2.3.6.2/include/linux/vserver/cacct.h 2013-05-31 14:47:11.000000000 +0000
10377 @@ -0,0 +1,15 @@
10378 +#ifndef _VSERVER_CACCT_H
10379 +#define _VSERVER_CACCT_H
10380 +
10381 +
10382 +enum sock_acc_field {
10383 +       VXA_SOCK_UNSPEC = 0,
10384 +       VXA_SOCK_UNIX,
10385 +       VXA_SOCK_INET,
10386 +       VXA_SOCK_INET6,
10387 +       VXA_SOCK_PACKET,
10388 +       VXA_SOCK_OTHER,
10389 +       VXA_SOCK_SIZE   /* array size */
10390 +};
10391 +
10392 +#endif /* _VSERVER_CACCT_H */
10393 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
10394 --- linux-3.9.4/include/linux/vserver/cacct_cmd.h       1970-01-01 00:00:00.000000000 +0000
10395 +++ linux-3.9.4-vs2.3.6.2/include/linux/vserver/cacct_cmd.h     2013-05-31 14:47:11.000000000 +0000
10396 @@ -0,0 +1,10 @@
10397 +#ifndef _VSERVER_CACCT_CMD_H
10398 +#define _VSERVER_CACCT_CMD_H
10399 +
10400 +
10401 +#include <linux/compiler.h>
10402 +#include <uapi/vserver/cacct_cmd.h>
10403 +
10404 +extern int vc_sock_stat(struct vx_info *, void __user *);
10405 +
10406 +#endif /* _VSERVER_CACCT_CMD_H */
10407 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
10408 --- linux-3.9.4/include/linux/vserver/cacct_def.h       1970-01-01 00:00:00.000000000 +0000
10409 +++ linux-3.9.4-vs2.3.6.2/include/linux/vserver/cacct_def.h     2013-05-31 14:47:11.000000000 +0000
10410 @@ -0,0 +1,43 @@
10411 +#ifndef _VSERVER_CACCT_DEF_H
10412 +#define _VSERVER_CACCT_DEF_H
10413 +
10414 +#include <asm/atomic.h>
10415 +#include <linux/vserver/cacct.h>
10416 +
10417 +
10418 +struct _vx_sock_acc {
10419 +       atomic_long_t count;
10420 +       atomic_long_t total;
10421 +};
10422 +
10423 +/* context sub struct */
10424 +
10425 +struct _vx_cacct {
10426 +       struct _vx_sock_acc sock[VXA_SOCK_SIZE][3];
10427 +       atomic_t slab[8];
10428 +       atomic_t page[6][8];
10429 +};
10430 +
10431 +#ifdef CONFIG_VSERVER_DEBUG
10432 +
10433 +static inline void __dump_vx_cacct(struct _vx_cacct *cacct)
10434 +{
10435 +       int i, j;
10436 +
10437 +       printk("\t_vx_cacct:");
10438 +       for (i = 0; i < 6; i++) {
10439 +               struct _vx_sock_acc *ptr = cacct->sock[i];
10440 +
10441 +               printk("\t [%d] =", i);
10442 +               for (j = 0; j < 3; j++) {
10443 +                       printk(" [%d] = %8lu, %8lu", j,
10444 +                               atomic_long_read(&ptr[j].count),
10445 +                               atomic_long_read(&ptr[j].total));
10446 +               }
10447 +               printk("\n");
10448 +       }
10449 +}
10450 +
10451 +#endif
10452 +
10453 +#endif /* _VSERVER_CACCT_DEF_H */
10454 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
10455 --- linux-3.9.4/include/linux/vserver/cacct_int.h       1970-01-01 00:00:00.000000000 +0000
10456 +++ linux-3.9.4-vs2.3.6.2/include/linux/vserver/cacct_int.h     2013-05-31 14:47:11.000000000 +0000
10457 @@ -0,0 +1,17 @@
10458 +#ifndef _VSERVER_CACCT_INT_H
10459 +#define _VSERVER_CACCT_INT_H
10460 +
10461 +static inline
10462 +unsigned long vx_sock_count(struct _vx_cacct *cacct, int type, int pos)
10463 +{
10464 +       return atomic_long_read(&cacct->sock[type][pos].count);
10465 +}
10466 +
10467 +
10468 +static inline
10469 +unsigned long vx_sock_total(struct _vx_cacct *cacct, int type, int pos)
10470 +{
10471 +       return atomic_long_read(&cacct->sock[type][pos].total);
10472 +}
10473 +
10474 +#endif /* _VSERVER_CACCT_INT_H */
10475 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
10476 --- linux-3.9.4/include/linux/vserver/check.h   1970-01-01 00:00:00.000000000 +0000
10477 +++ linux-3.9.4-vs2.3.6.2/include/linux/vserver/check.h 2013-05-31 14:47:11.000000000 +0000
10478 @@ -0,0 +1,89 @@
10479 +#ifndef _VSERVER_CHECK_H
10480 +#define _VSERVER_CHECK_H
10481 +
10482 +
10483 +#define MAX_S_CONTEXT  65535   /* Arbitrary limit */
10484 +
10485 +#ifdef CONFIG_VSERVER_DYNAMIC_IDS
10486 +#define MIN_D_CONTEXT  49152   /* dynamic contexts start here */
10487 +#else
10488 +#define MIN_D_CONTEXT  65536
10489 +#endif
10490 +
10491 +/* check conditions */
10492 +
10493 +#define VS_ADMIN       0x0001
10494 +#define VS_WATCH       0x0002
10495 +#define VS_HIDE                0x0004
10496 +#define VS_HOSTID      0x0008
10497 +
10498 +#define VS_IDENT       0x0010
10499 +#define VS_EQUIV       0x0020
10500 +#define VS_PARENT      0x0040
10501 +#define VS_CHILD       0x0080
10502 +
10503 +#define VS_ARG_MASK    0x00F0
10504 +
10505 +#define VS_DYNAMIC     0x0100
10506 +#define VS_STATIC      0x0200
10507 +
10508 +#define VS_ATR_MASK    0x0F00
10509 +
10510 +#ifdef CONFIG_VSERVER_PRIVACY
10511 +#define VS_ADMIN_P     (0)
10512 +#define VS_WATCH_P     (0)
10513 +#else
10514 +#define VS_ADMIN_P     VS_ADMIN
10515 +#define VS_WATCH_P     VS_WATCH
10516 +#endif
10517 +
10518 +#define VS_HARDIRQ     0x1000
10519 +#define VS_SOFTIRQ     0x2000
10520 +#define VS_IRQ         0x4000
10521 +
10522 +#define VS_IRQ_MASK    0xF000
10523 +
10524 +#include <linux/hardirq.h>
10525 +
10526 +/*
10527 + * check current context for ADMIN/WATCH and
10528 + * optionally against supplied argument
10529 + */
10530 +static inline int __vs_check(int cid, int id, unsigned int mode)
10531 +{
10532 +       if (mode & VS_ARG_MASK) {
10533 +               if ((mode & VS_IDENT) && (id == cid))
10534 +                       return 1;
10535 +       }
10536 +       if (mode & VS_ATR_MASK) {
10537 +               if ((mode & VS_DYNAMIC) &&
10538 +                       (id >= MIN_D_CONTEXT) &&
10539 +                       (id <= MAX_S_CONTEXT))
10540 +                       return 1;
10541 +               if ((mode & VS_STATIC) &&
10542 +                       (id > 1) && (id < MIN_D_CONTEXT))
10543 +                       return 1;
10544 +       }
10545 +       if (mode & VS_IRQ_MASK) {
10546 +               if ((mode & VS_IRQ) && unlikely(in_interrupt()))
10547 +                       return 1;
10548 +               if ((mode & VS_HARDIRQ) && unlikely(in_irq()))
10549 +                       return 1;
10550 +               if ((mode & VS_SOFTIRQ) && unlikely(in_softirq()))
10551 +                       return 1;
10552 +       }
10553 +       return (((mode & VS_ADMIN) && (cid == 0)) ||
10554 +               ((mode & VS_WATCH) && (cid == 1)) ||
10555 +               ((mode & VS_HOSTID) && (id == 0)));
10556 +}
10557 +
10558 +#define vx_check(c, m) __vs_check(vx_current_xid(), c, (m) | VS_IRQ)
10559 +
10560 +#define vx_weak_check(c, m)    ((m) ? vx_check(c, m) : 1)
10561 +
10562 +
10563 +#define nx_check(c, m) __vs_check(nx_current_nid(), c, m)
10564 +
10565 +#define nx_weak_check(c, m)    ((m) ? nx_check(c, m) : 1)
10566 +
10567 +#endif
10568 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
10569 --- linux-3.9.4/include/linux/vserver/context.h 1970-01-01 00:00:00.000000000 +0000
10570 +++ linux-3.9.4-vs2.3.6.2/include/linux/vserver/context.h       2013-05-31 14:47:11.000000000 +0000
10571 @@ -0,0 +1,110 @@
10572 +#ifndef _VSERVER_CONTEXT_H
10573 +#define _VSERVER_CONTEXT_H
10574 +
10575 +
10576 +#include <linux/list.h>
10577 +#include <linux/spinlock.h>
10578 +#include <linux/rcupdate.h>
10579 +#include <uapi/vserver/context.h>
10580 +
10581 +#include "limit_def.h"
10582 +#include "sched_def.h"
10583 +#include "cvirt_def.h"
10584 +#include "cacct_def.h"
10585 +#include "device_def.h"
10586 +
10587 +#define VX_SPACES      2
10588 +
10589 +struct _vx_info_pc {
10590 +       struct _vx_sched_pc sched_pc;
10591 +       struct _vx_cvirt_pc cvirt_pc;
10592 +};
10593 +
10594 +struct _vx_space {
10595 +       unsigned long vx_nsmask;                /* assignment mask */
10596 +       struct nsproxy *vx_nsproxy;             /* private namespaces */
10597 +       struct fs_struct *vx_fs;                /* private namespace fs */
10598 +       const struct cred *vx_cred;             /* task credentials */
10599 +};
10600 +
10601 +struct vx_info {
10602 +       struct hlist_node vx_hlist;             /* linked list of contexts */
10603 +       xid_t vx_id;                            /* context id */
10604 +       atomic_t vx_usecnt;                     /* usage count */
10605 +       atomic_t vx_tasks;                      /* tasks count */
10606 +       struct vx_info *vx_parent;              /* parent context */
10607 +       int vx_state;                           /* context state */
10608 +
10609 +       struct _vx_space space[VX_SPACES];      /* namespace store */
10610 +
10611 +       uint64_t vx_flags;                      /* context flags */
10612 +       uint64_t vx_ccaps;                      /* context caps (vserver) */
10613 +       uint64_t vx_umask;                      /* unshare mask (guest) */
10614 +       uint64_t vx_wmask;                      /* warn mask (guest) */
10615 +       kernel_cap_t vx_bcaps;                  /* bounding caps (system) */
10616 +
10617 +       struct task_struct *vx_reaper;          /* guest reaper process */
10618 +       pid_t vx_initpid;                       /* PID of guest init */
10619 +       int64_t vx_badness_bias;                /* OOM points bias */
10620 +
10621 +       struct _vx_limit limit;                 /* vserver limits */
10622 +       struct _vx_sched sched;                 /* vserver scheduler */
10623 +       struct _vx_cvirt cvirt;                 /* virtual/bias stuff */
10624 +       struct _vx_cacct cacct;                 /* context accounting */
10625 +
10626 +       struct _vx_device dmap;                 /* default device map targets */
10627 +
10628 +#ifndef CONFIG_SMP
10629 +       struct _vx_info_pc info_pc;             /* per cpu data */
10630 +#else
10631 +       struct _vx_info_pc *ptr_pc;             /* per cpu array */
10632 +#endif
10633 +
10634 +       wait_queue_head_t vx_wait;              /* context exit waitqueue */
10635 +       int reboot_cmd;                         /* last sys_reboot() cmd */
10636 +       int exit_code;                          /* last process exit code */
10637 +
10638 +       char vx_name[65];                       /* vserver name */
10639 +};
10640 +
10641 +#ifndef CONFIG_SMP
10642 +#define        vx_ptr_pc(vxi)          (&(vxi)->info_pc)
10643 +#define        vx_per_cpu(vxi, v, id)  vx_ptr_pc(vxi)->v
10644 +#else
10645 +#define        vx_ptr_pc(vxi)          ((vxi)->ptr_pc)
10646 +#define        vx_per_cpu(vxi, v, id)  per_cpu_ptr(vx_ptr_pc(vxi), id)->v
10647 +#endif
10648 +
10649 +#define        vx_cpu(vxi, v)          vx_per_cpu(vxi, v, smp_processor_id())
10650 +
10651 +
10652 +struct vx_info_save {
10653 +       struct vx_info *vxi;
10654 +       xid_t xid;
10655 +};
10656 +
10657 +
10658 +/* status flags */
10659 +
10660 +#define VXS_HASHED     0x0001
10661 +#define VXS_PAUSED     0x0010
10662 +#define VXS_SHUTDOWN   0x0100
10663 +#define VXS_HELPER     0x1000
10664 +#define VXS_RELEASED   0x8000
10665 +
10666 +
10667 +extern void claim_vx_info(struct vx_info *, struct task_struct *);
10668 +extern void release_vx_info(struct vx_info *, struct task_struct *);
10669 +
10670 +extern struct vx_info *lookup_vx_info(int);
10671 +extern struct vx_info *lookup_or_create_vx_info(int);
10672 +
10673 +extern int get_xid_list(int, unsigned int *, int);
10674 +extern int xid_is_hashed(xid_t);
10675 +
10676 +extern int vx_migrate_task(struct task_struct *, struct vx_info *, int);
10677 +
10678 +extern long vs_state_change(struct vx_info *, unsigned int);
10679 +
10680 +
10681 +#endif /* _VSERVER_CONTEXT_H */
10682 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
10683 --- linux-3.9.4/include/linux/vserver/context_cmd.h     1970-01-01 00:00:00.000000000 +0000
10684 +++ linux-3.9.4-vs2.3.6.2/include/linux/vserver/context_cmd.h   2013-05-31 14:47:11.000000000 +0000
10685 @@ -0,0 +1,33 @@
10686 +#ifndef _VSERVER_CONTEXT_CMD_H
10687 +#define _VSERVER_CONTEXT_CMD_H
10688 +
10689 +#include <uapi/vserver/context_cmd.h>
10690 +
10691 +extern int vc_task_xid(uint32_t);
10692 +
10693 +extern int vc_vx_info(struct vx_info *, void __user *);
10694 +
10695 +extern int vc_ctx_stat(struct vx_info *, void __user *);
10696 +
10697 +extern int vc_ctx_create(uint32_t, void __user *);
10698 +extern int vc_ctx_migrate(struct vx_info *, void __user *);
10699 +
10700 +extern int vc_get_cflags(struct vx_info *, void __user *);
10701 +extern int vc_set_cflags(struct vx_info *, void __user *);
10702 +
10703 +extern int vc_get_ccaps(struct vx_info *, void __user *);
10704 +extern int vc_set_ccaps(struct vx_info *, void __user *);
10705 +
10706 +extern int vc_get_bcaps(struct vx_info *, void __user *);
10707 +extern int vc_set_bcaps(struct vx_info *, void __user *);
10708 +
10709 +extern int vc_get_umask(struct vx_info *, void __user *);
10710 +extern int vc_set_umask(struct vx_info *, void __user *);
10711 +
10712 +extern int vc_get_wmask(struct vx_info *, void __user *);
10713 +extern int vc_set_wmask(struct vx_info *, void __user *);
10714 +
10715 +extern int vc_get_badness(struct vx_info *, void __user *);
10716 +extern int vc_set_badness(struct vx_info *, void __user *);
10717 +
10718 +#endif /* _VSERVER_CONTEXT_CMD_H */
10719 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
10720 --- linux-3.9.4/include/linux/vserver/cvirt.h   1970-01-01 00:00:00.000000000 +0000
10721 +++ linux-3.9.4-vs2.3.6.2/include/linux/vserver/cvirt.h 2013-05-31 14:47:11.000000000 +0000
10722 @@ -0,0 +1,18 @@
10723 +#ifndef _VSERVER_CVIRT_H
10724 +#define _VSERVER_CVIRT_H
10725 +
10726 +struct timespec;
10727 +
10728 +void vx_vsi_boottime(struct timespec *);
10729 +
10730 +void vx_vsi_uptime(struct timespec *, struct timespec *);
10731 +
10732 +
10733 +struct vx_info;
10734 +
10735 +void vx_update_load(struct vx_info *);
10736 +
10737 +
10738 +int vx_do_syslog(int, char __user *, int);
10739 +
10740 +#endif /* _VSERVER_CVIRT_H */
10741 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
10742 --- linux-3.9.4/include/linux/vserver/cvirt_cmd.h       1970-01-01 00:00:00.000000000 +0000
10743 +++ linux-3.9.4-vs2.3.6.2/include/linux/vserver/cvirt_cmd.h     2013-05-31 14:47:11.000000000 +0000
10744 @@ -0,0 +1,13 @@
10745 +#ifndef _VSERVER_CVIRT_CMD_H
10746 +#define _VSERVER_CVIRT_CMD_H
10747 +
10748 +
10749 +#include <linux/compiler.h>
10750 +#include <uapi/vserver/cvirt_cmd.h>
10751 +
10752 +extern int vc_set_vhi_name(struct vx_info *, void __user *);
10753 +extern int vc_get_vhi_name(struct vx_info *, void __user *);
10754 +
10755 +extern int vc_virt_stat(struct vx_info *, void __user *);
10756 +
10757 +#endif /* _VSERVER_CVIRT_CMD_H */
10758 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
10759 --- linux-3.9.4/include/linux/vserver/cvirt_def.h       1970-01-01 00:00:00.000000000 +0000
10760 +++ linux-3.9.4-vs2.3.6.2/include/linux/vserver/cvirt_def.h     2013-05-31 14:47:11.000000000 +0000
10761 @@ -0,0 +1,80 @@
10762 +#ifndef _VSERVER_CVIRT_DEF_H
10763 +#define _VSERVER_CVIRT_DEF_H
10764 +
10765 +#include <linux/jiffies.h>
10766 +#include <linux/spinlock.h>
10767 +#include <linux/wait.h>
10768 +#include <linux/time.h>
10769 +#include <asm/atomic.h>
10770 +
10771 +
10772 +struct _vx_usage_stat {
10773 +       uint64_t user;
10774 +       uint64_t nice;
10775 +       uint64_t system;
10776 +       uint64_t softirq;
10777 +       uint64_t irq;
10778 +       uint64_t idle;
10779 +       uint64_t iowait;
10780 +};
10781 +
10782 +struct _vx_syslog {
10783 +       wait_queue_head_t log_wait;
10784 +       spinlock_t logbuf_lock;         /* lock for the log buffer */
10785 +
10786 +       unsigned long log_start;        /* next char to be read by syslog() */
10787 +       unsigned long con_start;        /* next char to be sent to consoles */
10788 +       unsigned long log_end;  /* most-recently-written-char + 1 */
10789 +       unsigned long logged_chars;     /* #chars since last read+clear operation */
10790 +
10791 +       char log_buf[1024];
10792 +};
10793 +
10794 +
10795 +/* context sub struct */
10796 +
10797 +struct _vx_cvirt {
10798 +       atomic_t nr_threads;            /* number of current threads */
10799 +       atomic_t nr_running;            /* number of running threads */
10800 +       atomic_t nr_uninterruptible;    /* number of uninterruptible threads */
10801 +
10802 +       atomic_t nr_onhold;             /* processes on hold */
10803 +       uint32_t onhold_last;           /* jiffies when put on hold */
10804 +
10805 +       struct timespec bias_ts;        /* time offset to the host */
10806 +       struct timespec bias_idle;
10807 +       struct timespec bias_uptime;    /* context creation point */
10808 +       uint64_t bias_clock;            /* offset in clock_t */
10809 +
10810 +       spinlock_t load_lock;           /* lock for the load averages */
10811 +       atomic_t load_updates;          /* nr of load updates done so far */
10812 +       uint32_t load_last;             /* last time load was calculated */
10813 +       uint32_t load[3];               /* load averages 1,5,15 */
10814 +
10815 +       atomic_t total_forks;           /* number of forks so far */
10816 +
10817 +       struct _vx_syslog syslog;
10818 +};
10819 +
10820 +struct _vx_cvirt_pc {
10821 +       struct _vx_usage_stat cpustat;
10822 +};
10823 +
10824 +
10825 +#ifdef CONFIG_VSERVER_DEBUG
10826 +
10827 +static inline void __dump_vx_cvirt(struct _vx_cvirt *cvirt)
10828 +{
10829 +       printk("\t_vx_cvirt:\n");
10830 +       printk("\t threads: %4d, %4d, %4d, %4d\n",
10831 +               atomic_read(&cvirt->nr_threads),
10832 +               atomic_read(&cvirt->nr_running),
10833 +               atomic_read(&cvirt->nr_uninterruptible),
10834 +               atomic_read(&cvirt->nr_onhold));
10835 +       /* add rest here */
10836 +       printk("\t total_forks = %d\n", atomic_read(&cvirt->total_forks));
10837 +}
10838 +
10839 +#endif
10840 +
10841 +#endif /* _VSERVER_CVIRT_DEF_H */
10842 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
10843 --- linux-3.9.4/include/linux/vserver/debug.h   1970-01-01 00:00:00.000000000 +0000
10844 +++ linux-3.9.4-vs2.3.6.2/include/linux/vserver/debug.h 2013-05-31 14:47:11.000000000 +0000
10845 @@ -0,0 +1,145 @@
10846 +#ifndef _VSERVER_DEBUG_H
10847 +#define _VSERVER_DEBUG_H
10848 +
10849 +
10850 +#define VXD_CBIT(n, m) (vs_debug_ ## n & (1 << (m)))
10851 +#define VXD_CMIN(n, m) (vs_debug_ ## n > (m))
10852 +#define VXD_MASK(n, m) (vs_debug_ ## n & (m))
10853 +
10854 +#define VXD_DEV(d)     (d), (d)->bd_inode->i_ino,              \
10855 +                       imajor((d)->bd_inode), iminor((d)->bd_inode)
10856 +#define VXF_DEV                "%p[%lu,%d:%d]"
10857 +
10858 +#if    defined(CONFIG_QUOTES_UTF8)
10859 +#define        VS_Q_LQM        "\xc2\xbb"
10860 +#define        VS_Q_RQM        "\xc2\xab"
10861 +#elif  defined(CONFIG_QUOTES_ASCII)
10862 +#define        VS_Q_LQM        "\x27"
10863 +#define        VS_Q_RQM        "\x27"
10864 +#else
10865 +#define        VS_Q_LQM        "\xbb"
10866 +#define        VS_Q_RQM        "\xab"
10867 +#endif
10868 +
10869 +#define        VS_Q(f)         VS_Q_LQM f VS_Q_RQM
10870 +
10871 +
10872 +#define vxd_path(p)                                            \
10873 +       ({ static char _buffer[PATH_MAX];                       \
10874 +          d_path(p, _buffer, sizeof(_buffer)); })
10875 +
10876 +#define vxd_cond_path(n)                                       \
10877 +       ((n) ? vxd_path(&(n)->path) : "<null>" )
10878 +
10879 +
10880 +#ifdef CONFIG_VSERVER_DEBUG
10881 +
10882 +extern unsigned int vs_debug_switch;
10883 +extern unsigned int vs_debug_xid;
10884 +extern unsigned int vs_debug_nid;
10885 +extern unsigned int vs_debug_tag;
10886 +extern unsigned int vs_debug_net;
10887 +extern unsigned int vs_debug_limit;
10888 +extern unsigned int vs_debug_cres;
10889 +extern unsigned int vs_debug_dlim;
10890 +extern unsigned int vs_debug_quota;
10891 +extern unsigned int vs_debug_cvirt;
10892 +extern unsigned int vs_debug_space;
10893 +extern unsigned int vs_debug_perm;
10894 +extern unsigned int vs_debug_misc;
10895 +
10896 +
10897 +#define VX_LOGLEVEL    "vxD: "
10898 +#define VX_PROC_FMT    "%p: "
10899 +#define VX_PROCESS     current
10900 +
10901 +#define vxdprintk(c, f, x...)                                  \
10902 +       do {                                                    \
10903 +               if (c)                                          \
10904 +                       printk(VX_LOGLEVEL VX_PROC_FMT f "\n",  \
10905 +                               VX_PROCESS , ##x);              \
10906 +       } while (0)
10907 +
10908 +#define vxlprintk(c, f, x...)                                  \
10909 +       do {                                                    \
10910 +               if (c)                                          \
10911 +                       printk(VX_LOGLEVEL f " @%s:%d\n", x);   \
10912 +       } while (0)
10913 +
10914 +#define vxfprintk(c, f, x...)                                  \
10915 +       do {                                                    \
10916 +               if (c)                                          \
10917 +                       printk(VX_LOGLEVEL f " %s@%s:%d\n", x); \
10918 +       } while (0)
10919 +
10920 +
10921 +struct vx_info;
10922 +
10923 +void dump_vx_info(struct vx_info *, int);
10924 +void dump_vx_info_inactive(int);
10925 +
10926 +#else  /* CONFIG_VSERVER_DEBUG */
10927 +
10928 +#define vs_debug_switch        0
10929 +#define vs_debug_xid   0
10930 +#define vs_debug_nid   0
10931 +#define vs_debug_tag   0
10932 +#define vs_debug_net   0
10933 +#define vs_debug_limit 0
10934 +#define vs_debug_cres  0
10935 +#define vs_debug_dlim  0
10936 +#define vs_debug_quota 0
10937 +#define vs_debug_cvirt 0
10938 +#define vs_debug_space 0
10939 +#define vs_debug_perm  0
10940 +#define vs_debug_misc  0
10941 +
10942 +#define vxdprintk(x...) do { } while (0)
10943 +#define vxlprintk(x...) do { } while (0)
10944 +#define vxfprintk(x...) do { } while (0)
10945 +
10946 +#endif /* CONFIG_VSERVER_DEBUG */
10947 +
10948 +
10949 +#ifdef CONFIG_VSERVER_WARN
10950 +
10951 +#define VX_WARNLEVEL   KERN_WARNING "vxW: "
10952 +#define VX_WARN_TASK   "[" VS_Q("%s") ",%u:#%u|%u|%u] "
10953 +#define VX_WARN_XID    "[xid #%u] "
10954 +#define VX_WARN_NID    "[nid #%u] "
10955 +#define VX_WARN_TAG    "[tag #%u] "
10956 +
10957 +#define vxwprintk(c, f, x...)                                  \
10958 +       do {                                                    \
10959 +               if (c)                                          \
10960 +                       printk(VX_WARNLEVEL f "\n", ##x);       \
10961 +       } while (0)
10962 +
10963 +#else  /* CONFIG_VSERVER_WARN */
10964 +
10965 +#define vxwprintk(x...) do { } while (0)
10966 +
10967 +#endif /* CONFIG_VSERVER_WARN */
10968 +
10969 +#define vxwprintk_task(c, f, x...)                             \
10970 +       vxwprintk(c, VX_WARN_TASK f,                            \
10971 +               current->comm, current->pid,                    \
10972 +               current->xid, current->nid, current->tag, ##x)
10973 +#define vxwprintk_xid(c, f, x...)                              \
10974 +       vxwprintk(c, VX_WARN_XID f, current->xid, x)
10975 +#define vxwprintk_nid(c, f, x...)                              \
10976 +       vxwprintk(c, VX_WARN_NID f, current->nid, x)
10977 +#define vxwprintk_tag(c, f, x...)                              \
10978 +       vxwprintk(c, VX_WARN_TAG f, current->tag, x)
10979 +
10980 +#ifdef CONFIG_VSERVER_DEBUG
10981 +#define vxd_assert_lock(l)     assert_spin_locked(l)
10982 +#define vxd_assert(c, f, x...) vxlprintk(!(c), \
10983 +       "assertion [" f "] failed.", ##x, __FILE__, __LINE__)
10984 +#else
10985 +#define vxd_assert_lock(l)     do { } while (0)
10986 +#define vxd_assert(c, f, x...) do { } while (0)
10987 +#endif
10988 +
10989 +
10990 +#endif /* _VSERVER_DEBUG_H */
10991 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
10992 --- linux-3.9.4/include/linux/vserver/debug_cmd.h       1970-01-01 00:00:00.000000000 +0000
10993 +++ linux-3.9.4-vs2.3.6.2/include/linux/vserver/debug_cmd.h     2013-05-31 14:47:11.000000000 +0000
10994 @@ -0,0 +1,37 @@
10995 +#ifndef _VSERVER_DEBUG_CMD_H
10996 +#define _VSERVER_DEBUG_CMD_H
10997 +
10998 +#include <uapi/vserver/debug_cmd.h>
10999 +
11000 +
11001 +#ifdef CONFIG_COMPAT
11002 +
11003 +#include <asm/compat.h>
11004 +
11005 +struct vcmd_read_history_v0_x32 {
11006 +       uint32_t index;
11007 +       uint32_t count;
11008 +       compat_uptr_t data_ptr;
11009 +};
11010 +
11011 +struct vcmd_read_monitor_v0_x32 {
11012 +       uint32_t index;
11013 +       uint32_t count;
11014 +       compat_uptr_t data_ptr;
11015 +};
11016 +
11017 +#endif  /* CONFIG_COMPAT */
11018 +
11019 +extern int vc_dump_history(uint32_t);
11020 +
11021 +extern int vc_read_history(uint32_t, void __user *);
11022 +extern int vc_read_monitor(uint32_t, void __user *);
11023 +
11024 +#ifdef CONFIG_COMPAT
11025 +
11026 +extern int vc_read_history_x32(uint32_t, void __user *);
11027 +extern int vc_read_monitor_x32(uint32_t, void __user *);
11028 +
11029 +#endif  /* CONFIG_COMPAT */
11030 +
11031 +#endif /* _VSERVER_DEBUG_CMD_H */
11032 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
11033 --- linux-3.9.4/include/linux/vserver/device.h  1970-01-01 00:00:00.000000000 +0000
11034 +++ linux-3.9.4-vs2.3.6.2/include/linux/vserver/device.h        2013-05-31 14:47:11.000000000 +0000
11035 @@ -0,0 +1,9 @@
11036 +#ifndef _VSERVER_DEVICE_H
11037 +#define _VSERVER_DEVICE_H
11038 +
11039 +
11040 +#include <uapi/vserver/device.h>
11041 +
11042 +#else  /* _VSERVER_DEVICE_H */
11043 +#warning duplicate inclusion
11044 +#endif /* _VSERVER_DEVICE_H */
11045 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
11046 --- linux-3.9.4/include/linux/vserver/device_cmd.h      1970-01-01 00:00:00.000000000 +0000
11047 +++ linux-3.9.4-vs2.3.6.2/include/linux/vserver/device_cmd.h    2013-05-31 14:47:11.000000000 +0000
11048 @@ -0,0 +1,31 @@
11049 +#ifndef _VSERVER_DEVICE_CMD_H
11050 +#define _VSERVER_DEVICE_CMD_H
11051 +
11052 +#include <uapi/vserver/device_cmd.h>
11053 +
11054 +
11055 +#ifdef CONFIG_COMPAT
11056 +
11057 +#include <asm/compat.h>
11058 +
11059 +struct vcmd_set_mapping_v0_x32 {
11060 +       compat_uptr_t device_ptr;
11061 +       compat_uptr_t target_ptr;
11062 +       uint32_t flags;
11063 +};
11064 +
11065 +#endif /* CONFIG_COMPAT */
11066 +
11067 +#include <linux/compiler.h>
11068 +
11069 +extern int vc_set_mapping(struct vx_info *, void __user *);
11070 +extern int vc_unset_mapping(struct vx_info *, void __user *);
11071 +
11072 +#ifdef CONFIG_COMPAT
11073 +
11074 +extern int vc_set_mapping_x32(struct vx_info *, void __user *);
11075 +extern int vc_unset_mapping_x32(struct vx_info *, void __user *);
11076 +
11077 +#endif /* CONFIG_COMPAT */
11078 +
11079 +#endif /* _VSERVER_DEVICE_CMD_H */
11080 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
11081 --- linux-3.9.4/include/linux/vserver/device_def.h      1970-01-01 00:00:00.000000000 +0000
11082 +++ linux-3.9.4-vs2.3.6.2/include/linux/vserver/device_def.h    2013-05-31 14:47:11.000000000 +0000
11083 @@ -0,0 +1,17 @@
11084 +#ifndef _VSERVER_DEVICE_DEF_H
11085 +#define _VSERVER_DEVICE_DEF_H
11086 +
11087 +#include <linux/types.h>
11088 +
11089 +struct vx_dmap_target {
11090 +       dev_t target;
11091 +       uint32_t flags;
11092 +};
11093 +
11094 +struct _vx_device {
11095 +#ifdef CONFIG_VSERVER_DEVICE
11096 +       struct vx_dmap_target targets[2];
11097 +#endif
11098 +};
11099 +
11100 +#endif /* _VSERVER_DEVICE_DEF_H */
11101 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
11102 --- linux-3.9.4/include/linux/vserver/dlimit.h  1970-01-01 00:00:00.000000000 +0000
11103 +++ linux-3.9.4-vs2.3.6.2/include/linux/vserver/dlimit.h        2013-05-31 14:47:11.000000000 +0000
11104 @@ -0,0 +1,54 @@
11105 +#ifndef _VSERVER_DLIMIT_H
11106 +#define _VSERVER_DLIMIT_H
11107 +
11108 +#include "switch.h"
11109 +
11110 +
11111 +#ifdef __KERNEL__
11112 +
11113 +/*      keep in sync with CDLIM_INFINITY       */
11114 +
11115 +#define DLIM_INFINITY          (~0ULL)
11116 +
11117 +#include <linux/spinlock.h>
11118 +#include <linux/rcupdate.h>
11119 +
11120 +struct super_block;
11121 +
11122 +struct dl_info {
11123 +       struct hlist_node dl_hlist;             /* linked list of contexts */
11124 +       struct rcu_head dl_rcu;                 /* the rcu head */
11125 +       tag_t dl_tag;                           /* context tag */
11126 +       atomic_t dl_usecnt;                     /* usage count */
11127 +       atomic_t dl_refcnt;                     /* reference count */
11128 +
11129 +       struct super_block *dl_sb;              /* associated superblock */
11130 +
11131 +       spinlock_t dl_lock;                     /* protect the values */
11132 +
11133 +       unsigned long long dl_space_used;       /* used space in bytes */
11134 +       unsigned long long dl_space_total;      /* maximum space in bytes */
11135 +       unsigned long dl_inodes_used;           /* used inodes */
11136 +       unsigned long dl_inodes_total;          /* maximum inodes */
11137 +
11138 +       unsigned int dl_nrlmult;                /* non root limit mult */
11139 +};
11140 +
11141 +struct rcu_head;
11142 +
11143 +extern void rcu_free_dl_info(struct rcu_head *);
11144 +extern void unhash_dl_info(struct dl_info *);
11145 +
11146 +extern struct dl_info *locate_dl_info(struct super_block *, tag_t);
11147 +
11148 +
11149 +struct kstatfs;
11150 +
11151 +extern void vx_vsi_statfs(struct super_block *, struct kstatfs *);
11152 +
11153 +typedef uint64_t dlsize_t;
11154 +
11155 +#endif /* __KERNEL__ */
11156 +#else  /* _VSERVER_DLIMIT_H */
11157 +#warning duplicate inclusion
11158 +#endif /* _VSERVER_DLIMIT_H */
11159 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
11160 --- linux-3.9.4/include/linux/vserver/dlimit_cmd.h      1970-01-01 00:00:00.000000000 +0000
11161 +++ linux-3.9.4-vs2.3.6.2/include/linux/vserver/dlimit_cmd.h    2013-05-31 14:47:11.000000000 +0000
11162 @@ -0,0 +1,46 @@
11163 +#ifndef _VSERVER_DLIMIT_CMD_H
11164 +#define _VSERVER_DLIMIT_CMD_H
11165 +
11166 +#include <uapi/vserver/dlimit_cmd.h>
11167 +
11168 +
11169 +#ifdef CONFIG_COMPAT
11170 +
11171 +#include <asm/compat.h>
11172 +
11173 +struct vcmd_ctx_dlimit_base_v0_x32 {
11174 +       compat_uptr_t name_ptr;
11175 +       uint32_t flags;
11176 +};
11177 +
11178 +struct vcmd_ctx_dlimit_v0_x32 {
11179 +       compat_uptr_t name_ptr;
11180 +       uint32_t space_used;                    /* used space in kbytes */
11181 +       uint32_t space_total;                   /* maximum space in kbytes */
11182 +       uint32_t inodes_used;                   /* used inodes */
11183 +       uint32_t inodes_total;                  /* maximum inodes */
11184 +       uint32_t reserved;                      /* reserved for root in % */
11185 +       uint32_t flags;
11186 +};
11187 +
11188 +#endif /* CONFIG_COMPAT */
11189 +
11190 +#include <linux/compiler.h>
11191 +
11192 +extern int vc_add_dlimit(uint32_t, void __user *);
11193 +extern int vc_rem_dlimit(uint32_t, void __user *);
11194 +
11195 +extern int vc_set_dlimit(uint32_t, void __user *);
11196 +extern int vc_get_dlimit(uint32_t, void __user *);
11197 +
11198 +#ifdef CONFIG_COMPAT
11199 +
11200 +extern int vc_add_dlimit_x32(uint32_t, void __user *);
11201 +extern int vc_rem_dlimit_x32(uint32_t, void __user *);
11202 +
11203 +extern int vc_set_dlimit_x32(uint32_t, void __user *);
11204 +extern int vc_get_dlimit_x32(uint32_t, void __user *);
11205 +
11206 +#endif /* CONFIG_COMPAT */
11207 +
11208 +#endif /* _VSERVER_DLIMIT_CMD_H */
11209 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
11210 --- linux-3.9.4/include/linux/vserver/global.h  1970-01-01 00:00:00.000000000 +0000
11211 +++ linux-3.9.4-vs2.3.6.2/include/linux/vserver/global.h        2013-05-31 14:47:11.000000000 +0000
11212 @@ -0,0 +1,19 @@
11213 +#ifndef _VSERVER_GLOBAL_H
11214 +#define _VSERVER_GLOBAL_H
11215 +
11216 +
11217 +extern atomic_t vx_global_ctotal;
11218 +extern atomic_t vx_global_cactive;
11219 +
11220 +extern atomic_t nx_global_ctotal;
11221 +extern atomic_t nx_global_cactive;
11222 +
11223 +extern atomic_t vs_global_nsproxy;
11224 +extern atomic_t vs_global_fs;
11225 +extern atomic_t vs_global_mnt_ns;
11226 +extern atomic_t vs_global_uts_ns;
11227 +extern atomic_t vs_global_user_ns;
11228 +extern atomic_t vs_global_pid_ns;
11229 +
11230 +
11231 +#endif /* _VSERVER_GLOBAL_H */
11232 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
11233 --- linux-3.9.4/include/linux/vserver/history.h 1970-01-01 00:00:00.000000000 +0000
11234 +++ linux-3.9.4-vs2.3.6.2/include/linux/vserver/history.h       2013-05-31 14:47:11.000000000 +0000
11235 @@ -0,0 +1,197 @@
11236 +#ifndef _VSERVER_HISTORY_H
11237 +#define _VSERVER_HISTORY_H
11238 +
11239 +
11240 +enum {
11241 +       VXH_UNUSED = 0,
11242 +       VXH_THROW_OOPS = 1,
11243 +
11244 +       VXH_GET_VX_INFO,
11245 +       VXH_PUT_VX_INFO,
11246 +       VXH_INIT_VX_INFO,
11247 +       VXH_SET_VX_INFO,
11248 +       VXH_CLR_VX_INFO,
11249 +       VXH_CLAIM_VX_INFO,
11250 +       VXH_RELEASE_VX_INFO,
11251 +       VXH_ALLOC_VX_INFO,
11252 +       VXH_DEALLOC_VX_INFO,
11253 +       VXH_HASH_VX_INFO,
11254 +       VXH_UNHASH_VX_INFO,
11255 +       VXH_LOC_VX_INFO,
11256 +       VXH_LOOKUP_VX_INFO,
11257 +       VXH_CREATE_VX_INFO,
11258 +};
11259 +
11260 +struct _vxhe_vxi {
11261 +       struct vx_info *ptr;
11262 +       unsigned xid;
11263 +       unsigned usecnt;
11264 +       unsigned tasks;
11265 +};
11266 +
11267 +struct _vxhe_set_clr {
11268 +       void *data;
11269 +};
11270 +
11271 +struct _vxhe_loc_lookup {
11272 +       unsigned arg;
11273 +};
11274 +
11275 +struct _vx_hist_entry {
11276 +       void *loc;
11277 +       unsigned short seq;
11278 +       unsigned short type;
11279 +       struct _vxhe_vxi vxi;
11280 +       union {
11281 +               struct _vxhe_set_clr sc;
11282 +               struct _vxhe_loc_lookup ll;
11283 +       };
11284 +};
11285 +
11286 +#ifdef CONFIG_VSERVER_HISTORY
11287 +
11288 +extern unsigned volatile int vxh_active;
11289 +
11290 +struct _vx_hist_entry *vxh_advance(void *loc);
11291 +
11292 +
11293 +static inline
11294 +void   __vxh_copy_vxi(struct _vx_hist_entry *entry, struct vx_info *vxi)
11295 +{
11296 +       entry->vxi.ptr = vxi;
11297 +       if (vxi) {
11298 +               entry->vxi.usecnt = atomic_read(&vxi->vx_usecnt);
11299 +               entry->vxi.tasks = atomic_read(&vxi->vx_tasks);
11300 +               entry->vxi.xid = vxi->vx_id;
11301 +       }
11302 +}
11303 +
11304 +
11305 +#define        __HERE__ current_text_addr()
11306 +
11307 +#define __VXH_BODY(__type, __data, __here)     \
11308 +       struct _vx_hist_entry *entry;           \
11309 +                                               \
11310 +       preempt_disable();                      \
11311 +       entry = vxh_advance(__here);            \
11312 +       __data;                                 \
11313 +       entry->type = __type;                   \
11314 +       preempt_enable();
11315 +
11316 +
11317 +       /* pass vxi only */
11318 +
11319 +#define __VXH_SMPL                             \
11320 +       __vxh_copy_vxi(entry, vxi)
11321 +
11322 +static inline
11323 +void   __vxh_smpl(struct vx_info *vxi, int __type, void *__here)
11324 +{
11325 +       __VXH_BODY(__type, __VXH_SMPL, __here)
11326 +}
11327 +
11328 +       /* pass vxi and data (void *) */
11329 +
11330 +#define __VXH_DATA                             \
11331 +       __vxh_copy_vxi(entry, vxi);             \
11332 +       entry->sc.data = data
11333 +
11334 +static inline
11335 +void   __vxh_data(struct vx_info *vxi, void *data,
11336 +                       int __type, void *__here)
11337 +{
11338 +       __VXH_BODY(__type, __VXH_DATA, __here)
11339 +}
11340 +
11341 +       /* pass vxi and arg (long) */
11342 +
11343 +#define __VXH_LONG                             \
11344 +       __vxh_copy_vxi(entry, vxi);             \
11345 +       entry->ll.arg = arg
11346 +
11347 +static inline
11348 +void   __vxh_long(struct vx_info *vxi, long arg,
11349 +                       int __type, void *__here)
11350 +{
11351 +       __VXH_BODY(__type, __VXH_LONG, __here)
11352 +}
11353 +
11354 +
11355 +static inline
11356 +void   __vxh_throw_oops(void *__here)
11357 +{
11358 +       __VXH_BODY(VXH_THROW_OOPS, {}, __here);
11359 +       /* prevent further acquisition */
11360 +       vxh_active = 0;
11361 +}
11362 +
11363 +
11364 +#define vxh_throw_oops()       __vxh_throw_oops(__HERE__);
11365 +
11366 +#define __vxh_get_vx_info(v, h)        __vxh_smpl(v, VXH_GET_VX_INFO, h);
11367 +#define __vxh_put_vx_info(v, h)        __vxh_smpl(v, VXH_PUT_VX_INFO, h);
11368 +
11369 +#define __vxh_init_vx_info(v, d, h) \
11370 +       __vxh_data(v, d, VXH_INIT_VX_INFO, h);
11371 +#define __vxh_set_vx_info(v, d, h) \
11372 +       __vxh_data(v, d, VXH_SET_VX_INFO, h);
11373 +#define __vxh_clr_vx_info(v, d, h) \
11374 +       __vxh_data(v, d, VXH_CLR_VX_INFO, h);
11375 +
11376 +#define __vxh_claim_vx_info(v, d, h) \
11377 +       __vxh_data(v, d, VXH_CLAIM_VX_INFO, h);
11378 +#define __vxh_release_vx_info(v, d, h) \
11379 +       __vxh_data(v, d, VXH_RELEASE_VX_INFO, h);
11380 +
11381 +#define vxh_alloc_vx_info(v) \
11382 +       __vxh_smpl(v, VXH_ALLOC_VX_INFO, __HERE__);
11383 +#define vxh_dealloc_vx_info(v) \
11384 +       __vxh_smpl(v, VXH_DEALLOC_VX_INFO, __HERE__);
11385 +
11386 +#define vxh_hash_vx_info(v) \
11387 +       __vxh_smpl(v, VXH_HASH_VX_INFO, __HERE__);
11388 +#define vxh_unhash_vx_info(v) \
11389 +       __vxh_smpl(v, VXH_UNHASH_VX_INFO, __HERE__);
11390 +
11391 +#define vxh_loc_vx_info(v, l) \
11392 +       __vxh_long(v, l, VXH_LOC_VX_INFO, __HERE__);
11393 +#define vxh_lookup_vx_info(v, l) \
11394 +       __vxh_long(v, l, VXH_LOOKUP_VX_INFO, __HERE__);
11395 +#define vxh_create_vx_info(v, l) \
11396 +       __vxh_long(v, l, VXH_CREATE_VX_INFO, __HERE__);
11397 +
11398 +extern void vxh_dump_history(void);
11399 +
11400 +
11401 +#else  /* CONFIG_VSERVER_HISTORY */
11402 +
11403 +#define        __HERE__        0
11404 +
11405 +#define vxh_throw_oops()               do { } while (0)
11406 +
11407 +#define __vxh_get_vx_info(v, h)                do { } while (0)
11408 +#define __vxh_put_vx_info(v, h)                do { } while (0)
11409 +
11410 +#define __vxh_init_vx_info(v, d, h)    do { } while (0)
11411 +#define __vxh_set_vx_info(v, d, h)     do { } while (0)
11412 +#define __vxh_clr_vx_info(v, d, h)     do { } while (0)
11413 +
11414 +#define __vxh_claim_vx_info(v, d, h)   do { } while (0)
11415 +#define __vxh_release_vx_info(v, d, h) do { } while (0)
11416 +
11417 +#define vxh_alloc_vx_info(v)           do { } while (0)
11418 +#define vxh_dealloc_vx_info(v)         do { } while (0)
11419 +
11420 +#define vxh_hash_vx_info(v)            do { } while (0)
11421 +#define vxh_unhash_vx_info(v)          do { } while (0)
11422 +
11423 +#define vxh_loc_vx_info(v, l)          do { } while (0)
11424 +#define vxh_lookup_vx_info(v, l)       do { } while (0)
11425 +#define vxh_create_vx_info(v, l)       do { } while (0)
11426 +
11427 +#define vxh_dump_history()             do { } while (0)
11428 +
11429 +
11430 +#endif /* CONFIG_VSERVER_HISTORY */
11431 +
11432 +#endif /* _VSERVER_HISTORY_H */
11433 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
11434 --- linux-3.9.4/include/linux/vserver/inode.h   1970-01-01 00:00:00.000000000 +0000
11435 +++ linux-3.9.4-vs2.3.6.2/include/linux/vserver/inode.h 2013-05-31 14:47:11.000000000 +0000
11436 @@ -0,0 +1,19 @@
11437 +#ifndef _VSERVER_INODE_H
11438 +#define _VSERVER_INODE_H
11439 +
11440 +#include <uapi/vserver/inode.h>
11441 +
11442 +
11443 +#ifdef CONFIG_VSERVER_PROC_SECURE
11444 +#define IATTR_PROC_DEFAULT     ( IATTR_ADMIN | IATTR_HIDE )
11445 +#define IATTR_PROC_SYMLINK     ( IATTR_ADMIN )
11446 +#else
11447 +#define IATTR_PROC_DEFAULT     ( IATTR_ADMIN )
11448 +#define IATTR_PROC_SYMLINK     ( IATTR_ADMIN )
11449 +#endif
11450 +
11451 +#define vx_hide_check(c, m)    (((m) & IATTR_HIDE) ? vx_check(c, m) : 1)
11452 +
11453 +#else  /* _VSERVER_INODE_H */
11454 +#warning duplicate inclusion
11455 +#endif /* _VSERVER_INODE_H */
11456 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
11457 --- linux-3.9.4/include/linux/vserver/inode_cmd.h       1970-01-01 00:00:00.000000000 +0000
11458 +++ linux-3.9.4-vs2.3.6.2/include/linux/vserver/inode_cmd.h     2013-05-31 14:47:11.000000000 +0000
11459 @@ -0,0 +1,36 @@
11460 +#ifndef _VSERVER_INODE_CMD_H
11461 +#define _VSERVER_INODE_CMD_H
11462 +
11463 +#include <uapi/vserver/inode_cmd.h>
11464 +
11465 +
11466 +
11467 +#ifdef CONFIG_COMPAT
11468 +
11469 +#include <asm/compat.h>
11470 +
11471 +struct vcmd_ctx_iattr_v1_x32 {
11472 +       compat_uptr_t name_ptr;
11473 +       uint32_t tag;
11474 +       uint32_t flags;
11475 +       uint32_t mask;
11476 +};
11477 +
11478 +#endif /* CONFIG_COMPAT */
11479 +
11480 +#include <linux/compiler.h>
11481 +
11482 +extern int vc_get_iattr(void __user *);
11483 +extern int vc_set_iattr(void __user *);
11484 +
11485 +extern int vc_fget_iattr(uint32_t, void __user *);
11486 +extern int vc_fset_iattr(uint32_t, void __user *);
11487 +
11488 +#ifdef CONFIG_COMPAT
11489 +
11490 +extern int vc_get_iattr_x32(void __user *);
11491 +extern int vc_set_iattr_x32(void __user *);
11492 +
11493 +#endif /* CONFIG_COMPAT */
11494 +
11495 +#endif /* _VSERVER_INODE_CMD_H */
11496 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
11497 --- linux-3.9.4/include/linux/vserver/limit.h   1970-01-01 00:00:00.000000000 +0000
11498 +++ linux-3.9.4-vs2.3.6.2/include/linux/vserver/limit.h 2013-05-31 14:47:11.000000000 +0000
11499 @@ -0,0 +1,61 @@
11500 +#ifndef _VSERVER_LIMIT_H
11501 +#define _VSERVER_LIMIT_H
11502 +
11503 +#include <uapi/vserver/limit.h>
11504 +
11505 +
11506 +#define        VLIM_NOCHECK    ((1L << VLIMIT_DENTRY) | (1L << RLIMIT_RSS))
11507 +
11508 +/*     keep in sync with CRLIM_INFINITY */
11509 +
11510 +#define        VLIM_INFINITY   (~0ULL)
11511 +
11512 +#include <asm/atomic.h>
11513 +#include <asm/resource.h>
11514 +
11515 +#ifndef RLIM_INFINITY
11516 +#warning RLIM_INFINITY is undefined
11517 +#endif
11518 +
11519 +#define __rlim_val(l, r, v)    ((l)->res[r].v)
11520 +
11521 +#define __rlim_soft(l, r)      __rlim_val(l, r, soft)
11522 +#define __rlim_hard(l, r)      __rlim_val(l, r, hard)
11523 +
11524 +#define __rlim_rcur(l, r)      __rlim_val(l, r, rcur)
11525 +#define __rlim_rmin(l, r)      __rlim_val(l, r, rmin)
11526 +#define __rlim_rmax(l, r)      __rlim_val(l, r, rmax)
11527 +
11528 +#define __rlim_lhit(l, r)      __rlim_val(l, r, lhit)
11529 +#define __rlim_hit(l, r)       atomic_inc(&__rlim_lhit(l, r))
11530 +
11531 +typedef atomic_long_t rlim_atomic_t;
11532 +typedef unsigned long rlim_t;
11533 +
11534 +#define __rlim_get(l, r)       atomic_long_read(&__rlim_rcur(l, r))
11535 +#define __rlim_set(l, r, v)    atomic_long_set(&__rlim_rcur(l, r), v)
11536 +#define __rlim_inc(l, r)       atomic_long_inc(&__rlim_rcur(l, r))
11537 +#define __rlim_dec(l, r)       atomic_long_dec(&__rlim_rcur(l, r))
11538 +#define __rlim_add(l, r, v)    atomic_long_add(v, &__rlim_rcur(l, r))
11539 +#define __rlim_sub(l, r, v)    atomic_long_sub(v, &__rlim_rcur(l, r))
11540 +
11541 +
11542 +#if    (RLIM_INFINITY == VLIM_INFINITY)
11543 +#define        VX_VLIM(r) ((long long)(long)(r))
11544 +#define        VX_RLIM(v) ((rlim_t)(v))
11545 +#else
11546 +#define        VX_VLIM(r) (((r) == RLIM_INFINITY) \
11547 +               ? VLIM_INFINITY : (long long)(r))
11548 +#define        VX_RLIM(v) (((v) == VLIM_INFINITY) \
11549 +               ? RLIM_INFINITY : (rlim_t)(v))
11550 +#endif
11551 +
11552 +struct sysinfo;
11553 +
11554 +void vx_vsi_meminfo(struct sysinfo *);
11555 +void vx_vsi_swapinfo(struct sysinfo *);
11556 +long vx_vsi_cached(struct sysinfo *);
11557 +
11558 +#define NUM_LIMITS     24
11559 +
11560 +#endif /* _VSERVER_LIMIT_H */
11561 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
11562 --- linux-3.9.4/include/linux/vserver/limit_cmd.h       1970-01-01 00:00:00.000000000 +0000
11563 +++ linux-3.9.4-vs2.3.6.2/include/linux/vserver/limit_cmd.h     2013-05-31 14:47:11.000000000 +0000
11564 @@ -0,0 +1,35 @@
11565 +#ifndef _VSERVER_LIMIT_CMD_H
11566 +#define _VSERVER_LIMIT_CMD_H
11567 +
11568 +#include <uapi/vserver/limit_cmd.h>
11569 +
11570 +
11571 +#ifdef CONFIG_IA32_EMULATION
11572 +
11573 +struct vcmd_ctx_rlimit_v0_x32 {
11574 +       uint32_t id;
11575 +       uint64_t minimum;
11576 +       uint64_t softlimit;
11577 +       uint64_t maximum;
11578 +} __attribute__ ((packed));
11579 +
11580 +#endif /* CONFIG_IA32_EMULATION */
11581 +
11582 +#include <linux/compiler.h>
11583 +
11584 +extern int vc_get_rlimit_mask(uint32_t, void __user *);
11585 +extern int vc_get_rlimit(struct vx_info *, void __user *);
11586 +extern int vc_set_rlimit(struct vx_info *, void __user *);
11587 +extern int vc_reset_hits(struct vx_info *, void __user *);
11588 +extern int vc_reset_minmax(struct vx_info *, void __user *);
11589 +
11590 +extern int vc_rlimit_stat(struct vx_info *, void __user *);
11591 +
11592 +#ifdef CONFIG_IA32_EMULATION
11593 +
11594 +extern int vc_get_rlimit_x32(struct vx_info *, void __user *);
11595 +extern int vc_set_rlimit_x32(struct vx_info *, void __user *);
11596 +
11597 +#endif /* CONFIG_IA32_EMULATION */
11598 +
11599 +#endif /* _VSERVER_LIMIT_CMD_H */
11600 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
11601 --- linux-3.9.4/include/linux/vserver/limit_def.h       1970-01-01 00:00:00.000000000 +0000
11602 +++ linux-3.9.4-vs2.3.6.2/include/linux/vserver/limit_def.h     2013-05-31 14:47:11.000000000 +0000
11603 @@ -0,0 +1,47 @@
11604 +#ifndef _VSERVER_LIMIT_DEF_H
11605 +#define _VSERVER_LIMIT_DEF_H
11606 +
11607 +#include <asm/atomic.h>
11608 +#include <asm/resource.h>
11609 +
11610 +#include "limit.h"
11611 +
11612 +
11613 +struct _vx_res_limit {
11614 +       rlim_t soft;            /* Context soft limit */
11615 +       rlim_t hard;            /* Context hard limit */
11616 +
11617 +       rlim_atomic_t rcur;     /* Current value */
11618 +       rlim_t rmin;            /* Context minimum */
11619 +       rlim_t rmax;            /* Context maximum */
11620 +
11621 +       atomic_t lhit;          /* Limit hits */
11622 +};
11623 +
11624 +/* context sub struct */
11625 +
11626 +struct _vx_limit {
11627 +       struct _vx_res_limit res[NUM_LIMITS];
11628 +};
11629 +
11630 +#ifdef CONFIG_VSERVER_DEBUG
11631 +
11632 +static inline void __dump_vx_limit(struct _vx_limit *limit)
11633 +{
11634 +       int i;
11635 +
11636 +       printk("\t_vx_limit:");
11637 +       for (i = 0; i < NUM_LIMITS; i++) {
11638 +               printk("\t [%2d] = %8lu %8lu/%8lu, %8ld/%8ld, %8d\n",
11639 +                       i, (unsigned long)__rlim_get(limit, i),
11640 +                       (unsigned long)__rlim_rmin(limit, i),
11641 +                       (unsigned long)__rlim_rmax(limit, i),
11642 +                       (long)__rlim_soft(limit, i),
11643 +                       (long)__rlim_hard(limit, i),
11644 +                       atomic_read(&__rlim_lhit(limit, i)));
11645 +       }
11646 +}
11647 +
11648 +#endif
11649 +
11650 +#endif /* _VSERVER_LIMIT_DEF_H */
11651 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
11652 --- linux-3.9.4/include/linux/vserver/limit_int.h       1970-01-01 00:00:00.000000000 +0000
11653 +++ linux-3.9.4-vs2.3.6.2/include/linux/vserver/limit_int.h     2013-05-31 14:47:11.000000000 +0000
11654 @@ -0,0 +1,193 @@
11655 +#ifndef _VSERVER_LIMIT_INT_H
11656 +#define _VSERVER_LIMIT_INT_H
11657 +
11658 +#define VXD_RCRES_COND(r)      VXD_CBIT(cres, r)
11659 +#define VXD_RLIMIT_COND(r)     VXD_CBIT(limit, r)
11660 +
11661 +extern const char *vlimit_name[NUM_LIMITS];
11662 +
11663 +static inline void __vx_acc_cres(struct vx_info *vxi,
11664 +       int res, int dir, void *_data, char *_file, int _line)
11665 +{
11666 +       if (VXD_RCRES_COND(res))
11667 +               vxlprintk(1, "vx_acc_cres[%5d,%s,%2d]: %5ld%s (%p)",
11668 +                       (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
11669 +                       (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
11670 +                       (dir > 0) ? "++" : "--", _data, _file, _line);
11671 +       if (!vxi)
11672 +               return;
11673 +
11674 +       if (dir > 0)
11675 +               __rlim_inc(&vxi->limit, res);
11676 +       else
11677 +               __rlim_dec(&vxi->limit, res);
11678 +}
11679 +
11680 +static inline void __vx_add_cres(struct vx_info *vxi,
11681 +       int res, int amount, void *_data, char *_file, int _line)
11682 +{
11683 +       if (VXD_RCRES_COND(res))
11684 +               vxlprintk(1, "vx_add_cres[%5d,%s,%2d]: %5ld += %5d (%p)",
11685 +                       (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
11686 +                       (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
11687 +                       amount, _data, _file, _line);
11688 +       if (amount == 0)
11689 +               return;
11690 +       if (!vxi)
11691 +               return;
11692 +       __rlim_add(&vxi->limit, res, amount);
11693 +}
11694 +
11695 +static inline
11696 +int __vx_cres_adjust_max(struct _vx_limit *limit, int res, rlim_t value)
11697 +{
11698 +       int cond = (value > __rlim_rmax(limit, res));
11699 +
11700 +       if (cond)
11701 +               __rlim_rmax(limit, res) = value;
11702 +       return cond;
11703 +}
11704 +
11705 +static inline
11706 +int __vx_cres_adjust_min(struct _vx_limit *limit, int res, rlim_t value)
11707 +{
11708 +       int cond = (value < __rlim_rmin(limit, res));
11709 +
11710 +       if (cond)
11711 +               __rlim_rmin(limit, res) = value;
11712 +       return cond;
11713 +}
11714 +
11715 +static inline
11716 +void __vx_cres_fixup(struct _vx_limit *limit, int res, rlim_t value)
11717 +{
11718 +       if (!__vx_cres_adjust_max(limit, res, value))
11719 +               __vx_cres_adjust_min(limit, res, value);
11720 +}
11721 +
11722 +
11723 +/*     return values:
11724 +        +1 ... no limit hit
11725 +        -1 ... over soft limit
11726 +         0 ... over hard limit         */
11727 +
11728 +static inline int __vx_cres_avail(struct vx_info *vxi,
11729 +       int res, int num, char *_file, int _line)
11730 +{
11731 +       struct _vx_limit *limit;
11732 +       rlim_t value;
11733 +
11734 +       if (VXD_RLIMIT_COND(res))
11735 +               vxlprintk(1, "vx_cres_avail[%5d,%s,%2d]: %5ld/%5ld > %5ld + %5d",
11736 +                       (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
11737 +                       (vxi ? (long)__rlim_soft(&vxi->limit, res) : -1),
11738 +                       (vxi ? (long)__rlim_hard(&vxi->limit, res) : -1),
11739 +                       (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
11740 +                       num, _file, _line);
11741 +       if (!vxi)
11742 +               return 1;
11743 +
11744 +       limit = &vxi->limit;
11745 +       value = __rlim_get(limit, res);
11746 +
11747 +       if (!__vx_cres_adjust_max(limit, res, value))
11748 +               __vx_cres_adjust_min(limit, res, value);
11749 +
11750 +       if (num == 0)
11751 +               return 1;
11752 +
11753 +       if (__rlim_soft(limit, res) == RLIM_INFINITY)
11754 +               return -1;
11755 +       if (value + num <= __rlim_soft(limit, res))
11756 +               return -1;
11757 +
11758 +       if (__rlim_hard(limit, res) == RLIM_INFINITY)
11759 +               return 1;
11760 +       if (value + num <= __rlim_hard(limit, res))
11761 +               return 1;
11762 +
11763 +       __rlim_hit(limit, res);
11764 +       return 0;
11765 +}
11766 +
11767 +
11768 +static const int VLA_RSS[] = { RLIMIT_RSS, VLIMIT_ANON, VLIMIT_MAPPED, 0 };
11769 +
11770 +static inline
11771 +rlim_t __vx_cres_array_sum(struct _vx_limit *limit, const int *array)
11772 +{
11773 +       rlim_t value, sum = 0;
11774 +       int res;
11775 +
11776 +       while ((res = *array++)) {
11777 +               value = __rlim_get(limit, res);
11778 +               __vx_cres_fixup(limit, res, value);
11779 +               sum += value;
11780 +       }
11781 +       return sum;
11782 +}
11783 +
11784 +static inline
11785 +rlim_t __vx_cres_array_fixup(struct _vx_limit *limit, const int *array)
11786 +{
11787 +       rlim_t value = __vx_cres_array_sum(limit, array + 1);
11788 +       int res = *array;
11789 +
11790 +       if (value == __rlim_get(limit, res))
11791 +               return value;
11792 +
11793 +       __rlim_set(limit, res, value);
11794 +       /* now adjust min/max */
11795 +       if (!__vx_cres_adjust_max(limit, res, value))
11796 +               __vx_cres_adjust_min(limit, res, value);
11797 +
11798 +       return value;
11799 +}
11800 +
11801 +static inline int __vx_cres_array_avail(struct vx_info *vxi,
11802 +       const int *array, int num, char *_file, int _line)
11803 +{
11804 +       struct _vx_limit *limit;
11805 +       rlim_t value = 0;
11806 +       int res;
11807 +
11808 +       if (num == 0)
11809 +               return 1;
11810 +       if (!vxi)
11811 +               return 1;
11812 +
11813 +       limit = &vxi->limit;
11814 +       res = *array;
11815 +       value = __vx_cres_array_sum(limit, array + 1);
11816 +
11817 +       __rlim_set(limit, res, value);
11818 +       __vx_cres_fixup(limit, res, value);
11819 +
11820 +       return __vx_cres_avail(vxi, res, num, _file, _line);
11821 +}
11822 +
11823 +
11824 +static inline void vx_limit_fixup(struct _vx_limit *limit, int id)
11825 +{
11826 +       rlim_t value;
11827 +       int res;
11828 +
11829 +       /* complex resources first */
11830 +       if ((id < 0) || (id == RLIMIT_RSS))
11831 +               __vx_cres_array_fixup(limit, VLA_RSS);
11832 +
11833 +       for (res = 0; res < NUM_LIMITS; res++) {
11834 +               if ((id > 0) && (res != id))
11835 +                       continue;
11836 +
11837 +               value = __rlim_get(limit, res);
11838 +               __vx_cres_fixup(limit, res, value);
11839 +
11840 +               /* not supposed to happen, maybe warn? */
11841 +               if (__rlim_rmax(limit, res) > __rlim_hard(limit, res))
11842 +                       __rlim_rmax(limit, res) = __rlim_hard(limit, res);
11843 +       }
11844 +}
11845 +
11846 +
11847 +#endif /* _VSERVER_LIMIT_INT_H */
11848 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
11849 --- linux-3.9.4/include/linux/vserver/monitor.h 1970-01-01 00:00:00.000000000 +0000
11850 +++ linux-3.9.4-vs2.3.6.2/include/linux/vserver/monitor.h       2013-05-31 14:47:11.000000000 +0000
11851 @@ -0,0 +1,6 @@
11852 +#ifndef _VSERVER_MONITOR_H
11853 +#define _VSERVER_MONITOR_H
11854 +
11855 +#include <uapi/vserver/monitor.h>
11856 +
11857 +#endif /* _VSERVER_MONITOR_H */
11858 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
11859 --- linux-3.9.4/include/linux/vserver/network.h 1970-01-01 00:00:00.000000000 +0000
11860 +++ linux-3.9.4-vs2.3.6.2/include/linux/vserver/network.h       2013-05-31 14:47:11.000000000 +0000
11861 @@ -0,0 +1,76 @@
11862 +#ifndef _VSERVER_NETWORK_H
11863 +#define _VSERVER_NETWORK_H
11864 +
11865 +
11866 +#include <linux/list.h>
11867 +#include <linux/spinlock.h>
11868 +#include <linux/rcupdate.h>
11869 +#include <linux/in.h>
11870 +#include <linux/in6.h>
11871 +#include <asm/atomic.h>
11872 +#include <uapi/vserver/network.h>
11873 +
11874 +struct nx_addr_v4 {
11875 +       struct nx_addr_v4 *next;
11876 +       struct in_addr ip[2];
11877 +       struct in_addr mask;
11878 +       uint16_t type;
11879 +       uint16_t flags;
11880 +};
11881 +
11882 +struct nx_addr_v6 {
11883 +       struct nx_addr_v6 *next;
11884 +       struct in6_addr ip;
11885 +       struct in6_addr mask;
11886 +       uint32_t prefix;
11887 +       uint16_t type;
11888 +       uint16_t flags;
11889 +};
11890 +
11891 +struct nx_info {
11892 +       struct hlist_node nx_hlist;     /* linked list of nxinfos */
11893 +       nid_t nx_id;                    /* vnet id */
11894 +       atomic_t nx_usecnt;             /* usage count */
11895 +       atomic_t nx_tasks;              /* tasks count */
11896 +       int nx_state;                   /* context state */
11897 +
11898 +       uint64_t nx_flags;              /* network flag word */
11899 +       uint64_t nx_ncaps;              /* network capabilities */
11900 +
11901 +       spinlock_t addr_lock;           /* protect address changes */
11902 +       struct in_addr v4_lback;        /* Loopback address */
11903 +       struct in_addr v4_bcast;        /* Broadcast address */
11904 +       struct nx_addr_v4 v4;           /* First/Single ipv4 address */
11905 +#ifdef CONFIG_IPV6
11906 +       struct nx_addr_v6 v6;           /* First/Single ipv6 address */
11907 +#endif
11908 +       char nx_name[65];               /* network context name */
11909 +};
11910 +
11911 +
11912 +/* status flags */
11913 +
11914 +#define NXS_HASHED      0x0001
11915 +#define NXS_SHUTDOWN    0x0100
11916 +#define NXS_RELEASED    0x8000
11917 +
11918 +extern struct nx_info *lookup_nx_info(int);
11919 +
11920 +extern int get_nid_list(int, unsigned int *, int);
11921 +extern int nid_is_hashed(nid_t);
11922 +
11923 +extern int nx_migrate_task(struct task_struct *, struct nx_info *);
11924 +
11925 +extern long vs_net_change(struct nx_info *, unsigned int);
11926 +
11927 +struct sock;
11928 +
11929 +
11930 +#define NX_IPV4(n)     ((n)->v4.type != NXA_TYPE_NONE)
11931 +#ifdef  CONFIG_IPV6
11932 +#define NX_IPV6(n)     ((n)->v6.type != NXA_TYPE_NONE)
11933 +#else
11934 +#define NX_IPV6(n)     (0)
11935 +#endif
11936 +
11937 +#endif /* _VSERVER_NETWORK_H */
11938 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
11939 --- linux-3.9.4/include/linux/vserver/network_cmd.h     1970-01-01 00:00:00.000000000 +0000
11940 +++ linux-3.9.4-vs2.3.6.2/include/linux/vserver/network_cmd.h   2013-05-31 14:47:11.000000000 +0000
11941 @@ -0,0 +1,37 @@
11942 +#ifndef _VSERVER_NETWORK_CMD_H
11943 +#define _VSERVER_NETWORK_CMD_H
11944 +
11945 +#include <uapi/vserver/network_cmd.h>
11946 +
11947 +extern int vc_task_nid(uint32_t);
11948 +
11949 +extern int vc_nx_info(struct nx_info *, void __user *);
11950 +
11951 +extern int vc_net_create(uint32_t, void __user *);
11952 +extern int vc_net_migrate(struct nx_info *, void __user *);
11953 +
11954 +extern int vc_net_add(struct nx_info *, void __user *);
11955 +extern int vc_net_remove(struct nx_info *, void __user *);
11956 +
11957 +extern int vc_net_add_ipv4_v1(struct nx_info *, void __user *);
11958 +extern int vc_net_add_ipv4(struct nx_info *, void __user *);
11959 +
11960 +extern int vc_net_rem_ipv4_v1(struct nx_info *, void __user *);
11961 +extern int vc_net_rem_ipv4(struct nx_info *, void __user *);
11962 +
11963 +extern int vc_net_add_ipv6(struct nx_info *, void __user *);
11964 +extern int vc_net_remove_ipv6(struct nx_info *, void __user *);
11965 +
11966 +extern int vc_add_match_ipv4(struct nx_info *, void __user *);
11967 +extern int vc_get_match_ipv4(struct nx_info *, void __user *);
11968 +
11969 +extern int vc_add_match_ipv6(struct nx_info *, void __user *);
11970 +extern int vc_get_match_ipv6(struct nx_info *, void __user *);
11971 +
11972 +extern int vc_get_nflags(struct nx_info *, void __user *);
11973 +extern int vc_set_nflags(struct nx_info *, void __user *);
11974 +
11975 +extern int vc_get_ncaps(struct nx_info *, void __user *);
11976 +extern int vc_set_ncaps(struct nx_info *, void __user *);
11977 +
11978 +#endif /* _VSERVER_CONTEXT_CMD_H */
11979 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
11980 --- linux-3.9.4/include/linux/vserver/percpu.h  1970-01-01 00:00:00.000000000 +0000
11981 +++ linux-3.9.4-vs2.3.6.2/include/linux/vserver/percpu.h        2013-05-31 14:47:11.000000000 +0000
11982 @@ -0,0 +1,14 @@
11983 +#ifndef _VSERVER_PERCPU_H
11984 +#define _VSERVER_PERCPU_H
11985 +
11986 +#include "cvirt_def.h"
11987 +#include "sched_def.h"
11988 +
11989 +struct _vx_percpu {
11990 +       struct _vx_cvirt_pc cvirt;
11991 +       struct _vx_sched_pc sched;
11992 +};
11993 +
11994 +#define        PERCPU_PERCTX   (sizeof(struct _vx_percpu))
11995 +
11996 +#endif /* _VSERVER_PERCPU_H */
11997 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
11998 --- linux-3.9.4/include/linux/vserver/pid.h     1970-01-01 00:00:00.000000000 +0000
11999 +++ linux-3.9.4-vs2.3.6.2/include/linux/vserver/pid.h   2013-05-31 14:47:11.000000000 +0000
12000 @@ -0,0 +1,51 @@
12001 +#ifndef _VSERVER_PID_H
12002 +#define _VSERVER_PID_H
12003 +
12004 +/* pid faking stuff */
12005 +
12006 +#define vx_info_map_pid(v, p) \
12007 +       __vx_info_map_pid((v), (p), __func__, __FILE__, __LINE__)
12008 +#define vx_info_map_tgid(v,p)  vx_info_map_pid(v,p)
12009 +#define vx_map_pid(p) vx_info_map_pid(current_vx_info(), p)
12010 +#define vx_map_tgid(p) vx_map_pid(p)
12011 +
12012 +static inline int __vx_info_map_pid(struct vx_info *vxi, int pid,
12013 +       const char *func, const char *file, int line)
12014 +{
12015 +       if (vx_info_flags(vxi, VXF_INFO_INIT, 0)) {
12016 +               vxfprintk(VXD_CBIT(cvirt, 2),
12017 +                       "vx_map_tgid: %p/%llx: %d -> %d",
12018 +                       vxi, (long long)vxi->vx_flags, pid,
12019 +                       (pid && pid == vxi->vx_initpid) ? 1 : pid,
12020 +                       func, file, line);
12021 +               if (pid == 0)
12022 +                       return 0;
12023 +               if (pid == vxi->vx_initpid)
12024 +                       return 1;
12025 +       }
12026 +       return pid;
12027 +}
12028 +
12029 +#define vx_info_rmap_pid(v, p) \
12030 +       __vx_info_rmap_pid((v), (p), __func__, __FILE__, __LINE__)
12031 +#define vx_rmap_pid(p) vx_info_rmap_pid(current_vx_info(), p)
12032 +#define vx_rmap_tgid(p) vx_rmap_pid(p)
12033 +
12034 +static inline int __vx_info_rmap_pid(struct vx_info *vxi, int pid,
12035 +       const char *func, const char *file, int line)
12036 +{
12037 +       if (vx_info_flags(vxi, VXF_INFO_INIT, 0)) {
12038 +               vxfprintk(VXD_CBIT(cvirt, 2),
12039 +                       "vx_rmap_tgid: %p/%llx: %d -> %d",
12040 +                       vxi, (long long)vxi->vx_flags, pid,
12041 +                       (pid == 1) ? vxi->vx_initpid : pid,
12042 +                       func, file, line);
12043 +               if ((pid == 1) && vxi->vx_initpid)
12044 +                       return vxi->vx_initpid;
12045 +               if (pid == vxi->vx_initpid)
12046 +                       return ~0U;
12047 +       }
12048 +       return pid;
12049 +}
12050 +
12051 +#endif
12052 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
12053 --- linux-3.9.4/include/linux/vserver/sched.h   1970-01-01 00:00:00.000000000 +0000
12054 +++ linux-3.9.4-vs2.3.6.2/include/linux/vserver/sched.h 2013-05-31 14:47:11.000000000 +0000
12055 @@ -0,0 +1,23 @@
12056 +#ifndef _VSERVER_SCHED_H
12057 +#define _VSERVER_SCHED_H
12058 +
12059 +
12060 +#ifdef __KERNEL__
12061 +
12062 +struct timespec;
12063 +
12064 +void vx_vsi_uptime(struct timespec *, struct timespec *);
12065 +
12066 +
12067 +struct vx_info;
12068 +
12069 +void vx_update_load(struct vx_info *);
12070 +
12071 +
12072 +void vx_update_sched_param(struct _vx_sched *sched,
12073 +       struct _vx_sched_pc *sched_pc);
12074 +
12075 +#endif /* __KERNEL__ */
12076 +#else  /* _VSERVER_SCHED_H */
12077 +#warning duplicate inclusion
12078 +#endif /* _VSERVER_SCHED_H */
12079 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
12080 --- linux-3.9.4/include/linux/vserver/sched_cmd.h       1970-01-01 00:00:00.000000000 +0000
12081 +++ linux-3.9.4-vs2.3.6.2/include/linux/vserver/sched_cmd.h     2013-05-31 14:47:11.000000000 +0000
12082 @@ -0,0 +1,11 @@
12083 +#ifndef _VSERVER_SCHED_CMD_H
12084 +#define _VSERVER_SCHED_CMD_H
12085 +
12086 +
12087 +#include <linux/compiler.h>
12088 +#include <uapi/vserver/sched_cmd.h>
12089 +
12090 +extern int vc_set_prio_bias(struct vx_info *, void __user *);
12091 +extern int vc_get_prio_bias(struct vx_info *, void __user *);
12092 +
12093 +#endif /* _VSERVER_SCHED_CMD_H */
12094 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
12095 --- linux-3.9.4/include/linux/vserver/sched_def.h       1970-01-01 00:00:00.000000000 +0000
12096 +++ linux-3.9.4-vs2.3.6.2/include/linux/vserver/sched_def.h     2013-05-31 14:47:11.000000000 +0000
12097 @@ -0,0 +1,38 @@
12098 +#ifndef _VSERVER_SCHED_DEF_H
12099 +#define _VSERVER_SCHED_DEF_H
12100 +
12101 +#include <linux/spinlock.h>
12102 +#include <linux/jiffies.h>
12103 +#include <linux/cpumask.h>
12104 +#include <asm/atomic.h>
12105 +#include <asm/param.h>
12106 +
12107 +
12108 +/* context sub struct */
12109 +
12110 +struct _vx_sched {
12111 +       int prio_bias;                  /* bias offset for priority */
12112 +
12113 +       cpumask_t update;               /* CPUs which should update */
12114 +};
12115 +
12116 +struct _vx_sched_pc {
12117 +       int prio_bias;                  /* bias offset for priority */
12118 +
12119 +       uint64_t user_ticks;            /* token tick events */
12120 +       uint64_t sys_ticks;             /* token tick events */
12121 +       uint64_t hold_ticks;            /* token ticks paused */
12122 +};
12123 +
12124 +
12125 +#ifdef CONFIG_VSERVER_DEBUG
12126 +
12127 +static inline void __dump_vx_sched(struct _vx_sched *sched)
12128 +{
12129 +       printk("\t_vx_sched:\n");
12130 +       printk("\t priority = %4d\n", sched->prio_bias);
12131 +}
12132 +
12133 +#endif
12134 +
12135 +#endif /* _VSERVER_SCHED_DEF_H */
12136 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
12137 --- linux-3.9.4/include/linux/vserver/signal.h  1970-01-01 00:00:00.000000000 +0000
12138 +++ linux-3.9.4-vs2.3.6.2/include/linux/vserver/signal.h        2013-05-31 14:47:11.000000000 +0000
12139 @@ -0,0 +1,14 @@
12140 +#ifndef _VSERVER_SIGNAL_H
12141 +#define _VSERVER_SIGNAL_H
12142 +
12143 +
12144 +#ifdef __KERNEL__
12145 +
12146 +struct vx_info;
12147 +
12148 +int vx_info_kill(struct vx_info *, int, int);
12149 +
12150 +#endif /* __KERNEL__ */
12151 +#else  /* _VSERVER_SIGNAL_H */
12152 +#warning duplicate inclusion
12153 +#endif /* _VSERVER_SIGNAL_H */
12154 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
12155 --- linux-3.9.4/include/linux/vserver/signal_cmd.h      1970-01-01 00:00:00.000000000 +0000
12156 +++ linux-3.9.4-vs2.3.6.2/include/linux/vserver/signal_cmd.h    2013-05-31 14:47:11.000000000 +0000
12157 @@ -0,0 +1,14 @@
12158 +#ifndef _VSERVER_SIGNAL_CMD_H
12159 +#define _VSERVER_SIGNAL_CMD_H
12160 +
12161 +#include <uapi/vserver/signal_cmd.h>
12162 +
12163 +
12164 +extern int vc_ctx_kill(struct vx_info *, void __user *);
12165 +extern int vc_wait_exit(struct vx_info *, void __user *);
12166 +
12167 +
12168 +extern int vc_get_pflags(uint32_t pid, void __user *);
12169 +extern int vc_set_pflags(uint32_t pid, void __user *);
12170 +
12171 +#endif /* _VSERVER_SIGNAL_CMD_H */
12172 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
12173 --- linux-3.9.4/include/linux/vserver/space.h   1970-01-01 00:00:00.000000000 +0000
12174 +++ linux-3.9.4-vs2.3.6.2/include/linux/vserver/space.h 2013-05-31 14:47:11.000000000 +0000
12175 @@ -0,0 +1,12 @@
12176 +#ifndef _VSERVER_SPACE_H
12177 +#define _VSERVER_SPACE_H
12178 +
12179 +#include <linux/types.h>
12180 +
12181 +struct vx_info;
12182 +
12183 +int vx_set_space(struct vx_info *vxi, unsigned long mask, unsigned index);
12184 +
12185 +#else  /* _VSERVER_SPACE_H */
12186 +#warning duplicate inclusion
12187 +#endif /* _VSERVER_SPACE_H */
12188 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
12189 --- linux-3.9.4/include/linux/vserver/space_cmd.h       1970-01-01 00:00:00.000000000 +0000
12190 +++ linux-3.9.4-vs2.3.6.2/include/linux/vserver/space_cmd.h     2013-05-31 14:47:11.000000000 +0000
12191 @@ -0,0 +1,13 @@
12192 +#ifndef _VSERVER_SPACE_CMD_H
12193 +#define _VSERVER_SPACE_CMD_H
12194 +
12195 +#include <uapi/vserver/space_cmd.h>
12196 +
12197 +
12198 +extern int vc_enter_space_v1(struct vx_info *, void __user *);
12199 +extern int vc_set_space_v1(struct vx_info *, void __user *);
12200 +extern int vc_enter_space(struct vx_info *, void __user *);
12201 +extern int vc_set_space(struct vx_info *, void __user *);
12202 +extern int vc_get_space_mask(void __user *, int);
12203 +
12204 +#endif /* _VSERVER_SPACE_CMD_H */
12205 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
12206 --- linux-3.9.4/include/linux/vserver/switch.h  1970-01-01 00:00:00.000000000 +0000
12207 +++ linux-3.9.4-vs2.3.6.2/include/linux/vserver/switch.h        2013-05-31 14:47:11.000000000 +0000
12208 @@ -0,0 +1,8 @@
12209 +#ifndef _VSERVER_SWITCH_H
12210 +#define _VSERVER_SWITCH_H
12211 +
12212 +
12213 +#include <linux/errno.h>
12214 +#include <uapi/vserver/switch.h>
12215 +
12216 +#endif /* _VSERVER_SWITCH_H */
12217 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
12218 --- linux-3.9.4/include/linux/vserver/tag.h     1970-01-01 00:00:00.000000000 +0000
12219 +++ linux-3.9.4-vs2.3.6.2/include/linux/vserver/tag.h   2013-06-01 08:36:17.000000000 +0000
12220 @@ -0,0 +1,149 @@
12221 +#ifndef _DX_TAG_H
12222 +#define _DX_TAG_H
12223 +
12224 +#include <linux/types.h>
12225 +
12226 +
12227 +#define DX_TAG(in)     (IS_TAGGED(in))
12228 +
12229 +
12230 +#ifdef CONFIG_TAG_NFSD
12231 +#define DX_TAG_NFSD    1
12232 +#else
12233 +#define DX_TAG_NFSD    0
12234 +#endif
12235 +
12236 +
12237 +#ifdef CONFIG_TAGGING_NONE
12238 +
12239 +#define MAX_UID                0xFFFFFFFF
12240 +#define MAX_GID                0xFFFFFFFF
12241 +
12242 +#define INOTAG_TAG(cond, uid, gid, tag)        (0)
12243 +
12244 +#define TAGINO_UID(cond, uid, tag)     (uid)
12245 +#define TAGINO_GID(cond, gid, tag)     (gid)
12246 +
12247 +#endif
12248 +
12249 +
12250 +#ifdef CONFIG_TAGGING_GID16
12251 +
12252 +#define MAX_UID                0xFFFFFFFF
12253 +#define MAX_GID                0x0000FFFF
12254 +
12255 +#define INOTAG_TAG(cond, uid, gid, tag)        \
12256 +       ((cond) ? (((gid) >> 16) & 0xFFFF) : 0)
12257 +
12258 +#define TAGINO_UID(cond, uid, tag)     (uid)
12259 +#define TAGINO_GID(cond, gid, tag)     \
12260 +       ((cond) ? (((gid) & 0xFFFF) | ((tag) << 16)) : (gid))
12261 +
12262 +#endif
12263 +
12264 +
12265 +#ifdef CONFIG_TAGGING_ID24
12266 +
12267 +#define MAX_UID                0x00FFFFFF
12268 +#define MAX_GID                0x00FFFFFF
12269 +
12270 +#define INOTAG_TAG(cond, uid, gid, tag)        \
12271 +       ((cond) ? ((((uid) >> 16) & 0xFF00) | (((gid) >> 24) & 0xFF)) : 0)
12272 +
12273 +#define TAGINO_UID(cond, uid, tag)     \
12274 +       ((cond) ? (((uid) & 0xFFFFFF) | (((tag) & 0xFF00) << 16)) : (uid))
12275 +#define TAGINO_GID(cond, gid, tag)     \
12276 +       ((cond) ? (((gid) & 0xFFFFFF) | (((tag) & 0x00FF) << 24)) : (gid))
12277 +
12278 +#endif
12279 +
12280 +
12281 +#ifdef CONFIG_TAGGING_UID16
12282 +
12283 +#define MAX_UID                0x0000FFFF
12284 +#define MAX_GID                0xFFFFFFFF
12285 +
12286 +#define INOTAG_TAG(cond, uid, gid, tag)        \
12287 +       ((cond) ? (((uid) >> 16) & 0xFFFF) : 0)
12288 +
12289 +#define TAGINO_UID(cond, uid, tag)     \
12290 +       ((cond) ? (((uid) & 0xFFFF) | ((tag) << 16)) : (uid))
12291 +#define TAGINO_GID(cond, gid, tag)     (gid)
12292 +
12293 +#endif
12294 +
12295 +
12296 +#ifdef CONFIG_TAGGING_INTERN
12297 +
12298 +#define MAX_UID                0xFFFFFFFF
12299 +#define MAX_GID                0xFFFFFFFF
12300 +
12301 +#define INOTAG_TAG(cond, uid, gid, tag)        \
12302 +       ((cond) ? (tag) : 0)
12303 +
12304 +#define TAGINO_UID(cond, uid, tag)     (uid)
12305 +#define TAGINO_GID(cond, gid, tag)     (gid)
12306 +
12307 +#endif
12308 +
12309 +
12310 +#ifndef CONFIG_TAGGING_NONE
12311 +#define dx_current_fstag(sb)   \
12312 +       ((sb)->s_flags & MS_TAGGED ? dx_current_tag() : 0)
12313 +#else
12314 +#define dx_current_fstag(sb)   (0)
12315 +#endif
12316 +
12317 +#ifndef CONFIG_TAGGING_INTERN
12318 +#define TAGINO_TAG(cond, tag)  (0)
12319 +#else
12320 +#define TAGINO_TAG(cond, tag)  ((cond) ? (tag) : 0)
12321 +#endif
12322 +
12323 +#define INOTAG_UID(cond, uid, gid)     \
12324 +       ((cond) ? ((uid) & MAX_UID) : (uid))
12325 +#define INOTAG_GID(cond, uid, gid)     \
12326 +       ((cond) ? ((gid) & MAX_GID) : (gid))
12327 +
12328 +
12329 +static inline uid_t dx_map_uid(uid_t uid)
12330 +{
12331 +       if ((uid > MAX_UID) && (uid != -1))
12332 +               uid = -2;
12333 +       return (uid & MAX_UID);
12334 +}
12335 +
12336 +#define        dx_map_kuid(n, u) \
12337 +       make_kuid(n, dx_map_uid(from_kuid(n, u)))
12338 +
12339 +static inline gid_t dx_map_gid(gid_t gid)
12340 +{
12341 +       if ((gid > MAX_GID) && (gid != -1))
12342 +               gid = -2;
12343 +       return (gid & MAX_GID);
12344 +}
12345 +
12346 +#define        dx_map_kgid(n, u) \
12347 +       make_kgid(n, dx_map_gid(from_kgid(n, u)))
12348 +
12349 +struct peer_tag {
12350 +       int32_t xid;
12351 +       int32_t nid;
12352 +};
12353 +
12354 +#define dx_notagcheck(sb) ((sb) && ((sb)->s_flags & MS_NOTAGCHECK))
12355 +
12356 +int dx_parse_tag(char *string, tag_t *tag, int remove, int *mnt_flags,
12357 +                unsigned long *flags);
12358 +
12359 +#ifdef CONFIG_PROPAGATE
12360 +
12361 +void __dx_propagate_tag(struct nameidata *nd, struct inode *inode);
12362 +
12363 +#define dx_propagate_tag(n, i) __dx_propagate_tag(n, i)
12364 +
12365 +#else
12366 +#define dx_propagate_tag(n, i) do { } while (0)
12367 +#endif
12368 +
12369 +#endif /* _DX_TAG_H */
12370 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
12371 --- linux-3.9.4/include/linux/vserver/tag_cmd.h 1970-01-01 00:00:00.000000000 +0000
12372 +++ linux-3.9.4-vs2.3.6.2/include/linux/vserver/tag_cmd.h       2013-05-31 14:47:11.000000000 +0000
12373 @@ -0,0 +1,10 @@
12374 +#ifndef _VSERVER_TAG_CMD_H
12375 +#define _VSERVER_TAG_CMD_H
12376 +
12377 +#include <uapi/vserver/tag_cmd.h>
12378 +
12379 +extern int vc_task_tag(uint32_t);
12380 +
12381 +extern int vc_tag_migrate(uint32_t);
12382 +
12383 +#endif /* _VSERVER_TAG_CMD_H */
12384 diff -NurpP --minimal linux-3.9.4/include/net/addrconf.h linux-3.9.4-vs2.3.6.2/include/net/addrconf.h
12385 --- linux-3.9.4/include/net/addrconf.h  2013-05-31 13:45:28.000000000 +0000
12386 +++ linux-3.9.4-vs2.3.6.2/include/net/addrconf.h        2013-05-31 17:17:53.000000000 +0000
12387 @@ -85,7 +85,8 @@ extern int                    ipv6_dev_get_saddr(struct n
12388                                                const struct net_device *dev,
12389                                                const struct in6_addr *daddr,
12390                                                unsigned int srcprefs,
12391 -                                              struct in6_addr *saddr);
12392 +                                              struct in6_addr *saddr,
12393 +                                              struct nx_info *nxi);
12394  extern int                     ipv6_get_lladdr(struct net_device *dev,
12395                                                 struct in6_addr *addr,
12396                                                 unsigned char banned_flags);
12397 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
12398 --- linux-3.9.4/include/net/af_unix.h   2013-02-19 13:58:52.000000000 +0000
12399 +++ linux-3.9.4-vs2.3.6.2/include/net/af_unix.h 2013-05-31 17:17:53.000000000 +0000
12400 @@ -4,6 +4,7 @@
12401  #include <linux/socket.h>
12402  #include <linux/un.h>
12403  #include <linux/mutex.h>
12404 +#include <linux/vs_base.h>
12405  #include <net/sock.h>
12406  
12407  extern void unix_inflight(struct file *fp);
12408 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
12409 --- linux-3.9.4/include/net/inet_timewait_sock.h        2013-05-31 13:45:28.000000000 +0000
12410 +++ linux-3.9.4-vs2.3.6.2/include/net/inet_timewait_sock.h      2013-05-31 17:18:34.000000000 +0000
12411 @@ -116,6 +116,10 @@ struct inet_timewait_sock {
12412  #define tw_dport               __tw_common.skc_dport
12413  #define tw_num                 __tw_common.skc_num
12414  #define tw_portpair            __tw_common.skc_portpair
12415 +#define tw_xid                 __tw_common.skc_xid
12416 +#define tw_vx_info             __tw_common.skc_vx_info
12417 +#define tw_nid                 __tw_common.skc_nid
12418 +#define tw_nx_info             __tw_common.skc_nx_info
12419  
12420         int                     tw_timeout;
12421         volatile unsigned char  tw_substate;
12422 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
12423 --- linux-3.9.4/include/net/ip6_route.h 2013-05-31 13:45:28.000000000 +0000
12424 +++ linux-3.9.4-vs2.3.6.2/include/net/ip6_route.h       2013-05-31 17:17:53.000000000 +0000
12425 @@ -95,7 +95,8 @@ extern int                    ip6_route_get_saddr(struct
12426                                                     struct rt6_info *rt,
12427                                                     const struct in6_addr *daddr,
12428                                                     unsigned int prefs,
12429 -                                                   struct in6_addr *saddr);
12430 +                                                   struct in6_addr *saddr,
12431 +                                                   struct nx_info *nxi);
12432  
12433  extern struct rt6_info         *rt6_lookup(struct net *net,
12434                                             const struct in6_addr *daddr,
12435 diff -NurpP --minimal linux-3.9.4/include/net/route.h linux-3.9.4-vs2.3.6.2/include/net/route.h
12436 --- linux-3.9.4/include/net/route.h     2013-02-19 13:58:52.000000000 +0000
12437 +++ linux-3.9.4-vs2.3.6.2/include/net/route.h   2013-05-31 17:17:53.000000000 +0000
12438 @@ -207,6 +207,9 @@ static inline void ip_rt_put(struct rtab
12439         dst_release(&rt->dst);
12440  }
12441  
12442 +#include <linux/vs_base.h>
12443 +#include <linux/vs_inet.h>
12444 +
12445  #define IPTOS_RT_MASK  (IPTOS_TOS_MASK & ~3)
12446  
12447  extern const __u8 ip_tos2prio[16];
12448 @@ -256,6 +259,9 @@ static inline void ip_route_connect_init
12449                            protocol, flow_flags, dst, src, dport, sport);
12450  }
12451  
12452 +extern struct rtable *ip_v4_find_src(struct net *net, struct nx_info *,
12453 +       struct flowi4 *);
12454 +
12455  static inline struct rtable *ip_route_connect(struct flowi4 *fl4,
12456                                               __be32 dst, __be32 src, u32 tos,
12457                                               int oif, u8 protocol,
12458 @@ -264,11 +270,25 @@ static inline struct rtable *ip_route_co
12459  {
12460         struct net *net = sock_net(sk);
12461         struct rtable *rt;
12462 +       struct nx_info *nx_info = current_nx_info();
12463  
12464         ip_route_connect_init(fl4, dst, src, tos, oif, protocol,
12465                               sport, dport, sk, can_sleep);
12466  
12467 -       if (!dst || !src) {
12468 +       if (sk)
12469 +               nx_info = sk->sk_nx_info;
12470 +
12471 +       vxdprintk(VXD_CBIT(net, 4),
12472 +               "ip_route_connect(%p) %p,%p;%lx",
12473 +               sk, nx_info, sk->sk_socket,
12474 +               (sk->sk_socket?sk->sk_socket->flags:0));
12475 +
12476 +       rt = ip_v4_find_src(net, nx_info, fl4);
12477 +       if (IS_ERR(rt))
12478 +               return rt;
12479 +       ip_rt_put(rt);
12480 +
12481 +       if (!fl4->daddr || !fl4->saddr) {
12482                 rt = __ip_route_output_key(net, fl4);
12483                 if (IS_ERR(rt))
12484                         return rt;
12485 diff -NurpP --minimal linux-3.9.4/include/net/sock.h linux-3.9.4-vs2.3.6.2/include/net/sock.h
12486 --- linux-3.9.4/include/net/sock.h      2013-05-31 14:22:27.000000000 +0000
12487 +++ linux-3.9.4-vs2.3.6.2/include/net/sock.h    2013-05-31 17:17:53.000000000 +0000
12488 @@ -191,6 +191,10 @@ struct sock_common {
12489  #ifdef CONFIG_NET_NS
12490         struct net              *skc_net;
12491  #endif
12492 +       xid_t                   skc_xid;
12493 +       struct vx_info          *skc_vx_info;
12494 +       nid_t                   skc_nid;
12495 +       struct nx_info          *skc_nx_info;
12496         /*
12497          * fields between dontcopy_begin/dontcopy_end
12498          * are not copied in sock_copy()
12499 @@ -304,6 +308,10 @@ struct sock {
12500  #define sk_bind_node           __sk_common.skc_bind_node
12501  #define sk_prot                        __sk_common.skc_prot
12502  #define sk_net                 __sk_common.skc_net
12503 +#define sk_xid                 __sk_common.skc_xid
12504 +#define sk_vx_info             __sk_common.skc_vx_info
12505 +#define sk_nid                 __sk_common.skc_nid
12506 +#define sk_nx_info             __sk_common.skc_nx_info
12507         socket_lock_t           sk_lock;
12508         struct sk_buff_head     sk_receive_queue;
12509         /*
12510 diff -NurpP --minimal linux-3.9.4/include/uapi/Kbuild linux-3.9.4-vs2.3.6.2/include/uapi/Kbuild
12511 --- linux-3.9.4/include/uapi/Kbuild     2012-12-11 03:30:57.000000000 +0000
12512 +++ linux-3.9.4-vs2.3.6.2/include/uapi/Kbuild   2013-05-31 14:47:11.000000000 +0000
12513 @@ -12,3 +12,4 @@ header-y += video/
12514  header-y += drm/
12515  header-y += xen/
12516  header-y += scsi/
12517 +header-y += vserver/
12518 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
12519 --- linux-3.9.4/include/uapi/linux/capability.h 2012-12-11 03:30:57.000000000 +0000
12520 +++ linux-3.9.4-vs2.3.6.2/include/uapi/linux/capability.h       2013-05-31 14:47:11.000000000 +0000
12521 @@ -259,6 +259,7 @@ struct vfs_cap_data {
12522     arbitrary SCSI commands */
12523  /* Allow setting encryption key on loopback filesystem */
12524  /* Allow setting zone reclaim policy */
12525 +/* Allow the selection of a security context */
12526  
12527  #define CAP_SYS_ADMIN        21
12528  
12529 @@ -345,7 +346,12 @@ struct vfs_cap_data {
12530  
12531  #define CAP_LAST_CAP         CAP_BLOCK_SUSPEND
12532  
12533 -#define cap_valid(x) ((x) >= 0 && (x) <= CAP_LAST_CAP)
12534 +/* Allow context manipulations */
12535 +/* Allow changing context info on files */
12536 +
12537 +#define CAP_CONTEXT         63
12538 +
12539 +#define cap_valid(x) ((x) >= 0 && ((x) <= CAP_LAST_CAP || (x) == CAP_CONTEXT))
12540  
12541  /*
12542   * Bit location of each capability (used by user-space library and kernel)
12543 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
12544 --- linux-3.9.4/include/uapi/linux/fs.h 2013-05-31 13:45:29.000000000 +0000
12545 +++ linux-3.9.4-vs2.3.6.2/include/uapi/linux/fs.h       2013-05-31 23:07:43.000000000 +0000
12546 @@ -86,6 +86,9 @@ struct inodes_stat_t {
12547  #define MS_KERNMOUNT   (1<<22) /* this is a kern_mount call */
12548  #define MS_I_VERSION   (1<<23) /* Update inode I_version field */
12549  #define MS_STRICTATIME (1<<24) /* Always perform atime updates */
12550 +#define MS_TAGGED      (1<<8)  /* use generic inode tagging */
12551 +#define MS_NOTAGCHECK  (1<<9)  /* don't check tags */
12552 +#define MS_TAGID       (1<<25) /* use specific tag for this mount */
12553  
12554  /* These sb flags are internal to the kernel */
12555  #define MS_SNAP_STABLE (1<<27) /* Snapshot pages during writeback, if needed */
12556 @@ -192,11 +195,14 @@ struct inodes_stat_t {
12557  #define FS_EXTENT_FL                   0x00080000 /* Extents */
12558  #define FS_DIRECTIO_FL                 0x00100000 /* Use direct i/o */
12559  #define FS_NOCOW_FL                    0x00800000 /* Do not cow file */
12560 +#define FS_IXUNLINK_FL                 0x08000000 /* Immutable invert on unlink */
12561  #define FS_RESERVED_FL                 0x80000000 /* reserved for ext2 lib */
12562  
12563 -#define FS_FL_USER_VISIBLE             0x0003DFFF /* User visible flags */
12564 -#define FS_FL_USER_MODIFIABLE          0x000380FF /* User modifiable flags */
12565 +#define FS_BARRIER_FL                  0x04000000 /* Barrier for chroot() */
12566 +#define FS_COW_FL                      0x20000000 /* Copy on Write marker */
12567  
12568 +#define FS_FL_USER_VISIBLE             0x0103DFFF /* User visible flags */
12569 +#define FS_FL_USER_MODIFIABLE          0x010380FF /* User modifiable flags */
12570  
12571  #define SYNC_FILE_RANGE_WAIT_BEFORE    1
12572  #define SYNC_FILE_RANGE_WRITE          2
12573 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
12574 --- linux-3.9.4/include/uapi/linux/gfs2_ondisk.h        2012-12-11 03:30:57.000000000 +0000
12575 +++ linux-3.9.4-vs2.3.6.2/include/uapi/linux/gfs2_ondisk.h      2013-05-31 14:47:11.000000000 +0000
12576 @@ -225,6 +225,9 @@ enum {
12577         gfs2fl_Sync             = 8,
12578         gfs2fl_System           = 9,
12579         gfs2fl_TopLevel         = 10,
12580 +       gfs2fl_IXUnlink         = 16,
12581 +       gfs2fl_Barrier          = 17,
12582 +       gfs2fl_Cow              = 18,
12583         gfs2fl_TruncInProg      = 29,
12584         gfs2fl_InheritDirectio  = 30,
12585         gfs2fl_InheritJdata     = 31,
12586 @@ -242,6 +245,9 @@ enum {
12587  #define GFS2_DIF_SYNC                  0x00000100
12588  #define GFS2_DIF_SYSTEM                        0x00000200 /* New in gfs2 */
12589  #define GFS2_DIF_TOPDIR                        0x00000400 /* New in gfs2 */
12590 +#define GFS2_DIF_IXUNLINK               0x00010000
12591 +#define GFS2_DIF_BARRIER                0x00020000
12592 +#define GFS2_DIF_COW                    0x00040000
12593  #define GFS2_DIF_TRUNC_IN_PROG         0x20000000 /* New in gfs2 */
12594  #define GFS2_DIF_INHERIT_DIRECTIO      0x40000000 /* only in gfs1 */
12595  #define GFS2_DIF_INHERIT_JDATA         0x80000000
12596 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
12597 --- linux-3.9.4/include/uapi/linux/if_tun.h     2013-02-19 13:58:55.000000000 +0000
12598 +++ linux-3.9.4-vs2.3.6.2/include/uapi/linux/if_tun.h   2013-05-31 15:00:16.000000000 +0000
12599 @@ -56,6 +56,7 @@
12600  #define TUNGETVNETHDRSZ _IOR('T', 215, int)
12601  #define TUNSETVNETHDRSZ _IOW('T', 216, int)
12602  #define TUNSETQUEUE  _IOW('T', 217, int)
12603 +#define TUNSETNID     _IOW('T', 218, int)
12604  
12605  /* TUNSETIFF ifr flags */
12606  #define IFF_TUN                0x0001
12607 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
12608 --- linux-3.9.4/include/uapi/linux/major.h      2012-12-11 03:30:57.000000000 +0000
12609 +++ linux-3.9.4-vs2.3.6.2/include/uapi/linux/major.h    2013-05-31 14:47:11.000000000 +0000
12610 @@ -15,6 +15,7 @@
12611  #define HD_MAJOR               IDE0_MAJOR
12612  #define PTY_SLAVE_MAJOR                3
12613  #define TTY_MAJOR              4
12614 +#define VROOT_MAJOR            4
12615  #define TTYAUX_MAJOR           5
12616  #define LP_MAJOR               6
12617  #define VCS_MAJOR              7
12618 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
12619 --- linux-3.9.4/include/uapi/linux/nfs_mount.h  2012-12-11 03:30:57.000000000 +0000
12620 +++ linux-3.9.4-vs2.3.6.2/include/uapi/linux/nfs_mount.h        2013-05-31 14:47:11.000000000 +0000
12621 @@ -63,7 +63,8 @@ struct nfs_mount_data {
12622  #define NFS_MOUNT_SECFLAVOUR   0x2000  /* 5 */
12623  #define NFS_MOUNT_NORDIRPLUS   0x4000  /* 5 */
12624  #define NFS_MOUNT_UNSHARED     0x8000  /* 5 */
12625 -#define NFS_MOUNT_FLAGMASK     0xFFFF
12626 +#define NFS_MOUNT_TAGGED       0x10000 /* context tagging */
12627 +#define NFS_MOUNT_FLAGMASK     0x1FFFF
12628  
12629  /* The following are for internal use only */
12630  #define NFS_MOUNT_LOOKUP_CACHE_NONEG   0x10000
12631 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
12632 --- linux-3.9.4/include/uapi/linux/reboot.h     2012-12-11 03:30:57.000000000 +0000
12633 +++ linux-3.9.4-vs2.3.6.2/include/uapi/linux/reboot.h   2013-05-31 14:47:11.000000000 +0000
12634 @@ -33,7 +33,7 @@
12635  #define        LINUX_REBOOT_CMD_RESTART2       0xA1B2C3D4
12636  #define        LINUX_REBOOT_CMD_SW_SUSPEND     0xD000FCE2
12637  #define        LINUX_REBOOT_CMD_KEXEC          0x45584543
12638 -
12639 +#define        LINUX_REBOOT_CMD_OOM            0xDEADBEEF
12640  
12641  
12642  #endif /* _UAPI_LINUX_REBOOT_H */
12643 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
12644 --- linux-3.9.4/include/uapi/linux/sysctl.h     2012-12-11 03:30:57.000000000 +0000
12645 +++ linux-3.9.4-vs2.3.6.2/include/uapi/linux/sysctl.h   2013-05-31 14:47:11.000000000 +0000
12646 @@ -60,6 +60,7 @@ enum
12647         CTL_ABI=9,              /* Binary emulation */
12648         CTL_CPU=10,             /* CPU stuff (speed scaling, etc) */
12649         CTL_ARLAN=254,          /* arlan wireless driver */
12650 +       CTL_VSERVER=4242,       /* Linux-VServer debug */
12651         CTL_S390DBF=5677,       /* s390 debug */
12652         CTL_SUNRPC=7249,        /* sunrpc debug */
12653         CTL_PM=9899,            /* frv power management */
12654 @@ -94,6 +95,7 @@ enum
12655  
12656         KERN_PANIC=15,          /* int: panic timeout */
12657         KERN_REALROOTDEV=16,    /* real root device to mount after initrd */
12658 +       KERN_VSHELPER=17,       /* string: path to vshelper policy agent */
12659  
12660         KERN_SPARC_REBOOT=21,   /* reboot command on Sparc */
12661         KERN_CTLALTDEL=22,      /* int: allow ctl-alt-del to reboot */
12662 diff -NurpP --minimal linux-3.9.4/include/uapi/vserver/Kbuild linux-3.9.4-vs2.3.6.2/include/uapi/vserver/Kbuild
12663 --- linux-3.9.4/include/uapi/vserver/Kbuild     1970-01-01 00:00:00.000000000 +0000
12664 +++ linux-3.9.4-vs2.3.6.2/include/uapi/vserver/Kbuild   2013-05-31 14:47:11.000000000 +0000
12665 @@ -0,0 +1,9 @@
12666 +
12667 +header-y += context_cmd.h network_cmd.h space_cmd.h \
12668 +       cacct_cmd.h cvirt_cmd.h limit_cmd.h dlimit_cmd.h \
12669 +       inode_cmd.h tag_cmd.h sched_cmd.h signal_cmd.h \
12670 +       debug_cmd.h device_cmd.h
12671 +
12672 +header-y += switch.h context.h network.h monitor.h \
12673 +       limit.h inode.h device.h
12674 +
12675 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
12676 --- linux-3.9.4/include/uapi/vserver/cacct_cmd.h        1970-01-01 00:00:00.000000000 +0000
12677 +++ linux-3.9.4-vs2.3.6.2/include/uapi/vserver/cacct_cmd.h      2013-05-31 14:47:11.000000000 +0000
12678 @@ -0,0 +1,15 @@
12679 +#ifndef _UAPI_VS_CACCT_CMD_H
12680 +#define _UAPI_VS_CACCT_CMD_H
12681 +
12682 +
12683 +/* virtual host info name commands */
12684 +
12685 +#define VCMD_sock_stat         VC_CMD(VSTAT, 5, 0)
12686 +
12687 +struct vcmd_sock_stat_v0 {
12688 +       uint32_t field;
12689 +       uint32_t count[3];
12690 +       uint64_t total[3];
12691 +};
12692 +
12693 +#endif /* _UAPI_VS_CACCT_CMD_H */
12694 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
12695 --- linux-3.9.4/include/uapi/vserver/context.h  1970-01-01 00:00:00.000000000 +0000
12696 +++ linux-3.9.4-vs2.3.6.2/include/uapi/vserver/context.h        2013-05-31 19:44:13.000000000 +0000
12697 @@ -0,0 +1,81 @@
12698 +#ifndef _UAPI_VS_CONTEXT_H
12699 +#define _UAPI_VS_CONTEXT_H
12700 +
12701 +#include <linux/types.h>
12702 +#include <linux/capability.h>
12703 +
12704 +
12705 +/* context flags */
12706 +
12707 +#define VXF_INFO_SCHED         0x00000002
12708 +#define VXF_INFO_NPROC         0x00000004
12709 +#define VXF_INFO_PRIVATE       0x00000008
12710 +
12711 +#define VXF_INFO_INIT          0x00000010
12712 +#define VXF_INFO_HIDE          0x00000020
12713 +#define VXF_INFO_ULIMIT                0x00000040
12714 +#define VXF_INFO_NSPACE                0x00000080
12715 +
12716 +#define VXF_SCHED_HARD         0x00000100
12717 +#define VXF_SCHED_PRIO         0x00000200
12718 +#define VXF_SCHED_PAUSE                0x00000400
12719 +
12720 +#define VXF_VIRT_MEM           0x00010000
12721 +#define VXF_VIRT_UPTIME                0x00020000
12722 +#define VXF_VIRT_CPU           0x00040000
12723 +#define VXF_VIRT_LOAD          0x00080000
12724 +#define VXF_VIRT_TIME          0x00100000
12725 +
12726 +#define VXF_HIDE_MOUNT         0x01000000
12727 +/* was VXF_HIDE_NETIF          0x02000000 */
12728 +#define VXF_HIDE_VINFO         0x04000000
12729 +
12730 +#define VXF_STATE_SETUP                (1ULL << 32)
12731 +#define VXF_STATE_INIT         (1ULL << 33)
12732 +#define VXF_STATE_ADMIN                (1ULL << 34)
12733 +
12734 +#define VXF_SC_HELPER          (1ULL << 36)
12735 +#define VXF_REBOOT_KILL                (1ULL << 37)
12736 +#define VXF_PERSISTENT         (1ULL << 38)
12737 +
12738 +#define VXF_FORK_RSS           (1ULL << 48)
12739 +#define VXF_PROLIFIC           (1ULL << 49)
12740 +
12741 +#define VXF_IGNEG_NICE         (1ULL << 52)
12742 +
12743 +#define VXF_ONE_TIME           (0x0007ULL << 32)
12744 +
12745 +#define VXF_INIT_SET           (VXF_STATE_SETUP | VXF_STATE_INIT | VXF_STATE_ADMIN)
12746 +
12747 +
12748 +/* context migration */
12749 +
12750 +#define VXM_SET_INIT           0x00000001
12751 +#define VXM_SET_REAPER         0x00000002
12752 +
12753 +/* context caps */
12754 +
12755 +#define VXC_SET_UTSNAME                0x00000001
12756 +#define VXC_SET_RLIMIT         0x00000002
12757 +#define VXC_FS_SECURITY                0x00000004
12758 +#define VXC_FS_TRUSTED         0x00000008
12759 +#define VXC_TIOCSTI            0x00000010
12760 +
12761 +/* was VXC_RAW_ICMP            0x00000100 */
12762 +#define VXC_SYSLOG             0x00001000
12763 +#define VXC_OOM_ADJUST         0x00002000
12764 +#define VXC_AUDIT_CONTROL      0x00004000
12765 +
12766 +/* #define VXC_SECURE_MOUNT    0x00010000
12767 +#define VXC_SECURE_REMOUNT     0x00020000 */
12768 +#define VXC_BINARY_MOUNT       0x00040000
12769 +#define VXC_DEV_MOUNT          0x00080000
12770 +
12771 +#define VXC_QUOTA_CTL          0x00100000
12772 +#define VXC_ADMIN_MAPPER       0x00200000
12773 +#define VXC_ADMIN_CLOOP                0x00400000
12774 +
12775 +#define VXC_KTHREAD            0x01000000
12776 +#define VXC_NAMESPACE          0x02000000
12777 +
12778 +#endif /* _UAPI_VS_CONTEXT_H */
12779 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
12780 --- linux-3.9.4/include/uapi/vserver/context_cmd.h      1970-01-01 00:00:00.000000000 +0000
12781 +++ linux-3.9.4-vs2.3.6.2/include/uapi/vserver/context_cmd.h    2013-05-31 14:47:11.000000000 +0000
12782 @@ -0,0 +1,115 @@
12783 +#ifndef _UAPI_VS_CONTEXT_CMD_H
12784 +#define _UAPI_VS_CONTEXT_CMD_H
12785 +
12786 +
12787 +/* vinfo commands */
12788 +
12789 +#define VCMD_task_xid          VC_CMD(VINFO, 1, 0)
12790 +
12791 +
12792 +#define VCMD_vx_info           VC_CMD(VINFO, 5, 0)
12793 +
12794 +struct vcmd_vx_info_v0 {
12795 +       uint32_t xid;
12796 +       uint32_t initpid;
12797 +       /* more to come */
12798 +};
12799 +
12800 +
12801 +#define VCMD_ctx_stat          VC_CMD(VSTAT, 0, 0)
12802 +
12803 +struct vcmd_ctx_stat_v0 {
12804 +       uint32_t usecnt;
12805 +       uint32_t tasks;
12806 +       /* more to come */
12807 +};
12808 +
12809 +
12810 +/* context commands */
12811 +
12812 +#define VCMD_ctx_create_v0     VC_CMD(VPROC, 1, 0)
12813 +#define VCMD_ctx_create                VC_CMD(VPROC, 1, 1)
12814 +
12815 +struct vcmd_ctx_create {
12816 +       uint64_t flagword;
12817 +};
12818 +
12819 +#define VCMD_ctx_migrate_v0    VC_CMD(PROCMIG, 1, 0)
12820 +#define VCMD_ctx_migrate       VC_CMD(PROCMIG, 1, 1)
12821 +
12822 +struct vcmd_ctx_migrate {
12823 +       uint64_t flagword;
12824 +};
12825 +
12826 +
12827 +
12828 +/* flag commands */
12829 +
12830 +#define VCMD_get_cflags                VC_CMD(FLAGS, 1, 0)
12831 +#define VCMD_set_cflags                VC_CMD(FLAGS, 2, 0)
12832 +
12833 +struct vcmd_ctx_flags_v0 {
12834 +       uint64_t flagword;
12835 +       uint64_t mask;
12836 +};
12837 +
12838 +
12839 +
12840 +/* context caps commands */
12841 +
12842 +#define VCMD_get_ccaps         VC_CMD(FLAGS, 3, 1)
12843 +#define VCMD_set_ccaps         VC_CMD(FLAGS, 4, 1)
12844 +
12845 +struct vcmd_ctx_caps_v1 {
12846 +       uint64_t ccaps;
12847 +       uint64_t cmask;
12848 +};
12849 +
12850 +
12851 +
12852 +/* bcaps commands */
12853 +
12854 +#define VCMD_get_bcaps         VC_CMD(FLAGS, 9, 0)
12855 +#define VCMD_set_bcaps         VC_CMD(FLAGS, 10, 0)
12856 +
12857 +struct vcmd_bcaps {
12858 +       uint64_t bcaps;
12859 +       uint64_t bmask;
12860 +};
12861 +
12862 +
12863 +
12864 +/* umask commands */
12865 +
12866 +#define VCMD_get_umask         VC_CMD(FLAGS, 13, 0)
12867 +#define VCMD_set_umask         VC_CMD(FLAGS, 14, 0)
12868 +
12869 +struct vcmd_umask {
12870 +       uint64_t umask;
12871 +       uint64_t mask;
12872 +};
12873 +
12874 +
12875 +
12876 +/* wmask commands */
12877 +
12878 +#define VCMD_get_wmask         VC_CMD(FLAGS, 15, 0)
12879 +#define VCMD_set_wmask         VC_CMD(FLAGS, 16, 0)
12880 +
12881 +struct vcmd_wmask {
12882 +       uint64_t wmask;
12883 +       uint64_t mask;
12884 +};
12885 +
12886 +
12887 +
12888 +/* OOM badness */
12889 +
12890 +#define VCMD_get_badness       VC_CMD(MEMCTRL, 5, 0)
12891 +#define VCMD_set_badness       VC_CMD(MEMCTRL, 6, 0)
12892 +
12893 +struct vcmd_badness_v0 {
12894 +       int64_t bias;
12895 +};
12896 +
12897 +#endif /* _UAPI_VS_CONTEXT_CMD_H */
12898 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
12899 --- linux-3.9.4/include/uapi/vserver/cvirt_cmd.h        1970-01-01 00:00:00.000000000 +0000
12900 +++ linux-3.9.4-vs2.3.6.2/include/uapi/vserver/cvirt_cmd.h      2013-05-31 14:47:11.000000000 +0000
12901 @@ -0,0 +1,41 @@
12902 +#ifndef _UAPI_VS_CVIRT_CMD_H
12903 +#define _UAPI_VS_CVIRT_CMD_H
12904 +
12905 +
12906 +/* virtual host info name commands */
12907 +
12908 +#define VCMD_set_vhi_name      VC_CMD(VHOST, 1, 0)
12909 +#define VCMD_get_vhi_name      VC_CMD(VHOST, 2, 0)
12910 +
12911 +struct vcmd_vhi_name_v0 {
12912 +       uint32_t field;
12913 +       char name[65];
12914 +};
12915 +
12916 +
12917 +enum vhi_name_field {
12918 +       VHIN_CONTEXT = 0,
12919 +       VHIN_SYSNAME,
12920 +       VHIN_NODENAME,
12921 +       VHIN_RELEASE,
12922 +       VHIN_VERSION,
12923 +       VHIN_MACHINE,
12924 +       VHIN_DOMAINNAME,
12925 +};
12926 +
12927 +
12928 +
12929 +#define VCMD_virt_stat         VC_CMD(VSTAT, 3, 0)
12930 +
12931 +struct vcmd_virt_stat_v0 {
12932 +       uint64_t offset;
12933 +       uint64_t uptime;
12934 +       uint32_t nr_threads;
12935 +       uint32_t nr_running;
12936 +       uint32_t nr_uninterruptible;
12937 +       uint32_t nr_onhold;
12938 +       uint32_t nr_forks;
12939 +       uint32_t load[3];
12940 +};
12941 +
12942 +#endif /* _UAPI_VS_CVIRT_CMD_H */
12943 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
12944 --- linux-3.9.4/include/uapi/vserver/debug_cmd.h        1970-01-01 00:00:00.000000000 +0000
12945 +++ linux-3.9.4-vs2.3.6.2/include/uapi/vserver/debug_cmd.h      2013-05-31 14:47:11.000000000 +0000
12946 @@ -0,0 +1,24 @@
12947 +#ifndef _UAPI_VS_DEBUG_CMD_H
12948 +#define _UAPI_VS_DEBUG_CMD_H
12949 +
12950 +
12951 +/* debug commands */
12952 +
12953 +#define VCMD_dump_history      VC_CMD(DEBUG, 1, 0)
12954 +
12955 +#define VCMD_read_history      VC_CMD(DEBUG, 5, 0)
12956 +#define VCMD_read_monitor      VC_CMD(DEBUG, 6, 0)
12957 +
12958 +struct  vcmd_read_history_v0 {
12959 +       uint32_t index;
12960 +       uint32_t count;
12961 +       char __user *data;
12962 +};
12963 +
12964 +struct  vcmd_read_monitor_v0 {
12965 +       uint32_t index;
12966 +       uint32_t count;
12967 +       char __user *data;
12968 +};
12969 +
12970 +#endif /* _UAPI_VS_DEBUG_CMD_H */
12971 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
12972 --- linux-3.9.4/include/uapi/vserver/device.h   1970-01-01 00:00:00.000000000 +0000
12973 +++ linux-3.9.4-vs2.3.6.2/include/uapi/vserver/device.h 2013-05-31 14:47:11.000000000 +0000
12974 @@ -0,0 +1,12 @@
12975 +#ifndef _UAPI_VS_DEVICE_H
12976 +#define _UAPI_VS_DEVICE_H
12977 +
12978 +
12979 +#define DATTR_CREATE   0x00000001
12980 +#define DATTR_OPEN     0x00000002
12981 +
12982 +#define DATTR_REMAP    0x00000010
12983 +
12984 +#define DATTR_MASK     0x00000013
12985 +
12986 +#endif /* _UAPI_VS_DEVICE_H */
12987 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
12988 --- linux-3.9.4/include/uapi/vserver/device_cmd.h       1970-01-01 00:00:00.000000000 +0000
12989 +++ linux-3.9.4-vs2.3.6.2/include/uapi/vserver/device_cmd.h     2013-05-31 14:47:11.000000000 +0000
12990 @@ -0,0 +1,16 @@
12991 +#ifndef _UAPI_VS_DEVICE_CMD_H
12992 +#define _UAPI_VS_DEVICE_CMD_H
12993 +
12994 +
12995 +/*  device vserver commands */
12996 +
12997 +#define VCMD_set_mapping       VC_CMD(DEVICE, 1, 0)
12998 +#define VCMD_unset_mapping     VC_CMD(DEVICE, 2, 0)
12999 +
13000 +struct vcmd_set_mapping_v0 {
13001 +       const char __user *device;
13002 +       const char __user *target;
13003 +       uint32_t flags;
13004 +};
13005 +
13006 +#endif /* _UAPI_VS_DEVICE_CMD_H */
13007 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
13008 --- linux-3.9.4/include/uapi/vserver/dlimit_cmd.h       1970-01-01 00:00:00.000000000 +0000
13009 +++ linux-3.9.4-vs2.3.6.2/include/uapi/vserver/dlimit_cmd.h     2013-05-31 14:47:11.000000000 +0000
13010 @@ -0,0 +1,67 @@
13011 +#ifndef _UAPI_VS_DLIMIT_CMD_H
13012 +#define _UAPI_VS_DLIMIT_CMD_H
13013 +
13014 +
13015 +/*  dlimit vserver commands */
13016 +
13017 +#define VCMD_add_dlimit                VC_CMD(DLIMIT, 1, 0)
13018 +#define VCMD_rem_dlimit                VC_CMD(DLIMIT, 2, 0)
13019 +
13020 +#define VCMD_set_dlimit                VC_CMD(DLIMIT, 5, 0)
13021 +#define VCMD_get_dlimit                VC_CMD(DLIMIT, 6, 0)
13022 +
13023 +struct vcmd_ctx_dlimit_base_v0 {
13024 +       const char __user *name;
13025 +       uint32_t flags;
13026 +};
13027 +
13028 +struct vcmd_ctx_dlimit_v0 {
13029 +       const char __user *name;
13030 +       uint32_t space_used;                    /* used space in kbytes */
13031 +       uint32_t space_total;                   /* maximum space in kbytes */
13032 +       uint32_t inodes_used;                   /* used inodes */
13033 +       uint32_t inodes_total;                  /* maximum inodes */
13034 +       uint32_t reserved;                      /* reserved for root in % */
13035 +       uint32_t flags;
13036 +};
13037 +
13038 +#define CDLIM_UNSET            ((uint32_t)0UL)
13039 +#define CDLIM_INFINITY         ((uint32_t)~0UL)
13040 +#define CDLIM_KEEP             ((uint32_t)~1UL)
13041 +
13042 +#define DLIME_UNIT     0
13043 +#define DLIME_KILO     1
13044 +#define DLIME_MEGA     2
13045 +#define DLIME_GIGA     3
13046 +
13047 +#define DLIMF_SHIFT    0x10
13048 +
13049 +#define DLIMS_USED     0
13050 +#define DLIMS_TOTAL    2
13051 +
13052 +static inline
13053 +uint64_t dlimit_space_32to64(uint32_t val, uint32_t flags, int shift)
13054 +{
13055 +       int exp = (flags & DLIMF_SHIFT) ?
13056 +               (flags >> shift) & DLIME_GIGA : DLIME_KILO;
13057 +       return ((uint64_t)val) << (10 * exp);
13058 +}
13059 +
13060 +static inline
13061 +uint32_t dlimit_space_64to32(uint64_t val, uint32_t *flags, int shift)
13062 +{
13063 +       int exp = 0;
13064 +
13065 +       if (*flags & DLIMF_SHIFT) {
13066 +               while (val > (1LL << 32) && (exp < 3)) {
13067 +                       val >>= 10;
13068 +                       exp++;
13069 +               }
13070 +               *flags &= ~(DLIME_GIGA << shift);
13071 +               *flags |= exp << shift;
13072 +       } else
13073 +               val >>= 10;
13074 +       return val;
13075 +}
13076 +
13077 +#endif /* _UAPI_VS_DLIMIT_CMD_H */
13078 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
13079 --- linux-3.9.4/include/uapi/vserver/inode.h    1970-01-01 00:00:00.000000000 +0000
13080 +++ linux-3.9.4-vs2.3.6.2/include/uapi/vserver/inode.h  2013-05-31 14:47:11.000000000 +0000
13081 @@ -0,0 +1,23 @@
13082 +#ifndef _UAPI_VS_INODE_H
13083 +#define _UAPI_VS_INODE_H
13084 +
13085 +
13086 +#define IATTR_TAG      0x01000000
13087 +
13088 +#define IATTR_ADMIN    0x00000001
13089 +#define IATTR_WATCH    0x00000002
13090 +#define IATTR_HIDE     0x00000004
13091 +#define IATTR_FLAGS    0x00000007
13092 +
13093 +#define IATTR_BARRIER  0x00010000
13094 +#define IATTR_IXUNLINK 0x00020000
13095 +#define IATTR_IMMUTABLE 0x00040000
13096 +#define IATTR_COW      0x00080000
13097 +
13098 +
13099 +/* inode ioctls */
13100 +
13101 +#define FIOC_GETXFLG   _IOR('x', 5, long)
13102 +#define FIOC_SETXFLG   _IOW('x', 6, long)
13103 +
13104 +#endif /* _UAPI_VS_INODE_H */
13105 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
13106 --- linux-3.9.4/include/uapi/vserver/inode_cmd.h        1970-01-01 00:00:00.000000000 +0000
13107 +++ linux-3.9.4-vs2.3.6.2/include/uapi/vserver/inode_cmd.h      2013-05-31 14:47:11.000000000 +0000
13108 @@ -0,0 +1,26 @@
13109 +#ifndef _UAPI_VS_INODE_CMD_H
13110 +#define _UAPI_VS_INODE_CMD_H
13111 +
13112 +
13113 +/*  inode vserver commands */
13114 +
13115 +#define VCMD_get_iattr         VC_CMD(INODE, 1, 1)
13116 +#define VCMD_set_iattr         VC_CMD(INODE, 2, 1)
13117 +
13118 +#define VCMD_fget_iattr                VC_CMD(INODE, 3, 0)
13119 +#define VCMD_fset_iattr                VC_CMD(INODE, 4, 0)
13120 +
13121 +struct vcmd_ctx_iattr_v1 {
13122 +       const char __user *name;
13123 +       uint32_t tag;
13124 +       uint32_t flags;
13125 +       uint32_t mask;
13126 +};
13127 +
13128 +struct vcmd_ctx_fiattr_v0 {
13129 +       uint32_t tag;
13130 +       uint32_t flags;
13131 +       uint32_t mask;
13132 +};
13133 +
13134 +#endif /* _UAPI_VS_INODE_CMD_H */
13135 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
13136 --- linux-3.9.4/include/uapi/vserver/limit.h    1970-01-01 00:00:00.000000000 +0000
13137 +++ linux-3.9.4-vs2.3.6.2/include/uapi/vserver/limit.h  2013-05-31 14:47:11.000000000 +0000
13138 @@ -0,0 +1,14 @@
13139 +#ifndef _UAPI_VS_LIMIT_H
13140 +#define _UAPI_VS_LIMIT_H
13141 +
13142 +
13143 +#define VLIMIT_NSOCK   16
13144 +#define VLIMIT_OPENFD  17
13145 +#define VLIMIT_ANON    18
13146 +#define VLIMIT_SHMEM   19
13147 +#define VLIMIT_SEMARY  20
13148 +#define VLIMIT_NSEMS   21
13149 +#define VLIMIT_DENTRY  22
13150 +#define VLIMIT_MAPPED  23
13151 +
13152 +#endif /* _UAPI_VS_LIMIT_H */
13153 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
13154 --- linux-3.9.4/include/uapi/vserver/limit_cmd.h        1970-01-01 00:00:00.000000000 +0000
13155 +++ linux-3.9.4-vs2.3.6.2/include/uapi/vserver/limit_cmd.h      2013-05-31 14:47:11.000000000 +0000
13156 @@ -0,0 +1,40 @@
13157 +#ifndef _UAPI_VS_LIMIT_CMD_H
13158 +#define _UAPI_VS_LIMIT_CMD_H
13159 +
13160 +
13161 +/*  rlimit vserver commands */
13162 +
13163 +#define VCMD_get_rlimit                VC_CMD(RLIMIT, 1, 0)
13164 +#define VCMD_set_rlimit                VC_CMD(RLIMIT, 2, 0)
13165 +#define VCMD_get_rlimit_mask   VC_CMD(RLIMIT, 3, 0)
13166 +#define VCMD_reset_hits                VC_CMD(RLIMIT, 7, 0)
13167 +#define VCMD_reset_minmax      VC_CMD(RLIMIT, 9, 0)
13168 +
13169 +struct vcmd_ctx_rlimit_v0 {
13170 +       uint32_t id;
13171 +       uint64_t minimum;
13172 +       uint64_t softlimit;
13173 +       uint64_t maximum;
13174 +};
13175 +
13176 +struct vcmd_ctx_rlimit_mask_v0 {
13177 +       uint32_t minimum;
13178 +       uint32_t softlimit;
13179 +       uint32_t maximum;
13180 +};
13181 +
13182 +#define VCMD_rlimit_stat       VC_CMD(VSTAT, 1, 0)
13183 +
13184 +struct vcmd_rlimit_stat_v0 {
13185 +       uint32_t id;
13186 +       uint32_t hits;
13187 +       uint64_t value;
13188 +       uint64_t minimum;
13189 +       uint64_t maximum;
13190 +};
13191 +
13192 +#define CRLIM_UNSET            (0ULL)
13193 +#define CRLIM_INFINITY         (~0ULL)
13194 +#define CRLIM_KEEP             (~1ULL)
13195 +
13196 +#endif /* _UAPI_VS_LIMIT_CMD_H */
13197 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
13198 --- linux-3.9.4/include/uapi/vserver/monitor.h  1970-01-01 00:00:00.000000000 +0000
13199 +++ linux-3.9.4-vs2.3.6.2/include/uapi/vserver/monitor.h        2013-05-31 14:47:11.000000000 +0000
13200 @@ -0,0 +1,96 @@
13201 +#ifndef _UAPI_VS_MONITOR_H
13202 +#define _UAPI_VS_MONITOR_H
13203 +
13204 +#include <linux/types.h>
13205 +
13206 +
13207 +enum {
13208 +       VXM_UNUSED = 0,
13209 +
13210 +       VXM_SYNC = 0x10,
13211 +
13212 +       VXM_UPDATE = 0x20,
13213 +       VXM_UPDATE_1,
13214 +       VXM_UPDATE_2,
13215 +
13216 +       VXM_RQINFO_1 = 0x24,
13217 +       VXM_RQINFO_2,
13218 +
13219 +       VXM_ACTIVATE = 0x40,
13220 +       VXM_DEACTIVATE,
13221 +       VXM_IDLE,
13222 +
13223 +       VXM_HOLD = 0x44,
13224 +       VXM_UNHOLD,
13225 +
13226 +       VXM_MIGRATE = 0x48,
13227 +       VXM_RESCHED,
13228 +
13229 +       /* all other bits are flags */
13230 +       VXM_SCHED = 0x80,
13231 +};
13232 +
13233 +struct _vxm_update_1 {
13234 +       uint32_t tokens_max;
13235 +       uint32_t fill_rate;
13236 +       uint32_t interval;
13237 +};
13238 +
13239 +struct _vxm_update_2 {
13240 +       uint32_t tokens_min;
13241 +       uint32_t fill_rate;
13242 +       uint32_t interval;
13243 +};
13244 +
13245 +struct _vxm_rqinfo_1 {
13246 +       uint16_t running;
13247 +       uint16_t onhold;
13248 +       uint16_t iowait;
13249 +       uint16_t uintr;
13250 +       uint32_t idle_tokens;
13251 +};
13252 +
13253 +struct _vxm_rqinfo_2 {
13254 +       uint32_t norm_time;
13255 +       uint32_t idle_time;
13256 +       uint32_t idle_skip;
13257 +};
13258 +
13259 +struct _vxm_sched {
13260 +       uint32_t tokens;
13261 +       uint32_t norm_time;
13262 +       uint32_t idle_time;
13263 +};
13264 +
13265 +struct _vxm_task {
13266 +       uint16_t pid;
13267 +       uint16_t state;
13268 +};
13269 +
13270 +struct _vxm_event {
13271 +       uint32_t jif;
13272 +       union {
13273 +               uint32_t seq;
13274 +               uint32_t sec;
13275 +       };
13276 +       union {
13277 +               uint32_t tokens;
13278 +               uint32_t nsec;
13279 +               struct _vxm_task tsk;
13280 +       };
13281 +};
13282 +
13283 +struct _vx_mon_entry {
13284 +       uint16_t type;
13285 +       uint16_t xid;
13286 +       union {
13287 +               struct _vxm_event ev;
13288 +               struct _vxm_sched sd;
13289 +               struct _vxm_update_1 u1;
13290 +               struct _vxm_update_2 u2;
13291 +               struct _vxm_rqinfo_1 q1;
13292 +               struct _vxm_rqinfo_2 q2;
13293 +       };
13294 +};
13295 +
13296 +#endif /* _UAPI_VS_MONITOR_H */
13297 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
13298 --- linux-3.9.4/include/uapi/vserver/network.h  1970-01-01 00:00:00.000000000 +0000
13299 +++ linux-3.9.4-vs2.3.6.2/include/uapi/vserver/network.h        2013-05-31 14:47:11.000000000 +0000
13300 @@ -0,0 +1,76 @@
13301 +#ifndef _UAPI_VS_NETWORK_H
13302 +#define _UAPI_VS_NETWORK_H
13303 +
13304 +#include <linux/types.h>
13305 +
13306 +
13307 +#define MAX_N_CONTEXT  65535   /* Arbitrary limit */
13308 +
13309 +
13310 +/* network flags */
13311 +
13312 +#define NXF_INFO_PRIVATE       0x00000008
13313 +
13314 +#define NXF_SINGLE_IP          0x00000100
13315 +#define NXF_LBACK_REMAP                0x00000200
13316 +#define NXF_LBACK_ALLOW                0x00000400
13317 +
13318 +#define NXF_HIDE_NETIF         0x02000000
13319 +#define NXF_HIDE_LBACK         0x04000000
13320 +
13321 +#define NXF_STATE_SETUP                (1ULL << 32)
13322 +#define NXF_STATE_ADMIN                (1ULL << 34)
13323 +
13324 +#define NXF_SC_HELPER          (1ULL << 36)
13325 +#define NXF_PERSISTENT         (1ULL << 38)
13326 +
13327 +#define NXF_ONE_TIME           (0x0005ULL << 32)
13328 +
13329 +
13330 +#define        NXF_INIT_SET            (__nxf_init_set())
13331 +
13332 +static inline uint64_t __nxf_init_set(void) {
13333 +       return    NXF_STATE_ADMIN
13334 +#ifdef CONFIG_VSERVER_AUTO_LBACK
13335 +               | NXF_LBACK_REMAP
13336 +               | NXF_HIDE_LBACK
13337 +#endif
13338 +#ifdef CONFIG_VSERVER_AUTO_SINGLE
13339 +               | NXF_SINGLE_IP
13340 +#endif
13341 +               | NXF_HIDE_NETIF;
13342 +}
13343 +
13344 +
13345 +/* network caps */
13346 +
13347 +#define NXC_TUN_CREATE         0x00000001
13348 +
13349 +#define NXC_RAW_ICMP           0x00000100
13350 +
13351 +#define NXC_MULTICAST          0x00001000
13352 +
13353 +
13354 +/* address types */
13355 +
13356 +#define NXA_TYPE_IPV4          0x0001
13357 +#define NXA_TYPE_IPV6          0x0002
13358 +
13359 +#define NXA_TYPE_NONE          0x0000
13360 +#define NXA_TYPE_ANY           0x00FF
13361 +
13362 +#define NXA_TYPE_ADDR          0x0010
13363 +#define NXA_TYPE_MASK          0x0020
13364 +#define NXA_TYPE_RANGE         0x0040
13365 +
13366 +#define NXA_MASK_ALL           (NXA_TYPE_ADDR | NXA_TYPE_MASK | NXA_TYPE_RANGE)
13367 +
13368 +#define NXA_MOD_BCAST          0x0100
13369 +#define NXA_MOD_LBACK          0x0200
13370 +
13371 +#define NXA_LOOPBACK           0x1000
13372 +
13373 +#define NXA_MASK_BIND          (NXA_MASK_ALL | NXA_MOD_BCAST | NXA_MOD_LBACK)
13374 +#define NXA_MASK_SHOW          (NXA_MASK_ALL | NXA_LOOPBACK)
13375 +
13376 +#endif /* _UAPI_VS_NETWORK_H */
13377 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
13378 --- linux-3.9.4/include/uapi/vserver/network_cmd.h      1970-01-01 00:00:00.000000000 +0000
13379 +++ linux-3.9.4-vs2.3.6.2/include/uapi/vserver/network_cmd.h    2013-05-31 14:47:11.000000000 +0000
13380 @@ -0,0 +1,123 @@
13381 +#ifndef _UAPI_VS_NETWORK_CMD_H
13382 +#define _UAPI_VS_NETWORK_CMD_H
13383 +
13384 +
13385 +/* vinfo commands */
13386 +
13387 +#define VCMD_task_nid          VC_CMD(VINFO, 2, 0)
13388 +
13389 +
13390 +#define VCMD_nx_info           VC_CMD(VINFO, 6, 0)
13391 +
13392 +struct vcmd_nx_info_v0 {
13393 +       uint32_t nid;
13394 +       /* more to come */
13395 +};
13396 +
13397 +
13398 +#include <linux/in.h>
13399 +#include <linux/in6.h>
13400 +
13401 +#define VCMD_net_create_v0     VC_CMD(VNET, 1, 0)
13402 +#define VCMD_net_create                VC_CMD(VNET, 1, 1)
13403 +
13404 +struct  vcmd_net_create {
13405 +       uint64_t flagword;
13406 +};
13407 +
13408 +#define VCMD_net_migrate       VC_CMD(NETMIG, 1, 0)
13409 +
13410 +#define VCMD_net_add           VC_CMD(NETALT, 1, 0)
13411 +#define VCMD_net_remove                VC_CMD(NETALT, 2, 0)
13412 +
13413 +struct vcmd_net_addr_v0 {
13414 +       uint16_t type;
13415 +       uint16_t count;
13416 +       struct in_addr ip[4];
13417 +       struct in_addr mask[4];
13418 +};
13419 +
13420 +#define VCMD_net_add_ipv4_v1   VC_CMD(NETALT, 1, 1)
13421 +#define VCMD_net_rem_ipv4_v1   VC_CMD(NETALT, 2, 1)
13422 +
13423 +struct vcmd_net_addr_ipv4_v1 {
13424 +       uint16_t type;
13425 +       uint16_t flags;
13426 +       struct in_addr ip;
13427 +       struct in_addr mask;
13428 +};
13429 +
13430 +#define VCMD_net_add_ipv4      VC_CMD(NETALT, 1, 2)
13431 +#define VCMD_net_rem_ipv4      VC_CMD(NETALT, 2, 2)
13432 +
13433 +struct vcmd_net_addr_ipv4_v2 {
13434 +       uint16_t type;
13435 +       uint16_t flags;
13436 +       struct in_addr ip;
13437 +       struct in_addr ip2;
13438 +       struct in_addr mask;
13439 +};
13440 +
13441 +#define VCMD_net_add_ipv6      VC_CMD(NETALT, 3, 1)
13442 +#define VCMD_net_remove_ipv6   VC_CMD(NETALT, 4, 1)
13443 +
13444 +struct vcmd_net_addr_ipv6_v1 {
13445 +       uint16_t type;
13446 +       uint16_t flags;
13447 +       uint32_t prefix;
13448 +       struct in6_addr ip;
13449 +       struct in6_addr mask;
13450 +};
13451 +
13452 +#define VCMD_add_match_ipv4    VC_CMD(NETALT, 5, 0)
13453 +#define VCMD_get_match_ipv4    VC_CMD(NETALT, 6, 0)
13454 +
13455 +struct vcmd_match_ipv4_v0 {
13456 +       uint16_t type;
13457 +       uint16_t flags;
13458 +       uint16_t parent;
13459 +       uint16_t prefix;
13460 +       struct in_addr ip;
13461 +       struct in_addr ip2;
13462 +       struct in_addr mask;
13463 +};
13464 +
13465 +#define VCMD_add_match_ipv6    VC_CMD(NETALT, 7, 0)
13466 +#define VCMD_get_match_ipv6    VC_CMD(NETALT, 8, 0)
13467 +
13468 +struct vcmd_match_ipv6_v0 {
13469 +       uint16_t type;
13470 +       uint16_t flags;
13471 +       uint16_t parent;
13472 +       uint16_t prefix;
13473 +       struct in6_addr ip;
13474 +       struct in6_addr ip2;
13475 +       struct in6_addr mask;
13476 +};
13477 +
13478 +
13479 +
13480 +
13481 +/* flag commands */
13482 +
13483 +#define VCMD_get_nflags                VC_CMD(FLAGS, 5, 0)
13484 +#define VCMD_set_nflags                VC_CMD(FLAGS, 6, 0)
13485 +
13486 +struct vcmd_net_flags_v0 {
13487 +       uint64_t flagword;
13488 +       uint64_t mask;
13489 +};
13490 +
13491 +
13492 +
13493 +/* network caps commands */
13494 +
13495 +#define VCMD_get_ncaps         VC_CMD(FLAGS, 7, 0)
13496 +#define VCMD_set_ncaps         VC_CMD(FLAGS, 8, 0)
13497 +
13498 +struct vcmd_net_caps_v0 {
13499 +       uint64_t ncaps;
13500 +       uint64_t cmask;
13501 +};
13502 +
13503 +#endif /* _UAPI_VS_NETWORK_CMD_H */
13504 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
13505 --- linux-3.9.4/include/uapi/vserver/sched_cmd.h        1970-01-01 00:00:00.000000000 +0000
13506 +++ linux-3.9.4-vs2.3.6.2/include/uapi/vserver/sched_cmd.h      2013-05-31 14:47:11.000000000 +0000
13507 @@ -0,0 +1,13 @@
13508 +#ifndef _UAPI_VS_SCHED_CMD_H
13509 +#define _UAPI_VS_SCHED_CMD_H
13510 +
13511 +
13512 +struct vcmd_prio_bias {
13513 +       int32_t cpu_id;
13514 +       int32_t prio_bias;
13515 +};
13516 +
13517 +#define VCMD_set_prio_bias     VC_CMD(SCHED, 4, 0)
13518 +#define VCMD_get_prio_bias     VC_CMD(SCHED, 5, 0)
13519 +
13520 +#endif /* _UAPI_VS_SCHED_CMD_H */
13521 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
13522 --- linux-3.9.4/include/uapi/vserver/signal_cmd.h       1970-01-01 00:00:00.000000000 +0000
13523 +++ linux-3.9.4-vs2.3.6.2/include/uapi/vserver/signal_cmd.h     2013-05-31 14:47:11.000000000 +0000
13524 @@ -0,0 +1,31 @@
13525 +#ifndef _UAPI_VS_SIGNAL_CMD_H
13526 +#define _UAPI_VS_SIGNAL_CMD_H
13527 +
13528 +
13529 +/*  signalling vserver commands */
13530 +
13531 +#define VCMD_ctx_kill          VC_CMD(PROCTRL, 1, 0)
13532 +#define VCMD_wait_exit         VC_CMD(EVENT, 99, 0)
13533 +
13534 +struct vcmd_ctx_kill_v0 {
13535 +       int32_t pid;
13536 +       int32_t sig;
13537 +};
13538 +
13539 +struct vcmd_wait_exit_v0 {
13540 +       int32_t reboot_cmd;
13541 +       int32_t exit_code;
13542 +};
13543 +
13544 +
13545 +/*  process alteration commands */
13546 +
13547 +#define VCMD_get_pflags                VC_CMD(PROCALT, 5, 0)
13548 +#define VCMD_set_pflags                VC_CMD(PROCALT, 6, 0)
13549 +
13550 +struct vcmd_pflags_v0 {
13551 +       uint32_t flagword;
13552 +       uint32_t mask;
13553 +};
13554 +
13555 +#endif /* _UAPI_VS_SIGNAL_CMD_H */
13556 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
13557 --- linux-3.9.4/include/uapi/vserver/space_cmd.h        1970-01-01 00:00:00.000000000 +0000
13558 +++ linux-3.9.4-vs2.3.6.2/include/uapi/vserver/space_cmd.h      2013-05-31 14:47:11.000000000 +0000
13559 @@ -0,0 +1,28 @@
13560 +#ifndef _UAPI_VS_SPACE_CMD_H
13561 +#define _UAPI_VS_SPACE_CMD_H
13562 +
13563 +
13564 +#define VCMD_enter_space_v0    VC_CMD(PROCALT, 1, 0)
13565 +#define VCMD_enter_space_v1    VC_CMD(PROCALT, 1, 1)
13566 +#define VCMD_enter_space       VC_CMD(PROCALT, 1, 2)
13567 +
13568 +#define VCMD_set_space_v0      VC_CMD(PROCALT, 3, 0)
13569 +#define VCMD_set_space_v1      VC_CMD(PROCALT, 3, 1)
13570 +#define VCMD_set_space         VC_CMD(PROCALT, 3, 2)
13571 +
13572 +#define VCMD_get_space_mask_v0 VC_CMD(PROCALT, 4, 0)
13573 +
13574 +#define VCMD_get_space_mask    VC_CMD(VSPACE, 0, 1)
13575 +#define VCMD_get_space_default VC_CMD(VSPACE, 1, 0)
13576 +
13577 +
13578 +struct vcmd_space_mask_v1 {
13579 +       uint64_t mask;
13580 +};
13581 +
13582 +struct vcmd_space_mask_v2 {
13583 +       uint64_t mask;
13584 +       uint32_t index;
13585 +};
13586 +
13587 +#endif /* _UAPI_VS_SPACE_CMD_H */
13588 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
13589 --- linux-3.9.4/include/uapi/vserver/switch.h   1970-01-01 00:00:00.000000000 +0000
13590 +++ linux-3.9.4-vs2.3.6.2/include/uapi/vserver/switch.h 2013-05-31 14:47:11.000000000 +0000
13591 @@ -0,0 +1,90 @@
13592 +#ifndef _UAPI_VS_SWITCH_H
13593 +#define _UAPI_VS_SWITCH_H
13594 +
13595 +#include <linux/types.h>
13596 +
13597 +
13598 +#define VC_CATEGORY(c)         (((c) >> 24) & 0x3F)
13599 +#define VC_COMMAND(c)          (((c) >> 16) & 0xFF)
13600 +#define VC_VERSION(c)          ((c) & 0xFFF)
13601 +
13602 +#define VC_CMD(c, i, v)                ((((VC_CAT_ ## c) & 0x3F) << 24) \
13603 +                               | (((i) & 0xFF) << 16) | ((v) & 0xFFF))
13604 +
13605 +/*
13606 +
13607 +  Syscall Matrix V2.8
13608 +
13609 +        |VERSION|CREATE |MODIFY |MIGRATE|CONTROL|EXPERIM| |SPECIAL|SPECIAL|
13610 +        |STATS  |DESTROY|ALTER  |CHANGE |LIMIT  |TEST   | |       |       |
13611 +        |INFO   |SETUP  |       |MOVE   |       |       | |       |       |
13612 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13613 +  SYSTEM |VERSION|VSETUP |VHOST  |       |       |       | |DEVICE |       |
13614 +  HOST   |     00|     01|     02|     03|     04|     05| |     06|     07|
13615 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13616 +  CPU    |       |VPROC  |PROCALT|PROCMIG|PROCTRL|       | |SCHED. |       |
13617 +  PROCESS|     08|     09|     10|     11|     12|     13| |     14|     15|
13618 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13619 +  MEMORY |       |       |       |       |MEMCTRL|       | |SWAP   |       |
13620 +        |     16|     17|     18|     19|     20|     21| |     22|     23|
13621 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13622 +  NETWORK|       |VNET   |NETALT |NETMIG |NETCTL |       | |SERIAL |       |
13623 +        |     24|     25|     26|     27|     28|     29| |     30|     31|
13624 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13625 +  DISK   |       |       |       |TAGMIG |DLIMIT |       | |INODE  |       |
13626 +  VFS    |     32|     33|     34|     35|     36|     37| |     38|     39|
13627 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13628 +  OTHER  |VSTAT  |       |       |       |       |       | |VINFO  |       |
13629 +        |     40|     41|     42|     43|     44|     45| |     46|     47|
13630 +  =======+=======+=======+=======+=======+=======+=======+ +=======+=======+
13631 +  SPECIAL|EVENT  |       |       |       |FLAGS  |       | |VSPACE |       |
13632 +        |     48|     49|     50|     51|     52|     53| |     54|     55|
13633 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13634 +  SPECIAL|DEBUG  |       |       |       |RLIMIT |SYSCALL| |       |COMPAT |
13635 +        |     56|     57|     58|     59|     60|TEST 61| |     62|     63|
13636 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13637 +
13638 +*/
13639 +
13640 +#define VC_CAT_VERSION         0
13641 +
13642 +#define VC_CAT_VSETUP          1
13643 +#define VC_CAT_VHOST           2
13644 +
13645 +#define VC_CAT_DEVICE          6
13646 +
13647 +#define VC_CAT_VPROC           9
13648 +#define VC_CAT_PROCALT         10
13649 +#define VC_CAT_PROCMIG         11
13650 +#define VC_CAT_PROCTRL         12
13651 +
13652 +#define VC_CAT_SCHED           14
13653 +#define VC_CAT_MEMCTRL         20
13654 +
13655 +#define VC_CAT_VNET            25
13656 +#define VC_CAT_NETALT          26
13657 +#define VC_CAT_NETMIG          27
13658 +#define VC_CAT_NETCTRL         28
13659 +
13660 +#define VC_CAT_TAGMIG          35
13661 +#define VC_CAT_DLIMIT          36
13662 +#define VC_CAT_INODE           38
13663 +
13664 +#define VC_CAT_VSTAT           40
13665 +#define VC_CAT_VINFO           46
13666 +#define VC_CAT_EVENT           48
13667 +
13668 +#define VC_CAT_FLAGS           52
13669 +#define VC_CAT_VSPACE          54
13670 +#define VC_CAT_DEBUG           56
13671 +#define VC_CAT_RLIMIT          60
13672 +
13673 +#define VC_CAT_SYSTEST         61
13674 +#define VC_CAT_COMPAT          63
13675 +
13676 +/*  query version */
13677 +
13678 +#define VCMD_get_version       VC_CMD(VERSION, 0, 0)
13679 +#define VCMD_get_vci           VC_CMD(VERSION, 1, 0)
13680 +
13681 +#endif /* _UAPI_VS_SWITCH_H */
13682 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
13683 --- linux-3.9.4/include/uapi/vserver/tag_cmd.h  1970-01-01 00:00:00.000000000 +0000
13684 +++ linux-3.9.4-vs2.3.6.2/include/uapi/vserver/tag_cmd.h        2013-05-31 14:47:11.000000000 +0000
13685 @@ -0,0 +1,14 @@
13686 +#ifndef _UAPI_VS_TAG_CMD_H
13687 +#define _UAPI_VS_TAG_CMD_H
13688 +
13689 +
13690 +/* vinfo commands */
13691 +
13692 +#define VCMD_task_tag          VC_CMD(VINFO, 3, 0)
13693 +
13694 +
13695 +/* context commands */
13696 +
13697 +#define VCMD_tag_migrate       VC_CMD(TAGMIG, 1, 0)
13698 +
13699 +#endif /* _UAPI_VS_TAG_CMD_H */
13700 diff -NurpP --minimal linux-3.9.4/init/Kconfig linux-3.9.4-vs2.3.6.2/init/Kconfig
13701 --- linux-3.9.4/init/Kconfig    2013-05-31 13:45:29.000000000 +0000
13702 +++ linux-3.9.4-vs2.3.6.2/init/Kconfig  2013-05-31 14:47:11.000000000 +0000
13703 @@ -760,6 +760,7 @@ config NUMA_BALANCING
13704  menuconfig CGROUPS
13705         boolean "Control Group support"
13706         depends on EVENTFD
13707 +       default y
13708         help
13709           This option adds support for grouping sets of processes together, for
13710           use with process control subsystems such as Cpusets, CFS, memory
13711 @@ -1022,6 +1023,7 @@ config IPC_NS
13712  config USER_NS
13713         bool "User namespace"
13714         depends on UIDGID_CONVERTED
13715 +       depends on VSERVER_DISABLED
13716         select UIDGID_STRICT_TYPE_CHECKS
13717  
13718         default n
13719 diff -NurpP --minimal linux-3.9.4/init/main.c linux-3.9.4-vs2.3.6.2/init/main.c
13720 --- linux-3.9.4/init/main.c     2013-05-31 13:45:29.000000000 +0000
13721 +++ linux-3.9.4-vs2.3.6.2/init/main.c   2013-05-31 15:09:17.000000000 +0000
13722 @@ -72,6 +72,7 @@
13723  #include <linux/ptrace.h>
13724  #include <linux/blkdev.h>
13725  #include <linux/elevator.h>
13726 +#include <linux/vserver/percpu.h>
13727  
13728  #include <asm/io.h>
13729  #include <asm/bugs.h>
13730 diff -NurpP --minimal linux-3.9.4/ipc/mqueue.c linux-3.9.4-vs2.3.6.2/ipc/mqueue.c
13731 --- linux-3.9.4/ipc/mqueue.c    2013-05-31 13:45:29.000000000 +0000
13732 +++ linux-3.9.4-vs2.3.6.2/ipc/mqueue.c  2013-05-31 14:47:11.000000000 +0000
13733 @@ -35,6 +35,8 @@
13734  #include <linux/ipc_namespace.h>
13735  #include <linux/user_namespace.h>
13736  #include <linux/slab.h>
13737 +#include <linux/vs_context.h>
13738 +#include <linux/vs_limit.h>
13739  
13740  #include <net/sock.h>
13741  #include "util.h"
13742 @@ -76,6 +78,7 @@ struct mqueue_inode_info {
13743         struct pid* notify_owner;
13744         struct user_namespace *notify_user_ns;
13745         struct user_struct *user;       /* user who created, for accounting */
13746 +       struct vx_info *vxi;
13747         struct sock *notify_sock;
13748         struct sk_buff *notify_cookie;
13749  
13750 @@ -234,6 +237,7 @@ static struct inode *mqueue_get_inode(st
13751         if (S_ISREG(mode)) {
13752                 struct mqueue_inode_info *info;
13753                 unsigned long mq_bytes, mq_treesize;
13754 +               struct vx_info *vxi = current_vx_info();
13755  
13756                 inode->i_fop = &mqueue_file_operations;
13757                 inode->i_size = FILENT_SIZE;
13758 @@ -247,6 +251,7 @@ static struct inode *mqueue_get_inode(st
13759                 info->notify_user_ns = NULL;
13760                 info->qsize = 0;
13761                 info->user = NULL;      /* set when all is ok */
13762 +               info->vxi = NULL;
13763                 info->msg_tree = RB_ROOT;
13764                 info->node_cache = NULL;
13765                 memset(&info->attr, 0, sizeof(info->attr));
13766 @@ -280,17 +285,20 @@ static struct inode *mqueue_get_inode(st
13767  
13768                 spin_lock(&mq_lock);
13769                 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
13770 -                   u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE)) {
13771 +                   u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE) ||
13772 +                   !vx_ipcmsg_avail(vxi, mq_bytes)) {
13773                         spin_unlock(&mq_lock);
13774                         /* mqueue_evict_inode() releases info->messages */
13775                         ret = -EMFILE;
13776                         goto out_inode;
13777                 }
13778                 u->mq_bytes += mq_bytes;
13779 +               vx_ipcmsg_add(vxi, u, mq_bytes);
13780                 spin_unlock(&mq_lock);
13781  
13782                 /* all is ok */
13783                 info->user = get_uid(u);
13784 +               info->vxi = get_vx_info(vxi);
13785         } else if (S_ISDIR(mode)) {
13786                 inc_nlink(inode);
13787                 /* Some things misbehave if size == 0 on a directory */
13788 @@ -402,8 +410,11 @@ static void mqueue_evict_inode(struct in
13789  
13790         user = info->user;
13791         if (user) {
13792 +               struct vx_info *vxi = info->vxi;
13793 +
13794                 spin_lock(&mq_lock);
13795                 user->mq_bytes -= mq_bytes;
13796 +               vx_ipcmsg_sub(vxi, user, mq_bytes);
13797                 /*
13798                  * get_ns_from_inode() ensures that the
13799                  * (ipc_ns = sb->s_fs_info) is either a valid ipc_ns
13800 @@ -413,6 +424,7 @@ static void mqueue_evict_inode(struct in
13801                 if (ipc_ns)
13802                         ipc_ns->mq_queues_count--;
13803                 spin_unlock(&mq_lock);
13804 +               put_vx_info(vxi);
13805                 free_uid(user);
13806         }
13807         if (ipc_ns)
13808 diff -NurpP --minimal linux-3.9.4/ipc/msg.c linux-3.9.4-vs2.3.6.2/ipc/msg.c
13809 --- linux-3.9.4/ipc/msg.c       2013-05-31 13:45:29.000000000 +0000
13810 +++ linux-3.9.4-vs2.3.6.2/ipc/msg.c     2013-05-31 14:47:11.000000000 +0000
13811 @@ -37,6 +37,7 @@
13812  #include <linux/rwsem.h>
13813  #include <linux/nsproxy.h>
13814  #include <linux/ipc_namespace.h>
13815 +#include <linux/vs_base.h>
13816  
13817  #include <asm/current.h>
13818  #include <asm/uaccess.h>
13819 @@ -190,6 +191,7 @@ static int newque(struct ipc_namespace *
13820  
13821         msq->q_perm.mode = msgflg & S_IRWXUGO;
13822         msq->q_perm.key = key;
13823 +       msq->q_perm.xid = vx_current_xid();
13824  
13825         msq->q_perm.security = NULL;
13826         retval = security_msg_queue_alloc(msq);
13827 diff -NurpP --minimal linux-3.9.4/ipc/sem.c linux-3.9.4-vs2.3.6.2/ipc/sem.c
13828 --- linux-3.9.4/ipc/sem.c       2012-12-11 03:30:57.000000000 +0000
13829 +++ linux-3.9.4-vs2.3.6.2/ipc/sem.c     2013-05-31 14:47:11.000000000 +0000
13830 @@ -86,6 +86,8 @@
13831  #include <linux/rwsem.h>
13832  #include <linux/nsproxy.h>
13833  #include <linux/ipc_namespace.h>
13834 +#include <linux/vs_base.h>
13835 +#include <linux/vs_limit.h>
13836  
13837  #include <asm/uaccess.h>
13838  #include "util.h"
13839 @@ -306,6 +308,7 @@ static int newary(struct ipc_namespace *
13840  
13841         sma->sem_perm.mode = (semflg & S_IRWXUGO);
13842         sma->sem_perm.key = key;
13843 +       sma->sem_perm.xid = vx_current_xid();
13844  
13845         sma->sem_perm.security = NULL;
13846         retval = security_sem_alloc(sma);
13847 @@ -321,6 +324,9 @@ static int newary(struct ipc_namespace *
13848                 return id;
13849         }
13850         ns->used_sems += nsems;
13851 +       /* FIXME: obsoleted? */
13852 +       vx_semary_inc(sma);
13853 +       vx_nsems_add(sma, nsems);
13854  
13855         sma->sem_base = (struct sem *) &sma[1];
13856  
13857 @@ -770,6 +776,9 @@ static void freeary(struct ipc_namespace
13858  
13859         wake_up_sem_queue_do(&tasks);
13860         ns->used_sems -= sma->sem_nsems;
13861 +       /* FIXME: obsoleted? */
13862 +       vx_nsems_sub(sma, sma->sem_nsems);
13863 +       vx_semary_dec(sma);
13864         security_sem_free(sma);
13865         ipc_rcu_putref(sma);
13866  }
13867 diff -NurpP --minimal linux-3.9.4/ipc/shm.c linux-3.9.4-vs2.3.6.2/ipc/shm.c
13868 --- linux-3.9.4/ipc/shm.c       2013-05-31 14:22:27.000000000 +0000
13869 +++ linux-3.9.4-vs2.3.6.2/ipc/shm.c     2013-05-31 14:47:11.000000000 +0000
13870 @@ -39,6 +39,8 @@
13871  #include <linux/nsproxy.h>
13872  #include <linux/mount.h>
13873  #include <linux/ipc_namespace.h>
13874 +#include <linux/vs_context.h>
13875 +#include <linux/vs_limit.h>
13876  
13877  #include <asm/uaccess.h>
13878  
13879 @@ -187,7 +189,12 @@ static void shm_open(struct vm_area_stru
13880   */
13881  static void shm_destroy(struct ipc_namespace *ns, struct shmid_kernel *shp)
13882  {
13883 -       ns->shm_tot -= (shp->shm_segsz + PAGE_SIZE - 1) >> PAGE_SHIFT;
13884 +       struct vx_info *vxi = lookup_vx_info(shp->shm_perm.xid);
13885 +       int numpages = (shp->shm_segsz + PAGE_SIZE - 1) >> PAGE_SHIFT;
13886 +
13887 +       vx_ipcshm_sub(vxi, shp, numpages);
13888 +       ns->shm_tot -= numpages;
13889 +
13890         shm_rmid(ns, shp);
13891         shm_unlock(shp);
13892         if (!is_file_hugepages(shp->shm_file))
13893 @@ -197,6 +204,7 @@ static void shm_destroy(struct ipc_names
13894                                                 shp->mlock_user);
13895         fput (shp->shm_file);
13896         security_shm_free(shp);
13897 +       put_vx_info(vxi);
13898         ipc_rcu_putref(shp);
13899  }
13900  
13901 @@ -474,11 +482,15 @@ static int newseg(struct ipc_namespace *
13902         if (ns->shm_tot + numpages > ns->shm_ctlall)
13903                 return -ENOSPC;
13904  
13905 +       if (!vx_ipcshm_avail(current_vx_info(), numpages))
13906 +               return -ENOSPC;
13907 +
13908         shp = ipc_rcu_alloc(sizeof(*shp));
13909         if (!shp)
13910                 return -ENOMEM;
13911  
13912         shp->shm_perm.key = key;
13913 +       shp->shm_perm.xid = vx_current_xid();
13914         shp->shm_perm.mode = (shmflg & S_IRWXUGO);
13915         shp->mlock_user = NULL;
13916  
13917 @@ -544,6 +556,7 @@ static int newseg(struct ipc_namespace *
13918         ns->shm_tot += numpages;
13919         error = shp->shm_perm.id;
13920         shm_unlock(shp);
13921 +       vx_ipcshm_add(current_vx_info(), key, numpages);
13922         return error;
13923  
13924  no_id:
13925 diff -NurpP --minimal linux-3.9.4/kernel/Makefile linux-3.9.4-vs2.3.6.2/kernel/Makefile
13926 --- linux-3.9.4/kernel/Makefile 2013-05-31 14:22:27.000000000 +0000
13927 +++ linux-3.9.4-vs2.3.6.2/kernel/Makefile       2013-05-31 14:47:11.000000000 +0000
13928 @@ -24,6 +24,7 @@ endif
13929  
13930  obj-y += sched/
13931  obj-y += power/
13932 +obj-y += vserver/
13933  
13934  obj-$(CONFIG_CHECKPOINT_RESTORE) += kcmp.o
13935  obj-$(CONFIG_FREEZER) += freezer.o
13936 diff -NurpP --minimal linux-3.9.4/kernel/auditsc.c linux-3.9.4-vs2.3.6.2/kernel/auditsc.c
13937 --- linux-3.9.4/kernel/auditsc.c        2013-05-31 14:22:27.000000000 +0000
13938 +++ linux-3.9.4-vs2.3.6.2/kernel/auditsc.c      2013-05-31 14:47:11.000000000 +0000
13939 @@ -2315,7 +2315,7 @@ int audit_set_loginuid(kuid_t loginuid)
13940         if (audit_loginuid_set(task))
13941                 return -EPERM;
13942  #else /* CONFIG_AUDIT_LOGINUID_IMMUTABLE */
13943 -       if (!capable(CAP_AUDIT_CONTROL))
13944 +       if (!vx_capable(CAP_AUDIT_CONTROL, VXC_AUDIT_CONTROL))
13945                 return -EPERM;
13946  #endif  /* CONFIG_AUDIT_LOGINUID_IMMUTABLE */
13947  
13948 diff -NurpP --minimal linux-3.9.4/kernel/capability.c linux-3.9.4-vs2.3.6.2/kernel/capability.c
13949 --- linux-3.9.4/kernel/capability.c     2013-05-31 13:45:29.000000000 +0000
13950 +++ linux-3.9.4-vs2.3.6.2/kernel/capability.c   2013-05-31 14:47:11.000000000 +0000
13951 @@ -15,6 +15,7 @@
13952  #include <linux/syscalls.h>
13953  #include <linux/pid_namespace.h>
13954  #include <linux/user_namespace.h>
13955 +#include <linux/vs_context.h>
13956  #include <asm/uaccess.h>
13957  
13958  /*
13959 @@ -116,6 +117,7 @@ static int cap_validate_magic(cap_user_h
13960         return 0;
13961  }
13962  
13963 +
13964  /*
13965   * The only thing that can change the capabilities of the current
13966   * process is the current process. As such, we can't be in this code
13967 @@ -349,6 +351,8 @@ bool has_ns_capability_noaudit(struct ta
13968         return (ret == 0);
13969  }
13970  
13971 +#include <linux/vserver/base.h>
13972 +
13973  /**
13974   * has_capability_noaudit - Does a task have a capability (unaudited) in the
13975   * initial user ns
13976 diff -NurpP --minimal linux-3.9.4/kernel/compat.c linux-3.9.4-vs2.3.6.2/kernel/compat.c
13977 --- linux-3.9.4/kernel/compat.c 2013-05-31 13:45:29.000000000 +0000
13978 +++ linux-3.9.4-vs2.3.6.2/kernel/compat.c       2013-05-31 14:47:11.000000000 +0000
13979 @@ -27,6 +27,7 @@
13980  #include <linux/times.h>
13981  #include <linux/ptrace.h>
13982  #include <linux/gfp.h>
13983 +#include <linux/vs_time.h>
13984  
13985  #include <asm/uaccess.h>
13986  
13987 @@ -1059,7 +1060,7 @@ asmlinkage long compat_sys_stime(compat_
13988         if (err)
13989                 return err;
13990  
13991 -       do_settimeofday(&tv);
13992 +       vx_settimeofday(&tv);
13993         return 0;
13994  }
13995  
13996 diff -NurpP --minimal linux-3.9.4/kernel/cred.c linux-3.9.4-vs2.3.6.2/kernel/cred.c
13997 --- linux-3.9.4/kernel/cred.c   2013-02-19 13:58:56.000000000 +0000
13998 +++ linux-3.9.4-vs2.3.6.2/kernel/cred.c 2013-05-31 14:47:11.000000000 +0000
13999 @@ -56,31 +56,6 @@ struct cred init_cred = {
14000         .group_info             = &init_groups,
14001  };
14002  
14003 -static inline void set_cred_subscribers(struct cred *cred, int n)
14004 -{
14005 -#ifdef CONFIG_DEBUG_CREDENTIALS
14006 -       atomic_set(&cred->subscribers, n);
14007 -#endif
14008 -}
14009 -
14010 -static inline int read_cred_subscribers(const struct cred *cred)
14011 -{
14012 -#ifdef CONFIG_DEBUG_CREDENTIALS
14013 -       return atomic_read(&cred->subscribers);
14014 -#else
14015 -       return 0;
14016 -#endif
14017 -}
14018 -
14019 -static inline void alter_cred_subscribers(const struct cred *_cred, int n)
14020 -{
14021 -#ifdef CONFIG_DEBUG_CREDENTIALS
14022 -       struct cred *cred = (struct cred *) _cred;
14023 -
14024 -       atomic_add(n, &cred->subscribers);
14025 -#endif
14026 -}
14027 -
14028  /*
14029   * The RCU callback to actually dispose of a set of credentials
14030   */
14031 @@ -232,21 +207,16 @@ error:
14032   *
14033   * Call commit_creds() or abort_creds() to clean up.
14034   */
14035 -struct cred *prepare_creds(void)
14036 +struct cred *__prepare_creds(const struct cred *old)
14037  {
14038 -       struct task_struct *task = current;
14039 -       const struct cred *old;
14040         struct cred *new;
14041  
14042 -       validate_process_creds();
14043 -
14044         new = kmem_cache_alloc(cred_jar, GFP_KERNEL);
14045         if (!new)
14046                 return NULL;
14047  
14048         kdebug("prepare_creds() alloc %p", new);
14049  
14050 -       old = task->cred;
14051         memcpy(new, old, sizeof(struct cred));
14052  
14053         atomic_set(&new->usage, 1);
14054 @@ -275,6 +245,13 @@ error:
14055         abort_creds(new);
14056         return NULL;
14057  }
14058 +
14059 +struct cred *prepare_creds(void)
14060 +{
14061 +       validate_process_creds();
14062 +
14063 +       return __prepare_creds(current->cred);
14064 +}
14065  EXPORT_SYMBOL(prepare_creds);
14066  
14067  /*
14068 diff -NurpP --minimal linux-3.9.4/kernel/exit.c linux-3.9.4-vs2.3.6.2/kernel/exit.c
14069 --- linux-3.9.4/kernel/exit.c   2013-05-31 13:45:29.000000000 +0000
14070 +++ linux-3.9.4-vs2.3.6.2/kernel/exit.c 2013-05-31 14:47:11.000000000 +0000
14071 @@ -48,6 +48,10 @@
14072  #include <linux/fs_struct.h>
14073  #include <linux/init_task.h>
14074  #include <linux/perf_event.h>
14075 +#include <linux/vs_limit.h>
14076 +#include <linux/vs_context.h>
14077 +#include <linux/vs_network.h>
14078 +#include <linux/vs_pid.h>
14079  #include <trace/events/sched.h>
14080  #include <linux/hw_breakpoint.h>
14081  #include <linux/oom.h>
14082 @@ -514,15 +518,25 @@ static struct task_struct *find_new_reap
14083         __acquires(&tasklist_lock)
14084  {
14085         struct pid_namespace *pid_ns = task_active_pid_ns(father);
14086 -       struct task_struct *thread;
14087 +       struct vx_info *vxi = task_get_vx_info(father);
14088 +       struct task_struct *thread = father;
14089 +       struct task_struct *reaper;
14090  
14091 -       thread = father;
14092         while_each_thread(father, thread) {
14093                 if (thread->flags & PF_EXITING)
14094                         continue;
14095                 if (unlikely(pid_ns->child_reaper == father))
14096                         pid_ns->child_reaper = thread;
14097 -               return thread;
14098 +               reaper = thread;
14099 +               goto out_put;
14100 +       }
14101 +
14102 +       reaper = pid_ns->child_reaper;
14103 +       if (vxi) {
14104 +               BUG_ON(!vxi->vx_reaper);
14105 +               if (vxi->vx_reaper != init_pid_ns.child_reaper &&
14106 +                   vxi->vx_reaper != father)
14107 +                       reaper = vxi->vx_reaper;
14108         }
14109  
14110         if (unlikely(pid_ns->child_reaper == father)) {
14111 @@ -560,7 +574,9 @@ static struct task_struct *find_new_reap
14112                 }
14113         }
14114  
14115 -       return pid_ns->child_reaper;
14116 +out_put:
14117 +       put_vx_info(vxi);
14118 +       return reaper;
14119  }
14120  
14121  /*
14122 @@ -611,10 +627,15 @@ static void forget_original_parent(struc
14123         list_for_each_entry_safe(p, n, &father->children, sibling) {
14124                 struct task_struct *t = p;
14125                 do {
14126 -                       t->real_parent = reaper;
14127 +                       struct task_struct *new_parent = reaper;
14128 +
14129 +                       if (unlikely(p == reaper))
14130 +                               new_parent = task_active_pid_ns(p)->child_reaper;
14131 +
14132 +                       t->real_parent = new_parent;
14133                         if (t->parent == father) {
14134                                 BUG_ON(t->ptrace);
14135 -                               t->parent = t->real_parent;
14136 +                               t->parent = new_parent;
14137                         }
14138                         if (t->pdeath_signal)
14139                                 group_send_sig_info(t->pdeath_signal,
14140 @@ -821,6 +842,9 @@ void do_exit(long code)
14141          */
14142         ptrace_put_breakpoints(tsk);
14143  
14144 +       /* needs to stay before exit_notify() */
14145 +       exit_vx_info_early(tsk, code);
14146 +
14147         exit_notify(tsk, group_dead);
14148  #ifdef CONFIG_NUMA
14149         task_lock(tsk);
14150 @@ -874,10 +898,15 @@ void do_exit(long code)
14151         smp_mb();
14152         raw_spin_unlock_wait(&tsk->pi_lock);
14153  
14154 +       /* needs to stay after exit_notify() */
14155 +       exit_vx_info(tsk, code);
14156 +       exit_nx_info(tsk);
14157 +
14158         /* causes final put_task_struct in finish_task_switch(). */
14159         tsk->state = TASK_DEAD;
14160         tsk->flags |= PF_NOFREEZE;      /* tell freezer to ignore us */
14161         schedule();
14162 +       printk("bad task: %p [%lx]\n", current, current->state);
14163         BUG();
14164         /* Avoid "noreturn function does return".  */
14165         for (;;)
14166 diff -NurpP --minimal linux-3.9.4/kernel/fork.c linux-3.9.4-vs2.3.6.2/kernel/fork.c
14167 --- linux-3.9.4/kernel/fork.c   2013-05-31 13:45:29.000000000 +0000
14168 +++ linux-3.9.4-vs2.3.6.2/kernel/fork.c 2013-05-31 14:47:11.000000000 +0000
14169 @@ -70,6 +70,9 @@
14170  #include <linux/khugepaged.h>
14171  #include <linux/signalfd.h>
14172  #include <linux/uprobes.h>
14173 +#include <linux/vs_context.h>
14174 +#include <linux/vs_network.h>
14175 +#include <linux/vs_limit.h>
14176  
14177  #include <asm/pgtable.h>
14178  #include <asm/pgalloc.h>
14179 @@ -210,6 +213,8 @@ void free_task(struct task_struct *tsk)
14180         arch_release_thread_info(tsk->stack);
14181         free_thread_info(tsk->stack);
14182         rt_mutex_debug_task_free(tsk);
14183 +       clr_vx_info(&tsk->vx_info);
14184 +       clr_nx_info(&tsk->nx_info);
14185         ftrace_graph_exit_task(tsk);
14186         put_seccomp_filter(tsk);
14187         arch_release_task_struct(tsk);
14188 @@ -547,6 +552,7 @@ static struct mm_struct *mm_init(struct
14189         if (likely(!mm_alloc_pgd(mm))) {
14190                 mm->def_flags = 0;
14191                 mmu_notifier_mm_init(mm);
14192 +               set_vx_info(&mm->mm_vx_info, p->vx_info);
14193                 return mm;
14194         }
14195  
14196 @@ -599,6 +605,7 @@ void __mmdrop(struct mm_struct *mm)
14197         destroy_context(mm);
14198         mmu_notifier_mm_destroy(mm);
14199         check_mm(mm);
14200 +       clr_vx_info(&mm->mm_vx_info);
14201         free_mm(mm);
14202  }
14203  EXPORT_SYMBOL_GPL(__mmdrop);
14204 @@ -818,6 +825,7 @@ struct mm_struct *dup_mm(struct task_str
14205                 goto fail_nomem;
14206  
14207         memcpy(mm, oldmm, sizeof(*mm));
14208 +       mm->mm_vx_info = NULL;
14209         mm_init_cpumask(mm);
14210  
14211  #ifdef CONFIG_TRANSPARENT_HUGEPAGE
14212 @@ -859,6 +867,7 @@ fail_nocontext:
14213          * If init_new_context() failed, we cannot use mmput() to free the mm
14214          * because it calls destroy_context()
14215          */
14216 +       clr_vx_info(&mm->mm_vx_info);
14217         mm_free_pgd(mm);
14218         free_mm(mm);
14219         return NULL;
14220 @@ -1137,6 +1146,8 @@ static struct task_struct *copy_process(
14221  {
14222         int retval;
14223         struct task_struct *p;
14224 +       struct vx_info *vxi;
14225 +       struct nx_info *nxi;
14226  
14227         if ((clone_flags & (CLONE_NEWNS|CLONE_FS)) == (CLONE_NEWNS|CLONE_FS))
14228                 return ERR_PTR(-EINVAL);
14229 @@ -1195,7 +1206,12 @@ static struct task_struct *copy_process(
14230         DEBUG_LOCKS_WARN_ON(!p->hardirqs_enabled);
14231         DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
14232  #endif
14233 +       init_vx_info(&p->vx_info, current_vx_info());
14234 +       init_nx_info(&p->nx_info, current_nx_info());
14235 +
14236         retval = -EAGAIN;
14237 +       if (!vx_nproc_avail(1))
14238 +               goto bad_fork_free;
14239         if (atomic_read(&p->real_cred->user->processes) >=
14240                         task_rlimit(p, RLIMIT_NPROC)) {
14241                 if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE) &&
14242 @@ -1472,6 +1488,18 @@ static struct task_struct *copy_process(
14243  
14244         total_forks++;
14245         spin_unlock(&current->sighand->siglock);
14246 +
14247 +       /* p is copy of current */
14248 +       vxi = p->vx_info;
14249 +       if (vxi) {
14250 +               claim_vx_info(vxi, p);
14251 +               atomic_inc(&vxi->cvirt.nr_threads);
14252 +               atomic_inc(&vxi->cvirt.total_forks);
14253 +               vx_nproc_inc(p);
14254 +       }
14255 +       nxi = p->nx_info;
14256 +       if (nxi)
14257 +               claim_nx_info(nxi, p);
14258         write_unlock_irq(&tasklist_lock);
14259         proc_fork_connector(p);
14260         cgroup_post_fork(p);
14261 diff -NurpP --minimal linux-3.9.4/kernel/kthread.c linux-3.9.4-vs2.3.6.2/kernel/kthread.c
14262 --- linux-3.9.4/kernel/kthread.c        2013-05-31 13:45:30.000000000 +0000
14263 +++ linux-3.9.4-vs2.3.6.2/kernel/kthread.c      2013-05-31 14:47:11.000000000 +0000
14264 @@ -17,6 +17,7 @@
14265  #include <linux/slab.h>
14266  #include <linux/freezer.h>
14267  #include <linux/ptrace.h>
14268 +#include <linux/vs_pid.h>
14269  #include <trace/events/sched.h>
14270  
14271  static DEFINE_SPINLOCK(kthread_create_lock);
14272 diff -NurpP --minimal linux-3.9.4/kernel/nsproxy.c linux-3.9.4-vs2.3.6.2/kernel/nsproxy.c
14273 --- linux-3.9.4/kernel/nsproxy.c        2013-05-31 13:45:30.000000000 +0000
14274 +++ linux-3.9.4-vs2.3.6.2/kernel/nsproxy.c      2013-05-31 19:28:43.000000000 +0000
14275 @@ -20,11 +20,14 @@
14276  #include <linux/mnt_namespace.h>
14277  #include <linux/utsname.h>
14278  #include <linux/pid_namespace.h>
14279 +#include <linux/vserver/global.h>
14280 +#include <linux/vserver/debug.h>
14281  #include <net/net_namespace.h>
14282  #include <linux/ipc_namespace.h>
14283  #include <linux/proc_fs.h>
14284  #include <linux/file.h>
14285  #include <linux/syscalls.h>
14286 +#include "../fs/mount.h"
14287  
14288  static struct kmem_cache *nsproxy_cachep;
14289  
14290 @@ -46,8 +49,11 @@ static inline struct nsproxy *create_nsp
14291         struct nsproxy *nsproxy;
14292  
14293         nsproxy = kmem_cache_alloc(nsproxy_cachep, GFP_KERNEL);
14294 -       if (nsproxy)
14295 +       if (nsproxy) {
14296                 atomic_set(&nsproxy->count, 1);
14297 +               atomic_inc(&vs_global_nsproxy);
14298 +       }
14299 +       vxdprintk(VXD_CBIT(space, 2), "create_nsproxy = %p[1]", nsproxy);
14300         return nsproxy;
14301  }
14302  
14303 @@ -56,9 +62,12 @@ static inline struct nsproxy *create_nsp
14304   * Return the newly created nsproxy.  Do not attach this to the task,
14305   * leave it to the caller to do proper locking and attach it to task.
14306   */
14307 -static struct nsproxy *create_new_namespaces(unsigned long flags,
14308 -       struct task_struct *tsk, struct user_namespace *user_ns,
14309 -       struct fs_struct *new_fs)
14310 +static struct nsproxy *unshare_namespaces(
14311 +       unsigned long flags,
14312 +       struct nsproxy *orig,
14313 +       struct fs_struct *new_fs,
14314 +       struct user_namespace *new_user,
14315 +       struct pid_namespace *new_pid)
14316  {
14317         struct nsproxy *new_nsp;
14318         int err;
14319 @@ -67,31 +76,31 @@ static struct nsproxy *create_new_namesp
14320         if (!new_nsp)
14321                 return ERR_PTR(-ENOMEM);
14322  
14323 -       new_nsp->mnt_ns = copy_mnt_ns(flags, tsk->nsproxy->mnt_ns, user_ns, new_fs);
14324 +       new_nsp->mnt_ns = copy_mnt_ns(flags, orig->mnt_ns, new_user, new_fs);
14325         if (IS_ERR(new_nsp->mnt_ns)) {
14326                 err = PTR_ERR(new_nsp->mnt_ns);
14327                 goto out_ns;
14328         }
14329  
14330 -       new_nsp->uts_ns = copy_utsname(flags, user_ns, tsk->nsproxy->uts_ns);
14331 +       new_nsp->uts_ns = copy_utsname(flags, new_user, orig->uts_ns);
14332         if (IS_ERR(new_nsp->uts_ns)) {
14333                 err = PTR_ERR(new_nsp->uts_ns);
14334                 goto out_uts;
14335         }
14336  
14337 -       new_nsp->ipc_ns = copy_ipcs(flags, user_ns, tsk->nsproxy->ipc_ns);
14338 +       new_nsp->ipc_ns = copy_ipcs(flags, new_user, orig->ipc_ns);
14339         if (IS_ERR(new_nsp->ipc_ns)) {
14340                 err = PTR_ERR(new_nsp->ipc_ns);
14341                 goto out_ipc;
14342         }
14343  
14344 -       new_nsp->pid_ns = copy_pid_ns(flags, user_ns, tsk->nsproxy->pid_ns);
14345 +       new_nsp->pid_ns = copy_pid_ns(flags, new_user, new_pid);
14346         if (IS_ERR(new_nsp->pid_ns)) {
14347                 err = PTR_ERR(new_nsp->pid_ns);
14348                 goto out_pid;
14349         }
14350  
14351 -       new_nsp->net_ns = copy_net_ns(flags, user_ns, tsk->nsproxy->net_ns);
14352 +       new_nsp->net_ns = copy_net_ns(flags, new_user, orig->net_ns);
14353         if (IS_ERR(new_nsp->net_ns)) {
14354                 err = PTR_ERR(new_nsp->net_ns);
14355                 goto out_net;
14356 @@ -116,6 +125,41 @@ out_ns:
14357         return ERR_PTR(err);
14358  }
14359  
14360 +static struct nsproxy *create_new_namespaces(unsigned long flags,
14361 +       struct task_struct *tsk, struct user_namespace *user_ns,
14362 +       struct fs_struct *new_fs)
14363 +
14364 +{
14365 +       return unshare_namespaces(flags, tsk->nsproxy,
14366 +               new_fs, user_ns, task_active_pid_ns(tsk));
14367 +}
14368 +
14369 +/*
14370 + * copies the nsproxy, setting refcount to 1, and grabbing a
14371 + * reference to all contained namespaces.
14372 + */
14373 +struct nsproxy *copy_nsproxy(struct nsproxy *orig)
14374 +{
14375 +       struct nsproxy *ns = create_nsproxy();
14376 +
14377 +       if (ns) {
14378 +               memcpy(ns, orig, sizeof(struct nsproxy));
14379 +               atomic_set(&ns->count, 1);
14380 +
14381 +               if (ns->mnt_ns)
14382 +                       get_mnt_ns(ns->mnt_ns);
14383 +               if (ns->uts_ns)
14384 +                       get_uts_ns(ns->uts_ns);
14385 +               if (ns->ipc_ns)
14386 +                       get_ipc_ns(ns->ipc_ns);
14387 +               if (ns->pid_ns)
14388 +                       get_pid_ns(ns->pid_ns);
14389 +               if (ns->net_ns)
14390 +                       get_net(ns->net_ns);
14391 +       }
14392 +       return ns;
14393 +}
14394 +
14395  /*
14396   * called from clone.  This now handles copy for nsproxy and all
14397   * namespaces therein.
14398 @@ -124,9 +168,12 @@ int copy_namespaces(unsigned long flags,
14399  {
14400         struct nsproxy *old_ns = tsk->nsproxy;
14401         struct user_namespace *user_ns = task_cred_xxx(tsk, user_ns);
14402 -       struct nsproxy *new_ns;
14403 +       struct nsproxy *new_ns = NULL;
14404         int err = 0;
14405  
14406 +       vxdprintk(VXD_CBIT(space, 7), "copy_namespaces(0x%08lx,%p[%p])",
14407 +               flags, tsk, old_ns);
14408 +
14409         if (!old_ns)
14410                 return 0;
14411  
14412 @@ -136,7 +183,7 @@ int copy_namespaces(unsigned long flags,
14413                                 CLONE_NEWPID | CLONE_NEWNET)))
14414                 return 0;
14415  
14416 -       if (!ns_capable(user_ns, CAP_SYS_ADMIN)) {
14417 +       if (!vx_ns_can_unshare(user_ns, CAP_SYS_ADMIN, flags)) {
14418                 err = -EPERM;
14419                 goto out;
14420         }
14421 @@ -163,6 +210,9 @@ int copy_namespaces(unsigned long flags,
14422  
14423  out:
14424         put_nsproxy(old_ns);
14425 +       vxdprintk(VXD_CBIT(space, 3),
14426 +               "copy_namespaces(0x%08lx,%p[%p]) = %d [%p]",
14427 +               flags, tsk, old_ns, err, new_ns);
14428         return err;
14429  }
14430  
14431 @@ -176,7 +226,9 @@ void free_nsproxy(struct nsproxy *ns)
14432                 put_ipc_ns(ns->ipc_ns);
14433         if (ns->pid_ns)
14434                 put_pid_ns(ns->pid_ns);
14435 -       put_net(ns->net_ns);
14436 +       if (ns->net_ns)
14437 +               put_net(ns->net_ns);
14438 +       atomic_dec(&vs_global_nsproxy);
14439         kmem_cache_free(nsproxy_cachep, ns);
14440  }
14441  
14442 @@ -190,12 +242,16 @@ int unshare_nsproxy_namespaces(unsigned
14443         struct user_namespace *user_ns;
14444         int err = 0;
14445  
14446 +       vxdprintk(VXD_CBIT(space, 4),
14447 +               "unshare_nsproxy_namespaces(0x%08lx,[%p])",
14448 +               unshare_flags, current->nsproxy);
14449 +
14450         if (!(unshare_flags & (CLONE_NEWNS | CLONE_NEWUTS | CLONE_NEWIPC |
14451                                CLONE_NEWNET | CLONE_NEWPID)))
14452                 return 0;
14453  
14454         user_ns = new_cred ? new_cred->user_ns : current_user_ns();
14455 -       if (!ns_capable(user_ns, CAP_SYS_ADMIN))
14456 +       if (!vx_ns_can_unshare(user_ns, CAP_SYS_ADMIN, unshare_flags))
14457                 return -EPERM;
14458  
14459         *new_nsp = create_new_namespaces(unshare_flags, current, user_ns,
14460 diff -NurpP --minimal linux-3.9.4/kernel/pid.c linux-3.9.4-vs2.3.6.2/kernel/pid.c
14461 --- linux-3.9.4/kernel/pid.c    2013-05-31 13:45:30.000000000 +0000
14462 +++ linux-3.9.4-vs2.3.6.2/kernel/pid.c  2013-05-31 15:24:34.000000000 +0000
14463 @@ -37,6 +37,7 @@
14464  #include <linux/init_task.h>
14465  #include <linux/syscalls.h>
14466  #include <linux/proc_fs.h>
14467 +#include <linux/vs_pid.h>
14468  
14469  #define pid_hashfn(nr, ns)     \
14470         hash_long((unsigned long)nr + (unsigned long)ns, pidhash_shift)
14471 @@ -364,7 +365,7 @@ EXPORT_SYMBOL_GPL(find_pid_ns);
14472  
14473  struct pid *find_vpid(int nr)
14474  {
14475 -       return find_pid_ns(nr, task_active_pid_ns(current));
14476 +       return find_pid_ns(vx_rmap_pid(nr), task_active_pid_ns(current));
14477  }
14478  EXPORT_SYMBOL_GPL(find_vpid);
14479  
14480 @@ -424,6 +425,9 @@ void transfer_pid(struct task_struct *ol
14481  struct task_struct *pid_task(struct pid *pid, enum pid_type type)
14482  {
14483         struct task_struct *result = NULL;
14484 +
14485 +       if (type == PIDTYPE_REALPID)
14486 +               type = PIDTYPE_PID;
14487         if (pid) {
14488                 struct hlist_node *first;
14489                 first = rcu_dereference_check(hlist_first_rcu(&pid->tasks[type]),
14490 @@ -443,7 +447,7 @@ struct task_struct *find_task_by_pid_ns(
14491         rcu_lockdep_assert(rcu_read_lock_held(),
14492                            "find_task_by_pid_ns() needs rcu_read_lock()"
14493                            " protection");
14494 -       return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
14495 +       return pid_task(find_pid_ns(vx_rmap_pid(nr), ns), PIDTYPE_PID);
14496  }
14497  
14498  struct task_struct *find_task_by_vpid(pid_t vnr)
14499 @@ -487,7 +491,7 @@ struct pid *find_get_pid(pid_t nr)
14500  }
14501  EXPORT_SYMBOL_GPL(find_get_pid);
14502  
14503 -pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns)
14504 +pid_t pid_unmapped_nr_ns(struct pid *pid, struct pid_namespace *ns)
14505  {
14506         struct upid *upid;
14507         pid_t nr = 0;
14508 @@ -501,6 +505,11 @@ pid_t pid_nr_ns(struct pid *pid, struct
14509  }
14510  EXPORT_SYMBOL_GPL(pid_nr_ns);
14511  
14512 +pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns)
14513 +{
14514 +       return vx_map_pid(pid_unmapped_nr_ns(pid, ns));
14515 +}
14516 +
14517  pid_t pid_vnr(struct pid *pid)
14518  {
14519         return pid_nr_ns(pid, task_active_pid_ns(current));
14520 diff -NurpP --minimal linux-3.9.4/kernel/pid_namespace.c linux-3.9.4-vs2.3.6.2/kernel/pid_namespace.c
14521 --- linux-3.9.4/kernel/pid_namespace.c  2013-05-31 13:45:30.000000000 +0000
14522 +++ linux-3.9.4-vs2.3.6.2/kernel/pid_namespace.c        2013-05-31 17:59:48.000000000 +0000
14523 @@ -18,6 +18,7 @@
14524  #include <linux/proc_fs.h>
14525  #include <linux/reboot.h>
14526  #include <linux/export.h>
14527 +#include <linux/vserver/global.h>
14528  
14529  #define BITS_PER_PAGE          (PAGE_SIZE*8)
14530  
14531 @@ -112,6 +113,7 @@ static struct pid_namespace *create_pid_
14532                 goto out_free_map;
14533  
14534         kref_init(&ns->kref);
14535 +       atomic_inc(&vs_global_pid_ns);
14536         ns->level = level;
14537         ns->parent = get_pid_ns(parent_pid_ns);
14538         ns->user_ns = get_user_ns(user_ns);
14539 @@ -142,6 +144,7 @@ static void destroy_pid_namespace(struct
14540         for (i = 0; i < PIDMAP_ENTRIES; i++)
14541                 kfree(ns->pidmap[i].page);
14542         put_user_ns(ns->user_ns);
14543 +       atomic_dec(&vs_global_pid_ns);
14544         kmem_cache_free(pid_ns_cachep, ns);
14545  }
14546  
14547 diff -NurpP --minimal linux-3.9.4/kernel/posix-timers.c linux-3.9.4-vs2.3.6.2/kernel/posix-timers.c
14548 --- linux-3.9.4/kernel/posix-timers.c   2013-05-31 13:45:30.000000000 +0000
14549 +++ linux-3.9.4-vs2.3.6.2/kernel/posix-timers.c 2013-05-31 14:47:11.000000000 +0000
14550 @@ -47,6 +47,7 @@
14551  #include <linux/wait.h>
14552  #include <linux/workqueue.h>
14553  #include <linux/export.h>
14554 +#include <linux/vs_context.h>
14555  
14556  /*
14557   * Management arrays for POSIX timers.  Timers are kept in slab memory
14558 @@ -340,6 +341,7 @@ int posix_timer_event(struct k_itimer *t
14559  {
14560         struct task_struct *task;
14561         int shared, ret = -1;
14562 +
14563         /*
14564          * FIXME: if ->sigq is queued we can race with
14565          * dequeue_signal()->do_schedule_next_timer().
14566 @@ -356,10 +358,18 @@ int posix_timer_event(struct k_itimer *t
14567         rcu_read_lock();
14568         task = pid_task(timr->it_pid, PIDTYPE_PID);
14569         if (task) {
14570 +               struct vx_info_save vxis;
14571 +               struct vx_info *vxi;
14572 +
14573 +               vxi = get_vx_info(task->vx_info);
14574 +               enter_vx_info(vxi, &vxis);
14575                 shared = !(timr->it_sigev_notify & SIGEV_THREAD_ID);
14576                 ret = send_sigqueue(timr->sigq, task, shared);
14577 +               leave_vx_info(&vxis);
14578 +               put_vx_info(vxi);
14579         }
14580         rcu_read_unlock();
14581 +
14582         /* If we failed to send the signal the timer stops. */
14583         return ret > 0;
14584  }
14585 diff -NurpP --minimal linux-3.9.4/kernel/printk.c linux-3.9.4-vs2.3.6.2/kernel/printk.c
14586 --- linux-3.9.4/kernel/printk.c 2013-05-31 13:45:30.000000000 +0000
14587 +++ linux-3.9.4-vs2.3.6.2/kernel/printk.c       2013-05-31 15:23:35.000000000 +0000
14588 @@ -43,6 +43,7 @@
14589  #include <linux/rculist.h>
14590  #include <linux/poll.h>
14591  #include <linux/irq_work.h>
14592 +#include <linux/vs_cvirt.h>
14593  
14594  #include <asm/uaccess.h>
14595  
14596 @@ -841,7 +842,7 @@ static int check_syslog_permissions(int
14597                 return 0;
14598  
14599         if (syslog_action_restricted(type)) {
14600 -               if (capable(CAP_SYSLOG))
14601 +               if (vx_capable(CAP_SYSLOG, VXC_SYSLOG))
14602                         return 0;
14603                 /* For historical reasons, accept CAP_SYS_ADMIN too, with a warning */
14604                 if (capable(CAP_SYS_ADMIN)) {
14605 @@ -1135,12 +1136,9 @@ int do_syslog(int type, char __user *buf
14606         if (error)
14607                 return error;
14608  
14609 -       switch (type) {
14610 -       case SYSLOG_ACTION_CLOSE:       /* Close log */
14611 -               break;
14612 -       case SYSLOG_ACTION_OPEN:        /* Open log */
14613 -               break;
14614 -       case SYSLOG_ACTION_READ:        /* Read from log */
14615 +       if ((type == SYSLOG_ACTION_READ) ||
14616 +           (type == SYSLOG_ACTION_READ_ALL) ||
14617 +           (type == SYSLOG_ACTION_READ_CLEAR)) {
14618                 error = -EINVAL;
14619                 if (!buf || len < 0)
14620                         goto out;
14621 @@ -1151,6 +1149,16 @@ int do_syslog(int type, char __user *buf
14622                         error = -EFAULT;
14623                         goto out;
14624                 }
14625 +       }
14626 +       if (!vx_check(0, VS_ADMIN|VS_WATCH))
14627 +               return vx_do_syslog(type, buf, len);
14628 +
14629 +       switch (type) {
14630 +       case SYSLOG_ACTION_CLOSE:       /* Close log */
14631 +               break;
14632 +       case SYSLOG_ACTION_OPEN:        /* Open log */
14633 +               break;
14634 +       case SYSLOG_ACTION_READ:        /* Read from log */
14635                 error = wait_event_interruptible(log_wait,
14636                                                  syslog_seq != log_next_seq);
14637                 if (error)
14638 @@ -1163,16 +1171,6 @@ int do_syslog(int type, char __user *buf
14639                 /* FALL THRU */
14640         /* Read last kernel messages */
14641         case SYSLOG_ACTION_READ_ALL:
14642 -               error = -EINVAL;
14643 -               if (!buf || len < 0)
14644 -                       goto out;
14645 -               error = 0;
14646 -               if (!len)
14647 -                       goto out;
14648 -               if (!access_ok(VERIFY_WRITE, buf, len)) {
14649 -                       error = -EFAULT;
14650 -                       goto out;
14651 -               }
14652                 error = syslog_print_all(buf, len, clear);
14653                 break;
14654         /* Clear ring buffer */
14655 diff -NurpP --minimal linux-3.9.4/kernel/ptrace.c linux-3.9.4-vs2.3.6.2/kernel/ptrace.c
14656 --- linux-3.9.4/kernel/ptrace.c 2013-05-31 13:45:30.000000000 +0000
14657 +++ linux-3.9.4-vs2.3.6.2/kernel/ptrace.c       2013-05-31 15:22:34.000000000 +0000
14658 @@ -22,6 +22,7 @@
14659  #include <linux/syscalls.h>
14660  #include <linux/uaccess.h>
14661  #include <linux/regset.h>
14662 +#include <linux/vs_context.h>
14663  #include <linux/hw_breakpoint.h>
14664  #include <linux/cn_proc.h>
14665  
14666 @@ -261,6 +262,11 @@ ok:
14667         }
14668         rcu_read_unlock();
14669  
14670 +       if (!vx_check(task->xid, VS_ADMIN_P|VS_WATCH_P|VS_IDENT))
14671 +               return -EPERM;
14672 +       if (!vx_check(task->xid, VS_IDENT) &&
14673 +               !task_vx_flags(task, VXF_STATE_ADMIN, 0))
14674 +               return -EACCES;
14675         return security_ptrace_access_check(task, mode);
14676  }
14677  
14678 diff -NurpP --minimal linux-3.9.4/kernel/sched/core.c linux-3.9.4-vs2.3.6.2/kernel/sched/core.c
14679 --- linux-3.9.4/kernel/sched/core.c     2013-05-31 13:45:30.000000000 +0000
14680 +++ linux-3.9.4-vs2.3.6.2/kernel/sched/core.c   2013-05-31 15:17:22.000000000 +0000
14681 @@ -73,6 +73,8 @@
14682  #include <linux/init_task.h>
14683  #include <linux/binfmts.h>
14684  #include <linux/context_tracking.h>
14685 +#include <linux/vs_sched.h>
14686 +#include <linux/vs_cvirt.h>
14687  
14688  #include <asm/switch_to.h>
14689  #include <asm/tlb.h>
14690 @@ -2091,9 +2093,17 @@ EXPORT_SYMBOL(avenrun); /* should be rem
14691   */
14692  void get_avenrun(unsigned long *loads, unsigned long offset, int shift)
14693  {
14694 -       loads[0] = (avenrun[0] + offset) << shift;
14695 -       loads[1] = (avenrun[1] + offset) << shift;
14696 -       loads[2] = (avenrun[2] + offset) << shift;
14697 +       if (vx_flags(VXF_VIRT_LOAD, 0)) {
14698 +               struct vx_info *vxi = current_vx_info();
14699 +
14700 +               loads[0] = (vxi->cvirt.load[0] + offset) << shift;
14701 +               loads[1] = (vxi->cvirt.load[1] + offset) << shift;
14702 +               loads[2] = (vxi->cvirt.load[2] + offset) << shift;
14703 +       } else {
14704 +               loads[0] = (avenrun[0] + offset) << shift;
14705 +               loads[1] = (avenrun[1] + offset) << shift;
14706 +               loads[2] = (avenrun[2] + offset) << shift;
14707 +       }
14708  }
14709  
14710  static long calc_load_fold_active(struct rq *this_rq)
14711 @@ -3704,7 +3714,7 @@ SYSCALL_DEFINE1(nice, int, increment)
14712                 nice = 19;
14713  
14714         if (increment < 0 && !can_nice(current, nice))
14715 -               return -EPERM;
14716 +               return vx_flags(VXF_IGNEG_NICE, 0) ? 0 : -EPERM;
14717  
14718         retval = security_task_setnice(current, nice);
14719         if (retval)
14720 diff -NurpP --minimal linux-3.9.4/kernel/sched/cputime.c linux-3.9.4-vs2.3.6.2/kernel/sched/cputime.c
14721 --- linux-3.9.4/kernel/sched/cputime.c  2013-05-31 14:22:27.000000000 +0000
14722 +++ linux-3.9.4-vs2.3.6.2/kernel/sched/cputime.c        2013-05-31 15:17:55.000000000 +0000
14723 @@ -4,6 +4,7 @@
14724  #include <linux/kernel_stat.h>
14725  #include <linux/static_key.h>
14726  #include <linux/context_tracking.h>
14727 +#include <linux/vs_sched.h>
14728  #include "sched.h"
14729  
14730  
14731 @@ -151,14 +152,17 @@ static inline void task_group_account_fi
14732  void account_user_time(struct task_struct *p, cputime_t cputime,
14733                        cputime_t cputime_scaled)
14734  {
14735 +       struct vx_info *vxi = p->vx_info;  /* p is _always_ current */
14736 +       int nice = (TASK_NICE(p) > 0);
14737         int index;
14738  
14739         /* Add user time to process. */
14740         p->utime += cputime;
14741         p->utimescaled += cputime_scaled;
14742 +       vx_account_user(vxi, cputime, nice);
14743         account_group_user_time(p, cputime);
14744  
14745 -       index = (TASK_NICE(p) > 0) ? CPUTIME_NICE : CPUTIME_USER;
14746 +       index = (nice) ? CPUTIME_NICE : CPUTIME_USER;
14747  
14748         /* Add user time to cpustat. */
14749         task_group_account_field(p, index, (__force u64) cputime);
14750 @@ -205,9 +209,12 @@ static inline
14751  void __account_system_time(struct task_struct *p, cputime_t cputime,
14752                         cputime_t cputime_scaled, int index)
14753  {
14754 +       struct vx_info *vxi = p->vx_info;  /* p is _always_ current */
14755 +
14756         /* Add system time to process. */
14757         p->stime += cputime;
14758         p->stimescaled += cputime_scaled;
14759 +       vx_account_system(vxi, cputime, 0 /* do we have idle time? */);
14760         account_group_system_time(p, cputime);
14761  
14762         /* Add system time to cpustat. */
14763 diff -NurpP --minimal linux-3.9.4/kernel/sched/fair.c linux-3.9.4-vs2.3.6.2/kernel/sched/fair.c
14764 --- linux-3.9.4/kernel/sched/fair.c     2013-05-31 13:45:30.000000000 +0000
14765 +++ linux-3.9.4-vs2.3.6.2/kernel/sched/fair.c   2013-05-31 15:19:37.000000000 +0000
14766 @@ -29,6 +29,7 @@
14767  #include <linux/mempolicy.h>
14768  #include <linux/migrate.h>
14769  #include <linux/task_work.h>
14770 +#include <linux/vs_cvirt.h>
14771  
14772  #include <trace/events/sched.h>
14773  
14774 @@ -1714,6 +1715,8 @@ enqueue_entity(struct cfs_rq *cfs_rq, st
14775                 __enqueue_entity(cfs_rq, se);
14776         se->on_rq = 1;
14777  
14778 +       if (entity_is_task(se))
14779 +               vx_activate_task(task_of(se));
14780         if (cfs_rq->nr_running == 1) {
14781                 list_add_leaf_cfs_rq(cfs_rq);
14782                 check_enqueue_throttle(cfs_rq);
14783 @@ -1795,6 +1798,8 @@ dequeue_entity(struct cfs_rq *cfs_rq, st
14784         if (se != cfs_rq->curr)
14785                 __dequeue_entity(cfs_rq, se);
14786         se->on_rq = 0;
14787 +       if (entity_is_task(se))
14788 +               vx_deactivate_task(task_of(se));
14789         account_entity_dequeue(cfs_rq, se);
14790  
14791         /*
14792 diff -NurpP --minimal linux-3.9.4/kernel/signal.c linux-3.9.4-vs2.3.6.2/kernel/signal.c
14793 --- linux-3.9.4/kernel/signal.c 2013-05-31 13:45:30.000000000 +0000
14794 +++ linux-3.9.4-vs2.3.6.2/kernel/signal.c       2013-05-31 15:20:05.000000000 +0000
14795 @@ -32,6 +32,8 @@
14796  #include <linux/user_namespace.h>
14797  #include <linux/uprobes.h>
14798  #include <linux/compat.h>
14799 +#include <linux/vs_context.h>
14800 +#include <linux/vs_pid.h>
14801  #define CREATE_TRACE_POINTS
14802  #include <trace/events/signal.h>
14803  
14804 @@ -789,9 +791,18 @@ static int check_kill_permission(int sig
14805         struct pid *sid;
14806         int error;
14807  
14808 +       vxdprintk(VXD_CBIT(misc, 7),
14809 +               "check_kill_permission(%d,%p,%p[#%u,%u])",
14810 +               sig, info, t, vx_task_xid(t), t->pid);
14811 +
14812         if (!valid_signal(sig))
14813                 return -EINVAL;
14814  
14815 +/*     FIXME: needed? if so, why?
14816 +       if ((info != SEND_SIG_NOINFO) &&
14817 +               (is_si_special(info) || !si_fromuser(info)))
14818 +               goto skip;      */
14819 +
14820         if (!si_fromuser(info))
14821                 return 0;
14822  
14823 @@ -815,6 +826,20 @@ static int check_kill_permission(int sig
14824                 }
14825         }
14826  
14827 +       error = -EPERM;
14828 +       if (t->pid == 1 && current->xid)
14829 +               return error;
14830 +
14831 +       error = -ESRCH;
14832 +       /* FIXME: we shouldn't return ESRCH ever, to avoid
14833 +                 loops, maybe ENOENT or EACCES? */
14834 +       if (!vx_check(vx_task_xid(t), VS_WATCH_P | VS_IDENT)) {
14835 +               vxdprintk(current->xid || VXD_CBIT(misc, 7),
14836 +                       "signal %d[%p] xid mismatch %p[#%u,%u] xid=#%u",
14837 +                       sig, info, t, vx_task_xid(t), t->pid, current->xid);
14838 +               return error;
14839 +       }
14840 +/* skip: */
14841         return security_task_kill(t, info, sig, 0);
14842  }
14843  
14844 @@ -1351,7 +1376,7 @@ int kill_pid_info(int sig, struct siginf
14845         rcu_read_lock();
14846  retry:
14847         p = pid_task(pid, PIDTYPE_PID);
14848 -       if (p) {
14849 +       if (p && vx_check(vx_task_xid(p), VS_IDENT)) {
14850                 error = group_send_sig_info(sig, info, p);
14851                 if (unlikely(error == -ESRCH))
14852                         /*
14853 @@ -1399,7 +1424,7 @@ int kill_pid_info_as_cred(int sig, struc
14854  
14855         rcu_read_lock();
14856         p = pid_task(pid, PIDTYPE_PID);
14857 -       if (!p) {
14858 +       if (!p || !vx_check(vx_task_xid(p), VS_IDENT)) {
14859                 ret = -ESRCH;
14860                 goto out_unlock;
14861         }
14862 @@ -1451,8 +1476,10 @@ static int kill_something_info(int sig,
14863                 struct task_struct * p;
14864  
14865                 for_each_process(p) {
14866 -                       if (task_pid_vnr(p) > 1 &&
14867 -                                       !same_thread_group(p, current)) {
14868 +                       if (vx_check(vx_task_xid(p), VS_ADMIN|VS_IDENT) &&
14869 +                               task_pid_vnr(p) > 1 &&
14870 +                               !same_thread_group(p, current) &&
14871 +                               !vx_current_initpid(p->pid)) {
14872                                 int err = group_send_sig_info(sig, info, p);
14873                                 ++count;
14874                                 if (err != -EPERM)
14875 @@ -2306,6 +2333,11 @@ relock:
14876                                 !sig_kernel_only(signr))
14877                         continue;
14878  
14879 +               /* virtual init is protected against user signals */
14880 +               if ((info->si_code == SI_USER) &&
14881 +                       vx_current_initpid(current->pid))
14882 +                       continue;
14883 +
14884                 if (sig_kernel_stop(signr)) {
14885                         /*
14886                          * The default action is to stop all threads in
14887 diff -NurpP --minimal linux-3.9.4/kernel/softirq.c linux-3.9.4-vs2.3.6.2/kernel/softirq.c
14888 --- linux-3.9.4/kernel/softirq.c        2013-05-31 13:45:30.000000000 +0000
14889 +++ linux-3.9.4-vs2.3.6.2/kernel/softirq.c      2013-05-31 14:47:11.000000000 +0000
14890 @@ -25,6 +25,7 @@
14891  #include <linux/smp.h>
14892  #include <linux/smpboot.h>
14893  #include <linux/tick.h>
14894 +#include <linux/vs_context.h>
14895  
14896  #define CREATE_TRACE_POINTS
14897  #include <trace/events/irq.h>
14898 diff -NurpP --minimal linux-3.9.4/kernel/sys.c linux-3.9.4-vs2.3.6.2/kernel/sys.c
14899 --- linux-3.9.4/kernel/sys.c    2013-05-31 13:45:30.000000000 +0000
14900 +++ linux-3.9.4-vs2.3.6.2/kernel/sys.c  2013-05-31 15:23:14.000000000 +0000
14901 @@ -50,6 +50,7 @@
14902  #include <linux/binfmts.h>
14903  
14904  #include <linux/kmsg_dump.h>
14905 +#include <linux/vs_pid.h>
14906  /* Move somewhere else to avoid recompiling? */
14907  #include <generated/utsrelease.h>
14908  
14909 @@ -155,7 +156,10 @@ static int set_one_prio(struct task_stru
14910                 goto out;
14911         }
14912         if (niceval < task_nice(p) && !can_nice(p, niceval)) {
14913 -               error = -EACCES;
14914 +               if (vx_flags(VXF_IGNEG_NICE, 0))
14915 +                       error = 0;
14916 +               else
14917 +                       error = -EACCES;
14918                 goto out;
14919         }
14920         no_nice = security_task_setnice(p, niceval);
14921 @@ -206,6 +210,8 @@ SYSCALL_DEFINE3(setpriority, int, which,
14922                         else
14923                                 pgrp = task_pgrp(current);
14924                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
14925 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
14926 +                                       continue;
14927                                 error = set_one_prio(p, niceval, error);
14928                         } while_each_pid_thread(pgrp, PIDTYPE_PGID, p);
14929                         break;
14930 @@ -271,6 +277,8 @@ SYSCALL_DEFINE2(getpriority, int, which,
14931                         else
14932                                 pgrp = task_pgrp(current);
14933                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
14934 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
14935 +                                       continue;
14936                                 niceval = 20 - task_nice(p);
14937                                 if (niceval > retval)
14938                                         retval = niceval;
14939 @@ -424,6 +432,8 @@ EXPORT_SYMBOL_GPL(kernel_power_off);
14940  
14941  static DEFINE_MUTEX(reboot_mutex);
14942  
14943 +long vs_reboot(unsigned int, void __user *);
14944 +
14945  /*
14946   * Reboot system call: for obvious reasons only root may call it,
14947   * and even root needs to set up some magic numbers in the registers
14948 @@ -466,6 +476,9 @@ SYSCALL_DEFINE4(reboot, int, magic1, int
14949         if ((cmd == LINUX_REBOOT_CMD_POWER_OFF) && !pm_power_off)
14950                 cmd = LINUX_REBOOT_CMD_HALT;
14951  
14952 +       if (!vx_check(0, VS_ADMIN|VS_WATCH))
14953 +               return vs_reboot(cmd, arg);
14954 +
14955         mutex_lock(&reboot_mutex);
14956         switch (cmd) {
14957         case LINUX_REBOOT_CMD_RESTART:
14958 @@ -1373,7 +1386,8 @@ SYSCALL_DEFINE2(sethostname, char __user
14959         int errno;
14960         char tmp[__NEW_UTS_LEN];
14961  
14962 -       if (!ns_capable(current->nsproxy->uts_ns->user_ns, CAP_SYS_ADMIN))
14963 +       if (!vx_ns_capable(current->nsproxy->uts_ns->user_ns,
14964 +               CAP_SYS_ADMIN, VXC_SET_UTSNAME))
14965                 return -EPERM;
14966  
14967         if (len < 0 || len > __NEW_UTS_LEN)
14968 @@ -1424,7 +1438,8 @@ SYSCALL_DEFINE2(setdomainname, char __us
14969         int errno;
14970         char tmp[__NEW_UTS_LEN];
14971  
14972 -       if (!ns_capable(current->nsproxy->uts_ns->user_ns, CAP_SYS_ADMIN))
14973 +       if (!vx_ns_capable(current->nsproxy->uts_ns->user_ns,
14974 +               CAP_SYS_ADMIN, VXC_SET_UTSNAME))
14975                 return -EPERM;
14976         if (len < 0 || len > __NEW_UTS_LEN)
14977                 return -EINVAL;
14978 @@ -1543,7 +1558,7 @@ int do_prlimit(struct task_struct *tsk,
14979                 /* Keep the capable check against init_user_ns until
14980                    cgroups can contain all limits */
14981                 if (new_rlim->rlim_max > rlim->rlim_max &&
14982 -                               !capable(CAP_SYS_RESOURCE))
14983 +                       !vx_capable(CAP_SYS_RESOURCE, VXC_SET_RLIMIT))
14984                         retval = -EPERM;
14985                 if (!retval)
14986                         retval = security_task_setrlimit(tsk->group_leader,
14987 @@ -1596,7 +1611,8 @@ static int check_prlimit_permission(stru
14988             gid_eq(cred->gid, tcred->sgid) &&
14989             gid_eq(cred->gid, tcred->gid))
14990                 return 0;
14991 -       if (ns_capable(tcred->user_ns, CAP_SYS_RESOURCE))
14992 +       if (vx_ns_capable(tcred->user_ns,
14993 +               CAP_SYS_RESOURCE, VXC_SET_RLIMIT))
14994                 return 0;
14995  
14996         return -EPERM;
14997 diff -NurpP --minimal linux-3.9.4/kernel/sysctl.c linux-3.9.4-vs2.3.6.2/kernel/sysctl.c
14998 --- linux-3.9.4/kernel/sysctl.c 2013-05-31 13:45:30.000000000 +0000
14999 +++ linux-3.9.4-vs2.3.6.2/kernel/sysctl.c       2013-05-31 15:28:39.000000000 +0000
15000 @@ -83,6 +83,7 @@
15001  #if defined(CONFIG_PROVE_LOCKING) || defined(CONFIG_LOCK_STAT)
15002  #include <linux/lockdep.h>
15003  #endif
15004 +extern char vshelper_path[];
15005  #ifdef CONFIG_CHR_DEV_SG
15006  #include <scsi/sg.h>
15007  #endif
15008 @@ -629,6 +630,13 @@ static struct ctl_table kern_table[] = {
15009                 .mode           = 0644,
15010                 .proc_handler   = proc_dostring,
15011         },
15012 +       {
15013 +               .procname       = "vshelper",
15014 +               .data           = &vshelper_path,
15015 +               .maxlen         = 256,
15016 +               .mode           = 0644,
15017 +               .proc_handler   = &proc_dostring,
15018 +       },
15019  
15020  #ifdef CONFIG_CHR_DEV_SG
15021         {
15022 diff -NurpP --minimal linux-3.9.4/kernel/sysctl_binary.c linux-3.9.4-vs2.3.6.2/kernel/sysctl_binary.c
15023 --- linux-3.9.4/kernel/sysctl_binary.c  2013-05-31 13:45:30.000000000 +0000
15024 +++ linux-3.9.4-vs2.3.6.2/kernel/sysctl_binary.c        2013-05-31 14:47:11.000000000 +0000
15025 @@ -73,6 +73,7 @@ static const struct bin_table bin_kern_t
15026  
15027         { CTL_INT,      KERN_PANIC,                     "panic" },
15028         { CTL_INT,      KERN_REALROOTDEV,               "real-root-dev" },
15029 +       { CTL_STR,      KERN_VSHELPER,                  "vshelper" },
15030  
15031         { CTL_STR,      KERN_SPARC_REBOOT,              "reboot-cmd" },
15032         { CTL_INT,      KERN_CTLALTDEL,                 "ctrl-alt-del" },
15033 diff -NurpP --minimal linux-3.9.4/kernel/time/timekeeping.c linux-3.9.4-vs2.3.6.2/kernel/time/timekeeping.c
15034 --- linux-3.9.4/kernel/time/timekeeping.c       2013-05-31 13:45:30.000000000 +0000
15035 +++ linux-3.9.4-vs2.3.6.2/kernel/time/timekeeping.c     2013-05-31 15:24:55.000000000 +0000
15036 @@ -22,6 +22,7 @@
15037  #include <linux/tick.h>
15038  #include <linux/stop_machine.h>
15039  #include <linux/pvclock_gtod.h>
15040 +#include <linux/vs_time.h>
15041  
15042  
15043  static struct timekeeper timekeeper;
15044 @@ -594,6 +595,7 @@ void getrawmonotonic(struct timespec *ts
15045         } while (read_seqretry(&tk->lock, seq));
15046  
15047         timespec_add_ns(ts, nsecs);
15048 +       vx_adjust_timespec(ts);
15049  }
15050  EXPORT_SYMBOL(getrawmonotonic);
15051  
15052 diff -NurpP --minimal linux-3.9.4/kernel/time.c linux-3.9.4-vs2.3.6.2/kernel/time.c
15053 --- linux-3.9.4/kernel/time.c   2013-05-31 13:45:30.000000000 +0000
15054 +++ linux-3.9.4-vs2.3.6.2/kernel/time.c 2013-05-31 14:47:11.000000000 +0000
15055 @@ -37,6 +37,7 @@
15056  #include <linux/fs.h>
15057  #include <linux/math64.h>
15058  #include <linux/ptrace.h>
15059 +#include <linux/vs_time.h>
15060  
15061  #include <asm/uaccess.h>
15062  #include <asm/unistd.h>
15063 @@ -92,7 +93,7 @@ SYSCALL_DEFINE1(stime, time_t __user *,
15064         if (err)
15065                 return err;
15066  
15067 -       do_settimeofday(&tv);
15068 +       vx_settimeofday(&tv);
15069         return 0;
15070  }
15071  
15072 @@ -180,7 +181,7 @@ int do_sys_settimeofday(const struct tim
15073                 }
15074         }
15075         if (tv)
15076 -               return do_settimeofday(tv);
15077 +               return vx_settimeofday(tv);
15078         return 0;
15079  }
15080  
15081 diff -NurpP --minimal linux-3.9.4/kernel/timer.c linux-3.9.4-vs2.3.6.2/kernel/timer.c
15082 --- linux-3.9.4/kernel/timer.c  2013-05-31 14:22:27.000000000 +0000
15083 +++ linux-3.9.4-vs2.3.6.2/kernel/timer.c        2013-05-31 14:47:11.000000000 +0000
15084 @@ -41,6 +41,10 @@
15085  #include <linux/sched.h>
15086  #include <linux/sched/sysctl.h>
15087  #include <linux/slab.h>
15088 +#include <linux/vs_base.h>
15089 +#include <linux/vs_cvirt.h>
15090 +#include <linux/vs_pid.h>
15091 +#include <linux/vserver/sched.h>
15092  
15093  #include <asm/uaccess.h>
15094  #include <asm/unistd.h>
15095 diff -NurpP --minimal linux-3.9.4/kernel/user_namespace.c linux-3.9.4-vs2.3.6.2/kernel/user_namespace.c
15096 --- linux-3.9.4/kernel/user_namespace.c 2013-05-31 13:45:30.000000000 +0000
15097 +++ linux-3.9.4-vs2.3.6.2/kernel/user_namespace.c       2013-05-31 17:44:56.000000000 +0000
15098 @@ -22,6 +22,7 @@
15099  #include <linux/ctype.h>
15100  #include <linux/projid.h>
15101  #include <linux/fs_struct.h>
15102 +#include <linux/vserver/global.h>
15103  
15104  static struct kmem_cache *user_ns_cachep __read_mostly;
15105  
15106 @@ -91,6 +92,7 @@ int create_user_ns(struct cred *new)
15107  
15108         atomic_set(&ns->count, 1);
15109         /* Leave the new->user_ns reference with the new user namespace. */
15110 +       atomic_inc(&vs_global_user_ns);
15111         ns->parent = parent_ns;
15112         ns->owner = owner;
15113         ns->group = group;
15114 @@ -835,6 +837,8 @@ static void *userns_get(struct task_stru
15115  
15116  static void userns_put(void *ns)
15117  {
15118 +       /* FIXME: maybe move into destroyer? */
15119 +       atomic_dec(&vs_global_user_ns);
15120         put_user_ns(ns);
15121  }
15122  
15123 diff -NurpP --minimal linux-3.9.4/kernel/utsname.c linux-3.9.4-vs2.3.6.2/kernel/utsname.c
15124 --- linux-3.9.4/kernel/utsname.c        2013-05-31 13:45:30.000000000 +0000
15125 +++ linux-3.9.4-vs2.3.6.2/kernel/utsname.c      2013-05-31 15:15:55.000000000 +0000
15126 @@ -16,14 +16,17 @@
15127  #include <linux/slab.h>
15128  #include <linux/user_namespace.h>
15129  #include <linux/proc_fs.h>
15130 +#include <linux/vserver/global.h>
15131  
15132  static struct uts_namespace *create_uts_ns(void)
15133  {
15134         struct uts_namespace *uts_ns;
15135  
15136         uts_ns = kmalloc(sizeof(struct uts_namespace), GFP_KERNEL);
15137 -       if (uts_ns)
15138 +       if (uts_ns) {
15139                 kref_init(&uts_ns->kref);
15140 +               atomic_inc(&vs_global_uts_ns);
15141 +       }
15142         return uts_ns;
15143  }
15144  
15145 @@ -85,6 +88,7 @@ void free_uts_ns(struct kref *kref)
15146         ns = container_of(kref, struct uts_namespace, kref);
15147         put_user_ns(ns->user_ns);
15148         proc_free_inum(ns->proc_inum);
15149 +       atomic_dec(&vs_global_uts_ns);
15150         kfree(ns);
15151  }
15152  
15153 diff -NurpP --minimal linux-3.9.4/kernel/vserver/Kconfig linux-3.9.4-vs2.3.6.2/kernel/vserver/Kconfig
15154 --- linux-3.9.4/kernel/vserver/Kconfig  1970-01-01 00:00:00.000000000 +0000
15155 +++ linux-3.9.4-vs2.3.6.2/kernel/vserver/Kconfig        2013-05-31 14:47:11.000000000 +0000
15156 @@ -0,0 +1,233 @@
15157 +#
15158 +# Linux VServer configuration
15159 +#
15160 +
15161 +menu "Linux VServer"
15162 +
15163 +config VSERVER_AUTO_LBACK
15164 +       bool    "Automatically Assign Loopback IP"
15165 +       default y
15166 +       help
15167 +         Automatically assign a guest specific loopback
15168 +         IP and add it to the kernel network stack on
15169 +         startup.
15170 +
15171 +config VSERVER_AUTO_SINGLE
15172 +       bool    "Automatic Single IP Special Casing"
15173 +       depends on EXPERIMENTAL
15174 +       default y
15175 +       help
15176 +         This allows network contexts with a single IP to
15177 +         automatically remap 0.0.0.0 bindings to that IP,
15178 +         avoiding further network checks and improving
15179 +         performance.
15180 +
15181 +         (note: such guests do not allow to change the ip
15182 +          on the fly and do not show loopback addresses)
15183 +
15184 +config VSERVER_COWBL
15185 +       bool    "Enable COW Immutable Link Breaking"
15186 +       default y
15187 +       help
15188 +         This enables the COW (Copy-On-Write) link break code.
15189 +         It allows you to treat unified files like normal files
15190 +         when writing to them (which will implicitely break the
15191 +         link and create a copy of the unified file)
15192 +
15193 +config VSERVER_VTIME
15194 +       bool    "Enable Virtualized Guest Time"
15195 +       depends on EXPERIMENTAL
15196 +       default n
15197 +       help
15198 +         This enables per guest time offsets to allow for
15199 +         adjusting the system clock individually per guest.
15200 +         this adds some overhead to the time functions and
15201 +         therefore should not be enabled without good reason.
15202 +
15203 +config VSERVER_DEVICE
15204 +       bool    "Enable Guest Device Mapping"
15205 +       depends on EXPERIMENTAL
15206 +       default n
15207 +       help
15208 +         This enables generic device remapping.
15209 +
15210 +config VSERVER_PROC_SECURE
15211 +       bool    "Enable Proc Security"
15212 +       depends on PROC_FS
15213 +       default y
15214 +       help
15215 +         This configures ProcFS security to initially hide
15216 +         non-process entries for all contexts except the main and
15217 +         spectator context (i.e. for all guests), which is a secure
15218 +         default.
15219 +
15220 +         (note: on 1.2x the entries were visible by default)
15221 +
15222 +choice
15223 +       prompt  "Persistent Inode Tagging"
15224 +       default TAGGING_ID24
15225 +       help
15226 +         This adds persistent context information to filesystems
15227 +         mounted with the tagxid option. Tagging is a requirement
15228 +         for per-context disk limits and per-context quota.
15229 +
15230 +
15231 +config TAGGING_NONE
15232 +       bool    "Disabled"
15233 +       help
15234 +         do not store per-context information in inodes.
15235 +
15236 +config TAGGING_UID16
15237 +       bool    "UID16/GID32"
15238 +       help
15239 +         reduces UID to 16 bit, but leaves GID at 32 bit.
15240 +
15241 +config TAGGING_GID16
15242 +       bool    "UID32/GID16"
15243 +       help
15244 +         reduces GID to 16 bit, but leaves UID at 32 bit.
15245 +
15246 +config TAGGING_ID24
15247 +       bool    "UID24/GID24"
15248 +       help
15249 +         uses the upper 8bit from UID and GID for XID tagging
15250 +         which leaves 24bit for UID/GID each, which should be
15251 +         more than sufficient for normal use.
15252 +
15253 +config TAGGING_INTERN
15254 +       bool    "UID32/GID32"
15255 +       help
15256 +         this uses otherwise reserved inode fields in the on
15257 +         disk representation, which limits the use to a few
15258 +         filesystems (currently ext2 and ext3)
15259 +
15260 +endchoice
15261 +
15262 +config TAG_NFSD
15263 +       bool    "Tag NFSD User Auth and Files"
15264 +       default n
15265 +       help
15266 +         Enable this if you do want the in-kernel NFS
15267 +         Server to use the tagging specified above.
15268 +         (will require patched clients too)
15269 +
15270 +config VSERVER_PRIVACY
15271 +       bool    "Honor Privacy Aspects of Guests"
15272 +       default n
15273 +       help
15274 +         When enabled, most context checks will disallow
15275 +         access to structures assigned to a specific context,
15276 +         like ptys or loop devices.
15277 +
15278 +config VSERVER_CONTEXTS
15279 +       int     "Maximum number of Contexts (1-65533)"  if EMBEDDED
15280 +       range 1 65533
15281 +       default "768"   if 64BIT
15282 +       default "256"
15283 +       help
15284 +         This setting will optimize certain data structures
15285 +         and memory allocations according to the expected
15286 +         maximum.
15287 +
15288 +         note: this is not a strict upper limit.
15289 +
15290 +config VSERVER_WARN
15291 +       bool    "VServer Warnings"
15292 +       default y
15293 +       help
15294 +         This enables various runtime warnings, which will
15295 +         notify about potential manipulation attempts or
15296 +         resource shortage. It is generally considered to
15297 +         be a good idea to have that enabled.
15298 +
15299 +config VSERVER_WARN_DEVPTS
15300 +       bool    "VServer DevPTS Warnings"
15301 +       depends on VSERVER_WARN
15302 +       default y
15303 +       help
15304 +         This enables DevPTS related warnings, issued when a
15305 +         process inside a context tries to lookup or access
15306 +         a dynamic pts from the host or a different context.
15307 +
15308 +config VSERVER_DEBUG
15309 +       bool    "VServer Debugging Code"
15310 +       default n
15311 +       help
15312 +         Set this to yes if you want to be able to activate
15313 +         debugging output at runtime. It adds a very small
15314 +         overhead to all vserver related functions and
15315 +         increases the kernel size by about 20k.
15316 +
15317 +config VSERVER_HISTORY
15318 +       bool    "VServer History Tracing"
15319 +       depends on VSERVER_DEBUG
15320 +       default n
15321 +       help
15322 +         Set this to yes if you want to record the history of
15323 +         linux-vserver activities, so they can be replayed in
15324 +         the event of a kernel panic or oops.
15325 +
15326 +config VSERVER_HISTORY_SIZE
15327 +       int     "Per-CPU History Size (32-65536)"
15328 +       depends on VSERVER_HISTORY
15329 +       range 32 65536
15330 +       default 64
15331 +       help
15332 +         This allows you to specify the number of entries in
15333 +         the per-CPU history buffer.
15334 +
15335 +config VSERVER_EXTRA_MNT_CHECK
15336 +       bool    "Extra Checks for Reachability"
15337 +       default n
15338 +       help
15339 +         Set this to yes if you want to do extra checks for
15340 +         vfsmount reachability in the proc filesystem code.
15341 +         This shouldn't be required on any setup utilizing
15342 +         mnt namespaces.
15343 +
15344 +choice
15345 +       prompt  "Quotes used in debug and warn messages"
15346 +       default QUOTES_ISO8859
15347 +
15348 +config QUOTES_ISO8859
15349 +       bool    "Extended ASCII (ISO 8859) angle quotes"
15350 +       help
15351 +         This uses the extended ASCII characters \xbb
15352 +         and \xab for quoting file and process names.
15353 +
15354 +config QUOTES_UTF8
15355 +       bool    "UTF-8 angle quotes"
15356 +       help
15357 +         This uses the the UTF-8 sequences for angle
15358 +         quotes to quote file and process names.
15359 +
15360 +config QUOTES_ASCII
15361 +       bool    "ASCII single quotes"
15362 +       help
15363 +         This uses the ASCII single quote character
15364 +         (\x27) to quote file and process names.
15365 +
15366 +endchoice
15367 +
15368 +endmenu
15369 +
15370 +
15371 +config VSERVER
15372 +       bool
15373 +       default y
15374 +       select NAMESPACES
15375 +       select UTS_NS
15376 +       select IPC_NS
15377 +#      select USER_NS
15378 +       select SYSVIPC
15379 +
15380 +config VSERVER_SECURITY
15381 +       bool
15382 +       depends on SECURITY
15383 +       default y
15384 +       select SECURITY_CAPABILITIES
15385 +
15386 +config VSERVER_DISABLED
15387 +       bool
15388 +       default n
15389 +
15390 diff -NurpP --minimal linux-3.9.4/kernel/vserver/Makefile linux-3.9.4-vs2.3.6.2/kernel/vserver/Makefile
15391 --- linux-3.9.4/kernel/vserver/Makefile 1970-01-01 00:00:00.000000000 +0000
15392 +++ linux-3.9.4-vs2.3.6.2/kernel/vserver/Makefile       2013-05-31 14:47:11.000000000 +0000
15393 @@ -0,0 +1,18 @@
15394 +#
15395 +# Makefile for the Linux vserver routines.
15396 +#
15397 +
15398 +
15399 +obj-y          += vserver.o
15400 +
15401 +vserver-y      := switch.o context.o space.o sched.o network.o inode.o \
15402 +                  limit.o cvirt.o cacct.o signal.o helper.o init.o \
15403 +                  dlimit.o tag.o
15404 +
15405 +vserver-$(CONFIG_INET) += inet.o
15406 +vserver-$(CONFIG_PROC_FS) += proc.o
15407 +vserver-$(CONFIG_VSERVER_DEBUG) += sysctl.o debug.o
15408 +vserver-$(CONFIG_VSERVER_HISTORY) += history.o
15409 +vserver-$(CONFIG_VSERVER_MONITOR) += monitor.o
15410 +vserver-$(CONFIG_VSERVER_DEVICE) += device.o
15411 +
15412 diff -NurpP --minimal linux-3.9.4/kernel/vserver/cacct.c linux-3.9.4-vs2.3.6.2/kernel/vserver/cacct.c
15413 --- linux-3.9.4/kernel/vserver/cacct.c  1970-01-01 00:00:00.000000000 +0000
15414 +++ linux-3.9.4-vs2.3.6.2/kernel/vserver/cacct.c        2013-05-31 14:47:11.000000000 +0000
15415 @@ -0,0 +1,42 @@
15416 +/*
15417 + *  linux/kernel/vserver/cacct.c
15418 + *
15419 + *  Virtual Server: Context Accounting
15420 + *
15421 + *  Copyright (C) 2006-2007 Herbert Pötzl
15422 + *
15423 + *  V0.01  added accounting stats
15424 + *
15425 + */
15426 +
15427 +#include <linux/types.h>
15428 +#include <linux/vs_context.h>
15429 +#include <linux/vserver/cacct_cmd.h>
15430 +#include <linux/vserver/cacct_int.h>
15431 +
15432 +#include <asm/errno.h>
15433 +#include <asm/uaccess.h>
15434 +
15435 +
15436 +int vc_sock_stat(struct vx_info *vxi, void __user *data)
15437 +{
15438 +       struct vcmd_sock_stat_v0 vc_data;
15439 +       int j, field;
15440 +
15441 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
15442 +               return -EFAULT;
15443 +
15444 +       field = vc_data.field;
15445 +       if ((field < 0) || (field >= VXA_SOCK_SIZE))
15446 +               return -EINVAL;
15447 +
15448 +       for (j = 0; j < 3; j++) {
15449 +               vc_data.count[j] = vx_sock_count(&vxi->cacct, field, j);
15450 +               vc_data.total[j] = vx_sock_total(&vxi->cacct, field, j);
15451 +       }
15452 +
15453 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
15454 +               return -EFAULT;
15455 +       return 0;
15456 +}
15457 +
15458 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
15459 --- linux-3.9.4/kernel/vserver/cacct_init.h     1970-01-01 00:00:00.000000000 +0000
15460 +++ linux-3.9.4-vs2.3.6.2/kernel/vserver/cacct_init.h   2013-05-31 14:47:11.000000000 +0000
15461 @@ -0,0 +1,25 @@
15462 +
15463 +
15464 +static inline void vx_info_init_cacct(struct _vx_cacct *cacct)
15465 +{
15466 +       int i, j;
15467 +
15468 +
15469 +       for (i = 0; i < VXA_SOCK_SIZE; i++) {
15470 +               for (j = 0; j < 3; j++) {
15471 +                       atomic_long_set(&cacct->sock[i][j].count, 0);
15472 +                       atomic_long_set(&cacct->sock[i][j].total, 0);
15473 +               }
15474 +       }
15475 +       for (i = 0; i < 8; i++)
15476 +               atomic_set(&cacct->slab[i], 0);
15477 +       for (i = 0; i < 5; i++)
15478 +               for (j = 0; j < 4; j++)
15479 +                       atomic_set(&cacct->page[i][j], 0);
15480 +}
15481 +
15482 +static inline void vx_info_exit_cacct(struct _vx_cacct *cacct)
15483 +{
15484 +       return;
15485 +}
15486 +
15487 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
15488 --- linux-3.9.4/kernel/vserver/cacct_proc.h     1970-01-01 00:00:00.000000000 +0000
15489 +++ linux-3.9.4-vs2.3.6.2/kernel/vserver/cacct_proc.h   2013-05-31 14:47:11.000000000 +0000
15490 @@ -0,0 +1,53 @@
15491 +#ifndef _VX_CACCT_PROC_H
15492 +#define _VX_CACCT_PROC_H
15493 +
15494 +#include <linux/vserver/cacct_int.h>
15495 +
15496 +
15497 +#define VX_SOCKA_TOP   \
15498 +       "Type\t    recv #/bytes\t\t   send #/bytes\t\t    fail #/bytes\n"
15499 +
15500 +static inline int vx_info_proc_cacct(struct _vx_cacct *cacct, char *buffer)
15501 +{
15502 +       int i, j, length = 0;
15503 +       static char *type[VXA_SOCK_SIZE] = {
15504 +               "UNSPEC", "UNIX", "INET", "INET6", "PACKET", "OTHER"
15505 +       };
15506 +
15507 +       length += sprintf(buffer + length, VX_SOCKA_TOP);
15508 +       for (i = 0; i < VXA_SOCK_SIZE; i++) {
15509 +               length += sprintf(buffer + length, "%s:", type[i]);
15510 +               for (j = 0; j < 3; j++) {
15511 +                       length += sprintf(buffer + length,
15512 +                               "\t%10lu/%-10lu",
15513 +                               vx_sock_count(cacct, i, j),
15514 +                               vx_sock_total(cacct, i, j));
15515 +               }
15516 +               buffer[length++] = '\n';
15517 +       }
15518 +
15519 +       length += sprintf(buffer + length, "\n");
15520 +       length += sprintf(buffer + length,
15521 +               "slab:\t %8u %8u %8u %8u\n",
15522 +               atomic_read(&cacct->slab[1]),
15523 +               atomic_read(&cacct->slab[4]),
15524 +               atomic_read(&cacct->slab[0]),
15525 +               atomic_read(&cacct->slab[2]));
15526 +
15527 +       length += sprintf(buffer + length, "\n");
15528 +       for (i = 0; i < 5; i++) {
15529 +               length += sprintf(buffer + length,
15530 +                       "page[%d]: %8u %8u %8u %8u\t %8u %8u %8u %8u\n", i,
15531 +                       atomic_read(&cacct->page[i][0]),
15532 +                       atomic_read(&cacct->page[i][1]),
15533 +                       atomic_read(&cacct->page[i][2]),
15534 +                       atomic_read(&cacct->page[i][3]),
15535 +                       atomic_read(&cacct->page[i][4]),
15536 +                       atomic_read(&cacct->page[i][5]),
15537 +                       atomic_read(&cacct->page[i][6]),
15538 +                       atomic_read(&cacct->page[i][7]));
15539 +       }
15540 +       return length;
15541 +}
15542 +
15543 +#endif /* _VX_CACCT_PROC_H */
15544 diff -NurpP --minimal linux-3.9.4/kernel/vserver/context.c linux-3.9.4-vs2.3.6.2/kernel/vserver/context.c
15545 --- linux-3.9.4/kernel/vserver/context.c        1970-01-01 00:00:00.000000000 +0000
15546 +++ linux-3.9.4-vs2.3.6.2/kernel/vserver/context.c      2013-05-31 19:34:32.000000000 +0000
15547 @@ -0,0 +1,1119 @@
15548 +/*
15549 + *  linux/kernel/vserver/context.c
15550 + *
15551 + *  Virtual Server: Context Support
15552 + *
15553 + *  Copyright (C) 2003-2011  Herbert Pötzl
15554 + *
15555 + *  V0.01  context helper
15556 + *  V0.02  vx_ctx_kill syscall command
15557 + *  V0.03  replaced context_info calls
15558 + *  V0.04  redesign of struct (de)alloc
15559 + *  V0.05  rlimit basic implementation
15560 + *  V0.06  task_xid and info commands
15561 + *  V0.07  context flags and caps
15562 + *  V0.08  switch to RCU based hash
15563 + *  V0.09  revert to non RCU for now
15564 + *  V0.10  and back to working RCU hash
15565 + *  V0.11  and back to locking again
15566 + *  V0.12  referenced context store
15567 + *  V0.13  separate per cpu data
15568 + *  V0.14  changed vcmds to vxi arg
15569 + *  V0.15  added context stat
15570 + *  V0.16  have __create claim() the vxi
15571 + *  V0.17  removed older and legacy stuff
15572 + *  V0.18  added user credentials
15573 + *  V0.19  added warn mask
15574 + *
15575 + */
15576 +
15577 +#include <linux/slab.h>
15578 +#include <linux/types.h>
15579 +#include <linux/security.h>
15580 +#include <linux/pid_namespace.h>
15581 +#include <linux/capability.h>
15582 +
15583 +#include <linux/vserver/context.h>
15584 +#include <linux/vserver/network.h>
15585 +#include <linux/vserver/debug.h>
15586 +#include <linux/vserver/limit.h>
15587 +#include <linux/vserver/limit_int.h>
15588 +#include <linux/vserver/space.h>
15589 +#include <linux/init_task.h>
15590 +#include <linux/fs_struct.h>
15591 +#include <linux/cred.h>
15592 +
15593 +#include <linux/vs_context.h>
15594 +#include <linux/vs_limit.h>
15595 +#include <linux/vs_pid.h>
15596 +#include <linux/vserver/context_cmd.h>
15597 +
15598 +#include "cvirt_init.h"
15599 +#include "cacct_init.h"
15600 +#include "limit_init.h"
15601 +#include "sched_init.h"
15602 +
15603 +
15604 +atomic_t vx_global_ctotal      = ATOMIC_INIT(0);
15605 +atomic_t vx_global_cactive     = ATOMIC_INIT(0);
15606 +
15607 +
15608 +/*     now inactive context structures */
15609 +
15610 +static struct hlist_head vx_info_inactive = HLIST_HEAD_INIT;
15611 +
15612 +static DEFINE_SPINLOCK(vx_info_inactive_lock);
15613 +
15614 +
15615 +/*     __alloc_vx_info()
15616 +
15617 +       * allocate an initialized vx_info struct
15618 +       * doesn't make it visible (hash)                        */
15619 +
15620 +static struct vx_info *__alloc_vx_info(xid_t xid)
15621 +{
15622 +       struct vx_info *new = NULL;
15623 +       int cpu, index;
15624 +
15625 +       vxdprintk(VXD_CBIT(xid, 0), "alloc_vx_info(%d)*", xid);
15626 +
15627 +       /* would this benefit from a slab cache? */
15628 +       new = kmalloc(sizeof(struct vx_info), GFP_KERNEL);
15629 +       if (!new)
15630 +               return 0;
15631 +
15632 +       memset(new, 0, sizeof(struct vx_info));
15633 +#ifdef CONFIG_SMP
15634 +       new->ptr_pc = alloc_percpu(struct _vx_info_pc);
15635 +       if (!new->ptr_pc)
15636 +               goto error;
15637 +#endif
15638 +       new->vx_id = xid;
15639 +       INIT_HLIST_NODE(&new->vx_hlist);
15640 +       atomic_set(&new->vx_usecnt, 0);
15641 +       atomic_set(&new->vx_tasks, 0);
15642 +       new->vx_parent = NULL;
15643 +       new->vx_state = 0;
15644 +       init_waitqueue_head(&new->vx_wait);
15645 +
15646 +       /* prepare reaper */
15647 +       get_task_struct(init_pid_ns.child_reaper);
15648 +       new->vx_reaper = init_pid_ns.child_reaper;
15649 +       new->vx_badness_bias = 0;
15650 +
15651 +       /* rest of init goes here */
15652 +       vx_info_init_limit(&new->limit);
15653 +       vx_info_init_sched(&new->sched);
15654 +       vx_info_init_cvirt(&new->cvirt);
15655 +       vx_info_init_cacct(&new->cacct);
15656 +
15657 +       /* per cpu data structures */
15658 +       for_each_possible_cpu(cpu) {
15659 +               vx_info_init_sched_pc(
15660 +                       &vx_per_cpu(new, sched_pc, cpu), cpu);
15661 +               vx_info_init_cvirt_pc(
15662 +                       &vx_per_cpu(new, cvirt_pc, cpu), cpu);
15663 +       }
15664 +
15665 +       new->vx_flags = VXF_INIT_SET;
15666 +       new->vx_bcaps = CAP_FULL_SET;   // maybe ~CAP_SETPCAP
15667 +       new->vx_ccaps = 0;
15668 +       new->vx_umask = 0;
15669 +       new->vx_wmask = 0;
15670 +
15671 +       new->reboot_cmd = 0;
15672 +       new->exit_code = 0;
15673 +
15674 +       // preconfig spaces
15675 +       for (index = 0; index < VX_SPACES; index++) {
15676 +               struct _vx_space *space = &new->space[index];
15677 +
15678 +               // filesystem
15679 +               spin_lock(&init_fs.lock);
15680 +               init_fs.users++;
15681 +               spin_unlock(&init_fs.lock);
15682 +               space->vx_fs = &init_fs;
15683 +
15684 +               /* FIXME: do we want defaults? */
15685 +               // space->vx_real_cred = 0;
15686 +               // space->vx_cred = 0;
15687 +       }
15688 +
15689 +
15690 +       vxdprintk(VXD_CBIT(xid, 0),
15691 +               "alloc_vx_info(%d) = %p", xid, new);
15692 +       vxh_alloc_vx_info(new);
15693 +       atomic_inc(&vx_global_ctotal);
15694 +       return new;
15695 +#ifdef CONFIG_SMP
15696 +error:
15697 +       kfree(new);
15698 +       return 0;
15699 +#endif
15700 +}
15701 +
15702 +/*     __dealloc_vx_info()
15703 +
15704 +       * final disposal of vx_info                             */
15705 +
15706 +static void __dealloc_vx_info(struct vx_info *vxi)
15707 +{
15708 +#ifdef CONFIG_VSERVER_WARN
15709 +       struct vx_info_save vxis;
15710 +       int cpu;
15711 +#endif
15712 +       vxdprintk(VXD_CBIT(xid, 0),
15713 +               "dealloc_vx_info(%p)", vxi);
15714 +       vxh_dealloc_vx_info(vxi);
15715 +
15716 +#ifdef CONFIG_VSERVER_WARN
15717 +       enter_vx_info(vxi, &vxis);
15718 +       vx_info_exit_limit(&vxi->limit);
15719 +       vx_info_exit_sched(&vxi->sched);
15720 +       vx_info_exit_cvirt(&vxi->cvirt);
15721 +       vx_info_exit_cacct(&vxi->cacct);
15722 +
15723 +       for_each_possible_cpu(cpu) {
15724 +               vx_info_exit_sched_pc(
15725 +                       &vx_per_cpu(vxi, sched_pc, cpu), cpu);
15726 +               vx_info_exit_cvirt_pc(
15727 +                       &vx_per_cpu(vxi, cvirt_pc, cpu), cpu);
15728 +       }
15729 +       leave_vx_info(&vxis);
15730 +#endif
15731 +
15732 +       vxi->vx_id = -1;
15733 +       vxi->vx_state |= VXS_RELEASED;
15734 +
15735 +#ifdef CONFIG_SMP
15736 +       free_percpu(vxi->ptr_pc);
15737 +#endif
15738 +       kfree(vxi);
15739 +       atomic_dec(&vx_global_ctotal);
15740 +}
15741 +
15742 +static void __shutdown_vx_info(struct vx_info *vxi)
15743 +{
15744 +       struct nsproxy *nsproxy;
15745 +       struct fs_struct *fs;
15746 +       struct cred *cred;
15747 +       int index, kill;
15748 +
15749 +       might_sleep();
15750 +
15751 +       vxi->vx_state |= VXS_SHUTDOWN;
15752 +       vs_state_change(vxi, VSC_SHUTDOWN);
15753 +
15754 +       for (index = 0; index < VX_SPACES; index++) {
15755 +               struct _vx_space *space = &vxi->space[index];
15756 +
15757 +               nsproxy = xchg(&space->vx_nsproxy, NULL);
15758 +               if (nsproxy)
15759 +                       put_nsproxy(nsproxy);
15760 +
15761 +               fs = xchg(&space->vx_fs, NULL);
15762 +               spin_lock(&fs->lock);
15763 +               kill = !--fs->users;
15764 +               spin_unlock(&fs->lock);
15765 +               if (kill)
15766 +                       free_fs_struct(fs);
15767 +
15768 +               cred = (struct cred *)xchg(&space->vx_cred, NULL);
15769 +               if (cred)
15770 +                       abort_creds(cred);
15771 +       }
15772 +}
15773 +
15774 +/* exported stuff */
15775 +
15776 +void free_vx_info(struct vx_info *vxi)
15777 +{
15778 +       unsigned long flags;
15779 +       unsigned index;
15780 +
15781 +       /* check for reference counts first */
15782 +       BUG_ON(atomic_read(&vxi->vx_usecnt));
15783 +       BUG_ON(atomic_read(&vxi->vx_tasks));
15784 +
15785 +       /* context must not be hashed */
15786 +       BUG_ON(vx_info_state(vxi, VXS_HASHED));
15787 +
15788 +       /* context shutdown is mandatory */
15789 +       BUG_ON(!vx_info_state(vxi, VXS_SHUTDOWN));
15790 +
15791 +       /* spaces check */
15792 +       for (index = 0; index < VX_SPACES; index++) {
15793 +               struct _vx_space *space = &vxi->space[index];
15794 +
15795 +               BUG_ON(space->vx_nsproxy);
15796 +               BUG_ON(space->vx_fs);
15797 +               // BUG_ON(space->vx_real_cred);
15798 +               // BUG_ON(space->vx_cred);
15799 +       }
15800 +
15801 +       spin_lock_irqsave(&vx_info_inactive_lock, flags);
15802 +       hlist_del(&vxi->vx_hlist);
15803 +       spin_unlock_irqrestore(&vx_info_inactive_lock, flags);
15804 +
15805 +       __dealloc_vx_info(vxi);
15806 +}
15807 +
15808 +
15809 +/*     hash table for vx_info hash */
15810 +
15811 +#define VX_HASH_SIZE   13
15812 +
15813 +static struct hlist_head vx_info_hash[VX_HASH_SIZE] =
15814 +       { [0 ... VX_HASH_SIZE-1] = HLIST_HEAD_INIT };
15815 +
15816 +static DEFINE_SPINLOCK(vx_info_hash_lock);
15817 +
15818 +
15819 +static inline unsigned int __hashval(xid_t xid)
15820 +{
15821 +       return (xid % VX_HASH_SIZE);
15822 +}
15823 +
15824 +
15825 +
15826 +/*     __hash_vx_info()
15827 +
15828 +       * add the vxi to the global hash table
15829 +       * requires the hash_lock to be held                     */
15830 +
15831 +static inline void __hash_vx_info(struct vx_info *vxi)
15832 +{
15833 +       struct hlist_head *head;
15834 +
15835 +       vxd_assert_lock(&vx_info_hash_lock);
15836 +       vxdprintk(VXD_CBIT(xid, 4),
15837 +               "__hash_vx_info: %p[#%d]", vxi, vxi->vx_id);
15838 +       vxh_hash_vx_info(vxi);
15839 +
15840 +       /* context must not be hashed */
15841 +       BUG_ON(vx_info_state(vxi, VXS_HASHED));
15842 +
15843 +       vxi->vx_state |= VXS_HASHED;
15844 +       head = &vx_info_hash[__hashval(vxi->vx_id)];
15845 +       hlist_add_head(&vxi->vx_hlist, head);
15846 +       atomic_inc(&vx_global_cactive);
15847 +}
15848 +
15849 +/*     __unhash_vx_info()
15850 +
15851 +       * remove the vxi from the global hash table
15852 +       * requires the hash_lock to be held                     */
15853 +
15854 +static inline void __unhash_vx_info(struct vx_info *vxi)
15855 +{
15856 +       unsigned long flags;
15857 +
15858 +       vxd_assert_lock(&vx_info_hash_lock);
15859 +       vxdprintk(VXD_CBIT(xid, 4),
15860 +               "__unhash_vx_info: %p[#%d.%d.%d]", vxi, vxi->vx_id,
15861 +               atomic_read(&vxi->vx_usecnt), atomic_read(&vxi->vx_tasks));
15862 +       vxh_unhash_vx_info(vxi);
15863 +
15864 +       /* context must be hashed */
15865 +       BUG_ON(!vx_info_state(vxi, VXS_HASHED));
15866 +       /* but without tasks */
15867 +       BUG_ON(atomic_read(&vxi->vx_tasks));
15868 +
15869 +       vxi->vx_state &= ~VXS_HASHED;
15870 +       hlist_del_init(&vxi->vx_hlist);
15871 +       spin_lock_irqsave(&vx_info_inactive_lock, flags);
15872 +       hlist_add_head(&vxi->vx_hlist, &vx_info_inactive);
15873 +       spin_unlock_irqrestore(&vx_info_inactive_lock, flags);
15874 +       atomic_dec(&vx_global_cactive);
15875 +}
15876 +
15877 +
15878 +/*     __lookup_vx_info()
15879 +
15880 +       * requires the hash_lock to be held
15881 +       * doesn't increment the vx_refcnt                       */
15882 +
15883 +static inline struct vx_info *__lookup_vx_info(xid_t xid)
15884 +{
15885 +       struct hlist_head *head = &vx_info_hash[__hashval(xid)];
15886 +       struct hlist_node *pos;
15887 +       struct vx_info *vxi;
15888 +
15889 +       vxd_assert_lock(&vx_info_hash_lock);
15890 +       hlist_for_each(pos, head) {
15891 +               vxi = hlist_entry(pos, struct vx_info, vx_hlist);
15892 +
15893 +               if (vxi->vx_id == xid)
15894 +                       goto found;
15895 +       }
15896 +       vxi = NULL;
15897 +found:
15898 +       vxdprintk(VXD_CBIT(xid, 0),
15899 +               "__lookup_vx_info(#%u): %p[#%u]",
15900 +               xid, vxi, vxi ? vxi->vx_id : 0);
15901 +       vxh_lookup_vx_info(vxi, xid);
15902 +       return vxi;
15903 +}
15904 +
15905 +
15906 +/*     __create_vx_info()
15907 +
15908 +       * create the requested context
15909 +       * get(), claim() and hash it                            */
15910 +
15911 +static struct vx_info *__create_vx_info(int id)
15912 +{
15913 +       struct vx_info *new, *vxi = NULL;
15914 +
15915 +       vxdprintk(VXD_CBIT(xid, 1), "create_vx_info(%d)*", id);
15916 +
15917 +       if (!(new = __alloc_vx_info(id)))
15918 +               return ERR_PTR(-ENOMEM);
15919 +
15920 +       /* required to make dynamic xids unique */
15921 +       spin_lock(&vx_info_hash_lock);
15922 +
15923 +       /* static context requested */
15924 +       if ((vxi = __lookup_vx_info(id))) {
15925 +               vxdprintk(VXD_CBIT(xid, 0),
15926 +                       "create_vx_info(%d) = %p (already there)", id, vxi);
15927 +               if (vx_info_flags(vxi, VXF_STATE_SETUP, 0))
15928 +                       vxi = ERR_PTR(-EBUSY);
15929 +               else
15930 +                       vxi = ERR_PTR(-EEXIST);
15931 +               goto out_unlock;
15932 +       }
15933 +       /* new context */
15934 +       vxdprintk(VXD_CBIT(xid, 0),
15935 +               "create_vx_info(%d) = %p (new)", id, new);
15936 +       claim_vx_info(new, NULL);
15937 +       __hash_vx_info(get_vx_info(new));
15938 +       vxi = new, new = NULL;
15939 +
15940 +out_unlock:
15941 +       spin_unlock(&vx_info_hash_lock);
15942 +       vxh_create_vx_info(IS_ERR(vxi) ? NULL : vxi, id);
15943 +       if (new)
15944 +               __dealloc_vx_info(new);
15945 +       return vxi;
15946 +}
15947 +
15948 +
15949 +/*     exported stuff                                          */
15950 +
15951 +
15952 +void unhash_vx_info(struct vx_info *vxi)
15953 +{
15954 +       spin_lock(&vx_info_hash_lock);
15955 +       __unhash_vx_info(vxi);
15956 +       spin_unlock(&vx_info_hash_lock);
15957 +       __shutdown_vx_info(vxi);
15958 +       __wakeup_vx_info(vxi);
15959 +}
15960 +
15961 +
15962 +/*     lookup_vx_info()
15963 +
15964 +       * search for a vx_info and get() it
15965 +       * negative id means current                             */
15966 +
15967 +struct vx_info *lookup_vx_info(int id)
15968 +{
15969 +       struct vx_info *vxi = NULL;
15970 +
15971 +       if (id < 0) {
15972 +               vxi = get_vx_info(current_vx_info());
15973 +       } else if (id > 1) {
15974 +               spin_lock(&vx_info_hash_lock);
15975 +               vxi = get_vx_info(__lookup_vx_info(id));
15976 +               spin_unlock(&vx_info_hash_lock);
15977 +       }
15978 +       return vxi;
15979 +}
15980 +
15981 +/*     xid_is_hashed()
15982 +
15983 +       * verify that xid is still hashed                       */
15984 +
15985 +int xid_is_hashed(xid_t xid)
15986 +{
15987 +       int hashed;
15988 +
15989 +       spin_lock(&vx_info_hash_lock);
15990 +       hashed = (__lookup_vx_info(xid) != NULL);
15991 +       spin_unlock(&vx_info_hash_lock);
15992 +       return hashed;
15993 +}
15994 +
15995 +#ifdef CONFIG_PROC_FS
15996 +
15997 +/*     get_xid_list()
15998 +
15999 +       * get a subset of hashed xids for proc
16000 +       * assumes size is at least one                          */
16001 +
16002 +int get_xid_list(int index, unsigned int *xids, int size)
16003 +{
16004 +       int hindex, nr_xids = 0;
16005 +
16006 +       /* only show current and children */
16007 +       if (!vx_check(0, VS_ADMIN | VS_WATCH)) {
16008 +               if (index > 0)
16009 +                       return 0;
16010 +               xids[nr_xids] = vx_current_xid();
16011 +               return 1;
16012 +       }
16013 +
16014 +       for (hindex = 0; hindex < VX_HASH_SIZE; hindex++) {
16015 +               struct hlist_head *head = &vx_info_hash[hindex];
16016 +               struct hlist_node *pos;
16017 +
16018 +               spin_lock(&vx_info_hash_lock);
16019 +               hlist_for_each(pos, head) {
16020 +                       struct vx_info *vxi;
16021 +
16022 +                       if (--index > 0)
16023 +                               continue;
16024 +
16025 +                       vxi = hlist_entry(pos, struct vx_info, vx_hlist);
16026 +                       xids[nr_xids] = vxi->vx_id;
16027 +                       if (++nr_xids >= size) {
16028 +                               spin_unlock(&vx_info_hash_lock);
16029 +                               goto out;
16030 +                       }
16031 +               }
16032 +               /* keep the lock time short */
16033 +               spin_unlock(&vx_info_hash_lock);
16034 +       }
16035 +out:
16036 +       return nr_xids;
16037 +}
16038 +#endif
16039 +
16040 +#ifdef CONFIG_VSERVER_DEBUG
16041 +
16042 +void   dump_vx_info_inactive(int level)
16043 +{
16044 +       struct hlist_node *entry, *next;
16045 +
16046 +       hlist_for_each_safe(entry, next, &vx_info_inactive) {
16047 +               struct vx_info *vxi =
16048 +                       list_entry(entry, struct vx_info, vx_hlist);
16049 +
16050 +               dump_vx_info(vxi, level);
16051 +       }
16052 +}
16053 +
16054 +#endif
16055 +
16056 +#if 0
16057 +int vx_migrate_user(struct task_struct *p, struct vx_info *vxi)
16058 +{
16059 +       struct user_struct *new_user, *old_user;
16060 +
16061 +       if (!p || !vxi)
16062 +               BUG();
16063 +
16064 +       if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0))
16065 +               return -EACCES;
16066 +
16067 +       new_user = alloc_uid(vxi->vx_id, p->uid);
16068 +       if (!new_user)
16069 +               return -ENOMEM;
16070 +
16071 +       old_user = p->user;
16072 +       if (new_user != old_user) {
16073 +               atomic_inc(&new_user->processes);
16074 +               atomic_dec(&old_user->processes);
16075 +               p->user = new_user;
16076 +       }
16077 +       free_uid(old_user);
16078 +       return 0;
16079 +}
16080 +#endif
16081 +
16082 +#if 0
16083 +void vx_mask_cap_bset(struct vx_info *vxi, struct task_struct *p)
16084 +{
16085 +       // p->cap_effective &= vxi->vx_cap_bset;
16086 +       p->cap_effective =
16087 +               cap_intersect(p->cap_effective, vxi->cap_bset);
16088 +       // p->cap_inheritable &= vxi->vx_cap_bset;
16089 +       p->cap_inheritable =
16090 +               cap_intersect(p->cap_inheritable, vxi->cap_bset);
16091 +       // p->cap_permitted &= vxi->vx_cap_bset;
16092 +       p->cap_permitted =
16093 +               cap_intersect(p->cap_permitted, vxi->cap_bset);
16094 +}
16095 +#endif
16096 +
16097 +
16098 +#include <linux/file.h>
16099 +#include <linux/fdtable.h>
16100 +
16101 +static int vx_openfd_task(struct task_struct *tsk)
16102 +{
16103 +       struct files_struct *files = tsk->files;
16104 +       struct fdtable *fdt;
16105 +       const unsigned long *bptr;
16106 +       int count, total;
16107 +
16108 +       /* no rcu_read_lock() because of spin_lock() */
16109 +       spin_lock(&files->file_lock);
16110 +       fdt = files_fdtable(files);
16111 +       bptr = fdt->open_fds;
16112 +       count = fdt->max_fds / (sizeof(unsigned long) * 8);
16113 +       for (total = 0; count > 0; count--) {
16114 +               if (*bptr)
16115 +                       total += hweight_long(*bptr);
16116 +               bptr++;
16117 +       }
16118 +       spin_unlock(&files->file_lock);
16119 +       return total;
16120 +}
16121 +
16122 +
16123 +/*     for *space compatibility */
16124 +
16125 +asmlinkage long sys_unshare(unsigned long);
16126 +
16127 +/*
16128 + *     migrate task to new context
16129 + *     gets vxi, puts old_vxi on change
16130 + *     optionally unshares namespaces (hack)
16131 + */
16132 +
16133 +int vx_migrate_task(struct task_struct *p, struct vx_info *vxi, int unshare)
16134 +{
16135 +       struct vx_info *old_vxi;
16136 +       int ret = 0;
16137 +
16138 +       if (!p || !vxi)
16139 +               BUG();
16140 +
16141 +       vxdprintk(VXD_CBIT(xid, 5),
16142 +               "vx_migrate_task(%p,%p[#%d.%d])", p, vxi,
16143 +               vxi->vx_id, atomic_read(&vxi->vx_usecnt));
16144 +
16145 +       if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0) &&
16146 +               !vx_info_flags(vxi, VXF_STATE_SETUP, 0))
16147 +               return -EACCES;
16148 +
16149 +       if (vx_info_state(vxi, VXS_SHUTDOWN))
16150 +               return -EFAULT;
16151 +
16152 +       old_vxi = task_get_vx_info(p);
16153 +       if (old_vxi == vxi)
16154 +               goto out;
16155 +
16156 +//     if (!(ret = vx_migrate_user(p, vxi))) {
16157 +       {
16158 +               int openfd;
16159 +
16160 +               task_lock(p);
16161 +               openfd = vx_openfd_task(p);
16162 +
16163 +               if (old_vxi) {
16164 +                       atomic_dec(&old_vxi->cvirt.nr_threads);
16165 +                       atomic_dec(&old_vxi->cvirt.nr_running);
16166 +                       __rlim_dec(&old_vxi->limit, RLIMIT_NPROC);
16167 +                       /* FIXME: what about the struct files here? */
16168 +                       __rlim_sub(&old_vxi->limit, VLIMIT_OPENFD, openfd);
16169 +                       /* account for the executable */
16170 +                       __rlim_dec(&old_vxi->limit, VLIMIT_DENTRY);
16171 +               }
16172 +               atomic_inc(&vxi->cvirt.nr_threads);
16173 +               atomic_inc(&vxi->cvirt.nr_running);
16174 +               __rlim_inc(&vxi->limit, RLIMIT_NPROC);
16175 +               /* FIXME: what about the struct files here? */
16176 +               __rlim_add(&vxi->limit, VLIMIT_OPENFD, openfd);
16177 +               /* account for the executable */
16178 +               __rlim_inc(&vxi->limit, VLIMIT_DENTRY);
16179 +
16180 +               if (old_vxi) {
16181 +                       release_vx_info(old_vxi, p);
16182 +                       clr_vx_info(&p->vx_info);
16183 +               }
16184 +               claim_vx_info(vxi, p);
16185 +               set_vx_info(&p->vx_info, vxi);
16186 +               p->xid = vxi->vx_id;
16187 +
16188 +               vxdprintk(VXD_CBIT(xid, 5),
16189 +                       "moved task %p into vxi:%p[#%d]",
16190 +                       p, vxi, vxi->vx_id);
16191 +
16192 +               // vx_mask_cap_bset(vxi, p);
16193 +               task_unlock(p);
16194 +
16195 +               /* hack for *spaces to provide compatibility */
16196 +               if (unshare) {
16197 +                       struct nsproxy *old_nsp, *new_nsp;
16198 +
16199 +                       ret = unshare_nsproxy_namespaces(
16200 +                               CLONE_NEWUTS | CLONE_NEWIPC | CLONE_NEWUSER,
16201 +                               &new_nsp, NULL, NULL);
16202 +                       if (ret)
16203 +                               goto out;
16204 +
16205 +                       old_nsp = xchg(&p->nsproxy, new_nsp);
16206 +                       vx_set_space(vxi,
16207 +                               CLONE_NEWUTS | CLONE_NEWIPC | CLONE_NEWUSER, 0);
16208 +                       put_nsproxy(old_nsp);
16209 +               }
16210 +       }
16211 +out:
16212 +       put_vx_info(old_vxi);
16213 +       return ret;
16214 +}
16215 +
16216 +int vx_set_reaper(struct vx_info *vxi, struct task_struct *p)
16217 +{
16218 +       struct task_struct *old_reaper;
16219 +       struct vx_info *reaper_vxi;
16220 +
16221 +       if (!vxi)
16222 +               return -EINVAL;
16223 +
16224 +       vxdprintk(VXD_CBIT(xid, 6),
16225 +               "vx_set_reaper(%p[#%d],%p[#%d,%d])",
16226 +               vxi, vxi->vx_id, p, p->xid, p->pid);
16227 +
16228 +       old_reaper = vxi->vx_reaper;
16229 +       if (old_reaper == p)
16230 +               return 0;
16231 +
16232 +       reaper_vxi = task_get_vx_info(p);
16233 +       if (reaper_vxi && reaper_vxi != vxi) {
16234 +               vxwprintk(1,
16235 +                       "Unsuitable reaper [" VS_Q("%s") ",%u:#%u] "
16236 +                       "for [xid #%u]",
16237 +                       p->comm, p->pid, p->xid, vx_current_xid());
16238 +               goto out;
16239 +       }
16240 +
16241 +       /* set new child reaper */
16242 +       get_task_struct(p);
16243 +       vxi->vx_reaper = p;
16244 +       put_task_struct(old_reaper);
16245 +out:
16246 +       put_vx_info(reaper_vxi);
16247 +       return 0;
16248 +}
16249 +
16250 +int vx_set_init(struct vx_info *vxi, struct task_struct *p)
16251 +{
16252 +       if (!vxi)
16253 +               return -EINVAL;
16254 +
16255 +       vxdprintk(VXD_CBIT(xid, 6),
16256 +               "vx_set_init(%p[#%d],%p[#%d,%d,%d])",
16257 +               vxi, vxi->vx_id, p, p->xid, p->pid, p->tgid);
16258 +
16259 +       vxi->vx_flags &= ~VXF_STATE_INIT;
16260 +       // vxi->vx_initpid = p->tgid;
16261 +       vxi->vx_initpid = p->pid;
16262 +       return 0;
16263 +}
16264 +
16265 +void vx_exit_init(struct vx_info *vxi, struct task_struct *p, int code)
16266 +{
16267 +       vxdprintk(VXD_CBIT(xid, 6),
16268 +               "vx_exit_init(%p[#%d],%p[#%d,%d,%d])",
16269 +               vxi, vxi->vx_id, p, p->xid, p->pid, p->tgid);
16270 +
16271 +       vxi->exit_code = code;
16272 +       vxi->vx_initpid = 0;
16273 +}
16274 +
16275 +
16276 +void vx_set_persistent(struct vx_info *vxi)
16277 +{
16278 +       vxdprintk(VXD_CBIT(xid, 6),
16279 +               "vx_set_persistent(%p[#%d])", vxi, vxi->vx_id);
16280 +
16281 +       get_vx_info(vxi);
16282 +       claim_vx_info(vxi, NULL);
16283 +}
16284 +
16285 +void vx_clear_persistent(struct vx_info *vxi)
16286 +{
16287 +       vxdprintk(VXD_CBIT(xid, 6),
16288 +               "vx_clear_persistent(%p[#%d])", vxi, vxi->vx_id);
16289 +
16290 +       release_vx_info(vxi, NULL);
16291 +       put_vx_info(vxi);
16292 +}
16293 +
16294 +void vx_update_persistent(struct vx_info *vxi)
16295 +{
16296 +       if (vx_info_flags(vxi, VXF_PERSISTENT, 0))
16297 +               vx_set_persistent(vxi);
16298 +       else
16299 +               vx_clear_persistent(vxi);
16300 +}
16301 +
16302 +
16303 +/*     task must be current or locked          */
16304 +
16305 +void   exit_vx_info(struct task_struct *p, int code)
16306 +{
16307 +       struct vx_info *vxi = p->vx_info;
16308 +
16309 +       if (vxi) {
16310 +               atomic_dec(&vxi->cvirt.nr_threads);
16311 +               vx_nproc_dec(p);
16312 +
16313 +               vxi->exit_code = code;
16314 +               release_vx_info(vxi, p);
16315 +       }
16316 +}
16317 +
16318 +void   exit_vx_info_early(struct task_struct *p, int code)
16319 +{
16320 +       struct vx_info *vxi = p->vx_info;
16321 +
16322 +       if (vxi) {
16323 +               if (vxi->vx_initpid == p->pid)
16324 +                       vx_exit_init(vxi, p, code);
16325 +               if (vxi->vx_reaper == p)
16326 +                       vx_set_reaper(vxi, init_pid_ns.child_reaper);
16327 +       }
16328 +}
16329 +
16330 +
16331 +/* vserver syscall commands below here */
16332 +
16333 +/* taks xid and vx_info functions */
16334 +
16335 +#include <asm/uaccess.h>
16336 +
16337 +
16338 +int vc_task_xid(uint32_t id)
16339 +{
16340 +       xid_t xid;
16341 +
16342 +       if (id) {
16343 +               struct task_struct *tsk;
16344 +
16345 +               rcu_read_lock();
16346 +               tsk = find_task_by_real_pid(id);
16347 +               xid = (tsk) ? tsk->xid : -ESRCH;
16348 +               rcu_read_unlock();
16349 +       } else
16350 +               xid = vx_current_xid();
16351 +       return xid;
16352 +}
16353 +
16354 +
16355 +int vc_vx_info(struct vx_info *vxi, void __user *data)
16356 +{
16357 +       struct vcmd_vx_info_v0 vc_data;
16358 +
16359 +       vc_data.xid = vxi->vx_id;
16360 +       vc_data.initpid = vxi->vx_initpid;
16361 +
16362 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16363 +               return -EFAULT;
16364 +       return 0;
16365 +}
16366 +
16367 +
16368 +int vc_ctx_stat(struct vx_info *vxi, void __user *data)
16369 +{
16370 +       struct vcmd_ctx_stat_v0 vc_data;
16371 +
16372 +       vc_data.usecnt = atomic_read(&vxi->vx_usecnt);
16373 +       vc_data.tasks = atomic_read(&vxi->vx_tasks);
16374 +
16375 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16376 +               return -EFAULT;
16377 +       return 0;
16378 +}
16379 +
16380 +
16381 +/* context functions */
16382 +
16383 +int vc_ctx_create(uint32_t xid, void __user *data)
16384 +{
16385 +       struct vcmd_ctx_create vc_data = { .flagword = VXF_INIT_SET };
16386 +       struct vx_info *new_vxi;
16387 +       int ret;
16388 +
16389 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
16390 +               return -EFAULT;
16391 +
16392 +       if ((xid > MAX_S_CONTEXT) || (xid < 2))
16393 +               return -EINVAL;
16394 +
16395 +       new_vxi = __create_vx_info(xid);
16396 +       if (IS_ERR(new_vxi))
16397 +               return PTR_ERR(new_vxi);
16398 +
16399 +       /* initial flags */
16400 +       new_vxi->vx_flags = vc_data.flagword;
16401 +
16402 +       ret = -ENOEXEC;
16403 +       if (vs_state_change(new_vxi, VSC_STARTUP))
16404 +               goto out;
16405 +
16406 +       ret = vx_migrate_task(current, new_vxi, (!data));
16407 +       if (ret)
16408 +               goto out;
16409 +
16410 +       /* return context id on success */
16411 +       ret = new_vxi->vx_id;
16412 +
16413 +       /* get a reference for persistent contexts */
16414 +       if ((vc_data.flagword & VXF_PERSISTENT))
16415 +               vx_set_persistent(new_vxi);
16416 +out:
16417 +       release_vx_info(new_vxi, NULL);
16418 +       put_vx_info(new_vxi);
16419 +       return ret;
16420 +}
16421 +
16422 +
16423 +int vc_ctx_migrate(struct vx_info *vxi, void __user *data)
16424 +{
16425 +       struct vcmd_ctx_migrate vc_data = { .flagword = 0 };
16426 +       int ret;
16427 +
16428 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
16429 +               return -EFAULT;
16430 +
16431 +       ret = vx_migrate_task(current, vxi, 0);
16432 +       if (ret)
16433 +               return ret;
16434 +       if (vc_data.flagword & VXM_SET_INIT)
16435 +               ret = vx_set_init(vxi, current);
16436 +       if (ret)
16437 +               return ret;
16438 +       if (vc_data.flagword & VXM_SET_REAPER)
16439 +               ret = vx_set_reaper(vxi, current);
16440 +       return ret;
16441 +}
16442 +
16443 +
16444 +int vc_get_cflags(struct vx_info *vxi, void __user *data)
16445 +{
16446 +       struct vcmd_ctx_flags_v0 vc_data;
16447 +
16448 +       vc_data.flagword = vxi->vx_flags;
16449 +
16450 +       /* special STATE flag handling */
16451 +       vc_data.mask = vs_mask_flags(~0ULL, vxi->vx_flags, VXF_ONE_TIME);
16452 +
16453 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16454 +               return -EFAULT;
16455 +       return 0;
16456 +}
16457 +
16458 +int vc_set_cflags(struct vx_info *vxi, void __user *data)
16459 +{
16460 +       struct vcmd_ctx_flags_v0 vc_data;
16461 +       uint64_t mask, trigger;
16462 +
16463 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16464 +               return -EFAULT;
16465 +
16466 +       /* special STATE flag handling */
16467 +       mask = vs_mask_mask(vc_data.mask, vxi->vx_flags, VXF_ONE_TIME);
16468 +       trigger = (mask & vxi->vx_flags) ^ (mask & vc_data.flagword);
16469 +
16470 +       if (vxi == current_vx_info()) {
16471 +               /* if (trigger & VXF_STATE_SETUP)
16472 +                       vx_mask_cap_bset(vxi, current); */
16473 +               if (trigger & VXF_STATE_INIT) {
16474 +                       int ret;
16475 +
16476 +                       ret = vx_set_init(vxi, current);
16477 +                       if (ret)
16478 +                               return ret;
16479 +                       ret = vx_set_reaper(vxi, current);
16480 +                       if (ret)
16481 +                               return ret;
16482 +               }
16483 +       }
16484 +
16485 +       vxi->vx_flags = vs_mask_flags(vxi->vx_flags,
16486 +               vc_data.flagword, mask);
16487 +       if (trigger & VXF_PERSISTENT)
16488 +               vx_update_persistent(vxi);
16489 +
16490 +       return 0;
16491 +}
16492 +
16493 +
16494 +static inline uint64_t caps_from_cap_t(kernel_cap_t c)
16495 +{
16496 +       uint64_t v = c.cap[0] | ((uint64_t)c.cap[1] << 32);
16497 +
16498 +       // printk("caps_from_cap_t(%08x:%08x) = %016llx\n", c.cap[1], c.cap[0], v);
16499 +       return v;
16500 +}
16501 +
16502 +static inline kernel_cap_t cap_t_from_caps(uint64_t v)
16503 +{
16504 +       kernel_cap_t c = __cap_empty_set;
16505 +
16506 +       c.cap[0] = v & 0xFFFFFFFF;
16507 +       c.cap[1] = (v >> 32) & 0xFFFFFFFF;
16508 +
16509 +       // printk("cap_t_from_caps(%016llx) = %08x:%08x\n", v, c.cap[1], c.cap[0]);
16510 +       return c;
16511 +}
16512 +
16513 +
16514 +static int do_get_caps(struct vx_info *vxi, uint64_t *bcaps, uint64_t *ccaps)
16515 +{
16516 +       if (bcaps)
16517 +               *bcaps = caps_from_cap_t(vxi->vx_bcaps);
16518 +       if (ccaps)
16519 +               *ccaps = vxi->vx_ccaps;
16520 +
16521 +       return 0;
16522 +}
16523 +
16524 +int vc_get_ccaps(struct vx_info *vxi, void __user *data)
16525 +{
16526 +       struct vcmd_ctx_caps_v1 vc_data;
16527 +       int ret;
16528 +
16529 +       ret = do_get_caps(vxi, NULL, &vc_data.ccaps);
16530 +       if (ret)
16531 +               return ret;
16532 +       vc_data.cmask = ~0ULL;
16533 +
16534 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16535 +               return -EFAULT;
16536 +       return 0;
16537 +}
16538 +
16539 +static int do_set_caps(struct vx_info *vxi,
16540 +       uint64_t bcaps, uint64_t bmask, uint64_t ccaps, uint64_t cmask)
16541 +{
16542 +       uint64_t bcold = caps_from_cap_t(vxi->vx_bcaps);
16543 +
16544 +#if 0
16545 +       printk("do_set_caps(%16llx, %16llx, %16llx, %16llx)\n",
16546 +               bcaps, bmask, ccaps, cmask);
16547 +#endif
16548 +       vxi->vx_bcaps = cap_t_from_caps(
16549 +               vs_mask_flags(bcold, bcaps, bmask));
16550 +       vxi->vx_ccaps = vs_mask_flags(vxi->vx_ccaps, ccaps, cmask);
16551 +
16552 +       return 0;
16553 +}
16554 +
16555 +int vc_set_ccaps(struct vx_info *vxi, void __user *data)
16556 +{
16557 +       struct vcmd_ctx_caps_v1 vc_data;
16558 +
16559 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16560 +               return -EFAULT;
16561 +
16562 +       return do_set_caps(vxi, 0, 0, vc_data.ccaps, vc_data.cmask);
16563 +}
16564 +
16565 +int vc_get_bcaps(struct vx_info *vxi, void __user *data)
16566 +{
16567 +       struct vcmd_bcaps vc_data;
16568 +       int ret;
16569 +
16570 +       ret = do_get_caps(vxi, &vc_data.bcaps, NULL);
16571 +       if (ret)
16572 +               return ret;
16573 +       vc_data.bmask = ~0ULL;
16574 +
16575 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16576 +               return -EFAULT;
16577 +       return 0;
16578 +}
16579 +
16580 +int vc_set_bcaps(struct vx_info *vxi, void __user *data)
16581 +{
16582 +       struct vcmd_bcaps vc_data;
16583 +
16584 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16585 +               return -EFAULT;
16586 +
16587 +       return do_set_caps(vxi, vc_data.bcaps, vc_data.bmask, 0, 0);
16588 +}
16589 +
16590 +
16591 +int vc_get_umask(struct vx_info *vxi, void __user *data)
16592 +{
16593 +       struct vcmd_umask vc_data;
16594 +
16595 +       vc_data.umask = vxi->vx_umask;
16596 +       vc_data.mask = ~0ULL;
16597 +
16598 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16599 +               return -EFAULT;
16600 +       return 0;
16601 +}
16602 +
16603 +int vc_set_umask(struct vx_info *vxi, void __user *data)
16604 +{
16605 +       struct vcmd_umask vc_data;
16606 +
16607 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16608 +               return -EFAULT;
16609 +
16610 +       vxi->vx_umask = vs_mask_flags(vxi->vx_umask,
16611 +               vc_data.umask, vc_data.mask);
16612 +       return 0;
16613 +}
16614 +
16615 +
16616 +int vc_get_wmask(struct vx_info *vxi, void __user *data)
16617 +{
16618 +       struct vcmd_wmask vc_data;
16619 +
16620 +       vc_data.wmask = vxi->vx_wmask;
16621 +       vc_data.mask = ~0ULL;
16622 +
16623 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16624 +               return -EFAULT;
16625 +       return 0;
16626 +}
16627 +
16628 +int vc_set_wmask(struct vx_info *vxi, void __user *data)
16629 +{
16630 +       struct vcmd_wmask vc_data;
16631 +
16632 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16633 +               return -EFAULT;
16634 +
16635 +       vxi->vx_wmask = vs_mask_flags(vxi->vx_wmask,
16636 +               vc_data.wmask, vc_data.mask);
16637 +       return 0;
16638 +}
16639 +
16640 +
16641 +int vc_get_badness(struct vx_info *vxi, void __user *data)
16642 +{
16643 +       struct vcmd_badness_v0 vc_data;
16644 +
16645 +       vc_data.bias = vxi->vx_badness_bias;
16646 +
16647 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16648 +               return -EFAULT;
16649 +       return 0;
16650 +}
16651 +
16652 +int vc_set_badness(struct vx_info *vxi, void __user *data)
16653 +{
16654 +       struct vcmd_badness_v0 vc_data;
16655 +
16656 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16657 +               return -EFAULT;
16658 +
16659 +       vxi->vx_badness_bias = vc_data.bias;
16660 +       return 0;
16661 +}
16662 +
16663 +#include <linux/module.h>
16664 +
16665 +EXPORT_SYMBOL_GPL(free_vx_info);
16666 +
16667 diff -NurpP --minimal linux-3.9.4/kernel/vserver/cvirt.c linux-3.9.4-vs2.3.6.2/kernel/vserver/cvirt.c
16668 --- linux-3.9.4/kernel/vserver/cvirt.c  1970-01-01 00:00:00.000000000 +0000
16669 +++ linux-3.9.4-vs2.3.6.2/kernel/vserver/cvirt.c        2013-05-31 14:47:11.000000000 +0000
16670 @@ -0,0 +1,313 @@
16671 +/*
16672 + *  linux/kernel/vserver/cvirt.c
16673 + *
16674 + *  Virtual Server: Context Virtualization
16675 + *
16676 + *  Copyright (C) 2004-2007  Herbert Pötzl
16677 + *
16678 + *  V0.01  broken out from limit.c
16679 + *  V0.02  added utsname stuff
16680 + *  V0.03  changed vcmds to vxi arg
16681 + *
16682 + */
16683 +
16684 +#include <linux/types.h>
16685 +#include <linux/utsname.h>
16686 +#include <linux/vs_cvirt.h>
16687 +#include <linux/vserver/switch.h>
16688 +#include <linux/vserver/cvirt_cmd.h>
16689 +
16690 +#include <asm/uaccess.h>
16691 +
16692 +
16693 +void vx_vsi_boottime(struct timespec *boottime)
16694 +{
16695 +       struct vx_info *vxi = current_vx_info();
16696 +
16697 +       set_normalized_timespec(boottime,
16698 +               boottime->tv_sec + vxi->cvirt.bias_uptime.tv_sec,
16699 +               boottime->tv_nsec + vxi->cvirt.bias_uptime.tv_nsec);
16700 +       return;
16701 +}
16702 +
16703 +void vx_vsi_uptime(struct timespec *uptime, struct timespec *idle)
16704 +{
16705 +       struct vx_info *vxi = current_vx_info();
16706 +
16707 +       set_normalized_timespec(uptime,
16708 +               uptime->tv_sec - vxi->cvirt.bias_uptime.tv_sec,
16709 +               uptime->tv_nsec - vxi->cvirt.bias_uptime.tv_nsec);
16710 +       if (!idle)
16711 +               return;
16712 +       set_normalized_timespec(idle,
16713 +               idle->tv_sec - vxi->cvirt.bias_idle.tv_sec,
16714 +               idle->tv_nsec - vxi->cvirt.bias_idle.tv_nsec);
16715 +       return;
16716 +}
16717 +
16718 +uint64_t vx_idle_jiffies(void)
16719 +{
16720 +       return init_task.utime + init_task.stime;
16721 +}
16722 +
16723 +
16724 +
16725 +static inline uint32_t __update_loadavg(uint32_t load,
16726 +       int wsize, int delta, int n)
16727 +{
16728 +       unsigned long long calc, prev;
16729 +
16730 +       /* just set it to n */
16731 +       if (unlikely(delta >= wsize))
16732 +               return (n << FSHIFT);
16733 +
16734 +       calc = delta * n;
16735 +       calc <<= FSHIFT;
16736 +       prev = (wsize - delta);
16737 +       prev *= load;
16738 +       calc += prev;
16739 +       do_div(calc, wsize);
16740 +       return calc;
16741 +}
16742 +
16743 +
16744 +void vx_update_load(struct vx_info *vxi)
16745 +{
16746 +       uint32_t now, last, delta;
16747 +       unsigned int nr_running, nr_uninterruptible;
16748 +       unsigned int total;
16749 +       unsigned long flags;
16750 +
16751 +       spin_lock_irqsave(&vxi->cvirt.load_lock, flags);
16752 +
16753 +       now = jiffies;
16754 +       last = vxi->cvirt.load_last;
16755 +       delta = now - last;
16756 +
16757 +       if (delta < 5*HZ)
16758 +               goto out;
16759 +
16760 +       nr_running = atomic_read(&vxi->cvirt.nr_running);
16761 +       nr_uninterruptible = atomic_read(&vxi->cvirt.nr_uninterruptible);
16762 +       total = nr_running + nr_uninterruptible;
16763 +
16764 +       vxi->cvirt.load[0] = __update_loadavg(vxi->cvirt.load[0],
16765 +               60*HZ, delta, total);
16766 +       vxi->cvirt.load[1] = __update_loadavg(vxi->cvirt.load[1],
16767 +               5*60*HZ, delta, total);
16768 +       vxi->cvirt.load[2] = __update_loadavg(vxi->cvirt.load[2],
16769 +               15*60*HZ, delta, total);
16770 +
16771 +       vxi->cvirt.load_last = now;
16772 +out:
16773 +       atomic_inc(&vxi->cvirt.load_updates);
16774 +       spin_unlock_irqrestore(&vxi->cvirt.load_lock, flags);
16775 +}
16776 +
16777 +
16778 +/*
16779 + * Commands to do_syslog:
16780 + *
16781 + *      0 -- Close the log.  Currently a NOP.
16782 + *      1 -- Open the log. Currently a NOP.
16783 + *      2 -- Read from the log.
16784 + *      3 -- Read all messages remaining in the ring buffer.
16785 + *      4 -- Read and clear all messages remaining in the ring buffer
16786 + *      5 -- Clear ring buffer.
16787 + *      6 -- Disable printk's to console
16788 + *      7 -- Enable printk's to console
16789 + *      8 -- Set level of messages printed to console
16790 + *      9 -- Return number of unread characters in the log buffer
16791 + *     10 -- Return size of the log buffer
16792 + */
16793 +int vx_do_syslog(int type, char __user *buf, int len)
16794 +{
16795 +       int error = 0;
16796 +       int do_clear = 0;
16797 +       struct vx_info *vxi = current_vx_info();
16798 +       struct _vx_syslog *log;
16799 +
16800 +       if (!vxi)
16801 +               return -EINVAL;
16802 +       log = &vxi->cvirt.syslog;
16803 +
16804 +       switch (type) {
16805 +       case 0:         /* Close log */
16806 +       case 1:         /* Open log */
16807 +               break;
16808 +       case 2:         /* Read from log */
16809 +               error = wait_event_interruptible(log->log_wait,
16810 +                       (log->log_start - log->log_end));
16811 +               if (error)
16812 +                       break;
16813 +               spin_lock_irq(&log->logbuf_lock);
16814 +               spin_unlock_irq(&log->logbuf_lock);
16815 +               break;
16816 +       case 4:         /* Read/clear last kernel messages */
16817 +               do_clear = 1;
16818 +               /* fall through */
16819 +       case 3:         /* Read last kernel messages */
16820 +               return 0;
16821 +
16822 +       case 5:         /* Clear ring buffer */
16823 +               return 0;
16824 +
16825 +       case 6:         /* Disable logging to console */
16826 +       case 7:         /* Enable logging to console */
16827 +       case 8:         /* Set level of messages printed to console */
16828 +               break;
16829 +
16830 +       case 9:         /* Number of chars in the log buffer */
16831 +               return 0;
16832 +       case 10:        /* Size of the log buffer */
16833 +               return 0;
16834 +       default:
16835 +               error = -EINVAL;
16836 +               break;
16837 +       }
16838 +       return error;
16839 +}
16840 +
16841 +
16842 +/* virtual host info names */
16843 +
16844 +static char *vx_vhi_name(struct vx_info *vxi, int id)
16845 +{
16846 +       struct nsproxy *nsproxy;
16847 +       struct uts_namespace *uts;
16848 +
16849 +       if (id == VHIN_CONTEXT)
16850 +               return vxi->vx_name;
16851 +
16852 +       nsproxy = vxi->space[0].vx_nsproxy;
16853 +       if (!nsproxy)
16854 +               return NULL;
16855 +
16856 +       uts = nsproxy->uts_ns;
16857 +       if (!uts)
16858 +               return NULL;
16859 +
16860 +       switch (id) {
16861 +       case VHIN_SYSNAME:
16862 +               return uts->name.sysname;
16863 +       case VHIN_NODENAME:
16864 +               return uts->name.nodename;
16865 +       case VHIN_RELEASE:
16866 +               return uts->name.release;
16867 +       case VHIN_VERSION:
16868 +               return uts->name.version;
16869 +       case VHIN_MACHINE:
16870 +               return uts->name.machine;
16871 +       case VHIN_DOMAINNAME:
16872 +               return uts->name.domainname;
16873 +       default:
16874 +               return NULL;
16875 +       }
16876 +       return NULL;
16877 +}
16878 +
16879 +int vc_set_vhi_name(struct vx_info *vxi, void __user *data)
16880 +{
16881 +       struct vcmd_vhi_name_v0 vc_data;
16882 +       char *name;
16883 +
16884 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16885 +               return -EFAULT;
16886 +
16887 +       name = vx_vhi_name(vxi, vc_data.field);
16888 +       if (!name)
16889 +               return -EINVAL;
16890 +
16891 +       memcpy(name, vc_data.name, 65);
16892 +       return 0;
16893 +}
16894 +
16895 +int vc_get_vhi_name(struct vx_info *vxi, void __user *data)
16896 +{
16897 +       struct vcmd_vhi_name_v0 vc_data;
16898 +       char *name;
16899 +
16900 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16901 +               return -EFAULT;
16902 +
16903 +       name = vx_vhi_name(vxi, vc_data.field);
16904 +       if (!name)
16905 +               return -EINVAL;
16906 +
16907 +       memcpy(vc_data.name, name, 65);
16908 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16909 +               return -EFAULT;
16910 +       return 0;
16911 +}
16912 +
16913 +
16914 +int vc_virt_stat(struct vx_info *vxi, void __user *data)
16915 +{
16916 +       struct vcmd_virt_stat_v0 vc_data;
16917 +       struct _vx_cvirt *cvirt = &vxi->cvirt;
16918 +       struct timespec uptime;
16919 +
16920 +       do_posix_clock_monotonic_gettime(&uptime);
16921 +       set_normalized_timespec(&uptime,
16922 +               uptime.tv_sec - cvirt->bias_uptime.tv_sec,
16923 +               uptime.tv_nsec - cvirt->bias_uptime.tv_nsec);
16924 +
16925 +       vc_data.offset = timespec_to_ns(&cvirt->bias_ts);
16926 +       vc_data.uptime = timespec_to_ns(&uptime);
16927 +       vc_data.nr_threads = atomic_read(&cvirt->nr_threads);
16928 +       vc_data.nr_running = atomic_read(&cvirt->nr_running);
16929 +       vc_data.nr_uninterruptible = atomic_read(&cvirt->nr_uninterruptible);
16930 +       vc_data.nr_onhold = atomic_read(&cvirt->nr_onhold);
16931 +       vc_data.nr_forks = atomic_read(&cvirt->total_forks);
16932 +       vc_data.load[0] = cvirt->load[0];
16933 +       vc_data.load[1] = cvirt->load[1];
16934 +       vc_data.load[2] = cvirt->load[2];
16935 +
16936 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16937 +               return -EFAULT;
16938 +       return 0;
16939 +}
16940 +
16941 +
16942 +#ifdef CONFIG_VSERVER_VTIME
16943 +
16944 +/* virtualized time base */
16945 +
16946 +void vx_adjust_timespec(struct timespec *ts)
16947 +{
16948 +       struct vx_info *vxi;
16949 +
16950 +       if (!vx_flags(VXF_VIRT_TIME, 0))
16951 +               return;
16952 +
16953 +       vxi = current_vx_info();
16954 +       ts->tv_sec += vxi->cvirt.bias_ts.tv_sec;
16955 +       ts->tv_nsec += vxi->cvirt.bias_ts.tv_nsec;
16956 +
16957 +       if (ts->tv_nsec >= NSEC_PER_SEC) {
16958 +               ts->tv_sec++;
16959 +               ts->tv_nsec -= NSEC_PER_SEC;
16960 +       } else if (ts->tv_nsec < 0) {
16961 +               ts->tv_sec--;
16962 +               ts->tv_nsec += NSEC_PER_SEC;
16963 +       }
16964 +}
16965 +
16966 +int vx_settimeofday(const struct timespec *ts)
16967 +{
16968 +       struct timespec ats, delta;
16969 +       struct vx_info *vxi;
16970 +
16971 +       if (!vx_flags(VXF_VIRT_TIME, 0))
16972 +               return do_settimeofday(ts);
16973 +
16974 +       getnstimeofday(&ats);
16975 +       delta = timespec_sub(*ts, ats);
16976 +
16977 +       vxi = current_vx_info();
16978 +       vxi->cvirt.bias_ts = timespec_add(vxi->cvirt.bias_ts, delta);
16979 +       return 0;
16980 +}
16981 +
16982 +#endif
16983 +
16984 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
16985 --- linux-3.9.4/kernel/vserver/cvirt_init.h     1970-01-01 00:00:00.000000000 +0000
16986 +++ linux-3.9.4-vs2.3.6.2/kernel/vserver/cvirt_init.h   2013-05-31 14:47:11.000000000 +0000
16987 @@ -0,0 +1,70 @@
16988 +
16989 +
16990 +extern uint64_t vx_idle_jiffies(void);
16991 +
16992 +static inline void vx_info_init_cvirt(struct _vx_cvirt *cvirt)
16993 +{
16994 +       uint64_t idle_jiffies = vx_idle_jiffies();
16995 +       uint64_t nsuptime;
16996 +
16997 +       do_posix_clock_monotonic_gettime(&cvirt->bias_uptime);
16998 +       nsuptime = (unsigned long long)cvirt->bias_uptime.tv_sec
16999 +               * NSEC_PER_SEC + cvirt->bias_uptime.tv_nsec;
17000 +       cvirt->bias_clock = nsec_to_clock_t(nsuptime);
17001 +       cvirt->bias_ts.tv_sec = 0;
17002 +       cvirt->bias_ts.tv_nsec = 0;
17003 +
17004 +       jiffies_to_timespec(idle_jiffies, &cvirt->bias_idle);
17005 +       atomic_set(&cvirt->nr_threads, 0);
17006 +       atomic_set(&cvirt->nr_running, 0);
17007 +       atomic_set(&cvirt->nr_uninterruptible, 0);
17008 +       atomic_set(&cvirt->nr_onhold, 0);
17009 +
17010 +       spin_lock_init(&cvirt->load_lock);
17011 +       cvirt->load_last = jiffies;
17012 +       atomic_set(&cvirt->load_updates, 0);
17013 +       cvirt->load[0] = 0;
17014 +       cvirt->load[1] = 0;
17015 +       cvirt->load[2] = 0;
17016 +       atomic_set(&cvirt->total_forks, 0);
17017 +
17018 +       spin_lock_init(&cvirt->syslog.logbuf_lock);
17019 +       init_waitqueue_head(&cvirt->syslog.log_wait);
17020 +       cvirt->syslog.log_start = 0;
17021 +       cvirt->syslog.log_end = 0;
17022 +       cvirt->syslog.con_start = 0;
17023 +       cvirt->syslog.logged_chars = 0;
17024 +}
17025 +
17026 +static inline
17027 +void vx_info_init_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc, int cpu)
17028 +{
17029 +       // cvirt_pc->cpustat = { 0 };
17030 +}
17031 +
17032 +static inline void vx_info_exit_cvirt(struct _vx_cvirt *cvirt)
17033 +{
17034 +#ifdef CONFIG_VSERVER_WARN
17035 +       int value;
17036 +#endif
17037 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_threads)),
17038 +               "!!! cvirt: %p[nr_threads] = %d on exit.",
17039 +               cvirt, value);
17040 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_running)),
17041 +               "!!! cvirt: %p[nr_running] = %d on exit.",
17042 +               cvirt, value);
17043 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_uninterruptible)),
17044 +               "!!! cvirt: %p[nr_uninterruptible] = %d on exit.",
17045 +               cvirt, value);
17046 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_onhold)),
17047 +               "!!! cvirt: %p[nr_onhold] = %d on exit.",
17048 +               cvirt, value);
17049 +       return;
17050 +}
17051 +
17052 +static inline
17053 +void vx_info_exit_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc, int cpu)
17054 +{
17055 +       return;
17056 +}
17057 +
17058 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
17059 --- linux-3.9.4/kernel/vserver/cvirt_proc.h     1970-01-01 00:00:00.000000000 +0000
17060 +++ linux-3.9.4-vs2.3.6.2/kernel/vserver/cvirt_proc.h   2013-05-31 19:38:26.000000000 +0000
17061 @@ -0,0 +1,123 @@
17062 +#ifndef _VX_CVIRT_PROC_H
17063 +#define _VX_CVIRT_PROC_H
17064 +
17065 +#include <linux/nsproxy.h>
17066 +#include <linux/mnt_namespace.h>
17067 +#include <linux/ipc_namespace.h>
17068 +#include <linux/utsname.h>
17069 +#include <linux/ipc.h>
17070 +
17071 +extern int vx_info_mnt_namespace(struct mnt_namespace *, char *);
17072 +
17073 +static inline
17074 +int vx_info_proc_nsproxy(struct nsproxy *nsproxy, char *buffer)
17075 +{
17076 +       struct mnt_namespace *ns;
17077 +       struct uts_namespace *uts;
17078 +       struct ipc_namespace *ipc;
17079 +       int length = 0;
17080 +
17081 +       if (!nsproxy)
17082 +               goto out;
17083 +
17084 +       length += sprintf(buffer + length,
17085 +               "NSProxy:\t%p [%p,%p,%p]\n",
17086 +               nsproxy, nsproxy->mnt_ns,
17087 +               nsproxy->uts_ns, nsproxy->ipc_ns);
17088 +
17089 +       ns = nsproxy->mnt_ns;
17090 +       if (!ns)
17091 +               goto skip_ns;
17092 +
17093 +       length += vx_info_mnt_namespace(ns, buffer + length);
17094 +
17095 +skip_ns:
17096 +
17097 +       uts = nsproxy->uts_ns;
17098 +       if (!uts)
17099 +               goto skip_uts;
17100 +
17101 +       length += sprintf(buffer + length,
17102 +               "SysName:\t%.*s\n"
17103 +               "NodeName:\t%.*s\n"
17104 +               "Release:\t%.*s\n"
17105 +               "Version:\t%.*s\n"
17106 +               "Machine:\t%.*s\n"
17107 +               "DomainName:\t%.*s\n",
17108 +               __NEW_UTS_LEN, uts->name.sysname,
17109 +               __NEW_UTS_LEN, uts->name.nodename,
17110 +               __NEW_UTS_LEN, uts->name.release,
17111 +               __NEW_UTS_LEN, uts->name.version,
17112 +               __NEW_UTS_LEN, uts->name.machine,
17113 +               __NEW_UTS_LEN, uts->name.domainname);
17114 +skip_uts:
17115 +
17116 +       ipc = nsproxy->ipc_ns;
17117 +       if (!ipc)
17118 +               goto skip_ipc;
17119 +
17120 +       length += sprintf(buffer + length,
17121 +               "SEMS:\t\t%d %d %d %d  %d\n"
17122 +               "MSG:\t\t%d %d %d\n"
17123 +               "SHM:\t\t%lu %lu  %d %ld\n",
17124 +               ipc->sem_ctls[0], ipc->sem_ctls[1],
17125 +               ipc->sem_ctls[2], ipc->sem_ctls[3],
17126 +               ipc->used_sems,
17127 +               ipc->msg_ctlmax, ipc->msg_ctlmnb, ipc->msg_ctlmni,
17128 +               (unsigned long)ipc->shm_ctlmax,
17129 +               (unsigned long)ipc->shm_ctlall,
17130 +               ipc->shm_ctlmni, ipc->shm_tot);
17131 +skip_ipc:
17132 +out:
17133 +       return length;
17134 +}
17135 +
17136 +
17137 +#include <linux/sched.h>
17138 +
17139 +#define LOAD_INT(x) ((x) >> FSHIFT)
17140 +#define LOAD_FRAC(x) LOAD_INT(((x) & (FIXED_1 - 1)) * 100)
17141 +
17142 +static inline
17143 +int vx_info_proc_cvirt(struct _vx_cvirt *cvirt, char *buffer)
17144 +{
17145 +       int length = 0;
17146 +       int a, b, c;
17147 +
17148 +       length += sprintf(buffer + length,
17149 +               "BiasUptime:\t%lu.%02lu\n",
17150 +               (unsigned long)cvirt->bias_uptime.tv_sec,
17151 +               (cvirt->bias_uptime.tv_nsec / (NSEC_PER_SEC / 100)));
17152 +
17153 +       a = cvirt->load[0] + (FIXED_1 / 200);
17154 +       b = cvirt->load[1] + (FIXED_1 / 200);
17155 +       c = cvirt->load[2] + (FIXED_1 / 200);
17156 +       length += sprintf(buffer + length,
17157 +               "nr_threads:\t%d\n"
17158 +               "nr_running:\t%d\n"
17159 +               "nr_unintr:\t%d\n"
17160 +               "nr_onhold:\t%d\n"
17161 +               "load_updates:\t%d\n"
17162 +               "loadavg:\t%d.%02d %d.%02d %d.%02d\n"
17163 +               "total_forks:\t%d\n",
17164 +               atomic_read(&cvirt->nr_threads),
17165 +               atomic_read(&cvirt->nr_running),
17166 +               atomic_read(&cvirt->nr_uninterruptible),
17167 +               atomic_read(&cvirt->nr_onhold),
17168 +               atomic_read(&cvirt->load_updates),
17169 +               LOAD_INT(a), LOAD_FRAC(a),
17170 +               LOAD_INT(b), LOAD_FRAC(b),
17171 +               LOAD_INT(c), LOAD_FRAC(c),
17172 +               atomic_read(&cvirt->total_forks));
17173 +       return length;
17174 +}
17175 +
17176 +static inline
17177 +int vx_info_proc_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc,
17178 +       char *buffer, int cpu)
17179 +{
17180 +       int length = 0;
17181 +       return length;
17182 +}
17183 +
17184 +#endif /* _VX_CVIRT_PROC_H */
17185 diff -NurpP --minimal linux-3.9.4/kernel/vserver/debug.c linux-3.9.4-vs2.3.6.2/kernel/vserver/debug.c
17186 --- linux-3.9.4/kernel/vserver/debug.c  1970-01-01 00:00:00.000000000 +0000
17187 +++ linux-3.9.4-vs2.3.6.2/kernel/vserver/debug.c        2013-05-31 14:47:11.000000000 +0000
17188 @@ -0,0 +1,32 @@
17189 +/*
17190 + *  kernel/vserver/debug.c
17191 + *
17192 + *  Copyright (C) 2005-2007 Herbert Pötzl
17193 + *
17194 + *  V0.01  vx_info dump support
17195 + *
17196 + */
17197 +
17198 +#include <linux/module.h>
17199 +
17200 +#include <linux/vserver/context.h>
17201 +
17202 +
17203 +void   dump_vx_info(struct vx_info *vxi, int level)
17204 +{
17205 +       printk("vx_info %p[#%d, %d.%d, %4x]\n", vxi, vxi->vx_id,
17206 +               atomic_read(&vxi->vx_usecnt),
17207 +               atomic_read(&vxi->vx_tasks),
17208 +               vxi->vx_state);
17209 +       if (level > 0) {
17210 +               __dump_vx_limit(&vxi->limit);
17211 +               __dump_vx_sched(&vxi->sched);
17212 +               __dump_vx_cvirt(&vxi->cvirt);
17213 +               __dump_vx_cacct(&vxi->cacct);
17214 +       }
17215 +       printk("---\n");
17216 +}
17217 +
17218 +
17219 +EXPORT_SYMBOL_GPL(dump_vx_info);
17220 +
17221 diff -NurpP --minimal linux-3.9.4/kernel/vserver/device.c linux-3.9.4-vs2.3.6.2/kernel/vserver/device.c
17222 --- linux-3.9.4/kernel/vserver/device.c 1970-01-01 00:00:00.000000000 +0000
17223 +++ linux-3.9.4-vs2.3.6.2/kernel/vserver/device.c       2013-05-31 14:47:11.000000000 +0000
17224 @@ -0,0 +1,443 @@
17225 +/*
17226 + *  linux/kernel/vserver/device.c
17227 + *
17228 + *  Linux-VServer: Device Support
17229 + *
17230 + *  Copyright (C) 2006  Herbert Pötzl
17231 + *  Copyright (C) 2007  Daniel Hokka Zakrisson
17232 + *
17233 + *  V0.01  device mapping basics
17234 + *  V0.02  added defaults
17235 + *
17236 + */
17237 +
17238 +#include <linux/slab.h>
17239 +#include <linux/rcupdate.h>
17240 +#include <linux/fs.h>
17241 +#include <linux/namei.h>
17242 +#include <linux/hash.h>
17243 +
17244 +#include <asm/errno.h>
17245 +#include <asm/uaccess.h>
17246 +#include <linux/vserver/base.h>
17247 +#include <linux/vserver/debug.h>
17248 +#include <linux/vserver/context.h>
17249 +#include <linux/vserver/device.h>
17250 +#include <linux/vserver/device_cmd.h>
17251 +
17252 +
17253 +#define DMAP_HASH_BITS 4
17254 +
17255 +
17256 +struct vs_mapping {
17257 +       union {
17258 +               struct hlist_node hlist;
17259 +               struct list_head list;
17260 +       } u;
17261 +#define dm_hlist       u.hlist
17262 +#define dm_list                u.list
17263 +       xid_t xid;
17264 +       dev_t device;
17265 +       struct vx_dmap_target target;
17266 +};
17267 +
17268 +
17269 +static struct hlist_head dmap_main_hash[1 << DMAP_HASH_BITS];
17270 +
17271 +static DEFINE_SPINLOCK(dmap_main_hash_lock);
17272 +
17273 +static struct vx_dmap_target dmap_defaults[2] = {
17274 +       { .flags = DATTR_OPEN },
17275 +       { .flags = DATTR_OPEN },
17276 +};
17277 +
17278 +
17279 +struct kmem_cache *dmap_cachep __read_mostly;
17280 +
17281 +int __init dmap_cache_init(void)
17282 +{
17283 +       dmap_cachep = kmem_cache_create("dmap_cache",
17284 +               sizeof(struct vs_mapping), 0,
17285 +               SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
17286 +       return 0;
17287 +}
17288 +
17289 +__initcall(dmap_cache_init);
17290 +
17291 +
17292 +static inline unsigned int __hashval(dev_t dev, int bits)
17293 +{
17294 +       return hash_long((unsigned long)dev, bits);
17295 +}
17296 +
17297 +
17298 +/*     __hash_mapping()
17299 + *     add the mapping to the hash table
17300 + */
17301 +static inline void __hash_mapping(struct vx_info *vxi, struct vs_mapping *vdm)
17302 +{
17303 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
17304 +       struct hlist_head *head, *hash = dmap_main_hash;
17305 +       int device = vdm->device;
17306 +
17307 +       spin_lock(hash_lock);
17308 +       vxdprintk(VXD_CBIT(misc, 8), "__hash_mapping: %p[#%d] %08x:%08x",
17309 +               vxi, vxi ? vxi->vx_id : 0, device, vdm->target.target);
17310 +
17311 +       head = &hash[__hashval(device, DMAP_HASH_BITS)];
17312 +       hlist_add_head(&vdm->dm_hlist, head);
17313 +       spin_unlock(hash_lock);
17314 +}
17315 +
17316 +
17317 +static inline int __mode_to_default(umode_t mode)
17318 +{
17319 +       switch (mode) {
17320 +       case S_IFBLK:
17321 +               return 0;
17322 +       case S_IFCHR:
17323 +               return 1;
17324 +       default:
17325 +               BUG();
17326 +       }
17327 +}
17328 +
17329 +
17330 +/*     __set_default()
17331 + *     set a default
17332 + */
17333 +static inline void __set_default(struct vx_info *vxi, umode_t mode,
17334 +       struct vx_dmap_target *vdmt)
17335 +{
17336 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
17337 +       spin_lock(hash_lock);
17338 +
17339 +       if (vxi)
17340 +               vxi->dmap.targets[__mode_to_default(mode)] = *vdmt;
17341 +       else
17342 +               dmap_defaults[__mode_to_default(mode)] = *vdmt;
17343 +
17344 +
17345 +       spin_unlock(hash_lock);
17346 +
17347 +       vxdprintk(VXD_CBIT(misc, 8), "__set_default: %p[#%u] %08x %04x",
17348 +                 vxi, vxi ? vxi->vx_id : 0, vdmt->target, vdmt->flags);
17349 +}
17350 +
17351 +
17352 +/*     __remove_default()
17353 + *     remove a default
17354 + */
17355 +static inline int __remove_default(struct vx_info *vxi, umode_t mode)
17356 +{
17357 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
17358 +       spin_lock(hash_lock);
17359 +
17360 +       if (vxi)
17361 +               vxi->dmap.targets[__mode_to_default(mode)].flags = 0;
17362 +       else    /* remove == reset */
17363 +               dmap_defaults[__mode_to_default(mode)].flags = DATTR_OPEN | mode;
17364 +
17365 +       spin_unlock(hash_lock);
17366 +       return 0;
17367 +}
17368 +
17369 +
17370 +/*     __find_mapping()
17371 + *     find a mapping in the hash table
17372 + *
17373 + *     caller must hold hash_lock
17374 + */
17375 +static inline int __find_mapping(xid_t xid, dev_t device, umode_t mode,
17376 +       struct vs_mapping **local, struct vs_mapping **global)
17377 +{
17378 +       struct hlist_head *hash = dmap_main_hash;
17379 +       struct hlist_head *head = &hash[__hashval(device, DMAP_HASH_BITS)];
17380 +       struct hlist_node *pos;
17381 +       struct vs_mapping *vdm;
17382 +
17383 +       *local = NULL;
17384 +       if (global)
17385 +               *global = NULL;
17386 +
17387 +       hlist_for_each(pos, head) {
17388 +               vdm = hlist_entry(pos, struct vs_mapping, dm_hlist);
17389 +
17390 +               if ((vdm->device == device) &&
17391 +                       !((vdm->target.flags ^ mode) & S_IFMT)) {
17392 +                       if (vdm->xid == xid) {
17393 +                               *local = vdm;
17394 +                               return 1;
17395 +                       } else if (global && vdm->xid == 0)
17396 +                               *global = vdm;
17397 +               }
17398 +       }
17399 +
17400 +       if (global && *global)
17401 +               return 0;
17402 +       else
17403 +               return -ENOENT;
17404 +}
17405 +
17406 +
17407 +/*     __lookup_mapping()
17408 + *     find a mapping and store the result in target and flags
17409 + */
17410 +static inline int __lookup_mapping(struct vx_info *vxi,
17411 +       dev_t device, dev_t *target, int *flags, umode_t mode)
17412 +{
17413 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
17414 +       struct vs_mapping *vdm, *global;
17415 +       struct vx_dmap_target *vdmt;
17416 +       int ret = 0;
17417 +       xid_t xid = vxi->vx_id;
17418 +       int index;
17419 +
17420 +       spin_lock(hash_lock);
17421 +       if (__find_mapping(xid, device, mode, &vdm, &global) > 0) {
17422 +               ret = 1;
17423 +               vdmt = &vdm->target;
17424 +               goto found;
17425 +       }
17426 +
17427 +       index = __mode_to_default(mode);
17428 +       if (vxi && vxi->dmap.targets[index].flags) {
17429 +               ret = 2;
17430 +               vdmt = &vxi->dmap.targets[index];
17431 +       } else if (global) {
17432 +               ret = 3;
17433 +               vdmt = &global->target;
17434 +               goto found;
17435 +       } else {
17436 +               ret = 4;
17437 +               vdmt = &dmap_defaults[index];
17438 +       }
17439 +
17440 +found:
17441 +       if (target && (vdmt->flags & DATTR_REMAP))
17442 +               *target = vdmt->target;
17443 +       else if (target)
17444 +               *target = device;
17445 +       if (flags)
17446 +               *flags = vdmt->flags;
17447 +
17448 +       spin_unlock(hash_lock);
17449 +
17450 +       return ret;
17451 +}
17452 +
17453 +
17454 +/*     __remove_mapping()
17455 + *     remove a mapping from the hash table
17456 + */
17457 +static inline int __remove_mapping(struct vx_info *vxi, dev_t device,
17458 +       umode_t mode)
17459 +{
17460 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
17461 +       struct vs_mapping *vdm = NULL;
17462 +       int ret = 0;
17463 +
17464 +       spin_lock(hash_lock);
17465 +
17466 +       ret = __find_mapping((vxi ? vxi->vx_id : 0), device, mode, &vdm,
17467 +               NULL);
17468 +       vxdprintk(VXD_CBIT(misc, 8), "__remove_mapping: %p[#%d] %08x %04x",
17469 +               vxi, vxi ? vxi->vx_id : 0, device, mode);
17470 +       if (ret < 0)
17471 +               goto out;
17472 +       hlist_del(&vdm->dm_hlist);
17473 +
17474 +out:
17475 +       spin_unlock(hash_lock);
17476 +       if (vdm)
17477 +               kmem_cache_free(dmap_cachep, vdm);
17478 +       return ret;
17479 +}
17480 +
17481 +
17482 +
17483 +int vs_map_device(struct vx_info *vxi,
17484 +       dev_t device, dev_t *target, umode_t mode)
17485 +{
17486 +       int ret, flags = DATTR_MASK;
17487 +
17488 +       if (!vxi) {
17489 +               if (target)
17490 +                       *target = device;
17491 +               goto out;
17492 +       }
17493 +       ret = __lookup_mapping(vxi, device, target, &flags, mode);
17494 +       vxdprintk(VXD_CBIT(misc, 8), "vs_map_device: %08x target: %08x flags: %04x mode: %04x mapped=%d",
17495 +               device, target ? *target : 0, flags, mode, ret);
17496 +out:
17497 +       return (flags & DATTR_MASK);
17498 +}
17499 +
17500 +
17501 +
17502 +static int do_set_mapping(struct vx_info *vxi,
17503 +       dev_t device, dev_t target, int flags, umode_t mode)
17504 +{
17505 +       if (device) {
17506 +               struct vs_mapping *new;
17507 +
17508 +               new = kmem_cache_alloc(dmap_cachep, GFP_KERNEL);
17509 +               if (!new)
17510 +                       return -ENOMEM;
17511 +
17512 +               INIT_HLIST_NODE(&new->dm_hlist);
17513 +               new->device = device;
17514 +               new->target.target = target;
17515 +               new->target.flags = flags | mode;
17516 +               new->xid = (vxi ? vxi->vx_id : 0);
17517 +
17518 +               vxdprintk(VXD_CBIT(misc, 8), "do_set_mapping: %08x target: %08x flags: %04x", device, target, flags);
17519 +               __hash_mapping(vxi, new);
17520 +       } else {
17521 +               struct vx_dmap_target new = {
17522 +                       .target = target,
17523 +                       .flags = flags | mode,
17524 +               };
17525 +               __set_default(vxi, mode, &new);
17526 +       }
17527 +       return 0;
17528 +}
17529 +
17530 +
17531 +static int do_unset_mapping(struct vx_info *vxi,
17532 +       dev_t device, dev_t target, int flags, umode_t mode)
17533 +{
17534 +       int ret = -EINVAL;
17535 +
17536 +       if (device) {
17537 +               ret = __remove_mapping(vxi, device, mode);
17538 +               if (ret < 0)
17539 +                       goto out;
17540 +       } else {
17541 +               ret = __remove_default(vxi, mode);
17542 +               if (ret < 0)
17543 +                       goto out;
17544 +       }
17545 +
17546 +out:
17547 +       return ret;
17548 +}
17549 +
17550 +
17551 +static inline int __user_device(const char __user *name, dev_t *dev,
17552 +       umode_t *mode)
17553 +{
17554 +       struct nameidata nd;
17555 +       int ret;
17556 +
17557 +       if (!name) {
17558 +               *dev = 0;
17559 +               return 0;
17560 +       }
17561 +       ret = user_lpath(name, &nd.path);
17562 +       if (ret)
17563 +               return ret;
17564 +       if (nd.path.dentry->d_inode) {
17565 +               *dev = nd.path.dentry->d_inode->i_rdev;
17566 +               *mode = nd.path.dentry->d_inode->i_mode;
17567 +       }
17568 +       path_put(&nd.path);
17569 +       return 0;
17570 +}
17571 +
17572 +static inline int __mapping_mode(dev_t device, dev_t target,
17573 +       umode_t device_mode, umode_t target_mode, umode_t *mode)
17574 +{
17575 +       if (device)
17576 +               *mode = device_mode & S_IFMT;
17577 +       else if (target)
17578 +               *mode = target_mode & S_IFMT;
17579 +       else
17580 +               return -EINVAL;
17581 +
17582 +       /* if both given, device and target mode have to match */
17583 +       if (device && target &&
17584 +               ((device_mode ^ target_mode) & S_IFMT))
17585 +               return -EINVAL;
17586 +       return 0;
17587 +}
17588 +
17589 +
17590 +static inline int do_mapping(struct vx_info *vxi, const char __user *device_path,
17591 +       const char __user *target_path, int flags, int set)
17592 +{
17593 +       dev_t device = ~0, target = ~0;
17594 +       umode_t device_mode = 0, target_mode = 0, mode;
17595 +       int ret;
17596 +
17597 +       ret = __user_device(device_path, &device, &device_mode);
17598 +       if (ret)
17599 +               return ret;
17600 +       ret = __user_device(target_path, &target, &target_mode);
17601 +       if (ret)
17602 +               return ret;
17603 +
17604 +       ret = __mapping_mode(device, target,
17605 +               device_mode, target_mode, &mode);
17606 +       if (ret)
17607 +               return ret;
17608 +
17609 +       if (set)
17610 +               return do_set_mapping(vxi, device, target,
17611 +                       flags, mode);
17612 +       else
17613 +               return do_unset_mapping(vxi, device, target,
17614 +                       flags, mode);
17615 +}
17616 +
17617 +
17618 +int vc_set_mapping(struct vx_info *vxi, void __user *data)
17619 +{
17620 +       struct vcmd_set_mapping_v0 vc_data;
17621 +
17622 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17623 +               return -EFAULT;
17624 +
17625 +       return do_mapping(vxi, vc_data.device, vc_data.target,
17626 +               vc_data.flags, 1);
17627 +}
17628 +
17629 +int vc_unset_mapping(struct vx_info *vxi, void __user *data)
17630 +{
17631 +       struct vcmd_set_mapping_v0 vc_data;
17632 +
17633 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17634 +               return -EFAULT;
17635 +
17636 +       return do_mapping(vxi, vc_data.device, vc_data.target,
17637 +               vc_data.flags, 0);
17638 +}
17639 +
17640 +
17641 +#ifdef CONFIG_COMPAT
17642 +
17643 +int vc_set_mapping_x32(struct vx_info *vxi, void __user *data)
17644 +{
17645 +       struct vcmd_set_mapping_v0_x32 vc_data;
17646 +
17647 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17648 +               return -EFAULT;
17649 +
17650 +       return do_mapping(vxi, compat_ptr(vc_data.device_ptr),
17651 +               compat_ptr(vc_data.target_ptr), vc_data.flags, 1);
17652 +}
17653 +
17654 +int vc_unset_mapping_x32(struct vx_info *vxi, void __user *data)
17655 +{
17656 +       struct vcmd_set_mapping_v0_x32 vc_data;
17657 +
17658 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17659 +               return -EFAULT;
17660 +
17661 +       return do_mapping(vxi, compat_ptr(vc_data.device_ptr),
17662 +               compat_ptr(vc_data.target_ptr), vc_data.flags, 0);
17663 +}
17664 +
17665 +#endif /* CONFIG_COMPAT */
17666 +
17667 +
17668 diff -NurpP --minimal linux-3.9.4/kernel/vserver/dlimit.c linux-3.9.4-vs2.3.6.2/kernel/vserver/dlimit.c
17669 --- linux-3.9.4/kernel/vserver/dlimit.c 1970-01-01 00:00:00.000000000 +0000
17670 +++ linux-3.9.4-vs2.3.6.2/kernel/vserver/dlimit.c       2013-05-31 19:37:39.000000000 +0000
17671 @@ -0,0 +1,528 @@
17672 +/*
17673 + *  linux/kernel/vserver/dlimit.c
17674 + *
17675 + *  Virtual Server: Context Disk Limits
17676 + *
17677 + *  Copyright (C) 2004-2009  Herbert Pötzl
17678 + *
17679 + *  V0.01  initial version
17680 + *  V0.02  compat32 splitup
17681 + *  V0.03  extended interface
17682 + *
17683 + */
17684 +
17685 +#include <linux/statfs.h>
17686 +#include <linux/sched.h>
17687 +#include <linux/namei.h>
17688 +#include <linux/vs_tag.h>
17689 +#include <linux/vs_dlimit.h>
17690 +#include <linux/vserver/dlimit_cmd.h>
17691 +#include <linux/slab.h>
17692 +// #include <linux/gfp.h>
17693 +
17694 +#include <asm/uaccess.h>
17695 +
17696 +/*     __alloc_dl_info()
17697 +
17698 +       * allocate an initialized dl_info struct
17699 +       * doesn't make it visible (hash)                        */
17700 +
17701 +static struct dl_info *__alloc_dl_info(struct super_block *sb, tag_t tag)
17702 +{
17703 +       struct dl_info *new = NULL;
17704 +
17705 +       vxdprintk(VXD_CBIT(dlim, 5),
17706 +               "alloc_dl_info(%p,%d)*", sb, tag);
17707 +
17708 +       /* would this benefit from a slab cache? */
17709 +       new = kmalloc(sizeof(struct dl_info), GFP_KERNEL);
17710 +       if (!new)
17711 +               return 0;
17712 +
17713 +       memset(new, 0, sizeof(struct dl_info));
17714 +       new->dl_tag = tag;
17715 +       new->dl_sb = sb;
17716 +       // INIT_RCU_HEAD(&new->dl_rcu);
17717 +       INIT_HLIST_NODE(&new->dl_hlist);
17718 +       spin_lock_init(&new->dl_lock);
17719 +       atomic_set(&new->dl_refcnt, 0);
17720 +       atomic_set(&new->dl_usecnt, 0);
17721 +
17722 +       /* rest of init goes here */
17723 +
17724 +       vxdprintk(VXD_CBIT(dlim, 4),
17725 +               "alloc_dl_info(%p,%d) = %p", sb, tag, new);
17726 +       return new;
17727 +}
17728 +
17729 +/*     __dealloc_dl_info()
17730 +
17731 +       * final disposal of dl_info                             */
17732 +
17733 +static void __dealloc_dl_info(struct dl_info *dli)
17734 +{
17735 +       vxdprintk(VXD_CBIT(dlim, 4),
17736 +               "dealloc_dl_info(%p)", dli);
17737 +
17738 +       dli->dl_hlist.next = LIST_POISON1;
17739 +       dli->dl_tag = -1;
17740 +       dli->dl_sb = 0;
17741 +
17742 +       BUG_ON(atomic_read(&dli->dl_usecnt));
17743 +       BUG_ON(atomic_read(&dli->dl_refcnt));
17744 +
17745 +       kfree(dli);
17746 +}
17747 +
17748 +
17749 +/*     hash table for dl_info hash */
17750 +
17751 +#define DL_HASH_SIZE   13
17752 +
17753 +struct hlist_head dl_info_hash[DL_HASH_SIZE];
17754 +
17755 +static DEFINE_SPINLOCK(dl_info_hash_lock);
17756 +
17757 +
17758 +static inline unsigned int __hashval(struct super_block *sb, tag_t tag)
17759 +{
17760 +       return ((tag ^ (unsigned long)sb) % DL_HASH_SIZE);
17761 +}
17762 +
17763 +
17764 +
17765 +/*     __hash_dl_info()
17766 +
17767 +       * add the dli to the global hash table
17768 +       * requires the hash_lock to be held                     */
17769 +
17770 +static inline void __hash_dl_info(struct dl_info *dli)
17771 +{
17772 +       struct hlist_head *head;
17773 +
17774 +       vxdprintk(VXD_CBIT(dlim, 6),
17775 +               "__hash_dl_info: %p[#%d]", dli, dli->dl_tag);
17776 +       get_dl_info(dli);
17777 +       head = &dl_info_hash[__hashval(dli->dl_sb, dli->dl_tag)];
17778 +       hlist_add_head_rcu(&dli->dl_hlist, head);
17779 +}
17780 +
17781 +/*     __unhash_dl_info()
17782 +
17783 +       * remove the dli from the global hash table
17784 +       * requires the hash_lock to be held                     */
17785 +
17786 +static inline void __unhash_dl_info(struct dl_info *dli)
17787 +{
17788 +       vxdprintk(VXD_CBIT(dlim, 6),
17789 +               "__unhash_dl_info: %p[#%d]", dli, dli->dl_tag);
17790 +       hlist_del_rcu(&dli->dl_hlist);
17791 +       put_dl_info(dli);
17792 +}
17793 +
17794 +
17795 +/*     __lookup_dl_info()
17796 +
17797 +       * requires the rcu_read_lock()
17798 +       * doesn't increment the dl_refcnt                       */
17799 +
17800 +static inline struct dl_info *__lookup_dl_info(struct super_block *sb, tag_t tag)
17801 +{
17802 +       struct hlist_head *head = &dl_info_hash[__hashval(sb, tag)];
17803 +       struct dl_info *dli;
17804 +
17805 +       hlist_for_each_entry_rcu(dli, head, dl_hlist) {
17806 +               if (dli->dl_tag == tag && dli->dl_sb == sb)
17807 +                       return dli;
17808 +       }
17809 +       return NULL;
17810 +}
17811 +
17812 +
17813 +struct dl_info *locate_dl_info(struct super_block *sb, tag_t tag)
17814 +{
17815 +       struct dl_info *dli;
17816 +
17817 +       rcu_read_lock();
17818 +       dli = get_dl_info(__lookup_dl_info(sb, tag));
17819 +       vxdprintk(VXD_CBIT(dlim, 7),
17820 +               "locate_dl_info(%p,#%d) = %p", sb, tag, dli);
17821 +       rcu_read_unlock();
17822 +       return dli;
17823 +}
17824 +
17825 +void rcu_free_dl_info(struct rcu_head *head)
17826 +{
17827 +       struct dl_info *dli = container_of(head, struct dl_info, dl_rcu);
17828 +       int usecnt, refcnt;
17829 +
17830 +       BUG_ON(!dli || !head);
17831 +
17832 +       usecnt = atomic_read(&dli->dl_usecnt);
17833 +       BUG_ON(usecnt < 0);
17834 +
17835 +       refcnt = atomic_read(&dli->dl_refcnt);
17836 +       BUG_ON(refcnt < 0);
17837 +
17838 +       vxdprintk(VXD_CBIT(dlim, 3),
17839 +               "rcu_free_dl_info(%p)", dli);
17840 +       if (!usecnt)
17841 +               __dealloc_dl_info(dli);
17842 +       else
17843 +               printk("!!! rcu didn't free\n");
17844 +}
17845 +
17846 +
17847 +
17848 +
17849 +static int do_addrem_dlimit(uint32_t id, const char __user *name,
17850 +       uint32_t flags, int add)
17851 +{
17852 +       struct path path;
17853 +       int ret;
17854 +
17855 +       ret = user_lpath(name, &path);
17856 +       if (!ret) {
17857 +               struct super_block *sb;
17858 +               struct dl_info *dli;
17859 +
17860 +               ret = -EINVAL;
17861 +               if (!path.dentry->d_inode)
17862 +                       goto out_release;
17863 +               if (!(sb = path.dentry->d_inode->i_sb))
17864 +                       goto out_release;
17865 +
17866 +               if (add) {
17867 +                       dli = __alloc_dl_info(sb, id);
17868 +                       spin_lock(&dl_info_hash_lock);
17869 +
17870 +                       ret = -EEXIST;
17871 +                       if (__lookup_dl_info(sb, id))
17872 +                               goto out_unlock;
17873 +                       __hash_dl_info(dli);
17874 +                       dli = NULL;
17875 +               } else {
17876 +                       spin_lock(&dl_info_hash_lock);
17877 +                       dli = __lookup_dl_info(sb, id);
17878 +
17879 +                       ret = -ESRCH;
17880 +                       if (!dli)
17881 +                               goto out_unlock;
17882 +                       __unhash_dl_info(dli);
17883 +               }
17884 +               ret = 0;
17885 +       out_unlock:
17886 +               spin_unlock(&dl_info_hash_lock);
17887 +               if (add && dli)
17888 +                       __dealloc_dl_info(dli);
17889 +       out_release:
17890 +               path_put(&path);
17891 +       }
17892 +       return ret;
17893 +}
17894 +
17895 +int vc_add_dlimit(uint32_t id, void __user *data)
17896 +{
17897 +       struct vcmd_ctx_dlimit_base_v0 vc_data;
17898 +
17899 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17900 +               return -EFAULT;
17901 +
17902 +       return do_addrem_dlimit(id, vc_data.name, vc_data.flags, 1);
17903 +}
17904 +
17905 +int vc_rem_dlimit(uint32_t id, void __user *data)
17906 +{
17907 +       struct vcmd_ctx_dlimit_base_v0 vc_data;
17908 +
17909 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17910 +               return -EFAULT;
17911 +
17912 +       return do_addrem_dlimit(id, vc_data.name, vc_data.flags, 0);
17913 +}
17914 +
17915 +#ifdef CONFIG_COMPAT
17916 +
17917 +int vc_add_dlimit_x32(uint32_t id, void __user *data)
17918 +{
17919 +       struct vcmd_ctx_dlimit_base_v0_x32 vc_data;
17920 +
17921 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17922 +               return -EFAULT;
17923 +
17924 +       return do_addrem_dlimit(id,
17925 +               compat_ptr(vc_data.name_ptr), vc_data.flags, 1);
17926 +}
17927 +
17928 +int vc_rem_dlimit_x32(uint32_t id, void __user *data)
17929 +{
17930 +       struct vcmd_ctx_dlimit_base_v0_x32 vc_data;
17931 +
17932 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17933 +               return -EFAULT;
17934 +
17935 +       return do_addrem_dlimit(id,
17936 +               compat_ptr(vc_data.name_ptr), vc_data.flags, 0);
17937 +}
17938 +
17939 +#endif /* CONFIG_COMPAT */
17940 +
17941 +
17942 +static inline
17943 +int do_set_dlimit(uint32_t id, const char __user *name,
17944 +       uint32_t space_used, uint32_t space_total,
17945 +       uint32_t inodes_used, uint32_t inodes_total,
17946 +       uint32_t reserved, uint32_t flags)
17947 +{
17948 +       struct path path;
17949 +       int ret;
17950 +
17951 +       ret = user_lpath(name, &path);
17952 +       if (!ret) {
17953 +               struct super_block *sb;
17954 +               struct dl_info *dli;
17955 +
17956 +               ret = -EINVAL;
17957 +               if (!path.dentry->d_inode)
17958 +                       goto out_release;
17959 +               if (!(sb = path.dentry->d_inode->i_sb))
17960 +                       goto out_release;
17961 +
17962 +               /* sanity checks */
17963 +               if ((reserved != CDLIM_KEEP &&
17964 +                       reserved > 100) ||
17965 +                       (inodes_used != CDLIM_KEEP &&
17966 +                       inodes_used > inodes_total) ||
17967 +                       (space_used != CDLIM_KEEP &&
17968 +                       space_used > space_total))
17969 +                       goto out_release;
17970 +
17971 +               ret = -ESRCH;
17972 +               dli = locate_dl_info(sb, id);
17973 +               if (!dli)
17974 +                       goto out_release;
17975 +
17976 +               spin_lock(&dli->dl_lock);
17977 +
17978 +               if (inodes_used != CDLIM_KEEP)
17979 +                       dli->dl_inodes_used = inodes_used;
17980 +               if (inodes_total != CDLIM_KEEP)
17981 +                       dli->dl_inodes_total = inodes_total;
17982 +               if (space_used != CDLIM_KEEP)
17983 +                       dli->dl_space_used = dlimit_space_32to64(
17984 +                               space_used, flags, DLIMS_USED);
17985 +
17986 +               if (space_total == CDLIM_INFINITY)
17987 +                       dli->dl_space_total = DLIM_INFINITY;
17988 +               else if (space_total != CDLIM_KEEP)
17989 +                       dli->dl_space_total = dlimit_space_32to64(
17990 +                               space_total, flags, DLIMS_TOTAL);
17991 +
17992 +               if (reserved != CDLIM_KEEP)
17993 +                       dli->dl_nrlmult = (1 << 10) * (100 - reserved) / 100;
17994 +
17995 +               spin_unlock(&dli->dl_lock);
17996 +
17997 +               put_dl_info(dli);
17998 +               ret = 0;
17999 +
18000 +       out_release:
18001 +               path_put(&path);
18002 +       }
18003 +       return ret;
18004 +}
18005 +
18006 +int vc_set_dlimit(uint32_t id, void __user *data)
18007 +{
18008 +       struct vcmd_ctx_dlimit_v0 vc_data;
18009 +
18010 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18011 +               return -EFAULT;
18012 +
18013 +       return do_set_dlimit(id, vc_data.name,
18014 +               vc_data.space_used, vc_data.space_total,
18015 +               vc_data.inodes_used, vc_data.inodes_total,
18016 +               vc_data.reserved, vc_data.flags);
18017 +}
18018 +
18019 +#ifdef CONFIG_COMPAT
18020 +
18021 +int vc_set_dlimit_x32(uint32_t id, void __user *data)
18022 +{
18023 +       struct vcmd_ctx_dlimit_v0_x32 vc_data;
18024 +
18025 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18026 +               return -EFAULT;
18027 +
18028 +       return do_set_dlimit(id, compat_ptr(vc_data.name_ptr),
18029 +               vc_data.space_used, vc_data.space_total,
18030 +               vc_data.inodes_used, vc_data.inodes_total,
18031 +               vc_data.reserved, vc_data.flags);
18032 +}
18033 +
18034 +#endif /* CONFIG_COMPAT */
18035 +
18036 +
18037 +static inline
18038 +int do_get_dlimit(uint32_t id, const char __user *name,
18039 +       uint32_t *space_used, uint32_t *space_total,
18040 +       uint32_t *inodes_used, uint32_t *inodes_total,
18041 +       uint32_t *reserved, uint32_t *flags)
18042 +{
18043 +       struct path path;
18044 +       int ret;
18045 +
18046 +       ret = user_lpath(name, &path);
18047 +       if (!ret) {
18048 +               struct super_block *sb;
18049 +               struct dl_info *dli;
18050 +
18051 +               ret = -EINVAL;
18052 +               if (!path.dentry->d_inode)
18053 +                       goto out_release;
18054 +               if (!(sb = path.dentry->d_inode->i_sb))
18055 +                       goto out_release;
18056 +
18057 +               ret = -ESRCH;
18058 +               dli = locate_dl_info(sb, id);
18059 +               if (!dli)
18060 +                       goto out_release;
18061 +
18062 +               spin_lock(&dli->dl_lock);
18063 +               *inodes_used = dli->dl_inodes_used;
18064 +               *inodes_total = dli->dl_inodes_total;
18065 +
18066 +               *space_used = dlimit_space_64to32(
18067 +                       dli->dl_space_used, flags, DLIMS_USED);
18068 +
18069 +               if (dli->dl_space_total == DLIM_INFINITY)
18070 +                       *space_total = CDLIM_INFINITY;
18071 +               else
18072 +                       *space_total = dlimit_space_64to32(
18073 +                               dli->dl_space_total, flags, DLIMS_TOTAL);
18074 +
18075 +               *reserved = 100 - ((dli->dl_nrlmult * 100 + 512) >> 10);
18076 +               spin_unlock(&dli->dl_lock);
18077 +
18078 +               put_dl_info(dli);
18079 +               ret = -EFAULT;
18080 +
18081 +               ret = 0;
18082 +       out_release:
18083 +               path_put(&path);
18084 +       }
18085 +       return ret;
18086 +}
18087 +
18088 +
18089 +int vc_get_dlimit(uint32_t id, void __user *data)
18090 +{
18091 +       struct vcmd_ctx_dlimit_v0 vc_data;
18092 +       int ret;
18093 +
18094 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18095 +               return -EFAULT;
18096 +
18097 +       ret = do_get_dlimit(id, vc_data.name,
18098 +               &vc_data.space_used, &vc_data.space_total,
18099 +               &vc_data.inodes_used, &vc_data.inodes_total,
18100 +               &vc_data.reserved, &vc_data.flags);
18101 +       if (ret)
18102 +               return ret;
18103 +
18104 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18105 +               return -EFAULT;
18106 +       return 0;
18107 +}
18108 +
18109 +#ifdef CONFIG_COMPAT
18110 +
18111 +int vc_get_dlimit_x32(uint32_t id, void __user *data)
18112 +{
18113 +       struct vcmd_ctx_dlimit_v0_x32 vc_data;
18114 +       int ret;
18115 +
18116 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18117 +               return -EFAULT;
18118 +
18119 +       ret = do_get_dlimit(id, compat_ptr(vc_data.name_ptr),
18120 +               &vc_data.space_used, &vc_data.space_total,
18121 +               &vc_data.inodes_used, &vc_data.inodes_total,
18122 +               &vc_data.reserved, &vc_data.flags);
18123 +       if (ret)
18124 +               return ret;
18125 +
18126 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18127 +               return -EFAULT;
18128 +       return 0;
18129 +}
18130 +
18131 +#endif /* CONFIG_COMPAT */
18132 +
18133 +
18134 +void vx_vsi_statfs(struct super_block *sb, struct kstatfs *buf)
18135 +{
18136 +       struct dl_info *dli;
18137 +       __u64 blimit, bfree, bavail;
18138 +       __u32 ifree;
18139 +
18140 +       dli = locate_dl_info(sb, dx_current_tag());
18141 +       if (!dli)
18142 +               return;
18143 +
18144 +       spin_lock(&dli->dl_lock);
18145 +       if (dli->dl_inodes_total == (unsigned long)DLIM_INFINITY)
18146 +               goto no_ilim;
18147 +
18148 +       /* reduce max inodes available to limit */
18149 +       if (buf->f_files > dli->dl_inodes_total)
18150 +               buf->f_files = dli->dl_inodes_total;
18151 +
18152 +       ifree = dli->dl_inodes_total - dli->dl_inodes_used;
18153 +       /* reduce free inodes to min */
18154 +       if (ifree < buf->f_ffree)
18155 +               buf->f_ffree = ifree;
18156 +
18157 +no_ilim:
18158 +       if (dli->dl_space_total == DLIM_INFINITY)
18159 +               goto no_blim;
18160 +
18161 +       blimit = dli->dl_space_total >> sb->s_blocksize_bits;
18162 +
18163 +       if (dli->dl_space_total < dli->dl_space_used)
18164 +               bfree = 0;
18165 +       else
18166 +               bfree = (dli->dl_space_total - dli->dl_space_used)
18167 +                       >> sb->s_blocksize_bits;
18168 +
18169 +       bavail = ((dli->dl_space_total >> 10) * dli->dl_nrlmult);
18170 +       if (bavail < dli->dl_space_used)
18171 +               bavail = 0;
18172 +       else
18173 +               bavail = (bavail - dli->dl_space_used)
18174 +                       >> sb->s_blocksize_bits;
18175 +
18176 +       /* reduce max space available to limit */
18177 +       if (buf->f_blocks > blimit)
18178 +               buf->f_blocks = blimit;
18179 +
18180 +       /* reduce free space to min */
18181 +       if (bfree < buf->f_bfree)
18182 +               buf->f_bfree = bfree;
18183 +
18184 +       /* reduce avail space to min */
18185 +       if (bavail < buf->f_bavail)
18186 +               buf->f_bavail = bavail;
18187 +
18188 +no_blim:
18189 +       spin_unlock(&dli->dl_lock);
18190 +       put_dl_info(dli);
18191 +
18192 +       return;
18193 +}
18194 +
18195 +#include <linux/module.h>
18196 +
18197 +EXPORT_SYMBOL_GPL(locate_dl_info);
18198 +EXPORT_SYMBOL_GPL(rcu_free_dl_info);
18199 +
18200 diff -NurpP --minimal linux-3.9.4/kernel/vserver/helper.c linux-3.9.4-vs2.3.6.2/kernel/vserver/helper.c
18201 --- linux-3.9.4/kernel/vserver/helper.c 1970-01-01 00:00:00.000000000 +0000
18202 +++ linux-3.9.4-vs2.3.6.2/kernel/vserver/helper.c       2013-06-01 08:27:59.000000000 +0000
18203 @@ -0,0 +1,230 @@
18204 +/*
18205 + *  linux/kernel/vserver/helper.c
18206 + *
18207 + *  Virtual Context Support
18208 + *
18209 + *  Copyright (C) 2004-2007  Herbert Pötzl
18210 + *
18211 + *  V0.01  basic helper
18212 + *
18213 + */
18214 +
18215 +#include <linux/kmod.h>
18216 +#include <linux/reboot.h>
18217 +#include <linux/vs_context.h>
18218 +#include <linux/vs_network.h>
18219 +#include <linux/vserver/signal.h>
18220 +
18221 +
18222 +char vshelper_path[255] = "/sbin/vshelper";
18223 +
18224 +static int vshelper_init(struct subprocess_info *info, struct cred *new_cred)
18225 +{
18226 +       current->flags &= ~PF_THREAD_BOUND;
18227 +       return 0;
18228 +}
18229 +
18230 +static int do_vshelper(char *name, char *argv[], char *envp[], int sync)
18231 +{
18232 +       int ret;
18233 +
18234 +       if ((ret = call_usermodehelper_fns(name, argv, envp,
18235 +               sync ? UMH_WAIT_PROC : UMH_WAIT_EXEC,
18236 +               vshelper_init, NULL, NULL))) {
18237 +               printk(KERN_WARNING "%s: (%s %s) returned %s with %d\n",
18238 +                       name, argv[1], argv[2],
18239 +                       sync ? "sync" : "async", ret);
18240 +       }
18241 +       vxdprintk(VXD_CBIT(switch, 4),
18242 +               "%s: (%s %s) returned %s with %d",
18243 +               name, argv[1], argv[2], sync ? "sync" : "async", ret);
18244 +       return ret;
18245 +}
18246 +
18247 +/*
18248 + *      vshelper path is set via /proc/sys
18249 + *      invoked by vserver sys_reboot(), with
18250 + *      the following arguments
18251 + *
18252 + *      argv [0] = vshelper_path;
18253 + *      argv [1] = action: "restart", "halt", "poweroff", ...
18254 + *      argv [2] = context identifier
18255 + *
18256 + *      envp [*] = type-specific parameters
18257 + */
18258 +
18259 +long vs_reboot_helper(struct vx_info *vxi, int cmd, void __user *arg)
18260 +{
18261 +       char id_buf[8], cmd_buf[16];
18262 +       char uid_buf[16], pid_buf[16];
18263 +       int ret;
18264 +
18265 +       char *argv[] = {vshelper_path, NULL, id_buf, 0};
18266 +       char *envp[] = {"HOME=/", "TERM=linux",
18267 +                       "PATH=/sbin:/usr/sbin:/bin:/usr/bin",
18268 +                       uid_buf, pid_buf, cmd_buf, 0};
18269 +
18270 +       if (vx_info_state(vxi, VXS_HELPER))
18271 +               return -EAGAIN;
18272 +       vxi->vx_state |= VXS_HELPER;
18273 +
18274 +       snprintf(id_buf, sizeof(id_buf), "%d", vxi->vx_id);
18275 +
18276 +       snprintf(cmd_buf, sizeof(cmd_buf), "VS_CMD=%08x", cmd);
18277 +       snprintf(uid_buf, sizeof(uid_buf), "VS_UID=%d",
18278 +               from_kuid(&init_user_ns, current_uid()));
18279 +       snprintf(pid_buf, sizeof(pid_buf), "VS_PID=%d", current->pid);
18280 +
18281 +       switch (cmd) {
18282 +       case LINUX_REBOOT_CMD_RESTART:
18283 +               argv[1] = "restart";
18284 +               break;
18285 +
18286 +       case LINUX_REBOOT_CMD_HALT:
18287 +               argv[1] = "halt";
18288 +               break;
18289 +
18290 +       case LINUX_REBOOT_CMD_POWER_OFF:
18291 +               argv[1] = "poweroff";
18292 +               break;
18293 +
18294 +       case LINUX_REBOOT_CMD_SW_SUSPEND:
18295 +               argv[1] = "swsusp";
18296 +               break;
18297 +
18298 +       case LINUX_REBOOT_CMD_OOM:
18299 +               argv[1] = "oom";
18300 +               break;
18301 +
18302 +       default:
18303 +               vxi->vx_state &= ~VXS_HELPER;
18304 +               return 0;
18305 +       }
18306 +
18307 +       ret = do_vshelper(vshelper_path, argv, envp, 0);
18308 +       vxi->vx_state &= ~VXS_HELPER;
18309 +       __wakeup_vx_info(vxi);
18310 +       return (ret) ? -EPERM : 0;
18311 +}
18312 +
18313 +
18314 +long vs_reboot(unsigned int cmd, void __user *arg)
18315 +{
18316 +       struct vx_info *vxi = current_vx_info();
18317 +       long ret = 0;
18318 +
18319 +       vxdprintk(VXD_CBIT(misc, 5),
18320 +               "vs_reboot(%p[#%d],%u)",
18321 +               vxi, vxi ? vxi->vx_id : 0, cmd);
18322 +
18323 +       ret = vs_reboot_helper(vxi, cmd, arg);
18324 +       if (ret)
18325 +               return ret;
18326 +
18327 +       vxi->reboot_cmd = cmd;
18328 +       if (vx_info_flags(vxi, VXF_REBOOT_KILL, 0)) {
18329 +               switch (cmd) {
18330 +               case LINUX_REBOOT_CMD_RESTART:
18331 +               case LINUX_REBOOT_CMD_HALT:
18332 +               case LINUX_REBOOT_CMD_POWER_OFF:
18333 +                       vx_info_kill(vxi, 0, SIGKILL);
18334 +                       vx_info_kill(vxi, 1, SIGKILL);
18335 +               default:
18336 +                       break;
18337 +               }
18338 +       }
18339 +       return 0;
18340 +}
18341 +
18342 +long vs_oom_action(unsigned int cmd)
18343 +{
18344 +       struct vx_info *vxi = current_vx_info();
18345 +       long ret = 0;
18346 +
18347 +       vxdprintk(VXD_CBIT(misc, 5),
18348 +               "vs_oom_action(%p[#%d],%u)",
18349 +               vxi, vxi ? vxi->vx_id : 0, cmd);
18350 +
18351 +       ret = vs_reboot_helper(vxi, cmd, NULL);
18352 +       if (ret)
18353 +               return ret;
18354 +
18355 +       vxi->reboot_cmd = cmd;
18356 +       if (vx_info_flags(vxi, VXF_REBOOT_KILL, 0)) {
18357 +               vx_info_kill(vxi, 0, SIGKILL);
18358 +               vx_info_kill(vxi, 1, SIGKILL);
18359 +       }
18360 +       return 0;
18361 +}
18362 +
18363 +/*
18364 + *      argv [0] = vshelper_path;
18365 + *      argv [1] = action: "startup", "shutdown"
18366 + *      argv [2] = context identifier
18367 + *
18368 + *      envp [*] = type-specific parameters
18369 + */
18370 +
18371 +long vs_state_change(struct vx_info *vxi, unsigned int cmd)
18372 +{
18373 +       char id_buf[8], cmd_buf[16];
18374 +       char *argv[] = {vshelper_path, NULL, id_buf, 0};
18375 +       char *envp[] = {"HOME=/", "TERM=linux",
18376 +                       "PATH=/sbin:/usr/sbin:/bin:/usr/bin", cmd_buf, 0};
18377 +
18378 +       if (!vx_info_flags(vxi, VXF_SC_HELPER, 0))
18379 +               return 0;
18380 +
18381 +       snprintf(id_buf, sizeof(id_buf), "%d", vxi->vx_id);
18382 +       snprintf(cmd_buf, sizeof(cmd_buf), "VS_CMD=%08x", cmd);
18383 +
18384 +       switch (cmd) {
18385 +       case VSC_STARTUP:
18386 +               argv[1] = "startup";
18387 +               break;
18388 +       case VSC_SHUTDOWN:
18389 +               argv[1] = "shutdown";
18390 +               break;
18391 +       default:
18392 +               return 0;
18393 +       }
18394 +
18395 +       return do_vshelper(vshelper_path, argv, envp, 1);
18396 +}
18397 +
18398 +
18399 +/*
18400 + *      argv [0] = vshelper_path;
18401 + *      argv [1] = action: "netup", "netdown"
18402 + *      argv [2] = context identifier
18403 + *
18404 + *      envp [*] = type-specific parameters
18405 + */
18406 +
18407 +long vs_net_change(struct nx_info *nxi, unsigned int cmd)
18408 +{
18409 +       char id_buf[8], cmd_buf[16];
18410 +       char *argv[] = {vshelper_path, NULL, id_buf, 0};
18411 +       char *envp[] = {"HOME=/", "TERM=linux",
18412 +                       "PATH=/sbin:/usr/sbin:/bin:/usr/bin", cmd_buf, 0};
18413 +
18414 +       if (!nx_info_flags(nxi, NXF_SC_HELPER, 0))
18415 +               return 0;
18416 +
18417 +       snprintf(id_buf, sizeof(id_buf), "%d", nxi->nx_id);
18418 +       snprintf(cmd_buf, sizeof(cmd_buf), "VS_CMD=%08x", cmd);
18419 +
18420 +       switch (cmd) {
18421 +       case VSC_NETUP:
18422 +               argv[1] = "netup";
18423 +               break;
18424 +       case VSC_NETDOWN:
18425 +               argv[1] = "netdown";
18426 +               break;
18427 +       default:
18428 +               return 0;
18429 +       }
18430 +
18431 +       return do_vshelper(vshelper_path, argv, envp, 1);
18432 +}
18433 +
18434 diff -NurpP --minimal linux-3.9.4/kernel/vserver/history.c linux-3.9.4-vs2.3.6.2/kernel/vserver/history.c
18435 --- linux-3.9.4/kernel/vserver/history.c        1970-01-01 00:00:00.000000000 +0000
18436 +++ linux-3.9.4-vs2.3.6.2/kernel/vserver/history.c      2013-05-31 14:47:11.000000000 +0000
18437 @@ -0,0 +1,258 @@
18438 +/*
18439 + *  kernel/vserver/history.c
18440 + *
18441 + *  Virtual Context History Backtrace
18442 + *
18443 + *  Copyright (C) 2004-2007  Herbert Pötzl
18444 + *
18445 + *  V0.01  basic structure
18446 + *  V0.02  hash/unhash and trace
18447 + *  V0.03  preemption fixes
18448 + *
18449 + */
18450 +
18451 +#include <linux/module.h>
18452 +#include <asm/uaccess.h>
18453 +
18454 +#include <linux/vserver/context.h>
18455 +#include <linux/vserver/debug.h>
18456 +#include <linux/vserver/debug_cmd.h>
18457 +#include <linux/vserver/history.h>
18458 +
18459 +
18460 +#ifdef CONFIG_VSERVER_HISTORY
18461 +#define VXH_SIZE       CONFIG_VSERVER_HISTORY_SIZE
18462 +#else
18463 +#define VXH_SIZE       64
18464 +#endif
18465 +
18466 +struct _vx_history {
18467 +       unsigned int counter;
18468 +
18469 +       struct _vx_hist_entry entry[VXH_SIZE + 1];
18470 +};
18471 +
18472 +
18473 +DEFINE_PER_CPU(struct _vx_history, vx_history_buffer);
18474 +
18475 +unsigned volatile int vxh_active = 1;
18476 +
18477 +static atomic_t sequence = ATOMIC_INIT(0);
18478 +
18479 +
18480 +/*     vxh_advance()
18481 +
18482 +       * requires disabled preemption                          */
18483 +
18484 +struct _vx_hist_entry *vxh_advance(void *loc)
18485 +{
18486 +       unsigned int cpu = smp_processor_id();
18487 +       struct _vx_history *hist = &per_cpu(vx_history_buffer, cpu);
18488 +       struct _vx_hist_entry *entry;
18489 +       unsigned int index;
18490 +
18491 +       index = vxh_active ? (hist->counter++ % VXH_SIZE) : VXH_SIZE;
18492 +       entry = &hist->entry[index];
18493 +
18494 +       entry->seq = atomic_inc_return(&sequence);
18495 +       entry->loc = loc;
18496 +       return entry;
18497 +}
18498 +
18499 +EXPORT_SYMBOL_GPL(vxh_advance);
18500 +
18501 +
18502 +#define VXH_LOC_FMTS   "(#%04x,*%d):%p"
18503 +
18504 +#define VXH_LOC_ARGS(e)        (e)->seq, cpu, (e)->loc
18505 +
18506 +
18507 +#define VXH_VXI_FMTS   "%p[#%d,%d.%d]"
18508 +
18509 +#define VXH_VXI_ARGS(e)        (e)->vxi.ptr,                           \
18510 +                       (e)->vxi.ptr ? (e)->vxi.xid : 0,        \
18511 +                       (e)->vxi.ptr ? (e)->vxi.usecnt : 0,     \
18512 +                       (e)->vxi.ptr ? (e)->vxi.tasks : 0
18513 +
18514 +void   vxh_dump_entry(struct _vx_hist_entry *e, unsigned cpu)
18515 +{
18516 +       switch (e->type) {
18517 +       case VXH_THROW_OOPS:
18518 +               printk( VXH_LOC_FMTS " oops \n", VXH_LOC_ARGS(e));
18519 +               break;
18520 +
18521 +       case VXH_GET_VX_INFO:
18522 +       case VXH_PUT_VX_INFO:
18523 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS "\n",
18524 +                       VXH_LOC_ARGS(e),
18525 +                       (e->type == VXH_GET_VX_INFO) ? "get" : "put",
18526 +                       VXH_VXI_ARGS(e));
18527 +               break;
18528 +
18529 +       case VXH_INIT_VX_INFO:
18530 +       case VXH_SET_VX_INFO:
18531 +       case VXH_CLR_VX_INFO:
18532 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS " @%p\n",
18533 +                       VXH_LOC_ARGS(e),
18534 +                       (e->type == VXH_INIT_VX_INFO) ? "init" :
18535 +                       ((e->type == VXH_SET_VX_INFO) ? "set" : "clr"),
18536 +                       VXH_VXI_ARGS(e), e->sc.data);
18537 +               break;
18538 +
18539 +       case VXH_CLAIM_VX_INFO:
18540 +       case VXH_RELEASE_VX_INFO:
18541 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS " @%p\n",
18542 +                       VXH_LOC_ARGS(e),
18543 +                       (e->type == VXH_CLAIM_VX_INFO) ? "claim" : "release",
18544 +                       VXH_VXI_ARGS(e), e->sc.data);
18545 +               break;
18546 +
18547 +       case VXH_ALLOC_VX_INFO:
18548 +       case VXH_DEALLOC_VX_INFO:
18549 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS "\n",
18550 +                       VXH_LOC_ARGS(e),
18551 +                       (e->type == VXH_ALLOC_VX_INFO) ? "alloc" : "dealloc",
18552 +                       VXH_VXI_ARGS(e));
18553 +               break;
18554 +
18555 +       case VXH_HASH_VX_INFO:
18556 +       case VXH_UNHASH_VX_INFO:
18557 +               printk( VXH_LOC_FMTS " __%s_vx_info " VXH_VXI_FMTS "\n",
18558 +                       VXH_LOC_ARGS(e),
18559 +                       (e->type == VXH_HASH_VX_INFO) ? "hash" : "unhash",
18560 +                       VXH_VXI_ARGS(e));
18561 +               break;
18562 +
18563 +       case VXH_LOC_VX_INFO:
18564 +       case VXH_LOOKUP_VX_INFO:
18565 +       case VXH_CREATE_VX_INFO:
18566 +               printk( VXH_LOC_FMTS " __%s_vx_info [#%d] -> " VXH_VXI_FMTS "\n",
18567 +                       VXH_LOC_ARGS(e),
18568 +                       (e->type == VXH_CREATE_VX_INFO) ? "create" :
18569 +                       ((e->type == VXH_LOC_VX_INFO) ? "loc" : "lookup"),
18570 +                       e->ll.arg, VXH_VXI_ARGS(e));
18571 +               break;
18572 +       }
18573 +}
18574 +
18575 +static void __vxh_dump_history(void)
18576 +{
18577 +       unsigned int i, cpu;
18578 +
18579 +       printk("History:\tSEQ: %8x\tNR_CPUS: %d\n",
18580 +               atomic_read(&sequence), NR_CPUS);
18581 +
18582 +       for (i = 0; i < VXH_SIZE; i++) {
18583 +               for_each_online_cpu(cpu) {
18584 +                       struct _vx_history *hist =
18585 +                               &per_cpu(vx_history_buffer, cpu);
18586 +                       unsigned int index = (hist->counter - i) % VXH_SIZE;
18587 +                       struct _vx_hist_entry *entry = &hist->entry[index];
18588 +
18589 +                       vxh_dump_entry(entry, cpu);
18590 +               }
18591 +       }
18592 +}
18593 +
18594 +void   vxh_dump_history(void)
18595 +{
18596 +       vxh_active = 0;
18597 +#ifdef CONFIG_SMP
18598 +       local_irq_enable();
18599 +       smp_send_stop();
18600 +       local_irq_disable();
18601 +#endif
18602 +       __vxh_dump_history();
18603 +}
18604 +
18605 +
18606 +/* vserver syscall commands below here */
18607 +
18608 +
18609 +int vc_dump_history(uint32_t id)
18610 +{
18611 +       vxh_active = 0;
18612 +       __vxh_dump_history();
18613 +       vxh_active = 1;
18614 +
18615 +       return 0;
18616 +}
18617 +
18618 +
18619 +int do_read_history(struct __user _vx_hist_entry *data,
18620 +       int cpu, uint32_t *index, uint32_t *count)
18621 +{
18622 +       int pos, ret = 0;
18623 +       struct _vx_history *hist = &per_cpu(vx_history_buffer, cpu);
18624 +       int end = hist->counter;
18625 +       int start = end - VXH_SIZE + 2;
18626 +       int idx = *index;
18627 +
18628 +       /* special case: get current pos */
18629 +       if (!*count) {
18630 +               *index = end;
18631 +               return 0;
18632 +       }
18633 +
18634 +       /* have we lost some data? */
18635 +       if (idx < start)
18636 +               idx = start;
18637 +
18638 +       for (pos = 0; (pos < *count) && (idx < end); pos++, idx++) {
18639 +               struct _vx_hist_entry *entry =
18640 +                       &hist->entry[idx % VXH_SIZE];
18641 +
18642 +               /* send entry to userspace */
18643 +               ret = copy_to_user(&data[pos], entry, sizeof(*entry));
18644 +               if (ret)
18645 +                       break;
18646 +       }
18647 +       /* save new index and count */
18648 +       *index = idx;
18649 +       *count = pos;
18650 +       return ret ? ret : (*index < end);
18651 +}
18652 +
18653 +int vc_read_history(uint32_t id, void __user *data)
18654 +{
18655 +       struct vcmd_read_history_v0 vc_data;
18656 +       int ret;
18657 +
18658 +       if (id >= NR_CPUS)
18659 +               return -EINVAL;
18660 +
18661 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18662 +               return -EFAULT;
18663 +
18664 +       ret = do_read_history((struct __user _vx_hist_entry *)vc_data.data,
18665 +               id, &vc_data.index, &vc_data.count);
18666 +
18667 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18668 +               return -EFAULT;
18669 +       return ret;
18670 +}
18671 +
18672 +#ifdef CONFIG_COMPAT
18673 +
18674 +int vc_read_history_x32(uint32_t id, void __user *data)
18675 +{
18676 +       struct vcmd_read_history_v0_x32 vc_data;
18677 +       int ret;
18678 +
18679 +       if (id >= NR_CPUS)
18680 +               return -EINVAL;
18681 +
18682 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18683 +               return -EFAULT;
18684 +
18685 +       ret = do_read_history((struct __user _vx_hist_entry *)
18686 +               compat_ptr(vc_data.data_ptr),
18687 +               id, &vc_data.index, &vc_data.count);
18688 +
18689 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18690 +               return -EFAULT;
18691 +       return ret;
18692 +}
18693 +
18694 +#endif /* CONFIG_COMPAT */
18695 +
18696 diff -NurpP --minimal linux-3.9.4/kernel/vserver/inet.c linux-3.9.4-vs2.3.6.2/kernel/vserver/inet.c
18697 --- linux-3.9.4/kernel/vserver/inet.c   1970-01-01 00:00:00.000000000 +0000
18698 +++ linux-3.9.4-vs2.3.6.2/kernel/vserver/inet.c 2013-05-31 22:43:05.000000000 +0000
18699 @@ -0,0 +1,236 @@
18700 +
18701 +#include <linux/in.h>
18702 +#include <linux/inetdevice.h>
18703 +#include <linux/export.h>
18704 +#include <linux/vs_inet.h>
18705 +#include <linux/vs_inet6.h>
18706 +#include <linux/vserver/debug.h>
18707 +#include <net/route.h>
18708 +#include <net/addrconf.h>
18709 +
18710 +
18711 +int nx_v4_addr_conflict(struct nx_info *nxi1, struct nx_info *nxi2)
18712 +{
18713 +       int ret = 0;
18714 +
18715 +       if (!nxi1 || !nxi2 || nxi1 == nxi2)
18716 +               ret = 1;
18717 +       else {
18718 +               struct nx_addr_v4 *ptr;
18719 +               unsigned long irqflags;
18720 +
18721 +               spin_lock_irqsave(&nxi1->addr_lock, irqflags);
18722 +               for (ptr = &nxi1->v4; ptr; ptr = ptr->next) {
18723 +                       if (v4_nx_addr_in_nx_info(nxi2, ptr, -1)) {
18724 +                               ret = 1;
18725 +                               break;
18726 +                       }
18727 +               }
18728 +               spin_unlock_irqrestore(&nxi1->addr_lock, irqflags);
18729 +       }
18730 +
18731 +       vxdprintk(VXD_CBIT(net, 2),
18732 +               "nx_v4_addr_conflict(%p,%p): %d",
18733 +               nxi1, nxi2, ret);
18734 +
18735 +       return ret;
18736 +}
18737 +
18738 +
18739 +#ifdef CONFIG_IPV6
18740 +
18741 +int nx_v6_addr_conflict(struct nx_info *nxi1, struct nx_info *nxi2)
18742 +{
18743 +       int ret = 0;
18744 +
18745 +       if (!nxi1 || !nxi2 || nxi1 == nxi2)
18746 +               ret = 1;
18747 +       else {
18748 +               struct nx_addr_v6 *ptr;
18749 +               unsigned long irqflags;
18750 +
18751 +               spin_lock_irqsave(&nxi1->addr_lock, irqflags);
18752 +               for (ptr = &nxi1->v6; ptr; ptr = ptr->next) {
18753 +                       if (v6_nx_addr_in_nx_info(nxi2, ptr, -1)) {
18754 +                               ret = 1;
18755 +                               break;
18756 +                       }
18757 +               }
18758 +               spin_unlock_irqrestore(&nxi1->addr_lock, irqflags);
18759 +       }
18760 +
18761 +       vxdprintk(VXD_CBIT(net, 2),
18762 +               "nx_v6_addr_conflict(%p,%p): %d",
18763 +               nxi1, nxi2, ret);
18764 +
18765 +       return ret;
18766 +}
18767 +
18768 +#endif
18769 +
18770 +int v4_dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
18771 +{
18772 +       struct in_device *in_dev;
18773 +       struct in_ifaddr **ifap;
18774 +       struct in_ifaddr *ifa;
18775 +       int ret = 0;
18776 +
18777 +       if (!dev)
18778 +               goto out;
18779 +       in_dev = in_dev_get(dev);
18780 +       if (!in_dev)
18781 +               goto out;
18782 +
18783 +       for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
18784 +               ifap = &ifa->ifa_next) {
18785 +               if (v4_addr_in_nx_info(nxi, ifa->ifa_local, NXA_MASK_SHOW)) {
18786 +                       ret = 1;
18787 +                       break;
18788 +               }
18789 +       }
18790 +       in_dev_put(in_dev);
18791 +out:
18792 +       return ret;
18793 +}
18794 +
18795 +
18796 +#ifdef CONFIG_IPV6
18797 +
18798 +int v6_dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
18799 +{
18800 +       struct inet6_dev *in_dev;
18801 +       struct inet6_ifaddr *ifa;
18802 +       int ret = 0;
18803 +
18804 +       if (!dev)
18805 +               goto out;
18806 +       in_dev = in6_dev_get(dev);
18807 +       if (!in_dev)
18808 +               goto out;
18809 +
18810 +       // for (ifap = &in_dev->addr_list; (ifa = *ifap) != NULL;
18811 +       list_for_each_entry(ifa, &in_dev->addr_list, if_list) {
18812 +               if (v6_addr_in_nx_info(nxi, &ifa->addr, -1)) {
18813 +                       ret = 1;
18814 +                       break;
18815 +               }
18816 +       }
18817 +       in6_dev_put(in_dev);
18818 +out:
18819 +       return ret;
18820 +}
18821 +
18822 +#endif
18823 +
18824 +int dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
18825 +{
18826 +       int ret = 1;
18827 +
18828 +       if (!nxi)
18829 +               goto out;
18830 +       if (nxi->v4.type && v4_dev_in_nx_info(dev, nxi))
18831 +               goto out;
18832 +#ifdef CONFIG_IPV6
18833 +       ret = 2;
18834 +       if (nxi->v6.type && v6_dev_in_nx_info(dev, nxi))
18835 +               goto out;
18836 +#endif
18837 +       ret = 0;
18838 +out:
18839 +       vxdprintk(VXD_CBIT(net, 3),
18840 +               "dev_in_nx_info(%p,%p[#%d]) = %d",
18841 +               dev, nxi, nxi ? nxi->nx_id : 0, ret);
18842 +       return ret;
18843 +}
18844 +
18845 +struct rtable *ip_v4_find_src(struct net *net, struct nx_info *nxi,
18846 +       struct flowi4 *fl4)
18847 +{
18848 +       struct rtable *rt;
18849 +
18850 +       if (!nxi)
18851 +               return NULL;
18852 +
18853 +       /* FIXME: handle lback only case */
18854 +       if (!NX_IPV4(nxi))
18855 +               return ERR_PTR(-EPERM);
18856 +
18857 +       vxdprintk(VXD_CBIT(net, 4),
18858 +               "ip_v4_find_src(%p[#%u]) " NIPQUAD_FMT " -> " NIPQUAD_FMT,
18859 +               nxi, nxi ? nxi->nx_id : 0,
18860 +               NIPQUAD(fl4->saddr), NIPQUAD(fl4->daddr));
18861 +
18862 +       /* single IP is unconditional */
18863 +       if (nx_info_flags(nxi, NXF_SINGLE_IP, 0) &&
18864 +               (fl4->saddr == INADDR_ANY))
18865 +               fl4->saddr = nxi->v4.ip[0].s_addr;
18866 +
18867 +       if (fl4->saddr == INADDR_ANY) {
18868 +               struct nx_addr_v4 *ptr;
18869 +               __be32 found = 0;
18870 +
18871 +               rt = __ip_route_output_key(net, fl4);
18872 +               if (!IS_ERR(rt)) {
18873 +                       found = fl4->saddr;
18874 +                       ip_rt_put(rt);
18875 +                       vxdprintk(VXD_CBIT(net, 4),
18876 +                               "ip_v4_find_src(%p[#%u]) rok[%u]: " NIPQUAD_FMT,
18877 +                               nxi, nxi ? nxi->nx_id : 0, fl4->flowi4_oif, NIPQUAD(found));
18878 +                       if (v4_addr_in_nx_info(nxi, found, NXA_MASK_BIND))
18879 +                               goto found;
18880 +               }
18881 +
18882 +               WARN_ON_ONCE(in_irq());
18883 +               spin_lock_bh(&nxi->addr_lock);
18884 +               for (ptr = &nxi->v4; ptr; ptr = ptr->next) {
18885 +                       __be32 primary = ptr->ip[0].s_addr;
18886 +                       __be32 mask = ptr->mask.s_addr;
18887 +                       __be32 neta = primary & mask;
18888 +
18889 +                       vxdprintk(VXD_CBIT(net, 4), "ip_v4_find_src(%p[#%u]) chk: "
18890 +                               NIPQUAD_FMT "/" NIPQUAD_FMT "/" NIPQUAD_FMT,
18891 +                               nxi, nxi ? nxi->nx_id : 0, NIPQUAD(primary),
18892 +                               NIPQUAD(mask), NIPQUAD(neta));
18893 +                       if ((found & mask) != neta)
18894 +                               continue;
18895 +
18896 +                       fl4->saddr = primary;
18897 +                       rt = __ip_route_output_key(net, fl4);
18898 +                       vxdprintk(VXD_CBIT(net, 4),
18899 +                               "ip_v4_find_src(%p[#%u]) rok[%u]: " NIPQUAD_FMT,
18900 +                               nxi, nxi ? nxi->nx_id : 0, fl4->flowi4_oif, NIPQUAD(primary));
18901 +                       if (!IS_ERR(rt)) {
18902 +                               found = fl4->saddr;
18903 +                               ip_rt_put(rt);
18904 +                               if (found == primary)
18905 +                                       goto found_unlock;
18906 +                       }
18907 +               }
18908 +               /* still no source ip? */
18909 +               found = ipv4_is_loopback(fl4->daddr)
18910 +                       ? IPI_LOOPBACK : nxi->v4.ip[0].s_addr;
18911 +       found_unlock:
18912 +               spin_unlock_bh(&nxi->addr_lock);
18913 +       found:
18914 +               /* assign src ip to flow */
18915 +               fl4->saddr = found;
18916 +
18917 +       } else {
18918 +               if (!v4_addr_in_nx_info(nxi, fl4->saddr, NXA_MASK_BIND))
18919 +                       return ERR_PTR(-EPERM);
18920 +       }
18921 +
18922 +       if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0)) {
18923 +               if (ipv4_is_loopback(fl4->daddr))
18924 +                       fl4->daddr = nxi->v4_lback.s_addr;
18925 +               if (ipv4_is_loopback(fl4->saddr))
18926 +                       fl4->saddr = nxi->v4_lback.s_addr;
18927 +       } else if (ipv4_is_loopback(fl4->daddr) &&
18928 +               !nx_info_flags(nxi, NXF_LBACK_ALLOW, 0))
18929 +               return ERR_PTR(-EPERM);
18930 +
18931 +       return NULL;
18932 +}
18933 +
18934 +EXPORT_SYMBOL_GPL(ip_v4_find_src);
18935 +
18936 diff -NurpP --minimal linux-3.9.4/kernel/vserver/init.c linux-3.9.4-vs2.3.6.2/kernel/vserver/init.c
18937 --- linux-3.9.4/kernel/vserver/init.c   1970-01-01 00:00:00.000000000 +0000
18938 +++ linux-3.9.4-vs2.3.6.2/kernel/vserver/init.c 2013-05-31 14:47:11.000000000 +0000
18939 @@ -0,0 +1,45 @@
18940 +/*
18941 + *  linux/kernel/init.c
18942 + *
18943 + *  Virtual Server Init
18944 + *
18945 + *  Copyright (C) 2004-2007  Herbert Pötzl
18946 + *
18947 + *  V0.01  basic structure
18948 + *
18949 + */
18950 +
18951 +#include <linux/init.h>
18952 +
18953 +int    vserver_register_sysctl(void);
18954 +void   vserver_unregister_sysctl(void);
18955 +
18956 +
18957 +static int __init init_vserver(void)
18958 +{
18959 +       int ret = 0;
18960 +
18961 +#ifdef CONFIG_VSERVER_DEBUG
18962 +       vserver_register_sysctl();
18963 +#endif
18964 +       return ret;
18965 +}
18966 +
18967 +
18968 +static void __exit exit_vserver(void)
18969 +{
18970 +
18971 +#ifdef CONFIG_VSERVER_DEBUG
18972 +       vserver_unregister_sysctl();
18973 +#endif
18974 +       return;
18975 +}
18976 +
18977 +/* FIXME: GFP_ZONETYPES gone
18978 +long vx_slab[GFP_ZONETYPES]; */
18979 +long vx_area;
18980 +
18981 +
18982 +module_init(init_vserver);
18983 +module_exit(exit_vserver);
18984 +
18985 diff -NurpP --minimal linux-3.9.4/kernel/vserver/inode.c linux-3.9.4-vs2.3.6.2/kernel/vserver/inode.c
18986 --- linux-3.9.4/kernel/vserver/inode.c  1970-01-01 00:00:00.000000000 +0000
18987 +++ linux-3.9.4-vs2.3.6.2/kernel/vserver/inode.c        2013-06-01 08:26:06.000000000 +0000
18988 @@ -0,0 +1,437 @@
18989 +/*
18990 + *  linux/kernel/vserver/inode.c
18991 + *
18992 + *  Virtual Server: File System Support
18993 + *
18994 + *  Copyright (C) 2004-2007  Herbert Pötzl
18995 + *
18996 + *  V0.01  separated from vcontext V0.05
18997 + *  V0.02  moved to tag (instead of xid)
18998 + *
18999 + */
19000 +
19001 +#include <linux/tty.h>
19002 +#include <linux/proc_fs.h>
19003 +#include <linux/devpts_fs.h>
19004 +#include <linux/fs.h>
19005 +#include <linux/file.h>
19006 +#include <linux/mount.h>
19007 +#include <linux/parser.h>
19008 +#include <linux/namei.h>
19009 +#include <linux/vserver/inode.h>
19010 +#include <linux/vserver/inode_cmd.h>
19011 +#include <linux/vs_base.h>
19012 +#include <linux/vs_tag.h>
19013 +
19014 +#include <asm/uaccess.h>
19015 +
19016 +
19017 +static int __vc_get_iattr(struct inode *in, uint32_t *tag, uint32_t *flags, uint32_t *mask)
19018 +{
19019 +       struct proc_dir_entry *entry;
19020 +
19021 +       if (!in || !in->i_sb)
19022 +               return -ESRCH;
19023 +
19024 +       *flags = IATTR_TAG
19025 +               | (IS_IMMUTABLE(in) ? IATTR_IMMUTABLE : 0)
19026 +               | (IS_IXUNLINK(in) ? IATTR_IXUNLINK : 0)
19027 +               | (IS_BARRIER(in) ? IATTR_BARRIER : 0)
19028 +               | (IS_COW(in) ? IATTR_COW : 0);
19029 +       *mask = IATTR_IXUNLINK | IATTR_IMMUTABLE | IATTR_COW;
19030 +
19031 +       if (S_ISDIR(in->i_mode))
19032 +               *mask |= IATTR_BARRIER;
19033 +
19034 +       if (IS_TAGGED(in)) {
19035 +               *tag = i_tag_read(in);
19036 +               *mask |= IATTR_TAG;
19037 +       }
19038 +
19039 +       switch (in->i_sb->s_magic) {
19040 +       case PROC_SUPER_MAGIC:
19041 +               entry = PROC_I(in)->pde;
19042 +
19043 +               /* check for specific inodes? */
19044 +               if (entry)
19045 +                       *mask |= IATTR_FLAGS;
19046 +               if (entry)
19047 +                       *flags |= (entry->vx_flags & IATTR_FLAGS);
19048 +               else
19049 +                       *flags |= (PROC_I(in)->vx_flags & IATTR_FLAGS);
19050 +               break;
19051 +
19052 +       case DEVPTS_SUPER_MAGIC:
19053 +               *tag = i_tag_read(in);
19054 +               *mask |= IATTR_TAG;
19055 +               break;
19056 +
19057 +       default:
19058 +               break;
19059 +       }
19060 +       return 0;
19061 +}
19062 +
19063 +int vc_get_iattr(void __user *data)
19064 +{
19065 +       struct path path;
19066 +       struct vcmd_ctx_iattr_v1 vc_data = { .tag = -1 };
19067 +       int ret;
19068 +
19069 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19070 +               return -EFAULT;
19071 +
19072 +       ret = user_lpath(vc_data.name, &path);
19073 +       if (!ret) {
19074 +               ret = __vc_get_iattr(path.dentry->d_inode,
19075 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
19076 +               path_put(&path);
19077 +       }
19078 +       if (ret)
19079 +               return ret;
19080 +
19081 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19082 +               ret = -EFAULT;
19083 +       return ret;
19084 +}
19085 +
19086 +#ifdef CONFIG_COMPAT
19087 +
19088 +int vc_get_iattr_x32(void __user *data)
19089 +{
19090 +       struct path path;
19091 +       struct vcmd_ctx_iattr_v1_x32 vc_data = { .tag = -1 };
19092 +       int ret;
19093 +
19094 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19095 +               return -EFAULT;
19096 +
19097 +       ret = user_lpath(compat_ptr(vc_data.name_ptr), &path);
19098 +       if (!ret) {
19099 +               ret = __vc_get_iattr(path.dentry->d_inode,
19100 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
19101 +               path_put(&path);
19102 +       }
19103 +       if (ret)
19104 +               return ret;
19105 +
19106 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19107 +               ret = -EFAULT;
19108 +       return ret;
19109 +}
19110 +
19111 +#endif /* CONFIG_COMPAT */
19112 +
19113 +
19114 +int vc_fget_iattr(uint32_t fd, void __user *data)
19115 +{
19116 +       struct file *filp;
19117 +       struct vcmd_ctx_fiattr_v0 vc_data = { .tag = -1 };
19118 +       int ret;
19119 +
19120 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19121 +               return -EFAULT;
19122 +
19123 +       filp = fget(fd);
19124 +       if (!filp || !filp->f_dentry || !filp->f_dentry->d_inode)
19125 +               return -EBADF;
19126 +
19127 +       ret = __vc_get_iattr(filp->f_dentry->d_inode,
19128 +               &vc_data.tag, &vc_data.flags, &vc_data.mask);
19129 +
19130 +       fput(filp);
19131 +
19132 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19133 +               ret = -EFAULT;
19134 +       return ret;
19135 +}
19136 +
19137 +
19138 +static int __vc_set_iattr(struct dentry *de, uint32_t *tag, uint32_t *flags, uint32_t *mask)
19139 +{
19140 +       struct inode *in = de->d_inode;
19141 +       int error = 0, is_proc = 0, has_tag = 0;
19142 +       struct iattr attr = { 0 };
19143 +
19144 +       if (!in || !in->i_sb)
19145 +               return -ESRCH;
19146 +
19147 +       is_proc = (in->i_sb->s_magic == PROC_SUPER_MAGIC);
19148 +       if ((*mask & IATTR_FLAGS) && !is_proc)
19149 +               return -EINVAL;
19150 +
19151 +       has_tag = IS_TAGGED(in) ||
19152 +               (in->i_sb->s_magic == DEVPTS_SUPER_MAGIC);
19153 +       if ((*mask & IATTR_TAG) && !has_tag)
19154 +               return -EINVAL;
19155 +
19156 +       mutex_lock(&in->i_mutex);
19157 +       if (*mask & IATTR_TAG) {
19158 +               attr.ia_tag = make_ktag(&init_user_ns, *tag);
19159 +               attr.ia_valid |= ATTR_TAG;
19160 +       }
19161 +
19162 +       if (*mask & IATTR_FLAGS) {
19163 +               struct proc_dir_entry *entry = PROC_I(in)->pde;
19164 +               unsigned int iflags = PROC_I(in)->vx_flags;
19165 +
19166 +               iflags = (iflags & ~(*mask & IATTR_FLAGS))
19167 +                       | (*flags & IATTR_FLAGS);
19168 +               PROC_I(in)->vx_flags = iflags;
19169 +               if (entry)
19170 +                       entry->vx_flags = iflags;
19171 +       }
19172 +
19173 +       if (*mask & (IATTR_IMMUTABLE | IATTR_IXUNLINK |
19174 +               IATTR_BARRIER | IATTR_COW)) {
19175 +               int iflags = in->i_flags;
19176 +               int vflags = in->i_vflags;
19177 +
19178 +               if (*mask & IATTR_IMMUTABLE) {
19179 +                       if (*flags & IATTR_IMMUTABLE)
19180 +                               iflags |= S_IMMUTABLE;
19181 +                       else
19182 +                               iflags &= ~S_IMMUTABLE;
19183 +               }
19184 +               if (*mask & IATTR_IXUNLINK) {
19185 +                       if (*flags & IATTR_IXUNLINK)
19186 +                               iflags |= S_IXUNLINK;
19187 +                       else
19188 +                               iflags &= ~S_IXUNLINK;
19189 +               }
19190 +               if (S_ISDIR(in->i_mode) && (*mask & IATTR_BARRIER)) {
19191 +                       if (*flags & IATTR_BARRIER)
19192 +                               vflags |= V_BARRIER;
19193 +                       else
19194 +                               vflags &= ~V_BARRIER;
19195 +               }
19196 +               if (S_ISREG(in->i_mode) && (*mask & IATTR_COW)) {
19197 +                       if (*flags & IATTR_COW)
19198 +                               vflags |= V_COW;
19199 +                       else
19200 +                               vflags &= ~V_COW;
19201 +               }
19202 +               if (in->i_op && in->i_op->sync_flags) {
19203 +                       error = in->i_op->sync_flags(in, iflags, vflags);
19204 +                       if (error)
19205 +                               goto out;
19206 +               }
19207 +       }
19208 +
19209 +       if (attr.ia_valid) {
19210 +               if (in->i_op && in->i_op->setattr)
19211 +                       error = in->i_op->setattr(de, &attr);
19212 +               else {
19213 +                       error = inode_change_ok(in, &attr);
19214 +                       if (!error) {
19215 +                               setattr_copy(in, &attr);
19216 +                               mark_inode_dirty(in);
19217 +                       }
19218 +               }
19219 +       }
19220 +
19221 +out:
19222 +       mutex_unlock(&in->i_mutex);
19223 +       return error;
19224 +}
19225 +
19226 +int vc_set_iattr(void __user *data)
19227 +{
19228 +       struct path path;
19229 +       struct vcmd_ctx_iattr_v1 vc_data;
19230 +       int ret;
19231 +
19232 +       if (!capable(CAP_LINUX_IMMUTABLE))
19233 +               return -EPERM;
19234 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19235 +               return -EFAULT;
19236 +
19237 +       ret = user_lpath(vc_data.name, &path);
19238 +       if (!ret) {
19239 +               ret = __vc_set_iattr(path.dentry,
19240 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
19241 +               path_put(&path);
19242 +       }
19243 +
19244 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19245 +               ret = -EFAULT;
19246 +       return ret;
19247 +}
19248 +
19249 +#ifdef CONFIG_COMPAT
19250 +
19251 +int vc_set_iattr_x32(void __user *data)
19252 +{
19253 +       struct path path;
19254 +       struct vcmd_ctx_iattr_v1_x32 vc_data;
19255 +       int ret;
19256 +
19257 +       if (!capable(CAP_LINUX_IMMUTABLE))
19258 +               return -EPERM;
19259 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19260 +               return -EFAULT;
19261 +
19262 +       ret = user_lpath(compat_ptr(vc_data.name_ptr), &path);
19263 +       if (!ret) {
19264 +               ret = __vc_set_iattr(path.dentry,
19265 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
19266 +               path_put(&path);
19267 +       }
19268 +
19269 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19270 +               ret = -EFAULT;
19271 +       return ret;
19272 +}
19273 +
19274 +#endif /* CONFIG_COMPAT */
19275 +
19276 +int vc_fset_iattr(uint32_t fd, void __user *data)
19277 +{
19278 +       struct file *filp;
19279 +       struct vcmd_ctx_fiattr_v0 vc_data;
19280 +       int ret;
19281 +
19282 +       if (!capable(CAP_LINUX_IMMUTABLE))
19283 +               return -EPERM;
19284 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19285 +               return -EFAULT;
19286 +
19287 +       filp = fget(fd);
19288 +       if (!filp || !filp->f_dentry || !filp->f_dentry->d_inode)
19289 +               return -EBADF;
19290 +
19291 +       ret = __vc_set_iattr(filp->f_dentry, &vc_data.tag,
19292 +               &vc_data.flags, &vc_data.mask);
19293 +
19294 +       fput(filp);
19295 +
19296 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19297 +               return -EFAULT;
19298 +       return ret;
19299 +}
19300 +
19301 +
19302 +enum { Opt_notagcheck, Opt_tag, Opt_notag, Opt_tagid, Opt_err };
19303 +
19304 +static match_table_t tokens = {
19305 +       {Opt_notagcheck, "notagcheck"},
19306 +#ifdef CONFIG_PROPAGATE
19307 +       {Opt_notag, "notag"},
19308 +       {Opt_tag, "tag"},
19309 +       {Opt_tagid, "tagid=%u"},
19310 +#endif
19311 +       {Opt_err, NULL}
19312 +};
19313 +
19314 +
19315 +static void __dx_parse_remove(char *string, char *opt)
19316 +{
19317 +       char *p = strstr(string, opt);
19318 +       char *q = p;
19319 +
19320 +       if (p) {
19321 +               while (*q != '\0' && *q != ',')
19322 +                       q++;
19323 +               while (*q)
19324 +                       *p++ = *q++;
19325 +               while (*p)
19326 +                       *p++ = '\0';
19327 +       }
19328 +}
19329 +
19330 +int dx_parse_tag(char *string, tag_t *tag, int remove, int *mnt_flags,
19331 +                unsigned long *flags)
19332 +{
19333 +       int set = 0;
19334 +       substring_t args[MAX_OPT_ARGS];
19335 +       int token;
19336 +       char *s, *p, *opts;
19337 +#if defined(CONFIG_PROPAGATE) || defined(CONFIG_VSERVER_DEBUG)
19338 +       int option = 0;
19339 +#endif
19340 +
19341 +       if (!string)
19342 +               return 0;
19343 +       s = kstrdup(string, GFP_KERNEL | GFP_ATOMIC);
19344 +       if (!s)
19345 +               return 0;
19346 +
19347 +       opts = s;
19348 +       while ((p = strsep(&opts, ",")) != NULL) {
19349 +               token = match_token(p, tokens, args);
19350 +
19351 +               switch (token) {
19352 +#ifdef CONFIG_PROPAGATE
19353 +               case Opt_tag:
19354 +                       if (tag)
19355 +                               *tag = 0;
19356 +                       if (remove)
19357 +                               __dx_parse_remove(s, "tag");
19358 +                       *mnt_flags |= MNT_TAGID;
19359 +                       set |= MNT_TAGID;
19360 +                       break;
19361 +               case Opt_notag:
19362 +                       if (remove)
19363 +                               __dx_parse_remove(s, "notag");
19364 +                       *mnt_flags |= MNT_NOTAG;
19365 +                       set |= MNT_NOTAG;
19366 +                       break;
19367 +               case Opt_tagid:
19368 +                       if (tag && !match_int(args, &option))
19369 +                               *tag = option;
19370 +                       if (remove)
19371 +                               __dx_parse_remove(s, "tagid");
19372 +                       *mnt_flags |= MNT_TAGID;
19373 +                       set |= MNT_TAGID;
19374 +                       break;
19375 +#endif /* CONFIG_PROPAGATE */
19376 +               case Opt_notagcheck:
19377 +                       if (remove)
19378 +                               __dx_parse_remove(s, "notagcheck");
19379 +                       *flags |= MS_NOTAGCHECK;
19380 +                       set |= MS_NOTAGCHECK;
19381 +                       break;
19382 +               }
19383 +               vxdprintk(VXD_CBIT(tag, 7),
19384 +                       "dx_parse_tag(" VS_Q("%s") "): %d:#%d",
19385 +                       p, token, option);
19386 +       }
19387 +       if (set)
19388 +               strcpy(string, s);
19389 +       kfree(s);
19390 +       return set;
19391 +}
19392 +
19393 +#ifdef CONFIG_PROPAGATE
19394 +
19395 +void __dx_propagate_tag(struct nameidata *nd, struct inode *inode)
19396 +{
19397 +       tag_t new_tag = 0;
19398 +       struct vfsmount *mnt;
19399 +       int propagate;
19400 +
19401 +       if (!nd)
19402 +               return;
19403 +       mnt = nd->path.mnt;
19404 +       if (!mnt)
19405 +               return;
19406 +
19407 +       propagate = (mnt->mnt_flags & MNT_TAGID);
19408 +       if (propagate)
19409 +               new_tag = mnt->mnt_tag;
19410 +
19411 +       vxdprintk(VXD_CBIT(tag, 7),
19412 +               "dx_propagate_tag(%p[#%lu.%d]): %d,%d",
19413 +               inode, inode->i_ino, inode->i_tag,
19414 +               new_tag, (propagate) ? 1 : 0);
19415 +
19416 +       if (propagate)
19417 +               i_tag_write(inode, new_tag);
19418 +}
19419 +
19420 +#include <linux/module.h>
19421 +
19422 +EXPORT_SYMBOL_GPL(__dx_propagate_tag);
19423 +
19424 +#endif /* CONFIG_PROPAGATE */
19425 +
19426 diff -NurpP --minimal linux-3.9.4/kernel/vserver/limit.c linux-3.9.4-vs2.3.6.2/kernel/vserver/limit.c
19427 --- linux-3.9.4/kernel/vserver/limit.c  1970-01-01 00:00:00.000000000 +0000
19428 +++ linux-3.9.4-vs2.3.6.2/kernel/vserver/limit.c        2013-05-31 14:47:11.000000000 +0000
19429 @@ -0,0 +1,345 @@
19430 +/*
19431 + *  linux/kernel/vserver/limit.c
19432 + *
19433 + *  Virtual Server: Context Limits
19434 + *
19435 + *  Copyright (C) 2004-2010  Herbert Pötzl
19436 + *
19437 + *  V0.01  broken out from vcontext V0.05
19438 + *  V0.02  changed vcmds to vxi arg
19439 + *  V0.03  added memory cgroup support
19440 + *
19441 + */
19442 +
19443 +#include <linux/sched.h>
19444 +#include <linux/module.h>
19445 +#include <linux/memcontrol.h>
19446 +#include <linux/res_counter.h>
19447 +#include <linux/vs_limit.h>
19448 +#include <linux/vserver/limit.h>
19449 +#include <linux/vserver/limit_cmd.h>
19450 +
19451 +#include <asm/uaccess.h>
19452 +
19453 +
19454 +const char *vlimit_name[NUM_LIMITS] = {
19455 +       [RLIMIT_CPU]            = "CPU",
19456 +       [RLIMIT_NPROC]          = "NPROC",
19457 +       [RLIMIT_NOFILE]         = "NOFILE",
19458 +       [RLIMIT_LOCKS]          = "LOCKS",
19459 +       [RLIMIT_SIGPENDING]     = "SIGP",
19460 +       [RLIMIT_MSGQUEUE]       = "MSGQ",
19461 +
19462 +       [VLIMIT_NSOCK]          = "NSOCK",
19463 +       [VLIMIT_OPENFD]         = "OPENFD",
19464 +       [VLIMIT_SHMEM]          = "SHMEM",
19465 +       [VLIMIT_DENTRY]         = "DENTRY",
19466 +};
19467 +
19468 +EXPORT_SYMBOL_GPL(vlimit_name);
19469 +
19470 +#define MASK_ENTRY(x)  (1 << (x))
19471 +
19472 +const struct vcmd_ctx_rlimit_mask_v0 vlimit_mask = {
19473 +               /* minimum */
19474 +       0
19475 +       ,       /* softlimit */
19476 +       0
19477 +       ,       /* maximum */
19478 +       MASK_ENTRY( RLIMIT_NPROC        ) |
19479 +       MASK_ENTRY( RLIMIT_NOFILE       ) |
19480 +       MASK_ENTRY( RLIMIT_LOCKS        ) |
19481 +       MASK_ENTRY( RLIMIT_MSGQUEUE     ) |
19482 +
19483 +       MASK_ENTRY( VLIMIT_NSOCK        ) |
19484 +       MASK_ENTRY( VLIMIT_OPENFD       ) |
19485 +       MASK_ENTRY( VLIMIT_SHMEM        ) |
19486 +       MASK_ENTRY( VLIMIT_DENTRY       ) |
19487 +       0
19488 +};
19489 +               /* accounting only */
19490 +uint32_t account_mask =
19491 +       MASK_ENTRY( VLIMIT_SEMARY       ) |
19492 +       MASK_ENTRY( VLIMIT_NSEMS        ) |
19493 +       MASK_ENTRY( VLIMIT_MAPPED       ) |
19494 +       0;
19495 +
19496 +
19497 +static int is_valid_vlimit(int id)
19498 +{
19499 +       uint32_t mask = vlimit_mask.minimum |
19500 +               vlimit_mask.softlimit | vlimit_mask.maximum;
19501 +       return mask & (1 << id);
19502 +}
19503 +
19504 +static int is_accounted_vlimit(int id)
19505 +{
19506 +       if (is_valid_vlimit(id))
19507 +               return 1;
19508 +       return account_mask & (1 << id);
19509 +}
19510 +
19511 +
19512 +static inline uint64_t vc_get_soft(struct vx_info *vxi, int id)
19513 +{
19514 +       rlim_t limit = __rlim_soft(&vxi->limit, id);
19515 +       return VX_VLIM(limit);
19516 +}
19517 +
19518 +static inline uint64_t vc_get_hard(struct vx_info *vxi, int id)
19519 +{
19520 +       rlim_t limit = __rlim_hard(&vxi->limit, id);
19521 +       return VX_VLIM(limit);
19522 +}
19523 +
19524 +static int do_get_rlimit(struct vx_info *vxi, uint32_t id,
19525 +       uint64_t *minimum, uint64_t *softlimit, uint64_t *maximum)
19526 +{
19527 +       if (!is_valid_vlimit(id))
19528 +               return -EINVAL;
19529 +
19530 +       if (minimum)
19531 +               *minimum = CRLIM_UNSET;
19532 +       if (softlimit)
19533 +               *softlimit = vc_get_soft(vxi, id);
19534 +       if (maximum)
19535 +               *maximum = vc_get_hard(vxi, id);
19536 +       return 0;
19537 +}
19538 +
19539 +int vc_get_rlimit(struct vx_info *vxi, void __user *data)
19540 +{
19541 +       struct vcmd_ctx_rlimit_v0 vc_data;
19542 +       int ret;
19543 +
19544 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19545 +               return -EFAULT;
19546 +
19547 +       ret = do_get_rlimit(vxi, vc_data.id,
19548 +               &vc_data.minimum, &vc_data.softlimit, &vc_data.maximum);
19549 +       if (ret)
19550 +               return ret;
19551 +
19552 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19553 +               return -EFAULT;
19554 +       return 0;
19555 +}
19556 +
19557 +static int do_set_rlimit(struct vx_info *vxi, uint32_t id,
19558 +       uint64_t minimum, uint64_t softlimit, uint64_t maximum)
19559 +{
19560 +       if (!is_valid_vlimit(id))
19561 +               return -EINVAL;
19562 +
19563 +       if (maximum != CRLIM_KEEP)
19564 +               __rlim_hard(&vxi->limit, id) = VX_RLIM(maximum);
19565 +       if (softlimit != CRLIM_KEEP)
19566 +               __rlim_soft(&vxi->limit, id) = VX_RLIM(softlimit);
19567 +
19568 +       /* clamp soft limit */
19569 +       if (__rlim_soft(&vxi->limit, id) > __rlim_hard(&vxi->limit, id))
19570 +               __rlim_soft(&vxi->limit, id) = __rlim_hard(&vxi->limit, id);
19571 +
19572 +       return 0;
19573 +}
19574 +
19575 +int vc_set_rlimit(struct vx_info *vxi, void __user *data)
19576 +{
19577 +       struct vcmd_ctx_rlimit_v0 vc_data;
19578 +
19579 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19580 +               return -EFAULT;
19581 +
19582 +       return do_set_rlimit(vxi, vc_data.id,
19583 +               vc_data.minimum, vc_data.softlimit, vc_data.maximum);
19584 +}
19585 +
19586 +#ifdef CONFIG_IA32_EMULATION
19587 +
19588 +int vc_set_rlimit_x32(struct vx_info *vxi, void __user *data)
19589 +{
19590 +       struct vcmd_ctx_rlimit_v0_x32 vc_data;
19591 +
19592 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19593 +               return -EFAULT;
19594 +
19595 +       return do_set_rlimit(vxi, vc_data.id,
19596 +               vc_data.minimum, vc_data.softlimit, vc_data.maximum);
19597 +}
19598 +
19599 +int vc_get_rlimit_x32(struct vx_info *vxi, void __user *data)
19600 +{
19601 +       struct vcmd_ctx_rlimit_v0_x32 vc_data;
19602 +       int ret;
19603 +
19604 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19605 +               return -EFAULT;
19606 +
19607 +       ret = do_get_rlimit(vxi, vc_data.id,
19608 +               &vc_data.minimum, &vc_data.softlimit, &vc_data.maximum);
19609 +       if (ret)
19610 +               return ret;
19611 +
19612 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19613 +               return -EFAULT;
19614 +       return 0;
19615 +}
19616 +
19617 +#endif /* CONFIG_IA32_EMULATION */
19618 +
19619 +
19620 +int vc_get_rlimit_mask(uint32_t id, void __user *data)
19621 +{
19622 +       if (copy_to_user(data, &vlimit_mask, sizeof(vlimit_mask)))
19623 +               return -EFAULT;
19624 +       return 0;
19625 +}
19626 +
19627 +
19628 +static inline void vx_reset_hits(struct _vx_limit *limit)
19629 +{
19630 +       int lim;
19631 +
19632 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
19633 +               atomic_set(&__rlim_lhit(limit, lim), 0);
19634 +       }
19635 +}
19636 +
19637 +int vc_reset_hits(struct vx_info *vxi, void __user *data)
19638 +{
19639 +       vx_reset_hits(&vxi->limit);
19640 +       return 0;
19641 +}
19642 +
19643 +static inline void vx_reset_minmax(struct _vx_limit *limit)
19644 +{
19645 +       rlim_t value;
19646 +       int lim;
19647 +
19648 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
19649 +               value = __rlim_get(limit, lim);
19650 +               __rlim_rmax(limit, lim) = value;
19651 +               __rlim_rmin(limit, lim) = value;
19652 +       }
19653 +}
19654 +
19655 +int vc_reset_minmax(struct vx_info *vxi, void __user *data)
19656 +{
19657 +       vx_reset_minmax(&vxi->limit);
19658 +       return 0;
19659 +}
19660 +
19661 +
19662 +int vc_rlimit_stat(struct vx_info *vxi, void __user *data)
19663 +{
19664 +       struct vcmd_rlimit_stat_v0 vc_data;
19665 +       struct _vx_limit *limit = &vxi->limit;
19666 +       int id;
19667 +
19668 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19669 +               return -EFAULT;
19670 +
19671 +       id = vc_data.id;
19672 +       if (!is_accounted_vlimit(id))
19673 +               return -EINVAL;
19674 +
19675 +       vx_limit_fixup(limit, id);
19676 +       vc_data.hits = atomic_read(&__rlim_lhit(limit, id));
19677 +       vc_data.value = __rlim_get(limit, id);
19678 +       vc_data.minimum = __rlim_rmin(limit, id);
19679 +       vc_data.maximum = __rlim_rmax(limit, id);
19680 +
19681 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19682 +               return -EFAULT;
19683 +       return 0;
19684 +}
19685 +
19686 +
19687 +void vx_vsi_meminfo(struct sysinfo *val)
19688 +{
19689 +#ifdef CONFIG_MEMCG
19690 +       struct mem_cgroup *mcg;
19691 +       u64 res_limit, res_usage;
19692 +
19693 +       rcu_read_lock();
19694 +       mcg = mem_cgroup_from_task(current);
19695 +       rcu_read_unlock();
19696 +       if (!mcg)
19697 +               goto out;
19698 +
19699 +       res_limit = mem_cgroup_res_read_u64(mcg, RES_LIMIT);
19700 +       res_usage = mem_cgroup_res_read_u64(mcg, RES_USAGE);
19701 +
19702 +       if (res_limit != RESOURCE_MAX)
19703 +               val->totalram = (res_limit >> PAGE_SHIFT);
19704 +       val->freeram = val->totalram - (res_usage >> PAGE_SHIFT);
19705 +       val->bufferram = 0;
19706 +       val->totalhigh = 0;
19707 +       val->freehigh = 0;
19708 +out:
19709 +#endif /* CONFIG_MEMCG */
19710 +       return;
19711 +}
19712 +
19713 +void vx_vsi_swapinfo(struct sysinfo *val)
19714 +{
19715 +#ifdef CONFIG_MEMCG
19716 +#ifdef CONFIG_MEMCG_SWAP
19717 +       struct mem_cgroup *mcg;
19718 +       u64 res_limit, res_usage, memsw_limit, memsw_usage;
19719 +       s64 swap_limit, swap_usage;
19720 +
19721 +       rcu_read_lock();
19722 +       mcg = mem_cgroup_from_task(current);
19723 +       rcu_read_unlock();
19724 +       if (!mcg)
19725 +               goto out;
19726 +
19727 +       res_limit = mem_cgroup_res_read_u64(mcg, RES_LIMIT);
19728 +       res_usage = mem_cgroup_res_read_u64(mcg, RES_USAGE);
19729 +       memsw_limit = mem_cgroup_memsw_read_u64(mcg, RES_LIMIT);
19730 +       memsw_usage = mem_cgroup_memsw_read_u64(mcg, RES_USAGE);
19731 +
19732 +       /* memory unlimited */
19733 +       if (res_limit == RESOURCE_MAX)
19734 +               goto out;
19735 +
19736 +       swap_limit = memsw_limit - res_limit;
19737 +       /* we have a swap limit? */
19738 +       if (memsw_limit != RESOURCE_MAX)
19739 +               val->totalswap = swap_limit >> PAGE_SHIFT;
19740 +
19741 +       /* calculate swap part */
19742 +       swap_usage = (memsw_usage > res_usage) ?
19743 +               memsw_usage - res_usage : 0;
19744 +
19745 +       /* total shown minus usage gives free swap */
19746 +       val->freeswap = (swap_usage < swap_limit) ?
19747 +               val->totalswap - (swap_usage >> PAGE_SHIFT) : 0;
19748 +out:
19749 +#else  /* !CONFIG_MEMCG_SWAP */
19750 +       val->totalswap = 0;
19751 +       val->freeswap = 0;
19752 +#endif /* !CONFIG_MEMCG_SWAP */
19753 +#endif /* CONFIG_MEMCG */
19754 +       return;
19755 +}
19756 +
19757 +long vx_vsi_cached(struct sysinfo *val)
19758 +{
19759 +       long cache = 0;
19760 +#ifdef CONFIG_MEMCG
19761 +       struct mem_cgroup *mcg;
19762 +
19763 +       rcu_read_lock();
19764 +       mcg = mem_cgroup_from_task(current);
19765 +       rcu_read_unlock();
19766 +       if (!mcg)
19767 +               goto out;
19768 +
19769 +       cache = mem_cgroup_stat_read_cache(mcg);
19770 +out:
19771 +#endif
19772 +       return cache;
19773 +}
19774 +
19775 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
19776 --- linux-3.9.4/kernel/vserver/limit_init.h     1970-01-01 00:00:00.000000000 +0000
19777 +++ linux-3.9.4-vs2.3.6.2/kernel/vserver/limit_init.h   2013-05-31 14:47:11.000000000 +0000
19778 @@ -0,0 +1,31 @@
19779 +
19780 +
19781 +static inline void vx_info_init_limit(struct _vx_limit *limit)
19782 +{
19783 +       int lim;
19784 +
19785 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
19786 +               __rlim_soft(limit, lim) = RLIM_INFINITY;
19787 +               __rlim_hard(limit, lim) = RLIM_INFINITY;
19788 +               __rlim_set(limit, lim, 0);
19789 +               atomic_set(&__rlim_lhit(limit, lim), 0);
19790 +               __rlim_rmin(limit, lim) = 0;
19791 +               __rlim_rmax(limit, lim) = 0;
19792 +       }
19793 +}
19794 +
19795 +static inline void vx_info_exit_limit(struct _vx_limit *limit)
19796 +{
19797 +       rlim_t value;
19798 +       int lim;
19799 +
19800 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
19801 +               if ((1 << lim) & VLIM_NOCHECK)
19802 +                       continue;
19803 +               value = __rlim_get(limit, lim);
19804 +               vxwprintk_xid(value,
19805 +                       "!!! limit: %p[%s,%d] = %ld on exit.",
19806 +                       limit, vlimit_name[lim], lim, (long)value);
19807 +       }
19808 +}
19809 +
19810 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
19811 --- linux-3.9.4/kernel/vserver/limit_proc.h     1970-01-01 00:00:00.000000000 +0000
19812 +++ linux-3.9.4-vs2.3.6.2/kernel/vserver/limit_proc.h   2013-05-31 14:47:11.000000000 +0000
19813 @@ -0,0 +1,57 @@
19814 +#ifndef _VX_LIMIT_PROC_H
19815 +#define _VX_LIMIT_PROC_H
19816 +
19817 +#include <linux/vserver/limit_int.h>
19818 +
19819 +
19820 +#define VX_LIMIT_FMT   ":\t%8ld\t%8ld/%8ld\t%8lld/%8lld\t%6d\n"
19821 +#define VX_LIMIT_TOP   \
19822 +       "Limit\t current\t     min/max\t\t    soft/hard\t\thits\n"
19823 +
19824 +#define VX_LIMIT_ARG(r)                                \
19825 +       (unsigned long)__rlim_get(limit, r),    \
19826 +       (unsigned long)__rlim_rmin(limit, r),   \
19827 +       (unsigned long)__rlim_rmax(limit, r),   \
19828 +       VX_VLIM(__rlim_soft(limit, r)),         \
19829 +       VX_VLIM(__rlim_hard(limit, r)),         \
19830 +       atomic_read(&__rlim_lhit(limit, r))
19831 +
19832 +static inline int vx_info_proc_limit(struct _vx_limit *limit, char *buffer)
19833 +{
19834 +       vx_limit_fixup(limit, -1);
19835 +       return sprintf(buffer, VX_LIMIT_TOP
19836 +               "PROC"  VX_LIMIT_FMT
19837 +               "VM"    VX_LIMIT_FMT
19838 +               "VML"   VX_LIMIT_FMT
19839 +               "RSS"   VX_LIMIT_FMT
19840 +               "ANON"  VX_LIMIT_FMT
19841 +               "RMAP"  VX_LIMIT_FMT
19842 +               "FILES" VX_LIMIT_FMT
19843 +               "OFD"   VX_LIMIT_FMT
19844 +               "LOCKS" VX_LIMIT_FMT
19845 +               "SOCK"  VX_LIMIT_FMT
19846 +               "MSGQ"  VX_LIMIT_FMT
19847 +               "SHM"   VX_LIMIT_FMT
19848 +               "SEMA"  VX_LIMIT_FMT
19849 +               "SEMS"  VX_LIMIT_FMT
19850 +               "DENT"  VX_LIMIT_FMT,
19851 +               VX_LIMIT_ARG(RLIMIT_NPROC),
19852 +               VX_LIMIT_ARG(RLIMIT_AS),
19853 +               VX_LIMIT_ARG(RLIMIT_MEMLOCK),
19854 +               VX_LIMIT_ARG(RLIMIT_RSS),
19855 +               VX_LIMIT_ARG(VLIMIT_ANON),
19856 +               VX_LIMIT_ARG(VLIMIT_MAPPED),
19857 +               VX_LIMIT_ARG(RLIMIT_NOFILE),
19858 +               VX_LIMIT_ARG(VLIMIT_OPENFD),
19859 +               VX_LIMIT_ARG(RLIMIT_LOCKS),
19860 +               VX_LIMIT_ARG(VLIMIT_NSOCK),
19861 +               VX_LIMIT_ARG(RLIMIT_MSGQUEUE),
19862 +               VX_LIMIT_ARG(VLIMIT_SHMEM),
19863 +               VX_LIMIT_ARG(VLIMIT_SEMARY),
19864 +               VX_LIMIT_ARG(VLIMIT_NSEMS),
19865 +               VX_LIMIT_ARG(VLIMIT_DENTRY));
19866 +}
19867 +
19868 +#endif /* _VX_LIMIT_PROC_H */
19869 +
19870 +
19871 diff -NurpP --minimal linux-3.9.4/kernel/vserver/network.c linux-3.9.4-vs2.3.6.2/kernel/vserver/network.c
19872 --- linux-3.9.4/kernel/vserver/network.c        1970-01-01 00:00:00.000000000 +0000
19873 +++ linux-3.9.4-vs2.3.6.2/kernel/vserver/network.c      2013-05-31 14:47:11.000000000 +0000
19874 @@ -0,0 +1,1053 @@
19875 +/*
19876 + *  linux/kernel/vserver/network.c
19877 + *
19878 + *  Virtual Server: Network Support
19879 + *
19880 + *  Copyright (C) 2003-2007  Herbert Pötzl
19881 + *
19882 + *  V0.01  broken out from vcontext V0.05
19883 + *  V0.02  cleaned up implementation
19884 + *  V0.03  added equiv nx commands
19885 + *  V0.04  switch to RCU based hash
19886 + *  V0.05  and back to locking again
19887 + *  V0.06  changed vcmds to nxi arg
19888 + *  V0.07  have __create claim() the nxi
19889 + *
19890 + */
19891 +
19892 +#include <linux/err.h>
19893 +#include <linux/slab.h>
19894 +#include <linux/rcupdate.h>
19895 +#include <net/ipv6.h>
19896 +
19897 +#include <linux/vs_network.h>
19898 +#include <linux/vs_pid.h>
19899 +#include <linux/vserver/network_cmd.h>
19900 +
19901 +
19902 +atomic_t nx_global_ctotal      = ATOMIC_INIT(0);
19903 +atomic_t nx_global_cactive     = ATOMIC_INIT(0);
19904 +
19905 +static struct kmem_cache *nx_addr_v4_cachep = NULL;
19906 +static struct kmem_cache *nx_addr_v6_cachep = NULL;
19907 +
19908 +
19909 +static int __init init_network(void)
19910 +{
19911 +       nx_addr_v4_cachep = kmem_cache_create("nx_v4_addr_cache",
19912 +               sizeof(struct nx_addr_v4), 0,
19913 +               SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
19914 +       nx_addr_v6_cachep = kmem_cache_create("nx_v6_addr_cache",
19915 +               sizeof(struct nx_addr_v6), 0,
19916 +               SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
19917 +       return 0;
19918 +}
19919 +
19920 +
19921 +/*     __alloc_nx_addr_v4()                                    */
19922 +
19923 +static inline struct nx_addr_v4 *__alloc_nx_addr_v4(void)
19924 +{
19925 +       struct nx_addr_v4 *nxa = kmem_cache_alloc(
19926 +               nx_addr_v4_cachep, GFP_KERNEL);
19927 +
19928 +       if (!IS_ERR(nxa))
19929 +               memset(nxa, 0, sizeof(*nxa));
19930 +       return nxa;
19931 +}
19932 +
19933 +/*     __dealloc_nx_addr_v4()                                  */
19934 +
19935 +static inline void __dealloc_nx_addr_v4(struct nx_addr_v4 *nxa)
19936 +{
19937 +       kmem_cache_free(nx_addr_v4_cachep, nxa);
19938 +}
19939 +
19940 +/*     __dealloc_nx_addr_v4_all()                              */
19941 +
19942 +static inline void __dealloc_nx_addr_v4_all(struct nx_addr_v4 *nxa)
19943 +{
19944 +       while (nxa) {
19945 +               struct nx_addr_v4 *next = nxa->next;
19946 +
19947 +               __dealloc_nx_addr_v4(nxa);
19948 +               nxa = next;
19949 +       }
19950 +}
19951 +
19952 +
19953 +#ifdef CONFIG_IPV6
19954 +
19955 +/*     __alloc_nx_addr_v6()                                    */
19956 +
19957 +static inline struct nx_addr_v6 *__alloc_nx_addr_v6(void)
19958 +{
19959 +       struct nx_addr_v6 *nxa = kmem_cache_alloc(
19960 +               nx_addr_v6_cachep, GFP_KERNEL);
19961 +
19962 +       if (!IS_ERR(nxa))
19963 +               memset(nxa, 0, sizeof(*nxa));
19964 +       return nxa;
19965 +}
19966 +
19967 +/*     __dealloc_nx_addr_v6()                                  */
19968 +
19969 +static inline void __dealloc_nx_addr_v6(struct nx_addr_v6 *nxa)
19970 +{
19971 +       kmem_cache_free(nx_addr_v6_cachep, nxa);
19972 +}
19973 +
19974 +/*     __dealloc_nx_addr_v6_all()                              */
19975 +
19976 +static inline void __dealloc_nx_addr_v6_all(struct nx_addr_v6 *nxa)
19977 +{
19978 +       while (nxa) {
19979 +               struct nx_addr_v6 *next = nxa->next;
19980 +
19981 +               __dealloc_nx_addr_v6(nxa);
19982 +               nxa = next;
19983 +       }
19984 +}
19985 +
19986 +#endif /* CONFIG_IPV6 */
19987 +
19988 +/*     __alloc_nx_info()
19989 +
19990 +       * allocate an initialized nx_info struct
19991 +       * doesn't make it visible (hash)                        */
19992 +
19993 +static struct nx_info *__alloc_nx_info(nid_t nid)
19994 +{
19995 +       struct nx_info *new = NULL;
19996 +
19997 +       vxdprintk(VXD_CBIT(nid, 1), "alloc_nx_info(%d)*", nid);
19998 +
19999 +       /* would this benefit from a slab cache? */
20000 +       new = kmalloc(sizeof(struct nx_info), GFP_KERNEL);
20001 +       if (!new)
20002 +               return 0;
20003 +
20004 +       memset(new, 0, sizeof(struct nx_info));
20005 +       new->nx_id = nid;
20006 +       INIT_HLIST_NODE(&new->nx_hlist);
20007 +       atomic_set(&new->nx_usecnt, 0);
20008 +       atomic_set(&new->nx_tasks, 0);
20009 +       spin_lock_init(&new->addr_lock);
20010 +       new->nx_state = 0;
20011 +
20012 +       new->nx_flags = NXF_INIT_SET;
20013 +
20014 +       /* rest of init goes here */
20015 +
20016 +       new->v4_lback.s_addr = htonl(INADDR_LOOPBACK);
20017 +       new->v4_bcast.s_addr = htonl(INADDR_BROADCAST);
20018 +
20019 +       vxdprintk(VXD_CBIT(nid, 0),
20020 +               "alloc_nx_info(%d) = %p", nid, new);
20021 +       atomic_inc(&nx_global_ctotal);
20022 +       return new;
20023 +}
20024 +
20025 +/*     __dealloc_nx_info()
20026 +
20027 +       * final disposal of nx_info                             */
20028 +
20029 +static void __dealloc_nx_info(struct nx_info *nxi)
20030 +{
20031 +       vxdprintk(VXD_CBIT(nid, 0),
20032 +               "dealloc_nx_info(%p)", nxi);
20033 +
20034 +       nxi->nx_hlist.next = LIST_POISON1;
20035 +       nxi->nx_id = -1;
20036 +
20037 +       BUG_ON(atomic_read(&nxi->nx_usecnt));
20038 +       BUG_ON(atomic_read(&nxi->nx_tasks));
20039 +
20040 +       __dealloc_nx_addr_v4_all(nxi->v4.next);
20041 +#ifdef CONFIG_IPV6
20042 +       __dealloc_nx_addr_v6_all(nxi->v6.next);
20043 +#endif
20044 +
20045 +       nxi->nx_state |= NXS_RELEASED;
20046 +       kfree(nxi);
20047 +       atomic_dec(&nx_global_ctotal);
20048 +}
20049 +
20050 +static void __shutdown_nx_info(struct nx_info *nxi)
20051 +{
20052 +       nxi->nx_state |= NXS_SHUTDOWN;
20053 +       vs_net_change(nxi, VSC_NETDOWN);
20054 +}
20055 +
20056 +/*     exported stuff                                          */
20057 +
20058 +void free_nx_info(struct nx_info *nxi)
20059 +{
20060 +       /* context shutdown is mandatory */
20061 +       BUG_ON(nxi->nx_state != NXS_SHUTDOWN);
20062 +
20063 +       /* context must not be hashed */
20064 +       BUG_ON(nxi->nx_state & NXS_HASHED);
20065 +
20066 +       BUG_ON(atomic_read(&nxi->nx_usecnt));
20067 +       BUG_ON(atomic_read(&nxi->nx_tasks));
20068 +
20069 +       __dealloc_nx_info(nxi);
20070 +}
20071 +
20072 +
20073 +void __nx_set_lback(struct nx_info *nxi)
20074 +{
20075 +       int nid = nxi->nx_id;
20076 +       __be32 lback = htonl(INADDR_LOOPBACK ^ ((nid & 0xFFFF) << 8));
20077 +
20078 +       nxi->v4_lback.s_addr = lback;
20079 +}
20080 +
20081 +extern int __nx_inet_add_lback(__be32 addr);
20082 +extern int __nx_inet_del_lback(__be32 addr);
20083 +
20084 +
20085 +/*     hash table for nx_info hash */
20086 +
20087 +#define NX_HASH_SIZE   13
20088 +
20089 +struct hlist_head nx_info_hash[NX_HASH_SIZE];
20090 +
20091 +static DEFINE_SPINLOCK(nx_info_hash_lock);
20092 +
20093 +
20094 +static inline unsigned int __hashval(nid_t nid)
20095 +{
20096 +       return (nid % NX_HASH_SIZE);
20097 +}
20098 +
20099 +
20100 +
20101 +/*     __hash_nx_info()
20102 +
20103 +       * add the nxi to the global hash table
20104 +       * requires the hash_lock to be held                     */
20105 +
20106 +static inline void __hash_nx_info(struct nx_info *nxi)
20107 +{
20108 +       struct hlist_head *head;
20109 +
20110 +       vxd_assert_lock(&nx_info_hash_lock);
20111 +       vxdprintk(VXD_CBIT(nid, 4),
20112 +               "__hash_nx_info: %p[#%d]", nxi, nxi->nx_id);
20113 +
20114 +       /* context must not be hashed */
20115 +       BUG_ON(nx_info_state(nxi, NXS_HASHED));
20116 +
20117 +       nxi->nx_state |= NXS_HASHED;
20118 +       head = &nx_info_hash[__hashval(nxi->nx_id)];
20119 +       hlist_add_head(&nxi->nx_hlist, head);
20120 +       atomic_inc(&nx_global_cactive);
20121 +}
20122 +
20123 +/*     __unhash_nx_info()
20124 +
20125 +       * remove the nxi from the global hash table
20126 +       * requires the hash_lock to be held                     */
20127 +
20128 +static inline void __unhash_nx_info(struct nx_info *nxi)
20129 +{
20130 +       vxd_assert_lock(&nx_info_hash_lock);
20131 +       vxdprintk(VXD_CBIT(nid, 4),
20132 +               "__unhash_nx_info: %p[#%d.%d.%d]", nxi, nxi->nx_id,
20133 +               atomic_read(&nxi->nx_usecnt), atomic_read(&nxi->nx_tasks));
20134 +
20135 +       /* context must be hashed */
20136 +       BUG_ON(!nx_info_state(nxi, NXS_HASHED));
20137 +       /* but without tasks */
20138 +       BUG_ON(atomic_read(&nxi->nx_tasks));
20139 +
20140 +       nxi->nx_state &= ~NXS_HASHED;
20141 +       hlist_del(&nxi->nx_hlist);
20142 +       atomic_dec(&nx_global_cactive);
20143 +}
20144 +
20145 +
20146 +/*     __lookup_nx_info()
20147 +
20148 +       * requires the hash_lock to be held
20149 +       * doesn't increment the nx_refcnt                       */
20150 +
20151 +static inline struct nx_info *__lookup_nx_info(nid_t nid)
20152 +{
20153 +       struct hlist_head *head = &nx_info_hash[__hashval(nid)];
20154 +       struct hlist_node *pos;
20155 +       struct nx_info *nxi;
20156 +
20157 +       vxd_assert_lock(&nx_info_hash_lock);
20158 +       hlist_for_each(pos, head) {
20159 +               nxi = hlist_entry(pos, struct nx_info, nx_hlist);
20160 +
20161 +               if (nxi->nx_id == nid)
20162 +                       goto found;
20163 +       }
20164 +       nxi = NULL;
20165 +found:
20166 +       vxdprintk(VXD_CBIT(nid, 0),
20167 +               "__lookup_nx_info(#%u): %p[#%u]",
20168 +               nid, nxi, nxi ? nxi->nx_id : 0);
20169 +       return nxi;
20170 +}
20171 +
20172 +
20173 +/*     __create_nx_info()
20174 +
20175 +       * create the requested context
20176 +       * get(), claim() and hash it                            */
20177 +
20178 +static struct nx_info *__create_nx_info(int id)
20179 +{
20180 +       struct nx_info *new, *nxi = NULL;
20181 +
20182 +       vxdprintk(VXD_CBIT(nid, 1), "create_nx_info(%d)*", id);
20183 +
20184 +       if (!(new = __alloc_nx_info(id)))
20185 +               return ERR_PTR(-ENOMEM);
20186 +
20187 +       /* required to make dynamic xids unique */
20188 +       spin_lock(&nx_info_hash_lock);
20189 +
20190 +       /* static context requested */
20191 +       if ((nxi = __lookup_nx_info(id))) {
20192 +               vxdprintk(VXD_CBIT(nid, 0),
20193 +                       "create_nx_info(%d) = %p (already there)", id, nxi);
20194 +               if (nx_info_flags(nxi, NXF_STATE_SETUP, 0))
20195 +                       nxi = ERR_PTR(-EBUSY);
20196 +               else
20197 +                       nxi = ERR_PTR(-EEXIST);
20198 +               goto out_unlock;
20199 +       }
20200 +       /* new context */
20201 +       vxdprintk(VXD_CBIT(nid, 0),
20202 +               "create_nx_info(%d) = %p (new)", id, new);
20203 +       claim_nx_info(new, NULL);
20204 +       __nx_set_lback(new);
20205 +       __hash_nx_info(get_nx_info(new));
20206 +       nxi = new, new = NULL;
20207 +
20208 +out_unlock:
20209 +       spin_unlock(&nx_info_hash_lock);
20210 +       if (new)
20211 +               __dealloc_nx_info(new);
20212 +       return nxi;
20213 +}
20214 +
20215 +
20216 +
20217 +/*     exported stuff                                          */
20218 +
20219 +
20220 +void unhash_nx_info(struct nx_info *nxi)
20221 +{
20222 +       __shutdown_nx_info(nxi);
20223 +       spin_lock(&nx_info_hash_lock);
20224 +       __unhash_nx_info(nxi);
20225 +       spin_unlock(&nx_info_hash_lock);
20226 +}
20227 +
20228 +/*     lookup_nx_info()
20229 +
20230 +       * search for a nx_info and get() it
20231 +       * negative id means current                             */
20232 +
20233 +struct nx_info *lookup_nx_info(int id)
20234 +{
20235 +       struct nx_info *nxi = NULL;
20236 +
20237 +       if (id < 0) {
20238 +               nxi = get_nx_info(current_nx_info());
20239 +       } else if (id > 1) {
20240 +               spin_lock(&nx_info_hash_lock);
20241 +               nxi = get_nx_info(__lookup_nx_info(id));
20242 +               spin_unlock(&nx_info_hash_lock);
20243 +       }
20244 +       return nxi;
20245 +}
20246 +
20247 +/*     nid_is_hashed()
20248 +
20249 +       * verify that nid is still hashed                       */
20250 +
20251 +int nid_is_hashed(nid_t nid)
20252 +{
20253 +       int hashed;
20254 +
20255 +       spin_lock(&nx_info_hash_lock);
20256 +       hashed = (__lookup_nx_info(nid) != NULL);
20257 +       spin_unlock(&nx_info_hash_lock);
20258 +       return hashed;
20259 +}
20260 +
20261 +
20262 +#ifdef CONFIG_PROC_FS
20263 +
20264 +/*     get_nid_list()
20265 +
20266 +       * get a subset of hashed nids for proc
20267 +       * assumes size is at least one                          */
20268 +
20269 +int get_nid_list(int index, unsigned int *nids, int size)
20270 +{
20271 +       int hindex, nr_nids = 0;
20272 +
20273 +       /* only show current and children */
20274 +       if (!nx_check(0, VS_ADMIN | VS_WATCH)) {
20275 +               if (index > 0)
20276 +                       return 0;
20277 +               nids[nr_nids] = nx_current_nid();
20278 +               return 1;
20279 +       }
20280 +
20281 +       for (hindex = 0; hindex < NX_HASH_SIZE; hindex++) {
20282 +               struct hlist_head *head = &nx_info_hash[hindex];
20283 +               struct hlist_node *pos;
20284 +
20285 +               spin_lock(&nx_info_hash_lock);
20286 +               hlist_for_each(pos, head) {
20287 +                       struct nx_info *nxi;
20288 +
20289 +                       if (--index > 0)
20290 +                               continue;
20291 +
20292 +                       nxi = hlist_entry(pos, struct nx_info, nx_hlist);
20293 +                       nids[nr_nids] = nxi->nx_id;
20294 +                       if (++nr_nids >= size) {
20295 +                               spin_unlock(&nx_info_hash_lock);
20296 +                               goto out;
20297 +                       }
20298 +               }
20299 +               /* keep the lock time short */
20300 +               spin_unlock(&nx_info_hash_lock);
20301 +       }
20302 +out:
20303 +       return nr_nids;
20304 +}
20305 +#endif
20306 +
20307 +
20308 +/*
20309 + *     migrate task to new network
20310 + *     gets nxi, puts old_nxi on change
20311 + */
20312 +
20313 +int nx_migrate_task(struct task_struct *p, struct nx_info *nxi)
20314 +{
20315 +       struct nx_info *old_nxi;
20316 +       int ret = 0;
20317 +
20318 +       if (!p || !nxi)
20319 +               BUG();
20320 +
20321 +       vxdprintk(VXD_CBIT(nid, 5),
20322 +               "nx_migrate_task(%p,%p[#%d.%d.%d])",
20323 +               p, nxi, nxi->nx_id,
20324 +               atomic_read(&nxi->nx_usecnt),
20325 +               atomic_read(&nxi->nx_tasks));
20326 +
20327 +       if (nx_info_flags(nxi, NXF_INFO_PRIVATE, 0) &&
20328 +               !nx_info_flags(nxi, NXF_STATE_SETUP, 0))
20329 +               return -EACCES;
20330 +
20331 +       if (nx_info_state(nxi, NXS_SHUTDOWN))
20332 +               return -EFAULT;
20333 +
20334 +       /* maybe disallow this completely? */
20335 +       old_nxi = task_get_nx_info(p);
20336 +       if (old_nxi == nxi)
20337 +               goto out;
20338 +
20339 +       task_lock(p);
20340 +       if (old_nxi)
20341 +               clr_nx_info(&p->nx_info);
20342 +       claim_nx_info(nxi, p);
20343 +       set_nx_info(&p->nx_info, nxi);
20344 +       p->nid = nxi->nx_id;
20345 +       task_unlock(p);
20346 +
20347 +       vxdprintk(VXD_CBIT(nid, 5),
20348 +               "moved task %p into nxi:%p[#%d]",
20349 +               p, nxi, nxi->nx_id);
20350 +
20351 +       if (old_nxi)
20352 +               release_nx_info(old_nxi, p);
20353 +       ret = 0;
20354 +out:
20355 +       put_nx_info(old_nxi);
20356 +       return ret;
20357 +}
20358 +
20359 +
20360 +void nx_set_persistent(struct nx_info *nxi)
20361 +{
20362 +       vxdprintk(VXD_CBIT(nid, 6),
20363 +               "nx_set_persistent(%p[#%d])", nxi, nxi->nx_id);
20364 +
20365 +       get_nx_info(nxi);
20366 +       claim_nx_info(nxi, NULL);
20367 +}
20368 +
20369 +void nx_clear_persistent(struct nx_info *nxi)
20370 +{
20371 +       vxdprintk(VXD_CBIT(nid, 6),
20372 +               "nx_clear_persistent(%p[#%d])", nxi, nxi->nx_id);
20373 +
20374 +       release_nx_info(nxi, NULL);
20375 +       put_nx_info(nxi);
20376 +}
20377 +
20378 +void nx_update_persistent(struct nx_info *nxi)
20379 +{
20380 +       if (nx_info_flags(nxi, NXF_PERSISTENT, 0))
20381 +               nx_set_persistent(nxi);
20382 +       else
20383 +               nx_clear_persistent(nxi);
20384 +}
20385 +
20386 +/* vserver syscall commands below here */
20387 +
20388 +/* taks nid and nx_info functions */
20389 +
20390 +#include <asm/uaccess.h>
20391 +
20392 +
20393 +int vc_task_nid(uint32_t id)
20394 +{
20395 +       nid_t nid;
20396 +
20397 +       if (id) {
20398 +               struct task_struct *tsk;
20399 +
20400 +               rcu_read_lock();
20401 +               tsk = find_task_by_real_pid(id);
20402 +               nid = (tsk) ? tsk->nid : -ESRCH;
20403 +               rcu_read_unlock();
20404 +       } else
20405 +               nid = nx_current_nid();
20406 +       return nid;
20407 +}
20408 +
20409 +
20410 +int vc_nx_info(struct nx_info *nxi, void __user *data)
20411 +{
20412 +       struct vcmd_nx_info_v0 vc_data;
20413 +
20414 +       vc_data.nid = nxi->nx_id;
20415 +
20416 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20417 +               return -EFAULT;
20418 +       return 0;
20419 +}
20420 +
20421 +
20422 +/* network functions */
20423 +
20424 +int vc_net_create(uint32_t nid, void __user *data)
20425 +{
20426 +       struct vcmd_net_create vc_data = { .flagword = NXF_INIT_SET };
20427 +       struct nx_info *new_nxi;
20428 +       int ret;
20429 +
20430 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20431 +               return -EFAULT;
20432 +
20433 +       if ((nid > MAX_S_CONTEXT) || (nid < 2))
20434 +               return -EINVAL;
20435 +
20436 +       new_nxi = __create_nx_info(nid);
20437 +       if (IS_ERR(new_nxi))
20438 +               return PTR_ERR(new_nxi);
20439 +
20440 +       /* initial flags */
20441 +       new_nxi->nx_flags = vc_data.flagword;
20442 +
20443 +       ret = -ENOEXEC;
20444 +       if (vs_net_change(new_nxi, VSC_NETUP))
20445 +               goto out;
20446 +
20447 +       ret = nx_migrate_task(current, new_nxi);
20448 +       if (ret)
20449 +               goto out;
20450 +
20451 +       /* return context id on success */
20452 +       ret = new_nxi->nx_id;
20453 +
20454 +       /* get a reference for persistent contexts */
20455 +       if ((vc_data.flagword & NXF_PERSISTENT))
20456 +               nx_set_persistent(new_nxi);
20457 +out:
20458 +       release_nx_info(new_nxi, NULL);
20459 +       put_nx_info(new_nxi);
20460 +       return ret;
20461 +}
20462 +
20463 +
20464 +int vc_net_migrate(struct nx_info *nxi, void __user *data)
20465 +{
20466 +       return nx_migrate_task(current, nxi);
20467 +}
20468 +
20469 +
20470 +static inline
20471 +struct nx_addr_v4 *__find_v4_addr(struct nx_info *nxi,
20472 +       __be32 ip, __be32 ip2, __be32 mask, uint16_t type, uint16_t flags,
20473 +       struct nx_addr_v4 **prev)
20474 +{
20475 +       struct nx_addr_v4 *nxa = &nxi->v4;
20476 +
20477 +       for (; nxa; nxa = nxa->next) {
20478 +               if ((nxa->ip[0].s_addr == ip) &&
20479 +                   (nxa->ip[1].s_addr == ip2) &&
20480 +                   (nxa->mask.s_addr == mask) &&
20481 +                   (nxa->type == type) &&
20482 +                   (nxa->flags == flags))
20483 +                   return nxa;
20484 +
20485 +               /* save previous entry */
20486 +               if (prev)
20487 +                       *prev = nxa;
20488 +       }
20489 +       return NULL;
20490 +}
20491 +
20492 +int do_add_v4_addr(struct nx_info *nxi, __be32 ip, __be32 ip2, __be32 mask,
20493 +       uint16_t type, uint16_t flags)
20494 +{
20495 +       struct nx_addr_v4 *nxa = NULL;
20496 +       struct nx_addr_v4 *new = __alloc_nx_addr_v4();
20497 +       unsigned long irqflags;
20498 +       int ret = -EEXIST;
20499 +
20500 +       if (IS_ERR(new))
20501 +               return PTR_ERR(new);
20502 +
20503 +       spin_lock_irqsave(&nxi->addr_lock, irqflags);
20504 +       if (__find_v4_addr(nxi, ip, ip2, mask, type, flags, &nxa))
20505 +               goto out_unlock;
20506 +
20507 +       if (NX_IPV4(nxi)) {
20508 +               nxa->next = new;
20509 +               nxa = new;
20510 +               new = NULL;
20511 +
20512 +               /* remove single ip for ip list */
20513 +               nxi->nx_flags &= ~NXF_SINGLE_IP;
20514 +       }
20515 +
20516 +       nxa->ip[0].s_addr = ip;
20517 +       nxa->ip[1].s_addr = ip2;
20518 +       nxa->mask.s_addr = mask;
20519 +       nxa->type = type;
20520 +       nxa->flags = flags;
20521 +       ret = 0;
20522 +out_unlock:
20523 +       spin_unlock_irqrestore(&nxi->addr_lock, irqflags);
20524 +       if (new)
20525 +               __dealloc_nx_addr_v4(new);
20526 +       return ret;
20527 +}
20528 +
20529 +int do_remove_v4_addr(struct nx_info *nxi, __be32 ip, __be32 ip2, __be32 mask,
20530 +       uint16_t type, uint16_t flags)
20531 +{
20532 +       struct nx_addr_v4 *nxa = NULL;
20533 +       struct nx_addr_v4 *old = NULL;
20534 +       unsigned long irqflags;
20535 +       int ret = 0;
20536 +
20537 +       spin_lock_irqsave(&nxi->addr_lock, irqflags);
20538 +       switch (type) {
20539 +       case NXA_TYPE_ADDR:
20540 +               old = __find_v4_addr(nxi, ip, ip2, mask, type, flags, &nxa);
20541 +               if (old) {
20542 +                       if (nxa) {
20543 +                               nxa->next = old->next;
20544 +                               old->next = NULL;
20545 +                       } else {
20546 +                               if (old->next) {
20547 +                                       nxa = old;
20548 +                                       old = old->next;
20549 +                                       *nxa = *old;
20550 +                                       old->next = NULL;
20551 +                               } else {
20552 +                                       memset(old, 0, sizeof(*old));
20553 +                                       old = NULL;
20554 +                               }
20555 +                       }
20556 +               } else
20557 +                       ret = -ESRCH;
20558 +               break;
20559 +
20560 +       case NXA_TYPE_ANY:
20561 +               nxa = &nxi->v4;
20562 +               old = nxa->next;
20563 +               memset(nxa, 0, sizeof(*nxa));
20564 +               break;
20565 +
20566 +       default:
20567 +               ret = -EINVAL;
20568 +       }
20569 +       spin_unlock_irqrestore(&nxi->addr_lock, irqflags);
20570 +       __dealloc_nx_addr_v4_all(old);
20571 +       return ret;
20572 +}
20573 +
20574 +
20575 +int vc_net_add(struct nx_info *nxi, void __user *data)
20576 +{
20577 +       struct vcmd_net_addr_v0 vc_data;
20578 +       int index, ret = 0;
20579 +
20580 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20581 +               return -EFAULT;
20582 +
20583 +       switch (vc_data.type) {
20584 +       case NXA_TYPE_IPV4:
20585 +               if ((vc_data.count < 1) || (vc_data.count > 4))
20586 +                       return -EINVAL;
20587 +
20588 +               index = 0;
20589 +               while (index < vc_data.count) {
20590 +                       ret = do_add_v4_addr(nxi, vc_data.ip[index].s_addr, 0,
20591 +                               vc_data.mask[index].s_addr, NXA_TYPE_ADDR, 0);
20592 +                       if (ret)
20593 +                               return ret;
20594 +                       index++;
20595 +               }
20596 +               ret = index;
20597 +               break;
20598 +
20599 +       case NXA_TYPE_IPV4|NXA_MOD_BCAST:
20600 +               nxi->v4_bcast = vc_data.ip[0];
20601 +               ret = 1;
20602 +               break;
20603 +
20604 +       case NXA_TYPE_IPV4|NXA_MOD_LBACK:
20605 +               nxi->v4_lback = vc_data.ip[0];
20606 +               ret = 1;
20607 +               break;
20608 +
20609 +       default:
20610 +               ret = -EINVAL;
20611 +               break;
20612 +       }
20613 +       return ret;
20614 +}
20615 +
20616 +int vc_net_remove(struct nx_info *nxi, void __user *data)
20617 +{
20618 +       struct vcmd_net_addr_v0 vc_data;
20619 +
20620 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20621 +               return -EFAULT;
20622 +
20623 +       switch (vc_data.type) {
20624 +       case NXA_TYPE_ANY:
20625 +               return do_remove_v4_addr(nxi, 0, 0, 0, vc_data.type, 0);
20626 +       default:
20627 +               return -EINVAL;
20628 +       }
20629 +       return 0;
20630 +}
20631 +
20632 +
20633 +int vc_net_add_ipv4_v1(struct nx_info *nxi, void __user *data)
20634 +{
20635 +       struct vcmd_net_addr_ipv4_v1 vc_data;
20636 +
20637 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20638 +               return -EFAULT;
20639 +
20640 +       switch (vc_data.type) {
20641 +       case NXA_TYPE_ADDR:
20642 +       case NXA_TYPE_MASK:
20643 +               return do_add_v4_addr(nxi, vc_data.ip.s_addr, 0,
20644 +                       vc_data.mask.s_addr, vc_data.type, vc_data.flags);
20645 +
20646 +       case NXA_TYPE_ADDR | NXA_MOD_BCAST:
20647 +               nxi->v4_bcast = vc_data.ip;
20648 +               break;
20649 +
20650 +       case NXA_TYPE_ADDR | NXA_MOD_LBACK:
20651 +               nxi->v4_lback = vc_data.ip;
20652 +               break;
20653 +
20654 +       default:
20655 +               return -EINVAL;
20656 +       }
20657 +       return 0;
20658 +}
20659 +
20660 +int vc_net_add_ipv4(struct nx_info *nxi, void __user *data)
20661 +{
20662 +       struct vcmd_net_addr_ipv4_v2 vc_data;
20663 +
20664 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20665 +               return -EFAULT;
20666 +
20667 +       switch (vc_data.type) {
20668 +       case NXA_TYPE_ADDR:
20669 +       case NXA_TYPE_MASK:
20670 +       case NXA_TYPE_RANGE:
20671 +               return do_add_v4_addr(nxi, vc_data.ip.s_addr, vc_data.ip2.s_addr,
20672 +                       vc_data.mask.s_addr, vc_data.type, vc_data.flags);
20673 +
20674 +       case NXA_TYPE_ADDR | NXA_MOD_BCAST:
20675 +               nxi->v4_bcast = vc_data.ip;
20676 +               break;
20677 +
20678 +       case NXA_TYPE_ADDR | NXA_MOD_LBACK:
20679 +               nxi->v4_lback = vc_data.ip;
20680 +               break;
20681 +
20682 +       default:
20683 +               return -EINVAL;
20684 +       }
20685 +       return 0;
20686 +}
20687 +
20688 +int vc_net_rem_ipv4_v1(struct nx_info *nxi, void __user *data)
20689 +{
20690 +       struct vcmd_net_addr_ipv4_v1 vc_data;
20691 +
20692 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20693 +               return -EFAULT;
20694 +
20695 +       return do_remove_v4_addr(nxi, vc_data.ip.s_addr, 0,
20696 +               vc_data.mask.s_addr, vc_data.type, vc_data.flags);
20697 +}
20698 +
20699 +int vc_net_rem_ipv4(struct nx_info *nxi, void __user *data)
20700 +{
20701 +       struct vcmd_net_addr_ipv4_v2 vc_data;
20702 +
20703 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20704 +               return -EFAULT;
20705 +
20706 +       return do_remove_v4_addr(nxi, vc_data.ip.s_addr, vc_data.ip2.s_addr,
20707 +               vc_data.mask.s_addr, vc_data.type, vc_data.flags);
20708 +}
20709 +
20710 +#ifdef CONFIG_IPV6
20711 +
20712 +static inline
20713 +struct nx_addr_v6 *__find_v6_addr(struct nx_info *nxi,
20714 +       struct in6_addr *ip, struct in6_addr *mask,
20715 +       uint32_t prefix, uint16_t type, uint16_t flags,
20716 +       struct nx_addr_v6 **prev)
20717 +{
20718 +       struct nx_addr_v6 *nxa = &nxi->v6;
20719 +
20720 +       for (; nxa; nxa = nxa->next) {
20721 +               if (ipv6_addr_equal(&nxa->ip, ip) &&
20722 +                   ipv6_addr_equal(&nxa->mask, mask) &&
20723 +                   (nxa->prefix == prefix) &&
20724 +                   (nxa->type == type) &&
20725 +                   (nxa->flags == flags))
20726 +                   return nxa;
20727 +
20728 +               /* save previous entry */
20729 +               if (prev)
20730 +                       *prev = nxa;
20731 +       }
20732 +       return NULL;
20733 +}
20734 +
20735 +
20736 +int do_add_v6_addr(struct nx_info *nxi,
20737 +       struct in6_addr *ip, struct in6_addr *mask,
20738 +       uint32_t prefix, uint16_t type, uint16_t flags)
20739 +{
20740 +       struct nx_addr_v6 *nxa = NULL;
20741 +       struct nx_addr_v6 *new = __alloc_nx_addr_v6();
20742 +       unsigned long irqflags;
20743 +       int ret = -EEXIST;
20744 +
20745 +       if (IS_ERR(new))
20746 +               return PTR_ERR(new);
20747 +
20748 +       spin_lock_irqsave(&nxi->addr_lock, irqflags);
20749 +       if (__find_v6_addr(nxi, ip, mask, prefix, type, flags, &nxa))
20750 +               goto out_unlock;
20751 +
20752 +       if (NX_IPV6(nxi)) {
20753 +               nxa->next = new;
20754 +               nxa = new;
20755 +               new = NULL;
20756 +       }
20757 +
20758 +       nxa->ip = *ip;
20759 +       nxa->mask = *mask;
20760 +       nxa->prefix = prefix;
20761 +       nxa->type = type;
20762 +       nxa->flags = flags;
20763 +       ret = 0;
20764 +out_unlock:
20765 +       spin_unlock_irqrestore(&nxi->addr_lock, irqflags);
20766 +       if (new)
20767 +               __dealloc_nx_addr_v6(new);
20768 +       return ret;
20769 +}
20770 +
20771 +int do_remove_v6_addr(struct nx_info *nxi,
20772 +       struct in6_addr *ip, struct in6_addr *mask,
20773 +       uint32_t prefix, uint16_t type, uint16_t flags)
20774 +{
20775 +       struct nx_addr_v6 *nxa = NULL;
20776 +       struct nx_addr_v6 *old = NULL;
20777 +       unsigned long irqflags;
20778 +       int ret = 0;
20779 +
20780 +       spin_lock_irqsave(&nxi->addr_lock, irqflags);
20781 +       switch (type) {
20782 +       case NXA_TYPE_ADDR:
20783 +               old = __find_v6_addr(nxi, ip, mask, prefix, type, flags, &nxa);
20784 +               if (old) {
20785 +                       if (nxa) {
20786 +                               nxa->next = old->next;
20787 +                               old->next = NULL;
20788 +                       } else {
20789 +                               if (old->next) {
20790 +                                       nxa = old;
20791 +                                       old = old->next;
20792 +                                       *nxa = *old;
20793 +                                       old->next = NULL;
20794 +                               } else {
20795 +                                       memset(old, 0, sizeof(*old));
20796 +                                       old = NULL;
20797 +                               }
20798 +                       }
20799 +               } else
20800 +                       ret = -ESRCH;
20801 +               break;
20802 +
20803 +       case NXA_TYPE_ANY:
20804 +               nxa = &nxi->v6;
20805 +               old = nxa->next;
20806 +               memset(nxa, 0, sizeof(*nxa));
20807 +               break;
20808 +
20809 +       default:
20810 +               ret = -EINVAL;
20811 +       }
20812 +       spin_unlock_irqrestore(&nxi->addr_lock, irqflags);
20813 +       __dealloc_nx_addr_v6_all(old);
20814 +       return ret;
20815 +}
20816 +
20817 +int vc_net_add_ipv6(struct nx_info *nxi, void __user *data)
20818 +{
20819 +       struct vcmd_net_addr_ipv6_v1 vc_data;
20820 +
20821 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20822 +               return -EFAULT;
20823 +
20824 +       switch (vc_data.type) {
20825 +       case NXA_TYPE_ADDR:
20826 +               memset(&vc_data.mask, ~0, sizeof(vc_data.mask));
20827 +               /* fallthrough */
20828 +       case NXA_TYPE_MASK:
20829 +               return do_add_v6_addr(nxi, &vc_data.ip, &vc_data.mask,
20830 +                       vc_data.prefix, vc_data.type, vc_data.flags);
20831 +       default:
20832 +               return -EINVAL;
20833 +       }
20834 +       return 0;
20835 +}
20836 +
20837 +int vc_net_remove_ipv6(struct nx_info *nxi, void __user *data)
20838 +{
20839 +       struct vcmd_net_addr_ipv6_v1 vc_data;
20840 +
20841 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20842 +               return -EFAULT;
20843 +
20844 +       switch (vc_data.type) {
20845 +       case NXA_TYPE_ADDR:
20846 +               memset(&vc_data.mask, ~0, sizeof(vc_data.mask));
20847 +               /* fallthrough */
20848 +       case NXA_TYPE_MASK:
20849 +               return do_remove_v6_addr(nxi, &vc_data.ip, &vc_data.mask,
20850 +                       vc_data.prefix, vc_data.type, vc_data.flags);
20851 +       case NXA_TYPE_ANY:
20852 +               return do_remove_v6_addr(nxi, NULL, NULL, 0, vc_data.type, 0);
20853 +       default:
20854 +               return -EINVAL;
20855 +       }
20856 +       return 0;
20857 +}
20858 +
20859 +#endif /* CONFIG_IPV6 */
20860 +
20861 +
20862 +int vc_get_nflags(struct nx_info *nxi, void __user *data)
20863 +{
20864 +       struct vcmd_net_flags_v0 vc_data;
20865 +
20866 +       vc_data.flagword = nxi->nx_flags;
20867 +
20868 +       /* special STATE flag handling */
20869 +       vc_data.mask = vs_mask_flags(~0ULL, nxi->nx_flags, NXF_ONE_TIME);
20870 +
20871 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20872 +               return -EFAULT;
20873 +       return 0;
20874 +}
20875 +
20876 +int vc_set_nflags(struct nx_info *nxi, void __user *data)
20877 +{
20878 +       struct vcmd_net_flags_v0 vc_data;
20879 +       uint64_t mask, trigger;
20880 +
20881 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20882 +               return -EFAULT;
20883 +
20884 +       /* special STATE flag handling */
20885 +       mask = vs_mask_mask(vc_data.mask, nxi->nx_flags, NXF_ONE_TIME);
20886 +       trigger = (mask & nxi->nx_flags) ^ (mask & vc_data.flagword);
20887 +
20888 +       nxi->nx_flags = vs_mask_flags(nxi->nx_flags,
20889 +               vc_data.flagword, mask);
20890 +       if (trigger & NXF_PERSISTENT)
20891 +               nx_update_persistent(nxi);
20892 +
20893 +       return 0;
20894 +}
20895 +
20896 +int vc_get_ncaps(struct nx_info *nxi, void __user *data)
20897 +{
20898 +       struct vcmd_net_caps_v0 vc_data;
20899 +
20900 +       vc_data.ncaps = nxi->nx_ncaps;
20901 +       vc_data.cmask = ~0ULL;
20902 +
20903 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20904 +               return -EFAULT;
20905 +       return 0;
20906 +}
20907 +
20908 +int vc_set_ncaps(struct nx_info *nxi, void __user *data)
20909 +{
20910 +       struct vcmd_net_caps_v0 vc_data;
20911 +
20912 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20913 +               return -EFAULT;
20914 +
20915 +       nxi->nx_ncaps = vs_mask_flags(nxi->nx_ncaps,
20916 +               vc_data.ncaps, vc_data.cmask);
20917 +       return 0;
20918 +}
20919 +
20920 +
20921 +#include <linux/module.h>
20922 +
20923 +module_init(init_network);
20924 +
20925 +EXPORT_SYMBOL_GPL(free_nx_info);
20926 +EXPORT_SYMBOL_GPL(unhash_nx_info);
20927 +
20928 diff -NurpP --minimal linux-3.9.4/kernel/vserver/proc.c linux-3.9.4-vs2.3.6.2/kernel/vserver/proc.c
20929 --- linux-3.9.4/kernel/vserver/proc.c   1970-01-01 00:00:00.000000000 +0000
20930 +++ linux-3.9.4-vs2.3.6.2/kernel/vserver/proc.c 2013-06-01 08:30:38.000000000 +0000
20931 @@ -0,0 +1,1110 @@
20932 +/*
20933 + *  linux/kernel/vserver/proc.c
20934 + *
20935 + *  Virtual Context Support
20936 + *
20937 + *  Copyright (C) 2003-2011  Herbert Pötzl
20938 + *
20939 + *  V0.01  basic structure
20940 + *  V0.02  adaptation vs1.3.0
20941 + *  V0.03  proc permissions
20942 + *  V0.04  locking/generic
20943 + *  V0.05  next generation procfs
20944 + *  V0.06  inode validation
20945 + *  V0.07  generic rewrite vid
20946 + *  V0.08  remove inode type
20947 + *  V0.09  added u/wmask info
20948 + *
20949 + */
20950 +
20951 +#include <linux/proc_fs.h>
20952 +#include <linux/fs_struct.h>
20953 +#include <linux/mount.h>
20954 +#include <linux/namei.h>
20955 +#include <asm/unistd.h>
20956 +
20957 +#include <linux/vs_context.h>
20958 +#include <linux/vs_network.h>
20959 +#include <linux/vs_cvirt.h>
20960 +
20961 +#include <linux/in.h>
20962 +#include <linux/inetdevice.h>
20963 +#include <linux/vs_inet.h>
20964 +#include <linux/vs_inet6.h>
20965 +
20966 +#include <linux/vserver/global.h>
20967 +
20968 +#include "cvirt_proc.h"
20969 +#include "cacct_proc.h"
20970 +#include "limit_proc.h"
20971 +#include "sched_proc.h"
20972 +#include "vci_config.h"
20973 +
20974 +
20975 +static inline char *print_cap_t(char *buffer, kernel_cap_t *c)
20976 +{
20977 +       unsigned __capi;
20978 +
20979 +       CAP_FOR_EACH_U32(__capi) {
20980 +               buffer += sprintf(buffer, "%08x",
20981 +                       c->cap[(_KERNEL_CAPABILITY_U32S-1) - __capi]);
20982 +       }
20983 +       return buffer;
20984 +}
20985 +
20986 +
20987 +static struct proc_dir_entry *proc_virtual;
20988 +
20989 +static struct proc_dir_entry *proc_virtnet;
20990 +
20991 +
20992 +/* first the actual feeds */
20993 +
20994 +
20995 +static int proc_vci(char *buffer)
20996 +{
20997 +       return sprintf(buffer,
20998 +               "VCIVersion:\t%04x:%04x\n"
20999 +               "VCISyscall:\t%d\n"
21000 +               "VCIKernel:\t%08x\n",
21001 +               VCI_VERSION >> 16,
21002 +               VCI_VERSION & 0xFFFF,
21003 +               __NR_vserver,
21004 +               vci_kernel_config());
21005 +}
21006 +
21007 +static int proc_virtual_info(char *buffer)
21008 +{
21009 +       return proc_vci(buffer);
21010 +}
21011 +
21012 +static int proc_virtual_status(char *buffer)
21013 +{
21014 +       return sprintf(buffer,
21015 +               "#CTotal:\t%d\n"
21016 +               "#CActive:\t%d\n"
21017 +               "#NSProxy:\t%d\t%d %d %d %d %d %d\n"
21018 +               "#InitTask:\t%d\t%d %d\n",
21019 +               atomic_read(&vx_global_ctotal),
21020 +               atomic_read(&vx_global_cactive),
21021 +               atomic_read(&vs_global_nsproxy),
21022 +               atomic_read(&vs_global_fs),
21023 +               atomic_read(&vs_global_mnt_ns),
21024 +               atomic_read(&vs_global_uts_ns),
21025 +               atomic_read(&nr_ipc_ns),
21026 +               atomic_read(&vs_global_user_ns),
21027 +               atomic_read(&vs_global_pid_ns),
21028 +               atomic_read(&init_task.usage),
21029 +               atomic_read(&init_task.nsproxy->count),
21030 +               init_task.fs->users);
21031 +}
21032 +
21033 +
21034 +int proc_vxi_info(struct vx_info *vxi, char *buffer)
21035 +{
21036 +       int length;
21037 +
21038 +       length = sprintf(buffer,
21039 +               "ID:\t%d\n"
21040 +               "Info:\t%p\n"
21041 +               "Init:\t%d\n"
21042 +               "OOM:\t%lld\n",
21043 +               vxi->vx_id,
21044 +               vxi,
21045 +               vxi->vx_initpid,
21046 +               vxi->vx_badness_bias);
21047 +       return length;
21048 +}
21049 +
21050 +int proc_vxi_status(struct vx_info *vxi, char *buffer)
21051 +{
21052 +       char *orig = buffer;
21053 +
21054 +       buffer += sprintf(buffer,
21055 +               "UseCnt:\t%d\n"
21056 +               "Tasks:\t%d\n"
21057 +               "Flags:\t%016llx\n",
21058 +               atomic_read(&vxi->vx_usecnt),
21059 +               atomic_read(&vxi->vx_tasks),
21060 +               (unsigned long long)vxi->vx_flags);
21061 +
21062 +       buffer += sprintf(buffer, "BCaps:\t");
21063 +       buffer = print_cap_t(buffer, &vxi->vx_bcaps);
21064 +       buffer += sprintf(buffer, "\n");
21065 +
21066 +       buffer += sprintf(buffer,
21067 +               "CCaps:\t%016llx\n"
21068 +               "Umask:\t%16llx\n"
21069 +               "Wmask:\t%16llx\n"
21070 +               "Spaces:\t%08lx %08lx\n",
21071 +               (unsigned long long)vxi->vx_ccaps,
21072 +               (unsigned long long)vxi->vx_umask,
21073 +               (unsigned long long)vxi->vx_wmask,
21074 +               vxi->space[0].vx_nsmask, vxi->space[1].vx_nsmask);
21075 +       return buffer - orig;
21076 +}
21077 +
21078 +int proc_vxi_limit(struct vx_info *vxi, char *buffer)
21079 +{
21080 +       return vx_info_proc_limit(&vxi->limit, buffer);
21081 +}
21082 +
21083 +int proc_vxi_sched(struct vx_info *vxi, char *buffer)
21084 +{
21085 +       int cpu, length;
21086 +
21087 +       length = vx_info_proc_sched(&vxi->sched, buffer);
21088 +       for_each_online_cpu(cpu) {
21089 +               length += vx_info_proc_sched_pc(
21090 +                       &vx_per_cpu(vxi, sched_pc, cpu),
21091 +                       buffer + length, cpu);
21092 +       }
21093 +       return length;
21094 +}
21095 +
21096 +int proc_vxi_nsproxy0(struct vx_info *vxi, char *buffer)
21097 +{
21098 +       return vx_info_proc_nsproxy(vxi->space[0].vx_nsproxy, buffer);
21099 +}
21100 +
21101 +int proc_vxi_nsproxy1(struct vx_info *vxi, char *buffer)
21102 +{
21103 +       return vx_info_proc_nsproxy(vxi->space[1].vx_nsproxy, buffer);
21104 +}
21105 +
21106 +int proc_vxi_cvirt(struct vx_info *vxi, char *buffer)
21107 +{
21108 +       int cpu, length;
21109 +
21110 +       vx_update_load(vxi);
21111 +       length = vx_info_proc_cvirt(&vxi->cvirt, buffer);
21112 +       for_each_online_cpu(cpu) {
21113 +               length += vx_info_proc_cvirt_pc(
21114 +                       &vx_per_cpu(vxi, cvirt_pc, cpu),
21115 +                       buffer + length, cpu);
21116 +       }
21117 +       return length;
21118 +}
21119 +
21120 +int proc_vxi_cacct(struct vx_info *vxi, char *buffer)
21121 +{
21122 +       return vx_info_proc_cacct(&vxi->cacct, buffer);
21123 +}
21124 +
21125 +
21126 +static int proc_virtnet_info(char *buffer)
21127 +{
21128 +       return proc_vci(buffer);
21129 +}
21130 +
21131 +static int proc_virtnet_status(char *buffer)
21132 +{
21133 +       return sprintf(buffer,
21134 +               "#CTotal:\t%d\n"
21135 +               "#CActive:\t%d\n",
21136 +               atomic_read(&nx_global_ctotal),
21137 +               atomic_read(&nx_global_cactive));
21138 +}
21139 +
21140 +int proc_nxi_info(struct nx_info *nxi, char *buffer)
21141 +{
21142 +       struct nx_addr_v4 *v4a;
21143 +#ifdef CONFIG_IPV6
21144 +       struct nx_addr_v6 *v6a;
21145 +#endif
21146 +       int length, i;
21147 +
21148 +       length = sprintf(buffer,
21149 +               "ID:\t%d\n"
21150 +               "Info:\t%p\n"
21151 +               "Bcast:\t" NIPQUAD_FMT "\n"
21152 +               "Lback:\t" NIPQUAD_FMT "\n",
21153 +               nxi->nx_id,
21154 +               nxi,
21155 +               NIPQUAD(nxi->v4_bcast.s_addr),
21156 +               NIPQUAD(nxi->v4_lback.s_addr));
21157 +
21158 +       if (!NX_IPV4(nxi))
21159 +               goto skip_v4;
21160 +       for (i = 0, v4a = &nxi->v4; v4a; i++, v4a = v4a->next)
21161 +               length += sprintf(buffer + length, "%d:\t" NXAV4_FMT "\n",
21162 +                       i, NXAV4(v4a));
21163 +skip_v4:
21164 +#ifdef CONFIG_IPV6
21165 +       if (!NX_IPV6(nxi))
21166 +               goto skip_v6;
21167 +       for (i = 0, v6a = &nxi->v6; v6a; i++, v6a = v6a->next)
21168 +               length += sprintf(buffer + length, "%d:\t" NXAV6_FMT "\n",
21169 +                       i, NXAV6(v6a));
21170 +skip_v6:
21171 +#endif
21172 +       return length;
21173 +}
21174 +
21175 +int proc_nxi_status(struct nx_info *nxi, char *buffer)
21176 +{
21177 +       int length;
21178 +
21179 +       length = sprintf(buffer,
21180 +               "UseCnt:\t%d\n"
21181 +               "Tasks:\t%d\n"
21182 +               "Flags:\t%016llx\n"
21183 +               "NCaps:\t%016llx\n",
21184 +               atomic_read(&nxi->nx_usecnt),
21185 +               atomic_read(&nxi->nx_tasks),
21186 +               (unsigned long long)nxi->nx_flags,
21187 +               (unsigned long long)nxi->nx_ncaps);
21188 +       return length;
21189 +}
21190 +
21191 +
21192 +
21193 +/* here the inode helpers */
21194 +
21195 +struct vs_entry {
21196 +       int len;
21197 +       char *name;
21198 +       mode_t mode;
21199 +       struct inode_operations *iop;
21200 +       struct file_operations *fop;
21201 +       union proc_op op;
21202 +};
21203 +
21204 +static struct inode *vs_proc_make_inode(struct super_block *sb, struct vs_entry *p)
21205 +{
21206 +       struct inode *inode = new_inode(sb);
21207 +
21208 +       if (!inode)
21209 +               goto out;
21210 +
21211 +       inode->i_mode = p->mode;
21212 +       if (p->iop)
21213 +               inode->i_op = p->iop;
21214 +       if (p->fop)
21215 +               inode->i_fop = p->fop;
21216 +
21217 +       set_nlink(inode, (p->mode & S_IFDIR) ? 2 : 1);
21218 +       inode->i_flags |= S_IMMUTABLE;
21219 +
21220 +       inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
21221 +
21222 +       i_uid_write(inode, 0);
21223 +       i_gid_write(inode, 0);
21224 +       i_tag_write(inode, 0);
21225 +out:
21226 +       return inode;
21227 +}
21228 +
21229 +static struct dentry *vs_proc_instantiate(struct inode *dir,
21230 +       struct dentry *dentry, int id, void *ptr)
21231 +{
21232 +       struct vs_entry *p = ptr;
21233 +       struct inode *inode = vs_proc_make_inode(dir->i_sb, p);
21234 +       struct dentry *error = ERR_PTR(-EINVAL);
21235 +
21236 +       if (!inode)
21237 +               goto out;
21238 +
21239 +       PROC_I(inode)->op = p->op;
21240 +       PROC_I(inode)->fd = id;
21241 +       d_add(dentry, inode);
21242 +       error = NULL;
21243 +out:
21244 +       return error;
21245 +}
21246 +
21247 +/* Lookups */
21248 +
21249 +typedef struct dentry *instantiate_t(struct inode *, struct dentry *, int, void *);
21250 +
21251 +/*
21252 + * Fill a directory entry.
21253 + *
21254 + * If possible create the dcache entry and derive our inode number and
21255 + * file type from dcache entry.
21256 + *
21257 + * Since all of the proc inode numbers are dynamically generated, the inode
21258 + * numbers do not exist until the inode is cache.  This means creating the
21259 + * the dcache entry in readdir is necessary to keep the inode numbers
21260 + * reported by readdir in sync with the inode numbers reported
21261 + * by stat.
21262 + */
21263 +static int proc_fill_cache(struct file *filp, void *dirent, filldir_t filldir,
21264 +       char *name, int len, instantiate_t instantiate, int id, void *ptr)
21265 +{
21266 +       struct dentry *child, *dir = filp->f_dentry;
21267 +       struct inode *inode;
21268 +       struct qstr qname;
21269 +       ino_t ino = 0;
21270 +       unsigned type = DT_UNKNOWN;
21271 +
21272 +       qname.name = name;
21273 +       qname.len  = len;
21274 +       qname.hash = full_name_hash(name, len);
21275 +
21276 +       child = d_lookup(dir, &qname);
21277 +       if (!child) {
21278 +               struct dentry *new;
21279 +               new = d_alloc(dir, &qname);
21280 +               if (new) {
21281 +                       child = instantiate(dir->d_inode, new, id, ptr);
21282 +                       if (child)
21283 +                               dput(new);
21284 +                       else
21285 +                               child = new;
21286 +               }
21287 +       }
21288 +       if (!child || IS_ERR(child) || !child->d_inode)
21289 +               goto end_instantiate;
21290 +       inode = child->d_inode;
21291 +       if (inode) {
21292 +               ino = inode->i_ino;
21293 +               type = inode->i_mode >> 12;
21294 +       }
21295 +       dput(child);
21296 +end_instantiate:
21297 +       if (!ino)
21298 +               ino = find_inode_number(dir, &qname);
21299 +       if (!ino)
21300 +               ino = 1;
21301 +       return filldir(dirent, name, len, filp->f_pos, ino, type);
21302 +}
21303 +
21304 +
21305 +
21306 +/* get and revalidate vx_info/xid */
21307 +
21308 +static inline
21309 +struct vx_info *get_proc_vx_info(struct inode *inode)
21310 +{
21311 +       return lookup_vx_info(PROC_I(inode)->fd);
21312 +}
21313 +
21314 +static int proc_xid_revalidate(struct dentry *dentry, unsigned int flags)
21315 +{
21316 +       struct inode *inode = dentry->d_inode;
21317 +       xid_t xid = PROC_I(inode)->fd;
21318 +
21319 +       if (flags & LOOKUP_RCU) /* FIXME: can be dropped? */
21320 +               return -ECHILD;
21321 +
21322 +       if (!xid || xid_is_hashed(xid))
21323 +               return 1;
21324 +       d_drop(dentry);
21325 +       return 0;
21326 +}
21327 +
21328 +
21329 +/* get and revalidate nx_info/nid */
21330 +
21331 +static int proc_nid_revalidate(struct dentry *dentry, unsigned int flags)
21332 +{
21333 +       struct inode *inode = dentry->d_inode;
21334 +       nid_t nid = PROC_I(inode)->fd;
21335 +
21336 +       if (flags & LOOKUP_RCU) /* FIXME: can be dropped? */
21337 +               return -ECHILD;
21338 +
21339 +       if (!nid || nid_is_hashed(nid))
21340 +               return 1;
21341 +       d_drop(dentry);
21342 +       return 0;
21343 +}
21344 +
21345 +
21346 +
21347 +#define PROC_BLOCK_SIZE (PAGE_SIZE - 1024)
21348 +
21349 +static ssize_t proc_vs_info_read(struct file *file, char __user *buf,
21350 +                         size_t count, loff_t *ppos)
21351 +{
21352 +       struct inode *inode = file->f_dentry->d_inode;
21353 +       unsigned long page;
21354 +       ssize_t length = 0;
21355 +
21356 +       if (count > PROC_BLOCK_SIZE)
21357 +               count = PROC_BLOCK_SIZE;
21358 +
21359 +       /* fade that out as soon as stable */
21360 +       WARN_ON(PROC_I(inode)->fd);
21361 +
21362 +       if (!(page = __get_free_page(GFP_KERNEL)))
21363 +               return -ENOMEM;
21364 +
21365 +       BUG_ON(!PROC_I(inode)->op.proc_vs_read);
21366 +       length = PROC_I(inode)->op.proc_vs_read((char *)page);
21367 +
21368 +       if (length >= 0)
21369 +               length = simple_read_from_buffer(buf, count, ppos,
21370 +                       (char *)page, length);
21371 +
21372 +       free_page(page);
21373 +       return length;
21374 +}
21375 +
21376 +static ssize_t proc_vx_info_read(struct file *file, char __user *buf,
21377 +                         size_t count, loff_t *ppos)
21378 +{
21379 +       struct inode *inode = file->f_dentry->d_inode;
21380 +       struct vx_info *vxi = NULL;
21381 +       xid_t xid = PROC_I(inode)->fd;
21382 +       unsigned long page;
21383 +       ssize_t length = 0;
21384 +
21385 +       if (count > PROC_BLOCK_SIZE)
21386 +               count = PROC_BLOCK_SIZE;
21387 +
21388 +       /* fade that out as soon as stable */
21389 +       WARN_ON(!xid);
21390 +       vxi = lookup_vx_info(xid);
21391 +       if (!vxi)
21392 +               goto out;
21393 +
21394 +       length = -ENOMEM;
21395 +       if (!(page = __get_free_page(GFP_KERNEL)))
21396 +               goto out_put;
21397 +
21398 +       BUG_ON(!PROC_I(inode)->op.proc_vxi_read);
21399 +       length = PROC_I(inode)->op.proc_vxi_read(vxi, (char *)page);
21400 +
21401 +       if (length >= 0)
21402 +               length = simple_read_from_buffer(buf, count, ppos,
21403 +                       (char *)page, length);
21404 +
21405 +       free_page(page);
21406 +out_put:
21407 +       put_vx_info(vxi);
21408 +out:
21409 +       return length;
21410 +}
21411 +
21412 +static ssize_t proc_nx_info_read(struct file *file, char __user *buf,
21413 +                         size_t count, loff_t *ppos)
21414 +{
21415 +       struct inode *inode = file->f_dentry->d_inode;
21416 +       struct nx_info *nxi = NULL;
21417 +       nid_t nid = PROC_I(inode)->fd;
21418 +       unsigned long page;
21419 +       ssize_t length = 0;
21420 +
21421 +       if (count > PROC_BLOCK_SIZE)
21422 +               count = PROC_BLOCK_SIZE;
21423 +
21424 +       /* fade that out as soon as stable */
21425 +       WARN_ON(!nid);
21426 +       nxi = lookup_nx_info(nid);
21427 +       if (!nxi)
21428 +               goto out;
21429 +
21430 +       length = -ENOMEM;
21431 +       if (!(page = __get_free_page(GFP_KERNEL)))
21432 +               goto out_put;
21433 +
21434 +       BUG_ON(!PROC_I(inode)->op.proc_nxi_read);
21435 +       length = PROC_I(inode)->op.proc_nxi_read(nxi, (char *)page);
21436 +
21437 +       if (length >= 0)
21438 +               length = simple_read_from_buffer(buf, count, ppos,
21439 +                       (char *)page, length);
21440 +
21441 +       free_page(page);
21442 +out_put:
21443 +       put_nx_info(nxi);
21444 +out:
21445 +       return length;
21446 +}
21447 +
21448 +
21449 +
21450 +/* here comes the lower level */
21451 +
21452 +
21453 +#define NOD(NAME, MODE, IOP, FOP, OP) {        \
21454 +       .len  = sizeof(NAME) - 1,       \
21455 +       .name = (NAME),                 \
21456 +       .mode = MODE,                   \
21457 +       .iop  = IOP,                    \
21458 +       .fop  = FOP,                    \
21459 +       .op   = OP,                     \
21460 +}
21461 +
21462 +
21463 +#define DIR(NAME, MODE, OTYPE)                         \
21464 +       NOD(NAME, (S_IFDIR | (MODE)),                   \
21465 +               &proc_ ## OTYPE ## _inode_operations,   \
21466 +               &proc_ ## OTYPE ## _file_operations, { } )
21467 +
21468 +#define INF(NAME, MODE, OTYPE)                         \
21469 +       NOD(NAME, (S_IFREG | (MODE)), NULL,             \
21470 +               &proc_vs_info_file_operations,          \
21471 +               { .proc_vs_read = &proc_##OTYPE } )
21472 +
21473 +#define VINF(NAME, MODE, OTYPE)                                \
21474 +       NOD(NAME, (S_IFREG | (MODE)), NULL,             \
21475 +               &proc_vx_info_file_operations,          \
21476 +               { .proc_vxi_read = &proc_##OTYPE } )
21477 +
21478 +#define NINF(NAME, MODE, OTYPE)                                \
21479 +       NOD(NAME, (S_IFREG | (MODE)), NULL,             \
21480 +               &proc_nx_info_file_operations,          \
21481 +               { .proc_nxi_read = &proc_##OTYPE } )
21482 +
21483 +
21484 +static struct file_operations proc_vs_info_file_operations = {
21485 +       .read =         proc_vs_info_read,
21486 +};
21487 +
21488 +static struct file_operations proc_vx_info_file_operations = {
21489 +       .read =         proc_vx_info_read,
21490 +};
21491 +
21492 +static struct dentry_operations proc_xid_dentry_operations = {
21493 +       .d_revalidate = proc_xid_revalidate,
21494 +};
21495 +
21496 +static struct vs_entry vx_base_stuff[] = {
21497 +       VINF("info",    S_IRUGO, vxi_info),
21498 +       VINF("status",  S_IRUGO, vxi_status),
21499 +       VINF("limit",   S_IRUGO, vxi_limit),
21500 +       VINF("sched",   S_IRUGO, vxi_sched),
21501 +       VINF("nsproxy", S_IRUGO, vxi_nsproxy0),
21502 +       VINF("nsproxy1",S_IRUGO, vxi_nsproxy1),
21503 +       VINF("cvirt",   S_IRUGO, vxi_cvirt),
21504 +       VINF("cacct",   S_IRUGO, vxi_cacct),
21505 +       {}
21506 +};
21507 +
21508 +
21509 +
21510 +
21511 +static struct dentry *proc_xid_instantiate(struct inode *dir,
21512 +       struct dentry *dentry, int id, void *ptr)
21513 +{
21514 +       dentry->d_op = &proc_xid_dentry_operations;
21515 +       return vs_proc_instantiate(dir, dentry, id, ptr);
21516 +}
21517 +
21518 +static struct dentry *proc_xid_lookup(struct inode *dir,
21519 +       struct dentry *dentry, unsigned int flags)
21520 +{
21521 +       struct vs_entry *p = vx_base_stuff;
21522 +       struct dentry *error = ERR_PTR(-ENOENT);
21523 +
21524 +       for (; p->name; p++) {
21525 +               if (p->len != dentry->d_name.len)
21526 +                       continue;
21527 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
21528 +                       break;
21529 +       }
21530 +       if (!p->name)
21531 +               goto out;
21532 +
21533 +       error = proc_xid_instantiate(dir, dentry, PROC_I(dir)->fd, p);
21534 +out:
21535 +       return error;
21536 +}
21537 +
21538 +static int proc_xid_readdir(struct file *filp,
21539 +       void *dirent, filldir_t filldir)
21540 +{
21541 +       struct dentry *dentry = filp->f_dentry;
21542 +       struct inode *inode = dentry->d_inode;
21543 +       struct vs_entry *p = vx_base_stuff;
21544 +       int size = sizeof(vx_base_stuff) / sizeof(struct vs_entry);
21545 +       int pos, index;
21546 +       u64 ino;
21547 +
21548 +       pos = filp->f_pos;
21549 +       switch (pos) {
21550 +       case 0:
21551 +               ino = inode->i_ino;
21552 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
21553 +                       goto out;
21554 +               pos++;
21555 +               /* fall through */
21556 +       case 1:
21557 +               ino = parent_ino(dentry);
21558 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
21559 +                       goto out;
21560 +               pos++;
21561 +               /* fall through */
21562 +       default:
21563 +               index = pos - 2;
21564 +               if (index >= size)
21565 +                       goto out;
21566 +               for (p += index; p->name; p++) {
21567 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
21568 +                               vs_proc_instantiate, PROC_I(inode)->fd, p))
21569 +                               goto out;
21570 +                       pos++;
21571 +               }
21572 +       }
21573 +out:
21574 +       filp->f_pos = pos;
21575 +       return 1;
21576 +}
21577 +
21578 +
21579 +
21580 +static struct file_operations proc_nx_info_file_operations = {
21581 +       .read =         proc_nx_info_read,
21582 +};
21583 +
21584 +static struct dentry_operations proc_nid_dentry_operations = {
21585 +       .d_revalidate = proc_nid_revalidate,
21586 +};
21587 +
21588 +static struct vs_entry nx_base_stuff[] = {
21589 +       NINF("info",    S_IRUGO, nxi_info),
21590 +       NINF("status",  S_IRUGO, nxi_status),
21591 +       {}
21592 +};
21593 +
21594 +
21595 +static struct dentry *proc_nid_instantiate(struct inode *dir,
21596 +       struct dentry *dentry, int id, void *ptr)
21597 +{
21598 +       dentry->d_op = &proc_nid_dentry_operations;
21599 +       return vs_proc_instantiate(dir, dentry, id, ptr);
21600 +}
21601 +
21602 +static struct dentry *proc_nid_lookup(struct inode *dir,
21603 +       struct dentry *dentry, unsigned int flags)
21604 +{
21605 +       struct vs_entry *p = nx_base_stuff;
21606 +       struct dentry *error = ERR_PTR(-ENOENT);
21607 +
21608 +       for (; p->name; p++) {
21609 +               if (p->len != dentry->d_name.len)
21610 +                       continue;
21611 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
21612 +                       break;
21613 +       }
21614 +       if (!p->name)
21615 +               goto out;
21616 +
21617 +       error = proc_nid_instantiate(dir, dentry, PROC_I(dir)->fd, p);
21618 +out:
21619 +       return error;
21620 +}
21621 +
21622 +static int proc_nid_readdir(struct file *filp,
21623 +       void *dirent, filldir_t filldir)
21624 +{
21625 +       struct dentry *dentry = filp->f_dentry;
21626 +       struct inode *inode = dentry->d_inode;
21627 +       struct vs_entry *p = nx_base_stuff;
21628 +       int size = sizeof(nx_base_stuff) / sizeof(struct vs_entry);
21629 +       int pos, index;
21630 +       u64 ino;
21631 +
21632 +       pos = filp->f_pos;
21633 +       switch (pos) {
21634 +       case 0:
21635 +               ino = inode->i_ino;
21636 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
21637 +                       goto out;
21638 +               pos++;
21639 +               /* fall through */
21640 +       case 1:
21641 +               ino = parent_ino(dentry);
21642 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
21643 +                       goto out;
21644 +               pos++;
21645 +               /* fall through */
21646 +       default:
21647 +               index = pos - 2;
21648 +               if (index >= size)
21649 +                       goto out;
21650 +               for (p += index; p->name; p++) {
21651 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
21652 +                               vs_proc_instantiate, PROC_I(inode)->fd, p))
21653 +                               goto out;
21654 +                       pos++;
21655 +               }
21656 +       }
21657 +out:
21658 +       filp->f_pos = pos;
21659 +       return 1;
21660 +}
21661 +
21662 +
21663 +#define MAX_MULBY10    ((~0U - 9) / 10)
21664 +
21665 +static inline int atovid(const char *str, int len)
21666 +{
21667 +       int vid, c;
21668 +
21669 +       vid = 0;
21670 +       while (len-- > 0) {
21671 +               c = *str - '0';
21672 +               str++;
21673 +               if (c > 9)
21674 +                       return -1;
21675 +               if (vid >= MAX_MULBY10)
21676 +                       return -1;
21677 +               vid *= 10;
21678 +               vid += c;
21679 +               if (!vid)
21680 +                       return -1;
21681 +       }
21682 +       return vid;
21683 +}
21684 +
21685 +/* now the upper level (virtual) */
21686 +
21687 +
21688 +static struct file_operations proc_xid_file_operations = {
21689 +       .read =         generic_read_dir,
21690 +       .readdir =      proc_xid_readdir,
21691 +};
21692 +
21693 +static struct inode_operations proc_xid_inode_operations = {
21694 +       .lookup =       proc_xid_lookup,
21695 +};
21696 +
21697 +static struct vs_entry vx_virtual_stuff[] = {
21698 +       INF("info",     S_IRUGO, virtual_info),
21699 +       INF("status",   S_IRUGO, virtual_status),
21700 +       DIR(NULL,       S_IRUGO | S_IXUGO, xid),
21701 +};
21702 +
21703 +
21704 +static struct dentry *proc_virtual_lookup(struct inode *dir,
21705 +       struct dentry *dentry, unsigned int flags)
21706 +{
21707 +       struct vs_entry *p = vx_virtual_stuff;
21708 +       struct dentry *error = ERR_PTR(-ENOENT);
21709 +       int id = 0;
21710 +
21711 +       for (; p->name; p++) {
21712 +               if (p->len != dentry->d_name.len)
21713 +                       continue;
21714 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
21715 +                       break;
21716 +       }
21717 +       if (p->name)
21718 +               goto instantiate;
21719 +
21720 +       id = atovid(dentry->d_name.name, dentry->d_name.len);
21721 +       if ((id < 0) || !xid_is_hashed(id))
21722 +               goto out;
21723 +
21724 +instantiate:
21725 +       error = proc_xid_instantiate(dir, dentry, id, p);
21726 +out:
21727 +       return error;
21728 +}
21729 +
21730 +static struct file_operations proc_nid_file_operations = {
21731 +       .read =         generic_read_dir,
21732 +       .readdir =      proc_nid_readdir,
21733 +};
21734 +
21735 +static struct inode_operations proc_nid_inode_operations = {
21736 +       .lookup =       proc_nid_lookup,
21737 +};
21738 +
21739 +static struct vs_entry nx_virtnet_stuff[] = {
21740 +       INF("info",     S_IRUGO, virtnet_info),
21741 +       INF("status",   S_IRUGO, virtnet_status),
21742 +       DIR(NULL,       S_IRUGO | S_IXUGO, nid),
21743 +};
21744 +
21745 +
21746 +static struct dentry *proc_virtnet_lookup(struct inode *dir,
21747 +       struct dentry *dentry, unsigned int flags)
21748 +{
21749 +       struct vs_entry *p = nx_virtnet_stuff;
21750 +       struct dentry *error = ERR_PTR(-ENOENT);
21751 +       int id = 0;
21752 +
21753 +       for (; p->name; p++) {
21754 +               if (p->len != dentry->d_name.len)
21755 +                       continue;
21756 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
21757 +                       break;
21758 +       }
21759 +       if (p->name)
21760 +               goto instantiate;
21761 +
21762 +       id = atovid(dentry->d_name.name, dentry->d_name.len);
21763 +       if ((id < 0) || !nid_is_hashed(id))
21764 +               goto out;
21765 +
21766 +instantiate:
21767 +       error = proc_nid_instantiate(dir, dentry, id, p);
21768 +out:
21769 +       return error;
21770 +}
21771 +
21772 +
21773 +#define PROC_MAXVIDS 32
21774 +
21775 +int proc_virtual_readdir(struct file *filp,
21776 +       void *dirent, filldir_t filldir)
21777 +{
21778 +       struct dentry *dentry = filp->f_dentry;
21779 +       struct inode *inode = dentry->d_inode;
21780 +       struct vs_entry *p = vx_virtual_stuff;
21781 +       int size = sizeof(vx_virtual_stuff) / sizeof(struct vs_entry);
21782 +       int pos, index;
21783 +       unsigned int xid_array[PROC_MAXVIDS];
21784 +       char buf[PROC_NUMBUF];
21785 +       unsigned int nr_xids, i;
21786 +       u64 ino;
21787 +
21788 +       pos = filp->f_pos;
21789 +       switch (pos) {
21790 +       case 0:
21791 +               ino = inode->i_ino;
21792 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
21793 +                       goto out;
21794 +               pos++;
21795 +               /* fall through */
21796 +       case 1:
21797 +               ino = parent_ino(dentry);
21798 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
21799 +                       goto out;
21800 +               pos++;
21801 +               /* fall through */
21802 +       default:
21803 +               index = pos - 2;
21804 +               if (index >= size)
21805 +                       goto entries;
21806 +               for (p += index; p->name; p++) {
21807 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
21808 +                               vs_proc_instantiate, 0, p))
21809 +                               goto out;
21810 +                       pos++;
21811 +               }
21812 +       entries:
21813 +               index = pos - size;
21814 +               p = &vx_virtual_stuff[size - 1];
21815 +               nr_xids = get_xid_list(index, xid_array, PROC_MAXVIDS);
21816 +               for (i = 0; i < nr_xids; i++) {
21817 +                       int n, xid = xid_array[i];
21818 +                       unsigned int j = PROC_NUMBUF;
21819 +
21820 +                       n = xid;
21821 +                       do
21822 +                               buf[--j] = '0' + (n % 10);
21823 +                       while (n /= 10);
21824 +
21825 +                       if (proc_fill_cache(filp, dirent, filldir,
21826 +                               buf + j, PROC_NUMBUF - j,
21827 +                               vs_proc_instantiate, xid, p))
21828 +                               goto out;
21829 +                       pos++;
21830 +               }
21831 +       }
21832 +out:
21833 +       filp->f_pos = pos;
21834 +       return 0;
21835 +}
21836 +
21837 +static int proc_virtual_getattr(struct vfsmount *mnt,
21838 +       struct dentry *dentry, struct kstat *stat)
21839 +{
21840 +       struct inode *inode = dentry->d_inode;
21841 +
21842 +       generic_fillattr(inode, stat);
21843 +       stat->nlink = 2 + atomic_read(&vx_global_cactive);
21844 +       return 0;
21845 +}
21846 +
21847 +static struct file_operations proc_virtual_dir_operations = {
21848 +       .read =         generic_read_dir,
21849 +       .readdir =      proc_virtual_readdir,
21850 +};
21851 +
21852 +static struct inode_operations proc_virtual_dir_inode_operations = {
21853 +       .getattr =      proc_virtual_getattr,
21854 +       .lookup =       proc_virtual_lookup,
21855 +};
21856 +
21857 +
21858 +
21859 +
21860 +
21861 +int proc_virtnet_readdir(struct file *filp,
21862 +       void *dirent, filldir_t filldir)
21863 +{
21864 +       struct dentry *dentry = filp->f_dentry;
21865 +       struct inode *inode = dentry->d_inode;
21866 +       struct vs_entry *p = nx_virtnet_stuff;
21867 +       int size = sizeof(nx_virtnet_stuff) / sizeof(struct vs_entry);
21868 +       int pos, index;
21869 +       unsigned int nid_array[PROC_MAXVIDS];
21870 +       char buf[PROC_NUMBUF];
21871 +       unsigned int nr_nids, i;
21872 +       u64 ino;
21873 +
21874 +       pos = filp->f_pos;
21875 +       switch (pos) {
21876 +       case 0:
21877 +               ino = inode->i_ino;
21878 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
21879 +                       goto out;
21880 +               pos++;
21881 +               /* fall through */
21882 +       case 1:
21883 +               ino = parent_ino(dentry);
21884 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
21885 +                       goto out;
21886 +               pos++;
21887 +               /* fall through */
21888 +       default:
21889 +               index = pos - 2;
21890 +               if (index >= size)
21891 +                       goto entries;
21892 +               for (p += index; p->name; p++) {
21893 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
21894 +                               vs_proc_instantiate, 0, p))
21895 +                               goto out;
21896 +                       pos++;
21897 +               }
21898 +       entries:
21899 +               index = pos - size;
21900 +               p = &nx_virtnet_stuff[size - 1];
21901 +               nr_nids = get_nid_list(index, nid_array, PROC_MAXVIDS);
21902 +               for (i = 0; i < nr_nids; i++) {
21903 +                       int n, nid = nid_array[i];
21904 +                       unsigned int j = PROC_NUMBUF;
21905 +
21906 +                       n = nid;
21907 +                       do
21908 +                               buf[--j] = '0' + (n % 10);
21909 +                       while (n /= 10);
21910 +
21911 +                       if (proc_fill_cache(filp, dirent, filldir,
21912 +                               buf + j, PROC_NUMBUF - j,
21913 +                               vs_proc_instantiate, nid, p))
21914 +                               goto out;
21915 +                       pos++;
21916 +               }
21917 +       }
21918 +out:
21919 +       filp->f_pos = pos;
21920 +       return 0;
21921 +}
21922 +
21923 +static int proc_virtnet_getattr(struct vfsmount *mnt,
21924 +       struct dentry *dentry, struct kstat *stat)
21925 +{
21926 +       struct inode *inode = dentry->d_inode;
21927 +
21928 +       generic_fillattr(inode, stat);
21929 +       stat->nlink = 2 + atomic_read(&nx_global_cactive);
21930 +       return 0;
21931 +}
21932 +
21933 +static struct file_operations proc_virtnet_dir_operations = {
21934 +       .read =         generic_read_dir,
21935 +       .readdir =      proc_virtnet_readdir,
21936 +};
21937 +
21938 +static struct inode_operations proc_virtnet_dir_inode_operations = {
21939 +       .getattr =      proc_virtnet_getattr,
21940 +       .lookup =       proc_virtnet_lookup,
21941 +};
21942 +
21943 +
21944 +
21945 +void proc_vx_init(void)
21946 +{
21947 +       struct proc_dir_entry *ent;
21948 +
21949 +       ent = proc_mkdir("virtual", 0);
21950 +       if (ent) {
21951 +               ent->proc_fops = &proc_virtual_dir_operations;
21952 +               ent->proc_iops = &proc_virtual_dir_inode_operations;
21953 +       }
21954 +       proc_virtual = ent;
21955 +
21956 +       ent = proc_mkdir("virtnet", 0);
21957 +       if (ent) {
21958 +               ent->proc_fops = &proc_virtnet_dir_operations;
21959 +               ent->proc_iops = &proc_virtnet_dir_inode_operations;
21960 +       }
21961 +       proc_virtnet = ent;
21962 +}
21963 +
21964 +
21965 +
21966 +
21967 +/* per pid info */
21968 +
21969 +
21970 +int proc_pid_vx_info(struct task_struct *p, char *buffer)
21971 +{
21972 +       struct vx_info *vxi;
21973 +       char *orig = buffer;
21974 +
21975 +       buffer += sprintf(buffer, "XID:\t%d\n", vx_task_xid(p));
21976 +
21977 +       vxi = task_get_vx_info(p);
21978 +       if (!vxi)
21979 +               goto out;
21980 +
21981 +       buffer += sprintf(buffer, "BCaps:\t");
21982 +       buffer = print_cap_t(buffer, &vxi->vx_bcaps);
21983 +       buffer += sprintf(buffer, "\n");
21984 +       buffer += sprintf(buffer, "CCaps:\t%016llx\n",
21985 +               (unsigned long long)vxi->vx_ccaps);
21986 +       buffer += sprintf(buffer, "CFlags:\t%016llx\n",
21987 +               (unsigned long long)vxi->vx_flags);
21988 +       buffer += sprintf(buffer, "CIPid:\t%d\n", vxi->vx_initpid);
21989 +
21990 +       put_vx_info(vxi);
21991 +out:
21992 +       return buffer - orig;
21993 +}
21994 +
21995 +
21996 +int proc_pid_nx_info(struct task_struct *p, char *buffer)
21997 +{
21998 +       struct nx_info *nxi;
21999 +       struct nx_addr_v4 *v4a;
22000 +#ifdef CONFIG_IPV6
22001 +       struct nx_addr_v6 *v6a;
22002 +#endif
22003 +       char *orig = buffer;
22004 +       int i;
22005 +
22006 +       buffer += sprintf(buffer, "NID:\t%d\n", nx_task_nid(p));
22007 +
22008 +       nxi = task_get_nx_info(p);
22009 +       if (!nxi)
22010 +               goto out;
22011 +
22012 +       buffer += sprintf(buffer, "NCaps:\t%016llx\n",
22013 +               (unsigned long long)nxi->nx_ncaps);
22014 +       buffer += sprintf(buffer, "NFlags:\t%016llx\n",
22015 +               (unsigned long long)nxi->nx_flags);
22016 +
22017 +       buffer += sprintf(buffer,
22018 +               "V4Root[bcast]:\t" NIPQUAD_FMT "\n",
22019 +               NIPQUAD(nxi->v4_bcast.s_addr));
22020 +       buffer += sprintf (buffer,
22021 +               "V4Root[lback]:\t" NIPQUAD_FMT "\n",
22022 +               NIPQUAD(nxi->v4_lback.s_addr));
22023 +       if (!NX_IPV4(nxi))
22024 +               goto skip_v4;
22025 +       for (i = 0, v4a = &nxi->v4; v4a; i++, v4a = v4a->next)
22026 +               buffer += sprintf(buffer, "V4Root[%d]:\t" NXAV4_FMT "\n",
22027 +                       i, NXAV4(v4a));
22028 +skip_v4:
22029 +#ifdef CONFIG_IPV6
22030 +       if (!NX_IPV6(nxi))
22031 +               goto skip_v6;
22032 +       for (i = 0, v6a = &nxi->v6; v6a; i++, v6a = v6a->next)
22033 +               buffer += sprintf(buffer, "V6Root[%d]:\t" NXAV6_FMT "\n",
22034 +                       i, NXAV6(v6a));
22035 +skip_v6:
22036 +#endif
22037 +       put_nx_info(nxi);
22038 +out:
22039 +       return buffer - orig;
22040 +}
22041 +
22042 diff -NurpP --minimal linux-3.9.4/kernel/vserver/sched.c linux-3.9.4-vs2.3.6.2/kernel/vserver/sched.c
22043 --- linux-3.9.4/kernel/vserver/sched.c  1970-01-01 00:00:00.000000000 +0000
22044 +++ linux-3.9.4-vs2.3.6.2/kernel/vserver/sched.c        2013-05-31 14:47:11.000000000 +0000
22045 @@ -0,0 +1,83 @@
22046 +/*
22047 + *  linux/kernel/vserver/sched.c
22048 + *
22049 + *  Virtual Server: Scheduler Support
22050 + *
22051 + *  Copyright (C) 2004-2010  Herbert Pötzl
22052 + *
22053 + *  V0.01  adapted Sam Vilains version to 2.6.3
22054 + *  V0.02  removed legacy interface
22055 + *  V0.03  changed vcmds to vxi arg
22056 + *  V0.04  removed older and legacy interfaces
22057 + *  V0.05  removed scheduler code/commands
22058 + *
22059 + */
22060 +
22061 +#include <linux/vs_context.h>
22062 +#include <linux/vs_sched.h>
22063 +#include <linux/cpumask.h>
22064 +#include <linux/vserver/sched_cmd.h>
22065 +
22066 +#include <asm/uaccess.h>
22067 +
22068 +
22069 +void vx_update_sched_param(struct _vx_sched *sched,
22070 +       struct _vx_sched_pc *sched_pc)
22071 +{
22072 +       sched_pc->prio_bias = sched->prio_bias;
22073 +}
22074 +
22075 +static int do_set_prio_bias(struct vx_info *vxi, struct vcmd_prio_bias *data)
22076 +{
22077 +       int cpu;
22078 +
22079 +       if (data->prio_bias > MAX_PRIO_BIAS)
22080 +               data->prio_bias = MAX_PRIO_BIAS;
22081 +       if (data->prio_bias < MIN_PRIO_BIAS)
22082 +               data->prio_bias = MIN_PRIO_BIAS;
22083 +
22084 +       if (data->cpu_id != ~0) {
22085 +               vxi->sched.update = cpumask_of_cpu(data->cpu_id);
22086 +               cpumask_and(&vxi->sched.update, &vxi->sched.update,
22087 +                       cpu_online_mask);
22088 +       } else
22089 +               cpumask_copy(&vxi->sched.update, cpu_online_mask);
22090 +
22091 +       for_each_cpu_mask(cpu, vxi->sched.update)
22092 +               vx_update_sched_param(&vxi->sched,
22093 +                       &vx_per_cpu(vxi, sched_pc, cpu));
22094 +       return 0;
22095 +}
22096 +
22097 +int vc_set_prio_bias(struct vx_info *vxi, void __user *data)
22098 +{
22099 +       struct vcmd_prio_bias vc_data;
22100 +
22101 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
22102 +               return -EFAULT;
22103 +
22104 +       return do_set_prio_bias(vxi, &vc_data);
22105 +}
22106 +
22107 +int vc_get_prio_bias(struct vx_info *vxi, void __user *data)
22108 +{
22109 +       struct vcmd_prio_bias vc_data;
22110 +       struct _vx_sched_pc *pcd;
22111 +       int cpu;
22112 +
22113 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
22114 +               return -EFAULT;
22115 +
22116 +       cpu = vc_data.cpu_id;
22117 +
22118 +       if (!cpu_possible(cpu))
22119 +               return -EINVAL;
22120 +
22121 +       pcd = &vx_per_cpu(vxi, sched_pc, cpu);
22122 +       vc_data.prio_bias = pcd->prio_bias;
22123 +
22124 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
22125 +               return -EFAULT;
22126 +       return 0;
22127 +}
22128 +
22129 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
22130 --- linux-3.9.4/kernel/vserver/sched_init.h     1970-01-01 00:00:00.000000000 +0000
22131 +++ linux-3.9.4-vs2.3.6.2/kernel/vserver/sched_init.h   2013-05-31 14:47:11.000000000 +0000
22132 @@ -0,0 +1,27 @@
22133 +
22134 +static inline void vx_info_init_sched(struct _vx_sched *sched)
22135 +{
22136 +       /* scheduling; hard code starting values as constants */
22137 +       sched->prio_bias = 0;
22138 +}
22139 +
22140 +static inline
22141 +void vx_info_init_sched_pc(struct _vx_sched_pc *sched_pc, int cpu)
22142 +{
22143 +       sched_pc->prio_bias = 0;
22144 +
22145 +       sched_pc->user_ticks = 0;
22146 +       sched_pc->sys_ticks = 0;
22147 +       sched_pc->hold_ticks = 0;
22148 +}
22149 +
22150 +static inline void vx_info_exit_sched(struct _vx_sched *sched)
22151 +{
22152 +       return;
22153 +}
22154 +
22155 +static inline
22156 +void vx_info_exit_sched_pc(struct _vx_sched_pc *sched_pc, int cpu)
22157 +{
22158 +       return;
22159 +}
22160 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
22161 --- linux-3.9.4/kernel/vserver/sched_proc.h     1970-01-01 00:00:00.000000000 +0000
22162 +++ linux-3.9.4-vs2.3.6.2/kernel/vserver/sched_proc.h   2013-05-31 14:47:11.000000000 +0000
22163 @@ -0,0 +1,32 @@
22164 +#ifndef _VX_SCHED_PROC_H
22165 +#define _VX_SCHED_PROC_H
22166 +
22167 +
22168 +static inline
22169 +int vx_info_proc_sched(struct _vx_sched *sched, char *buffer)
22170 +{
22171 +       int length = 0;
22172 +
22173 +       length += sprintf(buffer,
22174 +               "PrioBias:\t%8d\n",
22175 +               sched->prio_bias);
22176 +       return length;
22177 +}
22178 +
22179 +static inline
22180 +int vx_info_proc_sched_pc(struct _vx_sched_pc *sched_pc,
22181 +       char *buffer, int cpu)
22182 +{
22183 +       int length = 0;
22184 +
22185 +       length += sprintf(buffer + length,
22186 +               "cpu %d: %lld %lld %lld", cpu,
22187 +               (unsigned long long)sched_pc->user_ticks,
22188 +               (unsigned long long)sched_pc->sys_ticks,
22189 +               (unsigned long long)sched_pc->hold_ticks);
22190 +       length += sprintf(buffer + length,
22191 +               " %d\n", sched_pc->prio_bias);
22192 +       return length;
22193 +}
22194 +
22195 +#endif /* _VX_SCHED_PROC_H */
22196 diff -NurpP --minimal linux-3.9.4/kernel/vserver/signal.c linux-3.9.4-vs2.3.6.2/kernel/vserver/signal.c
22197 --- linux-3.9.4/kernel/vserver/signal.c 1970-01-01 00:00:00.000000000 +0000
22198 +++ linux-3.9.4-vs2.3.6.2/kernel/vserver/signal.c       2013-05-31 14:47:11.000000000 +0000
22199 @@ -0,0 +1,134 @@
22200 +/*
22201 + *  linux/kernel/vserver/signal.c
22202 + *
22203 + *  Virtual Server: Signal Support
22204 + *
22205 + *  Copyright (C) 2003-2007  Herbert Pötzl
22206 + *
22207 + *  V0.01  broken out from vcontext V0.05
22208 + *  V0.02  changed vcmds to vxi arg
22209 + *  V0.03  adjusted siginfo for kill
22210 + *
22211 + */
22212 +
22213 +#include <asm/uaccess.h>
22214 +
22215 +#include <linux/vs_context.h>
22216 +#include <linux/vs_pid.h>
22217 +#include <linux/vserver/signal_cmd.h>
22218 +
22219 +
22220 +int vx_info_kill(struct vx_info *vxi, int pid, int sig)
22221 +{
22222 +       int retval, count = 0;
22223 +       struct task_struct *p;
22224 +       struct siginfo *sip = SEND_SIG_PRIV;
22225 +
22226 +       retval = -ESRCH;
22227 +       vxdprintk(VXD_CBIT(misc, 4),
22228 +               "vx_info_kill(%p[#%d],%d,%d)*",
22229 +               vxi, vxi->vx_id, pid, sig);
22230 +       read_lock(&tasklist_lock);
22231 +       switch (pid) {
22232 +       case  0:
22233 +       case -1:
22234 +               for_each_process(p) {
22235 +                       int err = 0;
22236 +
22237 +                       if (vx_task_xid(p) != vxi->vx_id || p->pid <= 1 ||
22238 +                               (pid && vxi->vx_initpid == p->pid))
22239 +                               continue;
22240 +
22241 +                       err = group_send_sig_info(sig, sip, p);
22242 +                       ++count;
22243 +                       if (err != -EPERM)
22244 +                               retval = err;
22245 +               }
22246 +               break;
22247 +
22248 +       case 1:
22249 +               if (vxi->vx_initpid) {
22250 +                       pid = vxi->vx_initpid;
22251 +                       /* for now, only SIGINT to private init ... */
22252 +                       if (!vx_info_flags(vxi, VXF_STATE_ADMIN, 0) &&
22253 +                               /* ... as long as there are tasks left */
22254 +                               (atomic_read(&vxi->vx_tasks) > 1))
22255 +                               sig = SIGINT;
22256 +               }
22257 +               /* fallthrough */
22258 +       default:
22259 +               rcu_read_lock();
22260 +               p = find_task_by_real_pid(pid);
22261 +               rcu_read_unlock();
22262 +               if (p) {
22263 +                       if (vx_task_xid(p) == vxi->vx_id)
22264 +                               retval = group_send_sig_info(sig, sip, p);
22265 +               }
22266 +               break;
22267 +       }
22268 +       read_unlock(&tasklist_lock);
22269 +       vxdprintk(VXD_CBIT(misc, 4),
22270 +               "vx_info_kill(%p[#%d],%d,%d,%ld) = %d",
22271 +               vxi, vxi->vx_id, pid, sig, (long)sip, retval);
22272 +       return retval;
22273 +}
22274 +
22275 +int vc_ctx_kill(struct vx_info *vxi, void __user *data)
22276 +{
22277 +       struct vcmd_ctx_kill_v0 vc_data;
22278 +
22279 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
22280 +               return -EFAULT;
22281 +
22282 +       /* special check to allow guest shutdown */
22283 +       if (!vx_info_flags(vxi, VXF_STATE_ADMIN, 0) &&
22284 +               /* forbid killall pid=0 when init is present */
22285 +               (((vc_data.pid < 1) && vxi->vx_initpid) ||
22286 +               (vc_data.pid > 1)))
22287 +               return -EACCES;
22288 +
22289 +       return vx_info_kill(vxi, vc_data.pid, vc_data.sig);
22290 +}
22291 +
22292 +
22293 +static int __wait_exit(struct vx_info *vxi)
22294 +{
22295 +       DECLARE_WAITQUEUE(wait, current);
22296 +       int ret = 0;
22297 +
22298 +       add_wait_queue(&vxi->vx_wait, &wait);
22299 +       set_current_state(TASK_INTERRUPTIBLE);
22300 +
22301 +wait:
22302 +       if (vx_info_state(vxi,
22303 +               VXS_SHUTDOWN | VXS_HASHED | VXS_HELPER) == VXS_SHUTDOWN)
22304 +               goto out;
22305 +       if (signal_pending(current)) {
22306 +               ret = -ERESTARTSYS;
22307 +               goto out;
22308 +       }
22309 +       schedule();
22310 +       goto wait;
22311 +
22312 +out:
22313 +       set_current_state(TASK_RUNNING);
22314 +       remove_wait_queue(&vxi->vx_wait, &wait);
22315 +       return ret;
22316 +}
22317 +
22318 +
22319 +
22320 +int vc_wait_exit(struct vx_info *vxi, void __user *data)
22321 +{
22322 +       struct vcmd_wait_exit_v0 vc_data;
22323 +       int ret;
22324 +
22325 +       ret = __wait_exit(vxi);
22326 +       vc_data.reboot_cmd = vxi->reboot_cmd;
22327 +       vc_data.exit_code = vxi->exit_code;
22328 +
22329 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
22330 +               ret = -EFAULT;
22331 +       return ret;
22332 +}
22333 +
22334 diff -NurpP --minimal linux-3.9.4/kernel/vserver/space.c linux-3.9.4-vs2.3.6.2/kernel/vserver/space.c
22335 --- linux-3.9.4/kernel/vserver/space.c  1970-01-01 00:00:00.000000000 +0000
22336 +++ linux-3.9.4-vs2.3.6.2/kernel/vserver/space.c        2013-05-31 14:47:11.000000000 +0000
22337 @@ -0,0 +1,436 @@
22338 +/*
22339 + *  linux/kernel/vserver/space.c
22340 + *
22341 + *  Virtual Server: Context Space Support
22342 + *
22343 + *  Copyright (C) 2003-2010  Herbert Pötzl
22344 + *
22345 + *  V0.01  broken out from context.c 0.07
22346 + *  V0.02  added task locking for namespace
22347 + *  V0.03  broken out vx_enter_namespace
22348 + *  V0.04  added *space support and commands
22349 + *  V0.05  added credential support
22350 + *
22351 + */
22352 +
22353 +#include <linux/utsname.h>
22354 +#include <linux/nsproxy.h>
22355 +#include <linux/err.h>
22356 +#include <linux/fs_struct.h>
22357 +#include <linux/cred.h>
22358 +#include <asm/uaccess.h>
22359 +
22360 +#include <linux/vs_context.h>
22361 +#include <linux/vserver/space.h>
22362 +#include <linux/vserver/space_cmd.h>
22363 +
22364 +atomic_t vs_global_nsproxy     = ATOMIC_INIT(0);
22365 +atomic_t vs_global_fs          = ATOMIC_INIT(0);
22366 +atomic_t vs_global_mnt_ns      = ATOMIC_INIT(0);
22367 +atomic_t vs_global_uts_ns      = ATOMIC_INIT(0);
22368 +atomic_t vs_global_user_ns     = ATOMIC_INIT(0);
22369 +atomic_t vs_global_pid_ns      = ATOMIC_INIT(0);
22370 +
22371 +
22372 +/* namespace functions */
22373 +
22374 +#include <linux/mnt_namespace.h>
22375 +#include <linux/user_namespace.h>
22376 +#include <linux/pid_namespace.h>
22377 +#include <linux/ipc_namespace.h>
22378 +#include <net/net_namespace.h>
22379 +#include "../fs/mount.h"
22380 +
22381 +
22382 +static const struct vcmd_space_mask_v1 space_mask_v0 = {
22383 +       .mask = CLONE_FS |
22384 +               CLONE_NEWNS |
22385 +#ifdef CONFIG_UTS_NS
22386 +               CLONE_NEWUTS |
22387 +#endif
22388 +#ifdef CONFIG_IPC_NS
22389 +               CLONE_NEWIPC |
22390 +#endif
22391 +#ifdef CONFIG_USER_NS
22392 +               CLONE_NEWUSER |
22393 +#endif
22394 +               0
22395 +};
22396 +
22397 +static const struct vcmd_space_mask_v1 space_mask = {
22398 +       .mask = CLONE_FS |
22399 +               CLONE_NEWNS |
22400 +#ifdef CONFIG_UTS_NS
22401 +               CLONE_NEWUTS |
22402 +#endif
22403 +#ifdef CONFIG_IPC_NS
22404 +               CLONE_NEWIPC |
22405 +#endif
22406 +#ifdef CONFIG_USER_NS
22407 +               CLONE_NEWUSER |
22408 +#endif
22409 +#ifdef CONFIG_PID_NS
22410 +               CLONE_NEWPID |
22411 +#endif
22412 +#ifdef CONFIG_NET_NS
22413 +               CLONE_NEWNET |
22414 +#endif
22415 +               0
22416 +};
22417 +
22418 +static const struct vcmd_space_mask_v1 default_space_mask = {
22419 +       .mask = CLONE_FS |
22420 +               CLONE_NEWNS |
22421 +#ifdef CONFIG_UTS_NS
22422 +               CLONE_NEWUTS |
22423 +#endif
22424 +#ifdef CONFIG_IPC_NS
22425 +               CLONE_NEWIPC |
22426 +#endif
22427 +#ifdef CONFIG_USER_NS
22428 +               CLONE_NEWUSER |
22429 +#endif
22430 +#ifdef CONFIG_PID_NS
22431 +//             CLONE_NEWPID |
22432 +#endif
22433 +               0
22434 +};
22435 +
22436 +/*
22437 + *     build a new nsproxy mix
22438 + *      assumes that both proxies are 'const'
22439 + *     does not touch nsproxy refcounts
22440 + *     will hold a reference on the result.
22441 + */
22442 +
22443 +struct nsproxy *vs_mix_nsproxy(struct nsproxy *old_nsproxy,
22444 +       struct nsproxy *new_nsproxy, unsigned long mask)
22445 +{
22446 +       struct mnt_namespace *old_ns;
22447 +       struct uts_namespace *old_uts;
22448 +       struct ipc_namespace *old_ipc;
22449 +#ifdef CONFIG_PID_NS
22450 +       struct pid_namespace *old_pid;
22451 +#endif
22452 +#ifdef CONFIG_NET_NS
22453 +       struct net *old_net;
22454 +#endif
22455 +       struct nsproxy *nsproxy;
22456 +
22457 +       nsproxy = copy_nsproxy(old_nsproxy);
22458 +       if (!nsproxy)
22459 +               goto out;
22460 +
22461 +       if (mask & CLONE_NEWNS) {
22462 +               old_ns = nsproxy->mnt_ns;
22463 +               nsproxy->mnt_ns = new_nsproxy->mnt_ns;
22464 +               if (nsproxy->mnt_ns)
22465 +                       get_mnt_ns(nsproxy->mnt_ns);
22466 +       } else
22467 +               old_ns = NULL;
22468 +
22469 +       if (mask & CLONE_NEWUTS) {
22470 +               old_uts = nsproxy->uts_ns;
22471 +               nsproxy->uts_ns = new_nsproxy->uts_ns;
22472 +               if (nsproxy->uts_ns)
22473 +                       get_uts_ns(nsproxy->uts_ns);
22474 +       } else
22475 +               old_uts = NULL;
22476 +
22477 +       if (mask & CLONE_NEWIPC) {
22478 +               old_ipc = nsproxy->ipc_ns;
22479 +               nsproxy->ipc_ns = new_nsproxy->ipc_ns;
22480 +               if (nsproxy->ipc_ns)
22481 +                       get_ipc_ns(nsproxy->ipc_ns);
22482 +       } else
22483 +               old_ipc = NULL;
22484 +
22485 +#ifdef CONFIG_PID_NS
22486 +       if (mask & CLONE_NEWPID) {
22487 +               old_pid = nsproxy->pid_ns;
22488 +               nsproxy->pid_ns = new_nsproxy->pid_ns;
22489 +               if (nsproxy->pid_ns)
22490 +                       get_pid_ns(nsproxy->pid_ns);
22491 +       } else
22492 +               old_pid = NULL;
22493 +#endif
22494 +#ifdef CONFIG_NET_NS
22495 +       if (mask & CLONE_NEWNET) {
22496 +               old_net = nsproxy->net_ns;
22497 +               nsproxy->net_ns = new_nsproxy->net_ns;
22498 +               if (nsproxy->net_ns)
22499 +                       get_net(nsproxy->net_ns);
22500 +       } else
22501 +               old_net = NULL;
22502 +#endif
22503 +       if (old_ns)
22504 +               put_mnt_ns(old_ns);
22505 +       if (old_uts)
22506 +               put_uts_ns(old_uts);
22507 +       if (old_ipc)
22508 +               put_ipc_ns(old_ipc);
22509 +#ifdef CONFIG_PID_NS
22510 +       if (old_pid)
22511 +               put_pid_ns(old_pid);
22512 +#endif
22513 +#ifdef CONFIG_NET_NS
22514 +       if (old_net)
22515 +               put_net(old_net);
22516 +#endif
22517 +out:
22518 +       return nsproxy;
22519 +}
22520 +
22521 +
22522 +/*
22523 + *     merge two nsproxy structs into a new one.
22524 + *     will hold a reference on the result.
22525 + */
22526 +
22527 +static inline
22528 +struct nsproxy *__vs_merge_nsproxy(struct nsproxy *old,
22529 +       struct nsproxy *proxy, unsigned long mask)
22530 +{
22531 +       struct nsproxy null_proxy = { .mnt_ns = NULL };
22532 +
22533 +       if (!proxy)
22534 +               return NULL;
22535 +
22536 +       if (mask) {
22537 +               /* vs_mix_nsproxy returns with reference */
22538 +               return vs_mix_nsproxy(old ? old : &null_proxy,
22539 +                       proxy, mask);
22540 +       }
22541 +       get_nsproxy(proxy);
22542 +       return proxy;
22543 +}
22544 +
22545 +
22546 +int vx_enter_space(struct vx_info *vxi, unsigned long mask, unsigned index)
22547 +{
22548 +       struct nsproxy *proxy, *proxy_cur, *proxy_new;
22549 +       struct fs_struct *fs_cur, *fs = NULL;
22550 +       struct _vx_space *space;
22551 +       int ret, kill = 0;
22552 +
22553 +       vxdprintk(VXD_CBIT(space, 8), "vx_enter_space(%p[#%u],0x%08lx,%d)",
22554 +               vxi, vxi->vx_id, mask, index);
22555 +
22556 +       if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0))
22557 +               return -EACCES;
22558 +
22559 +       if (index >= VX_SPACES)
22560 +               return -EINVAL;
22561 +
22562 +       space = &vxi->space[index];
22563 +
22564 +       if (!mask)
22565 +               mask = space->vx_nsmask;
22566 +
22567 +       if ((mask & space->vx_nsmask) != mask)
22568 +               return -EINVAL;
22569 +
22570 +       if (mask & CLONE_FS) {
22571 +               fs = copy_fs_struct(space->vx_fs);
22572 +               if (!fs)
22573 +                       return -ENOMEM;
22574 +       }
22575 +       proxy = space->vx_nsproxy;
22576 +
22577 +       vxdprintk(VXD_CBIT(space, 9),
22578 +               "vx_enter_space(%p[#%u],0x%08lx,%d) -> (%p,%p)",
22579 +               vxi, vxi->vx_id, mask, index, proxy, fs);
22580 +
22581 +       task_lock(current);
22582 +       fs_cur = current->fs;
22583 +
22584 +       if (mask & CLONE_FS) {
22585 +               spin_lock(&fs_cur->lock);
22586 +               current->fs = fs;
22587 +               kill = !--fs_cur->users;
22588 +               spin_unlock(&fs_cur->lock);
22589 +       }
22590 +
22591 +       proxy_cur = current->nsproxy;
22592 +       get_nsproxy(proxy_cur);
22593 +       task_unlock(current);
22594 +
22595 +       if (kill)
22596 +               free_fs_struct(fs_cur);
22597 +
22598 +       proxy_new = __vs_merge_nsproxy(proxy_cur, proxy, mask);
22599 +       if (IS_ERR(proxy_new)) {
22600 +               ret = PTR_ERR(proxy_new);
22601 +               goto out_put;
22602 +       }
22603 +
22604 +       proxy_new = xchg(&current->nsproxy, proxy_new);
22605 +
22606 +       if (mask & CLONE_NEWUSER) {
22607 +               struct cred *cred;
22608 +
22609 +               vxdprintk(VXD_CBIT(space, 10),
22610 +                       "vx_enter_space(%p[#%u],%p) cred (%p,%p)",
22611 +                       vxi, vxi->vx_id, space->vx_cred,
22612 +                       current->real_cred, current->cred);
22613 +
22614 +               if (space->vx_cred) {
22615 +                       cred = __prepare_creds(space->vx_cred);
22616 +                       if (cred)
22617 +                               commit_creds(cred);
22618 +               }
22619 +       }
22620 +
22621 +       ret = 0;
22622 +
22623 +       if (proxy_new)
22624 +               put_nsproxy(proxy_new);
22625 +out_put:
22626 +       if (proxy_cur)
22627 +               put_nsproxy(proxy_cur);
22628 +       return ret;
22629 +}
22630 +
22631 +
22632 +int vx_set_space(struct vx_info *vxi, unsigned long mask, unsigned index)
22633 +{
22634 +       struct nsproxy *proxy_vxi, *proxy_cur, *proxy_new;
22635 +       struct fs_struct *fs_vxi, *fs = NULL;
22636 +       struct _vx_space *space;
22637 +       int ret, kill = 0;
22638 +
22639 +       vxdprintk(VXD_CBIT(space, 8), "vx_set_space(%p[#%u],0x%08lx,%d)",
22640 +               vxi, vxi->vx_id, mask, index);
22641 +
22642 +       if ((mask & space_mask.mask) != mask)
22643 +               return -EINVAL;
22644 +
22645 +       if (index >= VX_SPACES)
22646 +               return -EINVAL;
22647 +
22648 +       space = &vxi->space[index];
22649 +
22650 +       proxy_vxi = space->vx_nsproxy;
22651 +       fs_vxi = space->vx_fs;
22652 +
22653 +       if (mask & CLONE_FS) {
22654 +               fs = copy_fs_struct(current->fs);
22655 +               if (!fs)
22656 +                       return -ENOMEM;
22657 +       }
22658 +
22659 +       task_lock(current);
22660 +
22661 +       if (mask & CLONE_FS) {
22662 +               spin_lock(&fs_vxi->lock);
22663 +               space->vx_fs = fs;
22664 +               kill = !--fs_vxi->users;
22665 +               spin_unlock(&fs_vxi->lock);
22666 +       }
22667 +
22668 +       proxy_cur = current->nsproxy;
22669 +       get_nsproxy(proxy_cur);
22670 +       task_unlock(current);
22671 +
22672 +       if (kill)
22673 +               free_fs_struct(fs_vxi);
22674 +
22675 +       proxy_new = __vs_merge_nsproxy(proxy_vxi, proxy_cur, mask);
22676 +       if (IS_ERR(proxy_new)) {
22677 +               ret = PTR_ERR(proxy_new);
22678 +               goto out_put;
22679 +       }
22680 +
22681 +       proxy_new = xchg(&space->vx_nsproxy, proxy_new);
22682 +       space->vx_nsmask |= mask;
22683 +
22684 +       if (mask & CLONE_NEWUSER) {
22685 +               struct cred *cred;
22686 +
22687 +               vxdprintk(VXD_CBIT(space, 10),
22688 +                       "vx_set_space(%p[#%u],%p) cred (%p,%p)",
22689 +                       vxi, vxi->vx_id, space->vx_cred,
22690 +                       current->real_cred, current->cred);
22691 +
22692 +               cred = prepare_creds();
22693 +               cred = (struct cred *)xchg(&space->vx_cred, cred);
22694 +               if (cred)
22695 +                       abort_creds(cred);
22696 +       }
22697 +
22698 +       ret = 0;
22699 +
22700 +       if (proxy_new)
22701 +               put_nsproxy(proxy_new);
22702 +out_put:
22703 +       if (proxy_cur)
22704 +               put_nsproxy(proxy_cur);
22705 +       return ret;
22706 +}
22707 +
22708 +
22709 +int vc_enter_space_v1(struct vx_info *vxi, void __user *data)
22710 +{
22711 +       struct vcmd_space_mask_v1 vc_data = { .mask = 0 };
22712 +
22713 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22714 +               return -EFAULT;
22715 +
22716 +       return vx_enter_space(vxi, vc_data.mask, 0);
22717 +}
22718 +
22719 +int vc_enter_space(struct vx_info *vxi, void __user *data)
22720 +{
22721 +       struct vcmd_space_mask_v2 vc_data = { .mask = 0 };
22722 +
22723 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22724 +               return -EFAULT;
22725 +
22726 +       if (vc_data.index >= VX_SPACES)
22727 +               return -EINVAL;
22728 +
22729 +       return vx_enter_space(vxi, vc_data.mask, vc_data.index);
22730 +}
22731 +
22732 +int vc_set_space_v1(struct vx_info *vxi, void __user *data)
22733 +{
22734 +       struct vcmd_space_mask_v1 vc_data = { .mask = 0 };
22735 +
22736 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22737 +               return -EFAULT;
22738 +
22739 +       return vx_set_space(vxi, vc_data.mask, 0);
22740 +}
22741 +
22742 +int vc_set_space(struct vx_info *vxi, void __user *data)
22743 +{
22744 +       struct vcmd_space_mask_v2 vc_data = { .mask = 0 };
22745 +
22746 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22747 +               return -EFAULT;
22748 +
22749 +       if (vc_data.index >= VX_SPACES)
22750 +               return -EINVAL;
22751 +
22752 +       return vx_set_space(vxi, vc_data.mask, vc_data.index);
22753 +}
22754 +
22755 +int vc_get_space_mask(void __user *data, int type)
22756 +{
22757 +       const struct vcmd_space_mask_v1 *mask;
22758 +
22759 +       if (type == 0)
22760 +               mask = &space_mask_v0;
22761 +       else if (type == 1)
22762 +               mask = &space_mask;
22763 +       else
22764 +               mask = &default_space_mask;
22765 +
22766 +       vxdprintk(VXD_CBIT(space, 10),
22767 +               "vc_get_space_mask(%d) = %08llx", type, mask->mask);
22768 +
22769 +       if (copy_to_user(data, mask, sizeof(*mask)))
22770 +               return -EFAULT;
22771 +       return 0;
22772 +}
22773 +
22774 diff -NurpP --minimal linux-3.9.4/kernel/vserver/switch.c linux-3.9.4-vs2.3.6.2/kernel/vserver/switch.c
22775 --- linux-3.9.4/kernel/vserver/switch.c 1970-01-01 00:00:00.000000000 +0000
22776 +++ linux-3.9.4-vs2.3.6.2/kernel/vserver/switch.c       2013-05-31 14:47:11.000000000 +0000
22777 @@ -0,0 +1,556 @@
22778 +/*
22779 + *  linux/kernel/vserver/switch.c
22780 + *
22781 + *  Virtual Server: Syscall Switch
22782 + *
22783 + *  Copyright (C) 2003-2011  Herbert Pötzl
22784 + *
22785 + *  V0.01  syscall switch
22786 + *  V0.02  added signal to context
22787 + *  V0.03  added rlimit functions
22788 + *  V0.04  added iattr, task/xid functions
22789 + *  V0.05  added debug/history stuff
22790 + *  V0.06  added compat32 layer
22791 + *  V0.07  vcmd args and perms
22792 + *  V0.08  added status commands
22793 + *  V0.09  added tag commands
22794 + *  V0.10  added oom bias
22795 + *  V0.11  added device commands
22796 + *  V0.12  added warn mask
22797 + *
22798 + */
22799 +
22800 +#include <linux/vs_context.h>
22801 +#include <linux/vs_network.h>
22802 +#include <linux/vserver/switch.h>
22803 +
22804 +#include "vci_config.h"
22805 +
22806 +
22807 +static inline
22808 +int vc_get_version(uint32_t id)
22809 +{
22810 +       return VCI_VERSION;
22811 +}
22812 +
22813 +static inline
22814 +int vc_get_vci(uint32_t id)
22815 +{
22816 +       return vci_kernel_config();
22817 +}
22818 +
22819 +#include <linux/vserver/context_cmd.h>
22820 +#include <linux/vserver/cvirt_cmd.h>
22821 +#include <linux/vserver/cacct_cmd.h>
22822 +#include <linux/vserver/limit_cmd.h>
22823 +#include <linux/vserver/network_cmd.h>
22824 +#include <linux/vserver/sched_cmd.h>
22825 +#include <linux/vserver/debug_cmd.h>
22826 +#include <linux/vserver/inode_cmd.h>
22827 +#include <linux/vserver/dlimit_cmd.h>
22828 +#include <linux/vserver/signal_cmd.h>
22829 +#include <linux/vserver/space_cmd.h>
22830 +#include <linux/vserver/tag_cmd.h>
22831 +#include <linux/vserver/device_cmd.h>
22832 +
22833 +#include <linux/vserver/inode.h>
22834 +#include <linux/vserver/dlimit.h>
22835 +
22836 +
22837 +#ifdef CONFIG_COMPAT
22838 +#define __COMPAT(name, id, data, compat)       \
22839 +       (compat) ? name ## _x32(id, data) : name(id, data)
22840 +#define __COMPAT_NO_ID(name, data, compat)     \
22841 +       (compat) ? name ## _x32(data) : name(data)
22842 +#else
22843 +#define __COMPAT(name, id, data, compat)       \
22844 +       name(id, data)
22845 +#define __COMPAT_NO_ID(name, data, compat)     \
22846 +       name(data)
22847 +#endif
22848 +
22849 +
22850 +static inline
22851 +long do_vcmd(uint32_t cmd, uint32_t id,
22852 +       struct vx_info *vxi, struct nx_info *nxi,
22853 +       void __user *data, int compat)
22854 +{
22855 +       switch (cmd) {
22856 +
22857 +       case VCMD_get_version:
22858 +               return vc_get_version(id);
22859 +       case VCMD_get_vci:
22860 +               return vc_get_vci(id);
22861 +
22862 +       case VCMD_task_xid:
22863 +               return vc_task_xid(id);
22864 +       case VCMD_vx_info:
22865 +               return vc_vx_info(vxi, data);
22866 +
22867 +       case VCMD_task_nid:
22868 +               return vc_task_nid(id);
22869 +       case VCMD_nx_info:
22870 +               return vc_nx_info(nxi, data);
22871 +
22872 +       case VCMD_task_tag:
22873 +               return vc_task_tag(id);
22874 +
22875 +       case VCMD_set_space_v1:
22876 +               return vc_set_space_v1(vxi, data);
22877 +       /* this is version 2 */
22878 +       case VCMD_set_space:
22879 +               return vc_set_space(vxi, data);
22880 +
22881 +       case VCMD_get_space_mask_v0:
22882 +               return vc_get_space_mask(data, 0);
22883 +       /* this is version 1 */
22884 +       case VCMD_get_space_mask:
22885 +               return vc_get_space_mask(data, 1);
22886 +
22887 +       case VCMD_get_space_default:
22888 +               return vc_get_space_mask(data, -1);
22889 +
22890 +       case VCMD_set_umask:
22891 +               return vc_set_umask(vxi, data);
22892 +
22893 +       case VCMD_get_umask:
22894 +               return vc_get_umask(vxi, data);
22895 +
22896 +       case VCMD_set_wmask:
22897 +               return vc_set_wmask(vxi, data);
22898 +
22899 +       case VCMD_get_wmask:
22900 +               return vc_get_wmask(vxi, data);
22901 +#ifdef CONFIG_IA32_EMULATION
22902 +       case VCMD_get_rlimit:
22903 +               return __COMPAT(vc_get_rlimit, vxi, data, compat);
22904 +       case VCMD_set_rlimit:
22905 +               return __COMPAT(vc_set_rlimit, vxi, data, compat);
22906 +#else
22907 +       case VCMD_get_rlimit:
22908 +               return vc_get_rlimit(vxi, data);
22909 +       case VCMD_set_rlimit:
22910 +               return vc_set_rlimit(vxi, data);
22911 +#endif
22912 +       case VCMD_get_rlimit_mask:
22913 +               return vc_get_rlimit_mask(id, data);
22914 +       case VCMD_reset_hits:
22915 +               return vc_reset_hits(vxi, data);
22916 +       case VCMD_reset_minmax:
22917 +               return vc_reset_minmax(vxi, data);
22918 +
22919 +       case VCMD_get_vhi_name:
22920 +               return vc_get_vhi_name(vxi, data);
22921 +       case VCMD_set_vhi_name:
22922 +               return vc_set_vhi_name(vxi, data);
22923 +
22924 +       case VCMD_ctx_stat:
22925 +               return vc_ctx_stat(vxi, data);
22926 +       case VCMD_virt_stat:
22927 +               return vc_virt_stat(vxi, data);
22928 +       case VCMD_sock_stat:
22929 +               return vc_sock_stat(vxi, data);
22930 +       case VCMD_rlimit_stat:
22931 +               return vc_rlimit_stat(vxi, data);
22932 +
22933 +       case VCMD_set_cflags:
22934 +               return vc_set_cflags(vxi, data);
22935 +       case VCMD_get_cflags:
22936 +               return vc_get_cflags(vxi, data);
22937 +
22938 +       /* this is version 1 */
22939 +       case VCMD_set_ccaps:
22940 +               return vc_set_ccaps(vxi, data);
22941 +       /* this is version 1 */
22942 +       case VCMD_get_ccaps:
22943 +               return vc_get_ccaps(vxi, data);
22944 +       case VCMD_set_bcaps:
22945 +               return vc_set_bcaps(vxi, data);
22946 +       case VCMD_get_bcaps:
22947 +               return vc_get_bcaps(vxi, data);
22948 +
22949 +       case VCMD_set_badness:
22950 +               return vc_set_badness(vxi, data);
22951 +       case VCMD_get_badness:
22952 +               return vc_get_badness(vxi, data);
22953 +
22954 +       case VCMD_set_nflags:
22955 +               return vc_set_nflags(nxi, data);
22956 +       case VCMD_get_nflags:
22957 +               return vc_get_nflags(nxi, data);
22958 +
22959 +       case VCMD_set_ncaps:
22960 +               return vc_set_ncaps(nxi, data);
22961 +       case VCMD_get_ncaps:
22962 +               return vc_get_ncaps(nxi, data);
22963 +
22964 +       case VCMD_set_prio_bias:
22965 +               return vc_set_prio_bias(vxi, data);
22966 +       case VCMD_get_prio_bias:
22967 +               return vc_get_prio_bias(vxi, data);
22968 +       case VCMD_add_dlimit:
22969 +               return __COMPAT(vc_add_dlimit, id, data, compat);
22970 +       case VCMD_rem_dlimit:
22971 +               return __COMPAT(vc_rem_dlimit, id, data, compat);
22972 +       case VCMD_set_dlimit:
22973 +               return __COMPAT(vc_set_dlimit, id, data, compat);
22974 +       case VCMD_get_dlimit:
22975 +               return __COMPAT(vc_get_dlimit, id, data, compat);
22976 +
22977 +       case VCMD_ctx_kill:
22978 +               return vc_ctx_kill(vxi, data);
22979 +
22980 +       case VCMD_wait_exit:
22981 +               return vc_wait_exit(vxi, data);
22982 +
22983 +       case VCMD_get_iattr:
22984 +               return __COMPAT_NO_ID(vc_get_iattr, data, compat);
22985 +       case VCMD_set_iattr:
22986 +               return __COMPAT_NO_ID(vc_set_iattr, data, compat);
22987 +
22988 +       case VCMD_fget_iattr:
22989 +               return vc_fget_iattr(id, data);
22990 +       case VCMD_fset_iattr:
22991 +               return vc_fset_iattr(id, data);
22992 +
22993 +       case VCMD_enter_space_v0:
22994 +               return vc_enter_space_v1(vxi, NULL);
22995 +       case VCMD_enter_space_v1:
22996 +               return vc_enter_space_v1(vxi, data);
22997 +       /* this is version 2 */
22998 +       case VCMD_enter_space:
22999 +               return vc_enter_space(vxi, data);
23000 +
23001 +       case VCMD_ctx_create_v0:
23002 +               return vc_ctx_create(id, NULL);
23003 +       case VCMD_ctx_create:
23004 +               return vc_ctx_create(id, data);
23005 +       case VCMD_ctx_migrate_v0:
23006 +               return vc_ctx_migrate(vxi, NULL);
23007 +       case VCMD_ctx_migrate:
23008 +               return vc_ctx_migrate(vxi, data);
23009 +
23010 +       case VCMD_net_create_v0:
23011 +               return vc_net_create(id, NULL);
23012 +       case VCMD_net_create:
23013 +               return vc_net_create(id, data);
23014 +       case VCMD_net_migrate:
23015 +               return vc_net_migrate(nxi, data);
23016 +
23017 +       case VCMD_tag_migrate:
23018 +               return vc_tag_migrate(id);
23019 +
23020 +       case VCMD_net_add:
23021 +               return vc_net_add(nxi, data);
23022 +       case VCMD_net_remove:
23023 +               return vc_net_remove(nxi, data);
23024 +
23025 +       case VCMD_net_add_ipv4_v1:
23026 +               return vc_net_add_ipv4_v1(nxi, data);
23027 +       /* this is version 2 */
23028 +       case VCMD_net_add_ipv4:
23029 +               return vc_net_add_ipv4(nxi, data);
23030 +
23031 +       case VCMD_net_rem_ipv4_v1:
23032 +               return vc_net_rem_ipv4_v1(nxi, data);
23033 +       /* this is version 2 */
23034 +       case VCMD_net_rem_ipv4:
23035 +               return vc_net_rem_ipv4(nxi, data);
23036 +#ifdef CONFIG_IPV6
23037 +       case VCMD_net_add_ipv6:
23038 +               return vc_net_add_ipv6(nxi, data);
23039 +       case VCMD_net_remove_ipv6:
23040 +               return vc_net_remove_ipv6(nxi, data);
23041 +#endif
23042 +/*     case VCMD_add_match_ipv4:
23043 +               return vc_add_match_ipv4(nxi, data);
23044 +       case VCMD_get_match_ipv4:
23045 +               return vc_get_match_ipv4(nxi, data);
23046 +#ifdef CONFIG_IPV6
23047 +       case VCMD_add_match_ipv6:
23048 +               return vc_add_match_ipv6(nxi, data);
23049 +       case VCMD_get_match_ipv6:
23050 +               return vc_get_match_ipv6(nxi, data);
23051 +#endif */
23052 +
23053 +#ifdef CONFIG_VSERVER_DEVICE
23054 +       case VCMD_set_mapping:
23055 +               return __COMPAT(vc_set_mapping, vxi, data, compat);
23056 +       case VCMD_unset_mapping:
23057 +               return __COMPAT(vc_unset_mapping, vxi, data, compat);
23058 +#endif
23059 +#ifdef CONFIG_VSERVER_HISTORY
23060 +       case VCMD_dump_history:
23061 +               return vc_dump_history(id);
23062 +       case VCMD_read_history:
23063 +               return __COMPAT(vc_read_history, id, data, compat);
23064 +#endif
23065 +       default:
23066 +               vxwprintk_task(1, "unimplemented VCMD_%02d_%d[%d]",
23067 +                       VC_CATEGORY(cmd), VC_COMMAND(cmd), VC_VERSION(cmd));
23068 +       }
23069 +       return -ENOSYS;
23070 +}
23071 +
23072 +
23073 +#define        __VCMD(vcmd, _perm, _args, _flags)              \
23074 +       case VCMD_ ## vcmd: perm = _perm;               \
23075 +               args = _args; flags = _flags; break
23076 +
23077 +
23078 +#define VCA_NONE       0x00
23079 +#define VCA_VXI                0x01
23080 +#define VCA_NXI                0x02
23081 +
23082 +#define VCF_NONE       0x00
23083 +#define VCF_INFO       0x01
23084 +#define VCF_ADMIN      0x02
23085 +#define VCF_ARES       0x06    /* includes admin */
23086 +#define VCF_SETUP      0x08
23087 +
23088 +#define VCF_ZIDOK      0x10    /* zero id okay */
23089 +
23090 +
23091 +static inline
23092 +long do_vserver(uint32_t cmd, uint32_t id, void __user *data, int compat)
23093 +{
23094 +       long ret;
23095 +       int permit = -1, state = 0;
23096 +       int perm = -1, args = 0, flags = 0;
23097 +       struct vx_info *vxi = NULL;
23098 +       struct nx_info *nxi = NULL;
23099 +
23100 +       switch (cmd) {
23101 +       /* unpriviledged commands */
23102 +       __VCMD(get_version,      0, VCA_NONE,   0);
23103 +       __VCMD(get_vci,          0, VCA_NONE,   0);
23104 +       __VCMD(get_rlimit_mask,  0, VCA_NONE,   0);
23105 +       __VCMD(get_space_mask_v0,0, VCA_NONE,   0);
23106 +       __VCMD(get_space_mask,   0, VCA_NONE,   0);
23107 +       __VCMD(get_space_default,0, VCA_NONE,   0);
23108 +
23109 +       /* info commands */
23110 +       __VCMD(task_xid,         2, VCA_NONE,   0);
23111 +       __VCMD(reset_hits,       2, VCA_VXI,    0);
23112 +       __VCMD(reset_minmax,     2, VCA_VXI,    0);
23113 +       __VCMD(vx_info,          3, VCA_VXI,    VCF_INFO);
23114 +       __VCMD(get_bcaps,        3, VCA_VXI,    VCF_INFO);
23115 +       __VCMD(get_ccaps,        3, VCA_VXI,    VCF_INFO);
23116 +       __VCMD(get_cflags,       3, VCA_VXI,    VCF_INFO);
23117 +       __VCMD(get_umask,        3, VCA_VXI,    VCF_INFO);
23118 +       __VCMD(get_wmask,        3, VCA_VXI,    VCF_INFO);
23119 +       __VCMD(get_badness,      3, VCA_VXI,    VCF_INFO);
23120 +       __VCMD(get_vhi_name,     3, VCA_VXI,    VCF_INFO);
23121 +       __VCMD(get_rlimit,       3, VCA_VXI,    VCF_INFO);
23122 +
23123 +       __VCMD(ctx_stat,         3, VCA_VXI,    VCF_INFO);
23124 +       __VCMD(virt_stat,        3, VCA_VXI,    VCF_INFO);
23125 +       __VCMD(sock_stat,        3, VCA_VXI,    VCF_INFO);
23126 +       __VCMD(rlimit_stat,      3, VCA_VXI,    VCF_INFO);
23127 +
23128 +       __VCMD(task_nid,         2, VCA_NONE,   0);
23129 +       __VCMD(nx_info,          3, VCA_NXI,    VCF_INFO);
23130 +       __VCMD(get_ncaps,        3, VCA_NXI,    VCF_INFO);
23131 +       __VCMD(get_nflags,       3, VCA_NXI,    VCF_INFO);
23132 +
23133 +       __VCMD(task_tag,         2, VCA_NONE,   0);
23134 +
23135 +       __VCMD(get_iattr,        2, VCA_NONE,   0);
23136 +       __VCMD(fget_iattr,       2, VCA_NONE,   0);
23137 +       __VCMD(get_dlimit,       3, VCA_NONE,   VCF_INFO);
23138 +       __VCMD(get_prio_bias,    3, VCA_VXI,    VCF_INFO);
23139 +
23140 +       /* lower admin commands */
23141 +       __VCMD(wait_exit,        4, VCA_VXI,    VCF_INFO);
23142 +       __VCMD(ctx_create_v0,    5, VCA_NONE,   0);
23143 +       __VCMD(ctx_create,       5, VCA_NONE,   0);
23144 +       __VCMD(ctx_migrate_v0,   5, VCA_VXI,    VCF_ADMIN);
23145 +       __VCMD(ctx_migrate,      5, VCA_VXI,    VCF_ADMIN);
23146 +       __VCMD(enter_space_v0,   5, VCA_VXI,    VCF_ADMIN);
23147 +       __VCMD(enter_space_v1,   5, VCA_VXI,    VCF_ADMIN);
23148 +       __VCMD(enter_space,      5, VCA_VXI,    VCF_ADMIN);
23149 +
23150 +       __VCMD(net_create_v0,    5, VCA_NONE,   0);
23151 +       __VCMD(net_create,       5, VCA_NONE,   0);
23152 +       __VCMD(net_migrate,      5, VCA_NXI,    VCF_ADMIN);
23153 +
23154 +       __VCMD(tag_migrate,      5, VCA_NONE,   VCF_ADMIN);
23155 +
23156 +       /* higher admin commands */
23157 +       __VCMD(ctx_kill,         6, VCA_VXI,    VCF_ARES);
23158 +       __VCMD(set_space_v1,     7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23159 +       __VCMD(set_space,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23160 +
23161 +       __VCMD(set_ccaps,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23162 +       __VCMD(set_bcaps,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23163 +       __VCMD(set_cflags,       7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23164 +       __VCMD(set_umask,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23165 +       __VCMD(set_wmask,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23166 +       __VCMD(set_badness,      7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23167 +
23168 +       __VCMD(set_vhi_name,     7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23169 +       __VCMD(set_rlimit,       7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23170 +       __VCMD(set_prio_bias,    7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23171 +
23172 +       __VCMD(set_ncaps,        7, VCA_NXI,    VCF_ARES | VCF_SETUP);
23173 +       __VCMD(set_nflags,       7, VCA_NXI,    VCF_ARES | VCF_SETUP);
23174 +       __VCMD(net_add,          8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23175 +       __VCMD(net_remove,       8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23176 +       __VCMD(net_add_ipv4_v1,  8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23177 +       __VCMD(net_rem_ipv4_v1,  8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23178 +       __VCMD(net_add_ipv4,     8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23179 +       __VCMD(net_rem_ipv4,     8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23180 +#ifdef CONFIG_IPV6
23181 +       __VCMD(net_add_ipv6,     8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23182 +       __VCMD(net_remove_ipv6,  8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23183 +#endif
23184 +       __VCMD(set_iattr,        7, VCA_NONE,   0);
23185 +       __VCMD(fset_iattr,       7, VCA_NONE,   0);
23186 +       __VCMD(set_dlimit,       7, VCA_NONE,   VCF_ARES);
23187 +       __VCMD(add_dlimit,       8, VCA_NONE,   VCF_ARES);
23188 +       __VCMD(rem_dlimit,       8, VCA_NONE,   VCF_ARES);
23189 +
23190 +#ifdef CONFIG_VSERVER_DEVICE
23191 +       __VCMD(set_mapping,      8, VCA_VXI,    VCF_ARES|VCF_ZIDOK);
23192 +       __VCMD(unset_mapping,    8, VCA_VXI,    VCF_ARES|VCF_ZIDOK);
23193 +#endif
23194 +       /* debug level admin commands */
23195 +#ifdef CONFIG_VSERVER_HISTORY
23196 +       __VCMD(dump_history,     9, VCA_NONE,   0);
23197 +       __VCMD(read_history,     9, VCA_NONE,   0);
23198 +#endif
23199 +
23200 +       default:
23201 +               perm = -1;
23202 +       }
23203 +
23204 +       vxdprintk(VXD_CBIT(switch, 0),
23205 +               "vc: VCMD_%02d_%d[%d], %d,%p [%d,%d,%x,%x]",
23206 +               VC_CATEGORY(cmd), VC_COMMAND(cmd),
23207 +               VC_VERSION(cmd), id, data, compat,
23208 +               perm, args, flags);
23209 +
23210 +       ret = -ENOSYS;
23211 +       if (perm < 0)
23212 +               goto out;
23213 +
23214 +       state = 1;
23215 +       if (!capable(CAP_CONTEXT))
23216 +               goto out;
23217 +
23218 +       state = 2;
23219 +       /* moved here from the individual commands */
23220 +       ret = -EPERM;
23221 +       if ((perm > 1) && !capable(CAP_SYS_ADMIN))
23222 +               goto out;
23223 +
23224 +       state = 3;
23225 +       /* vcmd involves resource management  */
23226 +       ret = -EPERM;
23227 +       if ((flags & VCF_ARES) && !capable(CAP_SYS_RESOURCE))
23228 +               goto out;
23229 +
23230 +       state = 4;
23231 +       /* various legacy exceptions */
23232 +       switch (cmd) {
23233 +       /* will go away when spectator is a cap */
23234 +       case VCMD_ctx_migrate_v0:
23235 +       case VCMD_ctx_migrate:
23236 +               if (id == 1) {
23237 +                       current->xid = 1;
23238 +                       ret = 1;
23239 +                       goto out;
23240 +               }
23241 +               break;
23242 +
23243 +       /* will go away when spectator is a cap */
23244 +       case VCMD_net_migrate:
23245 +               if (id == 1) {
23246 +                       current->nid = 1;
23247 +                       ret = 1;
23248 +                       goto out;
23249 +               }
23250 +               break;
23251 +       }
23252 +
23253 +       /* vcmds are fine by default */
23254 +       permit = 1;
23255 +
23256 +       /* admin type vcmds require admin ... */
23257 +       if (flags & VCF_ADMIN)
23258 +               permit = vx_check(0, VS_ADMIN) ? 1 : 0;
23259 +
23260 +       /* ... but setup type vcmds override that */
23261 +       if (!permit && (flags & VCF_SETUP))
23262 +               permit = vx_flags(VXF_STATE_SETUP, 0) ? 2 : 0;
23263 +
23264 +       state = 5;
23265 +       ret = -EPERM;
23266 +       if (!permit)
23267 +               goto out;
23268 +
23269 +       state = 6;
23270 +       if (!id && (flags & VCF_ZIDOK))
23271 +               goto skip_id;
23272 +
23273 +       ret = -ESRCH;
23274 +       if (args & VCA_VXI) {
23275 +               vxi = lookup_vx_info(id);
23276 +               if (!vxi)
23277 +                       goto out;
23278 +
23279 +               if ((flags & VCF_ADMIN) &&
23280 +                       /* special case kill for shutdown */
23281 +                       (cmd != VCMD_ctx_kill) &&
23282 +                       /* can context be administrated? */
23283 +                       !vx_info_flags(vxi, VXF_STATE_ADMIN, 0)) {
23284 +                       ret = -EACCES;
23285 +                       goto out_vxi;
23286 +               }
23287 +       }
23288 +       state = 7;
23289 +       if (args & VCA_NXI) {
23290 +               nxi = lookup_nx_info(id);
23291 +               if (!nxi)
23292 +                       goto out_vxi;
23293 +
23294 +               if ((flags & VCF_ADMIN) &&
23295 +                       /* can context be administrated? */
23296 +                       !nx_info_flags(nxi, NXF_STATE_ADMIN, 0)) {
23297 +                       ret = -EACCES;
23298 +                       goto out_nxi;
23299 +               }
23300 +       }
23301 +skip_id:
23302 +       state = 8;
23303 +       ret = do_vcmd(cmd, id, vxi, nxi, data, compat);
23304 +
23305 +out_nxi:
23306 +       if ((args & VCA_NXI) && nxi)
23307 +               put_nx_info(nxi);
23308 +out_vxi:
23309 +       if ((args & VCA_VXI) && vxi)
23310 +               put_vx_info(vxi);
23311 +out:
23312 +       vxdprintk(VXD_CBIT(switch, 1),
23313 +               "vc: VCMD_%02d_%d[%d] = %08lx(%ld) [%d,%d]",
23314 +               VC_CATEGORY(cmd), VC_COMMAND(cmd),
23315 +               VC_VERSION(cmd), ret, ret, state, permit);
23316 +       return ret;
23317 +}
23318 +
23319 +asmlinkage long
23320 +sys_vserver(uint32_t cmd, uint32_t id, void __user *data)
23321 +{
23322 +       return do_vserver(cmd, id, data, 0);
23323 +}
23324 +
23325 +#ifdef CONFIG_COMPAT
23326 +
23327 +asmlinkage long
23328 +sys32_vserver(uint32_t cmd, uint32_t id, void __user *data)
23329 +{
23330 +       return do_vserver(cmd, id, data, 1);
23331 +}
23332 +
23333 +#endif /* CONFIG_COMPAT */
23334 diff -NurpP --minimal linux-3.9.4/kernel/vserver/sysctl.c linux-3.9.4-vs2.3.6.2/kernel/vserver/sysctl.c
23335 --- linux-3.9.4/kernel/vserver/sysctl.c 1970-01-01 00:00:00.000000000 +0000
23336 +++ linux-3.9.4-vs2.3.6.2/kernel/vserver/sysctl.c       2013-05-31 14:47:11.000000000 +0000
23337 @@ -0,0 +1,247 @@
23338 +/*
23339 + *  kernel/vserver/sysctl.c
23340 + *
23341 + *  Virtual Context Support
23342 + *
23343 + *  Copyright (C) 2004-2007  Herbert Pötzl
23344 + *
23345 + *  V0.01  basic structure
23346 + *
23347 + */
23348 +
23349 +#include <linux/module.h>
23350 +#include <linux/ctype.h>
23351 +#include <linux/sysctl.h>
23352 +#include <linux/parser.h>
23353 +#include <asm/uaccess.h>
23354 +
23355 +enum {
23356 +       CTL_DEBUG_ERROR         = 0,
23357 +       CTL_DEBUG_SWITCH        = 1,
23358 +       CTL_DEBUG_XID,
23359 +       CTL_DEBUG_NID,
23360 +       CTL_DEBUG_TAG,
23361 +       CTL_DEBUG_NET,
23362 +       CTL_DEBUG_LIMIT,
23363 +       CTL_DEBUG_CRES,
23364 +       CTL_DEBUG_DLIM,
23365 +       CTL_DEBUG_QUOTA,
23366 +       CTL_DEBUG_CVIRT,
23367 +       CTL_DEBUG_SPACE,
23368 +       CTL_DEBUG_PERM,
23369 +       CTL_DEBUG_MISC,
23370 +};
23371 +
23372 +
23373 +unsigned int vs_debug_switch   = 0;
23374 +unsigned int vs_debug_xid      = 0;
23375 +unsigned int vs_debug_nid      = 0;
23376 +unsigned int vs_debug_tag      = 0;
23377 +unsigned int vs_debug_net      = 0;
23378 +unsigned int vs_debug_limit    = 0;
23379 +unsigned int vs_debug_cres     = 0;
23380 +unsigned int vs_debug_dlim     = 0;
23381 +unsigned int vs_debug_quota    = 0;
23382 +unsigned int vs_debug_cvirt    = 0;
23383 +unsigned int vs_debug_space    = 0;
23384 +unsigned int vs_debug_perm     = 0;
23385 +unsigned int vs_debug_misc     = 0;
23386 +
23387 +
23388 +static struct ctl_table_header *vserver_table_header;
23389 +static ctl_table vserver_root_table[];
23390 +
23391 +
23392 +void vserver_register_sysctl(void)
23393 +{
23394 +       if (!vserver_table_header) {
23395 +               vserver_table_header = register_sysctl_table(vserver_root_table);
23396 +       }
23397 +
23398 +}
23399 +
23400 +void vserver_unregister_sysctl(void)
23401 +{
23402 +       if (vserver_table_header) {
23403 +               unregister_sysctl_table(vserver_table_header);
23404 +               vserver_table_header = NULL;
23405 +       }
23406 +}
23407 +
23408 +
23409 +static int proc_dodebug(ctl_table *table, int write,
23410 +       void __user *buffer, size_t *lenp, loff_t *ppos)
23411 +{
23412 +       char            tmpbuf[20], *p, c;
23413 +       unsigned int    value;
23414 +       size_t          left, len;
23415 +
23416 +       if ((*ppos && !write) || !*lenp) {
23417 +               *lenp = 0;
23418 +               return 0;
23419 +       }
23420 +
23421 +       left = *lenp;
23422 +
23423 +       if (write) {
23424 +               if (!access_ok(VERIFY_READ, buffer, left))
23425 +                       return -EFAULT;
23426 +               p = (char *)buffer;
23427 +               while (left && __get_user(c, p) >= 0 && isspace(c))
23428 +                       left--, p++;
23429 +               if (!left)
23430 +                       goto done;
23431 +
23432 +               if (left > sizeof(tmpbuf) - 1)
23433 +                       return -EINVAL;
23434 +               if (copy_from_user(tmpbuf, p, left))
23435 +                       return -EFAULT;
23436 +               tmpbuf[left] = '\0';
23437 +
23438 +               for (p = tmpbuf, value = 0; '0' <= *p && *p <= '9'; p++, left--)
23439 +                       value = 10 * value + (*p - '0');
23440 +               if (*p && !isspace(*p))
23441 +                       return -EINVAL;
23442 +               while (left && isspace(*p))
23443 +                       left--, p++;
23444 +               *(unsigned int *)table->data = value;
23445 +       } else {
23446 +               if (!access_ok(VERIFY_WRITE, buffer, left))
23447 +                       return -EFAULT;
23448 +               len = sprintf(tmpbuf, "%d", *(unsigned int *)table->data);
23449 +               if (len > left)
23450 +                       len = left;
23451 +               if (__copy_to_user(buffer, tmpbuf, len))
23452 +                       return -EFAULT;
23453 +               if ((left -= len) > 0) {
23454 +                       if (put_user('\n', (char *)buffer + len))
23455 +                               return -EFAULT;
23456 +                       left--;
23457 +               }
23458 +       }
23459 +
23460 +done:
23461 +       *lenp -= left;
23462 +       *ppos += *lenp;
23463 +       return 0;
23464 +}
23465 +
23466 +static int zero;
23467 +
23468 +#define        CTL_ENTRY(ctl, name)                            \
23469 +       {                                               \
23470 +               .procname       = #name,                \
23471 +               .data           = &vs_ ## name,         \
23472 +               .maxlen         = sizeof(int),          \
23473 +               .mode           = 0644,                 \
23474 +               .proc_handler   = &proc_dodebug,        \
23475 +               .extra1         = &zero,                \
23476 +               .extra2         = &zero,                \
23477 +       }
23478 +
23479 +static ctl_table vserver_debug_table[] = {
23480 +       CTL_ENTRY(CTL_DEBUG_SWITCH,     debug_switch),
23481 +       CTL_ENTRY(CTL_DEBUG_XID,        debug_xid),
23482 +       CTL_ENTRY(CTL_DEBUG_NID,        debug_nid),
23483 +       CTL_ENTRY(CTL_DEBUG_TAG,        debug_tag),
23484 +       CTL_ENTRY(CTL_DEBUG_NET,        debug_net),
23485 +       CTL_ENTRY(CTL_DEBUG_LIMIT,      debug_limit),
23486 +       CTL_ENTRY(CTL_DEBUG_CRES,       debug_cres),
23487 +       CTL_ENTRY(CTL_DEBUG_DLIM,       debug_dlim),
23488 +       CTL_ENTRY(CTL_DEBUG_QUOTA,      debug_quota),
23489 +       CTL_ENTRY(CTL_DEBUG_CVIRT,      debug_cvirt),
23490 +       CTL_ENTRY(CTL_DEBUG_SPACE,      debug_space),
23491 +       CTL_ENTRY(CTL_DEBUG_PERM,       debug_perm),
23492 +       CTL_ENTRY(CTL_DEBUG_MISC,       debug_misc),
23493 +       { 0 }
23494 +};
23495 +
23496 +static ctl_table vserver_root_table[] = {
23497 +       {
23498 +               .procname       = "vserver",
23499 +               .mode           = 0555,
23500 +               .child          = vserver_debug_table
23501 +       },
23502 +       { 0 }
23503 +};
23504 +
23505 +
23506 +static match_table_t tokens = {
23507 +       { CTL_DEBUG_SWITCH,     "switch=%x"     },
23508 +       { CTL_DEBUG_XID,        "xid=%x"        },
23509 +       { CTL_DEBUG_NID,        "nid=%x"        },
23510 +       { CTL_DEBUG_TAG,        "tag=%x"        },
23511 +       { CTL_DEBUG_NET,        "net=%x"        },
23512 +       { CTL_DEBUG_LIMIT,      "limit=%x"      },
23513 +       { CTL_DEBUG_CRES,       "cres=%x"       },
23514 +       { CTL_DEBUG_DLIM,       "dlim=%x"       },
23515 +       { CTL_DEBUG_QUOTA,      "quota=%x"      },
23516 +       { CTL_DEBUG_CVIRT,      "cvirt=%x"      },
23517 +       { CTL_DEBUG_SPACE,      "space=%x"      },
23518 +       { CTL_DEBUG_PERM,       "perm=%x"       },
23519 +       { CTL_DEBUG_MISC,       "misc=%x"       },
23520 +       { CTL_DEBUG_ERROR,      NULL            }
23521 +};
23522 +
23523 +#define        HANDLE_CASE(id, name, val)                              \
23524 +       case CTL_DEBUG_ ## id:                                  \
23525 +               vs_debug_ ## name = val;                        \
23526 +               printk("vs_debug_" #name "=0x%x\n", val);       \
23527 +               break
23528 +
23529 +
23530 +static int __init vs_debug_setup(char *str)
23531 +{
23532 +       char *p;
23533 +       int token;
23534 +
23535 +       printk("vs_debug_setup(%s)\n", str);
23536 +       while ((p = strsep(&str, ",")) != NULL) {
23537 +               substring_t args[MAX_OPT_ARGS];
23538 +               unsigned int value;
23539 +
23540 +               if (!*p)
23541 +                       continue;
23542 +
23543 +               token = match_token(p, tokens, args);
23544 +               value = (token > 0) ? simple_strtoul(args[0].from, NULL, 0) : 0;
23545 +
23546 +               switch (token) {
23547 +               HANDLE_CASE(SWITCH, switch, value);
23548 +               HANDLE_CASE(XID,    xid,    value);
23549 +               HANDLE_CASE(NID,    nid,    value);
23550 +               HANDLE_CASE(TAG,    tag,    value);
23551 +               HANDLE_CASE(NET,    net,    value);
23552 +               HANDLE_CASE(LIMIT,  limit,  value);
23553 +               HANDLE_CASE(CRES,   cres,   value);
23554 +               HANDLE_CASE(DLIM,   dlim,   value);
23555 +               HANDLE_CASE(QUOTA,  quota,  value);
23556 +               HANDLE_CASE(CVIRT,  cvirt,  value);
23557 +               HANDLE_CASE(SPACE,  space,  value);
23558 +               HANDLE_CASE(PERM,   perm,   value);
23559 +               HANDLE_CASE(MISC,   misc,   value);
23560 +               default:
23561 +                       return -EINVAL;
23562 +                       break;
23563 +               }
23564 +       }
23565 +       return 1;
23566 +}
23567 +
23568 +__setup("vsdebug=", vs_debug_setup);
23569 +
23570 +
23571 +
23572 +EXPORT_SYMBOL_GPL(vs_debug_switch);
23573 +EXPORT_SYMBOL_GPL(vs_debug_xid);
23574 +EXPORT_SYMBOL_GPL(vs_debug_nid);
23575 +EXPORT_SYMBOL_GPL(vs_debug_net);
23576 +EXPORT_SYMBOL_GPL(vs_debug_limit);
23577 +EXPORT_SYMBOL_GPL(vs_debug_cres);
23578 +EXPORT_SYMBOL_GPL(vs_debug_dlim);
23579 +EXPORT_SYMBOL_GPL(vs_debug_quota);
23580 +EXPORT_SYMBOL_GPL(vs_debug_cvirt);
23581 +EXPORT_SYMBOL_GPL(vs_debug_space);
23582 +EXPORT_SYMBOL_GPL(vs_debug_perm);
23583 +EXPORT_SYMBOL_GPL(vs_debug_misc);
23584 +
23585 diff -NurpP --minimal linux-3.9.4/kernel/vserver/tag.c linux-3.9.4-vs2.3.6.2/kernel/vserver/tag.c
23586 --- linux-3.9.4/kernel/vserver/tag.c    1970-01-01 00:00:00.000000000 +0000
23587 +++ linux-3.9.4-vs2.3.6.2/kernel/vserver/tag.c  2013-05-31 14:47:11.000000000 +0000
23588 @@ -0,0 +1,63 @@
23589 +/*
23590 + *  linux/kernel/vserver/tag.c
23591 + *
23592 + *  Virtual Server: Shallow Tag Space
23593 + *
23594 + *  Copyright (C) 2007  Herbert Pötzl
23595 + *
23596 + *  V0.01  basic implementation
23597 + *
23598 + */
23599 +
23600 +#include <linux/sched.h>
23601 +#include <linux/vserver/debug.h>
23602 +#include <linux/vs_pid.h>
23603 +#include <linux/vs_tag.h>
23604 +
23605 +#include <linux/vserver/tag_cmd.h>
23606 +
23607 +
23608 +int dx_migrate_task(struct task_struct *p, tag_t tag)
23609 +{
23610 +       if (!p)
23611 +               BUG();
23612 +
23613 +       vxdprintk(VXD_CBIT(tag, 5),
23614 +               "dx_migrate_task(%p[#%d],#%d)", p, p->tag, tag);
23615 +
23616 +       task_lock(p);
23617 +       p->tag = tag;
23618 +       task_unlock(p);
23619 +
23620 +       vxdprintk(VXD_CBIT(tag, 5),
23621 +               "moved task %p into [#%d]", p, tag);
23622 +       return 0;
23623 +}
23624 +
23625 +/* vserver syscall commands below here */
23626 +
23627 +/* taks xid and vx_info functions */
23628 +
23629 +
23630 +int vc_task_tag(uint32_t id)
23631 +{
23632 +       tag_t tag;
23633 +
23634 +       if (id) {
23635 +               struct task_struct *tsk;
23636 +               rcu_read_lock();
23637 +               tsk = find_task_by_real_pid(id);
23638 +               tag = (tsk) ? tsk->tag : -ESRCH;
23639 +               rcu_read_unlock();
23640 +       } else
23641 +               tag = dx_current_tag();
23642 +       return tag;
23643 +}
23644 +
23645 +
23646 +int vc_tag_migrate(uint32_t tag)
23647 +{
23648 +       return dx_migrate_task(current, tag & 0xFFFF);
23649 +}
23650 +
23651 +
23652 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
23653 --- linux-3.9.4/kernel/vserver/vci_config.h     1970-01-01 00:00:00.000000000 +0000
23654 +++ linux-3.9.4-vs2.3.6.2/kernel/vserver/vci_config.h   2013-05-31 14:47:11.000000000 +0000
23655 @@ -0,0 +1,80 @@
23656 +
23657 +/*  interface version */
23658 +
23659 +#define VCI_VERSION            0x00020308
23660 +
23661 +
23662 +enum {
23663 +       VCI_KCBIT_NO_DYNAMIC = 0,
23664 +
23665 +       VCI_KCBIT_PROC_SECURE = 4,
23666 +       /* VCI_KCBIT_HARDCPU = 5, */
23667 +       /* VCI_KCBIT_IDLELIMIT = 6, */
23668 +       /* VCI_KCBIT_IDLETIME = 7, */
23669 +
23670 +       VCI_KCBIT_COWBL = 8,
23671 +       VCI_KCBIT_FULLCOWBL = 9,
23672 +       VCI_KCBIT_SPACES = 10,
23673 +       VCI_KCBIT_NETV2 = 11,
23674 +       VCI_KCBIT_MEMCG = 12,
23675 +       VCI_KCBIT_MEMCG_SWAP = 13,
23676 +
23677 +       VCI_KCBIT_DEBUG = 16,
23678 +       VCI_KCBIT_HISTORY = 20,
23679 +       VCI_KCBIT_TAGGED = 24,
23680 +       VCI_KCBIT_PPTAG = 28,
23681 +
23682 +       VCI_KCBIT_MORE = 31,
23683 +};
23684 +
23685 +
23686 +static inline uint32_t vci_kernel_config(void)
23687 +{
23688 +       return
23689 +       (1 << VCI_KCBIT_NO_DYNAMIC) |
23690 +
23691 +       /* configured features */
23692 +#ifdef CONFIG_VSERVER_PROC_SECURE
23693 +       (1 << VCI_KCBIT_PROC_SECURE) |
23694 +#endif
23695 +#ifdef CONFIG_VSERVER_COWBL
23696 +       (1 << VCI_KCBIT_COWBL) |
23697 +       (1 << VCI_KCBIT_FULLCOWBL) |
23698 +#endif
23699 +       (1 << VCI_KCBIT_SPACES) |
23700 +       (1 << VCI_KCBIT_NETV2) |
23701 +#ifdef CONFIG_MEMCG
23702 +       (1 << VCI_KCBIT_MEMCG) |
23703 +#endif
23704 +#ifdef CONFIG_MEMCG_SWAP
23705 +       (1 << VCI_KCBIT_MEMCG_SWAP) |
23706 +#endif
23707 +
23708 +       /* debug options */
23709 +#ifdef CONFIG_VSERVER_DEBUG
23710 +       (1 << VCI_KCBIT_DEBUG) |
23711 +#endif
23712 +#ifdef CONFIG_VSERVER_HISTORY
23713 +       (1 << VCI_KCBIT_HISTORY) |
23714 +#endif
23715 +
23716 +       /* inode context tagging */
23717 +#if    defined(CONFIG_TAGGING_NONE)
23718 +       (0 << VCI_KCBIT_TAGGED) |
23719 +#elif  defined(CONFIG_TAGGING_UID16)
23720 +       (1 << VCI_KCBIT_TAGGED) |
23721 +#elif  defined(CONFIG_TAGGING_GID16)
23722 +       (2 << VCI_KCBIT_TAGGED) |
23723 +#elif  defined(CONFIG_TAGGING_ID24)
23724 +       (3 << VCI_KCBIT_TAGGED) |
23725 +#elif  defined(CONFIG_TAGGING_INTERN)
23726 +       (4 << VCI_KCBIT_TAGGED) |
23727 +#elif  defined(CONFIG_TAGGING_RUNTIME)
23728 +       (5 << VCI_KCBIT_TAGGED) |
23729 +#else
23730 +       (7 << VCI_KCBIT_TAGGED) |
23731 +#endif
23732 +       (1 << VCI_KCBIT_PPTAG) |
23733 +       0;
23734 +}
23735 +
23736 diff -NurpP --minimal linux-3.9.4/mm/memcontrol.c linux-3.9.4-vs2.3.6.2/mm/memcontrol.c
23737 --- linux-3.9.4/mm/memcontrol.c 2013-05-31 13:45:31.000000000 +0000
23738 +++ linux-3.9.4-vs2.3.6.2/mm/memcontrol.c       2013-05-31 14:47:11.000000000 +0000
23739 @@ -1046,6 +1046,31 @@ struct mem_cgroup *mem_cgroup_from_task(
23740         return mem_cgroup_from_css(task_subsys_state(p, mem_cgroup_subsys_id));
23741  }
23742  
23743 +u64 mem_cgroup_res_read_u64(struct mem_cgroup *mem, int member)
23744 +{
23745 +       return res_counter_read_u64(&mem->res, member);
23746 +}
23747 +
23748 +u64 mem_cgroup_memsw_read_u64(struct mem_cgroup *mem, int member)
23749 +{
23750 +       return res_counter_read_u64(&mem->memsw, member);
23751 +}
23752 +
23753 +s64 mem_cgroup_stat_read_cache(struct mem_cgroup *mem)
23754 +{
23755 +       return mem_cgroup_read_stat(mem, MEM_CGROUP_STAT_CACHE);
23756 +}
23757 +
23758 +s64 mem_cgroup_stat_read_anon(struct mem_cgroup *mem)
23759 +{
23760 +       return mem_cgroup_read_stat(mem, MEM_CGROUP_STAT_RSS);
23761 +}
23762 +
23763 +s64 mem_cgroup_stat_read_mapped(struct mem_cgroup *mem)
23764 +{
23765 +       return mem_cgroup_read_stat(mem, MEM_CGROUP_STAT_FILE_MAPPED);
23766 +}
23767 +
23768  struct mem_cgroup *try_get_mem_cgroup_from_mm(struct mm_struct *mm)
23769  {
23770         struct mem_cgroup *memcg = NULL;
23771 diff -NurpP --minimal linux-3.9.4/mm/oom_kill.c linux-3.9.4-vs2.3.6.2/mm/oom_kill.c
23772 --- linux-3.9.4/mm/oom_kill.c   2013-05-31 13:45:31.000000000 +0000
23773 +++ linux-3.9.4-vs2.3.6.2/mm/oom_kill.c 2013-05-31 14:47:11.000000000 +0000
23774 @@ -35,6 +35,8 @@
23775  #include <linux/freezer.h>
23776  #include <linux/ftrace.h>
23777  #include <linux/ratelimit.h>
23778 +#include <linux/reboot.h>
23779 +#include <linux/vs_context.h>
23780  
23781  #define CREATE_TRACE_POINTS
23782  #include <trace/events/oom.h>
23783 @@ -113,11 +115,18 @@ struct task_struct *find_lock_task_mm(st
23784  static bool oom_unkillable_task(struct task_struct *p,
23785                 const struct mem_cgroup *memcg, const nodemask_t *nodemask)
23786  {
23787 -       if (is_global_init(p))
23788 +       unsigned xid = vx_current_xid();
23789 +
23790 +       /* skip the init task, global and per guest */
23791 +       if (task_is_init(p))
23792                 return true;
23793         if (p->flags & PF_KTHREAD)
23794                 return true;
23795  
23796 +       /* skip other guest and host processes if oom in guest */
23797 +       if (xid && vx_task_xid(p) != xid)
23798 +               return true;
23799 +
23800         /* When mem_cgroup_out_of_memory() and p is not member of the group */
23801         if (memcg && !task_in_mem_cgroup(p, memcg))
23802                 return true;
23803 @@ -426,8 +435,8 @@ void oom_kill_process(struct task_struct
23804                 dump_header(p, gfp_mask, order, memcg, nodemask);
23805  
23806         task_lock(p);
23807 -       pr_err("%s: Kill process %d (%s) score %d or sacrifice child\n",
23808 -               message, task_pid_nr(p), p->comm, points);
23809 +       pr_err("%s: Kill process %d:#%u (%s) score %d or sacrifice child\n",
23810 +               message, task_pid_nr(p), p->xid, p->comm, points);
23811         task_unlock(p);
23812  
23813         /*
23814 @@ -472,8 +481,8 @@ void oom_kill_process(struct task_struct
23815  
23816         /* mm cannot safely be dereferenced after task_unlock(victim) */
23817         mm = victim->mm;
23818 -       pr_err("Killed process %d (%s) total-vm:%lukB, anon-rss:%lukB, file-rss:%lukB\n",
23819 -               task_pid_nr(victim), victim->comm, K(victim->mm->total_vm),
23820 +       pr_err("Killed process %d:#%u (%s) total-vm:%lukB, anon-rss:%lukB, file-rss:%lukB\n",
23821 +               task_pid_nr(victim), victim->xid, victim->comm, K(victim->mm->total_vm),
23822                 K(get_mm_counter(victim->mm, MM_ANONPAGES)),
23823                 K(get_mm_counter(victim->mm, MM_FILEPAGES)));
23824         task_unlock(victim);
23825 @@ -543,6 +552,8 @@ int unregister_oom_notifier(struct notif
23826  }
23827  EXPORT_SYMBOL_GPL(unregister_oom_notifier);
23828  
23829 +long vs_oom_action(unsigned int);
23830 +
23831  /*
23832   * Try to acquire the OOM killer lock for the zones in zonelist.  Returns zero
23833   * if a parallel OOM killing is already taking place that includes a zone in
23834 @@ -655,7 +666,12 @@ void out_of_memory(struct zonelist *zone
23835         /* Found nothing?!?! Either we hang forever, or we panic. */
23836         if (!p) {
23837                 dump_header(NULL, gfp_mask, order, NULL, mpol_mask);
23838 -               panic("Out of memory and no killable processes...\n");
23839 +
23840 +               /* avoid panic for guest OOM */
23841 +               if (vx_current_xid())
23842 +                       vs_oom_action(LINUX_REBOOT_CMD_OOM);
23843 +               else
23844 +                       panic("Out of memory and no killable processes...\n");
23845         }
23846         if (PTR_ERR(p) != -1UL) {
23847                 oom_kill_process(p, gfp_mask, order, points, totalpages, NULL,
23848 diff -NurpP --minimal linux-3.9.4/mm/page_alloc.c linux-3.9.4-vs2.3.6.2/mm/page_alloc.c
23849 --- linux-3.9.4/mm/page_alloc.c 2013-05-31 13:45:31.000000000 +0000
23850 +++ linux-3.9.4-vs2.3.6.2/mm/page_alloc.c       2013-05-31 15:08:50.000000000 +0000
23851 @@ -59,6 +59,8 @@
23852  #include <linux/migrate.h>
23853  #include <linux/page-debug-flags.h>
23854  #include <linux/sched/rt.h>
23855 +#include <linux/vs_base.h>
23856 +#include <linux/vs_limit.h>
23857  
23858  #include <asm/tlbflush.h>
23859  #include <asm/div64.h>
23860 @@ -2873,6 +2875,9 @@ void si_meminfo(struct sysinfo *val)
23861         val->totalhigh = totalhigh_pages;
23862         val->freehigh = nr_free_highpages();
23863         val->mem_unit = PAGE_SIZE;
23864 +
23865 +       if (vx_flags(VXF_VIRT_MEM, 0))
23866 +               vx_vsi_meminfo(val);
23867  }
23868  
23869  EXPORT_SYMBOL(si_meminfo);
23870 @@ -2893,6 +2898,9 @@ void si_meminfo_node(struct sysinfo *val
23871         val->freehigh = 0;
23872  #endif
23873         val->mem_unit = PAGE_SIZE;
23874 +
23875 +       if (vx_flags(VXF_VIRT_MEM, 0))
23876 +               vx_vsi_meminfo(val);
23877  }
23878  #endif
23879  
23880 diff -NurpP --minimal linux-3.9.4/mm/pgtable-generic.c linux-3.9.4-vs2.3.6.2/mm/pgtable-generic.c
23881 --- linux-3.9.4/mm/pgtable-generic.c    2013-02-19 13:58:57.000000000 +0000
23882 +++ linux-3.9.4-vs2.3.6.2/mm/pgtable-generic.c  2013-05-31 14:47:11.000000000 +0000
23883 @@ -6,6 +6,8 @@
23884   *  Copyright (C) 2010  Linus Torvalds
23885   */
23886  
23887 +#include <linux/mm.h>
23888 +
23889  #include <linux/pagemap.h>
23890  #include <asm/tlb.h>
23891  #include <asm-generic/pgtable.h>
23892 diff -NurpP --minimal linux-3.9.4/mm/shmem.c linux-3.9.4-vs2.3.6.2/mm/shmem.c
23893 --- linux-3.9.4/mm/shmem.c      2013-05-31 13:45:31.000000000 +0000
23894 +++ linux-3.9.4-vs2.3.6.2/mm/shmem.c    2013-05-31 14:47:11.000000000 +0000
23895 @@ -1909,7 +1909,7 @@ static int shmem_statfs(struct dentry *d
23896  {
23897         struct shmem_sb_info *sbinfo = SHMEM_SB(dentry->d_sb);
23898  
23899 -       buf->f_type = TMPFS_MAGIC;
23900 +       buf->f_type = TMPFS_SUPER_MAGIC;
23901         buf->f_bsize = PAGE_CACHE_SIZE;
23902         buf->f_namelen = NAME_MAX;
23903         if (sbinfo->max_blocks) {
23904 @@ -2606,7 +2606,7 @@ int shmem_fill_super(struct super_block
23905         sb->s_maxbytes = MAX_LFS_FILESIZE;
23906         sb->s_blocksize = PAGE_CACHE_SIZE;
23907         sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
23908 -       sb->s_magic = TMPFS_MAGIC;
23909 +       sb->s_magic = TMPFS_SUPER_MAGIC;
23910         sb->s_op = &shmem_ops;
23911         sb->s_time_gran = 1;
23912  #ifdef CONFIG_TMPFS_XATTR
23913 diff -NurpP --minimal linux-3.9.4/mm/slab.c linux-3.9.4-vs2.3.6.2/mm/slab.c
23914 --- linux-3.9.4/mm/slab.c       2013-05-31 13:45:31.000000000 +0000
23915 +++ linux-3.9.4-vs2.3.6.2/mm/slab.c     2013-05-31 14:47:11.000000000 +0000
23916 @@ -429,6 +429,8 @@ static void kmem_list3_init(struct kmem_
23917  #define STATS_INC_FREEMISS(x)  do { } while (0)
23918  #endif
23919  
23920 +#include "slab_vs.h"
23921 +
23922  #if DEBUG
23923  
23924  /*
23925 @@ -3438,6 +3440,7 @@ retry:
23926  
23927         obj = slab_get_obj(cachep, slabp, nodeid);
23928         check_slabp(cachep, slabp);
23929 +       vx_slab_alloc(cachep, flags);
23930         l3->free_objects--;
23931         /* move slabp to correct slabp list: */
23932         list_del(&slabp->list);
23933 @@ -3517,6 +3520,7 @@ slab_alloc_node(struct kmem_cache *cache
23934         /* ___cache_alloc_node can fall back to other nodes */
23935         ptr = ____cache_alloc_node(cachep, flags, nodeid);
23936    out:
23937 +       vx_slab_alloc(cachep, flags);
23938         local_irq_restore(save_flags);
23939         ptr = cache_alloc_debugcheck_after(cachep, flags, ptr, caller);
23940         kmemleak_alloc_recursive(ptr, cachep->object_size, 1, cachep->flags,
23941 @@ -3709,6 +3713,7 @@ static inline void __cache_free(struct k
23942         check_irq_off();
23943         kmemleak_free_recursive(objp, cachep->flags);
23944         objp = cache_free_debugcheck(cachep, objp, caller);
23945 +       vx_slab_free(cachep);
23946  
23947         kmemcheck_slab_free(cachep, objp, cachep->object_size);
23948  
23949 diff -NurpP --minimal linux-3.9.4/mm/slab_vs.h linux-3.9.4-vs2.3.6.2/mm/slab_vs.h
23950 --- linux-3.9.4/mm/slab_vs.h    1970-01-01 00:00:00.000000000 +0000
23951 +++ linux-3.9.4-vs2.3.6.2/mm/slab_vs.h  2013-05-31 14:47:11.000000000 +0000
23952 @@ -0,0 +1,29 @@
23953 +
23954 +#include <linux/vserver/context.h>
23955 +
23956 +#include <linux/vs_context.h>
23957 +
23958 +static inline
23959 +void vx_slab_alloc(struct kmem_cache *cachep, gfp_t flags)
23960 +{
23961 +       int what = gfp_zone(cachep->allocflags);
23962 +       struct vx_info *vxi = current_vx_info();
23963 +
23964 +       if (!vxi)
23965 +               return;
23966 +
23967 +       atomic_add(cachep->size, &vxi->cacct.slab[what]);
23968 +}
23969 +
23970 +static inline
23971 +void vx_slab_free(struct kmem_cache *cachep)
23972 +{
23973 +       int what = gfp_zone(cachep->allocflags);
23974 +       struct vx_info *vxi = current_vx_info();
23975 +
23976 +       if (!vxi)
23977 +               return;
23978 +
23979 +       atomic_sub(cachep->size, &vxi->cacct.slab[what]);
23980 +}
23981 +
23982 diff -NurpP --minimal linux-3.9.4/mm/swapfile.c linux-3.9.4-vs2.3.6.2/mm/swapfile.c
23983 --- linux-3.9.4/mm/swapfile.c   2013-05-31 13:45:31.000000000 +0000
23984 +++ linux-3.9.4-vs2.3.6.2/mm/swapfile.c 2013-05-31 14:47:11.000000000 +0000
23985 @@ -39,6 +39,7 @@
23986  #include <asm/tlbflush.h>
23987  #include <linux/swapops.h>
23988  #include <linux/page_cgroup.h>
23989 +#include <linux/vs_base.h>
23990  
23991  static bool swap_count_continued(struct swap_info_struct *, pgoff_t,
23992                                  unsigned char);
23993 @@ -1767,6 +1768,16 @@ static int swap_show(struct seq_file *sw
23994  
23995         if (si == SEQ_START_TOKEN) {
23996                 seq_puts(swap,"Filename\t\t\t\tType\t\tSize\tUsed\tPriority\n");
23997 +               if (vx_flags(VXF_VIRT_MEM, 0)) {
23998 +                       struct sysinfo si;
23999 +
24000 +                       vx_vsi_swapinfo(&si);
24001 +                       if (si.totalswap < (1 << 10))
24002 +                               return 0;
24003 +                       seq_printf(swap, "%s\t\t\t\t\t%s\t%lu\t%lu\t%d\n",
24004 +                               "hdv0", "partition", si.totalswap >> 10,
24005 +                               (si.totalswap - si.freeswap) >> 10, -1);
24006 +               }
24007                 return 0;
24008         }
24009  
24010 @@ -2195,6 +2206,8 @@ void si_swapinfo(struct sysinfo *val)
24011         val->freeswap = atomic_long_read(&nr_swap_pages) + nr_to_be_unused;
24012         val->totalswap = total_swap_pages + nr_to_be_unused;
24013         spin_unlock(&swap_lock);
24014 +       if (vx_flags(VXF_VIRT_MEM, 0))
24015 +               vx_vsi_swapinfo(val);
24016  }
24017  
24018  /*
24019 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
24020 --- linux-3.9.4/net/bridge/br_multicast.c       2013-05-31 13:45:31.000000000 +0000
24021 +++ linux-3.9.4-vs2.3.6.2/net/bridge/br_multicast.c     2013-05-31 17:17:53.000000000 +0000
24022 @@ -443,7 +443,7 @@ static struct sk_buff *br_ip6_multicast_
24023         ip6h->hop_limit = 1;
24024         ipv6_addr_set(&ip6h->daddr, htonl(0xff020000), 0, 0, htonl(1));
24025         if (ipv6_dev_get_saddr(dev_net(br->dev), br->dev, &ip6h->daddr, 0,
24026 -                              &ip6h->saddr)) {
24027 +                              &ip6h->saddr, NULL)) {
24028                 kfree_skb(skb);
24029                 return NULL;
24030         }
24031 diff -NurpP --minimal linux-3.9.4/net/core/dev.c linux-3.9.4-vs2.3.6.2/net/core/dev.c
24032 --- linux-3.9.4/net/core/dev.c  2013-05-31 14:22:27.000000000 +0000
24033 +++ linux-3.9.4-vs2.3.6.2/net/core/dev.c        2013-05-31 18:37:38.000000000 +0000
24034 @@ -122,6 +122,7 @@
24035  #include <linux/in.h>
24036  #include <linux/jhash.h>
24037  #include <linux/random.h>
24038 +#include <linux/vs_inet.h>
24039  #include <trace/events/napi.h>
24040  #include <trace/events/net.h>
24041  #include <trace/events/skb.h>
24042 @@ -662,7 +663,8 @@ struct net_device *__dev_get_by_name(str
24043         struct hlist_head *head = dev_name_hash(net, name);
24044  
24045         hlist_for_each_entry(dev, head, name_hlist)
24046 -               if (!strncmp(dev->name, name, IFNAMSIZ))
24047 +               if (!strncmp(dev->name, name, IFNAMSIZ) &&
24048 +                   nx_dev_visible(current_nx_info(), dev))
24049                         return dev;
24050  
24051         return NULL;
24052 @@ -687,7 +689,8 @@ struct net_device *dev_get_by_name_rcu(s
24053         struct hlist_head *head = dev_name_hash(net, name);
24054  
24055         hlist_for_each_entry_rcu(dev, head, name_hlist)
24056 -               if (!strncmp(dev->name, name, IFNAMSIZ))
24057 +               if (!strncmp(dev->name, name, IFNAMSIZ) &&
24058 +                   nx_dev_visible(current_nx_info(), dev))
24059                         return dev;
24060  
24061         return NULL;
24062 @@ -737,7 +740,8 @@ struct net_device *__dev_get_by_index(st
24063         struct hlist_head *head = dev_index_hash(net, ifindex);
24064  
24065         hlist_for_each_entry(dev, head, index_hlist)
24066 -               if (dev->ifindex == ifindex)
24067 +               if ((dev->ifindex == ifindex) &&
24068 +                   nx_dev_visible(current_nx_info(), dev))
24069                         return dev;
24070  
24071         return NULL;
24072 @@ -755,7 +759,7 @@ EXPORT_SYMBOL(__dev_get_by_index);
24073   *     about locking. The caller must hold RCU lock.
24074   */
24075  
24076 -struct net_device *dev_get_by_index_rcu(struct net *net, int ifindex)
24077 +struct net_device *dev_get_by_index_real_rcu(struct net *net, int ifindex)
24078  {
24079         struct net_device *dev;
24080         struct hlist_head *head = dev_index_hash(net, ifindex);
24081 @@ -766,6 +770,16 @@ struct net_device *dev_get_by_index_rcu(
24082  
24083         return NULL;
24084  }
24085 +EXPORT_SYMBOL(dev_get_by_index_real_rcu);
24086 +
24087 +struct net_device *dev_get_by_index_rcu(struct net *net, int ifindex)
24088 +{
24089 +       struct net_device *dev = dev_get_by_index_real_rcu(net, ifindex);
24090 +
24091 +       if (nx_dev_visible(current_nx_info(), dev))
24092 +               return dev;
24093 +       return NULL;
24094 +}
24095  EXPORT_SYMBOL(dev_get_by_index_rcu);
24096  
24097  
24098 @@ -814,7 +828,8 @@ struct net_device *dev_getbyhwaddr_rcu(s
24099  
24100         for_each_netdev_rcu(net, dev)
24101                 if (dev->type == type &&
24102 -                   !memcmp(dev->dev_addr, ha, dev->addr_len))
24103 +                   !memcmp(dev->dev_addr, ha, dev->addr_len) &&
24104 +                   nx_dev_visible(current_nx_info(), dev))
24105                         return dev;
24106  
24107         return NULL;
24108 @@ -826,9 +841,11 @@ struct net_device *__dev_getfirstbyhwtyp
24109         struct net_device *dev;
24110  
24111         ASSERT_RTNL();
24112 -       for_each_netdev(net, dev)
24113 -               if (dev->type == type)
24114 +       for_each_netdev(net, dev) {
24115 +               if ((dev->type == type) &&
24116 +                   nx_dev_visible(current_nx_info(), dev))
24117                         return dev;
24118 +       }
24119  
24120         return NULL;
24121  }
24122 @@ -840,7 +857,8 @@ struct net_device *dev_getfirstbyhwtype(
24123  
24124         rcu_read_lock();
24125         for_each_netdev_rcu(net, dev)
24126 -               if (dev->type == type) {
24127 +               if ((dev->type == type) &&
24128 +                   nx_dev_visible(current_nx_info(), dev)) {
24129                         dev_hold(dev);
24130                         ret = dev;
24131                         break;
24132 @@ -868,7 +886,8 @@ struct net_device *dev_get_by_flags_rcu(
24133  
24134         ret = NULL;
24135         for_each_netdev_rcu(net, dev) {
24136 -               if (((dev->flags ^ if_flags) & mask) == 0) {
24137 +               if ((((dev->flags ^ if_flags) & mask) == 0) &&
24138 +                       nx_dev_visible(current_nx_info(), dev)) {
24139                         ret = dev;
24140                         break;
24141                 }
24142 @@ -946,6 +965,8 @@ static int __dev_alloc_name(struct net *
24143                                 continue;
24144                         if (i < 0 || i >= max_netdevices)
24145                                 continue;
24146 +                       if (!nx_dev_visible(current_nx_info(), d))
24147 +                               continue;
24148  
24149                         /*  avoid cases where sscanf is not exact inverse of printf */
24150                         snprintf(buf, IFNAMSIZ, name, i);
24151 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
24152 --- linux-3.9.4/net/core/net-procfs.c   2013-05-31 13:45:32.000000000 +0000
24153 +++ linux-3.9.4-vs2.3.6.2/net/core/net-procfs.c 2013-06-01 10:40:52.000000000 +0000
24154 @@ -1,6 +1,7 @@
24155  #include <linux/netdevice.h>
24156  #include <linux/proc_fs.h>
24157  #include <linux/seq_file.h>
24158 +#include <linux/vs_inet.h>
24159  #include <net/wext.h>
24160  
24161  #define BUCKET_SPACE (32 - NETDEV_HASHBITS - 1)
24162 @@ -77,8 +78,13 @@ static void dev_seq_stop(struct seq_file
24163  static void dev_seq_printf_stats(struct seq_file *seq, struct net_device *dev)
24164  {
24165         struct rtnl_link_stats64 temp;
24166 -       const struct rtnl_link_stats64 *stats = dev_get_stats(dev, &temp);
24167 +       const struct rtnl_link_stats64 *stats;
24168 +
24169 +       /* device visible inside network context? */
24170 +       if (!nx_dev_visible(current_nx_info(), dev))
24171 +               return;
24172  
24173 +       stats = dev_get_stats(dev, &temp);
24174         seq_printf(seq, "%6s: %7llu %7llu %4llu %4llu %4llu %5llu %10llu %9llu "
24175                    "%8llu %7llu %4llu %4llu %4llu %5llu %7llu %10llu\n",
24176                    dev->name, stats->rx_bytes, stats->rx_packets,
24177 diff -NurpP --minimal linux-3.9.4/net/core/rtnetlink.c linux-3.9.4-vs2.3.6.2/net/core/rtnetlink.c
24178 --- linux-3.9.4/net/core/rtnetlink.c    2013-05-31 13:45:32.000000000 +0000
24179 +++ linux-3.9.4-vs2.3.6.2/net/core/rtnetlink.c  2013-05-31 17:17:54.000000000 +0000
24180 @@ -1085,6 +1085,8 @@ static int rtnl_dump_ifinfo(struct sk_bu
24181                 hlist_for_each_entry_rcu(dev, head, index_hlist) {
24182                         if (idx < s_idx)
24183                                 goto cont;
24184 +                       if (!nx_dev_visible(skb->sk->sk_nx_info, dev))
24185 +                               continue;
24186                         if (rtnl_fill_ifinfo(skb, dev, RTM_NEWLINK,
24187                                              NETLINK_CB(cb->skb).portid,
24188                                              cb->nlh->nlmsg_seq, 0,
24189 @@ -1974,6 +1976,9 @@ void rtmsg_ifinfo(int type, struct net_d
24190         int err = -ENOBUFS;
24191         size_t if_info_size;
24192  
24193 +       if (!nx_dev_visible(current_nx_info(), dev))
24194 +               return;
24195 +
24196         skb = nlmsg_new((if_info_size = if_nlmsg_size(dev, 0)), GFP_KERNEL);
24197         if (skb == NULL)
24198                 goto errout;
24199 diff -NurpP --minimal linux-3.9.4/net/core/sock.c linux-3.9.4-vs2.3.6.2/net/core/sock.c
24200 --- linux-3.9.4/net/core/sock.c 2013-05-31 14:22:27.000000000 +0000
24201 +++ linux-3.9.4-vs2.3.6.2/net/core/sock.c       2013-05-31 17:17:54.000000000 +0000
24202 @@ -132,6 +132,10 @@
24203  #include <net/netprio_cgroup.h>
24204  
24205  #include <linux/filter.h>
24206 +#include <linux/vs_socket.h>
24207 +#include <linux/vs_limit.h>
24208 +#include <linux/vs_context.h>
24209 +#include <linux/vs_network.h>
24210  
24211  #include <trace/events/sock.h>
24212  
24213 @@ -1257,6 +1261,8 @@ static struct sock *sk_prot_alloc(struct
24214                         goto out_free_sec;
24215                 sk_tx_queue_clear(sk);
24216         }
24217 +               sock_vx_init(sk);
24218 +               sock_nx_init(sk);
24219  
24220         return sk;
24221  
24222 @@ -1367,6 +1373,11 @@ static void __sk_free(struct sock *sk)
24223                 put_cred(sk->sk_peer_cred);
24224         put_pid(sk->sk_peer_pid);
24225         put_net(sock_net(sk));
24226 +       vx_sock_dec(sk);
24227 +       clr_vx_info(&sk->sk_vx_info);
24228 +       sk->sk_xid = -1;
24229 +       clr_nx_info(&sk->sk_nx_info);
24230 +       sk->sk_nid = -1;
24231         sk_prot_free(sk->sk_prot_creator, sk);
24232  }
24233  
24234 @@ -1427,6 +1438,8 @@ struct sock *sk_clone_lock(const struct
24235  
24236                 /* SANITY */
24237                 get_net(sock_net(newsk));
24238 +               sock_vx_init(newsk);
24239 +               sock_nx_init(newsk);
24240                 sk_node_init(&newsk->sk_node);
24241                 sock_lock_init(newsk);
24242                 bh_lock_sock(newsk);
24243 @@ -1483,6 +1496,12 @@ struct sock *sk_clone_lock(const struct
24244                 smp_wmb();
24245                 atomic_set(&newsk->sk_refcnt, 2);
24246  
24247 +               set_vx_info(&newsk->sk_vx_info, sk->sk_vx_info);
24248 +               newsk->sk_xid = sk->sk_xid;
24249 +               vx_sock_inc(newsk);
24250 +               set_nx_info(&newsk->sk_nx_info, sk->sk_nx_info);
24251 +               newsk->sk_nid = sk->sk_nid;
24252 +
24253                 /*
24254                  * Increment the counter in the same struct proto as the master
24255                  * sock (sk_refcnt_debug_inc uses newsk->sk_prot->socks, that
24256 @@ -2278,6 +2297,12 @@ void sock_init_data(struct socket *sock,
24257  
24258         sk->sk_stamp = ktime_set(-1L, 0);
24259  
24260 +       set_vx_info(&sk->sk_vx_info, current_vx_info());
24261 +       sk->sk_xid = vx_current_xid();
24262 +       vx_sock_inc(sk);
24263 +       set_nx_info(&sk->sk_nx_info, current_nx_info());
24264 +       sk->sk_nid = nx_current_nid();
24265 +
24266         /*
24267          * Before updating sk_refcnt, we must commit prior changes to memory
24268          * (Documentation/RCU/rculist_nulls.txt for details)
24269 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
24270 --- linux-3.9.4/net/ipv4/af_inet.c      2013-05-31 13:45:32.000000000 +0000
24271 +++ linux-3.9.4-vs2.3.6.2/net/ipv4/af_inet.c    2013-05-31 18:24:05.000000000 +0000
24272 @@ -118,6 +118,7 @@
24273  #ifdef CONFIG_IP_MROUTE
24274  #include <linux/mroute.h>
24275  #endif
24276 +#include <linux/vs_limit.h>
24277  
24278  
24279  /* The inetsw table contains everything that inet_create needs to
24280 @@ -336,6 +337,10 @@ lookup_protocol:
24281         }
24282  
24283         err = -EPERM;
24284 +       if ((protocol == IPPROTO_ICMP) &&
24285 +               nx_capable(CAP_NET_RAW, NXC_RAW_ICMP))
24286 +               goto override;
24287 +override:
24288         if (sock->type == SOCK_RAW && !kern &&
24289             !ns_capable(net->user_ns, CAP_NET_RAW))
24290                 goto out_rcu_unlock;
24291 @@ -460,6 +465,7 @@ int inet_bind(struct socket *sock, struc
24292         struct sockaddr_in *addr = (struct sockaddr_in *)uaddr;
24293         struct sock *sk = sock->sk;
24294         struct inet_sock *inet = inet_sk(sk);
24295 +       struct nx_v4_sock_addr nsa;
24296         struct net *net = sock_net(sk);
24297         unsigned short snum;
24298         int chk_addr_ret;
24299 @@ -484,7 +490,11 @@ int inet_bind(struct socket *sock, struc
24300                         goto out;
24301         }
24302  
24303 -       chk_addr_ret = inet_addr_type(net, addr->sin_addr.s_addr);
24304 +       err = v4_map_sock_addr(inet, addr, &nsa);
24305 +       if (err)
24306 +               goto out;
24307 +
24308 +       chk_addr_ret = inet_addr_type(net, nsa.saddr);
24309  
24310         /* Not specified by any standard per-se, however it breaks too
24311          * many applications when removed.  It is unfortunate since
24312 @@ -496,7 +506,7 @@ int inet_bind(struct socket *sock, struc
24313         err = -EADDRNOTAVAIL;
24314         if (!sysctl_ip_nonlocal_bind &&
24315             !(inet->freebind || inet->transparent) &&
24316 -           addr->sin_addr.s_addr != htonl(INADDR_ANY) &&
24317 +           nsa.saddr != htonl(INADDR_ANY) &&
24318             chk_addr_ret != RTN_LOCAL &&
24319             chk_addr_ret != RTN_MULTICAST &&
24320             chk_addr_ret != RTN_BROADCAST)
24321 @@ -522,7 +532,7 @@ int inet_bind(struct socket *sock, struc
24322         if (sk->sk_state != TCP_CLOSE || inet->inet_num)
24323                 goto out_release_sock;
24324  
24325 -       inet->inet_rcv_saddr = inet->inet_saddr = addr->sin_addr.s_addr;
24326 +       v4_set_sock_addr(inet, &nsa);
24327         if (chk_addr_ret == RTN_MULTICAST || chk_addr_ret == RTN_BROADCAST)
24328                 inet->inet_saddr = 0;  /* Use device */
24329  
24330 @@ -741,11 +751,13 @@ int inet_getname(struct socket *sock, st
24331                      peer == 1))
24332                         return -ENOTCONN;
24333                 sin->sin_port = inet->inet_dport;
24334 -               sin->sin_addr.s_addr = inet->inet_daddr;
24335 +               sin->sin_addr.s_addr =
24336 +                       nx_map_sock_lback(sk->sk_nx_info, inet->inet_daddr);
24337         } else {
24338                 __be32 addr = inet->inet_rcv_saddr;
24339                 if (!addr)
24340                         addr = inet->inet_saddr;
24341 +               addr = nx_map_sock_lback(sk->sk_nx_info, addr);
24342                 sin->sin_port = inet->inet_sport;
24343                 sin->sin_addr.s_addr = addr;
24344         }
24345 diff -NurpP --minimal linux-3.9.4/net/ipv4/arp.c linux-3.9.4-vs2.3.6.2/net/ipv4/arp.c
24346 --- linux-3.9.4/net/ipv4/arp.c  2013-05-31 13:45:32.000000000 +0000
24347 +++ linux-3.9.4-vs2.3.6.2/net/ipv4/arp.c        2013-05-31 17:17:54.000000000 +0000
24348 @@ -1317,6 +1317,7 @@ static void arp_format_neigh_entry(struc
24349         struct net_device *dev = n->dev;
24350         int hatype = dev->type;
24351  
24352 +       /* FIXME: check for network context */
24353         read_lock(&n->lock);
24354         /* Convert hardware address to XX:XX:XX:XX ... form. */
24355  #if IS_ENABLED(CONFIG_AX25)
24356 @@ -1348,6 +1349,7 @@ static void arp_format_pneigh_entry(stru
24357         int hatype = dev ? dev->type : 0;
24358         char tbuf[16];
24359  
24360 +       /* FIXME: check for network context */
24361         sprintf(tbuf, "%pI4", n->key);
24362         seq_printf(seq, "%-16s 0x%-10x0x%-10x%s     *        %s\n",
24363                    tbuf, hatype, ATF_PUBL | ATF_PERM, "00:00:00:00:00:00",
24364 diff -NurpP --minimal linux-3.9.4/net/ipv4/devinet.c linux-3.9.4-vs2.3.6.2/net/ipv4/devinet.c
24365 --- linux-3.9.4/net/ipv4/devinet.c      2013-05-31 13:45:32.000000000 +0000
24366 +++ linux-3.9.4-vs2.3.6.2/net/ipv4/devinet.c    2013-05-31 17:17:54.000000000 +0000
24367 @@ -522,6 +522,7 @@ struct in_device *inetdev_by_index(struc
24368  }
24369  EXPORT_SYMBOL(inetdev_by_index);
24370  
24371 +
24372  /* Called only from RTNL semaphored context. No locks. */
24373  
24374  struct in_ifaddr *inet_ifa_byprefix(struct in_device *in_dev, __be32 prefix,
24375 @@ -940,6 +941,8 @@ int devinet_ioctl(struct net *net, unsig
24376  
24377         in_dev = __in_dev_get_rtnl(dev);
24378         if (in_dev) {
24379 +               struct nx_info *nxi = current_nx_info();
24380 +
24381                 if (tryaddrmatch) {
24382                         /* Matthias Andree */
24383                         /* compare label and address (4.4BSD style) */
24384 @@ -948,6 +951,8 @@ int devinet_ioctl(struct net *net, unsig
24385                            This is checked above. */
24386                         for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
24387                              ifap = &ifa->ifa_next) {
24388 +                               if (!nx_v4_ifa_visible(nxi, ifa))
24389 +                                       continue;
24390                                 if (!strcmp(ifr.ifr_name, ifa->ifa_label) &&
24391                                     sin_orig.sin_addr.s_addr ==
24392                                                         ifa->ifa_local) {
24393 @@ -960,9 +965,12 @@ int devinet_ioctl(struct net *net, unsig
24394                    comparing just the label */
24395                 if (!ifa) {
24396                         for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
24397 -                            ifap = &ifa->ifa_next)
24398 +                            ifap = &ifa->ifa_next) {
24399 +                               if (!nx_v4_ifa_visible(nxi, ifa))
24400 +                                       continue;
24401                                 if (!strcmp(ifr.ifr_name, ifa->ifa_label))
24402                                         break;
24403 +                       }
24404                 }
24405         }
24406  
24407 @@ -1116,6 +1124,8 @@ static int inet_gifconf(struct net_devic
24408                 goto out;
24409  
24410         for (ifa = in_dev->ifa_list; ifa; ifa = ifa->ifa_next) {
24411 +               if (!nx_v4_ifa_visible(current_nx_info(), ifa))
24412 +                       continue;
24413                 if (!buf) {
24414                         done += sizeof(ifr);
24415                         continue;
24416 @@ -1519,6 +1529,7 @@ static int inet_dump_ifaddr(struct sk_bu
24417         struct net_device *dev;
24418         struct in_device *in_dev;
24419         struct in_ifaddr *ifa;
24420 +       struct sock *sk = skb->sk;
24421         struct hlist_head *head;
24422  
24423         s_h = cb->args[0];
24424 @@ -1540,6 +1551,8 @@ static int inet_dump_ifaddr(struct sk_bu
24425  
24426                         for (ifa = in_dev->ifa_list, ip_idx = 0; ifa;
24427                              ifa = ifa->ifa_next, ip_idx++) {
24428 +                       if (sk && !nx_v4_ifa_visible(sk->sk_nx_info, ifa))
24429 +                               continue;
24430                                 if (ip_idx < s_ip_idx)
24431                                         continue;
24432                                 if (inet_fill_ifaddr(skb, ifa,
24433 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
24434 --- linux-3.9.4/net/ipv4/fib_trie.c     2013-05-31 13:45:32.000000000 +0000
24435 +++ linux-3.9.4-vs2.3.6.2/net/ipv4/fib_trie.c   2013-05-31 17:17:54.000000000 +0000
24436 @@ -2548,6 +2548,7 @@ static int fib_route_seq_show(struct seq
24437                             || fa->fa_type == RTN_MULTICAST)
24438                                 continue;
24439  
24440 +                       /* FIXME: check for network context? */
24441                         if (fi)
24442                                 seq_printf(seq,
24443                                          "%s\t%08X\t%08X\t%04X\t%d\t%u\t"
24444 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
24445 --- linux-3.9.4/net/ipv4/inet_connection_sock.c 2013-05-31 13:45:32.000000000 +0000
24446 +++ linux-3.9.4-vs2.3.6.2/net/ipv4/inet_connection_sock.c       2013-05-31 18:29:56.000000000 +0000
24447 @@ -53,6 +53,37 @@ void inet_get_local_port_range(int *low,
24448  }
24449  EXPORT_SYMBOL(inet_get_local_port_range);
24450  
24451 +int ipv4_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2)
24452 +{
24453 +       __be32  sk1_rcv_saddr = sk_rcv_saddr(sk1),
24454 +               sk2_rcv_saddr = sk_rcv_saddr(sk2);
24455 +
24456 +       if (inet_v6_ipv6only(sk2))
24457 +               return 0;
24458 +
24459 +       if (sk1_rcv_saddr &&
24460 +           sk2_rcv_saddr &&
24461 +           sk1_rcv_saddr == sk2_rcv_saddr)
24462 +               return 1;
24463 +
24464 +       if (sk1_rcv_saddr &&
24465 +           !sk2_rcv_saddr &&
24466 +           v4_addr_in_nx_info(sk2->sk_nx_info, sk1_rcv_saddr, NXA_MASK_BIND))
24467 +               return 1;
24468 +
24469 +       if (sk2_rcv_saddr &&
24470 +           !sk1_rcv_saddr &&
24471 +           v4_addr_in_nx_info(sk1->sk_nx_info, sk2_rcv_saddr, NXA_MASK_BIND))
24472 +               return 1;
24473 +
24474 +       if (!sk1_rcv_saddr &&
24475 +           !sk2_rcv_saddr &&
24476 +           nx_v4_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info))
24477 +               return 1;
24478 +
24479 +       return 0;
24480 +}
24481 +
24482  int inet_csk_bind_conflict(const struct sock *sk,
24483                            const struct inet_bind_bucket *tb, bool relax)
24484  {
24485 @@ -79,17 +110,12 @@ int inet_csk_bind_conflict(const struct
24486                             (!reuseport || !sk2->sk_reuseport ||
24487                             (sk2->sk_state != TCP_TIME_WAIT &&
24488                              !uid_eq(uid, sock_i_uid(sk2))))) {
24489 -                               const __be32 sk2_rcv_saddr = sk_rcv_saddr(sk2);
24490 -                               if (!sk2_rcv_saddr || !sk_rcv_saddr(sk) ||
24491 -                                   sk2_rcv_saddr == sk_rcv_saddr(sk))
24492 +                               if (ipv4_rcv_saddr_equal(sk, sk2))
24493                                         break;
24494                         }
24495                         if (!relax && reuse && sk2->sk_reuse &&
24496                             sk2->sk_state != TCP_LISTEN) {
24497 -                               const __be32 sk2_rcv_saddr = sk_rcv_saddr(sk2);
24498 -
24499 -                               if (!sk2_rcv_saddr || !sk_rcv_saddr(sk) ||
24500 -                                   sk2_rcv_saddr == sk_rcv_saddr(sk))
24501 +                               if (ipv4_rcv_saddr_equal(sk, sk2))
24502                                         break;
24503                         }
24504                 }
24505 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
24506 --- linux-3.9.4/net/ipv4/inet_diag.c    2013-02-19 13:58:58.000000000 +0000
24507 +++ linux-3.9.4-vs2.3.6.2/net/ipv4/inet_diag.c  2013-05-31 17:17:54.000000000 +0000
24508 @@ -31,6 +31,8 @@
24509  
24510  #include <linux/inet.h>
24511  #include <linux/stddef.h>
24512 +#include <linux/vs_network.h>
24513 +#include <linux/vs_inet.h>
24514  
24515  #include <linux/inet_diag.h>
24516  #include <linux/sock_diag.h>
24517 @@ -106,8 +108,10 @@ int inet_sk_diag_fill(struct sock *sk, s
24518  
24519         r->id.idiag_sport = inet->inet_sport;
24520         r->id.idiag_dport = inet->inet_dport;
24521 -       r->id.idiag_src[0] = inet->inet_rcv_saddr;
24522 -       r->id.idiag_dst[0] = inet->inet_daddr;
24523 +       r->id.idiag_src[0] = nx_map_sock_lback(sk->sk_nx_info,
24524 +               inet->inet_rcv_saddr);
24525 +       r->id.idiag_dst[0] = nx_map_sock_lback(sk->sk_nx_info,
24526 +               inet->inet_daddr);
24527  
24528         if (nla_put_u8(skb, INET_DIAG_SHUTDOWN, sk->sk_shutdown))
24529                 goto errout;
24530 @@ -242,8 +246,8 @@ static int inet_twsk_diag_fill(struct in
24531         sock_diag_save_cookie(tw, r->id.idiag_cookie);
24532         r->id.idiag_sport     = tw->tw_sport;
24533         r->id.idiag_dport     = tw->tw_dport;
24534 -       r->id.idiag_src[0]    = tw->tw_rcv_saddr;
24535 -       r->id.idiag_dst[0]    = tw->tw_daddr;
24536 +       r->id.idiag_src[0]    = nx_map_sock_lback(tw->tw_nx_info, tw->tw_rcv_saddr);
24537 +       r->id.idiag_dst[0]    = nx_map_sock_lback(tw->tw_nx_info, tw->tw_daddr);
24538         r->idiag_state        = tw->tw_substate;
24539         r->idiag_timer        = 3;
24540         r->idiag_expires      = DIV_ROUND_UP(tmo * 1000, HZ);
24541 @@ -287,12 +291,14 @@ int inet_diag_dump_one_icsk(struct inet_
24542  
24543         err = -EINVAL;
24544         if (req->sdiag_family == AF_INET) {
24545 +               /* TODO: lback */
24546                 sk = inet_lookup(net, hashinfo, req->id.idiag_dst[0],
24547                                  req->id.idiag_dport, req->id.idiag_src[0],
24548                                  req->id.idiag_sport, req->id.idiag_if);
24549         }
24550  #if IS_ENABLED(CONFIG_IPV6)
24551         else if (req->sdiag_family == AF_INET6) {
24552 +               /* TODO: lback */
24553                 sk = inet6_lookup(net, hashinfo,
24554                                   (struct in6_addr *)req->id.idiag_dst,
24555                                   req->id.idiag_dport,
24556 @@ -494,6 +500,7 @@ int inet_diag_bc_sk(const struct nlattr
24557         } else
24558  #endif
24559         {
24560 +                       /* TODO: lback */
24561                 entry.saddr = &inet->inet_rcv_saddr;
24562                 entry.daddr = &inet->inet_daddr;
24563         }
24564 @@ -652,6 +659,7 @@ static int inet_twsk_diag_dump(struct in
24565                 } else
24566  #endif
24567                 {
24568 +                       /* TODO: lback */
24569                         entry.saddr = &tw->tw_rcv_saddr;
24570                         entry.daddr = &tw->tw_daddr;
24571                 }
24572 @@ -730,8 +738,8 @@ static int inet_diag_fill_req(struct sk_
24573  
24574         r->id.idiag_sport = inet->inet_sport;
24575         r->id.idiag_dport = ireq->rmt_port;
24576 -       r->id.idiag_src[0] = ireq->loc_addr;
24577 -       r->id.idiag_dst[0] = ireq->rmt_addr;
24578 +       r->id.idiag_src[0] = nx_map_sock_lback(sk->sk_nx_info, ireq->loc_addr);
24579 +       r->id.idiag_dst[0] = nx_map_sock_lback(sk->sk_nx_info, ireq->rmt_addr);
24580         r->idiag_expires = jiffies_to_msecs(tmo);
24581         r->idiag_rqueue = 0;
24582         r->idiag_wqueue = 0;
24583 @@ -794,6 +802,7 @@ static int inet_diag_dump_reqs(struct sk
24584                             r->id.idiag_dport)
24585                                 continue;
24586  
24587 +                       /* TODO: lback */
24588                         if (bc) {
24589                                 inet_diag_req_addrs(sk, req, &entry);
24590                                 entry.dport = ntohs(ireq->rmt_port);
24591 @@ -850,6 +859,8 @@ void inet_diag_dump_icsk(struct inet_has
24592                                 if (!net_eq(sock_net(sk), net))
24593                                         continue;
24594  
24595 +                               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
24596 +                                       continue;
24597                                 if (num < s_num) {
24598                                         num++;
24599                                         continue;
24600 @@ -922,6 +933,8 @@ skip_listen_ht:
24601  
24602                         if (!net_eq(sock_net(sk), net))
24603                                 continue;
24604 +                       if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
24605 +                               continue;
24606                         if (num < s_num)
24607                                 goto next_normal;
24608                         if (!(r->idiag_states & (1 << sk->sk_state)))
24609 @@ -950,7 +963,8 @@ next_normal:
24610                                     &head->twchain) {
24611                                 if (!net_eq(twsk_net(tw), net))
24612                                         continue;
24613 -
24614 +                               if (!nx_check(tw->tw_nid, VS_WATCH_P | VS_IDENT))
24615 +                                       continue;
24616                                 if (num < s_num)
24617                                         goto next_dying;
24618                                 if (r->sdiag_family != AF_UNSPEC &&
24619 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
24620 --- linux-3.9.4/net/ipv4/inet_hashtables.c      2013-05-31 13:45:32.000000000 +0000
24621 +++ linux-3.9.4-vs2.3.6.2/net/ipv4/inet_hashtables.c    2013-05-31 18:20:50.000000000 +0000
24622 @@ -22,6 +22,7 @@
24623  #include <net/inet_connection_sock.h>
24624  #include <net/inet_hashtables.h>
24625  #include <net/secure_seq.h>
24626 +#include <net/route.h>
24627  #include <net/ip.h>
24628  
24629  /*
24630 @@ -156,6 +157,11 @@ static inline int compute_score(struct s
24631                         if (rcv_saddr != daddr)
24632                                 return -1;
24633                         score += 4;
24634 +               } else {
24635 +                       /* block non nx_info ips */
24636 +                       if (!v4_addr_in_nx_info(sk->sk_nx_info,
24637 +                               daddr, NXA_MASK_BIND))
24638 +                               return -1;
24639                 }
24640                 if (sk->sk_bound_dev_if) {
24641                         if (sk->sk_bound_dev_if != dif)
24642 @@ -173,7 +179,6 @@ static inline int compute_score(struct s
24643   * wildcarded during the search since they can never be otherwise.
24644   */
24645  
24646 -
24647  struct sock *__inet_lookup_listener(struct net *net,
24648                                     struct inet_hashinfo *hashinfo,
24649                                     const __be32 saddr, __be16 sport,
24650 @@ -209,6 +214,7 @@ begin:
24651                         phash = next_pseudo_random32(phash);
24652                 }
24653         }
24654 +
24655         /*
24656          * if the nulls value we got at the end of this lookup is
24657          * not the expected one, we must restart lookup.
24658 diff -NurpP --minimal linux-3.9.4/net/ipv4/netfilter.c linux-3.9.4-vs2.3.6.2/net/ipv4/netfilter.c
24659 --- linux-3.9.4/net/ipv4/netfilter.c    2012-12-11 03:30:57.000000000 +0000
24660 +++ linux-3.9.4-vs2.3.6.2/net/ipv4/netfilter.c  2013-05-31 17:17:54.000000000 +0000
24661 @@ -6,7 +6,7 @@
24662  #include <linux/skbuff.h>
24663  #include <linux/gfp.h>
24664  #include <linux/export.h>
24665 -#include <net/route.h>
24666 +// #include <net/route.h>
24667  #include <net/xfrm.h>
24668  #include <net/ip.h>
24669  #include <net/netfilter/nf_queue.h>
24670 diff -NurpP --minimal linux-3.9.4/net/ipv4/raw.c linux-3.9.4-vs2.3.6.2/net/ipv4/raw.c
24671 --- linux-3.9.4/net/ipv4/raw.c  2013-05-31 13:45:32.000000000 +0000
24672 +++ linux-3.9.4-vs2.3.6.2/net/ipv4/raw.c        2013-05-31 18:19:38.000000000 +0000
24673 @@ -116,7 +116,7 @@ static struct sock *__raw_v4_lookup(stru
24674  
24675                 if (net_eq(sock_net(sk), net) && inet->inet_num == num  &&
24676                     !(inet->inet_daddr && inet->inet_daddr != raddr)    &&
24677 -                   !(inet->inet_rcv_saddr && inet->inet_rcv_saddr != laddr) &&
24678 +                   v4_sock_addr_match(sk->sk_nx_info, inet, laddr)     &&
24679                     !(sk->sk_bound_dev_if && sk->sk_bound_dev_if != dif))
24680                         goto found; /* gotcha */
24681         }
24682 @@ -395,6 +395,12 @@ static int raw_send_hdrinc(struct sock *
24683                 icmp_out_count(net, ((struct icmphdr *)
24684                         skb_transport_header(skb))->type);
24685  
24686 +       err = -EPERM;
24687 +       if (!nx_check(0, VS_ADMIN) && !capable(CAP_NET_RAW) &&
24688 +               sk->sk_nx_info &&
24689 +               !v4_addr_in_nx_info(sk->sk_nx_info, iph->saddr, NXA_MASK_BIND))
24690 +               goto error_free;
24691 +
24692         err = NF_HOOK(NFPROTO_IPV4, NF_INET_LOCAL_OUT, skb, NULL,
24693                       rt->dst.dev, dst_output);
24694         if (err > 0)
24695 @@ -580,6 +586,16 @@ static int raw_sendmsg(struct kiocb *ioc
24696                         goto done;
24697         }
24698  
24699 +       if (sk->sk_nx_info) {
24700 +               rt = ip_v4_find_src(sock_net(sk), sk->sk_nx_info, &fl4);
24701 +               if (IS_ERR(rt)) {
24702 +                       err = PTR_ERR(rt);
24703 +                       rt = NULL;
24704 +                       goto done;
24705 +               }
24706 +               ip_rt_put(rt);
24707 +       }
24708 +
24709         security_sk_classify_flow(sk, flowi4_to_flowi(&fl4));
24710         rt = ip_route_output_flow(sock_net(sk), &fl4, sk);
24711         if (IS_ERR(rt)) {
24712 @@ -656,17 +672,19 @@ static int raw_bind(struct sock *sk, str
24713  {
24714         struct inet_sock *inet = inet_sk(sk);
24715         struct sockaddr_in *addr = (struct sockaddr_in *) uaddr;
24716 +       struct nx_v4_sock_addr nsa = { 0 };
24717         int ret = -EINVAL;
24718         int chk_addr_ret;
24719  
24720         if (sk->sk_state != TCP_CLOSE || addr_len < sizeof(struct sockaddr_in))
24721                 goto out;
24722 -       chk_addr_ret = inet_addr_type(sock_net(sk), addr->sin_addr.s_addr);
24723 +       v4_map_sock_addr(inet, addr, &nsa);
24724 +       chk_addr_ret = inet_addr_type(sock_net(sk), nsa.saddr);
24725         ret = -EADDRNOTAVAIL;
24726 -       if (addr->sin_addr.s_addr && chk_addr_ret != RTN_LOCAL &&
24727 +       if (nsa.saddr && chk_addr_ret != RTN_LOCAL &&
24728             chk_addr_ret != RTN_MULTICAST && chk_addr_ret != RTN_BROADCAST)
24729                 goto out;
24730 -       inet->inet_rcv_saddr = inet->inet_saddr = addr->sin_addr.s_addr;
24731 +       v4_set_sock_addr(inet, &nsa);
24732         if (chk_addr_ret == RTN_MULTICAST || chk_addr_ret == RTN_BROADCAST)
24733                 inet->inet_saddr = 0;  /* Use device */
24734         sk_dst_reset(sk);
24735 @@ -718,7 +736,8 @@ static int raw_recvmsg(struct kiocb *ioc
24736         /* Copy the address. */
24737         if (sin) {
24738                 sin->sin_family = AF_INET;
24739 -               sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
24740 +               sin->sin_addr.s_addr =
24741 +                       nx_map_sock_lback(sk->sk_nx_info, ip_hdr(skb)->saddr);
24742                 sin->sin_port = 0;
24743                 memset(&sin->sin_zero, 0, sizeof(sin->sin_zero));
24744         }
24745 @@ -913,7 +932,8 @@ static struct sock *raw_get_first(struct
24746         for (state->bucket = 0; state->bucket < RAW_HTABLE_SIZE;
24747                         ++state->bucket) {
24748                 sk_for_each(sk, &state->h->ht[state->bucket])
24749 -                       if (sock_net(sk) == seq_file_net(seq))
24750 +                       if ((sock_net(sk) == seq_file_net(seq)) &&
24751 +                           nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
24752                                 goto found;
24753         }
24754         sk = NULL;
24755 @@ -929,7 +949,8 @@ static struct sock *raw_get_next(struct
24756                 sk = sk_next(sk);
24757  try_again:
24758                 ;
24759 -       } while (sk && sock_net(sk) != seq_file_net(seq));
24760 +       } while (sk && ((sock_net(sk) != seq_file_net(seq)) ||
24761 +               !nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT)));
24762  
24763         if (!sk && ++state->bucket < RAW_HTABLE_SIZE) {
24764                 sk = sk_head(&state->h->ht[state->bucket]);
24765 diff -NurpP --minimal linux-3.9.4/net/ipv4/route.c linux-3.9.4-vs2.3.6.2/net/ipv4/route.c
24766 --- linux-3.9.4/net/ipv4/route.c        2013-05-31 13:45:32.000000000 +0000
24767 +++ linux-3.9.4-vs2.3.6.2/net/ipv4/route.c      2013-05-31 17:17:54.000000000 +0000
24768 @@ -1998,7 +1998,7 @@ struct rtable *__ip_route_output_key(str
24769  
24770  
24771         if (fl4->flowi4_oif) {
24772 -               dev_out = dev_get_by_index_rcu(net, fl4->flowi4_oif);
24773 +               dev_out = dev_get_by_index_real_rcu(net, fl4->flowi4_oif);
24774                 rth = ERR_PTR(-ENODEV);
24775                 if (dev_out == NULL)
24776                         goto out;
24777 diff -NurpP --minimal linux-3.9.4/net/ipv4/tcp.c linux-3.9.4-vs2.3.6.2/net/ipv4/tcp.c
24778 --- linux-3.9.4/net/ipv4/tcp.c  2013-05-31 13:45:32.000000000 +0000
24779 +++ linux-3.9.4-vs2.3.6.2/net/ipv4/tcp.c        2013-05-31 17:17:54.000000000 +0000
24780 @@ -268,6 +268,7 @@
24781  #include <linux/crypto.h>
24782  #include <linux/time.h>
24783  #include <linux/slab.h>
24784 +#include <linux/in.h>
24785  
24786  #include <net/icmp.h>
24787  #include <net/inet_common.h>
24788 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
24789 --- linux-3.9.4/net/ipv4/tcp_ipv4.c     2013-05-31 13:45:32.000000000 +0000
24790 +++ linux-3.9.4-vs2.3.6.2/net/ipv4/tcp_ipv4.c   2013-05-31 17:17:54.000000000 +0000
24791 @@ -2260,6 +2260,12 @@ static void *listening_get_next(struct s
24792                 req = req->dl_next;
24793                 while (1) {
24794                         while (req) {
24795 +                               vxdprintk(VXD_CBIT(net, 6),
24796 +                                       "sk,req: %p [#%d] (from %d)", req->sk,
24797 +                                       (req->sk)?req->sk->sk_nid:0, nx_current_nid());
24798 +                               if (req->sk &&
24799 +                                       !nx_check(req->sk->sk_nid, VS_WATCH_P | VS_IDENT))
24800 +                                       continue;
24801                                 if (req->rsk_ops->family == st->family) {
24802                                         cur = req;
24803                                         goto out;
24804 @@ -2284,6 +2290,10 @@ get_req:
24805         }
24806  get_sk:
24807         sk_nulls_for_each_from(sk, node) {
24808 +               vxdprintk(VXD_CBIT(net, 6), "sk: %p [#%d] (from %d)",
24809 +                       sk, sk->sk_nid, nx_current_nid());
24810 +               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
24811 +                       continue;
24812                 if (!net_eq(sock_net(sk), net))
24813                         continue;
24814                 if (sk->sk_family == st->family) {
24815 @@ -2360,6 +2370,11 @@ static void *established_get_first(struc
24816  
24817                 spin_lock_bh(lock);
24818                 sk_nulls_for_each(sk, node, &tcp_hashinfo.ehash[st->bucket].chain) {
24819 +                       vxdprintk(VXD_CBIT(net, 6),
24820 +                               "sk,egf: %p [#%d] (from %d)",
24821 +                               sk, sk->sk_nid, nx_current_nid());
24822 +                       if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
24823 +                               continue;
24824                         if (sk->sk_family != st->family ||
24825                             !net_eq(sock_net(sk), net)) {
24826                                 continue;
24827 @@ -2370,6 +2385,11 @@ static void *established_get_first(struc
24828                 st->state = TCP_SEQ_STATE_TIME_WAIT;
24829                 inet_twsk_for_each(tw, node,
24830                                    &tcp_hashinfo.ehash[st->bucket].twchain) {
24831 +                       vxdprintk(VXD_CBIT(net, 6),
24832 +                               "tw: %p [#%d] (from %d)",
24833 +                               tw, tw->tw_nid, nx_current_nid());
24834 +                       if (!nx_check(tw->tw_nid, VS_WATCH_P | VS_IDENT))
24835 +                               continue;
24836                         if (tw->tw_family != st->family ||
24837                             !net_eq(twsk_net(tw), net)) {
24838                                 continue;
24839 @@ -2399,7 +2419,9 @@ static void *established_get_next(struct
24840                 tw = cur;
24841                 tw = tw_next(tw);
24842  get_tw:
24843 -               while (tw && (tw->tw_family != st->family || !net_eq(twsk_net(tw), net))) {
24844 +               while (tw && (tw->tw_family != st->family ||
24845 +                       !net_eq(twsk_net(tw), net) ||
24846 +                       !nx_check(tw->tw_nid, VS_WATCH_P | VS_IDENT))) {
24847                         tw = tw_next(tw);
24848                 }
24849                 if (tw) {
24850 @@ -2423,6 +2445,11 @@ get_tw:
24851                 sk = sk_nulls_next(sk);
24852  
24853         sk_nulls_for_each_from(sk, node) {
24854 +               vxdprintk(VXD_CBIT(net, 6),
24855 +                       "sk,egn: %p [#%d] (from %d)",
24856 +                       sk, sk->sk_nid, nx_current_nid());
24857 +               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
24858 +                       continue;
24859                 if (sk->sk_family == st->family && net_eq(sock_net(sk), net))
24860                         goto found;
24861         }
24862 @@ -2628,9 +2655,9 @@ static void get_openreq4(const struct so
24863         seq_printf(f, "%4d: %08X:%04X %08X:%04X"
24864                 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %u %d %pK%n",
24865                 i,
24866 -               ireq->loc_addr,
24867 +               nx_map_sock_lback(current_nx_info(), ireq->loc_addr),
24868                 ntohs(inet_sk(sk)->inet_sport),
24869 -               ireq->rmt_addr,
24870 +               nx_map_sock_lback(current_nx_info(), ireq->rmt_addr),
24871                 ntohs(ireq->rmt_port),
24872                 TCP_SYN_RECV,
24873                 0, 0, /* could print option size, but that is af dependent. */
24874 @@ -2653,8 +2680,8 @@ static void get_tcp4_sock(struct sock *s
24875         const struct inet_connection_sock *icsk = inet_csk(sk);
24876         const struct inet_sock *inet = inet_sk(sk);
24877         struct fastopen_queue *fastopenq = icsk->icsk_accept_queue.fastopenq;
24878 -       __be32 dest = inet->inet_daddr;
24879 -       __be32 src = inet->inet_rcv_saddr;
24880 +       __be32 dest = nx_map_sock_lback(current_nx_info(), inet->inet_daddr);
24881 +       __be32 src = nx_map_sock_lback(current_nx_info(), inet->inet_rcv_saddr);
24882         __u16 destp = ntohs(inet->inet_dport);
24883         __u16 srcp = ntohs(inet->inet_sport);
24884         int rx_queue;
24885 @@ -2710,8 +2737,8 @@ static void get_timewait4_sock(const str
24886         __u16 destp, srcp;
24887         long delta = tw->tw_ttd - jiffies;
24888  
24889 -       dest  = tw->tw_daddr;
24890 -       src   = tw->tw_rcv_saddr;
24891 +       dest  = nx_map_sock_lback(current_nx_info(), tw->tw_daddr);
24892 +       src   = nx_map_sock_lback(current_nx_info(), tw->tw_rcv_saddr);
24893         destp = ntohs(tw->tw_dport);
24894         srcp  = ntohs(tw->tw_sport);
24895  
24896 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
24897 --- linux-3.9.4/net/ipv4/tcp_minisocks.c        2013-05-31 14:22:27.000000000 +0000
24898 +++ linux-3.9.4-vs2.3.6.2/net/ipv4/tcp_minisocks.c      2013-05-31 17:17:54.000000000 +0000
24899 @@ -23,6 +23,9 @@
24900  #include <linux/slab.h>
24901  #include <linux/sysctl.h>
24902  #include <linux/workqueue.h>
24903 +#include <linux/vs_limit.h>
24904 +#include <linux/vs_socket.h>
24905 +#include <linux/vs_context.h>
24906  #include <net/tcp.h>
24907  #include <net/inet_common.h>
24908  #include <net/xfrm.h>
24909 @@ -291,6 +294,11 @@ void tcp_time_wait(struct sock *sk, int
24910                 tcptw->tw_ts_recent_stamp = tp->rx_opt.ts_recent_stamp;
24911                 tcptw->tw_ts_offset     = tp->tsoffset;
24912  
24913 +               tw->tw_xid              = sk->sk_xid;
24914 +               tw->tw_vx_info          = NULL;
24915 +               tw->tw_nid              = sk->sk_nid;
24916 +               tw->tw_nx_info          = NULL;
24917 +
24918  #if IS_ENABLED(CONFIG_IPV6)
24919                 if (tw->tw_family == PF_INET6) {
24920                         struct ipv6_pinfo *np = inet6_sk(sk);
24921 diff -NurpP --minimal linux-3.9.4/net/ipv4/udp.c linux-3.9.4-vs2.3.6.2/net/ipv4/udp.c
24922 --- linux-3.9.4/net/ipv4/udp.c  2013-05-31 13:45:32.000000000 +0000
24923 +++ linux-3.9.4-vs2.3.6.2/net/ipv4/udp.c        2013-05-31 18:26:00.000000000 +0000
24924 @@ -306,14 +306,7 @@ fail:
24925  }
24926  EXPORT_SYMBOL(udp_lib_get_port);
24927  
24928 -static int ipv4_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2)
24929 -{
24930 -       struct inet_sock *inet1 = inet_sk(sk1), *inet2 = inet_sk(sk2);
24931 -
24932 -       return  (!ipv6_only_sock(sk2)  &&
24933 -                (!inet1->inet_rcv_saddr || !inet2->inet_rcv_saddr ||
24934 -                  inet1->inet_rcv_saddr == inet2->inet_rcv_saddr));
24935 -}
24936 +extern int ipv4_rcv_saddr_equal(const struct sock *, const struct sock *);
24937  
24938  static unsigned int udp4_portaddr_hash(struct net *net, __be32 saddr,
24939                                        unsigned int port)
24940 @@ -348,6 +341,11 @@ static inline int compute_score(struct s
24941                         if (inet->inet_rcv_saddr != daddr)
24942                                 return -1;
24943                         score += 4;
24944 +               } else {
24945 +                       /* block non nx_info ips */
24946 +                       if (!v4_addr_in_nx_info(sk->sk_nx_info,
24947 +                               daddr, NXA_MASK_BIND))
24948 +                               return -1;
24949                 }
24950                 if (inet->inet_daddr) {
24951                         if (inet->inet_daddr != saddr)
24952 @@ -458,6 +456,7 @@ begin:
24953         return result;
24954  }
24955  
24956 +
24957  /* UDP is nearly always wildcards out the wazoo, it makes no sense to try
24958   * harder than this. -DaveM
24959   */
24960 @@ -504,6 +503,11 @@ begin:
24961         sk_nulls_for_each_rcu(sk, node, &hslot->head) {
24962                 score = compute_score(sk, net, saddr, hnum, sport,
24963                                       daddr, dport, dif);
24964 +               /* FIXME: disabled?
24965 +               if (score == 9) {
24966 +                       result = sk;
24967 +                       break;
24968 +               } else */
24969                 if (score > badness) {
24970                         result = sk;
24971                         badness = score;
24972 @@ -528,6 +532,7 @@ begin:
24973         if (get_nulls_value(node) != slot)
24974                 goto begin;
24975  
24976 +
24977         if (result) {
24978                 if (unlikely(!atomic_inc_not_zero_hint(&result->sk_refcnt, 2)))
24979                         result = NULL;
24980 @@ -537,6 +542,7 @@ begin:
24981                         goto begin;
24982                 }
24983         }
24984 +
24985         rcu_read_unlock();
24986         return result;
24987  }
24988 @@ -580,8 +586,7 @@ static inline struct sock *udp_v4_mcast_
24989                     udp_sk(s)->udp_port_hash != hnum ||
24990                     (inet->inet_daddr && inet->inet_daddr != rmt_addr) ||
24991                     (inet->inet_dport != rmt_port && inet->inet_dport) ||
24992 -                   (inet->inet_rcv_saddr &&
24993 -                    inet->inet_rcv_saddr != loc_addr) ||
24994 +                   !v4_sock_addr_match(sk->sk_nx_info, inet, loc_addr) ||
24995                     ipv6_only_sock(s) ||
24996                     (s->sk_bound_dev_if && s->sk_bound_dev_if != dif))
24997                         continue;
24998 @@ -964,6 +969,16 @@ int udp_sendmsg(struct kiocb *iocb, stru
24999                                    inet_sk_flowi_flags(sk)|FLOWI_FLAG_CAN_SLEEP,
25000                                    faddr, saddr, dport, inet->inet_sport);
25001  
25002 +               if (sk->sk_nx_info) {
25003 +                       rt = ip_v4_find_src(net, sk->sk_nx_info, fl4);
25004 +                       if (IS_ERR(rt)) {
25005 +                               err = PTR_ERR(rt);
25006 +                               rt = NULL;
25007 +                               goto out;
25008 +                       }
25009 +                       ip_rt_put(rt);
25010 +               }
25011 +
25012                 security_sk_classify_flow(sk, flowi4_to_flowi(fl4));
25013                 rt = ip_route_output_flow(net, fl4, sk);
25014                 if (IS_ERR(rt)) {
25015 @@ -1269,7 +1284,8 @@ try_again:
25016         if (sin) {
25017                 sin->sin_family = AF_INET;
25018                 sin->sin_port = udp_hdr(skb)->source;
25019 -               sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
25020 +               sin->sin_addr.s_addr = nx_map_sock_lback(
25021 +                       skb->sk->sk_nx_info, ip_hdr(skb)->saddr);
25022                 memset(sin->sin_zero, 0, sizeof(sin->sin_zero));
25023         }
25024         if (inet->cmsg_flags)
25025 @@ -2025,6 +2041,8 @@ static struct sock *udp_get_first(struct
25026                 sk_nulls_for_each(sk, node, &hslot->head) {
25027                         if (!net_eq(sock_net(sk), net))
25028                                 continue;
25029 +                       if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
25030 +                               continue;
25031                         if (sk->sk_family == state->family)
25032                                 goto found;
25033                 }
25034 @@ -2042,7 +2060,9 @@ static struct sock *udp_get_next(struct
25035  
25036         do {
25037                 sk = sk_nulls_next(sk);
25038 -       } while (sk && (!net_eq(sock_net(sk), net) || sk->sk_family != state->family));
25039 +       } while (sk && (!net_eq(sock_net(sk), net) ||
25040 +               sk->sk_family != state->family ||
25041 +               !nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT)));
25042  
25043         if (!sk) {
25044                 if (state->bucket <= state->udp_table->mask)
25045 @@ -2138,8 +2158,8 @@ static void udp4_format_sock(struct sock
25046                 int bucket, int *len)
25047  {
25048         struct inet_sock *inet = inet_sk(sp);
25049 -       __be32 dest = inet->inet_daddr;
25050 -       __be32 src  = inet->inet_rcv_saddr;
25051 +       __be32 dest = nx_map_sock_lback(current_nx_info(), inet->inet_daddr);
25052 +       __be32 src = nx_map_sock_lback(current_nx_info(), inet->inet_rcv_saddr);
25053         __u16 destp       = ntohs(inet->inet_dport);
25054         __u16 srcp        = ntohs(inet->inet_sport);
25055  
25056 diff -NurpP --minimal linux-3.9.4/net/ipv6/Kconfig linux-3.9.4-vs2.3.6.2/net/ipv6/Kconfig
25057 --- linux-3.9.4/net/ipv6/Kconfig        2013-05-31 13:45:32.000000000 +0000
25058 +++ linux-3.9.4-vs2.3.6.2/net/ipv6/Kconfig      2013-05-31 17:17:54.000000000 +0000
25059 @@ -4,8 +4,8 @@
25060  
25061  #   IPv6 as module will cause a CRASH if you try to unload it
25062  menuconfig IPV6
25063 -       tristate "The IPv6 protocol"
25064 -       default m
25065 +       bool "The IPv6 protocol"
25066 +       default n
25067         ---help---
25068           This is complemental support for the IP version 6.
25069           You will still be able to do traditional IPv4 networking as well.
25070 diff -NurpP --minimal linux-3.9.4/net/ipv6/addrconf.c linux-3.9.4-vs2.3.6.2/net/ipv6/addrconf.c
25071 --- linux-3.9.4/net/ipv6/addrconf.c     2013-05-31 13:45:32.000000000 +0000
25072 +++ linux-3.9.4-vs2.3.6.2/net/ipv6/addrconf.c   2013-05-31 20:07:39.000000000 +0000
25073 @@ -93,6 +93,8 @@
25074  #include <linux/proc_fs.h>
25075  #include <linux/seq_file.h>
25076  #include <linux/export.h>
25077 +#include <linux/vs_network.h>
25078 +#include <linux/vs_inet6.h>
25079  
25080  /* Set to 3 to get tracing... */
25081  #define ACONF_DEBUG 2
25082 @@ -1250,7 +1252,7 @@ out:
25083  
25084  int ipv6_dev_get_saddr(struct net *net, const struct net_device *dst_dev,
25085                        const struct in6_addr *daddr, unsigned int prefs,
25086 -                      struct in6_addr *saddr)
25087 +                      struct in6_addr *saddr, struct nx_info *nxi)
25088  {
25089         struct ipv6_saddr_score scores[2],
25090                                 *score = &scores[0], *hiscore = &scores[1];
25091 @@ -1322,6 +1324,8 @@ int ipv6_dev_get_saddr(struct net *net,
25092                                                dev->name);
25093                                 continue;
25094                         }
25095 +                       if (!v6_addr_in_nx_info(nxi, &score->ifa->addr, -1))
25096 +                               continue;
25097  
25098                         score->rule = -1;
25099                         bitmap_zero(score->scorebits, IPV6_SADDR_RULE_MAX);
25100 @@ -3311,7 +3315,10 @@ static void if6_seq_stop(struct seq_file
25101  static int if6_seq_show(struct seq_file *seq, void *v)
25102  {
25103         struct inet6_ifaddr *ifp = (struct inet6_ifaddr *)v;
25104 -       seq_printf(seq, "%pi6 %02x %02x %02x %02x %8s\n",
25105 +
25106 +       if (nx_check(0, VS_ADMIN|VS_WATCH) ||
25107 +           v6_addr_in_nx_info(current_nx_info(), &ifp->addr, -1))
25108 +               seq_printf(seq, "%pi6 %02x %02x %02x %02x %8s\n",
25109                    &ifp->addr,
25110                    ifp->idev->dev->ifindex,
25111                    ifp->prefix_len,
25112 @@ -3815,6 +3822,11 @@ static int in6_dump_addrs(struct inet6_d
25113         struct ifacaddr6 *ifaca;
25114         int err = 1;
25115         int ip_idx = *p_ip_idx;
25116 +       struct nx_info *nxi = skb->sk ? skb->sk->sk_nx_info : NULL;
25117 +
25118 +       /* disable ipv6 on non v6 guests */
25119 +       if (nxi && !nx_info_has_v6(nxi))
25120 +               return skb->len;
25121  
25122         read_lock_bh(&idev->lock);
25123         switch (type) {
25124 @@ -3825,6 +3837,8 @@ static int in6_dump_addrs(struct inet6_d
25125                 list_for_each_entry(ifa, &idev->addr_list, if_list) {
25126                         if (++ip_idx < s_ip_idx)
25127                                 continue;
25128 +                               if (!v6_addr_in_nx_info(nxi, &ifa->addr, -1))
25129 +                                       continue;
25130                         err = inet6_fill_ifaddr(skb, ifa,
25131                                                 NETLINK_CB(cb->skb).portid,
25132                                                 cb->nlh->nlmsg_seq,
25133 @@ -3841,6 +3855,8 @@ static int in6_dump_addrs(struct inet6_d
25134                      ifmca = ifmca->next, ip_idx++) {
25135                         if (ip_idx < s_ip_idx)
25136                                 continue;
25137 +                               if (!v6_addr_in_nx_info(nxi, &ifmca->mca_addr, -1))
25138 +                                       continue;
25139                         err = inet6_fill_ifmcaddr(skb, ifmca,
25140                                                   NETLINK_CB(cb->skb).portid,
25141                                                   cb->nlh->nlmsg_seq,
25142 @@ -3856,6 +3872,8 @@ static int in6_dump_addrs(struct inet6_d
25143                      ifaca = ifaca->aca_next, ip_idx++) {
25144                         if (ip_idx < s_ip_idx)
25145                                 continue;
25146 +                               if (!v6_addr_in_nx_info(nxi, &ifaca->aca_addr, -1))
25147 +                                       continue;
25148                         err = inet6_fill_ifacaddr(skb, ifaca,
25149                                                   NETLINK_CB(cb->skb).portid,
25150                                                   cb->nlh->nlmsg_seq,
25151 @@ -3884,6 +3902,10 @@ static int inet6_dump_addr(struct sk_buf
25152         struct inet6_dev *idev;
25153         struct hlist_head *head;
25154  
25155 +       /* FIXME: maybe disable ipv6 on non v6 guests?
25156 +       if (skb->sk && skb->sk->sk_vx_info)
25157 +               return skb->len; */
25158 +
25159         s_h = cb->args[0];
25160         s_idx = idx = cb->args[1];
25161         s_ip_idx = ip_idx = cb->args[2];
25162 @@ -4238,6 +4260,7 @@ static int inet6_dump_ifinfo(struct sk_b
25163         struct net_device *dev;
25164         struct inet6_dev *idev;
25165         struct hlist_head *head;
25166 +       struct nx_info *nxi = skb->sk ? skb->sk->sk_nx_info : NULL;
25167  
25168         s_h = cb->args[0];
25169         s_idx = cb->args[1];
25170 @@ -4249,6 +4272,8 @@ static int inet6_dump_ifinfo(struct sk_b
25171                 hlist_for_each_entry_rcu(dev, head, index_hlist) {
25172                         if (idx < s_idx)
25173                                 goto cont;
25174 +                       if (!v6_dev_in_nx_info(dev, nxi))
25175 +                               goto cont;
25176                         idev = __in6_dev_get(dev);
25177                         if (!idev)
25178                                 goto cont;
25179 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
25180 --- linux-3.9.4/net/ipv6/af_inet6.c     2013-05-31 13:45:32.000000000 +0000
25181 +++ linux-3.9.4-vs2.3.6.2/net/ipv6/af_inet6.c   2013-05-31 20:04:41.000000000 +0000
25182 @@ -43,6 +43,8 @@
25183  #include <linux/netdevice.h>
25184  #include <linux/icmpv6.h>
25185  #include <linux/netfilter_ipv6.h>
25186 +#include <linux/vs_inet.h>
25187 +#include <linux/vs_inet6.h>
25188  
25189  #include <net/ip.h>
25190  #include <net/ipv6.h>
25191 @@ -160,10 +162,13 @@ lookup_protocol:
25192         }
25193  
25194         err = -EPERM;
25195 +       if ((protocol == IPPROTO_ICMPV6) &&
25196 +               nx_capable(CAP_NET_RAW, NXC_RAW_ICMP))
25197 +               goto override;
25198         if (sock->type == SOCK_RAW && !kern &&
25199             !ns_capable(net->user_ns, CAP_NET_RAW))
25200                 goto out_rcu_unlock;
25201 -
25202 +override:
25203         sock->ops = answer->ops;
25204         answer_prot = answer->prot;
25205         answer_no_check = answer->no_check;
25206 @@ -263,6 +268,7 @@ int inet6_bind(struct socket *sock, stru
25207         struct inet_sock *inet = inet_sk(sk);
25208         struct ipv6_pinfo *np = inet6_sk(sk);
25209         struct net *net = sock_net(sk);
25210 +       struct nx_v6_sock_addr nsa;
25211         __be32 v4addr = 0;
25212         unsigned short snum;
25213         int addr_type = 0;
25214 @@ -278,6 +284,10 @@ int inet6_bind(struct socket *sock, stru
25215         if (addr->sin6_family != AF_INET6)
25216                 return -EAFNOSUPPORT;
25217  
25218 +       err = v6_map_sock_addr(inet, addr, &nsa);
25219 +       if (err)
25220 +               return err;
25221 +
25222         addr_type = ipv6_addr_type(&addr->sin6_addr);
25223         if ((addr_type & IPV6_ADDR_MULTICAST) && sock->type == SOCK_STREAM)
25224                 return -EINVAL;
25225 @@ -309,6 +319,7 @@ int inet6_bind(struct socket *sock, stru
25226                 /* Reproduce AF_INET checks to make the bindings consistent */
25227                 v4addr = addr->sin6_addr.s6_addr32[3];
25228                 chk_addr_ret = inet_addr_type(net, v4addr);
25229 +
25230                 if (!sysctl_ip_nonlocal_bind &&
25231                     !(inet->freebind || inet->transparent) &&
25232                     v4addr != htonl(INADDR_ANY) &&
25233 @@ -318,6 +329,10 @@ int inet6_bind(struct socket *sock, stru
25234                         err = -EADDRNOTAVAIL;
25235                         goto out;
25236                 }
25237 +               if (!v4_addr_in_nx_info(sk->sk_nx_info, v4addr, NXA_MASK_BIND)) {
25238 +                       err = -EADDRNOTAVAIL;
25239 +                       goto out;
25240 +               }
25241         } else {
25242                 if (addr_type != IPV6_ADDR_ANY) {
25243                         struct net_device *dev = NULL;
25244 @@ -344,6 +359,11 @@ int inet6_bind(struct socket *sock, stru
25245                                 }
25246                         }
25247  
25248 +                       if (!v6_addr_in_nx_info(sk->sk_nx_info, &addr->sin6_addr, -1)) {
25249 +                               err = -EADDRNOTAVAIL;
25250 +                               goto out_unlock;
25251 +                       }
25252 +
25253                         /* ipv4 addr of the socket is invalid.  Only the
25254                          * unspecified and mapped address have a v4 equivalent.
25255                          */
25256 @@ -360,6 +380,9 @@ int inet6_bind(struct socket *sock, stru
25257                 }
25258         }
25259  
25260 +       /* what's that for? */
25261 +       v6_set_sock_addr(inet, &nsa);
25262 +
25263         inet->inet_rcv_saddr = v4addr;
25264         inet->inet_saddr = v4addr;
25265  
25266 @@ -461,9 +484,11 @@ int inet6_getname(struct socket *sock, s
25267                         return -ENOTCONN;
25268                 sin->sin6_port = inet->inet_dport;
25269                 sin->sin6_addr = np->daddr;
25270 +               /* FIXME: remap lback? */
25271                 if (np->sndflow)
25272                         sin->sin6_flowinfo = np->flow_label;
25273         } else {
25274 +               /* FIXME: remap lback? */
25275                 if (ipv6_addr_any(&np->rcv_saddr))
25276                         sin->sin6_addr = np->saddr;
25277                 else
25278 diff -NurpP --minimal linux-3.9.4/net/ipv6/datagram.c linux-3.9.4-vs2.3.6.2/net/ipv6/datagram.c
25279 --- linux-3.9.4/net/ipv6/datagram.c     2013-05-31 13:45:32.000000000 +0000
25280 +++ linux-3.9.4-vs2.3.6.2/net/ipv6/datagram.c   2013-05-31 17:17:54.000000000 +0000
25281 @@ -648,7 +648,7 @@ int ip6_datagram_send_ctl(struct net *ne
25282  
25283                         rcu_read_lock();
25284                         if (fl6->flowi6_oif) {
25285 -                               dev = dev_get_by_index_rcu(net, fl6->flowi6_oif);
25286 +                               dev = dev_get_by_index_real_rcu(net, fl6->flowi6_oif);
25287                                 if (!dev) {
25288                                         rcu_read_unlock();
25289                                         return -ENODEV;
25290 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
25291 --- linux-3.9.4/net/ipv6/fib6_rules.c   2013-02-19 13:58:58.000000000 +0000
25292 +++ linux-3.9.4-vs2.3.6.2/net/ipv6/fib6_rules.c 2013-05-31 17:17:54.000000000 +0000
25293 @@ -90,7 +90,7 @@ static int fib6_rule_action(struct fib_r
25294                                                ip6_dst_idev(&rt->dst)->dev,
25295                                                &flp6->daddr,
25296                                                rt6_flags2srcprefs(flags),
25297 -                                              &saddr))
25298 +                                              &saddr, NULL))
25299                                 goto again;
25300                         if (!ipv6_prefix_equal(&saddr, &r->src.addr,
25301                                                r->src.plen))
25302 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
25303 --- linux-3.9.4/net/ipv6/inet6_hashtables.c     2013-05-31 13:45:32.000000000 +0000
25304 +++ linux-3.9.4-vs2.3.6.2/net/ipv6/inet6_hashtables.c   2013-05-31 17:17:54.000000000 +0000
25305 @@ -16,6 +16,7 @@
25306  
25307  #include <linux/module.h>
25308  #include <linux/random.h>
25309 +#include <linux/vs_inet6.h>
25310  
25311  #include <net/inet_connection_sock.h>
25312  #include <net/inet_hashtables.h>
25313 @@ -83,7 +84,6 @@ struct sock *__inet6_lookup_established(
25314         unsigned int slot = hash & hashinfo->ehash_mask;
25315         struct inet_ehash_bucket *head = &hashinfo->ehash[slot];
25316  
25317 -
25318         rcu_read_lock();
25319  begin:
25320         sk_nulls_for_each_rcu(sk, node, &head->chain) {
25321 @@ -97,7 +97,7 @@ begin:
25322                                 sock_put(sk);
25323                                 goto begin;
25324                         }
25325 -               goto out;
25326 +                       goto out;
25327                 }
25328         }
25329         if (get_nulls_value(node) != slot)
25330 @@ -147,6 +147,9 @@ static inline int compute_score(struct s
25331                         if (!ipv6_addr_equal(&np->rcv_saddr, daddr))
25332                                 return -1;
25333                         score++;
25334 +               } else {
25335 +                       if (!v6_addr_in_nx_info(sk->sk_nx_info, daddr, -1))
25336 +                               return -1;
25337                 }
25338                 if (sk->sk_bound_dev_if) {
25339                         if (sk->sk_bound_dev_if != dif)
25340 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
25341 --- linux-3.9.4/net/ipv6/ip6_output.c   2013-05-31 13:45:32.000000000 +0000
25342 +++ linux-3.9.4-vs2.3.6.2/net/ipv6/ip6_output.c 2013-05-31 17:17:54.000000000 +0000
25343 @@ -877,7 +877,8 @@ static int ip6_dst_lookup_tail(struct so
25344                 struct rt6_info *rt = (struct rt6_info *) *dst;
25345                 err = ip6_route_get_saddr(net, rt, &fl6->daddr,
25346                                           sk ? inet6_sk(sk)->srcprefs : 0,
25347 -                                         &fl6->saddr);
25348 +                                         &fl6->saddr,
25349 +                                         sk ? sk->sk_nx_info : NULL);
25350                 if (err)
25351                         goto out_err_release;
25352         }
25353 diff -NurpP --minimal linux-3.9.4/net/ipv6/ndisc.c linux-3.9.4-vs2.3.6.2/net/ipv6/ndisc.c
25354 --- linux-3.9.4/net/ipv6/ndisc.c        2013-05-31 13:45:32.000000000 +0000
25355 +++ linux-3.9.4-vs2.3.6.2/net/ipv6/ndisc.c      2013-05-31 17:17:54.000000000 +0000
25356 @@ -485,7 +485,7 @@ static void ndisc_send_na(struct net_dev
25357         } else {
25358                 if (ipv6_dev_get_saddr(dev_net(dev), dev, daddr,
25359                                        inet6_sk(dev_net(dev)->ipv6.ndisc_sk)->srcprefs,
25360 -                                      &tmpaddr))
25361 +                                      &tmpaddr, NULL))
25362                         return;
25363                 src_addr = &tmpaddr;
25364         }
25365 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
25366 --- linux-3.9.4/net/ipv6/netfilter/ip6t_MASQUERADE.c    2012-12-11 03:30:57.000000000 +0000
25367 +++ linux-3.9.4-vs2.3.6.2/net/ipv6/netfilter/ip6t_MASQUERADE.c  2013-05-31 17:17:54.000000000 +0000
25368 @@ -34,7 +34,7 @@ masquerade_tg6(struct sk_buff *skb, cons
25369                             ctinfo == IP_CT_RELATED_REPLY));
25370  
25371         if (ipv6_dev_get_saddr(dev_net(par->out), par->out,
25372 -                              &ipv6_hdr(skb)->daddr, 0, &src) < 0)
25373 +                              &ipv6_hdr(skb)->daddr, 0, &src, NULL) < 0)
25374                 return NF_DROP;
25375  
25376         nfct_nat(ct)->masq_index = par->out->ifindex;
25377 diff -NurpP --minimal linux-3.9.4/net/ipv6/raw.c linux-3.9.4-vs2.3.6.2/net/ipv6/raw.c
25378 --- linux-3.9.4/net/ipv6/raw.c  2013-05-31 13:45:32.000000000 +0000
25379 +++ linux-3.9.4-vs2.3.6.2/net/ipv6/raw.c        2013-05-31 17:17:54.000000000 +0000
25380 @@ -30,6 +30,7 @@
25381  #include <linux/icmpv6.h>
25382  #include <linux/netfilter.h>
25383  #include <linux/netfilter_ipv6.h>
25384 +#include <linux/vs_inet6.h>
25385  #include <linux/skbuff.h>
25386  #include <linux/compat.h>
25387  #include <asm/uaccess.h>
25388 @@ -283,6 +284,13 @@ static int rawv6_bind(struct sock *sk, s
25389                                 goto out_unlock;
25390                 }
25391  
25392 +               if (!v6_addr_in_nx_info(sk->sk_nx_info, &addr->sin6_addr, -1)) {
25393 +                       err = -EADDRNOTAVAIL;
25394 +                       if (dev)
25395 +                               dev_put(dev);
25396 +                       goto out;
25397 +               }
25398 +
25399                 /* ipv4 addr of the socket is invalid.  Only the
25400                  * unspecified and mapped address have a v4 equivalent.
25401                  */
25402 diff -NurpP --minimal linux-3.9.4/net/ipv6/route.c linux-3.9.4-vs2.3.6.2/net/ipv6/route.c
25403 --- linux-3.9.4/net/ipv6/route.c        2013-05-31 13:45:32.000000000 +0000
25404 +++ linux-3.9.4-vs2.3.6.2/net/ipv6/route.c      2013-05-31 18:10:38.000000000 +0000
25405 @@ -58,6 +58,7 @@
25406  #include <net/netevent.h>
25407  #include <net/netlink.h>
25408  #include <net/nexthop.h>
25409 +#include <linux/vs_inet6.h>
25410  
25411  #include <asm/uaccess.h>
25412  
25413 @@ -2079,15 +2080,17 @@ int ip6_route_get_saddr(struct net *net,
25414                         struct rt6_info *rt,
25415                         const struct in6_addr *daddr,
25416                         unsigned int prefs,
25417 -                       struct in6_addr *saddr)
25418 +                       struct in6_addr *saddr,
25419 +                       struct nx_info *nxi)
25420  {
25421         struct inet6_dev *idev = ip6_dst_idev((struct dst_entry*)rt);
25422         int err = 0;
25423 -       if (rt->rt6i_prefsrc.plen)
25424 +       if (rt->rt6i_prefsrc.plen && (!nxi ||
25425 +           v6_addr_in_nx_info(nxi, &rt->rt6i_prefsrc.addr, NXA_TYPE_ADDR)))
25426                 *saddr = rt->rt6i_prefsrc.addr;
25427         else
25428                 err = ipv6_dev_get_saddr(net, idev ? idev->dev : NULL,
25429 -                                        daddr, prefs, saddr);
25430 +                                        daddr, prefs, saddr, nxi);
25431         return err;
25432  }
25433  
25434 @@ -2507,7 +2510,8 @@ static int rt6_fill_node(struct net *net
25435                                 goto nla_put_failure;
25436         } else if (dst) {
25437                 struct in6_addr saddr_buf;
25438 -               if (ip6_route_get_saddr(net, rt, dst, 0, &saddr_buf) == 0 &&
25439 +               if (ip6_route_get_saddr(net, rt, dst, 0, &saddr_buf,
25440 +                   (skb->sk ? skb->sk->sk_nx_info : NULL)) == 0 &&
25441                     nla_put(skb, RTA_PREFSRC, 16, &saddr_buf))
25442                         goto nla_put_failure;
25443         }
25444 @@ -2719,6 +2723,7 @@ static int rt6_info_route(struct rt6_inf
25445  {
25446         struct seq_file *m = p_arg;
25447  
25448 +       /* FIXME: check for network context? */
25449         seq_printf(m, "%pi6 %02x ", &rt->rt6i_dst.addr, rt->rt6i_dst.plen);
25450  
25451  #ifdef CONFIG_IPV6_SUBTREES
25452 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
25453 --- linux-3.9.4/net/ipv6/tcp_ipv6.c     2013-05-31 14:22:27.000000000 +0000
25454 +++ linux-3.9.4-vs2.3.6.2/net/ipv6/tcp_ipv6.c   2013-05-31 17:17:54.000000000 +0000
25455 @@ -71,6 +71,7 @@
25456  
25457  #include <linux/crypto.h>
25458  #include <linux/scatterlist.h>
25459 +#include <linux/vs_inet6.h>
25460  
25461  static void    tcp_v6_send_reset(struct sock *sk, struct sk_buff *skb);
25462  static void    tcp_v6_reqsk_send_ack(struct sock *sk, struct sk_buff *skb,
25463 @@ -164,8 +165,15 @@ static int tcp_v6_connect(struct sock *s
25464          *      connect() to INADDR_ANY means loopback (BSD'ism).
25465          */
25466  
25467 -       if(ipv6_addr_any(&usin->sin6_addr))
25468 -               usin->sin6_addr.s6_addr[15] = 0x1;
25469 +       if(ipv6_addr_any(&usin->sin6_addr)) {
25470 +               struct nx_info *nxi =  sk->sk_nx_info;
25471 +
25472 +               if (nxi && nx_info_has_v6(nxi))
25473 +                       /* FIXME: remap lback? */
25474 +                       usin->sin6_addr = nxi->v6.ip;
25475 +               else
25476 +                       usin->sin6_addr.s6_addr[15] = 0x1;
25477 +       }
25478  
25479         addr_type = ipv6_addr_type(&usin->sin6_addr);
25480  
25481 diff -NurpP --minimal linux-3.9.4/net/ipv6/udp.c linux-3.9.4-vs2.3.6.2/net/ipv6/udp.c
25482 --- linux-3.9.4/net/ipv6/udp.c  2013-05-31 14:22:27.000000000 +0000
25483 +++ linux-3.9.4-vs2.3.6.2/net/ipv6/udp.c        2013-05-31 18:16:01.000000000 +0000
25484 @@ -46,42 +46,68 @@
25485  #include <net/ip6_checksum.h>
25486  #include <net/xfrm.h>
25487  #include <net/inet6_hashtables.h>
25488 +#include <linux/vs_inet6.h>
25489  
25490  #include <linux/proc_fs.h>
25491  #include <linux/seq_file.h>
25492  #include <trace/events/skb.h>
25493  #include "udp_impl.h"
25494  
25495 -int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
25496 +int ipv6_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2)
25497  {
25498 -       const struct in6_addr *sk_rcv_saddr6 = &inet6_sk(sk)->rcv_saddr;
25499 +       const struct in6_addr *sk1_rcv_saddr6 = &inet6_sk(sk1)->rcv_saddr;
25500         const struct in6_addr *sk2_rcv_saddr6 = inet6_rcv_saddr(sk2);
25501 -       __be32 sk1_rcv_saddr = sk_rcv_saddr(sk);
25502 +       __be32 sk1_rcv_saddr = sk_rcv_saddr(sk1);
25503         __be32 sk2_rcv_saddr = sk_rcv_saddr(sk2);
25504 -       int sk_ipv6only = ipv6_only_sock(sk);
25505 +       int sk1_ipv6only = ipv6_only_sock(sk1);
25506         int sk2_ipv6only = inet_v6_ipv6only(sk2);
25507 -       int addr_type = ipv6_addr_type(sk_rcv_saddr6);
25508 +       int addr_type = ipv6_addr_type(sk1_rcv_saddr6);
25509         int addr_type2 = sk2_rcv_saddr6 ? ipv6_addr_type(sk2_rcv_saddr6) : IPV6_ADDR_MAPPED;
25510  
25511         /* if both are mapped, treat as IPv4 */
25512 -       if (addr_type == IPV6_ADDR_MAPPED && addr_type2 == IPV6_ADDR_MAPPED)
25513 -               return (!sk2_ipv6only &&
25514 +       if (addr_type == IPV6_ADDR_MAPPED && addr_type2 == IPV6_ADDR_MAPPED) {
25515 +               if (!sk2_ipv6only &&
25516                         (!sk1_rcv_saddr || !sk2_rcv_saddr ||
25517 -                         sk1_rcv_saddr == sk2_rcv_saddr));
25518 +                         sk1_rcv_saddr == sk2_rcv_saddr))
25519 +                       goto vs_v4;
25520 +               else
25521 +                       return 0;
25522 +       }
25523  
25524         if (addr_type2 == IPV6_ADDR_ANY &&
25525             !(sk2_ipv6only && addr_type == IPV6_ADDR_MAPPED))
25526 -               return 1;
25527 +               goto vs;
25528  
25529         if (addr_type == IPV6_ADDR_ANY &&
25530 -           !(sk_ipv6only && addr_type2 == IPV6_ADDR_MAPPED))
25531 -               return 1;
25532 +           !(sk1_ipv6only && addr_type2 == IPV6_ADDR_MAPPED))
25533 +               goto vs;
25534  
25535         if (sk2_rcv_saddr6 &&
25536 -           ipv6_addr_equal(sk_rcv_saddr6, sk2_rcv_saddr6))
25537 -               return 1;
25538 +           ipv6_addr_equal(sk1_rcv_saddr6, sk2_rcv_saddr6))
25539 +               goto vs;
25540  
25541         return 0;
25542 +
25543 +vs_v4:
25544 +       if (!sk1_rcv_saddr && !sk2_rcv_saddr)
25545 +               return nx_v4_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info);
25546 +       if (!sk2_rcv_saddr)
25547 +               return v4_addr_in_nx_info(sk1->sk_nx_info, sk2_rcv_saddr, -1);
25548 +       if (!sk1_rcv_saddr)
25549 +               return v4_addr_in_nx_info(sk2->sk_nx_info, sk1_rcv_saddr, -1);
25550 +       return 1;
25551 +vs:
25552 +       if (addr_type2 == IPV6_ADDR_ANY && addr_type == IPV6_ADDR_ANY)
25553 +               return nx_v6_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info);
25554 +       else if (addr_type2 == IPV6_ADDR_ANY)
25555 +               return v6_addr_in_nx_info(sk2->sk_nx_info, sk1_rcv_saddr6, -1);
25556 +       else if (addr_type == IPV6_ADDR_ANY) {
25557 +               if (addr_type2 == IPV6_ADDR_MAPPED)
25558 +                       return nx_v4_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info);
25559 +               else
25560 +                       return v6_addr_in_nx_info(sk1->sk_nx_info, sk2_rcv_saddr6, -1);
25561 +       }
25562 +       return 1;
25563  }
25564  
25565  static unsigned int udp6_portaddr_hash(struct net *net,
25566 @@ -145,6 +171,10 @@ static inline int compute_score(struct s
25567                         if (!ipv6_addr_equal(&np->rcv_saddr, daddr))
25568                                 return -1;
25569                         score++;
25570 +               } else {
25571 +                       /* block non nx_info ips */
25572 +                       if (!v6_addr_in_nx_info(sk->sk_nx_info, daddr, -1))
25573 +                               return -1;
25574                 }
25575                 if (!ipv6_addr_any(&np->daddr)) {
25576                         if (!ipv6_addr_equal(&np->daddr, saddr))
25577 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
25578 --- linux-3.9.4/net/ipv6/xfrm6_policy.c 2013-05-31 14:22:27.000000000 +0000
25579 +++ linux-3.9.4-vs2.3.6.2/net/ipv6/xfrm6_policy.c       2013-05-31 17:17:54.000000000 +0000
25580 @@ -63,7 +63,7 @@ static int xfrm6_get_saddr(struct net *n
25581         dev = ip6_dst_idev(dst)->dev;
25582         ipv6_dev_get_saddr(dev_net(dev), dev,
25583                            (struct in6_addr *)&daddr->a6, 0,
25584 -                          (struct in6_addr *)&saddr->a6);
25585 +                          (struct in6_addr *)&saddr->a6, NULL);
25586         dst_release(dst);
25587         return 0;
25588  }
25589 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
25590 --- linux-3.9.4/net/netfilter/ipvs/ip_vs_xmit.c 2013-02-19 13:58:59.000000000 +0000
25591 +++ linux-3.9.4-vs2.3.6.2/net/netfilter/ipvs/ip_vs_xmit.c       2013-05-31 17:17:54.000000000 +0000
25592 @@ -273,7 +273,7 @@ __ip_vs_route_output_v6(struct net *net,
25593                 return dst;
25594         if (ipv6_addr_any(&fl6.saddr) &&
25595             ipv6_dev_get_saddr(net, ip6_dst_idev(dst)->dev,
25596 -                              &fl6.daddr, 0, &fl6.saddr) < 0)
25597 +                              &fl6.daddr, 0, &fl6.saddr, NULL) < 0)
25598                 goto out_err;
25599         if (do_xfrm) {
25600                 dst = xfrm_lookup(net, dst, flowi6_to_flowi(&fl6), NULL, 0);
25601 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
25602 --- linux-3.9.4/net/netlink/af_netlink.c        2013-05-31 13:45:33.000000000 +0000
25603 +++ linux-3.9.4-vs2.3.6.2/net/netlink/af_netlink.c      2013-05-31 17:17:54.000000000 +0000
25604 @@ -55,6 +55,9 @@
25605  #include <linux/types.h>
25606  #include <linux/audit.h>
25607  #include <linux/mutex.h>
25608 +#include <linux/vs_context.h>
25609 +#include <linux/vs_network.h>
25610 +#include <linux/vs_limit.h>
25611  
25612  #include <net/net_namespace.h>
25613  #include <net/sock.h>
25614 @@ -1976,6 +1979,8 @@ static struct sock *netlink_seq_socket_i
25615                         sk_for_each(s, &hash->table[j]) {
25616                                 if (sock_net(s) != seq_file_net(seq))
25617                                         continue;
25618 +                               if (!nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT))
25619 +                                       continue;
25620                                 if (off == pos) {
25621                                         iter->link = i;
25622                                         iter->hash_idx = j;
25623 @@ -2010,7 +2015,8 @@ static void *netlink_seq_next(struct seq
25624         s = v;
25625         do {
25626                 s = sk_next(s);
25627 -       } while (s && sock_net(s) != seq_file_net(seq));
25628 +       } while (s && (sock_net(s) != seq_file_net(seq) ||
25629 +               !nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT)));
25630         if (s)
25631                 return s;
25632  
25633 @@ -2022,7 +2028,8 @@ static void *netlink_seq_next(struct seq
25634  
25635                 for (; j <= hash->mask; j++) {
25636                         s = sk_head(&hash->table[j]);
25637 -                       while (s && sock_net(s) != seq_file_net(seq))
25638 +                       while (s && (sock_net(s) != seq_file_net(seq) ||
25639 +                               !nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT)))
25640                                 s = sk_next(s);
25641                         if (s) {
25642                                 iter->link = i;
25643 diff -NurpP --minimal linux-3.9.4/net/socket.c linux-3.9.4-vs2.3.6.2/net/socket.c
25644 --- linux-3.9.4/net/socket.c    2013-05-31 13:45:33.000000000 +0000
25645 +++ linux-3.9.4-vs2.3.6.2/net/socket.c  2013-05-31 17:17:54.000000000 +0000
25646 @@ -98,6 +98,10 @@
25647  
25648  #include <net/sock.h>
25649  #include <linux/netfilter.h>
25650 +#include <linux/vs_base.h>
25651 +#include <linux/vs_socket.h>
25652 +#include <linux/vs_inet.h>
25653 +#include <linux/vs_inet6.h>
25654  
25655  #include <linux/if_tun.h>
25656  #include <linux/ipv6_route.h>
25657 @@ -617,13 +621,29 @@ static inline int __sock_sendmsg_nosec(s
25658                                        struct msghdr *msg, size_t size)
25659  {
25660         struct sock_iocb *si = kiocb_to_siocb(iocb);
25661 +       size_t len;
25662  
25663         si->sock = sock;
25664         si->scm = NULL;
25665         si->msg = msg;
25666         si->size = size;
25667  
25668 -       return sock->ops->sendmsg(iocb, sock, msg, size);
25669 +       len = sock->ops->sendmsg(iocb, sock, msg, size);
25670 +       if (sock->sk) {
25671 +               if (len == size)
25672 +                       vx_sock_send(sock->sk, size);
25673 +               else
25674 +                       vx_sock_fail(sock->sk, size);
25675 +       }
25676 +       vxdprintk(VXD_CBIT(net, 7),
25677 +               "__sock_sendmsg: %p[%p,%p,%p;%d/%d]:%d/%zu",
25678 +               sock, sock->sk,
25679 +               (sock->sk)?sock->sk->sk_nx_info:0,
25680 +               (sock->sk)?sock->sk->sk_vx_info:0,
25681 +               (sock->sk)?sock->sk->sk_xid:0,
25682 +               (sock->sk)?sock->sk->sk_nid:0,
25683 +               (unsigned int)size, len);
25684 +       return len;
25685  }
25686  
25687  static inline int __sock_sendmsg(struct kiocb *iocb, struct socket *sock,
25688 @@ -779,6 +799,7 @@ static inline int __sock_recvmsg_nosec(s
25689                                        struct msghdr *msg, size_t size, int flags)
25690  {
25691         struct sock_iocb *si = kiocb_to_siocb(iocb);
25692 +       int len;
25693  
25694         si->sock = sock;
25695         si->scm = NULL;
25696 @@ -786,7 +807,18 @@ static inline int __sock_recvmsg_nosec(s
25697         si->size = size;
25698         si->flags = flags;
25699  
25700 -       return sock->ops->recvmsg(iocb, sock, msg, size, flags);
25701 +       len = sock->ops->recvmsg(iocb, sock, msg, size, flags);
25702 +       if ((len >= 0) && sock->sk)
25703 +               vx_sock_recv(sock->sk, len);
25704 +       vxdprintk(VXD_CBIT(net, 7),
25705 +               "__sock_recvmsg: %p[%p,%p,%p;%d/%d]:%d/%d",
25706 +               sock, sock->sk,
25707 +               (sock->sk)?sock->sk->sk_nx_info:0,
25708 +               (sock->sk)?sock->sk->sk_vx_info:0,
25709 +               (sock->sk)?sock->sk->sk_xid:0,
25710 +               (sock->sk)?sock->sk->sk_nid:0,
25711 +               (unsigned int)size, len);
25712 +       return len;
25713  }
25714  
25715  static inline int __sock_recvmsg(struct kiocb *iocb, struct socket *sock,
25716 @@ -1269,6 +1301,13 @@ int __sock_create(struct net *net, int f
25717         if (type < 0 || type >= SOCK_MAX)
25718                 return -EINVAL;
25719  
25720 +       if (!nx_check(0, VS_ADMIN)) {
25721 +               if (family == PF_INET && !current_nx_info_has_v4())
25722 +                       return -EAFNOSUPPORT;
25723 +               if (family == PF_INET6 && !current_nx_info_has_v6())
25724 +                       return -EAFNOSUPPORT;
25725 +       }
25726 +
25727         /* Compatibility.
25728  
25729            This uglymoron is moved from INET layer to here to avoid
25730 @@ -1403,6 +1442,7 @@ SYSCALL_DEFINE3(socket, int, family, int
25731         if (retval < 0)
25732                 goto out;
25733  
25734 +       set_bit(SOCK_USER_SOCKET, &sock->flags);
25735         retval = sock_map_fd(sock, flags & (O_CLOEXEC | O_NONBLOCK));
25736         if (retval < 0)
25737                 goto out_release;
25738 @@ -1444,10 +1484,12 @@ SYSCALL_DEFINE4(socketpair, int, family,
25739         err = sock_create(family, type, protocol, &sock1);
25740         if (err < 0)
25741                 goto out;
25742 +       set_bit(SOCK_USER_SOCKET, &sock1->flags);
25743  
25744         err = sock_create(family, type, protocol, &sock2);
25745         if (err < 0)
25746                 goto out_release_1;
25747 +       set_bit(SOCK_USER_SOCKET, &sock2->flags);
25748  
25749         err = sock1->ops->socketpair(sock1, sock2);
25750         if (err < 0)
25751 diff -NurpP --minimal linux-3.9.4/net/sunrpc/auth.c linux-3.9.4-vs2.3.6.2/net/sunrpc/auth.c
25752 --- linux-3.9.4/net/sunrpc/auth.c       2013-05-31 13:45:33.000000000 +0000
25753 +++ linux-3.9.4-vs2.3.6.2/net/sunrpc/auth.c     2013-05-31 18:01:00.000000000 +0000
25754 @@ -15,6 +15,7 @@
25755  #include <linux/sunrpc/clnt.h>
25756  #include <linux/sunrpc/gss_api.h>
25757  #include <linux/spinlock.h>
25758 +#include <linux/vs_tag.h>
25759  
25760  #ifdef RPC_DEBUG
25761  # define RPCDBG_FACILITY       RPCDBG_AUTH
25762 @@ -480,6 +481,7 @@ rpcauth_lookupcred(struct rpc_auth *auth
25763         memset(&acred, 0, sizeof(acred));
25764         acred.uid = cred->fsuid;
25765         acred.gid = cred->fsgid;
25766 +       acred.tag = dx_current_tag();
25767         acred.group_info = get_group_info(((struct cred *)cred)->group_info);
25768  
25769         ret = auth->au_ops->lookup_cred(auth, &acred, flags);
25770 @@ -520,6 +522,7 @@ rpcauth_bind_root_cred(struct rpc_task *
25771         struct auth_cred acred = {
25772                 .uid = GLOBAL_ROOT_UID,
25773                 .gid = GLOBAL_ROOT_GID,
25774 +               .tag = dx_current_tag(),
25775         };
25776  
25777         dprintk("RPC: %5u looking up %s cred\n",
25778 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
25779 --- linux-3.9.4/net/sunrpc/auth_unix.c  2013-05-31 13:45:33.000000000 +0000
25780 +++ linux-3.9.4-vs2.3.6.2/net/sunrpc/auth_unix.c        2013-05-31 18:05:54.000000000 +0000
25781 @@ -13,11 +13,13 @@
25782  #include <linux/sunrpc/clnt.h>
25783  #include <linux/sunrpc/auth.h>
25784  #include <linux/user_namespace.h>
25785 +#include <linux/vs_tag.h>
25786  
25787  #define NFS_NGROUPS    16
25788  
25789  struct unx_cred {
25790         struct rpc_cred         uc_base;
25791 +       ktag_t                  uc_tag;
25792         kgid_t                  uc_gid;
25793         kgid_t                  uc_gids[NFS_NGROUPS];
25794  };
25795 @@ -80,6 +82,7 @@ unx_create_cred(struct rpc_auth *auth, s
25796                 groups = NFS_NGROUPS;
25797  
25798         cred->uc_gid = acred->gid;
25799 +       cred->uc_tag = acred->tag;
25800         for (i = 0; i < groups; i++)
25801                 cred->uc_gids[i] = GROUP_AT(acred->group_info, i);
25802         if (i < NFS_NGROUPS)
25803 @@ -121,7 +124,9 @@ unx_match(struct auth_cred *acred, struc
25804         unsigned int i;
25805  
25806  
25807 -       if (!uid_eq(cred->uc_uid, acred->uid) || !gid_eq(cred->uc_gid, acred->gid))
25808 +       if (!uid_eq(cred->uc_uid, acred->uid) ||
25809 +           !gid_eq(cred->uc_gid, acred->gid) ||
25810 +           !tag_eq(cred->uc_tag, acred->tag))
25811                 return 0;
25812  
25813         if (acred->group_info != NULL)
25814 @@ -146,7 +151,7 @@ unx_marshal(struct rpc_task *task, __be3
25815         struct rpc_clnt *clnt = task->tk_client;
25816         struct unx_cred *cred = container_of(task->tk_rqstp->rq_cred, struct unx_cred, uc_base);
25817         __be32          *base, *hold;
25818 -       int             i;
25819 +       int             i, tag;
25820  
25821         *p++ = htonl(RPC_AUTH_UNIX);
25822         base = p++;
25823 @@ -157,8 +162,13 @@ unx_marshal(struct rpc_task *task, __be3
25824          */
25825         p = xdr_encode_array(p, clnt->cl_nodename, clnt->cl_nodelen);
25826  
25827 -       *p++ = htonl((u32) from_kuid(&init_user_ns, cred->uc_uid));
25828 -       *p++ = htonl((u32) from_kgid(&init_user_ns, cred->uc_gid));
25829 +       tag = task->tk_client->cl_tag;
25830 +       *p++ = htonl((u32) TAGINO_UID(tag,
25831 +               from_kuid(&init_user_ns, cred->uc_uid),
25832 +               from_ktag(&init_user_ns, cred->uc_tag)));
25833 +       *p++ = htonl((u32) TAGINO_GID(tag,
25834 +               from_kgid(&init_user_ns, cred->uc_gid),
25835 +               from_ktag(&init_user_ns, cred->uc_tag)));
25836         hold = p++;
25837         for (i = 0; i < 16 && gid_valid(cred->uc_gids[i]); i++)
25838                 *p++ = htonl((u32) from_kgid(&init_user_ns, cred->uc_gids[i]));
25839 diff -NurpP --minimal linux-3.9.4/net/sunrpc/clnt.c linux-3.9.4-vs2.3.6.2/net/sunrpc/clnt.c
25840 --- linux-3.9.4/net/sunrpc/clnt.c       2013-05-31 13:45:33.000000000 +0000
25841 +++ linux-3.9.4-vs2.3.6.2/net/sunrpc/clnt.c     2013-05-31 17:17:54.000000000 +0000
25842 @@ -31,6 +31,7 @@
25843  #include <linux/in6.h>
25844  #include <linux/un.h>
25845  #include <linux/rcupdate.h>
25846 +#include <linux/vs_cvirt.h>
25847  
25848  #include <linux/sunrpc/clnt.h>
25849  #include <linux/sunrpc/addr.h>
25850 @@ -482,6 +483,9 @@ struct rpc_clnt *rpc_create(struct rpc_c
25851         if (!(args->flags & RPC_CLNT_CREATE_QUIET))
25852                 clnt->cl_chatty = 1;
25853  
25854 +       /* TODO: handle RPC_CLNT_CREATE_TAGGED
25855 +       if (args->flags & RPC_CLNT_CREATE_TAGGED)
25856 +               clnt->cl_tag = 1; */
25857         return clnt;
25858  }
25859  EXPORT_SYMBOL_GPL(rpc_create);
25860 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
25861 --- linux-3.9.4/net/unix/af_unix.c      2013-05-31 13:45:33.000000000 +0000
25862 +++ linux-3.9.4-vs2.3.6.2/net/unix/af_unix.c    2013-05-31 17:17:54.000000000 +0000
25863 @@ -114,6 +114,8 @@
25864  #include <linux/mount.h>
25865  #include <net/checksum.h>
25866  #include <linux/security.h>
25867 +#include <linux/vs_context.h>
25868 +#include <linux/vs_limit.h>
25869  
25870  struct hlist_head unix_socket_table[2 * UNIX_HASH_SIZE];
25871  EXPORT_SYMBOL_GPL(unix_socket_table);
25872 @@ -270,6 +272,8 @@ static struct sock *__unix_find_socket_b
25873                 if (!net_eq(sock_net(s), net))
25874                         continue;
25875  
25876 +               if (!nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT))
25877 +                       continue;
25878                 if (u->addr->len == len &&
25879                     !memcmp(u->addr->name, sunname, len))
25880                         goto found;
25881 @@ -2256,6 +2260,8 @@ static struct sock *unix_from_bucket(str
25882         for (sk = sk_head(&unix_socket_table[bucket]); sk; sk = sk_next(sk)) {
25883                 if (sock_net(sk) != seq_file_net(seq))
25884                         continue;
25885 +               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
25886 +                       continue;
25887                 if (++count == offset)
25888                         break;
25889         }
25890 @@ -2273,6 +2279,8 @@ static struct sock *unix_next_socket(str
25891                 sk = sk_next(sk);
25892                 if (!sk)
25893                         goto next_bucket;
25894 +               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
25895 +                       continue;
25896                 if (sock_net(sk) == seq_file_net(seq))
25897                         return sk;
25898         }
25899 diff -NurpP --minimal linux-3.9.4/scripts/checksyscalls.sh linux-3.9.4-vs2.3.6.2/scripts/checksyscalls.sh
25900 --- linux-3.9.4/scripts/checksyscalls.sh        2012-12-11 03:30:57.000000000 +0000
25901 +++ linux-3.9.4-vs2.3.6.2/scripts/checksyscalls.sh      2013-05-31 14:47:11.000000000 +0000
25902 @@ -193,7 +193,6 @@ cat << EOF
25903  #define __IGNORE_afs_syscall
25904  #define __IGNORE_getpmsg
25905  #define __IGNORE_putpmsg
25906 -#define __IGNORE_vserver
25907  EOF
25908  }
25909  
25910 diff -NurpP --minimal linux-3.9.4/security/commoncap.c linux-3.9.4-vs2.3.6.2/security/commoncap.c
25911 --- linux-3.9.4/security/commoncap.c    2013-05-31 13:45:34.000000000 +0000
25912 +++ linux-3.9.4-vs2.3.6.2/security/commoncap.c  2013-05-31 15:07:02.000000000 +0000
25913 @@ -76,6 +76,7 @@ int cap_netlink_send(struct sock *sk, st
25914  int cap_capable(const struct cred *cred, struct user_namespace *targ_ns,
25915                 int cap, int audit)
25916  {
25917 +       struct vx_info *vxi = current_vx_info(); /* FIXME: get vxi from cred? */
25918         struct user_namespace *ns = targ_ns;
25919  
25920         /* See if cred has the capability in the target user namespace
25921 @@ -84,8 +85,12 @@ int cap_capable(const struct cred *cred,
25922          */
25923         for (;;) {
25924                 /* Do we have the necessary capabilities? */
25925 -               if (ns == cred->user_ns)
25926 -                       return cap_raised(cred->cap_effective, cap) ? 0 : -EPERM;
25927 +               if (ns == cred->user_ns) {
25928 +                       if (vx_info_flags(vxi, VXF_STATE_SETUP, 0) &&
25929 +                           cap_raised(cred->cap_effective, cap))
25930 +                               return 0;
25931 +                       return vx_cap_raised(vxi, cred->cap_effective, cap) ? 0 : -EPERM;
25932 +               }
25933  
25934                 /* Have we tried all of the parent namespaces? */
25935                 if (ns == &init_user_ns)
25936 @@ -628,7 +633,7 @@ int cap_inode_setxattr(struct dentry *de
25937  
25938         if (!strncmp(name, XATTR_SECURITY_PREFIX,
25939                      sizeof(XATTR_SECURITY_PREFIX) - 1) &&
25940 -           !capable(CAP_SYS_ADMIN))
25941 +               !vx_capable(CAP_SYS_ADMIN, VXC_FS_SECURITY))
25942                 return -EPERM;
25943         return 0;
25944  }
25945 @@ -654,7 +659,7 @@ int cap_inode_removexattr(struct dentry
25946  
25947         if (!strncmp(name, XATTR_SECURITY_PREFIX,
25948                      sizeof(XATTR_SECURITY_PREFIX) - 1) &&
25949 -           !capable(CAP_SYS_ADMIN))
25950 +               !vx_capable(CAP_SYS_ADMIN, VXC_FS_SECURITY))
25951                 return -EPERM;
25952         return 0;
25953  }
25954 diff -NurpP --minimal linux-3.9.4/security/selinux/hooks.c linux-3.9.4-vs2.3.6.2/security/selinux/hooks.c
25955 --- linux-3.9.4/security/selinux/hooks.c        2013-05-31 13:45:34.000000000 +0000
25956 +++ linux-3.9.4-vs2.3.6.2/security/selinux/hooks.c      2013-05-31 14:47:11.000000000 +0000
25957 @@ -67,7 +67,6 @@
25958  #include <linux/dccp.h>
25959  #include <linux/quota.h>
25960  #include <linux/un.h>          /* for Unix socket types */
25961 -#include <net/af_unix.h>       /* for Unix socket types */
25962  #include <linux/parser.h>
25963  #include <linux/nfs_mount.h>
25964  #include <net/ipv6.h>
This page took 2.020761 seconds and 4 git commands to generate.