]> git.pld-linux.org Git - packages/kernel.git/blob - kernel-vserver-2.3.patch
fefd98ccca5b6a152150d61e43e5405ded5cdcfb
[packages/kernel.git] / kernel-vserver-2.3.patch
1 diff -NurpP --minimal linux-3.6.9/Documentation/vserver/debug.txt linux-3.6.9-vs2.3.4.4/Documentation/vserver/debug.txt
2 --- linux-3.6.9/Documentation/vserver/debug.txt 1970-01-01 01:00:00.000000000 +0100
3 +++ linux-3.6.9-vs2.3.4.4/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.9/arch/alpha/Kconfig linux-3.6.9-vs2.3.4.4/arch/alpha/Kconfig
160 --- linux-3.6.9/arch/alpha/Kconfig      2012-10-04 15:26:43.000000000 +0200
161 +++ linux-3.6.9-vs2.3.4.4/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.9/arch/alpha/kernel/ptrace.c linux-3.6.9-vs2.3.4.4/arch/alpha/kernel/ptrace.c
172 --- linux-3.6.9/arch/alpha/kernel/ptrace.c      2012-05-21 18:06:12.000000000 +0200
173 +++ linux-3.6.9-vs2.3.4.4/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.9/arch/alpha/kernel/systbls.S linux-3.6.9-vs2.3.4.4/arch/alpha/kernel/systbls.S
183 --- linux-3.6.9/arch/alpha/kernel/systbls.S     2012-10-04 15:26:43.000000000 +0200
184 +++ linux-3.6.9-vs2.3.4.4/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.9/arch/alpha/kernel/traps.c linux-3.6.9-vs2.3.4.4/arch/alpha/kernel/traps.c
195 --- linux-3.6.9/arch/alpha/kernel/traps.c       2012-05-21 18:06:12.000000000 +0200
196 +++ linux-3.6.9-vs2.3.4.4/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.9/arch/arm/Kconfig linux-3.6.9-vs2.3.4.4/arch/arm/Kconfig
208 --- linux-3.6.9/arch/arm/Kconfig        2012-12-08 01:34:06.000000000 +0100
209 +++ linux-3.6.9-vs2.3.4.4/arch/arm/Kconfig      2012-11-06 18:43:40.000000000 +0100
210 @@ -2341,6 +2341,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.9/arch/arm/kernel/calls.S linux-3.6.9-vs2.3.4.4/arch/arm/kernel/calls.S
220 --- linux-3.6.9/arch/arm/kernel/calls.S 2012-10-04 15:26:43.000000000 +0200
221 +++ linux-3.6.9-vs2.3.4.4/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.9/arch/arm/kernel/process.c linux-3.6.9-vs2.3.4.4/arch/arm/kernel/process.c
232 --- linux-3.6.9/arch/arm/kernel/process.c       2012-10-04 15:26:43.000000000 +0200
233 +++ linux-3.6.9-vs2.3.4.4/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.9/arch/arm/kernel/traps.c linux-3.6.9-vs2.3.4.4/arch/arm/kernel/traps.c
245 --- linux-3.6.9/arch/arm/kernel/traps.c 2012-10-04 15:26:44.000000000 +0200
246 +++ linux-3.6.9-vs2.3.4.4/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.9/arch/cris/Kconfig linux-3.6.9-vs2.3.4.4/arch/cris/Kconfig
259 --- linux-3.6.9/arch/cris/Kconfig       2012-10-04 15:26:51.000000000 +0200
260 +++ linux-3.6.9-vs2.3.4.4/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.9/arch/frv/kernel/kernel_thread.S linux-3.6.9-vs2.3.4.4/arch/frv/kernel/kernel_thread.S
271 --- linux-3.6.9/arch/frv/kernel/kernel_thread.S 2012-10-04 15:26:51.000000000 +0200
272 +++ linux-3.6.9-vs2.3.4.4/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.9/arch/h8300/Kconfig linux-3.6.9-vs2.3.4.4/arch/h8300/Kconfig
283 --- linux-3.6.9/arch/h8300/Kconfig      2012-10-04 15:26:51.000000000 +0200
284 +++ linux-3.6.9-vs2.3.4.4/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.9/arch/ia64/Kconfig linux-3.6.9-vs2.3.4.4/arch/ia64/Kconfig
295 --- linux-3.6.9/arch/ia64/Kconfig       2012-10-04 15:26:51.000000000 +0200
296 +++ linux-3.6.9-vs2.3.4.4/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.9/arch/ia64/kernel/entry.S linux-3.6.9-vs2.3.4.4/arch/ia64/kernel/entry.S
307 --- linux-3.6.9/arch/ia64/kernel/entry.S        2012-03-19 19:46:40.000000000 +0100
308 +++ linux-3.6.9-vs2.3.4.4/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.9/arch/ia64/kernel/process.c linux-3.6.9-vs2.3.4.4/arch/ia64/kernel/process.c
319 --- linux-3.6.9/arch/ia64/kernel/process.c      2012-12-08 01:34:06.000000000 +0100
320 +++ linux-3.6.9-vs2.3.4.4/arch/ia64/kernel/process.c    2012-11-06 18:43:40.000000000 +0100
321 @@ -111,8 +111,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.9/arch/ia64/kernel/ptrace.c linux-3.6.9-vs2.3.4.4/arch/ia64/kernel/ptrace.c
333 --- linux-3.6.9/arch/ia64/kernel/ptrace.c       2012-05-21 18:06:26.000000000 +0200
334 +++ linux-3.6.9-vs2.3.4.4/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.9/arch/ia64/kernel/traps.c linux-3.6.9-vs2.3.4.4/arch/ia64/kernel/traps.c
344 --- linux-3.6.9/arch/ia64/kernel/traps.c        2012-05-21 18:06:26.000000000 +0200
345 +++ linux-3.6.9-vs2.3.4.4/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.9/arch/m32r/kernel/traps.c linux-3.6.9-vs2.3.4.4/arch/m32r/kernel/traps.c
371 --- linux-3.6.9/arch/m32r/kernel/traps.c        2012-05-21 18:06:26.000000000 +0200
372 +++ linux-3.6.9-vs2.3.4.4/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.9/arch/m68k/Kconfig linux-3.6.9-vs2.3.4.4/arch/m68k/Kconfig
386 --- linux-3.6.9/arch/m68k/Kconfig       2012-10-04 15:26:51.000000000 +0200
387 +++ linux-3.6.9-vs2.3.4.4/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.9/arch/mips/Kconfig linux-3.6.9-vs2.3.4.4/arch/mips/Kconfig
398 --- linux-3.6.9/arch/mips/Kconfig       2012-10-04 15:26:52.000000000 +0200
399 +++ linux-3.6.9-vs2.3.4.4/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.9/arch/mips/kernel/ptrace.c linux-3.6.9-vs2.3.4.4/arch/mips/kernel/ptrace.c
410 --- linux-3.6.9/arch/mips/kernel/ptrace.c       2012-07-22 23:38:52.000000000 +0200
411 +++ linux-3.6.9-vs2.3.4.4/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.9/arch/mips/kernel/scall32-o32.S linux-3.6.9-vs2.3.4.4/arch/mips/kernel/scall32-o32.S
431 --- linux-3.6.9/arch/mips/kernel/scall32-o32.S  2012-01-09 16:14:05.000000000 +0100
432 +++ linux-3.6.9-vs2.3.4.4/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.9/arch/mips/kernel/scall64-64.S linux-3.6.9-vs2.3.4.4/arch/mips/kernel/scall64-64.S
443 --- linux-3.6.9/arch/mips/kernel/scall64-64.S   2012-01-09 16:14:05.000000000 +0100
444 +++ linux-3.6.9-vs2.3.4.4/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.9/arch/mips/kernel/scall64-n32.S linux-3.6.9-vs2.3.4.4/arch/mips/kernel/scall64-n32.S
455 --- linux-3.6.9/arch/mips/kernel/scall64-n32.S  2012-01-09 16:14:05.000000000 +0100
456 +++ linux-3.6.9-vs2.3.4.4/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.9/arch/mips/kernel/scall64-o32.S linux-3.6.9-vs2.3.4.4/arch/mips/kernel/scall64-o32.S
467 --- linux-3.6.9/arch/mips/kernel/scall64-o32.S  2012-01-09 16:14:05.000000000 +0100
468 +++ linux-3.6.9-vs2.3.4.4/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.9/arch/mips/kernel/traps.c linux-3.6.9-vs2.3.4.4/arch/mips/kernel/traps.c
479 --- linux-3.6.9/arch/mips/kernel/traps.c        2012-10-04 15:26:53.000000000 +0200
480 +++ linux-3.6.9-vs2.3.4.4/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.9/arch/parisc/Kconfig linux-3.6.9-vs2.3.4.4/arch/parisc/Kconfig
496 --- linux-3.6.9/arch/parisc/Kconfig     2012-07-22 23:38:52.000000000 +0200
497 +++ linux-3.6.9-vs2.3.4.4/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.9/arch/parisc/kernel/syscall_table.S linux-3.6.9-vs2.3.4.4/arch/parisc/kernel/syscall_table.S
508 --- linux-3.6.9/arch/parisc/kernel/syscall_table.S      2011-10-24 18:45:00.000000000 +0200
509 +++ linux-3.6.9-vs2.3.4.4/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.9/arch/parisc/kernel/traps.c linux-3.6.9-vs2.3.4.4/arch/parisc/kernel/traps.c
520 --- linux-3.6.9/arch/parisc/kernel/traps.c      2012-05-21 18:06:28.000000000 +0200
521 +++ linux-3.6.9-vs2.3.4.4/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.9/arch/parisc/mm/fault.c linux-3.6.9-vs2.3.4.4/arch/parisc/mm/fault.c
546 --- linux-3.6.9/arch/parisc/mm/fault.c  2010-08-02 16:52:06.000000000 +0200
547 +++ linux-3.6.9-vs2.3.4.4/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.9/arch/powerpc/Kconfig linux-3.6.9-vs2.3.4.4/arch/powerpc/Kconfig
561 --- linux-3.6.9/arch/powerpc/Kconfig    2012-10-04 15:26:53.000000000 +0200
562 +++ linux-3.6.9-vs2.3.4.4/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.9/arch/powerpc/include/asm/unistd.h linux-3.6.9-vs2.3.4.4/arch/powerpc/include/asm/unistd.h
573 --- linux-3.6.9/arch/powerpc/include/asm/unistd.h       2012-10-04 15:26:53.000000000 +0200
574 +++ linux-3.6.9-vs2.3.4.4/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.9/arch/powerpc/kernel/process.c linux-3.6.9-vs2.3.4.4/arch/powerpc/kernel/process.c
585 --- linux-3.6.9/arch/powerpc/kernel/process.c   2012-10-04 15:26:54.000000000 +0200
586 +++ linux-3.6.9-vs2.3.4.4/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.9/arch/powerpc/kernel/traps.c linux-3.6.9-vs2.3.4.4/arch/powerpc/kernel/traps.c
600 --- linux-3.6.9/arch/powerpc/kernel/traps.c     2012-10-04 15:26:54.000000000 +0200
601 +++ linux-3.6.9-vs2.3.4.4/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.9/arch/s390/Kconfig linux-3.6.9-vs2.3.4.4/arch/s390/Kconfig
615 --- linux-3.6.9/arch/s390/Kconfig       2012-10-04 15:26:54.000000000 +0200
616 +++ linux-3.6.9-vs2.3.4.4/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.9/arch/s390/include/asm/tlb.h linux-3.6.9-vs2.3.4.4/arch/s390/include/asm/tlb.h
627 --- linux-3.6.9/arch/s390/include/asm/tlb.h     2012-07-22 23:38:59.000000000 +0200
628 +++ linux-3.6.9-vs2.3.4.4/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.9/arch/s390/include/asm/unistd.h linux-3.6.9-vs2.3.4.4/arch/s390/include/asm/unistd.h
638 --- linux-3.6.9/arch/s390/include/asm/unistd.h  2012-10-04 15:26:55.000000000 +0200
639 +++ linux-3.6.9-vs2.3.4.4/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.9/arch/s390/kernel/ptrace.c linux-3.6.9-vs2.3.4.4/arch/s390/kernel/ptrace.c
650 --- linux-3.6.9/arch/s390/kernel/ptrace.c       2012-10-04 15:26:55.000000000 +0200
651 +++ linux-3.6.9-vs2.3.4.4/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.9/arch/s390/kernel/syscalls.S linux-3.6.9-vs2.3.4.4/arch/s390/kernel/syscalls.S
661 --- linux-3.6.9/arch/s390/kernel/syscalls.S     2012-01-09 16:14:06.000000000 +0100
662 +++ linux-3.6.9-vs2.3.4.4/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.9/arch/sh/Kconfig linux-3.6.9-vs2.3.4.4/arch/sh/Kconfig
673 --- linux-3.6.9/arch/sh/Kconfig 2012-10-04 15:26:55.000000000 +0200
674 +++ linux-3.6.9-vs2.3.4.4/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.9/arch/sh/kernel/irq.c linux-3.6.9-vs2.3.4.4/arch/sh/kernel/irq.c
685 --- linux-3.6.9/arch/sh/kernel/irq.c    2012-10-04 15:26:56.000000000 +0200
686 +++ linux-3.6.9-vs2.3.4.4/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.9/arch/sparc/Kconfig linux-3.6.9-vs2.3.4.4/arch/sparc/Kconfig
696 --- linux-3.6.9/arch/sparc/Kconfig      2012-10-04 15:26:58.000000000 +0200
697 +++ linux-3.6.9-vs2.3.4.4/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.9/arch/sparc/include/asm/unistd.h linux-3.6.9-vs2.3.4.4/arch/sparc/include/asm/unistd.h
708 --- linux-3.6.9/arch/sparc/include/asm/unistd.h 2012-10-04 15:26:59.000000000 +0200
709 +++ linux-3.6.9-vs2.3.4.4/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.9/arch/sparc/kernel/systbls_32.S linux-3.6.9-vs2.3.4.4/arch/sparc/kernel/systbls_32.S
720 --- linux-3.6.9/arch/sparc/kernel/systbls_32.S  2012-01-09 16:14:09.000000000 +0100
721 +++ linux-3.6.9-vs2.3.4.4/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.9/arch/sparc/kernel/systbls_64.S linux-3.6.9-vs2.3.4.4/arch/sparc/kernel/systbls_64.S
732 --- linux-3.6.9/arch/sparc/kernel/systbls_64.S  2012-07-22 23:39:00.000000000 +0200
733 +++ linux-3.6.9-vs2.3.4.4/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.9/arch/um/Kconfig.rest linux-3.6.9-vs2.3.4.4/arch/um/Kconfig.rest
753 --- linux-3.6.9/arch/um/Kconfig.rest    2012-01-09 16:14:09.000000000 +0100
754 +++ linux-3.6.9-vs2.3.4.4/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.9/arch/um/include/shared/kern_constants.h linux-3.6.9-vs2.3.4.4/arch/um/include/shared/kern_constants.h
765 --- linux-3.6.9/arch/um/include/shared/kern_constants.h 1970-01-01 01:00:00.000000000 +0100
766 +++ linux-3.6.9-vs2.3.4.4/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.9/arch/um/include/shared/user_constants.h linux-3.6.9-vs2.3.4.4/arch/um/include/shared/user_constants.h
770 --- linux-3.6.9/arch/um/include/shared/user_constants.h 1970-01-01 01:00:00.000000000 +0100
771 +++ linux-3.6.9-vs2.3.4.4/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.9/arch/x86/Kconfig linux-3.6.9-vs2.3.4.4/arch/x86/Kconfig
814 --- linux-3.6.9/arch/x86/Kconfig        2012-10-04 15:27:00.000000000 +0200
815 +++ linux-3.6.9-vs2.3.4.4/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.9/arch/x86/syscalls/syscall_32.tbl linux-3.6.9-vs2.3.4.4/arch/x86/syscalls/syscall_32.tbl
826 --- linux-3.6.9/arch/x86/syscalls/syscall_32.tbl        2012-07-22 23:39:02.000000000 +0200
827 +++ linux-3.6.9-vs2.3.4.4/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.9/arch/x86/syscalls/syscall_64.tbl linux-3.6.9-vs2.3.4.4/arch/x86/syscalls/syscall_64.tbl
838 --- linux-3.6.9/arch/x86/syscalls/syscall_64.tbl        2012-10-04 15:27:01.000000000 +0200
839 +++ linux-3.6.9-vs2.3.4.4/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.9/drivers/block/Kconfig linux-3.6.9-vs2.3.4.4/drivers/block/Kconfig
850 --- linux-3.6.9/drivers/block/Kconfig   2012-05-21 18:06:43.000000000 +0200
851 +++ linux-3.6.9-vs2.3.4.4/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.9/drivers/block/Makefile linux-3.6.9-vs2.3.4.4/drivers/block/Makefile
867 --- linux-3.6.9/drivers/block/Makefile  2012-03-19 19:46:52.000000000 +0100
868 +++ linux-3.6.9-vs2.3.4.4/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.9/drivers/block/loop.c linux-3.6.9-vs2.3.4.4/drivers/block/loop.c
878 --- linux-3.6.9/drivers/block/loop.c    2012-07-22 23:39:02.000000000 +0200
879 +++ linux-3.6.9-vs2.3.4.4/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.9/drivers/block/vroot.c linux-3.6.9-vs2.3.4.4/drivers/block/vroot.c
936 --- linux-3.6.9/drivers/block/vroot.c   1970-01-01 01:00:00.000000000 +0100
937 +++ linux-3.6.9-vs2.3.4.4/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.9/drivers/infiniband/Kconfig linux-3.6.9-vs2.3.4.4/drivers/infiniband/Kconfig
1231 --- linux-3.6.9/drivers/infiniband/Kconfig      2012-07-22 23:39:06.000000000 +0200
1232 +++ linux-3.6.9-vs2.3.4.4/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.9/drivers/infiniband/core/addr.c linux-3.6.9-vs2.3.4.4/drivers/infiniband/core/addr.c
1243 --- linux-3.6.9/drivers/infiniband/core/addr.c  2012-10-04 15:27:10.000000000 +0200
1244 +++ linux-3.6.9-vs2.3.4.4/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.9/drivers/md/dm-ioctl.c linux-3.6.9-vs2.3.4.4/drivers/md/dm-ioctl.c
1255 --- linux-3.6.9/drivers/md/dm-ioctl.c   2012-10-04 15:27:11.000000000 +0200
1256 +++ linux-3.6.9-vs2.3.4.4/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.9/drivers/md/dm.c linux-3.6.9-vs2.3.4.4/drivers/md/dm.c
1343 --- linux-3.6.9/drivers/md/dm.c 2012-12-08 01:34:09.000000000 +0100
1344 +++ linux-3.6.9-vs2.3.4.4/drivers/md/dm.c       2012-12-08 01:36:32.000000000 +0100
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 @@ -1898,6 +1910,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.9/drivers/md/dm.h linux-3.6.9-vs2.3.4.4/drivers/md/dm.h
1419 --- linux-3.6.9/drivers/md/dm.h 2012-10-04 15:27:11.000000000 +0200
1420 +++ linux-3.6.9-vs2.3.4.4/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.9/drivers/net/tun.c linux-3.6.9-vs2.3.4.4/drivers/net/tun.c
1431 --- linux-3.6.9/drivers/net/tun.c       2012-10-04 15:27:20.000000000 +0200
1432 +++ linux-3.6.9-vs2.3.4.4/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.9/drivers/tty/sysrq.c linux-3.6.9-vs2.3.4.4/drivers/tty/sysrq.c
1503 --- linux-3.6.9/drivers/tty/sysrq.c     2012-05-21 18:07:16.000000000 +0200
1504 +++ linux-3.6.9-vs2.3.4.4/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.9/drivers/tty/tty_io.c linux-3.6.9-vs2.3.4.4/drivers/tty/tty_io.c
1557 --- linux-3.6.9/drivers/tty/tty_io.c    2012-07-22 23:39:32.000000000 +0200
1558 +++ linux-3.6.9-vs2.3.4.4/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.9/fs/attr.c linux-3.6.9-vs2.3.4.4/fs/attr.c
1586 --- linux-3.6.9/fs/attr.c       2012-10-04 15:27:39.000000000 +0200
1587 +++ linux-3.6.9-vs2.3.4.4/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.9/fs/block_dev.c linux-3.6.9-vs2.3.4.4/fs/block_dev.c
1629 --- linux-3.6.9/fs/block_dev.c  2012-10-04 15:27:39.000000000 +0200
1630 +++ linux-3.6.9-vs2.3.4.4/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.9/fs/btrfs/ctree.h linux-3.6.9-vs2.3.4.4/fs/btrfs/ctree.h
1669 --- linux-3.6.9/fs/btrfs/ctree.h        2012-10-04 15:27:39.000000000 +0200
1670 +++ linux-3.6.9-vs2.3.4.4/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.9/fs/btrfs/disk-io.c linux-3.6.9-vs2.3.4.4/fs/btrfs/disk-io.c
1724 --- linux-3.6.9/fs/btrfs/disk-io.c      2012-10-04 15:27:39.000000000 +0200
1725 +++ linux-3.6.9-vs2.3.4.4/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.9/fs/btrfs/inode.c linux-3.6.9-vs2.3.4.4/fs/btrfs/inode.c
1737 --- linux-3.6.9/fs/btrfs/inode.c        2012-10-04 15:27:39.000000000 +0200
1738 +++ linux-3.6.9-vs2.3.4.4/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.9/fs/btrfs/ioctl.c linux-3.6.9-vs2.3.4.4/fs/btrfs/ioctl.c
1804 --- linux-3.6.9/fs/btrfs/ioctl.c        2012-10-04 15:27:39.000000000 +0200
1805 +++ linux-3.6.9-vs2.3.4.4/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.9/fs/btrfs/super.c linux-3.6.9-vs2.3.4.4/fs/btrfs/super.c
1978 --- linux-3.6.9/fs/btrfs/super.c        2012-10-04 15:27:39.000000000 +0200
1979 +++ linux-3.6.9-vs2.3.4.4/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.9/fs/char_dev.c linux-3.6.9-vs2.3.4.4/fs/char_dev.c
2036 --- linux-3.6.9/fs/char_dev.c   2012-03-19 19:47:25.000000000 +0100
2037 +++ linux-3.6.9-vs2.3.4.4/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.9/fs/dcache.c linux-3.6.9-vs2.3.4.4/fs/dcache.c
2071 --- linux-3.6.9/fs/dcache.c     2012-10-04 15:27:39.000000000 +0200
2072 +++ linux-3.6.9-vs2.3.4.4/fs/dcache.c   2012-12-07 22:49:54.000000000 +0100
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.9/fs/devpts/inode.c linux-3.6.9-vs2.3.4.4/fs/devpts/inode.c
2125 --- linux-3.6.9/fs/devpts/inode.c       2012-10-04 15:27:39.000000000 +0200
2126 +++ linux-3.6.9-vs2.3.4.4/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 = (vs_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 = (vs_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.9/fs/ext2/balloc.c linux-3.6.9-vs2.3.4.4/fs/ext2/balloc.c
2215 --- linux-3.6.9/fs/ext2/balloc.c        2012-10-04 15:27:39.000000000 +0200
2216 +++ linux-3.6.9-vs2.3.4.4/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.9/fs/ext2/ext2.h linux-3.6.9-vs2.3.4.4/fs/ext2/ext2.h
2226 --- linux-3.6.9/fs/ext2/ext2.h  2012-07-22 23:39:39.000000000 +0200
2227 +++ linux-3.6.9-vs2.3.4.4/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.9/fs/ext2/file.c linux-3.6.9-vs2.3.4.4/fs/ext2/file.c
2276 --- linux-3.6.9/fs/ext2/file.c  2011-10-24 18:45:27.000000000 +0200
2277 +++ linux-3.6.9-vs2.3.4.4/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.9/fs/ext2/ialloc.c linux-3.6.9-vs2.3.4.4/fs/ext2/ialloc.c
2285 --- linux-3.6.9/fs/ext2/ialloc.c        2012-10-04 15:27:39.000000000 +0200
2286 +++ linux-3.6.9-vs2.3.4.4/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.9/fs/ext2/inode.c linux-3.6.9-vs2.3.4.4/fs/ext2/inode.c
2304 --- linux-3.6.9/fs/ext2/inode.c 2012-10-04 15:27:39.000000000 +0200
2305 +++ linux-3.6.9-vs2.3.4.4/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.9/fs/ext2/ioctl.c linux-3.6.9-vs2.3.4.4/fs/ext2/ioctl.c
2437 --- linux-3.6.9/fs/ext2/ioctl.c 2012-03-19 19:47:25.000000000 +0100
2438 +++ linux-3.6.9-vs2.3.4.4/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.9/fs/ext2/namei.c linux-3.6.9-vs2.3.4.4/fs/ext2/namei.c
2489 --- linux-3.6.9/fs/ext2/namei.c 2012-10-04 15:27:39.000000000 +0200
2490 +++ linux-3.6.9-vs2.3.4.4/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.9/fs/ext2/super.c linux-3.6.9-vs2.3.4.4/fs/ext2/super.c
2516 --- linux-3.6.9/fs/ext2/super.c 2012-10-04 15:27:39.000000000 +0200
2517 +++ linux-3.6.9-vs2.3.4.4/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.9/fs/ext3/ext3.h linux-3.6.9-vs2.3.4.4/fs/ext3/ext3.h
2584 --- linux-3.6.9/fs/ext3/ext3.h  2012-07-22 23:39:39.000000000 +0200
2585 +++ linux-3.6.9-vs2.3.4.4/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.9/fs/ext3/file.c linux-3.6.9-vs2.3.4.4/fs/ext3/file.c
2638 --- linux-3.6.9/fs/ext3/file.c  2012-05-21 18:07:20.000000000 +0200
2639 +++ linux-3.6.9-vs2.3.4.4/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.9/fs/ext3/ialloc.c linux-3.6.9-vs2.3.4.4/fs/ext3/ialloc.c
2648 --- linux-3.6.9/fs/ext3/ialloc.c        2012-07-22 23:39:39.000000000 +0200
2649 +++ linux-3.6.9-vs2.3.4.4/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.9/fs/ext3/inode.c linux-3.6.9-vs2.3.4.4/fs/ext3/inode.c
2667 --- linux-3.6.9/fs/ext3/inode.c 2012-10-04 15:27:39.000000000 +0200
2668 +++ linux-3.6.9-vs2.3.4.4/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.9/fs/ext3/ioctl.c linux-3.6.9-vs2.3.4.4/fs/ext3/ioctl.c
2800 --- linux-3.6.9/fs/ext3/ioctl.c 2012-05-21 18:07:20.000000000 +0200
2801 +++ linux-3.6.9-vs2.3.4.4/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.9/fs/ext3/namei.c linux-3.6.9-vs2.3.4.4/fs/ext3/namei.c
2870 --- linux-3.6.9/fs/ext3/namei.c 2012-10-04 15:27:39.000000000 +0200
2871 +++ linux-3.6.9-vs2.3.4.4/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.9/fs/ext3/super.c linux-3.6.9-vs2.3.4.4/fs/ext3/super.c
2898 --- linux-3.6.9/fs/ext3/super.c 2012-10-04 15:27:39.000000000 +0200
2899 +++ linux-3.6.9-vs2.3.4.4/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.9/fs/ext4/ext4.h linux-3.6.9-vs2.3.4.4/fs/ext4/ext4.h
2967 --- linux-3.6.9/fs/ext4/ext4.h  2012-12-08 01:34:13.000000000 +0100
2968 +++ linux-3.6.9-vs2.3.4.4/fs/ext4/ext4.h        2012-12-08 01:36:33.000000000 +0100
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 @@ -2392,6 +2398,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.9/fs/ext4/file.c linux-3.6.9-vs2.3.4.4/fs/ext4/file.c
3016 --- linux-3.6.9/fs/ext4/file.c  2012-10-04 15:27:39.000000000 +0200
3017 +++ linux-3.6.9-vs2.3.4.4/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.9/fs/ext4/ialloc.c linux-3.6.9-vs2.3.4.4/fs/ext4/ialloc.c
3026 --- linux-3.6.9/fs/ext4/ialloc.c        2012-12-08 01:34:13.000000000 +0100
3027 +++ linux-3.6.9-vs2.3.4.4/fs/ext4/ialloc.c      2012-11-06 18:43:41.000000000 +0100
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 @@ -839,6 +840,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.9/fs/ext4/inode.c linux-3.6.9-vs2.3.4.4/fs/ext4/inode.c
3045 --- linux-3.6.9/fs/ext4/inode.c 2012-12-08 01:34:13.000000000 +0100
3046 +++ linux-3.6.9-vs2.3.4.4/fs/ext4/inode.c       2012-11-06 18:43:41.000000000 +0100
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 @@ -3715,41 +3716,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 @@ -3841,8 +3865,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 @@ -4066,8 +4092,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 @@ -4090,6 +4116,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 @@ -4278,7 +4307,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 @@ -4300,6 +4330,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.9/fs/ext4/ioctl.c linux-3.6.9-vs2.3.4.4/fs/ext4/ioctl.c
3181 --- linux-3.6.9/fs/ext4/ioctl.c 2012-10-04 15:27:39.000000000 +0200
3182 +++ linux-3.6.9-vs2.3.4.4/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.9/fs/ext4/namei.c linux-3.6.9-vs2.3.4.4/fs/ext4/namei.c
3248 --- linux-3.6.9/fs/ext4/namei.c 2012-12-08 01:34:13.000000000 +0100
3249 +++ linux-3.6.9-vs2.3.4.4/fs/ext4/namei.c       2012-11-06 18:43:41.000000000 +0100
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 @@ -2982,6 +2984,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.9/fs/ext4/super.c linux-3.6.9-vs2.3.4.4/fs/ext4/super.c
3275 --- linux-3.6.9/fs/ext4/super.c 2012-12-08 01:34:13.000000000 +0100
3276 +++ linux-3.6.9-vs2.3.4.4/fs/ext4/super.c       2012-12-08 01:36:33.000000000 +0100
3277 @@ -1220,6 +1220,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 @@ -1298,6 +1299,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 @@ -1544,6 +1548,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 @@ -3418,6 +3436,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 @@ -4583,6 +4604,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.9/fs/fcntl.c linux-3.6.9-vs2.3.4.4/fs/fcntl.c
3342 --- linux-3.6.9/fs/fcntl.c      2012-10-04 15:27:39.000000000 +0200
3343 +++ linux-3.6.9-vs2.3.4.4/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.9/fs/file.c linux-3.6.9-vs2.3.4.4/fs/file.c
3371 --- linux-3.6.9/fs/file.c       2012-05-21 18:07:20.000000000 +0200
3372 +++ linux-3.6.9-vs2.3.4.4/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.9/fs/file_table.c linux-3.6.9-vs2.3.4.4/fs/file_table.c
3399 --- linux-3.6.9/fs/file_table.c 2012-10-04 15:27:39.000000000 +0200
3400 +++ linux-3.6.9-vs2.3.4.4/fs/file_table.c       2012-11-17 14:36:19.000000000 +0100
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.9/fs/fs_struct.c linux-3.6.9-vs2.3.4.4/fs/fs_struct.c
3438 --- linux-3.6.9/fs/fs_struct.c  2012-10-04 15:27:39.000000000 +0200
3439 +++ linux-3.6.9-vs2.3.4.4/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.9/fs/gfs2/file.c linux-3.6.9-vs2.3.4.4/fs/gfs2/file.c
3465 --- linux-3.6.9/fs/gfs2/file.c  2012-12-08 01:34:13.000000000 +0100
3466 +++ linux-3.6.9-vs2.3.4.4/fs/gfs2/file.c        2012-12-08 01:36:33.000000000 +0100
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.9/fs/gfs2/inode.h linux-3.6.9-vs2.3.4.4/fs/gfs2/inode.h
3590 --- linux-3.6.9/fs/gfs2/inode.h 2012-07-22 23:39:40.000000000 +0200
3591 +++ linux-3.6.9-vs2.3.4.4/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.9/fs/inode.c linux-3.6.9-vs2.3.4.4/fs/inode.c
3601 --- linux-3.6.9/fs/inode.c      2012-12-08 01:34:13.000000000 +0100
3602 +++ linux-3.6.9-vs2.3.4.4/fs/inode.c    2012-12-08 01:36:33.000000000 +0100
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 @@ -483,6 +488,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 @@ -1804,9 +1811,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 @@ -1835,6 +1844,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.9/fs/ioctl.c linux-3.6.9-vs2.3.4.4/fs/ioctl.c
3659 --- linux-3.6.9/fs/ioctl.c      2012-05-21 18:07:24.000000000 +0200
3660 +++ linux-3.6.9-vs2.3.4.4/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.9/fs/ioprio.c linux-3.6.9-vs2.3.4.4/fs/ioprio.c
3672 --- linux-3.6.9/fs/ioprio.c     2012-07-22 23:39:40.000000000 +0200
3673 +++ linux-3.6.9-vs2.3.4.4/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.9/fs/jfs/file.c linux-3.6.9-vs2.3.4.4/fs/jfs/file.c
3701 --- linux-3.6.9/fs/jfs/file.c   2011-10-24 18:45:27.000000000 +0200
3702 +++ linux-3.6.9-vs2.3.4.4/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.9/fs/jfs/ioctl.c linux-3.6.9-vs2.3.4.4/fs/jfs/ioctl.c
3722 --- linux-3.6.9/fs/jfs/ioctl.c  2012-03-19 19:47:25.000000000 +0100
3723 +++ linux-3.6.9-vs2.3.4.4/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.9/fs/jfs/jfs_dinode.h linux-3.6.9-vs2.3.4.4/fs/jfs/jfs_dinode.h
3782 --- linux-3.6.9/fs/jfs/jfs_dinode.h     2008-12-25 00:26:37.000000000 +0100
3783 +++ linux-3.6.9-vs2.3.4.4/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.9/fs/jfs/jfs_filsys.h linux-3.6.9-vs2.3.4.4/fs/jfs/jfs_filsys.h
3801 --- linux-3.6.9/fs/jfs/jfs_filsys.h     2008-12-25 00:26:37.000000000 +0100
3802 +++ linux-3.6.9-vs2.3.4.4/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.9/fs/jfs/jfs_imap.c linux-3.6.9-vs2.3.4.4/fs/jfs/jfs_imap.c
3812 --- linux-3.6.9/fs/jfs/jfs_imap.c       2012-01-09 16:14:54.000000000 +0100
3813 +++ linux-3.6.9-vs2.3.4.4/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.9/fs/jfs/jfs_inode.c linux-3.6.9-vs2.3.4.4/fs/jfs/jfs_inode.c
3874 --- linux-3.6.9/fs/jfs/jfs_inode.c      2012-01-09 16:14:54.000000000 +0100
3875 +++ linux-3.6.9-vs2.3.4.4/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.9/fs/jfs/jfs_inode.h linux-3.6.9-vs2.3.4.4/fs/jfs/jfs_inode.h
3950 --- linux-3.6.9/fs/jfs/jfs_inode.h      2011-10-24 18:45:27.000000000 +0200
3951 +++ linux-3.6.9-vs2.3.4.4/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.9/fs/jfs/namei.c linux-3.6.9-vs2.3.4.4/fs/jfs/namei.c
3961 --- linux-3.6.9/fs/jfs/namei.c  2012-10-04 15:27:40.000000000 +0200
3962 +++ linux-3.6.9-vs2.3.4.4/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.9/fs/jfs/super.c linux-3.6.9-vs2.3.4.4/fs/jfs/super.c
3988 --- linux-3.6.9/fs/jfs/super.c  2012-10-04 15:27:40.000000000 +0200
3989 +++ linux-3.6.9-vs2.3.4.4/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.9/fs/libfs.c linux-3.6.9-vs2.3.4.4/fs/libfs.c
4056 --- linux-3.6.9/fs/libfs.c      2012-10-04 15:27:40.000000000 +0200
4057 +++ linux-3.6.9-vs2.3.4.4/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.9/fs/locks.c linux-3.6.9-vs2.3.4.4/fs/locks.c
4104 --- linux-3.6.9/fs/locks.c      2012-10-04 15:27:40.000000000 +0200
4105 +++ linux-3.6.9-vs2.3.4.4/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.9/fs/mount.h linux-3.6.9-vs2.3.4.4/fs/mount.h
4304 --- linux-3.6.9/fs/mount.h      2012-10-04 15:27:40.000000000 +0200
4305 +++ linux-3.6.9-vs2.3.4.4/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 +       vs_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.9/fs/namei.c linux-3.6.9-vs2.3.4.4/fs/namei.c
4315 --- linux-3.6.9/fs/namei.c      2012-12-08 01:34:14.000000000 +0100
4316 +++ linux-3.6.9-vs2.3.4.4/fs/namei.c    2012-12-08 01:08:53.000000000 +0100
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,16 @@ 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 (error == -EMLINK) {
4554 +               if (nd->root.mnt && !(nd->flags & LOOKUP_ROOT))
4555 +                       path_put(&nd->root);
4556 +               if (base)
4557 +                       fput(base);
4558 +               goto restart;
4559 +       }
4560 +#endif
4561  out:
4562         if (nd->root.mnt && !(nd->flags & LOOKUP_ROOT))
4563                 path_put(&nd->root);
4564 @@ -3023,6 +3160,11 @@ struct dentry *kern_path_create(int dfd,
4565                 goto fail;
4566         }
4567         *path = nd.path;
4568 +       vxdprintk(VXD_CBIT(misc, 3), "kern_path_create path.dentry = %p (%.*s), dentry = %p (%.*s), d_inode = %p",
4569 +               path->dentry, path->dentry->d_name.len,
4570 +               path->dentry->d_name.name, dentry,
4571 +               dentry->d_name.len, dentry->d_name.name,
4572 +               path->dentry->d_inode);
4573         return dentry;
4574  fail:
4575         dput(dentry);
4576 @@ -3489,7 +3631,7 @@ int vfs_link(struct dentry *old_dentry, 
4577         /*
4578          * A link to an append-only or immutable file cannot be created.
4579          */
4580 -       if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
4581 +       if (IS_APPEND(inode) || IS_IXORUNLINK(inode))
4582                 return -EPERM;
4583         if (!dir->i_op->link)
4584                 return -EPERM;
4585 @@ -3874,6 +4016,275 @@ int vfs_follow_link(struct nameidata *nd
4586         return __vfs_follow_link(nd, link);
4587  }
4588  
4589 +
4590 +#ifdef CONFIG_VSERVER_COWBL
4591 +
4592 +static inline
4593 +long do_cow_splice(struct file *in, struct file *out, size_t len)
4594 +{
4595 +       loff_t ppos = 0;
4596 +
4597 +       return do_splice_direct(in, &ppos, out, len, 0);
4598 +}
4599 +
4600 +struct dentry *cow_break_link(const char *pathname)
4601 +{
4602 +       int ret, mode, pathlen, redo = 0;
4603 +       struct nameidata old_nd, dir_nd;
4604 +       struct path dir_path, *old_path, *new_path;
4605 +       struct dentry *dir, *old_dentry, *new_dentry = NULL;
4606 +       struct file *old_file;
4607 +       struct file *new_file;
4608 +       char *to, *path, pad='\251';
4609 +       loff_t size;
4610 +
4611 +       vxdprintk(VXD_CBIT(misc, 1),
4612 +               "cow_break_link(" VS_Q("%s") ")", pathname);
4613 +
4614 +       path = kmalloc(PATH_MAX, GFP_KERNEL);
4615 +       ret = -ENOMEM;
4616 +       if (!path)
4617 +               goto out;
4618 +
4619 +       /* old_nd.path will have refs to dentry and mnt */
4620 +       ret = do_path_lookup(AT_FDCWD, pathname, LOOKUP_FOLLOW, &old_nd);
4621 +       vxdprintk(VXD_CBIT(misc, 2),
4622 +               "do_path_lookup(old): %d", ret);
4623 +       if (ret < 0)
4624 +               goto out_free_path;
4625 +
4626 +       /* dentry/mnt refs handed over to old_path */
4627 +       old_path = &old_nd.path;
4628 +       /* no explicit reference for old_dentry here */
4629 +       old_dentry = old_path->dentry;
4630 +
4631 +       mode = old_dentry->d_inode->i_mode;
4632 +       to = d_path(old_path, path, PATH_MAX-2);
4633 +       pathlen = strlen(to);
4634 +       vxdprintk(VXD_CBIT(misc, 2),
4635 +               "old path " VS_Q("%s") " [%p:" VS_Q("%.*s") ":%d]", to,
4636 +               old_dentry,
4637 +               old_dentry->d_name.len, old_dentry->d_name.name,
4638 +               old_dentry->d_name.len);
4639 +
4640 +       to[pathlen + 1] = 0;
4641 +retry:
4642 +       new_dentry = NULL;
4643 +       to[pathlen] = pad--;
4644 +       ret = -ELOOP;
4645 +       if (pad <= '\240')
4646 +               goto out_rel_old;
4647 +
4648 +       vxdprintk(VXD_CBIT(misc, 1), "temp copy " VS_Q("%s"), to);
4649 +
4650 +       /* dir_nd.path 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 +          dir_path will hold refs to dentry and mnt and
4659 +          we'll have get write access to the mnt */
4660 +       new_dentry = kern_path_create(AT_FDCWD, to, &dir_path, 0);
4661 +       if (!new_dentry || IS_ERR(new_dentry)) {
4662 +               path_put(&dir_nd.path);
4663 +               vxdprintk(VXD_CBIT(misc, 2),
4664 +                       "kern_path_create(new) failed with %ld",
4665 +                       PTR_ERR(new_dentry));
4666 +               goto retry;
4667 +       }
4668 +       vxdprintk(VXD_CBIT(misc, 2),
4669 +               "kern_path_create(new): %p [" VS_Q("%.*s") ":%d]",
4670 +               new_dentry,
4671 +               new_dentry->d_name.len, new_dentry->d_name.name,
4672 +               new_dentry->d_name.len);
4673 +
4674 +       /* take a reference on new_dentry */
4675 +       dget(new_dentry);
4676 +
4677 +       /* dentry/mnt refs handed over to new_path */
4678 +       new_path = &dir_path;
4679 +
4680 +       /* dentry for old/new dir */
4681 +       dir = dir_nd.path.dentry;
4682 +
4683 +       /* give up reference on dir */
4684 +       dput(new_path->dentry);
4685 +
4686 +       /* new_dentry already has a reference */
4687 +       new_path->dentry = new_dentry;
4688 +
4689 +       ret = vfs_create(dir->d_inode, new_dentry, mode, 1);
4690 +       vxdprintk(VXD_CBIT(misc, 2),
4691 +               "vfs_create(new): %d", ret);
4692 +       if (ret == -EEXIST) {
4693 +               mutex_unlock(&dir->d_inode->i_mutex);
4694 +               path_put(&dir_nd.path);
4695 +               mnt_drop_write(new_path->mnt);
4696 +               path_put(new_path);
4697 +               new_dentry = NULL;
4698 +               goto retry;
4699 +       }
4700 +       else if (ret < 0)
4701 +               goto out_unlock_new;
4702 +
4703 +       /* drop out early, ret passes ENOENT */
4704 +       ret = -ENOENT;
4705 +       if ((redo = d_unhashed(old_dentry)))
4706 +               goto out_unlock_new;
4707 +
4708 +       /* doesn't change refs for old_path */
4709 +       old_file = dentry_open(old_path, O_RDONLY, current_cred());
4710 +       vxdprintk(VXD_CBIT(misc, 2),
4711 +               "dentry_open(old): %p", old_file);
4712 +       if (IS_ERR(old_file)) {
4713 +               ret = PTR_ERR(old_file);
4714 +               goto out_unlock_new;
4715 +       }
4716 +
4717 +       /* doesn't change refs for new_path */
4718 +       new_file = dentry_open(new_path, O_WRONLY, current_cred());
4719 +       vxdprintk(VXD_CBIT(misc, 2),
4720 +               "dentry_open(new): %p", new_file);
4721 +       if (IS_ERR(new_file)) {
4722 +               ret = PTR_ERR(new_file);
4723 +               goto out_fput_old;
4724 +       }
4725 +
4726 +       size = i_size_read(old_file->f_dentry->d_inode);
4727 +       ret = do_cow_splice(old_file, new_file, size);
4728 +       vxdprintk(VXD_CBIT(misc, 2), "do_splice_direct: %d", ret);
4729 +       if (ret < 0) {
4730 +               goto out_fput_both;
4731 +       } else if (ret < size) {
4732 +               ret = -ENOSPC;
4733 +               goto out_fput_both;
4734 +       } else {
4735 +               struct inode *old_inode = old_dentry->d_inode;
4736 +               struct inode *new_inode = new_dentry->d_inode;
4737 +               struct iattr attr = {
4738 +                       .ia_uid = old_inode->i_uid,
4739 +                       .ia_gid = old_inode->i_gid,
4740 +                       .ia_valid = ATTR_UID | ATTR_GID
4741 +                       };
4742 +
4743 +               setattr_copy(new_inode, &attr);
4744 +               mark_inode_dirty(new_inode);
4745 +       }
4746 +
4747 +       /* lock rename mutex */
4748 +       mutex_lock(&old_dentry->d_inode->i_sb->s_vfs_rename_mutex);
4749 +
4750 +       /* drop out late */
4751 +       ret = -ENOENT;
4752 +       if ((redo = d_unhashed(old_dentry)))
4753 +               goto out_unlock;
4754 +
4755 +       vxdprintk(VXD_CBIT(misc, 2),
4756 +               "vfs_rename: [" VS_Q("%*s") ":%d] -> [" VS_Q("%*s") ":%d]",
4757 +               new_dentry->d_name.len, new_dentry->d_name.name,
4758 +               new_dentry->d_name.len,
4759 +               old_dentry->d_name.len, old_dentry->d_name.name,
4760 +               old_dentry->d_name.len);
4761 +       ret = vfs_rename(dir_nd.path.dentry->d_inode, new_dentry,
4762 +               old_dentry->d_parent->d_inode, old_dentry);
4763 +       vxdprintk(VXD_CBIT(misc, 2), "vfs_rename: %d", ret);
4764 +
4765 +out_unlock:
4766 +       mutex_unlock(&old_dentry->d_inode->i_sb->s_vfs_rename_mutex);
4767 +
4768 +out_fput_both:
4769 +       vxdprintk(VXD_CBIT(misc, 3),
4770 +               "fput(new_file=%p[#%ld])", new_file,
4771 +               atomic_long_read(&new_file->f_count));
4772 +       fput(new_file);
4773 +
4774 +out_fput_old:
4775 +       vxdprintk(VXD_CBIT(misc, 3),
4776 +               "fput(old_file=%p[#%ld])", old_file,
4777 +               atomic_long_read(&old_file->f_count));
4778 +       fput(old_file);
4779 +
4780 +out_unlock_new:
4781 +       /* drop references from dir_nd.path */
4782 +       path_put(&dir_nd.path);
4783 +
4784 +       /* drop write access to mnt */
4785 +       mnt_drop_write(new_path->mnt);
4786 +
4787 +       /* unlock the inode mutex from kern_path_create() */
4788 +       mutex_unlock(&dir->d_inode->i_mutex);
4789 +       if (!ret)
4790 +               goto out_redo;
4791 +
4792 +       /* error path cleanup */
4793 +       vfs_unlink(dir->d_inode, new_dentry);
4794 +
4795 +out_redo:
4796 +       if (!redo)
4797 +               goto out_rel_both;
4798 +
4799 +       /* lookup dentry once again
4800 +          old_nd.path will be freed as old_path in out_rel_old */
4801 +       ret = do_path_lookup(AT_FDCWD, pathname, LOOKUP_FOLLOW, &old_nd);
4802 +       if (ret)
4803 +               goto out_rel_both;
4804 +
4805 +       /* drop reference on new_dentry */
4806 +       dput(new_dentry);
4807 +       new_dentry = old_path->dentry;
4808 +       dget(new_dentry);
4809 +       vxdprintk(VXD_CBIT(misc, 2),
4810 +               "do_path_lookup(redo): %p [" VS_Q("%.*s") ":%d]",
4811 +               new_dentry,
4812 +               new_dentry->d_name.len, new_dentry->d_name.name,
4813 +               new_dentry->d_name.len);
4814 +
4815 +out_rel_both:
4816 +       if (new_path)
4817 +               path_put(new_path);
4818 +out_rel_old:
4819 +       path_put(old_path);
4820 +out_free_path:
4821 +       kfree(path);
4822 +out:
4823 +       if (ret) {
4824 +               dput(new_dentry);
4825 +               new_dentry = ERR_PTR(ret);
4826 +       }
4827 +       vxdprintk(VXD_CBIT(misc, 3),
4828 +               "cow_break_link returning with %p", new_dentry);
4829 +       return new_dentry;
4830 +}
4831 +
4832 +#endif
4833 +
4834 +int    vx_info_mnt_namespace(struct mnt_namespace *ns, char *buffer)
4835 +{
4836 +       struct path path;
4837 +       struct vfsmount *vmnt;
4838 +       char *pstr, *root;
4839 +       int length = 0;
4840 +
4841 +       pstr = kmalloc(PATH_MAX, GFP_KERNEL);
4842 +       if (!pstr)
4843 +               return 0;
4844 +
4845 +       vmnt = &ns->root->mnt;
4846 +       path.mnt = vmnt;
4847 +       path.dentry = vmnt->mnt_root;
4848 +       root = d_path(&path, pstr, PATH_MAX - 2);
4849 +       length = sprintf(buffer + length,
4850 +               "Namespace:\t%p [#%u]\n"
4851 +               "RootPath:\t%s\n",
4852 +               ns, atomic_read(&ns->count),
4853 +               root);
4854 +       kfree(pstr);
4855 +       return length;
4856 +}
4857 +
4858  /* get the link contents into pagecache */
4859  static char *page_getlink(struct dentry * dentry, struct page **ppage)
4860  {
4861 @@ -3998,3 +4409,4 @@ EXPORT_SYMBOL(vfs_symlink);
4862  EXPORT_SYMBOL(vfs_unlink);
4863  EXPORT_SYMBOL(dentry_unhash);
4864  EXPORT_SYMBOL(generic_readlink);
4865 +EXPORT_SYMBOL(vx_info_mnt_namespace);
4866 diff -NurpP --minimal linux-3.6.9/fs/namespace.c linux-3.6.9-vs2.3.4.4/fs/namespace.c
4867 --- linux-3.6.9/fs/namespace.c  2012-10-04 15:27:40.000000000 +0200
4868 +++ linux-3.6.9-vs2.3.4.4/fs/namespace.c        2012-12-08 01:10:23.000000000 +0100
4869 @@ -20,6 +20,11 @@
4870  #include <linux/fs_struct.h>   /* get_fs_root et.al. */
4871  #include <linux/fsnotify.h>    /* fsnotify_vfsmount_delete */
4872  #include <linux/uaccess.h>
4873 +#include <linux/vs_base.h>
4874 +#include <linux/vs_context.h>
4875 +#include <linux/vs_tag.h>
4876 +#include <linux/vserver/space.h>
4877 +#include <linux/vserver/global.h>
4878  #include "pnode.h"
4879  #include "internal.h"
4880  
4881 @@ -749,6 +754,10 @@ vfs_kern_mount(struct file_system_type *
4882         if (!type)
4883                 return ERR_PTR(-ENODEV);
4884  
4885 +       if ((type->fs_flags & FS_BINARY_MOUNTDATA) &&
4886 +               !vx_capable(CAP_SYS_ADMIN, VXC_BINARY_MOUNT))
4887 +               return ERR_PTR(-EPERM);
4888 +
4889         mnt = alloc_vfsmnt(name);
4890         if (!mnt)
4891                 return ERR_PTR(-ENOMEM);
4892 @@ -801,6 +810,7 @@ static struct mount *clone_mnt(struct mo
4893         mnt->mnt.mnt_root = dget(root);
4894         mnt->mnt_mountpoint = mnt->mnt.mnt_root;
4895         mnt->mnt_parent = mnt;
4896 +               mnt->mnt_tag = old->mnt_tag;
4897         br_write_lock(&vfsmount_lock);
4898         list_add_tail(&mnt->mnt_instance, &sb->s_mounts);
4899         br_write_unlock(&vfsmount_lock);
4900 @@ -1266,7 +1276,7 @@ SYSCALL_DEFINE2(umount, char __user *, n
4901                 goto dput_and_out;
4902  
4903         retval = -EPERM;
4904 -       if (!capable(CAP_SYS_ADMIN))
4905 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SECURE_MOUNT))
4906                 goto dput_and_out;
4907  
4908         retval = do_umount(mnt, flags);
4909 @@ -1292,7 +1302,7 @@ SYSCALL_DEFINE1(oldumount, char __user *
4910  
4911  static int mount_is_safe(struct path *path)
4912  {
4913 -       if (capable(CAP_SYS_ADMIN))
4914 +       if (vx_capable(CAP_SYS_ADMIN, VXC_SECURE_MOUNT))
4915                 return 0;
4916         return -EPERM;
4917  #ifdef notyet
4918 @@ -1610,7 +1620,7 @@ static int do_change_type(struct path *p
4919         int type;
4920         int err = 0;
4921  
4922 -       if (!capable(CAP_SYS_ADMIN))
4923 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_NAMESPACE))
4924                 return -EPERM;
4925  
4926         if (path->dentry != path->mnt->mnt_root)
4927 @@ -1626,6 +1636,7 @@ static int do_change_type(struct path *p
4928                 if (err)
4929                         goto out_unlock;
4930         }
4931 +       // mnt->mnt_flags = mnt_flags;
4932  
4933         br_write_lock(&vfsmount_lock);
4934         for (m = mnt; m; m = (recurse ? next_mnt(m, mnt) : NULL))
4935 @@ -1641,12 +1652,14 @@ static int do_change_type(struct path *p
4936   * do loopback mount.
4937   */
4938  static int do_loopback(struct path *path, char *old_name,
4939 -                               int recurse)
4940 +       vs_tag_t tag, unsigned long flags, int mnt_flags)
4941  {
4942         LIST_HEAD(umount_list);
4943         struct path old_path;
4944         struct mount *mnt = NULL, *old;
4945         int err = mount_is_safe(path);
4946 +       int recurse = flags & MS_REC;
4947 +
4948         if (err)
4949                 return err;
4950         if (!old_name || !*old_name)
4951 @@ -1715,13 +1728,13 @@ static int change_mount_flags(struct vfs
4952   * on it - tough luck.
4953   */
4954  static int do_remount(struct path *path, int flags, int mnt_flags,
4955 -                     void *data)
4956 +       void *data, xid_t xid)
4957  {
4958         int err;
4959         struct super_block *sb = path->mnt->mnt_sb;
4960         struct mount *mnt = real_mount(path->mnt);
4961  
4962 -       if (!capable(CAP_SYS_ADMIN))
4963 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SECURE_REMOUNT))
4964                 return -EPERM;
4965  
4966         if (!check_mnt(mnt))
4967 @@ -1770,7 +1783,7 @@ static int do_move_mount(struct path *pa
4968         struct mount *p;
4969         struct mount *old;
4970         int err = 0;
4971 -       if (!capable(CAP_SYS_ADMIN))
4972 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SECURE_MOUNT))
4973                 return -EPERM;
4974         if (!old_name || !*old_name)
4975                 return -EINVAL;
4976 @@ -1927,7 +1940,7 @@ static int do_new_mount(struct path *pat
4977                 return -EINVAL;
4978  
4979         /* we need capabilities... */
4980 -       if (!capable(CAP_SYS_ADMIN))
4981 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SECURE_MOUNT))
4982                 return -EPERM;
4983  
4984         mnt = do_kern_mount(type, flags, name, data);
4985 @@ -2197,6 +2210,7 @@ long do_mount(char *dev_name, char *dir_
4986         struct path path;
4987         int retval = 0;
4988         int mnt_flags = 0;
4989 +       vs_tag_t tag = 0;
4990  
4991         /* Discard magic */
4992         if ((flags & MS_MGC_MSK) == MS_MGC_VAL)
4993 @@ -2224,6 +2238,12 @@ long do_mount(char *dev_name, char *dir_
4994         if (!(flags & MS_NOATIME))
4995                 mnt_flags |= MNT_RELATIME;
4996  
4997 +       if (dx_parse_tag(data_page, &tag, 1, &mnt_flags, &flags)) {
4998 +               /* FIXME: bind and re-mounts get the tag flag? */
4999 +               if (flags & (MS_BIND|MS_REMOUNT))
5000 +                       flags |= MS_TAGID;
5001 +       }
5002 +
5003         /* Separate the per-mountpoint flags */
5004         if (flags & MS_NOSUID)
5005                 mnt_flags |= MNT_NOSUID;
5006 @@ -2240,15 +2260,17 @@ long do_mount(char *dev_name, char *dir_
5007         if (flags & MS_RDONLY)
5008                 mnt_flags |= MNT_READONLY;
5009  
5010 +       if (!capable(CAP_SYS_ADMIN))
5011 +               mnt_flags |= MNT_NODEV;
5012         flags &= ~(MS_NOSUID | MS_NOEXEC | MS_NODEV | MS_ACTIVE | MS_BORN |
5013                    MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
5014                    MS_STRICTATIME);
5015  
5016         if (flags & MS_REMOUNT)
5017                 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
5018 -                                   data_page);
5019 +                                   data_page, tag);
5020         else if (flags & MS_BIND)
5021 -               retval = do_loopback(&path, dev_name, flags & MS_REC);
5022 +               retval = do_loopback(&path, dev_name, tag, flags, mnt_flags);
5023         else if (flags & (MS_SHARED | MS_PRIVATE | MS_SLAVE | MS_UNBINDABLE))
5024                 retval = do_change_type(&path, flags);
5025         else if (flags & MS_MOVE)
5026 @@ -2329,6 +2351,7 @@ static struct mnt_namespace *dup_mnt_ns(
5027                 q = next_mnt(q, new);
5028         }
5029         up_write(&namespace_sem);
5030 +       atomic_inc(&vs_global_mnt_ns);
5031  
5032         if (rootmnt)
5033                 mntput(rootmnt);
5034 @@ -2524,9 +2547,10 @@ SYSCALL_DEFINE2(pivot_root, const char _
5035         error = -EINVAL;
5036         new_mnt = real_mount(new.mnt);
5037         root_mnt = real_mount(root.mnt);
5038 -       if (IS_MNT_SHARED(real_mount(old.mnt)) ||
5039 +       if ((IS_MNT_SHARED(real_mount(old.mnt)) ||
5040                 IS_MNT_SHARED(new_mnt->mnt_parent) ||
5041 -               IS_MNT_SHARED(root_mnt->mnt_parent))
5042 +               IS_MNT_SHARED(root_mnt->mnt_parent)) &&
5043 +               !vx_flags(VXF_STATE_SETUP, 0))
5044                 goto out4;
5045         if (!check_mnt(root_mnt) || !check_mnt(new_mnt))
5046                 goto out4;
5047 @@ -2647,6 +2671,7 @@ void put_mnt_ns(struct mnt_namespace *ns
5048         br_write_unlock(&vfsmount_lock);
5049         up_write(&namespace_sem);
5050         release_mounts(&umount_list);
5051 +       atomic_dec(&vs_global_mnt_ns);
5052         kfree(ns);
5053  }
5054  
5055 diff -NurpP --minimal linux-3.6.9/fs/nfs/client.c linux-3.6.9-vs2.3.4.4/fs/nfs/client.c
5056 --- linux-3.6.9/fs/nfs/client.c 2012-12-08 01:34:14.000000000 +0100
5057 +++ linux-3.6.9-vs2.3.4.4/fs/nfs/client.c       2012-11-06 18:43:41.000000000 +0100
5058 @@ -692,6 +692,9 @@ int nfs_init_server_rpcclient(struct nfs
5059         if (server->flags & NFS_MOUNT_SOFT)
5060                 server->client->cl_softrtry = 1;
5061  
5062 +       server->client->cl_tag = 0;
5063 +       if (server->flags & NFS_MOUNT_TAGGED)
5064 +               server->client->cl_tag = 1;
5065         return 0;
5066  }
5067  EXPORT_SYMBOL_GPL(nfs_init_server_rpcclient);
5068 @@ -869,6 +872,10 @@ static void nfs_server_set_fsinfo(struct
5069                 server->acdirmin = server->acdirmax = 0;
5070         }
5071  
5072 +       /* FIXME: needs fsinfo
5073 +       if (server->flags & NFS_MOUNT_TAGGED)
5074 +               sb->s_flags |= MS_TAGGED;       */
5075 +
5076         server->maxfilesize = fsinfo->maxfilesize;
5077  
5078         server->time_delta = fsinfo->time_delta;
5079 diff -NurpP --minimal linux-3.6.9/fs/nfs/dir.c linux-3.6.9-vs2.3.4.4/fs/nfs/dir.c
5080 --- linux-3.6.9/fs/nfs/dir.c    2012-10-04 15:27:40.000000000 +0200
5081 +++ linux-3.6.9-vs2.3.4.4/fs/nfs/dir.c  2012-10-04 18:47:00.000000000 +0200
5082 @@ -36,6 +36,7 @@
5083  #include <linux/sched.h>
5084  #include <linux/kmemleak.h>
5085  #include <linux/xattr.h>
5086 +#include <linux/vs_tag.h>
5087  
5088  #include "delegation.h"
5089  #include "iostat.h"
5090 @@ -1251,6 +1252,7 @@ struct dentry *nfs_lookup(struct inode *
5091         /* Success: notify readdir to use READDIRPLUS */
5092         nfs_advise_use_readdirplus(dir);
5093  
5094 +       dx_propagate_tag(nd, inode);
5095  no_entry:
5096         res = d_materialise_unique(dentry, inode);
5097         if (res != NULL) {
5098 diff -NurpP --minimal linux-3.6.9/fs/nfs/inode.c linux-3.6.9-vs2.3.4.4/fs/nfs/inode.c
5099 --- linux-3.6.9/fs/nfs/inode.c  2012-10-04 15:27:40.000000000 +0200
5100 +++ linux-3.6.9-vs2.3.4.4/fs/nfs/inode.c        2012-10-04 18:47:00.000000000 +0200
5101 @@ -39,6 +39,7 @@
5102  #include <linux/compat.h>
5103  #include <linux/freezer.h>
5104  #include <linux/crc32.h>
5105 +#include <linux/vs_tag.h>
5106  
5107  #include <asm/uaccess.h>
5108  
5109 @@ -279,6 +280,8 @@ nfs_fhget(struct super_block *sb, struct
5110         if (inode->i_state & I_NEW) {
5111                 struct nfs_inode *nfsi = NFS_I(inode);
5112                 unsigned long now = jiffies;
5113 +               uid_t uid;
5114 +               gid_t gid;
5115  
5116                 /* We set i_ino for the few things that still rely on it,
5117                  * such as stat(2) */
5118 @@ -323,8 +326,8 @@ nfs_fhget(struct super_block *sb, struct
5119                 inode->i_version = 0;
5120                 inode->i_size = 0;
5121                 clear_nlink(inode);
5122 -               inode->i_uid = -2;
5123 -               inode->i_gid = -2;
5124 +               uid = -2;
5125 +               gid = -2;
5126                 inode->i_blocks = 0;
5127                 memset(nfsi->cookieverf, 0, sizeof(nfsi->cookieverf));
5128                 nfsi->write_io = 0;
5129 @@ -358,11 +361,11 @@ nfs_fhget(struct super_block *sb, struct
5130                 else if (nfs_server_capable(inode, NFS_CAP_NLINK))
5131                         nfsi->cache_validity |= NFS_INO_INVALID_ATTR;
5132                 if (fattr->valid & NFS_ATTR_FATTR_OWNER)
5133 -                       inode->i_uid = fattr->uid;
5134 +                       uid = fattr->uid;
5135                 else if (nfs_server_capable(inode, NFS_CAP_OWNER))
5136                         nfsi->cache_validity |= NFS_INO_INVALID_ATTR;
5137                 if (fattr->valid & NFS_ATTR_FATTR_GROUP)
5138 -                       inode->i_gid = fattr->gid;
5139 +                       gid = fattr->gid;
5140                 else if (nfs_server_capable(inode, NFS_CAP_OWNER_GROUP))
5141                         nfsi->cache_validity |= NFS_INO_INVALID_ATTR;
5142                 if (fattr->valid & NFS_ATTR_FATTR_BLOCKS_USED)
5143 @@ -373,6 +376,11 @@ nfs_fhget(struct super_block *sb, struct
5144                          */
5145                         inode->i_blocks = nfs_calc_block_size(fattr->du.nfs3.used);
5146                 }
5147 +               inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
5148 +               inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
5149 +               inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid, 0);
5150 +                               /* maybe fattr->xid someday */
5151 +
5152                 nfsi->attrtimeo = NFS_MINATTRTIMEO(inode);
5153                 nfsi->attrtimeo_timestamp = now;
5154                 nfsi->access_cache = RB_ROOT;
5155 @@ -494,6 +502,8 @@ void nfs_setattr_update_inode(struct ino
5156                         inode->i_uid = attr->ia_uid;
5157                 if ((attr->ia_valid & ATTR_GID) != 0)
5158                         inode->i_gid = attr->ia_gid;
5159 +               if ((attr->ia_valid & ATTR_TAG) && IS_TAGGED(inode))
5160 +                       inode->i_tag = attr->ia_tag;
5161                 NFS_I(inode)->cache_validity |= NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL;
5162                 spin_unlock(&inode->i_lock);
5163         }
5164 @@ -965,6 +975,9 @@ static int nfs_check_inode_attributes(st
5165         struct nfs_inode *nfsi = NFS_I(inode);
5166         loff_t cur_size, new_isize;
5167         unsigned long invalid = 0;
5168 +       uid_t uid;
5169 +       gid_t gid;
5170 +       vs_tag_t tag;
5171  
5172  
5173         if (nfs_have_delegated_attributes(inode))
5174 @@ -990,13 +1003,18 @@ static int nfs_check_inode_attributes(st
5175                         invalid |= NFS_INO_INVALID_ATTR|NFS_INO_REVAL_PAGECACHE;
5176         }
5177  
5178 +       uid = INOTAG_UID(DX_TAG(inode), fattr->uid, fattr->gid);
5179 +       gid = INOTAG_GID(DX_TAG(inode), fattr->uid, fattr->gid);
5180 +       tag = INOTAG_TAG(DX_TAG(inode), fattr->uid, fattr->gid, 0);
5181 +
5182         /* Have any file permissions changed? */
5183         if ((fattr->valid & NFS_ATTR_FATTR_MODE) && (inode->i_mode & S_IALLUGO) != (fattr->mode & S_IALLUGO))
5184                 invalid |= NFS_INO_INVALID_ATTR | NFS_INO_INVALID_ACCESS | NFS_INO_INVALID_ACL;
5185 -       if ((fattr->valid & NFS_ATTR_FATTR_OWNER) && inode->i_uid != fattr->uid)
5186 +       if ((fattr->valid & NFS_ATTR_FATTR_OWNER) && uid != fattr->uid)
5187                 invalid |= NFS_INO_INVALID_ATTR | NFS_INO_INVALID_ACCESS | NFS_INO_INVALID_ACL;
5188 -       if ((fattr->valid & NFS_ATTR_FATTR_GROUP) && inode->i_gid != fattr->gid)
5189 +       if ((fattr->valid & NFS_ATTR_FATTR_GROUP) && gid != fattr->gid)
5190                 invalid |= NFS_INO_INVALID_ATTR | NFS_INO_INVALID_ACCESS | NFS_INO_INVALID_ACL;
5191 +               /* maybe check for tag too? */
5192  
5193         /* Has the link count changed? */
5194         if ((fattr->valid & NFS_ATTR_FATTR_NLINK) && inode->i_nlink != fattr->nlink)
5195 @@ -1300,6 +1318,9 @@ static int nfs_update_inode(struct inode
5196         unsigned long invalid = 0;
5197         unsigned long now = jiffies;
5198         unsigned long save_cache_validity;
5199 +       uid_t uid;
5200 +       gid_t gid;
5201 +       vs_tag_t tag;
5202  
5203         dfprintk(VFS, "NFS: %s(%s/%ld fh_crc=0x%08x ct=%d info=0x%x)\n",
5204                         __func__, inode->i_sb->s_id, inode->i_ino,
5205 @@ -1401,6 +1422,9 @@ static int nfs_update_inode(struct inode
5206                                 | NFS_INO_REVAL_PAGECACHE
5207                                 | NFS_INO_REVAL_FORCED);
5208  
5209 +       uid = TAGINO_UID(DX_TAG(inode), inode->i_uid, inode->i_tag);
5210 +       gid = TAGINO_GID(DX_TAG(inode), inode->i_gid, inode->i_tag);
5211 +       tag = inode->i_tag;
5212  
5213         if (fattr->valid & NFS_ATTR_FATTR_ATIME)
5214                 memcpy(&inode->i_atime, &fattr->atime, sizeof(inode->i_atime));
5215 @@ -1422,9 +1446,9 @@ static int nfs_update_inode(struct inode
5216                                 | NFS_INO_REVAL_FORCED);
5217  
5218         if (fattr->valid & NFS_ATTR_FATTR_OWNER) {
5219 -               if (inode->i_uid != fattr->uid) {
5220 +               if (uid != fattr->uid) {
5221                         invalid |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL;
5222 -                       inode->i_uid = fattr->uid;
5223 +                       uid = fattr->uid;
5224                 }
5225         } else if (server->caps & NFS_CAP_OWNER)
5226                 invalid |= save_cache_validity & (NFS_INO_INVALID_ATTR
5227 @@ -1433,9 +1457,9 @@ static int nfs_update_inode(struct inode
5228                                 | NFS_INO_REVAL_FORCED);
5229  
5230         if (fattr->valid & NFS_ATTR_FATTR_GROUP) {
5231 -               if (inode->i_gid != fattr->gid) {
5232 +               if (gid != fattr->gid) {
5233                         invalid |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL;
5234 -                       inode->i_gid = fattr->gid;
5235 +                       gid = fattr->gid;
5236                 }
5237         } else if (server->caps & NFS_CAP_OWNER_GROUP)
5238                 invalid |= save_cache_validity & (NFS_INO_INVALID_ATTR
5239 @@ -1443,6 +1467,10 @@ static int nfs_update_inode(struct inode
5240                                 | NFS_INO_INVALID_ACL
5241                                 | NFS_INO_REVAL_FORCED);
5242  
5243 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
5244 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
5245 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid, tag);
5246 +
5247         if (fattr->valid & NFS_ATTR_FATTR_NLINK) {
5248                 if (inode->i_nlink != fattr->nlink) {
5249                         invalid |= NFS_INO_INVALID_ATTR;
5250 diff -NurpP --minimal linux-3.6.9/fs/nfs/nfs3xdr.c linux-3.6.9-vs2.3.4.4/fs/nfs/nfs3xdr.c
5251 --- linux-3.6.9/fs/nfs/nfs3xdr.c        2012-10-04 15:27:40.000000000 +0200
5252 +++ linux-3.6.9-vs2.3.4.4/fs/nfs/nfs3xdr.c      2012-10-04 18:47:00.000000000 +0200
5253 @@ -20,6 +20,7 @@
5254  #include <linux/nfs3.h>
5255  #include <linux/nfs_fs.h>
5256  #include <linux/nfsacl.h>
5257 +#include <linux/vs_tag.h>
5258  #include "internal.h"
5259  
5260  #define NFSDBG_FACILITY                NFSDBG_XDR
5261 @@ -560,7 +561,8 @@ static __be32 *xdr_decode_nfstime3(__be3
5262   *             set_mtime       mtime;
5263   *     };
5264   */
5265 -static void encode_sattr3(struct xdr_stream *xdr, const struct iattr *attr)
5266 +static void encode_sattr3(struct xdr_stream *xdr,
5267 +       const struct iattr *attr, int tag)
5268  {
5269         u32 nbytes;
5270         __be32 *p;
5271 @@ -592,15 +594,19 @@ static void encode_sattr3(struct xdr_str
5272         } else
5273                 *p++ = xdr_zero;
5274  
5275 -       if (attr->ia_valid & ATTR_UID) {
5276 +       if (attr->ia_valid & ATTR_UID ||
5277 +               (tag && (attr->ia_valid & ATTR_TAG))) {
5278                 *p++ = xdr_one;
5279 -               *p++ = cpu_to_be32(attr->ia_uid);
5280 +               *p++ = cpu_to_be32(TAGINO_UID(tag,
5281 +                       attr->ia_uid, attr->ia_tag));
5282         } else
5283                 *p++ = xdr_zero;
5284  
5285 -       if (attr->ia_valid & ATTR_GID) {
5286 +       if (attr->ia_valid & ATTR_GID ||
5287 +               (tag && (attr->ia_valid & ATTR_TAG))) {
5288                 *p++ = xdr_one;
5289 -               *p++ = cpu_to_be32(attr->ia_gid);
5290 +               *p++ = cpu_to_be32(TAGINO_GID(tag,
5291 +                       attr->ia_gid, attr->ia_tag));
5292         } else
5293                 *p++ = xdr_zero;
5294  
5295 @@ -879,7 +885,7 @@ static void nfs3_xdr_enc_setattr3args(st
5296                                       const struct nfs3_sattrargs *args)
5297  {
5298         encode_nfs_fh3(xdr, args->fh);
5299 -       encode_sattr3(xdr, args->sattr);
5300 +       encode_sattr3(xdr, args->sattr, req->rq_task->tk_client->cl_tag);
5301         encode_sattrguard3(xdr, args);
5302  }
5303  
5304 @@ -1029,13 +1035,13 @@ static void nfs3_xdr_enc_write3args(stru
5305   *     };
5306   */
5307  static void encode_createhow3(struct xdr_stream *xdr,
5308 -                             const struct nfs3_createargs *args)
5309 +       const struct nfs3_createargs *args, int tag)
5310  {
5311         encode_uint32(xdr, args->createmode);
5312         switch (args->createmode) {
5313         case NFS3_CREATE_UNCHECKED:
5314         case NFS3_CREATE_GUARDED:
5315 -               encode_sattr3(xdr, args->sattr);
5316 +               encode_sattr3(xdr, args->sattr, tag);
5317                 break;
5318         case NFS3_CREATE_EXCLUSIVE:
5319                 encode_createverf3(xdr, args->verifier);
5320 @@ -1050,7 +1056,7 @@ static void nfs3_xdr_enc_create3args(str
5321                                      const struct nfs3_createargs *args)
5322  {
5323         encode_diropargs3(xdr, args->fh, args->name, args->len);
5324 -       encode_createhow3(xdr, args);
5325 +       encode_createhow3(xdr, args, req->rq_task->tk_client->cl_tag);
5326  }
5327  
5328  /*
5329 @@ -1066,7 +1072,7 @@ static void nfs3_xdr_enc_mkdir3args(stru
5330                                     const struct nfs3_mkdirargs *args)
5331  {
5332         encode_diropargs3(xdr, args->fh, args->name, args->len);
5333 -       encode_sattr3(xdr, args->sattr);
5334 +       encode_sattr3(xdr, args->sattr, req->rq_task->tk_client->cl_tag);
5335  }
5336  
5337  /*
5338 @@ -1083,9 +1089,9 @@ static void nfs3_xdr_enc_mkdir3args(stru
5339   *     };
5340   */
5341  static void encode_symlinkdata3(struct xdr_stream *xdr,
5342 -                               const struct nfs3_symlinkargs *args)
5343 +       const struct nfs3_symlinkargs *args, int tag)
5344  {
5345 -       encode_sattr3(xdr, args->sattr);
5346 +       encode_sattr3(xdr, args->sattr, tag);
5347         encode_nfspath3(xdr, args->pages, args->pathlen);
5348  }
5349  
5350 @@ -1094,7 +1100,7 @@ static void nfs3_xdr_enc_symlink3args(st
5351                                       const struct nfs3_symlinkargs *args)
5352  {
5353         encode_diropargs3(xdr, args->fromfh, args->fromname, args->fromlen);
5354 -       encode_symlinkdata3(xdr, args);
5355 +       encode_symlinkdata3(xdr, args, req->rq_task->tk_client->cl_tag);
5356  }
5357  
5358  /*
5359 @@ -1122,24 +1128,24 @@ static void nfs3_xdr_enc_symlink3args(st
5360   *     };
5361   */
5362  static void encode_devicedata3(struct xdr_stream *xdr,
5363 -                              const struct nfs3_mknodargs *args)
5364 +       const struct nfs3_mknodargs *args, int tag)
5365  {
5366 -       encode_sattr3(xdr, args->sattr);
5367 +       encode_sattr3(xdr, args->sattr, tag);
5368         encode_specdata3(xdr, args->rdev);
5369  }
5370  
5371  static void encode_mknoddata3(struct xdr_stream *xdr,
5372 -                             const struct nfs3_mknodargs *args)
5373 +       const struct nfs3_mknodargs *args, int tag)
5374  {
5375         encode_ftype3(xdr, args->type);
5376         switch (args->type) {
5377         case NF3CHR:
5378         case NF3BLK:
5379 -               encode_devicedata3(xdr, args);
5380 +               encode_devicedata3(xdr, args, tag);
5381                 break;
5382         case NF3SOCK:
5383         case NF3FIFO:
5384 -               encode_sattr3(xdr, args->sattr);
5385 +               encode_sattr3(xdr, args->sattr, tag);
5386                 break;
5387         case NF3REG:
5388         case NF3DIR:
5389 @@ -1154,7 +1160,7 @@ static void nfs3_xdr_enc_mknod3args(stru
5390                                     const struct nfs3_mknodargs *args)
5391  {
5392         encode_diropargs3(xdr, args->fh, args->name, args->len);
5393 -       encode_mknoddata3(xdr, args);
5394 +       encode_mknoddata3(xdr, args, req->rq_task->tk_client->cl_tag);
5395  }
5396  
5397  /*
5398 diff -NurpP --minimal linux-3.6.9/fs/nfs/super.c linux-3.6.9-vs2.3.4.4/fs/nfs/super.c
5399 --- linux-3.6.9/fs/nfs/super.c  2012-12-08 01:34:14.000000000 +0100
5400 +++ linux-3.6.9-vs2.3.4.4/fs/nfs/super.c        2012-12-08 01:36:33.000000000 +0100
5401 @@ -54,6 +54,7 @@
5402  #include <linux/parser.h>
5403  #include <linux/nsproxy.h>
5404  #include <linux/rcupdate.h>
5405 +#include <linux/vs_tag.h>
5406  
5407  #include <asm/uaccess.h>
5408  
5409 @@ -88,6 +89,7 @@ enum {
5410         Opt_sharecache, Opt_nosharecache,
5411         Opt_resvport, Opt_noresvport,
5412         Opt_fscache, Opt_nofscache,
5413 +       Opt_tag, Opt_notag,
5414  
5415         /* Mount options that take integer arguments */
5416         Opt_port,
5417 @@ -100,6 +102,7 @@ enum {
5418         Opt_mountport,
5419         Opt_mountvers,
5420         Opt_minorversion,
5421 +       Opt_tagid,
5422  
5423         /* Mount options that take string arguments */
5424         Opt_nfsvers,
5425 @@ -182,6 +185,10 @@ static const match_table_t nfs_mount_opt
5426         /* The following needs to be listed after all other options */
5427         { Opt_nfsvers, "v%s" },
5428  
5429 +       { Opt_tag, "tag" },
5430 +       { Opt_notag, "notag" },
5431 +       { Opt_tagid, "tagid=%u" },
5432 +
5433         { Opt_err, NULL }
5434  };
5435  
5436 @@ -626,6 +633,7 @@ static void nfs_show_mount_options(struc
5437                 { NFS_MOUNT_NORDIRPLUS, ",nordirplus", "" },
5438                 { NFS_MOUNT_UNSHARED, ",nosharecache", "" },
5439                 { NFS_MOUNT_NORESVPORT, ",noresvport", "" },
5440 +               { NFS_MOUNT_TAGGED, ",tag", "" },
5441                 { 0, NULL, NULL }
5442         };
5443         const struct proc_nfs_info *nfs_infop;
5444 @@ -1243,6 +1251,14 @@ static int nfs_parse_mount_options(char 
5445                         kfree(mnt->fscache_uniq);
5446                         mnt->fscache_uniq = NULL;
5447                         break;
5448 +#ifndef CONFIG_TAGGING_NONE
5449 +               case Opt_tag:
5450 +                       mnt->flags |= NFS_MOUNT_TAGGED;
5451 +                       break;
5452 +               case Opt_notag:
5453 +                       mnt->flags &= ~NFS_MOUNT_TAGGED;
5454 +                       break;
5455 +#endif
5456  
5457                 /*
5458                  * options that take numeric values
5459 @@ -1329,6 +1345,12 @@ static int nfs_parse_mount_options(char 
5460                                 goto out_invalid_value;
5461                         mnt->minorversion = option;
5462                         break;
5463 +#ifdef CONFIG_PROPAGATE
5464 +               case Opt_tagid:
5465 +                       /* use args[0] */
5466 +                       nfs_data.flags |= NFS_MOUNT_TAGGED;
5467 +                       break;
5468 +#endif
5469  
5470                 /*
5471                  * options that take text values
5472 diff -NurpP --minimal linux-3.6.9/fs/nfsd/auth.c linux-3.6.9-vs2.3.4.4/fs/nfsd/auth.c
5473 --- linux-3.6.9/fs/nfsd/auth.c  2012-07-22 23:39:41.000000000 +0200
5474 +++ linux-3.6.9-vs2.3.4.4/fs/nfsd/auth.c        2012-10-04 18:47:00.000000000 +0200
5475 @@ -2,6 +2,7 @@
5476  
5477  #include <linux/sched.h>
5478  #include <linux/user_namespace.h>
5479 +#include <linux/vs_tag.h>
5480  #include "nfsd.h"
5481  #include "auth.h"
5482  
5483 @@ -37,6 +38,9 @@ int nfsd_setuser(struct svc_rqst *rqstp,
5484  
5485         new->fsuid = rqstp->rq_cred.cr_uid;
5486         new->fsgid = rqstp->rq_cred.cr_gid;
5487 +       /* FIXME: this desperately needs a tag :)
5488 +       new->xid = (xid_t)INOTAG_TAG(DX_TAG_NFSD, cred.cr_uid, cred.cr_gid, 0);
5489 +                       */
5490  
5491         rqgi = rqstp->rq_cred.cr_group_info;
5492  
5493 diff -NurpP --minimal linux-3.6.9/fs/nfsd/nfs3xdr.c linux-3.6.9-vs2.3.4.4/fs/nfsd/nfs3xdr.c
5494 --- linux-3.6.9/fs/nfsd/nfs3xdr.c       2012-05-21 18:07:26.000000000 +0200
5495 +++ linux-3.6.9-vs2.3.4.4/fs/nfsd/nfs3xdr.c     2012-10-04 18:47:00.000000000 +0200
5496 @@ -7,6 +7,7 @@
5497   */
5498  
5499  #include <linux/namei.h>
5500 +#include <linux/vs_tag.h>
5501  #include "xdr3.h"
5502  #include "auth.h"
5503  
5504 @@ -95,6 +96,8 @@ static __be32 *
5505  decode_sattr3(__be32 *p, struct iattr *iap)
5506  {
5507         u32     tmp;
5508 +       uid_t   uid = 0;
5509 +       gid_t   gid = 0;
5510  
5511         iap->ia_valid = 0;
5512  
5513 @@ -104,12 +107,15 @@ decode_sattr3(__be32 *p, struct iattr *i
5514         }
5515         if (*p++) {
5516                 iap->ia_valid |= ATTR_UID;
5517 -               iap->ia_uid = ntohl(*p++);
5518 +               uid = ntohl(*p++);
5519         }
5520         if (*p++) {
5521                 iap->ia_valid |= ATTR_GID;
5522 -               iap->ia_gid = ntohl(*p++);
5523 +               gid = ntohl(*p++);
5524         }
5525 +       iap->ia_uid = INOTAG_UID(DX_TAG_NFSD, uid, gid);
5526 +       iap->ia_gid = INOTAG_GID(DX_TAG_NFSD, uid, gid);
5527 +       iap->ia_tag = INOTAG_TAG(DX_TAG_NFSD, uid, gid, 0);
5528         if (*p++) {
5529                 u64     newsize;
5530  
5531 @@ -165,8 +171,12 @@ encode_fattr3(struct svc_rqst *rqstp, __
5532         *p++ = htonl(nfs3_ftypes[(stat->mode & S_IFMT) >> 12]);
5533         *p++ = htonl((u32) stat->mode);
5534         *p++ = htonl((u32) stat->nlink);
5535 -       *p++ = htonl((u32) nfsd_ruid(rqstp, stat->uid));
5536 -       *p++ = htonl((u32) nfsd_rgid(rqstp, stat->gid));
5537 +       *p++ = htonl((u32) nfsd_ruid(rqstp,
5538 +               TAGINO_UID(0 /* FIXME: DX_TAG(dentry->d_inode) */,
5539 +               stat->uid, stat->tag)));
5540 +       *p++ = htonl((u32) nfsd_rgid(rqstp,
5541 +               TAGINO_GID(0 /* FIXME: DX_TAG(dentry->d_inode) */,
5542 +               stat->gid, stat->tag)));
5543         if (S_ISLNK(stat->mode) && stat->size > NFS3_MAXPATHLEN) {
5544                 p = xdr_encode_hyper(p, (u64) NFS3_MAXPATHLEN);
5545         } else {
5546 diff -NurpP --minimal linux-3.6.9/fs/nfsd/nfs4xdr.c linux-3.6.9-vs2.3.4.4/fs/nfsd/nfs4xdr.c
5547 --- linux-3.6.9/fs/nfsd/nfs4xdr.c       2012-10-04 15:27:40.000000000 +0200
5548 +++ linux-3.6.9-vs2.3.4.4/fs/nfsd/nfs4xdr.c     2012-10-04 18:47:00.000000000 +0200
5549 @@ -46,6 +46,7 @@
5550  #include <linux/utsname.h>
5551  #include <linux/pagemap.h>
5552  #include <linux/sunrpc/svcauth_gss.h>
5553 +#include <linux/vs_tag.h>
5554  
5555  #include "idmap.h"
5556  #include "acl.h"
5557 @@ -2351,14 +2352,18 @@ out_acl:
5558                 WRITE32(stat.nlink);
5559         }
5560         if (bmval1 & FATTR4_WORD1_OWNER) {
5561 -               status = nfsd4_encode_user(rqstp, stat.uid, &p, &buflen);
5562 +               status = nfsd4_encode_user(rqstp,
5563 +                       TAGINO_UID(DX_TAG(dentry->d_inode),
5564 +                       stat.uid, stat.tag), &p, &buflen);
5565                 if (status == nfserr_resource)
5566                         goto out_resource;
5567                 if (status)
5568                         goto out;
5569         }
5570         if (bmval1 & FATTR4_WORD1_OWNER_GROUP) {
5571 -               status = nfsd4_encode_group(rqstp, stat.gid, &p, &buflen);
5572 +               status = nfsd4_encode_group(rqstp,
5573 +                       TAGINO_GID(DX_TAG(dentry->d_inode),
5574 +                       stat.gid, stat.tag), &p, &buflen);
5575                 if (status == nfserr_resource)
5576                         goto out_resource;
5577                 if (status)
5578 diff -NurpP --minimal linux-3.6.9/fs/nfsd/nfsxdr.c linux-3.6.9-vs2.3.4.4/fs/nfsd/nfsxdr.c
5579 --- linux-3.6.9/fs/nfsd/nfsxdr.c        2011-05-22 16:17:53.000000000 +0200
5580 +++ linux-3.6.9-vs2.3.4.4/fs/nfsd/nfsxdr.c      2012-10-04 18:47:00.000000000 +0200
5581 @@ -6,6 +6,7 @@
5582  
5583  #include "xdr.h"
5584  #include "auth.h"
5585 +#include <linux/vs_tag.h>
5586  
5587  #define NFSDDBG_FACILITY               NFSDDBG_XDR
5588  
5589 @@ -88,6 +89,8 @@ static __be32 *
5590  decode_sattr(__be32 *p, struct iattr *iap)
5591  {
5592         u32     tmp, tmp1;
5593 +       uid_t   uid = 0;
5594 +       gid_t   gid = 0;
5595  
5596         iap->ia_valid = 0;
5597  
5598 @@ -101,12 +104,15 @@ decode_sattr(__be32 *p, struct iattr *ia
5599         }
5600         if ((tmp = ntohl(*p++)) != (u32)-1) {
5601                 iap->ia_valid |= ATTR_UID;
5602 -               iap->ia_uid = tmp;
5603 +               uid = tmp;
5604         }
5605         if ((tmp = ntohl(*p++)) != (u32)-1) {
5606                 iap->ia_valid |= ATTR_GID;
5607 -               iap->ia_gid = tmp;
5608 +               gid = tmp;
5609         }
5610 +       iap->ia_uid = INOTAG_UID(DX_TAG_NFSD, uid, gid);
5611 +       iap->ia_gid = INOTAG_GID(DX_TAG_NFSD, uid, gid);
5612 +       iap->ia_tag = INOTAG_TAG(DX_TAG_NFSD, uid, gid, 0);
5613         if ((tmp = ntohl(*p++)) != (u32)-1) {
5614                 iap->ia_valid |= ATTR_SIZE;
5615                 iap->ia_size = tmp;
5616 @@ -151,8 +157,10 @@ encode_fattr(struct svc_rqst *rqstp, __b
5617         *p++ = htonl(nfs_ftypes[type >> 12]);
5618         *p++ = htonl((u32) stat->mode);
5619         *p++ = htonl((u32) stat->nlink);
5620 -       *p++ = htonl((u32) nfsd_ruid(rqstp, stat->uid));
5621 -       *p++ = htonl((u32) nfsd_rgid(rqstp, stat->gid));
5622 +       *p++ = htonl((u32) nfsd_ruid(rqstp,
5623 +               TAGINO_UID(DX_TAG(dentry->d_inode), stat->uid, stat->tag)));
5624 +       *p++ = htonl((u32) nfsd_rgid(rqstp,
5625 +               TAGINO_GID(DX_TAG(dentry->d_inode), stat->gid, stat->tag)));
5626  
5627         if (S_ISLNK(type) && stat->size > NFS_MAXPATHLEN) {
5628                 *p++ = htonl(NFS_MAXPATHLEN);
5629 diff -NurpP --minimal linux-3.6.9/fs/ocfs2/dlmglue.c linux-3.6.9-vs2.3.4.4/fs/ocfs2/dlmglue.c
5630 --- linux-3.6.9/fs/ocfs2/dlmglue.c      2012-07-22 23:39:41.000000000 +0200
5631 +++ linux-3.6.9-vs2.3.4.4/fs/ocfs2/dlmglue.c    2012-10-04 18:47:00.000000000 +0200
5632 @@ -2047,6 +2047,7 @@ static void __ocfs2_stuff_meta_lvb(struc
5633         lvb->lvb_iclusters = cpu_to_be32(oi->ip_clusters);
5634         lvb->lvb_iuid      = cpu_to_be32(inode->i_uid);
5635         lvb->lvb_igid      = cpu_to_be32(inode->i_gid);
5636 +       lvb->lvb_itag      = cpu_to_be16(inode->i_tag);
5637         lvb->lvb_imode     = cpu_to_be16(inode->i_mode);
5638         lvb->lvb_inlink    = cpu_to_be16(inode->i_nlink);
5639         lvb->lvb_iatime_packed  =
5640 @@ -2097,6 +2098,7 @@ static void ocfs2_refresh_inode_from_lvb
5641  
5642         inode->i_uid     = be32_to_cpu(lvb->lvb_iuid);
5643         inode->i_gid     = be32_to_cpu(lvb->lvb_igid);
5644 +       inode->i_tag     = be16_to_cpu(lvb->lvb_itag);
5645         inode->i_mode    = be16_to_cpu(lvb->lvb_imode);
5646         set_nlink(inode, be16_to_cpu(lvb->lvb_inlink));
5647         ocfs2_unpack_timespec(&inode->i_atime,
5648 diff -NurpP --minimal linux-3.6.9/fs/ocfs2/dlmglue.h linux-3.6.9-vs2.3.4.4/fs/ocfs2/dlmglue.h
5649 --- linux-3.6.9/fs/ocfs2/dlmglue.h      2010-10-21 13:07:50.000000000 +0200
5650 +++ linux-3.6.9-vs2.3.4.4/fs/ocfs2/dlmglue.h    2012-10-04 18:47:00.000000000 +0200
5651 @@ -46,7 +46,8 @@ struct ocfs2_meta_lvb {
5652         __be16       lvb_inlink;
5653         __be32       lvb_iattr;
5654         __be32       lvb_igeneration;
5655 -       __be32       lvb_reserved2;
5656 +       __be16       lvb_itag;
5657 +       __be16       lvb_reserved2;
5658  };
5659  
5660  #define OCFS2_QINFO_LVB_VERSION 1
5661 diff -NurpP --minimal linux-3.6.9/fs/ocfs2/file.c linux-3.6.9-vs2.3.4.4/fs/ocfs2/file.c
5662 --- linux-3.6.9/fs/ocfs2/file.c 2012-10-04 15:27:41.000000000 +0200
5663 +++ linux-3.6.9-vs2.3.4.4/fs/ocfs2/file.c       2012-10-04 18:47:00.000000000 +0200
5664 @@ -1123,7 +1123,7 @@ int ocfs2_setattr(struct dentry *dentry,
5665                 attr->ia_valid &= ~ATTR_SIZE;
5666  
5667  #define OCFS2_VALID_ATTRS (ATTR_ATIME | ATTR_MTIME | ATTR_CTIME | ATTR_SIZE \
5668 -                          | ATTR_GID | ATTR_UID | ATTR_MODE)
5669 +                          | ATTR_GID | ATTR_UID | ATTR_TAG | ATTR_MODE)
5670         if (!(attr->ia_valid & OCFS2_VALID_ATTRS))
5671                 return 0;
5672  
5673 diff -NurpP --minimal linux-3.6.9/fs/ocfs2/inode.c linux-3.6.9-vs2.3.4.4/fs/ocfs2/inode.c
5674 --- linux-3.6.9/fs/ocfs2/inode.c        2012-07-22 23:39:41.000000000 +0200
5675 +++ linux-3.6.9-vs2.3.4.4/fs/ocfs2/inode.c      2012-10-04 18:47:00.000000000 +0200
5676 @@ -28,6 +28,7 @@
5677  #include <linux/highmem.h>
5678  #include <linux/pagemap.h>
5679  #include <linux/quotaops.h>
5680 +#include <linux/vs_tag.h>
5681  
5682  #include <asm/byteorder.h>
5683  
5684 @@ -78,11 +79,13 @@ void ocfs2_set_inode_flags(struct inode 
5685  {
5686         unsigned int flags = OCFS2_I(inode)->ip_attr;
5687  
5688 -       inode->i_flags &= ~(S_IMMUTABLE |
5689 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
5690                 S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
5691  
5692         if (flags & OCFS2_IMMUTABLE_FL)
5693                 inode->i_flags |= S_IMMUTABLE;
5694 +       if (flags & OCFS2_IXUNLINK_FL)
5695 +               inode->i_flags |= S_IXUNLINK;
5696  
5697         if (flags & OCFS2_SYNC_FL)
5698                 inode->i_flags |= S_SYNC;
5699 @@ -92,25 +95,44 @@ void ocfs2_set_inode_flags(struct inode 
5700                 inode->i_flags |= S_NOATIME;
5701         if (flags & OCFS2_DIRSYNC_FL)
5702                 inode->i_flags |= S_DIRSYNC;
5703 +
5704 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
5705 +
5706 +       if (flags & OCFS2_BARRIER_FL)
5707 +               inode->i_vflags |= V_BARRIER;
5708 +       if (flags & OCFS2_COW_FL)
5709 +               inode->i_vflags |= V_COW;
5710  }
5711  
5712  /* Propagate flags from i_flags to OCFS2_I(inode)->ip_attr */
5713  void ocfs2_get_inode_flags(struct ocfs2_inode_info *oi)
5714  {
5715         unsigned int flags = oi->vfs_inode.i_flags;
5716 +       unsigned int vflags = oi->vfs_inode.i_vflags;
5717 +
5718 +       oi->ip_attr &= ~(OCFS2_SYNC_FL | OCFS2_APPEND_FL |
5719 +                       OCFS2_IMMUTABLE_FL | OCFS2_IXUNLINK_FL |
5720 +                       OCFS2_NOATIME_FL | OCFS2_DIRSYNC_FL |
5721 +                       OCFS2_BARRIER_FL | OCFS2_COW_FL);
5722 +
5723 +       if (flags & S_IMMUTABLE)
5724 +               oi->ip_attr |= OCFS2_IMMUTABLE_FL;
5725 +       if (flags & S_IXUNLINK)
5726 +               oi->ip_attr |= OCFS2_IXUNLINK_FL;
5727  
5728 -       oi->ip_attr &= ~(OCFS2_SYNC_FL|OCFS2_APPEND_FL|
5729 -                       OCFS2_IMMUTABLE_FL|OCFS2_NOATIME_FL|OCFS2_DIRSYNC_FL);
5730         if (flags & S_SYNC)
5731                 oi->ip_attr |= OCFS2_SYNC_FL;
5732         if (flags & S_APPEND)
5733                 oi->ip_attr |= OCFS2_APPEND_FL;
5734 -       if (flags & S_IMMUTABLE)
5735 -               oi->ip_attr |= OCFS2_IMMUTABLE_FL;
5736         if (flags & S_NOATIME)
5737                 oi->ip_attr |= OCFS2_NOATIME_FL;
5738         if (flags & S_DIRSYNC)
5739                 oi->ip_attr |= OCFS2_DIRSYNC_FL;
5740 +
5741 +       if (vflags & V_BARRIER)
5742 +               oi->ip_attr |= OCFS2_BARRIER_FL;
5743 +       if (vflags & V_COW)
5744 +               oi->ip_attr |= OCFS2_COW_FL;
5745  }
5746  
5747  struct inode *ocfs2_ilookup(struct super_block *sb, u64 blkno)
5748 @@ -241,6 +263,8 @@ void ocfs2_populate_inode(struct inode *
5749         struct super_block *sb;
5750         struct ocfs2_super *osb;
5751         int use_plocks = 1;
5752 +       uid_t uid;
5753 +       gid_t gid;
5754  
5755         sb = inode->i_sb;
5756         osb = OCFS2_SB(sb);
5757 @@ -269,8 +293,12 @@ void ocfs2_populate_inode(struct inode *
5758         inode->i_generation = le32_to_cpu(fe->i_generation);
5759         inode->i_rdev = huge_decode_dev(le64_to_cpu(fe->id1.dev1.i_rdev));
5760         inode->i_mode = le16_to_cpu(fe->i_mode);
5761 -       inode->i_uid = le32_to_cpu(fe->i_uid);
5762 -       inode->i_gid = le32_to_cpu(fe->i_gid);
5763 +       uid = le32_to_cpu(fe->i_uid);
5764 +       gid = le32_to_cpu(fe->i_gid);
5765 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
5766 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
5767 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid,
5768 +               /* le16_to_cpu(raw_inode->i_raw_tag)i */ 0);
5769  
5770         /* Fast symlinks will have i_size but no allocated clusters. */
5771         if (S_ISLNK(inode->i_mode) && !fe->i_clusters) {
5772 diff -NurpP --minimal linux-3.6.9/fs/ocfs2/inode.h linux-3.6.9-vs2.3.4.4/fs/ocfs2/inode.h
5773 --- linux-3.6.9/fs/ocfs2/inode.h        2012-01-09 16:14:55.000000000 +0100
5774 +++ linux-3.6.9-vs2.3.4.4/fs/ocfs2/inode.h      2012-10-04 18:47:00.000000000 +0200
5775 @@ -154,6 +154,7 @@ struct buffer_head *ocfs2_bread(struct i
5776  
5777  void ocfs2_set_inode_flags(struct inode *inode);
5778  void ocfs2_get_inode_flags(struct ocfs2_inode_info *oi);
5779 +int ocfs2_sync_flags(struct inode *inode, int, int);
5780  
5781  static inline blkcnt_t ocfs2_inode_sector_count(struct inode *inode)
5782  {
5783 diff -NurpP --minimal linux-3.6.9/fs/ocfs2/ioctl.c linux-3.6.9-vs2.3.4.4/fs/ocfs2/ioctl.c
5784 --- linux-3.6.9/fs/ocfs2/ioctl.c        2012-10-04 15:27:41.000000000 +0200
5785 +++ linux-3.6.9-vs2.3.4.4/fs/ocfs2/ioctl.c      2012-10-04 18:47:00.000000000 +0200
5786 @@ -76,7 +76,41 @@ static int ocfs2_get_inode_attr(struct i
5787         return status;
5788  }
5789  
5790 -static int ocfs2_set_inode_attr(struct inode *inode, unsigned flags,
5791 +int ocfs2_sync_flags(struct inode *inode, int flags, int vflags)
5792 +{
5793 +       struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
5794 +       struct buffer_head *bh = NULL;
5795 +       handle_t *handle = NULL;
5796 +       int status;
5797 +
5798 +       status = ocfs2_inode_lock(inode, &bh, 1);
5799 +       if (status < 0) {
5800 +               mlog_errno(status);
5801 +               return status;
5802 +       }
5803 +       handle = ocfs2_start_trans(osb, OCFS2_INODE_UPDATE_CREDITS);
5804 +       if (IS_ERR(handle)) {
5805 +               status = PTR_ERR(handle);
5806 +               mlog_errno(status);
5807 +               goto bail_unlock;
5808 +       }
5809 +
5810 +       inode->i_flags = flags;
5811 +       inode->i_vflags = vflags;
5812 +       ocfs2_get_inode_flags(OCFS2_I(inode));
5813 +
5814 +       status = ocfs2_mark_inode_dirty(handle, inode, bh);
5815 +       if (status < 0)
5816 +               mlog_errno(status);
5817 +
5818 +       ocfs2_commit_trans(osb, handle);
5819 +bail_unlock:
5820 +       ocfs2_inode_unlock(inode, 1);
5821 +       brelse(bh);
5822 +       return status;
5823 +}
5824 +
5825 +int ocfs2_set_inode_attr(struct inode *inode, unsigned flags,
5826                                 unsigned mask)
5827  {
5828         struct ocfs2_inode_info *ocfs2_inode = OCFS2_I(inode);
5829 @@ -101,6 +135,11 @@ static int ocfs2_set_inode_attr(struct i
5830         if (!S_ISDIR(inode->i_mode))
5831                 flags &= ~OCFS2_DIRSYNC_FL;
5832  
5833 +       if (IS_BARRIER(inode)) {
5834 +               vxwprintk_task(1, "messing with the barrier.");
5835 +               goto bail_unlock;
5836 +       }
5837 +
5838         handle = ocfs2_start_trans(osb, OCFS2_INODE_UPDATE_CREDITS);
5839         if (IS_ERR(handle)) {
5840                 status = PTR_ERR(handle);
5841 @@ -879,6 +918,7 @@ bail:
5842         return status;
5843  }
5844  
5845 +
5846  long ocfs2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
5847  {
5848         struct inode *inode = filp->f_path.dentry->d_inode;
5849 diff -NurpP --minimal linux-3.6.9/fs/ocfs2/namei.c linux-3.6.9-vs2.3.4.4/fs/ocfs2/namei.c
5850 --- linux-3.6.9/fs/ocfs2/namei.c        2012-10-04 15:27:41.000000000 +0200
5851 +++ linux-3.6.9-vs2.3.4.4/fs/ocfs2/namei.c      2012-10-04 18:47:00.000000000 +0200
5852 @@ -41,6 +41,7 @@
5853  #include <linux/slab.h>
5854  #include <linux/highmem.h>
5855  #include <linux/quotaops.h>
5856 +#include <linux/vs_tag.h>
5857  
5858  #include <cluster/masklog.h>
5859  
5860 @@ -475,6 +476,7 @@ static int __ocfs2_mknod_locked(struct i
5861         struct ocfs2_dinode *fe = NULL;
5862         struct ocfs2_extent_list *fel;
5863         u16 feat;
5864 +       vs_tag_t tag;
5865  
5866         *new_fe_bh = NULL;
5867  
5868 @@ -512,8 +514,11 @@ static int __ocfs2_mknod_locked(struct i
5869         fe->i_suballoc_loc = cpu_to_le64(suballoc_loc);
5870         fe->i_suballoc_bit = cpu_to_le16(suballoc_bit);
5871         fe->i_suballoc_slot = cpu_to_le16(inode_ac->ac_alloc_slot);
5872 -       fe->i_uid = cpu_to_le32(inode->i_uid);
5873 -       fe->i_gid = cpu_to_le32(inode->i_gid);
5874 +
5875 +       tag = dx_current_fstag(osb->sb);
5876 +       fe->i_uid = cpu_to_le32(TAGINO_UID(DX_TAG(inode), inode->i_uid, tag));
5877 +       fe->i_gid = cpu_to_le32(TAGINO_GID(DX_TAG(inode), inode->i_gid, tag));
5878 +       inode->i_tag = tag;
5879         fe->i_mode = cpu_to_le16(inode->i_mode);
5880         if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode))
5881                 fe->id1.dev1.i_rdev = cpu_to_le64(huge_encode_dev(dev));
5882 diff -NurpP --minimal linux-3.6.9/fs/ocfs2/ocfs2.h linux-3.6.9-vs2.3.4.4/fs/ocfs2/ocfs2.h
5883 --- linux-3.6.9/fs/ocfs2/ocfs2.h        2012-01-09 16:14:55.000000000 +0100
5884 +++ linux-3.6.9-vs2.3.4.4/fs/ocfs2/ocfs2.h      2012-10-04 18:47:00.000000000 +0200
5885 @@ -272,6 +272,7 @@ enum ocfs2_mount_options
5886                                                      writes */
5887         OCFS2_MOUNT_HB_NONE = 1 << 13, /* No heartbeat */
5888         OCFS2_MOUNT_HB_GLOBAL = 1 << 14, /* Global heartbeat */
5889 +       OCFS2_MOUNT_TAGGED = 1 << 15, /* use tagging */
5890  };
5891  
5892  #define OCFS2_OSB_SOFT_RO                      0x0001
5893 diff -NurpP --minimal linux-3.6.9/fs/ocfs2/ocfs2_fs.h linux-3.6.9-vs2.3.4.4/fs/ocfs2/ocfs2_fs.h
5894 --- linux-3.6.9/fs/ocfs2/ocfs2_fs.h     2011-05-22 16:17:53.000000000 +0200
5895 +++ linux-3.6.9-vs2.3.4.4/fs/ocfs2/ocfs2_fs.h   2012-10-04 18:47:00.000000000 +0200
5896 @@ -266,6 +266,11 @@
5897  #define OCFS2_TOPDIR_FL                        FS_TOPDIR_FL    /* Top of directory hierarchies*/
5898  #define OCFS2_RESERVED_FL              FS_RESERVED_FL  /* reserved for ext2 lib */
5899  
5900 +#define OCFS2_IXUNLINK_FL              FS_IXUNLINK_FL  /* Immutable invert on unlink */
5901 +
5902 +#define OCFS2_BARRIER_FL               FS_BARRIER_FL   /* Barrier for chroot() */
5903 +#define OCFS2_COW_FL                   FS_COW_FL       /* Copy on Write marker */
5904 +
5905  #define OCFS2_FL_VISIBLE               FS_FL_USER_VISIBLE      /* User visible flags */
5906  #define OCFS2_FL_MODIFIABLE            FS_FL_USER_MODIFIABLE   /* User modifiable flags */
5907  
5908 diff -NurpP --minimal linux-3.6.9/fs/ocfs2/super.c linux-3.6.9-vs2.3.4.4/fs/ocfs2/super.c
5909 --- linux-3.6.9/fs/ocfs2/super.c        2012-05-21 18:07:26.000000000 +0200
5910 +++ linux-3.6.9-vs2.3.4.4/fs/ocfs2/super.c      2012-10-04 18:47:00.000000000 +0200
5911 @@ -185,6 +185,7 @@ enum {
5912         Opt_coherency_full,
5913         Opt_resv_level,
5914         Opt_dir_resv_level,
5915 +       Opt_tag, Opt_notag, Opt_tagid,
5916         Opt_err,
5917  };
5918  
5919 @@ -216,6 +217,9 @@ static const match_table_t tokens = {
5920         {Opt_coherency_full, "coherency=full"},
5921         {Opt_resv_level, "resv_level=%u"},
5922         {Opt_dir_resv_level, "dir_resv_level=%u"},
5923 +       {Opt_tag, "tag"},
5924 +       {Opt_notag, "notag"},
5925 +       {Opt_tagid, "tagid=%u"},
5926         {Opt_err, NULL}
5927  };
5928  
5929 @@ -662,6 +666,13 @@ static int ocfs2_remount(struct super_bl
5930                 goto out;
5931         }
5932  
5933 +       if ((osb->s_mount_opt & OCFS2_MOUNT_TAGGED) !=
5934 +           (parsed_options.mount_opt & OCFS2_MOUNT_TAGGED)) {
5935 +               ret = -EINVAL;
5936 +               mlog(ML_ERROR, "Cannot change tagging on remount\n");
5937 +               goto out;
5938 +       }
5939 +
5940         /* We're going to/from readonly mode. */
5941         if ((*flags & MS_RDONLY) != (sb->s_flags & MS_RDONLY)) {
5942                 /* Disable quota accounting before remounting RO */
5943 @@ -1177,6 +1188,9 @@ static int ocfs2_fill_super(struct super
5944  
5945         ocfs2_complete_mount_recovery(osb);
5946  
5947 +       if (osb->s_mount_opt & OCFS2_MOUNT_TAGGED)
5948 +               sb->s_flags |= MS_TAGGED;
5949 +
5950         if (ocfs2_mount_local(osb))
5951                 snprintf(nodestr, sizeof(nodestr), "local");
5952         else
5953 @@ -1503,6 +1517,20 @@ static int ocfs2_parse_options(struct su
5954                             option < OCFS2_MAX_RESV_LEVEL)
5955                                 mopt->dir_resv_level = option;
5956                         break;
5957 +#ifndef CONFIG_TAGGING_NONE
5958 +               case Opt_tag:
5959 +                       mopt->mount_opt |= OCFS2_MOUNT_TAGGED;
5960 +                       break;
5961 +               case Opt_notag:
5962 +                       mopt->mount_opt &= ~OCFS2_MOUNT_TAGGED;
5963 +                       break;
5964 +#endif
5965 +#ifdef CONFIG_PROPAGATE
5966 +               case Opt_tagid:
5967 +                       /* use args[0] */
5968 +                       mopt->mount_opt |= OCFS2_MOUNT_TAGGED;
5969 +                       break;
5970 +#endif
5971                 default:
5972                         mlog(ML_ERROR,
5973                              "Unrecognized mount option \"%s\" "
5974 diff -NurpP --minimal linux-3.6.9/fs/open.c linux-3.6.9-vs2.3.4.4/fs/open.c
5975 --- linux-3.6.9/fs/open.c       2012-10-04 15:27:41.000000000 +0200
5976 +++ linux-3.6.9-vs2.3.4.4/fs/open.c     2012-10-04 18:47:00.000000000 +0200
5977 @@ -30,6 +30,11 @@
5978  #include <linux/fs_struct.h>
5979  #include <linux/ima.h>
5980  #include <linux/dnotify.h>
5981 +#include <linux/vs_base.h>
5982 +#include <linux/vs_limit.h>
5983 +#include <linux/vs_tag.h>
5984 +#include <linux/vs_cowbl.h>
5985 +#include <linux/vserver/dlimit.h>
5986  
5987  #include "internal.h"
5988  
5989 @@ -74,6 +79,12 @@ static long do_sys_truncate(const char _
5990         error = user_path(pathname, &path);
5991         if (error)
5992                 goto out;
5993 +
5994 +#ifdef CONFIG_VSERVER_COWBL
5995 +       error = cow_check_and_break(&path);
5996 +       if (error)
5997 +               goto dput_and_out;
5998 +#endif
5999         inode = path.dentry->d_inode;
6000  
6001         /* For directories it's -EISDIR, for other non-regulars - -EINVAL */
6002 @@ -495,6 +506,10 @@ SYSCALL_DEFINE3(fchmodat, int, dfd, cons
6003  
6004         error = user_path_at(dfd, filename, LOOKUP_FOLLOW, &path);
6005         if (!error) {
6006 +#ifdef CONFIG_VSERVER_COWBL
6007 +               error = cow_check_and_break(&path);
6008 +               if (!error)
6009 +#endif
6010                 error = chmod_common(&path, mode);
6011                 path_put(&path);
6012         }
6013 @@ -522,13 +537,13 @@ static int chown_common(struct path *pat
6014                 if (!uid_valid(uid))
6015                         return -EINVAL;
6016                 newattrs.ia_valid |= ATTR_UID;
6017 -               newattrs.ia_uid = uid;
6018 +               newattrs.ia_uid = dx_map_uid(user);
6019         }
6020         if (group != (gid_t) -1) {
6021                 if (!gid_valid(gid))
6022                         return -EINVAL;
6023                 newattrs.ia_valid |= ATTR_GID;
6024 -               newattrs.ia_gid = gid;
6025 +               newattrs.ia_gid = dx_map_gid(group);
6026         }
6027         if (!S_ISDIR(inode->i_mode))
6028                 newattrs.ia_valid |=
6029 @@ -561,6 +576,18 @@ SYSCALL_DEFINE5(fchownat, int, dfd, cons
6030         error = mnt_want_write(path.mnt);
6031         if (error)
6032                 goto out_release;
6033 +#ifdef CONFIG_VSERVER_COWBL
6034 +       error = cow_check_and_break(&path);
6035 +       if (!error)
6036 +#endif
6037 +#ifdef CONFIG_VSERVER_COWBL
6038 +       error = cow_check_and_break(&path);
6039 +       if (!error)
6040 +#endif
6041 +#ifdef CONFIG_VSERVER_COWBL
6042 +       error = cow_check_and_break(&path);
6043 +       if (!error)
6044 +#endif
6045         error = chown_common(&path, user, group);
6046         mnt_drop_write(path.mnt);
6047  out_release:
6048 @@ -809,6 +836,7 @@ static void __put_unused_fd(struct files
6049         __clear_open_fd(fd, fdt);
6050         if (fd < files->next_fd)
6051                 files->next_fd = fd;
6052 +       vx_openfd_dec(fd);
6053  }
6054  
6055  void put_unused_fd(unsigned int fd)
6056 diff -NurpP --minimal linux-3.6.9/fs/proc/array.c linux-3.6.9-vs2.3.4.4/fs/proc/array.c
6057 --- linux-3.6.9/fs/proc/array.c 2012-07-22 23:39:42.000000000 +0200
6058 +++ linux-3.6.9-vs2.3.4.4/fs/proc/array.c       2012-10-04 18:47:00.000000000 +0200
6059 @@ -82,6 +82,8 @@
6060  #include <linux/ptrace.h>
6061  #include <linux/tracehook.h>
6062  #include <linux/user_namespace.h>
6063 +#include <linux/vs_context.h>
6064 +#include <linux/vs_network.h>
6065  
6066  #include <asm/pgtable.h>
6067  #include <asm/processor.h>
6068 @@ -172,6 +174,9 @@ static inline void task_state(struct seq
6069         rcu_read_lock();
6070         ppid = pid_alive(p) ?
6071                 task_tgid_nr_ns(rcu_dereference(p->real_parent), ns) : 0;
6072 +       if (unlikely(vx_current_initpid(p->pid)))
6073 +               ppid = 0;
6074 +
6075         tpid = 0;
6076         if (pid_alive(p)) {
6077                 struct task_struct *tracer = ptrace_parent(p);
6078 @@ -296,7 +301,7 @@ static inline void task_sig(struct seq_f
6079  }
6080  
6081  static void render_cap_t(struct seq_file *m, const char *header,
6082 -                       kernel_cap_t *a)
6083 +                       struct vx_info *vxi, kernel_cap_t *a)
6084  {
6085         unsigned __capi;
6086  
6087 @@ -321,10 +326,11 @@ static inline void task_cap(struct seq_f
6088         cap_bset        = cred->cap_bset;
6089         rcu_read_unlock();
6090  
6091 -       render_cap_t(m, "CapInh:\t", &cap_inheritable);
6092 -       render_cap_t(m, "CapPrm:\t", &cap_permitted);
6093 -       render_cap_t(m, "CapEff:\t", &cap_effective);
6094 -       render_cap_t(m, "CapBnd:\t", &cap_bset);
6095 +       /* FIXME: maybe move the p->vx_info masking to __task_cred() ? */
6096 +       render_cap_t(m, "CapInh:\t", p->vx_info, &cap_inheritable);
6097 +       render_cap_t(m, "CapPrm:\t", p->vx_info, &cap_permitted);
6098 +       render_cap_t(m, "CapEff:\t", p->vx_info, &cap_effective);
6099 +       render_cap_t(m, "CapBnd:\t", p->vx_info, &cap_bset);
6100  }
6101  
6102  static inline void task_context_switch_counts(struct seq_file *m,
6103 @@ -346,6 +352,42 @@ static void task_cpus_allowed(struct seq
6104         seq_putc(m, '\n');
6105  }
6106  
6107 +int proc_pid_nsproxy(struct seq_file *m, struct pid_namespace *ns,
6108 +                       struct pid *pid, struct task_struct *task)
6109 +{
6110 +       seq_printf(m,   "Proxy:\t%p(%c)\n"
6111 +                       "Count:\t%u\n"
6112 +                       "uts:\t%p(%c)\n"
6113 +                       "ipc:\t%p(%c)\n"
6114 +                       "mnt:\t%p(%c)\n"
6115 +                       "pid:\t%p(%c)\n"
6116 +                       "net:\t%p(%c)\n",
6117 +                       task->nsproxy,
6118 +                       (task->nsproxy == init_task.nsproxy ? 'I' : '-'),
6119 +                       atomic_read(&task->nsproxy->count),
6120 +                       task->nsproxy->uts_ns,
6121 +                       (task->nsproxy->uts_ns == init_task.nsproxy->uts_ns ? 'I' : '-'),
6122 +                       task->nsproxy->ipc_ns,
6123 +                       (task->nsproxy->ipc_ns == init_task.nsproxy->ipc_ns ? 'I' : '-'),
6124 +                       task->nsproxy->mnt_ns,
6125 +                       (task->nsproxy->mnt_ns == init_task.nsproxy->mnt_ns ? 'I' : '-'),
6126 +                       task->nsproxy->pid_ns,
6127 +                       (task->nsproxy->pid_ns == init_task.nsproxy->pid_ns ? 'I' : '-'),
6128 +                       task->nsproxy->net_ns,
6129 +                       (task->nsproxy->net_ns == init_task.nsproxy->net_ns ? 'I' : '-'));
6130 +       return 0;
6131 +}
6132 +
6133 +void task_vs_id(struct seq_file *m, struct task_struct *task)
6134 +{
6135 +       if (task_vx_flags(task, VXF_HIDE_VINFO, 0))
6136 +               return;
6137 +
6138 +       seq_printf(m, "VxID: %d\n", vx_task_xid(task));
6139 +       seq_printf(m, "NxID: %d\n", nx_task_nid(task));
6140 +}
6141 +
6142 +
6143  int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
6144                         struct pid *pid, struct task_struct *task)
6145  {
6146 @@ -362,6 +404,7 @@ int proc_pid_status(struct seq_file *m, 
6147         task_cap(m, task);
6148         task_cpus_allowed(m, task);
6149         cpuset_task_status_allowed(m, task);
6150 +       task_vs_id(m, task);
6151         task_context_switch_counts(m, task);
6152         return 0;
6153  }
6154 @@ -471,6 +514,17 @@ static int do_task_stat(struct seq_file 
6155         /* convert nsec -> ticks */
6156         start_time = nsec_to_clock_t(start_time);
6157  
6158 +       /* fixup start time for virt uptime */
6159 +       if (vx_flags(VXF_VIRT_UPTIME, 0)) {
6160 +               unsigned long long bias =
6161 +                       current->vx_info->cvirt.bias_clock;
6162 +
6163 +               if (start_time > bias)
6164 +                       start_time -= bias;
6165 +               else
6166 +                       start_time = 0;
6167 +       }
6168 +
6169         seq_printf(m, "%d (%s) %c", pid_nr_ns(pid, ns), tcomm, state);
6170         seq_put_decimal_ll(m, ' ', ppid);
6171         seq_put_decimal_ll(m, ' ', pgid);
6172 diff -NurpP --minimal linux-3.6.9/fs/proc/base.c linux-3.6.9-vs2.3.4.4/fs/proc/base.c
6173 --- linux-3.6.9/fs/proc/base.c  2012-10-04 15:27:41.000000000 +0200
6174 +++ linux-3.6.9-vs2.3.4.4/fs/proc/base.c        2012-10-04 18:47:00.000000000 +0200
6175 @@ -85,6 +85,8 @@
6176  #include <linux/fs_struct.h>
6177  #include <linux/slab.h>
6178  #include <linux/flex_array.h>
6179 +#include <linux/vs_context.h>
6180 +#include <linux/vs_network.h>
6181  #ifdef CONFIG_HARDWALL
6182  #include <asm/hardwall.h>
6183  #endif
6184 @@ -941,11 +943,16 @@ static ssize_t oom_adjust_write(struct f
6185                 goto err_task_lock;
6186         }
6187  
6188 -       if (oom_adjust < task->signal->oom_adj && !capable(CAP_SYS_RESOURCE)) {
6189 +       if (oom_adjust < task->signal->oom_adj &&
6190 +               !vx_capable(CAP_SYS_RESOURCE, VXC_OOM_ADJUST)) {
6191                 err = -EACCES;
6192                 goto err_sighand;
6193         }
6194  
6195 +       /* prevent guest processes from circumventing the oom killer */
6196 +       if (vx_current_xid() && (oom_adjust == OOM_DISABLE))
6197 +               oom_adjust = OOM_ADJUST_MIN;
6198 +
6199         /*
6200          * Warn that /proc/pid/oom_adj is deprecated, see
6201          * Documentation/feature-removal-schedule.txt.
6202 @@ -1548,6 +1555,8 @@ struct inode *proc_pid_make_inode(struct
6203                 inode->i_gid = cred->egid;
6204                 rcu_read_unlock();
6205         }
6206 +       /* procfs is xid tagged */
6207 +       inode->i_tag = (vs_tag_t)vx_task_xid(task);
6208         security_task_to_inode(task, inode);
6209  
6210  out:
6211 @@ -1593,6 +1602,8 @@ int pid_getattr(struct vfsmount *mnt, st
6212  
6213  /* dentry stuff */
6214  
6215 +static unsigned name_to_int(struct dentry *dentry);
6216 +
6217  /*
6218   *     Exceptional case: normally we are not allowed to unhash a busy
6219   * directory. In this case, however, we can do it - no aliasing problems
6220 @@ -1621,6 +1632,12 @@ int pid_revalidate(struct dentry *dentry
6221         task = get_proc_task(inode);
6222  
6223         if (task) {
6224 +               unsigned pid = name_to_int(dentry);
6225 +
6226 +               if (pid != ~0U && pid != vx_map_pid(task->pid)) {
6227 +                       put_task_struct(task);
6228 +                       goto drop;
6229 +               }
6230                 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
6231                     task_dumpable(task)) {
6232                         rcu_read_lock();
6233 @@ -1637,6 +1654,7 @@ int pid_revalidate(struct dentry *dentry
6234                 put_task_struct(task);
6235                 return 1;
6236         }
6237 +drop:
6238         d_drop(dentry);
6239         return 0;
6240  }
6241 @@ -2457,6 +2475,13 @@ static struct dentry *proc_pident_lookup
6242         if (!task)
6243                 goto out_no_task;
6244  
6245 +       /* TODO: maybe we can come up with a generic approach? */
6246 +       if (task_vx_flags(task, VXF_HIDE_VINFO, 0) &&
6247 +               (dentry->d_name.len == 5) &&
6248 +               (!memcmp(dentry->d_name.name, "vinfo", 5) ||
6249 +               !memcmp(dentry->d_name.name, "ninfo", 5)))
6250 +               goto out;
6251 +
6252         /*
6253          * Yes, it does not scale. And it should not. Don't add
6254          * new entries into /proc/<tgid>/ without very good reasons.
6255 @@ -2842,7 +2867,7 @@ out_iput:
6256  static struct dentry *proc_base_lookup(struct inode *dir, struct dentry *dentry)
6257  {
6258         struct dentry *error;
6259 -       struct task_struct *task = get_proc_task(dir);
6260 +       struct task_struct *task = get_proc_task_real(dir);
6261         const struct pid_entry *p, *last;
6262  
6263         error = ERR_PTR(-ENOENT);
6264 @@ -3017,6 +3042,9 @@ static int proc_pid_personality(struct s
6265  static const struct file_operations proc_task_operations;
6266  static const struct inode_operations proc_task_inode_operations;
6267  
6268 +extern int proc_pid_vx_info(struct task_struct *, char *);
6269 +extern int proc_pid_nx_info(struct task_struct *, char *);
6270 +
6271  static const struct pid_entry tgid_base_stuff[] = {
6272         DIR("task",       S_IRUGO|S_IXUGO, proc_task_inode_operations, proc_task_operations),
6273         DIR("fd",         S_IRUSR|S_IXUSR, proc_fd_inode_operations, proc_fd_operations),
6274 @@ -3083,6 +3111,8 @@ static const struct pid_entry tgid_base_
6275  #ifdef CONFIG_CGROUPS
6276         REG("cgroup",  S_IRUGO, proc_cgroup_operations),
6277  #endif
6278 +       INF("vinfo",      S_IRUGO, proc_pid_vx_info),
6279 +       INF("ninfo",      S_IRUGO, proc_pid_nx_info),
6280         INF("oom_score",  S_IRUGO, proc_oom_score),
6281         REG("oom_adj",    S_IRUGO|S_IWUSR, proc_oom_adjust_operations),
6282         REG("oom_score_adj", S_IRUGO|S_IWUSR, proc_oom_score_adj_operations),
6283 @@ -3106,6 +3136,7 @@ static const struct pid_entry tgid_base_
6284         REG("uid_map",    S_IRUGO|S_IWUSR, proc_uid_map_operations),
6285         REG("gid_map",    S_IRUGO|S_IWUSR, proc_gid_map_operations),
6286  #endif
6287 +       ONE("nsproxy",  S_IRUGO, proc_pid_nsproxy),
6288  };
6289  
6290  static int proc_tgid_base_readdir(struct file * filp,
6291 @@ -3300,7 +3331,7 @@ retry:
6292         iter.task = NULL;
6293         pid = find_ge_pid(iter.tgid, ns);
6294         if (pid) {
6295 -               iter.tgid = pid_nr_ns(pid, ns);
6296 +               iter.tgid = pid_unmapped_nr_ns(pid, ns);
6297                 iter.task = pid_task(pid, PIDTYPE_PID);
6298                 /* What we to know is if the pid we have find is the
6299                  * pid of a thread_group_leader.  Testing for task
6300 @@ -3330,7 +3361,7 @@ static int proc_pid_fill_cache(struct fi
6301         struct tgid_iter iter)
6302  {
6303         char name[PROC_NUMBUF];
6304 -       int len = snprintf(name, sizeof(name), "%d", iter.tgid);
6305 +       int len = snprintf(name, sizeof(name), "%d", vx_map_tgid(iter.tgid));
6306         return proc_fill_cache(filp, dirent, filldir, name, len,
6307                                 proc_pid_instantiate, iter.task, NULL);
6308  }
6309 @@ -3354,7 +3385,7 @@ int proc_pid_readdir(struct file * filp,
6310                 goto out_no_task;
6311         nr = filp->f_pos - FIRST_PROCESS_ENTRY;
6312  
6313 -       reaper = get_proc_task(filp->f_path.dentry->d_inode);
6314 +       reaper = get_proc_task_real(filp->f_path.dentry->d_inode);
6315         if (!reaper)
6316                 goto out_no_task;
6317  
6318 @@ -3376,6 +3407,8 @@ int proc_pid_readdir(struct file * filp,
6319                         __filldir = fake_filldir;
6320  
6321                 filp->f_pos = iter.tgid + TGID_OFFSET;
6322 +               if (!vx_proc_task_visible(iter.task))
6323 +                       continue;
6324                 if (proc_pid_fill_cache(filp, dirent, __filldir, iter) < 0) {
6325                         put_task_struct(iter.task);
6326                         goto out;
6327 @@ -3537,6 +3570,8 @@ static struct dentry *proc_task_lookup(s
6328         tid = name_to_int(dentry);
6329         if (tid == ~0U)
6330                 goto out;
6331 +       if (vx_current_initpid(tid))
6332 +               goto out;
6333  
6334         ns = dentry->d_sb->s_fs_info;
6335         rcu_read_lock();
6336 diff -NurpP --minimal linux-3.6.9/fs/proc/generic.c linux-3.6.9-vs2.3.4.4/fs/proc/generic.c
6337 --- linux-3.6.9/fs/proc/generic.c       2012-10-04 15:27:41.000000000 +0200
6338 +++ linux-3.6.9-vs2.3.4.4/fs/proc/generic.c     2012-10-04 18:47:00.000000000 +0200
6339 @@ -22,6 +22,7 @@
6340  #include <linux/bitops.h>
6341  #include <linux/spinlock.h>
6342  #include <linux/completion.h>
6343 +#include <linux/vserver/inode.h>
6344  #include <asm/uaccess.h>
6345  
6346  #include "internal.h"
6347 @@ -424,11 +425,15 @@ struct dentry *proc_lookup_de(struct pro
6348         for (de = de->subdir; de ; de = de->next) {
6349                 if (de->namelen != dentry->d_name.len)
6350                         continue;
6351 +               if (!vx_hide_check(0, de->vx_flags))
6352 +                       continue;
6353                 if (!memcmp(dentry->d_name.name, de->name, de->namelen)) {
6354                         pde_get(de);
6355                         spin_unlock(&proc_subdir_lock);
6356                         error = -EINVAL;
6357                         inode = proc_get_inode(dir->i_sb, de);
6358 +                       /* generic proc entries belong to the host */
6359 +                       inode->i_tag = 0;
6360                         goto out_unlock;
6361                 }
6362         }
6363 @@ -506,6 +511,8 @@ int proc_readdir_de(struct proc_dir_entr
6364  
6365                                 /* filldir passes info to user space */
6366                                 pde_get(de);
6367 +                               if (!vx_hide_check(0, de->vx_flags))
6368 +                                       goto skip;
6369                                 spin_unlock(&proc_subdir_lock);
6370                                 if (filldir(dirent, de->name, de->namelen, filp->f_pos,
6371                                             de->low_ino, de->mode >> 12) < 0) {
6372 @@ -513,6 +520,7 @@ int proc_readdir_de(struct proc_dir_entr
6373                                         goto out;
6374                                 }
6375                                 spin_lock(&proc_subdir_lock);
6376 +                       skip:
6377                                 filp->f_pos++;
6378                                 next = de->next;
6379                                 pde_put(de);
6380 @@ -626,6 +634,7 @@ static struct proc_dir_entry *__proc_cre
6381         ent->nlink = nlink;
6382         atomic_set(&ent->count, 1);
6383         ent->pde_users = 0;
6384 +       ent->vx_flags = IATTR_PROC_DEFAULT;
6385         spin_lock_init(&ent->pde_unload_lock);
6386         ent->pde_unload_completion = NULL;
6387         INIT_LIST_HEAD(&ent->pde_openers);
6388 @@ -649,7 +658,8 @@ struct proc_dir_entry *proc_symlink(cons
6389                                 kfree(ent->data);
6390                                 kfree(ent);
6391                                 ent = NULL;
6392 -                       }
6393 +                       } else
6394 +                               ent->vx_flags = IATTR_PROC_SYMLINK;
6395                 } else {
6396                         kfree(ent);
6397                         ent = NULL;
6398 diff -NurpP --minimal linux-3.6.9/fs/proc/inode.c linux-3.6.9-vs2.3.4.4/fs/proc/inode.c
6399 --- linux-3.6.9/fs/proc/inode.c 2012-07-22 23:39:42.000000000 +0200
6400 +++ linux-3.6.9-vs2.3.4.4/fs/proc/inode.c       2012-10-04 18:47:00.000000000 +0200
6401 @@ -458,6 +458,8 @@ struct inode *proc_get_inode(struct supe
6402                         inode->i_uid = de->uid;
6403                         inode->i_gid = de->gid;
6404                 }
6405 +               if (de->vx_flags)
6406 +                       PROC_I(inode)->vx_flags = de->vx_flags;
6407                 if (de->size)
6408                         inode->i_size = de->size;
6409                 if (de->nlink)
6410 diff -NurpP --minimal linux-3.6.9/fs/proc/internal.h linux-3.6.9-vs2.3.4.4/fs/proc/internal.h
6411 --- linux-3.6.9/fs/proc/internal.h      2012-10-04 15:27:41.000000000 +0200
6412 +++ linux-3.6.9-vs2.3.4.4/fs/proc/internal.h    2012-10-04 18:47:00.000000000 +0200
6413 @@ -10,6 +10,8 @@
6414   */
6415  
6416  #include <linux/proc_fs.h>
6417 +#include <linux/vs_pid.h>
6418 +
6419  struct  ctl_table_header;
6420  
6421  extern struct proc_dir_entry proc_root;
6422 @@ -52,6 +54,9 @@ extern int proc_pid_status(struct seq_fi
6423                                 struct pid *pid, struct task_struct *task);
6424  extern int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
6425                                 struct pid *pid, struct task_struct *task);
6426 +extern int proc_pid_nsproxy(struct seq_file *m, struct pid_namespace *ns,
6427 +                               struct pid *pid, struct task_struct *task);
6428 +
6429  extern loff_t mem_lseek(struct file *file, loff_t offset, int orig);
6430  
6431  extern const struct file_operations proc_tid_children_operations;
6432 @@ -81,11 +86,16 @@ static inline struct pid *proc_pid(struc
6433         return PROC_I(inode)->pid;
6434  }
6435  
6436 -static inline struct task_struct *get_proc_task(struct inode *inode)
6437 +static inline struct task_struct *get_proc_task_real(struct inode *inode)
6438  {
6439         return get_pid_task(proc_pid(inode), PIDTYPE_PID);
6440  }
6441  
6442 +static inline struct task_struct *get_proc_task(struct inode *inode)
6443 +{
6444 +       return vx_get_proc_task(inode, proc_pid(inode));
6445 +}
6446 +
6447  static inline int proc_fd(struct inode *inode)
6448  {
6449         return PROC_I(inode)->fd;
6450 diff -NurpP --minimal linux-3.6.9/fs/proc/loadavg.c linux-3.6.9-vs2.3.4.4/fs/proc/loadavg.c
6451 --- linux-3.6.9/fs/proc/loadavg.c       2009-09-10 15:26:23.000000000 +0200
6452 +++ linux-3.6.9-vs2.3.4.4/fs/proc/loadavg.c     2012-10-04 18:47:00.000000000 +0200
6453 @@ -12,15 +12,27 @@
6454  
6455  static int loadavg_proc_show(struct seq_file *m, void *v)
6456  {
6457 +       unsigned long running;
6458 +       unsigned int threads;
6459         unsigned long avnrun[3];
6460  
6461         get_avenrun(avnrun, FIXED_1/200, 0);
6462  
6463 +       if (vx_flags(VXF_VIRT_LOAD, 0)) {
6464 +               struct vx_info *vxi = current_vx_info();
6465 +
6466 +               running = atomic_read(&vxi->cvirt.nr_running);
6467 +               threads = atomic_read(&vxi->cvirt.nr_threads);
6468 +       } else {
6469 +               running = nr_running();
6470 +               threads = nr_threads;
6471 +       }
6472 +
6473         seq_printf(m, "%lu.%02lu %lu.%02lu %lu.%02lu %ld/%d %d\n",
6474                 LOAD_INT(avnrun[0]), LOAD_FRAC(avnrun[0]),
6475                 LOAD_INT(avnrun[1]), LOAD_FRAC(avnrun[1]),
6476                 LOAD_INT(avnrun[2]), LOAD_FRAC(avnrun[2]),
6477 -               nr_running(), nr_threads,
6478 +               running, threads,
6479                 task_active_pid_ns(current)->last_pid);
6480         return 0;
6481  }
6482 diff -NurpP --minimal linux-3.6.9/fs/proc/meminfo.c linux-3.6.9-vs2.3.4.4/fs/proc/meminfo.c
6483 --- linux-3.6.9/fs/proc/meminfo.c       2012-01-09 16:14:55.000000000 +0100
6484 +++ linux-3.6.9-vs2.3.4.4/fs/proc/meminfo.c     2012-10-04 18:47:00.000000000 +0200
6485 @@ -39,7 +39,8 @@ static int meminfo_proc_show(struct seq_
6486         allowed = ((totalram_pages - hugetlb_total_pages())
6487                 * sysctl_overcommit_ratio / 100) + total_swap_pages;
6488  
6489 -       cached = global_page_state(NR_FILE_PAGES) -
6490 +       cached = vx_flags(VXF_VIRT_MEM, 0) ?
6491 +               vx_vsi_cached(&i) : global_page_state(NR_FILE_PAGES) -
6492                         total_swapcache_pages - i.bufferram;
6493         if (cached < 0)
6494                 cached = 0;
6495 diff -NurpP --minimal linux-3.6.9/fs/proc/root.c linux-3.6.9-vs2.3.4.4/fs/proc/root.c
6496 --- linux-3.6.9/fs/proc/root.c  2012-10-04 15:27:41.000000000 +0200
6497 +++ linux-3.6.9-vs2.3.4.4/fs/proc/root.c        2012-10-04 18:47:00.000000000 +0200
6498 @@ -19,9 +19,14 @@
6499  #include <linux/mount.h>
6500  #include <linux/pid_namespace.h>
6501  #include <linux/parser.h>
6502 +#include <linux/vserver/inode.h>
6503  
6504  #include "internal.h"
6505  
6506 +struct proc_dir_entry *proc_virtual;
6507 +
6508 +extern void proc_vx_init(void);
6509 +
6510  static int proc_test_super(struct super_block *sb, void *data)
6511  {
6512         return sb->s_fs_info == data;
6513 @@ -189,6 +194,7 @@ void __init proc_root_init(void)
6514  #endif
6515         proc_mkdir("bus", NULL);
6516         proc_sys_init();
6517 +       proc_vx_init();
6518  }
6519  
6520  static int proc_root_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat
6521 @@ -255,6 +261,7 @@ struct proc_dir_entry proc_root = {
6522         .proc_iops      = &proc_root_inode_operations, 
6523         .proc_fops      = &proc_root_operations,
6524         .parent         = &proc_root,
6525 +       .vx_flags       = IATTR_ADMIN | IATTR_WATCH,
6526         .name           = "/proc",
6527  };
6528  
6529 diff -NurpP --minimal linux-3.6.9/fs/proc/stat.c linux-3.6.9-vs2.3.4.4/fs/proc/stat.c
6530 --- linux-3.6.9/fs/proc/stat.c  2012-12-08 01:34:14.000000000 +0100
6531 +++ linux-3.6.9-vs2.3.4.4/fs/proc/stat.c        2012-11-06 18:43:41.000000000 +0100
6532 @@ -9,6 +9,7 @@
6533  #include <linux/slab.h>
6534  #include <linux/time.h>
6535  #include <linux/irqnr.h>
6536 +#include <linux/vserver/cvirt.h>
6537  #include <asm/cputime.h>
6538  #include <linux/tick.h>
6539  
6540 @@ -92,6 +93,10 @@ static int show_stat(struct seq_file *p,
6541                 irq = softirq = steal = 0;
6542         guest = guest_nice = 0;
6543         getboottime(&boottime);
6544 +
6545 +       if (vx_flags(VXF_VIRT_UPTIME, 0))
6546 +               vx_vsi_boottime(&boottime);
6547 +
6548         jif = boottime.tv_sec;
6549  
6550         for_each_possible_cpu(i) {
6551 diff -NurpP --minimal linux-3.6.9/fs/proc/uptime.c linux-3.6.9-vs2.3.4.4/fs/proc/uptime.c
6552 --- linux-3.6.9/fs/proc/uptime.c        2012-03-19 19:47:26.000000000 +0100
6553 +++ linux-3.6.9-vs2.3.4.4/fs/proc/uptime.c      2012-10-04 18:47:00.000000000 +0200
6554 @@ -5,6 +5,7 @@
6555  #include <linux/seq_file.h>
6556  #include <linux/time.h>
6557  #include <linux/kernel_stat.h>
6558 +#include <linux/vserver/cvirt.h>
6559  #include <asm/cputime.h>
6560  
6561  static int uptime_proc_show(struct seq_file *m, void *v)
6562 @@ -25,6 +26,10 @@ static int uptime_proc_show(struct seq_f
6563         nsec = cputime64_to_jiffies64(idletime) * TICK_NSEC;
6564         idle.tv_sec = div_u64_rem(nsec, NSEC_PER_SEC, &rem);
6565         idle.tv_nsec = rem;
6566 +
6567 +       if (vx_flags(VXF_VIRT_UPTIME, 0))
6568 +               vx_vsi_uptime(&uptime, &idle);
6569 +
6570         seq_printf(m, "%lu.%02lu %lu.%02lu\n",
6571                         (unsigned long) uptime.tv_sec,
6572                         (uptime.tv_nsec / (NSEC_PER_SEC / 100)),
6573 diff -NurpP --minimal linux-3.6.9/fs/proc_namespace.c linux-3.6.9-vs2.3.4.4/fs/proc_namespace.c
6574 --- linux-3.6.9/fs/proc_namespace.c     2012-10-04 15:27:41.000000000 +0200
6575 +++ linux-3.6.9-vs2.3.4.4/fs/proc_namespace.c   2012-10-04 18:47:00.000000000 +0200
6576 @@ -44,6 +44,8 @@ static int show_sb_opts(struct seq_file 
6577                 { MS_SYNCHRONOUS, ",sync" },
6578                 { MS_DIRSYNC, ",dirsync" },
6579                 { MS_MANDLOCK, ",mand" },
6580 +               { MS_TAGGED, ",tag" },
6581 +               { MS_NOTAGCHECK, ",notagcheck" },
6582                 { 0, NULL }
6583         };
6584         const struct proc_fs_info *fs_infop;
6585 @@ -80,6 +82,34 @@ static inline void mangle(struct seq_fil
6586         seq_escape(m, s, " \t\n\\");
6587  }
6588  
6589 +static int mnt_is_reachable(struct vfsmount *vfsmnt)
6590 +{
6591 +       struct path root;
6592 +       struct dentry *point;
6593 +       struct mount *mnt = real_mount(vfsmnt);
6594 +       struct mount *root_mnt;
6595 +       int ret;
6596 +
6597 +       if (mnt == mnt->mnt_ns->root)
6598 +               return 1;
6599 +
6600 +       br_read_lock(&vfsmount_lock);
6601 +       root = current->fs->root;
6602 +       root_mnt = real_mount(root.mnt);
6603 +       point = root.dentry;
6604 +
6605 +       while ((mnt != mnt->mnt_parent) && (mnt != root_mnt)) {
6606 +               point = mnt->mnt_mountpoint;
6607 +               mnt = mnt->mnt_parent;
6608 +       }
6609 +
6610 +       ret = (mnt == root_mnt) && is_subdir(point, root.dentry);
6611 +
6612 +       br_read_unlock(&vfsmount_lock);
6613 +
6614 +       return ret;
6615 +}
6616 +
6617  static void show_type(struct seq_file *m, struct super_block *sb)
6618  {
6619         mangle(m, sb->s_type->name);
6620 @@ -96,6 +126,17 @@ static int show_vfsmnt(struct seq_file *
6621         struct path mnt_path = { .dentry = mnt->mnt_root, .mnt = mnt };
6622         struct super_block *sb = mnt_path.dentry->d_sb;
6623  
6624 +       if (vx_flags(VXF_HIDE_MOUNT, 0))
6625 +               return SEQ_SKIP;
6626 +       if (!mnt_is_reachable(mnt) && !vx_check(0, VS_WATCH_P))
6627 +               return SEQ_SKIP;
6628 +
6629 +       if (!vx_check(0, VS_ADMIN|VS_WATCH) &&
6630 +               mnt == current->fs->root.mnt) {
6631 +               seq_puts(m, "/dev/root / ");
6632 +               goto type;
6633 +       }
6634 +
6635         if (sb->s_op->show_devname) {
6636                 err = sb->s_op->show_devname(m, mnt_path.dentry);
6637                 if (err)
6638 @@ -106,6 +147,7 @@ static int show_vfsmnt(struct seq_file *
6639         seq_putc(m, ' ');
6640         seq_path(m, &mnt_path, " \t\n\\");
6641         seq_putc(m, ' ');
6642 +type:
6643         show_type(m, sb);
6644         seq_puts(m, __mnt_is_readonly(mnt) ? " ro" : " rw");
6645         err = show_sb_opts(m, sb);
6646 @@ -128,6 +170,11 @@ static int show_mountinfo(struct seq_fil
6647         struct path root = p->root;
6648         int err = 0;
6649  
6650 +       if (vx_flags(VXF_HIDE_MOUNT, 0))
6651 +               return SEQ_SKIP;
6652 +       if (!mnt_is_reachable(mnt) && !vx_check(0, VS_WATCH_P))
6653 +               return SEQ_SKIP;
6654 +
6655         seq_printf(m, "%i %i %u:%u ", r->mnt_id, r->mnt_parent->mnt_id,
6656                    MAJOR(sb->s_dev), MINOR(sb->s_dev));
6657         if (sb->s_op->show_path)
6658 @@ -187,6 +234,17 @@ static int show_vfsstat(struct seq_file 
6659         struct super_block *sb = mnt_path.dentry->d_sb;
6660         int err = 0;
6661  
6662 +       if (vx_flags(VXF_HIDE_MOUNT, 0))
6663 +               return SEQ_SKIP;
6664 +       if (!mnt_is_reachable(mnt) && !vx_check(0, VS_WATCH_P))
6665 +               return SEQ_SKIP;
6666 +
6667 +       if (!vx_check(0, VS_ADMIN|VS_WATCH) &&
6668 +               mnt == current->fs->root.mnt) {
6669 +               seq_puts(m, "device /dev/root mounted on / ");
6670 +               goto type;
6671 +       }
6672 +
6673         /* device */
6674         if (sb->s_op->show_devname) {
6675                 seq_puts(m, "device ");
6676 @@ -203,7 +261,7 @@ static int show_vfsstat(struct seq_file 
6677         seq_puts(m, " mounted on ");
6678         seq_path(m, &mnt_path, " \t\n\\");
6679         seq_putc(m, ' ');
6680 -
6681 +type:
6682         /* file system type */
6683         seq_puts(m, "with fstype ");
6684         show_type(m, sb);
6685 diff -NurpP --minimal linux-3.6.9/fs/quota/dquot.c linux-3.6.9-vs2.3.4.4/fs/quota/dquot.c
6686 --- linux-3.6.9/fs/quota/dquot.c        2012-10-04 15:27:41.000000000 +0200
6687 +++ linux-3.6.9-vs2.3.4.4/fs/quota/dquot.c      2012-10-04 18:47:00.000000000 +0200
6688 @@ -1580,6 +1580,9 @@ int __dquot_alloc_space(struct inode *in
6689         struct dquot **dquots = inode->i_dquot;
6690         int reserve = flags & DQUOT_SPACE_RESERVE;
6691  
6692 +       if ((ret = dl_alloc_space(inode, number)))
6693 +               return ret;
6694 +
6695         /*
6696          * First test before acquiring mutex - solves deadlocks when we
6697          * re-enter the quota code and are already holding the mutex
6698 @@ -1635,6 +1638,9 @@ int dquot_alloc_inode(const struct inode
6699         struct dquot_warn warn[MAXQUOTAS];
6700         struct dquot * const *dquots = inode->i_dquot;
6701  
6702 +       if ((ret = dl_alloc_inode(inode)))
6703 +               return ret;
6704 +
6705         /* First test before acquiring mutex - solves deadlocks when we
6706           * re-enter the quota code and are already holding the mutex */
6707         if (!dquot_active(inode))
6708 @@ -1706,6 +1712,8 @@ void __dquot_free_space(struct inode *in
6709         struct dquot **dquots = inode->i_dquot;
6710         int reserve = flags & DQUOT_SPACE_RESERVE;
6711  
6712 +       dl_free_space(inode, number);
6713 +
6714         /* First test before acquiring mutex - solves deadlocks when we
6715           * re-enter the quota code and are already holding the mutex */
6716         if (!dquot_active(inode)) {
6717 @@ -1750,6 +1758,8 @@ void dquot_free_inode(const struct inode
6718         struct dquot_warn warn[MAXQUOTAS];
6719         struct dquot * const *dquots = inode->i_dquot;
6720  
6721 +       dl_free_inode(inode);
6722 +
6723         /* First test before acquiring mutex - solves deadlocks when we
6724           * re-enter the quota code and are already holding the mutex */
6725         if (!dquot_active(inode))
6726 diff -NurpP --minimal linux-3.6.9/fs/quota/quota.c linux-3.6.9-vs2.3.4.4/fs/quota/quota.c
6727 --- linux-3.6.9/fs/quota/quota.c        2012-10-04 15:27:41.000000000 +0200
6728 +++ linux-3.6.9-vs2.3.4.4/fs/quota/quota.c      2012-10-04 18:47:00.000000000 +0200
6729 @@ -8,6 +8,7 @@
6730  #include <linux/fs.h>
6731  #include <linux/namei.h>
6732  #include <linux/slab.h>
6733 +#include <linux/vs_context.h>
6734  #include <asm/current.h>
6735  #include <linux/uaccess.h>
6736  #include <linux/kernel.h>
6737 @@ -37,7 +38,7 @@ static int check_quotactl_permission(str
6738                         break;
6739                 /*FALLTHROUGH*/
6740         default:
6741 -               if (!capable(CAP_SYS_ADMIN))
6742 +               if (!vx_capable(CAP_SYS_ADMIN, VXC_QUOTA_CTL))
6743                         return -EPERM;
6744         }
6745  
6746 @@ -291,6 +292,46 @@ static int do_quotactl(struct super_bloc
6747         }
6748  }
6749  
6750 +#if defined(CONFIG_BLK_DEV_VROOT) || defined(CONFIG_BLK_DEV_VROOT_MODULE)
6751 +
6752 +#include <linux/vroot.h>
6753 +#include <linux/major.h>
6754 +#include <linux/module.h>
6755 +#include <linux/kallsyms.h>
6756 +#include <linux/vserver/debug.h>
6757 +
6758 +static vroot_grb_func *vroot_get_real_bdev = NULL;
6759 +
6760 +static DEFINE_SPINLOCK(vroot_grb_lock);
6761 +
6762 +int register_vroot_grb(vroot_grb_func *func) {
6763 +       int ret = -EBUSY;
6764 +
6765 +       spin_lock(&vroot_grb_lock);
6766 +       if (!vroot_get_real_bdev) {
6767 +               vroot_get_real_bdev = func;
6768 +               ret = 0;
6769 +       }
6770 +       spin_unlock(&vroot_grb_lock);
6771 +       return ret;
6772 +}
6773 +EXPORT_SYMBOL(register_vroot_grb);
6774 +
6775 +int unregister_vroot_grb(vroot_grb_func *func) {
6776 +       int ret = -EINVAL;
6777 +
6778 +       spin_lock(&vroot_grb_lock);
6779 +       if (vroot_get_real_bdev) {
6780 +               vroot_get_real_bdev = NULL;
6781 +               ret = 0;
6782 +       }
6783 +       spin_unlock(&vroot_grb_lock);
6784 +       return ret;
6785 +}
6786 +EXPORT_SYMBOL(unregister_vroot_grb);
6787 +
6788 +#endif
6789 +
6790  /* Return 1 if 'cmd' will block on frozen filesystem */
6791  static int quotactl_cmd_write(int cmd)
6792  {
6793 @@ -323,6 +364,22 @@ static struct super_block *quotactl_bloc
6794         putname(tmp);
6795         if (IS_ERR(bdev))
6796                 return ERR_CAST(bdev);
6797 +#if defined(CONFIG_BLK_DEV_VROOT) || defined(CONFIG_BLK_DEV_VROOT_MODULE)
6798 +       if (bdev && bdev->bd_inode &&
6799 +                       imajor(bdev->bd_inode) == VROOT_MAJOR) {
6800 +               struct block_device *bdnew = (void *)-EINVAL;
6801 +
6802 +               if (vroot_get_real_bdev)
6803 +                       bdnew = vroot_get_real_bdev(bdev);
6804 +               else
6805 +                       vxdprintk(VXD_CBIT(misc, 0),
6806 +                                       "vroot_get_real_bdev not set");
6807 +               bdput(bdev);
6808 +               if (IS_ERR(bdnew))
6809 +                       return ERR_PTR(PTR_ERR(bdnew));
6810 +               bdev = bdnew;
6811 +       }
6812 +#endif
6813         if (quotactl_cmd_write(cmd))
6814                 sb = get_super_thawed(bdev);
6815         else
6816 diff -NurpP --minimal linux-3.6.9/fs/reiserfs/file.c linux-3.6.9-vs2.3.4.4/fs/reiserfs/file.c
6817 --- linux-3.6.9/fs/reiserfs/file.c      2012-05-21 18:07:26.000000000 +0200
6818 +++ linux-3.6.9-vs2.3.4.4/fs/reiserfs/file.c    2012-10-04 18:47:00.000000000 +0200
6819 @@ -319,5 +319,6 @@ const struct inode_operations reiserfs_f
6820         .listxattr = reiserfs_listxattr,
6821         .removexattr = reiserfs_removexattr,
6822         .permission = reiserfs_permission,
6823 +       .sync_flags = reiserfs_sync_flags,
6824         .get_acl = reiserfs_get_acl,
6825  };
6826 diff -NurpP --minimal linux-3.6.9/fs/reiserfs/inode.c linux-3.6.9-vs2.3.4.4/fs/reiserfs/inode.c
6827 --- linux-3.6.9/fs/reiserfs/inode.c     2012-12-08 01:34:14.000000000 +0100
6828 +++ linux-3.6.9-vs2.3.4.4/fs/reiserfs/inode.c   2012-12-08 01:36:33.000000000 +0100
6829 @@ -18,6 +18,7 @@
6830  #include <linux/writeback.h>
6831  #include <linux/quotaops.h>
6832  #include <linux/swap.h>
6833 +#include <linux/vs_tag.h>
6834  
6835  int reiserfs_commit_write(struct file *f, struct page *page,
6836                           unsigned from, unsigned to);
6837 @@ -1131,6 +1132,8 @@ static void init_inode(struct inode *ino
6838         struct buffer_head *bh;
6839         struct item_head *ih;
6840         __u32 rdev;
6841 +       uid_t uid;
6842 +       gid_t gid;
6843         //int version = ITEM_VERSION_1;
6844  
6845         bh = PATH_PLAST_BUFFER(path);
6846 @@ -1151,12 +1154,13 @@ static void init_inode(struct inode *ino
6847                     (struct stat_data_v1 *)B_I_PITEM(bh, ih);
6848                 unsigned long blocks;
6849  
6850 +               uid = sd_v1_uid(sd);
6851 +               gid = sd_v1_gid(sd);
6852 +
6853                 set_inode_item_key_version(inode, KEY_FORMAT_3_5);
6854                 set_inode_sd_version(inode, STAT_DATA_V1);
6855                 inode->i_mode = sd_v1_mode(sd);
6856                 set_nlink(inode, sd_v1_nlink(sd));
6857 -               inode->i_uid = sd_v1_uid(sd);
6858 -               inode->i_gid = sd_v1_gid(sd);
6859                 inode->i_size = sd_v1_size(sd);
6860                 inode->i_atime.tv_sec = sd_v1_atime(sd);
6861                 inode->i_mtime.tv_sec = sd_v1_mtime(sd);
6862 @@ -1198,11 +1202,12 @@ static void init_inode(struct inode *ino
6863                 // (directories and symlinks)
6864                 struct stat_data *sd = (struct stat_data *)B_I_PITEM(bh, ih);
6865  
6866 +               uid    = sd_v2_uid(sd);
6867 +               gid    = sd_v2_gid(sd);
6868 +
6869                 inode->i_mode = sd_v2_mode(sd);
6870                 set_nlink(inode, sd_v2_nlink(sd));
6871 -               inode->i_uid = sd_v2_uid(sd);
6872                 inode->i_size = sd_v2_size(sd);
6873 -               inode->i_gid = sd_v2_gid(sd);
6874                 inode->i_mtime.tv_sec = sd_v2_mtime(sd);
6875                 inode->i_atime.tv_sec = sd_v2_atime(sd);
6876                 inode->i_ctime.tv_sec = sd_v2_ctime(sd);
6877 @@ -1232,6 +1237,10 @@ static void init_inode(struct inode *ino
6878                 sd_attrs_to_i_attrs(sd_v2_attrs(sd), inode);
6879         }
6880  
6881 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
6882 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
6883 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid, 0);
6884 +
6885         pathrelse(path);
6886         if (S_ISREG(inode->i_mode)) {
6887                 inode->i_op = &reiserfs_file_inode_operations;
6888 @@ -1254,13 +1263,15 @@ static void init_inode(struct inode *ino
6889  static void inode2sd(void *sd, struct inode *inode, loff_t size)
6890  {
6891         struct stat_data *sd_v2 = (struct stat_data *)sd;
6892 +       uid_t uid = TAGINO_UID(DX_TAG(inode), inode->i_uid, inode->i_tag);
6893 +       gid_t gid = TAGINO_GID(DX_TAG(inode), inode->i_gid, inode->i_tag);
6894         __u16 flags;
6895  
6896 +       set_sd_v2_uid(sd_v2, uid);
6897 +       set_sd_v2_gid(sd_v2, gid);
6898         set_sd_v2_mode(sd_v2, inode->i_mode);
6899         set_sd_v2_nlink(sd_v2, inode->i_nlink);
6900 -       set_sd_v2_uid(sd_v2, inode->i_uid);
6901         set_sd_v2_size(sd_v2, size);
6902 -       set_sd_v2_gid(sd_v2, inode->i_gid);
6903         set_sd_v2_mtime(sd_v2, inode->i_mtime.tv_sec);
6904         set_sd_v2_atime(sd_v2, inode->i_atime.tv_sec);
6905         set_sd_v2_ctime(sd_v2, inode->i_ctime.tv_sec);
6906 @@ -2869,14 +2880,19 @@ int reiserfs_commit_write(struct file *f
6907  void sd_attrs_to_i_attrs(__u16 sd_attrs, struct inode *inode)
6908  {
6909         if (reiserfs_attrs(inode->i_sb)) {
6910 -               if (sd_attrs & REISERFS_SYNC_FL)
6911 -                       inode->i_flags |= S_SYNC;
6912 -               else
6913 -                       inode->i_flags &= ~S_SYNC;
6914                 if (sd_attrs & REISERFS_IMMUTABLE_FL)
6915                         inode->i_flags |= S_IMMUTABLE;
6916                 else
6917                         inode->i_flags &= ~S_IMMUTABLE;
6918 +               if (sd_attrs & REISERFS_IXUNLINK_FL)
6919 +                       inode->i_flags |= S_IXUNLINK;
6920 +               else
6921 +                       inode->i_flags &= ~S_IXUNLINK;
6922 +
6923 +               if (sd_attrs & REISERFS_SYNC_FL)
6924 +                       inode->i_flags |= S_SYNC;
6925 +               else
6926 +                       inode->i_flags &= ~S_SYNC;
6927                 if (sd_attrs & REISERFS_APPEND_FL)
6928                         inode->i_flags |= S_APPEND;
6929                 else
6930 @@ -2889,6 +2905,15 @@ void sd_attrs_to_i_attrs(__u16 sd_attrs,
6931                         REISERFS_I(inode)->i_flags |= i_nopack_mask;
6932                 else
6933                         REISERFS_I(inode)->i_flags &= ~i_nopack_mask;
6934 +
6935 +               if (sd_attrs & REISERFS_BARRIER_FL)
6936 +                       inode->i_vflags |= V_BARRIER;
6937 +               else
6938 +                       inode->i_vflags &= ~V_BARRIER;
6939 +               if (sd_attrs & REISERFS_COW_FL)
6940 +                       inode->i_vflags |= V_COW;
6941 +               else
6942 +                       inode->i_vflags &= ~V_COW;
6943         }
6944  }
6945  
6946 @@ -2899,6 +2924,11 @@ void i_attrs_to_sd_attrs(struct inode *i
6947                         *sd_attrs |= REISERFS_IMMUTABLE_FL;
6948                 else
6949                         *sd_attrs &= ~REISERFS_IMMUTABLE_FL;
6950 +               if (inode->i_flags & S_IXUNLINK)
6951 +                       *sd_attrs |= REISERFS_IXUNLINK_FL;
6952 +               else
6953 +                       *sd_attrs &= ~REISERFS_IXUNLINK_FL;
6954 +
6955                 if (inode->i_flags & S_SYNC)
6956                         *sd_attrs |= REISERFS_SYNC_FL;
6957                 else
6958 @@ -2911,6 +2941,15 @@ void i_attrs_to_sd_attrs(struct inode *i
6959                         *sd_attrs |= REISERFS_NOTAIL_FL;
6960                 else
6961                         *sd_attrs &= ~REISERFS_NOTAIL_FL;
6962 +
6963 +               if (inode->i_vflags & V_BARRIER)
6964 +                       *sd_attrs |= REISERFS_BARRIER_FL;
6965 +               else
6966 +                       *sd_attrs &= ~REISERFS_BARRIER_FL;
6967 +               if (inode->i_vflags & V_COW)
6968 +                       *sd_attrs |= REISERFS_COW_FL;
6969 +               else
6970 +                       *sd_attrs &= ~REISERFS_COW_FL;
6971         }
6972  }
6973  
6974 @@ -3155,7 +3194,8 @@ int reiserfs_setattr(struct dentry *dent
6975         }
6976  
6977         if ((ia_valid & ATTR_UID && attr->ia_uid != inode->i_uid) ||
6978 -           (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid)) {
6979 +           (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid) ||
6980 +           (ia_valid & ATTR_TAG && attr->ia_tag != inode->i_tag)) {
6981                 struct reiserfs_transaction_handle th;
6982                 int jbegin_count =
6983                     2 *
6984 @@ -3186,6 +3226,9 @@ int reiserfs_setattr(struct dentry *dent
6985                         inode->i_uid = attr->ia_uid;
6986                 if (attr->ia_valid & ATTR_GID)
6987                         inode->i_gid = attr->ia_gid;
6988 +                               if ((attr->ia_valid & ATTR_TAG) &&
6989 +                                       IS_TAGGED(inode))
6990 +                                       inode->i_tag = attr->ia_tag;
6991                 mark_inode_dirty(inode);
6992                 error = journal_end(&th, inode->i_sb, jbegin_count);
6993                 if (error)
6994 diff -NurpP --minimal linux-3.6.9/fs/reiserfs/ioctl.c linux-3.6.9-vs2.3.4.4/fs/reiserfs/ioctl.c
6995 --- linux-3.6.9/fs/reiserfs/ioctl.c     2012-05-21 18:07:27.000000000 +0200
6996 +++ linux-3.6.9-vs2.3.4.4/fs/reiserfs/ioctl.c   2012-10-04 18:47:00.000000000 +0200
6997 @@ -11,6 +11,21 @@
6998  #include <linux/pagemap.h>
6999  #include <linux/compat.h>
7000  
7001 +
7002 +int reiserfs_sync_flags(struct inode *inode, int flags, int vflags)
7003 +{
7004 +       __u16 sd_attrs = 0;
7005 +
7006 +       inode->i_flags = flags;
7007 +       inode->i_vflags = vflags;
7008 +
7009 +       i_attrs_to_sd_attrs(inode, &sd_attrs);
7010 +       REISERFS_I(inode)->i_attrs = sd_attrs;
7011 +       inode->i_ctime = CURRENT_TIME_SEC;
7012 +       mark_inode_dirty(inode);
7013 +       return 0;
7014 +}
7015 +
7016  /*
7017   * reiserfs_ioctl - handler for ioctl for inode
7018   * supported commands:
7019 @@ -22,7 +37,7 @@
7020  long reiserfs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
7021  {
7022         struct inode *inode = filp->f_path.dentry->d_inode;
7023 -       unsigned int flags;
7024 +       unsigned int flags, oldflags;
7025         int err = 0;
7026  
7027         reiserfs_write_lock(inode->i_sb);
7028 @@ -47,6 +62,7 @@ long reiserfs_ioctl(struct file *filp, u
7029  
7030                 flags = REISERFS_I(inode)->i_attrs;
7031                 i_attrs_to_sd_attrs(inode, (__u16 *) & flags);
7032 +               flags &= REISERFS_FL_USER_VISIBLE;
7033                 err = put_user(flags, (int __user *)arg);
7034                 break;
7035         case REISERFS_IOC_SETFLAGS:{
7036 @@ -67,6 +83,10 @@ long reiserfs_ioctl(struct file *filp, u
7037                                 err = -EFAULT;
7038                                 goto setflags_out;
7039                         }
7040 +                       if (IS_BARRIER(inode)) {
7041 +                               vxwprintk_task(1, "messing with the barrier.");
7042 +                               return -EACCES;
7043 +                       }
7044                         /*
7045                          * Is it quota file? Do not allow user to mess with it
7046                          */
7047 @@ -91,6 +111,10 @@ long reiserfs_ioctl(struct file *filp, u
7048                                         goto setflags_out;
7049                                 }
7050                         }
7051 +
7052 +                       oldflags = REISERFS_I(inode)->i_attrs;
7053 +                       flags &= REISERFS_FL_USER_MODIFIABLE;
7054 +                       flags |= oldflags & ~REISERFS_FL_USER_MODIFIABLE;
7055                         sd_attrs_to_i_attrs(flags, inode);
7056                         REISERFS_I(inode)->i_attrs = flags;
7057                         inode->i_ctime = CURRENT_TIME_SEC;
7058 diff -NurpP --minimal linux-3.6.9/fs/reiserfs/namei.c linux-3.6.9-vs2.3.4.4/fs/reiserfs/namei.c
7059 --- linux-3.6.9/fs/reiserfs/namei.c     2012-10-04 15:27:41.000000000 +0200
7060 +++ linux-3.6.9-vs2.3.4.4/fs/reiserfs/namei.c   2012-10-04 18:47:00.000000000 +0200
7061 @@ -18,6 +18,7 @@
7062  #include "acl.h"
7063  #include "xattr.h"
7064  #include <linux/quotaops.h>
7065 +#include <linux/vs_tag.h>
7066  
7067  #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); }
7068  #define DEC_DIR_INODE_NLINK(i) if (i->i_nlink != 1) drop_nlink(i);
7069 @@ -362,6 +363,7 @@ static struct dentry *reiserfs_lookup(st
7070         if (retval == IO_ERROR) {
7071                 return ERR_PTR(-EIO);
7072         }
7073 +               dx_propagate_tag(nd, inode);
7074  
7075         return d_splice_alias(inode, dentry);
7076  }
7077 diff -NurpP --minimal linux-3.6.9/fs/reiserfs/reiserfs.h linux-3.6.9-vs2.3.4.4/fs/reiserfs/reiserfs.h
7078 --- linux-3.6.9/fs/reiserfs/reiserfs.h  2012-07-22 23:39:42.000000000 +0200
7079 +++ linux-3.6.9-vs2.3.4.4/fs/reiserfs/reiserfs.h        2012-10-04 18:47:00.000000000 +0200
7080 @@ -549,6 +549,7 @@ enum reiserfs_mount_options {
7081         REISERFS_EXPOSE_PRIVROOT,
7082         REISERFS_BARRIER_NONE,
7083         REISERFS_BARRIER_FLUSH,
7084 +       REISERFS_TAGGED,
7085  
7086         /* Actions on error */
7087         REISERFS_ERROR_PANIC,
7088 @@ -1548,6 +1549,11 @@ struct stat_data_v1 {
7089  #define REISERFS_COMPR_FL     FS_COMPR_FL
7090  #define REISERFS_NOTAIL_FL    FS_NOTAIL_FL
7091  
7092 +/* unfortunately reiserfs sdattr is only 16 bit */
7093 +#define REISERFS_IXUNLINK_FL  (FS_IXUNLINK_FL >> 16)
7094 +#define REISERFS_BARRIER_FL   (FS_BARRIER_FL >> 16)
7095 +#define REISERFS_COW_FL       (FS_COW_FL >> 16)
7096 +
7097  /* persistent flags that file inherits from the parent directory */
7098  #define REISERFS_INHERIT_MASK ( REISERFS_IMMUTABLE_FL |        \
7099                                 REISERFS_SYNC_FL |      \
7100 @@ -1557,6 +1563,9 @@ struct stat_data_v1 {
7101                                 REISERFS_COMPR_FL |     \
7102                                 REISERFS_NOTAIL_FL )
7103  
7104 +#define REISERFS_FL_USER_VISIBLE       0x80FF
7105 +#define REISERFS_FL_USER_MODIFIABLE    0x80FF
7106 +
7107  /* Stat Data on disk (reiserfs version of UFS disk inode minus the
7108     address blocks) */
7109  struct stat_data {
7110 @@ -2647,6 +2656,7 @@ static inline void reiserfs_update_sd(st
7111  void sd_attrs_to_i_attrs(__u16 sd_attrs, struct inode *inode);
7112  void i_attrs_to_sd_attrs(struct inode *inode, __u16 * sd_attrs);
7113  int reiserfs_setattr(struct dentry *dentry, struct iattr *attr);
7114 +int reiserfs_sync_flags(struct inode *inode, int, int);
7115  
7116  int __reiserfs_write_begin(struct page *page, unsigned from, unsigned len);
7117  
7118 diff -NurpP --minimal linux-3.6.9/fs/reiserfs/super.c linux-3.6.9-vs2.3.4.4/fs/reiserfs/super.c
7119 --- linux-3.6.9/fs/reiserfs/super.c     2012-12-08 01:34:14.000000000 +0100
7120 +++ linux-3.6.9-vs2.3.4.4/fs/reiserfs/super.c   2012-12-08 01:36:33.000000000 +0100
7121 @@ -1020,6 +1020,14 @@ static int reiserfs_parse_options(struct
7122                 {"user_xattr",.setmask = 1 << REISERFS_UNSUPPORTED_OPT},
7123                 {"nouser_xattr",.clrmask = 1 << REISERFS_UNSUPPORTED_OPT},
7124  #endif
7125 +#ifndef CONFIG_TAGGING_NONE
7126 +               {"tagxid",.setmask = 1 << REISERFS_TAGGED},
7127 +               {"tag",.setmask = 1 << REISERFS_TAGGED},
7128 +               {"notag",.clrmask = 1 << REISERFS_TAGGED},
7129 +#endif
7130 +#ifdef CONFIG_PROPAGATE
7131 +               {"tag",.arg_required = 'T',.values = NULL},
7132 +#endif
7133  #ifdef CONFIG_REISERFS_FS_POSIX_ACL
7134                 {"acl",.setmask = 1 << REISERFS_POSIXACL},
7135                 {"noacl",.clrmask = 1 << REISERFS_POSIXACL},
7136 @@ -1338,6 +1346,14 @@ static int reiserfs_remount(struct super
7137         handle_quota_files(s, qf_names, &qfmt);
7138  #endif
7139  
7140 +       if ((mount_options & (1 << REISERFS_TAGGED)) &&
7141 +               !(s->s_flags & MS_TAGGED)) {
7142 +               reiserfs_warning(s, "super-vs01",
7143 +                       "reiserfs: tagging not permitted on remount.");
7144 +               err = -EINVAL;
7145 +               goto out_err;
7146 +       }
7147 +
7148         handle_attrs(s);
7149  
7150         /* Add options that are safe here */
7151 @@ -1831,6 +1847,10 @@ static int reiserfs_fill_super(struct su
7152                 goto error_unlocked;
7153         }
7154  
7155 +       /* map mount option tagxid */
7156 +       if (REISERFS_SB(s)->s_mount_opt & (1 << REISERFS_TAGGED))
7157 +               s->s_flags |= MS_TAGGED;
7158 +
7159         rs = SB_DISK_SUPER_BLOCK(s);
7160         /* Let's do basic sanity check to verify that underlying device is not
7161            smaller than the filesystem. If the check fails then abort and scream,
7162 diff -NurpP --minimal linux-3.6.9/fs/reiserfs/xattr.c linux-3.6.9-vs2.3.4.4/fs/reiserfs/xattr.c
7163 --- linux-3.6.9/fs/reiserfs/xattr.c     2012-10-04 15:27:41.000000000 +0200
7164 +++ linux-3.6.9-vs2.3.4.4/fs/reiserfs/xattr.c   2012-10-04 18:47:00.000000000 +0200
7165 @@ -40,6 +40,7 @@
7166  #include <linux/errno.h>
7167  #include <linux/gfp.h>
7168  #include <linux/fs.h>
7169 +#include <linux/mount.h>
7170  #include <linux/file.h>
7171  #include <linux/pagemap.h>
7172  #include <linux/xattr.h>
7173 diff -NurpP --minimal linux-3.6.9/fs/stat.c linux-3.6.9-vs2.3.4.4/fs/stat.c
7174 --- linux-3.6.9/fs/stat.c       2012-10-04 15:27:41.000000000 +0200
7175 +++ linux-3.6.9-vs2.3.4.4/fs/stat.c     2012-10-04 18:47:00.000000000 +0200
7176 @@ -26,6 +26,7 @@ void generic_fillattr(struct inode *inod
7177         stat->nlink = inode->i_nlink;
7178         stat->uid = inode->i_uid;
7179         stat->gid = inode->i_gid;
7180 +       stat->tag = inode->i_tag;
7181         stat->rdev = inode->i_rdev;
7182         stat->size = i_size_read(inode);
7183         stat->atime = inode->i_atime;
7184 diff -NurpP --minimal linux-3.6.9/fs/statfs.c linux-3.6.9-vs2.3.4.4/fs/statfs.c
7185 --- linux-3.6.9/fs/statfs.c     2012-07-22 23:39:42.000000000 +0200
7186 +++ linux-3.6.9-vs2.3.4.4/fs/statfs.c   2012-10-04 18:47:00.000000000 +0200
7187 @@ -7,6 +7,8 @@
7188  #include <linux/statfs.h>
7189  #include <linux/security.h>
7190  #include <linux/uaccess.h>
7191 +#include <linux/vs_base.h>
7192 +#include <linux/vs_dlimit.h>
7193  #include "internal.h"
7194  
7195  static int flags_by_mnt(int mnt_flags)
7196 @@ -60,6 +62,8 @@ static int statfs_by_dentry(struct dentr
7197         retval = dentry->d_sb->s_op->statfs(dentry, buf);
7198         if (retval == 0 && buf->f_frsize == 0)
7199                 buf->f_frsize = buf->f_bsize;
7200 +       if (!vx_check(0, VS_ADMIN|VS_WATCH))
7201 +               vx_vsi_statfs(dentry->d_sb, buf);
7202         return retval;
7203  }
7204  
7205 diff -NurpP --minimal linux-3.6.9/fs/super.c linux-3.6.9-vs2.3.4.4/fs/super.c
7206 --- linux-3.6.9/fs/super.c      2012-10-04 15:27:41.000000000 +0200
7207 +++ linux-3.6.9-vs2.3.4.4/fs/super.c    2012-10-04 19:06:05.000000000 +0200
7208 @@ -34,6 +34,8 @@
7209  #include <linux/cleancache.h>
7210  #include <linux/fsnotify.h>
7211  #include <linux/lockdep.h>
7212 +#include <linux/magic.h>
7213 +#include <linux/vs_context.h>
7214  #include "internal.h"
7215  
7216  
7217 @@ -1148,6 +1150,13 @@ mount_fs(struct file_system_type *type, 
7218         WARN_ON(sb->s_bdi == &default_backing_dev_info);
7219         sb->s_flags |= MS_BORN;
7220  
7221 +       error = -EPERM;
7222 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_BINARY_MOUNT) &&
7223 +               !sb->s_bdev &&
7224 +               (sb->s_magic != PROC_SUPER_MAGIC) &&
7225 +               (sb->s_magic != DEVPTS_SUPER_MAGIC))
7226 +               goto out_sb;
7227 +
7228         error = security_sb_kern_mount(sb, flags, secdata);
7229         if (error)
7230                 goto out_sb;
7231 diff -NurpP --minimal linux-3.6.9/fs/sysfs/mount.c linux-3.6.9-vs2.3.4.4/fs/sysfs/mount.c
7232 --- linux-3.6.9/fs/sysfs/mount.c        2012-10-04 15:27:41.000000000 +0200
7233 +++ linux-3.6.9-vs2.3.4.4/fs/sysfs/mount.c      2012-10-04 18:47:00.000000000 +0200
7234 @@ -47,7 +47,7 @@ static int sysfs_fill_super(struct super
7235  
7236         sb->s_blocksize = PAGE_CACHE_SIZE;
7237         sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
7238 -       sb->s_magic = SYSFS_MAGIC;
7239 +       sb->s_magic = SYSFS_SUPER_MAGIC;
7240         sb->s_op = &sysfs_ops;
7241         sb->s_time_gran = 1;
7242  
7243 diff -NurpP --minimal linux-3.6.9/fs/utimes.c linux-3.6.9-vs2.3.4.4/fs/utimes.c
7244 --- linux-3.6.9/fs/utimes.c     2012-07-22 23:39:42.000000000 +0200
7245 +++ linux-3.6.9-vs2.3.4.4/fs/utimes.c   2012-10-04 18:47:00.000000000 +0200
7246 @@ -8,6 +8,8 @@
7247  #include <linux/stat.h>
7248  #include <linux/utime.h>
7249  #include <linux/syscalls.h>
7250 +#include <linux/mount.h>
7251 +#include <linux/vs_cowbl.h>
7252  #include <asm/uaccess.h>
7253  #include <asm/unistd.h>
7254  
7255 @@ -52,12 +54,18 @@ static int utimes_common(struct path *pa
7256  {
7257         int error;
7258         struct iattr newattrs;
7259 -       struct inode *inode = path->dentry->d_inode;
7260 +       struct inode *inode;
7261  
7262         error = mnt_want_write(path->mnt);
7263         if (error)
7264                 goto out;
7265  
7266 +       error = cow_check_and_break(path);
7267 +       if (error)
7268 +               goto mnt_drop_write_and_out;
7269 +
7270 +       inode = path->dentry->d_inode;
7271 +
7272         if (times && times[0].tv_nsec == UTIME_NOW &&
7273                      times[1].tv_nsec == UTIME_NOW)
7274                 times = NULL;
7275 diff -NurpP --minimal linux-3.6.9/fs/xattr.c linux-3.6.9-vs2.3.4.4/fs/xattr.c
7276 --- linux-3.6.9/fs/xattr.c      2012-10-04 15:27:44.000000000 +0200
7277 +++ linux-3.6.9-vs2.3.4.4/fs/xattr.c    2012-10-04 18:47:00.000000000 +0200
7278 @@ -20,6 +20,7 @@
7279  #include <linux/fsnotify.h>
7280  #include <linux/audit.h>
7281  #include <linux/vmalloc.h>
7282 +#include <linux/mount.h>
7283  
7284  #include <asm/uaccess.h>
7285  
7286 @@ -51,7 +52,7 @@ xattr_permission(struct inode *inode, co
7287          * The trusted.* namespace can only be accessed by privileged users.
7288          */
7289         if (!strncmp(name, XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN)) {
7290 -               if (!capable(CAP_SYS_ADMIN))
7291 +               if (!vx_capable(CAP_SYS_ADMIN, VXC_FS_TRUSTED))
7292                         return (mask & MAY_WRITE) ? -EPERM : -ENODATA;
7293                 return 0;
7294         }
7295 diff -NurpP --minimal linux-3.6.9/fs/xfs/xfs_dinode.h linux-3.6.9-vs2.3.4.4/fs/xfs/xfs_dinode.h
7296 --- linux-3.6.9/fs/xfs/xfs_dinode.h     2012-10-04 15:27:44.000000000 +0200
7297 +++ linux-3.6.9-vs2.3.4.4/fs/xfs/xfs_dinode.h   2012-10-04 18:47:00.000000000 +0200
7298 @@ -51,7 +51,9 @@ typedef struct xfs_dinode {
7299         __be32          di_nlink;       /* number of links to file */
7300         __be16          di_projid_lo;   /* lower part of owner's project id */
7301         __be16          di_projid_hi;   /* higher part owner's project id */
7302 -       __u8            di_pad[6];      /* unused, zeroed space */
7303 +       __u8            di_pad[2];      /* unused, zeroed space */
7304 +       __be16          di_tag;         /* context tagging */
7305 +       __be16          di_vflags;      /* vserver specific flags */
7306         __be16          di_flushiter;   /* incremented on flush */
7307         xfs_timestamp_t di_atime;       /* time last accessed */
7308         xfs_timestamp_t di_mtime;       /* time last modified */
7309 @@ -184,6 +186,8 @@ static inline void xfs_dinode_put_rdev(s
7310  #define XFS_DIFLAG_EXTSZINHERIT_BIT 12 /* inherit inode extent size */
7311  #define XFS_DIFLAG_NODEFRAG_BIT     13 /* do not reorganize/defragment */
7312  #define XFS_DIFLAG_FILESTREAM_BIT   14  /* use filestream allocator */
7313 +#define XFS_DIFLAG_IXUNLINK_BIT     15 /* Immutable inver on unlink */
7314 +
7315  #define XFS_DIFLAG_REALTIME      (1 << XFS_DIFLAG_REALTIME_BIT)
7316  #define XFS_DIFLAG_PREALLOC      (1 << XFS_DIFLAG_PREALLOC_BIT)
7317  #define XFS_DIFLAG_NEWRTBM       (1 << XFS_DIFLAG_NEWRTBM_BIT)
7318 @@ -199,6 +203,7 @@ static inline void xfs_dinode_put_rdev(s
7319  #define XFS_DIFLAG_EXTSZINHERIT  (1 << XFS_DIFLAG_EXTSZINHERIT_BIT)
7320  #define XFS_DIFLAG_NODEFRAG      (1 << XFS_DIFLAG_NODEFRAG_BIT)
7321  #define XFS_DIFLAG_FILESTREAM    (1 << XFS_DIFLAG_FILESTREAM_BIT)
7322 +#define XFS_DIFLAG_IXUNLINK      (1 << XFS_DIFLAG_IXUNLINK_BIT)
7323  
7324  #ifdef CONFIG_XFS_RT
7325  #define XFS_IS_REALTIME_INODE(ip) ((ip)->i_d.di_flags & XFS_DIFLAG_REALTIME)
7326 @@ -211,6 +216,10 @@ static inline void xfs_dinode_put_rdev(s
7327          XFS_DIFLAG_IMMUTABLE | XFS_DIFLAG_APPEND | XFS_DIFLAG_SYNC | \
7328          XFS_DIFLAG_NOATIME | XFS_DIFLAG_NODUMP | XFS_DIFLAG_RTINHERIT | \
7329          XFS_DIFLAG_PROJINHERIT | XFS_DIFLAG_NOSYMLINKS | XFS_DIFLAG_EXTSIZE | \
7330 -        XFS_DIFLAG_EXTSZINHERIT | XFS_DIFLAG_NODEFRAG | XFS_DIFLAG_FILESTREAM)
7331 +        XFS_DIFLAG_EXTSZINHERIT | XFS_DIFLAG_NODEFRAG | XFS_DIFLAG_FILESTREAM | \
7332 +        XFS_DIFLAG_IXUNLINK)
7333 +
7334 +#define XFS_DIVFLAG_BARRIER    0x01
7335 +#define XFS_DIVFLAG_COW                0x02
7336  
7337  #endif /* __XFS_DINODE_H__ */
7338 diff -NurpP --minimal linux-3.6.9/fs/xfs/xfs_fs.h linux-3.6.9-vs2.3.4.4/fs/xfs/xfs_fs.h
7339 --- linux-3.6.9/fs/xfs/xfs_fs.h 2011-10-24 18:45:31.000000000 +0200
7340 +++ linux-3.6.9-vs2.3.4.4/fs/xfs/xfs_fs.h       2012-10-04 18:47:00.000000000 +0200
7341 @@ -67,6 +67,9 @@ struct fsxattr {
7342  #define XFS_XFLAG_EXTSZINHERIT 0x00001000      /* inherit inode extent size */
7343  #define XFS_XFLAG_NODEFRAG     0x00002000      /* do not defragment */
7344  #define XFS_XFLAG_FILESTREAM   0x00004000      /* use filestream allocator */
7345 +#define XFS_XFLAG_IXUNLINK     0x00008000      /* immutable invert on unlink */
7346 +#define XFS_XFLAG_BARRIER      0x10000000      /* chroot() barrier */
7347 +#define XFS_XFLAG_COW          0x20000000      /* copy on write mark */
7348  #define XFS_XFLAG_HASATTR      0x80000000      /* no DIFLAG for this   */
7349  
7350  /*
7351 @@ -302,7 +305,8 @@ typedef struct xfs_bstat {
7352  #define        bs_projid       bs_projid_lo    /* (previously just bs_projid)  */
7353         __u16           bs_forkoff;     /* inode fork offset in bytes   */
7354         __u16           bs_projid_hi;   /* higher part of project id    */
7355 -       unsigned char   bs_pad[10];     /* pad space, unused            */
7356 +       unsigned char   bs_pad[8];      /* pad space, unused            */
7357 +       __u16           bs_tag;         /* context tagging              */
7358         __u32           bs_dmevmask;    /* DMIG event mask              */
7359         __u16           bs_dmstate;     /* DMIG state info              */
7360         __u16           bs_aextents;    /* attribute number of extents  */
7361 diff -NurpP --minimal linux-3.6.9/fs/xfs/xfs_ialloc.c linux-3.6.9-vs2.3.4.4/fs/xfs/xfs_ialloc.c
7362 --- linux-3.6.9/fs/xfs/xfs_ialloc.c     2012-10-04 15:27:44.000000000 +0200
7363 +++ linux-3.6.9-vs2.3.4.4/fs/xfs/xfs_ialloc.c   2012-10-04 18:47:00.000000000 +0200
7364 @@ -37,7 +37,6 @@
7365  #include "xfs_error.h"
7366  #include "xfs_bmap.h"
7367  
7368 -
7369  /*
7370   * Allocation group level functions.
7371   */
7372 diff -NurpP --minimal linux-3.6.9/fs/xfs/xfs_inode.c linux-3.6.9-vs2.3.4.4/fs/xfs/xfs_inode.c
7373 --- linux-3.6.9/fs/xfs/xfs_inode.c      2012-10-04 15:27:44.000000000 +0200
7374 +++ linux-3.6.9-vs2.3.4.4/fs/xfs/xfs_inode.c    2012-11-16 22:43:16.000000000 +0100
7375 @@ -16,6 +16,7 @@
7376   * Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
7377   */
7378  #include <linux/log2.h>
7379 +#include <linux/vs_tag.h>
7380  
7381  #include "xfs.h"
7382  #include "xfs_fs.h"
7383 @@ -563,15 +564,25 @@ xfs_iformat_btree(
7384  STATIC void
7385  xfs_dinode_from_disk(
7386         xfs_icdinode_t          *to,
7387 -       xfs_dinode_t            *from)
7388 +       xfs_dinode_t            *from,
7389 +       int                     tagged)
7390  {
7391 +       uint32_t uid, gid, tag;
7392 +
7393         to->di_magic = be16_to_cpu(from->di_magic);
7394         to->di_mode = be16_to_cpu(from->di_mode);
7395         to->di_version = from ->di_version;
7396         to->di_format = from->di_format;
7397         to->di_onlink = be16_to_cpu(from->di_onlink);
7398 -       to->di_uid = be32_to_cpu(from->di_uid);
7399 -       to->di_gid = be32_to_cpu(from->di_gid);
7400 +
7401 +       uid = be32_to_cpu(from->di_uid);
7402 +       gid = be32_to_cpu(from->di_gid);
7403 +       tag = be16_to_cpu(from->di_tag);
7404 +
7405 +       to->di_uid = INOTAG_UID(tagged, uid, gid);
7406 +       to->di_gid = INOTAG_GID(tagged, uid, gid);
7407 +       to->di_tag = INOTAG_TAG(tagged, uid, gid, tag);
7408 +
7409         to->di_nlink = be32_to_cpu(from->di_nlink);
7410         to->di_projid_lo = be16_to_cpu(from->di_projid_lo);
7411         to->di_projid_hi = be16_to_cpu(from->di_projid_hi);
7412 @@ -593,21 +604,26 @@ xfs_dinode_from_disk(
7413         to->di_dmevmask = be32_to_cpu(from->di_dmevmask);
7414         to->di_dmstate  = be16_to_cpu(from->di_dmstate);
7415         to->di_flags    = be16_to_cpu(from->di_flags);
7416 +       to->di_vflags   = be16_to_cpu(from->di_vflags);
7417         to->di_gen      = be32_to_cpu(from->di_gen);
7418  }
7419  
7420  void
7421  xfs_dinode_to_disk(
7422         xfs_dinode_t            *to,
7423 -       xfs_icdinode_t          *from)
7424 +       xfs_icdinode_t          *from,
7425 +       int                     tagged)
7426  {
7427         to->di_magic = cpu_to_be16(from->di_magic);
7428         to->di_mode = cpu_to_be16(from->di_mode);
7429         to->di_version = from ->di_version;
7430         to->di_format = from->di_format;
7431         to->di_onlink = cpu_to_be16(from->di_onlink);
7432 -       to->di_uid = cpu_to_be32(from->di_uid);
7433 -       to->di_gid = cpu_to_be32(from->di_gid);
7434 +
7435 +       to->di_uid = cpu_to_be32(TAGINO_UID(tagged, from->di_uid, from->di_tag));
7436 +       to->di_gid = cpu_to_be32(TAGINO_GID(tagged, from->di_gid, from->di_tag));
7437 +       to->di_tag = cpu_to_be16(TAGINO_TAG(tagged, from->di_tag));
7438 +
7439         to->di_nlink = cpu_to_be32(from->di_nlink);
7440         to->di_projid_lo = cpu_to_be16(from->di_projid_lo);
7441         to->di_projid_hi = cpu_to_be16(from->di_projid_hi);
7442 @@ -629,12 +645,14 @@ xfs_dinode_to_disk(
7443         to->di_dmevmask = cpu_to_be32(from->di_dmevmask);
7444         to->di_dmstate = cpu_to_be16(from->di_dmstate);
7445         to->di_flags = cpu_to_be16(from->di_flags);
7446 +       to->di_vflags = cpu_to_be16(from->di_vflags);
7447         to->di_gen = cpu_to_be32(from->di_gen);
7448  }
7449  
7450  STATIC uint
7451  _xfs_dic2xflags(
7452 -       __uint16_t              di_flags)
7453 +       __uint16_t              di_flags,
7454 +       __uint16_t              di_vflags)
7455  {
7456         uint                    flags = 0;
7457  
7458 @@ -645,6 +663,8 @@ _xfs_dic2xflags(
7459                         flags |= XFS_XFLAG_PREALLOC;
7460                 if (di_flags & XFS_DIFLAG_IMMUTABLE)
7461                         flags |= XFS_XFLAG_IMMUTABLE;
7462 +               if (di_flags & XFS_DIFLAG_IXUNLINK)
7463 +                       flags |= XFS_XFLAG_IXUNLINK;
7464                 if (di_flags & XFS_DIFLAG_APPEND)
7465                         flags |= XFS_XFLAG_APPEND;
7466                 if (di_flags & XFS_DIFLAG_SYNC)
7467 @@ -669,6 +689,10 @@ _xfs_dic2xflags(
7468                         flags |= XFS_XFLAG_FILESTREAM;
7469         }
7470  
7471 +       if (di_vflags & XFS_DIVFLAG_BARRIER)
7472 +               flags |= FS_BARRIER_FL;
7473 +       if (di_vflags & XFS_DIVFLAG_COW)
7474 +               flags |= FS_COW_FL;
7475         return flags;
7476  }
7477  
7478 @@ -678,7 +702,7 @@ xfs_ip2xflags(
7479  {
7480         xfs_icdinode_t          *dic = &ip->i_d;
7481  
7482 -       return _xfs_dic2xflags(dic->di_flags) |
7483 +       return _xfs_dic2xflags(dic->di_flags, dic->di_vflags) |
7484                                 (XFS_IFORK_Q(ip) ? XFS_XFLAG_HASATTR : 0);
7485  }
7486  
7487 @@ -686,7 +710,8 @@ uint
7488  xfs_dic2xflags(
7489         xfs_dinode_t            *dip)
7490  {
7491 -       return _xfs_dic2xflags(be16_to_cpu(dip->di_flags)) |
7492 +       return _xfs_dic2xflags(be16_to_cpu(dip->di_flags),
7493 +                               be16_to_cpu(dip->di_vflags)) |
7494                                 (XFS_DFORK_Q(dip) ? XFS_XFLAG_HASATTR : 0);
7495  }
7496  
7497 @@ -740,7 +765,8 @@ xfs_iread(
7498          * Otherwise, just get the truly permanent information.
7499          */
7500         if (dip->di_mode) {
7501 -               xfs_dinode_from_disk(&ip->i_d, dip);
7502 +               xfs_dinode_from_disk(&ip->i_d, dip,
7503 +                       mp->m_flags & XFS_MOUNT_TAGGED);
7504                 error = xfs_iformat(ip, dip);
7505                 if (error)  {
7506  #ifdef DEBUG
7507 @@ -927,6 +953,7 @@ xfs_ialloc(
7508         ASSERT(ip->i_d.di_nlink == nlink);
7509         ip->i_d.di_uid = current_fsuid();
7510         ip->i_d.di_gid = current_fsgid();
7511 +       ip->i_d.di_tag = current_fstag(&ip->i_vnode);
7512         xfs_set_projid(ip, prid);
7513         memset(&(ip->i_d.di_pad[0]), 0, sizeof(ip->i_d.di_pad));
7514  
7515 @@ -986,6 +1013,7 @@ xfs_ialloc(
7516         ip->i_d.di_dmevmask = 0;
7517         ip->i_d.di_dmstate = 0;
7518         ip->i_d.di_flags = 0;
7519 +       ip->i_d.di_vflags = 0;
7520         flags = XFS_ILOG_CORE;
7521         switch (mode & S_IFMT) {
7522         case S_IFIFO:
7523 @@ -1667,6 +1695,7 @@ xfs_ifree(
7524         }
7525         ip->i_d.di_mode = 0;            /* mark incore inode as free */
7526         ip->i_d.di_flags = 0;
7527 +       ip->i_d.di_vflags = 0;
7528         ip->i_d.di_dmevmask = 0;
7529         ip->i_d.di_forkoff = 0;         /* mark the attr fork not in use */
7530         ip->i_d.di_format = XFS_DINODE_FMT_EXTENTS;
7531 @@ -1833,6 +1862,7 @@ xfs_iroot_realloc(
7532         return;
7533  }
7534  
7535 +#include <linux/vs_tag.h>
7536  
7537  /*
7538   * This is called when the amount of space needed for if_data
7539 @@ -2521,7 +2551,8 @@ xfs_iflush_int(
7540          * because if the inode is dirty at all the core must
7541          * be.
7542          */
7543 -       xfs_dinode_to_disk(dip, &ip->i_d);
7544 +       xfs_dinode_to_disk(dip, &ip->i_d,
7545 +               mp->m_flags & XFS_MOUNT_TAGGED);
7546  
7547         /* Wrap, we never let the log put out DI_MAX_FLUSH */
7548         if (ip->i_d.di_flushiter == DI_MAX_FLUSH)
7549 diff -NurpP --minimal linux-3.6.9/fs/xfs/xfs_inode.h linux-3.6.9-vs2.3.4.4/fs/xfs/xfs_inode.h
7550 --- linux-3.6.9/fs/xfs/xfs_inode.h      2012-10-04 15:27:44.000000000 +0200
7551 +++ linux-3.6.9-vs2.3.4.4/fs/xfs/xfs_inode.h    2012-10-04 18:47:00.000000000 +0200
7552 @@ -134,7 +134,9 @@ typedef struct xfs_icdinode {
7553         __uint32_t      di_nlink;       /* number of links to file */
7554         __uint16_t      di_projid_lo;   /* lower part of owner's project id */
7555         __uint16_t      di_projid_hi;   /* higher part of owner's project id */
7556 -       __uint8_t       di_pad[6];      /* unused, zeroed space */
7557 +       __uint8_t       di_pad[2];      /* unused, zeroed space */
7558 +       __uint16_t      di_tag;         /* context tagging */
7559 +       __uint16_t      di_vflags;      /* vserver specific flags */
7560         __uint16_t      di_flushiter;   /* incremented on flush */
7561         xfs_ictimestamp_t di_atime;     /* time last accessed */
7562         xfs_ictimestamp_t di_mtime;     /* time last modified */
7563 @@ -561,7 +563,7 @@ int         xfs_imap_to_bp(struct xfs_mount *, 
7564  int            xfs_iread(struct xfs_mount *, struct xfs_trans *,
7565                           struct xfs_inode *, uint);
7566  void           xfs_dinode_to_disk(struct xfs_dinode *,
7567 -                                  struct xfs_icdinode *);
7568 +                                  struct xfs_icdinode *, int);
7569  void           xfs_idestroy_fork(struct xfs_inode *, int);
7570  void           xfs_idata_realloc(struct xfs_inode *, int, int);
7571  void           xfs_iroot_realloc(struct xfs_inode *, int, int);
7572 diff -NurpP --minimal linux-3.6.9/fs/xfs/xfs_ioctl.c linux-3.6.9-vs2.3.4.4/fs/xfs/xfs_ioctl.c
7573 --- linux-3.6.9/fs/xfs/xfs_ioctl.c      2012-10-04 15:27:44.000000000 +0200
7574 +++ linux-3.6.9-vs2.3.4.4/fs/xfs/xfs_ioctl.c    2012-10-04 18:47:00.000000000 +0200
7575 @@ -26,7 +26,7 @@
7576  #include "xfs_bmap_btree.h"
7577  #include "xfs_dinode.h"
7578  #include "xfs_inode.h"
7579 -#include "xfs_ioctl.h"
7580 +// #include "xfs_ioctl.h"
7581  #include "xfs_rtalloc.h"
7582  #include "xfs_itable.h"
7583  #include "xfs_error.h"
7584 @@ -762,6 +762,10 @@ xfs_merge_ioc_xflags(
7585                 xflags |= XFS_XFLAG_IMMUTABLE;
7586         else
7587                 xflags &= ~XFS_XFLAG_IMMUTABLE;
7588 +       if (flags & FS_IXUNLINK_FL)
7589 +               xflags |= XFS_XFLAG_IXUNLINK;
7590 +       else
7591 +               xflags &= ~XFS_XFLAG_IXUNLINK;
7592         if (flags & FS_APPEND_FL)
7593                 xflags |= XFS_XFLAG_APPEND;
7594         else
7595 @@ -790,6 +794,8 @@ xfs_di2lxflags(
7596  
7597         if (di_flags & XFS_DIFLAG_IMMUTABLE)
7598                 flags |= FS_IMMUTABLE_FL;
7599 +       if (di_flags & XFS_DIFLAG_IXUNLINK)
7600 +               flags |= FS_IXUNLINK_FL;
7601         if (di_flags & XFS_DIFLAG_APPEND)
7602                 flags |= FS_APPEND_FL;
7603         if (di_flags & XFS_DIFLAG_SYNC)
7604 @@ -850,6 +856,8 @@ xfs_set_diflags(
7605         di_flags = (ip->i_d.di_flags & XFS_DIFLAG_PREALLOC);
7606         if (xflags & XFS_XFLAG_IMMUTABLE)
7607                 di_flags |= XFS_DIFLAG_IMMUTABLE;
7608 +       if (xflags & XFS_XFLAG_IXUNLINK)
7609 +               di_flags |= XFS_DIFLAG_IXUNLINK;
7610         if (xflags & XFS_XFLAG_APPEND)
7611                 di_flags |= XFS_DIFLAG_APPEND;
7612         if (xflags & XFS_XFLAG_SYNC)
7613 @@ -892,6 +900,10 @@ xfs_diflags_to_linux(
7614                 inode->i_flags |= S_IMMUTABLE;
7615         else
7616                 inode->i_flags &= ~S_IMMUTABLE;
7617 +       if (xflags & XFS_XFLAG_IXUNLINK)
7618 +               inode->i_flags |= S_IXUNLINK;
7619 +       else
7620 +               inode->i_flags &= ~S_IXUNLINK;
7621         if (xflags & XFS_XFLAG_APPEND)
7622                 inode->i_flags |= S_APPEND;
7623         else
7624 @@ -1396,10 +1408,18 @@ xfs_file_ioctl(
7625         case XFS_IOC_FSGETXATTRA:
7626                 return xfs_ioc_fsgetxattr(ip, 1, arg);
7627         case XFS_IOC_FSSETXATTR:
7628 +               if (IS_BARRIER(inode)) {
7629 +                       vxwprintk_task(1, "messing with the barrier.");
7630 +                       return -XFS_ERROR(EACCES);
7631 +               }
7632                 return xfs_ioc_fssetxattr(ip, filp, arg);
7633         case XFS_IOC_GETXFLAGS:
7634                 return xfs_ioc_getxflags(ip, arg);
7635         case XFS_IOC_SETXFLAGS:
7636 +               if (IS_BARRIER(inode)) {
7637 +                       vxwprintk_task(1, "messing with the barrier.");
7638 +                       return -XFS_ERROR(EACCES);
7639 +               }
7640                 return xfs_ioc_setxflags(ip, filp, arg);
7641  
7642         case XFS_IOC_FSSETDM: {
7643 diff -NurpP --minimal linux-3.6.9/fs/xfs/xfs_ioctl.h linux-3.6.9-vs2.3.4.4/fs/xfs/xfs_ioctl.h
7644 --- linux-3.6.9/fs/xfs/xfs_ioctl.h      2011-10-24 18:45:31.000000000 +0200
7645 +++ linux-3.6.9-vs2.3.4.4/fs/xfs/xfs_ioctl.h    2012-10-04 18:47:00.000000000 +0200
7646 @@ -70,6 +70,12 @@ xfs_handle_to_dentry(
7647         void __user             *uhandle,
7648         u32                     hlen);
7649  
7650 +extern int
7651 +xfs_sync_flags(
7652 +       struct inode            *inode,
7653 +       int                     flags,
7654 +       int                     vflags);
7655 +
7656  extern long
7657  xfs_file_ioctl(
7658         struct file             *filp,
7659 diff -NurpP --minimal linux-3.6.9/fs/xfs/xfs_iops.c linux-3.6.9-vs2.3.4.4/fs/xfs/xfs_iops.c
7660 --- linux-3.6.9/fs/xfs/xfs_iops.c       2012-10-04 15:27:44.000000000 +0200
7661 +++ linux-3.6.9-vs2.3.4.4/fs/xfs/xfs_iops.c     2012-11-16 22:14:53.000000000 +0100
7662 @@ -28,6 +28,7 @@
7663  #include "xfs_bmap_btree.h"
7664  #include "xfs_dinode.h"
7665  #include "xfs_inode.h"
7666 +#include "xfs_ioctl.h"
7667  #include "xfs_bmap.h"
7668  #include "xfs_rtalloc.h"
7669  #include "xfs_error.h"
7670 @@ -46,6 +47,7 @@
7671  #include <linux/security.h>
7672  #include <linux/fiemap.h>
7673  #include <linux/slab.h>
7674 +#include <linux/vs_tag.h>
7675  
7676  static int
7677  xfs_initxattrs(
7678 @@ -421,6 +423,7 @@ xfs_vn_getattr(
7679         stat->nlink = ip->i_d.di_nlink;
7680         stat->uid = ip->i_d.di_uid;
7681         stat->gid = ip->i_d.di_gid;
7682 +       stat->tag = ip->i_d.di_tag;
7683         stat->ino = ip->i_ino;
7684         stat->atime = inode->i_atime;
7685         stat->mtime = inode->i_mtime;
7686 @@ -1033,6 +1036,7 @@ static const struct inode_operations xfs
7687         .listxattr              = xfs_vn_listxattr,
7688         .fiemap                 = xfs_vn_fiemap,
7689         .update_time            = xfs_vn_update_time,
7690 +       .sync_flags             = xfs_sync_flags,
7691  };
7692  
7693  static const struct inode_operations xfs_dir_inode_operations = {
7694 @@ -1059,6 +1063,7 @@ static const struct inode_operations xfs
7695         .removexattr            = generic_removexattr,
7696         .listxattr              = xfs_vn_listxattr,
7697         .update_time            = xfs_vn_update_time,
7698 +       .sync_flags             = xfs_sync_flags,
7699  };
7700  
7701  static const struct inode_operations xfs_dir_ci_inode_operations = {
7702 @@ -1110,6 +1115,10 @@ xfs_diflags_to_iflags(
7703                 inode->i_flags |= S_IMMUTABLE;
7704         else
7705                 inode->i_flags &= ~S_IMMUTABLE;
7706 +       if (ip->i_d.di_flags & XFS_DIFLAG_IXUNLINK)
7707 +               inode->i_flags |= S_IXUNLINK;
7708 +       else
7709 +               inode->i_flags &= ~S_IXUNLINK;
7710         if (ip->i_d.di_flags & XFS_DIFLAG_APPEND)
7711                 inode->i_flags |= S_APPEND;
7712         else
7713 @@ -1122,6 +1131,15 @@ xfs_diflags_to_iflags(
7714                 inode->i_flags |= S_NOATIME;
7715         else
7716                 inode->i_flags &= ~S_NOATIME;
7717 +
7718 +       if (ip->i_d.di_vflags & XFS_DIVFLAG_BARRIER)
7719 +               inode->i_vflags |= V_BARRIER;
7720 +       else
7721 +               inode->i_vflags &= ~V_BARRIER;
7722 +       if (ip->i_d.di_vflags & XFS_DIVFLAG_COW)
7723 +               inode->i_vflags |= V_COW;
7724 +       else
7725 +               inode->i_vflags &= ~V_COW;
7726  }
7727  
7728  /*
7729 @@ -1153,6 +1171,7 @@ xfs_setup_inode(
7730         set_nlink(inode, ip->i_d.di_nlink);
7731         inode->i_uid    = ip->i_d.di_uid;
7732         inode->i_gid    = ip->i_d.di_gid;
7733 +       inode->i_tag    = ip->i_d.di_tag;
7734  
7735         switch (inode->i_mode & S_IFMT) {
7736         case S_IFBLK:
7737 diff -NurpP --minimal linux-3.6.9/fs/xfs/xfs_itable.c linux-3.6.9-vs2.3.4.4/fs/xfs/xfs_itable.c
7738 --- linux-3.6.9/fs/xfs/xfs_itable.c     2012-10-04 15:27:44.000000000 +0200
7739 +++ linux-3.6.9-vs2.3.4.4/fs/xfs/xfs_itable.c   2012-10-04 18:47:00.000000000 +0200
7740 @@ -96,6 +96,7 @@ xfs_bulkstat_one_int(
7741         buf->bs_mode = dic->di_mode;
7742         buf->bs_uid = dic->di_uid;
7743         buf->bs_gid = dic->di_gid;
7744 +       buf->bs_tag = dic->di_tag;
7745         buf->bs_size = dic->di_size;
7746         buf->bs_atime.tv_sec = dic->di_atime.t_sec;
7747         buf->bs_atime.tv_nsec = dic->di_atime.t_nsec;
7748 diff -NurpP --minimal linux-3.6.9/fs/xfs/xfs_linux.h linux-3.6.9-vs2.3.4.4/fs/xfs/xfs_linux.h
7749 --- linux-3.6.9/fs/xfs/xfs_linux.h      2011-10-24 18:45:31.000000000 +0200
7750 +++ linux-3.6.9-vs2.3.4.4/fs/xfs/xfs_linux.h    2012-10-04 18:47:00.000000000 +0200
7751 @@ -121,6 +121,7 @@
7752  
7753  #define current_cpu()          (raw_smp_processor_id())
7754  #define current_pid()          (current->pid)
7755 +#define current_fstag(vp)      (dx_current_fstag((vp)->i_sb))
7756  #define current_test_flags(f)  (current->flags & (f))
7757  #define current_set_flags_nested(sp, f)                \
7758                 (*(sp) = current->flags, current->flags |= (f))
7759 diff -NurpP --minimal linux-3.6.9/fs/xfs/xfs_log_recover.c linux-3.6.9-vs2.3.4.4/fs/xfs/xfs_log_recover.c
7760 --- linux-3.6.9/fs/xfs/xfs_log_recover.c        2012-12-08 01:34:14.000000000 +0100
7761 +++ linux-3.6.9-vs2.3.4.4/fs/xfs/xfs_log_recover.c      2012-12-08 01:36:33.000000000 +0100
7762 @@ -2359,7 +2359,8 @@ xlog_recover_inode_pass2(
7763         }
7764  
7765         /* The core is in in-core format */
7766 -       xfs_dinode_to_disk(dip, item->ri_buf[1].i_addr);
7767 +       xfs_dinode_to_disk(dip, item->ri_buf[1].i_addr,
7768 +               mp->m_flags & XFS_MOUNT_TAGGED);
7769  
7770         /* the rest is in on-disk format */
7771         if (item->ri_buf[1].i_len > sizeof(struct xfs_icdinode)) {
7772 diff -NurpP --minimal linux-3.6.9/fs/xfs/xfs_mount.h linux-3.6.9-vs2.3.4.4/fs/xfs/xfs_mount.h
7773 --- linux-3.6.9/fs/xfs/xfs_mount.h      2012-10-04 15:27:44.000000000 +0200
7774 +++ linux-3.6.9-vs2.3.4.4/fs/xfs/xfs_mount.h    2012-10-04 18:47:00.000000000 +0200
7775 @@ -251,6 +251,7 @@ typedef struct xfs_mount {
7776                                                    allocator */
7777  #define XFS_MOUNT_NOATTR2      (1ULL << 25)    /* disable use of attr2 format */
7778  
7779 +#define XFS_MOUNT_TAGGED       (1ULL << 31)    /* context tagging */
7780  
7781  /*
7782   * Default minimum read and write sizes.
7783 diff -NurpP --minimal linux-3.6.9/fs/xfs/xfs_super.c linux-3.6.9-vs2.3.4.4/fs/xfs/xfs_super.c
7784 --- linux-3.6.9/fs/xfs/xfs_super.c      2012-10-04 15:27:44.000000000 +0200
7785 +++ linux-3.6.9-vs2.3.4.4/fs/xfs/xfs_super.c    2012-10-04 18:47:00.000000000 +0200
7786 @@ -112,6 +112,9 @@ mempool_t *xfs_ioend_pool;
7787  #define MNTOPT_NODELAYLOG  "nodelaylog"        /* Delayed logging disabled */
7788  #define MNTOPT_DISCARD    "discard"    /* Discard unused blocks */
7789  #define MNTOPT_NODISCARD   "nodiscard" /* Do not discard unused blocks */
7790 +#define MNTOPT_TAGXID  "tagxid"        /* context tagging for inodes */
7791 +#define MNTOPT_TAGGED  "tag"           /* context tagging for inodes */
7792 +#define MNTOPT_NOTAGTAG        "notag"         /* do not use context tagging */
7793  
7794  /*
7795   * Table driven mount option parser.
7796 @@ -120,10 +123,14 @@ mempool_t *xfs_ioend_pool;
7797   * in the future, too.
7798   */
7799  enum {
7800 +       Opt_tag, Opt_notag,
7801         Opt_barrier, Opt_nobarrier, Opt_err
7802  };
7803  
7804  static const match_table_t tokens = {
7805 +       {Opt_tag, "tagxid"},
7806 +       {Opt_tag, "tag"},
7807 +       {Opt_notag, "notag"},
7808         {Opt_barrier, "barrier"},
7809         {Opt_nobarrier, "nobarrier"},
7810         {Opt_err, NULL}
7811 @@ -371,6 +378,19 @@ xfs_parseargs(
7812                 } else if (!strcmp(this_char, "irixsgid")) {
7813                         xfs_warn(mp,
7814         "irixsgid is now a sysctl(2) variable, option is deprecated.");
7815 +#ifndef CONFIG_TAGGING_NONE
7816 +               } else if (!strcmp(this_char, MNTOPT_TAGGED)) {
7817 +                       mp->m_flags |= XFS_MOUNT_TAGGED;
7818 +               } else if (!strcmp(this_char, MNTOPT_NOTAGTAG)) {
7819 +                       mp->m_flags &= ~XFS_MOUNT_TAGGED;
7820 +               } else if (!strcmp(this_char, MNTOPT_TAGXID)) {
7821 +                       mp->m_flags |= XFS_MOUNT_TAGGED;
7822 +#endif
7823 +#ifdef CONFIG_PROPAGATE
7824 +               } else if (!strcmp(this_char, MNTOPT_TAGGED)) {
7825 +                       /* use value */
7826 +                       mp->m_flags |= XFS_MOUNT_TAGGED;
7827 +#endif
7828                 } else {
7829                         xfs_warn(mp, "unknown mount option [%s].", this_char);
7830                         return EINVAL;
7831 @@ -1056,6 +1076,16 @@ xfs_fs_remount(
7832                 case Opt_nobarrier:
7833                         mp->m_flags &= ~XFS_MOUNT_BARRIER;
7834                         break;
7835 +               case Opt_tag:
7836 +                       if (!(sb->s_flags & MS_TAGGED)) {
7837 +                               printk(KERN_INFO
7838 +                                       "XFS: %s: tagging not permitted on remount.\n",
7839 +                                       sb->s_id);
7840 +                               return -EINVAL;
7841 +                       }
7842 +                       break;
7843 +               case Opt_notag:
7844 +                       break;
7845                 default:
7846                         /*
7847                          * Logically we would return an error here to prevent
7848 @@ -1275,6 +1305,9 @@ xfs_fs_fill_super(
7849         if (error)
7850                 goto out_free_sb;
7851  
7852 +       if (mp->m_flags & XFS_MOUNT_TAGGED)
7853 +               sb->s_flags |= MS_TAGGED;
7854 +
7855         /*
7856          * we must configure the block size in the superblock before we run the
7857          * full mount process as the mount process can lookup and cache inodes.
7858 diff -NurpP --minimal linux-3.6.9/fs/xfs/xfs_vnodeops.c linux-3.6.9-vs2.3.4.4/fs/xfs/xfs_vnodeops.c
7859 --- linux-3.6.9/fs/xfs/xfs_vnodeops.c   2012-10-04 15:27:44.000000000 +0200
7860 +++ linux-3.6.9-vs2.3.4.4/fs/xfs/xfs_vnodeops.c 2012-10-04 18:47:00.000000000 +0200
7861 @@ -103,6 +103,77 @@ xfs_readlink_bmap(
7862         return error;
7863  }
7864  
7865 +
7866 +STATIC void
7867 +xfs_get_inode_flags(
7868 +       xfs_inode_t     *ip)
7869 +{
7870 +       struct inode    *inode = VFS_I(ip);
7871 +       unsigned int    flags = inode->i_flags;
7872 +       unsigned int    vflags = inode->i_vflags;
7873 +
7874 +       if (flags & S_IMMUTABLE)
7875 +               ip->i_d.di_flags |= XFS_DIFLAG_IMMUTABLE;
7876 +       else
7877 +               ip->i_d.di_flags &= ~XFS_DIFLAG_IMMUTABLE;
7878 +       if (flags & S_IXUNLINK)
7879 +               ip->i_d.di_flags |= XFS_DIFLAG_IXUNLINK;
7880 +       else
7881 +               ip->i_d.di_flags &= ~XFS_DIFLAG_IXUNLINK;
7882 +
7883 +       if (vflags & V_BARRIER)
7884 +               ip->i_d.di_vflags |= XFS_DIVFLAG_BARRIER;
7885 +       else
7886 +               ip->i_d.di_vflags &= ~XFS_DIVFLAG_BARRIER;
7887 +       if (vflags & V_COW)
7888 +               ip->i_d.di_vflags |= XFS_DIVFLAG_COW;
7889 +       else
7890 +               ip->i_d.di_vflags &= ~XFS_DIVFLAG_COW;
7891 +}
7892 +
7893 +int
7894 +xfs_sync_flags(
7895 +       struct inode            *inode,
7896 +       int                     flags,
7897 +       int                     vflags)
7898 +{
7899 +       struct xfs_inode        *ip = XFS_I(inode);
7900 +       struct xfs_mount        *mp = ip->i_mount;
7901 +       struct xfs_trans        *tp;
7902 +       unsigned int            lock_flags = 0;
7903 +       int                     code;
7904 +
7905 +       tp = xfs_trans_alloc(mp, XFS_TRANS_SETATTR_NOT_SIZE);
7906 +       code = xfs_trans_reserve(tp, 0, XFS_ICHANGE_LOG_RES(mp), 0, 0, 0);
7907 +       if (code)
7908 +               goto error_out;
7909 +
7910 +       xfs_ilock(ip, XFS_ILOCK_EXCL);
7911 +       xfs_trans_ijoin(tp, ip, 0);
7912 +
7913 +       inode->i_flags = flags;
7914 +       inode->i_vflags = vflags;
7915 +       xfs_get_inode_flags(ip);
7916 +
7917 +       xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE);
7918 +       xfs_trans_ichgtime(tp, ip, XFS_ICHGTIME_CHG);
7919 +
7920 +       XFS_STATS_INC(xs_ig_attrchg);
7921 +
7922 +       if (mp->m_flags & XFS_MOUNT_WSYNC)
7923 +               xfs_trans_set_sync(tp);
7924 +       code = xfs_trans_commit(tp, 0);
7925 +       xfs_iunlock(ip, XFS_ILOCK_EXCL);
7926 +       return code;
7927 +
7928 +error_out:
7929 +       xfs_trans_cancel(tp, 0);
7930 +       if (lock_flags)
7931 +               xfs_iunlock(ip, XFS_ILOCK_EXCL);
7932 +       return code;
7933 +}
7934 +
7935 +
7936  int
7937  xfs_readlink(
7938         xfs_inode_t     *ip,
7939 diff -NurpP --minimal linux-3.6.9/include/linux/Kbuild linux-3.6.9-vs2.3.4.4/include/linux/Kbuild
7940 --- linux-3.6.9/include/linux/Kbuild    2012-10-04 15:27:45.000000000 +0200
7941 +++ linux-3.6.9-vs2.3.4.4/include/linux/Kbuild  2012-10-04 18:47:00.000000000 +0200
7942 @@ -18,6 +18,7 @@ header-y += netfilter_bridge/
7943  header-y += netfilter_ipv4/
7944  header-y += netfilter_ipv6/
7945  header-y += usb/
7946 +header-y += vserver/
7947  header-y += wimax/
7948  
7949  objhdr-y += version.h
7950 diff -NurpP --minimal linux-3.6.9/include/linux/capability.h linux-3.6.9-vs2.3.4.4/include/linux/capability.h
7951 --- linux-3.6.9/include/linux/capability.h      2012-07-22 23:39:43.000000000 +0200
7952 +++ linux-3.6.9-vs2.3.4.4/include/linux/capability.h    2012-10-04 18:47:00.000000000 +0200
7953 @@ -280,6 +280,7 @@ struct cpu_vfs_cap_data {
7954     arbitrary SCSI commands */
7955  /* Allow setting encryption key on loopback filesystem */
7956  /* Allow setting zone reclaim policy */
7957 +/* Allow the selection of a security context */
7958  
7959  #define CAP_SYS_ADMIN        21
7960  
7961 @@ -366,7 +367,12 @@ struct cpu_vfs_cap_data {
7962  
7963  #define CAP_LAST_CAP         CAP_BLOCK_SUSPEND
7964  
7965 -#define cap_valid(x) ((x) >= 0 && (x) <= CAP_LAST_CAP)
7966 +/* Allow context manipulations */
7967 +/* Allow changing context info on files */
7968 +
7969 +#define CAP_CONTEXT         63
7970 +
7971 +#define cap_valid(x) ((x) >= 0 && ((x) <= CAP_LAST_CAP || (x) == CAP_CONTEXT))
7972  
7973  /*
7974   * Bit location of each capability (used by user-space library and kernel)
7975 diff -NurpP --minimal linux-3.6.9/include/linux/cred.h linux-3.6.9-vs2.3.4.4/include/linux/cred.h
7976 --- linux-3.6.9/include/linux/cred.h    2012-07-22 23:39:43.000000000 +0200
7977 +++ linux-3.6.9-vs2.3.4.4/include/linux/cred.h  2012-10-04 18:47:00.000000000 +0200
7978 @@ -157,6 +157,7 @@ extern void exit_creds(struct task_struc
7979  extern int copy_creds(struct task_struct *, unsigned long);
7980  extern const struct cred *get_task_cred(struct task_struct *);
7981  extern struct cred *cred_alloc_blank(void);
7982 +extern struct cred *__prepare_creds(const struct cred *);
7983  extern struct cred *prepare_creds(void);
7984  extern struct cred *prepare_exec_creds(void);
7985  extern int commit_creds(struct cred *);
7986 @@ -210,6 +211,31 @@ static inline void validate_process_cred
7987  }
7988  #endif
7989  
7990 +static inline void set_cred_subscribers(struct cred *cred, int n)
7991 +{
7992 +#ifdef CONFIG_DEBUG_CREDENTIALS
7993 +       atomic_set(&cred->subscribers, n);
7994 +#endif
7995 +}
7996 +
7997 +static inline int read_cred_subscribers(const struct cred *cred)
7998 +{
7999 +#ifdef CONFIG_DEBUG_CREDENTIALS
8000 +       return atomic_read(&cred->subscribers);
8001 +#else
8002 +       return 0;
8003 +#endif
8004 +}
8005 +
8006 +static inline void alter_cred_subscribers(const struct cred *_cred, int n)
8007 +{
8008 +#ifdef CONFIG_DEBUG_CREDENTIALS
8009 +       struct cred *cred = (struct cred *) _cred;
8010 +
8011 +       atomic_add(n, &cred->subscribers);
8012 +#endif
8013 +}
8014 +
8015  /**
8016   * get_new_cred - Get a reference on a new set of credentials
8017   * @cred: The new credentials to reference
8018 diff -NurpP --minimal linux-3.6.9/include/linux/devpts_fs.h linux-3.6.9-vs2.3.4.4/include/linux/devpts_fs.h
8019 --- linux-3.6.9/include/linux/devpts_fs.h       2008-12-25 00:26:37.000000000 +0100
8020 +++ linux-3.6.9-vs2.3.4.4/include/linux/devpts_fs.h     2012-10-04 18:47:00.000000000 +0200
8021 @@ -45,5 +45,4 @@ static inline void devpts_pty_kill(struc
8022  
8023  #endif
8024  
8025 -
8026  #endif /* _LINUX_DEVPTS_FS_H */
8027 diff -NurpP --minimal linux-3.6.9/include/linux/fs.h linux-3.6.9-vs2.3.4.4/include/linux/fs.h
8028 --- linux-3.6.9/include/linux/fs.h      2012-10-04 15:27:45.000000000 +0200
8029 +++ linux-3.6.9-vs2.3.4.4/include/linux/fs.h    2012-10-04 18:47:00.000000000 +0200
8030 @@ -225,6 +225,9 @@ struct inodes_stat_t {
8031  #define MS_KERNMOUNT   (1<<22) /* this is a kern_mount call */
8032  #define MS_I_VERSION   (1<<23) /* Update inode I_version field */
8033  #define MS_STRICTATIME (1<<24) /* Always perform atime updates */
8034 +#define MS_TAGGED      (1<<25) /* use generic inode tagging */
8035 +#define MS_TAGID       (1<<26) /* use specific tag for this mount */
8036 +#define MS_NOTAGCHECK  (1<<27) /* don't check tags */
8037  #define MS_NOSEC       (1<<28)
8038  #define MS_BORN                (1<<29)
8039  #define MS_ACTIVE      (1<<30)
8040 @@ -256,6 +259,14 @@ struct inodes_stat_t {
8041  #define S_IMA          1024    /* Inode has an associated IMA struct */
8042  #define S_AUTOMOUNT    2048    /* Automount/referral quasi-directory */
8043  #define S_NOSEC                4096    /* no suid or xattr security attributes */
8044 +#define S_IXUNLINK     8192    /* Immutable Invert on unlink */
8045 +
8046 +/* Linux-VServer related Inode flags */
8047 +
8048 +#define V_VALID                1
8049 +#define V_XATTR                2
8050 +#define V_BARRIER      4       /* Barrier for chroot() */
8051 +#define V_COW          8       /* Copy on Write */
8052  
8053  /*
8054   * Note that nosuid etc flags are inode-specific: setting some file-system
8055 @@ -278,12 +289,15 @@ struct inodes_stat_t {
8056  #define IS_DIRSYNC(inode)      (__IS_FLG(inode, MS_SYNCHRONOUS|MS_DIRSYNC) || \
8057                                         ((inode)->i_flags & (S_SYNC|S_DIRSYNC)))
8058  #define IS_MANDLOCK(inode)     __IS_FLG(inode, MS_MANDLOCK)
8059 -#define IS_NOATIME(inode)   __IS_FLG(inode, MS_RDONLY|MS_NOATIME)
8060 -#define IS_I_VERSION(inode)   __IS_FLG(inode, MS_I_VERSION)
8061 +#define IS_NOATIME(inode)      __IS_FLG(inode, MS_RDONLY|MS_NOATIME)
8062 +#define IS_I_VERSION(inode)    __IS_FLG(inode, MS_I_VERSION)
8063 +#define IS_TAGGED(inode)       __IS_FLG(inode, MS_TAGGED)
8064  
8065  #define IS_NOQUOTA(inode)      ((inode)->i_flags & S_NOQUOTA)
8066  #define IS_APPEND(inode)       ((inode)->i_flags & S_APPEND)
8067  #define IS_IMMUTABLE(inode)    ((inode)->i_flags & S_IMMUTABLE)
8068 +#define IS_IXUNLINK(inode)     ((inode)->i_flags & S_IXUNLINK)
8069 +#define IS_IXORUNLINK(inode)   ((IS_IXUNLINK(inode) ? S_IMMUTABLE : 0) ^ IS_IMMUTABLE(inode))
8070  #define IS_POSIXACL(inode)     __IS_FLG(inode, MS_POSIXACL)
8071  
8072  #define IS_DEADDIR(inode)      ((inode)->i_flags & S_DEAD)
8073 @@ -294,6 +308,16 @@ struct inodes_stat_t {
8074  #define IS_AUTOMOUNT(inode)    ((inode)->i_flags & S_AUTOMOUNT)
8075  #define IS_NOSEC(inode)                ((inode)->i_flags & S_NOSEC)
8076  
8077 +#define IS_BARRIER(inode)      (S_ISDIR((inode)->i_mode) && ((inode)->i_vflags & V_BARRIER))
8078 +
8079 +#ifdef CONFIG_VSERVER_COWBL
8080 +#  define IS_COW(inode)                (IS_IXUNLINK(inode) && IS_IMMUTABLE(inode))
8081 +#  define IS_COW_LINK(inode)   (S_ISREG((inode)->i_mode) && ((inode)->i_nlink > 1))
8082 +#else
8083 +#  define IS_COW(inode)                (0)
8084 +#  define IS_COW_LINK(inode)   (0)
8085 +#endif
8086 +
8087  /* the read-only stuff doesn't really belong here, but any other place is
8088     probably as bad and I don't want to create yet another include file. */
8089  
8090 @@ -380,11 +404,14 @@ struct inodes_stat_t {
8091  #define FS_EXTENT_FL                   0x00080000 /* Extents */
8092  #define FS_DIRECTIO_FL                 0x00100000 /* Use direct i/o */
8093  #define FS_NOCOW_FL                    0x00800000 /* Do not cow file */
8094 +#define FS_IXUNLINK_FL                 0x08000000 /* Immutable invert on unlink */
8095  #define FS_RESERVED_FL                 0x80000000 /* reserved for ext2 lib */
8096  
8097 -#define FS_FL_USER_VISIBLE             0x0003DFFF /* User visible flags */
8098 -#define FS_FL_USER_MODIFIABLE          0x000380FF /* User modifiable flags */
8099 +#define FS_BARRIER_FL                  0x04000000 /* Barrier for chroot() */
8100 +#define FS_COW_FL                      0x20000000 /* Copy on Write marker */
8101  
8102 +#define FS_FL_USER_VISIBLE             0x0103DFFF /* User visible flags */
8103 +#define FS_FL_USER_MODIFIABLE          0x010380FF /* User modifiable flags */
8104  
8105  #define SYNC_FILE_RANGE_WAIT_BEFORE    1
8106  #define SYNC_FILE_RANGE_WRITE          2
8107 @@ -472,6 +499,7 @@ typedef void (dio_iodone_t)(struct kiocb
8108  #define ATTR_KILL_PRIV (1 << 14)
8109  #define ATTR_OPEN      (1 << 15) /* Truncating from open(O_TRUNC) */
8110  #define ATTR_TIMES_SET (1 << 16)
8111 +#define ATTR_TAG       (1 << 17)
8112  
8113  /*
8114   * This is the Inode Attributes structure, used for notify_change().  It
8115 @@ -487,6 +515,7 @@ struct iattr {
8116         umode_t         ia_mode;
8117         kuid_t          ia_uid;
8118         kgid_t          ia_gid;
8119 +       vs_tag_t                ia_tag;
8120         loff_t          ia_size;
8121         struct timespec ia_atime;
8122         struct timespec ia_mtime;
8123 @@ -500,6 +529,9 @@ struct iattr {
8124         struct file     *ia_file;
8125  };
8126  
8127 +#define ATTR_FLAG_BARRIER      512     /* Barrier for chroot() */
8128 +#define ATTR_FLAG_IXUNLINK     1024    /* Immutable invert on unlink */
8129 +
8130  /*
8131   * Includes for diskquotas.
8132   */
8133 @@ -784,7 +816,9 @@ struct inode {
8134         unsigned short          i_opflags;
8135         kuid_t                  i_uid;
8136         kgid_t                  i_gid;
8137 -       unsigned int            i_flags;
8138 +       vs_tag_t                        i_tag;
8139 +       unsigned short          i_flags;
8140 +       unsigned short          i_vflags;
8141  
8142  #ifdef CONFIG_FS_POSIX_ACL
8143         struct posix_acl        *i_acl;
8144 @@ -813,6 +847,7 @@ struct inode {
8145                 unsigned int __i_nlink;
8146         };
8147         dev_t                   i_rdev;
8148 +       dev_t                   i_mdev;
8149         loff_t                  i_size;
8150         struct timespec         i_atime;
8151         struct timespec         i_mtime;
8152 @@ -975,12 +1010,12 @@ static inline void i_gid_write(struct in
8153  
8154  static inline unsigned iminor(const struct inode *inode)
8155  {
8156 -       return MINOR(inode->i_rdev);
8157 +       return MINOR(inode->i_mdev);
8158  }
8159  
8160  static inline unsigned imajor(const struct inode *inode)
8161  {
8162 -       return MAJOR(inode->i_rdev);
8163 +       return MAJOR(inode->i_mdev);
8164  }
8165  
8166  extern struct block_device *I_BDEV(struct inode *inode);
8167 @@ -1047,6 +1082,7 @@ struct file {
8168         loff_t                  f_pos;
8169         struct fown_struct      f_owner;
8170         const struct cred       *f_cred;
8171 +       xid_t                   f_xid;
8172         struct file_ra_state    f_ra;
8173  
8174         u64                     f_version;
8175 @@ -1194,6 +1230,7 @@ struct file_lock {
8176         struct file *fl_file;
8177         loff_t fl_start;
8178         loff_t fl_end;
8179 +       xid_t fl_xid;
8180  
8181         struct fasync_struct *  fl_fasync; /* for lease break notifications */
8182         /* for lease breaks: */
8183 @@ -1829,6 +1866,7 @@ struct inode_operations {
8184         ssize_t (*getxattr) (struct dentry *, const char *, void *, size_t);
8185         ssize_t (*listxattr) (struct dentry *, char *, size_t);
8186         int (*removexattr) (struct dentry *, const char *);
8187 +       int (*sync_flags) (struct inode *, int, int);
8188         int (*fiemap)(struct inode *, struct fiemap_extent_info *, u64 start,
8189                       u64 len);
8190         int (*update_time)(struct inode *, struct timespec *, int);
8191 @@ -1850,6 +1888,7 @@ extern ssize_t vfs_readv(struct file *, 
8192                 unsigned long, loff_t *);
8193  extern ssize_t vfs_writev(struct file *, const struct iovec __user *,
8194                 unsigned long, loff_t *);
8195 +ssize_t vfs_sendfile(struct file *, struct file *, loff_t *, size_t, loff_t);
8196  
8197  struct super_operations {
8198         struct inode *(*alloc_inode)(struct super_block *sb);
8199 @@ -2692,6 +2731,7 @@ extern int dcache_dir_open(struct inode 
8200  extern int dcache_dir_close(struct inode *, struct file *);
8201  extern loff_t dcache_dir_lseek(struct file *, loff_t, int);
8202  extern int dcache_readdir(struct file *, void *, filldir_t);
8203 +extern int dcache_readdir_filter(struct file *, void *, filldir_t, int (*)(struct dentry *));
8204  extern int simple_setattr(struct dentry *, struct iattr *);
8205  extern int simple_getattr(struct vfsmount *, struct dentry *, struct kstat *);
8206  extern int simple_statfs(struct dentry *, struct kstatfs *);
8207 diff -NurpP --minimal linux-3.6.9/include/linux/gfs2_ondisk.h linux-3.6.9-vs2.3.4.4/include/linux/gfs2_ondisk.h
8208 --- linux-3.6.9/include/linux/gfs2_ondisk.h     2012-10-04 15:27:45.000000000 +0200
8209 +++ linux-3.6.9-vs2.3.4.4/include/linux/gfs2_ondisk.h   2012-10-04 18:54:29.000000000 +0200
8210 @@ -225,6 +225,9 @@ enum {
8211         gfs2fl_Sync             = 8,
8212         gfs2fl_System           = 9,
8213         gfs2fl_TopLevel         = 10,
8214 +       gfs2fl_IXUnlink         = 16,
8215 +       gfs2fl_Barrier          = 17,
8216 +       gfs2fl_Cow              = 18,
8217         gfs2fl_TruncInProg      = 29,
8218         gfs2fl_InheritDirectio  = 30,
8219         gfs2fl_InheritJdata     = 31,
8220 @@ -242,6 +245,9 @@ enum {
8221  #define GFS2_DIF_SYNC                  0x00000100
8222  #define GFS2_DIF_SYSTEM                        0x00000200 /* New in gfs2 */
8223  #define GFS2_DIF_TOPDIR                        0x00000400 /* New in gfs2 */
8224 +#define GFS2_DIF_IXUNLINK              0x00010000
8225 +#define GFS2_DIF_BARRIER               0x00020000
8226 +#define GFS2_DIF_COW                   0x00040000
8227  #define GFS2_DIF_TRUNC_IN_PROG         0x20000000 /* New in gfs2 */
8228  #define GFS2_DIF_INHERIT_DIRECTIO      0x40000000 /* only in gfs1 */
8229  #define GFS2_DIF_INHERIT_JDATA         0x80000000
8230 diff -NurpP --minimal linux-3.6.9/include/linux/if_tun.h linux-3.6.9-vs2.3.4.4/include/linux/if_tun.h
8231 --- linux-3.6.9/include/linux/if_tun.h  2010-08-02 16:52:54.000000000 +0200
8232 +++ linux-3.6.9-vs2.3.4.4/include/linux/if_tun.h        2012-10-04 18:47:00.000000000 +0200
8233 @@ -53,6 +53,7 @@
8234  #define TUNDETACHFILTER _IOW('T', 214, struct sock_fprog)
8235  #define TUNGETVNETHDRSZ _IOR('T', 215, int)
8236  #define TUNSETVNETHDRSZ _IOW('T', 216, int)
8237 +#define TUNSETNID     _IOW('T', 217, int)
8238  
8239  /* TUNSETIFF ifr flags */
8240  #define IFF_TUN                0x0001
8241 diff -NurpP --minimal linux-3.6.9/include/linux/init_task.h linux-3.6.9-vs2.3.4.4/include/linux/init_task.h
8242 --- linux-3.6.9/include/linux/init_task.h       2012-10-04 15:27:45.000000000 +0200
8243 +++ linux-3.6.9-vs2.3.4.4/include/linux/init_task.h     2012-10-04 18:47:00.000000000 +0200
8244 @@ -210,6 +210,10 @@ extern struct task_group root_task_group
8245         INIT_TRACE_RECURSION                                            \
8246         INIT_TASK_RCU_PREEMPT(tsk)                                      \
8247         INIT_CPUSET_SEQ                                                 \
8248 +       .xid            = 0,                                            \
8249 +       .vx_info        = NULL,                                         \
8250 +       .nid            = 0,                                            \
8251 +       .nx_info        = NULL,                                         \
8252  }
8253  
8254  
8255 diff -NurpP --minimal linux-3.6.9/include/linux/ipc.h linux-3.6.9-vs2.3.4.4/include/linux/ipc.h
8256 --- linux-3.6.9/include/linux/ipc.h     2012-03-19 19:47:28.000000000 +0100
8257 +++ linux-3.6.9-vs2.3.4.4/include/linux/ipc.h   2012-10-04 18:47:00.000000000 +0200
8258 @@ -91,6 +91,7 @@ struct kern_ipc_perm
8259         key_t           key;
8260         uid_t           uid;
8261         gid_t           gid;
8262 +       xid_t           xid;
8263         uid_t           cuid;
8264         gid_t           cgid;
8265         umode_t         mode; 
8266 diff -NurpP --minimal linux-3.6.9/include/linux/ipc_namespace.h linux-3.6.9-vs2.3.4.4/include/linux/ipc_namespace.h
8267 --- linux-3.6.9/include/linux/ipc_namespace.h   2012-07-22 23:39:43.000000000 +0200
8268 +++ linux-3.6.9-vs2.3.4.4/include/linux/ipc_namespace.h 2012-10-04 18:47:00.000000000 +0200
8269 @@ -133,7 +133,8 @@ static inline int mq_init_ns(struct ipc_
8270  
8271  #if defined(CONFIG_IPC_NS)
8272  extern struct ipc_namespace *copy_ipcs(unsigned long flags,
8273 -                                      struct task_struct *tsk);
8274 +                                      struct ipc_namespace *old_ns,
8275 +                                      struct user_namespace *user_ns);
8276  static inline struct ipc_namespace *get_ipc_ns(struct ipc_namespace *ns)
8277  {
8278         if (ns)
8279 @@ -144,12 +145,13 @@ static inline struct ipc_namespace *get_
8280  extern void put_ipc_ns(struct ipc_namespace *ns);
8281  #else
8282  static inline struct ipc_namespace *copy_ipcs(unsigned long flags,
8283 -                                             struct task_struct *tsk)
8284 +                                             struct ipc_namespace *old_ns,
8285 +                                             struct user_namespace *user_ns)
8286  {
8287         if (flags & CLONE_NEWIPC)
8288                 return ERR_PTR(-EINVAL);
8289  
8290 -       return tsk->nsproxy->ipc_ns;
8291 +       return old_ns;
8292  }
8293  
8294  static inline struct ipc_namespace *get_ipc_ns(struct ipc_namespace *ns)
8295 diff -NurpP --minimal linux-3.6.9/include/linux/loop.h linux-3.6.9-vs2.3.4.4/include/linux/loop.h
8296 --- linux-3.6.9/include/linux/loop.h    2012-01-09 16:14:58.000000000 +0100
8297 +++ linux-3.6.9-vs2.3.4.4/include/linux/loop.h  2012-10-04 18:47:00.000000000 +0200
8298 @@ -45,6 +45,7 @@ struct loop_device {
8299         struct loop_func_table *lo_encryption;
8300         __u32           lo_init[2];
8301         uid_t           lo_key_owner;   /* Who set the key */
8302 +       xid_t           lo_xid;
8303         int             (*ioctl)(struct loop_device *, int cmd, 
8304                                  unsigned long arg); 
8305  
8306 diff -NurpP --minimal linux-3.6.9/include/linux/magic.h linux-3.6.9-vs2.3.4.4/include/linux/magic.h
8307 --- linux-3.6.9/include/linux/magic.h   2012-05-21 18:07:31.000000000 +0200
8308 +++ linux-3.6.9-vs2.3.4.4/include/linux/magic.h 2012-10-04 18:47:00.000000000 +0200
8309 @@ -3,7 +3,7 @@
8310  
8311  #define ADFS_SUPER_MAGIC       0xadf5
8312  #define AFFS_SUPER_MAGIC       0xadff
8313 -#define AFS_SUPER_MAGIC                0x5346414F
8314 +#define AFS_SUPER_MAGIC                0x5346414F
8315  #define AUTOFS_SUPER_MAGIC     0x0187
8316  #define CODA_SUPER_MAGIC       0x73757245
8317  #define CRAMFS_MAGIC           0x28cd3d45      /* some random number */
8318 diff -NurpP --minimal linux-3.6.9/include/linux/major.h linux-3.6.9-vs2.3.4.4/include/linux/major.h
8319 --- linux-3.6.9/include/linux/major.h   2009-09-10 15:26:25.000000000 +0200
8320 +++ linux-3.6.9-vs2.3.4.4/include/linux/major.h 2012-10-04 18:47:00.000000000 +0200
8321 @@ -15,6 +15,7 @@
8322  #define HD_MAJOR               IDE0_MAJOR
8323  #define PTY_SLAVE_MAJOR                3
8324  #define TTY_MAJOR              4
8325 +#define VROOT_MAJOR            4
8326  #define TTYAUX_MAJOR           5
8327  #define LP_MAJOR               6
8328  #define VCS_MAJOR              7
8329 diff -NurpP --minimal linux-3.6.9/include/linux/memcontrol.h linux-3.6.9-vs2.3.4.4/include/linux/memcontrol.h
8330 --- linux-3.6.9/include/linux/memcontrol.h      2012-10-04 15:27:45.000000000 +0200
8331 +++ linux-3.6.9-vs2.3.4.4/include/linux/memcontrol.h    2012-10-04 18:47:00.000000000 +0200
8332 @@ -83,6 +83,13 @@ extern struct mem_cgroup *try_get_mem_cg
8333  extern struct mem_cgroup *parent_mem_cgroup(struct mem_cgroup *memcg);
8334  extern struct mem_cgroup *mem_cgroup_from_cont(struct cgroup *cont);
8335  
8336 +extern u64 mem_cgroup_res_read_u64(struct mem_cgroup *mem, int member);
8337 +extern u64 mem_cgroup_memsw_read_u64(struct mem_cgroup *mem, int member);
8338 +
8339 +extern s64 mem_cgroup_stat_read_cache(struct mem_cgroup *mem);
8340 +extern s64 mem_cgroup_stat_read_anon(struct mem_cgroup *mem);
8341 +extern s64 mem_cgroup_stat_read_mapped(struct mem_cgroup *mem);
8342 +
8343  static inline
8344  int mm_match_cgroup(const struct mm_struct *mm, const struct mem_cgroup *cgroup)
8345  {
8346 diff -NurpP --minimal linux-3.6.9/include/linux/mm_types.h linux-3.6.9-vs2.3.4.4/include/linux/mm_types.h
8347 --- linux-3.6.9/include/linux/mm_types.h        2012-10-04 15:27:46.000000000 +0200
8348 +++ linux-3.6.9-vs2.3.4.4/include/linux/mm_types.h      2012-10-04 18:47:00.000000000 +0200
8349 @@ -370,6 +370,7 @@ struct mm_struct {
8350  
8351         /* Architecture-specific MM context */
8352         mm_context_t context;
8353 +       struct vx_info *mm_vx_info;
8354  
8355         unsigned long flags; /* Must use atomic bitops to access the bits */
8356  
8357 diff -NurpP --minimal linux-3.6.9/include/linux/mmzone.h linux-3.6.9-vs2.3.4.4/include/linux/mmzone.h
8358 --- linux-3.6.9/include/linux/mmzone.h  2012-12-08 01:34:14.000000000 +0100
8359 +++ linux-3.6.9-vs2.3.4.4/include/linux/mmzone.h        2012-12-08 01:36:33.000000000 +0100
8360 @@ -727,6 +727,13 @@ typedef struct pglist_data {
8361         __pgdat->node_start_pfn + __pgdat->node_spanned_pages;\
8362  })
8363  
8364 +#define node_start_pfn(nid)    (NODE_DATA(nid)->node_start_pfn)
8365 +
8366 +#define node_end_pfn(nid) ({\
8367 +       pg_data_t *__pgdat = NODE_DATA(nid);\
8368 +       __pgdat->node_start_pfn + __pgdat->node_spanned_pages;\
8369 +})
8370 +
8371  #include <linux/memory_hotplug.h>
8372  
8373  extern struct mutex zonelists_mutex;
8374 diff -NurpP --minimal linux-3.6.9/include/linux/mount.h linux-3.6.9-vs2.3.4.4/include/linux/mount.h
8375 --- linux-3.6.9/include/linux/mount.h   2012-03-19 19:47:28.000000000 +0100
8376 +++ linux-3.6.9-vs2.3.4.4/include/linux/mount.h 2012-10-04 18:47:00.000000000 +0200
8377 @@ -47,6 +47,9 @@ struct mnt_namespace;
8378  
8379  #define MNT_INTERNAL   0x4000
8380  
8381 +#define MNT_TAGID      0x10000
8382 +#define MNT_NOTAG      0x20000
8383 +
8384  struct vfsmount {
8385         struct dentry *mnt_root;        /* root of the mounted tree */
8386         struct super_block *mnt_sb;     /* pointer to superblock */
8387 diff -NurpP --minimal linux-3.6.9/include/linux/net.h linux-3.6.9-vs2.3.4.4/include/linux/net.h
8388 --- linux-3.6.9/include/linux/net.h     2012-10-04 15:27:46.000000000 +0200
8389 +++ linux-3.6.9-vs2.3.4.4/include/linux/net.h   2012-10-04 18:47:00.000000000 +0200
8390 @@ -73,6 +73,7 @@ struct net;
8391  #define SOCK_PASSCRED          3
8392  #define SOCK_PASSSEC           4
8393  #define SOCK_EXTERNALLY_ALLOCATED 5
8394 +#define SOCK_USER_SOCKET       6
8395  
8396  #ifndef ARCH_HAS_SOCKET_TYPES
8397  /**
8398 diff -NurpP --minimal linux-3.6.9/include/linux/netdevice.h linux-3.6.9-vs2.3.4.4/include/linux/netdevice.h
8399 --- linux-3.6.9/include/linux/netdevice.h       2012-10-04 15:27:46.000000000 +0200
8400 +++ linux-3.6.9-vs2.3.4.4/include/linux/netdevice.h     2012-10-04 18:47:00.000000000 +0200
8401 @@ -1651,6 +1651,7 @@ extern void               netdev_resync_ops(struct ne
8402  
8403  extern struct net_device       *dev_get_by_index(struct net *net, int ifindex);
8404  extern struct net_device       *__dev_get_by_index(struct net *net, int ifindex);
8405 +extern struct net_device       *dev_get_by_index_real_rcu(struct net *net, int ifindex);
8406  extern struct net_device       *dev_get_by_index_rcu(struct net *net, int ifindex);
8407  extern int             dev_restart(struct net_device *dev);
8408  #ifdef CONFIG_NETPOLL_TRAP
8409 diff -NurpP --minimal linux-3.6.9/include/linux/nfs_mount.h linux-3.6.9-vs2.3.4.4/include/linux/nfs_mount.h
8410 --- linux-3.6.9/include/linux/nfs_mount.h       2011-01-05 21:50:31.000000000 +0100
8411 +++ linux-3.6.9-vs2.3.4.4/include/linux/nfs_mount.h     2012-10-04 18:47:00.000000000 +0200
8412 @@ -63,7 +63,8 @@ struct nfs_mount_data {
8413  #define NFS_MOUNT_SECFLAVOUR   0x2000  /* 5 */
8414  #define NFS_MOUNT_NORDIRPLUS   0x4000  /* 5 */
8415  #define NFS_MOUNT_UNSHARED     0x8000  /* 5 */
8416 -#define NFS_MOUNT_FLAGMASK     0xFFFF
8417 +#define NFS_MOUNT_TAGGED       0x10000 /* context tagging */
8418 +#define NFS_MOUNT_FLAGMASK     0x1FFFF
8419  
8420  /* The following are for internal use only */
8421  #define NFS_MOUNT_LOOKUP_CACHE_NONEG   0x10000
8422 diff -NurpP --minimal linux-3.6.9/include/linux/nsproxy.h linux-3.6.9-vs2.3.4.4/include/linux/nsproxy.h
8423 --- linux-3.6.9/include/linux/nsproxy.h 2011-10-24 18:45:32.000000000 +0200
8424 +++ linux-3.6.9-vs2.3.4.4/include/linux/nsproxy.h       2012-10-04 18:47:00.000000000 +0200
8425 @@ -3,6 +3,7 @@
8426  
8427  #include <linux/spinlock.h>
8428  #include <linux/sched.h>
8429 +#include <linux/vserver/debug.h>
8430  
8431  struct mnt_namespace;
8432  struct uts_namespace;
8433 @@ -63,6 +64,7 @@ static inline struct nsproxy *task_nspro
8434  }
8435  
8436  int copy_namespaces(unsigned long flags, struct task_struct *tsk);
8437 +struct nsproxy *copy_nsproxy(struct nsproxy *orig);
8438  void exit_task_namespaces(struct task_struct *tsk);
8439  void switch_task_namespaces(struct task_struct *tsk, struct nsproxy *new);
8440  void free_nsproxy(struct nsproxy *ns);
8441 @@ -70,16 +72,26 @@ int unshare_nsproxy_namespaces(unsigned 
8442         struct fs_struct *);
8443  int __init nsproxy_cache_init(void);
8444  
8445 -static inline void put_nsproxy(struct nsproxy *ns)
8446 +#define        get_nsproxy(n)  __get_nsproxy(n, __FILE__, __LINE__)
8447 +
8448 +static inline void __get_nsproxy(struct nsproxy *ns,
8449 +       const char *_file, int _line)
8450  {
8451 -       if (atomic_dec_and_test(&ns->count)) {
8452 -               free_nsproxy(ns);
8453 -       }
8454 +       vxlprintk(VXD_CBIT(space, 0), "get_nsproxy(%p[%u])",
8455 +               ns, atomic_read(&ns->count), _file, _line);
8456 +       atomic_inc(&ns->count);
8457  }
8458  
8459 -static inline void get_nsproxy(struct nsproxy *ns)
8460 +#define        put_nsproxy(n)  __put_nsproxy(n, __FILE__, __LINE__)
8461 +
8462 +static inline void __put_nsproxy(struct nsproxy *ns,
8463 +       const char *_file, int _line)
8464  {
8465 -       atomic_inc(&ns->count);
8466 +       vxlprintk(VXD_CBIT(space, 0), "put_nsproxy(%p[%u])",
8467 +               ns, atomic_read(&ns->count), _file, _line);
8468 +       if (atomic_dec_and_test(&ns->count)) {
8469 +               free_nsproxy(ns);
8470 +       }
8471  }
8472  
8473  #endif
8474 diff -NurpP --minimal linux-3.6.9/include/linux/pid.h linux-3.6.9-vs2.3.4.4/include/linux/pid.h
8475 --- linux-3.6.9/include/linux/pid.h     2011-07-22 11:18:11.000000000 +0200
8476 +++ linux-3.6.9-vs2.3.4.4/include/linux/pid.h   2012-10-04 18:47:00.000000000 +0200
8477 @@ -8,7 +8,8 @@ enum pid_type
8478         PIDTYPE_PID,
8479         PIDTYPE_PGID,
8480         PIDTYPE_SID,
8481 -       PIDTYPE_MAX
8482 +       PIDTYPE_MAX,
8483 +       PIDTYPE_REALPID
8484  };
8485  
8486  /*
8487 @@ -171,6 +172,7 @@ static inline pid_t pid_nr(struct pid *p
8488  }
8489  
8490  pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns);
8491 +pid_t pid_unmapped_nr_ns(struct pid *pid, struct pid_namespace *ns);
8492  pid_t pid_vnr(struct pid *pid);
8493  
8494  #define do_each_pid_task(pid, type, task)                              \
8495 diff -NurpP --minimal linux-3.6.9/include/linux/proc_fs.h linux-3.6.9-vs2.3.4.4/include/linux/proc_fs.h
8496 --- linux-3.6.9/include/linux/proc_fs.h 2012-07-22 23:39:44.000000000 +0200
8497 +++ linux-3.6.9-vs2.3.4.4/include/linux/proc_fs.h       2012-10-04 18:47:00.000000000 +0200
8498 @@ -54,6 +54,7 @@ struct proc_dir_entry {
8499         nlink_t nlink;
8500         kuid_t uid;
8501         kgid_t gid;
8502 +       int vx_flags;
8503         loff_t size;
8504         const struct inode_operations *proc_iops;
8505         /*
8506 @@ -252,12 +253,18 @@ extern const struct proc_ns_operations n
8507  extern const struct proc_ns_operations utsns_operations;
8508  extern const struct proc_ns_operations ipcns_operations;
8509  
8510 +struct vx_info;
8511 +struct nx_info;
8512 +
8513  union proc_op {
8514         int (*proc_get_link)(struct dentry *, struct path *);
8515         int (*proc_read)(struct task_struct *task, char *page);
8516         int (*proc_show)(struct seq_file *m,
8517                 struct pid_namespace *ns, struct pid *pid,
8518                 struct task_struct *task);
8519 +       int (*proc_vs_read)(char *page);
8520 +       int (*proc_vxi_read)(struct vx_info *vxi, char *page);
8521 +       int (*proc_nxi_read)(struct nx_info *nxi, char *page);
8522  };
8523  
8524  struct ctl_table_header;
8525 @@ -265,6 +272,7 @@ struct ctl_table;
8526  
8527  struct proc_inode {
8528         struct pid *pid;
8529 +       int vx_flags;
8530         int fd;
8531         union proc_op op;
8532         struct proc_dir_entry *pde;
8533 diff -NurpP --minimal linux-3.6.9/include/linux/quotaops.h linux-3.6.9-vs2.3.4.4/include/linux/quotaops.h
8534 --- linux-3.6.9/include/linux/quotaops.h        2012-10-04 15:27:46.000000000 +0200
8535 +++ linux-3.6.9-vs2.3.4.4/include/linux/quotaops.h      2012-10-04 18:47:00.000000000 +0200
8536 @@ -8,6 +8,7 @@
8537  #define _LINUX_QUOTAOPS_
8538  
8539  #include <linux/fs.h>
8540 +#include <linux/vs_dlimit.h>
8541  
8542  #define DQUOT_SPACE_WARN       0x1
8543  #define DQUOT_SPACE_RESERVE    0x2
8544 @@ -205,11 +206,12 @@ static inline void dquot_drop(struct ino
8545  
8546  static inline int dquot_alloc_inode(const struct inode *inode)
8547  {
8548 -       return 0;
8549 +       return dl_alloc_inode(inode);
8550  }
8551  
8552  static inline void dquot_free_inode(const struct inode *inode)
8553  {
8554 +       dl_free_inode(inode);
8555  }
8556  
8557  static inline int dquot_transfer(struct inode *inode, struct iattr *iattr)
8558 @@ -220,6 +222,10 @@ static inline int dquot_transfer(struct 
8559  static inline int __dquot_alloc_space(struct inode *inode, qsize_t number,
8560                 int flags)
8561  {
8562 +       int ret = 0;
8563 +
8564 +       if ((ret = dl_alloc_space(inode, number)))
8565 +               return ret;
8566         if (!(flags & DQUOT_SPACE_RESERVE))
8567                 inode_add_bytes(inode, number);
8568         return 0;
8569 @@ -230,6 +236,7 @@ static inline void __dquot_free_space(st
8570  {
8571         if (!(flags & DQUOT_SPACE_RESERVE))
8572                 inode_sub_bytes(inode, number);
8573 +       dl_free_space(inode, number);
8574  }
8575  
8576  static inline int dquot_claim_space_nodirty(struct inode *inode, qsize_t number)
8577 diff -NurpP --minimal linux-3.6.9/include/linux/reboot.h linux-3.6.9-vs2.3.4.4/include/linux/reboot.h
8578 --- linux-3.6.9/include/linux/reboot.h  2011-10-24 18:45:32.000000000 +0200
8579 +++ linux-3.6.9-vs2.3.4.4/include/linux/reboot.h        2012-10-04 18:47:00.000000000 +0200
8580 @@ -33,6 +33,7 @@
8581  #define        LINUX_REBOOT_CMD_RESTART2       0xA1B2C3D4
8582  #define        LINUX_REBOOT_CMD_SW_SUSPEND     0xD000FCE2
8583  #define        LINUX_REBOOT_CMD_KEXEC          0x45584543
8584 +#define        LINUX_REBOOT_CMD_OOM            0xDEADBEEF
8585  
8586  
8587  #ifdef __KERNEL__
8588 diff -NurpP --minimal linux-3.6.9/include/linux/sched.h linux-3.6.9-vs2.3.4.4/include/linux/sched.h
8589 --- linux-3.6.9/include/linux/sched.h   2012-10-04 15:27:46.000000000 +0200
8590 +++ linux-3.6.9-vs2.3.4.4/include/linux/sched.h 2012-10-04 18:47:00.000000000 +0200
8591 @@ -1422,6 +1422,14 @@ struct task_struct {
8592  #endif
8593         struct seccomp seccomp;
8594  
8595 +/* vserver context data */
8596 +       struct vx_info *vx_info;
8597 +       struct nx_info *nx_info;
8598 +
8599 +       xid_t xid;
8600 +       nid_t nid;
8601 +       vs_tag_t tag;
8602 +
8603  /* Thread group tracking */
8604         u32 parent_exec_id;
8605         u32 self_exec_id;
8606 @@ -1668,6 +1676,11 @@ struct pid_namespace;
8607  pid_t __task_pid_nr_ns(struct task_struct *task, enum pid_type type,
8608                         struct pid_namespace *ns);
8609  
8610 +#include <linux/vserver/base.h>
8611 +#include <linux/vserver/context.h>
8612 +#include <linux/vserver/debug.h>
8613 +#include <linux/vserver/pid.h>
8614 +
8615  static inline pid_t task_pid_nr(struct task_struct *tsk)
8616  {
8617         return tsk->pid;
8618 @@ -1681,7 +1694,8 @@ static inline pid_t task_pid_nr_ns(struc
8619  
8620  static inline pid_t task_pid_vnr(struct task_struct *tsk)
8621  {
8622 -       return __task_pid_nr_ns(tsk, PIDTYPE_PID, NULL);
8623 +       // return __task_pid_nr_ns(tsk, PIDTYPE_PID, NULL);
8624 +       return vx_map_pid(__task_pid_nr_ns(tsk, PIDTYPE_PID, NULL));
8625  }
8626  
8627  
8628 @@ -1694,7 +1708,7 @@ pid_t task_tgid_nr_ns(struct task_struct
8629  
8630  static inline pid_t task_tgid_vnr(struct task_struct *tsk)
8631  {
8632 -       return pid_vnr(task_tgid(tsk));
8633 +       return vx_map_tgid(pid_vnr(task_tgid(tsk)));
8634  }
8635  
8636  
8637 diff -NurpP --minimal linux-3.6.9/include/linux/shmem_fs.h linux-3.6.9-vs2.3.4.4/include/linux/shmem_fs.h
8638 --- linux-3.6.9/include/linux/shmem_fs.h        2012-07-22 23:39:44.000000000 +0200
8639 +++ linux-3.6.9-vs2.3.4.4/include/linux/shmem_fs.h      2012-10-04 18:47:00.000000000 +0200
8640 @@ -8,6 +8,9 @@
8641  
8642  /* inode in-kernel data */
8643  
8644 +#define TMPFS_SUPER_MAGIC      0x01021994
8645 +
8646 +
8647  struct shmem_inode_info {
8648         spinlock_t              lock;
8649         unsigned long           flags;
8650 diff -NurpP --minimal linux-3.6.9/include/linux/stat.h linux-3.6.9-vs2.3.4.4/include/linux/stat.h
8651 --- linux-3.6.9/include/linux/stat.h    2012-07-22 23:39:44.000000000 +0200
8652 +++ linux-3.6.9-vs2.3.4.4/include/linux/stat.h  2012-10-04 18:47:00.000000000 +0200
8653 @@ -67,6 +67,7 @@ struct kstat {
8654         unsigned int    nlink;
8655         kuid_t          uid;
8656         kgid_t          gid;
8657 +       vs_tag_t                tag;
8658         dev_t           rdev;
8659         loff_t          size;
8660         struct timespec  atime;
8661 diff -NurpP --minimal linux-3.6.9/include/linux/sunrpc/auth.h linux-3.6.9-vs2.3.4.4/include/linux/sunrpc/auth.h
8662 --- linux-3.6.9/include/linux/sunrpc/auth.h     2012-10-04 15:27:46.000000000 +0200
8663 +++ linux-3.6.9-vs2.3.4.4/include/linux/sunrpc/auth.h   2012-10-04 18:47:00.000000000 +0200
8664 @@ -25,6 +25,7 @@
8665  struct auth_cred {
8666         uid_t   uid;
8667         gid_t   gid;
8668 +       vs_tag_t        tag;
8669         struct group_info *group_info;
8670         const char *principal;
8671         unsigned char machine_cred : 1;
8672 diff -NurpP --minimal linux-3.6.9/include/linux/sunrpc/clnt.h linux-3.6.9-vs2.3.4.4/include/linux/sunrpc/clnt.h
8673 --- linux-3.6.9/include/linux/sunrpc/clnt.h     2012-05-21 18:07:32.000000000 +0200
8674 +++ linux-3.6.9-vs2.3.4.4/include/linux/sunrpc/clnt.h   2012-10-04 18:47:00.000000000 +0200
8675 @@ -49,7 +49,8 @@ struct rpc_clnt {
8676         unsigned int            cl_softrtry : 1,/* soft timeouts */
8677                                 cl_discrtry : 1,/* disconnect before retry */
8678                                 cl_autobind : 1,/* use getport() */
8679 -                               cl_chatty   : 1;/* be verbose */
8680 +                               cl_chatty   : 1,/* be verbose */
8681 +                               cl_tag      : 1;/* context tagging */
8682  
8683         struct rpc_rtt *        cl_rtt;         /* RTO estimator data */
8684         const struct rpc_timeout *cl_timeout;   /* Timeout strategy */
8685 diff -NurpP --minimal linux-3.6.9/include/linux/sysctl.h linux-3.6.9-vs2.3.4.4/include/linux/sysctl.h
8686 --- linux-3.6.9/include/linux/sysctl.h  2012-05-21 18:07:32.000000000 +0200
8687 +++ linux-3.6.9-vs2.3.4.4/include/linux/sysctl.h        2012-10-04 18:47:00.000000000 +0200
8688 @@ -60,6 +60,7 @@ enum
8689         CTL_ABI=9,              /* Binary emulation */
8690         CTL_CPU=10,             /* CPU stuff (speed scaling, etc) */
8691         CTL_ARLAN=254,          /* arlan wireless driver */
8692 +       CTL_VSERVER=4242,       /* Linux-VServer debug */
8693         CTL_S390DBF=5677,       /* s390 debug */
8694         CTL_SUNRPC=7249,        /* sunrpc debug */
8695         CTL_PM=9899,            /* frv power management */
8696 @@ -94,6 +95,7 @@ enum
8697  
8698         KERN_PANIC=15,          /* int: panic timeout */
8699         KERN_REALROOTDEV=16,    /* real root device to mount after initrd */
8700 +       KERN_VSHELPER=17,       /* string: path to vshelper policy agent */
8701  
8702         KERN_SPARC_REBOOT=21,   /* reboot command on Sparc */
8703         KERN_CTLALTDEL=22,      /* int: allow ctl-alt-del to reboot */
8704 diff -NurpP --minimal linux-3.6.9/include/linux/sysfs.h linux-3.6.9-vs2.3.4.4/include/linux/sysfs.h
8705 --- linux-3.6.9/include/linux/sysfs.h   2012-07-22 23:39:44.000000000 +0200
8706 +++ linux-3.6.9-vs2.3.4.4/include/linux/sysfs.h 2012-10-04 18:47:00.000000000 +0200
8707 @@ -19,6 +19,8 @@
8708  #include <linux/kobject_ns.h>
8709  #include <linux/atomic.h>
8710  
8711 +#define SYSFS_SUPER_MAGIC      0x62656572
8712 +
8713  struct kobject;
8714  struct module;
8715  enum kobj_ns_type;
8716 diff -NurpP --minimal linux-3.6.9/include/linux/time.h linux-3.6.9-vs2.3.4.4/include/linux/time.h
8717 --- linux-3.6.9/include/linux/time.h    2012-10-04 15:27:46.000000000 +0200
8718 +++ linux-3.6.9-vs2.3.4.4/include/linux/time.h  2012-10-04 18:47:00.000000000 +0200
8719 @@ -280,6 +280,8 @@ static __always_inline void timespec_add
8720         a->tv_nsec = ns;
8721  }
8722  
8723 +#include <linux/vs_time.h>
8724 +
8725  #endif /* __KERNEL__ */
8726  
8727  /*
8728 diff -NurpP --minimal linux-3.6.9/include/linux/types.h linux-3.6.9-vs2.3.4.4/include/linux/types.h
8729 --- linux-3.6.9/include/linux/types.h   2012-10-04 15:27:47.000000000 +0200
8730 +++ linux-3.6.9-vs2.3.4.4/include/linux/types.h 2012-10-04 18:47:00.000000000 +0200
8731 @@ -41,6 +41,9 @@ typedef __kernel_uid32_t      uid_t;
8732  typedef __kernel_gid32_t       gid_t;
8733  typedef __kernel_uid16_t        uid16_t;
8734  typedef __kernel_gid16_t        gid16_t;
8735 +typedef unsigned int           xid_t;
8736 +typedef unsigned int           nid_t;
8737 +typedef unsigned int           vs_tag_t;
8738  
8739  typedef unsigned long          uintptr_t;
8740  
8741 diff -NurpP --minimal linux-3.6.9/include/linux/utsname.h linux-3.6.9-vs2.3.4.4/include/linux/utsname.h
8742 --- linux-3.6.9/include/linux/utsname.h 2012-01-09 16:14:59.000000000 +0100
8743 +++ linux-3.6.9-vs2.3.4.4/include/linux/utsname.h       2012-10-04 18:47:00.000000000 +0200
8744 @@ -62,7 +62,8 @@ static inline void get_uts_ns(struct uts
8745  }
8746  
8747  extern struct uts_namespace *copy_utsname(unsigned long flags,
8748 -                                         struct task_struct *tsk);
8749 +                                         struct uts_namespace *old_ns,
8750 +                                         struct user_namespace *user_ns);
8751  extern void free_uts_ns(struct kref *kref);
8752  
8753  static inline void put_uts_ns(struct uts_namespace *ns)
8754 @@ -79,12 +80,13 @@ static inline void put_uts_ns(struct uts
8755  }
8756  
8757  static inline struct uts_namespace *copy_utsname(unsigned long flags,
8758 -                                                struct task_struct *tsk)
8759 +                                                struct uts_namespace *old_ns,
8760 +                                                struct user_namespace *user_ns)
8761  {
8762         if (flags & CLONE_NEWUTS)
8763                 return ERR_PTR(-EINVAL);
8764  
8765 -       return tsk->nsproxy->uts_ns;
8766 +       return old_ns;
8767  }
8768  #endif
8769  
8770 diff -NurpP --minimal linux-3.6.9/include/linux/vroot.h linux-3.6.9-vs2.3.4.4/include/linux/vroot.h
8771 --- linux-3.6.9/include/linux/vroot.h   1970-01-01 01:00:00.000000000 +0100
8772 +++ linux-3.6.9-vs2.3.4.4/include/linux/vroot.h 2012-10-04 18:47:00.000000000 +0200
8773 @@ -0,0 +1,51 @@
8774 +
8775 +/*
8776 + * include/linux/vroot.h
8777 + *
8778 + * written by Herbert Pötzl, 9/11/2002
8779 + * ported to 2.6 by Herbert Pötzl, 30/12/2004
8780 + *
8781 + * Copyright (C) 2002-2007 by Herbert Pötzl.
8782 + * Redistribution of this file is permitted under the
8783 + * GNU General Public License.
8784 + */
8785 +
8786 +#ifndef _LINUX_VROOT_H
8787 +#define _LINUX_VROOT_H
8788 +
8789 +
8790 +#ifdef __KERNEL__
8791 +
8792 +/* Possible states of device */
8793 +enum {
8794 +       Vr_unbound,
8795 +       Vr_bound,
8796 +};
8797 +
8798 +struct vroot_device {
8799 +       int             vr_number;
8800 +       int             vr_refcnt;
8801 +
8802 +       struct semaphore        vr_ctl_mutex;
8803 +       struct block_device    *vr_device;
8804 +       int                     vr_state;
8805 +};
8806 +
8807 +
8808 +typedef struct block_device *(vroot_grb_func)(struct block_device *);
8809 +
8810 +extern int register_vroot_grb(vroot_grb_func *);
8811 +extern int unregister_vroot_grb(vroot_grb_func *);
8812 +
8813 +#endif /* __KERNEL__ */
8814 +
8815 +#define MAX_VROOT_DEFAULT      8
8816 +
8817 +/*
8818 + * IOCTL commands --- we will commandeer 0x56 ('V')
8819 + */
8820 +
8821 +#define VROOT_SET_DEV          0x5600
8822 +#define VROOT_CLR_DEV          0x5601
8823 +
8824 +#endif /* _LINUX_VROOT_H */
8825 diff -NurpP --minimal linux-3.6.9/include/linux/vs_base.h linux-3.6.9-vs2.3.4.4/include/linux/vs_base.h
8826 --- linux-3.6.9/include/linux/vs_base.h 1970-01-01 01:00:00.000000000 +0100
8827 +++ linux-3.6.9-vs2.3.4.4/include/linux/vs_base.h       2012-10-04 18:47:00.000000000 +0200
8828 @@ -0,0 +1,10 @@
8829 +#ifndef _VS_BASE_H
8830 +#define _VS_BASE_H
8831 +
8832 +#include "vserver/base.h"
8833 +#include "vserver/check.h"
8834 +#include "vserver/debug.h"
8835 +
8836 +#else
8837 +#warning duplicate inclusion
8838 +#endif
8839 diff -NurpP --minimal linux-3.6.9/include/linux/vs_context.h linux-3.6.9-vs2.3.4.4/include/linux/vs_context.h
8840 --- linux-3.6.9/include/linux/vs_context.h      1970-01-01 01:00:00.000000000 +0100
8841 +++ linux-3.6.9-vs2.3.4.4/include/linux/vs_context.h    2012-10-04 18:47:00.000000000 +0200
8842 @@ -0,0 +1,242 @@
8843 +#ifndef _VS_CONTEXT_H
8844 +#define _VS_CONTEXT_H
8845 +
8846 +#include "vserver/base.h"
8847 +#include "vserver/check.h"
8848 +#include "vserver/context.h"
8849 +#include "vserver/history.h"
8850 +#include "vserver/debug.h"
8851 +
8852 +#include <linux/sched.h>
8853 +
8854 +
8855 +#define get_vx_info(i) __get_vx_info(i, __FILE__, __LINE__, __HERE__)
8856 +
8857 +static inline struct vx_info *__get_vx_info(struct vx_info *vxi,
8858 +       const char *_file, int _line, void *_here)
8859 +{
8860 +       if (!vxi)
8861 +               return NULL;
8862 +
8863 +       vxlprintk(VXD_CBIT(xid, 2), "get_vx_info(%p[#%d.%d])",
8864 +               vxi, vxi ? vxi->vx_id : 0,
8865 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
8866 +               _file, _line);
8867 +       __vxh_get_vx_info(vxi, _here);
8868 +
8869 +       atomic_inc(&vxi->vx_usecnt);
8870 +       return vxi;
8871 +}
8872 +
8873 +
8874 +extern void free_vx_info(struct vx_info *);
8875 +
8876 +#define put_vx_info(i) __put_vx_info(i, __FILE__, __LINE__, __HERE__)
8877 +
8878 +static inline void __put_vx_info(struct vx_info *vxi,
8879 +       const char *_file, int _line, void *_here)
8880 +{
8881 +       if (!vxi)
8882 +               return;
8883 +
8884 +       vxlprintk(VXD_CBIT(xid, 2), "put_vx_info(%p[#%d.%d])",
8885 +               vxi, vxi ? vxi->vx_id : 0,
8886 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
8887 +               _file, _line);
8888 +       __vxh_put_vx_info(vxi, _here);
8889 +
8890 +       if (atomic_dec_and_test(&vxi->vx_usecnt))
8891 +               free_vx_info(vxi);
8892 +}
8893 +
8894 +
8895 +#define init_vx_info(p, i) \
8896 +       __init_vx_info(p, i, __FILE__, __LINE__, __HERE__)
8897 +
8898 +static inline void __init_vx_info(struct vx_info **vxp, struct vx_info *vxi,
8899 +       const char *_file, int _line, void *_here)
8900 +{
8901 +       if (vxi) {
8902 +               vxlprintk(VXD_CBIT(xid, 3),
8903 +                       "init_vx_info(%p[#%d.%d])",
8904 +                       vxi, vxi ? vxi->vx_id : 0,
8905 +                       vxi ? atomic_read(&vxi->vx_usecnt) : 0,
8906 +                       _file, _line);
8907 +               __vxh_init_vx_info(vxi, vxp, _here);
8908 +
8909 +               atomic_inc(&vxi->vx_usecnt);
8910 +       }
8911 +       *vxp = vxi;
8912 +}
8913 +
8914 +
8915 +#define set_vx_info(p, i) \
8916 +       __set_vx_info(p, i, __FILE__, __LINE__, __HERE__)
8917 +
8918 +static inline void __set_vx_info(struct vx_info **vxp, struct vx_info *vxi,
8919 +       const char *_file, int _line, void *_here)
8920 +{
8921 +       struct vx_info *vxo;
8922 +
8923 +       if (!vxi)
8924 +               return;
8925 +
8926 +       vxlprintk(VXD_CBIT(xid, 3), "set_vx_info(%p[#%d.%d])",
8927 +               vxi, vxi ? vxi->vx_id : 0,
8928 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
8929 +               _file, _line);
8930 +       __vxh_set_vx_info(vxi, vxp, _here);
8931 +
8932 +       atomic_inc(&vxi->vx_usecnt);
8933 +       vxo = xchg(vxp, vxi);
8934 +       BUG_ON(vxo);
8935 +}
8936 +
8937 +
8938 +#define clr_vx_info(p) __clr_vx_info(p, __FILE__, __LINE__, __HERE__)
8939 +
8940 +static inline void __clr_vx_info(struct vx_info **vxp,
8941 +       const char *_file, int _line, void *_here)
8942 +{
8943 +       struct vx_info *vxo;
8944 +
8945 +       vxo = xchg(vxp, NULL);
8946 +       if (!vxo)
8947 +               return;
8948 +
8949 +       vxlprintk(VXD_CBIT(xid, 3), "clr_vx_info(%p[#%d.%d])",
8950 +               vxo, vxo ? vxo->vx_id : 0,
8951 +               vxo ? atomic_read(&vxo->vx_usecnt) : 0,
8952 +               _file, _line);
8953 +       __vxh_clr_vx_info(vxo, vxp, _here);
8954 +
8955 +       if (atomic_dec_and_test(&vxo->vx_usecnt))
8956 +               free_vx_info(vxo);
8957 +}
8958 +
8959 +
8960 +#define claim_vx_info(v, p) \
8961 +       __claim_vx_info(v, p, __FILE__, __LINE__, __HERE__)
8962 +
8963 +static inline void __claim_vx_info(struct vx_info *vxi,
8964 +       struct task_struct *task,
8965 +       const char *_file, int _line, void *_here)
8966 +{
8967 +       vxlprintk(VXD_CBIT(xid, 3), "claim_vx_info(%p[#%d.%d.%d]) %p",
8968 +               vxi, vxi ? vxi->vx_id : 0,
8969 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
8970 +               vxi ? atomic_read(&vxi->vx_tasks) : 0,
8971 +               task, _file, _line);
8972 +       __vxh_claim_vx_info(vxi, task, _here);
8973 +
8974 +       atomic_inc(&vxi->vx_tasks);
8975 +}
8976 +
8977 +
8978 +extern void unhash_vx_info(struct vx_info *);
8979 +
8980 +#define release_vx_info(v, p) \
8981 +       __release_vx_info(v, p, __FILE__, __LINE__, __HERE__)
8982 +
8983 +static inline void __release_vx_info(struct vx_info *vxi,
8984 +       struct task_struct *task,
8985 +       const char *_file, int _line, void *_here)
8986 +{
8987 +       vxlprintk(VXD_CBIT(xid, 3), "release_vx_info(%p[#%d.%d.%d]) %p",
8988 +               vxi, vxi ? vxi->vx_id : 0,
8989 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
8990 +               vxi ? atomic_read(&vxi->vx_tasks) : 0,
8991 +               task, _file, _line);
8992 +       __vxh_release_vx_info(vxi, task, _here);
8993 +
8994 +       might_sleep();
8995 +
8996 +       if (atomic_dec_and_test(&vxi->vx_tasks))
8997 +               unhash_vx_info(vxi);
8998 +}
8999 +
9000 +
9001 +#define task_get_vx_info(p) \
9002 +       __task_get_vx_info(p, __FILE__, __LINE__, __HERE__)
9003 +
9004 +static inline struct vx_info *__task_get_vx_info(struct task_struct *p,
9005 +       const char *_file, int _line, void *_here)
9006 +{
9007 +       struct vx_info *vxi;
9008 +
9009 +       task_lock(p);
9010 +       vxlprintk(VXD_CBIT(xid, 5), "task_get_vx_info(%p)",
9011 +               p, _file, _line);
9012 +       vxi = __get_vx_info(p->vx_info, _file, _line, _here);
9013 +       task_unlock(p);
9014 +       return vxi;
9015 +}
9016 +
9017 +
9018 +static inline void __wakeup_vx_info(struct vx_info *vxi)
9019 +{
9020 +       if (waitqueue_active(&vxi->vx_wait))
9021 +               wake_up_interruptible(&vxi->vx_wait);
9022 +}
9023 +
9024 +
9025 +#define enter_vx_info(v, s) __enter_vx_info(v, s, __FILE__, __LINE__)
9026 +
9027 +static inline void __enter_vx_info(struct vx_info *vxi,
9028 +       struct vx_info_save *vxis, const char *_file, int _line)
9029 +{
9030 +       vxlprintk(VXD_CBIT(xid, 5), "enter_vx_info(%p[#%d],%p) %p[#%d,%p]",
9031 +               vxi, vxi ? vxi->vx_id : 0, vxis, current,
9032 +               current->xid, current->vx_info, _file, _line);
9033 +       vxis->vxi = xchg(&current->vx_info, vxi);
9034 +       vxis->xid = current->xid;
9035 +       current->xid = vxi ? vxi->vx_id : 0;
9036 +}
9037 +
9038 +#define leave_vx_info(s) __leave_vx_info(s, __FILE__, __LINE__)
9039 +
9040 +static inline void __leave_vx_info(struct vx_info_save *vxis,
9041 +       const char *_file, int _line)
9042 +{
9043 +       vxlprintk(VXD_CBIT(xid, 5), "leave_vx_info(%p[#%d,%p]) %p[#%d,%p]",
9044 +               vxis, vxis->xid, vxis->vxi, current,
9045 +               current->xid, current->vx_info, _file, _line);
9046 +       (void)xchg(&current->vx_info, vxis->vxi);
9047 +       current->xid = vxis->xid;
9048 +}
9049 +
9050 +
9051 +static inline void __enter_vx_admin(struct vx_info_save *vxis)
9052 +{
9053 +       vxis->vxi = xchg(&current->vx_info, NULL);
9054 +       vxis->xid = xchg(&current->xid, (xid_t)0);
9055 +}
9056 +
9057 +static inline void __leave_vx_admin(struct vx_info_save *vxis)
9058 +{
9059 +       (void)xchg(&current->xid, vxis->xid);
9060 +       (void)xchg(&current->vx_info, vxis->vxi);
9061 +}
9062 +
9063 +#define task_is_init(p) \
9064 +       __task_is_init(p, __FILE__, __LINE__, __HERE__)
9065 +
9066 +static inline int __task_is_init(struct task_struct *p,
9067 +       const char *_file, int _line, void *_here)
9068 +{
9069 +       int is_init = is_global_init(p);
9070 +
9071 +       task_lock(p);
9072 +       if (p->vx_info)
9073 +               is_init = p->vx_info->vx_initpid == p->pid;
9074 +       task_unlock(p);
9075 +       return is_init;
9076 +}
9077 +
9078 +extern void exit_vx_info(struct task_struct *, int);
9079 +extern void exit_vx_info_early(struct task_struct *, int);
9080 +
9081 +
9082 +#else
9083 +#warning duplicate inclusion
9084 +#endif
9085 diff -NurpP --minimal linux-3.6.9/include/linux/vs_cowbl.h linux-3.6.9-vs2.3.4.4/include/linux/vs_cowbl.h
9086 --- linux-3.6.9/include/linux/vs_cowbl.h        1970-01-01 01:00:00.000000000 +0100
9087 +++ linux-3.6.9-vs2.3.4.4/include/linux/vs_cowbl.h      2012-10-04 18:47:00.000000000 +0200
9088 @@ -0,0 +1,48 @@
9089 +#ifndef _VS_COWBL_H
9090 +#define _VS_COWBL_H
9091 +
9092 +#include <linux/fs.h>
9093 +#include <linux/dcache.h>
9094 +#include <linux/namei.h>
9095 +#include <linux/slab.h>
9096 +
9097 +extern struct dentry *cow_break_link(const char *pathname);
9098 +
9099 +static inline int cow_check_and_break(struct path *path)
9100 +{
9101 +       struct inode *inode = path->dentry->d_inode;
9102 +       int error = 0;
9103 +
9104 +       /* do we need this check? */
9105 +       if (IS_RDONLY(inode))
9106 +               return -EROFS;
9107 +
9108 +       if (IS_COW(inode)) {
9109 +               if (IS_COW_LINK(inode)) {
9110 +                       struct dentry *new_dentry, *old_dentry = path->dentry;
9111 +                       char *pp, *buf;
9112 +
9113 +                       buf = kmalloc(PATH_MAX, GFP_KERNEL);
9114 +                       if (!buf) {
9115 +                               return -ENOMEM;
9116 +                       }
9117 +                       pp = d_path(path, buf, PATH_MAX);
9118 +                       new_dentry = cow_break_link(pp);
9119 +                       kfree(buf);
9120 +                       if (!IS_ERR(new_dentry)) {
9121 +                               path->dentry = new_dentry;
9122 +                               dput(old_dentry);
9123 +                       } else
9124 +                               error = PTR_ERR(new_dentry);
9125 +               } else {
9126 +                       inode->i_flags &= ~(S_IXUNLINK | S_IMMUTABLE);
9127 +                       inode->i_ctime = CURRENT_TIME;
9128 +                       mark_inode_dirty(inode);
9129 +               }
9130 +       }
9131 +       return error;
9132 +}
9133 +
9134 +#else
9135 +#warning duplicate inclusion
9136 +#endif
9137 diff -NurpP --minimal linux-3.6.9/include/linux/vs_cvirt.h linux-3.6.9-vs2.3.4.4/include/linux/vs_cvirt.h
9138 --- linux-3.6.9/include/linux/vs_cvirt.h        1970-01-01 01:00:00.000000000 +0100
9139 +++ linux-3.6.9-vs2.3.4.4/include/linux/vs_cvirt.h      2012-10-04 18:47:00.000000000 +0200
9140 @@ -0,0 +1,50 @@
9141 +#ifndef _VS_CVIRT_H
9142 +#define _VS_CVIRT_H
9143 +
9144 +#include "vserver/cvirt.h"
9145 +#include "vserver/context.h"
9146 +#include "vserver/base.h"
9147 +#include "vserver/check.h"
9148 +#include "vserver/debug.h"
9149 +
9150 +
9151 +static inline void vx_activate_task(struct task_struct *p)
9152 +{
9153 +       struct vx_info *vxi;
9154 +
9155 +       if ((vxi = p->vx_info)) {
9156 +               vx_update_load(vxi);
9157 +               atomic_inc(&vxi->cvirt.nr_running);
9158 +       }
9159 +}
9160 +
9161 +static inline void vx_deactivate_task(struct task_struct *p)
9162 +{
9163 +       struct vx_info *vxi;
9164 +
9165 +       if ((vxi = p->vx_info)) {
9166 +               vx_update_load(vxi);
9167 +               atomic_dec(&vxi->cvirt.nr_running);
9168 +       }
9169 +}
9170 +
9171 +static inline void vx_uninterruptible_inc(struct task_struct *p)
9172 +{
9173 +       struct vx_info *vxi;
9174 +
9175 +       if ((vxi = p->vx_info))
9176 +               atomic_inc(&vxi->cvirt.nr_uninterruptible);
9177 +}
9178 +
9179 +static inline void vx_uninterruptible_dec(struct task_struct *p)
9180 +{
9181 +       struct vx_info *vxi;
9182 +
9183 +       if ((vxi = p->vx_info))
9184 +               atomic_dec(&vxi->cvirt.nr_uninterruptible);
9185 +}
9186 +
9187 +
9188 +#else
9189 +#warning duplicate inclusion
9190 +#endif
9191 diff -NurpP --minimal linux-3.6.9/include/linux/vs_device.h linux-3.6.9-vs2.3.4.4/include/linux/vs_device.h
9192 --- linux-3.6.9/include/linux/vs_device.h       1970-01-01 01:00:00.000000000 +0100
9193 +++ linux-3.6.9-vs2.3.4.4/include/linux/vs_device.h     2012-10-04 18:47:00.000000000 +0200
9194 @@ -0,0 +1,45 @@
9195 +#ifndef _VS_DEVICE_H
9196 +#define _VS_DEVICE_H
9197 +
9198 +#include "vserver/base.h"
9199 +#include "vserver/device.h"
9200 +#include "vserver/debug.h"
9201 +
9202 +
9203 +#ifdef CONFIG_VSERVER_DEVICE
9204 +
9205 +int vs_map_device(struct vx_info *, dev_t, dev_t *, umode_t);
9206 +
9207 +#define vs_device_perm(v, d, m, p) \
9208 +       ((vs_map_device(current_vx_info(), d, NULL, m) & (p)) == (p))
9209 +
9210 +#else
9211 +
9212 +static inline
9213 +int vs_map_device(struct vx_info *vxi,
9214 +       dev_t device, dev_t *target, umode_t mode)
9215 +{
9216 +       if (target)
9217 +               *target = device;
9218 +       return ~0;
9219 +}
9220 +
9221 +#define vs_device_perm(v, d, m, p) ((p) == (p))
9222 +
9223 +#endif
9224 +
9225 +
9226 +#define vs_map_chrdev(d, t, p) \
9227 +       ((vs_map_device(current_vx_info(), d, t, S_IFCHR) & (p)) == (p))
9228 +#define vs_map_blkdev(d, t, p) \
9229 +       ((vs_map_device(current_vx_info(), d, t, S_IFBLK) & (p)) == (p))
9230 +
9231 +#define vs_chrdev_perm(d, p) \
9232 +       vs_device_perm(current_vx_info(), d, S_IFCHR, p)
9233 +#define vs_blkdev_perm(d, p) \
9234 +       vs_device_perm(current_vx_info(), d, S_IFBLK, p)
9235 +
9236 +
9237 +#else
9238 +#warning duplicate inclusion
9239 +#endif
9240 diff -NurpP --minimal linux-3.6.9/include/linux/vs_dlimit.h linux-3.6.9-vs2.3.4.4/include/linux/vs_dlimit.h
9241 --- linux-3.6.9/include/linux/vs_dlimit.h       1970-01-01 01:00:00.000000000 +0100
9242 +++ linux-3.6.9-vs2.3.4.4/include/linux/vs_dlimit.h     2012-10-04 18:47:00.000000000 +0200
9243 @@ -0,0 +1,215 @@
9244 +#ifndef _VS_DLIMIT_H
9245 +#define _VS_DLIMIT_H
9246 +
9247 +#include <linux/fs.h>
9248 +
9249 +#include "vserver/dlimit.h"
9250 +#include "vserver/base.h"
9251 +#include "vserver/debug.h"
9252 +
9253 +
9254 +#define get_dl_info(i) __get_dl_info(i, __FILE__, __LINE__)
9255 +
9256 +static inline struct dl_info *__get_dl_info(struct dl_info *dli,
9257 +       const char *_file, int _line)
9258 +{
9259 +       if (!dli)
9260 +               return NULL;
9261 +       vxlprintk(VXD_CBIT(dlim, 4), "get_dl_info(%p[#%d.%d])",
9262 +               dli, dli ? dli->dl_tag : 0,
9263 +               dli ? atomic_read(&dli->dl_usecnt) : 0,
9264 +               _file, _line);
9265 +       atomic_inc(&dli->dl_usecnt);
9266 +       return dli;
9267 +}
9268 +
9269 +
9270 +#define free_dl_info(i) \
9271 +       call_rcu(&(i)->dl_rcu, rcu_free_dl_info)
9272 +
9273 +#define put_dl_info(i) __put_dl_info(i, __FILE__, __LINE__)
9274 +
9275 +static inline void __put_dl_info(struct dl_info *dli,
9276 +       const char *_file, int _line)
9277 +{
9278 +       if (!dli)
9279 +               return;
9280 +       vxlprintk(VXD_CBIT(dlim, 4), "put_dl_info(%p[#%d.%d])",
9281 +               dli, dli ? dli->dl_tag : 0,
9282 +               dli ? atomic_read(&dli->dl_usecnt) : 0,
9283 +               _file, _line);
9284 +       if (atomic_dec_and_test(&dli->dl_usecnt))
9285 +               free_dl_info(dli);
9286 +}
9287 +
9288 +
9289 +#define __dlimit_char(d)       ((d) ? '*' : ' ')
9290 +
9291 +static inline int __dl_alloc_space(struct super_block *sb,
9292 +       vs_tag_t tag, dlsize_t nr, const char *file, int line)
9293 +{
9294 +       struct dl_info *dli = NULL;
9295 +       int ret = 0;
9296 +
9297 +       if (nr == 0)
9298 +               goto out;
9299 +       dli = locate_dl_info(sb, tag);
9300 +       if (!dli)
9301 +               goto out;
9302 +
9303 +       spin_lock(&dli->dl_lock);
9304 +       ret = (dli->dl_space_used + nr > dli->dl_space_total);
9305 +       if (!ret)
9306 +               dli->dl_space_used += nr;
9307 +       spin_unlock(&dli->dl_lock);
9308 +       put_dl_info(dli);
9309 +out:
9310 +       vxlprintk(VXD_CBIT(dlim, 1),
9311 +               "ALLOC (%p,#%d)%c %lld bytes (%d)",
9312 +               sb, tag, __dlimit_char(dli), (long long)nr,
9313 +               ret, file, line);
9314 +       return ret ? -ENOSPC : 0;
9315 +}
9316 +
9317 +static inline void __dl_free_space(struct super_block *sb,
9318 +       vs_tag_t tag, dlsize_t nr, const char *_file, int _line)
9319 +{
9320 +       struct dl_info *dli = NULL;
9321 +
9322 +       if (nr == 0)
9323 +               goto out;
9324 +       dli = locate_dl_info(sb, tag);
9325 +       if (!dli)
9326 +               goto out;
9327 +
9328 +       spin_lock(&dli->dl_lock);
9329 +       if (dli->dl_space_used > nr)
9330 +               dli->dl_space_used -= nr;
9331 +       else
9332 +               dli->dl_space_used = 0;
9333 +       spin_unlock(&dli->dl_lock);
9334 +       put_dl_info(dli);
9335 +out:
9336 +       vxlprintk(VXD_CBIT(dlim, 1),
9337 +               "FREE  (%p,#%d)%c %lld bytes",
9338 +               sb, tag, __dlimit_char(dli), (long long)nr,
9339 +               _file, _line);
9340 +}
9341 +
9342 +static inline int __dl_alloc_inode(struct super_block *sb,
9343 +       vs_tag_t tag, const char *_file, int _line)
9344 +{
9345 +       struct dl_info *dli;
9346 +       int ret = 0;
9347 +
9348 +       dli = locate_dl_info(sb, tag);
9349 +       if (!dli)
9350 +               goto out;
9351 +
9352 +       spin_lock(&dli->dl_lock);
9353 +       dli->dl_inodes_used++;
9354 +       ret = (dli->dl_inodes_used > dli->dl_inodes_total);
9355 +       spin_unlock(&dli->dl_lock);
9356 +       put_dl_info(dli);
9357 +out:
9358 +       vxlprintk(VXD_CBIT(dlim, 0),
9359 +               "ALLOC (%p,#%d)%c inode (%d)",
9360 +               sb, tag, __dlimit_char(dli), ret, _file, _line);
9361 +       return ret ? -ENOSPC : 0;
9362 +}
9363 +
9364 +static inline void __dl_free_inode(struct super_block *sb,
9365 +       vs_tag_t tag, const char *_file, int _line)
9366 +{
9367 +       struct dl_info *dli;
9368 +
9369 +       dli = locate_dl_info(sb, tag);
9370 +       if (!dli)
9371 +               goto out;
9372 +
9373 +       spin_lock(&dli->dl_lock);
9374 +       if (dli->dl_inodes_used > 1)
9375 +               dli->dl_inodes_used--;
9376 +       else
9377 +               dli->dl_inodes_used = 0;
9378 +       spin_unlock(&dli->dl_lock);
9379 +       put_dl_info(dli);
9380 +out:
9381 +       vxlprintk(VXD_CBIT(dlim, 0),
9382 +               "FREE  (%p,#%d)%c inode",
9383 +               sb, tag, __dlimit_char(dli), _file, _line);
9384 +}
9385 +
9386 +static inline void __dl_adjust_block(struct super_block *sb, vs_tag_t tag,
9387 +       unsigned long long *free_blocks, unsigned long long *root_blocks,
9388 +       const char *_file, int _line)
9389 +{
9390 +       struct dl_info *dli;
9391 +       uint64_t broot, bfree;
9392 +
9393 +       dli = locate_dl_info(sb, tag);
9394 +       if (!dli)
9395 +               return;
9396 +
9397 +       spin_lock(&dli->dl_lock);
9398 +       broot = (dli->dl_space_total -
9399 +               (dli->dl_space_total >> 10) * dli->dl_nrlmult)
9400 +               >> sb->s_blocksize_bits;
9401 +       bfree = (dli->dl_space_total - dli->dl_space_used)
9402 +                       >> sb->s_blocksize_bits;
9403 +       spin_unlock(&dli->dl_lock);
9404 +
9405 +       vxlprintk(VXD_CBIT(dlim, 2),
9406 +               "ADJUST: %lld,%lld on %lld,%lld [mult=%d]",
9407 +               (long long)bfree, (long long)broot,
9408 +               *free_blocks, *root_blocks, dli->dl_nrlmult,
9409 +               _file, _line);
9410 +       if (free_blocks) {
9411 +               if (*free_blocks > bfree)
9412 +                       *free_blocks = bfree;
9413 +       }
9414 +       if (root_blocks) {
9415 +               if (*root_blocks > broot)
9416 +                       *root_blocks = broot;
9417 +       }
9418 +       put_dl_info(dli);
9419 +}
9420 +
9421 +#define dl_prealloc_space(in, bytes) \
9422 +       __dl_alloc_space((in)->i_sb, (in)->i_tag, (dlsize_t)(bytes), \
9423 +               __FILE__, __LINE__ )
9424 +
9425 +#define dl_alloc_space(in, bytes) \
9426 +       __dl_alloc_space((in)->i_sb, (in)->i_tag, (dlsize_t)(bytes), \
9427 +               __FILE__, __LINE__ )
9428 +
9429 +#define dl_reserve_space(in, bytes) \
9430 +       __dl_alloc_space((in)->i_sb, (in)->i_tag, (dlsize_t)(bytes), \
9431 +               __FILE__, __LINE__ )
9432 +
9433 +#define dl_claim_space(in, bytes) (0)
9434 +
9435 +#define dl_release_space(in, bytes) \
9436 +       __dl_free_space((in)->i_sb, (in)->i_tag, (dlsize_t)(bytes), \
9437 +               __FILE__, __LINE__ )
9438 +
9439 +#define dl_free_space(in, bytes) \
9440 +       __dl_free_space((in)->i_sb, (in)->i_tag, (dlsize_t)(bytes), \
9441 +               __FILE__, __LINE__ )
9442 +
9443 +
9444 +
9445 +#define dl_alloc_inode(in) \
9446 +       __dl_alloc_inode((in)->i_sb, (in)->i_tag, __FILE__, __LINE__ )
9447 +
9448 +#define dl_free_inode(in) \
9449 +       __dl_free_inode((in)->i_sb, (in)->i_tag, __FILE__, __LINE__ )
9450 +
9451 +
9452 +#define dl_adjust_block(sb, tag, fb, rb) \
9453 +       __dl_adjust_block(sb, tag, fb, rb, __FILE__, __LINE__ )
9454 +
9455 +
9456 +#else
9457 +#warning duplicate inclusion
9458 +#endif
9459 diff -NurpP --minimal linux-3.6.9/include/linux/vs_inet.h linux-3.6.9-vs2.3.4.4/include/linux/vs_inet.h
9460 --- linux-3.6.9/include/linux/vs_inet.h 1970-01-01 01:00:00.000000000 +0100
9461 +++ linux-3.6.9-vs2.3.4.4/include/linux/vs_inet.h       2012-10-04 18:47:00.000000000 +0200
9462 @@ -0,0 +1,353 @@
9463 +#ifndef _VS_INET_H
9464 +#define _VS_INET_H
9465 +
9466 +#include "vserver/base.h"
9467 +#include "vserver/network.h"
9468 +#include "vserver/debug.h"
9469 +
9470 +#define IPI_LOOPBACK   htonl(INADDR_LOOPBACK)
9471 +
9472 +#define NXAV4(a)       NIPQUAD((a)->ip[0]), NIPQUAD((a)->ip[1]), \
9473 +                       NIPQUAD((a)->mask), (a)->type
9474 +#define NXAV4_FMT      "[" NIPQUAD_FMT "-" NIPQUAD_FMT "/" NIPQUAD_FMT ":%04x]"
9475 +
9476 +#define NIPQUAD(addr) \
9477 +       ((unsigned char *)&addr)[0], \
9478 +       ((unsigned char *)&addr)[1], \
9479 +       ((unsigned char *)&addr)[2], \
9480 +       ((unsigned char *)&addr)[3]
9481 +
9482 +#define NIPQUAD_FMT "%u.%u.%u.%u"
9483 +
9484 +
9485 +static inline
9486 +int v4_addr_match(struct nx_addr_v4 *nxa, __be32 addr, uint16_t tmask)
9487 +{
9488 +       __be32 ip = nxa->ip[0].s_addr;
9489 +       __be32 mask = nxa->mask.s_addr;
9490 +       __be32 bcast = ip | ~mask;
9491 +       int ret = 0;
9492 +
9493 +       switch (nxa->type & tmask) {
9494 +       case NXA_TYPE_MASK:
9495 +               ret = (ip == (addr & mask));
9496 +               break;
9497 +       case NXA_TYPE_ADDR:
9498 +               ret = 3;
9499 +               if (addr == ip)
9500 +                       break;
9501 +               /* fall through to broadcast */
9502 +       case NXA_MOD_BCAST:
9503 +               ret = ((tmask & NXA_MOD_BCAST) && (addr == bcast));
9504 +               break;
9505 +       case NXA_TYPE_RANGE:
9506 +               ret = ((nxa->ip[0].s_addr <= addr) &&
9507 +                       (nxa->ip[1].s_addr > addr));
9508 +               break;
9509 +       case NXA_TYPE_ANY:
9510 +               ret = 2;
9511 +               break;
9512 +       }
9513 +
9514 +       vxdprintk(VXD_CBIT(net, 0),
9515 +               "v4_addr_match(%p" NXAV4_FMT "," NIPQUAD_FMT ",%04x) = %d",
9516 +               nxa, NXAV4(nxa), NIPQUAD(addr), tmask, ret);
9517 +       return ret;
9518 +}
9519 +
9520 +static inline
9521 +int v4_addr_in_nx_info(struct nx_info *nxi, __be32 addr, uint16_t tmask)
9522 +{
9523 +       struct nx_addr_v4 *nxa;
9524 +       int ret = 1;
9525 +
9526 +       if (!nxi)
9527 +               goto out;
9528 +
9529 +       ret = 2;
9530 +       /* allow 127.0.0.1 when remapping lback */
9531 +       if ((tmask & NXA_LOOPBACK) &&
9532 +               (addr == IPI_LOOPBACK) &&
9533 +               nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
9534 +               goto out;
9535 +       ret = 3;
9536 +       /* check for lback address */
9537 +       if ((tmask & NXA_MOD_LBACK) &&
9538 +               (nxi->v4_lback.s_addr == addr))
9539 +               goto out;
9540 +       ret = 4;
9541 +       /* check for broadcast address */
9542 +       if ((tmask & NXA_MOD_BCAST) &&
9543 +               (nxi->v4_bcast.s_addr == addr))
9544 +               goto out;
9545 +       ret = 5;
9546 +       /* check for v4 addresses */
9547 +       for (nxa = &nxi->v4; nxa; nxa = nxa->next)
9548 +               if (v4_addr_match(nxa, addr, tmask))
9549 +                       goto out;
9550 +       ret = 0;
9551 +out:
9552 +       vxdprintk(VXD_CBIT(net, 0),
9553 +               "v4_addr_in_nx_info(%p[#%u]," NIPQUAD_FMT ",%04x) = %d",
9554 +               nxi, nxi ? nxi->nx_id : 0, NIPQUAD(addr), tmask, ret);
9555 +       return ret;
9556 +}
9557 +
9558 +static inline
9559 +int v4_nx_addr_match(struct nx_addr_v4 *nxa, struct nx_addr_v4 *addr, uint16_t mask)
9560 +{
9561 +       /* FIXME: needs full range checks */
9562 +       return v4_addr_match(nxa, addr->ip[0].s_addr, mask);
9563 +}
9564 +
9565 +static inline
9566 +int v4_nx_addr_in_nx_info(struct nx_info *nxi, struct nx_addr_v4 *nxa, uint16_t mask)
9567 +{
9568 +       struct nx_addr_v4 *ptr;
9569 +
9570 +       for (ptr = &nxi->v4; ptr; ptr = ptr->next)
9571 +               if (v4_nx_addr_match(ptr, nxa, mask))
9572 +                       return 1;
9573 +       return 0;
9574 +}
9575 +
9576 +#include <net/inet_sock.h>
9577 +
9578 +/*
9579 + *     Check if a given address matches for a socket
9580 + *
9581 + *     nxi:            the socket's nx_info if any
9582 + *     addr:           to be verified address
9583 + */
9584 +static inline
9585 +int v4_sock_addr_match (
9586 +       struct nx_info *nxi,
9587 +       struct inet_sock *inet,
9588 +       __be32 addr)
9589 +{
9590 +       __be32 saddr = inet->inet_rcv_saddr;
9591 +       __be32 bcast = nxi ? nxi->v4_bcast.s_addr : INADDR_BROADCAST;
9592 +
9593 +       if (addr && (saddr == addr || bcast == addr))
9594 +               return 1;
9595 +       if (!saddr)
9596 +               return v4_addr_in_nx_info(nxi, addr, NXA_MASK_BIND);
9597 +       return 0;
9598 +}
9599 +
9600 +
9601 +/* inet related checks and helpers */
9602 +
9603 +
9604 +struct in_ifaddr;
9605 +struct net_device;
9606 +struct sock;
9607 +
9608 +#ifdef CONFIG_INET
9609 +
9610 +#include <linux/netdevice.h>
9611 +#include <linux/inetdevice.h>
9612 +#include <net/inet_sock.h>
9613 +#include <net/inet_timewait_sock.h>
9614 +
9615 +
9616 +int dev_in_nx_info(struct net_device *, struct nx_info *);
9617 +int v4_dev_in_nx_info(struct net_device *, struct nx_info *);
9618 +int nx_v4_addr_conflict(struct nx_info *, struct nx_info *);
9619 +
9620 +
9621 +/*
9622 + *     check if address is covered by socket
9623 + *
9624 + *     sk:     the socket to check against
9625 + *     addr:   the address in question (must be != 0)
9626 + */
9627 +
9628 +static inline
9629 +int __v4_addr_match_socket(const struct sock *sk, struct nx_addr_v4 *nxa)
9630 +{
9631 +       struct nx_info *nxi = sk->sk_nx_info;
9632 +       __be32 saddr = sk_rcv_saddr(sk);
9633 +
9634 +       vxdprintk(VXD_CBIT(net, 5),
9635 +               "__v4_addr_in_socket(%p," NXAV4_FMT ") %p:" NIPQUAD_FMT " %p;%lx",
9636 +               sk, NXAV4(nxa), nxi, NIPQUAD(saddr), sk->sk_socket,
9637 +               (sk->sk_socket?sk->sk_socket->flags:0));
9638 +
9639 +       if (saddr) {            /* direct address match */
9640 +               return v4_addr_match(nxa, saddr, -1);
9641 +       } else if (nxi) {       /* match against nx_info */
9642 +               return v4_nx_addr_in_nx_info(nxi, nxa, -1);
9643 +       } else {                /* unrestricted any socket */
9644 +               return 1;
9645 +       }
9646 +}
9647 +
9648 +
9649 +
9650 +static inline
9651 +int nx_dev_visible(struct nx_info *nxi, struct net_device *dev)
9652 +{
9653 +       vxdprintk(VXD_CBIT(net, 1),
9654 +               "nx_dev_visible(%p[#%u],%p " VS_Q("%s") ") %d",
9655 +               nxi, nxi ? nxi->nx_id : 0, dev, dev->name,
9656 +               nxi ? dev_in_nx_info(dev, nxi) : 0);
9657 +
9658 +       if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
9659 +               return 1;
9660 +       if (dev_in_nx_info(dev, nxi))
9661 +               return 1;
9662 +       return 0;
9663 +}
9664 +
9665 +
9666 +static inline
9667 +int v4_ifa_in_nx_info(struct in_ifaddr *ifa, struct nx_info *nxi)
9668 +{
9669 +       if (!nxi)
9670 +               return 1;
9671 +       if (!ifa)
9672 +               return 0;
9673 +       return v4_addr_in_nx_info(nxi, ifa->ifa_local, NXA_MASK_SHOW);
9674 +}
9675 +
9676 +static inline
9677 +int nx_v4_ifa_visible(struct nx_info *nxi, struct in_ifaddr *ifa)
9678 +{
9679 +       vxdprintk(VXD_CBIT(net, 1), "nx_v4_ifa_visible(%p[#%u],%p) %d",
9680 +               nxi, nxi ? nxi->nx_id : 0, ifa,
9681 +               nxi ? v4_ifa_in_nx_info(ifa, nxi) : 0);
9682 +
9683 +       if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
9684 +               return 1;
9685 +       if (v4_ifa_in_nx_info(ifa, nxi))
9686 +               return 1;
9687 +       return 0;
9688 +}
9689 +
9690 +
9691 +struct nx_v4_sock_addr {
9692 +       __be32 saddr;   /* Address used for validation */
9693 +       __be32 baddr;   /* Address used for socket bind */
9694 +};
9695 +
9696 +static inline
9697 +int v4_map_sock_addr(struct inet_sock *inet, struct sockaddr_in *addr,
9698 +       struct nx_v4_sock_addr *nsa)
9699 +{
9700 +       struct sock *sk = &inet->sk;
9701 +       struct nx_info *nxi = sk->sk_nx_info;
9702 +       __be32 saddr = addr->sin_addr.s_addr;
9703 +       __be32 baddr = saddr;
9704 +
9705 +       vxdprintk(VXD_CBIT(net, 3),
9706 +               "inet_bind(%p)* %p,%p;%lx " NIPQUAD_FMT,
9707 +               sk, sk->sk_nx_info, sk->sk_socket,
9708 +               (sk->sk_socket ? sk->sk_socket->flags : 0),
9709 +               NIPQUAD(saddr));
9710 +
9711 +       if (nxi) {
9712 +               if (saddr == INADDR_ANY) {
9713 +                       if (nx_info_flags(nxi, NXF_SINGLE_IP, 0))
9714 +                               baddr = nxi->v4.ip[0].s_addr;
9715 +               } else if (saddr == IPI_LOOPBACK) {
9716 +                       if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
9717 +                               baddr = nxi->v4_lback.s_addr;
9718 +               } else if (!ipv4_is_multicast(saddr) ||
9719 +                       !nx_info_ncaps(nxi, NXC_MULTICAST)) {
9720 +                       /* normal address bind */
9721 +                       if (!v4_addr_in_nx_info(nxi, saddr, NXA_MASK_BIND))
9722 +                               return -EADDRNOTAVAIL;
9723 +               }
9724 +       }
9725 +
9726 +       vxdprintk(VXD_CBIT(net, 3),
9727 +               "inet_bind(%p) " NIPQUAD_FMT ", " NIPQUAD_FMT,
9728 +               sk, NIPQUAD(saddr), NIPQUAD(baddr));
9729 +
9730 +       nsa->saddr = saddr;
9731 +       nsa->baddr = baddr;
9732 +       return 0;
9733 +}
9734 +
9735 +static inline
9736 +void v4_set_sock_addr(struct inet_sock *inet, struct nx_v4_sock_addr *nsa)
9737 +{
9738 +       inet->inet_saddr = nsa->baddr;
9739 +       inet->inet_rcv_saddr = nsa->baddr;
9740 +}
9741 +
9742 +
9743 +/*
9744 + *      helper to simplify inet_lookup_listener
9745 + *
9746 + *      nxi:   the socket's nx_info if any
9747 + *      addr:  to be verified address
9748 + *      saddr: socket address
9749 + */
9750 +static inline int v4_inet_addr_match (
9751 +       struct nx_info *nxi,
9752 +       __be32 addr,
9753 +       __be32 saddr)
9754 +{
9755 +       if (addr && (saddr == addr))
9756 +               return 1;
9757 +       if (!saddr)
9758 +               return nxi ? v4_addr_in_nx_info(nxi, addr, NXA_MASK_BIND) : 1;
9759 +       return 0;
9760 +}
9761 +
9762 +static inline __be32 nx_map_sock_lback(struct nx_info *nxi, __be32 addr)
9763 +{
9764 +       if (nx_info_flags(nxi, NXF_HIDE_LBACK, 0) &&
9765 +               (addr == nxi->v4_lback.s_addr))
9766 +               return IPI_LOOPBACK;
9767 +       return addr;
9768 +}
9769 +
9770 +static inline
9771 +int nx_info_has_v4(struct nx_info *nxi)
9772 +{
9773 +       if (!nxi)
9774 +               return 1;
9775 +       if (NX_IPV4(nxi))
9776 +               return 1;
9777 +       if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
9778 +               return 1;
9779 +       return 0;
9780 +}
9781 +
9782 +#else /* CONFIG_INET */
9783 +
9784 +static inline
9785 +int nx_dev_visible(struct nx_info *n, struct net_device *d)
9786 +{
9787 +       return 1;
9788 +}
9789 +
9790 +static inline
9791 +int nx_v4_addr_conflict(struct nx_info *n, uint32_t a, const struct sock *s)
9792 +{
9793 +       return 1;
9794 +}
9795 +
9796 +static inline
9797 +int v4_ifa_in_nx_info(struct in_ifaddr *a, struct nx_info *n)
9798 +{
9799 +       return 1;
9800 +}
9801 +
9802 +static inline
9803 +int nx_info_has_v4(struct nx_info *nxi)
9804 +{
9805 +       return 0;
9806 +}
9807 +
9808 +#endif /* CONFIG_INET */
9809 +
9810 +#define current_nx_info_has_v4() \
9811 +       nx_info_has_v4(current_nx_info())
9812 +
9813 +#else
9814 +// #warning duplicate inclusion
9815 +#endif
9816 diff -NurpP --minimal linux-3.6.9/include/linux/vs_inet6.h linux-3.6.9-vs2.3.4.4/include/linux/vs_inet6.h
9817 --- linux-3.6.9/include/linux/vs_inet6.h        1970-01-01 01:00:00.000000000 +0100
9818 +++ linux-3.6.9-vs2.3.4.4/include/linux/vs_inet6.h      2012-10-04 18:47:00.000000000 +0200
9819 @@ -0,0 +1,246 @@
9820 +#ifndef _VS_INET6_H
9821 +#define _VS_INET6_H
9822 +
9823 +#include "vserver/base.h"
9824 +#include "vserver/network.h"
9825 +#include "vserver/debug.h"
9826 +
9827 +#include <net/ipv6.h>
9828 +
9829 +#define NXAV6(a)       &(a)->ip, &(a)->mask, (a)->prefix, (a)->type
9830 +#define NXAV6_FMT      "[%pI6/%pI6/%d:%04x]"
9831 +
9832 +
9833 +#ifdef CONFIG_IPV6
9834 +
9835 +static inline
9836 +int v6_addr_match(struct nx_addr_v6 *nxa,
9837 +       const struct in6_addr *addr, uint16_t mask)
9838 +{
9839 +       int ret = 0;
9840 +
9841 +       switch (nxa->type & mask) {
9842 +       case NXA_TYPE_MASK:
9843 +               ret = ipv6_masked_addr_cmp(&nxa->ip, &nxa->mask, addr);
9844 +               break;
9845 +       case NXA_TYPE_ADDR:
9846 +               ret = ipv6_addr_equal(&nxa->ip, addr);
9847 +               break;
9848 +       case NXA_TYPE_ANY:
9849 +               ret = 1;
9850 +               break;
9851 +       }
9852 +       vxdprintk(VXD_CBIT(net, 0),
9853 +               "v6_addr_match(%p" NXAV6_FMT ",%pI6,%04x) = %d",
9854 +               nxa, NXAV6(nxa), addr, mask, ret);
9855 +       return ret;
9856 +}
9857 +
9858 +static inline
9859 +int v6_addr_in_nx_info(struct nx_info *nxi,
9860 +       const struct in6_addr *addr, uint16_t mask)
9861 +{
9862 +       struct nx_addr_v6 *nxa;
9863 +       int ret = 1;
9864 +
9865 +       if (!nxi)
9866 +               goto out;
9867 +       for (nxa = &nxi->v6; nxa; nxa = nxa->next)
9868 +               if (v6_addr_match(nxa, addr, mask))
9869 +                       goto out;
9870 +       ret = 0;
9871 +out:
9872 +       vxdprintk(VXD_CBIT(net, 0),
9873 +               "v6_addr_in_nx_info(%p[#%u],%pI6,%04x) = %d",
9874 +               nxi, nxi ? nxi->nx_id : 0, addr, mask, ret);
9875 +       return ret;
9876 +}
9877 +
9878 +static inline
9879 +int v6_nx_addr_match(struct nx_addr_v6 *nxa, struct nx_addr_v6 *addr, uint16_t mask)
9880 +{
9881 +       /* FIXME: needs full range checks */
9882 +       return v6_addr_match(nxa, &addr->ip, mask);
9883 +}
9884 +
9885 +static inline
9886 +int v6_nx_addr_in_nx_info(struct nx_info *nxi, struct nx_addr_v6 *nxa, uint16_t mask)
9887 +{
9888 +       struct nx_addr_v6 *ptr;
9889 +
9890 +       for (ptr = &nxi->v6; ptr; ptr = ptr->next)
9891 +               if (v6_nx_addr_match(ptr, nxa, mask))
9892 +                       return 1;
9893 +       return 0;
9894 +}
9895 +
9896 +
9897 +/*
9898 + *     Check if a given address matches for a socket
9899 + *
9900 + *     nxi:            the socket's nx_info if any
9901 + *     addr:           to be verified address
9902 + */
9903 +static inline
9904 +int v6_sock_addr_match (
9905 +       struct nx_info *nxi,
9906 +       struct inet_sock *inet,
9907 +       struct in6_addr *addr)
9908 +{
9909 +       struct sock *sk = &inet->sk;
9910 +       struct in6_addr *saddr = inet6_rcv_saddr(sk);
9911 +
9912 +       if (!ipv6_addr_any(addr) &&
9913 +               ipv6_addr_equal(saddr, addr))
9914 +               return 1;
9915 +       if (ipv6_addr_any(saddr))
9916 +               return v6_addr_in_nx_info(nxi, addr, -1);
9917 +       return 0;
9918 +}
9919 +
9920 +/*
9921 + *     check if address is covered by socket
9922 + *
9923 + *     sk:     the socket to check against
9924 + *     addr:   the address in question (must be != 0)
9925 + */
9926 +
9927 +static inline
9928 +int __v6_addr_match_socket(const struct sock *sk, struct nx_addr_v6 *nxa)
9929 +{
9930 +       struct nx_info *nxi = sk->sk_nx_info;
9931 +       struct in6_addr *saddr = inet6_rcv_saddr(sk);
9932 +
9933 +       vxdprintk(VXD_CBIT(net, 5),
9934 +               "__v6_addr_in_socket(%p," NXAV6_FMT ") %p:%pI6 %p;%lx",
9935 +               sk, NXAV6(nxa), nxi, saddr, sk->sk_socket,
9936 +               (sk->sk_socket?sk->sk_socket->flags:0));
9937 +
9938 +       if (!ipv6_addr_any(saddr)) {    /* direct address match */
9939 +               return v6_addr_match(nxa, saddr, -1);
9940 +       } else if (nxi) {               /* match against nx_info */
9941 +               return v6_nx_addr_in_nx_info(nxi, nxa, -1);
9942 +       } else {                        /* unrestricted any socket */
9943 +               return 1;
9944 +       }
9945 +}
9946 +
9947 +
9948 +/* inet related checks and helpers */
9949 +
9950 +
9951 +struct in_ifaddr;
9952 +struct net_device;
9953 +struct sock;
9954 +
9955 +
9956 +#include <linux/netdevice.h>
9957 +#include <linux/inetdevice.h>
9958 +#include <net/inet_timewait_sock.h>
9959 +
9960 +
9961 +int dev_in_nx_info(struct net_device *, struct nx_info *);
9962 +int v6_dev_in_nx_info(struct net_device *, struct nx_info *);
9963 +int nx_v6_addr_conflict(struct nx_info *, struct nx_info *);
9964 +
9965 +
9966 +
9967 +static inline
9968 +int v6_ifa_in_nx_info(struct inet6_ifaddr *ifa, struct nx_info *nxi)
9969 +{
9970 +       if (!nxi)
9971 +               return 1;
9972 +       if (!ifa)
9973 +               return 0;
9974 +       return v6_addr_in_nx_info(nxi, &ifa->addr, -1);
9975 +}
9976 +
9977 +static inline
9978 +int nx_v6_ifa_visible(struct nx_info *nxi, struct inet6_ifaddr *ifa)
9979 +{
9980 +       vxdprintk(VXD_CBIT(net, 1), "nx_v6_ifa_visible(%p[#%u],%p) %d",
9981 +               nxi, nxi ? nxi->nx_id : 0, ifa,
9982 +               nxi ? v6_ifa_in_nx_info(ifa, nxi) : 0);
9983 +
9984 +       if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
9985 +               return 1;
9986 +       if (v6_ifa_in_nx_info(ifa, nxi))
9987 +               return 1;
9988 +       return 0;
9989 +}
9990 +
9991 +
9992 +struct nx_v6_sock_addr {
9993 +       struct in6_addr saddr;  /* Address used for validation */
9994 +       struct in6_addr baddr;  /* Address used for socket bind */
9995 +};
9996 +
9997 +static inline
9998 +int v6_map_sock_addr(struct inet_sock *inet, struct sockaddr_in6 *addr,
9999 +       struct nx_v6_sock_addr *nsa)
10000 +{
10001 +       // struct sock *sk = &inet->sk;
10002 +       // struct nx_info *nxi = sk->sk_nx_info;
10003 +       struct in6_addr saddr = addr->sin6_addr;
10004 +       struct in6_addr baddr = saddr;
10005 +
10006 +       nsa->saddr = saddr;
10007 +       nsa->baddr = baddr;
10008 +       return 0;
10009 +}
10010 +
10011 +static inline
10012 +void v6_set_sock_addr(struct inet_sock *inet, struct nx_v6_sock_addr *nsa)
10013 +{
10014 +       // struct sock *sk = &inet->sk;
10015 +       // struct in6_addr *saddr = inet6_rcv_saddr(sk);
10016 +
10017 +       // *saddr = nsa->baddr;
10018 +       // inet->inet_saddr = nsa->baddr;
10019 +}
10020 +
10021 +static inline
10022 +int nx_info_has_v6(struct nx_info *nxi)
10023 +{
10024 +       if (!nxi)
10025 +               return 1;
10026 +       if (NX_IPV6(nxi))
10027 +               return 1;
10028 +       return 0;
10029 +}
10030 +
10031 +#else /* CONFIG_IPV6 */
10032 +
10033 +static inline
10034 +int nx_v6_dev_visible(struct nx_info *n, struct net_device *d)
10035 +{
10036 +       return 1;
10037 +}
10038 +
10039 +
10040 +static inline
10041 +int nx_v6_addr_conflict(struct nx_info *n, uint32_t a, const struct sock *s)
10042 +{
10043 +       return 1;
10044 +}
10045 +
10046 +static inline
10047 +int v6_ifa_in_nx_info(struct in_ifaddr *a, struct nx_info *n)
10048 +{
10049 +       return 1;
10050 +}
10051 +
10052 +static inline
10053 +int nx_info_has_v6(struct nx_info *nxi)
10054 +{
10055 +       return 0;
10056 +}
10057 +
10058 +#endif /* CONFIG_IPV6 */
10059 +
10060 +#define current_nx_info_has_v6() \
10061 +       nx_info_has_v6(current_nx_info())
10062 +
10063 +#else
10064 +#warning duplicate inclusion
10065 +#endif
10066 diff -NurpP --minimal linux-3.6.9/include/linux/vs_limit.h linux-3.6.9-vs2.3.4.4/include/linux/vs_limit.h
10067 --- linux-3.6.9/include/linux/vs_limit.h        1970-01-01 01:00:00.000000000 +0100
10068 +++ linux-3.6.9-vs2.3.4.4/include/linux/vs_limit.h      2012-10-04 18:47:00.000000000 +0200
10069 @@ -0,0 +1,140 @@
10070 +#ifndef _VS_LIMIT_H
10071 +#define _VS_LIMIT_H
10072 +
10073 +#include "vserver/limit.h"
10074 +#include "vserver/base.h"
10075 +#include "vserver/context.h"
10076 +#include "vserver/debug.h"
10077 +#include "vserver/context.h"
10078 +#include "vserver/limit_int.h"
10079 +
10080 +
10081 +#define vx_acc_cres(v, d, p, r) \
10082 +       __vx_acc_cres(v, r, d, p, __FILE__, __LINE__)
10083 +
10084 +#define vx_acc_cres_cond(x, d, p, r) \
10085 +       __vx_acc_cres(((x) == vx_current_xid()) ? current_vx_info() : 0, \
10086 +       r, d, p, __FILE__, __LINE__)
10087 +
10088 +
10089 +#define vx_add_cres(v, a, p, r) \
10090 +       __vx_add_cres(v, r, a, p, __FILE__, __LINE__)
10091 +#define vx_sub_cres(v, a, p, r)                vx_add_cres(v, -(a), p, r)
10092 +
10093 +#define vx_add_cres_cond(x, a, p, r) \
10094 +       __vx_add_cres(((x) == vx_current_xid()) ? current_vx_info() : 0, \
10095 +       r, a, p, __FILE__, __LINE__)
10096 +#define vx_sub_cres_cond(x, a, p, r)   vx_add_cres_cond(x, -(a), p, r)
10097 +
10098 +
10099 +/* process and file limits */
10100 +
10101 +#define vx_nproc_inc(p) \
10102 +       vx_acc_cres((p)->vx_info, 1, p, RLIMIT_NPROC)
10103 +
10104 +#define vx_nproc_dec(p) \
10105 +       vx_acc_cres((p)->vx_info,-1, p, RLIMIT_NPROC)
10106 +
10107 +#define vx_files_inc(f) \
10108 +       vx_acc_cres_cond((f)->f_xid, 1, f, RLIMIT_NOFILE)
10109 +
10110 +#define vx_files_dec(f) \
10111 +       vx_acc_cres_cond((f)->f_xid,-1, f, RLIMIT_NOFILE)
10112 +
10113 +#define vx_locks_inc(l) \
10114 +       vx_acc_cres_cond((l)->fl_xid, 1, l, RLIMIT_LOCKS)
10115 +
10116 +#define vx_locks_dec(l) \
10117 +       vx_acc_cres_cond((l)->fl_xid,-1, l, RLIMIT_LOCKS)
10118 +
10119 +#define vx_openfd_inc(f) \
10120 +       vx_acc_cres(current_vx_info(), 1, (void *)(long)(f), VLIMIT_OPENFD)
10121 +
10122 +#define vx_openfd_dec(f) \
10123 +       vx_acc_cres(current_vx_info(),-1, (void *)(long)(f), VLIMIT_OPENFD)
10124 +
10125 +
10126 +#define vx_cres_avail(v, n, r) \
10127 +       __vx_cres_avail(v, r, n, __FILE__, __LINE__)
10128 +
10129 +
10130 +#define vx_nproc_avail(n) \
10131 +       vx_cres_avail(current_vx_info(), n, RLIMIT_NPROC)
10132 +
10133 +#define vx_files_avail(n) \
10134 +       vx_cres_avail(current_vx_info(), n, RLIMIT_NOFILE)
10135 +
10136 +#define vx_locks_avail(n) \
10137 +       vx_cres_avail(current_vx_info(), n, RLIMIT_LOCKS)
10138 +
10139 +#define vx_openfd_avail(n) \
10140 +       vx_cres_avail(current_vx_info(), n, VLIMIT_OPENFD)
10141 +
10142 +
10143 +/* dentry limits */
10144 +
10145 +#define vx_dentry_inc(d) do {                                          \
10146 +       if ((d)->d_count == 1)                                          \
10147 +               vx_acc_cres(current_vx_info(), 1, d, VLIMIT_DENTRY);    \
10148 +       } while (0)
10149 +
10150 +#define vx_dentry_dec(d) do {                                          \
10151 +       if ((d)->d_count == 0)                                          \
10152 +               vx_acc_cres(current_vx_info(),-1, d, VLIMIT_DENTRY);    \
10153 +       } while (0)
10154 +
10155 +#define vx_dentry_avail(n) \
10156 +       vx_cres_avail(current_vx_info(), n, VLIMIT_DENTRY)
10157 +
10158 +
10159 +/* socket limits */
10160 +
10161 +#define vx_sock_inc(s) \
10162 +       vx_acc_cres((s)->sk_vx_info, 1, s, VLIMIT_NSOCK)
10163 +
10164 +#define vx_sock_dec(s) \
10165 +       vx_acc_cres((s)->sk_vx_info,-1, s, VLIMIT_NSOCK)
10166 +
10167 +#define vx_sock_avail(n) \
10168 +       vx_cres_avail(current_vx_info(), n, VLIMIT_NSOCK)
10169 +
10170 +
10171 +/* ipc resource limits */
10172 +
10173 +#define vx_ipcmsg_add(v, u, a) \
10174 +       vx_add_cres(v, a, u, RLIMIT_MSGQUEUE)
10175 +
10176 +#define vx_ipcmsg_sub(v, u, a) \
10177 +       vx_sub_cres(v, a, u, RLIMIT_MSGQUEUE)
10178 +
10179 +#define vx_ipcmsg_avail(v, a) \
10180 +       vx_cres_avail(v, a, RLIMIT_MSGQUEUE)
10181 +
10182 +
10183 +#define vx_ipcshm_add(v, k, a) \
10184 +       vx_add_cres(v, a, (void *)(long)(k), VLIMIT_SHMEM)
10185 +
10186 +#define vx_ipcshm_sub(v, k, a) \
10187 +       vx_sub_cres(v, a, (void *)(long)(k), VLIMIT_SHMEM)
10188 +
10189 +#define vx_ipcshm_avail(v, a) \
10190 +       vx_cres_avail(v, a, VLIMIT_SHMEM)
10191 +
10192 +
10193 +#define vx_semary_inc(a) \
10194 +       vx_acc_cres(current_vx_info(), 1, a, VLIMIT_SEMARY)
10195 +
10196 +#define vx_semary_dec(a) \
10197 +       vx_acc_cres(current_vx_info(), -1, a, VLIMIT_SEMARY)
10198 +
10199 +
10200 +#define vx_nsems_add(a,n) \
10201 +       vx_add_cres(current_vx_info(), n, a, VLIMIT_NSEMS)
10202 +
10203 +#define vx_nsems_sub(a,n) \
10204 +       vx_sub_cres(current_vx_info(), n, a, VLIMIT_NSEMS)
10205 +
10206 +
10207 +#else
10208 +#warning duplicate inclusion
10209 +#endif
10210 diff -NurpP --minimal linux-3.6.9/include/linux/vs_network.h linux-3.6.9-vs2.3.4.4/include/linux/vs_network.h
10211 --- linux-3.6.9/include/linux/vs_network.h      1970-01-01 01:00:00.000000000 +0100
10212 +++ linux-3.6.9-vs2.3.4.4/include/linux/vs_network.h    2012-10-04 18:47:00.000000000 +0200
10213 @@ -0,0 +1,169 @@
10214 +#ifndef _NX_VS_NETWORK_H
10215 +#define _NX_VS_NETWORK_H
10216 +
10217 +#include "vserver/context.h"
10218 +#include "vserver/network.h"
10219 +#include "vserver/base.h"
10220 +#include "vserver/check.h"
10221 +#include "vserver/debug.h"
10222 +
10223 +#include <linux/sched.h>
10224 +
10225 +
10226 +#define get_nx_info(i) __get_nx_info(i, __FILE__, __LINE__)
10227 +
10228 +static inline struct nx_info *__get_nx_info(struct nx_info *nxi,
10229 +       const char *_file, int _line)
10230 +{
10231 +       if (!nxi)
10232 +               return NULL;
10233 +
10234 +       vxlprintk(VXD_CBIT(nid, 2), "get_nx_info(%p[#%d.%d])",
10235 +               nxi, nxi ? nxi->nx_id : 0,
10236 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
10237 +               _file, _line);
10238 +
10239 +       atomic_inc(&nxi->nx_usecnt);
10240 +       return nxi;
10241 +}
10242 +
10243 +
10244 +extern void free_nx_info(struct nx_info *);
10245 +
10246 +#define put_nx_info(i) __put_nx_info(i, __FILE__, __LINE__)
10247 +
10248 +static inline void __put_nx_info(struct nx_info *nxi, const char *_file, int _line)
10249 +{
10250 +       if (!nxi)
10251 +               return;
10252 +
10253 +       vxlprintk(VXD_CBIT(nid, 2), "put_nx_info(%p[#%d.%d])",
10254 +               nxi, nxi ? nxi->nx_id : 0,
10255 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
10256 +               _file, _line);
10257 +
10258 +       if (atomic_dec_and_test(&nxi->nx_usecnt))
10259 +               free_nx_info(nxi);
10260 +}
10261 +
10262 +
10263 +#define init_nx_info(p, i) __init_nx_info(p, i, __FILE__, __LINE__)
10264 +
10265 +static inline void __init_nx_info(struct nx_info **nxp, struct nx_info *nxi,
10266 +               const char *_file, int _line)
10267 +{
10268 +       if (nxi) {
10269 +               vxlprintk(VXD_CBIT(nid, 3),
10270 +                       "init_nx_info(%p[#%d.%d])",
10271 +                       nxi, nxi ? nxi->nx_id : 0,
10272 +                       nxi ? atomic_read(&nxi->nx_usecnt) : 0,
10273 +                       _file, _line);
10274 +
10275 +               atomic_inc(&nxi->nx_usecnt);
10276 +       }
10277 +       *nxp = nxi;
10278 +}
10279 +
10280 +
10281 +#define set_nx_info(p, i) __set_nx_info(p, i, __FILE__, __LINE__)
10282 +
10283 +static inline void __set_nx_info(struct nx_info **nxp, struct nx_info *nxi,
10284 +       const char *_file, int _line)
10285 +{
10286 +       struct nx_info *nxo;
10287 +
10288 +       if (!nxi)
10289 +               return;
10290 +
10291 +       vxlprintk(VXD_CBIT(nid, 3), "set_nx_info(%p[#%d.%d])",
10292 +               nxi, nxi ? nxi->nx_id : 0,
10293 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
10294 +               _file, _line);
10295 +
10296 +       atomic_inc(&nxi->nx_usecnt);
10297 +       nxo = xchg(nxp, nxi);
10298 +       BUG_ON(nxo);
10299 +}
10300 +
10301 +#define clr_nx_info(p) __clr_nx_info(p, __FILE__, __LINE__)
10302 +
10303 +static inline void __clr_nx_info(struct nx_info **nxp,
10304 +       const char *_file, int _line)
10305 +{
10306 +       struct nx_info *nxo;
10307 +
10308 +       nxo = xchg(nxp, NULL);
10309 +       if (!nxo)
10310 +               return;
10311 +
10312 +       vxlprintk(VXD_CBIT(nid, 3), "clr_nx_info(%p[#%d.%d])",
10313 +               nxo, nxo ? nxo->nx_id : 0,
10314 +               nxo ? atomic_read(&nxo->nx_usecnt) : 0,
10315 +               _file, _line);
10316 +
10317 +       if (atomic_dec_and_test(&nxo->nx_usecnt))
10318 +               free_nx_info(nxo);
10319 +}
10320 +
10321 +
10322 +#define claim_nx_info(v, p) __claim_nx_info(v, p, __FILE__, __LINE__)
10323 +
10324 +static inline void __claim_nx_info(struct nx_info *nxi,
10325 +       struct task_struct *task, const char *_file, int _line)
10326 +{
10327 +       vxlprintk(VXD_CBIT(nid, 3), "claim_nx_info(%p[#%d.%d.%d]) %p",
10328 +               nxi, nxi ? nxi->nx_id : 0,
10329 +               nxi?atomic_read(&nxi->nx_usecnt):0,
10330 +               nxi?atomic_read(&nxi->nx_tasks):0,
10331 +               task, _file, _line);
10332 +
10333 +       atomic_inc(&nxi->nx_tasks);
10334 +}
10335 +
10336 +
10337 +extern void unhash_nx_info(struct nx_info *);
10338 +
10339 +#define release_nx_info(v, p) __release_nx_info(v, p, __FILE__, __LINE__)
10340 +
10341 +static inline void __release_nx_info(struct nx_info *nxi,
10342 +       struct task_struct *task, const char *_file, int _line)
10343 +{
10344 +       vxlprintk(VXD_CBIT(nid, 3), "release_nx_info(%p[#%d.%d.%d]) %p",
10345 +               nxi, nxi ? nxi->nx_id : 0,
10346 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
10347 +               nxi ? atomic_read(&nxi->nx_tasks) : 0,
10348 +               task, _file, _line);
10349 +
10350 +       might_sleep();
10351 +
10352 +       if (atomic_dec_and_test(&nxi->nx_tasks))
10353 +               unhash_nx_info(nxi);
10354 +}
10355 +
10356 +
10357 +#define task_get_nx_info(i)    __task_get_nx_info(i, __FILE__, __LINE__)
10358 +
10359 +static __inline__ struct nx_info *__task_get_nx_info(struct task_struct *p,
10360 +       const char *_file, int _line)
10361 +{
10362 +       struct nx_info *nxi;
10363 +
10364 +       task_lock(p);
10365 +       vxlprintk(VXD_CBIT(nid, 5), "task_get_nx_info(%p)",
10366 +               p, _file, _line);
10367 +       nxi = __get_nx_info(p->nx_info, _file, _line);
10368 +       task_unlock(p);
10369 +       return nxi;
10370 +}
10371 +
10372 +
10373 +static inline void exit_nx_info(struct task_struct *p)
10374 +{
10375 +       if (p->nx_info)
10376 +               release_nx_info(p->nx_info, p);
10377 +}
10378 +
10379 +
10380 +#else
10381 +#warning duplicate inclusion
10382 +#endif
10383 diff -NurpP --minimal linux-3.6.9/include/linux/vs_pid.h linux-3.6.9-vs2.3.4.4/include/linux/vs_pid.h
10384 --- linux-3.6.9/include/linux/vs_pid.h  1970-01-01 01:00:00.000000000 +0100
10385 +++ linux-3.6.9-vs2.3.4.4/include/linux/vs_pid.h        2012-10-04 18:47:00.000000000 +0200
10386 @@ -0,0 +1,50 @@
10387 +#ifndef _VS_PID_H
10388 +#define _VS_PID_H
10389 +
10390 +#include "vserver/base.h"
10391 +#include "vserver/check.h"
10392 +#include "vserver/context.h"
10393 +#include "vserver/debug.h"
10394 +#include "vserver/pid.h"
10395 +#include <linux/pid_namespace.h>
10396 +
10397 +
10398 +#define VXF_FAKE_INIT  (VXF_INFO_INIT | VXF_STATE_INIT)
10399 +
10400 +static inline
10401 +int vx_proc_task_visible(struct task_struct *task)
10402 +{
10403 +       if ((task->pid == 1) &&
10404 +               !vx_flags(VXF_FAKE_INIT, VXF_FAKE_INIT))
10405 +               /* show a blend through init */
10406 +               goto visible;
10407 +       if (vx_check(vx_task_xid(task), VS_WATCH | VS_IDENT))
10408 +               goto visible;
10409 +       return 0;
10410 +visible:
10411 +       return 1;
10412 +}
10413 +
10414 +#define find_task_by_real_pid(pid) find_task_by_pid_ns(pid, &init_pid_ns)
10415 +
10416 +
10417 +static inline
10418 +struct task_struct *vx_get_proc_task(struct inode *inode, struct pid *pid)
10419 +{
10420 +       struct task_struct *task = get_pid_task(pid, PIDTYPE_PID);
10421 +
10422 +       if (task && !vx_proc_task_visible(task)) {
10423 +               vxdprintk(VXD_CBIT(misc, 6),
10424 +                       "dropping task (get) %p[#%u,%u] for %p[#%u,%u]",
10425 +                       task, task->xid, task->pid,
10426 +                       current, current->xid, current->pid);
10427 +               put_task_struct(task);
10428 +               task = NULL;
10429 +       }
10430 +       return task;
10431 +}
10432 +
10433 +
10434 +#else
10435 +#warning duplicate inclusion
10436 +#endif
10437 diff -NurpP --minimal linux-3.6.9/include/linux/vs_sched.h linux-3.6.9-vs2.3.4.4/include/linux/vs_sched.h
10438 --- linux-3.6.9/include/linux/vs_sched.h        1970-01-01 01:00:00.000000000 +0100
10439 +++ linux-3.6.9-vs2.3.4.4/include/linux/vs_sched.h      2012-10-04 18:47:00.000000000 +0200
10440 @@ -0,0 +1,40 @@
10441 +#ifndef _VS_SCHED_H
10442 +#define _VS_SCHED_H
10443 +
10444 +#include "vserver/base.h"
10445 +#include "vserver/context.h"
10446 +#include "vserver/sched.h"
10447 +
10448 +
10449 +#define MAX_PRIO_BIAS           20
10450 +#define MIN_PRIO_BIAS          -20
10451 +
10452 +static inline
10453 +int vx_adjust_prio(struct task_struct *p, int prio, int max_user)
10454 +{
10455 +       struct vx_info *vxi = p->vx_info;
10456 +
10457 +       if (vxi)
10458 +               prio += vx_cpu(vxi, sched_pc).prio_bias;
10459 +       return prio;
10460 +}
10461 +
10462 +static inline void vx_account_user(struct vx_info *vxi,
10463 +       cputime_t cputime, int nice)
10464 +{
10465 +       if (!vxi)
10466 +               return;
10467 +       vx_cpu(vxi, sched_pc).user_ticks += cputime;
10468 +}
10469 +
10470 +static inline void vx_account_system(struct vx_info *vxi,
10471 +       cputime_t cputime, int idle)
10472 +{
10473 +       if (!vxi)
10474 +               return;
10475 +       vx_cpu(vxi, sched_pc).sys_ticks += cputime;
10476 +}
10477 +
10478 +#else
10479 +#warning duplicate inclusion
10480 +#endif
10481 diff -NurpP --minimal linux-3.6.9/include/linux/vs_socket.h linux-3.6.9-vs2.3.4.4/include/linux/vs_socket.h
10482 --- linux-3.6.9/include/linux/vs_socket.h       1970-01-01 01:00:00.000000000 +0100
10483 +++ linux-3.6.9-vs2.3.4.4/include/linux/vs_socket.h     2012-10-04 18:47:00.000000000 +0200
10484 @@ -0,0 +1,67 @@
10485 +#ifndef _VS_SOCKET_H
10486 +#define _VS_SOCKET_H
10487 +
10488 +#include "vserver/debug.h"
10489 +#include "vserver/base.h"
10490 +#include "vserver/cacct.h"
10491 +#include "vserver/context.h"
10492 +#include "vserver/tag.h"
10493 +
10494 +
10495 +/* socket accounting */
10496 +
10497 +#include <linux/socket.h>
10498 +
10499 +static inline int vx_sock_type(int family)
10500 +{
10501 +       switch (family) {
10502 +       case PF_UNSPEC:
10503 +               return VXA_SOCK_UNSPEC;
10504 +       case PF_UNIX:
10505 +               return VXA_SOCK_UNIX;
10506 +       case PF_INET:
10507 +               return VXA_SOCK_INET;
10508 +       case PF_INET6:
10509 +               return VXA_SOCK_INET6;
10510 +       case PF_PACKET:
10511 +               return VXA_SOCK_PACKET;
10512 +       default:
10513 +               return VXA_SOCK_OTHER;
10514 +       }
10515 +}
10516 +
10517 +#define vx_acc_sock(v, f, p, s) \
10518 +       __vx_acc_sock(v, f, p, s, __FILE__, __LINE__)
10519 +
10520 +static inline void __vx_acc_sock(struct vx_info *vxi,
10521 +       int family, int pos, int size, char *file, int line)
10522 +{
10523 +       if (vxi) {
10524 +               int type = vx_sock_type(family);
10525 +
10526 +               atomic_long_inc(&vxi->cacct.sock[type][pos].count);
10527 +               atomic_long_add(size, &vxi->cacct.sock[type][pos].total);
10528 +       }
10529 +}
10530 +
10531 +#define vx_sock_recv(sk, s) \
10532 +       vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 0, s)
10533 +#define vx_sock_send(sk, s) \
10534 +       vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 1, s)
10535 +#define vx_sock_fail(sk, s) \
10536 +       vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 2, s)
10537 +
10538 +
10539 +#define sock_vx_init(s) do {           \
10540 +       (s)->sk_xid = 0;                \
10541 +       (s)->sk_vx_info = NULL;         \
10542 +       } while (0)
10543 +
10544 +#define sock_nx_init(s) do {           \
10545 +       (s)->sk_nid = 0;                \
10546 +       (s)->sk_nx_info = NULL;         \
10547 +       } while (0)
10548 +
10549 +#else
10550 +#warning duplicate inclusion
10551 +#endif
10552 diff -NurpP --minimal linux-3.6.9/include/linux/vs_tag.h linux-3.6.9-vs2.3.4.4/include/linux/vs_tag.h
10553 --- linux-3.6.9/include/linux/vs_tag.h  1970-01-01 01:00:00.000000000 +0100
10554 +++ linux-3.6.9-vs2.3.4.4/include/linux/vs_tag.h        2012-10-04 18:47:00.000000000 +0200
10555 @@ -0,0 +1,47 @@
10556 +#ifndef _VS_TAG_H
10557 +#define _VS_TAG_H
10558 +
10559 +#include <linux/vserver/tag.h>
10560 +
10561 +/* check conditions */
10562 +
10563 +#define DX_ADMIN       0x0001
10564 +#define DX_WATCH       0x0002
10565 +#define DX_HOSTID      0x0008
10566 +
10567 +#define DX_IDENT       0x0010
10568 +
10569 +#define DX_ARG_MASK    0x0010
10570 +
10571 +
10572 +#define dx_task_tag(t) ((t)->tag)
10573 +
10574 +#define dx_current_tag() dx_task_tag(current)
10575 +
10576 +#define dx_check(c, m) __dx_check(dx_current_tag(), c, m)
10577 +
10578 +#define dx_weak_check(c, m)    ((m) ? dx_check(c, m) : 1)
10579 +
10580 +
10581 +/*
10582 + * check current context for ADMIN/WATCH and
10583 + * optionally against supplied argument
10584 + */
10585 +static inline int __dx_check(vs_tag_t cid, vs_tag_t id, unsigned int mode)
10586 +{
10587 +       if (mode & DX_ARG_MASK) {
10588 +               if ((mode & DX_IDENT) && (id == cid))
10589 +                       return 1;
10590 +       }
10591 +       return (((mode & DX_ADMIN) && (cid == 0)) ||
10592 +               ((mode & DX_WATCH) && (cid == 1)) ||
10593 +               ((mode & DX_HOSTID) && (id == 0)));
10594 +}
10595 +
10596 +struct inode;
10597 +int dx_permission(const struct inode *inode, int mask);
10598 +
10599 +
10600 +#else
10601 +#warning duplicate inclusion
10602 +#endif
10603 diff -NurpP --minimal linux-3.6.9/include/linux/vs_time.h linux-3.6.9-vs2.3.4.4/include/linux/vs_time.h
10604 --- linux-3.6.9/include/linux/vs_time.h 1970-01-01 01:00:00.000000000 +0100
10605 +++ linux-3.6.9-vs2.3.4.4/include/linux/vs_time.h       2012-10-04 18:47:00.000000000 +0200
10606 @@ -0,0 +1,19 @@
10607 +#ifndef _VS_TIME_H
10608 +#define _VS_TIME_H
10609 +
10610 +
10611 +/* time faking stuff */
10612 +
10613 +#ifdef CONFIG_VSERVER_VTIME
10614 +
10615 +extern void vx_adjust_timespec(struct timespec *ts);
10616 +extern int vx_settimeofday(const struct timespec *ts);
10617 +
10618 +#else
10619 +#define        vx_adjust_timespec(t)   do { } while (0)
10620 +#define        vx_settimeofday(t)      do_settimeofday(t)
10621 +#endif
10622 +
10623 +#else
10624 +#warning duplicate inclusion
10625 +#endif
10626 diff -NurpP --minimal linux-3.6.9/include/linux/vserver/Kbuild linux-3.6.9-vs2.3.4.4/include/linux/vserver/Kbuild
10627 --- linux-3.6.9/include/linux/vserver/Kbuild    1970-01-01 01:00:00.000000000 +0100
10628 +++ linux-3.6.9-vs2.3.4.4/include/linux/vserver/Kbuild  2012-10-04 18:47:00.000000000 +0200
10629 @@ -0,0 +1,8 @@
10630 +
10631 +header-y += context_cmd.h network_cmd.h space_cmd.h \
10632 +       cacct_cmd.h cvirt_cmd.h limit_cmd.h dlimit_cmd.h \
10633 +       inode_cmd.h tag_cmd.h sched_cmd.h signal_cmd.h \
10634 +       debug_cmd.h device_cmd.h
10635 +
10636 +header-y += switch.h network.h monitor.h inode.h device.h
10637 +
10638 diff -NurpP --minimal linux-3.6.9/include/linux/vserver/base.h linux-3.6.9-vs2.3.4.4/include/linux/vserver/base.h
10639 --- linux-3.6.9/include/linux/vserver/base.h    1970-01-01 01:00:00.000000000 +0100
10640 +++ linux-3.6.9-vs2.3.4.4/include/linux/vserver/base.h  2012-10-04 18:47:00.000000000 +0200
10641 @@ -0,0 +1,178 @@
10642 +#ifndef _VX_BASE_H
10643 +#define _VX_BASE_H
10644 +
10645 +
10646 +/* context state changes */
10647 +
10648 +enum {
10649 +       VSC_STARTUP = 1,
10650 +       VSC_SHUTDOWN,
10651 +
10652 +       VSC_NETUP,
10653 +       VSC_NETDOWN,
10654 +};
10655 +
10656 +
10657 +
10658 +#define vx_task_xid(t) ((t)->xid)
10659 +
10660 +#define vx_current_xid() vx_task_xid(current)
10661 +
10662 +#define current_vx_info() (current->vx_info)
10663 +
10664 +
10665 +#define nx_task_nid(t) ((t)->nid)
10666 +
10667 +#define nx_current_nid() nx_task_nid(current)
10668 +
10669 +#define current_nx_info() (current->nx_info)
10670 +
10671 +
10672 +/* generic flag merging */
10673 +
10674 +#define vs_check_flags(v, m, f)        (((v) & (m)) ^ (f))
10675 +
10676 +#define vs_mask_flags(v, f, m) (((v) & ~(m)) | ((f) & (m)))
10677 +
10678 +#define vs_mask_mask(v, f, m)  (((v) & ~(m)) | ((v) & (f) & (m)))
10679 +
10680 +#define vs_check_bit(v, n)     ((v) & (1LL << (n)))
10681 +
10682 +
10683 +/* context flags */
10684 +
10685 +#define __vx_flags(v)  ((v) ? (v)->vx_flags : 0)
10686 +
10687 +#define vx_current_flags()     __vx_flags(current_vx_info())
10688 +
10689 +#define vx_info_flags(v, m, f) \
10690 +       vs_check_flags(__vx_flags(v), m, f)
10691 +
10692 +#define task_vx_flags(t, m, f) \
10693 +       ((t) && vx_info_flags((t)->vx_info, m, f))
10694 +
10695 +#define vx_flags(m, f) vx_info_flags(current_vx_info(), m, f)
10696 +
10697 +
10698 +/* context caps */
10699 +
10700 +#define __vx_ccaps(v)  ((v) ? (v)->vx_ccaps : 0)
10701 +
10702 +#define vx_current_ccaps()     __vx_ccaps(current_vx_info())
10703 +
10704 +#define vx_info_ccaps(v, c)    (__vx_ccaps(v) & (c))
10705 +
10706 +#define vx_ccaps(c)    vx_info_ccaps(current_vx_info(), (c))
10707 +
10708 +
10709 +
10710 +/* network flags */
10711 +
10712 +#define __nx_flags(n)  ((n) ? (n)->nx_flags : 0)
10713 +
10714 +#define nx_current_flags()     __nx_flags(current_nx_info())
10715 +
10716 +#define nx_info_flags(n, m, f) \
10717 +       vs_check_flags(__nx_flags(n), m, f)
10718 +
10719 +#define task_nx_flags(t, m, f) \
10720 +       ((t) && nx_info_flags((t)->nx_info, m, f))
10721 +
10722 +#define nx_flags(m, f) nx_info_flags(current_nx_info(), m, f)
10723 +
10724 +
10725 +/* network caps */
10726 +
10727 +#define __nx_ncaps(n)  ((n) ? (n)->nx_ncaps : 0)
10728 +
10729 +#define nx_current_ncaps()     __nx_ncaps(current_nx_info())
10730 +
10731 +#define nx_info_ncaps(n, c)    (__nx_ncaps(n) & (c))
10732 +
10733 +#define nx_ncaps(c)    nx_info_ncaps(current_nx_info(), c)
10734 +
10735 +
10736 +/* context mask capabilities */
10737 +
10738 +#define __vx_mcaps(v)  ((v) ? (v)->vx_ccaps >> 32UL : ~0 )
10739 +
10740 +#define vx_info_mcaps(v, c)    (__vx_mcaps(v) & (c))
10741 +
10742 +#define vx_mcaps(c)    vx_info_mcaps(current_vx_info(), c)
10743 +
10744 +
10745 +/* context bcap mask */
10746 +
10747 +#define __vx_bcaps(v)          ((v)->vx_bcaps)
10748 +
10749 +#define vx_current_bcaps()     __vx_bcaps(current_vx_info())
10750 +
10751 +
10752 +/* mask given bcaps */
10753 +
10754 +#define vx_info_mbcaps(v, c)   ((v) ? cap_intersect(__vx_bcaps(v), c) : c)
10755 +
10756 +#define vx_mbcaps(c)           vx_info_mbcaps(current_vx_info(), c)
10757 +
10758 +
10759 +/* masked cap_bset */
10760 +
10761 +#define vx_info_cap_bset(v)    vx_info_mbcaps(v, current->cap_bset)
10762 +
10763 +#define vx_current_cap_bset()  vx_info_cap_bset(current_vx_info())
10764 +
10765 +#if 0
10766 +#define vx_info_mbcap(v, b) \
10767 +       (!vx_info_flags(v, VXF_STATE_SETUP, 0) ? \
10768 +       vx_info_bcaps(v, b) : (b))
10769 +
10770 +#define task_vx_mbcap(t, b) \
10771 +       vx_info_mbcap((t)->vx_info, (t)->b)
10772 +
10773 +#define vx_mbcap(b)    task_vx_mbcap(current, b)
10774 +#endif
10775 +
10776 +#define vx_cap_raised(v, c, f) cap_raised(vx_info_mbcaps(v, c), f)
10777 +
10778 +#define vx_capable(b, c) (capable(b) || \
10779 +       (cap_raised(current_cap(), b) && vx_ccaps(c)))
10780 +
10781 +#define vx_ns_capable(n, b, c) (ns_capable(n, b) || \
10782 +       (cap_raised(current_cap(), b) && vx_ccaps(c)))
10783 +
10784 +#define nx_capable(b, c) (capable(b) || \
10785 +       (cap_raised(current_cap(), b) && nx_ncaps(c)))
10786 +
10787 +#define vx_task_initpid(t, n) \
10788 +       ((t)->vx_info && \
10789 +       ((t)->vx_info->vx_initpid == (n)))
10790 +
10791 +#define vx_current_initpid(n)  vx_task_initpid(current, n)
10792 +
10793 +
10794 +/* context unshare mask */
10795 +
10796 +#define __vx_umask(v)          ((v)->vx_umask)
10797 +
10798 +#define vx_current_umask()     __vx_umask(current_vx_info())
10799 +
10800 +#define vx_can_unshare(b, f) (capable(b) || \
10801 +       (cap_raised(current_cap(), b) && \
10802 +       !((f) & ~vx_current_umask())))
10803 +
10804 +
10805 +#define __vx_wmask(v)          ((v)->vx_wmask)
10806 +
10807 +#define vx_current_wmask()     __vx_wmask(current_vx_info())
10808 +
10809 +
10810 +#define __vx_state(v)  ((v) ? ((v)->vx_state) : 0)
10811 +
10812 +#define vx_info_state(v, m)    (__vx_state(v) & (m))
10813 +
10814 +
10815 +#define __nx_state(n)  ((n) ? ((n)->nx_state) : 0)
10816 +
10817 +#define nx_info_state(n, m)    (__nx_state(n) & (m))
10818 +
10819 +#endif
10820 diff -NurpP --minimal linux-3.6.9/include/linux/vserver/cacct.h linux-3.6.9-vs2.3.4.4/include/linux/vserver/cacct.h
10821 --- linux-3.6.9/include/linux/vserver/cacct.h   1970-01-01 01:00:00.000000000 +0100
10822 +++ linux-3.6.9-vs2.3.4.4/include/linux/vserver/cacct.h 2012-10-04 18:47:00.000000000 +0200
10823 @@ -0,0 +1,15 @@
10824 +#ifndef _VX_CACCT_H
10825 +#define _VX_CACCT_H
10826 +
10827 +
10828 +enum sock_acc_field {
10829 +       VXA_SOCK_UNSPEC = 0,
10830 +       VXA_SOCK_UNIX,
10831 +       VXA_SOCK_INET,
10832 +       VXA_SOCK_INET6,
10833 +       VXA_SOCK_PACKET,
10834 +       VXA_SOCK_OTHER,
10835 +       VXA_SOCK_SIZE   /* array size */
10836 +};
10837 +
10838 +#endif /* _VX_CACCT_H */
10839 diff -NurpP --minimal linux-3.6.9/include/linux/vserver/cacct_cmd.h linux-3.6.9-vs2.3.4.4/include/linux/vserver/cacct_cmd.h
10840 --- linux-3.6.9/include/linux/vserver/cacct_cmd.h       1970-01-01 01:00:00.000000000 +0100
10841 +++ linux-3.6.9-vs2.3.4.4/include/linux/vserver/cacct_cmd.h     2012-10-04 18:47:00.000000000 +0200
10842 @@ -0,0 +1,23 @@
10843 +#ifndef _VX_CACCT_CMD_H
10844 +#define _VX_CACCT_CMD_H
10845 +
10846 +
10847 +/* virtual host info name commands */
10848 +
10849 +#define VCMD_sock_stat         VC_CMD(VSTAT, 5, 0)
10850 +
10851 +struct vcmd_sock_stat_v0 {
10852 +       uint32_t field;
10853 +       uint32_t count[3];
10854 +       uint64_t total[3];
10855 +};
10856 +
10857 +
10858 +#ifdef __KERNEL__
10859 +
10860 +#include <linux/compiler.h>
10861 +
10862 +extern int vc_sock_stat(struct vx_info *, void __user *);
10863 +
10864 +#endif /* __KERNEL__ */
10865 +#endif /* _VX_CACCT_CMD_H */
10866 diff -NurpP --minimal linux-3.6.9/include/linux/vserver/cacct_def.h linux-3.6.9-vs2.3.4.4/include/linux/vserver/cacct_def.h
10867 --- linux-3.6.9/include/linux/vserver/cacct_def.h       1970-01-01 01:00:00.000000000 +0100
10868 +++ linux-3.6.9-vs2.3.4.4/include/linux/vserver/cacct_def.h     2012-10-04 18:47:00.000000000 +0200
10869 @@ -0,0 +1,43 @@
10870 +#ifndef _VX_CACCT_DEF_H
10871 +#define _VX_CACCT_DEF_H
10872 +
10873 +#include <asm/atomic.h>
10874 +#include <linux/vserver/cacct.h>
10875 +
10876 +
10877 +struct _vx_sock_acc {
10878 +       atomic_long_t count;
10879 +       atomic_long_t total;
10880 +};
10881 +
10882 +/* context sub struct */
10883 +
10884 +struct _vx_cacct {
10885 +       struct _vx_sock_acc sock[VXA_SOCK_SIZE][3];
10886 +       atomic_t slab[8];
10887 +       atomic_t page[6][8];
10888 +};
10889 +
10890 +#ifdef CONFIG_VSERVER_DEBUG
10891 +
10892 +static inline void __dump_vx_cacct(struct _vx_cacct *cacct)
10893 +{
10894 +       int i, j;
10895 +
10896 +       printk("\t_vx_cacct:");
10897 +       for (i = 0; i < 6; i++) {
10898 +               struct _vx_sock_acc *ptr = cacct->sock[i];
10899 +
10900 +               printk("\t [%d] =", i);
10901 +               for (j = 0; j < 3; j++) {
10902 +                       printk(" [%d] = %8lu, %8lu", j,
10903 +                               atomic_long_read(&ptr[j].count),
10904 +                               atomic_long_read(&ptr[j].total));
10905 +               }
10906 +               printk("\n");
10907 +       }
10908 +}
10909 +
10910 +#endif
10911 +
10912 +#endif /* _VX_CACCT_DEF_H */
10913 diff -NurpP --minimal linux-3.6.9/include/linux/vserver/cacct_int.h linux-3.6.9-vs2.3.4.4/include/linux/vserver/cacct_int.h
10914 --- linux-3.6.9/include/linux/vserver/cacct_int.h       1970-01-01 01:00:00.000000000 +0100
10915 +++ linux-3.6.9-vs2.3.4.4/include/linux/vserver/cacct_int.h     2012-10-04 18:47:00.000000000 +0200
10916 @@ -0,0 +1,21 @@
10917 +#ifndef _VX_CACCT_INT_H
10918 +#define _VX_CACCT_INT_H
10919 +
10920 +
10921 +#ifdef __KERNEL__
10922 +
10923 +static inline
10924 +unsigned long vx_sock_count(struct _vx_cacct *cacct, int type, int pos)
10925 +{
10926 +       return atomic_long_read(&cacct->sock[type][pos].count);
10927 +}
10928 +
10929 +
10930 +static inline
10931 +unsigned long vx_sock_total(struct _vx_cacct *cacct, int type, int pos)
10932 +{
10933 +       return atomic_long_read(&cacct->sock[type][pos].total);
10934 +}
10935 +
10936 +#endif /* __KERNEL__ */
10937 +#endif /* _VX_CACCT_INT_H */
10938 diff -NurpP --minimal linux-3.6.9/include/linux/vserver/check.h linux-3.6.9-vs2.3.4.4/include/linux/vserver/check.h
10939 --- linux-3.6.9/include/linux/vserver/check.h   1970-01-01 01:00:00.000000000 +0100
10940 +++ linux-3.6.9-vs2.3.4.4/include/linux/vserver/check.h 2012-10-04 18:47:00.000000000 +0200
10941 @@ -0,0 +1,89 @@
10942 +#ifndef _VS_CHECK_H
10943 +#define _VS_CHECK_H
10944 +
10945 +
10946 +#define MAX_S_CONTEXT  65535   /* Arbitrary limit */
10947 +
10948 +#ifdef CONFIG_VSERVER_DYNAMIC_IDS
10949 +#define MIN_D_CONTEXT  49152   /* dynamic contexts start here */
10950 +#else
10951 +#define MIN_D_CONTEXT  65536
10952 +#endif
10953 +
10954 +/* check conditions */
10955 +
10956 +#define VS_ADMIN       0x0001
10957 +#define VS_WATCH       0x0002
10958 +#define VS_HIDE                0x0004
10959 +#define VS_HOSTID      0x0008
10960 +
10961 +#define VS_IDENT       0x0010
10962 +#define VS_EQUIV       0x0020
10963 +#define VS_PARENT      0x0040
10964 +#define VS_CHILD       0x0080
10965 +
10966 +#define VS_ARG_MASK    0x00F0
10967 +
10968 +#define VS_DYNAMIC     0x0100
10969 +#define VS_STATIC      0x0200
10970 +
10971 +#define VS_ATR_MASK    0x0F00
10972 +
10973 +#ifdef CONFIG_VSERVER_PRIVACY
10974 +#define VS_ADMIN_P     (0)
10975 +#define VS_WATCH_P     (0)
10976 +#else
10977 +#define VS_ADMIN_P     VS_ADMIN
10978 +#define VS_WATCH_P     VS_WATCH
10979 +#endif
10980 +
10981 +#define VS_HARDIRQ     0x1000
10982 +#define VS_SOFTIRQ     0x2000
10983 +#define VS_IRQ         0x4000
10984 +
10985 +#define VS_IRQ_MASK    0xF000
10986 +
10987 +#include <linux/hardirq.h>
10988 +
10989 +/*
10990 + * check current context for ADMIN/WATCH and
10991 + * optionally against supplied argument
10992 + */
10993 +static inline int __vs_check(int cid, int id, unsigned int mode)
10994 +{
10995 +       if (mode & VS_ARG_MASK) {
10996 +               if ((mode & VS_IDENT) && (id == cid))
10997 +                       return 1;
10998 +       }
10999 +       if (mode & VS_ATR_MASK) {
11000 +               if ((mode & VS_DYNAMIC) &&
11001 +                       (id >= MIN_D_CONTEXT) &&
11002 +                       (id <= MAX_S_CONTEXT))
11003 +                       return 1;
11004 +               if ((mode & VS_STATIC) &&
11005 +                       (id > 1) && (id < MIN_D_CONTEXT))
11006 +                       return 1;
11007 +       }
11008 +       if (mode & VS_IRQ_MASK) {
11009 +               if ((mode & VS_IRQ) && unlikely(in_interrupt()))
11010 +                       return 1;
11011 +               if ((mode & VS_HARDIRQ) && unlikely(in_irq()))
11012 +                       return 1;
11013 +               if ((mode & VS_SOFTIRQ) && unlikely(in_softirq()))
11014 +                       return 1;
11015 +       }
11016 +       return (((mode & VS_ADMIN) && (cid == 0)) ||
11017 +               ((mode & VS_WATCH) && (cid == 1)) ||
11018 +               ((mode & VS_HOSTID) && (id == 0)));
11019 +}
11020 +
11021 +#define vx_check(c, m) __vs_check(vx_current_xid(), c, (m) | VS_IRQ)
11022 +
11023 +#define vx_weak_check(c, m)    ((m) ? vx_check(c, m) : 1)
11024 +
11025 +
11026 +#define nx_check(c, m) __vs_check(nx_current_nid(), c, m)
11027 +
11028 +#define nx_weak_check(c, m)    ((m) ? nx_check(c, m) : 1)
11029 +
11030 +#endif
11031 diff -NurpP --minimal linux-3.6.9/include/linux/vserver/context.h linux-3.6.9-vs2.3.4.4/include/linux/vserver/context.h
11032 --- linux-3.6.9/include/linux/vserver/context.h 1970-01-01 01:00:00.000000000 +0100
11033 +++ linux-3.6.9-vs2.3.4.4/include/linux/vserver/context.h       2012-10-04 18:47:00.000000000 +0200
11034 @@ -0,0 +1,188 @@
11035 +#ifndef _VX_CONTEXT_H
11036 +#define _VX_CONTEXT_H
11037 +
11038 +#include <linux/types.h>
11039 +#include <linux/capability.h>
11040 +
11041 +
11042 +/* context flags */
11043 +
11044 +#define VXF_INFO_SCHED         0x00000002
11045 +#define VXF_INFO_NPROC         0x00000004
11046 +#define VXF_INFO_PRIVATE       0x00000008
11047 +
11048 +#define VXF_INFO_INIT          0x00000010
11049 +#define VXF_INFO_HIDE          0x00000020
11050 +#define VXF_INFO_ULIMIT                0x00000040
11051 +#define VXF_INFO_NSPACE                0x00000080
11052 +
11053 +#define VXF_SCHED_HARD         0x00000100
11054 +#define VXF_SCHED_PRIO         0x00000200
11055 +#define VXF_SCHED_PAUSE                0x00000400
11056 +
11057 +#define VXF_VIRT_MEM           0x00010000
11058 +#define VXF_VIRT_UPTIME                0x00020000
11059 +#define VXF_VIRT_CPU           0x00040000
11060 +#define VXF_VIRT_LOAD          0x00080000
11061 +#define VXF_VIRT_TIME          0x00100000
11062 +
11063 +#define VXF_HIDE_MOUNT         0x01000000
11064 +/* was VXF_HIDE_NETIF          0x02000000 */
11065 +#define VXF_HIDE_VINFO         0x04000000
11066 +
11067 +#define VXF_STATE_SETUP                (1ULL << 32)
11068 +#define VXF_STATE_INIT         (1ULL << 33)
11069 +#define VXF_STATE_ADMIN                (1ULL << 34)
11070 +
11071 +#define VXF_SC_HELPER          (1ULL << 36)
11072 +#define VXF_REBOOT_KILL                (1ULL << 37)
11073 +#define VXF_PERSISTENT         (1ULL << 38)
11074 +
11075 +#define VXF_FORK_RSS           (1ULL << 48)
11076 +#define VXF_PROLIFIC           (1ULL << 49)
11077 +
11078 +#define VXF_IGNEG_NICE         (1ULL << 52)
11079 +
11080 +#define VXF_ONE_TIME           (0x0007ULL << 32)
11081 +
11082 +#define VXF_INIT_SET           (VXF_STATE_SETUP | VXF_STATE_INIT | VXF_STATE_ADMIN)
11083 +
11084 +
11085 +/* context migration */
11086 +
11087 +#define VXM_SET_INIT           0x00000001
11088 +#define VXM_SET_REAPER         0x00000002
11089 +
11090 +/* context caps */
11091 +
11092 +#define VXC_SET_UTSNAME                0x00000001
11093 +#define VXC_SET_RLIMIT         0x00000002
11094 +#define VXC_FS_SECURITY                0x00000004
11095 +#define VXC_FS_TRUSTED         0x00000008
11096 +#define VXC_TIOCSTI            0x00000010
11097 +
11098 +/* was VXC_RAW_ICMP            0x00000100 */
11099 +#define VXC_SYSLOG             0x00001000
11100 +#define VXC_OOM_ADJUST         0x00002000
11101 +#define VXC_AUDIT_CONTROL      0x00004000
11102 +
11103 +#define VXC_SECURE_MOUNT       0x00010000
11104 +#define VXC_SECURE_REMOUNT     0x00020000
11105 +#define VXC_BINARY_MOUNT       0x00040000
11106 +
11107 +#define VXC_QUOTA_CTL          0x00100000
11108 +#define VXC_ADMIN_MAPPER       0x00200000
11109 +#define VXC_ADMIN_CLOOP                0x00400000
11110 +
11111 +#define VXC_KTHREAD            0x01000000
11112 +#define VXC_NAMESPACE          0x02000000
11113 +
11114 +
11115 +#ifdef __KERNEL__
11116 +
11117 +#include <linux/list.h>
11118 +#include <linux/spinlock.h>
11119 +#include <linux/rcupdate.h>
11120 +
11121 +#include "limit_def.h"
11122 +#include "sched_def.h"
11123 +#include "cvirt_def.h"
11124 +#include "cacct_def.h"
11125 +#include "device_def.h"
11126 +
11127 +#define VX_SPACES      2
11128 +
11129 +struct _vx_info_pc {
11130 +       struct _vx_sched_pc sched_pc;
11131 +       struct _vx_cvirt_pc cvirt_pc;
11132 +};
11133 +
11134 +struct _vx_space {
11135 +       unsigned long vx_nsmask;                /* assignment mask */
11136 +       struct nsproxy *vx_nsproxy;             /* private namespaces */
11137 +       struct fs_struct *vx_fs;                /* private namespace fs */
11138 +       const struct cred *vx_cred;             /* task credentials */
11139 +};
11140 +
11141 +struct vx_info {
11142 +       struct hlist_node vx_hlist;             /* linked list of contexts */
11143 +       xid_t vx_id;                            /* context id */
11144 +       atomic_t vx_usecnt;                     /* usage count */
11145 +       atomic_t vx_tasks;                      /* tasks count */
11146 +       struct vx_info *vx_parent;              /* parent context */
11147 +       int vx_state;                           /* context state */
11148 +
11149 +       struct _vx_space space[VX_SPACES];      /* namespace store */
11150 +
11151 +       uint64_t vx_flags;                      /* context flags */
11152 +       uint64_t vx_ccaps;                      /* context caps (vserver) */
11153 +       uint64_t vx_umask;                      /* unshare mask (guest) */
11154 +       uint64_t vx_wmask;                      /* warn mask (guest) */
11155 +       kernel_cap_t vx_bcaps;                  /* bounding caps (system) */
11156 +
11157 +       struct task_struct *vx_reaper;          /* guest reaper process */
11158 +       pid_t vx_initpid;                       /* PID of guest init */
11159 +       int64_t vx_badness_bias;                /* OOM points bias */
11160 +
11161 +       struct _vx_limit limit;                 /* vserver limits */
11162 +       struct _vx_sched sched;                 /* vserver scheduler */
11163 +       struct _vx_cvirt cvirt;                 /* virtual/bias stuff */
11164 +       struct _vx_cacct cacct;                 /* context accounting */
11165 +
11166 +       struct _vx_device dmap;                 /* default device map targets */
11167 +
11168 +#ifndef CONFIG_SMP
11169 +       struct _vx_info_pc info_pc;             /* per cpu data */
11170 +#else
11171 +       struct _vx_info_pc *ptr_pc;             /* per cpu array */
11172 +#endif
11173 +
11174 +       wait_queue_head_t vx_wait;              /* context exit waitqueue */
11175 +       int reboot_cmd;                         /* last sys_reboot() cmd */
11176 +       int exit_code;                          /* last process exit code */
11177 +
11178 +       char vx_name[65];                       /* vserver name */
11179 +};
11180 +
11181 +#ifndef CONFIG_SMP
11182 +#define        vx_ptr_pc(vxi)          (&(vxi)->info_pc)
11183 +#define        vx_per_cpu(vxi, v, id)  vx_ptr_pc(vxi)->v
11184 +#else
11185 +#define        vx_ptr_pc(vxi)          ((vxi)->ptr_pc)
11186 +#define        vx_per_cpu(vxi, v, id)  per_cpu_ptr(vx_ptr_pc(vxi), id)->v
11187 +#endif
11188 +
11189 +#define        vx_cpu(vxi, v)          vx_per_cpu(vxi, v, smp_processor_id())
11190 +
11191 +
11192 +struct vx_info_save {
11193 +       struct vx_info *vxi;
11194 +       xid_t xid;
11195 +};
11196 +
11197 +
11198 +/* status flags */
11199 +
11200 +#define VXS_HASHED     0x0001
11201 +#define VXS_PAUSED     0x0010
11202 +#define VXS_SHUTDOWN   0x0100
11203 +#define VXS_HELPER     0x1000
11204 +#define VXS_RELEASED   0x8000
11205 +
11206 +
11207 +extern void claim_vx_info(struct vx_info *, struct task_struct *);
11208 +extern void release_vx_info(struct vx_info *, struct task_struct *);
11209 +
11210 +extern struct vx_info *lookup_vx_info(int);
11211 +extern struct vx_info *lookup_or_create_vx_info(int);
11212 +
11213 +extern int get_xid_list(int, unsigned int *, int);
11214 +extern int xid_is_hashed(xid_t);
11215 +
11216 +extern int vx_migrate_task(struct task_struct *, struct vx_info *, int);
11217 +
11218 +extern long vs_state_change(struct vx_info *, unsigned int);
11219 +
11220 +
11221 +#endif /* __KERNEL__ */
11222 +#endif /* _VX_CONTEXT_H */
11223 diff -NurpP --minimal linux-3.6.9/include/linux/vserver/context_cmd.h linux-3.6.9-vs2.3.4.4/include/linux/vserver/context_cmd.h
11224 --- linux-3.6.9/include/linux/vserver/context_cmd.h     1970-01-01 01:00:00.000000000 +0100
11225 +++ linux-3.6.9-vs2.3.4.4/include/linux/vserver/context_cmd.h   2012-10-04 18:47:00.000000000 +0200
11226 @@ -0,0 +1,162 @@
11227 +#ifndef _VX_CONTEXT_CMD_H
11228 +#define _VX_CONTEXT_CMD_H
11229 +
11230 +
11231 +/* vinfo commands */
11232 +
11233 +#define VCMD_task_xid          VC_CMD(VINFO, 1, 0)
11234 +
11235 +#ifdef __KERNEL__
11236 +extern int vc_task_xid(uint32_t);
11237 +
11238 +#endif /* __KERNEL__ */
11239 +
11240 +#define VCMD_vx_info           VC_CMD(VINFO, 5, 0)
11241 +
11242 +struct vcmd_vx_info_v0 {
11243 +       uint32_t xid;
11244 +       uint32_t initpid;
11245 +       /* more to come */
11246 +};
11247 +
11248 +#ifdef __KERNEL__
11249 +extern int vc_vx_info(struct vx_info *, void __user *);
11250 +
11251 +#endif /* __KERNEL__ */
11252 +
11253 +#define VCMD_ctx_stat          VC_CMD(VSTAT, 0, 0)
11254 +
11255 +struct vcmd_ctx_stat_v0 {
11256 +       uint32_t usecnt;
11257 +       uint32_t tasks;
11258 +       /* more to come */
11259 +};
11260 +
11261 +#ifdef __KERNEL__
11262 +extern int vc_ctx_stat(struct vx_info *, void __user *);
11263 +
11264 +#endif /* __KERNEL__ */
11265 +
11266 +/* context commands */
11267 +
11268 +#define VCMD_ctx_create_v0     VC_CMD(VPROC, 1, 0)
11269 +#define VCMD_ctx_create                VC_CMD(VPROC, 1, 1)
11270 +
11271 +struct vcmd_ctx_create {
11272 +       uint64_t flagword;
11273 +};
11274 +
11275 +#define VCMD_ctx_migrate_v0    VC_CMD(PROCMIG, 1, 0)
11276 +#define VCMD_ctx_migrate       VC_CMD(PROCMIG, 1, 1)
11277 +
11278 +struct vcmd_ctx_migrate {
11279 +       uint64_t flagword;
11280 +};
11281 +
11282 +#ifdef __KERNEL__
11283 +extern int vc_ctx_create(uint32_t, void __user *);
11284 +extern int vc_ctx_migrate(struct vx_info *, void __user *);
11285 +
11286 +#endif /* __KERNEL__ */
11287 +
11288 +
11289 +/* flag commands */
11290 +
11291 +#define VCMD_get_cflags                VC_CMD(FLAGS, 1, 0)
11292 +#define VCMD_set_cflags                VC_CMD(FLAGS, 2, 0)
11293 +
11294 +struct vcmd_ctx_flags_v0 {
11295 +       uint64_t flagword;
11296 +       uint64_t mask;
11297 +};
11298 +
11299 +#ifdef __KERNEL__
11300 +extern int vc_get_cflags(struct vx_info *, void __user *);
11301 +extern int vc_set_cflags(struct vx_info *, void __user *);
11302 +
11303 +#endif /* __KERNEL__ */
11304 +
11305 +
11306 +/* context caps commands */
11307 +
11308 +#define VCMD_get_ccaps         VC_CMD(FLAGS, 3, 1)
11309 +#define VCMD_set_ccaps         VC_CMD(FLAGS, 4, 1)
11310 +
11311 +struct vcmd_ctx_caps_v1 {
11312 +       uint64_t ccaps;
11313 +       uint64_t cmask;
11314 +};
11315 +
11316 +#ifdef __KERNEL__
11317 +extern int vc_get_ccaps(struct vx_info *, void __user *);
11318 +extern int vc_set_ccaps(struct vx_info *, void __user *);
11319 +
11320 +#endif /* __KERNEL__ */
11321 +
11322 +
11323 +/* bcaps commands */
11324 +
11325 +#define VCMD_get_bcaps         VC_CMD(FLAGS, 9, 0)
11326 +#define VCMD_set_bcaps         VC_CMD(FLAGS, 10, 0)
11327 +
11328 +struct vcmd_bcaps {
11329 +       uint64_t bcaps;
11330 +       uint64_t bmask;
11331 +};
11332 +
11333 +#ifdef __KERNEL__
11334 +extern int vc_get_bcaps(struct vx_info *, void __user *);
11335 +extern int vc_set_bcaps(struct vx_info *, void __user *);
11336 +
11337 +#endif /* __KERNEL__ */
11338 +
11339 +
11340 +/* umask commands */
11341 +
11342 +#define VCMD_get_umask         VC_CMD(FLAGS, 13, 0)
11343 +#define VCMD_set_umask         VC_CMD(FLAGS, 14, 0)
11344 +
11345 +struct vcmd_umask {
11346 +       uint64_t umask;
11347 +       uint64_t mask;
11348 +};
11349 +
11350 +#ifdef __KERNEL__
11351 +extern int vc_get_umask(struct vx_info *, void __user *);
11352 +extern int vc_set_umask(struct vx_info *, void __user *);
11353 +
11354 +#endif /* __KERNEL__ */
11355 +
11356 +
11357 +/* wmask commands */
11358 +
11359 +#define VCMD_get_wmask         VC_CMD(FLAGS, 15, 0)
11360 +#define VCMD_set_wmask         VC_CMD(FLAGS, 16, 0)
11361 +
11362 +struct vcmd_wmask {
11363 +       uint64_t wmask;
11364 +       uint64_t mask;
11365 +};
11366 +
11367 +#ifdef __KERNEL__
11368 +extern int vc_get_wmask(struct vx_info *, void __user *);
11369 +extern int vc_set_wmask(struct vx_info *, void __user *);
11370 +
11371 +#endif /* __KERNEL__ */
11372 +
11373 +
11374 +/* OOM badness */
11375 +
11376 +#define VCMD_get_badness       VC_CMD(MEMCTRL, 5, 0)
11377 +#define VCMD_set_badness       VC_CMD(MEMCTRL, 6, 0)
11378 +
11379 +struct vcmd_badness_v0 {
11380 +       int64_t bias;
11381 +};
11382 +
11383 +#ifdef __KERNEL__
11384 +extern int vc_get_badness(struct vx_info *, void __user *);
11385 +extern int vc_set_badness(struct vx_info *, void __user *);
11386 +
11387 +#endif /* __KERNEL__ */
11388 +#endif /* _VX_CONTEXT_CMD_H */
11389 diff -NurpP --minimal linux-3.6.9/include/linux/vserver/cvirt.h linux-3.6.9-vs2.3.4.4/include/linux/vserver/cvirt.h
11390 --- linux-3.6.9/include/linux/vserver/cvirt.h   1970-01-01 01:00:00.000000000 +0100
11391 +++ linux-3.6.9-vs2.3.4.4/include/linux/vserver/cvirt.h 2012-10-04 18:47:00.000000000 +0200
11392 @@ -0,0 +1,22 @@
11393 +#ifndef _VX_CVIRT_H
11394 +#define _VX_CVIRT_H
11395 +
11396 +
11397 +#ifdef __KERNEL__
11398 +
11399 +struct timespec;
11400 +
11401 +void vx_vsi_boottime(struct timespec *);
11402 +
11403 +void vx_vsi_uptime(struct timespec *, struct timespec *);
11404 +
11405 +
11406 +struct vx_info;
11407 +
11408 +void vx_update_load(struct vx_info *);
11409 +
11410 +
11411 +int vx_do_syslog(int, char __user *, int);
11412 +
11413 +#endif /* __KERNEL__ */
11414 +#endif /* _VX_CVIRT_H */
11415 diff -NurpP --minimal linux-3.6.9/include/linux/vserver/cvirt_cmd.h linux-3.6.9-vs2.3.4.4/include/linux/vserver/cvirt_cmd.h
11416 --- linux-3.6.9/include/linux/vserver/cvirt_cmd.h       1970-01-01 01:00:00.000000000 +0100
11417 +++ linux-3.6.9-vs2.3.4.4/include/linux/vserver/cvirt_cmd.h     2012-10-04 18:47:00.000000000 +0200
11418 @@ -0,0 +1,53 @@
11419 +#ifndef _VX_CVIRT_CMD_H
11420 +#define _VX_CVIRT_CMD_H
11421 +
11422 +
11423 +/* virtual host info name commands */
11424 +
11425 +#define VCMD_set_vhi_name      VC_CMD(VHOST, 1, 0)
11426 +#define VCMD_get_vhi_name      VC_CMD(VHOST, 2, 0)
11427 +
11428 +struct vcmd_vhi_name_v0 {
11429 +       uint32_t field;
11430 +       char name[65];
11431 +};
11432 +
11433 +
11434 +enum vhi_name_field {
11435 +       VHIN_CONTEXT = 0,
11436 +       VHIN_SYSNAME,
11437 +       VHIN_NODENAME,
11438 +       VHIN_RELEASE,
11439 +       VHIN_VERSION,
11440 +       VHIN_MACHINE,
11441 +       VHIN_DOMAINNAME,
11442 +};
11443 +
11444 +
11445 +#ifdef __KERNEL__
11446 +
11447 +#include <linux/compiler.h>
11448 +
11449 +extern int vc_set_vhi_name(struct vx_info *, void __user *);
11450 +extern int vc_get_vhi_name(struct vx_info *, void __user *);
11451 +
11452 +#endif /* __KERNEL__ */
11453 +
11454 +#define VCMD_virt_stat         VC_CMD(VSTAT, 3, 0)
11455 +
11456 +struct vcmd_virt_stat_v0 {
11457 +       uint64_t offset;
11458 +       uint64_t uptime;
11459 +       uint32_t nr_threads;
11460 +       uint32_t nr_running;
11461 +       uint32_t nr_uninterruptible;
11462 +       uint32_t nr_onhold;
11463 +       uint32_t nr_forks;
11464 +       uint32_t load[3];
11465 +};
11466 +
11467 +#ifdef __KERNEL__
11468 +extern int vc_virt_stat(struct vx_info *, void __user *);
11469 +
11470 +#endif /* __KERNEL__ */
11471 +#endif /* _VX_CVIRT_CMD_H */
11472 diff -NurpP --minimal linux-3.6.9/include/linux/vserver/cvirt_def.h linux-3.6.9-vs2.3.4.4/include/linux/vserver/cvirt_def.h
11473 --- linux-3.6.9/include/linux/vserver/cvirt_def.h       1970-01-01 01:00:00.000000000 +0100
11474 +++ linux-3.6.9-vs2.3.4.4/include/linux/vserver/cvirt_def.h     2012-10-04 18:47:00.000000000 +0200
11475 @@ -0,0 +1,80 @@
11476 +#ifndef _VX_CVIRT_DEF_H
11477 +#define _VX_CVIRT_DEF_H
11478 +
11479 +#include <linux/jiffies.h>
11480 +#include <linux/spinlock.h>
11481 +#include <linux/wait.h>
11482 +#include <linux/time.h>
11483 +#include <asm/atomic.h>
11484 +
11485 +
11486 +struct _vx_usage_stat {
11487 +       uint64_t user;
11488 +       uint64_t nice;
11489 +       uint64_t system;
11490 +       uint64_t softirq;
11491 +       uint64_t irq;
11492 +       uint64_t idle;
11493 +       uint64_t iowait;
11494 +};
11495 +
11496 +struct _vx_syslog {
11497 +       wait_queue_head_t log_wait;
11498 +       spinlock_t logbuf_lock;         /* lock for the log buffer */
11499 +
11500 +       unsigned long log_start;        /* next char to be read by syslog() */
11501 +       unsigned long con_start;        /* next char to be sent to consoles */
11502 +       unsigned long log_end;  /* most-recently-written-char + 1 */
11503 +       unsigned long logged_chars;     /* #chars since last read+clear operation */
11504 +
11505 +       char log_buf[1024];
11506 +};
11507 +
11508 +
11509 +/* context sub struct */
11510 +
11511 +struct _vx_cvirt {
11512 +       atomic_t nr_threads;            /* number of current threads */
11513 +       atomic_t nr_running;            /* number of running threads */
11514 +       atomic_t nr_uninterruptible;    /* number of uninterruptible threads */
11515 +
11516 +       atomic_t nr_onhold;             /* processes on hold */
11517 +       uint32_t onhold_last;           /* jiffies when put on hold */
11518 +
11519 +       struct timespec bias_ts;        /* time offset to the host */
11520 +       struct timespec bias_idle;
11521 +       struct timespec bias_uptime;    /* context creation point */
11522 +       uint64_t bias_clock;            /* offset in clock_t */
11523 +
11524 +       spinlock_t load_lock;           /* lock for the load averages */
11525 +       atomic_t load_updates;          /* nr of load updates done so far */
11526 +       uint32_t load_last;             /* last time load was calculated */
11527 +       uint32_t load[3];               /* load averages 1,5,15 */
11528 +
11529 +       atomic_t total_forks;           /* number of forks so far */
11530 +
11531 +       struct _vx_syslog syslog;
11532 +};
11533 +
11534 +struct _vx_cvirt_pc {
11535 +       struct _vx_usage_stat cpustat;
11536 +};
11537 +
11538 +
11539 +#ifdef CONFIG_VSERVER_DEBUG
11540 +
11541 +static inline void __dump_vx_cvirt(struct _vx_cvirt *cvirt)
11542 +{
11543 +       printk("\t_vx_cvirt:\n");
11544 +       printk("\t threads: %4d, %4d, %4d, %4d\n",
11545 +               atomic_read(&cvirt->nr_threads),
11546 +               atomic_read(&cvirt->nr_running),
11547 +               atomic_read(&cvirt->nr_uninterruptible),
11548 +               atomic_read(&cvirt->nr_onhold));
11549 +       /* add rest here */
11550 +       printk("\t total_forks = %d\n", atomic_read(&cvirt->total_forks));
11551 +}
11552 +
11553 +#endif
11554 +
11555 +#endif /* _VX_CVIRT_DEF_H */
11556 diff -NurpP --minimal linux-3.6.9/include/linux/vserver/debug.h linux-3.6.9-vs2.3.4.4/include/linux/vserver/debug.h
11557 --- linux-3.6.9/include/linux/vserver/debug.h   1970-01-01 01:00:00.000000000 +0100
11558 +++ linux-3.6.9-vs2.3.4.4/include/linux/vserver/debug.h 2012-10-04 18:47:00.000000000 +0200
11559 @@ -0,0 +1,145 @@
11560 +#ifndef _VX_DEBUG_H
11561 +#define _VX_DEBUG_H
11562 +
11563 +
11564 +#define VXD_CBIT(n, m) (vs_debug_ ## n & (1 << (m)))
11565 +#define VXD_CMIN(n, m) (vs_debug_ ## n > (m))
11566 +#define VXD_MASK(n, m) (vs_debug_ ## n & (m))
11567 +
11568 +#define VXD_DEV(d)     (d), (d)->bd_inode->i_ino,              \
11569 +                       imajor((d)->bd_inode), iminor((d)->bd_inode)
11570 +#define VXF_DEV                "%p[%lu,%d:%d]"
11571 +
11572 +#if    defined(CONFIG_QUOTES_UTF8)
11573 +#define        VS_Q_LQM        "\xc2\xbb"
11574 +#define        VS_Q_RQM        "\xc2\xab"
11575 +#elif  defined(CONFIG_QUOTES_ASCII)
11576 +#define        VS_Q_LQM        "\x27"
11577 +#define        VS_Q_RQM        "\x27"
11578 +#else
11579 +#define        VS_Q_LQM        "\xbb"
11580 +#define        VS_Q_RQM        "\xab"
11581 +#endif
11582 +
11583 +#define        VS_Q(f)         VS_Q_LQM f VS_Q_RQM
11584 +
11585 +
11586 +#define vxd_path(p)                                            \
11587 +       ({ static char _buffer[PATH_MAX];                       \
11588 +          d_path(p, _buffer, sizeof(_buffer)); })
11589 +
11590 +#define vxd_cond_path(n)                                       \
11591 +       ((n) ? vxd_path(&(n)->path) : "<null>" )
11592 +
11593 +
11594 +#ifdef CONFIG_VSERVER_DEBUG
11595 +
11596 +extern unsigned int vs_debug_switch;
11597 +extern unsigned int vs_debug_xid;
11598 +extern unsigned int vs_debug_nid;
11599 +extern unsigned int vs_debug_tag;
11600 +extern unsigned int vs_debug_net;
11601 +extern unsigned int vs_debug_limit;
11602 +extern unsigned int vs_debug_cres;
11603 +extern unsigned int vs_debug_dlim;
11604 +extern unsigned int vs_debug_quota;
11605 +extern unsigned int vs_debug_cvirt;
11606 +extern unsigned int vs_debug_space;
11607 +extern unsigned int vs_debug_perm;
11608 +extern unsigned int vs_debug_misc;
11609 +
11610 +
11611 +#define VX_LOGLEVEL    "vxD: "
11612 +#define VX_PROC_FMT    "%p: "
11613 +#define VX_PROCESS     current
11614 +
11615 +#define vxdprintk(c, f, x...)                                  \
11616 +       do {                                                    \
11617 +               if (c)                                          \
11618 +                       printk(VX_LOGLEVEL VX_PROC_FMT f "\n",  \
11619 +                               VX_PROCESS , ##x);              \
11620 +       } while (0)
11621 +
11622 +#define vxlprintk(c, f, x...)                                  \
11623 +       do {                                                    \
11624 +               if (c)                                          \
11625 +                       printk(VX_LOGLEVEL f " @%s:%d\n", x);   \
11626 +       } while (0)
11627 +
11628 +#define vxfprintk(c, f, x...)                                  \
11629 +       do {                                                    \
11630 +               if (c)                                          \
11631 +                       printk(VX_LOGLEVEL f " %s@%s:%d\n", x); \
11632 +       } while (0)
11633 +
11634 +
11635 +struct vx_info;
11636 +
11637 +void dump_vx_info(struct vx_info *, int);
11638 +void dump_vx_info_inactive(int);
11639 +
11640 +#else  /* CONFIG_VSERVER_DEBUG */
11641 +
11642 +#define vs_debug_switch        0
11643 +#define vs_debug_xid   0
11644 +#define vs_debug_nid   0
11645 +#define vs_debug_tag   0
11646 +#define vs_debug_net   0
11647 +#define vs_debug_limit 0
11648 +#define vs_debug_cres  0
11649 +#define vs_debug_dlim  0
11650 +#define vs_debug_quota 0
11651 +#define vs_debug_cvirt 0
11652 +#define vs_debug_space 0
11653 +#define vs_debug_perm  0
11654 +#define vs_debug_misc  0
11655 +
11656 +#define vxdprintk(x...) do { } while (0)
11657 +#define vxlprintk(x...) do { } while (0)
11658 +#define vxfprintk(x...) do { } while (0)
11659 +
11660 +#endif /* CONFIG_VSERVER_DEBUG */
11661 +
11662 +
11663 +#ifdef CONFIG_VSERVER_WARN
11664 +
11665 +#define VX_WARNLEVEL   KERN_WARNING "vxW: "
11666 +#define VX_WARN_TASK   "[" VS_Q("%s") ",%u:#%u|%u|%u] "
11667 +#define VX_WARN_XID    "[xid #%u] "
11668 +#define VX_WARN_NID    "[nid #%u] "
11669 +#define VX_WARN_TAG    "[tag #%u] "
11670 +
11671 +#define vxwprintk(c, f, x...)                                  \
11672 +       do {                                                    \
11673 +               if (c)                                          \
11674 +                       printk(VX_WARNLEVEL f "\n", ##x);       \
11675 +       } while (0)
11676 +
11677 +#else  /* CONFIG_VSERVER_WARN */
11678 +
11679 +#define vxwprintk(x...) do { } while (0)
11680 +
11681 +#endif /* CONFIG_VSERVER_WARN */
11682 +
11683 +#define vxwprintk_task(c, f, x...)                             \
11684 +       vxwprintk(c, VX_WARN_TASK f,                            \
11685 +               current->comm, current->pid,                    \
11686 +               current->xid, current->nid, current->tag, ##x)
11687 +#define vxwprintk_xid(c, f, x...)                              \
11688 +       vxwprintk(c, VX_WARN_XID f, current->xid, x)
11689 +#define vxwprintk_nid(c, f, x...)                              \
11690 +       vxwprintk(c, VX_WARN_NID f, current->nid, x)
11691 +#define vxwprintk_tag(c, f, x...)                              \
11692 +       vxwprintk(c, VX_WARN_TAG f, current->tag, x)
11693 +
11694 +#ifdef CONFIG_VSERVER_DEBUG
11695 +#define vxd_assert_lock(l)     assert_spin_locked(l)
11696 +#define vxd_assert(c, f, x...) vxlprintk(!(c), \
11697 +       "assertion [" f "] failed.", ##x, __FILE__, __LINE__)
11698 +#else
11699 +#define vxd_assert_lock(l)     do { } while (0)
11700 +#define vxd_assert(c, f, x...) do { } while (0)
11701 +#endif
11702 +
11703 +
11704 +#endif /* _VX_DEBUG_H */
11705 diff -NurpP --minimal linux-3.6.9/include/linux/vserver/debug_cmd.h linux-3.6.9-vs2.3.4.4/include/linux/vserver/debug_cmd.h
11706 --- linux-3.6.9/include/linux/vserver/debug_cmd.h       1970-01-01 01:00:00.000000000 +0100
11707 +++ linux-3.6.9-vs2.3.4.4/include/linux/vserver/debug_cmd.h     2012-10-04 18:47:00.000000000 +0200
11708 @@ -0,0 +1,58 @@
11709 +#ifndef _VX_DEBUG_CMD_H
11710 +#define _VX_DEBUG_CMD_H
11711 +
11712 +
11713 +/* debug commands */
11714 +
11715 +#define VCMD_dump_history      VC_CMD(DEBUG, 1, 0)
11716 +
11717 +#define VCMD_read_history      VC_CMD(DEBUG, 5, 0)
11718 +#define VCMD_read_monitor      VC_CMD(DEBUG, 6, 0)
11719 +
11720 +struct  vcmd_read_history_v0 {
11721 +       uint32_t index;
11722 +       uint32_t count;
11723 +       char __user *data;
11724 +};
11725 +
11726 +struct  vcmd_read_monitor_v0 {
11727 +       uint32_t index;
11728 +       uint32_t count;
11729 +       char __user *data;
11730 +};
11731 +
11732 +
11733 +#ifdef __KERNEL__
11734 +
11735 +#ifdef CONFIG_COMPAT
11736 +
11737 +#include <asm/compat.h>
11738 +
11739 +struct vcmd_read_history_v0_x32 {
11740 +       uint32_t index;
11741 +       uint32_t count;
11742 +       compat_uptr_t data_ptr;
11743 +};
11744 +
11745 +struct vcmd_read_monitor_v0_x32 {
11746 +       uint32_t index;
11747 +       uint32_t count;
11748 +       compat_uptr_t data_ptr;
11749 +};
11750 +
11751 +#endif  /* CONFIG_COMPAT */
11752 +
11753 +extern int vc_dump_history(uint32_t);
11754 +
11755 +extern int vc_read_history(uint32_t, void __user *);
11756 +extern int vc_read_monitor(uint32_t, void __user *);
11757 +
11758 +#ifdef CONFIG_COMPAT
11759 +
11760 +extern int vc_read_history_x32(uint32_t, void __user *);
11761 +extern int vc_read_monitor_x32(uint32_t, void __user *);
11762 +
11763 +#endif  /* CONFIG_COMPAT */
11764 +
11765 +#endif /* __KERNEL__ */
11766 +#endif /* _VX_DEBUG_CMD_H */
11767 diff -NurpP --minimal linux-3.6.9/include/linux/vserver/device.h linux-3.6.9-vs2.3.4.4/include/linux/vserver/device.h
11768 --- linux-3.6.9/include/linux/vserver/device.h  1970-01-01 01:00:00.000000000 +0100
11769 +++ linux-3.6.9-vs2.3.4.4/include/linux/vserver/device.h        2012-10-04 18:47:00.000000000 +0200
11770 @@ -0,0 +1,15 @@
11771 +#ifndef _VX_DEVICE_H
11772 +#define _VX_DEVICE_H
11773 +
11774 +
11775 +#define DATTR_CREATE   0x00000001
11776 +#define DATTR_OPEN     0x00000002
11777 +
11778 +#define DATTR_REMAP    0x00000010
11779 +
11780 +#define DATTR_MASK     0x00000013
11781 +
11782 +
11783 +#else  /* _VX_DEVICE_H */
11784 +#warning duplicate inclusion
11785 +#endif /* _VX_DEVICE_H */
11786 diff -NurpP --minimal linux-3.6.9/include/linux/vserver/device_cmd.h linux-3.6.9-vs2.3.4.4/include/linux/vserver/device_cmd.h
11787 --- linux-3.6.9/include/linux/vserver/device_cmd.h      1970-01-01 01:00:00.000000000 +0100
11788 +++ linux-3.6.9-vs2.3.4.4/include/linux/vserver/device_cmd.h    2012-10-04 18:47:00.000000000 +0200
11789 @@ -0,0 +1,44 @@
11790 +#ifndef _VX_DEVICE_CMD_H
11791 +#define _VX_DEVICE_CMD_H
11792 +
11793 +
11794 +/*  device vserver commands */
11795 +
11796 +#define VCMD_set_mapping       VC_CMD(DEVICE, 1, 0)
11797 +#define VCMD_unset_mapping     VC_CMD(DEVICE, 2, 0)
11798 +
11799 +struct vcmd_set_mapping_v0 {
11800 +       const char __user *device;
11801 +       const char __user *target;
11802 +       uint32_t flags;
11803 +};
11804 +
11805 +
11806 +#ifdef __KERNEL__
11807 +
11808 +#ifdef CONFIG_COMPAT
11809 +
11810 +#include <asm/compat.h>
11811 +
11812 +struct vcmd_set_mapping_v0_x32 {
11813 +       compat_uptr_t device_ptr;
11814 +       compat_uptr_t target_ptr;
11815 +       uint32_t flags;
11816 +};
11817 +
11818 +#endif /* CONFIG_COMPAT */
11819 +
11820 +#include <linux/compiler.h>
11821 +
11822 +extern int vc_set_mapping(struct vx_info *, void __user *);
11823 +extern int vc_unset_mapping(struct vx_info *, void __user *);
11824 +
11825 +#ifdef CONFIG_COMPAT
11826 +
11827 +extern int vc_set_mapping_x32(struct vx_info *, void __user *);
11828 +extern int vc_unset_mapping_x32(struct vx_info *, void __user *);
11829 +
11830 +#endif /* CONFIG_COMPAT */
11831 +
11832 +#endif /* __KERNEL__ */
11833 +#endif /* _VX_DEVICE_CMD_H */
11834 diff -NurpP --minimal linux-3.6.9/include/linux/vserver/device_def.h linux-3.6.9-vs2.3.4.4/include/linux/vserver/device_def.h
11835 --- linux-3.6.9/include/linux/vserver/device_def.h      1970-01-01 01:00:00.000000000 +0100
11836 +++ linux-3.6.9-vs2.3.4.4/include/linux/vserver/device_def.h    2012-10-04 18:47:00.000000000 +0200
11837 @@ -0,0 +1,17 @@
11838 +#ifndef _VX_DEVICE_DEF_H
11839 +#define _VX_DEVICE_DEF_H
11840 +
11841 +#include <linux/types.h>
11842 +
11843 +struct vx_dmap_target {
11844 +       dev_t target;
11845 +       uint32_t flags;
11846 +};
11847 +
11848 +struct _vx_device {
11849 +#ifdef CONFIG_VSERVER_DEVICE
11850 +       struct vx_dmap_target targets[2];
11851 +#endif
11852 +};
11853 +
11854 +#endif /* _VX_DEVICE_DEF_H */
11855 diff -NurpP --minimal linux-3.6.9/include/linux/vserver/dlimit.h linux-3.6.9-vs2.3.4.4/include/linux/vserver/dlimit.h
11856 --- linux-3.6.9/include/linux/vserver/dlimit.h  1970-01-01 01:00:00.000000000 +0100
11857 +++ linux-3.6.9-vs2.3.4.4/include/linux/vserver/dlimit.h        2012-10-04 18:47:00.000000000 +0200
11858 @@ -0,0 +1,54 @@
11859 +#ifndef _VX_DLIMIT_H
11860 +#define _VX_DLIMIT_H
11861 +
11862 +#include "switch.h"
11863 +
11864 +
11865 +#ifdef __KERNEL__
11866 +
11867 +/*      keep in sync with CDLIM_INFINITY       */
11868 +
11869 +#define DLIM_INFINITY          (~0ULL)
11870 +
11871 +#include <linux/spinlock.h>
11872 +#include <linux/rcupdate.h>
11873 +
11874 +struct super_block;
11875 +
11876 +struct dl_info {
11877 +       struct hlist_node dl_hlist;             /* linked list of contexts */
11878 +       struct rcu_head dl_rcu;                 /* the rcu head */
11879 +       vs_tag_t dl_tag;                                /* context tag */
11880 +       atomic_t dl_usecnt;                     /* usage count */
11881 +       atomic_t dl_refcnt;                     /* reference count */
11882 +
11883 +       struct super_block *dl_sb;              /* associated superblock */
11884 +
11885 +       spinlock_t dl_lock;                     /* protect the values */
11886 +
11887 +       unsigned long long dl_space_used;       /* used space in bytes */
11888 +       unsigned long long dl_space_total;      /* maximum space in bytes */
11889 +       unsigned long dl_inodes_used;           /* used inodes */
11890 +       unsigned long dl_inodes_total;          /* maximum inodes */
11891 +
11892 +       unsigned int dl_nrlmult;                /* non root limit mult */
11893 +};
11894 +
11895 +struct rcu_head;
11896 +
11897 +extern void rcu_free_dl_info(struct rcu_head *);
11898 +extern void unhash_dl_info(struct dl_info *);
11899 +
11900 +extern struct dl_info *locate_dl_info(struct super_block *, vs_tag_t);
11901 +
11902 +
11903 +struct kstatfs;
11904 +
11905 +extern void vx_vsi_statfs(struct super_block *, struct kstatfs *);
11906 +
11907 +typedef uint64_t dlsize_t;
11908 +
11909 +#endif /* __KERNEL__ */
11910 +#else  /* _VX_DLIMIT_H */
11911 +#warning duplicate inclusion
11912 +#endif /* _VX_DLIMIT_H */
11913 diff -NurpP --minimal linux-3.6.9/include/linux/vserver/dlimit_cmd.h linux-3.6.9-vs2.3.4.4/include/linux/vserver/dlimit_cmd.h
11914 --- linux-3.6.9/include/linux/vserver/dlimit_cmd.h      1970-01-01 01:00:00.000000000 +0100
11915 +++ linux-3.6.9-vs2.3.4.4/include/linux/vserver/dlimit_cmd.h    2012-10-04 18:47:00.000000000 +0200
11916 @@ -0,0 +1,109 @@
11917 +#ifndef _VX_DLIMIT_CMD_H
11918 +#define _VX_DLIMIT_CMD_H
11919 +
11920 +
11921 +/*  dlimit vserver commands */
11922 +
11923 +#define VCMD_add_dlimit                VC_CMD(DLIMIT, 1, 0)
11924 +#define VCMD_rem_dlimit                VC_CMD(DLIMIT, 2, 0)
11925 +
11926 +#define VCMD_set_dlimit                VC_CMD(DLIMIT, 5, 0)
11927 +#define VCMD_get_dlimit                VC_CMD(DLIMIT, 6, 0)
11928 +
11929 +struct vcmd_ctx_dlimit_base_v0 {
11930 +       const char __user *name;
11931 +       uint32_t flags;
11932 +};
11933 +
11934 +struct vcmd_ctx_dlimit_v0 {
11935 +       const char __user *name;
11936 +       uint32_t space_used;                    /* used space in kbytes */
11937 +       uint32_t space_total;                   /* maximum space in kbytes */
11938 +       uint32_t inodes_used;                   /* used inodes */
11939 +       uint32_t inodes_total;                  /* maximum inodes */
11940 +       uint32_t reserved;                      /* reserved for root in % */
11941 +       uint32_t flags;
11942 +};
11943 +
11944 +#define CDLIM_UNSET            ((uint32_t)0UL)
11945 +#define CDLIM_INFINITY         ((uint32_t)~0UL)
11946 +#define CDLIM_KEEP             ((uint32_t)~1UL)
11947 +
11948 +#define DLIME_UNIT     0
11949 +#define DLIME_KILO     1
11950 +#define DLIME_MEGA     2
11951 +#define DLIME_GIGA     3
11952 +
11953 +#define DLIMF_SHIFT    0x10
11954 +
11955 +#define DLIMS_USED     0
11956 +#define DLIMS_TOTAL    2
11957 +
11958 +static inline
11959 +uint64_t dlimit_space_32to64(uint32_t val, uint32_t flags, int shift)
11960 +{
11961 +       int exp = (flags & DLIMF_SHIFT) ?
11962 +               (flags >> shift) & DLIME_GIGA : DLIME_KILO;
11963 +       return ((uint64_t)val) << (10 * exp);
11964 +}
11965 +
11966 +static inline
11967 +uint32_t dlimit_space_64to32(uint64_t val, uint32_t *flags, int shift)
11968 +{
11969 +       int exp = 0;
11970 +
11971 +       if (*flags & DLIMF_SHIFT) {
11972 +               while (val > (1LL << 32) && (exp < 3)) {
11973 +                       val >>= 10;
11974 +                       exp++;
11975 +               }
11976 +               *flags &= ~(DLIME_GIGA << shift);
11977 +               *flags |= exp << shift;
11978 +       } else
11979 +               val >>= 10;
11980 +       return val;
11981 +}
11982 +
11983 +#ifdef __KERNEL__
11984 +
11985 +#ifdef CONFIG_COMPAT
11986 +
11987 +#include <asm/compat.h>
11988 +
11989 +struct vcmd_ctx_dlimit_base_v0_x32 {
11990 +       compat_uptr_t name_ptr;
11991 +       uint32_t flags;
11992 +};
11993 +
11994 +struct vcmd_ctx_dlimit_v0_x32 {
11995 +       compat_uptr_t name_ptr;
11996 +       uint32_t space_used;                    /* used space in kbytes */
11997 +       uint32_t space_total;                   /* maximum space in kbytes */
11998 +       uint32_t inodes_used;                   /* used inodes */
11999 +       uint32_t inodes_total;                  /* maximum inodes */
12000 +       uint32_t reserved;                      /* reserved for root in % */
12001 +       uint32_t flags;
12002 +};
12003 +
12004 +#endif /* CONFIG_COMPAT */
12005 +
12006 +#include <linux/compiler.h>
12007 +
12008 +extern int vc_add_dlimit(uint32_t, void __user *);
12009 +extern int vc_rem_dlimit(uint32_t, void __user *);
12010 +
12011 +extern int vc_set_dlimit(uint32_t, void __user *);
12012 +extern int vc_get_dlimit(uint32_t, void __user *);
12013 +
12014 +#ifdef CONFIG_COMPAT
12015 +
12016 +extern int vc_add_dlimit_x32(uint32_t, void __user *);
12017 +extern int vc_rem_dlimit_x32(uint32_t, void __user *);
12018 +
12019 +extern int vc_set_dlimit_x32(uint32_t, void __user *);
12020 +extern int vc_get_dlimit_x32(uint32_t, void __user *);
12021 +
12022 +#endif /* CONFIG_COMPAT */
12023 +
12024 +#endif /* __KERNEL__ */
12025 +#endif /* _VX_DLIMIT_CMD_H */
12026 diff -NurpP --minimal linux-3.6.9/include/linux/vserver/global.h linux-3.6.9-vs2.3.4.4/include/linux/vserver/global.h
12027 --- linux-3.6.9/include/linux/vserver/global.h  1970-01-01 01:00:00.000000000 +0100
12028 +++ linux-3.6.9-vs2.3.4.4/include/linux/vserver/global.h        2012-10-04 18:47:00.000000000 +0200
12029 @@ -0,0 +1,19 @@
12030 +#ifndef _VX_GLOBAL_H
12031 +#define _VX_GLOBAL_H
12032 +
12033 +
12034 +extern atomic_t vx_global_ctotal;
12035 +extern atomic_t vx_global_cactive;
12036 +
12037 +extern atomic_t nx_global_ctotal;
12038 +extern atomic_t nx_global_cactive;
12039 +
12040 +extern atomic_t vs_global_nsproxy;
12041 +extern atomic_t vs_global_fs;
12042 +extern atomic_t vs_global_mnt_ns;
12043 +extern atomic_t vs_global_uts_ns;
12044 +extern atomic_t vs_global_user_ns;
12045 +extern atomic_t vs_global_pid_ns;
12046 +
12047 +
12048 +#endif /* _VX_GLOBAL_H */
12049 diff -NurpP --minimal linux-3.6.9/include/linux/vserver/history.h linux-3.6.9-vs2.3.4.4/include/linux/vserver/history.h
12050 --- linux-3.6.9/include/linux/vserver/history.h 1970-01-01 01:00:00.000000000 +0100
12051 +++ linux-3.6.9-vs2.3.4.4/include/linux/vserver/history.h       2012-10-04 18:47:00.000000000 +0200
12052 @@ -0,0 +1,197 @@
12053 +#ifndef _VX_HISTORY_H
12054 +#define _VX_HISTORY_H
12055 +
12056 +
12057 +enum {
12058 +       VXH_UNUSED = 0,
12059 +       VXH_THROW_OOPS = 1,
12060 +
12061 +       VXH_GET_VX_INFO,
12062 +       VXH_PUT_VX_INFO,
12063 +       VXH_INIT_VX_INFO,
12064 +       VXH_SET_VX_INFO,
12065 +       VXH_CLR_VX_INFO,
12066 +       VXH_CLAIM_VX_INFO,
12067 +       VXH_RELEASE_VX_INFO,
12068 +       VXH_ALLOC_VX_INFO,
12069 +       VXH_DEALLOC_VX_INFO,
12070 +       VXH_HASH_VX_INFO,
12071 +       VXH_UNHASH_VX_INFO,
12072 +       VXH_LOC_VX_INFO,
12073 +       VXH_LOOKUP_VX_INFO,
12074 +       VXH_CREATE_VX_INFO,
12075 +};
12076 +
12077 +struct _vxhe_vxi {
12078 +       struct vx_info *ptr;
12079 +       unsigned xid;
12080 +       unsigned usecnt;
12081 +       unsigned tasks;
12082 +};
12083 +
12084 +struct _vxhe_set_clr {
12085 +       void *data;
12086 +};
12087 +
12088 +struct _vxhe_loc_lookup {
12089 +       unsigned arg;
12090 +};
12091 +
12092 +struct _vx_hist_entry {
12093 +       void *loc;
12094 +       unsigned short seq;
12095 +       unsigned short type;
12096 +       struct _vxhe_vxi vxi;
12097 +       union {
12098 +               struct _vxhe_set_clr sc;
12099 +               struct _vxhe_loc_lookup ll;
12100 +       };
12101 +};
12102 +
12103 +#ifdef CONFIG_VSERVER_HISTORY
12104 +
12105 +extern unsigned volatile int vxh_active;
12106 +
12107 +struct _vx_hist_entry *vxh_advance(void *loc);
12108 +
12109 +
12110 +static inline
12111 +void   __vxh_copy_vxi(struct _vx_hist_entry *entry, struct vx_info *vxi)
12112 +{
12113 +       entry->vxi.ptr = vxi;
12114 +       if (vxi) {
12115 +               entry->vxi.usecnt = atomic_read(&vxi->vx_usecnt);
12116 +               entry->vxi.tasks = atomic_read(&vxi->vx_tasks);
12117 +               entry->vxi.xid = vxi->vx_id;
12118 +       }
12119 +}
12120 +
12121 +
12122 +#define        __HERE__ current_text_addr()
12123 +
12124 +#define __VXH_BODY(__type, __data, __here)     \
12125 +       struct _vx_hist_entry *entry;           \
12126 +                                               \
12127 +       preempt_disable();                      \
12128 +       entry = vxh_advance(__here);            \
12129 +       __data;                                 \
12130 +       entry->type = __type;                   \
12131 +       preempt_enable();
12132 +
12133 +
12134 +       /* pass vxi only */
12135 +
12136 +#define __VXH_SMPL                             \
12137 +       __vxh_copy_vxi(entry, vxi)
12138 +
12139 +static inline
12140 +void   __vxh_smpl(struct vx_info *vxi, int __type, void *__here)
12141 +{
12142 +       __VXH_BODY(__type, __VXH_SMPL, __here)
12143 +}
12144 +
12145 +       /* pass vxi and data (void *) */
12146 +
12147 +#define __VXH_DATA                             \
12148 +       __vxh_copy_vxi(entry, vxi);             \
12149 +       entry->sc.data = data
12150 +
12151 +static inline
12152 +void   __vxh_data(struct vx_info *vxi, void *data,
12153 +                       int __type, void *__here)
12154 +{
12155 +       __VXH_BODY(__type, __VXH_DATA, __here)
12156 +}
12157 +
12158 +       /* pass vxi and arg (long) */
12159 +
12160 +#define __VXH_LONG                             \
12161 +       __vxh_copy_vxi(entry, vxi);             \
12162 +       entry->ll.arg = arg
12163 +
12164 +static inline
12165 +void   __vxh_long(struct vx_info *vxi, long arg,
12166 +                       int __type, void *__here)
12167 +{
12168 +       __VXH_BODY(__type, __VXH_LONG, __here)
12169 +}
12170 +
12171 +
12172 +static inline
12173 +void   __vxh_throw_oops(void *__here)
12174 +{
12175 +       __VXH_BODY(VXH_THROW_OOPS, {}, __here);
12176 +       /* prevent further acquisition */
12177 +       vxh_active = 0;
12178 +}
12179 +
12180 +
12181 +#define vxh_throw_oops()       __vxh_throw_oops(__HERE__);
12182 +
12183 +#define __vxh_get_vx_info(v, h)        __vxh_smpl(v, VXH_GET_VX_INFO, h);
12184 +#define __vxh_put_vx_info(v, h)        __vxh_smpl(v, VXH_PUT_VX_INFO, h);
12185 +
12186 +#define __vxh_init_vx_info(v, d, h) \
12187 +       __vxh_data(v, d, VXH_INIT_VX_INFO, h);
12188 +#define __vxh_set_vx_info(v, d, h) \
12189 +       __vxh_data(v, d, VXH_SET_VX_INFO, h);
12190 +#define __vxh_clr_vx_info(v, d, h) \
12191 +       __vxh_data(v, d, VXH_CLR_VX_INFO, h);
12192 +
12193 +#define __vxh_claim_vx_info(v, d, h) \
12194 +       __vxh_data(v, d, VXH_CLAIM_VX_INFO, h);
12195 +#define __vxh_release_vx_info(v, d, h) \
12196 +       __vxh_data(v, d, VXH_RELEASE_VX_INFO, h);
12197 +
12198 +#define vxh_alloc_vx_info(v) \
12199 +       __vxh_smpl(v, VXH_ALLOC_VX_INFO, __HERE__);
12200 +#define vxh_dealloc_vx_info(v) \
12201 +       __vxh_smpl(v, VXH_DEALLOC_VX_INFO, __HERE__);
12202 +
12203 +#define vxh_hash_vx_info(v) \
12204 +       __vxh_smpl(v, VXH_HASH_VX_INFO, __HERE__);
12205 +#define vxh_unhash_vx_info(v) \
12206 +       __vxh_smpl(v, VXH_UNHASH_VX_INFO, __HERE__);
12207 +
12208 +#define vxh_loc_vx_info(v, l) \
12209 +       __vxh_long(v, l, VXH_LOC_VX_INFO, __HERE__);
12210 +#define vxh_lookup_vx_info(v, l) \
12211 +       __vxh_long(v, l, VXH_LOOKUP_VX_INFO, __HERE__);
12212 +#define vxh_create_vx_info(v, l) \
12213 +       __vxh_long(v, l, VXH_CREATE_VX_INFO, __HERE__);
12214 +
12215 +extern void vxh_dump_history(void);
12216 +
12217 +
12218 +#else  /* CONFIG_VSERVER_HISTORY */
12219 +
12220 +#define        __HERE__        0
12221 +
12222 +#define vxh_throw_oops()               do { } while (0)
12223 +
12224 +#define __vxh_get_vx_info(v, h)                do { } while (0)
12225 +#define __vxh_put_vx_info(v, h)                do { } while (0)
12226 +
12227 +#define __vxh_init_vx_info(v, d, h)    do { } while (0)
12228 +#define __vxh_set_vx_info(v, d, h)     do { } while (0)
12229 +#define __vxh_clr_vx_info(v, d, h)     do { } while (0)
12230 +
12231 +#define __vxh_claim_vx_info(v, d, h)   do { } while (0)
12232 +#define __vxh_release_vx_info(v, d, h) do { } while (0)
12233 +
12234 +#define vxh_alloc_vx_info(v)           do { } while (0)
12235 +#define vxh_dealloc_vx_info(v)         do { } while (0)
12236 +
12237 +#define vxh_hash_vx_info(v)            do { } while (0)
12238 +#define vxh_unhash_vx_info(v)          do { } while (0)
12239 +
12240 +#define vxh_loc_vx_info(v, l)          do { } while (0)
12241 +#define vxh_lookup_vx_info(v, l)       do { } while (0)
12242 +#define vxh_create_vx_info(v, l)       do { } while (0)
12243 +
12244 +#define vxh_dump_history()             do { } while (0)
12245 +
12246 +
12247 +#endif /* CONFIG_VSERVER_HISTORY */
12248 +
12249 +#endif /* _VX_HISTORY_H */
12250 diff -NurpP --minimal linux-3.6.9/include/linux/vserver/inode.h linux-3.6.9-vs2.3.4.4/include/linux/vserver/inode.h
12251 --- linux-3.6.9/include/linux/vserver/inode.h   1970-01-01 01:00:00.000000000 +0100
12252 +++ linux-3.6.9-vs2.3.4.4/include/linux/vserver/inode.h 2012-10-04 18:47:00.000000000 +0200
12253 @@ -0,0 +1,39 @@
12254 +#ifndef _VX_INODE_H
12255 +#define _VX_INODE_H
12256 +
12257 +
12258 +#define IATTR_TAG      0x01000000
12259 +
12260 +#define IATTR_ADMIN    0x00000001
12261 +#define IATTR_WATCH    0x00000002
12262 +#define IATTR_HIDE     0x00000004
12263 +#define IATTR_FLAGS    0x00000007
12264 +
12265 +#define IATTR_BARRIER  0x00010000
12266 +#define IATTR_IXUNLINK 0x00020000
12267 +#define IATTR_IMMUTABLE 0x00040000
12268 +#define IATTR_COW      0x00080000
12269 +
12270 +#ifdef __KERNEL__
12271 +
12272 +
12273 +#ifdef CONFIG_VSERVER_PROC_SECURE
12274 +#define IATTR_PROC_DEFAULT     ( IATTR_ADMIN | IATTR_HIDE )
12275 +#define IATTR_PROC_SYMLINK     ( IATTR_ADMIN )
12276 +#else
12277 +#define IATTR_PROC_DEFAULT     ( IATTR_ADMIN )
12278 +#define IATTR_PROC_SYMLINK     ( IATTR_ADMIN )
12279 +#endif
12280 +
12281 +#define vx_hide_check(c, m)    (((m) & IATTR_HIDE) ? vx_check(c, m) : 1)
12282 +
12283 +#endif /* __KERNEL__ */
12284 +
12285 +/* inode ioctls */
12286 +
12287 +#define FIOC_GETXFLG   _IOR('x', 5, long)
12288 +#define FIOC_SETXFLG   _IOW('x', 6, long)
12289 +
12290 +#else  /* _VX_INODE_H */
12291 +#warning duplicate inclusion
12292 +#endif /* _VX_INODE_H */
12293 diff -NurpP --minimal linux-3.6.9/include/linux/vserver/inode_cmd.h linux-3.6.9-vs2.3.4.4/include/linux/vserver/inode_cmd.h
12294 --- linux-3.6.9/include/linux/vserver/inode_cmd.h       1970-01-01 01:00:00.000000000 +0100
12295 +++ linux-3.6.9-vs2.3.4.4/include/linux/vserver/inode_cmd.h     2012-10-04 18:47:00.000000000 +0200
12296 @@ -0,0 +1,59 @@
12297 +#ifndef _VX_INODE_CMD_H
12298 +#define _VX_INODE_CMD_H
12299 +
12300 +
12301 +/*  inode vserver commands */
12302 +
12303 +#define VCMD_get_iattr         VC_CMD(INODE, 1, 1)
12304 +#define VCMD_set_iattr         VC_CMD(INODE, 2, 1)
12305 +
12306 +#define VCMD_fget_iattr                VC_CMD(INODE, 3, 0)
12307 +#define VCMD_fset_iattr                VC_CMD(INODE, 4, 0)
12308 +
12309 +struct vcmd_ctx_iattr_v1 {
12310 +       const char __user *name;
12311 +       uint32_t tag;
12312 +       uint32_t flags;
12313 +       uint32_t mask;
12314 +};
12315 +
12316 +struct vcmd_ctx_fiattr_v0 {
12317 +       uint32_t tag;
12318 +       uint32_t flags;
12319 +       uint32_t mask;
12320 +};
12321 +
12322 +
12323 +#ifdef __KERNEL__
12324 +
12325 +
12326 +#ifdef CONFIG_COMPAT
12327 +
12328 +#include <asm/compat.h>
12329 +
12330 +struct vcmd_ctx_iattr_v1_x32 {
12331 +       compat_uptr_t name_ptr;
12332 +       uint32_t tag;
12333 +       uint32_t flags;
12334 +       uint32_t mask;
12335 +};
12336 +
12337 +#endif /* CONFIG_COMPAT */
12338 +
12339 +#include <linux/compiler.h>
12340 +
12341 +extern int vc_get_iattr(void __user *);
12342 +extern int vc_set_iattr(void __user *);
12343 +
12344 +extern int vc_fget_iattr(uint32_t, void __user *);
12345 +extern int vc_fset_iattr(uint32_t, void __user *);
12346 +
12347 +#ifdef CONFIG_COMPAT
12348 +
12349 +extern int vc_get_iattr_x32(void __user *);
12350 +extern int vc_set_iattr_x32(void __user *);
12351 +
12352 +#endif /* CONFIG_COMPAT */
12353 +
12354 +#endif /* __KERNEL__ */
12355 +#endif /* _VX_INODE_CMD_H */
12356 diff -NurpP --minimal linux-3.6.9/include/linux/vserver/limit.h linux-3.6.9-vs2.3.4.4/include/linux/vserver/limit.h
12357 --- linux-3.6.9/include/linux/vserver/limit.h   1970-01-01 01:00:00.000000000 +0100
12358 +++ linux-3.6.9-vs2.3.4.4/include/linux/vserver/limit.h 2012-10-04 18:47:00.000000000 +0200
12359 @@ -0,0 +1,71 @@
12360 +#ifndef _VX_LIMIT_H
12361 +#define _VX_LIMIT_H
12362 +
12363 +#define VLIMIT_NSOCK   16
12364 +#define VLIMIT_OPENFD  17
12365 +#define VLIMIT_ANON    18
12366 +#define VLIMIT_SHMEM   19
12367 +#define VLIMIT_SEMARY  20
12368 +#define VLIMIT_NSEMS   21
12369 +#define VLIMIT_DENTRY  22
12370 +#define VLIMIT_MAPPED  23
12371 +
12372 +
12373 +#ifdef __KERNEL__
12374 +
12375 +#define        VLIM_NOCHECK    ((1L << VLIMIT_DENTRY) | (1L << RLIMIT_RSS))
12376 +
12377 +/*     keep in sync with CRLIM_INFINITY */
12378 +
12379 +#define        VLIM_INFINITY   (~0ULL)
12380 +
12381 +#include <asm/atomic.h>
12382 +#include <asm/resource.h>
12383 +
12384 +#ifndef RLIM_INFINITY
12385 +#warning RLIM_INFINITY is undefined
12386 +#endif
12387 +
12388 +#define __rlim_val(l, r, v)    ((l)->res[r].v)
12389 +
12390 +#define __rlim_soft(l, r)      __rlim_val(l, r, soft)
12391 +#define __rlim_hard(l, r)      __rlim_val(l, r, hard)
12392 +
12393 +#define __rlim_rcur(l, r)      __rlim_val(l, r, rcur)
12394 +#define __rlim_rmin(l, r)      __rlim_val(l, r, rmin)
12395 +#define __rlim_rmax(l, r)      __rlim_val(l, r, rmax)
12396 +
12397 +#define __rlim_lhit(l, r)      __rlim_val(l, r, lhit)
12398 +#define __rlim_hit(l, r)       atomic_inc(&__rlim_lhit(l, r))
12399 +
12400 +typedef atomic_long_t rlim_atomic_t;
12401 +typedef unsigned long rlim_t;
12402 +
12403 +#define __rlim_get(l, r)       atomic_long_read(&__rlim_rcur(l, r))
12404 +#define __rlim_set(l, r, v)    atomic_long_set(&__rlim_rcur(l, r), v)
12405 +#define __rlim_inc(l, r)       atomic_long_inc(&__rlim_rcur(l, r))
12406 +#define __rlim_dec(l, r)       atomic_long_dec(&__rlim_rcur(l, r))
12407 +#define __rlim_add(l, r, v)    atomic_long_add(v, &__rlim_rcur(l, r))
12408 +#define __rlim_sub(l, r, v)    atomic_long_sub(v, &__rlim_rcur(l, r))
12409 +
12410 +
12411 +#if    (RLIM_INFINITY == VLIM_INFINITY)
12412 +#define        VX_VLIM(r) ((long long)(long)(r))
12413 +#define        VX_RLIM(v) ((rlim_t)(v))
12414 +#else
12415 +#define        VX_VLIM(r) (((r) == RLIM_INFINITY) \
12416 +               ? VLIM_INFINITY : (long long)(r))
12417 +#define        VX_RLIM(v) (((v) == VLIM_INFINITY) \
12418 +               ? RLIM_INFINITY : (rlim_t)(v))
12419 +#endif
12420 +
12421 +struct sysinfo;
12422 +
12423 +void vx_vsi_meminfo(struct sysinfo *);
12424 +void vx_vsi_swapinfo(struct sysinfo *);
12425 +long vx_vsi_cached(struct sysinfo *);
12426 +
12427 +#define NUM_LIMITS     24
12428 +
12429 +#endif /* __KERNEL__ */
12430 +#endif /* _VX_LIMIT_H */
12431 diff -NurpP --minimal linux-3.6.9/include/linux/vserver/limit_cmd.h linux-3.6.9-vs2.3.4.4/include/linux/vserver/limit_cmd.h
12432 --- linux-3.6.9/include/linux/vserver/limit_cmd.h       1970-01-01 01:00:00.000000000 +0100
12433 +++ linux-3.6.9-vs2.3.4.4/include/linux/vserver/limit_cmd.h     2012-10-04 18:47:00.000000000 +0200
12434 @@ -0,0 +1,71 @@
12435 +#ifndef _VX_LIMIT_CMD_H
12436 +#define _VX_LIMIT_CMD_H
12437 +
12438 +
12439 +/*  rlimit vserver commands */
12440 +
12441 +#define VCMD_get_rlimit                VC_CMD(RLIMIT, 1, 0)
12442 +#define VCMD_set_rlimit                VC_CMD(RLIMIT, 2, 0)
12443 +#define VCMD_get_rlimit_mask   VC_CMD(RLIMIT, 3, 0)
12444 +#define VCMD_reset_hits                VC_CMD(RLIMIT, 7, 0)
12445 +#define VCMD_reset_minmax      VC_CMD(RLIMIT, 9, 0)
12446 +
12447 +struct vcmd_ctx_rlimit_v0 {
12448 +       uint32_t id;
12449 +       uint64_t minimum;
12450 +       uint64_t softlimit;
12451 +       uint64_t maximum;
12452 +};
12453 +
12454 +struct vcmd_ctx_rlimit_mask_v0 {
12455 +       uint32_t minimum;
12456 +       uint32_t softlimit;
12457 +       uint32_t maximum;
12458 +};
12459 +
12460 +#define VCMD_rlimit_stat       VC_CMD(VSTAT, 1, 0)
12461 +
12462 +struct vcmd_rlimit_stat_v0 {
12463 +       uint32_t id;
12464 +       uint32_t hits;
12465 +       uint64_t value;
12466 +       uint64_t minimum;
12467 +       uint64_t maximum;
12468 +};
12469 +
12470 +#define CRLIM_UNSET            (0ULL)
12471 +#define CRLIM_INFINITY         (~0ULL)
12472 +#define CRLIM_KEEP             (~1ULL)
12473 +
12474 +#ifdef __KERNEL__
12475 +
12476 +#ifdef CONFIG_IA32_EMULATION
12477 +
12478 +struct vcmd_ctx_rlimit_v0_x32 {
12479 +       uint32_t id;
12480 +       uint64_t minimum;
12481 +       uint64_t softlimit;
12482 +       uint64_t maximum;
12483 +} __attribute__ ((packed));
12484 +
12485 +#endif /* CONFIG_IA32_EMULATION */
12486 +
12487 +#include <linux/compiler.h>
12488 +
12489 +extern int vc_get_rlimit_mask(uint32_t, void __user *);
12490 +extern int vc_get_rlimit(struct vx_info *, void __user *);
12491 +extern int vc_set_rlimit(struct vx_info *, void __user *);
12492 +extern int vc_reset_hits(struct vx_info *, void __user *);
12493 +extern int vc_reset_minmax(struct vx_info *, void __user *);
12494 +
12495 +extern int vc_rlimit_stat(struct vx_info *, void __user *);
12496 +
12497 +#ifdef CONFIG_IA32_EMULATION
12498 +
12499 +extern int vc_get_rlimit_x32(struct vx_info *, void __user *);
12500 +extern int vc_set_rlimit_x32(struct vx_info *, void __user *);
12501 +
12502 +#endif /* CONFIG_IA32_EMULATION */
12503 +
12504 +#endif /* __KERNEL__ */
12505 +#endif /* _VX_LIMIT_CMD_H */
12506 diff -NurpP --minimal linux-3.6.9/include/linux/vserver/limit_def.h linux-3.6.9-vs2.3.4.4/include/linux/vserver/limit_def.h
12507 --- linux-3.6.9/include/linux/vserver/limit_def.h       1970-01-01 01:00:00.000000000 +0100
12508 +++ linux-3.6.9-vs2.3.4.4/include/linux/vserver/limit_def.h     2012-10-04 18:47:00.000000000 +0200
12509 @@ -0,0 +1,47 @@
12510 +#ifndef _VX_LIMIT_DEF_H
12511 +#define _VX_LIMIT_DEF_H
12512 +
12513 +#include <asm/atomic.h>
12514 +#include <asm/resource.h>
12515 +
12516 +#include "limit.h"
12517 +
12518 +
12519 +struct _vx_res_limit {
12520 +       rlim_t soft;            /* Context soft limit */
12521 +       rlim_t hard;            /* Context hard limit */
12522 +
12523 +       rlim_atomic_t rcur;     /* Current value */
12524 +       rlim_t rmin;            /* Context minimum */
12525 +       rlim_t rmax;            /* Context maximum */
12526 +
12527 +       atomic_t lhit;          /* Limit hits */
12528 +};
12529 +
12530 +/* context sub struct */
12531 +
12532 +struct _vx_limit {
12533 +       struct _vx_res_limit res[NUM_LIMITS];
12534 +};
12535 +
12536 +#ifdef CONFIG_VSERVER_DEBUG
12537 +
12538 +static inline void __dump_vx_limit(struct _vx_limit *limit)
12539 +{
12540 +       int i;
12541 +
12542 +       printk("\t_vx_limit:");
12543 +       for (i = 0; i < NUM_LIMITS; i++) {
12544 +               printk("\t [%2d] = %8lu %8lu/%8lu, %8ld/%8ld, %8d\n",
12545 +                       i, (unsigned long)__rlim_get(limit, i),
12546 +                       (unsigned long)__rlim_rmin(limit, i),
12547 +                       (unsigned long)__rlim_rmax(limit, i),
12548 +                       (long)__rlim_soft(limit, i),
12549 +                       (long)__rlim_hard(limit, i),
12550 +                       atomic_read(&__rlim_lhit(limit, i)));
12551 +       }
12552 +}
12553 +
12554 +#endif
12555 +
12556 +#endif /* _VX_LIMIT_DEF_H */
12557 diff -NurpP --minimal linux-3.6.9/include/linux/vserver/limit_int.h linux-3.6.9-vs2.3.4.4/include/linux/vserver/limit_int.h
12558 --- linux-3.6.9/include/linux/vserver/limit_int.h       1970-01-01 01:00:00.000000000 +0100
12559 +++ linux-3.6.9-vs2.3.4.4/include/linux/vserver/limit_int.h     2012-10-04 18:47:00.000000000 +0200
12560 @@ -0,0 +1,198 @@
12561 +#ifndef _VX_LIMIT_INT_H
12562 +#define _VX_LIMIT_INT_H
12563 +
12564 +#include "context.h"
12565 +
12566 +#ifdef __KERNEL__
12567 +
12568 +#define VXD_RCRES_COND(r)      VXD_CBIT(cres, r)
12569 +#define VXD_RLIMIT_COND(r)     VXD_CBIT(limit, r)
12570 +
12571 +extern const char *vlimit_name[NUM_LIMITS];
12572 +
12573 +static inline void __vx_acc_cres(struct vx_info *vxi,
12574 +       int res, int dir, void *_data, char *_file, int _line)
12575 +{
12576 +       if (VXD_RCRES_COND(res))
12577 +               vxlprintk(1, "vx_acc_cres[%5d,%s,%2d]: %5ld%s (%p)",
12578 +                       (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
12579 +                       (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
12580 +                       (dir > 0) ? "++" : "--", _data, _file, _line);
12581 +       if (!vxi)
12582 +               return;
12583 +
12584 +       if (dir > 0)
12585 +               __rlim_inc(&vxi->limit, res);
12586 +       else
12587 +               __rlim_dec(&vxi->limit, res);
12588 +}
12589 +
12590 +static inline void __vx_add_cres(struct vx_info *vxi,
12591 +       int res, int amount, void *_data, char *_file, int _line)
12592 +{
12593 +       if (VXD_RCRES_COND(res))
12594 +               vxlprintk(1, "vx_add_cres[%5d,%s,%2d]: %5ld += %5d (%p)",
12595 +                       (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
12596 +                       (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
12597 +                       amount, _data, _file, _line);
12598 +       if (amount == 0)
12599 +               return;
12600 +       if (!vxi)
12601 +               return;
12602 +       __rlim_add(&vxi->limit, res, amount);
12603 +}
12604 +
12605 +static inline
12606 +int __vx_cres_adjust_max(struct _vx_limit *limit, int res, rlim_t value)
12607 +{
12608 +       int cond = (value > __rlim_rmax(limit, res));
12609 +
12610 +       if (cond)
12611 +               __rlim_rmax(limit, res) = value;
12612 +       return cond;
12613 +}
12614 +
12615 +static inline
12616 +int __vx_cres_adjust_min(struct _vx_limit *limit, int res, rlim_t value)
12617 +{
12618 +       int cond = (value < __rlim_rmin(limit, res));
12619 +
12620 +       if (cond)
12621 +               __rlim_rmin(limit, res) = value;
12622 +       return cond;
12623 +}
12624 +
12625 +static inline
12626 +void __vx_cres_fixup(struct _vx_limit *limit, int res, rlim_t value)
12627 +{
12628 +       if (!__vx_cres_adjust_max(limit, res, value))
12629 +               __vx_cres_adjust_min(limit, res, value);
12630 +}
12631 +
12632 +
12633 +/*     return values:
12634 +        +1 ... no limit hit
12635 +        -1 ... over soft limit
12636 +         0 ... over hard limit         */
12637 +
12638 +static inline int __vx_cres_avail(struct vx_info *vxi,
12639 +       int res, int num, char *_file, int _line)
12640 +{
12641 +       struct _vx_limit *limit;
12642 +       rlim_t value;
12643 +
12644 +       if (VXD_RLIMIT_COND(res))
12645 +               vxlprintk(1, "vx_cres_avail[%5d,%s,%2d]: %5ld/%5ld > %5ld + %5d",
12646 +                       (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
12647 +                       (vxi ? (long)__rlim_soft(&vxi->limit, res) : -1),
12648 +                       (vxi ? (long)__rlim_hard(&vxi->limit, res) : -1),
12649 +                       (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
12650 +                       num, _file, _line);
12651 +       if (!vxi)
12652 +               return 1;
12653 +
12654 +       limit = &vxi->limit;
12655 +       value = __rlim_get(limit, res);
12656 +
12657 +       if (!__vx_cres_adjust_max(limit, res, value))
12658 +               __vx_cres_adjust_min(limit, res, value);
12659 +
12660 +       if (num == 0)
12661 +               return 1;
12662 +
12663 +       if (__rlim_soft(limit, res) == RLIM_INFINITY)
12664 +               return -1;
12665 +       if (value + num <= __rlim_soft(limit, res))
12666 +               return -1;
12667 +
12668 +       if (__rlim_hard(limit, res) == RLIM_INFINITY)
12669 +               return 1;
12670 +       if (value + num <= __rlim_hard(limit, res))
12671 +               return 1;
12672 +
12673 +       __rlim_hit(limit, res);
12674 +       return 0;
12675 +}
12676 +
12677 +
12678 +static const int VLA_RSS[] = { RLIMIT_RSS, VLIMIT_ANON, VLIMIT_MAPPED, 0 };
12679 +
12680 +static inline
12681 +rlim_t __vx_cres_array_sum(struct _vx_limit *limit, const int *array)
12682 +{
12683 +       rlim_t value, sum = 0;
12684 +       int res;
12685 +
12686 +       while ((res = *array++)) {
12687 +               value = __rlim_get(limit, res);
12688 +               __vx_cres_fixup(limit, res, value);
12689 +               sum += value;
12690 +       }
12691 +       return sum;
12692 +}
12693 +
12694 +static inline
12695 +rlim_t __vx_cres_array_fixup(struct _vx_limit *limit, const int *array)
12696 +{
12697 +       rlim_t value = __vx_cres_array_sum(limit, array + 1);
12698 +       int res = *array;
12699 +
12700 +       if (value == __rlim_get(limit, res))
12701 +               return value;
12702 +
12703 +       __rlim_set(limit, res, value);
12704 +       /* now adjust min/max */
12705 +       if (!__vx_cres_adjust_max(limit, res, value))
12706 +               __vx_cres_adjust_min(limit, res, value);
12707 +
12708 +       return value;
12709 +}
12710 +
12711 +static inline int __vx_cres_array_avail(struct vx_info *vxi,
12712 +       const int *array, int num, char *_file, int _line)
12713 +{
12714 +       struct _vx_limit *limit;
12715 +       rlim_t value = 0;
12716 +       int res;
12717 +
12718 +       if (num == 0)
12719 +               return 1;
12720 +       if (!vxi)
12721 +               return 1;
12722 +
12723 +       limit = &vxi->limit;
12724 +       res = *array;
12725 +       value = __vx_cres_array_sum(limit, array + 1);
12726 +
12727 +       __rlim_set(limit, res, value);
12728 +       __vx_cres_fixup(limit, res, value);
12729 +
12730 +       return __vx_cres_avail(vxi, res, num, _file, _line);
12731 +}
12732 +
12733 +
12734 +static inline void vx_limit_fixup(struct _vx_limit *limit, int id)
12735 +{
12736 +       rlim_t value;
12737 +       int res;
12738 +
12739 +       /* complex resources first */
12740 +       if ((id < 0) || (id == RLIMIT_RSS))
12741 +               __vx_cres_array_fixup(limit, VLA_RSS);
12742 +
12743 +       for (res = 0; res < NUM_LIMITS; res++) {
12744 +               if ((id > 0) && (res != id))
12745 +                       continue;
12746 +
12747 +               value = __rlim_get(limit, res);
12748 +               __vx_cres_fixup(limit, res, value);
12749 +
12750 +               /* not supposed to happen, maybe warn? */
12751 +               if (__rlim_rmax(limit, res) > __rlim_hard(limit, res))
12752 +                       __rlim_rmax(limit, res) = __rlim_hard(limit, res);
12753 +       }
12754 +}
12755 +
12756 +
12757 +#endif /* __KERNEL__ */
12758 +#endif /* _VX_LIMIT_INT_H */
12759 diff -NurpP --minimal linux-3.6.9/include/linux/vserver/monitor.h linux-3.6.9-vs2.3.4.4/include/linux/vserver/monitor.h
12760 --- linux-3.6.9/include/linux/vserver/monitor.h 1970-01-01 01:00:00.000000000 +0100
12761 +++ linux-3.6.9-vs2.3.4.4/include/linux/vserver/monitor.h       2012-10-04 18:47:00.000000000 +0200
12762 @@ -0,0 +1,96 @@
12763 +#ifndef _VX_MONITOR_H
12764 +#define _VX_MONITOR_H
12765 +
12766 +#include <linux/types.h>
12767 +
12768 +enum {
12769 +       VXM_UNUSED = 0,
12770 +
12771 +       VXM_SYNC = 0x10,
12772 +
12773 +       VXM_UPDATE = 0x20,
12774 +       VXM_UPDATE_1,
12775 +       VXM_UPDATE_2,
12776 +
12777 +       VXM_RQINFO_1 = 0x24,
12778 +       VXM_RQINFO_2,
12779 +
12780 +       VXM_ACTIVATE = 0x40,
12781 +       VXM_DEACTIVATE,
12782 +       VXM_IDLE,
12783 +
12784 +       VXM_HOLD = 0x44,
12785 +       VXM_UNHOLD,
12786 +
12787 +       VXM_MIGRATE = 0x48,
12788 +       VXM_RESCHED,
12789 +
12790 +       /* all other bits are flags */
12791 +       VXM_SCHED = 0x80,
12792 +};
12793 +
12794 +struct _vxm_update_1 {
12795 +       uint32_t tokens_max;
12796 +       uint32_t fill_rate;
12797 +       uint32_t interval;
12798 +};
12799 +
12800 +struct _vxm_update_2 {
12801 +       uint32_t tokens_min;
12802 +       uint32_t fill_rate;
12803 +       uint32_t interval;
12804 +};
12805 +
12806 +struct _vxm_rqinfo_1 {
12807 +       uint16_t running;
12808 +       uint16_t onhold;
12809 +       uint16_t iowait;
12810 +       uint16_t uintr;
12811 +       uint32_t idle_tokens;
12812 +};
12813 +
12814 +struct _vxm_rqinfo_2 {
12815 +       uint32_t norm_time;
12816 +       uint32_t idle_time;
12817 +       uint32_t idle_skip;
12818 +};
12819 +
12820 +struct _vxm_sched {
12821 +       uint32_t tokens;
12822 +       uint32_t norm_time;
12823 +       uint32_t idle_time;
12824 +};
12825 +
12826 +struct _vxm_task {
12827 +       uint16_t pid;
12828 +       uint16_t state;
12829 +};
12830 +
12831 +struct _vxm_event {
12832 +       uint32_t jif;
12833 +       union {
12834 +               uint32_t seq;
12835 +               uint32_t sec;
12836 +       };
12837 +       union {
12838 +               uint32_t tokens;
12839 +               uint32_t nsec;
12840 +               struct _vxm_task tsk;
12841 +       };
12842 +};
12843 +
12844 +struct _vx_mon_entry {
12845 +       uint16_t type;
12846 +       uint16_t xid;
12847 +       union {
12848 +               struct _vxm_event ev;
12849 +               struct _vxm_sched sd;
12850 +               struct _vxm_update_1 u1;
12851 +               struct _vxm_update_2 u2;
12852 +               struct _vxm_rqinfo_1 q1;
12853 +               struct _vxm_rqinfo_2 q2;
12854 +       };
12855 +};
12856 +
12857 +
12858 +#endif /* _VX_MONITOR_H */
12859 diff -NurpP --minimal linux-3.6.9/include/linux/vserver/network.h linux-3.6.9-vs2.3.4.4/include/linux/vserver/network.h
12860 --- linux-3.6.9/include/linux/vserver/network.h 1970-01-01 01:00:00.000000000 +0100
12861 +++ linux-3.6.9-vs2.3.4.4/include/linux/vserver/network.h       2012-10-04 18:47:00.000000000 +0200
12862 @@ -0,0 +1,148 @@
12863 +#ifndef _VX_NETWORK_H
12864 +#define _VX_NETWORK_H
12865 +
12866 +#include <linux/types.h>
12867 +
12868 +
12869 +#define MAX_N_CONTEXT  65535   /* Arbitrary limit */
12870 +
12871 +
12872 +/* network flags */
12873 +
12874 +#define NXF_INFO_PRIVATE       0x00000008
12875 +
12876 +#define NXF_SINGLE_IP          0x00000100
12877 +#define NXF_LBACK_REMAP                0x00000200
12878 +#define NXF_LBACK_ALLOW                0x00000400
12879 +
12880 +#define NXF_HIDE_NETIF         0x02000000
12881 +#define NXF_HIDE_LBACK         0x04000000
12882 +
12883 +#define NXF_STATE_SETUP                (1ULL << 32)
12884 +#define NXF_STATE_ADMIN                (1ULL << 34)
12885 +
12886 +#define NXF_SC_HELPER          (1ULL << 36)
12887 +#define NXF_PERSISTENT         (1ULL << 38)
12888 +
12889 +#define NXF_ONE_TIME           (0x0005ULL << 32)
12890 +
12891 +
12892 +#define        NXF_INIT_SET            (__nxf_init_set())
12893 +
12894 +static inline uint64_t __nxf_init_set(void) {
12895 +       return    NXF_STATE_ADMIN
12896 +#ifdef CONFIG_VSERVER_AUTO_LBACK
12897 +               | NXF_LBACK_REMAP
12898 +               | NXF_HIDE_LBACK
12899 +#endif
12900 +#ifdef CONFIG_VSERVER_AUTO_SINGLE
12901 +               | NXF_SINGLE_IP
12902 +#endif
12903 +               | NXF_HIDE_NETIF;
12904 +}
12905 +
12906 +
12907 +/* network caps */
12908 +
12909 +#define NXC_TUN_CREATE         0x00000001
12910 +
12911 +#define NXC_RAW_ICMP           0x00000100
12912 +
12913 +#define NXC_MULTICAST          0x00001000
12914 +
12915 +
12916 +/* address types */
12917 +
12918 +#define NXA_TYPE_IPV4          0x0001
12919 +#define NXA_TYPE_IPV6          0x0002
12920 +
12921 +#define NXA_TYPE_NONE          0x0000
12922 +#define NXA_TYPE_ANY           0x00FF
12923 +
12924 +#define NXA_TYPE_ADDR          0x0010
12925 +#define NXA_TYPE_MASK          0x0020
12926 +#define NXA_TYPE_RANGE         0x0040
12927 +
12928 +#define NXA_MASK_ALL           (NXA_TYPE_ADDR | NXA_TYPE_MASK | NXA_TYPE_RANGE)
12929 +
12930 +#define NXA_MOD_BCAST          0x0100
12931 +#define NXA_MOD_LBACK          0x0200
12932 +
12933 +#define NXA_LOOPBACK           0x1000
12934 +
12935 +#define NXA_MASK_BIND          (NXA_MASK_ALL | NXA_MOD_BCAST | NXA_MOD_LBACK)
12936 +#define NXA_MASK_SHOW          (NXA_MASK_ALL | NXA_LOOPBACK)
12937 +
12938 +#ifdef __KERNEL__
12939 +
12940 +#include <linux/list.h>
12941 +#include <linux/spinlock.h>
12942 +#include <linux/rcupdate.h>
12943 +#include <linux/in.h>
12944 +#include <linux/in6.h>
12945 +#include <asm/atomic.h>
12946 +
12947 +struct nx_addr_v4 {
12948 +       struct nx_addr_v4 *next;
12949 +       struct in_addr ip[2];
12950 +       struct in_addr mask;
12951 +       uint16_t type;
12952 +       uint16_t flags;
12953 +};
12954 +
12955 +struct nx_addr_v6 {
12956 +       struct nx_addr_v6 *next;
12957 +       struct in6_addr ip;
12958 +       struct in6_addr mask;
12959 +       uint32_t prefix;
12960 +       uint16_t type;
12961 +       uint16_t flags;
12962 +};
12963 +
12964 +struct nx_info {
12965 +       struct hlist_node nx_hlist;     /* linked list of nxinfos */
12966 +       nid_t nx_id;                    /* vnet id */
12967 +       atomic_t nx_usecnt;             /* usage count */
12968 +       atomic_t nx_tasks;              /* tasks count */
12969 +       int nx_state;                   /* context state */
12970 +
12971 +       uint64_t nx_flags;              /* network flag word */
12972 +       uint64_t nx_ncaps;              /* network capabilities */
12973 +
12974 +       struct in_addr v4_lback;        /* Loopback address */
12975 +       struct in_addr v4_bcast;        /* Broadcast address */
12976 +       struct nx_addr_v4 v4;           /* First/Single ipv4 address */
12977 +#ifdef CONFIG_IPV6
12978 +       struct nx_addr_v6 v6;           /* First/Single ipv6 address */
12979 +#endif
12980 +       char nx_name[65];               /* network context name */
12981 +};
12982 +
12983 +
12984 +/* status flags */
12985 +
12986 +#define NXS_HASHED      0x0001
12987 +#define NXS_SHUTDOWN    0x0100
12988 +#define NXS_RELEASED    0x8000
12989 +
12990 +extern struct nx_info *lookup_nx_info(int);
12991 +
12992 +extern int get_nid_list(int, unsigned int *, int);
12993 +extern int nid_is_hashed(nid_t);
12994 +
12995 +extern int nx_migrate_task(struct task_struct *, struct nx_info *);
12996 +
12997 +extern long vs_net_change(struct nx_info *, unsigned int);
12998 +
12999 +struct sock;
13000 +
13001 +
13002 +#define NX_IPV4(n)     ((n)->v4.type != NXA_TYPE_NONE)
13003 +#ifdef  CONFIG_IPV6
13004 +#define NX_IPV6(n)     ((n)->v6.type != NXA_TYPE_NONE)
13005 +#else
13006 +#define NX_IPV6(n)     (0)
13007 +#endif
13008 +
13009 +#endif /* __KERNEL__ */
13010 +#endif /* _VX_NETWORK_H */
13011 diff -NurpP --minimal linux-3.6.9/include/linux/vserver/network_cmd.h linux-3.6.9-vs2.3.4.4/include/linux/vserver/network_cmd.h
13012 --- linux-3.6.9/include/linux/vserver/network_cmd.h     1970-01-01 01:00:00.000000000 +0100
13013 +++ linux-3.6.9-vs2.3.4.4/include/linux/vserver/network_cmd.h   2012-10-04 18:47:00.000000000 +0200
13014 @@ -0,0 +1,164 @@
13015 +#ifndef _VX_NETWORK_CMD_H
13016 +#define _VX_NETWORK_CMD_H
13017 +
13018 +
13019 +/* vinfo commands */
13020 +
13021 +#define VCMD_task_nid          VC_CMD(VINFO, 2, 0)
13022 +
13023 +#ifdef __KERNEL__
13024 +extern int vc_task_nid(uint32_t);
13025 +
13026 +#endif /* __KERNEL__ */
13027 +
13028 +#define VCMD_nx_info           VC_CMD(VINFO, 6, 0)
13029 +
13030 +struct vcmd_nx_info_v0 {
13031 +       uint32_t nid;
13032 +       /* more to come */
13033 +};
13034 +
13035 +#ifdef __KERNEL__
13036 +extern int vc_nx_info(struct nx_info *, void __user *);
13037 +
13038 +#endif /* __KERNEL__ */
13039 +
13040 +#include <linux/in.h>
13041 +#include <linux/in6.h>
13042 +
13043 +#define VCMD_net_create_v0     VC_CMD(VNET, 1, 0)
13044 +#define VCMD_net_create                VC_CMD(VNET, 1, 1)
13045 +
13046 +struct  vcmd_net_create {
13047 +       uint64_t flagword;
13048 +};
13049 +
13050 +#define VCMD_net_migrate       VC_CMD(NETMIG, 1, 0)
13051 +
13052 +#define VCMD_net_add           VC_CMD(NETALT, 1, 0)
13053 +#define VCMD_net_remove                VC_CMD(NETALT, 2, 0)
13054 +
13055 +struct vcmd_net_addr_v0 {
13056 +       uint16_t type;
13057 +       uint16_t count;
13058 +       struct in_addr ip[4];
13059 +       struct in_addr mask[4];
13060 +};
13061 +
13062 +#define VCMD_net_add_ipv4_v1   VC_CMD(NETALT, 1, 1)
13063 +#define VCMD_net_rem_ipv4_v1   VC_CMD(NETALT, 2, 1)
13064 +
13065 +struct vcmd_net_addr_ipv4_v1 {
13066 +       uint16_t type;
13067 +       uint16_t flags;
13068 +       struct in_addr ip;
13069 +       struct in_addr mask;
13070 +};
13071 +
13072 +#define VCMD_net_add_ipv4      VC_CMD(NETALT, 1, 2)
13073 +#define VCMD_net_rem_ipv4      VC_CMD(NETALT, 2, 2)
13074 +
13075 +struct vcmd_net_addr_ipv4_v2 {
13076 +       uint16_t type;
13077 +       uint16_t flags;
13078 +       struct in_addr ip;
13079 +       struct in_addr ip2;
13080 +       struct in_addr mask;
13081 +};
13082 +
13083 +#define VCMD_net_add_ipv6      VC_CMD(NETALT, 3, 1)
13084 +#define VCMD_net_remove_ipv6   VC_CMD(NETALT, 4, 1)
13085 +
13086 +struct vcmd_net_addr_ipv6_v1 {
13087 +       uint16_t type;
13088 +       uint16_t flags;
13089 +       uint32_t prefix;
13090 +       struct in6_addr ip;
13091 +       struct in6_addr mask;
13092 +};
13093 +
13094 +#define VCMD_add_match_ipv4    VC_CMD(NETALT, 5, 0)
13095 +#define VCMD_get_match_ipv4    VC_CMD(NETALT, 6, 0)
13096 +
13097 +struct vcmd_match_ipv4_v0 {
13098 +       uint16_t type;
13099 +       uint16_t flags;
13100 +       uint16_t parent;
13101 +       uint16_t prefix;
13102 +       struct in_addr ip;
13103 +       struct in_addr ip2;
13104 +       struct in_addr mask;
13105 +};
13106 +
13107 +#define VCMD_add_match_ipv6    VC_CMD(NETALT, 7, 0)
13108 +#define VCMD_get_match_ipv6    VC_CMD(NETALT, 8, 0)
13109 +
13110 +struct vcmd_match_ipv6_v0 {
13111 +       uint16_t type;
13112 +       uint16_t flags;
13113 +       uint16_t parent;
13114 +       uint16_t prefix;
13115 +       struct in6_addr ip;
13116 +       struct in6_addr ip2;
13117 +       struct in6_addr mask;
13118 +};
13119 +
13120 +
13121 +#ifdef __KERNEL__
13122 +extern int vc_net_create(uint32_t, void __user *);
13123 +extern int vc_net_migrate(struct nx_info *, void __user *);
13124 +
13125 +extern int vc_net_add(struct nx_info *, void __user *);
13126 +extern int vc_net_remove(struct nx_info *, void __user *);
13127 +
13128 +extern int vc_net_add_ipv4_v1(struct nx_info *, void __user *);
13129 +extern int vc_net_add_ipv4(struct nx_info *, void __user *);
13130 +
13131 +extern int vc_net_rem_ipv4_v1(struct nx_info *, void __user *);
13132 +extern int vc_net_rem_ipv4(struct nx_info *, void __user *);
13133 +
13134 +extern int vc_net_add_ipv6(struct nx_info *, void __user *);
13135 +extern int vc_net_remove_ipv6(struct nx_info *, void __user *);
13136 +
13137 +extern int vc_add_match_ipv4(struct nx_info *, void __user *);
13138 +extern int vc_get_match_ipv4(struct nx_info *, void __user *);
13139 +
13140 +extern int vc_add_match_ipv6(struct nx_info *, void __user *);
13141 +extern int vc_get_match_ipv6(struct nx_info *, void __user *);
13142 +
13143 +#endif /* __KERNEL__ */
13144 +
13145 +
13146 +/* flag commands */
13147 +
13148 +#define VCMD_get_nflags                VC_CMD(FLAGS, 5, 0)
13149 +#define VCMD_set_nflags                VC_CMD(FLAGS, 6, 0)
13150 +
13151 +struct vcmd_net_flags_v0 {
13152 +       uint64_t flagword;
13153 +       uint64_t mask;
13154 +};
13155 +
13156 +#ifdef __KERNEL__
13157 +extern int vc_get_nflags(struct nx_info *, void __user *);
13158 +extern int vc_set_nflags(struct nx_info *, void __user *);
13159 +
13160 +#endif /* __KERNEL__ */
13161 +
13162 +
13163 +/* network caps commands */
13164 +
13165 +#define VCMD_get_ncaps         VC_CMD(FLAGS, 7, 0)
13166 +#define VCMD_set_ncaps         VC_CMD(FLAGS, 8, 0)
13167 +
13168 +struct vcmd_net_caps_v0 {
13169 +       uint64_t ncaps;
13170 +       uint64_t cmask;
13171 +};
13172 +
13173 +#ifdef __KERNEL__
13174 +extern int vc_get_ncaps(struct nx_info *, void __user *);
13175 +extern int vc_set_ncaps(struct nx_info *, void __user *);
13176 +
13177 +#endif /* __KERNEL__ */
13178 +#endif /* _VX_CONTEXT_CMD_H */
13179 diff -NurpP --minimal linux-3.6.9/include/linux/vserver/percpu.h linux-3.6.9-vs2.3.4.4/include/linux/vserver/percpu.h
13180 --- linux-3.6.9/include/linux/vserver/percpu.h  1970-01-01 01:00:00.000000000 +0100
13181 +++ linux-3.6.9-vs2.3.4.4/include/linux/vserver/percpu.h        2012-10-04 18:47:00.000000000 +0200
13182 @@ -0,0 +1,14 @@
13183 +#ifndef _VX_PERCPU_H
13184 +#define _VX_PERCPU_H
13185 +
13186 +#include "cvirt_def.h"
13187 +#include "sched_def.h"
13188 +
13189 +struct _vx_percpu {
13190 +       struct _vx_cvirt_pc cvirt;
13191 +       struct _vx_sched_pc sched;
13192 +};
13193 +
13194 +#define        PERCPU_PERCTX   (sizeof(struct _vx_percpu))
13195 +
13196 +#endif /* _VX_PERCPU_H */
13197 diff -NurpP --minimal linux-3.6.9/include/linux/vserver/pid.h linux-3.6.9-vs2.3.4.4/include/linux/vserver/pid.h
13198 --- linux-3.6.9/include/linux/vserver/pid.h     1970-01-01 01:00:00.000000000 +0100
13199 +++ linux-3.6.9-vs2.3.4.4/include/linux/vserver/pid.h   2012-10-04 18:47:00.000000000 +0200
13200 @@ -0,0 +1,51 @@
13201 +#ifndef _VSERVER_PID_H
13202 +#define _VSERVER_PID_H
13203 +
13204 +/* pid faking stuff */
13205 +
13206 +#define vx_info_map_pid(v, p) \
13207 +       __vx_info_map_pid((v), (p), __func__, __FILE__, __LINE__)
13208 +#define vx_info_map_tgid(v,p)  vx_info_map_pid(v,p)
13209 +#define vx_map_pid(p) vx_info_map_pid(current_vx_info(), p)
13210 +#define vx_map_tgid(p) vx_map_pid(p)
13211 +
13212 +static inline int __vx_info_map_pid(struct vx_info *vxi, int pid,
13213 +       const char *func, const char *file, int line)
13214 +{
13215 +       if (vx_info_flags(vxi, VXF_INFO_INIT, 0)) {
13216 +               vxfprintk(VXD_CBIT(cvirt, 2),
13217 +                       "vx_map_tgid: %p/%llx: %d -> %d",
13218 +                       vxi, (long long)vxi->vx_flags, pid,
13219 +                       (pid && pid == vxi->vx_initpid) ? 1 : pid,
13220 +                       func, file, line);
13221 +               if (pid == 0)
13222 +                       return 0;
13223 +               if (pid == vxi->vx_initpid)
13224 +                       return 1;
13225 +       }
13226 +       return pid;
13227 +}
13228 +
13229 +#define vx_info_rmap_pid(v, p) \
13230 +       __vx_info_rmap_pid((v), (p), __func__, __FILE__, __LINE__)
13231 +#define vx_rmap_pid(p) vx_info_rmap_pid(current_vx_info(), p)
13232 +#define vx_rmap_tgid(p) vx_rmap_pid(p)
13233 +
13234 +static inline int __vx_info_rmap_pid(struct vx_info *vxi, int pid,
13235 +       const char *func, const char *file, int line)
13236 +{
13237 +       if (vx_info_flags(vxi, VXF_INFO_INIT, 0)) {
13238 +               vxfprintk(VXD_CBIT(cvirt, 2),
13239 +                       "vx_rmap_tgid: %p/%llx: %d -> %d",
13240 +                       vxi, (long long)vxi->vx_flags, pid,
13241 +                       (pid == 1) ? vxi->vx_initpid : pid,
13242 +                       func, file, line);
13243 +               if ((pid == 1) && vxi->vx_initpid)
13244 +                       return vxi->vx_initpid;
13245 +               if (pid == vxi->vx_initpid)
13246 +                       return ~0U;
13247 +       }
13248 +       return pid;
13249 +}
13250 +
13251 +#endif
13252 diff -NurpP --minimal linux-3.6.9/include/linux/vserver/sched.h linux-3.6.9-vs2.3.4.4/include/linux/vserver/sched.h
13253 --- linux-3.6.9/include/linux/vserver/sched.h   1970-01-01 01:00:00.000000000 +0100
13254 +++ linux-3.6.9-vs2.3.4.4/include/linux/vserver/sched.h 2012-10-04 18:47:00.000000000 +0200
13255 @@ -0,0 +1,23 @@
13256 +#ifndef _VX_SCHED_H
13257 +#define _VX_SCHED_H
13258 +
13259 +
13260 +#ifdef __KERNEL__
13261 +
13262 +struct timespec;
13263 +
13264 +void vx_vsi_uptime(struct timespec *, struct timespec *);
13265 +
13266 +
13267 +struct vx_info;
13268 +
13269 +void vx_update_load(struct vx_info *);
13270 +
13271 +
13272 +void vx_update_sched_param(struct _vx_sched *sched,
13273 +       struct _vx_sched_pc *sched_pc);
13274 +
13275 +#endif /* __KERNEL__ */
13276 +#else  /* _VX_SCHED_H */
13277 +#warning duplicate inclusion
13278 +#endif /* _VX_SCHED_H */
13279 diff -NurpP --minimal linux-3.6.9/include/linux/vserver/sched_cmd.h linux-3.6.9-vs2.3.4.4/include/linux/vserver/sched_cmd.h
13280 --- linux-3.6.9/include/linux/vserver/sched_cmd.h       1970-01-01 01:00:00.000000000 +0100
13281 +++ linux-3.6.9-vs2.3.4.4/include/linux/vserver/sched_cmd.h     2012-10-04 18:47:00.000000000 +0200
13282 @@ -0,0 +1,21 @@
13283 +#ifndef _VX_SCHED_CMD_H
13284 +#define _VX_SCHED_CMD_H
13285 +
13286 +
13287 +struct vcmd_prio_bias {
13288 +       int32_t cpu_id;
13289 +       int32_t prio_bias;
13290 +};
13291 +
13292 +#define VCMD_set_prio_bias     VC_CMD(SCHED, 4, 0)
13293 +#define VCMD_get_prio_bias     VC_CMD(SCHED, 5, 0)
13294 +
13295 +#ifdef __KERNEL__
13296 +
13297 +#include <linux/compiler.h>
13298 +
13299 +extern int vc_set_prio_bias(struct vx_info *, void __user *);
13300 +extern int vc_get_prio_bias(struct vx_info *, void __user *);
13301 +
13302 +#endif /* __KERNEL__ */
13303 +#endif /* _VX_SCHED_CMD_H */
13304 diff -NurpP --minimal linux-3.6.9/include/linux/vserver/sched_def.h linux-3.6.9-vs2.3.4.4/include/linux/vserver/sched_def.h
13305 --- linux-3.6.9/include/linux/vserver/sched_def.h       1970-01-01 01:00:00.000000000 +0100
13306 +++ linux-3.6.9-vs2.3.4.4/include/linux/vserver/sched_def.h     2012-10-04 18:47:00.000000000 +0200
13307 @@ -0,0 +1,38 @@
13308 +#ifndef _VX_SCHED_DEF_H
13309 +#define _VX_SCHED_DEF_H
13310 +
13311 +#include <linux/spinlock.h>
13312 +#include <linux/jiffies.h>
13313 +#include <linux/cpumask.h>
13314 +#include <asm/atomic.h>
13315 +#include <asm/param.h>
13316 +
13317 +
13318 +/* context sub struct */
13319 +
13320 +struct _vx_sched {
13321 +       int prio_bias;                  /* bias offset for priority */
13322 +
13323 +       cpumask_t update;               /* CPUs which should update */
13324 +};
13325 +
13326 +struct _vx_sched_pc {
13327 +       int prio_bias;                  /* bias offset for priority */
13328 +
13329 +       uint64_t user_ticks;            /* token tick events */
13330 +       uint64_t sys_ticks;             /* token tick events */
13331 +       uint64_t hold_ticks;            /* token ticks paused */
13332 +};
13333 +
13334 +
13335 +#ifdef CONFIG_VSERVER_DEBUG
13336 +
13337 +static inline void __dump_vx_sched(struct _vx_sched *sched)
13338 +{
13339 +       printk("\t_vx_sched:\n");
13340 +       printk("\t priority = %4d\n", sched->prio_bias);
13341 +}
13342 +
13343 +#endif
13344 +
13345 +#endif /* _VX_SCHED_DEF_H */
13346 diff -NurpP --minimal linux-3.6.9/include/linux/vserver/signal.h linux-3.6.9-vs2.3.4.4/include/linux/vserver/signal.h
13347 --- linux-3.6.9/include/linux/vserver/signal.h  1970-01-01 01:00:00.000000000 +0100
13348 +++ linux-3.6.9-vs2.3.4.4/include/linux/vserver/signal.h        2012-10-04 18:47:00.000000000 +0200
13349 @@ -0,0 +1,14 @@
13350 +#ifndef _VX_SIGNAL_H
13351 +#define _VX_SIGNAL_H
13352 +
13353 +
13354 +#ifdef __KERNEL__
13355 +
13356 +struct vx_info;
13357 +
13358 +int vx_info_kill(struct vx_info *, int, int);
13359 +
13360 +#endif /* __KERNEL__ */
13361 +#else  /* _VX_SIGNAL_H */
13362 +#warning duplicate inclusion
13363 +#endif /* _VX_SIGNAL_H */
13364 diff -NurpP --minimal linux-3.6.9/include/linux/vserver/signal_cmd.h linux-3.6.9-vs2.3.4.4/include/linux/vserver/signal_cmd.h
13365 --- linux-3.6.9/include/linux/vserver/signal_cmd.h      1970-01-01 01:00:00.000000000 +0100
13366 +++ linux-3.6.9-vs2.3.4.4/include/linux/vserver/signal_cmd.h    2012-10-04 18:47:00.000000000 +0200
13367 @@ -0,0 +1,43 @@
13368 +#ifndef _VX_SIGNAL_CMD_H
13369 +#define _VX_SIGNAL_CMD_H
13370 +
13371 +
13372 +/*  signalling vserver commands */
13373 +
13374 +#define VCMD_ctx_kill          VC_CMD(PROCTRL, 1, 0)
13375 +#define VCMD_wait_exit         VC_CMD(EVENT, 99, 0)
13376 +
13377 +struct vcmd_ctx_kill_v0 {
13378 +       int32_t pid;
13379 +       int32_t sig;
13380 +};
13381 +
13382 +struct vcmd_wait_exit_v0 {
13383 +       int32_t reboot_cmd;
13384 +       int32_t exit_code;
13385 +};
13386 +
13387 +#ifdef __KERNEL__
13388 +
13389 +extern int vc_ctx_kill(struct vx_info *, void __user *);
13390 +extern int vc_wait_exit(struct vx_info *, void __user *);
13391 +
13392 +#endif /* __KERNEL__ */
13393 +
13394 +/*  process alteration commands */
13395 +
13396 +#define VCMD_get_pflags                VC_CMD(PROCALT, 5, 0)
13397 +#define VCMD_set_pflags                VC_CMD(PROCALT, 6, 0)
13398 +
13399 +struct vcmd_pflags_v0 {
13400 +       uint32_t flagword;
13401 +       uint32_t mask;
13402 +};
13403 +
13404 +#ifdef __KERNEL__
13405 +
13406 +extern int vc_get_pflags(uint32_t pid, void __user *);
13407 +extern int vc_set_pflags(uint32_t pid, void __user *);
13408 +
13409 +#endif /* __KERNEL__ */
13410 +#endif /* _VX_SIGNAL_CMD_H */
13411 diff -NurpP --minimal linux-3.6.9/include/linux/vserver/space.h linux-3.6.9-vs2.3.4.4/include/linux/vserver/space.h
13412 --- linux-3.6.9/include/linux/vserver/space.h   1970-01-01 01:00:00.000000000 +0100
13413 +++ linux-3.6.9-vs2.3.4.4/include/linux/vserver/space.h 2012-10-04 18:47:00.000000000 +0200
13414 @@ -0,0 +1,12 @@
13415 +#ifndef _VX_SPACE_H
13416 +#define _VX_SPACE_H
13417 +
13418 +#include <linux/types.h>
13419 +
13420 +struct vx_info;
13421 +
13422 +int vx_set_space(struct vx_info *vxi, unsigned long mask, unsigned index);
13423 +
13424 +#else  /* _VX_SPACE_H */
13425 +#warning duplicate inclusion
13426 +#endif /* _VX_SPACE_H */
13427 diff -NurpP --minimal linux-3.6.9/include/linux/vserver/space_cmd.h linux-3.6.9-vs2.3.4.4/include/linux/vserver/space_cmd.h
13428 --- linux-3.6.9/include/linux/vserver/space_cmd.h       1970-01-01 01:00:00.000000000 +0100
13429 +++ linux-3.6.9-vs2.3.4.4/include/linux/vserver/space_cmd.h     2012-10-04 18:47:00.000000000 +0200
13430 @@ -0,0 +1,38 @@
13431 +#ifndef _VX_SPACE_CMD_H
13432 +#define _VX_SPACE_CMD_H
13433 +
13434 +
13435 +#define VCMD_enter_space_v0    VC_CMD(PROCALT, 1, 0)
13436 +#define VCMD_enter_space_v1    VC_CMD(PROCALT, 1, 1)
13437 +#define VCMD_enter_space       VC_CMD(PROCALT, 1, 2)
13438 +
13439 +#define VCMD_set_space_v0      VC_CMD(PROCALT, 3, 0)
13440 +#define VCMD_set_space_v1      VC_CMD(PROCALT, 3, 1)
13441 +#define VCMD_set_space         VC_CMD(PROCALT, 3, 2)
13442 +
13443 +#define VCMD_get_space_mask_v0 VC_CMD(PROCALT, 4, 0)
13444 +
13445 +#define VCMD_get_space_mask    VC_CMD(VSPACE, 0, 1)
13446 +#define VCMD_get_space_default VC_CMD(VSPACE, 1, 0)
13447 +
13448 +
13449 +struct vcmd_space_mask_v1 {
13450 +       uint64_t mask;
13451 +};
13452 +
13453 +struct vcmd_space_mask_v2 {
13454 +       uint64_t mask;
13455 +       uint32_t index;
13456 +};
13457 +
13458 +
13459 +#ifdef __KERNEL__
13460 +
13461 +extern int vc_enter_space_v1(struct vx_info *, void __user *);
13462 +extern int vc_set_space_v1(struct vx_info *, void __user *);
13463 +extern int vc_enter_space(struct vx_info *, void __user *);
13464 +extern int vc_set_space(struct vx_info *, void __user *);
13465 +extern int vc_get_space_mask(void __user *, int);
13466 +
13467 +#endif /* __KERNEL__ */
13468 +#endif /* _VX_SPACE_CMD_H */
13469 diff -NurpP --minimal linux-3.6.9/include/linux/vserver/switch.h linux-3.6.9-vs2.3.4.4/include/linux/vserver/switch.h
13470 --- linux-3.6.9/include/linux/vserver/switch.h  1970-01-01 01:00:00.000000000 +0100
13471 +++ linux-3.6.9-vs2.3.4.4/include/linux/vserver/switch.h        2012-10-04 18:47:00.000000000 +0200
13472 @@ -0,0 +1,98 @@
13473 +#ifndef _VX_SWITCH_H
13474 +#define _VX_SWITCH_H
13475 +
13476 +#include <linux/types.h>
13477 +
13478 +
13479 +#define VC_CATEGORY(c)         (((c) >> 24) & 0x3F)
13480 +#define VC_COMMAND(c)          (((c) >> 16) & 0xFF)
13481 +#define VC_VERSION(c)          ((c) & 0xFFF)
13482 +
13483 +#define VC_CMD(c, i, v)                ((((VC_CAT_ ## c) & 0x3F) << 24) \
13484 +                               | (((i) & 0xFF) << 16) | ((v) & 0xFFF))
13485 +
13486 +/*
13487 +
13488 +  Syscall Matrix V2.8
13489 +
13490 +        |VERSION|CREATE |MODIFY |MIGRATE|CONTROL|EXPERIM| |SPECIAL|SPECIAL|
13491 +        |STATS  |DESTROY|ALTER  |CHANGE |LIMIT  |TEST   | |       |       |
13492 +        |INFO   |SETUP  |       |MOVE   |       |       | |       |       |
13493 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13494 +  SYSTEM |VERSION|VSETUP |VHOST  |       |       |       | |DEVICE |       |
13495 +  HOST   |     00|     01|     02|     03|     04|     05| |     06|     07|
13496 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13497 +  CPU    |       |VPROC  |PROCALT|PROCMIG|PROCTRL|       | |SCHED. |       |
13498 +  PROCESS|     08|     09|     10|     11|     12|     13| |     14|     15|
13499 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13500 +  MEMORY |       |       |       |       |MEMCTRL|       | |SWAP   |       |
13501 +        |     16|     17|     18|     19|     20|     21| |     22|     23|
13502 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13503 +  NETWORK|       |VNET   |NETALT |NETMIG |NETCTL |       | |SERIAL |       |
13504 +        |     24|     25|     26|     27|     28|     29| |     30|     31|
13505 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13506 +  DISK   |       |       |       |TAGMIG |DLIMIT |       | |INODE  |       |
13507 +  VFS    |     32|     33|     34|     35|     36|     37| |     38|     39|
13508 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13509 +  OTHER  |VSTAT  |       |       |       |       |       | |VINFO  |       |
13510 +        |     40|     41|     42|     43|     44|     45| |     46|     47|
13511 +  =======+=======+=======+=======+=======+=======+=======+ +=======+=======+
13512 +  SPECIAL|EVENT  |       |       |       |FLAGS  |       | |VSPACE |       |
13513 +        |     48|     49|     50|     51|     52|     53| |     54|     55|
13514 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13515 +  SPECIAL|DEBUG  |       |       |       |RLIMIT |SYSCALL| |       |COMPAT |
13516 +        |     56|     57|     58|     59|     60|TEST 61| |     62|     63|
13517 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13518 +
13519 +*/
13520 +
13521 +#define VC_CAT_VERSION         0
13522 +
13523 +#define VC_CAT_VSETUP          1
13524 +#define VC_CAT_VHOST           2
13525 +
13526 +#define VC_CAT_DEVICE          6
13527 +
13528 +#define VC_CAT_VPROC           9
13529 +#define VC_CAT_PROCALT         10
13530 +#define VC_CAT_PROCMIG         11
13531 +#define VC_CAT_PROCTRL         12
13532 +
13533 +#define VC_CAT_SCHED           14
13534 +#define VC_CAT_MEMCTRL         20
13535 +
13536 +#define VC_CAT_VNET            25
13537 +#define VC_CAT_NETALT          26
13538 +#define VC_CAT_NETMIG          27
13539 +#define VC_CAT_NETCTRL         28
13540 +
13541 +#define VC_CAT_TAGMIG          35
13542 +#define VC_CAT_DLIMIT          36
13543 +#define VC_CAT_INODE           38
13544 +
13545 +#define VC_CAT_VSTAT           40
13546 +#define VC_CAT_VINFO           46
13547 +#define VC_CAT_EVENT           48
13548 +
13549 +#define VC_CAT_FLAGS           52
13550 +#define VC_CAT_VSPACE          54
13551 +#define VC_CAT_DEBUG           56
13552 +#define VC_CAT_RLIMIT          60
13553 +
13554 +#define VC_CAT_SYSTEST         61
13555 +#define VC_CAT_COMPAT          63
13556 +
13557 +/*  query version */
13558 +
13559 +#define VCMD_get_version       VC_CMD(VERSION, 0, 0)
13560 +#define VCMD_get_vci           VC_CMD(VERSION, 1, 0)
13561 +
13562 +
13563 +#ifdef __KERNEL__
13564 +
13565 +#include <linux/errno.h>
13566 +
13567 +#endif /* __KERNEL__ */
13568 +
13569 +#endif /* _VX_SWITCH_H */
13570 +
13571 diff -NurpP --minimal linux-3.6.9/include/linux/vserver/tag.h linux-3.6.9-vs2.3.4.4/include/linux/vserver/tag.h
13572 --- linux-3.6.9/include/linux/vserver/tag.h     1970-01-01 01:00:00.000000000 +0100
13573 +++ linux-3.6.9-vs2.3.4.4/include/linux/vserver/tag.h   2012-10-04 18:47:00.000000000 +0200
13574 @@ -0,0 +1,143 @@
13575 +#ifndef _DX_TAG_H
13576 +#define _DX_TAG_H
13577 +
13578 +#include <linux/types.h>
13579 +
13580 +
13581 +#define DX_TAG(in)     (IS_TAGGED(in))
13582 +
13583 +
13584 +#ifdef CONFIG_TAG_NFSD
13585 +#define DX_TAG_NFSD    1
13586 +#else
13587 +#define DX_TAG_NFSD    0
13588 +#endif
13589 +
13590 +
13591 +#ifdef CONFIG_TAGGING_NONE
13592 +
13593 +#define MAX_UID                0xFFFFFFFF
13594 +#define MAX_GID                0xFFFFFFFF
13595 +
13596 +#define INOTAG_TAG(cond, uid, gid, tag)        (0)
13597 +
13598 +#define TAGINO_UID(cond, uid, tag)     (uid)
13599 +#define TAGINO_GID(cond, gid, tag)     (gid)
13600 +
13601 +#endif
13602 +
13603 +
13604 +#ifdef CONFIG_TAGGING_GID16
13605 +
13606 +#define MAX_UID                0xFFFFFFFF
13607 +#define MAX_GID                0x0000FFFF
13608 +
13609 +#define INOTAG_TAG(cond, uid, gid, tag)        \
13610 +       ((cond) ? (((gid) >> 16) & 0xFFFF) : 0)
13611 +
13612 +#define TAGINO_UID(cond, uid, tag)     (uid)
13613 +#define TAGINO_GID(cond, gid, tag)     \
13614 +       ((cond) ? (((gid) & 0xFFFF) | ((tag) << 16)) : (gid))
13615 +
13616 +#endif
13617 +
13618 +
13619 +#ifdef CONFIG_TAGGING_ID24
13620 +
13621 +#define MAX_UID                0x00FFFFFF
13622 +#define MAX_GID                0x00FFFFFF
13623 +
13624 +#define INOTAG_TAG(cond, uid, gid, tag)        \
13625 +       ((cond) ? ((((uid) >> 16) & 0xFF00) | (((gid) >> 24) & 0xFF)) : 0)
13626 +
13627 +#define TAGINO_UID(cond, uid, tag)     \
13628 +       ((cond) ? (((uid) & 0xFFFFFF) | (((tag) & 0xFF00) << 16)) : (uid))
13629 +#define TAGINO_GID(cond, gid, tag)     \
13630 +       ((cond) ? (((gid) & 0xFFFFFF) | (((tag) & 0x00FF) << 24)) : (gid))
13631 +
13632 +#endif
13633 +
13634 +
13635 +#ifdef CONFIG_TAGGING_UID16
13636 +
13637 +#define MAX_UID                0x0000FFFF
13638 +#define MAX_GID                0xFFFFFFFF
13639 +
13640 +#define INOTAG_TAG(cond, uid, gid, tag)        \
13641 +       ((cond) ? (((uid) >> 16) & 0xFFFF) : 0)
13642 +
13643 +#define TAGINO_UID(cond, uid, tag)     \
13644 +       ((cond) ? (((uid) & 0xFFFF) | ((tag) << 16)) : (uid))
13645 +#define TAGINO_GID(cond, gid, tag)     (gid)
13646 +
13647 +#endif
13648 +
13649 +
13650 +#ifdef CONFIG_TAGGING_INTERN
13651 +
13652 +#define MAX_UID                0xFFFFFFFF
13653 +#define MAX_GID                0xFFFFFFFF
13654 +
13655 +#define INOTAG_TAG(cond, uid, gid, tag)        \
13656 +       ((cond) ? (tag) : 0)
13657 +
13658 +#define TAGINO_UID(cond, uid, tag)     (uid)
13659 +#define TAGINO_GID(cond, gid, tag)     (gid)
13660 +
13661 +#endif
13662 +
13663 +
13664 +#ifndef CONFIG_TAGGING_NONE
13665 +#define dx_current_fstag(sb)   \
13666 +       ((sb)->s_flags & MS_TAGGED ? dx_current_tag() : 0)
13667 +#else
13668 +#define dx_current_fstag(sb)   (0)
13669 +#endif
13670 +
13671 +#ifndef CONFIG_TAGGING_INTERN
13672 +#define TAGINO_TAG(cond, tag)  (0)
13673 +#else
13674 +#define TAGINO_TAG(cond, tag)  ((cond) ? (tag) : 0)
13675 +#endif
13676 +
13677 +#define INOTAG_UID(cond, uid, gid)     \
13678 +       ((cond) ? ((uid) & MAX_UID) : (uid))
13679 +#define INOTAG_GID(cond, uid, gid)     \
13680 +       ((cond) ? ((gid) & MAX_GID) : (gid))
13681 +
13682 +
13683 +static inline uid_t dx_map_uid(uid_t uid)
13684 +{
13685 +       if ((uid > MAX_UID) && (uid != -1))
13686 +               uid = -2;
13687 +       return (uid & MAX_UID);
13688 +}
13689 +
13690 +static inline gid_t dx_map_gid(gid_t gid)
13691 +{
13692 +       if ((gid > MAX_GID) && (gid != -1))
13693 +               gid = -2;
13694 +       return (gid & MAX_GID);
13695 +}
13696 +
13697 +struct peer_tag {
13698 +       int32_t xid;
13699 +       int32_t nid;
13700 +};
13701 +
13702 +#define dx_notagcheck(sb) ((sb) && ((sb)->s_flags & MS_NOTAGCHECK))
13703 +
13704 +int dx_parse_tag(char *string, vs_tag_t *tag, int remove, int *mnt_flags,
13705 +                unsigned long *flags);
13706 +
13707 +#ifdef CONFIG_PROPAGATE
13708 +
13709 +void __dx_propagate_tag(struct nameidata *nd, struct inode *inode);
13710 +
13711 +#define dx_propagate_tag(n, i) __dx_propagate_tag(n, i)
13712 +
13713 +#else
13714 +#define dx_propagate_tag(n, i) do { } while (0)
13715 +#endif
13716 +
13717 +#endif /* _DX_TAG_H */
13718 diff -NurpP --minimal linux-3.6.9/include/linux/vserver/tag_cmd.h linux-3.6.9-vs2.3.4.4/include/linux/vserver/tag_cmd.h
13719 --- linux-3.6.9/include/linux/vserver/tag_cmd.h 1970-01-01 01:00:00.000000000 +0100
13720 +++ linux-3.6.9-vs2.3.4.4/include/linux/vserver/tag_cmd.h       2012-10-04 18:47:00.000000000 +0200
13721 @@ -0,0 +1,22 @@
13722 +#ifndef _VX_TAG_CMD_H
13723 +#define _VX_TAG_CMD_H
13724 +
13725 +
13726 +/* vinfo commands */
13727 +
13728 +#define VCMD_task_tag          VC_CMD(VINFO, 3, 0)
13729 +
13730 +#ifdef __KERNEL__
13731 +extern int vc_task_tag(uint32_t);
13732 +
13733 +#endif /* __KERNEL__ */
13734 +
13735 +/* context commands */
13736 +
13737 +#define VCMD_tag_migrate       VC_CMD(TAGMIG, 1, 0)
13738 +
13739 +#ifdef __KERNEL__
13740 +extern int vc_tag_migrate(uint32_t);
13741 +
13742 +#endif /* __KERNEL__ */
13743 +#endif /* _VX_TAG_CMD_H */
13744 diff -NurpP --minimal linux-3.6.9/include/net/addrconf.h linux-3.6.9-vs2.3.4.4/include/net/addrconf.h
13745 --- linux-3.6.9/include/net/addrconf.h  2012-10-04 15:27:47.000000000 +0200
13746 +++ linux-3.6.9-vs2.3.4.4/include/net/addrconf.h        2012-10-04 18:47:00.000000000 +0200
13747 @@ -81,7 +81,8 @@ extern int                    ipv6_dev_get_saddr(struct n
13748                                                struct net_device *dev,
13749                                                const struct in6_addr *daddr,
13750                                                unsigned int srcprefs,
13751 -                                              struct in6_addr *saddr);
13752 +                                              struct in6_addr *saddr,
13753 +                                              struct nx_info *nxi);
13754  extern int                     ipv6_get_lladdr(struct net_device *dev,
13755                                                 struct in6_addr *addr,
13756                                                 unsigned char banned_flags);
13757 diff -NurpP --minimal linux-3.6.9/include/net/af_unix.h linux-3.6.9-vs2.3.4.4/include/net/af_unix.h
13758 --- linux-3.6.9/include/net/af_unix.h   2012-10-04 15:27:47.000000000 +0200
13759 +++ linux-3.6.9-vs2.3.4.4/include/net/af_unix.h 2012-10-04 18:47:00.000000000 +0200
13760 @@ -4,6 +4,7 @@
13761  #include <linux/socket.h>
13762  #include <linux/un.h>
13763  #include <linux/mutex.h>
13764 +#include <linux/vs_base.h>
13765  #include <net/sock.h>
13766  
13767  extern void unix_inflight(struct file *fp);
13768 diff -NurpP --minimal linux-3.6.9/include/net/inet_timewait_sock.h linux-3.6.9-vs2.3.4.4/include/net/inet_timewait_sock.h
13769 --- linux-3.6.9/include/net/inet_timewait_sock.h        2012-03-19 19:47:29.000000000 +0100
13770 +++ linux-3.6.9-vs2.3.4.4/include/net/inet_timewait_sock.h      2012-10-04 18:47:00.000000000 +0200
13771 @@ -112,6 +112,10 @@ struct inet_timewait_sock {
13772  #define tw_net                 __tw_common.skc_net
13773  #define tw_daddr               __tw_common.skc_daddr
13774  #define tw_rcv_saddr           __tw_common.skc_rcv_saddr
13775 +#define tw_xid                 __tw_common.skc_xid
13776 +#define tw_vx_info             __tw_common.skc_vx_info
13777 +#define tw_nid                 __tw_common.skc_nid
13778 +#define tw_nx_info             __tw_common.skc_nx_info
13779         int                     tw_timeout;
13780         volatile unsigned char  tw_substate;
13781         unsigned char           tw_rcv_wscale;
13782 diff -NurpP --minimal linux-3.6.9/include/net/ip6_route.h linux-3.6.9-vs2.3.4.4/include/net/ip6_route.h
13783 --- linux-3.6.9/include/net/ip6_route.h 2012-10-04 15:27:47.000000000 +0200
13784 +++ linux-3.6.9-vs2.3.4.4/include/net/ip6_route.h       2012-10-04 18:47:00.000000000 +0200
13785 @@ -97,7 +97,8 @@ extern int                    ip6_route_get_saddr(struct 
13786                                                     struct rt6_info *rt,
13787                                                     const struct in6_addr *daddr,
13788                                                     unsigned int prefs,
13789 -                                                   struct in6_addr *saddr);
13790 +                                                   struct in6_addr *saddr,
13791 +                                                   struct nx_info *nxi);
13792  
13793  extern struct rt6_info         *rt6_lookup(struct net *net,
13794                                             const struct in6_addr *daddr,
13795 diff -NurpP --minimal linux-3.6.9/include/net/route.h linux-3.6.9-vs2.3.4.4/include/net/route.h
13796 --- linux-3.6.9/include/net/route.h     2012-12-08 01:34:14.000000000 +0100
13797 +++ linux-3.6.9-vs2.3.4.4/include/net/route.h   2012-11-06 18:43:41.000000000 +0100
13798 @@ -204,6 +204,9 @@ static inline void ip_rt_put(struct rtab
13799                 dst_release(&rt->dst);
13800  }
13801  
13802 +#include <linux/vs_base.h>
13803 +#include <linux/vs_inet.h>
13804 +
13805  #define IPTOS_RT_MASK  (IPTOS_TOS_MASK & ~3)
13806  
13807  extern const __u8 ip_tos2prio[16];
13808 @@ -253,6 +256,9 @@ static inline void ip_route_connect_init
13809                            protocol, flow_flags, dst, src, dport, sport);
13810  }
13811  
13812 +extern struct rtable *ip_v4_find_src(struct net *net, struct nx_info *,
13813 +       struct flowi4 *);
13814 +
13815  static inline struct rtable *ip_route_connect(struct flowi4 *fl4,
13816                                               __be32 dst, __be32 src, u32 tos,
13817                                               int oif, u8 protocol,
13818 @@ -261,11 +267,25 @@ static inline struct rtable *ip_route_co
13819  {
13820         struct net *net = sock_net(sk);
13821         struct rtable *rt;
13822 +       struct nx_info *nx_info = current_nx_info();
13823  
13824         ip_route_connect_init(fl4, dst, src, tos, oif, protocol,
13825                               sport, dport, sk, can_sleep);
13826  
13827 -       if (!dst || !src) {
13828 +       if (sk)
13829 +               nx_info = sk->sk_nx_info;
13830 +
13831 +       vxdprintk(VXD_CBIT(net, 4),
13832 +               "ip_route_connect(%p) %p,%p;%lx",
13833 +               sk, nx_info, sk->sk_socket,
13834 +               (sk->sk_socket?sk->sk_socket->flags:0));
13835 +
13836 +       rt = ip_v4_find_src(net, nx_info, fl4);
13837 +       if (IS_ERR(rt))
13838 +               return rt;
13839 +       ip_rt_put(rt);
13840 +
13841 +       if (!fl4->daddr || !fl4->saddr) {
13842                 rt = __ip_route_output_key(net, fl4);
13843                 if (IS_ERR(rt))
13844                         return rt;
13845 diff -NurpP --minimal linux-3.6.9/include/net/sock.h linux-3.6.9-vs2.3.4.4/include/net/sock.h
13846 --- linux-3.6.9/include/net/sock.h      2012-10-04 15:27:47.000000000 +0200
13847 +++ linux-3.6.9-vs2.3.4.4/include/net/sock.h    2012-10-04 18:47:00.000000000 +0200
13848 @@ -171,6 +171,10 @@ struct sock_common {
13849  #ifdef CONFIG_NET_NS
13850         struct net              *skc_net;
13851  #endif
13852 +       xid_t                   skc_xid;
13853 +       struct vx_info          *skc_vx_info;
13854 +       nid_t                   skc_nid;
13855 +       struct nx_info          *skc_nx_info;
13856         /*
13857          * fields between dontcopy_begin/dontcopy_end
13858          * are not copied in sock_copy()
13859 @@ -284,6 +288,10 @@ struct sock {
13860  #define sk_bind_node           __sk_common.skc_bind_node
13861  #define sk_prot                        __sk_common.skc_prot
13862  #define sk_net                 __sk_common.skc_net
13863 +#define sk_xid                 __sk_common.skc_xid
13864 +#define sk_vx_info             __sk_common.skc_vx_info
13865 +#define sk_nid                 __sk_common.skc_nid
13866 +#define sk_nx_info             __sk_common.skc_nx_info
13867         socket_lock_t           sk_lock;
13868         struct sk_buff_head     sk_receive_queue;
13869         /*
13870 diff -NurpP --minimal linux-3.6.9/init/Kconfig linux-3.6.9-vs2.3.4.4/init/Kconfig
13871 --- linux-3.6.9/init/Kconfig    2012-10-04 15:27:48.000000000 +0200
13872 +++ linux-3.6.9-vs2.3.4.4/init/Kconfig  2012-10-04 18:47:00.000000000 +0200
13873 @@ -624,6 +624,7 @@ config HAVE_UNSTABLE_SCHED_CLOCK
13874  menuconfig CGROUPS
13875         boolean "Control Group support"
13876         depends on EVENTFD
13877 +       default y
13878         help
13879           This option adds support for grouping sets of processes together, for
13880           use with process control subsystems such as Cpusets, CFS, memory
13881 @@ -889,6 +890,7 @@ config USER_NS
13882         bool "User namespace (EXPERIMENTAL)"
13883         depends on EXPERIMENTAL
13884         depends on UIDGID_CONVERTED
13885 +       depends on VSERVER_DISABLED
13886         select UIDGID_STRICT_TYPE_CHECKS
13887  
13888         default n
13889 diff -NurpP --minimal linux-3.6.9/init/main.c linux-3.6.9-vs2.3.4.4/init/main.c
13890 --- linux-3.6.9/init/main.c     2012-12-08 01:34:14.000000000 +0100
13891 +++ linux-3.6.9-vs2.3.4.4/init/main.c   2012-11-06 18:43:41.000000000 +0100
13892 @@ -69,6 +69,7 @@
13893  #include <linux/slab.h>
13894  #include <linux/perf_event.h>
13895  #include <linux/file.h>
13896 +#include <linux/vserver/percpu.h>
13897  
13898  #include <asm/io.h>
13899  #include <asm/bugs.h>
13900 diff -NurpP --minimal linux-3.6.9/ipc/mqueue.c linux-3.6.9-vs2.3.4.4/ipc/mqueue.c
13901 --- linux-3.6.9/ipc/mqueue.c    2012-10-04 15:27:48.000000000 +0200
13902 +++ linux-3.6.9-vs2.3.4.4/ipc/mqueue.c  2012-10-04 18:47:00.000000000 +0200
13903 @@ -35,6 +35,8 @@
13904  #include <linux/ipc_namespace.h>
13905  #include <linux/user_namespace.h>
13906  #include <linux/slab.h>
13907 +#include <linux/vs_context.h>
13908 +#include <linux/vs_limit.h>
13909  
13910  #include <net/sock.h>
13911  #include "util.h"
13912 @@ -76,6 +78,7 @@ struct mqueue_inode_info {
13913         struct pid* notify_owner;
13914         struct user_namespace *notify_user_ns;
13915         struct user_struct *user;       /* user who created, for accounting */
13916 +       struct vx_info *vxi;
13917         struct sock *notify_sock;
13918         struct sk_buff *notify_cookie;
13919  
13920 @@ -235,6 +238,7 @@ static struct inode *mqueue_get_inode(st
13921         if (S_ISREG(mode)) {
13922                 struct mqueue_inode_info *info;
13923                 unsigned long mq_bytes, mq_treesize;
13924 +               struct vx_info *vxi = current_vx_info();
13925  
13926                 inode->i_fop = &mqueue_file_operations;
13927                 inode->i_size = FILENT_SIZE;
13928 @@ -248,6 +252,7 @@ static struct inode *mqueue_get_inode(st
13929                 info->notify_user_ns = NULL;
13930                 info->qsize = 0;
13931                 info->user = NULL;      /* set when all is ok */
13932 +               info->vxi = NULL;
13933                 info->msg_tree = RB_ROOT;
13934                 info->node_cache = NULL;
13935                 memset(&info->attr, 0, sizeof(info->attr));
13936 @@ -281,17 +286,20 @@ static struct inode *mqueue_get_inode(st
13937  
13938                 spin_lock(&mq_lock);
13939                 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
13940 -                   u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE)) {
13941 +                   u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE) ||
13942 +                   !vx_ipcmsg_avail(vxi, mq_bytes)) {
13943                         spin_unlock(&mq_lock);
13944                         /* mqueue_evict_inode() releases info->messages */
13945                         ret = -EMFILE;
13946                         goto out_inode;
13947                 }
13948                 u->mq_bytes += mq_bytes;
13949 +               vx_ipcmsg_add(vxi, u, mq_bytes);
13950                 spin_unlock(&mq_lock);
13951  
13952                 /* all is ok */
13953                 info->user = get_uid(u);
13954 +               info->vxi = get_vx_info(vxi);
13955         } else if (S_ISDIR(mode)) {
13956                 inc_nlink(inode);
13957                 /* Some things misbehave if size == 0 on a directory */
13958 @@ -395,8 +403,11 @@ static void mqueue_evict_inode(struct in
13959  
13960         user = info->user;
13961         if (user) {
13962 +               struct vx_info *vxi = info->vxi;
13963 +
13964                 spin_lock(&mq_lock);
13965                 user->mq_bytes -= mq_bytes;
13966 +               vx_ipcmsg_sub(vxi, user, mq_bytes);
13967                 /*
13968                  * get_ns_from_inode() ensures that the
13969                  * (ipc_ns = sb->s_fs_info) is either a valid ipc_ns
13970 @@ -406,6 +417,7 @@ static void mqueue_evict_inode(struct in
13971                 if (ipc_ns)
13972                         ipc_ns->mq_queues_count--;
13973                 spin_unlock(&mq_lock);
13974 +               put_vx_info(vxi);
13975                 free_uid(user);
13976         }
13977         if (ipc_ns)
13978 diff -NurpP --minimal linux-3.6.9/ipc/msg.c linux-3.6.9-vs2.3.4.4/ipc/msg.c
13979 --- linux-3.6.9/ipc/msg.c       2011-05-22 16:17:59.000000000 +0200
13980 +++ linux-3.6.9-vs2.3.4.4/ipc/msg.c     2012-10-04 18:47:00.000000000 +0200
13981 @@ -37,6 +37,7 @@
13982  #include <linux/rwsem.h>
13983  #include <linux/nsproxy.h>
13984  #include <linux/ipc_namespace.h>
13985 +#include <linux/vs_base.h>
13986  
13987  #include <asm/current.h>
13988  #include <asm/uaccess.h>
13989 @@ -190,6 +191,7 @@ static int newque(struct ipc_namespace *
13990  
13991         msq->q_perm.mode = msgflg & S_IRWXUGO;
13992         msq->q_perm.key = key;
13993 +       msq->q_perm.xid = vx_current_xid();
13994  
13995         msq->q_perm.security = NULL;
13996         retval = security_msg_queue_alloc(msq);
13997 diff -NurpP --minimal linux-3.6.9/ipc/namespace.c linux-3.6.9-vs2.3.4.4/ipc/namespace.c
13998 --- linux-3.6.9/ipc/namespace.c 2012-07-22 23:39:46.000000000 +0200
13999 +++ linux-3.6.9-vs2.3.4.4/ipc/namespace.c       2012-10-04 18:47:00.000000000 +0200
14000 @@ -13,11 +13,12 @@
14001  #include <linux/mount.h>
14002  #include <linux/user_namespace.h>
14003  #include <linux/proc_fs.h>
14004 +#include <linux/vs_base.h>
14005 +#include <linux/vserver/global.h>
14006  
14007  #include "util.h"
14008  
14009 -static struct ipc_namespace *create_ipc_ns(struct task_struct *tsk,
14010 -                                          struct ipc_namespace *old_ns)
14011 +static struct ipc_namespace *create_ipc_ns(struct user_namespace *user_ns)
14012  {
14013         struct ipc_namespace *ns;
14014         int err;
14015 @@ -46,19 +47,19 @@ static struct ipc_namespace *create_ipc_
14016         ipcns_notify(IPCNS_CREATED);
14017         register_ipcns_notifier(ns);
14018  
14019 -       ns->user_ns = get_user_ns(task_cred_xxx(tsk, user_ns));
14020 +       // ns->user_ns = get_user_ns(task_cred_xxx(tsk, user_ns));
14021 +       ns->user_ns = get_user_ns(user_ns);
14022  
14023         return ns;
14024  }
14025  
14026  struct ipc_namespace *copy_ipcs(unsigned long flags,
14027 -                               struct task_struct *tsk)
14028 +                               struct ipc_namespace *old_ns,
14029 +                               struct user_namespace *user_ns)
14030  {
14031 -       struct ipc_namespace *ns = tsk->nsproxy->ipc_ns;
14032 -
14033         if (!(flags & CLONE_NEWIPC))
14034 -               return get_ipc_ns(ns);
14035 -       return create_ipc_ns(tsk, ns);
14036 +               return get_ipc_ns(old_ns);
14037 +       return create_ipc_ns(user_ns);
14038  }
14039  
14040  /*
14041 diff -NurpP --minimal linux-3.6.9/ipc/sem.c linux-3.6.9-vs2.3.4.4/ipc/sem.c
14042 --- linux-3.6.9/ipc/sem.c       2012-01-09 16:14:59.000000000 +0100
14043 +++ linux-3.6.9-vs2.3.4.4/ipc/sem.c     2012-10-04 18:47:00.000000000 +0200
14044 @@ -86,6 +86,8 @@
14045  #include <linux/rwsem.h>
14046  #include <linux/nsproxy.h>
14047  #include <linux/ipc_namespace.h>
14048 +#include <linux/vs_base.h>
14049 +#include <linux/vs_limit.h>
14050  
14051  #include <asm/uaccess.h>
14052  #include "util.h"
14053 @@ -306,6 +308,7 @@ static int newary(struct ipc_namespace *
14054  
14055         sma->sem_perm.mode = (semflg & S_IRWXUGO);
14056         sma->sem_perm.key = key;
14057 +       sma->sem_perm.xid = vx_current_xid();
14058  
14059         sma->sem_perm.security = NULL;
14060         retval = security_sem_alloc(sma);
14061 @@ -321,6 +324,9 @@ static int newary(struct ipc_namespace *
14062                 return id;
14063         }
14064         ns->used_sems += nsems;
14065 +       /* FIXME: obsoleted? */
14066 +       vx_semary_inc(sma);
14067 +       vx_nsems_add(sma, nsems);
14068  
14069         sma->sem_base = (struct sem *) &sma[1];
14070  
14071 @@ -770,6 +776,9 @@ static void freeary(struct ipc_namespace
14072  
14073         wake_up_sem_queue_do(&tasks);
14074         ns->used_sems -= sma->sem_nsems;
14075 +       /* FIXME: obsoleted? */
14076 +       vx_nsems_sub(sma, sma->sem_nsems);
14077 +       vx_semary_dec(sma);
14078         security_sem_free(sma);
14079         ipc_rcu_putref(sma);
14080  }
14081 diff -NurpP --minimal linux-3.6.9/ipc/shm.c linux-3.6.9-vs2.3.4.4/ipc/shm.c
14082 --- linux-3.6.9/ipc/shm.c       2012-10-04 15:27:48.000000000 +0200
14083 +++ linux-3.6.9-vs2.3.4.4/ipc/shm.c     2012-10-04 18:47:00.000000000 +0200
14084 @@ -39,6 +39,8 @@
14085  #include <linux/nsproxy.h>
14086  #include <linux/mount.h>
14087  #include <linux/ipc_namespace.h>
14088 +#include <linux/vs_context.h>
14089 +#include <linux/vs_limit.h>
14090  
14091  #include <asm/uaccess.h>
14092  
14093 @@ -187,7 +189,12 @@ static void shm_open(struct vm_area_stru
14094   */
14095  static void shm_destroy(struct ipc_namespace *ns, struct shmid_kernel *shp)
14096  {
14097 -       ns->shm_tot -= (shp->shm_segsz + PAGE_SIZE - 1) >> PAGE_SHIFT;
14098 +       struct vx_info *vxi = lookup_vx_info(shp->shm_perm.xid);
14099 +       int numpages = (shp->shm_segsz + PAGE_SIZE - 1) >> PAGE_SHIFT;
14100 +
14101 +       vx_ipcshm_sub(vxi, shp, numpages);
14102 +       ns->shm_tot -= numpages;
14103 +
14104         shm_rmid(ns, shp);
14105         shm_unlock(shp);
14106         if (!is_file_hugepages(shp->shm_file))
14107 @@ -197,6 +204,7 @@ static void shm_destroy(struct ipc_names
14108                                                 shp->mlock_user);
14109         fput (shp->shm_file);
14110         security_shm_free(shp);
14111 +       put_vx_info(vxi);
14112         ipc_rcu_putref(shp);
14113  }
14114  
14115 @@ -474,11 +482,15 @@ static int newseg(struct ipc_namespace *
14116         if (ns->shm_tot + numpages > ns->shm_ctlall)
14117                 return -ENOSPC;
14118  
14119 +       if (!vx_ipcshm_avail(current_vx_info(), numpages))
14120 +               return -ENOSPC;
14121 +
14122         shp = ipc_rcu_alloc(sizeof(*shp));
14123         if (!shp)
14124                 return -ENOMEM;
14125  
14126         shp->shm_perm.key = key;
14127 +       shp->shm_perm.xid = vx_current_xid();
14128         shp->shm_perm.mode = (shmflg & S_IRWXUGO);
14129         shp->mlock_user = NULL;
14130  
14131 @@ -533,6 +545,7 @@ static int newseg(struct ipc_namespace *
14132         ns->shm_tot += numpages;
14133         error = shp->shm_perm.id;
14134         shm_unlock(shp);
14135 +       vx_ipcshm_add(current_vx_info(), key, numpages);
14136         return error;
14137  
14138  no_id:
14139 diff -NurpP --minimal linux-3.6.9/kernel/Makefile linux-3.6.9-vs2.3.4.4/kernel/Makefile
14140 --- linux-3.6.9/kernel/Makefile 2012-07-22 23:39:46.000000000 +0200
14141 +++ linux-3.6.9-vs2.3.4.4/kernel/Makefile       2012-10-04 18:47:00.000000000 +0200
14142 @@ -24,6 +24,7 @@ endif
14143  
14144  obj-y += sched/
14145  obj-y += power/
14146 +obj-y += vserver/
14147  
14148  ifeq ($(CONFIG_CHECKPOINT_RESTORE),y)
14149  obj-$(CONFIG_X86) += kcmp.o
14150 diff -NurpP --minimal linux-3.6.9/kernel/auditsc.c linux-3.6.9-vs2.3.4.4/kernel/auditsc.c
14151 --- linux-3.6.9/kernel/auditsc.c        2012-07-22 23:39:46.000000000 +0200
14152 +++ linux-3.6.9-vs2.3.4.4/kernel/auditsc.c      2012-10-04 18:47:00.000000000 +0200
14153 @@ -2309,7 +2309,7 @@ int audit_set_loginuid(uid_t loginuid)
14154         if (task->loginuid != -1)
14155                 return -EPERM;
14156  #else /* CONFIG_AUDIT_LOGINUID_IMMUTABLE */
14157 -       if (!capable(CAP_AUDIT_CONTROL))
14158 +       if (!vx_capable(CAP_AUDIT_CONTROL, VXC_AUDIT_CONTROL))
14159                 return -EPERM;
14160  #endif  /* CONFIG_AUDIT_LOGINUID_IMMUTABLE */
14161  
14162 diff -NurpP --minimal linux-3.6.9/kernel/capability.c linux-3.6.9-vs2.3.4.4/kernel/capability.c
14163 --- linux-3.6.9/kernel/capability.c     2012-07-22 23:39:46.000000000 +0200
14164 +++ linux-3.6.9-vs2.3.4.4/kernel/capability.c   2012-10-04 18:47:00.000000000 +0200
14165 @@ -15,6 +15,7 @@
14166  #include <linux/syscalls.h>
14167  #include <linux/pid_namespace.h>
14168  #include <linux/user_namespace.h>
14169 +#include <linux/vs_context.h>
14170  #include <asm/uaccess.h>
14171  
14172  /*
14173 @@ -116,6 +117,7 @@ static int cap_validate_magic(cap_user_h
14174         return 0;
14175  }
14176  
14177 +
14178  /*
14179   * The only thing that can change the capabilities of the current
14180   * process is the current process. As such, we can't be in this code
14181 @@ -349,6 +351,8 @@ bool has_ns_capability_noaudit(struct ta
14182         return (ret == 0);
14183  }
14184  
14185 +#include <linux/vserver/base.h>
14186 +
14187  /**
14188   * has_capability_noaudit - Does a task have a capability (unaudited) in the
14189   * initial user ns
14190 diff -NurpP --minimal linux-3.6.9/kernel/compat.c linux-3.6.9-vs2.3.4.4/kernel/compat.c
14191 --- linux-3.6.9/kernel/compat.c 2012-07-22 23:39:46.000000000 +0200
14192 +++ linux-3.6.9-vs2.3.4.4/kernel/compat.c       2012-10-04 18:47:00.000000000 +0200
14193 @@ -1054,7 +1054,7 @@ asmlinkage long compat_sys_stime(compat_
14194         if (err)
14195                 return err;
14196  
14197 -       do_settimeofday(&tv);
14198 +       vx_settimeofday(&tv);
14199         return 0;
14200  }
14201  
14202 diff -NurpP --minimal linux-3.6.9/kernel/cred.c linux-3.6.9-vs2.3.4.4/kernel/cred.c
14203 --- linux-3.6.9/kernel/cred.c   2012-07-22 23:39:46.000000000 +0200
14204 +++ linux-3.6.9-vs2.3.4.4/kernel/cred.c 2012-10-04 18:47:00.000000000 +0200
14205 @@ -70,31 +70,6 @@ struct cred init_cred = {
14206  #endif
14207  };
14208  
14209 -static inline void set_cred_subscribers(struct cred *cred, int n)
14210 -{
14211 -#ifdef CONFIG_DEBUG_CREDENTIALS
14212 -       atomic_set(&cred->subscribers, n);
14213 -#endif
14214 -}
14215 -
14216 -static inline int read_cred_subscribers(const struct cred *cred)
14217 -{
14218 -#ifdef CONFIG_DEBUG_CREDENTIALS
14219 -       return atomic_read(&cred->subscribers);
14220 -#else
14221 -       return 0;
14222 -#endif
14223 -}
14224 -
14225 -static inline void alter_cred_subscribers(const struct cred *_cred, int n)
14226 -{
14227 -#ifdef CONFIG_DEBUG_CREDENTIALS
14228 -       struct cred *cred = (struct cred *) _cred;
14229 -
14230 -       atomic_add(n, &cred->subscribers);
14231 -#endif
14232 -}
14233 -
14234  /*
14235   * Dispose of the shared task group credentials
14236   */
14237 @@ -284,21 +259,16 @@ error:
14238   *
14239   * Call commit_creds() or abort_creds() to clean up.
14240   */
14241 -struct cred *prepare_creds(void)
14242 +struct cred *__prepare_creds(const struct cred *old)
14243  {
14244 -       struct task_struct *task = current;
14245 -       const struct cred *old;
14246         struct cred *new;
14247  
14248 -       validate_process_creds();
14249 -
14250         new = kmem_cache_alloc(cred_jar, GFP_KERNEL);
14251         if (!new)
14252                 return NULL;
14253  
14254         kdebug("prepare_creds() alloc %p", new);
14255  
14256 -       old = task->cred;
14257         memcpy(new, old, sizeof(struct cred));
14258  
14259         atomic_set(&new->usage, 1);
14260 @@ -326,6 +296,13 @@ error:
14261         abort_creds(new);
14262         return NULL;
14263  }
14264 +
14265 +struct cred *prepare_creds(void)
14266 +{
14267 +       validate_process_creds();
14268 +
14269 +       return __prepare_creds(current->cred);
14270 +}
14271  EXPORT_SYMBOL(prepare_creds);
14272  
14273  /*
14274 diff -NurpP --minimal linux-3.6.9/kernel/exit.c linux-3.6.9-vs2.3.4.4/kernel/exit.c
14275 --- linux-3.6.9/kernel/exit.c   2012-10-04 15:27:48.000000000 +0200
14276 +++ linux-3.6.9-vs2.3.4.4/kernel/exit.c 2012-12-08 01:20:39.000000000 +0100
14277 @@ -48,6 +48,10 @@
14278  #include <linux/fs_struct.h>
14279  #include <linux/init_task.h>
14280  #include <linux/perf_event.h>
14281 +#include <linux/vs_limit.h>
14282 +#include <linux/vs_context.h>
14283 +#include <linux/vs_network.h>
14284 +#include <linux/vs_pid.h>
14285  #include <trace/events/sched.h>
14286  #include <linux/hw_breakpoint.h>
14287  #include <linux/oom.h>
14288 @@ -494,9 +498,11 @@ static void close_files(struct files_str
14289                                         filp_close(file, files);
14290                                         cond_resched();
14291                                 }
14292 +                               vx_openfd_dec(i);
14293                         }
14294                         i++;
14295                         set >>= 1;
14296 +                       cond_resched();
14297                 }
14298         }
14299  }
14300 @@ -711,15 +717,25 @@ static struct task_struct *find_new_reap
14301         __acquires(&tasklist_lock)
14302  {
14303         struct pid_namespace *pid_ns = task_active_pid_ns(father);
14304 -       struct task_struct *thread;
14305 +       struct vx_info *vxi = task_get_vx_info(father);
14306 +       struct task_struct *thread = father;
14307 +       struct task_struct *reaper;
14308  
14309 -       thread = father;
14310         while_each_thread(father, thread) {
14311                 if (thread->flags & PF_EXITING)
14312                         continue;
14313                 if (unlikely(pid_ns->child_reaper == father))
14314                         pid_ns->child_reaper = thread;
14315 -               return thread;
14316 +               reaper = thread;
14317 +               goto out_put;
14318 +       }
14319 +
14320 +       reaper = pid_ns->child_reaper;
14321 +       if (vxi) {
14322 +               BUG_ON(!vxi->vx_reaper);
14323 +               if (vxi->vx_reaper != init_pid_ns.child_reaper &&
14324 +                   vxi->vx_reaper != father)
14325 +                       reaper = vxi->vx_reaper;
14326         }
14327  
14328         if (unlikely(pid_ns->child_reaper == father)) {
14329 @@ -757,7 +773,9 @@ static struct task_struct *find_new_reap
14330                 }
14331         }
14332  
14333 -       return pid_ns->child_reaper;
14334 +out_put:
14335 +       put_vx_info(vxi);
14336 +       return reaper;
14337  }
14338  
14339  /*
14340 @@ -808,10 +826,15 @@ static void forget_original_parent(struc
14341         list_for_each_entry_safe(p, n, &father->children, sibling) {
14342                 struct task_struct *t = p;
14343                 do {
14344 -                       t->real_parent = reaper;
14345 +                       struct task_struct *new_parent = reaper;
14346 +
14347 +                       if (unlikely(p == reaper))
14348 +                               new_parent = task_active_pid_ns(p)->child_reaper;
14349 +
14350 +                       t->real_parent = new_parent;
14351                         if (t->parent == father) {
14352                                 BUG_ON(t->ptrace);
14353 -                               t->parent = t->real_parent;
14354 +                               t->parent = new_parent;
14355                         }
14356                         if (t->pdeath_signal)
14357                                 group_send_sig_info(t->pdeath_signal,
14358 @@ -1018,6 +1041,9 @@ void do_exit(long code)
14359          */
14360         ptrace_put_breakpoints(tsk);
14361  
14362 +       /* needs to stay before exit_notify() */
14363 +       exit_vx_info_early(tsk, code);
14364 +
14365         exit_notify(tsk, group_dead);
14366  #ifdef CONFIG_NUMA
14367         task_lock(tsk);
14368 @@ -1068,10 +1094,15 @@ void do_exit(long code)
14369         smp_mb();
14370         raw_spin_unlock_wait(&tsk->pi_lock);
14371  
14372 +       /* needs to stay after exit_notify() */
14373 +       exit_vx_info(tsk, code);
14374 +       exit_nx_info(tsk);
14375 +
14376         /* causes final put_task_struct in finish_task_switch(). */
14377         tsk->state = TASK_DEAD;
14378         tsk->flags |= PF_NOFREEZE;      /* tell freezer to ignore us */
14379         schedule();
14380 +       printk("bad task: %p [%lx]\n", current, current->state);
14381         BUG();
14382         /* Avoid "noreturn function does return".  */
14383         for (;;)
14384 diff -NurpP --minimal linux-3.6.9/kernel/fork.c linux-3.6.9-vs2.3.4.4/kernel/fork.c
14385 --- linux-3.6.9/kernel/fork.c   2012-10-04 15:27:48.000000000 +0200
14386 +++ linux-3.6.9-vs2.3.4.4/kernel/fork.c 2012-10-04 18:47:00.000000000 +0200
14387 @@ -70,6 +70,9 @@
14388  #include <linux/khugepaged.h>
14389  #include <linux/signalfd.h>
14390  #include <linux/uprobes.h>
14391 +#include <linux/vs_context.h>
14392 +#include <linux/vs_network.h>
14393 +#include <linux/vs_limit.h>
14394  
14395  #include <asm/pgtable.h>
14396  #include <asm/pgalloc.h>
14397 @@ -210,6 +213,8 @@ void free_task(struct task_struct *tsk)
14398         arch_release_thread_info(tsk->stack);
14399         free_thread_info(tsk->stack);
14400         rt_mutex_debug_task_free(tsk);
14401 +       clr_vx_info(&tsk->vx_info);
14402 +       clr_nx_info(&tsk->nx_info);
14403         ftrace_graph_exit_task(tsk);
14404         put_seccomp_filter(tsk);
14405         arch_release_task_struct(tsk);
14406 @@ -541,6 +546,7 @@ static struct mm_struct *mm_init(struct 
14407         if (likely(!mm_alloc_pgd(mm))) {
14408                 mm->def_flags = 0;
14409                 mmu_notifier_mm_init(mm);
14410 +               set_vx_info(&mm->mm_vx_info, p->vx_info);
14411                 return mm;
14412         }
14413  
14414 @@ -593,6 +599,7 @@ void __mmdrop(struct mm_struct *mm)
14415         destroy_context(mm);
14416         mmu_notifier_mm_destroy(mm);
14417         check_mm(mm);
14418 +       clr_vx_info(&mm->mm_vx_info);
14419         free_mm(mm);
14420  }
14421  EXPORT_SYMBOL_GPL(__mmdrop);
14422 @@ -834,6 +841,7 @@ struct mm_struct *dup_mm(struct task_str
14423                 goto fail_nomem;
14424  
14425         memcpy(mm, oldmm, sizeof(*mm));
14426 +       mm->mm_vx_info = NULL;
14427         mm_init_cpumask(mm);
14428  
14429  #ifdef CONFIG_TRANSPARENT_HUGEPAGE
14430 @@ -874,6 +882,7 @@ fail_nocontext:
14431          * If init_new_context() failed, we cannot use mmput() to free the mm
14432          * because it calls destroy_context()
14433          */
14434 +       clr_vx_info(&mm->mm_vx_info);
14435         mm_free_pgd(mm);
14436         free_mm(mm);
14437         return NULL;
14438 @@ -1157,6 +1166,8 @@ static struct task_struct *copy_process(
14439         int retval;
14440         struct task_struct *p;
14441         int cgroup_callbacks_done = 0;
14442 +       struct vx_info *vxi;
14443 +       struct nx_info *nxi;
14444  
14445         if ((clone_flags & (CLONE_NEWNS|CLONE_FS)) == (CLONE_NEWNS|CLONE_FS))
14446                 return ERR_PTR(-EINVAL);
14447 @@ -1204,7 +1215,12 @@ static struct task_struct *copy_process(
14448         DEBUG_LOCKS_WARN_ON(!p->hardirqs_enabled);
14449         DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
14450  #endif
14451 +       init_vx_info(&p->vx_info, current_vx_info());
14452 +       init_nx_info(&p->nx_info, current_nx_info());
14453 +
14454         retval = -EAGAIN;
14455 +       if (!vx_nproc_avail(1))
14456 +               goto bad_fork_free;
14457         if (atomic_read(&p->real_cred->user->processes) >=
14458                         task_rlimit(p, RLIMIT_NPROC)) {
14459                 if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE) &&
14460 @@ -1483,6 +1499,18 @@ static struct task_struct *copy_process(
14461  
14462         total_forks++;
14463         spin_unlock(&current->sighand->siglock);
14464 +
14465 +       /* p is copy of current */
14466 +       vxi = p->vx_info;
14467 +       if (vxi) {
14468 +               claim_vx_info(vxi, p);
14469 +               atomic_inc(&vxi->cvirt.nr_threads);
14470 +               atomic_inc(&vxi->cvirt.total_forks);
14471 +               vx_nproc_inc(p);
14472 +       }
14473 +       nxi = p->nx_info;
14474 +       if (nxi)
14475 +               claim_nx_info(nxi, p);
14476         write_unlock_irq(&tasklist_lock);
14477         proc_fork_connector(p);
14478         cgroup_post_fork(p);
14479 diff -NurpP --minimal linux-3.6.9/kernel/kthread.c linux-3.6.9-vs2.3.4.4/kernel/kthread.c
14480 --- linux-3.6.9/kernel/kthread.c        2012-10-04 15:27:48.000000000 +0200
14481 +++ linux-3.6.9-vs2.3.4.4/kernel/kthread.c      2012-10-04 18:47:00.000000000 +0200
14482 @@ -16,6 +16,7 @@
14483  #include <linux/mutex.h>
14484  #include <linux/slab.h>
14485  #include <linux/freezer.h>
14486 +#include <linux/vs_pid.h>
14487  #include <trace/events/sched.h>
14488  
14489  static DEFINE_SPINLOCK(kthread_create_lock);
14490 diff -NurpP --minimal linux-3.6.9/kernel/nsproxy.c linux-3.6.9-vs2.3.4.4/kernel/nsproxy.c
14491 --- linux-3.6.9/kernel/nsproxy.c        2012-01-09 16:15:00.000000000 +0100
14492 +++ linux-3.6.9-vs2.3.4.4/kernel/nsproxy.c      2012-10-04 18:47:00.000000000 +0200
14493 @@ -20,11 +20,14 @@
14494  #include <linux/mnt_namespace.h>
14495  #include <linux/utsname.h>
14496  #include <linux/pid_namespace.h>
14497 +#include <linux/vserver/global.h>
14498 +#include <linux/vserver/debug.h>
14499  #include <net/net_namespace.h>
14500  #include <linux/ipc_namespace.h>
14501  #include <linux/proc_fs.h>
14502  #include <linux/file.h>
14503  #include <linux/syscalls.h>
14504 +#include "../fs/mount.h"
14505  
14506  static struct kmem_cache *nsproxy_cachep;
14507  
14508 @@ -46,8 +49,11 @@ static inline struct nsproxy *create_nsp
14509         struct nsproxy *nsproxy;
14510  
14511         nsproxy = kmem_cache_alloc(nsproxy_cachep, GFP_KERNEL);
14512 -       if (nsproxy)
14513 +       if (nsproxy) {
14514                 atomic_set(&nsproxy->count, 1);
14515 +               atomic_inc(&vs_global_nsproxy);
14516 +       }
14517 +       vxdprintk(VXD_CBIT(space, 2), "create_nsproxy = %p[1]", nsproxy);
14518         return nsproxy;
14519  }
14520  
14521 @@ -56,8 +62,11 @@ static inline struct nsproxy *create_nsp
14522   * Return the newly created nsproxy.  Do not attach this to the task,
14523   * leave it to the caller to do proper locking and attach it to task.
14524   */
14525 -static struct nsproxy *create_new_namespaces(unsigned long flags,
14526 -                       struct task_struct *tsk, struct fs_struct *new_fs)
14527 +static struct nsproxy *unshare_namespaces(unsigned long flags,
14528 +                       struct nsproxy *orig,
14529 +                       struct fs_struct *new_fs,
14530 +                       struct user_namespace *new_user,
14531 +                       struct pid_namespace *new_pid)
14532  {
14533         struct nsproxy *new_nsp;
14534         int err;
14535 @@ -66,31 +75,31 @@ static struct nsproxy *create_new_namesp
14536         if (!new_nsp)
14537                 return ERR_PTR(-ENOMEM);
14538  
14539 -       new_nsp->mnt_ns = copy_mnt_ns(flags, tsk->nsproxy->mnt_ns, new_fs);
14540 +       new_nsp->mnt_ns = copy_mnt_ns(flags, orig->mnt_ns, new_fs);
14541         if (IS_ERR(new_nsp->mnt_ns)) {
14542                 err = PTR_ERR(new_nsp->mnt_ns);
14543                 goto out_ns;
14544         }
14545  
14546 -       new_nsp->uts_ns = copy_utsname(flags, tsk);
14547 +       new_nsp->uts_ns = copy_utsname(flags, orig->uts_ns, new_user);
14548         if (IS_ERR(new_nsp->uts_ns)) {
14549                 err = PTR_ERR(new_nsp->uts_ns);
14550                 goto out_uts;
14551         }
14552  
14553 -       new_nsp->ipc_ns = copy_ipcs(flags, tsk);
14554 +       new_nsp->ipc_ns = copy_ipcs(flags, orig->ipc_ns, new_user);
14555         if (IS_ERR(new_nsp->ipc_ns)) {
14556                 err = PTR_ERR(new_nsp->ipc_ns);
14557                 goto out_ipc;
14558         }
14559  
14560 -       new_nsp->pid_ns = copy_pid_ns(flags, task_active_pid_ns(tsk));
14561 +       new_nsp->pid_ns = copy_pid_ns(flags, new_pid);
14562         if (IS_ERR(new_nsp->pid_ns)) {
14563                 err = PTR_ERR(new_nsp->pid_ns);
14564                 goto out_pid;
14565         }
14566  
14567 -       new_nsp->net_ns = copy_net_ns(flags, tsk->nsproxy->net_ns);
14568 +       new_nsp->net_ns = copy_net_ns(flags, orig->net_ns);
14569         if (IS_ERR(new_nsp->net_ns)) {
14570                 err = PTR_ERR(new_nsp->net_ns);
14571                 goto out_net;
14572 @@ -115,6 +124,40 @@ out_ns:
14573         return ERR_PTR(err);
14574  }
14575  
14576 +static struct nsproxy *create_new_namespaces(unsigned long flags,
14577 +                       struct task_struct *tsk, struct fs_struct *new_fs)
14578 +{
14579 +       return unshare_namespaces(flags, tsk->nsproxy,
14580 +               new_fs, task_cred_xxx(tsk, user_ns),
14581 +               task_active_pid_ns(tsk));
14582 +}
14583 +
14584 +/*
14585 + * copies the nsproxy, setting refcount to 1, and grabbing a
14586 + * reference to all contained namespaces.
14587 + */
14588 +struct nsproxy *copy_nsproxy(struct nsproxy *orig)
14589 +{
14590 +       struct nsproxy *ns = create_nsproxy();
14591 +
14592 +       if (ns) {
14593 +               memcpy(ns, orig, sizeof(struct nsproxy));
14594 +               atomic_set(&ns->count, 1);
14595 +
14596 +               if (ns->mnt_ns)
14597 +                       get_mnt_ns(ns->mnt_ns);
14598 +               if (ns->uts_ns)
14599 +                       get_uts_ns(ns->uts_ns);
14600 +               if (ns->ipc_ns)
14601 +                       get_ipc_ns(ns->ipc_ns);
14602 +               if (ns->pid_ns)
14603 +                       get_pid_ns(ns->pid_ns);
14604 +               if (ns->net_ns)
14605 +                       get_net(ns->net_ns);
14606 +       }
14607 +       return ns;
14608 +}
14609 +
14610  /*
14611   * called from clone.  This now handles copy for nsproxy and all
14612   * namespaces therein.
14613 @@ -122,9 +165,12 @@ out_ns:
14614  int copy_namespaces(unsigned long flags, struct task_struct *tsk)
14615  {
14616         struct nsproxy *old_ns = tsk->nsproxy;
14617 -       struct nsproxy *new_ns;
14618 +       struct nsproxy *new_ns = NULL;
14619         int err = 0;
14620  
14621 +       vxdprintk(VXD_CBIT(space, 7), "copy_namespaces(0x%08lx,%p[%p])",
14622 +               flags, tsk, old_ns);
14623 +
14624         if (!old_ns)
14625                 return 0;
14626  
14627 @@ -134,7 +180,7 @@ int copy_namespaces(unsigned long flags,
14628                                 CLONE_NEWPID | CLONE_NEWNET)))
14629                 return 0;
14630  
14631 -       if (!capable(CAP_SYS_ADMIN)) {
14632 +       if (!vx_can_unshare(CAP_SYS_ADMIN, flags)) {
14633                 err = -EPERM;
14634                 goto out;
14635         }
14636 @@ -161,6 +207,9 @@ int copy_namespaces(unsigned long flags,
14637  
14638  out:
14639         put_nsproxy(old_ns);
14640 +       vxdprintk(VXD_CBIT(space, 3),
14641 +               "copy_namespaces(0x%08lx,%p[%p]) = %d [%p]",
14642 +               flags, tsk, old_ns, err, new_ns);
14643         return err;
14644  }
14645  
14646 @@ -174,7 +223,9 @@ void free_nsproxy(struct nsproxy *ns)
14647                 put_ipc_ns(ns->ipc_ns);
14648         if (ns->pid_ns)
14649                 put_pid_ns(ns->pid_ns);
14650 -       put_net(ns->net_ns);
14651 +       if (ns->net_ns)
14652 +               put_net(ns->net_ns);
14653 +       atomic_dec(&vs_global_nsproxy);
14654         kmem_cache_free(nsproxy_cachep, ns);
14655  }
14656  
14657 @@ -187,11 +238,15 @@ int unshare_nsproxy_namespaces(unsigned 
14658  {
14659         int err = 0;
14660  
14661 +       vxdprintk(VXD_CBIT(space, 4),
14662 +               "unshare_nsproxy_namespaces(0x%08lx,[%p])",
14663 +               unshare_flags, current->nsproxy);
14664 +
14665         if (!(unshare_flags & (CLONE_NEWNS | CLONE_NEWUTS | CLONE_NEWIPC |
14666                                CLONE_NEWNET)))
14667                 return 0;
14668  
14669 -       if (!capable(CAP_SYS_ADMIN))
14670 +       if (!vx_can_unshare(CAP_SYS_ADMIN, unshare_flags))
14671                 return -EPERM;
14672  
14673         *new_nsp = create_new_namespaces(unshare_flags, current,
14674 diff -NurpP --minimal linux-3.6.9/kernel/pid.c linux-3.6.9-vs2.3.4.4/kernel/pid.c
14675 --- linux-3.6.9/kernel/pid.c    2012-07-22 23:39:46.000000000 +0200
14676 +++ linux-3.6.9-vs2.3.4.4/kernel/pid.c  2012-10-04 18:47:00.000000000 +0200
14677 @@ -36,6 +36,7 @@
14678  #include <linux/pid_namespace.h>
14679  #include <linux/init_task.h>
14680  #include <linux/syscalls.h>
14681 +#include <linux/vs_pid.h>
14682  
14683  #define pid_hashfn(nr, ns)     \
14684         hash_long((unsigned long)nr + (unsigned long)ns, pidhash_shift)
14685 @@ -344,7 +345,7 @@ EXPORT_SYMBOL_GPL(find_pid_ns);
14686  
14687  struct pid *find_vpid(int nr)
14688  {
14689 -       return find_pid_ns(nr, current->nsproxy->pid_ns);
14690 +       return find_pid_ns(vx_rmap_pid(nr), current->nsproxy->pid_ns);
14691  }
14692  EXPORT_SYMBOL_GPL(find_vpid);
14693  
14694 @@ -404,6 +405,9 @@ void transfer_pid(struct task_struct *ol
14695  struct task_struct *pid_task(struct pid *pid, enum pid_type type)
14696  {
14697         struct task_struct *result = NULL;
14698 +
14699 +       if (type == PIDTYPE_REALPID)
14700 +               type = PIDTYPE_PID;
14701         if (pid) {
14702                 struct hlist_node *first;
14703                 first = rcu_dereference_check(hlist_first_rcu(&pid->tasks[type]),
14704 @@ -423,7 +427,7 @@ struct task_struct *find_task_by_pid_ns(
14705         rcu_lockdep_assert(rcu_read_lock_held(),
14706                            "find_task_by_pid_ns() needs rcu_read_lock()"
14707                            " protection");
14708 -       return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
14709 +       return pid_task(find_pid_ns(vx_rmap_pid(nr), ns), PIDTYPE_PID);
14710  }
14711  
14712  struct task_struct *find_task_by_vpid(pid_t vnr)
14713 @@ -467,7 +471,7 @@ struct pid *find_get_pid(pid_t nr)
14714  }
14715  EXPORT_SYMBOL_GPL(find_get_pid);
14716  
14717 -pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns)
14718 +pid_t pid_unmapped_nr_ns(struct pid *pid, struct pid_namespace *ns)
14719  {
14720         struct upid *upid;
14721         pid_t nr = 0;
14722 @@ -480,6 +484,11 @@ pid_t pid_nr_ns(struct pid *pid, struct 
14723         return nr;
14724  }
14725  
14726 +pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns)
14727 +{
14728 +       return vx_map_pid(pid_unmapped_nr_ns(pid, ns));
14729 +}
14730 +
14731  pid_t pid_vnr(struct pid *pid)
14732  {
14733         return pid_nr_ns(pid, current->nsproxy->pid_ns);
14734 diff -NurpP --minimal linux-3.6.9/kernel/pid_namespace.c linux-3.6.9-vs2.3.4.4/kernel/pid_namespace.c
14735 --- linux-3.6.9/kernel/pid_namespace.c  2012-10-04 15:27:48.000000000 +0200
14736 +++ linux-3.6.9-vs2.3.4.4/kernel/pid_namespace.c        2012-10-04 18:47:00.000000000 +0200
14737 @@ -16,6 +16,7 @@
14738  #include <linux/slab.h>
14739  #include <linux/proc_fs.h>
14740  #include <linux/reboot.h>
14741 +#include <linux/vserver/global.h>
14742  
14743  #define BITS_PER_PAGE          (PAGE_SIZE*8)
14744  
14745 @@ -89,6 +90,7 @@ static struct pid_namespace *create_pid_
14746                 goto out_free_map;
14747  
14748         kref_init(&ns->kref);
14749 +       atomic_inc(&vs_global_pid_ns);
14750         ns->level = level;
14751         ns->parent = get_pid_ns(parent_pid_ns);
14752  
14753 @@ -120,6 +122,7 @@ static void destroy_pid_namespace(struct
14754  
14755         for (i = 0; i < PIDMAP_ENTRIES; i++)
14756                 kfree(ns->pidmap[i].page);
14757 +       atomic_dec(&vs_global_pid_ns);
14758         kmem_cache_free(pid_ns_cachep, ns);
14759  }
14760  
14761 diff -NurpP --minimal linux-3.6.9/kernel/posix-timers.c linux-3.6.9-vs2.3.4.4/kernel/posix-timers.c
14762 --- linux-3.6.9/kernel/posix-timers.c   2012-01-09 16:15:00.000000000 +0100
14763 +++ linux-3.6.9-vs2.3.4.4/kernel/posix-timers.c 2012-10-04 18:47:00.000000000 +0200
14764 @@ -47,6 +47,7 @@
14765  #include <linux/wait.h>
14766  #include <linux/workqueue.h>
14767  #include <linux/export.h>
14768 +#include <linux/vs_context.h>
14769  
14770  /*
14771   * Management arrays for POSIX timers.  Timers are kept in slab memory
14772 @@ -340,6 +341,7 @@ int posix_timer_event(struct k_itimer *t
14773  {
14774         struct task_struct *task;
14775         int shared, ret = -1;
14776 +
14777         /*
14778          * FIXME: if ->sigq is queued we can race with
14779          * dequeue_signal()->do_schedule_next_timer().
14780 @@ -356,10 +358,18 @@ int posix_timer_event(struct k_itimer *t
14781         rcu_read_lock();
14782         task = pid_task(timr->it_pid, PIDTYPE_PID);
14783         if (task) {
14784 +               struct vx_info_save vxis;
14785 +               struct vx_info *vxi;
14786 +
14787 +               vxi = get_vx_info(task->vx_info);
14788 +               enter_vx_info(vxi, &vxis);
14789                 shared = !(timr->it_sigev_notify & SIGEV_THREAD_ID);
14790                 ret = send_sigqueue(timr->sigq, task, shared);
14791 +               leave_vx_info(&vxis);
14792 +               put_vx_info(vxi);
14793         }
14794         rcu_read_unlock();
14795 +
14796         /* If we failed to send the signal the timer stops. */
14797         return ret > 0;
14798  }
14799 diff -NurpP --minimal linux-3.6.9/kernel/printk.c linux-3.6.9-vs2.3.4.4/kernel/printk.c
14800 --- linux-3.6.9/kernel/printk.c 2012-10-04 15:27:48.000000000 +0200
14801 +++ linux-3.6.9-vs2.3.4.4/kernel/printk.c       2012-10-04 18:47:00.000000000 +0200
14802 @@ -42,6 +42,7 @@
14803  #include <linux/notifier.h>
14804  #include <linux/rculist.h>
14805  #include <linux/poll.h>
14806 +#include <linux/vs_cvirt.h>
14807  
14808  #include <asm/uaccess.h>
14809  
14810 @@ -818,7 +819,7 @@ static int check_syslog_permissions(int 
14811                 return 0;
14812  
14813         if (syslog_action_restricted(type)) {
14814 -               if (capable(CAP_SYSLOG))
14815 +               if (vx_capable(CAP_SYSLOG, VXC_SYSLOG))
14816                         return 0;
14817                 /* For historical reasons, accept CAP_SYS_ADMIN too, with a warning */
14818                 if (capable(CAP_SYS_ADMIN)) {
14819 @@ -1111,12 +1112,9 @@ int do_syslog(int type, char __user *buf
14820         if (error)
14821                 return error;
14822  
14823 -       switch (type) {
14824 -       case SYSLOG_ACTION_CLOSE:       /* Close log */
14825 -               break;
14826 -       case SYSLOG_ACTION_OPEN:        /* Open log */
14827 -               break;
14828 -       case SYSLOG_ACTION_READ:        /* Read from log */
14829 +       if ((type == SYSLOG_ACTION_READ) ||
14830 +           (type == SYSLOG_ACTION_READ_ALL) ||
14831 +           (type == SYSLOG_ACTION_READ_CLEAR)) {
14832                 error = -EINVAL;
14833                 if (!buf || len < 0)
14834                         goto out;
14835 @@ -1127,6 +1125,16 @@ int do_syslog(int type, char __user *buf
14836                         error = -EFAULT;
14837                         goto out;
14838                 }
14839 +       }
14840 +       if (!vx_check(0, VS_ADMIN|VS_WATCH))
14841 +               return vx_do_syslog(type, buf, len);
14842 +
14843 +       switch (type) {
14844 +       case SYSLOG_ACTION_CLOSE:       /* Close log */
14845 +               break;
14846 +       case SYSLOG_ACTION_OPEN:        /* Open log */
14847 +               break;
14848 +       case SYSLOG_ACTION_READ:        /* Read from log */
14849                 error = wait_event_interruptible(log_wait,
14850                                                  syslog_seq != log_next_seq);
14851                 if (error)
14852 @@ -1139,16 +1147,6 @@ int do_syslog(int type, char __user *buf
14853                 /* FALL THRU */
14854         /* Read last kernel messages */
14855         case SYSLOG_ACTION_READ_ALL:
14856 -               error = -EINVAL;
14857 -               if (!buf || len < 0)
14858 -                       goto out;
14859 -               error = 0;
14860 -               if (!len)
14861 -                       goto out;
14862 -               if (!access_ok(VERIFY_WRITE, buf, len)) {
14863 -                       error = -EFAULT;
14864 -                       goto out;
14865 -               }
14866                 error = syslog_print_all(buf, len, clear);
14867                 break;
14868         /* Clear ring buffer */
14869 diff -NurpP --minimal linux-3.6.9/kernel/ptrace.c linux-3.6.9-vs2.3.4.4/kernel/ptrace.c
14870 --- linux-3.6.9/kernel/ptrace.c 2012-07-22 23:39:46.000000000 +0200
14871 +++ linux-3.6.9-vs2.3.4.4/kernel/ptrace.c       2012-10-04 18:47:00.000000000 +0200
14872 @@ -22,6 +22,7 @@
14873  #include <linux/syscalls.h>
14874  #include <linux/uaccess.h>
14875  #include <linux/regset.h>
14876 +#include <linux/vs_context.h>
14877  #include <linux/hw_breakpoint.h>
14878  #include <linux/cn_proc.h>
14879  
14880 @@ -216,6 +217,11 @@ ok:
14881                 dumpable = get_dumpable(task->mm);
14882         if (!dumpable  && !ptrace_has_cap(task_user_ns(task), mode))
14883                 return -EPERM;
14884 +       if (!vx_check(task->xid, VS_ADMIN_P|VS_WATCH_P|VS_IDENT))
14885 +               return -EPERM;
14886 +       if (!vx_check(task->xid, VS_IDENT) &&
14887 +               !task_vx_flags(task, VXF_STATE_ADMIN, 0))
14888 +               return -EACCES;
14889  
14890         return security_ptrace_access_check(task, mode);
14891  }
14892 diff -NurpP --minimal linux-3.6.9/kernel/sched/core.c linux-3.6.9-vs2.3.4.4/kernel/sched/core.c
14893 --- linux-3.6.9/kernel/sched/core.c     2012-12-08 01:34:15.000000000 +0100
14894 +++ linux-3.6.9-vs2.3.4.4/kernel/sched/core.c   2012-11-06 18:43:41.000000000 +0100
14895 @@ -72,6 +72,8 @@
14896  #include <linux/slab.h>
14897  #include <linux/init_task.h>
14898  #include <linux/binfmts.h>
14899 +#include <linux/vs_sched.h>
14900 +#include <linux/vs_cvirt.h>
14901  
14902  #include <asm/switch_to.h>
14903  #include <asm/tlb.h>
14904 @@ -2223,9 +2225,17 @@ EXPORT_SYMBOL(avenrun); /* should be rem
14905   */
14906  void get_avenrun(unsigned long *loads, unsigned long offset, int shift)
14907  {
14908 -       loads[0] = (avenrun[0] + offset) << shift;
14909 -       loads[1] = (avenrun[1] + offset) << shift;
14910 -       loads[2] = (avenrun[2] + offset) << shift;
14911 +       if (vx_flags(VXF_VIRT_LOAD, 0)) {
14912 +               struct vx_info *vxi = current_vx_info();
14913 +
14914 +               loads[0] = (vxi->cvirt.load[0] + offset) << shift;
14915 +               loads[1] = (vxi->cvirt.load[1] + offset) << shift;
14916 +               loads[2] = (vxi->cvirt.load[2] + offset) << shift;
14917 +       } else {
14918 +               loads[0] = (avenrun[0] + offset) << shift;
14919 +               loads[1] = (avenrun[1] + offset) << shift;
14920 +               loads[2] = (avenrun[2] + offset) << shift;
14921 +       }
14922  }
14923  
14924  static long calc_load_fold_active(struct rq *this_rq)
14925 @@ -2854,14 +2864,17 @@ static inline void task_group_account_fi
14926  void account_user_time(struct task_struct *p, cputime_t cputime,
14927                        cputime_t cputime_scaled)
14928  {
14929 +       struct vx_info *vxi = p->vx_info;  /* p is _always_ current */
14930 +       int nice = (TASK_NICE(p) > 0);
14931         int index;
14932  
14933         /* Add user time to process. */
14934         p->utime += cputime;
14935         p->utimescaled += cputime_scaled;
14936 +       vx_account_user(vxi, cputime, nice);
14937         account_group_user_time(p, cputime);
14938  
14939 -       index = (TASK_NICE(p) > 0) ? CPUTIME_NICE : CPUTIME_USER;
14940 +       index = (nice) ? CPUTIME_NICE : CPUTIME_USER;
14941  
14942         /* Add user time to cpustat. */
14943         task_group_account_field(p, index, (__force u64) cputime);
14944 @@ -2908,9 +2921,12 @@ static inline
14945  void __account_system_time(struct task_struct *p, cputime_t cputime,
14946                         cputime_t cputime_scaled, int index)
14947  {
14948 +       struct vx_info *vxi = p->vx_info;  /* p is _always_ current */
14949 +
14950         /* Add system time to process. */
14951         p->stime += cputime;
14952         p->stimescaled += cputime_scaled;
14953 +       vx_account_system(vxi, cputime, 0 /* do we have idle time? */);
14954         account_group_system_time(p, cputime);
14955  
14956         /* Add system time to cpustat. */
14957 @@ -4137,7 +4153,7 @@ SYSCALL_DEFINE1(nice, int, increment)
14958                 nice = 19;
14959  
14960         if (increment < 0 && !can_nice(current, nice))
14961 -               return -EPERM;
14962 +               return vx_flags(VXF_IGNEG_NICE, 0) ? 0 : -EPERM;
14963  
14964         retval = security_task_setnice(current, nice);
14965         if (retval)
14966 diff -NurpP --minimal linux-3.6.9/kernel/sched/fair.c linux-3.6.9-vs2.3.4.4/kernel/sched/fair.c
14967 --- linux-3.6.9/kernel/sched/fair.c     2012-10-04 15:27:48.000000000 +0200
14968 +++ linux-3.6.9-vs2.3.4.4/kernel/sched/fair.c   2012-10-04 18:47:00.000000000 +0200
14969 @@ -26,6 +26,7 @@
14970  #include <linux/slab.h>
14971  #include <linux/profile.h>
14972  #include <linux/interrupt.h>
14973 +#include <linux/vs_cvirt.h>
14974  
14975  #include <trace/events/sched.h>
14976  
14977 @@ -1111,6 +1112,8 @@ enqueue_entity(struct cfs_rq *cfs_rq, st
14978                 __enqueue_entity(cfs_rq, se);
14979         se->on_rq = 1;
14980  
14981 +       if (entity_is_task(se))
14982 +               vx_activate_task(task_of(se));
14983         if (cfs_rq->nr_running == 1) {
14984                 list_add_leaf_cfs_rq(cfs_rq);
14985                 check_enqueue_throttle(cfs_rq);
14986 @@ -1191,6 +1194,8 @@ dequeue_entity(struct cfs_rq *cfs_rq, st
14987         if (se != cfs_rq->curr)
14988                 __dequeue_entity(cfs_rq, se);
14989         se->on_rq = 0;
14990 +       if (entity_is_task(se))
14991 +               vx_deactivate_task(task_of(se));
14992         update_cfs_load(cfs_rq, 0);
14993         account_entity_dequeue(cfs_rq, se);
14994  
14995 diff -NurpP --minimal linux-3.6.9/kernel/signal.c linux-3.6.9-vs2.3.4.4/kernel/signal.c
14996 --- linux-3.6.9/kernel/signal.c 2012-10-04 15:27:48.000000000 +0200
14997 +++ linux-3.6.9-vs2.3.4.4/kernel/signal.c       2012-10-04 18:47:00.000000000 +0200
14998 @@ -30,6 +30,8 @@
14999  #include <linux/nsproxy.h>
15000  #include <linux/user_namespace.h>
15001  #include <linux/uprobes.h>
15002 +#include <linux/vs_context.h>
15003 +#include <linux/vs_pid.h>
15004  #define CREATE_TRACE_POINTS
15005  #include <trace/events/signal.h>
15006  
15007 @@ -790,9 +792,18 @@ static int check_kill_permission(int sig
15008         struct pid *sid;
15009         int error;
15010  
15011 +       vxdprintk(VXD_CBIT(misc, 7),
15012 +               "check_kill_permission(%d,%p,%p[#%u,%u])",
15013 +               sig, info, t, vx_task_xid(t), t->pid);
15014 +
15015         if (!valid_signal(sig))
15016                 return -EINVAL;
15017  
15018 +/*     FIXME: needed? if so, why?
15019 +       if ((info != SEND_SIG_NOINFO) &&
15020 +               (is_si_special(info) || !si_fromuser(info)))
15021 +               goto skip;      */
15022 +
15023         if (!si_fromuser(info))
15024                 return 0;
15025  
15026 @@ -816,6 +827,20 @@ static int check_kill_permission(int sig
15027                 }
15028         }
15029  
15030 +       error = -EPERM;
15031 +       if (t->pid == 1 && current->xid)
15032 +               return error;
15033 +
15034 +       error = -ESRCH;
15035 +       /* FIXME: we shouldn't return ESRCH ever, to avoid
15036 +                 loops, maybe ENOENT or EACCES? */
15037 +       if (!vx_check(vx_task_xid(t), VS_WATCH_P | VS_IDENT)) {
15038 +               vxdprintk(current->xid || VXD_CBIT(misc, 7),
15039 +                       "signal %d[%p] xid mismatch %p[#%u,%u] xid=#%u",
15040 +                       sig, info, t, vx_task_xid(t), t->pid, current->xid);
15041 +               return error;
15042 +       }
15043 +/* skip: */
15044         return security_task_kill(t, info, sig, 0);
15045  }
15046  
15047 @@ -1351,7 +1376,7 @@ int kill_pid_info(int sig, struct siginf
15048         rcu_read_lock();
15049  retry:
15050         p = pid_task(pid, PIDTYPE_PID);
15051 -       if (p) {
15052 +       if (p && vx_check(vx_task_xid(p), VS_IDENT)) {
15053                 error = group_send_sig_info(sig, info, p);
15054                 if (unlikely(error == -ESRCH))
15055                         /*
15056 @@ -1399,7 +1424,7 @@ int kill_pid_info_as_cred(int sig, struc
15057  
15058         rcu_read_lock();
15059         p = pid_task(pid, PIDTYPE_PID);
15060 -       if (!p) {
15061 +       if (!p || !vx_check(vx_task_xid(p), VS_IDENT)) {
15062                 ret = -ESRCH;
15063                 goto out_unlock;
15064         }
15065 @@ -1451,8 +1476,10 @@ static int kill_something_info(int sig, 
15066                 struct task_struct * p;
15067  
15068                 for_each_process(p) {
15069 -                       if (task_pid_vnr(p) > 1 &&
15070 -                                       !same_thread_group(p, current)) {
15071 +                       if (vx_check(vx_task_xid(p), VS_ADMIN|VS_IDENT) &&
15072 +                               task_pid_vnr(p) > 1 &&
15073 +                               !same_thread_group(p, current) &&
15074 +                               !vx_current_initpid(p->pid)) {
15075                                 int err = group_send_sig_info(sig, info, p);
15076                                 ++count;
15077                                 if (err != -EPERM)
15078 @@ -2317,6 +2344,11 @@ relock:
15079                                 !sig_kernel_only(signr))
15080                         continue;
15081  
15082 +               /* virtual init is protected against user signals */
15083 +               if ((info->si_code == SI_USER) &&
15084 +                       vx_current_initpid(current->pid))
15085 +                       continue;
15086 +
15087                 if (sig_kernel_stop(signr)) {
15088                         /*
15089                          * The default action is to stop all threads in
15090 diff -NurpP --minimal linux-3.6.9/kernel/softirq.c linux-3.6.9-vs2.3.4.4/kernel/softirq.c
15091 --- linux-3.6.9/kernel/softirq.c        2012-10-04 15:27:48.000000000 +0200
15092 +++ linux-3.6.9-vs2.3.4.4/kernel/softirq.c      2012-10-04 18:47:00.000000000 +0200
15093 @@ -24,6 +24,7 @@
15094  #include <linux/ftrace.h>
15095  #include <linux/smp.h>
15096  #include <linux/tick.h>
15097 +#include <linux/vs_context.h>
15098  
15099  #define CREATE_TRACE_POINTS
15100  #include <trace/events/irq.h>
15101 diff -NurpP --minimal linux-3.6.9/kernel/sys.c linux-3.6.9-vs2.3.4.4/kernel/sys.c
15102 --- linux-3.6.9/kernel/sys.c    2012-12-08 01:34:15.000000000 +0100
15103 +++ linux-3.6.9-vs2.3.4.4/kernel/sys.c  2012-11-06 18:43:41.000000000 +0100
15104 @@ -47,6 +47,7 @@
15105  #include <linux/syscalls.h>
15106  #include <linux/kprobes.h>
15107  #include <linux/user_namespace.h>
15108 +#include <linux/vs_pid.h>
15109  
15110  #include <linux/kmsg_dump.h>
15111  /* Move somewhere else to avoid recompiling? */
15112 @@ -154,7 +155,10 @@ static int set_one_prio(struct task_stru
15113                 goto out;
15114         }
15115         if (niceval < task_nice(p) && !can_nice(p, niceval)) {
15116 -               error = -EACCES;
15117 +               if (vx_flags(VXF_IGNEG_NICE, 0))
15118 +                       error = 0;
15119 +               else
15120 +                       error = -EACCES;
15121                 goto out;
15122         }
15123         no_nice = security_task_setnice(p, niceval);
15124 @@ -205,6 +209,8 @@ SYSCALL_DEFINE3(setpriority, int, which,
15125                         else
15126                                 pgrp = task_pgrp(current);
15127                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
15128 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
15129 +                                       continue;
15130                                 error = set_one_prio(p, niceval, error);
15131                         } while_each_pid_thread(pgrp, PIDTYPE_PGID, p);
15132                         break;
15133 @@ -270,6 +276,8 @@ SYSCALL_DEFINE2(getpriority, int, which,
15134                         else
15135                                 pgrp = task_pgrp(current);
15136                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
15137 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
15138 +                                       continue;
15139                                 niceval = 20 - task_nice(p);
15140                                 if (niceval > retval)
15141                                         retval = niceval;
15142 @@ -422,6 +430,8 @@ EXPORT_SYMBOL_GPL(kernel_power_off);
15143  
15144  static DEFINE_MUTEX(reboot_mutex);
15145  
15146 +long vs_reboot(unsigned int, void __user *);
15147 +
15148  /*
15149   * Reboot system call: for obvious reasons only root may call it,
15150   * and even root needs to set up some magic numbers in the registers
15151 @@ -463,6 +473,9 @@ SYSCALL_DEFINE4(reboot, int, magic1, int
15152         if ((cmd == LINUX_REBOOT_CMD_POWER_OFF) && !pm_power_off)
15153                 cmd = LINUX_REBOOT_CMD_HALT;
15154  
15155 +       if (!vx_check(0, VS_ADMIN|VS_WATCH))
15156 +               return vs_reboot(cmd, arg);
15157 +
15158         mutex_lock(&reboot_mutex);
15159         switch (cmd) {
15160         case LINUX_REBOOT_CMD_RESTART:
15161 @@ -1370,7 +1383,8 @@ SYSCALL_DEFINE2(sethostname, char __user
15162         int errno;
15163         char tmp[__NEW_UTS_LEN];
15164  
15165 -       if (!ns_capable(current->nsproxy->uts_ns->user_ns, CAP_SYS_ADMIN))
15166 +       if (!vx_ns_capable(current->nsproxy->uts_ns->user_ns,
15167 +               CAP_SYS_ADMIN, VXC_SET_UTSNAME))
15168                 return -EPERM;
15169  
15170         if (len < 0 || len > __NEW_UTS_LEN)
15171 @@ -1421,7 +1435,8 @@ SYSCALL_DEFINE2(setdomainname, char __us
15172         int errno;
15173         char tmp[__NEW_UTS_LEN];
15174  
15175 -       if (!ns_capable(current->nsproxy->uts_ns->user_ns, CAP_SYS_ADMIN))
15176 +       if (!vx_ns_capable(current->nsproxy->uts_ns->user_ns,
15177 +               CAP_SYS_ADMIN, VXC_SET_UTSNAME))
15178                 return -EPERM;
15179         if (len < 0 || len > __NEW_UTS_LEN)
15180                 return -EINVAL;
15181 @@ -1540,7 +1555,7 @@ int do_prlimit(struct task_struct *tsk, 
15182                 /* Keep the capable check against init_user_ns until
15183                    cgroups can contain all limits */
15184                 if (new_rlim->rlim_max > rlim->rlim_max &&
15185 -                               !capable(CAP_SYS_RESOURCE))
15186 +                       !vx_capable(CAP_SYS_RESOURCE, VXC_SET_RLIMIT))
15187                         retval = -EPERM;
15188                 if (!retval)
15189                         retval = security_task_setrlimit(tsk->group_leader,
15190 @@ -1593,7 +1608,8 @@ static int check_prlimit_permission(stru
15191             gid_eq(cred->gid, tcred->sgid) &&
15192             gid_eq(cred->gid, tcred->gid))
15193                 return 0;
15194 -       if (ns_capable(tcred->user_ns, CAP_SYS_RESOURCE))
15195 +       if (vx_ns_capable(tcred->user_ns,
15196 +               CAP_SYS_RESOURCE, VXC_SET_RLIMIT))
15197                 return 0;
15198  
15199         return -EPERM;
15200 diff -NurpP --minimal linux-3.6.9/kernel/sysctl.c linux-3.6.9-vs2.3.4.4/kernel/sysctl.c
15201 --- linux-3.6.9/kernel/sysctl.c 2012-10-04 15:27:48.000000000 +0200
15202 +++ linux-3.6.9-vs2.3.4.4/kernel/sysctl.c       2012-10-04 18:47:00.000000000 +0200
15203 @@ -82,6 +82,7 @@
15204  #if defined(CONFIG_PROVE_LOCKING) || defined(CONFIG_LOCK_STAT)
15205  #include <linux/lockdep.h>
15206  #endif
15207 +extern char vshelper_path[];
15208  #ifdef CONFIG_CHR_DEV_SG
15209  #include <scsi/sg.h>
15210  #endif
15211 @@ -568,6 +569,13 @@ static struct ctl_table kern_table[] = {
15212                 .proc_handler   = proc_dostring,
15213         },
15214  #endif
15215 +       {
15216 +               .procname       = "vshelper",
15217 +               .data           = &vshelper_path,
15218 +               .maxlen         = 256,
15219 +               .mode           = 0644,
15220 +               .proc_handler   = &proc_dostring,
15221 +       },
15222  #ifdef CONFIG_CHR_DEV_SG
15223         {
15224                 .procname       = "sg-big-buff",
15225 diff -NurpP --minimal linux-3.6.9/kernel/sysctl_binary.c linux-3.6.9-vs2.3.4.4/kernel/sysctl_binary.c
15226 --- linux-3.6.9/kernel/sysctl_binary.c  2012-10-04 15:27:48.000000000 +0200
15227 +++ linux-3.6.9-vs2.3.4.4/kernel/sysctl_binary.c        2012-10-04 18:47:00.000000000 +0200
15228 @@ -73,6 +73,7 @@ static const struct bin_table bin_kern_t
15229  
15230         { CTL_INT,      KERN_PANIC,                     "panic" },
15231         { CTL_INT,      KERN_REALROOTDEV,               "real-root-dev" },
15232 +       { CTL_STR,      KERN_VSHELPER,                  "vshelper" },
15233  
15234         { CTL_STR,      KERN_SPARC_REBOOT,              "reboot-cmd" },
15235         { CTL_INT,      KERN_CTLALTDEL,                 "ctrl-alt-del" },
15236 diff -NurpP --minimal linux-3.6.9/kernel/time/timekeeping.c linux-3.6.9-vs2.3.4.4/kernel/time/timekeeping.c
15237 --- linux-3.6.9/kernel/time/timekeeping.c       2012-12-08 01:34:15.000000000 +0100
15238 +++ linux-3.6.9-vs2.3.4.4/kernel/time/timekeeping.c     2012-11-06 18:43:41.000000000 +0100
15239 @@ -309,6 +309,7 @@ void getnstimeofday(struct timespec *ts)
15240  
15241         ts->tv_nsec = 0;
15242         timespec_add_ns(ts, nsecs);
15243 +       vx_adjust_timespec(ts);
15244  }
15245  EXPORT_SYMBOL(getnstimeofday);
15246  
15247 diff -NurpP --minimal linux-3.6.9/kernel/time.c linux-3.6.9-vs2.3.4.4/kernel/time.c
15248 --- linux-3.6.9/kernel/time.c   2012-05-21 18:07:34.000000000 +0200
15249 +++ linux-3.6.9-vs2.3.4.4/kernel/time.c 2012-10-04 18:47:00.000000000 +0200
15250 @@ -92,7 +92,7 @@ SYSCALL_DEFINE1(stime, time_t __user *, 
15251         if (err)
15252                 return err;
15253  
15254 -       do_settimeofday(&tv);
15255 +       vx_settimeofday(&tv);
15256         return 0;
15257  }
15258  
15259 @@ -172,7 +172,7 @@ int do_sys_settimeofday(const struct tim
15260                 }
15261         }
15262         if (tv)
15263 -               return do_settimeofday(tv);
15264 +               return vx_settimeofday(tv);
15265         return 0;
15266  }
15267  
15268 diff -NurpP --minimal linux-3.6.9/kernel/timer.c linux-3.6.9-vs2.3.4.4/kernel/timer.c
15269 --- linux-3.6.9/kernel/timer.c  2012-12-08 01:34:15.000000000 +0100
15270 +++ linux-3.6.9-vs2.3.4.4/kernel/timer.c        2012-11-06 18:43:41.000000000 +0100
15271 @@ -40,6 +40,10 @@
15272  #include <linux/irq_work.h>
15273  #include <linux/sched.h>
15274  #include <linux/slab.h>
15275 +#include <linux/vs_base.h>
15276 +#include <linux/vs_cvirt.h>
15277 +#include <linux/vs_pid.h>
15278 +#include <linux/vserver/sched.h>
15279  
15280  #include <asm/uaccess.h>
15281  #include <asm/unistd.h>
15282 diff -NurpP --minimal linux-3.6.9/kernel/user_namespace.c linux-3.6.9-vs2.3.4.4/kernel/user_namespace.c
15283 --- linux-3.6.9/kernel/user_namespace.c 2012-07-22 23:39:47.000000000 +0200
15284 +++ linux-3.6.9-vs2.3.4.4/kernel/user_namespace.c       2012-10-04 18:47:00.000000000 +0200
15285 @@ -19,6 +19,7 @@
15286  #include <linux/fs.h>
15287  #include <linux/uaccess.h>
15288  #include <linux/ctype.h>
15289 +#include <linux/vserver/global.h>
15290  
15291  static struct kmem_cache *user_ns_cachep __read_mostly;
15292  
15293 @@ -52,6 +53,7 @@ int create_user_ns(struct cred *new)
15294                 return -ENOMEM;
15295  
15296         kref_init(&ns->kref);
15297 +       atomic_inc(&vs_global_user_ns);
15298         ns->parent = parent_ns;
15299         ns->owner = owner;
15300         ns->group = group;
15301 @@ -84,6 +86,9 @@ void free_user_ns(struct kref *kref)
15302  
15303         parent = ns->parent;
15304         kmem_cache_free(user_ns_cachep, ns);
15305 +
15306 +       /* FIXME: maybe move into destroyer? */
15307 +       atomic_dec(&vs_global_user_ns);
15308         put_user_ns(parent);
15309  }
15310  EXPORT_SYMBOL(free_user_ns);
15311 diff -NurpP --minimal linux-3.6.9/kernel/utsname.c linux-3.6.9-vs2.3.4.4/kernel/utsname.c
15312 --- linux-3.6.9/kernel/utsname.c        2012-07-22 23:39:47.000000000 +0200
15313 +++ linux-3.6.9-vs2.3.4.4/kernel/utsname.c      2012-10-04 18:47:00.000000000 +0200
15314 @@ -16,14 +16,17 @@
15315  #include <linux/slab.h>
15316  #include <linux/user_namespace.h>
15317  #include <linux/proc_fs.h>
15318 +#include <linux/vserver/global.h>
15319  
15320  static struct uts_namespace *create_uts_ns(void)
15321  {
15322         struct uts_namespace *uts_ns;
15323  
15324         uts_ns = kmalloc(sizeof(struct uts_namespace), GFP_KERNEL);
15325 -       if (uts_ns)
15326 +       if (uts_ns) {
15327                 kref_init(&uts_ns->kref);
15328 +               atomic_inc(&vs_global_uts_ns);
15329 +       }
15330         return uts_ns;
15331  }
15332  
15333 @@ -32,8 +35,8 @@ static struct uts_namespace *create_uts_
15334   * @old_ns: namespace to clone
15335   * Return NULL on error (failure to kmalloc), new ns otherwise
15336   */
15337 -static struct uts_namespace *clone_uts_ns(struct task_struct *tsk,
15338 -                                         struct uts_namespace *old_ns)
15339 +static struct uts_namespace *clone_uts_ns(struct uts_namespace *old_ns,
15340 +                                         struct user_namespace *old_user)
15341  {
15342         struct uts_namespace *ns;
15343  
15344 @@ -43,7 +46,7 @@ static struct uts_namespace *clone_uts_n
15345  
15346         down_read(&uts_sem);
15347         memcpy(&ns->name, &old_ns->name, sizeof(ns->name));
15348 -       ns->user_ns = get_user_ns(task_cred_xxx(tsk, user_ns));
15349 +       ns->user_ns = get_user_ns(old_user);
15350         up_read(&uts_sem);
15351         return ns;
15352  }
15353 @@ -55,9 +58,9 @@ static struct uts_namespace *clone_uts_n
15354   * versa.
15355   */
15356  struct uts_namespace *copy_utsname(unsigned long flags,
15357 -                                  struct task_struct *tsk)
15358 +                                  struct uts_namespace *old_ns,
15359 +                                  struct user_namespace *user_ns)
15360  {
15361 -       struct uts_namespace *old_ns = tsk->nsproxy->uts_ns;
15362         struct uts_namespace *new_ns;
15363  
15364         BUG_ON(!old_ns);
15365 @@ -66,7 +69,7 @@ struct uts_namespace *copy_utsname(unsig
15366         if (!(flags & CLONE_NEWUTS))
15367                 return old_ns;
15368  
15369 -       new_ns = clone_uts_ns(tsk, old_ns);
15370 +       new_ns = clone_uts_ns(old_ns, user_ns);
15371  
15372         put_uts_ns(old_ns);
15373         return new_ns;
15374 @@ -78,6 +81,7 @@ void free_uts_ns(struct kref *kref)
15375  
15376         ns = container_of(kref, struct uts_namespace, kref);
15377         put_user_ns(ns->user_ns);
15378 +       atomic_dec(&vs_global_uts_ns);
15379         kfree(ns);
15380  }
15381  
15382 diff -NurpP --minimal linux-3.6.9/kernel/vserver/Kconfig linux-3.6.9-vs2.3.4.4/kernel/vserver/Kconfig
15383 --- linux-3.6.9/kernel/vserver/Kconfig  1970-01-01 01:00:00.000000000 +0100
15384 +++ linux-3.6.9-vs2.3.4.4/kernel/vserver/Kconfig        2012-10-04 18:47:00.000000000 +0200
15385 @@ -0,0 +1,224 @@
15386 +#
15387 +# Linux VServer configuration
15388 +#
15389 +
15390 +menu "Linux VServer"
15391 +
15392 +config VSERVER_AUTO_LBACK
15393 +       bool    "Automatically Assign Loopback IP"
15394 +       default y
15395 +       help
15396 +         Automatically assign a guest specific loopback
15397 +         IP and add it to the kernel network stack on
15398 +         startup.
15399 +
15400 +config VSERVER_AUTO_SINGLE
15401 +       bool    "Automatic Single IP Special Casing"
15402 +       depends on EXPERIMENTAL
15403 +       default y
15404 +       help
15405 +         This allows network contexts with a single IP to
15406 +         automatically remap 0.0.0.0 bindings to that IP,
15407 +         avoiding further network checks and improving
15408 +         performance.
15409 +
15410 +         (note: such guests do not allow to change the ip
15411 +          on the fly and do not show loopback addresses)
15412 +
15413 +config VSERVER_COWBL
15414 +       bool    "Enable COW Immutable Link Breaking"
15415 +       default y
15416 +       help
15417 +         This enables the COW (Copy-On-Write) link break code.
15418 +         It allows you to treat unified files like normal files
15419 +         when writing to them (which will implicitely break the
15420 +         link and create a copy of the unified file)
15421 +
15422 +config VSERVER_VTIME
15423 +       bool    "Enable Virtualized Guest Time"
15424 +       depends on EXPERIMENTAL
15425 +       default n
15426 +       help
15427 +         This enables per guest time offsets to allow for
15428 +         adjusting the system clock individually per guest.
15429 +         this adds some overhead to the time functions and
15430 +         therefore should not be enabled without good reason.
15431 +
15432 +config VSERVER_DEVICE
15433 +       bool    "Enable Guest Device Mapping"
15434 +       depends on EXPERIMENTAL
15435 +       default n
15436 +       help
15437 +         This enables generic device remapping.
15438 +
15439 +config VSERVER_PROC_SECURE
15440 +       bool    "Enable Proc Security"
15441 +       depends on PROC_FS
15442 +       default y
15443 +       help
15444 +         This configures ProcFS security to initially hide
15445 +         non-process entries for all contexts except the main and
15446 +         spectator context (i.e. for all guests), which is a secure
15447 +         default.
15448 +
15449 +         (note: on 1.2x the entries were visible by default)
15450 +
15451 +choice
15452 +       prompt  "Persistent Inode Tagging"
15453 +       default TAGGING_ID24
15454 +       help
15455 +         This adds persistent context information to filesystems
15456 +         mounted with the tagxid option. Tagging is a requirement
15457 +         for per-context disk limits and per-context quota.
15458 +
15459 +
15460 +config TAGGING_NONE
15461 +       bool    "Disabled"
15462 +       help
15463 +         do not store per-context information in inodes.
15464 +
15465 +config TAGGING_UID16
15466 +       bool    "UID16/GID32"
15467 +       help
15468 +         reduces UID to 16 bit, but leaves GID at 32 bit.
15469 +
15470 +config TAGGING_GID16
15471 +       bool    "UID32/GID16"
15472 +       help
15473 +         reduces GID to 16 bit, but leaves UID at 32 bit.
15474 +
15475 +config TAGGING_ID24
15476 +       bool    "UID24/GID24"
15477 +       help
15478 +         uses the upper 8bit from UID and GID for XID tagging
15479 +         which leaves 24bit for UID/GID each, which should be
15480 +         more than sufficient for normal use.
15481 +
15482 +config TAGGING_INTERN
15483 +       bool    "UID32/GID32"
15484 +       help
15485 +         this uses otherwise reserved inode fields in the on
15486 +         disk representation, which limits the use to a few
15487 +         filesystems (currently ext2 and ext3)
15488 +
15489 +endchoice
15490 +
15491 +config TAG_NFSD
15492 +       bool    "Tag NFSD User Auth and Files"
15493 +       default n
15494 +       help
15495 +         Enable this if you do want the in-kernel NFS
15496 +         Server to use the tagging specified above.
15497 +         (will require patched clients too)
15498 +
15499 +config VSERVER_PRIVACY
15500 +       bool    "Honor Privacy Aspects of Guests"
15501 +       default n
15502 +       help
15503 +         When enabled, most context checks will disallow
15504 +         access to structures assigned to a specific context,
15505 +         like ptys or loop devices.
15506 +
15507 +config VSERVER_CONTEXTS
15508 +       int     "Maximum number of Contexts (1-65533)"  if EMBEDDED
15509 +       range 1 65533
15510 +       default "768"   if 64BIT
15511 +       default "256"
15512 +       help
15513 +         This setting will optimize certain data structures
15514 +         and memory allocations according to the expected
15515 +         maximum.
15516 +
15517 +         note: this is not a strict upper limit.
15518 +
15519 +config VSERVER_WARN
15520 +       bool    "VServer Warnings"
15521 +       default y
15522 +       help
15523 +         This enables various runtime warnings, which will
15524 +         notify about potential manipulation attempts or
15525 +         resource shortage. It is generally considered to
15526 +         be a good idea to have that enabled.
15527 +
15528 +config VSERVER_WARN_DEVPTS
15529 +       bool    "VServer DevPTS Warnings"
15530 +       depends on VSERVER_WARN
15531 +       default y
15532 +       help
15533 +         This enables DevPTS related warnings, issued when a
15534 +         process inside a context tries to lookup or access
15535 +         a dynamic pts from the host or a different context.
15536 +
15537 +config VSERVER_DEBUG
15538 +       bool    "VServer Debugging Code"
15539 +       default n
15540 +       help
15541 +         Set this to yes if you want to be able to activate
15542 +         debugging output at runtime. It adds a very small
15543 +         overhead to all vserver related functions and
15544 +         increases the kernel size by about 20k.
15545 +
15546 +config VSERVER_HISTORY
15547 +       bool    "VServer History Tracing"
15548 +       depends on VSERVER_DEBUG
15549 +       default n
15550 +       help
15551 +         Set this to yes if you want to record the history of
15552 +         linux-vserver activities, so they can be replayed in
15553 +         the event of a kernel panic or oops.
15554 +
15555 +config VSERVER_HISTORY_SIZE
15556 +       int     "Per-CPU History Size (32-65536)"
15557 +       depends on VSERVER_HISTORY
15558 +       range 32 65536
15559 +       default 64
15560 +       help
15561 +         This allows you to specify the number of entries in
15562 +         the per-CPU history buffer.
15563 +
15564 +choice
15565 +       prompt  "Quotes used in debug and warn messages"
15566 +       default QUOTES_ISO8859
15567 +
15568 +config QUOTES_ISO8859
15569 +       bool    "Extended ASCII (ISO 8859) angle quotes"
15570 +       help
15571 +         This uses the extended ASCII characters \xbb
15572 +         and \xab for quoting file and process names.
15573 +
15574 +config QUOTES_UTF8
15575 +       bool    "UTF-8 angle quotes"
15576 +       help
15577 +         This uses the the UTF-8 sequences for angle
15578 +         quotes to quote file and process names.
15579 +
15580 +config QUOTES_ASCII
15581 +       bool    "ASCII single quotes"
15582 +       help
15583 +         This uses the ASCII single quote character
15584 +         (\x27) to quote file and process names.
15585 +
15586 +endchoice
15587 +
15588 +endmenu
15589 +
15590 +
15591 +config VSERVER
15592 +       bool
15593 +       default y
15594 +       select NAMESPACES
15595 +       select UTS_NS
15596 +       select IPC_NS
15597 +#      select USER_NS
15598 +       select SYSVIPC
15599 +
15600 +config VSERVER_SECURITY
15601 +       bool
15602 +       depends on SECURITY
15603 +       default y
15604 +       select SECURITY_CAPABILITIES
15605 +
15606 +config VSERVER_DISABLED
15607 +       bool
15608 +       default n
15609 +
15610 diff -NurpP --minimal linux-3.6.9/kernel/vserver/Makefile linux-3.6.9-vs2.3.4.4/kernel/vserver/Makefile
15611 --- linux-3.6.9/kernel/vserver/Makefile 1970-01-01 01:00:00.000000000 +0100
15612 +++ linux-3.6.9-vs2.3.4.4/kernel/vserver/Makefile       2012-10-04 18:47:00.000000000 +0200
15613 @@ -0,0 +1,18 @@
15614 +#
15615 +# Makefile for the Linux vserver routines.
15616 +#
15617 +
15618 +
15619 +obj-y          += vserver.o
15620 +
15621 +vserver-y      := switch.o context.o space.o sched.o network.o inode.o \
15622 +                  limit.o cvirt.o cacct.o signal.o helper.o init.o \
15623 +                  dlimit.o tag.o
15624 +
15625 +vserver-$(CONFIG_INET) += inet.o
15626 +vserver-$(CONFIG_PROC_FS) += proc.o
15627 +vserver-$(CONFIG_VSERVER_DEBUG) += sysctl.o debug.o
15628 +vserver-$(CONFIG_VSERVER_HISTORY) += history.o
15629 +vserver-$(CONFIG_VSERVER_MONITOR) += monitor.o
15630 +vserver-$(CONFIG_VSERVER_DEVICE) += device.o
15631 +
15632 diff -NurpP --minimal linux-3.6.9/kernel/vserver/cacct.c linux-3.6.9-vs2.3.4.4/kernel/vserver/cacct.c
15633 --- linux-3.6.9/kernel/vserver/cacct.c  1970-01-01 01:00:00.000000000 +0100
15634 +++ linux-3.6.9-vs2.3.4.4/kernel/vserver/cacct.c        2012-10-04 18:47:00.000000000 +0200
15635 @@ -0,0 +1,42 @@
15636 +/*
15637 + *  linux/kernel/vserver/cacct.c
15638 + *
15639 + *  Virtual Server: Context Accounting
15640 + *
15641 + *  Copyright (C) 2006-2007 Herbert Pötzl
15642 + *
15643 + *  V0.01  added accounting stats
15644 + *
15645 + */
15646 +
15647 +#include <linux/types.h>
15648 +#include <linux/vs_context.h>
15649 +#include <linux/vserver/cacct_cmd.h>
15650 +#include <linux/vserver/cacct_int.h>
15651 +
15652 +#include <asm/errno.h>
15653 +#include <asm/uaccess.h>
15654 +
15655 +
15656 +int vc_sock_stat(struct vx_info *vxi, void __user *data)
15657 +{
15658 +       struct vcmd_sock_stat_v0 vc_data;
15659 +       int j, field;
15660 +
15661 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
15662 +               return -EFAULT;
15663 +
15664 +       field = vc_data.field;
15665 +       if ((field < 0) || (field >= VXA_SOCK_SIZE))
15666 +               return -EINVAL;
15667 +
15668 +       for (j = 0; j < 3; j++) {
15669 +               vc_data.count[j] = vx_sock_count(&vxi->cacct, field, j);
15670 +               vc_data.total[j] = vx_sock_total(&vxi->cacct, field, j);
15671 +       }
15672 +
15673 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
15674 +               return -EFAULT;
15675 +       return 0;
15676 +}
15677 +
15678 diff -NurpP --minimal linux-3.6.9/kernel/vserver/cacct_init.h linux-3.6.9-vs2.3.4.4/kernel/vserver/cacct_init.h
15679 --- linux-3.6.9/kernel/vserver/cacct_init.h     1970-01-01 01:00:00.000000000 +0100
15680 +++ linux-3.6.9-vs2.3.4.4/kernel/vserver/cacct_init.h   2012-10-04 18:47:00.000000000 +0200
15681 @@ -0,0 +1,25 @@
15682 +
15683 +
15684 +static inline void vx_info_init_cacct(struct _vx_cacct *cacct)
15685 +{
15686 +       int i, j;
15687 +
15688 +
15689 +       for (i = 0; i < VXA_SOCK_SIZE; i++) {
15690 +               for (j = 0; j < 3; j++) {
15691 +                       atomic_long_set(&cacct->sock[i][j].count, 0);
15692 +                       atomic_long_set(&cacct->sock[i][j].total, 0);
15693 +               }
15694 +       }
15695 +       for (i = 0; i < 8; i++)
15696 +               atomic_set(&cacct->slab[i], 0);
15697 +       for (i = 0; i < 5; i++)
15698 +               for (j = 0; j < 4; j++)
15699 +                       atomic_set(&cacct->page[i][j], 0);
15700 +}
15701 +
15702 +static inline void vx_info_exit_cacct(struct _vx_cacct *cacct)
15703 +{
15704 +       return;
15705 +}
15706 +
15707 diff -NurpP --minimal linux-3.6.9/kernel/vserver/cacct_proc.h linux-3.6.9-vs2.3.4.4/kernel/vserver/cacct_proc.h
15708 --- linux-3.6.9/kernel/vserver/cacct_proc.h     1970-01-01 01:00:00.000000000 +0100
15709 +++ linux-3.6.9-vs2.3.4.4/kernel/vserver/cacct_proc.h   2012-10-04 18:47:00.000000000 +0200
15710 @@ -0,0 +1,53 @@
15711 +#ifndef _VX_CACCT_PROC_H
15712 +#define _VX_CACCT_PROC_H
15713 +
15714 +#include <linux/vserver/cacct_int.h>
15715 +
15716 +
15717 +#define VX_SOCKA_TOP   \
15718 +       "Type\t    recv #/bytes\t\t   send #/bytes\t\t    fail #/bytes\n"
15719 +
15720 +static inline int vx_info_proc_cacct(struct _vx_cacct *cacct, char *buffer)
15721 +{
15722 +       int i, j, length = 0;
15723 +       static char *type[VXA_SOCK_SIZE] = {
15724 +               "UNSPEC", "UNIX", "INET", "INET6", "PACKET", "OTHER"
15725 +       };
15726 +
15727 +       length += sprintf(buffer + length, VX_SOCKA_TOP);
15728 +       for (i = 0; i < VXA_SOCK_SIZE; i++) {
15729 +               length += sprintf(buffer + length, "%s:", type[i]);
15730 +               for (j = 0; j < 3; j++) {
15731 +                       length += sprintf(buffer + length,
15732 +                               "\t%10lu/%-10lu",
15733 +                               vx_sock_count(cacct, i, j),
15734 +                               vx_sock_total(cacct, i, j));
15735 +               }
15736 +               buffer[length++] = '\n';
15737 +       }
15738 +
15739 +       length += sprintf(buffer + length, "\n");
15740 +       length += sprintf(buffer + length,
15741 +               "slab:\t %8u %8u %8u %8u\n",
15742 +               atomic_read(&cacct->slab[1]),
15743 +               atomic_read(&cacct->slab[4]),
15744 +               atomic_read(&cacct->slab[0]),
15745 +               atomic_read(&cacct->slab[2]));
15746 +
15747 +       length += sprintf(buffer + length, "\n");
15748 +       for (i = 0; i < 5; i++) {
15749 +               length += sprintf(buffer + length,
15750 +                       "page[%d]: %8u %8u %8u %8u\t %8u %8u %8u %8u\n", i,
15751 +                       atomic_read(&cacct->page[i][0]),
15752 +                       atomic_read(&cacct->page[i][1]),
15753 +                       atomic_read(&cacct->page[i][2]),
15754 +                       atomic_read(&cacct->page[i][3]),
15755 +                       atomic_read(&cacct->page[i][4]),
15756 +                       atomic_read(&cacct->page[i][5]),
15757 +                       atomic_read(&cacct->page[i][6]),
15758 +                       atomic_read(&cacct->page[i][7]));
15759 +       }
15760 +       return length;
15761 +}
15762 +
15763 +#endif /* _VX_CACCT_PROC_H */
15764 diff -NurpP --minimal linux-3.6.9/kernel/vserver/context.c linux-3.6.9-vs2.3.4.4/kernel/vserver/context.c
15765 --- linux-3.6.9/kernel/vserver/context.c        1970-01-01 01:00:00.000000000 +0100
15766 +++ linux-3.6.9-vs2.3.4.4/kernel/vserver/context.c      2012-10-04 18:47:00.000000000 +0200
15767 @@ -0,0 +1,1119 @@
15768 +/*
15769 + *  linux/kernel/vserver/context.c
15770 + *
15771 + *  Virtual Server: Context Support
15772 + *
15773 + *  Copyright (C) 2003-2011  Herbert Pötzl
15774 + *
15775 + *  V0.01  context helper
15776 + *  V0.02  vx_ctx_kill syscall command
15777 + *  V0.03  replaced context_info calls
15778 + *  V0.04  redesign of struct (de)alloc
15779 + *  V0.05  rlimit basic implementation
15780 + *  V0.06  task_xid and info commands
15781 + *  V0.07  context flags and caps
15782 + *  V0.08  switch to RCU based hash
15783 + *  V0.09  revert to non RCU for now
15784 + *  V0.10  and back to working RCU hash
15785 + *  V0.11  and back to locking again
15786 + *  V0.12  referenced context store
15787 + *  V0.13  separate per cpu data
15788 + *  V0.14  changed vcmds to vxi arg
15789 + *  V0.15  added context stat
15790 + *  V0.16  have __create claim() the vxi
15791 + *  V0.17  removed older and legacy stuff
15792 + *  V0.18  added user credentials
15793 + *  V0.19  added warn mask
15794 + *
15795 + */
15796 +
15797 +#include <linux/slab.h>
15798 +#include <linux/types.h>
15799 +#include <linux/security.h>
15800 +#include <linux/pid_namespace.h>
15801 +#include <linux/capability.h>
15802 +
15803 +#include <linux/vserver/context.h>
15804 +#include <linux/vserver/network.h>
15805 +#include <linux/vserver/debug.h>
15806 +#include <linux/vserver/limit.h>
15807 +#include <linux/vserver/limit_int.h>
15808 +#include <linux/vserver/space.h>
15809 +#include <linux/init_task.h>
15810 +#include <linux/fs_struct.h>
15811 +#include <linux/cred.h>
15812 +
15813 +#include <linux/vs_context.h>
15814 +#include <linux/vs_limit.h>
15815 +#include <linux/vs_pid.h>
15816 +#include <linux/vserver/context_cmd.h>
15817 +
15818 +#include "cvirt_init.h"
15819 +#include "cacct_init.h"
15820 +#include "limit_init.h"
15821 +#include "sched_init.h"
15822 +
15823 +
15824 +atomic_t vx_global_ctotal      = ATOMIC_INIT(0);
15825 +atomic_t vx_global_cactive     = ATOMIC_INIT(0);
15826 +
15827 +
15828 +/*     now inactive context structures */
15829 +
15830 +static struct hlist_head vx_info_inactive = HLIST_HEAD_INIT;
15831 +
15832 +static DEFINE_SPINLOCK(vx_info_inactive_lock);
15833 +
15834 +
15835 +/*     __alloc_vx_info()
15836 +
15837 +       * allocate an initialized vx_info struct
15838 +       * doesn't make it visible (hash)                        */
15839 +
15840 +static struct vx_info *__alloc_vx_info(xid_t xid)
15841 +{
15842 +       struct vx_info *new = NULL;
15843 +       int cpu, index;
15844 +
15845 +       vxdprintk(VXD_CBIT(xid, 0), "alloc_vx_info(%d)*", xid);
15846 +
15847 +       /* would this benefit from a slab cache? */
15848 +       new = kmalloc(sizeof(struct vx_info), GFP_KERNEL);
15849 +       if (!new)
15850 +               return 0;
15851 +
15852 +       memset(new, 0, sizeof(struct vx_info));
15853 +#ifdef CONFIG_SMP
15854 +       new->ptr_pc = alloc_percpu(struct _vx_info_pc);
15855 +       if (!new->ptr_pc)
15856 +               goto error;
15857 +#endif
15858 +       new->vx_id = xid;
15859 +       INIT_HLIST_NODE(&new->vx_hlist);
15860 +       atomic_set(&new->vx_usecnt, 0);
15861 +       atomic_set(&new->vx_tasks, 0);
15862 +       new->vx_parent = NULL;
15863 +       new->vx_state = 0;
15864 +       init_waitqueue_head(&new->vx_wait);
15865 +
15866 +       /* prepare reaper */
15867 +       get_task_struct(init_pid_ns.child_reaper);
15868 +       new->vx_reaper = init_pid_ns.child_reaper;
15869 +       new->vx_badness_bias = 0;
15870 +
15871 +       /* rest of init goes here */
15872 +       vx_info_init_limit(&new->limit);
15873 +       vx_info_init_sched(&new->sched);
15874 +       vx_info_init_cvirt(&new->cvirt);
15875 +       vx_info_init_cacct(&new->cacct);
15876 +
15877 +       /* per cpu data structures */
15878 +       for_each_possible_cpu(cpu) {
15879 +               vx_info_init_sched_pc(
15880 +                       &vx_per_cpu(new, sched_pc, cpu), cpu);
15881 +               vx_info_init_cvirt_pc(
15882 +                       &vx_per_cpu(new, cvirt_pc, cpu), cpu);
15883 +       }
15884 +
15885 +       new->vx_flags = VXF_INIT_SET;
15886 +       new->vx_bcaps = CAP_FULL_SET;   // maybe ~CAP_SETPCAP
15887 +       new->vx_ccaps = 0;
15888 +       new->vx_umask = 0;
15889 +       new->vx_wmask = 0;
15890 +
15891 +       new->reboot_cmd = 0;
15892 +       new->exit_code = 0;
15893 +
15894 +       // preconfig spaces
15895 +       for (index = 0; index < VX_SPACES; index++) {
15896 +               struct _vx_space *space = &new->space[index];
15897 +
15898 +               // filesystem
15899 +               spin_lock(&init_fs.lock);
15900 +               init_fs.users++;
15901 +               spin_unlock(&init_fs.lock);
15902 +               space->vx_fs = &init_fs;
15903 +
15904 +               /* FIXME: do we want defaults? */
15905 +               // space->vx_real_cred = 0;
15906 +               // space->vx_cred = 0;
15907 +       }
15908 +
15909 +
15910 +       vxdprintk(VXD_CBIT(xid, 0),
15911 +               "alloc_vx_info(%d) = %p", xid, new);
15912 +       vxh_alloc_vx_info(new);
15913 +       atomic_inc(&vx_global_ctotal);
15914 +       return new;
15915 +#ifdef CONFIG_SMP
15916 +error:
15917 +       kfree(new);
15918 +       return 0;
15919 +#endif
15920 +}
15921 +
15922 +/*     __dealloc_vx_info()
15923 +
15924 +       * final disposal of vx_info                             */
15925 +
15926 +static void __dealloc_vx_info(struct vx_info *vxi)
15927 +{
15928 +#ifdef CONFIG_VSERVER_WARN
15929 +       struct vx_info_save vxis;
15930 +       int cpu;
15931 +#endif
15932 +       vxdprintk(VXD_CBIT(xid, 0),
15933 +               "dealloc_vx_info(%p)", vxi);
15934 +       vxh_dealloc_vx_info(vxi);
15935 +
15936 +#ifdef CONFIG_VSERVER_WARN
15937 +       enter_vx_info(vxi, &vxis);
15938 +       vx_info_exit_limit(&vxi->limit);
15939 +       vx_info_exit_sched(&vxi->sched);
15940 +       vx_info_exit_cvirt(&vxi->cvirt);
15941 +       vx_info_exit_cacct(&vxi->cacct);
15942 +
15943 +       for_each_possible_cpu(cpu) {
15944 +               vx_info_exit_sched_pc(
15945 +                       &vx_per_cpu(vxi, sched_pc, cpu), cpu);
15946 +               vx_info_exit_cvirt_pc(
15947 +                       &vx_per_cpu(vxi, cvirt_pc, cpu), cpu);
15948 +       }
15949 +       leave_vx_info(&vxis);
15950 +#endif
15951 +
15952 +       vxi->vx_id = -1;
15953 +       vxi->vx_state |= VXS_RELEASED;
15954 +
15955 +#ifdef CONFIG_SMP
15956 +       free_percpu(vxi->ptr_pc);
15957 +#endif
15958 +       kfree(vxi);
15959 +       atomic_dec(&vx_global_ctotal);
15960 +}
15961 +
15962 +static void __shutdown_vx_info(struct vx_info *vxi)
15963 +{
15964 +       struct nsproxy *nsproxy;
15965 +       struct fs_struct *fs;
15966 +       struct cred *cred;
15967 +       int index, kill;
15968 +
15969 +       might_sleep();
15970 +
15971 +       vxi->vx_state |= VXS_SHUTDOWN;
15972 +       vs_state_change(vxi, VSC_SHUTDOWN);
15973 +
15974 +       for (index = 0; index < VX_SPACES; index++) {
15975 +               struct _vx_space *space = &vxi->space[index];
15976 +
15977 +               nsproxy = xchg(&space->vx_nsproxy, NULL);
15978 +               if (nsproxy)
15979 +                       put_nsproxy(nsproxy);
15980 +
15981 +               fs = xchg(&space->vx_fs, NULL);
15982 +               spin_lock(&fs->lock);
15983 +               kill = !--fs->users;
15984 +               spin_unlock(&fs->lock);
15985 +               if (kill)
15986 +                       free_fs_struct(fs);
15987 +
15988 +               cred = (struct cred *)xchg(&space->vx_cred, NULL);
15989 +               if (cred)
15990 +                       abort_creds(cred);
15991 +       }
15992 +}
15993 +
15994 +/* exported stuff */
15995 +
15996 +void free_vx_info(struct vx_info *vxi)
15997 +{
15998 +       unsigned long flags;
15999 +       unsigned index;
16000 +
16001 +       /* check for reference counts first */
16002 +       BUG_ON(atomic_read(&vxi->vx_usecnt));
16003 +       BUG_ON(atomic_read(&vxi->vx_tasks));
16004 +
16005 +       /* context must not be hashed */
16006 +       BUG_ON(vx_info_state(vxi, VXS_HASHED));
16007 +
16008 +       /* context shutdown is mandatory */
16009 +       BUG_ON(!vx_info_state(vxi, VXS_SHUTDOWN));
16010 +
16011 +       /* spaces check */
16012 +       for (index = 0; index < VX_SPACES; index++) {
16013 +               struct _vx_space *space = &vxi->space[index];
16014 +
16015 +               BUG_ON(space->vx_nsproxy);
16016 +               BUG_ON(space->vx_fs);
16017 +               // BUG_ON(space->vx_real_cred);
16018 +               // BUG_ON(space->vx_cred);
16019 +       }
16020 +
16021 +       spin_lock_irqsave(&vx_info_inactive_lock, flags);
16022 +       hlist_del(&vxi->vx_hlist);
16023 +       spin_unlock_irqrestore(&vx_info_inactive_lock, flags);
16024 +
16025 +       __dealloc_vx_info(vxi);
16026 +}
16027 +
16028 +
16029 +/*     hash table for vx_info hash */
16030 +
16031 +#define VX_HASH_SIZE   13
16032 +
16033 +static struct hlist_head vx_info_hash[VX_HASH_SIZE] =
16034 +       { [0 ... VX_HASH_SIZE-1] = HLIST_HEAD_INIT };
16035 +
16036 +static DEFINE_SPINLOCK(vx_info_hash_lock);
16037 +
16038 +
16039 +static inline unsigned int __hashval(xid_t xid)
16040 +{
16041 +       return (xid % VX_HASH_SIZE);
16042 +}
16043 +
16044 +
16045 +
16046 +/*     __hash_vx_info()
16047 +
16048 +       * add the vxi to the global hash table
16049 +       * requires the hash_lock to be held                     */
16050 +
16051 +static inline void __hash_vx_info(struct vx_info *vxi)
16052 +{
16053 +       struct hlist_head *head;
16054 +
16055 +       vxd_assert_lock(&vx_info_hash_lock);
16056 +       vxdprintk(VXD_CBIT(xid, 4),
16057 +               "__hash_vx_info: %p[#%d]", vxi, vxi->vx_id);
16058 +       vxh_hash_vx_info(vxi);
16059 +
16060 +       /* context must not be hashed */
16061 +       BUG_ON(vx_info_state(vxi, VXS_HASHED));
16062 +
16063 +       vxi->vx_state |= VXS_HASHED;
16064 +       head = &vx_info_hash[__hashval(vxi->vx_id)];
16065 +       hlist_add_head(&vxi->vx_hlist, head);
16066 +       atomic_inc(&vx_global_cactive);
16067 +}
16068 +
16069 +/*     __unhash_vx_info()
16070 +
16071 +       * remove the vxi from the global hash table
16072 +       * requires the hash_lock to be held                     */
16073 +
16074 +static inline void __unhash_vx_info(struct vx_info *vxi)
16075 +{
16076 +       unsigned long flags;
16077 +
16078 +       vxd_assert_lock(&vx_info_hash_lock);
16079 +       vxdprintk(VXD_CBIT(xid, 4),
16080 +               "__unhash_vx_info: %p[#%d.%d.%d]", vxi, vxi->vx_id,
16081 +               atomic_read(&vxi->vx_usecnt), atomic_read(&vxi->vx_tasks));
16082 +       vxh_unhash_vx_info(vxi);
16083 +
16084 +       /* context must be hashed */
16085 +       BUG_ON(!vx_info_state(vxi, VXS_HASHED));
16086 +       /* but without tasks */
16087 +       BUG_ON(atomic_read(&vxi->vx_tasks));
16088 +
16089 +       vxi->vx_state &= ~VXS_HASHED;
16090 +       hlist_del_init(&vxi->vx_hlist);
16091 +       spin_lock_irqsave(&vx_info_inactive_lock, flags);
16092 +       hlist_add_head(&vxi->vx_hlist, &vx_info_inactive);
16093 +       spin_unlock_irqrestore(&vx_info_inactive_lock, flags);
16094 +       atomic_dec(&vx_global_cactive);
16095 +}
16096 +
16097 +
16098 +/*     __lookup_vx_info()
16099 +
16100 +       * requires the hash_lock to be held
16101 +       * doesn't increment the vx_refcnt                       */
16102 +
16103 +static inline struct vx_info *__lookup_vx_info(xid_t xid)
16104 +{
16105 +       struct hlist_head *head = &vx_info_hash[__hashval(xid)];
16106 +       struct hlist_node *pos;
16107 +       struct vx_info *vxi;
16108 +
16109 +       vxd_assert_lock(&vx_info_hash_lock);
16110 +       hlist_for_each(pos, head) {
16111 +               vxi = hlist_entry(pos, struct vx_info, vx_hlist);
16112 +
16113 +               if (vxi->vx_id == xid)
16114 +                       goto found;
16115 +       }
16116 +       vxi = NULL;
16117 +found:
16118 +       vxdprintk(VXD_CBIT(xid, 0),
16119 +               "__lookup_vx_info(#%u): %p[#%u]",
16120 +               xid, vxi, vxi ? vxi->vx_id : 0);
16121 +       vxh_lookup_vx_info(vxi, xid);
16122 +       return vxi;
16123 +}
16124 +
16125 +
16126 +/*     __create_vx_info()
16127 +
16128 +       * create the requested context
16129 +       * get(), claim() and hash it                            */
16130 +
16131 +static struct vx_info *__create_vx_info(int id)
16132 +{
16133 +       struct vx_info *new, *vxi = NULL;
16134 +
16135 +       vxdprintk(VXD_CBIT(xid, 1), "create_vx_info(%d)*", id);
16136 +
16137 +       if (!(new = __alloc_vx_info(id)))
16138 +               return ERR_PTR(-ENOMEM);
16139 +
16140 +       /* required to make dynamic xids unique */
16141 +       spin_lock(&vx_info_hash_lock);
16142 +
16143 +       /* static context requested */
16144 +       if ((vxi = __lookup_vx_info(id))) {
16145 +               vxdprintk(VXD_CBIT(xid, 0),
16146 +                       "create_vx_info(%d) = %p (already there)", id, vxi);
16147 +               if (vx_info_flags(vxi, VXF_STATE_SETUP, 0))
16148 +                       vxi = ERR_PTR(-EBUSY);
16149 +               else
16150 +                       vxi = ERR_PTR(-EEXIST);
16151 +               goto out_unlock;
16152 +       }
16153 +       /* new context */
16154 +       vxdprintk(VXD_CBIT(xid, 0),
16155 +               "create_vx_info(%d) = %p (new)", id, new);
16156 +       claim_vx_info(new, NULL);
16157 +       __hash_vx_info(get_vx_info(new));
16158 +       vxi = new, new = NULL;
16159 +
16160 +out_unlock:
16161 +       spin_unlock(&vx_info_hash_lock);
16162 +       vxh_create_vx_info(IS_ERR(vxi) ? NULL : vxi, id);
16163 +       if (new)
16164 +               __dealloc_vx_info(new);
16165 +       return vxi;
16166 +}
16167 +
16168 +
16169 +/*     exported stuff                                          */
16170 +
16171 +
16172 +void unhash_vx_info(struct vx_info *vxi)
16173 +{
16174 +       spin_lock(&vx_info_hash_lock);
16175 +       __unhash_vx_info(vxi);
16176 +       spin_unlock(&vx_info_hash_lock);
16177 +       __shutdown_vx_info(vxi);
16178 +       __wakeup_vx_info(vxi);
16179 +}
16180 +
16181 +
16182 +/*     lookup_vx_info()
16183 +
16184 +       * search for a vx_info and get() it
16185 +       * negative id means current                             */
16186 +
16187 +struct vx_info *lookup_vx_info(int id)
16188 +{
16189 +       struct vx_info *vxi = NULL;
16190 +
16191 +       if (id < 0) {
16192 +               vxi = get_vx_info(current_vx_info());
16193 +       } else if (id > 1) {
16194 +               spin_lock(&vx_info_hash_lock);
16195 +               vxi = get_vx_info(__lookup_vx_info(id));
16196 +               spin_unlock(&vx_info_hash_lock);
16197 +       }
16198 +       return vxi;
16199 +}
16200 +
16201 +/*     xid_is_hashed()
16202 +
16203 +       * verify that xid is still hashed                       */
16204 +
16205 +int xid_is_hashed(xid_t xid)
16206 +{
16207 +       int hashed;
16208 +
16209 +       spin_lock(&vx_info_hash_lock);
16210 +       hashed = (__lookup_vx_info(xid) != NULL);
16211 +       spin_unlock(&vx_info_hash_lock);
16212 +       return hashed;
16213 +}
16214 +
16215 +#ifdef CONFIG_PROC_FS
16216 +
16217 +/*     get_xid_list()
16218 +
16219 +       * get a subset of hashed xids for proc
16220 +       * assumes size is at least one                          */
16221 +
16222 +int get_xid_list(int index, unsigned int *xids, int size)
16223 +{
16224 +       int hindex, nr_xids = 0;
16225 +
16226 +       /* only show current and children */
16227 +       if (!vx_check(0, VS_ADMIN | VS_WATCH)) {
16228 +               if (index > 0)
16229 +                       return 0;
16230 +               xids[nr_xids] = vx_current_xid();
16231 +               return 1;
16232 +       }
16233 +
16234 +       for (hindex = 0; hindex < VX_HASH_SIZE; hindex++) {
16235 +               struct hlist_head *head = &vx_info_hash[hindex];
16236 +               struct hlist_node *pos;
16237 +
16238 +               spin_lock(&vx_info_hash_lock);
16239 +               hlist_for_each(pos, head) {
16240 +                       struct vx_info *vxi;
16241 +
16242 +                       if (--index > 0)
16243 +                               continue;
16244 +
16245 +                       vxi = hlist_entry(pos, struct vx_info, vx_hlist);
16246 +                       xids[nr_xids] = vxi->vx_id;
16247 +                       if (++nr_xids >= size) {
16248 +                               spin_unlock(&vx_info_hash_lock);
16249 +                               goto out;
16250 +                       }
16251 +               }
16252 +               /* keep the lock time short */
16253 +               spin_unlock(&vx_info_hash_lock);
16254 +       }
16255 +out:
16256 +       return nr_xids;
16257 +}
16258 +#endif
16259 +
16260 +#ifdef CONFIG_VSERVER_DEBUG
16261 +
16262 +void   dump_vx_info_inactive(int level)
16263 +{
16264 +       struct hlist_node *entry, *next;
16265 +
16266 +       hlist_for_each_safe(entry, next, &vx_info_inactive) {
16267 +               struct vx_info *vxi =
16268 +                       list_entry(entry, struct vx_info, vx_hlist);
16269 +
16270 +               dump_vx_info(vxi, level);
16271 +       }
16272 +}
16273 +
16274 +#endif
16275 +
16276 +#if 0
16277 +int vx_migrate_user(struct task_struct *p, struct vx_info *vxi)
16278 +{
16279 +       struct user_struct *new_user, *old_user;
16280 +
16281 +       if (!p || !vxi)
16282 +               BUG();
16283 +
16284 +       if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0))
16285 +               return -EACCES;
16286 +
16287 +       new_user = alloc_uid(vxi->vx_id, p->uid);
16288 +       if (!new_user)
16289 +               return -ENOMEM;
16290 +
16291 +       old_user = p->user;
16292 +       if (new_user != old_user) {
16293 +               atomic_inc(&new_user->processes);
16294 +               atomic_dec(&old_user->processes);
16295 +               p->user = new_user;
16296 +       }
16297 +       free_uid(old_user);
16298 +       return 0;
16299 +}
16300 +#endif
16301 +
16302 +#if 0
16303 +void vx_mask_cap_bset(struct vx_info *vxi, struct task_struct *p)
16304 +{
16305 +       // p->cap_effective &= vxi->vx_cap_bset;
16306 +       p->cap_effective =
16307 +               cap_intersect(p->cap_effective, vxi->cap_bset);
16308 +       // p->cap_inheritable &= vxi->vx_cap_bset;
16309 +       p->cap_inheritable =
16310 +               cap_intersect(p->cap_inheritable, vxi->cap_bset);
16311 +       // p->cap_permitted &= vxi->vx_cap_bset;
16312 +       p->cap_permitted =
16313 +               cap_intersect(p->cap_permitted, vxi->cap_bset);
16314 +}
16315 +#endif
16316 +
16317 +
16318 +#include <linux/file.h>
16319 +#include <linux/fdtable.h>
16320 +
16321 +static int vx_openfd_task(struct task_struct *tsk)
16322 +{
16323 +       struct files_struct *files = tsk->files;
16324 +       struct fdtable *fdt;
16325 +       const unsigned long *bptr;
16326 +       int count, total;
16327 +
16328 +       /* no rcu_read_lock() because of spin_lock() */
16329 +       spin_lock(&files->file_lock);
16330 +       fdt = files_fdtable(files);
16331 +       bptr = fdt->open_fds;
16332 +       count = fdt->max_fds / (sizeof(unsigned long) * 8);
16333 +       for (total = 0; count > 0; count--) {
16334 +               if (*bptr)
16335 +                       total += hweight_long(*bptr);
16336 +               bptr++;
16337 +       }
16338 +       spin_unlock(&files->file_lock);
16339 +       return total;
16340 +}
16341 +
16342 +
16343 +/*     for *space compatibility */
16344 +
16345 +asmlinkage long sys_unshare(unsigned long);
16346 +
16347 +/*
16348 + *     migrate task to new context
16349 + *     gets vxi, puts old_vxi on change
16350 + *     optionally unshares namespaces (hack)
16351 + */
16352 +
16353 +int vx_migrate_task(struct task_struct *p, struct vx_info *vxi, int unshare)
16354 +{
16355 +       struct vx_info *old_vxi;
16356 +       int ret = 0;
16357 +
16358 +       if (!p || !vxi)
16359 +               BUG();
16360 +
16361 +       vxdprintk(VXD_CBIT(xid, 5),
16362 +               "vx_migrate_task(%p,%p[#%d.%d])", p, vxi,
16363 +               vxi->vx_id, atomic_read(&vxi->vx_usecnt));
16364 +
16365 +       if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0) &&
16366 +               !vx_info_flags(vxi, VXF_STATE_SETUP, 0))
16367 +               return -EACCES;
16368 +
16369 +       if (vx_info_state(vxi, VXS_SHUTDOWN))
16370 +               return -EFAULT;
16371 +
16372 +       old_vxi = task_get_vx_info(p);
16373 +       if (old_vxi == vxi)
16374 +               goto out;
16375 +
16376 +//     if (!(ret = vx_migrate_user(p, vxi))) {
16377 +       {
16378 +               int openfd;
16379 +
16380 +               task_lock(p);
16381 +               openfd = vx_openfd_task(p);
16382 +
16383 +               if (old_vxi) {
16384 +                       atomic_dec(&old_vxi->cvirt.nr_threads);
16385 +                       atomic_dec(&old_vxi->cvirt.nr_running);
16386 +                       __rlim_dec(&old_vxi->limit, RLIMIT_NPROC);
16387 +                       /* FIXME: what about the struct files here? */
16388 +                       __rlim_sub(&old_vxi->limit, VLIMIT_OPENFD, openfd);
16389 +                       /* account for the executable */
16390 +                       __rlim_dec(&old_vxi->limit, VLIMIT_DENTRY);
16391 +               }
16392 +               atomic_inc(&vxi->cvirt.nr_threads);
16393 +               atomic_inc(&vxi->cvirt.nr_running);
16394 +               __rlim_inc(&vxi->limit, RLIMIT_NPROC);
16395 +               /* FIXME: what about the struct files here? */
16396 +               __rlim_add(&vxi->limit, VLIMIT_OPENFD, openfd);
16397 +               /* account for the executable */
16398 +               __rlim_inc(&vxi->limit, VLIMIT_DENTRY);
16399 +
16400 +               if (old_vxi) {
16401 +                       release_vx_info(old_vxi, p);
16402 +                       clr_vx_info(&p->vx_info);
16403 +               }
16404 +               claim_vx_info(vxi, p);
16405 +               set_vx_info(&p->vx_info, vxi);
16406 +               p->xid = vxi->vx_id;
16407 +
16408 +               vxdprintk(VXD_CBIT(xid, 5),
16409 +                       "moved task %p into vxi:%p[#%d]",
16410 +                       p, vxi, vxi->vx_id);
16411 +
16412 +               // vx_mask_cap_bset(vxi, p);
16413 +               task_unlock(p);
16414 +
16415 +               /* hack for *spaces to provide compatibility */
16416 +               if (unshare) {
16417 +                       struct nsproxy *old_nsp, *new_nsp;
16418 +
16419 +                       ret = unshare_nsproxy_namespaces(
16420 +                               CLONE_NEWUTS | CLONE_NEWIPC | CLONE_NEWUSER,
16421 +                               &new_nsp, NULL);
16422 +                       if (ret)
16423 +                               goto out;
16424 +
16425 +                       old_nsp = xchg(&p->nsproxy, new_nsp);
16426 +                       vx_set_space(vxi,
16427 +                               CLONE_NEWUTS | CLONE_NEWIPC | CLONE_NEWUSER, 0);
16428 +                       put_nsproxy(old_nsp);
16429 +               }
16430 +       }
16431 +out:
16432 +       put_vx_info(old_vxi);
16433 +       return ret;
16434 +}
16435 +
16436 +int vx_set_reaper(struct vx_info *vxi, struct task_struct *p)
16437 +{
16438 +       struct task_struct *old_reaper;
16439 +       struct vx_info *reaper_vxi;
16440 +
16441 +       if (!vxi)
16442 +               return -EINVAL;
16443 +
16444 +       vxdprintk(VXD_CBIT(xid, 6),
16445 +               "vx_set_reaper(%p[#%d],%p[#%d,%d])",
16446 +               vxi, vxi->vx_id, p, p->xid, p->pid);
16447 +
16448 +       old_reaper = vxi->vx_reaper;
16449 +       if (old_reaper == p)
16450 +               return 0;
16451 +
16452 +       reaper_vxi = task_get_vx_info(p);
16453 +       if (reaper_vxi && reaper_vxi != vxi) {
16454 +               vxwprintk(1,
16455 +                       "Unsuitable reaper [" VS_Q("%s") ",%u:#%u] "
16456 +                       "for [xid #%u]",
16457 +                       p->comm, p->pid, p->xid, vx_current_xid());
16458 +               goto out;
16459 +       }
16460 +
16461 +       /* set new child reaper */
16462 +       get_task_struct(p);
16463 +       vxi->vx_reaper = p;
16464 +       put_task_struct(old_reaper);
16465 +out:
16466 +       put_vx_info(reaper_vxi);
16467 +       return 0;
16468 +}
16469 +
16470 +int vx_set_init(struct vx_info *vxi, struct task_struct *p)
16471 +{
16472 +       if (!vxi)
16473 +               return -EINVAL;
16474 +
16475 +       vxdprintk(VXD_CBIT(xid, 6),
16476 +               "vx_set_init(%p[#%d],%p[#%d,%d,%d])",
16477 +               vxi, vxi->vx_id, p, p->xid, p->pid, p->tgid);
16478 +
16479 +       vxi->vx_flags &= ~VXF_STATE_INIT;
16480 +       // vxi->vx_initpid = p->tgid;
16481 +       vxi->vx_initpid = p->pid;
16482 +       return 0;
16483 +}
16484 +
16485 +void vx_exit_init(struct vx_info *vxi, struct task_struct *p, int code)
16486 +{
16487 +       vxdprintk(VXD_CBIT(xid, 6),
16488 +               "vx_exit_init(%p[#%d],%p[#%d,%d,%d])",
16489 +               vxi, vxi->vx_id, p, p->xid, p->pid, p->tgid);
16490 +
16491 +       vxi->exit_code = code;
16492 +       vxi->vx_initpid = 0;
16493 +}
16494 +
16495 +
16496 +void vx_set_persistent(struct vx_info *vxi)
16497 +{
16498 +       vxdprintk(VXD_CBIT(xid, 6),
16499 +               "vx_set_persistent(%p[#%d])", vxi, vxi->vx_id);
16500 +
16501 +       get_vx_info(vxi);
16502 +       claim_vx_info(vxi, NULL);
16503 +}
16504 +
16505 +void vx_clear_persistent(struct vx_info *vxi)
16506 +{
16507 +       vxdprintk(VXD_CBIT(xid, 6),
16508 +               "vx_clear_persistent(%p[#%d])", vxi, vxi->vx_id);
16509 +
16510 +       release_vx_info(vxi, NULL);
16511 +       put_vx_info(vxi);
16512 +}
16513 +
16514 +void vx_update_persistent(struct vx_info *vxi)
16515 +{
16516 +       if (vx_info_flags(vxi, VXF_PERSISTENT, 0))
16517 +               vx_set_persistent(vxi);
16518 +       else
16519 +               vx_clear_persistent(vxi);
16520 +}
16521 +
16522 +
16523 +/*     task must be current or locked          */
16524 +
16525 +void   exit_vx_info(struct task_struct *p, int code)
16526 +{
16527 +       struct vx_info *vxi = p->vx_info;
16528 +
16529 +       if (vxi) {
16530 +               atomic_dec(&vxi->cvirt.nr_threads);
16531 +               vx_nproc_dec(p);
16532 +
16533 +               vxi->exit_code = code;
16534 +               release_vx_info(vxi, p);
16535 +       }
16536 +}
16537 +
16538 +void   exit_vx_info_early(struct task_struct *p, int code)
16539 +{
16540 +       struct vx_info *vxi = p->vx_info;
16541 +
16542 +       if (vxi) {
16543 +               if (vxi->vx_initpid == p->pid)
16544 +                       vx_exit_init(vxi, p, code);
16545 +               if (vxi->vx_reaper == p)
16546 +                       vx_set_reaper(vxi, init_pid_ns.child_reaper);
16547 +       }
16548 +}
16549 +
16550 +
16551 +/* vserver syscall commands below here */
16552 +
16553 +/* taks xid and vx_info functions */
16554 +
16555 +#include <asm/uaccess.h>
16556 +
16557 +
16558 +int vc_task_xid(uint32_t id)
16559 +{
16560 +       xid_t xid;
16561 +
16562 +       if (id) {
16563 +               struct task_struct *tsk;
16564 +
16565 +               rcu_read_lock();
16566 +               tsk = find_task_by_real_pid(id);
16567 +               xid = (tsk) ? tsk->xid : -ESRCH;
16568 +               rcu_read_unlock();
16569 +       } else
16570 +               xid = vx_current_xid();
16571 +       return xid;
16572 +}
16573 +
16574 +
16575 +int vc_vx_info(struct vx_info *vxi, void __user *data)
16576 +{
16577 +       struct vcmd_vx_info_v0 vc_data;
16578 +
16579 +       vc_data.xid = vxi->vx_id;
16580 +       vc_data.initpid = vxi->vx_initpid;
16581 +
16582 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16583 +               return -EFAULT;
16584 +       return 0;
16585 +}
16586 +
16587 +
16588 +int vc_ctx_stat(struct vx_info *vxi, void __user *data)
16589 +{
16590 +       struct vcmd_ctx_stat_v0 vc_data;
16591 +
16592 +       vc_data.usecnt = atomic_read(&vxi->vx_usecnt);
16593 +       vc_data.tasks = atomic_read(&vxi->vx_tasks);
16594 +
16595 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16596 +               return -EFAULT;
16597 +       return 0;
16598 +}
16599 +
16600 +
16601 +/* context functions */
16602 +
16603 +int vc_ctx_create(uint32_t xid, void __user *data)
16604 +{
16605 +       struct vcmd_ctx_create vc_data = { .flagword = VXF_INIT_SET };
16606 +       struct vx_info *new_vxi;
16607 +       int ret;
16608 +
16609 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
16610 +               return -EFAULT;
16611 +
16612 +       if ((xid > MAX_S_CONTEXT) || (xid < 2))
16613 +               return -EINVAL;
16614 +
16615 +       new_vxi = __create_vx_info(xid);
16616 +       if (IS_ERR(new_vxi))
16617 +               return PTR_ERR(new_vxi);
16618 +
16619 +       /* initial flags */
16620 +       new_vxi->vx_flags = vc_data.flagword;
16621 +
16622 +       ret = -ENOEXEC;
16623 +       if (vs_state_change(new_vxi, VSC_STARTUP))
16624 +               goto out;
16625 +
16626 +       ret = vx_migrate_task(current, new_vxi, (!data));
16627 +       if (ret)
16628 +               goto out;
16629 +
16630 +       /* return context id on success */
16631 +       ret = new_vxi->vx_id;
16632 +
16633 +       /* get a reference for persistent contexts */
16634 +       if ((vc_data.flagword & VXF_PERSISTENT))
16635 +               vx_set_persistent(new_vxi);
16636 +out:
16637 +       release_vx_info(new_vxi, NULL);
16638 +       put_vx_info(new_vxi);
16639 +       return ret;
16640 +}
16641 +
16642 +
16643 +int vc_ctx_migrate(struct vx_info *vxi, void __user *data)
16644 +{
16645 +       struct vcmd_ctx_migrate vc_data = { .flagword = 0 };
16646 +       int ret;
16647 +
16648 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
16649 +               return -EFAULT;
16650 +
16651 +       ret = vx_migrate_task(current, vxi, 0);
16652 +       if (ret)
16653 +               return ret;
16654 +       if (vc_data.flagword & VXM_SET_INIT)
16655 +               ret = vx_set_init(vxi, current);
16656 +       if (ret)
16657 +               return ret;
16658 +       if (vc_data.flagword & VXM_SET_REAPER)
16659 +               ret = vx_set_reaper(vxi, current);
16660 +       return ret;
16661 +}
16662 +
16663 +
16664 +int vc_get_cflags(struct vx_info *vxi, void __user *data)
16665 +{
16666 +       struct vcmd_ctx_flags_v0 vc_data;
16667 +
16668 +       vc_data.flagword = vxi->vx_flags;
16669 +
16670 +       /* special STATE flag handling */
16671 +       vc_data.mask = vs_mask_flags(~0ULL, vxi->vx_flags, VXF_ONE_TIME);
16672 +
16673 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16674 +               return -EFAULT;
16675 +       return 0;
16676 +}
16677 +
16678 +int vc_set_cflags(struct vx_info *vxi, void __user *data)
16679 +{
16680 +       struct vcmd_ctx_flags_v0 vc_data;
16681 +       uint64_t mask, trigger;
16682 +
16683 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16684 +               return -EFAULT;
16685 +
16686 +       /* special STATE flag handling */
16687 +       mask = vs_mask_mask(vc_data.mask, vxi->vx_flags, VXF_ONE_TIME);
16688 +       trigger = (mask & vxi->vx_flags) ^ (mask & vc_data.flagword);
16689 +
16690 +       if (vxi == current_vx_info()) {
16691 +               /* if (trigger & VXF_STATE_SETUP)
16692 +                       vx_mask_cap_bset(vxi, current); */
16693 +               if (trigger & VXF_STATE_INIT) {
16694 +                       int ret;
16695 +
16696 +                       ret = vx_set_init(vxi, current);
16697 +                       if (ret)
16698 +                               return ret;
16699 +                       ret = vx_set_reaper(vxi, current);
16700 +                       if (ret)
16701 +                               return ret;
16702 +               }
16703 +       }
16704 +
16705 +       vxi->vx_flags = vs_mask_flags(vxi->vx_flags,
16706 +               vc_data.flagword, mask);
16707 +       if (trigger & VXF_PERSISTENT)
16708 +               vx_update_persistent(vxi);
16709 +
16710 +       return 0;
16711 +}
16712 +
16713 +
16714 +static inline uint64_t caps_from_cap_t(kernel_cap_t c)
16715 +{
16716 +       uint64_t v = c.cap[0] | ((uint64_t)c.cap[1] << 32);
16717 +
16718 +       // printk("caps_from_cap_t(%08x:%08x) = %016llx\n", c.cap[1], c.cap[0], v);
16719 +       return v;
16720 +}
16721 +
16722 +static inline kernel_cap_t cap_t_from_caps(uint64_t v)
16723 +{
16724 +       kernel_cap_t c = __cap_empty_set;
16725 +
16726 +       c.cap[0] = v & 0xFFFFFFFF;
16727 +       c.cap[1] = (v >> 32) & 0xFFFFFFFF;
16728 +
16729 +       // printk("cap_t_from_caps(%016llx) = %08x:%08x\n", v, c.cap[1], c.cap[0]);
16730 +       return c;
16731 +}
16732 +
16733 +
16734 +static int do_get_caps(struct vx_info *vxi, uint64_t *bcaps, uint64_t *ccaps)
16735 +{
16736 +       if (bcaps)
16737 +               *bcaps = caps_from_cap_t(vxi->vx_bcaps);
16738 +       if (ccaps)
16739 +               *ccaps = vxi->vx_ccaps;
16740 +
16741 +       return 0;
16742 +}
16743 +
16744 +int vc_get_ccaps(struct vx_info *vxi, void __user *data)
16745 +{
16746 +       struct vcmd_ctx_caps_v1 vc_data;
16747 +       int ret;
16748 +
16749 +       ret = do_get_caps(vxi, NULL, &vc_data.ccaps);
16750 +       if (ret)
16751 +               return ret;
16752 +       vc_data.cmask = ~0ULL;
16753 +
16754 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16755 +               return -EFAULT;
16756 +       return 0;
16757 +}
16758 +
16759 +static int do_set_caps(struct vx_info *vxi,
16760 +       uint64_t bcaps, uint64_t bmask, uint64_t ccaps, uint64_t cmask)
16761 +{
16762 +       uint64_t bcold = caps_from_cap_t(vxi->vx_bcaps);
16763 +
16764 +#if 0
16765 +       printk("do_set_caps(%16llx, %16llx, %16llx, %16llx)\n",
16766 +               bcaps, bmask, ccaps, cmask);
16767 +#endif
16768 +       vxi->vx_bcaps = cap_t_from_caps(
16769 +               vs_mask_flags(bcold, bcaps, bmask));
16770 +       vxi->vx_ccaps = vs_mask_flags(vxi->vx_ccaps, ccaps, cmask);
16771 +
16772 +       return 0;
16773 +}
16774 +
16775 +int vc_set_ccaps(struct vx_info *vxi, void __user *data)
16776 +{
16777 +       struct vcmd_ctx_caps_v1 vc_data;
16778 +
16779 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16780 +               return -EFAULT;
16781 +
16782 +       return do_set_caps(vxi, 0, 0, vc_data.ccaps, vc_data.cmask);
16783 +}
16784 +
16785 +int vc_get_bcaps(struct vx_info *vxi, void __user *data)
16786 +{
16787 +       struct vcmd_bcaps vc_data;
16788 +       int ret;
16789 +
16790 +       ret = do_get_caps(vxi, &vc_data.bcaps, NULL);
16791 +       if (ret)
16792 +               return ret;
16793 +       vc_data.bmask = ~0ULL;
16794 +
16795 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16796 +               return -EFAULT;
16797 +       return 0;
16798 +}
16799 +
16800 +int vc_set_bcaps(struct vx_info *vxi, void __user *data)
16801 +{
16802 +       struct vcmd_bcaps vc_data;
16803 +
16804 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16805 +               return -EFAULT;
16806 +
16807 +       return do_set_caps(vxi, vc_data.bcaps, vc_data.bmask, 0, 0);
16808 +}
16809 +
16810 +
16811 +int vc_get_umask(struct vx_info *vxi, void __user *data)
16812 +{
16813 +       struct vcmd_umask vc_data;
16814 +
16815 +       vc_data.umask = vxi->vx_umask;
16816 +       vc_data.mask = ~0ULL;
16817 +
16818 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16819 +               return -EFAULT;
16820 +       return 0;
16821 +}
16822 +
16823 +int vc_set_umask(struct vx_info *vxi, void __user *data)
16824 +{
16825 +       struct vcmd_umask vc_data;
16826 +
16827 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16828 +               return -EFAULT;
16829 +
16830 +       vxi->vx_umask = vs_mask_flags(vxi->vx_umask,
16831 +               vc_data.umask, vc_data.mask);
16832 +       return 0;
16833 +}
16834 +
16835 +
16836 +int vc_get_wmask(struct vx_info *vxi, void __user *data)
16837 +{
16838 +       struct vcmd_wmask vc_data;
16839 +
16840 +       vc_data.wmask = vxi->vx_wmask;
16841 +       vc_data.mask = ~0ULL;
16842 +
16843 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16844 +               return -EFAULT;
16845 +       return 0;
16846 +}
16847 +
16848 +int vc_set_wmask(struct vx_info *vxi, void __user *data)
16849 +{
16850 +       struct vcmd_wmask vc_data;
16851 +
16852 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16853 +               return -EFAULT;
16854 +
16855 +       vxi->vx_wmask = vs_mask_flags(vxi->vx_wmask,
16856 +               vc_data.wmask, vc_data.mask);
16857 +       return 0;
16858 +}
16859 +
16860 +
16861 +int vc_get_badness(struct vx_info *vxi, void __user *data)
16862 +{
16863 +       struct vcmd_badness_v0 vc_data;
16864 +
16865 +       vc_data.bias = vxi->vx_badness_bias;
16866 +
16867 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16868 +               return -EFAULT;
16869 +       return 0;
16870 +}
16871 +
16872 +int vc_set_badness(struct vx_info *vxi, void __user *data)
16873 +{
16874 +       struct vcmd_badness_v0 vc_data;
16875 +
16876 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16877 +               return -EFAULT;
16878 +
16879 +       vxi->vx_badness_bias = vc_data.bias;
16880 +       return 0;
16881 +}
16882 +
16883 +#include <linux/module.h>
16884 +
16885 +EXPORT_SYMBOL_GPL(free_vx_info);
16886 +
16887 diff -NurpP --minimal linux-3.6.9/kernel/vserver/cvirt.c linux-3.6.9-vs2.3.4.4/kernel/vserver/cvirt.c
16888 --- linux-3.6.9/kernel/vserver/cvirt.c  1970-01-01 01:00:00.000000000 +0100
16889 +++ linux-3.6.9-vs2.3.4.4/kernel/vserver/cvirt.c        2012-10-04 18:47:00.000000000 +0200
16890 @@ -0,0 +1,313 @@
16891 +/*
16892 + *  linux/kernel/vserver/cvirt.c
16893 + *
16894 + *  Virtual Server: Context Virtualization
16895 + *
16896 + *  Copyright (C) 2004-2007  Herbert Pötzl
16897 + *
16898 + *  V0.01  broken out from limit.c
16899 + *  V0.02  added utsname stuff
16900 + *  V0.03  changed vcmds to vxi arg
16901 + *
16902 + */
16903 +
16904 +#include <linux/types.h>
16905 +#include <linux/utsname.h>
16906 +#include <linux/vs_cvirt.h>
16907 +#include <linux/vserver/switch.h>
16908 +#include <linux/vserver/cvirt_cmd.h>
16909 +
16910 +#include <asm/uaccess.h>
16911 +
16912 +
16913 +void vx_vsi_boottime(struct timespec *boottime)
16914 +{
16915 +       struct vx_info *vxi = current_vx_info();
16916 +
16917 +       set_normalized_timespec(boottime,
16918 +               boottime->tv_sec + vxi->cvirt.bias_uptime.tv_sec,
16919 +               boottime->tv_nsec + vxi->cvirt.bias_uptime.tv_nsec);
16920 +       return;
16921 +}
16922 +
16923 +void vx_vsi_uptime(struct timespec *uptime, struct timespec *idle)
16924 +{
16925 +       struct vx_info *vxi = current_vx_info();
16926 +
16927 +       set_normalized_timespec(uptime,
16928 +               uptime->tv_sec - vxi->cvirt.bias_uptime.tv_sec,
16929 +               uptime->tv_nsec - vxi->cvirt.bias_uptime.tv_nsec);
16930 +       if (!idle)
16931 +               return;
16932 +       set_normalized_timespec(idle,
16933 +               idle->tv_sec - vxi->cvirt.bias_idle.tv_sec,
16934 +               idle->tv_nsec - vxi->cvirt.bias_idle.tv_nsec);
16935 +       return;
16936 +}
16937 +
16938 +uint64_t vx_idle_jiffies(void)
16939 +{
16940 +       return init_task.utime + init_task.stime;
16941 +}
16942 +
16943 +
16944 +
16945 +static inline uint32_t __update_loadavg(uint32_t load,
16946 +       int wsize, int delta, int n)
16947 +{
16948 +       unsigned long long calc, prev;
16949 +
16950 +       /* just set it to n */
16951 +       if (unlikely(delta >= wsize))
16952 +               return (n << FSHIFT);
16953 +
16954 +       calc = delta * n;
16955 +       calc <<= FSHIFT;
16956 +       prev = (wsize - delta);
16957 +       prev *= load;
16958 +       calc += prev;
16959 +       do_div(calc, wsize);
16960 +       return calc;
16961 +}
16962 +
16963 +
16964 +void vx_update_load(struct vx_info *vxi)
16965 +{
16966 +       uint32_t now, last, delta;
16967 +       unsigned int nr_running, nr_uninterruptible;
16968 +       unsigned int total;
16969 +       unsigned long flags;
16970 +
16971 +       spin_lock_irqsave(&vxi->cvirt.load_lock, flags);
16972 +
16973 +       now = jiffies;
16974 +       last = vxi->cvirt.load_last;
16975 +       delta = now - last;
16976 +
16977 +       if (delta < 5*HZ)
16978 +               goto out;
16979 +
16980 +       nr_running = atomic_read(&vxi->cvirt.nr_running);
16981 +       nr_uninterruptible = atomic_read(&vxi->cvirt.nr_uninterruptible);
16982 +       total = nr_running + nr_uninterruptible;
16983 +
16984 +       vxi->cvirt.load[0] = __update_loadavg(vxi->cvirt.load[0],
16985 +               60*HZ, delta, total);
16986 +       vxi->cvirt.load[1] = __update_loadavg(vxi->cvirt.load[1],
16987 +               5*60*HZ, delta, total);
16988 +       vxi->cvirt.load[2] = __update_loadavg(vxi->cvirt.load[2],
16989 +               15*60*HZ, delta, total);
16990 +
16991 +       vxi->cvirt.load_last = now;
16992 +out:
16993 +       atomic_inc(&vxi->cvirt.load_updates);
16994 +       spin_unlock_irqrestore(&vxi->cvirt.load_lock, flags);
16995 +}
16996 +
16997 +
16998 +/*
16999 + * Commands to do_syslog:
17000 + *
17001 + *      0 -- Close the log.  Currently a NOP.
17002 + *      1 -- Open the log. Currently a NOP.
17003 + *      2 -- Read from the log.
17004 + *      3 -- Read all messages remaining in the ring buffer.
17005 + *      4 -- Read and clear all messages remaining in the ring buffer
17006 + *      5 -- Clear ring buffer.
17007 + *      6 -- Disable printk's to console
17008 + *      7 -- Enable printk's to console
17009 + *      8 -- Set level of messages printed to console
17010 + *      9 -- Return number of unread characters in the log buffer
17011 + *     10 -- Return size of the log buffer
17012 + */
17013 +int vx_do_syslog(int type, char __user *buf, int len)
17014 +{
17015 +       int error = 0;
17016 +       int do_clear = 0;
17017 +       struct vx_info *vxi = current_vx_info();
17018 +       struct _vx_syslog *log;
17019 +
17020 +       if (!vxi)
17021 +               return -EINVAL;
17022 +       log = &vxi->cvirt.syslog;
17023 +
17024 +       switch (type) {
17025 +       case 0:         /* Close log */
17026 +       case 1:         /* Open log */
17027 +               break;
17028 +       case 2:         /* Read from log */
17029 +               error = wait_event_interruptible(log->log_wait,
17030 +                       (log->log_start - log->log_end));
17031 +               if (error)
17032 +                       break;
17033 +               spin_lock_irq(&log->logbuf_lock);
17034 +               spin_unlock_irq(&log->logbuf_lock);
17035 +               break;
17036 +       case 4:         /* Read/clear last kernel messages */
17037 +               do_clear = 1;
17038 +               /* fall through */
17039 +       case 3:         /* Read last kernel messages */
17040 +               return 0;
17041 +
17042 +       case 5:         /* Clear ring buffer */
17043 +               return 0;
17044 +
17045 +       case 6:         /* Disable logging to console */
17046 +       case 7:         /* Enable logging to console */
17047 +       case 8:         /* Set level of messages printed to console */
17048 +               break;
17049 +
17050 +       case 9:         /* Number of chars in the log buffer */
17051 +               return 0;
17052 +       case 10:        /* Size of the log buffer */
17053 +               return 0;
17054 +       default:
17055 +               error = -EINVAL;
17056 +               break;
17057 +       }
17058 +       return error;
17059 +}
17060 +
17061 +
17062 +/* virtual host info names */
17063 +
17064 +static char *vx_vhi_name(struct vx_info *vxi, int id)
17065 +{
17066 +       struct nsproxy *nsproxy;
17067 +       struct uts_namespace *uts;
17068 +
17069 +       if (id == VHIN_CONTEXT)
17070 +               return vxi->vx_name;
17071 +
17072 +       nsproxy = vxi->space[0].vx_nsproxy;
17073 +       if (!nsproxy)
17074 +               return NULL;
17075 +
17076 +       uts = nsproxy->uts_ns;
17077 +       if (!uts)
17078 +               return NULL;
17079 +
17080 +       switch (id) {
17081 +       case VHIN_SYSNAME:
17082 +               return uts->name.sysname;
17083 +       case VHIN_NODENAME:
17084 +               return uts->name.nodename;
17085 +       case VHIN_RELEASE:
17086 +               return uts->name.release;
17087 +       case VHIN_VERSION:
17088 +               return uts->name.version;
17089 +       case VHIN_MACHINE:
17090 +               return uts->name.machine;
17091 +       case VHIN_DOMAINNAME:
17092 +               return uts->name.domainname;
17093 +       default:
17094 +               return NULL;
17095 +       }
17096 +       return NULL;
17097 +}
17098 +
17099 +int vc_set_vhi_name(struct vx_info *vxi, void __user *data)
17100 +{
17101 +       struct vcmd_vhi_name_v0 vc_data;
17102 +       char *name;
17103 +
17104 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17105 +               return -EFAULT;
17106 +
17107 +       name = vx_vhi_name(vxi, vc_data.field);
17108 +       if (!name)
17109 +               return -EINVAL;
17110 +
17111 +       memcpy(name, vc_data.name, 65);
17112 +       return 0;
17113 +}
17114 +
17115 +int vc_get_vhi_name(struct vx_info *vxi, void __user *data)
17116 +{
17117 +       struct vcmd_vhi_name_v0 vc_data;
17118 +       char *name;
17119 +
17120 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17121 +               return -EFAULT;
17122 +
17123 +       name = vx_vhi_name(vxi, vc_data.field);
17124 +       if (!name)
17125 +               return -EINVAL;
17126 +
17127 +       memcpy(vc_data.name, name, 65);
17128 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
17129 +               return -EFAULT;
17130 +       return 0;
17131 +}
17132 +
17133 +
17134 +int vc_virt_stat(struct vx_info *vxi, void __user *data)
17135 +{
17136 +       struct vcmd_virt_stat_v0 vc_data;
17137 +       struct _vx_cvirt *cvirt = &vxi->cvirt;
17138 +       struct timespec uptime;
17139 +
17140 +       do_posix_clock_monotonic_gettime(&uptime);
17141 +       set_normalized_timespec(&uptime,
17142 +               uptime.tv_sec - cvirt->bias_uptime.tv_sec,
17143 +               uptime.tv_nsec - cvirt->bias_uptime.tv_nsec);
17144 +
17145 +       vc_data.offset = timespec_to_ns(&cvirt->bias_ts);
17146 +       vc_data.uptime = timespec_to_ns(&uptime);
17147 +       vc_data.nr_threads = atomic_read(&cvirt->nr_threads);
17148 +       vc_data.nr_running = atomic_read(&cvirt->nr_running);
17149 +       vc_data.nr_uninterruptible = atomic_read(&cvirt->nr_uninterruptible);
17150 +       vc_data.nr_onhold = atomic_read(&cvirt->nr_onhold);
17151 +       vc_data.nr_forks = atomic_read(&cvirt->total_forks);
17152 +       vc_data.load[0] = cvirt->load[0];
17153 +       vc_data.load[1] = cvirt->load[1];
17154 +       vc_data.load[2] = cvirt->load[2];
17155 +
17156 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
17157 +               return -EFAULT;
17158 +       return 0;
17159 +}
17160 +
17161 +
17162 +#ifdef CONFIG_VSERVER_VTIME
17163 +
17164 +/* virtualized time base */
17165 +
17166 +void vx_adjust_timespec(struct timespec *ts)
17167 +{
17168 +       struct vx_info *vxi;
17169 +
17170 +       if (!vx_flags(VXF_VIRT_TIME, 0))
17171 +               return;
17172 +
17173 +       vxi = current_vx_info();
17174 +       ts->tv_sec += vxi->cvirt.bias_ts.tv_sec;
17175 +       ts->tv_nsec += vxi->cvirt.bias_ts.tv_nsec;
17176 +
17177 +       if (ts->tv_nsec >= NSEC_PER_SEC) {
17178 +               ts->tv_sec++;
17179 +               ts->tv_nsec -= NSEC_PER_SEC;
17180 +       } else if (ts->tv_nsec < 0) {
17181 +               ts->tv_sec--;
17182 +               ts->tv_nsec += NSEC_PER_SEC;
17183 +       }
17184 +}
17185 +
17186 +int vx_settimeofday(const struct timespec *ts)
17187 +{
17188 +       struct timespec ats, delta;
17189 +       struct vx_info *vxi;
17190 +
17191 +       if (!vx_flags(VXF_VIRT_TIME, 0))
17192 +               return do_settimeofday(ts);
17193 +
17194 +       getnstimeofday(&ats);
17195 +       delta = timespec_sub(*ts, ats);
17196 +
17197 +       vxi = current_vx_info();
17198 +       vxi->cvirt.bias_ts = timespec_add(vxi->cvirt.bias_ts, delta);
17199 +       return 0;
17200 +}
17201 +
17202 +#endif
17203 +
17204 diff -NurpP --minimal linux-3.6.9/kernel/vserver/cvirt_init.h linux-3.6.9-vs2.3.4.4/kernel/vserver/cvirt_init.h
17205 --- linux-3.6.9/kernel/vserver/cvirt_init.h     1970-01-01 01:00:00.000000000 +0100
17206 +++ linux-3.6.9-vs2.3.4.4/kernel/vserver/cvirt_init.h   2012-10-04 18:47:00.000000000 +0200
17207 @@ -0,0 +1,70 @@
17208 +
17209 +
17210 +extern uint64_t vx_idle_jiffies(void);
17211 +
17212 +static inline void vx_info_init_cvirt(struct _vx_cvirt *cvirt)
17213 +{
17214 +       uint64_t idle_jiffies = vx_idle_jiffies();
17215 +       uint64_t nsuptime;
17216 +
17217 +       do_posix_clock_monotonic_gettime(&cvirt->bias_uptime);
17218 +       nsuptime = (unsigned long long)cvirt->bias_uptime.tv_sec
17219 +               * NSEC_PER_SEC + cvirt->bias_uptime.tv_nsec;
17220 +       cvirt->bias_clock = nsec_to_clock_t(nsuptime);
17221 +       cvirt->bias_ts.tv_sec = 0;
17222 +       cvirt->bias_ts.tv_nsec = 0;
17223 +
17224 +       jiffies_to_timespec(idle_jiffies, &cvirt->bias_idle);
17225 +       atomic_set(&cvirt->nr_threads, 0);
17226 +       atomic_set(&cvirt->nr_running, 0);
17227 +       atomic_set(&cvirt->nr_uninterruptible, 0);
17228 +       atomic_set(&cvirt->nr_onhold, 0);
17229 +
17230 +       spin_lock_init(&cvirt->load_lock);
17231 +       cvirt->load_last = jiffies;
17232 +       atomic_set(&cvirt->load_updates, 0);
17233 +       cvirt->load[0] = 0;
17234 +       cvirt->load[1] = 0;
17235 +       cvirt->load[2] = 0;
17236 +       atomic_set(&cvirt->total_forks, 0);
17237 +
17238 +       spin_lock_init(&cvirt->syslog.logbuf_lock);
17239 +       init_waitqueue_head(&cvirt->syslog.log_wait);
17240 +       cvirt->syslog.log_start = 0;
17241 +       cvirt->syslog.log_end = 0;
17242 +       cvirt->syslog.con_start = 0;
17243 +       cvirt->syslog.logged_chars = 0;
17244 +}
17245 +
17246 +static inline
17247 +void vx_info_init_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc, int cpu)
17248 +{
17249 +       // cvirt_pc->cpustat = { 0 };
17250 +}
17251 +
17252 +static inline void vx_info_exit_cvirt(struct _vx_cvirt *cvirt)
17253 +{
17254 +#ifdef CONFIG_VSERVER_WARN
17255 +       int value;
17256 +#endif
17257 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_threads)),
17258 +               "!!! cvirt: %p[nr_threads] = %d on exit.",
17259 +               cvirt, value);
17260 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_running)),
17261 +               "!!! cvirt: %p[nr_running] = %d on exit.",
17262 +               cvirt, value);
17263 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_uninterruptible)),
17264 +               "!!! cvirt: %p[nr_uninterruptible] = %d on exit.",
17265 +               cvirt, value);
17266 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_onhold)),
17267 +               "!!! cvirt: %p[nr_onhold] = %d on exit.",
17268 +               cvirt, value);
17269 +       return;
17270 +}
17271 +
17272 +static inline
17273 +void vx_info_exit_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc, int cpu)
17274 +{
17275 +       return;
17276 +}
17277 +
17278 diff -NurpP --minimal linux-3.6.9/kernel/vserver/cvirt_proc.h linux-3.6.9-vs2.3.4.4/kernel/vserver/cvirt_proc.h
17279 --- linux-3.6.9/kernel/vserver/cvirt_proc.h     1970-01-01 01:00:00.000000000 +0100
17280 +++ linux-3.6.9-vs2.3.4.4/kernel/vserver/cvirt_proc.h   2012-10-04 18:47:00.000000000 +0200
17281 @@ -0,0 +1,123 @@
17282 +#ifndef _VX_CVIRT_PROC_H
17283 +#define _VX_CVIRT_PROC_H
17284 +
17285 +#include <linux/nsproxy.h>
17286 +#include <linux/mnt_namespace.h>
17287 +#include <linux/ipc_namespace.h>
17288 +#include <linux/utsname.h>
17289 +#include <linux/ipc.h>
17290 +
17291 +extern int vx_info_mnt_namespace(struct mnt_namespace *, char *);
17292 +
17293 +static inline
17294 +int vx_info_proc_nsproxy(struct nsproxy *nsproxy, char *buffer)
17295 +{
17296 +       struct mnt_namespace *ns;
17297 +       struct uts_namespace *uts;
17298 +       struct ipc_namespace *ipc;
17299 +       int length = 0;
17300 +
17301 +       if (!nsproxy)
17302 +               goto out;
17303 +
17304 +       length += sprintf(buffer + length,
17305 +               "NSProxy:\t%p [%p,%p,%p]\n",
17306 +               nsproxy, nsproxy->mnt_ns,
17307 +               nsproxy->uts_ns, nsproxy->ipc_ns);
17308 +
17309 +       ns = nsproxy->mnt_ns;
17310 +       if (!ns)
17311 +               goto skip_ns;
17312 +
17313 +       length += vx_info_mnt_namespace(ns, buffer + length);
17314 +
17315 +skip_ns:
17316 +
17317 +       uts = nsproxy->uts_ns;
17318 +       if (!uts)
17319 +               goto skip_uts;
17320 +
17321 +       length += sprintf(buffer + length,
17322 +               "SysName:\t%.*s\n"
17323 +               "NodeName:\t%.*s\n"
17324 +               "Release:\t%.*s\n"
17325 +               "Version:\t%.*s\n"
17326 +               "Machine:\t%.*s\n"
17327 +               "DomainName:\t%.*s\n",
17328 +               __NEW_UTS_LEN, uts->name.sysname,
17329 +               __NEW_UTS_LEN, uts->name.nodename,
17330 +               __NEW_UTS_LEN, uts->name.release,
17331 +               __NEW_UTS_LEN, uts->name.version,
17332 +               __NEW_UTS_LEN, uts->name.machine,
17333 +               __NEW_UTS_LEN, uts->name.domainname);
17334 +skip_uts:
17335 +
17336 +       ipc = nsproxy->ipc_ns;
17337 +       if (!ipc)
17338 +               goto skip_ipc;
17339 +
17340 +       length += sprintf(buffer + length,
17341 +               "SEMS:\t\t%d %d %d %d  %d\n"
17342 +               "MSG:\t\t%d %d %d\n"
17343 +               "SHM:\t\t%lu %lu  %d %d\n",
17344 +               ipc->sem_ctls[0], ipc->sem_ctls[1],
17345 +               ipc->sem_ctls[2], ipc->sem_ctls[3],
17346 +               ipc->used_sems,
17347 +               ipc->msg_ctlmax, ipc->msg_ctlmnb, ipc->msg_ctlmni,
17348 +               (unsigned long)ipc->shm_ctlmax,
17349 +               (unsigned long)ipc->shm_ctlall,
17350 +               ipc->shm_ctlmni, ipc->shm_tot);
17351 +skip_ipc:
17352 +out:
17353 +       return length;
17354 +}
17355 +
17356 +
17357 +#include <linux/sched.h>
17358 +
17359 +#define LOAD_INT(x) ((x) >> FSHIFT)
17360 +#define LOAD_FRAC(x) LOAD_INT(((x) & (FIXED_1 - 1)) * 100)
17361 +
17362 +static inline
17363 +int vx_info_proc_cvirt(struct _vx_cvirt *cvirt, char *buffer)
17364 +{
17365 +       int length = 0;
17366 +       int a, b, c;
17367 +
17368 +       length += sprintf(buffer + length,
17369 +               "BiasUptime:\t%lu.%02lu\n",
17370 +               (unsigned long)cvirt->bias_uptime.tv_sec,
17371 +               (cvirt->bias_uptime.tv_nsec / (NSEC_PER_SEC / 100)));
17372 +
17373 +       a = cvirt->load[0] + (FIXED_1 / 200);
17374 +       b = cvirt->load[1] + (FIXED_1 / 200);
17375 +       c = cvirt->load[2] + (FIXED_1 / 200);
17376 +       length += sprintf(buffer + length,
17377 +               "nr_threads:\t%d\n"
17378 +               "nr_running:\t%d\n"
17379 +               "nr_unintr:\t%d\n"
17380 +               "nr_onhold:\t%d\n"
17381 +               "load_updates:\t%d\n"
17382 +               "loadavg:\t%d.%02d %d.%02d %d.%02d\n"
17383 +               "total_forks:\t%d\n",
17384 +               atomic_read(&cvirt->nr_threads),
17385 +               atomic_read(&cvirt->nr_running),
17386 +               atomic_read(&cvirt->nr_uninterruptible),
17387 +               atomic_read(&cvirt->nr_onhold),
17388 +               atomic_read(&cvirt->load_updates),
17389 +               LOAD_INT(a), LOAD_FRAC(a),
17390 +               LOAD_INT(b), LOAD_FRAC(b),
17391 +               LOAD_INT(c), LOAD_FRAC(c),
17392 +               atomic_read(&cvirt->total_forks));
17393 +       return length;
17394 +}
17395 +
17396 +static inline
17397 +int vx_info_proc_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc,
17398 +       char *buffer, int cpu)
17399 +{
17400 +       int length = 0;
17401 +       return length;
17402 +}
17403 +
17404 +#endif /* _VX_CVIRT_PROC_H */
17405 diff -NurpP --minimal linux-3.6.9/kernel/vserver/debug.c linux-3.6.9-vs2.3.4.4/kernel/vserver/debug.c
17406 --- linux-3.6.9/kernel/vserver/debug.c  1970-01-01 01:00:00.000000000 +0100
17407 +++ linux-3.6.9-vs2.3.4.4/kernel/vserver/debug.c        2012-10-04 18:47:00.000000000 +0200
17408 @@ -0,0 +1,32 @@
17409 +/*
17410 + *  kernel/vserver/debug.c
17411 + *
17412 + *  Copyright (C) 2005-2007 Herbert Pötzl
17413 + *
17414 + *  V0.01  vx_info dump support
17415 + *
17416 + */
17417 +
17418 +#include <linux/module.h>
17419 +
17420 +#include <linux/vserver/context.h>
17421 +
17422 +
17423 +void   dump_vx_info(struct vx_info *vxi, int level)
17424 +{
17425 +       printk("vx_info %p[#%d, %d.%d, %4x]\n", vxi, vxi->vx_id,
17426 +               atomic_read(&vxi->vx_usecnt),
17427 +               atomic_read(&vxi->vx_tasks),
17428 +               vxi->vx_state);
17429 +       if (level > 0) {
17430 +               __dump_vx_limit(&vxi->limit);
17431 +               __dump_vx_sched(&vxi->sched);
17432 +               __dump_vx_cvirt(&vxi->cvirt);
17433 +               __dump_vx_cacct(&vxi->cacct);
17434 +       }
17435 +       printk("---\n");
17436 +}
17437 +
17438 +
17439 +EXPORT_SYMBOL_GPL(dump_vx_info);
17440 +
17441 diff -NurpP --minimal linux-3.6.9/kernel/vserver/device.c linux-3.6.9-vs2.3.4.4/kernel/vserver/device.c
17442 --- linux-3.6.9/kernel/vserver/device.c 1970-01-01 01:00:00.000000000 +0100
17443 +++ linux-3.6.9-vs2.3.4.4/kernel/vserver/device.c       2012-10-04 18:47:00.000000000 +0200
17444 @@ -0,0 +1,443 @@
17445 +/*
17446 + *  linux/kernel/vserver/device.c
17447 + *
17448 + *  Linux-VServer: Device Support
17449 + *
17450 + *  Copyright (C) 2006  Herbert Pötzl
17451 + *  Copyright (C) 2007  Daniel Hokka Zakrisson
17452 + *
17453 + *  V0.01  device mapping basics
17454 + *  V0.02  added defaults
17455 + *
17456 + */
17457 +
17458 +#include <linux/slab.h>
17459 +#include <linux/rcupdate.h>
17460 +#include <linux/fs.h>
17461 +#include <linux/namei.h>
17462 +#include <linux/hash.h>
17463 +
17464 +#include <asm/errno.h>
17465 +#include <asm/uaccess.h>
17466 +#include <linux/vserver/base.h>
17467 +#include <linux/vserver/debug.h>
17468 +#include <linux/vserver/context.h>
17469 +#include <linux/vserver/device.h>
17470 +#include <linux/vserver/device_cmd.h>
17471 +
17472 +
17473 +#define DMAP_HASH_BITS 4
17474 +
17475 +
17476 +struct vs_mapping {
17477 +       union {
17478 +               struct hlist_node hlist;
17479 +               struct list_head list;
17480 +       } u;
17481 +#define dm_hlist       u.hlist
17482 +#define dm_list                u.list
17483 +       xid_t xid;
17484 +       dev_t device;
17485 +       struct vx_dmap_target target;
17486 +};
17487 +
17488 +
17489 +static struct hlist_head dmap_main_hash[1 << DMAP_HASH_BITS];
17490 +
17491 +static DEFINE_SPINLOCK(dmap_main_hash_lock);
17492 +
17493 +static struct vx_dmap_target dmap_defaults[2] = {
17494 +       { .flags = DATTR_OPEN },
17495 +       { .flags = DATTR_OPEN },
17496 +};
17497 +
17498 +
17499 +struct kmem_cache *dmap_cachep __read_mostly;
17500 +
17501 +int __init dmap_cache_init(void)
17502 +{
17503 +       dmap_cachep = kmem_cache_create("dmap_cache",
17504 +               sizeof(struct vs_mapping), 0,
17505 +               SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
17506 +       return 0;
17507 +}
17508 +
17509 +__initcall(dmap_cache_init);
17510 +
17511 +
17512 +static inline unsigned int __hashval(dev_t dev, int bits)
17513 +{
17514 +       return hash_long((unsigned long)dev, bits);
17515 +}
17516 +
17517 +
17518 +/*     __hash_mapping()
17519 + *     add the mapping to the hash table
17520 + */
17521 +static inline void __hash_mapping(struct vx_info *vxi, struct vs_mapping *vdm)
17522 +{
17523 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
17524 +       struct hlist_head *head, *hash = dmap_main_hash;
17525 +       int device = vdm->device;
17526 +
17527 +       spin_lock(hash_lock);
17528 +       vxdprintk(VXD_CBIT(misc, 8), "__hash_mapping: %p[#%d] %08x:%08x",
17529 +               vxi, vxi ? vxi->vx_id : 0, device, vdm->target.target);
17530 +
17531 +       head = &hash[__hashval(device, DMAP_HASH_BITS)];
17532 +       hlist_add_head(&vdm->dm_hlist, head);
17533 +       spin_unlock(hash_lock);
17534 +}
17535 +
17536 +
17537 +static inline int __mode_to_default(umode_t mode)
17538 +{
17539 +       switch (mode) {
17540 +       case S_IFBLK:
17541 +               return 0;
17542 +       case S_IFCHR:
17543 +               return 1;
17544 +       default:
17545 +               BUG();
17546 +       }
17547 +}
17548 +
17549 +
17550 +/*     __set_default()
17551 + *     set a default
17552 + */
17553 +static inline void __set_default(struct vx_info *vxi, umode_t mode,
17554 +       struct vx_dmap_target *vdmt)
17555 +{
17556 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
17557 +       spin_lock(hash_lock);
17558 +
17559 +       if (vxi)
17560 +               vxi->dmap.targets[__mode_to_default(mode)] = *vdmt;
17561 +       else
17562 +               dmap_defaults[__mode_to_default(mode)] = *vdmt;
17563 +
17564 +
17565 +       spin_unlock(hash_lock);
17566 +
17567 +       vxdprintk(VXD_CBIT(misc, 8), "__set_default: %p[#%u] %08x %04x",
17568 +                 vxi, vxi ? vxi->vx_id : 0, vdmt->target, vdmt->flags);
17569 +}
17570 +
17571 +
17572 +/*     __remove_default()
17573 + *     remove a default
17574 + */
17575 +static inline int __remove_default(struct vx_info *vxi, umode_t mode)
17576 +{
17577 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
17578 +       spin_lock(hash_lock);
17579 +
17580 +       if (vxi)
17581 +               vxi->dmap.targets[__mode_to_default(mode)].flags = 0;
17582 +       else    /* remove == reset */
17583 +               dmap_defaults[__mode_to_default(mode)].flags = DATTR_OPEN | mode;
17584 +
17585 +       spin_unlock(hash_lock);
17586 +       return 0;
17587 +}
17588 +
17589 +
17590 +/*     __find_mapping()
17591 + *     find a mapping in the hash table
17592 + *
17593 + *     caller must hold hash_lock
17594 + */
17595 +static inline int __find_mapping(xid_t xid, dev_t device, umode_t mode,
17596 +       struct vs_mapping **local, struct vs_mapping **global)
17597 +{
17598 +       struct hlist_head *hash = dmap_main_hash;
17599 +       struct hlist_head *head = &hash[__hashval(device, DMAP_HASH_BITS)];
17600 +       struct hlist_node *pos;
17601 +       struct vs_mapping *vdm;
17602 +
17603 +       *local = NULL;
17604 +       if (global)
17605 +               *global = NULL;
17606 +
17607 +       hlist_for_each(pos, head) {
17608 +               vdm = hlist_entry(pos, struct vs_mapping, dm_hlist);
17609 +
17610 +               if ((vdm->device == device) &&
17611 +                       !((vdm->target.flags ^ mode) & S_IFMT)) {
17612 +                       if (vdm->xid == xid) {
17613 +                               *local = vdm;
17614 +                               return 1;
17615 +                       } else if (global && vdm->xid == 0)
17616 +                               *global = vdm;
17617 +               }
17618 +       }
17619 +
17620 +       if (global && *global)
17621 +               return 0;
17622 +       else
17623 +               return -ENOENT;
17624 +}
17625 +
17626 +
17627 +/*     __lookup_mapping()
17628 + *     find a mapping and store the result in target and flags
17629 + */
17630 +static inline int __lookup_mapping(struct vx_info *vxi,
17631 +       dev_t device, dev_t *target, int *flags, umode_t mode)
17632 +{
17633 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
17634 +       struct vs_mapping *vdm, *global;
17635 +       struct vx_dmap_target *vdmt;
17636 +       int ret = 0;
17637 +       xid_t xid = vxi->vx_id;
17638 +       int index;
17639 +
17640 +       spin_lock(hash_lock);
17641 +       if (__find_mapping(xid, device, mode, &vdm, &global) > 0) {
17642 +               ret = 1;
17643 +               vdmt = &vdm->target;
17644 +               goto found;
17645 +       }
17646 +
17647 +       index = __mode_to_default(mode);
17648 +       if (vxi && vxi->dmap.targets[index].flags) {
17649 +               ret = 2;
17650 +               vdmt = &vxi->dmap.targets[index];
17651 +       } else if (global) {
17652 +               ret = 3;
17653 +               vdmt = &global->target;
17654 +               goto found;
17655 +       } else {
17656 +               ret = 4;
17657 +               vdmt = &dmap_defaults[index];
17658 +       }
17659 +
17660 +found:
17661 +       if (target && (vdmt->flags & DATTR_REMAP))
17662 +               *target = vdmt->target;
17663 +       else if (target)
17664 +               *target = device;
17665 +       if (flags)
17666 +               *flags = vdmt->flags;
17667 +
17668 +       spin_unlock(hash_lock);
17669 +
17670 +       return ret;
17671 +}
17672 +
17673 +
17674 +/*     __remove_mapping()
17675 + *     remove a mapping from the hash table
17676 + */
17677 +static inline int __remove_mapping(struct vx_info *vxi, dev_t device,
17678 +       umode_t mode)
17679 +{
17680 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
17681 +       struct vs_mapping *vdm = NULL;
17682 +       int ret = 0;
17683 +
17684 +       spin_lock(hash_lock);
17685 +
17686 +       ret = __find_mapping((vxi ? vxi->vx_id : 0), device, mode, &vdm,
17687 +               NULL);
17688 +       vxdprintk(VXD_CBIT(misc, 8), "__remove_mapping: %p[#%d] %08x %04x",
17689 +               vxi, vxi ? vxi->vx_id : 0, device, mode);
17690 +       if (ret < 0)
17691 +               goto out;
17692 +       hlist_del(&vdm->dm_hlist);
17693 +
17694 +out:
17695 +       spin_unlock(hash_lock);
17696 +       if (vdm)
17697 +               kmem_cache_free(dmap_cachep, vdm);
17698 +       return ret;
17699 +}
17700 +
17701 +
17702 +
17703 +int vs_map_device(struct vx_info *vxi,
17704 +       dev_t device, dev_t *target, umode_t mode)
17705 +{
17706 +       int ret, flags = DATTR_MASK;
17707 +
17708 +       if (!vxi) {
17709 +               if (target)
17710 +                       *target = device;
17711 +               goto out;
17712 +       }
17713 +       ret = __lookup_mapping(vxi, device, target, &flags, mode);
17714 +       vxdprintk(VXD_CBIT(misc, 8), "vs_map_device: %08x target: %08x flags: %04x mode: %04x mapped=%d",
17715 +               device, target ? *target : 0, flags, mode, ret);
17716 +out:
17717 +       return (flags & DATTR_MASK);
17718 +}
17719 +
17720 +
17721 +
17722 +static int do_set_mapping(struct vx_info *vxi,
17723 +       dev_t device, dev_t target, int flags, umode_t mode)
17724 +{
17725 +       if (device) {
17726 +               struct vs_mapping *new;
17727 +
17728 +               new = kmem_cache_alloc(dmap_cachep, GFP_KERNEL);
17729 +               if (!new)
17730 +                       return -ENOMEM;
17731 +
17732 +               INIT_HLIST_NODE(&new->dm_hlist);
17733 +               new->device = device;
17734 +               new->target.target = target;
17735 +               new->target.flags = flags | mode;
17736 +               new->xid = (vxi ? vxi->vx_id : 0);
17737 +
17738 +               vxdprintk(VXD_CBIT(misc, 8), "do_set_mapping: %08x target: %08x flags: %04x", device, target, flags);
17739 +               __hash_mapping(vxi, new);
17740 +       } else {
17741 +               struct vx_dmap_target new = {
17742 +                       .target = target,
17743 +                       .flags = flags | mode,
17744 +               };
17745 +               __set_default(vxi, mode, &new);
17746 +       }
17747 +       return 0;
17748 +}
17749 +
17750 +
17751 +static int do_unset_mapping(struct vx_info *vxi,
17752 +       dev_t device, dev_t target, int flags, umode_t mode)
17753 +{
17754 +       int ret = -EINVAL;
17755 +
17756 +       if (device) {
17757 +               ret = __remove_mapping(vxi, device, mode);
17758 +               if (ret < 0)
17759 +                       goto out;
17760 +       } else {
17761 +               ret = __remove_default(vxi, mode);
17762 +               if (ret < 0)
17763 +                       goto out;
17764 +       }
17765 +
17766 +out:
17767 +       return ret;
17768 +}
17769 +
17770 +
17771 +static inline int __user_device(const char __user *name, dev_t *dev,
17772 +       umode_t *mode)
17773 +{
17774 +       struct nameidata nd;
17775 +       int ret;
17776 +
17777 +       if (!name) {
17778 +               *dev = 0;
17779 +               return 0;
17780 +       }
17781 +       ret = user_lpath(name, &nd.path);
17782 +       if (ret)
17783 +               return ret;
17784 +       if (nd.path.dentry->d_inode) {
17785 +               *dev = nd.path.dentry->d_inode->i_rdev;
17786 +               *mode = nd.path.dentry->d_inode->i_mode;
17787 +       }
17788 +       path_put(&nd.path);
17789 +       return 0;
17790 +}
17791 +
17792 +static inline int __mapping_mode(dev_t device, dev_t target,
17793 +       umode_t device_mode, umode_t target_mode, umode_t *mode)
17794 +{
17795 +       if (device)
17796 +               *mode = device_mode & S_IFMT;
17797 +       else if (target)
17798 +               *mode = target_mode & S_IFMT;
17799 +       else
17800 +               return -EINVAL;
17801 +
17802 +       /* if both given, device and target mode have to match */
17803 +       if (device && target &&
17804 +               ((device_mode ^ target_mode) & S_IFMT))
17805 +               return -EINVAL;
17806 +       return 0;
17807 +}
17808 +
17809 +
17810 +static inline int do_mapping(struct vx_info *vxi, const char __user *device_path,
17811 +       const char __user *target_path, int flags, int set)
17812 +{
17813 +       dev_t device = ~0, target = ~0;
17814 +       umode_t device_mode = 0, target_mode = 0, mode;
17815 +       int ret;
17816 +
17817 +       ret = __user_device(device_path, &device, &device_mode);
17818 +       if (ret)
17819 +               return ret;
17820 +       ret = __user_device(target_path, &target, &target_mode);
17821 +       if (ret)
17822 +               return ret;
17823 +
17824 +       ret = __mapping_mode(device, target,
17825 +               device_mode, target_mode, &mode);
17826 +       if (ret)
17827 +               return ret;
17828 +
17829 +       if (set)
17830 +               return do_set_mapping(vxi, device, target,
17831 +                       flags, mode);
17832 +       else
17833 +               return do_unset_mapping(vxi, device, target,
17834 +                       flags, mode);
17835 +}
17836 +
17837 +
17838 +int vc_set_mapping(struct vx_info *vxi, void __user *data)
17839 +{
17840 +       struct vcmd_set_mapping_v0 vc_data;
17841 +
17842 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17843 +               return -EFAULT;
17844 +
17845 +       return do_mapping(vxi, vc_data.device, vc_data.target,
17846 +               vc_data.flags, 1);
17847 +}
17848 +
17849 +int vc_unset_mapping(struct vx_info *vxi, void __user *data)
17850 +{
17851 +       struct vcmd_set_mapping_v0 vc_data;
17852 +
17853 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17854 +               return -EFAULT;
17855 +
17856 +       return do_mapping(vxi, vc_data.device, vc_data.target,
17857 +               vc_data.flags, 0);
17858 +}
17859 +
17860 +
17861 +#ifdef CONFIG_COMPAT
17862 +
17863 +int vc_set_mapping_x32(struct vx_info *vxi, void __user *data)
17864 +{
17865 +       struct vcmd_set_mapping_v0_x32 vc_data;
17866 +
17867 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17868 +               return -EFAULT;
17869 +
17870 +       return do_mapping(vxi, compat_ptr(vc_data.device_ptr),
17871 +               compat_ptr(vc_data.target_ptr), vc_data.flags, 1);
17872 +}
17873 +
17874 +int vc_unset_mapping_x32(struct vx_info *vxi, void __user *data)
17875 +{
17876 +       struct vcmd_set_mapping_v0_x32 vc_data;
17877 +
17878 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17879 +               return -EFAULT;
17880 +
17881 +       return do_mapping(vxi, compat_ptr(vc_data.device_ptr),
17882 +               compat_ptr(vc_data.target_ptr), vc_data.flags, 0);
17883 +}
17884 +
17885 +#endif /* CONFIG_COMPAT */
17886 +
17887 +
17888 diff -NurpP --minimal linux-3.6.9/kernel/vserver/dlimit.c linux-3.6.9-vs2.3.4.4/kernel/vserver/dlimit.c
17889 --- linux-3.6.9/kernel/vserver/dlimit.c 1970-01-01 01:00:00.000000000 +0100
17890 +++ linux-3.6.9-vs2.3.4.4/kernel/vserver/dlimit.c       2012-10-04 18:47:00.000000000 +0200
17891 @@ -0,0 +1,531 @@
17892 +/*
17893 + *  linux/kernel/vserver/dlimit.c
17894 + *
17895 + *  Virtual Server: Context Disk Limits
17896 + *
17897 + *  Copyright (C) 2004-2009  Herbert Pötzl
17898 + *
17899 + *  V0.01  initial version
17900 + *  V0.02  compat32 splitup
17901 + *  V0.03  extended interface
17902 + *
17903 + */
17904 +
17905 +#include <linux/statfs.h>
17906 +#include <linux/sched.h>
17907 +#include <linux/namei.h>
17908 +#include <linux/vs_tag.h>
17909 +#include <linux/vs_dlimit.h>
17910 +#include <linux/vserver/dlimit_cmd.h>
17911 +#include <linux/slab.h>
17912 +// #include <linux/gfp.h>
17913 +
17914 +#include <asm/uaccess.h>
17915 +
17916 +/*     __alloc_dl_info()
17917 +
17918 +       * allocate an initialized dl_info struct
17919 +       * doesn't make it visible (hash)                        */
17920 +
17921 +static struct dl_info *__alloc_dl_info(struct super_block *sb, vs_tag_t tag)
17922 +{
17923 +       struct dl_info *new = NULL;
17924 +
17925 +       vxdprintk(VXD_CBIT(dlim, 5),
17926 +               "alloc_dl_info(%p,%d)*", sb, tag);
17927 +
17928 +       /* would this benefit from a slab cache? */
17929 +       new = kmalloc(sizeof(struct dl_info), GFP_KERNEL);
17930 +       if (!new)
17931 +               return 0;
17932 +
17933 +       memset(new, 0, sizeof(struct dl_info));
17934 +       new->dl_tag = tag;
17935 +       new->dl_sb = sb;
17936 +       // INIT_RCU_HEAD(&new->dl_rcu);
17937 +       INIT_HLIST_NODE(&new->dl_hlist);
17938 +       spin_lock_init(&new->dl_lock);
17939 +       atomic_set(&new->dl_refcnt, 0);
17940 +       atomic_set(&new->dl_usecnt, 0);
17941 +
17942 +       /* rest of init goes here */
17943 +
17944 +       vxdprintk(VXD_CBIT(dlim, 4),
17945 +               "alloc_dl_info(%p,%d) = %p", sb, tag, new);
17946 +       return new;
17947 +}
17948 +
17949 +/*     __dealloc_dl_info()
17950 +
17951 +       * final disposal of dl_info                             */
17952 +
17953 +static void __dealloc_dl_info(struct dl_info *dli)
17954 +{
17955 +       vxdprintk(VXD_CBIT(dlim, 4),
17956 +               "dealloc_dl_info(%p)", dli);
17957 +
17958 +       dli->dl_hlist.next = LIST_POISON1;
17959 +       dli->dl_tag = -1;
17960 +       dli->dl_sb = 0;
17961 +
17962 +       BUG_ON(atomic_read(&dli->dl_usecnt));
17963 +       BUG_ON(atomic_read(&dli->dl_refcnt));
17964 +
17965 +       kfree(dli);
17966 +}
17967 +
17968 +
17969 +/*     hash table for dl_info hash */
17970 +
17971 +#define DL_HASH_SIZE   13
17972 +
17973 +struct hlist_head dl_info_hash[DL_HASH_SIZE];
17974 +
17975 +static DEFINE_SPINLOCK(dl_info_hash_lock);
17976 +
17977 +
17978 +static inline unsigned int __hashval(struct super_block *sb, vs_tag_t tag)
17979 +{
17980 +       return ((tag ^ (unsigned long)sb) % DL_HASH_SIZE);
17981 +}
17982 +
17983 +
17984 +
17985 +/*     __hash_dl_info()
17986 +
17987 +       * add the dli to the global hash table
17988 +       * requires the hash_lock to be held                     */
17989 +
17990 +static inline void __hash_dl_info(struct dl_info *dli)
17991 +{
17992 +       struct hlist_head *head;
17993 +
17994 +       vxdprintk(VXD_CBIT(dlim, 6),
17995 +               "__hash_dl_info: %p[#%d]", dli, dli->dl_tag);
17996 +       get_dl_info(dli);
17997 +       head = &dl_info_hash[__hashval(dli->dl_sb, dli->dl_tag)];
17998 +       hlist_add_head_rcu(&dli->dl_hlist, head);
17999 +}
18000 +
18001 +/*     __unhash_dl_info()
18002 +
18003 +       * remove the dli from the global hash table
18004 +       * requires the hash_lock to be held                     */
18005 +
18006 +static inline void __unhash_dl_info(struct dl_info *dli)
18007 +{
18008 +       vxdprintk(VXD_CBIT(dlim, 6),
18009 +               "__unhash_dl_info: %p[#%d]", dli, dli->dl_tag);
18010 +       hlist_del_rcu(&dli->dl_hlist);
18011 +       put_dl_info(dli);
18012 +}
18013 +
18014 +
18015 +/*     __lookup_dl_info()
18016 +
18017 +       * requires the rcu_read_lock()
18018 +       * doesn't increment the dl_refcnt                       */
18019 +
18020 +static inline struct dl_info *__lookup_dl_info(struct super_block *sb, vs_tag_t tag)
18021 +{
18022 +       struct hlist_head *head = &dl_info_hash[__hashval(sb, tag)];
18023 +       struct hlist_node *pos;
18024 +       struct dl_info *dli;
18025 +
18026 +       hlist_for_each_entry_rcu(dli, pos, head, dl_hlist) {
18027 +
18028 +               if (dli->dl_tag == tag && dli->dl_sb == sb) {
18029 +                       return dli;
18030 +               }
18031 +       }
18032 +       return NULL;
18033 +}
18034 +
18035 +
18036 +struct dl_info *locate_dl_info(struct super_block *sb, vs_tag_t tag)
18037 +{
18038 +       struct dl_info *dli;
18039 +
18040 +       rcu_read_lock();
18041 +       dli = get_dl_info(__lookup_dl_info(sb, tag));
18042 +       vxdprintk(VXD_CBIT(dlim, 7),
18043 +               "locate_dl_info(%p,#%d) = %p", sb, tag, dli);
18044 +       rcu_read_unlock();
18045 +       return dli;
18046 +}
18047 +
18048 +void rcu_free_dl_info(struct rcu_head *head)
18049 +{
18050 +       struct dl_info *dli = container_of(head, struct dl_info, dl_rcu);
18051 +       int usecnt, refcnt;
18052 +
18053 +       BUG_ON(!dli || !head);
18054 +
18055 +       usecnt = atomic_read(&dli->dl_usecnt);
18056 +       BUG_ON(usecnt < 0);
18057 +
18058 +       refcnt = atomic_read(&dli->dl_refcnt);
18059 +       BUG_ON(refcnt < 0);
18060 +
18061 +       vxdprintk(VXD_CBIT(dlim, 3),
18062 +               "rcu_free_dl_info(%p)", dli);
18063 +       if (!usecnt)
18064 +               __dealloc_dl_info(dli);
18065 +       else
18066 +               printk("!!! rcu didn't free\n");
18067 +}
18068 +
18069 +
18070 +
18071 +
18072 +static int do_addrem_dlimit(uint32_t id, const char __user *name,
18073 +       uint32_t flags, int add)
18074 +{
18075 +       struct path path;
18076 +       int ret;
18077 +
18078 +       ret = user_lpath(name, &path);
18079 +       if (!ret) {
18080 +               struct super_block *sb;
18081 +               struct dl_info *dli;
18082 +
18083 +               ret = -EINVAL;
18084 +               if (!path.dentry->d_inode)
18085 +                       goto out_release;
18086 +               if (!(sb = path.dentry->d_inode->i_sb))
18087 +                       goto out_release;
18088 +
18089 +               if (add) {
18090 +                       dli = __alloc_dl_info(sb, id);
18091 +                       spin_lock(&dl_info_hash_lock);
18092 +
18093 +                       ret = -EEXIST;
18094 +                       if (__lookup_dl_info(sb, id))
18095 +                               goto out_unlock;
18096 +                       __hash_dl_info(dli);
18097 +                       dli = NULL;
18098 +               } else {
18099 +                       spin_lock(&dl_info_hash_lock);
18100 +                       dli = __lookup_dl_info(sb, id);
18101 +
18102 +                       ret = -ESRCH;
18103 +                       if (!dli)
18104 +                               goto out_unlock;
18105 +                       __unhash_dl_info(dli);
18106 +               }
18107 +               ret = 0;
18108 +       out_unlock:
18109 +               spin_unlock(&dl_info_hash_lock);
18110 +               if (add && dli)
18111 +                       __dealloc_dl_info(dli);
18112 +       out_release:
18113 +               path_put(&path);
18114 +       }
18115 +       return ret;
18116 +}
18117 +
18118 +int vc_add_dlimit(uint32_t id, void __user *data)
18119 +{
18120 +       struct vcmd_ctx_dlimit_base_v0 vc_data;
18121 +
18122 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18123 +               return -EFAULT;
18124 +
18125 +       return do_addrem_dlimit(id, vc_data.name, vc_data.flags, 1);
18126 +}
18127 +
18128 +int vc_rem_dlimit(uint32_t id, void __user *data)
18129 +{
18130 +       struct vcmd_ctx_dlimit_base_v0 vc_data;
18131 +
18132 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18133 +               return -EFAULT;
18134 +
18135 +       return do_addrem_dlimit(id, vc_data.name, vc_data.flags, 0);
18136 +}
18137 +
18138 +#ifdef CONFIG_COMPAT
18139 +
18140 +int vc_add_dlimit_x32(uint32_t id, void __user *data)
18141 +{
18142 +       struct vcmd_ctx_dlimit_base_v0_x32 vc_data;
18143 +
18144 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18145 +               return -EFAULT;
18146 +
18147 +       return do_addrem_dlimit(id,
18148 +               compat_ptr(vc_data.name_ptr), vc_data.flags, 1);
18149 +}
18150 +
18151 +int vc_rem_dlimit_x32(uint32_t id, void __user *data)
18152 +{
18153 +       struct vcmd_ctx_dlimit_base_v0_x32 vc_data;
18154 +
18155 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18156 +               return -EFAULT;
18157 +
18158 +       return do_addrem_dlimit(id,
18159 +               compat_ptr(vc_data.name_ptr), vc_data.flags, 0);
18160 +}
18161 +
18162 +#endif /* CONFIG_COMPAT */
18163 +
18164 +
18165 +static inline
18166 +int do_set_dlimit(uint32_t id, const char __user *name,
18167 +       uint32_t space_used, uint32_t space_total,
18168 +       uint32_t inodes_used, uint32_t inodes_total,
18169 +       uint32_t reserved, uint32_t flags)
18170 +{
18171 +       struct path path;
18172 +       int ret;
18173 +
18174 +       ret = user_lpath(name, &path);
18175 +       if (!ret) {
18176 +               struct super_block *sb;
18177 +               struct dl_info *dli;
18178 +
18179 +               ret = -EINVAL;
18180 +               if (!path.dentry->d_inode)
18181 +                       goto out_release;
18182 +               if (!(sb = path.dentry->d_inode->i_sb))
18183 +                       goto out_release;
18184 +
18185 +               /* sanity checks */
18186 +               if ((reserved != CDLIM_KEEP &&
18187 +                       reserved > 100) ||
18188 +                       (inodes_used != CDLIM_KEEP &&
18189 +                       inodes_used > inodes_total) ||
18190 +                       (space_used != CDLIM_KEEP &&
18191 +                       space_used > space_total))
18192 +                       goto out_release;
18193 +
18194 +               ret = -ESRCH;
18195 +               dli = locate_dl_info(sb, id);
18196 +               if (!dli)
18197 +                       goto out_release;
18198 +
18199 +               spin_lock(&dli->dl_lock);
18200 +
18201 +               if (inodes_used != CDLIM_KEEP)
18202 +                       dli->dl_inodes_used = inodes_used;
18203 +               if (inodes_total != CDLIM_KEEP)
18204 +                       dli->dl_inodes_total = inodes_total;
18205 +               if (space_used != CDLIM_KEEP)
18206 +                       dli->dl_space_used = dlimit_space_32to64(
18207 +                               space_used, flags, DLIMS_USED);
18208 +
18209 +               if (space_total == CDLIM_INFINITY)
18210 +                       dli->dl_space_total = DLIM_INFINITY;
18211 +               else if (space_total != CDLIM_KEEP)
18212 +                       dli->dl_space_total = dlimit_space_32to64(
18213 +                               space_total, flags, DLIMS_TOTAL);
18214 +
18215 +               if (reserved != CDLIM_KEEP)
18216 +                       dli->dl_nrlmult = (1 << 10) * (100 - reserved) / 100;
18217 +
18218 +               spin_unlock(&dli->dl_lock);
18219 +
18220 +               put_dl_info(dli);
18221 +               ret = 0;
18222 +
18223 +       out_release:
18224 +               path_put(&path);
18225 +       }
18226 +       return ret;
18227 +}
18228 +
18229 +int vc_set_dlimit(uint32_t id, void __user *data)
18230 +{
18231 +       struct vcmd_ctx_dlimit_v0 vc_data;
18232 +
18233 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18234 +               return -EFAULT;
18235 +
18236 +       return do_set_dlimit(id, vc_data.name,
18237 +               vc_data.space_used, vc_data.space_total,
18238 +               vc_data.inodes_used, vc_data.inodes_total,
18239 +               vc_data.reserved, vc_data.flags);
18240 +}
18241 +
18242 +#ifdef CONFIG_COMPAT
18243 +
18244 +int vc_set_dlimit_x32(uint32_t id, void __user *data)
18245 +{
18246 +       struct vcmd_ctx_dlimit_v0_x32 vc_data;
18247 +
18248 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18249 +               return -EFAULT;
18250 +
18251 +       return do_set_dlimit(id, compat_ptr(vc_data.name_ptr),
18252 +               vc_data.space_used, vc_data.space_total,
18253 +               vc_data.inodes_used, vc_data.inodes_total,
18254 +               vc_data.reserved, vc_data.flags);
18255 +}
18256 +
18257 +#endif /* CONFIG_COMPAT */
18258 +
18259 +
18260 +static inline
18261 +int do_get_dlimit(uint32_t id, const char __user *name,
18262 +       uint32_t *space_used, uint32_t *space_total,
18263 +       uint32_t *inodes_used, uint32_t *inodes_total,
18264 +       uint32_t *reserved, uint32_t *flags)
18265 +{
18266 +       struct path path;
18267 +       int ret;
18268 +
18269 +       ret = user_lpath(name, &path);
18270 +       if (!ret) {
18271 +               struct super_block *sb;
18272 +               struct dl_info *dli;
18273 +
18274 +               ret = -EINVAL;
18275 +               if (!path.dentry->d_inode)
18276 +                       goto out_release;
18277 +               if (!(sb = path.dentry->d_inode->i_sb))
18278 +                       goto out_release;
18279 +
18280 +               ret = -ESRCH;
18281 +               dli = locate_dl_info(sb, id);
18282 +               if (!dli)
18283 +                       goto out_release;
18284 +
18285 +               spin_lock(&dli->dl_lock);
18286 +               *inodes_used = dli->dl_inodes_used;
18287 +               *inodes_total = dli->dl_inodes_total;
18288 +
18289 +               *space_used = dlimit_space_64to32(
18290 +                       dli->dl_space_used, flags, DLIMS_USED);
18291 +
18292 +               if (dli->dl_space_total == DLIM_INFINITY)
18293 +                       *space_total = CDLIM_INFINITY;
18294 +               else
18295 +                       *space_total = dlimit_space_64to32(
18296 +                               dli->dl_space_total, flags, DLIMS_TOTAL);
18297 +
18298 +               *reserved = 100 - ((dli->dl_nrlmult * 100 + 512) >> 10);
18299 +               spin_unlock(&dli->dl_lock);
18300 +
18301 +               put_dl_info(dli);
18302 +               ret = -EFAULT;
18303 +
18304 +               ret = 0;
18305 +       out_release:
18306 +               path_put(&path);
18307 +       }
18308 +       return ret;
18309 +}
18310 +
18311 +
18312 +int vc_get_dlimit(uint32_t id, void __user *data)
18313 +{
18314 +       struct vcmd_ctx_dlimit_v0 vc_data;
18315 +       int ret;
18316 +
18317 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18318 +               return -EFAULT;
18319 +
18320 +       ret = do_get_dlimit(id, vc_data.name,
18321 +               &vc_data.space_used, &vc_data.space_total,
18322 +               &vc_data.inodes_used, &vc_data.inodes_total,
18323 +               &vc_data.reserved, &vc_data.flags);
18324 +       if (ret)
18325 +               return ret;
18326 +
18327 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18328 +               return -EFAULT;
18329 +       return 0;
18330 +}
18331 +
18332 +#ifdef CONFIG_COMPAT
18333 +
18334 +int vc_get_dlimit_x32(uint32_t id, void __user *data)
18335 +{
18336 +       struct vcmd_ctx_dlimit_v0_x32 vc_data;
18337 +       int ret;
18338 +
18339 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18340 +               return -EFAULT;
18341 +
18342 +       ret = do_get_dlimit(id, compat_ptr(vc_data.name_ptr),
18343 +               &vc_data.space_used, &vc_data.space_total,
18344 +               &vc_data.inodes_used, &vc_data.inodes_total,
18345 +               &vc_data.reserved, &vc_data.flags);
18346 +       if (ret)
18347 +               return ret;
18348 +
18349 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18350 +               return -EFAULT;
18351 +       return 0;
18352 +}
18353 +
18354 +#endif /* CONFIG_COMPAT */
18355 +
18356 +
18357 +void vx_vsi_statfs(struct super_block *sb, struct kstatfs *buf)
18358 +{
18359 +       struct dl_info *dli;
18360 +       __u64 blimit, bfree, bavail;
18361 +       __u32 ifree;
18362 +
18363 +       dli = locate_dl_info(sb, dx_current_tag());
18364 +       if (!dli)
18365 +               return;
18366 +
18367 +       spin_lock(&dli->dl_lock);
18368 +       if (dli->dl_inodes_total == (unsigned long)DLIM_INFINITY)
18369 +               goto no_ilim;
18370 +
18371 +       /* reduce max inodes available to limit */
18372 +       if (buf->f_files > dli->dl_inodes_total)
18373 +               buf->f_files = dli->dl_inodes_total;
18374 +
18375 +       ifree = dli->dl_inodes_total - dli->dl_inodes_used;
18376 +       /* reduce free inodes to min */
18377 +       if (ifree < buf->f_ffree)
18378 +               buf->f_ffree = ifree;
18379 +
18380 +no_ilim:
18381 +       if (dli->dl_space_total == DLIM_INFINITY)
18382 +               goto no_blim;
18383 +
18384 +       blimit = dli->dl_space_total >> sb->s_blocksize_bits;
18385 +
18386 +       if (dli->dl_space_total < dli->dl_space_used)
18387 +               bfree = 0;
18388 +       else
18389 +               bfree = (dli->dl_space_total - dli->dl_space_used)
18390 +                       >> sb->s_blocksize_bits;
18391 +
18392 +       bavail = ((dli->dl_space_total >> 10) * dli->dl_nrlmult);
18393 +       if (bavail < dli->dl_space_used)
18394 +               bavail = 0;
18395 +       else
18396 +               bavail = (bavail - dli->dl_space_used)
18397 +                       >> sb->s_blocksize_bits;
18398 +
18399 +       /* reduce max space available to limit */
18400 +       if (buf->f_blocks > blimit)
18401 +               buf->f_blocks = blimit;
18402 +
18403 +       /* reduce free space to min */
18404 +       if (bfree < buf->f_bfree)
18405 +               buf->f_bfree = bfree;
18406 +
18407 +       /* reduce avail space to min */
18408 +       if (bavail < buf->f_bavail)
18409 +               buf->f_bavail = bavail;
18410 +
18411 +no_blim:
18412 +       spin_unlock(&dli->dl_lock);
18413 +       put_dl_info(dli);
18414 +
18415 +       return;
18416 +}
18417 +
18418 +#include <linux/module.h>
18419 +
18420 +EXPORT_SYMBOL_GPL(locate_dl_info);
18421 +EXPORT_SYMBOL_GPL(rcu_free_dl_info);
18422 +
18423 diff -NurpP --minimal linux-3.6.9/kernel/vserver/helper.c linux-3.6.9-vs2.3.4.4/kernel/vserver/helper.c
18424 --- linux-3.6.9/kernel/vserver/helper.c 1970-01-01 01:00:00.000000000 +0100
18425 +++ linux-3.6.9-vs2.3.4.4/kernel/vserver/helper.c       2012-10-04 18:47:00.000000000 +0200
18426 @@ -0,0 +1,229 @@
18427 +/*
18428 + *  linux/kernel/vserver/helper.c
18429 + *
18430 + *  Virtual Context Support
18431 + *
18432 + *  Copyright (C) 2004-2007  Herbert Pötzl
18433 + *
18434 + *  V0.01  basic helper
18435 + *
18436 + */
18437 +
18438 +#include <linux/kmod.h>
18439 +#include <linux/reboot.h>
18440 +#include <linux/vs_context.h>
18441 +#include <linux/vs_network.h>
18442 +#include <linux/vserver/signal.h>
18443 +
18444 +
18445 +char vshelper_path[255] = "/sbin/vshelper";
18446 +
18447 +static int vshelper_init(struct subprocess_info *info, struct cred *new_cred)
18448 +{
18449 +       current->flags &= ~PF_THREAD_BOUND;
18450 +       return 0;
18451 +}
18452 +
18453 +static int do_vshelper(char *name, char *argv[], char *envp[], int sync)
18454 +{
18455 +       int ret;
18456 +
18457 +       if ((ret = call_usermodehelper_fns(name, argv, envp,
18458 +               sync ? UMH_WAIT_PROC : UMH_WAIT_EXEC,
18459 +               vshelper_init, NULL, NULL))) {
18460 +               printk(KERN_WARNING "%s: (%s %s) returned %s with %d\n",
18461 +                       name, argv[1], argv[2],
18462 +                       sync ? "sync" : "async", ret);
18463 +       }
18464 +       vxdprintk(VXD_CBIT(switch, 4),
18465 +               "%s: (%s %s) returned %s with %d",
18466 +               name, argv[1], argv[2], sync ? "sync" : "async", ret);
18467 +       return ret;
18468 +}
18469 +
18470 +/*
18471 + *      vshelper path is set via /proc/sys
18472 + *      invoked by vserver sys_reboot(), with
18473 + *      the following arguments
18474 + *
18475 + *      argv [0] = vshelper_path;
18476 + *      argv [1] = action: "restart", "halt", "poweroff", ...
18477 + *      argv [2] = context identifier
18478 + *
18479 + *      envp [*] = type-specific parameters
18480 + */
18481 +
18482 +long vs_reboot_helper(struct vx_info *vxi, int cmd, void __user *arg)
18483 +{
18484 +       char id_buf[8], cmd_buf[16];
18485 +       char uid_buf[16], pid_buf[16];
18486 +       int ret;
18487 +
18488 +       char *argv[] = {vshelper_path, NULL, id_buf, 0};
18489 +       char *envp[] = {"HOME=/", "TERM=linux",
18490 +                       "PATH=/sbin:/usr/sbin:/bin:/usr/bin",
18491 +                       uid_buf, pid_buf, cmd_buf, 0};
18492 +
18493 +       if (vx_info_state(vxi, VXS_HELPER))
18494 +               return -EAGAIN;
18495 +       vxi->vx_state |= VXS_HELPER;
18496 +
18497 +       snprintf(id_buf, sizeof(id_buf), "%d", vxi->vx_id);
18498 +
18499 +       snprintf(cmd_buf, sizeof(cmd_buf), "VS_CMD=%08x", cmd);
18500 +       snprintf(uid_buf, sizeof(uid_buf), "VS_UID=%d", current_uid());
18501 +       snprintf(pid_buf, sizeof(pid_buf), "VS_PID=%d", current->pid);
18502 +
18503 +       switch (cmd) {
18504 +       case LINUX_REBOOT_CMD_RESTART:
18505 +               argv[1] = "restart";
18506 +               break;
18507 +
18508 +       case LINUX_REBOOT_CMD_HALT:
18509 +               argv[1] = "halt";
18510 +               break;
18511 +
18512 +       case LINUX_REBOOT_CMD_POWER_OFF:
18513 +               argv[1] = "poweroff";
18514 +               break;
18515 +
18516 +       case LINUX_REBOOT_CMD_SW_SUSPEND:
18517 +               argv[1] = "swsusp";
18518 +               break;
18519 +
18520 +       case LINUX_REBOOT_CMD_OOM:
18521 +               argv[1] = "oom";
18522 +               break;
18523 +
18524 +       default:
18525 +               vxi->vx_state &= ~VXS_HELPER;
18526 +               return 0;
18527 +       }
18528 +
18529 +       ret = do_vshelper(vshelper_path, argv, envp, 0);
18530 +       vxi->vx_state &= ~VXS_HELPER;
18531 +       __wakeup_vx_info(vxi);
18532 +       return (ret) ? -EPERM : 0;
18533 +}
18534 +
18535 +
18536 +long vs_reboot(unsigned int cmd, void __user *arg)
18537 +{
18538 +       struct vx_info *vxi = current_vx_info();
18539 +       long ret = 0;
18540 +
18541 +       vxdprintk(VXD_CBIT(misc, 5),
18542 +               "vs_reboot(%p[#%d],%u)",
18543 +               vxi, vxi ? vxi->vx_id : 0, cmd);
18544 +
18545 +       ret = vs_reboot_helper(vxi, cmd, arg);
18546 +       if (ret)
18547 +               return ret;
18548 +
18549 +       vxi->reboot_cmd = cmd;
18550 +       if (vx_info_flags(vxi, VXF_REBOOT_KILL, 0)) {
18551 +               switch (cmd) {
18552 +               case LINUX_REBOOT_CMD_RESTART:
18553 +               case LINUX_REBOOT_CMD_HALT:
18554 +               case LINUX_REBOOT_CMD_POWER_OFF:
18555 +                       vx_info_kill(vxi, 0, SIGKILL);
18556 +                       vx_info_kill(vxi, 1, SIGKILL);
18557 +               default:
18558 +                       break;
18559 +               }
18560 +       }
18561 +       return 0;
18562 +}
18563 +
18564 +long vs_oom_action(unsigned int cmd)
18565 +{
18566 +       struct vx_info *vxi = current_vx_info();
18567 +       long ret = 0;
18568 +
18569 +       vxdprintk(VXD_CBIT(misc, 5),
18570 +               "vs_oom_action(%p[#%d],%u)",
18571 +               vxi, vxi ? vxi->vx_id : 0, cmd);
18572 +
18573 +       ret = vs_reboot_helper(vxi, cmd, NULL);
18574 +       if (ret)
18575 +               return ret;
18576 +
18577 +       vxi->reboot_cmd = cmd;
18578 +       if (vx_info_flags(vxi, VXF_REBOOT_KILL, 0)) {
18579 +               vx_info_kill(vxi, 0, SIGKILL);
18580 +               vx_info_kill(vxi, 1, SIGKILL);
18581 +       }
18582 +       return 0;
18583 +}
18584 +
18585 +/*
18586 + *      argv [0] = vshelper_path;
18587 + *      argv [1] = action: "startup", "shutdown"
18588 + *      argv [2] = context identifier
18589 + *
18590 + *      envp [*] = type-specific parameters
18591 + */
18592 +
18593 +long vs_state_change(struct vx_info *vxi, unsigned int cmd)
18594 +{
18595 +       char id_buf[8], cmd_buf[16];
18596 +       char *argv[] = {vshelper_path, NULL, id_buf, 0};
18597 +       char *envp[] = {"HOME=/", "TERM=linux",
18598 +                       "PATH=/sbin:/usr/sbin:/bin:/usr/bin", cmd_buf, 0};
18599 +
18600 +       if (!vx_info_flags(vxi, VXF_SC_HELPER, 0))
18601 +               return 0;
18602 +
18603 +       snprintf(id_buf, sizeof(id_buf), "%d", vxi->vx_id);
18604 +       snprintf(cmd_buf, sizeof(cmd_buf), "VS_CMD=%08x", cmd);
18605 +
18606 +       switch (cmd) {
18607 +       case VSC_STARTUP:
18608 +               argv[1] = "startup";
18609 +               break;
18610 +       case VSC_SHUTDOWN:
18611 +               argv[1] = "shutdown";
18612 +               break;
18613 +       default:
18614 +               return 0;
18615 +       }
18616 +
18617 +       return do_vshelper(vshelper_path, argv, envp, 1);
18618 +}
18619 +
18620 +
18621 +/*
18622 + *      argv [0] = vshelper_path;
18623 + *      argv [1] = action: "netup", "netdown"
18624 + *      argv [2] = context identifier
18625 + *
18626 + *      envp [*] = type-specific parameters
18627 + */
18628 +
18629 +long vs_net_change(struct nx_info *nxi, unsigned int cmd)
18630 +{
18631 +       char id_buf[8], cmd_buf[16];
18632 +       char *argv[] = {vshelper_path, NULL, id_buf, 0};
18633 +       char *envp[] = {"HOME=/", "TERM=linux",
18634 +                       "PATH=/sbin:/usr/sbin:/bin:/usr/bin", cmd_buf, 0};
18635 +
18636 +       if (!nx_info_flags(nxi, NXF_SC_HELPER, 0))
18637 +               return 0;
18638 +
18639 +       snprintf(id_buf, sizeof(id_buf), "%d", nxi->nx_id);
18640 +       snprintf(cmd_buf, sizeof(cmd_buf), "VS_CMD=%08x", cmd);
18641 +
18642 +       switch (cmd) {
18643 +       case VSC_NETUP:
18644 +               argv[1] = "netup";
18645 +               break;
18646 +       case VSC_NETDOWN:
18647 +               argv[1] = "netdown";
18648 +               break;
18649 +       default:
18650 +               return 0;
18651 +       }
18652 +
18653 +       return do_vshelper(vshelper_path, argv, envp, 1);
18654 +}
18655 +
18656 diff -NurpP --minimal linux-3.6.9/kernel/vserver/history.c linux-3.6.9-vs2.3.4.4/kernel/vserver/history.c
18657 --- linux-3.6.9/kernel/vserver/history.c        1970-01-01 01:00:00.000000000 +0100
18658 +++ linux-3.6.9-vs2.3.4.4/kernel/vserver/history.c      2012-10-04 18:47:00.000000000 +0200
18659 @@ -0,0 +1,258 @@
18660 +/*
18661 + *  kernel/vserver/history.c
18662 + *
18663 + *  Virtual Context History Backtrace
18664 + *
18665 + *  Copyright (C) 2004-2007  Herbert Pötzl
18666 + *
18667 + *  V0.01  basic structure
18668 + *  V0.02  hash/unhash and trace
18669 + *  V0.03  preemption fixes
18670 + *
18671 + */
18672 +
18673 +#include <linux/module.h>
18674 +#include <asm/uaccess.h>
18675 +
18676 +#include <linux/vserver/context.h>
18677 +#include <linux/vserver/debug.h>
18678 +#include <linux/vserver/debug_cmd.h>
18679 +#include <linux/vserver/history.h>
18680 +
18681 +
18682 +#ifdef CONFIG_VSERVER_HISTORY
18683 +#define VXH_SIZE       CONFIG_VSERVER_HISTORY_SIZE
18684 +#else
18685 +#define VXH_SIZE       64
18686 +#endif
18687 +
18688 +struct _vx_history {
18689 +       unsigned int counter;
18690 +
18691 +       struct _vx_hist_entry entry[VXH_SIZE + 1];
18692 +};
18693 +
18694 +
18695 +DEFINE_PER_CPU(struct _vx_history, vx_history_buffer);
18696 +
18697 +unsigned volatile int vxh_active = 1;
18698 +
18699 +static atomic_t sequence = ATOMIC_INIT(0);
18700 +
18701 +
18702 +/*     vxh_advance()
18703 +
18704 +       * requires disabled preemption                          */
18705 +
18706 +struct _vx_hist_entry *vxh_advance(void *loc)
18707 +{
18708 +       unsigned int cpu = smp_processor_id();
18709 +       struct _vx_history *hist = &per_cpu(vx_history_buffer, cpu);
18710 +       struct _vx_hist_entry *entry;
18711 +       unsigned int index;
18712 +
18713 +       index = vxh_active ? (hist->counter++ % VXH_SIZE) : VXH_SIZE;
18714 +       entry = &hist->entry[index];
18715 +
18716 +       entry->seq = atomic_inc_return(&sequence);
18717 +       entry->loc = loc;
18718 +       return entry;
18719 +}
18720 +
18721 +EXPORT_SYMBOL_GPL(vxh_advance);
18722 +
18723 +
18724 +#define VXH_LOC_FMTS   "(#%04x,*%d):%p"
18725 +
18726 +#define VXH_LOC_ARGS(e)        (e)->seq, cpu, (e)->loc
18727 +
18728 +
18729 +#define VXH_VXI_FMTS   "%p[#%d,%d.%d]"
18730 +
18731 +#define VXH_VXI_ARGS(e)        (e)->vxi.ptr,                           \
18732 +                       (e)->vxi.ptr ? (e)->vxi.xid : 0,        \
18733 +                       (e)->vxi.ptr ? (e)->vxi.usecnt : 0,     \
18734 +                       (e)->vxi.ptr ? (e)->vxi.tasks : 0
18735 +
18736 +void   vxh_dump_entry(struct _vx_hist_entry *e, unsigned cpu)
18737 +{
18738 +       switch (e->type) {
18739 +       case VXH_THROW_OOPS:
18740 +               printk( VXH_LOC_FMTS " oops \n", VXH_LOC_ARGS(e));
18741 +               break;
18742 +
18743 +       case VXH_GET_VX_INFO:
18744 +       case VXH_PUT_VX_INFO:
18745 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS "\n",
18746 +                       VXH_LOC_ARGS(e),
18747 +                       (e->type == VXH_GET_VX_INFO) ? "get" : "put",
18748 +                       VXH_VXI_ARGS(e));
18749 +               break;
18750 +
18751 +       case VXH_INIT_VX_INFO:
18752 +       case VXH_SET_VX_INFO:
18753 +       case VXH_CLR_VX_INFO:
18754 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS " @%p\n",
18755 +                       VXH_LOC_ARGS(e),
18756 +                       (e->type == VXH_INIT_VX_INFO) ? "init" :
18757 +                       ((e->type == VXH_SET_VX_INFO) ? "set" : "clr"),
18758 +                       VXH_VXI_ARGS(e), e->sc.data);
18759 +               break;
18760 +
18761 +       case VXH_CLAIM_VX_INFO:
18762 +       case VXH_RELEASE_VX_INFO:
18763 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS " @%p\n",
18764 +                       VXH_LOC_ARGS(e),
18765 +                       (e->type == VXH_CLAIM_VX_INFO) ? "claim" : "release",
18766 +                       VXH_VXI_ARGS(e), e->sc.data);
18767 +               break;
18768 +
18769 +       case VXH_ALLOC_VX_INFO:
18770 +       case VXH_DEALLOC_VX_INFO:
18771 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS "\n",
18772 +                       VXH_LOC_ARGS(e),
18773 +                       (e->type == VXH_ALLOC_VX_INFO) ? "alloc" : "dealloc",
18774 +                       VXH_VXI_ARGS(e));
18775 +               break;
18776 +
18777 +       case VXH_HASH_VX_INFO:
18778 +       case VXH_UNHASH_VX_INFO:
18779 +               printk( VXH_LOC_FMTS " __%s_vx_info " VXH_VXI_FMTS "\n",
18780 +                       VXH_LOC_ARGS(e),
18781 +                       (e->type == VXH_HASH_VX_INFO) ? "hash" : "unhash",
18782 +                       VXH_VXI_ARGS(e));
18783 +               break;
18784 +
18785 +       case VXH_LOC_VX_INFO:
18786 +       case VXH_LOOKUP_VX_INFO:
18787 +       case VXH_CREATE_VX_INFO:
18788 +               printk( VXH_LOC_FMTS " __%s_vx_info [#%d] -> " VXH_VXI_FMTS "\n",
18789 +                       VXH_LOC_ARGS(e),
18790 +                       (e->type == VXH_CREATE_VX_INFO) ? "create" :
18791 +                       ((e->type == VXH_LOC_VX_INFO) ? "loc" : "lookup"),
18792 +                       e->ll.arg, VXH_VXI_ARGS(e));
18793 +               break;
18794 +       }
18795 +}
18796 +
18797 +static void __vxh_dump_history(void)
18798 +{
18799 +       unsigned int i, cpu;
18800 +
18801 +       printk("History:\tSEQ: %8x\tNR_CPUS: %d\n",
18802 +               atomic_read(&sequence), NR_CPUS);
18803 +
18804 +       for (i = 0; i < VXH_SIZE; i++) {
18805 +               for_each_online_cpu(cpu) {
18806 +                       struct _vx_history *hist =
18807 +                               &per_cpu(vx_history_buffer, cpu);
18808 +                       unsigned int index = (hist->counter - i) % VXH_SIZE;
18809 +                       struct _vx_hist_entry *entry = &hist->entry[index];
18810 +
18811 +                       vxh_dump_entry(entry, cpu);
18812 +               }
18813 +       }
18814 +}
18815 +
18816 +void   vxh_dump_history(void)
18817 +{
18818 +       vxh_active = 0;
18819 +#ifdef CONFIG_SMP
18820 +       local_irq_enable();
18821 +       smp_send_stop();
18822 +       local_irq_disable();
18823 +#endif
18824 +       __vxh_dump_history();
18825 +}
18826 +
18827 +
18828 +/* vserver syscall commands below here */
18829 +
18830 +
18831 +int vc_dump_history(uint32_t id)
18832 +{
18833 +       vxh_active = 0;
18834 +       __vxh_dump_history();
18835 +       vxh_active = 1;
18836 +
18837 +       return 0;
18838 +}
18839 +
18840 +
18841 +int do_read_history(struct __user _vx_hist_entry *data,
18842 +       int cpu, uint32_t *index, uint32_t *count)
18843 +{
18844 +       int pos, ret = 0;
18845 +       struct _vx_history *hist = &per_cpu(vx_history_buffer, cpu);
18846 +       int end = hist->counter;
18847 +       int start = end - VXH_SIZE + 2;
18848 +       int idx = *index;
18849 +
18850 +       /* special case: get current pos */
18851 +       if (!*count) {
18852 +               *index = end;
18853 +               return 0;
18854 +       }
18855 +
18856 +       /* have we lost some data? */
18857 +       if (idx < start)
18858 +               idx = start;
18859 +
18860 +       for (pos = 0; (pos < *count) && (idx < end); pos++, idx++) {
18861 +               struct _vx_hist_entry *entry =
18862 +                       &hist->entry[idx % VXH_SIZE];
18863 +
18864 +               /* send entry to userspace */
18865 +               ret = copy_to_user(&data[pos], entry, sizeof(*entry));
18866 +               if (ret)
18867 +                       break;
18868 +       }
18869 +       /* save new index and count */
18870 +       *index = idx;
18871 +       *count = pos;
18872 +       return ret ? ret : (*index < end);
18873 +}
18874 +
18875 +int vc_read_history(uint32_t id, void __user *data)
18876 +{
18877 +       struct vcmd_read_history_v0 vc_data;
18878 +       int ret;
18879 +
18880 +       if (id >= NR_CPUS)
18881 +               return -EINVAL;
18882 +
18883 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18884 +               return -EFAULT;
18885 +
18886 +       ret = do_read_history((struct __user _vx_hist_entry *)vc_data.data,
18887 +               id, &vc_data.index, &vc_data.count);
18888 +
18889 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18890 +               return -EFAULT;
18891 +       return ret;
18892 +}
18893 +
18894 +#ifdef CONFIG_COMPAT
18895 +
18896 +int vc_read_history_x32(uint32_t id, void __user *data)
18897 +{
18898 +       struct vcmd_read_history_v0_x32 vc_data;
18899 +       int ret;
18900 +
18901 +       if (id >= NR_CPUS)
18902 +               return -EINVAL;
18903 +
18904 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18905 +               return -EFAULT;
18906 +
18907 +       ret = do_read_history((struct __user _vx_hist_entry *)
18908 +               compat_ptr(vc_data.data_ptr),
18909 +               id, &vc_data.index, &vc_data.count);
18910 +
18911 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18912 +               return -EFAULT;
18913 +       return ret;
18914 +}
18915 +
18916 +#endif /* CONFIG_COMPAT */
18917 +
18918 diff -NurpP --minimal linux-3.6.9/kernel/vserver/inet.c linux-3.6.9-vs2.3.4.4/kernel/vserver/inet.c
18919 --- linux-3.6.9/kernel/vserver/inet.c   1970-01-01 01:00:00.000000000 +0100
18920 +++ linux-3.6.9-vs2.3.4.4/kernel/vserver/inet.c 2012-10-04 18:47:00.000000000 +0200
18921 @@ -0,0 +1,226 @@
18922 +
18923 +#include <linux/in.h>
18924 +#include <linux/inetdevice.h>
18925 +#include <linux/export.h>
18926 +#include <linux/vs_inet.h>
18927 +#include <linux/vs_inet6.h>
18928 +#include <linux/vserver/debug.h>
18929 +#include <net/route.h>
18930 +#include <net/addrconf.h>
18931 +
18932 +
18933 +int nx_v4_addr_conflict(struct nx_info *nxi1, struct nx_info *nxi2)
18934 +{
18935 +       int ret = 0;
18936 +
18937 +       if (!nxi1 || !nxi2 || nxi1 == nxi2)
18938 +               ret = 1;
18939 +       else {
18940 +               struct nx_addr_v4 *ptr;
18941 +
18942 +               for (ptr = &nxi1->v4; ptr; ptr = ptr->next) {
18943 +                       if (v4_nx_addr_in_nx_info(nxi2, ptr, -1)) {
18944 +                               ret = 1;
18945 +                               break;
18946 +                       }
18947 +               }
18948 +       }
18949 +
18950 +       vxdprintk(VXD_CBIT(net, 2),
18951 +               "nx_v4_addr_conflict(%p,%p): %d",
18952 +               nxi1, nxi2, ret);
18953 +
18954 +       return ret;
18955 +}
18956 +
18957 +
18958 +#ifdef CONFIG_IPV6
18959 +
18960 +int nx_v6_addr_conflict(struct nx_info *nxi1, struct nx_info *nxi2)
18961 +{
18962 +       int ret = 0;
18963 +
18964 +       if (!nxi1 || !nxi2 || nxi1 == nxi2)
18965 +               ret = 1;
18966 +       else {
18967 +               struct nx_addr_v6 *ptr;
18968 +
18969 +               for (ptr = &nxi1->v6; ptr; ptr = ptr->next) {
18970 +                       if (v6_nx_addr_in_nx_info(nxi2, ptr, -1)) {
18971 +                               ret = 1;
18972 +                               break;
18973 +                       }
18974 +               }
18975 +       }
18976 +
18977 +       vxdprintk(VXD_CBIT(net, 2),
18978 +               "nx_v6_addr_conflict(%p,%p): %d",
18979 +               nxi1, nxi2, ret);
18980 +
18981 +       return ret;
18982 +}
18983 +
18984 +#endif
18985 +
18986 +int v4_dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
18987 +{
18988 +       struct in_device *in_dev;
18989 +       struct in_ifaddr **ifap;
18990 +       struct in_ifaddr *ifa;
18991 +       int ret = 0;
18992 +
18993 +       if (!dev)
18994 +               goto out;
18995 +       in_dev = in_dev_get(dev);
18996 +       if (!in_dev)
18997 +               goto out;
18998 +
18999 +       for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
19000 +               ifap = &ifa->ifa_next) {
19001 +               if (v4_addr_in_nx_info(nxi, ifa->ifa_local, NXA_MASK_SHOW)) {
19002 +                       ret = 1;
19003 +                       break;
19004 +               }
19005 +       }
19006 +       in_dev_put(in_dev);
19007 +out:
19008 +       return ret;
19009 +}
19010 +
19011 +
19012 +#ifdef CONFIG_IPV6
19013 +
19014 +int v6_dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
19015 +{
19016 +       struct inet6_dev *in_dev;
19017 +       struct inet6_ifaddr *ifa;
19018 +       int ret = 0;
19019 +
19020 +       if (!dev)
19021 +               goto out;
19022 +       in_dev = in6_dev_get(dev);
19023 +       if (!in_dev)
19024 +               goto out;
19025 +
19026 +       // for (ifap = &in_dev->addr_list; (ifa = *ifap) != NULL;
19027 +       list_for_each_entry(ifa, &in_dev->addr_list, if_list) {
19028 +               if (v6_addr_in_nx_info(nxi, &ifa->addr, -1)) {
19029 +                       ret = 1;
19030 +                       break;
19031 +               }
19032 +       }
19033 +       in6_dev_put(in_dev);
19034 +out:
19035 +       return ret;
19036 +}
19037 +
19038 +#endif
19039 +
19040 +int dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
19041 +{
19042 +       int ret = 1;
19043 +
19044 +       if (!nxi)
19045 +               goto out;
19046 +       if (nxi->v4.type && v4_dev_in_nx_info(dev, nxi))
19047 +               goto out;
19048 +#ifdef CONFIG_IPV6
19049 +       ret = 2;
19050 +       if (nxi->v6.type && v6_dev_in_nx_info(dev, nxi))
19051 +               goto out;
19052 +#endif
19053 +       ret = 0;
19054 +out:
19055 +       vxdprintk(VXD_CBIT(net, 3),
19056 +               "dev_in_nx_info(%p,%p[#%d]) = %d",
19057 +               dev, nxi, nxi ? nxi->nx_id : 0, ret);
19058 +       return ret;
19059 +}
19060 +
19061 +struct rtable *ip_v4_find_src(struct net *net, struct nx_info *nxi,
19062 +       struct flowi4 *fl4)
19063 +{
19064 +       struct rtable *rt;
19065 +
19066 +       if (!nxi)
19067 +               return NULL;
19068 +
19069 +       /* FIXME: handle lback only case */
19070 +       if (!NX_IPV4(nxi))
19071 +               return ERR_PTR(-EPERM);
19072 +
19073 +       vxdprintk(VXD_CBIT(net, 4),
19074 +               "ip_v4_find_src(%p[#%u]) " NIPQUAD_FMT " -> " NIPQUAD_FMT,
19075 +               nxi, nxi ? nxi->nx_id : 0,
19076 +               NIPQUAD(fl4->saddr), NIPQUAD(fl4->daddr));
19077 +
19078 +       /* single IP is unconditional */
19079 +       if (nx_info_flags(nxi, NXF_SINGLE_IP, 0) &&
19080 +               (fl4->saddr == INADDR_ANY))
19081 +               fl4->saddr = nxi->v4.ip[0].s_addr;
19082 +
19083 +       if (fl4->saddr == INADDR_ANY) {
19084 +               struct nx_addr_v4 *ptr;
19085 +               __be32 found = 0;
19086 +
19087 +               rt = __ip_route_output_key(net, fl4);
19088 +               if (!IS_ERR(rt)) {
19089 +                       found = fl4->saddr;
19090 +                       ip_rt_put(rt);
19091 +                       vxdprintk(VXD_CBIT(net, 4),
19092 +                               "ip_v4_find_src(%p[#%u]) rok[%u]: " NIPQUAD_FMT,
19093 +                               nxi, nxi ? nxi->nx_id : 0, fl4->flowi4_oif, NIPQUAD(found));
19094 +                       if (v4_addr_in_nx_info(nxi, found, NXA_MASK_BIND))
19095 +                               goto found;
19096 +               }
19097 +
19098 +               for (ptr = &nxi->v4; ptr; ptr = ptr->next) {
19099 +                       __be32 primary = ptr->ip[0].s_addr;
19100 +                       __be32 mask = ptr->mask.s_addr;
19101 +                       __be32 neta = primary & mask;
19102 +
19103 +                       vxdprintk(VXD_CBIT(net, 4), "ip_v4_find_src(%p[#%u]) chk: "
19104 +                               NIPQUAD_FMT "/" NIPQUAD_FMT "/" NIPQUAD_FMT,
19105 +                               nxi, nxi ? nxi->nx_id : 0, NIPQUAD(primary),
19106 +                               NIPQUAD(mask), NIPQUAD(neta));
19107 +                       if ((found & mask) != neta)
19108 +                               continue;
19109 +
19110 +                       fl4->saddr = primary;
19111 +                       rt = __ip_route_output_key(net, fl4);
19112 +                       vxdprintk(VXD_CBIT(net, 4),
19113 +                               "ip_v4_find_src(%p[#%u]) rok[%u]: " NIPQUAD_FMT,
19114 +                               nxi, nxi ? nxi->nx_id : 0, fl4->flowi4_oif, NIPQUAD(primary));
19115 +                       if (!IS_ERR(rt)) {
19116 +                               found = fl4->saddr;
19117 +                               ip_rt_put(rt);
19118 +                               if (found == primary)
19119 +                                       goto found;
19120 +                       }
19121 +               }
19122 +               /* still no source ip? */
19123 +               found = ipv4_is_loopback(fl4->daddr)
19124 +                       ? IPI_LOOPBACK : nxi->v4.ip[0].s_addr;
19125 +       found:
19126 +               /* assign src ip to flow */
19127 +               fl4->saddr = found;
19128 +
19129 +       } else {
19130 +               if (!v4_addr_in_nx_info(nxi, fl4->saddr, NXA_MASK_BIND))
19131 +                       return ERR_PTR(-EPERM);
19132 +       }
19133 +
19134 +       if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0)) {
19135 +               if (ipv4_is_loopback(fl4->daddr))
19136 +                       fl4->daddr = nxi->v4_lback.s_addr;
19137 +               if (ipv4_is_loopback(fl4->saddr))
19138 +                       fl4->saddr = nxi->v4_lback.s_addr;
19139 +       } else if (ipv4_is_loopback(fl4->daddr) &&
19140 +               !nx_info_flags(nxi, NXF_LBACK_ALLOW, 0))
19141 +               return ERR_PTR(-EPERM);
19142 +
19143 +       return NULL;
19144 +}
19145 +
19146 +EXPORT_SYMBOL_GPL(ip_v4_find_src);
19147 +
19148 diff -NurpP --minimal linux-3.6.9/kernel/vserver/init.c linux-3.6.9-vs2.3.4.4/kernel/vserver/init.c
19149 --- linux-3.6.9/kernel/vserver/init.c   1970-01-01 01:00:00.000000000 +0100
19150 +++ linux-3.6.9-vs2.3.4.4/kernel/vserver/init.c 2012-10-04 18:47:00.000000000 +0200
19151 @@ -0,0 +1,45 @@
19152 +/*
19153 + *  linux/kernel/init.c
19154 + *
19155 + *  Virtual Server Init
19156 + *
19157 + *  Copyright (C) 2004-2007  Herbert Pötzl
19158 + *
19159 + *  V0.01  basic structure
19160 + *
19161 + */
19162 +
19163 +#include <linux/init.h>
19164 +
19165 +int    vserver_register_sysctl(void);
19166 +void   vserver_unregister_sysctl(void);
19167 +
19168 +
19169 +static int __init init_vserver(void)
19170 +{
19171 +       int ret = 0;
19172 +
19173 +#ifdef CONFIG_VSERVER_DEBUG
19174 +       vserver_register_sysctl();
19175 +#endif
19176 +       return ret;
19177 +}
19178 +
19179 +
19180 +static void __exit exit_vserver(void)
19181 +{
19182 +
19183 +#ifdef CONFIG_VSERVER_DEBUG
19184 +       vserver_unregister_sysctl();
19185 +#endif
19186 +       return;
19187 +}
19188 +
19189 +/* FIXME: GFP_ZONETYPES gone
19190 +long vx_slab[GFP_ZONETYPES]; */
19191 +long vx_area;
19192 +
19193 +
19194 +module_init(init_vserver);
19195 +module_exit(exit_vserver);
19196 +
19197 diff -NurpP --minimal linux-3.6.9/kernel/vserver/inode.c linux-3.6.9-vs2.3.4.4/kernel/vserver/inode.c
19198 --- linux-3.6.9/kernel/vserver/inode.c  1970-01-01 01:00:00.000000000 +0100
19199 +++ linux-3.6.9-vs2.3.4.4/kernel/vserver/inode.c        2012-10-04 18:47:00.000000000 +0200
19200 @@ -0,0 +1,437 @@
19201 +/*
19202 + *  linux/kernel/vserver/inode.c
19203 + *
19204 + *  Virtual Server: File System Support
19205 + *
19206 + *  Copyright (C) 2004-2007  Herbert Pötzl
19207 + *
19208 + *  V0.01  separated from vcontext V0.05
19209 + *  V0.02  moved to tag (instead of xid)
19210 + *
19211 + */
19212 +
19213 +#include <linux/tty.h>
19214 +#include <linux/proc_fs.h>
19215 +#include <linux/devpts_fs.h>
19216 +#include <linux/fs.h>
19217 +#include <linux/file.h>
19218 +#include <linux/mount.h>
19219 +#include <linux/parser.h>
19220 +#include <linux/namei.h>
19221 +#include <linux/vserver/inode.h>
19222 +#include <linux/vserver/inode_cmd.h>
19223 +#include <linux/vs_base.h>
19224 +#include <linux/vs_tag.h>
19225 +
19226 +#include <asm/uaccess.h>
19227 +
19228 +
19229 +static int __vc_get_iattr(struct inode *in, uint32_t *tag, uint32_t *flags, uint32_t *mask)
19230 +{
19231 +       struct proc_dir_entry *entry;
19232 +
19233 +       if (!in || !in->i_sb)
19234 +               return -ESRCH;
19235 +
19236 +       *flags = IATTR_TAG
19237 +               | (IS_IMMUTABLE(in) ? IATTR_IMMUTABLE : 0)
19238 +               | (IS_IXUNLINK(in) ? IATTR_IXUNLINK : 0)
19239 +               | (IS_BARRIER(in) ? IATTR_BARRIER : 0)
19240 +               | (IS_COW(in) ? IATTR_COW : 0);
19241 +       *mask = IATTR_IXUNLINK | IATTR_IMMUTABLE | IATTR_COW;
19242 +
19243 +       if (S_ISDIR(in->i_mode))
19244 +               *mask |= IATTR_BARRIER;
19245 +
19246 +       if (IS_TAGGED(in)) {
19247 +               *tag = in->i_tag;
19248 +               *mask |= IATTR_TAG;
19249 +       }
19250 +
19251 +       switch (in->i_sb->s_magic) {
19252 +       case PROC_SUPER_MAGIC:
19253 +               entry = PROC_I(in)->pde;
19254 +
19255 +               /* check for specific inodes? */
19256 +               if (entry)
19257 +                       *mask |= IATTR_FLAGS;
19258 +               if (entry)
19259 +                       *flags |= (entry->vx_flags & IATTR_FLAGS);
19260 +               else
19261 +                       *flags |= (PROC_I(in)->vx_flags & IATTR_FLAGS);
19262 +               break;
19263 +
19264 +       case DEVPTS_SUPER_MAGIC:
19265 +               *tag = in->i_tag;
19266 +               *mask |= IATTR_TAG;
19267 +               break;
19268 +
19269 +       default:
19270 +               break;
19271 +       }
19272 +       return 0;
19273 +}
19274 +
19275 +int vc_get_iattr(void __user *data)
19276 +{
19277 +       struct path path;
19278 +       struct vcmd_ctx_iattr_v1 vc_data = { .tag = -1 };
19279 +       int ret;
19280 +
19281 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19282 +               return -EFAULT;
19283 +
19284 +       ret = user_lpath(vc_data.name, &path);
19285 +       if (!ret) {
19286 +               ret = __vc_get_iattr(path.dentry->d_inode,
19287 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
19288 +               path_put(&path);
19289 +       }
19290 +       if (ret)
19291 +               return ret;
19292 +
19293 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19294 +               ret = -EFAULT;
19295 +       return ret;
19296 +}
19297 +
19298 +#ifdef CONFIG_COMPAT
19299 +
19300 +int vc_get_iattr_x32(void __user *data)
19301 +{
19302 +       struct path path;
19303 +       struct vcmd_ctx_iattr_v1_x32 vc_data = { .tag = -1 };
19304 +       int ret;
19305 +
19306 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19307 +               return -EFAULT;
19308 +
19309 +       ret = user_lpath(compat_ptr(vc_data.name_ptr), &path);
19310 +       if (!ret) {
19311 +               ret = __vc_get_iattr(path.dentry->d_inode,
19312 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
19313 +               path_put(&path);
19314 +       }
19315 +       if (ret)
19316 +               return ret;
19317 +
19318 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19319 +               ret = -EFAULT;
19320 +       return ret;
19321 +}
19322 +
19323 +#endif /* CONFIG_COMPAT */
19324 +
19325 +
19326 +int vc_fget_iattr(uint32_t fd, void __user *data)
19327 +{
19328 +       struct file *filp;
19329 +       struct vcmd_ctx_fiattr_v0 vc_data = { .tag = -1 };
19330 +       int ret;
19331 +
19332 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19333 +               return -EFAULT;
19334 +
19335 +       filp = fget(fd);
19336 +       if (!filp || !filp->f_dentry || !filp->f_dentry->d_inode)
19337 +               return -EBADF;
19338 +
19339 +       ret = __vc_get_iattr(filp->f_dentry->d_inode,
19340 +               &vc_data.tag, &vc_data.flags, &vc_data.mask);
19341 +
19342 +       fput(filp);
19343 +
19344 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19345 +               ret = -EFAULT;
19346 +       return ret;
19347 +}
19348 +
19349 +
19350 +static int __vc_set_iattr(struct dentry *de, uint32_t *tag, uint32_t *flags, uint32_t *mask)
19351 +{
19352 +       struct inode *in = de->d_inode;
19353 +       int error = 0, is_proc = 0, has_tag = 0;
19354 +       struct iattr attr = { 0 };
19355 +
19356 +       if (!in || !in->i_sb)
19357 +               return -ESRCH;
19358 +
19359 +       is_proc = (in->i_sb->s_magic == PROC_SUPER_MAGIC);
19360 +       if ((*mask & IATTR_FLAGS) && !is_proc)
19361 +               return -EINVAL;
19362 +
19363 +       has_tag = IS_TAGGED(in) ||
19364 +               (in->i_sb->s_magic == DEVPTS_SUPER_MAGIC);
19365 +       if ((*mask & IATTR_TAG) && !has_tag)
19366 +               return -EINVAL;
19367 +
19368 +       mutex_lock(&in->i_mutex);
19369 +       if (*mask & IATTR_TAG) {
19370 +               attr.ia_tag = *tag;
19371 +               attr.ia_valid |= ATTR_TAG;
19372 +       }
19373 +
19374 +       if (*mask & IATTR_FLAGS) {
19375 +               struct proc_dir_entry *entry = PROC_I(in)->pde;
19376 +               unsigned int iflags = PROC_I(in)->vx_flags;
19377 +
19378 +               iflags = (iflags & ~(*mask & IATTR_FLAGS))
19379 +                       | (*flags & IATTR_FLAGS);
19380 +               PROC_I(in)->vx_flags = iflags;
19381 +               if (entry)
19382 +                       entry->vx_flags = iflags;
19383 +       }
19384 +
19385 +       if (*mask & (IATTR_IMMUTABLE | IATTR_IXUNLINK |
19386 +               IATTR_BARRIER | IATTR_COW)) {
19387 +               int iflags = in->i_flags;
19388 +               int vflags = in->i_vflags;
19389 +
19390 +               if (*mask & IATTR_IMMUTABLE) {
19391 +                       if (*flags & IATTR_IMMUTABLE)
19392 +                               iflags |= S_IMMUTABLE;
19393 +                       else
19394 +                               iflags &= ~S_IMMUTABLE;
19395 +               }
19396 +               if (*mask & IATTR_IXUNLINK) {
19397 +                       if (*flags & IATTR_IXUNLINK)
19398 +                               iflags |= S_IXUNLINK;
19399 +                       else
19400 +                               iflags &= ~S_IXUNLINK;
19401 +               }
19402 +               if (S_ISDIR(in->i_mode) && (*mask & IATTR_BARRIER)) {
19403 +                       if (*flags & IATTR_BARRIER)
19404 +                               vflags |= V_BARRIER;
19405 +                       else
19406 +                               vflags &= ~V_BARRIER;
19407 +               }
19408 +               if (S_ISREG(in->i_mode) && (*mask & IATTR_COW)) {
19409 +                       if (*flags & IATTR_COW)
19410 +                               vflags |= V_COW;
19411 +                       else
19412 +                               vflags &= ~V_COW;
19413 +               }
19414 +               if (in->i_op && in->i_op->sync_flags) {
19415 +                       error = in->i_op->sync_flags(in, iflags, vflags);
19416 +                       if (error)
19417 +                               goto out;
19418 +               }
19419 +       }
19420 +
19421 +       if (attr.ia_valid) {
19422 +               if (in->i_op && in->i_op->setattr)
19423 +                       error = in->i_op->setattr(de, &attr);
19424 +               else {
19425 +                       error = inode_change_ok(in, &attr);
19426 +                       if (!error) {
19427 +                               setattr_copy(in, &attr);
19428 +                               mark_inode_dirty(in);
19429 +                       }
19430 +               }
19431 +       }
19432 +
19433 +out:
19434 +       mutex_unlock(&in->i_mutex);
19435 +       return error;
19436 +}
19437 +
19438 +int vc_set_iattr(void __user *data)
19439 +{
19440 +       struct path path;
19441 +       struct vcmd_ctx_iattr_v1 vc_data;
19442 +       int ret;
19443 +
19444 +       if (!capable(CAP_LINUX_IMMUTABLE))
19445 +               return -EPERM;
19446 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19447 +               return -EFAULT;
19448 +
19449 +       ret = user_lpath(vc_data.name, &path);
19450 +       if (!ret) {
19451 +               ret = __vc_set_iattr(path.dentry,
19452 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
19453 +               path_put(&path);
19454 +       }
19455 +
19456 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19457 +               ret = -EFAULT;
19458 +       return ret;
19459 +}
19460 +
19461 +#ifdef CONFIG_COMPAT
19462 +
19463 +int vc_set_iattr_x32(void __user *data)
19464 +{
19465 +       struct path path;
19466 +       struct vcmd_ctx_iattr_v1_x32 vc_data;
19467 +       int ret;
19468 +
19469 +       if (!capable(CAP_LINUX_IMMUTABLE))
19470 +               return -EPERM;
19471 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19472 +               return -EFAULT;
19473 +
19474 +       ret = user_lpath(compat_ptr(vc_data.name_ptr), &path);
19475 +       if (!ret) {
19476 +               ret = __vc_set_iattr(path.dentry,
19477 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
19478 +               path_put(&path);
19479 +       }
19480 +
19481 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19482 +               ret = -EFAULT;
19483 +       return ret;
19484 +}
19485 +
19486 +#endif /* CONFIG_COMPAT */
19487 +
19488 +int vc_fset_iattr(uint32_t fd, void __user *data)
19489 +{
19490 +       struct file *filp;
19491 +       struct vcmd_ctx_fiattr_v0 vc_data;
19492 +       int ret;
19493 +
19494 +       if (!capable(CAP_LINUX_IMMUTABLE))
19495 +               return -EPERM;
19496 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19497 +               return -EFAULT;
19498 +
19499 +       filp = fget(fd);
19500 +       if (!filp || !filp->f_dentry || !filp->f_dentry->d_inode)
19501 +               return -EBADF;
19502 +
19503 +       ret = __vc_set_iattr(filp->f_dentry, &vc_data.tag,
19504 +               &vc_data.flags, &vc_data.mask);
19505 +
19506 +       fput(filp);
19507 +
19508 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19509 +               return -EFAULT;
19510 +       return ret;
19511 +}
19512 +
19513 +
19514 +enum { Opt_notagcheck, Opt_tag, Opt_notag, Opt_tagid, Opt_err };
19515 +
19516 +static match_table_t tokens = {
19517 +       {Opt_notagcheck, "notagcheck"},
19518 +#ifdef CONFIG_PROPAGATE
19519 +       {Opt_notag, "notag"},
19520 +       {Opt_tag, "tag"},
19521 +       {Opt_tagid, "tagid=%u"},
19522 +#endif
19523 +       {Opt_err, NULL}
19524 +};
19525 +
19526 +
19527 +static void __dx_parse_remove(char *string, char *opt)
19528 +{
19529 +       char *p = strstr(string, opt);
19530 +       char *q = p;
19531 +
19532 +       if (p) {
19533 +               while (*q != '\0' && *q != ',')
19534 +                       q++;
19535 +               while (*q)
19536 +                       *p++ = *q++;
19537 +               while (*p)
19538 +                       *p++ = '\0';
19539 +       }
19540 +}
19541 +
19542 +int dx_parse_tag(char *string, vs_tag_t *tag, int remove, int *mnt_flags,
19543 +                unsigned long *flags)
19544 +{
19545 +       int set = 0;
19546 +       substring_t args[MAX_OPT_ARGS];
19547 +       int token;
19548 +       char *s, *p, *opts;
19549 +#if defined(CONFIG_PROPAGATE) || defined(CONFIG_VSERVER_DEBUG)
19550 +       int option = 0;
19551 +#endif
19552 +
19553 +       if (!string)
19554 +               return 0;
19555 +       s = kstrdup(string, GFP_KERNEL | GFP_ATOMIC);
19556 +       if (!s)
19557 +               return 0;
19558 +
19559 +       opts = s;
19560 +       while ((p = strsep(&opts, ",")) != NULL) {
19561 +               token = match_token(p, tokens, args);
19562 +
19563 +               switch (token) {
19564 +#ifdef CONFIG_PROPAGATE
19565 +               case Opt_tag:
19566 +                       if (tag)
19567 +                               *tag = 0;
19568 +                       if (remove)
19569 +                               __dx_parse_remove(s, "tag");
19570 +                       *mnt_flags |= MNT_TAGID;
19571 +                       set |= MNT_TAGID;
19572 +                       break;
19573 +               case Opt_notag:
19574 +                       if (remove)
19575 +                               __dx_parse_remove(s, "notag");
19576 +                       *mnt_flags |= MNT_NOTAG;
19577 +                       set |= MNT_NOTAG;
19578 +                       break;
19579 +               case Opt_tagid:
19580 +                       if (tag && !match_int(args, &option))
19581 +                               *tag = option;
19582 +                       if (remove)
19583 +                               __dx_parse_remove(s, "tagid");
19584 +                       *mnt_flags |= MNT_TAGID;
19585 +                       set |= MNT_TAGID;
19586 +                       break;
19587 +#endif /* CONFIG_PROPAGATE */
19588 +               case Opt_notagcheck:
19589 +                       if (remove)
19590 +                               __dx_parse_remove(s, "notagcheck");
19591 +                       *flags |= MS_NOTAGCHECK;
19592 +                       set |= MS_NOTAGCHECK;
19593 +                       break;
19594 +               }
19595 +               vxdprintk(VXD_CBIT(tag, 7),
19596 +                       "dx_parse_tag(" VS_Q("%s") "): %d:#%d",
19597 +                       p, token, option);
19598 +       }
19599 +       if (set)
19600 +               strcpy(string, s);
19601 +       kfree(s);
19602 +       return set;
19603 +}
19604 +
19605 +#ifdef CONFIG_PROPAGATE
19606 +
19607 +void __dx_propagate_tag(struct nameidata *nd, struct inode *inode)
19608 +{
19609 +       vs_tag_t new_tag = 0;
19610 +       struct vfsmount *mnt;
19611 +       int propagate;
19612 +
19613 +       if (!nd)
19614 +               return;
19615 +       mnt = nd->path.mnt;
19616 +       if (!mnt)
19617 +               return;
19618 +
19619 +       propagate = (mnt->mnt_flags & MNT_TAGID);
19620 +       if (propagate)
19621 +               new_tag = mnt->mnt_tag;
19622 +
19623 +       vxdprintk(VXD_CBIT(tag, 7),
19624 +               "dx_propagate_tag(%p[#%lu.%d]): %d,%d",
19625 +               inode, inode->i_ino, inode->i_tag,
19626 +               new_tag, (propagate) ? 1 : 0);
19627 +
19628 +       if (propagate)
19629 +               inode->i_tag = new_tag;
19630 +}
19631 +
19632 +#include <linux/module.h>
19633 +
19634 +EXPORT_SYMBOL_GPL(__dx_propagate_tag);
19635 +
19636 +#endif /* CONFIG_PROPAGATE */
19637 +
19638 diff -NurpP --minimal linux-3.6.9/kernel/vserver/limit.c linux-3.6.9-vs2.3.4.4/kernel/vserver/limit.c
19639 --- linux-3.6.9/kernel/vserver/limit.c  1970-01-01 01:00:00.000000000 +0100
19640 +++ linux-3.6.9-vs2.3.4.4/kernel/vserver/limit.c        2012-10-04 18:47:00.000000000 +0200
19641 @@ -0,0 +1,345 @@
19642 +/*
19643 + *  linux/kernel/vserver/limit.c
19644 + *
19645 + *  Virtual Server: Context Limits
19646 + *
19647 + *  Copyright (C) 2004-2010  Herbert Pötzl
19648 + *
19649 + *  V0.01  broken out from vcontext V0.05
19650 + *  V0.02  changed vcmds to vxi arg
19651 + *  V0.03  added memory cgroup support
19652 + *
19653 + */
19654 +
19655 +#include <linux/sched.h>
19656 +#include <linux/module.h>
19657 +#include <linux/memcontrol.h>
19658 +#include <linux/res_counter.h>
19659 +#include <linux/vs_limit.h>
19660 +#include <linux/vserver/limit.h>
19661 +#include <linux/vserver/limit_cmd.h>
19662 +
19663 +#include <asm/uaccess.h>
19664 +
19665 +
19666 +const char *vlimit_name[NUM_LIMITS] = {
19667 +       [RLIMIT_CPU]            = "CPU",
19668 +       [RLIMIT_NPROC]          = "NPROC",
19669 +       [RLIMIT_NOFILE]         = "NOFILE",
19670 +       [RLIMIT_LOCKS]          = "LOCKS",
19671 +       [RLIMIT_SIGPENDING]     = "SIGP",
19672 +       [RLIMIT_MSGQUEUE]       = "MSGQ",
19673 +
19674 +       [VLIMIT_NSOCK]          = "NSOCK",
19675 +       [VLIMIT_OPENFD]         = "OPENFD",
19676 +       [VLIMIT_SHMEM]          = "SHMEM",
19677 +       [VLIMIT_DENTRY]         = "DENTRY",
19678 +};
19679 +
19680 +EXPORT_SYMBOL_GPL(vlimit_name);
19681 +
19682 +#define MASK_ENTRY(x)  (1 << (x))
19683 +
19684 +const struct vcmd_ctx_rlimit_mask_v0 vlimit_mask = {
19685 +               /* minimum */
19686 +       0
19687 +       ,       /* softlimit */
19688 +       0
19689 +       ,       /* maximum */
19690 +       MASK_ENTRY( RLIMIT_NPROC        ) |
19691 +       MASK_ENTRY( RLIMIT_NOFILE       ) |
19692 +       MASK_ENTRY( RLIMIT_LOCKS        ) |
19693 +       MASK_ENTRY( RLIMIT_MSGQUEUE     ) |
19694 +
19695 +       MASK_ENTRY( VLIMIT_NSOCK        ) |
19696 +       MASK_ENTRY( VLIMIT_OPENFD       ) |
19697 +       MASK_ENTRY( VLIMIT_SHMEM        ) |
19698 +       MASK_ENTRY( VLIMIT_DENTRY       ) |
19699 +       0
19700 +};
19701 +               /* accounting only */
19702 +uint32_t account_mask =
19703 +       MASK_ENTRY( VLIMIT_SEMARY       ) |
19704 +       MASK_ENTRY( VLIMIT_NSEMS        ) |
19705 +       MASK_ENTRY( VLIMIT_MAPPED       ) |
19706 +       0;
19707 +
19708 +
19709 +static int is_valid_vlimit(int id)
19710 +{
19711 +       uint32_t mask = vlimit_mask.minimum |
19712 +               vlimit_mask.softlimit | vlimit_mask.maximum;
19713 +       return mask & (1 << id);
19714 +}
19715 +
19716 +static int is_accounted_vlimit(int id)
19717 +{
19718 +       if (is_valid_vlimit(id))
19719 +               return 1;
19720 +       return account_mask & (1 << id);
19721 +}
19722 +
19723 +
19724 +static inline uint64_t vc_get_soft(struct vx_info *vxi, int id)
19725 +{
19726 +       rlim_t limit = __rlim_soft(&vxi->limit, id);
19727 +       return VX_VLIM(limit);
19728 +}
19729 +
19730 +static inline uint64_t vc_get_hard(struct vx_info *vxi, int id)
19731 +{
19732 +       rlim_t limit = __rlim_hard(&vxi->limit, id);
19733 +       return VX_VLIM(limit);
19734 +}
19735 +
19736 +static int do_get_rlimit(struct vx_info *vxi, uint32_t id,
19737 +       uint64_t *minimum, uint64_t *softlimit, uint64_t *maximum)
19738 +{
19739 +       if (!is_valid_vlimit(id))
19740 +               return -EINVAL;
19741 +
19742 +       if (minimum)
19743 +               *minimum = CRLIM_UNSET;
19744 +       if (softlimit)
19745 +               *softlimit = vc_get_soft(vxi, id);
19746 +       if (maximum)
19747 +               *maximum = vc_get_hard(vxi, id);
19748 +       return 0;
19749 +}
19750 +
19751 +int vc_get_rlimit(struct vx_info *vxi, void __user *data)
19752 +{
19753 +       struct vcmd_ctx_rlimit_v0 vc_data;
19754 +       int ret;
19755 +
19756 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19757 +               return -EFAULT;
19758 +
19759 +       ret = do_get_rlimit(vxi, vc_data.id,
19760 +               &vc_data.minimum, &vc_data.softlimit, &vc_data.maximum);
19761 +       if (ret)
19762 +               return ret;
19763 +
19764 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19765 +               return -EFAULT;
19766 +       return 0;
19767 +}
19768 +
19769 +static int do_set_rlimit(struct vx_info *vxi, uint32_t id,
19770 +       uint64_t minimum, uint64_t softlimit, uint64_t maximum)
19771 +{
19772 +       if (!is_valid_vlimit(id))
19773 +               return -EINVAL;
19774 +
19775 +       if (maximum != CRLIM_KEEP)
19776 +               __rlim_hard(&vxi->limit, id) = VX_RLIM(maximum);
19777 +       if (softlimit != CRLIM_KEEP)
19778 +               __rlim_soft(&vxi->limit, id) = VX_RLIM(softlimit);
19779 +
19780 +       /* clamp soft limit */
19781 +       if (__rlim_soft(&vxi->limit, id) > __rlim_hard(&vxi->limit, id))
19782 +               __rlim_soft(&vxi->limit, id) = __rlim_hard(&vxi->limit, id);
19783 +
19784 +       return 0;
19785 +}
19786 +
19787 +int vc_set_rlimit(struct vx_info *vxi, void __user *data)
19788 +{
19789 +       struct vcmd_ctx_rlimit_v0 vc_data;
19790 +
19791 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19792 +               return -EFAULT;
19793 +
19794 +       return do_set_rlimit(vxi, vc_data.id,
19795 +               vc_data.minimum, vc_data.softlimit, vc_data.maximum);
19796 +}
19797 +
19798 +#ifdef CONFIG_IA32_EMULATION
19799 +
19800 +int vc_set_rlimit_x32(struct vx_info *vxi, void __user *data)
19801 +{
19802 +       struct vcmd_ctx_rlimit_v0_x32 vc_data;
19803 +
19804 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19805 +               return -EFAULT;
19806 +
19807 +       return do_set_rlimit(vxi, vc_data.id,
19808 +               vc_data.minimum, vc_data.softlimit, vc_data.maximum);
19809 +}
19810 +
19811 +int vc_get_rlimit_x32(struct vx_info *vxi, void __user *data)
19812 +{
19813 +       struct vcmd_ctx_rlimit_v0_x32 vc_data;
19814 +       int ret;
19815 +
19816 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19817 +               return -EFAULT;
19818 +
19819 +       ret = do_get_rlimit(vxi, vc_data.id,
19820 +               &vc_data.minimum, &vc_data.softlimit, &vc_data.maximum);
19821 +       if (ret)
19822 +               return ret;
19823 +
19824 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19825 +               return -EFAULT;
19826 +       return 0;
19827 +}
19828 +
19829 +#endif /* CONFIG_IA32_EMULATION */
19830 +
19831 +
19832 +int vc_get_rlimit_mask(uint32_t id, void __user *data)
19833 +{
19834 +       if (copy_to_user(data, &vlimit_mask, sizeof(vlimit_mask)))
19835 +               return -EFAULT;
19836 +       return 0;
19837 +}
19838 +
19839 +
19840 +static inline void vx_reset_hits(struct _vx_limit *limit)
19841 +{
19842 +       int lim;
19843 +
19844 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
19845 +               atomic_set(&__rlim_lhit(limit, lim), 0);
19846 +       }
19847 +}
19848 +
19849 +int vc_reset_hits(struct vx_info *vxi, void __user *data)
19850 +{
19851 +       vx_reset_hits(&vxi->limit);
19852 +       return 0;
19853 +}
19854 +
19855 +static inline void vx_reset_minmax(struct _vx_limit *limit)
19856 +{
19857 +       rlim_t value;
19858 +       int lim;
19859 +
19860 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
19861 +               value = __rlim_get(limit, lim);
19862 +               __rlim_rmax(limit, lim) = value;
19863 +               __rlim_rmin(limit, lim) = value;
19864 +       }
19865 +}
19866 +
19867 +int vc_reset_minmax(struct vx_info *vxi, void __user *data)
19868 +{
19869 +       vx_reset_minmax(&vxi->limit);
19870 +       return 0;
19871 +}
19872 +
19873 +
19874 +int vc_rlimit_stat(struct vx_info *vxi, void __user *data)
19875 +{
19876 +       struct vcmd_rlimit_stat_v0 vc_data;
19877 +       struct _vx_limit *limit = &vxi->limit;
19878 +       int id;
19879 +
19880 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19881 +               return -EFAULT;
19882 +
19883 +       id = vc_data.id;
19884 +       if (!is_accounted_vlimit(id))
19885 +               return -EINVAL;
19886 +
19887 +       vx_limit_fixup(limit, id);
19888 +       vc_data.hits = atomic_read(&__rlim_lhit(limit, id));
19889 +       vc_data.value = __rlim_get(limit, id);
19890 +       vc_data.minimum = __rlim_rmin(limit, id);
19891 +       vc_data.maximum = __rlim_rmax(limit, id);
19892 +
19893 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19894 +               return -EFAULT;
19895 +       return 0;
19896 +}
19897 +
19898 +
19899 +void vx_vsi_meminfo(struct sysinfo *val)
19900 +{
19901 +#ifdef CONFIG_CGROUP_MEM_RES_CTLR
19902 +       struct mem_cgroup *mcg;
19903 +       u64 res_limit, res_usage;
19904 +
19905 +       rcu_read_lock();
19906 +       mcg = mem_cgroup_from_task(current);
19907 +       rcu_read_unlock();
19908 +       if (!mcg)
19909 +               goto out;
19910 +
19911 +       res_limit = mem_cgroup_res_read_u64(mcg, RES_LIMIT);
19912 +       res_usage = mem_cgroup_res_read_u64(mcg, RES_USAGE);
19913 +
19914 +       if (res_limit != RESOURCE_MAX)
19915 +               val->totalram = (res_limit >> PAGE_SHIFT);
19916 +       val->freeram = val->totalram - (res_usage >> PAGE_SHIFT);
19917 +       val->bufferram = 0;
19918 +       val->totalhigh = 0;
19919 +       val->freehigh = 0;
19920 +out:
19921 +#endif /* CONFIG_CGROUP_MEM_RES_CTLR */
19922 +       return;
19923 +}
19924 +
19925 +void vx_vsi_swapinfo(struct sysinfo *val)
19926 +{
19927 +#ifdef CONFIG_CGROUP_MEM_RES_CTLR
19928 +#ifdef CONFIG_CGROUP_MEM_RES_CTLR_SWAP
19929 +       struct mem_cgroup *mcg;
19930 +       u64 res_limit, res_usage, memsw_limit, memsw_usage;
19931 +       s64 swap_limit, swap_usage;
19932 +
19933 +       rcu_read_lock();
19934 +       mcg = mem_cgroup_from_task(current);
19935 +       rcu_read_unlock();
19936 +       if (!mcg)
19937 +               goto out;
19938 +
19939 +       res_limit = mem_cgroup_res_read_u64(mcg, RES_LIMIT);
19940 +       res_usage = mem_cgroup_res_read_u64(mcg, RES_USAGE);
19941 +       memsw_limit = mem_cgroup_memsw_read_u64(mcg, RES_LIMIT);
19942 +       memsw_usage = mem_cgroup_memsw_read_u64(mcg, RES_USAGE);
19943 +
19944 +       /* memory unlimited */
19945 +       if (res_limit == RESOURCE_MAX)
19946 +               goto out;
19947 +
19948 +       swap_limit = memsw_limit - res_limit;
19949 +       /* we have a swap limit? */
19950 +       if (memsw_limit != RESOURCE_MAX)
19951 +               val->totalswap = swap_limit >> PAGE_SHIFT;
19952 +
19953 +       /* calculate swap part */
19954 +       swap_usage = (memsw_usage > res_usage) ?
19955 +               memsw_usage - res_usage : 0;
19956 +
19957 +       /* total shown minus usage gives free swap */
19958 +       val->freeswap = (swap_usage < swap_limit) ?
19959 +               val->totalswap - (swap_usage >> PAGE_SHIFT) : 0;
19960 +out:
19961 +#else  /* !CONFIG_CGROUP_MEM_RES_CTLR_SWAP */
19962 +       val->totalswap = 0;
19963 +       val->freeswap = 0;
19964 +#endif /* !CONFIG_CGROUP_MEM_RES_CTLR_SWAP */
19965 +#endif /* CONFIG_CGROUP_MEM_RES_CTLR */
19966 +       return;
19967 +}
19968 +
19969 +long vx_vsi_cached(struct sysinfo *val)
19970 +{
19971 +       long cache = 0;
19972 +#ifdef CONFIG_CGROUP_MEM_RES_CTLR
19973 +       struct mem_cgroup *mcg;
19974 +
19975 +       rcu_read_lock();
19976 +       mcg = mem_cgroup_from_task(current);
19977 +       rcu_read_unlock();
19978 +       if (!mcg)
19979 +               goto out;
19980 +
19981 +       cache = mem_cgroup_stat_read_cache(mcg);
19982 +out:
19983 +#endif
19984 +       return cache;
19985 +}
19986 +
19987 diff -NurpP --minimal linux-3.6.9/kernel/vserver/limit_init.h linux-3.6.9-vs2.3.4.4/kernel/vserver/limit_init.h
19988 --- linux-3.6.9/kernel/vserver/limit_init.h     1970-01-01 01:00:00.000000000 +0100
19989 +++ linux-3.6.9-vs2.3.4.4/kernel/vserver/limit_init.h   2012-10-04 18:47:00.000000000 +0200
19990 @@ -0,0 +1,31 @@
19991 +
19992 +
19993 +static inline void vx_info_init_limit(struct _vx_limit *limit)
19994 +{
19995 +       int lim;
19996 +
19997 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
19998 +               __rlim_soft(limit, lim) = RLIM_INFINITY;
19999 +               __rlim_hard(limit, lim) = RLIM_INFINITY;
20000 +               __rlim_set(limit, lim, 0);
20001 +               atomic_set(&__rlim_lhit(limit, lim), 0);
20002 +               __rlim_rmin(limit, lim) = 0;
20003 +               __rlim_rmax(limit, lim) = 0;
20004 +       }
20005 +}
20006 +
20007 +static inline void vx_info_exit_limit(struct _vx_limit *limit)
20008 +{
20009 +       rlim_t value;
20010 +       int lim;
20011 +
20012 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
20013 +               if ((1 << lim) & VLIM_NOCHECK)
20014 +                       continue;
20015 +               value = __rlim_get(limit, lim);
20016 +               vxwprintk_xid(value,
20017 +                       "!!! limit: %p[%s,%d] = %ld on exit.",
20018 +                       limit, vlimit_name[lim], lim, (long)value);
20019 +       }
20020 +}
20021 +
20022 diff -NurpP --minimal linux-3.6.9/kernel/vserver/limit_proc.h linux-3.6.9-vs2.3.4.4/kernel/vserver/limit_proc.h
20023 --- linux-3.6.9/kernel/vserver/limit_proc.h     1970-01-01 01:00:00.000000000 +0100
20024 +++ linux-3.6.9-vs2.3.4.4/kernel/vserver/limit_proc.h   2012-10-04 18:47:00.000000000 +0200
20025 @@ -0,0 +1,57 @@
20026 +#ifndef _VX_LIMIT_PROC_H
20027 +#define _VX_LIMIT_PROC_H
20028 +
20029 +#include <linux/vserver/limit_int.h>
20030 +
20031 +
20032 +#define VX_LIMIT_FMT   ":\t%8ld\t%8ld/%8ld\t%8lld/%8lld\t%6d\n"
20033 +#define VX_LIMIT_TOP   \
20034 +       "Limit\t current\t     min/max\t\t    soft/hard\t\thits\n"
20035 +
20036 +#define VX_LIMIT_ARG(r)                                \
20037 +       (unsigned long)__rlim_get(limit, r),    \
20038 +       (unsigned long)__rlim_rmin(limit, r),   \
20039 +       (unsigned long)__rlim_rmax(limit, r),   \
20040 +       VX_VLIM(__rlim_soft(limit, r)),         \
20041 +       VX_VLIM(__rlim_hard(limit, r)),         \
20042 +       atomic_read(&__rlim_lhit(limit, r))
20043 +
20044 +static inline int vx_info_proc_limit(struct _vx_limit *limit, char *buffer)
20045 +{
20046 +       vx_limit_fixup(limit, -1);
20047 +       return sprintf(buffer, VX_LIMIT_TOP
20048 +               "PROC"  VX_LIMIT_FMT
20049 +               "VM"    VX_LIMIT_FMT
20050 +               "VML"   VX_LIMIT_FMT
20051 +               "RSS"   VX_LIMIT_FMT
20052 +               "ANON"  VX_LIMIT_FMT
20053 +               "RMAP"  VX_LIMIT_FMT
20054 +               "FILES" VX_LIMIT_FMT
20055 +               "OFD"   VX_LIMIT_FMT
20056 +               "LOCKS" VX_LIMIT_FMT
20057 +               "SOCK"  VX_LIMIT_FMT
20058 +               "MSGQ"  VX_LIMIT_FMT
20059 +               "SHM"   VX_LIMIT_FMT
20060 +               "SEMA"  VX_LIMIT_FMT
20061 +               "SEMS"  VX_LIMIT_FMT
20062 +               "DENT"  VX_LIMIT_FMT,
20063 +               VX_LIMIT_ARG(RLIMIT_NPROC),
20064 +               VX_LIMIT_ARG(RLIMIT_AS),
20065 +               VX_LIMIT_ARG(RLIMIT_MEMLOCK),
20066 +               VX_LIMIT_ARG(RLIMIT_RSS),
20067 +               VX_LIMIT_ARG(VLIMIT_ANON),
20068 +               VX_LIMIT_ARG(VLIMIT_MAPPED),
20069 +               VX_LIMIT_ARG(RLIMIT_NOFILE),
20070 +               VX_LIMIT_ARG(VLIMIT_OPENFD),
20071 +               VX_LIMIT_ARG(RLIMIT_LOCKS),
20072 +               VX_LIMIT_ARG(VLIMIT_NSOCK),
20073 +               VX_LIMIT_ARG(RLIMIT_MSGQUEUE),
20074 +               VX_LIMIT_ARG(VLIMIT_SHMEM),
20075 +               VX_LIMIT_ARG(VLIMIT_SEMARY),
20076 +               VX_LIMIT_ARG(VLIMIT_NSEMS),
20077 +               VX_LIMIT_ARG(VLIMIT_DENTRY));
20078 +}
20079 +
20080 +#endif /* _VX_LIMIT_PROC_H */
20081 +
20082 +
20083 diff -NurpP --minimal linux-3.6.9/kernel/vserver/network.c linux-3.6.9-vs2.3.4.4/kernel/vserver/network.c
20084 --- linux-3.6.9/kernel/vserver/network.c        1970-01-01 01:00:00.000000000 +0100
20085 +++ linux-3.6.9-vs2.3.4.4/kernel/vserver/network.c      2012-10-04 18:47:00.000000000 +0200
20086 @@ -0,0 +1,912 @@
20087 +/*
20088 + *  linux/kernel/vserver/network.c
20089 + *
20090 + *  Virtual Server: Network Support
20091 + *
20092 + *  Copyright (C) 2003-2007  Herbert Pötzl
20093 + *
20094 + *  V0.01  broken out from vcontext V0.05
20095 + *  V0.02  cleaned up implementation
20096 + *  V0.03  added equiv nx commands
20097 + *  V0.04  switch to RCU based hash
20098 + *  V0.05  and back to locking again
20099 + *  V0.06  changed vcmds to nxi arg
20100 + *  V0.07  have __create claim() the nxi
20101 + *
20102 + */
20103 +
20104 +#include <linux/err.h>
20105 +#include <linux/slab.h>
20106 +#include <linux/rcupdate.h>
20107 +
20108 +#include <linux/vs_network.h>
20109 +#include <linux/vs_pid.h>
20110 +#include <linux/vserver/network_cmd.h>
20111 +
20112 +
20113 +atomic_t nx_global_ctotal      = ATOMIC_INIT(0);
20114 +atomic_t nx_global_cactive     = ATOMIC_INIT(0);
20115 +
20116 +static struct kmem_cache *nx_addr_v4_cachep = NULL;
20117 +static struct kmem_cache *nx_addr_v6_cachep = NULL;
20118 +
20119 +
20120 +static int __init init_network(void)
20121 +{
20122 +       nx_addr_v4_cachep = kmem_cache_create("nx_v4_addr_cache",
20123 +               sizeof(struct nx_addr_v4), 0,
20124 +               SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
20125 +       nx_addr_v6_cachep = kmem_cache_create("nx_v6_addr_cache",
20126 +               sizeof(struct nx_addr_v6), 0,
20127 +               SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
20128 +       return 0;
20129 +}
20130 +
20131 +
20132 +/*     __alloc_nx_addr_v4()                                    */
20133 +
20134 +static inline struct nx_addr_v4 *__alloc_nx_addr_v4(void)
20135 +{
20136 +       struct nx_addr_v4 *nxa = kmem_cache_alloc(
20137 +               nx_addr_v4_cachep, GFP_KERNEL);
20138 +
20139 +       if (!IS_ERR(nxa))
20140 +               memset(nxa, 0, sizeof(*nxa));
20141 +       return nxa;
20142 +}
20143 +
20144 +/*     __dealloc_nx_addr_v4()                                  */
20145 +
20146 +static inline void __dealloc_nx_addr_v4(struct nx_addr_v4 *nxa)
20147 +{
20148 +       kmem_cache_free(nx_addr_v4_cachep, nxa);
20149 +}
20150 +
20151 +/*     __dealloc_nx_addr_v4_all()                              */
20152 +
20153 +static inline void __dealloc_nx_addr_v4_all(struct nx_addr_v4 *nxa)
20154 +{
20155 +       while (nxa) {
20156 +               struct nx_addr_v4 *next = nxa->next;
20157 +
20158 +               __dealloc_nx_addr_v4(nxa);
20159 +               nxa = next;
20160 +       }
20161 +}
20162 +
20163 +
20164 +#ifdef CONFIG_IPV6
20165 +
20166 +/*     __alloc_nx_addr_v6()                                    */
20167 +
20168 +static inline struct nx_addr_v6 *__alloc_nx_addr_v6(void)
20169 +{
20170 +       struct nx_addr_v6 *nxa = kmem_cache_alloc(
20171 +               nx_addr_v6_cachep, GFP_KERNEL);
20172 +
20173 +       if (!IS_ERR(nxa))
20174 +               memset(nxa, 0, sizeof(*nxa));
20175 +       return nxa;
20176 +}
20177 +
20178 +/*     __dealloc_nx_addr_v6()                                  */
20179 +
20180 +static inline void __dealloc_nx_addr_v6(struct nx_addr_v6 *nxa)
20181 +{
20182 +       kmem_cache_free(nx_addr_v6_cachep, nxa);
20183 +}
20184 +
20185 +/*     __dealloc_nx_addr_v6_all()                              */
20186 +
20187 +static inline void __dealloc_nx_addr_v6_all(struct nx_addr_v6 *nxa)
20188 +{
20189 +       while (nxa) {
20190 +               struct nx_addr_v6 *next = nxa->next;
20191 +
20192 +               __dealloc_nx_addr_v6(nxa);
20193 +               nxa = next;
20194 +       }
20195 +}
20196 +
20197 +#endif /* CONFIG_IPV6 */
20198 +
20199 +/*     __alloc_nx_info()
20200 +
20201 +       * allocate an initialized nx_info struct
20202 +       * doesn't make it visible (hash)                        */
20203 +
20204 +static struct nx_info *__alloc_nx_info(nid_t nid)
20205 +{
20206 +       struct nx_info *new = NULL;
20207 +
20208 +       vxdprintk(VXD_CBIT(nid, 1), "alloc_nx_info(%d)*", nid);
20209 +
20210 +       /* would this benefit from a slab cache? */
20211 +       new = kmalloc(sizeof(struct nx_info), GFP_KERNEL);
20212 +       if (!new)
20213 +               return 0;
20214 +
20215 +       memset(new, 0, sizeof(struct nx_info));
20216 +       new->nx_id = nid;
20217 +       INIT_HLIST_NODE(&new->nx_hlist);
20218 +       atomic_set(&new->nx_usecnt, 0);
20219 +       atomic_set(&new->nx_tasks, 0);
20220 +       new->nx_state = 0;
20221 +
20222 +       new->nx_flags = NXF_INIT_SET;
20223 +
20224 +       /* rest of init goes here */
20225 +
20226 +       new->v4_lback.s_addr = htonl(INADDR_LOOPBACK);
20227 +       new->v4_bcast.s_addr = htonl(INADDR_BROADCAST);
20228 +
20229 +       vxdprintk(VXD_CBIT(nid, 0),
20230 +               "alloc_nx_info(%d) = %p", nid, new);
20231 +       atomic_inc(&nx_global_ctotal);
20232 +       return new;
20233 +}
20234 +
20235 +/*     __dealloc_nx_info()
20236 +
20237 +       * final disposal of nx_info                             */
20238 +
20239 +static void __dealloc_nx_info(struct nx_info *nxi)
20240 +{
20241 +       vxdprintk(VXD_CBIT(nid, 0),
20242 +               "dealloc_nx_info(%p)", nxi);
20243 +
20244 +       nxi->nx_hlist.next = LIST_POISON1;
20245 +       nxi->nx_id = -1;
20246 +
20247 +       BUG_ON(atomic_read(&nxi->nx_usecnt));
20248 +       BUG_ON(atomic_read(&nxi->nx_tasks));
20249 +
20250 +       __dealloc_nx_addr_v4_all(nxi->v4.next);
20251 +
20252 +       nxi->nx_state |= NXS_RELEASED;
20253 +       kfree(nxi);
20254 +       atomic_dec(&nx_global_ctotal);
20255 +}
20256 +
20257 +static void __shutdown_nx_info(struct nx_info *nxi)
20258 +{
20259 +       nxi->nx_state |= NXS_SHUTDOWN;
20260 +       vs_net_change(nxi, VSC_NETDOWN);
20261 +}
20262 +
20263 +/*     exported stuff                                          */
20264 +
20265 +void free_nx_info(struct nx_info *nxi)
20266 +{
20267 +       /* context shutdown is mandatory */
20268 +       BUG_ON(nxi->nx_state != NXS_SHUTDOWN);
20269 +
20270 +       /* context must not be hashed */
20271 +       BUG_ON(nxi->nx_state & NXS_HASHED);
20272 +
20273 +       BUG_ON(atomic_read(&nxi->nx_usecnt));
20274 +       BUG_ON(atomic_read(&nxi->nx_tasks));
20275 +
20276 +       __dealloc_nx_info(nxi);
20277 +}
20278 +
20279 +
20280 +void __nx_set_lback(struct nx_info *nxi)
20281 +{
20282 +       int nid = nxi->nx_id;
20283 +       __be32 lback = htonl(INADDR_LOOPBACK ^ ((nid & 0xFFFF) << 8));
20284 +
20285 +       nxi->v4_lback.s_addr = lback;
20286 +}
20287 +
20288 +extern int __nx_inet_add_lback(__be32 addr);
20289 +extern int __nx_inet_del_lback(__be32 addr);
20290 +
20291 +
20292 +/*     hash table for nx_info hash */
20293 +
20294 +#define NX_HASH_SIZE   13
20295 +
20296 +struct hlist_head nx_info_hash[NX_HASH_SIZE];
20297 +
20298 +static DEFINE_SPINLOCK(nx_info_hash_lock);
20299 +
20300 +
20301 +static inline unsigned int __hashval(nid_t nid)
20302 +{
20303 +       return (nid % NX_HASH_SIZE);
20304 +}
20305 +
20306 +
20307 +
20308 +/*     __hash_nx_info()
20309 +
20310 +       * add the nxi to the global hash table
20311 +       * requires the hash_lock to be held                     */
20312 +
20313 +static inline void __hash_nx_info(struct nx_info *nxi)
20314 +{
20315 +       struct hlist_head *head;
20316 +
20317 +       vxd_assert_lock(&nx_info_hash_lock);
20318 +       vxdprintk(VXD_CBIT(nid, 4),
20319 +               "__hash_nx_info: %p[#%d]", nxi, nxi->nx_id);
20320 +
20321 +       /* context must not be hashed */
20322 +       BUG_ON(nx_info_state(nxi, NXS_HASHED));
20323 +
20324 +       nxi->nx_state |= NXS_HASHED;
20325 +       head = &nx_info_hash[__hashval(nxi->nx_id)];
20326 +       hlist_add_head(&nxi->nx_hlist, head);
20327 +       atomic_inc(&nx_global_cactive);
20328 +}
20329 +
20330 +/*     __unhash_nx_info()
20331 +
20332 +       * remove the nxi from the global hash table
20333 +       * requires the hash_lock to be held                     */
20334 +
20335 +static inline void __unhash_nx_info(struct nx_info *nxi)
20336 +{
20337 +       vxd_assert_lock(&nx_info_hash_lock);
20338 +       vxdprintk(VXD_CBIT(nid, 4),
20339 +               "__unhash_nx_info: %p[#%d.%d.%d]", nxi, nxi->nx_id,
20340 +               atomic_read(&nxi->nx_usecnt), atomic_read(&nxi->nx_tasks));
20341 +
20342 +       /* context must be hashed */
20343 +       BUG_ON(!nx_info_state(nxi, NXS_HASHED));
20344 +       /* but without tasks */
20345 +       BUG_ON(atomic_read(&nxi->nx_tasks));
20346 +
20347 +       nxi->nx_state &= ~NXS_HASHED;
20348 +       hlist_del(&nxi->nx_hlist);
20349 +       atomic_dec(&nx_global_cactive);
20350 +}
20351 +
20352 +
20353 +/*     __lookup_nx_info()
20354 +
20355 +       * requires the hash_lock to be held
20356 +       * doesn't increment the nx_refcnt                       */
20357 +
20358 +static inline struct nx_info *__lookup_nx_info(nid_t nid)
20359 +{
20360 +       struct hlist_head *head = &nx_info_hash[__hashval(nid)];
20361 +       struct hlist_node *pos;
20362 +       struct nx_info *nxi;
20363 +
20364 +       vxd_assert_lock(&nx_info_hash_lock);
20365 +       hlist_for_each(pos, head) {
20366 +               nxi = hlist_entry(pos, struct nx_info, nx_hlist);
20367 +
20368 +               if (nxi->nx_id == nid)
20369 +                       goto found;
20370 +       }
20371 +       nxi = NULL;
20372 +found:
20373 +       vxdprintk(VXD_CBIT(nid, 0),
20374 +               "__lookup_nx_info(#%u): %p[#%u]",
20375 +               nid, nxi, nxi ? nxi->nx_id : 0);
20376 +       return nxi;
20377 +}
20378 +
20379 +
20380 +/*     __create_nx_info()
20381 +
20382 +       * create the requested context
20383 +       * get(), claim() and hash it                            */
20384 +
20385 +static struct nx_info *__create_nx_info(int id)
20386 +{
20387 +       struct nx_info *new, *nxi = NULL;
20388 +
20389 +       vxdprintk(VXD_CBIT(nid, 1), "create_nx_info(%d)*", id);
20390 +
20391 +       if (!(new = __alloc_nx_info(id)))
20392 +               return ERR_PTR(-ENOMEM);
20393 +
20394 +       /* required to make dynamic xids unique */
20395 +       spin_lock(&nx_info_hash_lock);
20396 +
20397 +       /* static context requested */
20398 +       if ((nxi = __lookup_nx_info(id))) {
20399 +               vxdprintk(VXD_CBIT(nid, 0),
20400 +                       "create_nx_info(%d) = %p (already there)", id, nxi);
20401 +               if (nx_info_flags(nxi, NXF_STATE_SETUP, 0))
20402 +                       nxi = ERR_PTR(-EBUSY);
20403 +               else
20404 +                       nxi = ERR_PTR(-EEXIST);
20405 +               goto out_unlock;
20406 +       }
20407 +       /* new context */
20408 +       vxdprintk(VXD_CBIT(nid, 0),
20409 +               "create_nx_info(%d) = %p (new)", id, new);
20410 +       claim_nx_info(new, NULL);
20411 +       __nx_set_lback(new);
20412 +       __hash_nx_info(get_nx_info(new));
20413 +       nxi = new, new = NULL;
20414 +
20415 +out_unlock:
20416 +       spin_unlock(&nx_info_hash_lock);
20417 +       if (new)
20418 +               __dealloc_nx_info(new);
20419 +       return nxi;
20420 +}
20421 +
20422 +
20423 +
20424 +/*     exported stuff                                          */
20425 +
20426 +
20427 +void unhash_nx_info(struct nx_info *nxi)
20428 +{
20429 +       __shutdown_nx_info(nxi);
20430 +       spin_lock(&nx_info_hash_lock);
20431 +       __unhash_nx_info(nxi);
20432 +       spin_unlock(&nx_info_hash_lock);
20433 +}
20434 +
20435 +/*     lookup_nx_info()
20436 +
20437 +       * search for a nx_info and get() it
20438 +       * negative id means current                             */
20439 +
20440 +struct nx_info *lookup_nx_info(int id)
20441 +{
20442 +       struct nx_info *nxi = NULL;
20443 +
20444 +       if (id < 0) {
20445 +               nxi = get_nx_info(current_nx_info());
20446 +       } else if (id > 1) {
20447 +               spin_lock(&nx_info_hash_lock);
20448 +               nxi = get_nx_info(__lookup_nx_info(id));
20449 +               spin_unlock(&nx_info_hash_lock);
20450 +       }
20451 +       return nxi;
20452 +}
20453 +
20454 +/*     nid_is_hashed()
20455 +
20456 +       * verify that nid is still hashed                       */
20457 +
20458 +int nid_is_hashed(nid_t nid)
20459 +{
20460 +       int hashed;
20461 +
20462 +       spin_lock(&nx_info_hash_lock);
20463 +       hashed = (__lookup_nx_info(nid) != NULL);
20464 +       spin_unlock(&nx_info_hash_lock);
20465 +       return hashed;
20466 +}
20467 +
20468 +
20469 +#ifdef CONFIG_PROC_FS
20470 +
20471 +/*     get_nid_list()
20472 +
20473 +       * get a subset of hashed nids for proc
20474 +       * assumes size is at least one                          */
20475 +
20476 +int get_nid_list(int index, unsigned int *nids, int size)
20477 +{
20478 +       int hindex, nr_nids = 0;
20479 +
20480 +       /* only show current and children */
20481 +       if (!nx_check(0, VS_ADMIN | VS_WATCH)) {
20482 +               if (index > 0)
20483 +                       return 0;
20484 +               nids[nr_nids] = nx_current_nid();
20485 +               return 1;
20486 +       }
20487 +
20488 +       for (hindex = 0; hindex < NX_HASH_SIZE; hindex++) {
20489 +               struct hlist_head *head = &nx_info_hash[hindex];
20490 +               struct hlist_node *pos;
20491 +
20492 +               spin_lock(&nx_info_hash_lock);
20493 +               hlist_for_each(pos, head) {
20494 +                       struct nx_info *nxi;
20495 +
20496 +                       if (--index > 0)
20497 +                               continue;
20498 +
20499 +                       nxi = hlist_entry(pos, struct nx_info, nx_hlist);
20500 +                       nids[nr_nids] = nxi->nx_id;
20501 +                       if (++nr_nids >= size) {
20502 +                               spin_unlock(&nx_info_hash_lock);
20503 +                               goto out;
20504 +                       }
20505 +               }
20506 +               /* keep the lock time short */
20507 +               spin_unlock(&nx_info_hash_lock);
20508 +       }
20509 +out:
20510 +       return nr_nids;
20511 +}
20512 +#endif
20513 +
20514 +
20515 +/*
20516 + *     migrate task to new network
20517 + *     gets nxi, puts old_nxi on change
20518 + */
20519 +
20520 +int nx_migrate_task(struct task_struct *p, struct nx_info *nxi)
20521 +{
20522 +       struct nx_info *old_nxi;
20523 +       int ret = 0;
20524 +
20525 +       if (!p || !nxi)
20526 +               BUG();
20527 +
20528 +       vxdprintk(VXD_CBIT(nid, 5),
20529 +               "nx_migrate_task(%p,%p[#%d.%d.%d])",
20530 +               p, nxi, nxi->nx_id,
20531 +               atomic_read(&nxi->nx_usecnt),
20532 +               atomic_read(&nxi->nx_tasks));
20533 +
20534 +       if (nx_info_flags(nxi, NXF_INFO_PRIVATE, 0) &&
20535 +               !nx_info_flags(nxi, NXF_STATE_SETUP, 0))
20536 +               return -EACCES;
20537 +
20538 +       if (nx_info_state(nxi, NXS_SHUTDOWN))
20539 +               return -EFAULT;
20540 +
20541 +       /* maybe disallow this completely? */
20542 +       old_nxi = task_get_nx_info(p);
20543 +       if (old_nxi == nxi)
20544 +               goto out;
20545 +
20546 +       task_lock(p);
20547 +       if (old_nxi)
20548 +               clr_nx_info(&p->nx_info);
20549 +       claim_nx_info(nxi, p);
20550 +       set_nx_info(&p->nx_info, nxi);
20551 +       p->nid = nxi->nx_id;
20552 +       task_unlock(p);
20553 +
20554 +       vxdprintk(VXD_CBIT(nid, 5),
20555 +               "moved task %p into nxi:%p[#%d]",
20556 +               p, nxi, nxi->nx_id);
20557 +
20558 +       if (old_nxi)
20559 +               release_nx_info(old_nxi, p);
20560 +       ret = 0;
20561 +out:
20562 +       put_nx_info(old_nxi);
20563 +       return ret;
20564 +}
20565 +
20566 +
20567 +void nx_set_persistent(struct nx_info *nxi)
20568 +{
20569 +       vxdprintk(VXD_CBIT(nid, 6),
20570 +               "nx_set_persistent(%p[#%d])", nxi, nxi->nx_id);
20571 +
20572 +       get_nx_info(nxi);
20573 +       claim_nx_info(nxi, NULL);
20574 +}
20575 +
20576 +void nx_clear_persistent(struct nx_info *nxi)
20577 +{
20578 +       vxdprintk(VXD_CBIT(nid, 6),
20579 +               "nx_clear_persistent(%p[#%d])", nxi, nxi->nx_id);
20580 +
20581 +       release_nx_info(nxi, NULL);
20582 +       put_nx_info(nxi);
20583 +}
20584 +
20585 +void nx_update_persistent(struct nx_info *nxi)
20586 +{
20587 +       if (nx_info_flags(nxi, NXF_PERSISTENT, 0))
20588 +               nx_set_persistent(nxi);
20589 +       else
20590 +               nx_clear_persistent(nxi);
20591 +}
20592 +
20593 +/* vserver syscall commands below here */
20594 +
20595 +/* taks nid and nx_info functions */
20596 +
20597 +#include <asm/uaccess.h>
20598 +
20599 +
20600 +int vc_task_nid(uint32_t id)
20601 +{
20602 +       nid_t nid;
20603 +
20604 +       if (id) {
20605 +               struct task_struct *tsk;
20606 +
20607 +               rcu_read_lock();
20608 +               tsk = find_task_by_real_pid(id);
20609 +               nid = (tsk) ? tsk->nid : -ESRCH;
20610 +               rcu_read_unlock();
20611 +       } else
20612 +               nid = nx_current_nid();
20613 +       return nid;
20614 +}
20615 +
20616 +
20617 +int vc_nx_info(struct nx_info *nxi, void __user *data)
20618 +{
20619 +       struct vcmd_nx_info_v0 vc_data;
20620 +
20621 +       vc_data.nid = nxi->nx_id;
20622 +
20623 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20624 +               return -EFAULT;
20625 +       return 0;
20626 +}
20627 +
20628 +
20629 +/* network functions */
20630 +
20631 +int vc_net_create(uint32_t nid, void __user *data)
20632 +{
20633 +       struct vcmd_net_create vc_data = { .flagword = NXF_INIT_SET };
20634 +       struct nx_info *new_nxi;
20635 +       int ret;
20636 +
20637 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20638 +               return -EFAULT;
20639 +
20640 +       if ((nid > MAX_S_CONTEXT) || (nid < 2))
20641 +               return -EINVAL;
20642 +
20643 +       new_nxi = __create_nx_info(nid);
20644 +       if (IS_ERR(new_nxi))
20645 +               return PTR_ERR(new_nxi);
20646 +
20647 +       /* initial flags */
20648 +       new_nxi->nx_flags = vc_data.flagword;
20649 +
20650 +       ret = -ENOEXEC;
20651 +       if (vs_net_change(new_nxi, VSC_NETUP))
20652 +               goto out;
20653 +
20654 +       ret = nx_migrate_task(current, new_nxi);
20655 +       if (ret)
20656 +               goto out;
20657 +
20658 +       /* return context id on success */
20659 +       ret = new_nxi->nx_id;
20660 +
20661 +       /* get a reference for persistent contexts */
20662 +       if ((vc_data.flagword & NXF_PERSISTENT))
20663 +               nx_set_persistent(new_nxi);
20664 +out:
20665 +       release_nx_info(new_nxi, NULL);
20666 +       put_nx_info(new_nxi);
20667 +       return ret;
20668 +}
20669 +
20670 +
20671 +int vc_net_migrate(struct nx_info *nxi, void __user *data)
20672 +{
20673 +       return nx_migrate_task(current, nxi);
20674 +}
20675 +
20676 +
20677 +
20678 +int do_add_v4_addr(struct nx_info *nxi, __be32 ip, __be32 ip2, __be32 mask,
20679 +       uint16_t type, uint16_t flags)
20680 +{
20681 +       struct nx_addr_v4 *nxa = &nxi->v4;
20682 +
20683 +       if (NX_IPV4(nxi)) {
20684 +               /* locate last entry */
20685 +               for (; nxa->next; nxa = nxa->next);
20686 +               nxa->next = __alloc_nx_addr_v4();
20687 +               nxa = nxa->next;
20688 +
20689 +               if (IS_ERR(nxa))
20690 +                       return PTR_ERR(nxa);
20691 +       }
20692 +
20693 +       if (nxi->v4.next)
20694 +               /* remove single ip for ip list */
20695 +               nxi->nx_flags &= ~NXF_SINGLE_IP;
20696 +
20697 +       nxa->ip[0].s_addr = ip;
20698 +       nxa->ip[1].s_addr = ip2;
20699 +       nxa->mask.s_addr = mask;
20700 +       nxa->type = type;
20701 +       nxa->flags = flags;
20702 +       return 0;
20703 +}
20704 +
20705 +int do_remove_v4_addr(struct nx_info *nxi, __be32 ip, __be32 ip2, __be32 mask,
20706 +       uint16_t type, uint16_t flags)
20707 +{
20708 +       struct nx_addr_v4 *nxa = &nxi->v4;
20709 +
20710 +       switch (type) {
20711 +/*     case NXA_TYPE_ADDR:
20712 +               break;          */
20713 +
20714 +       case NXA_TYPE_ANY:
20715 +               __dealloc_nx_addr_v4_all(xchg(&nxa->next, NULL));
20716 +               memset(nxa, 0, sizeof(*nxa));
20717 +               break;
20718 +
20719 +       default:
20720 +               return -EINVAL;
20721 +       }
20722 +       return 0;
20723 +}
20724 +
20725 +
20726 +int vc_net_add(struct nx_info *nxi, void __user *data)
20727 +{
20728 +       struct vcmd_net_addr_v0 vc_data;
20729 +       int index, ret = 0;
20730 +
20731 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20732 +               return -EFAULT;
20733 +
20734 +       switch (vc_data.type) {
20735 +       case NXA_TYPE_IPV4:
20736 +               if ((vc_data.count < 1) || (vc_data.count > 4))
20737 +                       return -EINVAL;
20738 +
20739 +               index = 0;
20740 +               while (index < vc_data.count) {
20741 +                       ret = do_add_v4_addr(nxi, vc_data.ip[index].s_addr, 0,
20742 +                               vc_data.mask[index].s_addr, NXA_TYPE_ADDR, 0);
20743 +                       if (ret)
20744 +                               return ret;
20745 +                       index++;
20746 +               }
20747 +               ret = index;
20748 +               break;
20749 +
20750 +       case NXA_TYPE_IPV4|NXA_MOD_BCAST:
20751 +               nxi->v4_bcast = vc_data.ip[0];
20752 +               ret = 1;
20753 +               break;
20754 +
20755 +       case NXA_TYPE_IPV4|NXA_MOD_LBACK:
20756 +               nxi->v4_lback = vc_data.ip[0];
20757 +               ret = 1;
20758 +               break;
20759 +
20760 +       default:
20761 +               ret = -EINVAL;
20762 +               break;
20763 +       }
20764 +       return ret;
20765 +}
20766 +
20767 +int vc_net_remove(struct nx_info *nxi, void __user *data)
20768 +{
20769 +       struct vcmd_net_addr_v0 vc_data;
20770 +
20771 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20772 +               return -EFAULT;
20773 +
20774 +       switch (vc_data.type) {
20775 +       case NXA_TYPE_ANY:
20776 +               __dealloc_nx_addr_v4_all(xchg(&nxi->v4.next, NULL));
20777 +               memset(&nxi->v4, 0, sizeof(nxi->v4));
20778 +               break;
20779 +
20780 +       default:
20781 +               return -EINVAL;
20782 +       }
20783 +       return 0;
20784 +}
20785 +
20786 +
20787 +int vc_net_add_ipv4_v1(struct nx_info *nxi, void __user *data)
20788 +{
20789 +       struct vcmd_net_addr_ipv4_v1 vc_data;
20790 +
20791 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20792 +               return -EFAULT;
20793 +
20794 +       switch (vc_data.type) {
20795 +       case NXA_TYPE_ADDR:
20796 +       case NXA_TYPE_MASK:
20797 +               return do_add_v4_addr(nxi, vc_data.ip.s_addr, 0,
20798 +                       vc_data.mask.s_addr, vc_data.type, vc_data.flags);
20799 +
20800 +       case NXA_TYPE_ADDR | NXA_MOD_BCAST:
20801 +               nxi->v4_bcast = vc_data.ip;
20802 +               break;
20803 +
20804 +       case NXA_TYPE_ADDR | NXA_MOD_LBACK:
20805 +               nxi->v4_lback = vc_data.ip;
20806 +               break;
20807 +
20808 +       default:
20809 +               return -EINVAL;
20810 +       }
20811 +       return 0;
20812 +}
20813 +
20814 +int vc_net_add_ipv4(struct nx_info *nxi, void __user *data)
20815 +{
20816 +       struct vcmd_net_addr_ipv4_v2 vc_data;
20817 +
20818 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20819 +               return -EFAULT;
20820 +
20821 +       switch (vc_data.type) {
20822 +       case NXA_TYPE_ADDR:
20823 +       case NXA_TYPE_MASK:
20824 +       case NXA_TYPE_RANGE:
20825 +               return do_add_v4_addr(nxi, vc_data.ip.s_addr, vc_data.ip2.s_addr,
20826 +                       vc_data.mask.s_addr, vc_data.type, vc_data.flags);
20827 +
20828 +       case NXA_TYPE_ADDR | NXA_MOD_BCAST:
20829 +               nxi->v4_bcast = vc_data.ip;
20830 +               break;
20831 +
20832 +       case NXA_TYPE_ADDR | NXA_MOD_LBACK:
20833 +               nxi->v4_lback = vc_data.ip;
20834 +               break;
20835 +
20836 +       default:
20837 +               return -EINVAL;
20838 +       }
20839 +       return 0;
20840 +}
20841 +
20842 +int vc_net_rem_ipv4_v1(struct nx_info *nxi, void __user *data)
20843 +{
20844 +       struct vcmd_net_addr_ipv4_v1 vc_data;
20845 +
20846 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20847 +               return -EFAULT;
20848 +
20849 +       return do_remove_v4_addr(nxi, vc_data.ip.s_addr, 0,
20850 +               vc_data.mask.s_addr, vc_data.type, vc_data.flags);
20851 +}
20852 +
20853 +int vc_net_rem_ipv4(struct nx_info *nxi, void __user *data)
20854 +{
20855 +       struct vcmd_net_addr_ipv4_v2 vc_data;
20856 +
20857 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20858 +               return -EFAULT;
20859 +
20860 +       return do_remove_v4_addr(nxi, vc_data.ip.s_addr, vc_data.ip2.s_addr,
20861 +               vc_data.mask.s_addr, vc_data.type, vc_data.flags);
20862 +}
20863 +
20864 +#ifdef CONFIG_IPV6
20865 +
20866 +int do_add_v6_addr(struct nx_info *nxi,
20867 +       struct in6_addr *ip, struct in6_addr *mask,
20868 +       uint32_t prefix, uint16_t type, uint16_t flags)
20869 +{
20870 +       struct nx_addr_v6 *nxa = &nxi->v6;
20871 +
20872 +       if (NX_IPV6(nxi)) {
20873 +               /* locate last entry */
20874 +               for (; nxa->next; nxa = nxa->next);
20875 +               nxa->next = __alloc_nx_addr_v6();
20876 +               nxa = nxa->next;
20877 +
20878 +               if (IS_ERR(nxa))
20879 +                       return PTR_ERR(nxa);
20880 +       }
20881 +
20882 +       nxa->ip = *ip;
20883 +       nxa->mask = *mask;
20884 +       nxa->prefix = prefix;
20885 +       nxa->type = type;
20886 +       nxa->flags = flags;
20887 +       return 0;
20888 +}
20889 +
20890 +
20891 +int vc_net_add_ipv6(struct nx_info *nxi, void __user *data)
20892 +{
20893 +       struct vcmd_net_addr_ipv6_v1 vc_data;
20894 +
20895 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20896 +               return -EFAULT;
20897 +
20898 +       switch (vc_data.type) {
20899 +       case NXA_TYPE_ADDR:
20900 +               memset(&vc_data.mask, ~0, sizeof(vc_data.mask));
20901 +               /* fallthrough */
20902 +       case NXA_TYPE_MASK:
20903 +               return do_add_v6_addr(nxi, &vc_data.ip, &vc_data.mask,
20904 +                       vc_data.prefix, vc_data.type, vc_data.flags);
20905 +       default:
20906 +               return -EINVAL;
20907 +       }
20908 +       return 0;
20909 +}
20910 +
20911 +int vc_net_remove_ipv6(struct nx_info *nxi, void __user *data)
20912 +{
20913 +       struct vcmd_net_addr_ipv6_v1 vc_data;
20914 +
20915 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20916 +               return -EFAULT;
20917 +
20918 +       switch (vc_data.type) {
20919 +       case NXA_TYPE_ANY:
20920 +               __dealloc_nx_addr_v6_all(xchg(&nxi->v6.next, NULL));
20921 +               memset(&nxi->v6, 0, sizeof(nxi->v6));
20922 +               break;
20923 +
20924 +       default:
20925 +               return -EINVAL;
20926 +       }
20927 +       return 0;
20928 +}
20929 +
20930 +#endif /* CONFIG_IPV6 */
20931 +
20932 +
20933 +int vc_get_nflags(struct nx_info *nxi, void __user *data)
20934 +{
20935 +       struct vcmd_net_flags_v0 vc_data;
20936 +
20937 +       vc_data.flagword = nxi->nx_flags;
20938 +
20939 +       /* special STATE flag handling */
20940 +       vc_data.mask = vs_mask_flags(~0ULL, nxi->nx_flags, NXF_ONE_TIME);
20941 +
20942 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20943 +               return -EFAULT;
20944 +       return 0;
20945 +}
20946 +
20947 +int vc_set_nflags(struct nx_info *nxi, void __user *data)
20948 +{
20949 +       struct vcmd_net_flags_v0 vc_data;
20950 +       uint64_t mask, trigger;
20951 +
20952 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20953 +               return -EFAULT;
20954 +
20955 +       /* special STATE flag handling */
20956 +       mask = vs_mask_mask(vc_data.mask, nxi->nx_flags, NXF_ONE_TIME);
20957 +       trigger = (mask & nxi->nx_flags) ^ (mask & vc_data.flagword);
20958 +
20959 +       nxi->nx_flags = vs_mask_flags(nxi->nx_flags,
20960 +               vc_data.flagword, mask);
20961 +       if (trigger & NXF_PERSISTENT)
20962 +               nx_update_persistent(nxi);
20963 +
20964 +       return 0;
20965 +}
20966 +
20967 +int vc_get_ncaps(struct nx_info *nxi, void __user *data)
20968 +{
20969 +       struct vcmd_net_caps_v0 vc_data;
20970 +
20971 +       vc_data.ncaps = nxi->nx_ncaps;
20972 +       vc_data.cmask = ~0ULL;
20973 +
20974 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20975 +               return -EFAULT;
20976 +       return 0;
20977 +}
20978 +
20979 +int vc_set_ncaps(struct nx_info *nxi, void __user *data)
20980 +{
20981 +       struct vcmd_net_caps_v0 vc_data;
20982 +
20983 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20984 +               return -EFAULT;
20985 +
20986 +       nxi->nx_ncaps = vs_mask_flags(nxi->nx_ncaps,
20987 +               vc_data.ncaps, vc_data.cmask);
20988 +       return 0;
20989 +}
20990 +
20991 +
20992 +#include <linux/module.h>
20993 +
20994 +module_init(init_network);
20995 +
20996 +EXPORT_SYMBOL_GPL(free_nx_info);
20997 +EXPORT_SYMBOL_GPL(unhash_nx_info);
20998 +
20999 diff -NurpP --minimal linux-3.6.9/kernel/vserver/proc.c linux-3.6.9-vs2.3.4.4/kernel/vserver/proc.c
21000 --- linux-3.6.9/kernel/vserver/proc.c   1970-01-01 01:00:00.000000000 +0100
21001 +++ linux-3.6.9-vs2.3.4.4/kernel/vserver/proc.c 2012-10-09 14:19:59.000000000 +0200
21002 @@ -0,0 +1,1110 @@
21003 +/*
21004 + *  linux/kernel/vserver/proc.c
21005 + *
21006 + *  Virtual Context Support
21007 + *
21008 + *  Copyright (C) 2003-2011  Herbert Pötzl
21009 + *
21010 + *  V0.01  basic structure
21011 + *  V0.02  adaptation vs1.3.0
21012 + *  V0.03  proc permissions
21013 + *  V0.04  locking/generic
21014 + *  V0.05  next generation procfs
21015 + *  V0.06  inode validation
21016 + *  V0.07  generic rewrite vid
21017 + *  V0.08  remove inode type
21018 + *  V0.09  added u/wmask info
21019 + *
21020 + */
21021 +
21022 +#include <linux/proc_fs.h>
21023 +#include <linux/fs_struct.h>
21024 +#include <linux/mount.h>
21025 +#include <linux/namei.h>
21026 +#include <asm/unistd.h>
21027 +
21028 +#include <linux/vs_context.h>
21029 +#include <linux/vs_network.h>
21030 +#include <linux/vs_cvirt.h>
21031 +
21032 +#include <linux/in.h>
21033 +#include <linux/inetdevice.h>
21034 +#include <linux/vs_inet.h>
21035 +#include <linux/vs_inet6.h>
21036 +
21037 +#include <linux/vserver/global.h>
21038 +
21039 +#include "cvirt_proc.h"
21040 +#include "cacct_proc.h"
21041 +#include "limit_proc.h"
21042 +#include "sched_proc.h"
21043 +#include "vci_config.h"
21044 +
21045 +
21046 +static inline char *print_cap_t(char *buffer, kernel_cap_t *c)
21047 +{
21048 +       unsigned __capi;
21049 +
21050 +       CAP_FOR_EACH_U32(__capi) {
21051 +               buffer += sprintf(buffer, "%08x",
21052 +                       c->cap[(_KERNEL_CAPABILITY_U32S-1) - __capi]);
21053 +       }
21054 +       return buffer;
21055 +}
21056 +
21057 +
21058 +static struct proc_dir_entry *proc_virtual;
21059 +
21060 +static struct proc_dir_entry *proc_virtnet;
21061 +
21062 +
21063 +/* first the actual feeds */
21064 +
21065 +
21066 +static int proc_vci(char *buffer)
21067 +{
21068 +       return sprintf(buffer,
21069 +               "VCIVersion:\t%04x:%04x\n"
21070 +               "VCISyscall:\t%d\n"
21071 +               "VCIKernel:\t%08x\n",
21072 +               VCI_VERSION >> 16,
21073 +               VCI_VERSION & 0xFFFF,
21074 +               __NR_vserver,
21075 +               vci_kernel_config());
21076 +}
21077 +
21078 +static int proc_virtual_info(char *buffer)
21079 +{
21080 +       return proc_vci(buffer);
21081 +}
21082 +
21083 +static int proc_virtual_status(char *buffer)
21084 +{
21085 +       return sprintf(buffer,
21086 +               "#CTotal:\t%d\n"
21087 +               "#CActive:\t%d\n"
21088 +               "#NSProxy:\t%d\t%d %d %d %d %d %d\n"
21089 +               "#InitTask:\t%d\t%d %d\n",
21090 +               atomic_read(&vx_global_ctotal),
21091 +               atomic_read(&vx_global_cactive),
21092 +               atomic_read(&vs_global_nsproxy),
21093 +               atomic_read(&vs_global_fs),
21094 +               atomic_read(&vs_global_mnt_ns),
21095 +               atomic_read(&vs_global_uts_ns),
21096 +               atomic_read(&nr_ipc_ns),
21097 +               atomic_read(&vs_global_user_ns),
21098 +               atomic_read(&vs_global_pid_ns),
21099 +               atomic_read(&init_task.usage),
21100 +               atomic_read(&init_task.nsproxy->count),
21101 +               init_task.fs->users);
21102 +}
21103 +
21104 +
21105 +int proc_vxi_info(struct vx_info *vxi, char *buffer)
21106 +{
21107 +       int length;
21108 +
21109 +       length = sprintf(buffer,
21110 +               "ID:\t%d\n"
21111 +               "Info:\t%p\n"
21112 +               "Init:\t%d\n"
21113 +               "OOM:\t%lld\n",
21114 +               vxi->vx_id,
21115 +               vxi,
21116 +               vxi->vx_initpid,
21117 +               vxi->vx_badness_bias);
21118 +       return length;
21119 +}
21120 +
21121 +int proc_vxi_status(struct vx_info *vxi, char *buffer)
21122 +{
21123 +       char *orig = buffer;
21124 +
21125 +       buffer += sprintf(buffer,
21126 +               "UseCnt:\t%d\n"
21127 +               "Tasks:\t%d\n"
21128 +               "Flags:\t%016llx\n",
21129 +               atomic_read(&vxi->vx_usecnt),
21130 +               atomic_read(&vxi->vx_tasks),
21131 +               (unsigned long long)vxi->vx_flags);
21132 +
21133 +       buffer += sprintf(buffer, "BCaps:\t");
21134 +       buffer = print_cap_t(buffer, &vxi->vx_bcaps);
21135 +       buffer += sprintf(buffer, "\n");
21136 +
21137 +       buffer += sprintf(buffer,
21138 +               "CCaps:\t%016llx\n"
21139 +               "Umask:\t%16llx\n"
21140 +               "Wmask:\t%16llx\n"
21141 +               "Spaces:\t%08lx %08lx\n",
21142 +               (unsigned long long)vxi->vx_ccaps,
21143 +               (unsigned long long)vxi->vx_umask,
21144 +               (unsigned long long)vxi->vx_wmask,
21145 +               vxi->space[0].vx_nsmask, vxi->space[1].vx_nsmask);
21146 +       return buffer - orig;
21147 +}
21148 +
21149 +int proc_vxi_limit(struct vx_info *vxi, char *buffer)
21150 +{
21151 +       return vx_info_proc_limit(&vxi->limit, buffer);
21152 +}
21153 +
21154 +int proc_vxi_sched(struct vx_info *vxi, char *buffer)
21155 +{
21156 +       int cpu, length;
21157 +
21158 +       length = vx_info_proc_sched(&vxi->sched, buffer);
21159 +       for_each_online_cpu(cpu) {
21160 +               length += vx_info_proc_sched_pc(
21161 +                       &vx_per_cpu(vxi, sched_pc, cpu),
21162 +                       buffer + length, cpu);
21163 +       }
21164 +       return length;
21165 +}
21166 +
21167 +int proc_vxi_nsproxy0(struct vx_info *vxi, char *buffer)
21168 +{
21169 +       return vx_info_proc_nsproxy(vxi->space[0].vx_nsproxy, buffer);
21170 +}
21171 +
21172 +int proc_vxi_nsproxy1(struct vx_info *vxi, char *buffer)
21173 +{
21174 +       return vx_info_proc_nsproxy(vxi->space[1].vx_nsproxy, buffer);
21175 +}
21176 +
21177 +int proc_vxi_cvirt(struct vx_info *vxi, char *buffer)
21178 +{
21179 +       int cpu, length;
21180 +
21181 +       vx_update_load(vxi);
21182 +       length = vx_info_proc_cvirt(&vxi->cvirt, buffer);
21183 +       for_each_online_cpu(cpu) {
21184 +               length += vx_info_proc_cvirt_pc(
21185 +                       &vx_per_cpu(vxi, cvirt_pc, cpu),
21186 +                       buffer + length, cpu);
21187 +       }
21188 +       return length;
21189 +}
21190 +
21191 +int proc_vxi_cacct(struct vx_info *vxi, char *buffer)
21192 +{
21193 +       return vx_info_proc_cacct(&vxi->cacct, buffer);
21194 +}
21195 +
21196 +
21197 +static int proc_virtnet_info(char *buffer)
21198 +{
21199 +       return proc_vci(buffer);
21200 +}
21201 +
21202 +static int proc_virtnet_status(char *buffer)
21203 +{
21204 +       return sprintf(buffer,
21205 +               "#CTotal:\t%d\n"
21206 +               "#CActive:\t%d\n",
21207 +               atomic_read(&nx_global_ctotal),
21208 +               atomic_read(&nx_global_cactive));
21209 +}
21210 +
21211 +int proc_nxi_info(struct nx_info *nxi, char *buffer)
21212 +{
21213 +       struct nx_addr_v4 *v4a;
21214 +#ifdef CONFIG_IPV6
21215 +       struct nx_addr_v6 *v6a;
21216 +#endif
21217 +       int length, i;
21218 +
21219 +       length = sprintf(buffer,
21220 +               "ID:\t%d\n"
21221 +               "Info:\t%p\n"
21222 +               "Bcast:\t" NIPQUAD_FMT "\n"
21223 +               "Lback:\t" NIPQUAD_FMT "\n",
21224 +               nxi->nx_id,
21225 +               nxi,
21226 +               NIPQUAD(nxi->v4_bcast.s_addr),
21227 +               NIPQUAD(nxi->v4_lback.s_addr));
21228 +
21229 +       if (!NX_IPV4(nxi))
21230 +               goto skip_v4;
21231 +       for (i = 0, v4a = &nxi->v4; v4a; i++, v4a = v4a->next)
21232 +               length += sprintf(buffer + length, "%d:\t" NXAV4_FMT "\n",
21233 +                       i, NXAV4(v4a));
21234 +skip_v4:
21235 +#ifdef CONFIG_IPV6
21236 +       if (!NX_IPV6(nxi))
21237 +               goto skip_v6;
21238 +       for (i = 0, v6a = &nxi->v6; v6a; i++, v6a = v6a->next)
21239 +               length += sprintf(buffer + length, "%d:\t" NXAV6_FMT "\n",
21240 +                       i, NXAV6(v6a));
21241 +skip_v6:
21242 +#endif
21243 +       return length;
21244 +}
21245 +
21246 +int proc_nxi_status(struct nx_info *nxi, char *buffer)
21247 +{
21248 +       int length;
21249 +
21250 +       length = sprintf(buffer,
21251 +               "UseCnt:\t%d\n"
21252 +               "Tasks:\t%d\n"
21253 +               "Flags:\t%016llx\n"
21254 +               "NCaps:\t%016llx\n",
21255 +               atomic_read(&nxi->nx_usecnt),
21256 +               atomic_read(&nxi->nx_tasks),
21257 +               (unsigned long long)nxi->nx_flags,
21258 +               (unsigned long long)nxi->nx_ncaps);
21259 +       return length;
21260 +}
21261 +
21262 +
21263 +
21264 +/* here the inode helpers */
21265 +
21266 +struct vs_entry {
21267 +       int len;
21268 +       char *name;
21269 +       mode_t mode;
21270 +       struct inode_operations *iop;
21271 +       struct file_operations *fop;
21272 +       union proc_op op;
21273 +};
21274 +
21275 +static struct inode *vs_proc_make_inode(struct super_block *sb, struct vs_entry *p)
21276 +{
21277 +       struct inode *inode = new_inode(sb);
21278 +
21279 +       if (!inode)
21280 +               goto out;
21281 +
21282 +       inode->i_mode = p->mode;
21283 +       if (p->iop)
21284 +               inode->i_op = p->iop;
21285 +       if (p->fop)
21286 +               inode->i_fop = p->fop;
21287 +
21288 +       set_nlink(inode, (p->mode & S_IFDIR) ? 2 : 1);
21289 +       inode->i_flags |= S_IMMUTABLE;
21290 +
21291 +       inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
21292 +
21293 +       inode->i_uid = 0;
21294 +       inode->i_gid = 0;
21295 +       inode->i_tag = 0;
21296 +out:
21297 +       return inode;
21298 +}
21299 +
21300 +static struct dentry *vs_proc_instantiate(struct inode *dir,
21301 +       struct dentry *dentry, int id, void *ptr)
21302 +{
21303 +       struct vs_entry *p = ptr;
21304 +       struct inode *inode = vs_proc_make_inode(dir->i_sb, p);
21305 +       struct dentry *error = ERR_PTR(-EINVAL);
21306 +
21307 +       if (!inode)
21308 +               goto out;
21309 +
21310 +       PROC_I(inode)->op = p->op;
21311 +       PROC_I(inode)->fd = id;
21312 +       d_add(dentry, inode);
21313 +       error = NULL;
21314 +out:
21315 +       return error;
21316 +}
21317 +
21318 +/* Lookups */
21319 +
21320 +typedef struct dentry *instantiate_t(struct inode *, struct dentry *, int, void *);
21321 +
21322 +/*
21323 + * Fill a directory entry.
21324 + *
21325 + * If possible create the dcache entry and derive our inode number and
21326 + * file type from dcache entry.
21327 + *
21328 + * Since all of the proc inode numbers are dynamically generated, the inode
21329 + * numbers do not exist until the inode is cache.  This means creating the
21330 + * the dcache entry in readdir is necessary to keep the inode numbers
21331 + * reported by readdir in sync with the inode numbers reported
21332 + * by stat.
21333 + */
21334 +static int proc_fill_cache(struct file *filp, void *dirent, filldir_t filldir,
21335 +       char *name, int len, instantiate_t instantiate, int id, void *ptr)
21336 +{
21337 +       struct dentry *child, *dir = filp->f_dentry;
21338 +       struct inode *inode;
21339 +       struct qstr qname;
21340 +       ino_t ino = 0;
21341 +       unsigned type = DT_UNKNOWN;
21342 +
21343 +       qname.name = name;
21344 +       qname.len  = len;
21345 +       qname.hash = full_name_hash(name, len);
21346 +
21347 +       child = d_lookup(dir, &qname);
21348 +       if (!child) {
21349 +               struct dentry *new;
21350 +               new = d_alloc(dir, &qname);
21351 +               if (new) {
21352 +                       child = instantiate(dir->d_inode, new, id, ptr);
21353 +                       if (child)
21354 +                               dput(new);
21355 +                       else
21356 +                               child = new;
21357 +               }
21358 +       }
21359 +       if (!child || IS_ERR(child) || !child->d_inode)
21360 +               goto end_instantiate;
21361 +       inode = child->d_inode;
21362 +       if (inode) {
21363 +               ino = inode->i_ino;
21364 +               type = inode->i_mode >> 12;
21365 +       }
21366 +       dput(child);
21367 +end_instantiate:
21368 +       if (!ino)
21369 +               ino = find_inode_number(dir, &qname);
21370 +       if (!ino)
21371 +               ino = 1;
21372 +       return filldir(dirent, name, len, filp->f_pos, ino, type);
21373 +}
21374 +
21375 +
21376 +
21377 +/* get and revalidate vx_info/xid */
21378 +
21379 +static inline
21380 +struct vx_info *get_proc_vx_info(struct inode *inode)
21381 +{
21382 +       return lookup_vx_info(PROC_I(inode)->fd);
21383 +}
21384 +
21385 +static int proc_xid_revalidate(struct dentry *dentry, unsigned int flags)
21386 +{
21387 +       struct inode *inode = dentry->d_inode;
21388 +       xid_t xid = PROC_I(inode)->fd;
21389 +
21390 +       if (flags & LOOKUP_RCU) /* FIXME: can be dropped? */
21391 +               return -ECHILD;
21392 +
21393 +       if (!xid || xid_is_hashed(xid))
21394 +               return 1;
21395 +       d_drop(dentry);
21396 +       return 0;
21397 +}
21398 +
21399 +
21400 +/* get and revalidate nx_info/nid */
21401 +
21402 +static int proc_nid_revalidate(struct dentry *dentry, unsigned int flags)
21403 +{
21404 +       struct inode *inode = dentry->d_inode;
21405 +       nid_t nid = PROC_I(inode)->fd;
21406 +
21407 +       if (flags & LOOKUP_RCU) /* FIXME: can be dropped? */
21408 +               return -ECHILD;
21409 +
21410 +       if (!nid || nid_is_hashed(nid))
21411 +               return 1;
21412 +       d_drop(dentry);
21413 +       return 0;
21414 +}
21415 +
21416 +
21417 +
21418 +#define PROC_BLOCK_SIZE (PAGE_SIZE - 1024)
21419 +
21420 +static ssize_t proc_vs_info_read(struct file *file, char __user *buf,
21421 +                         size_t count, loff_t *ppos)
21422 +{
21423 +       struct inode *inode = file->f_dentry->d_inode;
21424 +       unsigned long page;
21425 +       ssize_t length = 0;
21426 +
21427 +       if (count > PROC_BLOCK_SIZE)
21428 +               count = PROC_BLOCK_SIZE;
21429 +
21430 +       /* fade that out as soon as stable */
21431 +       WARN_ON(PROC_I(inode)->fd);
21432 +
21433 +       if (!(page = __get_free_page(GFP_KERNEL)))
21434 +               return -ENOMEM;
21435 +
21436 +       BUG_ON(!PROC_I(inode)->op.proc_vs_read);
21437 +       length = PROC_I(inode)->op.proc_vs_read((char *)page);
21438 +
21439 +       if (length >= 0)
21440 +               length = simple_read_from_buffer(buf, count, ppos,
21441 +                       (char *)page, length);
21442 +
21443 +       free_page(page);
21444 +       return length;
21445 +}
21446 +
21447 +static ssize_t proc_vx_info_read(struct file *file, char __user *buf,
21448 +                         size_t count, loff_t *ppos)
21449 +{
21450 +       struct inode *inode = file->f_dentry->d_inode;
21451 +       struct vx_info *vxi = NULL;
21452 +       xid_t xid = PROC_I(inode)->fd;
21453 +       unsigned long page;
21454 +       ssize_t length = 0;
21455 +
21456 +       if (count > PROC_BLOCK_SIZE)
21457 +               count = PROC_BLOCK_SIZE;
21458 +
21459 +       /* fade that out as soon as stable */
21460 +       WARN_ON(!xid);
21461 +       vxi = lookup_vx_info(xid);
21462 +       if (!vxi)
21463 +               goto out;
21464 +
21465 +       length = -ENOMEM;
21466 +       if (!(page = __get_free_page(GFP_KERNEL)))
21467 +               goto out_put;
21468 +
21469 +       BUG_ON(!PROC_I(inode)->op.proc_vxi_read);
21470 +       length = PROC_I(inode)->op.proc_vxi_read(vxi, (char *)page);
21471 +
21472 +       if (length >= 0)
21473 +               length = simple_read_from_buffer(buf, count, ppos,
21474 +                       (char *)page, length);
21475 +
21476 +       free_page(page);
21477 +out_put:
21478 +       put_vx_info(vxi);
21479 +out:
21480 +       return length;
21481 +}
21482 +
21483 +static ssize_t proc_nx_info_read(struct file *file, char __user *buf,
21484 +                         size_t count, loff_t *ppos)
21485 +{
21486 +       struct inode *inode = file->f_dentry->d_inode;
21487 +       struct nx_info *nxi = NULL;
21488 +       nid_t nid = PROC_I(inode)->fd;
21489 +       unsigned long page;
21490 +       ssize_t length = 0;
21491 +
21492 +       if (count > PROC_BLOCK_SIZE)
21493 +               count = PROC_BLOCK_SIZE;
21494 +
21495 +       /* fade that out as soon as stable */
21496 +       WARN_ON(!nid);
21497 +       nxi = lookup_nx_info(nid);
21498 +       if (!nxi)
21499 +               goto out;
21500 +
21501 +       length = -ENOMEM;
21502 +       if (!(page = __get_free_page(GFP_KERNEL)))
21503 +               goto out_put;
21504 +
21505 +       BUG_ON(!PROC_I(inode)->op.proc_nxi_read);
21506 +       length = PROC_I(inode)->op.proc_nxi_read(nxi, (char *)page);
21507 +
21508 +       if (length >= 0)
21509 +               length = simple_read_from_buffer(buf, count, ppos,
21510 +                       (char *)page, length);
21511 +
21512 +       free_page(page);
21513 +out_put:
21514 +       put_nx_info(nxi);
21515 +out:
21516 +       return length;
21517 +}
21518 +
21519 +
21520 +
21521 +/* here comes the lower level */
21522 +
21523 +
21524 +#define NOD(NAME, MODE, IOP, FOP, OP) {        \
21525 +       .len  = sizeof(NAME) - 1,       \
21526 +       .name = (NAME),                 \
21527 +       .mode = MODE,                   \
21528 +       .iop  = IOP,                    \
21529 +       .fop  = FOP,                    \
21530 +       .op   = OP,                     \
21531 +}
21532 +
21533 +
21534 +#define DIR(NAME, MODE, OTYPE)                         \
21535 +       NOD(NAME, (S_IFDIR | (MODE)),                   \
21536 +               &proc_ ## OTYPE ## _inode_operations,   \
21537 +               &proc_ ## OTYPE ## _file_operations, { } )
21538 +
21539 +#define INF(NAME, MODE, OTYPE)                         \
21540 +       NOD(NAME, (S_IFREG | (MODE)), NULL,             \
21541 +               &proc_vs_info_file_operations,          \
21542 +               { .proc_vs_read = &proc_##OTYPE } )
21543 +
21544 +#define VINF(NAME, MODE, OTYPE)                                \
21545 +       NOD(NAME, (S_IFREG | (MODE)), NULL,             \
21546 +               &proc_vx_info_file_operations,          \
21547 +               { .proc_vxi_read = &proc_##OTYPE } )
21548 +
21549 +#define NINF(NAME, MODE, OTYPE)                                \
21550 +       NOD(NAME, (S_IFREG | (MODE)), NULL,             \
21551 +               &proc_nx_info_file_operations,          \
21552 +               { .proc_nxi_read = &proc_##OTYPE } )
21553 +
21554 +
21555 +static struct file_operations proc_vs_info_file_operations = {
21556 +       .read =         proc_vs_info_read,
21557 +};
21558 +
21559 +static struct file_operations proc_vx_info_file_operations = {
21560 +       .read =         proc_vx_info_read,
21561 +};
21562 +
21563 +static struct dentry_operations proc_xid_dentry_operations = {
21564 +       .d_revalidate = proc_xid_revalidate,
21565 +};
21566 +
21567 +static struct vs_entry vx_base_stuff[] = {
21568 +       VINF("info",    S_IRUGO, vxi_info),
21569 +       VINF("status",  S_IRUGO, vxi_status),
21570 +       VINF("limit",   S_IRUGO, vxi_limit),
21571 +       VINF("sched",   S_IRUGO, vxi_sched),
21572 +       VINF("nsproxy", S_IRUGO, vxi_nsproxy0),
21573 +       VINF("nsproxy1",S_IRUGO, vxi_nsproxy1),
21574 +       VINF("cvirt",   S_IRUGO, vxi_cvirt),
21575 +       VINF("cacct",   S_IRUGO, vxi_cacct),
21576 +       {}
21577 +};
21578 +
21579 +
21580 +
21581 +
21582 +static struct dentry *proc_xid_instantiate(struct inode *dir,
21583 +       struct dentry *dentry, int id, void *ptr)
21584 +{
21585 +       dentry->d_op = &proc_xid_dentry_operations;
21586 +       return vs_proc_instantiate(dir, dentry, id, ptr);
21587 +}
21588 +
21589 +static struct dentry *proc_xid_lookup(struct inode *dir,
21590 +       struct dentry *dentry, unsigned int flags)
21591 +{
21592 +       struct vs_entry *p = vx_base_stuff;
21593 +       struct dentry *error = ERR_PTR(-ENOENT);
21594 +
21595 +       for (; p->name; p++) {
21596 +               if (p->len != dentry->d_name.len)
21597 +                       continue;
21598 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
21599 +                       break;
21600 +       }
21601 +       if (!p->name)
21602 +               goto out;
21603 +
21604 +       error = proc_xid_instantiate(dir, dentry, PROC_I(dir)->fd, p);
21605 +out:
21606 +       return error;
21607 +}
21608 +
21609 +static int proc_xid_readdir(struct file *filp,
21610 +       void *dirent, filldir_t filldir)
21611 +{
21612 +       struct dentry *dentry = filp->f_dentry;
21613 +       struct inode *inode = dentry->d_inode;
21614 +       struct vs_entry *p = vx_base_stuff;
21615 +       int size = sizeof(vx_base_stuff) / sizeof(struct vs_entry);
21616 +       int pos, index;
21617 +       u64 ino;
21618 +
21619 +       pos = filp->f_pos;
21620 +       switch (pos) {
21621 +       case 0:
21622 +               ino = inode->i_ino;
21623 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
21624 +                       goto out;
21625 +               pos++;
21626 +               /* fall through */
21627 +       case 1:
21628 +               ino = parent_ino(dentry);
21629 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
21630 +                       goto out;
21631 +               pos++;
21632 +               /* fall through */
21633 +       default:
21634 +               index = pos - 2;
21635 +               if (index >= size)
21636 +                       goto out;
21637 +               for (p += index; p->name; p++) {
21638 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
21639 +                               vs_proc_instantiate, PROC_I(inode)->fd, p))
21640 +                               goto out;
21641 +                       pos++;
21642 +               }
21643 +       }
21644 +out:
21645 +       filp->f_pos = pos;
21646 +       return 1;
21647 +}
21648 +
21649 +
21650 +
21651 +static struct file_operations proc_nx_info_file_operations = {
21652 +       .read =         proc_nx_info_read,
21653 +};
21654 +
21655 +static struct dentry_operations proc_nid_dentry_operations = {
21656 +       .d_revalidate = proc_nid_revalidate,
21657 +};
21658 +
21659 +static struct vs_entry nx_base_stuff[] = {
21660 +       NINF("info",    S_IRUGO, nxi_info),
21661 +       NINF("status",  S_IRUGO, nxi_status),
21662 +       {}
21663 +};
21664 +
21665 +
21666 +static struct dentry *proc_nid_instantiate(struct inode *dir,
21667 +       struct dentry *dentry, int id, void *ptr)
21668 +{
21669 +       dentry->d_op = &proc_nid_dentry_operations;
21670 +       return vs_proc_instantiate(dir, dentry, id, ptr);
21671 +}
21672 +
21673 +static struct dentry *proc_nid_lookup(struct inode *dir,
21674 +       struct dentry *dentry, unsigned int flags)
21675 +{
21676 +       struct vs_entry *p = nx_base_stuff;
21677 +       struct dentry *error = ERR_PTR(-ENOENT);
21678 +
21679 +       for (; p->name; p++) {
21680 +               if (p->len != dentry->d_name.len)
21681 +                       continue;
21682 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
21683 +                       break;
21684 +       }
21685 +       if (!p->name)
21686 +               goto out;
21687 +
21688 +       error = proc_nid_instantiate(dir, dentry, PROC_I(dir)->fd, p);
21689 +out:
21690 +       return error;
21691 +}
21692 +
21693 +static int proc_nid_readdir(struct file *filp,
21694 +       void *dirent, filldir_t filldir)
21695 +{
21696 +       struct dentry *dentry = filp->f_dentry;
21697 +       struct inode *inode = dentry->d_inode;
21698 +       struct vs_entry *p = nx_base_stuff;
21699 +       int size = sizeof(nx_base_stuff) / sizeof(struct vs_entry);
21700 +       int pos, index;
21701 +       u64 ino;
21702 +
21703 +       pos = filp->f_pos;
21704 +       switch (pos) {
21705 +       case 0:
21706 +               ino = inode->i_ino;
21707 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
21708 +                       goto out;
21709 +               pos++;
21710 +               /* fall through */
21711 +       case 1:
21712 +               ino = parent_ino(dentry);
21713 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
21714 +                       goto out;
21715 +               pos++;
21716 +               /* fall through */
21717 +       default:
21718 +               index = pos - 2;
21719 +               if (index >= size)
21720 +                       goto out;
21721 +               for (p += index; p->name; p++) {
21722 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
21723 +                               vs_proc_instantiate, PROC_I(inode)->fd, p))
21724 +                               goto out;
21725 +                       pos++;
21726 +               }
21727 +       }
21728 +out:
21729 +       filp->f_pos = pos;
21730 +       return 1;
21731 +}
21732 +
21733 +
21734 +#define MAX_MULBY10    ((~0U - 9) / 10)
21735 +
21736 +static inline int atovid(const char *str, int len)
21737 +{
21738 +       int vid, c;
21739 +
21740 +       vid = 0;
21741 +       while (len-- > 0) {
21742 +               c = *str - '0';
21743 +               str++;
21744 +               if (c > 9)
21745 +                       return -1;
21746 +               if (vid >= MAX_MULBY10)
21747 +                       return -1;
21748 +               vid *= 10;
21749 +               vid += c;
21750 +               if (!vid)
21751 +                       return -1;
21752 +       }
21753 +       return vid;
21754 +}
21755 +
21756 +/* now the upper level (virtual) */
21757 +
21758 +
21759 +static struct file_operations proc_xid_file_operations = {
21760 +       .read =         generic_read_dir,
21761 +       .readdir =      proc_xid_readdir,
21762 +};
21763 +
21764 +static struct inode_operations proc_xid_inode_operations = {
21765 +       .lookup =       proc_xid_lookup,
21766 +};
21767 +
21768 +static struct vs_entry vx_virtual_stuff[] = {
21769 +       INF("info",     S_IRUGO, virtual_info),
21770 +       INF("status",   S_IRUGO, virtual_status),
21771 +       DIR(NULL,       S_IRUGO | S_IXUGO, xid),
21772 +};
21773 +
21774 +
21775 +static struct dentry *proc_virtual_lookup(struct inode *dir,
21776 +       struct dentry *dentry, unsigned int flags)
21777 +{
21778 +       struct vs_entry *p = vx_virtual_stuff;
21779 +       struct dentry *error = ERR_PTR(-ENOENT);
21780 +       int id = 0;
21781 +
21782 +       for (; p->name; p++) {
21783 +               if (p->len != dentry->d_name.len)
21784 +                       continue;
21785 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
21786 +                       break;
21787 +       }
21788 +       if (p->name)
21789 +               goto instantiate;
21790 +
21791 +       id = atovid(dentry->d_name.name, dentry->d_name.len);
21792 +       if ((id < 0) || !xid_is_hashed(id))
21793 +               goto out;
21794 +
21795 +instantiate:
21796 +       error = proc_xid_instantiate(dir, dentry, id, p);
21797 +out:
21798 +       return error;
21799 +}
21800 +
21801 +static struct file_operations proc_nid_file_operations = {
21802 +       .read =         generic_read_dir,
21803 +       .readdir =      proc_nid_readdir,
21804 +};
21805 +
21806 +static struct inode_operations proc_nid_inode_operations = {
21807 +       .lookup =       proc_nid_lookup,
21808 +};
21809 +
21810 +static struct vs_entry nx_virtnet_stuff[] = {
21811 +       INF("info",     S_IRUGO, virtnet_info),
21812 +       INF("status",   S_IRUGO, virtnet_status),
21813 +       DIR(NULL,       S_IRUGO | S_IXUGO, nid),
21814 +};
21815 +
21816 +
21817 +static struct dentry *proc_virtnet_lookup(struct inode *dir,
21818 +       struct dentry *dentry, unsigned int flags)
21819 +{
21820 +       struct vs_entry *p = nx_virtnet_stuff;
21821 +       struct dentry *error = ERR_PTR(-ENOENT);
21822 +       int id = 0;
21823 +
21824 +       for (; p->name; p++) {
21825 +               if (p->len != dentry->d_name.len)
21826 +                       continue;
21827 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
21828 +                       break;
21829 +       }
21830 +       if (p->name)
21831 +               goto instantiate;
21832 +
21833 +       id = atovid(dentry->d_name.name, dentry->d_name.len);
21834 +       if ((id < 0) || !nid_is_hashed(id))
21835 +               goto out;
21836 +
21837 +instantiate:
21838 +       error = proc_nid_instantiate(dir, dentry, id, p);
21839 +out:
21840 +       return error;
21841 +}
21842 +
21843 +
21844 +#define PROC_MAXVIDS 32
21845 +
21846 +int proc_virtual_readdir(struct file *filp,
21847 +       void *dirent, filldir_t filldir)
21848 +{
21849 +       struct dentry *dentry = filp->f_dentry;
21850 +       struct inode *inode = dentry->d_inode;
21851 +       struct vs_entry *p = vx_virtual_stuff;
21852 +       int size = sizeof(vx_virtual_stuff) / sizeof(struct vs_entry);
21853 +       int pos, index;
21854 +       unsigned int xid_array[PROC_MAXVIDS];
21855 +       char buf[PROC_NUMBUF];
21856 +       unsigned int nr_xids, i;
21857 +       u64 ino;
21858 +
21859 +       pos = filp->f_pos;
21860 +       switch (pos) {
21861 +       case 0:
21862 +               ino = inode->i_ino;
21863 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
21864 +                       goto out;
21865 +               pos++;
21866 +               /* fall through */
21867 +       case 1:
21868 +               ino = parent_ino(dentry);
21869 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
21870 +                       goto out;
21871 +               pos++;
21872 +               /* fall through */
21873 +       default:
21874 +               index = pos - 2;
21875 +               if (index >= size)
21876 +                       goto entries;
21877 +               for (p += index; p->name; p++) {
21878 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
21879 +                               vs_proc_instantiate, 0, p))
21880 +                               goto out;
21881 +                       pos++;
21882 +               }
21883 +       entries:
21884 +               index = pos - size;
21885 +               p = &vx_virtual_stuff[size - 1];
21886 +               nr_xids = get_xid_list(index, xid_array, PROC_MAXVIDS);
21887 +               for (i = 0; i < nr_xids; i++) {
21888 +                       int n, xid = xid_array[i];
21889 +                       unsigned int j = PROC_NUMBUF;
21890 +
21891 +                       n = xid;
21892 +                       do
21893 +                               buf[--j] = '0' + (n % 10);
21894 +                       while (n /= 10);
21895 +
21896 +                       if (proc_fill_cache(filp, dirent, filldir,
21897 +                               buf + j, PROC_NUMBUF - j,
21898 +                               vs_proc_instantiate, xid, p))
21899 +                               goto out;
21900 +                       pos++;
21901 +               }
21902 +       }
21903 +out:
21904 +       filp->f_pos = pos;
21905 +       return 0;
21906 +}
21907 +
21908 +static int proc_virtual_getattr(struct vfsmount *mnt,
21909 +       struct dentry *dentry, struct kstat *stat)
21910 +{
21911 +       struct inode *inode = dentry->d_inode;
21912 +
21913 +       generic_fillattr(inode, stat);
21914 +       stat->nlink = 2 + atomic_read(&vx_global_cactive);
21915 +       return 0;
21916 +}
21917 +
21918 +static struct file_operations proc_virtual_dir_operations = {
21919 +       .read =         generic_read_dir,
21920 +       .readdir =      proc_virtual_readdir,
21921 +};
21922 +
21923 +static struct inode_operations proc_virtual_dir_inode_operations = {
21924 +       .getattr =      proc_virtual_getattr,
21925 +       .lookup =       proc_virtual_lookup,
21926 +};
21927 +
21928 +
21929 +
21930 +
21931 +
21932 +int proc_virtnet_readdir(struct file *filp,
21933 +       void *dirent, filldir_t filldir)
21934 +{
21935 +       struct dentry *dentry = filp->f_dentry;
21936 +       struct inode *inode = dentry->d_inode;
21937 +       struct vs_entry *p = nx_virtnet_stuff;
21938 +       int size = sizeof(nx_virtnet_stuff) / sizeof(struct vs_entry);
21939 +       int pos, index;
21940 +       unsigned int nid_array[PROC_MAXVIDS];
21941 +       char buf[PROC_NUMBUF];
21942 +       unsigned int nr_nids, i;
21943 +       u64 ino;
21944 +
21945 +       pos = filp->f_pos;
21946 +       switch (pos) {
21947 +       case 0:
21948 +               ino = inode->i_ino;
21949 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
21950 +                       goto out;
21951 +               pos++;
21952 +               /* fall through */
21953 +       case 1:
21954 +               ino = parent_ino(dentry);
21955 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
21956 +                       goto out;
21957 +               pos++;
21958 +               /* fall through */
21959 +       default:
21960 +               index = pos - 2;
21961 +               if (index >= size)
21962 +                       goto entries;
21963 +               for (p += index; p->name; p++) {
21964 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
21965 +                               vs_proc_instantiate, 0, p))
21966 +                               goto out;
21967 +                       pos++;
21968 +               }
21969 +       entries:
21970 +               index = pos - size;
21971 +               p = &nx_virtnet_stuff[size - 1];
21972 +               nr_nids = get_nid_list(index, nid_array, PROC_MAXVIDS);
21973 +               for (i = 0; i < nr_nids; i++) {
21974 +                       int n, nid = nid_array[i];
21975 +                       unsigned int j = PROC_NUMBUF;
21976 +
21977 +                       n = nid;
21978 +                       do
21979 +                               buf[--j] = '0' + (n % 10);
21980 +                       while (n /= 10);
21981 +
21982 +                       if (proc_fill_cache(filp, dirent, filldir,
21983 +                               buf + j, PROC_NUMBUF - j,
21984 +                               vs_proc_instantiate, nid, p))
21985 +                               goto out;
21986 +                       pos++;
21987 +               }
21988 +       }
21989 +out:
21990 +       filp->f_pos = pos;
21991 +       return 0;
21992 +}
21993 +
21994 +static int proc_virtnet_getattr(struct vfsmount *mnt,
21995 +       struct dentry *dentry, struct kstat *stat)
21996 +{
21997 +       struct inode *inode = dentry->d_inode;
21998 +
21999 +       generic_fillattr(inode, stat);
22000 +       stat->nlink = 2 + atomic_read(&nx_global_cactive);
22001 +       return 0;
22002 +}
22003 +
22004 +static struct file_operations proc_virtnet_dir_operations = {
22005 +       .read =         generic_read_dir,
22006 +       .readdir =      proc_virtnet_readdir,
22007 +};
22008 +
22009 +static struct inode_operations proc_virtnet_dir_inode_operations = {
22010 +       .getattr =      proc_virtnet_getattr,
22011 +       .lookup =       proc_virtnet_lookup,
22012 +};
22013 +
22014 +
22015 +
22016 +void proc_vx_init(void)
22017 +{
22018 +       struct proc_dir_entry *ent;
22019 +
22020 +       ent = proc_mkdir("virtual", 0);
22021 +       if (ent) {
22022 +               ent->proc_fops = &proc_virtual_dir_operations;
22023 +               ent->proc_iops = &proc_virtual_dir_inode_operations;
22024 +       }
22025 +       proc_virtual = ent;
22026 +
22027 +       ent = proc_mkdir("virtnet", 0);
22028 +       if (ent) {
22029 +               ent->proc_fops = &proc_virtnet_dir_operations;
22030 +               ent->proc_iops = &proc_virtnet_dir_inode_operations;
22031 +       }
22032 +       proc_virtnet = ent;
22033 +}
22034 +
22035 +
22036 +
22037 +
22038 +/* per pid info */
22039 +
22040 +
22041 +int proc_pid_vx_info(struct task_struct *p, char *buffer)
22042 +{
22043 +       struct vx_info *vxi;
22044 +       char *orig = buffer;
22045 +
22046 +       buffer += sprintf(buffer, "XID:\t%d\n", vx_task_xid(p));
22047 +
22048 +       vxi = task_get_vx_info(p);
22049 +       if (!vxi)
22050 +               goto out;
22051 +
22052 +       buffer += sprintf(buffer, "BCaps:\t");
22053 +       buffer = print_cap_t(buffer, &vxi->vx_bcaps);
22054 +       buffer += sprintf(buffer, "\n");
22055 +       buffer += sprintf(buffer, "CCaps:\t%016llx\n",
22056 +               (unsigned long long)vxi->vx_ccaps);
22057 +       buffer += sprintf(buffer, "CFlags:\t%016llx\n",
22058 +               (unsigned long long)vxi->vx_flags);
22059 +       buffer += sprintf(buffer, "CIPid:\t%d\n", vxi->vx_initpid);
22060 +
22061 +       put_vx_info(vxi);
22062 +out:
22063 +       return buffer - orig;
22064 +}
22065 +
22066 +
22067 +int proc_pid_nx_info(struct task_struct *p, char *buffer)
22068 +{
22069 +       struct nx_info *nxi;
22070 +       struct nx_addr_v4 *v4a;
22071 +#ifdef CONFIG_IPV6
22072 +       struct nx_addr_v6 *v6a;
22073 +#endif
22074 +       char *orig = buffer;
22075 +       int i;
22076 +
22077 +       buffer += sprintf(buffer, "NID:\t%d\n", nx_task_nid(p));
22078 +
22079 +       nxi = task_get_nx_info(p);
22080 +       if (!nxi)
22081 +               goto out;
22082 +
22083 +       buffer += sprintf(buffer, "NCaps:\t%016llx\n",
22084 +               (unsigned long long)nxi->nx_ncaps);
22085 +       buffer += sprintf(buffer, "NFlags:\t%016llx\n",
22086 +               (unsigned long long)nxi->nx_flags);
22087 +
22088 +       buffer += sprintf(buffer,
22089 +               "V4Root[bcast]:\t" NIPQUAD_FMT "\n",
22090 +               NIPQUAD(nxi->v4_bcast.s_addr));
22091 +       buffer += sprintf (buffer,
22092 +               "V4Root[lback]:\t" NIPQUAD_FMT "\n",
22093 +               NIPQUAD(nxi->v4_lback.s_addr));
22094 +       if (!NX_IPV4(nxi))
22095 +               goto skip_v4;
22096 +       for (i = 0, v4a = &nxi->v4; v4a; i++, v4a = v4a->next)
22097 +               buffer += sprintf(buffer, "V4Root[%d]:\t" NXAV4_FMT "\n",
22098 +                       i, NXAV4(v4a));
22099 +skip_v4:
22100 +#ifdef CONFIG_IPV6
22101 +       if (!NX_IPV6(nxi))
22102 +               goto skip_v6;
22103 +       for (i = 0, v6a = &nxi->v6; v6a; i++, v6a = v6a->next)
22104 +               buffer += sprintf(buffer, "V6Root[%d]:\t" NXAV6_FMT "\n",
22105 +                       i, NXAV6(v6a));
22106 +skip_v6:
22107 +#endif
22108 +       put_nx_info(nxi);
22109 +out:
22110 +       return buffer - orig;
22111 +}
22112 +
22113 diff -NurpP --minimal linux-3.6.9/kernel/vserver/sched.c linux-3.6.9-vs2.3.4.4/kernel/vserver/sched.c
22114 --- linux-3.6.9/kernel/vserver/sched.c  1970-01-01 01:00:00.000000000 +0100
22115 +++ linux-3.6.9-vs2.3.4.4/kernel/vserver/sched.c        2012-10-04 18:47:00.000000000 +0200
22116 @@ -0,0 +1,83 @@
22117 +/*
22118 + *  linux/kernel/vserver/sched.c
22119 + *
22120 + *  Virtual Server: Scheduler Support
22121 + *
22122 + *  Copyright (C) 2004-2010  Herbert Pötzl
22123 + *
22124 + *  V0.01  adapted Sam Vilains version to 2.6.3
22125 + *  V0.02  removed legacy interface
22126 + *  V0.03  changed vcmds to vxi arg
22127 + *  V0.04  removed older and legacy interfaces
22128 + *  V0.05  removed scheduler code/commands
22129 + *
22130 + */
22131 +
22132 +#include <linux/vs_context.h>
22133 +#include <linux/vs_sched.h>
22134 +#include <linux/cpumask.h>
22135 +#include <linux/vserver/sched_cmd.h>
22136 +
22137 +#include <asm/uaccess.h>
22138 +
22139 +
22140 +void vx_update_sched_param(struct _vx_sched *sched,
22141 +       struct _vx_sched_pc *sched_pc)
22142 +{
22143 +       sched_pc->prio_bias = sched->prio_bias;
22144 +}
22145 +
22146 +static int do_set_prio_bias(struct vx_info *vxi, struct vcmd_prio_bias *data)
22147 +{
22148 +       int cpu;
22149 +
22150 +       if (data->prio_bias > MAX_PRIO_BIAS)
22151 +               data->prio_bias = MAX_PRIO_BIAS;
22152 +       if (data->prio_bias < MIN_PRIO_BIAS)
22153 +               data->prio_bias = MIN_PRIO_BIAS;
22154 +
22155 +       if (data->cpu_id != ~0) {
22156 +               vxi->sched.update = cpumask_of_cpu(data->cpu_id);
22157 +               cpumask_and(&vxi->sched.update, &vxi->sched.update,
22158 +                       cpu_online_mask);
22159 +       } else
22160 +               cpumask_copy(&vxi->sched.update, cpu_online_mask);
22161 +
22162 +       for_each_cpu_mask(cpu, vxi->sched.update)
22163 +               vx_update_sched_param(&vxi->sched,
22164 +                       &vx_per_cpu(vxi, sched_pc, cpu));
22165 +       return 0;
22166 +}
22167 +
22168 +int vc_set_prio_bias(struct vx_info *vxi, void __user *data)
22169 +{
22170 +       struct vcmd_prio_bias vc_data;
22171 +
22172 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
22173 +               return -EFAULT;
22174 +
22175 +       return do_set_prio_bias(vxi, &vc_data);
22176 +}
22177 +
22178 +int vc_get_prio_bias(struct vx_info *vxi, void __user *data)
22179 +{
22180 +       struct vcmd_prio_bias vc_data;
22181 +       struct _vx_sched_pc *pcd;
22182 +       int cpu;
22183 +
22184 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
22185 +               return -EFAULT;
22186 +
22187 +       cpu = vc_data.cpu_id;
22188 +
22189 +       if (!cpu_possible(cpu))
22190 +               return -EINVAL;
22191 +
22192 +       pcd = &vx_per_cpu(vxi, sched_pc, cpu);
22193 +       vc_data.prio_bias = pcd->prio_bias;
22194 +
22195 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
22196 +               return -EFAULT;
22197 +       return 0;
22198 +}
22199 +
22200 diff -NurpP --minimal linux-3.6.9/kernel/vserver/sched_init.h linux-3.6.9-vs2.3.4.4/kernel/vserver/sched_init.h
22201 --- linux-3.6.9/kernel/vserver/sched_init.h     1970-01-01 01:00:00.000000000 +0100
22202 +++ linux-3.6.9-vs2.3.4.4/kernel/vserver/sched_init.h   2012-10-04 18:47:00.000000000 +0200
22203 @@ -0,0 +1,27 @@
22204 +
22205 +static inline void vx_info_init_sched(struct _vx_sched *sched)
22206 +{
22207 +       /* scheduling; hard code starting values as constants */
22208 +       sched->prio_bias = 0;
22209 +}
22210 +
22211 +static inline
22212 +void vx_info_init_sched_pc(struct _vx_sched_pc *sched_pc, int cpu)
22213 +{
22214 +       sched_pc->prio_bias = 0;
22215 +
22216 +       sched_pc->user_ticks = 0;
22217 +       sched_pc->sys_ticks = 0;
22218 +       sched_pc->hold_ticks = 0;
22219 +}
22220 +
22221 +static inline void vx_info_exit_sched(struct _vx_sched *sched)
22222 +{
22223 +       return;
22224 +}
22225 +
22226 +static inline
22227 +void vx_info_exit_sched_pc(struct _vx_sched_pc *sched_pc, int cpu)
22228 +{
22229 +       return;
22230 +}
22231 diff -NurpP --minimal linux-3.6.9/kernel/vserver/sched_proc.h linux-3.6.9-vs2.3.4.4/kernel/vserver/sched_proc.h
22232 --- linux-3.6.9/kernel/vserver/sched_proc.h     1970-01-01 01:00:00.000000000 +0100
22233 +++ linux-3.6.9-vs2.3.4.4/kernel/vserver/sched_proc.h   2012-10-04 18:47:00.000000000 +0200
22234 @@ -0,0 +1,32 @@
22235 +#ifndef _VX_SCHED_PROC_H
22236 +#define _VX_SCHED_PROC_H
22237 +
22238 +
22239 +static inline
22240 +int vx_info_proc_sched(struct _vx_sched *sched, char *buffer)
22241 +{
22242 +       int length = 0;
22243 +
22244 +       length += sprintf(buffer,
22245 +               "PrioBias:\t%8d\n",
22246 +               sched->prio_bias);
22247 +       return length;
22248 +}
22249 +
22250 +static inline
22251 +int vx_info_proc_sched_pc(struct _vx_sched_pc *sched_pc,
22252 +       char *buffer, int cpu)
22253 +{
22254 +       int length = 0;
22255 +
22256 +       length += sprintf(buffer + length,
22257 +               "cpu %d: %lld %lld %lld", cpu,
22258 +               (unsigned long long)sched_pc->user_ticks,
22259 +               (unsigned long long)sched_pc->sys_ticks,
22260 +               (unsigned long long)sched_pc->hold_ticks);
22261 +       length += sprintf(buffer + length,
22262 +               " %d\n", sched_pc->prio_bias);
22263 +       return length;
22264 +}
22265 +
22266 +#endif /* _VX_SCHED_PROC_H */
22267 diff -NurpP --minimal linux-3.6.9/kernel/vserver/signal.c linux-3.6.9-vs2.3.4.4/kernel/vserver/signal.c
22268 --- linux-3.6.9/kernel/vserver/signal.c 1970-01-01 01:00:00.000000000 +0100
22269 +++ linux-3.6.9-vs2.3.4.4/kernel/vserver/signal.c       2012-10-04 18:47:00.000000000 +0200
22270 @@ -0,0 +1,134 @@
22271 +/*
22272 + *  linux/kernel/vserver/signal.c
22273 + *
22274 + *  Virtual Server: Signal Support
22275 + *
22276 + *  Copyright (C) 2003-2007  Herbert Pötzl
22277 + *
22278 + *  V0.01  broken out from vcontext V0.05
22279 + *  V0.02  changed vcmds to vxi arg
22280 + *  V0.03  adjusted siginfo for kill
22281 + *
22282 + */
22283 +
22284 +#include <asm/uaccess.h>
22285 +
22286 +#include <linux/vs_context.h>
22287 +#include <linux/vs_pid.h>
22288 +#include <linux/vserver/signal_cmd.h>
22289 +
22290 +
22291 +int vx_info_kill(struct vx_info *vxi, int pid, int sig)
22292 +{
22293 +       int retval, count = 0;
22294 +       struct task_struct *p;
22295 +       struct siginfo *sip = SEND_SIG_PRIV;
22296 +
22297 +       retval = -ESRCH;
22298 +       vxdprintk(VXD_CBIT(misc, 4),
22299 +               "vx_info_kill(%p[#%d],%d,%d)*",
22300 +               vxi, vxi->vx_id, pid, sig);
22301 +       read_lock(&tasklist_lock);
22302 +       switch (pid) {
22303 +       case  0:
22304 +       case -1:
22305 +               for_each_process(p) {
22306 +                       int err = 0;
22307 +
22308 +                       if (vx_task_xid(p) != vxi->vx_id || p->pid <= 1 ||
22309 +                               (pid && vxi->vx_initpid == p->pid))
22310 +                               continue;
22311 +
22312 +                       err = group_send_sig_info(sig, sip, p);
22313 +                       ++count;
22314 +                       if (err != -EPERM)
22315 +                               retval = err;
22316 +               }
22317 +               break;
22318 +
22319 +       case 1:
22320 +               if (vxi->vx_initpid) {
22321 +                       pid = vxi->vx_initpid;
22322 +                       /* for now, only SIGINT to private init ... */
22323 +                       if (!vx_info_flags(vxi, VXF_STATE_ADMIN, 0) &&
22324 +                               /* ... as long as there are tasks left */
22325 +                               (atomic_read(&vxi->vx_tasks) > 1))
22326 +                               sig = SIGINT;
22327 +               }
22328 +               /* fallthrough */
22329 +       default:
22330 +               rcu_read_lock();
22331 +               p = find_task_by_real_pid(pid);
22332 +               rcu_read_unlock();
22333 +               if (p) {
22334 +                       if (vx_task_xid(p) == vxi->vx_id)
22335 +                               retval = group_send_sig_info(sig, sip, p);
22336 +               }
22337 +               break;
22338 +       }
22339 +       read_unlock(&tasklist_lock);
22340 +       vxdprintk(VXD_CBIT(misc, 4),
22341 +               "vx_info_kill(%p[#%d],%d,%d,%ld) = %d",
22342 +               vxi, vxi->vx_id, pid, sig, (long)sip, retval);
22343 +       return retval;
22344 +}
22345 +
22346 +int vc_ctx_kill(struct vx_info *vxi, void __user *data)
22347 +{
22348 +       struct vcmd_ctx_kill_v0 vc_data;
22349 +
22350 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
22351 +               return -EFAULT;
22352 +
22353 +       /* special check to allow guest shutdown */
22354 +       if (!vx_info_flags(vxi, VXF_STATE_ADMIN, 0) &&
22355 +               /* forbid killall pid=0 when init is present */
22356 +               (((vc_data.pid < 1) && vxi->vx_initpid) ||
22357 +               (vc_data.pid > 1)))
22358 +               return -EACCES;
22359 +
22360 +       return vx_info_kill(vxi, vc_data.pid, vc_data.sig);
22361 +}
22362 +
22363 +
22364 +static int __wait_exit(struct vx_info *vxi)
22365 +{
22366 +       DECLARE_WAITQUEUE(wait, current);
22367 +       int ret = 0;
22368 +
22369 +       add_wait_queue(&vxi->vx_wait, &wait);
22370 +       set_current_state(TASK_INTERRUPTIBLE);
22371 +
22372 +wait:
22373 +       if (vx_info_state(vxi,
22374 +               VXS_SHUTDOWN | VXS_HASHED | VXS_HELPER) == VXS_SHUTDOWN)
22375 +               goto out;
22376 +       if (signal_pending(current)) {
22377 +               ret = -ERESTARTSYS;
22378 +               goto out;
22379 +       }
22380 +       schedule();
22381 +       goto wait;
22382 +
22383 +out:
22384 +       set_current_state(TASK_RUNNING);
22385 +       remove_wait_queue(&vxi->vx_wait, &wait);
22386 +       return ret;
22387 +}
22388 +
22389 +
22390 +
22391 +int vc_wait_exit(struct vx_info *vxi, void __user *data)
22392 +{
22393 +       struct vcmd_wait_exit_v0 vc_data;
22394 +       int ret;
22395 +
22396 +       ret = __wait_exit(vxi);
22397 +       vc_data.reboot_cmd = vxi->reboot_cmd;
22398 +       vc_data.exit_code = vxi->exit_code;
22399 +
22400 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
22401 +               ret = -EFAULT;
22402 +       return ret;
22403 +}
22404 +
22405 diff -NurpP --minimal linux-3.6.9/kernel/vserver/space.c linux-3.6.9-vs2.3.4.4/kernel/vserver/space.c
22406 --- linux-3.6.9/kernel/vserver/space.c  1970-01-01 01:00:00.000000000 +0100
22407 +++ linux-3.6.9-vs2.3.4.4/kernel/vserver/space.c        2012-10-04 18:47:00.000000000 +0200
22408 @@ -0,0 +1,436 @@
22409 +/*
22410 + *  linux/kernel/vserver/space.c
22411 + *
22412 + *  Virtual Server: Context Space Support
22413 + *
22414 + *  Copyright (C) 2003-2010  Herbert Pötzl
22415 + *
22416 + *  V0.01  broken out from context.c 0.07
22417 + *  V0.02  added task locking for namespace
22418 + *  V0.03  broken out vx_enter_namespace
22419 + *  V0.04  added *space support and commands
22420 + *  V0.05  added credential support
22421 + *
22422 + */
22423 +
22424 +#include <linux/utsname.h>
22425 +#include <linux/nsproxy.h>
22426 +#include <linux/err.h>
22427 +#include <linux/fs_struct.h>
22428 +#include <linux/cred.h>
22429 +#include <asm/uaccess.h>
22430 +
22431 +#include <linux/vs_context.h>
22432 +#include <linux/vserver/space.h>
22433 +#include <linux/vserver/space_cmd.h>
22434 +
22435 +atomic_t vs_global_nsproxy     = ATOMIC_INIT(0);
22436 +atomic_t vs_global_fs          = ATOMIC_INIT(0);
22437 +atomic_t vs_global_mnt_ns      = ATOMIC_INIT(0);
22438 +atomic_t vs_global_uts_ns      = ATOMIC_INIT(0);
22439 +atomic_t vs_global_user_ns     = ATOMIC_INIT(0);
22440 +atomic_t vs_global_pid_ns      = ATOMIC_INIT(0);
22441 +
22442 +
22443 +/* namespace functions */
22444 +
22445 +#include <linux/mnt_namespace.h>
22446 +#include <linux/user_namespace.h>
22447 +#include <linux/pid_namespace.h>
22448 +#include <linux/ipc_namespace.h>
22449 +#include <net/net_namespace.h>
22450 +#include "../fs/mount.h"
22451 +
22452 +
22453 +static const struct vcmd_space_mask_v1 space_mask_v0 = {
22454 +       .mask = CLONE_FS |
22455 +               CLONE_NEWNS |
22456 +#ifdef CONFIG_UTS_NS
22457 +               CLONE_NEWUTS |
22458 +#endif
22459 +#ifdef CONFIG_IPC_NS
22460 +               CLONE_NEWIPC |
22461 +#endif
22462 +#ifdef CONFIG_USER_NS
22463 +               CLONE_NEWUSER |
22464 +#endif
22465 +               0
22466 +};
22467 +
22468 +static const struct vcmd_space_mask_v1 space_mask = {
22469 +       .mask = CLONE_FS |
22470 +               CLONE_NEWNS |
22471 +#ifdef CONFIG_UTS_NS
22472 +               CLONE_NEWUTS |
22473 +#endif
22474 +#ifdef CONFIG_IPC_NS
22475 +               CLONE_NEWIPC |
22476 +#endif
22477 +#ifdef CONFIG_USER_NS
22478 +               CLONE_NEWUSER |
22479 +#endif
22480 +#ifdef CONFIG_PID_NS
22481 +               CLONE_NEWPID |
22482 +#endif
22483 +#ifdef CONFIG_NET_NS
22484 +               CLONE_NEWNET |
22485 +#endif
22486 +               0
22487 +};
22488 +
22489 +static const struct vcmd_space_mask_v1 default_space_mask = {
22490 +       .mask = CLONE_FS |
22491 +               CLONE_NEWNS |
22492 +#ifdef CONFIG_UTS_NS
22493 +               CLONE_NEWUTS |
22494 +#endif
22495 +#ifdef CONFIG_IPC_NS
22496 +               CLONE_NEWIPC |
22497 +#endif
22498 +#ifdef CONFIG_USER_NS
22499 +               CLONE_NEWUSER |
22500 +#endif
22501 +#ifdef CONFIG_PID_NS
22502 +//             CLONE_NEWPID |
22503 +#endif
22504 +               0
22505 +};
22506 +
22507 +/*
22508 + *     build a new nsproxy mix
22509 + *      assumes that both proxies are 'const'
22510 + *     does not touch nsproxy refcounts
22511 + *     will hold a reference on the result.
22512 + */
22513 +
22514 +struct nsproxy *vs_mix_nsproxy(struct nsproxy *old_nsproxy,
22515 +       struct nsproxy *new_nsproxy, unsigned long mask)
22516 +{
22517 +       struct mnt_namespace *old_ns;
22518 +       struct uts_namespace *old_uts;
22519 +       struct ipc_namespace *old_ipc;
22520 +#ifdef CONFIG_PID_NS
22521 +       struct pid_namespace *old_pid;
22522 +#endif
22523 +#ifdef CONFIG_NET_NS
22524 +       struct net *old_net;
22525 +#endif
22526 +       struct nsproxy *nsproxy;
22527 +
22528 +       nsproxy = copy_nsproxy(old_nsproxy);
22529 +       if (!nsproxy)
22530 +               goto out;
22531 +
22532 +       if (mask & CLONE_NEWNS) {
22533 +               old_ns = nsproxy->mnt_ns;
22534 +               nsproxy->mnt_ns = new_nsproxy->mnt_ns;
22535 +               if (nsproxy->mnt_ns)
22536 +                       get_mnt_ns(nsproxy->mnt_ns);
22537 +       } else
22538 +               old_ns = NULL;
22539 +
22540 +       if (mask & CLONE_NEWUTS) {
22541 +               old_uts = nsproxy->uts_ns;
22542 +               nsproxy->uts_ns = new_nsproxy->uts_ns;
22543 +               if (nsproxy->uts_ns)
22544 +                       get_uts_ns(nsproxy->uts_ns);
22545 +       } else
22546 +               old_uts = NULL;
22547 +
22548 +       if (mask & CLONE_NEWIPC) {
22549 +               old_ipc = nsproxy->ipc_ns;
22550 +               nsproxy->ipc_ns = new_nsproxy->ipc_ns;
22551 +               if (nsproxy->ipc_ns)
22552 +                       get_ipc_ns(nsproxy->ipc_ns);
22553 +       } else
22554 +               old_ipc = NULL;
22555 +
22556 +#ifdef CONFIG_PID_NS
22557 +       if (mask & CLONE_NEWPID) {
22558 +               old_pid = nsproxy->pid_ns;
22559 +               nsproxy->pid_ns = new_nsproxy->pid_ns;
22560 +               if (nsproxy->pid_ns)
22561 +                       get_pid_ns(nsproxy->pid_ns);
22562 +       } else
22563 +               old_pid = NULL;
22564 +#endif
22565 +#ifdef CONFIG_NET_NS
22566 +       if (mask & CLONE_NEWNET) {
22567 +               old_net = nsproxy->net_ns;
22568 +               nsproxy->net_ns = new_nsproxy->net_ns;
22569 +               if (nsproxy->net_ns)
22570 +                       get_net(nsproxy->net_ns);
22571 +       } else
22572 +               old_net = NULL;
22573 +#endif
22574 +       if (old_ns)
22575 +               put_mnt_ns(old_ns);
22576 +       if (old_uts)
22577 +               put_uts_ns(old_uts);
22578 +       if (old_ipc)
22579 +               put_ipc_ns(old_ipc);
22580 +#ifdef CONFIG_PID_NS
22581 +       if (old_pid)
22582 +               put_pid_ns(old_pid);
22583 +#endif
22584 +#ifdef CONFIG_NET_NS
22585 +       if (old_net)
22586 +               put_net(old_net);
22587 +#endif
22588 +out:
22589 +       return nsproxy;
22590 +}
22591 +
22592 +
22593 +/*
22594 + *     merge two nsproxy structs into a new one.
22595 + *     will hold a reference on the result.
22596 + */
22597 +
22598 +static inline
22599 +struct nsproxy *__vs_merge_nsproxy(struct nsproxy *old,
22600 +       struct nsproxy *proxy, unsigned long mask)
22601 +{
22602 +       struct nsproxy null_proxy = { .mnt_ns = NULL };
22603 +
22604 +       if (!proxy)
22605 +               return NULL;
22606 +
22607 +       if (mask) {
22608 +               /* vs_mix_nsproxy returns with reference */
22609 +               return vs_mix_nsproxy(old ? old : &null_proxy,
22610 +                       proxy, mask);
22611 +       }
22612 +       get_nsproxy(proxy);
22613 +       return proxy;
22614 +}
22615 +
22616 +
22617 +int vx_enter_space(struct vx_info *vxi, unsigned long mask, unsigned index)
22618 +{
22619 +       struct nsproxy *proxy, *proxy_cur, *proxy_new;
22620 +       struct fs_struct *fs_cur, *fs = NULL;
22621 +       struct _vx_space *space;
22622 +       int ret, kill = 0;
22623 +
22624 +       vxdprintk(VXD_CBIT(space, 8), "vx_enter_space(%p[#%u],0x%08lx,%d)",
22625 +               vxi, vxi->vx_id, mask, index);
22626 +
22627 +       if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0))
22628 +               return -EACCES;
22629 +
22630 +       if (index >= VX_SPACES)
22631 +               return -EINVAL;
22632 +
22633 +       space = &vxi->space[index];
22634 +
22635 +       if (!mask)
22636 +               mask = space->vx_nsmask;
22637 +
22638 +       if ((mask & space->vx_nsmask) != mask)
22639 +               return -EINVAL;
22640 +
22641 +       if (mask & CLONE_FS) {
22642 +               fs = copy_fs_struct(space->vx_fs);
22643 +               if (!fs)
22644 +                       return -ENOMEM;
22645 +       }
22646 +       proxy = space->vx_nsproxy;
22647 +
22648 +       vxdprintk(VXD_CBIT(space, 9),
22649 +               "vx_enter_space(%p[#%u],0x%08lx,%d) -> (%p,%p)",
22650 +               vxi, vxi->vx_id, mask, index, proxy, fs);
22651 +
22652 +       task_lock(current);
22653 +       fs_cur = current->fs;
22654 +
22655 +       if (mask & CLONE_FS) {
22656 +               spin_lock(&fs_cur->lock);
22657 +               current->fs = fs;
22658 +               kill = !--fs_cur->users;
22659 +               spin_unlock(&fs_cur->lock);
22660 +       }
22661 +
22662 +       proxy_cur = current->nsproxy;
22663 +       get_nsproxy(proxy_cur);
22664 +       task_unlock(current);
22665 +
22666 +       if (kill)
22667 +               free_fs_struct(fs_cur);
22668 +
22669 +       proxy_new = __vs_merge_nsproxy(proxy_cur, proxy, mask);
22670 +       if (IS_ERR(proxy_new)) {
22671 +               ret = PTR_ERR(proxy_new);
22672 +               goto out_put;
22673 +       }
22674 +
22675 +       proxy_new = xchg(&current->nsproxy, proxy_new);
22676 +
22677 +       if (mask & CLONE_NEWUSER) {
22678 +               struct cred *cred;
22679 +
22680 +               vxdprintk(VXD_CBIT(space, 10),
22681 +                       "vx_enter_space(%p[#%u],%p) cred (%p,%p)",
22682 +                       vxi, vxi->vx_id, space->vx_cred,
22683 +                       current->real_cred, current->cred);
22684 +
22685 +               if (space->vx_cred) {
22686 +                       cred = __prepare_creds(space->vx_cred);
22687 +                       if (cred)
22688 +                               commit_creds(cred);
22689 +               }
22690 +       }
22691 +
22692 +       ret = 0;
22693 +
22694 +       if (proxy_new)
22695 +               put_nsproxy(proxy_new);
22696 +out_put:
22697 +       if (proxy_cur)
22698 +               put_nsproxy(proxy_cur);
22699 +       return ret;
22700 +}
22701 +
22702 +
22703 +int vx_set_space(struct vx_info *vxi, unsigned long mask, unsigned index)
22704 +{
22705 +       struct nsproxy *proxy_vxi, *proxy_cur, *proxy_new;
22706 +       struct fs_struct *fs_vxi, *fs;
22707 +       struct _vx_space *space;
22708 +       int ret, kill = 0;
22709 +
22710 +       vxdprintk(VXD_CBIT(space, 8), "vx_set_space(%p[#%u],0x%08lx,%d)",
22711 +               vxi, vxi->vx_id, mask, index);
22712 +
22713 +       if ((mask & space_mask.mask) != mask)
22714 +               return -EINVAL;
22715 +
22716 +       if (index >= VX_SPACES)
22717 +               return -EINVAL;
22718 +
22719 +       space = &vxi->space[index];
22720 +
22721 +       proxy_vxi = space->vx_nsproxy;
22722 +       fs_vxi = space->vx_fs;
22723 +
22724 +       if (mask & CLONE_FS) {
22725 +               fs = copy_fs_struct(current->fs);
22726 +               if (!fs)
22727 +                       return -ENOMEM;
22728 +       }
22729 +
22730 +       task_lock(current);
22731 +
22732 +       if (mask & CLONE_FS) {
22733 +               spin_lock(&fs_vxi->lock);
22734 +               space->vx_fs = fs;
22735 +               kill = !--fs_vxi->users;
22736 +               spin_unlock(&fs_vxi->lock);
22737 +       }
22738 +
22739 +       proxy_cur = current->nsproxy;
22740 +       get_nsproxy(proxy_cur);
22741 +       task_unlock(current);
22742 +
22743 +       if (kill)
22744 +               free_fs_struct(fs_vxi);
22745 +
22746 +       proxy_new = __vs_merge_nsproxy(proxy_vxi, proxy_cur, mask);
22747 +       if (IS_ERR(proxy_new)) {
22748 +               ret = PTR_ERR(proxy_new);
22749 +               goto out_put;
22750 +       }
22751 +
22752 +       proxy_new = xchg(&space->vx_nsproxy, proxy_new);
22753 +       space->vx_nsmask |= mask;
22754 +
22755 +       if (mask & CLONE_NEWUSER) {
22756 +               struct cred *cred;
22757 +
22758 +               vxdprintk(VXD_CBIT(space, 10),
22759 +                       "vx_set_space(%p[#%u],%p) cred (%p,%p)",
22760 +                       vxi, vxi->vx_id, space->vx_cred,
22761 +                       current->real_cred, current->cred);
22762 +
22763 +               cred = prepare_creds();
22764 +               cred = (struct cred *)xchg(&space->vx_cred, cred);
22765 +               if (cred)
22766 +                       abort_creds(cred);
22767 +       }
22768 +
22769 +       ret = 0;
22770 +
22771 +       if (proxy_new)
22772 +               put_nsproxy(proxy_new);
22773 +out_put:
22774 +       if (proxy_cur)
22775 +               put_nsproxy(proxy_cur);
22776 +       return ret;
22777 +}
22778 +
22779 +
22780 +int vc_enter_space_v1(struct vx_info *vxi, void __user *data)
22781 +{
22782 +       struct vcmd_space_mask_v1 vc_data = { .mask = 0 };
22783 +
22784 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22785 +               return -EFAULT;
22786 +
22787 +       return vx_enter_space(vxi, vc_data.mask, 0);
22788 +}
22789 +
22790 +int vc_enter_space(struct vx_info *vxi, void __user *data)
22791 +{
22792 +       struct vcmd_space_mask_v2 vc_data = { .mask = 0 };
22793 +
22794 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22795 +               return -EFAULT;
22796 +
22797 +       if (vc_data.index >= VX_SPACES)
22798 +               return -EINVAL;
22799 +
22800 +       return vx_enter_space(vxi, vc_data.mask, vc_data.index);
22801 +}
22802 +
22803 +int vc_set_space_v1(struct vx_info *vxi, void __user *data)
22804 +{
22805 +       struct vcmd_space_mask_v1 vc_data = { .mask = 0 };
22806 +
22807 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22808 +               return -EFAULT;
22809 +
22810 +       return vx_set_space(vxi, vc_data.mask, 0);
22811 +}
22812 +
22813 +int vc_set_space(struct vx_info *vxi, void __user *data)
22814 +{
22815 +       struct vcmd_space_mask_v2 vc_data = { .mask = 0 };
22816 +
22817 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22818 +               return -EFAULT;
22819 +
22820 +       if (vc_data.index >= VX_SPACES)
22821 +               return -EINVAL;
22822 +
22823 +       return vx_set_space(vxi, vc_data.mask, vc_data.index);
22824 +}
22825 +
22826 +int vc_get_space_mask(void __user *data, int type)
22827 +{
22828 +       const struct vcmd_space_mask_v1 *mask;
22829 +
22830 +       if (type == 0)
22831 +               mask = &space_mask_v0;
22832 +       else if (type == 1)
22833 +               mask = &space_mask;
22834 +       else
22835 +               mask = &default_space_mask;
22836 +
22837 +       vxdprintk(VXD_CBIT(space, 10),
22838 +               "vc_get_space_mask(%d) = %08llx", type, mask->mask);
22839 +
22840 +       if (copy_to_user(data, mask, sizeof(*mask)))
22841 +               return -EFAULT;
22842 +       return 0;
22843 +}
22844 +
22845 diff -NurpP --minimal linux-3.6.9/kernel/vserver/switch.c linux-3.6.9-vs2.3.4.4/kernel/vserver/switch.c
22846 --- linux-3.6.9/kernel/vserver/switch.c 1970-01-01 01:00:00.000000000 +0100
22847 +++ linux-3.6.9-vs2.3.4.4/kernel/vserver/switch.c       2012-10-04 18:47:00.000000000 +0200
22848 @@ -0,0 +1,556 @@
22849 +/*
22850 + *  linux/kernel/vserver/switch.c
22851 + *
22852 + *  Virtual Server: Syscall Switch
22853 + *
22854 + *  Copyright (C) 2003-2011  Herbert Pötzl
22855 + *
22856 + *  V0.01  syscall switch
22857 + *  V0.02  added signal to context
22858 + *  V0.03  added rlimit functions
22859 + *  V0.04  added iattr, task/xid functions
22860 + *  V0.05  added debug/history stuff
22861 + *  V0.06  added compat32 layer
22862 + *  V0.07  vcmd args and perms
22863 + *  V0.08  added status commands
22864 + *  V0.09  added tag commands
22865 + *  V0.10  added oom bias
22866 + *  V0.11  added device commands
22867 + *  V0.12  added warn mask
22868 + *
22869 + */
22870 +
22871 +#include <linux/vs_context.h>
22872 +#include <linux/vs_network.h>
22873 +#include <linux/vserver/switch.h>
22874 +
22875 +#include "vci_config.h"
22876 +
22877 +
22878 +static inline
22879 +int vc_get_version(uint32_t id)
22880 +{
22881 +       return VCI_VERSION;
22882 +}
22883 +
22884 +static inline
22885 +int vc_get_vci(uint32_t id)
22886 +{
22887 +       return vci_kernel_config();
22888 +}
22889 +
22890 +#include <linux/vserver/context_cmd.h>
22891 +#include <linux/vserver/cvirt_cmd.h>
22892 +#include <linux/vserver/cacct_cmd.h>
22893 +#include <linux/vserver/limit_cmd.h>
22894 +#include <linux/vserver/network_cmd.h>
22895 +#include <linux/vserver/sched_cmd.h>
22896 +#include <linux/vserver/debug_cmd.h>
22897 +#include <linux/vserver/inode_cmd.h>
22898 +#include <linux/vserver/dlimit_cmd.h>
22899 +#include <linux/vserver/signal_cmd.h>
22900 +#include <linux/vserver/space_cmd.h>
22901 +#include <linux/vserver/tag_cmd.h>
22902 +#include <linux/vserver/device_cmd.h>
22903 +
22904 +#include <linux/vserver/inode.h>
22905 +#include <linux/vserver/dlimit.h>
22906 +
22907 +
22908 +#ifdef CONFIG_COMPAT
22909 +#define __COMPAT(name, id, data, compat)       \
22910 +       (compat) ? name ## _x32(id, data) : name(id, data)
22911 +#define __COMPAT_NO_ID(name, data, compat)     \
22912 +       (compat) ? name ## _x32(data) : name(data)
22913 +#else
22914 +#define __COMPAT(name, id, data, compat)       \
22915 +       name(id, data)
22916 +#define __COMPAT_NO_ID(name, data, compat)     \
22917 +       name(data)
22918 +#endif
22919 +
22920 +
22921 +static inline
22922 +long do_vcmd(uint32_t cmd, uint32_t id,
22923 +       struct vx_info *vxi, struct nx_info *nxi,
22924 +       void __user *data, int compat)
22925 +{
22926 +       switch (cmd) {
22927 +
22928 +       case VCMD_get_version:
22929 +               return vc_get_version(id);
22930 +       case VCMD_get_vci:
22931 +               return vc_get_vci(id);
22932 +
22933 +       case VCMD_task_xid:
22934 +               return vc_task_xid(id);
22935 +       case VCMD_vx_info:
22936 +               return vc_vx_info(vxi, data);
22937 +
22938 +       case VCMD_task_nid:
22939 +               return vc_task_nid(id);
22940 +       case VCMD_nx_info:
22941 +               return vc_nx_info(nxi, data);
22942 +
22943 +       case VCMD_task_tag:
22944 +               return vc_task_tag(id);
22945 +
22946 +       case VCMD_set_space_v1:
22947 +               return vc_set_space_v1(vxi, data);
22948 +       /* this is version 2 */
22949 +       case VCMD_set_space:
22950 +               return vc_set_space(vxi, data);
22951 +
22952 +       case VCMD_get_space_mask_v0:
22953 +               return vc_get_space_mask(data, 0);
22954 +       /* this is version 1 */
22955 +       case VCMD_get_space_mask:
22956 +               return vc_get_space_mask(data, 1);
22957 +
22958 +       case VCMD_get_space_default:
22959 +               return vc_get_space_mask(data, -1);
22960 +
22961 +       case VCMD_set_umask:
22962 +               return vc_set_umask(vxi, data);
22963 +
22964 +       case VCMD_get_umask:
22965 +               return vc_get_umask(vxi, data);
22966 +
22967 +       case VCMD_set_wmask:
22968 +               return vc_set_wmask(vxi, data);
22969 +
22970 +       case VCMD_get_wmask:
22971 +               return vc_get_wmask(vxi, data);
22972 +#ifdef CONFIG_IA32_EMULATION
22973 +       case VCMD_get_rlimit:
22974 +               return __COMPAT(vc_get_rlimit, vxi, data, compat);
22975 +       case VCMD_set_rlimit:
22976 +               return __COMPAT(vc_set_rlimit, vxi, data, compat);
22977 +#else
22978 +       case VCMD_get_rlimit:
22979 +               return vc_get_rlimit(vxi, data);
22980 +       case VCMD_set_rlimit:
22981 +               return vc_set_rlimit(vxi, data);
22982 +#endif
22983 +       case VCMD_get_rlimit_mask:
22984 +               return vc_get_rlimit_mask(id, data);
22985 +       case VCMD_reset_hits:
22986 +               return vc_reset_hits(vxi, data);
22987 +       case VCMD_reset_minmax:
22988 +               return vc_reset_minmax(vxi, data);
22989 +
22990 +       case VCMD_get_vhi_name:
22991 +               return vc_get_vhi_name(vxi, data);
22992 +       case VCMD_set_vhi_name:
22993 +               return vc_set_vhi_name(vxi, data);
22994 +
22995 +       case VCMD_ctx_stat:
22996 +               return vc_ctx_stat(vxi, data);
22997 +       case VCMD_virt_stat:
22998 +               return vc_virt_stat(vxi, data);
22999 +       case VCMD_sock_stat:
23000 +               return vc_sock_stat(vxi, data);
23001 +       case VCMD_rlimit_stat:
23002 +               return vc_rlimit_stat(vxi, data);
23003 +
23004 +       case VCMD_set_cflags:
23005 +               return vc_set_cflags(vxi, data);
23006 +       case VCMD_get_cflags:
23007 +               return vc_get_cflags(vxi, data);
23008 +
23009 +       /* this is version 1 */
23010 +       case VCMD_set_ccaps:
23011 +               return vc_set_ccaps(vxi, data);
23012 +       /* this is version 1 */
23013 +       case VCMD_get_ccaps:
23014 +               return vc_get_ccaps(vxi, data);
23015 +       case VCMD_set_bcaps:
23016 +               return vc_set_bcaps(vxi, data);
23017 +       case VCMD_get_bcaps:
23018 +               return vc_get_bcaps(vxi, data);
23019 +
23020 +       case VCMD_set_badness:
23021 +               return vc_set_badness(vxi, data);
23022 +       case VCMD_get_badness:
23023 +               return vc_get_badness(vxi, data);
23024 +
23025 +       case VCMD_set_nflags:
23026 +               return vc_set_nflags(nxi, data);
23027 +       case VCMD_get_nflags:
23028 +               return vc_get_nflags(nxi, data);
23029 +
23030 +       case VCMD_set_ncaps:
23031 +               return vc_set_ncaps(nxi, data);
23032 +       case VCMD_get_ncaps:
23033 +               return vc_get_ncaps(nxi, data);
23034 +
23035 +       case VCMD_set_prio_bias:
23036 +               return vc_set_prio_bias(vxi, data);
23037 +       case VCMD_get_prio_bias:
23038 +               return vc_get_prio_bias(vxi, data);
23039 +       case VCMD_add_dlimit:
23040 +               return __COMPAT(vc_add_dlimit, id, data, compat);
23041 +       case VCMD_rem_dlimit:
23042 +               return __COMPAT(vc_rem_dlimit, id, data, compat);
23043 +       case VCMD_set_dlimit:
23044 +               return __COMPAT(vc_set_dlimit, id, data, compat);
23045 +       case VCMD_get_dlimit:
23046 +               return __COMPAT(vc_get_dlimit, id, data, compat);
23047 +
23048 +       case VCMD_ctx_kill:
23049 +               return vc_ctx_kill(vxi, data);
23050 +
23051 +       case VCMD_wait_exit:
23052 +               return vc_wait_exit(vxi, data);
23053 +
23054 +       case VCMD_get_iattr:
23055 +               return __COMPAT_NO_ID(vc_get_iattr, data, compat);
23056 +       case VCMD_set_iattr:
23057 +               return __COMPAT_NO_ID(vc_set_iattr, data, compat);
23058 +
23059 +       case VCMD_fget_iattr:
23060 +               return vc_fget_iattr(id, data);
23061 +       case VCMD_fset_iattr:
23062 +               return vc_fset_iattr(id, data);
23063 +
23064 +       case VCMD_enter_space_v0:
23065 +               return vc_enter_space_v1(vxi, NULL);
23066 +       case VCMD_enter_space_v1:
23067 +               return vc_enter_space_v1(vxi, data);
23068 +       /* this is version 2 */
23069 +       case VCMD_enter_space:
23070 +               return vc_enter_space(vxi, data);
23071 +
23072 +       case VCMD_ctx_create_v0:
23073 +               return vc_ctx_create(id, NULL);
23074 +       case VCMD_ctx_create:
23075 +               return vc_ctx_create(id, data);
23076 +       case VCMD_ctx_migrate_v0:
23077 +               return vc_ctx_migrate(vxi, NULL);
23078 +       case VCMD_ctx_migrate:
23079 +               return vc_ctx_migrate(vxi, data);
23080 +
23081 +       case VCMD_net_create_v0:
23082 +               return vc_net_create(id, NULL);
23083 +       case VCMD_net_create:
23084 +               return vc_net_create(id, data);
23085 +       case VCMD_net_migrate:
23086 +               return vc_net_migrate(nxi, data);
23087 +
23088 +       case VCMD_tag_migrate:
23089 +               return vc_tag_migrate(id);
23090 +
23091 +       case VCMD_net_add:
23092 +               return vc_net_add(nxi, data);
23093 +       case VCMD_net_remove:
23094 +               return vc_net_remove(nxi, data);
23095 +
23096 +       case VCMD_net_add_ipv4_v1:
23097 +               return vc_net_add_ipv4_v1(nxi, data);
23098 +       /* this is version 2 */
23099 +       case VCMD_net_add_ipv4:
23100 +               return vc_net_add_ipv4(nxi, data);
23101 +
23102 +       case VCMD_net_rem_ipv4_v1:
23103 +               return vc_net_rem_ipv4_v1(nxi, data);
23104 +       /* this is version 2 */
23105 +       case VCMD_net_rem_ipv4:
23106 +               return vc_net_rem_ipv4(nxi, data);
23107 +#ifdef CONFIG_IPV6
23108 +       case VCMD_net_add_ipv6:
23109 +               return vc_net_add_ipv6(nxi, data);
23110 +       case VCMD_net_remove_ipv6:
23111 +               return vc_net_remove_ipv6(nxi, data);
23112 +#endif
23113 +/*     case VCMD_add_match_ipv4:
23114 +               return vc_add_match_ipv4(nxi, data);
23115 +       case VCMD_get_match_ipv4:
23116 +               return vc_get_match_ipv4(nxi, data);
23117 +#ifdef CONFIG_IPV6
23118 +       case VCMD_add_match_ipv6:
23119 +               return vc_add_match_ipv6(nxi, data);
23120 +       case VCMD_get_match_ipv6:
23121 +               return vc_get_match_ipv6(nxi, data);
23122 +#endif */
23123 +
23124 +#ifdef CONFIG_VSERVER_DEVICE
23125 +       case VCMD_set_mapping:
23126 +               return __COMPAT(vc_set_mapping, vxi, data, compat);
23127 +       case VCMD_unset_mapping:
23128 +               return __COMPAT(vc_unset_mapping, vxi, data, compat);
23129 +#endif
23130 +#ifdef CONFIG_VSERVER_HISTORY
23131 +       case VCMD_dump_history:
23132 +               return vc_dump_history(id);
23133 +       case VCMD_read_history:
23134 +               return __COMPAT(vc_read_history, id, data, compat);
23135 +#endif
23136 +       default:
23137 +               vxwprintk_task(1, "unimplemented VCMD_%02d_%d[%d]",
23138 +                       VC_CATEGORY(cmd), VC_COMMAND(cmd), VC_VERSION(cmd));
23139 +       }
23140 +       return -ENOSYS;
23141 +}
23142 +
23143 +
23144 +#define        __VCMD(vcmd, _perm, _args, _flags)              \
23145 +       case VCMD_ ## vcmd: perm = _perm;               \
23146 +               args = _args; flags = _flags; break
23147 +
23148 +
23149 +#define VCA_NONE       0x00
23150 +#define VCA_VXI                0x01
23151 +#define VCA_NXI                0x02
23152 +
23153 +#define VCF_NONE       0x00
23154 +#define VCF_INFO       0x01
23155 +#define VCF_ADMIN      0x02
23156 +#define VCF_ARES       0x06    /* includes admin */
23157 +#define VCF_SETUP      0x08
23158 +
23159 +#define VCF_ZIDOK      0x10    /* zero id okay */
23160 +
23161 +
23162 +static inline
23163 +long do_vserver(uint32_t cmd, uint32_t id, void __user *data, int compat)
23164 +{
23165 +       long ret;
23166 +       int permit = -1, state = 0;
23167 +       int perm = -1, args = 0, flags = 0;
23168 +       struct vx_info *vxi = NULL;
23169 +       struct nx_info *nxi = NULL;
23170 +
23171 +       switch (cmd) {
23172 +       /* unpriviledged commands */
23173 +       __VCMD(get_version,      0, VCA_NONE,   0);
23174 +       __VCMD(get_vci,          0, VCA_NONE,   0);
23175 +       __VCMD(get_rlimit_mask,  0, VCA_NONE,   0);
23176 +       __VCMD(get_space_mask_v0,0, VCA_NONE,   0);
23177 +       __VCMD(get_space_mask,   0, VCA_NONE,   0);
23178 +       __VCMD(get_space_default,0, VCA_NONE,   0);
23179 +
23180 +       /* info commands */
23181 +       __VCMD(task_xid,         2, VCA_NONE,   0);
23182 +       __VCMD(reset_hits,       2, VCA_VXI,    0);
23183 +       __VCMD(reset_minmax,     2, VCA_VXI,    0);
23184 +       __VCMD(vx_info,          3, VCA_VXI,    VCF_INFO);
23185 +       __VCMD(get_bcaps,        3, VCA_VXI,    VCF_INFO);
23186 +       __VCMD(get_ccaps,        3, VCA_VXI,    VCF_INFO);
23187 +       __VCMD(get_cflags,       3, VCA_VXI,    VCF_INFO);
23188 +       __VCMD(get_umask,        3, VCA_VXI,    VCF_INFO);
23189 +       __VCMD(get_wmask,        3, VCA_VXI,    VCF_INFO);
23190 +       __VCMD(get_badness,      3, VCA_VXI,    VCF_INFO);
23191 +       __VCMD(get_vhi_name,     3, VCA_VXI,    VCF_INFO);
23192 +       __VCMD(get_rlimit,       3, VCA_VXI,    VCF_INFO);
23193 +
23194 +       __VCMD(ctx_stat,         3, VCA_VXI,    VCF_INFO);
23195 +       __VCMD(virt_stat,        3, VCA_VXI,    VCF_INFO);
23196 +       __VCMD(sock_stat,        3, VCA_VXI,    VCF_INFO);
23197 +       __VCMD(rlimit_stat,      3, VCA_VXI,    VCF_INFO);
23198 +
23199 +       __VCMD(task_nid,         2, VCA_NONE,   0);
23200 +       __VCMD(nx_info,          3, VCA_NXI,    VCF_INFO);
23201 +       __VCMD(get_ncaps,        3, VCA_NXI,    VCF_INFO);
23202 +       __VCMD(get_nflags,       3, VCA_NXI,    VCF_INFO);
23203 +
23204 +       __VCMD(task_tag,         2, VCA_NONE,   0);
23205 +
23206 +       __VCMD(get_iattr,        2, VCA_NONE,   0);
23207 +       __VCMD(fget_iattr,       2, VCA_NONE,   0);
23208 +       __VCMD(get_dlimit,       3, VCA_NONE,   VCF_INFO);
23209 +       __VCMD(get_prio_bias,    3, VCA_VXI,    VCF_INFO);
23210 +
23211 +       /* lower admin commands */
23212 +       __VCMD(wait_exit,        4, VCA_VXI,    VCF_INFO);
23213 +       __VCMD(ctx_create_v0,    5, VCA_NONE,   0);
23214 +       __VCMD(ctx_create,       5, VCA_NONE,   0);
23215 +       __VCMD(ctx_migrate_v0,   5, VCA_VXI,    VCF_ADMIN);
23216 +       __VCMD(ctx_migrate,      5, VCA_VXI,    VCF_ADMIN);
23217 +       __VCMD(enter_space_v0,   5, VCA_VXI,    VCF_ADMIN);
23218 +       __VCMD(enter_space_v1,   5, VCA_VXI,    VCF_ADMIN);
23219 +       __VCMD(enter_space,      5, VCA_VXI,    VCF_ADMIN);
23220 +
23221 +       __VCMD(net_create_v0,    5, VCA_NONE,   0);
23222 +       __VCMD(net_create,       5, VCA_NONE,   0);
23223 +       __VCMD(net_migrate,      5, VCA_NXI,    VCF_ADMIN);
23224 +
23225 +       __VCMD(tag_migrate,      5, VCA_NONE,   VCF_ADMIN);
23226 +
23227 +       /* higher admin commands */
23228 +       __VCMD(ctx_kill,         6, VCA_VXI,    VCF_ARES);
23229 +       __VCMD(set_space_v1,     7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23230 +       __VCMD(set_space,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23231 +
23232 +       __VCMD(set_ccaps,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23233 +       __VCMD(set_bcaps,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23234 +       __VCMD(set_cflags,       7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23235 +       __VCMD(set_umask,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23236 +       __VCMD(set_wmask,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23237 +       __VCMD(set_badness,      7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23238 +
23239 +       __VCMD(set_vhi_name,     7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23240 +       __VCMD(set_rlimit,       7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23241 +       __VCMD(set_prio_bias,    7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23242 +
23243 +       __VCMD(set_ncaps,        7, VCA_NXI,    VCF_ARES | VCF_SETUP);
23244 +       __VCMD(set_nflags,       7, VCA_NXI,    VCF_ARES | VCF_SETUP);
23245 +       __VCMD(net_add,          8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23246 +       __VCMD(net_remove,       8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23247 +       __VCMD(net_add_ipv4_v1,  8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23248 +       __VCMD(net_rem_ipv4_v1,  8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23249 +       __VCMD(net_add_ipv4,     8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23250 +       __VCMD(net_rem_ipv4,     8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23251 +#ifdef CONFIG_IPV6
23252 +       __VCMD(net_add_ipv6,     8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23253 +       __VCMD(net_remove_ipv6,  8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23254 +#endif
23255 +       __VCMD(set_iattr,        7, VCA_NONE,   0);
23256 +       __VCMD(fset_iattr,       7, VCA_NONE,   0);
23257 +       __VCMD(set_dlimit,       7, VCA_NONE,   VCF_ARES);
23258 +       __VCMD(add_dlimit,       8, VCA_NONE,   VCF_ARES);
23259 +       __VCMD(rem_dlimit,       8, VCA_NONE,   VCF_ARES);
23260 +
23261 +#ifdef CONFIG_VSERVER_DEVICE
23262 +       __VCMD(set_mapping,      8, VCA_VXI,    VCF_ARES|VCF_ZIDOK);
23263 +       __VCMD(unset_mapping,    8, VCA_VXI,    VCF_ARES|VCF_ZIDOK);
23264 +#endif
23265 +       /* debug level admin commands */
23266 +#ifdef CONFIG_VSERVER_HISTORY
23267 +       __VCMD(dump_history,     9, VCA_NONE,   0);
23268 +       __VCMD(read_history,     9, VCA_NONE,   0);
23269 +#endif
23270 +
23271 +       default:
23272 +               perm = -1;
23273 +       }
23274 +
23275 +       vxdprintk(VXD_CBIT(switch, 0),
23276 +               "vc: VCMD_%02d_%d[%d], %d,%p [%d,%d,%x,%x]",
23277 +               VC_CATEGORY(cmd), VC_COMMAND(cmd),
23278 +               VC_VERSION(cmd), id, data, compat,
23279 +               perm, args, flags);
23280 +
23281 +       ret = -ENOSYS;
23282 +       if (perm < 0)
23283 +               goto out;
23284 +
23285 +       state = 1;
23286 +       if (!capable(CAP_CONTEXT))
23287 +               goto out;
23288 +
23289 +       state = 2;
23290 +       /* moved here from the individual commands */
23291 +       ret = -EPERM;
23292 +       if ((perm > 1) && !capable(CAP_SYS_ADMIN))
23293 +               goto out;
23294 +
23295 +       state = 3;
23296 +       /* vcmd involves resource management  */
23297 +       ret = -EPERM;
23298 +       if ((flags & VCF_ARES) && !capable(CAP_SYS_RESOURCE))
23299 +               goto out;
23300 +
23301 +       state = 4;
23302 +       /* various legacy exceptions */
23303 +       switch (cmd) {
23304 +       /* will go away when spectator is a cap */
23305 +       case VCMD_ctx_migrate_v0:
23306 +       case VCMD_ctx_migrate:
23307 +               if (id == 1) {
23308 +                       current->xid = 1;
23309 +                       ret = 1;
23310 +                       goto out;
23311 +               }
23312 +               break;
23313 +
23314 +       /* will go away when spectator is a cap */
23315 +       case VCMD_net_migrate:
23316 +               if (id == 1) {
23317 +                       current->nid = 1;
23318 +                       ret = 1;
23319 +                       goto out;
23320 +               }
23321 +               break;
23322 +       }
23323 +
23324 +       /* vcmds are fine by default */
23325 +       permit = 1;
23326 +
23327 +       /* admin type vcmds require admin ... */
23328 +       if (flags & VCF_ADMIN)
23329 +               permit = vx_check(0, VS_ADMIN) ? 1 : 0;
23330 +
23331 +       /* ... but setup type vcmds override that */
23332 +       if (!permit && (flags & VCF_SETUP))
23333 +               permit = vx_flags(VXF_STATE_SETUP, 0) ? 2 : 0;
23334 +
23335 +       state = 5;
23336 +       ret = -EPERM;
23337 +       if (!permit)
23338 +               goto out;
23339 +
23340 +       state = 6;
23341 +       if (!id && (flags & VCF_ZIDOK))
23342 +               goto skip_id;
23343 +
23344 +       ret = -ESRCH;
23345 +       if (args & VCA_VXI) {
23346 +               vxi = lookup_vx_info(id);
23347 +               if (!vxi)
23348 +                       goto out;
23349 +
23350 +               if ((flags & VCF_ADMIN) &&
23351 +                       /* special case kill for shutdown */
23352 +                       (cmd != VCMD_ctx_kill) &&
23353 +                       /* can context be administrated? */
23354 +                       !vx_info_flags(vxi, VXF_STATE_ADMIN, 0)) {
23355 +                       ret = -EACCES;
23356 +                       goto out_vxi;
23357 +               }
23358 +       }
23359 +       state = 7;
23360 +       if (args & VCA_NXI) {
23361 +               nxi = lookup_nx_info(id);
23362 +               if (!nxi)
23363 +                       goto out_vxi;
23364 +
23365 +               if ((flags & VCF_ADMIN) &&
23366 +                       /* can context be administrated? */
23367 +                       !nx_info_flags(nxi, NXF_STATE_ADMIN, 0)) {
23368 +                       ret = -EACCES;
23369 +                       goto out_nxi;
23370 +               }
23371 +       }
23372 +skip_id:
23373 +       state = 8;
23374 +       ret = do_vcmd(cmd, id, vxi, nxi, data, compat);
23375 +
23376 +out_nxi:
23377 +       if ((args & VCA_NXI) && nxi)
23378 +               put_nx_info(nxi);
23379 +out_vxi:
23380 +       if ((args & VCA_VXI) && vxi)
23381 +               put_vx_info(vxi);
23382 +out:
23383 +       vxdprintk(VXD_CBIT(switch, 1),
23384 +               "vc: VCMD_%02d_%d[%d] = %08lx(%ld) [%d,%d]",
23385 +               VC_CATEGORY(cmd), VC_COMMAND(cmd),
23386 +               VC_VERSION(cmd), ret, ret, state, permit);
23387 +       return ret;
23388 +}
23389 +
23390 +asmlinkage long
23391 +sys_vserver(uint32_t cmd, uint32_t id, void __user *data)
23392 +{
23393 +       return do_vserver(cmd, id, data, 0);
23394 +}
23395 +
23396 +#ifdef CONFIG_COMPAT
23397 +
23398 +asmlinkage long
23399 +sys32_vserver(uint32_t cmd, uint32_t id, void __user *data)
23400 +{
23401 +       return do_vserver(cmd, id, data, 1);
23402 +}
23403 +
23404 +#endif /* CONFIG_COMPAT */
23405 diff -NurpP --minimal linux-3.6.9/kernel/vserver/sysctl.c linux-3.6.9-vs2.3.4.4/kernel/vserver/sysctl.c
23406 --- linux-3.6.9/kernel/vserver/sysctl.c 1970-01-01 01:00:00.000000000 +0100
23407 +++ linux-3.6.9-vs2.3.4.4/kernel/vserver/sysctl.c       2012-10-04 18:47:00.000000000 +0200
23408 @@ -0,0 +1,247 @@
23409 +/*
23410 + *  kernel/vserver/sysctl.c
23411 + *
23412 + *  Virtual Context Support
23413 + *
23414 + *  Copyright (C) 2004-2007  Herbert Pötzl
23415 + *
23416 + *  V0.01  basic structure
23417 + *
23418 + */
23419 +
23420 +#include <linux/module.h>
23421 +#include <linux/ctype.h>
23422 +#include <linux/sysctl.h>
23423 +#include <linux/parser.h>
23424 +#include <asm/uaccess.h>
23425 +
23426 +enum {
23427 +       CTL_DEBUG_ERROR         = 0,
23428 +       CTL_DEBUG_SWITCH        = 1,
23429 +       CTL_DEBUG_XID,
23430 +       CTL_DEBUG_NID,
23431 +       CTL_DEBUG_TAG,
23432 +       CTL_DEBUG_NET,
23433 +       CTL_DEBUG_LIMIT,
23434 +       CTL_DEBUG_CRES,
23435 +       CTL_DEBUG_DLIM,
23436 +       CTL_DEBUG_QUOTA,
23437 +       CTL_DEBUG_CVIRT,
23438 +       CTL_DEBUG_SPACE,
23439 +       CTL_DEBUG_PERM,
23440 +       CTL_DEBUG_MISC,
23441 +};
23442 +
23443 +
23444 +unsigned int vs_debug_switch   = 0;
23445 +unsigned int vs_debug_xid      = 0;
23446 +unsigned int vs_debug_nid      = 0;
23447 +unsigned int vs_debug_tag      = 0;
23448 +unsigned int vs_debug_net      = 0;
23449 +unsigned int vs_debug_limit    = 0;
23450 +unsigned int vs_debug_cres     = 0;
23451 +unsigned int vs_debug_dlim     = 0;
23452 +unsigned int vs_debug_quota    = 0;
23453 +unsigned int vs_debug_cvirt    = 0;
23454 +unsigned int vs_debug_space    = 0;
23455 +unsigned int vs_debug_perm     = 0;
23456 +unsigned int vs_debug_misc     = 0;
23457 +
23458 +
23459 +static struct ctl_table_header *vserver_table_header;
23460 +static ctl_table vserver_root_table[];
23461 +
23462 +
23463 +void vserver_register_sysctl(void)
23464 +{
23465 +       if (!vserver_table_header) {
23466 +               vserver_table_header = register_sysctl_table(vserver_root_table);
23467 +       }
23468 +
23469 +}
23470 +
23471 +void vserver_unregister_sysctl(void)
23472 +{
23473 +       if (vserver_table_header) {
23474 +               unregister_sysctl_table(vserver_table_header);
23475 +               vserver_table_header = NULL;
23476 +       }
23477 +}
23478 +
23479 +
23480 +static int proc_dodebug(ctl_table *table, int write,
23481 +       void __user *buffer, size_t *lenp, loff_t *ppos)
23482 +{
23483 +       char            tmpbuf[20], *p, c;
23484 +       unsigned int    value;
23485 +       size_t          left, len;
23486 +
23487 +       if ((*ppos && !write) || !*lenp) {
23488 +               *lenp = 0;
23489 +               return 0;
23490 +       }
23491 +
23492 +       left = *lenp;
23493 +
23494 +       if (write) {
23495 +               if (!access_ok(VERIFY_READ, buffer, left))
23496 +                       return -EFAULT;
23497 +               p = (char *)buffer;
23498 +               while (left && __get_user(c, p) >= 0 && isspace(c))
23499 +                       left--, p++;
23500 +               if (!left)
23501 +                       goto done;
23502 +
23503 +               if (left > sizeof(tmpbuf) - 1)
23504 +                       return -EINVAL;
23505 +               if (copy_from_user(tmpbuf, p, left))
23506 +                       return -EFAULT;
23507 +               tmpbuf[left] = '\0';
23508 +
23509 +               for (p = tmpbuf, value = 0; '0' <= *p && *p <= '9'; p++, left--)
23510 +                       value = 10 * value + (*p - '0');
23511 +               if (*p && !isspace(*p))
23512 +                       return -EINVAL;
23513 +               while (left && isspace(*p))
23514 +                       left--, p++;
23515 +               *(unsigned int *)table->data = value;
23516 +       } else {
23517 +               if (!access_ok(VERIFY_WRITE, buffer, left))
23518 +                       return -EFAULT;
23519 +               len = sprintf(tmpbuf, "%d", *(unsigned int *)table->data);
23520 +               if (len > left)
23521 +                       len = left;
23522 +               if (__copy_to_user(buffer, tmpbuf, len))
23523 +                       return -EFAULT;
23524 +               if ((left -= len) > 0) {
23525 +                       if (put_user('\n', (char *)buffer + len))
23526 +                               return -EFAULT;
23527 +                       left--;
23528 +               }
23529 +       }
23530 +
23531 +done:
23532 +       *lenp -= left;
23533 +       *ppos += *lenp;
23534 +       return 0;
23535 +}
23536 +
23537 +static int zero;
23538 +
23539 +#define        CTL_ENTRY(ctl, name)                            \
23540 +       {                                               \
23541 +               .procname       = #name,                \
23542 +               .data           = &vs_ ## name,         \
23543 +               .maxlen         = sizeof(int),          \
23544 +               .mode           = 0644,                 \
23545 +               .proc_handler   = &proc_dodebug,        \
23546 +               .extra1         = &zero,                \
23547 +               .extra2         = &zero,                \
23548 +       }
23549 +
23550 +static ctl_table vserver_debug_table[] = {
23551 +       CTL_ENTRY(CTL_DEBUG_SWITCH,     debug_switch),
23552 +       CTL_ENTRY(CTL_DEBUG_XID,        debug_xid),
23553 +       CTL_ENTRY(CTL_DEBUG_NID,        debug_nid),
23554 +       CTL_ENTRY(CTL_DEBUG_TAG,        debug_tag),
23555 +       CTL_ENTRY(CTL_DEBUG_NET,        debug_net),
23556 +       CTL_ENTRY(CTL_DEBUG_LIMIT,      debug_limit),
23557 +       CTL_ENTRY(CTL_DEBUG_CRES,       debug_cres),
23558 +       CTL_ENTRY(CTL_DEBUG_DLIM,       debug_dlim),
23559 +       CTL_ENTRY(CTL_DEBUG_QUOTA,      debug_quota),
23560 +       CTL_ENTRY(CTL_DEBUG_CVIRT,      debug_cvirt),
23561 +       CTL_ENTRY(CTL_DEBUG_SPACE,      debug_space),
23562 +       CTL_ENTRY(CTL_DEBUG_PERM,       debug_perm),
23563 +       CTL_ENTRY(CTL_DEBUG_MISC,       debug_misc),
23564 +       { 0 }
23565 +};
23566 +
23567 +static ctl_table vserver_root_table[] = {
23568 +       {
23569 +               .procname       = "vserver",
23570 +               .mode           = 0555,
23571 +               .child          = vserver_debug_table
23572 +       },
23573 +       { 0 }
23574 +};
23575 +
23576 +
23577 +static match_table_t tokens = {
23578 +       { CTL_DEBUG_SWITCH,     "switch=%x"     },
23579 +       { CTL_DEBUG_XID,        "xid=%x"        },
23580 +       { CTL_DEBUG_NID,        "nid=%x"        },
23581 +       { CTL_DEBUG_TAG,        "tag=%x"        },
23582 +       { CTL_DEBUG_NET,        "net=%x"        },
23583 +       { CTL_DEBUG_LIMIT,      "limit=%x"      },
23584 +       { CTL_DEBUG_CRES,       "cres=%x"       },
23585 +       { CTL_DEBUG_DLIM,       "dlim=%x"       },
23586 +       { CTL_DEBUG_QUOTA,      "quota=%x"      },
23587 +       { CTL_DEBUG_CVIRT,      "cvirt=%x"      },
23588 +       { CTL_DEBUG_SPACE,      "space=%x"      },
23589 +       { CTL_DEBUG_PERM,       "perm=%x"       },
23590 +       { CTL_DEBUG_MISC,       "misc=%x"       },
23591 +       { CTL_DEBUG_ERROR,      NULL            }
23592 +};
23593 +
23594 +#define        HANDLE_CASE(id, name, val)                              \
23595 +       case CTL_DEBUG_ ## id:                                  \
23596 +               vs_debug_ ## name = val;                        \
23597 +               printk("vs_debug_" #name "=0x%x\n", val);       \
23598 +               break
23599 +
23600 +
23601 +static int __init vs_debug_setup(char *str)
23602 +{
23603 +       char *p;
23604 +       int token;
23605 +
23606 +       printk("vs_debug_setup(%s)\n", str);
23607 +       while ((p = strsep(&str, ",")) != NULL) {
23608 +               substring_t args[MAX_OPT_ARGS];
23609 +               unsigned int value;
23610 +
23611 +               if (!*p)
23612 +                       continue;
23613 +
23614 +               token = match_token(p, tokens, args);
23615 +               value = (token > 0) ? simple_strtoul(args[0].from, NULL, 0) : 0;
23616 +
23617 +               switch (token) {
23618 +               HANDLE_CASE(SWITCH, switch, value);
23619 +               HANDLE_CASE(XID,    xid,    value);
23620 +               HANDLE_CASE(NID,    nid,    value);
23621 +               HANDLE_CASE(TAG,    tag,    value);
23622 +               HANDLE_CASE(NET,    net,    value);
23623 +               HANDLE_CASE(LIMIT,  limit,  value);
23624 +               HANDLE_CASE(CRES,   cres,   value);
23625 +               HANDLE_CASE(DLIM,   dlim,   value);
23626 +               HANDLE_CASE(QUOTA,  quota,  value);
23627 +               HANDLE_CASE(CVIRT,  cvirt,  value);
23628 +               HANDLE_CASE(SPACE,  space,  value);
23629 +               HANDLE_CASE(PERM,   perm,   value);
23630 +               HANDLE_CASE(MISC,   misc,   value);
23631 +               default:
23632 +                       return -EINVAL;
23633 +                       break;
23634 +               }
23635 +       }
23636 +       return 1;
23637 +}
23638 +
23639 +__setup("vsdebug=", vs_debug_setup);
23640 +
23641 +
23642 +
23643 +EXPORT_SYMBOL_GPL(vs_debug_switch);
23644 +EXPORT_SYMBOL_GPL(vs_debug_xid);
23645 +EXPORT_SYMBOL_GPL(vs_debug_nid);
23646 +EXPORT_SYMBOL_GPL(vs_debug_net);
23647 +EXPORT_SYMBOL_GPL(vs_debug_limit);
23648 +EXPORT_SYMBOL_GPL(vs_debug_cres);
23649 +EXPORT_SYMBOL_GPL(vs_debug_dlim);
23650 +EXPORT_SYMBOL_GPL(vs_debug_quota);
23651 +EXPORT_SYMBOL_GPL(vs_debug_cvirt);
23652 +EXPORT_SYMBOL_GPL(vs_debug_space);
23653 +EXPORT_SYMBOL_GPL(vs_debug_perm);
23654 +EXPORT_SYMBOL_GPL(vs_debug_misc);
23655 +
23656 diff -NurpP --minimal linux-3.6.9/kernel/vserver/tag.c linux-3.6.9-vs2.3.4.4/kernel/vserver/tag.c
23657 --- linux-3.6.9/kernel/vserver/tag.c    1970-01-01 01:00:00.000000000 +0100
23658 +++ linux-3.6.9-vs2.3.4.4/kernel/vserver/tag.c  2012-10-04 18:47:00.000000000 +0200
23659 @@ -0,0 +1,63 @@
23660 +/*
23661 + *  linux/kernel/vserver/tag.c
23662 + *
23663 + *  Virtual Server: Shallow Tag Space
23664 + *
23665 + *  Copyright (C) 2007  Herbert Pötzl
23666 + *
23667 + *  V0.01  basic implementation
23668 + *
23669 + */
23670 +
23671 +#include <linux/sched.h>
23672 +#include <linux/vserver/debug.h>
23673 +#include <linux/vs_pid.h>
23674 +#include <linux/vs_tag.h>
23675 +
23676 +#include <linux/vserver/tag_cmd.h>
23677 +
23678 +
23679 +int dx_migrate_task(struct task_struct *p, vs_tag_t tag)
23680 +{
23681 +       if (!p)
23682 +               BUG();
23683 +
23684 +       vxdprintk(VXD_CBIT(tag, 5),
23685 +               "dx_migrate_task(%p[#%d],#%d)", p, p->tag, tag);
23686 +
23687 +       task_lock(p);
23688 +       p->tag = tag;
23689 +       task_unlock(p);
23690 +
23691 +       vxdprintk(VXD_CBIT(tag, 5),
23692 +               "moved task %p into [#%d]", p, tag);
23693 +       return 0;
23694 +}
23695 +
23696 +/* vserver syscall commands below here */
23697 +
23698 +/* taks xid and vx_info functions */
23699 +
23700 +
23701 +int vc_task_tag(uint32_t id)
23702 +{
23703 +       vs_tag_t tag;
23704 +
23705 +       if (id) {
23706 +               struct task_struct *tsk;
23707 +               rcu_read_lock();
23708 +               tsk = find_task_by_real_pid(id);
23709 +               tag = (tsk) ? tsk->tag : -ESRCH;
23710 +               rcu_read_unlock();
23711 +       } else
23712 +               tag = dx_current_tag();
23713 +       return tag;
23714 +}
23715 +
23716 +
23717 +int vc_tag_migrate(uint32_t tag)
23718 +{
23719 +       return dx_migrate_task(current, tag & 0xFFFF);
23720 +}
23721 +
23722 +
23723 diff -NurpP --minimal linux-3.6.9/kernel/vserver/vci_config.h linux-3.6.9-vs2.3.4.4/kernel/vserver/vci_config.h
23724 --- linux-3.6.9/kernel/vserver/vci_config.h     1970-01-01 01:00:00.000000000 +0100
23725 +++ linux-3.6.9-vs2.3.4.4/kernel/vserver/vci_config.h   2012-10-04 18:47:00.000000000 +0200
23726 @@ -0,0 +1,76 @@
23727 +
23728 +/*  interface version */
23729 +
23730 +#define VCI_VERSION            0x00020308
23731 +
23732 +
23733 +enum {
23734 +       VCI_KCBIT_NO_DYNAMIC = 0,
23735 +
23736 +       VCI_KCBIT_PROC_SECURE = 4,
23737 +       /* VCI_KCBIT_HARDCPU = 5, */
23738 +       /* VCI_KCBIT_IDLELIMIT = 6, */
23739 +       /* VCI_KCBIT_IDLETIME = 7, */
23740 +
23741 +       VCI_KCBIT_COWBL = 8,
23742 +       VCI_KCBIT_FULLCOWBL = 9,
23743 +       VCI_KCBIT_SPACES = 10,
23744 +       VCI_KCBIT_NETV2 = 11,
23745 +       VCI_KCBIT_MEMCG = 12,
23746 +
23747 +       VCI_KCBIT_DEBUG = 16,
23748 +       VCI_KCBIT_HISTORY = 20,
23749 +       VCI_KCBIT_TAGGED = 24,
23750 +       VCI_KCBIT_PPTAG = 28,
23751 +
23752 +       VCI_KCBIT_MORE = 31,
23753 +};
23754 +
23755 +
23756 +static inline uint32_t vci_kernel_config(void)
23757 +{
23758 +       return
23759 +       (1 << VCI_KCBIT_NO_DYNAMIC) |
23760 +
23761 +       /* configured features */
23762 +#ifdef CONFIG_VSERVER_PROC_SECURE
23763 +       (1 << VCI_KCBIT_PROC_SECURE) |
23764 +#endif
23765 +#ifdef CONFIG_VSERVER_COWBL
23766 +       (1 << VCI_KCBIT_COWBL) |
23767 +       (1 << VCI_KCBIT_FULLCOWBL) |
23768 +#endif
23769 +       (1 << VCI_KCBIT_SPACES) |
23770 +       (1 << VCI_KCBIT_NETV2) |
23771 +#ifdef CONFIG_CGROUP_MEM_RES_CTLR
23772 +       (1 << VCI_KCBIT_MEMCG) |
23773 +#endif
23774 +
23775 +       /* debug options */
23776 +#ifdef CONFIG_VSERVER_DEBUG
23777 +       (1 << VCI_KCBIT_DEBUG) |
23778 +#endif
23779 +#ifdef CONFIG_VSERVER_HISTORY
23780 +       (1 << VCI_KCBIT_HISTORY) |
23781 +#endif
23782 +
23783 +       /* inode context tagging */
23784 +#if    defined(CONFIG_TAGGING_NONE)
23785 +       (0 << VCI_KCBIT_TAGGED) |
23786 +#elif  defined(CONFIG_TAGGING_UID16)
23787 +       (1 << VCI_KCBIT_TAGGED) |
23788 +#elif  defined(CONFIG_TAGGING_GID16)
23789 +       (2 << VCI_KCBIT_TAGGED) |
23790 +#elif  defined(CONFIG_TAGGING_ID24)
23791 +       (3 << VCI_KCBIT_TAGGED) |
23792 +#elif  defined(CONFIG_TAGGING_INTERN)
23793 +       (4 << VCI_KCBIT_TAGGED) |
23794 +#elif  defined(CONFIG_TAGGING_RUNTIME)
23795 +       (5 << VCI_KCBIT_TAGGED) |
23796 +#else
23797 +       (7 << VCI_KCBIT_TAGGED) |
23798 +#endif
23799 +       (1 << VCI_KCBIT_PPTAG) |
23800 +       0;
23801 +}
23802 +
23803 diff -NurpP --minimal linux-3.6.9/mm/memcontrol.c linux-3.6.9-vs2.3.4.4/mm/memcontrol.c
23804 --- linux-3.6.9/mm/memcontrol.c 2012-12-08 01:34:15.000000000 +0100
23805 +++ linux-3.6.9-vs2.3.4.4/mm/memcontrol.c       2012-12-08 01:36:33.000000000 +0100
23806 @@ -885,6 +885,31 @@ struct mem_cgroup *mem_cgroup_from_task(
23807         return mem_cgroup_from_css(task_subsys_state(p, mem_cgroup_subsys_id));
23808  }
23809  
23810 +u64 mem_cgroup_res_read_u64(struct mem_cgroup *mem, int member)
23811 +{
23812 +       return res_counter_read_u64(&mem->res, member);
23813 +}
23814 +
23815 +u64 mem_cgroup_memsw_read_u64(struct mem_cgroup *mem, int member)
23816 +{
23817 +       return res_counter_read_u64(&mem->memsw, member);
23818 +}
23819 +
23820 +s64 mem_cgroup_stat_read_cache(struct mem_cgroup *mem)
23821 +{
23822 +       return mem_cgroup_read_stat(mem, MEM_CGROUP_STAT_CACHE);
23823 +}
23824 +
23825 +s64 mem_cgroup_stat_read_anon(struct mem_cgroup *mem)
23826 +{
23827 +       return mem_cgroup_read_stat(mem, MEM_CGROUP_STAT_RSS);
23828 +}
23829 +
23830 +s64 mem_cgroup_stat_read_mapped(struct mem_cgroup *mem)
23831 +{
23832 +       return mem_cgroup_read_stat(mem, MEM_CGROUP_STAT_FILE_MAPPED);
23833 +}
23834 +
23835  struct mem_cgroup *try_get_mem_cgroup_from_mm(struct mm_struct *mm)
23836  {
23837         struct mem_cgroup *memcg = NULL;
23838 diff -NurpP --minimal linux-3.6.9/mm/oom_kill.c linux-3.6.9-vs2.3.4.4/mm/oom_kill.c
23839 --- linux-3.6.9/mm/oom_kill.c   2012-10-04 15:27:48.000000000 +0200
23840 +++ linux-3.6.9-vs2.3.4.4/mm/oom_kill.c 2012-10-04 18:53:46.000000000 +0200
23841 @@ -35,6 +35,8 @@
23842  #include <linux/freezer.h>
23843  #include <linux/ftrace.h>
23844  #include <linux/ratelimit.h>
23845 +#include <linux/reboot.h>
23846 +#include <linux/vs_context.h>
23847  
23848  #define CREATE_TRACE_POINTS
23849  #include <trace/events/oom.h>
23850 @@ -155,11 +157,18 @@ struct task_struct *find_lock_task_mm(st
23851  static bool oom_unkillable_task(struct task_struct *p,
23852                 const struct mem_cgroup *memcg, const nodemask_t *nodemask)
23853  {
23854 -       if (is_global_init(p))
23855 +       unsigned xid = vx_current_xid();
23856 +
23857 +       /* skip the init task, global and per guest */
23858 +       if (task_is_init(p))
23859                 return true;
23860         if (p->flags & PF_KTHREAD)
23861                 return true;
23862  
23863 +       /* skip other guest and host processes if oom in guest */
23864 +       if (xid && vx_task_xid(p) != xid)
23865 +               return true;
23866 +
23867         /* When mem_cgroup_out_of_memory() and p is not member of the group */
23868         if (memcg && !task_in_mem_cgroup(p, memcg))
23869                 return true;
23870 @@ -472,8 +481,8 @@ void oom_kill_process(struct task_struct
23871                 dump_header(p, gfp_mask, order, memcg, nodemask);
23872  
23873         task_lock(p);
23874 -       pr_err("%s: Kill process %d (%s) score %d or sacrifice child\n",
23875 -               message, task_pid_nr(p), p->comm, points);
23876 +       pr_err("%s: Kill process %d:#%u (%s) score %d or sacrifice child\n",
23877 +               message, task_pid_nr(p), p->xid, p->comm, points);
23878         task_unlock(p);
23879  
23880         /*
23881 @@ -518,8 +527,8 @@ void oom_kill_process(struct task_struct
23882  
23883         /* mm cannot safely be dereferenced after task_unlock(victim) */
23884         mm = victim->mm;
23885 -       pr_err("Killed process %d (%s) total-vm:%lukB, anon-rss:%lukB, file-rss:%lukB\n",
23886 -               task_pid_nr(victim), victim->comm, K(victim->mm->total_vm),
23887 +       pr_err("Killed process %d:#%u (%s) total-vm:%lukB, anon-rss:%lukB, file-rss:%lukB\n",
23888 +               task_pid_nr(victim), victim->xid, victim->comm, K(victim->mm->total_vm),
23889                 K(get_mm_counter(victim->mm, MM_ANONPAGES)),
23890                 K(get_mm_counter(victim->mm, MM_FILEPAGES)));
23891         task_unlock(victim);
23892 @@ -589,6 +598,8 @@ int unregister_oom_notifier(struct notif
23893  }
23894  EXPORT_SYMBOL_GPL(unregister_oom_notifier);
23895  
23896 +long vs_oom_action(unsigned int);
23897 +
23898  /*
23899   * Try to acquire the OOM killer lock for the zones in zonelist.  Returns zero
23900   * if a parallel OOM killing is already taking place that includes a zone in
23901 @@ -738,7 +749,12 @@ void out_of_memory(struct zonelist *zone
23902         /* Found nothing?!?! Either we hang forever, or we panic. */
23903         if (!p) {
23904                 dump_header(NULL, gfp_mask, order, NULL, mpol_mask);
23905 -               panic("Out of memory and no killable processes...\n");
23906 +
23907 +               /* avoid panic for guest OOM */
23908 +               if (current->xid)
23909 +                       vs_oom_action(LINUX_REBOOT_CMD_OOM);
23910 +               else
23911 +                       panic("Out of memory and no killable processes...\n");
23912         }
23913         if (PTR_ERR(p) != -1UL) {
23914                 oom_kill_process(p, gfp_mask, order, points, totalpages, NULL,
23915 diff -NurpP --minimal linux-3.6.9/mm/page_alloc.c linux-3.6.9-vs2.3.4.4/mm/page_alloc.c
23916 --- linux-3.6.9/mm/page_alloc.c 2012-12-08 01:34:15.000000000 +0100
23917 +++ linux-3.6.9-vs2.3.4.4/mm/page_alloc.c       2012-12-08 01:36:33.000000000 +0100
23918 @@ -58,6 +58,8 @@
23919  #include <linux/prefetch.h>
23920  #include <linux/migrate.h>
23921  #include <linux/page-debug-flags.h>
23922 +#include <linux/vs_base.h>
23923 +#include <linux/vs_limit.h>
23924  
23925  #include <asm/tlbflush.h>
23926  #include <asm/div64.h>
23927 @@ -2773,6 +2775,9 @@ void si_meminfo(struct sysinfo *val)
23928         val->totalhigh = totalhigh_pages;
23929         val->freehigh = nr_free_highpages();
23930         val->mem_unit = PAGE_SIZE;
23931 +
23932 +       if (vx_flags(VXF_VIRT_MEM, 0))
23933 +               vx_vsi_meminfo(val);
23934  }
23935  
23936  EXPORT_SYMBOL(si_meminfo);
23937 @@ -2793,6 +2798,9 @@ void si_meminfo_node(struct sysinfo *val
23938         val->freehigh = 0;
23939  #endif
23940         val->mem_unit = PAGE_SIZE;
23941 +
23942 +       if (vx_flags(VXF_VIRT_MEM, 0))
23943 +               vx_vsi_meminfo(val);
23944  }
23945  #endif
23946  
23947 diff -NurpP --minimal linux-3.6.9/mm/pgtable-generic.c linux-3.6.9-vs2.3.4.4/mm/pgtable-generic.c
23948 --- linux-3.6.9/mm/pgtable-generic.c    2012-07-22 23:39:47.000000000 +0200
23949 +++ linux-3.6.9-vs2.3.4.4/mm/pgtable-generic.c  2012-10-04 18:47:00.000000000 +0200
23950 @@ -6,6 +6,8 @@
23951   *  Copyright (C) 2010  Linus Torvalds
23952   */
23953  
23954 +#include <linux/mm.h>
23955 +
23956  #include <linux/pagemap.h>
23957  #include <asm/tlb.h>
23958  #include <asm-generic/pgtable.h>
23959 diff -NurpP --minimal linux-3.6.9/mm/shmem.c linux-3.6.9-vs2.3.4.4/mm/shmem.c
23960 --- linux-3.6.9/mm/shmem.c      2012-12-08 01:34:15.000000000 +0100
23961 +++ linux-3.6.9-vs2.3.4.4/mm/shmem.c    2012-12-08 01:36:33.000000000 +0100
23962 @@ -1826,7 +1826,7 @@ static int shmem_statfs(struct dentry *d
23963  {
23964         struct shmem_sb_info *sbinfo = SHMEM_SB(dentry->d_sb);
23965  
23966 -       buf->f_type = TMPFS_MAGIC;
23967 +       buf->f_type = TMPFS_SUPER_MAGIC;
23968         buf->f_bsize = PAGE_CACHE_SIZE;
23969         buf->f_namelen = NAME_MAX;
23970         if (sbinfo->max_blocks) {
23971 @@ -2644,7 +2644,7 @@ int shmem_fill_super(struct super_block 
23972         sb->s_maxbytes = MAX_LFS_FILESIZE;
23973         sb->s_blocksize = PAGE_CACHE_SIZE;
23974         sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
23975 -       sb->s_magic = TMPFS_MAGIC;
23976 +       sb->s_magic = TMPFS_SUPER_MAGIC;
23977         sb->s_op = &shmem_ops;
23978         sb->s_time_gran = 1;
23979  #ifdef CONFIG_TMPFS_XATTR
23980 diff -NurpP --minimal linux-3.6.9/mm/slab.c linux-3.6.9-vs2.3.4.4/mm/slab.c
23981 --- linux-3.6.9/mm/slab.c       2012-12-08 01:34:15.000000000 +0100
23982 +++ linux-3.6.9-vs2.3.4.4/mm/slab.c     2012-11-06 18:43:41.000000000 +0100
23983 @@ -445,6 +445,8 @@ static void kmem_list3_init(struct kmem_
23984  #define STATS_INC_FREEMISS(x)  do { } while (0)
23985  #endif
23986  
23987 +#include "slab_vs.h"
23988 +
23989  #if DEBUG
23990  
23991  /*
23992 @@ -3539,6 +3541,7 @@ retry:
23993  
23994         obj = slab_get_obj(cachep, slabp, nodeid);
23995         check_slabp(cachep, slabp);
23996 +       vx_slab_alloc(cachep, flags);
23997         l3->free_objects--;
23998         /* move slabp to correct slabp list: */
23999         list_del(&slabp->list);
24000 @@ -3616,6 +3619,7 @@ __cache_alloc_node(struct kmem_cache *ca
24001         /* ___cache_alloc_node can fall back to other nodes */
24002         ptr = ____cache_alloc_node(cachep, flags, nodeid);
24003    out:
24004 +       vx_slab_alloc(cachep, flags);
24005         local_irq_restore(save_flags);
24006         ptr = cache_alloc_debugcheck_after(cachep, flags, ptr, caller);
24007         kmemleak_alloc_recursive(ptr, cachep->object_size, 1, cachep->flags,
24008 @@ -3806,6 +3810,7 @@ static inline void __cache_free(struct k
24009         check_irq_off();
24010         kmemleak_free_recursive(objp, cachep->flags);
24011         objp = cache_free_debugcheck(cachep, objp, caller);
24012 +       vx_slab_free(cachep);
24013  
24014         kmemcheck_slab_free(cachep, objp, cachep->object_size);
24015  
24016 diff -NurpP --minimal linux-3.6.9/mm/slab_vs.h linux-3.6.9-vs2.3.4.4/mm/slab_vs.h
24017 --- linux-3.6.9/mm/slab_vs.h    1970-01-01 01:00:00.000000000 +0100
24018 +++ linux-3.6.9-vs2.3.4.4/mm/slab_vs.h  2012-10-09 16:28:11.000000000 +0200
24019 @@ -0,0 +1,29 @@
24020 +
24021 +#include <linux/vserver/context.h>
24022 +
24023 +#include <linux/vs_context.h>
24024 +
24025 +static inline
24026 +void vx_slab_alloc(struct kmem_cache *cachep, gfp_t flags)
24027 +{
24028 +       int what = gfp_zone(cachep->allocflags);
24029 +       struct vx_info *vxi = current_vx_info();
24030 +
24031 +       if (!vxi)
24032 +               return;
24033 +
24034 +       atomic_add(cachep->size, &vxi->cacct.slab[what]);
24035 +}
24036 +
24037 +static inline
24038 +void vx_slab_free(struct kmem_cache *cachep)
24039 +{
24040 +       int what = gfp_zone(cachep->allocflags);
24041 +       struct vx_info *vxi = current_vx_info();
24042 +
24043 +       if (!vxi)
24044 +               return;
24045 +
24046 +       atomic_sub(cachep->size, &vxi->cacct.slab[what]);
24047 +}
24048 +
24049 diff -NurpP --minimal linux-3.6.9/mm/swapfile.c linux-3.6.9-vs2.3.4.4/mm/swapfile.c
24050 --- linux-3.6.9/mm/swapfile.c   2012-10-04 15:27:48.000000000 +0200
24051 +++ linux-3.6.9-vs2.3.4.4/mm/swapfile.c 2012-10-04 18:47:00.000000000 +0200
24052 @@ -39,6 +39,7 @@
24053  #include <asm/tlbflush.h>
24054  #include <linux/swapops.h>
24055  #include <linux/page_cgroup.h>
24056 +#include <linux/vs_base.h>
24057  
24058  static bool swap_count_continued(struct swap_info_struct *, pgoff_t,
24059                                  unsigned char);
24060 @@ -1686,6 +1687,16 @@ static int swap_show(struct seq_file *sw
24061  
24062         if (si == SEQ_START_TOKEN) {
24063                 seq_puts(swap,"Filename\t\t\t\tType\t\tSize\tUsed\tPriority\n");
24064 +               if (vx_flags(VXF_VIRT_MEM, 0)) {
24065 +                       struct sysinfo si;
24066 +
24067 +                       vx_vsi_swapinfo(&si);
24068 +                       if (si.totalswap < (1 << 10))
24069 +                               return 0;
24070 +                       seq_printf(swap, "%s\t\t\t\t\t%s\t%lu\t%lu\t%d\n",
24071 +                               "hdv0", "partition", si.totalswap >> 10,
24072 +                               (si.totalswap - si.freeswap) >> 10, -1);
24073 +               }
24074                 return 0;
24075         }
24076  
24077 @@ -2113,6 +2124,8 @@ void si_swapinfo(struct sysinfo *val)
24078         val->freeswap = nr_swap_pages + nr_to_be_unused;
24079         val->totalswap = total_swap_pages + nr_to_be_unused;
24080         spin_unlock(&swap_lock);
24081 +       if (vx_flags(VXF_VIRT_MEM, 0))
24082 +               vx_vsi_swapinfo(val);
24083  }
24084  
24085  /*
24086 diff -NurpP --minimal linux-3.6.9/net/bridge/br_multicast.c linux-3.6.9-vs2.3.4.4/net/bridge/br_multicast.c
24087 --- linux-3.6.9/net/bridge/br_multicast.c       2012-10-04 15:27:49.000000000 +0200
24088 +++ linux-3.6.9-vs2.3.4.4/net/bridge/br_multicast.c     2012-10-04 18:47:00.000000000 +0200
24089 @@ -447,7 +447,7 @@ static struct sk_buff *br_ip6_multicast_
24090         ip6h->hop_limit = 1;
24091         ipv6_addr_set(&ip6h->daddr, htonl(0xff020000), 0, 0, htonl(1));
24092         if (ipv6_dev_get_saddr(dev_net(br->dev), br->dev, &ip6h->daddr, 0,
24093 -                              &ip6h->saddr)) {
24094 +                              &ip6h->saddr, NULL)) {
24095                 kfree_skb(skb);
24096                 return NULL;
24097         }
24098 diff -NurpP --minimal linux-3.6.9/net/core/dev.c linux-3.6.9-vs2.3.4.4/net/core/dev.c
24099 --- linux-3.6.9/net/core/dev.c  2012-12-08 01:34:15.000000000 +0100
24100 +++ linux-3.6.9-vs2.3.4.4/net/core/dev.c        2012-12-08 01:36:33.000000000 +0100
24101 @@ -126,6 +126,7 @@
24102  #include <linux/in.h>
24103  #include <linux/jhash.h>
24104  #include <linux/random.h>
24105 +#include <linux/vs_inet.h>
24106  #include <trace/events/napi.h>
24107  #include <trace/events/net.h>
24108  #include <trace/events/skb.h>
24109 @@ -620,7 +621,8 @@ struct net_device *__dev_get_by_name(str
24110         struct hlist_head *head = dev_name_hash(net, name);
24111  
24112         hlist_for_each_entry(dev, p, head, name_hlist)
24113 -               if (!strncmp(dev->name, name, IFNAMSIZ))
24114 +               if (!strncmp(dev->name, name, IFNAMSIZ) &&
24115 +                   nx_dev_visible(current_nx_info(), dev))
24116                         return dev;
24117  
24118         return NULL;
24119 @@ -646,7 +648,8 @@ struct net_device *dev_get_by_name_rcu(s
24120         struct hlist_head *head = dev_name_hash(net, name);
24121  
24122         hlist_for_each_entry_rcu(dev, p, head, name_hlist)
24123 -               if (!strncmp(dev->name, name, IFNAMSIZ))
24124 +               if (!strncmp(dev->name, name, IFNAMSIZ) &&
24125 +                   nx_dev_visible(current_nx_info(), dev))
24126                         return dev;
24127  
24128         return NULL;
24129 @@ -697,7 +700,8 @@ struct net_device *__dev_get_by_index(st
24130         struct hlist_head *head = dev_index_hash(net, ifindex);
24131  
24132         hlist_for_each_entry(dev, p, head, index_hlist)
24133 -               if (dev->ifindex == ifindex)
24134 +               if ((dev->ifindex == ifindex) &&
24135 +                   nx_dev_visible(current_nx_info(), dev))
24136                         return dev;
24137  
24138         return NULL;
24139 @@ -715,7 +719,7 @@ EXPORT_SYMBOL(__dev_get_by_index);
24140   *     about locking. The caller must hold RCU lock.
24141   */
24142  
24143 -struct net_device *dev_get_by_index_rcu(struct net *net, int ifindex)
24144 +struct net_device *dev_get_by_index_real_rcu(struct net *net, int ifindex)
24145  {
24146         struct hlist_node *p;
24147         struct net_device *dev;
24148 @@ -727,6 +731,16 @@ struct net_device *dev_get_by_index_rcu(
24149  
24150         return NULL;
24151  }
24152 +EXPORT_SYMBOL(dev_get_by_index_real_rcu);
24153 +
24154 +struct net_device *dev_get_by_index_rcu(struct net *net, int ifindex)
24155 +{
24156 +       struct net_device *dev = dev_get_by_index_real_rcu(net, ifindex);
24157 +
24158 +       if (nx_dev_visible(current_nx_info(), dev))
24159 +               return dev;
24160 +       return NULL;
24161 +}
24162  EXPORT_SYMBOL(dev_get_by_index_rcu);
24163  
24164  
24165 @@ -775,7 +789,8 @@ struct net_device *dev_getbyhwaddr_rcu(s
24166  
24167         for_each_netdev_rcu(net, dev)
24168                 if (dev->type == type &&
24169 -                   !memcmp(dev->dev_addr, ha, dev->addr_len))
24170 +                   !memcmp(dev->dev_addr, ha, dev->addr_len) &&
24171 +                   nx_dev_visible(current_nx_info(), dev))
24172                         return dev;
24173  
24174         return NULL;
24175 @@ -787,9 +802,11 @@ struct net_device *__dev_getfirstbyhwtyp
24176         struct net_device *dev;
24177  
24178         ASSERT_RTNL();
24179 -       for_each_netdev(net, dev)
24180 -               if (dev->type == type)
24181 +       for_each_netdev(net, dev) {
24182 +               if ((dev->type == type) &&
24183 +                   nx_dev_visible(current_nx_info(), dev))
24184                         return dev;
24185 +       }
24186  
24187         return NULL;
24188  }
24189 @@ -907,6 +924,8 @@ static int __dev_alloc_name(struct net *
24190                                 continue;
24191                         if (i < 0 || i >= max_netdevices)
24192                                 continue;
24193 +                       if (!nx_dev_visible(current_nx_info(), d))
24194 +                               continue;
24195  
24196                         /*  avoid cases where sscanf is not exact inverse of printf */
24197                         snprintf(buf, IFNAMSIZ, name, i);
24198 @@ -4076,6 +4095,8 @@ static int dev_ifconf(struct net *net, c
24199  
24200         total = 0;
24201         for_each_netdev(net, dev) {
24202 +               if (!nx_dev_visible(current_nx_info(), dev))
24203 +                       continue;
24204                 for (i = 0; i < NPROTO; i++) {
24205                         if (gifconf_list[i]) {
24206                                 int done;
24207 @@ -4178,6 +4199,10 @@ static void dev_seq_printf_stats(struct 
24208         struct rtnl_link_stats64 temp;
24209         const struct rtnl_link_stats64 *stats = dev_get_stats(dev, &temp);
24210  
24211 +       /* device visible inside network context? */
24212 +       if (!nx_dev_visible(current_nx_info(), dev))
24213 +               return;
24214 +
24215         seq_printf(seq, "%6s: %7llu %7llu %4llu %4llu %4llu %5llu %10llu %9llu "
24216                    "%8llu %7llu %4llu %4llu %4llu %5llu %7llu %10llu\n",
24217                    dev->name, stats->rx_bytes, stats->rx_packets,
24218 diff -NurpP --minimal linux-3.6.9/net/core/rtnetlink.c linux-3.6.9-vs2.3.4.4/net/core/rtnetlink.c
24219 --- linux-3.6.9/net/core/rtnetlink.c    2012-10-04 15:27:49.000000000 +0200
24220 +++ linux-3.6.9-vs2.3.4.4/net/core/rtnetlink.c  2012-10-04 18:47:00.000000000 +0200
24221 @@ -1080,6 +1080,8 @@ static int rtnl_dump_ifinfo(struct sk_bu
24222                 hlist_for_each_entry_rcu(dev, node, head, index_hlist) {
24223                         if (idx < s_idx)
24224                                 goto cont;
24225 +                       if (!nx_dev_visible(skb->sk->sk_nx_info, dev))
24226 +                               continue;
24227                         if (rtnl_fill_ifinfo(skb, dev, RTM_NEWLINK,
24228                                              NETLINK_CB(cb->skb).pid,
24229                                              cb->nlh->nlmsg_seq, 0,
24230 @@ -1969,6 +1971,9 @@ void rtmsg_ifinfo(int type, struct net_d
24231         int err = -ENOBUFS;
24232         size_t if_info_size;
24233  
24234 +       if (!nx_dev_visible(current_nx_info(), dev))
24235 +               return;
24236 +
24237         skb = nlmsg_new((if_info_size = if_nlmsg_size(dev, 0)), GFP_KERNEL);
24238         if (skb == NULL)
24239                 goto errout;
24240 diff -NurpP --minimal linux-3.6.9/net/core/sock.c linux-3.6.9-vs2.3.4.4/net/core/sock.c
24241 --- linux-3.6.9/net/core/sock.c 2012-10-04 15:27:49.000000000 +0200
24242 +++ linux-3.6.9-vs2.3.4.4/net/core/sock.c       2012-10-04 18:47:00.000000000 +0200
24243 @@ -132,6 +132,10 @@
24244  #include <net/netprio_cgroup.h>
24245  
24246  #include <linux/filter.h>
24247 +#include <linux/vs_socket.h>
24248 +#include <linux/vs_limit.h>
24249 +#include <linux/vs_context.h>
24250 +#include <linux/vs_network.h>
24251  
24252  #include <trace/events/sock.h>
24253  
24254 @@ -1194,6 +1198,8 @@ static struct sock *sk_prot_alloc(struct
24255                         goto out_free_sec;
24256                 sk_tx_queue_clear(sk);
24257         }
24258 +               sock_vx_init(sk);
24259 +               sock_nx_init(sk);
24260  
24261         return sk;
24262  
24263 @@ -1302,6 +1308,11 @@ static void __sk_free(struct sock *sk)
24264                 put_cred(sk->sk_peer_cred);
24265         put_pid(sk->sk_peer_pid);
24266         put_net(sock_net(sk));
24267 +       vx_sock_dec(sk);
24268 +       clr_vx_info(&sk->sk_vx_info);
24269 +       sk->sk_xid = -1;
24270 +       clr_nx_info(&sk->sk_nx_info);
24271 +       sk->sk_nid = -1;
24272         sk_prot_free(sk->sk_prot_creator, sk);
24273  }
24274  
24275 @@ -1362,6 +1373,8 @@ struct sock *sk_clone_lock(const struct 
24276  
24277                 /* SANITY */
24278                 get_net(sock_net(newsk));
24279 +               sock_vx_init(newsk);
24280 +               sock_nx_init(newsk);
24281                 sk_node_init(&newsk->sk_node);
24282                 sock_lock_init(newsk);
24283                 bh_lock_sock(newsk);
24284 @@ -1418,6 +1431,12 @@ struct sock *sk_clone_lock(const struct 
24285                 smp_wmb();
24286                 atomic_set(&newsk->sk_refcnt, 2);
24287  
24288 +               set_vx_info(&newsk->sk_vx_info, sk->sk_vx_info);
24289 +               newsk->sk_xid = sk->sk_xid;
24290 +               vx_sock_inc(newsk);
24291 +               set_nx_info(&newsk->sk_nx_info, sk->sk_nx_info);
24292 +               newsk->sk_nid = sk->sk_nid;
24293 +
24294                 /*
24295                  * Increment the counter in the same struct proto as the master
24296                  * sock (sk_refcnt_debug_inc uses newsk->sk_prot->socks, that
24297 @@ -2187,6 +2206,12 @@ void sock_init_data(struct socket *sock,
24298  
24299         sk->sk_stamp = ktime_set(-1L, 0);
24300  
24301 +       set_vx_info(&sk->sk_vx_info, current_vx_info());
24302 +       sk->sk_xid = vx_current_xid();
24303 +       vx_sock_inc(sk);
24304 +       set_nx_info(&sk->sk_nx_info, current_nx_info());
24305 +       sk->sk_nid = nx_current_nid();
24306 +
24307         /*
24308          * Before updating sk_refcnt, we must commit prior changes to memory
24309          * (Documentation/RCU/rculist_nulls.txt for details)
24310 diff -NurpP --minimal linux-3.6.9/net/ipv4/af_inet.c linux-3.6.9-vs2.3.4.4/net/ipv4/af_inet.c
24311 --- linux-3.6.9/net/ipv4/af_inet.c      2012-10-04 15:27:49.000000000 +0200
24312 +++ linux-3.6.9-vs2.3.4.4/net/ipv4/af_inet.c    2012-10-04 18:47:00.000000000 +0200
24313 @@ -118,6 +118,7 @@
24314  #ifdef CONFIG_IP_MROUTE
24315  #include <linux/mroute.h>
24316  #endif
24317 +#include <linux/vs_limit.h>
24318  
24319  
24320  /* The inetsw table contains everything that inet_create needs to
24321 @@ -326,9 +327,13 @@ lookup_protocol:
24322         }
24323  
24324         err = -EPERM;
24325 +       if ((protocol == IPPROTO_ICMP) &&
24326 +               nx_capable(CAP_NET_RAW, NXC_RAW_ICMP))
24327 +               goto override;
24328 +
24329         if (sock->type == SOCK_RAW && !kern && !capable(CAP_NET_RAW))
24330                 goto out_rcu_unlock;
24331 -
24332 +override:
24333         err = -EAFNOSUPPORT;
24334         if (!inet_netns_ok(net, protocol))
24335                 goto out_rcu_unlock;
24336 @@ -453,6 +458,7 @@ int inet_bind(struct socket *sock, struc
24337         struct sockaddr_in *addr = (struct sockaddr_in *)uaddr;
24338         struct sock *sk = sock->sk;
24339         struct inet_sock *inet = inet_sk(sk);
24340 +       struct nx_v4_sock_addr nsa;
24341         unsigned short snum;
24342         int chk_addr_ret;
24343         int err;
24344 @@ -476,7 +482,11 @@ int inet_bind(struct socket *sock, struc
24345                         goto out;
24346         }
24347  
24348 -       chk_addr_ret = inet_addr_type(sock_net(sk), addr->sin_addr.s_addr);
24349 +       err = v4_map_sock_addr(inet, addr, &nsa);
24350 +       if (err)
24351 +               goto out;
24352 +
24353 +       chk_addr_ret = inet_addr_type(sock_net(sk), nsa.saddr);
24354  
24355         /* Not specified by any standard per-se, however it breaks too
24356          * many applications when removed.  It is unfortunate since
24357 @@ -488,7 +498,7 @@ int inet_bind(struct socket *sock, struc
24358         err = -EADDRNOTAVAIL;
24359         if (!sysctl_ip_nonlocal_bind &&
24360             !(inet->freebind || inet->transparent) &&
24361 -           addr->sin_addr.s_addr != htonl(INADDR_ANY) &&
24362 +           nsa.saddr != htonl(INADDR_ANY) &&
24363             chk_addr_ret != RTN_LOCAL &&
24364             chk_addr_ret != RTN_MULTICAST &&
24365             chk_addr_ret != RTN_BROADCAST)
24366 @@ -513,7 +523,7 @@ int inet_bind(struct socket *sock, struc
24367         if (sk->sk_state != TCP_CLOSE || inet->inet_num)
24368                 goto out_release_sock;
24369  
24370 -       inet->inet_rcv_saddr = inet->inet_saddr = addr->sin_addr.s_addr;
24371 +       v4_set_sock_addr(inet, &nsa);
24372         if (chk_addr_ret == RTN_MULTICAST || chk_addr_ret == RTN_BROADCAST)
24373                 inet->inet_saddr = 0;  /* Use device */
24374  
24375 @@ -731,11 +741,13 @@ int inet_getname(struct socket *sock, st
24376                      peer == 1))
24377                         return -ENOTCONN;
24378                 sin->sin_port = inet->inet_dport;
24379 -               sin->sin_addr.s_addr = inet->inet_daddr;
24380 +               sin->sin_addr.s_addr =
24381 +                       nx_map_sock_lback(sk->sk_nx_info, inet->inet_daddr);
24382         } else {
24383                 __be32 addr = inet->inet_rcv_saddr;
24384                 if (!addr)
24385                         addr = inet->inet_saddr;
24386 +               addr = nx_map_sock_lback(sk->sk_nx_info, addr);
24387                 sin->sin_port = inet->inet_sport;
24388                 sin->sin_addr.s_addr = addr;
24389         }
24390 diff -NurpP --minimal linux-3.6.9/net/ipv4/arp.c linux-3.6.9-vs2.3.4.4/net/ipv4/arp.c
24391 --- linux-3.6.9/net/ipv4/arp.c  2012-10-04 15:27:49.000000000 +0200
24392 +++ linux-3.6.9-vs2.3.4.4/net/ipv4/arp.c        2012-10-04 18:47:00.000000000 +0200
24393 @@ -1318,6 +1318,7 @@ static void arp_format_neigh_entry(struc
24394         struct net_device *dev = n->dev;
24395         int hatype = dev->type;
24396  
24397 +       /* FIXME: check for network context */
24398         read_lock(&n->lock);
24399         /* Convert hardware address to XX:XX:XX:XX ... form. */
24400  #if IS_ENABLED(CONFIG_AX25)
24401 @@ -1349,6 +1350,7 @@ static void arp_format_pneigh_entry(stru
24402         int hatype = dev ? dev->type : 0;
24403         char tbuf[16];
24404  
24405 +       /* FIXME: check for network context */
24406         sprintf(tbuf, "%pI4", n->key);
24407         seq_printf(seq, "%-16s 0x%-10x0x%-10x%s     *        %s\n",
24408                    tbuf, hatype, ATF_PUBL | ATF_PERM, "00:00:00:00:00:00",
24409 diff -NurpP --minimal linux-3.6.9/net/ipv4/devinet.c linux-3.6.9-vs2.3.4.4/net/ipv4/devinet.c
24410 --- linux-3.6.9/net/ipv4/devinet.c      2012-10-04 15:27:49.000000000 +0200
24411 +++ linux-3.6.9-vs2.3.4.4/net/ipv4/devinet.c    2012-10-04 18:47:00.000000000 +0200
24412 @@ -516,6 +516,7 @@ struct in_device *inetdev_by_index(struc
24413  }
24414  EXPORT_SYMBOL(inetdev_by_index);
24415  
24416 +
24417  /* Called only from RTNL semaphored context. No locks. */
24418  
24419  struct in_ifaddr *inet_ifa_byprefix(struct in_device *in_dev, __be32 prefix,
24420 @@ -757,6 +758,8 @@ int devinet_ioctl(struct net *net, unsig
24421  
24422         in_dev = __in_dev_get_rtnl(dev);
24423         if (in_dev) {
24424 +               struct nx_info *nxi = current_nx_info();
24425 +
24426                 if (tryaddrmatch) {
24427                         /* Matthias Andree */
24428                         /* compare label and address (4.4BSD style) */
24429 @@ -765,6 +768,8 @@ int devinet_ioctl(struct net *net, unsig
24430                            This is checked above. */
24431                         for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
24432                              ifap = &ifa->ifa_next) {
24433 +                               if (!nx_v4_ifa_visible(nxi, ifa))
24434 +                                       continue;
24435                                 if (!strcmp(ifr.ifr_name, ifa->ifa_label) &&
24436                                     sin_orig.sin_addr.s_addr ==
24437                                                         ifa->ifa_local) {
24438 @@ -777,9 +782,12 @@ int devinet_ioctl(struct net *net, unsig
24439                    comparing just the label */
24440                 if (!ifa) {
24441                         for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
24442 -                            ifap = &ifa->ifa_next)
24443 +                            ifap = &ifa->ifa_next) {
24444 +                               if (!nx_v4_ifa_visible(nxi, ifa))
24445 +                                       continue;
24446                                 if (!strcmp(ifr.ifr_name, ifa->ifa_label))
24447                                         break;
24448 +                       }
24449                 }
24450         }
24451  
24452 @@ -932,6 +940,8 @@ static int inet_gifconf(struct net_devic
24453                 goto out;
24454  
24455         for (ifa = in_dev->ifa_list; ifa; ifa = ifa->ifa_next) {
24456 +               if (!nx_v4_ifa_visible(current_nx_info(), ifa))
24457 +                       continue;
24458                 if (!buf) {
24459                         done += sizeof(ifr);
24460                         continue;
24461 @@ -1291,6 +1301,7 @@ static int inet_dump_ifaddr(struct sk_bu
24462         struct net_device *dev;
24463         struct in_device *in_dev;
24464         struct in_ifaddr *ifa;
24465 +       struct sock *sk = skb->sk;
24466         struct hlist_head *head;
24467         struct hlist_node *node;
24468  
24469 @@ -1313,6 +1324,8 @@ static int inet_dump_ifaddr(struct sk_bu
24470  
24471                         for (ifa = in_dev->ifa_list, ip_idx = 0; ifa;
24472                              ifa = ifa->ifa_next, ip_idx++) {
24473 +                       if (sk && !nx_v4_ifa_visible(sk->sk_nx_info, ifa))
24474 +                               continue;
24475                                 if (ip_idx < s_ip_idx)
24476                                         continue;
24477                                 if (inet_fill_ifaddr(skb, ifa,
24478 diff -NurpP --minimal linux-3.6.9/net/ipv4/fib_trie.c linux-3.6.9-vs2.3.4.4/net/ipv4/fib_trie.c
24479 --- linux-3.6.9/net/ipv4/fib_trie.c     2012-10-04 15:27:49.000000000 +0200
24480 +++ linux-3.6.9-vs2.3.4.4/net/ipv4/fib_trie.c   2012-10-04 18:47:00.000000000 +0200
24481 @@ -2554,6 +2554,7 @@ static int fib_route_seq_show(struct seq
24482                             || fa->fa_type == RTN_MULTICAST)
24483                                 continue;
24484  
24485 +                       /* FIXME: check for network context? */
24486                         if (fi)
24487                                 seq_printf(seq,
24488                                          "%s\t%08X\t%08X\t%04X\t%d\t%u\t"
24489 diff -NurpP --minimal linux-3.6.9/net/ipv4/inet_connection_sock.c linux-3.6.9-vs2.3.4.4/net/ipv4/inet_connection_sock.c
24490 --- linux-3.6.9/net/ipv4/inet_connection_sock.c 2012-12-08 01:34:15.000000000 +0100
24491 +++ linux-3.6.9-vs2.3.4.4/net/ipv4/inet_connection_sock.c       2012-11-06 18:43:41.000000000 +0100
24492 @@ -53,6 +53,37 @@ void inet_get_local_port_range(int *low,
24493  }
24494  EXPORT_SYMBOL(inet_get_local_port_range);
24495  
24496 +int ipv4_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2)
24497 +{
24498 +       __be32  sk1_rcv_saddr = sk_rcv_saddr(sk1),
24499 +               sk2_rcv_saddr = sk_rcv_saddr(sk2);
24500 +
24501 +       if (inet_v6_ipv6only(sk2))
24502 +               return 0;
24503 +
24504 +       if (sk1_rcv_saddr &&
24505 +           sk2_rcv_saddr &&
24506 +           sk1_rcv_saddr == sk2_rcv_saddr)
24507 +               return 1;
24508 +
24509 +       if (sk1_rcv_saddr &&
24510 +           !sk2_rcv_saddr &&
24511 +           v4_addr_in_nx_info(sk2->sk_nx_info, sk1_rcv_saddr, NXA_MASK_BIND))
24512 +               return 1;
24513 +
24514 +       if (sk2_rcv_saddr &&
24515 +           !sk1_rcv_saddr &&
24516 +           v4_addr_in_nx_info(sk1->sk_nx_info, sk2_rcv_saddr, NXA_MASK_BIND))
24517 +               return 1;
24518 +
24519 +       if (!sk1_rcv_saddr &&
24520 +           !sk2_rcv_saddr &&
24521 +           nx_v4_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info))
24522 +               return 1;
24523 +
24524 +       return 0;
24525 +}
24526 +
24527  int inet_csk_bind_conflict(const struct sock *sk,
24528                            const struct inet_bind_bucket *tb, bool relax)
24529  {
24530 @@ -75,9 +106,7 @@ int inet_csk_bind_conflict(const struct 
24531                      sk->sk_bound_dev_if == sk2->sk_bound_dev_if)) {
24532                         if (!reuse || !sk2->sk_reuse ||
24533                             sk2->sk_state == TCP_LISTEN) {
24534 -                               const __be32 sk2_rcv_saddr = sk_rcv_saddr(sk2);
24535 -                               if (!sk2_rcv_saddr || !sk_rcv_saddr(sk) ||
24536 -                                   sk2_rcv_saddr == sk_rcv_saddr(sk))
24537 +                               if (ipv4_rcv_saddr_equal(sk, sk2))
24538                                         break;
24539                         }
24540                         if (!relax && reuse && sk2->sk_reuse &&
24541 diff -NurpP --minimal linux-3.6.9/net/ipv4/inet_diag.c linux-3.6.9-vs2.3.4.4/net/ipv4/inet_diag.c
24542 --- linux-3.6.9/net/ipv4/inet_diag.c    2012-12-08 01:34:15.000000000 +0100
24543 +++ linux-3.6.9-vs2.3.4.4/net/ipv4/inet_diag.c  2012-12-08 01:36:33.000000000 +0100
24544 @@ -31,6 +31,8 @@
24545  
24546  #include <linux/inet.h>
24547  #include <linux/stddef.h>
24548 +#include <linux/vs_network.h>
24549 +#include <linux/vs_inet.h>
24550  
24551  #include <linux/inet_diag.h>
24552  #include <linux/sock_diag.h>
24553 @@ -101,8 +103,10 @@ int inet_sk_diag_fill(struct sock *sk, s
24554  
24555         r->id.idiag_sport = inet->inet_sport;
24556         r->id.idiag_dport = inet->inet_dport;
24557 -       r->id.idiag_src[0] = inet->inet_rcv_saddr;
24558 -       r->id.idiag_dst[0] = inet->inet_daddr;
24559 +       r->id.idiag_src[0] = nx_map_sock_lback(sk->sk_nx_info,
24560 +               inet->inet_rcv_saddr);
24561 +       r->id.idiag_dst[0] = nx_map_sock_lback(sk->sk_nx_info,
24562 +               inet->inet_daddr);
24563  
24564         /* IPv6 dual-stack sockets use inet->tos for IPv4 connections,
24565          * hence this needs to be included regardless of socket family.
24566 @@ -233,8 +237,8 @@ static int inet_twsk_diag_fill(struct in
24567         sock_diag_save_cookie(tw, r->id.idiag_cookie);
24568         r->id.idiag_sport     = tw->tw_sport;
24569         r->id.idiag_dport     = tw->tw_dport;
24570 -       r->id.idiag_src[0]    = tw->tw_rcv_saddr;
24571 -       r->id.idiag_dst[0]    = tw->tw_daddr;
24572 +       r->id.idiag_src[0]    = nx_map_sock_lback(tw->tw_nx_info, tw->tw_rcv_saddr);
24573 +       r->id.idiag_dst[0]    = nx_map_sock_lback(tw->tw_nx_info, tw->tw_daddr);
24574         r->idiag_state        = tw->tw_substate;
24575         r->idiag_timer        = 3;
24576         r->idiag_expires      = DIV_ROUND_UP(tmo * 1000, HZ);
24577 @@ -276,12 +280,14 @@ int inet_diag_dump_one_icsk(struct inet_
24578  
24579         err = -EINVAL;
24580         if (req->sdiag_family == AF_INET) {
24581 +               /* TODO: lback */
24582                 sk = inet_lookup(net, hashinfo, req->id.idiag_dst[0],
24583                                  req->id.idiag_dport, req->id.idiag_src[0],
24584                                  req->id.idiag_sport, req->id.idiag_if);
24585         }
24586  #if IS_ENABLED(CONFIG_IPV6)
24587         else if (req->sdiag_family == AF_INET6) {
24588 +               /* TODO: lback */
24589                 sk = inet6_lookup(net, hashinfo,
24590                                   (struct in6_addr *)req->id.idiag_dst,
24591                                   req->id.idiag_dport,
24592 @@ -476,6 +482,7 @@ int inet_diag_bc_sk(const struct nlattr 
24593         } else
24594  #endif
24595         {
24596 +                       /* TODO: lback */
24597                 entry.saddr = &inet->inet_rcv_saddr;
24598                 entry.daddr = &inet->inet_daddr;
24599         }
24600 @@ -574,6 +581,7 @@ static int inet_twsk_diag_dump(struct in
24601                 } else
24602  #endif
24603                 {
24604 +                       /* TODO: lback */
24605                         entry.saddr = &tw->tw_rcv_saddr;
24606                         entry.daddr = &tw->tw_daddr;
24607                 }
24608 @@ -620,8 +628,8 @@ static int inet_diag_fill_req(struct sk_
24609  
24610         r->id.idiag_sport = inet->inet_sport;
24611         r->id.idiag_dport = ireq->rmt_port;
24612 -       r->id.idiag_src[0] = ireq->loc_addr;
24613 -       r->id.idiag_dst[0] = ireq->rmt_addr;
24614 +       r->id.idiag_src[0] = nx_map_sock_lback(sk->sk_nx_info, ireq->loc_addr);
24615 +       r->id.idiag_dst[0] = nx_map_sock_lback(sk->sk_nx_info, ireq->rmt_addr);
24616         r->idiag_expires = jiffies_to_msecs(tmo);
24617         r->idiag_rqueue = 0;
24618         r->idiag_wqueue = 0;
24619 @@ -683,6 +691,7 @@ static int inet_diag_dump_reqs(struct sk
24620                                 continue;
24621  
24622                         if (bc) {
24623 +                               /* TODO: lback */
24624                                 entry.saddr =
24625  #if IS_ENABLED(CONFIG_IPV6)
24626                                         (entry.family == AF_INET6) ?
24627 @@ -748,6 +757,8 @@ void inet_diag_dump_icsk(struct inet_has
24628                                 if (!net_eq(sock_net(sk), net))
24629                                         continue;
24630  
24631 +                               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
24632 +                                       continue;
24633                                 if (num < s_num) {
24634                                         num++;
24635                                         continue;
24636 @@ -820,6 +831,8 @@ skip_listen_ht:
24637  
24638                         if (!net_eq(sock_net(sk), net))
24639                                 continue;
24640 +                       if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
24641 +                               continue;
24642                         if (num < s_num)
24643                                 goto next_normal;
24644                         if (!(r->idiag_states & (1 << sk->sk_state)))
24645 @@ -848,7 +861,8 @@ next_normal:
24646                                     &head->twchain) {
24647                                 if (!net_eq(twsk_net(tw), net))
24648                                         continue;
24649 -
24650 +                               if (!nx_check(tw->tw_nid, VS_WATCH_P | VS_IDENT))
24651 +                                       continue;
24652                                 if (num < s_num)
24653                                         goto next_dying;
24654                                 if (r->sdiag_family != AF_UNSPEC &&
24655 diff -NurpP --minimal linux-3.6.9/net/ipv4/inet_hashtables.c linux-3.6.9-vs2.3.4.4/net/ipv4/inet_hashtables.c
24656 --- linux-3.6.9/net/ipv4/inet_hashtables.c      2012-07-22 23:39:48.000000000 +0200
24657 +++ linux-3.6.9-vs2.3.4.4/net/ipv4/inet_hashtables.c    2012-10-04 18:47:00.000000000 +0200
24658 @@ -22,6 +22,7 @@
24659  #include <net/inet_connection_sock.h>
24660  #include <net/inet_hashtables.h>
24661  #include <net/secure_seq.h>
24662 +#include <net/route.h>
24663  #include <net/ip.h>
24664  
24665  /*
24666 @@ -156,6 +157,11 @@ static inline int compute_score(struct s
24667                         if (rcv_saddr != daddr)
24668                                 return -1;
24669                         score += 2;
24670 +               } else {
24671 +                       /* block non nx_info ips */
24672 +                       if (!v4_addr_in_nx_info(sk->sk_nx_info,
24673 +                               daddr, NXA_MASK_BIND))
24674 +                               return -1;
24675                 }
24676                 if (sk->sk_bound_dev_if) {
24677                         if (sk->sk_bound_dev_if != dif)
24678 @@ -173,7 +179,6 @@ static inline int compute_score(struct s
24679   * wildcarded during the search since they can never be otherwise.
24680   */
24681  
24682 -
24683  struct sock *__inet_lookup_listener(struct net *net,
24684                                     struct inet_hashinfo *hashinfo,
24685                                     const __be32 daddr, const unsigned short hnum,
24686 @@ -196,6 +201,7 @@ begin:
24687                         hiscore = score;
24688                 }
24689         }
24690 +
24691         /*
24692          * if the nulls value we got at the end of this lookup is
24693          * not the expected one, we must restart lookup.
24694 diff -NurpP --minimal linux-3.6.9/net/ipv4/netfilter/nf_nat_helper.c linux-3.6.9-vs2.3.4.4/net/ipv4/netfilter/nf_nat_helper.c
24695 --- linux-3.6.9/net/ipv4/netfilter/nf_nat_helper.c      2012-10-04 15:27:50.000000000 +0200
24696 +++ linux-3.6.9-vs2.3.4.4/net/ipv4/netfilter/nf_nat_helper.c    2012-10-04 18:47:00.000000000 +0200
24697 @@ -20,6 +20,7 @@
24698  #include <net/route.h>
24699  
24700  #include <linux/netfilter_ipv4.h>
24701 +#include <net/route.h>
24702  #include <net/netfilter/nf_conntrack.h>
24703  #include <net/netfilter/nf_conntrack_helper.h>
24704  #include <net/netfilter/nf_conntrack_ecache.h>
24705 diff -NurpP --minimal linux-3.6.9/net/ipv4/netfilter.c linux-3.6.9-vs2.3.4.4/net/ipv4/netfilter.c
24706 --- linux-3.6.9/net/ipv4/netfilter.c    2012-07-22 23:39:48.000000000 +0200
24707 +++ linux-3.6.9-vs2.3.4.4/net/ipv4/netfilter.c  2012-10-04 18:47:00.000000000 +0200
24708 @@ -6,7 +6,7 @@
24709  #include <linux/skbuff.h>
24710  #include <linux/gfp.h>
24711  #include <linux/export.h>
24712 -#include <net/route.h>
24713 +// #include <net/route.h>
24714  #include <net/xfrm.h>
24715  #include <net/ip.h>
24716  #include <net/netfilter/nf_queue.h>
24717 diff -NurpP --minimal linux-3.6.9/net/ipv4/raw.c linux-3.6.9-vs2.3.4.4/net/ipv4/raw.c
24718 --- linux-3.6.9/net/ipv4/raw.c  2012-10-04 15:27:50.000000000 +0200
24719 +++ linux-3.6.9-vs2.3.4.4/net/ipv4/raw.c        2012-10-04 18:47:00.000000000 +0200
24720 @@ -118,7 +118,7 @@ static struct sock *__raw_v4_lookup(stru
24721  
24722                 if (net_eq(sock_net(sk), net) && inet->inet_num == num  &&
24723                     !(inet->inet_daddr && inet->inet_daddr != raddr)    &&
24724 -                   !(inet->inet_rcv_saddr && inet->inet_rcv_saddr != laddr) &&
24725 +                   v4_sock_addr_match(sk->sk_nx_info, inet, laddr)     &&
24726                     !(sk->sk_bound_dev_if && sk->sk_bound_dev_if != dif))
24727                         goto found; /* gotcha */
24728         }
24729 @@ -397,6 +397,12 @@ static int raw_send_hdrinc(struct sock *
24730                 icmp_out_count(net, ((struct icmphdr *)
24731                         skb_transport_header(skb))->type);
24732  
24733 +       err = -EPERM;
24734 +       if (!nx_check(0, VS_ADMIN) && !capable(CAP_NET_RAW) &&
24735 +               sk->sk_nx_info &&
24736 +               !v4_addr_in_nx_info(sk->sk_nx_info, iph->saddr, NXA_MASK_BIND))
24737 +               goto error_free;
24738 +
24739         err = NF_HOOK(NFPROTO_IPV4, NF_INET_LOCAL_OUT, skb, NULL,
24740                       rt->dst.dev, dst_output);
24741         if (err > 0)
24742 @@ -582,6 +588,16 @@ static int raw_sendmsg(struct kiocb *ioc
24743                         goto done;
24744         }
24745  
24746 +       if (sk->sk_nx_info) {
24747 +               rt = ip_v4_find_src(sock_net(sk), sk->sk_nx_info, &fl4);
24748 +               if (IS_ERR(rt)) {
24749 +                       err = PTR_ERR(rt);
24750 +                       rt = NULL;
24751 +                       goto done;
24752 +               }
24753 +               ip_rt_put(rt);
24754 +       }
24755 +
24756         security_sk_classify_flow(sk, flowi4_to_flowi(&fl4));
24757         rt = ip_route_output_flow(sock_net(sk), &fl4, sk);
24758         if (IS_ERR(rt)) {
24759 @@ -658,17 +674,19 @@ static int raw_bind(struct sock *sk, str
24760  {
24761         struct inet_sock *inet = inet_sk(sk);
24762         struct sockaddr_in *addr = (struct sockaddr_in *) uaddr;
24763 +       struct nx_v4_sock_addr nsa = { 0 };
24764         int ret = -EINVAL;
24765         int chk_addr_ret;
24766  
24767         if (sk->sk_state != TCP_CLOSE || addr_len < sizeof(struct sockaddr_in))
24768                 goto out;
24769 -       chk_addr_ret = inet_addr_type(sock_net(sk), addr->sin_addr.s_addr);
24770 +       v4_map_sock_addr(inet, addr, &nsa);
24771 +       chk_addr_ret = inet_addr_type(sock_net(sk), nsa.saddr);
24772         ret = -EADDRNOTAVAIL;
24773 -       if (addr->sin_addr.s_addr && chk_addr_ret != RTN_LOCAL &&
24774 +       if (nsa.saddr && chk_addr_ret != RTN_LOCAL &&
24775             chk_addr_ret != RTN_MULTICAST && chk_addr_ret != RTN_BROADCAST)
24776                 goto out;
24777 -       inet->inet_rcv_saddr = inet->inet_saddr = addr->sin_addr.s_addr;
24778 +       v4_set_sock_addr(inet, &nsa);
24779         if (chk_addr_ret == RTN_MULTICAST || chk_addr_ret == RTN_BROADCAST)
24780                 inet->inet_saddr = 0;  /* Use device */
24781         sk_dst_reset(sk);
24782 @@ -720,7 +738,8 @@ static int raw_recvmsg(struct kiocb *ioc
24783         /* Copy the address. */
24784         if (sin) {
24785                 sin->sin_family = AF_INET;
24786 -               sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
24787 +               sin->sin_addr.s_addr =
24788 +                       nx_map_sock_lback(sk->sk_nx_info, ip_hdr(skb)->saddr);
24789                 sin->sin_port = 0;
24790                 memset(&sin->sin_zero, 0, sizeof(sin->sin_zero));
24791         }
24792 @@ -916,7 +935,8 @@ static struct sock *raw_get_first(struct
24793                 struct hlist_node *node;
24794  
24795                 sk_for_each(sk, node, &state->h->ht[state->bucket])
24796 -                       if (sock_net(sk) == seq_file_net(seq))
24797 +                       if ((sock_net(sk) == seq_file_net(seq)) &&
24798 +                               nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
24799                                 goto found;
24800         }
24801         sk = NULL;
24802 @@ -932,7 +952,8 @@ static struct sock *raw_get_next(struct 
24803                 sk = sk_next(sk);
24804  try_again:
24805                 ;
24806 -       } while (sk && sock_net(sk) != seq_file_net(seq));
24807 +       } while (sk && ((sock_net(sk) != seq_file_net(seq)) ||
24808 +               !nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT)));
24809  
24810         if (!sk && ++state->bucket < RAW_HTABLE_SIZE) {
24811                 sk = sk_head(&state->h->ht[state->bucket]);
24812 diff -NurpP --minimal linux-3.6.9/net/ipv4/route.c linux-3.6.9-vs2.3.4.4/net/ipv4/route.c
24813 --- linux-3.6.9/net/ipv4/route.c        2012-12-08 01:34:15.000000000 +0100
24814 +++ linux-3.6.9-vs2.3.4.4/net/ipv4/route.c      2012-12-08 01:36:33.000000000 +0100
24815 @@ -1949,7 +1949,7 @@ struct rtable *__ip_route_output_key(str
24816  
24817  
24818         if (fl4->flowi4_oif) {
24819 -               dev_out = dev_get_by_index_rcu(net, fl4->flowi4_oif);
24820 +               dev_out = dev_get_by_index_real_rcu(net, fl4->flowi4_oif);
24821                 rth = ERR_PTR(-ENODEV);
24822                 if (dev_out == NULL)
24823                         goto out;
24824 diff -NurpP --minimal linux-3.6.9/net/ipv4/tcp.c linux-3.6.9-vs2.3.4.4/net/ipv4/tcp.c
24825 --- linux-3.6.9/net/ipv4/tcp.c  2012-12-08 01:34:16.000000000 +0100
24826 +++ linux-3.6.9-vs2.3.4.4/net/ipv4/tcp.c        2012-12-08 01:36:33.000000000 +0100
24827 @@ -268,6 +268,7 @@
24828  #include <linux/crypto.h>
24829  #include <linux/time.h>
24830  #include <linux/slab.h>
24831 +#include <linux/in.h>
24832  
24833  #include <net/icmp.h>
24834  #include <net/inet_common.h>
24835 diff -NurpP --minimal linux-3.6.9/net/ipv4/tcp_ipv4.c linux-3.6.9-vs2.3.4.4/net/ipv4/tcp_ipv4.c
24836 --- linux-3.6.9/net/ipv4/tcp_ipv4.c     2012-12-08 01:34:16.000000000 +0100
24837 +++ linux-3.6.9-vs2.3.4.4/net/ipv4/tcp_ipv4.c   2012-11-06 18:43:41.000000000 +0100
24838 @@ -2034,6 +2034,12 @@ static void *listening_get_next(struct s
24839                 req = req->dl_next;
24840                 while (1) {
24841                         while (req) {
24842 +                               vxdprintk(VXD_CBIT(net, 6),
24843 +                                       "sk,req: %p [#%d] (from %d)", req->sk,
24844 +                                       (req->sk)?req->sk->sk_nid:0, nx_current_nid());
24845 +                               if (req->sk &&
24846 +                                       !nx_check(req->sk->sk_nid, VS_WATCH_P | VS_IDENT))
24847 +                                       continue;
24848                                 if (req->rsk_ops->family == st->family) {
24849                                         cur = req;
24850                                         goto out;
24851 @@ -2058,6 +2064,10 @@ get_req:
24852         }
24853  get_sk:
24854         sk_nulls_for_each_from(sk, node) {
24855 +               vxdprintk(VXD_CBIT(net, 6), "sk: %p [#%d] (from %d)",
24856 +                       sk, sk->sk_nid, nx_current_nid());
24857 +               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
24858 +                       continue;
24859                 if (!net_eq(sock_net(sk), net))
24860                         continue;
24861                 if (sk->sk_family == st->family) {
24862 @@ -2134,6 +2144,11 @@ static void *established_get_first(struc
24863  
24864                 spin_lock_bh(lock);
24865                 sk_nulls_for_each(sk, node, &tcp_hashinfo.ehash[st->bucket].chain) {
24866 +                       vxdprintk(VXD_CBIT(net, 6),
24867 +                               "sk,egf: %p [#%d] (from %d)",
24868 +                               sk, sk->sk_nid, nx_current_nid());
24869 +                       if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
24870 +                               continue;
24871                         if (sk->sk_family != st->family ||
24872                             !net_eq(sock_net(sk), net)) {
24873                                 continue;
24874 @@ -2144,6 +2159,11 @@ static void *established_get_first(struc
24875                 st->state = TCP_SEQ_STATE_TIME_WAIT;
24876                 inet_twsk_for_each(tw, node,
24877                                    &tcp_hashinfo.ehash[st->bucket].twchain) {
24878 +                       vxdprintk(VXD_CBIT(net, 6),
24879 +                               "tw: %p [#%d] (from %d)",
24880 +                               tw, tw->tw_nid, nx_current_nid());
24881 +                       if (!nx_check(tw->tw_nid, VS_WATCH_P | VS_IDENT))
24882 +                               continue;
24883                         if (tw->tw_family != st->family ||
24884                             !net_eq(twsk_net(tw), net)) {
24885                                 continue;
24886 @@ -2173,7 +2193,9 @@ static void *established_get_next(struct
24887                 tw = cur;
24888                 tw = tw_next(tw);
24889  get_tw:
24890 -               while (tw && (tw->tw_family != st->family || !net_eq(twsk_net(tw), net))) {
24891 +               while (tw && (tw->tw_family != st->family ||
24892 +                       !net_eq(twsk_net(tw), net) ||
24893 +                       !nx_check(tw->tw_nid, VS_WATCH_P | VS_IDENT))) {
24894                         tw = tw_next(tw);
24895                 }
24896                 if (tw) {
24897 @@ -2197,6 +2219,11 @@ get_tw:
24898                 sk = sk_nulls_next(sk);
24899  
24900         sk_nulls_for_each_from(sk, node) {
24901 +               vxdprintk(VXD_CBIT(net, 6),
24902 +                       "sk,egn: %p [#%d] (from %d)",
24903 +                       sk, sk->sk_nid, nx_current_nid());
24904 +               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
24905 +                       continue;
24906                 if (sk->sk_family == st->family && net_eq(sock_net(sk), net))
24907                         goto found;
24908         }
24909 @@ -2402,9 +2429,9 @@ static void get_openreq4(const struct so
24910         seq_printf(f, "%4d: %08X:%04X %08X:%04X"
24911                 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %u %d %pK%n",
24912                 i,
24913 -               ireq->loc_addr,
24914 +               nx_map_sock_lback(current_nx_info(), ireq->loc_addr),
24915                 ntohs(inet_sk(sk)->inet_sport),
24916 -               ireq->rmt_addr,
24917 +               nx_map_sock_lback(current_nx_info(), ireq->rmt_addr),
24918                 ntohs(ireq->rmt_port),
24919                 TCP_SYN_RECV,
24920                 0, 0, /* could print option size, but that is af dependent. */
24921 @@ -2426,8 +2453,8 @@ static void get_tcp4_sock(struct sock *s
24922         const struct tcp_sock *tp = tcp_sk(sk);
24923         const struct inet_connection_sock *icsk = inet_csk(sk);
24924         const struct inet_sock *inet = inet_sk(sk);
24925 -       __be32 dest = inet->inet_daddr;
24926 -       __be32 src = inet->inet_rcv_saddr;
24927 +       __be32 dest = nx_map_sock_lback(current_nx_info(), inet->inet_daddr);
24928 +       __be32 src = nx_map_sock_lback(current_nx_info(), inet->inet_rcv_saddr);
24929         __u16 destp = ntohs(inet->inet_dport);
24930         __u16 srcp = ntohs(inet->inet_sport);
24931         int rx_queue;
24932 @@ -2484,8 +2511,8 @@ static void get_timewait4_sock(const str
24933         if (ttd < 0)
24934                 ttd = 0;
24935  
24936 -       dest  = tw->tw_daddr;
24937 -       src   = tw->tw_rcv_saddr;
24938 +       dest  = nx_map_sock_lback(current_nx_info(), tw->tw_daddr);
24939 +       src   = nx_map_sock_lback(current_nx_info(), tw->tw_rcv_saddr);
24940         destp = ntohs(tw->tw_dport);
24941         srcp  = ntohs(tw->tw_sport);
24942  
24943 diff -NurpP --minimal linux-3.6.9/net/ipv4/tcp_minisocks.c linux-3.6.9-vs2.3.4.4/net/ipv4/tcp_minisocks.c
24944 --- linux-3.6.9/net/ipv4/tcp_minisocks.c        2012-10-04 15:27:50.000000000 +0200
24945 +++ linux-3.6.9-vs2.3.4.4/net/ipv4/tcp_minisocks.c      2012-10-04 18:47:00.000000000 +0200
24946 @@ -23,6 +23,9 @@
24947  #include <linux/slab.h>
24948  #include <linux/sysctl.h>
24949  #include <linux/workqueue.h>
24950 +#include <linux/vs_limit.h>
24951 +#include <linux/vs_socket.h>
24952 +#include <linux/vs_context.h>
24953  #include <net/tcp.h>
24954  #include <net/inet_common.h>
24955  #include <net/xfrm.h>
24956 @@ -287,6 +290,11 @@ void tcp_time_wait(struct sock *sk, int 
24957                 tcptw->tw_ts_recent     = tp->rx_opt.ts_recent;
24958                 tcptw->tw_ts_recent_stamp = tp->rx_opt.ts_recent_stamp;
24959  
24960 +               tw->tw_xid              = sk->sk_xid;
24961 +               tw->tw_vx_info          = NULL;
24962 +               tw->tw_nid              = sk->sk_nid;
24963 +               tw->tw_nx_info          = NULL;
24964 +
24965  #if IS_ENABLED(CONFIG_IPV6)
24966                 if (tw->tw_family == PF_INET6) {
24967                         struct ipv6_pinfo *np = inet6_sk(sk);
24968 diff -NurpP --minimal linux-3.6.9/net/ipv4/udp.c linux-3.6.9-vs2.3.4.4/net/ipv4/udp.c
24969 --- linux-3.6.9/net/ipv4/udp.c  2012-10-04 15:27:50.000000000 +0200
24970 +++ linux-3.6.9-vs2.3.4.4/net/ipv4/udp.c        2012-10-04 18:47:00.000000000 +0200
24971 @@ -300,14 +300,7 @@ fail:
24972  }
24973  EXPORT_SYMBOL(udp_lib_get_port);
24974  
24975 -static int ipv4_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2)
24976 -{
24977 -       struct inet_sock *inet1 = inet_sk(sk1), *inet2 = inet_sk(sk2);
24978 -
24979 -       return  (!ipv6_only_sock(sk2)  &&
24980 -                (!inet1->inet_rcv_saddr || !inet2->inet_rcv_saddr ||
24981 -                  inet1->inet_rcv_saddr == inet2->inet_rcv_saddr));
24982 -}
24983 +extern int ipv4_rcv_saddr_equal(const struct sock *, const struct sock *);
24984  
24985  static unsigned int udp4_portaddr_hash(struct net *net, __be32 saddr,
24986                                        unsigned int port)
24987 @@ -342,6 +335,11 @@ static inline int compute_score(struct s
24988                         if (inet->inet_rcv_saddr != daddr)
24989                                 return -1;
24990                         score += 2;
24991 +               } else {
24992 +                       /* block non nx_info ips */
24993 +                       if (!v4_addr_in_nx_info(sk->sk_nx_info,
24994 +                               daddr, NXA_MASK_BIND))
24995 +                               return -1;
24996                 }
24997                 if (inet->inet_daddr) {
24998                         if (inet->inet_daddr != saddr)
24999 @@ -445,6 +443,7 @@ exact_match:
25000         return result;
25001  }
25002  
25003 +
25004  /* UDP is nearly always wildcards out the wazoo, it makes no sense to try
25005   * harder than this. -DaveM
25006   */
25007 @@ -490,6 +489,11 @@ begin:
25008         sk_nulls_for_each_rcu(sk, node, &hslot->head) {
25009                 score = compute_score(sk, net, saddr, hnum, sport,
25010                                       daddr, dport, dif);
25011 +               /* FIXME: disabled?
25012 +               if (score == 9) {
25013 +                       result = sk;
25014 +                       break;
25015 +               } else */
25016                 if (score > badness) {
25017                         result = sk;
25018                         badness = score;
25019 @@ -503,6 +507,7 @@ begin:
25020         if (get_nulls_value(node) != slot)
25021                 goto begin;
25022  
25023 +
25024         if (result) {
25025                 if (unlikely(!atomic_inc_not_zero_hint(&result->sk_refcnt, 2)))
25026                         result = NULL;
25027 @@ -512,6 +517,7 @@ begin:
25028                         goto begin;
25029                 }
25030         }
25031 +
25032         rcu_read_unlock();
25033         return result;
25034  }
25035 @@ -555,8 +561,7 @@ static inline struct sock *udp_v4_mcast_
25036                     udp_sk(s)->udp_port_hash != hnum ||
25037                     (inet->inet_daddr && inet->inet_daddr != rmt_addr) ||
25038                     (inet->inet_dport != rmt_port && inet->inet_dport) ||
25039 -                   (inet->inet_rcv_saddr &&
25040 -                    inet->inet_rcv_saddr != loc_addr) ||
25041 +                   !v4_sock_addr_match(sk->sk_nx_info, inet, loc_addr) ||
25042                     ipv6_only_sock(s) ||
25043                     (s->sk_bound_dev_if && s->sk_bound_dev_if != dif))
25044                         continue;
25045 @@ -939,6 +944,16 @@ int udp_sendmsg(struct kiocb *iocb, stru
25046                                    inet_sk_flowi_flags(sk)|FLOWI_FLAG_CAN_SLEEP,
25047                                    faddr, saddr, dport, inet->inet_sport);
25048  
25049 +               if (sk->sk_nx_info) {
25050 +                       rt = ip_v4_find_src(net, sk->sk_nx_info, fl4);
25051 +                       if (IS_ERR(rt)) {
25052 +                               err = PTR_ERR(rt);
25053 +                               rt = NULL;
25054 +                               goto out;
25055 +                       }
25056 +                       ip_rt_put(rt);
25057 +               }
25058 +
25059                 security_sk_classify_flow(sk, flowi4_to_flowi(fl4));
25060                 rt = ip_route_output_flow(net, fl4, sk);
25061                 if (IS_ERR(rt)) {
25062 @@ -1244,7 +1259,8 @@ try_again:
25063         if (sin) {
25064                 sin->sin_family = AF_INET;
25065                 sin->sin_port = udp_hdr(skb)->source;
25066 -               sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
25067 +               sin->sin_addr.s_addr = nx_map_sock_lback(
25068 +                       skb->sk->sk_nx_info, ip_hdr(skb)->saddr);
25069                 memset(sin->sin_zero, 0, sizeof(sin->sin_zero));
25070         }
25071         if (inet->cmsg_flags)
25072 @@ -1992,6 +2008,8 @@ static struct sock *udp_get_first(struct
25073                 sk_nulls_for_each(sk, node, &hslot->head) {
25074                         if (!net_eq(sock_net(sk), net))
25075                                 continue;
25076 +                       if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
25077 +                               continue;
25078                         if (sk->sk_family == state->family)
25079                                 goto found;
25080                 }
25081 @@ -2009,7 +2027,9 @@ static struct sock *udp_get_next(struct 
25082  
25083         do {
25084                 sk = sk_nulls_next(sk);
25085 -       } while (sk && (!net_eq(sock_net(sk), net) || sk->sk_family != state->family));
25086 +       } while (sk && (!net_eq(sock_net(sk), net) ||
25087 +               sk->sk_family != state->family ||
25088 +               !nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT)));
25089  
25090         if (!sk) {
25091                 if (state->bucket <= state->udp_table->mask)
25092 @@ -2105,8 +2125,8 @@ static void udp4_format_sock(struct sock
25093                 int bucket, int *len)
25094  {
25095         struct inet_sock *inet = inet_sk(sp);
25096 -       __be32 dest = inet->inet_daddr;
25097 -       __be32 src  = inet->inet_rcv_saddr;
25098 +       __be32 dest = nx_map_sock_lback(current_nx_info(), inet->inet_daddr);
25099 +       __be32 src = nx_map_sock_lback(current_nx_info(), inet->inet_rcv_saddr);
25100         __u16 destp       = ntohs(inet->inet_dport);
25101         __u16 srcp        = ntohs(inet->inet_sport);
25102  
25103 diff -NurpP --minimal linux-3.6.9/net/ipv6/Kconfig linux-3.6.9-vs2.3.4.4/net/ipv6/Kconfig
25104 --- linux-3.6.9/net/ipv6/Kconfig        2012-07-22 23:39:48.000000000 +0200
25105 +++ linux-3.6.9-vs2.3.4.4/net/ipv6/Kconfig      2012-10-04 18:47:00.000000000 +0200
25106 @@ -4,8 +4,8 @@
25107  
25108  #   IPv6 as module will cause a CRASH if you try to unload it
25109  menuconfig IPV6
25110 -       tristate "The IPv6 protocol"
25111 -       default m
25112 +       bool "The IPv6 protocol"
25113 +       default n
25114         ---help---
25115           This is complemental support for the IP version 6.
25116           You will still be able to do traditional IPv4 networking as well.
25117 diff -NurpP --minimal linux-3.6.9/net/ipv6/addrconf.c linux-3.6.9-vs2.3.4.4/net/ipv6/addrconf.c
25118 --- linux-3.6.9/net/ipv6/addrconf.c     2012-12-08 01:34:16.000000000 +0100
25119 +++ linux-3.6.9-vs2.3.4.4/net/ipv6/addrconf.c   2012-11-06 18:43:41.000000000 +0100
25120 @@ -92,6 +92,8 @@
25121  #include <linux/proc_fs.h>
25122  #include <linux/seq_file.h>
25123  #include <linux/export.h>
25124 +#include <linux/vs_network.h>
25125 +#include <linux/vs_inet6.h>
25126  
25127  /* Set to 3 to get tracing... */
25128  #define ACONF_DEBUG 2
25129 @@ -1101,7 +1103,7 @@ out:
25130  
25131  int ipv6_dev_get_saddr(struct net *net, struct net_device *dst_dev,
25132                        const struct in6_addr *daddr, unsigned int prefs,
25133 -                      struct in6_addr *saddr)
25134 +                      struct in6_addr *saddr, struct nx_info *nxi)
25135  {
25136         struct ipv6_saddr_score scores[2],
25137                                 *score = &scores[0], *hiscore = &scores[1];
25138 @@ -1173,6 +1175,8 @@ int ipv6_dev_get_saddr(struct net *net, 
25139                                                dev->name);
25140                                 continue;
25141                         }
25142 +                       if (!v6_addr_in_nx_info(nxi, &score->ifa->addr, -1))
25143 +                               continue;
25144  
25145                         score->rule = -1;
25146                         bitmap_zero(score->scorebits, IPV6_SADDR_RULE_MAX);
25147 @@ -3159,7 +3163,10 @@ static void if6_seq_stop(struct seq_file
25148  static int if6_seq_show(struct seq_file *seq, void *v)
25149  {
25150         struct inet6_ifaddr *ifp = (struct inet6_ifaddr *)v;
25151 -       seq_printf(seq, "%pi6 %02x %02x %02x %02x %8s\n",
25152 +
25153 +       if (nx_check(0, VS_ADMIN|VS_WATCH) ||
25154 +           v6_addr_in_nx_info(current_nx_info(), &ifp->addr, -1))
25155 +               seq_printf(seq, "%pi6 %02x %02x %02x %02x %8s\n",
25156                    &ifp->addr,
25157                    ifp->idev->dev->ifindex,
25158                    ifp->prefix_len,
25159 @@ -3665,6 +3672,11 @@ static int in6_dump_addrs(struct inet6_d
25160         struct ifacaddr6 *ifaca;
25161         int err = 1;
25162         int ip_idx = *p_ip_idx;
25163 +       struct nx_info *nxi = skb->sk ? skb->sk->sk_nx_info : NULL;
25164 +
25165 +       /* disable ipv6 on non v6 guests */
25166 +       if (nxi && !nx_info_has_v6(nxi))
25167 +               return skb->len;
25168  
25169         read_lock_bh(&idev->lock);
25170         switch (type) {
25171 @@ -3675,6 +3687,8 @@ static int in6_dump_addrs(struct inet6_d
25172                 list_for_each_entry(ifa, &idev->addr_list, if_list) {
25173                         if (++ip_idx < s_ip_idx)
25174                                 continue;
25175 +                               if (!v6_addr_in_nx_info(nxi, &ifa->addr, -1))
25176 +                                       continue;
25177                         err = inet6_fill_ifaddr(skb, ifa,
25178                                                 NETLINK_CB(cb->skb).pid,
25179                                                 cb->nlh->nlmsg_seq,
25180 @@ -3691,6 +3705,8 @@ static int in6_dump_addrs(struct inet6_d
25181                      ifmca = ifmca->next, ip_idx++) {
25182                         if (ip_idx < s_ip_idx)
25183                                 continue;
25184 +                               if (!v6_addr_in_nx_info(nxi, &ifmca->mca_addr, -1))
25185 +                                       continue;
25186                         err = inet6_fill_ifmcaddr(skb, ifmca,
25187                                                   NETLINK_CB(cb->skb).pid,
25188                                                   cb->nlh->nlmsg_seq,
25189 @@ -3706,6 +3722,8 @@ static int in6_dump_addrs(struct inet6_d
25190                      ifaca = ifaca->aca_next, ip_idx++) {
25191                         if (ip_idx < s_ip_idx)
25192                                 continue;
25193 +                               if (!v6_addr_in_nx_info(nxi, &ifaca->aca_addr, -1))
25194 +                                       continue;
25195                         err = inet6_fill_ifacaddr(skb, ifaca,
25196                                                   NETLINK_CB(cb->skb).pid,
25197                                                   cb->nlh->nlmsg_seq,
25198 @@ -4089,6 +4107,11 @@ static int inet6_dump_ifinfo(struct sk_b
25199         struct inet6_dev *idev;
25200         struct hlist_head *head;
25201         struct hlist_node *node;
25202 +       struct nx_info *nxi = skb->sk ? skb->sk->sk_nx_info : NULL;
25203 +
25204 +       /* FIXME: maybe disable ipv6 on non v6 guests?
25205 +       if (skb->sk && skb->sk->sk_vx_info)
25206 +               return skb->len; */
25207  
25208         s_h = cb->args[0];
25209         s_idx = cb->args[1];
25210 @@ -4100,6 +4123,8 @@ static int inet6_dump_ifinfo(struct sk_b
25211                 hlist_for_each_entry_rcu(dev, node, head, index_hlist) {
25212                         if (idx < s_idx)
25213                                 goto cont;
25214 +                       if (!v6_dev_in_nx_info(dev, nxi))
25215 +                               goto cont;
25216                         idev = __in6_dev_get(dev);
25217                         if (!idev)
25218                                 goto cont;
25219 diff -NurpP --minimal linux-3.6.9/net/ipv6/af_inet6.c linux-3.6.9-vs2.3.4.4/net/ipv6/af_inet6.c
25220 --- linux-3.6.9/net/ipv6/af_inet6.c     2012-12-08 01:34:16.000000000 +0100
25221 +++ linux-3.6.9-vs2.3.4.4/net/ipv6/af_inet6.c   2012-11-06 18:43:41.000000000 +0100
25222 @@ -43,6 +43,8 @@
25223  #include <linux/netdevice.h>
25224  #include <linux/icmpv6.h>
25225  #include <linux/netfilter_ipv6.h>
25226 +#include <linux/vs_inet.h>
25227 +#include <linux/vs_inet6.h>
25228  
25229  #include <net/ip.h>
25230  #include <net/ipv6.h>
25231 @@ -160,9 +162,12 @@ lookup_protocol:
25232         }
25233  
25234         err = -EPERM;
25235 +       if ((protocol == IPPROTO_ICMPV6) &&
25236 +               nx_capable(CAP_NET_RAW, NXC_RAW_ICMP))
25237 +               goto override;
25238         if (sock->type == SOCK_RAW && !kern && !capable(CAP_NET_RAW))
25239                 goto out_rcu_unlock;
25240 -
25241 +override:
25242         sock->ops = answer->ops;
25243         answer_prot = answer->prot;
25244         answer_no_check = answer->no_check;
25245 @@ -262,6 +267,7 @@ int inet6_bind(struct socket *sock, stru
25246         struct inet_sock *inet = inet_sk(sk);
25247         struct ipv6_pinfo *np = inet6_sk(sk);
25248         struct net *net = sock_net(sk);
25249 +       struct nx_v6_sock_addr nsa;
25250         __be32 v4addr = 0;
25251         unsigned short snum;
25252         int addr_type = 0;
25253 @@ -277,6 +283,10 @@ int inet6_bind(struct socket *sock, stru
25254         if (addr->sin6_family != AF_INET6)
25255                 return -EAFNOSUPPORT;
25256  
25257 +       err = v6_map_sock_addr(inet, addr, &nsa);
25258 +       if (err)
25259 +               return err;
25260 +
25261         addr_type = ipv6_addr_type(&addr->sin6_addr);
25262         if ((addr_type & IPV6_ADDR_MULTICAST) && sock->type == SOCK_STREAM)
25263                 return -EINVAL;
25264 @@ -308,6 +318,7 @@ int inet6_bind(struct socket *sock, stru
25265                 /* Reproduce AF_INET checks to make the bindings consistent */
25266                 v4addr = addr->sin6_addr.s6_addr32[3];
25267                 chk_addr_ret = inet_addr_type(net, v4addr);
25268 +
25269                 if (!sysctl_ip_nonlocal_bind &&
25270                     !(inet->freebind || inet->transparent) &&
25271                     v4addr != htonl(INADDR_ANY) &&
25272 @@ -317,6 +328,10 @@ int inet6_bind(struct socket *sock, stru
25273                         err = -EADDRNOTAVAIL;
25274                         goto out;
25275                 }
25276 +               if (!v4_addr_in_nx_info(sk->sk_nx_info, v4addr, NXA_MASK_BIND)) {
25277 +                       err = -EADDRNOTAVAIL;
25278 +                       goto out;
25279 +               }
25280         } else {
25281                 if (addr_type != IPV6_ADDR_ANY) {
25282                         struct net_device *dev = NULL;
25283 @@ -343,6 +358,11 @@ int inet6_bind(struct socket *sock, stru
25284                                 }
25285                         }
25286  
25287 +                       if (!v6_addr_in_nx_info(sk->sk_nx_info, &addr->sin6_addr, -1)) {
25288 +                               err = -EADDRNOTAVAIL;
25289 +                               goto out_unlock;
25290 +                       }
25291 +
25292                         /* ipv4 addr of the socket is invalid.  Only the
25293                          * unspecified and mapped address have a v4 equivalent.
25294                          */
25295 @@ -359,6 +379,9 @@ int inet6_bind(struct socket *sock, stru
25296                 }
25297         }
25298  
25299 +       /* what's that for? */
25300 +       v6_set_sock_addr(inet, &nsa);
25301 +
25302         inet->inet_rcv_saddr = v4addr;
25303         inet->inet_saddr = v4addr;
25304  
25305 @@ -460,9 +483,11 @@ int inet6_getname(struct socket *sock, s
25306                         return -ENOTCONN;
25307                 sin->sin6_port = inet->inet_dport;
25308                 sin->sin6_addr = np->daddr;
25309 +               /* FIXME: remap lback? */
25310                 if (np->sndflow)
25311                         sin->sin6_flowinfo = np->flow_label;
25312         } else {
25313 +               /* FIXME: remap lback? */
25314                 if (ipv6_addr_any(&np->rcv_saddr))
25315                         sin->sin6_addr = np->saddr;
25316                 else
25317 diff -NurpP --minimal linux-3.6.9/net/ipv6/datagram.c linux-3.6.9-vs2.3.4.4/net/ipv6/datagram.c
25318 --- linux-3.6.9/net/ipv6/datagram.c     2012-07-22 23:39:48.000000000 +0200
25319 +++ linux-3.6.9-vs2.3.4.4/net/ipv6/datagram.c   2012-10-04 18:47:00.000000000 +0200
25320 @@ -645,7 +645,7 @@ int datagram_send_ctl(struct net *net, s
25321  
25322                         rcu_read_lock();
25323                         if (fl6->flowi6_oif) {
25324 -                               dev = dev_get_by_index_rcu(net, fl6->flowi6_oif);
25325 +                               dev = dev_get_by_index_real_rcu(net, fl6->flowi6_oif);
25326                                 if (!dev) {
25327                                         rcu_read_unlock();
25328                                         return -ENODEV;
25329 diff -NurpP --minimal linux-3.6.9/net/ipv6/fib6_rules.c linux-3.6.9-vs2.3.4.4/net/ipv6/fib6_rules.c
25330 --- linux-3.6.9/net/ipv6/fib6_rules.c   2012-07-22 23:39:48.000000000 +0200
25331 +++ linux-3.6.9-vs2.3.4.4/net/ipv6/fib6_rules.c 2012-10-04 18:47:00.000000000 +0200
25332 @@ -90,7 +90,7 @@ static int fib6_rule_action(struct fib_r
25333                                                ip6_dst_idev(&rt->dst)->dev,
25334                                                &flp6->daddr,
25335                                                rt6_flags2srcprefs(flags),
25336 -                                              &saddr))
25337 +                                              &saddr, NULL))
25338                                 goto again;
25339                         if (!ipv6_prefix_equal(&saddr, &r->src.addr,
25340                                                r->src.plen))
25341 diff -NurpP --minimal linux-3.6.9/net/ipv6/inet6_hashtables.c linux-3.6.9-vs2.3.4.4/net/ipv6/inet6_hashtables.c
25342 --- linux-3.6.9/net/ipv6/inet6_hashtables.c     2011-10-24 18:45:34.000000000 +0200
25343 +++ linux-3.6.9-vs2.3.4.4/net/ipv6/inet6_hashtables.c   2012-10-04 18:47:00.000000000 +0200
25344 @@ -16,6 +16,7 @@
25345  
25346  #include <linux/module.h>
25347  #include <linux/random.h>
25348 +#include <linux/vs_inet6.h>
25349  
25350  #include <net/inet_connection_sock.h>
25351  #include <net/inet_hashtables.h>
25352 @@ -83,7 +84,6 @@ struct sock *__inet6_lookup_established(
25353         unsigned int slot = hash & hashinfo->ehash_mask;
25354         struct inet_ehash_bucket *head = &hashinfo->ehash[slot];
25355  
25356 -
25357         rcu_read_lock();
25358  begin:
25359         sk_nulls_for_each_rcu(sk, node, &head->chain) {
25360 @@ -95,7 +95,7 @@ begin:
25361                                 sock_put(sk);
25362                                 goto begin;
25363                         }
25364 -               goto out;
25365 +                       goto out;
25366                 }
25367         }
25368         if (get_nulls_value(node) != slot)
25369 @@ -141,6 +141,9 @@ static inline int compute_score(struct s
25370                         if (!ipv6_addr_equal(&np->rcv_saddr, daddr))
25371                                 return -1;
25372                         score++;
25373 +               } else {
25374 +                       if (!v6_addr_in_nx_info(sk->sk_nx_info, daddr, -1))
25375 +                               return -1;
25376                 }
25377                 if (sk->sk_bound_dev_if) {
25378                         if (sk->sk_bound_dev_if != dif)
25379 diff -NurpP --minimal linux-3.6.9/net/ipv6/ip6_output.c linux-3.6.9-vs2.3.4.4/net/ipv6/ip6_output.c
25380 --- linux-3.6.9/net/ipv6/ip6_output.c   2012-10-04 15:27:50.000000000 +0200
25381 +++ linux-3.6.9-vs2.3.4.4/net/ipv6/ip6_output.c 2012-10-04 18:47:00.000000000 +0200
25382 @@ -966,7 +966,8 @@ static int ip6_dst_lookup_tail(struct so
25383                 struct rt6_info *rt = (struct rt6_info *) *dst;
25384                 err = ip6_route_get_saddr(net, rt, &fl6->daddr,
25385                                           sk ? inet6_sk(sk)->srcprefs : 0,
25386 -                                         &fl6->saddr);
25387 +                                         &fl6->saddr,
25388 +                                         sk ? sk->sk_nx_info : NULL);
25389                 if (err)
25390                         goto out_err_release;
25391         }
25392 diff -NurpP --minimal linux-3.6.9/net/ipv6/ndisc.c linux-3.6.9-vs2.3.4.4/net/ipv6/ndisc.c
25393 --- linux-3.6.9/net/ipv6/ndisc.c        2012-12-08 01:34:16.000000000 +0100
25394 +++ linux-3.6.9-vs2.3.4.4/net/ipv6/ndisc.c      2012-12-08 01:36:33.000000000 +0100
25395 @@ -517,7 +517,7 @@ static void ndisc_send_na(struct net_dev
25396         } else {
25397                 if (ipv6_dev_get_saddr(dev_net(dev), dev, daddr,
25398                                        inet6_sk(dev_net(dev)->ipv6.ndisc_sk)->srcprefs,
25399 -                                      &tmpaddr))
25400 +                                      &tmpaddr, NULL))
25401                         return;
25402                 src_addr = &tmpaddr;
25403         }
25404 diff -NurpP --minimal linux-3.6.9/net/ipv6/raw.c linux-3.6.9-vs2.3.4.4/net/ipv6/raw.c
25405 --- linux-3.6.9/net/ipv6/raw.c  2012-10-04 15:27:50.000000000 +0200
25406 +++ linux-3.6.9-vs2.3.4.4/net/ipv6/raw.c        2012-10-04 18:47:00.000000000 +0200
25407 @@ -30,6 +30,7 @@
25408  #include <linux/icmpv6.h>
25409  #include <linux/netfilter.h>
25410  #include <linux/netfilter_ipv6.h>
25411 +#include <linux/vs_inet6.h>
25412  #include <linux/skbuff.h>
25413  #include <linux/compat.h>
25414  #include <asm/uaccess.h>
25415 @@ -284,6 +285,13 @@ static int rawv6_bind(struct sock *sk, s
25416                                 goto out_unlock;
25417                 }
25418  
25419 +               if (!v6_addr_in_nx_info(sk->sk_nx_info, &addr->sin6_addr, -1)) {
25420 +                       err = -EADDRNOTAVAIL;
25421 +                       if (dev)
25422 +                               dev_put(dev);
25423 +                       goto out;
25424 +               }
25425 +
25426                 /* ipv4 addr of the socket is invalid.  Only the
25427                  * unspecified and mapped address have a v4 equivalent.
25428                  */
25429 diff -NurpP --minimal linux-3.6.9/net/ipv6/route.c linux-3.6.9-vs2.3.4.4/net/ipv6/route.c
25430 --- linux-3.6.9/net/ipv6/route.c        2012-12-08 01:34:16.000000000 +0100
25431 +++ linux-3.6.9-vs2.3.4.4/net/ipv6/route.c      2012-12-08 01:36:33.000000000 +0100
25432 @@ -57,6 +57,7 @@
25433  #include <net/xfrm.h>
25434  #include <net/netevent.h>
25435  #include <net/netlink.h>
25436 +#include <linux/vs_inet6.h>
25437  
25438  #include <asm/uaccess.h>
25439  
25440 @@ -2112,15 +2113,17 @@ int ip6_route_get_saddr(struct net *net,
25441                         struct rt6_info *rt,
25442                         const struct in6_addr *daddr,
25443                         unsigned int prefs,
25444 -                       struct in6_addr *saddr)
25445 +                       struct in6_addr *saddr,
25446 +                       struct nx_info *nxi)
25447  {
25448         struct inet6_dev *idev = ip6_dst_idev((struct dst_entry*)rt);
25449         int err = 0;
25450 -       if (rt->rt6i_prefsrc.plen)
25451 +       if (rt->rt6i_prefsrc.plen && (!nxi ||
25452 +           v6_addr_in_nx_info(nxi, &rt->rt6i_prefsrc.addr, NXA_TYPE_ADDR)))
25453                 *saddr = rt->rt6i_prefsrc.addr;
25454         else
25455                 err = ipv6_dev_get_saddr(net, idev ? idev->dev : NULL,
25456 -                                        daddr, prefs, saddr);
25457 +                                        daddr, prefs, saddr, nxi);
25458         return err;
25459  }
25460  
25461 @@ -2456,7 +2459,8 @@ static int rt6_fill_node(struct net *net
25462                                 goto nla_put_failure;
25463         } else if (dst) {
25464                 struct in6_addr saddr_buf;
25465 -               if (ip6_route_get_saddr(net, rt, dst, 0, &saddr_buf) == 0 &&
25466 +               if (ip6_route_get_saddr(net, rt, dst, 0, &saddr_buf,
25467 +                   (skb->sk ? skb->sk->sk_nx_info : NULL)) == 0 &&
25468                     nla_put(skb, RTA_PREFSRC, 16, &saddr_buf))
25469                         goto nla_put_failure;
25470         }
25471 @@ -2674,6 +2678,7 @@ static int rt6_info_route(struct rt6_inf
25472         struct seq_file *m = p_arg;
25473         struct neighbour *n;
25474  
25475 +       /* FIXME: check for network context? */
25476         seq_printf(m, "%pi6 %02x ", &rt->rt6i_dst.addr, rt->rt6i_dst.plen);
25477  
25478  #ifdef CONFIG_IPV6_SUBTREES
25479 diff -NurpP --minimal linux-3.6.9/net/ipv6/tcp_ipv6.c linux-3.6.9-vs2.3.4.4/net/ipv6/tcp_ipv6.c
25480 --- linux-3.6.9/net/ipv6/tcp_ipv6.c     2012-12-08 01:34:17.000000000 +0100
25481 +++ linux-3.6.9-vs2.3.4.4/net/ipv6/tcp_ipv6.c   2012-11-06 18:43:41.000000000 +0100
25482 @@ -71,6 +71,7 @@
25483  
25484  #include <linux/crypto.h>
25485  #include <linux/scatterlist.h>
25486 +#include <linux/vs_inet6.h>
25487  
25488  static void    tcp_v6_send_reset(struct sock *sk, struct sk_buff *skb);
25489  static void    tcp_v6_reqsk_send_ack(struct sock *sk, struct sk_buff *skb,
25490 @@ -175,8 +176,15 @@ static int tcp_v6_connect(struct sock *s
25491          *      connect() to INADDR_ANY means loopback (BSD'ism).
25492          */
25493  
25494 -       if(ipv6_addr_any(&usin->sin6_addr))
25495 -               usin->sin6_addr.s6_addr[15] = 0x1;
25496 +       if(ipv6_addr_any(&usin->sin6_addr)) {
25497 +               struct nx_info *nxi =  sk->sk_nx_info;
25498 +
25499 +               if (nxi && nx_info_has_v6(nxi))
25500 +                       /* FIXME: remap lback? */
25501 +                       usin->sin6_addr = nxi->v6.ip;
25502 +               else
25503 +                       usin->sin6_addr.s6_addr[15] = 0x1;
25504 +       }
25505  
25506         addr_type = ipv6_addr_type(&usin->sin6_addr);
25507  
25508 diff -NurpP --minimal linux-3.6.9/net/ipv6/udp.c linux-3.6.9-vs2.3.4.4/net/ipv6/udp.c
25509 --- linux-3.6.9/net/ipv6/udp.c  2012-10-04 15:27:50.000000000 +0200
25510 +++ linux-3.6.9-vs2.3.4.4/net/ipv6/udp.c        2012-10-04 18:56:03.000000000 +0200
25511 @@ -45,42 +45,68 @@
25512  #include <net/tcp_states.h>
25513  #include <net/ip6_checksum.h>
25514  #include <net/xfrm.h>
25515 +#include <linux/vs_inet6.h>
25516  
25517  #include <linux/proc_fs.h>
25518  #include <linux/seq_file.h>
25519  #include <trace/events/skb.h>
25520  #include "udp_impl.h"
25521  
25522 -int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
25523 +int ipv6_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2)
25524  {
25525 -       const struct in6_addr *sk_rcv_saddr6 = &inet6_sk(sk)->rcv_saddr;
25526 +       const struct in6_addr *sk1_rcv_saddr6 = &inet6_sk(sk1)->rcv_saddr;
25527         const struct in6_addr *sk2_rcv_saddr6 = inet6_rcv_saddr(sk2);
25528 -       __be32 sk1_rcv_saddr = sk_rcv_saddr(sk);
25529 +       __be32 sk1_rcv_saddr = sk_rcv_saddr(sk1);
25530         __be32 sk2_rcv_saddr = sk_rcv_saddr(sk2);
25531 -       int sk_ipv6only = ipv6_only_sock(sk);
25532 +       int sk1_ipv6only = ipv6_only_sock(sk1);
25533         int sk2_ipv6only = inet_v6_ipv6only(sk2);
25534 -       int addr_type = ipv6_addr_type(sk_rcv_saddr6);
25535 +       int addr_type = ipv6_addr_type(sk1_rcv_saddr6);
25536         int addr_type2 = sk2_rcv_saddr6 ? ipv6_addr_type(sk2_rcv_saddr6) : IPV6_ADDR_MAPPED;
25537  
25538         /* if both are mapped, treat as IPv4 */
25539 -       if (addr_type == IPV6_ADDR_MAPPED && addr_type2 == IPV6_ADDR_MAPPED)
25540 -               return (!sk2_ipv6only &&
25541 +       if (addr_type == IPV6_ADDR_MAPPED && addr_type2 == IPV6_ADDR_MAPPED) {
25542 +               if (!sk2_ipv6only &&
25543                         (!sk1_rcv_saddr || !sk2_rcv_saddr ||
25544 -                         sk1_rcv_saddr == sk2_rcv_saddr));
25545 +                         sk1_rcv_saddr == sk2_rcv_saddr))
25546 +                       goto vs_v4;
25547 +               else
25548 +                       return 0;
25549 +       }
25550  
25551         if (addr_type2 == IPV6_ADDR_ANY &&
25552             !(sk2_ipv6only && addr_type == IPV6_ADDR_MAPPED))
25553 -               return 1;
25554 +               goto vs;
25555  
25556         if (addr_type == IPV6_ADDR_ANY &&
25557 -           !(sk_ipv6only && addr_type2 == IPV6_ADDR_MAPPED))
25558 -               return 1;
25559 +           !(sk1_ipv6only && addr_type2 == IPV6_ADDR_MAPPED))
25560 +               goto vs;
25561  
25562         if (sk2_rcv_saddr6 &&
25563 -           ipv6_addr_equal(sk_rcv_saddr6, sk2_rcv_saddr6))
25564 -               return 1;
25565 +           ipv6_addr_equal(sk1_rcv_saddr6, sk2_rcv_saddr6))
25566 +               goto vs;
25567  
25568         return 0;
25569 +
25570 +vs_v4:
25571 +       if (!sk1_rcv_saddr && !sk2_rcv_saddr)
25572 +               return nx_v4_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info);
25573 +       if (!sk2_rcv_saddr)
25574 +               return v4_addr_in_nx_info(sk1->sk_nx_info, sk2_rcv_saddr, -1);
25575 +       if (!sk1_rcv_saddr)
25576 +               return v4_addr_in_nx_info(sk2->sk_nx_info, sk1_rcv_saddr, -1);
25577 +       return 1;
25578 +vs:
25579 +       if (addr_type2 == IPV6_ADDR_ANY && addr_type == IPV6_ADDR_ANY)
25580 +               return nx_v6_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info);
25581 +       else if (addr_type2 == IPV6_ADDR_ANY)
25582 +               return v6_addr_in_nx_info(sk2->sk_nx_info, sk1_rcv_saddr6, -1);
25583 +       else if (addr_type == IPV6_ADDR_ANY) {
25584 +               if (addr_type2 == IPV6_ADDR_MAPPED)
25585 +                       return nx_v4_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info);
25586 +               else
25587 +                       return v6_addr_in_nx_info(sk1->sk_nx_info, sk2_rcv_saddr6, -1);
25588 +       }
25589 +       return 1;
25590  }
25591  
25592  static unsigned int udp6_portaddr_hash(struct net *net,
25593 @@ -144,6 +170,10 @@ static inline int compute_score(struct s
25594                         if (!ipv6_addr_equal(&np->rcv_saddr, daddr))
25595                                 return -1;
25596                         score++;
25597 +               } else {
25598 +                       /* block non nx_info ips */
25599 +                       if (!v6_addr_in_nx_info(sk->sk_nx_info, daddr, -1))
25600 +                               return -1;
25601                 }
25602                 if (!ipv6_addr_any(&np->daddr)) {
25603                         if (!ipv6_addr_equal(&np->daddr, saddr))
25604 diff -NurpP --minimal linux-3.6.9/net/ipv6/xfrm6_policy.c linux-3.6.9-vs2.3.4.4/net/ipv6/xfrm6_policy.c
25605 --- linux-3.6.9/net/ipv6/xfrm6_policy.c 2012-10-04 15:27:50.000000000 +0200
25606 +++ linux-3.6.9-vs2.3.4.4/net/ipv6/xfrm6_policy.c       2012-10-04 18:47:00.000000000 +0200
25607 @@ -63,7 +63,7 @@ static int xfrm6_get_saddr(struct net *n
25608         dev = ip6_dst_idev(dst)->dev;
25609         ipv6_dev_get_saddr(dev_net(dev), dev,
25610                            (struct in6_addr *)&daddr->a6, 0,
25611 -                          (struct in6_addr *)&saddr->a6);
25612 +                          (struct in6_addr *)&saddr->a6, NULL);
25613         dst_release(dst);
25614         return 0;
25615  }
25616 diff -NurpP --minimal linux-3.6.9/net/netfilter/ipvs/ip_vs_xmit.c linux-3.6.9-vs2.3.4.4/net/netfilter/ipvs/ip_vs_xmit.c
25617 --- linux-3.6.9/net/netfilter/ipvs/ip_vs_xmit.c 2012-12-08 01:34:19.000000000 +0100
25618 +++ linux-3.6.9-vs2.3.4.4/net/netfilter/ipvs/ip_vs_xmit.c       2012-11-06 18:43:41.000000000 +0100
25619 @@ -231,7 +231,7 @@ __ip_vs_route_output_v6(struct net *net,
25620                 return dst;
25621         if (ipv6_addr_any(&fl6.saddr) &&
25622             ipv6_dev_get_saddr(net, ip6_dst_idev(dst)->dev,
25623 -                              &fl6.daddr, 0, &fl6.saddr) < 0)
25624 +                              &fl6.daddr, 0, &fl6.saddr, NULL) < 0)
25625                 goto out_err;
25626         if (do_xfrm) {
25627                 dst = xfrm_lookup(net, dst, flowi6_to_flowi(&fl6), NULL, 0);
25628 diff -NurpP --minimal linux-3.6.9/net/netlink/af_netlink.c linux-3.6.9-vs2.3.4.4/net/netlink/af_netlink.c
25629 --- linux-3.6.9/net/netlink/af_netlink.c        2012-12-08 01:34:19.000000000 +0100
25630 +++ linux-3.6.9-vs2.3.4.4/net/netlink/af_netlink.c      2012-12-08 01:36:33.000000000 +0100
25631 @@ -55,6 +55,9 @@
25632  #include <linux/types.h>
25633  #include <linux/audit.h>
25634  #include <linux/mutex.h>
25635 +#include <linux/vs_context.h>
25636 +#include <linux/vs_network.h>
25637 +#include <linux/vs_limit.h>
25638  
25639  #include <net/net_namespace.h>
25640  #include <net/sock.h>
25641 @@ -1983,6 +1986,8 @@ static struct sock *netlink_seq_socket_i
25642                         sk_for_each(s, node, &hash->table[j]) {
25643                                 if (sock_net(s) != seq_file_net(seq))
25644                                         continue;
25645 +                               if (!nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT))
25646 +                                       continue;
25647                                 if (off == pos) {
25648                                         iter->link = i;
25649                                         iter->hash_idx = j;
25650 @@ -2017,7 +2022,8 @@ static void *netlink_seq_next(struct seq
25651         s = v;
25652         do {
25653                 s = sk_next(s);
25654 -       } while (s && sock_net(s) != seq_file_net(seq));
25655 +       } while (s && (sock_net(s) != seq_file_net(seq) ||
25656 +               !nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT)));
25657         if (s)
25658                 return s;
25659  
25660 @@ -2029,7 +2035,8 @@ static void *netlink_seq_next(struct seq
25661  
25662                 for (; j <= hash->mask; j++) {
25663                         s = sk_head(&hash->table[j]);
25664 -                       while (s && sock_net(s) != seq_file_net(seq))
25665 +                       while (s && (sock_net(s) != seq_file_net(seq) ||
25666 +                               !nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT)))
25667                                 s = sk_next(s);
25668                         if (s) {
25669                                 iter->link = i;
25670 diff -NurpP --minimal linux-3.6.9/net/socket.c linux-3.6.9-vs2.3.4.4/net/socket.c
25671 --- linux-3.6.9/net/socket.c    2012-10-04 15:27:51.000000000 +0200
25672 +++ linux-3.6.9-vs2.3.4.4/net/socket.c  2012-10-04 18:47:00.000000000 +0200
25673 @@ -98,6 +98,10 @@
25674  
25675  #include <net/sock.h>
25676  #include <linux/netfilter.h>
25677 +#include <linux/vs_base.h>
25678 +#include <linux/vs_socket.h>
25679 +#include <linux/vs_inet.h>
25680 +#include <linux/vs_inet6.h>
25681  
25682  #include <linux/if_tun.h>
25683  #include <linux/ipv6_route.h>
25684 @@ -552,6 +556,7 @@ static inline int __sock_sendmsg_nosec(s
25685                                        struct msghdr *msg, size_t size)
25686  {
25687         struct sock_iocb *si = kiocb_to_siocb(iocb);
25688 +       size_t len;
25689  
25690         sock_update_classid(sock->sk);
25691  
25692 @@ -560,7 +565,22 @@ static inline int __sock_sendmsg_nosec(s
25693         si->msg = msg;
25694         si->size = size;
25695  
25696 -       return sock->ops->sendmsg(iocb, sock, msg, size);
25697 +       len = sock->ops->sendmsg(iocb, sock, msg, size);
25698 +       if (sock->sk) {
25699 +               if (len == size)
25700 +                       vx_sock_send(sock->sk, size);
25701 +               else
25702 +                       vx_sock_fail(sock->sk, size);
25703 +       }
25704 +       vxdprintk(VXD_CBIT(net, 7),
25705 +               "__sock_sendmsg: %p[%p,%p,%p;%d/%d]:%d/%zu",
25706 +               sock, sock->sk,
25707 +               (sock->sk)?sock->sk->sk_nx_info:0,
25708 +               (sock->sk)?sock->sk->sk_vx_info:0,
25709 +               (sock->sk)?sock->sk->sk_xid:0,
25710 +               (sock->sk)?sock->sk->sk_nid:0,
25711 +               (unsigned int)size, len);
25712 +       return len;
25713  }
25714  
25715  static inline int __sock_sendmsg(struct kiocb *iocb, struct socket *sock,
25716 @@ -716,6 +736,7 @@ static inline int __sock_recvmsg_nosec(s
25717                                        struct msghdr *msg, size_t size, int flags)
25718  {
25719         struct sock_iocb *si = kiocb_to_siocb(iocb);
25720 +       int len;
25721  
25722         sock_update_classid(sock->sk);
25723  
25724 @@ -725,7 +746,18 @@ static inline int __sock_recvmsg_nosec(s
25725         si->size = size;
25726         si->flags = flags;
25727  
25728 -       return sock->ops->recvmsg(iocb, sock, msg, size, flags);
25729 +       len = sock->ops->recvmsg(iocb, sock, msg, size, flags);
25730 +       if ((len >= 0) && sock->sk)
25731 +               vx_sock_recv(sock->sk, len);
25732 +       vxdprintk(VXD_CBIT(net, 7),
25733 +               "__sock_recvmsg: %p[%p,%p,%p;%d/%d]:%d/%d",
25734 +               sock, sock->sk,
25735 +               (sock->sk)?sock->sk->sk_nx_info:0,
25736 +               (sock->sk)?sock->sk->sk_vx_info:0,
25737 +               (sock->sk)?sock->sk->sk_xid:0,
25738 +               (sock->sk)?sock->sk->sk_nid:0,
25739 +               (unsigned int)size, len);
25740 +       return len;
25741  }
25742  
25743  static inline int __sock_recvmsg(struct kiocb *iocb, struct socket *sock,
25744 @@ -1210,6 +1242,13 @@ int __sock_create(struct net *net, int f
25745         if (type < 0 || type >= SOCK_MAX)
25746                 return -EINVAL;
25747  
25748 +       if (!nx_check(0, VS_ADMIN)) {
25749 +               if (family == PF_INET && !current_nx_info_has_v4())
25750 +                       return -EAFNOSUPPORT;
25751 +               if (family == PF_INET6 && !current_nx_info_has_v6())
25752 +                       return -EAFNOSUPPORT;
25753 +       }
25754 +
25755         /* Compatibility.
25756  
25757            This uglymoron is moved from INET layer to here to avoid
25758 @@ -1344,6 +1383,7 @@ SYSCALL_DEFINE3(socket, int, family, int
25759         if (retval < 0)
25760                 goto out;
25761  
25762 +       set_bit(SOCK_USER_SOCKET, &sock->flags);
25763         retval = sock_map_fd(sock, flags & (O_CLOEXEC | O_NONBLOCK));
25764         if (retval < 0)
25765                 goto out_release;
25766 @@ -1385,10 +1425,12 @@ SYSCALL_DEFINE4(socketpair, int, family,
25767         err = sock_create(family, type, protocol, &sock1);
25768         if (err < 0)
25769                 goto out;
25770 +       set_bit(SOCK_USER_SOCKET, &sock1->flags);
25771  
25772         err = sock_create(family, type, protocol, &sock2);
25773         if (err < 0)
25774                 goto out_release_1;
25775 +       set_bit(SOCK_USER_SOCKET, &sock2->flags);
25776  
25777         err = sock1->ops->socketpair(sock1, sock2);
25778         if (err < 0)
25779 diff -NurpP --minimal linux-3.6.9/net/sunrpc/auth.c linux-3.6.9-vs2.3.4.4/net/sunrpc/auth.c
25780 --- linux-3.6.9/net/sunrpc/auth.c       2012-10-04 15:27:51.000000000 +0200
25781 +++ linux-3.6.9-vs2.3.4.4/net/sunrpc/auth.c     2012-10-04 18:47:00.000000000 +0200
25782 @@ -15,6 +15,7 @@
25783  #include <linux/sunrpc/clnt.h>
25784  #include <linux/sunrpc/gss_api.h>
25785  #include <linux/spinlock.h>
25786 +#include <linux/vs_tag.h>
25787  
25788  #ifdef RPC_DEBUG
25789  # define RPCDBG_FACILITY       RPCDBG_AUTH
25790 @@ -481,6 +482,7 @@ rpcauth_lookupcred(struct rpc_auth *auth
25791         memset(&acred, 0, sizeof(acred));
25792         acred.uid = cred->fsuid;
25793         acred.gid = cred->fsgid;
25794 +       acred.tag = dx_current_tag();
25795         acred.group_info = get_group_info(((struct cred *)cred)->group_info);
25796  
25797         ret = auth->au_ops->lookup_cred(auth, &acred, flags);
25798 @@ -521,6 +523,7 @@ rpcauth_bind_root_cred(struct rpc_task *
25799         struct auth_cred acred = {
25800                 .uid = 0,
25801                 .gid = 0,
25802 +               .tag = dx_current_tag(),
25803         };
25804  
25805         dprintk("RPC: %5u looking up %s cred\n",
25806 diff -NurpP --minimal linux-3.6.9/net/sunrpc/auth_unix.c linux-3.6.9-vs2.3.4.4/net/sunrpc/auth_unix.c
25807 --- linux-3.6.9/net/sunrpc/auth_unix.c  2012-07-22 23:39:49.000000000 +0200
25808 +++ linux-3.6.9-vs2.3.4.4/net/sunrpc/auth_unix.c        2012-10-04 18:47:00.000000000 +0200
25809 @@ -13,11 +13,13 @@
25810  #include <linux/sunrpc/clnt.h>
25811  #include <linux/sunrpc/auth.h>
25812  #include <linux/user_namespace.h>
25813 +#include <linux/vs_tag.h>
25814  
25815  #define NFS_NGROUPS    16
25816  
25817  struct unx_cred {
25818         struct rpc_cred         uc_base;
25819 +       vs_tag_t                        uc_tag;
25820         gid_t                   uc_gid;
25821         gid_t                   uc_gids[NFS_NGROUPS];
25822  };
25823 @@ -79,6 +81,7 @@ unx_create_cred(struct rpc_auth *auth, s
25824                 groups = NFS_NGROUPS;
25825  
25826         cred->uc_gid = acred->gid;
25827 +       cred->uc_tag = acred->tag;
25828         for (i = 0; i < groups; i++) {
25829                 gid_t gid;
25830                 gid = from_kgid(&init_user_ns, GROUP_AT(acred->group_info, i));
25831 @@ -123,7 +126,9 @@ unx_match(struct auth_cred *acred, struc
25832         unsigned int i;
25833  
25834  
25835 -       if (cred->uc_uid != acred->uid || cred->uc_gid != acred->gid)
25836 +       if (cred->uc_uid != acred->uid ||
25837 +               cred->uc_gid != acred->gid ||
25838 +               cred->uc_tag != acred->tag)
25839                 return 0;
25840  
25841         if (acred->group_info != NULL)
25842 @@ -152,7 +157,7 @@ unx_marshal(struct rpc_task *task, __be3
25843         struct rpc_clnt *clnt = task->tk_client;
25844         struct unx_cred *cred = container_of(task->tk_rqstp->rq_cred, struct unx_cred, uc_base);
25845         __be32          *base, *hold;
25846 -       int             i;
25847 +       int             i, tag;
25848  
25849         *p++ = htonl(RPC_AUTH_UNIX);
25850         base = p++;
25851 @@ -162,9 +167,12 @@ unx_marshal(struct rpc_task *task, __be3
25852          * Copy the UTS nodename captured when the client was created.
25853          */
25854         p = xdr_encode_array(p, clnt->cl_nodename, clnt->cl_nodelen);
25855 +       tag = task->tk_client->cl_tag;
25856  
25857 -       *p++ = htonl((u32) cred->uc_uid);
25858 -       *p++ = htonl((u32) cred->uc_gid);
25859 +       *p++ = htonl((u32) TAGINO_UID(tag,
25860 +               cred->uc_uid, cred->uc_tag));
25861 +       *p++ = htonl((u32) TAGINO_GID(tag,
25862 +               cred->uc_gid, cred->uc_tag));
25863         hold = p++;
25864         for (i = 0; i < 16 && cred->uc_gids[i] != (gid_t) NOGROUP; i++)
25865                 *p++ = htonl((u32) cred->uc_gids[i]);
25866 diff -NurpP --minimal linux-3.6.9/net/sunrpc/clnt.c linux-3.6.9-vs2.3.4.4/net/sunrpc/clnt.c
25867 --- linux-3.6.9/net/sunrpc/clnt.c       2012-10-04 15:27:51.000000000 +0200
25868 +++ linux-3.6.9-vs2.3.4.4/net/sunrpc/clnt.c     2012-10-04 18:47:00.000000000 +0200
25869 @@ -31,6 +31,7 @@
25870  #include <linux/in6.h>
25871  #include <linux/un.h>
25872  #include <linux/rcupdate.h>
25873 +#include <linux/vs_cvirt.h>
25874  
25875  #include <linux/sunrpc/clnt.h>
25876  #include <linux/sunrpc/rpc_pipe_fs.h>
25877 @@ -481,6 +482,9 @@ struct rpc_clnt *rpc_create(struct rpc_c
25878         if (!(args->flags & RPC_CLNT_CREATE_QUIET))
25879                 clnt->cl_chatty = 1;
25880  
25881 +       /* TODO: handle RPC_CLNT_CREATE_TAGGED
25882 +       if (args->flags & RPC_CLNT_CREATE_TAGGED)
25883 +               clnt->cl_tag = 1; */
25884         return clnt;
25885  }
25886  EXPORT_SYMBOL_GPL(rpc_create);
25887 diff -NurpP --minimal linux-3.6.9/net/unix/af_unix.c linux-3.6.9-vs2.3.4.4/net/unix/af_unix.c
25888 --- linux-3.6.9/net/unix/af_unix.c      2012-10-04 15:27:51.000000000 +0200
25889 +++ linux-3.6.9-vs2.3.4.4/net/unix/af_unix.c    2012-10-04 18:59:36.000000000 +0200
25890 @@ -114,6 +114,8 @@
25891  #include <linux/mount.h>
25892  #include <net/checksum.h>
25893  #include <linux/security.h>
25894 +#include <linux/vs_context.h>
25895 +#include <linux/vs_limit.h>
25896  
25897  struct hlist_head unix_socket_table[2 * UNIX_HASH_SIZE];
25898  EXPORT_SYMBOL_GPL(unix_socket_table);
25899 @@ -271,6 +273,8 @@ static struct sock *__unix_find_socket_b
25900                 if (!net_eq(sock_net(s), net))
25901                         continue;
25902  
25903 +               if (!nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT))
25904 +                       continue;
25905                 if (u->addr->len == len &&
25906                     !memcmp(u->addr->name, sunname, len))
25907                         goto found;
25908 @@ -2258,6 +2262,8 @@ static struct sock *unix_from_bucket(str
25909         for (sk = sk_head(&unix_socket_table[bucket]); sk; sk = sk_next(sk)) {
25910                 if (sock_net(sk) != seq_file_net(seq))
25911                         continue;
25912 +               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
25913 +                       continue;
25914                 if (++count == offset)
25915                         break;
25916         }
25917 @@ -2275,6 +2281,8 @@ static struct sock *unix_next_socket(str
25918                 sk = sk_next(sk);
25919                 if (!sk)
25920                         goto next_bucket;
25921 +               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
25922 +                       continue;
25923                 if (sock_net(sk) == seq_file_net(seq))
25924                         return sk;
25925         }
25926 diff -NurpP --minimal linux-3.6.9/scripts/checksyscalls.sh linux-3.6.9-vs2.3.4.4/scripts/checksyscalls.sh
25927 --- linux-3.6.9/scripts/checksyscalls.sh        2012-10-04 15:27:51.000000000 +0200
25928 +++ linux-3.6.9-vs2.3.4.4/scripts/checksyscalls.sh      2012-10-04 18:47:00.000000000 +0200
25929 @@ -193,7 +193,6 @@ cat << EOF
25930  #define __IGNORE_afs_syscall
25931  #define __IGNORE_getpmsg
25932  #define __IGNORE_putpmsg
25933 -#define __IGNORE_vserver
25934  EOF
25935  }
25936  
25937 diff -NurpP --minimal linux-3.6.9/security/commoncap.c linux-3.6.9-vs2.3.4.4/security/commoncap.c
25938 --- linux-3.6.9/security/commoncap.c    2012-07-22 23:39:51.000000000 +0200
25939 +++ linux-3.6.9-vs2.3.4.4/security/commoncap.c  2012-10-04 18:47:00.000000000 +0200
25940 @@ -76,14 +76,20 @@ int cap_netlink_send(struct sock *sk, st
25941  int cap_capable(const struct cred *cred, struct user_namespace *targ_ns,
25942                 int cap, int audit)
25943  {
25944 +       struct vx_info *vxi = current_vx_info(); /* FIXME: get vxi from cred? */
25945 +
25946         for (;;) {
25947                 /* The owner of the user namespace has all caps. */
25948                 if (targ_ns != &init_user_ns && uid_eq(targ_ns->owner, cred->euid))
25949                         return 0;
25950  
25951                 /* Do we have the necessary capabilities? */
25952 -               if (targ_ns == cred->user_ns)
25953 -                       return cap_raised(cred->cap_effective, cap) ? 0 : -EPERM;
25954 +               if (targ_ns == cred->user_ns) {
25955 +                       if (vx_info_flags(vxi, VXF_STATE_SETUP, 0) &&
25956 +                           cap_raised(cred->cap_effective, cap))
25957 +                               return 0;
25958 +                       return vx_cap_raised(vxi, cred->cap_effective, cap) ? 0 : -EPERM;
25959 +               }
25960  
25961                 /* Have we tried all of the parent namespaces? */
25962                 if (targ_ns == &init_user_ns)
25963 @@ -619,7 +625,7 @@ int cap_inode_setxattr(struct dentry *de
25964  
25965         if (!strncmp(name, XATTR_SECURITY_PREFIX,
25966                      sizeof(XATTR_SECURITY_PREFIX) - 1) &&
25967 -           !capable(CAP_SYS_ADMIN))
25968 +               !vx_capable(CAP_SYS_ADMIN, VXC_FS_SECURITY))
25969                 return -EPERM;
25970         return 0;
25971  }
25972 @@ -645,7 +651,7 @@ int cap_inode_removexattr(struct dentry 
25973  
25974         if (!strncmp(name, XATTR_SECURITY_PREFIX,
25975                      sizeof(XATTR_SECURITY_PREFIX) - 1) &&
25976 -           !capable(CAP_SYS_ADMIN))
25977 +               !vx_capable(CAP_SYS_ADMIN, VXC_FS_SECURITY))
25978                 return -EPERM;
25979         return 0;
25980  }
25981 diff -NurpP --minimal linux-3.6.9/security/selinux/hooks.c linux-3.6.9-vs2.3.4.4/security/selinux/hooks.c
25982 --- linux-3.6.9/security/selinux/hooks.c        2012-10-04 15:27:53.000000000 +0200
25983 +++ linux-3.6.9-vs2.3.4.4/security/selinux/hooks.c      2012-10-04 18:47:00.000000000 +0200
25984 @@ -66,7 +66,6 @@
25985  #include <linux/dccp.h>
25986  #include <linux/quota.h>
25987  #include <linux/un.h>          /* for Unix socket types */
25988 -#include <net/af_unix.h>       /* for Unix socket types */
25989  #include <linux/parser.h>
25990  #include <linux/nfs_mount.h>
25991  #include <net/ipv6.h>
This page took 2.185255 seconds and 3 git commands to generate.