]> git.pld-linux.org Git - packages/kernel.git/blob - kernel-vserver-2.3.patch
5538a243037e1c53de41e215b1518ae51c4457d0
[packages/kernel.git] / kernel-vserver-2.3.patch
1 diff -NurpP --minimal linux-3.6/Documentation/vserver/debug.txt linux-3.6-vs2.3.4.3-noxfs-nocow/Documentation/vserver/debug.txt
2 --- linux-3.6/Documentation/vserver/debug.txt   1970-01-01 01:00:00.000000000 +0100
3 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/Documentation/vserver/debug.txt     2012-10-04 18:46:59.000000000 +0200
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.6/arch/alpha/Kconfig linux-3.6-vs2.3.4.3-noxfs-nocow/arch/alpha/Kconfig
160 --- linux-3.6/arch/alpha/Kconfig        2012-10-04 15:26:43.000000000 +0200
161 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/arch/alpha/Kconfig  2012-10-04 18:46:59.000000000 +0200
162 @@ -664,6 +664,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.6/arch/alpha/kernel/ptrace.c linux-3.6-vs2.3.4.3-noxfs-nocow/arch/alpha/kernel/ptrace.c
172 --- linux-3.6/arch/alpha/kernel/ptrace.c        2012-05-21 18:06:12.000000000 +0200
173 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/arch/alpha/kernel/ptrace.c  2012-10-04 18:46:59.000000000 +0200
174 @@ -13,6 +13,7 @@
175  #include <linux/user.h>
176  #include <linux/security.h>
177  #include <linux/signal.h>
178 +#include <linux/vs_base.h>
179  
180  #include <asm/uaccess.h>
181  #include <asm/pgtable.h>
182 diff -NurpP --minimal linux-3.6/arch/alpha/kernel/systbls.S linux-3.6-vs2.3.4.3-noxfs-nocow/arch/alpha/kernel/systbls.S
183 --- linux-3.6/arch/alpha/kernel/systbls.S       2012-10-04 15:26:43.000000000 +0200
184 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/arch/alpha/kernel/systbls.S 2012-10-04 18:46:59.000000000 +0200
185 @@ -446,7 +446,7 @@ sys_call_table:
186         .quad sys_stat64                        /* 425 */
187         .quad sys_lstat64
188         .quad sys_fstat64
189 -       .quad sys_ni_syscall                    /* sys_vserver */
190 +       .quad sys_vserver                       /* sys_vserver */
191         .quad sys_ni_syscall                    /* sys_mbind */
192         .quad sys_ni_syscall                    /* sys_get_mempolicy */
193         .quad sys_ni_syscall                    /* sys_set_mempolicy */
194 diff -NurpP --minimal linux-3.6/arch/alpha/kernel/traps.c linux-3.6-vs2.3.4.3-noxfs-nocow/arch/alpha/kernel/traps.c
195 --- linux-3.6/arch/alpha/kernel/traps.c 2012-05-21 18:06:12.000000000 +0200
196 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/arch/alpha/kernel/traps.c   2012-10-04 18:46:59.000000000 +0200
197 @@ -184,7 +184,8 @@ die_if_kernel(char * str, struct pt_regs
198  #ifdef CONFIG_SMP
199         printk("CPU %d ", hard_smp_processor_id());
200  #endif
201 -       printk("%s(%d): %s %ld\n", current->comm, task_pid_nr(current), str, err);
202 +       printk("%s(%d[#%u]): %s %ld\n", current->comm,
203 +               task_pid_nr(current), current->xid, str, err);
204         dik_show_regs(regs, r9_15);
205         add_taint(TAINT_DIE);
206         dik_show_trace((unsigned long *)(regs+1));
207 diff -NurpP --minimal linux-3.6/arch/arm/Kconfig linux-3.6-vs2.3.4.3-noxfs-nocow/arch/arm/Kconfig
208 --- linux-3.6/arch/arm/Kconfig  2012-10-04 15:26:43.000000000 +0200
209 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/arch/arm/Kconfig    2012-10-04 18:46:59.000000000 +0200
210 @@ -2331,6 +2331,8 @@ source "fs/Kconfig"
211  
212  source "arch/arm/Kconfig.debug"
213  
214 +source "kernel/vserver/Kconfig"
215 +
216  source "security/Kconfig"
217  
218  source "crypto/Kconfig"
219 diff -NurpP --minimal linux-3.6/arch/arm/kernel/calls.S linux-3.6-vs2.3.4.3-noxfs-nocow/arch/arm/kernel/calls.S
220 --- linux-3.6/arch/arm/kernel/calls.S   2012-10-04 15:26:43.000000000 +0200
221 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/arch/arm/kernel/calls.S     2012-10-04 18:46:59.000000000 +0200
222 @@ -322,7 +322,7 @@
223  /* 310 */      CALL(sys_request_key)
224                 CALL(sys_keyctl)
225                 CALL(ABI(sys_semtimedop, sys_oabi_semtimedop))
226 -/* vserver */  CALL(sys_ni_syscall)
227 +               CALL(sys_vserver)
228                 CALL(sys_ioprio_set)
229  /* 315 */      CALL(sys_ioprio_get)
230                 CALL(sys_inotify_init)
231 diff -NurpP --minimal linux-3.6/arch/arm/kernel/process.c linux-3.6-vs2.3.4.3-noxfs-nocow/arch/arm/kernel/process.c
232 --- linux-3.6/arch/arm/kernel/process.c 2012-10-04 15:26:43.000000000 +0200
233 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/arch/arm/kernel/process.c   2012-10-04 18:46:59.000000000 +0200
234 @@ -337,7 +337,8 @@ void __show_regs(struct pt_regs *regs)
235  void show_regs(struct pt_regs * regs)
236  {
237         printk("\n");
238 -       printk("Pid: %d, comm: %20s\n", task_pid_nr(current), current->comm);
239 +       printk("Pid: %d[#%u], comm: %20s\n",
240 +               task_pid_nr(current), current->xid, current->comm);
241         __show_regs(regs);
242         dump_stack();
243  }
244 diff -NurpP --minimal linux-3.6/arch/arm/kernel/traps.c linux-3.6-vs2.3.4.3-noxfs-nocow/arch/arm/kernel/traps.c
245 --- linux-3.6/arch/arm/kernel/traps.c   2012-10-04 15:26:44.000000000 +0200
246 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/arch/arm/kernel/traps.c     2012-10-04 19:03:56.000000000 +0200
247 @@ -249,8 +249,8 @@ static int __die(const char *str, int er
248  
249         print_modules();
250         __show_regs(regs);
251 -       printk(KERN_EMERG "Process %.*s (pid: %d, stack limit = 0x%p)\n",
252 -               TASK_COMM_LEN, tsk->comm, task_pid_nr(tsk), end_of_stack(tsk));
253 +       printk(KERN_EMERG "Process %.*s (pid: %d:#%u, stack limit = 0x%p)\n",
254 +               TASK_COMM_LEN, tsk->comm, task_pid_nr(tsk), tsk->xid, end_of_stack(tsk));
255  
256         if (!user_mode(regs) || in_interrupt()) {
257                 dump_mem(KERN_EMERG, "Stack: ", regs->ARM_sp,
258 diff -NurpP --minimal linux-3.6/arch/cris/Kconfig linux-3.6-vs2.3.4.3-noxfs-nocow/arch/cris/Kconfig
259 --- linux-3.6/arch/cris/Kconfig 2012-10-04 15:26:51.000000000 +0200
260 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/arch/cris/Kconfig   2012-10-04 18:46:59.000000000 +0200
261 @@ -673,6 +673,8 @@ source "drivers/staging/Kconfig"
262  
263  source "arch/cris/Kconfig.debug"
264  
265 +source "kernel/vserver/Kconfig"
266 +
267  source "security/Kconfig"
268  
269  source "crypto/Kconfig"
270 diff -NurpP --minimal linux-3.6/arch/frv/kernel/kernel_thread.S linux-3.6-vs2.3.4.3-noxfs-nocow/arch/frv/kernel/kernel_thread.S
271 --- linux-3.6/arch/frv/kernel/kernel_thread.S   2012-10-04 15:26:51.000000000 +0200
272 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/arch/frv/kernel/kernel_thread.S     2012-10-04 18:46:59.000000000 +0200
273 @@ -37,7 +37,7 @@ kernel_thread:
274  
275         # start by forking the current process, but with shared VM
276         setlos.p        #__NR_clone,gr7         ; syscall number
277 -       ori             gr10,#CLONE_VM,gr8      ; first syscall arg     [clone_flags]
278 +       ori             gr10,#CLONE_KT,gr8      ; first syscall arg     [clone_flags]
279         sethi.p         #0xe4e4,gr9             ; second syscall arg    [newsp]
280         setlo           #0xe4e4,gr9
281         setlos.p        #0,gr10                 ; third syscall arg     [parent_tidptr]
282 diff -NurpP --minimal linux-3.6/arch/h8300/Kconfig linux-3.6-vs2.3.4.3-noxfs-nocow/arch/h8300/Kconfig
283 --- linux-3.6/arch/h8300/Kconfig        2012-10-04 15:26:51.000000000 +0200
284 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/arch/h8300/Kconfig  2012-10-04 18:46:59.000000000 +0200
285 @@ -215,6 +215,8 @@ source "fs/Kconfig"
286  
287  source "arch/h8300/Kconfig.debug"
288  
289 +source "kernel/vserver/Kconfig"
290 +
291  source "security/Kconfig"
292  
293  source "crypto/Kconfig"
294 diff -NurpP --minimal linux-3.6/arch/ia64/Kconfig linux-3.6-vs2.3.4.3-noxfs-nocow/arch/ia64/Kconfig
295 --- linux-3.6/arch/ia64/Kconfig 2012-10-04 15:26:51.000000000 +0200
296 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/arch/ia64/Kconfig   2012-10-04 18:46:59.000000000 +0200
297 @@ -652,6 +652,8 @@ source "fs/Kconfig"
298  
299  source "arch/ia64/Kconfig.debug"
300  
301 +source "kernel/vserver/Kconfig"
302 +
303  source "security/Kconfig"
304  
305  source "crypto/Kconfig"
306 diff -NurpP --minimal linux-3.6/arch/ia64/kernel/entry.S linux-3.6-vs2.3.4.3-noxfs-nocow/arch/ia64/kernel/entry.S
307 --- linux-3.6/arch/ia64/kernel/entry.S  2012-03-19 19:46:40.000000000 +0100
308 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/arch/ia64/kernel/entry.S    2012-10-04 18:46:59.000000000 +0200
309 @@ -1714,7 +1714,7 @@ sys_call_table:
310         data8 sys_mq_notify
311         data8 sys_mq_getsetattr
312         data8 sys_kexec_load
313 -       data8 sys_ni_syscall                    // reserved for vserver
314 +       data8 sys_vserver
315         data8 sys_waitid                        // 1270
316         data8 sys_add_key
317         data8 sys_request_key
318 diff -NurpP --minimal linux-3.6/arch/ia64/kernel/process.c linux-3.6-vs2.3.4.3-noxfs-nocow/arch/ia64/kernel/process.c
319 --- linux-3.6/arch/ia64/kernel/process.c        2012-07-22 23:38:51.000000000 +0200
320 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/arch/ia64/kernel/process.c  2012-10-04 18:46:59.000000000 +0200
321 @@ -110,8 +110,8 @@ show_regs (struct pt_regs *regs)
322         unsigned long ip = regs->cr_iip + ia64_psr(regs)->ri;
323  
324         print_modules();
325 -       printk("\nPid: %d, CPU %d, comm: %20s\n", task_pid_nr(current),
326 -                       smp_processor_id(), current->comm);
327 +       printk("\nPid: %d[#%u], CPU %d, comm: %20s\n", task_pid_nr(current),
328 +                       current->xid, smp_processor_id(), current->comm);
329         printk("psr : %016lx ifs : %016lx ip  : [<%016lx>]    %s (%s)\n",
330                regs->cr_ipsr, regs->cr_ifs, ip, print_tainted(),
331                init_utsname()->release);
332 diff -NurpP --minimal linux-3.6/arch/ia64/kernel/ptrace.c linux-3.6-vs2.3.4.3-noxfs-nocow/arch/ia64/kernel/ptrace.c
333 --- linux-3.6/arch/ia64/kernel/ptrace.c 2012-05-21 18:06:26.000000000 +0200
334 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/arch/ia64/kernel/ptrace.c   2012-10-04 18:46:59.000000000 +0200
335 @@ -21,6 +21,7 @@
336  #include <linux/regset.h>
337  #include <linux/elf.h>
338  #include <linux/tracehook.h>
339 +#include <linux/vs_base.h>
340  
341  #include <asm/pgtable.h>
342  #include <asm/processor.h>
343 diff -NurpP --minimal linux-3.6/arch/ia64/kernel/traps.c linux-3.6-vs2.3.4.3-noxfs-nocow/arch/ia64/kernel/traps.c
344 --- linux-3.6/arch/ia64/kernel/traps.c  2012-05-21 18:06:26.000000000 +0200
345 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/arch/ia64/kernel/traps.c    2012-10-04 18:47:00.000000000 +0200
346 @@ -60,8 +60,9 @@ die (const char *str, struct pt_regs *re
347         put_cpu();
348  
349         if (++die.lock_owner_depth < 3) {
350 -               printk("%s[%d]: %s %ld [%d]\n",
351 -               current->comm, task_pid_nr(current), str, err, ++die_counter);
352 +               printk("%s[%d[#%u]]: %s %ld [%d]\n",
353 +                       current->comm, task_pid_nr(current), current->xid,
354 +                       str, err, ++die_counter);
355                 if (notify_die(DIE_OOPS, str, regs, err, 255, SIGSEGV)
356                     != NOTIFY_STOP)
357                         show_regs(regs);
358 @@ -324,8 +325,9 @@ handle_fpu_swa (int fp_fault, struct pt_
359                         if ((last.count & 15) < 5 && (ia64_fetchadd(1, &last.count, acq) & 15) < 5) {
360                                 last.time = current_jiffies + 5 * HZ;
361                                 printk(KERN_WARNING
362 -                                       "%s(%d): floating-point assist fault at ip %016lx, isr %016lx\n",
363 -                                       current->comm, task_pid_nr(current), regs->cr_iip + ia64_psr(regs)->ri, isr);
364 +                                       "%s(%d[#%u]): floating-point assist fault at ip %016lx, isr %016lx\n",
365 +                                       current->comm, task_pid_nr(current), current->xid,
366 +                                       regs->cr_iip + ia64_psr(regs)->ri, isr);
367                         }
368                 }
369         }
370 diff -NurpP --minimal linux-3.6/arch/m32r/kernel/traps.c linux-3.6-vs2.3.4.3-noxfs-nocow/arch/m32r/kernel/traps.c
371 --- linux-3.6/arch/m32r/kernel/traps.c  2012-05-21 18:06:26.000000000 +0200
372 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/arch/m32r/kernel/traps.c    2012-10-04 18:47:00.000000000 +0200
373 @@ -195,8 +195,9 @@ static void show_registers(struct pt_reg
374         } else {
375                 printk("SPI: %08lx\n", sp);
376         }
377 -       printk("Process %s (pid: %d, process nr: %d, stackpage=%08lx)",
378 -               current->comm, task_pid_nr(current), 0xffff & i, 4096+(unsigned long)current);
379 +       printk("Process %s (pid: %d[#%u], process nr: %d, stackpage=%08lx)",
380 +               current->comm, task_pid_nr(current), current->xid,
381 +               0xffff & i, 4096+(unsigned long)current);
382  
383         /*
384          * When in-kernel, we also print out the stack and code at the
385 diff -NurpP --minimal linux-3.6/arch/m68k/Kconfig linux-3.6-vs2.3.4.3-noxfs-nocow/arch/m68k/Kconfig
386 --- linux-3.6/arch/m68k/Kconfig 2012-10-04 15:26:51.000000000 +0200
387 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/arch/m68k/Kconfig   2012-10-04 18:47:00.000000000 +0200
388 @@ -129,6 +129,8 @@ source "fs/Kconfig"
389  
390  source "arch/m68k/Kconfig.debug"
391  
392 +source "kernel/vserver/Kconfig"
393 +
394  source "security/Kconfig"
395  
396  source "crypto/Kconfig"
397 diff -NurpP --minimal linux-3.6/arch/mips/Kconfig linux-3.6-vs2.3.4.3-noxfs-nocow/arch/mips/Kconfig
398 --- linux-3.6/arch/mips/Kconfig 2012-10-04 15:26:52.000000000 +0200
399 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/arch/mips/Kconfig   2012-10-04 18:47:00.000000000 +0200
400 @@ -2554,6 +2554,8 @@ source "fs/Kconfig"
401  
402  source "arch/mips/Kconfig.debug"
403  
404 +source "kernel/vserver/Kconfig"
405 +
406  source "security/Kconfig"
407  
408  source "crypto/Kconfig"
409 diff -NurpP --minimal linux-3.6/arch/mips/kernel/ptrace.c linux-3.6-vs2.3.4.3-noxfs-nocow/arch/mips/kernel/ptrace.c
410 --- linux-3.6/arch/mips/kernel/ptrace.c 2012-07-22 23:38:52.000000000 +0200
411 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/arch/mips/kernel/ptrace.c   2012-10-04 18:47:00.000000000 +0200
412 @@ -25,6 +25,7 @@
413  #include <linux/security.h>
414  #include <linux/audit.h>
415  #include <linux/seccomp.h>
416 +#include <linux/vs_base.h>
417  
418  #include <asm/byteorder.h>
419  #include <asm/cpu.h>
420 @@ -262,6 +263,9 @@ long arch_ptrace(struct task_struct *chi
421         void __user *datavp = (void __user *) data;
422         unsigned long __user *datalp = (void __user *) data;
423  
424 +       if (!vx_check(vx_task_xid(child), VS_WATCH_P | VS_IDENT))
425 +               goto out;
426 +
427         switch (request) {
428         /* when I and D space are separate, these will need to be fixed. */
429         case PTRACE_PEEKTEXT: /* read word at location addr. */
430 diff -NurpP --minimal linux-3.6/arch/mips/kernel/scall32-o32.S linux-3.6-vs2.3.4.3-noxfs-nocow/arch/mips/kernel/scall32-o32.S
431 --- linux-3.6/arch/mips/kernel/scall32-o32.S    2012-01-09 16:14:05.000000000 +0100
432 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/arch/mips/kernel/scall32-o32.S      2012-10-04 18:47:00.000000000 +0200
433 @@ -523,7 +523,7 @@ einval:     li      v0, -ENOSYS
434         sys     sys_mq_timedreceive     5
435         sys     sys_mq_notify           2       /* 4275 */
436         sys     sys_mq_getsetattr       3
437 -       sys     sys_ni_syscall          0       /* sys_vserver */
438 +       sys     sys_vserver             3
439         sys     sys_waitid              5
440         sys     sys_ni_syscall          0       /* available, was setaltroot */
441         sys     sys_add_key             5       /* 4280 */
442 diff -NurpP --minimal linux-3.6/arch/mips/kernel/scall64-64.S linux-3.6-vs2.3.4.3-noxfs-nocow/arch/mips/kernel/scall64-64.S
443 --- linux-3.6/arch/mips/kernel/scall64-64.S     2012-01-09 16:14:05.000000000 +0100
444 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/arch/mips/kernel/scall64-64.S       2012-10-04 18:47:00.000000000 +0200
445 @@ -362,7 +362,7 @@ sys_call_table:
446         PTR     sys_mq_timedreceive
447         PTR     sys_mq_notify
448         PTR     sys_mq_getsetattr               /* 5235 */
449 -       PTR     sys_ni_syscall                  /* sys_vserver */
450 +       PTR     sys_vserver
451         PTR     sys_waitid
452         PTR     sys_ni_syscall                  /* available, was setaltroot */
453         PTR     sys_add_key
454 diff -NurpP --minimal linux-3.6/arch/mips/kernel/scall64-n32.S linux-3.6-vs2.3.4.3-noxfs-nocow/arch/mips/kernel/scall64-n32.S
455 --- linux-3.6/arch/mips/kernel/scall64-n32.S    2012-01-09 16:14:05.000000000 +0100
456 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/arch/mips/kernel/scall64-n32.S      2012-10-04 18:47:00.000000000 +0200
457 @@ -361,7 +361,7 @@ EXPORT(sysn32_call_table)
458         PTR     compat_sys_mq_timedreceive
459         PTR     compat_sys_mq_notify
460         PTR     compat_sys_mq_getsetattr
461 -       PTR     sys_ni_syscall                  /* 6240, sys_vserver */
462 +       PTR     sys32_vserver                   /* 6240 */
463         PTR     compat_sys_waitid
464         PTR     sys_ni_syscall                  /* available, was setaltroot */
465         PTR     sys_add_key
466 diff -NurpP --minimal linux-3.6/arch/mips/kernel/scall64-o32.S linux-3.6-vs2.3.4.3-noxfs-nocow/arch/mips/kernel/scall64-o32.S
467 --- linux-3.6/arch/mips/kernel/scall64-o32.S    2012-01-09 16:14:05.000000000 +0100
468 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/arch/mips/kernel/scall64-o32.S      2012-10-04 18:47:00.000000000 +0200
469 @@ -480,7 +480,7 @@ sys_call_table:
470         PTR     compat_sys_mq_timedreceive
471         PTR     compat_sys_mq_notify            /* 4275 */
472         PTR     compat_sys_mq_getsetattr
473 -       PTR     sys_ni_syscall                  /* sys_vserver */
474 +       PTR     sys32_vserver
475         PTR     sys_32_waitid
476         PTR     sys_ni_syscall                  /* available, was setaltroot */
477         PTR     sys_add_key                     /* 4280 */
478 diff -NurpP --minimal linux-3.6/arch/mips/kernel/traps.c linux-3.6-vs2.3.4.3-noxfs-nocow/arch/mips/kernel/traps.c
479 --- linux-3.6/arch/mips/kernel/traps.c  2012-10-04 15:26:53.000000000 +0200
480 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/arch/mips/kernel/traps.c    2012-10-04 18:47:00.000000000 +0200
481 @@ -347,9 +347,10 @@ void show_registers(struct pt_regs *regs
482  
483         __show_regs(regs);
484         print_modules();
485 -       printk("Process %s (pid: %d, threadinfo=%p, task=%p, tls=%0*lx)\n",
486 -              current->comm, current->pid, current_thread_info(), current,
487 -             field, current_thread_info()->tp_value);
488 +       printk("Process %s (pid: %d:#%u, threadinfo=%p, task=%p, tls=%0*lx)\n",
489 +               current->comm, task_pid_nr(current), current->xid,
490 +               current_thread_info(), current,
491 +               field, current_thread_info()->tp_value);
492         if (cpu_has_userlocal) {
493                 unsigned long tls;
494  
495 diff -NurpP --minimal linux-3.6/arch/parisc/Kconfig linux-3.6-vs2.3.4.3-noxfs-nocow/arch/parisc/Kconfig
496 --- linux-3.6/arch/parisc/Kconfig       2012-07-22 23:38:52.000000000 +0200
497 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/arch/parisc/Kconfig 2012-10-04 18:47:00.000000000 +0200
498 @@ -281,6 +281,8 @@ source "fs/Kconfig"
499  
500  source "arch/parisc/Kconfig.debug"
501  
502 +source "kernel/vserver/Kconfig"
503 +
504  source "security/Kconfig"
505  
506  source "crypto/Kconfig"
507 diff -NurpP --minimal linux-3.6/arch/parisc/kernel/syscall_table.S linux-3.6-vs2.3.4.3-noxfs-nocow/arch/parisc/kernel/syscall_table.S
508 --- linux-3.6/arch/parisc/kernel/syscall_table.S        2011-10-24 18:45:00.000000000 +0200
509 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/arch/parisc/kernel/syscall_table.S  2012-10-04 18:47:00.000000000 +0200
510 @@ -361,7 +361,7 @@
511         ENTRY_COMP(mbind)               /* 260 */
512         ENTRY_COMP(get_mempolicy)
513         ENTRY_COMP(set_mempolicy)
514 -       ENTRY_SAME(ni_syscall)  /* 263: reserved for vserver */
515 +       ENTRY_DIFF(vserver)
516         ENTRY_SAME(add_key)
517         ENTRY_SAME(request_key)         /* 265 */
518         ENTRY_SAME(keyctl)
519 diff -NurpP --minimal linux-3.6/arch/parisc/kernel/traps.c linux-3.6-vs2.3.4.3-noxfs-nocow/arch/parisc/kernel/traps.c
520 --- linux-3.6/arch/parisc/kernel/traps.c        2012-05-21 18:06:28.000000000 +0200
521 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/arch/parisc/kernel/traps.c  2012-10-04 18:47:00.000000000 +0200
522 @@ -235,8 +235,9 @@ void die_if_kernel(char *str, struct pt_
523                 if (err == 0)
524                         return; /* STFU */
525  
526 -               printk(KERN_CRIT "%s (pid %d): %s (code %ld) at " RFMT "\n",
527 -                       current->comm, task_pid_nr(current), str, err, regs->iaoq[0]);
528 +               printk(KERN_CRIT "%s (pid %d:#%u): %s (code %ld) at " RFMT "\n",
529 +                       current->comm, task_pid_nr(current), current->xid,
530 +                       str, err, regs->iaoq[0]);
531  #ifdef PRINT_USER_FAULTS
532                 /* XXX for debugging only */
533                 show_regs(regs);
534 @@ -269,8 +270,8 @@ void die_if_kernel(char *str, struct pt_
535                 pdc_console_restart();
536         
537         if (err)
538 -               printk(KERN_CRIT "%s (pid %d): %s (code %ld)\n",
539 -                       current->comm, task_pid_nr(current), str, err);
540 +               printk(KERN_CRIT "%s (pid %d:#%u): %s (code %ld)\n",
541 +                       current->comm, task_pid_nr(current), current->xid, str, err);
542  
543         /* Wot's wrong wif bein' racy? */
544         if (current->thread.flags & PARISC_KERNEL_DEATH) {
545 diff -NurpP --minimal linux-3.6/arch/parisc/mm/fault.c linux-3.6-vs2.3.4.3-noxfs-nocow/arch/parisc/mm/fault.c
546 --- linux-3.6/arch/parisc/mm/fault.c    2010-08-02 16:52:06.000000000 +0200
547 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/arch/parisc/mm/fault.c      2012-10-04 18:47:00.000000000 +0200
548 @@ -237,8 +237,9 @@ bad_area:
549  
550  #ifdef PRINT_USER_FAULTS
551                 printk(KERN_DEBUG "\n");
552 -               printk(KERN_DEBUG "do_page_fault() pid=%d command='%s' type=%lu address=0x%08lx\n",
553 -                   task_pid_nr(tsk), tsk->comm, code, address);
554 +               printk(KERN_DEBUG "do_page_fault() pid=%d:#%u "
555 +                   "command='%s' type=%lu address=0x%08lx\n",
556 +                   task_pid_nr(tsk), tsk->xid, tsk->comm, code, address);
557                 if (vma) {
558                         printk(KERN_DEBUG "vm_start = 0x%08lx, vm_end = 0x%08lx\n",
559                                         vma->vm_start, vma->vm_end);
560 diff -NurpP --minimal linux-3.6/arch/powerpc/Kconfig linux-3.6-vs2.3.4.3-noxfs-nocow/arch/powerpc/Kconfig
561 --- linux-3.6/arch/powerpc/Kconfig      2012-10-04 15:26:53.000000000 +0200
562 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/arch/powerpc/Kconfig        2012-10-04 18:47:00.000000000 +0200
563 @@ -996,6 +996,8 @@ source "lib/Kconfig"
564  
565  source "arch/powerpc/Kconfig.debug"
566  
567 +source "kernel/vserver/Kconfig"
568 +
569  source "security/Kconfig"
570  
571  config KEYS_COMPAT
572 diff -NurpP --minimal linux-3.6/arch/powerpc/include/asm/unistd.h linux-3.6-vs2.3.4.3-noxfs-nocow/arch/powerpc/include/asm/unistd.h
573 --- linux-3.6/arch/powerpc/include/asm/unistd.h 2012-10-04 15:26:53.000000000 +0200
574 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/arch/powerpc/include/asm/unistd.h   2012-10-04 18:47:00.000000000 +0200
575 @@ -275,7 +275,7 @@
576  #endif
577  #define __NR_rtas              255
578  #define __NR_sys_debug_setcontext 256
579 -/* Number 257 is reserved for vserver */
580 +#define __NR_vserver           257
581  #define __NR_migrate_pages     258
582  #define __NR_mbind             259
583  #define __NR_get_mempolicy     260
584 diff -NurpP --minimal linux-3.6/arch/powerpc/kernel/process.c linux-3.6-vs2.3.4.3-noxfs-nocow/arch/powerpc/kernel/process.c
585 --- linux-3.6/arch/powerpc/kernel/process.c     2012-10-04 15:26:54.000000000 +0200
586 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/arch/powerpc/kernel/process.c       2012-10-04 18:47:00.000000000 +0200
587 @@ -661,8 +661,9 @@ void show_regs(struct pt_regs * regs)
588  #else
589                 printk("DAR: "REG", DSISR: %08lx\n", regs->dar, regs->dsisr);
590  #endif
591 -       printk("TASK = %p[%d] '%s' THREAD: %p",
592 -              current, task_pid_nr(current), current->comm, task_thread_info(current));
593 +       printk("TASK = %p[%d,#%u] '%s' THREAD: %p",
594 +              current, task_pid_nr(current), current->xid,
595 +              current->comm, task_thread_info(current));
596  
597  #ifdef CONFIG_SMP
598         printk(" CPU: %d", raw_smp_processor_id());
599 diff -NurpP --minimal linux-3.6/arch/powerpc/kernel/traps.c linux-3.6-vs2.3.4.3-noxfs-nocow/arch/powerpc/kernel/traps.c
600 --- linux-3.6/arch/powerpc/kernel/traps.c       2012-10-04 15:26:54.000000000 +0200
601 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/arch/powerpc/kernel/traps.c 2012-10-04 18:47:00.000000000 +0200
602 @@ -1119,8 +1119,9 @@ void nonrecoverable_exception(struct pt_
603  
604  void trace_syscall(struct pt_regs *regs)
605  {
606 -       printk("Task: %p(%d), PC: %08lX/%08lX, Syscall: %3ld, Result: %s%ld    %s\n",
607 -              current, task_pid_nr(current), regs->nip, regs->link, regs->gpr[0],
608 +       printk("Task: %p(%d[#%u]), PC: %08lX/%08lX, Syscall: %3ld, Result: %s%ld    %s\n",
609 +              current, task_pid_nr(current), current->xid,
610 +              regs->nip, regs->link, regs->gpr[0],
611                regs->ccr&0x10000000?"Error=":"", regs->gpr[3], print_tainted());
612  }
613  
614 diff -NurpP --minimal linux-3.6/arch/s390/Kconfig linux-3.6-vs2.3.4.3-noxfs-nocow/arch/s390/Kconfig
615 --- linux-3.6/arch/s390/Kconfig 2012-10-04 15:26:54.000000000 +0200
616 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/arch/s390/Kconfig   2012-10-04 18:47:00.000000000 +0200
617 @@ -634,6 +634,8 @@ source "fs/Kconfig"
618  
619  source "arch/s390/Kconfig.debug"
620  
621 +source "kernel/vserver/Kconfig"
622 +
623  source "security/Kconfig"
624  
625  source "crypto/Kconfig"
626 diff -NurpP --minimal linux-3.6/arch/s390/include/asm/tlb.h linux-3.6-vs2.3.4.3-noxfs-nocow/arch/s390/include/asm/tlb.h
627 --- linux-3.6/arch/s390/include/asm/tlb.h       2012-07-22 23:38:59.000000000 +0200
628 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/arch/s390/include/asm/tlb.h 2012-10-04 18:47:00.000000000 +0200
629 @@ -24,6 +24,7 @@
630  #include <linux/mm.h>
631  #include <linux/pagemap.h>
632  #include <linux/swap.h>
633 +
634  #include <asm/processor.h>
635  #include <asm/pgalloc.h>
636  #include <asm/tlbflush.h>
637 diff -NurpP --minimal linux-3.6/arch/s390/include/asm/unistd.h linux-3.6-vs2.3.4.3-noxfs-nocow/arch/s390/include/asm/unistd.h
638 --- linux-3.6/arch/s390/include/asm/unistd.h    2012-10-04 15:26:55.000000000 +0200
639 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/arch/s390/include/asm/unistd.h      2012-10-04 18:47:00.000000000 +0200
640 @@ -200,7 +200,7 @@
641  #define __NR_clock_gettime     (__NR_timer_create+6)
642  #define __NR_clock_getres      (__NR_timer_create+7)
643  #define __NR_clock_nanosleep   (__NR_timer_create+8)
644 -/* Number 263 is reserved for vserver */
645 +#define __NR_vserver           263
646  #define __NR_statfs64          265
647  #define __NR_fstatfs64         266
648  #define __NR_remap_file_pages  267
649 diff -NurpP --minimal linux-3.6/arch/s390/kernel/ptrace.c linux-3.6-vs2.3.4.3-noxfs-nocow/arch/s390/kernel/ptrace.c
650 --- linux-3.6/arch/s390/kernel/ptrace.c 2012-10-04 15:26:55.000000000 +0200
651 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/arch/s390/kernel/ptrace.c   2012-10-04 18:47:00.000000000 +0200
652 @@ -21,6 +21,7 @@
653  #include <linux/tracehook.h>
654  #include <linux/seccomp.h>
655  #include <linux/compat.h>
656 +#include <linux/vs_base.h>
657  #include <trace/syscall.h>
658  #include <asm/segment.h>
659  #include <asm/page.h>
660 diff -NurpP --minimal linux-3.6/arch/s390/kernel/syscalls.S linux-3.6-vs2.3.4.3-noxfs-nocow/arch/s390/kernel/syscalls.S
661 --- linux-3.6/arch/s390/kernel/syscalls.S       2012-01-09 16:14:06.000000000 +0100
662 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/arch/s390/kernel/syscalls.S 2012-10-04 18:47:00.000000000 +0200
663 @@ -271,7 +271,7 @@ SYSCALL(sys_clock_settime,sys_clock_sett
664  SYSCALL(sys_clock_gettime,sys_clock_gettime,sys32_clock_gettime_wrapper)       /* 260 */
665  SYSCALL(sys_clock_getres,sys_clock_getres,sys32_clock_getres_wrapper)
666  SYSCALL(sys_clock_nanosleep,sys_clock_nanosleep,sys32_clock_nanosleep_wrapper)
667 -NI_SYSCALL                                                     /* reserved for vserver */
668 +SYSCALL(sys_vserver,sys_vserver,sys32_vserver)
669  SYSCALL(sys_s390_fadvise64_64,sys_ni_syscall,sys32_fadvise64_64_wrapper)
670  SYSCALL(sys_statfs64,sys_statfs64,compat_sys_statfs64_wrapper)
671  SYSCALL(sys_fstatfs64,sys_fstatfs64,compat_sys_fstatfs64_wrapper)
672 diff -NurpP --minimal linux-3.6/arch/sh/Kconfig linux-3.6-vs2.3.4.3-noxfs-nocow/arch/sh/Kconfig
673 --- linux-3.6/arch/sh/Kconfig   2012-10-04 15:26:55.000000000 +0200
674 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/arch/sh/Kconfig     2012-10-04 18:47:00.000000000 +0200
675 @@ -940,6 +940,8 @@ source "fs/Kconfig"
676  
677  source "arch/sh/Kconfig.debug"
678  
679 +source "kernel/vserver/Kconfig"
680 +
681  source "security/Kconfig"
682  
683  source "crypto/Kconfig"
684 diff -NurpP --minimal linux-3.6/arch/sh/kernel/irq.c linux-3.6-vs2.3.4.3-noxfs-nocow/arch/sh/kernel/irq.c
685 --- linux-3.6/arch/sh/kernel/irq.c      2012-10-04 15:26:56.000000000 +0200
686 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/arch/sh/kernel/irq.c        2012-10-04 18:47:00.000000000 +0200
687 @@ -14,6 +14,7 @@
688  #include <linux/ftrace.h>
689  #include <linux/delay.h>
690  #include <linux/ratelimit.h>
691 +// #include <linux/vs_context.h>
692  #include <asm/processor.h>
693  #include <asm/machvec.h>
694  #include <asm/uaccess.h>
695 diff -NurpP --minimal linux-3.6/arch/sparc/Kconfig linux-3.6-vs2.3.4.3-noxfs-nocow/arch/sparc/Kconfig
696 --- linux-3.6/arch/sparc/Kconfig        2012-10-04 15:26:58.000000000 +0200
697 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/arch/sparc/Kconfig  2012-10-04 18:47:00.000000000 +0200
698 @@ -593,6 +593,8 @@ source "fs/Kconfig"
699  
700  source "arch/sparc/Kconfig.debug"
701  
702 +source "kernel/vserver/Kconfig"
703 +
704  source "security/Kconfig"
705  
706  source "crypto/Kconfig"
707 diff -NurpP --minimal linux-3.6/arch/sparc/include/asm/unistd.h linux-3.6-vs2.3.4.3-noxfs-nocow/arch/sparc/include/asm/unistd.h
708 --- linux-3.6/arch/sparc/include/asm/unistd.h   2012-10-04 15:26:59.000000000 +0200
709 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/arch/sparc/include/asm/unistd.h     2012-10-04 18:47:00.000000000 +0200
710 @@ -335,7 +335,7 @@
711  #define __NR_timer_getoverrun  264
712  #define __NR_timer_delete      265
713  #define __NR_timer_create      266
714 -/* #define __NR_vserver                267 Reserved for VSERVER */
715 +#define __NR_vserver           267
716  #define __NR_io_setup          268
717  #define __NR_io_destroy                269
718  #define __NR_io_submit         270
719 diff -NurpP --minimal linux-3.6/arch/sparc/kernel/systbls_32.S linux-3.6-vs2.3.4.3-noxfs-nocow/arch/sparc/kernel/systbls_32.S
720 --- linux-3.6/arch/sparc/kernel/systbls_32.S    2012-01-09 16:14:09.000000000 +0100
721 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/arch/sparc/kernel/systbls_32.S      2012-10-04 18:47:00.000000000 +0200
722 @@ -70,7 +70,7 @@ sys_call_table:
723  /*250*/        .long sys_mremap, sys_sysctl, sys_getsid, sys_fdatasync, sys_ni_syscall
724  /*255*/        .long sys_sync_file_range, sys_clock_settime, sys_clock_gettime, sys_clock_getres, sys_clock_nanosleep
725  /*260*/        .long sys_sched_getaffinity, sys_sched_setaffinity, sys_timer_settime, sys_timer_gettime, sys_timer_getoverrun
726 -/*265*/        .long sys_timer_delete, sys_timer_create, sys_nis_syscall, sys_io_setup, sys_io_destroy
727 +/*265*/        .long sys_timer_delete, sys_timer_create, sys_vserver, sys_io_setup, sys_io_destroy
728  /*270*/        .long sys_io_submit, sys_io_cancel, sys_io_getevents, sys_mq_open, sys_mq_unlink
729  /*275*/        .long sys_mq_timedsend, sys_mq_timedreceive, sys_mq_notify, sys_mq_getsetattr, sys_waitid
730  /*280*/        .long sys_tee, sys_add_key, sys_request_key, sys_keyctl, sys_openat
731 diff -NurpP --minimal linux-3.6/arch/sparc/kernel/systbls_64.S linux-3.6-vs2.3.4.3-noxfs-nocow/arch/sparc/kernel/systbls_64.S
732 --- linux-3.6/arch/sparc/kernel/systbls_64.S    2012-07-22 23:39:00.000000000 +0200
733 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/arch/sparc/kernel/systbls_64.S      2012-10-04 18:47:00.000000000 +0200
734 @@ -71,7 +71,7 @@ sys_call_table32:
735  /*250*/        .word sys_mremap, compat_sys_sysctl, sys32_getsid, sys_fdatasync, sys_nis_syscall
736         .word sys32_sync_file_range, compat_sys_clock_settime, compat_sys_clock_gettime, compat_sys_clock_getres, sys32_clock_nanosleep
737  /*260*/        .word compat_sys_sched_getaffinity, compat_sys_sched_setaffinity, sys32_timer_settime, compat_sys_timer_gettime, sys_timer_getoverrun
738 -       .word sys_timer_delete, compat_sys_timer_create, sys_ni_syscall, compat_sys_io_setup, sys_io_destroy
739 +       .word sys_timer_delete, compat_sys_timer_create, sys32_vserver, compat_sys_io_setup, sys_io_destroy
740  /*270*/        .word sys32_io_submit, sys_io_cancel, compat_sys_io_getevents, sys32_mq_open, sys_mq_unlink
741         .word compat_sys_mq_timedsend, compat_sys_mq_timedreceive, compat_sys_mq_notify, compat_sys_mq_getsetattr, compat_sys_waitid
742  /*280*/        .word sys32_tee, sys_add_key, sys_request_key, compat_sys_keyctl, compat_sys_openat
743 @@ -148,7 +148,7 @@ sys_call_table:
744  /*250*/        .word sys_64_mremap, sys_sysctl, sys_getsid, sys_fdatasync, sys_nis_syscall
745         .word sys_sync_file_range, sys_clock_settime, sys_clock_gettime, sys_clock_getres, sys_clock_nanosleep
746  /*260*/        .word sys_sched_getaffinity, sys_sched_setaffinity, sys_timer_settime, sys_timer_gettime, sys_timer_getoverrun
747 -       .word sys_timer_delete, sys_timer_create, sys_ni_syscall, sys_io_setup, sys_io_destroy
748 +       .word sys_timer_delete, sys_timer_create, sys_vserver, sys_io_setup, sys_io_destroy
749  /*270*/        .word sys_io_submit, sys_io_cancel, sys_io_getevents, sys_mq_open, sys_mq_unlink
750         .word sys_mq_timedsend, sys_mq_timedreceive, sys_mq_notify, sys_mq_getsetattr, sys_waitid
751  /*280*/        .word sys_tee, sys_add_key, sys_request_key, sys_keyctl, sys_openat
752 diff -NurpP --minimal linux-3.6/arch/um/Kconfig.rest linux-3.6-vs2.3.4.3-noxfs-nocow/arch/um/Kconfig.rest
753 --- linux-3.6/arch/um/Kconfig.rest      2012-01-09 16:14:09.000000000 +0100
754 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/arch/um/Kconfig.rest        2012-10-04 18:47:00.000000000 +0200
755 @@ -12,6 +12,8 @@ source "arch/um/Kconfig.net"
756  
757  source "fs/Kconfig"
758  
759 +source "kernel/vserver/Kconfig"
760 +
761  source "security/Kconfig"
762  
763  source "crypto/Kconfig"
764 diff -NurpP --minimal linux-3.6/arch/um/include/shared/kern_constants.h linux-3.6-vs2.3.4.3-noxfs-nocow/arch/um/include/shared/kern_constants.h
765 --- linux-3.6/arch/um/include/shared/kern_constants.h   1970-01-01 01:00:00.000000000 +0100
766 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/arch/um/include/shared/kern_constants.h     2012-10-04 18:47:00.000000000 +0200
767 @@ -0,0 +1 @@
768 +#include "../../../../include/generated/asm-offsets.h"
769 diff -NurpP --minimal linux-3.6/arch/um/include/shared/user_constants.h linux-3.6-vs2.3.4.3-noxfs-nocow/arch/um/include/shared/user_constants.h
770 --- linux-3.6/arch/um/include/shared/user_constants.h   1970-01-01 01:00:00.000000000 +0100
771 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/arch/um/include/shared/user_constants.h     2012-10-04 18:47:00.000000000 +0200
772 @@ -0,0 +1,40 @@
773 +/*
774 + * DO NOT MODIFY.
775 + *
776 + * This file was generated by arch/um/Makefile
777 + *
778 + */
779 +
780 +#define HOST_SC_CR2 176 /* offsetof(struct sigcontext, cr2)    # */
781 +#define HOST_SC_ERR 152 /* offsetof(struct sigcontext, err)    # */
782 +#define HOST_SC_TRAPNO 160 /* offsetof(struct sigcontext, trapno)      # */
783 +#define HOST_FP_SIZE 64 /* sizeof(struct _fpstate) / sizeof(unsigned long)     # */
784 +#define HOST_RBX 5 /* RBX      # */
785 +#define HOST_RCX 11 /* RCX     # */
786 +#define HOST_RDI 14 /* RDI     # */
787 +#define HOST_RSI 13 /* RSI     # */
788 +#define HOST_RDX 12 /* RDX     # */
789 +#define HOST_RBP 4 /* RBP      # */
790 +#define HOST_RAX 10 /* RAX     # */
791 +#define HOST_R8 9 /* R8        # */
792 +#define HOST_R9 8 /* R9        # */
793 +#define HOST_R10 7 /* R10      # */
794 +#define HOST_R11 6 /* R11      # */
795 +#define HOST_R12 3 /* R12      # */
796 +#define HOST_R13 2 /* R13      # */
797 +#define HOST_R14 1 /* R14      # */
798 +#define HOST_R15 0 /* R15      # */
799 +#define HOST_ORIG_RAX 15 /* ORIG_RAX   # */
800 +#define HOST_CS 17 /* CS       # */
801 +#define HOST_SS 20 /* SS       # */
802 +#define HOST_EFLAGS 18 /* EFLAGS       # */
803 +#define HOST_IP 16 /* RIP      # */
804 +#define HOST_SP 19 /* RSP      # */
805 +#define UM_FRAME_SIZE 216 /* sizeof(struct user_regs_struct)   # */
806 +#define UM_POLLIN 1 /* POLLIN  # */
807 +#define UM_POLLPRI 2 /* POLLPRI        # */
808 +#define UM_POLLOUT 4 /* POLLOUT        # */
809 +#define UM_PROT_READ 1 /* PROT_READ    # */
810 +#define UM_PROT_WRITE 2 /* PROT_WRITE  # */
811 +#define UM_PROT_EXEC 4 /* PROT_EXEC    # */
812 +
813 diff -NurpP --minimal linux-3.6/arch/x86/Kconfig linux-3.6-vs2.3.4.3-noxfs-nocow/arch/x86/Kconfig
814 --- linux-3.6/arch/x86/Kconfig  2012-10-04 15:27:00.000000000 +0200
815 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/arch/x86/Kconfig    2012-10-04 18:47:00.000000000 +0200
816 @@ -2228,6 +2228,8 @@ source "fs/Kconfig"
817  
818  source "arch/x86/Kconfig.debug"
819  
820 +source "kernel/vserver/Kconfig"
821 +
822  source "security/Kconfig"
823  
824  source "crypto/Kconfig"
825 diff -NurpP --minimal linux-3.6/arch/x86/syscalls/syscall_32.tbl linux-3.6-vs2.3.4.3-noxfs-nocow/arch/x86/syscalls/syscall_32.tbl
826 --- linux-3.6/arch/x86/syscalls/syscall_32.tbl  2012-07-22 23:39:02.000000000 +0200
827 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/arch/x86/syscalls/syscall_32.tbl    2012-10-04 18:47:00.000000000 +0200
828 @@ -279,7 +279,7 @@
829  270    i386    tgkill                  sys_tgkill
830  271    i386    utimes                  sys_utimes                      compat_sys_utimes
831  272    i386    fadvise64_64            sys_fadvise64_64                sys32_fadvise64_64
832 -273    i386    vserver
833 +273    i386    vserver                 sys_vserver                     sys32_vserver
834  274    i386    mbind                   sys_mbind
835  275    i386    get_mempolicy           sys_get_mempolicy               compat_sys_get_mempolicy
836  276    i386    set_mempolicy           sys_set_mempolicy
837 diff -NurpP --minimal linux-3.6/arch/x86/syscalls/syscall_64.tbl linux-3.6-vs2.3.4.3-noxfs-nocow/arch/x86/syscalls/syscall_64.tbl
838 --- linux-3.6/arch/x86/syscalls/syscall_64.tbl  2012-10-04 15:27:01.000000000 +0200
839 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/arch/x86/syscalls/syscall_64.tbl    2012-10-04 18:47:00.000000000 +0200
840 @@ -242,7 +242,7 @@
841  233    common  epoll_ctl               sys_epoll_ctl
842  234    common  tgkill                  sys_tgkill
843  235    common  utimes                  sys_utimes
844 -236    64      vserver
845 +236    64      vserver                 sys_vserver
846  237    common  mbind                   sys_mbind
847  238    common  set_mempolicy           sys_set_mempolicy
848  239    common  get_mempolicy           sys_get_mempolicy
849 diff -NurpP --minimal linux-3.6/drivers/block/Kconfig linux-3.6-vs2.3.4.3-noxfs-nocow/drivers/block/Kconfig
850 --- linux-3.6/drivers/block/Kconfig     2012-05-21 18:06:43.000000000 +0200
851 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/drivers/block/Kconfig       2012-10-04 18:47:00.000000000 +0200
852 @@ -290,6 +290,13 @@ config BLK_DEV_CRYPTOLOOP
853  
854  source "drivers/block/drbd/Kconfig"
855  
856 +config BLK_DEV_VROOT
857 +       tristate "Virtual Root device support"
858 +       depends on QUOTACTL
859 +       ---help---
860 +         Saying Y here will allow you to use quota/fs ioctls on a shared
861 +         partition within a virtual server without compromising security.
862 +
863  config BLK_DEV_NBD
864         tristate "Network block device support"
865         depends on NET
866 diff -NurpP --minimal linux-3.6/drivers/block/Makefile linux-3.6-vs2.3.4.3-noxfs-nocow/drivers/block/Makefile
867 --- linux-3.6/drivers/block/Makefile    2012-03-19 19:46:52.000000000 +0100
868 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/drivers/block/Makefile      2012-10-04 18:47:00.000000000 +0200
869 @@ -35,6 +35,7 @@ obj-$(CONFIG_VIODASD)         += viodasd.o
870  obj-$(CONFIG_BLK_DEV_SX8)      += sx8.o
871  obj-$(CONFIG_BLK_DEV_UB)       += ub.o
872  obj-$(CONFIG_BLK_DEV_HD)       += hd.o
873 +obj-$(CONFIG_BLK_DEV_VROOT)    += vroot.o
874  
875  obj-$(CONFIG_XEN_BLKDEV_FRONTEND)      += xen-blkfront.o
876  obj-$(CONFIG_XEN_BLKDEV_BACKEND)       += xen-blkback/
877 diff -NurpP --minimal linux-3.6/drivers/block/loop.c linux-3.6-vs2.3.4.3-noxfs-nocow/drivers/block/loop.c
878 --- linux-3.6/drivers/block/loop.c      2012-07-22 23:39:02.000000000 +0200
879 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/drivers/block/loop.c        2012-10-04 18:47:00.000000000 +0200
880 @@ -76,6 +76,7 @@
881  #include <linux/sysfs.h>
882  #include <linux/miscdevice.h>
883  #include <linux/falloc.h>
884 +#include <linux/vs_context.h>
885  
886  #include <asm/uaccess.h>
887  
888 @@ -869,6 +870,7 @@ static int loop_set_fd(struct loop_devic
889         lo->lo_blocksize = lo_blocksize;
890         lo->lo_device = bdev;
891         lo->lo_flags = lo_flags;
892 +       lo->lo_xid = vx_current_xid();
893         lo->lo_backing_file = file;
894         lo->transfer = transfer_none;
895         lo->ioctl = NULL;
896 @@ -1001,6 +1003,7 @@ static int loop_clr_fd(struct loop_devic
897         lo->lo_sizelimit = 0;
898         lo->lo_encrypt_key_size = 0;
899         lo->lo_thread = NULL;
900 +       lo->lo_xid = 0;
901         memset(lo->lo_encrypt_key, 0, LO_KEY_SIZE);
902         memset(lo->lo_crypt_name, 0, LO_NAME_SIZE);
903         memset(lo->lo_file_name, 0, LO_NAME_SIZE);
904 @@ -1042,7 +1045,7 @@ loop_set_status(struct loop_device *lo, 
905  
906         if (lo->lo_encrypt_key_size &&
907             lo->lo_key_owner != uid &&
908 -           !capable(CAP_SYS_ADMIN))
909 +           !vx_capable(CAP_SYS_ADMIN, VXC_ADMIN_CLOOP))
910                 return -EPERM;
911         if (lo->lo_state != Lo_bound)
912                 return -ENXIO;
913 @@ -1132,7 +1135,8 @@ loop_get_status(struct loop_device *lo, 
914         memcpy(info->lo_crypt_name, lo->lo_crypt_name, LO_NAME_SIZE);
915         info->lo_encrypt_type =
916                 lo->lo_encryption ? lo->lo_encryption->number : 0;
917 -       if (lo->lo_encrypt_key_size && capable(CAP_SYS_ADMIN)) {
918 +       if (lo->lo_encrypt_key_size &&
919 +               vx_capable(CAP_SYS_ADMIN, VXC_ADMIN_CLOOP)) {
920                 info->lo_encrypt_key_size = lo->lo_encrypt_key_size;
921                 memcpy(info->lo_encrypt_key, lo->lo_encrypt_key,
922                        lo->lo_encrypt_key_size);
923 @@ -1492,6 +1496,11 @@ static int lo_open(struct block_device *
924                 goto out;
925         }
926  
927 +       if (!vx_check(lo->lo_xid, VS_IDENT|VS_HOSTID|VS_ADMIN_P)) {
928 +               err = -EACCES;
929 +               goto out;
930 +       }
931 +
932         mutex_lock(&lo->lo_ctl_mutex);
933         lo->lo_refcnt++;
934         mutex_unlock(&lo->lo_ctl_mutex);
935 diff -NurpP --minimal linux-3.6/drivers/block/vroot.c linux-3.6-vs2.3.4.3-noxfs-nocow/drivers/block/vroot.c
936 --- linux-3.6/drivers/block/vroot.c     1970-01-01 01:00:00.000000000 +0100
937 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/drivers/block/vroot.c       2012-10-04 18:47:00.000000000 +0200
938 @@ -0,0 +1,291 @@
939 +/*
940 + *  linux/drivers/block/vroot.c
941 + *
942 + *  written by Herbert Pötzl, 9/11/2002
943 + *  ported to 2.6.10 by Herbert Pötzl, 30/12/2004
944 + *
945 + *  based on the loop.c code by Theodore Ts'o.
946 + *
947 + * Copyright (C) 2002-2007 by Herbert Pötzl.
948 + * Redistribution of this file is permitted under the
949 + * GNU General Public License.
950 + *
951 + */
952 +
953 +#include <linux/module.h>
954 +#include <linux/moduleparam.h>
955 +#include <linux/file.h>
956 +#include <linux/major.h>
957 +#include <linux/blkdev.h>
958 +#include <linux/slab.h>
959 +
960 +#include <linux/vroot.h>
961 +#include <linux/vs_context.h>
962 +
963 +
964 +static int max_vroot = 8;
965 +
966 +static struct vroot_device *vroot_dev;
967 +static struct gendisk **disks;
968 +
969 +
970 +static int vroot_set_dev(
971 +       struct vroot_device *vr,
972 +       struct block_device *bdev,
973 +       unsigned int arg)
974 +{
975 +       struct block_device *real_bdev;
976 +       struct file *file;
977 +       struct inode *inode;
978 +       int error;
979 +
980 +       error = -EBUSY;
981 +       if (vr->vr_state != Vr_unbound)
982 +               goto out;
983 +
984 +       error = -EBADF;
985 +       file = fget(arg);
986 +       if (!file)
987 +               goto out;
988 +
989 +       error = -EINVAL;
990 +       inode = file->f_dentry->d_inode;
991 +
992 +
993 +       if (S_ISBLK(inode->i_mode)) {
994 +               real_bdev = inode->i_bdev;
995 +               vr->vr_device = real_bdev;
996 +               __iget(real_bdev->bd_inode);
997 +       } else
998 +               goto out_fput;
999 +
1000 +       vxdprintk(VXD_CBIT(misc, 0),
1001 +               "vroot[%d]_set_dev: dev=" VXF_DEV,
1002 +               vr->vr_number, VXD_DEV(real_bdev));
1003 +
1004 +       vr->vr_state = Vr_bound;
1005 +       error = 0;
1006 +
1007 + out_fput:
1008 +       fput(file);
1009 + out:
1010 +       return error;
1011 +}
1012 +
1013 +static int vroot_clr_dev(
1014 +       struct vroot_device *vr,
1015 +       struct block_device *bdev)
1016 +{
1017 +       struct block_device *real_bdev;
1018 +
1019 +       if (vr->vr_state != Vr_bound)
1020 +               return -ENXIO;
1021 +       if (vr->vr_refcnt > 1)  /* we needed one fd for the ioctl */
1022 +               return -EBUSY;
1023 +
1024 +       real_bdev = vr->vr_device;
1025 +
1026 +       vxdprintk(VXD_CBIT(misc, 0),
1027 +               "vroot[%d]_clr_dev: dev=" VXF_DEV,
1028 +               vr->vr_number, VXD_DEV(real_bdev));
1029 +
1030 +       bdput(real_bdev);
1031 +       vr->vr_state = Vr_unbound;
1032 +       vr->vr_device = NULL;
1033 +       return 0;
1034 +}
1035 +
1036 +
1037 +static int vr_ioctl(struct block_device *bdev, fmode_t mode,
1038 +       unsigned int cmd, unsigned long arg)
1039 +{
1040 +       struct vroot_device *vr = bdev->bd_disk->private_data;
1041 +       int err;
1042 +
1043 +       down(&vr->vr_ctl_mutex);
1044 +       switch (cmd) {
1045 +       case VROOT_SET_DEV:
1046 +               err = vroot_set_dev(vr, bdev, arg);
1047 +               break;
1048 +       case VROOT_CLR_DEV:
1049 +               err = vroot_clr_dev(vr, bdev);
1050 +               break;
1051 +       default:
1052 +               err = -EINVAL;
1053 +               break;
1054 +       }
1055 +       up(&vr->vr_ctl_mutex);
1056 +       return err;
1057 +}
1058 +
1059 +static int vr_open(struct block_device *bdev, fmode_t mode)
1060 +{
1061 +       struct vroot_device *vr = bdev->bd_disk->private_data;
1062 +
1063 +       down(&vr->vr_ctl_mutex);
1064 +       vr->vr_refcnt++;
1065 +       up(&vr->vr_ctl_mutex);
1066 +       return 0;
1067 +}
1068 +
1069 +static int vr_release(struct gendisk *disk, fmode_t mode)
1070 +{
1071 +       struct vroot_device *vr = disk->private_data;
1072 +
1073 +       down(&vr->vr_ctl_mutex);
1074 +       --vr->vr_refcnt;
1075 +       up(&vr->vr_ctl_mutex);
1076 +       return 0;
1077 +}
1078 +
1079 +static struct block_device_operations vr_fops = {
1080 +       .owner =        THIS_MODULE,
1081 +       .open =         vr_open,
1082 +       .release =      vr_release,
1083 +       .ioctl =        vr_ioctl,
1084 +};
1085 +
1086 +static void vroot_make_request(struct request_queue *q, struct bio *bio)
1087 +{
1088 +       printk("vroot_make_request %p, %p\n", q, bio);
1089 +       bio_io_error(bio);
1090 +}
1091 +
1092 +struct block_device *__vroot_get_real_bdev(struct block_device *bdev)
1093 +{
1094 +       struct inode *inode = bdev->bd_inode;
1095 +       struct vroot_device *vr;
1096 +       struct block_device *real_bdev;
1097 +       int minor = iminor(inode);
1098 +
1099 +       vr = &vroot_dev[minor];
1100 +       real_bdev = vr->vr_device;
1101 +
1102 +       vxdprintk(VXD_CBIT(misc, 0),
1103 +               "vroot[%d]_get_real_bdev: dev=" VXF_DEV,
1104 +               vr->vr_number, VXD_DEV(real_bdev));
1105 +
1106 +       if (vr->vr_state != Vr_bound)
1107 +               return ERR_PTR(-ENXIO);
1108 +
1109 +       __iget(real_bdev->bd_inode);
1110 +       return real_bdev;
1111 +}
1112 +
1113 +
1114 +
1115 +/*
1116 + * And now the modules code and kernel interface.
1117 + */
1118 +
1119 +module_param(max_vroot, int, 0);
1120 +
1121 +MODULE_PARM_DESC(max_vroot, "Maximum number of vroot devices (1-256)");
1122 +MODULE_LICENSE("GPL");
1123 +MODULE_ALIAS_BLOCKDEV_MAJOR(VROOT_MAJOR);
1124 +
1125 +MODULE_AUTHOR ("Herbert Pötzl");
1126 +MODULE_DESCRIPTION ("Virtual Root Device Mapper");
1127 +
1128 +
1129 +int __init vroot_init(void)
1130 +{
1131 +       int err, i;
1132 +
1133 +       if (max_vroot < 1 || max_vroot > 256) {
1134 +               max_vroot = MAX_VROOT_DEFAULT;
1135 +               printk(KERN_WARNING "vroot: invalid max_vroot "
1136 +                       "(must be between 1 and 256), "
1137 +                       "using default (%d)\n", max_vroot);
1138 +       }
1139 +
1140 +       if (register_blkdev(VROOT_MAJOR, "vroot"))
1141 +               return -EIO;
1142 +
1143 +       err = -ENOMEM;
1144 +       vroot_dev = kmalloc(max_vroot * sizeof(struct vroot_device), GFP_KERNEL);
1145 +       if (!vroot_dev)
1146 +               goto out_mem1;
1147 +       memset(vroot_dev, 0, max_vroot * sizeof(struct vroot_device));
1148 +
1149 +       disks = kmalloc(max_vroot * sizeof(struct gendisk *), GFP_KERNEL);
1150 +       if (!disks)
1151 +               goto out_mem2;
1152 +
1153 +       for (i = 0; i < max_vroot; i++) {
1154 +               disks[i] = alloc_disk(1);
1155 +               if (!disks[i])
1156 +                       goto out_mem3;
1157 +               disks[i]->queue = blk_alloc_queue(GFP_KERNEL);
1158 +               if (!disks[i]->queue)
1159 +                       goto out_mem3;
1160 +               blk_queue_make_request(disks[i]->queue, vroot_make_request);
1161 +       }
1162 +
1163 +       for (i = 0; i < max_vroot; i++) {
1164 +               struct vroot_device *vr = &vroot_dev[i];
1165 +               struct gendisk *disk = disks[i];
1166 +
1167 +               memset(vr, 0, sizeof(*vr));
1168 +               sema_init(&vr->vr_ctl_mutex, 1);
1169 +               vr->vr_number = i;
1170 +               disk->major = VROOT_MAJOR;
1171 +               disk->first_minor = i;
1172 +               disk->fops = &vr_fops;
1173 +               sprintf(disk->disk_name, "vroot%d", i);
1174 +               disk->private_data = vr;
1175 +       }
1176 +
1177 +       err = register_vroot_grb(&__vroot_get_real_bdev);
1178 +       if (err)
1179 +               goto out_mem3;
1180 +
1181 +       for (i = 0; i < max_vroot; i++)
1182 +               add_disk(disks[i]);
1183 +       printk(KERN_INFO "vroot: loaded (max %d devices)\n", max_vroot);
1184 +       return 0;
1185 +
1186 +out_mem3:
1187 +       while (i--)
1188 +               put_disk(disks[i]);
1189 +       kfree(disks);
1190 +out_mem2:
1191 +       kfree(vroot_dev);
1192 +out_mem1:
1193 +       unregister_blkdev(VROOT_MAJOR, "vroot");
1194 +       printk(KERN_ERR "vroot: ran out of memory\n");
1195 +       return err;
1196 +}
1197 +
1198 +void vroot_exit(void)
1199 +{
1200 +       int i;
1201 +
1202 +       if (unregister_vroot_grb(&__vroot_get_real_bdev))
1203 +               printk(KERN_WARNING "vroot: cannot unregister grb\n");
1204 +
1205 +       for (i = 0; i < max_vroot; i++) {
1206 +               del_gendisk(disks[i]);
1207 +               put_disk(disks[i]);
1208 +       }
1209 +       unregister_blkdev(VROOT_MAJOR, "vroot");
1210 +
1211 +       kfree(disks);
1212 +       kfree(vroot_dev);
1213 +}
1214 +
1215 +module_init(vroot_init);
1216 +module_exit(vroot_exit);
1217 +
1218 +#ifndef MODULE
1219 +
1220 +static int __init max_vroot_setup(char *str)
1221 +{
1222 +       max_vroot = simple_strtol(str, NULL, 0);
1223 +       return 1;
1224 +}
1225 +
1226 +__setup("max_vroot=", max_vroot_setup);
1227 +
1228 +#endif
1229 +
1230 diff -NurpP --minimal linux-3.6/drivers/infiniband/Kconfig linux-3.6-vs2.3.4.3-noxfs-nocow/drivers/infiniband/Kconfig
1231 --- linux-3.6/drivers/infiniband/Kconfig        2012-07-22 23:39:06.000000000 +0200
1232 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/drivers/infiniband/Kconfig  2012-10-04 18:47:00.000000000 +0200
1233 @@ -39,7 +39,7 @@ config INFINIBAND_USER_MEM
1234  config INFINIBAND_ADDR_TRANS
1235         bool
1236         depends on INET
1237 -       depends on !(INFINIBAND = y && IPV6 = m)
1238 +       depends on !(INFINIBAND = y && IPV6 = y)
1239         default y
1240  
1241  source "drivers/infiniband/hw/mthca/Kconfig"
1242 diff -NurpP --minimal linux-3.6/drivers/infiniband/core/addr.c linux-3.6-vs2.3.4.3-noxfs-nocow/drivers/infiniband/core/addr.c
1243 --- linux-3.6/drivers/infiniband/core/addr.c    2012-10-04 15:27:10.000000000 +0200
1244 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/drivers/infiniband/core/addr.c      2012-10-04 18:47:00.000000000 +0200
1245 @@ -263,7 +263,7 @@ static int addr6_resolve(struct sockaddr
1246  
1247         if (ipv6_addr_any(&fl6.saddr)) {
1248                 ret = ipv6_dev_get_saddr(&init_net, ip6_dst_idev(dst)->dev,
1249 -                                        &fl6.daddr, 0, &fl6.saddr);
1250 +                                        &fl6.daddr, 0, &fl6.saddr, NULL);
1251                 if (ret)
1252                         goto put;
1253  
1254 diff -NurpP --minimal linux-3.6/drivers/md/dm-ioctl.c linux-3.6-vs2.3.4.3-noxfs-nocow/drivers/md/dm-ioctl.c
1255 --- linux-3.6/drivers/md/dm-ioctl.c     2012-10-04 15:27:11.000000000 +0200
1256 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/drivers/md/dm-ioctl.c       2012-10-04 18:47:00.000000000 +0200
1257 @@ -16,6 +16,7 @@
1258  #include <linux/dm-ioctl.h>
1259  #include <linux/hdreg.h>
1260  #include <linux/compat.h>
1261 +#include <linux/vs_context.h>
1262  
1263  #include <asm/uaccess.h>
1264  
1265 @@ -106,7 +107,8 @@ static struct hash_cell *__get_name_cell
1266         unsigned int h = hash_str(str);
1267  
1268         list_for_each_entry (hc, _name_buckets + h, name_list)
1269 -               if (!strcmp(hc->name, str)) {
1270 +               if (vx_check(dm_get_xid(hc->md), VS_WATCH_P | VS_IDENT) &&
1271 +                       !strcmp(hc->name, str)) {
1272                         dm_get(hc->md);
1273                         return hc;
1274                 }
1275 @@ -120,7 +122,8 @@ static struct hash_cell *__get_uuid_cell
1276         unsigned int h = hash_str(str);
1277  
1278         list_for_each_entry (hc, _uuid_buckets + h, uuid_list)
1279 -               if (!strcmp(hc->uuid, str)) {
1280 +               if (vx_check(dm_get_xid(hc->md), VS_WATCH_P | VS_IDENT) &&
1281 +                       !strcmp(hc->uuid, str)) {
1282                         dm_get(hc->md);
1283                         return hc;
1284                 }
1285 @@ -131,13 +134,15 @@ static struct hash_cell *__get_uuid_cell
1286  static struct hash_cell *__get_dev_cell(uint64_t dev)
1287  {
1288         struct mapped_device *md;
1289 -       struct hash_cell *hc;
1290 +       struct hash_cell *hc = NULL;
1291  
1292         md = dm_get_md(huge_decode_dev(dev));
1293         if (!md)
1294                 return NULL;
1295  
1296 -       hc = dm_get_mdptr(md);
1297 +       if (vx_check(dm_get_xid(md), VS_WATCH_P | VS_IDENT))
1298 +               hc = dm_get_mdptr(md);
1299 +
1300         if (!hc) {
1301                 dm_put(md);
1302                 return NULL;
1303 @@ -445,6 +450,9 @@ typedef int (*ioctl_fn)(struct dm_ioctl 
1304  
1305  static int remove_all(struct dm_ioctl *param, size_t param_size)
1306  {
1307 +       if (!vx_check(0, VS_ADMIN))
1308 +               return -EPERM;
1309 +
1310         dm_hash_remove_all(1);
1311         param->data_size = 0;
1312         return 0;
1313 @@ -492,6 +500,8 @@ static int list_devices(struct dm_ioctl 
1314          */
1315         for (i = 0; i < NUM_BUCKETS; i++) {
1316                 list_for_each_entry (hc, _name_buckets + i, name_list) {
1317 +                       if (!vx_check(dm_get_xid(hc->md), VS_WATCH_P | VS_IDENT))
1318 +                               continue;
1319                         needed += sizeof(struct dm_name_list);
1320                         needed += strlen(hc->name) + 1;
1321                         needed += ALIGN_MASK;
1322 @@ -515,6 +525,8 @@ static int list_devices(struct dm_ioctl 
1323          */
1324         for (i = 0; i < NUM_BUCKETS; i++) {
1325                 list_for_each_entry (hc, _name_buckets + i, name_list) {
1326 +                       if (!vx_check(dm_get_xid(hc->md), VS_WATCH_P | VS_IDENT))
1327 +                               continue;
1328                         if (old_nl)
1329                                 old_nl->next = (uint32_t) ((void *) nl -
1330                                                            (void *) old_nl);
1331 @@ -1619,8 +1631,8 @@ static int ctl_ioctl(uint command, struc
1332         ioctl_fn fn = NULL;
1333         size_t input_param_size;
1334  
1335 -       /* only root can play with this */
1336 -       if (!capable(CAP_SYS_ADMIN))
1337 +       /* only root and certain contexts can play with this */
1338 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_ADMIN_MAPPER))
1339                 return -EACCES;
1340  
1341         if (_IOC_TYPE(command) != DM_IOCTL)
1342 diff -NurpP --minimal linux-3.6/drivers/md/dm.c linux-3.6-vs2.3.4.3-noxfs-nocow/drivers/md/dm.c
1343 --- linux-3.6/drivers/md/dm.c   2012-10-04 15:27:11.000000000 +0200
1344 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/drivers/md/dm.c     2012-10-04 18:47:00.000000000 +0200
1345 @@ -19,6 +19,7 @@
1346  #include <linux/idr.h>
1347  #include <linux/hdreg.h>
1348  #include <linux/delay.h>
1349 +#include <linux/vs_base.h>
1350  
1351  #include <trace/events/block.h>
1352  
1353 @@ -131,6 +132,7 @@ struct mapped_device {
1354         rwlock_t map_lock;
1355         atomic_t holders;
1356         atomic_t open_count;
1357 +       xid_t xid;
1358  
1359         unsigned long flags;
1360  
1361 @@ -343,6 +345,7 @@ int dm_deleting_md(struct mapped_device 
1362  static int dm_blk_open(struct block_device *bdev, fmode_t mode)
1363  {
1364         struct mapped_device *md;
1365 +       int ret = -ENXIO;
1366  
1367         spin_lock(&_minor_lock);
1368  
1369 @@ -351,18 +354,19 @@ static int dm_blk_open(struct block_devi
1370                 goto out;
1371  
1372         if (test_bit(DMF_FREEING, &md->flags) ||
1373 -           dm_deleting_md(md)) {
1374 -               md = NULL;
1375 +           dm_deleting_md(md))
1376 +               goto out;
1377 +
1378 +       ret = -EACCES;
1379 +       if (!vx_check(md->xid, VS_IDENT|VS_HOSTID))
1380                 goto out;
1381 -       }
1382  
1383         dm_get(md);
1384         atomic_inc(&md->open_count);
1385 -
1386 +       ret = 0;
1387  out:
1388         spin_unlock(&_minor_lock);
1389 -
1390 -       return md ? 0 : -ENXIO;
1391 +       return ret;
1392  }
1393  
1394  static int dm_blk_close(struct gendisk *disk, fmode_t mode)
1395 @@ -583,6 +587,14 @@ int dm_set_geometry(struct mapped_device
1396         return 0;
1397  }
1398  
1399 +/*
1400 + * Get the xid associated with a dm device
1401 + */
1402 +xid_t dm_get_xid(struct mapped_device *md)
1403 +{
1404 +       return md->xid;
1405 +}
1406 +
1407  /*-----------------------------------------------------------------
1408   * CRUD START:
1409   *   A more elegant soln is in the works that uses the queue
1410 @@ -1892,6 +1904,7 @@ static struct mapped_device *alloc_dev(i
1411         INIT_LIST_HEAD(&md->uevent_list);
1412         spin_lock_init(&md->uevent_lock);
1413  
1414 +       md->xid = vx_current_xid();
1415         md->queue = blk_alloc_queue(GFP_KERNEL);
1416         if (!md->queue)
1417                 goto bad_queue;
1418 diff -NurpP --minimal linux-3.6/drivers/md/dm.h linux-3.6-vs2.3.4.3-noxfs-nocow/drivers/md/dm.h
1419 --- linux-3.6/drivers/md/dm.h   2012-10-04 15:27:11.000000000 +0200
1420 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/drivers/md/dm.h     2012-10-04 18:47:00.000000000 +0200
1421 @@ -46,6 +46,8 @@ struct dm_dev_internal {
1422  struct dm_table;
1423  struct dm_md_mempools;
1424  
1425 +xid_t dm_get_xid(struct mapped_device *md);
1426 +
1427  /*-----------------------------------------------------------------
1428   * Internal table functions.
1429   *---------------------------------------------------------------*/
1430 diff -NurpP --minimal linux-3.6/drivers/net/tun.c linux-3.6-vs2.3.4.3-noxfs-nocow/drivers/net/tun.c
1431 --- linux-3.6/drivers/net/tun.c 2012-10-04 15:27:20.000000000 +0200
1432 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/drivers/net/tun.c   2012-10-04 18:47:00.000000000 +0200
1433 @@ -64,6 +64,7 @@
1434  #include <linux/nsproxy.h>
1435  #include <linux/virtio_net.h>
1436  #include <linux/rcupdate.h>
1437 +#include <linux/vs_network.h>
1438  #include <net/net_namespace.h>
1439  #include <net/netns/generic.h>
1440  #include <net/rtnetlink.h>
1441 @@ -122,6 +123,7 @@ struct tun_struct {
1442         unsigned int            flags;
1443         uid_t                   owner;
1444         gid_t                   group;
1445 +       nid_t                   nid;
1446  
1447         struct net_device       *dev;
1448         netdev_features_t       set_features;
1449 @@ -1033,6 +1035,7 @@ static void tun_setup(struct net_device 
1450  
1451         tun->owner = -1;
1452         tun->group = -1;
1453 +       tun->nid = current->nid;
1454  
1455         dev->ethtool_ops = &tun_ethtool_ops;
1456         dev->destructor = tun_free_netdev;
1457 @@ -1191,7 +1194,7 @@ static int tun_set_iff(struct net *net, 
1458  
1459                 if (((tun->owner != -1 && cred->euid != tun->owner) ||
1460                      (tun->group != -1 && !in_egroup_p(tun->group))) &&
1461 -                   !capable(CAP_NET_ADMIN))
1462 +               !cap_raised(current_cap(), CAP_NET_ADMIN))
1463                         return -EPERM;
1464                 err = security_tun_dev_attach(tun->socket.sk);
1465                 if (err < 0)
1466 @@ -1205,7 +1208,7 @@ static int tun_set_iff(struct net *net, 
1467                 char *name;
1468                 unsigned long flags = 0;
1469  
1470 -               if (!capable(CAP_NET_ADMIN))
1471 +               if (!nx_capable(CAP_NET_ADMIN, NXC_TUN_CREATE))
1472                         return -EPERM;
1473                 err = security_tun_dev_create();
1474                 if (err < 0)
1475 @@ -1276,6 +1279,9 @@ static int tun_set_iff(struct net *net, 
1476  
1477                 sk->sk_destruct = tun_sock_destruct;
1478  
1479 +               if (!nx_check(tun->nid, VS_IDENT | VS_HOSTID | VS_ADMIN_P))
1480 +                       return -EPERM;
1481 +
1482                 err = tun_attach(tun, file);
1483                 if (err < 0)
1484                         goto failed;
1485 @@ -1459,6 +1465,16 @@ static long __tun_chr_ioctl(struct file 
1486                 tun_debug(KERN_INFO, tun, "group set to %d\n", tun->group);
1487                 break;
1488  
1489 +       case TUNSETNID:
1490 +               if (!capable(CAP_CONTEXT))
1491 +                       return -EPERM;
1492 +
1493 +               /* Set nid owner of the device */
1494 +               tun->nid = (nid_t) arg;
1495 +
1496 +               tun_debug(KERN_INFO, tun, "nid owner set to %u\n", tun->nid);
1497 +               break;
1498 +
1499         case TUNSETLINK:
1500                 /* Only allow setting the type when the interface is down */
1501                 if (tun->dev->flags & IFF_UP) {
1502 diff -NurpP --minimal linux-3.6/drivers/tty/sysrq.c linux-3.6-vs2.3.4.3-noxfs-nocow/drivers/tty/sysrq.c
1503 --- linux-3.6/drivers/tty/sysrq.c       2012-05-21 18:07:16.000000000 +0200
1504 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/drivers/tty/sysrq.c 2012-10-04 18:47:00.000000000 +0200
1505 @@ -41,6 +41,7 @@
1506  #include <linux/slab.h>
1507  #include <linux/input.h>
1508  #include <linux/uaccess.h>
1509 +#include <linux/vserver/debug.h>
1510  
1511  #include <asm/ptrace.h>
1512  #include <asm/irq_regs.h>
1513 @@ -398,6 +399,21 @@ static struct sysrq_key_op sysrq_unrt_op
1514         .enable_mask    = SYSRQ_ENABLE_RTNICE,
1515  };
1516  
1517 +
1518 +#ifdef CONFIG_VSERVER_DEBUG
1519 +static void sysrq_handle_vxinfo(int key)
1520 +{
1521 +       dump_vx_info_inactive((key == 'x') ? 0 : 1);
1522 +}
1523 +
1524 +static struct sysrq_key_op sysrq_showvxinfo_op = {
1525 +       .handler        = sysrq_handle_vxinfo,
1526 +       .help_msg       = "conteXt",
1527 +       .action_msg     = "Show Context Info",
1528 +       .enable_mask    = SYSRQ_ENABLE_DUMP,
1529 +};
1530 +#endif
1531 +
1532  /* Key Operations table and lock */
1533  static DEFINE_SPINLOCK(sysrq_key_table_lock);
1534  
1535 @@ -452,7 +468,11 @@ static struct sysrq_key_op *sysrq_key_ta
1536         NULL,                           /* v */
1537         &sysrq_showstate_blocked_op,    /* w */
1538         /* x: May be registered on ppc/powerpc for xmon */
1539 +#ifdef CONFIG_VSERVER_DEBUG
1540 +       &sysrq_showvxinfo_op,           /* x */
1541 +#else
1542         NULL,                           /* x */
1543 +#endif
1544         /* y: May be registered on sparc64 for global register dump */
1545         NULL,                           /* y */
1546         &sysrq_ftrace_dump_op,          /* z */
1547 @@ -467,6 +487,8 @@ static int sysrq_key_table_key2index(int
1548                 retval = key - '0';
1549         else if ((key >= 'a') && (key <= 'z'))
1550                 retval = key + 10 - 'a';
1551 +       else if ((key >= 'A') && (key <= 'Z'))
1552 +               retval = key + 10 - 'A';
1553         else
1554                 retval = -1;
1555         return retval;
1556 diff -NurpP --minimal linux-3.6/drivers/tty/tty_io.c linux-3.6-vs2.3.4.3-noxfs-nocow/drivers/tty/tty_io.c
1557 --- linux-3.6/drivers/tty/tty_io.c      2012-07-22 23:39:32.000000000 +0200
1558 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/drivers/tty/tty_io.c        2012-10-04 18:47:00.000000000 +0200
1559 @@ -104,6 +104,7 @@
1560  
1561  #include <linux/kmod.h>
1562  #include <linux/nsproxy.h>
1563 +#include <linux/vs_pid.h>
1564  
1565  #undef TTY_DEBUG_HANGUP
1566  
1567 @@ -2123,7 +2124,8 @@ static int tiocsti(struct tty_struct *tt
1568         char ch, mbz = 0;
1569         struct tty_ldisc *ld;
1570  
1571 -       if ((current->signal->tty != tty) && !capable(CAP_SYS_ADMIN))
1572 +       if (((current->signal->tty != tty) &&
1573 +               !vx_capable(CAP_SYS_ADMIN, VXC_TIOCSTI)))
1574                 return -EPERM;
1575         if (get_user(ch, p))
1576                 return -EFAULT;
1577 @@ -2411,6 +2413,7 @@ static int tiocspgrp(struct tty_struct *
1578                 return -ENOTTY;
1579         if (get_user(pgrp_nr, p))
1580                 return -EFAULT;
1581 +       pgrp_nr = vx_rmap_pid(pgrp_nr);
1582         if (pgrp_nr < 0)
1583                 return -EINVAL;
1584         rcu_read_lock();
1585 diff -NurpP --minimal linux-3.6/fs/attr.c linux-3.6-vs2.3.4.3-noxfs-nocow/fs/attr.c
1586 --- linux-3.6/fs/attr.c 2012-10-04 15:27:39.000000000 +0200
1587 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/fs/attr.c   2012-10-04 18:47:00.000000000 +0200
1588 @@ -14,6 +14,9 @@
1589  #include <linux/fcntl.h>
1590  #include <linux/security.h>
1591  #include <linux/evm.h>
1592 +#include <linux/proc_fs.h>
1593 +#include <linux/devpts_fs.h>
1594 +#include <linux/vs_tag.h>
1595  
1596  /**
1597   * inode_change_ok - check if attribute changes to an inode are allowed
1598 @@ -74,6 +77,10 @@ int inode_change_ok(const struct inode *
1599                         return -EPERM;
1600         }
1601  
1602 +       /* check for inode tag permission */
1603 +       if (dx_permission(inode, MAY_WRITE))
1604 +               return -EACCES;
1605 +
1606         return 0;
1607  }
1608  EXPORT_SYMBOL(inode_change_ok);
1609 @@ -144,6 +151,8 @@ void setattr_copy(struct inode *inode, c
1610                 inode->i_uid = attr->ia_uid;
1611         if (ia_valid & ATTR_GID)
1612                 inode->i_gid = attr->ia_gid;
1613 +       if ((ia_valid & ATTR_TAG) && IS_TAGGED(inode))
1614 +               inode->i_tag = attr->ia_tag;
1615         if (ia_valid & ATTR_ATIME)
1616                 inode->i_atime = timespec_trunc(attr->ia_atime,
1617                                                 inode->i_sb->s_time_gran);
1618 @@ -173,7 +182,8 @@ int notify_change(struct dentry * dentry
1619  
1620         WARN_ON_ONCE(!mutex_is_locked(&inode->i_mutex));
1621  
1622 -       if (ia_valid & (ATTR_MODE | ATTR_UID | ATTR_GID | ATTR_TIMES_SET)) {
1623 +       if (ia_valid & (ATTR_MODE | ATTR_UID | ATTR_GID |
1624 +               ATTR_TAG | ATTR_TIMES_SET)) {
1625                 if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
1626                         return -EPERM;
1627         }
1628 diff -NurpP --minimal linux-3.6/fs/block_dev.c linux-3.6-vs2.3.4.3-noxfs-nocow/fs/block_dev.c
1629 --- linux-3.6/fs/block_dev.c    2012-10-04 15:27:39.000000000 +0200
1630 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/fs/block_dev.c      2012-10-04 18:47:00.000000000 +0200
1631 @@ -27,6 +27,7 @@
1632  #include <linux/namei.h>
1633  #include <linux/log2.h>
1634  #include <linux/cleancache.h>
1635 +#include <linux/vs_device.h>
1636  #include <asm/uaccess.h>
1637  #include "internal.h"
1638  
1639 @@ -581,6 +582,7 @@ struct block_device *bdget(dev_t dev)
1640                 bdev->bd_invalidated = 0;
1641                 inode->i_mode = S_IFBLK;
1642                 inode->i_rdev = dev;
1643 +               inode->i_mdev = dev;
1644                 inode->i_bdev = bdev;
1645                 inode->i_data.a_ops = &def_blk_aops;
1646                 mapping_set_gfp_mask(&inode->i_data, GFP_USER);
1647 @@ -627,6 +629,11 @@ EXPORT_SYMBOL(bdput);
1648  static struct block_device *bd_acquire(struct inode *inode)
1649  {
1650         struct block_device *bdev;
1651 +       dev_t mdev;
1652 +
1653 +       if (!vs_map_blkdev(inode->i_rdev, &mdev, DATTR_OPEN))
1654 +               return NULL;
1655 +       inode->i_mdev = mdev;
1656  
1657         spin_lock(&bdev_lock);
1658         bdev = inode->i_bdev;
1659 @@ -637,7 +644,7 @@ static struct block_device *bd_acquire(s
1660         }
1661         spin_unlock(&bdev_lock);
1662  
1663 -       bdev = bdget(inode->i_rdev);
1664 +       bdev = bdget(mdev);
1665         if (bdev) {
1666                 spin_lock(&bdev_lock);
1667                 if (!inode->i_bdev) {
1668 diff -NurpP --minimal linux-3.6/fs/btrfs/ctree.h linux-3.6-vs2.3.4.3-noxfs-nocow/fs/btrfs/ctree.h
1669 --- linux-3.6/fs/btrfs/ctree.h  2012-10-04 15:27:39.000000000 +0200
1670 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/fs/btrfs/ctree.h    2012-10-04 18:47:00.000000000 +0200
1671 @@ -674,11 +674,14 @@ struct btrfs_inode_item {
1672         /* modification sequence number for NFS */
1673         __le64 sequence;
1674  
1675 +       __le16 tag;
1676         /*
1677          * a little future expansion, for more than this we can
1678          * just grow the inode item and version it
1679          */
1680 -       __le64 reserved[4];
1681 +       __le16 reserved16;
1682 +       __le32 reserved32;
1683 +       __le64 reserved[3];
1684         struct btrfs_timespec atime;
1685         struct btrfs_timespec ctime;
1686         struct btrfs_timespec mtime;
1687 @@ -1727,6 +1730,8 @@ struct btrfs_ioctl_defrag_range_args {
1688  #define BTRFS_MOUNT_CHECK_INTEGRITY_INCLUDING_EXTENT_DATA (1 << 21)
1689  #define BTRFS_MOUNT_PANIC_ON_FATAL_ERROR       (1 << 22)
1690  
1691 +#define BTRFS_MOUNT_TAGGED             (1 << 24)
1692 +
1693  #define btrfs_clear_opt(o, opt)                ((o) &= ~BTRFS_MOUNT_##opt)
1694  #define btrfs_set_opt(o, opt)          ((o) |= BTRFS_MOUNT_##opt)
1695  #define btrfs_test_opt(root, opt)      ((root)->fs_info->mount_opt & \
1696 @@ -1988,6 +1993,7 @@ BTRFS_SETGET_FUNCS(inode_block_group, st
1697  BTRFS_SETGET_FUNCS(inode_nlink, struct btrfs_inode_item, nlink, 32);
1698  BTRFS_SETGET_FUNCS(inode_uid, struct btrfs_inode_item, uid, 32);
1699  BTRFS_SETGET_FUNCS(inode_gid, struct btrfs_inode_item, gid, 32);
1700 +BTRFS_SETGET_FUNCS(inode_tag, struct btrfs_inode_item, tag, 16);
1701  BTRFS_SETGET_FUNCS(inode_mode, struct btrfs_inode_item, mode, 32);
1702  BTRFS_SETGET_FUNCS(inode_rdev, struct btrfs_inode_item, rdev, 64);
1703  BTRFS_SETGET_FUNCS(inode_flags, struct btrfs_inode_item, flags, 64);
1704 @@ -2041,6 +2047,10 @@ BTRFS_SETGET_FUNCS(extent_flags, struct 
1705  
1706  BTRFS_SETGET_FUNCS(extent_refs_v0, struct btrfs_extent_item_v0, refs, 32);
1707  
1708 +#define BTRFS_INODE_IXUNLINK           (1 << 24)
1709 +#define BTRFS_INODE_BARRIER            (1 << 25)
1710 +#define BTRFS_INODE_COW                        (1 << 26)
1711 +
1712  
1713  BTRFS_SETGET_FUNCS(tree_block_level, struct btrfs_tree_block_info, level, 8);
1714  
1715 @@ -3305,6 +3315,7 @@ extern const struct dentry_operations bt
1716  long btrfs_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
1717  void btrfs_update_iflags(struct inode *inode);
1718  void btrfs_inherit_iflags(struct inode *inode, struct inode *dir);
1719 +int btrfs_sync_flags(struct inode *inode, int, int);
1720  int btrfs_defrag_file(struct inode *inode, struct file *file,
1721                       struct btrfs_ioctl_defrag_range_args *range,
1722                       u64 newer_than, unsigned long max_pages);
1723 diff -NurpP --minimal linux-3.6/fs/btrfs/disk-io.c linux-3.6-vs2.3.4.3-noxfs-nocow/fs/btrfs/disk-io.c
1724 --- linux-3.6/fs/btrfs/disk-io.c        2012-10-04 15:27:39.000000000 +0200
1725 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/fs/btrfs/disk-io.c  2012-10-04 18:47:00.000000000 +0200
1726 @@ -2187,6 +2187,9 @@ int open_ctree(struct super_block *sb,
1727                 goto fail_alloc;
1728         }
1729  
1730 +       if (btrfs_test_opt(tree_root, TAGGED))
1731 +               sb->s_flags |= MS_TAGGED;
1732 +
1733         features = btrfs_super_incompat_flags(disk_super) &
1734                 ~BTRFS_FEATURE_INCOMPAT_SUPP;
1735         if (features) {
1736 diff -NurpP --minimal linux-3.6/fs/btrfs/inode.c linux-3.6-vs2.3.4.3-noxfs-nocow/fs/btrfs/inode.c
1737 --- linux-3.6/fs/btrfs/inode.c  2012-10-04 15:27:39.000000000 +0200
1738 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/fs/btrfs/inode.c    2012-10-04 18:47:00.000000000 +0200
1739 @@ -39,6 +39,7 @@
1740  #include <linux/slab.h>
1741  #include <linux/ratelimit.h>
1742  #include <linux/mount.h>
1743 +#include <linux/vs_tag.h>
1744  #include "compat.h"
1745  #include "ctree.h"
1746  #include "disk-io.h"
1747 @@ -2545,6 +2546,8 @@ static void btrfs_read_locked_inode(stru
1748         struct btrfs_key location;
1749         int maybe_acls;
1750         u32 rdev;
1751 +       uid_t uid;
1752 +       gid_t gid;
1753         int ret;
1754         bool filled = false;
1755  
1756 @@ -2572,8 +2575,13 @@ static void btrfs_read_locked_inode(stru
1757                                     struct btrfs_inode_item);
1758         inode->i_mode = btrfs_inode_mode(leaf, inode_item);
1759         set_nlink(inode, btrfs_inode_nlink(leaf, inode_item));
1760 -       inode->i_uid = btrfs_inode_uid(leaf, inode_item);
1761 -       inode->i_gid = btrfs_inode_gid(leaf, inode_item);
1762 +
1763 +       uid = btrfs_inode_uid(leaf, inode_item);
1764 +       gid = btrfs_inode_gid(leaf, inode_item);
1765 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
1766 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
1767 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid,
1768 +               btrfs_inode_tag(leaf, inode_item));
1769         btrfs_i_size_write(inode, btrfs_inode_size(leaf, inode_item));
1770  
1771         tspec = btrfs_inode_atime(inode_item);
1772 @@ -2651,8 +2659,14 @@ static void fill_inode_item(struct btrfs
1773                             struct btrfs_inode_item *item,
1774                             struct inode *inode)
1775  {
1776 -       btrfs_set_inode_uid(leaf, item, inode->i_uid);
1777 -       btrfs_set_inode_gid(leaf, item, inode->i_gid);
1778 +       uid_t uid = TAGINO_UID(DX_TAG(inode), inode->i_uid, inode->i_tag);
1779 +       gid_t gid = TAGINO_GID(DX_TAG(inode), inode->i_gid, inode->i_tag);
1780 +
1781 +       btrfs_set_inode_uid(leaf, item, uid);
1782 +       btrfs_set_inode_gid(leaf, item, gid);
1783 +#ifdef CONFIG_TAGGING_INTERN
1784 +       btrfs_set_inode_tag(leaf, item, inode->i_tag);
1785 +#endif
1786         btrfs_set_inode_size(leaf, item, BTRFS_I(inode)->disk_i_size);
1787         btrfs_set_inode_mode(leaf, item, inode->i_mode);
1788         btrfs_set_inode_nlink(leaf, item, inode->i_nlink);
1789 @@ -7636,11 +7650,13 @@ static const struct inode_operations btr
1790         .listxattr      = btrfs_listxattr,
1791         .removexattr    = btrfs_removexattr,
1792         .permission     = btrfs_permission,
1793 +       .sync_flags     = btrfs_sync_flags,
1794         .get_acl        = btrfs_get_acl,
1795  };
1796  static const struct inode_operations btrfs_dir_ro_inode_operations = {
1797         .lookup         = btrfs_lookup,
1798         .permission     = btrfs_permission,
1799 +       .sync_flags     = btrfs_sync_flags,
1800         .get_acl        = btrfs_get_acl,
1801  };
1802  
1803 diff -NurpP --minimal linux-3.6/fs/btrfs/ioctl.c linux-3.6-vs2.3.4.3-noxfs-nocow/fs/btrfs/ioctl.c
1804 --- linux-3.6/fs/btrfs/ioctl.c  2012-10-04 15:27:39.000000000 +0200
1805 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/fs/btrfs/ioctl.c    2012-10-04 18:47:00.000000000 +0200
1806 @@ -74,10 +74,13 @@ static unsigned int btrfs_flags_to_ioctl
1807  {
1808         unsigned int iflags = 0;
1809  
1810 -       if (flags & BTRFS_INODE_SYNC)
1811 -               iflags |= FS_SYNC_FL;
1812         if (flags & BTRFS_INODE_IMMUTABLE)
1813                 iflags |= FS_IMMUTABLE_FL;
1814 +       if (flags & BTRFS_INODE_IXUNLINK)
1815 +               iflags |= FS_IXUNLINK_FL;
1816 +
1817 +       if (flags & BTRFS_INODE_SYNC)
1818 +               iflags |= FS_SYNC_FL;
1819         if (flags & BTRFS_INODE_APPEND)
1820                 iflags |= FS_APPEND_FL;
1821         if (flags & BTRFS_INODE_NODUMP)
1822 @@ -94,28 +97,78 @@ static unsigned int btrfs_flags_to_ioctl
1823         else if (flags & BTRFS_INODE_NOCOMPRESS)
1824                 iflags |= FS_NOCOMP_FL;
1825  
1826 +       if (flags & BTRFS_INODE_BARRIER)
1827 +               iflags |= FS_BARRIER_FL;
1828 +       if (flags & BTRFS_INODE_COW)
1829 +               iflags |= FS_COW_FL;
1830         return iflags;
1831  }
1832  
1833  /*
1834 - * Update inode->i_flags based on the btrfs internal flags.
1835 + * Update inode->i_(v)flags based on the btrfs internal flags.
1836   */
1837  void btrfs_update_iflags(struct inode *inode)
1838  {
1839         struct btrfs_inode *ip = BTRFS_I(inode);
1840  
1841 -       inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
1842 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
1843 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
1844  
1845 -       if (ip->flags & BTRFS_INODE_SYNC)
1846 -               inode->i_flags |= S_SYNC;
1847         if (ip->flags & BTRFS_INODE_IMMUTABLE)
1848                 inode->i_flags |= S_IMMUTABLE;
1849 +       if (ip->flags & BTRFS_INODE_IXUNLINK)
1850 +               inode->i_flags |= S_IXUNLINK;
1851 +
1852 +       if (ip->flags & BTRFS_INODE_SYNC)
1853 +               inode->i_flags |= S_SYNC;
1854         if (ip->flags & BTRFS_INODE_APPEND)
1855                 inode->i_flags |= S_APPEND;
1856         if (ip->flags & BTRFS_INODE_NOATIME)
1857                 inode->i_flags |= S_NOATIME;
1858         if (ip->flags & BTRFS_INODE_DIRSYNC)
1859                 inode->i_flags |= S_DIRSYNC;
1860 +
1861 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
1862 +
1863 +       if (ip->flags & BTRFS_INODE_BARRIER)
1864 +               inode->i_vflags |= V_BARRIER;
1865 +       if (ip->flags & BTRFS_INODE_COW)
1866 +               inode->i_vflags |= V_COW;
1867 +}
1868 +
1869 +/*
1870 + * Update btrfs internal flags from inode->i_(v)flags.
1871 + */
1872 +void btrfs_update_flags(struct inode *inode)
1873 +{
1874 +       struct btrfs_inode *ip = BTRFS_I(inode);
1875 +
1876 +       unsigned int flags = inode->i_flags;
1877 +       unsigned int vflags = inode->i_vflags;
1878 +
1879 +       ip->flags &= ~(BTRFS_INODE_SYNC | BTRFS_INODE_APPEND |
1880 +                       BTRFS_INODE_IMMUTABLE | BTRFS_INODE_IXUNLINK |
1881 +                       BTRFS_INODE_NOATIME | BTRFS_INODE_DIRSYNC |
1882 +                       BTRFS_INODE_BARRIER | BTRFS_INODE_COW);
1883 +
1884 +       if (flags & S_IMMUTABLE)
1885 +               ip->flags |= BTRFS_INODE_IMMUTABLE;
1886 +       if (flags & S_IXUNLINK)
1887 +               ip->flags |= BTRFS_INODE_IXUNLINK;
1888 +
1889 +       if (flags & S_SYNC)
1890 +               ip->flags |= BTRFS_INODE_SYNC;
1891 +       if (flags & S_APPEND)
1892 +               ip->flags |= BTRFS_INODE_APPEND;
1893 +       if (flags & S_NOATIME)
1894 +               ip->flags |= BTRFS_INODE_NOATIME;
1895 +       if (flags & S_DIRSYNC)
1896 +               ip->flags |= BTRFS_INODE_DIRSYNC;
1897 +
1898 +       if (vflags & V_BARRIER)
1899 +               ip->flags |= BTRFS_INODE_BARRIER;
1900 +       if (vflags & V_COW)
1901 +               ip->flags |= BTRFS_INODE_COW;
1902  }
1903  
1904  /*
1905 @@ -131,6 +184,7 @@ void btrfs_inherit_iflags(struct inode *
1906                 return;
1907  
1908         flags = BTRFS_I(dir)->flags;
1909 +       flags &= ~BTRFS_INODE_BARRIER;
1910  
1911         if (flags & BTRFS_INODE_NOCOMPRESS) {
1912                 BTRFS_I(inode)->flags &= ~BTRFS_INODE_COMPRESS;
1913 @@ -146,6 +200,30 @@ void btrfs_inherit_iflags(struct inode *
1914         btrfs_update_iflags(inode);
1915  }
1916  
1917 +int btrfs_sync_flags(struct inode *inode, int flags, int vflags)
1918 +{
1919 +       struct btrfs_inode *ip = BTRFS_I(inode);
1920 +       struct btrfs_root *root = ip->root;
1921 +       struct btrfs_trans_handle *trans;
1922 +       int ret;
1923 +
1924 +       trans = btrfs_join_transaction(root);
1925 +       BUG_ON(!trans);
1926 +
1927 +       inode->i_flags = flags;
1928 +       inode->i_vflags = vflags;
1929 +       btrfs_update_flags(inode);
1930 +
1931 +       ret = btrfs_update_inode(trans, root, inode);
1932 +       BUG_ON(ret);
1933 +
1934 +       btrfs_update_iflags(inode);
1935 +       inode->i_ctime = CURRENT_TIME;
1936 +       btrfs_end_transaction(trans, root);
1937 +
1938 +       return 0;
1939 +}
1940 +
1941  static int btrfs_ioctl_getflags(struct file *file, void __user *arg)
1942  {
1943         struct btrfs_inode *ip = BTRFS_I(file->f_path.dentry->d_inode);
1944 @@ -206,21 +284,27 @@ static int btrfs_ioctl_setflags(struct f
1945  
1946         flags = btrfs_mask_flags(inode->i_mode, flags);
1947         oldflags = btrfs_flags_to_ioctl(ip->flags);
1948 -       if ((flags ^ oldflags) & (FS_APPEND_FL | FS_IMMUTABLE_FL)) {
1949 +       if ((flags ^ oldflags) & (FS_APPEND_FL |
1950 +               FS_IMMUTABLE_FL | FS_IXUNLINK_FL)) {
1951                 if (!capable(CAP_LINUX_IMMUTABLE)) {
1952                         ret = -EPERM;
1953                         goto out_unlock;
1954                 }
1955         }
1956  
1957 -       if (flags & FS_SYNC_FL)
1958 -               ip->flags |= BTRFS_INODE_SYNC;
1959 -       else
1960 -               ip->flags &= ~BTRFS_INODE_SYNC;
1961         if (flags & FS_IMMUTABLE_FL)
1962                 ip->flags |= BTRFS_INODE_IMMUTABLE;
1963         else
1964                 ip->flags &= ~BTRFS_INODE_IMMUTABLE;
1965 +       if (flags & FS_IXUNLINK_FL)
1966 +               ip->flags |= BTRFS_INODE_IXUNLINK;
1967 +       else
1968 +               ip->flags &= ~BTRFS_INODE_IXUNLINK;
1969 +
1970 +       if (flags & FS_SYNC_FL)
1971 +               ip->flags |= BTRFS_INODE_SYNC;
1972 +       else
1973 +               ip->flags &= ~BTRFS_INODE_SYNC;
1974         if (flags & FS_APPEND_FL)
1975                 ip->flags |= BTRFS_INODE_APPEND;
1976         else
1977 diff -NurpP --minimal linux-3.6/fs/btrfs/super.c linux-3.6-vs2.3.4.3-noxfs-nocow/fs/btrfs/super.c
1978 --- linux-3.6/fs/btrfs/super.c  2012-10-04 15:27:39.000000000 +0200
1979 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/fs/btrfs/super.c    2012-10-04 18:47:00.000000000 +0200
1980 @@ -306,7 +306,7 @@ enum {
1981         Opt_no_space_cache, Opt_recovery, Opt_skip_balance,
1982         Opt_check_integrity, Opt_check_integrity_including_extent_data,
1983         Opt_check_integrity_print_mask, Opt_fatal_errors,
1984 -       Opt_err,
1985 +       Opt_tag, Opt_notag, Opt_tagid, Opt_err,
1986  };
1987  
1988  static match_table_t tokens = {
1989 @@ -346,6 +346,9 @@ static match_table_t tokens = {
1990         {Opt_check_integrity_including_extent_data, "check_int_data"},
1991         {Opt_check_integrity_print_mask, "check_int_print_mask=%d"},
1992         {Opt_fatal_errors, "fatal_errors=%s"},
1993 +       {Opt_tag, "tag"},
1994 +       {Opt_notag, "notag"},
1995 +       {Opt_tagid, "tagid=%u"},
1996         {Opt_err, NULL},
1997  };
1998  
1999 @@ -596,6 +599,22 @@ int btrfs_parse_options(struct btrfs_roo
2000                                 goto out;
2001                         }
2002                         break;
2003 +#ifndef CONFIG_TAGGING_NONE
2004 +               case Opt_tag:
2005 +                       printk(KERN_INFO "btrfs: use tagging\n");
2006 +                       btrfs_set_opt(info->mount_opt, TAGGED);
2007 +                       break;
2008 +               case Opt_notag:
2009 +                       printk(KERN_INFO "btrfs: disabled tagging\n");
2010 +                       btrfs_clear_opt(info->mount_opt, TAGGED);
2011 +                       break;
2012 +#endif
2013 +#ifdef CONFIG_PROPAGATE
2014 +               case Opt_tagid:
2015 +                       /* use args[0] */
2016 +                       btrfs_set_opt(info->mount_opt, TAGGED);
2017 +                       break;
2018 +#endif
2019                 case Opt_err:
2020                         printk(KERN_INFO "btrfs: unrecognized mount option "
2021                                "'%s'\n", p);
2022 @@ -1196,6 +1215,12 @@ static int btrfs_remount(struct super_bl
2023         btrfs_resize_thread_pool(fs_info,
2024                 fs_info->thread_pool_size, old_thread_pool_size);
2025  
2026 +       if (btrfs_test_opt(root, TAGGED) && !(sb->s_flags & MS_TAGGED)) {
2027 +               printk("btrfs: %s: tagging not permitted on remount.\n",
2028 +                       sb->s_id);
2029 +               return -EINVAL;
2030 +       }
2031 +
2032         if ((*flags & MS_RDONLY) == (sb->s_flags & MS_RDONLY))
2033                 return 0;
2034  
2035 diff -NurpP --minimal linux-3.6/fs/char_dev.c linux-3.6-vs2.3.4.3-noxfs-nocow/fs/char_dev.c
2036 --- linux-3.6/fs/char_dev.c     2012-03-19 19:47:25.000000000 +0100
2037 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/fs/char_dev.c       2012-10-04 18:47:00.000000000 +0200
2038 @@ -21,6 +21,8 @@
2039  #include <linux/mutex.h>
2040  #include <linux/backing-dev.h>
2041  #include <linux/tty.h>
2042 +#include <linux/vs_context.h>
2043 +#include <linux/vs_device.h>
2044  
2045  #include "internal.h"
2046  
2047 @@ -371,14 +373,21 @@ static int chrdev_open(struct inode *ino
2048         struct cdev *p;
2049         struct cdev *new = NULL;
2050         int ret = 0;
2051 +       dev_t mdev;
2052 +
2053 +       if (!vs_map_chrdev(inode->i_rdev, &mdev, DATTR_OPEN))
2054 +               return -EPERM;
2055 +       inode->i_mdev = mdev;
2056  
2057         spin_lock(&cdev_lock);
2058         p = inode->i_cdev;
2059         if (!p) {
2060                 struct kobject *kobj;
2061                 int idx;
2062 +
2063                 spin_unlock(&cdev_lock);
2064 -               kobj = kobj_lookup(cdev_map, inode->i_rdev, &idx);
2065 +
2066 +               kobj = kobj_lookup(cdev_map, mdev, &idx);
2067                 if (!kobj)
2068                         return -ENXIO;
2069                 new = container_of(kobj, struct cdev, kobj);
2070 diff -NurpP --minimal linux-3.6/fs/dcache.c linux-3.6-vs2.3.4.3-noxfs-nocow/fs/dcache.c
2071 --- linux-3.6/fs/dcache.c       2012-10-04 15:27:39.000000000 +0200
2072 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/fs/dcache.c 2012-10-04 18:47:00.000000000 +0200
2073 @@ -37,6 +37,7 @@
2074  #include <linux/rculist_bl.h>
2075  #include <linux/prefetch.h>
2076  #include <linux/ratelimit.h>
2077 +#include <linux/vs_limit.h>
2078  #include "internal.h"
2079  #include "mount.h"
2080  
2081 @@ -617,6 +618,8 @@ int d_invalidate(struct dentry * dentry)
2082                 spin_lock(&dentry->d_lock);
2083         }
2084  
2085 +       vx_dentry_dec(dentry);
2086 +
2087         /*
2088          * Somebody else still using it?
2089          *
2090 @@ -646,6 +649,7 @@ EXPORT_SYMBOL(d_invalidate);
2091  static inline void __dget_dlock(struct dentry *dentry)
2092  {
2093         dentry->d_count++;
2094 +       vx_dentry_inc(dentry);
2095  }
2096  
2097  static inline void __dget(struct dentry *dentry)
2098 @@ -1276,6 +1280,9 @@ struct dentry *__d_alloc(struct super_bl
2099         struct dentry *dentry;
2100         char *dname;
2101  
2102 +       if (!vx_dentry_avail(1))
2103 +               return NULL;
2104 +
2105         dentry = kmem_cache_alloc(dentry_cache, GFP_KERNEL);
2106         if (!dentry)
2107                 return NULL;
2108 @@ -1308,6 +1315,7 @@ struct dentry *__d_alloc(struct super_bl
2109  
2110         dentry->d_count = 1;
2111         dentry->d_flags = 0;
2112 +       vx_dentry_inc(dentry);
2113         spin_lock_init(&dentry->d_lock);
2114         seqcount_init(&dentry->d_seq);
2115         dentry->d_inode = NULL;
2116 @@ -2012,6 +2020,7 @@ struct dentry *__d_lookup(struct dentry 
2117                 }
2118  
2119                 dentry->d_count++;
2120 +               vx_dentry_inc(dentry);
2121                 found = dentry;
2122                 spin_unlock(&dentry->d_lock);
2123                 break;
2124 diff -NurpP --minimal linux-3.6/fs/devpts/inode.c linux-3.6-vs2.3.4.3-noxfs-nocow/fs/devpts/inode.c
2125 --- linux-3.6/fs/devpts/inode.c 2012-10-04 15:27:39.000000000 +0200
2126 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/fs/devpts/inode.c   2012-10-04 18:47:00.000000000 +0200
2127 @@ -25,6 +25,7 @@
2128  #include <linux/parser.h>
2129  #include <linux/fsnotify.h>
2130  #include <linux/seq_file.h>
2131 +#include <linux/vs_base.h>
2132  
2133  #define DEVPTS_DEFAULT_MODE 0600
2134  /*
2135 @@ -36,6 +37,21 @@
2136  #define DEVPTS_DEFAULT_PTMX_MODE 0000
2137  #define PTMX_MINOR     2
2138  
2139 +static int devpts_permission(struct inode *inode, int mask)
2140 +{
2141 +       int ret = -EACCES;
2142 +
2143 +       /* devpts is xid tagged */
2144 +       if (vx_check((xid_t)inode->i_tag, VS_WATCH_P | VS_IDENT))
2145 +               ret = generic_permission(inode, mask);
2146 +       return ret;
2147 +}
2148 +
2149 +static struct inode_operations devpts_file_inode_operations = {
2150 +       .permission     = devpts_permission,
2151 +};
2152 +
2153 +
2154  /*
2155   * sysctl support for setting limits on the number of Unix98 ptys allocated.
2156   * Otherwise one can eat up all kernel memory by opening /dev/ptmx repeatedly.
2157 @@ -336,6 +352,34 @@ static int devpts_show_options(struct se
2158         return 0;
2159  }
2160  
2161 +static int devpts_filter(struct dentry *de)
2162 +{
2163 +       xid_t xid = 0;
2164 +
2165 +       /* devpts is xid tagged */
2166 +       if (de && de->d_inode)
2167 +               xid = (xid_t)de->d_inode->i_tag;
2168 +#ifdef CONFIG_VSERVER_WARN_DEVPTS
2169 +       else
2170 +               vxwprintk_task(1, "devpts " VS_Q("%.*s") " without inode.",
2171 +                       de->d_name.len, de->d_name.name);
2172 +#endif
2173 +       return vx_check(xid, VS_WATCH_P | VS_IDENT);
2174 +}
2175 +
2176 +static int devpts_readdir(struct file * filp, void * dirent, filldir_t filldir)
2177 +{
2178 +       return dcache_readdir_filter(filp, dirent, filldir, devpts_filter);
2179 +}
2180 +
2181 +static struct file_operations devpts_dir_operations = {
2182 +       .open           = dcache_dir_open,
2183 +       .release        = dcache_dir_close,
2184 +       .llseek         = dcache_dir_lseek,
2185 +       .read           = generic_read_dir,
2186 +       .readdir        = devpts_readdir,
2187 +};
2188 +
2189  static const struct super_operations devpts_sops = {
2190         .statfs         = simple_statfs,
2191         .remount_fs     = devpts_remount,
2192 @@ -379,8 +423,10 @@ devpts_fill_super(struct super_block *s,
2193         inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
2194         inode->i_mode = S_IFDIR | S_IRUGO | S_IXUGO | S_IWUSR;
2195         inode->i_op = &simple_dir_inode_operations;
2196 -       inode->i_fop = &simple_dir_operations;
2197 +       inode->i_fop = &devpts_dir_operations;
2198         set_nlink(inode, 2);
2199 +       /* devpts is xid tagged */
2200 +       inode->i_tag = (tag_t)vx_current_xid();
2201  
2202         s->s_root = d_make_root(inode);
2203         if (s->s_root)
2204 @@ -572,6 +618,9 @@ int devpts_pty_new(struct inode *ptmx_in
2205         inode->i_gid = opts->setgid ? opts->gid : current_fsgid();
2206         inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
2207         init_special_inode(inode, S_IFCHR|opts->mode, device);
2208 +       /* devpts is xid tagged */
2209 +       inode->i_tag = (tag_t)vx_current_xid();
2210 +       inode->i_op = &devpts_file_inode_operations;
2211         inode->i_private = tty;
2212         tty->driver_data = inode;
2213  
2214 diff -NurpP --minimal linux-3.6/fs/ext2/balloc.c linux-3.6-vs2.3.4.3-noxfs-nocow/fs/ext2/balloc.c
2215 --- linux-3.6/fs/ext2/balloc.c  2012-10-04 15:27:39.000000000 +0200
2216 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/fs/ext2/balloc.c    2012-10-04 18:47:00.000000000 +0200
2217 @@ -699,7 +699,6 @@ ext2_try_to_allocate(struct super_block 
2218                         start = 0;
2219                 end = EXT2_BLOCKS_PER_GROUP(sb);
2220         }
2221 -
2222         BUG_ON(start > EXT2_BLOCKS_PER_GROUP(sb));
2223  
2224  repeat:
2225 diff -NurpP --minimal linux-3.6/fs/ext2/ext2.h linux-3.6-vs2.3.4.3-noxfs-nocow/fs/ext2/ext2.h
2226 --- linux-3.6/fs/ext2/ext2.h    2012-07-22 23:39:39.000000000 +0200
2227 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/fs/ext2/ext2.h      2012-10-04 18:47:00.000000000 +0200
2228 @@ -244,8 +244,12 @@ struct ext2_group_desc
2229  #define EXT2_NOTAIL_FL                 FS_NOTAIL_FL    /* file tail should not be merged */
2230  #define EXT2_DIRSYNC_FL                        FS_DIRSYNC_FL   /* dirsync behaviour (directories only) */
2231  #define EXT2_TOPDIR_FL                 FS_TOPDIR_FL    /* Top of directory hierarchies*/
2232 +#define EXT2_IXUNLINK_FL               FS_IXUNLINK_FL  /* Immutable invert on unlink */
2233  #define EXT2_RESERVED_FL               FS_RESERVED_FL  /* reserved for ext2 lib */
2234  
2235 +#define EXT2_BARRIER_FL                        FS_BARRIER_FL   /* Barrier for chroot() */
2236 +#define EXT2_COW_FL                    FS_COW_FL       /* Copy on Write marker */
2237 +
2238  #define EXT2_FL_USER_VISIBLE           FS_FL_USER_VISIBLE      /* User visible flags */
2239  #define EXT2_FL_USER_MODIFIABLE                FS_FL_USER_MODIFIABLE   /* User modifiable flags */
2240  
2241 @@ -329,7 +333,8 @@ struct ext2_inode {
2242                         __u16   i_pad1;
2243                         __le16  l_i_uid_high;   /* these 2 fields    */
2244                         __le16  l_i_gid_high;   /* were reserved2[0] */
2245 -                       __u32   l_i_reserved2;
2246 +                       __le16  l_i_tag;        /* Context Tag */
2247 +                       __u16   l_i_reserved2;
2248                 } linux2;
2249                 struct {
2250                         __u8    h_i_frag;       /* Fragment number */
2251 @@ -357,6 +362,7 @@ struct ext2_inode {
2252  #define i_gid_low      i_gid
2253  #define i_uid_high     osd2.linux2.l_i_uid_high
2254  #define i_gid_high     osd2.linux2.l_i_gid_high
2255 +#define i_raw_tag      osd2.linux2.l_i_tag
2256  #define i_reserved2    osd2.linux2.l_i_reserved2
2257  
2258  /*
2259 @@ -384,6 +390,7 @@ struct ext2_inode {
2260  #define EXT2_MOUNT_USRQUOTA            0x020000  /* user quota */
2261  #define EXT2_MOUNT_GRPQUOTA            0x040000  /* group quota */
2262  #define EXT2_MOUNT_RESERVATION         0x080000  /* Preallocation */
2263 +#define EXT2_MOUNT_TAGGED              (1<<24)   /* Enable Context Tags */
2264  
2265  
2266  #define clear_opt(o, opt)              o &= ~EXT2_MOUNT_##opt
2267 @@ -757,6 +764,7 @@ extern void ext2_set_inode_flags(struct 
2268  extern void ext2_get_inode_flags(struct ext2_inode_info *);
2269  extern int ext2_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
2270                        u64 start, u64 len);
2271 +extern int ext2_sync_flags(struct inode *, int, int);
2272  
2273  /* ioctl.c */
2274  extern long ext2_ioctl(struct file *, unsigned int, unsigned long);
2275 diff -NurpP --minimal linux-3.6/fs/ext2/file.c linux-3.6-vs2.3.4.3-noxfs-nocow/fs/ext2/file.c
2276 --- linux-3.6/fs/ext2/file.c    2011-10-24 18:45:27.000000000 +0200
2277 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/fs/ext2/file.c      2012-10-04 18:47:00.000000000 +0200
2278 @@ -104,4 +104,5 @@ const struct inode_operations ext2_file_
2279         .setattr        = ext2_setattr,
2280         .get_acl        = ext2_get_acl,
2281         .fiemap         = ext2_fiemap,
2282 +       .sync_flags     = ext2_sync_flags,
2283  };
2284 diff -NurpP --minimal linux-3.6/fs/ext2/ialloc.c linux-3.6-vs2.3.4.3-noxfs-nocow/fs/ext2/ialloc.c
2285 --- linux-3.6/fs/ext2/ialloc.c  2012-10-04 15:27:39.000000000 +0200
2286 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/fs/ext2/ialloc.c    2012-10-04 18:47:00.000000000 +0200
2287 @@ -17,6 +17,7 @@
2288  #include <linux/backing-dev.h>
2289  #include <linux/buffer_head.h>
2290  #include <linux/random.h>
2291 +#include <linux/vs_tag.h>
2292  #include "ext2.h"
2293  #include "xattr.h"
2294  #include "acl.h"
2295 @@ -547,6 +548,7 @@ got:
2296                 inode->i_mode = mode;
2297                 inode->i_uid = current_fsuid();
2298                 inode->i_gid = dir->i_gid;
2299 +               inode->i_tag = dx_current_fstag(sb);
2300         } else
2301                 inode_init_owner(inode, dir, mode);
2302  
2303 diff -NurpP --minimal linux-3.6/fs/ext2/inode.c linux-3.6-vs2.3.4.3-noxfs-nocow/fs/ext2/inode.c
2304 --- linux-3.6/fs/ext2/inode.c   2012-10-04 15:27:39.000000000 +0200
2305 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/fs/ext2/inode.c     2012-10-04 18:47:00.000000000 +0200
2306 @@ -31,6 +31,7 @@
2307  #include <linux/mpage.h>
2308  #include <linux/fiemap.h>
2309  #include <linux/namei.h>
2310 +#include <linux/vs_tag.h>
2311  #include "ext2.h"
2312  #include "acl.h"
2313  #include "xip.h"
2314 @@ -1165,7 +1166,7 @@ static void ext2_truncate_blocks(struct 
2315                 return;
2316         if (ext2_inode_is_fast_symlink(inode))
2317                 return;
2318 -       if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
2319 +       if (IS_APPEND(inode) || IS_IXORUNLINK(inode))
2320                 return;
2321         __ext2_truncate_blocks(inode, offset);
2322  }
2323 @@ -1256,36 +1257,61 @@ void ext2_set_inode_flags(struct inode *
2324  {
2325         unsigned int flags = EXT2_I(inode)->i_flags;
2326  
2327 -       inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
2328 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
2329 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
2330 +
2331 +
2332 +       if (flags & EXT2_IMMUTABLE_FL)
2333 +               inode->i_flags |= S_IMMUTABLE;
2334 +       if (flags & EXT2_IXUNLINK_FL)
2335 +               inode->i_flags |= S_IXUNLINK;
2336 +
2337         if (flags & EXT2_SYNC_FL)
2338                 inode->i_flags |= S_SYNC;
2339         if (flags & EXT2_APPEND_FL)
2340                 inode->i_flags |= S_APPEND;
2341 -       if (flags & EXT2_IMMUTABLE_FL)
2342 -               inode->i_flags |= S_IMMUTABLE;
2343         if (flags & EXT2_NOATIME_FL)
2344                 inode->i_flags |= S_NOATIME;
2345         if (flags & EXT2_DIRSYNC_FL)
2346                 inode->i_flags |= S_DIRSYNC;
2347 +
2348 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
2349 +
2350 +       if (flags & EXT2_BARRIER_FL)
2351 +               inode->i_vflags |= V_BARRIER;
2352 +       if (flags & EXT2_COW_FL)
2353 +               inode->i_vflags |= V_COW;
2354  }
2355  
2356  /* Propagate flags from i_flags to EXT2_I(inode)->i_flags */
2357  void ext2_get_inode_flags(struct ext2_inode_info *ei)
2358  {
2359         unsigned int flags = ei->vfs_inode.i_flags;
2360 +       unsigned int vflags = ei->vfs_inode.i_vflags;
2361 +
2362 +       ei->i_flags &= ~(EXT2_SYNC_FL | EXT2_APPEND_FL |
2363 +                       EXT2_IMMUTABLE_FL | EXT2_IXUNLINK_FL |
2364 +                       EXT2_NOATIME_FL | EXT2_DIRSYNC_FL |
2365 +                       EXT2_BARRIER_FL | EXT2_COW_FL);
2366 +
2367 +       if (flags & S_IMMUTABLE)
2368 +               ei->i_flags |= EXT2_IMMUTABLE_FL;
2369 +       if (flags & S_IXUNLINK)
2370 +               ei->i_flags |= EXT2_IXUNLINK_FL;
2371  
2372 -       ei->i_flags &= ~(EXT2_SYNC_FL|EXT2_APPEND_FL|
2373 -                       EXT2_IMMUTABLE_FL|EXT2_NOATIME_FL|EXT2_DIRSYNC_FL);
2374         if (flags & S_SYNC)
2375                 ei->i_flags |= EXT2_SYNC_FL;
2376         if (flags & S_APPEND)
2377                 ei->i_flags |= EXT2_APPEND_FL;
2378 -       if (flags & S_IMMUTABLE)
2379 -               ei->i_flags |= EXT2_IMMUTABLE_FL;
2380         if (flags & S_NOATIME)
2381                 ei->i_flags |= EXT2_NOATIME_FL;
2382         if (flags & S_DIRSYNC)
2383                 ei->i_flags |= EXT2_DIRSYNC_FL;
2384 +
2385 +       if (vflags & V_BARRIER)
2386 +               ei->i_flags |= EXT2_BARRIER_FL;
2387 +       if (vflags & V_COW)
2388 +               ei->i_flags |= EXT2_COW_FL;
2389  }
2390  
2391  struct inode *ext2_iget (struct super_block *sb, unsigned long ino)
2392 @@ -1321,8 +1347,10 @@ struct inode *ext2_iget (struct super_bl
2393                 i_uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
2394                 i_gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
2395         }
2396 -       i_uid_write(inode, i_uid);
2397 -       i_gid_write(inode, i_gid);
2398 +       i_uid_write(inode, INOTAG_UID(DX_TAG(inode), i_uid, i_gid));
2399 +       i_gid_write(inode, INOTAG_GID(DX_TAG(inode), i_uid, i_gid));
2400 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), i_uid, i_gid,
2401 +               le16_to_cpu(raw_inode->i_raw_tag));
2402         set_nlink(inode, le16_to_cpu(raw_inode->i_links_count));
2403         inode->i_size = le32_to_cpu(raw_inode->i_size);
2404         inode->i_atime.tv_sec = (signed)le32_to_cpu(raw_inode->i_atime);
2405 @@ -1420,8 +1448,8 @@ static int __ext2_write_inode(struct ino
2406         struct ext2_inode_info *ei = EXT2_I(inode);
2407         struct super_block *sb = inode->i_sb;
2408         ino_t ino = inode->i_ino;
2409 -       uid_t uid = i_uid_read(inode);
2410 -       gid_t gid = i_gid_read(inode);
2411 +       uid_t uid = TAGINO_UID(DX_TAG(inode), i_uid_read(inode), inode->i_tag);
2412 +       gid_t gid = TAGINO_GID(DX_TAG(inode), i_gid_read(inode), inode->i_tag);
2413         struct buffer_head * bh;
2414         struct ext2_inode * raw_inode = ext2_get_inode(sb, ino, &bh);
2415         int n;
2416 @@ -1457,6 +1485,9 @@ static int __ext2_write_inode(struct ino
2417                 raw_inode->i_uid_high = 0;
2418                 raw_inode->i_gid_high = 0;
2419         }
2420 +#ifdef CONFIG_TAGGING_INTERN
2421 +       raw_inode->i_raw_tag = cpu_to_le16(inode->i_tag);
2422 +#endif
2423         raw_inode->i_links_count = cpu_to_le16(inode->i_nlink);
2424         raw_inode->i_size = cpu_to_le32(inode->i_size);
2425         raw_inode->i_atime = cpu_to_le32(inode->i_atime.tv_sec);
2426 @@ -1537,7 +1568,8 @@ int ext2_setattr(struct dentry *dentry, 
2427         if (is_quota_modification(inode, iattr))
2428                 dquot_initialize(inode);
2429         if ((iattr->ia_valid & ATTR_UID && !uid_eq(iattr->ia_uid, inode->i_uid)) ||
2430 -           (iattr->ia_valid & ATTR_GID && !gid_eq(iattr->ia_gid, inode->i_gid))) {
2431 +           (iattr->ia_valid & ATTR_GID && !gid_eq(iattr->ia_gid, inode->i_gid)) ||
2432 +           (iattr->ia_valid & ATTR_TAG && iattr->ia_tag != inode->i_tag)) {
2433                 error = dquot_transfer(inode, iattr);
2434                 if (error)
2435                         return error;
2436 diff -NurpP --minimal linux-3.6/fs/ext2/ioctl.c linux-3.6-vs2.3.4.3-noxfs-nocow/fs/ext2/ioctl.c
2437 --- linux-3.6/fs/ext2/ioctl.c   2012-03-19 19:47:25.000000000 +0100
2438 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/fs/ext2/ioctl.c     2012-10-04 18:47:00.000000000 +0200
2439 @@ -17,6 +17,16 @@
2440  #include <asm/uaccess.h>
2441  
2442  
2443 +int ext2_sync_flags(struct inode *inode, int flags, int vflags)
2444 +{
2445 +       inode->i_flags = flags;
2446 +       inode->i_vflags = vflags;
2447 +       ext2_get_inode_flags(EXT2_I(inode));
2448 +       inode->i_ctime = CURRENT_TIME_SEC;
2449 +       mark_inode_dirty(inode);
2450 +       return 0;
2451 +}
2452 +
2453  long ext2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
2454  {
2455         struct inode *inode = filp->f_dentry->d_inode;
2456 @@ -51,6 +61,11 @@ long ext2_ioctl(struct file *filp, unsig
2457  
2458                 flags = ext2_mask_flags(inode->i_mode, flags);
2459  
2460 +               if (IS_BARRIER(inode)) {
2461 +                       vxwprintk_task(1, "messing with the barrier.");
2462 +                       return -EACCES;
2463 +               }
2464 +
2465                 mutex_lock(&inode->i_mutex);
2466                 /* Is it quota file? Do not allow user to mess with it */
2467                 if (IS_NOQUOTA(inode)) {
2468 @@ -66,7 +81,9 @@ long ext2_ioctl(struct file *filp, unsig
2469                  *
2470                  * This test looks nicer. Thanks to Pauline Middelink
2471                  */
2472 -               if ((flags ^ oldflags) & (EXT2_APPEND_FL | EXT2_IMMUTABLE_FL)) {
2473 +               if ((oldflags & EXT2_IMMUTABLE_FL) ||
2474 +                       ((flags ^ oldflags) & (EXT2_APPEND_FL |
2475 +                       EXT2_IMMUTABLE_FL | EXT2_IXUNLINK_FL))) {
2476                         if (!capable(CAP_LINUX_IMMUTABLE)) {
2477                                 mutex_unlock(&inode->i_mutex);
2478                                 ret = -EPERM;
2479 @@ -74,7 +91,7 @@ long ext2_ioctl(struct file *filp, unsig
2480                         }
2481                 }
2482  
2483 -               flags = flags & EXT2_FL_USER_MODIFIABLE;
2484 +               flags &= EXT2_FL_USER_MODIFIABLE;
2485                 flags |= oldflags & ~EXT2_FL_USER_MODIFIABLE;
2486                 ei->i_flags = flags;
2487  
2488 diff -NurpP --minimal linux-3.6/fs/ext2/namei.c linux-3.6-vs2.3.4.3-noxfs-nocow/fs/ext2/namei.c
2489 --- linux-3.6/fs/ext2/namei.c   2012-10-04 15:27:39.000000000 +0200
2490 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/fs/ext2/namei.c     2012-10-04 18:47:00.000000000 +0200
2491 @@ -32,6 +32,7 @@
2492  
2493  #include <linux/pagemap.h>
2494  #include <linux/quotaops.h>
2495 +#include <linux/vs_tag.h>
2496  #include "ext2.h"
2497  #include "xattr.h"
2498  #include "acl.h"
2499 @@ -73,6 +74,7 @@ static struct dentry *ext2_lookup(struct
2500                                         (unsigned long) ino);
2501                         return ERR_PTR(-EIO);
2502                 }
2503 +               dx_propagate_tag(nd, inode);
2504         }
2505         return d_splice_alias(inode, dentry);
2506  }
2507 @@ -397,6 +399,7 @@ const struct inode_operations ext2_dir_i
2508         .removexattr    = generic_removexattr,
2509  #endif
2510         .setattr        = ext2_setattr,
2511 +       .sync_flags     = ext2_sync_flags,
2512         .get_acl        = ext2_get_acl,
2513  };
2514  
2515 diff -NurpP --minimal linux-3.6/fs/ext2/super.c linux-3.6-vs2.3.4.3-noxfs-nocow/fs/ext2/super.c
2516 --- linux-3.6/fs/ext2/super.c   2012-10-04 15:27:39.000000000 +0200
2517 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/fs/ext2/super.c     2012-10-04 18:47:00.000000000 +0200
2518 @@ -390,7 +390,8 @@ enum {
2519         Opt_err_ro, Opt_nouid32, Opt_nocheck, Opt_debug,
2520         Opt_oldalloc, Opt_orlov, Opt_nobh, Opt_user_xattr, Opt_nouser_xattr,
2521         Opt_acl, Opt_noacl, Opt_xip, Opt_ignore, Opt_err, Opt_quota,
2522 -       Opt_usrquota, Opt_grpquota, Opt_reservation, Opt_noreservation
2523 +       Opt_usrquota, Opt_grpquota, Opt_reservation, Opt_noreservation,
2524 +       Opt_tag, Opt_notag, Opt_tagid
2525  };
2526  
2527  static const match_table_t tokens = {
2528 @@ -418,6 +419,9 @@ static const match_table_t tokens = {
2529         {Opt_acl, "acl"},
2530         {Opt_noacl, "noacl"},
2531         {Opt_xip, "xip"},
2532 +       {Opt_tag, "tag"},
2533 +       {Opt_notag, "notag"},
2534 +       {Opt_tagid, "tagid=%u"},
2535         {Opt_grpquota, "grpquota"},
2536         {Opt_ignore, "noquota"},
2537         {Opt_quota, "quota"},
2538 @@ -501,6 +505,20 @@ static int parse_options(char *options, 
2539                 case Opt_nouid32:
2540                         set_opt (sbi->s_mount_opt, NO_UID32);
2541                         break;
2542 +#ifndef CONFIG_TAGGING_NONE
2543 +               case Opt_tag:
2544 +                       set_opt (sbi->s_mount_opt, TAGGED);
2545 +                       break;
2546 +               case Opt_notag:
2547 +                       clear_opt (sbi->s_mount_opt, TAGGED);
2548 +                       break;
2549 +#endif
2550 +#ifdef CONFIG_PROPAGATE
2551 +               case Opt_tagid:
2552 +                       /* use args[0] */
2553 +                       set_opt (sbi->s_mount_opt, TAGGED);
2554 +                       break;
2555 +#endif
2556                 case Opt_nocheck:
2557                         clear_opt (sbi->s_mount_opt, CHECK);
2558                         break;
2559 @@ -859,6 +877,8 @@ static int ext2_fill_super(struct super_
2560         if (!parse_options((char *) data, sb))
2561                 goto failed_mount;
2562  
2563 +       if (EXT2_SB(sb)->s_mount_opt & EXT2_MOUNT_TAGGED)
2564 +               sb->s_flags |= MS_TAGGED;
2565         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
2566                 ((EXT2_SB(sb)->s_mount_opt & EXT2_MOUNT_POSIX_ACL) ?
2567                  MS_POSIXACL : 0);
2568 @@ -1265,6 +1285,14 @@ static int ext2_remount (struct super_bl
2569                 goto restore_opts;
2570         }
2571  
2572 +       if ((sbi->s_mount_opt & EXT2_MOUNT_TAGGED) &&
2573 +               !(sb->s_flags & MS_TAGGED)) {
2574 +               printk("EXT2-fs: %s: tagging not permitted on remount.\n",
2575 +                      sb->s_id);
2576 +               err = -EINVAL;
2577 +               goto restore_opts;
2578 +       }
2579 +
2580         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
2581                 ((sbi->s_mount_opt & EXT2_MOUNT_POSIX_ACL) ? MS_POSIXACL : 0);
2582  
2583 diff -NurpP --minimal linux-3.6/fs/ext3/ext3.h linux-3.6-vs2.3.4.3-noxfs-nocow/fs/ext3/ext3.h
2584 --- linux-3.6/fs/ext3/ext3.h    2012-07-22 23:39:39.000000000 +0200
2585 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/fs/ext3/ext3.h      2012-10-04 18:47:00.000000000 +0200
2586 @@ -151,10 +151,14 @@ struct ext3_group_desc
2587  #define EXT3_NOTAIL_FL                 0x00008000 /* file tail should not be merged */
2588  #define EXT3_DIRSYNC_FL                        0x00010000 /* dirsync behaviour (directories only) */
2589  #define EXT3_TOPDIR_FL                 0x00020000 /* Top of directory hierarchies*/
2590 +#define EXT3_IXUNLINK_FL               0x08000000 /* Immutable invert on unlink */
2591  #define EXT3_RESERVED_FL               0x80000000 /* reserved for ext3 lib */
2592  
2593 -#define EXT3_FL_USER_VISIBLE           0x0003DFFF /* User visible flags */
2594 -#define EXT3_FL_USER_MODIFIABLE                0x000380FF /* User modifiable flags */
2595 +#define EXT3_BARRIER_FL                        0x04000000 /* Barrier for chroot() */
2596 +#define EXT3_COW_FL                    0x20000000 /* Copy on Write marker */
2597 +
2598 +#define EXT3_FL_USER_VISIBLE           0x0103DFFF /* User visible flags */
2599 +#define EXT3_FL_USER_MODIFIABLE                0x010380FF /* User modifiable flags */
2600  
2601  /* Flags that should be inherited by new inodes from their parent. */
2602  #define EXT3_FL_INHERITED (EXT3_SECRM_FL | EXT3_UNRM_FL | EXT3_COMPR_FL |\
2603 @@ -290,7 +294,8 @@ struct ext3_inode {
2604                         __u16   i_pad1;
2605                         __le16  l_i_uid_high;   /* these 2 fields    */
2606                         __le16  l_i_gid_high;   /* were reserved2[0] */
2607 -                       __u32   l_i_reserved2;
2608 +                       __le16  l_i_tag;        /* Context Tag */
2609 +                       __u16   l_i_reserved2;
2610                 } linux2;
2611                 struct {
2612                         __u8    h_i_frag;       /* Fragment number */
2613 @@ -320,6 +325,7 @@ struct ext3_inode {
2614  #define i_gid_low      i_gid
2615  #define i_uid_high     osd2.linux2.l_i_uid_high
2616  #define i_gid_high     osd2.linux2.l_i_gid_high
2617 +#define i_raw_tag      osd2.linux2.l_i_tag
2618  #define i_reserved2    osd2.linux2.l_i_reserved2
2619  
2620  /*
2621 @@ -364,6 +370,7 @@ struct ext3_inode {
2622  #define EXT3_MOUNT_GRPQUOTA            0x200000 /* "old" group quota */
2623  #define EXT3_MOUNT_DATA_ERR_ABORT      0x400000 /* Abort on file data write
2624                                                   * error in ordered mode */
2625 +#define EXT3_MOUNT_TAGGED              (1<<24) /* Enable Context Tags */
2626  
2627  /* Compatibility, for having both ext2_fs.h and ext3_fs.h included at once */
2628  #ifndef _LINUX_EXT2_FS_H
2629 @@ -1061,6 +1068,7 @@ extern void ext3_get_inode_flags(struct 
2630  extern void ext3_set_aops(struct inode *inode);
2631  extern int ext3_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
2632                        u64 start, u64 len);
2633 +extern int ext3_sync_flags(struct inode *, int, int);
2634  
2635  /* ioctl.c */
2636  extern long ext3_ioctl(struct file *, unsigned int, unsigned long);
2637 diff -NurpP --minimal linux-3.6/fs/ext3/file.c linux-3.6-vs2.3.4.3-noxfs-nocow/fs/ext3/file.c
2638 --- linux-3.6/fs/ext3/file.c    2012-05-21 18:07:20.000000000 +0200
2639 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/fs/ext3/file.c      2012-10-04 18:47:00.000000000 +0200
2640 @@ -76,5 +76,6 @@ const struct inode_operations ext3_file_
2641  #endif
2642         .get_acl        = ext3_get_acl,
2643         .fiemap         = ext3_fiemap,
2644 +       .sync_flags     = ext3_sync_flags,
2645  };
2646  
2647 diff -NurpP --minimal linux-3.6/fs/ext3/ialloc.c linux-3.6-vs2.3.4.3-noxfs-nocow/fs/ext3/ialloc.c
2648 --- linux-3.6/fs/ext3/ialloc.c  2012-07-22 23:39:39.000000000 +0200
2649 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/fs/ext3/ialloc.c    2012-10-04 18:47:00.000000000 +0200
2650 @@ -14,6 +14,7 @@
2651  
2652  #include <linux/quotaops.h>
2653  #include <linux/random.h>
2654 +#include <linux/vs_tag.h>
2655  
2656  #include "ext3.h"
2657  #include "xattr.h"
2658 @@ -469,6 +470,7 @@ got:
2659                 inode->i_mode = mode;
2660                 inode->i_uid = current_fsuid();
2661                 inode->i_gid = dir->i_gid;
2662 +               inode->i_tag = dx_current_fstag(sb);
2663         } else
2664                 inode_init_owner(inode, dir, mode);
2665  
2666 diff -NurpP --minimal linux-3.6/fs/ext3/inode.c linux-3.6-vs2.3.4.3-noxfs-nocow/fs/ext3/inode.c
2667 --- linux-3.6/fs/ext3/inode.c   2012-10-04 15:27:39.000000000 +0200
2668 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/fs/ext3/inode.c     2012-10-04 18:47:00.000000000 +0200
2669 @@ -27,6 +27,8 @@
2670  #include <linux/writeback.h>
2671  #include <linux/mpage.h>
2672  #include <linux/namei.h>
2673 +#include <linux/vs_tag.h>
2674 +
2675  #include "ext3.h"
2676  #include "xattr.h"
2677  #include "acl.h"
2678 @@ -2848,36 +2850,60 @@ void ext3_set_inode_flags(struct inode *
2679  {
2680         unsigned int flags = EXT3_I(inode)->i_flags;
2681  
2682 -       inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
2683 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
2684 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
2685 +
2686 +       if (flags & EXT3_IMMUTABLE_FL)
2687 +               inode->i_flags |= S_IMMUTABLE;
2688 +       if (flags & EXT3_IXUNLINK_FL)
2689 +               inode->i_flags |= S_IXUNLINK;
2690 +
2691         if (flags & EXT3_SYNC_FL)
2692                 inode->i_flags |= S_SYNC;
2693         if (flags & EXT3_APPEND_FL)
2694                 inode->i_flags |= S_APPEND;
2695 -       if (flags & EXT3_IMMUTABLE_FL)
2696 -               inode->i_flags |= S_IMMUTABLE;
2697         if (flags & EXT3_NOATIME_FL)
2698                 inode->i_flags |= S_NOATIME;
2699         if (flags & EXT3_DIRSYNC_FL)
2700                 inode->i_flags |= S_DIRSYNC;
2701 +
2702 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
2703 +
2704 +       if (flags & EXT3_BARRIER_FL)
2705 +               inode->i_vflags |= V_BARRIER;
2706 +       if (flags & EXT3_COW_FL)
2707 +               inode->i_vflags |= V_COW;
2708  }
2709  
2710  /* Propagate flags from i_flags to EXT3_I(inode)->i_flags */
2711  void ext3_get_inode_flags(struct ext3_inode_info *ei)
2712  {
2713         unsigned int flags = ei->vfs_inode.i_flags;
2714 +       unsigned int vflags = ei->vfs_inode.i_vflags;
2715 +
2716 +       ei->i_flags &= ~(EXT3_SYNC_FL | EXT3_APPEND_FL |
2717 +                       EXT3_IMMUTABLE_FL | EXT3_IXUNLINK_FL |
2718 +                       EXT3_NOATIME_FL | EXT3_DIRSYNC_FL |
2719 +                       EXT3_BARRIER_FL | EXT3_COW_FL);
2720 +
2721 +       if (flags & S_IMMUTABLE)
2722 +               ei->i_flags |= EXT3_IMMUTABLE_FL;
2723 +       if (flags & S_IXUNLINK)
2724 +               ei->i_flags |= EXT3_IXUNLINK_FL;
2725  
2726 -       ei->i_flags &= ~(EXT3_SYNC_FL|EXT3_APPEND_FL|
2727 -                       EXT3_IMMUTABLE_FL|EXT3_NOATIME_FL|EXT3_DIRSYNC_FL);
2728         if (flags & S_SYNC)
2729                 ei->i_flags |= EXT3_SYNC_FL;
2730         if (flags & S_APPEND)
2731                 ei->i_flags |= EXT3_APPEND_FL;
2732 -       if (flags & S_IMMUTABLE)
2733 -               ei->i_flags |= EXT3_IMMUTABLE_FL;
2734         if (flags & S_NOATIME)
2735                 ei->i_flags |= EXT3_NOATIME_FL;
2736         if (flags & S_DIRSYNC)
2737                 ei->i_flags |= EXT3_DIRSYNC_FL;
2738 +
2739 +       if (vflags & V_BARRIER)
2740 +               ei->i_flags |= EXT3_BARRIER_FL;
2741 +       if (vflags & V_COW)
2742 +               ei->i_flags |= EXT3_COW_FL;
2743  }
2744  
2745  struct inode *ext3_iget(struct super_block *sb, unsigned long ino)
2746 @@ -2915,8 +2941,10 @@ struct inode *ext3_iget(struct super_blo
2747                 i_uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
2748                 i_gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
2749         }
2750 -       i_uid_write(inode, i_uid);
2751 -       i_gid_write(inode, i_gid);
2752 +       i_uid_write(inode, INOTAG_UID(DX_TAG(inode), i_uid, i_gid));
2753 +       i_gid_write(inode, INOTAG_GID(DX_TAG(inode), i_uid, i_gid));
2754 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), i_uid, i_gid,
2755 +               le16_to_cpu(raw_inode->i_raw_tag));
2756         set_nlink(inode, le16_to_cpu(raw_inode->i_links_count));
2757         inode->i_size = le32_to_cpu(raw_inode->i_size);
2758         inode->i_atime.tv_sec = (signed)le32_to_cpu(raw_inode->i_atime);
2759 @@ -3088,8 +3116,8 @@ again:
2760  
2761         ext3_get_inode_flags(ei);
2762         raw_inode->i_mode = cpu_to_le16(inode->i_mode);
2763 -       i_uid = i_uid_read(inode);
2764 -       i_gid = i_gid_read(inode);
2765 +       i_uid = TAGINO_UID(DX_TAG(inode), i_uid_read(inode), inode->i_tag);
2766 +       i_gid = TAGINO_GID(DX_TAG(inode), i_gid_read(inode), inode->i_tag);
2767         if(!(test_opt(inode->i_sb, NO_UID32))) {
2768                 raw_inode->i_uid_low = cpu_to_le16(low_16_bits(i_uid));
2769                 raw_inode->i_gid_low = cpu_to_le16(low_16_bits(i_gid));
2770 @@ -3114,6 +3142,9 @@ again:
2771                 raw_inode->i_uid_high = 0;
2772                 raw_inode->i_gid_high = 0;
2773         }
2774 +#ifdef CONFIG_TAGGING_INTERN
2775 +       raw_inode->i_raw_tag = cpu_to_le16(inode->i_tag);
2776 +#endif
2777         raw_inode->i_links_count = cpu_to_le16(inode->i_nlink);
2778         disksize = cpu_to_le32(ei->i_disksize);
2779         if (disksize != raw_inode->i_size) {
2780 @@ -3282,7 +3313,8 @@ int ext3_setattr(struct dentry *dentry, 
2781         if (is_quota_modification(inode, attr))
2782                 dquot_initialize(inode);
2783         if ((ia_valid & ATTR_UID && !uid_eq(attr->ia_uid, inode->i_uid)) ||
2784 -           (ia_valid & ATTR_GID && !gid_eq(attr->ia_gid, inode->i_gid))) {
2785 +           (ia_valid & ATTR_GID && !gid_eq(attr->ia_gid, inode->i_gid)) ||
2786 +           (ia_valid & ATTR_TAG && attr->ia_tag != inode->i_tag)) {
2787                 handle_t *handle;
2788  
2789                 /* (user+group)*(old+new) structure, inode write (sb,
2790 @@ -3304,6 +3336,8 @@ int ext3_setattr(struct dentry *dentry, 
2791                         inode->i_uid = attr->ia_uid;
2792                 if (attr->ia_valid & ATTR_GID)
2793                         inode->i_gid = attr->ia_gid;
2794 +               if ((attr->ia_valid & ATTR_TAG) && IS_TAGGED(inode))
2795 +                       inode->i_tag = attr->ia_tag;
2796                 error = ext3_mark_inode_dirty(handle, inode);
2797                 ext3_journal_stop(handle);
2798         }
2799 diff -NurpP --minimal linux-3.6/fs/ext3/ioctl.c linux-3.6-vs2.3.4.3-noxfs-nocow/fs/ext3/ioctl.c
2800 --- linux-3.6/fs/ext3/ioctl.c   2012-05-21 18:07:20.000000000 +0200
2801 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/fs/ext3/ioctl.c     2012-10-04 18:47:00.000000000 +0200
2802 @@ -12,6 +12,34 @@
2803  #include <asm/uaccess.h>
2804  #include "ext3.h"
2805  
2806 +
2807 +int ext3_sync_flags(struct inode *inode, int flags, int vflags)
2808 +{
2809 +       handle_t *handle = NULL;
2810 +       struct ext3_iloc iloc;
2811 +       int err;
2812 +
2813 +       handle = ext3_journal_start(inode, 1);
2814 +       if (IS_ERR(handle))
2815 +               return PTR_ERR(handle);
2816 +
2817 +       if (IS_SYNC(inode))
2818 +               handle->h_sync = 1;
2819 +       err = ext3_reserve_inode_write(handle, inode, &iloc);
2820 +       if (err)
2821 +               goto flags_err;
2822 +
2823 +       inode->i_flags = flags;
2824 +       inode->i_vflags = vflags;
2825 +       ext3_get_inode_flags(EXT3_I(inode));
2826 +       inode->i_ctime = CURRENT_TIME_SEC;
2827 +
2828 +       err = ext3_mark_iloc_dirty(handle, inode, &iloc);
2829 +flags_err:
2830 +       ext3_journal_stop(handle);
2831 +       return err;
2832 +}
2833 +
2834  long ext3_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
2835  {
2836         struct inode *inode = filp->f_dentry->d_inode;
2837 @@ -45,6 +73,11 @@ long ext3_ioctl(struct file *filp, unsig
2838  
2839                 flags = ext3_mask_flags(inode->i_mode, flags);
2840  
2841 +               if (IS_BARRIER(inode)) {
2842 +                       vxwprintk_task(1, "messing with the barrier.");
2843 +                       return -EACCES;
2844 +               }
2845 +
2846                 mutex_lock(&inode->i_mutex);
2847  
2848                 /* Is it quota file? Do not allow user to mess with it */
2849 @@ -63,7 +96,9 @@ long ext3_ioctl(struct file *filp, unsig
2850                  *
2851                  * This test looks nicer. Thanks to Pauline Middelink
2852                  */
2853 -               if ((flags ^ oldflags) & (EXT3_APPEND_FL | EXT3_IMMUTABLE_FL)) {
2854 +               if ((oldflags & EXT3_IMMUTABLE_FL) ||
2855 +                       ((flags ^ oldflags) & (EXT3_APPEND_FL |
2856 +                       EXT3_IMMUTABLE_FL | EXT3_IXUNLINK_FL))) {
2857                         if (!capable(CAP_LINUX_IMMUTABLE))
2858                                 goto flags_out;
2859                 }
2860 @@ -88,7 +123,7 @@ long ext3_ioctl(struct file *filp, unsig
2861                 if (err)
2862                         goto flags_err;
2863  
2864 -               flags = flags & EXT3_FL_USER_MODIFIABLE;
2865 +               flags &= EXT3_FL_USER_MODIFIABLE;
2866                 flags |= oldflags & ~EXT3_FL_USER_MODIFIABLE;
2867                 ei->i_flags = flags;
2868  
2869 diff -NurpP --minimal linux-3.6/fs/ext3/namei.c linux-3.6-vs2.3.4.3-noxfs-nocow/fs/ext3/namei.c
2870 --- linux-3.6/fs/ext3/namei.c   2012-10-04 15:27:39.000000000 +0200
2871 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/fs/ext3/namei.c     2012-10-04 18:47:00.000000000 +0200
2872 @@ -25,6 +25,8 @@
2873   */
2874  
2875  #include <linux/quotaops.h>
2876 +#include <linux/vs_tag.h>
2877 +
2878  #include "ext3.h"
2879  #include "namei.h"
2880  #include "xattr.h"
2881 @@ -915,6 +917,7 @@ restart:
2882                                         submit_bh(READ | REQ_META | REQ_PRIO,
2883                                                   bh);
2884                                 }
2885 +               dx_propagate_tag(nd, inode);
2886                         }
2887                 }
2888                 if ((bh = bh_use[ra_ptr++]) == NULL)
2889 @@ -2526,6 +2529,7 @@ const struct inode_operations ext3_dir_i
2890         .listxattr      = ext3_listxattr,
2891         .removexattr    = generic_removexattr,
2892  #endif
2893 +       .sync_flags     = ext3_sync_flags,
2894         .get_acl        = ext3_get_acl,
2895  };
2896  
2897 diff -NurpP --minimal linux-3.6/fs/ext3/super.c linux-3.6-vs2.3.4.3-noxfs-nocow/fs/ext3/super.c
2898 --- linux-3.6/fs/ext3/super.c   2012-10-04 15:27:39.000000000 +0200
2899 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/fs/ext3/super.c     2012-10-04 18:47:00.000000000 +0200
2900 @@ -811,7 +811,8 @@ enum {
2901         Opt_usrjquota, Opt_grpjquota, Opt_offusrjquota, Opt_offgrpjquota,
2902         Opt_jqfmt_vfsold, Opt_jqfmt_vfsv0, Opt_jqfmt_vfsv1, Opt_quota,
2903         Opt_noquota, Opt_ignore, Opt_barrier, Opt_nobarrier, Opt_err,
2904 -       Opt_resize, Opt_usrquota, Opt_grpquota
2905 +       Opt_resize, Opt_usrquota, Opt_grpquota,
2906 +       Opt_tag, Opt_notag, Opt_tagid
2907  };
2908  
2909  static const match_table_t tokens = {
2910 @@ -868,6 +869,9 @@ static const match_table_t tokens = {
2911         {Opt_barrier, "barrier"},
2912         {Opt_nobarrier, "nobarrier"},
2913         {Opt_resize, "resize"},
2914 +       {Opt_tag, "tag"},
2915 +       {Opt_notag, "notag"},
2916 +       {Opt_tagid, "tagid=%u"},
2917         {Opt_err, NULL},
2918  };
2919  
2920 @@ -1033,6 +1037,20 @@ static int parse_options (char *options,
2921                 case Opt_nouid32:
2922                         set_opt (sbi->s_mount_opt, NO_UID32);
2923                         break;
2924 +#ifndef CONFIG_TAGGING_NONE
2925 +               case Opt_tag:
2926 +                       set_opt (sbi->s_mount_opt, TAGGED);
2927 +                       break;
2928 +               case Opt_notag:
2929 +                       clear_opt (sbi->s_mount_opt, TAGGED);
2930 +                       break;
2931 +#endif
2932 +#ifdef CONFIG_PROPAGATE
2933 +               case Opt_tagid:
2934 +                       /* use args[0] */
2935 +                       set_opt (sbi->s_mount_opt, TAGGED);
2936 +                       break;
2937 +#endif
2938                 case Opt_nocheck:
2939                         clear_opt (sbi->s_mount_opt, CHECK);
2940                         break;
2941 @@ -1731,6 +1749,9 @@ static int ext3_fill_super (struct super
2942                             NULL, 0))
2943                 goto failed_mount;
2944  
2945 +       if (EXT3_SB(sb)->s_mount_opt & EXT3_MOUNT_TAGGED)
2946 +               sb->s_flags |= MS_TAGGED;
2947 +
2948         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
2949                 (test_opt(sb, POSIX_ACL) ? MS_POSIXACL : 0);
2950  
2951 @@ -2618,6 +2639,14 @@ static int ext3_remount (struct super_bl
2952         if (test_opt(sb, ABORT))
2953                 ext3_abort(sb, __func__, "Abort forced by user");
2954  
2955 +       if ((sbi->s_mount_opt & EXT3_MOUNT_TAGGED) &&
2956 +               !(sb->s_flags & MS_TAGGED)) {
2957 +               printk("EXT3-fs: %s: tagging not permitted on remount.\n",
2958 +                       sb->s_id);
2959 +               err = -EINVAL;
2960 +               goto restore_opts;
2961 +       }
2962 +
2963         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
2964                 (test_opt(sb, POSIX_ACL) ? MS_POSIXACL : 0);
2965  
2966 diff -NurpP --minimal linux-3.6/fs/ext4/ext4.h linux-3.6-vs2.3.4.3-noxfs-nocow/fs/ext4/ext4.h
2967 --- linux-3.6/fs/ext4/ext4.h    2012-10-04 15:27:39.000000000 +0200
2968 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/fs/ext4/ext4.h      2012-10-04 18:47:00.000000000 +0200
2969 @@ -393,8 +393,12 @@ struct flex_groups {
2970  #define EXT4_EXTENTS_FL                        0x00080000 /* Inode uses extents */
2971  #define EXT4_EA_INODE_FL               0x00200000 /* Inode used for large EA */
2972  #define EXT4_EOFBLOCKS_FL              0x00400000 /* Blocks allocated beyond EOF */
2973 +#define EXT4_IXUNLINK_FL               0x08000000 /* Immutable invert on unlink */
2974  #define EXT4_RESERVED_FL               0x80000000 /* reserved for ext4 lib */
2975  
2976 +#define EXT4_BARRIER_FL                        0x04000000 /* Barrier for chroot() */
2977 +#define EXT4_COW_FL                    0x20000000 /* Copy on Write marker */
2978 +
2979  #define EXT4_FL_USER_VISIBLE           0x004BDFFF /* User visible flags */
2980  #define EXT4_FL_USER_MODIFIABLE                0x004B80FF /* User modifiable flags */
2981  
2982 @@ -666,7 +670,7 @@ struct ext4_inode {
2983                         __le16  l_i_uid_high;   /* these 2 fields */
2984                         __le16  l_i_gid_high;   /* were reserved2[0] */
2985                         __le16  l_i_checksum_lo;/* crc32c(uuid+inum+inode) LE */
2986 -                       __le16  l_i_reserved;
2987 +                       __le16  l_i_tag;        /* Context Tag */
2988                 } linux2;
2989                 struct {
2990                         __le16  h_i_reserved1;  /* Obsoleted fragment number/size which are removed in ext4 */
2991 @@ -784,6 +788,7 @@ do {                                                                               \
2992  #define i_gid_low      i_gid
2993  #define i_uid_high     osd2.linux2.l_i_uid_high
2994  #define i_gid_high     osd2.linux2.l_i_gid_high
2995 +#define i_raw_tag      osd2.linux2.l_i_tag
2996  #define i_checksum_lo  osd2.linux2.l_i_checksum_lo
2997  
2998  #elif defined(__GNU__)
2999 @@ -964,6 +969,7 @@ struct ext4_inode_info {
3000  #define EXT4_MOUNT_POSIX_ACL           0x08000 /* POSIX Access Control Lists */
3001  #define EXT4_MOUNT_NO_AUTO_DA_ALLOC    0x10000 /* No auto delalloc mapping */
3002  #define EXT4_MOUNT_BARRIER             0x20000 /* Use block barriers */
3003 +#define EXT4_MOUNT_TAGGED              0x40000 /* Enable Context Tags */
3004  #define EXT4_MOUNT_QUOTA               0x80000 /* Some quota option set */
3005  #define EXT4_MOUNT_USRQUOTA            0x100000 /* "old" user quota */
3006  #define EXT4_MOUNT_GRPQUOTA            0x200000 /* "old" group quota */
3007 @@ -2393,6 +2399,7 @@ extern int ext4_map_blocks(handle_t *han
3008                            struct ext4_map_blocks *map, int flags);
3009  extern int ext4_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
3010                         __u64 start, __u64 len);
3011 +extern int ext4_sync_flags(struct inode *, int, int);
3012  /* move_extent.c */
3013  extern int ext4_move_extents(struct file *o_filp, struct file *d_filp,
3014                              __u64 start_orig, __u64 start_donor,
3015 diff -NurpP --minimal linux-3.6/fs/ext4/file.c linux-3.6-vs2.3.4.3-noxfs-nocow/fs/ext4/file.c
3016 --- linux-3.6/fs/ext4/file.c    2012-10-04 15:27:39.000000000 +0200
3017 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/fs/ext4/file.c      2012-10-04 18:47:00.000000000 +0200
3018 @@ -334,5 +334,6 @@ const struct inode_operations ext4_file_
3019  #endif
3020         .get_acl        = ext4_get_acl,
3021         .fiemap         = ext4_fiemap,
3022 +       .sync_flags     = ext4_sync_flags,
3023  };
3024  
3025 diff -NurpP --minimal linux-3.6/fs/ext4/ialloc.c linux-3.6-vs2.3.4.3-noxfs-nocow/fs/ext4/ialloc.c
3026 --- linux-3.6/fs/ext4/ialloc.c  2012-10-04 15:27:39.000000000 +0200
3027 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/fs/ext4/ialloc.c    2012-10-04 18:47:00.000000000 +0200
3028 @@ -22,6 +22,7 @@
3029  #include <linux/random.h>
3030  #include <linux/bitops.h>
3031  #include <linux/blkdev.h>
3032 +#include <linux/vs_tag.h>
3033  #include <asm/byteorder.h>
3034  
3035  #include "ext4.h"
3036 @@ -842,6 +843,7 @@ got:
3037                 inode->i_mode = mode;
3038                 inode->i_uid = current_fsuid();
3039                 inode->i_gid = dir->i_gid;
3040 +               inode->i_tag = dx_current_fstag(sb);
3041         } else
3042                 inode_init_owner(inode, dir, mode);
3043  
3044 diff -NurpP --minimal linux-3.6/fs/ext4/inode.c linux-3.6-vs2.3.4.3-noxfs-nocow/fs/ext4/inode.c
3045 --- linux-3.6/fs/ext4/inode.c   2012-10-04 15:27:39.000000000 +0200
3046 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/fs/ext4/inode.c     2012-10-04 18:47:00.000000000 +0200
3047 @@ -37,6 +37,7 @@
3048  #include <linux/printk.h>
3049  #include <linux/slab.h>
3050  #include <linux/ratelimit.h>
3051 +#include <linux/vs_tag.h>
3052  
3053  #include "ext4_jbd2.h"
3054  #include "xattr.h"
3055 @@ -3712,41 +3713,64 @@ void ext4_set_inode_flags(struct inode *
3056  {
3057         unsigned int flags = EXT4_I(inode)->i_flags;
3058  
3059 -       inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
3060 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
3061 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
3062 +
3063 +       if (flags & EXT4_IMMUTABLE_FL)
3064 +               inode->i_flags |= S_IMMUTABLE;
3065 +       if (flags & EXT4_IXUNLINK_FL)
3066 +               inode->i_flags |= S_IXUNLINK;
3067 +
3068         if (flags & EXT4_SYNC_FL)
3069                 inode->i_flags |= S_SYNC;
3070         if (flags & EXT4_APPEND_FL)
3071                 inode->i_flags |= S_APPEND;
3072 -       if (flags & EXT4_IMMUTABLE_FL)
3073 -               inode->i_flags |= S_IMMUTABLE;
3074         if (flags & EXT4_NOATIME_FL)
3075                 inode->i_flags |= S_NOATIME;
3076         if (flags & EXT4_DIRSYNC_FL)
3077                 inode->i_flags |= S_DIRSYNC;
3078 +
3079 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
3080 +
3081 +       if (flags & EXT4_BARRIER_FL)
3082 +               inode->i_vflags |= V_BARRIER;
3083 +       if (flags & EXT4_COW_FL)
3084 +               inode->i_vflags |= V_COW;
3085  }
3086  
3087  /* Propagate flags from i_flags to EXT4_I(inode)->i_flags */
3088  void ext4_get_inode_flags(struct ext4_inode_info *ei)
3089  {
3090 -       unsigned int vfs_fl;
3091 +       unsigned int vfs_fl, vfs_vf;
3092         unsigned long old_fl, new_fl;
3093  
3094         do {
3095                 vfs_fl = ei->vfs_inode.i_flags;
3096 +               vfs_vf = ei->vfs_inode.i_vflags;
3097                 old_fl = ei->i_flags;
3098                 new_fl = old_fl & ~(EXT4_SYNC_FL|EXT4_APPEND_FL|
3099                                 EXT4_IMMUTABLE_FL|EXT4_NOATIME_FL|
3100 -                               EXT4_DIRSYNC_FL);
3101 +                               EXT4_DIRSYNC_FL|EXT4_BARRIER_FL|
3102 +                               EXT4_COW_FL);
3103 +
3104 +               if (vfs_fl & S_IMMUTABLE)
3105 +                       new_fl |= EXT4_IMMUTABLE_FL;
3106 +               if (vfs_fl & S_IXUNLINK)
3107 +                       new_fl |= EXT4_IXUNLINK_FL;
3108 +
3109                 if (vfs_fl & S_SYNC)
3110                         new_fl |= EXT4_SYNC_FL;
3111                 if (vfs_fl & S_APPEND)
3112                         new_fl |= EXT4_APPEND_FL;
3113 -               if (vfs_fl & S_IMMUTABLE)
3114 -                       new_fl |= EXT4_IMMUTABLE_FL;
3115                 if (vfs_fl & S_NOATIME)
3116                         new_fl |= EXT4_NOATIME_FL;
3117                 if (vfs_fl & S_DIRSYNC)
3118                         new_fl |= EXT4_DIRSYNC_FL;
3119 +
3120 +               if (vfs_vf & V_BARRIER)
3121 +                       new_fl |= EXT4_BARRIER_FL;
3122 +               if (vfs_vf & V_COW)
3123 +                       new_fl |= EXT4_COW_FL;
3124         } while (cmpxchg(&ei->i_flags, old_fl, new_fl) != old_fl);
3125  }
3126  
3127 @@ -3838,8 +3862,10 @@ struct inode *ext4_iget(struct super_blo
3128                 i_uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
3129                 i_gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
3130         }
3131 -       i_uid_write(inode, i_uid);
3132 -       i_gid_write(inode, i_gid);
3133 +       i_uid_write(inode, INOTAG_UID(DX_TAG(inode), i_uid, i_gid));
3134 +       i_gid_write(inode, INOTAG_GID(DX_TAG(inode), i_uid, i_gid));
3135 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), i_uid, i_gid,
3136 +               le16_to_cpu(raw_inode->i_raw_tag));
3137         set_nlink(inode, le16_to_cpu(raw_inode->i_links_count));
3138  
3139         ext4_clear_state_flags(ei);     /* Only relevant on 32-bit archs */
3140 @@ -4062,8 +4088,8 @@ static int ext4_do_update_inode(handle_t
3141  
3142         ext4_get_inode_flags(ei);
3143         raw_inode->i_mode = cpu_to_le16(inode->i_mode);
3144 -       i_uid = i_uid_read(inode);
3145 -       i_gid = i_gid_read(inode);
3146 +       i_uid = TAGINO_UID(DX_TAG(inode), i_uid_read(inode), inode->i_tag);
3147 +       i_gid = TAGINO_GID(DX_TAG(inode), i_gid_read(inode), inode->i_tag);
3148         if (!(test_opt(inode->i_sb, NO_UID32))) {
3149                 raw_inode->i_uid_low = cpu_to_le16(low_16_bits(i_uid));
3150                 raw_inode->i_gid_low = cpu_to_le16(low_16_bits(i_gid));
3151 @@ -4086,6 +4112,9 @@ static int ext4_do_update_inode(handle_t
3152                 raw_inode->i_uid_high = 0;
3153                 raw_inode->i_gid_high = 0;
3154         }
3155 +#ifdef CONFIG_TAGGING_INTERN
3156 +       raw_inode->i_raw_tag = cpu_to_le16(inode->i_tag);
3157 +#endif
3158         raw_inode->i_links_count = cpu_to_le16(inode->i_nlink);
3159  
3160         EXT4_INODE_SET_XTIME(i_ctime, inode, raw_inode);
3161 @@ -4271,7 +4300,8 @@ int ext4_setattr(struct dentry *dentry, 
3162         if (is_quota_modification(inode, attr))
3163                 dquot_initialize(inode);
3164         if ((ia_valid & ATTR_UID && !uid_eq(attr->ia_uid, inode->i_uid)) ||
3165 -           (ia_valid & ATTR_GID && !gid_eq(attr->ia_gid, inode->i_gid))) {
3166 +           (ia_valid & ATTR_GID && !gid_eq(attr->ia_gid, inode->i_gid)) ||
3167 +           (ia_valid & ATTR_TAG && attr->ia_tag != inode->i_tag)) {
3168                 handle_t *handle;
3169  
3170                 /* (user+group)*(old+new) structure, inode write (sb,
3171 @@ -4293,6 +4323,8 @@ int ext4_setattr(struct dentry *dentry, 
3172                         inode->i_uid = attr->ia_uid;
3173                 if (attr->ia_valid & ATTR_GID)
3174                         inode->i_gid = attr->ia_gid;
3175 +               if ((attr->ia_valid & ATTR_TAG) && IS_TAGGED(inode))
3176 +                       inode->i_tag = attr->ia_tag;
3177                 error = ext4_mark_inode_dirty(handle, inode);
3178                 ext4_journal_stop(handle);
3179         }
3180 diff -NurpP --minimal linux-3.6/fs/ext4/ioctl.c linux-3.6-vs2.3.4.3-noxfs-nocow/fs/ext4/ioctl.c
3181 --- linux-3.6/fs/ext4/ioctl.c   2012-10-04 15:27:39.000000000 +0200
3182 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/fs/ext4/ioctl.c     2012-10-04 18:47:00.000000000 +0200
3183 @@ -14,12 +14,40 @@
3184  #include <linux/compat.h>
3185  #include <linux/mount.h>
3186  #include <linux/file.h>
3187 +#include <linux/vs_tag.h>
3188  #include <asm/uaccess.h>
3189  #include "ext4_jbd2.h"
3190  #include "ext4.h"
3191  
3192  #define MAX_32_NUM ((((unsigned long long) 1) << 32) - 1)
3193  
3194 +int ext4_sync_flags(struct inode *inode, int flags, int vflags)
3195 +{
3196 +       handle_t *handle = NULL;
3197 +       struct ext4_iloc iloc;
3198 +       int err;
3199 +
3200 +       handle = ext4_journal_start(inode, 1);
3201 +       if (IS_ERR(handle))
3202 +               return PTR_ERR(handle);
3203 +
3204 +       if (IS_SYNC(inode))
3205 +               ext4_handle_sync(handle);
3206 +       err = ext4_reserve_inode_write(handle, inode, &iloc);
3207 +       if (err)
3208 +               goto flags_err;
3209 +
3210 +       inode->i_flags = flags;
3211 +       inode->i_vflags = vflags;
3212 +       ext4_get_inode_flags(EXT4_I(inode));
3213 +       inode->i_ctime = ext4_current_time(inode);
3214 +
3215 +       err = ext4_mark_iloc_dirty(handle, inode, &iloc);
3216 +flags_err:
3217 +       ext4_journal_stop(handle);
3218 +       return err;
3219 +}
3220 +
3221  long ext4_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
3222  {
3223         struct inode *inode = filp->f_dentry->d_inode;
3224 @@ -53,6 +81,11 @@ long ext4_ioctl(struct file *filp, unsig
3225  
3226                 flags = ext4_mask_flags(inode->i_mode, flags);
3227  
3228 +               if (IS_BARRIER(inode)) {
3229 +                       vxwprintk_task(1, "messing with the barrier.");
3230 +                       return -EACCES;
3231 +               }
3232 +
3233                 err = -EPERM;
3234                 mutex_lock(&inode->i_mutex);
3235                 /* Is it quota file? Do not allow user to mess with it */
3236 @@ -70,7 +103,9 @@ long ext4_ioctl(struct file *filp, unsig
3237                  *
3238                  * This test looks nicer. Thanks to Pauline Middelink
3239                  */
3240 -               if ((flags ^ oldflags) & (EXT4_APPEND_FL | EXT4_IMMUTABLE_FL)) {
3241 +               if ((oldflags & EXT4_IMMUTABLE_FL) ||
3242 +                       ((flags ^ oldflags) & (EXT4_APPEND_FL |
3243 +                       EXT4_IMMUTABLE_FL | EXT4_IXUNLINK_FL))) {
3244                         if (!capable(CAP_LINUX_IMMUTABLE))
3245                                 goto flags_out;
3246                 }
3247 diff -NurpP --minimal linux-3.6/fs/ext4/namei.c linux-3.6-vs2.3.4.3-noxfs-nocow/fs/ext4/namei.c
3248 --- linux-3.6/fs/ext4/namei.c   2012-10-04 15:27:39.000000000 +0200
3249 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/fs/ext4/namei.c     2012-10-04 18:47:00.000000000 +0200
3250 @@ -34,6 +34,7 @@
3251  #include <linux/quotaops.h>
3252  #include <linux/buffer_head.h>
3253  #include <linux/bio.h>
3254 +#include <linux/vs_tag.h>
3255  #include "ext4.h"
3256  #include "ext4_jbd2.h"
3257  
3258 @@ -1199,6 +1200,7 @@ restart:
3259                                         ll_rw_block(READ | REQ_META | REQ_PRIO,
3260                                                     1, &bh);
3261                         }
3262 +               dx_propagate_tag(nd, inode);
3263                 }
3264                 if ((bh = bh_use[ra_ptr++]) == NULL)
3265                         goto next;
3266 @@ -2984,6 +2986,7 @@ const struct inode_operations ext4_dir_i
3267  #endif
3268         .get_acl        = ext4_get_acl,
3269         .fiemap         = ext4_fiemap,
3270 +       .sync_flags     = ext4_sync_flags,
3271  };
3272  
3273  const struct inode_operations ext4_special_inode_operations = {
3274 diff -NurpP --minimal linux-3.6/fs/ext4/super.c linux-3.6-vs2.3.4.3-noxfs-nocow/fs/ext4/super.c
3275 --- linux-3.6/fs/ext4/super.c   2012-10-04 15:27:39.000000000 +0200
3276 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/fs/ext4/super.c     2012-10-04 18:47:00.000000000 +0200
3277 @@ -1219,6 +1219,7 @@ enum {
3278         Opt_inode_readahead_blks, Opt_journal_ioprio,
3279         Opt_dioread_nolock, Opt_dioread_lock,
3280         Opt_discard, Opt_nodiscard, Opt_init_itable, Opt_noinit_itable,
3281 +       Opt_tag, Opt_notag, Opt_tagid
3282  };
3283  
3284  static const match_table_t tokens = {
3285 @@ -1297,6 +1298,9 @@ static const match_table_t tokens = {
3286         {Opt_removed, "reservation"},   /* mount option from ext2/3 */
3287         {Opt_removed, "noreservation"}, /* mount option from ext2/3 */
3288         {Opt_removed, "journal=%u"},    /* mount option from ext2/3 */
3289 +       {Opt_tag, "tag"},
3290 +       {Opt_notag, "notag"},
3291 +       {Opt_tagid, "tagid=%u"},
3292         {Opt_err, NULL},
3293  };
3294  
3295 @@ -1543,6 +1547,20 @@ static int handle_mount_opt(struct super
3296                         return -1;
3297                 *journal_ioprio = IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE, arg);
3298                 return 1;
3299 +#ifndef CONFIG_TAGGING_NONE
3300 +       case Opt_tag:
3301 +               set_opt(sb, TAGGED);
3302 +               return 1;
3303 +       case Opt_notag:
3304 +               clear_opt(sb, TAGGED);
3305 +               return 1;
3306 +#endif
3307 +#ifdef CONFIG_PROPAGATE
3308 +       case Opt_tagid:
3309 +               /* use args[0] */
3310 +               set_opt(sb, TAGGED);
3311 +               return 1;
3312 +#endif
3313         }
3314  
3315         for (m = ext4_mount_opts; m->token != Opt_err; m++) {
3316 @@ -3417,6 +3435,9 @@ static int ext4_fill_super(struct super_
3317                 }
3318         }
3319  
3320 +       if (EXT4_SB(sb)->s_mount_opt & EXT4_MOUNT_TAGGED)
3321 +               sb->s_flags |= MS_TAGGED;
3322 +
3323         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
3324                 (test_opt(sb, POSIX_ACL) ? MS_POSIXACL : 0);
3325  
3326 @@ -4582,6 +4603,14 @@ static int ext4_remount(struct super_blo
3327         if (sbi->s_mount_flags & EXT4_MF_FS_ABORTED)
3328                 ext4_abort(sb, "Abort forced by user");
3329  
3330 +       if ((sbi->s_mount_opt & EXT4_MOUNT_TAGGED) &&
3331 +               !(sb->s_flags & MS_TAGGED)) {
3332 +               printk("EXT4-fs: %s: tagging not permitted on remount.\n",
3333 +                       sb->s_id);
3334 +               err = -EINVAL;
3335 +               goto restore_opts;
3336 +       }
3337 +
3338         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
3339                 (test_opt(sb, POSIX_ACL) ? MS_POSIXACL : 0);
3340  
3341 diff -NurpP --minimal linux-3.6/fs/fcntl.c linux-3.6-vs2.3.4.3-noxfs-nocow/fs/fcntl.c
3342 --- linux-3.6/fs/fcntl.c        2012-10-04 15:27:39.000000000 +0200
3343 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/fs/fcntl.c  2012-10-04 19:05:02.000000000 +0200
3344 @@ -21,6 +21,7 @@
3345  #include <linux/rcupdate.h>
3346  #include <linux/pid_namespace.h>
3347  #include <linux/user_namespace.h>
3348 +#include <linux/vs_limit.h>
3349  
3350  #include <asm/poll.h>
3351  #include <asm/siginfo.h>
3352 @@ -104,6 +105,8 @@ SYSCALL_DEFINE3(dup3, unsigned int, oldf
3353  
3354         if (tofree)
3355                 filp_close(tofree, files);
3356 +       else
3357 +               vx_openfd_inc(newfd);   /* fd was unused */
3358  
3359         return newfd;
3360  
3361 @@ -477,6 +480,8 @@ SYSCALL_DEFINE3(fcntl, unsigned int, fd,
3362         filp = fget_raw_light(fd, &fput_needed);
3363         if (!filp)
3364                 goto out;
3365 +       if (!vx_files_avail(1))
3366 +               goto out;
3367  
3368         if (unlikely(filp->f_mode & FMODE_PATH)) {
3369                 if (!check_fcntl_cmd(cmd))
3370 diff -NurpP --minimal linux-3.6/fs/file.c linux-3.6-vs2.3.4.3-noxfs-nocow/fs/file.c
3371 --- linux-3.6/fs/file.c 2012-05-21 18:07:20.000000000 +0200
3372 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/fs/file.c   2012-10-04 18:47:00.000000000 +0200
3373 @@ -21,6 +21,7 @@
3374  #include <linux/spinlock.h>
3375  #include <linux/rcupdate.h>
3376  #include <linux/workqueue.h>
3377 +#include <linux/vs_limit.h>
3378  
3379  struct fdtable_defer {
3380         spinlock_t lock;
3381 @@ -358,6 +359,8 @@ struct files_struct *dup_fd(struct files
3382                 struct file *f = *old_fds++;
3383                 if (f) {
3384                         get_file(f);
3385 +                       /* TODO: sum it first for check and performance */
3386 +                       vx_openfd_inc(open_files - i);
3387                 } else {
3388                         /*
3389                          * The fd may be claimed in the fd bitmap but not yet
3390 @@ -464,6 +467,7 @@ repeat:
3391         else
3392                 __clear_close_on_exec(fd, fdt);
3393         error = fd;
3394 +       vx_openfd_inc(fd);
3395  #if 1
3396         /* Sanity check */
3397         if (rcu_dereference_raw(fdt->fd[fd]) != NULL) {
3398 diff -NurpP --minimal linux-3.6/fs/file_table.c linux-3.6-vs2.3.4.3-noxfs-nocow/fs/file_table.c
3399 --- linux-3.6/fs/file_table.c   2012-10-04 15:27:39.000000000 +0200
3400 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/fs/file_table.c     2012-10-04 19:10:21.000000000 +0200
3401 @@ -26,6 +26,8 @@
3402  #include <linux/hardirq.h>
3403  #include <linux/task_work.h>
3404  #include <linux/ima.h>
3405 +#include <linux/vs_limit.h>
3406 +#include <linux/vs_context.h>
3407  
3408  #include <linux/atomic.h>
3409  
3410 @@ -136,6 +138,8 @@ struct file *get_empty_filp(void)
3411         spin_lock_init(&f->f_lock);
3412         eventpoll_init_file(f);
3413         /* f->f_version: 0 */
3414 +       f->f_xid = vx_current_xid();
3415 +       vx_files_inc(f);
3416         return f;
3417  
3418  over:
3419 @@ -257,6 +261,8 @@ static void __fput(struct file *file)
3420                 i_readcount_dec(inode);
3421         if (file->f_mode & FMODE_WRITE)
3422                 drop_file_write_access(file);
3423 +       vx_files_dec(file);
3424 +       file->f_xid = 0;
3425         file->f_path.dentry = NULL;
3426         file->f_path.mnt = NULL;
3427         file_free(file);
3428 @@ -449,6 +455,8 @@ void put_filp(struct file *file)
3429  {
3430         if (atomic_long_dec_and_test(&file->f_count)) {
3431                 security_file_free(file);
3432 +               vx_files_dec(file);
3433 +               file->f_xid = 0;
3434                 file_sb_list_del(file);
3435                 file_free(file);
3436         }
3437 diff -NurpP --minimal linux-3.6/fs/fs_struct.c linux-3.6-vs2.3.4.3-noxfs-nocow/fs/fs_struct.c
3438 --- linux-3.6/fs/fs_struct.c    2012-10-04 15:27:39.000000000 +0200
3439 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/fs/fs_struct.c      2012-10-04 19:08:56.000000000 +0200
3440 @@ -4,6 +4,7 @@
3441  #include <linux/path.h>
3442  #include <linux/slab.h>
3443  #include <linux/fs_struct.h>
3444 +#include <linux/vserver/global.h>
3445  #include "internal.h"
3446  
3447  /*
3448 @@ -87,6 +88,7 @@ void free_fs_struct(struct fs_struct *fs
3449  {
3450         path_put(&fs->root);
3451         path_put(&fs->pwd);
3452 +       atomic_dec(&vs_global_fs);
3453         kmem_cache_free(fs_cachep, fs);
3454  }
3455  
3456 @@ -124,6 +126,7 @@ struct fs_struct *copy_fs_struct(struct 
3457                 fs->pwd = old->pwd;
3458                 path_get(&fs->pwd);
3459                 spin_unlock(&old->lock);
3460 +               atomic_inc(&vs_global_fs);
3461         }
3462         return fs;
3463  }
3464 diff -NurpP --minimal linux-3.6/fs/gfs2/file.c linux-3.6-vs2.3.4.3-noxfs-nocow/fs/gfs2/file.c
3465 --- linux-3.6/fs/gfs2/file.c    2012-10-04 15:27:40.000000000 +0200
3466 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/fs/gfs2/file.c      2012-10-04 19:05:34.000000000 +0200
3467 @@ -143,6 +143,9 @@ static const u32 fsflags_to_gfs2[32] = {
3468         [12] = GFS2_DIF_EXHASH,
3469         [14] = GFS2_DIF_INHERIT_JDATA,
3470         [17] = GFS2_DIF_TOPDIR,
3471 +       [27] = GFS2_DIF_IXUNLINK,
3472 +       [26] = GFS2_DIF_BARRIER,
3473 +       [29] = GFS2_DIF_COW,
3474  };
3475  
3476  static const u32 gfs2_to_fsflags[32] = {
3477 @@ -153,6 +156,9 @@ static const u32 gfs2_to_fsflags[32] = {
3478         [gfs2fl_ExHash] = FS_INDEX_FL,
3479         [gfs2fl_TopLevel] = FS_TOPDIR_FL,
3480         [gfs2fl_InheritJdata] = FS_JOURNAL_DATA_FL,
3481 +       [gfs2fl_IXUnlink] = FS_IXUNLINK_FL,
3482 +       [gfs2fl_Barrier] = FS_BARRIER_FL,
3483 +       [gfs2fl_Cow] = FS_COW_FL,
3484  };
3485  
3486  static int gfs2_get_flags(struct file *filp, u32 __user *ptr)
3487 @@ -183,12 +189,18 @@ void gfs2_set_inode_flags(struct inode *
3488  {
3489         struct gfs2_inode *ip = GFS2_I(inode);
3490         unsigned int flags = inode->i_flags;
3491 +       unsigned int vflags = inode->i_vflags;
3492 +
3493 +       flags &= ~(S_IMMUTABLE | S_IXUNLINK |
3494 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC | S_NOSEC);
3495  
3496 -       flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC|S_NOSEC);
3497         if ((ip->i_eattr == 0) && !is_sxid(inode->i_mode))
3498                 inode->i_flags |= S_NOSEC;
3499         if (ip->i_diskflags & GFS2_DIF_IMMUTABLE)
3500                 flags |= S_IMMUTABLE;
3501 +       if (ip->i_diskflags & GFS2_DIF_IXUNLINK)
3502 +               flags |= S_IXUNLINK;
3503 +
3504         if (ip->i_diskflags & GFS2_DIF_APPENDONLY)
3505                 flags |= S_APPEND;
3506         if (ip->i_diskflags & GFS2_DIF_NOATIME)
3507 @@ -196,6 +208,43 @@ void gfs2_set_inode_flags(struct inode *
3508         if (ip->i_diskflags & GFS2_DIF_SYNC)
3509                 flags |= S_SYNC;
3510         inode->i_flags = flags;
3511 +
3512 +       vflags &= ~(V_BARRIER | V_COW);
3513 +
3514 +       if (ip->i_diskflags & GFS2_DIF_BARRIER)
3515 +               vflags |= V_BARRIER;
3516 +       if (ip->i_diskflags & GFS2_DIF_COW)
3517 +               vflags |= V_COW;
3518 +       inode->i_vflags = vflags;
3519 +}
3520 +
3521 +void gfs2_get_inode_flags(struct inode *inode)
3522 +{
3523 +       struct gfs2_inode *ip = GFS2_I(inode);
3524 +       unsigned int flags = inode->i_flags;
3525 +       unsigned int vflags = inode->i_vflags;
3526 +
3527 +       ip->i_diskflags &= ~(GFS2_DIF_APPENDONLY |
3528 +                       GFS2_DIF_NOATIME | GFS2_DIF_SYNC |
3529 +                       GFS2_DIF_IMMUTABLE | GFS2_DIF_IXUNLINK |
3530 +                       GFS2_DIF_BARRIER | GFS2_DIF_COW);
3531 +
3532 +       if (flags & S_IMMUTABLE)
3533 +               ip->i_diskflags |= GFS2_DIF_IMMUTABLE;
3534 +       if (flags & S_IXUNLINK)
3535 +               ip->i_diskflags |= GFS2_DIF_IXUNLINK;
3536 +
3537 +       if (flags & S_APPEND)
3538 +               ip->i_diskflags |= GFS2_DIF_APPENDONLY;
3539 +       if (flags & S_NOATIME)
3540 +               ip->i_diskflags |= GFS2_DIF_NOATIME;
3541 +       if (flags & S_SYNC)
3542 +               ip->i_diskflags |= GFS2_DIF_SYNC;
3543 +
3544 +       if (vflags & V_BARRIER)
3545 +               ip->i_diskflags |= GFS2_DIF_BARRIER;
3546 +       if (vflags & V_COW)
3547 +               ip->i_diskflags |= GFS2_DIF_COW;
3548  }
3549  
3550  /* Flags that can be set by user space */
3551 @@ -309,6 +358,37 @@ static int gfs2_set_flags(struct file *f
3552         return do_gfs2_set_flags(filp, gfsflags, ~GFS2_DIF_JDATA);
3553  }
3554  
3555 +int gfs2_sync_flags(struct inode *inode, int flags, int vflags)
3556 +{
3557 +       struct gfs2_inode *ip = GFS2_I(inode);
3558 +       struct gfs2_sbd *sdp = GFS2_SB(inode);
3559 +       struct buffer_head *bh;
3560 +       struct gfs2_holder gh;
3561 +       int error;
3562 +
3563 +       error = gfs2_glock_nq_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &gh);
3564 +       if (error)
3565 +               return error;
3566 +       error = gfs2_trans_begin(sdp, RES_DINODE, 0);
3567 +       if (error)
3568 +               goto out;
3569 +       error = gfs2_meta_inode_buffer(ip, &bh);
3570 +       if (error)
3571 +               goto out_trans_end;
3572 +       gfs2_trans_add_bh(ip->i_gl, bh, 1);
3573 +       inode->i_flags = flags;
3574 +       inode->i_vflags = vflags;
3575 +       gfs2_get_inode_flags(inode);
3576 +       gfs2_dinode_out(ip, bh->b_data);
3577 +       brelse(bh);
3578 +       gfs2_set_aops(inode);
3579 +out_trans_end:
3580 +       gfs2_trans_end(sdp);
3581 +out:
3582 +       gfs2_glock_dq_uninit(&gh);
3583 +       return error;
3584 +}
3585 +
3586  static long gfs2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
3587  {
3588         switch(cmd) {
3589 diff -NurpP --minimal linux-3.6/fs/gfs2/inode.h linux-3.6-vs2.3.4.3-noxfs-nocow/fs/gfs2/inode.h
3590 --- linux-3.6/fs/gfs2/inode.h   2012-07-22 23:39:40.000000000 +0200
3591 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/fs/gfs2/inode.h     2012-10-04 18:47:00.000000000 +0200
3592 @@ -117,6 +117,7 @@ extern const struct file_operations gfs2
3593  extern const struct file_operations gfs2_dir_fops_nolock;
3594  
3595  extern void gfs2_set_inode_flags(struct inode *inode);
3596 +extern int gfs2_sync_flags(struct inode *inode, int flags, int vflags);
3597   
3598  #ifdef CONFIG_GFS2_FS_LOCKING_DLM
3599  extern const struct file_operations gfs2_file_fops;
3600 diff -NurpP --minimal linux-3.6/fs/inode.c linux-3.6-vs2.3.4.3-noxfs-nocow/fs/inode.c
3601 --- linux-3.6/fs/inode.c        2012-10-04 15:27:40.000000000 +0200
3602 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/fs/inode.c  2012-10-04 18:47:00.000000000 +0200
3603 @@ -17,6 +17,7 @@
3604  #include <linux/prefetch.h>
3605  #include <linux/buffer_head.h> /* for inode_has_buffers */
3606  #include <linux/ratelimit.h>
3607 +#include <linux/vs_tag.h>
3608  #include "internal.h"
3609  
3610  /*
3611 @@ -128,6 +129,9 @@ int inode_init_always(struct super_block
3612         struct address_space *const mapping = &inode->i_data;
3613  
3614         inode->i_sb = sb;
3615 +
3616 +       /* essential because of inode slab reuse */
3617 +       inode->i_tag = 0;
3618         inode->i_blkbits = sb->s_blocksize_bits;
3619         inode->i_flags = 0;
3620         atomic_set(&inode->i_count, 1);
3621 @@ -149,6 +153,7 @@ int inode_init_always(struct super_block
3622         inode->i_bdev = NULL;
3623         inode->i_cdev = NULL;
3624         inode->i_rdev = 0;
3625 +       inode->i_mdev = 0;
3626         inode->dirtied_when = 0;
3627  
3628         if (security_inode_alloc(inode))
3629 @@ -470,6 +475,8 @@ void __insert_inode_hash(struct inode *i
3630  }
3631  EXPORT_SYMBOL(__insert_inode_hash);
3632  
3633 +EXPORT_SYMBOL_GPL(__iget);
3634 +
3635  /**
3636   *     __remove_inode_hash - remove an inode from the hash
3637   *     @inode: inode to unhash
3638 @@ -1792,9 +1799,11 @@ void init_special_inode(struct inode *in
3639         if (S_ISCHR(mode)) {
3640                 inode->i_fop = &def_chr_fops;
3641                 inode->i_rdev = rdev;
3642 +               inode->i_mdev = rdev;
3643         } else if (S_ISBLK(mode)) {
3644                 inode->i_fop = &def_blk_fops;
3645                 inode->i_rdev = rdev;
3646 +               inode->i_mdev = rdev;
3647         } else if (S_ISFIFO(mode))
3648                 inode->i_fop = &def_fifo_fops;
3649         else if (S_ISSOCK(mode))
3650 @@ -1823,6 +1832,7 @@ void inode_init_owner(struct inode *inod
3651         } else
3652                 inode->i_gid = current_fsgid();
3653         inode->i_mode = mode;
3654 +       inode->i_tag = dx_current_fstag(inode->i_sb);
3655  }
3656  EXPORT_SYMBOL(inode_init_owner);
3657  
3658 diff -NurpP --minimal linux-3.6/fs/ioctl.c linux-3.6-vs2.3.4.3-noxfs-nocow/fs/ioctl.c
3659 --- linux-3.6/fs/ioctl.c        2012-05-21 18:07:24.000000000 +0200
3660 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/fs/ioctl.c  2012-10-04 18:47:00.000000000 +0200
3661 @@ -15,6 +15,9 @@
3662  #include <linux/writeback.h>
3663  #include <linux/buffer_head.h>
3664  #include <linux/falloc.h>
3665 +#include <linux/proc_fs.h>
3666 +#include <linux/vserver/inode.h>
3667 +#include <linux/vs_tag.h>
3668  
3669  #include <asm/ioctls.h>
3670  
3671 diff -NurpP --minimal linux-3.6/fs/ioprio.c linux-3.6-vs2.3.4.3-noxfs-nocow/fs/ioprio.c
3672 --- linux-3.6/fs/ioprio.c       2012-07-22 23:39:40.000000000 +0200
3673 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/fs/ioprio.c 2012-10-04 18:47:00.000000000 +0200
3674 @@ -28,6 +28,7 @@
3675  #include <linux/syscalls.h>
3676  #include <linux/security.h>
3677  #include <linux/pid_namespace.h>
3678 +#include <linux/vs_base.h>
3679  
3680  int set_task_ioprio(struct task_struct *task, int ioprio)
3681  {
3682 @@ -105,6 +106,8 @@ SYSCALL_DEFINE3(ioprio_set, int, which, 
3683                         else
3684                                 pgrp = find_vpid(who);
3685                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
3686 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
3687 +                                       continue;
3688                                 ret = set_task_ioprio(p, ioprio);
3689                                 if (ret)
3690                                         break;
3691 @@ -198,6 +201,8 @@ SYSCALL_DEFINE2(ioprio_get, int, which, 
3692                         else
3693                                 pgrp = find_vpid(who);
3694                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
3695 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
3696 +                                       continue;
3697                                 tmpio = get_task_ioprio(p);
3698                                 if (tmpio < 0)
3699                                         continue;
3700 diff -NurpP --minimal linux-3.6/fs/jfs/file.c linux-3.6-vs2.3.4.3-noxfs-nocow/fs/jfs/file.c
3701 --- linux-3.6/fs/jfs/file.c     2011-10-24 18:45:27.000000000 +0200
3702 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/fs/jfs/file.c       2012-10-04 18:47:00.000000000 +0200
3703 @@ -109,7 +109,8 @@ int jfs_setattr(struct dentry *dentry, s
3704         if (is_quota_modification(inode, iattr))
3705                 dquot_initialize(inode);
3706         if ((iattr->ia_valid & ATTR_UID && iattr->ia_uid != inode->i_uid) ||
3707 -           (iattr->ia_valid & ATTR_GID && iattr->ia_gid != inode->i_gid)) {
3708 +           (iattr->ia_valid & ATTR_GID && iattr->ia_gid != inode->i_gid) ||
3709 +           (iattr->ia_valid & ATTR_TAG && iattr->ia_tag != inode->i_tag)) {
3710                 rc = dquot_transfer(inode, iattr);
3711                 if (rc)
3712                         return rc;
3713 @@ -142,6 +143,7 @@ const struct inode_operations jfs_file_i
3714  #ifdef CONFIG_JFS_POSIX_ACL
3715         .get_acl        = jfs_get_acl,
3716  #endif
3717 +       .sync_flags     = jfs_sync_flags,
3718  };
3719  
3720  const struct file_operations jfs_file_operations = {
3721 diff -NurpP --minimal linux-3.6/fs/jfs/ioctl.c linux-3.6-vs2.3.4.3-noxfs-nocow/fs/jfs/ioctl.c
3722 --- linux-3.6/fs/jfs/ioctl.c    2012-03-19 19:47:25.000000000 +0100
3723 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/fs/jfs/ioctl.c      2012-10-04 18:47:00.000000000 +0200
3724 @@ -11,6 +11,7 @@
3725  #include <linux/mount.h>
3726  #include <linux/time.h>
3727  #include <linux/sched.h>
3728 +#include <linux/mount.h>
3729  #include <asm/current.h>
3730  #include <asm/uaccess.h>
3731  
3732 @@ -52,6 +53,16 @@ static long jfs_map_ext2(unsigned long f
3733  }
3734  
3735  
3736 +int jfs_sync_flags(struct inode *inode, int flags, int vflags)
3737 +{
3738 +       inode->i_flags = flags;
3739 +       inode->i_vflags = vflags;
3740 +       jfs_get_inode_flags(JFS_IP(inode));
3741 +       inode->i_ctime = CURRENT_TIME_SEC;
3742 +       mark_inode_dirty(inode);
3743 +       return 0;
3744 +}
3745 +
3746  long jfs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
3747  {
3748         struct inode *inode = filp->f_dentry->d_inode;
3749 @@ -85,6 +96,11 @@ long jfs_ioctl(struct file *filp, unsign
3750                 if (!S_ISDIR(inode->i_mode))
3751                         flags &= ~JFS_DIRSYNC_FL;
3752  
3753 +               if (IS_BARRIER(inode)) {
3754 +                       vxwprintk_task(1, "messing with the barrier.");
3755 +                       return -EACCES;
3756 +               }
3757 +
3758                 /* Is it quota file? Do not allow user to mess with it */
3759                 if (IS_NOQUOTA(inode)) {
3760                         err = -EPERM;
3761 @@ -102,8 +118,8 @@ long jfs_ioctl(struct file *filp, unsign
3762                  * the relevant capability.
3763                  */
3764                 if ((oldflags & JFS_IMMUTABLE_FL) ||
3765 -                       ((flags ^ oldflags) &
3766 -                       (JFS_APPEND_FL | JFS_IMMUTABLE_FL))) {
3767 +                       ((flags ^ oldflags) & (JFS_APPEND_FL |
3768 +                       JFS_IMMUTABLE_FL | JFS_IXUNLINK_FL))) {
3769                         if (!capable(CAP_LINUX_IMMUTABLE)) {
3770                                 mutex_unlock(&inode->i_mutex);
3771                                 err = -EPERM;
3772 @@ -111,7 +127,7 @@ long jfs_ioctl(struct file *filp, unsign
3773                         }
3774                 }
3775  
3776 -               flags = flags & JFS_FL_USER_MODIFIABLE;
3777 +               flags &= JFS_FL_USER_MODIFIABLE;
3778                 flags |= oldflags & ~JFS_FL_USER_MODIFIABLE;
3779                 jfs_inode->mode2 = flags;
3780  
3781 diff -NurpP --minimal linux-3.6/fs/jfs/jfs_dinode.h linux-3.6-vs2.3.4.3-noxfs-nocow/fs/jfs/jfs_dinode.h
3782 --- linux-3.6/fs/jfs/jfs_dinode.h       2008-12-25 00:26:37.000000000 +0100
3783 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/fs/jfs/jfs_dinode.h 2012-10-04 18:47:00.000000000 +0200
3784 @@ -161,9 +161,13 @@ struct dinode {
3785  
3786  #define JFS_APPEND_FL          0x01000000 /* writes to file may only append */
3787  #define JFS_IMMUTABLE_FL       0x02000000 /* Immutable file */
3788 +#define JFS_IXUNLINK_FL                0x08000000 /* Immutable invert on unlink */
3789  
3790 -#define JFS_FL_USER_VISIBLE    0x03F80000
3791 -#define JFS_FL_USER_MODIFIABLE 0x03F80000
3792 +#define JFS_BARRIER_FL         0x04000000 /* Barrier for chroot() */
3793 +#define JFS_COW_FL             0x20000000 /* Copy on Write marker */
3794 +
3795 +#define JFS_FL_USER_VISIBLE    0x07F80000
3796 +#define JFS_FL_USER_MODIFIABLE 0x07F80000
3797  #define JFS_FL_INHERIT         0x03C80000
3798  
3799  /* These are identical to EXT[23]_IOC_GETFLAGS/SETFLAGS */
3800 diff -NurpP --minimal linux-3.6/fs/jfs/jfs_filsys.h linux-3.6-vs2.3.4.3-noxfs-nocow/fs/jfs/jfs_filsys.h
3801 --- linux-3.6/fs/jfs/jfs_filsys.h       2008-12-25 00:26:37.000000000 +0100
3802 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/fs/jfs/jfs_filsys.h 2012-10-04 18:47:00.000000000 +0200
3803 @@ -263,6 +263,7 @@
3804  #define JFS_NAME_MAX   255
3805  #define JFS_PATH_MAX   BPSIZE
3806  
3807 +#define JFS_TAGGED             0x00800000      /* Context Tagging */
3808  
3809  /*
3810   *     file system state (superblock state)
3811 diff -NurpP --minimal linux-3.6/fs/jfs/jfs_imap.c linux-3.6-vs2.3.4.3-noxfs-nocow/fs/jfs/jfs_imap.c
3812 --- linux-3.6/fs/jfs/jfs_imap.c 2012-01-09 16:14:54.000000000 +0100
3813 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/fs/jfs/jfs_imap.c   2012-10-04 18:47:00.000000000 +0200
3814 @@ -46,6 +46,7 @@
3815  #include <linux/pagemap.h>
3816  #include <linux/quotaops.h>
3817  #include <linux/slab.h>
3818 +#include <linux/vs_tag.h>
3819  
3820  #include "jfs_incore.h"
3821  #include "jfs_inode.h"
3822 @@ -3058,6 +3059,8 @@ static int copy_from_dinode(struct dinod
3823  {
3824         struct jfs_inode_info *jfs_ip = JFS_IP(ip);
3825         struct jfs_sb_info *sbi = JFS_SBI(ip->i_sb);
3826 +       uid_t uid;
3827 +       gid_t gid;
3828  
3829         jfs_ip->fileset = le32_to_cpu(dip->di_fileset);
3830         jfs_ip->mode2 = le32_to_cpu(dip->di_mode);
3831 @@ -3078,14 +3081,18 @@ static int copy_from_dinode(struct dinod
3832         }
3833         set_nlink(ip, le32_to_cpu(dip->di_nlink));
3834  
3835 -       jfs_ip->saved_uid = le32_to_cpu(dip->di_uid);
3836 +       uid = le32_to_cpu(dip->di_uid);
3837 +       gid = le32_to_cpu(dip->di_gid);
3838 +       ip->i_tag = INOTAG_TAG(DX_TAG(ip), uid, gid, 0);
3839 +
3840 +       jfs_ip->saved_uid = INOTAG_UID(DX_TAG(ip), uid, gid);
3841         if (sbi->uid == -1)
3842                 ip->i_uid = jfs_ip->saved_uid;
3843         else {
3844                 ip->i_uid = sbi->uid;
3845         }
3846  
3847 -       jfs_ip->saved_gid = le32_to_cpu(dip->di_gid);
3848 +       jfs_ip->saved_gid = INOTAG_GID(DX_TAG(ip), uid, gid);
3849         if (sbi->gid == -1)
3850                 ip->i_gid = jfs_ip->saved_gid;
3851         else {
3852 @@ -3150,14 +3157,12 @@ static void copy_to_dinode(struct dinode
3853         dip->di_size = cpu_to_le64(ip->i_size);
3854         dip->di_nblocks = cpu_to_le64(PBLK2LBLK(ip->i_sb, ip->i_blocks));
3855         dip->di_nlink = cpu_to_le32(ip->i_nlink);
3856 -       if (sbi->uid == -1)
3857 -               dip->di_uid = cpu_to_le32(ip->i_uid);
3858 -       else
3859 -               dip->di_uid = cpu_to_le32(jfs_ip->saved_uid);
3860 -       if (sbi->gid == -1)
3861 -               dip->di_gid = cpu_to_le32(ip->i_gid);
3862 -       else
3863 -               dip->di_gid = cpu_to_le32(jfs_ip->saved_gid);
3864 +
3865 +       dip->di_uid = cpu_to_le32(TAGINO_UID(DX_TAG(ip),
3866 +               (sbi->uid == -1) ? ip->i_uid : jfs_ip->saved_uid, ip->i_tag));
3867 +       dip->di_gid = cpu_to_le32(TAGINO_GID(DX_TAG(ip),
3868 +               (sbi->gid == -1) ? ip->i_gid : jfs_ip->saved_gid, ip->i_tag));
3869 +
3870         jfs_get_inode_flags(jfs_ip);
3871         /*
3872          * mode2 is only needed for storing the higher order bits.
3873 diff -NurpP --minimal linux-3.6/fs/jfs/jfs_inode.c linux-3.6-vs2.3.4.3-noxfs-nocow/fs/jfs/jfs_inode.c
3874 --- linux-3.6/fs/jfs/jfs_inode.c        2012-01-09 16:14:54.000000000 +0100
3875 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/fs/jfs/jfs_inode.c  2012-10-04 18:47:00.000000000 +0200
3876 @@ -18,6 +18,7 @@
3877  
3878  #include <linux/fs.h>
3879  #include <linux/quotaops.h>
3880 +#include <linux/vs_tag.h>
3881  #include "jfs_incore.h"
3882  #include "jfs_inode.h"
3883  #include "jfs_filsys.h"
3884 @@ -30,29 +31,46 @@ void jfs_set_inode_flags(struct inode *i
3885  {
3886         unsigned int flags = JFS_IP(inode)->mode2;
3887  
3888 -       inode->i_flags &= ~(S_IMMUTABLE | S_APPEND |
3889 -               S_NOATIME | S_DIRSYNC | S_SYNC);
3890 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
3891 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
3892  
3893         if (flags & JFS_IMMUTABLE_FL)
3894                 inode->i_flags |= S_IMMUTABLE;
3895 +       if (flags & JFS_IXUNLINK_FL)
3896 +               inode->i_flags |= S_IXUNLINK;
3897 +
3898 +       if (flags & JFS_SYNC_FL)
3899 +               inode->i_flags |= S_SYNC;
3900         if (flags & JFS_APPEND_FL)
3901                 inode->i_flags |= S_APPEND;
3902         if (flags & JFS_NOATIME_FL)
3903                 inode->i_flags |= S_NOATIME;
3904         if (flags & JFS_DIRSYNC_FL)
3905                 inode->i_flags |= S_DIRSYNC;
3906 -       if (flags & JFS_SYNC_FL)
3907 -               inode->i_flags |= S_SYNC;
3908 +
3909 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
3910 +
3911 +       if (flags & JFS_BARRIER_FL)
3912 +               inode->i_vflags |= V_BARRIER;
3913 +       if (flags & JFS_COW_FL)
3914 +               inode->i_vflags |= V_COW;
3915  }
3916  
3917  void jfs_get_inode_flags(struct jfs_inode_info *jfs_ip)
3918  {
3919         unsigned int flags = jfs_ip->vfs_inode.i_flags;
3920 +       unsigned int vflags = jfs_ip->vfs_inode.i_vflags;
3921 +
3922 +       jfs_ip->mode2 &= ~(JFS_IMMUTABLE_FL | JFS_IXUNLINK_FL |
3923 +                          JFS_APPEND_FL | JFS_NOATIME_FL |
3924 +                          JFS_DIRSYNC_FL | JFS_SYNC_FL |
3925 +                          JFS_BARRIER_FL | JFS_COW_FL);
3926  
3927 -       jfs_ip->mode2 &= ~(JFS_IMMUTABLE_FL | JFS_APPEND_FL | JFS_NOATIME_FL |
3928 -                          JFS_DIRSYNC_FL | JFS_SYNC_FL);
3929         if (flags & S_IMMUTABLE)
3930                 jfs_ip->mode2 |= JFS_IMMUTABLE_FL;
3931 +       if (flags & S_IXUNLINK)
3932 +               jfs_ip->mode2 |= JFS_IXUNLINK_FL;
3933 +
3934         if (flags & S_APPEND)
3935                 jfs_ip->mode2 |= JFS_APPEND_FL;
3936         if (flags & S_NOATIME)
3937 @@ -61,6 +79,11 @@ void jfs_get_inode_flags(struct jfs_inod
3938                 jfs_ip->mode2 |= JFS_DIRSYNC_FL;
3939         if (flags & S_SYNC)
3940                 jfs_ip->mode2 |= JFS_SYNC_FL;
3941 +
3942 +       if (vflags & V_BARRIER)
3943 +               jfs_ip->mode2 |= JFS_BARRIER_FL;
3944 +       if (vflags & V_COW)
3945 +               jfs_ip->mode2 |= JFS_COW_FL;
3946  }
3947  
3948  /*
3949 diff -NurpP --minimal linux-3.6/fs/jfs/jfs_inode.h linux-3.6-vs2.3.4.3-noxfs-nocow/fs/jfs/jfs_inode.h
3950 --- linux-3.6/fs/jfs/jfs_inode.h        2011-10-24 18:45:27.000000000 +0200
3951 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/fs/jfs/jfs_inode.h  2012-10-04 18:47:00.000000000 +0200
3952 @@ -39,6 +39,7 @@ extern struct dentry *jfs_fh_to_dentry(s
3953  extern struct dentry *jfs_fh_to_parent(struct super_block *sb, struct fid *fid,
3954         int fh_len, int fh_type);
3955  extern void jfs_set_inode_flags(struct inode *);
3956 +extern int jfs_sync_flags(struct inode *, int, int);
3957  extern int jfs_get_block(struct inode *, sector_t, struct buffer_head *, int);
3958  extern int jfs_setattr(struct dentry *, struct iattr *);
3959  
3960 diff -NurpP --minimal linux-3.6/fs/jfs/namei.c linux-3.6-vs2.3.4.3-noxfs-nocow/fs/jfs/namei.c
3961 --- linux-3.6/fs/jfs/namei.c    2012-10-04 15:27:40.000000000 +0200
3962 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/fs/jfs/namei.c      2012-10-04 18:47:00.000000000 +0200
3963 @@ -22,6 +22,7 @@
3964  #include <linux/ctype.h>
3965  #include <linux/quotaops.h>
3966  #include <linux/exportfs.h>
3967 +#include <linux/vs_tag.h>
3968  #include "jfs_incore.h"
3969  #include "jfs_superblock.h"
3970  #include "jfs_inode.h"
3971 @@ -1461,6 +1462,7 @@ static struct dentry *jfs_lookup(struct 
3972                         jfs_err("jfs_lookup: iget failed on inum %d", (uint)inum);
3973         }
3974  
3975 +       dx_propagate_tag(nd, ip);
3976         return d_splice_alias(ip, dentry);
3977  }
3978  
3979 @@ -1525,6 +1527,7 @@ const struct inode_operations jfs_dir_in
3980  #ifdef CONFIG_JFS_POSIX_ACL
3981         .get_acl        = jfs_get_acl,
3982  #endif
3983 +       .sync_flags     = jfs_sync_flags,
3984  };
3985  
3986  const struct file_operations jfs_dir_operations = {
3987 diff -NurpP --minimal linux-3.6/fs/jfs/super.c linux-3.6-vs2.3.4.3-noxfs-nocow/fs/jfs/super.c
3988 --- linux-3.6/fs/jfs/super.c    2012-10-04 15:27:40.000000000 +0200
3989 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/fs/jfs/super.c      2012-10-04 18:47:00.000000000 +0200
3990 @@ -197,7 +197,8 @@ static void jfs_put_super(struct super_b
3991  enum {
3992         Opt_integrity, Opt_nointegrity, Opt_iocharset, Opt_resize,
3993         Opt_resize_nosize, Opt_errors, Opt_ignore, Opt_err, Opt_quota,
3994 -       Opt_usrquota, Opt_grpquota, Opt_uid, Opt_gid, Opt_umask
3995 +       Opt_usrquota, Opt_grpquota, Opt_uid, Opt_gid, Opt_umask,
3996 +       Opt_tag, Opt_notag, Opt_tagid
3997  };
3998  
3999  static const match_table_t tokens = {
4000 @@ -207,6 +208,10 @@ static const match_table_t tokens = {
4001         {Opt_resize, "resize=%u"},
4002         {Opt_resize_nosize, "resize"},
4003         {Opt_errors, "errors=%s"},
4004 +       {Opt_tag, "tag"},
4005 +       {Opt_notag, "notag"},
4006 +       {Opt_tagid, "tagid=%u"},
4007 +       {Opt_tag, "tagxid"},
4008         {Opt_ignore, "noquota"},
4009         {Opt_ignore, "quota"},
4010         {Opt_usrquota, "usrquota"},
4011 @@ -341,6 +346,20 @@ static int parse_options(char *options, 
4012                         }
4013                         break;
4014                 }
4015 +#ifndef CONFIG_TAGGING_NONE
4016 +               case Opt_tag:
4017 +                       *flag |= JFS_TAGGED;
4018 +                       break;
4019 +               case Opt_notag:
4020 +                       *flag &= JFS_TAGGED;
4021 +                       break;
4022 +#endif
4023 +#ifdef CONFIG_PROPAGATE
4024 +               case Opt_tagid:
4025 +                       /* use args[0] */
4026 +                       *flag |= JFS_TAGGED;
4027 +                       break;
4028 +#endif
4029                 default:
4030                         printk("jfs: Unrecognized mount option \"%s\" "
4031                                         " or missing value\n", p);
4032 @@ -372,6 +391,12 @@ static int jfs_remount(struct super_bloc
4033                 return -EINVAL;
4034         }
4035  
4036 +       if ((flag & JFS_TAGGED) && !(sb->s_flags & MS_TAGGED)) {
4037 +               printk(KERN_ERR "JFS: %s: tagging not permitted on remount.\n",
4038 +                       sb->s_id);
4039 +               return -EINVAL;
4040 +       }
4041 +
4042         if (newLVSize) {
4043                 if (sb->s_flags & MS_RDONLY) {
4044                         printk(KERN_ERR
4045 @@ -455,6 +480,9 @@ static int jfs_fill_super(struct super_b
4046  #ifdef CONFIG_JFS_POSIX_ACL
4047         sb->s_flags |= MS_POSIXACL;
4048  #endif
4049 +       /* map mount option tagxid */
4050 +       if (sbi->flag & JFS_TAGGED)
4051 +               sb->s_flags |= MS_TAGGED;
4052  
4053         if (newLVSize) {
4054                 printk(KERN_ERR "resize option for remount only\n");
4055 diff -NurpP --minimal linux-3.6/fs/libfs.c linux-3.6-vs2.3.4.3-noxfs-nocow/fs/libfs.c
4056 --- linux-3.6/fs/libfs.c        2012-10-04 15:27:40.000000000 +0200
4057 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/fs/libfs.c  2012-10-04 18:47:00.000000000 +0200
4058 @@ -135,7 +135,8 @@ static inline unsigned char dt_type(stru
4059   * both impossible due to the lock on directory.
4060   */
4061  
4062 -int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
4063 +static inline int do_dcache_readdir_filter(struct file *filp,
4064 +       void *dirent, filldir_t filldir, int (*filter)(struct dentry *dentry))
4065  {
4066         struct dentry *dentry = filp->f_path.dentry;
4067         struct dentry *cursor = filp->private_data;
4068 @@ -166,6 +167,8 @@ int dcache_readdir(struct file * filp, v
4069                         for (p=q->next; p != &dentry->d_subdirs; p=p->next) {
4070                                 struct dentry *next;
4071                                 next = list_entry(p, struct dentry, d_u.d_child);
4072 +                               if (filter && !filter(next))
4073 +                                       continue;
4074                                 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
4075                                 if (!simple_positive(next)) {
4076                                         spin_unlock(&next->d_lock);
4077 @@ -192,6 +195,17 @@ int dcache_readdir(struct file * filp, v
4078         return 0;
4079  }
4080  
4081 +int dcache_readdir(struct file *filp, void *dirent, filldir_t filldir)
4082 +{
4083 +       return do_dcache_readdir_filter(filp, dirent, filldir, NULL);
4084 +}
4085 +
4086 +int dcache_readdir_filter(struct file *filp, void *dirent, filldir_t filldir,
4087 +       int (*filter)(struct dentry *))
4088 +{
4089 +       return do_dcache_readdir_filter(filp, dirent, filldir, filter);
4090 +}
4091 +
4092  ssize_t generic_read_dir(struct file *filp, char __user *buf, size_t siz, loff_t *ppos)
4093  {
4094         return -EISDIR;
4095 @@ -983,6 +997,7 @@ EXPORT_SYMBOL(dcache_dir_close);
4096  EXPORT_SYMBOL(dcache_dir_lseek);
4097  EXPORT_SYMBOL(dcache_dir_open);
4098  EXPORT_SYMBOL(dcache_readdir);
4099 +EXPORT_SYMBOL(dcache_readdir_filter);
4100  EXPORT_SYMBOL(generic_read_dir);
4101  EXPORT_SYMBOL(mount_pseudo);
4102  EXPORT_SYMBOL(simple_write_begin);
4103 diff -NurpP --minimal linux-3.6/fs/locks.c linux-3.6-vs2.3.4.3-noxfs-nocow/fs/locks.c
4104 --- linux-3.6/fs/locks.c        2012-10-04 15:27:40.000000000 +0200
4105 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/fs/locks.c  2012-10-04 18:47:00.000000000 +0200
4106 @@ -126,6 +126,8 @@
4107  #include <linux/time.h>
4108  #include <linux/rcupdate.h>
4109  #include <linux/pid_namespace.h>
4110 +#include <linux/vs_base.h>
4111 +#include <linux/vs_limit.h>
4112  
4113  #include <asm/uaccess.h>
4114  
4115 @@ -184,11 +186,17 @@ static void locks_init_lock_heads(struct
4116  /* Allocate an empty lock structure. */
4117  struct file_lock *locks_alloc_lock(void)
4118  {
4119 -       struct file_lock *fl = kmem_cache_zalloc(filelock_cache, GFP_KERNEL);
4120 +       struct file_lock *fl;
4121  
4122 -       if (fl)
4123 -               locks_init_lock_heads(fl);
4124 +       if (!vx_locks_avail(1))
4125 +               return NULL;
4126  
4127 +       fl = kmem_cache_zalloc(filelock_cache, GFP_KERNEL);
4128 +
4129 +       if (fl) {
4130 +               locks_init_lock_heads(fl);
4131 +               fl->fl_xid = -1;
4132 +       }
4133         return fl;
4134  }
4135  EXPORT_SYMBOL_GPL(locks_alloc_lock);
4136 @@ -212,6 +220,7 @@ void locks_free_lock(struct file_lock *f
4137         BUG_ON(!list_empty(&fl->fl_block));
4138         BUG_ON(!list_empty(&fl->fl_link));
4139  
4140 +       vx_locks_dec(fl);
4141         locks_release_private(fl);
4142         kmem_cache_free(filelock_cache, fl);
4143  }
4144 @@ -221,6 +230,7 @@ void locks_init_lock(struct file_lock *f
4145  {
4146         memset(fl, 0, sizeof(struct file_lock));
4147         locks_init_lock_heads(fl);
4148 +       fl->fl_xid = -1;
4149  }
4150  
4151  EXPORT_SYMBOL(locks_init_lock);
4152 @@ -261,6 +271,7 @@ void locks_copy_lock(struct file_lock *n
4153         new->fl_file = fl->fl_file;
4154         new->fl_ops = fl->fl_ops;
4155         new->fl_lmops = fl->fl_lmops;
4156 +       new->fl_xid = fl->fl_xid;
4157  
4158         locks_copy_private(new, fl);
4159  }
4160 @@ -299,6 +310,11 @@ static int flock_make_lock(struct file *
4161         fl->fl_flags = FL_FLOCK;
4162         fl->fl_type = type;
4163         fl->fl_end = OFFSET_MAX;
4164 +
4165 +       vxd_assert(filp->f_xid == vx_current_xid(),
4166 +               "f_xid(%d) == current(%d)", filp->f_xid, vx_current_xid());
4167 +       fl->fl_xid = filp->f_xid;
4168 +       vx_locks_inc(fl);
4169         
4170         *lock = fl;
4171         return 0;
4172 @@ -438,6 +454,7 @@ static int lease_init(struct file *filp,
4173  
4174         fl->fl_owner = current->files;
4175         fl->fl_pid = current->tgid;
4176 +       fl->fl_xid = vx_current_xid();
4177  
4178         fl->fl_file = filp;
4179         fl->fl_flags = FL_LEASE;
4180 @@ -457,6 +474,11 @@ static struct file_lock *lease_alloc(str
4181         if (fl == NULL)
4182                 return ERR_PTR(error);
4183  
4184 +       fl->fl_xid = vx_current_xid();
4185 +       if (filp)
4186 +               vxd_assert(filp->f_xid == fl->fl_xid,
4187 +                       "f_xid(%d) == fl_xid(%d)", filp->f_xid, fl->fl_xid);
4188 +       vx_locks_inc(fl);
4189         error = lease_init(filp, type, fl);
4190         if (error) {
4191                 locks_free_lock(fl);
4192 @@ -753,6 +775,7 @@ static int flock_lock_file(struct file *
4193                 lock_flocks();
4194         }
4195  
4196 +       new_fl->fl_xid = -1;
4197  find_conflict:
4198         for_each_lock(inode, before) {
4199                 struct file_lock *fl = *before;
4200 @@ -773,6 +796,7 @@ find_conflict:
4201                 goto out;
4202         locks_copy_lock(new_fl, request);
4203         locks_insert_lock(before, new_fl);
4204 +       vx_locks_inc(new_fl);
4205         new_fl = NULL;
4206         error = 0;
4207  
4208 @@ -783,7 +807,8 @@ out:
4209         return error;
4210  }
4211  
4212 -static int __posix_lock_file(struct inode *inode, struct file_lock *request, struct file_lock *conflock)
4213 +static int __posix_lock_file(struct inode *inode, struct file_lock *request,
4214 +       struct file_lock *conflock, xid_t xid)
4215  {
4216         struct file_lock *fl;
4217         struct file_lock *new_fl = NULL;
4218 @@ -793,6 +818,8 @@ static int __posix_lock_file(struct inod
4219         struct file_lock **before;
4220         int error, added = 0;
4221  
4222 +       vxd_assert(xid == vx_current_xid(),
4223 +               "xid(%d) == current(%d)", xid, vx_current_xid());
4224         /*
4225          * We may need two file_lock structures for this operation,
4226          * so we get them in advance to avoid races.
4227 @@ -803,7 +830,11 @@ static int __posix_lock_file(struct inod
4228             (request->fl_type != F_UNLCK ||
4229              request->fl_start != 0 || request->fl_end != OFFSET_MAX)) {
4230                 new_fl = locks_alloc_lock();
4231 +               new_fl->fl_xid = xid;
4232 +               vx_locks_inc(new_fl);
4233                 new_fl2 = locks_alloc_lock();
4234 +               new_fl2->fl_xid = xid;
4235 +               vx_locks_inc(new_fl2);
4236         }
4237  
4238         lock_flocks();
4239 @@ -1002,7 +1033,8 @@ static int __posix_lock_file(struct inod
4240  int posix_lock_file(struct file *filp, struct file_lock *fl,
4241                         struct file_lock *conflock)
4242  {
4243 -       return __posix_lock_file(filp->f_path.dentry->d_inode, fl, conflock);
4244 +       return __posix_lock_file(filp->f_path.dentry->d_inode,
4245 +               fl, conflock, filp->f_xid);
4246  }
4247  EXPORT_SYMBOL(posix_lock_file);
4248  
4249 @@ -1092,7 +1124,7 @@ int locks_mandatory_area(int read_write,
4250         fl.fl_end = offset + count - 1;
4251  
4252         for (;;) {
4253 -               error = __posix_lock_file(inode, &fl, NULL);
4254 +               error = __posix_lock_file(inode, &fl, NULL, filp->f_xid);
4255                 if (error != FILE_LOCK_DEFERRED)
4256                         break;
4257                 error = wait_event_interruptible(fl.fl_wait, !fl.fl_next);
4258 @@ -1397,6 +1429,7 @@ int generic_add_lease(struct file *filp,
4259                 goto out;
4260  
4261         locks_insert_lock(before, lease);
4262 +       vx_locks_inc(lease);
4263         return 0;
4264  
4265  out:
4266 @@ -1838,6 +1871,11 @@ int fcntl_setlk(unsigned int fd, struct 
4267         if (file_lock == NULL)
4268                 return -ENOLCK;
4269  
4270 +       vxd_assert(filp->f_xid == vx_current_xid(),
4271 +               "f_xid(%d) == current(%d)", filp->f_xid, vx_current_xid());
4272 +       file_lock->fl_xid = filp->f_xid;
4273 +       vx_locks_inc(file_lock);
4274 +
4275         /*
4276          * This might block, so we do it before checking the inode.
4277          */
4278 @@ -1956,6 +1994,11 @@ int fcntl_setlk64(unsigned int fd, struc
4279         if (file_lock == NULL)
4280                 return -ENOLCK;
4281  
4282 +       vxd_assert(filp->f_xid == vx_current_xid(),
4283 +               "f_xid(%d) == current(%d)", filp->f_xid, vx_current_xid());
4284 +       file_lock->fl_xid = filp->f_xid;
4285 +       vx_locks_inc(file_lock);
4286 +
4287         /*
4288          * This might block, so we do it before checking the inode.
4289          */
4290 @@ -2221,8 +2264,11 @@ static int locks_show(struct seq_file *f
4291  
4292         lock_get_status(f, fl, *((loff_t *)f->private), "");
4293  
4294 -       list_for_each_entry(bfl, &fl->fl_block, fl_block)
4295 +       list_for_each_entry(bfl, &fl->fl_block, fl_block) {
4296 +               if (!vx_check(fl->fl_xid, VS_WATCH_P | VS_IDENT))
4297 +                       continue;
4298                 lock_get_status(f, bfl, *((loff_t *)f->private), " ->");
4299 +       }
4300  
4301         return 0;
4302  }
4303 diff -NurpP --minimal linux-3.6/fs/mount.h linux-3.6-vs2.3.4.3-noxfs-nocow/fs/mount.h
4304 --- linux-3.6/fs/mount.h        2012-10-04 15:27:40.000000000 +0200
4305 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/fs/mount.h  2012-10-04 18:47:00.000000000 +0200
4306 @@ -46,6 +46,7 @@ struct mount {
4307         int mnt_expiry_mark;            /* true if marked for expiry */
4308         int mnt_pinned;
4309         int mnt_ghosts;
4310 +       tag_t mnt_tag;                  /* tagging used for vfsmount */
4311  };
4312  
4313  #define MNT_NS_INTERNAL ERR_PTR(-EINVAL) /* distinct from any mnt_namespace */
4314 diff -NurpP --minimal linux-3.6/fs/namei.c linux-3.6-vs2.3.4.3-noxfs-nocow/fs/namei.c
4315 --- linux-3.6/fs/namei.c        2012-10-04 15:27:40.000000000 +0200
4316 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/fs/namei.c  2012-10-04 19:08:15.000000000 +0200
4317 @@ -34,6 +34,14 @@
4318  #include <linux/device_cgroup.h>
4319  #include <linux/fs_struct.h>
4320  #include <linux/posix_acl.h>
4321 +#include <linux/proc_fs.h>
4322 +#include <linux/vserver/inode.h>
4323 +#include <linux/vs_base.h>
4324 +#include <linux/vs_tag.h>
4325 +#include <linux/vs_cowbl.h>
4326 +#include <linux/vs_device.h>
4327 +#include <linux/vs_context.h>
4328 +#include <linux/pid_namespace.h>
4329  #include <asm/uaccess.h>
4330  
4331  #include "internal.h"
4332 @@ -212,6 +220,89 @@ static int check_acl(struct inode *inode
4333         return -EAGAIN;
4334  }
4335  
4336 +static inline int dx_barrier(const struct inode *inode)
4337 +{
4338 +       if (IS_BARRIER(inode) && !vx_check(0, VS_ADMIN | VS_WATCH)) {
4339 +               vxwprintk_task(1, "did hit the barrier.");
4340 +               return 1;
4341 +       }
4342 +       return 0;
4343 +}
4344 +
4345 +static int __dx_permission(const struct inode *inode, int mask)
4346 +{
4347 +       if (dx_barrier(inode))
4348 +               return -EACCES;
4349 +
4350 +       if (inode->i_sb->s_magic == DEVPTS_SUPER_MAGIC) {
4351 +               /* devpts is xid tagged */
4352 +               if (S_ISDIR(inode->i_mode) ||
4353 +                   vx_check((xid_t)inode->i_tag, VS_IDENT | VS_WATCH_P))
4354 +                       return 0;
4355 +
4356 +               /* just pretend we didn't find anything */
4357 +               return -ENOENT;
4358 +       }
4359 +       else if (inode->i_sb->s_magic == PROC_SUPER_MAGIC) {
4360 +               struct proc_dir_entry *de = PDE(inode);
4361 +
4362 +               if (de && !vx_hide_check(0, de->vx_flags))
4363 +                       goto out;
4364 +
4365 +               if ((mask & (MAY_WRITE | MAY_APPEND))) {
4366 +                       struct pid *pid;
4367 +                       struct task_struct *tsk;
4368 +
4369 +                       if (vx_check(0, VS_ADMIN | VS_WATCH_P) ||
4370 +                           vx_flags(VXF_STATE_SETUP, 0))
4371 +                               return 0;
4372 +
4373 +                       pid = PROC_I(inode)->pid;
4374 +                       if (!pid)
4375 +                               goto out;
4376 +
4377 +                       rcu_read_lock();
4378 +                       tsk = pid_task(pid, PIDTYPE_PID);
4379 +                       vxdprintk(VXD_CBIT(tag, 0), "accessing %p[#%u]",
4380 +                                 tsk, (tsk ? vx_task_xid(tsk) : 0));
4381 +                       if (tsk &&
4382 +                               vx_check(vx_task_xid(tsk), VS_IDENT | VS_WATCH_P)) {
4383 +                               rcu_read_unlock();
4384 +                               return 0;
4385 +                       }
4386 +                       rcu_read_unlock();
4387 +               }
4388 +               else {
4389 +                       /* FIXME: Should we block some entries here? */
4390 +                       return 0;
4391 +               }
4392 +       }
4393 +       else {
4394 +               if (dx_notagcheck(inode->i_sb) ||
4395 +                   dx_check(inode->i_tag, DX_HOSTID | DX_ADMIN | DX_WATCH |
4396 +                            DX_IDENT))
4397 +                       return 0;
4398 +       }
4399 +
4400 +out:
4401 +       return -EACCES;
4402 +}
4403 +
4404 +int dx_permission(const struct inode *inode, int mask)
4405 +{
4406 +       int ret = __dx_permission(inode, mask);
4407 +       if (unlikely(ret)) {
4408 +#ifndef        CONFIG_VSERVER_WARN_DEVPTS
4409 +               if (inode->i_sb->s_magic != DEVPTS_SUPER_MAGIC)
4410 +#endif
4411 +                   vxwprintk_task(1,
4412 +                       "denied [0x%x] access to inode %s:%p[#%d,%lu]",
4413 +                       mask, inode->i_sb->s_id, inode, inode->i_tag,
4414 +                       inode->i_ino);
4415 +       }
4416 +       return ret;
4417 +}
4418 +
4419  /*
4420   * This does the basic permission checking
4421   */
4422 @@ -334,10 +425,14 @@ int __inode_permission(struct inode *ino
4423                 /*
4424                  * Nobody gets write access to an immutable file.
4425                  */
4426 -               if (IS_IMMUTABLE(inode))
4427 +               if (IS_IMMUTABLE(inode) && !IS_COW(inode))
4428                         return -EACCES;
4429         }
4430  
4431 +       retval = dx_permission(inode, mask);
4432 +       if (retval)
4433 +               return retval;
4434 +
4435         retval = do_inode_permission(inode, mask);
4436         if (retval)
4437                 return retval;
4438 @@ -1189,7 +1284,8 @@ static void follow_dotdot(struct nameida
4439  
4440                 if (nd->path.dentry == nd->root.dentry &&
4441                     nd->path.mnt == nd->root.mnt) {
4442 -                       break;
4443 +                       /* for sane '/' avoid follow_mount() */
4444 +                       return;
4445                 }
4446                 if (nd->path.dentry != nd->path.mnt->mnt_root) {
4447                         /* rare case of legitimate dget_parent()... */
4448 @@ -1338,6 +1434,9 @@ static int lookup_fast(struct nameidata 
4449                                 goto unlazy;
4450                         }
4451                 }
4452 +
4453 +               /* FIXME: check dx permission */
4454 +
4455                 path->mnt = mnt;
4456                 path->dentry = dentry;
4457                 if (unlikely(!__follow_mount_rcu(nd, path, inode)))
4458 @@ -1373,6 +1472,8 @@ unlazy:
4459                 }
4460         }
4461  
4462 +       /* FIXME: check dx permission */
4463 +
4464         path->mnt = mnt;
4465         path->dentry = dentry;
4466         err = follow_managed(path, nd->flags);
4467 @@ -2192,7 +2293,7 @@ static int may_delete(struct inode *dir,
4468         if (IS_APPEND(dir))
4469                 return -EPERM;
4470         if (check_sticky(dir, victim->d_inode)||IS_APPEND(victim->d_inode)||
4471 -           IS_IMMUTABLE(victim->d_inode) || IS_SWAPFILE(victim->d_inode))
4472 +               IS_IXORUNLINK(victim->d_inode) || IS_SWAPFILE(victim->d_inode))
4473                 return -EPERM;
4474         if (isdir) {
4475                 if (!S_ISDIR(victim->d_inode->i_mode))
4476 @@ -2271,19 +2372,25 @@ int vfs_create(struct inode *dir, struct
4477                 bool want_excl)
4478  {
4479         int error = may_create(dir, dentry);
4480 -       if (error)
4481 -               return error;
4482 +       if (error) {
4483 +               vxdprintk(VXD_CBIT(misc, 3), "may_create failed with %d", error);
4484 +               return error;
4485 +       }
4486  
4487         if (!dir->i_op->create)
4488                 return -EACCES; /* shouldn't it be ENOSYS? */
4489         mode &= S_IALLUGO;
4490         mode |= S_IFREG;
4491         error = security_inode_create(dir, dentry, mode);
4492 -       if (error)
4493 -               return error;
4494 +       if (error) {
4495 +               vxdprintk(VXD_CBIT(misc, 3), "security_inode_create failed with %d", error);
4496 +               return error;
4497 +       }
4498         error = dir->i_op->create(dir, dentry, mode, want_excl);
4499         if (!error)
4500                 fsnotify_create(dir, dentry);
4501 +       else
4502 +               vxdprintk(VXD_CBIT(misc, 3), "i_op->create failed with %d", error);
4503         return error;
4504  }
4505  
4506 @@ -2318,6 +2425,15 @@ static int may_open(struct path *path, i
4507                 break;
4508         }
4509  
4510 +#ifdef CONFIG_VSERVER_COWBL
4511 +       if (IS_COW(inode) &&
4512 +               ((flag & O_ACCMODE) != O_RDONLY)) {
4513 +               if (IS_COW_LINK(inode))
4514 +                       return -EMLINK;
4515 +               inode->i_flags &= ~(S_IXUNLINK|S_IMMUTABLE);
4516 +               mark_inode_dirty(inode);
4517 +       }
4518 +#endif
4519         error = inode_permission(inode, acc_mode);
4520         if (error)
4521                 return error;
4522 @@ -2820,6 +2936,16 @@ finish_open:
4523         }
4524  finish_open_created:
4525         error = may_open(&nd->path, acc_mode, open_flag);
4526 +#ifdef CONFIG_VSERVER_COWBL
4527 +       if (error == -EMLINK) {
4528 +               struct dentry *dentry;
4529 +               dentry = cow_break_link(pathname);
4530 +               if (IS_ERR(dentry))
4531 +                       error = PTR_ERR(dentry);
4532 +               else
4533 +                       dput(dentry);
4534 +       }
4535 +#endif
4536         if (error)
4537                 goto out;
4538         file->f_path.mnt = nd->path.mnt;
4539 @@ -2884,6 +3010,7 @@ static struct file *path_openat(int dfd,
4540         int opened = 0;
4541         int error;
4542  
4543 +restart:
4544         file = get_empty_filp();
4545         if (!file)
4546                 return ERR_PTR(-ENFILE);
4547 @@ -2920,6 +3047,17 @@ static struct file *path_openat(int dfd,
4548                 error = do_last(nd, &path, file, op, &opened, pathname);
4549                 put_link(nd, &link, cookie);
4550         }
4551 +
4552 +#ifdef CONFIG_VSERVER_COWBL
4553 +       if (filp == ERR_PTR(-EMLINK)) {
4554 +               if (nd->root.mnt && !(nd->flags & LOOKUP_ROOT))
4555 +                       path_put(&nd->root);
4556 +               if (base)
4557 +                       fput(base);
4558 +               release_open_intent(nd);
4559 +               goto restart;
4560 +       }
4561 +#endif
4562  out:
4563         if (nd->root.mnt && !(nd->flags & LOOKUP_ROOT))
4564                 path_put(&nd->root);
4565 @@ -3023,6 +3161,11 @@ struct dentry *kern_path_create(int dfd,
4566                 goto fail;
4567         }
4568         *path = nd.path;
4569 +       vxdprintk(VXD_CBIT(misc, 3), "kern_path_create path.dentry = %p (%.*s), dentry = %p (%.*s), d_inode = %p",
4570 +               path->dentry, path->dentry->d_name.len,
4571 +               path->dentry->d_name.name, dentry,
4572 +               dentry->d_name.len, dentry->d_name.name,
4573 +               path->dentry->d_inode);
4574         return dentry;
4575  fail:
4576         dput(dentry);
4577 @@ -3489,7 +3632,7 @@ int vfs_link(struct dentry *old_dentry, 
4578         /*
4579          * A link to an append-only or immutable file cannot be created.
4580          */
4581 -       if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
4582 +       if (IS_APPEND(inode) || IS_IXORUNLINK(inode))
4583                 return -EPERM;
4584         if (!dir->i_op->link)
4585                 return -EPERM;
4586 @@ -3874,6 +4017,253 @@ int vfs_follow_link(struct nameidata *nd
4587         return __vfs_follow_link(nd, link);
4588  }
4589  
4590 +
4591 +#ifdef CONFIG_VSERVER_COWBL
4592 +
4593 +static inline
4594 +long do_cow_splice(struct file *in, struct file *out, size_t len)
4595 +{
4596 +       loff_t ppos = 0;
4597 +
4598 +       return do_splice_direct(in, &ppos, out, len, 0);
4599 +}
4600 +
4601 +extern unsigned int mnt_get_count(struct mount *mnt);
4602 +
4603 +struct dentry *cow_break_link(const char *pathname)
4604 +{
4605 +       int ret, mode, pathlen, redo = 0;
4606 +       struct nameidata old_nd, dir_nd;
4607 +       struct path old_path, dir_path;
4608 +       struct dentry *dir, *old_dentry, *new_dentry = NULL;
4609 +       struct file *old_file;
4610 +       struct file *new_file;
4611 +       char *to, *path, pad='\251';
4612 +       loff_t size;
4613 +
4614 +       vxdprintk(VXD_CBIT(misc, 1),
4615 +               "cow_break_link(" VS_Q("%s") ")", pathname);
4616 +       path = kmalloc(PATH_MAX, GFP_KERNEL);
4617 +       ret = -ENOMEM;
4618 +       if (!path)
4619 +               goto out;
4620 +
4621 +       /* old_nd will have refs to dentry and mnt */
4622 +       ret = do_path_lookup(AT_FDCWD, pathname, LOOKUP_FOLLOW, &old_nd);
4623 +       vxdprintk(VXD_CBIT(misc, 2),
4624 +               "do_path_lookup(old): %d [r=%d]",
4625 +               ret, mnt_get_count(real_mount(old_nd.path.mnt)));
4626 +       if (ret < 0)
4627 +               goto out_free_path;
4628 +
4629 +       old_path = old_nd.path;
4630 +       old_dentry = old_path.dentry;
4631 +       mode = old_dentry->d_inode->i_mode;
4632 +
4633 +       to = d_path(&old_path, path, PATH_MAX-2);
4634 +       pathlen = strlen(to);
4635 +       vxdprintk(VXD_CBIT(misc, 2),
4636 +               "old path " VS_Q("%s") " [%p:" VS_Q("%.*s") ":%d]", to,
4637 +               old_dentry,
4638 +               old_dentry->d_name.len, old_dentry->d_name.name,
4639 +               old_dentry->d_name.len);
4640 +
4641 +       to[pathlen + 1] = 0;
4642 +retry:
4643 +       new_dentry = NULL;
4644 +       to[pathlen] = pad--;
4645 +       ret = -ELOOP;
4646 +       if (pad <= '\240')
4647 +               goto out_rel_old;
4648 +
4649 +       vxdprintk(VXD_CBIT(misc, 1), "temp copy " VS_Q("%s"), to);
4650 +       /* dir_nd will have refs to dentry and mnt */
4651 +       ret = do_path_lookup(AT_FDCWD, to,
4652 +               LOOKUP_PARENT | LOOKUP_OPEN | LOOKUP_CREATE, &dir_nd);
4653 +       vxdprintk(VXD_CBIT(misc, 2), "do_path_lookup(new): %d", ret);
4654 +       if (ret < 0)
4655 +               goto retry;
4656 +
4657 +       /* this puppy downs the dir inode mutex if successful */
4658 +       new_dentry = kern_path_create(AT_FDCWD, to, &dir_path, 0);
4659 +       if (!new_dentry || IS_ERR(new_dentry)) {
4660 +               path_put(&dir_nd.path);
4661 +               vxdprintk(VXD_CBIT(misc, 2),
4662 +                       "kern_path_create(new) failed with %ld",
4663 +                       PTR_ERR(new_dentry));
4664 +               goto retry;
4665 +       }
4666 +       path_put(&dir_path);
4667 +       vxdprintk(VXD_CBIT(misc, 2),
4668 +               "kern_path_create(new): %p [" VS_Q("%.*s") ":%d]",
4669 +               new_dentry,
4670 +               new_dentry->d_name.len, new_dentry->d_name.name,
4671 +               new_dentry->d_name.len);
4672 +
4673 +       dir = dir_nd.path.dentry;
4674 +
4675 +       ret = vfs_create(dir->d_inode, new_dentry, mode, &dir_nd);
4676 +       vxdprintk(VXD_CBIT(misc, 2),
4677 +               "vfs_create(new): %d", ret);
4678 +       if (ret == -EEXIST) {
4679 +               mutex_unlock(&dir->d_inode->i_mutex);
4680 +               path_put(&dir_nd.path);
4681 +               dput(new_dentry);
4682 +               goto retry;
4683 +       }
4684 +       else if (ret < 0)
4685 +               goto out_unlock_new;
4686 +
4687 +       /* drop out early, ret passes ENOENT */
4688 +       ret = -ENOENT;
4689 +       if ((redo = d_unhashed(old_dentry)))
4690 +               goto out_unlock_new;
4691 +
4692 +       path_get(&old_path);
4693 +       /* this one cleans up the dentry/mnt in case of failure */
4694 +       old_file = dentry_open(old_dentry, old_path.mnt,
4695 +               O_RDONLY, current_cred());
4696 +       vxdprintk(VXD_CBIT(misc, 2),
4697 +               "dentry_open(old): %p", old_file);
4698 +       if (IS_ERR(old_file)) {
4699 +               ret = PTR_ERR(old_file);
4700 +               goto out_unlock_new;
4701 +       }
4702 +
4703 +       dget(new_dentry);
4704 +       mntget(old_path.mnt);
4705 +       /* this one cleans up the dentry/mnt in case of failure */
4706 +       new_file = dentry_open(new_dentry, old_path.mnt,
4707 +               O_WRONLY, current_cred());
4708 +       vxdprintk(VXD_CBIT(misc, 2),
4709 +               "dentry_open(new): %p", new_file);
4710 +       if (IS_ERR(new_file)) {
4711 +               ret = PTR_ERR(new_file);
4712 +               goto out_fput_old;
4713 +       }
4714 +
4715 +       size = i_size_read(old_file->f_dentry->d_inode);
4716 +       ret = do_cow_splice(old_file, new_file, size);
4717 +       vxdprintk(VXD_CBIT(misc, 2), "do_splice_direct: %d", ret);
4718 +       if (ret < 0) {
4719 +               goto out_fput_both;
4720 +       } else if (ret < size) {
4721 +               ret = -ENOSPC;
4722 +               goto out_fput_both;
4723 +       } else {
4724 +               struct inode *old_inode = old_dentry->d_inode;
4725 +               struct inode *new_inode = new_dentry->d_inode;
4726 +               struct iattr attr = {
4727 +                       .ia_uid = old_inode->i_uid,
4728 +                       .ia_gid = old_inode->i_gid,
4729 +                       .ia_valid = ATTR_UID | ATTR_GID
4730 +                       };
4731 +
4732 +               setattr_copy(new_inode, &attr);
4733 +               mark_inode_dirty(new_inode);
4734 +       }
4735 +
4736 +       mutex_lock(&old_dentry->d_inode->i_sb->s_vfs_rename_mutex);
4737 +
4738 +       /* drop out late */
4739 +       ret = -ENOENT;
4740 +       if ((redo = d_unhashed(old_dentry)))
4741 +               goto out_unlock;
4742 +
4743 +       vxdprintk(VXD_CBIT(misc, 2),
4744 +               "vfs_rename: [" VS_Q("%*s") ":%d] -> [" VS_Q("%*s") ":%d]",
4745 +               new_dentry->d_name.len, new_dentry->d_name.name,
4746 +               new_dentry->d_name.len,
4747 +               old_dentry->d_name.len, old_dentry->d_name.name,
4748 +               old_dentry->d_name.len);
4749 +       ret = vfs_rename(dir_nd.path.dentry->d_inode, new_dentry,
4750 +               old_dentry->d_parent->d_inode, old_dentry);
4751 +       vxdprintk(VXD_CBIT(misc, 2), "vfs_rename: %d", ret);
4752 +
4753 +out_unlock:
4754 +       mutex_unlock(&old_dentry->d_inode->i_sb->s_vfs_rename_mutex);
4755 +
4756 +out_fput_both:
4757 +       vxdprintk(VXD_CBIT(misc, 3),
4758 +               "fput(new_file=%p[#%ld])", new_file,
4759 +               atomic_long_read(&new_file->f_count));
4760 +       fput(new_file);
4761 +
4762 +out_fput_old:
4763 +       vxdprintk(VXD_CBIT(misc, 3),
4764 +               "fput(old_file=%p[#%ld])", old_file,
4765 +               atomic_long_read(&old_file->f_count));
4766 +       fput(old_file);
4767 +
4768 +out_unlock_new:
4769 +       mutex_unlock(&dir->d_inode->i_mutex);
4770 +       if (!ret)
4771 +               goto out_redo;
4772 +
4773 +       /* error path cleanup */
4774 +       vfs_unlink(dir->d_inode, new_dentry);
4775 +
4776 +out_redo:
4777 +       if (!redo)
4778 +               goto out_rel_both;
4779 +       /* lookup dentry once again */
4780 +       /* old_nd.path is freed as old_path in out_rel_old */
4781 +       ret = do_path_lookup(AT_FDCWD, pathname, LOOKUP_FOLLOW, &old_nd);
4782 +       if (ret)
4783 +               goto out_rel_both;
4784 +
4785 +       dput(new_dentry);
4786 +       new_dentry = old_nd.path.dentry;
4787 +       vxdprintk(VXD_CBIT(misc, 2),
4788 +               "do_path_lookup(redo): %p [" VS_Q("%.*s") ":%d]",
4789 +               new_dentry,
4790 +               new_dentry->d_name.len, new_dentry->d_name.name,
4791 +               new_dentry->d_name.len);
4792 +       dget(new_dentry);
4793 +
4794 +out_rel_both:
4795 +       path_put(&dir_nd.path);
4796 +out_rel_old:
4797 +       path_put(&old_path);
4798 +out_free_path:
4799 +       kfree(path);
4800 +out:
4801 +       if (ret) {
4802 +               dput(new_dentry);
4803 +               new_dentry = ERR_PTR(ret);
4804 +       }
4805 +       vxdprintk(VXD_CBIT(misc, 3),
4806 +               "cow_break_link returning with %p [r=%d]",
4807 +               new_dentry, mnt_get_count(real_mount(old_nd.path.mnt)));
4808 +       return new_dentry;
4809 +}
4810 +
4811 +#endif
4812 +
4813 +int    vx_info_mnt_namespace(struct mnt_namespace *ns, char *buffer)
4814 +{
4815 +       struct path path;
4816 +       struct vfsmount *vmnt;
4817 +       char *pstr, *root;
4818 +       int length = 0;
4819 +
4820 +       pstr = kmalloc(PATH_MAX, GFP_KERNEL);
4821 +       if (!pstr)
4822 +               return 0;
4823 +
4824 +       vmnt = &ns->root->mnt;
4825 +       path.mnt = vmnt;
4826 +       path.dentry = vmnt->mnt_root;
4827 +       root = d_path(&path, pstr, PATH_MAX - 2);
4828 +       length = sprintf(buffer + length,
4829 +               "Namespace:\t%p [#%u]\n"
4830 +               "RootPath:\t%s\n",
4831 +               ns, atomic_read(&ns->count),
4832 +               root);
4833 +       kfree(pstr);
4834 +       return length;
4835 +}
4836 +
4837  /* get the link contents into pagecache */
4838  static char *page_getlink(struct dentry * dentry, struct page **ppage)
4839  {
4840 @@ -3998,3 +4388,4 @@ EXPORT_SYMBOL(vfs_symlink);
4841  EXPORT_SYMBOL(vfs_unlink);
4842  EXPORT_SYMBOL(dentry_unhash);
4843  EXPORT_SYMBOL(generic_readlink);
4844 +EXPORT_SYMBOL(vx_info_mnt_namespace);
4845 diff -NurpP --minimal linux-3.6/fs/namespace.c linux-3.6-vs2.3.4.3-noxfs-nocow/fs/namespace.c
4846 --- linux-3.6/fs/namespace.c    2012-10-04 15:27:40.000000000 +0200
4847 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/fs/namespace.c      2012-10-04 18:47:00.000000000 +0200
4848 @@ -20,6 +20,11 @@
4849  #include <linux/fs_struct.h>   /* get_fs_root et.al. */
4850  #include <linux/fsnotify.h>    /* fsnotify_vfsmount_delete */
4851  #include <linux/uaccess.h>
4852 +#include <linux/vs_base.h>
4853 +#include <linux/vs_context.h>
4854 +#include <linux/vs_tag.h>
4855 +#include <linux/vserver/space.h>
4856 +#include <linux/vserver/global.h>
4857  #include "pnode.h"
4858  #include "internal.h"
4859  
4860 @@ -749,6 +754,10 @@ vfs_kern_mount(struct file_system_type *
4861         if (!type)
4862                 return ERR_PTR(-ENODEV);
4863  
4864 +       if ((type->fs_flags & FS_BINARY_MOUNTDATA) &&
4865 +               !vx_capable(CAP_SYS_ADMIN, VXC_BINARY_MOUNT))
4866 +               return ERR_PTR(-EPERM);
4867 +
4868         mnt = alloc_vfsmnt(name);
4869         if (!mnt)
4870                 return ERR_PTR(-ENOMEM);
4871 @@ -801,6 +810,7 @@ static struct mount *clone_mnt(struct mo
4872         mnt->mnt.mnt_root = dget(root);
4873         mnt->mnt_mountpoint = mnt->mnt.mnt_root;
4874         mnt->mnt_parent = mnt;
4875 +               mnt->mnt_tag = old->mnt_tag;
4876         br_write_lock(&vfsmount_lock);
4877         list_add_tail(&mnt->mnt_instance, &sb->s_mounts);
4878         br_write_unlock(&vfsmount_lock);
4879 @@ -1266,7 +1276,7 @@ SYSCALL_DEFINE2(umount, char __user *, n
4880                 goto dput_and_out;
4881  
4882         retval = -EPERM;
4883 -       if (!capable(CAP_SYS_ADMIN))
4884 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SECURE_MOUNT))
4885                 goto dput_and_out;
4886  
4887         retval = do_umount(mnt, flags);
4888 @@ -1292,7 +1302,7 @@ SYSCALL_DEFINE1(oldumount, char __user *
4889  
4890  static int mount_is_safe(struct path *path)
4891  {
4892 -       if (capable(CAP_SYS_ADMIN))
4893 +       if (vx_capable(CAP_SYS_ADMIN, VXC_SECURE_MOUNT))
4894                 return 0;
4895         return -EPERM;
4896  #ifdef notyet
4897 @@ -1610,7 +1620,7 @@ static int do_change_type(struct path *p
4898         int type;
4899         int err = 0;
4900  
4901 -       if (!capable(CAP_SYS_ADMIN))
4902 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_NAMESPACE))
4903                 return -EPERM;
4904  
4905         if (path->dentry != path->mnt->mnt_root)
4906 @@ -1626,6 +1636,7 @@ static int do_change_type(struct path *p
4907                 if (err)
4908                         goto out_unlock;
4909         }
4910 +       // mnt->mnt_flags = mnt_flags;
4911  
4912         br_write_lock(&vfsmount_lock);
4913         for (m = mnt; m; m = (recurse ? next_mnt(m, mnt) : NULL))
4914 @@ -1641,12 +1652,14 @@ static int do_change_type(struct path *p
4915   * do loopback mount.
4916   */
4917  static int do_loopback(struct path *path, char *old_name,
4918 -                               int recurse)
4919 +       tag_t tag, unsigned long flags, int mnt_flags)
4920  {
4921         LIST_HEAD(umount_list);
4922         struct path old_path;
4923         struct mount *mnt = NULL, *old;
4924         int err = mount_is_safe(path);
4925 +       int recurse = flags & MS_REC;
4926 +
4927         if (err)
4928                 return err;
4929         if (!old_name || !*old_name)
4930 @@ -1715,13 +1728,13 @@ static int change_mount_flags(struct vfs
4931   * on it - tough luck.
4932   */
4933  static int do_remount(struct path *path, int flags, int mnt_flags,
4934 -                     void *data)
4935 +       void *data, xid_t xid)
4936  {
4937         int err;
4938         struct super_block *sb = path->mnt->mnt_sb;
4939         struct mount *mnt = real_mount(path->mnt);
4940  
4941 -       if (!capable(CAP_SYS_ADMIN))
4942 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SECURE_REMOUNT))
4943                 return -EPERM;
4944  
4945         if (!check_mnt(mnt))
4946 @@ -1770,7 +1783,7 @@ static int do_move_mount(struct path *pa
4947         struct mount *p;
4948         struct mount *old;
4949         int err = 0;
4950 -       if (!capable(CAP_SYS_ADMIN))
4951 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SECURE_MOUNT))
4952                 return -EPERM;
4953         if (!old_name || !*old_name)
4954                 return -EINVAL;
4955 @@ -1927,7 +1940,7 @@ static int do_new_mount(struct path *pat
4956                 return -EINVAL;
4957  
4958         /* we need capabilities... */
4959 -       if (!capable(CAP_SYS_ADMIN))
4960 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SECURE_MOUNT))
4961                 return -EPERM;
4962  
4963         mnt = do_kern_mount(type, flags, name, data);
4964 @@ -2197,6 +2210,7 @@ long do_mount(char *dev_name, char *dir_
4965         struct path path;
4966         int retval = 0;
4967         int mnt_flags = 0;
4968 +       tag_t tag = 0;
4969  
4970         /* Discard magic */
4971         if ((flags & MS_MGC_MSK) == MS_MGC_VAL)
4972 @@ -2224,6 +2238,12 @@ long do_mount(char *dev_name, char *dir_
4973         if (!(flags & MS_NOATIME))
4974                 mnt_flags |= MNT_RELATIME;
4975  
4976 +       if (dx_parse_tag(data_page, &tag, 1, &mnt_flags, &flags)) {
4977 +               /* FIXME: bind and re-mounts get the tag flag? */
4978 +               if (flags & (MS_BIND|MS_REMOUNT))
4979 +                       flags |= MS_TAGID;
4980 +       }
4981 +
4982         /* Separate the per-mountpoint flags */
4983         if (flags & MS_NOSUID)
4984                 mnt_flags |= MNT_NOSUID;
4985 @@ -2240,15 +2260,17 @@ long do_mount(char *dev_name, char *dir_
4986         if (flags & MS_RDONLY)
4987                 mnt_flags |= MNT_READONLY;
4988  
4989 +       if (!capable(CAP_SYS_ADMIN))
4990 +               mnt_flags |= MNT_NODEV;
4991         flags &= ~(MS_NOSUID | MS_NOEXEC | MS_NODEV | MS_ACTIVE | MS_BORN |
4992                    MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
4993                    MS_STRICTATIME);
4994  
4995         if (flags & MS_REMOUNT)
4996                 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
4997 -                                   data_page);
4998 +                                   data_page, tag);
4999         else if (flags & MS_BIND)
5000 -               retval = do_loopback(&path, dev_name, flags & MS_REC);
5001 +               retval = do_loopback(&path, dev_name, tag, flags, mnt_flags);
5002         else if (flags & (MS_SHARED | MS_PRIVATE | MS_SLAVE | MS_UNBINDABLE))
5003                 retval = do_change_type(&path, flags);
5004         else if (flags & MS_MOVE)
5005 @@ -2329,6 +2351,7 @@ static struct mnt_namespace *dup_mnt_ns(
5006                 q = next_mnt(q, new);
5007         }
5008         up_write(&namespace_sem);
5009 +       atomic_inc(&vs_global_mnt_ns);
5010  
5011         if (rootmnt)
5012                 mntput(rootmnt);
5013 @@ -2524,9 +2547,10 @@ SYSCALL_DEFINE2(pivot_root, const char _
5014         error = -EINVAL;
5015         new_mnt = real_mount(new.mnt);
5016         root_mnt = real_mount(root.mnt);
5017 -       if (IS_MNT_SHARED(real_mount(old.mnt)) ||
5018 +       if ((IS_MNT_SHARED(real_mount(old.mnt)) ||
5019                 IS_MNT_SHARED(new_mnt->mnt_parent) ||
5020 -               IS_MNT_SHARED(root_mnt->mnt_parent))
5021 +               IS_MNT_SHARED(root_mnt->mnt_parent)) &&
5022 +               !vx_flags(VXF_STATE_SETUP, 0))
5023                 goto out4;
5024         if (!check_mnt(root_mnt) || !check_mnt(new_mnt))
5025                 goto out4;
5026 @@ -2647,6 +2671,7 @@ void put_mnt_ns(struct mnt_namespace *ns
5027         br_write_unlock(&vfsmount_lock);
5028         up_write(&namespace_sem);
5029         release_mounts(&umount_list);
5030 +       atomic_dec(&vs_global_mnt_ns);
5031         kfree(ns);
5032  }
5033  
5034 diff -NurpP --minimal linux-3.6/fs/nfs/client.c linux-3.6-vs2.3.4.3-noxfs-nocow/fs/nfs/client.c
5035 --- linux-3.6/fs/nfs/client.c   2012-10-04 15:27:40.000000000 +0200
5036 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/fs/nfs/client.c     2012-10-04 18:47:00.000000000 +0200
5037 @@ -692,6 +692,9 @@ int nfs_init_server_rpcclient(struct nfs
5038         if (server->flags & NFS_MOUNT_SOFT)
5039                 server->client->cl_softrtry = 1;
5040  
5041 +       server->client->cl_tag = 0;
5042 +       if (server->flags & NFS_MOUNT_TAGGED)
5043 +               server->client->cl_tag = 1;
5044         return 0;
5045  }
5046  EXPORT_SYMBOL_GPL(nfs_init_server_rpcclient);
5047 @@ -870,6 +873,10 @@ static void nfs_server_set_fsinfo(struct
5048                 server->acdirmin = server->acdirmax = 0;
5049         }
5050  
5051 +       /* FIXME: needs fsinfo
5052 +       if (server->flags & NFS_MOUNT_TAGGED)
5053 +               sb->s_flags |= MS_TAGGED;       */
5054 +
5055         server->maxfilesize = fsinfo->maxfilesize;
5056  
5057         server->time_delta = fsinfo->time_delta;
5058 diff -NurpP --minimal linux-3.6/fs/nfs/dir.c linux-3.6-vs2.3.4.3-noxfs-nocow/fs/nfs/dir.c
5059 --- linux-3.6/fs/nfs/dir.c      2012-10-04 15:27:40.000000000 +0200
5060 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/fs/nfs/dir.c        2012-10-04 18:47:00.000000000 +0200
5061 @@ -36,6 +36,7 @@
5062  #include <linux/sched.h>
5063  #include <linux/kmemleak.h>
5064  #include <linux/xattr.h>
5065 +#include <linux/vs_tag.h>
5066  
5067  #include "delegation.h"
5068  #include "iostat.h"
5069 @@ -1251,6 +1252,7 @@ struct dentry *nfs_lookup(struct inode *
5070         /* Success: notify readdir to use READDIRPLUS */
5071         nfs_advise_use_readdirplus(dir);
5072  
5073 +       dx_propagate_tag(nd, inode);
5074  no_entry:
5075         res = d_materialise_unique(dentry, inode);
5076         if (res != NULL) {
5077 diff -NurpP --minimal linux-3.6/fs/nfs/inode.c linux-3.6-vs2.3.4.3-noxfs-nocow/fs/nfs/inode.c
5078 --- linux-3.6/fs/nfs/inode.c    2012-10-04 15:27:40.000000000 +0200
5079 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/fs/nfs/inode.c      2012-10-04 18:47:00.000000000 +0200
5080 @@ -39,6 +39,7 @@
5081  #include <linux/compat.h>
5082  #include <linux/freezer.h>
5083  #include <linux/crc32.h>
5084 +#include <linux/vs_tag.h>
5085  
5086  #include <asm/uaccess.h>
5087  
5088 @@ -279,6 +280,8 @@ nfs_fhget(struct super_block *sb, struct
5089         if (inode->i_state & I_NEW) {
5090                 struct nfs_inode *nfsi = NFS_I(inode);
5091                 unsigned long now = jiffies;
5092 +               uid_t uid;
5093 +               gid_t gid;
5094  
5095                 /* We set i_ino for the few things that still rely on it,
5096                  * such as stat(2) */
5097 @@ -323,8 +326,8 @@ nfs_fhget(struct super_block *sb, struct
5098                 inode->i_version = 0;
5099                 inode->i_size = 0;
5100                 clear_nlink(inode);
5101 -               inode->i_uid = -2;
5102 -               inode->i_gid = -2;
5103 +               uid = -2;
5104 +               gid = -2;
5105                 inode->i_blocks = 0;
5106                 memset(nfsi->cookieverf, 0, sizeof(nfsi->cookieverf));
5107                 nfsi->write_io = 0;
5108 @@ -358,11 +361,11 @@ nfs_fhget(struct super_block *sb, struct
5109                 else if (nfs_server_capable(inode, NFS_CAP_NLINK))
5110                         nfsi->cache_validity |= NFS_INO_INVALID_ATTR;
5111                 if (fattr->valid & NFS_ATTR_FATTR_OWNER)
5112 -                       inode->i_uid = fattr->uid;
5113 +                       uid = fattr->uid;
5114                 else if (nfs_server_capable(inode, NFS_CAP_OWNER))
5115                         nfsi->cache_validity |= NFS_INO_INVALID_ATTR;
5116                 if (fattr->valid & NFS_ATTR_FATTR_GROUP)
5117 -                       inode->i_gid = fattr->gid;
5118 +                       gid = fattr->gid;
5119                 else if (nfs_server_capable(inode, NFS_CAP_OWNER_GROUP))
5120                         nfsi->cache_validity |= NFS_INO_INVALID_ATTR;
5121                 if (fattr->valid & NFS_ATTR_FATTR_BLOCKS_USED)
5122 @@ -373,6 +376,11 @@ nfs_fhget(struct super_block *sb, struct
5123                          */
5124                         inode->i_blocks = nfs_calc_block_size(fattr->du.nfs3.used);
5125                 }
5126 +               inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
5127 +               inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
5128 +               inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid, 0);
5129 +                               /* maybe fattr->xid someday */
5130 +
5131                 nfsi->attrtimeo = NFS_MINATTRTIMEO(inode);
5132                 nfsi->attrtimeo_timestamp = now;
5133                 nfsi->access_cache = RB_ROOT;
5134 @@ -494,6 +502,8 @@ void nfs_setattr_update_inode(struct ino
5135                         inode->i_uid = attr->ia_uid;
5136                 if ((attr->ia_valid & ATTR_GID) != 0)
5137                         inode->i_gid = attr->ia_gid;
5138 +               if ((attr->ia_valid & ATTR_TAG) && IS_TAGGED(inode))
5139 +                       inode->i_tag = attr->ia_tag;
5140                 NFS_I(inode)->cache_validity |= NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL;
5141                 spin_unlock(&inode->i_lock);
5142         }
5143 @@ -965,6 +975,9 @@ static int nfs_check_inode_attributes(st
5144         struct nfs_inode *nfsi = NFS_I(inode);
5145         loff_t cur_size, new_isize;
5146         unsigned long invalid = 0;
5147 +       uid_t uid;
5148 +       gid_t gid;
5149 +       tag_t tag;
5150  
5151  
5152         if (nfs_have_delegated_attributes(inode))
5153 @@ -990,13 +1003,18 @@ static int nfs_check_inode_attributes(st
5154                         invalid |= NFS_INO_INVALID_ATTR|NFS_INO_REVAL_PAGECACHE;
5155         }
5156  
5157 +       uid = INOTAG_UID(DX_TAG(inode), fattr->uid, fattr->gid);
5158 +       gid = INOTAG_GID(DX_TAG(inode), fattr->uid, fattr->gid);
5159 +       tag = INOTAG_TAG(DX_TAG(inode), fattr->uid, fattr->gid, 0);
5160 +
5161         /* Have any file permissions changed? */
5162         if ((fattr->valid & NFS_ATTR_FATTR_MODE) && (inode->i_mode & S_IALLUGO) != (fattr->mode & S_IALLUGO))
5163                 invalid |= NFS_INO_INVALID_ATTR | NFS_INO_INVALID_ACCESS | NFS_INO_INVALID_ACL;
5164 -       if ((fattr->valid & NFS_ATTR_FATTR_OWNER) && inode->i_uid != fattr->uid)
5165 +       if ((fattr->valid & NFS_ATTR_FATTR_OWNER) && uid != fattr->uid)
5166                 invalid |= NFS_INO_INVALID_ATTR | NFS_INO_INVALID_ACCESS | NFS_INO_INVALID_ACL;
5167 -       if ((fattr->valid & NFS_ATTR_FATTR_GROUP) && inode->i_gid != fattr->gid)
5168 +       if ((fattr->valid & NFS_ATTR_FATTR_GROUP) && gid != fattr->gid)
5169                 invalid |= NFS_INO_INVALID_ATTR | NFS_INO_INVALID_ACCESS | NFS_INO_INVALID_ACL;
5170 +               /* maybe check for tag too? */
5171  
5172         /* Has the link count changed? */
5173         if ((fattr->valid & NFS_ATTR_FATTR_NLINK) && inode->i_nlink != fattr->nlink)
5174 @@ -1300,6 +1318,9 @@ static int nfs_update_inode(struct inode
5175         unsigned long invalid = 0;
5176         unsigned long now = jiffies;
5177         unsigned long save_cache_validity;
5178 +       uid_t uid;
5179 +       gid_t gid;
5180 +       tag_t tag;
5181  
5182         dfprintk(VFS, "NFS: %s(%s/%ld fh_crc=0x%08x ct=%d info=0x%x)\n",
5183                         __func__, inode->i_sb->s_id, inode->i_ino,
5184 @@ -1401,6 +1422,9 @@ static int nfs_update_inode(struct inode
5185                                 | NFS_INO_REVAL_PAGECACHE
5186                                 | NFS_INO_REVAL_FORCED);
5187  
5188 +       uid = TAGINO_UID(DX_TAG(inode), inode->i_uid, inode->i_tag);
5189 +       gid = TAGINO_GID(DX_TAG(inode), inode->i_gid, inode->i_tag);
5190 +       tag = inode->i_tag;
5191  
5192         if (fattr->valid & NFS_ATTR_FATTR_ATIME)
5193                 memcpy(&inode->i_atime, &fattr->atime, sizeof(inode->i_atime));
5194 @@ -1422,9 +1446,9 @@ static int nfs_update_inode(struct inode
5195                                 | NFS_INO_REVAL_FORCED);
5196  
5197         if (fattr->valid & NFS_ATTR_FATTR_OWNER) {
5198 -               if (inode->i_uid != fattr->uid) {
5199 +               if (uid != fattr->uid) {
5200                         invalid |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL;
5201 -                       inode->i_uid = fattr->uid;
5202 +                       uid = fattr->uid;
5203                 }
5204         } else if (server->caps & NFS_CAP_OWNER)
5205                 invalid |= save_cache_validity & (NFS_INO_INVALID_ATTR
5206 @@ -1433,9 +1457,9 @@ static int nfs_update_inode(struct inode
5207                                 | NFS_INO_REVAL_FORCED);
5208  
5209         if (fattr->valid & NFS_ATTR_FATTR_GROUP) {
5210 -               if (inode->i_gid != fattr->gid) {
5211 +               if (gid != fattr->gid) {
5212                         invalid |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL;
5213 -                       inode->i_gid = fattr->gid;
5214 +                       gid = fattr->gid;
5215                 }
5216         } else if (server->caps & NFS_CAP_OWNER_GROUP)
5217                 invalid |= save_cache_validity & (NFS_INO_INVALID_ATTR
5218 @@ -1443,6 +1467,10 @@ static int nfs_update_inode(struct inode
5219                                 | NFS_INO_INVALID_ACL
5220                                 | NFS_INO_REVAL_FORCED);
5221  
5222 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
5223 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
5224 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid, tag);
5225 +
5226         if (fattr->valid & NFS_ATTR_FATTR_NLINK) {
5227                 if (inode->i_nlink != fattr->nlink) {
5228                         invalid |= NFS_INO_INVALID_ATTR;
5229 diff -NurpP --minimal linux-3.6/fs/nfs/nfs3xdr.c linux-3.6-vs2.3.4.3-noxfs-nocow/fs/nfs/nfs3xdr.c
5230 --- linux-3.6/fs/nfs/nfs3xdr.c  2012-10-04 15:27:40.000000000 +0200
5231 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/fs/nfs/nfs3xdr.c    2012-10-04 18:47:00.000000000 +0200
5232 @@ -20,6 +20,7 @@
5233  #include <linux/nfs3.h>
5234  #include <linux/nfs_fs.h>
5235  #include <linux/nfsacl.h>
5236 +#include <linux/vs_tag.h>
5237  #include "internal.h"
5238  
5239  #define NFSDBG_FACILITY                NFSDBG_XDR
5240 @@ -560,7 +561,8 @@ static __be32 *xdr_decode_nfstime3(__be3
5241   *             set_mtime       mtime;
5242   *     };
5243   */
5244 -static void encode_sattr3(struct xdr_stream *xdr, const struct iattr *attr)
5245 +static void encode_sattr3(struct xdr_stream *xdr,
5246 +       const struct iattr *attr, int tag)
5247  {
5248         u32 nbytes;
5249         __be32 *p;
5250 @@ -592,15 +594,19 @@ static void encode_sattr3(struct xdr_str
5251         } else
5252                 *p++ = xdr_zero;
5253  
5254 -       if (attr->ia_valid & ATTR_UID) {
5255 +       if (attr->ia_valid & ATTR_UID ||
5256 +               (tag && (attr->ia_valid & ATTR_TAG))) {
5257                 *p++ = xdr_one;
5258 -               *p++ = cpu_to_be32(attr->ia_uid);
5259 +               *p++ = cpu_to_be32(TAGINO_UID(tag,
5260 +                       attr->ia_uid, attr->ia_tag));
5261         } else
5262                 *p++ = xdr_zero;
5263  
5264 -       if (attr->ia_valid & ATTR_GID) {
5265 +       if (attr->ia_valid & ATTR_GID ||
5266 +               (tag && (attr->ia_valid & ATTR_TAG))) {
5267                 *p++ = xdr_one;
5268 -               *p++ = cpu_to_be32(attr->ia_gid);
5269 +               *p++ = cpu_to_be32(TAGINO_GID(tag,
5270 +                       attr->ia_gid, attr->ia_tag));
5271         } else
5272                 *p++ = xdr_zero;
5273  
5274 @@ -879,7 +885,7 @@ static void nfs3_xdr_enc_setattr3args(st
5275                                       const struct nfs3_sattrargs *args)
5276  {
5277         encode_nfs_fh3(xdr, args->fh);
5278 -       encode_sattr3(xdr, args->sattr);
5279 +       encode_sattr3(xdr, args->sattr, req->rq_task->tk_client->cl_tag);
5280         encode_sattrguard3(xdr, args);
5281  }
5282  
5283 @@ -1029,13 +1035,13 @@ static void nfs3_xdr_enc_write3args(stru
5284   *     };
5285   */
5286  static void encode_createhow3(struct xdr_stream *xdr,
5287 -                             const struct nfs3_createargs *args)
5288 +       const struct nfs3_createargs *args, int tag)
5289  {
5290         encode_uint32(xdr, args->createmode);
5291         switch (args->createmode) {
5292         case NFS3_CREATE_UNCHECKED:
5293         case NFS3_CREATE_GUARDED:
5294 -               encode_sattr3(xdr, args->sattr);
5295 +               encode_sattr3(xdr, args->sattr, tag);
5296                 break;
5297         case NFS3_CREATE_EXCLUSIVE:
5298                 encode_createverf3(xdr, args->verifier);
5299 @@ -1050,7 +1056,7 @@ static void nfs3_xdr_enc_create3args(str
5300                                      const struct nfs3_createargs *args)
5301  {
5302         encode_diropargs3(xdr, args->fh, args->name, args->len);
5303 -       encode_createhow3(xdr, args);
5304 +       encode_createhow3(xdr, args, req->rq_task->tk_client->cl_tag);
5305  }
5306  
5307  /*
5308 @@ -1066,7 +1072,7 @@ static void nfs3_xdr_enc_mkdir3args(stru
5309                                     const struct nfs3_mkdirargs *args)
5310  {
5311         encode_diropargs3(xdr, args->fh, args->name, args->len);
5312 -       encode_sattr3(xdr, args->sattr);
5313 +       encode_sattr3(xdr, args->sattr, req->rq_task->tk_client->cl_tag);
5314  }
5315  
5316  /*
5317 @@ -1083,9 +1089,9 @@ static void nfs3_xdr_enc_mkdir3args(stru
5318   *     };
5319   */
5320  static void encode_symlinkdata3(struct xdr_stream *xdr,
5321 -                               const struct nfs3_symlinkargs *args)
5322 +       const struct nfs3_symlinkargs *args, int tag)
5323  {
5324 -       encode_sattr3(xdr, args->sattr);
5325 +       encode_sattr3(xdr, args->sattr, tag);
5326         encode_nfspath3(xdr, args->pages, args->pathlen);
5327  }
5328  
5329 @@ -1094,7 +1100,7 @@ static void nfs3_xdr_enc_symlink3args(st
5330                                       const struct nfs3_symlinkargs *args)
5331  {
5332         encode_diropargs3(xdr, args->fromfh, args->fromname, args->fromlen);
5333 -       encode_symlinkdata3(xdr, args);
5334 +       encode_symlinkdata3(xdr, args, req->rq_task->tk_client->cl_tag);
5335  }
5336  
5337  /*
5338 @@ -1122,24 +1128,24 @@ static void nfs3_xdr_enc_symlink3args(st
5339   *     };
5340   */
5341  static void encode_devicedata3(struct xdr_stream *xdr,
5342 -                              const struct nfs3_mknodargs *args)
5343 +       const struct nfs3_mknodargs *args, int tag)
5344  {
5345 -       encode_sattr3(xdr, args->sattr);
5346 +       encode_sattr3(xdr, args->sattr, tag);
5347         encode_specdata3(xdr, args->rdev);
5348  }
5349  
5350  static void encode_mknoddata3(struct xdr_stream *xdr,
5351 -                             const struct nfs3_mknodargs *args)
5352 +       const struct nfs3_mknodargs *args, int tag)
5353  {
5354         encode_ftype3(xdr, args->type);
5355         switch (args->type) {
5356         case NF3CHR:
5357         case NF3BLK:
5358 -               encode_devicedata3(xdr, args);
5359 +               encode_devicedata3(xdr, args, tag);
5360                 break;
5361         case NF3SOCK:
5362         case NF3FIFO:
5363 -               encode_sattr3(xdr, args->sattr);
5364 +               encode_sattr3(xdr, args->sattr, tag);
5365                 break;
5366         case NF3REG:
5367         case NF3DIR:
5368 @@ -1154,7 +1160,7 @@ static void nfs3_xdr_enc_mknod3args(stru
5369                                     const struct nfs3_mknodargs *args)
5370  {
5371         encode_diropargs3(xdr, args->fh, args->name, args->len);
5372 -       encode_mknoddata3(xdr, args);
5373 +       encode_mknoddata3(xdr, args, req->rq_task->tk_client->cl_tag);
5374  }
5375  
5376  /*
5377 diff -NurpP --minimal linux-3.6/fs/nfs/super.c linux-3.6-vs2.3.4.3-noxfs-nocow/fs/nfs/super.c
5378 --- linux-3.6/fs/nfs/super.c    2012-10-04 15:27:40.000000000 +0200
5379 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/fs/nfs/super.c      2012-10-04 18:47:00.000000000 +0200
5380 @@ -54,6 +54,7 @@
5381  #include <linux/parser.h>
5382  #include <linux/nsproxy.h>
5383  #include <linux/rcupdate.h>
5384 +#include <linux/vs_tag.h>
5385  
5386  #include <asm/uaccess.h>
5387  
5388 @@ -88,6 +89,7 @@ enum {
5389         Opt_sharecache, Opt_nosharecache,
5390         Opt_resvport, Opt_noresvport,
5391         Opt_fscache, Opt_nofscache,
5392 +       Opt_tag, Opt_notag,
5393  
5394         /* Mount options that take integer arguments */
5395         Opt_port,
5396 @@ -100,6 +102,7 @@ enum {
5397         Opt_mountport,
5398         Opt_mountvers,
5399         Opt_minorversion,
5400 +       Opt_tagid,
5401  
5402         /* Mount options that take string arguments */
5403         Opt_nfsvers,
5404 @@ -182,6 +185,10 @@ static const match_table_t nfs_mount_opt
5405         /* The following needs to be listed after all other options */
5406         { Opt_nfsvers, "v%s" },
5407  
5408 +       { Opt_tag, "tag" },
5409 +       { Opt_notag, "notag" },
5410 +       { Opt_tagid, "tagid=%u" },
5411 +
5412         { Opt_err, NULL }
5413  };
5414  
5415 @@ -626,6 +633,7 @@ static void nfs_show_mount_options(struc
5416                 { NFS_MOUNT_NORDIRPLUS, ",nordirplus", "" },
5417                 { NFS_MOUNT_UNSHARED, ",nosharecache", "" },
5418                 { NFS_MOUNT_NORESVPORT, ",noresvport", "" },
5419 +               { NFS_MOUNT_TAGGED, ",tag", "" },
5420                 { 0, NULL, NULL }
5421         };
5422         const struct proc_nfs_info *nfs_infop;
5423 @@ -1243,6 +1251,14 @@ static int nfs_parse_mount_options(char 
5424                         kfree(mnt->fscache_uniq);
5425                         mnt->fscache_uniq = NULL;
5426                         break;
5427 +#ifndef CONFIG_TAGGING_NONE
5428 +               case Opt_tag:
5429 +                       mnt->flags |= NFS_MOUNT_TAGGED;
5430 +                       break;
5431 +               case Opt_notag:
5432 +                       mnt->flags &= ~NFS_MOUNT_TAGGED;
5433 +                       break;
5434 +#endif
5435  
5436                 /*
5437                  * options that take numeric values
5438 @@ -1329,6 +1345,12 @@ static int nfs_parse_mount_options(char 
5439                                 goto out_invalid_value;
5440                         mnt->minorversion = option;
5441                         break;
5442 +#ifdef CONFIG_PROPAGATE
5443 +               case Opt_tagid:
5444 +                       /* use args[0] */
5445 +                       nfs_data.flags |= NFS_MOUNT_TAGGED;
5446 +                       break;
5447 +#endif
5448  
5449                 /*
5450                  * options that take text values
5451 diff -NurpP --minimal linux-3.6/fs/nfsd/auth.c linux-3.6-vs2.3.4.3-noxfs-nocow/fs/nfsd/auth.c
5452 --- linux-3.6/fs/nfsd/auth.c    2012-07-22 23:39:41.000000000 +0200
5453 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/fs/nfsd/auth.c      2012-10-04 18:47:00.000000000 +0200
5454 @@ -2,6 +2,7 @@
5455  
5456  #include <linux/sched.h>
5457  #include <linux/user_namespace.h>
5458 +#include <linux/vs_tag.h>
5459  #include "nfsd.h"
5460  #include "auth.h"
5461  
5462 @@ -37,6 +38,9 @@ int nfsd_setuser(struct svc_rqst *rqstp,
5463  
5464         new->fsuid = rqstp->rq_cred.cr_uid;
5465         new->fsgid = rqstp->rq_cred.cr_gid;
5466 +       /* FIXME: this desperately needs a tag :)
5467 +       new->xid = (xid_t)INOTAG_TAG(DX_TAG_NFSD, cred.cr_uid, cred.cr_gid, 0);
5468 +                       */
5469  
5470         rqgi = rqstp->rq_cred.cr_group_info;
5471  
5472 diff -NurpP --minimal linux-3.6/fs/nfsd/nfs3xdr.c linux-3.6-vs2.3.4.3-noxfs-nocow/fs/nfsd/nfs3xdr.c
5473 --- linux-3.6/fs/nfsd/nfs3xdr.c 2012-05-21 18:07:26.000000000 +0200
5474 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/fs/nfsd/nfs3xdr.c   2012-10-04 18:47:00.000000000 +0200
5475 @@ -7,6 +7,7 @@
5476   */
5477  
5478  #include <linux/namei.h>
5479 +#include <linux/vs_tag.h>
5480  #include "xdr3.h"
5481  #include "auth.h"
5482  
5483 @@ -95,6 +96,8 @@ static __be32 *
5484  decode_sattr3(__be32 *p, struct iattr *iap)
5485  {
5486         u32     tmp;
5487 +       uid_t   uid = 0;
5488 +       gid_t   gid = 0;
5489  
5490         iap->ia_valid = 0;
5491  
5492 @@ -104,12 +107,15 @@ decode_sattr3(__be32 *p, struct iattr *i
5493         }
5494         if (*p++) {
5495                 iap->ia_valid |= ATTR_UID;
5496 -               iap->ia_uid = ntohl(*p++);
5497 +               uid = ntohl(*p++);
5498         }
5499         if (*p++) {
5500                 iap->ia_valid |= ATTR_GID;
5501 -               iap->ia_gid = ntohl(*p++);
5502 +               gid = ntohl(*p++);
5503         }
5504 +       iap->ia_uid = INOTAG_UID(DX_TAG_NFSD, uid, gid);
5505 +       iap->ia_gid = INOTAG_GID(DX_TAG_NFSD, uid, gid);
5506 +       iap->ia_tag = INOTAG_TAG(DX_TAG_NFSD, uid, gid, 0);
5507         if (*p++) {
5508                 u64     newsize;
5509  
5510 @@ -165,8 +171,12 @@ encode_fattr3(struct svc_rqst *rqstp, __
5511         *p++ = htonl(nfs3_ftypes[(stat->mode & S_IFMT) >> 12]);
5512         *p++ = htonl((u32) stat->mode);
5513         *p++ = htonl((u32) stat->nlink);
5514 -       *p++ = htonl((u32) nfsd_ruid(rqstp, stat->uid));
5515 -       *p++ = htonl((u32) nfsd_rgid(rqstp, stat->gid));
5516 +       *p++ = htonl((u32) nfsd_ruid(rqstp,
5517 +               TAGINO_UID(0 /* FIXME: DX_TAG(dentry->d_inode) */,
5518 +               stat->uid, stat->tag)));
5519 +       *p++ = htonl((u32) nfsd_rgid(rqstp,
5520 +               TAGINO_GID(0 /* FIXME: DX_TAG(dentry->d_inode) */,
5521 +               stat->gid, stat->tag)));
5522         if (S_ISLNK(stat->mode) && stat->size > NFS3_MAXPATHLEN) {
5523                 p = xdr_encode_hyper(p, (u64) NFS3_MAXPATHLEN);
5524         } else {
5525 diff -NurpP --minimal linux-3.6/fs/nfsd/nfs4xdr.c linux-3.6-vs2.3.4.3-noxfs-nocow/fs/nfsd/nfs4xdr.c
5526 --- linux-3.6/fs/nfsd/nfs4xdr.c 2012-10-04 15:27:40.000000000 +0200
5527 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/fs/nfsd/nfs4xdr.c   2012-10-04 18:47:00.000000000 +0200
5528 @@ -46,6 +46,7 @@
5529  #include <linux/utsname.h>
5530  #include <linux/pagemap.h>
5531  #include <linux/sunrpc/svcauth_gss.h>
5532 +#include <linux/vs_tag.h>
5533  
5534  #include "idmap.h"
5535  #include "acl.h"
5536 @@ -2351,14 +2352,18 @@ out_acl:
5537                 WRITE32(stat.nlink);
5538         }
5539         if (bmval1 & FATTR4_WORD1_OWNER) {
5540 -               status = nfsd4_encode_user(rqstp, stat.uid, &p, &buflen);
5541 +               status = nfsd4_encode_user(rqstp,
5542 +                       TAGINO_UID(DX_TAG(dentry->d_inode),
5543 +                       stat.uid, stat.tag), &p, &buflen);
5544                 if (status == nfserr_resource)
5545                         goto out_resource;
5546                 if (status)
5547                         goto out;
5548         }
5549         if (bmval1 & FATTR4_WORD1_OWNER_GROUP) {
5550 -               status = nfsd4_encode_group(rqstp, stat.gid, &p, &buflen);
5551 +               status = nfsd4_encode_group(rqstp,
5552 +                       TAGINO_GID(DX_TAG(dentry->d_inode),
5553 +                       stat.gid, stat.tag), &p, &buflen);
5554                 if (status == nfserr_resource)
5555                         goto out_resource;
5556                 if (status)
5557 diff -NurpP --minimal linux-3.6/fs/nfsd/nfsxdr.c linux-3.6-vs2.3.4.3-noxfs-nocow/fs/nfsd/nfsxdr.c
5558 --- linux-3.6/fs/nfsd/nfsxdr.c  2011-05-22 16:17:53.000000000 +0200
5559 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/fs/nfsd/nfsxdr.c    2012-10-04 18:47:00.000000000 +0200
5560 @@ -6,6 +6,7 @@
5561  
5562  #include "xdr.h"
5563  #include "auth.h"
5564 +#include <linux/vs_tag.h>
5565  
5566  #define NFSDDBG_FACILITY               NFSDDBG_XDR
5567  
5568 @@ -88,6 +89,8 @@ static __be32 *
5569  decode_sattr(__be32 *p, struct iattr *iap)
5570  {
5571         u32     tmp, tmp1;
5572 +       uid_t   uid = 0;
5573 +       gid_t   gid = 0;
5574  
5575         iap->ia_valid = 0;
5576  
5577 @@ -101,12 +104,15 @@ decode_sattr(__be32 *p, struct iattr *ia
5578         }
5579         if ((tmp = ntohl(*p++)) != (u32)-1) {
5580                 iap->ia_valid |= ATTR_UID;
5581 -               iap->ia_uid = tmp;
5582 +               uid = tmp;
5583         }
5584         if ((tmp = ntohl(*p++)) != (u32)-1) {
5585                 iap->ia_valid |= ATTR_GID;
5586 -               iap->ia_gid = tmp;
5587 +               gid = tmp;
5588         }
5589 +       iap->ia_uid = INOTAG_UID(DX_TAG_NFSD, uid, gid);
5590 +       iap->ia_gid = INOTAG_GID(DX_TAG_NFSD, uid, gid);
5591 +       iap->ia_tag = INOTAG_TAG(DX_TAG_NFSD, uid, gid, 0);
5592         if ((tmp = ntohl(*p++)) != (u32)-1) {
5593                 iap->ia_valid |= ATTR_SIZE;
5594                 iap->ia_size = tmp;
5595 @@ -151,8 +157,10 @@ encode_fattr(struct svc_rqst *rqstp, __b
5596         *p++ = htonl(nfs_ftypes[type >> 12]);
5597         *p++ = htonl((u32) stat->mode);
5598         *p++ = htonl((u32) stat->nlink);
5599 -       *p++ = htonl((u32) nfsd_ruid(rqstp, stat->uid));
5600 -       *p++ = htonl((u32) nfsd_rgid(rqstp, stat->gid));
5601 +       *p++ = htonl((u32) nfsd_ruid(rqstp,
5602 +               TAGINO_UID(DX_TAG(dentry->d_inode), stat->uid, stat->tag)));
5603 +       *p++ = htonl((u32) nfsd_rgid(rqstp,
5604 +               TAGINO_GID(DX_TAG(dentry->d_inode), stat->gid, stat->tag)));
5605  
5606         if (S_ISLNK(type) && stat->size > NFS_MAXPATHLEN) {
5607                 *p++ = htonl(NFS_MAXPATHLEN);
5608 diff -NurpP --minimal linux-3.6/fs/ocfs2/dlmglue.c linux-3.6-vs2.3.4.3-noxfs-nocow/fs/ocfs2/dlmglue.c
5609 --- linux-3.6/fs/ocfs2/dlmglue.c        2012-07-22 23:39:41.000000000 +0200
5610 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/fs/ocfs2/dlmglue.c  2012-10-04 18:47:00.000000000 +0200
5611 @@ -2047,6 +2047,7 @@ static void __ocfs2_stuff_meta_lvb(struc
5612         lvb->lvb_iclusters = cpu_to_be32(oi->ip_clusters);
5613         lvb->lvb_iuid      = cpu_to_be32(inode->i_uid);
5614         lvb->lvb_igid      = cpu_to_be32(inode->i_gid);
5615 +       lvb->lvb_itag      = cpu_to_be16(inode->i_tag);
5616         lvb->lvb_imode     = cpu_to_be16(inode->i_mode);
5617         lvb->lvb_inlink    = cpu_to_be16(inode->i_nlink);
5618         lvb->lvb_iatime_packed  =
5619 @@ -2097,6 +2098,7 @@ static void ocfs2_refresh_inode_from_lvb
5620  
5621         inode->i_uid     = be32_to_cpu(lvb->lvb_iuid);
5622         inode->i_gid     = be32_to_cpu(lvb->lvb_igid);
5623 +       inode->i_tag     = be16_to_cpu(lvb->lvb_itag);
5624         inode->i_mode    = be16_to_cpu(lvb->lvb_imode);
5625         set_nlink(inode, be16_to_cpu(lvb->lvb_inlink));
5626         ocfs2_unpack_timespec(&inode->i_atime,
5627 diff -NurpP --minimal linux-3.6/fs/ocfs2/dlmglue.h linux-3.6-vs2.3.4.3-noxfs-nocow/fs/ocfs2/dlmglue.h
5628 --- linux-3.6/fs/ocfs2/dlmglue.h        2010-10-21 13:07:50.000000000 +0200
5629 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/fs/ocfs2/dlmglue.h  2012-10-04 18:47:00.000000000 +0200
5630 @@ -46,7 +46,8 @@ struct ocfs2_meta_lvb {
5631         __be16       lvb_inlink;
5632         __be32       lvb_iattr;
5633         __be32       lvb_igeneration;
5634 -       __be32       lvb_reserved2;
5635 +       __be16       lvb_itag;
5636 +       __be16       lvb_reserved2;
5637  };
5638  
5639  #define OCFS2_QINFO_LVB_VERSION 1
5640 diff -NurpP --minimal linux-3.6/fs/ocfs2/file.c linux-3.6-vs2.3.4.3-noxfs-nocow/fs/ocfs2/file.c
5641 --- linux-3.6/fs/ocfs2/file.c   2012-10-04 15:27:41.000000000 +0200
5642 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/fs/ocfs2/file.c     2012-10-04 18:47:00.000000000 +0200
5643 @@ -1123,7 +1123,7 @@ int ocfs2_setattr(struct dentry *dentry,
5644                 attr->ia_valid &= ~ATTR_SIZE;
5645  
5646  #define OCFS2_VALID_ATTRS (ATTR_ATIME | ATTR_MTIME | ATTR_CTIME | ATTR_SIZE \
5647 -                          | ATTR_GID | ATTR_UID | ATTR_MODE)
5648 +                          | ATTR_GID | ATTR_UID | ATTR_TAG | ATTR_MODE)
5649         if (!(attr->ia_valid & OCFS2_VALID_ATTRS))
5650                 return 0;
5651  
5652 diff -NurpP --minimal linux-3.6/fs/ocfs2/inode.c linux-3.6-vs2.3.4.3-noxfs-nocow/fs/ocfs2/inode.c
5653 --- linux-3.6/fs/ocfs2/inode.c  2012-07-22 23:39:41.000000000 +0200
5654 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/fs/ocfs2/inode.c    2012-10-04 18:47:00.000000000 +0200
5655 @@ -28,6 +28,7 @@
5656  #include <linux/highmem.h>
5657  #include <linux/pagemap.h>
5658  #include <linux/quotaops.h>
5659 +#include <linux/vs_tag.h>
5660  
5661  #include <asm/byteorder.h>
5662  
5663 @@ -78,11 +79,13 @@ void ocfs2_set_inode_flags(struct inode 
5664  {
5665         unsigned int flags = OCFS2_I(inode)->ip_attr;
5666  
5667 -       inode->i_flags &= ~(S_IMMUTABLE |
5668 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
5669                 S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
5670  
5671         if (flags & OCFS2_IMMUTABLE_FL)
5672                 inode->i_flags |= S_IMMUTABLE;
5673 +       if (flags & OCFS2_IXUNLINK_FL)
5674 +               inode->i_flags |= S_IXUNLINK;
5675  
5676         if (flags & OCFS2_SYNC_FL)
5677                 inode->i_flags |= S_SYNC;
5678 @@ -92,25 +95,44 @@ void ocfs2_set_inode_flags(struct inode 
5679                 inode->i_flags |= S_NOATIME;
5680         if (flags & OCFS2_DIRSYNC_FL)
5681                 inode->i_flags |= S_DIRSYNC;
5682 +
5683 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
5684 +
5685 +       if (flags & OCFS2_BARRIER_FL)
5686 +               inode->i_vflags |= V_BARRIER;
5687 +       if (flags & OCFS2_COW_FL)
5688 +               inode->i_vflags |= V_COW;
5689  }
5690  
5691  /* Propagate flags from i_flags to OCFS2_I(inode)->ip_attr */
5692  void ocfs2_get_inode_flags(struct ocfs2_inode_info *oi)
5693  {
5694         unsigned int flags = oi->vfs_inode.i_flags;
5695 +       unsigned int vflags = oi->vfs_inode.i_vflags;
5696 +
5697 +       oi->ip_attr &= ~(OCFS2_SYNC_FL | OCFS2_APPEND_FL |
5698 +                       OCFS2_IMMUTABLE_FL | OCFS2_IXUNLINK_FL |
5699 +                       OCFS2_NOATIME_FL | OCFS2_DIRSYNC_FL |
5700 +                       OCFS2_BARRIER_FL | OCFS2_COW_FL);
5701 +
5702 +       if (flags & S_IMMUTABLE)
5703 +               oi->ip_attr |= OCFS2_IMMUTABLE_FL;
5704 +       if (flags & S_IXUNLINK)
5705 +               oi->ip_attr |= OCFS2_IXUNLINK_FL;
5706  
5707 -       oi->ip_attr &= ~(OCFS2_SYNC_FL|OCFS2_APPEND_FL|
5708 -                       OCFS2_IMMUTABLE_FL|OCFS2_NOATIME_FL|OCFS2_DIRSYNC_FL);
5709         if (flags & S_SYNC)
5710                 oi->ip_attr |= OCFS2_SYNC_FL;
5711         if (flags & S_APPEND)
5712                 oi->ip_attr |= OCFS2_APPEND_FL;
5713 -       if (flags & S_IMMUTABLE)
5714 -               oi->ip_attr |= OCFS2_IMMUTABLE_FL;
5715         if (flags & S_NOATIME)
5716                 oi->ip_attr |= OCFS2_NOATIME_FL;
5717         if (flags & S_DIRSYNC)
5718                 oi->ip_attr |= OCFS2_DIRSYNC_FL;
5719 +
5720 +       if (vflags & V_BARRIER)
5721 +               oi->ip_attr |= OCFS2_BARRIER_FL;
5722 +       if (vflags & V_COW)
5723 +               oi->ip_attr |= OCFS2_COW_FL;
5724  }
5725  
5726  struct inode *ocfs2_ilookup(struct super_block *sb, u64 blkno)
5727 @@ -241,6 +263,8 @@ void ocfs2_populate_inode(struct inode *
5728         struct super_block *sb;
5729         struct ocfs2_super *osb;
5730         int use_plocks = 1;
5731 +       uid_t uid;
5732 +       gid_t gid;
5733  
5734         sb = inode->i_sb;
5735         osb = OCFS2_SB(sb);
5736 @@ -269,8 +293,12 @@ void ocfs2_populate_inode(struct inode *
5737         inode->i_generation = le32_to_cpu(fe->i_generation);
5738         inode->i_rdev = huge_decode_dev(le64_to_cpu(fe->id1.dev1.i_rdev));
5739         inode->i_mode = le16_to_cpu(fe->i_mode);
5740 -       inode->i_uid = le32_to_cpu(fe->i_uid);
5741 -       inode->i_gid = le32_to_cpu(fe->i_gid);
5742 +       uid = le32_to_cpu(fe->i_uid);
5743 +       gid = le32_to_cpu(fe->i_gid);
5744 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
5745 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
5746 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid,
5747 +               /* le16_to_cpu(raw_inode->i_raw_tag)i */ 0);
5748  
5749         /* Fast symlinks will have i_size but no allocated clusters. */
5750         if (S_ISLNK(inode->i_mode) && !fe->i_clusters) {
5751 diff -NurpP --minimal linux-3.6/fs/ocfs2/inode.h linux-3.6-vs2.3.4.3-noxfs-nocow/fs/ocfs2/inode.h
5752 --- linux-3.6/fs/ocfs2/inode.h  2012-01-09 16:14:55.000000000 +0100
5753 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/fs/ocfs2/inode.h    2012-10-04 18:47:00.000000000 +0200
5754 @@ -154,6 +154,7 @@ struct buffer_head *ocfs2_bread(struct i
5755  
5756  void ocfs2_set_inode_flags(struct inode *inode);
5757  void ocfs2_get_inode_flags(struct ocfs2_inode_info *oi);
5758 +int ocfs2_sync_flags(struct inode *inode, int, int);
5759  
5760  static inline blkcnt_t ocfs2_inode_sector_count(struct inode *inode)
5761  {
5762 diff -NurpP --minimal linux-3.6/fs/ocfs2/ioctl.c linux-3.6-vs2.3.4.3-noxfs-nocow/fs/ocfs2/ioctl.c
5763 --- linux-3.6/fs/ocfs2/ioctl.c  2012-10-04 15:27:41.000000000 +0200
5764 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/fs/ocfs2/ioctl.c    2012-10-04 18:47:00.000000000 +0200
5765 @@ -76,7 +76,41 @@ static int ocfs2_get_inode_attr(struct i
5766         return status;
5767  }
5768  
5769 -static int ocfs2_set_inode_attr(struct inode *inode, unsigned flags,
5770 +int ocfs2_sync_flags(struct inode *inode, int flags, int vflags)
5771 +{
5772 +       struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
5773 +       struct buffer_head *bh = NULL;
5774 +       handle_t *handle = NULL;
5775 +       int status;
5776 +
5777 +       status = ocfs2_inode_lock(inode, &bh, 1);
5778 +       if (status < 0) {
5779 +               mlog_errno(status);
5780 +               return status;
5781 +       }
5782 +       handle = ocfs2_start_trans(osb, OCFS2_INODE_UPDATE_CREDITS);
5783 +       if (IS_ERR(handle)) {
5784 +               status = PTR_ERR(handle);
5785 +               mlog_errno(status);
5786 +               goto bail_unlock;
5787 +       }
5788 +
5789 +       inode->i_flags = flags;
5790 +       inode->i_vflags = vflags;
5791 +       ocfs2_get_inode_flags(OCFS2_I(inode));
5792 +
5793 +       status = ocfs2_mark_inode_dirty(handle, inode, bh);
5794 +       if (status < 0)
5795 +               mlog_errno(status);
5796 +
5797 +       ocfs2_commit_trans(osb, handle);
5798 +bail_unlock:
5799 +       ocfs2_inode_unlock(inode, 1);
5800 +       brelse(bh);
5801 +       return status;
5802 +}
5803 +
5804 +int ocfs2_set_inode_attr(struct inode *inode, unsigned flags,
5805                                 unsigned mask)
5806  {
5807         struct ocfs2_inode_info *ocfs2_inode = OCFS2_I(inode);
5808 @@ -101,6 +135,11 @@ static int ocfs2_set_inode_attr(struct i
5809         if (!S_ISDIR(inode->i_mode))
5810                 flags &= ~OCFS2_DIRSYNC_FL;
5811  
5812 +       if (IS_BARRIER(inode)) {
5813 +               vxwprintk_task(1, "messing with the barrier.");
5814 +               goto bail_unlock;
5815 +       }
5816 +
5817         handle = ocfs2_start_trans(osb, OCFS2_INODE_UPDATE_CREDITS);
5818         if (IS_ERR(handle)) {
5819                 status = PTR_ERR(handle);
5820 @@ -879,6 +918,7 @@ bail:
5821         return status;
5822  }
5823  
5824 +
5825  long ocfs2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
5826  {
5827         struct inode *inode = filp->f_path.dentry->d_inode;
5828 diff -NurpP --minimal linux-3.6/fs/ocfs2/namei.c linux-3.6-vs2.3.4.3-noxfs-nocow/fs/ocfs2/namei.c
5829 --- linux-3.6/fs/ocfs2/namei.c  2012-10-04 15:27:41.000000000 +0200
5830 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/fs/ocfs2/namei.c    2012-10-04 18:47:00.000000000 +0200
5831 @@ -41,6 +41,7 @@
5832  #include <linux/slab.h>
5833  #include <linux/highmem.h>
5834  #include <linux/quotaops.h>
5835 +#include <linux/vs_tag.h>
5836  
5837  #include <cluster/masklog.h>
5838  
5839 @@ -475,6 +476,7 @@ static int __ocfs2_mknod_locked(struct i
5840         struct ocfs2_dinode *fe = NULL;
5841         struct ocfs2_extent_list *fel;
5842         u16 feat;
5843 +       tag_t tag;
5844  
5845         *new_fe_bh = NULL;
5846  
5847 @@ -512,8 +514,11 @@ static int __ocfs2_mknod_locked(struct i
5848         fe->i_suballoc_loc = cpu_to_le64(suballoc_loc);
5849         fe->i_suballoc_bit = cpu_to_le16(suballoc_bit);
5850         fe->i_suballoc_slot = cpu_to_le16(inode_ac->ac_alloc_slot);
5851 -       fe->i_uid = cpu_to_le32(inode->i_uid);
5852 -       fe->i_gid = cpu_to_le32(inode->i_gid);
5853 +
5854 +       tag = dx_current_fstag(osb->sb);
5855 +       fe->i_uid = cpu_to_le32(TAGINO_UID(DX_TAG(inode), inode->i_uid, tag));
5856 +       fe->i_gid = cpu_to_le32(TAGINO_GID(DX_TAG(inode), inode->i_gid, tag));
5857 +       inode->i_tag = tag;
5858         fe->i_mode = cpu_to_le16(inode->i_mode);
5859         if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode))
5860                 fe->id1.dev1.i_rdev = cpu_to_le64(huge_encode_dev(dev));
5861 diff -NurpP --minimal linux-3.6/fs/ocfs2/ocfs2.h linux-3.6-vs2.3.4.3-noxfs-nocow/fs/ocfs2/ocfs2.h
5862 --- linux-3.6/fs/ocfs2/ocfs2.h  2012-01-09 16:14:55.000000000 +0100
5863 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/fs/ocfs2/ocfs2.h    2012-10-04 18:47:00.000000000 +0200
5864 @@ -272,6 +272,7 @@ enum ocfs2_mount_options
5865                                                      writes */
5866         OCFS2_MOUNT_HB_NONE = 1 << 13, /* No heartbeat */
5867         OCFS2_MOUNT_HB_GLOBAL = 1 << 14, /* Global heartbeat */
5868 +       OCFS2_MOUNT_TAGGED = 1 << 15, /* use tagging */
5869  };
5870  
5871  #define OCFS2_OSB_SOFT_RO                      0x0001
5872 diff -NurpP --minimal linux-3.6/fs/ocfs2/ocfs2_fs.h linux-3.6-vs2.3.4.3-noxfs-nocow/fs/ocfs2/ocfs2_fs.h
5873 --- linux-3.6/fs/ocfs2/ocfs2_fs.h       2011-05-22 16:17:53.000000000 +0200
5874 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/fs/ocfs2/ocfs2_fs.h 2012-10-04 18:47:00.000000000 +0200
5875 @@ -266,6 +266,11 @@
5876  #define OCFS2_TOPDIR_FL                        FS_TOPDIR_FL    /* Top of directory hierarchies*/
5877  #define OCFS2_RESERVED_FL              FS_RESERVED_FL  /* reserved for ext2 lib */
5878  
5879 +#define OCFS2_IXUNLINK_FL              FS_IXUNLINK_FL  /* Immutable invert on unlink */
5880 +
5881 +#define OCFS2_BARRIER_FL               FS_BARRIER_FL   /* Barrier for chroot() */
5882 +#define OCFS2_COW_FL                   FS_COW_FL       /* Copy on Write marker */
5883 +
5884  #define OCFS2_FL_VISIBLE               FS_FL_USER_VISIBLE      /* User visible flags */
5885  #define OCFS2_FL_MODIFIABLE            FS_FL_USER_MODIFIABLE   /* User modifiable flags */
5886  
5887 diff -NurpP --minimal linux-3.6/fs/ocfs2/super.c linux-3.6-vs2.3.4.3-noxfs-nocow/fs/ocfs2/super.c
5888 --- linux-3.6/fs/ocfs2/super.c  2012-05-21 18:07:26.000000000 +0200
5889 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/fs/ocfs2/super.c    2012-10-04 18:47:00.000000000 +0200
5890 @@ -185,6 +185,7 @@ enum {
5891         Opt_coherency_full,
5892         Opt_resv_level,
5893         Opt_dir_resv_level,
5894 +       Opt_tag, Opt_notag, Opt_tagid,
5895         Opt_err,
5896  };
5897  
5898 @@ -216,6 +217,9 @@ static const match_table_t tokens = {
5899         {Opt_coherency_full, "coherency=full"},
5900         {Opt_resv_level, "resv_level=%u"},
5901         {Opt_dir_resv_level, "dir_resv_level=%u"},
5902 +       {Opt_tag, "tag"},
5903 +       {Opt_notag, "notag"},
5904 +       {Opt_tagid, "tagid=%u"},
5905         {Opt_err, NULL}
5906  };
5907  
5908 @@ -662,6 +666,13 @@ static int ocfs2_remount(struct super_bl
5909                 goto out;
5910         }
5911  
5912 +       if ((osb->s_mount_opt & OCFS2_MOUNT_TAGGED) !=
5913 +           (parsed_options.mount_opt & OCFS2_MOUNT_TAGGED)) {
5914 +               ret = -EINVAL;
5915 +               mlog(ML_ERROR, "Cannot change tagging on remount\n");
5916 +               goto out;
5917 +       }
5918 +
5919         /* We're going to/from readonly mode. */
5920         if ((*flags & MS_RDONLY) != (sb->s_flags & MS_RDONLY)) {
5921                 /* Disable quota accounting before remounting RO */
5922 @@ -1177,6 +1188,9 @@ static int ocfs2_fill_super(struct super
5923  
5924         ocfs2_complete_mount_recovery(osb);
5925  
5926 +       if (osb->s_mount_opt & OCFS2_MOUNT_TAGGED)
5927 +               sb->s_flags |= MS_TAGGED;
5928 +
5929         if (ocfs2_mount_local(osb))
5930                 snprintf(nodestr, sizeof(nodestr), "local");
5931         else
5932 @@ -1503,6 +1517,20 @@ static int ocfs2_parse_options(struct su
5933                             option < OCFS2_MAX_RESV_LEVEL)
5934                                 mopt->dir_resv_level = option;
5935                         break;
5936 +#ifndef CONFIG_TAGGING_NONE
5937 +               case Opt_tag:
5938 +                       mopt->mount_opt |= OCFS2_MOUNT_TAGGED;
5939 +                       break;
5940 +               case Opt_notag:
5941 +                       mopt->mount_opt &= ~OCFS2_MOUNT_TAGGED;
5942 +                       break;
5943 +#endif
5944 +#ifdef CONFIG_PROPAGATE
5945 +               case Opt_tagid:
5946 +                       /* use args[0] */
5947 +                       mopt->mount_opt |= OCFS2_MOUNT_TAGGED;
5948 +                       break;
5949 +#endif
5950                 default:
5951                         mlog(ML_ERROR,
5952                              "Unrecognized mount option \"%s\" "
5953 diff -NurpP --minimal linux-3.6/fs/open.c linux-3.6-vs2.3.4.3-noxfs-nocow/fs/open.c
5954 --- linux-3.6/fs/open.c 2012-10-04 15:27:41.000000000 +0200
5955 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/fs/open.c   2012-10-04 18:47:00.000000000 +0200
5956 @@ -30,6 +30,11 @@
5957  #include <linux/fs_struct.h>
5958  #include <linux/ima.h>
5959  #include <linux/dnotify.h>
5960 +#include <linux/vs_base.h>
5961 +#include <linux/vs_limit.h>
5962 +#include <linux/vs_tag.h>
5963 +#include <linux/vs_cowbl.h>
5964 +#include <linux/vserver/dlimit.h>
5965  
5966  #include "internal.h"
5967  
5968 @@ -74,6 +79,12 @@ static long do_sys_truncate(const char _
5969         error = user_path(pathname, &path);
5970         if (error)
5971                 goto out;
5972 +
5973 +#ifdef CONFIG_VSERVER_COWBL
5974 +       error = cow_check_and_break(&path);
5975 +       if (error)
5976 +               goto dput_and_out;
5977 +#endif
5978         inode = path.dentry->d_inode;
5979  
5980         /* For directories it's -EISDIR, for other non-regulars - -EINVAL */
5981 @@ -495,6 +506,10 @@ SYSCALL_DEFINE3(fchmodat, int, dfd, cons
5982  
5983         error = user_path_at(dfd, filename, LOOKUP_FOLLOW, &path);
5984         if (!error) {
5985 +#ifdef CONFIG_VSERVER_COWBL
5986 +               error = cow_check_and_break(&path);
5987 +               if (!error)
5988 +#endif
5989                 error = chmod_common(&path, mode);
5990                 path_put(&path);
5991         }
5992 @@ -522,13 +537,13 @@ static int chown_common(struct path *pat
5993                 if (!uid_valid(uid))
5994                         return -EINVAL;
5995                 newattrs.ia_valid |= ATTR_UID;
5996 -               newattrs.ia_uid = uid;
5997 +               newattrs.ia_uid = 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 = dx_map_gid(group);
6005         }
6006         if (!S_ISDIR(inode->i_mode))
6007                 newattrs.ia_valid |=
6008 @@ -561,6 +576,18 @@ SYSCALL_DEFINE5(fchownat, int, dfd, cons
6009         error = mnt_want_write(path.mnt);
6010         if (error)
6011                 goto out_release;
6012 +#ifdef CONFIG_VSERVER_COWBL
6013 +       error = cow_check_and_break(&path);
6014 +       if (!error)
6015 +#endif
6016 +#ifdef CONFIG_VSERVER_COWBL
6017 +       error = cow_check_and_break(&path);
6018 +       if (!error)
6019 +#endif
6020 +#ifdef CONFIG_VSERVER_COWBL
6021 +       error = cow_check_and_break(&path);
6022 +       if (!error)
6023 +#endif
6024         error = chown_common(&path, user, group);
6025         mnt_drop_write(path.mnt);
6026  out_release:
6027 @@ -809,6 +836,7 @@ static void __put_unused_fd(struct files
6028         __clear_open_fd(fd, fdt);
6029         if (fd < files->next_fd)
6030                 files->next_fd = fd;
6031 +       vx_openfd_dec(fd);
6032  }
6033  
6034  void put_unused_fd(unsigned int fd)
6035 diff -NurpP --minimal linux-3.6/fs/proc/array.c linux-3.6-vs2.3.4.3-noxfs-nocow/fs/proc/array.c
6036 --- linux-3.6/fs/proc/array.c   2012-07-22 23:39:42.000000000 +0200
6037 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/fs/proc/array.c     2012-10-04 18:47:00.000000000 +0200
6038 @@ -82,6 +82,8 @@
6039  #include <linux/ptrace.h>
6040  #include <linux/tracehook.h>
6041  #include <linux/user_namespace.h>
6042 +#include <linux/vs_context.h>
6043 +#include <linux/vs_network.h>
6044  
6045  #include <asm/pgtable.h>
6046  #include <asm/processor.h>
6047 @@ -172,6 +174,9 @@ static inline void task_state(struct seq
6048         rcu_read_lock();
6049         ppid = pid_alive(p) ?
6050                 task_tgid_nr_ns(rcu_dereference(p->real_parent), ns) : 0;
6051 +       if (unlikely(vx_current_initpid(p->pid)))
6052 +               ppid = 0;
6053 +
6054         tpid = 0;
6055         if (pid_alive(p)) {
6056                 struct task_struct *tracer = ptrace_parent(p);
6057 @@ -296,7 +301,7 @@ static inline void task_sig(struct seq_f
6058  }
6059  
6060  static void render_cap_t(struct seq_file *m, const char *header,
6061 -                       kernel_cap_t *a)
6062 +                       struct vx_info *vxi, kernel_cap_t *a)
6063  {
6064         unsigned __capi;
6065  
6066 @@ -321,10 +326,11 @@ static inline void task_cap(struct seq_f
6067         cap_bset        = cred->cap_bset;
6068         rcu_read_unlock();
6069  
6070 -       render_cap_t(m, "CapInh:\t", &cap_inheritable);
6071 -       render_cap_t(m, "CapPrm:\t", &cap_permitted);
6072 -       render_cap_t(m, "CapEff:\t", &cap_effective);
6073 -       render_cap_t(m, "CapBnd:\t", &cap_bset);
6074 +       /* FIXME: maybe move the p->vx_info masking to __task_cred() ? */
6075 +       render_cap_t(m, "CapInh:\t", p->vx_info, &cap_inheritable);
6076 +       render_cap_t(m, "CapPrm:\t", p->vx_info, &cap_permitted);
6077 +       render_cap_t(m, "CapEff:\t", p->vx_info, &cap_effective);
6078 +       render_cap_t(m, "CapBnd:\t", p->vx_info, &cap_bset);
6079  }
6080  
6081  static inline void task_context_switch_counts(struct seq_file *m,
6082 @@ -346,6 +352,42 @@ static void task_cpus_allowed(struct seq
6083         seq_putc(m, '\n');
6084  }
6085  
6086 +int proc_pid_nsproxy(struct seq_file *m, struct pid_namespace *ns,
6087 +                       struct pid *pid, struct task_struct *task)
6088 +{
6089 +       seq_printf(m,   "Proxy:\t%p(%c)\n"
6090 +                       "Count:\t%u\n"
6091 +                       "uts:\t%p(%c)\n"
6092 +                       "ipc:\t%p(%c)\n"
6093 +                       "mnt:\t%p(%c)\n"
6094 +                       "pid:\t%p(%c)\n"
6095 +                       "net:\t%p(%c)\n",
6096 +                       task->nsproxy,
6097 +                       (task->nsproxy == init_task.nsproxy ? 'I' : '-'),
6098 +                       atomic_read(&task->nsproxy->count),
6099 +                       task->nsproxy->uts_ns,
6100 +                       (task->nsproxy->uts_ns == init_task.nsproxy->uts_ns ? 'I' : '-'),
6101 +                       task->nsproxy->ipc_ns,
6102 +                       (task->nsproxy->ipc_ns == init_task.nsproxy->ipc_ns ? 'I' : '-'),
6103 +                       task->nsproxy->mnt_ns,
6104 +                       (task->nsproxy->mnt_ns == init_task.nsproxy->mnt_ns ? 'I' : '-'),
6105 +                       task->nsproxy->pid_ns,
6106 +                       (task->nsproxy->pid_ns == init_task.nsproxy->pid_ns ? 'I' : '-'),
6107 +                       task->nsproxy->net_ns,
6108 +                       (task->nsproxy->net_ns == init_task.nsproxy->net_ns ? 'I' : '-'));
6109 +       return 0;
6110 +}
6111 +
6112 +void task_vs_id(struct seq_file *m, struct task_struct *task)
6113 +{
6114 +       if (task_vx_flags(task, VXF_HIDE_VINFO, 0))
6115 +               return;
6116 +
6117 +       seq_printf(m, "VxID: %d\n", vx_task_xid(task));
6118 +       seq_printf(m, "NxID: %d\n", nx_task_nid(task));
6119 +}
6120 +
6121 +
6122  int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
6123                         struct pid *pid, struct task_struct *task)
6124  {
6125 @@ -362,6 +404,7 @@ int proc_pid_status(struct seq_file *m, 
6126         task_cap(m, task);
6127         task_cpus_allowed(m, task);
6128         cpuset_task_status_allowed(m, task);
6129 +       task_vs_id(m, task);
6130         task_context_switch_counts(m, task);
6131         return 0;
6132  }
6133 @@ -471,6 +514,17 @@ static int do_task_stat(struct seq_file 
6134         /* convert nsec -> ticks */
6135         start_time = nsec_to_clock_t(start_time);
6136  
6137 +       /* fixup start time for virt uptime */
6138 +       if (vx_flags(VXF_VIRT_UPTIME, 0)) {
6139 +               unsigned long long bias =
6140 +                       current->vx_info->cvirt.bias_clock;
6141 +
6142 +               if (start_time > bias)
6143 +                       start_time -= bias;
6144 +               else
6145 +                       start_time = 0;
6146 +       }
6147 +
6148         seq_printf(m, "%d (%s) %c", pid_nr_ns(pid, ns), tcomm, state);
6149         seq_put_decimal_ll(m, ' ', ppid);
6150         seq_put_decimal_ll(m, ' ', pgid);
6151 diff -NurpP --minimal linux-3.6/fs/proc/base.c linux-3.6-vs2.3.4.3-noxfs-nocow/fs/proc/base.c
6152 --- linux-3.6/fs/proc/base.c    2012-10-04 15:27:41.000000000 +0200
6153 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/fs/proc/base.c      2012-10-04 18:47:00.000000000 +0200
6154 @@ -85,6 +85,8 @@
6155  #include <linux/fs_struct.h>
6156  #include <linux/slab.h>
6157  #include <linux/flex_array.h>
6158 +#include <linux/vs_context.h>
6159 +#include <linux/vs_network.h>
6160  #ifdef CONFIG_HARDWALL
6161  #include <asm/hardwall.h>
6162  #endif
6163 @@ -941,11 +943,16 @@ static ssize_t oom_adjust_write(struct f
6164                 goto err_task_lock;
6165         }
6166  
6167 -       if (oom_adjust < task->signal->oom_adj && !capable(CAP_SYS_RESOURCE)) {
6168 +       if (oom_adjust < task->signal->oom_adj &&
6169 +               !vx_capable(CAP_SYS_RESOURCE, VXC_OOM_ADJUST)) {
6170                 err = -EACCES;
6171                 goto err_sighand;
6172         }
6173  
6174 +       /* prevent guest processes from circumventing the oom killer */
6175 +       if (vx_current_xid() && (oom_adjust == OOM_DISABLE))
6176 +               oom_adjust = OOM_ADJUST_MIN;
6177 +
6178         /*
6179          * Warn that /proc/pid/oom_adj is deprecated, see
6180          * Documentation/feature-removal-schedule.txt.
6181 @@ -1548,6 +1555,8 @@ struct inode *proc_pid_make_inode(struct
6182                 inode->i_gid = cred->egid;
6183                 rcu_read_unlock();
6184         }
6185 +       /* procfs is xid tagged */
6186 +       inode->i_tag = (tag_t)vx_task_xid(task);
6187         security_task_to_inode(task, inode);
6188  
6189  out:
6190 @@ -1593,6 +1602,8 @@ int pid_getattr(struct vfsmount *mnt, st
6191  
6192  /* dentry stuff */
6193  
6194 +static unsigned name_to_int(struct dentry *dentry);
6195 +
6196  /*
6197   *     Exceptional case: normally we are not allowed to unhash a busy
6198   * directory. In this case, however, we can do it - no aliasing problems
6199 @@ -1621,6 +1632,12 @@ int pid_revalidate(struct dentry *dentry
6200         task = get_proc_task(inode);
6201  
6202         if (task) {
6203 +               unsigned pid = name_to_int(dentry);
6204 +
6205 +               if (pid != ~0U && pid != vx_map_pid(task->pid)) {
6206 +                       put_task_struct(task);
6207 +                       goto drop;
6208 +               }
6209                 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
6210                     task_dumpable(task)) {
6211                         rcu_read_lock();
6212 @@ -1637,6 +1654,7 @@ int pid_revalidate(struct dentry *dentry
6213                 put_task_struct(task);
6214                 return 1;
6215         }
6216 +drop:
6217         d_drop(dentry);
6218         return 0;
6219  }
6220 @@ -2457,6 +2475,13 @@ static struct dentry *proc_pident_lookup
6221         if (!task)
6222                 goto out_no_task;
6223  
6224 +       /* TODO: maybe we can come up with a generic approach? */
6225 +       if (task_vx_flags(task, VXF_HIDE_VINFO, 0) &&
6226 +               (dentry->d_name.len == 5) &&
6227 +               (!memcmp(dentry->d_name.name, "vinfo", 5) ||
6228 +               !memcmp(dentry->d_name.name, "ninfo", 5)))
6229 +               goto out;
6230 +
6231         /*
6232          * Yes, it does not scale. And it should not. Don't add
6233          * new entries into /proc/<tgid>/ without very good reasons.
6234 @@ -2842,7 +2867,7 @@ out_iput:
6235  static struct dentry *proc_base_lookup(struct inode *dir, struct dentry *dentry)
6236  {
6237         struct dentry *error;
6238 -       struct task_struct *task = get_proc_task(dir);
6239 +       struct task_struct *task = get_proc_task_real(dir);
6240         const struct pid_entry *p, *last;
6241  
6242         error = ERR_PTR(-ENOENT);
6243 @@ -3017,6 +3042,9 @@ static int proc_pid_personality(struct s
6244  static const struct file_operations proc_task_operations;
6245  static const struct inode_operations proc_task_inode_operations;
6246  
6247 +extern int proc_pid_vx_info(struct task_struct *, char *);
6248 +extern int proc_pid_nx_info(struct task_struct *, char *);
6249 +
6250  static const struct pid_entry tgid_base_stuff[] = {
6251         DIR("task",       S_IRUGO|S_IXUGO, proc_task_inode_operations, proc_task_operations),
6252         DIR("fd",         S_IRUSR|S_IXUSR, proc_fd_inode_operations, proc_fd_operations),
6253 @@ -3083,6 +3111,8 @@ static const struct pid_entry tgid_base_
6254  #ifdef CONFIG_CGROUPS
6255         REG("cgroup",  S_IRUGO, proc_cgroup_operations),
6256  #endif
6257 +       INF("vinfo",      S_IRUGO, proc_pid_vx_info),
6258 +       INF("ninfo",      S_IRUGO, proc_pid_nx_info),
6259         INF("oom_score",  S_IRUGO, proc_oom_score),
6260         REG("oom_adj",    S_IRUGO|S_IWUSR, proc_oom_adjust_operations),
6261         REG("oom_score_adj", S_IRUGO|S_IWUSR, proc_oom_score_adj_operations),
6262 @@ -3106,6 +3136,7 @@ static const struct pid_entry tgid_base_
6263         REG("uid_map",    S_IRUGO|S_IWUSR, proc_uid_map_operations),
6264         REG("gid_map",    S_IRUGO|S_IWUSR, proc_gid_map_operations),
6265  #endif
6266 +       ONE("nsproxy",  S_IRUGO, proc_pid_nsproxy),
6267  };
6268  
6269  static int proc_tgid_base_readdir(struct file * filp,
6270 @@ -3300,7 +3331,7 @@ retry:
6271         iter.task = NULL;
6272         pid = find_ge_pid(iter.tgid, ns);
6273         if (pid) {
6274 -               iter.tgid = pid_nr_ns(pid, ns);
6275 +               iter.tgid = pid_unmapped_nr_ns(pid, ns);
6276                 iter.task = pid_task(pid, PIDTYPE_PID);
6277                 /* What we to know is if the pid we have find is the
6278                  * pid of a thread_group_leader.  Testing for task
6279 @@ -3330,7 +3361,7 @@ static int proc_pid_fill_cache(struct fi
6280         struct tgid_iter iter)
6281  {
6282         char name[PROC_NUMBUF];
6283 -       int len = snprintf(name, sizeof(name), "%d", iter.tgid);
6284 +       int len = snprintf(name, sizeof(name), "%d", vx_map_tgid(iter.tgid));
6285         return proc_fill_cache(filp, dirent, filldir, name, len,
6286                                 proc_pid_instantiate, iter.task, NULL);
6287  }
6288 @@ -3354,7 +3385,7 @@ int proc_pid_readdir(struct file * filp,
6289                 goto out_no_task;
6290         nr = filp->f_pos - FIRST_PROCESS_ENTRY;
6291  
6292 -       reaper = get_proc_task(filp->f_path.dentry->d_inode);
6293 +       reaper = get_proc_task_real(filp->f_path.dentry->d_inode);
6294         if (!reaper)
6295                 goto out_no_task;
6296  
6297 @@ -3376,6 +3407,8 @@ int proc_pid_readdir(struct file * filp,
6298                         __filldir = fake_filldir;
6299  
6300                 filp->f_pos = iter.tgid + TGID_OFFSET;
6301 +               if (!vx_proc_task_visible(iter.task))
6302 +                       continue;
6303                 if (proc_pid_fill_cache(filp, dirent, __filldir, iter) < 0) {
6304                         put_task_struct(iter.task);
6305                         goto out;
6306 @@ -3537,6 +3570,8 @@ static struct dentry *proc_task_lookup(s
6307         tid = name_to_int(dentry);
6308         if (tid == ~0U)
6309                 goto out;
6310 +       if (vx_current_initpid(tid))
6311 +               goto out;
6312  
6313         ns = dentry->d_sb->s_fs_info;
6314         rcu_read_lock();
6315 diff -NurpP --minimal linux-3.6/fs/proc/generic.c linux-3.6-vs2.3.4.3-noxfs-nocow/fs/proc/generic.c
6316 --- linux-3.6/fs/proc/generic.c 2012-10-04 15:27:41.000000000 +0200
6317 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/fs/proc/generic.c   2012-10-04 18:47:00.000000000 +0200
6318 @@ -22,6 +22,7 @@
6319  #include <linux/bitops.h>
6320  #include <linux/spinlock.h>
6321  #include <linux/completion.h>
6322 +#include <linux/vserver/inode.h>
6323  #include <asm/uaccess.h>
6324  
6325  #include "internal.h"
6326 @@ -424,11 +425,15 @@ struct dentry *proc_lookup_de(struct pro
6327         for (de = de->subdir; de ; de = de->next) {
6328                 if (de->namelen != dentry->d_name.len)
6329                         continue;
6330 +               if (!vx_hide_check(0, de->vx_flags))
6331 +                       continue;
6332                 if (!memcmp(dentry->d_name.name, de->name, de->namelen)) {
6333                         pde_get(de);
6334                         spin_unlock(&proc_subdir_lock);
6335                         error = -EINVAL;
6336                         inode = proc_get_inode(dir->i_sb, de);
6337 +                       /* generic proc entries belong to the host */
6338 +                       inode->i_tag = 0;
6339                         goto out_unlock;
6340                 }
6341         }
6342 @@ -506,6 +511,8 @@ int proc_readdir_de(struct proc_dir_entr
6343  
6344                                 /* filldir passes info to user space */
6345                                 pde_get(de);
6346 +                               if (!vx_hide_check(0, de->vx_flags))
6347 +                                       goto skip;
6348                                 spin_unlock(&proc_subdir_lock);
6349                                 if (filldir(dirent, de->name, de->namelen, filp->f_pos,
6350                                             de->low_ino, de->mode >> 12) < 0) {
6351 @@ -513,6 +520,7 @@ int proc_readdir_de(struct proc_dir_entr
6352                                         goto out;
6353                                 }
6354                                 spin_lock(&proc_subdir_lock);
6355 +                       skip:
6356                                 filp->f_pos++;
6357                                 next = de->next;
6358                                 pde_put(de);
6359 @@ -626,6 +634,7 @@ static struct proc_dir_entry *__proc_cre
6360         ent->nlink = nlink;
6361         atomic_set(&ent->count, 1);
6362         ent->pde_users = 0;
6363 +       ent->vx_flags = IATTR_PROC_DEFAULT;
6364         spin_lock_init(&ent->pde_unload_lock);
6365         ent->pde_unload_completion = NULL;
6366         INIT_LIST_HEAD(&ent->pde_openers);
6367 @@ -649,7 +658,8 @@ struct proc_dir_entry *proc_symlink(cons
6368                                 kfree(ent->data);
6369                                 kfree(ent);
6370                                 ent = NULL;
6371 -                       }
6372 +                       } else
6373 +                               ent->vx_flags = IATTR_PROC_SYMLINK;
6374                 } else {
6375                         kfree(ent);
6376                         ent = NULL;
6377 diff -NurpP --minimal linux-3.6/fs/proc/inode.c linux-3.6-vs2.3.4.3-noxfs-nocow/fs/proc/inode.c
6378 --- linux-3.6/fs/proc/inode.c   2012-07-22 23:39:42.000000000 +0200
6379 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/fs/proc/inode.c     2012-10-04 18:47:00.000000000 +0200
6380 @@ -458,6 +458,8 @@ struct inode *proc_get_inode(struct supe
6381                         inode->i_uid = de->uid;
6382                         inode->i_gid = de->gid;
6383                 }
6384 +               if (de->vx_flags)
6385 +                       PROC_I(inode)->vx_flags = de->vx_flags;
6386                 if (de->size)
6387                         inode->i_size = de->size;
6388                 if (de->nlink)
6389 diff -NurpP --minimal linux-3.6/fs/proc/internal.h linux-3.6-vs2.3.4.3-noxfs-nocow/fs/proc/internal.h
6390 --- linux-3.6/fs/proc/internal.h        2012-10-04 15:27:41.000000000 +0200
6391 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/fs/proc/internal.h  2012-10-04 18:47:00.000000000 +0200
6392 @@ -10,6 +10,8 @@
6393   */
6394  
6395  #include <linux/proc_fs.h>
6396 +#include <linux/vs_pid.h>
6397 +
6398  struct  ctl_table_header;
6399  
6400  extern struct proc_dir_entry proc_root;
6401 @@ -52,6 +54,9 @@ extern int proc_pid_status(struct seq_fi
6402                                 struct pid *pid, struct task_struct *task);
6403  extern int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
6404                                 struct pid *pid, struct task_struct *task);
6405 +extern int proc_pid_nsproxy(struct seq_file *m, struct pid_namespace *ns,
6406 +                               struct pid *pid, struct task_struct *task);
6407 +
6408  extern loff_t mem_lseek(struct file *file, loff_t offset, int orig);
6409  
6410  extern const struct file_operations proc_tid_children_operations;
6411 @@ -81,11 +86,16 @@ static inline struct pid *proc_pid(struc
6412         return PROC_I(inode)->pid;
6413  }
6414  
6415 -static inline struct task_struct *get_proc_task(struct inode *inode)
6416 +static inline struct task_struct *get_proc_task_real(struct inode *inode)
6417  {
6418         return get_pid_task(proc_pid(inode), PIDTYPE_PID);
6419  }
6420  
6421 +static inline struct task_struct *get_proc_task(struct inode *inode)
6422 +{
6423 +       return vx_get_proc_task(inode, proc_pid(inode));
6424 +}
6425 +
6426  static inline int proc_fd(struct inode *inode)
6427  {
6428         return PROC_I(inode)->fd;
6429 diff -NurpP --minimal linux-3.6/fs/proc/loadavg.c linux-3.6-vs2.3.4.3-noxfs-nocow/fs/proc/loadavg.c
6430 --- linux-3.6/fs/proc/loadavg.c 2009-09-10 15:26:23.000000000 +0200
6431 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/fs/proc/loadavg.c   2012-10-04 18:47:00.000000000 +0200
6432 @@ -12,15 +12,27 @@
6433  
6434  static int loadavg_proc_show(struct seq_file *m, void *v)
6435  {
6436 +       unsigned long running;
6437 +       unsigned int threads;
6438         unsigned long avnrun[3];
6439  
6440         get_avenrun(avnrun, FIXED_1/200, 0);
6441  
6442 +       if (vx_flags(VXF_VIRT_LOAD, 0)) {
6443 +               struct vx_info *vxi = current_vx_info();
6444 +
6445 +               running = atomic_read(&vxi->cvirt.nr_running);
6446 +               threads = atomic_read(&vxi->cvirt.nr_threads);
6447 +       } else {
6448 +               running = nr_running();
6449 +               threads = nr_threads;
6450 +       }
6451 +
6452         seq_printf(m, "%lu.%02lu %lu.%02lu %lu.%02lu %ld/%d %d\n",
6453                 LOAD_INT(avnrun[0]), LOAD_FRAC(avnrun[0]),
6454                 LOAD_INT(avnrun[1]), LOAD_FRAC(avnrun[1]),
6455                 LOAD_INT(avnrun[2]), LOAD_FRAC(avnrun[2]),
6456 -               nr_running(), nr_threads,
6457 +               running, threads,
6458                 task_active_pid_ns(current)->last_pid);
6459         return 0;
6460  }
6461 diff -NurpP --minimal linux-3.6/fs/proc/meminfo.c linux-3.6-vs2.3.4.3-noxfs-nocow/fs/proc/meminfo.c
6462 --- linux-3.6/fs/proc/meminfo.c 2012-01-09 16:14:55.000000000 +0100
6463 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/fs/proc/meminfo.c   2012-10-04 18:47:00.000000000 +0200
6464 @@ -39,7 +39,8 @@ static int meminfo_proc_show(struct seq_
6465         allowed = ((totalram_pages - hugetlb_total_pages())
6466                 * sysctl_overcommit_ratio / 100) + total_swap_pages;
6467  
6468 -       cached = global_page_state(NR_FILE_PAGES) -
6469 +       cached = vx_flags(VXF_VIRT_MEM, 0) ?
6470 +               vx_vsi_cached(&i) : global_page_state(NR_FILE_PAGES) -
6471                         total_swapcache_pages - i.bufferram;
6472         if (cached < 0)
6473                 cached = 0;
6474 diff -NurpP --minimal linux-3.6/fs/proc/root.c linux-3.6-vs2.3.4.3-noxfs-nocow/fs/proc/root.c
6475 --- linux-3.6/fs/proc/root.c    2012-10-04 15:27:41.000000000 +0200
6476 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/fs/proc/root.c      2012-10-04 18:47:00.000000000 +0200
6477 @@ -19,9 +19,14 @@
6478  #include <linux/mount.h>
6479  #include <linux/pid_namespace.h>
6480  #include <linux/parser.h>
6481 +#include <linux/vserver/inode.h>
6482  
6483  #include "internal.h"
6484  
6485 +struct proc_dir_entry *proc_virtual;
6486 +
6487 +extern void proc_vx_init(void);
6488 +
6489  static int proc_test_super(struct super_block *sb, void *data)
6490  {
6491         return sb->s_fs_info == data;
6492 @@ -189,6 +194,7 @@ void __init proc_root_init(void)
6493  #endif
6494         proc_mkdir("bus", NULL);
6495         proc_sys_init();
6496 +       proc_vx_init();
6497  }
6498  
6499  static int proc_root_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat
6500 @@ -255,6 +261,7 @@ struct proc_dir_entry proc_root = {
6501         .proc_iops      = &proc_root_inode_operations, 
6502         .proc_fops      = &proc_root_operations,
6503         .parent         = &proc_root,
6504 +       .vx_flags       = IATTR_ADMIN | IATTR_WATCH,
6505         .name           = "/proc",
6506  };
6507  
6508 diff -NurpP --minimal linux-3.6/fs/proc/stat.c linux-3.6-vs2.3.4.3-noxfs-nocow/fs/proc/stat.c
6509 --- linux-3.6/fs/proc/stat.c    2012-05-21 18:07:26.000000000 +0200
6510 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/fs/proc/stat.c      2012-10-04 18:47:00.000000000 +0200
6511 @@ -9,6 +9,7 @@
6512  #include <linux/slab.h>
6513  #include <linux/time.h>
6514  #include <linux/irqnr.h>
6515 +#include <linux/vserver/cvirt.h>
6516  #include <asm/cputime.h>
6517  #include <linux/tick.h>
6518  
6519 @@ -86,6 +87,10 @@ static int show_stat(struct seq_file *p,
6520                 irq = softirq = steal = 0;
6521         guest = guest_nice = 0;
6522         getboottime(&boottime);
6523 +
6524 +       if (vx_flags(VXF_VIRT_UPTIME, 0))
6525 +               vx_vsi_boottime(&boottime);
6526 +
6527         jif = boottime.tv_sec;
6528  
6529         for_each_possible_cpu(i) {
6530 diff -NurpP --minimal linux-3.6/fs/proc/uptime.c linux-3.6-vs2.3.4.3-noxfs-nocow/fs/proc/uptime.c
6531 --- linux-3.6/fs/proc/uptime.c  2012-03-19 19:47:26.000000000 +0100
6532 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/fs/proc/uptime.c    2012-10-04 18:47:00.000000000 +0200
6533 @@ -5,6 +5,7 @@
6534  #include <linux/seq_file.h>
6535  #include <linux/time.h>
6536  #include <linux/kernel_stat.h>
6537 +#include <linux/vserver/cvirt.h>
6538  #include <asm/cputime.h>
6539  
6540  static int uptime_proc_show(struct seq_file *m, void *v)
6541 @@ -25,6 +26,10 @@ static int uptime_proc_show(struct seq_f
6542         nsec = cputime64_to_jiffies64(idletime) * TICK_NSEC;
6543         idle.tv_sec = div_u64_rem(nsec, NSEC_PER_SEC, &rem);
6544         idle.tv_nsec = rem;
6545 +
6546 +       if (vx_flags(VXF_VIRT_UPTIME, 0))
6547 +               vx_vsi_uptime(&uptime, &idle);
6548 +
6549         seq_printf(m, "%lu.%02lu %lu.%02lu\n",
6550                         (unsigned long) uptime.tv_sec,
6551                         (uptime.tv_nsec / (NSEC_PER_SEC / 100)),
6552 diff -NurpP --minimal linux-3.6/fs/proc_namespace.c linux-3.6-vs2.3.4.3-noxfs-nocow/fs/proc_namespace.c
6553 --- linux-3.6/fs/proc_namespace.c       2012-10-04 15:27:41.000000000 +0200
6554 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/fs/proc_namespace.c 2012-10-04 18:47:00.000000000 +0200
6555 @@ -44,6 +44,8 @@ static int show_sb_opts(struct seq_file 
6556                 { MS_SYNCHRONOUS, ",sync" },
6557                 { MS_DIRSYNC, ",dirsync" },
6558                 { MS_MANDLOCK, ",mand" },
6559 +               { MS_TAGGED, ",tag" },
6560 +               { MS_NOTAGCHECK, ",notagcheck" },
6561                 { 0, NULL }
6562         };
6563         const struct proc_fs_info *fs_infop;
6564 @@ -80,6 +82,34 @@ static inline void mangle(struct seq_fil
6565         seq_escape(m, s, " \t\n\\");
6566  }
6567  
6568 +static int mnt_is_reachable(struct vfsmount *vfsmnt)
6569 +{
6570 +       struct path root;
6571 +       struct dentry *point;
6572 +       struct mount *mnt = real_mount(vfsmnt);
6573 +       struct mount *root_mnt;
6574 +       int ret;
6575 +
6576 +       if (mnt == mnt->mnt_ns->root)
6577 +               return 1;
6578 +
6579 +       br_read_lock(&vfsmount_lock);
6580 +       root = current->fs->root;
6581 +       root_mnt = real_mount(root.mnt);
6582 +       point = root.dentry;
6583 +
6584 +       while ((mnt != mnt->mnt_parent) && (mnt != root_mnt)) {
6585 +               point = mnt->mnt_mountpoint;
6586 +               mnt = mnt->mnt_parent;
6587 +       }
6588 +
6589 +       ret = (mnt == root_mnt) && is_subdir(point, root.dentry);
6590 +
6591 +       br_read_unlock(&vfsmount_lock);
6592 +
6593 +       return ret;
6594 +}
6595 +
6596  static void show_type(struct seq_file *m, struct super_block *sb)
6597  {
6598         mangle(m, sb->s_type->name);
6599 @@ -96,6 +126,17 @@ static int show_vfsmnt(struct seq_file *
6600         struct path mnt_path = { .dentry = mnt->mnt_root, .mnt = mnt };
6601         struct super_block *sb = mnt_path.dentry->d_sb;
6602  
6603 +       if (vx_flags(VXF_HIDE_MOUNT, 0))
6604 +               return SEQ_SKIP;
6605 +       if (!mnt_is_reachable(mnt) && !vx_check(0, VS_WATCH_P))
6606 +               return SEQ_SKIP;
6607 +
6608 +       if (!vx_check(0, VS_ADMIN|VS_WATCH) &&
6609 +               mnt == current->fs->root.mnt) {
6610 +               seq_puts(m, "/dev/root / ");
6611 +               goto type;
6612 +       }
6613 +
6614         if (sb->s_op->show_devname) {
6615                 err = sb->s_op->show_devname(m, mnt_path.dentry);
6616                 if (err)
6617 @@ -106,6 +147,7 @@ static int show_vfsmnt(struct seq_file *
6618         seq_putc(m, ' ');
6619         seq_path(m, &mnt_path, " \t\n\\");
6620         seq_putc(m, ' ');
6621 +type:
6622         show_type(m, sb);
6623         seq_puts(m, __mnt_is_readonly(mnt) ? " ro" : " rw");
6624         err = show_sb_opts(m, sb);
6625 @@ -128,6 +170,11 @@ static int show_mountinfo(struct seq_fil
6626         struct path root = p->root;
6627         int err = 0;
6628  
6629 +       if (vx_flags(VXF_HIDE_MOUNT, 0))
6630 +               return SEQ_SKIP;
6631 +       if (!mnt_is_reachable(mnt) && !vx_check(0, VS_WATCH_P))
6632 +               return SEQ_SKIP;
6633 +
6634         seq_printf(m, "%i %i %u:%u ", r->mnt_id, r->mnt_parent->mnt_id,
6635                    MAJOR(sb->s_dev), MINOR(sb->s_dev));
6636         if (sb->s_op->show_path)
6637 @@ -187,6 +234,17 @@ static int show_vfsstat(struct seq_file 
6638         struct super_block *sb = mnt_path.dentry->d_sb;
6639         int err = 0;
6640  
6641 +       if (vx_flags(VXF_HIDE_MOUNT, 0))
6642 +               return SEQ_SKIP;
6643 +       if (!mnt_is_reachable(mnt) && !vx_check(0, VS_WATCH_P))
6644 +               return SEQ_SKIP;
6645 +
6646 +       if (!vx_check(0, VS_ADMIN|VS_WATCH) &&
6647 +               mnt == current->fs->root.mnt) {
6648 +               seq_puts(m, "device /dev/root mounted on / ");
6649 +               goto type;
6650 +       }
6651 +
6652         /* device */
6653         if (sb->s_op->show_devname) {
6654                 seq_puts(m, "device ");
6655 @@ -203,7 +261,7 @@ static int show_vfsstat(struct seq_file 
6656         seq_puts(m, " mounted on ");
6657         seq_path(m, &mnt_path, " \t\n\\");
6658         seq_putc(m, ' ');
6659 -
6660 +type:
6661         /* file system type */
6662         seq_puts(m, "with fstype ");
6663         show_type(m, sb);
6664 diff -NurpP --minimal linux-3.6/fs/quota/dquot.c linux-3.6-vs2.3.4.3-noxfs-nocow/fs/quota/dquot.c
6665 --- linux-3.6/fs/quota/dquot.c  2012-10-04 15:27:41.000000000 +0200
6666 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/fs/quota/dquot.c    2012-10-04 18:47:00.000000000 +0200
6667 @@ -1580,6 +1580,9 @@ int __dquot_alloc_space(struct inode *in
6668         struct dquot **dquots = inode->i_dquot;
6669         int reserve = flags & DQUOT_SPACE_RESERVE;
6670  
6671 +       if ((ret = dl_alloc_space(inode, number)))
6672 +               return ret;
6673 +
6674         /*
6675          * First test before acquiring mutex - solves deadlocks when we
6676          * re-enter the quota code and are already holding the mutex
6677 @@ -1635,6 +1638,9 @@ int dquot_alloc_inode(const struct inode
6678         struct dquot_warn warn[MAXQUOTAS];
6679         struct dquot * const *dquots = inode->i_dquot;
6680  
6681 +       if ((ret = dl_alloc_inode(inode)))
6682 +               return ret;
6683 +
6684         /* First test before acquiring mutex - solves deadlocks when we
6685           * re-enter the quota code and are already holding the mutex */
6686         if (!dquot_active(inode))
6687 @@ -1706,6 +1712,8 @@ void __dquot_free_space(struct inode *in
6688         struct dquot **dquots = inode->i_dquot;
6689         int reserve = flags & DQUOT_SPACE_RESERVE;
6690  
6691 +       dl_free_space(inode, number);
6692 +
6693         /* First test before acquiring mutex - solves deadlocks when we
6694           * re-enter the quota code and are already holding the mutex */
6695         if (!dquot_active(inode)) {
6696 @@ -1750,6 +1758,8 @@ void dquot_free_inode(const struct inode
6697         struct dquot_warn warn[MAXQUOTAS];
6698         struct dquot * const *dquots = inode->i_dquot;
6699  
6700 +       dl_free_inode(inode);
6701 +
6702         /* First test before acquiring mutex - solves deadlocks when we
6703           * re-enter the quota code and are already holding the mutex */
6704         if (!dquot_active(inode))
6705 diff -NurpP --minimal linux-3.6/fs/quota/quota.c linux-3.6-vs2.3.4.3-noxfs-nocow/fs/quota/quota.c
6706 --- linux-3.6/fs/quota/quota.c  2012-10-04 15:27:41.000000000 +0200
6707 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/fs/quota/quota.c    2012-10-04 18:47:00.000000000 +0200
6708 @@ -8,6 +8,7 @@
6709  #include <linux/fs.h>
6710  #include <linux/namei.h>
6711  #include <linux/slab.h>
6712 +#include <linux/vs_context.h>
6713  #include <asm/current.h>
6714  #include <linux/uaccess.h>
6715  #include <linux/kernel.h>
6716 @@ -37,7 +38,7 @@ static int check_quotactl_permission(str
6717                         break;
6718                 /*FALLTHROUGH*/
6719         default:
6720 -               if (!capable(CAP_SYS_ADMIN))
6721 +               if (!vx_capable(CAP_SYS_ADMIN, VXC_QUOTA_CTL))
6722                         return -EPERM;
6723         }
6724  
6725 @@ -291,6 +292,46 @@ static int do_quotactl(struct super_bloc
6726         }
6727  }
6728  
6729 +#if defined(CONFIG_BLK_DEV_VROOT) || defined(CONFIG_BLK_DEV_VROOT_MODULE)
6730 +
6731 +#include <linux/vroot.h>
6732 +#include <linux/major.h>
6733 +#include <linux/module.h>
6734 +#include <linux/kallsyms.h>
6735 +#include <linux/vserver/debug.h>
6736 +
6737 +static vroot_grb_func *vroot_get_real_bdev = NULL;
6738 +
6739 +static DEFINE_SPINLOCK(vroot_grb_lock);
6740 +
6741 +int register_vroot_grb(vroot_grb_func *func) {
6742 +       int ret = -EBUSY;
6743 +
6744 +       spin_lock(&vroot_grb_lock);
6745 +       if (!vroot_get_real_bdev) {
6746 +               vroot_get_real_bdev = func;
6747 +               ret = 0;
6748 +       }
6749 +       spin_unlock(&vroot_grb_lock);
6750 +       return ret;
6751 +}
6752 +EXPORT_SYMBOL(register_vroot_grb);
6753 +
6754 +int unregister_vroot_grb(vroot_grb_func *func) {
6755 +       int ret = -EINVAL;
6756 +
6757 +       spin_lock(&vroot_grb_lock);
6758 +       if (vroot_get_real_bdev) {
6759 +               vroot_get_real_bdev = NULL;
6760 +               ret = 0;
6761 +       }
6762 +       spin_unlock(&vroot_grb_lock);
6763 +       return ret;
6764 +}
6765 +EXPORT_SYMBOL(unregister_vroot_grb);
6766 +
6767 +#endif
6768 +
6769  /* Return 1 if 'cmd' will block on frozen filesystem */
6770  static int quotactl_cmd_write(int cmd)
6771  {
6772 @@ -323,6 +364,22 @@ static struct super_block *quotactl_bloc
6773         putname(tmp);
6774         if (IS_ERR(bdev))
6775                 return ERR_CAST(bdev);
6776 +#if defined(CONFIG_BLK_DEV_VROOT) || defined(CONFIG_BLK_DEV_VROOT_MODULE)
6777 +       if (bdev && bdev->bd_inode &&
6778 +                       imajor(bdev->bd_inode) == VROOT_MAJOR) {
6779 +               struct block_device *bdnew = (void *)-EINVAL;
6780 +
6781 +               if (vroot_get_real_bdev)
6782 +                       bdnew = vroot_get_real_bdev(bdev);
6783 +               else
6784 +                       vxdprintk(VXD_CBIT(misc, 0),
6785 +                                       "vroot_get_real_bdev not set");
6786 +               bdput(bdev);
6787 +               if (IS_ERR(bdnew))
6788 +                       return ERR_PTR(PTR_ERR(bdnew));
6789 +               bdev = bdnew;
6790 +       }
6791 +#endif
6792         if (quotactl_cmd_write(cmd))
6793                 sb = get_super_thawed(bdev);
6794         else
6795 diff -NurpP --minimal linux-3.6/fs/reiserfs/file.c linux-3.6-vs2.3.4.3-noxfs-nocow/fs/reiserfs/file.c
6796 --- linux-3.6/fs/reiserfs/file.c        2012-05-21 18:07:26.000000000 +0200
6797 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/fs/reiserfs/file.c  2012-10-04 18:47:00.000000000 +0200
6798 @@ -319,5 +319,6 @@ const struct inode_operations reiserfs_f
6799         .listxattr = reiserfs_listxattr,
6800         .removexattr = reiserfs_removexattr,
6801         .permission = reiserfs_permission,
6802 +       .sync_flags = reiserfs_sync_flags,
6803         .get_acl = reiserfs_get_acl,
6804  };
6805 diff -NurpP --minimal linux-3.6/fs/reiserfs/inode.c linux-3.6-vs2.3.4.3-noxfs-nocow/fs/reiserfs/inode.c
6806 --- linux-3.6/fs/reiserfs/inode.c       2012-10-04 15:27:41.000000000 +0200
6807 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/fs/reiserfs/inode.c 2012-10-04 18:47:00.000000000 +0200
6808 @@ -18,6 +18,7 @@
6809  #include <linux/writeback.h>
6810  #include <linux/quotaops.h>
6811  #include <linux/swap.h>
6812 +#include <linux/vs_tag.h>
6813  
6814  int reiserfs_commit_write(struct file *f, struct page *page,
6815                           unsigned from, unsigned to);
6816 @@ -1131,6 +1132,8 @@ static void init_inode(struct inode *ino
6817         struct buffer_head *bh;
6818         struct item_head *ih;
6819         __u32 rdev;
6820 +       uid_t uid;
6821 +       gid_t gid;
6822         //int version = ITEM_VERSION_1;
6823  
6824         bh = PATH_PLAST_BUFFER(path);
6825 @@ -1151,12 +1154,13 @@ static void init_inode(struct inode *ino
6826                     (struct stat_data_v1 *)B_I_PITEM(bh, ih);
6827                 unsigned long blocks;
6828  
6829 +               uid = sd_v1_uid(sd);
6830 +               gid = sd_v1_gid(sd);
6831 +
6832                 set_inode_item_key_version(inode, KEY_FORMAT_3_5);
6833                 set_inode_sd_version(inode, STAT_DATA_V1);
6834                 inode->i_mode = sd_v1_mode(sd);
6835                 set_nlink(inode, sd_v1_nlink(sd));
6836 -               inode->i_uid = sd_v1_uid(sd);
6837 -               inode->i_gid = sd_v1_gid(sd);
6838                 inode->i_size = sd_v1_size(sd);
6839                 inode->i_atime.tv_sec = sd_v1_atime(sd);
6840                 inode->i_mtime.tv_sec = sd_v1_mtime(sd);
6841 @@ -1198,11 +1202,12 @@ static void init_inode(struct inode *ino
6842                 // (directories and symlinks)
6843                 struct stat_data *sd = (struct stat_data *)B_I_PITEM(bh, ih);
6844  
6845 +               uid    = sd_v2_uid(sd);
6846 +               gid    = sd_v2_gid(sd);
6847 +
6848                 inode->i_mode = sd_v2_mode(sd);
6849                 set_nlink(inode, sd_v2_nlink(sd));
6850 -               inode->i_uid = sd_v2_uid(sd);
6851                 inode->i_size = sd_v2_size(sd);
6852 -               inode->i_gid = sd_v2_gid(sd);
6853                 inode->i_mtime.tv_sec = sd_v2_mtime(sd);
6854                 inode->i_atime.tv_sec = sd_v2_atime(sd);
6855                 inode->i_ctime.tv_sec = sd_v2_ctime(sd);
6856 @@ -1232,6 +1237,10 @@ static void init_inode(struct inode *ino
6857                 sd_attrs_to_i_attrs(sd_v2_attrs(sd), inode);
6858         }
6859  
6860 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
6861 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
6862 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid, 0);
6863 +
6864         pathrelse(path);
6865         if (S_ISREG(inode->i_mode)) {
6866                 inode->i_op = &reiserfs_file_inode_operations;
6867 @@ -1254,13 +1263,15 @@ static void init_inode(struct inode *ino
6868  static void inode2sd(void *sd, struct inode *inode, loff_t size)
6869  {
6870         struct stat_data *sd_v2 = (struct stat_data *)sd;
6871 +       uid_t uid = TAGINO_UID(DX_TAG(inode), inode->i_uid, inode->i_tag);
6872 +       gid_t gid = TAGINO_GID(DX_TAG(inode), inode->i_gid, inode->i_tag);
6873         __u16 flags;
6874  
6875 +       set_sd_v2_uid(sd_v2, uid);
6876 +       set_sd_v2_gid(sd_v2, gid);
6877         set_sd_v2_mode(sd_v2, inode->i_mode);
6878         set_sd_v2_nlink(sd_v2, inode->i_nlink);
6879 -       set_sd_v2_uid(sd_v2, inode->i_uid);
6880         set_sd_v2_size(sd_v2, size);
6881 -       set_sd_v2_gid(sd_v2, inode->i_gid);
6882         set_sd_v2_mtime(sd_v2, inode->i_mtime.tv_sec);
6883         set_sd_v2_atime(sd_v2, inode->i_atime.tv_sec);
6884         set_sd_v2_ctime(sd_v2, inode->i_ctime.tv_sec);
6885 @@ -2862,14 +2873,19 @@ int reiserfs_commit_write(struct file *f
6886  void sd_attrs_to_i_attrs(__u16 sd_attrs, struct inode *inode)
6887  {
6888         if (reiserfs_attrs(inode->i_sb)) {
6889 -               if (sd_attrs & REISERFS_SYNC_FL)
6890 -                       inode->i_flags |= S_SYNC;
6891 -               else
6892 -                       inode->i_flags &= ~S_SYNC;
6893                 if (sd_attrs & REISERFS_IMMUTABLE_FL)
6894                         inode->i_flags |= S_IMMUTABLE;
6895                 else
6896                         inode->i_flags &= ~S_IMMUTABLE;
6897 +               if (sd_attrs & REISERFS_IXUNLINK_FL)
6898 +                       inode->i_flags |= S_IXUNLINK;
6899 +               else
6900 +                       inode->i_flags &= ~S_IXUNLINK;
6901 +
6902 +               if (sd_attrs & REISERFS_SYNC_FL)
6903 +                       inode->i_flags |= S_SYNC;
6904 +               else
6905 +                       inode->i_flags &= ~S_SYNC;
6906                 if (sd_attrs & REISERFS_APPEND_FL)
6907                         inode->i_flags |= S_APPEND;
6908                 else
6909 @@ -2882,6 +2898,15 @@ void sd_attrs_to_i_attrs(__u16 sd_attrs,
6910                         REISERFS_I(inode)->i_flags |= i_nopack_mask;
6911                 else
6912                         REISERFS_I(inode)->i_flags &= ~i_nopack_mask;
6913 +
6914 +               if (sd_attrs & REISERFS_BARRIER_FL)
6915 +                       inode->i_vflags |= V_BARRIER;
6916 +               else
6917 +                       inode->i_vflags &= ~V_BARRIER;
6918 +               if (sd_attrs & REISERFS_COW_FL)
6919 +                       inode->i_vflags |= V_COW;
6920 +               else
6921 +                       inode->i_vflags &= ~V_COW;
6922         }
6923  }
6924  
6925 @@ -2892,6 +2917,11 @@ void i_attrs_to_sd_attrs(struct inode *i
6926                         *sd_attrs |= REISERFS_IMMUTABLE_FL;
6927                 else
6928                         *sd_attrs &= ~REISERFS_IMMUTABLE_FL;
6929 +               if (inode->i_flags & S_IXUNLINK)
6930 +                       *sd_attrs |= REISERFS_IXUNLINK_FL;
6931 +               else
6932 +                       *sd_attrs &= ~REISERFS_IXUNLINK_FL;
6933 +
6934                 if (inode->i_flags & S_SYNC)
6935                         *sd_attrs |= REISERFS_SYNC_FL;
6936                 else
6937 @@ -2904,6 +2934,15 @@ void i_attrs_to_sd_attrs(struct inode *i
6938                         *sd_attrs |= REISERFS_NOTAIL_FL;
6939                 else
6940                         *sd_attrs &= ~REISERFS_NOTAIL_FL;
6941 +
6942 +               if (inode->i_vflags & V_BARRIER)
6943 +                       *sd_attrs |= REISERFS_BARRIER_FL;
6944 +               else
6945 +                       *sd_attrs &= ~REISERFS_BARRIER_FL;
6946 +               if (inode->i_vflags & V_COW)
6947 +                       *sd_attrs |= REISERFS_COW_FL;
6948 +               else
6949 +                       *sd_attrs &= ~REISERFS_COW_FL;
6950         }
6951  }
6952  
6953 @@ -3149,7 +3188,8 @@ int reiserfs_setattr(struct dentry *dent
6954         }
6955  
6956         if ((ia_valid & ATTR_UID && attr->ia_uid != inode->i_uid) ||
6957 -           (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid)) {
6958 +           (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid) ||
6959 +           (ia_valid & ATTR_TAG && attr->ia_tag != inode->i_tag)) {
6960                 struct reiserfs_transaction_handle th;
6961                 int jbegin_count =
6962                     2 *
6963 @@ -3178,6 +3218,9 @@ int reiserfs_setattr(struct dentry *dent
6964                         inode->i_uid = attr->ia_uid;
6965                 if (attr->ia_valid & ATTR_GID)
6966                         inode->i_gid = attr->ia_gid;
6967 +                               if ((attr->ia_valid & ATTR_TAG) &&
6968 +                                       IS_TAGGED(inode))
6969 +                                       inode->i_tag = attr->ia_tag;
6970                 mark_inode_dirty(inode);
6971                 error = journal_end(&th, inode->i_sb, jbegin_count);
6972                 if (error)
6973 diff -NurpP --minimal linux-3.6/fs/reiserfs/ioctl.c linux-3.6-vs2.3.4.3-noxfs-nocow/fs/reiserfs/ioctl.c
6974 --- linux-3.6/fs/reiserfs/ioctl.c       2012-05-21 18:07:27.000000000 +0200
6975 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/fs/reiserfs/ioctl.c 2012-10-04 18:47:00.000000000 +0200
6976 @@ -11,6 +11,21 @@
6977  #include <linux/pagemap.h>
6978  #include <linux/compat.h>
6979  
6980 +
6981 +int reiserfs_sync_flags(struct inode *inode, int flags, int vflags)
6982 +{
6983 +       __u16 sd_attrs = 0;
6984 +
6985 +       inode->i_flags = flags;
6986 +       inode->i_vflags = vflags;
6987 +
6988 +       i_attrs_to_sd_attrs(inode, &sd_attrs);
6989 +       REISERFS_I(inode)->i_attrs = sd_attrs;
6990 +       inode->i_ctime = CURRENT_TIME_SEC;
6991 +       mark_inode_dirty(inode);
6992 +       return 0;
6993 +}
6994 +
6995  /*
6996   * reiserfs_ioctl - handler for ioctl for inode
6997   * supported commands:
6998 @@ -22,7 +37,7 @@
6999  long reiserfs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
7000  {
7001         struct inode *inode = filp->f_path.dentry->d_inode;
7002 -       unsigned int flags;
7003 +       unsigned int flags, oldflags;
7004         int err = 0;
7005  
7006         reiserfs_write_lock(inode->i_sb);
7007 @@ -47,6 +62,7 @@ long reiserfs_ioctl(struct file *filp, u
7008  
7009                 flags = REISERFS_I(inode)->i_attrs;
7010                 i_attrs_to_sd_attrs(inode, (__u16 *) & flags);
7011 +               flags &= REISERFS_FL_USER_VISIBLE;
7012                 err = put_user(flags, (int __user *)arg);
7013                 break;
7014         case REISERFS_IOC_SETFLAGS:{
7015 @@ -67,6 +83,10 @@ long reiserfs_ioctl(struct file *filp, u
7016                                 err = -EFAULT;
7017                                 goto setflags_out;
7018                         }
7019 +                       if (IS_BARRIER(inode)) {
7020 +                               vxwprintk_task(1, "messing with the barrier.");
7021 +                               return -EACCES;
7022 +                       }
7023                         /*
7024                          * Is it quota file? Do not allow user to mess with it
7025                          */
7026 @@ -91,6 +111,10 @@ long reiserfs_ioctl(struct file *filp, u
7027                                         goto setflags_out;
7028                                 }
7029                         }
7030 +
7031 +                       oldflags = REISERFS_I(inode)->i_attrs;
7032 +                       flags &= REISERFS_FL_USER_MODIFIABLE;
7033 +                       flags |= oldflags & ~REISERFS_FL_USER_MODIFIABLE;
7034                         sd_attrs_to_i_attrs(flags, inode);
7035                         REISERFS_I(inode)->i_attrs = flags;
7036                         inode->i_ctime = CURRENT_TIME_SEC;
7037 diff -NurpP --minimal linux-3.6/fs/reiserfs/namei.c linux-3.6-vs2.3.4.3-noxfs-nocow/fs/reiserfs/namei.c
7038 --- linux-3.6/fs/reiserfs/namei.c       2012-10-04 15:27:41.000000000 +0200
7039 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/fs/reiserfs/namei.c 2012-10-04 18:47:00.000000000 +0200
7040 @@ -18,6 +18,7 @@
7041  #include "acl.h"
7042  #include "xattr.h"
7043  #include <linux/quotaops.h>
7044 +#include <linux/vs_tag.h>
7045  
7046  #define INC_DIR_INODE_NLINK(i) if (i->i_nlink != 1) { inc_nlink(i); if (i->i_nlink >= REISERFS_LINK_MAX) set_nlink(i, 1); }
7047  #define DEC_DIR_INODE_NLINK(i) if (i->i_nlink != 1) drop_nlink(i);
7048 @@ -362,6 +363,7 @@ static struct dentry *reiserfs_lookup(st
7049         if (retval == IO_ERROR) {
7050                 return ERR_PTR(-EIO);
7051         }
7052 +               dx_propagate_tag(nd, inode);
7053  
7054         return d_splice_alias(inode, dentry);
7055  }
7056 diff -NurpP --minimal linux-3.6/fs/reiserfs/reiserfs.h linux-3.6-vs2.3.4.3-noxfs-nocow/fs/reiserfs/reiserfs.h
7057 --- linux-3.6/fs/reiserfs/reiserfs.h    2012-07-22 23:39:42.000000000 +0200
7058 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/fs/reiserfs/reiserfs.h      2012-10-04 18:47:00.000000000 +0200
7059 @@ -549,6 +549,7 @@ enum reiserfs_mount_options {
7060         REISERFS_EXPOSE_PRIVROOT,
7061         REISERFS_BARRIER_NONE,
7062         REISERFS_BARRIER_FLUSH,
7063 +       REISERFS_TAGGED,
7064  
7065         /* Actions on error */
7066         REISERFS_ERROR_PANIC,
7067 @@ -1548,6 +1549,11 @@ struct stat_data_v1 {
7068  #define REISERFS_COMPR_FL     FS_COMPR_FL
7069  #define REISERFS_NOTAIL_FL    FS_NOTAIL_FL
7070  
7071 +/* unfortunately reiserfs sdattr is only 16 bit */
7072 +#define REISERFS_IXUNLINK_FL  (FS_IXUNLINK_FL >> 16)
7073 +#define REISERFS_BARRIER_FL   (FS_BARRIER_FL >> 16)
7074 +#define REISERFS_COW_FL       (FS_COW_FL >> 16)
7075 +
7076  /* persistent flags that file inherits from the parent directory */
7077  #define REISERFS_INHERIT_MASK ( REISERFS_IMMUTABLE_FL |        \
7078                                 REISERFS_SYNC_FL |      \
7079 @@ -1557,6 +1563,9 @@ struct stat_data_v1 {
7080                                 REISERFS_COMPR_FL |     \
7081                                 REISERFS_NOTAIL_FL )
7082  
7083 +#define REISERFS_FL_USER_VISIBLE       0x80FF
7084 +#define REISERFS_FL_USER_MODIFIABLE    0x80FF
7085 +
7086  /* Stat Data on disk (reiserfs version of UFS disk inode minus the
7087     address blocks) */
7088  struct stat_data {
7089 @@ -2647,6 +2656,7 @@ static inline void reiserfs_update_sd(st
7090  void sd_attrs_to_i_attrs(__u16 sd_attrs, struct inode *inode);
7091  void i_attrs_to_sd_attrs(struct inode *inode, __u16 * sd_attrs);
7092  int reiserfs_setattr(struct dentry *dentry, struct iattr *attr);
7093 +int reiserfs_sync_flags(struct inode *inode, int, int);
7094  
7095  int __reiserfs_write_begin(struct page *page, unsigned from, unsigned len);
7096  
7097 diff -NurpP --minimal linux-3.6/fs/reiserfs/super.c linux-3.6-vs2.3.4.3-noxfs-nocow/fs/reiserfs/super.c
7098 --- linux-3.6/fs/reiserfs/super.c       2012-10-04 15:27:41.000000000 +0200
7099 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/fs/reiserfs/super.c 2012-10-04 18:47:00.000000000 +0200
7100 @@ -1018,6 +1018,14 @@ static int reiserfs_parse_options(struct
7101                 {"user_xattr",.setmask = 1 << REISERFS_UNSUPPORTED_OPT},
7102                 {"nouser_xattr",.clrmask = 1 << REISERFS_UNSUPPORTED_OPT},
7103  #endif
7104 +#ifndef CONFIG_TAGGING_NONE
7105 +               {"tagxid",.setmask = 1 << REISERFS_TAGGED},
7106 +               {"tag",.setmask = 1 << REISERFS_TAGGED},
7107 +               {"notag",.clrmask = 1 << REISERFS_TAGGED},
7108 +#endif
7109 +#ifdef CONFIG_PROPAGATE
7110 +               {"tag",.arg_required = 'T',.values = NULL},
7111 +#endif
7112  #ifdef CONFIG_REISERFS_FS_POSIX_ACL
7113                 {"acl",.setmask = 1 << REISERFS_POSIXACL},
7114                 {"noacl",.clrmask = 1 << REISERFS_POSIXACL},
7115 @@ -1336,6 +1344,14 @@ static int reiserfs_remount(struct super
7116         handle_quota_files(s, qf_names, &qfmt);
7117  #endif
7118  
7119 +       if ((mount_options & (1 << REISERFS_TAGGED)) &&
7120 +               !(s->s_flags & MS_TAGGED)) {
7121 +               reiserfs_warning(s, "super-vs01",
7122 +                       "reiserfs: tagging not permitted on remount.");
7123 +               err = -EINVAL;
7124 +               goto out_err;
7125 +       }
7126 +
7127         handle_attrs(s);
7128  
7129         /* Add options that are safe here */
7130 @@ -1816,6 +1832,10 @@ static int reiserfs_fill_super(struct su
7131                 goto error_unlocked;
7132         }
7133  
7134 +       /* map mount option tagxid */
7135 +       if (REISERFS_SB(s)->s_mount_opt & (1 << REISERFS_TAGGED))
7136 +               s->s_flags |= MS_TAGGED;
7137 +
7138         rs = SB_DISK_SUPER_BLOCK(s);
7139         /* Let's do basic sanity check to verify that underlying device is not
7140            smaller than the filesystem. If the check fails then abort and scream,
7141 diff -NurpP --minimal linux-3.6/fs/reiserfs/xattr.c linux-3.6-vs2.3.4.3-noxfs-nocow/fs/reiserfs/xattr.c
7142 --- linux-3.6/fs/reiserfs/xattr.c       2012-10-04 15:27:41.000000000 +0200
7143 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/fs/reiserfs/xattr.c 2012-10-04 18:47:00.000000000 +0200
7144 @@ -40,6 +40,7 @@
7145  #include <linux/errno.h>
7146  #include <linux/gfp.h>
7147  #include <linux/fs.h>
7148 +#include <linux/mount.h>
7149  #include <linux/file.h>
7150  #include <linux/pagemap.h>
7151  #include <linux/xattr.h>
7152 diff -NurpP --minimal linux-3.6/fs/stat.c linux-3.6-vs2.3.4.3-noxfs-nocow/fs/stat.c
7153 --- linux-3.6/fs/stat.c 2012-10-04 15:27:41.000000000 +0200
7154 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/fs/stat.c   2012-10-04 18:47:00.000000000 +0200
7155 @@ -26,6 +26,7 @@ void generic_fillattr(struct inode *inod
7156         stat->nlink = inode->i_nlink;
7157         stat->uid = inode->i_uid;
7158         stat->gid = inode->i_gid;
7159 +       stat->tag = inode->i_tag;
7160         stat->rdev = inode->i_rdev;
7161         stat->size = i_size_read(inode);
7162         stat->atime = inode->i_atime;
7163 diff -NurpP --minimal linux-3.6/fs/statfs.c linux-3.6-vs2.3.4.3-noxfs-nocow/fs/statfs.c
7164 --- linux-3.6/fs/statfs.c       2012-07-22 23:39:42.000000000 +0200
7165 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/fs/statfs.c 2012-10-04 18:47:00.000000000 +0200
7166 @@ -7,6 +7,8 @@
7167  #include <linux/statfs.h>
7168  #include <linux/security.h>
7169  #include <linux/uaccess.h>
7170 +#include <linux/vs_base.h>
7171 +#include <linux/vs_dlimit.h>
7172  #include "internal.h"
7173  
7174  static int flags_by_mnt(int mnt_flags)
7175 @@ -60,6 +62,8 @@ static int statfs_by_dentry(struct dentr
7176         retval = dentry->d_sb->s_op->statfs(dentry, buf);
7177         if (retval == 0 && buf->f_frsize == 0)
7178                 buf->f_frsize = buf->f_bsize;
7179 +       if (!vx_check(0, VS_ADMIN|VS_WATCH))
7180 +               vx_vsi_statfs(dentry->d_sb, buf);
7181         return retval;
7182  }
7183  
7184 diff -NurpP --minimal linux-3.6/fs/super.c linux-3.6-vs2.3.4.3-noxfs-nocow/fs/super.c
7185 --- linux-3.6/fs/super.c        2012-10-04 15:27:41.000000000 +0200
7186 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/fs/super.c  2012-10-04 19:06:05.000000000 +0200
7187 @@ -34,6 +34,8 @@
7188  #include <linux/cleancache.h>
7189  #include <linux/fsnotify.h>
7190  #include <linux/lockdep.h>
7191 +#include <linux/magic.h>
7192 +#include <linux/vs_context.h>
7193  #include "internal.h"
7194  
7195  
7196 @@ -1148,6 +1150,13 @@ mount_fs(struct file_system_type *type, 
7197         WARN_ON(sb->s_bdi == &default_backing_dev_info);
7198         sb->s_flags |= MS_BORN;
7199  
7200 +       error = -EPERM;
7201 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_BINARY_MOUNT) &&
7202 +               !sb->s_bdev &&
7203 +               (sb->s_magic != PROC_SUPER_MAGIC) &&
7204 +               (sb->s_magic != DEVPTS_SUPER_MAGIC))
7205 +               goto out_sb;
7206 +
7207         error = security_sb_kern_mount(sb, flags, secdata);
7208         if (error)
7209                 goto out_sb;
7210 diff -NurpP --minimal linux-3.6/fs/sysfs/mount.c linux-3.6-vs2.3.4.3-noxfs-nocow/fs/sysfs/mount.c
7211 --- linux-3.6/fs/sysfs/mount.c  2012-10-04 15:27:41.000000000 +0200
7212 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/fs/sysfs/mount.c    2012-10-04 18:47:00.000000000 +0200
7213 @@ -47,7 +47,7 @@ static int sysfs_fill_super(struct super
7214  
7215         sb->s_blocksize = PAGE_CACHE_SIZE;
7216         sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
7217 -       sb->s_magic = SYSFS_MAGIC;
7218 +       sb->s_magic = SYSFS_SUPER_MAGIC;
7219         sb->s_op = &sysfs_ops;
7220         sb->s_time_gran = 1;
7221  
7222 diff -NurpP --minimal linux-3.6/fs/utimes.c linux-3.6-vs2.3.4.3-noxfs-nocow/fs/utimes.c
7223 --- linux-3.6/fs/utimes.c       2012-07-22 23:39:42.000000000 +0200
7224 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/fs/utimes.c 2012-10-04 18:47:00.000000000 +0200
7225 @@ -8,6 +8,8 @@
7226  #include <linux/stat.h>
7227  #include <linux/utime.h>
7228  #include <linux/syscalls.h>
7229 +#include <linux/mount.h>
7230 +#include <linux/vs_cowbl.h>
7231  #include <asm/uaccess.h>
7232  #include <asm/unistd.h>
7233  
7234 @@ -52,12 +54,18 @@ static int utimes_common(struct path *pa
7235  {
7236         int error;
7237         struct iattr newattrs;
7238 -       struct inode *inode = path->dentry->d_inode;
7239 +       struct inode *inode;
7240  
7241         error = mnt_want_write(path->mnt);
7242         if (error)
7243                 goto out;
7244  
7245 +       error = cow_check_and_break(path);
7246 +       if (error)
7247 +               goto mnt_drop_write_and_out;
7248 +
7249 +       inode = path->dentry->d_inode;
7250 +
7251         if (times && times[0].tv_nsec == UTIME_NOW &&
7252                      times[1].tv_nsec == UTIME_NOW)
7253                 times = NULL;
7254 diff -NurpP --minimal linux-3.6/fs/xattr.c linux-3.6-vs2.3.4.3-noxfs-nocow/fs/xattr.c
7255 --- linux-3.6/fs/xattr.c        2012-10-04 15:27:44.000000000 +0200
7256 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/fs/xattr.c  2012-10-04 18:47:00.000000000 +0200
7257 @@ -20,6 +20,7 @@
7258  #include <linux/fsnotify.h>
7259  #include <linux/audit.h>
7260  #include <linux/vmalloc.h>
7261 +#include <linux/mount.h>
7262  
7263  #include <asm/uaccess.h>
7264  
7265 @@ -51,7 +52,7 @@ xattr_permission(struct inode *inode, co
7266          * The trusted.* namespace can only be accessed by privileged users.
7267          */
7268         if (!strncmp(name, XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN)) {
7269 -               if (!capable(CAP_SYS_ADMIN))
7270 +               if (!vx_capable(CAP_SYS_ADMIN, VXC_FS_TRUSTED))
7271                         return (mask & MAY_WRITE) ? -EPERM : -ENODATA;
7272                 return 0;
7273         }
7274 diff -NurpP --minimal linux-3.6/fs/xfs/xfs_dinode.h linux-3.6-vs2.3.4.3-noxfs-nocow/fs/xfs/xfs_dinode.h
7275 --- linux-3.6/fs/xfs/xfs_dinode.h       2012-10-04 15:27:44.000000000 +0200
7276 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/fs/xfs/xfs_dinode.h 2012-10-04 18:47:00.000000000 +0200
7277 @@ -51,7 +51,9 @@ typedef struct xfs_dinode {
7278         __be32          di_nlink;       /* number of links to file */
7279         __be16          di_projid_lo;   /* lower part of owner's project id */
7280         __be16          di_projid_hi;   /* higher part owner's project id */
7281 -       __u8            di_pad[6];      /* unused, zeroed space */
7282 +       __u8            di_pad[2];      /* unused, zeroed space */
7283 +       __be16          di_tag;         /* context tagging */
7284 +       __be16          di_vflags;      /* vserver specific flags */
7285         __be16          di_flushiter;   /* incremented on flush */
7286         xfs_timestamp_t di_atime;       /* time last accessed */
7287         xfs_timestamp_t di_mtime;       /* time last modified */
7288 @@ -184,6 +186,8 @@ static inline void xfs_dinode_put_rdev(s
7289  #define XFS_DIFLAG_EXTSZINHERIT_BIT 12 /* inherit inode extent size */
7290  #define XFS_DIFLAG_NODEFRAG_BIT     13 /* do not reorganize/defragment */
7291  #define XFS_DIFLAG_FILESTREAM_BIT   14  /* use filestream allocator */
7292 +#define XFS_DIFLAG_IXUNLINK_BIT     15 /* Immutable inver on unlink */
7293 +
7294  #define XFS_DIFLAG_REALTIME      (1 << XFS_DIFLAG_REALTIME_BIT)
7295  #define XFS_DIFLAG_PREALLOC      (1 << XFS_DIFLAG_PREALLOC_BIT)
7296  #define XFS_DIFLAG_NEWRTBM       (1 << XFS_DIFLAG_NEWRTBM_BIT)
7297 @@ -199,6 +203,7 @@ static inline void xfs_dinode_put_rdev(s
7298  #define XFS_DIFLAG_EXTSZINHERIT  (1 << XFS_DIFLAG_EXTSZINHERIT_BIT)
7299  #define XFS_DIFLAG_NODEFRAG      (1 << XFS_DIFLAG_NODEFRAG_BIT)
7300  #define XFS_DIFLAG_FILESTREAM    (1 << XFS_DIFLAG_FILESTREAM_BIT)
7301 +#define XFS_DIFLAG_IXUNLINK      (1 << XFS_DIFLAG_IXUNLINK_BIT)
7302  
7303  #ifdef CONFIG_XFS_RT
7304  #define XFS_IS_REALTIME_INODE(ip) ((ip)->i_d.di_flags & XFS_DIFLAG_REALTIME)
7305 @@ -211,6 +216,10 @@ static inline void xfs_dinode_put_rdev(s
7306          XFS_DIFLAG_IMMUTABLE | XFS_DIFLAG_APPEND | XFS_DIFLAG_SYNC | \
7307          XFS_DIFLAG_NOATIME | XFS_DIFLAG_NODUMP | XFS_DIFLAG_RTINHERIT | \
7308          XFS_DIFLAG_PROJINHERIT | XFS_DIFLAG_NOSYMLINKS | XFS_DIFLAG_EXTSIZE | \
7309 -        XFS_DIFLAG_EXTSZINHERIT | XFS_DIFLAG_NODEFRAG | XFS_DIFLAG_FILESTREAM)
7310 +        XFS_DIFLAG_EXTSZINHERIT | XFS_DIFLAG_NODEFRAG | XFS_DIFLAG_FILESTREAM | \
7311 +        XFS_DIFLAG_IXUNLINK)
7312 +
7313 +#define XFS_DIVFLAG_BARRIER    0x01
7314 +#define XFS_DIVFLAG_COW                0x02
7315  
7316  #endif /* __XFS_DINODE_H__ */
7317 diff -NurpP --minimal linux-3.6/fs/xfs/xfs_fs.h linux-3.6-vs2.3.4.3-noxfs-nocow/fs/xfs/xfs_fs.h
7318 --- linux-3.6/fs/xfs/xfs_fs.h   2011-10-24 18:45:31.000000000 +0200
7319 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/fs/xfs/xfs_fs.h     2012-10-04 18:47:00.000000000 +0200
7320 @@ -67,6 +67,9 @@ struct fsxattr {
7321  #define XFS_XFLAG_EXTSZINHERIT 0x00001000      /* inherit inode extent size */
7322  #define XFS_XFLAG_NODEFRAG     0x00002000      /* do not defragment */
7323  #define XFS_XFLAG_FILESTREAM   0x00004000      /* use filestream allocator */
7324 +#define XFS_XFLAG_IXUNLINK     0x00008000      /* immutable invert on unlink */
7325 +#define XFS_XFLAG_BARRIER      0x10000000      /* chroot() barrier */
7326 +#define XFS_XFLAG_COW          0x20000000      /* copy on write mark */
7327  #define XFS_XFLAG_HASATTR      0x80000000      /* no DIFLAG for this   */
7328  
7329  /*
7330 @@ -302,7 +305,8 @@ typedef struct xfs_bstat {
7331  #define        bs_projid       bs_projid_lo    /* (previously just bs_projid)  */
7332         __u16           bs_forkoff;     /* inode fork offset in bytes   */
7333         __u16           bs_projid_hi;   /* higher part of project id    */
7334 -       unsigned char   bs_pad[10];     /* pad space, unused            */
7335 +       unsigned char   bs_pad[8];      /* pad space, unused            */
7336 +       __u16           bs_tag;         /* context tagging              */
7337         __u32           bs_dmevmask;    /* DMIG event mask              */
7338         __u16           bs_dmstate;     /* DMIG state info              */
7339         __u16           bs_aextents;    /* attribute number of extents  */
7340 diff -NurpP --minimal linux-3.6/fs/xfs/xfs_ialloc.c linux-3.6-vs2.3.4.3-noxfs-nocow/fs/xfs/xfs_ialloc.c
7341 --- linux-3.6/fs/xfs/xfs_ialloc.c       2012-10-04 15:27:44.000000000 +0200
7342 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/fs/xfs/xfs_ialloc.c 2012-10-04 18:47:00.000000000 +0200
7343 @@ -37,7 +37,6 @@
7344  #include "xfs_error.h"
7345  #include "xfs_bmap.h"
7346  
7347 -
7348  /*
7349   * Allocation group level functions.
7350   */
7351 diff -NurpP --minimal linux-3.6/fs/xfs/xfs_inode.c linux-3.6-vs2.3.4.3-noxfs-nocow/fs/xfs/xfs_inode.c
7352 --- linux-3.6/fs/xfs/xfs_inode.c        2012-10-04 15:27:44.000000000 +0200
7353 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/fs/xfs/xfs_inode.c  2012-10-04 18:47:00.000000000 +0200
7354 @@ -1833,6 +1833,7 @@ xfs_iroot_realloc(
7355         return;
7356  }
7357  
7358 +#include <linux/vs_tag.h>
7359  
7360  /*
7361   * This is called when the amount of space needed for if_data
7362 @@ -2521,7 +2522,8 @@ xfs_iflush_int(
7363          * because if the inode is dirty at all the core must
7364          * be.
7365          */
7366 -       xfs_dinode_to_disk(dip, &ip->i_d);
7367 +       xfs_dinode_to_disk(dip, &ip->i_d,
7368 +               mp->m_flags & XFS_MOUNT_TAGGED);
7369  
7370         /* Wrap, we never let the log put out DI_MAX_FLUSH */
7371         if (ip->i_d.di_flushiter == DI_MAX_FLUSH)
7372 diff -NurpP --minimal linux-3.6/fs/xfs/xfs_inode.h linux-3.6-vs2.3.4.3-noxfs-nocow/fs/xfs/xfs_inode.h
7373 --- linux-3.6/fs/xfs/xfs_inode.h        2012-10-04 15:27:44.000000000 +0200
7374 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/fs/xfs/xfs_inode.h  2012-10-04 18:47:00.000000000 +0200
7375 @@ -134,7 +134,9 @@ typedef struct xfs_icdinode {
7376         __uint32_t      di_nlink;       /* number of links to file */
7377         __uint16_t      di_projid_lo;   /* lower part of owner's project id */
7378         __uint16_t      di_projid_hi;   /* higher part of owner's project id */
7379 -       __uint8_t       di_pad[6];      /* unused, zeroed space */
7380 +       __uint8_t       di_pad[2];      /* unused, zeroed space */
7381 +       __uint16_t      di_tag;         /* context tagging */
7382 +       __uint16_t      di_vflags;      /* vserver specific flags */
7383         __uint16_t      di_flushiter;   /* incremented on flush */
7384         xfs_ictimestamp_t di_atime;     /* time last accessed */
7385         xfs_ictimestamp_t di_mtime;     /* time last modified */
7386 @@ -561,7 +563,7 @@ int         xfs_imap_to_bp(struct xfs_mount *, 
7387  int            xfs_iread(struct xfs_mount *, struct xfs_trans *,
7388                           struct xfs_inode *, uint);
7389  void           xfs_dinode_to_disk(struct xfs_dinode *,
7390 -                                  struct xfs_icdinode *);
7391 +                                  struct xfs_icdinode *, int);
7392  void           xfs_idestroy_fork(struct xfs_inode *, int);
7393  void           xfs_idata_realloc(struct xfs_inode *, int, int);
7394  void           xfs_iroot_realloc(struct xfs_inode *, int, int);
7395 diff -NurpP --minimal linux-3.6/fs/xfs/xfs_ioctl.c linux-3.6-vs2.3.4.3-noxfs-nocow/fs/xfs/xfs_ioctl.c
7396 --- linux-3.6/fs/xfs/xfs_ioctl.c        2012-10-04 15:27:44.000000000 +0200
7397 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/fs/xfs/xfs_ioctl.c  2012-10-04 18:47:00.000000000 +0200
7398 @@ -26,7 +26,7 @@
7399  #include "xfs_bmap_btree.h"
7400  #include "xfs_dinode.h"
7401  #include "xfs_inode.h"
7402 -#include "xfs_ioctl.h"
7403 +// #include "xfs_ioctl.h"
7404  #include "xfs_rtalloc.h"
7405  #include "xfs_itable.h"
7406  #include "xfs_error.h"
7407 @@ -762,6 +762,10 @@ xfs_merge_ioc_xflags(
7408                 xflags |= XFS_XFLAG_IMMUTABLE;
7409         else
7410                 xflags &= ~XFS_XFLAG_IMMUTABLE;
7411 +       if (flags & FS_IXUNLINK_FL)
7412 +               xflags |= XFS_XFLAG_IXUNLINK;
7413 +       else
7414 +               xflags &= ~XFS_XFLAG_IXUNLINK;
7415         if (flags & FS_APPEND_FL)
7416                 xflags |= XFS_XFLAG_APPEND;
7417         else
7418 @@ -790,6 +794,8 @@ xfs_di2lxflags(
7419  
7420         if (di_flags & XFS_DIFLAG_IMMUTABLE)
7421                 flags |= FS_IMMUTABLE_FL;
7422 +       if (di_flags & XFS_DIFLAG_IXUNLINK)
7423 +               flags |= FS_IXUNLINK_FL;
7424         if (di_flags & XFS_DIFLAG_APPEND)
7425                 flags |= FS_APPEND_FL;
7426         if (di_flags & XFS_DIFLAG_SYNC)
7427 @@ -850,6 +856,8 @@ xfs_set_diflags(
7428         di_flags = (ip->i_d.di_flags & XFS_DIFLAG_PREALLOC);
7429         if (xflags & XFS_XFLAG_IMMUTABLE)
7430                 di_flags |= XFS_DIFLAG_IMMUTABLE;
7431 +       if (xflags & XFS_XFLAG_IXUNLINK)
7432 +               di_flags |= XFS_DIFLAG_IXUNLINK;
7433         if (xflags & XFS_XFLAG_APPEND)
7434                 di_flags |= XFS_DIFLAG_APPEND;
7435         if (xflags & XFS_XFLAG_SYNC)
7436 @@ -892,6 +900,10 @@ xfs_diflags_to_linux(
7437                 inode->i_flags |= S_IMMUTABLE;
7438         else
7439                 inode->i_flags &= ~S_IMMUTABLE;
7440 +       if (xflags & XFS_XFLAG_IXUNLINK)
7441 +               inode->i_flags |= S_IXUNLINK;
7442 +       else
7443 +               inode->i_flags &= ~S_IXUNLINK;
7444         if (xflags & XFS_XFLAG_APPEND)
7445                 inode->i_flags |= S_APPEND;
7446         else
7447 @@ -1396,10 +1408,18 @@ xfs_file_ioctl(
7448         case XFS_IOC_FSGETXATTRA:
7449                 return xfs_ioc_fsgetxattr(ip, 1, arg);
7450         case XFS_IOC_FSSETXATTR:
7451 +               if (IS_BARRIER(inode)) {
7452 +                       vxwprintk_task(1, "messing with the barrier.");
7453 +                       return -XFS_ERROR(EACCES);
7454 +               }
7455                 return xfs_ioc_fssetxattr(ip, filp, arg);
7456         case XFS_IOC_GETXFLAGS:
7457                 return xfs_ioc_getxflags(ip, arg);
7458         case XFS_IOC_SETXFLAGS:
7459 +               if (IS_BARRIER(inode)) {
7460 +                       vxwprintk_task(1, "messing with the barrier.");
7461 +                       return -XFS_ERROR(EACCES);
7462 +               }
7463                 return xfs_ioc_setxflags(ip, filp, arg);
7464  
7465         case XFS_IOC_FSSETDM: {
7466 diff -NurpP --minimal linux-3.6/fs/xfs/xfs_ioctl.h linux-3.6-vs2.3.4.3-noxfs-nocow/fs/xfs/xfs_ioctl.h
7467 --- linux-3.6/fs/xfs/xfs_ioctl.h        2011-10-24 18:45:31.000000000 +0200
7468 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/fs/xfs/xfs_ioctl.h  2012-10-04 18:47:00.000000000 +0200
7469 @@ -70,6 +70,12 @@ xfs_handle_to_dentry(
7470         void __user             *uhandle,
7471         u32                     hlen);
7472  
7473 +extern int
7474 +xfs_sync_flags(
7475 +       struct inode            *inode,
7476 +       int                     flags,
7477 +       int                     vflags);
7478 +
7479  extern long
7480  xfs_file_ioctl(
7481         struct file             *filp,
7482 diff -NurpP --minimal linux-3.6/fs/xfs/xfs_iops.c linux-3.6-vs2.3.4.3-noxfs-nocow/fs/xfs/xfs_iops.c
7483 --- linux-3.6/fs/xfs/xfs_iops.c 2012-10-04 15:27:44.000000000 +0200
7484 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/fs/xfs/xfs_iops.c   2012-10-04 18:47:00.000000000 +0200
7485 @@ -28,6 +28,7 @@
7486  #include "xfs_bmap_btree.h"
7487  #include "xfs_dinode.h"
7488  #include "xfs_inode.h"
7489 +#include "xfs_ioctl.h"
7490  #include "xfs_bmap.h"
7491  #include "xfs_rtalloc.h"
7492  #include "xfs_error.h"
7493 @@ -46,6 +47,7 @@
7494  #include <linux/security.h>
7495  #include <linux/fiemap.h>
7496  #include <linux/slab.h>
7497 +#include <linux/vs_tag.h>
7498  
7499  static int
7500  xfs_initxattrs(
7501 @@ -421,6 +423,7 @@ xfs_vn_getattr(
7502         stat->nlink = ip->i_d.di_nlink;
7503         stat->uid = ip->i_d.di_uid;
7504         stat->gid = ip->i_d.di_gid;
7505 +       stat->tag = ip->i_d.di_tag;
7506         stat->ino = ip->i_ino;
7507         stat->atime = inode->i_atime;
7508         stat->mtime = inode->i_mtime;
7509 @@ -1110,6 +1113,10 @@ xfs_diflags_to_iflags(
7510                 inode->i_flags |= S_IMMUTABLE;
7511         else
7512                 inode->i_flags &= ~S_IMMUTABLE;
7513 +       if (ip->i_d.di_flags & XFS_DIFLAG_IXUNLINK)
7514 +               inode->i_flags |= S_IXUNLINK;
7515 +       else
7516 +               inode->i_flags &= ~S_IXUNLINK;
7517         if (ip->i_d.di_flags & XFS_DIFLAG_APPEND)
7518                 inode->i_flags |= S_APPEND;
7519         else
7520 @@ -1122,6 +1129,15 @@ xfs_diflags_to_iflags(
7521                 inode->i_flags |= S_NOATIME;
7522         else
7523                 inode->i_flags &= ~S_NOATIME;
7524 +
7525 +       if (ip->i_d.di_vflags & XFS_DIVFLAG_BARRIER)
7526 +               inode->i_vflags |= V_BARRIER;
7527 +       else
7528 +               inode->i_vflags &= ~V_BARRIER;
7529 +       if (ip->i_d.di_vflags & XFS_DIVFLAG_COW)
7530 +               inode->i_vflags |= V_COW;
7531 +       else
7532 +               inode->i_vflags &= ~V_COW;
7533  }
7534  
7535  /*
7536 @@ -1153,6 +1169,7 @@ xfs_setup_inode(
7537         set_nlink(inode, ip->i_d.di_nlink);
7538         inode->i_uid    = ip->i_d.di_uid;
7539         inode->i_gid    = ip->i_d.di_gid;
7540 +       inode->i_tag    = ip->i_d.di_tag;
7541  
7542         switch (inode->i_mode & S_IFMT) {
7543         case S_IFBLK:
7544 diff -NurpP --minimal linux-3.6/fs/xfs/xfs_itable.c linux-3.6-vs2.3.4.3-noxfs-nocow/fs/xfs/xfs_itable.c
7545 --- linux-3.6/fs/xfs/xfs_itable.c       2012-10-04 15:27:44.000000000 +0200
7546 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/fs/xfs/xfs_itable.c 2012-10-04 18:47:00.000000000 +0200
7547 @@ -96,6 +96,7 @@ xfs_bulkstat_one_int(
7548         buf->bs_mode = dic->di_mode;
7549         buf->bs_uid = dic->di_uid;
7550         buf->bs_gid = dic->di_gid;
7551 +       buf->bs_tag = dic->di_tag;
7552         buf->bs_size = dic->di_size;
7553         buf->bs_atime.tv_sec = dic->di_atime.t_sec;
7554         buf->bs_atime.tv_nsec = dic->di_atime.t_nsec;
7555 diff -NurpP --minimal linux-3.6/fs/xfs/xfs_linux.h linux-3.6-vs2.3.4.3-noxfs-nocow/fs/xfs/xfs_linux.h
7556 --- linux-3.6/fs/xfs/xfs_linux.h        2011-10-24 18:45:31.000000000 +0200
7557 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/fs/xfs/xfs_linux.h  2012-10-04 18:47:00.000000000 +0200
7558 @@ -121,6 +121,7 @@
7559  
7560  #define current_cpu()          (raw_smp_processor_id())
7561  #define current_pid()          (current->pid)
7562 +#define current_fstag(vp)      (dx_current_fstag((vp)->i_sb))
7563  #define current_test_flags(f)  (current->flags & (f))
7564  #define current_set_flags_nested(sp, f)                \
7565                 (*(sp) = current->flags, current->flags |= (f))
7566 diff -NurpP --minimal linux-3.6/fs/xfs/xfs_log_recover.c linux-3.6-vs2.3.4.3-noxfs-nocow/fs/xfs/xfs_log_recover.c
7567 --- linux-3.6/fs/xfs/xfs_log_recover.c  2012-10-04 15:27:44.000000000 +0200
7568 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/fs/xfs/xfs_log_recover.c    2012-10-04 18:47:00.000000000 +0200
7569 @@ -2359,7 +2359,8 @@ xlog_recover_inode_pass2(
7570         }
7571  
7572         /* The core is in in-core format */
7573 -       xfs_dinode_to_disk(dip, item->ri_buf[1].i_addr);
7574 +       xfs_dinode_to_disk(dip, item->ri_buf[1].i_addr,
7575 +               mp->m_flags & XFS_MOUNT_TAGGED);
7576  
7577         /* the rest is in on-disk format */
7578         if (item->ri_buf[1].i_len > sizeof(struct xfs_icdinode)) {
7579 diff -NurpP --minimal linux-3.6/fs/xfs/xfs_mount.h linux-3.6-vs2.3.4.3-noxfs-nocow/fs/xfs/xfs_mount.h
7580 --- linux-3.6/fs/xfs/xfs_mount.h        2012-10-04 15:27:44.000000000 +0200
7581 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/fs/xfs/xfs_mount.h  2012-10-04 18:47:00.000000000 +0200
7582 @@ -251,6 +251,7 @@ typedef struct xfs_mount {
7583                                                    allocator */
7584  #define XFS_MOUNT_NOATTR2      (1ULL << 25)    /* disable use of attr2 format */
7585  
7586 +#define XFS_MOUNT_TAGGED       (1ULL << 31)    /* context tagging */
7587  
7588  /*
7589   * Default minimum read and write sizes.
7590 diff -NurpP --minimal linux-3.6/fs/xfs/xfs_super.c linux-3.6-vs2.3.4.3-noxfs-nocow/fs/xfs/xfs_super.c
7591 --- linux-3.6/fs/xfs/xfs_super.c        2012-10-04 15:27:44.000000000 +0200
7592 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/fs/xfs/xfs_super.c  2012-10-04 18:47:00.000000000 +0200
7593 @@ -112,6 +112,9 @@ mempool_t *xfs_ioend_pool;
7594  #define MNTOPT_NODELAYLOG  "nodelaylog"        /* Delayed logging disabled */
7595  #define MNTOPT_DISCARD    "discard"    /* Discard unused blocks */
7596  #define MNTOPT_NODISCARD   "nodiscard" /* Do not discard unused blocks */
7597 +#define MNTOPT_TAGXID  "tagxid"        /* context tagging for inodes */
7598 +#define MNTOPT_TAGGED  "tag"           /* context tagging for inodes */
7599 +#define MNTOPT_NOTAGTAG        "notag"         /* do not use context tagging */
7600  
7601  /*
7602   * Table driven mount option parser.
7603 @@ -120,10 +123,14 @@ mempool_t *xfs_ioend_pool;
7604   * in the future, too.
7605   */
7606  enum {
7607 +       Opt_tag, Opt_notag,
7608         Opt_barrier, Opt_nobarrier, Opt_err
7609  };
7610  
7611  static const match_table_t tokens = {
7612 +       {Opt_tag, "tagxid"},
7613 +       {Opt_tag, "tag"},
7614 +       {Opt_notag, "notag"},
7615         {Opt_barrier, "barrier"},
7616         {Opt_nobarrier, "nobarrier"},
7617         {Opt_err, NULL}
7618 @@ -371,6 +378,19 @@ xfs_parseargs(
7619                 } else if (!strcmp(this_char, "irixsgid")) {
7620                         xfs_warn(mp,
7621         "irixsgid is now a sysctl(2) variable, option is deprecated.");
7622 +#ifndef CONFIG_TAGGING_NONE
7623 +               } else if (!strcmp(this_char, MNTOPT_TAGGED)) {
7624 +                       mp->m_flags |= XFS_MOUNT_TAGGED;
7625 +               } else if (!strcmp(this_char, MNTOPT_NOTAGTAG)) {
7626 +                       mp->m_flags &= ~XFS_MOUNT_TAGGED;
7627 +               } else if (!strcmp(this_char, MNTOPT_TAGXID)) {
7628 +                       mp->m_flags |= XFS_MOUNT_TAGGED;
7629 +#endif
7630 +#ifdef CONFIG_PROPAGATE
7631 +               } else if (!strcmp(this_char, MNTOPT_TAGGED)) {
7632 +                       /* use value */
7633 +                       mp->m_flags |= XFS_MOUNT_TAGGED;
7634 +#endif
7635                 } else {
7636                         xfs_warn(mp, "unknown mount option [%s].", this_char);
7637                         return EINVAL;
7638 @@ -1056,6 +1076,16 @@ xfs_fs_remount(
7639                 case Opt_nobarrier:
7640                         mp->m_flags &= ~XFS_MOUNT_BARRIER;
7641                         break;
7642 +               case Opt_tag:
7643 +                       if (!(sb->s_flags & MS_TAGGED)) {
7644 +                               printk(KERN_INFO
7645 +                                       "XFS: %s: tagging not permitted on remount.\n",
7646 +                                       sb->s_id);
7647 +                               return -EINVAL;
7648 +                       }
7649 +                       break;
7650 +               case Opt_notag:
7651 +                       break;
7652                 default:
7653                         /*
7654                          * Logically we would return an error here to prevent
7655 @@ -1275,6 +1305,9 @@ xfs_fs_fill_super(
7656         if (error)
7657                 goto out_free_sb;
7658  
7659 +       if (mp->m_flags & XFS_MOUNT_TAGGED)
7660 +               sb->s_flags |= MS_TAGGED;
7661 +
7662         /*
7663          * we must configure the block size in the superblock before we run the
7664          * full mount process as the mount process can lookup and cache inodes.
7665 diff -NurpP --minimal linux-3.6/fs/xfs/xfs_vnodeops.c linux-3.6-vs2.3.4.3-noxfs-nocow/fs/xfs/xfs_vnodeops.c
7666 --- linux-3.6/fs/xfs/xfs_vnodeops.c     2012-10-04 15:27:44.000000000 +0200
7667 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/fs/xfs/xfs_vnodeops.c       2012-10-04 18:47:00.000000000 +0200
7668 @@ -103,6 +103,77 @@ xfs_readlink_bmap(
7669         return error;
7670  }
7671  
7672 +
7673 +STATIC void
7674 +xfs_get_inode_flags(
7675 +       xfs_inode_t     *ip)
7676 +{
7677 +       struct inode    *inode = VFS_I(ip);
7678 +       unsigned int    flags = inode->i_flags;
7679 +       unsigned int    vflags = inode->i_vflags;
7680 +
7681 +       if (flags & S_IMMUTABLE)
7682 +               ip->i_d.di_flags |= XFS_DIFLAG_IMMUTABLE;
7683 +       else
7684 +               ip->i_d.di_flags &= ~XFS_DIFLAG_IMMUTABLE;
7685 +       if (flags & S_IXUNLINK)
7686 +               ip->i_d.di_flags |= XFS_DIFLAG_IXUNLINK;
7687 +       else
7688 +               ip->i_d.di_flags &= ~XFS_DIFLAG_IXUNLINK;
7689 +
7690 +       if (vflags & V_BARRIER)
7691 +               ip->i_d.di_vflags |= XFS_DIVFLAG_BARRIER;
7692 +       else
7693 +               ip->i_d.di_vflags &= ~XFS_DIVFLAG_BARRIER;
7694 +       if (vflags & V_COW)
7695 +               ip->i_d.di_vflags |= XFS_DIVFLAG_COW;
7696 +       else
7697 +               ip->i_d.di_vflags &= ~XFS_DIVFLAG_COW;
7698 +}
7699 +
7700 +int
7701 +xfs_sync_flags(
7702 +       struct inode            *inode,
7703 +       int                     flags,
7704 +       int                     vflags)
7705 +{
7706 +       struct xfs_inode        *ip = XFS_I(inode);
7707 +       struct xfs_mount        *mp = ip->i_mount;
7708 +       struct xfs_trans        *tp;
7709 +       unsigned int            lock_flags = 0;
7710 +       int                     code;
7711 +
7712 +       tp = xfs_trans_alloc(mp, XFS_TRANS_SETATTR_NOT_SIZE);
7713 +       code = xfs_trans_reserve(tp, 0, XFS_ICHANGE_LOG_RES(mp), 0, 0, 0);
7714 +       if (code)
7715 +               goto error_out;
7716 +
7717 +       xfs_ilock(ip, XFS_ILOCK_EXCL);
7718 +       xfs_trans_ijoin(tp, ip, 0);
7719 +
7720 +       inode->i_flags = flags;
7721 +       inode->i_vflags = vflags;
7722 +       xfs_get_inode_flags(ip);
7723 +
7724 +       xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE);
7725 +       xfs_trans_ichgtime(tp, ip, XFS_ICHGTIME_CHG);
7726 +
7727 +       XFS_STATS_INC(xs_ig_attrchg);
7728 +
7729 +       if (mp->m_flags & XFS_MOUNT_WSYNC)
7730 +               xfs_trans_set_sync(tp);
7731 +       code = xfs_trans_commit(tp, 0);
7732 +       xfs_iunlock(ip, XFS_ILOCK_EXCL);
7733 +       return code;
7734 +
7735 +error_out:
7736 +       xfs_trans_cancel(tp, 0);
7737 +       if (lock_flags)
7738 +               xfs_iunlock(ip, XFS_ILOCK_EXCL);
7739 +       return code;
7740 +}
7741 +
7742 +
7743  int
7744  xfs_readlink(
7745         xfs_inode_t     *ip,
7746 diff -NurpP --minimal linux-3.6/include/linux/Kbuild linux-3.6-vs2.3.4.3-noxfs-nocow/include/linux/Kbuild
7747 --- linux-3.6/include/linux/Kbuild      2012-10-04 15:27:45.000000000 +0200
7748 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/include/linux/Kbuild        2012-10-04 18:47:00.000000000 +0200
7749 @@ -18,6 +18,7 @@ header-y += netfilter_bridge/
7750  header-y += netfilter_ipv4/
7751  header-y += netfilter_ipv6/
7752  header-y += usb/
7753 +header-y += vserver/
7754  header-y += wimax/
7755  
7756  objhdr-y += version.h
7757 diff -NurpP --minimal linux-3.6/include/linux/capability.h linux-3.6-vs2.3.4.3-noxfs-nocow/include/linux/capability.h
7758 --- linux-3.6/include/linux/capability.h        2012-07-22 23:39:43.000000000 +0200
7759 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/include/linux/capability.h  2012-10-04 18:47:00.000000000 +0200
7760 @@ -280,6 +280,7 @@ struct cpu_vfs_cap_data {
7761     arbitrary SCSI commands */
7762  /* Allow setting encryption key on loopback filesystem */
7763  /* Allow setting zone reclaim policy */
7764 +/* Allow the selection of a security context */
7765  
7766  #define CAP_SYS_ADMIN        21
7767  
7768 @@ -366,7 +367,12 @@ struct cpu_vfs_cap_data {
7769  
7770  #define CAP_LAST_CAP         CAP_BLOCK_SUSPEND
7771  
7772 -#define cap_valid(x) ((x) >= 0 && (x) <= CAP_LAST_CAP)
7773 +/* Allow context manipulations */
7774 +/* Allow changing context info on files */
7775 +
7776 +#define CAP_CONTEXT         63
7777 +
7778 +#define cap_valid(x) ((x) >= 0 && ((x) <= CAP_LAST_CAP || (x) == CAP_CONTEXT))
7779  
7780  /*
7781   * Bit location of each capability (used by user-space library and kernel)
7782 diff -NurpP --minimal linux-3.6/include/linux/cred.h linux-3.6-vs2.3.4.3-noxfs-nocow/include/linux/cred.h
7783 --- linux-3.6/include/linux/cred.h      2012-07-22 23:39:43.000000000 +0200
7784 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/include/linux/cred.h        2012-10-04 18:47:00.000000000 +0200
7785 @@ -157,6 +157,7 @@ extern void exit_creds(struct task_struc
7786  extern int copy_creds(struct task_struct *, unsigned long);
7787  extern const struct cred *get_task_cred(struct task_struct *);
7788  extern struct cred *cred_alloc_blank(void);
7789 +extern struct cred *__prepare_creds(const struct cred *);
7790  extern struct cred *prepare_creds(void);
7791  extern struct cred *prepare_exec_creds(void);
7792  extern int commit_creds(struct cred *);
7793 @@ -210,6 +211,31 @@ static inline void validate_process_cred
7794  }
7795  #endif
7796  
7797 +static inline void set_cred_subscribers(struct cred *cred, int n)
7798 +{
7799 +#ifdef CONFIG_DEBUG_CREDENTIALS
7800 +       atomic_set(&cred->subscribers, n);
7801 +#endif
7802 +}
7803 +
7804 +static inline int read_cred_subscribers(const struct cred *cred)
7805 +{
7806 +#ifdef CONFIG_DEBUG_CREDENTIALS
7807 +       return atomic_read(&cred->subscribers);
7808 +#else
7809 +       return 0;
7810 +#endif
7811 +}
7812 +
7813 +static inline void alter_cred_subscribers(const struct cred *_cred, int n)
7814 +{
7815 +#ifdef CONFIG_DEBUG_CREDENTIALS
7816 +       struct cred *cred = (struct cred *) _cred;
7817 +
7818 +       atomic_add(n, &cred->subscribers);
7819 +#endif
7820 +}
7821 +
7822  /**
7823   * get_new_cred - Get a reference on a new set of credentials
7824   * @cred: The new credentials to reference
7825 diff -NurpP --minimal linux-3.6/include/linux/devpts_fs.h linux-3.6-vs2.3.4.3-noxfs-nocow/include/linux/devpts_fs.h
7826 --- linux-3.6/include/linux/devpts_fs.h 2008-12-25 00:26:37.000000000 +0100
7827 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/include/linux/devpts_fs.h   2012-10-04 18:47:00.000000000 +0200
7828 @@ -45,5 +45,4 @@ static inline void devpts_pty_kill(struc
7829  
7830  #endif
7831  
7832 -
7833  #endif /* _LINUX_DEVPTS_FS_H */
7834 diff -NurpP --minimal linux-3.6/include/linux/fs.h linux-3.6-vs2.3.4.3-noxfs-nocow/include/linux/fs.h
7835 --- linux-3.6/include/linux/fs.h        2012-10-04 15:27:45.000000000 +0200
7836 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/include/linux/fs.h  2012-10-04 18:47:00.000000000 +0200
7837 @@ -225,6 +225,9 @@ struct inodes_stat_t {
7838  #define MS_KERNMOUNT   (1<<22) /* this is a kern_mount call */
7839  #define MS_I_VERSION   (1<<23) /* Update inode I_version field */
7840  #define MS_STRICTATIME (1<<24) /* Always perform atime updates */
7841 +#define MS_TAGGED      (1<<25) /* use generic inode tagging */
7842 +#define MS_TAGID       (1<<26) /* use specific tag for this mount */
7843 +#define MS_NOTAGCHECK  (1<<27) /* don't check tags */
7844  #define MS_NOSEC       (1<<28)
7845  #define MS_BORN                (1<<29)
7846  #define MS_ACTIVE      (1<<30)
7847 @@ -256,6 +259,14 @@ struct inodes_stat_t {
7848  #define S_IMA          1024    /* Inode has an associated IMA struct */
7849  #define S_AUTOMOUNT    2048    /* Automount/referral quasi-directory */
7850  #define S_NOSEC                4096    /* no suid or xattr security attributes */
7851 +#define S_IXUNLINK     8192    /* Immutable Invert on unlink */
7852 +
7853 +/* Linux-VServer related Inode flags */
7854 +
7855 +#define V_VALID                1
7856 +#define V_XATTR                2
7857 +#define V_BARRIER      4       /* Barrier for chroot() */
7858 +#define V_COW          8       /* Copy on Write */
7859  
7860  /*
7861   * Note that nosuid etc flags are inode-specific: setting some file-system
7862 @@ -278,12 +289,15 @@ struct inodes_stat_t {
7863  #define IS_DIRSYNC(inode)      (__IS_FLG(inode, MS_SYNCHRONOUS|MS_DIRSYNC) || \
7864                                         ((inode)->i_flags & (S_SYNC|S_DIRSYNC)))
7865  #define IS_MANDLOCK(inode)     __IS_FLG(inode, MS_MANDLOCK)
7866 -#define IS_NOATIME(inode)   __IS_FLG(inode, MS_RDONLY|MS_NOATIME)
7867 -#define IS_I_VERSION(inode)   __IS_FLG(inode, MS_I_VERSION)
7868 +#define IS_NOATIME(inode)      __IS_FLG(inode, MS_RDONLY|MS_NOATIME)
7869 +#define IS_I_VERSION(inode)    __IS_FLG(inode, MS_I_VERSION)
7870 +#define IS_TAGGED(inode)       __IS_FLG(inode, MS_TAGGED)
7871  
7872  #define IS_NOQUOTA(inode)      ((inode)->i_flags & S_NOQUOTA)
7873  #define IS_APPEND(inode)       ((inode)->i_flags & S_APPEND)
7874  #define IS_IMMUTABLE(inode)    ((inode)->i_flags & S_IMMUTABLE)
7875 +#define IS_IXUNLINK(inode)     ((inode)->i_flags & S_IXUNLINK)
7876 +#define IS_IXORUNLINK(inode)   ((IS_IXUNLINK(inode) ? S_IMMUTABLE : 0) ^ IS_IMMUTABLE(inode))
7877  #define IS_POSIXACL(inode)     __IS_FLG(inode, MS_POSIXACL)
7878  
7879  #define IS_DEADDIR(inode)      ((inode)->i_flags & S_DEAD)
7880 @@ -294,6 +308,16 @@ struct inodes_stat_t {
7881  #define IS_AUTOMOUNT(inode)    ((inode)->i_flags & S_AUTOMOUNT)
7882  #define IS_NOSEC(inode)                ((inode)->i_flags & S_NOSEC)
7883  
7884 +#define IS_BARRIER(inode)      (S_ISDIR((inode)->i_mode) && ((inode)->i_vflags & V_BARRIER))
7885 +
7886 +#ifdef CONFIG_VSERVER_COWBL
7887 +#  define IS_COW(inode)                (IS_IXUNLINK(inode) && IS_IMMUTABLE(inode))
7888 +#  define IS_COW_LINK(inode)   (S_ISREG((inode)->i_mode) && ((inode)->i_nlink > 1))
7889 +#else
7890 +#  define IS_COW(inode)                (0)
7891 +#  define IS_COW_LINK(inode)   (0)
7892 +#endif
7893 +
7894  /* the read-only stuff doesn't really belong here, but any other place is
7895     probably as bad and I don't want to create yet another include file. */
7896  
7897 @@ -380,11 +404,14 @@ struct inodes_stat_t {
7898  #define FS_EXTENT_FL                   0x00080000 /* Extents */
7899  #define FS_DIRECTIO_FL                 0x00100000 /* Use direct i/o */
7900  #define FS_NOCOW_FL                    0x00800000 /* Do not cow file */
7901 +#define FS_IXUNLINK_FL                 0x08000000 /* Immutable invert on unlink */
7902  #define FS_RESERVED_FL                 0x80000000 /* reserved for ext2 lib */
7903  
7904 -#define FS_FL_USER_VISIBLE             0x0003DFFF /* User visible flags */
7905 -#define FS_FL_USER_MODIFIABLE          0x000380FF /* User modifiable flags */
7906 +#define FS_BARRIER_FL                  0x04000000 /* Barrier for chroot() */
7907 +#define FS_COW_FL                      0x20000000 /* Copy on Write marker */
7908  
7909 +#define FS_FL_USER_VISIBLE             0x0103DFFF /* User visible flags */
7910 +#define FS_FL_USER_MODIFIABLE          0x010380FF /* User modifiable flags */
7911  
7912  #define SYNC_FILE_RANGE_WAIT_BEFORE    1
7913  #define SYNC_FILE_RANGE_WRITE          2
7914 @@ -472,6 +499,7 @@ typedef void (dio_iodone_t)(struct kiocb
7915  #define ATTR_KILL_PRIV (1 << 14)
7916  #define ATTR_OPEN      (1 << 15) /* Truncating from open(O_TRUNC) */
7917  #define ATTR_TIMES_SET (1 << 16)
7918 +#define ATTR_TAG       (1 << 17)
7919  
7920  /*
7921   * This is the Inode Attributes structure, used for notify_change().  It
7922 @@ -487,6 +515,7 @@ struct iattr {
7923         umode_t         ia_mode;
7924         kuid_t          ia_uid;
7925         kgid_t          ia_gid;
7926 +       tag_t           ia_tag;
7927         loff_t          ia_size;
7928         struct timespec ia_atime;
7929         struct timespec ia_mtime;
7930 @@ -500,6 +529,9 @@ struct iattr {
7931         struct file     *ia_file;
7932  };
7933  
7934 +#define ATTR_FLAG_BARRIER      512     /* Barrier for chroot() */
7935 +#define ATTR_FLAG_IXUNLINK     1024    /* Immutable invert on unlink */
7936 +
7937  /*
7938   * Includes for diskquotas.
7939   */
7940 @@ -784,7 +816,9 @@ struct inode {
7941         unsigned short          i_opflags;
7942         kuid_t                  i_uid;
7943         kgid_t                  i_gid;
7944 -       unsigned int            i_flags;
7945 +       tag_t                   i_tag;
7946 +       unsigned short          i_flags;
7947 +       unsigned short          i_vflags;
7948  
7949  #ifdef CONFIG_FS_POSIX_ACL
7950         struct posix_acl        *i_acl;
7951 @@ -813,6 +847,7 @@ struct inode {
7952                 unsigned int __i_nlink;
7953         };
7954         dev_t                   i_rdev;
7955 +       dev_t                   i_mdev;
7956         loff_t                  i_size;
7957         struct timespec         i_atime;
7958         struct timespec         i_mtime;
7959 @@ -975,12 +1010,12 @@ static inline void i_gid_write(struct in
7960  
7961  static inline unsigned iminor(const struct inode *inode)
7962  {
7963 -       return MINOR(inode->i_rdev);
7964 +       return MINOR(inode->i_mdev);
7965  }
7966  
7967  static inline unsigned imajor(const struct inode *inode)
7968  {
7969 -       return MAJOR(inode->i_rdev);
7970 +       return MAJOR(inode->i_mdev);
7971  }
7972  
7973  extern struct block_device *I_BDEV(struct inode *inode);
7974 @@ -1047,6 +1082,7 @@ struct file {
7975         loff_t                  f_pos;
7976         struct fown_struct      f_owner;
7977         const struct cred       *f_cred;
7978 +       xid_t                   f_xid;
7979         struct file_ra_state    f_ra;
7980  
7981         u64                     f_version;
7982 @@ -1194,6 +1230,7 @@ struct file_lock {
7983         struct file *fl_file;
7984         loff_t fl_start;
7985         loff_t fl_end;
7986 +       xid_t fl_xid;
7987  
7988         struct fasync_struct *  fl_fasync; /* for lease break notifications */
7989         /* for lease breaks: */
7990 @@ -1829,6 +1866,7 @@ struct inode_operations {
7991         ssize_t (*getxattr) (struct dentry *, const char *, void *, size_t);
7992         ssize_t (*listxattr) (struct dentry *, char *, size_t);
7993         int (*removexattr) (struct dentry *, const char *);
7994 +       int (*sync_flags) (struct inode *, int, int);
7995         int (*fiemap)(struct inode *, struct fiemap_extent_info *, u64 start,
7996                       u64 len);
7997         int (*update_time)(struct inode *, struct timespec *, int);
7998 @@ -1850,6 +1888,7 @@ extern ssize_t vfs_readv(struct file *, 
7999                 unsigned long, loff_t *);
8000  extern ssize_t vfs_writev(struct file *, const struct iovec __user *,
8001                 unsigned long, loff_t *);
8002 +ssize_t vfs_sendfile(struct file *, struct file *, loff_t *, size_t, loff_t);
8003  
8004  struct super_operations {
8005         struct inode *(*alloc_inode)(struct super_block *sb);
8006 @@ -2692,6 +2731,7 @@ extern int dcache_dir_open(struct inode 
8007  extern int dcache_dir_close(struct inode *, struct file *);
8008  extern loff_t dcache_dir_lseek(struct file *, loff_t, int);
8009  extern int dcache_readdir(struct file *, void *, filldir_t);
8010 +extern int dcache_readdir_filter(struct file *, void *, filldir_t, int (*)(struct dentry *));
8011  extern int simple_setattr(struct dentry *, struct iattr *);
8012  extern int simple_getattr(struct vfsmount *, struct dentry *, struct kstat *);
8013  extern int simple_statfs(struct dentry *, struct kstatfs *);
8014 diff -NurpP --minimal linux-3.6/include/linux/gfs2_ondisk.h linux-3.6-vs2.3.4.3-noxfs-nocow/include/linux/gfs2_ondisk.h
8015 --- linux-3.6/include/linux/gfs2_ondisk.h       2012-10-04 15:27:45.000000000 +0200
8016 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/include/linux/gfs2_ondisk.h 2012-10-04 18:54:29.000000000 +0200
8017 @@ -225,6 +225,9 @@ enum {
8018         gfs2fl_Sync             = 8,
8019         gfs2fl_System           = 9,
8020         gfs2fl_TopLevel         = 10,
8021 +       gfs2fl_IXUnlink         = 16,
8022 +       gfs2fl_Barrier          = 17,
8023 +       gfs2fl_Cow              = 18,
8024         gfs2fl_TruncInProg      = 29,
8025         gfs2fl_InheritDirectio  = 30,
8026         gfs2fl_InheritJdata     = 31,
8027 @@ -242,6 +245,9 @@ enum {
8028  #define GFS2_DIF_SYNC                  0x00000100
8029  #define GFS2_DIF_SYSTEM                        0x00000200 /* New in gfs2 */
8030  #define GFS2_DIF_TOPDIR                        0x00000400 /* New in gfs2 */
8031 +#define GFS2_DIF_IXUNLINK              0x00010000
8032 +#define GFS2_DIF_BARRIER               0x00020000
8033 +#define GFS2_DIF_COW                   0x00040000
8034  #define GFS2_DIF_TRUNC_IN_PROG         0x20000000 /* New in gfs2 */
8035  #define GFS2_DIF_INHERIT_DIRECTIO      0x40000000 /* only in gfs1 */
8036  #define GFS2_DIF_INHERIT_JDATA         0x80000000
8037 diff -NurpP --minimal linux-3.6/include/linux/if_tun.h linux-3.6-vs2.3.4.3-noxfs-nocow/include/linux/if_tun.h
8038 --- linux-3.6/include/linux/if_tun.h    2010-08-02 16:52:54.000000000 +0200
8039 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/include/linux/if_tun.h      2012-10-04 18:47:00.000000000 +0200
8040 @@ -53,6 +53,7 @@
8041  #define TUNDETACHFILTER _IOW('T', 214, struct sock_fprog)
8042  #define TUNGETVNETHDRSZ _IOR('T', 215, int)
8043  #define TUNSETVNETHDRSZ _IOW('T', 216, int)
8044 +#define TUNSETNID     _IOW('T', 217, int)
8045  
8046  /* TUNSETIFF ifr flags */
8047  #define IFF_TUN                0x0001
8048 diff -NurpP --minimal linux-3.6/include/linux/init_task.h linux-3.6-vs2.3.4.3-noxfs-nocow/include/linux/init_task.h
8049 --- linux-3.6/include/linux/init_task.h 2012-10-04 15:27:45.000000000 +0200
8050 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/include/linux/init_task.h   2012-10-04 18:47:00.000000000 +0200
8051 @@ -210,6 +210,10 @@ extern struct task_group root_task_group
8052         INIT_TRACE_RECURSION                                            \
8053         INIT_TASK_RCU_PREEMPT(tsk)                                      \
8054         INIT_CPUSET_SEQ                                                 \
8055 +       .xid            = 0,                                            \
8056 +       .vx_info        = NULL,                                         \
8057 +       .nid            = 0,                                            \
8058 +       .nx_info        = NULL,                                         \
8059  }
8060  
8061  
8062 diff -NurpP --minimal linux-3.6/include/linux/ipc.h linux-3.6-vs2.3.4.3-noxfs-nocow/include/linux/ipc.h
8063 --- linux-3.6/include/linux/ipc.h       2012-03-19 19:47:28.000000000 +0100
8064 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/include/linux/ipc.h 2012-10-04 18:47:00.000000000 +0200
8065 @@ -91,6 +91,7 @@ struct kern_ipc_perm
8066         key_t           key;
8067         uid_t           uid;
8068         gid_t           gid;
8069 +       xid_t           xid;
8070         uid_t           cuid;
8071         gid_t           cgid;
8072         umode_t         mode; 
8073 diff -NurpP --minimal linux-3.6/include/linux/ipc_namespace.h linux-3.6-vs2.3.4.3-noxfs-nocow/include/linux/ipc_namespace.h
8074 --- linux-3.6/include/linux/ipc_namespace.h     2012-07-22 23:39:43.000000000 +0200
8075 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/include/linux/ipc_namespace.h       2012-10-04 18:47:00.000000000 +0200
8076 @@ -133,7 +133,8 @@ static inline int mq_init_ns(struct ipc_
8077  
8078  #if defined(CONFIG_IPC_NS)
8079  extern struct ipc_namespace *copy_ipcs(unsigned long flags,
8080 -                                      struct task_struct *tsk);
8081 +                                      struct ipc_namespace *old_ns,
8082 +                                      struct user_namespace *user_ns);
8083  static inline struct ipc_namespace *get_ipc_ns(struct ipc_namespace *ns)
8084  {
8085         if (ns)
8086 @@ -144,12 +145,13 @@ static inline struct ipc_namespace *get_
8087  extern void put_ipc_ns(struct ipc_namespace *ns);
8088  #else
8089  static inline struct ipc_namespace *copy_ipcs(unsigned long flags,
8090 -                                             struct task_struct *tsk)
8091 +                                             struct ipc_namespace *old_ns,
8092 +                                             struct user_namespace *user_ns)
8093  {
8094         if (flags & CLONE_NEWIPC)
8095                 return ERR_PTR(-EINVAL);
8096  
8097 -       return tsk->nsproxy->ipc_ns;
8098 +       return old_ns;
8099  }
8100  
8101  static inline struct ipc_namespace *get_ipc_ns(struct ipc_namespace *ns)
8102 diff -NurpP --minimal linux-3.6/include/linux/loop.h linux-3.6-vs2.3.4.3-noxfs-nocow/include/linux/loop.h
8103 --- linux-3.6/include/linux/loop.h      2012-01-09 16:14:58.000000000 +0100
8104 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/include/linux/loop.h        2012-10-04 18:47:00.000000000 +0200
8105 @@ -45,6 +45,7 @@ struct loop_device {
8106         struct loop_func_table *lo_encryption;
8107         __u32           lo_init[2];
8108         uid_t           lo_key_owner;   /* Who set the key */
8109 +       xid_t           lo_xid;
8110         int             (*ioctl)(struct loop_device *, int cmd, 
8111                                  unsigned long arg); 
8112  
8113 diff -NurpP --minimal linux-3.6/include/linux/magic.h linux-3.6-vs2.3.4.3-noxfs-nocow/include/linux/magic.h
8114 --- linux-3.6/include/linux/magic.h     2012-05-21 18:07:31.000000000 +0200
8115 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/include/linux/magic.h       2012-10-04 18:47:00.000000000 +0200
8116 @@ -3,7 +3,7 @@
8117  
8118  #define ADFS_SUPER_MAGIC       0xadf5
8119  #define AFFS_SUPER_MAGIC       0xadff
8120 -#define AFS_SUPER_MAGIC                0x5346414F
8121 +#define AFS_SUPER_MAGIC                0x5346414F
8122  #define AUTOFS_SUPER_MAGIC     0x0187
8123  #define CODA_SUPER_MAGIC       0x73757245
8124  #define CRAMFS_MAGIC           0x28cd3d45      /* some random number */
8125 diff -NurpP --minimal linux-3.6/include/linux/major.h linux-3.6-vs2.3.4.3-noxfs-nocow/include/linux/major.h
8126 --- linux-3.6/include/linux/major.h     2009-09-10 15:26:25.000000000 +0200
8127 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/include/linux/major.h       2012-10-04 18:47:00.000000000 +0200
8128 @@ -15,6 +15,7 @@
8129  #define HD_MAJOR               IDE0_MAJOR
8130  #define PTY_SLAVE_MAJOR                3
8131  #define TTY_MAJOR              4
8132 +#define VROOT_MAJOR            4
8133  #define TTYAUX_MAJOR           5
8134  #define LP_MAJOR               6
8135  #define VCS_MAJOR              7
8136 diff -NurpP --minimal linux-3.6/include/linux/memcontrol.h linux-3.6-vs2.3.4.3-noxfs-nocow/include/linux/memcontrol.h
8137 --- linux-3.6/include/linux/memcontrol.h        2012-10-04 15:27:45.000000000 +0200
8138 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/include/linux/memcontrol.h  2012-10-04 18:47:00.000000000 +0200
8139 @@ -83,6 +83,13 @@ extern struct mem_cgroup *try_get_mem_cg
8140  extern struct mem_cgroup *parent_mem_cgroup(struct mem_cgroup *memcg);
8141  extern struct mem_cgroup *mem_cgroup_from_cont(struct cgroup *cont);
8142  
8143 +extern u64 mem_cgroup_res_read_u64(struct mem_cgroup *mem, int member);
8144 +extern u64 mem_cgroup_memsw_read_u64(struct mem_cgroup *mem, int member);
8145 +
8146 +extern s64 mem_cgroup_stat_read_cache(struct mem_cgroup *mem);
8147 +extern s64 mem_cgroup_stat_read_anon(struct mem_cgroup *mem);
8148 +extern s64 mem_cgroup_stat_read_mapped(struct mem_cgroup *mem);
8149 +
8150  static inline
8151  int mm_match_cgroup(const struct mm_struct *mm, const struct mem_cgroup *cgroup)
8152  {
8153 diff -NurpP --minimal linux-3.6/include/linux/mm_types.h linux-3.6-vs2.3.4.3-noxfs-nocow/include/linux/mm_types.h
8154 --- linux-3.6/include/linux/mm_types.h  2012-10-04 15:27:46.000000000 +0200
8155 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/include/linux/mm_types.h    2012-10-04 18:47:00.000000000 +0200
8156 @@ -370,6 +370,7 @@ struct mm_struct {
8157  
8158         /* Architecture-specific MM context */
8159         mm_context_t context;
8160 +       struct vx_info *mm_vx_info;
8161  
8162         unsigned long flags; /* Must use atomic bitops to access the bits */
8163  
8164 diff -NurpP --minimal linux-3.6/include/linux/mmzone.h linux-3.6-vs2.3.4.3-noxfs-nocow/include/linux/mmzone.h
8165 --- linux-3.6/include/linux/mmzone.h    2012-10-04 15:27:46.000000000 +0200
8166 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/include/linux/mmzone.h      2012-10-04 18:47:00.000000000 +0200
8167 @@ -727,6 +727,13 @@ typedef struct pglist_data {
8168         __pgdat->node_start_pfn + __pgdat->node_spanned_pages;\
8169  })
8170  
8171 +#define node_start_pfn(nid)    (NODE_DATA(nid)->node_start_pfn)
8172 +
8173 +#define node_end_pfn(nid) ({\
8174 +       pg_data_t *__pgdat = NODE_DATA(nid);\
8175 +       __pgdat->node_start_pfn + __pgdat->node_spanned_pages;\
8176 +})
8177 +
8178  #include <linux/memory_hotplug.h>
8179  
8180  extern struct mutex zonelists_mutex;
8181 diff -NurpP --minimal linux-3.6/include/linux/mount.h linux-3.6-vs2.3.4.3-noxfs-nocow/include/linux/mount.h
8182 --- linux-3.6/include/linux/mount.h     2012-03-19 19:47:28.000000000 +0100
8183 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/include/linux/mount.h       2012-10-04 18:47:00.000000000 +0200
8184 @@ -47,6 +47,9 @@ struct mnt_namespace;
8185  
8186  #define MNT_INTERNAL   0x4000
8187  
8188 +#define MNT_TAGID      0x10000
8189 +#define MNT_NOTAG      0x20000
8190 +
8191  struct vfsmount {
8192         struct dentry *mnt_root;        /* root of the mounted tree */
8193         struct super_block *mnt_sb;     /* pointer to superblock */
8194 diff -NurpP --minimal linux-3.6/include/linux/net.h linux-3.6-vs2.3.4.3-noxfs-nocow/include/linux/net.h
8195 --- linux-3.6/include/linux/net.h       2012-10-04 15:27:46.000000000 +0200
8196 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/include/linux/net.h 2012-10-04 18:47:00.000000000 +0200
8197 @@ -73,6 +73,7 @@ struct net;
8198  #define SOCK_PASSCRED          3
8199  #define SOCK_PASSSEC           4
8200  #define SOCK_EXTERNALLY_ALLOCATED 5
8201 +#define SOCK_USER_SOCKET       6
8202  
8203  #ifndef ARCH_HAS_SOCKET_TYPES
8204  /**
8205 diff -NurpP --minimal linux-3.6/include/linux/netdevice.h linux-3.6-vs2.3.4.3-noxfs-nocow/include/linux/netdevice.h
8206 --- linux-3.6/include/linux/netdevice.h 2012-10-04 15:27:46.000000000 +0200
8207 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/include/linux/netdevice.h   2012-10-04 18:47:00.000000000 +0200
8208 @@ -1651,6 +1651,7 @@ extern void               netdev_resync_ops(struct ne
8209  
8210  extern struct net_device       *dev_get_by_index(struct net *net, int ifindex);
8211  extern struct net_device       *__dev_get_by_index(struct net *net, int ifindex);
8212 +extern struct net_device       *dev_get_by_index_real_rcu(struct net *net, int ifindex);
8213  extern struct net_device       *dev_get_by_index_rcu(struct net *net, int ifindex);
8214  extern int             dev_restart(struct net_device *dev);
8215  #ifdef CONFIG_NETPOLL_TRAP
8216 diff -NurpP --minimal linux-3.6/include/linux/nfs_mount.h linux-3.6-vs2.3.4.3-noxfs-nocow/include/linux/nfs_mount.h
8217 --- linux-3.6/include/linux/nfs_mount.h 2011-01-05 21:50:31.000000000 +0100
8218 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/include/linux/nfs_mount.h   2012-10-04 18:47:00.000000000 +0200
8219 @@ -63,7 +63,8 @@ struct nfs_mount_data {
8220  #define NFS_MOUNT_SECFLAVOUR   0x2000  /* 5 */
8221  #define NFS_MOUNT_NORDIRPLUS   0x4000  /* 5 */
8222  #define NFS_MOUNT_UNSHARED     0x8000  /* 5 */
8223 -#define NFS_MOUNT_FLAGMASK     0xFFFF
8224 +#define NFS_MOUNT_TAGGED       0x10000 /* context tagging */
8225 +#define NFS_MOUNT_FLAGMASK     0x1FFFF
8226  
8227  /* The following are for internal use only */
8228  #define NFS_MOUNT_LOOKUP_CACHE_NONEG   0x10000
8229 diff -NurpP --minimal linux-3.6/include/linux/nsproxy.h linux-3.6-vs2.3.4.3-noxfs-nocow/include/linux/nsproxy.h
8230 --- linux-3.6/include/linux/nsproxy.h   2011-10-24 18:45:32.000000000 +0200
8231 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/include/linux/nsproxy.h     2012-10-04 18:47:00.000000000 +0200
8232 @@ -3,6 +3,7 @@
8233  
8234  #include <linux/spinlock.h>
8235  #include <linux/sched.h>
8236 +#include <linux/vserver/debug.h>
8237  
8238  struct mnt_namespace;
8239  struct uts_namespace;
8240 @@ -63,6 +64,7 @@ static inline struct nsproxy *task_nspro
8241  }
8242  
8243  int copy_namespaces(unsigned long flags, struct task_struct *tsk);
8244 +struct nsproxy *copy_nsproxy(struct nsproxy *orig);
8245  void exit_task_namespaces(struct task_struct *tsk);
8246  void switch_task_namespaces(struct task_struct *tsk, struct nsproxy *new);
8247  void free_nsproxy(struct nsproxy *ns);
8248 @@ -70,16 +72,26 @@ int unshare_nsproxy_namespaces(unsigned 
8249         struct fs_struct *);
8250  int __init nsproxy_cache_init(void);
8251  
8252 -static inline void put_nsproxy(struct nsproxy *ns)
8253 +#define        get_nsproxy(n)  __get_nsproxy(n, __FILE__, __LINE__)
8254 +
8255 +static inline void __get_nsproxy(struct nsproxy *ns,
8256 +       const char *_file, int _line)
8257  {
8258 -       if (atomic_dec_and_test(&ns->count)) {
8259 -               free_nsproxy(ns);
8260 -       }
8261 +       vxlprintk(VXD_CBIT(space, 0), "get_nsproxy(%p[%u])",
8262 +               ns, atomic_read(&ns->count), _file, _line);
8263 +       atomic_inc(&ns->count);
8264  }
8265  
8266 -static inline void get_nsproxy(struct nsproxy *ns)
8267 +#define        put_nsproxy(n)  __put_nsproxy(n, __FILE__, __LINE__)
8268 +
8269 +static inline void __put_nsproxy(struct nsproxy *ns,
8270 +       const char *_file, int _line)
8271  {
8272 -       atomic_inc(&ns->count);
8273 +       vxlprintk(VXD_CBIT(space, 0), "put_nsproxy(%p[%u])",
8274 +               ns, atomic_read(&ns->count), _file, _line);
8275 +       if (atomic_dec_and_test(&ns->count)) {
8276 +               free_nsproxy(ns);
8277 +       }
8278  }
8279  
8280  #endif
8281 diff -NurpP --minimal linux-3.6/include/linux/pid.h linux-3.6-vs2.3.4.3-noxfs-nocow/include/linux/pid.h
8282 --- linux-3.6/include/linux/pid.h       2011-07-22 11:18:11.000000000 +0200
8283 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/include/linux/pid.h 2012-10-04 18:47:00.000000000 +0200
8284 @@ -8,7 +8,8 @@ enum pid_type
8285         PIDTYPE_PID,
8286         PIDTYPE_PGID,
8287         PIDTYPE_SID,
8288 -       PIDTYPE_MAX
8289 +       PIDTYPE_MAX,
8290 +       PIDTYPE_REALPID
8291  };
8292  
8293  /*
8294 @@ -171,6 +172,7 @@ static inline pid_t pid_nr(struct pid *p
8295  }
8296  
8297  pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns);
8298 +pid_t pid_unmapped_nr_ns(struct pid *pid, struct pid_namespace *ns);
8299  pid_t pid_vnr(struct pid *pid);
8300  
8301  #define do_each_pid_task(pid, type, task)                              \
8302 diff -NurpP --minimal linux-3.6/include/linux/proc_fs.h linux-3.6-vs2.3.4.3-noxfs-nocow/include/linux/proc_fs.h
8303 --- linux-3.6/include/linux/proc_fs.h   2012-07-22 23:39:44.000000000 +0200
8304 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/include/linux/proc_fs.h     2012-10-04 18:47:00.000000000 +0200
8305 @@ -54,6 +54,7 @@ struct proc_dir_entry {
8306         nlink_t nlink;
8307         kuid_t uid;
8308         kgid_t gid;
8309 +       int vx_flags;
8310         loff_t size;
8311         const struct inode_operations *proc_iops;
8312         /*
8313 @@ -252,12 +253,18 @@ extern const struct proc_ns_operations n
8314  extern const struct proc_ns_operations utsns_operations;
8315  extern const struct proc_ns_operations ipcns_operations;
8316  
8317 +struct vx_info;
8318 +struct nx_info;
8319 +
8320  union proc_op {
8321         int (*proc_get_link)(struct dentry *, struct path *);
8322         int (*proc_read)(struct task_struct *task, char *page);
8323         int (*proc_show)(struct seq_file *m,
8324                 struct pid_namespace *ns, struct pid *pid,
8325                 struct task_struct *task);
8326 +       int (*proc_vs_read)(char *page);
8327 +       int (*proc_vxi_read)(struct vx_info *vxi, char *page);
8328 +       int (*proc_nxi_read)(struct nx_info *nxi, char *page);
8329  };
8330  
8331  struct ctl_table_header;
8332 @@ -265,6 +272,7 @@ struct ctl_table;
8333  
8334  struct proc_inode {
8335         struct pid *pid;
8336 +       int vx_flags;
8337         int fd;
8338         union proc_op op;
8339         struct proc_dir_entry *pde;
8340 diff -NurpP --minimal linux-3.6/include/linux/quotaops.h linux-3.6-vs2.3.4.3-noxfs-nocow/include/linux/quotaops.h
8341 --- linux-3.6/include/linux/quotaops.h  2012-10-04 15:27:46.000000000 +0200
8342 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/include/linux/quotaops.h    2012-10-04 18:47:00.000000000 +0200
8343 @@ -8,6 +8,7 @@
8344  #define _LINUX_QUOTAOPS_
8345  
8346  #include <linux/fs.h>
8347 +#include <linux/vs_dlimit.h>
8348  
8349  #define DQUOT_SPACE_WARN       0x1
8350  #define DQUOT_SPACE_RESERVE    0x2
8351 @@ -205,11 +206,12 @@ static inline void dquot_drop(struct ino
8352  
8353  static inline int dquot_alloc_inode(const struct inode *inode)
8354  {
8355 -       return 0;
8356 +       return dl_alloc_inode(inode);
8357  }
8358  
8359  static inline void dquot_free_inode(const struct inode *inode)
8360  {
8361 +       dl_free_inode(inode);
8362  }
8363  
8364  static inline int dquot_transfer(struct inode *inode, struct iattr *iattr)
8365 @@ -220,6 +222,10 @@ static inline int dquot_transfer(struct 
8366  static inline int __dquot_alloc_space(struct inode *inode, qsize_t number,
8367                 int flags)
8368  {
8369 +       int ret = 0;
8370 +
8371 +       if ((ret = dl_alloc_space(inode, number)))
8372 +               return ret;
8373         if (!(flags & DQUOT_SPACE_RESERVE))
8374                 inode_add_bytes(inode, number);
8375         return 0;
8376 @@ -230,6 +236,7 @@ static inline void __dquot_free_space(st
8377  {
8378         if (!(flags & DQUOT_SPACE_RESERVE))
8379                 inode_sub_bytes(inode, number);
8380 +       dl_free_space(inode, number);
8381  }
8382  
8383  static inline int dquot_claim_space_nodirty(struct inode *inode, qsize_t number)
8384 diff -NurpP --minimal linux-3.6/include/linux/reboot.h linux-3.6-vs2.3.4.3-noxfs-nocow/include/linux/reboot.h
8385 --- linux-3.6/include/linux/reboot.h    2011-10-24 18:45:32.000000000 +0200
8386 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/include/linux/reboot.h      2012-10-04 18:47:00.000000000 +0200
8387 @@ -33,6 +33,7 @@
8388  #define        LINUX_REBOOT_CMD_RESTART2       0xA1B2C3D4
8389  #define        LINUX_REBOOT_CMD_SW_SUSPEND     0xD000FCE2
8390  #define        LINUX_REBOOT_CMD_KEXEC          0x45584543
8391 +#define        LINUX_REBOOT_CMD_OOM            0xDEADBEEF
8392  
8393  
8394  #ifdef __KERNEL__
8395 diff -NurpP --minimal linux-3.6/include/linux/sched.h linux-3.6-vs2.3.4.3-noxfs-nocow/include/linux/sched.h
8396 --- linux-3.6/include/linux/sched.h     2012-10-04 15:27:46.000000000 +0200
8397 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/include/linux/sched.h       2012-10-04 18:47:00.000000000 +0200
8398 @@ -1422,6 +1422,14 @@ struct task_struct {
8399  #endif
8400         struct seccomp seccomp;
8401  
8402 +/* vserver context data */
8403 +       struct vx_info *vx_info;
8404 +       struct nx_info *nx_info;
8405 +
8406 +       xid_t xid;
8407 +       nid_t nid;
8408 +       tag_t tag;
8409 +
8410  /* Thread group tracking */
8411         u32 parent_exec_id;
8412         u32 self_exec_id;
8413 @@ -1668,6 +1676,11 @@ struct pid_namespace;
8414  pid_t __task_pid_nr_ns(struct task_struct *task, enum pid_type type,
8415                         struct pid_namespace *ns);
8416  
8417 +#include <linux/vserver/base.h>
8418 +#include <linux/vserver/context.h>
8419 +#include <linux/vserver/debug.h>
8420 +#include <linux/vserver/pid.h>
8421 +
8422  static inline pid_t task_pid_nr(struct task_struct *tsk)
8423  {
8424         return tsk->pid;
8425 @@ -1681,7 +1694,8 @@ static inline pid_t task_pid_nr_ns(struc
8426  
8427  static inline pid_t task_pid_vnr(struct task_struct *tsk)
8428  {
8429 -       return __task_pid_nr_ns(tsk, PIDTYPE_PID, NULL);
8430 +       // return __task_pid_nr_ns(tsk, PIDTYPE_PID, NULL);
8431 +       return vx_map_pid(__task_pid_nr_ns(tsk, PIDTYPE_PID, NULL));
8432  }
8433  
8434  
8435 @@ -1694,7 +1708,7 @@ pid_t task_tgid_nr_ns(struct task_struct
8436  
8437  static inline pid_t task_tgid_vnr(struct task_struct *tsk)
8438  {
8439 -       return pid_vnr(task_tgid(tsk));
8440 +       return vx_map_tgid(pid_vnr(task_tgid(tsk)));
8441  }
8442  
8443  
8444 diff -NurpP --minimal linux-3.6/include/linux/shmem_fs.h linux-3.6-vs2.3.4.3-noxfs-nocow/include/linux/shmem_fs.h
8445 --- linux-3.6/include/linux/shmem_fs.h  2012-07-22 23:39:44.000000000 +0200
8446 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/include/linux/shmem_fs.h    2012-10-04 18:47:00.000000000 +0200
8447 @@ -8,6 +8,9 @@
8448  
8449  /* inode in-kernel data */
8450  
8451 +#define TMPFS_SUPER_MAGIC      0x01021994
8452 +
8453 +
8454  struct shmem_inode_info {
8455         spinlock_t              lock;
8456         unsigned long           flags;
8457 diff -NurpP --minimal linux-3.6/include/linux/stat.h linux-3.6-vs2.3.4.3-noxfs-nocow/include/linux/stat.h
8458 --- linux-3.6/include/linux/stat.h      2012-07-22 23:39:44.000000000 +0200
8459 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/include/linux/stat.h        2012-10-04 18:47:00.000000000 +0200
8460 @@ -67,6 +67,7 @@ struct kstat {
8461         unsigned int    nlink;
8462         kuid_t          uid;
8463         kgid_t          gid;
8464 +       tag_t           tag;
8465         dev_t           rdev;
8466         loff_t          size;
8467         struct timespec  atime;
8468 diff -NurpP --minimal linux-3.6/include/linux/sunrpc/auth.h linux-3.6-vs2.3.4.3-noxfs-nocow/include/linux/sunrpc/auth.h
8469 --- linux-3.6/include/linux/sunrpc/auth.h       2012-10-04 15:27:46.000000000 +0200
8470 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/include/linux/sunrpc/auth.h 2012-10-04 18:47:00.000000000 +0200
8471 @@ -25,6 +25,7 @@
8472  struct auth_cred {
8473         uid_t   uid;
8474         gid_t   gid;
8475 +       tag_t   tag;
8476         struct group_info *group_info;
8477         const char *principal;
8478         unsigned char machine_cred : 1;
8479 diff -NurpP --minimal linux-3.6/include/linux/sunrpc/clnt.h linux-3.6-vs2.3.4.3-noxfs-nocow/include/linux/sunrpc/clnt.h
8480 --- linux-3.6/include/linux/sunrpc/clnt.h       2012-05-21 18:07:32.000000000 +0200
8481 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/include/linux/sunrpc/clnt.h 2012-10-04 18:47:00.000000000 +0200
8482 @@ -49,7 +49,8 @@ struct rpc_clnt {
8483         unsigned int            cl_softrtry : 1,/* soft timeouts */
8484                                 cl_discrtry : 1,/* disconnect before retry */
8485                                 cl_autobind : 1,/* use getport() */
8486 -                               cl_chatty   : 1;/* be verbose */
8487 +                               cl_chatty   : 1,/* be verbose */
8488 +                               cl_tag      : 1;/* context tagging */
8489  
8490         struct rpc_rtt *        cl_rtt;         /* RTO estimator data */
8491         const struct rpc_timeout *cl_timeout;   /* Timeout strategy */
8492 diff -NurpP --minimal linux-3.6/include/linux/sysctl.h linux-3.6-vs2.3.4.3-noxfs-nocow/include/linux/sysctl.h
8493 --- linux-3.6/include/linux/sysctl.h    2012-05-21 18:07:32.000000000 +0200
8494 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/include/linux/sysctl.h      2012-10-04 18:47:00.000000000 +0200
8495 @@ -60,6 +60,7 @@ enum
8496         CTL_ABI=9,              /* Binary emulation */
8497         CTL_CPU=10,             /* CPU stuff (speed scaling, etc) */
8498         CTL_ARLAN=254,          /* arlan wireless driver */
8499 +       CTL_VSERVER=4242,       /* Linux-VServer debug */
8500         CTL_S390DBF=5677,       /* s390 debug */
8501         CTL_SUNRPC=7249,        /* sunrpc debug */
8502         CTL_PM=9899,            /* frv power management */
8503 @@ -94,6 +95,7 @@ enum
8504  
8505         KERN_PANIC=15,          /* int: panic timeout */
8506         KERN_REALROOTDEV=16,    /* real root device to mount after initrd */
8507 +       KERN_VSHELPER=17,       /* string: path to vshelper policy agent */
8508  
8509         KERN_SPARC_REBOOT=21,   /* reboot command on Sparc */
8510         KERN_CTLALTDEL=22,      /* int: allow ctl-alt-del to reboot */
8511 diff -NurpP --minimal linux-3.6/include/linux/sysfs.h linux-3.6-vs2.3.4.3-noxfs-nocow/include/linux/sysfs.h
8512 --- linux-3.6/include/linux/sysfs.h     2012-07-22 23:39:44.000000000 +0200
8513 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/include/linux/sysfs.h       2012-10-04 18:47:00.000000000 +0200
8514 @@ -19,6 +19,8 @@
8515  #include <linux/kobject_ns.h>
8516  #include <linux/atomic.h>
8517  
8518 +#define SYSFS_SUPER_MAGIC      0x62656572
8519 +
8520  struct kobject;
8521  struct module;
8522  enum kobj_ns_type;
8523 diff -NurpP --minimal linux-3.6/include/linux/time.h linux-3.6-vs2.3.4.3-noxfs-nocow/include/linux/time.h
8524 --- linux-3.6/include/linux/time.h      2012-10-04 15:27:46.000000000 +0200
8525 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/include/linux/time.h        2012-10-04 18:47:00.000000000 +0200
8526 @@ -280,6 +280,8 @@ static __always_inline void timespec_add
8527         a->tv_nsec = ns;
8528  }
8529  
8530 +#include <linux/vs_time.h>
8531 +
8532  #endif /* __KERNEL__ */
8533  
8534  /*
8535 diff -NurpP --minimal linux-3.6/include/linux/types.h linux-3.6-vs2.3.4.3-noxfs-nocow/include/linux/types.h
8536 --- linux-3.6/include/linux/types.h     2012-10-04 15:27:47.000000000 +0200
8537 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/include/linux/types.h       2012-10-04 18:47:00.000000000 +0200
8538 @@ -41,6 +41,9 @@ typedef __kernel_uid32_t      uid_t;
8539  typedef __kernel_gid32_t       gid_t;
8540  typedef __kernel_uid16_t        uid16_t;
8541  typedef __kernel_gid16_t        gid16_t;
8542 +typedef unsigned int           xid_t;
8543 +typedef unsigned int           nid_t;
8544 +typedef unsigned int           tag_t;
8545  
8546  typedef unsigned long          uintptr_t;
8547  
8548 diff -NurpP --minimal linux-3.6/include/linux/utsname.h linux-3.6-vs2.3.4.3-noxfs-nocow/include/linux/utsname.h
8549 --- linux-3.6/include/linux/utsname.h   2012-01-09 16:14:59.000000000 +0100
8550 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/include/linux/utsname.h     2012-10-04 18:47:00.000000000 +0200
8551 @@ -62,7 +62,8 @@ static inline void get_uts_ns(struct uts
8552  }
8553  
8554  extern struct uts_namespace *copy_utsname(unsigned long flags,
8555 -                                         struct task_struct *tsk);
8556 +                                         struct uts_namespace *old_ns,
8557 +                                         struct user_namespace *user_ns);
8558  extern void free_uts_ns(struct kref *kref);
8559  
8560  static inline void put_uts_ns(struct uts_namespace *ns)
8561 @@ -79,12 +80,13 @@ static inline void put_uts_ns(struct uts
8562  }
8563  
8564  static inline struct uts_namespace *copy_utsname(unsigned long flags,
8565 -                                                struct task_struct *tsk)
8566 +                                                struct uts_namespace *old_ns,
8567 +                                                struct user_namespace *user_ns)
8568  {
8569         if (flags & CLONE_NEWUTS)
8570                 return ERR_PTR(-EINVAL);
8571  
8572 -       return tsk->nsproxy->uts_ns;
8573 +       return old_ns;
8574  }
8575  #endif
8576  
8577 diff -NurpP --minimal linux-3.6/include/linux/vroot.h linux-3.6-vs2.3.4.3-noxfs-nocow/include/linux/vroot.h
8578 --- linux-3.6/include/linux/vroot.h     1970-01-01 01:00:00.000000000 +0100
8579 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/include/linux/vroot.h       2012-10-04 18:47:00.000000000 +0200
8580 @@ -0,0 +1,51 @@
8581 +
8582 +/*
8583 + * include/linux/vroot.h
8584 + *
8585 + * written by Herbert Pötzl, 9/11/2002
8586 + * ported to 2.6 by Herbert Pötzl, 30/12/2004
8587 + *
8588 + * Copyright (C) 2002-2007 by Herbert Pötzl.
8589 + * Redistribution of this file is permitted under the
8590 + * GNU General Public License.
8591 + */
8592 +
8593 +#ifndef _LINUX_VROOT_H
8594 +#define _LINUX_VROOT_H
8595 +
8596 +
8597 +#ifdef __KERNEL__
8598 +
8599 +/* Possible states of device */
8600 +enum {
8601 +       Vr_unbound,
8602 +       Vr_bound,
8603 +};
8604 +
8605 +struct vroot_device {
8606 +       int             vr_number;
8607 +       int             vr_refcnt;
8608 +
8609 +       struct semaphore        vr_ctl_mutex;
8610 +       struct block_device    *vr_device;
8611 +       int                     vr_state;
8612 +};
8613 +
8614 +
8615 +typedef struct block_device *(vroot_grb_func)(struct block_device *);
8616 +
8617 +extern int register_vroot_grb(vroot_grb_func *);
8618 +extern int unregister_vroot_grb(vroot_grb_func *);
8619 +
8620 +#endif /* __KERNEL__ */
8621 +
8622 +#define MAX_VROOT_DEFAULT      8
8623 +
8624 +/*
8625 + * IOCTL commands --- we will commandeer 0x56 ('V')
8626 + */
8627 +
8628 +#define VROOT_SET_DEV          0x5600
8629 +#define VROOT_CLR_DEV          0x5601
8630 +
8631 +#endif /* _LINUX_VROOT_H */
8632 diff -NurpP --minimal linux-3.6/include/linux/vs_base.h linux-3.6-vs2.3.4.3-noxfs-nocow/include/linux/vs_base.h
8633 --- linux-3.6/include/linux/vs_base.h   1970-01-01 01:00:00.000000000 +0100
8634 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/include/linux/vs_base.h     2012-10-04 18:47:00.000000000 +0200
8635 @@ -0,0 +1,10 @@
8636 +#ifndef _VS_BASE_H
8637 +#define _VS_BASE_H
8638 +
8639 +#include "vserver/base.h"
8640 +#include "vserver/check.h"
8641 +#include "vserver/debug.h"
8642 +
8643 +#else
8644 +#warning duplicate inclusion
8645 +#endif
8646 diff -NurpP --minimal linux-3.6/include/linux/vs_context.h linux-3.6-vs2.3.4.3-noxfs-nocow/include/linux/vs_context.h
8647 --- linux-3.6/include/linux/vs_context.h        1970-01-01 01:00:00.000000000 +0100
8648 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/include/linux/vs_context.h  2012-10-04 18:47:00.000000000 +0200
8649 @@ -0,0 +1,242 @@
8650 +#ifndef _VS_CONTEXT_H
8651 +#define _VS_CONTEXT_H
8652 +
8653 +#include "vserver/base.h"
8654 +#include "vserver/check.h"
8655 +#include "vserver/context.h"
8656 +#include "vserver/history.h"
8657 +#include "vserver/debug.h"
8658 +
8659 +#include <linux/sched.h>
8660 +
8661 +
8662 +#define get_vx_info(i) __get_vx_info(i, __FILE__, __LINE__, __HERE__)
8663 +
8664 +static inline struct vx_info *__get_vx_info(struct vx_info *vxi,
8665 +       const char *_file, int _line, void *_here)
8666 +{
8667 +       if (!vxi)
8668 +               return NULL;
8669 +
8670 +       vxlprintk(VXD_CBIT(xid, 2), "get_vx_info(%p[#%d.%d])",
8671 +               vxi, vxi ? vxi->vx_id : 0,
8672 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
8673 +               _file, _line);
8674 +       __vxh_get_vx_info(vxi, _here);
8675 +
8676 +       atomic_inc(&vxi->vx_usecnt);
8677 +       return vxi;
8678 +}
8679 +
8680 +
8681 +extern void free_vx_info(struct vx_info *);
8682 +
8683 +#define put_vx_info(i) __put_vx_info(i, __FILE__, __LINE__, __HERE__)
8684 +
8685 +static inline void __put_vx_info(struct vx_info *vxi,
8686 +       const char *_file, int _line, void *_here)
8687 +{
8688 +       if (!vxi)
8689 +               return;
8690 +
8691 +       vxlprintk(VXD_CBIT(xid, 2), "put_vx_info(%p[#%d.%d])",
8692 +               vxi, vxi ? vxi->vx_id : 0,
8693 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
8694 +               _file, _line);
8695 +       __vxh_put_vx_info(vxi, _here);
8696 +
8697 +       if (atomic_dec_and_test(&vxi->vx_usecnt))
8698 +               free_vx_info(vxi);
8699 +}
8700 +
8701 +
8702 +#define init_vx_info(p, i) \
8703 +       __init_vx_info(p, i, __FILE__, __LINE__, __HERE__)
8704 +
8705 +static inline void __init_vx_info(struct vx_info **vxp, struct vx_info *vxi,
8706 +       const char *_file, int _line, void *_here)
8707 +{
8708 +       if (vxi) {
8709 +               vxlprintk(VXD_CBIT(xid, 3),
8710 +                       "init_vx_info(%p[#%d.%d])",
8711 +                       vxi, vxi ? vxi->vx_id : 0,
8712 +                       vxi ? atomic_read(&vxi->vx_usecnt) : 0,
8713 +                       _file, _line);
8714 +               __vxh_init_vx_info(vxi, vxp, _here);
8715 +
8716 +               atomic_inc(&vxi->vx_usecnt);
8717 +       }
8718 +       *vxp = vxi;
8719 +}
8720 +
8721 +
8722 +#define set_vx_info(p, i) \
8723 +       __set_vx_info(p, i, __FILE__, __LINE__, __HERE__)
8724 +
8725 +static inline void __set_vx_info(struct vx_info **vxp, struct vx_info *vxi,
8726 +       const char *_file, int _line, void *_here)
8727 +{
8728 +       struct vx_info *vxo;
8729 +
8730 +       if (!vxi)
8731 +               return;
8732 +
8733 +       vxlprintk(VXD_CBIT(xid, 3), "set_vx_info(%p[#%d.%d])",
8734 +               vxi, vxi ? vxi->vx_id : 0,
8735 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
8736 +               _file, _line);
8737 +       __vxh_set_vx_info(vxi, vxp, _here);
8738 +
8739 +       atomic_inc(&vxi->vx_usecnt);
8740 +       vxo = xchg(vxp, vxi);
8741 +       BUG_ON(vxo);
8742 +}
8743 +
8744 +
8745 +#define clr_vx_info(p) __clr_vx_info(p, __FILE__, __LINE__, __HERE__)
8746 +
8747 +static inline void __clr_vx_info(struct vx_info **vxp,
8748 +       const char *_file, int _line, void *_here)
8749 +{
8750 +       struct vx_info *vxo;
8751 +
8752 +       vxo = xchg(vxp, NULL);
8753 +       if (!vxo)
8754 +               return;
8755 +
8756 +       vxlprintk(VXD_CBIT(xid, 3), "clr_vx_info(%p[#%d.%d])",
8757 +               vxo, vxo ? vxo->vx_id : 0,
8758 +               vxo ? atomic_read(&vxo->vx_usecnt) : 0,
8759 +               _file, _line);
8760 +       __vxh_clr_vx_info(vxo, vxp, _here);
8761 +
8762 +       if (atomic_dec_and_test(&vxo->vx_usecnt))
8763 +               free_vx_info(vxo);
8764 +}
8765 +
8766 +
8767 +#define claim_vx_info(v, p) \
8768 +       __claim_vx_info(v, p, __FILE__, __LINE__, __HERE__)
8769 +
8770 +static inline void __claim_vx_info(struct vx_info *vxi,
8771 +       struct task_struct *task,
8772 +       const char *_file, int _line, void *_here)
8773 +{
8774 +       vxlprintk(VXD_CBIT(xid, 3), "claim_vx_info(%p[#%d.%d.%d]) %p",
8775 +               vxi, vxi ? vxi->vx_id : 0,
8776 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
8777 +               vxi ? atomic_read(&vxi->vx_tasks) : 0,
8778 +               task, _file, _line);
8779 +       __vxh_claim_vx_info(vxi, task, _here);
8780 +
8781 +       atomic_inc(&vxi->vx_tasks);
8782 +}
8783 +
8784 +
8785 +extern void unhash_vx_info(struct vx_info *);
8786 +
8787 +#define release_vx_info(v, p) \
8788 +       __release_vx_info(v, p, __FILE__, __LINE__, __HERE__)
8789 +
8790 +static inline void __release_vx_info(struct vx_info *vxi,
8791 +       struct task_struct *task,
8792 +       const char *_file, int _line, void *_here)
8793 +{
8794 +       vxlprintk(VXD_CBIT(xid, 3), "release_vx_info(%p[#%d.%d.%d]) %p",
8795 +               vxi, vxi ? vxi->vx_id : 0,
8796 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
8797 +               vxi ? atomic_read(&vxi->vx_tasks) : 0,
8798 +               task, _file, _line);
8799 +       __vxh_release_vx_info(vxi, task, _here);
8800 +
8801 +       might_sleep();
8802 +
8803 +       if (atomic_dec_and_test(&vxi->vx_tasks))
8804 +               unhash_vx_info(vxi);
8805 +}
8806 +
8807 +
8808 +#define task_get_vx_info(p) \
8809 +       __task_get_vx_info(p, __FILE__, __LINE__, __HERE__)
8810 +
8811 +static inline struct vx_info *__task_get_vx_info(struct task_struct *p,
8812 +       const char *_file, int _line, void *_here)
8813 +{
8814 +       struct vx_info *vxi;
8815 +
8816 +       task_lock(p);
8817 +       vxlprintk(VXD_CBIT(xid, 5), "task_get_vx_info(%p)",
8818 +               p, _file, _line);
8819 +       vxi = __get_vx_info(p->vx_info, _file, _line, _here);
8820 +       task_unlock(p);
8821 +       return vxi;
8822 +}
8823 +
8824 +
8825 +static inline void __wakeup_vx_info(struct vx_info *vxi)
8826 +{
8827 +       if (waitqueue_active(&vxi->vx_wait))
8828 +               wake_up_interruptible(&vxi->vx_wait);
8829 +}
8830 +
8831 +
8832 +#define enter_vx_info(v, s) __enter_vx_info(v, s, __FILE__, __LINE__)
8833 +
8834 +static inline void __enter_vx_info(struct vx_info *vxi,
8835 +       struct vx_info_save *vxis, const char *_file, int _line)
8836 +{
8837 +       vxlprintk(VXD_CBIT(xid, 5), "enter_vx_info(%p[#%d],%p) %p[#%d,%p]",
8838 +               vxi, vxi ? vxi->vx_id : 0, vxis, current,
8839 +               current->xid, current->vx_info, _file, _line);
8840 +       vxis->vxi = xchg(&current->vx_info, vxi);
8841 +       vxis->xid = current->xid;
8842 +       current->xid = vxi ? vxi->vx_id : 0;
8843 +}
8844 +
8845 +#define leave_vx_info(s) __leave_vx_info(s, __FILE__, __LINE__)
8846 +
8847 +static inline void __leave_vx_info(struct vx_info_save *vxis,
8848 +       const char *_file, int _line)
8849 +{
8850 +       vxlprintk(VXD_CBIT(xid, 5), "leave_vx_info(%p[#%d,%p]) %p[#%d,%p]",
8851 +               vxis, vxis->xid, vxis->vxi, current,
8852 +               current->xid, current->vx_info, _file, _line);
8853 +       (void)xchg(&current->vx_info, vxis->vxi);
8854 +       current->xid = vxis->xid;
8855 +}
8856 +
8857 +
8858 +static inline void __enter_vx_admin(struct vx_info_save *vxis)
8859 +{
8860 +       vxis->vxi = xchg(&current->vx_info, NULL);
8861 +       vxis->xid = xchg(&current->xid, (xid_t)0);
8862 +}
8863 +
8864 +static inline void __leave_vx_admin(struct vx_info_save *vxis)
8865 +{
8866 +       (void)xchg(&current->xid, vxis->xid);
8867 +       (void)xchg(&current->vx_info, vxis->vxi);
8868 +}
8869 +
8870 +#define task_is_init(p) \
8871 +       __task_is_init(p, __FILE__, __LINE__, __HERE__)
8872 +
8873 +static inline int __task_is_init(struct task_struct *p,
8874 +       const char *_file, int _line, void *_here)
8875 +{
8876 +       int is_init = is_global_init(p);
8877 +
8878 +       task_lock(p);
8879 +       if (p->vx_info)
8880 +               is_init = p->vx_info->vx_initpid == p->pid;
8881 +       task_unlock(p);
8882 +       return is_init;
8883 +}
8884 +
8885 +extern void exit_vx_info(struct task_struct *, int);
8886 +extern void exit_vx_info_early(struct task_struct *, int);
8887 +
8888 +
8889 +#else
8890 +#warning duplicate inclusion
8891 +#endif
8892 diff -NurpP --minimal linux-3.6/include/linux/vs_cowbl.h linux-3.6-vs2.3.4.3-noxfs-nocow/include/linux/vs_cowbl.h
8893 --- linux-3.6/include/linux/vs_cowbl.h  1970-01-01 01:00:00.000000000 +0100
8894 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/include/linux/vs_cowbl.h    2012-10-04 18:47:00.000000000 +0200
8895 @@ -0,0 +1,48 @@
8896 +#ifndef _VS_COWBL_H
8897 +#define _VS_COWBL_H
8898 +
8899 +#include <linux/fs.h>
8900 +#include <linux/dcache.h>
8901 +#include <linux/namei.h>
8902 +#include <linux/slab.h>
8903 +
8904 +extern struct dentry *cow_break_link(const char *pathname);
8905 +
8906 +static inline int cow_check_and_break(struct path *path)
8907 +{
8908 +       struct inode *inode = path->dentry->d_inode;
8909 +       int error = 0;
8910 +
8911 +       /* do we need this check? */
8912 +       if (IS_RDONLY(inode))
8913 +               return -EROFS;
8914 +
8915 +       if (IS_COW(inode)) {
8916 +               if (IS_COW_LINK(inode)) {
8917 +                       struct dentry *new_dentry, *old_dentry = path->dentry;
8918 +                       char *pp, *buf;
8919 +
8920 +                       buf = kmalloc(PATH_MAX, GFP_KERNEL);
8921 +                       if (!buf) {
8922 +                               return -ENOMEM;
8923 +                       }
8924 +                       pp = d_path(path, buf, PATH_MAX);
8925 +                       new_dentry = cow_break_link(pp);
8926 +                       kfree(buf);
8927 +                       if (!IS_ERR(new_dentry)) {
8928 +                               path->dentry = new_dentry;
8929 +                               dput(old_dentry);
8930 +                       } else
8931 +                               error = PTR_ERR(new_dentry);
8932 +               } else {
8933 +                       inode->i_flags &= ~(S_IXUNLINK | S_IMMUTABLE);
8934 +                       inode->i_ctime = CURRENT_TIME;
8935 +                       mark_inode_dirty(inode);
8936 +               }
8937 +       }
8938 +       return error;
8939 +}
8940 +
8941 +#else
8942 +#warning duplicate inclusion
8943 +#endif
8944 diff -NurpP --minimal linux-3.6/include/linux/vs_cvirt.h linux-3.6-vs2.3.4.3-noxfs-nocow/include/linux/vs_cvirt.h
8945 --- linux-3.6/include/linux/vs_cvirt.h  1970-01-01 01:00:00.000000000 +0100
8946 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/include/linux/vs_cvirt.h    2012-10-04 18:47:00.000000000 +0200
8947 @@ -0,0 +1,50 @@
8948 +#ifndef _VS_CVIRT_H
8949 +#define _VS_CVIRT_H
8950 +
8951 +#include "vserver/cvirt.h"
8952 +#include "vserver/context.h"
8953 +#include "vserver/base.h"
8954 +#include "vserver/check.h"
8955 +#include "vserver/debug.h"
8956 +
8957 +
8958 +static inline void vx_activate_task(struct task_struct *p)
8959 +{
8960 +       struct vx_info *vxi;
8961 +
8962 +       if ((vxi = p->vx_info)) {
8963 +               vx_update_load(vxi);
8964 +               atomic_inc(&vxi->cvirt.nr_running);
8965 +       }
8966 +}
8967 +
8968 +static inline void vx_deactivate_task(struct task_struct *p)
8969 +{
8970 +       struct vx_info *vxi;
8971 +
8972 +       if ((vxi = p->vx_info)) {
8973 +               vx_update_load(vxi);
8974 +               atomic_dec(&vxi->cvirt.nr_running);
8975 +       }
8976 +}
8977 +
8978 +static inline void vx_uninterruptible_inc(struct task_struct *p)
8979 +{
8980 +       struct vx_info *vxi;
8981 +
8982 +       if ((vxi = p->vx_info))
8983 +               atomic_inc(&vxi->cvirt.nr_uninterruptible);
8984 +}
8985 +
8986 +static inline void vx_uninterruptible_dec(struct task_struct *p)
8987 +{
8988 +       struct vx_info *vxi;
8989 +
8990 +       if ((vxi = p->vx_info))
8991 +               atomic_dec(&vxi->cvirt.nr_uninterruptible);
8992 +}
8993 +
8994 +
8995 +#else
8996 +#warning duplicate inclusion
8997 +#endif
8998 diff -NurpP --minimal linux-3.6/include/linux/vs_device.h linux-3.6-vs2.3.4.3-noxfs-nocow/include/linux/vs_device.h
8999 --- linux-3.6/include/linux/vs_device.h 1970-01-01 01:00:00.000000000 +0100
9000 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/include/linux/vs_device.h   2012-10-04 18:47:00.000000000 +0200
9001 @@ -0,0 +1,45 @@
9002 +#ifndef _VS_DEVICE_H
9003 +#define _VS_DEVICE_H
9004 +
9005 +#include "vserver/base.h"
9006 +#include "vserver/device.h"
9007 +#include "vserver/debug.h"
9008 +
9009 +
9010 +#ifdef CONFIG_VSERVER_DEVICE
9011 +
9012 +int vs_map_device(struct vx_info *, dev_t, dev_t *, umode_t);
9013 +
9014 +#define vs_device_perm(v, d, m, p) \
9015 +       ((vs_map_device(current_vx_info(), d, NULL, m) & (p)) == (p))
9016 +
9017 +#else
9018 +
9019 +static inline
9020 +int vs_map_device(struct vx_info *vxi,
9021 +       dev_t device, dev_t *target, umode_t mode)
9022 +{
9023 +       if (target)
9024 +               *target = device;
9025 +       return ~0;
9026 +}
9027 +
9028 +#define vs_device_perm(v, d, m, p) ((p) == (p))
9029 +
9030 +#endif
9031 +
9032 +
9033 +#define vs_map_chrdev(d, t, p) \
9034 +       ((vs_map_device(current_vx_info(), d, t, S_IFCHR) & (p)) == (p))
9035 +#define vs_map_blkdev(d, t, p) \
9036 +       ((vs_map_device(current_vx_info(), d, t, S_IFBLK) & (p)) == (p))
9037 +
9038 +#define vs_chrdev_perm(d, p) \
9039 +       vs_device_perm(current_vx_info(), d, S_IFCHR, p)
9040 +#define vs_blkdev_perm(d, p) \
9041 +       vs_device_perm(current_vx_info(), d, S_IFBLK, p)
9042 +
9043 +
9044 +#else
9045 +#warning duplicate inclusion
9046 +#endif
9047 diff -NurpP --minimal linux-3.6/include/linux/vs_dlimit.h linux-3.6-vs2.3.4.3-noxfs-nocow/include/linux/vs_dlimit.h
9048 --- linux-3.6/include/linux/vs_dlimit.h 1970-01-01 01:00:00.000000000 +0100
9049 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/include/linux/vs_dlimit.h   2012-10-04 18:47:00.000000000 +0200
9050 @@ -0,0 +1,215 @@
9051 +#ifndef _VS_DLIMIT_H
9052 +#define _VS_DLIMIT_H
9053 +
9054 +#include <linux/fs.h>
9055 +
9056 +#include "vserver/dlimit.h"
9057 +#include "vserver/base.h"
9058 +#include "vserver/debug.h"
9059 +
9060 +
9061 +#define get_dl_info(i) __get_dl_info(i, __FILE__, __LINE__)
9062 +
9063 +static inline struct dl_info *__get_dl_info(struct dl_info *dli,
9064 +       const char *_file, int _line)
9065 +{
9066 +       if (!dli)
9067 +               return NULL;
9068 +       vxlprintk(VXD_CBIT(dlim, 4), "get_dl_info(%p[#%d.%d])",
9069 +               dli, dli ? dli->dl_tag : 0,
9070 +               dli ? atomic_read(&dli->dl_usecnt) : 0,
9071 +               _file, _line);
9072 +       atomic_inc(&dli->dl_usecnt);
9073 +       return dli;
9074 +}
9075 +
9076 +
9077 +#define free_dl_info(i) \
9078 +       call_rcu(&(i)->dl_rcu, rcu_free_dl_info)
9079 +
9080 +#define put_dl_info(i) __put_dl_info(i, __FILE__, __LINE__)
9081 +
9082 +static inline void __put_dl_info(struct dl_info *dli,
9083 +       const char *_file, int _line)
9084 +{
9085 +       if (!dli)
9086 +               return;
9087 +       vxlprintk(VXD_CBIT(dlim, 4), "put_dl_info(%p[#%d.%d])",
9088 +               dli, dli ? dli->dl_tag : 0,
9089 +               dli ? atomic_read(&dli->dl_usecnt) : 0,
9090 +               _file, _line);
9091 +       if (atomic_dec_and_test(&dli->dl_usecnt))
9092 +               free_dl_info(dli);
9093 +}
9094 +
9095 +
9096 +#define __dlimit_char(d)       ((d) ? '*' : ' ')
9097 +
9098 +static inline int __dl_alloc_space(struct super_block *sb,
9099 +       tag_t tag, dlsize_t nr, const char *file, int line)
9100 +{
9101 +       struct dl_info *dli = NULL;
9102 +       int ret = 0;
9103 +
9104 +       if (nr == 0)
9105 +               goto out;
9106 +       dli = locate_dl_info(sb, tag);
9107 +       if (!dli)
9108 +               goto out;
9109 +
9110 +       spin_lock(&dli->dl_lock);
9111 +       ret = (dli->dl_space_used + nr > dli->dl_space_total);
9112 +       if (!ret)
9113 +               dli->dl_space_used += nr;
9114 +       spin_unlock(&dli->dl_lock);
9115 +       put_dl_info(dli);
9116 +out:
9117 +       vxlprintk(VXD_CBIT(dlim, 1),
9118 +               "ALLOC (%p,#%d)%c %lld bytes (%d)",
9119 +               sb, tag, __dlimit_char(dli), (long long)nr,
9120 +               ret, file, line);
9121 +       return ret ? -ENOSPC : 0;
9122 +}
9123 +
9124 +static inline void __dl_free_space(struct super_block *sb,
9125 +       tag_t tag, dlsize_t nr, const char *_file, int _line)
9126 +{
9127 +       struct dl_info *dli = NULL;
9128 +
9129 +       if (nr == 0)
9130 +               goto out;
9131 +       dli = locate_dl_info(sb, tag);
9132 +       if (!dli)
9133 +               goto out;
9134 +
9135 +       spin_lock(&dli->dl_lock);
9136 +       if (dli->dl_space_used > nr)
9137 +               dli->dl_space_used -= nr;
9138 +       else
9139 +               dli->dl_space_used = 0;
9140 +       spin_unlock(&dli->dl_lock);
9141 +       put_dl_info(dli);
9142 +out:
9143 +       vxlprintk(VXD_CBIT(dlim, 1),
9144 +               "FREE  (%p,#%d)%c %lld bytes",
9145 +               sb, tag, __dlimit_char(dli), (long long)nr,
9146 +               _file, _line);
9147 +}
9148 +
9149 +static inline int __dl_alloc_inode(struct super_block *sb,
9150 +       tag_t tag, const char *_file, int _line)
9151 +{
9152 +       struct dl_info *dli;
9153 +       int ret = 0;
9154 +
9155 +       dli = locate_dl_info(sb, tag);
9156 +       if (!dli)
9157 +               goto out;
9158 +
9159 +       spin_lock(&dli->dl_lock);
9160 +       dli->dl_inodes_used++;
9161 +       ret = (dli->dl_inodes_used > dli->dl_inodes_total);
9162 +       spin_unlock(&dli->dl_lock);
9163 +       put_dl_info(dli);
9164 +out:
9165 +       vxlprintk(VXD_CBIT(dlim, 0),
9166 +               "ALLOC (%p,#%d)%c inode (%d)",
9167 +               sb, tag, __dlimit_char(dli), ret, _file, _line);
9168 +       return ret ? -ENOSPC : 0;
9169 +}
9170 +
9171 +static inline void __dl_free_inode(struct super_block *sb,
9172 +       tag_t tag, const char *_file, int _line)
9173 +{
9174 +       struct dl_info *dli;
9175 +
9176 +       dli = locate_dl_info(sb, tag);
9177 +       if (!dli)
9178 +               goto out;
9179 +
9180 +       spin_lock(&dli->dl_lock);
9181 +       if (dli->dl_inodes_used > 1)
9182 +               dli->dl_inodes_used--;
9183 +       else
9184 +               dli->dl_inodes_used = 0;
9185 +       spin_unlock(&dli->dl_lock);
9186 +       put_dl_info(dli);
9187 +out:
9188 +       vxlprintk(VXD_CBIT(dlim, 0),
9189 +               "FREE  (%p,#%d)%c inode",
9190 +               sb, tag, __dlimit_char(dli), _file, _line);
9191 +}
9192 +
9193 +static inline void __dl_adjust_block(struct super_block *sb, tag_t tag,
9194 +       unsigned long long *free_blocks, unsigned long long *root_blocks,
9195 +       const char *_file, int _line)
9196 +{
9197 +       struct dl_info *dli;
9198 +       uint64_t broot, bfree;
9199 +
9200 +       dli = locate_dl_info(sb, tag);
9201 +       if (!dli)
9202 +               return;
9203 +
9204 +       spin_lock(&dli->dl_lock);
9205 +       broot = (dli->dl_space_total -
9206 +               (dli->dl_space_total >> 10) * dli->dl_nrlmult)
9207 +               >> sb->s_blocksize_bits;
9208 +       bfree = (dli->dl_space_total - dli->dl_space_used)
9209 +                       >> sb->s_blocksize_bits;
9210 +       spin_unlock(&dli->dl_lock);
9211 +
9212 +       vxlprintk(VXD_CBIT(dlim, 2),
9213 +               "ADJUST: %lld,%lld on %lld,%lld [mult=%d]",
9214 +               (long long)bfree, (long long)broot,
9215 +               *free_blocks, *root_blocks, dli->dl_nrlmult,
9216 +               _file, _line);
9217 +       if (free_blocks) {
9218 +               if (*free_blocks > bfree)
9219 +                       *free_blocks = bfree;
9220 +       }
9221 +       if (root_blocks) {
9222 +               if (*root_blocks > broot)
9223 +                       *root_blocks = broot;
9224 +       }
9225 +       put_dl_info(dli);
9226 +}
9227 +
9228 +#define dl_prealloc_space(in, bytes) \
9229 +       __dl_alloc_space((in)->i_sb, (in)->i_tag, (dlsize_t)(bytes), \
9230 +               __FILE__, __LINE__ )
9231 +
9232 +#define dl_alloc_space(in, bytes) \
9233 +       __dl_alloc_space((in)->i_sb, (in)->i_tag, (dlsize_t)(bytes), \
9234 +               __FILE__, __LINE__ )
9235 +
9236 +#define dl_reserve_space(in, bytes) \
9237 +       __dl_alloc_space((in)->i_sb, (in)->i_tag, (dlsize_t)(bytes), \
9238 +               __FILE__, __LINE__ )
9239 +
9240 +#define dl_claim_space(in, bytes) (0)
9241 +
9242 +#define dl_release_space(in, bytes) \
9243 +       __dl_free_space((in)->i_sb, (in)->i_tag, (dlsize_t)(bytes), \
9244 +               __FILE__, __LINE__ )
9245 +
9246 +#define dl_free_space(in, bytes) \
9247 +       __dl_free_space((in)->i_sb, (in)->i_tag, (dlsize_t)(bytes), \
9248 +               __FILE__, __LINE__ )
9249 +
9250 +
9251 +
9252 +#define dl_alloc_inode(in) \
9253 +       __dl_alloc_inode((in)->i_sb, (in)->i_tag, __FILE__, __LINE__ )
9254 +
9255 +#define dl_free_inode(in) \
9256 +       __dl_free_inode((in)->i_sb, (in)->i_tag, __FILE__, __LINE__ )
9257 +
9258 +
9259 +#define dl_adjust_block(sb, tag, fb, rb) \
9260 +       __dl_adjust_block(sb, tag, fb, rb, __FILE__, __LINE__ )
9261 +
9262 +
9263 +#else
9264 +#warning duplicate inclusion
9265 +#endif
9266 diff -NurpP --minimal linux-3.6/include/linux/vs_inet.h linux-3.6-vs2.3.4.3-noxfs-nocow/include/linux/vs_inet.h
9267 --- linux-3.6/include/linux/vs_inet.h   1970-01-01 01:00:00.000000000 +0100
9268 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/include/linux/vs_inet.h     2012-10-04 18:47:00.000000000 +0200
9269 @@ -0,0 +1,353 @@
9270 +#ifndef _VS_INET_H
9271 +#define _VS_INET_H
9272 +
9273 +#include "vserver/base.h"
9274 +#include "vserver/network.h"
9275 +#include "vserver/debug.h"
9276 +
9277 +#define IPI_LOOPBACK   htonl(INADDR_LOOPBACK)
9278 +
9279 +#define NXAV4(a)       NIPQUAD((a)->ip[0]), NIPQUAD((a)->ip[1]), \
9280 +                       NIPQUAD((a)->mask), (a)->type
9281 +#define NXAV4_FMT      "[" NIPQUAD_FMT "-" NIPQUAD_FMT "/" NIPQUAD_FMT ":%04x]"
9282 +
9283 +#define NIPQUAD(addr) \
9284 +       ((unsigned char *)&addr)[0], \
9285 +       ((unsigned char *)&addr)[1], \
9286 +       ((unsigned char *)&addr)[2], \
9287 +       ((unsigned char *)&addr)[3]
9288 +
9289 +#define NIPQUAD_FMT "%u.%u.%u.%u"
9290 +
9291 +
9292 +static inline
9293 +int v4_addr_match(struct nx_addr_v4 *nxa, __be32 addr, uint16_t tmask)
9294 +{
9295 +       __be32 ip = nxa->ip[0].s_addr;
9296 +       __be32 mask = nxa->mask.s_addr;
9297 +       __be32 bcast = ip | ~mask;
9298 +       int ret = 0;
9299 +
9300 +       switch (nxa->type & tmask) {
9301 +       case NXA_TYPE_MASK:
9302 +               ret = (ip == (addr & mask));
9303 +               break;
9304 +       case NXA_TYPE_ADDR:
9305 +               ret = 3;
9306 +               if (addr == ip)
9307 +                       break;
9308 +               /* fall through to broadcast */
9309 +       case NXA_MOD_BCAST:
9310 +               ret = ((tmask & NXA_MOD_BCAST) && (addr == bcast));
9311 +               break;
9312 +       case NXA_TYPE_RANGE:
9313 +               ret = ((nxa->ip[0].s_addr <= addr) &&
9314 +                       (nxa->ip[1].s_addr > addr));
9315 +               break;
9316 +       case NXA_TYPE_ANY:
9317 +               ret = 2;
9318 +               break;
9319 +       }
9320 +
9321 +       vxdprintk(VXD_CBIT(net, 0),
9322 +               "v4_addr_match(%p" NXAV4_FMT "," NIPQUAD_FMT ",%04x) = %d",
9323 +               nxa, NXAV4(nxa), NIPQUAD(addr), tmask, ret);
9324 +       return ret;
9325 +}
9326 +
9327 +static inline
9328 +int v4_addr_in_nx_info(struct nx_info *nxi, __be32 addr, uint16_t tmask)
9329 +{
9330 +       struct nx_addr_v4 *nxa;
9331 +       int ret = 1;
9332 +
9333 +       if (!nxi)
9334 +               goto out;
9335 +
9336 +       ret = 2;
9337 +       /* allow 127.0.0.1 when remapping lback */
9338 +       if ((tmask & NXA_LOOPBACK) &&
9339 +               (addr == IPI_LOOPBACK) &&
9340 +               nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
9341 +               goto out;
9342 +       ret = 3;
9343 +       /* check for lback address */
9344 +       if ((tmask & NXA_MOD_LBACK) &&
9345 +               (nxi->v4_lback.s_addr == addr))
9346 +               goto out;
9347 +       ret = 4;
9348 +       /* check for broadcast address */
9349 +       if ((tmask & NXA_MOD_BCAST) &&
9350 +               (nxi->v4_bcast.s_addr == addr))
9351 +               goto out;
9352 +       ret = 5;
9353 +       /* check for v4 addresses */
9354 +       for (nxa = &nxi->v4; nxa; nxa = nxa->next)
9355 +               if (v4_addr_match(nxa, addr, tmask))
9356 +                       goto out;
9357 +       ret = 0;
9358 +out:
9359 +       vxdprintk(VXD_CBIT(net, 0),
9360 +               "v4_addr_in_nx_info(%p[#%u]," NIPQUAD_FMT ",%04x) = %d",
9361 +               nxi, nxi ? nxi->nx_id : 0, NIPQUAD(addr), tmask, ret);
9362 +       return ret;
9363 +}
9364 +
9365 +static inline
9366 +int v4_nx_addr_match(struct nx_addr_v4 *nxa, struct nx_addr_v4 *addr, uint16_t mask)
9367 +{
9368 +       /* FIXME: needs full range checks */
9369 +       return v4_addr_match(nxa, addr->ip[0].s_addr, mask);
9370 +}
9371 +
9372 +static inline
9373 +int v4_nx_addr_in_nx_info(struct nx_info *nxi, struct nx_addr_v4 *nxa, uint16_t mask)
9374 +{
9375 +       struct nx_addr_v4 *ptr;
9376 +
9377 +       for (ptr = &nxi->v4; ptr; ptr = ptr->next)
9378 +               if (v4_nx_addr_match(ptr, nxa, mask))
9379 +                       return 1;
9380 +       return 0;
9381 +}
9382 +
9383 +#include <net/inet_sock.h>
9384 +
9385 +/*
9386 + *     Check if a given address matches for a socket
9387 + *
9388 + *     nxi:            the socket's nx_info if any
9389 + *     addr:           to be verified address
9390 + */
9391 +static inline
9392 +int v4_sock_addr_match (
9393 +       struct nx_info *nxi,
9394 +       struct inet_sock *inet,
9395 +       __be32 addr)
9396 +{
9397 +       __be32 saddr = inet->inet_rcv_saddr;
9398 +       __be32 bcast = nxi ? nxi->v4_bcast.s_addr : INADDR_BROADCAST;
9399 +
9400 +       if (addr && (saddr == addr || bcast == addr))
9401 +               return 1;
9402 +       if (!saddr)
9403 +               return v4_addr_in_nx_info(nxi, addr, NXA_MASK_BIND);
9404 +       return 0;
9405 +}
9406 +
9407 +
9408 +/* inet related checks and helpers */
9409 +
9410 +
9411 +struct in_ifaddr;
9412 +struct net_device;
9413 +struct sock;
9414 +
9415 +#ifdef CONFIG_INET
9416 +
9417 +#include <linux/netdevice.h>
9418 +#include <linux/inetdevice.h>
9419 +#include <net/inet_sock.h>
9420 +#include <net/inet_timewait_sock.h>
9421 +
9422 +
9423 +int dev_in_nx_info(struct net_device *, struct nx_info *);
9424 +int v4_dev_in_nx_info(struct net_device *, struct nx_info *);
9425 +int nx_v4_addr_conflict(struct nx_info *, struct nx_info *);
9426 +
9427 +
9428 +/*
9429 + *     check if address is covered by socket
9430 + *
9431 + *     sk:     the socket to check against
9432 + *     addr:   the address in question (must be != 0)
9433 + */
9434 +
9435 +static inline
9436 +int __v4_addr_match_socket(const struct sock *sk, struct nx_addr_v4 *nxa)
9437 +{
9438 +       struct nx_info *nxi = sk->sk_nx_info;
9439 +       __be32 saddr = sk_rcv_saddr(sk);
9440 +
9441 +       vxdprintk(VXD_CBIT(net, 5),
9442 +               "__v4_addr_in_socket(%p," NXAV4_FMT ") %p:" NIPQUAD_FMT " %p;%lx",
9443 +               sk, NXAV4(nxa), nxi, NIPQUAD(saddr), sk->sk_socket,
9444 +               (sk->sk_socket?sk->sk_socket->flags:0));
9445 +
9446 +       if (saddr) {            /* direct address match */
9447 +               return v4_addr_match(nxa, saddr, -1);
9448 +       } else if (nxi) {       /* match against nx_info */
9449 +               return v4_nx_addr_in_nx_info(nxi, nxa, -1);
9450 +       } else {                /* unrestricted any socket */
9451 +               return 1;
9452 +       }
9453 +}
9454 +
9455 +
9456 +
9457 +static inline
9458 +int nx_dev_visible(struct nx_info *nxi, struct net_device *dev)
9459 +{
9460 +       vxdprintk(VXD_CBIT(net, 1),
9461 +               "nx_dev_visible(%p[#%u],%p " VS_Q("%s") ") %d",
9462 +               nxi, nxi ? nxi->nx_id : 0, dev, dev->name,
9463 +               nxi ? dev_in_nx_info(dev, nxi) : 0);
9464 +
9465 +       if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
9466 +               return 1;
9467 +       if (dev_in_nx_info(dev, nxi))
9468 +               return 1;
9469 +       return 0;
9470 +}
9471 +
9472 +
9473 +static inline
9474 +int v4_ifa_in_nx_info(struct in_ifaddr *ifa, struct nx_info *nxi)
9475 +{
9476 +       if (!nxi)
9477 +               return 1;
9478 +       if (!ifa)
9479 +               return 0;
9480 +       return v4_addr_in_nx_info(nxi, ifa->ifa_local, NXA_MASK_SHOW);
9481 +}
9482 +
9483 +static inline
9484 +int nx_v4_ifa_visible(struct nx_info *nxi, struct in_ifaddr *ifa)
9485 +{
9486 +       vxdprintk(VXD_CBIT(net, 1), "nx_v4_ifa_visible(%p[#%u],%p) %d",
9487 +               nxi, nxi ? nxi->nx_id : 0, ifa,
9488 +               nxi ? v4_ifa_in_nx_info(ifa, nxi) : 0);
9489 +
9490 +       if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
9491 +               return 1;
9492 +       if (v4_ifa_in_nx_info(ifa, nxi))
9493 +               return 1;
9494 +       return 0;
9495 +}
9496 +
9497 +
9498 +struct nx_v4_sock_addr {
9499 +       __be32 saddr;   /* Address used for validation */
9500 +       __be32 baddr;   /* Address used for socket bind */
9501 +};
9502 +
9503 +static inline
9504 +int v4_map_sock_addr(struct inet_sock *inet, struct sockaddr_in *addr,
9505 +       struct nx_v4_sock_addr *nsa)
9506 +{
9507 +       struct sock *sk = &inet->sk;
9508 +       struct nx_info *nxi = sk->sk_nx_info;
9509 +       __be32 saddr = addr->sin_addr.s_addr;
9510 +       __be32 baddr = saddr;
9511 +
9512 +       vxdprintk(VXD_CBIT(net, 3),
9513 +               "inet_bind(%p)* %p,%p;%lx " NIPQUAD_FMT,
9514 +               sk, sk->sk_nx_info, sk->sk_socket,
9515 +               (sk->sk_socket ? sk->sk_socket->flags : 0),
9516 +               NIPQUAD(saddr));
9517 +
9518 +       if (nxi) {
9519 +               if (saddr == INADDR_ANY) {
9520 +                       if (nx_info_flags(nxi, NXF_SINGLE_IP, 0))
9521 +                               baddr = nxi->v4.ip[0].s_addr;
9522 +               } else if (saddr == IPI_LOOPBACK) {
9523 +                       if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
9524 +                               baddr = nxi->v4_lback.s_addr;
9525 +               } else if (!ipv4_is_multicast(saddr) ||
9526 +                       !nx_info_ncaps(nxi, NXC_MULTICAST)) {
9527 +                       /* normal address bind */
9528 +                       if (!v4_addr_in_nx_info(nxi, saddr, NXA_MASK_BIND))
9529 +                               return -EADDRNOTAVAIL;
9530 +               }
9531 +       }
9532 +
9533 +       vxdprintk(VXD_CBIT(net, 3),
9534 +               "inet_bind(%p) " NIPQUAD_FMT ", " NIPQUAD_FMT,
9535 +               sk, NIPQUAD(saddr), NIPQUAD(baddr));
9536 +
9537 +       nsa->saddr = saddr;
9538 +       nsa->baddr = baddr;
9539 +       return 0;
9540 +}
9541 +
9542 +static inline
9543 +void v4_set_sock_addr(struct inet_sock *inet, struct nx_v4_sock_addr *nsa)
9544 +{
9545 +       inet->inet_saddr = nsa->baddr;
9546 +       inet->inet_rcv_saddr = nsa->baddr;
9547 +}
9548 +
9549 +
9550 +/*
9551 + *      helper to simplify inet_lookup_listener
9552 + *
9553 + *      nxi:   the socket's nx_info if any
9554 + *      addr:  to be verified address
9555 + *      saddr: socket address
9556 + */
9557 +static inline int v4_inet_addr_match (
9558 +       struct nx_info *nxi,
9559 +       __be32 addr,
9560 +       __be32 saddr)
9561 +{
9562 +       if (addr && (saddr == addr))
9563 +               return 1;
9564 +       if (!saddr)
9565 +               return nxi ? v4_addr_in_nx_info(nxi, addr, NXA_MASK_BIND) : 1;
9566 +       return 0;
9567 +}
9568 +
9569 +static inline __be32 nx_map_sock_lback(struct nx_info *nxi, __be32 addr)
9570 +{
9571 +       if (nx_info_flags(nxi, NXF_HIDE_LBACK, 0) &&
9572 +               (addr == nxi->v4_lback.s_addr))
9573 +               return IPI_LOOPBACK;
9574 +       return addr;
9575 +}
9576 +
9577 +static inline
9578 +int nx_info_has_v4(struct nx_info *nxi)
9579 +{
9580 +       if (!nxi)
9581 +               return 1;
9582 +       if (NX_IPV4(nxi))
9583 +               return 1;
9584 +       if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
9585 +               return 1;
9586 +       return 0;
9587 +}
9588 +
9589 +#else /* CONFIG_INET */
9590 +
9591 +static inline
9592 +int nx_dev_visible(struct nx_info *n, struct net_device *d)
9593 +{
9594 +       return 1;
9595 +}
9596 +
9597 +static inline
9598 +int nx_v4_addr_conflict(struct nx_info *n, uint32_t a, const struct sock *s)
9599 +{
9600 +       return 1;
9601 +}
9602 +
9603 +static inline
9604 +int v4_ifa_in_nx_info(struct in_ifaddr *a, struct nx_info *n)
9605 +{
9606 +       return 1;
9607 +}
9608 +
9609 +static inline
9610 +int nx_info_has_v4(struct nx_info *nxi)
9611 +{
9612 +       return 0;
9613 +}
9614 +
9615 +#endif /* CONFIG_INET */
9616 +
9617 +#define current_nx_info_has_v4() \
9618 +       nx_info_has_v4(current_nx_info())
9619 +
9620 +#else
9621 +// #warning duplicate inclusion
9622 +#endif
9623 diff -NurpP --minimal linux-3.6/include/linux/vs_inet6.h linux-3.6-vs2.3.4.3-noxfs-nocow/include/linux/vs_inet6.h
9624 --- linux-3.6/include/linux/vs_inet6.h  1970-01-01 01:00:00.000000000 +0100
9625 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/include/linux/vs_inet6.h    2012-10-04 18:47:00.000000000 +0200
9626 @@ -0,0 +1,246 @@
9627 +#ifndef _VS_INET6_H
9628 +#define _VS_INET6_H
9629 +
9630 +#include "vserver/base.h"
9631 +#include "vserver/network.h"
9632 +#include "vserver/debug.h"
9633 +
9634 +#include <net/ipv6.h>
9635 +
9636 +#define NXAV6(a)       &(a)->ip, &(a)->mask, (a)->prefix, (a)->type
9637 +#define NXAV6_FMT      "[%pI6/%pI6/%d:%04x]"
9638 +
9639 +
9640 +#ifdef CONFIG_IPV6
9641 +
9642 +static inline
9643 +int v6_addr_match(struct nx_addr_v6 *nxa,
9644 +       const struct in6_addr *addr, uint16_t mask)
9645 +{
9646 +       int ret = 0;
9647 +
9648 +       switch (nxa->type & mask) {
9649 +       case NXA_TYPE_MASK:
9650 +               ret = ipv6_masked_addr_cmp(&nxa->ip, &nxa->mask, addr);
9651 +               break;
9652 +       case NXA_TYPE_ADDR:
9653 +               ret = ipv6_addr_equal(&nxa->ip, addr);
9654 +               break;
9655 +       case NXA_TYPE_ANY:
9656 +               ret = 1;
9657 +               break;
9658 +       }
9659 +       vxdprintk(VXD_CBIT(net, 0),
9660 +               "v6_addr_match(%p" NXAV6_FMT ",%pI6,%04x) = %d",
9661 +               nxa, NXAV6(nxa), addr, mask, ret);
9662 +       return ret;
9663 +}
9664 +
9665 +static inline
9666 +int v6_addr_in_nx_info(struct nx_info *nxi,
9667 +       const struct in6_addr *addr, uint16_t mask)
9668 +{
9669 +       struct nx_addr_v6 *nxa;
9670 +       int ret = 1;
9671 +
9672 +       if (!nxi)
9673 +               goto out;
9674 +       for (nxa = &nxi->v6; nxa; nxa = nxa->next)
9675 +               if (v6_addr_match(nxa, addr, mask))
9676 +                       goto out;
9677 +       ret = 0;
9678 +out:
9679 +       vxdprintk(VXD_CBIT(net, 0),
9680 +               "v6_addr_in_nx_info(%p[#%u],%pI6,%04x) = %d",
9681 +               nxi, nxi ? nxi->nx_id : 0, addr, mask, ret);
9682 +       return ret;
9683 +}
9684 +
9685 +static inline
9686 +int v6_nx_addr_match(struct nx_addr_v6 *nxa, struct nx_addr_v6 *addr, uint16_t mask)
9687 +{
9688 +       /* FIXME: needs full range checks */
9689 +       return v6_addr_match(nxa, &addr->ip, mask);
9690 +}
9691 +
9692 +static inline
9693 +int v6_nx_addr_in_nx_info(struct nx_info *nxi, struct nx_addr_v6 *nxa, uint16_t mask)
9694 +{
9695 +       struct nx_addr_v6 *ptr;
9696 +
9697 +       for (ptr = &nxi->v6; ptr; ptr = ptr->next)
9698 +               if (v6_nx_addr_match(ptr, nxa, mask))
9699 +                       return 1;
9700 +       return 0;
9701 +}
9702 +
9703 +
9704 +/*
9705 + *     Check if a given address matches for a socket
9706 + *
9707 + *     nxi:            the socket's nx_info if any
9708 + *     addr:           to be verified address
9709 + */
9710 +static inline
9711 +int v6_sock_addr_match (
9712 +       struct nx_info *nxi,
9713 +       struct inet_sock *inet,
9714 +       struct in6_addr *addr)
9715 +{
9716 +       struct sock *sk = &inet->sk;
9717 +       struct in6_addr *saddr = inet6_rcv_saddr(sk);
9718 +
9719 +       if (!ipv6_addr_any(addr) &&
9720 +               ipv6_addr_equal(saddr, addr))
9721 +               return 1;
9722 +       if (ipv6_addr_any(saddr))
9723 +               return v6_addr_in_nx_info(nxi, addr, -1);
9724 +       return 0;
9725 +}
9726 +
9727 +/*
9728 + *     check if address is covered by socket
9729 + *
9730 + *     sk:     the socket to check against
9731 + *     addr:   the address in question (must be != 0)
9732 + */
9733 +
9734 +static inline
9735 +int __v6_addr_match_socket(const struct sock *sk, struct nx_addr_v6 *nxa)
9736 +{
9737 +       struct nx_info *nxi = sk->sk_nx_info;
9738 +       struct in6_addr *saddr = inet6_rcv_saddr(sk);
9739 +
9740 +       vxdprintk(VXD_CBIT(net, 5),
9741 +               "__v6_addr_in_socket(%p," NXAV6_FMT ") %p:%pI6 %p;%lx",
9742 +               sk, NXAV6(nxa), nxi, saddr, sk->sk_socket,
9743 +               (sk->sk_socket?sk->sk_socket->flags:0));
9744 +
9745 +       if (!ipv6_addr_any(saddr)) {    /* direct address match */
9746 +               return v6_addr_match(nxa, saddr, -1);
9747 +       } else if (nxi) {               /* match against nx_info */
9748 +               return v6_nx_addr_in_nx_info(nxi, nxa, -1);
9749 +       } else {                        /* unrestricted any socket */
9750 +               return 1;
9751 +       }
9752 +}
9753 +
9754 +
9755 +/* inet related checks and helpers */
9756 +
9757 +
9758 +struct in_ifaddr;
9759 +struct net_device;
9760 +struct sock;
9761 +
9762 +
9763 +#include <linux/netdevice.h>
9764 +#include <linux/inetdevice.h>
9765 +#include <net/inet_timewait_sock.h>
9766 +
9767 +
9768 +int dev_in_nx_info(struct net_device *, struct nx_info *);
9769 +int v6_dev_in_nx_info(struct net_device *, struct nx_info *);
9770 +int nx_v6_addr_conflict(struct nx_info *, struct nx_info *);
9771 +
9772 +
9773 +
9774 +static inline
9775 +int v6_ifa_in_nx_info(struct inet6_ifaddr *ifa, struct nx_info *nxi)
9776 +{
9777 +       if (!nxi)
9778 +               return 1;
9779 +       if (!ifa)
9780 +               return 0;
9781 +       return v6_addr_in_nx_info(nxi, &ifa->addr, -1);
9782 +}
9783 +
9784 +static inline
9785 +int nx_v6_ifa_visible(struct nx_info *nxi, struct inet6_ifaddr *ifa)
9786 +{
9787 +       vxdprintk(VXD_CBIT(net, 1), "nx_v6_ifa_visible(%p[#%u],%p) %d",
9788 +               nxi, nxi ? nxi->nx_id : 0, ifa,
9789 +               nxi ? v6_ifa_in_nx_info(ifa, nxi) : 0);
9790 +
9791 +       if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
9792 +               return 1;
9793 +       if (v6_ifa_in_nx_info(ifa, nxi))
9794 +               return 1;
9795 +       return 0;
9796 +}
9797 +
9798 +
9799 +struct nx_v6_sock_addr {
9800 +       struct in6_addr saddr;  /* Address used for validation */
9801 +       struct in6_addr baddr;  /* Address used for socket bind */
9802 +};
9803 +
9804 +static inline
9805 +int v6_map_sock_addr(struct inet_sock *inet, struct sockaddr_in6 *addr,
9806 +       struct nx_v6_sock_addr *nsa)
9807 +{
9808 +       // struct sock *sk = &inet->sk;
9809 +       // struct nx_info *nxi = sk->sk_nx_info;
9810 +       struct in6_addr saddr = addr->sin6_addr;
9811 +       struct in6_addr baddr = saddr;
9812 +
9813 +       nsa->saddr = saddr;
9814 +       nsa->baddr = baddr;
9815 +       return 0;
9816 +}
9817 +
9818 +static inline
9819 +void v6_set_sock_addr(struct inet_sock *inet, struct nx_v6_sock_addr *nsa)
9820 +{
9821 +       // struct sock *sk = &inet->sk;
9822 +       // struct in6_addr *saddr = inet6_rcv_saddr(sk);
9823 +
9824 +       // *saddr = nsa->baddr;
9825 +       // inet->inet_saddr = nsa->baddr;
9826 +}
9827 +
9828 +static inline
9829 +int nx_info_has_v6(struct nx_info *nxi)
9830 +{
9831 +       if (!nxi)
9832 +               return 1;
9833 +       if (NX_IPV6(nxi))
9834 +               return 1;
9835 +       return 0;
9836 +}
9837 +
9838 +#else /* CONFIG_IPV6 */
9839 +
9840 +static inline
9841 +int nx_v6_dev_visible(struct nx_info *n, struct net_device *d)
9842 +{
9843 +       return 1;
9844 +}
9845 +
9846 +
9847 +static inline
9848 +int nx_v6_addr_conflict(struct nx_info *n, uint32_t a, const struct sock *s)
9849 +{
9850 +       return 1;
9851 +}
9852 +
9853 +static inline
9854 +int v6_ifa_in_nx_info(struct in_ifaddr *a, struct nx_info *n)
9855 +{
9856 +       return 1;
9857 +}
9858 +
9859 +static inline
9860 +int nx_info_has_v6(struct nx_info *nxi)
9861 +{
9862 +       return 0;
9863 +}
9864 +
9865 +#endif /* CONFIG_IPV6 */
9866 +
9867 +#define current_nx_info_has_v6() \
9868 +       nx_info_has_v6(current_nx_info())
9869 +
9870 +#else
9871 +#warning duplicate inclusion
9872 +#endif
9873 diff -NurpP --minimal linux-3.6/include/linux/vs_limit.h linux-3.6-vs2.3.4.3-noxfs-nocow/include/linux/vs_limit.h
9874 --- linux-3.6/include/linux/vs_limit.h  1970-01-01 01:00:00.000000000 +0100
9875 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/include/linux/vs_limit.h    2012-10-04 18:47:00.000000000 +0200
9876 @@ -0,0 +1,140 @@
9877 +#ifndef _VS_LIMIT_H
9878 +#define _VS_LIMIT_H
9879 +
9880 +#include "vserver/limit.h"
9881 +#include "vserver/base.h"
9882 +#include "vserver/context.h"
9883 +#include "vserver/debug.h"
9884 +#include "vserver/context.h"
9885 +#include "vserver/limit_int.h"
9886 +
9887 +
9888 +#define vx_acc_cres(v, d, p, r) \
9889 +       __vx_acc_cres(v, r, d, p, __FILE__, __LINE__)
9890 +
9891 +#define vx_acc_cres_cond(x, d, p, r) \
9892 +       __vx_acc_cres(((x) == vx_current_xid()) ? current_vx_info() : 0, \
9893 +       r, d, p, __FILE__, __LINE__)
9894 +
9895 +
9896 +#define vx_add_cres(v, a, p, r) \
9897 +       __vx_add_cres(v, r, a, p, __FILE__, __LINE__)
9898 +#define vx_sub_cres(v, a, p, r)                vx_add_cres(v, -(a), p, r)
9899 +
9900 +#define vx_add_cres_cond(x, a, p, r) \
9901 +       __vx_add_cres(((x) == vx_current_xid()) ? current_vx_info() : 0, \
9902 +       r, a, p, __FILE__, __LINE__)
9903 +#define vx_sub_cres_cond(x, a, p, r)   vx_add_cres_cond(x, -(a), p, r)
9904 +
9905 +
9906 +/* process and file limits */
9907 +
9908 +#define vx_nproc_inc(p) \
9909 +       vx_acc_cres((p)->vx_info, 1, p, RLIMIT_NPROC)
9910 +
9911 +#define vx_nproc_dec(p) \
9912 +       vx_acc_cres((p)->vx_info,-1, p, RLIMIT_NPROC)
9913 +
9914 +#define vx_files_inc(f) \
9915 +       vx_acc_cres_cond((f)->f_xid, 1, f, RLIMIT_NOFILE)
9916 +
9917 +#define vx_files_dec(f) \
9918 +       vx_acc_cres_cond((f)->f_xid,-1, f, RLIMIT_NOFILE)
9919 +
9920 +#define vx_locks_inc(l) \
9921 +       vx_acc_cres_cond((l)->fl_xid, 1, l, RLIMIT_LOCKS)
9922 +
9923 +#define vx_locks_dec(l) \
9924 +       vx_acc_cres_cond((l)->fl_xid,-1, l, RLIMIT_LOCKS)
9925 +
9926 +#define vx_openfd_inc(f) \
9927 +       vx_acc_cres(current_vx_info(), 1, (void *)(long)(f), VLIMIT_OPENFD)
9928 +
9929 +#define vx_openfd_dec(f) \
9930 +       vx_acc_cres(current_vx_info(),-1, (void *)(long)(f), VLIMIT_OPENFD)
9931 +
9932 +
9933 +#define vx_cres_avail(v, n, r) \
9934 +       __vx_cres_avail(v, r, n, __FILE__, __LINE__)
9935 +
9936 +
9937 +#define vx_nproc_avail(n) \
9938 +       vx_cres_avail(current_vx_info(), n, RLIMIT_NPROC)
9939 +
9940 +#define vx_files_avail(n) \
9941 +       vx_cres_avail(current_vx_info(), n, RLIMIT_NOFILE)
9942 +
9943 +#define vx_locks_avail(n) \
9944 +       vx_cres_avail(current_vx_info(), n, RLIMIT_LOCKS)
9945 +
9946 +#define vx_openfd_avail(n) \
9947 +       vx_cres_avail(current_vx_info(), n, VLIMIT_OPENFD)
9948 +
9949 +
9950 +/* dentry limits */
9951 +
9952 +#define vx_dentry_inc(d) do {                                          \
9953 +       if ((d)->d_count == 1)                                          \
9954 +               vx_acc_cres(current_vx_info(), 1, d, VLIMIT_DENTRY);    \
9955 +       } while (0)
9956 +
9957 +#define vx_dentry_dec(d) do {                                          \
9958 +       if ((d)->d_count == 0)                                          \
9959 +               vx_acc_cres(current_vx_info(),-1, d, VLIMIT_DENTRY);    \
9960 +       } while (0)
9961 +
9962 +#define vx_dentry_avail(n) \
9963 +       vx_cres_avail(current_vx_info(), n, VLIMIT_DENTRY)
9964 +
9965 +
9966 +/* socket limits */
9967 +
9968 +#define vx_sock_inc(s) \
9969 +       vx_acc_cres((s)->sk_vx_info, 1, s, VLIMIT_NSOCK)
9970 +
9971 +#define vx_sock_dec(s) \
9972 +       vx_acc_cres((s)->sk_vx_info,-1, s, VLIMIT_NSOCK)
9973 +
9974 +#define vx_sock_avail(n) \
9975 +       vx_cres_avail(current_vx_info(), n, VLIMIT_NSOCK)
9976 +
9977 +
9978 +/* ipc resource limits */
9979 +
9980 +#define vx_ipcmsg_add(v, u, a) \
9981 +       vx_add_cres(v, a, u, RLIMIT_MSGQUEUE)
9982 +
9983 +#define vx_ipcmsg_sub(v, u, a) \
9984 +       vx_sub_cres(v, a, u, RLIMIT_MSGQUEUE)
9985 +
9986 +#define vx_ipcmsg_avail(v, a) \
9987 +       vx_cres_avail(v, a, RLIMIT_MSGQUEUE)
9988 +
9989 +
9990 +#define vx_ipcshm_add(v, k, a) \
9991 +       vx_add_cres(v, a, (void *)(long)(k), VLIMIT_SHMEM)
9992 +
9993 +#define vx_ipcshm_sub(v, k, a) \
9994 +       vx_sub_cres(v, a, (void *)(long)(k), VLIMIT_SHMEM)
9995 +
9996 +#define vx_ipcshm_avail(v, a) \
9997 +       vx_cres_avail(v, a, VLIMIT_SHMEM)
9998 +
9999 +
10000 +#define vx_semary_inc(a) \
10001 +       vx_acc_cres(current_vx_info(), 1, a, VLIMIT_SEMARY)
10002 +
10003 +#define vx_semary_dec(a) \
10004 +       vx_acc_cres(current_vx_info(), -1, a, VLIMIT_SEMARY)
10005 +
10006 +
10007 +#define vx_nsems_add(a,n) \
10008 +       vx_add_cres(current_vx_info(), n, a, VLIMIT_NSEMS)
10009 +
10010 +#define vx_nsems_sub(a,n) \
10011 +       vx_sub_cres(current_vx_info(), n, a, VLIMIT_NSEMS)
10012 +
10013 +
10014 +#else
10015 +#warning duplicate inclusion
10016 +#endif
10017 diff -NurpP --minimal linux-3.6/include/linux/vs_network.h linux-3.6-vs2.3.4.3-noxfs-nocow/include/linux/vs_network.h
10018 --- linux-3.6/include/linux/vs_network.h        1970-01-01 01:00:00.000000000 +0100
10019 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/include/linux/vs_network.h  2012-10-04 18:47:00.000000000 +0200
10020 @@ -0,0 +1,169 @@
10021 +#ifndef _NX_VS_NETWORK_H
10022 +#define _NX_VS_NETWORK_H
10023 +
10024 +#include "vserver/context.h"
10025 +#include "vserver/network.h"
10026 +#include "vserver/base.h"
10027 +#include "vserver/check.h"
10028 +#include "vserver/debug.h"
10029 +
10030 +#include <linux/sched.h>
10031 +
10032 +
10033 +#define get_nx_info(i) __get_nx_info(i, __FILE__, __LINE__)
10034 +
10035 +static inline struct nx_info *__get_nx_info(struct nx_info *nxi,
10036 +       const char *_file, int _line)
10037 +{
10038 +       if (!nxi)
10039 +               return NULL;
10040 +
10041 +       vxlprintk(VXD_CBIT(nid, 2), "get_nx_info(%p[#%d.%d])",
10042 +               nxi, nxi ? nxi->nx_id : 0,
10043 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
10044 +               _file, _line);
10045 +
10046 +       atomic_inc(&nxi->nx_usecnt);
10047 +       return nxi;
10048 +}
10049 +
10050 +
10051 +extern void free_nx_info(struct nx_info *);
10052 +
10053 +#define put_nx_info(i) __put_nx_info(i, __FILE__, __LINE__)
10054 +
10055 +static inline void __put_nx_info(struct nx_info *nxi, const char *_file, int _line)
10056 +{
10057 +       if (!nxi)
10058 +               return;
10059 +
10060 +       vxlprintk(VXD_CBIT(nid, 2), "put_nx_info(%p[#%d.%d])",
10061 +               nxi, nxi ? nxi->nx_id : 0,
10062 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
10063 +               _file, _line);
10064 +
10065 +       if (atomic_dec_and_test(&nxi->nx_usecnt))
10066 +               free_nx_info(nxi);
10067 +}
10068 +
10069 +
10070 +#define init_nx_info(p, i) __init_nx_info(p, i, __FILE__, __LINE__)
10071 +
10072 +static inline void __init_nx_info(struct nx_info **nxp, struct nx_info *nxi,
10073 +               const char *_file, int _line)
10074 +{
10075 +       if (nxi) {
10076 +               vxlprintk(VXD_CBIT(nid, 3),
10077 +                       "init_nx_info(%p[#%d.%d])",
10078 +                       nxi, nxi ? nxi->nx_id : 0,
10079 +                       nxi ? atomic_read(&nxi->nx_usecnt) : 0,
10080 +                       _file, _line);
10081 +
10082 +               atomic_inc(&nxi->nx_usecnt);
10083 +       }
10084 +       *nxp = nxi;
10085 +}
10086 +
10087 +
10088 +#define set_nx_info(p, i) __set_nx_info(p, i, __FILE__, __LINE__)
10089 +
10090 +static inline void __set_nx_info(struct nx_info **nxp, struct nx_info *nxi,
10091 +       const char *_file, int _line)
10092 +{
10093 +       struct nx_info *nxo;
10094 +
10095 +       if (!nxi)
10096 +               return;
10097 +
10098 +       vxlprintk(VXD_CBIT(nid, 3), "set_nx_info(%p[#%d.%d])",
10099 +               nxi, nxi ? nxi->nx_id : 0,
10100 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
10101 +               _file, _line);
10102 +
10103 +       atomic_inc(&nxi->nx_usecnt);
10104 +       nxo = xchg(nxp, nxi);
10105 +       BUG_ON(nxo);
10106 +}
10107 +
10108 +#define clr_nx_info(p) __clr_nx_info(p, __FILE__, __LINE__)
10109 +
10110 +static inline void __clr_nx_info(struct nx_info **nxp,
10111 +       const char *_file, int _line)
10112 +{
10113 +       struct nx_info *nxo;
10114 +
10115 +       nxo = xchg(nxp, NULL);
10116 +       if (!nxo)
10117 +               return;
10118 +
10119 +       vxlprintk(VXD_CBIT(nid, 3), "clr_nx_info(%p[#%d.%d])",
10120 +               nxo, nxo ? nxo->nx_id : 0,
10121 +               nxo ? atomic_read(&nxo->nx_usecnt) : 0,
10122 +               _file, _line);
10123 +
10124 +       if (atomic_dec_and_test(&nxo->nx_usecnt))
10125 +               free_nx_info(nxo);
10126 +}
10127 +
10128 +
10129 +#define claim_nx_info(v, p) __claim_nx_info(v, p, __FILE__, __LINE__)
10130 +
10131 +static inline void __claim_nx_info(struct nx_info *nxi,
10132 +       struct task_struct *task, const char *_file, int _line)
10133 +{
10134 +       vxlprintk(VXD_CBIT(nid, 3), "claim_nx_info(%p[#%d.%d.%d]) %p",
10135 +               nxi, nxi ? nxi->nx_id : 0,
10136 +               nxi?atomic_read(&nxi->nx_usecnt):0,
10137 +               nxi?atomic_read(&nxi->nx_tasks):0,
10138 +               task, _file, _line);
10139 +
10140 +       atomic_inc(&nxi->nx_tasks);
10141 +}
10142 +
10143 +
10144 +extern void unhash_nx_info(struct nx_info *);
10145 +
10146 +#define release_nx_info(v, p) __release_nx_info(v, p, __FILE__, __LINE__)
10147 +
10148 +static inline void __release_nx_info(struct nx_info *nxi,
10149 +       struct task_struct *task, const char *_file, int _line)
10150 +{
10151 +       vxlprintk(VXD_CBIT(nid, 3), "release_nx_info(%p[#%d.%d.%d]) %p",
10152 +               nxi, nxi ? nxi->nx_id : 0,
10153 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
10154 +               nxi ? atomic_read(&nxi->nx_tasks) : 0,
10155 +               task, _file, _line);
10156 +
10157 +       might_sleep();
10158 +
10159 +       if (atomic_dec_and_test(&nxi->nx_tasks))
10160 +               unhash_nx_info(nxi);
10161 +}
10162 +
10163 +
10164 +#define task_get_nx_info(i)    __task_get_nx_info(i, __FILE__, __LINE__)
10165 +
10166 +static __inline__ struct nx_info *__task_get_nx_info(struct task_struct *p,
10167 +       const char *_file, int _line)
10168 +{
10169 +       struct nx_info *nxi;
10170 +
10171 +       task_lock(p);
10172 +       vxlprintk(VXD_CBIT(nid, 5), "task_get_nx_info(%p)",
10173 +               p, _file, _line);
10174 +       nxi = __get_nx_info(p->nx_info, _file, _line);
10175 +       task_unlock(p);
10176 +       return nxi;
10177 +}
10178 +
10179 +
10180 +static inline void exit_nx_info(struct task_struct *p)
10181 +{
10182 +       if (p->nx_info)
10183 +               release_nx_info(p->nx_info, p);
10184 +}
10185 +
10186 +
10187 +#else
10188 +#warning duplicate inclusion
10189 +#endif
10190 diff -NurpP --minimal linux-3.6/include/linux/vs_pid.h linux-3.6-vs2.3.4.3-noxfs-nocow/include/linux/vs_pid.h
10191 --- linux-3.6/include/linux/vs_pid.h    1970-01-01 01:00:00.000000000 +0100
10192 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/include/linux/vs_pid.h      2012-10-04 18:47:00.000000000 +0200
10193 @@ -0,0 +1,50 @@
10194 +#ifndef _VS_PID_H
10195 +#define _VS_PID_H
10196 +
10197 +#include "vserver/base.h"
10198 +#include "vserver/check.h"
10199 +#include "vserver/context.h"
10200 +#include "vserver/debug.h"
10201 +#include "vserver/pid.h"
10202 +#include <linux/pid_namespace.h>
10203 +
10204 +
10205 +#define VXF_FAKE_INIT  (VXF_INFO_INIT | VXF_STATE_INIT)
10206 +
10207 +static inline
10208 +int vx_proc_task_visible(struct task_struct *task)
10209 +{
10210 +       if ((task->pid == 1) &&
10211 +               !vx_flags(VXF_FAKE_INIT, VXF_FAKE_INIT))
10212 +               /* show a blend through init */
10213 +               goto visible;
10214 +       if (vx_check(vx_task_xid(task), VS_WATCH | VS_IDENT))
10215 +               goto visible;
10216 +       return 0;
10217 +visible:
10218 +       return 1;
10219 +}
10220 +
10221 +#define find_task_by_real_pid(pid) find_task_by_pid_ns(pid, &init_pid_ns)
10222 +
10223 +
10224 +static inline
10225 +struct task_struct *vx_get_proc_task(struct inode *inode, struct pid *pid)
10226 +{
10227 +       struct task_struct *task = get_pid_task(pid, PIDTYPE_PID);
10228 +
10229 +       if (task && !vx_proc_task_visible(task)) {
10230 +               vxdprintk(VXD_CBIT(misc, 6),
10231 +                       "dropping task (get) %p[#%u,%u] for %p[#%u,%u]",
10232 +                       task, task->xid, task->pid,
10233 +                       current, current->xid, current->pid);
10234 +               put_task_struct(task);
10235 +               task = NULL;
10236 +       }
10237 +       return task;
10238 +}
10239 +
10240 +
10241 +#else
10242 +#warning duplicate inclusion
10243 +#endif
10244 diff -NurpP --minimal linux-3.6/include/linux/vs_sched.h linux-3.6-vs2.3.4.3-noxfs-nocow/include/linux/vs_sched.h
10245 --- linux-3.6/include/linux/vs_sched.h  1970-01-01 01:00:00.000000000 +0100
10246 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/include/linux/vs_sched.h    2012-10-04 18:47:00.000000000 +0200
10247 @@ -0,0 +1,40 @@
10248 +#ifndef _VS_SCHED_H
10249 +#define _VS_SCHED_H
10250 +
10251 +#include "vserver/base.h"
10252 +#include "vserver/context.h"
10253 +#include "vserver/sched.h"
10254 +
10255 +
10256 +#define MAX_PRIO_BIAS           20
10257 +#define MIN_PRIO_BIAS          -20
10258 +
10259 +static inline
10260 +int vx_adjust_prio(struct task_struct *p, int prio, int max_user)
10261 +{
10262 +       struct vx_info *vxi = p->vx_info;
10263 +
10264 +       if (vxi)
10265 +               prio += vx_cpu(vxi, sched_pc).prio_bias;
10266 +       return prio;
10267 +}
10268 +
10269 +static inline void vx_account_user(struct vx_info *vxi,
10270 +       cputime_t cputime, int nice)
10271 +{
10272 +       if (!vxi)
10273 +               return;
10274 +       vx_cpu(vxi, sched_pc).user_ticks += cputime;
10275 +}
10276 +
10277 +static inline void vx_account_system(struct vx_info *vxi,
10278 +       cputime_t cputime, int idle)
10279 +{
10280 +       if (!vxi)
10281 +               return;
10282 +       vx_cpu(vxi, sched_pc).sys_ticks += cputime;
10283 +}
10284 +
10285 +#else
10286 +#warning duplicate inclusion
10287 +#endif
10288 diff -NurpP --minimal linux-3.6/include/linux/vs_socket.h linux-3.6-vs2.3.4.3-noxfs-nocow/include/linux/vs_socket.h
10289 --- linux-3.6/include/linux/vs_socket.h 1970-01-01 01:00:00.000000000 +0100
10290 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/include/linux/vs_socket.h   2012-10-04 18:47:00.000000000 +0200
10291 @@ -0,0 +1,67 @@
10292 +#ifndef _VS_SOCKET_H
10293 +#define _VS_SOCKET_H
10294 +
10295 +#include "vserver/debug.h"
10296 +#include "vserver/base.h"
10297 +#include "vserver/cacct.h"
10298 +#include "vserver/context.h"
10299 +#include "vserver/tag.h"
10300 +
10301 +
10302 +/* socket accounting */
10303 +
10304 +#include <linux/socket.h>
10305 +
10306 +static inline int vx_sock_type(int family)
10307 +{
10308 +       switch (family) {
10309 +       case PF_UNSPEC:
10310 +               return VXA_SOCK_UNSPEC;
10311 +       case PF_UNIX:
10312 +               return VXA_SOCK_UNIX;
10313 +       case PF_INET:
10314 +               return VXA_SOCK_INET;
10315 +       case PF_INET6:
10316 +               return VXA_SOCK_INET6;
10317 +       case PF_PACKET:
10318 +               return VXA_SOCK_PACKET;
10319 +       default:
10320 +               return VXA_SOCK_OTHER;
10321 +       }
10322 +}
10323 +
10324 +#define vx_acc_sock(v, f, p, s) \
10325 +       __vx_acc_sock(v, f, p, s, __FILE__, __LINE__)
10326 +
10327 +static inline void __vx_acc_sock(struct vx_info *vxi,
10328 +       int family, int pos, int size, char *file, int line)
10329 +{
10330 +       if (vxi) {
10331 +               int type = vx_sock_type(family);
10332 +
10333 +               atomic_long_inc(&vxi->cacct.sock[type][pos].count);
10334 +               atomic_long_add(size, &vxi->cacct.sock[type][pos].total);
10335 +       }
10336 +}
10337 +
10338 +#define vx_sock_recv(sk, s) \
10339 +       vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 0, s)
10340 +#define vx_sock_send(sk, s) \
10341 +       vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 1, s)
10342 +#define vx_sock_fail(sk, s) \
10343 +       vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 2, s)
10344 +
10345 +
10346 +#define sock_vx_init(s) do {           \
10347 +       (s)->sk_xid = 0;                \
10348 +       (s)->sk_vx_info = NULL;         \
10349 +       } while (0)
10350 +
10351 +#define sock_nx_init(s) do {           \
10352 +       (s)->sk_nid = 0;                \
10353 +       (s)->sk_nx_info = NULL;         \
10354 +       } while (0)
10355 +
10356 +#else
10357 +#warning duplicate inclusion
10358 +#endif
10359 diff -NurpP --minimal linux-3.6/include/linux/vs_tag.h linux-3.6-vs2.3.4.3-noxfs-nocow/include/linux/vs_tag.h
10360 --- linux-3.6/include/linux/vs_tag.h    1970-01-01 01:00:00.000000000 +0100
10361 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/include/linux/vs_tag.h      2012-10-04 18:47:00.000000000 +0200
10362 @@ -0,0 +1,47 @@
10363 +#ifndef _VS_TAG_H
10364 +#define _VS_TAG_H
10365 +
10366 +#include <linux/vserver/tag.h>
10367 +
10368 +/* check conditions */
10369 +
10370 +#define DX_ADMIN       0x0001
10371 +#define DX_WATCH       0x0002
10372 +#define DX_HOSTID      0x0008
10373 +
10374 +#define DX_IDENT       0x0010
10375 +
10376 +#define DX_ARG_MASK    0x0010
10377 +
10378 +
10379 +#define dx_task_tag(t) ((t)->tag)
10380 +
10381 +#define dx_current_tag() dx_task_tag(current)
10382 +
10383 +#define dx_check(c, m) __dx_check(dx_current_tag(), c, m)
10384 +
10385 +#define dx_weak_check(c, m)    ((m) ? dx_check(c, m) : 1)
10386 +
10387 +
10388 +/*
10389 + * check current context for ADMIN/WATCH and
10390 + * optionally against supplied argument
10391 + */
10392 +static inline int __dx_check(tag_t cid, tag_t id, unsigned int mode)
10393 +{
10394 +       if (mode & DX_ARG_MASK) {
10395 +               if ((mode & DX_IDENT) && (id == cid))
10396 +                       return 1;
10397 +       }
10398 +       return (((mode & DX_ADMIN) && (cid == 0)) ||
10399 +               ((mode & DX_WATCH) && (cid == 1)) ||
10400 +               ((mode & DX_HOSTID) && (id == 0)));
10401 +}
10402 +
10403 +struct inode;
10404 +int dx_permission(const struct inode *inode, int mask);
10405 +
10406 +
10407 +#else
10408 +#warning duplicate inclusion
10409 +#endif
10410 diff -NurpP --minimal linux-3.6/include/linux/vs_time.h linux-3.6-vs2.3.4.3-noxfs-nocow/include/linux/vs_time.h
10411 --- linux-3.6/include/linux/vs_time.h   1970-01-01 01:00:00.000000000 +0100
10412 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/include/linux/vs_time.h     2012-10-04 18:47:00.000000000 +0200
10413 @@ -0,0 +1,19 @@
10414 +#ifndef _VS_TIME_H
10415 +#define _VS_TIME_H
10416 +
10417 +
10418 +/* time faking stuff */
10419 +
10420 +#ifdef CONFIG_VSERVER_VTIME
10421 +
10422 +extern void vx_adjust_timespec(struct timespec *ts);
10423 +extern int vx_settimeofday(const struct timespec *ts);
10424 +
10425 +#else
10426 +#define        vx_adjust_timespec(t)   do { } while (0)
10427 +#define        vx_settimeofday(t)      do_settimeofday(t)
10428 +#endif
10429 +
10430 +#else
10431 +#warning duplicate inclusion
10432 +#endif
10433 diff -NurpP --minimal linux-3.6/include/linux/vserver/Kbuild linux-3.6-vs2.3.4.3-noxfs-nocow/include/linux/vserver/Kbuild
10434 --- linux-3.6/include/linux/vserver/Kbuild      1970-01-01 01:00:00.000000000 +0100
10435 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/include/linux/vserver/Kbuild        2012-10-04 18:47:00.000000000 +0200
10436 @@ -0,0 +1,8 @@
10437 +
10438 +header-y += context_cmd.h network_cmd.h space_cmd.h \
10439 +       cacct_cmd.h cvirt_cmd.h limit_cmd.h dlimit_cmd.h \
10440 +       inode_cmd.h tag_cmd.h sched_cmd.h signal_cmd.h \
10441 +       debug_cmd.h device_cmd.h
10442 +
10443 +header-y += switch.h network.h monitor.h inode.h device.h
10444 +
10445 diff -NurpP --minimal linux-3.6/include/linux/vserver/base.h linux-3.6-vs2.3.4.3-noxfs-nocow/include/linux/vserver/base.h
10446 --- linux-3.6/include/linux/vserver/base.h      1970-01-01 01:00:00.000000000 +0100
10447 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/include/linux/vserver/base.h        2012-10-04 18:47:00.000000000 +0200
10448 @@ -0,0 +1,178 @@
10449 +#ifndef _VX_BASE_H
10450 +#define _VX_BASE_H
10451 +
10452 +
10453 +/* context state changes */
10454 +
10455 +enum {
10456 +       VSC_STARTUP = 1,
10457 +       VSC_SHUTDOWN,
10458 +
10459 +       VSC_NETUP,
10460 +       VSC_NETDOWN,
10461 +};
10462 +
10463 +
10464 +
10465 +#define vx_task_xid(t) ((t)->xid)
10466 +
10467 +#define vx_current_xid() vx_task_xid(current)
10468 +
10469 +#define current_vx_info() (current->vx_info)
10470 +
10471 +
10472 +#define nx_task_nid(t) ((t)->nid)
10473 +
10474 +#define nx_current_nid() nx_task_nid(current)
10475 +
10476 +#define current_nx_info() (current->nx_info)
10477 +
10478 +
10479 +/* generic flag merging */
10480 +
10481 +#define vs_check_flags(v, m, f)        (((v) & (m)) ^ (f))
10482 +
10483 +#define vs_mask_flags(v, f, m) (((v) & ~(m)) | ((f) & (m)))
10484 +
10485 +#define vs_mask_mask(v, f, m)  (((v) & ~(m)) | ((v) & (f) & (m)))
10486 +
10487 +#define vs_check_bit(v, n)     ((v) & (1LL << (n)))
10488 +
10489 +
10490 +/* context flags */
10491 +
10492 +#define __vx_flags(v)  ((v) ? (v)->vx_flags : 0)
10493 +
10494 +#define vx_current_flags()     __vx_flags(current_vx_info())
10495 +
10496 +#define vx_info_flags(v, m, f) \
10497 +       vs_check_flags(__vx_flags(v), m, f)
10498 +
10499 +#define task_vx_flags(t, m, f) \
10500 +       ((t) && vx_info_flags((t)->vx_info, m, f))
10501 +
10502 +#define vx_flags(m, f) vx_info_flags(current_vx_info(), m, f)
10503 +
10504 +
10505 +/* context caps */
10506 +
10507 +#define __vx_ccaps(v)  ((v) ? (v)->vx_ccaps : 0)
10508 +
10509 +#define vx_current_ccaps()     __vx_ccaps(current_vx_info())
10510 +
10511 +#define vx_info_ccaps(v, c)    (__vx_ccaps(v) & (c))
10512 +
10513 +#define vx_ccaps(c)    vx_info_ccaps(current_vx_info(), (c))
10514 +
10515 +
10516 +
10517 +/* network flags */
10518 +
10519 +#define __nx_flags(n)  ((n) ? (n)->nx_flags : 0)
10520 +
10521 +#define nx_current_flags()     __nx_flags(current_nx_info())
10522 +
10523 +#define nx_info_flags(n, m, f) \
10524 +       vs_check_flags(__nx_flags(n), m, f)
10525 +
10526 +#define task_nx_flags(t, m, f) \
10527 +       ((t) && nx_info_flags((t)->nx_info, m, f))
10528 +
10529 +#define nx_flags(m, f) nx_info_flags(current_nx_info(), m, f)
10530 +
10531 +
10532 +/* network caps */
10533 +
10534 +#define __nx_ncaps(n)  ((n) ? (n)->nx_ncaps : 0)
10535 +
10536 +#define nx_current_ncaps()     __nx_ncaps(current_nx_info())
10537 +
10538 +#define nx_info_ncaps(n, c)    (__nx_ncaps(n) & (c))
10539 +
10540 +#define nx_ncaps(c)    nx_info_ncaps(current_nx_info(), c)
10541 +
10542 +
10543 +/* context mask capabilities */
10544 +
10545 +#define __vx_mcaps(v)  ((v) ? (v)->vx_ccaps >> 32UL : ~0 )
10546 +
10547 +#define vx_info_mcaps(v, c)    (__vx_mcaps(v) & (c))
10548 +
10549 +#define vx_mcaps(c)    vx_info_mcaps(current_vx_info(), c)
10550 +
10551 +
10552 +/* context bcap mask */
10553 +
10554 +#define __vx_bcaps(v)          ((v)->vx_bcaps)
10555 +
10556 +#define vx_current_bcaps()     __vx_bcaps(current_vx_info())
10557 +
10558 +
10559 +/* mask given bcaps */
10560 +
10561 +#define vx_info_mbcaps(v, c)   ((v) ? cap_intersect(__vx_bcaps(v), c) : c)
10562 +
10563 +#define vx_mbcaps(c)           vx_info_mbcaps(current_vx_info(), c)
10564 +
10565 +
10566 +/* masked cap_bset */
10567 +
10568 +#define vx_info_cap_bset(v)    vx_info_mbcaps(v, current->cap_bset)
10569 +
10570 +#define vx_current_cap_bset()  vx_info_cap_bset(current_vx_info())
10571 +
10572 +#if 0
10573 +#define vx_info_mbcap(v, b) \
10574 +       (!vx_info_flags(v, VXF_STATE_SETUP, 0) ? \
10575 +       vx_info_bcaps(v, b) : (b))
10576 +
10577 +#define task_vx_mbcap(t, b) \
10578 +       vx_info_mbcap((t)->vx_info, (t)->b)
10579 +
10580 +#define vx_mbcap(b)    task_vx_mbcap(current, b)
10581 +#endif
10582 +
10583 +#define vx_cap_raised(v, c, f) cap_raised(vx_info_mbcaps(v, c), f)
10584 +
10585 +#define vx_capable(b, c) (capable(b) || \
10586 +       (cap_raised(current_cap(), b) && vx_ccaps(c)))
10587 +
10588 +#define vx_ns_capable(n, b, c) (ns_capable(n, b) || \
10589 +       (cap_raised(current_cap(), b) && vx_ccaps(c)))
10590 +
10591 +#define nx_capable(b, c) (capable(b) || \
10592 +       (cap_raised(current_cap(), b) && nx_ncaps(c)))
10593 +
10594 +#define vx_task_initpid(t, n) \
10595 +       ((t)->vx_info && \
10596 +       ((t)->vx_info->vx_initpid == (n)))
10597 +
10598 +#define vx_current_initpid(n)  vx_task_initpid(current, n)
10599 +
10600 +
10601 +/* context unshare mask */
10602 +
10603 +#define __vx_umask(v)          ((v)->vx_umask)
10604 +
10605 +#define vx_current_umask()     __vx_umask(current_vx_info())
10606 +
10607 +#define vx_can_unshare(b, f) (capable(b) || \
10608 +       (cap_raised(current_cap(), b) && \
10609 +       !((f) & ~vx_current_umask())))
10610 +
10611 +
10612 +#define __vx_wmask(v)          ((v)->vx_wmask)
10613 +
10614 +#define vx_current_wmask()     __vx_wmask(current_vx_info())
10615 +
10616 +
10617 +#define __vx_state(v)  ((v) ? ((v)->vx_state) : 0)
10618 +
10619 +#define vx_info_state(v, m)    (__vx_state(v) & (m))
10620 +
10621 +
10622 +#define __nx_state(n)  ((n) ? ((n)->nx_state) : 0)
10623 +
10624 +#define nx_info_state(n, m)    (__nx_state(n) & (m))
10625 +
10626 +#endif
10627 diff -NurpP --minimal linux-3.6/include/linux/vserver/cacct.h linux-3.6-vs2.3.4.3-noxfs-nocow/include/linux/vserver/cacct.h
10628 --- linux-3.6/include/linux/vserver/cacct.h     1970-01-01 01:00:00.000000000 +0100
10629 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/include/linux/vserver/cacct.h       2012-10-04 18:47:00.000000000 +0200
10630 @@ -0,0 +1,15 @@
10631 +#ifndef _VX_CACCT_H
10632 +#define _VX_CACCT_H
10633 +
10634 +
10635 +enum sock_acc_field {
10636 +       VXA_SOCK_UNSPEC = 0,
10637 +       VXA_SOCK_UNIX,
10638 +       VXA_SOCK_INET,
10639 +       VXA_SOCK_INET6,
10640 +       VXA_SOCK_PACKET,
10641 +       VXA_SOCK_OTHER,
10642 +       VXA_SOCK_SIZE   /* array size */
10643 +};
10644 +
10645 +#endif /* _VX_CACCT_H */
10646 diff -NurpP --minimal linux-3.6/include/linux/vserver/cacct_cmd.h linux-3.6-vs2.3.4.3-noxfs-nocow/include/linux/vserver/cacct_cmd.h
10647 --- linux-3.6/include/linux/vserver/cacct_cmd.h 1970-01-01 01:00:00.000000000 +0100
10648 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/include/linux/vserver/cacct_cmd.h   2012-10-04 18:47:00.000000000 +0200
10649 @@ -0,0 +1,23 @@
10650 +#ifndef _VX_CACCT_CMD_H
10651 +#define _VX_CACCT_CMD_H
10652 +
10653 +
10654 +/* virtual host info name commands */
10655 +
10656 +#define VCMD_sock_stat         VC_CMD(VSTAT, 5, 0)
10657 +
10658 +struct vcmd_sock_stat_v0 {
10659 +       uint32_t field;
10660 +       uint32_t count[3];
10661 +       uint64_t total[3];
10662 +};
10663 +
10664 +
10665 +#ifdef __KERNEL__
10666 +
10667 +#include <linux/compiler.h>
10668 +
10669 +extern int vc_sock_stat(struct vx_info *, void __user *);
10670 +
10671 +#endif /* __KERNEL__ */
10672 +#endif /* _VX_CACCT_CMD_H */
10673 diff -NurpP --minimal linux-3.6/include/linux/vserver/cacct_def.h linux-3.6-vs2.3.4.3-noxfs-nocow/include/linux/vserver/cacct_def.h
10674 --- linux-3.6/include/linux/vserver/cacct_def.h 1970-01-01 01:00:00.000000000 +0100
10675 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/include/linux/vserver/cacct_def.h   2012-10-04 18:47:00.000000000 +0200
10676 @@ -0,0 +1,43 @@
10677 +#ifndef _VX_CACCT_DEF_H
10678 +#define _VX_CACCT_DEF_H
10679 +
10680 +#include <asm/atomic.h>
10681 +#include <linux/vserver/cacct.h>
10682 +
10683 +
10684 +struct _vx_sock_acc {
10685 +       atomic_long_t count;
10686 +       atomic_long_t total;
10687 +};
10688 +
10689 +/* context sub struct */
10690 +
10691 +struct _vx_cacct {
10692 +       struct _vx_sock_acc sock[VXA_SOCK_SIZE][3];
10693 +       atomic_t slab[8];
10694 +       atomic_t page[6][8];
10695 +};
10696 +
10697 +#ifdef CONFIG_VSERVER_DEBUG
10698 +
10699 +static inline void __dump_vx_cacct(struct _vx_cacct *cacct)
10700 +{
10701 +       int i, j;
10702 +
10703 +       printk("\t_vx_cacct:");
10704 +       for (i = 0; i < 6; i++) {
10705 +               struct _vx_sock_acc *ptr = cacct->sock[i];
10706 +
10707 +               printk("\t [%d] =", i);
10708 +               for (j = 0; j < 3; j++) {
10709 +                       printk(" [%d] = %8lu, %8lu", j,
10710 +                               atomic_long_read(&ptr[j].count),
10711 +                               atomic_long_read(&ptr[j].total));
10712 +               }
10713 +               printk("\n");
10714 +       }
10715 +}
10716 +
10717 +#endif
10718 +
10719 +#endif /* _VX_CACCT_DEF_H */
10720 diff -NurpP --minimal linux-3.6/include/linux/vserver/cacct_int.h linux-3.6-vs2.3.4.3-noxfs-nocow/include/linux/vserver/cacct_int.h
10721 --- linux-3.6/include/linux/vserver/cacct_int.h 1970-01-01 01:00:00.000000000 +0100
10722 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/include/linux/vserver/cacct_int.h   2012-10-04 18:47:00.000000000 +0200
10723 @@ -0,0 +1,21 @@
10724 +#ifndef _VX_CACCT_INT_H
10725 +#define _VX_CACCT_INT_H
10726 +
10727 +
10728 +#ifdef __KERNEL__
10729 +
10730 +static inline
10731 +unsigned long vx_sock_count(struct _vx_cacct *cacct, int type, int pos)
10732 +{
10733 +       return atomic_long_read(&cacct->sock[type][pos].count);
10734 +}
10735 +
10736 +
10737 +static inline
10738 +unsigned long vx_sock_total(struct _vx_cacct *cacct, int type, int pos)
10739 +{
10740 +       return atomic_long_read(&cacct->sock[type][pos].total);
10741 +}
10742 +
10743 +#endif /* __KERNEL__ */
10744 +#endif /* _VX_CACCT_INT_H */
10745 diff -NurpP --minimal linux-3.6/include/linux/vserver/check.h linux-3.6-vs2.3.4.3-noxfs-nocow/include/linux/vserver/check.h
10746 --- linux-3.6/include/linux/vserver/check.h     1970-01-01 01:00:00.000000000 +0100
10747 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/include/linux/vserver/check.h       2012-10-04 18:47:00.000000000 +0200
10748 @@ -0,0 +1,89 @@
10749 +#ifndef _VS_CHECK_H
10750 +#define _VS_CHECK_H
10751 +
10752 +
10753 +#define MAX_S_CONTEXT  65535   /* Arbitrary limit */
10754 +
10755 +#ifdef CONFIG_VSERVER_DYNAMIC_IDS
10756 +#define MIN_D_CONTEXT  49152   /* dynamic contexts start here */
10757 +#else
10758 +#define MIN_D_CONTEXT  65536
10759 +#endif
10760 +
10761 +/* check conditions */
10762 +
10763 +#define VS_ADMIN       0x0001
10764 +#define VS_WATCH       0x0002
10765 +#define VS_HIDE                0x0004
10766 +#define VS_HOSTID      0x0008
10767 +
10768 +#define VS_IDENT       0x0010
10769 +#define VS_EQUIV       0x0020
10770 +#define VS_PARENT      0x0040
10771 +#define VS_CHILD       0x0080
10772 +
10773 +#define VS_ARG_MASK    0x00F0
10774 +
10775 +#define VS_DYNAMIC     0x0100
10776 +#define VS_STATIC      0x0200
10777 +
10778 +#define VS_ATR_MASK    0x0F00
10779 +
10780 +#ifdef CONFIG_VSERVER_PRIVACY
10781 +#define VS_ADMIN_P     (0)
10782 +#define VS_WATCH_P     (0)
10783 +#else
10784 +#define VS_ADMIN_P     VS_ADMIN
10785 +#define VS_WATCH_P     VS_WATCH
10786 +#endif
10787 +
10788 +#define VS_HARDIRQ     0x1000
10789 +#define VS_SOFTIRQ     0x2000
10790 +#define VS_IRQ         0x4000
10791 +
10792 +#define VS_IRQ_MASK    0xF000
10793 +
10794 +#include <linux/hardirq.h>
10795 +
10796 +/*
10797 + * check current context for ADMIN/WATCH and
10798 + * optionally against supplied argument
10799 + */
10800 +static inline int __vs_check(int cid, int id, unsigned int mode)
10801 +{
10802 +       if (mode & VS_ARG_MASK) {
10803 +               if ((mode & VS_IDENT) && (id == cid))
10804 +                       return 1;
10805 +       }
10806 +       if (mode & VS_ATR_MASK) {
10807 +               if ((mode & VS_DYNAMIC) &&
10808 +                       (id >= MIN_D_CONTEXT) &&
10809 +                       (id <= MAX_S_CONTEXT))
10810 +                       return 1;
10811 +               if ((mode & VS_STATIC) &&
10812 +                       (id > 1) && (id < MIN_D_CONTEXT))
10813 +                       return 1;
10814 +       }
10815 +       if (mode & VS_IRQ_MASK) {
10816 +               if ((mode & VS_IRQ) && unlikely(in_interrupt()))
10817 +                       return 1;
10818 +               if ((mode & VS_HARDIRQ) && unlikely(in_irq()))
10819 +                       return 1;
10820 +               if ((mode & VS_SOFTIRQ) && unlikely(in_softirq()))
10821 +                       return 1;
10822 +       }
10823 +       return (((mode & VS_ADMIN) && (cid == 0)) ||
10824 +               ((mode & VS_WATCH) && (cid == 1)) ||
10825 +               ((mode & VS_HOSTID) && (id == 0)));
10826 +}
10827 +
10828 +#define vx_check(c, m) __vs_check(vx_current_xid(), c, (m) | VS_IRQ)
10829 +
10830 +#define vx_weak_check(c, m)    ((m) ? vx_check(c, m) : 1)
10831 +
10832 +
10833 +#define nx_check(c, m) __vs_check(nx_current_nid(), c, m)
10834 +
10835 +#define nx_weak_check(c, m)    ((m) ? nx_check(c, m) : 1)
10836 +
10837 +#endif
10838 diff -NurpP --minimal linux-3.6/include/linux/vserver/context.h linux-3.6-vs2.3.4.3-noxfs-nocow/include/linux/vserver/context.h
10839 --- linux-3.6/include/linux/vserver/context.h   1970-01-01 01:00:00.000000000 +0100
10840 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/include/linux/vserver/context.h     2012-10-04 18:47:00.000000000 +0200
10841 @@ -0,0 +1,188 @@
10842 +#ifndef _VX_CONTEXT_H
10843 +#define _VX_CONTEXT_H
10844 +
10845 +#include <linux/types.h>
10846 +#include <linux/capability.h>
10847 +
10848 +
10849 +/* context flags */
10850 +
10851 +#define VXF_INFO_SCHED         0x00000002
10852 +#define VXF_INFO_NPROC         0x00000004
10853 +#define VXF_INFO_PRIVATE       0x00000008
10854 +
10855 +#define VXF_INFO_INIT          0x00000010
10856 +#define VXF_INFO_HIDE          0x00000020
10857 +#define VXF_INFO_ULIMIT                0x00000040
10858 +#define VXF_INFO_NSPACE                0x00000080
10859 +
10860 +#define VXF_SCHED_HARD         0x00000100
10861 +#define VXF_SCHED_PRIO         0x00000200
10862 +#define VXF_SCHED_PAUSE                0x00000400
10863 +
10864 +#define VXF_VIRT_MEM           0x00010000
10865 +#define VXF_VIRT_UPTIME                0x00020000
10866 +#define VXF_VIRT_CPU           0x00040000
10867 +#define VXF_VIRT_LOAD          0x00080000
10868 +#define VXF_VIRT_TIME          0x00100000
10869 +
10870 +#define VXF_HIDE_MOUNT         0x01000000
10871 +/* was VXF_HIDE_NETIF          0x02000000 */
10872 +#define VXF_HIDE_VINFO         0x04000000
10873 +
10874 +#define VXF_STATE_SETUP                (1ULL << 32)
10875 +#define VXF_STATE_INIT         (1ULL << 33)
10876 +#define VXF_STATE_ADMIN                (1ULL << 34)
10877 +
10878 +#define VXF_SC_HELPER          (1ULL << 36)
10879 +#define VXF_REBOOT_KILL                (1ULL << 37)
10880 +#define VXF_PERSISTENT         (1ULL << 38)
10881 +
10882 +#define VXF_FORK_RSS           (1ULL << 48)
10883 +#define VXF_PROLIFIC           (1ULL << 49)
10884 +
10885 +#define VXF_IGNEG_NICE         (1ULL << 52)
10886 +
10887 +#define VXF_ONE_TIME           (0x0007ULL << 32)
10888 +
10889 +#define VXF_INIT_SET           (VXF_STATE_SETUP | VXF_STATE_INIT | VXF_STATE_ADMIN)
10890 +
10891 +
10892 +/* context migration */
10893 +
10894 +#define VXM_SET_INIT           0x00000001
10895 +#define VXM_SET_REAPER         0x00000002
10896 +
10897 +/* context caps */
10898 +
10899 +#define VXC_SET_UTSNAME                0x00000001
10900 +#define VXC_SET_RLIMIT         0x00000002
10901 +#define VXC_FS_SECURITY                0x00000004
10902 +#define VXC_FS_TRUSTED         0x00000008
10903 +#define VXC_TIOCSTI            0x00000010
10904 +
10905 +/* was VXC_RAW_ICMP            0x00000100 */
10906 +#define VXC_SYSLOG             0x00001000
10907 +#define VXC_OOM_ADJUST         0x00002000
10908 +#define VXC_AUDIT_CONTROL      0x00004000
10909 +
10910 +#define VXC_SECURE_MOUNT       0x00010000
10911 +#define VXC_SECURE_REMOUNT     0x00020000
10912 +#define VXC_BINARY_MOUNT       0x00040000
10913 +
10914 +#define VXC_QUOTA_CTL          0x00100000
10915 +#define VXC_ADMIN_MAPPER       0x00200000
10916 +#define VXC_ADMIN_CLOOP                0x00400000
10917 +
10918 +#define VXC_KTHREAD            0x01000000
10919 +#define VXC_NAMESPACE          0x02000000
10920 +
10921 +
10922 +#ifdef __KERNEL__
10923 +
10924 +#include <linux/list.h>
10925 +#include <linux/spinlock.h>
10926 +#include <linux/rcupdate.h>
10927 +
10928 +#include "limit_def.h"
10929 +#include "sched_def.h"
10930 +#include "cvirt_def.h"
10931 +#include "cacct_def.h"
10932 +#include "device_def.h"
10933 +
10934 +#define VX_SPACES      2
10935 +
10936 +struct _vx_info_pc {
10937 +       struct _vx_sched_pc sched_pc;
10938 +       struct _vx_cvirt_pc cvirt_pc;
10939 +};
10940 +
10941 +struct _vx_space {
10942 +       unsigned long vx_nsmask;                /* assignment mask */
10943 +       struct nsproxy *vx_nsproxy;             /* private namespaces */
10944 +       struct fs_struct *vx_fs;                /* private namespace fs */
10945 +       const struct cred *vx_cred;             /* task credentials */
10946 +};
10947 +
10948 +struct vx_info {
10949 +       struct hlist_node vx_hlist;             /* linked list of contexts */
10950 +       xid_t vx_id;                            /* context id */
10951 +       atomic_t vx_usecnt;                     /* usage count */
10952 +       atomic_t vx_tasks;                      /* tasks count */
10953 +       struct vx_info *vx_parent;              /* parent context */
10954 +       int vx_state;                           /* context state */
10955 +
10956 +       struct _vx_space space[VX_SPACES];      /* namespace store */
10957 +
10958 +       uint64_t vx_flags;                      /* context flags */
10959 +       uint64_t vx_ccaps;                      /* context caps (vserver) */
10960 +       uint64_t vx_umask;                      /* unshare mask (guest) */
10961 +       uint64_t vx_wmask;                      /* warn mask (guest) */
10962 +       kernel_cap_t vx_bcaps;                  /* bounding caps (system) */
10963 +
10964 +       struct task_struct *vx_reaper;          /* guest reaper process */
10965 +       pid_t vx_initpid;                       /* PID of guest init */
10966 +       int64_t vx_badness_bias;                /* OOM points bias */
10967 +
10968 +       struct _vx_limit limit;                 /* vserver limits */
10969 +       struct _vx_sched sched;                 /* vserver scheduler */
10970 +       struct _vx_cvirt cvirt;                 /* virtual/bias stuff */
10971 +       struct _vx_cacct cacct;                 /* context accounting */
10972 +
10973 +       struct _vx_device dmap;                 /* default device map targets */
10974 +
10975 +#ifndef CONFIG_SMP
10976 +       struct _vx_info_pc info_pc;             /* per cpu data */
10977 +#else
10978 +       struct _vx_info_pc *ptr_pc;             /* per cpu array */
10979 +#endif
10980 +
10981 +       wait_queue_head_t vx_wait;              /* context exit waitqueue */
10982 +       int reboot_cmd;                         /* last sys_reboot() cmd */
10983 +       int exit_code;                          /* last process exit code */
10984 +
10985 +       char vx_name[65];                       /* vserver name */
10986 +};
10987 +
10988 +#ifndef CONFIG_SMP
10989 +#define        vx_ptr_pc(vxi)          (&(vxi)->info_pc)
10990 +#define        vx_per_cpu(vxi, v, id)  vx_ptr_pc(vxi)->v
10991 +#else
10992 +#define        vx_ptr_pc(vxi)          ((vxi)->ptr_pc)
10993 +#define        vx_per_cpu(vxi, v, id)  per_cpu_ptr(vx_ptr_pc(vxi), id)->v
10994 +#endif
10995 +
10996 +#define        vx_cpu(vxi, v)          vx_per_cpu(vxi, v, smp_processor_id())
10997 +
10998 +
10999 +struct vx_info_save {
11000 +       struct vx_info *vxi;
11001 +       xid_t xid;
11002 +};
11003 +
11004 +
11005 +/* status flags */
11006 +
11007 +#define VXS_HASHED     0x0001
11008 +#define VXS_PAUSED     0x0010
11009 +#define VXS_SHUTDOWN   0x0100
11010 +#define VXS_HELPER     0x1000
11011 +#define VXS_RELEASED   0x8000
11012 +
11013 +
11014 +extern void claim_vx_info(struct vx_info *, struct task_struct *);
11015 +extern void release_vx_info(struct vx_info *, struct task_struct *);
11016 +
11017 +extern struct vx_info *lookup_vx_info(int);
11018 +extern struct vx_info *lookup_or_create_vx_info(int);
11019 +
11020 +extern int get_xid_list(int, unsigned int *, int);
11021 +extern int xid_is_hashed(xid_t);
11022 +
11023 +extern int vx_migrate_task(struct task_struct *, struct vx_info *, int);
11024 +
11025 +extern long vs_state_change(struct vx_info *, unsigned int);
11026 +
11027 +
11028 +#endif /* __KERNEL__ */
11029 +#endif /* _VX_CONTEXT_H */
11030 diff -NurpP --minimal linux-3.6/include/linux/vserver/context_cmd.h linux-3.6-vs2.3.4.3-noxfs-nocow/include/linux/vserver/context_cmd.h
11031 --- linux-3.6/include/linux/vserver/context_cmd.h       1970-01-01 01:00:00.000000000 +0100
11032 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/include/linux/vserver/context_cmd.h 2012-10-04 18:47:00.000000000 +0200
11033 @@ -0,0 +1,162 @@
11034 +#ifndef _VX_CONTEXT_CMD_H
11035 +#define _VX_CONTEXT_CMD_H
11036 +
11037 +
11038 +/* vinfo commands */
11039 +
11040 +#define VCMD_task_xid          VC_CMD(VINFO, 1, 0)
11041 +
11042 +#ifdef __KERNEL__
11043 +extern int vc_task_xid(uint32_t);
11044 +
11045 +#endif /* __KERNEL__ */
11046 +
11047 +#define VCMD_vx_info           VC_CMD(VINFO, 5, 0)
11048 +
11049 +struct vcmd_vx_info_v0 {
11050 +       uint32_t xid;
11051 +       uint32_t initpid;
11052 +       /* more to come */
11053 +};
11054 +
11055 +#ifdef __KERNEL__
11056 +extern int vc_vx_info(struct vx_info *, void __user *);
11057 +
11058 +#endif /* __KERNEL__ */
11059 +
11060 +#define VCMD_ctx_stat          VC_CMD(VSTAT, 0, 0)
11061 +
11062 +struct vcmd_ctx_stat_v0 {
11063 +       uint32_t usecnt;
11064 +       uint32_t tasks;
11065 +       /* more to come */
11066 +};
11067 +
11068 +#ifdef __KERNEL__
11069 +extern int vc_ctx_stat(struct vx_info *, void __user *);
11070 +
11071 +#endif /* __KERNEL__ */
11072 +
11073 +/* context commands */
11074 +
11075 +#define VCMD_ctx_create_v0     VC_CMD(VPROC, 1, 0)
11076 +#define VCMD_ctx_create                VC_CMD(VPROC, 1, 1)
11077 +
11078 +struct vcmd_ctx_create {
11079 +       uint64_t flagword;
11080 +};
11081 +
11082 +#define VCMD_ctx_migrate_v0    VC_CMD(PROCMIG, 1, 0)
11083 +#define VCMD_ctx_migrate       VC_CMD(PROCMIG, 1, 1)
11084 +
11085 +struct vcmd_ctx_migrate {
11086 +       uint64_t flagword;
11087 +};
11088 +
11089 +#ifdef __KERNEL__
11090 +extern int vc_ctx_create(uint32_t, void __user *);
11091 +extern int vc_ctx_migrate(struct vx_info *, void __user *);
11092 +
11093 +#endif /* __KERNEL__ */
11094 +
11095 +
11096 +/* flag commands */
11097 +
11098 +#define VCMD_get_cflags                VC_CMD(FLAGS, 1, 0)
11099 +#define VCMD_set_cflags                VC_CMD(FLAGS, 2, 0)
11100 +
11101 +struct vcmd_ctx_flags_v0 {
11102 +       uint64_t flagword;
11103 +       uint64_t mask;
11104 +};
11105 +
11106 +#ifdef __KERNEL__
11107 +extern int vc_get_cflags(struct vx_info *, void __user *);
11108 +extern int vc_set_cflags(struct vx_info *, void __user *);
11109 +
11110 +#endif /* __KERNEL__ */
11111 +
11112 +
11113 +/* context caps commands */
11114 +
11115 +#define VCMD_get_ccaps         VC_CMD(FLAGS, 3, 1)
11116 +#define VCMD_set_ccaps         VC_CMD(FLAGS, 4, 1)
11117 +
11118 +struct vcmd_ctx_caps_v1 {
11119 +       uint64_t ccaps;
11120 +       uint64_t cmask;
11121 +};
11122 +
11123 +#ifdef __KERNEL__
11124 +extern int vc_get_ccaps(struct vx_info *, void __user *);
11125 +extern int vc_set_ccaps(struct vx_info *, void __user *);
11126 +
11127 +#endif /* __KERNEL__ */
11128 +
11129 +
11130 +/* bcaps commands */
11131 +
11132 +#define VCMD_get_bcaps         VC_CMD(FLAGS, 9, 0)
11133 +#define VCMD_set_bcaps         VC_CMD(FLAGS, 10, 0)
11134 +
11135 +struct vcmd_bcaps {
11136 +       uint64_t bcaps;
11137 +       uint64_t bmask;
11138 +};
11139 +
11140 +#ifdef __KERNEL__
11141 +extern int vc_get_bcaps(struct vx_info *, void __user *);
11142 +extern int vc_set_bcaps(struct vx_info *, void __user *);
11143 +
11144 +#endif /* __KERNEL__ */
11145 +
11146 +
11147 +/* umask commands */
11148 +
11149 +#define VCMD_get_umask         VC_CMD(FLAGS, 13, 0)
11150 +#define VCMD_set_umask         VC_CMD(FLAGS, 14, 0)
11151 +
11152 +struct vcmd_umask {
11153 +       uint64_t umask;
11154 +       uint64_t mask;
11155 +};
11156 +
11157 +#ifdef __KERNEL__
11158 +extern int vc_get_umask(struct vx_info *, void __user *);
11159 +extern int vc_set_umask(struct vx_info *, void __user *);
11160 +
11161 +#endif /* __KERNEL__ */
11162 +
11163 +
11164 +/* wmask commands */
11165 +
11166 +#define VCMD_get_wmask         VC_CMD(FLAGS, 15, 0)
11167 +#define VCMD_set_wmask         VC_CMD(FLAGS, 16, 0)
11168 +
11169 +struct vcmd_wmask {
11170 +       uint64_t wmask;
11171 +       uint64_t mask;
11172 +};
11173 +
11174 +#ifdef __KERNEL__
11175 +extern int vc_get_wmask(struct vx_info *, void __user *);
11176 +extern int vc_set_wmask(struct vx_info *, void __user *);
11177 +
11178 +#endif /* __KERNEL__ */
11179 +
11180 +
11181 +/* OOM badness */
11182 +
11183 +#define VCMD_get_badness       VC_CMD(MEMCTRL, 5, 0)
11184 +#define VCMD_set_badness       VC_CMD(MEMCTRL, 6, 0)
11185 +
11186 +struct vcmd_badness_v0 {
11187 +       int64_t bias;
11188 +};
11189 +
11190 +#ifdef __KERNEL__
11191 +extern int vc_get_badness(struct vx_info *, void __user *);
11192 +extern int vc_set_badness(struct vx_info *, void __user *);
11193 +
11194 +#endif /* __KERNEL__ */
11195 +#endif /* _VX_CONTEXT_CMD_H */
11196 diff -NurpP --minimal linux-3.6/include/linux/vserver/cvirt.h linux-3.6-vs2.3.4.3-noxfs-nocow/include/linux/vserver/cvirt.h
11197 --- linux-3.6/include/linux/vserver/cvirt.h     1970-01-01 01:00:00.000000000 +0100
11198 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/include/linux/vserver/cvirt.h       2012-10-04 18:47:00.000000000 +0200
11199 @@ -0,0 +1,22 @@
11200 +#ifndef _VX_CVIRT_H
11201 +#define _VX_CVIRT_H
11202 +
11203 +
11204 +#ifdef __KERNEL__
11205 +
11206 +struct timespec;
11207 +
11208 +void vx_vsi_boottime(struct timespec *);
11209 +
11210 +void vx_vsi_uptime(struct timespec *, struct timespec *);
11211 +
11212 +
11213 +struct vx_info;
11214 +
11215 +void vx_update_load(struct vx_info *);
11216 +
11217 +
11218 +int vx_do_syslog(int, char __user *, int);
11219 +
11220 +#endif /* __KERNEL__ */
11221 +#endif /* _VX_CVIRT_H */
11222 diff -NurpP --minimal linux-3.6/include/linux/vserver/cvirt_cmd.h linux-3.6-vs2.3.4.3-noxfs-nocow/include/linux/vserver/cvirt_cmd.h
11223 --- linux-3.6/include/linux/vserver/cvirt_cmd.h 1970-01-01 01:00:00.000000000 +0100
11224 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/include/linux/vserver/cvirt_cmd.h   2012-10-04 18:47:00.000000000 +0200
11225 @@ -0,0 +1,53 @@
11226 +#ifndef _VX_CVIRT_CMD_H
11227 +#define _VX_CVIRT_CMD_H
11228 +
11229 +
11230 +/* virtual host info name commands */
11231 +
11232 +#define VCMD_set_vhi_name      VC_CMD(VHOST, 1, 0)
11233 +#define VCMD_get_vhi_name      VC_CMD(VHOST, 2, 0)
11234 +
11235 +struct vcmd_vhi_name_v0 {
11236 +       uint32_t field;
11237 +       char name[65];
11238 +};
11239 +
11240 +
11241 +enum vhi_name_field {
11242 +       VHIN_CONTEXT = 0,
11243 +       VHIN_SYSNAME,
11244 +       VHIN_NODENAME,
11245 +       VHIN_RELEASE,
11246 +       VHIN_VERSION,
11247 +       VHIN_MACHINE,
11248 +       VHIN_DOMAINNAME,
11249 +};
11250 +
11251 +
11252 +#ifdef __KERNEL__
11253 +
11254 +#include <linux/compiler.h>
11255 +
11256 +extern int vc_set_vhi_name(struct vx_info *, void __user *);
11257 +extern int vc_get_vhi_name(struct vx_info *, void __user *);
11258 +
11259 +#endif /* __KERNEL__ */
11260 +
11261 +#define VCMD_virt_stat         VC_CMD(VSTAT, 3, 0)
11262 +
11263 +struct vcmd_virt_stat_v0 {
11264 +       uint64_t offset;
11265 +       uint64_t uptime;
11266 +       uint32_t nr_threads;
11267 +       uint32_t nr_running;
11268 +       uint32_t nr_uninterruptible;
11269 +       uint32_t nr_onhold;
11270 +       uint32_t nr_forks;
11271 +       uint32_t load[3];
11272 +};
11273 +
11274 +#ifdef __KERNEL__
11275 +extern int vc_virt_stat(struct vx_info *, void __user *);
11276 +
11277 +#endif /* __KERNEL__ */
11278 +#endif /* _VX_CVIRT_CMD_H */
11279 diff -NurpP --minimal linux-3.6/include/linux/vserver/cvirt_def.h linux-3.6-vs2.3.4.3-noxfs-nocow/include/linux/vserver/cvirt_def.h
11280 --- linux-3.6/include/linux/vserver/cvirt_def.h 1970-01-01 01:00:00.000000000 +0100
11281 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/include/linux/vserver/cvirt_def.h   2012-10-04 18:47:00.000000000 +0200
11282 @@ -0,0 +1,80 @@
11283 +#ifndef _VX_CVIRT_DEF_H
11284 +#define _VX_CVIRT_DEF_H
11285 +
11286 +#include <linux/jiffies.h>
11287 +#include <linux/spinlock.h>
11288 +#include <linux/wait.h>
11289 +#include <linux/time.h>
11290 +#include <asm/atomic.h>
11291 +
11292 +
11293 +struct _vx_usage_stat {
11294 +       uint64_t user;
11295 +       uint64_t nice;
11296 +       uint64_t system;
11297 +       uint64_t softirq;
11298 +       uint64_t irq;
11299 +       uint64_t idle;
11300 +       uint64_t iowait;
11301 +};
11302 +
11303 +struct _vx_syslog {
11304 +       wait_queue_head_t log_wait;
11305 +       spinlock_t logbuf_lock;         /* lock for the log buffer */
11306 +
11307 +       unsigned long log_start;        /* next char to be read by syslog() */
11308 +       unsigned long con_start;        /* next char to be sent to consoles */
11309 +       unsigned long log_end;  /* most-recently-written-char + 1 */
11310 +       unsigned long logged_chars;     /* #chars since last read+clear operation */
11311 +
11312 +       char log_buf[1024];
11313 +};
11314 +
11315 +
11316 +/* context sub struct */
11317 +
11318 +struct _vx_cvirt {
11319 +       atomic_t nr_threads;            /* number of current threads */
11320 +       atomic_t nr_running;            /* number of running threads */
11321 +       atomic_t nr_uninterruptible;    /* number of uninterruptible threads */
11322 +
11323 +       atomic_t nr_onhold;             /* processes on hold */
11324 +       uint32_t onhold_last;           /* jiffies when put on hold */
11325 +
11326 +       struct timespec bias_ts;        /* time offset to the host */
11327 +       struct timespec bias_idle;
11328 +       struct timespec bias_uptime;    /* context creation point */
11329 +       uint64_t bias_clock;            /* offset in clock_t */
11330 +
11331 +       spinlock_t load_lock;           /* lock for the load averages */
11332 +       atomic_t load_updates;          /* nr of load updates done so far */
11333 +       uint32_t load_last;             /* last time load was calculated */
11334 +       uint32_t load[3];               /* load averages 1,5,15 */
11335 +
11336 +       atomic_t total_forks;           /* number of forks so far */
11337 +
11338 +       struct _vx_syslog syslog;
11339 +};
11340 +
11341 +struct _vx_cvirt_pc {
11342 +       struct _vx_usage_stat cpustat;
11343 +};
11344 +
11345 +
11346 +#ifdef CONFIG_VSERVER_DEBUG
11347 +
11348 +static inline void __dump_vx_cvirt(struct _vx_cvirt *cvirt)
11349 +{
11350 +       printk("\t_vx_cvirt:\n");
11351 +       printk("\t threads: %4d, %4d, %4d, %4d\n",
11352 +               atomic_read(&cvirt->nr_threads),
11353 +               atomic_read(&cvirt->nr_running),
11354 +               atomic_read(&cvirt->nr_uninterruptible),
11355 +               atomic_read(&cvirt->nr_onhold));
11356 +       /* add rest here */
11357 +       printk("\t total_forks = %d\n", atomic_read(&cvirt->total_forks));
11358 +}
11359 +
11360 +#endif
11361 +
11362 +#endif /* _VX_CVIRT_DEF_H */
11363 diff -NurpP --minimal linux-3.6/include/linux/vserver/debug.h linux-3.6-vs2.3.4.3-noxfs-nocow/include/linux/vserver/debug.h
11364 --- linux-3.6/include/linux/vserver/debug.h     1970-01-01 01:00:00.000000000 +0100
11365 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/include/linux/vserver/debug.h       2012-10-04 18:47:00.000000000 +0200
11366 @@ -0,0 +1,145 @@
11367 +#ifndef _VX_DEBUG_H
11368 +#define _VX_DEBUG_H
11369 +
11370 +
11371 +#define VXD_CBIT(n, m) (vs_debug_ ## n & (1 << (m)))
11372 +#define VXD_CMIN(n, m) (vs_debug_ ## n > (m))
11373 +#define VXD_MASK(n, m) (vs_debug_ ## n & (m))
11374 +
11375 +#define VXD_DEV(d)     (d), (d)->bd_inode->i_ino,              \
11376 +                       imajor((d)->bd_inode), iminor((d)->bd_inode)
11377 +#define VXF_DEV                "%p[%lu,%d:%d]"
11378 +
11379 +#if    defined(CONFIG_QUOTES_UTF8)
11380 +#define        VS_Q_LQM        "\xc2\xbb"
11381 +#define        VS_Q_RQM        "\xc2\xab"
11382 +#elif  defined(CONFIG_QUOTES_ASCII)
11383 +#define        VS_Q_LQM        "\x27"
11384 +#define        VS_Q_RQM        "\x27"
11385 +#else
11386 +#define        VS_Q_LQM        "\xbb"
11387 +#define        VS_Q_RQM        "\xab"
11388 +#endif
11389 +
11390 +#define        VS_Q(f)         VS_Q_LQM f VS_Q_RQM
11391 +
11392 +
11393 +#define vxd_path(p)                                            \
11394 +       ({ static char _buffer[PATH_MAX];                       \
11395 +          d_path(p, _buffer, sizeof(_buffer)); })
11396 +
11397 +#define vxd_cond_path(n)                                       \
11398 +       ((n) ? vxd_path(&(n)->path) : "<null>" )
11399 +
11400 +
11401 +#ifdef CONFIG_VSERVER_DEBUG
11402 +
11403 +extern unsigned int vs_debug_switch;
11404 +extern unsigned int vs_debug_xid;
11405 +extern unsigned int vs_debug_nid;
11406 +extern unsigned int vs_debug_tag;
11407 +extern unsigned int vs_debug_net;
11408 +extern unsigned int vs_debug_limit;
11409 +extern unsigned int vs_debug_cres;
11410 +extern unsigned int vs_debug_dlim;
11411 +extern unsigned int vs_debug_quota;
11412 +extern unsigned int vs_debug_cvirt;
11413 +extern unsigned int vs_debug_space;
11414 +extern unsigned int vs_debug_perm;
11415 +extern unsigned int vs_debug_misc;
11416 +
11417 +
11418 +#define VX_LOGLEVEL    "vxD: "
11419 +#define VX_PROC_FMT    "%p: "
11420 +#define VX_PROCESS     current
11421 +
11422 +#define vxdprintk(c, f, x...)                                  \
11423 +       do {                                                    \
11424 +               if (c)                                          \
11425 +                       printk(VX_LOGLEVEL VX_PROC_FMT f "\n",  \
11426 +                               VX_PROCESS , ##x);              \
11427 +       } while (0)
11428 +
11429 +#define vxlprintk(c, f, x...)                                  \
11430 +       do {                                                    \
11431 +               if (c)                                          \
11432 +                       printk(VX_LOGLEVEL f " @%s:%d\n", x);   \
11433 +       } while (0)
11434 +
11435 +#define vxfprintk(c, f, x...)                                  \
11436 +       do {                                                    \
11437 +               if (c)                                          \
11438 +                       printk(VX_LOGLEVEL f " %s@%s:%d\n", x); \
11439 +       } while (0)
11440 +
11441 +
11442 +struct vx_info;
11443 +
11444 +void dump_vx_info(struct vx_info *, int);
11445 +void dump_vx_info_inactive(int);
11446 +
11447 +#else  /* CONFIG_VSERVER_DEBUG */
11448 +
11449 +#define vs_debug_switch        0
11450 +#define vs_debug_xid   0
11451 +#define vs_debug_nid   0
11452 +#define vs_debug_tag   0
11453 +#define vs_debug_net   0
11454 +#define vs_debug_limit 0
11455 +#define vs_debug_cres  0
11456 +#define vs_debug_dlim  0
11457 +#define vs_debug_quota 0
11458 +#define vs_debug_cvirt 0
11459 +#define vs_debug_space 0
11460 +#define vs_debug_perm  0
11461 +#define vs_debug_misc  0
11462 +
11463 +#define vxdprintk(x...) do { } while (0)
11464 +#define vxlprintk(x...) do { } while (0)
11465 +#define vxfprintk(x...) do { } while (0)
11466 +
11467 +#endif /* CONFIG_VSERVER_DEBUG */
11468 +
11469 +
11470 +#ifdef CONFIG_VSERVER_WARN
11471 +
11472 +#define VX_WARNLEVEL   KERN_WARNING "vxW: "
11473 +#define VX_WARN_TASK   "[" VS_Q("%s") ",%u:#%u|%u|%u] "
11474 +#define VX_WARN_XID    "[xid #%u] "
11475 +#define VX_WARN_NID    "[nid #%u] "
11476 +#define VX_WARN_TAG    "[tag #%u] "
11477 +
11478 +#define vxwprintk(c, f, x...)                                  \
11479 +       do {                                                    \
11480 +               if (c)                                          \
11481 +                       printk(VX_WARNLEVEL f "\n", ##x);       \
11482 +       } while (0)
11483 +
11484 +#else  /* CONFIG_VSERVER_WARN */
11485 +
11486 +#define vxwprintk(x...) do { } while (0)
11487 +
11488 +#endif /* CONFIG_VSERVER_WARN */
11489 +
11490 +#define vxwprintk_task(c, f, x...)                             \
11491 +       vxwprintk(c, VX_WARN_TASK f,                            \
11492 +               current->comm, current->pid,                    \
11493 +               current->xid, current->nid, current->tag, ##x)
11494 +#define vxwprintk_xid(c, f, x...)                              \
11495 +       vxwprintk(c, VX_WARN_XID f, current->xid, x)
11496 +#define vxwprintk_nid(c, f, x...)                              \
11497 +       vxwprintk(c, VX_WARN_NID f, current->nid, x)
11498 +#define vxwprintk_tag(c, f, x...)                              \
11499 +       vxwprintk(c, VX_WARN_TAG f, current->tag, x)
11500 +
11501 +#ifdef CONFIG_VSERVER_DEBUG
11502 +#define vxd_assert_lock(l)     assert_spin_locked(l)
11503 +#define vxd_assert(c, f, x...) vxlprintk(!(c), \
11504 +       "assertion [" f "] failed.", ##x, __FILE__, __LINE__)
11505 +#else
11506 +#define vxd_assert_lock(l)     do { } while (0)
11507 +#define vxd_assert(c, f, x...) do { } while (0)
11508 +#endif
11509 +
11510 +
11511 +#endif /* _VX_DEBUG_H */
11512 diff -NurpP --minimal linux-3.6/include/linux/vserver/debug_cmd.h linux-3.6-vs2.3.4.3-noxfs-nocow/include/linux/vserver/debug_cmd.h
11513 --- linux-3.6/include/linux/vserver/debug_cmd.h 1970-01-01 01:00:00.000000000 +0100
11514 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/include/linux/vserver/debug_cmd.h   2012-10-04 18:47:00.000000000 +0200
11515 @@ -0,0 +1,58 @@
11516 +#ifndef _VX_DEBUG_CMD_H
11517 +#define _VX_DEBUG_CMD_H
11518 +
11519 +
11520 +/* debug commands */
11521 +
11522 +#define VCMD_dump_history      VC_CMD(DEBUG, 1, 0)
11523 +
11524 +#define VCMD_read_history      VC_CMD(DEBUG, 5, 0)
11525 +#define VCMD_read_monitor      VC_CMD(DEBUG, 6, 0)
11526 +
11527 +struct  vcmd_read_history_v0 {
11528 +       uint32_t index;
11529 +       uint32_t count;
11530 +       char __user *data;
11531 +};
11532 +
11533 +struct  vcmd_read_monitor_v0 {
11534 +       uint32_t index;
11535 +       uint32_t count;
11536 +       char __user *data;
11537 +};
11538 +
11539 +
11540 +#ifdef __KERNEL__
11541 +
11542 +#ifdef CONFIG_COMPAT
11543 +
11544 +#include <asm/compat.h>
11545 +
11546 +struct vcmd_read_history_v0_x32 {
11547 +       uint32_t index;
11548 +       uint32_t count;
11549 +       compat_uptr_t data_ptr;
11550 +};
11551 +
11552 +struct vcmd_read_monitor_v0_x32 {
11553 +       uint32_t index;
11554 +       uint32_t count;
11555 +       compat_uptr_t data_ptr;
11556 +};
11557 +
11558 +#endif  /* CONFIG_COMPAT */
11559 +
11560 +extern int vc_dump_history(uint32_t);
11561 +
11562 +extern int vc_read_history(uint32_t, void __user *);
11563 +extern int vc_read_monitor(uint32_t, void __user *);
11564 +
11565 +#ifdef CONFIG_COMPAT
11566 +
11567 +extern int vc_read_history_x32(uint32_t, void __user *);
11568 +extern int vc_read_monitor_x32(uint32_t, void __user *);
11569 +
11570 +#endif  /* CONFIG_COMPAT */
11571 +
11572 +#endif /* __KERNEL__ */
11573 +#endif /* _VX_DEBUG_CMD_H */
11574 diff -NurpP --minimal linux-3.6/include/linux/vserver/device.h linux-3.6-vs2.3.4.3-noxfs-nocow/include/linux/vserver/device.h
11575 --- linux-3.6/include/linux/vserver/device.h    1970-01-01 01:00:00.000000000 +0100
11576 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/include/linux/vserver/device.h      2012-10-04 18:47:00.000000000 +0200
11577 @@ -0,0 +1,15 @@
11578 +#ifndef _VX_DEVICE_H
11579 +#define _VX_DEVICE_H
11580 +
11581 +
11582 +#define DATTR_CREATE   0x00000001
11583 +#define DATTR_OPEN     0x00000002
11584 +
11585 +#define DATTR_REMAP    0x00000010
11586 +
11587 +#define DATTR_MASK     0x00000013
11588 +
11589 +
11590 +#else  /* _VX_DEVICE_H */
11591 +#warning duplicate inclusion
11592 +#endif /* _VX_DEVICE_H */
11593 diff -NurpP --minimal linux-3.6/include/linux/vserver/device_cmd.h linux-3.6-vs2.3.4.3-noxfs-nocow/include/linux/vserver/device_cmd.h
11594 --- linux-3.6/include/linux/vserver/device_cmd.h        1970-01-01 01:00:00.000000000 +0100
11595 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/include/linux/vserver/device_cmd.h  2012-10-04 18:47:00.000000000 +0200
11596 @@ -0,0 +1,44 @@
11597 +#ifndef _VX_DEVICE_CMD_H
11598 +#define _VX_DEVICE_CMD_H
11599 +
11600 +
11601 +/*  device vserver commands */
11602 +
11603 +#define VCMD_set_mapping       VC_CMD(DEVICE, 1, 0)
11604 +#define VCMD_unset_mapping     VC_CMD(DEVICE, 2, 0)
11605 +
11606 +struct vcmd_set_mapping_v0 {
11607 +       const char __user *device;
11608 +       const char __user *target;
11609 +       uint32_t flags;
11610 +};
11611 +
11612 +
11613 +#ifdef __KERNEL__
11614 +
11615 +#ifdef CONFIG_COMPAT
11616 +
11617 +#include <asm/compat.h>
11618 +
11619 +struct vcmd_set_mapping_v0_x32 {
11620 +       compat_uptr_t device_ptr;
11621 +       compat_uptr_t target_ptr;
11622 +       uint32_t flags;
11623 +};
11624 +
11625 +#endif /* CONFIG_COMPAT */
11626 +
11627 +#include <linux/compiler.h>
11628 +
11629 +extern int vc_set_mapping(struct vx_info *, void __user *);
11630 +extern int vc_unset_mapping(struct vx_info *, void __user *);
11631 +
11632 +#ifdef CONFIG_COMPAT
11633 +
11634 +extern int vc_set_mapping_x32(struct vx_info *, void __user *);
11635 +extern int vc_unset_mapping_x32(struct vx_info *, void __user *);
11636 +
11637 +#endif /* CONFIG_COMPAT */
11638 +
11639 +#endif /* __KERNEL__ */
11640 +#endif /* _VX_DEVICE_CMD_H */
11641 diff -NurpP --minimal linux-3.6/include/linux/vserver/device_def.h linux-3.6-vs2.3.4.3-noxfs-nocow/include/linux/vserver/device_def.h
11642 --- linux-3.6/include/linux/vserver/device_def.h        1970-01-01 01:00:00.000000000 +0100
11643 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/include/linux/vserver/device_def.h  2012-10-04 18:47:00.000000000 +0200
11644 @@ -0,0 +1,17 @@
11645 +#ifndef _VX_DEVICE_DEF_H
11646 +#define _VX_DEVICE_DEF_H
11647 +
11648 +#include <linux/types.h>
11649 +
11650 +struct vx_dmap_target {
11651 +       dev_t target;
11652 +       uint32_t flags;
11653 +};
11654 +
11655 +struct _vx_device {
11656 +#ifdef CONFIG_VSERVER_DEVICE
11657 +       struct vx_dmap_target targets[2];
11658 +#endif
11659 +};
11660 +
11661 +#endif /* _VX_DEVICE_DEF_H */
11662 diff -NurpP --minimal linux-3.6/include/linux/vserver/dlimit.h linux-3.6-vs2.3.4.3-noxfs-nocow/include/linux/vserver/dlimit.h
11663 --- linux-3.6/include/linux/vserver/dlimit.h    1970-01-01 01:00:00.000000000 +0100
11664 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/include/linux/vserver/dlimit.h      2012-10-04 18:47:00.000000000 +0200
11665 @@ -0,0 +1,54 @@
11666 +#ifndef _VX_DLIMIT_H
11667 +#define _VX_DLIMIT_H
11668 +
11669 +#include "switch.h"
11670 +
11671 +
11672 +#ifdef __KERNEL__
11673 +
11674 +/*      keep in sync with CDLIM_INFINITY       */
11675 +
11676 +#define DLIM_INFINITY          (~0ULL)
11677 +
11678 +#include <linux/spinlock.h>
11679 +#include <linux/rcupdate.h>
11680 +
11681 +struct super_block;
11682 +
11683 +struct dl_info {
11684 +       struct hlist_node dl_hlist;             /* linked list of contexts */
11685 +       struct rcu_head dl_rcu;                 /* the rcu head */
11686 +       tag_t dl_tag;                           /* context tag */
11687 +       atomic_t dl_usecnt;                     /* usage count */
11688 +       atomic_t dl_refcnt;                     /* reference count */
11689 +
11690 +       struct super_block *dl_sb;              /* associated superblock */
11691 +
11692 +       spinlock_t dl_lock;                     /* protect the values */
11693 +
11694 +       unsigned long long dl_space_used;       /* used space in bytes */
11695 +       unsigned long long dl_space_total;      /* maximum space in bytes */
11696 +       unsigned long dl_inodes_used;           /* used inodes */
11697 +       unsigned long dl_inodes_total;          /* maximum inodes */
11698 +
11699 +       unsigned int dl_nrlmult;                /* non root limit mult */
11700 +};
11701 +
11702 +struct rcu_head;
11703 +
11704 +extern void rcu_free_dl_info(struct rcu_head *);
11705 +extern void unhash_dl_info(struct dl_info *);
11706 +
11707 +extern struct dl_info *locate_dl_info(struct super_block *, tag_t);
11708 +
11709 +
11710 +struct kstatfs;
11711 +
11712 +extern void vx_vsi_statfs(struct super_block *, struct kstatfs *);
11713 +
11714 +typedef uint64_t dlsize_t;
11715 +
11716 +#endif /* __KERNEL__ */
11717 +#else  /* _VX_DLIMIT_H */
11718 +#warning duplicate inclusion
11719 +#endif /* _VX_DLIMIT_H */
11720 diff -NurpP --minimal linux-3.6/include/linux/vserver/dlimit_cmd.h linux-3.6-vs2.3.4.3-noxfs-nocow/include/linux/vserver/dlimit_cmd.h
11721 --- linux-3.6/include/linux/vserver/dlimit_cmd.h        1970-01-01 01:00:00.000000000 +0100
11722 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/include/linux/vserver/dlimit_cmd.h  2012-10-04 18:47:00.000000000 +0200
11723 @@ -0,0 +1,109 @@
11724 +#ifndef _VX_DLIMIT_CMD_H
11725 +#define _VX_DLIMIT_CMD_H
11726 +
11727 +
11728 +/*  dlimit vserver commands */
11729 +
11730 +#define VCMD_add_dlimit                VC_CMD(DLIMIT, 1, 0)
11731 +#define VCMD_rem_dlimit                VC_CMD(DLIMIT, 2, 0)
11732 +
11733 +#define VCMD_set_dlimit                VC_CMD(DLIMIT, 5, 0)
11734 +#define VCMD_get_dlimit                VC_CMD(DLIMIT, 6, 0)
11735 +
11736 +struct vcmd_ctx_dlimit_base_v0 {
11737 +       const char __user *name;
11738 +       uint32_t flags;
11739 +};
11740 +
11741 +struct vcmd_ctx_dlimit_v0 {
11742 +       const char __user *name;
11743 +       uint32_t space_used;                    /* used space in kbytes */
11744 +       uint32_t space_total;                   /* maximum space in kbytes */
11745 +       uint32_t inodes_used;                   /* used inodes */
11746 +       uint32_t inodes_total;                  /* maximum inodes */
11747 +       uint32_t reserved;                      /* reserved for root in % */
11748 +       uint32_t flags;
11749 +};
11750 +
11751 +#define CDLIM_UNSET            ((uint32_t)0UL)
11752 +#define CDLIM_INFINITY         ((uint32_t)~0UL)
11753 +#define CDLIM_KEEP             ((uint32_t)~1UL)
11754 +
11755 +#define DLIME_UNIT     0
11756 +#define DLIME_KILO     1
11757 +#define DLIME_MEGA     2
11758 +#define DLIME_GIGA     3
11759 +
11760 +#define DLIMF_SHIFT    0x10
11761 +
11762 +#define DLIMS_USED     0
11763 +#define DLIMS_TOTAL    2
11764 +
11765 +static inline
11766 +uint64_t dlimit_space_32to64(uint32_t val, uint32_t flags, int shift)
11767 +{
11768 +       int exp = (flags & DLIMF_SHIFT) ?
11769 +               (flags >> shift) & DLIME_GIGA : DLIME_KILO;
11770 +       return ((uint64_t)val) << (10 * exp);
11771 +}
11772 +
11773 +static inline
11774 +uint32_t dlimit_space_64to32(uint64_t val, uint32_t *flags, int shift)
11775 +{
11776 +       int exp = 0;
11777 +
11778 +       if (*flags & DLIMF_SHIFT) {
11779 +               while (val > (1LL << 32) && (exp < 3)) {
11780 +                       val >>= 10;
11781 +                       exp++;
11782 +               }
11783 +               *flags &= ~(DLIME_GIGA << shift);
11784 +               *flags |= exp << shift;
11785 +       } else
11786 +               val >>= 10;
11787 +       return val;
11788 +}
11789 +
11790 +#ifdef __KERNEL__
11791 +
11792 +#ifdef CONFIG_COMPAT
11793 +
11794 +#include <asm/compat.h>
11795 +
11796 +struct vcmd_ctx_dlimit_base_v0_x32 {
11797 +       compat_uptr_t name_ptr;
11798 +       uint32_t flags;
11799 +};
11800 +
11801 +struct vcmd_ctx_dlimit_v0_x32 {
11802 +       compat_uptr_t name_ptr;
11803 +       uint32_t space_used;                    /* used space in kbytes */
11804 +       uint32_t space_total;                   /* maximum space in kbytes */
11805 +       uint32_t inodes_used;                   /* used inodes */
11806 +       uint32_t inodes_total;                  /* maximum inodes */
11807 +       uint32_t reserved;                      /* reserved for root in % */
11808 +       uint32_t flags;
11809 +};
11810 +
11811 +#endif /* CONFIG_COMPAT */
11812 +
11813 +#include <linux/compiler.h>
11814 +
11815 +extern int vc_add_dlimit(uint32_t, void __user *);
11816 +extern int vc_rem_dlimit(uint32_t, void __user *);
11817 +
11818 +extern int vc_set_dlimit(uint32_t, void __user *);
11819 +extern int vc_get_dlimit(uint32_t, void __user *);
11820 +
11821 +#ifdef CONFIG_COMPAT
11822 +
11823 +extern int vc_add_dlimit_x32(uint32_t, void __user *);
11824 +extern int vc_rem_dlimit_x32(uint32_t, void __user *);
11825 +
11826 +extern int vc_set_dlimit_x32(uint32_t, void __user *);
11827 +extern int vc_get_dlimit_x32(uint32_t, void __user *);
11828 +
11829 +#endif /* CONFIG_COMPAT */
11830 +
11831 +#endif /* __KERNEL__ */
11832 +#endif /* _VX_DLIMIT_CMD_H */
11833 diff -NurpP --minimal linux-3.6/include/linux/vserver/global.h linux-3.6-vs2.3.4.3-noxfs-nocow/include/linux/vserver/global.h
11834 --- linux-3.6/include/linux/vserver/global.h    1970-01-01 01:00:00.000000000 +0100
11835 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/include/linux/vserver/global.h      2012-10-04 18:47:00.000000000 +0200
11836 @@ -0,0 +1,19 @@
11837 +#ifndef _VX_GLOBAL_H
11838 +#define _VX_GLOBAL_H
11839 +
11840 +
11841 +extern atomic_t vx_global_ctotal;
11842 +extern atomic_t vx_global_cactive;
11843 +
11844 +extern atomic_t nx_global_ctotal;
11845 +extern atomic_t nx_global_cactive;
11846 +
11847 +extern atomic_t vs_global_nsproxy;
11848 +extern atomic_t vs_global_fs;
11849 +extern atomic_t vs_global_mnt_ns;
11850 +extern atomic_t vs_global_uts_ns;
11851 +extern atomic_t vs_global_user_ns;
11852 +extern atomic_t vs_global_pid_ns;
11853 +
11854 +
11855 +#endif /* _VX_GLOBAL_H */
11856 diff -NurpP --minimal linux-3.6/include/linux/vserver/history.h linux-3.6-vs2.3.4.3-noxfs-nocow/include/linux/vserver/history.h
11857 --- linux-3.6/include/linux/vserver/history.h   1970-01-01 01:00:00.000000000 +0100
11858 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/include/linux/vserver/history.h     2012-10-04 18:47:00.000000000 +0200
11859 @@ -0,0 +1,197 @@
11860 +#ifndef _VX_HISTORY_H
11861 +#define _VX_HISTORY_H
11862 +
11863 +
11864 +enum {
11865 +       VXH_UNUSED = 0,
11866 +       VXH_THROW_OOPS = 1,
11867 +
11868 +       VXH_GET_VX_INFO,
11869 +       VXH_PUT_VX_INFO,
11870 +       VXH_INIT_VX_INFO,
11871 +       VXH_SET_VX_INFO,
11872 +       VXH_CLR_VX_INFO,
11873 +       VXH_CLAIM_VX_INFO,
11874 +       VXH_RELEASE_VX_INFO,
11875 +       VXH_ALLOC_VX_INFO,
11876 +       VXH_DEALLOC_VX_INFO,
11877 +       VXH_HASH_VX_INFO,
11878 +       VXH_UNHASH_VX_INFO,
11879 +       VXH_LOC_VX_INFO,
11880 +       VXH_LOOKUP_VX_INFO,
11881 +       VXH_CREATE_VX_INFO,
11882 +};
11883 +
11884 +struct _vxhe_vxi {
11885 +       struct vx_info *ptr;
11886 +       unsigned xid;
11887 +       unsigned usecnt;
11888 +       unsigned tasks;
11889 +};
11890 +
11891 +struct _vxhe_set_clr {
11892 +       void *data;
11893 +};
11894 +
11895 +struct _vxhe_loc_lookup {
11896 +       unsigned arg;
11897 +};
11898 +
11899 +struct _vx_hist_entry {
11900 +       void *loc;
11901 +       unsigned short seq;
11902 +       unsigned short type;
11903 +       struct _vxhe_vxi vxi;
11904 +       union {
11905 +               struct _vxhe_set_clr sc;
11906 +               struct _vxhe_loc_lookup ll;
11907 +       };
11908 +};
11909 +
11910 +#ifdef CONFIG_VSERVER_HISTORY
11911 +
11912 +extern unsigned volatile int vxh_active;
11913 +
11914 +struct _vx_hist_entry *vxh_advance(void *loc);
11915 +
11916 +
11917 +static inline
11918 +void   __vxh_copy_vxi(struct _vx_hist_entry *entry, struct vx_info *vxi)
11919 +{
11920 +       entry->vxi.ptr = vxi;
11921 +       if (vxi) {
11922 +               entry->vxi.usecnt = atomic_read(&vxi->vx_usecnt);
11923 +               entry->vxi.tasks = atomic_read(&vxi->vx_tasks);
11924 +               entry->vxi.xid = vxi->vx_id;
11925 +       }
11926 +}
11927 +
11928 +
11929 +#define        __HERE__ current_text_addr()
11930 +
11931 +#define __VXH_BODY(__type, __data, __here)     \
11932 +       struct _vx_hist_entry *entry;           \
11933 +                                               \
11934 +       preempt_disable();                      \
11935 +       entry = vxh_advance(__here);            \
11936 +       __data;                                 \
11937 +       entry->type = __type;                   \
11938 +       preempt_enable();
11939 +
11940 +
11941 +       /* pass vxi only */
11942 +
11943 +#define __VXH_SMPL                             \
11944 +       __vxh_copy_vxi(entry, vxi)
11945 +
11946 +static inline
11947 +void   __vxh_smpl(struct vx_info *vxi, int __type, void *__here)
11948 +{
11949 +       __VXH_BODY(__type, __VXH_SMPL, __here)
11950 +}
11951 +
11952 +       /* pass vxi and data (void *) */
11953 +
11954 +#define __VXH_DATA                             \
11955 +       __vxh_copy_vxi(entry, vxi);             \
11956 +       entry->sc.data = data
11957 +
11958 +static inline
11959 +void   __vxh_data(struct vx_info *vxi, void *data,
11960 +                       int __type, void *__here)
11961 +{
11962 +       __VXH_BODY(__type, __VXH_DATA, __here)
11963 +}
11964 +
11965 +       /* pass vxi and arg (long) */
11966 +
11967 +#define __VXH_LONG                             \
11968 +       __vxh_copy_vxi(entry, vxi);             \
11969 +       entry->ll.arg = arg
11970 +
11971 +static inline
11972 +void   __vxh_long(struct vx_info *vxi, long arg,
11973 +                       int __type, void *__here)
11974 +{
11975 +       __VXH_BODY(__type, __VXH_LONG, __here)
11976 +}
11977 +
11978 +
11979 +static inline
11980 +void   __vxh_throw_oops(void *__here)
11981 +{
11982 +       __VXH_BODY(VXH_THROW_OOPS, {}, __here);
11983 +       /* prevent further acquisition */
11984 +       vxh_active = 0;
11985 +}
11986 +
11987 +
11988 +#define vxh_throw_oops()       __vxh_throw_oops(__HERE__);
11989 +
11990 +#define __vxh_get_vx_info(v, h)        __vxh_smpl(v, VXH_GET_VX_INFO, h);
11991 +#define __vxh_put_vx_info(v, h)        __vxh_smpl(v, VXH_PUT_VX_INFO, h);
11992 +
11993 +#define __vxh_init_vx_info(v, d, h) \
11994 +       __vxh_data(v, d, VXH_INIT_VX_INFO, h);
11995 +#define __vxh_set_vx_info(v, d, h) \
11996 +       __vxh_data(v, d, VXH_SET_VX_INFO, h);
11997 +#define __vxh_clr_vx_info(v, d, h) \
11998 +       __vxh_data(v, d, VXH_CLR_VX_INFO, h);
11999 +
12000 +#define __vxh_claim_vx_info(v, d, h) \
12001 +       __vxh_data(v, d, VXH_CLAIM_VX_INFO, h);
12002 +#define __vxh_release_vx_info(v, d, h) \
12003 +       __vxh_data(v, d, VXH_RELEASE_VX_INFO, h);
12004 +
12005 +#define vxh_alloc_vx_info(v) \
12006 +       __vxh_smpl(v, VXH_ALLOC_VX_INFO, __HERE__);
12007 +#define vxh_dealloc_vx_info(v) \
12008 +       __vxh_smpl(v, VXH_DEALLOC_VX_INFO, __HERE__);
12009 +
12010 +#define vxh_hash_vx_info(v) \
12011 +       __vxh_smpl(v, VXH_HASH_VX_INFO, __HERE__);
12012 +#define vxh_unhash_vx_info(v) \
12013 +       __vxh_smpl(v, VXH_UNHASH_VX_INFO, __HERE__);
12014 +
12015 +#define vxh_loc_vx_info(v, l) \
12016 +       __vxh_long(v, l, VXH_LOC_VX_INFO, __HERE__);
12017 +#define vxh_lookup_vx_info(v, l) \
12018 +       __vxh_long(v, l, VXH_LOOKUP_VX_INFO, __HERE__);
12019 +#define vxh_create_vx_info(v, l) \
12020 +       __vxh_long(v, l, VXH_CREATE_VX_INFO, __HERE__);
12021 +
12022 +extern void vxh_dump_history(void);
12023 +
12024 +
12025 +#else  /* CONFIG_VSERVER_HISTORY */
12026 +
12027 +#define        __HERE__        0
12028 +
12029 +#define vxh_throw_oops()               do { } while (0)
12030 +
12031 +#define __vxh_get_vx_info(v, h)                do { } while (0)
12032 +#define __vxh_put_vx_info(v, h)                do { } while (0)
12033 +
12034 +#define __vxh_init_vx_info(v, d, h)    do { } while (0)
12035 +#define __vxh_set_vx_info(v, d, h)     do { } while (0)
12036 +#define __vxh_clr_vx_info(v, d, h)     do { } while (0)
12037 +
12038 +#define __vxh_claim_vx_info(v, d, h)   do { } while (0)
12039 +#define __vxh_release_vx_info(v, d, h) do { } while (0)
12040 +
12041 +#define vxh_alloc_vx_info(v)           do { } while (0)
12042 +#define vxh_dealloc_vx_info(v)         do { } while (0)
12043 +
12044 +#define vxh_hash_vx_info(v)            do { } while (0)
12045 +#define vxh_unhash_vx_info(v)          do { } while (0)
12046 +
12047 +#define vxh_loc_vx_info(v, l)          do { } while (0)
12048 +#define vxh_lookup_vx_info(v, l)       do { } while (0)
12049 +#define vxh_create_vx_info(v, l)       do { } while (0)
12050 +
12051 +#define vxh_dump_history()             do { } while (0)
12052 +
12053 +
12054 +#endif /* CONFIG_VSERVER_HISTORY */
12055 +
12056 +#endif /* _VX_HISTORY_H */
12057 diff -NurpP --minimal linux-3.6/include/linux/vserver/inode.h linux-3.6-vs2.3.4.3-noxfs-nocow/include/linux/vserver/inode.h
12058 --- linux-3.6/include/linux/vserver/inode.h     1970-01-01 01:00:00.000000000 +0100
12059 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/include/linux/vserver/inode.h       2012-10-04 18:47:00.000000000 +0200
12060 @@ -0,0 +1,39 @@
12061 +#ifndef _VX_INODE_H
12062 +#define _VX_INODE_H
12063 +
12064 +
12065 +#define IATTR_TAG      0x01000000
12066 +
12067 +#define IATTR_ADMIN    0x00000001
12068 +#define IATTR_WATCH    0x00000002
12069 +#define IATTR_HIDE     0x00000004
12070 +#define IATTR_FLAGS    0x00000007
12071 +
12072 +#define IATTR_BARRIER  0x00010000
12073 +#define IATTR_IXUNLINK 0x00020000
12074 +#define IATTR_IMMUTABLE 0x00040000
12075 +#define IATTR_COW      0x00080000
12076 +
12077 +#ifdef __KERNEL__
12078 +
12079 +
12080 +#ifdef CONFIG_VSERVER_PROC_SECURE
12081 +#define IATTR_PROC_DEFAULT     ( IATTR_ADMIN | IATTR_HIDE )
12082 +#define IATTR_PROC_SYMLINK     ( IATTR_ADMIN )
12083 +#else
12084 +#define IATTR_PROC_DEFAULT     ( IATTR_ADMIN )
12085 +#define IATTR_PROC_SYMLINK     ( IATTR_ADMIN )
12086 +#endif
12087 +
12088 +#define vx_hide_check(c, m)    (((m) & IATTR_HIDE) ? vx_check(c, m) : 1)
12089 +
12090 +#endif /* __KERNEL__ */
12091 +
12092 +/* inode ioctls */
12093 +
12094 +#define FIOC_GETXFLG   _IOR('x', 5, long)
12095 +#define FIOC_SETXFLG   _IOW('x', 6, long)
12096 +
12097 +#else  /* _VX_INODE_H */
12098 +#warning duplicate inclusion
12099 +#endif /* _VX_INODE_H */
12100 diff -NurpP --minimal linux-3.6/include/linux/vserver/inode_cmd.h linux-3.6-vs2.3.4.3-noxfs-nocow/include/linux/vserver/inode_cmd.h
12101 --- linux-3.6/include/linux/vserver/inode_cmd.h 1970-01-01 01:00:00.000000000 +0100
12102 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/include/linux/vserver/inode_cmd.h   2012-10-04 18:47:00.000000000 +0200
12103 @@ -0,0 +1,59 @@
12104 +#ifndef _VX_INODE_CMD_H
12105 +#define _VX_INODE_CMD_H
12106 +
12107 +
12108 +/*  inode vserver commands */
12109 +
12110 +#define VCMD_get_iattr         VC_CMD(INODE, 1, 1)
12111 +#define VCMD_set_iattr         VC_CMD(INODE, 2, 1)
12112 +
12113 +#define VCMD_fget_iattr                VC_CMD(INODE, 3, 0)
12114 +#define VCMD_fset_iattr                VC_CMD(INODE, 4, 0)
12115 +
12116 +struct vcmd_ctx_iattr_v1 {
12117 +       const char __user *name;
12118 +       uint32_t tag;
12119 +       uint32_t flags;
12120 +       uint32_t mask;
12121 +};
12122 +
12123 +struct vcmd_ctx_fiattr_v0 {
12124 +       uint32_t tag;
12125 +       uint32_t flags;
12126 +       uint32_t mask;
12127 +};
12128 +
12129 +
12130 +#ifdef __KERNEL__
12131 +
12132 +
12133 +#ifdef CONFIG_COMPAT
12134 +
12135 +#include <asm/compat.h>
12136 +
12137 +struct vcmd_ctx_iattr_v1_x32 {
12138 +       compat_uptr_t name_ptr;
12139 +       uint32_t tag;
12140 +       uint32_t flags;
12141 +       uint32_t mask;
12142 +};
12143 +
12144 +#endif /* CONFIG_COMPAT */
12145 +
12146 +#include <linux/compiler.h>
12147 +
12148 +extern int vc_get_iattr(void __user *);
12149 +extern int vc_set_iattr(void __user *);
12150 +
12151 +extern int vc_fget_iattr(uint32_t, void __user *);
12152 +extern int vc_fset_iattr(uint32_t, void __user *);
12153 +
12154 +#ifdef CONFIG_COMPAT
12155 +
12156 +extern int vc_get_iattr_x32(void __user *);
12157 +extern int vc_set_iattr_x32(void __user *);
12158 +
12159 +#endif /* CONFIG_COMPAT */
12160 +
12161 +#endif /* __KERNEL__ */
12162 +#endif /* _VX_INODE_CMD_H */
12163 diff -NurpP --minimal linux-3.6/include/linux/vserver/limit.h linux-3.6-vs2.3.4.3-noxfs-nocow/include/linux/vserver/limit.h
12164 --- linux-3.6/include/linux/vserver/limit.h     1970-01-01 01:00:00.000000000 +0100
12165 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/include/linux/vserver/limit.h       2012-10-04 18:47:00.000000000 +0200
12166 @@ -0,0 +1,71 @@
12167 +#ifndef _VX_LIMIT_H
12168 +#define _VX_LIMIT_H
12169 +
12170 +#define VLIMIT_NSOCK   16
12171 +#define VLIMIT_OPENFD  17
12172 +#define VLIMIT_ANON    18
12173 +#define VLIMIT_SHMEM   19
12174 +#define VLIMIT_SEMARY  20
12175 +#define VLIMIT_NSEMS   21
12176 +#define VLIMIT_DENTRY  22
12177 +#define VLIMIT_MAPPED  23
12178 +
12179 +
12180 +#ifdef __KERNEL__
12181 +
12182 +#define        VLIM_NOCHECK    ((1L << VLIMIT_DENTRY) | (1L << RLIMIT_RSS))
12183 +
12184 +/*     keep in sync with CRLIM_INFINITY */
12185 +
12186 +#define        VLIM_INFINITY   (~0ULL)
12187 +
12188 +#include <asm/atomic.h>
12189 +#include <asm/resource.h>
12190 +
12191 +#ifndef RLIM_INFINITY
12192 +#warning RLIM_INFINITY is undefined
12193 +#endif
12194 +
12195 +#define __rlim_val(l, r, v)    ((l)->res[r].v)
12196 +
12197 +#define __rlim_soft(l, r)      __rlim_val(l, r, soft)
12198 +#define __rlim_hard(l, r)      __rlim_val(l, r, hard)
12199 +
12200 +#define __rlim_rcur(l, r)      __rlim_val(l, r, rcur)
12201 +#define __rlim_rmin(l, r)      __rlim_val(l, r, rmin)
12202 +#define __rlim_rmax(l, r)      __rlim_val(l, r, rmax)
12203 +
12204 +#define __rlim_lhit(l, r)      __rlim_val(l, r, lhit)
12205 +#define __rlim_hit(l, r)       atomic_inc(&__rlim_lhit(l, r))
12206 +
12207 +typedef atomic_long_t rlim_atomic_t;
12208 +typedef unsigned long rlim_t;
12209 +
12210 +#define __rlim_get(l, r)       atomic_long_read(&__rlim_rcur(l, r))
12211 +#define __rlim_set(l, r, v)    atomic_long_set(&__rlim_rcur(l, r), v)
12212 +#define __rlim_inc(l, r)       atomic_long_inc(&__rlim_rcur(l, r))
12213 +#define __rlim_dec(l, r)       atomic_long_dec(&__rlim_rcur(l, r))
12214 +#define __rlim_add(l, r, v)    atomic_long_add(v, &__rlim_rcur(l, r))
12215 +#define __rlim_sub(l, r, v)    atomic_long_sub(v, &__rlim_rcur(l, r))
12216 +
12217 +
12218 +#if    (RLIM_INFINITY == VLIM_INFINITY)
12219 +#define        VX_VLIM(r) ((long long)(long)(r))
12220 +#define        VX_RLIM(v) ((rlim_t)(v))
12221 +#else
12222 +#define        VX_VLIM(r) (((r) == RLIM_INFINITY) \
12223 +               ? VLIM_INFINITY : (long long)(r))
12224 +#define        VX_RLIM(v) (((v) == VLIM_INFINITY) \
12225 +               ? RLIM_INFINITY : (rlim_t)(v))
12226 +#endif
12227 +
12228 +struct sysinfo;
12229 +
12230 +void vx_vsi_meminfo(struct sysinfo *);
12231 +void vx_vsi_swapinfo(struct sysinfo *);
12232 +long vx_vsi_cached(struct sysinfo *);
12233 +
12234 +#define NUM_LIMITS     24
12235 +
12236 +#endif /* __KERNEL__ */
12237 +#endif /* _VX_LIMIT_H */
12238 diff -NurpP --minimal linux-3.6/include/linux/vserver/limit_cmd.h linux-3.6-vs2.3.4.3-noxfs-nocow/include/linux/vserver/limit_cmd.h
12239 --- linux-3.6/include/linux/vserver/limit_cmd.h 1970-01-01 01:00:00.000000000 +0100
12240 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/include/linux/vserver/limit_cmd.h   2012-10-04 18:47:00.000000000 +0200
12241 @@ -0,0 +1,71 @@
12242 +#ifndef _VX_LIMIT_CMD_H
12243 +#define _VX_LIMIT_CMD_H
12244 +
12245 +
12246 +/*  rlimit vserver commands */
12247 +
12248 +#define VCMD_get_rlimit                VC_CMD(RLIMIT, 1, 0)
12249 +#define VCMD_set_rlimit                VC_CMD(RLIMIT, 2, 0)
12250 +#define VCMD_get_rlimit_mask   VC_CMD(RLIMIT, 3, 0)
12251 +#define VCMD_reset_hits                VC_CMD(RLIMIT, 7, 0)
12252 +#define VCMD_reset_minmax      VC_CMD(RLIMIT, 9, 0)
12253 +
12254 +struct vcmd_ctx_rlimit_v0 {
12255 +       uint32_t id;
12256 +       uint64_t minimum;
12257 +       uint64_t softlimit;
12258 +       uint64_t maximum;
12259 +};
12260 +
12261 +struct vcmd_ctx_rlimit_mask_v0 {
12262 +       uint32_t minimum;
12263 +       uint32_t softlimit;
12264 +       uint32_t maximum;
12265 +};
12266 +
12267 +#define VCMD_rlimit_stat       VC_CMD(VSTAT, 1, 0)
12268 +
12269 +struct vcmd_rlimit_stat_v0 {
12270 +       uint32_t id;
12271 +       uint32_t hits;
12272 +       uint64_t value;
12273 +       uint64_t minimum;
12274 +       uint64_t maximum;
12275 +};
12276 +
12277 +#define CRLIM_UNSET            (0ULL)
12278 +#define CRLIM_INFINITY         (~0ULL)
12279 +#define CRLIM_KEEP             (~1ULL)
12280 +
12281 +#ifdef __KERNEL__
12282 +
12283 +#ifdef CONFIG_IA32_EMULATION
12284 +
12285 +struct vcmd_ctx_rlimit_v0_x32 {
12286 +       uint32_t id;
12287 +       uint64_t minimum;
12288 +       uint64_t softlimit;
12289 +       uint64_t maximum;
12290 +} __attribute__ ((packed));
12291 +
12292 +#endif /* CONFIG_IA32_EMULATION */
12293 +
12294 +#include <linux/compiler.h>
12295 +
12296 +extern int vc_get_rlimit_mask(uint32_t, void __user *);
12297 +extern int vc_get_rlimit(struct vx_info *, void __user *);
12298 +extern int vc_set_rlimit(struct vx_info *, void __user *);
12299 +extern int vc_reset_hits(struct vx_info *, void __user *);
12300 +extern int vc_reset_minmax(struct vx_info *, void __user *);
12301 +
12302 +extern int vc_rlimit_stat(struct vx_info *, void __user *);
12303 +
12304 +#ifdef CONFIG_IA32_EMULATION
12305 +
12306 +extern int vc_get_rlimit_x32(struct vx_info *, void __user *);
12307 +extern int vc_set_rlimit_x32(struct vx_info *, void __user *);
12308 +
12309 +#endif /* CONFIG_IA32_EMULATION */
12310 +
12311 +#endif /* __KERNEL__ */
12312 +#endif /* _VX_LIMIT_CMD_H */
12313 diff -NurpP --minimal linux-3.6/include/linux/vserver/limit_def.h linux-3.6-vs2.3.4.3-noxfs-nocow/include/linux/vserver/limit_def.h
12314 --- linux-3.6/include/linux/vserver/limit_def.h 1970-01-01 01:00:00.000000000 +0100
12315 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/include/linux/vserver/limit_def.h   2012-10-04 18:47:00.000000000 +0200
12316 @@ -0,0 +1,47 @@
12317 +#ifndef _VX_LIMIT_DEF_H
12318 +#define _VX_LIMIT_DEF_H
12319 +
12320 +#include <asm/atomic.h>
12321 +#include <asm/resource.h>
12322 +
12323 +#include "limit.h"
12324 +
12325 +
12326 +struct _vx_res_limit {
12327 +       rlim_t soft;            /* Context soft limit */
12328 +       rlim_t hard;            /* Context hard limit */
12329 +
12330 +       rlim_atomic_t rcur;     /* Current value */
12331 +       rlim_t rmin;            /* Context minimum */
12332 +       rlim_t rmax;            /* Context maximum */
12333 +
12334 +       atomic_t lhit;          /* Limit hits */
12335 +};
12336 +
12337 +/* context sub struct */
12338 +
12339 +struct _vx_limit {
12340 +       struct _vx_res_limit res[NUM_LIMITS];
12341 +};
12342 +
12343 +#ifdef CONFIG_VSERVER_DEBUG
12344 +
12345 +static inline void __dump_vx_limit(struct _vx_limit *limit)
12346 +{
12347 +       int i;
12348 +
12349 +       printk("\t_vx_limit:");
12350 +       for (i = 0; i < NUM_LIMITS; i++) {
12351 +               printk("\t [%2d] = %8lu %8lu/%8lu, %8ld/%8ld, %8d\n",
12352 +                       i, (unsigned long)__rlim_get(limit, i),
12353 +                       (unsigned long)__rlim_rmin(limit, i),
12354 +                       (unsigned long)__rlim_rmax(limit, i),
12355 +                       (long)__rlim_soft(limit, i),
12356 +                       (long)__rlim_hard(limit, i),
12357 +                       atomic_read(&__rlim_lhit(limit, i)));
12358 +       }
12359 +}
12360 +
12361 +#endif
12362 +
12363 +#endif /* _VX_LIMIT_DEF_H */
12364 diff -NurpP --minimal linux-3.6/include/linux/vserver/limit_int.h linux-3.6-vs2.3.4.3-noxfs-nocow/include/linux/vserver/limit_int.h
12365 --- linux-3.6/include/linux/vserver/limit_int.h 1970-01-01 01:00:00.000000000 +0100
12366 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/include/linux/vserver/limit_int.h   2012-10-04 18:47:00.000000000 +0200
12367 @@ -0,0 +1,198 @@
12368 +#ifndef _VX_LIMIT_INT_H
12369 +#define _VX_LIMIT_INT_H
12370 +
12371 +#include "context.h"
12372 +
12373 +#ifdef __KERNEL__
12374 +
12375 +#define VXD_RCRES_COND(r)      VXD_CBIT(cres, r)
12376 +#define VXD_RLIMIT_COND(r)     VXD_CBIT(limit, r)
12377 +
12378 +extern const char *vlimit_name[NUM_LIMITS];
12379 +
12380 +static inline void __vx_acc_cres(struct vx_info *vxi,
12381 +       int res, int dir, void *_data, char *_file, int _line)
12382 +{
12383 +       if (VXD_RCRES_COND(res))
12384 +               vxlprintk(1, "vx_acc_cres[%5d,%s,%2d]: %5ld%s (%p)",
12385 +                       (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
12386 +                       (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
12387 +                       (dir > 0) ? "++" : "--", _data, _file, _line);
12388 +       if (!vxi)
12389 +               return;
12390 +
12391 +       if (dir > 0)
12392 +               __rlim_inc(&vxi->limit, res);
12393 +       else
12394 +               __rlim_dec(&vxi->limit, res);
12395 +}
12396 +
12397 +static inline void __vx_add_cres(struct vx_info *vxi,
12398 +       int res, int amount, void *_data, char *_file, int _line)
12399 +{
12400 +       if (VXD_RCRES_COND(res))
12401 +               vxlprintk(1, "vx_add_cres[%5d,%s,%2d]: %5ld += %5d (%p)",
12402 +                       (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
12403 +                       (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
12404 +                       amount, _data, _file, _line);
12405 +       if (amount == 0)
12406 +               return;
12407 +       if (!vxi)
12408 +               return;
12409 +       __rlim_add(&vxi->limit, res, amount);
12410 +}
12411 +
12412 +static inline
12413 +int __vx_cres_adjust_max(struct _vx_limit *limit, int res, rlim_t value)
12414 +{
12415 +       int cond = (value > __rlim_rmax(limit, res));
12416 +
12417 +       if (cond)
12418 +               __rlim_rmax(limit, res) = value;
12419 +       return cond;
12420 +}
12421 +
12422 +static inline
12423 +int __vx_cres_adjust_min(struct _vx_limit *limit, int res, rlim_t value)
12424 +{
12425 +       int cond = (value < __rlim_rmin(limit, res));
12426 +
12427 +       if (cond)
12428 +               __rlim_rmin(limit, res) = value;
12429 +       return cond;
12430 +}
12431 +
12432 +static inline
12433 +void __vx_cres_fixup(struct _vx_limit *limit, int res, rlim_t value)
12434 +{
12435 +       if (!__vx_cres_adjust_max(limit, res, value))
12436 +               __vx_cres_adjust_min(limit, res, value);
12437 +}
12438 +
12439 +
12440 +/*     return values:
12441 +        +1 ... no limit hit
12442 +        -1 ... over soft limit
12443 +         0 ... over hard limit         */
12444 +
12445 +static inline int __vx_cres_avail(struct vx_info *vxi,
12446 +       int res, int num, char *_file, int _line)
12447 +{
12448 +       struct _vx_limit *limit;
12449 +       rlim_t value;
12450 +
12451 +       if (VXD_RLIMIT_COND(res))
12452 +               vxlprintk(1, "vx_cres_avail[%5d,%s,%2d]: %5ld/%5ld > %5ld + %5d",
12453 +                       (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
12454 +                       (vxi ? (long)__rlim_soft(&vxi->limit, res) : -1),
12455 +                       (vxi ? (long)__rlim_hard(&vxi->limit, res) : -1),
12456 +                       (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
12457 +                       num, _file, _line);
12458 +       if (!vxi)
12459 +               return 1;
12460 +
12461 +       limit = &vxi->limit;
12462 +       value = __rlim_get(limit, res);
12463 +
12464 +       if (!__vx_cres_adjust_max(limit, res, value))
12465 +               __vx_cres_adjust_min(limit, res, value);
12466 +
12467 +       if (num == 0)
12468 +               return 1;
12469 +
12470 +       if (__rlim_soft(limit, res) == RLIM_INFINITY)
12471 +               return -1;
12472 +       if (value + num <= __rlim_soft(limit, res))
12473 +               return -1;
12474 +
12475 +       if (__rlim_hard(limit, res) == RLIM_INFINITY)
12476 +               return 1;
12477 +       if (value + num <= __rlim_hard(limit, res))
12478 +               return 1;
12479 +
12480 +       __rlim_hit(limit, res);
12481 +       return 0;
12482 +}
12483 +
12484 +
12485 +static const int VLA_RSS[] = { RLIMIT_RSS, VLIMIT_ANON, VLIMIT_MAPPED, 0 };
12486 +
12487 +static inline
12488 +rlim_t __vx_cres_array_sum(struct _vx_limit *limit, const int *array)
12489 +{
12490 +       rlim_t value, sum = 0;
12491 +       int res;
12492 +
12493 +       while ((res = *array++)) {
12494 +               value = __rlim_get(limit, res);
12495 +               __vx_cres_fixup(limit, res, value);
12496 +               sum += value;
12497 +       }
12498 +       return sum;
12499 +}
12500 +
12501 +static inline
12502 +rlim_t __vx_cres_array_fixup(struct _vx_limit *limit, const int *array)
12503 +{
12504 +       rlim_t value = __vx_cres_array_sum(limit, array + 1);
12505 +       int res = *array;
12506 +
12507 +       if (value == __rlim_get(limit, res))
12508 +               return value;
12509 +
12510 +       __rlim_set(limit, res, value);
12511 +       /* now adjust min/max */
12512 +       if (!__vx_cres_adjust_max(limit, res, value))
12513 +               __vx_cres_adjust_min(limit, res, value);
12514 +
12515 +       return value;
12516 +}
12517 +
12518 +static inline int __vx_cres_array_avail(struct vx_info *vxi,
12519 +       const int *array, int num, char *_file, int _line)
12520 +{
12521 +       struct _vx_limit *limit;
12522 +       rlim_t value = 0;
12523 +       int res;
12524 +
12525 +       if (num == 0)
12526 +               return 1;
12527 +       if (!vxi)
12528 +               return 1;
12529 +
12530 +       limit = &vxi->limit;
12531 +       res = *array;
12532 +       value = __vx_cres_array_sum(limit, array + 1);
12533 +
12534 +       __rlim_set(limit, res, value);
12535 +       __vx_cres_fixup(limit, res, value);
12536 +
12537 +       return __vx_cres_avail(vxi, res, num, _file, _line);
12538 +}
12539 +
12540 +
12541 +static inline void vx_limit_fixup(struct _vx_limit *limit, int id)
12542 +{
12543 +       rlim_t value;
12544 +       int res;
12545 +
12546 +       /* complex resources first */
12547 +       if ((id < 0) || (id == RLIMIT_RSS))
12548 +               __vx_cres_array_fixup(limit, VLA_RSS);
12549 +
12550 +       for (res = 0; res < NUM_LIMITS; res++) {
12551 +               if ((id > 0) && (res != id))
12552 +                       continue;
12553 +
12554 +               value = __rlim_get(limit, res);
12555 +               __vx_cres_fixup(limit, res, value);
12556 +
12557 +               /* not supposed to happen, maybe warn? */
12558 +               if (__rlim_rmax(limit, res) > __rlim_hard(limit, res))
12559 +                       __rlim_rmax(limit, res) = __rlim_hard(limit, res);
12560 +       }
12561 +}
12562 +
12563 +
12564 +#endif /* __KERNEL__ */
12565 +#endif /* _VX_LIMIT_INT_H */
12566 diff -NurpP --minimal linux-3.6/include/linux/vserver/monitor.h linux-3.6-vs2.3.4.3-noxfs-nocow/include/linux/vserver/monitor.h
12567 --- linux-3.6/include/linux/vserver/monitor.h   1970-01-01 01:00:00.000000000 +0100
12568 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/include/linux/vserver/monitor.h     2012-10-04 18:47:00.000000000 +0200
12569 @@ -0,0 +1,96 @@
12570 +#ifndef _VX_MONITOR_H
12571 +#define _VX_MONITOR_H
12572 +
12573 +#include <linux/types.h>
12574 +
12575 +enum {
12576 +       VXM_UNUSED = 0,
12577 +
12578 +       VXM_SYNC = 0x10,
12579 +
12580 +       VXM_UPDATE = 0x20,
12581 +       VXM_UPDATE_1,
12582 +       VXM_UPDATE_2,
12583 +
12584 +       VXM_RQINFO_1 = 0x24,
12585 +       VXM_RQINFO_2,
12586 +
12587 +       VXM_ACTIVATE = 0x40,
12588 +       VXM_DEACTIVATE,
12589 +       VXM_IDLE,
12590 +
12591 +       VXM_HOLD = 0x44,
12592 +       VXM_UNHOLD,
12593 +
12594 +       VXM_MIGRATE = 0x48,
12595 +       VXM_RESCHED,
12596 +
12597 +       /* all other bits are flags */
12598 +       VXM_SCHED = 0x80,
12599 +};
12600 +
12601 +struct _vxm_update_1 {
12602 +       uint32_t tokens_max;
12603 +       uint32_t fill_rate;
12604 +       uint32_t interval;
12605 +};
12606 +
12607 +struct _vxm_update_2 {
12608 +       uint32_t tokens_min;
12609 +       uint32_t fill_rate;
12610 +       uint32_t interval;
12611 +};
12612 +
12613 +struct _vxm_rqinfo_1 {
12614 +       uint16_t running;
12615 +       uint16_t onhold;
12616 +       uint16_t iowait;
12617 +       uint16_t uintr;
12618 +       uint32_t idle_tokens;
12619 +};
12620 +
12621 +struct _vxm_rqinfo_2 {
12622 +       uint32_t norm_time;
12623 +       uint32_t idle_time;
12624 +       uint32_t idle_skip;
12625 +};
12626 +
12627 +struct _vxm_sched {
12628 +       uint32_t tokens;
12629 +       uint32_t norm_time;
12630 +       uint32_t idle_time;
12631 +};
12632 +
12633 +struct _vxm_task {
12634 +       uint16_t pid;
12635 +       uint16_t state;
12636 +};
12637 +
12638 +struct _vxm_event {
12639 +       uint32_t jif;
12640 +       union {
12641 +               uint32_t seq;
12642 +               uint32_t sec;
12643 +       };
12644 +       union {
12645 +               uint32_t tokens;
12646 +               uint32_t nsec;
12647 +               struct _vxm_task tsk;
12648 +       };
12649 +};
12650 +
12651 +struct _vx_mon_entry {
12652 +       uint16_t type;
12653 +       uint16_t xid;
12654 +       union {
12655 +               struct _vxm_event ev;
12656 +               struct _vxm_sched sd;
12657 +               struct _vxm_update_1 u1;
12658 +               struct _vxm_update_2 u2;
12659 +               struct _vxm_rqinfo_1 q1;
12660 +               struct _vxm_rqinfo_2 q2;
12661 +       };
12662 +};
12663 +
12664 +
12665 +#endif /* _VX_MONITOR_H */
12666 diff -NurpP --minimal linux-3.6/include/linux/vserver/network.h linux-3.6-vs2.3.4.3-noxfs-nocow/include/linux/vserver/network.h
12667 --- linux-3.6/include/linux/vserver/network.h   1970-01-01 01:00:00.000000000 +0100
12668 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/include/linux/vserver/network.h     2012-10-04 18:47:00.000000000 +0200
12669 @@ -0,0 +1,148 @@
12670 +#ifndef _VX_NETWORK_H
12671 +#define _VX_NETWORK_H
12672 +
12673 +#include <linux/types.h>
12674 +
12675 +
12676 +#define MAX_N_CONTEXT  65535   /* Arbitrary limit */
12677 +
12678 +
12679 +/* network flags */
12680 +
12681 +#define NXF_INFO_PRIVATE       0x00000008
12682 +
12683 +#define NXF_SINGLE_IP          0x00000100
12684 +#define NXF_LBACK_REMAP                0x00000200
12685 +#define NXF_LBACK_ALLOW                0x00000400
12686 +
12687 +#define NXF_HIDE_NETIF         0x02000000
12688 +#define NXF_HIDE_LBACK         0x04000000
12689 +
12690 +#define NXF_STATE_SETUP                (1ULL << 32)
12691 +#define NXF_STATE_ADMIN                (1ULL << 34)
12692 +
12693 +#define NXF_SC_HELPER          (1ULL << 36)
12694 +#define NXF_PERSISTENT         (1ULL << 38)
12695 +
12696 +#define NXF_ONE_TIME           (0x0005ULL << 32)
12697 +
12698 +
12699 +#define        NXF_INIT_SET            (__nxf_init_set())
12700 +
12701 +static inline uint64_t __nxf_init_set(void) {
12702 +       return    NXF_STATE_ADMIN
12703 +#ifdef CONFIG_VSERVER_AUTO_LBACK
12704 +               | NXF_LBACK_REMAP
12705 +               | NXF_HIDE_LBACK
12706 +#endif
12707 +#ifdef CONFIG_VSERVER_AUTO_SINGLE
12708 +               | NXF_SINGLE_IP
12709 +#endif
12710 +               | NXF_HIDE_NETIF;
12711 +}
12712 +
12713 +
12714 +/* network caps */
12715 +
12716 +#define NXC_TUN_CREATE         0x00000001
12717 +
12718 +#define NXC_RAW_ICMP           0x00000100
12719 +
12720 +#define NXC_MULTICAST          0x00001000
12721 +
12722 +
12723 +/* address types */
12724 +
12725 +#define NXA_TYPE_IPV4          0x0001
12726 +#define NXA_TYPE_IPV6          0x0002
12727 +
12728 +#define NXA_TYPE_NONE          0x0000
12729 +#define NXA_TYPE_ANY           0x00FF
12730 +
12731 +#define NXA_TYPE_ADDR          0x0010
12732 +#define NXA_TYPE_MASK          0x0020
12733 +#define NXA_TYPE_RANGE         0x0040
12734 +
12735 +#define NXA_MASK_ALL           (NXA_TYPE_ADDR | NXA_TYPE_MASK | NXA_TYPE_RANGE)
12736 +
12737 +#define NXA_MOD_BCAST          0x0100
12738 +#define NXA_MOD_LBACK          0x0200
12739 +
12740 +#define NXA_LOOPBACK           0x1000
12741 +
12742 +#define NXA_MASK_BIND          (NXA_MASK_ALL | NXA_MOD_BCAST | NXA_MOD_LBACK)
12743 +#define NXA_MASK_SHOW          (NXA_MASK_ALL | NXA_LOOPBACK)
12744 +
12745 +#ifdef __KERNEL__
12746 +
12747 +#include <linux/list.h>
12748 +#include <linux/spinlock.h>
12749 +#include <linux/rcupdate.h>
12750 +#include <linux/in.h>
12751 +#include <linux/in6.h>
12752 +#include <asm/atomic.h>
12753 +
12754 +struct nx_addr_v4 {
12755 +       struct nx_addr_v4 *next;
12756 +       struct in_addr ip[2];
12757 +       struct in_addr mask;
12758 +       uint16_t type;
12759 +       uint16_t flags;
12760 +};
12761 +
12762 +struct nx_addr_v6 {
12763 +       struct nx_addr_v6 *next;
12764 +       struct in6_addr ip;
12765 +       struct in6_addr mask;
12766 +       uint32_t prefix;
12767 +       uint16_t type;
12768 +       uint16_t flags;
12769 +};
12770 +
12771 +struct nx_info {
12772 +       struct hlist_node nx_hlist;     /* linked list of nxinfos */
12773 +       nid_t nx_id;                    /* vnet id */
12774 +       atomic_t nx_usecnt;             /* usage count */
12775 +       atomic_t nx_tasks;              /* tasks count */
12776 +       int nx_state;                   /* context state */
12777 +
12778 +       uint64_t nx_flags;              /* network flag word */
12779 +       uint64_t nx_ncaps;              /* network capabilities */
12780 +
12781 +       struct in_addr v4_lback;        /* Loopback address */
12782 +       struct in_addr v4_bcast;        /* Broadcast address */
12783 +       struct nx_addr_v4 v4;           /* First/Single ipv4 address */
12784 +#ifdef CONFIG_IPV6
12785 +       struct nx_addr_v6 v6;           /* First/Single ipv6 address */
12786 +#endif
12787 +       char nx_name[65];               /* network context name */
12788 +};
12789 +
12790 +
12791 +/* status flags */
12792 +
12793 +#define NXS_HASHED      0x0001
12794 +#define NXS_SHUTDOWN    0x0100
12795 +#define NXS_RELEASED    0x8000
12796 +
12797 +extern struct nx_info *lookup_nx_info(int);
12798 +
12799 +extern int get_nid_list(int, unsigned int *, int);
12800 +extern int nid_is_hashed(nid_t);
12801 +
12802 +extern int nx_migrate_task(struct task_struct *, struct nx_info *);
12803 +
12804 +extern long vs_net_change(struct nx_info *, unsigned int);
12805 +
12806 +struct sock;
12807 +
12808 +
12809 +#define NX_IPV4(n)     ((n)->v4.type != NXA_TYPE_NONE)
12810 +#ifdef  CONFIG_IPV6
12811 +#define NX_IPV6(n)     ((n)->v6.type != NXA_TYPE_NONE)
12812 +#else
12813 +#define NX_IPV6(n)     (0)
12814 +#endif
12815 +
12816 +#endif /* __KERNEL__ */
12817 +#endif /* _VX_NETWORK_H */
12818 diff -NurpP --minimal linux-3.6/include/linux/vserver/network_cmd.h linux-3.6-vs2.3.4.3-noxfs-nocow/include/linux/vserver/network_cmd.h
12819 --- linux-3.6/include/linux/vserver/network_cmd.h       1970-01-01 01:00:00.000000000 +0100
12820 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/include/linux/vserver/network_cmd.h 2012-10-04 18:47:00.000000000 +0200
12821 @@ -0,0 +1,164 @@
12822 +#ifndef _VX_NETWORK_CMD_H
12823 +#define _VX_NETWORK_CMD_H
12824 +
12825 +
12826 +/* vinfo commands */
12827 +
12828 +#define VCMD_task_nid          VC_CMD(VINFO, 2, 0)
12829 +
12830 +#ifdef __KERNEL__
12831 +extern int vc_task_nid(uint32_t);
12832 +
12833 +#endif /* __KERNEL__ */
12834 +
12835 +#define VCMD_nx_info           VC_CMD(VINFO, 6, 0)
12836 +
12837 +struct vcmd_nx_info_v0 {
12838 +       uint32_t nid;
12839 +       /* more to come */
12840 +};
12841 +
12842 +#ifdef __KERNEL__
12843 +extern int vc_nx_info(struct nx_info *, void __user *);
12844 +
12845 +#endif /* __KERNEL__ */
12846 +
12847 +#include <linux/in.h>
12848 +#include <linux/in6.h>
12849 +
12850 +#define VCMD_net_create_v0     VC_CMD(VNET, 1, 0)
12851 +#define VCMD_net_create                VC_CMD(VNET, 1, 1)
12852 +
12853 +struct  vcmd_net_create {
12854 +       uint64_t flagword;
12855 +};
12856 +
12857 +#define VCMD_net_migrate       VC_CMD(NETMIG, 1, 0)
12858 +
12859 +#define VCMD_net_add           VC_CMD(NETALT, 1, 0)
12860 +#define VCMD_net_remove                VC_CMD(NETALT, 2, 0)
12861 +
12862 +struct vcmd_net_addr_v0 {
12863 +       uint16_t type;
12864 +       uint16_t count;
12865 +       struct in_addr ip[4];
12866 +       struct in_addr mask[4];
12867 +};
12868 +
12869 +#define VCMD_net_add_ipv4_v1   VC_CMD(NETALT, 1, 1)
12870 +#define VCMD_net_rem_ipv4_v1   VC_CMD(NETALT, 2, 1)
12871 +
12872 +struct vcmd_net_addr_ipv4_v1 {
12873 +       uint16_t type;
12874 +       uint16_t flags;
12875 +       struct in_addr ip;
12876 +       struct in_addr mask;
12877 +};
12878 +
12879 +#define VCMD_net_add_ipv4      VC_CMD(NETALT, 1, 2)
12880 +#define VCMD_net_rem_ipv4      VC_CMD(NETALT, 2, 2)
12881 +
12882 +struct vcmd_net_addr_ipv4_v2 {
12883 +       uint16_t type;
12884 +       uint16_t flags;
12885 +       struct in_addr ip;
12886 +       struct in_addr ip2;
12887 +       struct in_addr mask;
12888 +};
12889 +
12890 +#define VCMD_net_add_ipv6      VC_CMD(NETALT, 3, 1)
12891 +#define VCMD_net_remove_ipv6   VC_CMD(NETALT, 4, 1)
12892 +
12893 +struct vcmd_net_addr_ipv6_v1 {
12894 +       uint16_t type;
12895 +       uint16_t flags;
12896 +       uint32_t prefix;
12897 +       struct in6_addr ip;
12898 +       struct in6_addr mask;
12899 +};
12900 +
12901 +#define VCMD_add_match_ipv4    VC_CMD(NETALT, 5, 0)
12902 +#define VCMD_get_match_ipv4    VC_CMD(NETALT, 6, 0)
12903 +
12904 +struct vcmd_match_ipv4_v0 {
12905 +       uint16_t type;
12906 +       uint16_t flags;
12907 +       uint16_t parent;
12908 +       uint16_t prefix;
12909 +       struct in_addr ip;
12910 +       struct in_addr ip2;
12911 +       struct in_addr mask;
12912 +};
12913 +
12914 +#define VCMD_add_match_ipv6    VC_CMD(NETALT, 7, 0)
12915 +#define VCMD_get_match_ipv6    VC_CMD(NETALT, 8, 0)
12916 +
12917 +struct vcmd_match_ipv6_v0 {
12918 +       uint16_t type;
12919 +       uint16_t flags;
12920 +       uint16_t parent;
12921 +       uint16_t prefix;
12922 +       struct in6_addr ip;
12923 +       struct in6_addr ip2;
12924 +       struct in6_addr mask;
12925 +};
12926 +
12927 +
12928 +#ifdef __KERNEL__
12929 +extern int vc_net_create(uint32_t, void __user *);
12930 +extern int vc_net_migrate(struct nx_info *, void __user *);
12931 +
12932 +extern int vc_net_add(struct nx_info *, void __user *);
12933 +extern int vc_net_remove(struct nx_info *, void __user *);
12934 +
12935 +extern int vc_net_add_ipv4_v1(struct nx_info *, void __user *);
12936 +extern int vc_net_add_ipv4(struct nx_info *, void __user *);
12937 +
12938 +extern int vc_net_rem_ipv4_v1(struct nx_info *, void __user *);
12939 +extern int vc_net_rem_ipv4(struct nx_info *, void __user *);
12940 +
12941 +extern int vc_net_add_ipv6(struct nx_info *, void __user *);
12942 +extern int vc_net_remove_ipv6(struct nx_info *, void __user *);
12943 +
12944 +extern int vc_add_match_ipv4(struct nx_info *, void __user *);
12945 +extern int vc_get_match_ipv4(struct nx_info *, void __user *);
12946 +
12947 +extern int vc_add_match_ipv6(struct nx_info *, void __user *);
12948 +extern int vc_get_match_ipv6(struct nx_info *, void __user *);
12949 +
12950 +#endif /* __KERNEL__ */
12951 +
12952 +
12953 +/* flag commands */
12954 +
12955 +#define VCMD_get_nflags                VC_CMD(FLAGS, 5, 0)
12956 +#define VCMD_set_nflags                VC_CMD(FLAGS, 6, 0)
12957 +
12958 +struct vcmd_net_flags_v0 {
12959 +       uint64_t flagword;
12960 +       uint64_t mask;
12961 +};
12962 +
12963 +#ifdef __KERNEL__
12964 +extern int vc_get_nflags(struct nx_info *, void __user *);
12965 +extern int vc_set_nflags(struct nx_info *, void __user *);
12966 +
12967 +#endif /* __KERNEL__ */
12968 +
12969 +
12970 +/* network caps commands */
12971 +
12972 +#define VCMD_get_ncaps         VC_CMD(FLAGS, 7, 0)
12973 +#define VCMD_set_ncaps         VC_CMD(FLAGS, 8, 0)
12974 +
12975 +struct vcmd_net_caps_v0 {
12976 +       uint64_t ncaps;
12977 +       uint64_t cmask;
12978 +};
12979 +
12980 +#ifdef __KERNEL__
12981 +extern int vc_get_ncaps(struct nx_info *, void __user *);
12982 +extern int vc_set_ncaps(struct nx_info *, void __user *);
12983 +
12984 +#endif /* __KERNEL__ */
12985 +#endif /* _VX_CONTEXT_CMD_H */
12986 diff -NurpP --minimal linux-3.6/include/linux/vserver/percpu.h linux-3.6-vs2.3.4.3-noxfs-nocow/include/linux/vserver/percpu.h
12987 --- linux-3.6/include/linux/vserver/percpu.h    1970-01-01 01:00:00.000000000 +0100
12988 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/include/linux/vserver/percpu.h      2012-10-04 18:47:00.000000000 +0200
12989 @@ -0,0 +1,14 @@
12990 +#ifndef _VX_PERCPU_H
12991 +#define _VX_PERCPU_H
12992 +
12993 +#include "cvirt_def.h"
12994 +#include "sched_def.h"
12995 +
12996 +struct _vx_percpu {
12997 +       struct _vx_cvirt_pc cvirt;
12998 +       struct _vx_sched_pc sched;
12999 +};
13000 +
13001 +#define        PERCPU_PERCTX   (sizeof(struct _vx_percpu))
13002 +
13003 +#endif /* _VX_PERCPU_H */
13004 diff -NurpP --minimal linux-3.6/include/linux/vserver/pid.h linux-3.6-vs2.3.4.3-noxfs-nocow/include/linux/vserver/pid.h
13005 --- linux-3.6/include/linux/vserver/pid.h       1970-01-01 01:00:00.000000000 +0100
13006 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/include/linux/vserver/pid.h 2012-10-04 18:47:00.000000000 +0200
13007 @@ -0,0 +1,51 @@
13008 +#ifndef _VSERVER_PID_H
13009 +#define _VSERVER_PID_H
13010 +
13011 +/* pid faking stuff */
13012 +
13013 +#define vx_info_map_pid(v, p) \
13014 +       __vx_info_map_pid((v), (p), __func__, __FILE__, __LINE__)
13015 +#define vx_info_map_tgid(v,p)  vx_info_map_pid(v,p)
13016 +#define vx_map_pid(p) vx_info_map_pid(current_vx_info(), p)
13017 +#define vx_map_tgid(p) vx_map_pid(p)
13018 +
13019 +static inline int __vx_info_map_pid(struct vx_info *vxi, int pid,
13020 +       const char *func, const char *file, int line)
13021 +{
13022 +       if (vx_info_flags(vxi, VXF_INFO_INIT, 0)) {
13023 +               vxfprintk(VXD_CBIT(cvirt, 2),
13024 +                       "vx_map_tgid: %p/%llx: %d -> %d",
13025 +                       vxi, (long long)vxi->vx_flags, pid,
13026 +                       (pid && pid == vxi->vx_initpid) ? 1 : pid,
13027 +                       func, file, line);
13028 +               if (pid == 0)
13029 +                       return 0;
13030 +               if (pid == vxi->vx_initpid)
13031 +                       return 1;
13032 +       }
13033 +       return pid;
13034 +}
13035 +
13036 +#define vx_info_rmap_pid(v, p) \
13037 +       __vx_info_rmap_pid((v), (p), __func__, __FILE__, __LINE__)
13038 +#define vx_rmap_pid(p) vx_info_rmap_pid(current_vx_info(), p)
13039 +#define vx_rmap_tgid(p) vx_rmap_pid(p)
13040 +
13041 +static inline int __vx_info_rmap_pid(struct vx_info *vxi, int pid,
13042 +       const char *func, const char *file, int line)
13043 +{
13044 +       if (vx_info_flags(vxi, VXF_INFO_INIT, 0)) {
13045 +               vxfprintk(VXD_CBIT(cvirt, 2),
13046 +                       "vx_rmap_tgid: %p/%llx: %d -> %d",
13047 +                       vxi, (long long)vxi->vx_flags, pid,
13048 +                       (pid == 1) ? vxi->vx_initpid : pid,
13049 +                       func, file, line);
13050 +               if ((pid == 1) && vxi->vx_initpid)
13051 +                       return vxi->vx_initpid;
13052 +               if (pid == vxi->vx_initpid)
13053 +                       return ~0U;
13054 +       }
13055 +       return pid;
13056 +}
13057 +
13058 +#endif
13059 diff -NurpP --minimal linux-3.6/include/linux/vserver/sched.h linux-3.6-vs2.3.4.3-noxfs-nocow/include/linux/vserver/sched.h
13060 --- linux-3.6/include/linux/vserver/sched.h     1970-01-01 01:00:00.000000000 +0100
13061 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/include/linux/vserver/sched.h       2012-10-04 18:47:00.000000000 +0200
13062 @@ -0,0 +1,23 @@
13063 +#ifndef _VX_SCHED_H
13064 +#define _VX_SCHED_H
13065 +
13066 +
13067 +#ifdef __KERNEL__
13068 +
13069 +struct timespec;
13070 +
13071 +void vx_vsi_uptime(struct timespec *, struct timespec *);
13072 +
13073 +
13074 +struct vx_info;
13075 +
13076 +void vx_update_load(struct vx_info *);
13077 +
13078 +
13079 +void vx_update_sched_param(struct _vx_sched *sched,
13080 +       struct _vx_sched_pc *sched_pc);
13081 +
13082 +#endif /* __KERNEL__ */
13083 +#else  /* _VX_SCHED_H */
13084 +#warning duplicate inclusion
13085 +#endif /* _VX_SCHED_H */
13086 diff -NurpP --minimal linux-3.6/include/linux/vserver/sched_cmd.h linux-3.6-vs2.3.4.3-noxfs-nocow/include/linux/vserver/sched_cmd.h
13087 --- linux-3.6/include/linux/vserver/sched_cmd.h 1970-01-01 01:00:00.000000000 +0100
13088 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/include/linux/vserver/sched_cmd.h   2012-10-04 18:47:00.000000000 +0200
13089 @@ -0,0 +1,21 @@
13090 +#ifndef _VX_SCHED_CMD_H
13091 +#define _VX_SCHED_CMD_H
13092 +
13093 +
13094 +struct vcmd_prio_bias {
13095 +       int32_t cpu_id;
13096 +       int32_t prio_bias;
13097 +};
13098 +
13099 +#define VCMD_set_prio_bias     VC_CMD(SCHED, 4, 0)
13100 +#define VCMD_get_prio_bias     VC_CMD(SCHED, 5, 0)
13101 +
13102 +#ifdef __KERNEL__
13103 +
13104 +#include <linux/compiler.h>
13105 +
13106 +extern int vc_set_prio_bias(struct vx_info *, void __user *);
13107 +extern int vc_get_prio_bias(struct vx_info *, void __user *);
13108 +
13109 +#endif /* __KERNEL__ */
13110 +#endif /* _VX_SCHED_CMD_H */
13111 diff -NurpP --minimal linux-3.6/include/linux/vserver/sched_def.h linux-3.6-vs2.3.4.3-noxfs-nocow/include/linux/vserver/sched_def.h
13112 --- linux-3.6/include/linux/vserver/sched_def.h 1970-01-01 01:00:00.000000000 +0100
13113 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/include/linux/vserver/sched_def.h   2012-10-04 18:47:00.000000000 +0200
13114 @@ -0,0 +1,38 @@
13115 +#ifndef _VX_SCHED_DEF_H
13116 +#define _VX_SCHED_DEF_H
13117 +
13118 +#include <linux/spinlock.h>
13119 +#include <linux/jiffies.h>
13120 +#include <linux/cpumask.h>
13121 +#include <asm/atomic.h>
13122 +#include <asm/param.h>
13123 +
13124 +
13125 +/* context sub struct */
13126 +
13127 +struct _vx_sched {
13128 +       int prio_bias;                  /* bias offset for priority */
13129 +
13130 +       cpumask_t update;               /* CPUs which should update */
13131 +};
13132 +
13133 +struct _vx_sched_pc {
13134 +       int prio_bias;                  /* bias offset for priority */
13135 +
13136 +       uint64_t user_ticks;            /* token tick events */
13137 +       uint64_t sys_ticks;             /* token tick events */
13138 +       uint64_t hold_ticks;            /* token ticks paused */
13139 +};
13140 +
13141 +
13142 +#ifdef CONFIG_VSERVER_DEBUG
13143 +
13144 +static inline void __dump_vx_sched(struct _vx_sched *sched)
13145 +{
13146 +       printk("\t_vx_sched:\n");
13147 +       printk("\t priority = %4d\n", sched->prio_bias);
13148 +}
13149 +
13150 +#endif
13151 +
13152 +#endif /* _VX_SCHED_DEF_H */
13153 diff -NurpP --minimal linux-3.6/include/linux/vserver/signal.h linux-3.6-vs2.3.4.3-noxfs-nocow/include/linux/vserver/signal.h
13154 --- linux-3.6/include/linux/vserver/signal.h    1970-01-01 01:00:00.000000000 +0100
13155 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/include/linux/vserver/signal.h      2012-10-04 18:47:00.000000000 +0200
13156 @@ -0,0 +1,14 @@
13157 +#ifndef _VX_SIGNAL_H
13158 +#define _VX_SIGNAL_H
13159 +
13160 +
13161 +#ifdef __KERNEL__
13162 +
13163 +struct vx_info;
13164 +
13165 +int vx_info_kill(struct vx_info *, int, int);
13166 +
13167 +#endif /* __KERNEL__ */
13168 +#else  /* _VX_SIGNAL_H */
13169 +#warning duplicate inclusion
13170 +#endif /* _VX_SIGNAL_H */
13171 diff -NurpP --minimal linux-3.6/include/linux/vserver/signal_cmd.h linux-3.6-vs2.3.4.3-noxfs-nocow/include/linux/vserver/signal_cmd.h
13172 --- linux-3.6/include/linux/vserver/signal_cmd.h        1970-01-01 01:00:00.000000000 +0100
13173 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/include/linux/vserver/signal_cmd.h  2012-10-04 18:47:00.000000000 +0200
13174 @@ -0,0 +1,43 @@
13175 +#ifndef _VX_SIGNAL_CMD_H
13176 +#define _VX_SIGNAL_CMD_H
13177 +
13178 +
13179 +/*  signalling vserver commands */
13180 +
13181 +#define VCMD_ctx_kill          VC_CMD(PROCTRL, 1, 0)
13182 +#define VCMD_wait_exit         VC_CMD(EVENT, 99, 0)
13183 +
13184 +struct vcmd_ctx_kill_v0 {
13185 +       int32_t pid;
13186 +       int32_t sig;
13187 +};
13188 +
13189 +struct vcmd_wait_exit_v0 {
13190 +       int32_t reboot_cmd;
13191 +       int32_t exit_code;
13192 +};
13193 +
13194 +#ifdef __KERNEL__
13195 +
13196 +extern int vc_ctx_kill(struct vx_info *, void __user *);
13197 +extern int vc_wait_exit(struct vx_info *, void __user *);
13198 +
13199 +#endif /* __KERNEL__ */
13200 +
13201 +/*  process alteration commands */
13202 +
13203 +#define VCMD_get_pflags                VC_CMD(PROCALT, 5, 0)
13204 +#define VCMD_set_pflags                VC_CMD(PROCALT, 6, 0)
13205 +
13206 +struct vcmd_pflags_v0 {
13207 +       uint32_t flagword;
13208 +       uint32_t mask;
13209 +};
13210 +
13211 +#ifdef __KERNEL__
13212 +
13213 +extern int vc_get_pflags(uint32_t pid, void __user *);
13214 +extern int vc_set_pflags(uint32_t pid, void __user *);
13215 +
13216 +#endif /* __KERNEL__ */
13217 +#endif /* _VX_SIGNAL_CMD_H */
13218 diff -NurpP --minimal linux-3.6/include/linux/vserver/space.h linux-3.6-vs2.3.4.3-noxfs-nocow/include/linux/vserver/space.h
13219 --- linux-3.6/include/linux/vserver/space.h     1970-01-01 01:00:00.000000000 +0100
13220 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/include/linux/vserver/space.h       2012-10-04 18:47:00.000000000 +0200
13221 @@ -0,0 +1,12 @@
13222 +#ifndef _VX_SPACE_H
13223 +#define _VX_SPACE_H
13224 +
13225 +#include <linux/types.h>
13226 +
13227 +struct vx_info;
13228 +
13229 +int vx_set_space(struct vx_info *vxi, unsigned long mask, unsigned index);
13230 +
13231 +#else  /* _VX_SPACE_H */
13232 +#warning duplicate inclusion
13233 +#endif /* _VX_SPACE_H */
13234 diff -NurpP --minimal linux-3.6/include/linux/vserver/space_cmd.h linux-3.6-vs2.3.4.3-noxfs-nocow/include/linux/vserver/space_cmd.h
13235 --- linux-3.6/include/linux/vserver/space_cmd.h 1970-01-01 01:00:00.000000000 +0100
13236 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/include/linux/vserver/space_cmd.h   2012-10-04 18:47:00.000000000 +0200
13237 @@ -0,0 +1,38 @@
13238 +#ifndef _VX_SPACE_CMD_H
13239 +#define _VX_SPACE_CMD_H
13240 +
13241 +
13242 +#define VCMD_enter_space_v0    VC_CMD(PROCALT, 1, 0)
13243 +#define VCMD_enter_space_v1    VC_CMD(PROCALT, 1, 1)
13244 +#define VCMD_enter_space       VC_CMD(PROCALT, 1, 2)
13245 +
13246 +#define VCMD_set_space_v0      VC_CMD(PROCALT, 3, 0)
13247 +#define VCMD_set_space_v1      VC_CMD(PROCALT, 3, 1)
13248 +#define VCMD_set_space         VC_CMD(PROCALT, 3, 2)
13249 +
13250 +#define VCMD_get_space_mask_v0 VC_CMD(PROCALT, 4, 0)
13251 +
13252 +#define VCMD_get_space_mask    VC_CMD(VSPACE, 0, 1)
13253 +#define VCMD_get_space_default VC_CMD(VSPACE, 1, 0)
13254 +
13255 +
13256 +struct vcmd_space_mask_v1 {
13257 +       uint64_t mask;
13258 +};
13259 +
13260 +struct vcmd_space_mask_v2 {
13261 +       uint64_t mask;
13262 +       uint32_t index;
13263 +};
13264 +
13265 +
13266 +#ifdef __KERNEL__
13267 +
13268 +extern int vc_enter_space_v1(struct vx_info *, void __user *);
13269 +extern int vc_set_space_v1(struct vx_info *, void __user *);
13270 +extern int vc_enter_space(struct vx_info *, void __user *);
13271 +extern int vc_set_space(struct vx_info *, void __user *);
13272 +extern int vc_get_space_mask(void __user *, int);
13273 +
13274 +#endif /* __KERNEL__ */
13275 +#endif /* _VX_SPACE_CMD_H */
13276 diff -NurpP --minimal linux-3.6/include/linux/vserver/switch.h linux-3.6-vs2.3.4.3-noxfs-nocow/include/linux/vserver/switch.h
13277 --- linux-3.6/include/linux/vserver/switch.h    1970-01-01 01:00:00.000000000 +0100
13278 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/include/linux/vserver/switch.h      2012-10-04 18:47:00.000000000 +0200
13279 @@ -0,0 +1,98 @@
13280 +#ifndef _VX_SWITCH_H
13281 +#define _VX_SWITCH_H
13282 +
13283 +#include <linux/types.h>
13284 +
13285 +
13286 +#define VC_CATEGORY(c)         (((c) >> 24) & 0x3F)
13287 +#define VC_COMMAND(c)          (((c) >> 16) & 0xFF)
13288 +#define VC_VERSION(c)          ((c) & 0xFFF)
13289 +
13290 +#define VC_CMD(c, i, v)                ((((VC_CAT_ ## c) & 0x3F) << 24) \
13291 +                               | (((i) & 0xFF) << 16) | ((v) & 0xFFF))
13292 +
13293 +/*
13294 +
13295 +  Syscall Matrix V2.8
13296 +
13297 +        |VERSION|CREATE |MODIFY |MIGRATE|CONTROL|EXPERIM| |SPECIAL|SPECIAL|
13298 +        |STATS  |DESTROY|ALTER  |CHANGE |LIMIT  |TEST   | |       |       |
13299 +        |INFO   |SETUP  |       |MOVE   |       |       | |       |       |
13300 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13301 +  SYSTEM |VERSION|VSETUP |VHOST  |       |       |       | |DEVICE |       |
13302 +  HOST   |     00|     01|     02|     03|     04|     05| |     06|     07|
13303 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13304 +  CPU    |       |VPROC  |PROCALT|PROCMIG|PROCTRL|       | |SCHED. |       |
13305 +  PROCESS|     08|     09|     10|     11|     12|     13| |     14|     15|
13306 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13307 +  MEMORY |       |       |       |       |MEMCTRL|       | |SWAP   |       |
13308 +        |     16|     17|     18|     19|     20|     21| |     22|     23|
13309 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13310 +  NETWORK|       |VNET   |NETALT |NETMIG |NETCTL |       | |SERIAL |       |
13311 +        |     24|     25|     26|     27|     28|     29| |     30|     31|
13312 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13313 +  DISK   |       |       |       |TAGMIG |DLIMIT |       | |INODE  |       |
13314 +  VFS    |     32|     33|     34|     35|     36|     37| |     38|     39|
13315 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13316 +  OTHER  |VSTAT  |       |       |       |       |       | |VINFO  |       |
13317 +        |     40|     41|     42|     43|     44|     45| |     46|     47|
13318 +  =======+=======+=======+=======+=======+=======+=======+ +=======+=======+
13319 +  SPECIAL|EVENT  |       |       |       |FLAGS  |       | |VSPACE |       |
13320 +        |     48|     49|     50|     51|     52|     53| |     54|     55|
13321 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13322 +  SPECIAL|DEBUG  |       |       |       |RLIMIT |SYSCALL| |       |COMPAT |
13323 +        |     56|     57|     58|     59|     60|TEST 61| |     62|     63|
13324 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13325 +
13326 +*/
13327 +
13328 +#define VC_CAT_VERSION         0
13329 +
13330 +#define VC_CAT_VSETUP          1
13331 +#define VC_CAT_VHOST           2
13332 +
13333 +#define VC_CAT_DEVICE          6
13334 +
13335 +#define VC_CAT_VPROC           9
13336 +#define VC_CAT_PROCALT         10
13337 +#define VC_CAT_PROCMIG         11
13338 +#define VC_CAT_PROCTRL         12
13339 +
13340 +#define VC_CAT_SCHED           14
13341 +#define VC_CAT_MEMCTRL         20
13342 +
13343 +#define VC_CAT_VNET            25
13344 +#define VC_CAT_NETALT          26
13345 +#define VC_CAT_NETMIG          27
13346 +#define VC_CAT_NETCTRL         28
13347 +
13348 +#define VC_CAT_TAGMIG          35
13349 +#define VC_CAT_DLIMIT          36
13350 +#define VC_CAT_INODE           38
13351 +
13352 +#define VC_CAT_VSTAT           40
13353 +#define VC_CAT_VINFO           46
13354 +#define VC_CAT_EVENT           48
13355 +
13356 +#define VC_CAT_FLAGS           52
13357 +#define VC_CAT_VSPACE          54
13358 +#define VC_CAT_DEBUG           56
13359 +#define VC_CAT_RLIMIT          60
13360 +
13361 +#define VC_CAT_SYSTEST         61
13362 +#define VC_CAT_COMPAT          63
13363 +
13364 +/*  query version */
13365 +
13366 +#define VCMD_get_version       VC_CMD(VERSION, 0, 0)
13367 +#define VCMD_get_vci           VC_CMD(VERSION, 1, 0)
13368 +
13369 +
13370 +#ifdef __KERNEL__
13371 +
13372 +#include <linux/errno.h>
13373 +
13374 +#endif /* __KERNEL__ */
13375 +
13376 +#endif /* _VX_SWITCH_H */
13377 +
13378 diff -NurpP --minimal linux-3.6/include/linux/vserver/tag.h linux-3.6-vs2.3.4.3-noxfs-nocow/include/linux/vserver/tag.h
13379 --- linux-3.6/include/linux/vserver/tag.h       1970-01-01 01:00:00.000000000 +0100
13380 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/include/linux/vserver/tag.h 2012-10-04 18:47:00.000000000 +0200
13381 @@ -0,0 +1,143 @@
13382 +#ifndef _DX_TAG_H
13383 +#define _DX_TAG_H
13384 +
13385 +#include <linux/types.h>
13386 +
13387 +
13388 +#define DX_TAG(in)     (IS_TAGGED(in))
13389 +
13390 +
13391 +#ifdef CONFIG_TAG_NFSD
13392 +#define DX_TAG_NFSD    1
13393 +#else
13394 +#define DX_TAG_NFSD    0
13395 +#endif
13396 +
13397 +
13398 +#ifdef CONFIG_TAGGING_NONE
13399 +
13400 +#define MAX_UID                0xFFFFFFFF
13401 +#define MAX_GID                0xFFFFFFFF
13402 +
13403 +#define INOTAG_TAG(cond, uid, gid, tag)        (0)
13404 +
13405 +#define TAGINO_UID(cond, uid, tag)     (uid)
13406 +#define TAGINO_GID(cond, gid, tag)     (gid)
13407 +
13408 +#endif
13409 +
13410 +
13411 +#ifdef CONFIG_TAGGING_GID16
13412 +
13413 +#define MAX_UID                0xFFFFFFFF
13414 +#define MAX_GID                0x0000FFFF
13415 +
13416 +#define INOTAG_TAG(cond, uid, gid, tag)        \
13417 +       ((cond) ? (((gid) >> 16) & 0xFFFF) : 0)
13418 +
13419 +#define TAGINO_UID(cond, uid, tag)     (uid)
13420 +#define TAGINO_GID(cond, gid, tag)     \
13421 +       ((cond) ? (((gid) & 0xFFFF) | ((tag) << 16)) : (gid))
13422 +
13423 +#endif
13424 +
13425 +
13426 +#ifdef CONFIG_TAGGING_ID24
13427 +
13428 +#define MAX_UID                0x00FFFFFF
13429 +#define MAX_GID                0x00FFFFFF
13430 +
13431 +#define INOTAG_TAG(cond, uid, gid, tag)        \
13432 +       ((cond) ? ((((uid) >> 16) & 0xFF00) | (((gid) >> 24) & 0xFF)) : 0)
13433 +
13434 +#define TAGINO_UID(cond, uid, tag)     \
13435 +       ((cond) ? (((uid) & 0xFFFFFF) | (((tag) & 0xFF00) << 16)) : (uid))
13436 +#define TAGINO_GID(cond, gid, tag)     \
13437 +       ((cond) ? (((gid) & 0xFFFFFF) | (((tag) & 0x00FF) << 24)) : (gid))
13438 +
13439 +#endif
13440 +
13441 +
13442 +#ifdef CONFIG_TAGGING_UID16
13443 +
13444 +#define MAX_UID                0x0000FFFF
13445 +#define MAX_GID                0xFFFFFFFF
13446 +
13447 +#define INOTAG_TAG(cond, uid, gid, tag)        \
13448 +       ((cond) ? (((uid) >> 16) & 0xFFFF) : 0)
13449 +
13450 +#define TAGINO_UID(cond, uid, tag)     \
13451 +       ((cond) ? (((uid) & 0xFFFF) | ((tag) << 16)) : (uid))
13452 +#define TAGINO_GID(cond, gid, tag)     (gid)
13453 +
13454 +#endif
13455 +
13456 +
13457 +#ifdef CONFIG_TAGGING_INTERN
13458 +
13459 +#define MAX_UID                0xFFFFFFFF
13460 +#define MAX_GID                0xFFFFFFFF
13461 +
13462 +#define INOTAG_TAG(cond, uid, gid, tag)        \
13463 +       ((cond) ? (tag) : 0)
13464 +
13465 +#define TAGINO_UID(cond, uid, tag)     (uid)
13466 +#define TAGINO_GID(cond, gid, tag)     (gid)
13467 +
13468 +#endif
13469 +
13470 +
13471 +#ifndef CONFIG_TAGGING_NONE
13472 +#define dx_current_fstag(sb)   \
13473 +       ((sb)->s_flags & MS_TAGGED ? dx_current_tag() : 0)
13474 +#else
13475 +#define dx_current_fstag(sb)   (0)
13476 +#endif
13477 +
13478 +#ifndef CONFIG_TAGGING_INTERN
13479 +#define TAGINO_TAG(cond, tag)  (0)
13480 +#else
13481 +#define TAGINO_TAG(cond, tag)  ((cond) ? (tag) : 0)
13482 +#endif
13483 +
13484 +#define INOTAG_UID(cond, uid, gid)     \
13485 +       ((cond) ? ((uid) & MAX_UID) : (uid))
13486 +#define INOTAG_GID(cond, uid, gid)     \
13487 +       ((cond) ? ((gid) & MAX_GID) : (gid))
13488 +
13489 +
13490 +static inline uid_t dx_map_uid(uid_t uid)
13491 +{
13492 +       if ((uid > MAX_UID) && (uid != -1))
13493 +               uid = -2;
13494 +       return (uid & MAX_UID);
13495 +}
13496 +
13497 +static inline gid_t dx_map_gid(gid_t gid)
13498 +{
13499 +       if ((gid > MAX_GID) && (gid != -1))
13500 +               gid = -2;
13501 +       return (gid & MAX_GID);
13502 +}
13503 +
13504 +struct peer_tag {
13505 +       int32_t xid;
13506 +       int32_t nid;
13507 +};
13508 +
13509 +#define dx_notagcheck(sb) ((sb) && ((sb)->s_flags & MS_NOTAGCHECK))
13510 +
13511 +int dx_parse_tag(char *string, tag_t *tag, int remove, int *mnt_flags,
13512 +                unsigned long *flags);
13513 +
13514 +#ifdef CONFIG_PROPAGATE
13515 +
13516 +void __dx_propagate_tag(struct nameidata *nd, struct inode *inode);
13517 +
13518 +#define dx_propagate_tag(n, i) __dx_propagate_tag(n, i)
13519 +
13520 +#else
13521 +#define dx_propagate_tag(n, i) do { } while (0)
13522 +#endif
13523 +
13524 +#endif /* _DX_TAG_H */
13525 diff -NurpP --minimal linux-3.6/include/linux/vserver/tag_cmd.h linux-3.6-vs2.3.4.3-noxfs-nocow/include/linux/vserver/tag_cmd.h
13526 --- linux-3.6/include/linux/vserver/tag_cmd.h   1970-01-01 01:00:00.000000000 +0100
13527 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/include/linux/vserver/tag_cmd.h     2012-10-04 18:47:00.000000000 +0200
13528 @@ -0,0 +1,22 @@
13529 +#ifndef _VX_TAG_CMD_H
13530 +#define _VX_TAG_CMD_H
13531 +
13532 +
13533 +/* vinfo commands */
13534 +
13535 +#define VCMD_task_tag          VC_CMD(VINFO, 3, 0)
13536 +
13537 +#ifdef __KERNEL__
13538 +extern int vc_task_tag(uint32_t);
13539 +
13540 +#endif /* __KERNEL__ */
13541 +
13542 +/* context commands */
13543 +
13544 +#define VCMD_tag_migrate       VC_CMD(TAGMIG, 1, 0)
13545 +
13546 +#ifdef __KERNEL__
13547 +extern int vc_tag_migrate(uint32_t);
13548 +
13549 +#endif /* __KERNEL__ */
13550 +#endif /* _VX_TAG_CMD_H */
13551 diff -NurpP --minimal linux-3.6/include/net/addrconf.h linux-3.6-vs2.3.4.3-noxfs-nocow/include/net/addrconf.h
13552 --- linux-3.6/include/net/addrconf.h    2012-10-04 15:27:47.000000000 +0200
13553 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/include/net/addrconf.h      2012-10-04 18:47:00.000000000 +0200
13554 @@ -81,7 +81,8 @@ extern int                    ipv6_dev_get_saddr(struct n
13555                                                struct net_device *dev,
13556                                                const struct in6_addr *daddr,
13557                                                unsigned int srcprefs,
13558 -                                              struct in6_addr *saddr);
13559 +                                              struct in6_addr *saddr,
13560 +                                              struct nx_info *nxi);
13561  extern int                     ipv6_get_lladdr(struct net_device *dev,
13562                                                 struct in6_addr *addr,
13563                                                 unsigned char banned_flags);
13564 diff -NurpP --minimal linux-3.6/include/net/af_unix.h linux-3.6-vs2.3.4.3-noxfs-nocow/include/net/af_unix.h
13565 --- linux-3.6/include/net/af_unix.h     2012-10-04 15:27:47.000000000 +0200
13566 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/include/net/af_unix.h       2012-10-04 18:47:00.000000000 +0200
13567 @@ -4,6 +4,7 @@
13568  #include <linux/socket.h>
13569  #include <linux/un.h>
13570  #include <linux/mutex.h>
13571 +#include <linux/vs_base.h>
13572  #include <net/sock.h>
13573  
13574  extern void unix_inflight(struct file *fp);
13575 diff -NurpP --minimal linux-3.6/include/net/inet_timewait_sock.h linux-3.6-vs2.3.4.3-noxfs-nocow/include/net/inet_timewait_sock.h
13576 --- linux-3.6/include/net/inet_timewait_sock.h  2012-03-19 19:47:29.000000000 +0100
13577 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/include/net/inet_timewait_sock.h    2012-10-04 18:47:00.000000000 +0200
13578 @@ -112,6 +112,10 @@ struct inet_timewait_sock {
13579  #define tw_net                 __tw_common.skc_net
13580  #define tw_daddr               __tw_common.skc_daddr
13581  #define tw_rcv_saddr           __tw_common.skc_rcv_saddr
13582 +#define tw_xid                 __tw_common.skc_xid
13583 +#define tw_vx_info             __tw_common.skc_vx_info
13584 +#define tw_nid                 __tw_common.skc_nid
13585 +#define tw_nx_info             __tw_common.skc_nx_info
13586         int                     tw_timeout;
13587         volatile unsigned char  tw_substate;
13588         unsigned char           tw_rcv_wscale;
13589 diff -NurpP --minimal linux-3.6/include/net/ip6_route.h linux-3.6-vs2.3.4.3-noxfs-nocow/include/net/ip6_route.h
13590 --- linux-3.6/include/net/ip6_route.h   2012-10-04 15:27:47.000000000 +0200
13591 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/include/net/ip6_route.h     2012-10-04 18:47:00.000000000 +0200
13592 @@ -97,7 +97,8 @@ extern int                    ip6_route_get_saddr(struct 
13593                                                     struct rt6_info *rt,
13594                                                     const struct in6_addr *daddr,
13595                                                     unsigned int prefs,
13596 -                                                   struct in6_addr *saddr);
13597 +                                                   struct in6_addr *saddr,
13598 +                                                   struct nx_info *nxi);
13599  
13600  extern struct rt6_info         *rt6_lookup(struct net *net,
13601                                             const struct in6_addr *daddr,
13602 diff -NurpP --minimal linux-3.6/include/net/route.h linux-3.6-vs2.3.4.3-noxfs-nocow/include/net/route.h
13603 --- linux-3.6/include/net/route.h       2012-10-04 15:27:47.000000000 +0200
13604 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/include/net/route.h 2012-10-04 18:47:00.000000000 +0200
13605 @@ -203,6 +203,9 @@ static inline void ip_rt_put(struct rtab
13606                 dst_release(&rt->dst);
13607  }
13608  
13609 +#include <linux/vs_base.h>
13610 +#include <linux/vs_inet.h>
13611 +
13612  #define IPTOS_RT_MASK  (IPTOS_TOS_MASK & ~3)
13613  
13614  extern const __u8 ip_tos2prio[16];
13615 @@ -252,6 +255,9 @@ static inline void ip_route_connect_init
13616                            protocol, flow_flags, dst, src, dport, sport);
13617  }
13618  
13619 +extern struct rtable *ip_v4_find_src(struct net *net, struct nx_info *,
13620 +       struct flowi4 *);
13621 +
13622  static inline struct rtable *ip_route_connect(struct flowi4 *fl4,
13623                                               __be32 dst, __be32 src, u32 tos,
13624                                               int oif, u8 protocol,
13625 @@ -260,11 +266,25 @@ static inline struct rtable *ip_route_co
13626  {
13627         struct net *net = sock_net(sk);
13628         struct rtable *rt;
13629 +       struct nx_info *nx_info = current_nx_info();
13630  
13631         ip_route_connect_init(fl4, dst, src, tos, oif, protocol,
13632                               sport, dport, sk, can_sleep);
13633  
13634 -       if (!dst || !src) {
13635 +       if (sk)
13636 +               nx_info = sk->sk_nx_info;
13637 +
13638 +       vxdprintk(VXD_CBIT(net, 4),
13639 +               "ip_route_connect(%p) %p,%p;%lx",
13640 +               sk, nx_info, sk->sk_socket,
13641 +               (sk->sk_socket?sk->sk_socket->flags:0));
13642 +
13643 +       rt = ip_v4_find_src(net, nx_info, fl4);
13644 +       if (IS_ERR(rt))
13645 +               return rt;
13646 +       ip_rt_put(rt);
13647 +
13648 +       if (!fl4->daddr || !fl4->saddr) {
13649                 rt = __ip_route_output_key(net, fl4);
13650                 if (IS_ERR(rt))
13651                         return rt;
13652 diff -NurpP --minimal linux-3.6/include/net/sock.h linux-3.6-vs2.3.4.3-noxfs-nocow/include/net/sock.h
13653 --- linux-3.6/include/net/sock.h        2012-10-04 15:27:47.000000000 +0200
13654 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/include/net/sock.h  2012-10-04 18:47:00.000000000 +0200
13655 @@ -171,6 +171,10 @@ struct sock_common {
13656  #ifdef CONFIG_NET_NS
13657         struct net              *skc_net;
13658  #endif
13659 +       xid_t                   skc_xid;
13660 +       struct vx_info          *skc_vx_info;
13661 +       nid_t                   skc_nid;
13662 +       struct nx_info          *skc_nx_info;
13663         /*
13664          * fields between dontcopy_begin/dontcopy_end
13665          * are not copied in sock_copy()
13666 @@ -284,6 +288,10 @@ struct sock {
13667  #define sk_bind_node           __sk_common.skc_bind_node
13668  #define sk_prot                        __sk_common.skc_prot
13669  #define sk_net                 __sk_common.skc_net
13670 +#define sk_xid                 __sk_common.skc_xid
13671 +#define sk_vx_info             __sk_common.skc_vx_info
13672 +#define sk_nid                 __sk_common.skc_nid
13673 +#define sk_nx_info             __sk_common.skc_nx_info
13674         socket_lock_t           sk_lock;
13675         struct sk_buff_head     sk_receive_queue;
13676         /*
13677 diff -NurpP --minimal linux-3.6/init/Kconfig linux-3.6-vs2.3.4.3-noxfs-nocow/init/Kconfig
13678 --- linux-3.6/init/Kconfig      2012-10-04 15:27:48.000000000 +0200
13679 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/init/Kconfig        2012-10-04 18:47:00.000000000 +0200
13680 @@ -624,6 +624,7 @@ config HAVE_UNSTABLE_SCHED_CLOCK
13681  menuconfig CGROUPS
13682         boolean "Control Group support"
13683         depends on EVENTFD
13684 +       default y
13685         help
13686           This option adds support for grouping sets of processes together, for
13687           use with process control subsystems such as Cpusets, CFS, memory
13688 @@ -889,6 +890,7 @@ config USER_NS
13689         bool "User namespace (EXPERIMENTAL)"
13690         depends on EXPERIMENTAL
13691         depends on UIDGID_CONVERTED
13692 +       depends on VSERVER_DISABLED
13693         select UIDGID_STRICT_TYPE_CHECKS
13694  
13695         default n
13696 diff -NurpP --minimal linux-3.6/init/main.c linux-3.6-vs2.3.4.3-noxfs-nocow/init/main.c
13697 --- linux-3.6/init/main.c       2012-10-04 15:27:48.000000000 +0200
13698 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/init/main.c 2012-10-04 18:51:41.000000000 +0200
13699 @@ -69,6 +69,7 @@
13700  #include <linux/slab.h>
13701  #include <linux/perf_event.h>
13702  #include <linux/file.h>
13703 +#include <linux/vserver/percpu.h>
13704  
13705  #include <asm/io.h>
13706  #include <asm/bugs.h>
13707 diff -NurpP --minimal linux-3.6/ipc/mqueue.c linux-3.6-vs2.3.4.3-noxfs-nocow/ipc/mqueue.c
13708 --- linux-3.6/ipc/mqueue.c      2012-10-04 15:27:48.000000000 +0200
13709 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/ipc/mqueue.c        2012-10-04 18:47:00.000000000 +0200
13710 @@ -35,6 +35,8 @@
13711  #include <linux/ipc_namespace.h>
13712  #include <linux/user_namespace.h>
13713  #include <linux/slab.h>
13714 +#include <linux/vs_context.h>
13715 +#include <linux/vs_limit.h>
13716  
13717  #include <net/sock.h>
13718  #include "util.h"
13719 @@ -76,6 +78,7 @@ struct mqueue_inode_info {
13720         struct pid* notify_owner;
13721         struct user_namespace *notify_user_ns;
13722         struct user_struct *user;       /* user who created, for accounting */
13723 +       struct vx_info *vxi;
13724         struct sock *notify_sock;
13725         struct sk_buff *notify_cookie;
13726  
13727 @@ -235,6 +238,7 @@ static struct inode *mqueue_get_inode(st
13728         if (S_ISREG(mode)) {
13729                 struct mqueue_inode_info *info;
13730                 unsigned long mq_bytes, mq_treesize;
13731 +               struct vx_info *vxi = current_vx_info();
13732  
13733                 inode->i_fop = &mqueue_file_operations;
13734                 inode->i_size = FILENT_SIZE;
13735 @@ -248,6 +252,7 @@ static struct inode *mqueue_get_inode(st
13736                 info->notify_user_ns = NULL;
13737                 info->qsize = 0;
13738                 info->user = NULL;      /* set when all is ok */
13739 +               info->vxi = NULL;
13740                 info->msg_tree = RB_ROOT;
13741                 info->node_cache = NULL;
13742                 memset(&info->attr, 0, sizeof(info->attr));
13743 @@ -281,17 +286,20 @@ static struct inode *mqueue_get_inode(st
13744  
13745                 spin_lock(&mq_lock);
13746                 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
13747 -                   u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE)) {
13748 +                   u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE) ||
13749 +                   !vx_ipcmsg_avail(vxi, mq_bytes)) {
13750                         spin_unlock(&mq_lock);
13751                         /* mqueue_evict_inode() releases info->messages */
13752                         ret = -EMFILE;
13753                         goto out_inode;
13754                 }
13755                 u->mq_bytes += mq_bytes;
13756 +               vx_ipcmsg_add(vxi, u, mq_bytes);
13757                 spin_unlock(&mq_lock);
13758  
13759                 /* all is ok */
13760                 info->user = get_uid(u);
13761 +               info->vxi = get_vx_info(vxi);
13762         } else if (S_ISDIR(mode)) {
13763                 inc_nlink(inode);
13764                 /* Some things misbehave if size == 0 on a directory */
13765 @@ -395,8 +403,11 @@ static void mqueue_evict_inode(struct in
13766  
13767         user = info->user;
13768         if (user) {
13769 +               struct vx_info *vxi = info->vxi;
13770 +
13771                 spin_lock(&mq_lock);
13772                 user->mq_bytes -= mq_bytes;
13773 +               vx_ipcmsg_sub(vxi, user, mq_bytes);
13774                 /*
13775                  * get_ns_from_inode() ensures that the
13776                  * (ipc_ns = sb->s_fs_info) is either a valid ipc_ns
13777 @@ -406,6 +417,7 @@ static void mqueue_evict_inode(struct in
13778                 if (ipc_ns)
13779                         ipc_ns->mq_queues_count--;
13780                 spin_unlock(&mq_lock);
13781 +               put_vx_info(vxi);
13782                 free_uid(user);
13783         }
13784         if (ipc_ns)
13785 diff -NurpP --minimal linux-3.6/ipc/msg.c linux-3.6-vs2.3.4.3-noxfs-nocow/ipc/msg.c
13786 --- linux-3.6/ipc/msg.c 2011-05-22 16:17:59.000000000 +0200
13787 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/ipc/msg.c   2012-10-04 18:47:00.000000000 +0200
13788 @@ -37,6 +37,7 @@
13789  #include <linux/rwsem.h>
13790  #include <linux/nsproxy.h>
13791  #include <linux/ipc_namespace.h>
13792 +#include <linux/vs_base.h>
13793  
13794  #include <asm/current.h>
13795  #include <asm/uaccess.h>
13796 @@ -190,6 +191,7 @@ static int newque(struct ipc_namespace *
13797  
13798         msq->q_perm.mode = msgflg & S_IRWXUGO;
13799         msq->q_perm.key = key;
13800 +       msq->q_perm.xid = vx_current_xid();
13801  
13802         msq->q_perm.security = NULL;
13803         retval = security_msg_queue_alloc(msq);
13804 diff -NurpP --minimal linux-3.6/ipc/namespace.c linux-3.6-vs2.3.4.3-noxfs-nocow/ipc/namespace.c
13805 --- linux-3.6/ipc/namespace.c   2012-07-22 23:39:46.000000000 +0200
13806 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/ipc/namespace.c     2012-10-04 18:47:00.000000000 +0200
13807 @@ -13,11 +13,12 @@
13808  #include <linux/mount.h>
13809  #include <linux/user_namespace.h>
13810  #include <linux/proc_fs.h>
13811 +#include <linux/vs_base.h>
13812 +#include <linux/vserver/global.h>
13813  
13814  #include "util.h"
13815  
13816 -static struct ipc_namespace *create_ipc_ns(struct task_struct *tsk,
13817 -                                          struct ipc_namespace *old_ns)
13818 +static struct ipc_namespace *create_ipc_ns(struct user_namespace *user_ns)
13819  {
13820         struct ipc_namespace *ns;
13821         int err;
13822 @@ -46,19 +47,19 @@ static struct ipc_namespace *create_ipc_
13823         ipcns_notify(IPCNS_CREATED);
13824         register_ipcns_notifier(ns);
13825  
13826 -       ns->user_ns = get_user_ns(task_cred_xxx(tsk, user_ns));
13827 +       // ns->user_ns = get_user_ns(task_cred_xxx(tsk, user_ns));
13828 +       ns->user_ns = get_user_ns(user_ns);
13829  
13830         return ns;
13831  }
13832  
13833  struct ipc_namespace *copy_ipcs(unsigned long flags,
13834 -                               struct task_struct *tsk)
13835 +                               struct ipc_namespace *old_ns,
13836 +                               struct user_namespace *user_ns)
13837  {
13838 -       struct ipc_namespace *ns = tsk->nsproxy->ipc_ns;
13839 -
13840         if (!(flags & CLONE_NEWIPC))
13841 -               return get_ipc_ns(ns);
13842 -       return create_ipc_ns(tsk, ns);
13843 +               return get_ipc_ns(old_ns);
13844 +       return create_ipc_ns(user_ns);
13845  }
13846  
13847  /*
13848 diff -NurpP --minimal linux-3.6/ipc/sem.c linux-3.6-vs2.3.4.3-noxfs-nocow/ipc/sem.c
13849 --- linux-3.6/ipc/sem.c 2012-01-09 16:14:59.000000000 +0100
13850 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/ipc/sem.c   2012-10-04 18:47:00.000000000 +0200
13851 @@ -86,6 +86,8 @@
13852  #include <linux/rwsem.h>
13853  #include <linux/nsproxy.h>
13854  #include <linux/ipc_namespace.h>
13855 +#include <linux/vs_base.h>
13856 +#include <linux/vs_limit.h>
13857  
13858  #include <asm/uaccess.h>
13859  #include "util.h"
13860 @@ -306,6 +308,7 @@ static int newary(struct ipc_namespace *
13861  
13862         sma->sem_perm.mode = (semflg & S_IRWXUGO);
13863         sma->sem_perm.key = key;
13864 +       sma->sem_perm.xid = vx_current_xid();
13865  
13866         sma->sem_perm.security = NULL;
13867         retval = security_sem_alloc(sma);
13868 @@ -321,6 +324,9 @@ static int newary(struct ipc_namespace *
13869                 return id;
13870         }
13871         ns->used_sems += nsems;
13872 +       /* FIXME: obsoleted? */
13873 +       vx_semary_inc(sma);
13874 +       vx_nsems_add(sma, nsems);
13875  
13876         sma->sem_base = (struct sem *) &sma[1];
13877  
13878 @@ -770,6 +776,9 @@ static void freeary(struct ipc_namespace
13879  
13880         wake_up_sem_queue_do(&tasks);
13881         ns->used_sems -= sma->sem_nsems;
13882 +       /* FIXME: obsoleted? */
13883 +       vx_nsems_sub(sma, sma->sem_nsems);
13884 +       vx_semary_dec(sma);
13885         security_sem_free(sma);
13886         ipc_rcu_putref(sma);
13887  }
13888 diff -NurpP --minimal linux-3.6/ipc/shm.c linux-3.6-vs2.3.4.3-noxfs-nocow/ipc/shm.c
13889 --- linux-3.6/ipc/shm.c 2012-10-04 15:27:48.000000000 +0200
13890 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/ipc/shm.c   2012-10-04 18:47:00.000000000 +0200
13891 @@ -39,6 +39,8 @@
13892  #include <linux/nsproxy.h>
13893  #include <linux/mount.h>
13894  #include <linux/ipc_namespace.h>
13895 +#include <linux/vs_context.h>
13896 +#include <linux/vs_limit.h>
13897  
13898  #include <asm/uaccess.h>
13899  
13900 @@ -187,7 +189,12 @@ static void shm_open(struct vm_area_stru
13901   */
13902  static void shm_destroy(struct ipc_namespace *ns, struct shmid_kernel *shp)
13903  {
13904 -       ns->shm_tot -= (shp->shm_segsz + PAGE_SIZE - 1) >> PAGE_SHIFT;
13905 +       struct vx_info *vxi = lookup_vx_info(shp->shm_perm.xid);
13906 +       int numpages = (shp->shm_segsz + PAGE_SIZE - 1) >> PAGE_SHIFT;
13907 +
13908 +       vx_ipcshm_sub(vxi, shp, numpages);
13909 +       ns->shm_tot -= numpages;
13910 +
13911         shm_rmid(ns, shp);
13912         shm_unlock(shp);
13913         if (!is_file_hugepages(shp->shm_file))
13914 @@ -197,6 +204,7 @@ static void shm_destroy(struct ipc_names
13915                                                 shp->mlock_user);
13916         fput (shp->shm_file);
13917         security_shm_free(shp);
13918 +       put_vx_info(vxi);
13919         ipc_rcu_putref(shp);
13920  }
13921  
13922 @@ -474,11 +482,15 @@ static int newseg(struct ipc_namespace *
13923         if (ns->shm_tot + numpages > ns->shm_ctlall)
13924                 return -ENOSPC;
13925  
13926 +       if (!vx_ipcshm_avail(current_vx_info(), numpages))
13927 +               return -ENOSPC;
13928 +
13929         shp = ipc_rcu_alloc(sizeof(*shp));
13930         if (!shp)
13931                 return -ENOMEM;
13932  
13933         shp->shm_perm.key = key;
13934 +       shp->shm_perm.xid = vx_current_xid();
13935         shp->shm_perm.mode = (shmflg & S_IRWXUGO);
13936         shp->mlock_user = NULL;
13937  
13938 @@ -533,6 +545,7 @@ static int newseg(struct ipc_namespace *
13939         ns->shm_tot += numpages;
13940         error = shp->shm_perm.id;
13941         shm_unlock(shp);
13942 +       vx_ipcshm_add(current_vx_info(), key, numpages);
13943         return error;
13944  
13945  no_id:
13946 diff -NurpP --minimal linux-3.6/kernel/Makefile linux-3.6-vs2.3.4.3-noxfs-nocow/kernel/Makefile
13947 --- linux-3.6/kernel/Makefile   2012-07-22 23:39:46.000000000 +0200
13948 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/kernel/Makefile     2012-10-04 18:47:00.000000000 +0200
13949 @@ -24,6 +24,7 @@ endif
13950  
13951  obj-y += sched/
13952  obj-y += power/
13953 +obj-y += vserver/
13954  
13955  ifeq ($(CONFIG_CHECKPOINT_RESTORE),y)
13956  obj-$(CONFIG_X86) += kcmp.o
13957 diff -NurpP --minimal linux-3.6/kernel/auditsc.c linux-3.6-vs2.3.4.3-noxfs-nocow/kernel/auditsc.c
13958 --- linux-3.6/kernel/auditsc.c  2012-07-22 23:39:46.000000000 +0200
13959 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/kernel/auditsc.c    2012-10-04 18:47:00.000000000 +0200
13960 @@ -2309,7 +2309,7 @@ int audit_set_loginuid(uid_t loginuid)
13961         if (task->loginuid != -1)
13962                 return -EPERM;
13963  #else /* CONFIG_AUDIT_LOGINUID_IMMUTABLE */
13964 -       if (!capable(CAP_AUDIT_CONTROL))
13965 +       if (!vx_capable(CAP_AUDIT_CONTROL, VXC_AUDIT_CONTROL))
13966                 return -EPERM;
13967  #endif  /* CONFIG_AUDIT_LOGINUID_IMMUTABLE */
13968  
13969 diff -NurpP --minimal linux-3.6/kernel/capability.c linux-3.6-vs2.3.4.3-noxfs-nocow/kernel/capability.c
13970 --- linux-3.6/kernel/capability.c       2012-07-22 23:39:46.000000000 +0200
13971 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/kernel/capability.c 2012-10-04 18:47:00.000000000 +0200
13972 @@ -15,6 +15,7 @@
13973  #include <linux/syscalls.h>
13974  #include <linux/pid_namespace.h>
13975  #include <linux/user_namespace.h>
13976 +#include <linux/vs_context.h>
13977  #include <asm/uaccess.h>
13978  
13979  /*
13980 @@ -116,6 +117,7 @@ static int cap_validate_magic(cap_user_h
13981         return 0;
13982  }
13983  
13984 +
13985  /*
13986   * The only thing that can change the capabilities of the current
13987   * process is the current process. As such, we can't be in this code
13988 @@ -349,6 +351,8 @@ bool has_ns_capability_noaudit(struct ta
13989         return (ret == 0);
13990  }
13991  
13992 +#include <linux/vserver/base.h>
13993 +
13994  /**
13995   * has_capability_noaudit - Does a task have a capability (unaudited) in the
13996   * initial user ns
13997 diff -NurpP --minimal linux-3.6/kernel/compat.c linux-3.6-vs2.3.4.3-noxfs-nocow/kernel/compat.c
13998 --- linux-3.6/kernel/compat.c   2012-07-22 23:39:46.000000000 +0200
13999 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/kernel/compat.c     2012-10-04 18:47:00.000000000 +0200
14000 @@ -1054,7 +1054,7 @@ asmlinkage long compat_sys_stime(compat_
14001         if (err)
14002                 return err;
14003  
14004 -       do_settimeofday(&tv);
14005 +       vx_settimeofday(&tv);
14006         return 0;
14007  }
14008  
14009 diff -NurpP --minimal linux-3.6/kernel/cred.c linux-3.6-vs2.3.4.3-noxfs-nocow/kernel/cred.c
14010 --- linux-3.6/kernel/cred.c     2012-07-22 23:39:46.000000000 +0200
14011 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/kernel/cred.c       2012-10-04 18:47:00.000000000 +0200
14012 @@ -70,31 +70,6 @@ struct cred init_cred = {
14013  #endif
14014  };
14015  
14016 -static inline void set_cred_subscribers(struct cred *cred, int n)
14017 -{
14018 -#ifdef CONFIG_DEBUG_CREDENTIALS
14019 -       atomic_set(&cred->subscribers, n);
14020 -#endif
14021 -}
14022 -
14023 -static inline int read_cred_subscribers(const struct cred *cred)
14024 -{
14025 -#ifdef CONFIG_DEBUG_CREDENTIALS
14026 -       return atomic_read(&cred->subscribers);
14027 -#else
14028 -       return 0;
14029 -#endif
14030 -}
14031 -
14032 -static inline void alter_cred_subscribers(const struct cred *_cred, int n)
14033 -{
14034 -#ifdef CONFIG_DEBUG_CREDENTIALS
14035 -       struct cred *cred = (struct cred *) _cred;
14036 -
14037 -       atomic_add(n, &cred->subscribers);
14038 -#endif
14039 -}
14040 -
14041  /*
14042   * Dispose of the shared task group credentials
14043   */
14044 @@ -284,21 +259,16 @@ error:
14045   *
14046   * Call commit_creds() or abort_creds() to clean up.
14047   */
14048 -struct cred *prepare_creds(void)
14049 +struct cred *__prepare_creds(const struct cred *old)
14050  {
14051 -       struct task_struct *task = current;
14052 -       const struct cred *old;
14053         struct cred *new;
14054  
14055 -       validate_process_creds();
14056 -
14057         new = kmem_cache_alloc(cred_jar, GFP_KERNEL);
14058         if (!new)
14059                 return NULL;
14060  
14061         kdebug("prepare_creds() alloc %p", new);
14062  
14063 -       old = task->cred;
14064         memcpy(new, old, sizeof(struct cred));
14065  
14066         atomic_set(&new->usage, 1);
14067 @@ -326,6 +296,13 @@ error:
14068         abort_creds(new);
14069         return NULL;
14070  }
14071 +
14072 +struct cred *prepare_creds(void)
14073 +{
14074 +       validate_process_creds();
14075 +
14076 +       return __prepare_creds(current->cred);
14077 +}
14078  EXPORT_SYMBOL(prepare_creds);
14079  
14080  /*
14081 diff -NurpP --minimal linux-3.6/kernel/exit.c linux-3.6-vs2.3.4.3-noxfs-nocow/kernel/exit.c
14082 --- linux-3.6/kernel/exit.c     2012-10-04 15:27:48.000000000 +0200
14083 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/kernel/exit.c       2012-10-04 18:47:00.000000000 +0200
14084 @@ -48,6 +48,10 @@
14085  #include <linux/fs_struct.h>
14086  #include <linux/init_task.h>
14087  #include <linux/perf_event.h>
14088 +#include <linux/vs_limit.h>
14089 +#include <linux/vs_context.h>
14090 +#include <linux/vs_network.h>
14091 +#include <linux/vs_pid.h>
14092  #include <trace/events/sched.h>
14093  #include <linux/hw_breakpoint.h>
14094  #include <linux/oom.h>
14095 @@ -494,9 +498,11 @@ static void close_files(struct files_str
14096                                         filp_close(file, files);
14097                                         cond_resched();
14098                                 }
14099 +                               vx_openfd_dec(i);
14100                         }
14101                         i++;
14102                         set >>= 1;
14103 +                       cond_resched();
14104                 }
14105         }
14106  }
14107 @@ -1018,6 +1024,9 @@ void do_exit(long code)
14108          */
14109         ptrace_put_breakpoints(tsk);
14110  
14111 +       /* needs to stay before exit_notify() */
14112 +       exit_vx_info_early(tsk, code);
14113 +
14114         exit_notify(tsk, group_dead);
14115  #ifdef CONFIG_NUMA
14116         task_lock(tsk);
14117 @@ -1068,10 +1077,15 @@ void do_exit(long code)
14118         smp_mb();
14119         raw_spin_unlock_wait(&tsk->pi_lock);
14120  
14121 +       /* needs to stay after exit_notify() */
14122 +       exit_vx_info(tsk, code);
14123 +       exit_nx_info(tsk);
14124 +
14125         /* causes final put_task_struct in finish_task_switch(). */
14126         tsk->state = TASK_DEAD;
14127         tsk->flags |= PF_NOFREEZE;      /* tell freezer to ignore us */
14128         schedule();
14129 +       printk("bad task: %p [%lx]\n", current, current->state);
14130         BUG();
14131         /* Avoid "noreturn function does return".  */
14132         for (;;)
14133 diff -NurpP --minimal linux-3.6/kernel/fork.c linux-3.6-vs2.3.4.3-noxfs-nocow/kernel/fork.c
14134 --- linux-3.6/kernel/fork.c     2012-10-04 15:27:48.000000000 +0200
14135 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/kernel/fork.c       2012-10-04 18:47:00.000000000 +0200
14136 @@ -70,6 +70,9 @@
14137  #include <linux/khugepaged.h>
14138  #include <linux/signalfd.h>
14139  #include <linux/uprobes.h>
14140 +#include <linux/vs_context.h>
14141 +#include <linux/vs_network.h>
14142 +#include <linux/vs_limit.h>
14143  
14144  #include <asm/pgtable.h>
14145  #include <asm/pgalloc.h>
14146 @@ -210,6 +213,8 @@ void free_task(struct task_struct *tsk)
14147         arch_release_thread_info(tsk->stack);
14148         free_thread_info(tsk->stack);
14149         rt_mutex_debug_task_free(tsk);
14150 +       clr_vx_info(&tsk->vx_info);
14151 +       clr_nx_info(&tsk->nx_info);
14152         ftrace_graph_exit_task(tsk);
14153         put_seccomp_filter(tsk);
14154         arch_release_task_struct(tsk);
14155 @@ -541,6 +546,7 @@ static struct mm_struct *mm_init(struct 
14156         if (likely(!mm_alloc_pgd(mm))) {
14157                 mm->def_flags = 0;
14158                 mmu_notifier_mm_init(mm);
14159 +               set_vx_info(&mm->mm_vx_info, p->vx_info);
14160                 return mm;
14161         }
14162  
14163 @@ -593,6 +599,7 @@ void __mmdrop(struct mm_struct *mm)
14164         destroy_context(mm);
14165         mmu_notifier_mm_destroy(mm);
14166         check_mm(mm);
14167 +       clr_vx_info(&mm->mm_vx_info);
14168         free_mm(mm);
14169  }
14170  EXPORT_SYMBOL_GPL(__mmdrop);
14171 @@ -834,6 +841,7 @@ struct mm_struct *dup_mm(struct task_str
14172                 goto fail_nomem;
14173  
14174         memcpy(mm, oldmm, sizeof(*mm));
14175 +       mm->mm_vx_info = NULL;
14176         mm_init_cpumask(mm);
14177  
14178  #ifdef CONFIG_TRANSPARENT_HUGEPAGE
14179 @@ -874,6 +882,7 @@ fail_nocontext:
14180          * If init_new_context() failed, we cannot use mmput() to free the mm
14181          * because it calls destroy_context()
14182          */
14183 +       clr_vx_info(&mm->mm_vx_info);
14184         mm_free_pgd(mm);
14185         free_mm(mm);
14186         return NULL;
14187 @@ -1157,6 +1166,8 @@ static struct task_struct *copy_process(
14188         int retval;
14189         struct task_struct *p;
14190         int cgroup_callbacks_done = 0;
14191 +       struct vx_info *vxi;
14192 +       struct nx_info *nxi;
14193  
14194         if ((clone_flags & (CLONE_NEWNS|CLONE_FS)) == (CLONE_NEWNS|CLONE_FS))
14195                 return ERR_PTR(-EINVAL);
14196 @@ -1204,7 +1215,12 @@ static struct task_struct *copy_process(
14197         DEBUG_LOCKS_WARN_ON(!p->hardirqs_enabled);
14198         DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
14199  #endif
14200 +       init_vx_info(&p->vx_info, current_vx_info());
14201 +       init_nx_info(&p->nx_info, current_nx_info());
14202 +
14203         retval = -EAGAIN;
14204 +       if (!vx_nproc_avail(1))
14205 +               goto bad_fork_free;
14206         if (atomic_read(&p->real_cred->user->processes) >=
14207                         task_rlimit(p, RLIMIT_NPROC)) {
14208                 if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE) &&
14209 @@ -1483,6 +1499,18 @@ static struct task_struct *copy_process(
14210  
14211         total_forks++;
14212         spin_unlock(&current->sighand->siglock);
14213 +
14214 +       /* p is copy of current */
14215 +       vxi = p->vx_info;
14216 +       if (vxi) {
14217 +               claim_vx_info(vxi, p);
14218 +               atomic_inc(&vxi->cvirt.nr_threads);
14219 +               atomic_inc(&vxi->cvirt.total_forks);
14220 +               vx_nproc_inc(p);
14221 +       }
14222 +       nxi = p->nx_info;
14223 +       if (nxi)
14224 +               claim_nx_info(nxi, p);
14225         write_unlock_irq(&tasklist_lock);
14226         proc_fork_connector(p);
14227         cgroup_post_fork(p);
14228 diff -NurpP --minimal linux-3.6/kernel/kthread.c linux-3.6-vs2.3.4.3-noxfs-nocow/kernel/kthread.c
14229 --- linux-3.6/kernel/kthread.c  2012-10-04 15:27:48.000000000 +0200
14230 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/kernel/kthread.c    2012-10-04 18:47:00.000000000 +0200
14231 @@ -16,6 +16,7 @@
14232  #include <linux/mutex.h>
14233  #include <linux/slab.h>
14234  #include <linux/freezer.h>
14235 +#include <linux/vs_pid.h>
14236  #include <trace/events/sched.h>
14237  
14238  static DEFINE_SPINLOCK(kthread_create_lock);
14239 diff -NurpP --minimal linux-3.6/kernel/nsproxy.c linux-3.6-vs2.3.4.3-noxfs-nocow/kernel/nsproxy.c
14240 --- linux-3.6/kernel/nsproxy.c  2012-01-09 16:15:00.000000000 +0100
14241 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/kernel/nsproxy.c    2012-10-04 18:47:00.000000000 +0200
14242 @@ -20,11 +20,14 @@
14243  #include <linux/mnt_namespace.h>
14244  #include <linux/utsname.h>
14245  #include <linux/pid_namespace.h>
14246 +#include <linux/vserver/global.h>
14247 +#include <linux/vserver/debug.h>
14248  #include <net/net_namespace.h>
14249  #include <linux/ipc_namespace.h>
14250  #include <linux/proc_fs.h>
14251  #include <linux/file.h>
14252  #include <linux/syscalls.h>
14253 +#include "../fs/mount.h"
14254  
14255  static struct kmem_cache *nsproxy_cachep;
14256  
14257 @@ -46,8 +49,11 @@ static inline struct nsproxy *create_nsp
14258         struct nsproxy *nsproxy;
14259  
14260         nsproxy = kmem_cache_alloc(nsproxy_cachep, GFP_KERNEL);
14261 -       if (nsproxy)
14262 +       if (nsproxy) {
14263                 atomic_set(&nsproxy->count, 1);
14264 +               atomic_inc(&vs_global_nsproxy);
14265 +       }
14266 +       vxdprintk(VXD_CBIT(space, 2), "create_nsproxy = %p[1]", nsproxy);
14267         return nsproxy;
14268  }
14269  
14270 @@ -56,8 +62,11 @@ static inline struct nsproxy *create_nsp
14271   * Return the newly created nsproxy.  Do not attach this to the task,
14272   * leave it to the caller to do proper locking and attach it to task.
14273   */
14274 -static struct nsproxy *create_new_namespaces(unsigned long flags,
14275 -                       struct task_struct *tsk, struct fs_struct *new_fs)
14276 +static struct nsproxy *unshare_namespaces(unsigned long flags,
14277 +                       struct nsproxy *orig,
14278 +                       struct fs_struct *new_fs,
14279 +                       struct user_namespace *new_user,
14280 +                       struct pid_namespace *new_pid)
14281  {
14282         struct nsproxy *new_nsp;
14283         int err;
14284 @@ -66,31 +75,31 @@ static struct nsproxy *create_new_namesp
14285         if (!new_nsp)
14286                 return ERR_PTR(-ENOMEM);
14287  
14288 -       new_nsp->mnt_ns = copy_mnt_ns(flags, tsk->nsproxy->mnt_ns, new_fs);
14289 +       new_nsp->mnt_ns = copy_mnt_ns(flags, orig->mnt_ns, new_fs);
14290         if (IS_ERR(new_nsp->mnt_ns)) {
14291                 err = PTR_ERR(new_nsp->mnt_ns);
14292                 goto out_ns;
14293         }
14294  
14295 -       new_nsp->uts_ns = copy_utsname(flags, tsk);
14296 +       new_nsp->uts_ns = copy_utsname(flags, orig->uts_ns, new_user);
14297         if (IS_ERR(new_nsp->uts_ns)) {
14298                 err = PTR_ERR(new_nsp->uts_ns);
14299                 goto out_uts;
14300         }
14301  
14302 -       new_nsp->ipc_ns = copy_ipcs(flags, tsk);
14303 +       new_nsp->ipc_ns = copy_ipcs(flags, orig->ipc_ns, new_user);
14304         if (IS_ERR(new_nsp->ipc_ns)) {
14305                 err = PTR_ERR(new_nsp->ipc_ns);
14306                 goto out_ipc;
14307         }
14308  
14309 -       new_nsp->pid_ns = copy_pid_ns(flags, task_active_pid_ns(tsk));
14310 +       new_nsp->pid_ns = copy_pid_ns(flags, new_pid);
14311         if (IS_ERR(new_nsp->pid_ns)) {
14312                 err = PTR_ERR(new_nsp->pid_ns);
14313                 goto out_pid;
14314         }
14315  
14316 -       new_nsp->net_ns = copy_net_ns(flags, tsk->nsproxy->net_ns);
14317 +       new_nsp->net_ns = copy_net_ns(flags, orig->net_ns);
14318         if (IS_ERR(new_nsp->net_ns)) {
14319                 err = PTR_ERR(new_nsp->net_ns);
14320                 goto out_net;
14321 @@ -115,6 +124,40 @@ out_ns:
14322         return ERR_PTR(err);
14323  }
14324  
14325 +static struct nsproxy *create_new_namespaces(unsigned long flags,
14326 +                       struct task_struct *tsk, struct fs_struct *new_fs)
14327 +{
14328 +       return unshare_namespaces(flags, tsk->nsproxy,
14329 +               new_fs, task_cred_xxx(tsk, user_ns),
14330 +               task_active_pid_ns(tsk));
14331 +}
14332 +
14333 +/*
14334 + * copies the nsproxy, setting refcount to 1, and grabbing a
14335 + * reference to all contained namespaces.
14336 + */
14337 +struct nsproxy *copy_nsproxy(struct nsproxy *orig)
14338 +{
14339 +       struct nsproxy *ns = create_nsproxy();
14340 +
14341 +       if (ns) {
14342 +               memcpy(ns, orig, sizeof(struct nsproxy));
14343 +               atomic_set(&ns->count, 1);
14344 +
14345 +               if (ns->mnt_ns)
14346 +                       get_mnt_ns(ns->mnt_ns);
14347 +               if (ns->uts_ns)
14348 +                       get_uts_ns(ns->uts_ns);
14349 +               if (ns->ipc_ns)
14350 +                       get_ipc_ns(ns->ipc_ns);
14351 +               if (ns->pid_ns)
14352 +                       get_pid_ns(ns->pid_ns);
14353 +               if (ns->net_ns)
14354 +                       get_net(ns->net_ns);
14355 +       }
14356 +       return ns;
14357 +}
14358 +
14359  /*
14360   * called from clone.  This now handles copy for nsproxy and all
14361   * namespaces therein.
14362 @@ -122,9 +165,12 @@ out_ns:
14363  int copy_namespaces(unsigned long flags, struct task_struct *tsk)
14364  {
14365         struct nsproxy *old_ns = tsk->nsproxy;
14366 -       struct nsproxy *new_ns;
14367 +       struct nsproxy *new_ns = NULL;
14368         int err = 0;
14369  
14370 +       vxdprintk(VXD_CBIT(space, 7), "copy_namespaces(0x%08lx,%p[%p])",
14371 +               flags, tsk, old_ns);
14372 +
14373         if (!old_ns)
14374                 return 0;
14375  
14376 @@ -134,7 +180,7 @@ int copy_namespaces(unsigned long flags,
14377                                 CLONE_NEWPID | CLONE_NEWNET)))
14378                 return 0;
14379  
14380 -       if (!capable(CAP_SYS_ADMIN)) {
14381 +       if (!vx_can_unshare(CAP_SYS_ADMIN, flags)) {
14382                 err = -EPERM;
14383                 goto out;
14384         }
14385 @@ -161,6 +207,9 @@ int copy_namespaces(unsigned long flags,
14386  
14387  out:
14388         put_nsproxy(old_ns);
14389 +       vxdprintk(VXD_CBIT(space, 3),
14390 +               "copy_namespaces(0x%08lx,%p[%p]) = %d [%p]",
14391 +               flags, tsk, old_ns, err, new_ns);
14392         return err;
14393  }
14394  
14395 @@ -174,7 +223,9 @@ void free_nsproxy(struct nsproxy *ns)
14396                 put_ipc_ns(ns->ipc_ns);
14397         if (ns->pid_ns)
14398                 put_pid_ns(ns->pid_ns);
14399 -       put_net(ns->net_ns);
14400 +       if (ns->net_ns)
14401 +               put_net(ns->net_ns);
14402 +       atomic_dec(&vs_global_nsproxy);
14403         kmem_cache_free(nsproxy_cachep, ns);
14404  }
14405  
14406 @@ -187,11 +238,15 @@ int unshare_nsproxy_namespaces(unsigned 
14407  {
14408         int err = 0;
14409  
14410 +       vxdprintk(VXD_CBIT(space, 4),
14411 +               "unshare_nsproxy_namespaces(0x%08lx,[%p])",
14412 +               unshare_flags, current->nsproxy);
14413 +
14414         if (!(unshare_flags & (CLONE_NEWNS | CLONE_NEWUTS | CLONE_NEWIPC |
14415                                CLONE_NEWNET)))
14416                 return 0;
14417  
14418 -       if (!capable(CAP_SYS_ADMIN))
14419 +       if (!vx_can_unshare(CAP_SYS_ADMIN, unshare_flags))
14420                 return -EPERM;
14421  
14422         *new_nsp = create_new_namespaces(unshare_flags, current,
14423 diff -NurpP --minimal linux-3.6/kernel/pid.c linux-3.6-vs2.3.4.3-noxfs-nocow/kernel/pid.c
14424 --- linux-3.6/kernel/pid.c      2012-07-22 23:39:46.000000000 +0200
14425 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/kernel/pid.c        2012-10-04 18:47:00.000000000 +0200
14426 @@ -36,6 +36,7 @@
14427  #include <linux/pid_namespace.h>
14428  #include <linux/init_task.h>
14429  #include <linux/syscalls.h>
14430 +#include <linux/vs_pid.h>
14431  
14432  #define pid_hashfn(nr, ns)     \
14433         hash_long((unsigned long)nr + (unsigned long)ns, pidhash_shift)
14434 @@ -344,7 +345,7 @@ EXPORT_SYMBOL_GPL(find_pid_ns);
14435  
14436  struct pid *find_vpid(int nr)
14437  {
14438 -       return find_pid_ns(nr, current->nsproxy->pid_ns);
14439 +       return find_pid_ns(vx_rmap_pid(nr), current->nsproxy->pid_ns);
14440  }
14441  EXPORT_SYMBOL_GPL(find_vpid);
14442  
14443 @@ -404,6 +405,9 @@ void transfer_pid(struct task_struct *ol
14444  struct task_struct *pid_task(struct pid *pid, enum pid_type type)
14445  {
14446         struct task_struct *result = NULL;
14447 +
14448 +       if (type == PIDTYPE_REALPID)
14449 +               type = PIDTYPE_PID;
14450         if (pid) {
14451                 struct hlist_node *first;
14452                 first = rcu_dereference_check(hlist_first_rcu(&pid->tasks[type]),
14453 @@ -423,7 +427,7 @@ struct task_struct *find_task_by_pid_ns(
14454         rcu_lockdep_assert(rcu_read_lock_held(),
14455                            "find_task_by_pid_ns() needs rcu_read_lock()"
14456                            " protection");
14457 -       return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
14458 +       return pid_task(find_pid_ns(vx_rmap_pid(nr), ns), PIDTYPE_PID);
14459  }
14460  
14461  struct task_struct *find_task_by_vpid(pid_t vnr)
14462 @@ -467,7 +471,7 @@ struct pid *find_get_pid(pid_t nr)
14463  }
14464  EXPORT_SYMBOL_GPL(find_get_pid);
14465  
14466 -pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns)
14467 +pid_t pid_unmapped_nr_ns(struct pid *pid, struct pid_namespace *ns)
14468  {
14469         struct upid *upid;
14470         pid_t nr = 0;
14471 @@ -480,6 +484,11 @@ pid_t pid_nr_ns(struct pid *pid, struct 
14472         return nr;
14473  }
14474  
14475 +pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns)
14476 +{
14477 +       return vx_map_pid(pid_unmapped_nr_ns(pid, ns));
14478 +}
14479 +
14480  pid_t pid_vnr(struct pid *pid)
14481  {
14482         return pid_nr_ns(pid, current->nsproxy->pid_ns);
14483 diff -NurpP --minimal linux-3.6/kernel/pid_namespace.c linux-3.6-vs2.3.4.3-noxfs-nocow/kernel/pid_namespace.c
14484 --- linux-3.6/kernel/pid_namespace.c    2012-10-04 15:27:48.000000000 +0200
14485 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/kernel/pid_namespace.c      2012-10-04 18:47:00.000000000 +0200
14486 @@ -16,6 +16,7 @@
14487  #include <linux/slab.h>
14488  #include <linux/proc_fs.h>
14489  #include <linux/reboot.h>
14490 +#include <linux/vserver/global.h>
14491  
14492  #define BITS_PER_PAGE          (PAGE_SIZE*8)
14493  
14494 @@ -89,6 +90,7 @@ static struct pid_namespace *create_pid_
14495                 goto out_free_map;
14496  
14497         kref_init(&ns->kref);
14498 +       atomic_inc(&vs_global_pid_ns);
14499         ns->level = level;
14500         ns->parent = get_pid_ns(parent_pid_ns);
14501  
14502 @@ -120,6 +122,7 @@ static void destroy_pid_namespace(struct
14503  
14504         for (i = 0; i < PIDMAP_ENTRIES; i++)
14505                 kfree(ns->pidmap[i].page);
14506 +       atomic_dec(&vs_global_pid_ns);
14507         kmem_cache_free(pid_ns_cachep, ns);
14508  }
14509  
14510 diff -NurpP --minimal linux-3.6/kernel/posix-timers.c linux-3.6-vs2.3.4.3-noxfs-nocow/kernel/posix-timers.c
14511 --- linux-3.6/kernel/posix-timers.c     2012-01-09 16:15:00.000000000 +0100
14512 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/kernel/posix-timers.c       2012-10-04 18:47:00.000000000 +0200
14513 @@ -47,6 +47,7 @@
14514  #include <linux/wait.h>
14515  #include <linux/workqueue.h>
14516  #include <linux/export.h>
14517 +#include <linux/vs_context.h>
14518  
14519  /*
14520   * Management arrays for POSIX timers.  Timers are kept in slab memory
14521 @@ -340,6 +341,7 @@ int posix_timer_event(struct k_itimer *t
14522  {
14523         struct task_struct *task;
14524         int shared, ret = -1;
14525 +
14526         /*
14527          * FIXME: if ->sigq is queued we can race with
14528          * dequeue_signal()->do_schedule_next_timer().
14529 @@ -356,10 +358,18 @@ int posix_timer_event(struct k_itimer *t
14530         rcu_read_lock();
14531         task = pid_task(timr->it_pid, PIDTYPE_PID);
14532         if (task) {
14533 +               struct vx_info_save vxis;
14534 +               struct vx_info *vxi;
14535 +
14536 +               vxi = get_vx_info(task->vx_info);
14537 +               enter_vx_info(vxi, &vxis);
14538                 shared = !(timr->it_sigev_notify & SIGEV_THREAD_ID);
14539                 ret = send_sigqueue(timr->sigq, task, shared);
14540 +               leave_vx_info(&vxis);
14541 +               put_vx_info(vxi);
14542         }
14543         rcu_read_unlock();
14544 +
14545         /* If we failed to send the signal the timer stops. */
14546         return ret > 0;
14547  }
14548 diff -NurpP --minimal linux-3.6/kernel/printk.c linux-3.6-vs2.3.4.3-noxfs-nocow/kernel/printk.c
14549 --- linux-3.6/kernel/printk.c   2012-10-04 15:27:48.000000000 +0200
14550 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/kernel/printk.c     2012-10-04 18:47:00.000000000 +0200
14551 @@ -42,6 +42,7 @@
14552  #include <linux/notifier.h>
14553  #include <linux/rculist.h>
14554  #include <linux/poll.h>
14555 +#include <linux/vs_cvirt.h>
14556  
14557  #include <asm/uaccess.h>
14558  
14559 @@ -818,7 +819,7 @@ static int check_syslog_permissions(int 
14560                 return 0;
14561  
14562         if (syslog_action_restricted(type)) {
14563 -               if (capable(CAP_SYSLOG))
14564 +               if (vx_capable(CAP_SYSLOG, VXC_SYSLOG))
14565                         return 0;
14566                 /* For historical reasons, accept CAP_SYS_ADMIN too, with a warning */
14567                 if (capable(CAP_SYS_ADMIN)) {
14568 @@ -1111,12 +1112,9 @@ int do_syslog(int type, char __user *buf
14569         if (error)
14570                 return error;
14571  
14572 -       switch (type) {
14573 -       case SYSLOG_ACTION_CLOSE:       /* Close log */
14574 -               break;
14575 -       case SYSLOG_ACTION_OPEN:        /* Open log */
14576 -               break;
14577 -       case SYSLOG_ACTION_READ:        /* Read from log */
14578 +       if ((type == SYSLOG_ACTION_READ) ||
14579 +           (type == SYSLOG_ACTION_READ_ALL) ||
14580 +           (type == SYSLOG_ACTION_READ_CLEAR)) {
14581                 error = -EINVAL;
14582                 if (!buf || len < 0)
14583                         goto out;
14584 @@ -1127,6 +1125,16 @@ int do_syslog(int type, char __user *buf
14585                         error = -EFAULT;
14586                         goto out;
14587                 }
14588 +       }
14589 +       if (!vx_check(0, VS_ADMIN|VS_WATCH))
14590 +               return vx_do_syslog(type, buf, len);
14591 +
14592 +       switch (type) {
14593 +       case SYSLOG_ACTION_CLOSE:       /* Close log */
14594 +               break;
14595 +       case SYSLOG_ACTION_OPEN:        /* Open log */
14596 +               break;
14597 +       case SYSLOG_ACTION_READ:        /* Read from log */
14598                 error = wait_event_interruptible(log_wait,
14599                                                  syslog_seq != log_next_seq);
14600                 if (error)
14601 @@ -1139,16 +1147,6 @@ int do_syslog(int type, char __user *buf
14602                 /* FALL THRU */
14603         /* Read last kernel messages */
14604         case SYSLOG_ACTION_READ_ALL:
14605 -               error = -EINVAL;
14606 -               if (!buf || len < 0)
14607 -                       goto out;
14608 -               error = 0;
14609 -               if (!len)
14610 -                       goto out;
14611 -               if (!access_ok(VERIFY_WRITE, buf, len)) {
14612 -                       error = -EFAULT;
14613 -                       goto out;
14614 -               }
14615                 error = syslog_print_all(buf, len, clear);
14616                 break;
14617         /* Clear ring buffer */
14618 diff -NurpP --minimal linux-3.6/kernel/ptrace.c linux-3.6-vs2.3.4.3-noxfs-nocow/kernel/ptrace.c
14619 --- linux-3.6/kernel/ptrace.c   2012-07-22 23:39:46.000000000 +0200
14620 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/kernel/ptrace.c     2012-10-04 18:47:00.000000000 +0200
14621 @@ -22,6 +22,7 @@
14622  #include <linux/syscalls.h>
14623  #include <linux/uaccess.h>
14624  #include <linux/regset.h>
14625 +#include <linux/vs_context.h>
14626  #include <linux/hw_breakpoint.h>
14627  #include <linux/cn_proc.h>
14628  
14629 @@ -216,6 +217,11 @@ ok:
14630                 dumpable = get_dumpable(task->mm);
14631         if (!dumpable  && !ptrace_has_cap(task_user_ns(task), mode))
14632                 return -EPERM;
14633 +       if (!vx_check(task->xid, VS_ADMIN_P|VS_WATCH_P|VS_IDENT))
14634 +               return -EPERM;
14635 +       if (!vx_check(task->xid, VS_IDENT) &&
14636 +               !task_vx_flags(task, VXF_STATE_ADMIN, 0))
14637 +               return -EACCES;
14638  
14639         return security_ptrace_access_check(task, mode);
14640  }
14641 diff -NurpP --minimal linux-3.6/kernel/sched/core.c linux-3.6-vs2.3.4.3-noxfs-nocow/kernel/sched/core.c
14642 --- linux-3.6/kernel/sched/core.c       2012-10-04 15:27:48.000000000 +0200
14643 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/kernel/sched/core.c 2012-10-04 18:47:00.000000000 +0200
14644 @@ -72,6 +72,8 @@
14645  #include <linux/slab.h>
14646  #include <linux/init_task.h>
14647  #include <linux/binfmts.h>
14648 +#include <linux/vs_sched.h>
14649 +#include <linux/vs_cvirt.h>
14650  
14651  #include <asm/switch_to.h>
14652  #include <asm/tlb.h>
14653 @@ -2223,9 +2225,17 @@ EXPORT_SYMBOL(avenrun); /* should be rem
14654   */
14655  void get_avenrun(unsigned long *loads, unsigned long offset, int shift)
14656  {
14657 -       loads[0] = (avenrun[0] + offset) << shift;
14658 -       loads[1] = (avenrun[1] + offset) << shift;
14659 -       loads[2] = (avenrun[2] + offset) << shift;
14660 +       if (vx_flags(VXF_VIRT_LOAD, 0)) {
14661 +               struct vx_info *vxi = current_vx_info();
14662 +
14663 +               loads[0] = (vxi->cvirt.load[0] + offset) << shift;
14664 +               loads[1] = (vxi->cvirt.load[1] + offset) << shift;
14665 +               loads[2] = (vxi->cvirt.load[2] + offset) << shift;
14666 +       } else {
14667 +               loads[0] = (avenrun[0] + offset) << shift;
14668 +               loads[1] = (avenrun[1] + offset) << shift;
14669 +               loads[2] = (avenrun[2] + offset) << shift;
14670 +       }
14671  }
14672  
14673  static long calc_load_fold_active(struct rq *this_rq)
14674 @@ -2854,14 +2864,17 @@ static inline void task_group_account_fi
14675  void account_user_time(struct task_struct *p, cputime_t cputime,
14676                        cputime_t cputime_scaled)
14677  {
14678 +       struct vx_info *vxi = p->vx_info;  /* p is _always_ current */
14679 +       int nice = (TASK_NICE(p) > 0);
14680         int index;
14681  
14682         /* Add user time to process. */
14683         p->utime += cputime;
14684         p->utimescaled += cputime_scaled;
14685 +       vx_account_user(vxi, cputime, nice);
14686         account_group_user_time(p, cputime);
14687  
14688 -       index = (TASK_NICE(p) > 0) ? CPUTIME_NICE : CPUTIME_USER;
14689 +       index = (nice) ? CPUTIME_NICE : CPUTIME_USER;
14690  
14691         /* Add user time to cpustat. */
14692         task_group_account_field(p, index, (__force u64) cputime);
14693 @@ -2908,9 +2921,12 @@ static inline
14694  void __account_system_time(struct task_struct *p, cputime_t cputime,
14695                         cputime_t cputime_scaled, int index)
14696  {
14697 +       struct vx_info *vxi = p->vx_info;  /* p is _always_ current */
14698 +
14699         /* Add system time to process. */
14700         p->stime += cputime;
14701         p->stimescaled += cputime_scaled;
14702 +       vx_account_system(vxi, cputime, 0 /* do we have idle time? */);
14703         account_group_system_time(p, cputime);
14704  
14705         /* Add system time to cpustat. */
14706 @@ -4137,7 +4153,7 @@ SYSCALL_DEFINE1(nice, int, increment)
14707                 nice = 19;
14708  
14709         if (increment < 0 && !can_nice(current, nice))
14710 -               return -EPERM;
14711 +               return vx_flags(VXF_IGNEG_NICE, 0) ? 0 : -EPERM;
14712  
14713         retval = security_task_setnice(current, nice);
14714         if (retval)
14715 diff -NurpP --minimal linux-3.6/kernel/sched/fair.c linux-3.6-vs2.3.4.3-noxfs-nocow/kernel/sched/fair.c
14716 --- linux-3.6/kernel/sched/fair.c       2012-10-04 15:27:48.000000000 +0200
14717 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/kernel/sched/fair.c 2012-10-04 18:47:00.000000000 +0200
14718 @@ -26,6 +26,7 @@
14719  #include <linux/slab.h>
14720  #include <linux/profile.h>
14721  #include <linux/interrupt.h>
14722 +#include <linux/vs_cvirt.h>
14723  
14724  #include <trace/events/sched.h>
14725  
14726 @@ -1111,6 +1112,8 @@ enqueue_entity(struct cfs_rq *cfs_rq, st
14727                 __enqueue_entity(cfs_rq, se);
14728         se->on_rq = 1;
14729  
14730 +       if (entity_is_task(se))
14731 +               vx_activate_task(task_of(se));
14732         if (cfs_rq->nr_running == 1) {
14733                 list_add_leaf_cfs_rq(cfs_rq);
14734                 check_enqueue_throttle(cfs_rq);
14735 @@ -1191,6 +1194,8 @@ dequeue_entity(struct cfs_rq *cfs_rq, st
14736         if (se != cfs_rq->curr)
14737                 __dequeue_entity(cfs_rq, se);
14738         se->on_rq = 0;
14739 +       if (entity_is_task(se))
14740 +               vx_deactivate_task(task_of(se));
14741         update_cfs_load(cfs_rq, 0);
14742         account_entity_dequeue(cfs_rq, se);
14743  
14744 diff -NurpP --minimal linux-3.6/kernel/signal.c linux-3.6-vs2.3.4.3-noxfs-nocow/kernel/signal.c
14745 --- linux-3.6/kernel/signal.c   2012-10-04 15:27:48.000000000 +0200
14746 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/kernel/signal.c     2012-10-04 18:47:00.000000000 +0200
14747 @@ -30,6 +30,8 @@
14748  #include <linux/nsproxy.h>
14749  #include <linux/user_namespace.h>
14750  #include <linux/uprobes.h>
14751 +#include <linux/vs_context.h>
14752 +#include <linux/vs_pid.h>
14753  #define CREATE_TRACE_POINTS
14754  #include <trace/events/signal.h>
14755  
14756 @@ -790,9 +792,18 @@ static int check_kill_permission(int sig
14757         struct pid *sid;
14758         int error;
14759  
14760 +       vxdprintk(VXD_CBIT(misc, 7),
14761 +               "check_kill_permission(%d,%p,%p[#%u,%u])",
14762 +               sig, info, t, vx_task_xid(t), t->pid);
14763 +
14764         if (!valid_signal(sig))
14765                 return -EINVAL;
14766  
14767 +/*     FIXME: needed? if so, why?
14768 +       if ((info != SEND_SIG_NOINFO) &&
14769 +               (is_si_special(info) || !si_fromuser(info)))
14770 +               goto skip;      */
14771 +
14772         if (!si_fromuser(info))
14773                 return 0;
14774  
14775 @@ -816,6 +827,20 @@ static int check_kill_permission(int sig
14776                 }
14777         }
14778  
14779 +       error = -EPERM;
14780 +       if (t->pid == 1 && current->xid)
14781 +               return error;
14782 +
14783 +       error = -ESRCH;
14784 +       /* FIXME: we shouldn't return ESRCH ever, to avoid
14785 +                 loops, maybe ENOENT or EACCES? */
14786 +       if (!vx_check(vx_task_xid(t), VS_WATCH_P | VS_IDENT)) {
14787 +               vxdprintk(current->xid || VXD_CBIT(misc, 7),
14788 +                       "signal %d[%p] xid mismatch %p[#%u,%u] xid=#%u",
14789 +                       sig, info, t, vx_task_xid(t), t->pid, current->xid);
14790 +               return error;
14791 +       }
14792 +/* skip: */
14793         return security_task_kill(t, info, sig, 0);
14794  }
14795  
14796 @@ -1351,7 +1376,7 @@ int kill_pid_info(int sig, struct siginf
14797         rcu_read_lock();
14798  retry:
14799         p = pid_task(pid, PIDTYPE_PID);
14800 -       if (p) {
14801 +       if (p && vx_check(vx_task_xid(p), VS_IDENT)) {
14802                 error = group_send_sig_info(sig, info, p);
14803                 if (unlikely(error == -ESRCH))
14804                         /*
14805 @@ -1399,7 +1424,7 @@ int kill_pid_info_as_cred(int sig, struc
14806  
14807         rcu_read_lock();
14808         p = pid_task(pid, PIDTYPE_PID);
14809 -       if (!p) {
14810 +       if (!p || !vx_check(vx_task_xid(p), VS_IDENT)) {
14811                 ret = -ESRCH;
14812                 goto out_unlock;
14813         }
14814 @@ -1451,8 +1476,10 @@ static int kill_something_info(int sig, 
14815                 struct task_struct * p;
14816  
14817                 for_each_process(p) {
14818 -                       if (task_pid_vnr(p) > 1 &&
14819 -                                       !same_thread_group(p, current)) {
14820 +                       if (vx_check(vx_task_xid(p), VS_ADMIN|VS_IDENT) &&
14821 +                               task_pid_vnr(p) > 1 &&
14822 +                               !same_thread_group(p, current) &&
14823 +                               !vx_current_initpid(p->pid)) {
14824                                 int err = group_send_sig_info(sig, info, p);
14825                                 ++count;
14826                                 if (err != -EPERM)
14827 @@ -2317,6 +2344,11 @@ relock:
14828                                 !sig_kernel_only(signr))
14829                         continue;
14830  
14831 +               /* virtual init is protected against user signals */
14832 +               if ((info->si_code == SI_USER) &&
14833 +                       vx_current_initpid(current->pid))
14834 +                       continue;
14835 +
14836                 if (sig_kernel_stop(signr)) {
14837                         /*
14838                          * The default action is to stop all threads in
14839 diff -NurpP --minimal linux-3.6/kernel/softirq.c linux-3.6-vs2.3.4.3-noxfs-nocow/kernel/softirq.c
14840 --- linux-3.6/kernel/softirq.c  2012-10-04 15:27:48.000000000 +0200
14841 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/kernel/softirq.c    2012-10-04 18:47:00.000000000 +0200
14842 @@ -24,6 +24,7 @@
14843  #include <linux/ftrace.h>
14844  #include <linux/smp.h>
14845  #include <linux/tick.h>
14846 +#include <linux/vs_context.h>
14847  
14848  #define CREATE_TRACE_POINTS
14849  #include <trace/events/irq.h>
14850 diff -NurpP --minimal linux-3.6/kernel/sys.c linux-3.6-vs2.3.4.3-noxfs-nocow/kernel/sys.c
14851 --- linux-3.6/kernel/sys.c      2012-10-04 15:27:48.000000000 +0200
14852 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/kernel/sys.c        2012-10-04 18:47:00.000000000 +0200
14853 @@ -47,6 +47,7 @@
14854  #include <linux/syscalls.h>
14855  #include <linux/kprobes.h>
14856  #include <linux/user_namespace.h>
14857 +#include <linux/vs_pid.h>
14858  
14859  #include <linux/kmsg_dump.h>
14860  /* Move somewhere else to avoid recompiling? */
14861 @@ -154,7 +155,10 @@ static int set_one_prio(struct task_stru
14862                 goto out;
14863         }
14864         if (niceval < task_nice(p) && !can_nice(p, niceval)) {
14865 -               error = -EACCES;
14866 +               if (vx_flags(VXF_IGNEG_NICE, 0))
14867 +                       error = 0;
14868 +               else
14869 +                       error = -EACCES;
14870                 goto out;
14871         }
14872         no_nice = security_task_setnice(p, niceval);
14873 @@ -205,6 +209,8 @@ SYSCALL_DEFINE3(setpriority, int, which,
14874                         else
14875                                 pgrp = task_pgrp(current);
14876                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
14877 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
14878 +                                       continue;
14879                                 error = set_one_prio(p, niceval, error);
14880                         } while_each_pid_thread(pgrp, PIDTYPE_PGID, p);
14881                         break;
14882 @@ -270,6 +276,8 @@ SYSCALL_DEFINE2(getpriority, int, which,
14883                         else
14884                                 pgrp = task_pgrp(current);
14885                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
14886 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
14887 +                                       continue;
14888                                 niceval = 20 - task_nice(p);
14889                                 if (niceval > retval)
14890                                         retval = niceval;
14891 @@ -421,6 +429,8 @@ EXPORT_SYMBOL_GPL(kernel_power_off);
14892  
14893  static DEFINE_MUTEX(reboot_mutex);
14894  
14895 +long vs_reboot(unsigned int, void __user *);
14896 +
14897  /*
14898   * Reboot system call: for obvious reasons only root may call it,
14899   * and even root needs to set up some magic numbers in the registers
14900 @@ -462,6 +472,9 @@ SYSCALL_DEFINE4(reboot, int, magic1, int
14901         if ((cmd == LINUX_REBOOT_CMD_POWER_OFF) && !pm_power_off)
14902                 cmd = LINUX_REBOOT_CMD_HALT;
14903  
14904 +       if (!vx_check(0, VS_ADMIN|VS_WATCH))
14905 +               return vs_reboot(cmd, arg);
14906 +
14907         mutex_lock(&reboot_mutex);
14908         switch (cmd) {
14909         case LINUX_REBOOT_CMD_RESTART:
14910 @@ -1367,7 +1380,8 @@ SYSCALL_DEFINE2(sethostname, char __user
14911         int errno;
14912         char tmp[__NEW_UTS_LEN];
14913  
14914 -       if (!ns_capable(current->nsproxy->uts_ns->user_ns, CAP_SYS_ADMIN))
14915 +       if (!vx_ns_capable(current->nsproxy->uts_ns->user_ns,
14916 +               CAP_SYS_ADMIN, VXC_SET_UTSNAME))
14917                 return -EPERM;
14918  
14919         if (len < 0 || len > __NEW_UTS_LEN)
14920 @@ -1418,7 +1432,8 @@ SYSCALL_DEFINE2(setdomainname, char __us
14921         int errno;
14922         char tmp[__NEW_UTS_LEN];
14923  
14924 -       if (!ns_capable(current->nsproxy->uts_ns->user_ns, CAP_SYS_ADMIN))
14925 +       if (!vx_ns_capable(current->nsproxy->uts_ns->user_ns,
14926 +               CAP_SYS_ADMIN, VXC_SET_UTSNAME))
14927                 return -EPERM;
14928         if (len < 0 || len > __NEW_UTS_LEN)
14929                 return -EINVAL;
14930 @@ -1537,7 +1552,7 @@ int do_prlimit(struct task_struct *tsk, 
14931                 /* Keep the capable check against init_user_ns until
14932                    cgroups can contain all limits */
14933                 if (new_rlim->rlim_max > rlim->rlim_max &&
14934 -                               !capable(CAP_SYS_RESOURCE))
14935 +                       !vx_capable(CAP_SYS_RESOURCE, VXC_SET_RLIMIT))
14936                         retval = -EPERM;
14937                 if (!retval)
14938                         retval = security_task_setrlimit(tsk->group_leader,
14939 @@ -1590,7 +1605,8 @@ static int check_prlimit_permission(stru
14940             gid_eq(cred->gid, tcred->sgid) &&
14941             gid_eq(cred->gid, tcred->gid))
14942                 return 0;
14943 -       if (ns_capable(tcred->user_ns, CAP_SYS_RESOURCE))
14944 +       if (vx_ns_capable(tcred->user_ns,
14945 +               CAP_SYS_RESOURCE, VXC_SET_RLIMIT))
14946                 return 0;
14947  
14948         return -EPERM;
14949 diff -NurpP --minimal linux-3.6/kernel/sysctl.c linux-3.6-vs2.3.4.3-noxfs-nocow/kernel/sysctl.c
14950 --- linux-3.6/kernel/sysctl.c   2012-10-04 15:27:48.000000000 +0200
14951 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/kernel/sysctl.c     2012-10-04 18:47:00.000000000 +0200
14952 @@ -82,6 +82,7 @@
14953  #if defined(CONFIG_PROVE_LOCKING) || defined(CONFIG_LOCK_STAT)
14954  #include <linux/lockdep.h>
14955  #endif
14956 +extern char vshelper_path[];
14957  #ifdef CONFIG_CHR_DEV_SG
14958  #include <scsi/sg.h>
14959  #endif
14960 @@ -568,6 +569,13 @@ static struct ctl_table kern_table[] = {
14961                 .proc_handler   = proc_dostring,
14962         },
14963  #endif
14964 +       {
14965 +               .procname       = "vshelper",
14966 +               .data           = &vshelper_path,
14967 +               .maxlen         = 256,
14968 +               .mode           = 0644,
14969 +               .proc_handler   = &proc_dostring,
14970 +       },
14971  #ifdef CONFIG_CHR_DEV_SG
14972         {
14973                 .procname       = "sg-big-buff",
14974 diff -NurpP --minimal linux-3.6/kernel/sysctl_binary.c linux-3.6-vs2.3.4.3-noxfs-nocow/kernel/sysctl_binary.c
14975 --- linux-3.6/kernel/sysctl_binary.c    2012-10-04 15:27:48.000000000 +0200
14976 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/kernel/sysctl_binary.c      2012-10-04 18:47:00.000000000 +0200
14977 @@ -73,6 +73,7 @@ static const struct bin_table bin_kern_t
14978  
14979         { CTL_INT,      KERN_PANIC,                     "panic" },
14980         { CTL_INT,      KERN_REALROOTDEV,               "real-root-dev" },
14981 +       { CTL_STR,      KERN_VSHELPER,                  "vshelper" },
14982  
14983         { CTL_STR,      KERN_SPARC_REBOOT,              "reboot-cmd" },
14984         { CTL_INT,      KERN_CTLALTDEL,                 "ctrl-alt-del" },
14985 diff -NurpP --minimal linux-3.6/kernel/time/timekeeping.c linux-3.6-vs2.3.4.3-noxfs-nocow/kernel/time/timekeeping.c
14986 --- linux-3.6/kernel/time/timekeeping.c 2012-10-04 15:27:48.000000000 +0200
14987 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/kernel/time/timekeeping.c   2012-10-04 18:47:00.000000000 +0200
14988 @@ -309,6 +309,7 @@ void getnstimeofday(struct timespec *ts)
14989  
14990         ts->tv_nsec = 0;
14991         timespec_add_ns(ts, nsecs);
14992 +       vx_adjust_timespec(ts);
14993  }
14994  EXPORT_SYMBOL(getnstimeofday);
14995  
14996 diff -NurpP --minimal linux-3.6/kernel/time.c linux-3.6-vs2.3.4.3-noxfs-nocow/kernel/time.c
14997 --- linux-3.6/kernel/time.c     2012-05-21 18:07:34.000000000 +0200
14998 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/kernel/time.c       2012-10-04 18:47:00.000000000 +0200
14999 @@ -92,7 +92,7 @@ SYSCALL_DEFINE1(stime, time_t __user *, 
15000         if (err)
15001                 return err;
15002  
15003 -       do_settimeofday(&tv);
15004 +       vx_settimeofday(&tv);
15005         return 0;
15006  }
15007  
15008 @@ -172,7 +172,7 @@ int do_sys_settimeofday(const struct tim
15009                 }
15010         }
15011         if (tv)
15012 -               return do_settimeofday(tv);
15013 +               return vx_settimeofday(tv);
15014         return 0;
15015  }
15016  
15017 diff -NurpP --minimal linux-3.6/kernel/timer.c linux-3.6-vs2.3.4.3-noxfs-nocow/kernel/timer.c
15018 --- linux-3.6/kernel/timer.c    2012-10-04 15:27:48.000000000 +0200
15019 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/kernel/timer.c      2012-10-09 14:02:12.000000000 +0200
15020 @@ -40,6 +40,10 @@
15021  #include <linux/irq_work.h>
15022  #include <linux/sched.h>
15023  #include <linux/slab.h>
15024 +#include <linux/vs_base.h>
15025 +#include <linux/vs_cvirt.h>
15026 +#include <linux/vs_pid.h>
15027 +#include <linux/vserver/sched.h>
15028  
15029  #include <asm/uaccess.h>
15030  #include <asm/unistd.h>
15031 diff -NurpP --minimal linux-3.6/kernel/user_namespace.c linux-3.6-vs2.3.4.3-noxfs-nocow/kernel/user_namespace.c
15032 --- linux-3.6/kernel/user_namespace.c   2012-07-22 23:39:47.000000000 +0200
15033 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/kernel/user_namespace.c     2012-10-04 18:47:00.000000000 +0200
15034 @@ -19,6 +19,7 @@
15035  #include <linux/fs.h>
15036  #include <linux/uaccess.h>
15037  #include <linux/ctype.h>
15038 +#include <linux/vserver/global.h>
15039  
15040  static struct kmem_cache *user_ns_cachep __read_mostly;
15041  
15042 @@ -52,6 +53,7 @@ int create_user_ns(struct cred *new)
15043                 return -ENOMEM;
15044  
15045         kref_init(&ns->kref);
15046 +       atomic_inc(&vs_global_user_ns);
15047         ns->parent = parent_ns;
15048         ns->owner = owner;
15049         ns->group = group;
15050 @@ -84,6 +86,9 @@ void free_user_ns(struct kref *kref)
15051  
15052         parent = ns->parent;
15053         kmem_cache_free(user_ns_cachep, ns);
15054 +
15055 +       /* FIXME: maybe move into destroyer? */
15056 +       atomic_dec(&vs_global_user_ns);
15057         put_user_ns(parent);
15058  }
15059  EXPORT_SYMBOL(free_user_ns);
15060 diff -NurpP --minimal linux-3.6/kernel/utsname.c linux-3.6-vs2.3.4.3-noxfs-nocow/kernel/utsname.c
15061 --- linux-3.6/kernel/utsname.c  2012-07-22 23:39:47.000000000 +0200
15062 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/kernel/utsname.c    2012-10-04 18:47:00.000000000 +0200
15063 @@ -16,14 +16,17 @@
15064  #include <linux/slab.h>
15065  #include <linux/user_namespace.h>
15066  #include <linux/proc_fs.h>
15067 +#include <linux/vserver/global.h>
15068  
15069  static struct uts_namespace *create_uts_ns(void)
15070  {
15071         struct uts_namespace *uts_ns;
15072  
15073         uts_ns = kmalloc(sizeof(struct uts_namespace), GFP_KERNEL);
15074 -       if (uts_ns)
15075 +       if (uts_ns) {
15076                 kref_init(&uts_ns->kref);
15077 +               atomic_inc(&vs_global_uts_ns);
15078 +       }
15079         return uts_ns;
15080  }
15081  
15082 @@ -32,8 +35,8 @@ static struct uts_namespace *create_uts_
15083   * @old_ns: namespace to clone
15084   * Return NULL on error (failure to kmalloc), new ns otherwise
15085   */
15086 -static struct uts_namespace *clone_uts_ns(struct task_struct *tsk,
15087 -                                         struct uts_namespace *old_ns)
15088 +static struct uts_namespace *clone_uts_ns(struct uts_namespace *old_ns,
15089 +                                         struct user_namespace *old_user)
15090  {
15091         struct uts_namespace *ns;
15092  
15093 @@ -43,7 +46,7 @@ static struct uts_namespace *clone_uts_n
15094  
15095         down_read(&uts_sem);
15096         memcpy(&ns->name, &old_ns->name, sizeof(ns->name));
15097 -       ns->user_ns = get_user_ns(task_cred_xxx(tsk, user_ns));
15098 +       ns->user_ns = get_user_ns(old_user);
15099         up_read(&uts_sem);
15100         return ns;
15101  }
15102 @@ -55,9 +58,9 @@ static struct uts_namespace *clone_uts_n
15103   * versa.
15104   */
15105  struct uts_namespace *copy_utsname(unsigned long flags,
15106 -                                  struct task_struct *tsk)
15107 +                                  struct uts_namespace *old_ns,
15108 +                                  struct user_namespace *user_ns)
15109  {
15110 -       struct uts_namespace *old_ns = tsk->nsproxy->uts_ns;
15111         struct uts_namespace *new_ns;
15112  
15113         BUG_ON(!old_ns);
15114 @@ -66,7 +69,7 @@ struct uts_namespace *copy_utsname(unsig
15115         if (!(flags & CLONE_NEWUTS))
15116                 return old_ns;
15117  
15118 -       new_ns = clone_uts_ns(tsk, old_ns);
15119 +       new_ns = clone_uts_ns(old_ns, user_ns);
15120  
15121         put_uts_ns(old_ns);
15122         return new_ns;
15123 @@ -78,6 +81,7 @@ void free_uts_ns(struct kref *kref)
15124  
15125         ns = container_of(kref, struct uts_namespace, kref);
15126         put_user_ns(ns->user_ns);
15127 +       atomic_dec(&vs_global_uts_ns);
15128         kfree(ns);
15129  }
15130  
15131 diff -NurpP --minimal linux-3.6/kernel/vserver/Kconfig linux-3.6-vs2.3.4.3-noxfs-nocow/kernel/vserver/Kconfig
15132 --- linux-3.6/kernel/vserver/Kconfig    1970-01-01 01:00:00.000000000 +0100
15133 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/kernel/vserver/Kconfig      2012-10-04 18:47:00.000000000 +0200
15134 @@ -0,0 +1,224 @@
15135 +#
15136 +# Linux VServer configuration
15137 +#
15138 +
15139 +menu "Linux VServer"
15140 +
15141 +config VSERVER_AUTO_LBACK
15142 +       bool    "Automatically Assign Loopback IP"
15143 +       default y
15144 +       help
15145 +         Automatically assign a guest specific loopback
15146 +         IP and add it to the kernel network stack on
15147 +         startup.
15148 +
15149 +config VSERVER_AUTO_SINGLE
15150 +       bool    "Automatic Single IP Special Casing"
15151 +       depends on EXPERIMENTAL
15152 +       default y
15153 +       help
15154 +         This allows network contexts with a single IP to
15155 +         automatically remap 0.0.0.0 bindings to that IP,
15156 +         avoiding further network checks and improving
15157 +         performance.
15158 +
15159 +         (note: such guests do not allow to change the ip
15160 +          on the fly and do not show loopback addresses)
15161 +
15162 +config VSERVER_COWBL
15163 +       bool    "Enable COW Immutable Link Breaking"
15164 +       default y
15165 +       help
15166 +         This enables the COW (Copy-On-Write) link break code.
15167 +         It allows you to treat unified files like normal files
15168 +         when writing to them (which will implicitely break the
15169 +         link and create a copy of the unified file)
15170 +
15171 +config VSERVER_VTIME
15172 +       bool    "Enable Virtualized Guest Time"
15173 +       depends on EXPERIMENTAL
15174 +       default n
15175 +       help
15176 +         This enables per guest time offsets to allow for
15177 +         adjusting the system clock individually per guest.
15178 +         this adds some overhead to the time functions and
15179 +         therefore should not be enabled without good reason.
15180 +
15181 +config VSERVER_DEVICE
15182 +       bool    "Enable Guest Device Mapping"
15183 +       depends on EXPERIMENTAL
15184 +       default n
15185 +       help
15186 +         This enables generic device remapping.
15187 +
15188 +config VSERVER_PROC_SECURE
15189 +       bool    "Enable Proc Security"
15190 +       depends on PROC_FS
15191 +       default y
15192 +       help
15193 +         This configures ProcFS security to initially hide
15194 +         non-process entries for all contexts except the main and
15195 +         spectator context (i.e. for all guests), which is a secure
15196 +         default.
15197 +
15198 +         (note: on 1.2x the entries were visible by default)
15199 +
15200 +choice
15201 +       prompt  "Persistent Inode Tagging"
15202 +       default TAGGING_ID24
15203 +       help
15204 +         This adds persistent context information to filesystems
15205 +         mounted with the tagxid option. Tagging is a requirement
15206 +         for per-context disk limits and per-context quota.
15207 +
15208 +
15209 +config TAGGING_NONE
15210 +       bool    "Disabled"
15211 +       help
15212 +         do not store per-context information in inodes.
15213 +
15214 +config TAGGING_UID16
15215 +       bool    "UID16/GID32"
15216 +       help
15217 +         reduces UID to 16 bit, but leaves GID at 32 bit.
15218 +
15219 +config TAGGING_GID16
15220 +       bool    "UID32/GID16"
15221 +       help
15222 +         reduces GID to 16 bit, but leaves UID at 32 bit.
15223 +
15224 +config TAGGING_ID24
15225 +       bool    "UID24/GID24"
15226 +       help
15227 +         uses the upper 8bit from UID and GID for XID tagging
15228 +         which leaves 24bit for UID/GID each, which should be
15229 +         more than sufficient for normal use.
15230 +
15231 +config TAGGING_INTERN
15232 +       bool    "UID32/GID32"
15233 +       help
15234 +         this uses otherwise reserved inode fields in the on
15235 +         disk representation, which limits the use to a few
15236 +         filesystems (currently ext2 and ext3)
15237 +
15238 +endchoice
15239 +
15240 +config TAG_NFSD
15241 +       bool    "Tag NFSD User Auth and Files"
15242 +       default n
15243 +       help
15244 +         Enable this if you do want the in-kernel NFS
15245 +         Server to use the tagging specified above.
15246 +         (will require patched clients too)
15247 +
15248 +config VSERVER_PRIVACY
15249 +       bool    "Honor Privacy Aspects of Guests"
15250 +       default n
15251 +       help
15252 +         When enabled, most context checks will disallow
15253 +         access to structures assigned to a specific context,
15254 +         like ptys or loop devices.
15255 +
15256 +config VSERVER_CONTEXTS
15257 +       int     "Maximum number of Contexts (1-65533)"  if EMBEDDED
15258 +       range 1 65533
15259 +       default "768"   if 64BIT
15260 +       default "256"
15261 +       help
15262 +         This setting will optimize certain data structures
15263 +         and memory allocations according to the expected
15264 +         maximum.
15265 +
15266 +         note: this is not a strict upper limit.
15267 +
15268 +config VSERVER_WARN
15269 +       bool    "VServer Warnings"
15270 +       default y
15271 +       help
15272 +         This enables various runtime warnings, which will
15273 +         notify about potential manipulation attempts or
15274 +         resource shortage. It is generally considered to
15275 +         be a good idea to have that enabled.
15276 +
15277 +config VSERVER_WARN_DEVPTS
15278 +       bool    "VServer DevPTS Warnings"
15279 +       depends on VSERVER_WARN
15280 +       default y
15281 +       help
15282 +         This enables DevPTS related warnings, issued when a
15283 +         process inside a context tries to lookup or access
15284 +         a dynamic pts from the host or a different context.
15285 +
15286 +config VSERVER_DEBUG
15287 +       bool    "VServer Debugging Code"
15288 +       default n
15289 +       help
15290 +         Set this to yes if you want to be able to activate
15291 +         debugging output at runtime. It adds a very small
15292 +         overhead to all vserver related functions and
15293 +         increases the kernel size by about 20k.
15294 +
15295 +config VSERVER_HISTORY
15296 +       bool    "VServer History Tracing"
15297 +       depends on VSERVER_DEBUG
15298 +       default n
15299 +       help
15300 +         Set this to yes if you want to record the history of
15301 +         linux-vserver activities, so they can be replayed in
15302 +         the event of a kernel panic or oops.
15303 +
15304 +config VSERVER_HISTORY_SIZE
15305 +       int     "Per-CPU History Size (32-65536)"
15306 +       depends on VSERVER_HISTORY
15307 +       range 32 65536
15308 +       default 64
15309 +       help
15310 +         This allows you to specify the number of entries in
15311 +         the per-CPU history buffer.
15312 +
15313 +choice
15314 +       prompt  "Quotes used in debug and warn messages"
15315 +       default QUOTES_ISO8859
15316 +
15317 +config QUOTES_ISO8859
15318 +       bool    "Extended ASCII (ISO 8859) angle quotes"
15319 +       help
15320 +         This uses the extended ASCII characters \xbb
15321 +         and \xab for quoting file and process names.
15322 +
15323 +config QUOTES_UTF8
15324 +       bool    "UTF-8 angle quotes"
15325 +       help
15326 +         This uses the the UTF-8 sequences for angle
15327 +         quotes to quote file and process names.
15328 +
15329 +config QUOTES_ASCII
15330 +       bool    "ASCII single quotes"
15331 +       help
15332 +         This uses the ASCII single quote character
15333 +         (\x27) to quote file and process names.
15334 +
15335 +endchoice
15336 +
15337 +endmenu
15338 +
15339 +
15340 +config VSERVER
15341 +       bool
15342 +       default y
15343 +       select NAMESPACES
15344 +       select UTS_NS
15345 +       select IPC_NS
15346 +#      select USER_NS
15347 +       select SYSVIPC
15348 +
15349 +config VSERVER_SECURITY
15350 +       bool
15351 +       depends on SECURITY
15352 +       default y
15353 +       select SECURITY_CAPABILITIES
15354 +
15355 +config VSERVER_DISABLED
15356 +       bool
15357 +       default n
15358 +
15359 diff -NurpP --minimal linux-3.6/kernel/vserver/Makefile linux-3.6-vs2.3.4.3-noxfs-nocow/kernel/vserver/Makefile
15360 --- linux-3.6/kernel/vserver/Makefile   1970-01-01 01:00:00.000000000 +0100
15361 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/kernel/vserver/Makefile     2012-10-04 18:47:00.000000000 +0200
15362 @@ -0,0 +1,18 @@
15363 +#
15364 +# Makefile for the Linux vserver routines.
15365 +#
15366 +
15367 +
15368 +obj-y          += vserver.o
15369 +
15370 +vserver-y      := switch.o context.o space.o sched.o network.o inode.o \
15371 +                  limit.o cvirt.o cacct.o signal.o helper.o init.o \
15372 +                  dlimit.o tag.o
15373 +
15374 +vserver-$(CONFIG_INET) += inet.o
15375 +vserver-$(CONFIG_PROC_FS) += proc.o
15376 +vserver-$(CONFIG_VSERVER_DEBUG) += sysctl.o debug.o
15377 +vserver-$(CONFIG_VSERVER_HISTORY) += history.o
15378 +vserver-$(CONFIG_VSERVER_MONITOR) += monitor.o
15379 +vserver-$(CONFIG_VSERVER_DEVICE) += device.o
15380 +
15381 diff -NurpP --minimal linux-3.6/kernel/vserver/cacct.c linux-3.6-vs2.3.4.3-noxfs-nocow/kernel/vserver/cacct.c
15382 --- linux-3.6/kernel/vserver/cacct.c    1970-01-01 01:00:00.000000000 +0100
15383 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/kernel/vserver/cacct.c      2012-10-04 18:47:00.000000000 +0200
15384 @@ -0,0 +1,42 @@
15385 +/*
15386 + *  linux/kernel/vserver/cacct.c
15387 + *
15388 + *  Virtual Server: Context Accounting
15389 + *
15390 + *  Copyright (C) 2006-2007 Herbert Pötzl
15391 + *
15392 + *  V0.01  added accounting stats
15393 + *
15394 + */
15395 +
15396 +#include <linux/types.h>
15397 +#include <linux/vs_context.h>
15398 +#include <linux/vserver/cacct_cmd.h>
15399 +#include <linux/vserver/cacct_int.h>
15400 +
15401 +#include <asm/errno.h>
15402 +#include <asm/uaccess.h>
15403 +
15404 +
15405 +int vc_sock_stat(struct vx_info *vxi, void __user *data)
15406 +{
15407 +       struct vcmd_sock_stat_v0 vc_data;
15408 +       int j, field;
15409 +
15410 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
15411 +               return -EFAULT;
15412 +
15413 +       field = vc_data.field;
15414 +       if ((field < 0) || (field >= VXA_SOCK_SIZE))
15415 +               return -EINVAL;
15416 +
15417 +       for (j = 0; j < 3; j++) {
15418 +               vc_data.count[j] = vx_sock_count(&vxi->cacct, field, j);
15419 +               vc_data.total[j] = vx_sock_total(&vxi->cacct, field, j);
15420 +       }
15421 +
15422 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
15423 +               return -EFAULT;
15424 +       return 0;
15425 +}
15426 +
15427 diff -NurpP --minimal linux-3.6/kernel/vserver/cacct_init.h linux-3.6-vs2.3.4.3-noxfs-nocow/kernel/vserver/cacct_init.h
15428 --- linux-3.6/kernel/vserver/cacct_init.h       1970-01-01 01:00:00.000000000 +0100
15429 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/kernel/vserver/cacct_init.h 2012-10-04 18:47:00.000000000 +0200
15430 @@ -0,0 +1,25 @@
15431 +
15432 +
15433 +static inline void vx_info_init_cacct(struct _vx_cacct *cacct)
15434 +{
15435 +       int i, j;
15436 +
15437 +
15438 +       for (i = 0; i < VXA_SOCK_SIZE; i++) {
15439 +               for (j = 0; j < 3; j++) {
15440 +                       atomic_long_set(&cacct->sock[i][j].count, 0);
15441 +                       atomic_long_set(&cacct->sock[i][j].total, 0);
15442 +               }
15443 +       }
15444 +       for (i = 0; i < 8; i++)
15445 +               atomic_set(&cacct->slab[i], 0);
15446 +       for (i = 0; i < 5; i++)
15447 +               for (j = 0; j < 4; j++)
15448 +                       atomic_set(&cacct->page[i][j], 0);
15449 +}
15450 +
15451 +static inline void vx_info_exit_cacct(struct _vx_cacct *cacct)
15452 +{
15453 +       return;
15454 +}
15455 +
15456 diff -NurpP --minimal linux-3.6/kernel/vserver/cacct_proc.h linux-3.6-vs2.3.4.3-noxfs-nocow/kernel/vserver/cacct_proc.h
15457 --- linux-3.6/kernel/vserver/cacct_proc.h       1970-01-01 01:00:00.000000000 +0100
15458 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/kernel/vserver/cacct_proc.h 2012-10-04 18:47:00.000000000 +0200
15459 @@ -0,0 +1,53 @@
15460 +#ifndef _VX_CACCT_PROC_H
15461 +#define _VX_CACCT_PROC_H
15462 +
15463 +#include <linux/vserver/cacct_int.h>
15464 +
15465 +
15466 +#define VX_SOCKA_TOP   \
15467 +       "Type\t    recv #/bytes\t\t   send #/bytes\t\t    fail #/bytes\n"
15468 +
15469 +static inline int vx_info_proc_cacct(struct _vx_cacct *cacct, char *buffer)
15470 +{
15471 +       int i, j, length = 0;
15472 +       static char *type[VXA_SOCK_SIZE] = {
15473 +               "UNSPEC", "UNIX", "INET", "INET6", "PACKET", "OTHER"
15474 +       };
15475 +
15476 +       length += sprintf(buffer + length, VX_SOCKA_TOP);
15477 +       for (i = 0; i < VXA_SOCK_SIZE; i++) {
15478 +               length += sprintf(buffer + length, "%s:", type[i]);
15479 +               for (j = 0; j < 3; j++) {
15480 +                       length += sprintf(buffer + length,
15481 +                               "\t%10lu/%-10lu",
15482 +                               vx_sock_count(cacct, i, j),
15483 +                               vx_sock_total(cacct, i, j));
15484 +               }
15485 +               buffer[length++] = '\n';
15486 +       }
15487 +
15488 +       length += sprintf(buffer + length, "\n");
15489 +       length += sprintf(buffer + length,
15490 +               "slab:\t %8u %8u %8u %8u\n",
15491 +               atomic_read(&cacct->slab[1]),
15492 +               atomic_read(&cacct->slab[4]),
15493 +               atomic_read(&cacct->slab[0]),
15494 +               atomic_read(&cacct->slab[2]));
15495 +
15496 +       length += sprintf(buffer + length, "\n");
15497 +       for (i = 0; i < 5; i++) {
15498 +               length += sprintf(buffer + length,
15499 +                       "page[%d]: %8u %8u %8u %8u\t %8u %8u %8u %8u\n", i,
15500 +                       atomic_read(&cacct->page[i][0]),
15501 +                       atomic_read(&cacct->page[i][1]),
15502 +                       atomic_read(&cacct->page[i][2]),
15503 +                       atomic_read(&cacct->page[i][3]),
15504 +                       atomic_read(&cacct->page[i][4]),
15505 +                       atomic_read(&cacct->page[i][5]),
15506 +                       atomic_read(&cacct->page[i][6]),
15507 +                       atomic_read(&cacct->page[i][7]));
15508 +       }
15509 +       return length;
15510 +}
15511 +
15512 +#endif /* _VX_CACCT_PROC_H */
15513 diff -NurpP --minimal linux-3.6/kernel/vserver/context.c linux-3.6-vs2.3.4.3-noxfs-nocow/kernel/vserver/context.c
15514 --- linux-3.6/kernel/vserver/context.c  1970-01-01 01:00:00.000000000 +0100
15515 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/kernel/vserver/context.c    2012-10-04 18:47:00.000000000 +0200
15516 @@ -0,0 +1,1119 @@
15517 +/*
15518 + *  linux/kernel/vserver/context.c
15519 + *
15520 + *  Virtual Server: Context Support
15521 + *
15522 + *  Copyright (C) 2003-2011  Herbert Pötzl
15523 + *
15524 + *  V0.01  context helper
15525 + *  V0.02  vx_ctx_kill syscall command
15526 + *  V0.03  replaced context_info calls
15527 + *  V0.04  redesign of struct (de)alloc
15528 + *  V0.05  rlimit basic implementation
15529 + *  V0.06  task_xid and info commands
15530 + *  V0.07  context flags and caps
15531 + *  V0.08  switch to RCU based hash
15532 + *  V0.09  revert to non RCU for now
15533 + *  V0.10  and back to working RCU hash
15534 + *  V0.11  and back to locking again
15535 + *  V0.12  referenced context store
15536 + *  V0.13  separate per cpu data
15537 + *  V0.14  changed vcmds to vxi arg
15538 + *  V0.15  added context stat
15539 + *  V0.16  have __create claim() the vxi
15540 + *  V0.17  removed older and legacy stuff
15541 + *  V0.18  added user credentials
15542 + *  V0.19  added warn mask
15543 + *
15544 + */
15545 +
15546 +#include <linux/slab.h>
15547 +#include <linux/types.h>
15548 +#include <linux/security.h>
15549 +#include <linux/pid_namespace.h>
15550 +#include <linux/capability.h>
15551 +
15552 +#include <linux/vserver/context.h>
15553 +#include <linux/vserver/network.h>
15554 +#include <linux/vserver/debug.h>
15555 +#include <linux/vserver/limit.h>
15556 +#include <linux/vserver/limit_int.h>
15557 +#include <linux/vserver/space.h>
15558 +#include <linux/init_task.h>
15559 +#include <linux/fs_struct.h>
15560 +#include <linux/cred.h>
15561 +
15562 +#include <linux/vs_context.h>
15563 +#include <linux/vs_limit.h>
15564 +#include <linux/vs_pid.h>
15565 +#include <linux/vserver/context_cmd.h>
15566 +
15567 +#include "cvirt_init.h"
15568 +#include "cacct_init.h"
15569 +#include "limit_init.h"
15570 +#include "sched_init.h"
15571 +
15572 +
15573 +atomic_t vx_global_ctotal      = ATOMIC_INIT(0);
15574 +atomic_t vx_global_cactive     = ATOMIC_INIT(0);
15575 +
15576 +
15577 +/*     now inactive context structures */
15578 +
15579 +static struct hlist_head vx_info_inactive = HLIST_HEAD_INIT;
15580 +
15581 +static DEFINE_SPINLOCK(vx_info_inactive_lock);
15582 +
15583 +
15584 +/*     __alloc_vx_info()
15585 +
15586 +       * allocate an initialized vx_info struct
15587 +       * doesn't make it visible (hash)                        */
15588 +
15589 +static struct vx_info *__alloc_vx_info(xid_t xid)
15590 +{
15591 +       struct vx_info *new = NULL;
15592 +       int cpu, index;
15593 +
15594 +       vxdprintk(VXD_CBIT(xid, 0), "alloc_vx_info(%d)*", xid);
15595 +
15596 +       /* would this benefit from a slab cache? */
15597 +       new = kmalloc(sizeof(struct vx_info), GFP_KERNEL);
15598 +       if (!new)
15599 +               return 0;
15600 +
15601 +       memset(new, 0, sizeof(struct vx_info));
15602 +#ifdef CONFIG_SMP
15603 +       new->ptr_pc = alloc_percpu(struct _vx_info_pc);
15604 +       if (!new->ptr_pc)
15605 +               goto error;
15606 +#endif
15607 +       new->vx_id = xid;
15608 +       INIT_HLIST_NODE(&new->vx_hlist);
15609 +       atomic_set(&new->vx_usecnt, 0);
15610 +       atomic_set(&new->vx_tasks, 0);
15611 +       new->vx_parent = NULL;
15612 +       new->vx_state = 0;
15613 +       init_waitqueue_head(&new->vx_wait);
15614 +
15615 +       /* prepare reaper */
15616 +       get_task_struct(init_pid_ns.child_reaper);
15617 +       new->vx_reaper = init_pid_ns.child_reaper;
15618 +       new->vx_badness_bias = 0;
15619 +
15620 +       /* rest of init goes here */
15621 +       vx_info_init_limit(&new->limit);
15622 +       vx_info_init_sched(&new->sched);
15623 +       vx_info_init_cvirt(&new->cvirt);
15624 +       vx_info_init_cacct(&new->cacct);
15625 +
15626 +       /* per cpu data structures */
15627 +       for_each_possible_cpu(cpu) {
15628 +               vx_info_init_sched_pc(
15629 +                       &vx_per_cpu(new, sched_pc, cpu), cpu);
15630 +               vx_info_init_cvirt_pc(
15631 +                       &vx_per_cpu(new, cvirt_pc, cpu), cpu);
15632 +       }
15633 +
15634 +       new->vx_flags = VXF_INIT_SET;
15635 +       new->vx_bcaps = CAP_FULL_SET;   // maybe ~CAP_SETPCAP
15636 +       new->vx_ccaps = 0;
15637 +       new->vx_umask = 0;
15638 +       new->vx_wmask = 0;
15639 +
15640 +       new->reboot_cmd = 0;
15641 +       new->exit_code = 0;
15642 +
15643 +       // preconfig spaces
15644 +       for (index = 0; index < VX_SPACES; index++) {
15645 +               struct _vx_space *space = &new->space[index];
15646 +
15647 +               // filesystem
15648 +               spin_lock(&init_fs.lock);
15649 +               init_fs.users++;
15650 +               spin_unlock(&init_fs.lock);
15651 +               space->vx_fs = &init_fs;
15652 +
15653 +               /* FIXME: do we want defaults? */
15654 +               // space->vx_real_cred = 0;
15655 +               // space->vx_cred = 0;
15656 +       }
15657 +
15658 +
15659 +       vxdprintk(VXD_CBIT(xid, 0),
15660 +               "alloc_vx_info(%d) = %p", xid, new);
15661 +       vxh_alloc_vx_info(new);
15662 +       atomic_inc(&vx_global_ctotal);
15663 +       return new;
15664 +#ifdef CONFIG_SMP
15665 +error:
15666 +       kfree(new);
15667 +       return 0;
15668 +#endif
15669 +}
15670 +
15671 +/*     __dealloc_vx_info()
15672 +
15673 +       * final disposal of vx_info                             */
15674 +
15675 +static void __dealloc_vx_info(struct vx_info *vxi)
15676 +{
15677 +#ifdef CONFIG_VSERVER_WARN
15678 +       struct vx_info_save vxis;
15679 +       int cpu;
15680 +#endif
15681 +       vxdprintk(VXD_CBIT(xid, 0),
15682 +               "dealloc_vx_info(%p)", vxi);
15683 +       vxh_dealloc_vx_info(vxi);
15684 +
15685 +#ifdef CONFIG_VSERVER_WARN
15686 +       enter_vx_info(vxi, &vxis);
15687 +       vx_info_exit_limit(&vxi->limit);
15688 +       vx_info_exit_sched(&vxi->sched);
15689 +       vx_info_exit_cvirt(&vxi->cvirt);
15690 +       vx_info_exit_cacct(&vxi->cacct);
15691 +
15692 +       for_each_possible_cpu(cpu) {
15693 +               vx_info_exit_sched_pc(
15694 +                       &vx_per_cpu(vxi, sched_pc, cpu), cpu);
15695 +               vx_info_exit_cvirt_pc(
15696 +                       &vx_per_cpu(vxi, cvirt_pc, cpu), cpu);
15697 +       }
15698 +       leave_vx_info(&vxis);
15699 +#endif
15700 +
15701 +       vxi->vx_id = -1;
15702 +       vxi->vx_state |= VXS_RELEASED;
15703 +
15704 +#ifdef CONFIG_SMP
15705 +       free_percpu(vxi->ptr_pc);
15706 +#endif
15707 +       kfree(vxi);
15708 +       atomic_dec(&vx_global_ctotal);
15709 +}
15710 +
15711 +static void __shutdown_vx_info(struct vx_info *vxi)
15712 +{
15713 +       struct nsproxy *nsproxy;
15714 +       struct fs_struct *fs;
15715 +       struct cred *cred;
15716 +       int index, kill;
15717 +
15718 +       might_sleep();
15719 +
15720 +       vxi->vx_state |= VXS_SHUTDOWN;
15721 +       vs_state_change(vxi, VSC_SHUTDOWN);
15722 +
15723 +       for (index = 0; index < VX_SPACES; index++) {
15724 +               struct _vx_space *space = &vxi->space[index];
15725 +
15726 +               nsproxy = xchg(&space->vx_nsproxy, NULL);
15727 +               if (nsproxy)
15728 +                       put_nsproxy(nsproxy);
15729 +
15730 +               fs = xchg(&space->vx_fs, NULL);
15731 +               spin_lock(&fs->lock);
15732 +               kill = !--fs->users;
15733 +               spin_unlock(&fs->lock);
15734 +               if (kill)
15735 +                       free_fs_struct(fs);
15736 +
15737 +               cred = (struct cred *)xchg(&space->vx_cred, NULL);
15738 +               if (cred)
15739 +                       abort_creds(cred);
15740 +       }
15741 +}
15742 +
15743 +/* exported stuff */
15744 +
15745 +void free_vx_info(struct vx_info *vxi)
15746 +{
15747 +       unsigned long flags;
15748 +       unsigned index;
15749 +
15750 +       /* check for reference counts first */
15751 +       BUG_ON(atomic_read(&vxi->vx_usecnt));
15752 +       BUG_ON(atomic_read(&vxi->vx_tasks));
15753 +
15754 +       /* context must not be hashed */
15755 +       BUG_ON(vx_info_state(vxi, VXS_HASHED));
15756 +
15757 +       /* context shutdown is mandatory */
15758 +       BUG_ON(!vx_info_state(vxi, VXS_SHUTDOWN));
15759 +
15760 +       /* spaces check */
15761 +       for (index = 0; index < VX_SPACES; index++) {
15762 +               struct _vx_space *space = &vxi->space[index];
15763 +
15764 +               BUG_ON(space->vx_nsproxy);
15765 +               BUG_ON(space->vx_fs);
15766 +               // BUG_ON(space->vx_real_cred);
15767 +               // BUG_ON(space->vx_cred);
15768 +       }
15769 +
15770 +       spin_lock_irqsave(&vx_info_inactive_lock, flags);
15771 +       hlist_del(&vxi->vx_hlist);
15772 +       spin_unlock_irqrestore(&vx_info_inactive_lock, flags);
15773 +
15774 +       __dealloc_vx_info(vxi);
15775 +}
15776 +
15777 +
15778 +/*     hash table for vx_info hash */
15779 +
15780 +#define VX_HASH_SIZE   13
15781 +
15782 +static struct hlist_head vx_info_hash[VX_HASH_SIZE] =
15783 +       { [0 ... VX_HASH_SIZE-1] = HLIST_HEAD_INIT };
15784 +
15785 +static DEFINE_SPINLOCK(vx_info_hash_lock);
15786 +
15787 +
15788 +static inline unsigned int __hashval(xid_t xid)
15789 +{
15790 +       return (xid % VX_HASH_SIZE);
15791 +}
15792 +
15793 +
15794 +
15795 +/*     __hash_vx_info()
15796 +
15797 +       * add the vxi to the global hash table
15798 +       * requires the hash_lock to be held                     */
15799 +
15800 +static inline void __hash_vx_info(struct vx_info *vxi)
15801 +{
15802 +       struct hlist_head *head;
15803 +
15804 +       vxd_assert_lock(&vx_info_hash_lock);
15805 +       vxdprintk(VXD_CBIT(xid, 4),
15806 +               "__hash_vx_info: %p[#%d]", vxi, vxi->vx_id);
15807 +       vxh_hash_vx_info(vxi);
15808 +
15809 +       /* context must not be hashed */
15810 +       BUG_ON(vx_info_state(vxi, VXS_HASHED));
15811 +
15812 +       vxi->vx_state |= VXS_HASHED;
15813 +       head = &vx_info_hash[__hashval(vxi->vx_id)];
15814 +       hlist_add_head(&vxi->vx_hlist, head);
15815 +       atomic_inc(&vx_global_cactive);
15816 +}
15817 +
15818 +/*     __unhash_vx_info()
15819 +
15820 +       * remove the vxi from the global hash table
15821 +       * requires the hash_lock to be held                     */
15822 +
15823 +static inline void __unhash_vx_info(struct vx_info *vxi)
15824 +{
15825 +       unsigned long flags;
15826 +
15827 +       vxd_assert_lock(&vx_info_hash_lock);
15828 +       vxdprintk(VXD_CBIT(xid, 4),
15829 +               "__unhash_vx_info: %p[#%d.%d.%d]", vxi, vxi->vx_id,
15830 +               atomic_read(&vxi->vx_usecnt), atomic_read(&vxi->vx_tasks));
15831 +       vxh_unhash_vx_info(vxi);
15832 +
15833 +       /* context must be hashed */
15834 +       BUG_ON(!vx_info_state(vxi, VXS_HASHED));
15835 +       /* but without tasks */
15836 +       BUG_ON(atomic_read(&vxi->vx_tasks));
15837 +
15838 +       vxi->vx_state &= ~VXS_HASHED;
15839 +       hlist_del_init(&vxi->vx_hlist);
15840 +       spin_lock_irqsave(&vx_info_inactive_lock, flags);
15841 +       hlist_add_head(&vxi->vx_hlist, &vx_info_inactive);
15842 +       spin_unlock_irqrestore(&vx_info_inactive_lock, flags);
15843 +       atomic_dec(&vx_global_cactive);
15844 +}
15845 +
15846 +
15847 +/*     __lookup_vx_info()
15848 +
15849 +       * requires the hash_lock to be held
15850 +       * doesn't increment the vx_refcnt                       */
15851 +
15852 +static inline struct vx_info *__lookup_vx_info(xid_t xid)
15853 +{
15854 +       struct hlist_head *head = &vx_info_hash[__hashval(xid)];
15855 +       struct hlist_node *pos;
15856 +       struct vx_info *vxi;
15857 +
15858 +       vxd_assert_lock(&vx_info_hash_lock);
15859 +       hlist_for_each(pos, head) {
15860 +               vxi = hlist_entry(pos, struct vx_info, vx_hlist);
15861 +
15862 +               if (vxi->vx_id == xid)
15863 +                       goto found;
15864 +       }
15865 +       vxi = NULL;
15866 +found:
15867 +       vxdprintk(VXD_CBIT(xid, 0),
15868 +               "__lookup_vx_info(#%u): %p[#%u]",
15869 +               xid, vxi, vxi ? vxi->vx_id : 0);
15870 +       vxh_lookup_vx_info(vxi, xid);
15871 +       return vxi;
15872 +}
15873 +
15874 +
15875 +/*     __create_vx_info()
15876 +
15877 +       * create the requested context
15878 +       * get(), claim() and hash it                            */
15879 +
15880 +static struct vx_info *__create_vx_info(int id)
15881 +{
15882 +       struct vx_info *new, *vxi = NULL;
15883 +
15884 +       vxdprintk(VXD_CBIT(xid, 1), "create_vx_info(%d)*", id);
15885 +
15886 +       if (!(new = __alloc_vx_info(id)))
15887 +               return ERR_PTR(-ENOMEM);
15888 +
15889 +       /* required to make dynamic xids unique */
15890 +       spin_lock(&vx_info_hash_lock);
15891 +
15892 +       /* static context requested */
15893 +       if ((vxi = __lookup_vx_info(id))) {
15894 +               vxdprintk(VXD_CBIT(xid, 0),
15895 +                       "create_vx_info(%d) = %p (already there)", id, vxi);
15896 +               if (vx_info_flags(vxi, VXF_STATE_SETUP, 0))
15897 +                       vxi = ERR_PTR(-EBUSY);
15898 +               else
15899 +                       vxi = ERR_PTR(-EEXIST);
15900 +               goto out_unlock;
15901 +       }
15902 +       /* new context */
15903 +       vxdprintk(VXD_CBIT(xid, 0),
15904 +               "create_vx_info(%d) = %p (new)", id, new);
15905 +       claim_vx_info(new, NULL);
15906 +       __hash_vx_info(get_vx_info(new));
15907 +       vxi = new, new = NULL;
15908 +
15909 +out_unlock:
15910 +       spin_unlock(&vx_info_hash_lock);
15911 +       vxh_create_vx_info(IS_ERR(vxi) ? NULL : vxi, id);
15912 +       if (new)
15913 +               __dealloc_vx_info(new);
15914 +       return vxi;
15915 +}
15916 +
15917 +
15918 +/*     exported stuff                                          */
15919 +
15920 +
15921 +void unhash_vx_info(struct vx_info *vxi)
15922 +{
15923 +       spin_lock(&vx_info_hash_lock);
15924 +       __unhash_vx_info(vxi);
15925 +       spin_unlock(&vx_info_hash_lock);
15926 +       __shutdown_vx_info(vxi);
15927 +       __wakeup_vx_info(vxi);
15928 +}
15929 +
15930 +
15931 +/*     lookup_vx_info()
15932 +
15933 +       * search for a vx_info and get() it
15934 +       * negative id means current                             */
15935 +
15936 +struct vx_info *lookup_vx_info(int id)
15937 +{
15938 +       struct vx_info *vxi = NULL;
15939 +
15940 +       if (id < 0) {
15941 +               vxi = get_vx_info(current_vx_info());
15942 +       } else if (id > 1) {
15943 +               spin_lock(&vx_info_hash_lock);
15944 +               vxi = get_vx_info(__lookup_vx_info(id));
15945 +               spin_unlock(&vx_info_hash_lock);
15946 +       }
15947 +       return vxi;
15948 +}
15949 +
15950 +/*     xid_is_hashed()
15951 +
15952 +       * verify that xid is still hashed                       */
15953 +
15954 +int xid_is_hashed(xid_t xid)
15955 +{
15956 +       int hashed;
15957 +
15958 +       spin_lock(&vx_info_hash_lock);
15959 +       hashed = (__lookup_vx_info(xid) != NULL);
15960 +       spin_unlock(&vx_info_hash_lock);
15961 +       return hashed;
15962 +}
15963 +
15964 +#ifdef CONFIG_PROC_FS
15965 +
15966 +/*     get_xid_list()
15967 +
15968 +       * get a subset of hashed xids for proc
15969 +       * assumes size is at least one                          */
15970 +
15971 +int get_xid_list(int index, unsigned int *xids, int size)
15972 +{
15973 +       int hindex, nr_xids = 0;
15974 +
15975 +       /* only show current and children */
15976 +       if (!vx_check(0, VS_ADMIN | VS_WATCH)) {
15977 +               if (index > 0)
15978 +                       return 0;
15979 +               xids[nr_xids] = vx_current_xid();
15980 +               return 1;
15981 +       }
15982 +
15983 +       for (hindex = 0; hindex < VX_HASH_SIZE; hindex++) {
15984 +               struct hlist_head *head = &vx_info_hash[hindex];
15985 +               struct hlist_node *pos;
15986 +
15987 +               spin_lock(&vx_info_hash_lock);
15988 +               hlist_for_each(pos, head) {
15989 +                       struct vx_info *vxi;
15990 +
15991 +                       if (--index > 0)
15992 +                               continue;
15993 +
15994 +                       vxi = hlist_entry(pos, struct vx_info, vx_hlist);
15995 +                       xids[nr_xids] = vxi->vx_id;
15996 +                       if (++nr_xids >= size) {
15997 +                               spin_unlock(&vx_info_hash_lock);
15998 +                               goto out;
15999 +                       }
16000 +               }
16001 +               /* keep the lock time short */
16002 +               spin_unlock(&vx_info_hash_lock);
16003 +       }
16004 +out:
16005 +       return nr_xids;
16006 +}
16007 +#endif
16008 +
16009 +#ifdef CONFIG_VSERVER_DEBUG
16010 +
16011 +void   dump_vx_info_inactive(int level)
16012 +{
16013 +       struct hlist_node *entry, *next;
16014 +
16015 +       hlist_for_each_safe(entry, next, &vx_info_inactive) {
16016 +               struct vx_info *vxi =
16017 +                       list_entry(entry, struct vx_info, vx_hlist);
16018 +
16019 +               dump_vx_info(vxi, level);
16020 +       }
16021 +}
16022 +
16023 +#endif
16024 +
16025 +#if 0
16026 +int vx_migrate_user(struct task_struct *p, struct vx_info *vxi)
16027 +{
16028 +       struct user_struct *new_user, *old_user;
16029 +
16030 +       if (!p || !vxi)
16031 +               BUG();
16032 +
16033 +       if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0))
16034 +               return -EACCES;
16035 +
16036 +       new_user = alloc_uid(vxi->vx_id, p->uid);
16037 +       if (!new_user)
16038 +               return -ENOMEM;
16039 +
16040 +       old_user = p->user;
16041 +       if (new_user != old_user) {
16042 +               atomic_inc(&new_user->processes);
16043 +               atomic_dec(&old_user->processes);
16044 +               p->user = new_user;
16045 +       }
16046 +       free_uid(old_user);
16047 +       return 0;
16048 +}
16049 +#endif
16050 +
16051 +#if 0
16052 +void vx_mask_cap_bset(struct vx_info *vxi, struct task_struct *p)
16053 +{
16054 +       // p->cap_effective &= vxi->vx_cap_bset;
16055 +       p->cap_effective =
16056 +               cap_intersect(p->cap_effective, vxi->cap_bset);
16057 +       // p->cap_inheritable &= vxi->vx_cap_bset;
16058 +       p->cap_inheritable =
16059 +               cap_intersect(p->cap_inheritable, vxi->cap_bset);
16060 +       // p->cap_permitted &= vxi->vx_cap_bset;
16061 +       p->cap_permitted =
16062 +               cap_intersect(p->cap_permitted, vxi->cap_bset);
16063 +}
16064 +#endif
16065 +
16066 +
16067 +#include <linux/file.h>
16068 +#include <linux/fdtable.h>
16069 +
16070 +static int vx_openfd_task(struct task_struct *tsk)
16071 +{
16072 +       struct files_struct *files = tsk->files;
16073 +       struct fdtable *fdt;
16074 +       const unsigned long *bptr;
16075 +       int count, total;
16076 +
16077 +       /* no rcu_read_lock() because of spin_lock() */
16078 +       spin_lock(&files->file_lock);
16079 +       fdt = files_fdtable(files);
16080 +       bptr = fdt->open_fds;
16081 +       count = fdt->max_fds / (sizeof(unsigned long) * 8);
16082 +       for (total = 0; count > 0; count--) {
16083 +               if (*bptr)
16084 +                       total += hweight_long(*bptr);
16085 +               bptr++;
16086 +       }
16087 +       spin_unlock(&files->file_lock);
16088 +       return total;
16089 +}
16090 +
16091 +
16092 +/*     for *space compatibility */
16093 +
16094 +asmlinkage long sys_unshare(unsigned long);
16095 +
16096 +/*
16097 + *     migrate task to new context
16098 + *     gets vxi, puts old_vxi on change
16099 + *     optionally unshares namespaces (hack)
16100 + */
16101 +
16102 +int vx_migrate_task(struct task_struct *p, struct vx_info *vxi, int unshare)
16103 +{
16104 +       struct vx_info *old_vxi;
16105 +       int ret = 0;
16106 +
16107 +       if (!p || !vxi)
16108 +               BUG();
16109 +
16110 +       vxdprintk(VXD_CBIT(xid, 5),
16111 +               "vx_migrate_task(%p,%p[#%d.%d])", p, vxi,
16112 +               vxi->vx_id, atomic_read(&vxi->vx_usecnt));
16113 +
16114 +       if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0) &&
16115 +               !vx_info_flags(vxi, VXF_STATE_SETUP, 0))
16116 +               return -EACCES;
16117 +
16118 +       if (vx_info_state(vxi, VXS_SHUTDOWN))
16119 +               return -EFAULT;
16120 +
16121 +       old_vxi = task_get_vx_info(p);
16122 +       if (old_vxi == vxi)
16123 +               goto out;
16124 +
16125 +//     if (!(ret = vx_migrate_user(p, vxi))) {
16126 +       {
16127 +               int openfd;
16128 +
16129 +               task_lock(p);
16130 +               openfd = vx_openfd_task(p);
16131 +
16132 +               if (old_vxi) {
16133 +                       atomic_dec(&old_vxi->cvirt.nr_threads);
16134 +                       atomic_dec(&old_vxi->cvirt.nr_running);
16135 +                       __rlim_dec(&old_vxi->limit, RLIMIT_NPROC);
16136 +                       /* FIXME: what about the struct files here? */
16137 +                       __rlim_sub(&old_vxi->limit, VLIMIT_OPENFD, openfd);
16138 +                       /* account for the executable */
16139 +                       __rlim_dec(&old_vxi->limit, VLIMIT_DENTRY);
16140 +               }
16141 +               atomic_inc(&vxi->cvirt.nr_threads);
16142 +               atomic_inc(&vxi->cvirt.nr_running);
16143 +               __rlim_inc(&vxi->limit, RLIMIT_NPROC);
16144 +               /* FIXME: what about the struct files here? */
16145 +               __rlim_add(&vxi->limit, VLIMIT_OPENFD, openfd);
16146 +               /* account for the executable */
16147 +               __rlim_inc(&vxi->limit, VLIMIT_DENTRY);
16148 +
16149 +               if (old_vxi) {
16150 +                       release_vx_info(old_vxi, p);
16151 +                       clr_vx_info(&p->vx_info);
16152 +               }
16153 +               claim_vx_info(vxi, p);
16154 +               set_vx_info(&p->vx_info, vxi);
16155 +               p->xid = vxi->vx_id;
16156 +
16157 +               vxdprintk(VXD_CBIT(xid, 5),
16158 +                       "moved task %p into vxi:%p[#%d]",
16159 +                       p, vxi, vxi->vx_id);
16160 +
16161 +               // vx_mask_cap_bset(vxi, p);
16162 +               task_unlock(p);
16163 +
16164 +               /* hack for *spaces to provide compatibility */
16165 +               if (unshare) {
16166 +                       struct nsproxy *old_nsp, *new_nsp;
16167 +
16168 +                       ret = unshare_nsproxy_namespaces(
16169 +                               CLONE_NEWUTS | CLONE_NEWIPC | CLONE_NEWUSER,
16170 +                               &new_nsp, NULL);
16171 +                       if (ret)
16172 +                               goto out;
16173 +
16174 +                       old_nsp = xchg(&p->nsproxy, new_nsp);
16175 +                       vx_set_space(vxi,
16176 +                               CLONE_NEWUTS | CLONE_NEWIPC | CLONE_NEWUSER, 0);
16177 +                       put_nsproxy(old_nsp);
16178 +               }
16179 +       }
16180 +out:
16181 +       put_vx_info(old_vxi);
16182 +       return ret;
16183 +}
16184 +
16185 +int vx_set_reaper(struct vx_info *vxi, struct task_struct *p)
16186 +{
16187 +       struct task_struct *old_reaper;
16188 +       struct vx_info *reaper_vxi;
16189 +
16190 +       if (!vxi)
16191 +               return -EINVAL;
16192 +
16193 +       vxdprintk(VXD_CBIT(xid, 6),
16194 +               "vx_set_reaper(%p[#%d],%p[#%d,%d])",
16195 +               vxi, vxi->vx_id, p, p->xid, p->pid);
16196 +
16197 +       old_reaper = vxi->vx_reaper;
16198 +       if (old_reaper == p)
16199 +               return 0;
16200 +
16201 +       reaper_vxi = task_get_vx_info(p);
16202 +       if (reaper_vxi && reaper_vxi != vxi) {
16203 +               vxwprintk(1,
16204 +                       "Unsuitable reaper [" VS_Q("%s") ",%u:#%u] "
16205 +                       "for [xid #%u]",
16206 +                       p->comm, p->pid, p->xid, vx_current_xid());
16207 +               goto out;
16208 +       }
16209 +
16210 +       /* set new child reaper */
16211 +       get_task_struct(p);
16212 +       vxi->vx_reaper = p;
16213 +       put_task_struct(old_reaper);
16214 +out:
16215 +       put_vx_info(reaper_vxi);
16216 +       return 0;
16217 +}
16218 +
16219 +int vx_set_init(struct vx_info *vxi, struct task_struct *p)
16220 +{
16221 +       if (!vxi)
16222 +               return -EINVAL;
16223 +
16224 +       vxdprintk(VXD_CBIT(xid, 6),
16225 +               "vx_set_init(%p[#%d],%p[#%d,%d,%d])",
16226 +               vxi, vxi->vx_id, p, p->xid, p->pid, p->tgid);
16227 +
16228 +       vxi->vx_flags &= ~VXF_STATE_INIT;
16229 +       // vxi->vx_initpid = p->tgid;
16230 +       vxi->vx_initpid = p->pid;
16231 +       return 0;
16232 +}
16233 +
16234 +void vx_exit_init(struct vx_info *vxi, struct task_struct *p, int code)
16235 +{
16236 +       vxdprintk(VXD_CBIT(xid, 6),
16237 +               "vx_exit_init(%p[#%d],%p[#%d,%d,%d])",
16238 +               vxi, vxi->vx_id, p, p->xid, p->pid, p->tgid);
16239 +
16240 +       vxi->exit_code = code;
16241 +       vxi->vx_initpid = 0;
16242 +}
16243 +
16244 +
16245 +void vx_set_persistent(struct vx_info *vxi)
16246 +{
16247 +       vxdprintk(VXD_CBIT(xid, 6),
16248 +               "vx_set_persistent(%p[#%d])", vxi, vxi->vx_id);
16249 +
16250 +       get_vx_info(vxi);
16251 +       claim_vx_info(vxi, NULL);
16252 +}
16253 +
16254 +void vx_clear_persistent(struct vx_info *vxi)
16255 +{
16256 +       vxdprintk(VXD_CBIT(xid, 6),
16257 +               "vx_clear_persistent(%p[#%d])", vxi, vxi->vx_id);
16258 +
16259 +       release_vx_info(vxi, NULL);
16260 +       put_vx_info(vxi);
16261 +}
16262 +
16263 +void vx_update_persistent(struct vx_info *vxi)
16264 +{
16265 +       if (vx_info_flags(vxi, VXF_PERSISTENT, 0))
16266 +               vx_set_persistent(vxi);
16267 +       else
16268 +               vx_clear_persistent(vxi);
16269 +}
16270 +
16271 +
16272 +/*     task must be current or locked          */
16273 +
16274 +void   exit_vx_info(struct task_struct *p, int code)
16275 +{
16276 +       struct vx_info *vxi = p->vx_info;
16277 +
16278 +       if (vxi) {
16279 +               atomic_dec(&vxi->cvirt.nr_threads);
16280 +               vx_nproc_dec(p);
16281 +
16282 +               vxi->exit_code = code;
16283 +               release_vx_info(vxi, p);
16284 +       }
16285 +}
16286 +
16287 +void   exit_vx_info_early(struct task_struct *p, int code)
16288 +{
16289 +       struct vx_info *vxi = p->vx_info;
16290 +
16291 +       if (vxi) {
16292 +               if (vxi->vx_initpid == p->pid)
16293 +                       vx_exit_init(vxi, p, code);
16294 +               if (vxi->vx_reaper == p)
16295 +                       vx_set_reaper(vxi, init_pid_ns.child_reaper);
16296 +       }
16297 +}
16298 +
16299 +
16300 +/* vserver syscall commands below here */
16301 +
16302 +/* taks xid and vx_info functions */
16303 +
16304 +#include <asm/uaccess.h>
16305 +
16306 +
16307 +int vc_task_xid(uint32_t id)
16308 +{
16309 +       xid_t xid;
16310 +
16311 +       if (id) {
16312 +               struct task_struct *tsk;
16313 +
16314 +               rcu_read_lock();
16315 +               tsk = find_task_by_real_pid(id);
16316 +               xid = (tsk) ? tsk->xid : -ESRCH;
16317 +               rcu_read_unlock();
16318 +       } else
16319 +               xid = vx_current_xid();
16320 +       return xid;
16321 +}
16322 +
16323 +
16324 +int vc_vx_info(struct vx_info *vxi, void __user *data)
16325 +{
16326 +       struct vcmd_vx_info_v0 vc_data;
16327 +
16328 +       vc_data.xid = vxi->vx_id;
16329 +       vc_data.initpid = vxi->vx_initpid;
16330 +
16331 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16332 +               return -EFAULT;
16333 +       return 0;
16334 +}
16335 +
16336 +
16337 +int vc_ctx_stat(struct vx_info *vxi, void __user *data)
16338 +{
16339 +       struct vcmd_ctx_stat_v0 vc_data;
16340 +
16341 +       vc_data.usecnt = atomic_read(&vxi->vx_usecnt);
16342 +       vc_data.tasks = atomic_read(&vxi->vx_tasks);
16343 +
16344 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16345 +               return -EFAULT;
16346 +       return 0;
16347 +}
16348 +
16349 +
16350 +/* context functions */
16351 +
16352 +int vc_ctx_create(uint32_t xid, void __user *data)
16353 +{
16354 +       struct vcmd_ctx_create vc_data = { .flagword = VXF_INIT_SET };
16355 +       struct vx_info *new_vxi;
16356 +       int ret;
16357 +
16358 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
16359 +               return -EFAULT;
16360 +
16361 +       if ((xid > MAX_S_CONTEXT) || (xid < 2))
16362 +               return -EINVAL;
16363 +
16364 +       new_vxi = __create_vx_info(xid);
16365 +       if (IS_ERR(new_vxi))
16366 +               return PTR_ERR(new_vxi);
16367 +
16368 +       /* initial flags */
16369 +       new_vxi->vx_flags = vc_data.flagword;
16370 +
16371 +       ret = -ENOEXEC;
16372 +       if (vs_state_change(new_vxi, VSC_STARTUP))
16373 +               goto out;
16374 +
16375 +       ret = vx_migrate_task(current, new_vxi, (!data));
16376 +       if (ret)
16377 +               goto out;
16378 +
16379 +       /* return context id on success */
16380 +       ret = new_vxi->vx_id;
16381 +
16382 +       /* get a reference for persistent contexts */
16383 +       if ((vc_data.flagword & VXF_PERSISTENT))
16384 +               vx_set_persistent(new_vxi);
16385 +out:
16386 +       release_vx_info(new_vxi, NULL);
16387 +       put_vx_info(new_vxi);
16388 +       return ret;
16389 +}
16390 +
16391 +
16392 +int vc_ctx_migrate(struct vx_info *vxi, void __user *data)
16393 +{
16394 +       struct vcmd_ctx_migrate vc_data = { .flagword = 0 };
16395 +       int ret;
16396 +
16397 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
16398 +               return -EFAULT;
16399 +
16400 +       ret = vx_migrate_task(current, vxi, 0);
16401 +       if (ret)
16402 +               return ret;
16403 +       if (vc_data.flagword & VXM_SET_INIT)
16404 +               ret = vx_set_init(vxi, current);
16405 +       if (ret)
16406 +               return ret;
16407 +       if (vc_data.flagword & VXM_SET_REAPER)
16408 +               ret = vx_set_reaper(vxi, current);
16409 +       return ret;
16410 +}
16411 +
16412 +
16413 +int vc_get_cflags(struct vx_info *vxi, void __user *data)
16414 +{
16415 +       struct vcmd_ctx_flags_v0 vc_data;
16416 +
16417 +       vc_data.flagword = vxi->vx_flags;
16418 +
16419 +       /* special STATE flag handling */
16420 +       vc_data.mask = vs_mask_flags(~0ULL, vxi->vx_flags, VXF_ONE_TIME);
16421 +
16422 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16423 +               return -EFAULT;
16424 +       return 0;
16425 +}
16426 +
16427 +int vc_set_cflags(struct vx_info *vxi, void __user *data)
16428 +{
16429 +       struct vcmd_ctx_flags_v0 vc_data;
16430 +       uint64_t mask, trigger;
16431 +
16432 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16433 +               return -EFAULT;
16434 +
16435 +       /* special STATE flag handling */
16436 +       mask = vs_mask_mask(vc_data.mask, vxi->vx_flags, VXF_ONE_TIME);
16437 +       trigger = (mask & vxi->vx_flags) ^ (mask & vc_data.flagword);
16438 +
16439 +       if (vxi == current_vx_info()) {
16440 +               /* if (trigger & VXF_STATE_SETUP)
16441 +                       vx_mask_cap_bset(vxi, current); */
16442 +               if (trigger & VXF_STATE_INIT) {
16443 +                       int ret;
16444 +
16445 +                       ret = vx_set_init(vxi, current);
16446 +                       if (ret)
16447 +                               return ret;
16448 +                       ret = vx_set_reaper(vxi, current);
16449 +                       if (ret)
16450 +                               return ret;
16451 +               }
16452 +       }
16453 +
16454 +       vxi->vx_flags = vs_mask_flags(vxi->vx_flags,
16455 +               vc_data.flagword, mask);
16456 +       if (trigger & VXF_PERSISTENT)
16457 +               vx_update_persistent(vxi);
16458 +
16459 +       return 0;
16460 +}
16461 +
16462 +
16463 +static inline uint64_t caps_from_cap_t(kernel_cap_t c)
16464 +{
16465 +       uint64_t v = c.cap[0] | ((uint64_t)c.cap[1] << 32);
16466 +
16467 +       // printk("caps_from_cap_t(%08x:%08x) = %016llx\n", c.cap[1], c.cap[0], v);
16468 +       return v;
16469 +}
16470 +
16471 +static inline kernel_cap_t cap_t_from_caps(uint64_t v)
16472 +{
16473 +       kernel_cap_t c = __cap_empty_set;
16474 +
16475 +       c.cap[0] = v & 0xFFFFFFFF;
16476 +       c.cap[1] = (v >> 32) & 0xFFFFFFFF;
16477 +
16478 +       // printk("cap_t_from_caps(%016llx) = %08x:%08x\n", v, c.cap[1], c.cap[0]);
16479 +       return c;
16480 +}
16481 +
16482 +
16483 +static int do_get_caps(struct vx_info *vxi, uint64_t *bcaps, uint64_t *ccaps)
16484 +{
16485 +       if (bcaps)
16486 +               *bcaps = caps_from_cap_t(vxi->vx_bcaps);
16487 +       if (ccaps)
16488 +               *ccaps = vxi->vx_ccaps;
16489 +
16490 +       return 0;
16491 +}
16492 +
16493 +int vc_get_ccaps(struct vx_info *vxi, void __user *data)
16494 +{
16495 +       struct vcmd_ctx_caps_v1 vc_data;
16496 +       int ret;
16497 +
16498 +       ret = do_get_caps(vxi, NULL, &vc_data.ccaps);
16499 +       if (ret)
16500 +               return ret;
16501 +       vc_data.cmask = ~0ULL;
16502 +
16503 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16504 +               return -EFAULT;
16505 +       return 0;
16506 +}
16507 +
16508 +static int do_set_caps(struct vx_info *vxi,
16509 +       uint64_t bcaps, uint64_t bmask, uint64_t ccaps, uint64_t cmask)
16510 +{
16511 +       uint64_t bcold = caps_from_cap_t(vxi->vx_bcaps);
16512 +
16513 +#if 0
16514 +       printk("do_set_caps(%16llx, %16llx, %16llx, %16llx)\n",
16515 +               bcaps, bmask, ccaps, cmask);
16516 +#endif
16517 +       vxi->vx_bcaps = cap_t_from_caps(
16518 +               vs_mask_flags(bcold, bcaps, bmask));
16519 +       vxi->vx_ccaps = vs_mask_flags(vxi->vx_ccaps, ccaps, cmask);
16520 +
16521 +       return 0;
16522 +}
16523 +
16524 +int vc_set_ccaps(struct vx_info *vxi, void __user *data)
16525 +{
16526 +       struct vcmd_ctx_caps_v1 vc_data;
16527 +
16528 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16529 +               return -EFAULT;
16530 +
16531 +       return do_set_caps(vxi, 0, 0, vc_data.ccaps, vc_data.cmask);
16532 +}
16533 +
16534 +int vc_get_bcaps(struct vx_info *vxi, void __user *data)
16535 +{
16536 +       struct vcmd_bcaps vc_data;
16537 +       int ret;
16538 +
16539 +       ret = do_get_caps(vxi, &vc_data.bcaps, NULL);
16540 +       if (ret)
16541 +               return ret;
16542 +       vc_data.bmask = ~0ULL;
16543 +
16544 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16545 +               return -EFAULT;
16546 +       return 0;
16547 +}
16548 +
16549 +int vc_set_bcaps(struct vx_info *vxi, void __user *data)
16550 +{
16551 +       struct vcmd_bcaps vc_data;
16552 +
16553 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16554 +               return -EFAULT;
16555 +
16556 +       return do_set_caps(vxi, vc_data.bcaps, vc_data.bmask, 0, 0);
16557 +}
16558 +
16559 +
16560 +int vc_get_umask(struct vx_info *vxi, void __user *data)
16561 +{
16562 +       struct vcmd_umask vc_data;
16563 +
16564 +       vc_data.umask = vxi->vx_umask;
16565 +       vc_data.mask = ~0ULL;
16566 +
16567 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16568 +               return -EFAULT;
16569 +       return 0;
16570 +}
16571 +
16572 +int vc_set_umask(struct vx_info *vxi, void __user *data)
16573 +{
16574 +       struct vcmd_umask vc_data;
16575 +
16576 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16577 +               return -EFAULT;
16578 +
16579 +       vxi->vx_umask = vs_mask_flags(vxi->vx_umask,
16580 +               vc_data.umask, vc_data.mask);
16581 +       return 0;
16582 +}
16583 +
16584 +
16585 +int vc_get_wmask(struct vx_info *vxi, void __user *data)
16586 +{
16587 +       struct vcmd_wmask vc_data;
16588 +
16589 +       vc_data.wmask = vxi->vx_wmask;
16590 +       vc_data.mask = ~0ULL;
16591 +
16592 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16593 +               return -EFAULT;
16594 +       return 0;
16595 +}
16596 +
16597 +int vc_set_wmask(struct vx_info *vxi, void __user *data)
16598 +{
16599 +       struct vcmd_wmask vc_data;
16600 +
16601 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16602 +               return -EFAULT;
16603 +
16604 +       vxi->vx_wmask = vs_mask_flags(vxi->vx_wmask,
16605 +               vc_data.wmask, vc_data.mask);
16606 +       return 0;
16607 +}
16608 +
16609 +
16610 +int vc_get_badness(struct vx_info *vxi, void __user *data)
16611 +{
16612 +       struct vcmd_badness_v0 vc_data;
16613 +
16614 +       vc_data.bias = vxi->vx_badness_bias;
16615 +
16616 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16617 +               return -EFAULT;
16618 +       return 0;
16619 +}
16620 +
16621 +int vc_set_badness(struct vx_info *vxi, void __user *data)
16622 +{
16623 +       struct vcmd_badness_v0 vc_data;
16624 +
16625 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16626 +               return -EFAULT;
16627 +
16628 +       vxi->vx_badness_bias = vc_data.bias;
16629 +       return 0;
16630 +}
16631 +
16632 +#include <linux/module.h>
16633 +
16634 +EXPORT_SYMBOL_GPL(free_vx_info);
16635 +
16636 diff -NurpP --minimal linux-3.6/kernel/vserver/cvirt.c linux-3.6-vs2.3.4.3-noxfs-nocow/kernel/vserver/cvirt.c
16637 --- linux-3.6/kernel/vserver/cvirt.c    1970-01-01 01:00:00.000000000 +0100
16638 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/kernel/vserver/cvirt.c      2012-10-04 18:47:00.000000000 +0200
16639 @@ -0,0 +1,313 @@
16640 +/*
16641 + *  linux/kernel/vserver/cvirt.c
16642 + *
16643 + *  Virtual Server: Context Virtualization
16644 + *
16645 + *  Copyright (C) 2004-2007  Herbert Pötzl
16646 + *
16647 + *  V0.01  broken out from limit.c
16648 + *  V0.02  added utsname stuff
16649 + *  V0.03  changed vcmds to vxi arg
16650 + *
16651 + */
16652 +
16653 +#include <linux/types.h>
16654 +#include <linux/utsname.h>
16655 +#include <linux/vs_cvirt.h>
16656 +#include <linux/vserver/switch.h>
16657 +#include <linux/vserver/cvirt_cmd.h>
16658 +
16659 +#include <asm/uaccess.h>
16660 +
16661 +
16662 +void vx_vsi_boottime(struct timespec *boottime)
16663 +{
16664 +       struct vx_info *vxi = current_vx_info();
16665 +
16666 +       set_normalized_timespec(boottime,
16667 +               boottime->tv_sec + vxi->cvirt.bias_uptime.tv_sec,
16668 +               boottime->tv_nsec + vxi->cvirt.bias_uptime.tv_nsec);
16669 +       return;
16670 +}
16671 +
16672 +void vx_vsi_uptime(struct timespec *uptime, struct timespec *idle)
16673 +{
16674 +       struct vx_info *vxi = current_vx_info();
16675 +
16676 +       set_normalized_timespec(uptime,
16677 +               uptime->tv_sec - vxi->cvirt.bias_uptime.tv_sec,
16678 +               uptime->tv_nsec - vxi->cvirt.bias_uptime.tv_nsec);
16679 +       if (!idle)
16680 +               return;
16681 +       set_normalized_timespec(idle,
16682 +               idle->tv_sec - vxi->cvirt.bias_idle.tv_sec,
16683 +               idle->tv_nsec - vxi->cvirt.bias_idle.tv_nsec);
16684 +       return;
16685 +}
16686 +
16687 +uint64_t vx_idle_jiffies(void)
16688 +{
16689 +       return init_task.utime + init_task.stime;
16690 +}
16691 +
16692 +
16693 +
16694 +static inline uint32_t __update_loadavg(uint32_t load,
16695 +       int wsize, int delta, int n)
16696 +{
16697 +       unsigned long long calc, prev;
16698 +
16699 +       /* just set it to n */
16700 +       if (unlikely(delta >= wsize))
16701 +               return (n << FSHIFT);
16702 +
16703 +       calc = delta * n;
16704 +       calc <<= FSHIFT;
16705 +       prev = (wsize - delta);
16706 +       prev *= load;
16707 +       calc += prev;
16708 +       do_div(calc, wsize);
16709 +       return calc;
16710 +}
16711 +
16712 +
16713 +void vx_update_load(struct vx_info *vxi)
16714 +{
16715 +       uint32_t now, last, delta;
16716 +       unsigned int nr_running, nr_uninterruptible;
16717 +       unsigned int total;
16718 +       unsigned long flags;
16719 +
16720 +       spin_lock_irqsave(&vxi->cvirt.load_lock, flags);
16721 +
16722 +       now = jiffies;
16723 +       last = vxi->cvirt.load_last;
16724 +       delta = now - last;
16725 +
16726 +       if (delta < 5*HZ)
16727 +               goto out;
16728 +
16729 +       nr_running = atomic_read(&vxi->cvirt.nr_running);
16730 +       nr_uninterruptible = atomic_read(&vxi->cvirt.nr_uninterruptible);
16731 +       total = nr_running + nr_uninterruptible;
16732 +
16733 +       vxi->cvirt.load[0] = __update_loadavg(vxi->cvirt.load[0],
16734 +               60*HZ, delta, total);
16735 +       vxi->cvirt.load[1] = __update_loadavg(vxi->cvirt.load[1],
16736 +               5*60*HZ, delta, total);
16737 +       vxi->cvirt.load[2] = __update_loadavg(vxi->cvirt.load[2],
16738 +               15*60*HZ, delta, total);
16739 +
16740 +       vxi->cvirt.load_last = now;
16741 +out:
16742 +       atomic_inc(&vxi->cvirt.load_updates);
16743 +       spin_unlock_irqrestore(&vxi->cvirt.load_lock, flags);
16744 +}
16745 +
16746 +
16747 +/*
16748 + * Commands to do_syslog:
16749 + *
16750 + *      0 -- Close the log.  Currently a NOP.
16751 + *      1 -- Open the log. Currently a NOP.
16752 + *      2 -- Read from the log.
16753 + *      3 -- Read all messages remaining in the ring buffer.
16754 + *      4 -- Read and clear all messages remaining in the ring buffer
16755 + *      5 -- Clear ring buffer.
16756 + *      6 -- Disable printk's to console
16757 + *      7 -- Enable printk's to console
16758 + *      8 -- Set level of messages printed to console
16759 + *      9 -- Return number of unread characters in the log buffer
16760 + *     10 -- Return size of the log buffer
16761 + */
16762 +int vx_do_syslog(int type, char __user *buf, int len)
16763 +{
16764 +       int error = 0;
16765 +       int do_clear = 0;
16766 +       struct vx_info *vxi = current_vx_info();
16767 +       struct _vx_syslog *log;
16768 +
16769 +       if (!vxi)
16770 +               return -EINVAL;
16771 +       log = &vxi->cvirt.syslog;
16772 +
16773 +       switch (type) {
16774 +       case 0:         /* Close log */
16775 +       case 1:         /* Open log */
16776 +               break;
16777 +       case 2:         /* Read from log */
16778 +               error = wait_event_interruptible(log->log_wait,
16779 +                       (log->log_start - log->log_end));
16780 +               if (error)
16781 +                       break;
16782 +               spin_lock_irq(&log->logbuf_lock);
16783 +               spin_unlock_irq(&log->logbuf_lock);
16784 +               break;
16785 +       case 4:         /* Read/clear last kernel messages */
16786 +               do_clear = 1;
16787 +               /* fall through */
16788 +       case 3:         /* Read last kernel messages */
16789 +               return 0;
16790 +
16791 +       case 5:         /* Clear ring buffer */
16792 +               return 0;
16793 +
16794 +       case 6:         /* Disable logging to console */
16795 +       case 7:         /* Enable logging to console */
16796 +       case 8:         /* Set level of messages printed to console */
16797 +               break;
16798 +
16799 +       case 9:         /* Number of chars in the log buffer */
16800 +               return 0;
16801 +       case 10:        /* Size of the log buffer */
16802 +               return 0;
16803 +       default:
16804 +               error = -EINVAL;
16805 +               break;
16806 +       }
16807 +       return error;
16808 +}
16809 +
16810 +
16811 +/* virtual host info names */
16812 +
16813 +static char *vx_vhi_name(struct vx_info *vxi, int id)
16814 +{
16815 +       struct nsproxy *nsproxy;
16816 +       struct uts_namespace *uts;
16817 +
16818 +       if (id == VHIN_CONTEXT)
16819 +               return vxi->vx_name;
16820 +
16821 +       nsproxy = vxi->space[0].vx_nsproxy;
16822 +       if (!nsproxy)
16823 +               return NULL;
16824 +
16825 +       uts = nsproxy->uts_ns;
16826 +       if (!uts)
16827 +               return NULL;
16828 +
16829 +       switch (id) {
16830 +       case VHIN_SYSNAME:
16831 +               return uts->name.sysname;
16832 +       case VHIN_NODENAME:
16833 +               return uts->name.nodename;
16834 +       case VHIN_RELEASE:
16835 +               return uts->name.release;
16836 +       case VHIN_VERSION:
16837 +               return uts->name.version;
16838 +       case VHIN_MACHINE:
16839 +               return uts->name.machine;
16840 +       case VHIN_DOMAINNAME:
16841 +               return uts->name.domainname;
16842 +       default:
16843 +               return NULL;
16844 +       }
16845 +       return NULL;
16846 +}
16847 +
16848 +int vc_set_vhi_name(struct vx_info *vxi, void __user *data)
16849 +{
16850 +       struct vcmd_vhi_name_v0 vc_data;
16851 +       char *name;
16852 +
16853 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16854 +               return -EFAULT;
16855 +
16856 +       name = vx_vhi_name(vxi, vc_data.field);
16857 +       if (!name)
16858 +               return -EINVAL;
16859 +
16860 +       memcpy(name, vc_data.name, 65);
16861 +       return 0;
16862 +}
16863 +
16864 +int vc_get_vhi_name(struct vx_info *vxi, void __user *data)
16865 +{
16866 +       struct vcmd_vhi_name_v0 vc_data;
16867 +       char *name;
16868 +
16869 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16870 +               return -EFAULT;
16871 +
16872 +       name = vx_vhi_name(vxi, vc_data.field);
16873 +       if (!name)
16874 +               return -EINVAL;
16875 +
16876 +       memcpy(vc_data.name, name, 65);
16877 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16878 +               return -EFAULT;
16879 +       return 0;
16880 +}
16881 +
16882 +
16883 +int vc_virt_stat(struct vx_info *vxi, void __user *data)
16884 +{
16885 +       struct vcmd_virt_stat_v0 vc_data;
16886 +       struct _vx_cvirt *cvirt = &vxi->cvirt;
16887 +       struct timespec uptime;
16888 +
16889 +       do_posix_clock_monotonic_gettime(&uptime);
16890 +       set_normalized_timespec(&uptime,
16891 +               uptime.tv_sec - cvirt->bias_uptime.tv_sec,
16892 +               uptime.tv_nsec - cvirt->bias_uptime.tv_nsec);
16893 +
16894 +       vc_data.offset = timespec_to_ns(&cvirt->bias_ts);
16895 +       vc_data.uptime = timespec_to_ns(&uptime);
16896 +       vc_data.nr_threads = atomic_read(&cvirt->nr_threads);
16897 +       vc_data.nr_running = atomic_read(&cvirt->nr_running);
16898 +       vc_data.nr_uninterruptible = atomic_read(&cvirt->nr_uninterruptible);
16899 +       vc_data.nr_onhold = atomic_read(&cvirt->nr_onhold);
16900 +       vc_data.nr_forks = atomic_read(&cvirt->total_forks);
16901 +       vc_data.load[0] = cvirt->load[0];
16902 +       vc_data.load[1] = cvirt->load[1];
16903 +       vc_data.load[2] = cvirt->load[2];
16904 +
16905 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16906 +               return -EFAULT;
16907 +       return 0;
16908 +}
16909 +
16910 +
16911 +#ifdef CONFIG_VSERVER_VTIME
16912 +
16913 +/* virtualized time base */
16914 +
16915 +void vx_adjust_timespec(struct timespec *ts)
16916 +{
16917 +       struct vx_info *vxi;
16918 +
16919 +       if (!vx_flags(VXF_VIRT_TIME, 0))
16920 +               return;
16921 +
16922 +       vxi = current_vx_info();
16923 +       ts->tv_sec += vxi->cvirt.bias_ts.tv_sec;
16924 +       ts->tv_nsec += vxi->cvirt.bias_ts.tv_nsec;
16925 +
16926 +       if (ts->tv_nsec >= NSEC_PER_SEC) {
16927 +               ts->tv_sec++;
16928 +               ts->tv_nsec -= NSEC_PER_SEC;
16929 +       } else if (ts->tv_nsec < 0) {
16930 +               ts->tv_sec--;
16931 +               ts->tv_nsec += NSEC_PER_SEC;
16932 +       }
16933 +}
16934 +
16935 +int vx_settimeofday(const struct timespec *ts)
16936 +{
16937 +       struct timespec ats, delta;
16938 +       struct vx_info *vxi;
16939 +
16940 +       if (!vx_flags(VXF_VIRT_TIME, 0))
16941 +               return do_settimeofday(ts);
16942 +
16943 +       getnstimeofday(&ats);
16944 +       delta = timespec_sub(*ts, ats);
16945 +
16946 +       vxi = current_vx_info();
16947 +       vxi->cvirt.bias_ts = timespec_add(vxi->cvirt.bias_ts, delta);
16948 +       return 0;
16949 +}
16950 +
16951 +#endif
16952 +
16953 diff -NurpP --minimal linux-3.6/kernel/vserver/cvirt_init.h linux-3.6-vs2.3.4.3-noxfs-nocow/kernel/vserver/cvirt_init.h
16954 --- linux-3.6/kernel/vserver/cvirt_init.h       1970-01-01 01:00:00.000000000 +0100
16955 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/kernel/vserver/cvirt_init.h 2012-10-04 18:47:00.000000000 +0200
16956 @@ -0,0 +1,70 @@
16957 +
16958 +
16959 +extern uint64_t vx_idle_jiffies(void);
16960 +
16961 +static inline void vx_info_init_cvirt(struct _vx_cvirt *cvirt)
16962 +{
16963 +       uint64_t idle_jiffies = vx_idle_jiffies();
16964 +       uint64_t nsuptime;
16965 +
16966 +       do_posix_clock_monotonic_gettime(&cvirt->bias_uptime);
16967 +       nsuptime = (unsigned long long)cvirt->bias_uptime.tv_sec
16968 +               * NSEC_PER_SEC + cvirt->bias_uptime.tv_nsec;
16969 +       cvirt->bias_clock = nsec_to_clock_t(nsuptime);
16970 +       cvirt->bias_ts.tv_sec = 0;
16971 +       cvirt->bias_ts.tv_nsec = 0;
16972 +
16973 +       jiffies_to_timespec(idle_jiffies, &cvirt->bias_idle);
16974 +       atomic_set(&cvirt->nr_threads, 0);
16975 +       atomic_set(&cvirt->nr_running, 0);
16976 +       atomic_set(&cvirt->nr_uninterruptible, 0);
16977 +       atomic_set(&cvirt->nr_onhold, 0);
16978 +
16979 +       spin_lock_init(&cvirt->load_lock);
16980 +       cvirt->load_last = jiffies;
16981 +       atomic_set(&cvirt->load_updates, 0);
16982 +       cvirt->load[0] = 0;
16983 +       cvirt->load[1] = 0;
16984 +       cvirt->load[2] = 0;
16985 +       atomic_set(&cvirt->total_forks, 0);
16986 +
16987 +       spin_lock_init(&cvirt->syslog.logbuf_lock);
16988 +       init_waitqueue_head(&cvirt->syslog.log_wait);
16989 +       cvirt->syslog.log_start = 0;
16990 +       cvirt->syslog.log_end = 0;
16991 +       cvirt->syslog.con_start = 0;
16992 +       cvirt->syslog.logged_chars = 0;
16993 +}
16994 +
16995 +static inline
16996 +void vx_info_init_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc, int cpu)
16997 +{
16998 +       // cvirt_pc->cpustat = { 0 };
16999 +}
17000 +
17001 +static inline void vx_info_exit_cvirt(struct _vx_cvirt *cvirt)
17002 +{
17003 +#ifdef CONFIG_VSERVER_WARN
17004 +       int value;
17005 +#endif
17006 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_threads)),
17007 +               "!!! cvirt: %p[nr_threads] = %d on exit.",
17008 +               cvirt, value);
17009 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_running)),
17010 +               "!!! cvirt: %p[nr_running] = %d on exit.",
17011 +               cvirt, value);
17012 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_uninterruptible)),
17013 +               "!!! cvirt: %p[nr_uninterruptible] = %d on exit.",
17014 +               cvirt, value);
17015 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_onhold)),
17016 +               "!!! cvirt: %p[nr_onhold] = %d on exit.",
17017 +               cvirt, value);
17018 +       return;
17019 +}
17020 +
17021 +static inline
17022 +void vx_info_exit_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc, int cpu)
17023 +{
17024 +       return;
17025 +}
17026 +
17027 diff -NurpP --minimal linux-3.6/kernel/vserver/cvirt_proc.h linux-3.6-vs2.3.4.3-noxfs-nocow/kernel/vserver/cvirt_proc.h
17028 --- linux-3.6/kernel/vserver/cvirt_proc.h       1970-01-01 01:00:00.000000000 +0100
17029 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/kernel/vserver/cvirt_proc.h 2012-10-04 18:47:00.000000000 +0200
17030 @@ -0,0 +1,123 @@
17031 +#ifndef _VX_CVIRT_PROC_H
17032 +#define _VX_CVIRT_PROC_H
17033 +
17034 +#include <linux/nsproxy.h>
17035 +#include <linux/mnt_namespace.h>
17036 +#include <linux/ipc_namespace.h>
17037 +#include <linux/utsname.h>
17038 +#include <linux/ipc.h>
17039 +
17040 +extern int vx_info_mnt_namespace(struct mnt_namespace *, char *);
17041 +
17042 +static inline
17043 +int vx_info_proc_nsproxy(struct nsproxy *nsproxy, char *buffer)
17044 +{
17045 +       struct mnt_namespace *ns;
17046 +       struct uts_namespace *uts;
17047 +       struct ipc_namespace *ipc;
17048 +       int length = 0;
17049 +
17050 +       if (!nsproxy)
17051 +               goto out;
17052 +
17053 +       length += sprintf(buffer + length,
17054 +               "NSProxy:\t%p [%p,%p,%p]\n",
17055 +               nsproxy, nsproxy->mnt_ns,
17056 +               nsproxy->uts_ns, nsproxy->ipc_ns);
17057 +
17058 +       ns = nsproxy->mnt_ns;
17059 +       if (!ns)
17060 +               goto skip_ns;
17061 +
17062 +       length += vx_info_mnt_namespace(ns, buffer + length);
17063 +
17064 +skip_ns:
17065 +
17066 +       uts = nsproxy->uts_ns;
17067 +       if (!uts)
17068 +               goto skip_uts;
17069 +
17070 +       length += sprintf(buffer + length,
17071 +               "SysName:\t%.*s\n"
17072 +               "NodeName:\t%.*s\n"
17073 +               "Release:\t%.*s\n"
17074 +               "Version:\t%.*s\n"
17075 +               "Machine:\t%.*s\n"
17076 +               "DomainName:\t%.*s\n",
17077 +               __NEW_UTS_LEN, uts->name.sysname,
17078 +               __NEW_UTS_LEN, uts->name.nodename,
17079 +               __NEW_UTS_LEN, uts->name.release,
17080 +               __NEW_UTS_LEN, uts->name.version,
17081 +               __NEW_UTS_LEN, uts->name.machine,
17082 +               __NEW_UTS_LEN, uts->name.domainname);
17083 +skip_uts:
17084 +
17085 +       ipc = nsproxy->ipc_ns;
17086 +       if (!ipc)
17087 +               goto skip_ipc;
17088 +
17089 +       length += sprintf(buffer + length,
17090 +               "SEMS:\t\t%d %d %d %d  %d\n"
17091 +               "MSG:\t\t%d %d %d\n"
17092 +               "SHM:\t\t%lu %lu  %d %d\n",
17093 +               ipc->sem_ctls[0], ipc->sem_ctls[1],
17094 +               ipc->sem_ctls[2], ipc->sem_ctls[3],
17095 +               ipc->used_sems,
17096 +               ipc->msg_ctlmax, ipc->msg_ctlmnb, ipc->msg_ctlmni,
17097 +               (unsigned long)ipc->shm_ctlmax,
17098 +               (unsigned long)ipc->shm_ctlall,
17099 +               ipc->shm_ctlmni, ipc->shm_tot);
17100 +skip_ipc:
17101 +out:
17102 +       return length;
17103 +}
17104 +
17105 +
17106 +#include <linux/sched.h>
17107 +
17108 +#define LOAD_INT(x) ((x) >> FSHIFT)
17109 +#define LOAD_FRAC(x) LOAD_INT(((x) & (FIXED_1 - 1)) * 100)
17110 +
17111 +static inline
17112 +int vx_info_proc_cvirt(struct _vx_cvirt *cvirt, char *buffer)
17113 +{
17114 +       int length = 0;
17115 +       int a, b, c;
17116 +
17117 +       length += sprintf(buffer + length,
17118 +               "BiasUptime:\t%lu.%02lu\n",
17119 +               (unsigned long)cvirt->bias_uptime.tv_sec,
17120 +               (cvirt->bias_uptime.tv_nsec / (NSEC_PER_SEC / 100)));
17121 +
17122 +       a = cvirt->load[0] + (FIXED_1 / 200);
17123 +       b = cvirt->load[1] + (FIXED_1 / 200);
17124 +       c = cvirt->load[2] + (FIXED_1 / 200);
17125 +       length += sprintf(buffer + length,
17126 +               "nr_threads:\t%d\n"
17127 +               "nr_running:\t%d\n"
17128 +               "nr_unintr:\t%d\n"
17129 +               "nr_onhold:\t%d\n"
17130 +               "load_updates:\t%d\n"
17131 +               "loadavg:\t%d.%02d %d.%02d %d.%02d\n"
17132 +               "total_forks:\t%d\n",
17133 +               atomic_read(&cvirt->nr_threads),
17134 +               atomic_read(&cvirt->nr_running),
17135 +               atomic_read(&cvirt->nr_uninterruptible),
17136 +               atomic_read(&cvirt->nr_onhold),
17137 +               atomic_read(&cvirt->load_updates),
17138 +               LOAD_INT(a), LOAD_FRAC(a),
17139 +               LOAD_INT(b), LOAD_FRAC(b),
17140 +               LOAD_INT(c), LOAD_FRAC(c),
17141 +               atomic_read(&cvirt->total_forks));
17142 +       return length;
17143 +}
17144 +
17145 +static inline
17146 +int vx_info_proc_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc,
17147 +       char *buffer, int cpu)
17148 +{
17149 +       int length = 0;
17150 +       return length;
17151 +}
17152 +
17153 +#endif /* _VX_CVIRT_PROC_H */
17154 diff -NurpP --minimal linux-3.6/kernel/vserver/debug.c linux-3.6-vs2.3.4.3-noxfs-nocow/kernel/vserver/debug.c
17155 --- linux-3.6/kernel/vserver/debug.c    1970-01-01 01:00:00.000000000 +0100
17156 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/kernel/vserver/debug.c      2012-10-04 18:47:00.000000000 +0200
17157 @@ -0,0 +1,32 @@
17158 +/*
17159 + *  kernel/vserver/debug.c
17160 + *
17161 + *  Copyright (C) 2005-2007 Herbert Pötzl
17162 + *
17163 + *  V0.01  vx_info dump support
17164 + *
17165 + */
17166 +
17167 +#include <linux/module.h>
17168 +
17169 +#include <linux/vserver/context.h>
17170 +
17171 +
17172 +void   dump_vx_info(struct vx_info *vxi, int level)
17173 +{
17174 +       printk("vx_info %p[#%d, %d.%d, %4x]\n", vxi, vxi->vx_id,
17175 +               atomic_read(&vxi->vx_usecnt),
17176 +               atomic_read(&vxi->vx_tasks),
17177 +               vxi->vx_state);
17178 +       if (level > 0) {
17179 +               __dump_vx_limit(&vxi->limit);
17180 +               __dump_vx_sched(&vxi->sched);
17181 +               __dump_vx_cvirt(&vxi->cvirt);
17182 +               __dump_vx_cacct(&vxi->cacct);
17183 +       }
17184 +       printk("---\n");
17185 +}
17186 +
17187 +
17188 +EXPORT_SYMBOL_GPL(dump_vx_info);
17189 +
17190 diff -NurpP --minimal linux-3.6/kernel/vserver/device.c linux-3.6-vs2.3.4.3-noxfs-nocow/kernel/vserver/device.c
17191 --- linux-3.6/kernel/vserver/device.c   1970-01-01 01:00:00.000000000 +0100
17192 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/kernel/vserver/device.c     2012-10-04 18:47:00.000000000 +0200
17193 @@ -0,0 +1,443 @@
17194 +/*
17195 + *  linux/kernel/vserver/device.c
17196 + *
17197 + *  Linux-VServer: Device Support
17198 + *
17199 + *  Copyright (C) 2006  Herbert Pötzl
17200 + *  Copyright (C) 2007  Daniel Hokka Zakrisson
17201 + *
17202 + *  V0.01  device mapping basics
17203 + *  V0.02  added defaults
17204 + *
17205 + */
17206 +
17207 +#include <linux/slab.h>
17208 +#include <linux/rcupdate.h>
17209 +#include <linux/fs.h>
17210 +#include <linux/namei.h>
17211 +#include <linux/hash.h>
17212 +
17213 +#include <asm/errno.h>
17214 +#include <asm/uaccess.h>
17215 +#include <linux/vserver/base.h>
17216 +#include <linux/vserver/debug.h>
17217 +#include <linux/vserver/context.h>
17218 +#include <linux/vserver/device.h>
17219 +#include <linux/vserver/device_cmd.h>
17220 +
17221 +
17222 +#define DMAP_HASH_BITS 4
17223 +
17224 +
17225 +struct vs_mapping {
17226 +       union {
17227 +               struct hlist_node hlist;
17228 +               struct list_head list;
17229 +       } u;
17230 +#define dm_hlist       u.hlist
17231 +#define dm_list                u.list
17232 +       xid_t xid;
17233 +       dev_t device;
17234 +       struct vx_dmap_target target;
17235 +};
17236 +
17237 +
17238 +static struct hlist_head dmap_main_hash[1 << DMAP_HASH_BITS];
17239 +
17240 +static DEFINE_SPINLOCK(dmap_main_hash_lock);
17241 +
17242 +static struct vx_dmap_target dmap_defaults[2] = {
17243 +       { .flags = DATTR_OPEN },
17244 +       { .flags = DATTR_OPEN },
17245 +};
17246 +
17247 +
17248 +struct kmem_cache *dmap_cachep __read_mostly;
17249 +
17250 +int __init dmap_cache_init(void)
17251 +{
17252 +       dmap_cachep = kmem_cache_create("dmap_cache",
17253 +               sizeof(struct vs_mapping), 0,
17254 +               SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
17255 +       return 0;
17256 +}
17257 +
17258 +__initcall(dmap_cache_init);
17259 +
17260 +
17261 +static inline unsigned int __hashval(dev_t dev, int bits)
17262 +{
17263 +       return hash_long((unsigned long)dev, bits);
17264 +}
17265 +
17266 +
17267 +/*     __hash_mapping()
17268 + *     add the mapping to the hash table
17269 + */
17270 +static inline void __hash_mapping(struct vx_info *vxi, struct vs_mapping *vdm)
17271 +{
17272 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
17273 +       struct hlist_head *head, *hash = dmap_main_hash;
17274 +       int device = vdm->device;
17275 +
17276 +       spin_lock(hash_lock);
17277 +       vxdprintk(VXD_CBIT(misc, 8), "__hash_mapping: %p[#%d] %08x:%08x",
17278 +               vxi, vxi ? vxi->vx_id : 0, device, vdm->target.target);
17279 +
17280 +       head = &hash[__hashval(device, DMAP_HASH_BITS)];
17281 +       hlist_add_head(&vdm->dm_hlist, head);
17282 +       spin_unlock(hash_lock);
17283 +}
17284 +
17285 +
17286 +static inline int __mode_to_default(umode_t mode)
17287 +{
17288 +       switch (mode) {
17289 +       case S_IFBLK:
17290 +               return 0;
17291 +       case S_IFCHR:
17292 +               return 1;
17293 +       default:
17294 +               BUG();
17295 +       }
17296 +}
17297 +
17298 +
17299 +/*     __set_default()
17300 + *     set a default
17301 + */
17302 +static inline void __set_default(struct vx_info *vxi, umode_t mode,
17303 +       struct vx_dmap_target *vdmt)
17304 +{
17305 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
17306 +       spin_lock(hash_lock);
17307 +
17308 +       if (vxi)
17309 +               vxi->dmap.targets[__mode_to_default(mode)] = *vdmt;
17310 +       else
17311 +               dmap_defaults[__mode_to_default(mode)] = *vdmt;
17312 +
17313 +
17314 +       spin_unlock(hash_lock);
17315 +
17316 +       vxdprintk(VXD_CBIT(misc, 8), "__set_default: %p[#%u] %08x %04x",
17317 +                 vxi, vxi ? vxi->vx_id : 0, vdmt->target, vdmt->flags);
17318 +}
17319 +
17320 +
17321 +/*     __remove_default()
17322 + *     remove a default
17323 + */
17324 +static inline int __remove_default(struct vx_info *vxi, umode_t mode)
17325 +{
17326 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
17327 +       spin_lock(hash_lock);
17328 +
17329 +       if (vxi)
17330 +               vxi->dmap.targets[__mode_to_default(mode)].flags = 0;
17331 +       else    /* remove == reset */
17332 +               dmap_defaults[__mode_to_default(mode)].flags = DATTR_OPEN | mode;
17333 +
17334 +       spin_unlock(hash_lock);
17335 +       return 0;
17336 +}
17337 +
17338 +
17339 +/*     __find_mapping()
17340 + *     find a mapping in the hash table
17341 + *
17342 + *     caller must hold hash_lock
17343 + */
17344 +static inline int __find_mapping(xid_t xid, dev_t device, umode_t mode,
17345 +       struct vs_mapping **local, struct vs_mapping **global)
17346 +{
17347 +       struct hlist_head *hash = dmap_main_hash;
17348 +       struct hlist_head *head = &hash[__hashval(device, DMAP_HASH_BITS)];
17349 +       struct hlist_node *pos;
17350 +       struct vs_mapping *vdm;
17351 +
17352 +       *local = NULL;
17353 +       if (global)
17354 +               *global = NULL;
17355 +
17356 +       hlist_for_each(pos, head) {
17357 +               vdm = hlist_entry(pos, struct vs_mapping, dm_hlist);
17358 +
17359 +               if ((vdm->device == device) &&
17360 +                       !((vdm->target.flags ^ mode) & S_IFMT)) {
17361 +                       if (vdm->xid == xid) {
17362 +                               *local = vdm;
17363 +                               return 1;
17364 +                       } else if (global && vdm->xid == 0)
17365 +                               *global = vdm;
17366 +               }
17367 +       }
17368 +
17369 +       if (global && *global)
17370 +               return 0;
17371 +       else
17372 +               return -ENOENT;
17373 +}
17374 +
17375 +
17376 +/*     __lookup_mapping()
17377 + *     find a mapping and store the result in target and flags
17378 + */
17379 +static inline int __lookup_mapping(struct vx_info *vxi,
17380 +       dev_t device, dev_t *target, int *flags, umode_t mode)
17381 +{
17382 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
17383 +       struct vs_mapping *vdm, *global;
17384 +       struct vx_dmap_target *vdmt;
17385 +       int ret = 0;
17386 +       xid_t xid = vxi->vx_id;
17387 +       int index;
17388 +
17389 +       spin_lock(hash_lock);
17390 +       if (__find_mapping(xid, device, mode, &vdm, &global) > 0) {
17391 +               ret = 1;
17392 +               vdmt = &vdm->target;
17393 +               goto found;
17394 +       }
17395 +
17396 +       index = __mode_to_default(mode);
17397 +       if (vxi && vxi->dmap.targets[index].flags) {
17398 +               ret = 2;
17399 +               vdmt = &vxi->dmap.targets[index];
17400 +       } else if (global) {
17401 +               ret = 3;
17402 +               vdmt = &global->target;
17403 +               goto found;
17404 +       } else {
17405 +               ret = 4;
17406 +               vdmt = &dmap_defaults[index];
17407 +       }
17408 +
17409 +found:
17410 +       if (target && (vdmt->flags & DATTR_REMAP))
17411 +               *target = vdmt->target;
17412 +       else if (target)
17413 +               *target = device;
17414 +       if (flags)
17415 +               *flags = vdmt->flags;
17416 +
17417 +       spin_unlock(hash_lock);
17418 +
17419 +       return ret;
17420 +}
17421 +
17422 +
17423 +/*     __remove_mapping()
17424 + *     remove a mapping from the hash table
17425 + */
17426 +static inline int __remove_mapping(struct vx_info *vxi, dev_t device,
17427 +       umode_t mode)
17428 +{
17429 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
17430 +       struct vs_mapping *vdm = NULL;
17431 +       int ret = 0;
17432 +
17433 +       spin_lock(hash_lock);
17434 +
17435 +       ret = __find_mapping((vxi ? vxi->vx_id : 0), device, mode, &vdm,
17436 +               NULL);
17437 +       vxdprintk(VXD_CBIT(misc, 8), "__remove_mapping: %p[#%d] %08x %04x",
17438 +               vxi, vxi ? vxi->vx_id : 0, device, mode);
17439 +       if (ret < 0)
17440 +               goto out;
17441 +       hlist_del(&vdm->dm_hlist);
17442 +
17443 +out:
17444 +       spin_unlock(hash_lock);
17445 +       if (vdm)
17446 +               kmem_cache_free(dmap_cachep, vdm);
17447 +       return ret;
17448 +}
17449 +
17450 +
17451 +
17452 +int vs_map_device(struct vx_info *vxi,
17453 +       dev_t device, dev_t *target, umode_t mode)
17454 +{
17455 +       int ret, flags = DATTR_MASK;
17456 +
17457 +       if (!vxi) {
17458 +               if (target)
17459 +                       *target = device;
17460 +               goto out;
17461 +       }
17462 +       ret = __lookup_mapping(vxi, device, target, &flags, mode);
17463 +       vxdprintk(VXD_CBIT(misc, 8), "vs_map_device: %08x target: %08x flags: %04x mode: %04x mapped=%d",
17464 +               device, target ? *target : 0, flags, mode, ret);
17465 +out:
17466 +       return (flags & DATTR_MASK);
17467 +}
17468 +
17469 +
17470 +
17471 +static int do_set_mapping(struct vx_info *vxi,
17472 +       dev_t device, dev_t target, int flags, umode_t mode)
17473 +{
17474 +       if (device) {
17475 +               struct vs_mapping *new;
17476 +
17477 +               new = kmem_cache_alloc(dmap_cachep, GFP_KERNEL);
17478 +               if (!new)
17479 +                       return -ENOMEM;
17480 +
17481 +               INIT_HLIST_NODE(&new->dm_hlist);
17482 +               new->device = device;
17483 +               new->target.target = target;
17484 +               new->target.flags = flags | mode;
17485 +               new->xid = (vxi ? vxi->vx_id : 0);
17486 +
17487 +               vxdprintk(VXD_CBIT(misc, 8), "do_set_mapping: %08x target: %08x flags: %04x", device, target, flags);
17488 +               __hash_mapping(vxi, new);
17489 +       } else {
17490 +               struct vx_dmap_target new = {
17491 +                       .target = target,
17492 +                       .flags = flags | mode,
17493 +               };
17494 +               __set_default(vxi, mode, &new);
17495 +       }
17496 +       return 0;
17497 +}
17498 +
17499 +
17500 +static int do_unset_mapping(struct vx_info *vxi,
17501 +       dev_t device, dev_t target, int flags, umode_t mode)
17502 +{
17503 +       int ret = -EINVAL;
17504 +
17505 +       if (device) {
17506 +               ret = __remove_mapping(vxi, device, mode);
17507 +               if (ret < 0)
17508 +                       goto out;
17509 +       } else {
17510 +               ret = __remove_default(vxi, mode);
17511 +               if (ret < 0)
17512 +                       goto out;
17513 +       }
17514 +
17515 +out:
17516 +       return ret;
17517 +}
17518 +
17519 +
17520 +static inline int __user_device(const char __user *name, dev_t *dev,
17521 +       umode_t *mode)
17522 +{
17523 +       struct nameidata nd;
17524 +       int ret;
17525 +
17526 +       if (!name) {
17527 +               *dev = 0;
17528 +               return 0;
17529 +       }
17530 +       ret = user_lpath(name, &nd.path);
17531 +       if (ret)
17532 +               return ret;
17533 +       if (nd.path.dentry->d_inode) {
17534 +               *dev = nd.path.dentry->d_inode->i_rdev;
17535 +               *mode = nd.path.dentry->d_inode->i_mode;
17536 +       }
17537 +       path_put(&nd.path);
17538 +       return 0;
17539 +}
17540 +
17541 +static inline int __mapping_mode(dev_t device, dev_t target,
17542 +       umode_t device_mode, umode_t target_mode, umode_t *mode)
17543 +{
17544 +       if (device)
17545 +               *mode = device_mode & S_IFMT;
17546 +       else if (target)
17547 +               *mode = target_mode & S_IFMT;
17548 +       else
17549 +               return -EINVAL;
17550 +
17551 +       /* if both given, device and target mode have to match */
17552 +       if (device && target &&
17553 +               ((device_mode ^ target_mode) & S_IFMT))
17554 +               return -EINVAL;
17555 +       return 0;
17556 +}
17557 +
17558 +
17559 +static inline int do_mapping(struct vx_info *vxi, const char __user *device_path,
17560 +       const char __user *target_path, int flags, int set)
17561 +{
17562 +       dev_t device = ~0, target = ~0;
17563 +       umode_t device_mode = 0, target_mode = 0, mode;
17564 +       int ret;
17565 +
17566 +       ret = __user_device(device_path, &device, &device_mode);
17567 +       if (ret)
17568 +               return ret;
17569 +       ret = __user_device(target_path, &target, &target_mode);
17570 +       if (ret)
17571 +               return ret;
17572 +
17573 +       ret = __mapping_mode(device, target,
17574 +               device_mode, target_mode, &mode);
17575 +       if (ret)
17576 +               return ret;
17577 +
17578 +       if (set)
17579 +               return do_set_mapping(vxi, device, target,
17580 +                       flags, mode);
17581 +       else
17582 +               return do_unset_mapping(vxi, device, target,
17583 +                       flags, mode);
17584 +}
17585 +
17586 +
17587 +int vc_set_mapping(struct vx_info *vxi, void __user *data)
17588 +{
17589 +       struct vcmd_set_mapping_v0 vc_data;
17590 +
17591 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17592 +               return -EFAULT;
17593 +
17594 +       return do_mapping(vxi, vc_data.device, vc_data.target,
17595 +               vc_data.flags, 1);
17596 +}
17597 +
17598 +int vc_unset_mapping(struct vx_info *vxi, void __user *data)
17599 +{
17600 +       struct vcmd_set_mapping_v0 vc_data;
17601 +
17602 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17603 +               return -EFAULT;
17604 +
17605 +       return do_mapping(vxi, vc_data.device, vc_data.target,
17606 +               vc_data.flags, 0);
17607 +}
17608 +
17609 +
17610 +#ifdef CONFIG_COMPAT
17611 +
17612 +int vc_set_mapping_x32(struct vx_info *vxi, void __user *data)
17613 +{
17614 +       struct vcmd_set_mapping_v0_x32 vc_data;
17615 +
17616 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17617 +               return -EFAULT;
17618 +
17619 +       return do_mapping(vxi, compat_ptr(vc_data.device_ptr),
17620 +               compat_ptr(vc_data.target_ptr), vc_data.flags, 1);
17621 +}
17622 +
17623 +int vc_unset_mapping_x32(struct vx_info *vxi, void __user *data)
17624 +{
17625 +       struct vcmd_set_mapping_v0_x32 vc_data;
17626 +
17627 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17628 +               return -EFAULT;
17629 +
17630 +       return do_mapping(vxi, compat_ptr(vc_data.device_ptr),
17631 +               compat_ptr(vc_data.target_ptr), vc_data.flags, 0);
17632 +}
17633 +
17634 +#endif /* CONFIG_COMPAT */
17635 +
17636 +
17637 diff -NurpP --minimal linux-3.6/kernel/vserver/dlimit.c linux-3.6-vs2.3.4.3-noxfs-nocow/kernel/vserver/dlimit.c
17638 --- linux-3.6/kernel/vserver/dlimit.c   1970-01-01 01:00:00.000000000 +0100
17639 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/kernel/vserver/dlimit.c     2012-10-04 18:47:00.000000000 +0200
17640 @@ -0,0 +1,531 @@
17641 +/*
17642 + *  linux/kernel/vserver/dlimit.c
17643 + *
17644 + *  Virtual Server: Context Disk Limits
17645 + *
17646 + *  Copyright (C) 2004-2009  Herbert Pötzl
17647 + *
17648 + *  V0.01  initial version
17649 + *  V0.02  compat32 splitup
17650 + *  V0.03  extended interface
17651 + *
17652 + */
17653 +
17654 +#include <linux/statfs.h>
17655 +#include <linux/sched.h>
17656 +#include <linux/namei.h>
17657 +#include <linux/vs_tag.h>
17658 +#include <linux/vs_dlimit.h>
17659 +#include <linux/vserver/dlimit_cmd.h>
17660 +#include <linux/slab.h>
17661 +// #include <linux/gfp.h>
17662 +
17663 +#include <asm/uaccess.h>
17664 +
17665 +/*     __alloc_dl_info()
17666 +
17667 +       * allocate an initialized dl_info struct
17668 +       * doesn't make it visible (hash)                        */
17669 +
17670 +static struct dl_info *__alloc_dl_info(struct super_block *sb, tag_t tag)
17671 +{
17672 +       struct dl_info *new = NULL;
17673 +
17674 +       vxdprintk(VXD_CBIT(dlim, 5),
17675 +               "alloc_dl_info(%p,%d)*", sb, tag);
17676 +
17677 +       /* would this benefit from a slab cache? */
17678 +       new = kmalloc(sizeof(struct dl_info), GFP_KERNEL);
17679 +       if (!new)
17680 +               return 0;
17681 +
17682 +       memset(new, 0, sizeof(struct dl_info));
17683 +       new->dl_tag = tag;
17684 +       new->dl_sb = sb;
17685 +       // INIT_RCU_HEAD(&new->dl_rcu);
17686 +       INIT_HLIST_NODE(&new->dl_hlist);
17687 +       spin_lock_init(&new->dl_lock);
17688 +       atomic_set(&new->dl_refcnt, 0);
17689 +       atomic_set(&new->dl_usecnt, 0);
17690 +
17691 +       /* rest of init goes here */
17692 +
17693 +       vxdprintk(VXD_CBIT(dlim, 4),
17694 +               "alloc_dl_info(%p,%d) = %p", sb, tag, new);
17695 +       return new;
17696 +}
17697 +
17698 +/*     __dealloc_dl_info()
17699 +
17700 +       * final disposal of dl_info                             */
17701 +
17702 +static void __dealloc_dl_info(struct dl_info *dli)
17703 +{
17704 +       vxdprintk(VXD_CBIT(dlim, 4),
17705 +               "dealloc_dl_info(%p)", dli);
17706 +
17707 +       dli->dl_hlist.next = LIST_POISON1;
17708 +       dli->dl_tag = -1;
17709 +       dli->dl_sb = 0;
17710 +
17711 +       BUG_ON(atomic_read(&dli->dl_usecnt));
17712 +       BUG_ON(atomic_read(&dli->dl_refcnt));
17713 +
17714 +       kfree(dli);
17715 +}
17716 +
17717 +
17718 +/*     hash table for dl_info hash */
17719 +
17720 +#define DL_HASH_SIZE   13
17721 +
17722 +struct hlist_head dl_info_hash[DL_HASH_SIZE];
17723 +
17724 +static DEFINE_SPINLOCK(dl_info_hash_lock);
17725 +
17726 +
17727 +static inline unsigned int __hashval(struct super_block *sb, tag_t tag)
17728 +{
17729 +       return ((tag ^ (unsigned long)sb) % DL_HASH_SIZE);
17730 +}
17731 +
17732 +
17733 +
17734 +/*     __hash_dl_info()
17735 +
17736 +       * add the dli to the global hash table
17737 +       * requires the hash_lock to be held                     */
17738 +
17739 +static inline void __hash_dl_info(struct dl_info *dli)
17740 +{
17741 +       struct hlist_head *head;
17742 +
17743 +       vxdprintk(VXD_CBIT(dlim, 6),
17744 +               "__hash_dl_info: %p[#%d]", dli, dli->dl_tag);
17745 +       get_dl_info(dli);
17746 +       head = &dl_info_hash[__hashval(dli->dl_sb, dli->dl_tag)];
17747 +       hlist_add_head_rcu(&dli->dl_hlist, head);
17748 +}
17749 +
17750 +/*     __unhash_dl_info()
17751 +
17752 +       * remove the dli from the global hash table
17753 +       * requires the hash_lock to be held                     */
17754 +
17755 +static inline void __unhash_dl_info(struct dl_info *dli)
17756 +{
17757 +       vxdprintk(VXD_CBIT(dlim, 6),
17758 +               "__unhash_dl_info: %p[#%d]", dli, dli->dl_tag);
17759 +       hlist_del_rcu(&dli->dl_hlist);
17760 +       put_dl_info(dli);
17761 +}
17762 +
17763 +
17764 +/*     __lookup_dl_info()
17765 +
17766 +       * requires the rcu_read_lock()
17767 +       * doesn't increment the dl_refcnt                       */
17768 +
17769 +static inline struct dl_info *__lookup_dl_info(struct super_block *sb, tag_t tag)
17770 +{
17771 +       struct hlist_head *head = &dl_info_hash[__hashval(sb, tag)];
17772 +       struct hlist_node *pos;
17773 +       struct dl_info *dli;
17774 +
17775 +       hlist_for_each_entry_rcu(dli, pos, head, dl_hlist) {
17776 +
17777 +               if (dli->dl_tag == tag && dli->dl_sb == sb) {
17778 +                       return dli;
17779 +               }
17780 +       }
17781 +       return NULL;
17782 +}
17783 +
17784 +
17785 +struct dl_info *locate_dl_info(struct super_block *sb, tag_t tag)
17786 +{
17787 +       struct dl_info *dli;
17788 +
17789 +       rcu_read_lock();
17790 +       dli = get_dl_info(__lookup_dl_info(sb, tag));
17791 +       vxdprintk(VXD_CBIT(dlim, 7),
17792 +               "locate_dl_info(%p,#%d) = %p", sb, tag, dli);
17793 +       rcu_read_unlock();
17794 +       return dli;
17795 +}
17796 +
17797 +void rcu_free_dl_info(struct rcu_head *head)
17798 +{
17799 +       struct dl_info *dli = container_of(head, struct dl_info, dl_rcu);
17800 +       int usecnt, refcnt;
17801 +
17802 +       BUG_ON(!dli || !head);
17803 +
17804 +       usecnt = atomic_read(&dli->dl_usecnt);
17805 +       BUG_ON(usecnt < 0);
17806 +
17807 +       refcnt = atomic_read(&dli->dl_refcnt);
17808 +       BUG_ON(refcnt < 0);
17809 +
17810 +       vxdprintk(VXD_CBIT(dlim, 3),
17811 +               "rcu_free_dl_info(%p)", dli);
17812 +       if (!usecnt)
17813 +               __dealloc_dl_info(dli);
17814 +       else
17815 +               printk("!!! rcu didn't free\n");
17816 +}
17817 +
17818 +
17819 +
17820 +
17821 +static int do_addrem_dlimit(uint32_t id, const char __user *name,
17822 +       uint32_t flags, int add)
17823 +{
17824 +       struct path path;
17825 +       int ret;
17826 +
17827 +       ret = user_lpath(name, &path);
17828 +       if (!ret) {
17829 +               struct super_block *sb;
17830 +               struct dl_info *dli;
17831 +
17832 +               ret = -EINVAL;
17833 +               if (!path.dentry->d_inode)
17834 +                       goto out_release;
17835 +               if (!(sb = path.dentry->d_inode->i_sb))
17836 +                       goto out_release;
17837 +
17838 +               if (add) {
17839 +                       dli = __alloc_dl_info(sb, id);
17840 +                       spin_lock(&dl_info_hash_lock);
17841 +
17842 +                       ret = -EEXIST;
17843 +                       if (__lookup_dl_info(sb, id))
17844 +                               goto out_unlock;
17845 +                       __hash_dl_info(dli);
17846 +                       dli = NULL;
17847 +               } else {
17848 +                       spin_lock(&dl_info_hash_lock);
17849 +                       dli = __lookup_dl_info(sb, id);
17850 +
17851 +                       ret = -ESRCH;
17852 +                       if (!dli)
17853 +                               goto out_unlock;
17854 +                       __unhash_dl_info(dli);
17855 +               }
17856 +               ret = 0;
17857 +       out_unlock:
17858 +               spin_unlock(&dl_info_hash_lock);
17859 +               if (add && dli)
17860 +                       __dealloc_dl_info(dli);
17861 +       out_release:
17862 +               path_put(&path);
17863 +       }
17864 +       return ret;
17865 +}
17866 +
17867 +int vc_add_dlimit(uint32_t id, void __user *data)
17868 +{
17869 +       struct vcmd_ctx_dlimit_base_v0 vc_data;
17870 +
17871 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17872 +               return -EFAULT;
17873 +
17874 +       return do_addrem_dlimit(id, vc_data.name, vc_data.flags, 1);
17875 +}
17876 +
17877 +int vc_rem_dlimit(uint32_t id, void __user *data)
17878 +{
17879 +       struct vcmd_ctx_dlimit_base_v0 vc_data;
17880 +
17881 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17882 +               return -EFAULT;
17883 +
17884 +       return do_addrem_dlimit(id, vc_data.name, vc_data.flags, 0);
17885 +}
17886 +
17887 +#ifdef CONFIG_COMPAT
17888 +
17889 +int vc_add_dlimit_x32(uint32_t id, void __user *data)
17890 +{
17891 +       struct vcmd_ctx_dlimit_base_v0_x32 vc_data;
17892 +
17893 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17894 +               return -EFAULT;
17895 +
17896 +       return do_addrem_dlimit(id,
17897 +               compat_ptr(vc_data.name_ptr), vc_data.flags, 1);
17898 +}
17899 +
17900 +int vc_rem_dlimit_x32(uint32_t id, void __user *data)
17901 +{
17902 +       struct vcmd_ctx_dlimit_base_v0_x32 vc_data;
17903 +
17904 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17905 +               return -EFAULT;
17906 +
17907 +       return do_addrem_dlimit(id,
17908 +               compat_ptr(vc_data.name_ptr), vc_data.flags, 0);
17909 +}
17910 +
17911 +#endif /* CONFIG_COMPAT */
17912 +
17913 +
17914 +static inline
17915 +int do_set_dlimit(uint32_t id, const char __user *name,
17916 +       uint32_t space_used, uint32_t space_total,
17917 +       uint32_t inodes_used, uint32_t inodes_total,
17918 +       uint32_t reserved, uint32_t flags)
17919 +{
17920 +       struct path path;
17921 +       int ret;
17922 +
17923 +       ret = user_lpath(name, &path);
17924 +       if (!ret) {
17925 +               struct super_block *sb;
17926 +               struct dl_info *dli;
17927 +
17928 +               ret = -EINVAL;
17929 +               if (!path.dentry->d_inode)
17930 +                       goto out_release;
17931 +               if (!(sb = path.dentry->d_inode->i_sb))
17932 +                       goto out_release;
17933 +
17934 +               /* sanity checks */
17935 +               if ((reserved != CDLIM_KEEP &&
17936 +                       reserved > 100) ||
17937 +                       (inodes_used != CDLIM_KEEP &&
17938 +                       inodes_used > inodes_total) ||
17939 +                       (space_used != CDLIM_KEEP &&
17940 +                       space_used > space_total))
17941 +                       goto out_release;
17942 +
17943 +               ret = -ESRCH;
17944 +               dli = locate_dl_info(sb, id);
17945 +               if (!dli)
17946 +                       goto out_release;
17947 +
17948 +               spin_lock(&dli->dl_lock);
17949 +
17950 +               if (inodes_used != CDLIM_KEEP)
17951 +                       dli->dl_inodes_used = inodes_used;
17952 +               if (inodes_total != CDLIM_KEEP)
17953 +                       dli->dl_inodes_total = inodes_total;
17954 +               if (space_used != CDLIM_KEEP)
17955 +                       dli->dl_space_used = dlimit_space_32to64(
17956 +                               space_used, flags, DLIMS_USED);
17957 +
17958 +               if (space_total == CDLIM_INFINITY)
17959 +                       dli->dl_space_total = DLIM_INFINITY;
17960 +               else if (space_total != CDLIM_KEEP)
17961 +                       dli->dl_space_total = dlimit_space_32to64(
17962 +                               space_total, flags, DLIMS_TOTAL);
17963 +
17964 +               if (reserved != CDLIM_KEEP)
17965 +                       dli->dl_nrlmult = (1 << 10) * (100 - reserved) / 100;
17966 +
17967 +               spin_unlock(&dli->dl_lock);
17968 +
17969 +               put_dl_info(dli);
17970 +               ret = 0;
17971 +
17972 +       out_release:
17973 +               path_put(&path);
17974 +       }
17975 +       return ret;
17976 +}
17977 +
17978 +int vc_set_dlimit(uint32_t id, void __user *data)
17979 +{
17980 +       struct vcmd_ctx_dlimit_v0 vc_data;
17981 +
17982 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17983 +               return -EFAULT;
17984 +
17985 +       return do_set_dlimit(id, vc_data.name,
17986 +               vc_data.space_used, vc_data.space_total,
17987 +               vc_data.inodes_used, vc_data.inodes_total,
17988 +               vc_data.reserved, vc_data.flags);
17989 +}
17990 +
17991 +#ifdef CONFIG_COMPAT
17992 +
17993 +int vc_set_dlimit_x32(uint32_t id, void __user *data)
17994 +{
17995 +       struct vcmd_ctx_dlimit_v0_x32 vc_data;
17996 +
17997 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17998 +               return -EFAULT;
17999 +
18000 +       return do_set_dlimit(id, compat_ptr(vc_data.name_ptr),
18001 +               vc_data.space_used, vc_data.space_total,
18002 +               vc_data.inodes_used, vc_data.inodes_total,
18003 +               vc_data.reserved, vc_data.flags);
18004 +}
18005 +
18006 +#endif /* CONFIG_COMPAT */
18007 +
18008 +
18009 +static inline
18010 +int do_get_dlimit(uint32_t id, const char __user *name,
18011 +       uint32_t *space_used, uint32_t *space_total,
18012 +       uint32_t *inodes_used, uint32_t *inodes_total,
18013 +       uint32_t *reserved, uint32_t *flags)
18014 +{
18015 +       struct path path;
18016 +       int ret;
18017 +
18018 +       ret = user_lpath(name, &path);
18019 +       if (!ret) {
18020 +               struct super_block *sb;
18021 +               struct dl_info *dli;
18022 +
18023 +               ret = -EINVAL;
18024 +               if (!path.dentry->d_inode)
18025 +                       goto out_release;
18026 +               if (!(sb = path.dentry->d_inode->i_sb))
18027 +                       goto out_release;
18028 +
18029 +               ret = -ESRCH;
18030 +               dli = locate_dl_info(sb, id);
18031 +               if (!dli)
18032 +                       goto out_release;
18033 +
18034 +               spin_lock(&dli->dl_lock);
18035 +               *inodes_used = dli->dl_inodes_used;
18036 +               *inodes_total = dli->dl_inodes_total;
18037 +
18038 +               *space_used = dlimit_space_64to32(
18039 +                       dli->dl_space_used, flags, DLIMS_USED);
18040 +
18041 +               if (dli->dl_space_total == DLIM_INFINITY)
18042 +                       *space_total = CDLIM_INFINITY;
18043 +               else
18044 +                       *space_total = dlimit_space_64to32(
18045 +                               dli->dl_space_total, flags, DLIMS_TOTAL);
18046 +
18047 +               *reserved = 100 - ((dli->dl_nrlmult * 100 + 512) >> 10);
18048 +               spin_unlock(&dli->dl_lock);
18049 +
18050 +               put_dl_info(dli);
18051 +               ret = -EFAULT;
18052 +
18053 +               ret = 0;
18054 +       out_release:
18055 +               path_put(&path);
18056 +       }
18057 +       return ret;
18058 +}
18059 +
18060 +
18061 +int vc_get_dlimit(uint32_t id, void __user *data)
18062 +{
18063 +       struct vcmd_ctx_dlimit_v0 vc_data;
18064 +       int ret;
18065 +
18066 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18067 +               return -EFAULT;
18068 +
18069 +       ret = do_get_dlimit(id, vc_data.name,
18070 +               &vc_data.space_used, &vc_data.space_total,
18071 +               &vc_data.inodes_used, &vc_data.inodes_total,
18072 +               &vc_data.reserved, &vc_data.flags);
18073 +       if (ret)
18074 +               return ret;
18075 +
18076 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18077 +               return -EFAULT;
18078 +       return 0;
18079 +}
18080 +
18081 +#ifdef CONFIG_COMPAT
18082 +
18083 +int vc_get_dlimit_x32(uint32_t id, void __user *data)
18084 +{
18085 +       struct vcmd_ctx_dlimit_v0_x32 vc_data;
18086 +       int ret;
18087 +
18088 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18089 +               return -EFAULT;
18090 +
18091 +       ret = do_get_dlimit(id, compat_ptr(vc_data.name_ptr),
18092 +               &vc_data.space_used, &vc_data.space_total,
18093 +               &vc_data.inodes_used, &vc_data.inodes_total,
18094 +               &vc_data.reserved, &vc_data.flags);
18095 +       if (ret)
18096 +               return ret;
18097 +
18098 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18099 +               return -EFAULT;
18100 +       return 0;
18101 +}
18102 +
18103 +#endif /* CONFIG_COMPAT */
18104 +
18105 +
18106 +void vx_vsi_statfs(struct super_block *sb, struct kstatfs *buf)
18107 +{
18108 +       struct dl_info *dli;
18109 +       __u64 blimit, bfree, bavail;
18110 +       __u32 ifree;
18111 +
18112 +       dli = locate_dl_info(sb, dx_current_tag());
18113 +       if (!dli)
18114 +               return;
18115 +
18116 +       spin_lock(&dli->dl_lock);
18117 +       if (dli->dl_inodes_total == (unsigned long)DLIM_INFINITY)
18118 +               goto no_ilim;
18119 +
18120 +       /* reduce max inodes available to limit */
18121 +       if (buf->f_files > dli->dl_inodes_total)
18122 +               buf->f_files = dli->dl_inodes_total;
18123 +
18124 +       ifree = dli->dl_inodes_total - dli->dl_inodes_used;
18125 +       /* reduce free inodes to min */
18126 +       if (ifree < buf->f_ffree)
18127 +               buf->f_ffree = ifree;
18128 +
18129 +no_ilim:
18130 +       if (dli->dl_space_total == DLIM_INFINITY)
18131 +               goto no_blim;
18132 +
18133 +       blimit = dli->dl_space_total >> sb->s_blocksize_bits;
18134 +
18135 +       if (dli->dl_space_total < dli->dl_space_used)
18136 +               bfree = 0;
18137 +       else
18138 +               bfree = (dli->dl_space_total - dli->dl_space_used)
18139 +                       >> sb->s_blocksize_bits;
18140 +
18141 +       bavail = ((dli->dl_space_total >> 10) * dli->dl_nrlmult);
18142 +       if (bavail < dli->dl_space_used)
18143 +               bavail = 0;
18144 +       else
18145 +               bavail = (bavail - dli->dl_space_used)
18146 +                       >> sb->s_blocksize_bits;
18147 +
18148 +       /* reduce max space available to limit */
18149 +       if (buf->f_blocks > blimit)
18150 +               buf->f_blocks = blimit;
18151 +
18152 +       /* reduce free space to min */
18153 +       if (bfree < buf->f_bfree)
18154 +               buf->f_bfree = bfree;
18155 +
18156 +       /* reduce avail space to min */
18157 +       if (bavail < buf->f_bavail)
18158 +               buf->f_bavail = bavail;
18159 +
18160 +no_blim:
18161 +       spin_unlock(&dli->dl_lock);
18162 +       put_dl_info(dli);
18163 +
18164 +       return;
18165 +}
18166 +
18167 +#include <linux/module.h>
18168 +
18169 +EXPORT_SYMBOL_GPL(locate_dl_info);
18170 +EXPORT_SYMBOL_GPL(rcu_free_dl_info);
18171 +
18172 diff -NurpP --minimal linux-3.6/kernel/vserver/helper.c linux-3.6-vs2.3.4.3-noxfs-nocow/kernel/vserver/helper.c
18173 --- linux-3.6/kernel/vserver/helper.c   1970-01-01 01:00:00.000000000 +0100
18174 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/kernel/vserver/helper.c     2012-10-04 18:47:00.000000000 +0200
18175 @@ -0,0 +1,229 @@
18176 +/*
18177 + *  linux/kernel/vserver/helper.c
18178 + *
18179 + *  Virtual Context Support
18180 + *
18181 + *  Copyright (C) 2004-2007  Herbert Pötzl
18182 + *
18183 + *  V0.01  basic helper
18184 + *
18185 + */
18186 +
18187 +#include <linux/kmod.h>
18188 +#include <linux/reboot.h>
18189 +#include <linux/vs_context.h>
18190 +#include <linux/vs_network.h>
18191 +#include <linux/vserver/signal.h>
18192 +
18193 +
18194 +char vshelper_path[255] = "/sbin/vshelper";
18195 +
18196 +static int vshelper_init(struct subprocess_info *info, struct cred *new_cred)
18197 +{
18198 +       current->flags &= ~PF_THREAD_BOUND;
18199 +       return 0;
18200 +}
18201 +
18202 +static int do_vshelper(char *name, char *argv[], char *envp[], int sync)
18203 +{
18204 +       int ret;
18205 +
18206 +       if ((ret = call_usermodehelper_fns(name, argv, envp,
18207 +               sync ? UMH_WAIT_PROC : UMH_WAIT_EXEC,
18208 +               vshelper_init, NULL, NULL))) {
18209 +               printk(KERN_WARNING "%s: (%s %s) returned %s with %d\n",
18210 +                       name, argv[1], argv[2],
18211 +                       sync ? "sync" : "async", ret);
18212 +       }
18213 +       vxdprintk(VXD_CBIT(switch, 4),
18214 +               "%s: (%s %s) returned %s with %d",
18215 +               name, argv[1], argv[2], sync ? "sync" : "async", ret);
18216 +       return ret;
18217 +}
18218 +
18219 +/*
18220 + *      vshelper path is set via /proc/sys
18221 + *      invoked by vserver sys_reboot(), with
18222 + *      the following arguments
18223 + *
18224 + *      argv [0] = vshelper_path;
18225 + *      argv [1] = action: "restart", "halt", "poweroff", ...
18226 + *      argv [2] = context identifier
18227 + *
18228 + *      envp [*] = type-specific parameters
18229 + */
18230 +
18231 +long vs_reboot_helper(struct vx_info *vxi, int cmd, void __user *arg)
18232 +{
18233 +       char id_buf[8], cmd_buf[16];
18234 +       char uid_buf[16], pid_buf[16];
18235 +       int ret;
18236 +
18237 +       char *argv[] = {vshelper_path, NULL, id_buf, 0};
18238 +       char *envp[] = {"HOME=/", "TERM=linux",
18239 +                       "PATH=/sbin:/usr/sbin:/bin:/usr/bin",
18240 +                       uid_buf, pid_buf, cmd_buf, 0};
18241 +
18242 +       if (vx_info_state(vxi, VXS_HELPER))
18243 +               return -EAGAIN;
18244 +       vxi->vx_state |= VXS_HELPER;
18245 +
18246 +       snprintf(id_buf, sizeof(id_buf), "%d", vxi->vx_id);
18247 +
18248 +       snprintf(cmd_buf, sizeof(cmd_buf), "VS_CMD=%08x", cmd);
18249 +       snprintf(uid_buf, sizeof(uid_buf), "VS_UID=%d", current_uid());
18250 +       snprintf(pid_buf, sizeof(pid_buf), "VS_PID=%d", current->pid);
18251 +
18252 +       switch (cmd) {
18253 +       case LINUX_REBOOT_CMD_RESTART:
18254 +               argv[1] = "restart";
18255 +               break;
18256 +
18257 +       case LINUX_REBOOT_CMD_HALT:
18258 +               argv[1] = "halt";
18259 +               break;
18260 +
18261 +       case LINUX_REBOOT_CMD_POWER_OFF:
18262 +               argv[1] = "poweroff";
18263 +               break;
18264 +
18265 +       case LINUX_REBOOT_CMD_SW_SUSPEND:
18266 +               argv[1] = "swsusp";
18267 +               break;
18268 +
18269 +       case LINUX_REBOOT_CMD_OOM:
18270 +               argv[1] = "oom";
18271 +               break;
18272 +
18273 +       default:
18274 +               vxi->vx_state &= ~VXS_HELPER;
18275 +               return 0;
18276 +       }
18277 +
18278 +       ret = do_vshelper(vshelper_path, argv, envp, 0);
18279 +       vxi->vx_state &= ~VXS_HELPER;
18280 +       __wakeup_vx_info(vxi);
18281 +       return (ret) ? -EPERM : 0;
18282 +}
18283 +
18284 +
18285 +long vs_reboot(unsigned int cmd, void __user *arg)
18286 +{
18287 +       struct vx_info *vxi = current_vx_info();
18288 +       long ret = 0;
18289 +
18290 +       vxdprintk(VXD_CBIT(misc, 5),
18291 +               "vs_reboot(%p[#%d],%u)",
18292 +               vxi, vxi ? vxi->vx_id : 0, cmd);
18293 +
18294 +       ret = vs_reboot_helper(vxi, cmd, arg);
18295 +       if (ret)
18296 +               return ret;
18297 +
18298 +       vxi->reboot_cmd = cmd;
18299 +       if (vx_info_flags(vxi, VXF_REBOOT_KILL, 0)) {
18300 +               switch (cmd) {
18301 +               case LINUX_REBOOT_CMD_RESTART:
18302 +               case LINUX_REBOOT_CMD_HALT:
18303 +               case LINUX_REBOOT_CMD_POWER_OFF:
18304 +                       vx_info_kill(vxi, 0, SIGKILL);
18305 +                       vx_info_kill(vxi, 1, SIGKILL);
18306 +               default:
18307 +                       break;
18308 +               }
18309 +       }
18310 +       return 0;
18311 +}
18312 +
18313 +long vs_oom_action(unsigned int cmd)
18314 +{
18315 +       struct vx_info *vxi = current_vx_info();
18316 +       long ret = 0;
18317 +
18318 +       vxdprintk(VXD_CBIT(misc, 5),
18319 +               "vs_oom_action(%p[#%d],%u)",
18320 +               vxi, vxi ? vxi->vx_id : 0, cmd);
18321 +
18322 +       ret = vs_reboot_helper(vxi, cmd, NULL);
18323 +       if (ret)
18324 +               return ret;
18325 +
18326 +       vxi->reboot_cmd = cmd;
18327 +       if (vx_info_flags(vxi, VXF_REBOOT_KILL, 0)) {
18328 +               vx_info_kill(vxi, 0, SIGKILL);
18329 +               vx_info_kill(vxi, 1, SIGKILL);
18330 +       }
18331 +       return 0;
18332 +}
18333 +
18334 +/*
18335 + *      argv [0] = vshelper_path;
18336 + *      argv [1] = action: "startup", "shutdown"
18337 + *      argv [2] = context identifier
18338 + *
18339 + *      envp [*] = type-specific parameters
18340 + */
18341 +
18342 +long vs_state_change(struct vx_info *vxi, unsigned int cmd)
18343 +{
18344 +       char id_buf[8], cmd_buf[16];
18345 +       char *argv[] = {vshelper_path, NULL, id_buf, 0};
18346 +       char *envp[] = {"HOME=/", "TERM=linux",
18347 +                       "PATH=/sbin:/usr/sbin:/bin:/usr/bin", cmd_buf, 0};
18348 +
18349 +       if (!vx_info_flags(vxi, VXF_SC_HELPER, 0))
18350 +               return 0;
18351 +
18352 +       snprintf(id_buf, sizeof(id_buf), "%d", vxi->vx_id);
18353 +       snprintf(cmd_buf, sizeof(cmd_buf), "VS_CMD=%08x", cmd);
18354 +
18355 +       switch (cmd) {
18356 +       case VSC_STARTUP:
18357 +               argv[1] = "startup";
18358 +               break;
18359 +       case VSC_SHUTDOWN:
18360 +               argv[1] = "shutdown";
18361 +               break;
18362 +       default:
18363 +               return 0;
18364 +       }
18365 +
18366 +       return do_vshelper(vshelper_path, argv, envp, 1);
18367 +}
18368 +
18369 +
18370 +/*
18371 + *      argv [0] = vshelper_path;
18372 + *      argv [1] = action: "netup", "netdown"
18373 + *      argv [2] = context identifier
18374 + *
18375 + *      envp [*] = type-specific parameters
18376 + */
18377 +
18378 +long vs_net_change(struct nx_info *nxi, unsigned int cmd)
18379 +{
18380 +       char id_buf[8], cmd_buf[16];
18381 +       char *argv[] = {vshelper_path, NULL, id_buf, 0};
18382 +       char *envp[] = {"HOME=/", "TERM=linux",
18383 +                       "PATH=/sbin:/usr/sbin:/bin:/usr/bin", cmd_buf, 0};
18384 +
18385 +       if (!nx_info_flags(nxi, NXF_SC_HELPER, 0))
18386 +               return 0;
18387 +
18388 +       snprintf(id_buf, sizeof(id_buf), "%d", nxi->nx_id);
18389 +       snprintf(cmd_buf, sizeof(cmd_buf), "VS_CMD=%08x", cmd);
18390 +
18391 +       switch (cmd) {
18392 +       case VSC_NETUP:
18393 +               argv[1] = "netup";
18394 +               break;
18395 +       case VSC_NETDOWN:
18396 +               argv[1] = "netdown";
18397 +               break;
18398 +       default:
18399 +               return 0;
18400 +       }
18401 +
18402 +       return do_vshelper(vshelper_path, argv, envp, 1);
18403 +}
18404 +
18405 diff -NurpP --minimal linux-3.6/kernel/vserver/history.c linux-3.6-vs2.3.4.3-noxfs-nocow/kernel/vserver/history.c
18406 --- linux-3.6/kernel/vserver/history.c  1970-01-01 01:00:00.000000000 +0100
18407 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/kernel/vserver/history.c    2012-10-04 18:47:00.000000000 +0200
18408 @@ -0,0 +1,258 @@
18409 +/*
18410 + *  kernel/vserver/history.c
18411 + *
18412 + *  Virtual Context History Backtrace
18413 + *
18414 + *  Copyright (C) 2004-2007  Herbert Pötzl
18415 + *
18416 + *  V0.01  basic structure
18417 + *  V0.02  hash/unhash and trace
18418 + *  V0.03  preemption fixes
18419 + *
18420 + */
18421 +
18422 +#include <linux/module.h>
18423 +#include <asm/uaccess.h>
18424 +
18425 +#include <linux/vserver/context.h>
18426 +#include <linux/vserver/debug.h>
18427 +#include <linux/vserver/debug_cmd.h>
18428 +#include <linux/vserver/history.h>
18429 +
18430 +
18431 +#ifdef CONFIG_VSERVER_HISTORY
18432 +#define VXH_SIZE       CONFIG_VSERVER_HISTORY_SIZE
18433 +#else
18434 +#define VXH_SIZE       64
18435 +#endif
18436 +
18437 +struct _vx_history {
18438 +       unsigned int counter;
18439 +
18440 +       struct _vx_hist_entry entry[VXH_SIZE + 1];
18441 +};
18442 +
18443 +
18444 +DEFINE_PER_CPU(struct _vx_history, vx_history_buffer);
18445 +
18446 +unsigned volatile int vxh_active = 1;
18447 +
18448 +static atomic_t sequence = ATOMIC_INIT(0);
18449 +
18450 +
18451 +/*     vxh_advance()
18452 +
18453 +       * requires disabled preemption                          */
18454 +
18455 +struct _vx_hist_entry *vxh_advance(void *loc)
18456 +{
18457 +       unsigned int cpu = smp_processor_id();
18458 +       struct _vx_history *hist = &per_cpu(vx_history_buffer, cpu);
18459 +       struct _vx_hist_entry *entry;
18460 +       unsigned int index;
18461 +
18462 +       index = vxh_active ? (hist->counter++ % VXH_SIZE) : VXH_SIZE;
18463 +       entry = &hist->entry[index];
18464 +
18465 +       entry->seq = atomic_inc_return(&sequence);
18466 +       entry->loc = loc;
18467 +       return entry;
18468 +}
18469 +
18470 +EXPORT_SYMBOL_GPL(vxh_advance);
18471 +
18472 +
18473 +#define VXH_LOC_FMTS   "(#%04x,*%d):%p"
18474 +
18475 +#define VXH_LOC_ARGS(e)        (e)->seq, cpu, (e)->loc
18476 +
18477 +
18478 +#define VXH_VXI_FMTS   "%p[#%d,%d.%d]"
18479 +
18480 +#define VXH_VXI_ARGS(e)        (e)->vxi.ptr,                           \
18481 +                       (e)->vxi.ptr ? (e)->vxi.xid : 0,        \
18482 +                       (e)->vxi.ptr ? (e)->vxi.usecnt : 0,     \
18483 +                       (e)->vxi.ptr ? (e)->vxi.tasks : 0
18484 +
18485 +void   vxh_dump_entry(struct _vx_hist_entry *e, unsigned cpu)
18486 +{
18487 +       switch (e->type) {
18488 +       case VXH_THROW_OOPS:
18489 +               printk( VXH_LOC_FMTS " oops \n", VXH_LOC_ARGS(e));
18490 +               break;
18491 +
18492 +       case VXH_GET_VX_INFO:
18493 +       case VXH_PUT_VX_INFO:
18494 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS "\n",
18495 +                       VXH_LOC_ARGS(e),
18496 +                       (e->type == VXH_GET_VX_INFO) ? "get" : "put",
18497 +                       VXH_VXI_ARGS(e));
18498 +               break;
18499 +
18500 +       case VXH_INIT_VX_INFO:
18501 +       case VXH_SET_VX_INFO:
18502 +       case VXH_CLR_VX_INFO:
18503 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS " @%p\n",
18504 +                       VXH_LOC_ARGS(e),
18505 +                       (e->type == VXH_INIT_VX_INFO) ? "init" :
18506 +                       ((e->type == VXH_SET_VX_INFO) ? "set" : "clr"),
18507 +                       VXH_VXI_ARGS(e), e->sc.data);
18508 +               break;
18509 +
18510 +       case VXH_CLAIM_VX_INFO:
18511 +       case VXH_RELEASE_VX_INFO:
18512 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS " @%p\n",
18513 +                       VXH_LOC_ARGS(e),
18514 +                       (e->type == VXH_CLAIM_VX_INFO) ? "claim" : "release",
18515 +                       VXH_VXI_ARGS(e), e->sc.data);
18516 +               break;
18517 +
18518 +       case VXH_ALLOC_VX_INFO:
18519 +       case VXH_DEALLOC_VX_INFO:
18520 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS "\n",
18521 +                       VXH_LOC_ARGS(e),
18522 +                       (e->type == VXH_ALLOC_VX_INFO) ? "alloc" : "dealloc",
18523 +                       VXH_VXI_ARGS(e));
18524 +               break;
18525 +
18526 +       case VXH_HASH_VX_INFO:
18527 +       case VXH_UNHASH_VX_INFO:
18528 +               printk( VXH_LOC_FMTS " __%s_vx_info " VXH_VXI_FMTS "\n",
18529 +                       VXH_LOC_ARGS(e),
18530 +                       (e->type == VXH_HASH_VX_INFO) ? "hash" : "unhash",
18531 +                       VXH_VXI_ARGS(e));
18532 +               break;
18533 +
18534 +       case VXH_LOC_VX_INFO:
18535 +       case VXH_LOOKUP_VX_INFO:
18536 +       case VXH_CREATE_VX_INFO:
18537 +               printk( VXH_LOC_FMTS " __%s_vx_info [#%d] -> " VXH_VXI_FMTS "\n",
18538 +                       VXH_LOC_ARGS(e),
18539 +                       (e->type == VXH_CREATE_VX_INFO) ? "create" :
18540 +                       ((e->type == VXH_LOC_VX_INFO) ? "loc" : "lookup"),
18541 +                       e->ll.arg, VXH_VXI_ARGS(e));
18542 +               break;
18543 +       }
18544 +}
18545 +
18546 +static void __vxh_dump_history(void)
18547 +{
18548 +       unsigned int i, cpu;
18549 +
18550 +       printk("History:\tSEQ: %8x\tNR_CPUS: %d\n",
18551 +               atomic_read(&sequence), NR_CPUS);
18552 +
18553 +       for (i = 0; i < VXH_SIZE; i++) {
18554 +               for_each_online_cpu(cpu) {
18555 +                       struct _vx_history *hist =
18556 +                               &per_cpu(vx_history_buffer, cpu);
18557 +                       unsigned int index = (hist->counter - i) % VXH_SIZE;
18558 +                       struct _vx_hist_entry *entry = &hist->entry[index];
18559 +
18560 +                       vxh_dump_entry(entry, cpu);
18561 +               }
18562 +       }
18563 +}
18564 +
18565 +void   vxh_dump_history(void)
18566 +{
18567 +       vxh_active = 0;
18568 +#ifdef CONFIG_SMP
18569 +       local_irq_enable();
18570 +       smp_send_stop();
18571 +       local_irq_disable();
18572 +#endif
18573 +       __vxh_dump_history();
18574 +}
18575 +
18576 +
18577 +/* vserver syscall commands below here */
18578 +
18579 +
18580 +int vc_dump_history(uint32_t id)
18581 +{
18582 +       vxh_active = 0;
18583 +       __vxh_dump_history();
18584 +       vxh_active = 1;
18585 +
18586 +       return 0;
18587 +}
18588 +
18589 +
18590 +int do_read_history(struct __user _vx_hist_entry *data,
18591 +       int cpu, uint32_t *index, uint32_t *count)
18592 +{
18593 +       int pos, ret = 0;
18594 +       struct _vx_history *hist = &per_cpu(vx_history_buffer, cpu);
18595 +       int end = hist->counter;
18596 +       int start = end - VXH_SIZE + 2;
18597 +       int idx = *index;
18598 +
18599 +       /* special case: get current pos */
18600 +       if (!*count) {
18601 +               *index = end;
18602 +               return 0;
18603 +       }
18604 +
18605 +       /* have we lost some data? */
18606 +       if (idx < start)
18607 +               idx = start;
18608 +
18609 +       for (pos = 0; (pos < *count) && (idx < end); pos++, idx++) {
18610 +               struct _vx_hist_entry *entry =
18611 +                       &hist->entry[idx % VXH_SIZE];
18612 +
18613 +               /* send entry to userspace */
18614 +               ret = copy_to_user(&data[pos], entry, sizeof(*entry));
18615 +               if (ret)
18616 +                       break;
18617 +       }
18618 +       /* save new index and count */
18619 +       *index = idx;
18620 +       *count = pos;
18621 +       return ret ? ret : (*index < end);
18622 +}
18623 +
18624 +int vc_read_history(uint32_t id, void __user *data)
18625 +{
18626 +       struct vcmd_read_history_v0 vc_data;
18627 +       int ret;
18628 +
18629 +       if (id >= NR_CPUS)
18630 +               return -EINVAL;
18631 +
18632 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18633 +               return -EFAULT;
18634 +
18635 +       ret = do_read_history((struct __user _vx_hist_entry *)vc_data.data,
18636 +               id, &vc_data.index, &vc_data.count);
18637 +
18638 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18639 +               return -EFAULT;
18640 +       return ret;
18641 +}
18642 +
18643 +#ifdef CONFIG_COMPAT
18644 +
18645 +int vc_read_history_x32(uint32_t id, void __user *data)
18646 +{
18647 +       struct vcmd_read_history_v0_x32 vc_data;
18648 +       int ret;
18649 +
18650 +       if (id >= NR_CPUS)
18651 +               return -EINVAL;
18652 +
18653 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18654 +               return -EFAULT;
18655 +
18656 +       ret = do_read_history((struct __user _vx_hist_entry *)
18657 +               compat_ptr(vc_data.data_ptr),
18658 +               id, &vc_data.index, &vc_data.count);
18659 +
18660 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18661 +               return -EFAULT;
18662 +       return ret;
18663 +}
18664 +
18665 +#endif /* CONFIG_COMPAT */
18666 +
18667 diff -NurpP --minimal linux-3.6/kernel/vserver/inet.c linux-3.6-vs2.3.4.3-noxfs-nocow/kernel/vserver/inet.c
18668 --- linux-3.6/kernel/vserver/inet.c     1970-01-01 01:00:00.000000000 +0100
18669 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/kernel/vserver/inet.c       2012-10-04 18:47:00.000000000 +0200
18670 @@ -0,0 +1,226 @@
18671 +
18672 +#include <linux/in.h>
18673 +#include <linux/inetdevice.h>
18674 +#include <linux/export.h>
18675 +#include <linux/vs_inet.h>
18676 +#include <linux/vs_inet6.h>
18677 +#include <linux/vserver/debug.h>
18678 +#include <net/route.h>
18679 +#include <net/addrconf.h>
18680 +
18681 +
18682 +int nx_v4_addr_conflict(struct nx_info *nxi1, struct nx_info *nxi2)
18683 +{
18684 +       int ret = 0;
18685 +
18686 +       if (!nxi1 || !nxi2 || nxi1 == nxi2)
18687 +               ret = 1;
18688 +       else {
18689 +               struct nx_addr_v4 *ptr;
18690 +
18691 +               for (ptr = &nxi1->v4; ptr; ptr = ptr->next) {
18692 +                       if (v4_nx_addr_in_nx_info(nxi2, ptr, -1)) {
18693 +                               ret = 1;
18694 +                               break;
18695 +                       }
18696 +               }
18697 +       }
18698 +
18699 +       vxdprintk(VXD_CBIT(net, 2),
18700 +               "nx_v4_addr_conflict(%p,%p): %d",
18701 +               nxi1, nxi2, ret);
18702 +
18703 +       return ret;
18704 +}
18705 +
18706 +
18707 +#ifdef CONFIG_IPV6
18708 +
18709 +int nx_v6_addr_conflict(struct nx_info *nxi1, struct nx_info *nxi2)
18710 +{
18711 +       int ret = 0;
18712 +
18713 +       if (!nxi1 || !nxi2 || nxi1 == nxi2)
18714 +               ret = 1;
18715 +       else {
18716 +               struct nx_addr_v6 *ptr;
18717 +
18718 +               for (ptr = &nxi1->v6; ptr; ptr = ptr->next) {
18719 +                       if (v6_nx_addr_in_nx_info(nxi2, ptr, -1)) {
18720 +                               ret = 1;
18721 +                               break;
18722 +                       }
18723 +               }
18724 +       }
18725 +
18726 +       vxdprintk(VXD_CBIT(net, 2),
18727 +               "nx_v6_addr_conflict(%p,%p): %d",
18728 +               nxi1, nxi2, ret);
18729 +
18730 +       return ret;
18731 +}
18732 +
18733 +#endif
18734 +
18735 +int v4_dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
18736 +{
18737 +       struct in_device *in_dev;
18738 +       struct in_ifaddr **ifap;
18739 +       struct in_ifaddr *ifa;
18740 +       int ret = 0;
18741 +
18742 +       if (!dev)
18743 +               goto out;
18744 +       in_dev = in_dev_get(dev);
18745 +       if (!in_dev)
18746 +               goto out;
18747 +
18748 +       for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
18749 +               ifap = &ifa->ifa_next) {
18750 +               if (v4_addr_in_nx_info(nxi, ifa->ifa_local, NXA_MASK_SHOW)) {
18751 +                       ret = 1;
18752 +                       break;
18753 +               }
18754 +       }
18755 +       in_dev_put(in_dev);
18756 +out:
18757 +       return ret;
18758 +}
18759 +
18760 +
18761 +#ifdef CONFIG_IPV6
18762 +
18763 +int v6_dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
18764 +{
18765 +       struct inet6_dev *in_dev;
18766 +       struct inet6_ifaddr *ifa;
18767 +       int ret = 0;
18768 +
18769 +       if (!dev)
18770 +               goto out;
18771 +       in_dev = in6_dev_get(dev);
18772 +       if (!in_dev)
18773 +               goto out;
18774 +
18775 +       // for (ifap = &in_dev->addr_list; (ifa = *ifap) != NULL;
18776 +       list_for_each_entry(ifa, &in_dev->addr_list, if_list) {
18777 +               if (v6_addr_in_nx_info(nxi, &ifa->addr, -1)) {
18778 +                       ret = 1;
18779 +                       break;
18780 +               }
18781 +       }
18782 +       in6_dev_put(in_dev);
18783 +out:
18784 +       return ret;
18785 +}
18786 +
18787 +#endif
18788 +
18789 +int dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
18790 +{
18791 +       int ret = 1;
18792 +
18793 +       if (!nxi)
18794 +               goto out;
18795 +       if (nxi->v4.type && v4_dev_in_nx_info(dev, nxi))
18796 +               goto out;
18797 +#ifdef CONFIG_IPV6
18798 +       ret = 2;
18799 +       if (nxi->v6.type && v6_dev_in_nx_info(dev, nxi))
18800 +               goto out;
18801 +#endif
18802 +       ret = 0;
18803 +out:
18804 +       vxdprintk(VXD_CBIT(net, 3),
18805 +               "dev_in_nx_info(%p,%p[#%d]) = %d",
18806 +               dev, nxi, nxi ? nxi->nx_id : 0, ret);
18807 +       return ret;
18808 +}
18809 +
18810 +struct rtable *ip_v4_find_src(struct net *net, struct nx_info *nxi,
18811 +       struct flowi4 *fl4)
18812 +{
18813 +       struct rtable *rt;
18814 +
18815 +       if (!nxi)
18816 +               return NULL;
18817 +
18818 +       /* FIXME: handle lback only case */
18819 +       if (!NX_IPV4(nxi))
18820 +               return ERR_PTR(-EPERM);
18821 +
18822 +       vxdprintk(VXD_CBIT(net, 4),
18823 +               "ip_v4_find_src(%p[#%u]) " NIPQUAD_FMT " -> " NIPQUAD_FMT,
18824 +               nxi, nxi ? nxi->nx_id : 0,
18825 +               NIPQUAD(fl4->saddr), NIPQUAD(fl4->daddr));
18826 +
18827 +       /* single IP is unconditional */
18828 +       if (nx_info_flags(nxi, NXF_SINGLE_IP, 0) &&
18829 +               (fl4->saddr == INADDR_ANY))
18830 +               fl4->saddr = nxi->v4.ip[0].s_addr;
18831 +
18832 +       if (fl4->saddr == INADDR_ANY) {
18833 +               struct nx_addr_v4 *ptr;
18834 +               __be32 found = 0;
18835 +
18836 +               rt = __ip_route_output_key(net, fl4);
18837 +               if (!IS_ERR(rt)) {
18838 +                       found = fl4->saddr;
18839 +                       ip_rt_put(rt);
18840 +                       vxdprintk(VXD_CBIT(net, 4),
18841 +                               "ip_v4_find_src(%p[#%u]) rok[%u]: " NIPQUAD_FMT,
18842 +                               nxi, nxi ? nxi->nx_id : 0, fl4->flowi4_oif, NIPQUAD(found));
18843 +                       if (v4_addr_in_nx_info(nxi, found, NXA_MASK_BIND))
18844 +                               goto found;
18845 +               }
18846 +
18847 +               for (ptr = &nxi->v4; ptr; ptr = ptr->next) {
18848 +                       __be32 primary = ptr->ip[0].s_addr;
18849 +                       __be32 mask = ptr->mask.s_addr;
18850 +                       __be32 neta = primary & mask;
18851 +
18852 +                       vxdprintk(VXD_CBIT(net, 4), "ip_v4_find_src(%p[#%u]) chk: "
18853 +                               NIPQUAD_FMT "/" NIPQUAD_FMT "/" NIPQUAD_FMT,
18854 +                               nxi, nxi ? nxi->nx_id : 0, NIPQUAD(primary),
18855 +                               NIPQUAD(mask), NIPQUAD(neta));
18856 +                       if ((found & mask) != neta)
18857 +                               continue;
18858 +
18859 +                       fl4->saddr = primary;
18860 +                       rt = __ip_route_output_key(net, fl4);
18861 +                       vxdprintk(VXD_CBIT(net, 4),
18862 +                               "ip_v4_find_src(%p[#%u]) rok[%u]: " NIPQUAD_FMT,
18863 +                               nxi, nxi ? nxi->nx_id : 0, fl4->flowi4_oif, NIPQUAD(primary));
18864 +                       if (!IS_ERR(rt)) {
18865 +                               found = fl4->saddr;
18866 +                               ip_rt_put(rt);
18867 +                               if (found == primary)
18868 +                                       goto found;
18869 +                       }
18870 +               }
18871 +               /* still no source ip? */
18872 +               found = ipv4_is_loopback(fl4->daddr)
18873 +                       ? IPI_LOOPBACK : nxi->v4.ip[0].s_addr;
18874 +       found:
18875 +               /* assign src ip to flow */
18876 +               fl4->saddr = found;
18877 +
18878 +       } else {
18879 +               if (!v4_addr_in_nx_info(nxi, fl4->saddr, NXA_MASK_BIND))
18880 +                       return ERR_PTR(-EPERM);
18881 +       }
18882 +
18883 +       if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0)) {
18884 +               if (ipv4_is_loopback(fl4->daddr))
18885 +                       fl4->daddr = nxi->v4_lback.s_addr;
18886 +               if (ipv4_is_loopback(fl4->saddr))
18887 +                       fl4->saddr = nxi->v4_lback.s_addr;
18888 +       } else if (ipv4_is_loopback(fl4->daddr) &&
18889 +               !nx_info_flags(nxi, NXF_LBACK_ALLOW, 0))
18890 +               return ERR_PTR(-EPERM);
18891 +
18892 +       return NULL;
18893 +}
18894 +
18895 +EXPORT_SYMBOL_GPL(ip_v4_find_src);
18896 +
18897 diff -NurpP --minimal linux-3.6/kernel/vserver/init.c linux-3.6-vs2.3.4.3-noxfs-nocow/kernel/vserver/init.c
18898 --- linux-3.6/kernel/vserver/init.c     1970-01-01 01:00:00.000000000 +0100
18899 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/kernel/vserver/init.c       2012-10-04 18:47:00.000000000 +0200
18900 @@ -0,0 +1,45 @@
18901 +/*
18902 + *  linux/kernel/init.c
18903 + *
18904 + *  Virtual Server Init
18905 + *
18906 + *  Copyright (C) 2004-2007  Herbert Pötzl
18907 + *
18908 + *  V0.01  basic structure
18909 + *
18910 + */
18911 +
18912 +#include <linux/init.h>
18913 +
18914 +int    vserver_register_sysctl(void);
18915 +void   vserver_unregister_sysctl(void);
18916 +
18917 +
18918 +static int __init init_vserver(void)
18919 +{
18920 +       int ret = 0;
18921 +
18922 +#ifdef CONFIG_VSERVER_DEBUG
18923 +       vserver_register_sysctl();
18924 +#endif
18925 +       return ret;
18926 +}
18927 +
18928 +
18929 +static void __exit exit_vserver(void)
18930 +{
18931 +
18932 +#ifdef CONFIG_VSERVER_DEBUG
18933 +       vserver_unregister_sysctl();
18934 +#endif
18935 +       return;
18936 +}
18937 +
18938 +/* FIXME: GFP_ZONETYPES gone
18939 +long vx_slab[GFP_ZONETYPES]; */
18940 +long vx_area;
18941 +
18942 +
18943 +module_init(init_vserver);
18944 +module_exit(exit_vserver);
18945 +
18946 diff -NurpP --minimal linux-3.6/kernel/vserver/inode.c linux-3.6-vs2.3.4.3-noxfs-nocow/kernel/vserver/inode.c
18947 --- linux-3.6/kernel/vserver/inode.c    1970-01-01 01:00:00.000000000 +0100
18948 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/kernel/vserver/inode.c      2012-10-04 18:47:00.000000000 +0200
18949 @@ -0,0 +1,437 @@
18950 +/*
18951 + *  linux/kernel/vserver/inode.c
18952 + *
18953 + *  Virtual Server: File System Support
18954 + *
18955 + *  Copyright (C) 2004-2007  Herbert Pötzl
18956 + *
18957 + *  V0.01  separated from vcontext V0.05
18958 + *  V0.02  moved to tag (instead of xid)
18959 + *
18960 + */
18961 +
18962 +#include <linux/tty.h>
18963 +#include <linux/proc_fs.h>
18964 +#include <linux/devpts_fs.h>
18965 +#include <linux/fs.h>
18966 +#include <linux/file.h>
18967 +#include <linux/mount.h>
18968 +#include <linux/parser.h>
18969 +#include <linux/namei.h>
18970 +#include <linux/vserver/inode.h>
18971 +#include <linux/vserver/inode_cmd.h>
18972 +#include <linux/vs_base.h>
18973 +#include <linux/vs_tag.h>
18974 +
18975 +#include <asm/uaccess.h>
18976 +
18977 +
18978 +static int __vc_get_iattr(struct inode *in, uint32_t *tag, uint32_t *flags, uint32_t *mask)
18979 +{
18980 +       struct proc_dir_entry *entry;
18981 +
18982 +       if (!in || !in->i_sb)
18983 +               return -ESRCH;
18984 +
18985 +       *flags = IATTR_TAG
18986 +               | (IS_IMMUTABLE(in) ? IATTR_IMMUTABLE : 0)
18987 +               | (IS_IXUNLINK(in) ? IATTR_IXUNLINK : 0)
18988 +               | (IS_BARRIER(in) ? IATTR_BARRIER : 0)
18989 +               | (IS_COW(in) ? IATTR_COW : 0);
18990 +       *mask = IATTR_IXUNLINK | IATTR_IMMUTABLE | IATTR_COW;
18991 +
18992 +       if (S_ISDIR(in->i_mode))
18993 +               *mask |= IATTR_BARRIER;
18994 +
18995 +       if (IS_TAGGED(in)) {
18996 +               *tag = in->i_tag;
18997 +               *mask |= IATTR_TAG;
18998 +       }
18999 +
19000 +       switch (in->i_sb->s_magic) {
19001 +       case PROC_SUPER_MAGIC:
19002 +               entry = PROC_I(in)->pde;
19003 +
19004 +               /* check for specific inodes? */
19005 +               if (entry)
19006 +                       *mask |= IATTR_FLAGS;
19007 +               if (entry)
19008 +                       *flags |= (entry->vx_flags & IATTR_FLAGS);
19009 +               else
19010 +                       *flags |= (PROC_I(in)->vx_flags & IATTR_FLAGS);
19011 +               break;
19012 +
19013 +       case DEVPTS_SUPER_MAGIC:
19014 +               *tag = in->i_tag;
19015 +               *mask |= IATTR_TAG;
19016 +               break;
19017 +
19018 +       default:
19019 +               break;
19020 +       }
19021 +       return 0;
19022 +}
19023 +
19024 +int vc_get_iattr(void __user *data)
19025 +{
19026 +       struct path path;
19027 +       struct vcmd_ctx_iattr_v1 vc_data = { .tag = -1 };
19028 +       int ret;
19029 +
19030 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19031 +               return -EFAULT;
19032 +
19033 +       ret = user_lpath(vc_data.name, &path);
19034 +       if (!ret) {
19035 +               ret = __vc_get_iattr(path.dentry->d_inode,
19036 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
19037 +               path_put(&path);
19038 +       }
19039 +       if (ret)
19040 +               return ret;
19041 +
19042 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19043 +               ret = -EFAULT;
19044 +       return ret;
19045 +}
19046 +
19047 +#ifdef CONFIG_COMPAT
19048 +
19049 +int vc_get_iattr_x32(void __user *data)
19050 +{
19051 +       struct path path;
19052 +       struct vcmd_ctx_iattr_v1_x32 vc_data = { .tag = -1 };
19053 +       int ret;
19054 +
19055 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19056 +               return -EFAULT;
19057 +
19058 +       ret = user_lpath(compat_ptr(vc_data.name_ptr), &path);
19059 +       if (!ret) {
19060 +               ret = __vc_get_iattr(path.dentry->d_inode,
19061 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
19062 +               path_put(&path);
19063 +       }
19064 +       if (ret)
19065 +               return ret;
19066 +
19067 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19068 +               ret = -EFAULT;
19069 +       return ret;
19070 +}
19071 +
19072 +#endif /* CONFIG_COMPAT */
19073 +
19074 +
19075 +int vc_fget_iattr(uint32_t fd, void __user *data)
19076 +{
19077 +       struct file *filp;
19078 +       struct vcmd_ctx_fiattr_v0 vc_data = { .tag = -1 };
19079 +       int ret;
19080 +
19081 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19082 +               return -EFAULT;
19083 +
19084 +       filp = fget(fd);
19085 +       if (!filp || !filp->f_dentry || !filp->f_dentry->d_inode)
19086 +               return -EBADF;
19087 +
19088 +       ret = __vc_get_iattr(filp->f_dentry->d_inode,
19089 +               &vc_data.tag, &vc_data.flags, &vc_data.mask);
19090 +
19091 +       fput(filp);
19092 +
19093 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19094 +               ret = -EFAULT;
19095 +       return ret;
19096 +}
19097 +
19098 +
19099 +static int __vc_set_iattr(struct dentry *de, uint32_t *tag, uint32_t *flags, uint32_t *mask)
19100 +{
19101 +       struct inode *in = de->d_inode;
19102 +       int error = 0, is_proc = 0, has_tag = 0;
19103 +       struct iattr attr = { 0 };
19104 +
19105 +       if (!in || !in->i_sb)
19106 +               return -ESRCH;
19107 +
19108 +       is_proc = (in->i_sb->s_magic == PROC_SUPER_MAGIC);
19109 +       if ((*mask & IATTR_FLAGS) && !is_proc)
19110 +               return -EINVAL;
19111 +
19112 +       has_tag = IS_TAGGED(in) ||
19113 +               (in->i_sb->s_magic == DEVPTS_SUPER_MAGIC);
19114 +       if ((*mask & IATTR_TAG) && !has_tag)
19115 +               return -EINVAL;
19116 +
19117 +       mutex_lock(&in->i_mutex);
19118 +       if (*mask & IATTR_TAG) {
19119 +               attr.ia_tag = *tag;
19120 +               attr.ia_valid |= ATTR_TAG;
19121 +       }
19122 +
19123 +       if (*mask & IATTR_FLAGS) {
19124 +               struct proc_dir_entry *entry = PROC_I(in)->pde;
19125 +               unsigned int iflags = PROC_I(in)->vx_flags;
19126 +
19127 +               iflags = (iflags & ~(*mask & IATTR_FLAGS))
19128 +                       | (*flags & IATTR_FLAGS);
19129 +               PROC_I(in)->vx_flags = iflags;
19130 +               if (entry)
19131 +                       entry->vx_flags = iflags;
19132 +       }
19133 +
19134 +       if (*mask & (IATTR_IMMUTABLE | IATTR_IXUNLINK |
19135 +               IATTR_BARRIER | IATTR_COW)) {
19136 +               int iflags = in->i_flags;
19137 +               int vflags = in->i_vflags;
19138 +
19139 +               if (*mask & IATTR_IMMUTABLE) {
19140 +                       if (*flags & IATTR_IMMUTABLE)
19141 +                               iflags |= S_IMMUTABLE;
19142 +                       else
19143 +                               iflags &= ~S_IMMUTABLE;
19144 +               }
19145 +               if (*mask & IATTR_IXUNLINK) {
19146 +                       if (*flags & IATTR_IXUNLINK)
19147 +                               iflags |= S_IXUNLINK;
19148 +                       else
19149 +                               iflags &= ~S_IXUNLINK;
19150 +               }
19151 +               if (S_ISDIR(in->i_mode) && (*mask & IATTR_BARRIER)) {
19152 +                       if (*flags & IATTR_BARRIER)
19153 +                               vflags |= V_BARRIER;
19154 +                       else
19155 +                               vflags &= ~V_BARRIER;
19156 +               }
19157 +               if (S_ISREG(in->i_mode) && (*mask & IATTR_COW)) {
19158 +                       if (*flags & IATTR_COW)
19159 +                               vflags |= V_COW;
19160 +                       else
19161 +                               vflags &= ~V_COW;
19162 +               }
19163 +               if (in->i_op && in->i_op->sync_flags) {
19164 +                       error = in->i_op->sync_flags(in, iflags, vflags);
19165 +                       if (error)
19166 +                               goto out;
19167 +               }
19168 +       }
19169 +
19170 +       if (attr.ia_valid) {
19171 +               if (in->i_op && in->i_op->setattr)
19172 +                       error = in->i_op->setattr(de, &attr);
19173 +               else {
19174 +                       error = inode_change_ok(in, &attr);
19175 +                       if (!error) {
19176 +                               setattr_copy(in, &attr);
19177 +                               mark_inode_dirty(in);
19178 +                       }
19179 +               }
19180 +       }
19181 +
19182 +out:
19183 +       mutex_unlock(&in->i_mutex);
19184 +       return error;
19185 +}
19186 +
19187 +int vc_set_iattr(void __user *data)
19188 +{
19189 +       struct path path;
19190 +       struct vcmd_ctx_iattr_v1 vc_data;
19191 +       int ret;
19192 +
19193 +       if (!capable(CAP_LINUX_IMMUTABLE))
19194 +               return -EPERM;
19195 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19196 +               return -EFAULT;
19197 +
19198 +       ret = user_lpath(vc_data.name, &path);
19199 +       if (!ret) {
19200 +               ret = __vc_set_iattr(path.dentry,
19201 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
19202 +               path_put(&path);
19203 +       }
19204 +
19205 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19206 +               ret = -EFAULT;
19207 +       return ret;
19208 +}
19209 +
19210 +#ifdef CONFIG_COMPAT
19211 +
19212 +int vc_set_iattr_x32(void __user *data)
19213 +{
19214 +       struct path path;
19215 +       struct vcmd_ctx_iattr_v1_x32 vc_data;
19216 +       int ret;
19217 +
19218 +       if (!capable(CAP_LINUX_IMMUTABLE))
19219 +               return -EPERM;
19220 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19221 +               return -EFAULT;
19222 +
19223 +       ret = user_lpath(compat_ptr(vc_data.name_ptr), &path);
19224 +       if (!ret) {
19225 +               ret = __vc_set_iattr(path.dentry,
19226 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
19227 +               path_put(&path);
19228 +       }
19229 +
19230 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19231 +               ret = -EFAULT;
19232 +       return ret;
19233 +}
19234 +
19235 +#endif /* CONFIG_COMPAT */
19236 +
19237 +int vc_fset_iattr(uint32_t fd, void __user *data)
19238 +{
19239 +       struct file *filp;
19240 +       struct vcmd_ctx_fiattr_v0 vc_data;
19241 +       int ret;
19242 +
19243 +       if (!capable(CAP_LINUX_IMMUTABLE))
19244 +               return -EPERM;
19245 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19246 +               return -EFAULT;
19247 +
19248 +       filp = fget(fd);
19249 +       if (!filp || !filp->f_dentry || !filp->f_dentry->d_inode)
19250 +               return -EBADF;
19251 +
19252 +       ret = __vc_set_iattr(filp->f_dentry, &vc_data.tag,
19253 +               &vc_data.flags, &vc_data.mask);
19254 +
19255 +       fput(filp);
19256 +
19257 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19258 +               return -EFAULT;
19259 +       return ret;
19260 +}
19261 +
19262 +
19263 +enum { Opt_notagcheck, Opt_tag, Opt_notag, Opt_tagid, Opt_err };
19264 +
19265 +static match_table_t tokens = {
19266 +       {Opt_notagcheck, "notagcheck"},
19267 +#ifdef CONFIG_PROPAGATE
19268 +       {Opt_notag, "notag"},
19269 +       {Opt_tag, "tag"},
19270 +       {Opt_tagid, "tagid=%u"},
19271 +#endif
19272 +       {Opt_err, NULL}
19273 +};
19274 +
19275 +
19276 +static void __dx_parse_remove(char *string, char *opt)
19277 +{
19278 +       char *p = strstr(string, opt);
19279 +       char *q = p;
19280 +
19281 +       if (p) {
19282 +               while (*q != '\0' && *q != ',')
19283 +                       q++;
19284 +               while (*q)
19285 +                       *p++ = *q++;
19286 +               while (*p)
19287 +                       *p++ = '\0';
19288 +       }
19289 +}
19290 +
19291 +int dx_parse_tag(char *string, tag_t *tag, int remove, int *mnt_flags,
19292 +                unsigned long *flags)
19293 +{
19294 +       int set = 0;
19295 +       substring_t args[MAX_OPT_ARGS];
19296 +       int token;
19297 +       char *s, *p, *opts;
19298 +#if defined(CONFIG_PROPAGATE) || defined(CONFIG_VSERVER_DEBUG)
19299 +       int option = 0;
19300 +#endif
19301 +
19302 +       if (!string)
19303 +               return 0;
19304 +       s = kstrdup(string, GFP_KERNEL | GFP_ATOMIC);
19305 +       if (!s)
19306 +               return 0;
19307 +
19308 +       opts = s;
19309 +       while ((p = strsep(&opts, ",")) != NULL) {
19310 +               token = match_token(p, tokens, args);
19311 +
19312 +               switch (token) {
19313 +#ifdef CONFIG_PROPAGATE
19314 +               case Opt_tag:
19315 +                       if (tag)
19316 +                               *tag = 0;
19317 +                       if (remove)
19318 +                               __dx_parse_remove(s, "tag");
19319 +                       *mnt_flags |= MNT_TAGID;
19320 +                       set |= MNT_TAGID;
19321 +                       break;
19322 +               case Opt_notag:
19323 +                       if (remove)
19324 +                               __dx_parse_remove(s, "notag");
19325 +                       *mnt_flags |= MNT_NOTAG;
19326 +                       set |= MNT_NOTAG;
19327 +                       break;
19328 +               case Opt_tagid:
19329 +                       if (tag && !match_int(args, &option))
19330 +                               *tag = option;
19331 +                       if (remove)
19332 +                               __dx_parse_remove(s, "tagid");
19333 +                       *mnt_flags |= MNT_TAGID;
19334 +                       set |= MNT_TAGID;
19335 +                       break;
19336 +#endif /* CONFIG_PROPAGATE */
19337 +               case Opt_notagcheck:
19338 +                       if (remove)
19339 +                               __dx_parse_remove(s, "notagcheck");
19340 +                       *flags |= MS_NOTAGCHECK;
19341 +                       set |= MS_NOTAGCHECK;
19342 +                       break;
19343 +               }
19344 +               vxdprintk(VXD_CBIT(tag, 7),
19345 +                       "dx_parse_tag(" VS_Q("%s") "): %d:#%d",
19346 +                       p, token, option);
19347 +       }
19348 +       if (set)
19349 +               strcpy(string, s);
19350 +       kfree(s);
19351 +       return set;
19352 +}
19353 +
19354 +#ifdef CONFIG_PROPAGATE
19355 +
19356 +void __dx_propagate_tag(struct nameidata *nd, struct inode *inode)
19357 +{
19358 +       tag_t new_tag = 0;
19359 +       struct vfsmount *mnt;
19360 +       int propagate;
19361 +
19362 +       if (!nd)
19363 +               return;
19364 +       mnt = nd->path.mnt;
19365 +       if (!mnt)
19366 +               return;
19367 +
19368 +       propagate = (mnt->mnt_flags & MNT_TAGID);
19369 +       if (propagate)
19370 +               new_tag = mnt->mnt_tag;
19371 +
19372 +       vxdprintk(VXD_CBIT(tag, 7),
19373 +               "dx_propagate_tag(%p[#%lu.%d]): %d,%d",
19374 +               inode, inode->i_ino, inode->i_tag,
19375 +               new_tag, (propagate) ? 1 : 0);
19376 +
19377 +       if (propagate)
19378 +               inode->i_tag = new_tag;
19379 +}
19380 +
19381 +#include <linux/module.h>
19382 +
19383 +EXPORT_SYMBOL_GPL(__dx_propagate_tag);
19384 +
19385 +#endif /* CONFIG_PROPAGATE */
19386 +
19387 diff -NurpP --minimal linux-3.6/kernel/vserver/limit.c linux-3.6-vs2.3.4.3-noxfs-nocow/kernel/vserver/limit.c
19388 --- linux-3.6/kernel/vserver/limit.c    1970-01-01 01:00:00.000000000 +0100
19389 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/kernel/vserver/limit.c      2012-10-04 18:47:00.000000000 +0200
19390 @@ -0,0 +1,345 @@
19391 +/*
19392 + *  linux/kernel/vserver/limit.c
19393 + *
19394 + *  Virtual Server: Context Limits
19395 + *
19396 + *  Copyright (C) 2004-2010  Herbert Pötzl
19397 + *
19398 + *  V0.01  broken out from vcontext V0.05
19399 + *  V0.02  changed vcmds to vxi arg
19400 + *  V0.03  added memory cgroup support
19401 + *
19402 + */
19403 +
19404 +#include <linux/sched.h>
19405 +#include <linux/module.h>
19406 +#include <linux/memcontrol.h>
19407 +#include <linux/res_counter.h>
19408 +#include <linux/vs_limit.h>
19409 +#include <linux/vserver/limit.h>
19410 +#include <linux/vserver/limit_cmd.h>
19411 +
19412 +#include <asm/uaccess.h>
19413 +
19414 +
19415 +const char *vlimit_name[NUM_LIMITS] = {
19416 +       [RLIMIT_CPU]            = "CPU",
19417 +       [RLIMIT_NPROC]          = "NPROC",
19418 +       [RLIMIT_NOFILE]         = "NOFILE",
19419 +       [RLIMIT_LOCKS]          = "LOCKS",
19420 +       [RLIMIT_SIGPENDING]     = "SIGP",
19421 +       [RLIMIT_MSGQUEUE]       = "MSGQ",
19422 +
19423 +       [VLIMIT_NSOCK]          = "NSOCK",
19424 +       [VLIMIT_OPENFD]         = "OPENFD",
19425 +       [VLIMIT_SHMEM]          = "SHMEM",
19426 +       [VLIMIT_DENTRY]         = "DENTRY",
19427 +};
19428 +
19429 +EXPORT_SYMBOL_GPL(vlimit_name);
19430 +
19431 +#define MASK_ENTRY(x)  (1 << (x))
19432 +
19433 +const struct vcmd_ctx_rlimit_mask_v0 vlimit_mask = {
19434 +               /* minimum */
19435 +       0
19436 +       ,       /* softlimit */
19437 +       0
19438 +       ,       /* maximum */
19439 +       MASK_ENTRY( RLIMIT_NPROC        ) |
19440 +       MASK_ENTRY( RLIMIT_NOFILE       ) |
19441 +       MASK_ENTRY( RLIMIT_LOCKS        ) |
19442 +       MASK_ENTRY( RLIMIT_MSGQUEUE     ) |
19443 +
19444 +       MASK_ENTRY( VLIMIT_NSOCK        ) |
19445 +       MASK_ENTRY( VLIMIT_OPENFD       ) |
19446 +       MASK_ENTRY( VLIMIT_SHMEM        ) |
19447 +       MASK_ENTRY( VLIMIT_DENTRY       ) |
19448 +       0
19449 +};
19450 +               /* accounting only */
19451 +uint32_t account_mask =
19452 +       MASK_ENTRY( VLIMIT_SEMARY       ) |
19453 +       MASK_ENTRY( VLIMIT_NSEMS        ) |
19454 +       MASK_ENTRY( VLIMIT_MAPPED       ) |
19455 +       0;
19456 +
19457 +
19458 +static int is_valid_vlimit(int id)
19459 +{
19460 +       uint32_t mask = vlimit_mask.minimum |
19461 +               vlimit_mask.softlimit | vlimit_mask.maximum;
19462 +       return mask & (1 << id);
19463 +}
19464 +
19465 +static int is_accounted_vlimit(int id)
19466 +{
19467 +       if (is_valid_vlimit(id))
19468 +               return 1;
19469 +       return account_mask & (1 << id);
19470 +}
19471 +
19472 +
19473 +static inline uint64_t vc_get_soft(struct vx_info *vxi, int id)
19474 +{
19475 +       rlim_t limit = __rlim_soft(&vxi->limit, id);
19476 +       return VX_VLIM(limit);
19477 +}
19478 +
19479 +static inline uint64_t vc_get_hard(struct vx_info *vxi, int id)
19480 +{
19481 +       rlim_t limit = __rlim_hard(&vxi->limit, id);
19482 +       return VX_VLIM(limit);
19483 +}
19484 +
19485 +static int do_get_rlimit(struct vx_info *vxi, uint32_t id,
19486 +       uint64_t *minimum, uint64_t *softlimit, uint64_t *maximum)
19487 +{
19488 +       if (!is_valid_vlimit(id))
19489 +               return -EINVAL;
19490 +
19491 +       if (minimum)
19492 +               *minimum = CRLIM_UNSET;
19493 +       if (softlimit)
19494 +               *softlimit = vc_get_soft(vxi, id);
19495 +       if (maximum)
19496 +               *maximum = vc_get_hard(vxi, id);
19497 +       return 0;
19498 +}
19499 +
19500 +int vc_get_rlimit(struct vx_info *vxi, void __user *data)
19501 +{
19502 +       struct vcmd_ctx_rlimit_v0 vc_data;
19503 +       int ret;
19504 +
19505 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19506 +               return -EFAULT;
19507 +
19508 +       ret = do_get_rlimit(vxi, vc_data.id,
19509 +               &vc_data.minimum, &vc_data.softlimit, &vc_data.maximum);
19510 +       if (ret)
19511 +               return ret;
19512 +
19513 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19514 +               return -EFAULT;
19515 +       return 0;
19516 +}
19517 +
19518 +static int do_set_rlimit(struct vx_info *vxi, uint32_t id,
19519 +       uint64_t minimum, uint64_t softlimit, uint64_t maximum)
19520 +{
19521 +       if (!is_valid_vlimit(id))
19522 +               return -EINVAL;
19523 +
19524 +       if (maximum != CRLIM_KEEP)
19525 +               __rlim_hard(&vxi->limit, id) = VX_RLIM(maximum);
19526 +       if (softlimit != CRLIM_KEEP)
19527 +               __rlim_soft(&vxi->limit, id) = VX_RLIM(softlimit);
19528 +
19529 +       /* clamp soft limit */
19530 +       if (__rlim_soft(&vxi->limit, id) > __rlim_hard(&vxi->limit, id))
19531 +               __rlim_soft(&vxi->limit, id) = __rlim_hard(&vxi->limit, id);
19532 +
19533 +       return 0;
19534 +}
19535 +
19536 +int vc_set_rlimit(struct vx_info *vxi, void __user *data)
19537 +{
19538 +       struct vcmd_ctx_rlimit_v0 vc_data;
19539 +
19540 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19541 +               return -EFAULT;
19542 +
19543 +       return do_set_rlimit(vxi, vc_data.id,
19544 +               vc_data.minimum, vc_data.softlimit, vc_data.maximum);
19545 +}
19546 +
19547 +#ifdef CONFIG_IA32_EMULATION
19548 +
19549 +int vc_set_rlimit_x32(struct vx_info *vxi, void __user *data)
19550 +{
19551 +       struct vcmd_ctx_rlimit_v0_x32 vc_data;
19552 +
19553 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19554 +               return -EFAULT;
19555 +
19556 +       return do_set_rlimit(vxi, vc_data.id,
19557 +               vc_data.minimum, vc_data.softlimit, vc_data.maximum);
19558 +}
19559 +
19560 +int vc_get_rlimit_x32(struct vx_info *vxi, void __user *data)
19561 +{
19562 +       struct vcmd_ctx_rlimit_v0_x32 vc_data;
19563 +       int ret;
19564 +
19565 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19566 +               return -EFAULT;
19567 +
19568 +       ret = do_get_rlimit(vxi, vc_data.id,
19569 +               &vc_data.minimum, &vc_data.softlimit, &vc_data.maximum);
19570 +       if (ret)
19571 +               return ret;
19572 +
19573 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19574 +               return -EFAULT;
19575 +       return 0;
19576 +}
19577 +
19578 +#endif /* CONFIG_IA32_EMULATION */
19579 +
19580 +
19581 +int vc_get_rlimit_mask(uint32_t id, void __user *data)
19582 +{
19583 +       if (copy_to_user(data, &vlimit_mask, sizeof(vlimit_mask)))
19584 +               return -EFAULT;
19585 +       return 0;
19586 +}
19587 +
19588 +
19589 +static inline void vx_reset_hits(struct _vx_limit *limit)
19590 +{
19591 +       int lim;
19592 +
19593 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
19594 +               atomic_set(&__rlim_lhit(limit, lim), 0);
19595 +       }
19596 +}
19597 +
19598 +int vc_reset_hits(struct vx_info *vxi, void __user *data)
19599 +{
19600 +       vx_reset_hits(&vxi->limit);
19601 +       return 0;
19602 +}
19603 +
19604 +static inline void vx_reset_minmax(struct _vx_limit *limit)
19605 +{
19606 +       rlim_t value;
19607 +       int lim;
19608 +
19609 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
19610 +               value = __rlim_get(limit, lim);
19611 +               __rlim_rmax(limit, lim) = value;
19612 +               __rlim_rmin(limit, lim) = value;
19613 +       }
19614 +}
19615 +
19616 +int vc_reset_minmax(struct vx_info *vxi, void __user *data)
19617 +{
19618 +       vx_reset_minmax(&vxi->limit);
19619 +       return 0;
19620 +}
19621 +
19622 +
19623 +int vc_rlimit_stat(struct vx_info *vxi, void __user *data)
19624 +{
19625 +       struct vcmd_rlimit_stat_v0 vc_data;
19626 +       struct _vx_limit *limit = &vxi->limit;
19627 +       int id;
19628 +
19629 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19630 +               return -EFAULT;
19631 +
19632 +       id = vc_data.id;
19633 +       if (!is_accounted_vlimit(id))
19634 +               return -EINVAL;
19635 +
19636 +       vx_limit_fixup(limit, id);
19637 +       vc_data.hits = atomic_read(&__rlim_lhit(limit, id));
19638 +       vc_data.value = __rlim_get(limit, id);
19639 +       vc_data.minimum = __rlim_rmin(limit, id);
19640 +       vc_data.maximum = __rlim_rmax(limit, id);
19641 +
19642 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19643 +               return -EFAULT;
19644 +       return 0;
19645 +}
19646 +
19647 +
19648 +void vx_vsi_meminfo(struct sysinfo *val)
19649 +{
19650 +#ifdef CONFIG_CGROUP_MEM_RES_CTLR
19651 +       struct mem_cgroup *mcg;
19652 +       u64 res_limit, res_usage;
19653 +
19654 +       rcu_read_lock();
19655 +       mcg = mem_cgroup_from_task(current);
19656 +       rcu_read_unlock();
19657 +       if (!mcg)
19658 +               goto out;
19659 +
19660 +       res_limit = mem_cgroup_res_read_u64(mcg, RES_LIMIT);
19661 +       res_usage = mem_cgroup_res_read_u64(mcg, RES_USAGE);
19662 +
19663 +       if (res_limit != RESOURCE_MAX)
19664 +               val->totalram = (res_limit >> PAGE_SHIFT);
19665 +       val->freeram = val->totalram - (res_usage >> PAGE_SHIFT);
19666 +       val->bufferram = 0;
19667 +       val->totalhigh = 0;
19668 +       val->freehigh = 0;
19669 +out:
19670 +#endif /* CONFIG_CGROUP_MEM_RES_CTLR */
19671 +       return;
19672 +}
19673 +
19674 +void vx_vsi_swapinfo(struct sysinfo *val)
19675 +{
19676 +#ifdef CONFIG_CGROUP_MEM_RES_CTLR
19677 +#ifdef CONFIG_CGROUP_MEM_RES_CTLR_SWAP
19678 +       struct mem_cgroup *mcg;
19679 +       u64 res_limit, res_usage, memsw_limit, memsw_usage;
19680 +       s64 swap_limit, swap_usage;
19681 +
19682 +       rcu_read_lock();
19683 +       mcg = mem_cgroup_from_task(current);
19684 +       rcu_read_unlock();
19685 +       if (!mcg)
19686 +               goto out;
19687 +
19688 +       res_limit = mem_cgroup_res_read_u64(mcg, RES_LIMIT);
19689 +       res_usage = mem_cgroup_res_read_u64(mcg, RES_USAGE);
19690 +       memsw_limit = mem_cgroup_memsw_read_u64(mcg, RES_LIMIT);
19691 +       memsw_usage = mem_cgroup_memsw_read_u64(mcg, RES_USAGE);
19692 +
19693 +       /* memory unlimited */
19694 +       if (res_limit == RESOURCE_MAX)
19695 +               goto out;
19696 +
19697 +       swap_limit = memsw_limit - res_limit;
19698 +       /* we have a swap limit? */
19699 +       if (memsw_limit != RESOURCE_MAX)
19700 +               val->totalswap = swap_limit >> PAGE_SHIFT;
19701 +
19702 +       /* calculate swap part */
19703 +       swap_usage = (memsw_usage > res_usage) ?
19704 +               memsw_usage - res_usage : 0;
19705 +
19706 +       /* total shown minus usage gives free swap */
19707 +       val->freeswap = (swap_usage < swap_limit) ?
19708 +               val->totalswap - (swap_usage >> PAGE_SHIFT) : 0;
19709 +out:
19710 +#else  /* !CONFIG_CGROUP_MEM_RES_CTLR_SWAP */
19711 +       val->totalswap = 0;
19712 +       val->freeswap = 0;
19713 +#endif /* !CONFIG_CGROUP_MEM_RES_CTLR_SWAP */
19714 +#endif /* CONFIG_CGROUP_MEM_RES_CTLR */
19715 +       return;
19716 +}
19717 +
19718 +long vx_vsi_cached(struct sysinfo *val)
19719 +{
19720 +       long cache = 0;
19721 +#ifdef CONFIG_CGROUP_MEM_RES_CTLR
19722 +       struct mem_cgroup *mcg;
19723 +
19724 +       rcu_read_lock();
19725 +       mcg = mem_cgroup_from_task(current);
19726 +       rcu_read_unlock();
19727 +       if (!mcg)
19728 +               goto out;
19729 +
19730 +       cache = mem_cgroup_stat_read_cache(mcg);
19731 +out:
19732 +#endif
19733 +       return cache;
19734 +}
19735 +
19736 diff -NurpP --minimal linux-3.6/kernel/vserver/limit_init.h linux-3.6-vs2.3.4.3-noxfs-nocow/kernel/vserver/limit_init.h
19737 --- linux-3.6/kernel/vserver/limit_init.h       1970-01-01 01:00:00.000000000 +0100
19738 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/kernel/vserver/limit_init.h 2012-10-04 18:47:00.000000000 +0200
19739 @@ -0,0 +1,31 @@
19740 +
19741 +
19742 +static inline void vx_info_init_limit(struct _vx_limit *limit)
19743 +{
19744 +       int lim;
19745 +
19746 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
19747 +               __rlim_soft(limit, lim) = RLIM_INFINITY;
19748 +               __rlim_hard(limit, lim) = RLIM_INFINITY;
19749 +               __rlim_set(limit, lim, 0);
19750 +               atomic_set(&__rlim_lhit(limit, lim), 0);
19751 +               __rlim_rmin(limit, lim) = 0;
19752 +               __rlim_rmax(limit, lim) = 0;
19753 +       }
19754 +}
19755 +
19756 +static inline void vx_info_exit_limit(struct _vx_limit *limit)
19757 +{
19758 +       rlim_t value;
19759 +       int lim;
19760 +
19761 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
19762 +               if ((1 << lim) & VLIM_NOCHECK)
19763 +                       continue;
19764 +               value = __rlim_get(limit, lim);
19765 +               vxwprintk_xid(value,
19766 +                       "!!! limit: %p[%s,%d] = %ld on exit.",
19767 +                       limit, vlimit_name[lim], lim, (long)value);
19768 +       }
19769 +}
19770 +
19771 diff -NurpP --minimal linux-3.6/kernel/vserver/limit_proc.h linux-3.6-vs2.3.4.3-noxfs-nocow/kernel/vserver/limit_proc.h
19772 --- linux-3.6/kernel/vserver/limit_proc.h       1970-01-01 01:00:00.000000000 +0100
19773 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/kernel/vserver/limit_proc.h 2012-10-04 18:47:00.000000000 +0200
19774 @@ -0,0 +1,57 @@
19775 +#ifndef _VX_LIMIT_PROC_H
19776 +#define _VX_LIMIT_PROC_H
19777 +
19778 +#include <linux/vserver/limit_int.h>
19779 +
19780 +
19781 +#define VX_LIMIT_FMT   ":\t%8ld\t%8ld/%8ld\t%8lld/%8lld\t%6d\n"
19782 +#define VX_LIMIT_TOP   \
19783 +       "Limit\t current\t     min/max\t\t    soft/hard\t\thits\n"
19784 +
19785 +#define VX_LIMIT_ARG(r)                                \
19786 +       (unsigned long)__rlim_get(limit, r),    \
19787 +       (unsigned long)__rlim_rmin(limit, r),   \
19788 +       (unsigned long)__rlim_rmax(limit, r),   \
19789 +       VX_VLIM(__rlim_soft(limit, r)),         \
19790 +       VX_VLIM(__rlim_hard(limit, r)),         \
19791 +       atomic_read(&__rlim_lhit(limit, r))
19792 +
19793 +static inline int vx_info_proc_limit(struct _vx_limit *limit, char *buffer)
19794 +{
19795 +       vx_limit_fixup(limit, -1);
19796 +       return sprintf(buffer, VX_LIMIT_TOP
19797 +               "PROC"  VX_LIMIT_FMT
19798 +               "VM"    VX_LIMIT_FMT
19799 +               "VML"   VX_LIMIT_FMT
19800 +               "RSS"   VX_LIMIT_FMT
19801 +               "ANON"  VX_LIMIT_FMT
19802 +               "RMAP"  VX_LIMIT_FMT
19803 +               "FILES" VX_LIMIT_FMT
19804 +               "OFD"   VX_LIMIT_FMT
19805 +               "LOCKS" VX_LIMIT_FMT
19806 +               "SOCK"  VX_LIMIT_FMT
19807 +               "MSGQ"  VX_LIMIT_FMT
19808 +               "SHM"   VX_LIMIT_FMT
19809 +               "SEMA"  VX_LIMIT_FMT
19810 +               "SEMS"  VX_LIMIT_FMT
19811 +               "DENT"  VX_LIMIT_FMT,
19812 +               VX_LIMIT_ARG(RLIMIT_NPROC),
19813 +               VX_LIMIT_ARG(RLIMIT_AS),
19814 +               VX_LIMIT_ARG(RLIMIT_MEMLOCK),
19815 +               VX_LIMIT_ARG(RLIMIT_RSS),
19816 +               VX_LIMIT_ARG(VLIMIT_ANON),
19817 +               VX_LIMIT_ARG(VLIMIT_MAPPED),
19818 +               VX_LIMIT_ARG(RLIMIT_NOFILE),
19819 +               VX_LIMIT_ARG(VLIMIT_OPENFD),
19820 +               VX_LIMIT_ARG(RLIMIT_LOCKS),
19821 +               VX_LIMIT_ARG(VLIMIT_NSOCK),
19822 +               VX_LIMIT_ARG(RLIMIT_MSGQUEUE),
19823 +               VX_LIMIT_ARG(VLIMIT_SHMEM),
19824 +               VX_LIMIT_ARG(VLIMIT_SEMARY),
19825 +               VX_LIMIT_ARG(VLIMIT_NSEMS),
19826 +               VX_LIMIT_ARG(VLIMIT_DENTRY));
19827 +}
19828 +
19829 +#endif /* _VX_LIMIT_PROC_H */
19830 +
19831 +
19832 diff -NurpP --minimal linux-3.6/kernel/vserver/network.c linux-3.6-vs2.3.4.3-noxfs-nocow/kernel/vserver/network.c
19833 --- linux-3.6/kernel/vserver/network.c  1970-01-01 01:00:00.000000000 +0100
19834 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/kernel/vserver/network.c    2012-10-04 18:47:00.000000000 +0200
19835 @@ -0,0 +1,912 @@
19836 +/*
19837 + *  linux/kernel/vserver/network.c
19838 + *
19839 + *  Virtual Server: Network Support
19840 + *
19841 + *  Copyright (C) 2003-2007  Herbert Pötzl
19842 + *
19843 + *  V0.01  broken out from vcontext V0.05
19844 + *  V0.02  cleaned up implementation
19845 + *  V0.03  added equiv nx commands
19846 + *  V0.04  switch to RCU based hash
19847 + *  V0.05  and back to locking again
19848 + *  V0.06  changed vcmds to nxi arg
19849 + *  V0.07  have __create claim() the nxi
19850 + *
19851 + */
19852 +
19853 +#include <linux/err.h>
19854 +#include <linux/slab.h>
19855 +#include <linux/rcupdate.h>
19856 +
19857 +#include <linux/vs_network.h>
19858 +#include <linux/vs_pid.h>
19859 +#include <linux/vserver/network_cmd.h>
19860 +
19861 +
19862 +atomic_t nx_global_ctotal      = ATOMIC_INIT(0);
19863 +atomic_t nx_global_cactive     = ATOMIC_INIT(0);
19864 +
19865 +static struct kmem_cache *nx_addr_v4_cachep = NULL;
19866 +static struct kmem_cache *nx_addr_v6_cachep = NULL;
19867 +
19868 +
19869 +static int __init init_network(void)
19870 +{
19871 +       nx_addr_v4_cachep = kmem_cache_create("nx_v4_addr_cache",
19872 +               sizeof(struct nx_addr_v4), 0,
19873 +               SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
19874 +       nx_addr_v6_cachep = kmem_cache_create("nx_v6_addr_cache",
19875 +               sizeof(struct nx_addr_v6), 0,
19876 +               SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
19877 +       return 0;
19878 +}
19879 +
19880 +
19881 +/*     __alloc_nx_addr_v4()                                    */
19882 +
19883 +static inline struct nx_addr_v4 *__alloc_nx_addr_v4(void)
19884 +{
19885 +       struct nx_addr_v4 *nxa = kmem_cache_alloc(
19886 +               nx_addr_v4_cachep, GFP_KERNEL);
19887 +
19888 +       if (!IS_ERR(nxa))
19889 +               memset(nxa, 0, sizeof(*nxa));
19890 +       return nxa;
19891 +}
19892 +
19893 +/*     __dealloc_nx_addr_v4()                                  */
19894 +
19895 +static inline void __dealloc_nx_addr_v4(struct nx_addr_v4 *nxa)
19896 +{
19897 +       kmem_cache_free(nx_addr_v4_cachep, nxa);
19898 +}
19899 +
19900 +/*     __dealloc_nx_addr_v4_all()                              */
19901 +
19902 +static inline void __dealloc_nx_addr_v4_all(struct nx_addr_v4 *nxa)
19903 +{
19904 +       while (nxa) {
19905 +               struct nx_addr_v4 *next = nxa->next;
19906 +
19907 +               __dealloc_nx_addr_v4(nxa);
19908 +               nxa = next;
19909 +       }
19910 +}
19911 +
19912 +
19913 +#ifdef CONFIG_IPV6
19914 +
19915 +/*     __alloc_nx_addr_v6()                                    */
19916 +
19917 +static inline struct nx_addr_v6 *__alloc_nx_addr_v6(void)
19918 +{
19919 +       struct nx_addr_v6 *nxa = kmem_cache_alloc(
19920 +               nx_addr_v6_cachep, GFP_KERNEL);
19921 +
19922 +       if (!IS_ERR(nxa))
19923 +               memset(nxa, 0, sizeof(*nxa));
19924 +       return nxa;
19925 +}
19926 +
19927 +/*     __dealloc_nx_addr_v6()                                  */
19928 +
19929 +static inline void __dealloc_nx_addr_v6(struct nx_addr_v6 *nxa)
19930 +{
19931 +       kmem_cache_free(nx_addr_v6_cachep, nxa);
19932 +}
19933 +
19934 +/*     __dealloc_nx_addr_v6_all()                              */
19935 +
19936 +static inline void __dealloc_nx_addr_v6_all(struct nx_addr_v6 *nxa)
19937 +{
19938 +       while (nxa) {
19939 +               struct nx_addr_v6 *next = nxa->next;
19940 +
19941 +               __dealloc_nx_addr_v6(nxa);
19942 +               nxa = next;
19943 +       }
19944 +}
19945 +
19946 +#endif /* CONFIG_IPV6 */
19947 +
19948 +/*     __alloc_nx_info()
19949 +
19950 +       * allocate an initialized nx_info struct
19951 +       * doesn't make it visible (hash)                        */
19952 +
19953 +static struct nx_info *__alloc_nx_info(nid_t nid)
19954 +{
19955 +       struct nx_info *new = NULL;
19956 +
19957 +       vxdprintk(VXD_CBIT(nid, 1), "alloc_nx_info(%d)*", nid);
19958 +
19959 +       /* would this benefit from a slab cache? */
19960 +       new = kmalloc(sizeof(struct nx_info), GFP_KERNEL);
19961 +       if (!new)
19962 +               return 0;
19963 +
19964 +       memset(new, 0, sizeof(struct nx_info));
19965 +       new->nx_id = nid;
19966 +       INIT_HLIST_NODE(&new->nx_hlist);
19967 +       atomic_set(&new->nx_usecnt, 0);
19968 +       atomic_set(&new->nx_tasks, 0);
19969 +       new->nx_state = 0;
19970 +
19971 +       new->nx_flags = NXF_INIT_SET;
19972 +
19973 +       /* rest of init goes here */
19974 +
19975 +       new->v4_lback.s_addr = htonl(INADDR_LOOPBACK);
19976 +       new->v4_bcast.s_addr = htonl(INADDR_BROADCAST);
19977 +
19978 +       vxdprintk(VXD_CBIT(nid, 0),
19979 +               "alloc_nx_info(%d) = %p", nid, new);
19980 +       atomic_inc(&nx_global_ctotal);
19981 +       return new;
19982 +}
19983 +
19984 +/*     __dealloc_nx_info()
19985 +
19986 +       * final disposal of nx_info                             */
19987 +
19988 +static void __dealloc_nx_info(struct nx_info *nxi)
19989 +{
19990 +       vxdprintk(VXD_CBIT(nid, 0),
19991 +               "dealloc_nx_info(%p)", nxi);
19992 +
19993 +       nxi->nx_hlist.next = LIST_POISON1;
19994 +       nxi->nx_id = -1;
19995 +
19996 +       BUG_ON(atomic_read(&nxi->nx_usecnt));
19997 +       BUG_ON(atomic_read(&nxi->nx_tasks));
19998 +
19999 +       __dealloc_nx_addr_v4_all(nxi->v4.next);
20000 +
20001 +       nxi->nx_state |= NXS_RELEASED;
20002 +       kfree(nxi);
20003 +       atomic_dec(&nx_global_ctotal);
20004 +}
20005 +
20006 +static void __shutdown_nx_info(struct nx_info *nxi)
20007 +{
20008 +       nxi->nx_state |= NXS_SHUTDOWN;
20009 +       vs_net_change(nxi, VSC_NETDOWN);
20010 +}
20011 +
20012 +/*     exported stuff                                          */
20013 +
20014 +void free_nx_info(struct nx_info *nxi)
20015 +{
20016 +       /* context shutdown is mandatory */
20017 +       BUG_ON(nxi->nx_state != NXS_SHUTDOWN);
20018 +
20019 +       /* context must not be hashed */
20020 +       BUG_ON(nxi->nx_state & NXS_HASHED);
20021 +
20022 +       BUG_ON(atomic_read(&nxi->nx_usecnt));
20023 +       BUG_ON(atomic_read(&nxi->nx_tasks));
20024 +
20025 +       __dealloc_nx_info(nxi);
20026 +}
20027 +
20028 +
20029 +void __nx_set_lback(struct nx_info *nxi)
20030 +{
20031 +       int nid = nxi->nx_id;
20032 +       __be32 lback = htonl(INADDR_LOOPBACK ^ ((nid & 0xFFFF) << 8));
20033 +
20034 +       nxi->v4_lback.s_addr = lback;
20035 +}
20036 +
20037 +extern int __nx_inet_add_lback(__be32 addr);
20038 +extern int __nx_inet_del_lback(__be32 addr);
20039 +
20040 +
20041 +/*     hash table for nx_info hash */
20042 +
20043 +#define NX_HASH_SIZE   13
20044 +
20045 +struct hlist_head nx_info_hash[NX_HASH_SIZE];
20046 +
20047 +static DEFINE_SPINLOCK(nx_info_hash_lock);
20048 +
20049 +
20050 +static inline unsigned int __hashval(nid_t nid)
20051 +{
20052 +       return (nid % NX_HASH_SIZE);
20053 +}
20054 +
20055 +
20056 +
20057 +/*     __hash_nx_info()
20058 +
20059 +       * add the nxi to the global hash table
20060 +       * requires the hash_lock to be held                     */
20061 +
20062 +static inline void __hash_nx_info(struct nx_info *nxi)
20063 +{
20064 +       struct hlist_head *head;
20065 +
20066 +       vxd_assert_lock(&nx_info_hash_lock);
20067 +       vxdprintk(VXD_CBIT(nid, 4),
20068 +               "__hash_nx_info: %p[#%d]", nxi, nxi->nx_id);
20069 +
20070 +       /* context must not be hashed */
20071 +       BUG_ON(nx_info_state(nxi, NXS_HASHED));
20072 +
20073 +       nxi->nx_state |= NXS_HASHED;
20074 +       head = &nx_info_hash[__hashval(nxi->nx_id)];
20075 +       hlist_add_head(&nxi->nx_hlist, head);
20076 +       atomic_inc(&nx_global_cactive);
20077 +}
20078 +
20079 +/*     __unhash_nx_info()
20080 +
20081 +       * remove the nxi from the global hash table
20082 +       * requires the hash_lock to be held                     */
20083 +
20084 +static inline void __unhash_nx_info(struct nx_info *nxi)
20085 +{
20086 +       vxd_assert_lock(&nx_info_hash_lock);
20087 +       vxdprintk(VXD_CBIT(nid, 4),
20088 +               "__unhash_nx_info: %p[#%d.%d.%d]", nxi, nxi->nx_id,
20089 +               atomic_read(&nxi->nx_usecnt), atomic_read(&nxi->nx_tasks));
20090 +
20091 +       /* context must be hashed */
20092 +       BUG_ON(!nx_info_state(nxi, NXS_HASHED));
20093 +       /* but without tasks */
20094 +       BUG_ON(atomic_read(&nxi->nx_tasks));
20095 +
20096 +       nxi->nx_state &= ~NXS_HASHED;
20097 +       hlist_del(&nxi->nx_hlist);
20098 +       atomic_dec(&nx_global_cactive);
20099 +}
20100 +
20101 +
20102 +/*     __lookup_nx_info()
20103 +
20104 +       * requires the hash_lock to be held
20105 +       * doesn't increment the nx_refcnt                       */
20106 +
20107 +static inline struct nx_info *__lookup_nx_info(nid_t nid)
20108 +{
20109 +       struct hlist_head *head = &nx_info_hash[__hashval(nid)];
20110 +       struct hlist_node *pos;
20111 +       struct nx_info *nxi;
20112 +
20113 +       vxd_assert_lock(&nx_info_hash_lock);
20114 +       hlist_for_each(pos, head) {
20115 +               nxi = hlist_entry(pos, struct nx_info, nx_hlist);
20116 +
20117 +               if (nxi->nx_id == nid)
20118 +                       goto found;
20119 +       }
20120 +       nxi = NULL;
20121 +found:
20122 +       vxdprintk(VXD_CBIT(nid, 0),
20123 +               "__lookup_nx_info(#%u): %p[#%u]",
20124 +               nid, nxi, nxi ? nxi->nx_id : 0);
20125 +       return nxi;
20126 +}
20127 +
20128 +
20129 +/*     __create_nx_info()
20130 +
20131 +       * create the requested context
20132 +       * get(), claim() and hash it                            */
20133 +
20134 +static struct nx_info *__create_nx_info(int id)
20135 +{
20136 +       struct nx_info *new, *nxi = NULL;
20137 +
20138 +       vxdprintk(VXD_CBIT(nid, 1), "create_nx_info(%d)*", id);
20139 +
20140 +       if (!(new = __alloc_nx_info(id)))
20141 +               return ERR_PTR(-ENOMEM);
20142 +
20143 +       /* required to make dynamic xids unique */
20144 +       spin_lock(&nx_info_hash_lock);
20145 +
20146 +       /* static context requested */
20147 +       if ((nxi = __lookup_nx_info(id))) {
20148 +               vxdprintk(VXD_CBIT(nid, 0),
20149 +                       "create_nx_info(%d) = %p (already there)", id, nxi);
20150 +               if (nx_info_flags(nxi, NXF_STATE_SETUP, 0))
20151 +                       nxi = ERR_PTR(-EBUSY);
20152 +               else
20153 +                       nxi = ERR_PTR(-EEXIST);
20154 +               goto out_unlock;
20155 +       }
20156 +       /* new context */
20157 +       vxdprintk(VXD_CBIT(nid, 0),
20158 +               "create_nx_info(%d) = %p (new)", id, new);
20159 +       claim_nx_info(new, NULL);
20160 +       __nx_set_lback(new);
20161 +       __hash_nx_info(get_nx_info(new));
20162 +       nxi = new, new = NULL;
20163 +
20164 +out_unlock:
20165 +       spin_unlock(&nx_info_hash_lock);
20166 +       if (new)
20167 +               __dealloc_nx_info(new);
20168 +       return nxi;
20169 +}
20170 +
20171 +
20172 +
20173 +/*     exported stuff                                          */
20174 +
20175 +
20176 +void unhash_nx_info(struct nx_info *nxi)
20177 +{
20178 +       __shutdown_nx_info(nxi);
20179 +       spin_lock(&nx_info_hash_lock);
20180 +       __unhash_nx_info(nxi);
20181 +       spin_unlock(&nx_info_hash_lock);
20182 +}
20183 +
20184 +/*     lookup_nx_info()
20185 +
20186 +       * search for a nx_info and get() it
20187 +       * negative id means current                             */
20188 +
20189 +struct nx_info *lookup_nx_info(int id)
20190 +{
20191 +       struct nx_info *nxi = NULL;
20192 +
20193 +       if (id < 0) {
20194 +               nxi = get_nx_info(current_nx_info());
20195 +       } else if (id > 1) {
20196 +               spin_lock(&nx_info_hash_lock);
20197 +               nxi = get_nx_info(__lookup_nx_info(id));
20198 +               spin_unlock(&nx_info_hash_lock);
20199 +       }
20200 +       return nxi;
20201 +}
20202 +
20203 +/*     nid_is_hashed()
20204 +
20205 +       * verify that nid is still hashed                       */
20206 +
20207 +int nid_is_hashed(nid_t nid)
20208 +{
20209 +       int hashed;
20210 +
20211 +       spin_lock(&nx_info_hash_lock);
20212 +       hashed = (__lookup_nx_info(nid) != NULL);
20213 +       spin_unlock(&nx_info_hash_lock);
20214 +       return hashed;
20215 +}
20216 +
20217 +
20218 +#ifdef CONFIG_PROC_FS
20219 +
20220 +/*     get_nid_list()
20221 +
20222 +       * get a subset of hashed nids for proc
20223 +       * assumes size is at least one                          */
20224 +
20225 +int get_nid_list(int index, unsigned int *nids, int size)
20226 +{
20227 +       int hindex, nr_nids = 0;
20228 +
20229 +       /* only show current and children */
20230 +       if (!nx_check(0, VS_ADMIN | VS_WATCH)) {
20231 +               if (index > 0)
20232 +                       return 0;
20233 +               nids[nr_nids] = nx_current_nid();
20234 +               return 1;
20235 +       }
20236 +
20237 +       for (hindex = 0; hindex < NX_HASH_SIZE; hindex++) {
20238 +               struct hlist_head *head = &nx_info_hash[hindex];
20239 +               struct hlist_node *pos;
20240 +
20241 +               spin_lock(&nx_info_hash_lock);
20242 +               hlist_for_each(pos, head) {
20243 +                       struct nx_info *nxi;
20244 +
20245 +                       if (--index > 0)
20246 +                               continue;
20247 +
20248 +                       nxi = hlist_entry(pos, struct nx_info, nx_hlist);
20249 +                       nids[nr_nids] = nxi->nx_id;
20250 +                       if (++nr_nids >= size) {
20251 +                               spin_unlock(&nx_info_hash_lock);
20252 +                               goto out;
20253 +                       }
20254 +               }
20255 +               /* keep the lock time short */
20256 +               spin_unlock(&nx_info_hash_lock);
20257 +       }
20258 +out:
20259 +       return nr_nids;
20260 +}
20261 +#endif
20262 +
20263 +
20264 +/*
20265 + *     migrate task to new network
20266 + *     gets nxi, puts old_nxi on change
20267 + */
20268 +
20269 +int nx_migrate_task(struct task_struct *p, struct nx_info *nxi)
20270 +{
20271 +       struct nx_info *old_nxi;
20272 +       int ret = 0;
20273 +
20274 +       if (!p || !nxi)
20275 +               BUG();
20276 +
20277 +       vxdprintk(VXD_CBIT(nid, 5),
20278 +               "nx_migrate_task(%p,%p[#%d.%d.%d])",
20279 +               p, nxi, nxi->nx_id,
20280 +               atomic_read(&nxi->nx_usecnt),
20281 +               atomic_read(&nxi->nx_tasks));
20282 +
20283 +       if (nx_info_flags(nxi, NXF_INFO_PRIVATE, 0) &&
20284 +               !nx_info_flags(nxi, NXF_STATE_SETUP, 0))
20285 +               return -EACCES;
20286 +
20287 +       if (nx_info_state(nxi, NXS_SHUTDOWN))
20288 +               return -EFAULT;
20289 +
20290 +       /* maybe disallow this completely? */
20291 +       old_nxi = task_get_nx_info(p);
20292 +       if (old_nxi == nxi)
20293 +               goto out;
20294 +
20295 +       task_lock(p);
20296 +       if (old_nxi)
20297 +               clr_nx_info(&p->nx_info);
20298 +       claim_nx_info(nxi, p);
20299 +       set_nx_info(&p->nx_info, nxi);
20300 +       p->nid = nxi->nx_id;
20301 +       task_unlock(p);
20302 +
20303 +       vxdprintk(VXD_CBIT(nid, 5),
20304 +               "moved task %p into nxi:%p[#%d]",
20305 +               p, nxi, nxi->nx_id);
20306 +
20307 +       if (old_nxi)
20308 +               release_nx_info(old_nxi, p);
20309 +       ret = 0;
20310 +out:
20311 +       put_nx_info(old_nxi);
20312 +       return ret;
20313 +}
20314 +
20315 +
20316 +void nx_set_persistent(struct nx_info *nxi)
20317 +{
20318 +       vxdprintk(VXD_CBIT(nid, 6),
20319 +               "nx_set_persistent(%p[#%d])", nxi, nxi->nx_id);
20320 +
20321 +       get_nx_info(nxi);
20322 +       claim_nx_info(nxi, NULL);
20323 +}
20324 +
20325 +void nx_clear_persistent(struct nx_info *nxi)
20326 +{
20327 +       vxdprintk(VXD_CBIT(nid, 6),
20328 +               "nx_clear_persistent(%p[#%d])", nxi, nxi->nx_id);
20329 +
20330 +       release_nx_info(nxi, NULL);
20331 +       put_nx_info(nxi);
20332 +}
20333 +
20334 +void nx_update_persistent(struct nx_info *nxi)
20335 +{
20336 +       if (nx_info_flags(nxi, NXF_PERSISTENT, 0))
20337 +               nx_set_persistent(nxi);
20338 +       else
20339 +               nx_clear_persistent(nxi);
20340 +}
20341 +
20342 +/* vserver syscall commands below here */
20343 +
20344 +/* taks nid and nx_info functions */
20345 +
20346 +#include <asm/uaccess.h>
20347 +
20348 +
20349 +int vc_task_nid(uint32_t id)
20350 +{
20351 +       nid_t nid;
20352 +
20353 +       if (id) {
20354 +               struct task_struct *tsk;
20355 +
20356 +               rcu_read_lock();
20357 +               tsk = find_task_by_real_pid(id);
20358 +               nid = (tsk) ? tsk->nid : -ESRCH;
20359 +               rcu_read_unlock();
20360 +       } else
20361 +               nid = nx_current_nid();
20362 +       return nid;
20363 +}
20364 +
20365 +
20366 +int vc_nx_info(struct nx_info *nxi, void __user *data)
20367 +{
20368 +       struct vcmd_nx_info_v0 vc_data;
20369 +
20370 +       vc_data.nid = nxi->nx_id;
20371 +
20372 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20373 +               return -EFAULT;
20374 +       return 0;
20375 +}
20376 +
20377 +
20378 +/* network functions */
20379 +
20380 +int vc_net_create(uint32_t nid, void __user *data)
20381 +{
20382 +       struct vcmd_net_create vc_data = { .flagword = NXF_INIT_SET };
20383 +       struct nx_info *new_nxi;
20384 +       int ret;
20385 +
20386 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20387 +               return -EFAULT;
20388 +
20389 +       if ((nid > MAX_S_CONTEXT) || (nid < 2))
20390 +               return -EINVAL;
20391 +
20392 +       new_nxi = __create_nx_info(nid);
20393 +       if (IS_ERR(new_nxi))
20394 +               return PTR_ERR(new_nxi);
20395 +
20396 +       /* initial flags */
20397 +       new_nxi->nx_flags = vc_data.flagword;
20398 +
20399 +       ret = -ENOEXEC;
20400 +       if (vs_net_change(new_nxi, VSC_NETUP))
20401 +               goto out;
20402 +
20403 +       ret = nx_migrate_task(current, new_nxi);
20404 +       if (ret)
20405 +               goto out;
20406 +
20407 +       /* return context id on success */
20408 +       ret = new_nxi->nx_id;
20409 +
20410 +       /* get a reference for persistent contexts */
20411 +       if ((vc_data.flagword & NXF_PERSISTENT))
20412 +               nx_set_persistent(new_nxi);
20413 +out:
20414 +       release_nx_info(new_nxi, NULL);
20415 +       put_nx_info(new_nxi);
20416 +       return ret;
20417 +}
20418 +
20419 +
20420 +int vc_net_migrate(struct nx_info *nxi, void __user *data)
20421 +{
20422 +       return nx_migrate_task(current, nxi);
20423 +}
20424 +
20425 +
20426 +
20427 +int do_add_v4_addr(struct nx_info *nxi, __be32 ip, __be32 ip2, __be32 mask,
20428 +       uint16_t type, uint16_t flags)
20429 +{
20430 +       struct nx_addr_v4 *nxa = &nxi->v4;
20431 +
20432 +       if (NX_IPV4(nxi)) {
20433 +               /* locate last entry */
20434 +               for (; nxa->next; nxa = nxa->next);
20435 +               nxa->next = __alloc_nx_addr_v4();
20436 +               nxa = nxa->next;
20437 +
20438 +               if (IS_ERR(nxa))
20439 +                       return PTR_ERR(nxa);
20440 +       }
20441 +
20442 +       if (nxi->v4.next)
20443 +               /* remove single ip for ip list */
20444 +               nxi->nx_flags &= ~NXF_SINGLE_IP;
20445 +
20446 +       nxa->ip[0].s_addr = ip;
20447 +       nxa->ip[1].s_addr = ip2;
20448 +       nxa->mask.s_addr = mask;
20449 +       nxa->type = type;
20450 +       nxa->flags = flags;
20451 +       return 0;
20452 +}
20453 +
20454 +int do_remove_v4_addr(struct nx_info *nxi, __be32 ip, __be32 ip2, __be32 mask,
20455 +       uint16_t type, uint16_t flags)
20456 +{
20457 +       struct nx_addr_v4 *nxa = &nxi->v4;
20458 +
20459 +       switch (type) {
20460 +/*     case NXA_TYPE_ADDR:
20461 +               break;          */
20462 +
20463 +       case NXA_TYPE_ANY:
20464 +               __dealloc_nx_addr_v4_all(xchg(&nxa->next, NULL));
20465 +               memset(nxa, 0, sizeof(*nxa));
20466 +               break;
20467 +
20468 +       default:
20469 +               return -EINVAL;
20470 +       }
20471 +       return 0;
20472 +}
20473 +
20474 +
20475 +int vc_net_add(struct nx_info *nxi, void __user *data)
20476 +{
20477 +       struct vcmd_net_addr_v0 vc_data;
20478 +       int index, ret = 0;
20479 +
20480 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20481 +               return -EFAULT;
20482 +
20483 +       switch (vc_data.type) {
20484 +       case NXA_TYPE_IPV4:
20485 +               if ((vc_data.count < 1) || (vc_data.count > 4))
20486 +                       return -EINVAL;
20487 +
20488 +               index = 0;
20489 +               while (index < vc_data.count) {
20490 +                       ret = do_add_v4_addr(nxi, vc_data.ip[index].s_addr, 0,
20491 +                               vc_data.mask[index].s_addr, NXA_TYPE_ADDR, 0);
20492 +                       if (ret)
20493 +                               return ret;
20494 +                       index++;
20495 +               }
20496 +               ret = index;
20497 +               break;
20498 +
20499 +       case NXA_TYPE_IPV4|NXA_MOD_BCAST:
20500 +               nxi->v4_bcast = vc_data.ip[0];
20501 +               ret = 1;
20502 +               break;
20503 +
20504 +       case NXA_TYPE_IPV4|NXA_MOD_LBACK:
20505 +               nxi->v4_lback = vc_data.ip[0];
20506 +               ret = 1;
20507 +               break;
20508 +
20509 +       default:
20510 +               ret = -EINVAL;
20511 +               break;
20512 +       }
20513 +       return ret;
20514 +}
20515 +
20516 +int vc_net_remove(struct nx_info *nxi, void __user *data)
20517 +{
20518 +       struct vcmd_net_addr_v0 vc_data;
20519 +
20520 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20521 +               return -EFAULT;
20522 +
20523 +       switch (vc_data.type) {
20524 +       case NXA_TYPE_ANY:
20525 +               __dealloc_nx_addr_v4_all(xchg(&nxi->v4.next, NULL));
20526 +               memset(&nxi->v4, 0, sizeof(nxi->v4));
20527 +               break;
20528 +
20529 +       default:
20530 +               return -EINVAL;
20531 +       }
20532 +       return 0;
20533 +}
20534 +
20535 +
20536 +int vc_net_add_ipv4_v1(struct nx_info *nxi, void __user *data)
20537 +{
20538 +       struct vcmd_net_addr_ipv4_v1 vc_data;
20539 +
20540 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20541 +               return -EFAULT;
20542 +
20543 +       switch (vc_data.type) {
20544 +       case NXA_TYPE_ADDR:
20545 +       case NXA_TYPE_MASK:
20546 +               return do_add_v4_addr(nxi, vc_data.ip.s_addr, 0,
20547 +                       vc_data.mask.s_addr, vc_data.type, vc_data.flags);
20548 +
20549 +       case NXA_TYPE_ADDR | NXA_MOD_BCAST:
20550 +               nxi->v4_bcast = vc_data.ip;
20551 +               break;
20552 +
20553 +       case NXA_TYPE_ADDR | NXA_MOD_LBACK:
20554 +               nxi->v4_lback = vc_data.ip;
20555 +               break;
20556 +
20557 +       default:
20558 +               return -EINVAL;
20559 +       }
20560 +       return 0;
20561 +}
20562 +
20563 +int vc_net_add_ipv4(struct nx_info *nxi, void __user *data)
20564 +{
20565 +       struct vcmd_net_addr_ipv4_v2 vc_data;
20566 +
20567 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20568 +               return -EFAULT;
20569 +
20570 +       switch (vc_data.type) {
20571 +       case NXA_TYPE_ADDR:
20572 +       case NXA_TYPE_MASK:
20573 +       case NXA_TYPE_RANGE:
20574 +               return do_add_v4_addr(nxi, vc_data.ip.s_addr, vc_data.ip2.s_addr,
20575 +                       vc_data.mask.s_addr, vc_data.type, vc_data.flags);
20576 +
20577 +       case NXA_TYPE_ADDR | NXA_MOD_BCAST:
20578 +               nxi->v4_bcast = vc_data.ip;
20579 +               break;
20580 +
20581 +       case NXA_TYPE_ADDR | NXA_MOD_LBACK:
20582 +               nxi->v4_lback = vc_data.ip;
20583 +               break;
20584 +
20585 +       default:
20586 +               return -EINVAL;
20587 +       }
20588 +       return 0;
20589 +}
20590 +
20591 +int vc_net_rem_ipv4_v1(struct nx_info *nxi, void __user *data)
20592 +{
20593 +       struct vcmd_net_addr_ipv4_v1 vc_data;
20594 +
20595 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20596 +               return -EFAULT;
20597 +
20598 +       return do_remove_v4_addr(nxi, vc_data.ip.s_addr, 0,
20599 +               vc_data.mask.s_addr, vc_data.type, vc_data.flags);
20600 +}
20601 +
20602 +int vc_net_rem_ipv4(struct nx_info *nxi, void __user *data)
20603 +{
20604 +       struct vcmd_net_addr_ipv4_v2 vc_data;
20605 +
20606 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20607 +               return -EFAULT;
20608 +
20609 +       return do_remove_v4_addr(nxi, vc_data.ip.s_addr, vc_data.ip2.s_addr,
20610 +               vc_data.mask.s_addr, vc_data.type, vc_data.flags);
20611 +}
20612 +
20613 +#ifdef CONFIG_IPV6
20614 +
20615 +int do_add_v6_addr(struct nx_info *nxi,
20616 +       struct in6_addr *ip, struct in6_addr *mask,
20617 +       uint32_t prefix, uint16_t type, uint16_t flags)
20618 +{
20619 +       struct nx_addr_v6 *nxa = &nxi->v6;
20620 +
20621 +       if (NX_IPV6(nxi)) {
20622 +               /* locate last entry */
20623 +               for (; nxa->next; nxa = nxa->next);
20624 +               nxa->next = __alloc_nx_addr_v6();
20625 +               nxa = nxa->next;
20626 +
20627 +               if (IS_ERR(nxa))
20628 +                       return PTR_ERR(nxa);
20629 +       }
20630 +
20631 +       nxa->ip = *ip;
20632 +       nxa->mask = *mask;
20633 +       nxa->prefix = prefix;
20634 +       nxa->type = type;
20635 +       nxa->flags = flags;
20636 +       return 0;
20637 +}
20638 +
20639 +
20640 +int vc_net_add_ipv6(struct nx_info *nxi, void __user *data)
20641 +{
20642 +       struct vcmd_net_addr_ipv6_v1 vc_data;
20643 +
20644 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20645 +               return -EFAULT;
20646 +
20647 +       switch (vc_data.type) {
20648 +       case NXA_TYPE_ADDR:
20649 +               memset(&vc_data.mask, ~0, sizeof(vc_data.mask));
20650 +               /* fallthrough */
20651 +       case NXA_TYPE_MASK:
20652 +               return do_add_v6_addr(nxi, &vc_data.ip, &vc_data.mask,
20653 +                       vc_data.prefix, vc_data.type, vc_data.flags);
20654 +       default:
20655 +               return -EINVAL;
20656 +       }
20657 +       return 0;
20658 +}
20659 +
20660 +int vc_net_remove_ipv6(struct nx_info *nxi, void __user *data)
20661 +{
20662 +       struct vcmd_net_addr_ipv6_v1 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_ANY:
20669 +               __dealloc_nx_addr_v6_all(xchg(&nxi->v6.next, NULL));
20670 +               memset(&nxi->v6, 0, sizeof(nxi->v6));
20671 +               break;
20672 +
20673 +       default:
20674 +               return -EINVAL;
20675 +       }
20676 +       return 0;
20677 +}
20678 +
20679 +#endif /* CONFIG_IPV6 */
20680 +
20681 +
20682 +int vc_get_nflags(struct nx_info *nxi, void __user *data)
20683 +{
20684 +       struct vcmd_net_flags_v0 vc_data;
20685 +
20686 +       vc_data.flagword = nxi->nx_flags;
20687 +
20688 +       /* special STATE flag handling */
20689 +       vc_data.mask = vs_mask_flags(~0ULL, nxi->nx_flags, NXF_ONE_TIME);
20690 +
20691 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20692 +               return -EFAULT;
20693 +       return 0;
20694 +}
20695 +
20696 +int vc_set_nflags(struct nx_info *nxi, void __user *data)
20697 +{
20698 +       struct vcmd_net_flags_v0 vc_data;
20699 +       uint64_t mask, trigger;
20700 +
20701 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20702 +               return -EFAULT;
20703 +
20704 +       /* special STATE flag handling */
20705 +       mask = vs_mask_mask(vc_data.mask, nxi->nx_flags, NXF_ONE_TIME);
20706 +       trigger = (mask & nxi->nx_flags) ^ (mask & vc_data.flagword);
20707 +
20708 +       nxi->nx_flags = vs_mask_flags(nxi->nx_flags,
20709 +               vc_data.flagword, mask);
20710 +       if (trigger & NXF_PERSISTENT)
20711 +               nx_update_persistent(nxi);
20712 +
20713 +       return 0;
20714 +}
20715 +
20716 +int vc_get_ncaps(struct nx_info *nxi, void __user *data)
20717 +{
20718 +       struct vcmd_net_caps_v0 vc_data;
20719 +
20720 +       vc_data.ncaps = nxi->nx_ncaps;
20721 +       vc_data.cmask = ~0ULL;
20722 +
20723 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20724 +               return -EFAULT;
20725 +       return 0;
20726 +}
20727 +
20728 +int vc_set_ncaps(struct nx_info *nxi, void __user *data)
20729 +{
20730 +       struct vcmd_net_caps_v0 vc_data;
20731 +
20732 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20733 +               return -EFAULT;
20734 +
20735 +       nxi->nx_ncaps = vs_mask_flags(nxi->nx_ncaps,
20736 +               vc_data.ncaps, vc_data.cmask);
20737 +       return 0;
20738 +}
20739 +
20740 +
20741 +#include <linux/module.h>
20742 +
20743 +module_init(init_network);
20744 +
20745 +EXPORT_SYMBOL_GPL(free_nx_info);
20746 +EXPORT_SYMBOL_GPL(unhash_nx_info);
20747 +
20748 diff -NurpP --minimal linux-3.6/kernel/vserver/proc.c linux-3.6-vs2.3.4.3-noxfs-nocow/kernel/vserver/proc.c
20749 --- linux-3.6/kernel/vserver/proc.c     1970-01-01 01:00:00.000000000 +0100
20750 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/kernel/vserver/proc.c       2012-10-09 14:19:59.000000000 +0200
20751 @@ -0,0 +1,1110 @@
20752 +/*
20753 + *  linux/kernel/vserver/proc.c
20754 + *
20755 + *  Virtual Context Support
20756 + *
20757 + *  Copyright (C) 2003-2011  Herbert Pötzl
20758 + *
20759 + *  V0.01  basic structure
20760 + *  V0.02  adaptation vs1.3.0
20761 + *  V0.03  proc permissions
20762 + *  V0.04  locking/generic
20763 + *  V0.05  next generation procfs
20764 + *  V0.06  inode validation
20765 + *  V0.07  generic rewrite vid
20766 + *  V0.08  remove inode type
20767 + *  V0.09  added u/wmask info
20768 + *
20769 + */
20770 +
20771 +#include <linux/proc_fs.h>
20772 +#include <linux/fs_struct.h>
20773 +#include <linux/mount.h>
20774 +#include <linux/namei.h>
20775 +#include <asm/unistd.h>
20776 +
20777 +#include <linux/vs_context.h>
20778 +#include <linux/vs_network.h>
20779 +#include <linux/vs_cvirt.h>
20780 +
20781 +#include <linux/in.h>
20782 +#include <linux/inetdevice.h>
20783 +#include <linux/vs_inet.h>
20784 +#include <linux/vs_inet6.h>
20785 +
20786 +#include <linux/vserver/global.h>
20787 +
20788 +#include "cvirt_proc.h"
20789 +#include "cacct_proc.h"
20790 +#include "limit_proc.h"
20791 +#include "sched_proc.h"
20792 +#include "vci_config.h"
20793 +
20794 +
20795 +static inline char *print_cap_t(char *buffer, kernel_cap_t *c)
20796 +{
20797 +       unsigned __capi;
20798 +
20799 +       CAP_FOR_EACH_U32(__capi) {
20800 +               buffer += sprintf(buffer, "%08x",
20801 +                       c->cap[(_KERNEL_CAPABILITY_U32S-1) - __capi]);
20802 +       }
20803 +       return buffer;
20804 +}
20805 +
20806 +
20807 +static struct proc_dir_entry *proc_virtual;
20808 +
20809 +static struct proc_dir_entry *proc_virtnet;
20810 +
20811 +
20812 +/* first the actual feeds */
20813 +
20814 +
20815 +static int proc_vci(char *buffer)
20816 +{
20817 +       return sprintf(buffer,
20818 +               "VCIVersion:\t%04x:%04x\n"
20819 +               "VCISyscall:\t%d\n"
20820 +               "VCIKernel:\t%08x\n",
20821 +               VCI_VERSION >> 16,
20822 +               VCI_VERSION & 0xFFFF,
20823 +               __NR_vserver,
20824 +               vci_kernel_config());
20825 +}
20826 +
20827 +static int proc_virtual_info(char *buffer)
20828 +{
20829 +       return proc_vci(buffer);
20830 +}
20831 +
20832 +static int proc_virtual_status(char *buffer)
20833 +{
20834 +       return sprintf(buffer,
20835 +               "#CTotal:\t%d\n"
20836 +               "#CActive:\t%d\n"
20837 +               "#NSProxy:\t%d\t%d %d %d %d %d %d\n"
20838 +               "#InitTask:\t%d\t%d %d\n",
20839 +               atomic_read(&vx_global_ctotal),
20840 +               atomic_read(&vx_global_cactive),
20841 +               atomic_read(&vs_global_nsproxy),
20842 +               atomic_read(&vs_global_fs),
20843 +               atomic_read(&vs_global_mnt_ns),
20844 +               atomic_read(&vs_global_uts_ns),
20845 +               atomic_read(&nr_ipc_ns),
20846 +               atomic_read(&vs_global_user_ns),
20847 +               atomic_read(&vs_global_pid_ns),
20848 +               atomic_read(&init_task.usage),
20849 +               atomic_read(&init_task.nsproxy->count),
20850 +               init_task.fs->users);
20851 +}
20852 +
20853 +
20854 +int proc_vxi_info(struct vx_info *vxi, char *buffer)
20855 +{
20856 +       int length;
20857 +
20858 +       length = sprintf(buffer,
20859 +               "ID:\t%d\n"
20860 +               "Info:\t%p\n"
20861 +               "Init:\t%d\n"
20862 +               "OOM:\t%lld\n",
20863 +               vxi->vx_id,
20864 +               vxi,
20865 +               vxi->vx_initpid,
20866 +               vxi->vx_badness_bias);
20867 +       return length;
20868 +}
20869 +
20870 +int proc_vxi_status(struct vx_info *vxi, char *buffer)
20871 +{
20872 +       char *orig = buffer;
20873 +
20874 +       buffer += sprintf(buffer,
20875 +               "UseCnt:\t%d\n"
20876 +               "Tasks:\t%d\n"
20877 +               "Flags:\t%016llx\n",
20878 +               atomic_read(&vxi->vx_usecnt),
20879 +               atomic_read(&vxi->vx_tasks),
20880 +               (unsigned long long)vxi->vx_flags);
20881 +
20882 +       buffer += sprintf(buffer, "BCaps:\t");
20883 +       buffer = print_cap_t(buffer, &vxi->vx_bcaps);
20884 +       buffer += sprintf(buffer, "\n");
20885 +
20886 +       buffer += sprintf(buffer,
20887 +               "CCaps:\t%016llx\n"
20888 +               "Umask:\t%16llx\n"
20889 +               "Wmask:\t%16llx\n"
20890 +               "Spaces:\t%08lx %08lx\n",
20891 +               (unsigned long long)vxi->vx_ccaps,
20892 +               (unsigned long long)vxi->vx_umask,
20893 +               (unsigned long long)vxi->vx_wmask,
20894 +               vxi->space[0].vx_nsmask, vxi->space[1].vx_nsmask);
20895 +       return buffer - orig;
20896 +}
20897 +
20898 +int proc_vxi_limit(struct vx_info *vxi, char *buffer)
20899 +{
20900 +       return vx_info_proc_limit(&vxi->limit, buffer);
20901 +}
20902 +
20903 +int proc_vxi_sched(struct vx_info *vxi, char *buffer)
20904 +{
20905 +       int cpu, length;
20906 +
20907 +       length = vx_info_proc_sched(&vxi->sched, buffer);
20908 +       for_each_online_cpu(cpu) {
20909 +               length += vx_info_proc_sched_pc(
20910 +                       &vx_per_cpu(vxi, sched_pc, cpu),
20911 +                       buffer + length, cpu);
20912 +       }
20913 +       return length;
20914 +}
20915 +
20916 +int proc_vxi_nsproxy0(struct vx_info *vxi, char *buffer)
20917 +{
20918 +       return vx_info_proc_nsproxy(vxi->space[0].vx_nsproxy, buffer);
20919 +}
20920 +
20921 +int proc_vxi_nsproxy1(struct vx_info *vxi, char *buffer)
20922 +{
20923 +       return vx_info_proc_nsproxy(vxi->space[1].vx_nsproxy, buffer);
20924 +}
20925 +
20926 +int proc_vxi_cvirt(struct vx_info *vxi, char *buffer)
20927 +{
20928 +       int cpu, length;
20929 +
20930 +       vx_update_load(vxi);
20931 +       length = vx_info_proc_cvirt(&vxi->cvirt, buffer);
20932 +       for_each_online_cpu(cpu) {
20933 +               length += vx_info_proc_cvirt_pc(
20934 +                       &vx_per_cpu(vxi, cvirt_pc, cpu),
20935 +                       buffer + length, cpu);
20936 +       }
20937 +       return length;
20938 +}
20939 +
20940 +int proc_vxi_cacct(struct vx_info *vxi, char *buffer)
20941 +{
20942 +       return vx_info_proc_cacct(&vxi->cacct, buffer);
20943 +}
20944 +
20945 +
20946 +static int proc_virtnet_info(char *buffer)
20947 +{
20948 +       return proc_vci(buffer);
20949 +}
20950 +
20951 +static int proc_virtnet_status(char *buffer)
20952 +{
20953 +       return sprintf(buffer,
20954 +               "#CTotal:\t%d\n"
20955 +               "#CActive:\t%d\n",
20956 +               atomic_read(&nx_global_ctotal),
20957 +               atomic_read(&nx_global_cactive));
20958 +}
20959 +
20960 +int proc_nxi_info(struct nx_info *nxi, char *buffer)
20961 +{
20962 +       struct nx_addr_v4 *v4a;
20963 +#ifdef CONFIG_IPV6
20964 +       struct nx_addr_v6 *v6a;
20965 +#endif
20966 +       int length, i;
20967 +
20968 +       length = sprintf(buffer,
20969 +               "ID:\t%d\n"
20970 +               "Info:\t%p\n"
20971 +               "Bcast:\t" NIPQUAD_FMT "\n"
20972 +               "Lback:\t" NIPQUAD_FMT "\n",
20973 +               nxi->nx_id,
20974 +               nxi,
20975 +               NIPQUAD(nxi->v4_bcast.s_addr),
20976 +               NIPQUAD(nxi->v4_lback.s_addr));
20977 +
20978 +       if (!NX_IPV4(nxi))
20979 +               goto skip_v4;
20980 +       for (i = 0, v4a = &nxi->v4; v4a; i++, v4a = v4a->next)
20981 +               length += sprintf(buffer + length, "%d:\t" NXAV4_FMT "\n",
20982 +                       i, NXAV4(v4a));
20983 +skip_v4:
20984 +#ifdef CONFIG_IPV6
20985 +       if (!NX_IPV6(nxi))
20986 +               goto skip_v6;
20987 +       for (i = 0, v6a = &nxi->v6; v6a; i++, v6a = v6a->next)
20988 +               length += sprintf(buffer + length, "%d:\t" NXAV6_FMT "\n",
20989 +                       i, NXAV6(v6a));
20990 +skip_v6:
20991 +#endif
20992 +       return length;
20993 +}
20994 +
20995 +int proc_nxi_status(struct nx_info *nxi, char *buffer)
20996 +{
20997 +       int length;
20998 +
20999 +       length = sprintf(buffer,
21000 +               "UseCnt:\t%d\n"
21001 +               "Tasks:\t%d\n"
21002 +               "Flags:\t%016llx\n"
21003 +               "NCaps:\t%016llx\n",
21004 +               atomic_read(&nxi->nx_usecnt),
21005 +               atomic_read(&nxi->nx_tasks),
21006 +               (unsigned long long)nxi->nx_flags,
21007 +               (unsigned long long)nxi->nx_ncaps);
21008 +       return length;
21009 +}
21010 +
21011 +
21012 +
21013 +/* here the inode helpers */
21014 +
21015 +struct vs_entry {
21016 +       int len;
21017 +       char *name;
21018 +       mode_t mode;
21019 +       struct inode_operations *iop;
21020 +       struct file_operations *fop;
21021 +       union proc_op op;
21022 +};
21023 +
21024 +static struct inode *vs_proc_make_inode(struct super_block *sb, struct vs_entry *p)
21025 +{
21026 +       struct inode *inode = new_inode(sb);
21027 +
21028 +       if (!inode)
21029 +               goto out;
21030 +
21031 +       inode->i_mode = p->mode;
21032 +       if (p->iop)
21033 +               inode->i_op = p->iop;
21034 +       if (p->fop)
21035 +               inode->i_fop = p->fop;
21036 +
21037 +       set_nlink(inode, (p->mode & S_IFDIR) ? 2 : 1);
21038 +       inode->i_flags |= S_IMMUTABLE;
21039 +
21040 +       inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
21041 +
21042 +       inode->i_uid = 0;
21043 +       inode->i_gid = 0;
21044 +       inode->i_tag = 0;
21045 +out:
21046 +       return inode;
21047 +}
21048 +
21049 +static struct dentry *vs_proc_instantiate(struct inode *dir,
21050 +       struct dentry *dentry, int id, void *ptr)
21051 +{
21052 +       struct vs_entry *p = ptr;
21053 +       struct inode *inode = vs_proc_make_inode(dir->i_sb, p);
21054 +       struct dentry *error = ERR_PTR(-EINVAL);
21055 +
21056 +       if (!inode)
21057 +               goto out;
21058 +
21059 +       PROC_I(inode)->op = p->op;
21060 +       PROC_I(inode)->fd = id;
21061 +       d_add(dentry, inode);
21062 +       error = NULL;
21063 +out:
21064 +       return error;
21065 +}
21066 +
21067 +/* Lookups */
21068 +
21069 +typedef struct dentry *instantiate_t(struct inode *, struct dentry *, int, void *);
21070 +
21071 +/*
21072 + * Fill a directory entry.
21073 + *
21074 + * If possible create the dcache entry and derive our inode number and
21075 + * file type from dcache entry.
21076 + *
21077 + * Since all of the proc inode numbers are dynamically generated, the inode
21078 + * numbers do not exist until the inode is cache.  This means creating the
21079 + * the dcache entry in readdir is necessary to keep the inode numbers
21080 + * reported by readdir in sync with the inode numbers reported
21081 + * by stat.
21082 + */
21083 +static int proc_fill_cache(struct file *filp, void *dirent, filldir_t filldir,
21084 +       char *name, int len, instantiate_t instantiate, int id, void *ptr)
21085 +{
21086 +       struct dentry *child, *dir = filp->f_dentry;
21087 +       struct inode *inode;
21088 +       struct qstr qname;
21089 +       ino_t ino = 0;
21090 +       unsigned type = DT_UNKNOWN;
21091 +
21092 +       qname.name = name;
21093 +       qname.len  = len;
21094 +       qname.hash = full_name_hash(name, len);
21095 +
21096 +       child = d_lookup(dir, &qname);
21097 +       if (!child) {
21098 +               struct dentry *new;
21099 +               new = d_alloc(dir, &qname);
21100 +               if (new) {
21101 +                       child = instantiate(dir->d_inode, new, id, ptr);
21102 +                       if (child)
21103 +                               dput(new);
21104 +                       else
21105 +                               child = new;
21106 +               }
21107 +       }
21108 +       if (!child || IS_ERR(child) || !child->d_inode)
21109 +               goto end_instantiate;
21110 +       inode = child->d_inode;
21111 +       if (inode) {
21112 +               ino = inode->i_ino;
21113 +               type = inode->i_mode >> 12;
21114 +       }
21115 +       dput(child);
21116 +end_instantiate:
21117 +       if (!ino)
21118 +               ino = find_inode_number(dir, &qname);
21119 +       if (!ino)
21120 +               ino = 1;
21121 +       return filldir(dirent, name, len, filp->f_pos, ino, type);
21122 +}
21123 +
21124 +
21125 +
21126 +/* get and revalidate vx_info/xid */
21127 +
21128 +static inline
21129 +struct vx_info *get_proc_vx_info(struct inode *inode)
21130 +{
21131 +       return lookup_vx_info(PROC_I(inode)->fd);
21132 +}
21133 +
21134 +static int proc_xid_revalidate(struct dentry *dentry, unsigned int flags)
21135 +{
21136 +       struct inode *inode = dentry->d_inode;
21137 +       xid_t xid = PROC_I(inode)->fd;
21138 +
21139 +       if (flags & LOOKUP_RCU) /* FIXME: can be dropped? */
21140 +               return -ECHILD;
21141 +
21142 +       if (!xid || xid_is_hashed(xid))
21143 +               return 1;
21144 +       d_drop(dentry);
21145 +       return 0;
21146 +}
21147 +
21148 +
21149 +/* get and revalidate nx_info/nid */
21150 +
21151 +static int proc_nid_revalidate(struct dentry *dentry, unsigned int flags)
21152 +{
21153 +       struct inode *inode = dentry->d_inode;
21154 +       nid_t nid = PROC_I(inode)->fd;
21155 +
21156 +       if (flags & LOOKUP_RCU) /* FIXME: can be dropped? */
21157 +               return -ECHILD;
21158 +
21159 +       if (!nid || nid_is_hashed(nid))
21160 +               return 1;
21161 +       d_drop(dentry);
21162 +       return 0;
21163 +}
21164 +
21165 +
21166 +
21167 +#define PROC_BLOCK_SIZE (PAGE_SIZE - 1024)
21168 +
21169 +static ssize_t proc_vs_info_read(struct file *file, char __user *buf,
21170 +                         size_t count, loff_t *ppos)
21171 +{
21172 +       struct inode *inode = file->f_dentry->d_inode;
21173 +       unsigned long page;
21174 +       ssize_t length = 0;
21175 +
21176 +       if (count > PROC_BLOCK_SIZE)
21177 +               count = PROC_BLOCK_SIZE;
21178 +
21179 +       /* fade that out as soon as stable */
21180 +       WARN_ON(PROC_I(inode)->fd);
21181 +
21182 +       if (!(page = __get_free_page(GFP_KERNEL)))
21183 +               return -ENOMEM;
21184 +
21185 +       BUG_ON(!PROC_I(inode)->op.proc_vs_read);
21186 +       length = PROC_I(inode)->op.proc_vs_read((char *)page);
21187 +
21188 +       if (length >= 0)
21189 +               length = simple_read_from_buffer(buf, count, ppos,
21190 +                       (char *)page, length);
21191 +
21192 +       free_page(page);
21193 +       return length;
21194 +}
21195 +
21196 +static ssize_t proc_vx_info_read(struct file *file, char __user *buf,
21197 +                         size_t count, loff_t *ppos)
21198 +{
21199 +       struct inode *inode = file->f_dentry->d_inode;
21200 +       struct vx_info *vxi = NULL;
21201 +       xid_t xid = PROC_I(inode)->fd;
21202 +       unsigned long page;
21203 +       ssize_t length = 0;
21204 +
21205 +       if (count > PROC_BLOCK_SIZE)
21206 +               count = PROC_BLOCK_SIZE;
21207 +
21208 +       /* fade that out as soon as stable */
21209 +       WARN_ON(!xid);
21210 +       vxi = lookup_vx_info(xid);
21211 +       if (!vxi)
21212 +               goto out;
21213 +
21214 +       length = -ENOMEM;
21215 +       if (!(page = __get_free_page(GFP_KERNEL)))
21216 +               goto out_put;
21217 +
21218 +       BUG_ON(!PROC_I(inode)->op.proc_vxi_read);
21219 +       length = PROC_I(inode)->op.proc_vxi_read(vxi, (char *)page);
21220 +
21221 +       if (length >= 0)
21222 +               length = simple_read_from_buffer(buf, count, ppos,
21223 +                       (char *)page, length);
21224 +
21225 +       free_page(page);
21226 +out_put:
21227 +       put_vx_info(vxi);
21228 +out:
21229 +       return length;
21230 +}
21231 +
21232 +static ssize_t proc_nx_info_read(struct file *file, char __user *buf,
21233 +                         size_t count, loff_t *ppos)
21234 +{
21235 +       struct inode *inode = file->f_dentry->d_inode;
21236 +       struct nx_info *nxi = NULL;
21237 +       nid_t nid = PROC_I(inode)->fd;
21238 +       unsigned long page;
21239 +       ssize_t length = 0;
21240 +
21241 +       if (count > PROC_BLOCK_SIZE)
21242 +               count = PROC_BLOCK_SIZE;
21243 +
21244 +       /* fade that out as soon as stable */
21245 +       WARN_ON(!nid);
21246 +       nxi = lookup_nx_info(nid);
21247 +       if (!nxi)
21248 +               goto out;
21249 +
21250 +       length = -ENOMEM;
21251 +       if (!(page = __get_free_page(GFP_KERNEL)))
21252 +               goto out_put;
21253 +
21254 +       BUG_ON(!PROC_I(inode)->op.proc_nxi_read);
21255 +       length = PROC_I(inode)->op.proc_nxi_read(nxi, (char *)page);
21256 +
21257 +       if (length >= 0)
21258 +               length = simple_read_from_buffer(buf, count, ppos,
21259 +                       (char *)page, length);
21260 +
21261 +       free_page(page);
21262 +out_put:
21263 +       put_nx_info(nxi);
21264 +out:
21265 +       return length;
21266 +}
21267 +
21268 +
21269 +
21270 +/* here comes the lower level */
21271 +
21272 +
21273 +#define NOD(NAME, MODE, IOP, FOP, OP) {        \
21274 +       .len  = sizeof(NAME) - 1,       \
21275 +       .name = (NAME),                 \
21276 +       .mode = MODE,                   \
21277 +       .iop  = IOP,                    \
21278 +       .fop  = FOP,                    \
21279 +       .op   = OP,                     \
21280 +}
21281 +
21282 +
21283 +#define DIR(NAME, MODE, OTYPE)                         \
21284 +       NOD(NAME, (S_IFDIR | (MODE)),                   \
21285 +               &proc_ ## OTYPE ## _inode_operations,   \
21286 +               &proc_ ## OTYPE ## _file_operations, { } )
21287 +
21288 +#define INF(NAME, MODE, OTYPE)                         \
21289 +       NOD(NAME, (S_IFREG | (MODE)), NULL,             \
21290 +               &proc_vs_info_file_operations,          \
21291 +               { .proc_vs_read = &proc_##OTYPE } )
21292 +
21293 +#define VINF(NAME, MODE, OTYPE)                                \
21294 +       NOD(NAME, (S_IFREG | (MODE)), NULL,             \
21295 +               &proc_vx_info_file_operations,          \
21296 +               { .proc_vxi_read = &proc_##OTYPE } )
21297 +
21298 +#define NINF(NAME, MODE, OTYPE)                                \
21299 +       NOD(NAME, (S_IFREG | (MODE)), NULL,             \
21300 +               &proc_nx_info_file_operations,          \
21301 +               { .proc_nxi_read = &proc_##OTYPE } )
21302 +
21303 +
21304 +static struct file_operations proc_vs_info_file_operations = {
21305 +       .read =         proc_vs_info_read,
21306 +};
21307 +
21308 +static struct file_operations proc_vx_info_file_operations = {
21309 +       .read =         proc_vx_info_read,
21310 +};
21311 +
21312 +static struct dentry_operations proc_xid_dentry_operations = {
21313 +       .d_revalidate = proc_xid_revalidate,
21314 +};
21315 +
21316 +static struct vs_entry vx_base_stuff[] = {
21317 +       VINF("info",    S_IRUGO, vxi_info),
21318 +       VINF("status",  S_IRUGO, vxi_status),
21319 +       VINF("limit",   S_IRUGO, vxi_limit),
21320 +       VINF("sched",   S_IRUGO, vxi_sched),
21321 +       VINF("nsproxy", S_IRUGO, vxi_nsproxy0),
21322 +       VINF("nsproxy1",S_IRUGO, vxi_nsproxy1),
21323 +       VINF("cvirt",   S_IRUGO, vxi_cvirt),
21324 +       VINF("cacct",   S_IRUGO, vxi_cacct),
21325 +       {}
21326 +};
21327 +
21328 +
21329 +
21330 +
21331 +static struct dentry *proc_xid_instantiate(struct inode *dir,
21332 +       struct dentry *dentry, int id, void *ptr)
21333 +{
21334 +       dentry->d_op = &proc_xid_dentry_operations;
21335 +       return vs_proc_instantiate(dir, dentry, id, ptr);
21336 +}
21337 +
21338 +static struct dentry *proc_xid_lookup(struct inode *dir,
21339 +       struct dentry *dentry, unsigned int flags)
21340 +{
21341 +       struct vs_entry *p = vx_base_stuff;
21342 +       struct dentry *error = ERR_PTR(-ENOENT);
21343 +
21344 +       for (; p->name; p++) {
21345 +               if (p->len != dentry->d_name.len)
21346 +                       continue;
21347 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
21348 +                       break;
21349 +       }
21350 +       if (!p->name)
21351 +               goto out;
21352 +
21353 +       error = proc_xid_instantiate(dir, dentry, PROC_I(dir)->fd, p);
21354 +out:
21355 +       return error;
21356 +}
21357 +
21358 +static int proc_xid_readdir(struct file *filp,
21359 +       void *dirent, filldir_t filldir)
21360 +{
21361 +       struct dentry *dentry = filp->f_dentry;
21362 +       struct inode *inode = dentry->d_inode;
21363 +       struct vs_entry *p = vx_base_stuff;
21364 +       int size = sizeof(vx_base_stuff) / sizeof(struct vs_entry);
21365 +       int pos, index;
21366 +       u64 ino;
21367 +
21368 +       pos = filp->f_pos;
21369 +       switch (pos) {
21370 +       case 0:
21371 +               ino = inode->i_ino;
21372 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
21373 +                       goto out;
21374 +               pos++;
21375 +               /* fall through */
21376 +       case 1:
21377 +               ino = parent_ino(dentry);
21378 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
21379 +                       goto out;
21380 +               pos++;
21381 +               /* fall through */
21382 +       default:
21383 +               index = pos - 2;
21384 +               if (index >= size)
21385 +                       goto out;
21386 +               for (p += index; p->name; p++) {
21387 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
21388 +                               vs_proc_instantiate, PROC_I(inode)->fd, p))
21389 +                               goto out;
21390 +                       pos++;
21391 +               }
21392 +       }
21393 +out:
21394 +       filp->f_pos = pos;
21395 +       return 1;
21396 +}
21397 +
21398 +
21399 +
21400 +static struct file_operations proc_nx_info_file_operations = {
21401 +       .read =         proc_nx_info_read,
21402 +};
21403 +
21404 +static struct dentry_operations proc_nid_dentry_operations = {
21405 +       .d_revalidate = proc_nid_revalidate,
21406 +};
21407 +
21408 +static struct vs_entry nx_base_stuff[] = {
21409 +       NINF("info",    S_IRUGO, nxi_info),
21410 +       NINF("status",  S_IRUGO, nxi_status),
21411 +       {}
21412 +};
21413 +
21414 +
21415 +static struct dentry *proc_nid_instantiate(struct inode *dir,
21416 +       struct dentry *dentry, int id, void *ptr)
21417 +{
21418 +       dentry->d_op = &proc_nid_dentry_operations;
21419 +       return vs_proc_instantiate(dir, dentry, id, ptr);
21420 +}
21421 +
21422 +static struct dentry *proc_nid_lookup(struct inode *dir,
21423 +       struct dentry *dentry, unsigned int flags)
21424 +{
21425 +       struct vs_entry *p = nx_base_stuff;
21426 +       struct dentry *error = ERR_PTR(-ENOENT);
21427 +
21428 +       for (; p->name; p++) {
21429 +               if (p->len != dentry->d_name.len)
21430 +                       continue;
21431 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
21432 +                       break;
21433 +       }
21434 +       if (!p->name)
21435 +               goto out;
21436 +
21437 +       error = proc_nid_instantiate(dir, dentry, PROC_I(dir)->fd, p);
21438 +out:
21439 +       return error;
21440 +}
21441 +
21442 +static int proc_nid_readdir(struct file *filp,
21443 +       void *dirent, filldir_t filldir)
21444 +{
21445 +       struct dentry *dentry = filp->f_dentry;
21446 +       struct inode *inode = dentry->d_inode;
21447 +       struct vs_entry *p = nx_base_stuff;
21448 +       int size = sizeof(nx_base_stuff) / sizeof(struct vs_entry);
21449 +       int pos, index;
21450 +       u64 ino;
21451 +
21452 +       pos = filp->f_pos;
21453 +       switch (pos) {
21454 +       case 0:
21455 +               ino = inode->i_ino;
21456 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
21457 +                       goto out;
21458 +               pos++;
21459 +               /* fall through */
21460 +       case 1:
21461 +               ino = parent_ino(dentry);
21462 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
21463 +                       goto out;
21464 +               pos++;
21465 +               /* fall through */
21466 +       default:
21467 +               index = pos - 2;
21468 +               if (index >= size)
21469 +                       goto out;
21470 +               for (p += index; p->name; p++) {
21471 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
21472 +                               vs_proc_instantiate, PROC_I(inode)->fd, p))
21473 +                               goto out;
21474 +                       pos++;
21475 +               }
21476 +       }
21477 +out:
21478 +       filp->f_pos = pos;
21479 +       return 1;
21480 +}
21481 +
21482 +
21483 +#define MAX_MULBY10    ((~0U - 9) / 10)
21484 +
21485 +static inline int atovid(const char *str, int len)
21486 +{
21487 +       int vid, c;
21488 +
21489 +       vid = 0;
21490 +       while (len-- > 0) {
21491 +               c = *str - '0';
21492 +               str++;
21493 +               if (c > 9)
21494 +                       return -1;
21495 +               if (vid >= MAX_MULBY10)
21496 +                       return -1;
21497 +               vid *= 10;
21498 +               vid += c;
21499 +               if (!vid)
21500 +                       return -1;
21501 +       }
21502 +       return vid;
21503 +}
21504 +
21505 +/* now the upper level (virtual) */
21506 +
21507 +
21508 +static struct file_operations proc_xid_file_operations = {
21509 +       .read =         generic_read_dir,
21510 +       .readdir =      proc_xid_readdir,
21511 +};
21512 +
21513 +static struct inode_operations proc_xid_inode_operations = {
21514 +       .lookup =       proc_xid_lookup,
21515 +};
21516 +
21517 +static struct vs_entry vx_virtual_stuff[] = {
21518 +       INF("info",     S_IRUGO, virtual_info),
21519 +       INF("status",   S_IRUGO, virtual_status),
21520 +       DIR(NULL,       S_IRUGO | S_IXUGO, xid),
21521 +};
21522 +
21523 +
21524 +static struct dentry *proc_virtual_lookup(struct inode *dir,
21525 +       struct dentry *dentry, unsigned int flags)
21526 +{
21527 +       struct vs_entry *p = vx_virtual_stuff;
21528 +       struct dentry *error = ERR_PTR(-ENOENT);
21529 +       int id = 0;
21530 +
21531 +       for (; p->name; p++) {
21532 +               if (p->len != dentry->d_name.len)
21533 +                       continue;
21534 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
21535 +                       break;
21536 +       }
21537 +       if (p->name)
21538 +               goto instantiate;
21539 +
21540 +       id = atovid(dentry->d_name.name, dentry->d_name.len);
21541 +       if ((id < 0) || !xid_is_hashed(id))
21542 +               goto out;
21543 +
21544 +instantiate:
21545 +       error = proc_xid_instantiate(dir, dentry, id, p);
21546 +out:
21547 +       return error;
21548 +}
21549 +
21550 +static struct file_operations proc_nid_file_operations = {
21551 +       .read =         generic_read_dir,
21552 +       .readdir =      proc_nid_readdir,
21553 +};
21554 +
21555 +static struct inode_operations proc_nid_inode_operations = {
21556 +       .lookup =       proc_nid_lookup,
21557 +};
21558 +
21559 +static struct vs_entry nx_virtnet_stuff[] = {
21560 +       INF("info",     S_IRUGO, virtnet_info),
21561 +       INF("status",   S_IRUGO, virtnet_status),
21562 +       DIR(NULL,       S_IRUGO | S_IXUGO, nid),
21563 +};
21564 +
21565 +
21566 +static struct dentry *proc_virtnet_lookup(struct inode *dir,
21567 +       struct dentry *dentry, unsigned int flags)
21568 +{
21569 +       struct vs_entry *p = nx_virtnet_stuff;
21570 +       struct dentry *error = ERR_PTR(-ENOENT);
21571 +       int id = 0;
21572 +
21573 +       for (; p->name; p++) {
21574 +               if (p->len != dentry->d_name.len)
21575 +                       continue;
21576 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
21577 +                       break;
21578 +       }
21579 +       if (p->name)
21580 +               goto instantiate;
21581 +
21582 +       id = atovid(dentry->d_name.name, dentry->d_name.len);
21583 +       if ((id < 0) || !nid_is_hashed(id))
21584 +               goto out;
21585 +
21586 +instantiate:
21587 +       error = proc_nid_instantiate(dir, dentry, id, p);
21588 +out:
21589 +       return error;
21590 +}
21591 +
21592 +
21593 +#define PROC_MAXVIDS 32
21594 +
21595 +int proc_virtual_readdir(struct file *filp,
21596 +       void *dirent, filldir_t filldir)
21597 +{
21598 +       struct dentry *dentry = filp->f_dentry;
21599 +       struct inode *inode = dentry->d_inode;
21600 +       struct vs_entry *p = vx_virtual_stuff;
21601 +       int size = sizeof(vx_virtual_stuff) / sizeof(struct vs_entry);
21602 +       int pos, index;
21603 +       unsigned int xid_array[PROC_MAXVIDS];
21604 +       char buf[PROC_NUMBUF];
21605 +       unsigned int nr_xids, i;
21606 +       u64 ino;
21607 +
21608 +       pos = filp->f_pos;
21609 +       switch (pos) {
21610 +       case 0:
21611 +               ino = inode->i_ino;
21612 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
21613 +                       goto out;
21614 +               pos++;
21615 +               /* fall through */
21616 +       case 1:
21617 +               ino = parent_ino(dentry);
21618 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
21619 +                       goto out;
21620 +               pos++;
21621 +               /* fall through */
21622 +       default:
21623 +               index = pos - 2;
21624 +               if (index >= size)
21625 +                       goto entries;
21626 +               for (p += index; p->name; p++) {
21627 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
21628 +                               vs_proc_instantiate, 0, p))
21629 +                               goto out;
21630 +                       pos++;
21631 +               }
21632 +       entries:
21633 +               index = pos - size;
21634 +               p = &vx_virtual_stuff[size - 1];
21635 +               nr_xids = get_xid_list(index, xid_array, PROC_MAXVIDS);
21636 +               for (i = 0; i < nr_xids; i++) {
21637 +                       int n, xid = xid_array[i];
21638 +                       unsigned int j = PROC_NUMBUF;
21639 +
21640 +                       n = xid;
21641 +                       do
21642 +                               buf[--j] = '0' + (n % 10);
21643 +                       while (n /= 10);
21644 +
21645 +                       if (proc_fill_cache(filp, dirent, filldir,
21646 +                               buf + j, PROC_NUMBUF - j,
21647 +                               vs_proc_instantiate, xid, p))
21648 +                               goto out;
21649 +                       pos++;
21650 +               }
21651 +       }
21652 +out:
21653 +       filp->f_pos = pos;
21654 +       return 0;
21655 +}
21656 +
21657 +static int proc_virtual_getattr(struct vfsmount *mnt,
21658 +       struct dentry *dentry, struct kstat *stat)
21659 +{
21660 +       struct inode *inode = dentry->d_inode;
21661 +
21662 +       generic_fillattr(inode, stat);
21663 +       stat->nlink = 2 + atomic_read(&vx_global_cactive);
21664 +       return 0;
21665 +}
21666 +
21667 +static struct file_operations proc_virtual_dir_operations = {
21668 +       .read =         generic_read_dir,
21669 +       .readdir =      proc_virtual_readdir,
21670 +};
21671 +
21672 +static struct inode_operations proc_virtual_dir_inode_operations = {
21673 +       .getattr =      proc_virtual_getattr,
21674 +       .lookup =       proc_virtual_lookup,
21675 +};
21676 +
21677 +
21678 +
21679 +
21680 +
21681 +int proc_virtnet_readdir(struct file *filp,
21682 +       void *dirent, filldir_t filldir)
21683 +{
21684 +       struct dentry *dentry = filp->f_dentry;
21685 +       struct inode *inode = dentry->d_inode;
21686 +       struct vs_entry *p = nx_virtnet_stuff;
21687 +       int size = sizeof(nx_virtnet_stuff) / sizeof(struct vs_entry);
21688 +       int pos, index;
21689 +       unsigned int nid_array[PROC_MAXVIDS];
21690 +       char buf[PROC_NUMBUF];
21691 +       unsigned int nr_nids, i;
21692 +       u64 ino;
21693 +
21694 +       pos = filp->f_pos;
21695 +       switch (pos) {
21696 +       case 0:
21697 +               ino = inode->i_ino;
21698 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
21699 +                       goto out;
21700 +               pos++;
21701 +               /* fall through */
21702 +       case 1:
21703 +               ino = parent_ino(dentry);
21704 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
21705 +                       goto out;
21706 +               pos++;
21707 +               /* fall through */
21708 +       default:
21709 +               index = pos - 2;
21710 +               if (index >= size)
21711 +                       goto entries;
21712 +               for (p += index; p->name; p++) {
21713 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
21714 +                               vs_proc_instantiate, 0, p))
21715 +                               goto out;
21716 +                       pos++;
21717 +               }
21718 +       entries:
21719 +               index = pos - size;
21720 +               p = &nx_virtnet_stuff[size - 1];
21721 +               nr_nids = get_nid_list(index, nid_array, PROC_MAXVIDS);
21722 +               for (i = 0; i < nr_nids; i++) {
21723 +                       int n, nid = nid_array[i];
21724 +                       unsigned int j = PROC_NUMBUF;
21725 +
21726 +                       n = nid;
21727 +                       do
21728 +                               buf[--j] = '0' + (n % 10);
21729 +                       while (n /= 10);
21730 +
21731 +                       if (proc_fill_cache(filp, dirent, filldir,
21732 +                               buf + j, PROC_NUMBUF - j,
21733 +                               vs_proc_instantiate, nid, p))
21734 +                               goto out;
21735 +                       pos++;
21736 +               }
21737 +       }
21738 +out:
21739 +       filp->f_pos = pos;
21740 +       return 0;
21741 +}
21742 +
21743 +static int proc_virtnet_getattr(struct vfsmount *mnt,
21744 +       struct dentry *dentry, struct kstat *stat)
21745 +{
21746 +       struct inode *inode = dentry->d_inode;
21747 +
21748 +       generic_fillattr(inode, stat);
21749 +       stat->nlink = 2 + atomic_read(&nx_global_cactive);
21750 +       return 0;
21751 +}
21752 +
21753 +static struct file_operations proc_virtnet_dir_operations = {
21754 +       .read =         generic_read_dir,
21755 +       .readdir =      proc_virtnet_readdir,
21756 +};
21757 +
21758 +static struct inode_operations proc_virtnet_dir_inode_operations = {
21759 +       .getattr =      proc_virtnet_getattr,
21760 +       .lookup =       proc_virtnet_lookup,
21761 +};
21762 +
21763 +
21764 +
21765 +void proc_vx_init(void)
21766 +{
21767 +       struct proc_dir_entry *ent;
21768 +
21769 +       ent = proc_mkdir("virtual", 0);
21770 +       if (ent) {
21771 +               ent->proc_fops = &proc_virtual_dir_operations;
21772 +               ent->proc_iops = &proc_virtual_dir_inode_operations;
21773 +       }
21774 +       proc_virtual = ent;
21775 +
21776 +       ent = proc_mkdir("virtnet", 0);
21777 +       if (ent) {
21778 +               ent->proc_fops = &proc_virtnet_dir_operations;
21779 +               ent->proc_iops = &proc_virtnet_dir_inode_operations;
21780 +       }
21781 +       proc_virtnet = ent;
21782 +}
21783 +
21784 +
21785 +
21786 +
21787 +/* per pid info */
21788 +
21789 +
21790 +int proc_pid_vx_info(struct task_struct *p, char *buffer)
21791 +{
21792 +       struct vx_info *vxi;
21793 +       char *orig = buffer;
21794 +
21795 +       buffer += sprintf(buffer, "XID:\t%d\n", vx_task_xid(p));
21796 +
21797 +       vxi = task_get_vx_info(p);
21798 +       if (!vxi)
21799 +               goto out;
21800 +
21801 +       buffer += sprintf(buffer, "BCaps:\t");
21802 +       buffer = print_cap_t(buffer, &vxi->vx_bcaps);
21803 +       buffer += sprintf(buffer, "\n");
21804 +       buffer += sprintf(buffer, "CCaps:\t%016llx\n",
21805 +               (unsigned long long)vxi->vx_ccaps);
21806 +       buffer += sprintf(buffer, "CFlags:\t%016llx\n",
21807 +               (unsigned long long)vxi->vx_flags);
21808 +       buffer += sprintf(buffer, "CIPid:\t%d\n", vxi->vx_initpid);
21809 +
21810 +       put_vx_info(vxi);
21811 +out:
21812 +       return buffer - orig;
21813 +}
21814 +
21815 +
21816 +int proc_pid_nx_info(struct task_struct *p, char *buffer)
21817 +{
21818 +       struct nx_info *nxi;
21819 +       struct nx_addr_v4 *v4a;
21820 +#ifdef CONFIG_IPV6
21821 +       struct nx_addr_v6 *v6a;
21822 +#endif
21823 +       char *orig = buffer;
21824 +       int i;
21825 +
21826 +       buffer += sprintf(buffer, "NID:\t%d\n", nx_task_nid(p));
21827 +
21828 +       nxi = task_get_nx_info(p);
21829 +       if (!nxi)
21830 +               goto out;
21831 +
21832 +       buffer += sprintf(buffer, "NCaps:\t%016llx\n",
21833 +               (unsigned long long)nxi->nx_ncaps);
21834 +       buffer += sprintf(buffer, "NFlags:\t%016llx\n",
21835 +               (unsigned long long)nxi->nx_flags);
21836 +
21837 +       buffer += sprintf(buffer,
21838 +               "V4Root[bcast]:\t" NIPQUAD_FMT "\n",
21839 +               NIPQUAD(nxi->v4_bcast.s_addr));
21840 +       buffer += sprintf (buffer,
21841 +               "V4Root[lback]:\t" NIPQUAD_FMT "\n",
21842 +               NIPQUAD(nxi->v4_lback.s_addr));
21843 +       if (!NX_IPV4(nxi))
21844 +               goto skip_v4;
21845 +       for (i = 0, v4a = &nxi->v4; v4a; i++, v4a = v4a->next)
21846 +               buffer += sprintf(buffer, "V4Root[%d]:\t" NXAV4_FMT "\n",
21847 +                       i, NXAV4(v4a));
21848 +skip_v4:
21849 +#ifdef CONFIG_IPV6
21850 +       if (!NX_IPV6(nxi))
21851 +               goto skip_v6;
21852 +       for (i = 0, v6a = &nxi->v6; v6a; i++, v6a = v6a->next)
21853 +               buffer += sprintf(buffer, "V6Root[%d]:\t" NXAV6_FMT "\n",
21854 +                       i, NXAV6(v6a));
21855 +skip_v6:
21856 +#endif
21857 +       put_nx_info(nxi);
21858 +out:
21859 +       return buffer - orig;
21860 +}
21861 +
21862 diff -NurpP --minimal linux-3.6/kernel/vserver/sched.c linux-3.6-vs2.3.4.3-noxfs-nocow/kernel/vserver/sched.c
21863 --- linux-3.6/kernel/vserver/sched.c    1970-01-01 01:00:00.000000000 +0100
21864 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/kernel/vserver/sched.c      2012-10-04 18:47:00.000000000 +0200
21865 @@ -0,0 +1,83 @@
21866 +/*
21867 + *  linux/kernel/vserver/sched.c
21868 + *
21869 + *  Virtual Server: Scheduler Support
21870 + *
21871 + *  Copyright (C) 2004-2010  Herbert Pötzl
21872 + *
21873 + *  V0.01  adapted Sam Vilains version to 2.6.3
21874 + *  V0.02  removed legacy interface
21875 + *  V0.03  changed vcmds to vxi arg
21876 + *  V0.04  removed older and legacy interfaces
21877 + *  V0.05  removed scheduler code/commands
21878 + *
21879 + */
21880 +
21881 +#include <linux/vs_context.h>
21882 +#include <linux/vs_sched.h>
21883 +#include <linux/cpumask.h>
21884 +#include <linux/vserver/sched_cmd.h>
21885 +
21886 +#include <asm/uaccess.h>
21887 +
21888 +
21889 +void vx_update_sched_param(struct _vx_sched *sched,
21890 +       struct _vx_sched_pc *sched_pc)
21891 +{
21892 +       sched_pc->prio_bias = sched->prio_bias;
21893 +}
21894 +
21895 +static int do_set_prio_bias(struct vx_info *vxi, struct vcmd_prio_bias *data)
21896 +{
21897 +       int cpu;
21898 +
21899 +       if (data->prio_bias > MAX_PRIO_BIAS)
21900 +               data->prio_bias = MAX_PRIO_BIAS;
21901 +       if (data->prio_bias < MIN_PRIO_BIAS)
21902 +               data->prio_bias = MIN_PRIO_BIAS;
21903 +
21904 +       if (data->cpu_id != ~0) {
21905 +               vxi->sched.update = cpumask_of_cpu(data->cpu_id);
21906 +               cpumask_and(&vxi->sched.update, &vxi->sched.update,
21907 +                       cpu_online_mask);
21908 +       } else
21909 +               cpumask_copy(&vxi->sched.update, cpu_online_mask);
21910 +
21911 +       for_each_cpu_mask(cpu, vxi->sched.update)
21912 +               vx_update_sched_param(&vxi->sched,
21913 +                       &vx_per_cpu(vxi, sched_pc, cpu));
21914 +       return 0;
21915 +}
21916 +
21917 +int vc_set_prio_bias(struct vx_info *vxi, void __user *data)
21918 +{
21919 +       struct vcmd_prio_bias vc_data;
21920 +
21921 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21922 +               return -EFAULT;
21923 +
21924 +       return do_set_prio_bias(vxi, &vc_data);
21925 +}
21926 +
21927 +int vc_get_prio_bias(struct vx_info *vxi, void __user *data)
21928 +{
21929 +       struct vcmd_prio_bias vc_data;
21930 +       struct _vx_sched_pc *pcd;
21931 +       int cpu;
21932 +
21933 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21934 +               return -EFAULT;
21935 +
21936 +       cpu = vc_data.cpu_id;
21937 +
21938 +       if (!cpu_possible(cpu))
21939 +               return -EINVAL;
21940 +
21941 +       pcd = &vx_per_cpu(vxi, sched_pc, cpu);
21942 +       vc_data.prio_bias = pcd->prio_bias;
21943 +
21944 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21945 +               return -EFAULT;
21946 +       return 0;
21947 +}
21948 +
21949 diff -NurpP --minimal linux-3.6/kernel/vserver/sched_init.h linux-3.6-vs2.3.4.3-noxfs-nocow/kernel/vserver/sched_init.h
21950 --- linux-3.6/kernel/vserver/sched_init.h       1970-01-01 01:00:00.000000000 +0100
21951 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/kernel/vserver/sched_init.h 2012-10-04 18:47:00.000000000 +0200
21952 @@ -0,0 +1,27 @@
21953 +
21954 +static inline void vx_info_init_sched(struct _vx_sched *sched)
21955 +{
21956 +       /* scheduling; hard code starting values as constants */
21957 +       sched->prio_bias = 0;
21958 +}
21959 +
21960 +static inline
21961 +void vx_info_init_sched_pc(struct _vx_sched_pc *sched_pc, int cpu)
21962 +{
21963 +       sched_pc->prio_bias = 0;
21964 +
21965 +       sched_pc->user_ticks = 0;
21966 +       sched_pc->sys_ticks = 0;
21967 +       sched_pc->hold_ticks = 0;
21968 +}
21969 +
21970 +static inline void vx_info_exit_sched(struct _vx_sched *sched)
21971 +{
21972 +       return;
21973 +}
21974 +
21975 +static inline
21976 +void vx_info_exit_sched_pc(struct _vx_sched_pc *sched_pc, int cpu)
21977 +{
21978 +       return;
21979 +}
21980 diff -NurpP --minimal linux-3.6/kernel/vserver/sched_proc.h linux-3.6-vs2.3.4.3-noxfs-nocow/kernel/vserver/sched_proc.h
21981 --- linux-3.6/kernel/vserver/sched_proc.h       1970-01-01 01:00:00.000000000 +0100
21982 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/kernel/vserver/sched_proc.h 2012-10-04 18:47:00.000000000 +0200
21983 @@ -0,0 +1,32 @@
21984 +#ifndef _VX_SCHED_PROC_H
21985 +#define _VX_SCHED_PROC_H
21986 +
21987 +
21988 +static inline
21989 +int vx_info_proc_sched(struct _vx_sched *sched, char *buffer)
21990 +{
21991 +       int length = 0;
21992 +
21993 +       length += sprintf(buffer,
21994 +               "PrioBias:\t%8d\n",
21995 +               sched->prio_bias);
21996 +       return length;
21997 +}
21998 +
21999 +static inline
22000 +int vx_info_proc_sched_pc(struct _vx_sched_pc *sched_pc,
22001 +       char *buffer, int cpu)
22002 +{
22003 +       int length = 0;
22004 +
22005 +       length += sprintf(buffer + length,
22006 +               "cpu %d: %lld %lld %lld", cpu,
22007 +               (unsigned long long)sched_pc->user_ticks,
22008 +               (unsigned long long)sched_pc->sys_ticks,
22009 +               (unsigned long long)sched_pc->hold_ticks);
22010 +       length += sprintf(buffer + length,
22011 +               " %d\n", sched_pc->prio_bias);
22012 +       return length;
22013 +}
22014 +
22015 +#endif /* _VX_SCHED_PROC_H */
22016 diff -NurpP --minimal linux-3.6/kernel/vserver/signal.c linux-3.6-vs2.3.4.3-noxfs-nocow/kernel/vserver/signal.c
22017 --- linux-3.6/kernel/vserver/signal.c   1970-01-01 01:00:00.000000000 +0100
22018 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/kernel/vserver/signal.c     2012-10-04 18:47:00.000000000 +0200
22019 @@ -0,0 +1,134 @@
22020 +/*
22021 + *  linux/kernel/vserver/signal.c
22022 + *
22023 + *  Virtual Server: Signal Support
22024 + *
22025 + *  Copyright (C) 2003-2007  Herbert Pötzl
22026 + *
22027 + *  V0.01  broken out from vcontext V0.05
22028 + *  V0.02  changed vcmds to vxi arg
22029 + *  V0.03  adjusted siginfo for kill
22030 + *
22031 + */
22032 +
22033 +#include <asm/uaccess.h>
22034 +
22035 +#include <linux/vs_context.h>
22036 +#include <linux/vs_pid.h>
22037 +#include <linux/vserver/signal_cmd.h>
22038 +
22039 +
22040 +int vx_info_kill(struct vx_info *vxi, int pid, int sig)
22041 +{
22042 +       int retval, count = 0;
22043 +       struct task_struct *p;
22044 +       struct siginfo *sip = SEND_SIG_PRIV;
22045 +
22046 +       retval = -ESRCH;
22047 +       vxdprintk(VXD_CBIT(misc, 4),
22048 +               "vx_info_kill(%p[#%d],%d,%d)*",
22049 +               vxi, vxi->vx_id, pid, sig);
22050 +       read_lock(&tasklist_lock);
22051 +       switch (pid) {
22052 +       case  0:
22053 +       case -1:
22054 +               for_each_process(p) {
22055 +                       int err = 0;
22056 +
22057 +                       if (vx_task_xid(p) != vxi->vx_id || p->pid <= 1 ||
22058 +                               (pid && vxi->vx_initpid == p->pid))
22059 +                               continue;
22060 +
22061 +                       err = group_send_sig_info(sig, sip, p);
22062 +                       ++count;
22063 +                       if (err != -EPERM)
22064 +                               retval = err;
22065 +               }
22066 +               break;
22067 +
22068 +       case 1:
22069 +               if (vxi->vx_initpid) {
22070 +                       pid = vxi->vx_initpid;
22071 +                       /* for now, only SIGINT to private init ... */
22072 +                       if (!vx_info_flags(vxi, VXF_STATE_ADMIN, 0) &&
22073 +                               /* ... as long as there are tasks left */
22074 +                               (atomic_read(&vxi->vx_tasks) > 1))
22075 +                               sig = SIGINT;
22076 +               }
22077 +               /* fallthrough */
22078 +       default:
22079 +               rcu_read_lock();
22080 +               p = find_task_by_real_pid(pid);
22081 +               rcu_read_unlock();
22082 +               if (p) {
22083 +                       if (vx_task_xid(p) == vxi->vx_id)
22084 +                               retval = group_send_sig_info(sig, sip, p);
22085 +               }
22086 +               break;
22087 +       }
22088 +       read_unlock(&tasklist_lock);
22089 +       vxdprintk(VXD_CBIT(misc, 4),
22090 +               "vx_info_kill(%p[#%d],%d,%d,%ld) = %d",
22091 +               vxi, vxi->vx_id, pid, sig, (long)sip, retval);
22092 +       return retval;
22093 +}
22094 +
22095 +int vc_ctx_kill(struct vx_info *vxi, void __user *data)
22096 +{
22097 +       struct vcmd_ctx_kill_v0 vc_data;
22098 +
22099 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
22100 +               return -EFAULT;
22101 +
22102 +       /* special check to allow guest shutdown */
22103 +       if (!vx_info_flags(vxi, VXF_STATE_ADMIN, 0) &&
22104 +               /* forbid killall pid=0 when init is present */
22105 +               (((vc_data.pid < 1) && vxi->vx_initpid) ||
22106 +               (vc_data.pid > 1)))
22107 +               return -EACCES;
22108 +
22109 +       return vx_info_kill(vxi, vc_data.pid, vc_data.sig);
22110 +}
22111 +
22112 +
22113 +static int __wait_exit(struct vx_info *vxi)
22114 +{
22115 +       DECLARE_WAITQUEUE(wait, current);
22116 +       int ret = 0;
22117 +
22118 +       add_wait_queue(&vxi->vx_wait, &wait);
22119 +       set_current_state(TASK_INTERRUPTIBLE);
22120 +
22121 +wait:
22122 +       if (vx_info_state(vxi,
22123 +               VXS_SHUTDOWN | VXS_HASHED | VXS_HELPER) == VXS_SHUTDOWN)
22124 +               goto out;
22125 +       if (signal_pending(current)) {
22126 +               ret = -ERESTARTSYS;
22127 +               goto out;
22128 +       }
22129 +       schedule();
22130 +       goto wait;
22131 +
22132 +out:
22133 +       set_current_state(TASK_RUNNING);
22134 +       remove_wait_queue(&vxi->vx_wait, &wait);
22135 +       return ret;
22136 +}
22137 +
22138 +
22139 +
22140 +int vc_wait_exit(struct vx_info *vxi, void __user *data)
22141 +{
22142 +       struct vcmd_wait_exit_v0 vc_data;
22143 +       int ret;
22144 +
22145 +       ret = __wait_exit(vxi);
22146 +       vc_data.reboot_cmd = vxi->reboot_cmd;
22147 +       vc_data.exit_code = vxi->exit_code;
22148 +
22149 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
22150 +               ret = -EFAULT;
22151 +       return ret;
22152 +}
22153 +
22154 diff -NurpP --minimal linux-3.6/kernel/vserver/space.c linux-3.6-vs2.3.4.3-noxfs-nocow/kernel/vserver/space.c
22155 --- linux-3.6/kernel/vserver/space.c    1970-01-01 01:00:00.000000000 +0100
22156 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/kernel/vserver/space.c      2012-10-04 18:47:00.000000000 +0200
22157 @@ -0,0 +1,436 @@
22158 +/*
22159 + *  linux/kernel/vserver/space.c
22160 + *
22161 + *  Virtual Server: Context Space Support
22162 + *
22163 + *  Copyright (C) 2003-2010  Herbert Pötzl
22164 + *
22165 + *  V0.01  broken out from context.c 0.07
22166 + *  V0.02  added task locking for namespace
22167 + *  V0.03  broken out vx_enter_namespace
22168 + *  V0.04  added *space support and commands
22169 + *  V0.05  added credential support
22170 + *
22171 + */
22172 +
22173 +#include <linux/utsname.h>
22174 +#include <linux/nsproxy.h>
22175 +#include <linux/err.h>
22176 +#include <linux/fs_struct.h>
22177 +#include <linux/cred.h>
22178 +#include <asm/uaccess.h>
22179 +
22180 +#include <linux/vs_context.h>
22181 +#include <linux/vserver/space.h>
22182 +#include <linux/vserver/space_cmd.h>
22183 +
22184 +atomic_t vs_global_nsproxy     = ATOMIC_INIT(0);
22185 +atomic_t vs_global_fs          = ATOMIC_INIT(0);
22186 +atomic_t vs_global_mnt_ns      = ATOMIC_INIT(0);
22187 +atomic_t vs_global_uts_ns      = ATOMIC_INIT(0);
22188 +atomic_t vs_global_user_ns     = ATOMIC_INIT(0);
22189 +atomic_t vs_global_pid_ns      = ATOMIC_INIT(0);
22190 +
22191 +
22192 +/* namespace functions */
22193 +
22194 +#include <linux/mnt_namespace.h>
22195 +#include <linux/user_namespace.h>
22196 +#include <linux/pid_namespace.h>
22197 +#include <linux/ipc_namespace.h>
22198 +#include <net/net_namespace.h>
22199 +#include "../fs/mount.h"
22200 +
22201 +
22202 +static const struct vcmd_space_mask_v1 space_mask_v0 = {
22203 +       .mask = CLONE_FS |
22204 +               CLONE_NEWNS |
22205 +#ifdef CONFIG_UTS_NS
22206 +               CLONE_NEWUTS |
22207 +#endif
22208 +#ifdef CONFIG_IPC_NS
22209 +               CLONE_NEWIPC |
22210 +#endif
22211 +#ifdef CONFIG_USER_NS
22212 +               CLONE_NEWUSER |
22213 +#endif
22214 +               0
22215 +};
22216 +
22217 +static const struct vcmd_space_mask_v1 space_mask = {
22218 +       .mask = CLONE_FS |
22219 +               CLONE_NEWNS |
22220 +#ifdef CONFIG_UTS_NS
22221 +               CLONE_NEWUTS |
22222 +#endif
22223 +#ifdef CONFIG_IPC_NS
22224 +               CLONE_NEWIPC |
22225 +#endif
22226 +#ifdef CONFIG_USER_NS
22227 +               CLONE_NEWUSER |
22228 +#endif
22229 +#ifdef CONFIG_PID_NS
22230 +               CLONE_NEWPID |
22231 +#endif
22232 +#ifdef CONFIG_NET_NS
22233 +               CLONE_NEWNET |
22234 +#endif
22235 +               0
22236 +};
22237 +
22238 +static const struct vcmd_space_mask_v1 default_space_mask = {
22239 +       .mask = CLONE_FS |
22240 +               CLONE_NEWNS |
22241 +#ifdef CONFIG_UTS_NS
22242 +               CLONE_NEWUTS |
22243 +#endif
22244 +#ifdef CONFIG_IPC_NS
22245 +               CLONE_NEWIPC |
22246 +#endif
22247 +#ifdef CONFIG_USER_NS
22248 +               CLONE_NEWUSER |
22249 +#endif
22250 +#ifdef CONFIG_PID_NS
22251 +//             CLONE_NEWPID |
22252 +#endif
22253 +               0
22254 +};
22255 +
22256 +/*
22257 + *     build a new nsproxy mix
22258 + *      assumes that both proxies are 'const'
22259 + *     does not touch nsproxy refcounts
22260 + *     will hold a reference on the result.
22261 + */
22262 +
22263 +struct nsproxy *vs_mix_nsproxy(struct nsproxy *old_nsproxy,
22264 +       struct nsproxy *new_nsproxy, unsigned long mask)
22265 +{
22266 +       struct mnt_namespace *old_ns;
22267 +       struct uts_namespace *old_uts;
22268 +       struct ipc_namespace *old_ipc;
22269 +#ifdef CONFIG_PID_NS
22270 +       struct pid_namespace *old_pid;
22271 +#endif
22272 +#ifdef CONFIG_NET_NS
22273 +       struct net *old_net;
22274 +#endif
22275 +       struct nsproxy *nsproxy;
22276 +
22277 +       nsproxy = copy_nsproxy(old_nsproxy);
22278 +       if (!nsproxy)
22279 +               goto out;
22280 +
22281 +       if (mask & CLONE_NEWNS) {
22282 +               old_ns = nsproxy->mnt_ns;
22283 +               nsproxy->mnt_ns = new_nsproxy->mnt_ns;
22284 +               if (nsproxy->mnt_ns)
22285 +                       get_mnt_ns(nsproxy->mnt_ns);
22286 +       } else
22287 +               old_ns = NULL;
22288 +
22289 +       if (mask & CLONE_NEWUTS) {
22290 +               old_uts = nsproxy->uts_ns;
22291 +               nsproxy->uts_ns = new_nsproxy->uts_ns;
22292 +               if (nsproxy->uts_ns)
22293 +                       get_uts_ns(nsproxy->uts_ns);
22294 +       } else
22295 +               old_uts = NULL;
22296 +
22297 +       if (mask & CLONE_NEWIPC) {
22298 +               old_ipc = nsproxy->ipc_ns;
22299 +               nsproxy->ipc_ns = new_nsproxy->ipc_ns;
22300 +               if (nsproxy->ipc_ns)
22301 +                       get_ipc_ns(nsproxy->ipc_ns);
22302 +       } else
22303 +               old_ipc = NULL;
22304 +
22305 +#ifdef CONFIG_PID_NS
22306 +       if (mask & CLONE_NEWPID) {
22307 +               old_pid = nsproxy->pid_ns;
22308 +               nsproxy->pid_ns = new_nsproxy->pid_ns;
22309 +               if (nsproxy->pid_ns)
22310 +                       get_pid_ns(nsproxy->pid_ns);
22311 +       } else
22312 +               old_pid = NULL;
22313 +#endif
22314 +#ifdef CONFIG_NET_NS
22315 +       if (mask & CLONE_NEWNET) {
22316 +               old_net = nsproxy->net_ns;
22317 +               nsproxy->net_ns = new_nsproxy->net_ns;
22318 +               if (nsproxy->net_ns)
22319 +                       get_net(nsproxy->net_ns);
22320 +       } else
22321 +               old_net = NULL;
22322 +#endif
22323 +       if (old_ns)
22324 +               put_mnt_ns(old_ns);
22325 +       if (old_uts)
22326 +               put_uts_ns(old_uts);
22327 +       if (old_ipc)
22328 +               put_ipc_ns(old_ipc);
22329 +#ifdef CONFIG_PID_NS
22330 +       if (old_pid)
22331 +               put_pid_ns(old_pid);
22332 +#endif
22333 +#ifdef CONFIG_NET_NS
22334 +       if (old_net)
22335 +               put_net(old_net);
22336 +#endif
22337 +out:
22338 +       return nsproxy;
22339 +}
22340 +
22341 +
22342 +/*
22343 + *     merge two nsproxy structs into a new one.
22344 + *     will hold a reference on the result.
22345 + */
22346 +
22347 +static inline
22348 +struct nsproxy *__vs_merge_nsproxy(struct nsproxy *old,
22349 +       struct nsproxy *proxy, unsigned long mask)
22350 +{
22351 +       struct nsproxy null_proxy = { .mnt_ns = NULL };
22352 +
22353 +       if (!proxy)
22354 +               return NULL;
22355 +
22356 +       if (mask) {
22357 +               /* vs_mix_nsproxy returns with reference */
22358 +               return vs_mix_nsproxy(old ? old : &null_proxy,
22359 +                       proxy, mask);
22360 +       }
22361 +       get_nsproxy(proxy);
22362 +       return proxy;
22363 +}
22364 +
22365 +
22366 +int vx_enter_space(struct vx_info *vxi, unsigned long mask, unsigned index)
22367 +{
22368 +       struct nsproxy *proxy, *proxy_cur, *proxy_new;
22369 +       struct fs_struct *fs_cur, *fs = NULL;
22370 +       struct _vx_space *space;
22371 +       int ret, kill = 0;
22372 +
22373 +       vxdprintk(VXD_CBIT(space, 8), "vx_enter_space(%p[#%u],0x%08lx,%d)",
22374 +               vxi, vxi->vx_id, mask, index);
22375 +
22376 +       if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0))
22377 +               return -EACCES;
22378 +
22379 +       if (index >= VX_SPACES)
22380 +               return -EINVAL;
22381 +
22382 +       space = &vxi->space[index];
22383 +
22384 +       if (!mask)
22385 +               mask = space->vx_nsmask;
22386 +
22387 +       if ((mask & space->vx_nsmask) != mask)
22388 +               return -EINVAL;
22389 +
22390 +       if (mask & CLONE_FS) {
22391 +               fs = copy_fs_struct(space->vx_fs);
22392 +               if (!fs)
22393 +                       return -ENOMEM;
22394 +       }
22395 +       proxy = space->vx_nsproxy;
22396 +
22397 +       vxdprintk(VXD_CBIT(space, 9),
22398 +               "vx_enter_space(%p[#%u],0x%08lx,%d) -> (%p,%p)",
22399 +               vxi, vxi->vx_id, mask, index, proxy, fs);
22400 +
22401 +       task_lock(current);
22402 +       fs_cur = current->fs;
22403 +
22404 +       if (mask & CLONE_FS) {
22405 +               spin_lock(&fs_cur->lock);
22406 +               current->fs = fs;
22407 +               kill = !--fs_cur->users;
22408 +               spin_unlock(&fs_cur->lock);
22409 +       }
22410 +
22411 +       proxy_cur = current->nsproxy;
22412 +       get_nsproxy(proxy_cur);
22413 +       task_unlock(current);
22414 +
22415 +       if (kill)
22416 +               free_fs_struct(fs_cur);
22417 +
22418 +       proxy_new = __vs_merge_nsproxy(proxy_cur, proxy, mask);
22419 +       if (IS_ERR(proxy_new)) {
22420 +               ret = PTR_ERR(proxy_new);
22421 +               goto out_put;
22422 +       }
22423 +
22424 +       proxy_new = xchg(&current->nsproxy, proxy_new);
22425 +
22426 +       if (mask & CLONE_NEWUSER) {
22427 +               struct cred *cred;
22428 +
22429 +               vxdprintk(VXD_CBIT(space, 10),
22430 +                       "vx_enter_space(%p[#%u],%p) cred (%p,%p)",
22431 +                       vxi, vxi->vx_id, space->vx_cred,
22432 +                       current->real_cred, current->cred);
22433 +
22434 +               if (space->vx_cred) {
22435 +                       cred = __prepare_creds(space->vx_cred);
22436 +                       if (cred)
22437 +                               commit_creds(cred);
22438 +               }
22439 +       }
22440 +
22441 +       ret = 0;
22442 +
22443 +       if (proxy_new)
22444 +               put_nsproxy(proxy_new);
22445 +out_put:
22446 +       if (proxy_cur)
22447 +               put_nsproxy(proxy_cur);
22448 +       return ret;
22449 +}
22450 +
22451 +
22452 +int vx_set_space(struct vx_info *vxi, unsigned long mask, unsigned index)
22453 +{
22454 +       struct nsproxy *proxy_vxi, *proxy_cur, *proxy_new;
22455 +       struct fs_struct *fs_vxi, *fs;
22456 +       struct _vx_space *space;
22457 +       int ret, kill = 0;
22458 +
22459 +       vxdprintk(VXD_CBIT(space, 8), "vx_set_space(%p[#%u],0x%08lx,%d)",
22460 +               vxi, vxi->vx_id, mask, index);
22461 +
22462 +       if ((mask & space_mask.mask) != mask)
22463 +               return -EINVAL;
22464 +
22465 +       if (index >= VX_SPACES)
22466 +               return -EINVAL;
22467 +
22468 +       space = &vxi->space[index];
22469 +
22470 +       proxy_vxi = space->vx_nsproxy;
22471 +       fs_vxi = space->vx_fs;
22472 +
22473 +       if (mask & CLONE_FS) {
22474 +               fs = copy_fs_struct(current->fs);
22475 +               if (!fs)
22476 +                       return -ENOMEM;
22477 +       }
22478 +
22479 +       task_lock(current);
22480 +
22481 +       if (mask & CLONE_FS) {
22482 +               spin_lock(&fs_vxi->lock);
22483 +               space->vx_fs = fs;
22484 +               kill = !--fs_vxi->users;
22485 +               spin_unlock(&fs_vxi->lock);
22486 +       }
22487 +
22488 +       proxy_cur = current->nsproxy;
22489 +       get_nsproxy(proxy_cur);
22490 +       task_unlock(current);
22491 +
22492 +       if (kill)
22493 +               free_fs_struct(fs_vxi);
22494 +
22495 +       proxy_new = __vs_merge_nsproxy(proxy_vxi, proxy_cur, mask);
22496 +       if (IS_ERR(proxy_new)) {
22497 +               ret = PTR_ERR(proxy_new);
22498 +               goto out_put;
22499 +       }
22500 +
22501 +       proxy_new = xchg(&space->vx_nsproxy, proxy_new);
22502 +       space->vx_nsmask |= mask;
22503 +
22504 +       if (mask & CLONE_NEWUSER) {
22505 +               struct cred *cred;
22506 +
22507 +               vxdprintk(VXD_CBIT(space, 10),
22508 +                       "vx_set_space(%p[#%u],%p) cred (%p,%p)",
22509 +                       vxi, vxi->vx_id, space->vx_cred,
22510 +                       current->real_cred, current->cred);
22511 +
22512 +               cred = prepare_creds();
22513 +               cred = (struct cred *)xchg(&space->vx_cred, cred);
22514 +               if (cred)
22515 +                       abort_creds(cred);
22516 +       }
22517 +
22518 +       ret = 0;
22519 +
22520 +       if (proxy_new)
22521 +               put_nsproxy(proxy_new);
22522 +out_put:
22523 +       if (proxy_cur)
22524 +               put_nsproxy(proxy_cur);
22525 +       return ret;
22526 +}
22527 +
22528 +
22529 +int vc_enter_space_v1(struct vx_info *vxi, void __user *data)
22530 +{
22531 +       struct vcmd_space_mask_v1 vc_data = { .mask = 0 };
22532 +
22533 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22534 +               return -EFAULT;
22535 +
22536 +       return vx_enter_space(vxi, vc_data.mask, 0);
22537 +}
22538 +
22539 +int vc_enter_space(struct vx_info *vxi, void __user *data)
22540 +{
22541 +       struct vcmd_space_mask_v2 vc_data = { .mask = 0 };
22542 +
22543 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22544 +               return -EFAULT;
22545 +
22546 +       if (vc_data.index >= VX_SPACES)
22547 +               return -EINVAL;
22548 +
22549 +       return vx_enter_space(vxi, vc_data.mask, vc_data.index);
22550 +}
22551 +
22552 +int vc_set_space_v1(struct vx_info *vxi, void __user *data)
22553 +{
22554 +       struct vcmd_space_mask_v1 vc_data = { .mask = 0 };
22555 +
22556 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22557 +               return -EFAULT;
22558 +
22559 +       return vx_set_space(vxi, vc_data.mask, 0);
22560 +}
22561 +
22562 +int vc_set_space(struct vx_info *vxi, void __user *data)
22563 +{
22564 +       struct vcmd_space_mask_v2 vc_data = { .mask = 0 };
22565 +
22566 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22567 +               return -EFAULT;
22568 +
22569 +       if (vc_data.index >= VX_SPACES)
22570 +               return -EINVAL;
22571 +
22572 +       return vx_set_space(vxi, vc_data.mask, vc_data.index);
22573 +}
22574 +
22575 +int vc_get_space_mask(void __user *data, int type)
22576 +{
22577 +       const struct vcmd_space_mask_v1 *mask;
22578 +
22579 +       if (type == 0)
22580 +               mask = &space_mask_v0;
22581 +       else if (type == 1)
22582 +               mask = &space_mask;
22583 +       else
22584 +               mask = &default_space_mask;
22585 +
22586 +       vxdprintk(VXD_CBIT(space, 10),
22587 +               "vc_get_space_mask(%d) = %08llx", type, mask->mask);
22588 +
22589 +       if (copy_to_user(data, mask, sizeof(*mask)))
22590 +               return -EFAULT;
22591 +       return 0;
22592 +}
22593 +
22594 diff -NurpP --minimal linux-3.6/kernel/vserver/switch.c linux-3.6-vs2.3.4.3-noxfs-nocow/kernel/vserver/switch.c
22595 --- linux-3.6/kernel/vserver/switch.c   1970-01-01 01:00:00.000000000 +0100
22596 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/kernel/vserver/switch.c     2012-10-04 18:47:00.000000000 +0200
22597 @@ -0,0 +1,556 @@
22598 +/*
22599 + *  linux/kernel/vserver/switch.c
22600 + *
22601 + *  Virtual Server: Syscall Switch
22602 + *
22603 + *  Copyright (C) 2003-2011  Herbert Pötzl
22604 + *
22605 + *  V0.01  syscall switch
22606 + *  V0.02  added signal to context
22607 + *  V0.03  added rlimit functions
22608 + *  V0.04  added iattr, task/xid functions
22609 + *  V0.05  added debug/history stuff
22610 + *  V0.06  added compat32 layer
22611 + *  V0.07  vcmd args and perms
22612 + *  V0.08  added status commands
22613 + *  V0.09  added tag commands
22614 + *  V0.10  added oom bias
22615 + *  V0.11  added device commands
22616 + *  V0.12  added warn mask
22617 + *
22618 + */
22619 +
22620 +#include <linux/vs_context.h>
22621 +#include <linux/vs_network.h>
22622 +#include <linux/vserver/switch.h>
22623 +
22624 +#include "vci_config.h"
22625 +
22626 +
22627 +static inline
22628 +int vc_get_version(uint32_t id)
22629 +{
22630 +       return VCI_VERSION;
22631 +}
22632 +
22633 +static inline
22634 +int vc_get_vci(uint32_t id)
22635 +{
22636 +       return vci_kernel_config();
22637 +}
22638 +
22639 +#include <linux/vserver/context_cmd.h>
22640 +#include <linux/vserver/cvirt_cmd.h>
22641 +#include <linux/vserver/cacct_cmd.h>
22642 +#include <linux/vserver/limit_cmd.h>
22643 +#include <linux/vserver/network_cmd.h>
22644 +#include <linux/vserver/sched_cmd.h>
22645 +#include <linux/vserver/debug_cmd.h>
22646 +#include <linux/vserver/inode_cmd.h>
22647 +#include <linux/vserver/dlimit_cmd.h>
22648 +#include <linux/vserver/signal_cmd.h>
22649 +#include <linux/vserver/space_cmd.h>
22650 +#include <linux/vserver/tag_cmd.h>
22651 +#include <linux/vserver/device_cmd.h>
22652 +
22653 +#include <linux/vserver/inode.h>
22654 +#include <linux/vserver/dlimit.h>
22655 +
22656 +
22657 +#ifdef CONFIG_COMPAT
22658 +#define __COMPAT(name, id, data, compat)       \
22659 +       (compat) ? name ## _x32(id, data) : name(id, data)
22660 +#define __COMPAT_NO_ID(name, data, compat)     \
22661 +       (compat) ? name ## _x32(data) : name(data)
22662 +#else
22663 +#define __COMPAT(name, id, data, compat)       \
22664 +       name(id, data)
22665 +#define __COMPAT_NO_ID(name, data, compat)     \
22666 +       name(data)
22667 +#endif
22668 +
22669 +
22670 +static inline
22671 +long do_vcmd(uint32_t cmd, uint32_t id,
22672 +       struct vx_info *vxi, struct nx_info *nxi,
22673 +       void __user *data, int compat)
22674 +{
22675 +       switch (cmd) {
22676 +
22677 +       case VCMD_get_version:
22678 +               return vc_get_version(id);
22679 +       case VCMD_get_vci:
22680 +               return vc_get_vci(id);
22681 +
22682 +       case VCMD_task_xid:
22683 +               return vc_task_xid(id);
22684 +       case VCMD_vx_info:
22685 +               return vc_vx_info(vxi, data);
22686 +
22687 +       case VCMD_task_nid:
22688 +               return vc_task_nid(id);
22689 +       case VCMD_nx_info:
22690 +               return vc_nx_info(nxi, data);
22691 +
22692 +       case VCMD_task_tag:
22693 +               return vc_task_tag(id);
22694 +
22695 +       case VCMD_set_space_v1:
22696 +               return vc_set_space_v1(vxi, data);
22697 +       /* this is version 2 */
22698 +       case VCMD_set_space:
22699 +               return vc_set_space(vxi, data);
22700 +
22701 +       case VCMD_get_space_mask_v0:
22702 +               return vc_get_space_mask(data, 0);
22703 +       /* this is version 1 */
22704 +       case VCMD_get_space_mask:
22705 +               return vc_get_space_mask(data, 1);
22706 +
22707 +       case VCMD_get_space_default:
22708 +               return vc_get_space_mask(data, -1);
22709 +
22710 +       case VCMD_set_umask:
22711 +               return vc_set_umask(vxi, data);
22712 +
22713 +       case VCMD_get_umask:
22714 +               return vc_get_umask(vxi, data);
22715 +
22716 +       case VCMD_set_wmask:
22717 +               return vc_set_wmask(vxi, data);
22718 +
22719 +       case VCMD_get_wmask:
22720 +               return vc_get_wmask(vxi, data);
22721 +#ifdef CONFIG_IA32_EMULATION
22722 +       case VCMD_get_rlimit:
22723 +               return __COMPAT(vc_get_rlimit, vxi, data, compat);
22724 +       case VCMD_set_rlimit:
22725 +               return __COMPAT(vc_set_rlimit, vxi, data, compat);
22726 +#else
22727 +       case VCMD_get_rlimit:
22728 +               return vc_get_rlimit(vxi, data);
22729 +       case VCMD_set_rlimit:
22730 +               return vc_set_rlimit(vxi, data);
22731 +#endif
22732 +       case VCMD_get_rlimit_mask:
22733 +               return vc_get_rlimit_mask(id, data);
22734 +       case VCMD_reset_hits:
22735 +               return vc_reset_hits(vxi, data);
22736 +       case VCMD_reset_minmax:
22737 +               return vc_reset_minmax(vxi, data);
22738 +
22739 +       case VCMD_get_vhi_name:
22740 +               return vc_get_vhi_name(vxi, data);
22741 +       case VCMD_set_vhi_name:
22742 +               return vc_set_vhi_name(vxi, data);
22743 +
22744 +       case VCMD_ctx_stat:
22745 +               return vc_ctx_stat(vxi, data);
22746 +       case VCMD_virt_stat:
22747 +               return vc_virt_stat(vxi, data);
22748 +       case VCMD_sock_stat:
22749 +               return vc_sock_stat(vxi, data);
22750 +       case VCMD_rlimit_stat:
22751 +               return vc_rlimit_stat(vxi, data);
22752 +
22753 +       case VCMD_set_cflags:
22754 +               return vc_set_cflags(vxi, data);
22755 +       case VCMD_get_cflags:
22756 +               return vc_get_cflags(vxi, data);
22757 +
22758 +       /* this is version 1 */
22759 +       case VCMD_set_ccaps:
22760 +               return vc_set_ccaps(vxi, data);
22761 +       /* this is version 1 */
22762 +       case VCMD_get_ccaps:
22763 +               return vc_get_ccaps(vxi, data);
22764 +       case VCMD_set_bcaps:
22765 +               return vc_set_bcaps(vxi, data);
22766 +       case VCMD_get_bcaps:
22767 +               return vc_get_bcaps(vxi, data);
22768 +
22769 +       case VCMD_set_badness:
22770 +               return vc_set_badness(vxi, data);
22771 +       case VCMD_get_badness:
22772 +               return vc_get_badness(vxi, data);
22773 +
22774 +       case VCMD_set_nflags:
22775 +               return vc_set_nflags(nxi, data);
22776 +       case VCMD_get_nflags:
22777 +               return vc_get_nflags(nxi, data);
22778 +
22779 +       case VCMD_set_ncaps:
22780 +               return vc_set_ncaps(nxi, data);
22781 +       case VCMD_get_ncaps:
22782 +               return vc_get_ncaps(nxi, data);
22783 +
22784 +       case VCMD_set_prio_bias:
22785 +               return vc_set_prio_bias(vxi, data);
22786 +       case VCMD_get_prio_bias:
22787 +               return vc_get_prio_bias(vxi, data);
22788 +       case VCMD_add_dlimit:
22789 +               return __COMPAT(vc_add_dlimit, id, data, compat);
22790 +       case VCMD_rem_dlimit:
22791 +               return __COMPAT(vc_rem_dlimit, id, data, compat);
22792 +       case VCMD_set_dlimit:
22793 +               return __COMPAT(vc_set_dlimit, id, data, compat);
22794 +       case VCMD_get_dlimit:
22795 +               return __COMPAT(vc_get_dlimit, id, data, compat);
22796 +
22797 +       case VCMD_ctx_kill:
22798 +               return vc_ctx_kill(vxi, data);
22799 +
22800 +       case VCMD_wait_exit:
22801 +               return vc_wait_exit(vxi, data);
22802 +
22803 +       case VCMD_get_iattr:
22804 +               return __COMPAT_NO_ID(vc_get_iattr, data, compat);
22805 +       case VCMD_set_iattr:
22806 +               return __COMPAT_NO_ID(vc_set_iattr, data, compat);
22807 +
22808 +       case VCMD_fget_iattr:
22809 +               return vc_fget_iattr(id, data);
22810 +       case VCMD_fset_iattr:
22811 +               return vc_fset_iattr(id, data);
22812 +
22813 +       case VCMD_enter_space_v0:
22814 +               return vc_enter_space_v1(vxi, NULL);
22815 +       case VCMD_enter_space_v1:
22816 +               return vc_enter_space_v1(vxi, data);
22817 +       /* this is version 2 */
22818 +       case VCMD_enter_space:
22819 +               return vc_enter_space(vxi, data);
22820 +
22821 +       case VCMD_ctx_create_v0:
22822 +               return vc_ctx_create(id, NULL);
22823 +       case VCMD_ctx_create:
22824 +               return vc_ctx_create(id, data);
22825 +       case VCMD_ctx_migrate_v0:
22826 +               return vc_ctx_migrate(vxi, NULL);
22827 +       case VCMD_ctx_migrate:
22828 +               return vc_ctx_migrate(vxi, data);
22829 +
22830 +       case VCMD_net_create_v0:
22831 +               return vc_net_create(id, NULL);
22832 +       case VCMD_net_create:
22833 +               return vc_net_create(id, data);
22834 +       case VCMD_net_migrate:
22835 +               return vc_net_migrate(nxi, data);
22836 +
22837 +       case VCMD_tag_migrate:
22838 +               return vc_tag_migrate(id);
22839 +
22840 +       case VCMD_net_add:
22841 +               return vc_net_add(nxi, data);
22842 +       case VCMD_net_remove:
22843 +               return vc_net_remove(nxi, data);
22844 +
22845 +       case VCMD_net_add_ipv4_v1:
22846 +               return vc_net_add_ipv4_v1(nxi, data);
22847 +       /* this is version 2 */
22848 +       case VCMD_net_add_ipv4:
22849 +               return vc_net_add_ipv4(nxi, data);
22850 +
22851 +       case VCMD_net_rem_ipv4_v1:
22852 +               return vc_net_rem_ipv4_v1(nxi, data);
22853 +       /* this is version 2 */
22854 +       case VCMD_net_rem_ipv4:
22855 +               return vc_net_rem_ipv4(nxi, data);
22856 +#ifdef CONFIG_IPV6
22857 +       case VCMD_net_add_ipv6:
22858 +               return vc_net_add_ipv6(nxi, data);
22859 +       case VCMD_net_remove_ipv6:
22860 +               return vc_net_remove_ipv6(nxi, data);
22861 +#endif
22862 +/*     case VCMD_add_match_ipv4:
22863 +               return vc_add_match_ipv4(nxi, data);
22864 +       case VCMD_get_match_ipv4:
22865 +               return vc_get_match_ipv4(nxi, data);
22866 +#ifdef CONFIG_IPV6
22867 +       case VCMD_add_match_ipv6:
22868 +               return vc_add_match_ipv6(nxi, data);
22869 +       case VCMD_get_match_ipv6:
22870 +               return vc_get_match_ipv6(nxi, data);
22871 +#endif */
22872 +
22873 +#ifdef CONFIG_VSERVER_DEVICE
22874 +       case VCMD_set_mapping:
22875 +               return __COMPAT(vc_set_mapping, vxi, data, compat);
22876 +       case VCMD_unset_mapping:
22877 +               return __COMPAT(vc_unset_mapping, vxi, data, compat);
22878 +#endif
22879 +#ifdef CONFIG_VSERVER_HISTORY
22880 +       case VCMD_dump_history:
22881 +               return vc_dump_history(id);
22882 +       case VCMD_read_history:
22883 +               return __COMPAT(vc_read_history, id, data, compat);
22884 +#endif
22885 +       default:
22886 +               vxwprintk_task(1, "unimplemented VCMD_%02d_%d[%d]",
22887 +                       VC_CATEGORY(cmd), VC_COMMAND(cmd), VC_VERSION(cmd));
22888 +       }
22889 +       return -ENOSYS;
22890 +}
22891 +
22892 +
22893 +#define        __VCMD(vcmd, _perm, _args, _flags)              \
22894 +       case VCMD_ ## vcmd: perm = _perm;               \
22895 +               args = _args; flags = _flags; break
22896 +
22897 +
22898 +#define VCA_NONE       0x00
22899 +#define VCA_VXI                0x01
22900 +#define VCA_NXI                0x02
22901 +
22902 +#define VCF_NONE       0x00
22903 +#define VCF_INFO       0x01
22904 +#define VCF_ADMIN      0x02
22905 +#define VCF_ARES       0x06    /* includes admin */
22906 +#define VCF_SETUP      0x08
22907 +
22908 +#define VCF_ZIDOK      0x10    /* zero id okay */
22909 +
22910 +
22911 +static inline
22912 +long do_vserver(uint32_t cmd, uint32_t id, void __user *data, int compat)
22913 +{
22914 +       long ret;
22915 +       int permit = -1, state = 0;
22916 +       int perm = -1, args = 0, flags = 0;
22917 +       struct vx_info *vxi = NULL;
22918 +       struct nx_info *nxi = NULL;
22919 +
22920 +       switch (cmd) {
22921 +       /* unpriviledged commands */
22922 +       __VCMD(get_version,      0, VCA_NONE,   0);
22923 +       __VCMD(get_vci,          0, VCA_NONE,   0);
22924 +       __VCMD(get_rlimit_mask,  0, VCA_NONE,   0);
22925 +       __VCMD(get_space_mask_v0,0, VCA_NONE,   0);
22926 +       __VCMD(get_space_mask,   0, VCA_NONE,   0);
22927 +       __VCMD(get_space_default,0, VCA_NONE,   0);
22928 +
22929 +       /* info commands */
22930 +       __VCMD(task_xid,         2, VCA_NONE,   0);
22931 +       __VCMD(reset_hits,       2, VCA_VXI,    0);
22932 +       __VCMD(reset_minmax,     2, VCA_VXI,    0);
22933 +       __VCMD(vx_info,          3, VCA_VXI,    VCF_INFO);
22934 +       __VCMD(get_bcaps,        3, VCA_VXI,    VCF_INFO);
22935 +       __VCMD(get_ccaps,        3, VCA_VXI,    VCF_INFO);
22936 +       __VCMD(get_cflags,       3, VCA_VXI,    VCF_INFO);
22937 +       __VCMD(get_umask,        3, VCA_VXI,    VCF_INFO);
22938 +       __VCMD(get_wmask,        3, VCA_VXI,    VCF_INFO);
22939 +       __VCMD(get_badness,      3, VCA_VXI,    VCF_INFO);
22940 +       __VCMD(get_vhi_name,     3, VCA_VXI,    VCF_INFO);
22941 +       __VCMD(get_rlimit,       3, VCA_VXI,    VCF_INFO);
22942 +
22943 +       __VCMD(ctx_stat,         3, VCA_VXI,    VCF_INFO);
22944 +       __VCMD(virt_stat,        3, VCA_VXI,    VCF_INFO);
22945 +       __VCMD(sock_stat,        3, VCA_VXI,    VCF_INFO);
22946 +       __VCMD(rlimit_stat,      3, VCA_VXI,    VCF_INFO);
22947 +
22948 +       __VCMD(task_nid,         2, VCA_NONE,   0);
22949 +       __VCMD(nx_info,          3, VCA_NXI,    VCF_INFO);
22950 +       __VCMD(get_ncaps,        3, VCA_NXI,    VCF_INFO);
22951 +       __VCMD(get_nflags,       3, VCA_NXI,    VCF_INFO);
22952 +
22953 +       __VCMD(task_tag,         2, VCA_NONE,   0);
22954 +
22955 +       __VCMD(get_iattr,        2, VCA_NONE,   0);
22956 +       __VCMD(fget_iattr,       2, VCA_NONE,   0);
22957 +       __VCMD(get_dlimit,       3, VCA_NONE,   VCF_INFO);
22958 +       __VCMD(get_prio_bias,    3, VCA_VXI,    VCF_INFO);
22959 +
22960 +       /* lower admin commands */
22961 +       __VCMD(wait_exit,        4, VCA_VXI,    VCF_INFO);
22962 +       __VCMD(ctx_create_v0,    5, VCA_NONE,   0);
22963 +       __VCMD(ctx_create,       5, VCA_NONE,   0);
22964 +       __VCMD(ctx_migrate_v0,   5, VCA_VXI,    VCF_ADMIN);
22965 +       __VCMD(ctx_migrate,      5, VCA_VXI,    VCF_ADMIN);
22966 +       __VCMD(enter_space_v0,   5, VCA_VXI,    VCF_ADMIN);
22967 +       __VCMD(enter_space_v1,   5, VCA_VXI,    VCF_ADMIN);
22968 +       __VCMD(enter_space,      5, VCA_VXI,    VCF_ADMIN);
22969 +
22970 +       __VCMD(net_create_v0,    5, VCA_NONE,   0);
22971 +       __VCMD(net_create,       5, VCA_NONE,   0);
22972 +       __VCMD(net_migrate,      5, VCA_NXI,    VCF_ADMIN);
22973 +
22974 +       __VCMD(tag_migrate,      5, VCA_NONE,   VCF_ADMIN);
22975 +
22976 +       /* higher admin commands */
22977 +       __VCMD(ctx_kill,         6, VCA_VXI,    VCF_ARES);
22978 +       __VCMD(set_space_v1,     7, VCA_VXI,    VCF_ARES | VCF_SETUP);
22979 +       __VCMD(set_space,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
22980 +
22981 +       __VCMD(set_ccaps,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
22982 +       __VCMD(set_bcaps,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
22983 +       __VCMD(set_cflags,       7, VCA_VXI,    VCF_ARES | VCF_SETUP);
22984 +       __VCMD(set_umask,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
22985 +       __VCMD(set_wmask,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
22986 +       __VCMD(set_badness,      7, VCA_VXI,    VCF_ARES | VCF_SETUP);
22987 +
22988 +       __VCMD(set_vhi_name,     7, VCA_VXI,    VCF_ARES | VCF_SETUP);
22989 +       __VCMD(set_rlimit,       7, VCA_VXI,    VCF_ARES | VCF_SETUP);
22990 +       __VCMD(set_prio_bias,    7, VCA_VXI,    VCF_ARES | VCF_SETUP);
22991 +
22992 +       __VCMD(set_ncaps,        7, VCA_NXI,    VCF_ARES | VCF_SETUP);
22993 +       __VCMD(set_nflags,       7, VCA_NXI,    VCF_ARES | VCF_SETUP);
22994 +       __VCMD(net_add,          8, VCA_NXI,    VCF_ARES | VCF_SETUP);
22995 +       __VCMD(net_remove,       8, VCA_NXI,    VCF_ARES | VCF_SETUP);
22996 +       __VCMD(net_add_ipv4_v1,  8, VCA_NXI,    VCF_ARES | VCF_SETUP);
22997 +       __VCMD(net_rem_ipv4_v1,  8, VCA_NXI,    VCF_ARES | VCF_SETUP);
22998 +       __VCMD(net_add_ipv4,     8, VCA_NXI,    VCF_ARES | VCF_SETUP);
22999 +       __VCMD(net_rem_ipv4,     8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23000 +#ifdef CONFIG_IPV6
23001 +       __VCMD(net_add_ipv6,     8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23002 +       __VCMD(net_remove_ipv6,  8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23003 +#endif
23004 +       __VCMD(set_iattr,        7, VCA_NONE,   0);
23005 +       __VCMD(fset_iattr,       7, VCA_NONE,   0);
23006 +       __VCMD(set_dlimit,       7, VCA_NONE,   VCF_ARES);
23007 +       __VCMD(add_dlimit,       8, VCA_NONE,   VCF_ARES);
23008 +       __VCMD(rem_dlimit,       8, VCA_NONE,   VCF_ARES);
23009 +
23010 +#ifdef CONFIG_VSERVER_DEVICE
23011 +       __VCMD(set_mapping,      8, VCA_VXI,    VCF_ARES|VCF_ZIDOK);
23012 +       __VCMD(unset_mapping,    8, VCA_VXI,    VCF_ARES|VCF_ZIDOK);
23013 +#endif
23014 +       /* debug level admin commands */
23015 +#ifdef CONFIG_VSERVER_HISTORY
23016 +       __VCMD(dump_history,     9, VCA_NONE,   0);
23017 +       __VCMD(read_history,     9, VCA_NONE,   0);
23018 +#endif
23019 +
23020 +       default:
23021 +               perm = -1;
23022 +       }
23023 +
23024 +       vxdprintk(VXD_CBIT(switch, 0),
23025 +               "vc: VCMD_%02d_%d[%d], %d,%p [%d,%d,%x,%x]",
23026 +               VC_CATEGORY(cmd), VC_COMMAND(cmd),
23027 +               VC_VERSION(cmd), id, data, compat,
23028 +               perm, args, flags);
23029 +
23030 +       ret = -ENOSYS;
23031 +       if (perm < 0)
23032 +               goto out;
23033 +
23034 +       state = 1;
23035 +       if (!capable(CAP_CONTEXT))
23036 +               goto out;
23037 +
23038 +       state = 2;
23039 +       /* moved here from the individual commands */
23040 +       ret = -EPERM;
23041 +       if ((perm > 1) && !capable(CAP_SYS_ADMIN))
23042 +               goto out;
23043 +
23044 +       state = 3;
23045 +       /* vcmd involves resource management  */
23046 +       ret = -EPERM;
23047 +       if ((flags & VCF_ARES) && !capable(CAP_SYS_RESOURCE))
23048 +               goto out;
23049 +
23050 +       state = 4;
23051 +       /* various legacy exceptions */
23052 +       switch (cmd) {
23053 +       /* will go away when spectator is a cap */
23054 +       case VCMD_ctx_migrate_v0:
23055 +       case VCMD_ctx_migrate:
23056 +               if (id == 1) {
23057 +                       current->xid = 1;
23058 +                       ret = 1;
23059 +                       goto out;
23060 +               }
23061 +               break;
23062 +
23063 +       /* will go away when spectator is a cap */
23064 +       case VCMD_net_migrate:
23065 +               if (id == 1) {
23066 +                       current->nid = 1;
23067 +                       ret = 1;
23068 +                       goto out;
23069 +               }
23070 +               break;
23071 +       }
23072 +
23073 +       /* vcmds are fine by default */
23074 +       permit = 1;
23075 +
23076 +       /* admin type vcmds require admin ... */
23077 +       if (flags & VCF_ADMIN)
23078 +               permit = vx_check(0, VS_ADMIN) ? 1 : 0;
23079 +
23080 +       /* ... but setup type vcmds override that */
23081 +       if (!permit && (flags & VCF_SETUP))
23082 +               permit = vx_flags(VXF_STATE_SETUP, 0) ? 2 : 0;
23083 +
23084 +       state = 5;
23085 +       ret = -EPERM;
23086 +       if (!permit)
23087 +               goto out;
23088 +
23089 +       state = 6;
23090 +       if (!id && (flags & VCF_ZIDOK))
23091 +               goto skip_id;
23092 +
23093 +       ret = -ESRCH;
23094 +       if (args & VCA_VXI) {
23095 +               vxi = lookup_vx_info(id);
23096 +               if (!vxi)
23097 +                       goto out;
23098 +
23099 +               if ((flags & VCF_ADMIN) &&
23100 +                       /* special case kill for shutdown */
23101 +                       (cmd != VCMD_ctx_kill) &&
23102 +                       /* can context be administrated? */
23103 +                       !vx_info_flags(vxi, VXF_STATE_ADMIN, 0)) {
23104 +                       ret = -EACCES;
23105 +                       goto out_vxi;
23106 +               }
23107 +       }
23108 +       state = 7;
23109 +       if (args & VCA_NXI) {
23110 +               nxi = lookup_nx_info(id);
23111 +               if (!nxi)
23112 +                       goto out_vxi;
23113 +
23114 +               if ((flags & VCF_ADMIN) &&
23115 +                       /* can context be administrated? */
23116 +                       !nx_info_flags(nxi, NXF_STATE_ADMIN, 0)) {
23117 +                       ret = -EACCES;
23118 +                       goto out_nxi;
23119 +               }
23120 +       }
23121 +skip_id:
23122 +       state = 8;
23123 +       ret = do_vcmd(cmd, id, vxi, nxi, data, compat);
23124 +
23125 +out_nxi:
23126 +       if ((args & VCA_NXI) && nxi)
23127 +               put_nx_info(nxi);
23128 +out_vxi:
23129 +       if ((args & VCA_VXI) && vxi)
23130 +               put_vx_info(vxi);
23131 +out:
23132 +       vxdprintk(VXD_CBIT(switch, 1),
23133 +               "vc: VCMD_%02d_%d[%d] = %08lx(%ld) [%d,%d]",
23134 +               VC_CATEGORY(cmd), VC_COMMAND(cmd),
23135 +               VC_VERSION(cmd), ret, ret, state, permit);
23136 +       return ret;
23137 +}
23138 +
23139 +asmlinkage long
23140 +sys_vserver(uint32_t cmd, uint32_t id, void __user *data)
23141 +{
23142 +       return do_vserver(cmd, id, data, 0);
23143 +}
23144 +
23145 +#ifdef CONFIG_COMPAT
23146 +
23147 +asmlinkage long
23148 +sys32_vserver(uint32_t cmd, uint32_t id, void __user *data)
23149 +{
23150 +       return do_vserver(cmd, id, data, 1);
23151 +}
23152 +
23153 +#endif /* CONFIG_COMPAT */
23154 diff -NurpP --minimal linux-3.6/kernel/vserver/sysctl.c linux-3.6-vs2.3.4.3-noxfs-nocow/kernel/vserver/sysctl.c
23155 --- linux-3.6/kernel/vserver/sysctl.c   1970-01-01 01:00:00.000000000 +0100
23156 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/kernel/vserver/sysctl.c     2012-10-04 18:47:00.000000000 +0200
23157 @@ -0,0 +1,247 @@
23158 +/*
23159 + *  kernel/vserver/sysctl.c
23160 + *
23161 + *  Virtual Context Support
23162 + *
23163 + *  Copyright (C) 2004-2007  Herbert Pötzl
23164 + *
23165 + *  V0.01  basic structure
23166 + *
23167 + */
23168 +
23169 +#include <linux/module.h>
23170 +#include <linux/ctype.h>
23171 +#include <linux/sysctl.h>
23172 +#include <linux/parser.h>
23173 +#include <asm/uaccess.h>
23174 +
23175 +enum {
23176 +       CTL_DEBUG_ERROR         = 0,
23177 +       CTL_DEBUG_SWITCH        = 1,
23178 +       CTL_DEBUG_XID,
23179 +       CTL_DEBUG_NID,
23180 +       CTL_DEBUG_TAG,
23181 +       CTL_DEBUG_NET,
23182 +       CTL_DEBUG_LIMIT,
23183 +       CTL_DEBUG_CRES,
23184 +       CTL_DEBUG_DLIM,
23185 +       CTL_DEBUG_QUOTA,
23186 +       CTL_DEBUG_CVIRT,
23187 +       CTL_DEBUG_SPACE,
23188 +       CTL_DEBUG_PERM,
23189 +       CTL_DEBUG_MISC,
23190 +};
23191 +
23192 +
23193 +unsigned int vs_debug_switch   = 0;
23194 +unsigned int vs_debug_xid      = 0;
23195 +unsigned int vs_debug_nid      = 0;
23196 +unsigned int vs_debug_tag      = 0;
23197 +unsigned int vs_debug_net      = 0;
23198 +unsigned int vs_debug_limit    = 0;
23199 +unsigned int vs_debug_cres     = 0;
23200 +unsigned int vs_debug_dlim     = 0;
23201 +unsigned int vs_debug_quota    = 0;
23202 +unsigned int vs_debug_cvirt    = 0;
23203 +unsigned int vs_debug_space    = 0;
23204 +unsigned int vs_debug_perm     = 0;
23205 +unsigned int vs_debug_misc     = 0;
23206 +
23207 +
23208 +static struct ctl_table_header *vserver_table_header;
23209 +static ctl_table vserver_root_table[];
23210 +
23211 +
23212 +void vserver_register_sysctl(void)
23213 +{
23214 +       if (!vserver_table_header) {
23215 +               vserver_table_header = register_sysctl_table(vserver_root_table);
23216 +       }
23217 +
23218 +}
23219 +
23220 +void vserver_unregister_sysctl(void)
23221 +{
23222 +       if (vserver_table_header) {
23223 +               unregister_sysctl_table(vserver_table_header);
23224 +               vserver_table_header = NULL;
23225 +       }
23226 +}
23227 +
23228 +
23229 +static int proc_dodebug(ctl_table *table, int write,
23230 +       void __user *buffer, size_t *lenp, loff_t *ppos)
23231 +{
23232 +       char            tmpbuf[20], *p, c;
23233 +       unsigned int    value;
23234 +       size_t          left, len;
23235 +
23236 +       if ((*ppos && !write) || !*lenp) {
23237 +               *lenp = 0;
23238 +               return 0;
23239 +       }
23240 +
23241 +       left = *lenp;
23242 +
23243 +       if (write) {
23244 +               if (!access_ok(VERIFY_READ, buffer, left))
23245 +                       return -EFAULT;
23246 +               p = (char *)buffer;
23247 +               while (left && __get_user(c, p) >= 0 && isspace(c))
23248 +                       left--, p++;
23249 +               if (!left)
23250 +                       goto done;
23251 +
23252 +               if (left > sizeof(tmpbuf) - 1)
23253 +                       return -EINVAL;
23254 +               if (copy_from_user(tmpbuf, p, left))
23255 +                       return -EFAULT;
23256 +               tmpbuf[left] = '\0';
23257 +
23258 +               for (p = tmpbuf, value = 0; '0' <= *p && *p <= '9'; p++, left--)
23259 +                       value = 10 * value + (*p - '0');
23260 +               if (*p && !isspace(*p))
23261 +                       return -EINVAL;
23262 +               while (left && isspace(*p))
23263 +                       left--, p++;
23264 +               *(unsigned int *)table->data = value;
23265 +       } else {
23266 +               if (!access_ok(VERIFY_WRITE, buffer, left))
23267 +                       return -EFAULT;
23268 +               len = sprintf(tmpbuf, "%d", *(unsigned int *)table->data);
23269 +               if (len > left)
23270 +                       len = left;
23271 +               if (__copy_to_user(buffer, tmpbuf, len))
23272 +                       return -EFAULT;
23273 +               if ((left -= len) > 0) {
23274 +                       if (put_user('\n', (char *)buffer + len))
23275 +                               return -EFAULT;
23276 +                       left--;
23277 +               }
23278 +       }
23279 +
23280 +done:
23281 +       *lenp -= left;
23282 +       *ppos += *lenp;
23283 +       return 0;
23284 +}
23285 +
23286 +static int zero;
23287 +
23288 +#define        CTL_ENTRY(ctl, name)                            \
23289 +       {                                               \
23290 +               .procname       = #name,                \
23291 +               .data           = &vs_ ## name,         \
23292 +               .maxlen         = sizeof(int),          \
23293 +               .mode           = 0644,                 \
23294 +               .proc_handler   = &proc_dodebug,        \
23295 +               .extra1         = &zero,                \
23296 +               .extra2         = &zero,                \
23297 +       }
23298 +
23299 +static ctl_table vserver_debug_table[] = {
23300 +       CTL_ENTRY(CTL_DEBUG_SWITCH,     debug_switch),
23301 +       CTL_ENTRY(CTL_DEBUG_XID,        debug_xid),
23302 +       CTL_ENTRY(CTL_DEBUG_NID,        debug_nid),
23303 +       CTL_ENTRY(CTL_DEBUG_TAG,        debug_tag),
23304 +       CTL_ENTRY(CTL_DEBUG_NET,        debug_net),
23305 +       CTL_ENTRY(CTL_DEBUG_LIMIT,      debug_limit),
23306 +       CTL_ENTRY(CTL_DEBUG_CRES,       debug_cres),
23307 +       CTL_ENTRY(CTL_DEBUG_DLIM,       debug_dlim),
23308 +       CTL_ENTRY(CTL_DEBUG_QUOTA,      debug_quota),
23309 +       CTL_ENTRY(CTL_DEBUG_CVIRT,      debug_cvirt),
23310 +       CTL_ENTRY(CTL_DEBUG_SPACE,      debug_space),
23311 +       CTL_ENTRY(CTL_DEBUG_PERM,       debug_perm),
23312 +       CTL_ENTRY(CTL_DEBUG_MISC,       debug_misc),
23313 +       { 0 }
23314 +};
23315 +
23316 +static ctl_table vserver_root_table[] = {
23317 +       {
23318 +               .procname       = "vserver",
23319 +               .mode           = 0555,
23320 +               .child          = vserver_debug_table
23321 +       },
23322 +       { 0 }
23323 +};
23324 +
23325 +
23326 +static match_table_t tokens = {
23327 +       { CTL_DEBUG_SWITCH,     "switch=%x"     },
23328 +       { CTL_DEBUG_XID,        "xid=%x"        },
23329 +       { CTL_DEBUG_NID,        "nid=%x"        },
23330 +       { CTL_DEBUG_TAG,        "tag=%x"        },
23331 +       { CTL_DEBUG_NET,        "net=%x"        },
23332 +       { CTL_DEBUG_LIMIT,      "limit=%x"      },
23333 +       { CTL_DEBUG_CRES,       "cres=%x"       },
23334 +       { CTL_DEBUG_DLIM,       "dlim=%x"       },
23335 +       { CTL_DEBUG_QUOTA,      "quota=%x"      },
23336 +       { CTL_DEBUG_CVIRT,      "cvirt=%x"      },
23337 +       { CTL_DEBUG_SPACE,      "space=%x"      },
23338 +       { CTL_DEBUG_PERM,       "perm=%x"       },
23339 +       { CTL_DEBUG_MISC,       "misc=%x"       },
23340 +       { CTL_DEBUG_ERROR,      NULL            }
23341 +};
23342 +
23343 +#define        HANDLE_CASE(id, name, val)                              \
23344 +       case CTL_DEBUG_ ## id:                                  \
23345 +               vs_debug_ ## name = val;                        \
23346 +               printk("vs_debug_" #name "=0x%x\n", val);       \
23347 +               break
23348 +
23349 +
23350 +static int __init vs_debug_setup(char *str)
23351 +{
23352 +       char *p;
23353 +       int token;
23354 +
23355 +       printk("vs_debug_setup(%s)\n", str);
23356 +       while ((p = strsep(&str, ",")) != NULL) {
23357 +               substring_t args[MAX_OPT_ARGS];
23358 +               unsigned int value;
23359 +
23360 +               if (!*p)
23361 +                       continue;
23362 +
23363 +               token = match_token(p, tokens, args);
23364 +               value = (token > 0) ? simple_strtoul(args[0].from, NULL, 0) : 0;
23365 +
23366 +               switch (token) {
23367 +               HANDLE_CASE(SWITCH, switch, value);
23368 +               HANDLE_CASE(XID,    xid,    value);
23369 +               HANDLE_CASE(NID,    nid,    value);
23370 +               HANDLE_CASE(TAG,    tag,    value);
23371 +               HANDLE_CASE(NET,    net,    value);
23372 +               HANDLE_CASE(LIMIT,  limit,  value);
23373 +               HANDLE_CASE(CRES,   cres,   value);
23374 +               HANDLE_CASE(DLIM,   dlim,   value);
23375 +               HANDLE_CASE(QUOTA,  quota,  value);
23376 +               HANDLE_CASE(CVIRT,  cvirt,  value);
23377 +               HANDLE_CASE(SPACE,  space,  value);
23378 +               HANDLE_CASE(PERM,   perm,   value);
23379 +               HANDLE_CASE(MISC,   misc,   value);
23380 +               default:
23381 +                       return -EINVAL;
23382 +                       break;
23383 +               }
23384 +       }
23385 +       return 1;
23386 +}
23387 +
23388 +__setup("vsdebug=", vs_debug_setup);
23389 +
23390 +
23391 +
23392 +EXPORT_SYMBOL_GPL(vs_debug_switch);
23393 +EXPORT_SYMBOL_GPL(vs_debug_xid);
23394 +EXPORT_SYMBOL_GPL(vs_debug_nid);
23395 +EXPORT_SYMBOL_GPL(vs_debug_net);
23396 +EXPORT_SYMBOL_GPL(vs_debug_limit);
23397 +EXPORT_SYMBOL_GPL(vs_debug_cres);
23398 +EXPORT_SYMBOL_GPL(vs_debug_dlim);
23399 +EXPORT_SYMBOL_GPL(vs_debug_quota);
23400 +EXPORT_SYMBOL_GPL(vs_debug_cvirt);
23401 +EXPORT_SYMBOL_GPL(vs_debug_space);
23402 +EXPORT_SYMBOL_GPL(vs_debug_perm);
23403 +EXPORT_SYMBOL_GPL(vs_debug_misc);
23404 +
23405 diff -NurpP --minimal linux-3.6/kernel/vserver/tag.c linux-3.6-vs2.3.4.3-noxfs-nocow/kernel/vserver/tag.c
23406 --- linux-3.6/kernel/vserver/tag.c      1970-01-01 01:00:00.000000000 +0100
23407 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/kernel/vserver/tag.c        2012-10-04 18:47:00.000000000 +0200
23408 @@ -0,0 +1,63 @@
23409 +/*
23410 + *  linux/kernel/vserver/tag.c
23411 + *
23412 + *  Virtual Server: Shallow Tag Space
23413 + *
23414 + *  Copyright (C) 2007  Herbert Pötzl
23415 + *
23416 + *  V0.01  basic implementation
23417 + *
23418 + */
23419 +
23420 +#include <linux/sched.h>
23421 +#include <linux/vserver/debug.h>
23422 +#include <linux/vs_pid.h>
23423 +#include <linux/vs_tag.h>
23424 +
23425 +#include <linux/vserver/tag_cmd.h>
23426 +
23427 +
23428 +int dx_migrate_task(struct task_struct *p, tag_t tag)
23429 +{
23430 +       if (!p)
23431 +               BUG();
23432 +
23433 +       vxdprintk(VXD_CBIT(tag, 5),
23434 +               "dx_migrate_task(%p[#%d],#%d)", p, p->tag, tag);
23435 +
23436 +       task_lock(p);
23437 +       p->tag = tag;
23438 +       task_unlock(p);
23439 +
23440 +       vxdprintk(VXD_CBIT(tag, 5),
23441 +               "moved task %p into [#%d]", p, tag);
23442 +       return 0;
23443 +}
23444 +
23445 +/* vserver syscall commands below here */
23446 +
23447 +/* taks xid and vx_info functions */
23448 +
23449 +
23450 +int vc_task_tag(uint32_t id)
23451 +{
23452 +       tag_t tag;
23453 +
23454 +       if (id) {
23455 +               struct task_struct *tsk;
23456 +               rcu_read_lock();
23457 +               tsk = find_task_by_real_pid(id);
23458 +               tag = (tsk) ? tsk->tag : -ESRCH;
23459 +               rcu_read_unlock();
23460 +       } else
23461 +               tag = dx_current_tag();
23462 +       return tag;
23463 +}
23464 +
23465 +
23466 +int vc_tag_migrate(uint32_t tag)
23467 +{
23468 +       return dx_migrate_task(current, tag & 0xFFFF);
23469 +}
23470 +
23471 +
23472 diff -NurpP --minimal linux-3.6/kernel/vserver/vci_config.h linux-3.6-vs2.3.4.3-noxfs-nocow/kernel/vserver/vci_config.h
23473 --- linux-3.6/kernel/vserver/vci_config.h       1970-01-01 01:00:00.000000000 +0100
23474 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/kernel/vserver/vci_config.h 2012-10-04 18:47:00.000000000 +0200
23475 @@ -0,0 +1,76 @@
23476 +
23477 +/*  interface version */
23478 +
23479 +#define VCI_VERSION            0x00020308
23480 +
23481 +
23482 +enum {
23483 +       VCI_KCBIT_NO_DYNAMIC = 0,
23484 +
23485 +       VCI_KCBIT_PROC_SECURE = 4,
23486 +       /* VCI_KCBIT_HARDCPU = 5, */
23487 +       /* VCI_KCBIT_IDLELIMIT = 6, */
23488 +       /* VCI_KCBIT_IDLETIME = 7, */
23489 +
23490 +       VCI_KCBIT_COWBL = 8,
23491 +       VCI_KCBIT_FULLCOWBL = 9,
23492 +       VCI_KCBIT_SPACES = 10,
23493 +       VCI_KCBIT_NETV2 = 11,
23494 +       VCI_KCBIT_MEMCG = 12,
23495 +
23496 +       VCI_KCBIT_DEBUG = 16,
23497 +       VCI_KCBIT_HISTORY = 20,
23498 +       VCI_KCBIT_TAGGED = 24,
23499 +       VCI_KCBIT_PPTAG = 28,
23500 +
23501 +       VCI_KCBIT_MORE = 31,
23502 +};
23503 +
23504 +
23505 +static inline uint32_t vci_kernel_config(void)
23506 +{
23507 +       return
23508 +       (1 << VCI_KCBIT_NO_DYNAMIC) |
23509 +
23510 +       /* configured features */
23511 +#ifdef CONFIG_VSERVER_PROC_SECURE
23512 +       (1 << VCI_KCBIT_PROC_SECURE) |
23513 +#endif
23514 +#ifdef CONFIG_VSERVER_COWBL
23515 +       (1 << VCI_KCBIT_COWBL) |
23516 +       (1 << VCI_KCBIT_FULLCOWBL) |
23517 +#endif
23518 +       (1 << VCI_KCBIT_SPACES) |
23519 +       (1 << VCI_KCBIT_NETV2) |
23520 +#ifdef CONFIG_CGROUP_MEM_RES_CTLR
23521 +       (1 << VCI_KCBIT_MEMCG) |
23522 +#endif
23523 +
23524 +       /* debug options */
23525 +#ifdef CONFIG_VSERVER_DEBUG
23526 +       (1 << VCI_KCBIT_DEBUG) |
23527 +#endif
23528 +#ifdef CONFIG_VSERVER_HISTORY
23529 +       (1 << VCI_KCBIT_HISTORY) |
23530 +#endif
23531 +
23532 +       /* inode context tagging */
23533 +#if    defined(CONFIG_TAGGING_NONE)
23534 +       (0 << VCI_KCBIT_TAGGED) |
23535 +#elif  defined(CONFIG_TAGGING_UID16)
23536 +       (1 << VCI_KCBIT_TAGGED) |
23537 +#elif  defined(CONFIG_TAGGING_GID16)
23538 +       (2 << VCI_KCBIT_TAGGED) |
23539 +#elif  defined(CONFIG_TAGGING_ID24)
23540 +       (3 << VCI_KCBIT_TAGGED) |
23541 +#elif  defined(CONFIG_TAGGING_INTERN)
23542 +       (4 << VCI_KCBIT_TAGGED) |
23543 +#elif  defined(CONFIG_TAGGING_RUNTIME)
23544 +       (5 << VCI_KCBIT_TAGGED) |
23545 +#else
23546 +       (7 << VCI_KCBIT_TAGGED) |
23547 +#endif
23548 +       (1 << VCI_KCBIT_PPTAG) |
23549 +       0;
23550 +}
23551 +
23552 diff -NurpP --minimal linux-3.6/mm/memcontrol.c linux-3.6-vs2.3.4.3-noxfs-nocow/mm/memcontrol.c
23553 --- linux-3.6/mm/memcontrol.c   2012-10-04 15:27:48.000000000 +0200
23554 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/mm/memcontrol.c     2012-10-04 18:47:00.000000000 +0200
23555 @@ -885,6 +885,31 @@ struct mem_cgroup *mem_cgroup_from_task(
23556         return mem_cgroup_from_css(task_subsys_state(p, mem_cgroup_subsys_id));
23557  }
23558  
23559 +u64 mem_cgroup_res_read_u64(struct mem_cgroup *mem, int member)
23560 +{
23561 +       return res_counter_read_u64(&mem->res, member);
23562 +}
23563 +
23564 +u64 mem_cgroup_memsw_read_u64(struct mem_cgroup *mem, int member)
23565 +{
23566 +       return res_counter_read_u64(&mem->memsw, member);
23567 +}
23568 +
23569 +s64 mem_cgroup_stat_read_cache(struct mem_cgroup *mem)
23570 +{
23571 +       return mem_cgroup_read_stat(mem, MEM_CGROUP_STAT_CACHE);
23572 +}
23573 +
23574 +s64 mem_cgroup_stat_read_anon(struct mem_cgroup *mem)
23575 +{
23576 +       return mem_cgroup_read_stat(mem, MEM_CGROUP_STAT_RSS);
23577 +}
23578 +
23579 +s64 mem_cgroup_stat_read_mapped(struct mem_cgroup *mem)
23580 +{
23581 +       return mem_cgroup_read_stat(mem, MEM_CGROUP_STAT_FILE_MAPPED);
23582 +}
23583 +
23584  struct mem_cgroup *try_get_mem_cgroup_from_mm(struct mm_struct *mm)
23585  {
23586         struct mem_cgroup *memcg = NULL;
23587 diff -NurpP --minimal linux-3.6/mm/oom_kill.c linux-3.6-vs2.3.4.3-noxfs-nocow/mm/oom_kill.c
23588 --- linux-3.6/mm/oom_kill.c     2012-10-04 15:27:48.000000000 +0200
23589 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/mm/oom_kill.c       2012-10-04 18:53:46.000000000 +0200
23590 @@ -35,6 +35,8 @@
23591  #include <linux/freezer.h>
23592  #include <linux/ftrace.h>
23593  #include <linux/ratelimit.h>
23594 +#include <linux/reboot.h>
23595 +#include <linux/vs_context.h>
23596  
23597  #define CREATE_TRACE_POINTS
23598  #include <trace/events/oom.h>
23599 @@ -155,11 +157,18 @@ struct task_struct *find_lock_task_mm(st
23600  static bool oom_unkillable_task(struct task_struct *p,
23601                 const struct mem_cgroup *memcg, const nodemask_t *nodemask)
23602  {
23603 -       if (is_global_init(p))
23604 +       unsigned xid = vx_current_xid();
23605 +
23606 +       /* skip the init task, global and per guest */
23607 +       if (task_is_init(p))
23608                 return true;
23609         if (p->flags & PF_KTHREAD)
23610                 return true;
23611  
23612 +       /* skip other guest and host processes if oom in guest */
23613 +       if (xid && vx_task_xid(p) != xid)
23614 +               return true;
23615 +
23616         /* When mem_cgroup_out_of_memory() and p is not member of the group */
23617         if (memcg && !task_in_mem_cgroup(p, memcg))
23618                 return true;
23619 @@ -472,8 +481,8 @@ void oom_kill_process(struct task_struct
23620                 dump_header(p, gfp_mask, order, memcg, nodemask);
23621  
23622         task_lock(p);
23623 -       pr_err("%s: Kill process %d (%s) score %d or sacrifice child\n",
23624 -               message, task_pid_nr(p), p->comm, points);
23625 +       pr_err("%s: Kill process %d:#%u (%s) score %d or sacrifice child\n",
23626 +               message, task_pid_nr(p), p->xid, p->comm, points);
23627         task_unlock(p);
23628  
23629         /*
23630 @@ -518,8 +527,8 @@ void oom_kill_process(struct task_struct
23631  
23632         /* mm cannot safely be dereferenced after task_unlock(victim) */
23633         mm = victim->mm;
23634 -       pr_err("Killed process %d (%s) total-vm:%lukB, anon-rss:%lukB, file-rss:%lukB\n",
23635 -               task_pid_nr(victim), victim->comm, K(victim->mm->total_vm),
23636 +       pr_err("Killed process %d:#%u (%s) total-vm:%lukB, anon-rss:%lukB, file-rss:%lukB\n",
23637 +               task_pid_nr(victim), victim->xid, victim->comm, K(victim->mm->total_vm),
23638                 K(get_mm_counter(victim->mm, MM_ANONPAGES)),
23639                 K(get_mm_counter(victim->mm, MM_FILEPAGES)));
23640         task_unlock(victim);
23641 @@ -589,6 +598,8 @@ int unregister_oom_notifier(struct notif
23642  }
23643  EXPORT_SYMBOL_GPL(unregister_oom_notifier);
23644  
23645 +long vs_oom_action(unsigned int);
23646 +
23647  /*
23648   * Try to acquire the OOM killer lock for the zones in zonelist.  Returns zero
23649   * if a parallel OOM killing is already taking place that includes a zone in
23650 @@ -738,7 +749,12 @@ void out_of_memory(struct zonelist *zone
23651         /* Found nothing?!?! Either we hang forever, or we panic. */
23652         if (!p) {
23653                 dump_header(NULL, gfp_mask, order, NULL, mpol_mask);
23654 -               panic("Out of memory and no killable processes...\n");
23655 +
23656 +               /* avoid panic for guest OOM */
23657 +               if (current->xid)
23658 +                       vs_oom_action(LINUX_REBOOT_CMD_OOM);
23659 +               else
23660 +                       panic("Out of memory and no killable processes...\n");
23661         }
23662         if (PTR_ERR(p) != -1UL) {
23663                 oom_kill_process(p, gfp_mask, order, points, totalpages, NULL,
23664 diff -NurpP --minimal linux-3.6/mm/page_alloc.c linux-3.6-vs2.3.4.3-noxfs-nocow/mm/page_alloc.c
23665 --- linux-3.6/mm/page_alloc.c   2012-10-04 15:27:48.000000000 +0200
23666 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/mm/page_alloc.c     2012-10-04 18:47:00.000000000 +0200
23667 @@ -58,6 +58,8 @@
23668  #include <linux/prefetch.h>
23669  #include <linux/migrate.h>
23670  #include <linux/page-debug-flags.h>
23671 +#include <linux/vs_base.h>
23672 +#include <linux/vs_limit.h>
23673  
23674  #include <asm/tlbflush.h>
23675  #include <asm/div64.h>
23676 @@ -2773,6 +2775,9 @@ void si_meminfo(struct sysinfo *val)
23677         val->totalhigh = totalhigh_pages;
23678         val->freehigh = nr_free_highpages();
23679         val->mem_unit = PAGE_SIZE;
23680 +
23681 +       if (vx_flags(VXF_VIRT_MEM, 0))
23682 +               vx_vsi_meminfo(val);
23683  }
23684  
23685  EXPORT_SYMBOL(si_meminfo);
23686 @@ -2793,6 +2798,9 @@ void si_meminfo_node(struct sysinfo *val
23687         val->freehigh = 0;
23688  #endif
23689         val->mem_unit = PAGE_SIZE;
23690 +
23691 +       if (vx_flags(VXF_VIRT_MEM, 0))
23692 +               vx_vsi_meminfo(val);
23693  }
23694  #endif
23695  
23696 diff -NurpP --minimal linux-3.6/mm/pgtable-generic.c linux-3.6-vs2.3.4.3-noxfs-nocow/mm/pgtable-generic.c
23697 --- linux-3.6/mm/pgtable-generic.c      2012-07-22 23:39:47.000000000 +0200
23698 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/mm/pgtable-generic.c        2012-10-04 18:47:00.000000000 +0200
23699 @@ -6,6 +6,8 @@
23700   *  Copyright (C) 2010  Linus Torvalds
23701   */
23702  
23703 +#include <linux/mm.h>
23704 +
23705  #include <linux/pagemap.h>
23706  #include <asm/tlb.h>
23707  #include <asm-generic/pgtable.h>
23708 diff -NurpP --minimal linux-3.6/mm/shmem.c linux-3.6-vs2.3.4.3-noxfs-nocow/mm/shmem.c
23709 --- linux-3.6/mm/shmem.c        2012-10-04 15:27:48.000000000 +0200
23710 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/mm/shmem.c  2012-10-04 18:47:00.000000000 +0200
23711 @@ -1814,7 +1814,7 @@ static int shmem_statfs(struct dentry *d
23712  {
23713         struct shmem_sb_info *sbinfo = SHMEM_SB(dentry->d_sb);
23714  
23715 -       buf->f_type = TMPFS_MAGIC;
23716 +       buf->f_type = TMPFS_SUPER_MAGIC;
23717         buf->f_bsize = PAGE_CACHE_SIZE;
23718         buf->f_namelen = NAME_MAX;
23719         if (sbinfo->max_blocks) {
23720 @@ -2630,7 +2630,7 @@ int shmem_fill_super(struct super_block 
23721         sb->s_maxbytes = MAX_LFS_FILESIZE;
23722         sb->s_blocksize = PAGE_CACHE_SIZE;
23723         sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
23724 -       sb->s_magic = TMPFS_MAGIC;
23725 +       sb->s_magic = TMPFS_SUPER_MAGIC;
23726         sb->s_op = &shmem_ops;
23727         sb->s_time_gran = 1;
23728  #ifdef CONFIG_TMPFS_XATTR
23729 diff -NurpP --minimal linux-3.6/mm/slab.c linux-3.6-vs2.3.4.3-noxfs-nocow/mm/slab.c
23730 --- linux-3.6/mm/slab.c 2012-10-04 15:27:48.000000000 +0200
23731 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/mm/slab.c   2012-10-04 18:47:00.000000000 +0200
23732 @@ -445,6 +445,8 @@ static void kmem_list3_init(struct kmem_
23733  #define STATS_INC_FREEMISS(x)  do { } while (0)
23734  #endif
23735  
23736 +#include "slab_vs.h"
23737 +
23738  #if DEBUG
23739  
23740  /*
23741 @@ -3539,6 +3541,7 @@ retry:
23742  
23743         obj = slab_get_obj(cachep, slabp, nodeid);
23744         check_slabp(cachep, slabp);
23745 +       vx_slab_alloc(cachep, flags);
23746         l3->free_objects--;
23747         /* move slabp to correct slabp list: */
23748         list_del(&slabp->list);
23749 @@ -3616,6 +3619,7 @@ __cache_alloc_node(struct kmem_cache *ca
23750         /* ___cache_alloc_node can fall back to other nodes */
23751         ptr = ____cache_alloc_node(cachep, flags, nodeid);
23752    out:
23753 +       vx_slab_alloc(cachep, flags);
23754         local_irq_restore(save_flags);
23755         ptr = cache_alloc_debugcheck_after(cachep, flags, ptr, caller);
23756         kmemleak_alloc_recursive(ptr, cachep->object_size, 1, cachep->flags,
23757 @@ -3806,6 +3810,7 @@ static inline void __cache_free(struct k
23758         check_irq_off();
23759         kmemleak_free_recursive(objp, cachep->flags);
23760         objp = cache_free_debugcheck(cachep, objp, caller);
23761 +       vx_slab_free(cachep);
23762  
23763         kmemcheck_slab_free(cachep, objp, cachep->object_size);
23764  
23765 diff -NurpP --minimal linux-3.6/mm/slab_vs.h linux-3.6-vs2.3.4.3-noxfs-nocow/mm/slab_vs.h
23766 --- linux-3.6/mm/slab_vs.h      1970-01-01 01:00:00.000000000 +0100
23767 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/mm/slab_vs.h        2012-10-04 18:47:00.000000000 +0200
23768 @@ -0,0 +1,29 @@
23769 +
23770 +#include <linux/vserver/context.h>
23771 +
23772 +#include <linux/vs_context.h>
23773 +
23774 +static inline
23775 +void vx_slab_alloc(struct kmem_cache *cachep, gfp_t flags)
23776 +{
23777 +       int what = gfp_zone(cachep->gfpflags);
23778 +       struct vx_info *vxi = current_vx_info();
23779 +
23780 +       if (!vxi)
23781 +               return;
23782 +
23783 +       atomic_add(cachep->buffer_size, &vxi->cacct.slab[what]);
23784 +}
23785 +
23786 +static inline
23787 +void vx_slab_free(struct kmem_cache *cachep)
23788 +{
23789 +       int what = gfp_zone(cachep->gfpflags);
23790 +       struct vx_info *vxi = current_vx_info();
23791 +
23792 +       if (!vxi)
23793 +               return;
23794 +
23795 +       atomic_sub(cachep->buffer_size, &vxi->cacct.slab[what]);
23796 +}
23797 +
23798 diff -NurpP --minimal linux-3.6/mm/swapfile.c linux-3.6-vs2.3.4.3-noxfs-nocow/mm/swapfile.c
23799 --- linux-3.6/mm/swapfile.c     2012-10-04 15:27:48.000000000 +0200
23800 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/mm/swapfile.c       2012-10-04 18:47:00.000000000 +0200
23801 @@ -39,6 +39,7 @@
23802  #include <asm/tlbflush.h>
23803  #include <linux/swapops.h>
23804  #include <linux/page_cgroup.h>
23805 +#include <linux/vs_base.h>
23806  
23807  static bool swap_count_continued(struct swap_info_struct *, pgoff_t,
23808                                  unsigned char);
23809 @@ -1686,6 +1687,16 @@ static int swap_show(struct seq_file *sw
23810  
23811         if (si == SEQ_START_TOKEN) {
23812                 seq_puts(swap,"Filename\t\t\t\tType\t\tSize\tUsed\tPriority\n");
23813 +               if (vx_flags(VXF_VIRT_MEM, 0)) {
23814 +                       struct sysinfo si;
23815 +
23816 +                       vx_vsi_swapinfo(&si);
23817 +                       if (si.totalswap < (1 << 10))
23818 +                               return 0;
23819 +                       seq_printf(swap, "%s\t\t\t\t\t%s\t%lu\t%lu\t%d\n",
23820 +                               "hdv0", "partition", si.totalswap >> 10,
23821 +                               (si.totalswap - si.freeswap) >> 10, -1);
23822 +               }
23823                 return 0;
23824         }
23825  
23826 @@ -2113,6 +2124,8 @@ void si_swapinfo(struct sysinfo *val)
23827         val->freeswap = nr_swap_pages + nr_to_be_unused;
23828         val->totalswap = total_swap_pages + nr_to_be_unused;
23829         spin_unlock(&swap_lock);
23830 +       if (vx_flags(VXF_VIRT_MEM, 0))
23831 +               vx_vsi_swapinfo(val);
23832  }
23833  
23834  /*
23835 diff -NurpP --minimal linux-3.6/net/bridge/br_multicast.c linux-3.6-vs2.3.4.3-noxfs-nocow/net/bridge/br_multicast.c
23836 --- linux-3.6/net/bridge/br_multicast.c 2012-10-04 15:27:49.000000000 +0200
23837 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/net/bridge/br_multicast.c   2012-10-04 18:47:00.000000000 +0200
23838 @@ -447,7 +447,7 @@ static struct sk_buff *br_ip6_multicast_
23839         ip6h->hop_limit = 1;
23840         ipv6_addr_set(&ip6h->daddr, htonl(0xff020000), 0, 0, htonl(1));
23841         if (ipv6_dev_get_saddr(dev_net(br->dev), br->dev, &ip6h->daddr, 0,
23842 -                              &ip6h->saddr)) {
23843 +                              &ip6h->saddr, NULL)) {
23844                 kfree_skb(skb);
23845                 return NULL;
23846         }
23847 diff -NurpP --minimal linux-3.6/net/core/dev.c linux-3.6-vs2.3.4.3-noxfs-nocow/net/core/dev.c
23848 --- linux-3.6/net/core/dev.c    2012-10-04 15:27:49.000000000 +0200
23849 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/net/core/dev.c      2012-10-04 18:47:00.000000000 +0200
23850 @@ -126,6 +126,7 @@
23851  #include <linux/in.h>
23852  #include <linux/jhash.h>
23853  #include <linux/random.h>
23854 +#include <linux/vs_inet.h>
23855  #include <trace/events/napi.h>
23856  #include <trace/events/net.h>
23857  #include <trace/events/skb.h>
23858 @@ -620,7 +621,8 @@ struct net_device *__dev_get_by_name(str
23859         struct hlist_head *head = dev_name_hash(net, name);
23860  
23861         hlist_for_each_entry(dev, p, head, name_hlist)
23862 -               if (!strncmp(dev->name, name, IFNAMSIZ))
23863 +               if (!strncmp(dev->name, name, IFNAMSIZ) &&
23864 +                   nx_dev_visible(current_nx_info(), dev))
23865                         return dev;
23866  
23867         return NULL;
23868 @@ -646,7 +648,8 @@ struct net_device *dev_get_by_name_rcu(s
23869         struct hlist_head *head = dev_name_hash(net, name);
23870  
23871         hlist_for_each_entry_rcu(dev, p, head, name_hlist)
23872 -               if (!strncmp(dev->name, name, IFNAMSIZ))
23873 +               if (!strncmp(dev->name, name, IFNAMSIZ) &&
23874 +                   nx_dev_visible(current_nx_info(), dev))
23875                         return dev;
23876  
23877         return NULL;
23878 @@ -697,7 +700,8 @@ struct net_device *__dev_get_by_index(st
23879         struct hlist_head *head = dev_index_hash(net, ifindex);
23880  
23881         hlist_for_each_entry(dev, p, head, index_hlist)
23882 -               if (dev->ifindex == ifindex)
23883 +               if ((dev->ifindex == ifindex) &&
23884 +                   nx_dev_visible(current_nx_info(), dev))
23885                         return dev;
23886  
23887         return NULL;
23888 @@ -715,7 +719,7 @@ EXPORT_SYMBOL(__dev_get_by_index);
23889   *     about locking. The caller must hold RCU lock.
23890   */
23891  
23892 -struct net_device *dev_get_by_index_rcu(struct net *net, int ifindex)
23893 +struct net_device *dev_get_by_index_real_rcu(struct net *net, int ifindex)
23894  {
23895         struct hlist_node *p;
23896         struct net_device *dev;
23897 @@ -727,6 +731,16 @@ struct net_device *dev_get_by_index_rcu(
23898  
23899         return NULL;
23900  }
23901 +EXPORT_SYMBOL(dev_get_by_index_real_rcu);
23902 +
23903 +struct net_device *dev_get_by_index_rcu(struct net *net, int ifindex)
23904 +{
23905 +       struct net_device *dev = dev_get_by_index_real_rcu(net, ifindex);
23906 +
23907 +       if (nx_dev_visible(current_nx_info(), dev))
23908 +               return dev;
23909 +       return NULL;
23910 +}
23911  EXPORT_SYMBOL(dev_get_by_index_rcu);
23912  
23913  
23914 @@ -775,7 +789,8 @@ struct net_device *dev_getbyhwaddr_rcu(s
23915  
23916         for_each_netdev_rcu(net, dev)
23917                 if (dev->type == type &&
23918 -                   !memcmp(dev->dev_addr, ha, dev->addr_len))
23919 +                   !memcmp(dev->dev_addr, ha, dev->addr_len) &&
23920 +                   nx_dev_visible(current_nx_info(), dev))
23921                         return dev;
23922  
23923         return NULL;
23924 @@ -787,9 +802,11 @@ struct net_device *__dev_getfirstbyhwtyp
23925         struct net_device *dev;
23926  
23927         ASSERT_RTNL();
23928 -       for_each_netdev(net, dev)
23929 -               if (dev->type == type)
23930 +       for_each_netdev(net, dev) {
23931 +               if ((dev->type == type) &&
23932 +                   nx_dev_visible(current_nx_info(), dev))
23933                         return dev;
23934 +       }
23935  
23936         return NULL;
23937  }
23938 @@ -907,6 +924,8 @@ static int __dev_alloc_name(struct net *
23939                                 continue;
23940                         if (i < 0 || i >= max_netdevices)
23941                                 continue;
23942 +                       if (!nx_dev_visible(current_nx_info(), d))
23943 +                               continue;
23944  
23945                         /*  avoid cases where sscanf is not exact inverse of printf */
23946                         snprintf(buf, IFNAMSIZ, name, i);
23947 @@ -4071,6 +4090,8 @@ static int dev_ifconf(struct net *net, c
23948  
23949         total = 0;
23950         for_each_netdev(net, dev) {
23951 +               if (!nx_dev_visible(current_nx_info(), dev))
23952 +                       continue;
23953                 for (i = 0; i < NPROTO; i++) {
23954                         if (gifconf_list[i]) {
23955                                 int done;
23956 @@ -4173,6 +4194,10 @@ static void dev_seq_printf_stats(struct 
23957         struct rtnl_link_stats64 temp;
23958         const struct rtnl_link_stats64 *stats = dev_get_stats(dev, &temp);
23959  
23960 +       /* device visible inside network context? */
23961 +       if (!nx_dev_visible(current_nx_info(), dev))
23962 +               return;
23963 +
23964         seq_printf(seq, "%6s: %7llu %7llu %4llu %4llu %4llu %5llu %10llu %9llu "
23965                    "%8llu %7llu %4llu %4llu %4llu %5llu %7llu %10llu\n",
23966                    dev->name, stats->rx_bytes, stats->rx_packets,
23967 diff -NurpP --minimal linux-3.6/net/core/rtnetlink.c linux-3.6-vs2.3.4.3-noxfs-nocow/net/core/rtnetlink.c
23968 --- linux-3.6/net/core/rtnetlink.c      2012-10-04 15:27:49.000000000 +0200
23969 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/net/core/rtnetlink.c        2012-10-04 18:47:00.000000000 +0200
23970 @@ -1080,6 +1080,8 @@ static int rtnl_dump_ifinfo(struct sk_bu
23971                 hlist_for_each_entry_rcu(dev, node, head, index_hlist) {
23972                         if (idx < s_idx)
23973                                 goto cont;
23974 +                       if (!nx_dev_visible(skb->sk->sk_nx_info, dev))
23975 +                               continue;
23976                         if (rtnl_fill_ifinfo(skb, dev, RTM_NEWLINK,
23977                                              NETLINK_CB(cb->skb).pid,
23978                                              cb->nlh->nlmsg_seq, 0,
23979 @@ -1969,6 +1971,9 @@ void rtmsg_ifinfo(int type, struct net_d
23980         int err = -ENOBUFS;
23981         size_t if_info_size;
23982  
23983 +       if (!nx_dev_visible(current_nx_info(), dev))
23984 +               return;
23985 +
23986         skb = nlmsg_new((if_info_size = if_nlmsg_size(dev, 0)), GFP_KERNEL);
23987         if (skb == NULL)
23988                 goto errout;
23989 diff -NurpP --minimal linux-3.6/net/core/sock.c linux-3.6-vs2.3.4.3-noxfs-nocow/net/core/sock.c
23990 --- linux-3.6/net/core/sock.c   2012-10-04 15:27:49.000000000 +0200
23991 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/net/core/sock.c     2012-10-04 18:47:00.000000000 +0200
23992 @@ -132,6 +132,10 @@
23993  #include <net/netprio_cgroup.h>
23994  
23995  #include <linux/filter.h>
23996 +#include <linux/vs_socket.h>
23997 +#include <linux/vs_limit.h>
23998 +#include <linux/vs_context.h>
23999 +#include <linux/vs_network.h>
24000  
24001  #include <trace/events/sock.h>
24002  
24003 @@ -1194,6 +1198,8 @@ static struct sock *sk_prot_alloc(struct
24004                         goto out_free_sec;
24005                 sk_tx_queue_clear(sk);
24006         }
24007 +               sock_vx_init(sk);
24008 +               sock_nx_init(sk);
24009  
24010         return sk;
24011  
24012 @@ -1302,6 +1308,11 @@ static void __sk_free(struct sock *sk)
24013                 put_cred(sk->sk_peer_cred);
24014         put_pid(sk->sk_peer_pid);
24015         put_net(sock_net(sk));
24016 +       vx_sock_dec(sk);
24017 +       clr_vx_info(&sk->sk_vx_info);
24018 +       sk->sk_xid = -1;
24019 +       clr_nx_info(&sk->sk_nx_info);
24020 +       sk->sk_nid = -1;
24021         sk_prot_free(sk->sk_prot_creator, sk);
24022  }
24023  
24024 @@ -1362,6 +1373,8 @@ struct sock *sk_clone_lock(const struct 
24025  
24026                 /* SANITY */
24027                 get_net(sock_net(newsk));
24028 +               sock_vx_init(newsk);
24029 +               sock_nx_init(newsk);
24030                 sk_node_init(&newsk->sk_node);
24031                 sock_lock_init(newsk);
24032                 bh_lock_sock(newsk);
24033 @@ -1418,6 +1431,12 @@ struct sock *sk_clone_lock(const struct 
24034                 smp_wmb();
24035                 atomic_set(&newsk->sk_refcnt, 2);
24036  
24037 +               set_vx_info(&newsk->sk_vx_info, sk->sk_vx_info);
24038 +               newsk->sk_xid = sk->sk_xid;
24039 +               vx_sock_inc(newsk);
24040 +               set_nx_info(&newsk->sk_nx_info, sk->sk_nx_info);
24041 +               newsk->sk_nid = sk->sk_nid;
24042 +
24043                 /*
24044                  * Increment the counter in the same struct proto as the master
24045                  * sock (sk_refcnt_debug_inc uses newsk->sk_prot->socks, that
24046 @@ -2187,6 +2206,12 @@ void sock_init_data(struct socket *sock,
24047  
24048         sk->sk_stamp = ktime_set(-1L, 0);
24049  
24050 +       set_vx_info(&sk->sk_vx_info, current_vx_info());
24051 +       sk->sk_xid = vx_current_xid();
24052 +       vx_sock_inc(sk);
24053 +       set_nx_info(&sk->sk_nx_info, current_nx_info());
24054 +       sk->sk_nid = nx_current_nid();
24055 +
24056         /*
24057          * Before updating sk_refcnt, we must commit prior changes to memory
24058          * (Documentation/RCU/rculist_nulls.txt for details)
24059 diff -NurpP --minimal linux-3.6/net/ipv4/af_inet.c linux-3.6-vs2.3.4.3-noxfs-nocow/net/ipv4/af_inet.c
24060 --- linux-3.6/net/ipv4/af_inet.c        2012-10-04 15:27:49.000000000 +0200
24061 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/net/ipv4/af_inet.c  2012-10-04 18:47:00.000000000 +0200
24062 @@ -118,6 +118,7 @@
24063  #ifdef CONFIG_IP_MROUTE
24064  #include <linux/mroute.h>
24065  #endif
24066 +#include <linux/vs_limit.h>
24067  
24068  
24069  /* The inetsw table contains everything that inet_create needs to
24070 @@ -326,9 +327,13 @@ lookup_protocol:
24071         }
24072  
24073         err = -EPERM;
24074 +       if ((protocol == IPPROTO_ICMP) &&
24075 +               nx_capable(CAP_NET_RAW, NXC_RAW_ICMP))
24076 +               goto override;
24077 +
24078         if (sock->type == SOCK_RAW && !kern && !capable(CAP_NET_RAW))
24079                 goto out_rcu_unlock;
24080 -
24081 +override:
24082         err = -EAFNOSUPPORT;
24083         if (!inet_netns_ok(net, protocol))
24084                 goto out_rcu_unlock;
24085 @@ -453,6 +458,7 @@ int inet_bind(struct socket *sock, struc
24086         struct sockaddr_in *addr = (struct sockaddr_in *)uaddr;
24087         struct sock *sk = sock->sk;
24088         struct inet_sock *inet = inet_sk(sk);
24089 +       struct nx_v4_sock_addr nsa;
24090         unsigned short snum;
24091         int chk_addr_ret;
24092         int err;
24093 @@ -476,7 +482,11 @@ int inet_bind(struct socket *sock, struc
24094                         goto out;
24095         }
24096  
24097 -       chk_addr_ret = inet_addr_type(sock_net(sk), addr->sin_addr.s_addr);
24098 +       err = v4_map_sock_addr(inet, addr, &nsa);
24099 +       if (err)
24100 +               goto out;
24101 +
24102 +       chk_addr_ret = inet_addr_type(sock_net(sk), nsa.saddr);
24103  
24104         /* Not specified by any standard per-se, however it breaks too
24105          * many applications when removed.  It is unfortunate since
24106 @@ -488,7 +498,7 @@ int inet_bind(struct socket *sock, struc
24107         err = -EADDRNOTAVAIL;
24108         if (!sysctl_ip_nonlocal_bind &&
24109             !(inet->freebind || inet->transparent) &&
24110 -           addr->sin_addr.s_addr != htonl(INADDR_ANY) &&
24111 +           nsa.saddr != htonl(INADDR_ANY) &&
24112             chk_addr_ret != RTN_LOCAL &&
24113             chk_addr_ret != RTN_MULTICAST &&
24114             chk_addr_ret != RTN_BROADCAST)
24115 @@ -513,7 +523,7 @@ int inet_bind(struct socket *sock, struc
24116         if (sk->sk_state != TCP_CLOSE || inet->inet_num)
24117                 goto out_release_sock;
24118  
24119 -       inet->inet_rcv_saddr = inet->inet_saddr = addr->sin_addr.s_addr;
24120 +       v4_set_sock_addr(inet, &nsa);
24121         if (chk_addr_ret == RTN_MULTICAST || chk_addr_ret == RTN_BROADCAST)
24122                 inet->inet_saddr = 0;  /* Use device */
24123  
24124 @@ -731,11 +741,13 @@ int inet_getname(struct socket *sock, st
24125                      peer == 1))
24126                         return -ENOTCONN;
24127                 sin->sin_port = inet->inet_dport;
24128 -               sin->sin_addr.s_addr = inet->inet_daddr;
24129 +               sin->sin_addr.s_addr =
24130 +                       nx_map_sock_lback(sk->sk_nx_info, inet->inet_daddr);
24131         } else {
24132                 __be32 addr = inet->inet_rcv_saddr;
24133                 if (!addr)
24134                         addr = inet->inet_saddr;
24135 +               addr = nx_map_sock_lback(sk->sk_nx_info, addr);
24136                 sin->sin_port = inet->inet_sport;
24137                 sin->sin_addr.s_addr = addr;
24138         }
24139 diff -NurpP --minimal linux-3.6/net/ipv4/arp.c linux-3.6-vs2.3.4.3-noxfs-nocow/net/ipv4/arp.c
24140 --- linux-3.6/net/ipv4/arp.c    2012-10-04 15:27:49.000000000 +0200
24141 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/net/ipv4/arp.c      2012-10-04 18:47:00.000000000 +0200
24142 @@ -1318,6 +1318,7 @@ static void arp_format_neigh_entry(struc
24143         struct net_device *dev = n->dev;
24144         int hatype = dev->type;
24145  
24146 +       /* FIXME: check for network context */
24147         read_lock(&n->lock);
24148         /* Convert hardware address to XX:XX:XX:XX ... form. */
24149  #if IS_ENABLED(CONFIG_AX25)
24150 @@ -1349,6 +1350,7 @@ static void arp_format_pneigh_entry(stru
24151         int hatype = dev ? dev->type : 0;
24152         char tbuf[16];
24153  
24154 +       /* FIXME: check for network context */
24155         sprintf(tbuf, "%pI4", n->key);
24156         seq_printf(seq, "%-16s 0x%-10x0x%-10x%s     *        %s\n",
24157                    tbuf, hatype, ATF_PUBL | ATF_PERM, "00:00:00:00:00:00",
24158 diff -NurpP --minimal linux-3.6/net/ipv4/devinet.c linux-3.6-vs2.3.4.3-noxfs-nocow/net/ipv4/devinet.c
24159 --- linux-3.6/net/ipv4/devinet.c        2012-10-04 15:27:49.000000000 +0200
24160 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/net/ipv4/devinet.c  2012-10-04 18:47:00.000000000 +0200
24161 @@ -516,6 +516,7 @@ struct in_device *inetdev_by_index(struc
24162  }
24163  EXPORT_SYMBOL(inetdev_by_index);
24164  
24165 +
24166  /* Called only from RTNL semaphored context. No locks. */
24167  
24168  struct in_ifaddr *inet_ifa_byprefix(struct in_device *in_dev, __be32 prefix,
24169 @@ -757,6 +758,8 @@ int devinet_ioctl(struct net *net, unsig
24170  
24171         in_dev = __in_dev_get_rtnl(dev);
24172         if (in_dev) {
24173 +               struct nx_info *nxi = current_nx_info();
24174 +
24175                 if (tryaddrmatch) {
24176                         /* Matthias Andree */
24177                         /* compare label and address (4.4BSD style) */
24178 @@ -765,6 +768,8 @@ int devinet_ioctl(struct net *net, unsig
24179                            This is checked above. */
24180                         for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
24181                              ifap = &ifa->ifa_next) {
24182 +                               if (!nx_v4_ifa_visible(nxi, ifa))
24183 +                                       continue;
24184                                 if (!strcmp(ifr.ifr_name, ifa->ifa_label) &&
24185                                     sin_orig.sin_addr.s_addr ==
24186                                                         ifa->ifa_local) {
24187 @@ -777,9 +782,12 @@ int devinet_ioctl(struct net *net, unsig
24188                    comparing just the label */
24189                 if (!ifa) {
24190                         for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
24191 -                            ifap = &ifa->ifa_next)
24192 +                            ifap = &ifa->ifa_next) {
24193 +                               if (!nx_v4_ifa_visible(nxi, ifa))
24194 +                                       continue;
24195                                 if (!strcmp(ifr.ifr_name, ifa->ifa_label))
24196                                         break;
24197 +                       }
24198                 }
24199         }
24200  
24201 @@ -932,6 +940,8 @@ static int inet_gifconf(struct net_devic
24202                 goto out;
24203  
24204         for (ifa = in_dev->ifa_list; ifa; ifa = ifa->ifa_next) {
24205 +               if (!nx_v4_ifa_visible(current_nx_info(), ifa))
24206 +                       continue;
24207                 if (!buf) {
24208                         done += sizeof(ifr);
24209                         continue;
24210 @@ -1291,6 +1301,7 @@ static int inet_dump_ifaddr(struct sk_bu
24211         struct net_device *dev;
24212         struct in_device *in_dev;
24213         struct in_ifaddr *ifa;
24214 +       struct sock *sk = skb->sk;
24215         struct hlist_head *head;
24216         struct hlist_node *node;
24217  
24218 @@ -1313,6 +1324,8 @@ static int inet_dump_ifaddr(struct sk_bu
24219  
24220                         for (ifa = in_dev->ifa_list, ip_idx = 0; ifa;
24221                              ifa = ifa->ifa_next, ip_idx++) {
24222 +                       if (sk && !nx_v4_ifa_visible(sk->sk_nx_info, ifa))
24223 +                               continue;
24224                                 if (ip_idx < s_ip_idx)
24225                                         continue;
24226                                 if (inet_fill_ifaddr(skb, ifa,
24227 diff -NurpP --minimal linux-3.6/net/ipv4/fib_trie.c linux-3.6-vs2.3.4.3-noxfs-nocow/net/ipv4/fib_trie.c
24228 --- linux-3.6/net/ipv4/fib_trie.c       2012-10-04 15:27:49.000000000 +0200
24229 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/net/ipv4/fib_trie.c 2012-10-04 18:47:00.000000000 +0200
24230 @@ -2554,6 +2554,7 @@ static int fib_route_seq_show(struct seq
24231                             || fa->fa_type == RTN_MULTICAST)
24232                                 continue;
24233  
24234 +                       /* FIXME: check for network context? */
24235                         if (fi)
24236                                 seq_printf(seq,
24237                                          "%s\t%08X\t%08X\t%04X\t%d\t%u\t"
24238 diff -NurpP --minimal linux-3.6/net/ipv4/inet_connection_sock.c linux-3.6-vs2.3.4.3-noxfs-nocow/net/ipv4/inet_connection_sock.c
24239 --- linux-3.6/net/ipv4/inet_connection_sock.c   2012-10-04 15:27:49.000000000 +0200
24240 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/net/ipv4/inet_connection_sock.c     2012-10-04 18:47:00.000000000 +0200
24241 @@ -53,6 +53,37 @@ void inet_get_local_port_range(int *low,
24242  }
24243  EXPORT_SYMBOL(inet_get_local_port_range);
24244  
24245 +int ipv4_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2)
24246 +{
24247 +       __be32  sk1_rcv_saddr = sk_rcv_saddr(sk1),
24248 +               sk2_rcv_saddr = sk_rcv_saddr(sk2);
24249 +
24250 +       if (inet_v6_ipv6only(sk2))
24251 +               return 0;
24252 +
24253 +       if (sk1_rcv_saddr &&
24254 +           sk2_rcv_saddr &&
24255 +           sk1_rcv_saddr == sk2_rcv_saddr)
24256 +               return 1;
24257 +
24258 +       if (sk1_rcv_saddr &&
24259 +           !sk2_rcv_saddr &&
24260 +           v4_addr_in_nx_info(sk2->sk_nx_info, sk1_rcv_saddr, NXA_MASK_BIND))
24261 +               return 1;
24262 +
24263 +       if (sk2_rcv_saddr &&
24264 +           !sk1_rcv_saddr &&
24265 +           v4_addr_in_nx_info(sk1->sk_nx_info, sk2_rcv_saddr, NXA_MASK_BIND))
24266 +               return 1;
24267 +
24268 +       if (!sk1_rcv_saddr &&
24269 +           !sk2_rcv_saddr &&
24270 +           nx_v4_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info))
24271 +               return 1;
24272 +
24273 +       return 0;
24274 +}
24275 +
24276  int inet_csk_bind_conflict(const struct sock *sk,
24277                            const struct inet_bind_bucket *tb, bool relax)
24278  {
24279 @@ -75,9 +106,7 @@ int inet_csk_bind_conflict(const struct 
24280                      sk->sk_bound_dev_if == sk2->sk_bound_dev_if)) {
24281                         if (!reuse || !sk2->sk_reuse ||
24282                             sk2->sk_state == TCP_LISTEN) {
24283 -                               const __be32 sk2_rcv_saddr = sk_rcv_saddr(sk2);
24284 -                               if (!sk2_rcv_saddr || !sk_rcv_saddr(sk) ||
24285 -                                   sk2_rcv_saddr == sk_rcv_saddr(sk))
24286 +                               if (ipv4_rcv_saddr_equal(sk, sk2))
24287                                         break;
24288                         }
24289                         if (!relax && reuse && sk2->sk_reuse &&
24290 diff -NurpP --minimal linux-3.6/net/ipv4/inet_diag.c linux-3.6-vs2.3.4.3-noxfs-nocow/net/ipv4/inet_diag.c
24291 --- linux-3.6/net/ipv4/inet_diag.c      2012-10-04 15:27:49.000000000 +0200
24292 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/net/ipv4/inet_diag.c        2012-10-04 19:02:16.000000000 +0200
24293 @@ -31,6 +31,8 @@
24294  
24295  #include <linux/inet.h>
24296  #include <linux/stddef.h>
24297 +#include <linux/vs_network.h>
24298 +#include <linux/vs_inet.h>
24299  
24300  #include <linux/inet_diag.h>
24301  #include <linux/sock_diag.h>
24302 @@ -101,8 +103,10 @@ int inet_sk_diag_fill(struct sock *sk, s
24303  
24304         r->id.idiag_sport = inet->inet_sport;
24305         r->id.idiag_dport = inet->inet_dport;
24306 -       r->id.idiag_src[0] = inet->inet_rcv_saddr;
24307 -       r->id.idiag_dst[0] = inet->inet_daddr;
24308 +       r->id.idiag_src[0] = nx_map_sock_lback(sk->sk_nx_info,
24309 +               inet->inet_rcv_saddr);
24310 +       r->id.idiag_dst[0] = nx_map_sock_lback(sk->sk_nx_info,
24311 +               inet->inet_daddr);
24312  
24313         /* IPv6 dual-stack sockets use inet->tos for IPv4 connections,
24314          * hence this needs to be included regardless of socket family.
24315 @@ -233,8 +237,8 @@ static int inet_twsk_diag_fill(struct in
24316         sock_diag_save_cookie(tw, r->id.idiag_cookie);
24317         r->id.idiag_sport     = tw->tw_sport;
24318         r->id.idiag_dport     = tw->tw_dport;
24319 -       r->id.idiag_src[0]    = tw->tw_rcv_saddr;
24320 -       r->id.idiag_dst[0]    = tw->tw_daddr;
24321 +       r->id.idiag_src[0]    = nx_map_sock_lback(tw->tw_nx_info, tw->tw_rcv_saddr);
24322 +       r->id.idiag_dst[0]    = nx_map_sock_lback(tw->tw_nx_info, tw->tw_daddr);
24323         r->idiag_state        = tw->tw_substate;
24324         r->idiag_timer        = 3;
24325         r->idiag_expires      = DIV_ROUND_UP(tmo * 1000, HZ);
24326 @@ -276,12 +280,14 @@ int inet_diag_dump_one_icsk(struct inet_
24327  
24328         err = -EINVAL;
24329         if (req->sdiag_family == AF_INET) {
24330 +               /* TODO: lback */
24331                 sk = inet_lookup(net, hashinfo, req->id.idiag_dst[0],
24332                                  req->id.idiag_dport, req->id.idiag_src[0],
24333                                  req->id.idiag_sport, req->id.idiag_if);
24334         }
24335  #if IS_ENABLED(CONFIG_IPV6)
24336         else if (req->sdiag_family == AF_INET6) {
24337 +               /* TODO: lback */
24338                 sk = inet6_lookup(net, hashinfo,
24339                                   (struct in6_addr *)req->id.idiag_dst,
24340                                   req->id.idiag_dport,
24341 @@ -476,6 +482,7 @@ int inet_diag_bc_sk(const struct nlattr 
24342         } else
24343  #endif
24344         {
24345 +                       /* TODO: lback */
24346                 entry.saddr = &inet->inet_rcv_saddr;
24347                 entry.daddr = &inet->inet_daddr;
24348         }
24349 @@ -574,6 +581,7 @@ static int inet_twsk_diag_dump(struct in
24350                 } else
24351  #endif
24352                 {
24353 +                       /* TODO: lback */
24354                         entry.saddr = &tw->tw_rcv_saddr;
24355                         entry.daddr = &tw->tw_daddr;
24356                 }
24357 @@ -620,8 +628,8 @@ static int inet_diag_fill_req(struct sk_
24358  
24359         r->id.idiag_sport = inet->inet_sport;
24360         r->id.idiag_dport = ireq->rmt_port;
24361 -       r->id.idiag_src[0] = ireq->loc_addr;
24362 -       r->id.idiag_dst[0] = ireq->rmt_addr;
24363 +       r->id.idiag_src[0] = nx_map_sock_lback(sk->sk_nx_info, ireq->loc_addr);
24364 +       r->id.idiag_dst[0] = nx_map_sock_lback(sk->sk_nx_info, ireq->rmt_addr);
24365         r->idiag_expires = jiffies_to_msecs(tmo);
24366         r->idiag_rqueue = 0;
24367         r->idiag_wqueue = 0;
24368 @@ -683,6 +691,7 @@ static int inet_diag_dump_reqs(struct sk
24369                                 continue;
24370  
24371                         if (bc) {
24372 +                               /* TODO: lback */
24373                                 entry.saddr =
24374  #if IS_ENABLED(CONFIG_IPV6)
24375                                         (entry.family == AF_INET6) ?
24376 @@ -748,6 +757,8 @@ void inet_diag_dump_icsk(struct inet_has
24377                                 if (!net_eq(sock_net(sk), net))
24378                                         continue;
24379  
24380 +                               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
24381 +                                       continue;
24382                                 if (num < s_num) {
24383                                         num++;
24384                                         continue;
24385 @@ -820,6 +831,8 @@ skip_listen_ht:
24386  
24387                         if (!net_eq(sock_net(sk), net))
24388                                 continue;
24389 +                       if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
24390 +                               continue;
24391                         if (num < s_num)
24392                                 goto next_normal;
24393                         if (!(r->idiag_states & (1 << sk->sk_state)))
24394 @@ -848,7 +861,8 @@ next_normal:
24395                                     &head->twchain) {
24396                                 if (!net_eq(twsk_net(tw), net))
24397                                         continue;
24398 -
24399 +                               if (!nx_check(tw->tw_nid, VS_WATCH_P | VS_IDENT))
24400 +                                       continue;
24401                                 if (num < s_num)
24402                                         goto next_dying;
24403                                 if (r->sdiag_family != AF_UNSPEC &&
24404 diff -NurpP --minimal linux-3.6/net/ipv4/inet_hashtables.c linux-3.6-vs2.3.4.3-noxfs-nocow/net/ipv4/inet_hashtables.c
24405 --- linux-3.6/net/ipv4/inet_hashtables.c        2012-07-22 23:39:48.000000000 +0200
24406 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/net/ipv4/inet_hashtables.c  2012-10-04 18:47:00.000000000 +0200
24407 @@ -22,6 +22,7 @@
24408  #include <net/inet_connection_sock.h>
24409  #include <net/inet_hashtables.h>
24410  #include <net/secure_seq.h>
24411 +#include <net/route.h>
24412  #include <net/ip.h>
24413  
24414  /*
24415 @@ -156,6 +157,11 @@ static inline int compute_score(struct s
24416                         if (rcv_saddr != daddr)
24417                                 return -1;
24418                         score += 2;
24419 +               } else {
24420 +                       /* block non nx_info ips */
24421 +                       if (!v4_addr_in_nx_info(sk->sk_nx_info,
24422 +                               daddr, NXA_MASK_BIND))
24423 +                               return -1;
24424                 }
24425                 if (sk->sk_bound_dev_if) {
24426                         if (sk->sk_bound_dev_if != dif)
24427 @@ -173,7 +179,6 @@ static inline int compute_score(struct s
24428   * wildcarded during the search since they can never be otherwise.
24429   */
24430  
24431 -
24432  struct sock *__inet_lookup_listener(struct net *net,
24433                                     struct inet_hashinfo *hashinfo,
24434                                     const __be32 daddr, const unsigned short hnum,
24435 @@ -196,6 +201,7 @@ begin:
24436                         hiscore = score;
24437                 }
24438         }
24439 +
24440         /*
24441          * if the nulls value we got at the end of this lookup is
24442          * not the expected one, we must restart lookup.
24443 diff -NurpP --minimal linux-3.6/net/ipv4/netfilter/nf_nat_helper.c linux-3.6-vs2.3.4.3-noxfs-nocow/net/ipv4/netfilter/nf_nat_helper.c
24444 --- linux-3.6/net/ipv4/netfilter/nf_nat_helper.c        2012-10-04 15:27:50.000000000 +0200
24445 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/net/ipv4/netfilter/nf_nat_helper.c  2012-10-04 18:47:00.000000000 +0200
24446 @@ -20,6 +20,7 @@
24447  #include <net/route.h>
24448  
24449  #include <linux/netfilter_ipv4.h>
24450 +#include <net/route.h>
24451  #include <net/netfilter/nf_conntrack.h>
24452  #include <net/netfilter/nf_conntrack_helper.h>
24453  #include <net/netfilter/nf_conntrack_ecache.h>
24454 diff -NurpP --minimal linux-3.6/net/ipv4/netfilter.c linux-3.6-vs2.3.4.3-noxfs-nocow/net/ipv4/netfilter.c
24455 --- linux-3.6/net/ipv4/netfilter.c      2012-07-22 23:39:48.000000000 +0200
24456 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/net/ipv4/netfilter.c        2012-10-04 18:47:00.000000000 +0200
24457 @@ -6,7 +6,7 @@
24458  #include <linux/skbuff.h>
24459  #include <linux/gfp.h>
24460  #include <linux/export.h>
24461 -#include <net/route.h>
24462 +// #include <net/route.h>
24463  #include <net/xfrm.h>
24464  #include <net/ip.h>
24465  #include <net/netfilter/nf_queue.h>
24466 diff -NurpP --minimal linux-3.6/net/ipv4/raw.c linux-3.6-vs2.3.4.3-noxfs-nocow/net/ipv4/raw.c
24467 --- linux-3.6/net/ipv4/raw.c    2012-10-04 15:27:50.000000000 +0200
24468 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/net/ipv4/raw.c      2012-10-04 18:47:00.000000000 +0200
24469 @@ -118,7 +118,7 @@ static struct sock *__raw_v4_lookup(stru
24470  
24471                 if (net_eq(sock_net(sk), net) && inet->inet_num == num  &&
24472                     !(inet->inet_daddr && inet->inet_daddr != raddr)    &&
24473 -                   !(inet->inet_rcv_saddr && inet->inet_rcv_saddr != laddr) &&
24474 +                   v4_sock_addr_match(sk->sk_nx_info, inet, laddr)     &&
24475                     !(sk->sk_bound_dev_if && sk->sk_bound_dev_if != dif))
24476                         goto found; /* gotcha */
24477         }
24478 @@ -397,6 +397,12 @@ static int raw_send_hdrinc(struct sock *
24479                 icmp_out_count(net, ((struct icmphdr *)
24480                         skb_transport_header(skb))->type);
24481  
24482 +       err = -EPERM;
24483 +       if (!nx_check(0, VS_ADMIN) && !capable(CAP_NET_RAW) &&
24484 +               sk->sk_nx_info &&
24485 +               !v4_addr_in_nx_info(sk->sk_nx_info, iph->saddr, NXA_MASK_BIND))
24486 +               goto error_free;
24487 +
24488         err = NF_HOOK(NFPROTO_IPV4, NF_INET_LOCAL_OUT, skb, NULL,
24489                       rt->dst.dev, dst_output);
24490         if (err > 0)
24491 @@ -582,6 +588,16 @@ static int raw_sendmsg(struct kiocb *ioc
24492                         goto done;
24493         }
24494  
24495 +       if (sk->sk_nx_info) {
24496 +               rt = ip_v4_find_src(sock_net(sk), sk->sk_nx_info, &fl4);
24497 +               if (IS_ERR(rt)) {
24498 +                       err = PTR_ERR(rt);
24499 +                       rt = NULL;
24500 +                       goto done;
24501 +               }
24502 +               ip_rt_put(rt);
24503 +       }
24504 +
24505         security_sk_classify_flow(sk, flowi4_to_flowi(&fl4));
24506         rt = ip_route_output_flow(sock_net(sk), &fl4, sk);
24507         if (IS_ERR(rt)) {
24508 @@ -658,17 +674,19 @@ static int raw_bind(struct sock *sk, str
24509  {
24510         struct inet_sock *inet = inet_sk(sk);
24511         struct sockaddr_in *addr = (struct sockaddr_in *) uaddr;
24512 +       struct nx_v4_sock_addr nsa = { 0 };
24513         int ret = -EINVAL;
24514         int chk_addr_ret;
24515  
24516         if (sk->sk_state != TCP_CLOSE || addr_len < sizeof(struct sockaddr_in))
24517                 goto out;
24518 -       chk_addr_ret = inet_addr_type(sock_net(sk), addr->sin_addr.s_addr);
24519 +       v4_map_sock_addr(inet, addr, &nsa);
24520 +       chk_addr_ret = inet_addr_type(sock_net(sk), nsa.saddr);
24521         ret = -EADDRNOTAVAIL;
24522 -       if (addr->sin_addr.s_addr && chk_addr_ret != RTN_LOCAL &&
24523 +       if (nsa.saddr && chk_addr_ret != RTN_LOCAL &&
24524             chk_addr_ret != RTN_MULTICAST && chk_addr_ret != RTN_BROADCAST)
24525                 goto out;
24526 -       inet->inet_rcv_saddr = inet->inet_saddr = addr->sin_addr.s_addr;
24527 +       v4_set_sock_addr(inet, &nsa);
24528         if (chk_addr_ret == RTN_MULTICAST || chk_addr_ret == RTN_BROADCAST)
24529                 inet->inet_saddr = 0;  /* Use device */
24530         sk_dst_reset(sk);
24531 @@ -720,7 +738,8 @@ static int raw_recvmsg(struct kiocb *ioc
24532         /* Copy the address. */
24533         if (sin) {
24534                 sin->sin_family = AF_INET;
24535 -               sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
24536 +               sin->sin_addr.s_addr =
24537 +                       nx_map_sock_lback(sk->sk_nx_info, ip_hdr(skb)->saddr);
24538                 sin->sin_port = 0;
24539                 memset(&sin->sin_zero, 0, sizeof(sin->sin_zero));
24540         }
24541 @@ -916,7 +935,8 @@ static struct sock *raw_get_first(struct
24542                 struct hlist_node *node;
24543  
24544                 sk_for_each(sk, node, &state->h->ht[state->bucket])
24545 -                       if (sock_net(sk) == seq_file_net(seq))
24546 +                       if ((sock_net(sk) == seq_file_net(seq)) &&
24547 +                               nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
24548                                 goto found;
24549         }
24550         sk = NULL;
24551 @@ -932,7 +952,8 @@ static struct sock *raw_get_next(struct 
24552                 sk = sk_next(sk);
24553  try_again:
24554                 ;
24555 -       } while (sk && sock_net(sk) != seq_file_net(seq));
24556 +       } while (sk && ((sock_net(sk) != seq_file_net(seq)) ||
24557 +               !nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT)));
24558  
24559         if (!sk && ++state->bucket < RAW_HTABLE_SIZE) {
24560                 sk = sk_head(&state->h->ht[state->bucket]);
24561 diff -NurpP --minimal linux-3.6/net/ipv4/route.c linux-3.6-vs2.3.4.3-noxfs-nocow/net/ipv4/route.c
24562 --- linux-3.6/net/ipv4/route.c  2012-10-04 15:27:50.000000000 +0200
24563 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/net/ipv4/route.c    2012-10-04 18:47:00.000000000 +0200
24564 @@ -1928,7 +1928,7 @@ struct rtable *__ip_route_output_key(str
24565  
24566  
24567         if (fl4->flowi4_oif) {
24568 -               dev_out = dev_get_by_index_rcu(net, fl4->flowi4_oif);
24569 +               dev_out = dev_get_by_index_real_rcu(net, fl4->flowi4_oif);
24570                 rth = ERR_PTR(-ENODEV);
24571                 if (dev_out == NULL)
24572                         goto out;
24573 diff -NurpP --minimal linux-3.6/net/ipv4/tcp.c linux-3.6-vs2.3.4.3-noxfs-nocow/net/ipv4/tcp.c
24574 --- linux-3.6/net/ipv4/tcp.c    2012-10-04 15:27:50.000000000 +0200
24575 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/net/ipv4/tcp.c      2012-10-04 18:47:00.000000000 +0200
24576 @@ -268,6 +268,7 @@
24577  #include <linux/crypto.h>
24578  #include <linux/time.h>
24579  #include <linux/slab.h>
24580 +#include <linux/in.h>
24581  
24582  #include <net/icmp.h>
24583  #include <net/inet_common.h>
24584 diff -NurpP --minimal linux-3.6/net/ipv4/tcp_ipv4.c linux-3.6-vs2.3.4.3-noxfs-nocow/net/ipv4/tcp_ipv4.c
24585 --- linux-3.6/net/ipv4/tcp_ipv4.c       2012-10-04 15:27:50.000000000 +0200
24586 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/net/ipv4/tcp_ipv4.c 2012-10-04 18:47:00.000000000 +0200
24587 @@ -2033,6 +2033,12 @@ static void *listening_get_next(struct s
24588                 req = req->dl_next;
24589                 while (1) {
24590                         while (req) {
24591 +                               vxdprintk(VXD_CBIT(net, 6),
24592 +                                       "sk,req: %p [#%d] (from %d)", req->sk,
24593 +                                       (req->sk)?req->sk->sk_nid:0, nx_current_nid());
24594 +                               if (req->sk &&
24595 +                                       !nx_check(req->sk->sk_nid, VS_WATCH_P | VS_IDENT))
24596 +                                       continue;
24597                                 if (req->rsk_ops->family == st->family) {
24598                                         cur = req;
24599                                         goto out;
24600 @@ -2057,6 +2063,10 @@ get_req:
24601         }
24602  get_sk:
24603         sk_nulls_for_each_from(sk, node) {
24604 +               vxdprintk(VXD_CBIT(net, 6), "sk: %p [#%d] (from %d)",
24605 +                       sk, sk->sk_nid, nx_current_nid());
24606 +               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
24607 +                       continue;
24608                 if (!net_eq(sock_net(sk), net))
24609                         continue;
24610                 if (sk->sk_family == st->family) {
24611 @@ -2133,6 +2143,11 @@ static void *established_get_first(struc
24612  
24613                 spin_lock_bh(lock);
24614                 sk_nulls_for_each(sk, node, &tcp_hashinfo.ehash[st->bucket].chain) {
24615 +                       vxdprintk(VXD_CBIT(net, 6),
24616 +                               "sk,egf: %p [#%d] (from %d)",
24617 +                               sk, sk->sk_nid, nx_current_nid());
24618 +                       if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
24619 +                               continue;
24620                         if (sk->sk_family != st->family ||
24621                             !net_eq(sock_net(sk), net)) {
24622                                 continue;
24623 @@ -2143,6 +2158,11 @@ static void *established_get_first(struc
24624                 st->state = TCP_SEQ_STATE_TIME_WAIT;
24625                 inet_twsk_for_each(tw, node,
24626                                    &tcp_hashinfo.ehash[st->bucket].twchain) {
24627 +                       vxdprintk(VXD_CBIT(net, 6),
24628 +                               "tw: %p [#%d] (from %d)",
24629 +                               tw, tw->tw_nid, nx_current_nid());
24630 +                       if (!nx_check(tw->tw_nid, VS_WATCH_P | VS_IDENT))
24631 +                               continue;
24632                         if (tw->tw_family != st->family ||
24633                             !net_eq(twsk_net(tw), net)) {
24634                                 continue;
24635 @@ -2172,7 +2192,9 @@ static void *established_get_next(struct
24636                 tw = cur;
24637                 tw = tw_next(tw);
24638  get_tw:
24639 -               while (tw && (tw->tw_family != st->family || !net_eq(twsk_net(tw), net))) {
24640 +               while (tw && (tw->tw_family != st->family ||
24641 +                       !net_eq(twsk_net(tw), net) ||
24642 +                       !nx_check(tw->tw_nid, VS_WATCH_P | VS_IDENT))) {
24643                         tw = tw_next(tw);
24644                 }
24645                 if (tw) {
24646 @@ -2196,6 +2218,11 @@ get_tw:
24647                 sk = sk_nulls_next(sk);
24648  
24649         sk_nulls_for_each_from(sk, node) {
24650 +               vxdprintk(VXD_CBIT(net, 6),
24651 +                       "sk,egn: %p [#%d] (from %d)",
24652 +                       sk, sk->sk_nid, nx_current_nid());
24653 +               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
24654 +                       continue;
24655                 if (sk->sk_family == st->family && net_eq(sock_net(sk), net))
24656                         goto found;
24657         }
24658 @@ -2401,9 +2428,9 @@ static void get_openreq4(const struct so
24659         seq_printf(f, "%4d: %08X:%04X %08X:%04X"
24660                 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %u %d %pK%n",
24661                 i,
24662 -               ireq->loc_addr,
24663 +               nx_map_sock_lback(current_nx_info(), ireq->loc_addr),
24664                 ntohs(inet_sk(sk)->inet_sport),
24665 -               ireq->rmt_addr,
24666 +               nx_map_sock_lback(current_nx_info(), ireq->rmt_addr),
24667                 ntohs(ireq->rmt_port),
24668                 TCP_SYN_RECV,
24669                 0, 0, /* could print option size, but that is af dependent. */
24670 @@ -2425,8 +2452,8 @@ static void get_tcp4_sock(struct sock *s
24671         const struct tcp_sock *tp = tcp_sk(sk);
24672         const struct inet_connection_sock *icsk = inet_csk(sk);
24673         const struct inet_sock *inet = inet_sk(sk);
24674 -       __be32 dest = inet->inet_daddr;
24675 -       __be32 src = inet->inet_rcv_saddr;
24676 +       __be32 dest = nx_map_sock_lback(current_nx_info(), inet->inet_daddr);
24677 +       __be32 src = nx_map_sock_lback(current_nx_info(), inet->inet_rcv_saddr);
24678         __u16 destp = ntohs(inet->inet_dport);
24679         __u16 srcp = ntohs(inet->inet_sport);
24680         int rx_queue;
24681 @@ -2483,8 +2510,8 @@ static void get_timewait4_sock(const str
24682         if (ttd < 0)
24683                 ttd = 0;
24684  
24685 -       dest  = tw->tw_daddr;
24686 -       src   = tw->tw_rcv_saddr;
24687 +       dest  = nx_map_sock_lback(current_nx_info(), tw->tw_daddr);
24688 +       src   = nx_map_sock_lback(current_nx_info(), tw->tw_rcv_saddr);
24689         destp = ntohs(tw->tw_dport);
24690         srcp  = ntohs(tw->tw_sport);
24691  
24692 diff -NurpP --minimal linux-3.6/net/ipv4/tcp_minisocks.c linux-3.6-vs2.3.4.3-noxfs-nocow/net/ipv4/tcp_minisocks.c
24693 --- linux-3.6/net/ipv4/tcp_minisocks.c  2012-10-04 15:27:50.000000000 +0200
24694 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/net/ipv4/tcp_minisocks.c    2012-10-04 18:47:00.000000000 +0200
24695 @@ -23,6 +23,9 @@
24696  #include <linux/slab.h>
24697  #include <linux/sysctl.h>
24698  #include <linux/workqueue.h>
24699 +#include <linux/vs_limit.h>
24700 +#include <linux/vs_socket.h>
24701 +#include <linux/vs_context.h>
24702  #include <net/tcp.h>
24703  #include <net/inet_common.h>
24704  #include <net/xfrm.h>
24705 @@ -287,6 +290,11 @@ void tcp_time_wait(struct sock *sk, int 
24706                 tcptw->tw_ts_recent     = tp->rx_opt.ts_recent;
24707                 tcptw->tw_ts_recent_stamp = tp->rx_opt.ts_recent_stamp;
24708  
24709 +               tw->tw_xid              = sk->sk_xid;
24710 +               tw->tw_vx_info          = NULL;
24711 +               tw->tw_nid              = sk->sk_nid;
24712 +               tw->tw_nx_info          = NULL;
24713 +
24714  #if IS_ENABLED(CONFIG_IPV6)
24715                 if (tw->tw_family == PF_INET6) {
24716                         struct ipv6_pinfo *np = inet6_sk(sk);
24717 diff -NurpP --minimal linux-3.6/net/ipv4/udp.c linux-3.6-vs2.3.4.3-noxfs-nocow/net/ipv4/udp.c
24718 --- linux-3.6/net/ipv4/udp.c    2012-10-04 15:27:50.000000000 +0200
24719 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/net/ipv4/udp.c      2012-10-04 18:47:00.000000000 +0200
24720 @@ -300,14 +300,7 @@ fail:
24721  }
24722  EXPORT_SYMBOL(udp_lib_get_port);
24723  
24724 -static int ipv4_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2)
24725 -{
24726 -       struct inet_sock *inet1 = inet_sk(sk1), *inet2 = inet_sk(sk2);
24727 -
24728 -       return  (!ipv6_only_sock(sk2)  &&
24729 -                (!inet1->inet_rcv_saddr || !inet2->inet_rcv_saddr ||
24730 -                  inet1->inet_rcv_saddr == inet2->inet_rcv_saddr));
24731 -}
24732 +extern int ipv4_rcv_saddr_equal(const struct sock *, const struct sock *);
24733  
24734  static unsigned int udp4_portaddr_hash(struct net *net, __be32 saddr,
24735                                        unsigned int port)
24736 @@ -342,6 +335,11 @@ static inline int compute_score(struct s
24737                         if (inet->inet_rcv_saddr != daddr)
24738                                 return -1;
24739                         score += 2;
24740 +               } else {
24741 +                       /* block non nx_info ips */
24742 +                       if (!v4_addr_in_nx_info(sk->sk_nx_info,
24743 +                               daddr, NXA_MASK_BIND))
24744 +                               return -1;
24745                 }
24746                 if (inet->inet_daddr) {
24747                         if (inet->inet_daddr != saddr)
24748 @@ -445,6 +443,7 @@ exact_match:
24749         return result;
24750  }
24751  
24752 +
24753  /* UDP is nearly always wildcards out the wazoo, it makes no sense to try
24754   * harder than this. -DaveM
24755   */
24756 @@ -490,6 +489,11 @@ begin:
24757         sk_nulls_for_each_rcu(sk, node, &hslot->head) {
24758                 score = compute_score(sk, net, saddr, hnum, sport,
24759                                       daddr, dport, dif);
24760 +               /* FIXME: disabled?
24761 +               if (score == 9) {
24762 +                       result = sk;
24763 +                       break;
24764 +               } else */
24765                 if (score > badness) {
24766                         result = sk;
24767                         badness = score;
24768 @@ -503,6 +507,7 @@ begin:
24769         if (get_nulls_value(node) != slot)
24770                 goto begin;
24771  
24772 +
24773         if (result) {
24774                 if (unlikely(!atomic_inc_not_zero_hint(&result->sk_refcnt, 2)))
24775                         result = NULL;
24776 @@ -512,6 +517,7 @@ begin:
24777                         goto begin;
24778                 }
24779         }
24780 +
24781         rcu_read_unlock();
24782         return result;
24783  }
24784 @@ -555,8 +561,7 @@ static inline struct sock *udp_v4_mcast_
24785                     udp_sk(s)->udp_port_hash != hnum ||
24786                     (inet->inet_daddr && inet->inet_daddr != rmt_addr) ||
24787                     (inet->inet_dport != rmt_port && inet->inet_dport) ||
24788 -                   (inet->inet_rcv_saddr &&
24789 -                    inet->inet_rcv_saddr != loc_addr) ||
24790 +                   !v4_sock_addr_match(sk->sk_nx_info, inet, loc_addr) ||
24791                     ipv6_only_sock(s) ||
24792                     (s->sk_bound_dev_if && s->sk_bound_dev_if != dif))
24793                         continue;
24794 @@ -939,6 +944,16 @@ int udp_sendmsg(struct kiocb *iocb, stru
24795                                    inet_sk_flowi_flags(sk)|FLOWI_FLAG_CAN_SLEEP,
24796                                    faddr, saddr, dport, inet->inet_sport);
24797  
24798 +               if (sk->sk_nx_info) {
24799 +                       rt = ip_v4_find_src(net, sk->sk_nx_info, fl4);
24800 +                       if (IS_ERR(rt)) {
24801 +                               err = PTR_ERR(rt);
24802 +                               rt = NULL;
24803 +                               goto out;
24804 +                       }
24805 +                       ip_rt_put(rt);
24806 +               }
24807 +
24808                 security_sk_classify_flow(sk, flowi4_to_flowi(fl4));
24809                 rt = ip_route_output_flow(net, fl4, sk);
24810                 if (IS_ERR(rt)) {
24811 @@ -1244,7 +1259,8 @@ try_again:
24812         if (sin) {
24813                 sin->sin_family = AF_INET;
24814                 sin->sin_port = udp_hdr(skb)->source;
24815 -               sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
24816 +               sin->sin_addr.s_addr = nx_map_sock_lback(
24817 +                       skb->sk->sk_nx_info, ip_hdr(skb)->saddr);
24818                 memset(sin->sin_zero, 0, sizeof(sin->sin_zero));
24819         }
24820         if (inet->cmsg_flags)
24821 @@ -1992,6 +2008,8 @@ static struct sock *udp_get_first(struct
24822                 sk_nulls_for_each(sk, node, &hslot->head) {
24823                         if (!net_eq(sock_net(sk), net))
24824                                 continue;
24825 +                       if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
24826 +                               continue;
24827                         if (sk->sk_family == state->family)
24828                                 goto found;
24829                 }
24830 @@ -2009,7 +2027,9 @@ static struct sock *udp_get_next(struct 
24831  
24832         do {
24833                 sk = sk_nulls_next(sk);
24834 -       } while (sk && (!net_eq(sock_net(sk), net) || sk->sk_family != state->family));
24835 +       } while (sk && (!net_eq(sock_net(sk), net) ||
24836 +               sk->sk_family != state->family ||
24837 +               !nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT)));
24838  
24839         if (!sk) {
24840                 if (state->bucket <= state->udp_table->mask)
24841 @@ -2105,8 +2125,8 @@ static void udp4_format_sock(struct sock
24842                 int bucket, int *len)
24843  {
24844         struct inet_sock *inet = inet_sk(sp);
24845 -       __be32 dest = inet->inet_daddr;
24846 -       __be32 src  = inet->inet_rcv_saddr;
24847 +       __be32 dest = nx_map_sock_lback(current_nx_info(), inet->inet_daddr);
24848 +       __be32 src = nx_map_sock_lback(current_nx_info(), inet->inet_rcv_saddr);
24849         __u16 destp       = ntohs(inet->inet_dport);
24850         __u16 srcp        = ntohs(inet->inet_sport);
24851  
24852 diff -NurpP --minimal linux-3.6/net/ipv6/Kconfig linux-3.6-vs2.3.4.3-noxfs-nocow/net/ipv6/Kconfig
24853 --- linux-3.6/net/ipv6/Kconfig  2012-07-22 23:39:48.000000000 +0200
24854 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/net/ipv6/Kconfig    2012-10-04 18:47:00.000000000 +0200
24855 @@ -4,8 +4,8 @@
24856  
24857  #   IPv6 as module will cause a CRASH if you try to unload it
24858  menuconfig IPV6
24859 -       tristate "The IPv6 protocol"
24860 -       default m
24861 +       bool "The IPv6 protocol"
24862 +       default n
24863         ---help---
24864           This is complemental support for the IP version 6.
24865           You will still be able to do traditional IPv4 networking as well.
24866 diff -NurpP --minimal linux-3.6/net/ipv6/addrconf.c linux-3.6-vs2.3.4.3-noxfs-nocow/net/ipv6/addrconf.c
24867 --- linux-3.6/net/ipv6/addrconf.c       2012-10-04 15:27:50.000000000 +0200
24868 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/net/ipv6/addrconf.c 2012-10-04 18:47:00.000000000 +0200
24869 @@ -92,6 +92,8 @@
24870  #include <linux/proc_fs.h>
24871  #include <linux/seq_file.h>
24872  #include <linux/export.h>
24873 +#include <linux/vs_network.h>
24874 +#include <linux/vs_inet6.h>
24875  
24876  /* Set to 3 to get tracing... */
24877  #define ACONF_DEBUG 2
24878 @@ -1095,7 +1097,7 @@ out:
24879  
24880  int ipv6_dev_get_saddr(struct net *net, struct net_device *dst_dev,
24881                        const struct in6_addr *daddr, unsigned int prefs,
24882 -                      struct in6_addr *saddr)
24883 +                      struct in6_addr *saddr, struct nx_info *nxi)
24884  {
24885         struct ipv6_saddr_score scores[2],
24886                                 *score = &scores[0], *hiscore = &scores[1];
24887 @@ -1167,6 +1169,8 @@ int ipv6_dev_get_saddr(struct net *net, 
24888                                                dev->name);
24889                                 continue;
24890                         }
24891 +                       if (!v6_addr_in_nx_info(nxi, &score->ifa->addr, -1))
24892 +                               continue;
24893  
24894                         score->rule = -1;
24895                         bitmap_zero(score->scorebits, IPV6_SADDR_RULE_MAX);
24896 @@ -3150,7 +3154,10 @@ static void if6_seq_stop(struct seq_file
24897  static int if6_seq_show(struct seq_file *seq, void *v)
24898  {
24899         struct inet6_ifaddr *ifp = (struct inet6_ifaddr *)v;
24900 -       seq_printf(seq, "%pi6 %02x %02x %02x %02x %8s\n",
24901 +
24902 +       if (nx_check(0, VS_ADMIN|VS_WATCH) ||
24903 +           v6_addr_in_nx_info(current_nx_info(), &ifp->addr, -1))
24904 +               seq_printf(seq, "%pi6 %02x %02x %02x %02x %8s\n",
24905                    &ifp->addr,
24906                    ifp->idev->dev->ifindex,
24907                    ifp->prefix_len,
24908 @@ -3656,6 +3663,11 @@ static int in6_dump_addrs(struct inet6_d
24909         struct ifacaddr6 *ifaca;
24910         int err = 1;
24911         int ip_idx = *p_ip_idx;
24912 +       struct nx_info *nxi = skb->sk ? skb->sk->sk_nx_info : NULL;
24913 +
24914 +       /* disable ipv6 on non v6 guests */
24915 +       if (nxi && !nx_info_has_v6(nxi))
24916 +               return skb->len;
24917  
24918         read_lock_bh(&idev->lock);
24919         switch (type) {
24920 @@ -3666,6 +3678,8 @@ static int in6_dump_addrs(struct inet6_d
24921                 list_for_each_entry(ifa, &idev->addr_list, if_list) {
24922                         if (++ip_idx < s_ip_idx)
24923                                 continue;
24924 +                               if (!v6_addr_in_nx_info(nxi, &ifa->addr, -1))
24925 +                                       continue;
24926                         err = inet6_fill_ifaddr(skb, ifa,
24927                                                 NETLINK_CB(cb->skb).pid,
24928                                                 cb->nlh->nlmsg_seq,
24929 @@ -3682,6 +3696,8 @@ static int in6_dump_addrs(struct inet6_d
24930                      ifmca = ifmca->next, ip_idx++) {
24931                         if (ip_idx < s_ip_idx)
24932                                 continue;
24933 +                               if (!v6_addr_in_nx_info(nxi, &ifmca->mca_addr, -1))
24934 +                                       continue;
24935                         err = inet6_fill_ifmcaddr(skb, ifmca,
24936                                                   NETLINK_CB(cb->skb).pid,
24937                                                   cb->nlh->nlmsg_seq,
24938 @@ -3697,6 +3713,8 @@ static int in6_dump_addrs(struct inet6_d
24939                      ifaca = ifaca->aca_next, ip_idx++) {
24940                         if (ip_idx < s_ip_idx)
24941                                 continue;
24942 +                               if (!v6_addr_in_nx_info(nxi, &ifaca->aca_addr, -1))
24943 +                                       continue;
24944                         err = inet6_fill_ifacaddr(skb, ifaca,
24945                                                   NETLINK_CB(cb->skb).pid,
24946                                                   cb->nlh->nlmsg_seq,
24947 @@ -4080,6 +4098,11 @@ static int inet6_dump_ifinfo(struct sk_b
24948         struct inet6_dev *idev;
24949         struct hlist_head *head;
24950         struct hlist_node *node;
24951 +       struct nx_info *nxi = skb->sk ? skb->sk->sk_nx_info : NULL;
24952 +
24953 +       /* FIXME: maybe disable ipv6 on non v6 guests?
24954 +       if (skb->sk && skb->sk->sk_vx_info)
24955 +               return skb->len; */
24956  
24957         s_h = cb->args[0];
24958         s_idx = cb->args[1];
24959 @@ -4091,6 +4114,8 @@ static int inet6_dump_ifinfo(struct sk_b
24960                 hlist_for_each_entry_rcu(dev, node, head, index_hlist) {
24961                         if (idx < s_idx)
24962                                 goto cont;
24963 +                       if (!v6_dev_in_nx_info(dev, nxi))
24964 +                               goto cont;
24965                         idev = __in6_dev_get(dev);
24966                         if (!idev)
24967                                 goto cont;
24968 diff -NurpP --minimal linux-3.6/net/ipv6/af_inet6.c linux-3.6-vs2.3.4.3-noxfs-nocow/net/ipv6/af_inet6.c
24969 --- linux-3.6/net/ipv6/af_inet6.c       2012-07-22 23:39:48.000000000 +0200
24970 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/net/ipv6/af_inet6.c 2012-10-04 18:47:00.000000000 +0200
24971 @@ -43,6 +43,8 @@
24972  #include <linux/netdevice.h>
24973  #include <linux/icmpv6.h>
24974  #include <linux/netfilter_ipv6.h>
24975 +#include <linux/vs_inet.h>
24976 +#include <linux/vs_inet6.h>
24977  
24978  #include <net/ip.h>
24979  #include <net/ipv6.h>
24980 @@ -160,9 +162,12 @@ lookup_protocol:
24981         }
24982  
24983         err = -EPERM;
24984 +       if ((protocol == IPPROTO_ICMPV6) &&
24985 +               nx_capable(CAP_NET_RAW, NXC_RAW_ICMP))
24986 +               goto override;
24987         if (sock->type == SOCK_RAW && !kern && !capable(CAP_NET_RAW))
24988                 goto out_rcu_unlock;
24989 -
24990 +override:
24991         sock->ops = answer->ops;
24992         answer_prot = answer->prot;
24993         answer_no_check = answer->no_check;
24994 @@ -262,6 +267,7 @@ int inet6_bind(struct socket *sock, stru
24995         struct inet_sock *inet = inet_sk(sk);
24996         struct ipv6_pinfo *np = inet6_sk(sk);
24997         struct net *net = sock_net(sk);
24998 +       struct nx_v6_sock_addr nsa;
24999         __be32 v4addr = 0;
25000         unsigned short snum;
25001         int addr_type = 0;
25002 @@ -277,6 +283,10 @@ int inet6_bind(struct socket *sock, stru
25003         if (addr->sin6_family != AF_INET6)
25004                 return -EAFNOSUPPORT;
25005  
25006 +       err = v6_map_sock_addr(inet, addr, &nsa);
25007 +       if (err)
25008 +               return err;
25009 +
25010         addr_type = ipv6_addr_type(&addr->sin6_addr);
25011         if ((addr_type & IPV6_ADDR_MULTICAST) && sock->type == SOCK_STREAM)
25012                 return -EINVAL;
25013 @@ -308,6 +318,7 @@ int inet6_bind(struct socket *sock, stru
25014                 /* Reproduce AF_INET checks to make the bindings consistent */
25015                 v4addr = addr->sin6_addr.s6_addr32[3];
25016                 chk_addr_ret = inet_addr_type(net, v4addr);
25017 +
25018                 if (!sysctl_ip_nonlocal_bind &&
25019                     !(inet->freebind || inet->transparent) &&
25020                     v4addr != htonl(INADDR_ANY) &&
25021 @@ -317,6 +328,10 @@ int inet6_bind(struct socket *sock, stru
25022                         err = -EADDRNOTAVAIL;
25023                         goto out;
25024                 }
25025 +               if (!v4_addr_in_nx_info(sk->sk_nx_info, v4addr, NXA_MASK_BIND)) {
25026 +                       err = -EADDRNOTAVAIL;
25027 +                       goto out;
25028 +               }
25029         } else {
25030                 if (addr_type != IPV6_ADDR_ANY) {
25031                         struct net_device *dev = NULL;
25032 @@ -343,6 +358,11 @@ int inet6_bind(struct socket *sock, stru
25033                                 }
25034                         }
25035  
25036 +                       if (!v6_addr_in_nx_info(sk->sk_nx_info, &addr->sin6_addr, -1)) {
25037 +                               err = -EADDRNOTAVAIL;
25038 +                               goto out_unlock;
25039 +                       }
25040 +
25041                         /* ipv4 addr of the socket is invalid.  Only the
25042                          * unspecified and mapped address have a v4 equivalent.
25043                          */
25044 @@ -359,6 +379,9 @@ int inet6_bind(struct socket *sock, stru
25045                 }
25046         }
25047  
25048 +       /* what's that for? */
25049 +       v6_set_sock_addr(inet, &nsa);
25050 +
25051         inet->inet_rcv_saddr = v4addr;
25052         inet->inet_saddr = v4addr;
25053  
25054 @@ -460,9 +483,11 @@ int inet6_getname(struct socket *sock, s
25055                         return -ENOTCONN;
25056                 sin->sin6_port = inet->inet_dport;
25057                 sin->sin6_addr = np->daddr;
25058 +               /* FIXME: remap lback? */
25059                 if (np->sndflow)
25060                         sin->sin6_flowinfo = np->flow_label;
25061         } else {
25062 +               /* FIXME: remap lback? */
25063                 if (ipv6_addr_any(&np->rcv_saddr))
25064                         sin->sin6_addr = np->saddr;
25065                 else
25066 diff -NurpP --minimal linux-3.6/net/ipv6/datagram.c linux-3.6-vs2.3.4.3-noxfs-nocow/net/ipv6/datagram.c
25067 --- linux-3.6/net/ipv6/datagram.c       2012-07-22 23:39:48.000000000 +0200
25068 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/net/ipv6/datagram.c 2012-10-04 18:47:00.000000000 +0200
25069 @@ -645,7 +645,7 @@ int datagram_send_ctl(struct net *net, s
25070  
25071                         rcu_read_lock();
25072                         if (fl6->flowi6_oif) {
25073 -                               dev = dev_get_by_index_rcu(net, fl6->flowi6_oif);
25074 +                               dev = dev_get_by_index_real_rcu(net, fl6->flowi6_oif);
25075                                 if (!dev) {
25076                                         rcu_read_unlock();
25077                                         return -ENODEV;
25078 diff -NurpP --minimal linux-3.6/net/ipv6/fib6_rules.c linux-3.6-vs2.3.4.3-noxfs-nocow/net/ipv6/fib6_rules.c
25079 --- linux-3.6/net/ipv6/fib6_rules.c     2012-07-22 23:39:48.000000000 +0200
25080 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/net/ipv6/fib6_rules.c       2012-10-04 18:47:00.000000000 +0200
25081 @@ -90,7 +90,7 @@ static int fib6_rule_action(struct fib_r
25082                                                ip6_dst_idev(&rt->dst)->dev,
25083                                                &flp6->daddr,
25084                                                rt6_flags2srcprefs(flags),
25085 -                                              &saddr))
25086 +                                              &saddr, NULL))
25087                                 goto again;
25088                         if (!ipv6_prefix_equal(&saddr, &r->src.addr,
25089                                                r->src.plen))
25090 diff -NurpP --minimal linux-3.6/net/ipv6/inet6_hashtables.c linux-3.6-vs2.3.4.3-noxfs-nocow/net/ipv6/inet6_hashtables.c
25091 --- linux-3.6/net/ipv6/inet6_hashtables.c       2011-10-24 18:45:34.000000000 +0200
25092 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/net/ipv6/inet6_hashtables.c 2012-10-04 18:47:00.000000000 +0200
25093 @@ -16,6 +16,7 @@
25094  
25095  #include <linux/module.h>
25096  #include <linux/random.h>
25097 +#include <linux/vs_inet6.h>
25098  
25099  #include <net/inet_connection_sock.h>
25100  #include <net/inet_hashtables.h>
25101 @@ -83,7 +84,6 @@ struct sock *__inet6_lookup_established(
25102         unsigned int slot = hash & hashinfo->ehash_mask;
25103         struct inet_ehash_bucket *head = &hashinfo->ehash[slot];
25104  
25105 -
25106         rcu_read_lock();
25107  begin:
25108         sk_nulls_for_each_rcu(sk, node, &head->chain) {
25109 @@ -95,7 +95,7 @@ begin:
25110                                 sock_put(sk);
25111                                 goto begin;
25112                         }
25113 -               goto out;
25114 +                       goto out;
25115                 }
25116         }
25117         if (get_nulls_value(node) != slot)
25118 @@ -141,6 +141,9 @@ static inline int compute_score(struct s
25119                         if (!ipv6_addr_equal(&np->rcv_saddr, daddr))
25120                                 return -1;
25121                         score++;
25122 +               } else {
25123 +                       if (!v6_addr_in_nx_info(sk->sk_nx_info, daddr, -1))
25124 +                               return -1;
25125                 }
25126                 if (sk->sk_bound_dev_if) {
25127                         if (sk->sk_bound_dev_if != dif)
25128 diff -NurpP --minimal linux-3.6/net/ipv6/ip6_output.c linux-3.6-vs2.3.4.3-noxfs-nocow/net/ipv6/ip6_output.c
25129 --- linux-3.6/net/ipv6/ip6_output.c     2012-10-04 15:27:50.000000000 +0200
25130 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/net/ipv6/ip6_output.c       2012-10-04 18:47:00.000000000 +0200
25131 @@ -966,7 +966,8 @@ static int ip6_dst_lookup_tail(struct so
25132                 struct rt6_info *rt = (struct rt6_info *) *dst;
25133                 err = ip6_route_get_saddr(net, rt, &fl6->daddr,
25134                                           sk ? inet6_sk(sk)->srcprefs : 0,
25135 -                                         &fl6->saddr);
25136 +                                         &fl6->saddr,
25137 +                                         sk ? sk->sk_nx_info : NULL);
25138                 if (err)
25139                         goto out_err_release;
25140         }
25141 diff -NurpP --minimal linux-3.6/net/ipv6/ndisc.c linux-3.6-vs2.3.4.3-noxfs-nocow/net/ipv6/ndisc.c
25142 --- linux-3.6/net/ipv6/ndisc.c  2012-10-04 15:27:50.000000000 +0200
25143 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/net/ipv6/ndisc.c    2012-10-04 18:47:00.000000000 +0200
25144 @@ -517,7 +517,7 @@ static void ndisc_send_na(struct net_dev
25145         } else {
25146                 if (ipv6_dev_get_saddr(dev_net(dev), dev, daddr,
25147                                        inet6_sk(dev_net(dev)->ipv6.ndisc_sk)->srcprefs,
25148 -                                      &tmpaddr))
25149 +                                      &tmpaddr, NULL))
25150                         return;
25151                 src_addr = &tmpaddr;
25152         }
25153 diff -NurpP --minimal linux-3.6/net/ipv6/raw.c linux-3.6-vs2.3.4.3-noxfs-nocow/net/ipv6/raw.c
25154 --- linux-3.6/net/ipv6/raw.c    2012-10-04 15:27:50.000000000 +0200
25155 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/net/ipv6/raw.c      2012-10-04 18:47:00.000000000 +0200
25156 @@ -30,6 +30,7 @@
25157  #include <linux/icmpv6.h>
25158  #include <linux/netfilter.h>
25159  #include <linux/netfilter_ipv6.h>
25160 +#include <linux/vs_inet6.h>
25161  #include <linux/skbuff.h>
25162  #include <linux/compat.h>
25163  #include <asm/uaccess.h>
25164 @@ -284,6 +285,13 @@ static int rawv6_bind(struct sock *sk, s
25165                                 goto out_unlock;
25166                 }
25167  
25168 +               if (!v6_addr_in_nx_info(sk->sk_nx_info, &addr->sin6_addr, -1)) {
25169 +                       err = -EADDRNOTAVAIL;
25170 +                       if (dev)
25171 +                               dev_put(dev);
25172 +                       goto out;
25173 +               }
25174 +
25175                 /* ipv4 addr of the socket is invalid.  Only the
25176                  * unspecified and mapped address have a v4 equivalent.
25177                  */
25178 diff -NurpP --minimal linux-3.6/net/ipv6/route.c linux-3.6-vs2.3.4.3-noxfs-nocow/net/ipv6/route.c
25179 --- linux-3.6/net/ipv6/route.c  2012-10-04 15:27:50.000000000 +0200
25180 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/net/ipv6/route.c    2012-10-04 18:47:00.000000000 +0200
25181 @@ -57,6 +57,7 @@
25182  #include <net/xfrm.h>
25183  #include <net/netevent.h>
25184  #include <net/netlink.h>
25185 +#include <linux/vs_inet6.h>
25186  
25187  #include <asm/uaccess.h>
25188  
25189 @@ -2111,15 +2112,17 @@ int ip6_route_get_saddr(struct net *net,
25190                         struct rt6_info *rt,
25191                         const struct in6_addr *daddr,
25192                         unsigned int prefs,
25193 -                       struct in6_addr *saddr)
25194 +                       struct in6_addr *saddr,
25195 +                       struct nx_info *nxi)
25196  {
25197         struct inet6_dev *idev = ip6_dst_idev((struct dst_entry*)rt);
25198         int err = 0;
25199 -       if (rt->rt6i_prefsrc.plen)
25200 +       if (rt->rt6i_prefsrc.plen && (!nxi ||
25201 +           v6_addr_in_nx_info(nxi, &rt->rt6i_prefsrc.addr, NXA_TYPE_ADDR)))
25202                 *saddr = rt->rt6i_prefsrc.addr;
25203         else
25204                 err = ipv6_dev_get_saddr(net, idev ? idev->dev : NULL,
25205 -                                        daddr, prefs, saddr);
25206 +                                        daddr, prefs, saddr, nxi);
25207         return err;
25208  }
25209  
25210 @@ -2455,7 +2458,8 @@ static int rt6_fill_node(struct net *net
25211                                 goto nla_put_failure;
25212         } else if (dst) {
25213                 struct in6_addr saddr_buf;
25214 -               if (ip6_route_get_saddr(net, rt, dst, 0, &saddr_buf) == 0 &&
25215 +               if (ip6_route_get_saddr(net, rt, dst, 0, &saddr_buf,
25216 +                   (skb->sk ? skb->sk->sk_nx_info : NULL)) == 0 &&
25217                     nla_put(skb, RTA_PREFSRC, 16, &saddr_buf))
25218                         goto nla_put_failure;
25219         }
25220 @@ -2673,6 +2677,7 @@ static int rt6_info_route(struct rt6_inf
25221         struct seq_file *m = p_arg;
25222         struct neighbour *n;
25223  
25224 +       /* FIXME: check for network context? */
25225         seq_printf(m, "%pi6 %02x ", &rt->rt6i_dst.addr, rt->rt6i_dst.plen);
25226  
25227  #ifdef CONFIG_IPV6_SUBTREES
25228 diff -NurpP --minimal linux-3.6/net/ipv6/tcp_ipv6.c linux-3.6-vs2.3.4.3-noxfs-nocow/net/ipv6/tcp_ipv6.c
25229 --- linux-3.6/net/ipv6/tcp_ipv6.c       2012-10-04 15:27:50.000000000 +0200
25230 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/net/ipv6/tcp_ipv6.c 2012-10-04 18:47:00.000000000 +0200
25231 @@ -71,6 +71,7 @@
25232  
25233  #include <linux/crypto.h>
25234  #include <linux/scatterlist.h>
25235 +#include <linux/vs_inet6.h>
25236  
25237  static void    tcp_v6_send_reset(struct sock *sk, struct sk_buff *skb);
25238  static void    tcp_v6_reqsk_send_ack(struct sock *sk, struct sk_buff *skb,
25239 @@ -175,8 +176,15 @@ static int tcp_v6_connect(struct sock *s
25240          *      connect() to INADDR_ANY means loopback (BSD'ism).
25241          */
25242  
25243 -       if(ipv6_addr_any(&usin->sin6_addr))
25244 -               usin->sin6_addr.s6_addr[15] = 0x1;
25245 +       if(ipv6_addr_any(&usin->sin6_addr)) {
25246 +               struct nx_info *nxi =  sk->sk_nx_info;
25247 +
25248 +               if (nxi && nx_info_has_v6(nxi))
25249 +                       /* FIXME: remap lback? */
25250 +                       usin->sin6_addr = nxi->v6.ip;
25251 +               else
25252 +                       usin->sin6_addr.s6_addr[15] = 0x1;
25253 +       }
25254  
25255         addr_type = ipv6_addr_type(&usin->sin6_addr);
25256  
25257 diff -NurpP --minimal linux-3.6/net/ipv6/udp.c linux-3.6-vs2.3.4.3-noxfs-nocow/net/ipv6/udp.c
25258 --- linux-3.6/net/ipv6/udp.c    2012-10-04 15:27:50.000000000 +0200
25259 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/net/ipv6/udp.c      2012-10-04 18:56:03.000000000 +0200
25260 @@ -45,42 +45,68 @@
25261  #include <net/tcp_states.h>
25262  #include <net/ip6_checksum.h>
25263  #include <net/xfrm.h>
25264 +#include <linux/vs_inet6.h>
25265  
25266  #include <linux/proc_fs.h>
25267  #include <linux/seq_file.h>
25268  #include <trace/events/skb.h>
25269  #include "udp_impl.h"
25270  
25271 -int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
25272 +int ipv6_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2)
25273  {
25274 -       const struct in6_addr *sk_rcv_saddr6 = &inet6_sk(sk)->rcv_saddr;
25275 +       const struct in6_addr *sk1_rcv_saddr6 = &inet6_sk(sk1)->rcv_saddr;
25276         const struct in6_addr *sk2_rcv_saddr6 = inet6_rcv_saddr(sk2);
25277 -       __be32 sk1_rcv_saddr = sk_rcv_saddr(sk);
25278 +       __be32 sk1_rcv_saddr = sk_rcv_saddr(sk1);
25279         __be32 sk2_rcv_saddr = sk_rcv_saddr(sk2);
25280 -       int sk_ipv6only = ipv6_only_sock(sk);
25281 +       int sk1_ipv6only = ipv6_only_sock(sk1);
25282         int sk2_ipv6only = inet_v6_ipv6only(sk2);
25283 -       int addr_type = ipv6_addr_type(sk_rcv_saddr6);
25284 +       int addr_type = ipv6_addr_type(sk1_rcv_saddr6);
25285         int addr_type2 = sk2_rcv_saddr6 ? ipv6_addr_type(sk2_rcv_saddr6) : IPV6_ADDR_MAPPED;
25286  
25287         /* if both are mapped, treat as IPv4 */
25288 -       if (addr_type == IPV6_ADDR_MAPPED && addr_type2 == IPV6_ADDR_MAPPED)
25289 -               return (!sk2_ipv6only &&
25290 +       if (addr_type == IPV6_ADDR_MAPPED && addr_type2 == IPV6_ADDR_MAPPED) {
25291 +               if (!sk2_ipv6only &&
25292                         (!sk1_rcv_saddr || !sk2_rcv_saddr ||
25293 -                         sk1_rcv_saddr == sk2_rcv_saddr));
25294 +                         sk1_rcv_saddr == sk2_rcv_saddr))
25295 +                       goto vs_v4;
25296 +               else
25297 +                       return 0;
25298 +       }
25299  
25300         if (addr_type2 == IPV6_ADDR_ANY &&
25301             !(sk2_ipv6only && addr_type == IPV6_ADDR_MAPPED))
25302 -               return 1;
25303 +               goto vs;
25304  
25305         if (addr_type == IPV6_ADDR_ANY &&
25306 -           !(sk_ipv6only && addr_type2 == IPV6_ADDR_MAPPED))
25307 -               return 1;
25308 +           !(sk1_ipv6only && addr_type2 == IPV6_ADDR_MAPPED))
25309 +               goto vs;
25310  
25311         if (sk2_rcv_saddr6 &&
25312 -           ipv6_addr_equal(sk_rcv_saddr6, sk2_rcv_saddr6))
25313 -               return 1;
25314 +           ipv6_addr_equal(sk1_rcv_saddr6, sk2_rcv_saddr6))
25315 +               goto vs;
25316  
25317         return 0;
25318 +
25319 +vs_v4:
25320 +       if (!sk1_rcv_saddr && !sk2_rcv_saddr)
25321 +               return nx_v4_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info);
25322 +       if (!sk2_rcv_saddr)
25323 +               return v4_addr_in_nx_info(sk1->sk_nx_info, sk2_rcv_saddr, -1);
25324 +       if (!sk1_rcv_saddr)
25325 +               return v4_addr_in_nx_info(sk2->sk_nx_info, sk1_rcv_saddr, -1);
25326 +       return 1;
25327 +vs:
25328 +       if (addr_type2 == IPV6_ADDR_ANY && addr_type == IPV6_ADDR_ANY)
25329 +               return nx_v6_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info);
25330 +       else if (addr_type2 == IPV6_ADDR_ANY)
25331 +               return v6_addr_in_nx_info(sk2->sk_nx_info, sk1_rcv_saddr6, -1);
25332 +       else if (addr_type == IPV6_ADDR_ANY) {
25333 +               if (addr_type2 == IPV6_ADDR_MAPPED)
25334 +                       return nx_v4_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info);
25335 +               else
25336 +                       return v6_addr_in_nx_info(sk1->sk_nx_info, sk2_rcv_saddr6, -1);
25337 +       }
25338 +       return 1;
25339  }
25340  
25341  static unsigned int udp6_portaddr_hash(struct net *net,
25342 @@ -144,6 +170,10 @@ static inline int compute_score(struct s
25343                         if (!ipv6_addr_equal(&np->rcv_saddr, daddr))
25344                                 return -1;
25345                         score++;
25346 +               } else {
25347 +                       /* block non nx_info ips */
25348 +                       if (!v6_addr_in_nx_info(sk->sk_nx_info, daddr, -1))
25349 +                               return -1;
25350                 }
25351                 if (!ipv6_addr_any(&np->daddr)) {
25352                         if (!ipv6_addr_equal(&np->daddr, saddr))
25353 diff -NurpP --minimal linux-3.6/net/ipv6/xfrm6_policy.c linux-3.6-vs2.3.4.3-noxfs-nocow/net/ipv6/xfrm6_policy.c
25354 --- linux-3.6/net/ipv6/xfrm6_policy.c   2012-10-04 15:27:50.000000000 +0200
25355 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/net/ipv6/xfrm6_policy.c     2012-10-04 18:47:00.000000000 +0200
25356 @@ -63,7 +63,7 @@ static int xfrm6_get_saddr(struct net *n
25357         dev = ip6_dst_idev(dst)->dev;
25358         ipv6_dev_get_saddr(dev_net(dev), dev,
25359                            (struct in6_addr *)&daddr->a6, 0,
25360 -                          (struct in6_addr *)&saddr->a6);
25361 +                          (struct in6_addr *)&saddr->a6, NULL);
25362         dst_release(dst);
25363         return 0;
25364  }
25365 diff -NurpP --minimal linux-3.6/net/netfilter/ipvs/ip_vs_xmit.c linux-3.6-vs2.3.4.3-noxfs-nocow/net/netfilter/ipvs/ip_vs_xmit.c
25366 --- linux-3.6/net/netfilter/ipvs/ip_vs_xmit.c   2012-10-04 15:27:50.000000000 +0200
25367 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/net/netfilter/ipvs/ip_vs_xmit.c     2012-10-04 18:47:00.000000000 +0200
25368 @@ -226,7 +226,7 @@ __ip_vs_route_output_v6(struct net *net,
25369                 return dst;
25370         if (ipv6_addr_any(&fl6.saddr) &&
25371             ipv6_dev_get_saddr(net, ip6_dst_idev(dst)->dev,
25372 -                              &fl6.daddr, 0, &fl6.saddr) < 0)
25373 +                              &fl6.daddr, 0, &fl6.saddr, NULL) < 0)
25374                 goto out_err;
25375         if (do_xfrm) {
25376                 dst = xfrm_lookup(net, dst, flowi6_to_flowi(&fl6), NULL, 0);
25377 diff -NurpP --minimal linux-3.6/net/netlink/af_netlink.c linux-3.6-vs2.3.4.3-noxfs-nocow/net/netlink/af_netlink.c
25378 --- linux-3.6/net/netlink/af_netlink.c  2012-10-04 15:27:50.000000000 +0200
25379 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/net/netlink/af_netlink.c    2012-10-04 18:47:00.000000000 +0200
25380 @@ -55,6 +55,9 @@
25381  #include <linux/types.h>
25382  #include <linux/audit.h>
25383  #include <linux/mutex.h>
25384 +#include <linux/vs_context.h>
25385 +#include <linux/vs_network.h>
25386 +#include <linux/vs_limit.h>
25387  
25388  #include <net/net_namespace.h>
25389  #include <net/sock.h>
25390 @@ -1959,6 +1962,8 @@ static struct sock *netlink_seq_socket_i
25391                         sk_for_each(s, node, &hash->table[j]) {
25392                                 if (sock_net(s) != seq_file_net(seq))
25393                                         continue;
25394 +                               if (!nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT))
25395 +                                       continue;
25396                                 if (off == pos) {
25397                                         iter->link = i;
25398                                         iter->hash_idx = j;
25399 @@ -1993,7 +1998,8 @@ static void *netlink_seq_next(struct seq
25400         s = v;
25401         do {
25402                 s = sk_next(s);
25403 -       } while (s && sock_net(s) != seq_file_net(seq));
25404 +       } while (s && (sock_net(s) != seq_file_net(seq) ||
25405 +               !nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT)));
25406         if (s)
25407                 return s;
25408  
25409 @@ -2005,7 +2011,8 @@ static void *netlink_seq_next(struct seq
25410  
25411                 for (; j <= hash->mask; j++) {
25412                         s = sk_head(&hash->table[j]);
25413 -                       while (s && sock_net(s) != seq_file_net(seq))
25414 +                       while (s && (sock_net(s) != seq_file_net(seq) ||
25415 +                               !nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT)))
25416                                 s = sk_next(s);
25417                         if (s) {
25418                                 iter->link = i;
25419 diff -NurpP --minimal linux-3.6/net/socket.c linux-3.6-vs2.3.4.3-noxfs-nocow/net/socket.c
25420 --- linux-3.6/net/socket.c      2012-10-04 15:27:51.000000000 +0200
25421 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/net/socket.c        2012-10-04 18:47:00.000000000 +0200
25422 @@ -98,6 +98,10 @@
25423  
25424  #include <net/sock.h>
25425  #include <linux/netfilter.h>
25426 +#include <linux/vs_base.h>
25427 +#include <linux/vs_socket.h>
25428 +#include <linux/vs_inet.h>
25429 +#include <linux/vs_inet6.h>
25430  
25431  #include <linux/if_tun.h>
25432  #include <linux/ipv6_route.h>
25433 @@ -552,6 +556,7 @@ static inline int __sock_sendmsg_nosec(s
25434                                        struct msghdr *msg, size_t size)
25435  {
25436         struct sock_iocb *si = kiocb_to_siocb(iocb);
25437 +       size_t len;
25438  
25439         sock_update_classid(sock->sk);
25440  
25441 @@ -560,7 +565,22 @@ static inline int __sock_sendmsg_nosec(s
25442         si->msg = msg;
25443         si->size = size;
25444  
25445 -       return sock->ops->sendmsg(iocb, sock, msg, size);
25446 +       len = sock->ops->sendmsg(iocb, sock, msg, size);
25447 +       if (sock->sk) {
25448 +               if (len == size)
25449 +                       vx_sock_send(sock->sk, size);
25450 +               else
25451 +                       vx_sock_fail(sock->sk, size);
25452 +       }
25453 +       vxdprintk(VXD_CBIT(net, 7),
25454 +               "__sock_sendmsg: %p[%p,%p,%p;%d/%d]:%d/%zu",
25455 +               sock, sock->sk,
25456 +               (sock->sk)?sock->sk->sk_nx_info:0,
25457 +               (sock->sk)?sock->sk->sk_vx_info:0,
25458 +               (sock->sk)?sock->sk->sk_xid:0,
25459 +               (sock->sk)?sock->sk->sk_nid:0,
25460 +               (unsigned int)size, len);
25461 +       return len;
25462  }
25463  
25464  static inline int __sock_sendmsg(struct kiocb *iocb, struct socket *sock,
25465 @@ -716,6 +736,7 @@ static inline int __sock_recvmsg_nosec(s
25466                                        struct msghdr *msg, size_t size, int flags)
25467  {
25468         struct sock_iocb *si = kiocb_to_siocb(iocb);
25469 +       int len;
25470  
25471         sock_update_classid(sock->sk);
25472  
25473 @@ -725,7 +746,18 @@ static inline int __sock_recvmsg_nosec(s
25474         si->size = size;
25475         si->flags = flags;
25476  
25477 -       return sock->ops->recvmsg(iocb, sock, msg, size, flags);
25478 +       len = sock->ops->recvmsg(iocb, sock, msg, size, flags);
25479 +       if ((len >= 0) && sock->sk)
25480 +               vx_sock_recv(sock->sk, len);
25481 +       vxdprintk(VXD_CBIT(net, 7),
25482 +               "__sock_recvmsg: %p[%p,%p,%p;%d/%d]:%d/%d",
25483 +               sock, sock->sk,
25484 +               (sock->sk)?sock->sk->sk_nx_info:0,
25485 +               (sock->sk)?sock->sk->sk_vx_info:0,
25486 +               (sock->sk)?sock->sk->sk_xid:0,
25487 +               (sock->sk)?sock->sk->sk_nid:0,
25488 +               (unsigned int)size, len);
25489 +       return len;
25490  }
25491  
25492  static inline int __sock_recvmsg(struct kiocb *iocb, struct socket *sock,
25493 @@ -1210,6 +1242,13 @@ int __sock_create(struct net *net, int f
25494         if (type < 0 || type >= SOCK_MAX)
25495                 return -EINVAL;
25496  
25497 +       if (!nx_check(0, VS_ADMIN)) {
25498 +               if (family == PF_INET && !current_nx_info_has_v4())
25499 +                       return -EAFNOSUPPORT;
25500 +               if (family == PF_INET6 && !current_nx_info_has_v6())
25501 +                       return -EAFNOSUPPORT;
25502 +       }
25503 +
25504         /* Compatibility.
25505  
25506            This uglymoron is moved from INET layer to here to avoid
25507 @@ -1344,6 +1383,7 @@ SYSCALL_DEFINE3(socket, int, family, int
25508         if (retval < 0)
25509                 goto out;
25510  
25511 +       set_bit(SOCK_USER_SOCKET, &sock->flags);
25512         retval = sock_map_fd(sock, flags & (O_CLOEXEC | O_NONBLOCK));
25513         if (retval < 0)
25514                 goto out_release;
25515 @@ -1385,10 +1425,12 @@ SYSCALL_DEFINE4(socketpair, int, family,
25516         err = sock_create(family, type, protocol, &sock1);
25517         if (err < 0)
25518                 goto out;
25519 +       set_bit(SOCK_USER_SOCKET, &sock1->flags);
25520  
25521         err = sock_create(family, type, protocol, &sock2);
25522         if (err < 0)
25523                 goto out_release_1;
25524 +       set_bit(SOCK_USER_SOCKET, &sock2->flags);
25525  
25526         err = sock1->ops->socketpair(sock1, sock2);
25527         if (err < 0)
25528 diff -NurpP --minimal linux-3.6/net/sunrpc/auth.c linux-3.6-vs2.3.4.3-noxfs-nocow/net/sunrpc/auth.c
25529 --- linux-3.6/net/sunrpc/auth.c 2012-10-04 15:27:51.000000000 +0200
25530 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/net/sunrpc/auth.c   2012-10-04 18:47:00.000000000 +0200
25531 @@ -15,6 +15,7 @@
25532  #include <linux/sunrpc/clnt.h>
25533  #include <linux/sunrpc/gss_api.h>
25534  #include <linux/spinlock.h>
25535 +#include <linux/vs_tag.h>
25536  
25537  #ifdef RPC_DEBUG
25538  # define RPCDBG_FACILITY       RPCDBG_AUTH
25539 @@ -481,6 +482,7 @@ rpcauth_lookupcred(struct rpc_auth *auth
25540         memset(&acred, 0, sizeof(acred));
25541         acred.uid = cred->fsuid;
25542         acred.gid = cred->fsgid;
25543 +       acred.tag = dx_current_tag();
25544         acred.group_info = get_group_info(((struct cred *)cred)->group_info);
25545  
25546         ret = auth->au_ops->lookup_cred(auth, &acred, flags);
25547 @@ -521,6 +523,7 @@ rpcauth_bind_root_cred(struct rpc_task *
25548         struct auth_cred acred = {
25549                 .uid = 0,
25550                 .gid = 0,
25551 +               .tag = dx_current_tag(),
25552         };
25553  
25554         dprintk("RPC: %5u looking up %s cred\n",
25555 diff -NurpP --minimal linux-3.6/net/sunrpc/auth_unix.c linux-3.6-vs2.3.4.3-noxfs-nocow/net/sunrpc/auth_unix.c
25556 --- linux-3.6/net/sunrpc/auth_unix.c    2012-07-22 23:39:49.000000000 +0200
25557 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/net/sunrpc/auth_unix.c      2012-10-04 18:47:00.000000000 +0200
25558 @@ -13,11 +13,13 @@
25559  #include <linux/sunrpc/clnt.h>
25560  #include <linux/sunrpc/auth.h>
25561  #include <linux/user_namespace.h>
25562 +#include <linux/vs_tag.h>
25563  
25564  #define NFS_NGROUPS    16
25565  
25566  struct unx_cred {
25567         struct rpc_cred         uc_base;
25568 +       tag_t                   uc_tag;
25569         gid_t                   uc_gid;
25570         gid_t                   uc_gids[NFS_NGROUPS];
25571  };
25572 @@ -79,6 +81,7 @@ unx_create_cred(struct rpc_auth *auth, s
25573                 groups = NFS_NGROUPS;
25574  
25575         cred->uc_gid = acred->gid;
25576 +       cred->uc_tag = acred->tag;
25577         for (i = 0; i < groups; i++) {
25578                 gid_t gid;
25579                 gid = from_kgid(&init_user_ns, GROUP_AT(acred->group_info, i));
25580 @@ -123,7 +126,9 @@ unx_match(struct auth_cred *acred, struc
25581         unsigned int i;
25582  
25583  
25584 -       if (cred->uc_uid != acred->uid || cred->uc_gid != acred->gid)
25585 +       if (cred->uc_uid != acred->uid ||
25586 +               cred->uc_gid != acred->gid ||
25587 +               cred->uc_tag != acred->tag)
25588                 return 0;
25589  
25590         if (acred->group_info != NULL)
25591 @@ -152,7 +157,7 @@ unx_marshal(struct rpc_task *task, __be3
25592         struct rpc_clnt *clnt = task->tk_client;
25593         struct unx_cred *cred = container_of(task->tk_rqstp->rq_cred, struct unx_cred, uc_base);
25594         __be32          *base, *hold;
25595 -       int             i;
25596 +       int             i, tag;
25597  
25598         *p++ = htonl(RPC_AUTH_UNIX);
25599         base = p++;
25600 @@ -162,9 +167,12 @@ unx_marshal(struct rpc_task *task, __be3
25601          * Copy the UTS nodename captured when the client was created.
25602          */
25603         p = xdr_encode_array(p, clnt->cl_nodename, clnt->cl_nodelen);
25604 +       tag = task->tk_client->cl_tag;
25605  
25606 -       *p++ = htonl((u32) cred->uc_uid);
25607 -       *p++ = htonl((u32) cred->uc_gid);
25608 +       *p++ = htonl((u32) TAGINO_UID(tag,
25609 +               cred->uc_uid, cred->uc_tag));
25610 +       *p++ = htonl((u32) TAGINO_GID(tag,
25611 +               cred->uc_gid, cred->uc_tag));
25612         hold = p++;
25613         for (i = 0; i < 16 && cred->uc_gids[i] != (gid_t) NOGROUP; i++)
25614                 *p++ = htonl((u32) cred->uc_gids[i]);
25615 diff -NurpP --minimal linux-3.6/net/sunrpc/clnt.c linux-3.6-vs2.3.4.3-noxfs-nocow/net/sunrpc/clnt.c
25616 --- linux-3.6/net/sunrpc/clnt.c 2012-10-04 15:27:51.000000000 +0200
25617 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/net/sunrpc/clnt.c   2012-10-04 18:47:00.000000000 +0200
25618 @@ -31,6 +31,7 @@
25619  #include <linux/in6.h>
25620  #include <linux/un.h>
25621  #include <linux/rcupdate.h>
25622 +#include <linux/vs_cvirt.h>
25623  
25624  #include <linux/sunrpc/clnt.h>
25625  #include <linux/sunrpc/rpc_pipe_fs.h>
25626 @@ -481,6 +482,9 @@ struct rpc_clnt *rpc_create(struct rpc_c
25627         if (!(args->flags & RPC_CLNT_CREATE_QUIET))
25628                 clnt->cl_chatty = 1;
25629  
25630 +       /* TODO: handle RPC_CLNT_CREATE_TAGGED
25631 +       if (args->flags & RPC_CLNT_CREATE_TAGGED)
25632 +               clnt->cl_tag = 1; */
25633         return clnt;
25634  }
25635  EXPORT_SYMBOL_GPL(rpc_create);
25636 diff -NurpP --minimal linux-3.6/net/unix/af_unix.c linux-3.6-vs2.3.4.3-noxfs-nocow/net/unix/af_unix.c
25637 --- linux-3.6/net/unix/af_unix.c        2012-10-04 15:27:51.000000000 +0200
25638 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/net/unix/af_unix.c  2012-10-04 18:59:36.000000000 +0200
25639 @@ -114,6 +114,8 @@
25640  #include <linux/mount.h>
25641  #include <net/checksum.h>
25642  #include <linux/security.h>
25643 +#include <linux/vs_context.h>
25644 +#include <linux/vs_limit.h>
25645  
25646  struct hlist_head unix_socket_table[2 * UNIX_HASH_SIZE];
25647  EXPORT_SYMBOL_GPL(unix_socket_table);
25648 @@ -271,6 +273,8 @@ static struct sock *__unix_find_socket_b
25649                 if (!net_eq(sock_net(s), net))
25650                         continue;
25651  
25652 +               if (!nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT))
25653 +                       continue;
25654                 if (u->addr->len == len &&
25655                     !memcmp(u->addr->name, sunname, len))
25656                         goto found;
25657 @@ -2258,6 +2262,8 @@ static struct sock *unix_from_bucket(str
25658         for (sk = sk_head(&unix_socket_table[bucket]); sk; sk = sk_next(sk)) {
25659                 if (sock_net(sk) != seq_file_net(seq))
25660                         continue;
25661 +               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
25662 +                       continue;
25663                 if (++count == offset)
25664                         break;
25665         }
25666 @@ -2275,6 +2281,8 @@ static struct sock *unix_next_socket(str
25667                 sk = sk_next(sk);
25668                 if (!sk)
25669                         goto next_bucket;
25670 +               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
25671 +                       continue;
25672                 if (sock_net(sk) == seq_file_net(seq))
25673                         return sk;
25674         }
25675 diff -NurpP --minimal linux-3.6/scripts/checksyscalls.sh linux-3.6-vs2.3.4.3-noxfs-nocow/scripts/checksyscalls.sh
25676 --- linux-3.6/scripts/checksyscalls.sh  2012-10-04 15:27:51.000000000 +0200
25677 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/scripts/checksyscalls.sh    2012-10-04 18:47:00.000000000 +0200
25678 @@ -193,7 +193,6 @@ cat << EOF
25679  #define __IGNORE_afs_syscall
25680  #define __IGNORE_getpmsg
25681  #define __IGNORE_putpmsg
25682 -#define __IGNORE_vserver
25683  EOF
25684  }
25685  
25686 diff -NurpP --minimal linux-3.6/security/commoncap.c linux-3.6-vs2.3.4.3-noxfs-nocow/security/commoncap.c
25687 --- linux-3.6/security/commoncap.c      2012-07-22 23:39:51.000000000 +0200
25688 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/security/commoncap.c        2012-10-04 18:47:00.000000000 +0200
25689 @@ -76,14 +76,20 @@ int cap_netlink_send(struct sock *sk, st
25690  int cap_capable(const struct cred *cred, struct user_namespace *targ_ns,
25691                 int cap, int audit)
25692  {
25693 +       struct vx_info *vxi = current_vx_info(); /* FIXME: get vxi from cred? */
25694 +
25695         for (;;) {
25696                 /* The owner of the user namespace has all caps. */
25697                 if (targ_ns != &init_user_ns && uid_eq(targ_ns->owner, cred->euid))
25698                         return 0;
25699  
25700                 /* Do we have the necessary capabilities? */
25701 -               if (targ_ns == cred->user_ns)
25702 -                       return cap_raised(cred->cap_effective, cap) ? 0 : -EPERM;
25703 +               if (targ_ns == cred->user_ns) {
25704 +                       if (vx_info_flags(vxi, VXF_STATE_SETUP, 0) &&
25705 +                           cap_raised(cred->cap_effective, cap))
25706 +                               return 0;
25707 +                       return vx_cap_raised(vxi, cred->cap_effective, cap) ? 0 : -EPERM;
25708 +               }
25709  
25710                 /* Have we tried all of the parent namespaces? */
25711                 if (targ_ns == &init_user_ns)
25712 @@ -619,7 +625,7 @@ int cap_inode_setxattr(struct dentry *de
25713  
25714         if (!strncmp(name, XATTR_SECURITY_PREFIX,
25715                      sizeof(XATTR_SECURITY_PREFIX) - 1) &&
25716 -           !capable(CAP_SYS_ADMIN))
25717 +               !vx_capable(CAP_SYS_ADMIN, VXC_FS_SECURITY))
25718                 return -EPERM;
25719         return 0;
25720  }
25721 @@ -645,7 +651,7 @@ int cap_inode_removexattr(struct dentry 
25722  
25723         if (!strncmp(name, XATTR_SECURITY_PREFIX,
25724                      sizeof(XATTR_SECURITY_PREFIX) - 1) &&
25725 -           !capable(CAP_SYS_ADMIN))
25726 +               !vx_capable(CAP_SYS_ADMIN, VXC_FS_SECURITY))
25727                 return -EPERM;
25728         return 0;
25729  }
25730 diff -NurpP --minimal linux-3.6/security/selinux/hooks.c linux-3.6-vs2.3.4.3-noxfs-nocow/security/selinux/hooks.c
25731 --- linux-3.6/security/selinux/hooks.c  2012-10-04 15:27:53.000000000 +0200
25732 +++ linux-3.6-vs2.3.4.3-noxfs-nocow/security/selinux/hooks.c    2012-10-04 18:47:00.000000000 +0200
25733 @@ -66,7 +66,6 @@
25734  #include <linux/dccp.h>
25735  #include <linux/quota.h>
25736  #include <linux/un.h>          /* for Unix socket types */
25737 -#include <net/af_unix.h>       /* for Unix socket types */
25738  #include <linux/parser.h>
25739  #include <linux/nfs_mount.h>
25740  #include <net/ipv6.h>
This page took 7.482759 seconds and 2 git commands to generate.