]> git.pld-linux.org Git - packages/kernel.git/blob - kernel-vserver-2.3.patch
8dff9eab769a80a5749d6d32d9ffb1b64832521c
[packages/kernel.git] / kernel-vserver-2.3.patch
1 diff -NurpP --minimal linux-3.6.10/Documentation/vserver/debug.txt linux-3.6.10-vs2.3.4.5/Documentation/vserver/debug.txt
2 --- linux-3.6.10/Documentation/vserver/debug.txt        1970-01-01 01:00:00.000000000 +0100
3 +++ linux-3.6.10-vs2.3.4.5/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.10/arch/alpha/Kconfig linux-3.6.10-vs2.3.4.5/arch/alpha/Kconfig
160 --- linux-3.6.10/arch/alpha/Kconfig     2012-10-04 15:26:43.000000000 +0200
161 +++ linux-3.6.10-vs2.3.4.5/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.10/arch/alpha/kernel/ptrace.c linux-3.6.10-vs2.3.4.5/arch/alpha/kernel/ptrace.c
172 --- linux-3.6.10/arch/alpha/kernel/ptrace.c     2012-05-21 18:06:12.000000000 +0200
173 +++ linux-3.6.10-vs2.3.4.5/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.10/arch/alpha/kernel/systbls.S linux-3.6.10-vs2.3.4.5/arch/alpha/kernel/systbls.S
183 --- linux-3.6.10/arch/alpha/kernel/systbls.S    2012-10-04 15:26:43.000000000 +0200
184 +++ linux-3.6.10-vs2.3.4.5/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.10/arch/alpha/kernel/traps.c linux-3.6.10-vs2.3.4.5/arch/alpha/kernel/traps.c
195 --- linux-3.6.10/arch/alpha/kernel/traps.c      2012-05-21 18:06:12.000000000 +0200
196 +++ linux-3.6.10-vs2.3.4.5/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.10/arch/arm/Kconfig linux-3.6.10-vs2.3.4.5/arch/arm/Kconfig
208 --- linux-3.6.10/arch/arm/Kconfig       2012-12-11 12:36:49.000000000 +0100
209 +++ linux-3.6.10-vs2.3.4.5/arch/arm/Kconfig     2012-12-11 12:45:19.000000000 +0100
210 @@ -2342,6 +2342,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.10/arch/arm/kernel/calls.S linux-3.6.10-vs2.3.4.5/arch/arm/kernel/calls.S
220 --- linux-3.6.10/arch/arm/kernel/calls.S        2012-10-04 15:26:43.000000000 +0200
221 +++ linux-3.6.10-vs2.3.4.5/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.10/arch/arm/kernel/process.c linux-3.6.10-vs2.3.4.5/arch/arm/kernel/process.c
232 --- linux-3.6.10/arch/arm/kernel/process.c      2012-10-04 15:26:43.000000000 +0200
233 +++ linux-3.6.10-vs2.3.4.5/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.10/arch/arm/kernel/traps.c linux-3.6.10-vs2.3.4.5/arch/arm/kernel/traps.c
245 --- linux-3.6.10/arch/arm/kernel/traps.c        2012-10-04 15:26:44.000000000 +0200
246 +++ linux-3.6.10-vs2.3.4.5/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.10/arch/cris/Kconfig linux-3.6.10-vs2.3.4.5/arch/cris/Kconfig
259 --- linux-3.6.10/arch/cris/Kconfig      2012-10-04 15:26:51.000000000 +0200
260 +++ linux-3.6.10-vs2.3.4.5/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.10/arch/frv/kernel/kernel_thread.S linux-3.6.10-vs2.3.4.5/arch/frv/kernel/kernel_thread.S
271 --- linux-3.6.10/arch/frv/kernel/kernel_thread.S        2012-10-04 15:26:51.000000000 +0200
272 +++ linux-3.6.10-vs2.3.4.5/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.10/arch/h8300/Kconfig linux-3.6.10-vs2.3.4.5/arch/h8300/Kconfig
283 --- linux-3.6.10/arch/h8300/Kconfig     2012-10-04 15:26:51.000000000 +0200
284 +++ linux-3.6.10-vs2.3.4.5/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.10/arch/ia64/Kconfig linux-3.6.10-vs2.3.4.5/arch/ia64/Kconfig
295 --- linux-3.6.10/arch/ia64/Kconfig      2012-10-04 15:26:51.000000000 +0200
296 +++ linux-3.6.10-vs2.3.4.5/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.10/arch/ia64/kernel/entry.S linux-3.6.10-vs2.3.4.5/arch/ia64/kernel/entry.S
307 --- linux-3.6.10/arch/ia64/kernel/entry.S       2012-03-19 19:46:40.000000000 +0100
308 +++ linux-3.6.10-vs2.3.4.5/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.10/arch/ia64/kernel/process.c linux-3.6.10-vs2.3.4.5/arch/ia64/kernel/process.c
319 --- linux-3.6.10/arch/ia64/kernel/process.c     2012-12-11 12:36:49.000000000 +0100
320 +++ linux-3.6.10-vs2.3.4.5/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.10/arch/ia64/kernel/ptrace.c linux-3.6.10-vs2.3.4.5/arch/ia64/kernel/ptrace.c
333 --- linux-3.6.10/arch/ia64/kernel/ptrace.c      2012-05-21 18:06:26.000000000 +0200
334 +++ linux-3.6.10-vs2.3.4.5/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.10/arch/ia64/kernel/traps.c linux-3.6.10-vs2.3.4.5/arch/ia64/kernel/traps.c
344 --- linux-3.6.10/arch/ia64/kernel/traps.c       2012-05-21 18:06:26.000000000 +0200
345 +++ linux-3.6.10-vs2.3.4.5/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.10/arch/m32r/kernel/traps.c linux-3.6.10-vs2.3.4.5/arch/m32r/kernel/traps.c
371 --- linux-3.6.10/arch/m32r/kernel/traps.c       2012-05-21 18:06:26.000000000 +0200
372 +++ linux-3.6.10-vs2.3.4.5/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.10/arch/m68k/Kconfig linux-3.6.10-vs2.3.4.5/arch/m68k/Kconfig
386 --- linux-3.6.10/arch/m68k/Kconfig      2012-10-04 15:26:51.000000000 +0200
387 +++ linux-3.6.10-vs2.3.4.5/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.10/arch/mips/Kconfig linux-3.6.10-vs2.3.4.5/arch/mips/Kconfig
398 --- linux-3.6.10/arch/mips/Kconfig      2012-10-04 15:26:52.000000000 +0200
399 +++ linux-3.6.10-vs2.3.4.5/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.10/arch/mips/kernel/ptrace.c linux-3.6.10-vs2.3.4.5/arch/mips/kernel/ptrace.c
410 --- linux-3.6.10/arch/mips/kernel/ptrace.c      2012-07-22 23:38:52.000000000 +0200
411 +++ linux-3.6.10-vs2.3.4.5/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.10/arch/mips/kernel/scall32-o32.S linux-3.6.10-vs2.3.4.5/arch/mips/kernel/scall32-o32.S
431 --- linux-3.6.10/arch/mips/kernel/scall32-o32.S 2012-01-09 16:14:05.000000000 +0100
432 +++ linux-3.6.10-vs2.3.4.5/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.10/arch/mips/kernel/scall64-64.S linux-3.6.10-vs2.3.4.5/arch/mips/kernel/scall64-64.S
443 --- linux-3.6.10/arch/mips/kernel/scall64-64.S  2012-01-09 16:14:05.000000000 +0100
444 +++ linux-3.6.10-vs2.3.4.5/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.10/arch/mips/kernel/scall64-n32.S linux-3.6.10-vs2.3.4.5/arch/mips/kernel/scall64-n32.S
455 --- linux-3.6.10/arch/mips/kernel/scall64-n32.S 2012-01-09 16:14:05.000000000 +0100
456 +++ linux-3.6.10-vs2.3.4.5/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.10/arch/mips/kernel/scall64-o32.S linux-3.6.10-vs2.3.4.5/arch/mips/kernel/scall64-o32.S
467 --- linux-3.6.10/arch/mips/kernel/scall64-o32.S 2012-01-09 16:14:05.000000000 +0100
468 +++ linux-3.6.10-vs2.3.4.5/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.10/arch/mips/kernel/traps.c linux-3.6.10-vs2.3.4.5/arch/mips/kernel/traps.c
479 --- linux-3.6.10/arch/mips/kernel/traps.c       2012-10-04 15:26:53.000000000 +0200
480 +++ linux-3.6.10-vs2.3.4.5/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.10/arch/parisc/Kconfig linux-3.6.10-vs2.3.4.5/arch/parisc/Kconfig
496 --- linux-3.6.10/arch/parisc/Kconfig    2012-07-22 23:38:52.000000000 +0200
497 +++ linux-3.6.10-vs2.3.4.5/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.10/arch/parisc/kernel/syscall_table.S linux-3.6.10-vs2.3.4.5/arch/parisc/kernel/syscall_table.S
508 --- linux-3.6.10/arch/parisc/kernel/syscall_table.S     2011-10-24 18:45:00.000000000 +0200
509 +++ linux-3.6.10-vs2.3.4.5/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.10/arch/parisc/kernel/traps.c linux-3.6.10-vs2.3.4.5/arch/parisc/kernel/traps.c
520 --- linux-3.6.10/arch/parisc/kernel/traps.c     2012-05-21 18:06:28.000000000 +0200
521 +++ linux-3.6.10-vs2.3.4.5/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.10/arch/parisc/mm/fault.c linux-3.6.10-vs2.3.4.5/arch/parisc/mm/fault.c
546 --- linux-3.6.10/arch/parisc/mm/fault.c 2010-08-02 16:52:06.000000000 +0200
547 +++ linux-3.6.10-vs2.3.4.5/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.10/arch/powerpc/Kconfig linux-3.6.10-vs2.3.4.5/arch/powerpc/Kconfig
561 --- linux-3.6.10/arch/powerpc/Kconfig   2012-10-04 15:26:53.000000000 +0200
562 +++ linux-3.6.10-vs2.3.4.5/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.10/arch/powerpc/include/asm/unistd.h linux-3.6.10-vs2.3.4.5/arch/powerpc/include/asm/unistd.h
573 --- linux-3.6.10/arch/powerpc/include/asm/unistd.h      2012-10-04 15:26:53.000000000 +0200
574 +++ linux-3.6.10-vs2.3.4.5/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.10/arch/powerpc/kernel/process.c linux-3.6.10-vs2.3.4.5/arch/powerpc/kernel/process.c
585 --- linux-3.6.10/arch/powerpc/kernel/process.c  2012-10-04 15:26:54.000000000 +0200
586 +++ linux-3.6.10-vs2.3.4.5/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.10/arch/powerpc/kernel/traps.c linux-3.6.10-vs2.3.4.5/arch/powerpc/kernel/traps.c
600 --- linux-3.6.10/arch/powerpc/kernel/traps.c    2012-10-04 15:26:54.000000000 +0200
601 +++ linux-3.6.10-vs2.3.4.5/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.10/arch/s390/Kconfig linux-3.6.10-vs2.3.4.5/arch/s390/Kconfig
615 --- linux-3.6.10/arch/s390/Kconfig      2012-10-04 15:26:54.000000000 +0200
616 +++ linux-3.6.10-vs2.3.4.5/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.10/arch/s390/include/asm/tlb.h linux-3.6.10-vs2.3.4.5/arch/s390/include/asm/tlb.h
627 --- linux-3.6.10/arch/s390/include/asm/tlb.h    2012-07-22 23:38:59.000000000 +0200
628 +++ linux-3.6.10-vs2.3.4.5/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.10/arch/s390/include/asm/unistd.h linux-3.6.10-vs2.3.4.5/arch/s390/include/asm/unistd.h
638 --- linux-3.6.10/arch/s390/include/asm/unistd.h 2012-10-04 15:26:55.000000000 +0200
639 +++ linux-3.6.10-vs2.3.4.5/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.10/arch/s390/kernel/ptrace.c linux-3.6.10-vs2.3.4.5/arch/s390/kernel/ptrace.c
650 --- linux-3.6.10/arch/s390/kernel/ptrace.c      2012-10-04 15:26:55.000000000 +0200
651 +++ linux-3.6.10-vs2.3.4.5/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.10/arch/s390/kernel/syscalls.S linux-3.6.10-vs2.3.4.5/arch/s390/kernel/syscalls.S
661 --- linux-3.6.10/arch/s390/kernel/syscalls.S    2012-01-09 16:14:06.000000000 +0100
662 +++ linux-3.6.10-vs2.3.4.5/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.10/arch/sh/Kconfig linux-3.6.10-vs2.3.4.5/arch/sh/Kconfig
673 --- linux-3.6.10/arch/sh/Kconfig        2012-10-04 15:26:55.000000000 +0200
674 +++ linux-3.6.10-vs2.3.4.5/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.10/arch/sh/kernel/irq.c linux-3.6.10-vs2.3.4.5/arch/sh/kernel/irq.c
685 --- linux-3.6.10/arch/sh/kernel/irq.c   2012-10-04 15:26:56.000000000 +0200
686 +++ linux-3.6.10-vs2.3.4.5/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.10/arch/sparc/Kconfig linux-3.6.10-vs2.3.4.5/arch/sparc/Kconfig
696 --- linux-3.6.10/arch/sparc/Kconfig     2012-10-04 15:26:58.000000000 +0200
697 +++ linux-3.6.10-vs2.3.4.5/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.10/arch/sparc/include/asm/unistd.h linux-3.6.10-vs2.3.4.5/arch/sparc/include/asm/unistd.h
708 --- linux-3.6.10/arch/sparc/include/asm/unistd.h        2012-10-04 15:26:59.000000000 +0200
709 +++ linux-3.6.10-vs2.3.4.5/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.10/arch/sparc/kernel/systbls_32.S linux-3.6.10-vs2.3.4.5/arch/sparc/kernel/systbls_32.S
720 --- linux-3.6.10/arch/sparc/kernel/systbls_32.S 2012-01-09 16:14:09.000000000 +0100
721 +++ linux-3.6.10-vs2.3.4.5/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.10/arch/sparc/kernel/systbls_64.S linux-3.6.10-vs2.3.4.5/arch/sparc/kernel/systbls_64.S
732 --- linux-3.6.10/arch/sparc/kernel/systbls_64.S 2012-07-22 23:39:00.000000000 +0200
733 +++ linux-3.6.10-vs2.3.4.5/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.10/arch/um/Kconfig.rest linux-3.6.10-vs2.3.4.5/arch/um/Kconfig.rest
753 --- linux-3.6.10/arch/um/Kconfig.rest   2012-01-09 16:14:09.000000000 +0100
754 +++ linux-3.6.10-vs2.3.4.5/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.10/arch/um/include/shared/kern_constants.h linux-3.6.10-vs2.3.4.5/arch/um/include/shared/kern_constants.h
765 --- linux-3.6.10/arch/um/include/shared/kern_constants.h        1970-01-01 01:00:00.000000000 +0100
766 +++ linux-3.6.10-vs2.3.4.5/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.10/arch/um/include/shared/user_constants.h linux-3.6.10-vs2.3.4.5/arch/um/include/shared/user_constants.h
770 --- linux-3.6.10/arch/um/include/shared/user_constants.h        1970-01-01 01:00:00.000000000 +0100
771 +++ linux-3.6.10-vs2.3.4.5/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.10/arch/x86/Kconfig linux-3.6.10-vs2.3.4.5/arch/x86/Kconfig
814 --- linux-3.6.10/arch/x86/Kconfig       2012-10-04 15:27:00.000000000 +0200
815 +++ linux-3.6.10-vs2.3.4.5/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.10/arch/x86/syscalls/syscall_32.tbl linux-3.6.10-vs2.3.4.5/arch/x86/syscalls/syscall_32.tbl
826 --- linux-3.6.10/arch/x86/syscalls/syscall_32.tbl       2012-07-22 23:39:02.000000000 +0200
827 +++ linux-3.6.10-vs2.3.4.5/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.10/arch/x86/syscalls/syscall_64.tbl linux-3.6.10-vs2.3.4.5/arch/x86/syscalls/syscall_64.tbl
838 --- linux-3.6.10/arch/x86/syscalls/syscall_64.tbl       2012-10-04 15:27:01.000000000 +0200
839 +++ linux-3.6.10-vs2.3.4.5/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.10/drivers/block/Kconfig linux-3.6.10-vs2.3.4.5/drivers/block/Kconfig
850 --- linux-3.6.10/drivers/block/Kconfig  2012-05-21 18:06:43.000000000 +0200
851 +++ linux-3.6.10-vs2.3.4.5/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.10/drivers/block/Makefile linux-3.6.10-vs2.3.4.5/drivers/block/Makefile
867 --- linux-3.6.10/drivers/block/Makefile 2012-03-19 19:46:52.000000000 +0100
868 +++ linux-3.6.10-vs2.3.4.5/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.10/drivers/block/loop.c linux-3.6.10-vs2.3.4.5/drivers/block/loop.c
878 --- linux-3.6.10/drivers/block/loop.c   2012-07-22 23:39:02.000000000 +0200
879 +++ linux-3.6.10-vs2.3.4.5/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.10/drivers/block/vroot.c linux-3.6.10-vs2.3.4.5/drivers/block/vroot.c
936 --- linux-3.6.10/drivers/block/vroot.c  1970-01-01 01:00:00.000000000 +0100
937 +++ linux-3.6.10-vs2.3.4.5/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.10/drivers/infiniband/Kconfig linux-3.6.10-vs2.3.4.5/drivers/infiniband/Kconfig
1231 --- linux-3.6.10/drivers/infiniband/Kconfig     2012-07-22 23:39:06.000000000 +0200
1232 +++ linux-3.6.10-vs2.3.4.5/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.10/drivers/infiniband/core/addr.c linux-3.6.10-vs2.3.4.5/drivers/infiniband/core/addr.c
1243 --- linux-3.6.10/drivers/infiniband/core/addr.c 2012-10-04 15:27:10.000000000 +0200
1244 +++ linux-3.6.10-vs2.3.4.5/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.10/drivers/md/dm-ioctl.c linux-3.6.10-vs2.3.4.5/drivers/md/dm-ioctl.c
1255 --- linux-3.6.10/drivers/md/dm-ioctl.c  2012-10-04 15:27:11.000000000 +0200
1256 +++ linux-3.6.10-vs2.3.4.5/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.10/drivers/md/dm.c linux-3.6.10-vs2.3.4.5/drivers/md/dm.c
1343 --- linux-3.6.10/drivers/md/dm.c        2012-12-11 12:36:52.000000000 +0100
1344 +++ linux-3.6.10-vs2.3.4.5/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.10/drivers/md/dm.h linux-3.6.10-vs2.3.4.5/drivers/md/dm.h
1419 --- linux-3.6.10/drivers/md/dm.h        2012-10-04 15:27:11.000000000 +0200
1420 +++ linux-3.6.10-vs2.3.4.5/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.10/drivers/net/tun.c linux-3.6.10-vs2.3.4.5/drivers/net/tun.c
1431 --- linux-3.6.10/drivers/net/tun.c      2012-10-04 15:27:20.000000000 +0200
1432 +++ linux-3.6.10-vs2.3.4.5/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.10/drivers/staging/csr/csr_wifi_hip_xbv.c linux-3.6.10-vs2.3.4.5/drivers/staging/csr/csr_wifi_hip_xbv.c
1503 --- linux-3.6.10/drivers/staging/csr/csr_wifi_hip_xbv.c 2012-10-04 15:27:30.000000000 +0200
1504 +++ linux-3.6.10-vs2.3.4.5/drivers/staging/csr/csr_wifi_hip_xbv.c       2012-12-10 17:33:14.000000000 +0100
1505 @@ -55,7 +55,7 @@ typedef struct
1506  {
1507      char t_name[4];
1508      u32     t_len;
1509 -} tag_t;
1510 +} ctag_t;
1511  
1512  
1513  #define TAG_EQ(i, v)    (((i)[0] == (v)[0]) &&  \
1514 @@ -90,7 +90,7 @@ typedef struct
1515      u32 ptr;
1516  } xbv_stack_t;
1517  
1518 -static s32 read_tag(card_t *card, ct_t *ct, tag_t *tag);
1519 +static s32 read_tag(card_t *card, ct_t *ct, ctag_t *tag);
1520  static s32 read_bytes(card_t *card, ct_t *ct, void *buf, u32 len);
1521  static s32 read_uint(card_t *card, ct_t *ct, u32 *u, u32 len);
1522  static s32 xbv_check(xbv1_t *fwinfo, const xbv_stack_t *stack,
1523 @@ -160,7 +160,7 @@ static u32 write_fwdl_to_ptdl(void *buf,
1524  CsrResult xbv1_parse(card_t *card, fwreadfn_t readfn, void *dlpriv, xbv1_t *fwinfo)
1525  {
1526      ct_t ct;
1527 -    tag_t tag;
1528 +    ctag_t tag;
1529      xbv_stack_t stack;
1530  
1531      ct.dlpriv = dlpriv;
1532 @@ -505,7 +505,7 @@ static u32 xbv2uint(u8 *ptr, s32 len)
1533  }
1534  
1535  
1536 -static s32 read_tag(card_t *card, ct_t *ct, tag_t *tag)
1537 +static s32 read_tag(card_t *card, ct_t *ct, ctag_t *tag)
1538  {
1539      u8 buf[8];
1540      s32 n;
1541 diff -NurpP --minimal linux-3.6.10/drivers/tty/sysrq.c linux-3.6.10-vs2.3.4.5/drivers/tty/sysrq.c
1542 --- linux-3.6.10/drivers/tty/sysrq.c    2012-05-21 18:07:16.000000000 +0200
1543 +++ linux-3.6.10-vs2.3.4.5/drivers/tty/sysrq.c  2012-10-04 18:47:00.000000000 +0200
1544 @@ -41,6 +41,7 @@
1545  #include <linux/slab.h>
1546  #include <linux/input.h>
1547  #include <linux/uaccess.h>
1548 +#include <linux/vserver/debug.h>
1549  
1550  #include <asm/ptrace.h>
1551  #include <asm/irq_regs.h>
1552 @@ -398,6 +399,21 @@ static struct sysrq_key_op sysrq_unrt_op
1553         .enable_mask    = SYSRQ_ENABLE_RTNICE,
1554  };
1555  
1556 +
1557 +#ifdef CONFIG_VSERVER_DEBUG
1558 +static void sysrq_handle_vxinfo(int key)
1559 +{
1560 +       dump_vx_info_inactive((key == 'x') ? 0 : 1);
1561 +}
1562 +
1563 +static struct sysrq_key_op sysrq_showvxinfo_op = {
1564 +       .handler        = sysrq_handle_vxinfo,
1565 +       .help_msg       = "conteXt",
1566 +       .action_msg     = "Show Context Info",
1567 +       .enable_mask    = SYSRQ_ENABLE_DUMP,
1568 +};
1569 +#endif
1570 +
1571  /* Key Operations table and lock */
1572  static DEFINE_SPINLOCK(sysrq_key_table_lock);
1573  
1574 @@ -452,7 +468,11 @@ static struct sysrq_key_op *sysrq_key_ta
1575         NULL,                           /* v */
1576         &sysrq_showstate_blocked_op,    /* w */
1577         /* x: May be registered on ppc/powerpc for xmon */
1578 +#ifdef CONFIG_VSERVER_DEBUG
1579 +       &sysrq_showvxinfo_op,           /* x */
1580 +#else
1581         NULL,                           /* x */
1582 +#endif
1583         /* y: May be registered on sparc64 for global register dump */
1584         NULL,                           /* y */
1585         &sysrq_ftrace_dump_op,          /* z */
1586 @@ -467,6 +487,8 @@ static int sysrq_key_table_key2index(int
1587                 retval = key - '0';
1588         else if ((key >= 'a') && (key <= 'z'))
1589                 retval = key + 10 - 'a';
1590 +       else if ((key >= 'A') && (key <= 'Z'))
1591 +               retval = key + 10 - 'A';
1592         else
1593                 retval = -1;
1594         return retval;
1595 diff -NurpP --minimal linux-3.6.10/drivers/tty/tty_io.c linux-3.6.10-vs2.3.4.5/drivers/tty/tty_io.c
1596 --- linux-3.6.10/drivers/tty/tty_io.c   2012-07-22 23:39:32.000000000 +0200
1597 +++ linux-3.6.10-vs2.3.4.5/drivers/tty/tty_io.c 2012-10-04 18:47:00.000000000 +0200
1598 @@ -104,6 +104,7 @@
1599  
1600  #include <linux/kmod.h>
1601  #include <linux/nsproxy.h>
1602 +#include <linux/vs_pid.h>
1603  
1604  #undef TTY_DEBUG_HANGUP
1605  
1606 @@ -2123,7 +2124,8 @@ static int tiocsti(struct tty_struct *tt
1607         char ch, mbz = 0;
1608         struct tty_ldisc *ld;
1609  
1610 -       if ((current->signal->tty != tty) && !capable(CAP_SYS_ADMIN))
1611 +       if (((current->signal->tty != tty) &&
1612 +               !vx_capable(CAP_SYS_ADMIN, VXC_TIOCSTI)))
1613                 return -EPERM;
1614         if (get_user(ch, p))
1615                 return -EFAULT;
1616 @@ -2411,6 +2413,7 @@ static int tiocspgrp(struct tty_struct *
1617                 return -ENOTTY;
1618         if (get_user(pgrp_nr, p))
1619                 return -EFAULT;
1620 +       pgrp_nr = vx_rmap_pid(pgrp_nr);
1621         if (pgrp_nr < 0)
1622                 return -EINVAL;
1623         rcu_read_lock();
1624 diff -NurpP --minimal linux-3.6.10/fs/attr.c linux-3.6.10-vs2.3.4.5/fs/attr.c
1625 --- linux-3.6.10/fs/attr.c      2012-10-04 15:27:39.000000000 +0200
1626 +++ linux-3.6.10-vs2.3.4.5/fs/attr.c    2012-10-04 18:47:00.000000000 +0200
1627 @@ -14,6 +14,9 @@
1628  #include <linux/fcntl.h>
1629  #include <linux/security.h>
1630  #include <linux/evm.h>
1631 +#include <linux/proc_fs.h>
1632 +#include <linux/devpts_fs.h>
1633 +#include <linux/vs_tag.h>
1634  
1635  /**
1636   * inode_change_ok - check if attribute changes to an inode are allowed
1637 @@ -74,6 +77,10 @@ int inode_change_ok(const struct inode *
1638                         return -EPERM;
1639         }
1640  
1641 +       /* check for inode tag permission */
1642 +       if (dx_permission(inode, MAY_WRITE))
1643 +               return -EACCES;
1644 +
1645         return 0;
1646  }
1647  EXPORT_SYMBOL(inode_change_ok);
1648 @@ -144,6 +151,8 @@ void setattr_copy(struct inode *inode, c
1649                 inode->i_uid = attr->ia_uid;
1650         if (ia_valid & ATTR_GID)
1651                 inode->i_gid = attr->ia_gid;
1652 +       if ((ia_valid & ATTR_TAG) && IS_TAGGED(inode))
1653 +               inode->i_tag = attr->ia_tag;
1654         if (ia_valid & ATTR_ATIME)
1655                 inode->i_atime = timespec_trunc(attr->ia_atime,
1656                                                 inode->i_sb->s_time_gran);
1657 @@ -173,7 +182,8 @@ int notify_change(struct dentry * dentry
1658  
1659         WARN_ON_ONCE(!mutex_is_locked(&inode->i_mutex));
1660  
1661 -       if (ia_valid & (ATTR_MODE | ATTR_UID | ATTR_GID | ATTR_TIMES_SET)) {
1662 +       if (ia_valid & (ATTR_MODE | ATTR_UID | ATTR_GID |
1663 +               ATTR_TAG | ATTR_TIMES_SET)) {
1664                 if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
1665                         return -EPERM;
1666         }
1667 diff -NurpP --minimal linux-3.6.10/fs/block_dev.c linux-3.6.10-vs2.3.4.5/fs/block_dev.c
1668 --- linux-3.6.10/fs/block_dev.c 2012-10-04 15:27:39.000000000 +0200
1669 +++ linux-3.6.10-vs2.3.4.5/fs/block_dev.c       2012-10-04 18:47:00.000000000 +0200
1670 @@ -27,6 +27,7 @@
1671  #include <linux/namei.h>
1672  #include <linux/log2.h>
1673  #include <linux/cleancache.h>
1674 +#include <linux/vs_device.h>
1675  #include <asm/uaccess.h>
1676  #include "internal.h"
1677  
1678 @@ -581,6 +582,7 @@ struct block_device *bdget(dev_t dev)
1679                 bdev->bd_invalidated = 0;
1680                 inode->i_mode = S_IFBLK;
1681                 inode->i_rdev = dev;
1682 +               inode->i_mdev = dev;
1683                 inode->i_bdev = bdev;
1684                 inode->i_data.a_ops = &def_blk_aops;
1685                 mapping_set_gfp_mask(&inode->i_data, GFP_USER);
1686 @@ -627,6 +629,11 @@ EXPORT_SYMBOL(bdput);
1687  static struct block_device *bd_acquire(struct inode *inode)
1688  {
1689         struct block_device *bdev;
1690 +       dev_t mdev;
1691 +
1692 +       if (!vs_map_blkdev(inode->i_rdev, &mdev, DATTR_OPEN))
1693 +               return NULL;
1694 +       inode->i_mdev = mdev;
1695  
1696         spin_lock(&bdev_lock);
1697         bdev = inode->i_bdev;
1698 @@ -637,7 +644,7 @@ static struct block_device *bd_acquire(s
1699         }
1700         spin_unlock(&bdev_lock);
1701  
1702 -       bdev = bdget(inode->i_rdev);
1703 +       bdev = bdget(mdev);
1704         if (bdev) {
1705                 spin_lock(&bdev_lock);
1706                 if (!inode->i_bdev) {
1707 diff -NurpP --minimal linux-3.6.10/fs/btrfs/ctree.h linux-3.6.10-vs2.3.4.5/fs/btrfs/ctree.h
1708 --- linux-3.6.10/fs/btrfs/ctree.h       2012-10-04 15:27:39.000000000 +0200
1709 +++ linux-3.6.10-vs2.3.4.5/fs/btrfs/ctree.h     2012-10-04 18:47:00.000000000 +0200
1710 @@ -674,11 +674,14 @@ struct btrfs_inode_item {
1711         /* modification sequence number for NFS */
1712         __le64 sequence;
1713  
1714 +       __le16 tag;
1715         /*
1716          * a little future expansion, for more than this we can
1717          * just grow the inode item and version it
1718          */
1719 -       __le64 reserved[4];
1720 +       __le16 reserved16;
1721 +       __le32 reserved32;
1722 +       __le64 reserved[3];
1723         struct btrfs_timespec atime;
1724         struct btrfs_timespec ctime;
1725         struct btrfs_timespec mtime;
1726 @@ -1727,6 +1730,8 @@ struct btrfs_ioctl_defrag_range_args {
1727  #define BTRFS_MOUNT_CHECK_INTEGRITY_INCLUDING_EXTENT_DATA (1 << 21)
1728  #define BTRFS_MOUNT_PANIC_ON_FATAL_ERROR       (1 << 22)
1729  
1730 +#define BTRFS_MOUNT_TAGGED             (1 << 24)
1731 +
1732  #define btrfs_clear_opt(o, opt)                ((o) &= ~BTRFS_MOUNT_##opt)
1733  #define btrfs_set_opt(o, opt)          ((o) |= BTRFS_MOUNT_##opt)
1734  #define btrfs_test_opt(root, opt)      ((root)->fs_info->mount_opt & \
1735 @@ -1988,6 +1993,7 @@ BTRFS_SETGET_FUNCS(inode_block_group, st
1736  BTRFS_SETGET_FUNCS(inode_nlink, struct btrfs_inode_item, nlink, 32);
1737  BTRFS_SETGET_FUNCS(inode_uid, struct btrfs_inode_item, uid, 32);
1738  BTRFS_SETGET_FUNCS(inode_gid, struct btrfs_inode_item, gid, 32);
1739 +BTRFS_SETGET_FUNCS(inode_tag, struct btrfs_inode_item, tag, 16);
1740  BTRFS_SETGET_FUNCS(inode_mode, struct btrfs_inode_item, mode, 32);
1741  BTRFS_SETGET_FUNCS(inode_rdev, struct btrfs_inode_item, rdev, 64);
1742  BTRFS_SETGET_FUNCS(inode_flags, struct btrfs_inode_item, flags, 64);
1743 @@ -2041,6 +2047,10 @@ BTRFS_SETGET_FUNCS(extent_flags, struct 
1744  
1745  BTRFS_SETGET_FUNCS(extent_refs_v0, struct btrfs_extent_item_v0, refs, 32);
1746  
1747 +#define BTRFS_INODE_IXUNLINK           (1 << 24)
1748 +#define BTRFS_INODE_BARRIER            (1 << 25)
1749 +#define BTRFS_INODE_COW                        (1 << 26)
1750 +
1751  
1752  BTRFS_SETGET_FUNCS(tree_block_level, struct btrfs_tree_block_info, level, 8);
1753  
1754 @@ -3305,6 +3315,7 @@ extern const struct dentry_operations bt
1755  long btrfs_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
1756  void btrfs_update_iflags(struct inode *inode);
1757  void btrfs_inherit_iflags(struct inode *inode, struct inode *dir);
1758 +int btrfs_sync_flags(struct inode *inode, int, int);
1759  int btrfs_defrag_file(struct inode *inode, struct file *file,
1760                       struct btrfs_ioctl_defrag_range_args *range,
1761                       u64 newer_than, unsigned long max_pages);
1762 diff -NurpP --minimal linux-3.6.10/fs/btrfs/disk-io.c linux-3.6.10-vs2.3.4.5/fs/btrfs/disk-io.c
1763 --- linux-3.6.10/fs/btrfs/disk-io.c     2012-10-04 15:27:39.000000000 +0200
1764 +++ linux-3.6.10-vs2.3.4.5/fs/btrfs/disk-io.c   2012-10-04 18:47:00.000000000 +0200
1765 @@ -2187,6 +2187,9 @@ int open_ctree(struct super_block *sb,
1766                 goto fail_alloc;
1767         }
1768  
1769 +       if (btrfs_test_opt(tree_root, TAGGED))
1770 +               sb->s_flags |= MS_TAGGED;
1771 +
1772         features = btrfs_super_incompat_flags(disk_super) &
1773                 ~BTRFS_FEATURE_INCOMPAT_SUPP;
1774         if (features) {
1775 diff -NurpP --minimal linux-3.6.10/fs/btrfs/inode.c linux-3.6.10-vs2.3.4.5/fs/btrfs/inode.c
1776 --- linux-3.6.10/fs/btrfs/inode.c       2012-10-04 15:27:39.000000000 +0200
1777 +++ linux-3.6.10-vs2.3.4.5/fs/btrfs/inode.c     2012-10-04 18:47:00.000000000 +0200
1778 @@ -39,6 +39,7 @@
1779  #include <linux/slab.h>
1780  #include <linux/ratelimit.h>
1781  #include <linux/mount.h>
1782 +#include <linux/vs_tag.h>
1783  #include "compat.h"
1784  #include "ctree.h"
1785  #include "disk-io.h"
1786 @@ -2545,6 +2546,8 @@ static void btrfs_read_locked_inode(stru
1787         struct btrfs_key location;
1788         int maybe_acls;
1789         u32 rdev;
1790 +       uid_t uid;
1791 +       gid_t gid;
1792         int ret;
1793         bool filled = false;
1794  
1795 @@ -2572,8 +2575,13 @@ static void btrfs_read_locked_inode(stru
1796                                     struct btrfs_inode_item);
1797         inode->i_mode = btrfs_inode_mode(leaf, inode_item);
1798         set_nlink(inode, btrfs_inode_nlink(leaf, inode_item));
1799 -       inode->i_uid = btrfs_inode_uid(leaf, inode_item);
1800 -       inode->i_gid = btrfs_inode_gid(leaf, inode_item);
1801 +
1802 +       uid = btrfs_inode_uid(leaf, inode_item);
1803 +       gid = btrfs_inode_gid(leaf, inode_item);
1804 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
1805 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
1806 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid,
1807 +               btrfs_inode_tag(leaf, inode_item));
1808         btrfs_i_size_write(inode, btrfs_inode_size(leaf, inode_item));
1809  
1810         tspec = btrfs_inode_atime(inode_item);
1811 @@ -2651,8 +2659,14 @@ static void fill_inode_item(struct btrfs
1812                             struct btrfs_inode_item *item,
1813                             struct inode *inode)
1814  {
1815 -       btrfs_set_inode_uid(leaf, item, inode->i_uid);
1816 -       btrfs_set_inode_gid(leaf, item, inode->i_gid);
1817 +       uid_t uid = TAGINO_UID(DX_TAG(inode), inode->i_uid, inode->i_tag);
1818 +       gid_t gid = TAGINO_GID(DX_TAG(inode), inode->i_gid, inode->i_tag);
1819 +
1820 +       btrfs_set_inode_uid(leaf, item, uid);
1821 +       btrfs_set_inode_gid(leaf, item, gid);
1822 +#ifdef CONFIG_TAGGING_INTERN
1823 +       btrfs_set_inode_tag(leaf, item, inode->i_tag);
1824 +#endif
1825         btrfs_set_inode_size(leaf, item, BTRFS_I(inode)->disk_i_size);
1826         btrfs_set_inode_mode(leaf, item, inode->i_mode);
1827         btrfs_set_inode_nlink(leaf, item, inode->i_nlink);
1828 @@ -7636,11 +7650,13 @@ static const struct inode_operations btr
1829         .listxattr      = btrfs_listxattr,
1830         .removexattr    = btrfs_removexattr,
1831         .permission     = btrfs_permission,
1832 +       .sync_flags     = btrfs_sync_flags,
1833         .get_acl        = btrfs_get_acl,
1834  };
1835  static const struct inode_operations btrfs_dir_ro_inode_operations = {
1836         .lookup         = btrfs_lookup,
1837         .permission     = btrfs_permission,
1838 +       .sync_flags     = btrfs_sync_flags,
1839         .get_acl        = btrfs_get_acl,
1840  };
1841  
1842 diff -NurpP --minimal linux-3.6.10/fs/btrfs/ioctl.c linux-3.6.10-vs2.3.4.5/fs/btrfs/ioctl.c
1843 --- linux-3.6.10/fs/btrfs/ioctl.c       2012-10-04 15:27:39.000000000 +0200
1844 +++ linux-3.6.10-vs2.3.4.5/fs/btrfs/ioctl.c     2012-10-04 18:47:00.000000000 +0200
1845 @@ -74,10 +74,13 @@ static unsigned int btrfs_flags_to_ioctl
1846  {
1847         unsigned int iflags = 0;
1848  
1849 -       if (flags & BTRFS_INODE_SYNC)
1850 -               iflags |= FS_SYNC_FL;
1851         if (flags & BTRFS_INODE_IMMUTABLE)
1852                 iflags |= FS_IMMUTABLE_FL;
1853 +       if (flags & BTRFS_INODE_IXUNLINK)
1854 +               iflags |= FS_IXUNLINK_FL;
1855 +
1856 +       if (flags & BTRFS_INODE_SYNC)
1857 +               iflags |= FS_SYNC_FL;
1858         if (flags & BTRFS_INODE_APPEND)
1859                 iflags |= FS_APPEND_FL;
1860         if (flags & BTRFS_INODE_NODUMP)
1861 @@ -94,28 +97,78 @@ static unsigned int btrfs_flags_to_ioctl
1862         else if (flags & BTRFS_INODE_NOCOMPRESS)
1863                 iflags |= FS_NOCOMP_FL;
1864  
1865 +       if (flags & BTRFS_INODE_BARRIER)
1866 +               iflags |= FS_BARRIER_FL;
1867 +       if (flags & BTRFS_INODE_COW)
1868 +               iflags |= FS_COW_FL;
1869         return iflags;
1870  }
1871  
1872  /*
1873 - * Update inode->i_flags based on the btrfs internal flags.
1874 + * Update inode->i_(v)flags based on the btrfs internal flags.
1875   */
1876  void btrfs_update_iflags(struct inode *inode)
1877  {
1878         struct btrfs_inode *ip = BTRFS_I(inode);
1879  
1880 -       inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
1881 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
1882 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
1883  
1884 -       if (ip->flags & BTRFS_INODE_SYNC)
1885 -               inode->i_flags |= S_SYNC;
1886         if (ip->flags & BTRFS_INODE_IMMUTABLE)
1887                 inode->i_flags |= S_IMMUTABLE;
1888 +       if (ip->flags & BTRFS_INODE_IXUNLINK)
1889 +               inode->i_flags |= S_IXUNLINK;
1890 +
1891 +       if (ip->flags & BTRFS_INODE_SYNC)
1892 +               inode->i_flags |= S_SYNC;
1893         if (ip->flags & BTRFS_INODE_APPEND)
1894                 inode->i_flags |= S_APPEND;
1895         if (ip->flags & BTRFS_INODE_NOATIME)
1896                 inode->i_flags |= S_NOATIME;
1897         if (ip->flags & BTRFS_INODE_DIRSYNC)
1898                 inode->i_flags |= S_DIRSYNC;
1899 +
1900 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
1901 +
1902 +       if (ip->flags & BTRFS_INODE_BARRIER)
1903 +               inode->i_vflags |= V_BARRIER;
1904 +       if (ip->flags & BTRFS_INODE_COW)
1905 +               inode->i_vflags |= V_COW;
1906 +}
1907 +
1908 +/*
1909 + * Update btrfs internal flags from inode->i_(v)flags.
1910 + */
1911 +void btrfs_update_flags(struct inode *inode)
1912 +{
1913 +       struct btrfs_inode *ip = BTRFS_I(inode);
1914 +
1915 +       unsigned int flags = inode->i_flags;
1916 +       unsigned int vflags = inode->i_vflags;
1917 +
1918 +       ip->flags &= ~(BTRFS_INODE_SYNC | BTRFS_INODE_APPEND |
1919 +                       BTRFS_INODE_IMMUTABLE | BTRFS_INODE_IXUNLINK |
1920 +                       BTRFS_INODE_NOATIME | BTRFS_INODE_DIRSYNC |
1921 +                       BTRFS_INODE_BARRIER | BTRFS_INODE_COW);
1922 +
1923 +       if (flags & S_IMMUTABLE)
1924 +               ip->flags |= BTRFS_INODE_IMMUTABLE;
1925 +       if (flags & S_IXUNLINK)
1926 +               ip->flags |= BTRFS_INODE_IXUNLINK;
1927 +
1928 +       if (flags & S_SYNC)
1929 +               ip->flags |= BTRFS_INODE_SYNC;
1930 +       if (flags & S_APPEND)
1931 +               ip->flags |= BTRFS_INODE_APPEND;
1932 +       if (flags & S_NOATIME)
1933 +               ip->flags |= BTRFS_INODE_NOATIME;
1934 +       if (flags & S_DIRSYNC)
1935 +               ip->flags |= BTRFS_INODE_DIRSYNC;
1936 +
1937 +       if (vflags & V_BARRIER)
1938 +               ip->flags |= BTRFS_INODE_BARRIER;
1939 +       if (vflags & V_COW)
1940 +               ip->flags |= BTRFS_INODE_COW;
1941  }
1942  
1943  /*
1944 @@ -131,6 +184,7 @@ void btrfs_inherit_iflags(struct inode *
1945                 return;
1946  
1947         flags = BTRFS_I(dir)->flags;
1948 +       flags &= ~BTRFS_INODE_BARRIER;
1949  
1950         if (flags & BTRFS_INODE_NOCOMPRESS) {
1951                 BTRFS_I(inode)->flags &= ~BTRFS_INODE_COMPRESS;
1952 @@ -146,6 +200,30 @@ void btrfs_inherit_iflags(struct inode *
1953         btrfs_update_iflags(inode);
1954  }
1955  
1956 +int btrfs_sync_flags(struct inode *inode, int flags, int vflags)
1957 +{
1958 +       struct btrfs_inode *ip = BTRFS_I(inode);
1959 +       struct btrfs_root *root = ip->root;
1960 +       struct btrfs_trans_handle *trans;
1961 +       int ret;
1962 +
1963 +       trans = btrfs_join_transaction(root);
1964 +       BUG_ON(!trans);
1965 +
1966 +       inode->i_flags = flags;
1967 +       inode->i_vflags = vflags;
1968 +       btrfs_update_flags(inode);
1969 +
1970 +       ret = btrfs_update_inode(trans, root, inode);
1971 +       BUG_ON(ret);
1972 +
1973 +       btrfs_update_iflags(inode);
1974 +       inode->i_ctime = CURRENT_TIME;
1975 +       btrfs_end_transaction(trans, root);
1976 +
1977 +       return 0;
1978 +}
1979 +
1980  static int btrfs_ioctl_getflags(struct file *file, void __user *arg)
1981  {
1982         struct btrfs_inode *ip = BTRFS_I(file->f_path.dentry->d_inode);
1983 @@ -206,21 +284,27 @@ static int btrfs_ioctl_setflags(struct f
1984  
1985         flags = btrfs_mask_flags(inode->i_mode, flags);
1986         oldflags = btrfs_flags_to_ioctl(ip->flags);
1987 -       if ((flags ^ oldflags) & (FS_APPEND_FL | FS_IMMUTABLE_FL)) {
1988 +       if ((flags ^ oldflags) & (FS_APPEND_FL |
1989 +               FS_IMMUTABLE_FL | FS_IXUNLINK_FL)) {
1990                 if (!capable(CAP_LINUX_IMMUTABLE)) {
1991                         ret = -EPERM;
1992                         goto out_unlock;
1993                 }
1994         }
1995  
1996 -       if (flags & FS_SYNC_FL)
1997 -               ip->flags |= BTRFS_INODE_SYNC;
1998 -       else
1999 -               ip->flags &= ~BTRFS_INODE_SYNC;
2000         if (flags & FS_IMMUTABLE_FL)
2001                 ip->flags |= BTRFS_INODE_IMMUTABLE;
2002         else
2003                 ip->flags &= ~BTRFS_INODE_IMMUTABLE;
2004 +       if (flags & FS_IXUNLINK_FL)
2005 +               ip->flags |= BTRFS_INODE_IXUNLINK;
2006 +       else
2007 +               ip->flags &= ~BTRFS_INODE_IXUNLINK;
2008 +
2009 +       if (flags & FS_SYNC_FL)
2010 +               ip->flags |= BTRFS_INODE_SYNC;
2011 +       else
2012 +               ip->flags &= ~BTRFS_INODE_SYNC;
2013         if (flags & FS_APPEND_FL)
2014                 ip->flags |= BTRFS_INODE_APPEND;
2015         else
2016 diff -NurpP --minimal linux-3.6.10/fs/btrfs/super.c linux-3.6.10-vs2.3.4.5/fs/btrfs/super.c
2017 --- linux-3.6.10/fs/btrfs/super.c       2012-10-04 15:27:39.000000000 +0200
2018 +++ linux-3.6.10-vs2.3.4.5/fs/btrfs/super.c     2012-10-04 18:47:00.000000000 +0200
2019 @@ -306,7 +306,7 @@ enum {
2020         Opt_no_space_cache, Opt_recovery, Opt_skip_balance,
2021         Opt_check_integrity, Opt_check_integrity_including_extent_data,
2022         Opt_check_integrity_print_mask, Opt_fatal_errors,
2023 -       Opt_err,
2024 +       Opt_tag, Opt_notag, Opt_tagid, Opt_err,
2025  };
2026  
2027  static match_table_t tokens = {
2028 @@ -346,6 +346,9 @@ static match_table_t tokens = {
2029         {Opt_check_integrity_including_extent_data, "check_int_data"},
2030         {Opt_check_integrity_print_mask, "check_int_print_mask=%d"},
2031         {Opt_fatal_errors, "fatal_errors=%s"},
2032 +       {Opt_tag, "tag"},
2033 +       {Opt_notag, "notag"},
2034 +       {Opt_tagid, "tagid=%u"},
2035         {Opt_err, NULL},
2036  };
2037  
2038 @@ -596,6 +599,22 @@ int btrfs_parse_options(struct btrfs_roo
2039                                 goto out;
2040                         }
2041                         break;
2042 +#ifndef CONFIG_TAGGING_NONE
2043 +               case Opt_tag:
2044 +                       printk(KERN_INFO "btrfs: use tagging\n");
2045 +                       btrfs_set_opt(info->mount_opt, TAGGED);
2046 +                       break;
2047 +               case Opt_notag:
2048 +                       printk(KERN_INFO "btrfs: disabled tagging\n");
2049 +                       btrfs_clear_opt(info->mount_opt, TAGGED);
2050 +                       break;
2051 +#endif
2052 +#ifdef CONFIG_PROPAGATE
2053 +               case Opt_tagid:
2054 +                       /* use args[0] */
2055 +                       btrfs_set_opt(info->mount_opt, TAGGED);
2056 +                       break;
2057 +#endif
2058                 case Opt_err:
2059                         printk(KERN_INFO "btrfs: unrecognized mount option "
2060                                "'%s'\n", p);
2061 @@ -1196,6 +1215,12 @@ static int btrfs_remount(struct super_bl
2062         btrfs_resize_thread_pool(fs_info,
2063                 fs_info->thread_pool_size, old_thread_pool_size);
2064  
2065 +       if (btrfs_test_opt(root, TAGGED) && !(sb->s_flags & MS_TAGGED)) {
2066 +               printk("btrfs: %s: tagging not permitted on remount.\n",
2067 +                       sb->s_id);
2068 +               return -EINVAL;
2069 +       }
2070 +
2071         if ((*flags & MS_RDONLY) == (sb->s_flags & MS_RDONLY))
2072                 return 0;
2073  
2074 diff -NurpP --minimal linux-3.6.10/fs/char_dev.c linux-3.6.10-vs2.3.4.5/fs/char_dev.c
2075 --- linux-3.6.10/fs/char_dev.c  2012-03-19 19:47:25.000000000 +0100
2076 +++ linux-3.6.10-vs2.3.4.5/fs/char_dev.c        2012-10-04 18:47:00.000000000 +0200
2077 @@ -21,6 +21,8 @@
2078  #include <linux/mutex.h>
2079  #include <linux/backing-dev.h>
2080  #include <linux/tty.h>
2081 +#include <linux/vs_context.h>
2082 +#include <linux/vs_device.h>
2083  
2084  #include "internal.h"
2085  
2086 @@ -371,14 +373,21 @@ static int chrdev_open(struct inode *ino
2087         struct cdev *p;
2088         struct cdev *new = NULL;
2089         int ret = 0;
2090 +       dev_t mdev;
2091 +
2092 +       if (!vs_map_chrdev(inode->i_rdev, &mdev, DATTR_OPEN))
2093 +               return -EPERM;
2094 +       inode->i_mdev = mdev;
2095  
2096         spin_lock(&cdev_lock);
2097         p = inode->i_cdev;
2098         if (!p) {
2099                 struct kobject *kobj;
2100                 int idx;
2101 +
2102                 spin_unlock(&cdev_lock);
2103 -               kobj = kobj_lookup(cdev_map, inode->i_rdev, &idx);
2104 +
2105 +               kobj = kobj_lookup(cdev_map, mdev, &idx);
2106                 if (!kobj)
2107                         return -ENXIO;
2108                 new = container_of(kobj, struct cdev, kobj);
2109 diff -NurpP --minimal linux-3.6.10/fs/dcache.c linux-3.6.10-vs2.3.4.5/fs/dcache.c
2110 --- linux-3.6.10/fs/dcache.c    2012-10-04 15:27:39.000000000 +0200
2111 +++ linux-3.6.10-vs2.3.4.5/fs/dcache.c  2012-12-07 22:49:54.000000000 +0100
2112 @@ -37,6 +37,7 @@
2113  #include <linux/rculist_bl.h>
2114  #include <linux/prefetch.h>
2115  #include <linux/ratelimit.h>
2116 +#include <linux/vs_limit.h>
2117  #include "internal.h"
2118  #include "mount.h"
2119  
2120 @@ -617,6 +618,8 @@ int d_invalidate(struct dentry * dentry)
2121                 spin_lock(&dentry->d_lock);
2122         }
2123  
2124 +       vx_dentry_dec(dentry);
2125 +
2126         /*
2127          * Somebody else still using it?
2128          *
2129 @@ -646,6 +649,7 @@ EXPORT_SYMBOL(d_invalidate);
2130  static inline void __dget_dlock(struct dentry *dentry)
2131  {
2132         dentry->d_count++;
2133 +       vx_dentry_inc(dentry);
2134  }
2135  
2136  static inline void __dget(struct dentry *dentry)
2137 @@ -1276,6 +1280,9 @@ struct dentry *__d_alloc(struct super_bl
2138         struct dentry *dentry;
2139         char *dname;
2140  
2141 +       if (!vx_dentry_avail(1))
2142 +               return NULL;
2143 +
2144         dentry = kmem_cache_alloc(dentry_cache, GFP_KERNEL);
2145         if (!dentry)
2146                 return NULL;
2147 @@ -1308,6 +1315,7 @@ struct dentry *__d_alloc(struct super_bl
2148  
2149         dentry->d_count = 1;
2150         dentry->d_flags = 0;
2151 +       vx_dentry_inc(dentry);
2152         spin_lock_init(&dentry->d_lock);
2153         seqcount_init(&dentry->d_seq);
2154         dentry->d_inode = NULL;
2155 @@ -2012,6 +2020,7 @@ struct dentry *__d_lookup(struct dentry 
2156                 }
2157  
2158                 dentry->d_count++;
2159 +               vx_dentry_inc(dentry);
2160                 found = dentry;
2161                 spin_unlock(&dentry->d_lock);
2162                 break;
2163 diff -NurpP --minimal linux-3.6.10/fs/devpts/inode.c linux-3.6.10-vs2.3.4.5/fs/devpts/inode.c
2164 --- linux-3.6.10/fs/devpts/inode.c      2012-10-04 15:27:39.000000000 +0200
2165 +++ linux-3.6.10-vs2.3.4.5/fs/devpts/inode.c    2012-10-04 18:47:00.000000000 +0200
2166 @@ -25,6 +25,7 @@
2167  #include <linux/parser.h>
2168  #include <linux/fsnotify.h>
2169  #include <linux/seq_file.h>
2170 +#include <linux/vs_base.h>
2171  
2172  #define DEVPTS_DEFAULT_MODE 0600
2173  /*
2174 @@ -36,6 +37,21 @@
2175  #define DEVPTS_DEFAULT_PTMX_MODE 0000
2176  #define PTMX_MINOR     2
2177  
2178 +static int devpts_permission(struct inode *inode, int mask)
2179 +{
2180 +       int ret = -EACCES;
2181 +
2182 +       /* devpts is xid tagged */
2183 +       if (vx_check((xid_t)inode->i_tag, VS_WATCH_P | VS_IDENT))
2184 +               ret = generic_permission(inode, mask);
2185 +       return ret;
2186 +}
2187 +
2188 +static struct inode_operations devpts_file_inode_operations = {
2189 +       .permission     = devpts_permission,
2190 +};
2191 +
2192 +
2193  /*
2194   * sysctl support for setting limits on the number of Unix98 ptys allocated.
2195   * Otherwise one can eat up all kernel memory by opening /dev/ptmx repeatedly.
2196 @@ -336,6 +352,34 @@ static int devpts_show_options(struct se
2197         return 0;
2198  }
2199  
2200 +static int devpts_filter(struct dentry *de)
2201 +{
2202 +       xid_t xid = 0;
2203 +
2204 +       /* devpts is xid tagged */
2205 +       if (de && de->d_inode)
2206 +               xid = (xid_t)de->d_inode->i_tag;
2207 +#ifdef CONFIG_VSERVER_WARN_DEVPTS
2208 +       else
2209 +               vxwprintk_task(1, "devpts " VS_Q("%.*s") " without inode.",
2210 +                       de->d_name.len, de->d_name.name);
2211 +#endif
2212 +       return vx_check(xid, VS_WATCH_P | VS_IDENT);
2213 +}
2214 +
2215 +static int devpts_readdir(struct file * filp, void * dirent, filldir_t filldir)
2216 +{
2217 +       return dcache_readdir_filter(filp, dirent, filldir, devpts_filter);
2218 +}
2219 +
2220 +static struct file_operations devpts_dir_operations = {
2221 +       .open           = dcache_dir_open,
2222 +       .release        = dcache_dir_close,
2223 +       .llseek         = dcache_dir_lseek,
2224 +       .read           = generic_read_dir,
2225 +       .readdir        = devpts_readdir,
2226 +};
2227 +
2228  static const struct super_operations devpts_sops = {
2229         .statfs         = simple_statfs,
2230         .remount_fs     = devpts_remount,
2231 @@ -379,8 +423,10 @@ devpts_fill_super(struct super_block *s,
2232         inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
2233         inode->i_mode = S_IFDIR | S_IRUGO | S_IXUGO | S_IWUSR;
2234         inode->i_op = &simple_dir_inode_operations;
2235 -       inode->i_fop = &simple_dir_operations;
2236 +       inode->i_fop = &devpts_dir_operations;
2237         set_nlink(inode, 2);
2238 +       /* devpts is xid tagged */
2239 +       inode->i_tag = (tag_t)vx_current_xid();
2240  
2241         s->s_root = d_make_root(inode);
2242         if (s->s_root)
2243 @@ -572,6 +618,9 @@ int devpts_pty_new(struct inode *ptmx_in
2244         inode->i_gid = opts->setgid ? opts->gid : current_fsgid();
2245         inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
2246         init_special_inode(inode, S_IFCHR|opts->mode, device);
2247 +       /* devpts is xid tagged */
2248 +       inode->i_tag = (tag_t)vx_current_xid();
2249 +       inode->i_op = &devpts_file_inode_operations;
2250         inode->i_private = tty;
2251         tty->driver_data = inode;
2252  
2253 diff -NurpP --minimal linux-3.6.10/fs/ext2/balloc.c linux-3.6.10-vs2.3.4.5/fs/ext2/balloc.c
2254 --- linux-3.6.10/fs/ext2/balloc.c       2012-10-04 15:27:39.000000000 +0200
2255 +++ linux-3.6.10-vs2.3.4.5/fs/ext2/balloc.c     2012-10-04 18:47:00.000000000 +0200
2256 @@ -699,7 +699,6 @@ ext2_try_to_allocate(struct super_block 
2257                         start = 0;
2258                 end = EXT2_BLOCKS_PER_GROUP(sb);
2259         }
2260 -
2261         BUG_ON(start > EXT2_BLOCKS_PER_GROUP(sb));
2262  
2263  repeat:
2264 diff -NurpP --minimal linux-3.6.10/fs/ext2/ext2.h linux-3.6.10-vs2.3.4.5/fs/ext2/ext2.h
2265 --- linux-3.6.10/fs/ext2/ext2.h 2012-07-22 23:39:39.000000000 +0200
2266 +++ linux-3.6.10-vs2.3.4.5/fs/ext2/ext2.h       2012-10-04 18:47:00.000000000 +0200
2267 @@ -244,8 +244,12 @@ struct ext2_group_desc
2268  #define EXT2_NOTAIL_FL                 FS_NOTAIL_FL    /* file tail should not be merged */
2269  #define EXT2_DIRSYNC_FL                        FS_DIRSYNC_FL   /* dirsync behaviour (directories only) */
2270  #define EXT2_TOPDIR_FL                 FS_TOPDIR_FL    /* Top of directory hierarchies*/
2271 +#define EXT2_IXUNLINK_FL               FS_IXUNLINK_FL  /* Immutable invert on unlink */
2272  #define EXT2_RESERVED_FL               FS_RESERVED_FL  /* reserved for ext2 lib */
2273  
2274 +#define EXT2_BARRIER_FL                        FS_BARRIER_FL   /* Barrier for chroot() */
2275 +#define EXT2_COW_FL                    FS_COW_FL       /* Copy on Write marker */
2276 +
2277  #define EXT2_FL_USER_VISIBLE           FS_FL_USER_VISIBLE      /* User visible flags */
2278  #define EXT2_FL_USER_MODIFIABLE                FS_FL_USER_MODIFIABLE   /* User modifiable flags */
2279  
2280 @@ -329,7 +333,8 @@ struct ext2_inode {
2281                         __u16   i_pad1;
2282                         __le16  l_i_uid_high;   /* these 2 fields    */
2283                         __le16  l_i_gid_high;   /* were reserved2[0] */
2284 -                       __u32   l_i_reserved2;
2285 +                       __le16  l_i_tag;        /* Context Tag */
2286 +                       __u16   l_i_reserved2;
2287                 } linux2;
2288                 struct {
2289                         __u8    h_i_frag;       /* Fragment number */
2290 @@ -357,6 +362,7 @@ struct ext2_inode {
2291  #define i_gid_low      i_gid
2292  #define i_uid_high     osd2.linux2.l_i_uid_high
2293  #define i_gid_high     osd2.linux2.l_i_gid_high
2294 +#define i_raw_tag      osd2.linux2.l_i_tag
2295  #define i_reserved2    osd2.linux2.l_i_reserved2
2296  
2297  /*
2298 @@ -384,6 +390,7 @@ struct ext2_inode {
2299  #define EXT2_MOUNT_USRQUOTA            0x020000  /* user quota */
2300  #define EXT2_MOUNT_GRPQUOTA            0x040000  /* group quota */
2301  #define EXT2_MOUNT_RESERVATION         0x080000  /* Preallocation */
2302 +#define EXT2_MOUNT_TAGGED              (1<<24)   /* Enable Context Tags */
2303  
2304  
2305  #define clear_opt(o, opt)              o &= ~EXT2_MOUNT_##opt
2306 @@ -757,6 +764,7 @@ extern void ext2_set_inode_flags(struct 
2307  extern void ext2_get_inode_flags(struct ext2_inode_info *);
2308  extern int ext2_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
2309                        u64 start, u64 len);
2310 +extern int ext2_sync_flags(struct inode *, int, int);
2311  
2312  /* ioctl.c */
2313  extern long ext2_ioctl(struct file *, unsigned int, unsigned long);
2314 diff -NurpP --minimal linux-3.6.10/fs/ext2/file.c linux-3.6.10-vs2.3.4.5/fs/ext2/file.c
2315 --- linux-3.6.10/fs/ext2/file.c 2011-10-24 18:45:27.000000000 +0200
2316 +++ linux-3.6.10-vs2.3.4.5/fs/ext2/file.c       2012-10-04 18:47:00.000000000 +0200
2317 @@ -104,4 +104,5 @@ const struct inode_operations ext2_file_
2318         .setattr        = ext2_setattr,
2319         .get_acl        = ext2_get_acl,
2320         .fiemap         = ext2_fiemap,
2321 +       .sync_flags     = ext2_sync_flags,
2322  };
2323 diff -NurpP --minimal linux-3.6.10/fs/ext2/ialloc.c linux-3.6.10-vs2.3.4.5/fs/ext2/ialloc.c
2324 --- linux-3.6.10/fs/ext2/ialloc.c       2012-10-04 15:27:39.000000000 +0200
2325 +++ linux-3.6.10-vs2.3.4.5/fs/ext2/ialloc.c     2012-10-04 18:47:00.000000000 +0200
2326 @@ -17,6 +17,7 @@
2327  #include <linux/backing-dev.h>
2328  #include <linux/buffer_head.h>
2329  #include <linux/random.h>
2330 +#include <linux/vs_tag.h>
2331  #include "ext2.h"
2332  #include "xattr.h"
2333  #include "acl.h"
2334 @@ -547,6 +548,7 @@ got:
2335                 inode->i_mode = mode;
2336                 inode->i_uid = current_fsuid();
2337                 inode->i_gid = dir->i_gid;
2338 +               inode->i_tag = dx_current_fstag(sb);
2339         } else
2340                 inode_init_owner(inode, dir, mode);
2341  
2342 diff -NurpP --minimal linux-3.6.10/fs/ext2/inode.c linux-3.6.10-vs2.3.4.5/fs/ext2/inode.c
2343 --- linux-3.6.10/fs/ext2/inode.c        2012-10-04 15:27:39.000000000 +0200
2344 +++ linux-3.6.10-vs2.3.4.5/fs/ext2/inode.c      2012-10-04 18:47:00.000000000 +0200
2345 @@ -31,6 +31,7 @@
2346  #include <linux/mpage.h>
2347  #include <linux/fiemap.h>
2348  #include <linux/namei.h>
2349 +#include <linux/vs_tag.h>
2350  #include "ext2.h"
2351  #include "acl.h"
2352  #include "xip.h"
2353 @@ -1165,7 +1166,7 @@ static void ext2_truncate_blocks(struct 
2354                 return;
2355         if (ext2_inode_is_fast_symlink(inode))
2356                 return;
2357 -       if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
2358 +       if (IS_APPEND(inode) || IS_IXORUNLINK(inode))
2359                 return;
2360         __ext2_truncate_blocks(inode, offset);
2361  }
2362 @@ -1256,36 +1257,61 @@ void ext2_set_inode_flags(struct inode *
2363  {
2364         unsigned int flags = EXT2_I(inode)->i_flags;
2365  
2366 -       inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
2367 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
2368 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
2369 +
2370 +
2371 +       if (flags & EXT2_IMMUTABLE_FL)
2372 +               inode->i_flags |= S_IMMUTABLE;
2373 +       if (flags & EXT2_IXUNLINK_FL)
2374 +               inode->i_flags |= S_IXUNLINK;
2375 +
2376         if (flags & EXT2_SYNC_FL)
2377                 inode->i_flags |= S_SYNC;
2378         if (flags & EXT2_APPEND_FL)
2379                 inode->i_flags |= S_APPEND;
2380 -       if (flags & EXT2_IMMUTABLE_FL)
2381 -               inode->i_flags |= S_IMMUTABLE;
2382         if (flags & EXT2_NOATIME_FL)
2383                 inode->i_flags |= S_NOATIME;
2384         if (flags & EXT2_DIRSYNC_FL)
2385                 inode->i_flags |= S_DIRSYNC;
2386 +
2387 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
2388 +
2389 +       if (flags & EXT2_BARRIER_FL)
2390 +               inode->i_vflags |= V_BARRIER;
2391 +       if (flags & EXT2_COW_FL)
2392 +               inode->i_vflags |= V_COW;
2393  }
2394  
2395  /* Propagate flags from i_flags to EXT2_I(inode)->i_flags */
2396  void ext2_get_inode_flags(struct ext2_inode_info *ei)
2397  {
2398         unsigned int flags = ei->vfs_inode.i_flags;
2399 +       unsigned int vflags = ei->vfs_inode.i_vflags;
2400 +
2401 +       ei->i_flags &= ~(EXT2_SYNC_FL | EXT2_APPEND_FL |
2402 +                       EXT2_IMMUTABLE_FL | EXT2_IXUNLINK_FL |
2403 +                       EXT2_NOATIME_FL | EXT2_DIRSYNC_FL |
2404 +                       EXT2_BARRIER_FL | EXT2_COW_FL);
2405 +
2406 +       if (flags & S_IMMUTABLE)
2407 +               ei->i_flags |= EXT2_IMMUTABLE_FL;
2408 +       if (flags & S_IXUNLINK)
2409 +               ei->i_flags |= EXT2_IXUNLINK_FL;
2410  
2411 -       ei->i_flags &= ~(EXT2_SYNC_FL|EXT2_APPEND_FL|
2412 -                       EXT2_IMMUTABLE_FL|EXT2_NOATIME_FL|EXT2_DIRSYNC_FL);
2413         if (flags & S_SYNC)
2414                 ei->i_flags |= EXT2_SYNC_FL;
2415         if (flags & S_APPEND)
2416                 ei->i_flags |= EXT2_APPEND_FL;
2417 -       if (flags & S_IMMUTABLE)
2418 -               ei->i_flags |= EXT2_IMMUTABLE_FL;
2419         if (flags & S_NOATIME)
2420                 ei->i_flags |= EXT2_NOATIME_FL;
2421         if (flags & S_DIRSYNC)
2422                 ei->i_flags |= EXT2_DIRSYNC_FL;
2423 +
2424 +       if (vflags & V_BARRIER)
2425 +               ei->i_flags |= EXT2_BARRIER_FL;
2426 +       if (vflags & V_COW)
2427 +               ei->i_flags |= EXT2_COW_FL;
2428  }
2429  
2430  struct inode *ext2_iget (struct super_block *sb, unsigned long ino)
2431 @@ -1321,8 +1347,10 @@ struct inode *ext2_iget (struct super_bl
2432                 i_uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
2433                 i_gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
2434         }
2435 -       i_uid_write(inode, i_uid);
2436 -       i_gid_write(inode, i_gid);
2437 +       i_uid_write(inode, INOTAG_UID(DX_TAG(inode), i_uid, i_gid));
2438 +       i_gid_write(inode, INOTAG_GID(DX_TAG(inode), i_uid, i_gid));
2439 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), i_uid, i_gid,
2440 +               le16_to_cpu(raw_inode->i_raw_tag));
2441         set_nlink(inode, le16_to_cpu(raw_inode->i_links_count));
2442         inode->i_size = le32_to_cpu(raw_inode->i_size);
2443         inode->i_atime.tv_sec = (signed)le32_to_cpu(raw_inode->i_atime);
2444 @@ -1420,8 +1448,8 @@ static int __ext2_write_inode(struct ino
2445         struct ext2_inode_info *ei = EXT2_I(inode);
2446         struct super_block *sb = inode->i_sb;
2447         ino_t ino = inode->i_ino;
2448 -       uid_t uid = i_uid_read(inode);
2449 -       gid_t gid = i_gid_read(inode);
2450 +       uid_t uid = TAGINO_UID(DX_TAG(inode), i_uid_read(inode), inode->i_tag);
2451 +       gid_t gid = TAGINO_GID(DX_TAG(inode), i_gid_read(inode), inode->i_tag);
2452         struct buffer_head * bh;
2453         struct ext2_inode * raw_inode = ext2_get_inode(sb, ino, &bh);
2454         int n;
2455 @@ -1457,6 +1485,9 @@ static int __ext2_write_inode(struct ino
2456                 raw_inode->i_uid_high = 0;
2457                 raw_inode->i_gid_high = 0;
2458         }
2459 +#ifdef CONFIG_TAGGING_INTERN
2460 +       raw_inode->i_raw_tag = cpu_to_le16(inode->i_tag);
2461 +#endif
2462         raw_inode->i_links_count = cpu_to_le16(inode->i_nlink);
2463         raw_inode->i_size = cpu_to_le32(inode->i_size);
2464         raw_inode->i_atime = cpu_to_le32(inode->i_atime.tv_sec);
2465 @@ -1537,7 +1568,8 @@ int ext2_setattr(struct dentry *dentry, 
2466         if (is_quota_modification(inode, iattr))
2467                 dquot_initialize(inode);
2468         if ((iattr->ia_valid & ATTR_UID && !uid_eq(iattr->ia_uid, inode->i_uid)) ||
2469 -           (iattr->ia_valid & ATTR_GID && !gid_eq(iattr->ia_gid, inode->i_gid))) {
2470 +           (iattr->ia_valid & ATTR_GID && !gid_eq(iattr->ia_gid, inode->i_gid)) ||
2471 +           (iattr->ia_valid & ATTR_TAG && iattr->ia_tag != inode->i_tag)) {
2472                 error = dquot_transfer(inode, iattr);
2473                 if (error)
2474                         return error;
2475 diff -NurpP --minimal linux-3.6.10/fs/ext2/ioctl.c linux-3.6.10-vs2.3.4.5/fs/ext2/ioctl.c
2476 --- linux-3.6.10/fs/ext2/ioctl.c        2012-03-19 19:47:25.000000000 +0100
2477 +++ linux-3.6.10-vs2.3.4.5/fs/ext2/ioctl.c      2012-10-04 18:47:00.000000000 +0200
2478 @@ -17,6 +17,16 @@
2479  #include <asm/uaccess.h>
2480  
2481  
2482 +int ext2_sync_flags(struct inode *inode, int flags, int vflags)
2483 +{
2484 +       inode->i_flags = flags;
2485 +       inode->i_vflags = vflags;
2486 +       ext2_get_inode_flags(EXT2_I(inode));
2487 +       inode->i_ctime = CURRENT_TIME_SEC;
2488 +       mark_inode_dirty(inode);
2489 +       return 0;
2490 +}
2491 +
2492  long ext2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
2493  {
2494         struct inode *inode = filp->f_dentry->d_inode;
2495 @@ -51,6 +61,11 @@ long ext2_ioctl(struct file *filp, unsig
2496  
2497                 flags = ext2_mask_flags(inode->i_mode, flags);
2498  
2499 +               if (IS_BARRIER(inode)) {
2500 +                       vxwprintk_task(1, "messing with the barrier.");
2501 +                       return -EACCES;
2502 +               }
2503 +
2504                 mutex_lock(&inode->i_mutex);
2505                 /* Is it quota file? Do not allow user to mess with it */
2506                 if (IS_NOQUOTA(inode)) {
2507 @@ -66,7 +81,9 @@ long ext2_ioctl(struct file *filp, unsig
2508                  *
2509                  * This test looks nicer. Thanks to Pauline Middelink
2510                  */
2511 -               if ((flags ^ oldflags) & (EXT2_APPEND_FL | EXT2_IMMUTABLE_FL)) {
2512 +               if ((oldflags & EXT2_IMMUTABLE_FL) ||
2513 +                       ((flags ^ oldflags) & (EXT2_APPEND_FL |
2514 +                       EXT2_IMMUTABLE_FL | EXT2_IXUNLINK_FL))) {
2515                         if (!capable(CAP_LINUX_IMMUTABLE)) {
2516                                 mutex_unlock(&inode->i_mutex);
2517                                 ret = -EPERM;
2518 @@ -74,7 +91,7 @@ long ext2_ioctl(struct file *filp, unsig
2519                         }
2520                 }
2521  
2522 -               flags = flags & EXT2_FL_USER_MODIFIABLE;
2523 +               flags &= EXT2_FL_USER_MODIFIABLE;
2524                 flags |= oldflags & ~EXT2_FL_USER_MODIFIABLE;
2525                 ei->i_flags = flags;
2526  
2527 diff -NurpP --minimal linux-3.6.10/fs/ext2/namei.c linux-3.6.10-vs2.3.4.5/fs/ext2/namei.c
2528 --- linux-3.6.10/fs/ext2/namei.c        2012-10-04 15:27:39.000000000 +0200
2529 +++ linux-3.6.10-vs2.3.4.5/fs/ext2/namei.c      2012-10-04 18:47:00.000000000 +0200
2530 @@ -32,6 +32,7 @@
2531  
2532  #include <linux/pagemap.h>
2533  #include <linux/quotaops.h>
2534 +#include <linux/vs_tag.h>
2535  #include "ext2.h"
2536  #include "xattr.h"
2537  #include "acl.h"
2538 @@ -73,6 +74,7 @@ static struct dentry *ext2_lookup(struct
2539                                         (unsigned long) ino);
2540                         return ERR_PTR(-EIO);
2541                 }
2542 +               dx_propagate_tag(nd, inode);
2543         }
2544         return d_splice_alias(inode, dentry);
2545  }
2546 @@ -397,6 +399,7 @@ const struct inode_operations ext2_dir_i
2547         .removexattr    = generic_removexattr,
2548  #endif
2549         .setattr        = ext2_setattr,
2550 +       .sync_flags     = ext2_sync_flags,
2551         .get_acl        = ext2_get_acl,
2552  };
2553  
2554 diff -NurpP --minimal linux-3.6.10/fs/ext2/super.c linux-3.6.10-vs2.3.4.5/fs/ext2/super.c
2555 --- linux-3.6.10/fs/ext2/super.c        2012-10-04 15:27:39.000000000 +0200
2556 +++ linux-3.6.10-vs2.3.4.5/fs/ext2/super.c      2012-10-04 18:47:00.000000000 +0200
2557 @@ -390,7 +390,8 @@ enum {
2558         Opt_err_ro, Opt_nouid32, Opt_nocheck, Opt_debug,
2559         Opt_oldalloc, Opt_orlov, Opt_nobh, Opt_user_xattr, Opt_nouser_xattr,
2560         Opt_acl, Opt_noacl, Opt_xip, Opt_ignore, Opt_err, Opt_quota,
2561 -       Opt_usrquota, Opt_grpquota, Opt_reservation, Opt_noreservation
2562 +       Opt_usrquota, Opt_grpquota, Opt_reservation, Opt_noreservation,
2563 +       Opt_tag, Opt_notag, Opt_tagid
2564  };
2565  
2566  static const match_table_t tokens = {
2567 @@ -418,6 +419,9 @@ static const match_table_t tokens = {
2568         {Opt_acl, "acl"},
2569         {Opt_noacl, "noacl"},
2570         {Opt_xip, "xip"},
2571 +       {Opt_tag, "tag"},
2572 +       {Opt_notag, "notag"},
2573 +       {Opt_tagid, "tagid=%u"},
2574         {Opt_grpquota, "grpquota"},
2575         {Opt_ignore, "noquota"},
2576         {Opt_quota, "quota"},
2577 @@ -501,6 +505,20 @@ static int parse_options(char *options, 
2578                 case Opt_nouid32:
2579                         set_opt (sbi->s_mount_opt, NO_UID32);
2580                         break;
2581 +#ifndef CONFIG_TAGGING_NONE
2582 +               case Opt_tag:
2583 +                       set_opt (sbi->s_mount_opt, TAGGED);
2584 +                       break;
2585 +               case Opt_notag:
2586 +                       clear_opt (sbi->s_mount_opt, TAGGED);
2587 +                       break;
2588 +#endif
2589 +#ifdef CONFIG_PROPAGATE
2590 +               case Opt_tagid:
2591 +                       /* use args[0] */
2592 +                       set_opt (sbi->s_mount_opt, TAGGED);
2593 +                       break;
2594 +#endif
2595                 case Opt_nocheck:
2596                         clear_opt (sbi->s_mount_opt, CHECK);
2597                         break;
2598 @@ -859,6 +877,8 @@ static int ext2_fill_super(struct super_
2599         if (!parse_options((char *) data, sb))
2600                 goto failed_mount;
2601  
2602 +       if (EXT2_SB(sb)->s_mount_opt & EXT2_MOUNT_TAGGED)
2603 +               sb->s_flags |= MS_TAGGED;
2604         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
2605                 ((EXT2_SB(sb)->s_mount_opt & EXT2_MOUNT_POSIX_ACL) ?
2606                  MS_POSIXACL : 0);
2607 @@ -1265,6 +1285,14 @@ static int ext2_remount (struct super_bl
2608                 goto restore_opts;
2609         }
2610  
2611 +       if ((sbi->s_mount_opt & EXT2_MOUNT_TAGGED) &&
2612 +               !(sb->s_flags & MS_TAGGED)) {
2613 +               printk("EXT2-fs: %s: tagging not permitted on remount.\n",
2614 +                      sb->s_id);
2615 +               err = -EINVAL;
2616 +               goto restore_opts;
2617 +       }
2618 +
2619         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
2620                 ((sbi->s_mount_opt & EXT2_MOUNT_POSIX_ACL) ? MS_POSIXACL : 0);
2621  
2622 diff -NurpP --minimal linux-3.6.10/fs/ext3/ext3.h linux-3.6.10-vs2.3.4.5/fs/ext3/ext3.h
2623 --- linux-3.6.10/fs/ext3/ext3.h 2012-07-22 23:39:39.000000000 +0200
2624 +++ linux-3.6.10-vs2.3.4.5/fs/ext3/ext3.h       2012-10-04 18:47:00.000000000 +0200
2625 @@ -151,10 +151,14 @@ struct ext3_group_desc
2626  #define EXT3_NOTAIL_FL                 0x00008000 /* file tail should not be merged */
2627  #define EXT3_DIRSYNC_FL                        0x00010000 /* dirsync behaviour (directories only) */
2628  #define EXT3_TOPDIR_FL                 0x00020000 /* Top of directory hierarchies*/
2629 +#define EXT3_IXUNLINK_FL               0x08000000 /* Immutable invert on unlink */
2630  #define EXT3_RESERVED_FL               0x80000000 /* reserved for ext3 lib */
2631  
2632 -#define EXT3_FL_USER_VISIBLE           0x0003DFFF /* User visible flags */
2633 -#define EXT3_FL_USER_MODIFIABLE                0x000380FF /* User modifiable flags */
2634 +#define EXT3_BARRIER_FL                        0x04000000 /* Barrier for chroot() */
2635 +#define EXT3_COW_FL                    0x20000000 /* Copy on Write marker */
2636 +
2637 +#define EXT3_FL_USER_VISIBLE           0x0103DFFF /* User visible flags */
2638 +#define EXT3_FL_USER_MODIFIABLE                0x010380FF /* User modifiable flags */
2639  
2640  /* Flags that should be inherited by new inodes from their parent. */
2641  #define EXT3_FL_INHERITED (EXT3_SECRM_FL | EXT3_UNRM_FL | EXT3_COMPR_FL |\
2642 @@ -290,7 +294,8 @@ struct ext3_inode {
2643                         __u16   i_pad1;
2644                         __le16  l_i_uid_high;   /* these 2 fields    */
2645                         __le16  l_i_gid_high;   /* were reserved2[0] */
2646 -                       __u32   l_i_reserved2;
2647 +                       __le16  l_i_tag;        /* Context Tag */
2648 +                       __u16   l_i_reserved2;
2649                 } linux2;
2650                 struct {
2651                         __u8    h_i_frag;       /* Fragment number */
2652 @@ -320,6 +325,7 @@ struct ext3_inode {
2653  #define i_gid_low      i_gid
2654  #define i_uid_high     osd2.linux2.l_i_uid_high
2655  #define i_gid_high     osd2.linux2.l_i_gid_high
2656 +#define i_raw_tag      osd2.linux2.l_i_tag
2657  #define i_reserved2    osd2.linux2.l_i_reserved2
2658  
2659  /*
2660 @@ -364,6 +370,7 @@ struct ext3_inode {
2661  #define EXT3_MOUNT_GRPQUOTA            0x200000 /* "old" group quota */
2662  #define EXT3_MOUNT_DATA_ERR_ABORT      0x400000 /* Abort on file data write
2663                                                   * error in ordered mode */
2664 +#define EXT3_MOUNT_TAGGED              (1<<24) /* Enable Context Tags */
2665  
2666  /* Compatibility, for having both ext2_fs.h and ext3_fs.h included at once */
2667  #ifndef _LINUX_EXT2_FS_H
2668 @@ -1061,6 +1068,7 @@ extern void ext3_get_inode_flags(struct 
2669  extern void ext3_set_aops(struct inode *inode);
2670  extern int ext3_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
2671                        u64 start, u64 len);
2672 +extern int ext3_sync_flags(struct inode *, int, int);
2673  
2674  /* ioctl.c */
2675  extern long ext3_ioctl(struct file *, unsigned int, unsigned long);
2676 diff -NurpP --minimal linux-3.6.10/fs/ext3/file.c linux-3.6.10-vs2.3.4.5/fs/ext3/file.c
2677 --- linux-3.6.10/fs/ext3/file.c 2012-05-21 18:07:20.000000000 +0200
2678 +++ linux-3.6.10-vs2.3.4.5/fs/ext3/file.c       2012-10-04 18:47:00.000000000 +0200
2679 @@ -76,5 +76,6 @@ const struct inode_operations ext3_file_
2680  #endif
2681         .get_acl        = ext3_get_acl,
2682         .fiemap         = ext3_fiemap,
2683 +       .sync_flags     = ext3_sync_flags,
2684  };
2685  
2686 diff -NurpP --minimal linux-3.6.10/fs/ext3/ialloc.c linux-3.6.10-vs2.3.4.5/fs/ext3/ialloc.c
2687 --- linux-3.6.10/fs/ext3/ialloc.c       2012-07-22 23:39:39.000000000 +0200
2688 +++ linux-3.6.10-vs2.3.4.5/fs/ext3/ialloc.c     2012-10-04 18:47:00.000000000 +0200
2689 @@ -14,6 +14,7 @@
2690  
2691  #include <linux/quotaops.h>
2692  #include <linux/random.h>
2693 +#include <linux/vs_tag.h>
2694  
2695  #include "ext3.h"
2696  #include "xattr.h"
2697 @@ -469,6 +470,7 @@ got:
2698                 inode->i_mode = mode;
2699                 inode->i_uid = current_fsuid();
2700                 inode->i_gid = dir->i_gid;
2701 +               inode->i_tag = dx_current_fstag(sb);
2702         } else
2703                 inode_init_owner(inode, dir, mode);
2704  
2705 diff -NurpP --minimal linux-3.6.10/fs/ext3/inode.c linux-3.6.10-vs2.3.4.5/fs/ext3/inode.c
2706 --- linux-3.6.10/fs/ext3/inode.c        2012-10-04 15:27:39.000000000 +0200
2707 +++ linux-3.6.10-vs2.3.4.5/fs/ext3/inode.c      2012-10-04 18:47:00.000000000 +0200
2708 @@ -27,6 +27,8 @@
2709  #include <linux/writeback.h>
2710  #include <linux/mpage.h>
2711  #include <linux/namei.h>
2712 +#include <linux/vs_tag.h>
2713 +
2714  #include "ext3.h"
2715  #include "xattr.h"
2716  #include "acl.h"
2717 @@ -2848,36 +2850,60 @@ void ext3_set_inode_flags(struct inode *
2718  {
2719         unsigned int flags = EXT3_I(inode)->i_flags;
2720  
2721 -       inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
2722 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
2723 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
2724 +
2725 +       if (flags & EXT3_IMMUTABLE_FL)
2726 +               inode->i_flags |= S_IMMUTABLE;
2727 +       if (flags & EXT3_IXUNLINK_FL)
2728 +               inode->i_flags |= S_IXUNLINK;
2729 +
2730         if (flags & EXT3_SYNC_FL)
2731                 inode->i_flags |= S_SYNC;
2732         if (flags & EXT3_APPEND_FL)
2733                 inode->i_flags |= S_APPEND;
2734 -       if (flags & EXT3_IMMUTABLE_FL)
2735 -               inode->i_flags |= S_IMMUTABLE;
2736         if (flags & EXT3_NOATIME_FL)
2737                 inode->i_flags |= S_NOATIME;
2738         if (flags & EXT3_DIRSYNC_FL)
2739                 inode->i_flags |= S_DIRSYNC;
2740 +
2741 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
2742 +
2743 +       if (flags & EXT3_BARRIER_FL)
2744 +               inode->i_vflags |= V_BARRIER;
2745 +       if (flags & EXT3_COW_FL)
2746 +               inode->i_vflags |= V_COW;
2747  }
2748  
2749  /* Propagate flags from i_flags to EXT3_I(inode)->i_flags */
2750  void ext3_get_inode_flags(struct ext3_inode_info *ei)
2751  {
2752         unsigned int flags = ei->vfs_inode.i_flags;
2753 +       unsigned int vflags = ei->vfs_inode.i_vflags;
2754 +
2755 +       ei->i_flags &= ~(EXT3_SYNC_FL | EXT3_APPEND_FL |
2756 +                       EXT3_IMMUTABLE_FL | EXT3_IXUNLINK_FL |
2757 +                       EXT3_NOATIME_FL | EXT3_DIRSYNC_FL |
2758 +                       EXT3_BARRIER_FL | EXT3_COW_FL);
2759 +
2760 +       if (flags & S_IMMUTABLE)
2761 +               ei->i_flags |= EXT3_IMMUTABLE_FL;
2762 +       if (flags & S_IXUNLINK)
2763 +               ei->i_flags |= EXT3_IXUNLINK_FL;
2764  
2765 -       ei->i_flags &= ~(EXT3_SYNC_FL|EXT3_APPEND_FL|
2766 -                       EXT3_IMMUTABLE_FL|EXT3_NOATIME_FL|EXT3_DIRSYNC_FL);
2767         if (flags & S_SYNC)
2768                 ei->i_flags |= EXT3_SYNC_FL;
2769         if (flags & S_APPEND)
2770                 ei->i_flags |= EXT3_APPEND_FL;
2771 -       if (flags & S_IMMUTABLE)
2772 -               ei->i_flags |= EXT3_IMMUTABLE_FL;
2773         if (flags & S_NOATIME)
2774                 ei->i_flags |= EXT3_NOATIME_FL;
2775         if (flags & S_DIRSYNC)
2776                 ei->i_flags |= EXT3_DIRSYNC_FL;
2777 +
2778 +       if (vflags & V_BARRIER)
2779 +               ei->i_flags |= EXT3_BARRIER_FL;
2780 +       if (vflags & V_COW)
2781 +               ei->i_flags |= EXT3_COW_FL;
2782  }
2783  
2784  struct inode *ext3_iget(struct super_block *sb, unsigned long ino)
2785 @@ -2915,8 +2941,10 @@ struct inode *ext3_iget(struct super_blo
2786                 i_uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
2787                 i_gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
2788         }
2789 -       i_uid_write(inode, i_uid);
2790 -       i_gid_write(inode, i_gid);
2791 +       i_uid_write(inode, INOTAG_UID(DX_TAG(inode), i_uid, i_gid));
2792 +       i_gid_write(inode, INOTAG_GID(DX_TAG(inode), i_uid, i_gid));
2793 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), i_uid, i_gid,
2794 +               le16_to_cpu(raw_inode->i_raw_tag));
2795         set_nlink(inode, le16_to_cpu(raw_inode->i_links_count));
2796         inode->i_size = le32_to_cpu(raw_inode->i_size);
2797         inode->i_atime.tv_sec = (signed)le32_to_cpu(raw_inode->i_atime);
2798 @@ -3088,8 +3116,8 @@ again:
2799  
2800         ext3_get_inode_flags(ei);
2801         raw_inode->i_mode = cpu_to_le16(inode->i_mode);
2802 -       i_uid = i_uid_read(inode);
2803 -       i_gid = i_gid_read(inode);
2804 +       i_uid = TAGINO_UID(DX_TAG(inode), i_uid_read(inode), inode->i_tag);
2805 +       i_gid = TAGINO_GID(DX_TAG(inode), i_gid_read(inode), inode->i_tag);
2806         if(!(test_opt(inode->i_sb, NO_UID32))) {
2807                 raw_inode->i_uid_low = cpu_to_le16(low_16_bits(i_uid));
2808                 raw_inode->i_gid_low = cpu_to_le16(low_16_bits(i_gid));
2809 @@ -3114,6 +3142,9 @@ again:
2810                 raw_inode->i_uid_high = 0;
2811                 raw_inode->i_gid_high = 0;
2812         }
2813 +#ifdef CONFIG_TAGGING_INTERN
2814 +       raw_inode->i_raw_tag = cpu_to_le16(inode->i_tag);
2815 +#endif
2816         raw_inode->i_links_count = cpu_to_le16(inode->i_nlink);
2817         disksize = cpu_to_le32(ei->i_disksize);
2818         if (disksize != raw_inode->i_size) {
2819 @@ -3282,7 +3313,8 @@ int ext3_setattr(struct dentry *dentry, 
2820         if (is_quota_modification(inode, attr))
2821                 dquot_initialize(inode);
2822         if ((ia_valid & ATTR_UID && !uid_eq(attr->ia_uid, inode->i_uid)) ||
2823 -           (ia_valid & ATTR_GID && !gid_eq(attr->ia_gid, inode->i_gid))) {
2824 +           (ia_valid & ATTR_GID && !gid_eq(attr->ia_gid, inode->i_gid)) ||
2825 +           (ia_valid & ATTR_TAG && attr->ia_tag != inode->i_tag)) {
2826                 handle_t *handle;
2827  
2828                 /* (user+group)*(old+new) structure, inode write (sb,
2829 @@ -3304,6 +3336,8 @@ int ext3_setattr(struct dentry *dentry, 
2830                         inode->i_uid = attr->ia_uid;
2831                 if (attr->ia_valid & ATTR_GID)
2832                         inode->i_gid = attr->ia_gid;
2833 +               if ((attr->ia_valid & ATTR_TAG) && IS_TAGGED(inode))
2834 +                       inode->i_tag = attr->ia_tag;
2835                 error = ext3_mark_inode_dirty(handle, inode);
2836                 ext3_journal_stop(handle);
2837         }
2838 diff -NurpP --minimal linux-3.6.10/fs/ext3/ioctl.c linux-3.6.10-vs2.3.4.5/fs/ext3/ioctl.c
2839 --- linux-3.6.10/fs/ext3/ioctl.c        2012-05-21 18:07:20.000000000 +0200
2840 +++ linux-3.6.10-vs2.3.4.5/fs/ext3/ioctl.c      2012-10-04 18:47:00.000000000 +0200
2841 @@ -12,6 +12,34 @@
2842  #include <asm/uaccess.h>
2843  #include "ext3.h"
2844  
2845 +
2846 +int ext3_sync_flags(struct inode *inode, int flags, int vflags)
2847 +{
2848 +       handle_t *handle = NULL;
2849 +       struct ext3_iloc iloc;
2850 +       int err;
2851 +
2852 +       handle = ext3_journal_start(inode, 1);
2853 +       if (IS_ERR(handle))
2854 +               return PTR_ERR(handle);
2855 +
2856 +       if (IS_SYNC(inode))
2857 +               handle->h_sync = 1;
2858 +       err = ext3_reserve_inode_write(handle, inode, &iloc);
2859 +       if (err)
2860 +               goto flags_err;
2861 +
2862 +       inode->i_flags = flags;
2863 +       inode->i_vflags = vflags;
2864 +       ext3_get_inode_flags(EXT3_I(inode));
2865 +       inode->i_ctime = CURRENT_TIME_SEC;
2866 +
2867 +       err = ext3_mark_iloc_dirty(handle, inode, &iloc);
2868 +flags_err:
2869 +       ext3_journal_stop(handle);
2870 +       return err;
2871 +}
2872 +
2873  long ext3_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
2874  {
2875         struct inode *inode = filp->f_dentry->d_inode;
2876 @@ -45,6 +73,11 @@ long ext3_ioctl(struct file *filp, unsig
2877  
2878                 flags = ext3_mask_flags(inode->i_mode, flags);
2879  
2880 +               if (IS_BARRIER(inode)) {
2881 +                       vxwprintk_task(1, "messing with the barrier.");
2882 +                       return -EACCES;
2883 +               }
2884 +
2885                 mutex_lock(&inode->i_mutex);
2886  
2887                 /* Is it quota file? Do not allow user to mess with it */
2888 @@ -63,7 +96,9 @@ long ext3_ioctl(struct file *filp, unsig
2889                  *
2890                  * This test looks nicer. Thanks to Pauline Middelink
2891                  */
2892 -               if ((flags ^ oldflags) & (EXT3_APPEND_FL | EXT3_IMMUTABLE_FL)) {
2893 +               if ((oldflags & EXT3_IMMUTABLE_FL) ||
2894 +                       ((flags ^ oldflags) & (EXT3_APPEND_FL |
2895 +                       EXT3_IMMUTABLE_FL | EXT3_IXUNLINK_FL))) {
2896                         if (!capable(CAP_LINUX_IMMUTABLE))
2897                                 goto flags_out;
2898                 }
2899 @@ -88,7 +123,7 @@ long ext3_ioctl(struct file *filp, unsig
2900                 if (err)
2901                         goto flags_err;
2902  
2903 -               flags = flags & EXT3_FL_USER_MODIFIABLE;
2904 +               flags &= EXT3_FL_USER_MODIFIABLE;
2905                 flags |= oldflags & ~EXT3_FL_USER_MODIFIABLE;
2906                 ei->i_flags = flags;
2907  
2908 diff -NurpP --minimal linux-3.6.10/fs/ext3/namei.c linux-3.6.10-vs2.3.4.5/fs/ext3/namei.c
2909 --- linux-3.6.10/fs/ext3/namei.c        2012-10-04 15:27:39.000000000 +0200
2910 +++ linux-3.6.10-vs2.3.4.5/fs/ext3/namei.c      2012-10-04 18:47:00.000000000 +0200
2911 @@ -25,6 +25,8 @@
2912   */
2913  
2914  #include <linux/quotaops.h>
2915 +#include <linux/vs_tag.h>
2916 +
2917  #include "ext3.h"
2918  #include "namei.h"
2919  #include "xattr.h"
2920 @@ -915,6 +917,7 @@ restart:
2921                                         submit_bh(READ | REQ_META | REQ_PRIO,
2922                                                   bh);
2923                                 }
2924 +               dx_propagate_tag(nd, inode);
2925                         }
2926                 }
2927                 if ((bh = bh_use[ra_ptr++]) == NULL)
2928 @@ -2526,6 +2529,7 @@ const struct inode_operations ext3_dir_i
2929         .listxattr      = ext3_listxattr,
2930         .removexattr    = generic_removexattr,
2931  #endif
2932 +       .sync_flags     = ext3_sync_flags,
2933         .get_acl        = ext3_get_acl,
2934  };
2935  
2936 diff -NurpP --minimal linux-3.6.10/fs/ext3/super.c linux-3.6.10-vs2.3.4.5/fs/ext3/super.c
2937 --- linux-3.6.10/fs/ext3/super.c        2012-10-04 15:27:39.000000000 +0200
2938 +++ linux-3.6.10-vs2.3.4.5/fs/ext3/super.c      2012-10-04 18:47:00.000000000 +0200
2939 @@ -811,7 +811,8 @@ enum {
2940         Opt_usrjquota, Opt_grpjquota, Opt_offusrjquota, Opt_offgrpjquota,
2941         Opt_jqfmt_vfsold, Opt_jqfmt_vfsv0, Opt_jqfmt_vfsv1, Opt_quota,
2942         Opt_noquota, Opt_ignore, Opt_barrier, Opt_nobarrier, Opt_err,
2943 -       Opt_resize, Opt_usrquota, Opt_grpquota
2944 +       Opt_resize, Opt_usrquota, Opt_grpquota,
2945 +       Opt_tag, Opt_notag, Opt_tagid
2946  };
2947  
2948  static const match_table_t tokens = {
2949 @@ -868,6 +869,9 @@ static const match_table_t tokens = {
2950         {Opt_barrier, "barrier"},
2951         {Opt_nobarrier, "nobarrier"},
2952         {Opt_resize, "resize"},
2953 +       {Opt_tag, "tag"},
2954 +       {Opt_notag, "notag"},
2955 +       {Opt_tagid, "tagid=%u"},
2956         {Opt_err, NULL},
2957  };
2958  
2959 @@ -1033,6 +1037,20 @@ static int parse_options (char *options,
2960                 case Opt_nouid32:
2961                         set_opt (sbi->s_mount_opt, NO_UID32);
2962                         break;
2963 +#ifndef CONFIG_TAGGING_NONE
2964 +               case Opt_tag:
2965 +                       set_opt (sbi->s_mount_opt, TAGGED);
2966 +                       break;
2967 +               case Opt_notag:
2968 +                       clear_opt (sbi->s_mount_opt, TAGGED);
2969 +                       break;
2970 +#endif
2971 +#ifdef CONFIG_PROPAGATE
2972 +               case Opt_tagid:
2973 +                       /* use args[0] */
2974 +                       set_opt (sbi->s_mount_opt, TAGGED);
2975 +                       break;
2976 +#endif
2977                 case Opt_nocheck:
2978                         clear_opt (sbi->s_mount_opt, CHECK);
2979                         break;
2980 @@ -1731,6 +1749,9 @@ static int ext3_fill_super (struct super
2981                             NULL, 0))
2982                 goto failed_mount;
2983  
2984 +       if (EXT3_SB(sb)->s_mount_opt & EXT3_MOUNT_TAGGED)
2985 +               sb->s_flags |= MS_TAGGED;
2986 +
2987         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
2988                 (test_opt(sb, POSIX_ACL) ? MS_POSIXACL : 0);
2989  
2990 @@ -2618,6 +2639,14 @@ static int ext3_remount (struct super_bl
2991         if (test_opt(sb, ABORT))
2992                 ext3_abort(sb, __func__, "Abort forced by user");
2993  
2994 +       if ((sbi->s_mount_opt & EXT3_MOUNT_TAGGED) &&
2995 +               !(sb->s_flags & MS_TAGGED)) {
2996 +               printk("EXT3-fs: %s: tagging not permitted on remount.\n",
2997 +                       sb->s_id);
2998 +               err = -EINVAL;
2999 +               goto restore_opts;
3000 +       }
3001 +
3002         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
3003                 (test_opt(sb, POSIX_ACL) ? MS_POSIXACL : 0);
3004  
3005 diff -NurpP --minimal linux-3.6.10/fs/ext4/ext4.h linux-3.6.10-vs2.3.4.5/fs/ext4/ext4.h
3006 --- linux-3.6.10/fs/ext4/ext4.h 2012-12-11 12:36:57.000000000 +0100
3007 +++ linux-3.6.10-vs2.3.4.5/fs/ext4/ext4.h       2012-12-08 01:36:33.000000000 +0100
3008 @@ -393,8 +393,12 @@ struct flex_groups {
3009  #define EXT4_EXTENTS_FL                        0x00080000 /* Inode uses extents */
3010  #define EXT4_EA_INODE_FL               0x00200000 /* Inode used for large EA */
3011  #define EXT4_EOFBLOCKS_FL              0x00400000 /* Blocks allocated beyond EOF */
3012 +#define EXT4_IXUNLINK_FL               0x08000000 /* Immutable invert on unlink */
3013  #define EXT4_RESERVED_FL               0x80000000 /* reserved for ext4 lib */
3014  
3015 +#define EXT4_BARRIER_FL                        0x04000000 /* Barrier for chroot() */
3016 +#define EXT4_COW_FL                    0x20000000 /* Copy on Write marker */
3017 +
3018  #define EXT4_FL_USER_VISIBLE           0x004BDFFF /* User visible flags */
3019  #define EXT4_FL_USER_MODIFIABLE                0x004B80FF /* User modifiable flags */
3020  
3021 @@ -666,7 +670,7 @@ struct ext4_inode {
3022                         __le16  l_i_uid_high;   /* these 2 fields */
3023                         __le16  l_i_gid_high;   /* were reserved2[0] */
3024                         __le16  l_i_checksum_lo;/* crc32c(uuid+inum+inode) LE */
3025 -                       __le16  l_i_reserved;
3026 +                       __le16  l_i_tag;        /* Context Tag */
3027                 } linux2;
3028                 struct {
3029                         __le16  h_i_reserved1;  /* Obsoleted fragment number/size which are removed in ext4 */
3030 @@ -784,6 +788,7 @@ do {                                                                               \
3031  #define i_gid_low      i_gid
3032  #define i_uid_high     osd2.linux2.l_i_uid_high
3033  #define i_gid_high     osd2.linux2.l_i_gid_high
3034 +#define i_raw_tag      osd2.linux2.l_i_tag
3035  #define i_checksum_lo  osd2.linux2.l_i_checksum_lo
3036  
3037  #elif defined(__GNU__)
3038 @@ -964,6 +969,7 @@ struct ext4_inode_info {
3039  #define EXT4_MOUNT_POSIX_ACL           0x08000 /* POSIX Access Control Lists */
3040  #define EXT4_MOUNT_NO_AUTO_DA_ALLOC    0x10000 /* No auto delalloc mapping */
3041  #define EXT4_MOUNT_BARRIER             0x20000 /* Use block barriers */
3042 +#define EXT4_MOUNT_TAGGED              0x40000 /* Enable Context Tags */
3043  #define EXT4_MOUNT_QUOTA               0x80000 /* Some quota option set */
3044  #define EXT4_MOUNT_USRQUOTA            0x100000 /* "old" user quota */
3045  #define EXT4_MOUNT_GRPQUOTA            0x200000 /* "old" group quota */
3046 @@ -2392,6 +2398,7 @@ extern int ext4_map_blocks(handle_t *han
3047                            struct ext4_map_blocks *map, int flags);
3048  extern int ext4_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
3049                         __u64 start, __u64 len);
3050 +extern int ext4_sync_flags(struct inode *, int, int);
3051  /* move_extent.c */
3052  extern int ext4_move_extents(struct file *o_filp, struct file *d_filp,
3053                              __u64 start_orig, __u64 start_donor,
3054 diff -NurpP --minimal linux-3.6.10/fs/ext4/file.c linux-3.6.10-vs2.3.4.5/fs/ext4/file.c
3055 --- linux-3.6.10/fs/ext4/file.c 2012-10-04 15:27:39.000000000 +0200
3056 +++ linux-3.6.10-vs2.3.4.5/fs/ext4/file.c       2012-10-04 18:47:00.000000000 +0200
3057 @@ -334,5 +334,6 @@ const struct inode_operations ext4_file_
3058  #endif
3059         .get_acl        = ext4_get_acl,
3060         .fiemap         = ext4_fiemap,
3061 +       .sync_flags     = ext4_sync_flags,
3062  };
3063  
3064 diff -NurpP --minimal linux-3.6.10/fs/ext4/ialloc.c linux-3.6.10-vs2.3.4.5/fs/ext4/ialloc.c
3065 --- linux-3.6.10/fs/ext4/ialloc.c       2012-12-11 12:36:57.000000000 +0100
3066 +++ linux-3.6.10-vs2.3.4.5/fs/ext4/ialloc.c     2012-11-06 18:43:41.000000000 +0100
3067 @@ -22,6 +22,7 @@
3068  #include <linux/random.h>
3069  #include <linux/bitops.h>
3070  #include <linux/blkdev.h>
3071 +#include <linux/vs_tag.h>
3072  #include <asm/byteorder.h>
3073  
3074  #include "ext4.h"
3075 @@ -839,6 +840,7 @@ got:
3076                 inode->i_mode = mode;
3077                 inode->i_uid = current_fsuid();
3078                 inode->i_gid = dir->i_gid;
3079 +               inode->i_tag = dx_current_fstag(sb);
3080         } else
3081                 inode_init_owner(inode, dir, mode);
3082  
3083 diff -NurpP --minimal linux-3.6.10/fs/ext4/inode.c linux-3.6.10-vs2.3.4.5/fs/ext4/inode.c
3084 --- linux-3.6.10/fs/ext4/inode.c        2012-12-11 12:36:57.000000000 +0100
3085 +++ linux-3.6.10-vs2.3.4.5/fs/ext4/inode.c      2012-11-06 18:43:41.000000000 +0100
3086 @@ -37,6 +37,7 @@
3087  #include <linux/printk.h>
3088  #include <linux/slab.h>
3089  #include <linux/ratelimit.h>
3090 +#include <linux/vs_tag.h>
3091  
3092  #include "ext4_jbd2.h"
3093  #include "xattr.h"
3094 @@ -3715,41 +3716,64 @@ void ext4_set_inode_flags(struct inode *
3095  {
3096         unsigned int flags = EXT4_I(inode)->i_flags;
3097  
3098 -       inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
3099 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
3100 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
3101 +
3102 +       if (flags & EXT4_IMMUTABLE_FL)
3103 +               inode->i_flags |= S_IMMUTABLE;
3104 +       if (flags & EXT4_IXUNLINK_FL)
3105 +               inode->i_flags |= S_IXUNLINK;
3106 +
3107         if (flags & EXT4_SYNC_FL)
3108                 inode->i_flags |= S_SYNC;
3109         if (flags & EXT4_APPEND_FL)
3110                 inode->i_flags |= S_APPEND;
3111 -       if (flags & EXT4_IMMUTABLE_FL)
3112 -               inode->i_flags |= S_IMMUTABLE;
3113         if (flags & EXT4_NOATIME_FL)
3114                 inode->i_flags |= S_NOATIME;
3115         if (flags & EXT4_DIRSYNC_FL)
3116                 inode->i_flags |= S_DIRSYNC;
3117 +
3118 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
3119 +
3120 +       if (flags & EXT4_BARRIER_FL)
3121 +               inode->i_vflags |= V_BARRIER;
3122 +       if (flags & EXT4_COW_FL)
3123 +               inode->i_vflags |= V_COW;
3124  }
3125  
3126  /* Propagate flags from i_flags to EXT4_I(inode)->i_flags */
3127  void ext4_get_inode_flags(struct ext4_inode_info *ei)
3128  {
3129 -       unsigned int vfs_fl;
3130 +       unsigned int vfs_fl, vfs_vf;
3131         unsigned long old_fl, new_fl;
3132  
3133         do {
3134                 vfs_fl = ei->vfs_inode.i_flags;
3135 +               vfs_vf = ei->vfs_inode.i_vflags;
3136                 old_fl = ei->i_flags;
3137                 new_fl = old_fl & ~(EXT4_SYNC_FL|EXT4_APPEND_FL|
3138                                 EXT4_IMMUTABLE_FL|EXT4_NOATIME_FL|
3139 -                               EXT4_DIRSYNC_FL);
3140 +                               EXT4_DIRSYNC_FL|EXT4_BARRIER_FL|
3141 +                               EXT4_COW_FL);
3142 +
3143 +               if (vfs_fl & S_IMMUTABLE)
3144 +                       new_fl |= EXT4_IMMUTABLE_FL;
3145 +               if (vfs_fl & S_IXUNLINK)
3146 +                       new_fl |= EXT4_IXUNLINK_FL;
3147 +
3148                 if (vfs_fl & S_SYNC)
3149                         new_fl |= EXT4_SYNC_FL;
3150                 if (vfs_fl & S_APPEND)
3151                         new_fl |= EXT4_APPEND_FL;
3152 -               if (vfs_fl & S_IMMUTABLE)
3153 -                       new_fl |= EXT4_IMMUTABLE_FL;
3154                 if (vfs_fl & S_NOATIME)
3155                         new_fl |= EXT4_NOATIME_FL;
3156                 if (vfs_fl & S_DIRSYNC)
3157                         new_fl |= EXT4_DIRSYNC_FL;
3158 +
3159 +               if (vfs_vf & V_BARRIER)
3160 +                       new_fl |= EXT4_BARRIER_FL;
3161 +               if (vfs_vf & V_COW)
3162 +                       new_fl |= EXT4_COW_FL;
3163         } while (cmpxchg(&ei->i_flags, old_fl, new_fl) != old_fl);
3164  }
3165  
3166 @@ -3841,8 +3865,10 @@ struct inode *ext4_iget(struct super_blo
3167                 i_uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
3168                 i_gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
3169         }
3170 -       i_uid_write(inode, i_uid);
3171 -       i_gid_write(inode, i_gid);
3172 +       i_uid_write(inode, INOTAG_UID(DX_TAG(inode), i_uid, i_gid));
3173 +       i_gid_write(inode, INOTAG_GID(DX_TAG(inode), i_uid, i_gid));
3174 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), i_uid, i_gid,
3175 +               le16_to_cpu(raw_inode->i_raw_tag));
3176         set_nlink(inode, le16_to_cpu(raw_inode->i_links_count));
3177  
3178         ext4_clear_state_flags(ei);     /* Only relevant on 32-bit archs */
3179 @@ -4066,8 +4092,8 @@ static int ext4_do_update_inode(handle_t
3180  
3181         ext4_get_inode_flags(ei);
3182         raw_inode->i_mode = cpu_to_le16(inode->i_mode);
3183 -       i_uid = i_uid_read(inode);
3184 -       i_gid = i_gid_read(inode);
3185 +       i_uid = TAGINO_UID(DX_TAG(inode), i_uid_read(inode), inode->i_tag);
3186 +       i_gid = TAGINO_GID(DX_TAG(inode), i_gid_read(inode), inode->i_tag);
3187         if (!(test_opt(inode->i_sb, NO_UID32))) {
3188                 raw_inode->i_uid_low = cpu_to_le16(low_16_bits(i_uid));
3189                 raw_inode->i_gid_low = cpu_to_le16(low_16_bits(i_gid));
3190 @@ -4090,6 +4116,9 @@ static int ext4_do_update_inode(handle_t
3191                 raw_inode->i_uid_high = 0;
3192                 raw_inode->i_gid_high = 0;
3193         }
3194 +#ifdef CONFIG_TAGGING_INTERN
3195 +       raw_inode->i_raw_tag = cpu_to_le16(inode->i_tag);
3196 +#endif
3197         raw_inode->i_links_count = cpu_to_le16(inode->i_nlink);
3198  
3199         EXT4_INODE_SET_XTIME(i_ctime, inode, raw_inode);
3200 @@ -4278,7 +4307,8 @@ int ext4_setattr(struct dentry *dentry, 
3201         if (is_quota_modification(inode, attr))
3202                 dquot_initialize(inode);
3203         if ((ia_valid & ATTR_UID && !uid_eq(attr->ia_uid, inode->i_uid)) ||
3204 -           (ia_valid & ATTR_GID && !gid_eq(attr->ia_gid, inode->i_gid))) {
3205 +           (ia_valid & ATTR_GID && !gid_eq(attr->ia_gid, inode->i_gid)) ||
3206 +           (ia_valid & ATTR_TAG && attr->ia_tag != inode->i_tag)) {
3207                 handle_t *handle;
3208  
3209                 /* (user+group)*(old+new) structure, inode write (sb,
3210 @@ -4300,6 +4330,8 @@ int ext4_setattr(struct dentry *dentry, 
3211                         inode->i_uid = attr->ia_uid;
3212                 if (attr->ia_valid & ATTR_GID)
3213                         inode->i_gid = attr->ia_gid;
3214 +               if ((attr->ia_valid & ATTR_TAG) && IS_TAGGED(inode))
3215 +                       inode->i_tag = attr->ia_tag;
3216                 error = ext4_mark_inode_dirty(handle, inode);
3217                 ext4_journal_stop(handle);
3218         }
3219 diff -NurpP --minimal linux-3.6.10/fs/ext4/ioctl.c linux-3.6.10-vs2.3.4.5/fs/ext4/ioctl.c
3220 --- linux-3.6.10/fs/ext4/ioctl.c        2012-10-04 15:27:39.000000000 +0200
3221 +++ linux-3.6.10-vs2.3.4.5/fs/ext4/ioctl.c      2012-10-04 18:47:00.000000000 +0200
3222 @@ -14,12 +14,40 @@
3223  #include <linux/compat.h>
3224  #include <linux/mount.h>
3225  #include <linux/file.h>
3226 +#include <linux/vs_tag.h>
3227  #include <asm/uaccess.h>
3228  #include "ext4_jbd2.h"
3229  #include "ext4.h"
3230  
3231  #define MAX_32_NUM ((((unsigned long long) 1) << 32) - 1)
3232  
3233 +int ext4_sync_flags(struct inode *inode, int flags, int vflags)
3234 +{
3235 +       handle_t *handle = NULL;
3236 +       struct ext4_iloc iloc;
3237 +       int err;
3238 +
3239 +       handle = ext4_journal_start(inode, 1);
3240 +       if (IS_ERR(handle))
3241 +               return PTR_ERR(handle);
3242 +
3243 +       if (IS_SYNC(inode))
3244 +               ext4_handle_sync(handle);
3245 +       err = ext4_reserve_inode_write(handle, inode, &iloc);
3246 +       if (err)
3247 +               goto flags_err;
3248 +
3249 +       inode->i_flags = flags;
3250 +       inode->i_vflags = vflags;
3251 +       ext4_get_inode_flags(EXT4_I(inode));
3252 +       inode->i_ctime = ext4_current_time(inode);
3253 +
3254 +       err = ext4_mark_iloc_dirty(handle, inode, &iloc);
3255 +flags_err:
3256 +       ext4_journal_stop(handle);
3257 +       return err;
3258 +}
3259 +
3260  long ext4_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
3261  {
3262         struct inode *inode = filp->f_dentry->d_inode;
3263 @@ -53,6 +81,11 @@ long ext4_ioctl(struct file *filp, unsig
3264  
3265                 flags = ext4_mask_flags(inode->i_mode, flags);
3266  
3267 +               if (IS_BARRIER(inode)) {
3268 +                       vxwprintk_task(1, "messing with the barrier.");
3269 +                       return -EACCES;
3270 +               }
3271 +
3272                 err = -EPERM;
3273                 mutex_lock(&inode->i_mutex);
3274                 /* Is it quota file? Do not allow user to mess with it */
3275 @@ -70,7 +103,9 @@ long ext4_ioctl(struct file *filp, unsig
3276                  *
3277                  * This test looks nicer. Thanks to Pauline Middelink
3278                  */
3279 -               if ((flags ^ oldflags) & (EXT4_APPEND_FL | EXT4_IMMUTABLE_FL)) {
3280 +               if ((oldflags & EXT4_IMMUTABLE_FL) ||
3281 +                       ((flags ^ oldflags) & (EXT4_APPEND_FL |
3282 +                       EXT4_IMMUTABLE_FL | EXT4_IXUNLINK_FL))) {
3283                         if (!capable(CAP_LINUX_IMMUTABLE))
3284                                 goto flags_out;
3285                 }
3286 diff -NurpP --minimal linux-3.6.10/fs/ext4/namei.c linux-3.6.10-vs2.3.4.5/fs/ext4/namei.c
3287 --- linux-3.6.10/fs/ext4/namei.c        2012-12-11 12:36:57.000000000 +0100
3288 +++ linux-3.6.10-vs2.3.4.5/fs/ext4/namei.c      2012-11-06 18:43:41.000000000 +0100
3289 @@ -34,6 +34,7 @@
3290  #include <linux/quotaops.h>
3291  #include <linux/buffer_head.h>
3292  #include <linux/bio.h>
3293 +#include <linux/vs_tag.h>
3294  #include "ext4.h"
3295  #include "ext4_jbd2.h"
3296  
3297 @@ -1199,6 +1200,7 @@ restart:
3298                                         ll_rw_block(READ | REQ_META | REQ_PRIO,
3299                                                     1, &bh);
3300                         }
3301 +               dx_propagate_tag(nd, inode);
3302                 }
3303                 if ((bh = bh_use[ra_ptr++]) == NULL)
3304                         goto next;
3305 @@ -2982,6 +2984,7 @@ const struct inode_operations ext4_dir_i
3306  #endif
3307         .get_acl        = ext4_get_acl,
3308         .fiemap         = ext4_fiemap,
3309 +       .sync_flags     = ext4_sync_flags,
3310  };
3311  
3312  const struct inode_operations ext4_special_inode_operations = {
3313 diff -NurpP --minimal linux-3.6.10/fs/ext4/super.c linux-3.6.10-vs2.3.4.5/fs/ext4/super.c
3314 --- linux-3.6.10/fs/ext4/super.c        2012-12-11 12:36:57.000000000 +0100
3315 +++ linux-3.6.10-vs2.3.4.5/fs/ext4/super.c      2012-12-08 01:36:33.000000000 +0100
3316 @@ -1220,6 +1220,7 @@ enum {
3317         Opt_inode_readahead_blks, Opt_journal_ioprio,
3318         Opt_dioread_nolock, Opt_dioread_lock,
3319         Opt_discard, Opt_nodiscard, Opt_init_itable, Opt_noinit_itable,
3320 +       Opt_tag, Opt_notag, Opt_tagid
3321  };
3322  
3323  static const match_table_t tokens = {
3324 @@ -1298,6 +1299,9 @@ static const match_table_t tokens = {
3325         {Opt_removed, "reservation"},   /* mount option from ext2/3 */
3326         {Opt_removed, "noreservation"}, /* mount option from ext2/3 */
3327         {Opt_removed, "journal=%u"},    /* mount option from ext2/3 */
3328 +       {Opt_tag, "tag"},
3329 +       {Opt_notag, "notag"},
3330 +       {Opt_tagid, "tagid=%u"},
3331         {Opt_err, NULL},
3332  };
3333  
3334 @@ -1544,6 +1548,20 @@ static int handle_mount_opt(struct super
3335                         return -1;
3336                 *journal_ioprio = IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE, arg);
3337                 return 1;
3338 +#ifndef CONFIG_TAGGING_NONE
3339 +       case Opt_tag:
3340 +               set_opt(sb, TAGGED);
3341 +               return 1;
3342 +       case Opt_notag:
3343 +               clear_opt(sb, TAGGED);
3344 +               return 1;
3345 +#endif
3346 +#ifdef CONFIG_PROPAGATE
3347 +       case Opt_tagid:
3348 +               /* use args[0] */
3349 +               set_opt(sb, TAGGED);
3350 +               return 1;
3351 +#endif
3352         }
3353  
3354         for (m = ext4_mount_opts; m->token != Opt_err; m++) {
3355 @@ -3418,6 +3436,9 @@ static int ext4_fill_super(struct super_
3356                 }
3357         }
3358  
3359 +       if (EXT4_SB(sb)->s_mount_opt & EXT4_MOUNT_TAGGED)
3360 +               sb->s_flags |= MS_TAGGED;
3361 +
3362         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
3363                 (test_opt(sb, POSIX_ACL) ? MS_POSIXACL : 0);
3364  
3365 @@ -4583,6 +4604,14 @@ static int ext4_remount(struct super_blo
3366         if (sbi->s_mount_flags & EXT4_MF_FS_ABORTED)
3367                 ext4_abort(sb, "Abort forced by user");
3368  
3369 +       if ((sbi->s_mount_opt & EXT4_MOUNT_TAGGED) &&
3370 +               !(sb->s_flags & MS_TAGGED)) {
3371 +               printk("EXT4-fs: %s: tagging not permitted on remount.\n",
3372 +                       sb->s_id);
3373 +               err = -EINVAL;
3374 +               goto restore_opts;
3375 +       }
3376 +
3377         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
3378                 (test_opt(sb, POSIX_ACL) ? MS_POSIXACL : 0);
3379  
3380 diff -NurpP --minimal linux-3.6.10/fs/fcntl.c linux-3.6.10-vs2.3.4.5/fs/fcntl.c
3381 --- linux-3.6.10/fs/fcntl.c     2012-10-04 15:27:39.000000000 +0200
3382 +++ linux-3.6.10-vs2.3.4.5/fs/fcntl.c   2012-10-04 19:05:02.000000000 +0200
3383 @@ -21,6 +21,7 @@
3384  #include <linux/rcupdate.h>
3385  #include <linux/pid_namespace.h>
3386  #include <linux/user_namespace.h>
3387 +#include <linux/vs_limit.h>
3388  
3389  #include <asm/poll.h>
3390  #include <asm/siginfo.h>
3391 @@ -104,6 +105,8 @@ SYSCALL_DEFINE3(dup3, unsigned int, oldf
3392  
3393         if (tofree)
3394                 filp_close(tofree, files);
3395 +       else
3396 +               vx_openfd_inc(newfd);   /* fd was unused */
3397  
3398         return newfd;
3399  
3400 @@ -477,6 +480,8 @@ SYSCALL_DEFINE3(fcntl, unsigned int, fd,
3401         filp = fget_raw_light(fd, &fput_needed);
3402         if (!filp)
3403                 goto out;
3404 +       if (!vx_files_avail(1))
3405 +               goto out;
3406  
3407         if (unlikely(filp->f_mode & FMODE_PATH)) {
3408                 if (!check_fcntl_cmd(cmd))
3409 diff -NurpP --minimal linux-3.6.10/fs/file.c linux-3.6.10-vs2.3.4.5/fs/file.c
3410 --- linux-3.6.10/fs/file.c      2012-05-21 18:07:20.000000000 +0200
3411 +++ linux-3.6.10-vs2.3.4.5/fs/file.c    2012-10-04 18:47:00.000000000 +0200
3412 @@ -21,6 +21,7 @@
3413  #include <linux/spinlock.h>
3414  #include <linux/rcupdate.h>
3415  #include <linux/workqueue.h>
3416 +#include <linux/vs_limit.h>
3417  
3418  struct fdtable_defer {
3419         spinlock_t lock;
3420 @@ -358,6 +359,8 @@ struct files_struct *dup_fd(struct files
3421                 struct file *f = *old_fds++;
3422                 if (f) {
3423                         get_file(f);
3424 +                       /* TODO: sum it first for check and performance */
3425 +                       vx_openfd_inc(open_files - i);
3426                 } else {
3427                         /*
3428                          * The fd may be claimed in the fd bitmap but not yet
3429 @@ -464,6 +467,7 @@ repeat:
3430         else
3431                 __clear_close_on_exec(fd, fdt);
3432         error = fd;
3433 +       vx_openfd_inc(fd);
3434  #if 1
3435         /* Sanity check */
3436         if (rcu_dereference_raw(fdt->fd[fd]) != NULL) {
3437 diff -NurpP --minimal linux-3.6.10/fs/file_table.c linux-3.6.10-vs2.3.4.5/fs/file_table.c
3438 --- linux-3.6.10/fs/file_table.c        2012-10-04 15:27:39.000000000 +0200
3439 +++ linux-3.6.10-vs2.3.4.5/fs/file_table.c      2012-11-17 14:36:19.000000000 +0100
3440 @@ -26,6 +26,8 @@
3441  #include <linux/hardirq.h>
3442  #include <linux/task_work.h>
3443  #include <linux/ima.h>
3444 +#include <linux/vs_limit.h>
3445 +#include <linux/vs_context.h>
3446  
3447  #include <linux/atomic.h>
3448  
3449 @@ -136,6 +138,8 @@ struct file *get_empty_filp(void)
3450         spin_lock_init(&f->f_lock);
3451         eventpoll_init_file(f);
3452         /* f->f_version: 0 */
3453 +       f->f_xid = vx_current_xid();
3454 +       vx_files_inc(f);
3455         return f;
3456  
3457  over:
3458 @@ -257,6 +261,8 @@ static void __fput(struct file *file)
3459                 i_readcount_dec(inode);
3460         if (file->f_mode & FMODE_WRITE)
3461                 drop_file_write_access(file);
3462 +       vx_files_dec(file);
3463 +       file->f_xid = 0;
3464         file->f_path.dentry = NULL;
3465         file->f_path.mnt = NULL;
3466         file_free(file);
3467 @@ -449,6 +455,8 @@ void put_filp(struct file *file)
3468  {
3469         if (atomic_long_dec_and_test(&file->f_count)) {
3470                 security_file_free(file);
3471 +               vx_files_dec(file);
3472 +               file->f_xid = 0;
3473                 file_sb_list_del(file);
3474                 file_free(file);
3475         }
3476 diff -NurpP --minimal linux-3.6.10/fs/fs_struct.c linux-3.6.10-vs2.3.4.5/fs/fs_struct.c
3477 --- linux-3.6.10/fs/fs_struct.c 2012-10-04 15:27:39.000000000 +0200
3478 +++ linux-3.6.10-vs2.3.4.5/fs/fs_struct.c       2012-10-04 19:08:56.000000000 +0200
3479 @@ -4,6 +4,7 @@
3480  #include <linux/path.h>
3481  #include <linux/slab.h>
3482  #include <linux/fs_struct.h>
3483 +#include <linux/vserver/global.h>
3484  #include "internal.h"
3485  
3486  /*
3487 @@ -87,6 +88,7 @@ void free_fs_struct(struct fs_struct *fs
3488  {
3489         path_put(&fs->root);
3490         path_put(&fs->pwd);
3491 +       atomic_dec(&vs_global_fs);
3492         kmem_cache_free(fs_cachep, fs);
3493  }
3494  
3495 @@ -124,6 +126,7 @@ struct fs_struct *copy_fs_struct(struct 
3496                 fs->pwd = old->pwd;
3497                 path_get(&fs->pwd);
3498                 spin_unlock(&old->lock);
3499 +               atomic_inc(&vs_global_fs);
3500         }
3501         return fs;
3502  }
3503 diff -NurpP --minimal linux-3.6.10/fs/gfs2/file.c linux-3.6.10-vs2.3.4.5/fs/gfs2/file.c
3504 --- linux-3.6.10/fs/gfs2/file.c 2012-12-11 12:36:57.000000000 +0100
3505 +++ linux-3.6.10-vs2.3.4.5/fs/gfs2/file.c       2012-12-08 01:36:33.000000000 +0100
3506 @@ -143,6 +143,9 @@ static const u32 fsflags_to_gfs2[32] = {
3507         [12] = GFS2_DIF_EXHASH,
3508         [14] = GFS2_DIF_INHERIT_JDATA,
3509         [17] = GFS2_DIF_TOPDIR,
3510 +       [27] = GFS2_DIF_IXUNLINK,
3511 +       [26] = GFS2_DIF_BARRIER,
3512 +       [29] = GFS2_DIF_COW,
3513  };
3514  
3515  static const u32 gfs2_to_fsflags[32] = {
3516 @@ -153,6 +156,9 @@ static const u32 gfs2_to_fsflags[32] = {
3517         [gfs2fl_ExHash] = FS_INDEX_FL,
3518         [gfs2fl_TopLevel] = FS_TOPDIR_FL,
3519         [gfs2fl_InheritJdata] = FS_JOURNAL_DATA_FL,
3520 +       [gfs2fl_IXUnlink] = FS_IXUNLINK_FL,
3521 +       [gfs2fl_Barrier] = FS_BARRIER_FL,
3522 +       [gfs2fl_Cow] = FS_COW_FL,
3523  };
3524  
3525  static int gfs2_get_flags(struct file *filp, u32 __user *ptr)
3526 @@ -183,12 +189,18 @@ void gfs2_set_inode_flags(struct inode *
3527  {
3528         struct gfs2_inode *ip = GFS2_I(inode);
3529         unsigned int flags = inode->i_flags;
3530 +       unsigned int vflags = inode->i_vflags;
3531 +
3532 +       flags &= ~(S_IMMUTABLE | S_IXUNLINK |
3533 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC | S_NOSEC);
3534  
3535 -       flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC|S_NOSEC);
3536         if ((ip->i_eattr == 0) && !is_sxid(inode->i_mode))
3537                 inode->i_flags |= S_NOSEC;
3538         if (ip->i_diskflags & GFS2_DIF_IMMUTABLE)
3539                 flags |= S_IMMUTABLE;
3540 +       if (ip->i_diskflags & GFS2_DIF_IXUNLINK)
3541 +               flags |= S_IXUNLINK;
3542 +
3543         if (ip->i_diskflags & GFS2_DIF_APPENDONLY)
3544                 flags |= S_APPEND;
3545         if (ip->i_diskflags & GFS2_DIF_NOATIME)
3546 @@ -196,6 +208,43 @@ void gfs2_set_inode_flags(struct inode *
3547         if (ip->i_diskflags & GFS2_DIF_SYNC)
3548                 flags |= S_SYNC;
3549         inode->i_flags = flags;
3550 +
3551 +       vflags &= ~(V_BARRIER | V_COW);
3552 +
3553 +       if (ip->i_diskflags & GFS2_DIF_BARRIER)
3554 +               vflags |= V_BARRIER;
3555 +       if (ip->i_diskflags & GFS2_DIF_COW)
3556 +               vflags |= V_COW;
3557 +       inode->i_vflags = vflags;
3558 +}
3559 +
3560 +void gfs2_get_inode_flags(struct inode *inode)
3561 +{
3562 +       struct gfs2_inode *ip = GFS2_I(inode);
3563 +       unsigned int flags = inode->i_flags;
3564 +       unsigned int vflags = inode->i_vflags;
3565 +
3566 +       ip->i_diskflags &= ~(GFS2_DIF_APPENDONLY |
3567 +                       GFS2_DIF_NOATIME | GFS2_DIF_SYNC |
3568 +                       GFS2_DIF_IMMUTABLE | GFS2_DIF_IXUNLINK |
3569 +                       GFS2_DIF_BARRIER | GFS2_DIF_COW);
3570 +
3571 +       if (flags & S_IMMUTABLE)
3572 +               ip->i_diskflags |= GFS2_DIF_IMMUTABLE;
3573 +       if (flags & S_IXUNLINK)
3574 +               ip->i_diskflags |= GFS2_DIF_IXUNLINK;
3575 +
3576 +       if (flags & S_APPEND)
3577 +               ip->i_diskflags |= GFS2_DIF_APPENDONLY;
3578 +       if (flags & S_NOATIME)
3579 +               ip->i_diskflags |= GFS2_DIF_NOATIME;
3580 +       if (flags & S_SYNC)
3581 +               ip->i_diskflags |= GFS2_DIF_SYNC;
3582 +
3583 +       if (vflags & V_BARRIER)
3584 +               ip->i_diskflags |= GFS2_DIF_BARRIER;
3585 +       if (vflags & V_COW)
3586 +               ip->i_diskflags |= GFS2_DIF_COW;
3587  }
3588  
3589  /* Flags that can be set by user space */
3590 @@ -309,6 +358,37 @@ static int gfs2_set_flags(struct file *f
3591         return do_gfs2_set_flags(filp, gfsflags, ~GFS2_DIF_JDATA);
3592  }
3593  
3594 +int gfs2_sync_flags(struct inode *inode, int flags, int vflags)
3595 +{
3596 +       struct gfs2_inode *ip = GFS2_I(inode);
3597 +       struct gfs2_sbd *sdp = GFS2_SB(inode);
3598 +       struct buffer_head *bh;
3599 +       struct gfs2_holder gh;
3600 +       int error;
3601 +
3602 +       error = gfs2_glock_nq_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &gh);
3603 +       if (error)
3604 +               return error;
3605 +       error = gfs2_trans_begin(sdp, RES_DINODE, 0);
3606 +       if (error)
3607 +               goto out;
3608 +       error = gfs2_meta_inode_buffer(ip, &bh);
3609 +       if (error)
3610 +               goto out_trans_end;
3611 +       gfs2_trans_add_bh(ip->i_gl, bh, 1);
3612 +       inode->i_flags = flags;
3613 +       inode->i_vflags = vflags;
3614 +       gfs2_get_inode_flags(inode);
3615 +       gfs2_dinode_out(ip, bh->b_data);
3616 +       brelse(bh);
3617 +       gfs2_set_aops(inode);
3618 +out_trans_end:
3619 +       gfs2_trans_end(sdp);
3620 +out:
3621 +       gfs2_glock_dq_uninit(&gh);
3622 +       return error;
3623 +}
3624 +
3625  static long gfs2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
3626  {
3627         switch(cmd) {
3628 diff -NurpP --minimal linux-3.6.10/fs/gfs2/inode.h linux-3.6.10-vs2.3.4.5/fs/gfs2/inode.h
3629 --- linux-3.6.10/fs/gfs2/inode.h        2012-07-22 23:39:40.000000000 +0200
3630 +++ linux-3.6.10-vs2.3.4.5/fs/gfs2/inode.h      2012-10-04 18:47:00.000000000 +0200
3631 @@ -117,6 +117,7 @@ extern const struct file_operations gfs2
3632  extern const struct file_operations gfs2_dir_fops_nolock;
3633  
3634  extern void gfs2_set_inode_flags(struct inode *inode);
3635 +extern int gfs2_sync_flags(struct inode *inode, int flags, int vflags);
3636   
3637  #ifdef CONFIG_GFS2_FS_LOCKING_DLM
3638  extern const struct file_operations gfs2_file_fops;
3639 diff -NurpP --minimal linux-3.6.10/fs/inode.c linux-3.6.10-vs2.3.4.5/fs/inode.c
3640 --- linux-3.6.10/fs/inode.c     2012-12-11 12:36:58.000000000 +0100
3641 +++ linux-3.6.10-vs2.3.4.5/fs/inode.c   2012-12-08 01:36:33.000000000 +0100
3642 @@ -17,6 +17,7 @@
3643  #include <linux/prefetch.h>
3644  #include <linux/buffer_head.h> /* for inode_has_buffers */
3645  #include <linux/ratelimit.h>
3646 +#include <linux/vs_tag.h>
3647  #include "internal.h"
3648  
3649  /*
3650 @@ -128,6 +129,9 @@ int inode_init_always(struct super_block
3651         struct address_space *const mapping = &inode->i_data;
3652  
3653         inode->i_sb = sb;
3654 +
3655 +       /* essential because of inode slab reuse */
3656 +       inode->i_tag = 0;
3657         inode->i_blkbits = sb->s_blocksize_bits;
3658         inode->i_flags = 0;
3659         atomic_set(&inode->i_count, 1);
3660 @@ -149,6 +153,7 @@ int inode_init_always(struct super_block
3661         inode->i_bdev = NULL;
3662         inode->i_cdev = NULL;
3663         inode->i_rdev = 0;
3664 +       inode->i_mdev = 0;
3665         inode->dirtied_when = 0;
3666  
3667         if (security_inode_alloc(inode))
3668 @@ -483,6 +488,8 @@ void __insert_inode_hash(struct inode *i
3669  }
3670  EXPORT_SYMBOL(__insert_inode_hash);
3671  
3672 +EXPORT_SYMBOL_GPL(__iget);
3673 +
3674  /**
3675   *     __remove_inode_hash - remove an inode from the hash
3676   *     @inode: inode to unhash
3677 @@ -1804,9 +1811,11 @@ void init_special_inode(struct inode *in
3678         if (S_ISCHR(mode)) {
3679                 inode->i_fop = &def_chr_fops;
3680                 inode->i_rdev = rdev;
3681 +               inode->i_mdev = rdev;
3682         } else if (S_ISBLK(mode)) {
3683                 inode->i_fop = &def_blk_fops;
3684                 inode->i_rdev = rdev;
3685 +               inode->i_mdev = rdev;
3686         } else if (S_ISFIFO(mode))
3687                 inode->i_fop = &def_fifo_fops;
3688         else if (S_ISSOCK(mode))
3689 @@ -1835,6 +1844,7 @@ void inode_init_owner(struct inode *inod
3690         } else
3691                 inode->i_gid = current_fsgid();
3692         inode->i_mode = mode;
3693 +       inode->i_tag = dx_current_fstag(inode->i_sb);
3694  }
3695  EXPORT_SYMBOL(inode_init_owner);
3696  
3697 diff -NurpP --minimal linux-3.6.10/fs/ioctl.c linux-3.6.10-vs2.3.4.5/fs/ioctl.c
3698 --- linux-3.6.10/fs/ioctl.c     2012-05-21 18:07:24.000000000 +0200
3699 +++ linux-3.6.10-vs2.3.4.5/fs/ioctl.c   2012-10-04 18:47:00.000000000 +0200
3700 @@ -15,6 +15,9 @@
3701  #include <linux/writeback.h>
3702  #include <linux/buffer_head.h>
3703  #include <linux/falloc.h>
3704 +#include <linux/proc_fs.h>
3705 +#include <linux/vserver/inode.h>
3706 +#include <linux/vs_tag.h>
3707  
3708  #include <asm/ioctls.h>
3709  
3710 diff -NurpP --minimal linux-3.6.10/fs/ioprio.c linux-3.6.10-vs2.3.4.5/fs/ioprio.c
3711 --- linux-3.6.10/fs/ioprio.c    2012-07-22 23:39:40.000000000 +0200
3712 +++ linux-3.6.10-vs2.3.4.5/fs/ioprio.c  2012-10-04 18:47:00.000000000 +0200
3713 @@ -28,6 +28,7 @@
3714  #include <linux/syscalls.h>
3715  #include <linux/security.h>
3716  #include <linux/pid_namespace.h>
3717 +#include <linux/vs_base.h>
3718  
3719  int set_task_ioprio(struct task_struct *task, int ioprio)
3720  {
3721 @@ -105,6 +106,8 @@ SYSCALL_DEFINE3(ioprio_set, int, which, 
3722                         else
3723                                 pgrp = find_vpid(who);
3724                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
3725 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
3726 +                                       continue;
3727                                 ret = set_task_ioprio(p, ioprio);
3728                                 if (ret)
3729                                         break;
3730 @@ -198,6 +201,8 @@ SYSCALL_DEFINE2(ioprio_get, int, which, 
3731                         else
3732                                 pgrp = find_vpid(who);
3733                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
3734 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
3735 +                                       continue;
3736                                 tmpio = get_task_ioprio(p);
3737                                 if (tmpio < 0)
3738                                         continue;
3739 diff -NurpP --minimal linux-3.6.10/fs/jfs/file.c linux-3.6.10-vs2.3.4.5/fs/jfs/file.c
3740 --- linux-3.6.10/fs/jfs/file.c  2011-10-24 18:45:27.000000000 +0200
3741 +++ linux-3.6.10-vs2.3.4.5/fs/jfs/file.c        2012-10-04 18:47:00.000000000 +0200
3742 @@ -109,7 +109,8 @@ int jfs_setattr(struct dentry *dentry, s
3743         if (is_quota_modification(inode, iattr))
3744                 dquot_initialize(inode);
3745         if ((iattr->ia_valid & ATTR_UID && iattr->ia_uid != inode->i_uid) ||
3746 -           (iattr->ia_valid & ATTR_GID && iattr->ia_gid != inode->i_gid)) {
3747 +           (iattr->ia_valid & ATTR_GID && iattr->ia_gid != inode->i_gid) ||
3748 +           (iattr->ia_valid & ATTR_TAG && iattr->ia_tag != inode->i_tag)) {
3749                 rc = dquot_transfer(inode, iattr);
3750                 if (rc)
3751                         return rc;
3752 @@ -142,6 +143,7 @@ const struct inode_operations jfs_file_i
3753  #ifdef CONFIG_JFS_POSIX_ACL
3754         .get_acl        = jfs_get_acl,
3755  #endif
3756 +       .sync_flags     = jfs_sync_flags,
3757  };
3758  
3759  const struct file_operations jfs_file_operations = {
3760 diff -NurpP --minimal linux-3.6.10/fs/jfs/ioctl.c linux-3.6.10-vs2.3.4.5/fs/jfs/ioctl.c
3761 --- linux-3.6.10/fs/jfs/ioctl.c 2012-03-19 19:47:25.000000000 +0100
3762 +++ linux-3.6.10-vs2.3.4.5/fs/jfs/ioctl.c       2012-10-04 18:47:00.000000000 +0200
3763 @@ -11,6 +11,7 @@
3764  #include <linux/mount.h>
3765  #include <linux/time.h>
3766  #include <linux/sched.h>
3767 +#include <linux/mount.h>
3768  #include <asm/current.h>
3769  #include <asm/uaccess.h>
3770  
3771 @@ -52,6 +53,16 @@ static long jfs_map_ext2(unsigned long f
3772  }
3773  
3774  
3775 +int jfs_sync_flags(struct inode *inode, int flags, int vflags)
3776 +{
3777 +       inode->i_flags = flags;
3778 +       inode->i_vflags = vflags;
3779 +       jfs_get_inode_flags(JFS_IP(inode));
3780 +       inode->i_ctime = CURRENT_TIME_SEC;
3781 +       mark_inode_dirty(inode);
3782 +       return 0;
3783 +}
3784 +
3785  long jfs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
3786  {
3787         struct inode *inode = filp->f_dentry->d_inode;
3788 @@ -85,6 +96,11 @@ long jfs_ioctl(struct file *filp, unsign
3789                 if (!S_ISDIR(inode->i_mode))
3790                         flags &= ~JFS_DIRSYNC_FL;
3791  
3792 +               if (IS_BARRIER(inode)) {
3793 +                       vxwprintk_task(1, "messing with the barrier.");
3794 +                       return -EACCES;
3795 +               }
3796 +
3797                 /* Is it quota file? Do not allow user to mess with it */
3798                 if (IS_NOQUOTA(inode)) {
3799                         err = -EPERM;
3800 @@ -102,8 +118,8 @@ long jfs_ioctl(struct file *filp, unsign
3801                  * the relevant capability.
3802                  */
3803                 if ((oldflags & JFS_IMMUTABLE_FL) ||
3804 -                       ((flags ^ oldflags) &
3805 -                       (JFS_APPEND_FL | JFS_IMMUTABLE_FL))) {
3806 +                       ((flags ^ oldflags) & (JFS_APPEND_FL |
3807 +                       JFS_IMMUTABLE_FL | JFS_IXUNLINK_FL))) {
3808                         if (!capable(CAP_LINUX_IMMUTABLE)) {
3809                                 mutex_unlock(&inode->i_mutex);
3810                                 err = -EPERM;
3811 @@ -111,7 +127,7 @@ long jfs_ioctl(struct file *filp, unsign
3812                         }
3813                 }
3814  
3815 -               flags = flags & JFS_FL_USER_MODIFIABLE;
3816 +               flags &= JFS_FL_USER_MODIFIABLE;
3817                 flags |= oldflags & ~JFS_FL_USER_MODIFIABLE;
3818                 jfs_inode->mode2 = flags;
3819  
3820 diff -NurpP --minimal linux-3.6.10/fs/jfs/jfs_dinode.h linux-3.6.10-vs2.3.4.5/fs/jfs/jfs_dinode.h
3821 --- linux-3.6.10/fs/jfs/jfs_dinode.h    2008-12-25 00:26:37.000000000 +0100
3822 +++ linux-3.6.10-vs2.3.4.5/fs/jfs/jfs_dinode.h  2012-10-04 18:47:00.000000000 +0200
3823 @@ -161,9 +161,13 @@ struct dinode {
3824  
3825  #define JFS_APPEND_FL          0x01000000 /* writes to file may only append */
3826  #define JFS_IMMUTABLE_FL       0x02000000 /* Immutable file */
3827 +#define JFS_IXUNLINK_FL                0x08000000 /* Immutable invert on unlink */
3828  
3829 -#define JFS_FL_USER_VISIBLE    0x03F80000
3830 -#define JFS_FL_USER_MODIFIABLE 0x03F80000
3831 +#define JFS_BARRIER_FL         0x04000000 /* Barrier for chroot() */
3832 +#define JFS_COW_FL             0x20000000 /* Copy on Write marker */
3833 +
3834 +#define JFS_FL_USER_VISIBLE    0x07F80000
3835 +#define JFS_FL_USER_MODIFIABLE 0x07F80000
3836  #define JFS_FL_INHERIT         0x03C80000
3837  
3838  /* These are identical to EXT[23]_IOC_GETFLAGS/SETFLAGS */
3839 diff -NurpP --minimal linux-3.6.10/fs/jfs/jfs_filsys.h linux-3.6.10-vs2.3.4.5/fs/jfs/jfs_filsys.h
3840 --- linux-3.6.10/fs/jfs/jfs_filsys.h    2008-12-25 00:26:37.000000000 +0100
3841 +++ linux-3.6.10-vs2.3.4.5/fs/jfs/jfs_filsys.h  2012-10-04 18:47:00.000000000 +0200
3842 @@ -263,6 +263,7 @@
3843  #define JFS_NAME_MAX   255
3844  #define JFS_PATH_MAX   BPSIZE
3845  
3846 +#define JFS_TAGGED             0x00800000      /* Context Tagging */
3847  
3848  /*
3849   *     file system state (superblock state)
3850 diff -NurpP --minimal linux-3.6.10/fs/jfs/jfs_imap.c linux-3.6.10-vs2.3.4.5/fs/jfs/jfs_imap.c
3851 --- linux-3.6.10/fs/jfs/jfs_imap.c      2012-01-09 16:14:54.000000000 +0100
3852 +++ linux-3.6.10-vs2.3.4.5/fs/jfs/jfs_imap.c    2012-10-04 18:47:00.000000000 +0200
3853 @@ -46,6 +46,7 @@
3854  #include <linux/pagemap.h>
3855  #include <linux/quotaops.h>
3856  #include <linux/slab.h>
3857 +#include <linux/vs_tag.h>
3858  
3859  #include "jfs_incore.h"
3860  #include "jfs_inode.h"
3861 @@ -3058,6 +3059,8 @@ static int copy_from_dinode(struct dinod
3862  {
3863         struct jfs_inode_info *jfs_ip = JFS_IP(ip);
3864         struct jfs_sb_info *sbi = JFS_SBI(ip->i_sb);
3865 +       uid_t uid;
3866 +       gid_t gid;
3867  
3868         jfs_ip->fileset = le32_to_cpu(dip->di_fileset);
3869         jfs_ip->mode2 = le32_to_cpu(dip->di_mode);
3870 @@ -3078,14 +3081,18 @@ static int copy_from_dinode(struct dinod
3871         }
3872         set_nlink(ip, le32_to_cpu(dip->di_nlink));
3873  
3874 -       jfs_ip->saved_uid = le32_to_cpu(dip->di_uid);
3875 +       uid = le32_to_cpu(dip->di_uid);
3876 +       gid = le32_to_cpu(dip->di_gid);
3877 +       ip->i_tag = INOTAG_TAG(DX_TAG(ip), uid, gid, 0);
3878 +
3879 +       jfs_ip->saved_uid = INOTAG_UID(DX_TAG(ip), uid, gid);
3880         if (sbi->uid == -1)
3881                 ip->i_uid = jfs_ip->saved_uid;
3882         else {
3883                 ip->i_uid = sbi->uid;
3884         }
3885  
3886 -       jfs_ip->saved_gid = le32_to_cpu(dip->di_gid);
3887 +       jfs_ip->saved_gid = INOTAG_GID(DX_TAG(ip), uid, gid);
3888         if (sbi->gid == -1)
3889                 ip->i_gid = jfs_ip->saved_gid;
3890         else {
3891 @@ -3150,14 +3157,12 @@ static void copy_to_dinode(struct dinode
3892         dip->di_size = cpu_to_le64(ip->i_size);
3893         dip->di_nblocks = cpu_to_le64(PBLK2LBLK(ip->i_sb, ip->i_blocks));
3894         dip->di_nlink = cpu_to_le32(ip->i_nlink);
3895 -       if (sbi->uid == -1)
3896 -               dip->di_uid = cpu_to_le32(ip->i_uid);
3897 -       else
3898 -               dip->di_uid = cpu_to_le32(jfs_ip->saved_uid);
3899 -       if (sbi->gid == -1)
3900 -               dip->di_gid = cpu_to_le32(ip->i_gid);
3901 -       else
3902 -               dip->di_gid = cpu_to_le32(jfs_ip->saved_gid);
3903 +
3904 +       dip->di_uid = cpu_to_le32(TAGINO_UID(DX_TAG(ip),
3905 +               (sbi->uid == -1) ? ip->i_uid : jfs_ip->saved_uid, ip->i_tag));
3906 +       dip->di_gid = cpu_to_le32(TAGINO_GID(DX_TAG(ip),
3907 +               (sbi->gid == -1) ? ip->i_gid : jfs_ip->saved_gid, ip->i_tag));
3908 +
3909         jfs_get_inode_flags(jfs_ip);
3910         /*
3911          * mode2 is only needed for storing the higher order bits.
3912 diff -NurpP --minimal linux-3.6.10/fs/jfs/jfs_inode.c linux-3.6.10-vs2.3.4.5/fs/jfs/jfs_inode.c
3913 --- linux-3.6.10/fs/jfs/jfs_inode.c     2012-01-09 16:14:54.000000000 +0100
3914 +++ linux-3.6.10-vs2.3.4.5/fs/jfs/jfs_inode.c   2012-10-04 18:47:00.000000000 +0200
3915 @@ -18,6 +18,7 @@
3916  
3917  #include <linux/fs.h>
3918  #include <linux/quotaops.h>
3919 +#include <linux/vs_tag.h>
3920  #include "jfs_incore.h"
3921  #include "jfs_inode.h"
3922  #include "jfs_filsys.h"
3923 @@ -30,29 +31,46 @@ void jfs_set_inode_flags(struct inode *i
3924  {
3925         unsigned int flags = JFS_IP(inode)->mode2;
3926  
3927 -       inode->i_flags &= ~(S_IMMUTABLE | S_APPEND |
3928 -               S_NOATIME | S_DIRSYNC | S_SYNC);
3929 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
3930 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
3931  
3932         if (flags & JFS_IMMUTABLE_FL)
3933                 inode->i_flags |= S_IMMUTABLE;
3934 +       if (flags & JFS_IXUNLINK_FL)
3935 +               inode->i_flags |= S_IXUNLINK;
3936 +
3937 +       if (flags & JFS_SYNC_FL)
3938 +               inode->i_flags |= S_SYNC;
3939         if (flags & JFS_APPEND_FL)
3940                 inode->i_flags |= S_APPEND;
3941         if (flags & JFS_NOATIME_FL)
3942                 inode->i_flags |= S_NOATIME;
3943         if (flags & JFS_DIRSYNC_FL)
3944                 inode->i_flags |= S_DIRSYNC;
3945 -       if (flags & JFS_SYNC_FL)
3946 -               inode->i_flags |= S_SYNC;
3947 +
3948 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
3949 +
3950 +       if (flags & JFS_BARRIER_FL)
3951 +               inode->i_vflags |= V_BARRIER;
3952 +       if (flags & JFS_COW_FL)
3953 +               inode->i_vflags |= V_COW;
3954  }
3955  
3956  void jfs_get_inode_flags(struct jfs_inode_info *jfs_ip)
3957  {
3958         unsigned int flags = jfs_ip->vfs_inode.i_flags;
3959 +       unsigned int vflags = jfs_ip->vfs_inode.i_vflags;
3960 +
3961 +       jfs_ip->mode2 &= ~(JFS_IMMUTABLE_FL | JFS_IXUNLINK_FL |
3962 +                          JFS_APPEND_FL | JFS_NOATIME_FL |
3963 +                          JFS_DIRSYNC_FL | JFS_SYNC_FL |
3964 +                          JFS_BARRIER_FL | JFS_COW_FL);
3965  
3966 -       jfs_ip->mode2 &= ~(JFS_IMMUTABLE_FL | JFS_APPEND_FL | JFS_NOATIME_FL |
3967 -                          JFS_DIRSYNC_FL | JFS_SYNC_FL);
3968         if (flags & S_IMMUTABLE)
3969                 jfs_ip->mode2 |= JFS_IMMUTABLE_FL;
3970 +       if (flags & S_IXUNLINK)
3971 +               jfs_ip->mode2 |= JFS_IXUNLINK_FL;
3972 +
3973         if (flags & S_APPEND)
3974                 jfs_ip->mode2 |= JFS_APPEND_FL;
3975         if (flags & S_NOATIME)
3976 @@ -61,6 +79,11 @@ void jfs_get_inode_flags(struct jfs_inod
3977                 jfs_ip->mode2 |= JFS_DIRSYNC_FL;
3978         if (flags & S_SYNC)
3979                 jfs_ip->mode2 |= JFS_SYNC_FL;
3980 +
3981 +       if (vflags & V_BARRIER)
3982 +               jfs_ip->mode2 |= JFS_BARRIER_FL;
3983 +       if (vflags & V_COW)
3984 +               jfs_ip->mode2 |= JFS_COW_FL;
3985  }
3986  
3987  /*
3988 diff -NurpP --minimal linux-3.6.10/fs/jfs/jfs_inode.h linux-3.6.10-vs2.3.4.5/fs/jfs/jfs_inode.h
3989 --- linux-3.6.10/fs/jfs/jfs_inode.h     2011-10-24 18:45:27.000000000 +0200
3990 +++ linux-3.6.10-vs2.3.4.5/fs/jfs/jfs_inode.h   2012-10-04 18:47:00.000000000 +0200
3991 @@ -39,6 +39,7 @@ extern struct dentry *jfs_fh_to_dentry(s
3992  extern struct dentry *jfs_fh_to_parent(struct super_block *sb, struct fid *fid,
3993         int fh_len, int fh_type);
3994  extern void jfs_set_inode_flags(struct inode *);
3995 +extern int jfs_sync_flags(struct inode *, int, int);
3996  extern int jfs_get_block(struct inode *, sector_t, struct buffer_head *, int);
3997  extern int jfs_setattr(struct dentry *, struct iattr *);
3998  
3999 diff -NurpP --minimal linux-3.6.10/fs/jfs/namei.c linux-3.6.10-vs2.3.4.5/fs/jfs/namei.c
4000 --- linux-3.6.10/fs/jfs/namei.c 2012-10-04 15:27:40.000000000 +0200
4001 +++ linux-3.6.10-vs2.3.4.5/fs/jfs/namei.c       2012-10-04 18:47:00.000000000 +0200
4002 @@ -22,6 +22,7 @@
4003  #include <linux/ctype.h>
4004  #include <linux/quotaops.h>
4005  #include <linux/exportfs.h>
4006 +#include <linux/vs_tag.h>
4007  #include "jfs_incore.h"
4008  #include "jfs_superblock.h"
4009  #include "jfs_inode.h"
4010 @@ -1461,6 +1462,7 @@ static struct dentry *jfs_lookup(struct 
4011                         jfs_err("jfs_lookup: iget failed on inum %d", (uint)inum);
4012         }
4013  
4014 +       dx_propagate_tag(nd, ip);
4015         return d_splice_alias(ip, dentry);
4016  }
4017  
4018 @@ -1525,6 +1527,7 @@ const struct inode_operations jfs_dir_in
4019  #ifdef CONFIG_JFS_POSIX_ACL
4020         .get_acl        = jfs_get_acl,
4021  #endif
4022 +       .sync_flags     = jfs_sync_flags,
4023  };
4024  
4025  const struct file_operations jfs_dir_operations = {
4026 diff -NurpP --minimal linux-3.6.10/fs/jfs/super.c linux-3.6.10-vs2.3.4.5/fs/jfs/super.c
4027 --- linux-3.6.10/fs/jfs/super.c 2012-10-04 15:27:40.000000000 +0200
4028 +++ linux-3.6.10-vs2.3.4.5/fs/jfs/super.c       2012-10-04 18:47:00.000000000 +0200
4029 @@ -197,7 +197,8 @@ static void jfs_put_super(struct super_b
4030  enum {
4031         Opt_integrity, Opt_nointegrity, Opt_iocharset, Opt_resize,
4032         Opt_resize_nosize, Opt_errors, Opt_ignore, Opt_err, Opt_quota,
4033 -       Opt_usrquota, Opt_grpquota, Opt_uid, Opt_gid, Opt_umask
4034 +       Opt_usrquota, Opt_grpquota, Opt_uid, Opt_gid, Opt_umask,
4035 +       Opt_tag, Opt_notag, Opt_tagid
4036  };
4037  
4038  static const match_table_t tokens = {
4039 @@ -207,6 +208,10 @@ static const match_table_t tokens = {
4040         {Opt_resize, "resize=%u"},
4041         {Opt_resize_nosize, "resize"},
4042         {Opt_errors, "errors=%s"},
4043 +       {Opt_tag, "tag"},
4044 +       {Opt_notag, "notag"},
4045 +       {Opt_tagid, "tagid=%u"},
4046 +       {Opt_tag, "tagxid"},
4047         {Opt_ignore, "noquota"},
4048         {Opt_ignore, "quota"},
4049         {Opt_usrquota, "usrquota"},
4050 @@ -341,6 +346,20 @@ static int parse_options(char *options, 
4051                         }
4052                         break;
4053                 }
4054 +#ifndef CONFIG_TAGGING_NONE
4055 +               case Opt_tag:
4056 +                       *flag |= JFS_TAGGED;
4057 +                       break;
4058 +               case Opt_notag:
4059 +                       *flag &= JFS_TAGGED;
4060 +                       break;
4061 +#endif
4062 +#ifdef CONFIG_PROPAGATE
4063 +               case Opt_tagid:
4064 +                       /* use args[0] */
4065 +                       *flag |= JFS_TAGGED;
4066 +                       break;
4067 +#endif
4068                 default:
4069                         printk("jfs: Unrecognized mount option \"%s\" "
4070                                         " or missing value\n", p);
4071 @@ -372,6 +391,12 @@ static int jfs_remount(struct super_bloc
4072                 return -EINVAL;
4073         }
4074  
4075 +       if ((flag & JFS_TAGGED) && !(sb->s_flags & MS_TAGGED)) {
4076 +               printk(KERN_ERR "JFS: %s: tagging not permitted on remount.\n",
4077 +                       sb->s_id);
4078 +               return -EINVAL;
4079 +       }
4080 +
4081         if (newLVSize) {
4082                 if (sb->s_flags & MS_RDONLY) {
4083                         printk(KERN_ERR
4084 @@ -455,6 +480,9 @@ static int jfs_fill_super(struct super_b
4085  #ifdef CONFIG_JFS_POSIX_ACL
4086         sb->s_flags |= MS_POSIXACL;
4087  #endif
4088 +       /* map mount option tagxid */
4089 +       if (sbi->flag & JFS_TAGGED)
4090 +               sb->s_flags |= MS_TAGGED;
4091  
4092         if (newLVSize) {
4093                 printk(KERN_ERR "resize option for remount only\n");
4094 diff -NurpP --minimal linux-3.6.10/fs/libfs.c linux-3.6.10-vs2.3.4.5/fs/libfs.c
4095 --- linux-3.6.10/fs/libfs.c     2012-10-04 15:27:40.000000000 +0200
4096 +++ linux-3.6.10-vs2.3.4.5/fs/libfs.c   2012-10-04 18:47:00.000000000 +0200
4097 @@ -135,7 +135,8 @@ static inline unsigned char dt_type(stru
4098   * both impossible due to the lock on directory.
4099   */
4100  
4101 -int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
4102 +static inline int do_dcache_readdir_filter(struct file *filp,
4103 +       void *dirent, filldir_t filldir, int (*filter)(struct dentry *dentry))
4104  {
4105         struct dentry *dentry = filp->f_path.dentry;
4106         struct dentry *cursor = filp->private_data;
4107 @@ -166,6 +167,8 @@ int dcache_readdir(struct file * filp, v
4108                         for (p=q->next; p != &dentry->d_subdirs; p=p->next) {
4109                                 struct dentry *next;
4110                                 next = list_entry(p, struct dentry, d_u.d_child);
4111 +                               if (filter && !filter(next))
4112 +                                       continue;
4113                                 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
4114                                 if (!simple_positive(next)) {
4115                                         spin_unlock(&next->d_lock);
4116 @@ -192,6 +195,17 @@ int dcache_readdir(struct file * filp, v
4117         return 0;
4118  }
4119  
4120 +int dcache_readdir(struct file *filp, void *dirent, filldir_t filldir)
4121 +{
4122 +       return do_dcache_readdir_filter(filp, dirent, filldir, NULL);
4123 +}
4124 +
4125 +int dcache_readdir_filter(struct file *filp, void *dirent, filldir_t filldir,
4126 +       int (*filter)(struct dentry *))
4127 +{
4128 +       return do_dcache_readdir_filter(filp, dirent, filldir, filter);
4129 +}
4130 +
4131  ssize_t generic_read_dir(struct file *filp, char __user *buf, size_t siz, loff_t *ppos)
4132  {
4133         return -EISDIR;
4134 @@ -983,6 +997,7 @@ EXPORT_SYMBOL(dcache_dir_close);
4135  EXPORT_SYMBOL(dcache_dir_lseek);
4136  EXPORT_SYMBOL(dcache_dir_open);
4137  EXPORT_SYMBOL(dcache_readdir);
4138 +EXPORT_SYMBOL(dcache_readdir_filter);
4139  EXPORT_SYMBOL(generic_read_dir);
4140  EXPORT_SYMBOL(mount_pseudo);
4141  EXPORT_SYMBOL(simple_write_begin);
4142 diff -NurpP --minimal linux-3.6.10/fs/locks.c linux-3.6.10-vs2.3.4.5/fs/locks.c
4143 --- linux-3.6.10/fs/locks.c     2012-10-04 15:27:40.000000000 +0200
4144 +++ linux-3.6.10-vs2.3.4.5/fs/locks.c   2012-10-04 18:47:00.000000000 +0200
4145 @@ -126,6 +126,8 @@
4146  #include <linux/time.h>
4147  #include <linux/rcupdate.h>
4148  #include <linux/pid_namespace.h>
4149 +#include <linux/vs_base.h>
4150 +#include <linux/vs_limit.h>
4151  
4152  #include <asm/uaccess.h>
4153  
4154 @@ -184,11 +186,17 @@ static void locks_init_lock_heads(struct
4155  /* Allocate an empty lock structure. */
4156  struct file_lock *locks_alloc_lock(void)
4157  {
4158 -       struct file_lock *fl = kmem_cache_zalloc(filelock_cache, GFP_KERNEL);
4159 +       struct file_lock *fl;
4160  
4161 -       if (fl)
4162 -               locks_init_lock_heads(fl);
4163 +       if (!vx_locks_avail(1))
4164 +               return NULL;
4165  
4166 +       fl = kmem_cache_zalloc(filelock_cache, GFP_KERNEL);
4167 +
4168 +       if (fl) {
4169 +               locks_init_lock_heads(fl);
4170 +               fl->fl_xid = -1;
4171 +       }
4172         return fl;
4173  }
4174  EXPORT_SYMBOL_GPL(locks_alloc_lock);
4175 @@ -212,6 +220,7 @@ void locks_free_lock(struct file_lock *f
4176         BUG_ON(!list_empty(&fl->fl_block));
4177         BUG_ON(!list_empty(&fl->fl_link));
4178  
4179 +       vx_locks_dec(fl);
4180         locks_release_private(fl);
4181         kmem_cache_free(filelock_cache, fl);
4182  }
4183 @@ -221,6 +230,7 @@ void locks_init_lock(struct file_lock *f
4184  {
4185         memset(fl, 0, sizeof(struct file_lock));
4186         locks_init_lock_heads(fl);
4187 +       fl->fl_xid = -1;
4188  }
4189  
4190  EXPORT_SYMBOL(locks_init_lock);
4191 @@ -261,6 +271,7 @@ void locks_copy_lock(struct file_lock *n
4192         new->fl_file = fl->fl_file;
4193         new->fl_ops = fl->fl_ops;
4194         new->fl_lmops = fl->fl_lmops;
4195 +       new->fl_xid = fl->fl_xid;
4196  
4197         locks_copy_private(new, fl);
4198  }
4199 @@ -299,6 +310,11 @@ static int flock_make_lock(struct file *
4200         fl->fl_flags = FL_FLOCK;
4201         fl->fl_type = type;
4202         fl->fl_end = OFFSET_MAX;
4203 +
4204 +       vxd_assert(filp->f_xid == vx_current_xid(),
4205 +               "f_xid(%d) == current(%d)", filp->f_xid, vx_current_xid());
4206 +       fl->fl_xid = filp->f_xid;
4207 +       vx_locks_inc(fl);
4208         
4209         *lock = fl;
4210         return 0;
4211 @@ -438,6 +454,7 @@ static int lease_init(struct file *filp,
4212  
4213         fl->fl_owner = current->files;
4214         fl->fl_pid = current->tgid;
4215 +       fl->fl_xid = vx_current_xid();
4216  
4217         fl->fl_file = filp;
4218         fl->fl_flags = FL_LEASE;
4219 @@ -457,6 +474,11 @@ static struct file_lock *lease_alloc(str
4220         if (fl == NULL)
4221                 return ERR_PTR(error);
4222  
4223 +       fl->fl_xid = vx_current_xid();
4224 +       if (filp)
4225 +               vxd_assert(filp->f_xid == fl->fl_xid,
4226 +                       "f_xid(%d) == fl_xid(%d)", filp->f_xid, fl->fl_xid);
4227 +       vx_locks_inc(fl);
4228         error = lease_init(filp, type, fl);
4229         if (error) {
4230                 locks_free_lock(fl);
4231 @@ -753,6 +775,7 @@ static int flock_lock_file(struct file *
4232                 lock_flocks();
4233         }
4234  
4235 +       new_fl->fl_xid = -1;
4236  find_conflict:
4237         for_each_lock(inode, before) {
4238                 struct file_lock *fl = *before;
4239 @@ -773,6 +796,7 @@ find_conflict:
4240                 goto out;
4241         locks_copy_lock(new_fl, request);
4242         locks_insert_lock(before, new_fl);
4243 +       vx_locks_inc(new_fl);
4244         new_fl = NULL;
4245         error = 0;
4246  
4247 @@ -783,7 +807,8 @@ out:
4248         return error;
4249  }
4250  
4251 -static int __posix_lock_file(struct inode *inode, struct file_lock *request, struct file_lock *conflock)
4252 +static int __posix_lock_file(struct inode *inode, struct file_lock *request,
4253 +       struct file_lock *conflock, xid_t xid)
4254  {
4255         struct file_lock *fl;
4256         struct file_lock *new_fl = NULL;
4257 @@ -793,6 +818,8 @@ static int __posix_lock_file(struct inod
4258         struct file_lock **before;
4259         int error, added = 0;
4260  
4261 +       vxd_assert(xid == vx_current_xid(),
4262 +               "xid(%d) == current(%d)", xid, vx_current_xid());
4263         /*
4264          * We may need two file_lock structures for this operation,
4265          * so we get them in advance to avoid races.
4266 @@ -803,7 +830,11 @@ static int __posix_lock_file(struct inod
4267             (request->fl_type != F_UNLCK ||
4268              request->fl_start != 0 || request->fl_end != OFFSET_MAX)) {
4269                 new_fl = locks_alloc_lock();
4270 +               new_fl->fl_xid = xid;
4271 +               vx_locks_inc(new_fl);
4272                 new_fl2 = locks_alloc_lock();
4273 +               new_fl2->fl_xid = xid;
4274 +               vx_locks_inc(new_fl2);
4275         }
4276  
4277         lock_flocks();
4278 @@ -1002,7 +1033,8 @@ static int __posix_lock_file(struct inod
4279  int posix_lock_file(struct file *filp, struct file_lock *fl,
4280                         struct file_lock *conflock)
4281  {
4282 -       return __posix_lock_file(filp->f_path.dentry->d_inode, fl, conflock);
4283 +       return __posix_lock_file(filp->f_path.dentry->d_inode,
4284 +               fl, conflock, filp->f_xid);
4285  }
4286  EXPORT_SYMBOL(posix_lock_file);
4287  
4288 @@ -1092,7 +1124,7 @@ int locks_mandatory_area(int read_write,
4289         fl.fl_end = offset + count - 1;
4290  
4291         for (;;) {
4292 -               error = __posix_lock_file(inode, &fl, NULL);
4293 +               error = __posix_lock_file(inode, &fl, NULL, filp->f_xid);
4294                 if (error != FILE_LOCK_DEFERRED)
4295                         break;
4296                 error = wait_event_interruptible(fl.fl_wait, !fl.fl_next);
4297 @@ -1397,6 +1429,7 @@ int generic_add_lease(struct file *filp,
4298                 goto out;
4299  
4300         locks_insert_lock(before, lease);
4301 +       vx_locks_inc(lease);
4302         return 0;
4303  
4304  out:
4305 @@ -1838,6 +1871,11 @@ int fcntl_setlk(unsigned int fd, struct 
4306         if (file_lock == NULL)
4307                 return -ENOLCK;
4308  
4309 +       vxd_assert(filp->f_xid == vx_current_xid(),
4310 +               "f_xid(%d) == current(%d)", filp->f_xid, vx_current_xid());
4311 +       file_lock->fl_xid = filp->f_xid;
4312 +       vx_locks_inc(file_lock);
4313 +
4314         /*
4315          * This might block, so we do it before checking the inode.
4316          */
4317 @@ -1956,6 +1994,11 @@ int fcntl_setlk64(unsigned int fd, struc
4318         if (file_lock == NULL)
4319                 return -ENOLCK;
4320  
4321 +       vxd_assert(filp->f_xid == vx_current_xid(),
4322 +               "f_xid(%d) == current(%d)", filp->f_xid, vx_current_xid());
4323 +       file_lock->fl_xid = filp->f_xid;
4324 +       vx_locks_inc(file_lock);
4325 +
4326         /*
4327          * This might block, so we do it before checking the inode.
4328          */
4329 @@ -2221,8 +2264,11 @@ static int locks_show(struct seq_file *f
4330  
4331         lock_get_status(f, fl, *((loff_t *)f->private), "");
4332  
4333 -       list_for_each_entry(bfl, &fl->fl_block, fl_block)
4334 +       list_for_each_entry(bfl, &fl->fl_block, fl_block) {
4335 +               if (!vx_check(fl->fl_xid, VS_WATCH_P | VS_IDENT))
4336 +                       continue;
4337                 lock_get_status(f, bfl, *((loff_t *)f->private), " ->");
4338 +       }
4339  
4340         return 0;
4341  }
4342 diff -NurpP --minimal linux-3.6.10/fs/mount.h linux-3.6.10-vs2.3.4.5/fs/mount.h
4343 --- linux-3.6.10/fs/mount.h     2012-10-04 15:27:40.000000000 +0200
4344 +++ linux-3.6.10-vs2.3.4.5/fs/mount.h   2012-10-04 18:47:00.000000000 +0200
4345 @@ -46,6 +46,7 @@ struct mount {
4346         int mnt_expiry_mark;            /* true if marked for expiry */
4347         int mnt_pinned;
4348         int mnt_ghosts;
4349 +       tag_t mnt_tag;                  /* tagging used for vfsmount */
4350  };
4351  
4352  #define MNT_NS_INTERNAL ERR_PTR(-EINVAL) /* distinct from any mnt_namespace */
4353 diff -NurpP --minimal linux-3.6.10/fs/namei.c linux-3.6.10-vs2.3.4.5/fs/namei.c
4354 --- linux-3.6.10/fs/namei.c     2012-12-11 12:36:58.000000000 +0100
4355 +++ linux-3.6.10-vs2.3.4.5/fs/namei.c   2012-12-08 01:08:53.000000000 +0100
4356 @@ -34,6 +34,14 @@
4357  #include <linux/device_cgroup.h>
4358  #include <linux/fs_struct.h>
4359  #include <linux/posix_acl.h>
4360 +#include <linux/proc_fs.h>
4361 +#include <linux/vserver/inode.h>
4362 +#include <linux/vs_base.h>
4363 +#include <linux/vs_tag.h>
4364 +#include <linux/vs_cowbl.h>
4365 +#include <linux/vs_device.h>
4366 +#include <linux/vs_context.h>
4367 +#include <linux/pid_namespace.h>
4368  #include <asm/uaccess.h>
4369  
4370  #include "internal.h"
4371 @@ -212,6 +220,89 @@ static int check_acl(struct inode *inode
4372         return -EAGAIN;
4373  }
4374  
4375 +static inline int dx_barrier(const struct inode *inode)
4376 +{
4377 +       if (IS_BARRIER(inode) && !vx_check(0, VS_ADMIN | VS_WATCH)) {
4378 +               vxwprintk_task(1, "did hit the barrier.");
4379 +               return 1;
4380 +       }
4381 +       return 0;
4382 +}
4383 +
4384 +static int __dx_permission(const struct inode *inode, int mask)
4385 +{
4386 +       if (dx_barrier(inode))
4387 +               return -EACCES;
4388 +
4389 +       if (inode->i_sb->s_magic == DEVPTS_SUPER_MAGIC) {
4390 +               /* devpts is xid tagged */
4391 +               if (S_ISDIR(inode->i_mode) ||
4392 +                   vx_check((xid_t)inode->i_tag, VS_IDENT | VS_WATCH_P))
4393 +                       return 0;
4394 +
4395 +               /* just pretend we didn't find anything */
4396 +               return -ENOENT;
4397 +       }
4398 +       else if (inode->i_sb->s_magic == PROC_SUPER_MAGIC) {
4399 +               struct proc_dir_entry *de = PDE(inode);
4400 +
4401 +               if (de && !vx_hide_check(0, de->vx_flags))
4402 +                       goto out;
4403 +
4404 +               if ((mask & (MAY_WRITE | MAY_APPEND))) {
4405 +                       struct pid *pid;
4406 +                       struct task_struct *tsk;
4407 +
4408 +                       if (vx_check(0, VS_ADMIN | VS_WATCH_P) ||
4409 +                           vx_flags(VXF_STATE_SETUP, 0))
4410 +                               return 0;
4411 +
4412 +                       pid = PROC_I(inode)->pid;
4413 +                       if (!pid)
4414 +                               goto out;
4415 +
4416 +                       rcu_read_lock();
4417 +                       tsk = pid_task(pid, PIDTYPE_PID);
4418 +                       vxdprintk(VXD_CBIT(tag, 0), "accessing %p[#%u]",
4419 +                                 tsk, (tsk ? vx_task_xid(tsk) : 0));
4420 +                       if (tsk &&
4421 +                               vx_check(vx_task_xid(tsk), VS_IDENT | VS_WATCH_P)) {
4422 +                               rcu_read_unlock();
4423 +                               return 0;
4424 +                       }
4425 +                       rcu_read_unlock();
4426 +               }
4427 +               else {
4428 +                       /* FIXME: Should we block some entries here? */
4429 +                       return 0;
4430 +               }
4431 +       }
4432 +       else {
4433 +               if (dx_notagcheck(inode->i_sb) ||
4434 +                   dx_check(inode->i_tag, DX_HOSTID | DX_ADMIN | DX_WATCH |
4435 +                            DX_IDENT))
4436 +                       return 0;
4437 +       }
4438 +
4439 +out:
4440 +       return -EACCES;
4441 +}
4442 +
4443 +int dx_permission(const struct inode *inode, int mask)
4444 +{
4445 +       int ret = __dx_permission(inode, mask);
4446 +       if (unlikely(ret)) {
4447 +#ifndef        CONFIG_VSERVER_WARN_DEVPTS
4448 +               if (inode->i_sb->s_magic != DEVPTS_SUPER_MAGIC)
4449 +#endif
4450 +                   vxwprintk_task(1,
4451 +                       "denied [0x%x] access to inode %s:%p[#%d,%lu]",
4452 +                       mask, inode->i_sb->s_id, inode, inode->i_tag,
4453 +                       inode->i_ino);
4454 +       }
4455 +       return ret;
4456 +}
4457 +
4458  /*
4459   * This does the basic permission checking
4460   */
4461 @@ -334,10 +425,14 @@ int __inode_permission(struct inode *ino
4462                 /*
4463                  * Nobody gets write access to an immutable file.
4464                  */
4465 -               if (IS_IMMUTABLE(inode))
4466 +               if (IS_IMMUTABLE(inode) && !IS_COW(inode))
4467                         return -EACCES;
4468         }
4469  
4470 +       retval = dx_permission(inode, mask);
4471 +       if (retval)
4472 +               return retval;
4473 +
4474         retval = do_inode_permission(inode, mask);
4475         if (retval)
4476                 return retval;
4477 @@ -1189,7 +1284,8 @@ static void follow_dotdot(struct nameida
4478  
4479                 if (nd->path.dentry == nd->root.dentry &&
4480                     nd->path.mnt == nd->root.mnt) {
4481 -                       break;
4482 +                       /* for sane '/' avoid follow_mount() */
4483 +                       return;
4484                 }
4485                 if (nd->path.dentry != nd->path.mnt->mnt_root) {
4486                         /* rare case of legitimate dget_parent()... */
4487 @@ -1338,6 +1434,9 @@ static int lookup_fast(struct nameidata 
4488                                 goto unlazy;
4489                         }
4490                 }
4491 +
4492 +               /* FIXME: check dx permission */
4493 +
4494                 path->mnt = mnt;
4495                 path->dentry = dentry;
4496                 if (unlikely(!__follow_mount_rcu(nd, path, inode)))
4497 @@ -1373,6 +1472,8 @@ unlazy:
4498                 }
4499         }
4500  
4501 +       /* FIXME: check dx permission */
4502 +
4503         path->mnt = mnt;
4504         path->dentry = dentry;
4505         err = follow_managed(path, nd->flags);
4506 @@ -2192,7 +2293,7 @@ static int may_delete(struct inode *dir,
4507         if (IS_APPEND(dir))
4508                 return -EPERM;
4509         if (check_sticky(dir, victim->d_inode)||IS_APPEND(victim->d_inode)||
4510 -           IS_IMMUTABLE(victim->d_inode) || IS_SWAPFILE(victim->d_inode))
4511 +               IS_IXORUNLINK(victim->d_inode) || IS_SWAPFILE(victim->d_inode))
4512                 return -EPERM;
4513         if (isdir) {
4514                 if (!S_ISDIR(victim->d_inode->i_mode))
4515 @@ -2271,19 +2372,25 @@ int vfs_create(struct inode *dir, struct
4516                 bool want_excl)
4517  {
4518         int error = may_create(dir, dentry);
4519 -       if (error)
4520 -               return error;
4521 +       if (error) {
4522 +               vxdprintk(VXD_CBIT(misc, 3), "may_create failed with %d", error);
4523 +               return error;
4524 +       }
4525  
4526         if (!dir->i_op->create)
4527                 return -EACCES; /* shouldn't it be ENOSYS? */
4528         mode &= S_IALLUGO;
4529         mode |= S_IFREG;
4530         error = security_inode_create(dir, dentry, mode);
4531 -       if (error)
4532 -               return error;
4533 +       if (error) {
4534 +               vxdprintk(VXD_CBIT(misc, 3), "security_inode_create failed with %d", error);
4535 +               return error;
4536 +       }
4537         error = dir->i_op->create(dir, dentry, mode, want_excl);
4538         if (!error)
4539                 fsnotify_create(dir, dentry);
4540 +       else
4541 +               vxdprintk(VXD_CBIT(misc, 3), "i_op->create failed with %d", error);
4542         return error;
4543  }
4544  
4545 @@ -2318,6 +2425,15 @@ static int may_open(struct path *path, i
4546                 break;
4547         }
4548  
4549 +#ifdef CONFIG_VSERVER_COWBL
4550 +       if (IS_COW(inode) &&
4551 +               ((flag & O_ACCMODE) != O_RDONLY)) {
4552 +               if (IS_COW_LINK(inode))
4553 +                       return -EMLINK;
4554 +               inode->i_flags &= ~(S_IXUNLINK|S_IMMUTABLE);
4555 +               mark_inode_dirty(inode);
4556 +       }
4557 +#endif
4558         error = inode_permission(inode, acc_mode);
4559         if (error)
4560                 return error;
4561 @@ -2820,6 +2936,16 @@ finish_open:
4562         }
4563  finish_open_created:
4564         error = may_open(&nd->path, acc_mode, open_flag);
4565 +#ifdef CONFIG_VSERVER_COWBL
4566 +       if (error == -EMLINK) {
4567 +               struct dentry *dentry;
4568 +               dentry = cow_break_link(pathname);
4569 +               if (IS_ERR(dentry))
4570 +                       error = PTR_ERR(dentry);
4571 +               else
4572 +                       dput(dentry);
4573 +       }
4574 +#endif
4575         if (error)
4576                 goto out;
4577         file->f_path.mnt = nd->path.mnt;
4578 @@ -2884,6 +3010,7 @@ static struct file *path_openat(int dfd,
4579         int opened = 0;
4580         int error;
4581  
4582 +restart:
4583         file = get_empty_filp();
4584         if (!file)
4585                 return ERR_PTR(-ENFILE);
4586 @@ -2920,6 +3047,16 @@ static struct file *path_openat(int dfd,
4587                 error = do_last(nd, &path, file, op, &opened, pathname);
4588                 put_link(nd, &link, cookie);
4589         }
4590 +
4591 +#ifdef CONFIG_VSERVER_COWBL
4592 +       if (error == -EMLINK) {
4593 +               if (nd->root.mnt && !(nd->flags & LOOKUP_ROOT))
4594 +                       path_put(&nd->root);
4595 +               if (base)
4596 +                       fput(base);
4597 +               goto restart;
4598 +       }
4599 +#endif
4600  out:
4601         if (nd->root.mnt && !(nd->flags & LOOKUP_ROOT))
4602                 path_put(&nd->root);
4603 @@ -3023,6 +3160,11 @@ struct dentry *kern_path_create(int dfd,
4604                 goto fail;
4605         }
4606         *path = nd.path;
4607 +       vxdprintk(VXD_CBIT(misc, 3), "kern_path_create path.dentry = %p (%.*s), dentry = %p (%.*s), d_inode = %p",
4608 +               path->dentry, path->dentry->d_name.len,
4609 +               path->dentry->d_name.name, dentry,
4610 +               dentry->d_name.len, dentry->d_name.name,
4611 +               path->dentry->d_inode);
4612         return dentry;
4613  fail:
4614         dput(dentry);
4615 @@ -3489,7 +3631,7 @@ int vfs_link(struct dentry *old_dentry, 
4616         /*
4617          * A link to an append-only or immutable file cannot be created.
4618          */
4619 -       if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
4620 +       if (IS_APPEND(inode) || IS_IXORUNLINK(inode))
4621                 return -EPERM;
4622         if (!dir->i_op->link)
4623                 return -EPERM;
4624 @@ -3874,6 +4016,275 @@ int vfs_follow_link(struct nameidata *nd
4625         return __vfs_follow_link(nd, link);
4626  }
4627  
4628 +
4629 +#ifdef CONFIG_VSERVER_COWBL
4630 +
4631 +static inline
4632 +long do_cow_splice(struct file *in, struct file *out, size_t len)
4633 +{
4634 +       loff_t ppos = 0;
4635 +
4636 +       return do_splice_direct(in, &ppos, out, len, 0);
4637 +}
4638 +
4639 +struct dentry *cow_break_link(const char *pathname)
4640 +{
4641 +       int ret, mode, pathlen, redo = 0;
4642 +       struct nameidata old_nd, dir_nd;
4643 +       struct path dir_path, *old_path, *new_path;
4644 +       struct dentry *dir, *old_dentry, *new_dentry = NULL;
4645 +       struct file *old_file;
4646 +       struct file *new_file;
4647 +       char *to, *path, pad='\251';
4648 +       loff_t size;
4649 +
4650 +       vxdprintk(VXD_CBIT(misc, 1),
4651 +               "cow_break_link(" VS_Q("%s") ")", pathname);
4652 +
4653 +       path = kmalloc(PATH_MAX, GFP_KERNEL);
4654 +       ret = -ENOMEM;
4655 +       if (!path)
4656 +               goto out;
4657 +
4658 +       /* old_nd.path will have refs to dentry and mnt */
4659 +       ret = do_path_lookup(AT_FDCWD, pathname, LOOKUP_FOLLOW, &old_nd);
4660 +       vxdprintk(VXD_CBIT(misc, 2),
4661 +               "do_path_lookup(old): %d", ret);
4662 +       if (ret < 0)
4663 +               goto out_free_path;
4664 +
4665 +       /* dentry/mnt refs handed over to old_path */
4666 +       old_path = &old_nd.path;
4667 +       /* no explicit reference for old_dentry here */
4668 +       old_dentry = old_path->dentry;
4669 +
4670 +       mode = old_dentry->d_inode->i_mode;
4671 +       to = d_path(old_path, path, PATH_MAX-2);
4672 +       pathlen = strlen(to);
4673 +       vxdprintk(VXD_CBIT(misc, 2),
4674 +               "old path " VS_Q("%s") " [%p:" VS_Q("%.*s") ":%d]", to,
4675 +               old_dentry,
4676 +               old_dentry->d_name.len, old_dentry->d_name.name,
4677 +               old_dentry->d_name.len);
4678 +
4679 +       to[pathlen + 1] = 0;
4680 +retry:
4681 +       new_dentry = NULL;
4682 +       to[pathlen] = pad--;
4683 +       ret = -ELOOP;
4684 +       if (pad <= '\240')
4685 +               goto out_rel_old;
4686 +
4687 +       vxdprintk(VXD_CBIT(misc, 1), "temp copy " VS_Q("%s"), to);
4688 +
4689 +       /* dir_nd.path will have refs to dentry and mnt */
4690 +       ret = do_path_lookup(AT_FDCWD, to,
4691 +               LOOKUP_PARENT | LOOKUP_OPEN | LOOKUP_CREATE, &dir_nd);
4692 +       vxdprintk(VXD_CBIT(misc, 2), "do_path_lookup(new): %d", ret);
4693 +       if (ret < 0)
4694 +               goto retry;
4695 +
4696 +       /* this puppy downs the dir inode mutex if successful.
4697 +          dir_path will hold refs to dentry and mnt and
4698 +          we'll have get write access to the mnt */
4699 +       new_dentry = kern_path_create(AT_FDCWD, to, &dir_path, 0);
4700 +       if (!new_dentry || IS_ERR(new_dentry)) {
4701 +               path_put(&dir_nd.path);
4702 +               vxdprintk(VXD_CBIT(misc, 2),
4703 +                       "kern_path_create(new) failed with %ld",
4704 +                       PTR_ERR(new_dentry));
4705 +               goto retry;
4706 +       }
4707 +       vxdprintk(VXD_CBIT(misc, 2),
4708 +               "kern_path_create(new): %p [" VS_Q("%.*s") ":%d]",
4709 +               new_dentry,
4710 +               new_dentry->d_name.len, new_dentry->d_name.name,
4711 +               new_dentry->d_name.len);
4712 +
4713 +       /* take a reference on new_dentry */
4714 +       dget(new_dentry);
4715 +
4716 +       /* dentry/mnt refs handed over to new_path */
4717 +       new_path = &dir_path;
4718 +
4719 +       /* dentry for old/new dir */
4720 +       dir = dir_nd.path.dentry;
4721 +
4722 +       /* give up reference on dir */
4723 +       dput(new_path->dentry);
4724 +
4725 +       /* new_dentry already has a reference */
4726 +       new_path->dentry = new_dentry;
4727 +
4728 +       ret = vfs_create(dir->d_inode, new_dentry, mode, 1);
4729 +       vxdprintk(VXD_CBIT(misc, 2),
4730 +               "vfs_create(new): %d", ret);
4731 +       if (ret == -EEXIST) {
4732 +               mutex_unlock(&dir->d_inode->i_mutex);
4733 +               path_put(&dir_nd.path);
4734 +               mnt_drop_write(new_path->mnt);
4735 +               path_put(new_path);
4736 +               new_dentry = NULL;
4737 +               goto retry;
4738 +       }
4739 +       else if (ret < 0)
4740 +               goto out_unlock_new;
4741 +
4742 +       /* drop out early, ret passes ENOENT */
4743 +       ret = -ENOENT;
4744 +       if ((redo = d_unhashed(old_dentry)))
4745 +               goto out_unlock_new;
4746 +
4747 +       /* doesn't change refs for old_path */
4748 +       old_file = dentry_open(old_path, O_RDONLY, current_cred());
4749 +       vxdprintk(VXD_CBIT(misc, 2),
4750 +               "dentry_open(old): %p", old_file);
4751 +       if (IS_ERR(old_file)) {
4752 +               ret = PTR_ERR(old_file);
4753 +               goto out_unlock_new;
4754 +       }
4755 +
4756 +       /* doesn't change refs for new_path */
4757 +       new_file = dentry_open(new_path, O_WRONLY, current_cred());
4758 +       vxdprintk(VXD_CBIT(misc, 2),
4759 +               "dentry_open(new): %p", new_file);
4760 +       if (IS_ERR(new_file)) {
4761 +               ret = PTR_ERR(new_file);
4762 +               goto out_fput_old;
4763 +       }
4764 +
4765 +       size = i_size_read(old_file->f_dentry->d_inode);
4766 +       ret = do_cow_splice(old_file, new_file, size);
4767 +       vxdprintk(VXD_CBIT(misc, 2), "do_splice_direct: %d", ret);
4768 +       if (ret < 0) {
4769 +               goto out_fput_both;
4770 +       } else if (ret < size) {
4771 +               ret = -ENOSPC;
4772 +               goto out_fput_both;
4773 +       } else {
4774 +               struct inode *old_inode = old_dentry->d_inode;
4775 +               struct inode *new_inode = new_dentry->d_inode;
4776 +               struct iattr attr = {
4777 +                       .ia_uid = old_inode->i_uid,
4778 +                       .ia_gid = old_inode->i_gid,
4779 +                       .ia_valid = ATTR_UID | ATTR_GID
4780 +                       };
4781 +
4782 +               setattr_copy(new_inode, &attr);
4783 +               mark_inode_dirty(new_inode);
4784 +       }
4785 +
4786 +       /* lock rename mutex */
4787 +       mutex_lock(&old_dentry->d_inode->i_sb->s_vfs_rename_mutex);
4788 +
4789 +       /* drop out late */
4790 +       ret = -ENOENT;
4791 +       if ((redo = d_unhashed(old_dentry)))
4792 +               goto out_unlock;
4793 +
4794 +       vxdprintk(VXD_CBIT(misc, 2),
4795 +               "vfs_rename: [" VS_Q("%*s") ":%d] -> [" VS_Q("%*s") ":%d]",
4796 +               new_dentry->d_name.len, new_dentry->d_name.name,
4797 +               new_dentry->d_name.len,
4798 +               old_dentry->d_name.len, old_dentry->d_name.name,
4799 +               old_dentry->d_name.len);
4800 +       ret = vfs_rename(dir_nd.path.dentry->d_inode, new_dentry,
4801 +               old_dentry->d_parent->d_inode, old_dentry);
4802 +       vxdprintk(VXD_CBIT(misc, 2), "vfs_rename: %d", ret);
4803 +
4804 +out_unlock:
4805 +       mutex_unlock(&old_dentry->d_inode->i_sb->s_vfs_rename_mutex);
4806 +
4807 +out_fput_both:
4808 +       vxdprintk(VXD_CBIT(misc, 3),
4809 +               "fput(new_file=%p[#%ld])", new_file,
4810 +               atomic_long_read(&new_file->f_count));
4811 +       fput(new_file);
4812 +
4813 +out_fput_old:
4814 +       vxdprintk(VXD_CBIT(misc, 3),
4815 +               "fput(old_file=%p[#%ld])", old_file,
4816 +               atomic_long_read(&old_file->f_count));
4817 +       fput(old_file);
4818 +
4819 +out_unlock_new:
4820 +       /* drop references from dir_nd.path */
4821 +       path_put(&dir_nd.path);
4822 +
4823 +       /* drop write access to mnt */
4824 +       mnt_drop_write(new_path->mnt);
4825 +
4826 +       /* unlock the inode mutex from kern_path_create() */
4827 +       mutex_unlock(&dir->d_inode->i_mutex);
4828 +       if (!ret)
4829 +               goto out_redo;
4830 +
4831 +       /* error path cleanup */
4832 +       vfs_unlink(dir->d_inode, new_dentry);
4833 +
4834 +out_redo:
4835 +       if (!redo)
4836 +               goto out_rel_both;
4837 +
4838 +       /* lookup dentry once again
4839 +          old_nd.path will be freed as old_path in out_rel_old */
4840 +       ret = do_path_lookup(AT_FDCWD, pathname, LOOKUP_FOLLOW, &old_nd);
4841 +       if (ret)
4842 +               goto out_rel_both;
4843 +
4844 +       /* drop reference on new_dentry */
4845 +       dput(new_dentry);
4846 +       new_dentry = old_path->dentry;
4847 +       dget(new_dentry);
4848 +       vxdprintk(VXD_CBIT(misc, 2),
4849 +               "do_path_lookup(redo): %p [" VS_Q("%.*s") ":%d]",
4850 +               new_dentry,
4851 +               new_dentry->d_name.len, new_dentry->d_name.name,
4852 +               new_dentry->d_name.len);
4853 +
4854 +out_rel_both:
4855 +       if (new_path)
4856 +               path_put(new_path);
4857 +out_rel_old:
4858 +       path_put(old_path);
4859 +out_free_path:
4860 +       kfree(path);
4861 +out:
4862 +       if (ret) {
4863 +               dput(new_dentry);
4864 +               new_dentry = ERR_PTR(ret);
4865 +       }
4866 +       vxdprintk(VXD_CBIT(misc, 3),
4867 +               "cow_break_link returning with %p", new_dentry);
4868 +       return new_dentry;
4869 +}
4870 +
4871 +#endif
4872 +
4873 +int    vx_info_mnt_namespace(struct mnt_namespace *ns, char *buffer)
4874 +{
4875 +       struct path path;
4876 +       struct vfsmount *vmnt;
4877 +       char *pstr, *root;
4878 +       int length = 0;
4879 +
4880 +       pstr = kmalloc(PATH_MAX, GFP_KERNEL);
4881 +       if (!pstr)
4882 +               return 0;
4883 +
4884 +       vmnt = &ns->root->mnt;
4885 +       path.mnt = vmnt;
4886 +       path.dentry = vmnt->mnt_root;
4887 +       root = d_path(&path, pstr, PATH_MAX - 2);
4888 +       length = sprintf(buffer + length,
4889 +               "Namespace:\t%p [#%u]\n"
4890 +               "RootPath:\t%s\n",
4891 +               ns, atomic_read(&ns->count),
4892 +               root);
4893 +       kfree(pstr);
4894 +       return length;
4895 +}
4896 +
4897  /* get the link contents into pagecache */
4898  static char *page_getlink(struct dentry * dentry, struct page **ppage)
4899  {
4900 @@ -3998,3 +4409,4 @@ EXPORT_SYMBOL(vfs_symlink);
4901  EXPORT_SYMBOL(vfs_unlink);
4902  EXPORT_SYMBOL(dentry_unhash);
4903  EXPORT_SYMBOL(generic_readlink);
4904 +EXPORT_SYMBOL(vx_info_mnt_namespace);
4905 diff -NurpP --minimal linux-3.6.10/fs/namespace.c linux-3.6.10-vs2.3.4.5/fs/namespace.c
4906 --- linux-3.6.10/fs/namespace.c 2012-10-04 15:27:40.000000000 +0200
4907 +++ linux-3.6.10-vs2.3.4.5/fs/namespace.c       2012-12-08 01:10:23.000000000 +0100
4908 @@ -20,6 +20,11 @@
4909  #include <linux/fs_struct.h>   /* get_fs_root et.al. */
4910  #include <linux/fsnotify.h>    /* fsnotify_vfsmount_delete */
4911  #include <linux/uaccess.h>
4912 +#include <linux/vs_base.h>
4913 +#include <linux/vs_context.h>
4914 +#include <linux/vs_tag.h>
4915 +#include <linux/vserver/space.h>
4916 +#include <linux/vserver/global.h>
4917  #include "pnode.h"
4918  #include "internal.h"
4919  
4920 @@ -749,6 +754,10 @@ vfs_kern_mount(struct file_system_type *
4921         if (!type)
4922                 return ERR_PTR(-ENODEV);
4923  
4924 +       if ((type->fs_flags & FS_BINARY_MOUNTDATA) &&
4925 +               !vx_capable(CAP_SYS_ADMIN, VXC_BINARY_MOUNT))
4926 +               return ERR_PTR(-EPERM);
4927 +
4928         mnt = alloc_vfsmnt(name);
4929         if (!mnt)
4930                 return ERR_PTR(-ENOMEM);
4931 @@ -801,6 +810,7 @@ static struct mount *clone_mnt(struct mo
4932         mnt->mnt.mnt_root = dget(root);
4933         mnt->mnt_mountpoint = mnt->mnt.mnt_root;
4934         mnt->mnt_parent = mnt;
4935 +               mnt->mnt_tag = old->mnt_tag;
4936         br_write_lock(&vfsmount_lock);
4937         list_add_tail(&mnt->mnt_instance, &sb->s_mounts);
4938         br_write_unlock(&vfsmount_lock);
4939 @@ -1266,7 +1276,7 @@ SYSCALL_DEFINE2(umount, char __user *, n
4940                 goto dput_and_out;
4941  
4942         retval = -EPERM;
4943 -       if (!capable(CAP_SYS_ADMIN))
4944 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SECURE_MOUNT))
4945                 goto dput_and_out;
4946  
4947         retval = do_umount(mnt, flags);
4948 @@ -1292,7 +1302,7 @@ SYSCALL_DEFINE1(oldumount, char __user *
4949  
4950  static int mount_is_safe(struct path *path)
4951  {
4952 -       if (capable(CAP_SYS_ADMIN))
4953 +       if (vx_capable(CAP_SYS_ADMIN, VXC_SECURE_MOUNT))
4954                 return 0;
4955         return -EPERM;
4956  #ifdef notyet
4957 @@ -1610,7 +1620,7 @@ static int do_change_type(struct path *p
4958         int type;
4959         int err = 0;
4960  
4961 -       if (!capable(CAP_SYS_ADMIN))
4962 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_NAMESPACE))
4963                 return -EPERM;
4964  
4965         if (path->dentry != path->mnt->mnt_root)
4966 @@ -1626,6 +1636,7 @@ static int do_change_type(struct path *p
4967                 if (err)
4968                         goto out_unlock;
4969         }
4970 +       // mnt->mnt_flags = mnt_flags;
4971  
4972         br_write_lock(&vfsmount_lock);
4973         for (m = mnt; m; m = (recurse ? next_mnt(m, mnt) : NULL))
4974 @@ -1641,12 +1652,14 @@ static int do_change_type(struct path *p
4975   * do loopback mount.
4976   */
4977  static int do_loopback(struct path *path, char *old_name,
4978 -                               int recurse)
4979 +       tag_t tag, unsigned long flags, int mnt_flags)
4980  {
4981         LIST_HEAD(umount_list);
4982         struct path old_path;
4983         struct mount *mnt = NULL, *old;
4984         int err = mount_is_safe(path);
4985 +       int recurse = flags & MS_REC;
4986 +
4987         if (err)
4988                 return err;
4989         if (!old_name || !*old_name)
4990 @@ -1715,13 +1728,13 @@ static int change_mount_flags(struct vfs
4991   * on it - tough luck.
4992   */
4993  static int do_remount(struct path *path, int flags, int mnt_flags,
4994 -                     void *data)
4995 +       void *data, xid_t xid)
4996  {
4997         int err;
4998         struct super_block *sb = path->mnt->mnt_sb;
4999         struct mount *mnt = real_mount(path->mnt);
5000  
5001 -       if (!capable(CAP_SYS_ADMIN))
5002 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SECURE_REMOUNT))
5003                 return -EPERM;
5004  
5005         if (!check_mnt(mnt))
5006 @@ -1770,7 +1783,7 @@ static int do_move_mount(struct path *pa
5007         struct mount *p;
5008         struct mount *old;
5009         int err = 0;
5010 -       if (!capable(CAP_SYS_ADMIN))
5011 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SECURE_MOUNT))
5012                 return -EPERM;
5013         if (!old_name || !*old_name)
5014                 return -EINVAL;
5015 @@ -1927,7 +1940,7 @@ static int do_new_mount(struct path *pat
5016                 return -EINVAL;
5017  
5018         /* we need capabilities... */
5019 -       if (!capable(CAP_SYS_ADMIN))
5020 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SECURE_MOUNT))
5021                 return -EPERM;
5022  
5023         mnt = do_kern_mount(type, flags, name, data);
5024 @@ -2197,6 +2210,7 @@ long do_mount(char *dev_name, char *dir_
5025         struct path path;
5026         int retval = 0;
5027         int mnt_flags = 0;
5028 +       tag_t tag = 0;
5029  
5030         /* Discard magic */
5031         if ((flags & MS_MGC_MSK) == MS_MGC_VAL)
5032 @@ -2224,6 +2238,12 @@ long do_mount(char *dev_name, char *dir_
5033         if (!(flags & MS_NOATIME))
5034                 mnt_flags |= MNT_RELATIME;
5035  
5036 +       if (dx_parse_tag(data_page, &tag, 1, &mnt_flags, &flags)) {
5037 +               /* FIXME: bind and re-mounts get the tag flag? */
5038 +               if (flags & (MS_BIND|MS_REMOUNT))
5039 +                       flags |= MS_TAGID;
5040 +       }
5041 +
5042         /* Separate the per-mountpoint flags */
5043         if (flags & MS_NOSUID)
5044                 mnt_flags |= MNT_NOSUID;
5045 @@ -2240,15 +2260,17 @@ long do_mount(char *dev_name, char *dir_
5046         if (flags & MS_RDONLY)
5047                 mnt_flags |= MNT_READONLY;
5048  
5049 +       if (!capable(CAP_SYS_ADMIN))
5050 +               mnt_flags |= MNT_NODEV;
5051         flags &= ~(MS_NOSUID | MS_NOEXEC | MS_NODEV | MS_ACTIVE | MS_BORN |
5052                    MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
5053                    MS_STRICTATIME);
5054  
5055         if (flags & MS_REMOUNT)
5056                 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
5057 -                                   data_page);
5058 +                                   data_page, tag);
5059         else if (flags & MS_BIND)
5060 -               retval = do_loopback(&path, dev_name, flags & MS_REC);
5061 +               retval = do_loopback(&path, dev_name, tag, flags, mnt_flags);
5062         else if (flags & (MS_SHARED | MS_PRIVATE | MS_SLAVE | MS_UNBINDABLE))
5063                 retval = do_change_type(&path, flags);
5064         else if (flags & MS_MOVE)
5065 @@ -2329,6 +2351,7 @@ static struct mnt_namespace *dup_mnt_ns(
5066                 q = next_mnt(q, new);
5067         }
5068         up_write(&namespace_sem);
5069 +       atomic_inc(&vs_global_mnt_ns);
5070  
5071         if (rootmnt)
5072                 mntput(rootmnt);
5073 @@ -2524,9 +2547,10 @@ SYSCALL_DEFINE2(pivot_root, const char _
5074         error = -EINVAL;
5075         new_mnt = real_mount(new.mnt);
5076         root_mnt = real_mount(root.mnt);
5077 -       if (IS_MNT_SHARED(real_mount(old.mnt)) ||
5078 +       if ((IS_MNT_SHARED(real_mount(old.mnt)) ||
5079                 IS_MNT_SHARED(new_mnt->mnt_parent) ||
5080 -               IS_MNT_SHARED(root_mnt->mnt_parent))
5081 +               IS_MNT_SHARED(root_mnt->mnt_parent)) &&
5082 +               !vx_flags(VXF_STATE_SETUP, 0))
5083                 goto out4;
5084         if (!check_mnt(root_mnt) || !check_mnt(new_mnt))
5085                 goto out4;
5086 @@ -2647,6 +2671,7 @@ void put_mnt_ns(struct mnt_namespace *ns
5087         br_write_unlock(&vfsmount_lock);
5088         up_write(&namespace_sem);
5089         release_mounts(&umount_list);
5090 +       atomic_dec(&vs_global_mnt_ns);
5091         kfree(ns);
5092  }
5093  
5094 diff -NurpP --minimal linux-3.6.10/fs/nfs/client.c linux-3.6.10-vs2.3.4.5/fs/nfs/client.c
5095 --- linux-3.6.10/fs/nfs/client.c        2012-12-11 12:36:58.000000000 +0100
5096 +++ linux-3.6.10-vs2.3.4.5/fs/nfs/client.c      2012-11-06 18:43:41.000000000 +0100
5097 @@ -692,6 +692,9 @@ int nfs_init_server_rpcclient(struct nfs
5098         if (server->flags & NFS_MOUNT_SOFT)
5099                 server->client->cl_softrtry = 1;
5100  
5101 +       server->client->cl_tag = 0;
5102 +       if (server->flags & NFS_MOUNT_TAGGED)
5103 +               server->client->cl_tag = 1;
5104         return 0;
5105  }
5106  EXPORT_SYMBOL_GPL(nfs_init_server_rpcclient);
5107 @@ -869,6 +872,10 @@ static void nfs_server_set_fsinfo(struct
5108                 server->acdirmin = server->acdirmax = 0;
5109         }
5110  
5111 +       /* FIXME: needs fsinfo
5112 +       if (server->flags & NFS_MOUNT_TAGGED)
5113 +               sb->s_flags |= MS_TAGGED;       */
5114 +
5115         server->maxfilesize = fsinfo->maxfilesize;
5116  
5117         server->time_delta = fsinfo->time_delta;
5118 diff -NurpP --minimal linux-3.6.10/fs/nfs/dir.c linux-3.6.10-vs2.3.4.5/fs/nfs/dir.c
5119 --- linux-3.6.10/fs/nfs/dir.c   2012-10-04 15:27:40.000000000 +0200
5120 +++ linux-3.6.10-vs2.3.4.5/fs/nfs/dir.c 2012-10-04 18:47:00.000000000 +0200
5121 @@ -36,6 +36,7 @@
5122  #include <linux/sched.h>
5123  #include <linux/kmemleak.h>
5124  #include <linux/xattr.h>
5125 +#include <linux/vs_tag.h>
5126  
5127  #include "delegation.h"
5128  #include "iostat.h"
5129 @@ -1251,6 +1252,7 @@ struct dentry *nfs_lookup(struct inode *
5130         /* Success: notify readdir to use READDIRPLUS */
5131         nfs_advise_use_readdirplus(dir);
5132  
5133 +       dx_propagate_tag(nd, inode);
5134  no_entry:
5135         res = d_materialise_unique(dentry, inode);
5136         if (res != NULL) {
5137 diff -NurpP --minimal linux-3.6.10/fs/nfs/inode.c linux-3.6.10-vs2.3.4.5/fs/nfs/inode.c
5138 --- linux-3.6.10/fs/nfs/inode.c 2012-10-04 15:27:40.000000000 +0200
5139 +++ linux-3.6.10-vs2.3.4.5/fs/nfs/inode.c       2012-10-04 18:47:00.000000000 +0200
5140 @@ -39,6 +39,7 @@
5141  #include <linux/compat.h>
5142  #include <linux/freezer.h>
5143  #include <linux/crc32.h>
5144 +#include <linux/vs_tag.h>
5145  
5146  #include <asm/uaccess.h>
5147  
5148 @@ -279,6 +280,8 @@ nfs_fhget(struct super_block *sb, struct
5149         if (inode->i_state & I_NEW) {
5150                 struct nfs_inode *nfsi = NFS_I(inode);
5151                 unsigned long now = jiffies;
5152 +               uid_t uid;
5153 +               gid_t gid;
5154  
5155                 /* We set i_ino for the few things that still rely on it,
5156                  * such as stat(2) */
5157 @@ -323,8 +326,8 @@ nfs_fhget(struct super_block *sb, struct
5158                 inode->i_version = 0;
5159                 inode->i_size = 0;
5160                 clear_nlink(inode);
5161 -               inode->i_uid = -2;
5162 -               inode->i_gid = -2;
5163 +               uid = -2;
5164 +               gid = -2;
5165                 inode->i_blocks = 0;
5166                 memset(nfsi->cookieverf, 0, sizeof(nfsi->cookieverf));
5167                 nfsi->write_io = 0;
5168 @@ -358,11 +361,11 @@ nfs_fhget(struct super_block *sb, struct
5169                 else if (nfs_server_capable(inode, NFS_CAP_NLINK))
5170                         nfsi->cache_validity |= NFS_INO_INVALID_ATTR;
5171                 if (fattr->valid & NFS_ATTR_FATTR_OWNER)
5172 -                       inode->i_uid = fattr->uid;
5173 +                       uid = fattr->uid;
5174                 else if (nfs_server_capable(inode, NFS_CAP_OWNER))
5175                         nfsi->cache_validity |= NFS_INO_INVALID_ATTR;
5176                 if (fattr->valid & NFS_ATTR_FATTR_GROUP)
5177 -                       inode->i_gid = fattr->gid;
5178 +                       gid = fattr->gid;
5179                 else if (nfs_server_capable(inode, NFS_CAP_OWNER_GROUP))
5180                         nfsi->cache_validity |= NFS_INO_INVALID_ATTR;
5181                 if (fattr->valid & NFS_ATTR_FATTR_BLOCKS_USED)
5182 @@ -373,6 +376,11 @@ nfs_fhget(struct super_block *sb, struct
5183                          */
5184                         inode->i_blocks = nfs_calc_block_size(fattr->du.nfs3.used);
5185                 }
5186 +               inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
5187 +               inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
5188 +               inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid, 0);
5189 +                               /* maybe fattr->xid someday */
5190 +
5191                 nfsi->attrtimeo = NFS_MINATTRTIMEO(inode);
5192                 nfsi->attrtimeo_timestamp = now;
5193                 nfsi->access_cache = RB_ROOT;
5194 @@ -494,6 +502,8 @@ void nfs_setattr_update_inode(struct ino
5195                         inode->i_uid = attr->ia_uid;
5196                 if ((attr->ia_valid & ATTR_GID) != 0)
5197                         inode->i_gid = attr->ia_gid;
5198 +               if ((attr->ia_valid & ATTR_TAG) && IS_TAGGED(inode))
5199 +                       inode->i_tag = attr->ia_tag;
5200                 NFS_I(inode)->cache_validity |= NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL;
5201                 spin_unlock(&inode->i_lock);
5202         }
5203 @@ -965,6 +975,9 @@ static int nfs_check_inode_attributes(st
5204         struct nfs_inode *nfsi = NFS_I(inode);
5205         loff_t cur_size, new_isize;
5206         unsigned long invalid = 0;
5207 +       uid_t uid;
5208 +       gid_t gid;
5209 +       tag_t tag;
5210  
5211  
5212         if (nfs_have_delegated_attributes(inode))
5213 @@ -990,13 +1003,18 @@ static int nfs_check_inode_attributes(st
5214                         invalid |= NFS_INO_INVALID_ATTR|NFS_INO_REVAL_PAGECACHE;
5215         }
5216  
5217 +       uid = INOTAG_UID(DX_TAG(inode), fattr->uid, fattr->gid);
5218 +       gid = INOTAG_GID(DX_TAG(inode), fattr->uid, fattr->gid);
5219 +       tag = INOTAG_TAG(DX_TAG(inode), fattr->uid, fattr->gid, 0);
5220 +
5221         /* Have any file permissions changed? */
5222         if ((fattr->valid & NFS_ATTR_FATTR_MODE) && (inode->i_mode & S_IALLUGO) != (fattr->mode & S_IALLUGO))
5223                 invalid |= NFS_INO_INVALID_ATTR | NFS_INO_INVALID_ACCESS | NFS_INO_INVALID_ACL;
5224 -       if ((fattr->valid & NFS_ATTR_FATTR_OWNER) && inode->i_uid != fattr->uid)
5225 +       if ((fattr->valid & NFS_ATTR_FATTR_OWNER) && uid != fattr->uid)
5226                 invalid |= NFS_INO_INVALID_ATTR | NFS_INO_INVALID_ACCESS | NFS_INO_INVALID_ACL;
5227 -       if ((fattr->valid & NFS_ATTR_FATTR_GROUP) && inode->i_gid != fattr->gid)
5228 +       if ((fattr->valid & NFS_ATTR_FATTR_GROUP) && gid != fattr->gid)
5229                 invalid |= NFS_INO_INVALID_ATTR | NFS_INO_INVALID_ACCESS | NFS_INO_INVALID_ACL;
5230 +               /* maybe check for tag too? */
5231  
5232         /* Has the link count changed? */
5233         if ((fattr->valid & NFS_ATTR_FATTR_NLINK) && inode->i_nlink != fattr->nlink)
5234 @@ -1300,6 +1318,9 @@ static int nfs_update_inode(struct inode
5235         unsigned long invalid = 0;
5236         unsigned long now = jiffies;
5237         unsigned long save_cache_validity;
5238 +       uid_t uid;
5239 +       gid_t gid;
5240 +       tag_t tag;
5241  
5242         dfprintk(VFS, "NFS: %s(%s/%ld fh_crc=0x%08x ct=%d info=0x%x)\n",
5243                         __func__, inode->i_sb->s_id, inode->i_ino,
5244 @@ -1401,6 +1422,9 @@ static int nfs_update_inode(struct inode
5245                                 | NFS_INO_REVAL_PAGECACHE
5246                                 | NFS_INO_REVAL_FORCED);
5247  
5248 +       uid = TAGINO_UID(DX_TAG(inode), inode->i_uid, inode->i_tag);
5249 +       gid = TAGINO_GID(DX_TAG(inode), inode->i_gid, inode->i_tag);
5250 +       tag = inode->i_tag;
5251  
5252         if (fattr->valid & NFS_ATTR_FATTR_ATIME)
5253                 memcpy(&inode->i_atime, &fattr->atime, sizeof(inode->i_atime));
5254 @@ -1422,9 +1446,9 @@ static int nfs_update_inode(struct inode
5255                                 | NFS_INO_REVAL_FORCED);
5256  
5257         if (fattr->valid & NFS_ATTR_FATTR_OWNER) {
5258 -               if (inode->i_uid != fattr->uid) {
5259 +               if (uid != fattr->uid) {
5260                         invalid |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL;
5261 -                       inode->i_uid = fattr->uid;
5262 +                       uid = fattr->uid;
5263                 }
5264         } else if (server->caps & NFS_CAP_OWNER)
5265                 invalid |= save_cache_validity & (NFS_INO_INVALID_ATTR
5266 @@ -1433,9 +1457,9 @@ static int nfs_update_inode(struct inode
5267                                 | NFS_INO_REVAL_FORCED);
5268  
5269         if (fattr->valid & NFS_ATTR_FATTR_GROUP) {
5270 -               if (inode->i_gid != fattr->gid) {
5271 +               if (gid != fattr->gid) {
5272                         invalid |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL;
5273 -                       inode->i_gid = fattr->gid;
5274 +                       gid = fattr->gid;
5275                 }
5276         } else if (server->caps & NFS_CAP_OWNER_GROUP)
5277                 invalid |= save_cache_validity & (NFS_INO_INVALID_ATTR
5278 @@ -1443,6 +1467,10 @@ static int nfs_update_inode(struct inode
5279                                 | NFS_INO_INVALID_ACL
5280                                 | NFS_INO_REVAL_FORCED);
5281  
5282 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
5283 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
5284 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid, tag);
5285 +
5286         if (fattr->valid & NFS_ATTR_FATTR_NLINK) {
5287                 if (inode->i_nlink != fattr->nlink) {
5288                         invalid |= NFS_INO_INVALID_ATTR;
5289 diff -NurpP --minimal linux-3.6.10/fs/nfs/nfs3xdr.c linux-3.6.10-vs2.3.4.5/fs/nfs/nfs3xdr.c
5290 --- linux-3.6.10/fs/nfs/nfs3xdr.c       2012-10-04 15:27:40.000000000 +0200
5291 +++ linux-3.6.10-vs2.3.4.5/fs/nfs/nfs3xdr.c     2012-10-04 18:47:00.000000000 +0200
5292 @@ -20,6 +20,7 @@
5293  #include <linux/nfs3.h>
5294  #include <linux/nfs_fs.h>
5295  #include <linux/nfsacl.h>
5296 +#include <linux/vs_tag.h>
5297  #include "internal.h"
5298  
5299  #define NFSDBG_FACILITY                NFSDBG_XDR
5300 @@ -560,7 +561,8 @@ static __be32 *xdr_decode_nfstime3(__be3
5301   *             set_mtime       mtime;
5302   *     };
5303   */
5304 -static void encode_sattr3(struct xdr_stream *xdr, const struct iattr *attr)
5305 +static void encode_sattr3(struct xdr_stream *xdr,
5306 +       const struct iattr *attr, int tag)
5307  {
5308         u32 nbytes;
5309         __be32 *p;
5310 @@ -592,15 +594,19 @@ static void encode_sattr3(struct xdr_str
5311         } else
5312                 *p++ = xdr_zero;
5313  
5314 -       if (attr->ia_valid & ATTR_UID) {
5315 +       if (attr->ia_valid & ATTR_UID ||
5316 +               (tag && (attr->ia_valid & ATTR_TAG))) {
5317                 *p++ = xdr_one;
5318 -               *p++ = cpu_to_be32(attr->ia_uid);
5319 +               *p++ = cpu_to_be32(TAGINO_UID(tag,
5320 +                       attr->ia_uid, attr->ia_tag));
5321         } else
5322                 *p++ = xdr_zero;
5323  
5324 -       if (attr->ia_valid & ATTR_GID) {
5325 +       if (attr->ia_valid & ATTR_GID ||
5326 +               (tag && (attr->ia_valid & ATTR_TAG))) {
5327                 *p++ = xdr_one;
5328 -               *p++ = cpu_to_be32(attr->ia_gid);
5329 +               *p++ = cpu_to_be32(TAGINO_GID(tag,
5330 +                       attr->ia_gid, attr->ia_tag));
5331         } else
5332                 *p++ = xdr_zero;
5333  
5334 @@ -879,7 +885,7 @@ static void nfs3_xdr_enc_setattr3args(st
5335                                       const struct nfs3_sattrargs *args)
5336  {
5337         encode_nfs_fh3(xdr, args->fh);
5338 -       encode_sattr3(xdr, args->sattr);
5339 +       encode_sattr3(xdr, args->sattr, req->rq_task->tk_client->cl_tag);
5340         encode_sattrguard3(xdr, args);
5341  }
5342  
5343 @@ -1029,13 +1035,13 @@ static void nfs3_xdr_enc_write3args(stru
5344   *     };
5345   */
5346  static void encode_createhow3(struct xdr_stream *xdr,
5347 -                             const struct nfs3_createargs *args)
5348 +       const struct nfs3_createargs *args, int tag)
5349  {
5350         encode_uint32(xdr, args->createmode);
5351         switch (args->createmode) {
5352         case NFS3_CREATE_UNCHECKED:
5353         case NFS3_CREATE_GUARDED:
5354 -               encode_sattr3(xdr, args->sattr);
5355 +               encode_sattr3(xdr, args->sattr, tag);
5356                 break;
5357         case NFS3_CREATE_EXCLUSIVE:
5358                 encode_createverf3(xdr, args->verifier);
5359 @@ -1050,7 +1056,7 @@ static void nfs3_xdr_enc_create3args(str
5360                                      const struct nfs3_createargs *args)
5361  {
5362         encode_diropargs3(xdr, args->fh, args->name, args->len);
5363 -       encode_createhow3(xdr, args);
5364 +       encode_createhow3(xdr, args, req->rq_task->tk_client->cl_tag);
5365  }
5366  
5367  /*
5368 @@ -1066,7 +1072,7 @@ static void nfs3_xdr_enc_mkdir3args(stru
5369                                     const struct nfs3_mkdirargs *args)
5370  {
5371         encode_diropargs3(xdr, args->fh, args->name, args->len);
5372 -       encode_sattr3(xdr, args->sattr);
5373 +       encode_sattr3(xdr, args->sattr, req->rq_task->tk_client->cl_tag);
5374  }
5375  
5376  /*
5377 @@ -1083,9 +1089,9 @@ static void nfs3_xdr_enc_mkdir3args(stru
5378   *     };
5379   */
5380  static void encode_symlinkdata3(struct xdr_stream *xdr,
5381 -                               const struct nfs3_symlinkargs *args)
5382 +       const struct nfs3_symlinkargs *args, int tag)
5383  {
5384 -       encode_sattr3(xdr, args->sattr);
5385 +       encode_sattr3(xdr, args->sattr, tag);
5386         encode_nfspath3(xdr, args->pages, args->pathlen);
5387  }
5388  
5389 @@ -1094,7 +1100,7 @@ static void nfs3_xdr_enc_symlink3args(st
5390                                       const struct nfs3_symlinkargs *args)
5391  {
5392         encode_diropargs3(xdr, args->fromfh, args->fromname, args->fromlen);
5393 -       encode_symlinkdata3(xdr, args);
5394 +       encode_symlinkdata3(xdr, args, req->rq_task->tk_client->cl_tag);
5395  }
5396  
5397  /*
5398 @@ -1122,24 +1128,24 @@ static void nfs3_xdr_enc_symlink3args(st
5399   *     };
5400   */
5401  static void encode_devicedata3(struct xdr_stream *xdr,
5402 -                              const struct nfs3_mknodargs *args)
5403 +       const struct nfs3_mknodargs *args, int tag)
5404  {
5405 -       encode_sattr3(xdr, args->sattr);
5406 +       encode_sattr3(xdr, args->sattr, tag);
5407         encode_specdata3(xdr, args->rdev);
5408  }
5409  
5410  static void encode_mknoddata3(struct xdr_stream *xdr,
5411 -                             const struct nfs3_mknodargs *args)
5412 +       const struct nfs3_mknodargs *args, int tag)
5413  {
5414         encode_ftype3(xdr, args->type);
5415         switch (args->type) {
5416         case NF3CHR:
5417         case NF3BLK:
5418 -               encode_devicedata3(xdr, args);
5419 +               encode_devicedata3(xdr, args, tag);
5420                 break;
5421         case NF3SOCK:
5422         case NF3FIFO:
5423 -               encode_sattr3(xdr, args->sattr);
5424 +               encode_sattr3(xdr, args->sattr, tag);
5425                 break;
5426         case NF3REG:
5427         case NF3DIR:
5428 @@ -1154,7 +1160,7 @@ static void nfs3_xdr_enc_mknod3args(stru
5429                                     const struct nfs3_mknodargs *args)
5430  {
5431         encode_diropargs3(xdr, args->fh, args->name, args->len);
5432 -       encode_mknoddata3(xdr, args);
5433 +       encode_mknoddata3(xdr, args, req->rq_task->tk_client->cl_tag);
5434  }
5435  
5436  /*
5437 diff -NurpP --minimal linux-3.6.10/fs/nfs/super.c linux-3.6.10-vs2.3.4.5/fs/nfs/super.c
5438 --- linux-3.6.10/fs/nfs/super.c 2012-12-11 12:36:58.000000000 +0100
5439 +++ linux-3.6.10-vs2.3.4.5/fs/nfs/super.c       2012-12-08 01:36:33.000000000 +0100
5440 @@ -54,6 +54,7 @@
5441  #include <linux/parser.h>
5442  #include <linux/nsproxy.h>
5443  #include <linux/rcupdate.h>
5444 +#include <linux/vs_tag.h>
5445  
5446  #include <asm/uaccess.h>
5447  
5448 @@ -88,6 +89,7 @@ enum {
5449         Opt_sharecache, Opt_nosharecache,
5450         Opt_resvport, Opt_noresvport,
5451         Opt_fscache, Opt_nofscache,
5452 +       Opt_tag, Opt_notag,
5453  
5454         /* Mount options that take integer arguments */
5455         Opt_port,
5456 @@ -100,6 +102,7 @@ enum {
5457         Opt_mountport,
5458         Opt_mountvers,
5459         Opt_minorversion,
5460 +       Opt_tagid,
5461  
5462         /* Mount options that take string arguments */
5463         Opt_nfsvers,
5464 @@ -182,6 +185,10 @@ static const match_table_t nfs_mount_opt
5465         /* The following needs to be listed after all other options */
5466         { Opt_nfsvers, "v%s" },
5467  
5468 +       { Opt_tag, "tag" },
5469 +       { Opt_notag, "notag" },
5470 +       { Opt_tagid, "tagid=%u" },
5471 +
5472         { Opt_err, NULL }
5473  };
5474  
5475 @@ -626,6 +633,7 @@ static void nfs_show_mount_options(struc
5476                 { NFS_MOUNT_NORDIRPLUS, ",nordirplus", "" },
5477                 { NFS_MOUNT_UNSHARED, ",nosharecache", "" },
5478                 { NFS_MOUNT_NORESVPORT, ",noresvport", "" },
5479 +               { NFS_MOUNT_TAGGED, ",tag", "" },
5480                 { 0, NULL, NULL }
5481         };
5482         const struct proc_nfs_info *nfs_infop;
5483 @@ -1243,6 +1251,14 @@ static int nfs_parse_mount_options(char 
5484                         kfree(mnt->fscache_uniq);
5485                         mnt->fscache_uniq = NULL;
5486                         break;
5487 +#ifndef CONFIG_TAGGING_NONE
5488 +               case Opt_tag:
5489 +                       mnt->flags |= NFS_MOUNT_TAGGED;
5490 +                       break;
5491 +               case Opt_notag:
5492 +                       mnt->flags &= ~NFS_MOUNT_TAGGED;
5493 +                       break;
5494 +#endif
5495  
5496                 /*
5497                  * options that take numeric values
5498 @@ -1329,6 +1345,12 @@ static int nfs_parse_mount_options(char 
5499                                 goto out_invalid_value;
5500                         mnt->minorversion = option;
5501                         break;
5502 +#ifdef CONFIG_PROPAGATE
5503 +               case Opt_tagid:
5504 +                       /* use args[0] */
5505 +                       nfs_data.flags |= NFS_MOUNT_TAGGED;
5506 +                       break;
5507 +#endif
5508  
5509                 /*
5510                  * options that take text values
5511 diff -NurpP --minimal linux-3.6.10/fs/nfsd/auth.c linux-3.6.10-vs2.3.4.5/fs/nfsd/auth.c
5512 --- linux-3.6.10/fs/nfsd/auth.c 2012-07-22 23:39:41.000000000 +0200
5513 +++ linux-3.6.10-vs2.3.4.5/fs/nfsd/auth.c       2012-10-04 18:47:00.000000000 +0200
5514 @@ -2,6 +2,7 @@
5515  
5516  #include <linux/sched.h>
5517  #include <linux/user_namespace.h>
5518 +#include <linux/vs_tag.h>
5519  #include "nfsd.h"
5520  #include "auth.h"
5521  
5522 @@ -37,6 +38,9 @@ int nfsd_setuser(struct svc_rqst *rqstp,
5523  
5524         new->fsuid = rqstp->rq_cred.cr_uid;
5525         new->fsgid = rqstp->rq_cred.cr_gid;
5526 +       /* FIXME: this desperately needs a tag :)
5527 +       new->xid = (xid_t)INOTAG_TAG(DX_TAG_NFSD, cred.cr_uid, cred.cr_gid, 0);
5528 +                       */
5529  
5530         rqgi = rqstp->rq_cred.cr_group_info;
5531  
5532 diff -NurpP --minimal linux-3.6.10/fs/nfsd/nfs3xdr.c linux-3.6.10-vs2.3.4.5/fs/nfsd/nfs3xdr.c
5533 --- linux-3.6.10/fs/nfsd/nfs3xdr.c      2012-05-21 18:07:26.000000000 +0200
5534 +++ linux-3.6.10-vs2.3.4.5/fs/nfsd/nfs3xdr.c    2012-10-04 18:47:00.000000000 +0200
5535 @@ -7,6 +7,7 @@
5536   */
5537  
5538  #include <linux/namei.h>
5539 +#include <linux/vs_tag.h>
5540  #include "xdr3.h"
5541  #include "auth.h"
5542  
5543 @@ -95,6 +96,8 @@ static __be32 *
5544  decode_sattr3(__be32 *p, struct iattr *iap)
5545  {
5546         u32     tmp;
5547 +       uid_t   uid = 0;
5548 +       gid_t   gid = 0;
5549  
5550         iap->ia_valid = 0;
5551  
5552 @@ -104,12 +107,15 @@ decode_sattr3(__be32 *p, struct iattr *i
5553         }
5554         if (*p++) {
5555                 iap->ia_valid |= ATTR_UID;
5556 -               iap->ia_uid = ntohl(*p++);
5557 +               uid = ntohl(*p++);
5558         }
5559         if (*p++) {
5560                 iap->ia_valid |= ATTR_GID;
5561 -               iap->ia_gid = ntohl(*p++);
5562 +               gid = ntohl(*p++);
5563         }
5564 +       iap->ia_uid = INOTAG_UID(DX_TAG_NFSD, uid, gid);
5565 +       iap->ia_gid = INOTAG_GID(DX_TAG_NFSD, uid, gid);
5566 +       iap->ia_tag = INOTAG_TAG(DX_TAG_NFSD, uid, gid, 0);
5567         if (*p++) {
5568                 u64     newsize;
5569  
5570 @@ -165,8 +171,12 @@ encode_fattr3(struct svc_rqst *rqstp, __
5571         *p++ = htonl(nfs3_ftypes[(stat->mode & S_IFMT) >> 12]);
5572         *p++ = htonl((u32) stat->mode);
5573         *p++ = htonl((u32) stat->nlink);
5574 -       *p++ = htonl((u32) nfsd_ruid(rqstp, stat->uid));
5575 -       *p++ = htonl((u32) nfsd_rgid(rqstp, stat->gid));
5576 +       *p++ = htonl((u32) nfsd_ruid(rqstp,
5577 +               TAGINO_UID(0 /* FIXME: DX_TAG(dentry->d_inode) */,
5578 +               stat->uid, stat->tag)));
5579 +       *p++ = htonl((u32) nfsd_rgid(rqstp,
5580 +               TAGINO_GID(0 /* FIXME: DX_TAG(dentry->d_inode) */,
5581 +               stat->gid, stat->tag)));
5582         if (S_ISLNK(stat->mode) && stat->size > NFS3_MAXPATHLEN) {
5583                 p = xdr_encode_hyper(p, (u64) NFS3_MAXPATHLEN);
5584         } else {
5585 diff -NurpP --minimal linux-3.6.10/fs/nfsd/nfs4xdr.c linux-3.6.10-vs2.3.4.5/fs/nfsd/nfs4xdr.c
5586 --- linux-3.6.10/fs/nfsd/nfs4xdr.c      2012-10-04 15:27:40.000000000 +0200
5587 +++ linux-3.6.10-vs2.3.4.5/fs/nfsd/nfs4xdr.c    2012-10-04 18:47:00.000000000 +0200
5588 @@ -46,6 +46,7 @@
5589  #include <linux/utsname.h>
5590  #include <linux/pagemap.h>
5591  #include <linux/sunrpc/svcauth_gss.h>
5592 +#include <linux/vs_tag.h>
5593  
5594  #include "idmap.h"
5595  #include "acl.h"
5596 @@ -2351,14 +2352,18 @@ out_acl:
5597                 WRITE32(stat.nlink);
5598         }
5599         if (bmval1 & FATTR4_WORD1_OWNER) {
5600 -               status = nfsd4_encode_user(rqstp, stat.uid, &p, &buflen);
5601 +               status = nfsd4_encode_user(rqstp,
5602 +                       TAGINO_UID(DX_TAG(dentry->d_inode),
5603 +                       stat.uid, stat.tag), &p, &buflen);
5604                 if (status == nfserr_resource)
5605                         goto out_resource;
5606                 if (status)
5607                         goto out;
5608         }
5609         if (bmval1 & FATTR4_WORD1_OWNER_GROUP) {
5610 -               status = nfsd4_encode_group(rqstp, stat.gid, &p, &buflen);
5611 +               status = nfsd4_encode_group(rqstp,
5612 +                       TAGINO_GID(DX_TAG(dentry->d_inode),
5613 +                       stat.gid, stat.tag), &p, &buflen);
5614                 if (status == nfserr_resource)
5615                         goto out_resource;
5616                 if (status)
5617 diff -NurpP --minimal linux-3.6.10/fs/nfsd/nfsxdr.c linux-3.6.10-vs2.3.4.5/fs/nfsd/nfsxdr.c
5618 --- linux-3.6.10/fs/nfsd/nfsxdr.c       2011-05-22 16:17:53.000000000 +0200
5619 +++ linux-3.6.10-vs2.3.4.5/fs/nfsd/nfsxdr.c     2012-10-04 18:47:00.000000000 +0200
5620 @@ -6,6 +6,7 @@
5621  
5622  #include "xdr.h"
5623  #include "auth.h"
5624 +#include <linux/vs_tag.h>
5625  
5626  #define NFSDDBG_FACILITY               NFSDDBG_XDR
5627  
5628 @@ -88,6 +89,8 @@ static __be32 *
5629  decode_sattr(__be32 *p, struct iattr *iap)
5630  {
5631         u32     tmp, tmp1;
5632 +       uid_t   uid = 0;
5633 +       gid_t   gid = 0;
5634  
5635         iap->ia_valid = 0;
5636  
5637 @@ -101,12 +104,15 @@ decode_sattr(__be32 *p, struct iattr *ia
5638         }
5639         if ((tmp = ntohl(*p++)) != (u32)-1) {
5640                 iap->ia_valid |= ATTR_UID;
5641 -               iap->ia_uid = tmp;
5642 +               uid = tmp;
5643         }
5644         if ((tmp = ntohl(*p++)) != (u32)-1) {
5645                 iap->ia_valid |= ATTR_GID;
5646 -               iap->ia_gid = tmp;
5647 +               gid = tmp;
5648         }
5649 +       iap->ia_uid = INOTAG_UID(DX_TAG_NFSD, uid, gid);
5650 +       iap->ia_gid = INOTAG_GID(DX_TAG_NFSD, uid, gid);
5651 +       iap->ia_tag = INOTAG_TAG(DX_TAG_NFSD, uid, gid, 0);
5652         if ((tmp = ntohl(*p++)) != (u32)-1) {
5653                 iap->ia_valid |= ATTR_SIZE;
5654                 iap->ia_size = tmp;
5655 @@ -151,8 +157,10 @@ encode_fattr(struct svc_rqst *rqstp, __b
5656         *p++ = htonl(nfs_ftypes[type >> 12]);
5657         *p++ = htonl((u32) stat->mode);
5658         *p++ = htonl((u32) stat->nlink);
5659 -       *p++ = htonl((u32) nfsd_ruid(rqstp, stat->uid));
5660 -       *p++ = htonl((u32) nfsd_rgid(rqstp, stat->gid));
5661 +       *p++ = htonl((u32) nfsd_ruid(rqstp,
5662 +               TAGINO_UID(DX_TAG(dentry->d_inode), stat->uid, stat->tag)));
5663 +       *p++ = htonl((u32) nfsd_rgid(rqstp,
5664 +               TAGINO_GID(DX_TAG(dentry->d_inode), stat->gid, stat->tag)));
5665  
5666         if (S_ISLNK(type) && stat->size > NFS_MAXPATHLEN) {
5667                 *p++ = htonl(NFS_MAXPATHLEN);
5668 diff -NurpP --minimal linux-3.6.10/fs/ocfs2/dlmglue.c linux-3.6.10-vs2.3.4.5/fs/ocfs2/dlmglue.c
5669 --- linux-3.6.10/fs/ocfs2/dlmglue.c     2012-07-22 23:39:41.000000000 +0200
5670 +++ linux-3.6.10-vs2.3.4.5/fs/ocfs2/dlmglue.c   2012-10-04 18:47:00.000000000 +0200
5671 @@ -2047,6 +2047,7 @@ static void __ocfs2_stuff_meta_lvb(struc
5672         lvb->lvb_iclusters = cpu_to_be32(oi->ip_clusters);
5673         lvb->lvb_iuid      = cpu_to_be32(inode->i_uid);
5674         lvb->lvb_igid      = cpu_to_be32(inode->i_gid);
5675 +       lvb->lvb_itag      = cpu_to_be16(inode->i_tag);
5676         lvb->lvb_imode     = cpu_to_be16(inode->i_mode);
5677         lvb->lvb_inlink    = cpu_to_be16(inode->i_nlink);
5678         lvb->lvb_iatime_packed  =
5679 @@ -2097,6 +2098,7 @@ static void ocfs2_refresh_inode_from_lvb
5680  
5681         inode->i_uid     = be32_to_cpu(lvb->lvb_iuid);
5682         inode->i_gid     = be32_to_cpu(lvb->lvb_igid);
5683 +       inode->i_tag     = be16_to_cpu(lvb->lvb_itag);
5684         inode->i_mode    = be16_to_cpu(lvb->lvb_imode);
5685         set_nlink(inode, be16_to_cpu(lvb->lvb_inlink));
5686         ocfs2_unpack_timespec(&inode->i_atime,
5687 diff -NurpP --minimal linux-3.6.10/fs/ocfs2/dlmglue.h linux-3.6.10-vs2.3.4.5/fs/ocfs2/dlmglue.h
5688 --- linux-3.6.10/fs/ocfs2/dlmglue.h     2010-10-21 13:07:50.000000000 +0200
5689 +++ linux-3.6.10-vs2.3.4.5/fs/ocfs2/dlmglue.h   2012-10-04 18:47:00.000000000 +0200
5690 @@ -46,7 +46,8 @@ struct ocfs2_meta_lvb {
5691         __be16       lvb_inlink;
5692         __be32       lvb_iattr;
5693         __be32       lvb_igeneration;
5694 -       __be32       lvb_reserved2;
5695 +       __be16       lvb_itag;
5696 +       __be16       lvb_reserved2;
5697  };
5698  
5699  #define OCFS2_QINFO_LVB_VERSION 1
5700 diff -NurpP --minimal linux-3.6.10/fs/ocfs2/file.c linux-3.6.10-vs2.3.4.5/fs/ocfs2/file.c
5701 --- linux-3.6.10/fs/ocfs2/file.c        2012-10-04 15:27:41.000000000 +0200
5702 +++ linux-3.6.10-vs2.3.4.5/fs/ocfs2/file.c      2012-10-04 18:47:00.000000000 +0200
5703 @@ -1123,7 +1123,7 @@ int ocfs2_setattr(struct dentry *dentry,
5704                 attr->ia_valid &= ~ATTR_SIZE;
5705  
5706  #define OCFS2_VALID_ATTRS (ATTR_ATIME | ATTR_MTIME | ATTR_CTIME | ATTR_SIZE \
5707 -                          | ATTR_GID | ATTR_UID | ATTR_MODE)
5708 +                          | ATTR_GID | ATTR_UID | ATTR_TAG | ATTR_MODE)
5709         if (!(attr->ia_valid & OCFS2_VALID_ATTRS))
5710                 return 0;
5711  
5712 diff -NurpP --minimal linux-3.6.10/fs/ocfs2/inode.c linux-3.6.10-vs2.3.4.5/fs/ocfs2/inode.c
5713 --- linux-3.6.10/fs/ocfs2/inode.c       2012-07-22 23:39:41.000000000 +0200
5714 +++ linux-3.6.10-vs2.3.4.5/fs/ocfs2/inode.c     2012-10-04 18:47:00.000000000 +0200
5715 @@ -28,6 +28,7 @@
5716  #include <linux/highmem.h>
5717  #include <linux/pagemap.h>
5718  #include <linux/quotaops.h>
5719 +#include <linux/vs_tag.h>
5720  
5721  #include <asm/byteorder.h>
5722  
5723 @@ -78,11 +79,13 @@ void ocfs2_set_inode_flags(struct inode 
5724  {
5725         unsigned int flags = OCFS2_I(inode)->ip_attr;
5726  
5727 -       inode->i_flags &= ~(S_IMMUTABLE |
5728 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
5729                 S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
5730  
5731         if (flags & OCFS2_IMMUTABLE_FL)
5732                 inode->i_flags |= S_IMMUTABLE;
5733 +       if (flags & OCFS2_IXUNLINK_FL)
5734 +               inode->i_flags |= S_IXUNLINK;
5735  
5736         if (flags & OCFS2_SYNC_FL)
5737                 inode->i_flags |= S_SYNC;
5738 @@ -92,25 +95,44 @@ void ocfs2_set_inode_flags(struct inode 
5739                 inode->i_flags |= S_NOATIME;
5740         if (flags & OCFS2_DIRSYNC_FL)
5741                 inode->i_flags |= S_DIRSYNC;
5742 +
5743 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
5744 +
5745 +       if (flags & OCFS2_BARRIER_FL)
5746 +               inode->i_vflags |= V_BARRIER;
5747 +       if (flags & OCFS2_COW_FL)
5748 +               inode->i_vflags |= V_COW;
5749  }
5750  
5751  /* Propagate flags from i_flags to OCFS2_I(inode)->ip_attr */
5752  void ocfs2_get_inode_flags(struct ocfs2_inode_info *oi)
5753  {
5754         unsigned int flags = oi->vfs_inode.i_flags;
5755 +       unsigned int vflags = oi->vfs_inode.i_vflags;
5756 +
5757 +       oi->ip_attr &= ~(OCFS2_SYNC_FL | OCFS2_APPEND_FL |
5758 +                       OCFS2_IMMUTABLE_FL | OCFS2_IXUNLINK_FL |
5759 +                       OCFS2_NOATIME_FL | OCFS2_DIRSYNC_FL |
5760 +                       OCFS2_BARRIER_FL | OCFS2_COW_FL);
5761 +
5762 +       if (flags & S_IMMUTABLE)
5763 +               oi->ip_attr |= OCFS2_IMMUTABLE_FL;
5764 +       if (flags & S_IXUNLINK)
5765 +               oi->ip_attr |= OCFS2_IXUNLINK_FL;
5766  
5767 -       oi->ip_attr &= ~(OCFS2_SYNC_FL|OCFS2_APPEND_FL|
5768 -                       OCFS2_IMMUTABLE_FL|OCFS2_NOATIME_FL|OCFS2_DIRSYNC_FL);
5769         if (flags & S_SYNC)
5770                 oi->ip_attr |= OCFS2_SYNC_FL;
5771         if (flags & S_APPEND)
5772                 oi->ip_attr |= OCFS2_APPEND_FL;
5773 -       if (flags & S_IMMUTABLE)
5774 -               oi->ip_attr |= OCFS2_IMMUTABLE_FL;
5775         if (flags & S_NOATIME)
5776                 oi->ip_attr |= OCFS2_NOATIME_FL;
5777         if (flags & S_DIRSYNC)
5778                 oi->ip_attr |= OCFS2_DIRSYNC_FL;
5779 +
5780 +       if (vflags & V_BARRIER)
5781 +               oi->ip_attr |= OCFS2_BARRIER_FL;
5782 +       if (vflags & V_COW)
5783 +               oi->ip_attr |= OCFS2_COW_FL;
5784  }
5785  
5786  struct inode *ocfs2_ilookup(struct super_block *sb, u64 blkno)
5787 @@ -241,6 +263,8 @@ void ocfs2_populate_inode(struct inode *
5788         struct super_block *sb;
5789         struct ocfs2_super *osb;
5790         int use_plocks = 1;
5791 +       uid_t uid;
5792 +       gid_t gid;
5793  
5794         sb = inode->i_sb;
5795         osb = OCFS2_SB(sb);
5796 @@ -269,8 +293,12 @@ void ocfs2_populate_inode(struct inode *
5797         inode->i_generation = le32_to_cpu(fe->i_generation);
5798         inode->i_rdev = huge_decode_dev(le64_to_cpu(fe->id1.dev1.i_rdev));
5799         inode->i_mode = le16_to_cpu(fe->i_mode);
5800 -       inode->i_uid = le32_to_cpu(fe->i_uid);
5801 -       inode->i_gid = le32_to_cpu(fe->i_gid);
5802 +       uid = le32_to_cpu(fe->i_uid);
5803 +       gid = le32_to_cpu(fe->i_gid);
5804 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
5805 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
5806 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid,
5807 +               /* le16_to_cpu(raw_inode->i_raw_tag)i */ 0);
5808  
5809         /* Fast symlinks will have i_size but no allocated clusters. */
5810         if (S_ISLNK(inode->i_mode) && !fe->i_clusters) {
5811 diff -NurpP --minimal linux-3.6.10/fs/ocfs2/inode.h linux-3.6.10-vs2.3.4.5/fs/ocfs2/inode.h
5812 --- linux-3.6.10/fs/ocfs2/inode.h       2012-01-09 16:14:55.000000000 +0100
5813 +++ linux-3.6.10-vs2.3.4.5/fs/ocfs2/inode.h     2012-10-04 18:47:00.000000000 +0200
5814 @@ -154,6 +154,7 @@ struct buffer_head *ocfs2_bread(struct i
5815  
5816  void ocfs2_set_inode_flags(struct inode *inode);
5817  void ocfs2_get_inode_flags(struct ocfs2_inode_info *oi);
5818 +int ocfs2_sync_flags(struct inode *inode, int, int);
5819  
5820  static inline blkcnt_t ocfs2_inode_sector_count(struct inode *inode)
5821  {
5822 diff -NurpP --minimal linux-3.6.10/fs/ocfs2/ioctl.c linux-3.6.10-vs2.3.4.5/fs/ocfs2/ioctl.c
5823 --- linux-3.6.10/fs/ocfs2/ioctl.c       2012-10-04 15:27:41.000000000 +0200
5824 +++ linux-3.6.10-vs2.3.4.5/fs/ocfs2/ioctl.c     2012-10-04 18:47:00.000000000 +0200
5825 @@ -76,7 +76,41 @@ static int ocfs2_get_inode_attr(struct i
5826         return status;
5827  }
5828  
5829 -static int ocfs2_set_inode_attr(struct inode *inode, unsigned flags,
5830 +int ocfs2_sync_flags(struct inode *inode, int flags, int vflags)
5831 +{
5832 +       struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
5833 +       struct buffer_head *bh = NULL;
5834 +       handle_t *handle = NULL;
5835 +       int status;
5836 +
5837 +       status = ocfs2_inode_lock(inode, &bh, 1);
5838 +       if (status < 0) {
5839 +               mlog_errno(status);
5840 +               return status;
5841 +       }
5842 +       handle = ocfs2_start_trans(osb, OCFS2_INODE_UPDATE_CREDITS);
5843 +       if (IS_ERR(handle)) {
5844 +               status = PTR_ERR(handle);
5845 +               mlog_errno(status);
5846 +               goto bail_unlock;
5847 +       }
5848 +
5849 +       inode->i_flags = flags;
5850 +       inode->i_vflags = vflags;
5851 +       ocfs2_get_inode_flags(OCFS2_I(inode));
5852 +
5853 +       status = ocfs2_mark_inode_dirty(handle, inode, bh);
5854 +       if (status < 0)
5855 +               mlog_errno(status);
5856 +
5857 +       ocfs2_commit_trans(osb, handle);
5858 +bail_unlock:
5859 +       ocfs2_inode_unlock(inode, 1);
5860 +       brelse(bh);
5861 +       return status;
5862 +}
5863 +
5864 +int ocfs2_set_inode_attr(struct inode *inode, unsigned flags,
5865                                 unsigned mask)
5866  {
5867         struct ocfs2_inode_info *ocfs2_inode = OCFS2_I(inode);
5868 @@ -101,6 +135,11 @@ static int ocfs2_set_inode_attr(struct i
5869         if (!S_ISDIR(inode->i_mode))
5870                 flags &= ~OCFS2_DIRSYNC_FL;
5871  
5872 +       if (IS_BARRIER(inode)) {
5873 +               vxwprintk_task(1, "messing with the barrier.");
5874 +               goto bail_unlock;
5875 +       }
5876 +
5877         handle = ocfs2_start_trans(osb, OCFS2_INODE_UPDATE_CREDITS);
5878         if (IS_ERR(handle)) {
5879                 status = PTR_ERR(handle);
5880 @@ -879,6 +918,7 @@ bail:
5881         return status;
5882  }
5883  
5884 +
5885  long ocfs2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
5886  {
5887         struct inode *inode = filp->f_path.dentry->d_inode;
5888 diff -NurpP --minimal linux-3.6.10/fs/ocfs2/namei.c linux-3.6.10-vs2.3.4.5/fs/ocfs2/namei.c
5889 --- linux-3.6.10/fs/ocfs2/namei.c       2012-10-04 15:27:41.000000000 +0200
5890 +++ linux-3.6.10-vs2.3.4.5/fs/ocfs2/namei.c     2012-10-04 18:47:00.000000000 +0200
5891 @@ -41,6 +41,7 @@
5892  #include <linux/slab.h>
5893  #include <linux/highmem.h>
5894  #include <linux/quotaops.h>
5895 +#include <linux/vs_tag.h>
5896  
5897  #include <cluster/masklog.h>
5898  
5899 @@ -475,6 +476,7 @@ static int __ocfs2_mknod_locked(struct i
5900         struct ocfs2_dinode *fe = NULL;
5901         struct ocfs2_extent_list *fel;
5902         u16 feat;
5903 +       tag_t tag;
5904  
5905         *new_fe_bh = NULL;
5906  
5907 @@ -512,8 +514,11 @@ static int __ocfs2_mknod_locked(struct i
5908         fe->i_suballoc_loc = cpu_to_le64(suballoc_loc);
5909         fe->i_suballoc_bit = cpu_to_le16(suballoc_bit);
5910         fe->i_suballoc_slot = cpu_to_le16(inode_ac->ac_alloc_slot);
5911 -       fe->i_uid = cpu_to_le32(inode->i_uid);
5912 -       fe->i_gid = cpu_to_le32(inode->i_gid);
5913 +
5914 +       tag = dx_current_fstag(osb->sb);
5915 +       fe->i_uid = cpu_to_le32(TAGINO_UID(DX_TAG(inode), inode->i_uid, tag));
5916 +       fe->i_gid = cpu_to_le32(TAGINO_GID(DX_TAG(inode), inode->i_gid, tag));
5917 +       inode->i_tag = tag;
5918         fe->i_mode = cpu_to_le16(inode->i_mode);
5919         if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode))
5920                 fe->id1.dev1.i_rdev = cpu_to_le64(huge_encode_dev(dev));
5921 diff -NurpP --minimal linux-3.6.10/fs/ocfs2/ocfs2.h linux-3.6.10-vs2.3.4.5/fs/ocfs2/ocfs2.h
5922 --- linux-3.6.10/fs/ocfs2/ocfs2.h       2012-01-09 16:14:55.000000000 +0100
5923 +++ linux-3.6.10-vs2.3.4.5/fs/ocfs2/ocfs2.h     2012-10-04 18:47:00.000000000 +0200
5924 @@ -272,6 +272,7 @@ enum ocfs2_mount_options
5925                                                      writes */
5926         OCFS2_MOUNT_HB_NONE = 1 << 13, /* No heartbeat */
5927         OCFS2_MOUNT_HB_GLOBAL = 1 << 14, /* Global heartbeat */
5928 +       OCFS2_MOUNT_TAGGED = 1 << 15, /* use tagging */
5929  };
5930  
5931  #define OCFS2_OSB_SOFT_RO                      0x0001
5932 diff -NurpP --minimal linux-3.6.10/fs/ocfs2/ocfs2_fs.h linux-3.6.10-vs2.3.4.5/fs/ocfs2/ocfs2_fs.h
5933 --- linux-3.6.10/fs/ocfs2/ocfs2_fs.h    2011-05-22 16:17:53.000000000 +0200
5934 +++ linux-3.6.10-vs2.3.4.5/fs/ocfs2/ocfs2_fs.h  2012-10-04 18:47:00.000000000 +0200
5935 @@ -266,6 +266,11 @@
5936  #define OCFS2_TOPDIR_FL                        FS_TOPDIR_FL    /* Top of directory hierarchies*/
5937  #define OCFS2_RESERVED_FL              FS_RESERVED_FL  /* reserved for ext2 lib */
5938  
5939 +#define OCFS2_IXUNLINK_FL              FS_IXUNLINK_FL  /* Immutable invert on unlink */
5940 +
5941 +#define OCFS2_BARRIER_FL               FS_BARRIER_FL   /* Barrier for chroot() */
5942 +#define OCFS2_COW_FL                   FS_COW_FL       /* Copy on Write marker */
5943 +
5944  #define OCFS2_FL_VISIBLE               FS_FL_USER_VISIBLE      /* User visible flags */
5945  #define OCFS2_FL_MODIFIABLE            FS_FL_USER_MODIFIABLE   /* User modifiable flags */
5946  
5947 diff -NurpP --minimal linux-3.6.10/fs/ocfs2/super.c linux-3.6.10-vs2.3.4.5/fs/ocfs2/super.c
5948 --- linux-3.6.10/fs/ocfs2/super.c       2012-05-21 18:07:26.000000000 +0200
5949 +++ linux-3.6.10-vs2.3.4.5/fs/ocfs2/super.c     2012-10-04 18:47:00.000000000 +0200
5950 @@ -185,6 +185,7 @@ enum {
5951         Opt_coherency_full,
5952         Opt_resv_level,
5953         Opt_dir_resv_level,
5954 +       Opt_tag, Opt_notag, Opt_tagid,
5955         Opt_err,
5956  };
5957  
5958 @@ -216,6 +217,9 @@ static const match_table_t tokens = {
5959         {Opt_coherency_full, "coherency=full"},
5960         {Opt_resv_level, "resv_level=%u"},
5961         {Opt_dir_resv_level, "dir_resv_level=%u"},
5962 +       {Opt_tag, "tag"},
5963 +       {Opt_notag, "notag"},
5964 +       {Opt_tagid, "tagid=%u"},
5965         {Opt_err, NULL}
5966  };
5967  
5968 @@ -662,6 +666,13 @@ static int ocfs2_remount(struct super_bl
5969                 goto out;
5970         }
5971  
5972 +       if ((osb->s_mount_opt & OCFS2_MOUNT_TAGGED) !=
5973 +           (parsed_options.mount_opt & OCFS2_MOUNT_TAGGED)) {
5974 +               ret = -EINVAL;
5975 +               mlog(ML_ERROR, "Cannot change tagging on remount\n");
5976 +               goto out;
5977 +       }
5978 +
5979         /* We're going to/from readonly mode. */
5980         if ((*flags & MS_RDONLY) != (sb->s_flags & MS_RDONLY)) {
5981                 /* Disable quota accounting before remounting RO */
5982 @@ -1177,6 +1188,9 @@ static int ocfs2_fill_super(struct super
5983  
5984         ocfs2_complete_mount_recovery(osb);
5985  
5986 +       if (osb->s_mount_opt & OCFS2_MOUNT_TAGGED)
5987 +               sb->s_flags |= MS_TAGGED;
5988 +
5989         if (ocfs2_mount_local(osb))
5990                 snprintf(nodestr, sizeof(nodestr), "local");
5991         else
5992 @@ -1503,6 +1517,20 @@ static int ocfs2_parse_options(struct su
5993                             option < OCFS2_MAX_RESV_LEVEL)
5994                                 mopt->dir_resv_level = option;
5995                         break;
5996 +#ifndef CONFIG_TAGGING_NONE
5997 +               case Opt_tag:
5998 +                       mopt->mount_opt |= OCFS2_MOUNT_TAGGED;
5999 +                       break;
6000 +               case Opt_notag:
6001 +                       mopt->mount_opt &= ~OCFS2_MOUNT_TAGGED;
6002 +                       break;
6003 +#endif
6004 +#ifdef CONFIG_PROPAGATE
6005 +               case Opt_tagid:
6006 +                       /* use args[0] */
6007 +                       mopt->mount_opt |= OCFS2_MOUNT_TAGGED;
6008 +                       break;
6009 +#endif
6010                 default:
6011                         mlog(ML_ERROR,
6012                              "Unrecognized mount option \"%s\" "
6013 diff -NurpP --minimal linux-3.6.10/fs/open.c linux-3.6.10-vs2.3.4.5/fs/open.c
6014 --- linux-3.6.10/fs/open.c      2012-10-04 15:27:41.000000000 +0200
6015 +++ linux-3.6.10-vs2.3.4.5/fs/open.c    2012-10-04 18:47:00.000000000 +0200
6016 @@ -30,6 +30,11 @@
6017  #include <linux/fs_struct.h>
6018  #include <linux/ima.h>
6019  #include <linux/dnotify.h>
6020 +#include <linux/vs_base.h>
6021 +#include <linux/vs_limit.h>
6022 +#include <linux/vs_tag.h>
6023 +#include <linux/vs_cowbl.h>
6024 +#include <linux/vserver/dlimit.h>
6025  
6026  #include "internal.h"
6027  
6028 @@ -74,6 +79,12 @@ static long do_sys_truncate(const char _
6029         error = user_path(pathname, &path);
6030         if (error)
6031                 goto out;
6032 +
6033 +#ifdef CONFIG_VSERVER_COWBL
6034 +       error = cow_check_and_break(&path);
6035 +       if (error)
6036 +               goto dput_and_out;
6037 +#endif
6038         inode = path.dentry->d_inode;
6039  
6040         /* For directories it's -EISDIR, for other non-regulars - -EINVAL */
6041 @@ -495,6 +506,10 @@ SYSCALL_DEFINE3(fchmodat, int, dfd, cons
6042  
6043         error = user_path_at(dfd, filename, LOOKUP_FOLLOW, &path);
6044         if (!error) {
6045 +#ifdef CONFIG_VSERVER_COWBL
6046 +               error = cow_check_and_break(&path);
6047 +               if (!error)
6048 +#endif
6049                 error = chmod_common(&path, mode);
6050                 path_put(&path);
6051         }
6052 @@ -522,13 +537,13 @@ static int chown_common(struct path *pat
6053                 if (!uid_valid(uid))
6054                         return -EINVAL;
6055                 newattrs.ia_valid |= ATTR_UID;
6056 -               newattrs.ia_uid = uid;
6057 +               newattrs.ia_uid = dx_map_uid(user);
6058         }
6059         if (group != (gid_t) -1) {
6060                 if (!gid_valid(gid))
6061                         return -EINVAL;
6062                 newattrs.ia_valid |= ATTR_GID;
6063 -               newattrs.ia_gid = gid;
6064 +               newattrs.ia_gid = dx_map_gid(group);
6065         }
6066         if (!S_ISDIR(inode->i_mode))
6067                 newattrs.ia_valid |=
6068 @@ -561,6 +576,18 @@ SYSCALL_DEFINE5(fchownat, int, dfd, cons
6069         error = mnt_want_write(path.mnt);
6070         if (error)
6071                 goto out_release;
6072 +#ifdef CONFIG_VSERVER_COWBL
6073 +       error = cow_check_and_break(&path);
6074 +       if (!error)
6075 +#endif
6076 +#ifdef CONFIG_VSERVER_COWBL
6077 +       error = cow_check_and_break(&path);
6078 +       if (!error)
6079 +#endif
6080 +#ifdef CONFIG_VSERVER_COWBL
6081 +       error = cow_check_and_break(&path);
6082 +       if (!error)
6083 +#endif
6084         error = chown_common(&path, user, group);
6085         mnt_drop_write(path.mnt);
6086  out_release:
6087 @@ -809,6 +836,7 @@ static void __put_unused_fd(struct files
6088         __clear_open_fd(fd, fdt);
6089         if (fd < files->next_fd)
6090                 files->next_fd = fd;
6091 +       vx_openfd_dec(fd);
6092  }
6093  
6094  void put_unused_fd(unsigned int fd)
6095 diff -NurpP --minimal linux-3.6.10/fs/proc/array.c linux-3.6.10-vs2.3.4.5/fs/proc/array.c
6096 --- linux-3.6.10/fs/proc/array.c        2012-07-22 23:39:42.000000000 +0200
6097 +++ linux-3.6.10-vs2.3.4.5/fs/proc/array.c      2012-10-04 18:47:00.000000000 +0200
6098 @@ -82,6 +82,8 @@
6099  #include <linux/ptrace.h>
6100  #include <linux/tracehook.h>
6101  #include <linux/user_namespace.h>
6102 +#include <linux/vs_context.h>
6103 +#include <linux/vs_network.h>
6104  
6105  #include <asm/pgtable.h>
6106  #include <asm/processor.h>
6107 @@ -172,6 +174,9 @@ static inline void task_state(struct seq
6108         rcu_read_lock();
6109         ppid = pid_alive(p) ?
6110                 task_tgid_nr_ns(rcu_dereference(p->real_parent), ns) : 0;
6111 +       if (unlikely(vx_current_initpid(p->pid)))
6112 +               ppid = 0;
6113 +
6114         tpid = 0;
6115         if (pid_alive(p)) {
6116                 struct task_struct *tracer = ptrace_parent(p);
6117 @@ -296,7 +301,7 @@ static inline void task_sig(struct seq_f
6118  }
6119  
6120  static void render_cap_t(struct seq_file *m, const char *header,
6121 -                       kernel_cap_t *a)
6122 +                       struct vx_info *vxi, kernel_cap_t *a)
6123  {
6124         unsigned __capi;
6125  
6126 @@ -321,10 +326,11 @@ static inline void task_cap(struct seq_f
6127         cap_bset        = cred->cap_bset;
6128         rcu_read_unlock();
6129  
6130 -       render_cap_t(m, "CapInh:\t", &cap_inheritable);
6131 -       render_cap_t(m, "CapPrm:\t", &cap_permitted);
6132 -       render_cap_t(m, "CapEff:\t", &cap_effective);
6133 -       render_cap_t(m, "CapBnd:\t", &cap_bset);
6134 +       /* FIXME: maybe move the p->vx_info masking to __task_cred() ? */
6135 +       render_cap_t(m, "CapInh:\t", p->vx_info, &cap_inheritable);
6136 +       render_cap_t(m, "CapPrm:\t", p->vx_info, &cap_permitted);
6137 +       render_cap_t(m, "CapEff:\t", p->vx_info, &cap_effective);
6138 +       render_cap_t(m, "CapBnd:\t", p->vx_info, &cap_bset);
6139  }
6140  
6141  static inline void task_context_switch_counts(struct seq_file *m,
6142 @@ -346,6 +352,42 @@ static void task_cpus_allowed(struct seq
6143         seq_putc(m, '\n');
6144  }
6145  
6146 +int proc_pid_nsproxy(struct seq_file *m, struct pid_namespace *ns,
6147 +                       struct pid *pid, struct task_struct *task)
6148 +{
6149 +       seq_printf(m,   "Proxy:\t%p(%c)\n"
6150 +                       "Count:\t%u\n"
6151 +                       "uts:\t%p(%c)\n"
6152 +                       "ipc:\t%p(%c)\n"
6153 +                       "mnt:\t%p(%c)\n"
6154 +                       "pid:\t%p(%c)\n"
6155 +                       "net:\t%p(%c)\n",
6156 +                       task->nsproxy,
6157 +                       (task->nsproxy == init_task.nsproxy ? 'I' : '-'),
6158 +                       atomic_read(&task->nsproxy->count),
6159 +                       task->nsproxy->uts_ns,
6160 +                       (task->nsproxy->uts_ns == init_task.nsproxy->uts_ns ? 'I' : '-'),
6161 +                       task->nsproxy->ipc_ns,
6162 +                       (task->nsproxy->ipc_ns == init_task.nsproxy->ipc_ns ? 'I' : '-'),
6163 +                       task->nsproxy->mnt_ns,
6164 +                       (task->nsproxy->mnt_ns == init_task.nsproxy->mnt_ns ? 'I' : '-'),
6165 +                       task->nsproxy->pid_ns,
6166 +                       (task->nsproxy->pid_ns == init_task.nsproxy->pid_ns ? 'I' : '-'),
6167 +                       task->nsproxy->net_ns,
6168 +                       (task->nsproxy->net_ns == init_task.nsproxy->net_ns ? 'I' : '-'));
6169 +       return 0;
6170 +}
6171 +
6172 +void task_vs_id(struct seq_file *m, struct task_struct *task)
6173 +{
6174 +       if (task_vx_flags(task, VXF_HIDE_VINFO, 0))
6175 +               return;
6176 +
6177 +       seq_printf(m, "VxID: %d\n", vx_task_xid(task));
6178 +       seq_printf(m, "NxID: %d\n", nx_task_nid(task));
6179 +}
6180 +
6181 +
6182  int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
6183                         struct pid *pid, struct task_struct *task)
6184  {
6185 @@ -362,6 +404,7 @@ int proc_pid_status(struct seq_file *m, 
6186         task_cap(m, task);
6187         task_cpus_allowed(m, task);
6188         cpuset_task_status_allowed(m, task);
6189 +       task_vs_id(m, task);
6190         task_context_switch_counts(m, task);
6191         return 0;
6192  }
6193 @@ -471,6 +514,17 @@ static int do_task_stat(struct seq_file 
6194         /* convert nsec -> ticks */
6195         start_time = nsec_to_clock_t(start_time);
6196  
6197 +       /* fixup start time for virt uptime */
6198 +       if (vx_flags(VXF_VIRT_UPTIME, 0)) {
6199 +               unsigned long long bias =
6200 +                       current->vx_info->cvirt.bias_clock;
6201 +
6202 +               if (start_time > bias)
6203 +                       start_time -= bias;
6204 +               else
6205 +                       start_time = 0;
6206 +       }
6207 +
6208         seq_printf(m, "%d (%s) %c", pid_nr_ns(pid, ns), tcomm, state);
6209         seq_put_decimal_ll(m, ' ', ppid);
6210         seq_put_decimal_ll(m, ' ', pgid);
6211 diff -NurpP --minimal linux-3.6.10/fs/proc/base.c linux-3.6.10-vs2.3.4.5/fs/proc/base.c
6212 --- linux-3.6.10/fs/proc/base.c 2012-10-04 15:27:41.000000000 +0200
6213 +++ linux-3.6.10-vs2.3.4.5/fs/proc/base.c       2012-10-04 18:47:00.000000000 +0200
6214 @@ -85,6 +85,8 @@
6215  #include <linux/fs_struct.h>
6216  #include <linux/slab.h>
6217  #include <linux/flex_array.h>
6218 +#include <linux/vs_context.h>
6219 +#include <linux/vs_network.h>
6220  #ifdef CONFIG_HARDWALL
6221  #include <asm/hardwall.h>
6222  #endif
6223 @@ -941,11 +943,16 @@ static ssize_t oom_adjust_write(struct f
6224                 goto err_task_lock;
6225         }
6226  
6227 -       if (oom_adjust < task->signal->oom_adj && !capable(CAP_SYS_RESOURCE)) {
6228 +       if (oom_adjust < task->signal->oom_adj &&
6229 +               !vx_capable(CAP_SYS_RESOURCE, VXC_OOM_ADJUST)) {
6230                 err = -EACCES;
6231                 goto err_sighand;
6232         }
6233  
6234 +       /* prevent guest processes from circumventing the oom killer */
6235 +       if (vx_current_xid() && (oom_adjust == OOM_DISABLE))
6236 +               oom_adjust = OOM_ADJUST_MIN;
6237 +
6238         /*
6239          * Warn that /proc/pid/oom_adj is deprecated, see
6240          * Documentation/feature-removal-schedule.txt.
6241 @@ -1548,6 +1555,8 @@ struct inode *proc_pid_make_inode(struct
6242                 inode->i_gid = cred->egid;
6243                 rcu_read_unlock();
6244         }
6245 +       /* procfs is xid tagged */
6246 +       inode->i_tag = (tag_t)vx_task_xid(task);
6247         security_task_to_inode(task, inode);
6248  
6249  out:
6250 @@ -1593,6 +1602,8 @@ int pid_getattr(struct vfsmount *mnt, st
6251  
6252  /* dentry stuff */
6253  
6254 +static unsigned name_to_int(struct dentry *dentry);
6255 +
6256  /*
6257   *     Exceptional case: normally we are not allowed to unhash a busy
6258   * directory. In this case, however, we can do it - no aliasing problems
6259 @@ -1621,6 +1632,12 @@ int pid_revalidate(struct dentry *dentry
6260         task = get_proc_task(inode);
6261  
6262         if (task) {
6263 +               unsigned pid = name_to_int(dentry);
6264 +
6265 +               if (pid != ~0U && pid != vx_map_pid(task->pid)) {
6266 +                       put_task_struct(task);
6267 +                       goto drop;
6268 +               }
6269                 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
6270                     task_dumpable(task)) {
6271                         rcu_read_lock();
6272 @@ -1637,6 +1654,7 @@ int pid_revalidate(struct dentry *dentry
6273                 put_task_struct(task);
6274                 return 1;
6275         }
6276 +drop:
6277         d_drop(dentry);
6278         return 0;
6279  }
6280 @@ -2457,6 +2475,13 @@ static struct dentry *proc_pident_lookup
6281         if (!task)
6282                 goto out_no_task;
6283  
6284 +       /* TODO: maybe we can come up with a generic approach? */
6285 +       if (task_vx_flags(task, VXF_HIDE_VINFO, 0) &&
6286 +               (dentry->d_name.len == 5) &&
6287 +               (!memcmp(dentry->d_name.name, "vinfo", 5) ||
6288 +               !memcmp(dentry->d_name.name, "ninfo", 5)))
6289 +               goto out;
6290 +
6291         /*
6292          * Yes, it does not scale. And it should not. Don't add
6293          * new entries into /proc/<tgid>/ without very good reasons.
6294 @@ -2842,7 +2867,7 @@ out_iput:
6295  static struct dentry *proc_base_lookup(struct inode *dir, struct dentry *dentry)
6296  {
6297         struct dentry *error;
6298 -       struct task_struct *task = get_proc_task(dir);
6299 +       struct task_struct *task = get_proc_task_real(dir);
6300         const struct pid_entry *p, *last;
6301  
6302         error = ERR_PTR(-ENOENT);
6303 @@ -3017,6 +3042,9 @@ static int proc_pid_personality(struct s
6304  static const struct file_operations proc_task_operations;
6305  static const struct inode_operations proc_task_inode_operations;
6306  
6307 +extern int proc_pid_vx_info(struct task_struct *, char *);
6308 +extern int proc_pid_nx_info(struct task_struct *, char *);
6309 +
6310  static const struct pid_entry tgid_base_stuff[] = {
6311         DIR("task",       S_IRUGO|S_IXUGO, proc_task_inode_operations, proc_task_operations),
6312         DIR("fd",         S_IRUSR|S_IXUSR, proc_fd_inode_operations, proc_fd_operations),
6313 @@ -3083,6 +3111,8 @@ static const struct pid_entry tgid_base_
6314  #ifdef CONFIG_CGROUPS
6315         REG("cgroup",  S_IRUGO, proc_cgroup_operations),
6316  #endif
6317 +       INF("vinfo",      S_IRUGO, proc_pid_vx_info),
6318 +       INF("ninfo",      S_IRUGO, proc_pid_nx_info),
6319         INF("oom_score",  S_IRUGO, proc_oom_score),
6320         REG("oom_adj",    S_IRUGO|S_IWUSR, proc_oom_adjust_operations),
6321         REG("oom_score_adj", S_IRUGO|S_IWUSR, proc_oom_score_adj_operations),
6322 @@ -3106,6 +3136,7 @@ static const struct pid_entry tgid_base_
6323         REG("uid_map",    S_IRUGO|S_IWUSR, proc_uid_map_operations),
6324         REG("gid_map",    S_IRUGO|S_IWUSR, proc_gid_map_operations),
6325  #endif
6326 +       ONE("nsproxy",  S_IRUGO, proc_pid_nsproxy),
6327  };
6328  
6329  static int proc_tgid_base_readdir(struct file * filp,
6330 @@ -3300,7 +3331,7 @@ retry:
6331         iter.task = NULL;
6332         pid = find_ge_pid(iter.tgid, ns);
6333         if (pid) {
6334 -               iter.tgid = pid_nr_ns(pid, ns);
6335 +               iter.tgid = pid_unmapped_nr_ns(pid, ns);
6336                 iter.task = pid_task(pid, PIDTYPE_PID);
6337                 /* What we to know is if the pid we have find is the
6338                  * pid of a thread_group_leader.  Testing for task
6339 @@ -3330,7 +3361,7 @@ static int proc_pid_fill_cache(struct fi
6340         struct tgid_iter iter)
6341  {
6342         char name[PROC_NUMBUF];
6343 -       int len = snprintf(name, sizeof(name), "%d", iter.tgid);
6344 +       int len = snprintf(name, sizeof(name), "%d", vx_map_tgid(iter.tgid));
6345         return proc_fill_cache(filp, dirent, filldir, name, len,
6346                                 proc_pid_instantiate, iter.task, NULL);
6347  }
6348 @@ -3354,7 +3385,7 @@ int proc_pid_readdir(struct file * filp,
6349                 goto out_no_task;
6350         nr = filp->f_pos - FIRST_PROCESS_ENTRY;
6351  
6352 -       reaper = get_proc_task(filp->f_path.dentry->d_inode);
6353 +       reaper = get_proc_task_real(filp->f_path.dentry->d_inode);
6354         if (!reaper)
6355                 goto out_no_task;
6356  
6357 @@ -3376,6 +3407,8 @@ int proc_pid_readdir(struct file * filp,
6358                         __filldir = fake_filldir;
6359  
6360                 filp->f_pos = iter.tgid + TGID_OFFSET;
6361 +               if (!vx_proc_task_visible(iter.task))
6362 +                       continue;
6363                 if (proc_pid_fill_cache(filp, dirent, __filldir, iter) < 0) {
6364                         put_task_struct(iter.task);
6365                         goto out;
6366 @@ -3537,6 +3570,8 @@ static struct dentry *proc_task_lookup(s
6367         tid = name_to_int(dentry);
6368         if (tid == ~0U)
6369                 goto out;
6370 +       if (vx_current_initpid(tid))
6371 +               goto out;
6372  
6373         ns = dentry->d_sb->s_fs_info;
6374         rcu_read_lock();
6375 diff -NurpP --minimal linux-3.6.10/fs/proc/generic.c linux-3.6.10-vs2.3.4.5/fs/proc/generic.c
6376 --- linux-3.6.10/fs/proc/generic.c      2012-10-04 15:27:41.000000000 +0200
6377 +++ linux-3.6.10-vs2.3.4.5/fs/proc/generic.c    2012-10-04 18:47:00.000000000 +0200
6378 @@ -22,6 +22,7 @@
6379  #include <linux/bitops.h>
6380  #include <linux/spinlock.h>
6381  #include <linux/completion.h>
6382 +#include <linux/vserver/inode.h>
6383  #include <asm/uaccess.h>
6384  
6385  #include "internal.h"
6386 @@ -424,11 +425,15 @@ struct dentry *proc_lookup_de(struct pro
6387         for (de = de->subdir; de ; de = de->next) {
6388                 if (de->namelen != dentry->d_name.len)
6389                         continue;
6390 +               if (!vx_hide_check(0, de->vx_flags))
6391 +                       continue;
6392                 if (!memcmp(dentry->d_name.name, de->name, de->namelen)) {
6393                         pde_get(de);
6394                         spin_unlock(&proc_subdir_lock);
6395                         error = -EINVAL;
6396                         inode = proc_get_inode(dir->i_sb, de);
6397 +                       /* generic proc entries belong to the host */
6398 +                       inode->i_tag = 0;
6399                         goto out_unlock;
6400                 }
6401         }
6402 @@ -506,6 +511,8 @@ int proc_readdir_de(struct proc_dir_entr
6403  
6404                                 /* filldir passes info to user space */
6405                                 pde_get(de);
6406 +                               if (!vx_hide_check(0, de->vx_flags))
6407 +                                       goto skip;
6408                                 spin_unlock(&proc_subdir_lock);
6409                                 if (filldir(dirent, de->name, de->namelen, filp->f_pos,
6410                                             de->low_ino, de->mode >> 12) < 0) {
6411 @@ -513,6 +520,7 @@ int proc_readdir_de(struct proc_dir_entr
6412                                         goto out;
6413                                 }
6414                                 spin_lock(&proc_subdir_lock);
6415 +                       skip:
6416                                 filp->f_pos++;
6417                                 next = de->next;
6418                                 pde_put(de);
6419 @@ -626,6 +634,7 @@ static struct proc_dir_entry *__proc_cre
6420         ent->nlink = nlink;
6421         atomic_set(&ent->count, 1);
6422         ent->pde_users = 0;
6423 +       ent->vx_flags = IATTR_PROC_DEFAULT;
6424         spin_lock_init(&ent->pde_unload_lock);
6425         ent->pde_unload_completion = NULL;
6426         INIT_LIST_HEAD(&ent->pde_openers);
6427 @@ -649,7 +658,8 @@ struct proc_dir_entry *proc_symlink(cons
6428                                 kfree(ent->data);
6429                                 kfree(ent);
6430                                 ent = NULL;
6431 -                       }
6432 +                       } else
6433 +                               ent->vx_flags = IATTR_PROC_SYMLINK;
6434                 } else {
6435                         kfree(ent);
6436                         ent = NULL;
6437 diff -NurpP --minimal linux-3.6.10/fs/proc/inode.c linux-3.6.10-vs2.3.4.5/fs/proc/inode.c
6438 --- linux-3.6.10/fs/proc/inode.c        2012-07-22 23:39:42.000000000 +0200
6439 +++ linux-3.6.10-vs2.3.4.5/fs/proc/inode.c      2012-10-04 18:47:00.000000000 +0200
6440 @@ -458,6 +458,8 @@ struct inode *proc_get_inode(struct supe
6441                         inode->i_uid = de->uid;
6442                         inode->i_gid = de->gid;
6443                 }
6444 +               if (de->vx_flags)
6445 +                       PROC_I(inode)->vx_flags = de->vx_flags;
6446                 if (de->size)
6447                         inode->i_size = de->size;
6448                 if (de->nlink)
6449 diff -NurpP --minimal linux-3.6.10/fs/proc/internal.h linux-3.6.10-vs2.3.4.5/fs/proc/internal.h
6450 --- linux-3.6.10/fs/proc/internal.h     2012-10-04 15:27:41.000000000 +0200
6451 +++ linux-3.6.10-vs2.3.4.5/fs/proc/internal.h   2012-10-04 18:47:00.000000000 +0200
6452 @@ -10,6 +10,8 @@
6453   */
6454  
6455  #include <linux/proc_fs.h>
6456 +#include <linux/vs_pid.h>
6457 +
6458  struct  ctl_table_header;
6459  
6460  extern struct proc_dir_entry proc_root;
6461 @@ -52,6 +54,9 @@ extern int proc_pid_status(struct seq_fi
6462                                 struct pid *pid, struct task_struct *task);
6463  extern int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
6464                                 struct pid *pid, struct task_struct *task);
6465 +extern int proc_pid_nsproxy(struct seq_file *m, struct pid_namespace *ns,
6466 +                               struct pid *pid, struct task_struct *task);
6467 +
6468  extern loff_t mem_lseek(struct file *file, loff_t offset, int orig);
6469  
6470  extern const struct file_operations proc_tid_children_operations;
6471 @@ -81,11 +86,16 @@ static inline struct pid *proc_pid(struc
6472         return PROC_I(inode)->pid;
6473  }
6474  
6475 -static inline struct task_struct *get_proc_task(struct inode *inode)
6476 +static inline struct task_struct *get_proc_task_real(struct inode *inode)
6477  {
6478         return get_pid_task(proc_pid(inode), PIDTYPE_PID);
6479  }
6480  
6481 +static inline struct task_struct *get_proc_task(struct inode *inode)
6482 +{
6483 +       return vx_get_proc_task(inode, proc_pid(inode));
6484 +}
6485 +
6486  static inline int proc_fd(struct inode *inode)
6487  {
6488         return PROC_I(inode)->fd;
6489 diff -NurpP --minimal linux-3.6.10/fs/proc/loadavg.c linux-3.6.10-vs2.3.4.5/fs/proc/loadavg.c
6490 --- linux-3.6.10/fs/proc/loadavg.c      2009-09-10 15:26:23.000000000 +0200
6491 +++ linux-3.6.10-vs2.3.4.5/fs/proc/loadavg.c    2012-10-04 18:47:00.000000000 +0200
6492 @@ -12,15 +12,27 @@
6493  
6494  static int loadavg_proc_show(struct seq_file *m, void *v)
6495  {
6496 +       unsigned long running;
6497 +       unsigned int threads;
6498         unsigned long avnrun[3];
6499  
6500         get_avenrun(avnrun, FIXED_1/200, 0);
6501  
6502 +       if (vx_flags(VXF_VIRT_LOAD, 0)) {
6503 +               struct vx_info *vxi = current_vx_info();
6504 +
6505 +               running = atomic_read(&vxi->cvirt.nr_running);
6506 +               threads = atomic_read(&vxi->cvirt.nr_threads);
6507 +       } else {
6508 +               running = nr_running();
6509 +               threads = nr_threads;
6510 +       }
6511 +
6512         seq_printf(m, "%lu.%02lu %lu.%02lu %lu.%02lu %ld/%d %d\n",
6513                 LOAD_INT(avnrun[0]), LOAD_FRAC(avnrun[0]),
6514                 LOAD_INT(avnrun[1]), LOAD_FRAC(avnrun[1]),
6515                 LOAD_INT(avnrun[2]), LOAD_FRAC(avnrun[2]),
6516 -               nr_running(), nr_threads,
6517 +               running, threads,
6518                 task_active_pid_ns(current)->last_pid);
6519         return 0;
6520  }
6521 diff -NurpP --minimal linux-3.6.10/fs/proc/meminfo.c linux-3.6.10-vs2.3.4.5/fs/proc/meminfo.c
6522 --- linux-3.6.10/fs/proc/meminfo.c      2012-01-09 16:14:55.000000000 +0100
6523 +++ linux-3.6.10-vs2.3.4.5/fs/proc/meminfo.c    2012-10-04 18:47:00.000000000 +0200
6524 @@ -39,7 +39,8 @@ static int meminfo_proc_show(struct seq_
6525         allowed = ((totalram_pages - hugetlb_total_pages())
6526                 * sysctl_overcommit_ratio / 100) + total_swap_pages;
6527  
6528 -       cached = global_page_state(NR_FILE_PAGES) -
6529 +       cached = vx_flags(VXF_VIRT_MEM, 0) ?
6530 +               vx_vsi_cached(&i) : global_page_state(NR_FILE_PAGES) -
6531                         total_swapcache_pages - i.bufferram;
6532         if (cached < 0)
6533                 cached = 0;
6534 diff -NurpP --minimal linux-3.6.10/fs/proc/root.c linux-3.6.10-vs2.3.4.5/fs/proc/root.c
6535 --- linux-3.6.10/fs/proc/root.c 2012-10-04 15:27:41.000000000 +0200
6536 +++ linux-3.6.10-vs2.3.4.5/fs/proc/root.c       2012-10-04 18:47:00.000000000 +0200
6537 @@ -19,9 +19,14 @@
6538  #include <linux/mount.h>
6539  #include <linux/pid_namespace.h>
6540  #include <linux/parser.h>
6541 +#include <linux/vserver/inode.h>
6542  
6543  #include "internal.h"
6544  
6545 +struct proc_dir_entry *proc_virtual;
6546 +
6547 +extern void proc_vx_init(void);
6548 +
6549  static int proc_test_super(struct super_block *sb, void *data)
6550  {
6551         return sb->s_fs_info == data;
6552 @@ -189,6 +194,7 @@ void __init proc_root_init(void)
6553  #endif
6554         proc_mkdir("bus", NULL);
6555         proc_sys_init();
6556 +       proc_vx_init();
6557  }
6558  
6559  static int proc_root_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat
6560 @@ -255,6 +261,7 @@ struct proc_dir_entry proc_root = {
6561         .proc_iops      = &proc_root_inode_operations, 
6562         .proc_fops      = &proc_root_operations,
6563         .parent         = &proc_root,
6564 +       .vx_flags       = IATTR_ADMIN | IATTR_WATCH,
6565         .name           = "/proc",
6566  };
6567  
6568 diff -NurpP --minimal linux-3.6.10/fs/proc/stat.c linux-3.6.10-vs2.3.4.5/fs/proc/stat.c
6569 --- linux-3.6.10/fs/proc/stat.c 2012-12-11 12:36:58.000000000 +0100
6570 +++ linux-3.6.10-vs2.3.4.5/fs/proc/stat.c       2012-11-06 18:43:41.000000000 +0100
6571 @@ -9,6 +9,7 @@
6572  #include <linux/slab.h>
6573  #include <linux/time.h>
6574  #include <linux/irqnr.h>
6575 +#include <linux/vserver/cvirt.h>
6576  #include <asm/cputime.h>
6577  #include <linux/tick.h>
6578  
6579 @@ -92,6 +93,10 @@ static int show_stat(struct seq_file *p,
6580                 irq = softirq = steal = 0;
6581         guest = guest_nice = 0;
6582         getboottime(&boottime);
6583 +
6584 +       if (vx_flags(VXF_VIRT_UPTIME, 0))
6585 +               vx_vsi_boottime(&boottime);
6586 +
6587         jif = boottime.tv_sec;
6588  
6589         for_each_possible_cpu(i) {
6590 diff -NurpP --minimal linux-3.6.10/fs/proc/uptime.c linux-3.6.10-vs2.3.4.5/fs/proc/uptime.c
6591 --- linux-3.6.10/fs/proc/uptime.c       2012-03-19 19:47:26.000000000 +0100
6592 +++ linux-3.6.10-vs2.3.4.5/fs/proc/uptime.c     2012-10-04 18:47:00.000000000 +0200
6593 @@ -5,6 +5,7 @@
6594  #include <linux/seq_file.h>
6595  #include <linux/time.h>
6596  #include <linux/kernel_stat.h>
6597 +#include <linux/vserver/cvirt.h>
6598  #include <asm/cputime.h>
6599  
6600  static int uptime_proc_show(struct seq_file *m, void *v)
6601 @@ -25,6 +26,10 @@ static int uptime_proc_show(struct seq_f
6602         nsec = cputime64_to_jiffies64(idletime) * TICK_NSEC;
6603         idle.tv_sec = div_u64_rem(nsec, NSEC_PER_SEC, &rem);
6604         idle.tv_nsec = rem;
6605 +
6606 +       if (vx_flags(VXF_VIRT_UPTIME, 0))
6607 +               vx_vsi_uptime(&uptime, &idle);
6608 +
6609         seq_printf(m, "%lu.%02lu %lu.%02lu\n",
6610                         (unsigned long) uptime.tv_sec,
6611                         (uptime.tv_nsec / (NSEC_PER_SEC / 100)),
6612 diff -NurpP --minimal linux-3.6.10/fs/proc_namespace.c linux-3.6.10-vs2.3.4.5/fs/proc_namespace.c
6613 --- linux-3.6.10/fs/proc_namespace.c    2012-10-04 15:27:41.000000000 +0200
6614 +++ linux-3.6.10-vs2.3.4.5/fs/proc_namespace.c  2012-12-10 18:17:40.000000000 +0100
6615 @@ -44,6 +44,8 @@ static int show_sb_opts(struct seq_file 
6616                 { MS_SYNCHRONOUS, ",sync" },
6617                 { MS_DIRSYNC, ",dirsync" },
6618                 { MS_MANDLOCK, ",mand" },
6619 +               { MS_TAGGED, ",tag" },
6620 +               { MS_NOTAGCHECK, ",notagcheck" },
6621                 { 0, NULL }
6622         };
6623         const struct proc_fs_info *fs_infop;
6624 @@ -80,6 +82,40 @@ static inline void mangle(struct seq_fil
6625         seq_escape(m, s, " \t\n\\");
6626  }
6627  
6628 +#ifdef CONFIG_VSERVER_EXTRA_MNT_CHECK
6629 +
6630 +static int mnt_is_reachable(struct vfsmount *vfsmnt)
6631 +{
6632 +       struct path root;
6633 +       struct dentry *point;
6634 +       struct mount *mnt = real_mount(vfsmnt);
6635 +       struct mount *root_mnt;
6636 +       int ret;
6637 +
6638 +       if (mnt == mnt->mnt_ns->root)
6639 +               return 1;
6640 +
6641 +       br_read_lock(&vfsmount_lock);
6642 +       root = current->fs->root;
6643 +       root_mnt = real_mount(root.mnt);
6644 +       point = root.dentry;
6645 +
6646 +       while ((mnt != mnt->mnt_parent) && (mnt != root_mnt)) {
6647 +               point = mnt->mnt_mountpoint;
6648 +               mnt = mnt->mnt_parent;
6649 +       }
6650 +
6651 +       ret = (mnt == root_mnt) && is_subdir(point, root.dentry);
6652 +
6653 +       br_read_unlock(&vfsmount_lock);
6654 +
6655 +       return ret;
6656 +}
6657 +
6658 +#else
6659 +#define        mnt_is_reachable(v)     (1)
6660 +#endif
6661 +
6662  static void show_type(struct seq_file *m, struct super_block *sb)
6663  {
6664         mangle(m, sb->s_type->name);
6665 @@ -96,6 +132,17 @@ static int show_vfsmnt(struct seq_file *
6666         struct path mnt_path = { .dentry = mnt->mnt_root, .mnt = mnt };
6667         struct super_block *sb = mnt_path.dentry->d_sb;
6668  
6669 +       if (vx_flags(VXF_HIDE_MOUNT, 0))
6670 +               return SEQ_SKIP;
6671 +       if (!mnt_is_reachable(mnt) && !vx_check(0, VS_WATCH_P))
6672 +               return SEQ_SKIP;
6673 +
6674 +       if (!vx_check(0, VS_ADMIN|VS_WATCH) &&
6675 +               mnt == current->fs->root.mnt) {
6676 +               seq_puts(m, "/dev/root / ");
6677 +               goto type;
6678 +       }
6679 +
6680         if (sb->s_op->show_devname) {
6681                 err = sb->s_op->show_devname(m, mnt_path.dentry);
6682                 if (err)
6683 @@ -106,6 +153,7 @@ static int show_vfsmnt(struct seq_file *
6684         seq_putc(m, ' ');
6685         seq_path(m, &mnt_path, " \t\n\\");
6686         seq_putc(m, ' ');
6687 +type:
6688         show_type(m, sb);
6689         seq_puts(m, __mnt_is_readonly(mnt) ? " ro" : " rw");
6690         err = show_sb_opts(m, sb);
6691 @@ -128,6 +176,11 @@ static int show_mountinfo(struct seq_fil
6692         struct path root = p->root;
6693         int err = 0;
6694  
6695 +       if (vx_flags(VXF_HIDE_MOUNT, 0))
6696 +               return SEQ_SKIP;
6697 +       if (!mnt_is_reachable(mnt) && !vx_check(0, VS_WATCH_P))
6698 +               return SEQ_SKIP;
6699 +
6700         seq_printf(m, "%i %i %u:%u ", r->mnt_id, r->mnt_parent->mnt_id,
6701                    MAJOR(sb->s_dev), MINOR(sb->s_dev));
6702         if (sb->s_op->show_path)
6703 @@ -187,6 +240,17 @@ static int show_vfsstat(struct seq_file 
6704         struct super_block *sb = mnt_path.dentry->d_sb;
6705         int err = 0;
6706  
6707 +       if (vx_flags(VXF_HIDE_MOUNT, 0))
6708 +               return SEQ_SKIP;
6709 +       if (!mnt_is_reachable(mnt) && !vx_check(0, VS_WATCH_P))
6710 +               return SEQ_SKIP;
6711 +
6712 +       if (!vx_check(0, VS_ADMIN|VS_WATCH) &&
6713 +               mnt == current->fs->root.mnt) {
6714 +               seq_puts(m, "device /dev/root mounted on / ");
6715 +               goto type;
6716 +       }
6717 +
6718         /* device */
6719         if (sb->s_op->show_devname) {
6720                 seq_puts(m, "device ");
6721 @@ -203,7 +267,7 @@ static int show_vfsstat(struct seq_file 
6722         seq_puts(m, " mounted on ");
6723         seq_path(m, &mnt_path, " \t\n\\");
6724         seq_putc(m, ' ');
6725 -
6726 +type:
6727         /* file system type */
6728         seq_puts(m, "with fstype ");
6729         show_type(m, sb);
6730 diff -NurpP --minimal linux-3.6.10/fs/quota/dquot.c linux-3.6.10-vs2.3.4.5/fs/quota/dquot.c
6731 --- linux-3.6.10/fs/quota/dquot.c       2012-10-04 15:27:41.000000000 +0200
6732 +++ linux-3.6.10-vs2.3.4.5/fs/quota/dquot.c     2012-10-04 18:47:00.000000000 +0200
6733 @@ -1580,6 +1580,9 @@ int __dquot_alloc_space(struct inode *in
6734         struct dquot **dquots = inode->i_dquot;
6735         int reserve = flags & DQUOT_SPACE_RESERVE;
6736  
6737 +       if ((ret = dl_alloc_space(inode, number)))
6738 +               return ret;
6739 +
6740         /*
6741          * First test before acquiring mutex - solves deadlocks when we
6742          * re-enter the quota code and are already holding the mutex
6743 @@ -1635,6 +1638,9 @@ int dquot_alloc_inode(const struct inode
6744         struct dquot_warn warn[MAXQUOTAS];
6745         struct dquot * const *dquots = inode->i_dquot;
6746  
6747 +       if ((ret = dl_alloc_inode(inode)))
6748 +               return ret;
6749 +
6750         /* First test before acquiring mutex - solves deadlocks when we
6751           * re-enter the quota code and are already holding the mutex */
6752         if (!dquot_active(inode))
6753 @@ -1706,6 +1712,8 @@ void __dquot_free_space(struct inode *in
6754         struct dquot **dquots = inode->i_dquot;
6755         int reserve = flags & DQUOT_SPACE_RESERVE;
6756  
6757 +       dl_free_space(inode, number);
6758 +
6759         /* First test before acquiring mutex - solves deadlocks when we
6760           * re-enter the quota code and are already holding the mutex */
6761         if (!dquot_active(inode)) {
6762 @@ -1750,6 +1758,8 @@ void dquot_free_inode(const struct inode
6763         struct dquot_warn warn[MAXQUOTAS];
6764         struct dquot * const *dquots = inode->i_dquot;
6765  
6766 +       dl_free_inode(inode);
6767 +
6768         /* First test before acquiring mutex - solves deadlocks when we
6769           * re-enter the quota code and are already holding the mutex */
6770         if (!dquot_active(inode))
6771 diff -NurpP --minimal linux-3.6.10/fs/quota/quota.c linux-3.6.10-vs2.3.4.5/fs/quota/quota.c
6772 --- linux-3.6.10/fs/quota/quota.c       2012-10-04 15:27:41.000000000 +0200
6773 +++ linux-3.6.10-vs2.3.4.5/fs/quota/quota.c     2012-10-04 18:47:00.000000000 +0200
6774 @@ -8,6 +8,7 @@
6775  #include <linux/fs.h>
6776  #include <linux/namei.h>
6777  #include <linux/slab.h>
6778 +#include <linux/vs_context.h>
6779  #include <asm/current.h>
6780  #include <linux/uaccess.h>
6781  #include <linux/kernel.h>
6782 @@ -37,7 +38,7 @@ static int check_quotactl_permission(str
6783                         break;
6784                 /*FALLTHROUGH*/
6785         default:
6786 -               if (!capable(CAP_SYS_ADMIN))
6787 +               if (!vx_capable(CAP_SYS_ADMIN, VXC_QUOTA_CTL))
6788                         return -EPERM;
6789         }
6790  
6791 @@ -291,6 +292,46 @@ static int do_quotactl(struct super_bloc
6792         }
6793  }
6794  
6795 +#if defined(CONFIG_BLK_DEV_VROOT) || defined(CONFIG_BLK_DEV_VROOT_MODULE)
6796 +
6797 +#include <linux/vroot.h>
6798 +#include <linux/major.h>
6799 +#include <linux/module.h>
6800 +#include <linux/kallsyms.h>
6801 +#include <linux/vserver/debug.h>
6802 +
6803 +static vroot_grb_func *vroot_get_real_bdev = NULL;
6804 +
6805 +static DEFINE_SPINLOCK(vroot_grb_lock);
6806 +
6807 +int register_vroot_grb(vroot_grb_func *func) {
6808 +       int ret = -EBUSY;
6809 +
6810 +       spin_lock(&vroot_grb_lock);
6811 +       if (!vroot_get_real_bdev) {
6812 +               vroot_get_real_bdev = func;
6813 +               ret = 0;
6814 +       }
6815 +       spin_unlock(&vroot_grb_lock);
6816 +       return ret;
6817 +}
6818 +EXPORT_SYMBOL(register_vroot_grb);
6819 +
6820 +int unregister_vroot_grb(vroot_grb_func *func) {
6821 +       int ret = -EINVAL;
6822 +
6823 +       spin_lock(&vroot_grb_lock);
6824 +       if (vroot_get_real_bdev) {
6825 +               vroot_get_real_bdev = NULL;
6826 +               ret = 0;
6827 +       }
6828 +       spin_unlock(&vroot_grb_lock);
6829 +       return ret;
6830 +}
6831 +EXPORT_SYMBOL(unregister_vroot_grb);
6832 +
6833 +#endif
6834 +
6835  /* Return 1 if 'cmd' will block on frozen filesystem */
6836  static int quotactl_cmd_write(int cmd)
6837  {
6838 @@ -323,6 +364,22 @@ static struct super_block *quotactl_bloc
6839         putname(tmp);
6840         if (IS_ERR(bdev))
6841                 return ERR_CAST(bdev);
6842 +#if defined(CONFIG_BLK_DEV_VROOT) || defined(CONFIG_BLK_DEV_VROOT_MODULE)
6843 +       if (bdev && bdev->bd_inode &&
6844 +                       imajor(bdev->bd_inode) == VROOT_MAJOR) {
6845 +               struct block_device *bdnew = (void *)-EINVAL;
6846 +
6847 +               if (vroot_get_real_bdev)
6848 +                       bdnew = vroot_get_real_bdev(bdev);
6849 +               else
6850 +                       vxdprintk(VXD_CBIT(misc, 0),
6851 +                                       "vroot_get_real_bdev not set");
6852 +               bdput(bdev);
6853 +               if (IS_ERR(bdnew))
6854 +                       return ERR_PTR(PTR_ERR(bdnew));
6855 +               bdev = bdnew;
6856 +       }
6857 +#endif
6858         if (quotactl_cmd_write(cmd))
6859                 sb = get_super_thawed(bdev);
6860         else
6861 diff -NurpP --minimal linux-3.6.10/fs/reiserfs/file.c linux-3.6.10-vs2.3.4.5/fs/reiserfs/file.c
6862 --- linux-3.6.10/fs/reiserfs/file.c     2012-05-21 18:07:26.000000000 +0200
6863 +++ linux-3.6.10-vs2.3.4.5/fs/reiserfs/file.c   2012-10-04 18:47:00.000000000 +0200
6864 @@ -319,5 +319,6 @@ const struct inode_operations reiserfs_f
6865         .listxattr = reiserfs_listxattr,
6866         .removexattr = reiserfs_removexattr,
6867         .permission = reiserfs_permission,
6868 +       .sync_flags = reiserfs_sync_flags,
6869         .get_acl = reiserfs_get_acl,
6870  };
6871 diff -NurpP --minimal linux-3.6.10/fs/reiserfs/inode.c linux-3.6.10-vs2.3.4.5/fs/reiserfs/inode.c
6872 --- linux-3.6.10/fs/reiserfs/inode.c    2012-12-11 12:36:58.000000000 +0100
6873 +++ linux-3.6.10-vs2.3.4.5/fs/reiserfs/inode.c  2012-12-08 01:36:33.000000000 +0100
6874 @@ -18,6 +18,7 @@
6875  #include <linux/writeback.h>
6876  #include <linux/quotaops.h>
6877  #include <linux/swap.h>
6878 +#include <linux/vs_tag.h>
6879  
6880  int reiserfs_commit_write(struct file *f, struct page *page,
6881                           unsigned from, unsigned to);
6882 @@ -1131,6 +1132,8 @@ static void init_inode(struct inode *ino
6883         struct buffer_head *bh;
6884         struct item_head *ih;
6885         __u32 rdev;
6886 +       uid_t uid;
6887 +       gid_t gid;
6888         //int version = ITEM_VERSION_1;
6889  
6890         bh = PATH_PLAST_BUFFER(path);
6891 @@ -1151,12 +1154,13 @@ static void init_inode(struct inode *ino
6892                     (struct stat_data_v1 *)B_I_PITEM(bh, ih);
6893                 unsigned long blocks;
6894  
6895 +               uid = sd_v1_uid(sd);
6896 +               gid = sd_v1_gid(sd);
6897 +
6898                 set_inode_item_key_version(inode, KEY_FORMAT_3_5);
6899                 set_inode_sd_version(inode, STAT_DATA_V1);
6900                 inode->i_mode = sd_v1_mode(sd);
6901                 set_nlink(inode, sd_v1_nlink(sd));
6902 -               inode->i_uid = sd_v1_uid(sd);
6903 -               inode->i_gid = sd_v1_gid(sd);
6904                 inode->i_size = sd_v1_size(sd);
6905                 inode->i_atime.tv_sec = sd_v1_atime(sd);
6906                 inode->i_mtime.tv_sec = sd_v1_mtime(sd);
6907 @@ -1198,11 +1202,12 @@ static void init_inode(struct inode *ino
6908                 // (directories and symlinks)
6909                 struct stat_data *sd = (struct stat_data *)B_I_PITEM(bh, ih);
6910  
6911 +               uid    = sd_v2_uid(sd);
6912 +               gid    = sd_v2_gid(sd);
6913 +
6914                 inode->i_mode = sd_v2_mode(sd);
6915                 set_nlink(inode, sd_v2_nlink(sd));
6916 -               inode->i_uid = sd_v2_uid(sd);
6917                 inode->i_size = sd_v2_size(sd);
6918 -               inode->i_gid = sd_v2_gid(sd);
6919                 inode->i_mtime.tv_sec = sd_v2_mtime(sd);
6920                 inode->i_atime.tv_sec = sd_v2_atime(sd);
6921                 inode->i_ctime.tv_sec = sd_v2_ctime(sd);
6922 @@ -1232,6 +1237,10 @@ static void init_inode(struct inode *ino
6923                 sd_attrs_to_i_attrs(sd_v2_attrs(sd), inode);
6924         }
6925  
6926 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
6927 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
6928 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid, 0);
6929 +
6930         pathrelse(path);
6931         if (S_ISREG(inode->i_mode)) {
6932                 inode->i_op = &reiserfs_file_inode_operations;
6933 @@ -1254,13 +1263,15 @@ static void init_inode(struct inode *ino
6934  static void inode2sd(void *sd, struct inode *inode, loff_t size)
6935  {
6936         struct stat_data *sd_v2 = (struct stat_data *)sd;
6937 +       uid_t uid = TAGINO_UID(DX_TAG(inode), inode->i_uid, inode->i_tag);
6938 +       gid_t gid = TAGINO_GID(DX_TAG(inode), inode->i_gid, inode->i_tag);
6939         __u16 flags;
6940  
6941 +       set_sd_v2_uid(sd_v2, uid);
6942 +       set_sd_v2_gid(sd_v2, gid);
6943         set_sd_v2_mode(sd_v2, inode->i_mode);
6944         set_sd_v2_nlink(sd_v2, inode->i_nlink);
6945 -       set_sd_v2_uid(sd_v2, inode->i_uid);
6946         set_sd_v2_size(sd_v2, size);
6947 -       set_sd_v2_gid(sd_v2, inode->i_gid);
6948         set_sd_v2_mtime(sd_v2, inode->i_mtime.tv_sec);
6949         set_sd_v2_atime(sd_v2, inode->i_atime.tv_sec);
6950         set_sd_v2_ctime(sd_v2, inode->i_ctime.tv_sec);
6951 @@ -2869,14 +2880,19 @@ int reiserfs_commit_write(struct file *f
6952  void sd_attrs_to_i_attrs(__u16 sd_attrs, struct inode *inode)
6953  {
6954         if (reiserfs_attrs(inode->i_sb)) {
6955 -               if (sd_attrs & REISERFS_SYNC_FL)
6956 -                       inode->i_flags |= S_SYNC;
6957 -               else
6958 -                       inode->i_flags &= ~S_SYNC;
6959                 if (sd_attrs & REISERFS_IMMUTABLE_FL)
6960                         inode->i_flags |= S_IMMUTABLE;
6961                 else
6962                         inode->i_flags &= ~S_IMMUTABLE;
6963 +               if (sd_attrs & REISERFS_IXUNLINK_FL)
6964 +                       inode->i_flags |= S_IXUNLINK;
6965 +               else
6966 +                       inode->i_flags &= ~S_IXUNLINK;
6967 +
6968 +               if (sd_attrs & REISERFS_SYNC_FL)
6969 +                       inode->i_flags |= S_SYNC;
6970 +               else
6971 +                       inode->i_flags &= ~S_SYNC;
6972                 if (sd_attrs & REISERFS_APPEND_FL)
6973                         inode->i_flags |= S_APPEND;
6974                 else
6975 @@ -2889,6 +2905,15 @@ void sd_attrs_to_i_attrs(__u16 sd_attrs,
6976                         REISERFS_I(inode)->i_flags |= i_nopack_mask;
6977                 else
6978                         REISERFS_I(inode)->i_flags &= ~i_nopack_mask;
6979 +
6980 +               if (sd_attrs & REISERFS_BARRIER_FL)
6981 +                       inode->i_vflags |= V_BARRIER;
6982 +               else
6983 +                       inode->i_vflags &= ~V_BARRIER;
6984 +               if (sd_attrs & REISERFS_COW_FL)
6985 +                       inode->i_vflags |= V_COW;
6986 +               else
6987 +                       inode->i_vflags &= ~V_COW;
6988         }
6989  }
6990  
6991 @@ -2899,6 +2924,11 @@ void i_attrs_to_sd_attrs(struct inode *i
6992                         *sd_attrs |= REISERFS_IMMUTABLE_FL;
6993                 else
6994                         *sd_attrs &= ~REISERFS_IMMUTABLE_FL;
6995 +               if (inode->i_flags & S_IXUNLINK)
6996 +                       *sd_attrs |= REISERFS_IXUNLINK_FL;
6997 +               else
6998 +                       *sd_attrs &= ~REISERFS_IXUNLINK_FL;
6999 +
7000                 if (inode->i_flags & S_SYNC)
7001                         *sd_attrs |= REISERFS_SYNC_FL;
7002                 else
7003 @@ -2911,6 +2941,15 @@ void i_attrs_to_sd_attrs(struct inode *i
7004                         *sd_attrs |= REISERFS_NOTAIL_FL;
7005                 else
7006                         *sd_attrs &= ~REISERFS_NOTAIL_FL;
7007 +
7008 +               if (inode->i_vflags & V_BARRIER)
7009 +                       *sd_attrs |= REISERFS_BARRIER_FL;
7010 +               else
7011 +                       *sd_attrs &= ~REISERFS_BARRIER_FL;
7012 +               if (inode->i_vflags & V_COW)
7013 +                       *sd_attrs |= REISERFS_COW_FL;
7014 +               else
7015 +                       *sd_attrs &= ~REISERFS_COW_FL;
7016         }
7017  }
7018  
7019 @@ -3155,7 +3194,8 @@ int reiserfs_setattr(struct dentry *dent
7020         }
7021  
7022         if ((ia_valid & ATTR_UID && attr->ia_uid != inode->i_uid) ||
7023 -           (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid)) {
7024 +           (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid) ||
7025 +           (ia_valid & ATTR_TAG && attr->ia_tag != inode->i_tag)) {
7026                 struct reiserfs_transaction_handle th;
7027                 int jbegin_count =
7028                     2 *
7029 @@ -3186,6 +3226,9 @@ int reiserfs_setattr(struct dentry *dent
7030                         inode->i_uid = attr->ia_uid;
7031                 if (attr->ia_valid & ATTR_GID)
7032                         inode->i_gid = attr->ia_gid;
7033 +                               if ((attr->ia_valid & ATTR_TAG) &&
7034 +                                       IS_TAGGED(inode))
7035 +                                       inode->i_tag = attr->ia_tag;
7036                 mark_inode_dirty(inode);
7037                 error = journal_end(&th, inode->i_sb, jbegin_count);
7038                 if (error)
7039 diff -NurpP --minimal linux-3.6.10/fs/reiserfs/ioctl.c linux-3.6.10-vs2.3.4.5/fs/reiserfs/ioctl.c
7040 --- linux-3.6.10/fs/reiserfs/ioctl.c    2012-05-21 18:07:27.000000000 +0200
7041 +++ linux-3.6.10-vs2.3.4.5/fs/reiserfs/ioctl.c  2012-10-04 18:47:00.000000000 +0200
7042 @@ -11,6 +11,21 @@
7043  #include <linux/pagemap.h>
7044  #include <linux/compat.h>
7045  
7046 +
7047 +int reiserfs_sync_flags(struct inode *inode, int flags, int vflags)
7048 +{
7049 +       __u16 sd_attrs = 0;
7050 +
7051 +       inode->i_flags = flags;
7052 +       inode->i_vflags = vflags;
7053 +
7054 +       i_attrs_to_sd_attrs(inode, &sd_attrs);
7055 +       REISERFS_I(inode)->i_attrs = sd_attrs;
7056 +       inode->i_ctime = CURRENT_TIME_SEC;
7057 +       mark_inode_dirty(inode);
7058 +       return 0;
7059 +}
7060 +
7061  /*
7062   * reiserfs_ioctl - handler for ioctl for inode
7063   * supported commands:
7064 @@ -22,7 +37,7 @@
7065  long reiserfs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
7066  {
7067         struct inode *inode = filp->f_path.dentry->d_inode;
7068 -       unsigned int flags;
7069 +       unsigned int flags, oldflags;
7070         int err = 0;
7071  
7072         reiserfs_write_lock(inode->i_sb);
7073 @@ -47,6 +62,7 @@ long reiserfs_ioctl(struct file *filp, u
7074  
7075                 flags = REISERFS_I(inode)->i_attrs;
7076                 i_attrs_to_sd_attrs(inode, (__u16 *) & flags);
7077 +               flags &= REISERFS_FL_USER_VISIBLE;
7078                 err = put_user(flags, (int __user *)arg);
7079                 break;
7080         case REISERFS_IOC_SETFLAGS:{
7081 @@ -67,6 +83,10 @@ long reiserfs_ioctl(struct file *filp, u
7082                                 err = -EFAULT;
7083                                 goto setflags_out;
7084                         }
7085 +                       if (IS_BARRIER(inode)) {
7086 +                               vxwprintk_task(1, "messing with the barrier.");
7087 +                               return -EACCES;
7088 +                       }
7089                         /*
7090                          * Is it quota file? Do not allow user to mess with it
7091                          */
7092 @@ -91,6 +111,10 @@ long reiserfs_ioctl(struct file *filp, u
7093                                         goto setflags_out;
7094                                 }
7095                         }
7096 +
7097 +                       oldflags = REISERFS_I(inode)->i_attrs;
7098 +                       flags &= REISERFS_FL_USER_MODIFIABLE;
7099 +                       flags |= oldflags & ~REISERFS_FL_USER_MODIFIABLE;
7100                         sd_attrs_to_i_attrs(flags, inode);
7101                         REISERFS_I(inode)->i_attrs = flags;
7102                         inode->i_ctime = CURRENT_TIME_SEC;
7103 diff -NurpP --minimal linux-3.6.10/fs/reiserfs/namei.c linux-3.6.10-vs2.3.4.5/fs/reiserfs/namei.c
7104 --- linux-3.6.10/fs/reiserfs/namei.c    2012-10-04 15:27:41.000000000 +0200
7105 +++ linux-3.6.10-vs2.3.4.5/fs/reiserfs/namei.c  2012-10-04 18:47:00.000000000 +0200
7106 @@ -18,6 +18,7 @@
7107  #include "acl.h"
7108  #include "xattr.h"
7109  #include <linux/quotaops.h>
7110 +#include <linux/vs_tag.h>
7111  
7112  #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); }
7113  #define DEC_DIR_INODE_NLINK(i) if (i->i_nlink != 1) drop_nlink(i);
7114 @@ -362,6 +363,7 @@ static struct dentry *reiserfs_lookup(st
7115         if (retval == IO_ERROR) {
7116                 return ERR_PTR(-EIO);
7117         }
7118 +               dx_propagate_tag(nd, inode);
7119  
7120         return d_splice_alias(inode, dentry);
7121  }
7122 diff -NurpP --minimal linux-3.6.10/fs/reiserfs/reiserfs.h linux-3.6.10-vs2.3.4.5/fs/reiserfs/reiserfs.h
7123 --- linux-3.6.10/fs/reiserfs/reiserfs.h 2012-07-22 23:39:42.000000000 +0200
7124 +++ linux-3.6.10-vs2.3.4.5/fs/reiserfs/reiserfs.h       2012-10-04 18:47:00.000000000 +0200
7125 @@ -549,6 +549,7 @@ enum reiserfs_mount_options {
7126         REISERFS_EXPOSE_PRIVROOT,
7127         REISERFS_BARRIER_NONE,
7128         REISERFS_BARRIER_FLUSH,
7129 +       REISERFS_TAGGED,
7130  
7131         /* Actions on error */
7132         REISERFS_ERROR_PANIC,
7133 @@ -1548,6 +1549,11 @@ struct stat_data_v1 {
7134  #define REISERFS_COMPR_FL     FS_COMPR_FL
7135  #define REISERFS_NOTAIL_FL    FS_NOTAIL_FL
7136  
7137 +/* unfortunately reiserfs sdattr is only 16 bit */
7138 +#define REISERFS_IXUNLINK_FL  (FS_IXUNLINK_FL >> 16)
7139 +#define REISERFS_BARRIER_FL   (FS_BARRIER_FL >> 16)
7140 +#define REISERFS_COW_FL       (FS_COW_FL >> 16)
7141 +
7142  /* persistent flags that file inherits from the parent directory */
7143  #define REISERFS_INHERIT_MASK ( REISERFS_IMMUTABLE_FL |        \
7144                                 REISERFS_SYNC_FL |      \
7145 @@ -1557,6 +1563,9 @@ struct stat_data_v1 {
7146                                 REISERFS_COMPR_FL |     \
7147                                 REISERFS_NOTAIL_FL )
7148  
7149 +#define REISERFS_FL_USER_VISIBLE       0x80FF
7150 +#define REISERFS_FL_USER_MODIFIABLE    0x80FF
7151 +
7152  /* Stat Data on disk (reiserfs version of UFS disk inode minus the
7153     address blocks) */
7154  struct stat_data {
7155 @@ -2647,6 +2656,7 @@ static inline void reiserfs_update_sd(st
7156  void sd_attrs_to_i_attrs(__u16 sd_attrs, struct inode *inode);
7157  void i_attrs_to_sd_attrs(struct inode *inode, __u16 * sd_attrs);
7158  int reiserfs_setattr(struct dentry *dentry, struct iattr *attr);
7159 +int reiserfs_sync_flags(struct inode *inode, int, int);
7160  
7161  int __reiserfs_write_begin(struct page *page, unsigned from, unsigned len);
7162  
7163 diff -NurpP --minimal linux-3.6.10/fs/reiserfs/super.c linux-3.6.10-vs2.3.4.5/fs/reiserfs/super.c
7164 --- linux-3.6.10/fs/reiserfs/super.c    2012-12-11 12:36:58.000000000 +0100
7165 +++ linux-3.6.10-vs2.3.4.5/fs/reiserfs/super.c  2012-12-08 01:36:33.000000000 +0100
7166 @@ -1020,6 +1020,14 @@ static int reiserfs_parse_options(struct
7167                 {"user_xattr",.setmask = 1 << REISERFS_UNSUPPORTED_OPT},
7168                 {"nouser_xattr",.clrmask = 1 << REISERFS_UNSUPPORTED_OPT},
7169  #endif
7170 +#ifndef CONFIG_TAGGING_NONE
7171 +               {"tagxid",.setmask = 1 << REISERFS_TAGGED},
7172 +               {"tag",.setmask = 1 << REISERFS_TAGGED},
7173 +               {"notag",.clrmask = 1 << REISERFS_TAGGED},
7174 +#endif
7175 +#ifdef CONFIG_PROPAGATE
7176 +               {"tag",.arg_required = 'T',.values = NULL},
7177 +#endif
7178  #ifdef CONFIG_REISERFS_FS_POSIX_ACL
7179                 {"acl",.setmask = 1 << REISERFS_POSIXACL},
7180                 {"noacl",.clrmask = 1 << REISERFS_POSIXACL},
7181 @@ -1338,6 +1346,14 @@ static int reiserfs_remount(struct super
7182         handle_quota_files(s, qf_names, &qfmt);
7183  #endif
7184  
7185 +       if ((mount_options & (1 << REISERFS_TAGGED)) &&
7186 +               !(s->s_flags & MS_TAGGED)) {
7187 +               reiserfs_warning(s, "super-vs01",
7188 +                       "reiserfs: tagging not permitted on remount.");
7189 +               err = -EINVAL;
7190 +               goto out_err;
7191 +       }
7192 +
7193         handle_attrs(s);
7194  
7195         /* Add options that are safe here */
7196 @@ -1831,6 +1847,10 @@ static int reiserfs_fill_super(struct su
7197                 goto error_unlocked;
7198         }
7199  
7200 +       /* map mount option tagxid */
7201 +       if (REISERFS_SB(s)->s_mount_opt & (1 << REISERFS_TAGGED))
7202 +               s->s_flags |= MS_TAGGED;
7203 +
7204         rs = SB_DISK_SUPER_BLOCK(s);
7205         /* Let's do basic sanity check to verify that underlying device is not
7206            smaller than the filesystem. If the check fails then abort and scream,
7207 diff -NurpP --minimal linux-3.6.10/fs/reiserfs/xattr.c linux-3.6.10-vs2.3.4.5/fs/reiserfs/xattr.c
7208 --- linux-3.6.10/fs/reiserfs/xattr.c    2012-10-04 15:27:41.000000000 +0200
7209 +++ linux-3.6.10-vs2.3.4.5/fs/reiserfs/xattr.c  2012-10-04 18:47:00.000000000 +0200
7210 @@ -40,6 +40,7 @@
7211  #include <linux/errno.h>
7212  #include <linux/gfp.h>
7213  #include <linux/fs.h>
7214 +#include <linux/mount.h>
7215  #include <linux/file.h>
7216  #include <linux/pagemap.h>
7217  #include <linux/xattr.h>
7218 diff -NurpP --minimal linux-3.6.10/fs/stat.c linux-3.6.10-vs2.3.4.5/fs/stat.c
7219 --- linux-3.6.10/fs/stat.c      2012-10-04 15:27:41.000000000 +0200
7220 +++ linux-3.6.10-vs2.3.4.5/fs/stat.c    2012-10-04 18:47:00.000000000 +0200
7221 @@ -26,6 +26,7 @@ void generic_fillattr(struct inode *inod
7222         stat->nlink = inode->i_nlink;
7223         stat->uid = inode->i_uid;
7224         stat->gid = inode->i_gid;
7225 +       stat->tag = inode->i_tag;
7226         stat->rdev = inode->i_rdev;
7227         stat->size = i_size_read(inode);
7228         stat->atime = inode->i_atime;
7229 diff -NurpP --minimal linux-3.6.10/fs/statfs.c linux-3.6.10-vs2.3.4.5/fs/statfs.c
7230 --- linux-3.6.10/fs/statfs.c    2012-07-22 23:39:42.000000000 +0200
7231 +++ linux-3.6.10-vs2.3.4.5/fs/statfs.c  2012-10-04 18:47:00.000000000 +0200
7232 @@ -7,6 +7,8 @@
7233  #include <linux/statfs.h>
7234  #include <linux/security.h>
7235  #include <linux/uaccess.h>
7236 +#include <linux/vs_base.h>
7237 +#include <linux/vs_dlimit.h>
7238  #include "internal.h"
7239  
7240  static int flags_by_mnt(int mnt_flags)
7241 @@ -60,6 +62,8 @@ static int statfs_by_dentry(struct dentr
7242         retval = dentry->d_sb->s_op->statfs(dentry, buf);
7243         if (retval == 0 && buf->f_frsize == 0)
7244                 buf->f_frsize = buf->f_bsize;
7245 +       if (!vx_check(0, VS_ADMIN|VS_WATCH))
7246 +               vx_vsi_statfs(dentry->d_sb, buf);
7247         return retval;
7248  }
7249  
7250 diff -NurpP --minimal linux-3.6.10/fs/super.c linux-3.6.10-vs2.3.4.5/fs/super.c
7251 --- linux-3.6.10/fs/super.c     2012-10-04 15:27:41.000000000 +0200
7252 +++ linux-3.6.10-vs2.3.4.5/fs/super.c   2012-10-04 19:06:05.000000000 +0200
7253 @@ -34,6 +34,8 @@
7254  #include <linux/cleancache.h>
7255  #include <linux/fsnotify.h>
7256  #include <linux/lockdep.h>
7257 +#include <linux/magic.h>
7258 +#include <linux/vs_context.h>
7259  #include "internal.h"
7260  
7261  
7262 @@ -1148,6 +1150,13 @@ mount_fs(struct file_system_type *type, 
7263         WARN_ON(sb->s_bdi == &default_backing_dev_info);
7264         sb->s_flags |= MS_BORN;
7265  
7266 +       error = -EPERM;
7267 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_BINARY_MOUNT) &&
7268 +               !sb->s_bdev &&
7269 +               (sb->s_magic != PROC_SUPER_MAGIC) &&
7270 +               (sb->s_magic != DEVPTS_SUPER_MAGIC))
7271 +               goto out_sb;
7272 +
7273         error = security_sb_kern_mount(sb, flags, secdata);
7274         if (error)
7275                 goto out_sb;
7276 diff -NurpP --minimal linux-3.6.10/fs/sysfs/mount.c linux-3.6.10-vs2.3.4.5/fs/sysfs/mount.c
7277 --- linux-3.6.10/fs/sysfs/mount.c       2012-10-04 15:27:41.000000000 +0200
7278 +++ linux-3.6.10-vs2.3.4.5/fs/sysfs/mount.c     2012-10-04 18:47:00.000000000 +0200
7279 @@ -47,7 +47,7 @@ static int sysfs_fill_super(struct super
7280  
7281         sb->s_blocksize = PAGE_CACHE_SIZE;
7282         sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
7283 -       sb->s_magic = SYSFS_MAGIC;
7284 +       sb->s_magic = SYSFS_SUPER_MAGIC;
7285         sb->s_op = &sysfs_ops;
7286         sb->s_time_gran = 1;
7287  
7288 diff -NurpP --minimal linux-3.6.10/fs/utimes.c linux-3.6.10-vs2.3.4.5/fs/utimes.c
7289 --- linux-3.6.10/fs/utimes.c    2012-07-22 23:39:42.000000000 +0200
7290 +++ linux-3.6.10-vs2.3.4.5/fs/utimes.c  2012-10-04 18:47:00.000000000 +0200
7291 @@ -8,6 +8,8 @@
7292  #include <linux/stat.h>
7293  #include <linux/utime.h>
7294  #include <linux/syscalls.h>
7295 +#include <linux/mount.h>
7296 +#include <linux/vs_cowbl.h>
7297  #include <asm/uaccess.h>
7298  #include <asm/unistd.h>
7299  
7300 @@ -52,12 +54,18 @@ static int utimes_common(struct path *pa
7301  {
7302         int error;
7303         struct iattr newattrs;
7304 -       struct inode *inode = path->dentry->d_inode;
7305 +       struct inode *inode;
7306  
7307         error = mnt_want_write(path->mnt);
7308         if (error)
7309                 goto out;
7310  
7311 +       error = cow_check_and_break(path);
7312 +       if (error)
7313 +               goto mnt_drop_write_and_out;
7314 +
7315 +       inode = path->dentry->d_inode;
7316 +
7317         if (times && times[0].tv_nsec == UTIME_NOW &&
7318                      times[1].tv_nsec == UTIME_NOW)
7319                 times = NULL;
7320 diff -NurpP --minimal linux-3.6.10/fs/xattr.c linux-3.6.10-vs2.3.4.5/fs/xattr.c
7321 --- linux-3.6.10/fs/xattr.c     2012-10-04 15:27:44.000000000 +0200
7322 +++ linux-3.6.10-vs2.3.4.5/fs/xattr.c   2012-10-04 18:47:00.000000000 +0200
7323 @@ -20,6 +20,7 @@
7324  #include <linux/fsnotify.h>
7325  #include <linux/audit.h>
7326  #include <linux/vmalloc.h>
7327 +#include <linux/mount.h>
7328  
7329  #include <asm/uaccess.h>
7330  
7331 @@ -51,7 +52,7 @@ xattr_permission(struct inode *inode, co
7332          * The trusted.* namespace can only be accessed by privileged users.
7333          */
7334         if (!strncmp(name, XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN)) {
7335 -               if (!capable(CAP_SYS_ADMIN))
7336 +               if (!vx_capable(CAP_SYS_ADMIN, VXC_FS_TRUSTED))
7337                         return (mask & MAY_WRITE) ? -EPERM : -ENODATA;
7338                 return 0;
7339         }
7340 diff -NurpP --minimal linux-3.6.10/fs/xfs/xfs_dinode.h linux-3.6.10-vs2.3.4.5/fs/xfs/xfs_dinode.h
7341 --- linux-3.6.10/fs/xfs/xfs_dinode.h    2012-10-04 15:27:44.000000000 +0200
7342 +++ linux-3.6.10-vs2.3.4.5/fs/xfs/xfs_dinode.h  2012-10-04 18:47:00.000000000 +0200
7343 @@ -51,7 +51,9 @@ typedef struct xfs_dinode {
7344         __be32          di_nlink;       /* number of links to file */
7345         __be16          di_projid_lo;   /* lower part of owner's project id */
7346         __be16          di_projid_hi;   /* higher part owner's project id */
7347 -       __u8            di_pad[6];      /* unused, zeroed space */
7348 +       __u8            di_pad[2];      /* unused, zeroed space */
7349 +       __be16          di_tag;         /* context tagging */
7350 +       __be16          di_vflags;      /* vserver specific flags */
7351         __be16          di_flushiter;   /* incremented on flush */
7352         xfs_timestamp_t di_atime;       /* time last accessed */
7353         xfs_timestamp_t di_mtime;       /* time last modified */
7354 @@ -184,6 +186,8 @@ static inline void xfs_dinode_put_rdev(s
7355  #define XFS_DIFLAG_EXTSZINHERIT_BIT 12 /* inherit inode extent size */
7356  #define XFS_DIFLAG_NODEFRAG_BIT     13 /* do not reorganize/defragment */
7357  #define XFS_DIFLAG_FILESTREAM_BIT   14  /* use filestream allocator */
7358 +#define XFS_DIFLAG_IXUNLINK_BIT     15 /* Immutable inver on unlink */
7359 +
7360  #define XFS_DIFLAG_REALTIME      (1 << XFS_DIFLAG_REALTIME_BIT)
7361  #define XFS_DIFLAG_PREALLOC      (1 << XFS_DIFLAG_PREALLOC_BIT)
7362  #define XFS_DIFLAG_NEWRTBM       (1 << XFS_DIFLAG_NEWRTBM_BIT)
7363 @@ -199,6 +203,7 @@ static inline void xfs_dinode_put_rdev(s
7364  #define XFS_DIFLAG_EXTSZINHERIT  (1 << XFS_DIFLAG_EXTSZINHERIT_BIT)
7365  #define XFS_DIFLAG_NODEFRAG      (1 << XFS_DIFLAG_NODEFRAG_BIT)
7366  #define XFS_DIFLAG_FILESTREAM    (1 << XFS_DIFLAG_FILESTREAM_BIT)
7367 +#define XFS_DIFLAG_IXUNLINK      (1 << XFS_DIFLAG_IXUNLINK_BIT)
7368  
7369  #ifdef CONFIG_XFS_RT
7370  #define XFS_IS_REALTIME_INODE(ip) ((ip)->i_d.di_flags & XFS_DIFLAG_REALTIME)
7371 @@ -211,6 +216,10 @@ static inline void xfs_dinode_put_rdev(s
7372          XFS_DIFLAG_IMMUTABLE | XFS_DIFLAG_APPEND | XFS_DIFLAG_SYNC | \
7373          XFS_DIFLAG_NOATIME | XFS_DIFLAG_NODUMP | XFS_DIFLAG_RTINHERIT | \
7374          XFS_DIFLAG_PROJINHERIT | XFS_DIFLAG_NOSYMLINKS | XFS_DIFLAG_EXTSIZE | \
7375 -        XFS_DIFLAG_EXTSZINHERIT | XFS_DIFLAG_NODEFRAG | XFS_DIFLAG_FILESTREAM)
7376 +        XFS_DIFLAG_EXTSZINHERIT | XFS_DIFLAG_NODEFRAG | XFS_DIFLAG_FILESTREAM | \
7377 +        XFS_DIFLAG_IXUNLINK)
7378 +
7379 +#define XFS_DIVFLAG_BARRIER    0x01
7380 +#define XFS_DIVFLAG_COW                0x02
7381  
7382  #endif /* __XFS_DINODE_H__ */
7383 diff -NurpP --minimal linux-3.6.10/fs/xfs/xfs_fs.h linux-3.6.10-vs2.3.4.5/fs/xfs/xfs_fs.h
7384 --- linux-3.6.10/fs/xfs/xfs_fs.h        2011-10-24 18:45:31.000000000 +0200
7385 +++ linux-3.6.10-vs2.3.4.5/fs/xfs/xfs_fs.h      2012-10-04 18:47:00.000000000 +0200
7386 @@ -67,6 +67,9 @@ struct fsxattr {
7387  #define XFS_XFLAG_EXTSZINHERIT 0x00001000      /* inherit inode extent size */
7388  #define XFS_XFLAG_NODEFRAG     0x00002000      /* do not defragment */
7389  #define XFS_XFLAG_FILESTREAM   0x00004000      /* use filestream allocator */
7390 +#define XFS_XFLAG_IXUNLINK     0x00008000      /* immutable invert on unlink */
7391 +#define XFS_XFLAG_BARRIER      0x10000000      /* chroot() barrier */
7392 +#define XFS_XFLAG_COW          0x20000000      /* copy on write mark */
7393  #define XFS_XFLAG_HASATTR      0x80000000      /* no DIFLAG for this   */
7394  
7395  /*
7396 @@ -302,7 +305,8 @@ typedef struct xfs_bstat {
7397  #define        bs_projid       bs_projid_lo    /* (previously just bs_projid)  */
7398         __u16           bs_forkoff;     /* inode fork offset in bytes   */
7399         __u16           bs_projid_hi;   /* higher part of project id    */
7400 -       unsigned char   bs_pad[10];     /* pad space, unused            */
7401 +       unsigned char   bs_pad[8];      /* pad space, unused            */
7402 +       __u16           bs_tag;         /* context tagging              */
7403         __u32           bs_dmevmask;    /* DMIG event mask              */
7404         __u16           bs_dmstate;     /* DMIG state info              */
7405         __u16           bs_aextents;    /* attribute number of extents  */
7406 diff -NurpP --minimal linux-3.6.10/fs/xfs/xfs_ialloc.c linux-3.6.10-vs2.3.4.5/fs/xfs/xfs_ialloc.c
7407 --- linux-3.6.10/fs/xfs/xfs_ialloc.c    2012-10-04 15:27:44.000000000 +0200
7408 +++ linux-3.6.10-vs2.3.4.5/fs/xfs/xfs_ialloc.c  2012-10-04 18:47:00.000000000 +0200
7409 @@ -37,7 +37,6 @@
7410  #include "xfs_error.h"
7411  #include "xfs_bmap.h"
7412  
7413 -
7414  /*
7415   * Allocation group level functions.
7416   */
7417 diff -NurpP --minimal linux-3.6.10/fs/xfs/xfs_inode.c linux-3.6.10-vs2.3.4.5/fs/xfs/xfs_inode.c
7418 --- linux-3.6.10/fs/xfs/xfs_inode.c     2012-10-04 15:27:44.000000000 +0200
7419 +++ linux-3.6.10-vs2.3.4.5/fs/xfs/xfs_inode.c   2012-11-16 22:43:16.000000000 +0100
7420 @@ -16,6 +16,7 @@
7421   * Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
7422   */
7423  #include <linux/log2.h>
7424 +#include <linux/vs_tag.h>
7425  
7426  #include "xfs.h"
7427  #include "xfs_fs.h"
7428 @@ -563,15 +564,25 @@ xfs_iformat_btree(
7429  STATIC void
7430  xfs_dinode_from_disk(
7431         xfs_icdinode_t          *to,
7432 -       xfs_dinode_t            *from)
7433 +       xfs_dinode_t            *from,
7434 +       int                     tagged)
7435  {
7436 +       uint32_t uid, gid, tag;
7437 +
7438         to->di_magic = be16_to_cpu(from->di_magic);
7439         to->di_mode = be16_to_cpu(from->di_mode);
7440         to->di_version = from ->di_version;
7441         to->di_format = from->di_format;
7442         to->di_onlink = be16_to_cpu(from->di_onlink);
7443 -       to->di_uid = be32_to_cpu(from->di_uid);
7444 -       to->di_gid = be32_to_cpu(from->di_gid);
7445 +
7446 +       uid = be32_to_cpu(from->di_uid);
7447 +       gid = be32_to_cpu(from->di_gid);
7448 +       tag = be16_to_cpu(from->di_tag);
7449 +
7450 +       to->di_uid = INOTAG_UID(tagged, uid, gid);
7451 +       to->di_gid = INOTAG_GID(tagged, uid, gid);
7452 +       to->di_tag = INOTAG_TAG(tagged, uid, gid, tag);
7453 +
7454         to->di_nlink = be32_to_cpu(from->di_nlink);
7455         to->di_projid_lo = be16_to_cpu(from->di_projid_lo);
7456         to->di_projid_hi = be16_to_cpu(from->di_projid_hi);
7457 @@ -593,21 +604,26 @@ xfs_dinode_from_disk(
7458         to->di_dmevmask = be32_to_cpu(from->di_dmevmask);
7459         to->di_dmstate  = be16_to_cpu(from->di_dmstate);
7460         to->di_flags    = be16_to_cpu(from->di_flags);
7461 +       to->di_vflags   = be16_to_cpu(from->di_vflags);
7462         to->di_gen      = be32_to_cpu(from->di_gen);
7463  }
7464  
7465  void
7466  xfs_dinode_to_disk(
7467         xfs_dinode_t            *to,
7468 -       xfs_icdinode_t          *from)
7469 +       xfs_icdinode_t          *from,
7470 +       int                     tagged)
7471  {
7472         to->di_magic = cpu_to_be16(from->di_magic);
7473         to->di_mode = cpu_to_be16(from->di_mode);
7474         to->di_version = from ->di_version;
7475         to->di_format = from->di_format;
7476         to->di_onlink = cpu_to_be16(from->di_onlink);
7477 -       to->di_uid = cpu_to_be32(from->di_uid);
7478 -       to->di_gid = cpu_to_be32(from->di_gid);
7479 +
7480 +       to->di_uid = cpu_to_be32(TAGINO_UID(tagged, from->di_uid, from->di_tag));
7481 +       to->di_gid = cpu_to_be32(TAGINO_GID(tagged, from->di_gid, from->di_tag));
7482 +       to->di_tag = cpu_to_be16(TAGINO_TAG(tagged, from->di_tag));
7483 +
7484         to->di_nlink = cpu_to_be32(from->di_nlink);
7485         to->di_projid_lo = cpu_to_be16(from->di_projid_lo);
7486         to->di_projid_hi = cpu_to_be16(from->di_projid_hi);
7487 @@ -629,12 +645,14 @@ xfs_dinode_to_disk(
7488         to->di_dmevmask = cpu_to_be32(from->di_dmevmask);
7489         to->di_dmstate = cpu_to_be16(from->di_dmstate);
7490         to->di_flags = cpu_to_be16(from->di_flags);
7491 +       to->di_vflags = cpu_to_be16(from->di_vflags);
7492         to->di_gen = cpu_to_be32(from->di_gen);
7493  }
7494  
7495  STATIC uint
7496  _xfs_dic2xflags(
7497 -       __uint16_t              di_flags)
7498 +       __uint16_t              di_flags,
7499 +       __uint16_t              di_vflags)
7500  {
7501         uint                    flags = 0;
7502  
7503 @@ -645,6 +663,8 @@ _xfs_dic2xflags(
7504                         flags |= XFS_XFLAG_PREALLOC;
7505                 if (di_flags & XFS_DIFLAG_IMMUTABLE)
7506                         flags |= XFS_XFLAG_IMMUTABLE;
7507 +               if (di_flags & XFS_DIFLAG_IXUNLINK)
7508 +                       flags |= XFS_XFLAG_IXUNLINK;
7509                 if (di_flags & XFS_DIFLAG_APPEND)
7510                         flags |= XFS_XFLAG_APPEND;
7511                 if (di_flags & XFS_DIFLAG_SYNC)
7512 @@ -669,6 +689,10 @@ _xfs_dic2xflags(
7513                         flags |= XFS_XFLAG_FILESTREAM;
7514         }
7515  
7516 +       if (di_vflags & XFS_DIVFLAG_BARRIER)
7517 +               flags |= FS_BARRIER_FL;
7518 +       if (di_vflags & XFS_DIVFLAG_COW)
7519 +               flags |= FS_COW_FL;
7520         return flags;
7521  }
7522  
7523 @@ -678,7 +702,7 @@ xfs_ip2xflags(
7524  {
7525         xfs_icdinode_t          *dic = &ip->i_d;
7526  
7527 -       return _xfs_dic2xflags(dic->di_flags) |
7528 +       return _xfs_dic2xflags(dic->di_flags, dic->di_vflags) |
7529                                 (XFS_IFORK_Q(ip) ? XFS_XFLAG_HASATTR : 0);
7530  }
7531  
7532 @@ -686,7 +710,8 @@ uint
7533  xfs_dic2xflags(
7534         xfs_dinode_t            *dip)
7535  {
7536 -       return _xfs_dic2xflags(be16_to_cpu(dip->di_flags)) |
7537 +       return _xfs_dic2xflags(be16_to_cpu(dip->di_flags),
7538 +                               be16_to_cpu(dip->di_vflags)) |
7539                                 (XFS_DFORK_Q(dip) ? XFS_XFLAG_HASATTR : 0);
7540  }
7541  
7542 @@ -740,7 +765,8 @@ xfs_iread(
7543          * Otherwise, just get the truly permanent information.
7544          */
7545         if (dip->di_mode) {
7546 -               xfs_dinode_from_disk(&ip->i_d, dip);
7547 +               xfs_dinode_from_disk(&ip->i_d, dip,
7548 +                       mp->m_flags & XFS_MOUNT_TAGGED);
7549                 error = xfs_iformat(ip, dip);
7550                 if (error)  {
7551  #ifdef DEBUG
7552 @@ -927,6 +953,7 @@ xfs_ialloc(
7553         ASSERT(ip->i_d.di_nlink == nlink);
7554         ip->i_d.di_uid = current_fsuid();
7555         ip->i_d.di_gid = current_fsgid();
7556 +       ip->i_d.di_tag = current_fstag(&ip->i_vnode);
7557         xfs_set_projid(ip, prid);
7558         memset(&(ip->i_d.di_pad[0]), 0, sizeof(ip->i_d.di_pad));
7559  
7560 @@ -986,6 +1013,7 @@ xfs_ialloc(
7561         ip->i_d.di_dmevmask = 0;
7562         ip->i_d.di_dmstate = 0;
7563         ip->i_d.di_flags = 0;
7564 +       ip->i_d.di_vflags = 0;
7565         flags = XFS_ILOG_CORE;
7566         switch (mode & S_IFMT) {
7567         case S_IFIFO:
7568 @@ -1667,6 +1695,7 @@ xfs_ifree(
7569         }
7570         ip->i_d.di_mode = 0;            /* mark incore inode as free */
7571         ip->i_d.di_flags = 0;
7572 +       ip->i_d.di_vflags = 0;
7573         ip->i_d.di_dmevmask = 0;
7574         ip->i_d.di_forkoff = 0;         /* mark the attr fork not in use */
7575         ip->i_d.di_format = XFS_DINODE_FMT_EXTENTS;
7576 @@ -1833,6 +1862,7 @@ xfs_iroot_realloc(
7577         return;
7578  }
7579  
7580 +#include <linux/vs_tag.h>
7581  
7582  /*
7583   * This is called when the amount of space needed for if_data
7584 @@ -2521,7 +2551,8 @@ xfs_iflush_int(
7585          * because if the inode is dirty at all the core must
7586          * be.
7587          */
7588 -       xfs_dinode_to_disk(dip, &ip->i_d);
7589 +       xfs_dinode_to_disk(dip, &ip->i_d,
7590 +               mp->m_flags & XFS_MOUNT_TAGGED);
7591  
7592         /* Wrap, we never let the log put out DI_MAX_FLUSH */
7593         if (ip->i_d.di_flushiter == DI_MAX_FLUSH)
7594 diff -NurpP --minimal linux-3.6.10/fs/xfs/xfs_inode.h linux-3.6.10-vs2.3.4.5/fs/xfs/xfs_inode.h
7595 --- linux-3.6.10/fs/xfs/xfs_inode.h     2012-10-04 15:27:44.000000000 +0200
7596 +++ linux-3.6.10-vs2.3.4.5/fs/xfs/xfs_inode.h   2012-10-04 18:47:00.000000000 +0200
7597 @@ -134,7 +134,9 @@ typedef struct xfs_icdinode {
7598         __uint32_t      di_nlink;       /* number of links to file */
7599         __uint16_t      di_projid_lo;   /* lower part of owner's project id */
7600         __uint16_t      di_projid_hi;   /* higher part of owner's project id */
7601 -       __uint8_t       di_pad[6];      /* unused, zeroed space */
7602 +       __uint8_t       di_pad[2];      /* unused, zeroed space */
7603 +       __uint16_t      di_tag;         /* context tagging */
7604 +       __uint16_t      di_vflags;      /* vserver specific flags */
7605         __uint16_t      di_flushiter;   /* incremented on flush */
7606         xfs_ictimestamp_t di_atime;     /* time last accessed */
7607         xfs_ictimestamp_t di_mtime;     /* time last modified */
7608 @@ -561,7 +563,7 @@ int         xfs_imap_to_bp(struct xfs_mount *, 
7609  int            xfs_iread(struct xfs_mount *, struct xfs_trans *,
7610                           struct xfs_inode *, uint);
7611  void           xfs_dinode_to_disk(struct xfs_dinode *,
7612 -                                  struct xfs_icdinode *);
7613 +                                  struct xfs_icdinode *, int);
7614  void           xfs_idestroy_fork(struct xfs_inode *, int);
7615  void           xfs_idata_realloc(struct xfs_inode *, int, int);
7616  void           xfs_iroot_realloc(struct xfs_inode *, int, int);
7617 diff -NurpP --minimal linux-3.6.10/fs/xfs/xfs_ioctl.c linux-3.6.10-vs2.3.4.5/fs/xfs/xfs_ioctl.c
7618 --- linux-3.6.10/fs/xfs/xfs_ioctl.c     2012-10-04 15:27:44.000000000 +0200
7619 +++ linux-3.6.10-vs2.3.4.5/fs/xfs/xfs_ioctl.c   2012-10-04 18:47:00.000000000 +0200
7620 @@ -26,7 +26,7 @@
7621  #include "xfs_bmap_btree.h"
7622  #include "xfs_dinode.h"
7623  #include "xfs_inode.h"
7624 -#include "xfs_ioctl.h"
7625 +// #include "xfs_ioctl.h"
7626  #include "xfs_rtalloc.h"
7627  #include "xfs_itable.h"
7628  #include "xfs_error.h"
7629 @@ -762,6 +762,10 @@ xfs_merge_ioc_xflags(
7630                 xflags |= XFS_XFLAG_IMMUTABLE;
7631         else
7632                 xflags &= ~XFS_XFLAG_IMMUTABLE;
7633 +       if (flags & FS_IXUNLINK_FL)
7634 +               xflags |= XFS_XFLAG_IXUNLINK;
7635 +       else
7636 +               xflags &= ~XFS_XFLAG_IXUNLINK;
7637         if (flags & FS_APPEND_FL)
7638                 xflags |= XFS_XFLAG_APPEND;
7639         else
7640 @@ -790,6 +794,8 @@ xfs_di2lxflags(
7641  
7642         if (di_flags & XFS_DIFLAG_IMMUTABLE)
7643                 flags |= FS_IMMUTABLE_FL;
7644 +       if (di_flags & XFS_DIFLAG_IXUNLINK)
7645 +               flags |= FS_IXUNLINK_FL;
7646         if (di_flags & XFS_DIFLAG_APPEND)
7647                 flags |= FS_APPEND_FL;
7648         if (di_flags & XFS_DIFLAG_SYNC)
7649 @@ -850,6 +856,8 @@ xfs_set_diflags(
7650         di_flags = (ip->i_d.di_flags & XFS_DIFLAG_PREALLOC);
7651         if (xflags & XFS_XFLAG_IMMUTABLE)
7652                 di_flags |= XFS_DIFLAG_IMMUTABLE;
7653 +       if (xflags & XFS_XFLAG_IXUNLINK)
7654 +               di_flags |= XFS_DIFLAG_IXUNLINK;
7655         if (xflags & XFS_XFLAG_APPEND)
7656                 di_flags |= XFS_DIFLAG_APPEND;
7657         if (xflags & XFS_XFLAG_SYNC)
7658 @@ -892,6 +900,10 @@ xfs_diflags_to_linux(
7659                 inode->i_flags |= S_IMMUTABLE;
7660         else
7661                 inode->i_flags &= ~S_IMMUTABLE;
7662 +       if (xflags & XFS_XFLAG_IXUNLINK)
7663 +               inode->i_flags |= S_IXUNLINK;
7664 +       else
7665 +               inode->i_flags &= ~S_IXUNLINK;
7666         if (xflags & XFS_XFLAG_APPEND)
7667                 inode->i_flags |= S_APPEND;
7668         else
7669 @@ -1396,10 +1408,18 @@ xfs_file_ioctl(
7670         case XFS_IOC_FSGETXATTRA:
7671                 return xfs_ioc_fsgetxattr(ip, 1, arg);
7672         case XFS_IOC_FSSETXATTR:
7673 +               if (IS_BARRIER(inode)) {
7674 +                       vxwprintk_task(1, "messing with the barrier.");
7675 +                       return -XFS_ERROR(EACCES);
7676 +               }
7677                 return xfs_ioc_fssetxattr(ip, filp, arg);
7678         case XFS_IOC_GETXFLAGS:
7679                 return xfs_ioc_getxflags(ip, arg);
7680         case XFS_IOC_SETXFLAGS:
7681 +               if (IS_BARRIER(inode)) {
7682 +                       vxwprintk_task(1, "messing with the barrier.");
7683 +                       return -XFS_ERROR(EACCES);
7684 +               }
7685                 return xfs_ioc_setxflags(ip, filp, arg);
7686  
7687         case XFS_IOC_FSSETDM: {
7688 diff -NurpP --minimal linux-3.6.10/fs/xfs/xfs_ioctl.h linux-3.6.10-vs2.3.4.5/fs/xfs/xfs_ioctl.h
7689 --- linux-3.6.10/fs/xfs/xfs_ioctl.h     2011-10-24 18:45:31.000000000 +0200
7690 +++ linux-3.6.10-vs2.3.4.5/fs/xfs/xfs_ioctl.h   2012-10-04 18:47:00.000000000 +0200
7691 @@ -70,6 +70,12 @@ xfs_handle_to_dentry(
7692         void __user             *uhandle,
7693         u32                     hlen);
7694  
7695 +extern int
7696 +xfs_sync_flags(
7697 +       struct inode            *inode,
7698 +       int                     flags,
7699 +       int                     vflags);
7700 +
7701  extern long
7702  xfs_file_ioctl(
7703         struct file             *filp,
7704 diff -NurpP --minimal linux-3.6.10/fs/xfs/xfs_iops.c linux-3.6.10-vs2.3.4.5/fs/xfs/xfs_iops.c
7705 --- linux-3.6.10/fs/xfs/xfs_iops.c      2012-10-04 15:27:44.000000000 +0200
7706 +++ linux-3.6.10-vs2.3.4.5/fs/xfs/xfs_iops.c    2012-11-16 22:14:53.000000000 +0100
7707 @@ -28,6 +28,7 @@
7708  #include "xfs_bmap_btree.h"
7709  #include "xfs_dinode.h"
7710  #include "xfs_inode.h"
7711 +#include "xfs_ioctl.h"
7712  #include "xfs_bmap.h"
7713  #include "xfs_rtalloc.h"
7714  #include "xfs_error.h"
7715 @@ -46,6 +47,7 @@
7716  #include <linux/security.h>
7717  #include <linux/fiemap.h>
7718  #include <linux/slab.h>
7719 +#include <linux/vs_tag.h>
7720  
7721  static int
7722  xfs_initxattrs(
7723 @@ -421,6 +423,7 @@ xfs_vn_getattr(
7724         stat->nlink = ip->i_d.di_nlink;
7725         stat->uid = ip->i_d.di_uid;
7726         stat->gid = ip->i_d.di_gid;
7727 +       stat->tag = ip->i_d.di_tag;
7728         stat->ino = ip->i_ino;
7729         stat->atime = inode->i_atime;
7730         stat->mtime = inode->i_mtime;
7731 @@ -1033,6 +1036,7 @@ static const struct inode_operations xfs
7732         .listxattr              = xfs_vn_listxattr,
7733         .fiemap                 = xfs_vn_fiemap,
7734         .update_time            = xfs_vn_update_time,
7735 +       .sync_flags             = xfs_sync_flags,
7736  };
7737  
7738  static const struct inode_operations xfs_dir_inode_operations = {
7739 @@ -1059,6 +1063,7 @@ static const struct inode_operations xfs
7740         .removexattr            = generic_removexattr,
7741         .listxattr              = xfs_vn_listxattr,
7742         .update_time            = xfs_vn_update_time,
7743 +       .sync_flags             = xfs_sync_flags,
7744  };
7745  
7746  static const struct inode_operations xfs_dir_ci_inode_operations = {
7747 @@ -1110,6 +1115,10 @@ xfs_diflags_to_iflags(
7748                 inode->i_flags |= S_IMMUTABLE;
7749         else
7750                 inode->i_flags &= ~S_IMMUTABLE;
7751 +       if (ip->i_d.di_flags & XFS_DIFLAG_IXUNLINK)
7752 +               inode->i_flags |= S_IXUNLINK;
7753 +       else
7754 +               inode->i_flags &= ~S_IXUNLINK;
7755         if (ip->i_d.di_flags & XFS_DIFLAG_APPEND)
7756                 inode->i_flags |= S_APPEND;
7757         else
7758 @@ -1122,6 +1131,15 @@ xfs_diflags_to_iflags(
7759                 inode->i_flags |= S_NOATIME;
7760         else
7761                 inode->i_flags &= ~S_NOATIME;
7762 +
7763 +       if (ip->i_d.di_vflags & XFS_DIVFLAG_BARRIER)
7764 +               inode->i_vflags |= V_BARRIER;
7765 +       else
7766 +               inode->i_vflags &= ~V_BARRIER;
7767 +       if (ip->i_d.di_vflags & XFS_DIVFLAG_COW)
7768 +               inode->i_vflags |= V_COW;
7769 +       else
7770 +               inode->i_vflags &= ~V_COW;
7771  }
7772  
7773  /*
7774 @@ -1153,6 +1171,7 @@ xfs_setup_inode(
7775         set_nlink(inode, ip->i_d.di_nlink);
7776         inode->i_uid    = ip->i_d.di_uid;
7777         inode->i_gid    = ip->i_d.di_gid;
7778 +       inode->i_tag    = ip->i_d.di_tag;
7779  
7780         switch (inode->i_mode & S_IFMT) {
7781         case S_IFBLK:
7782 diff -NurpP --minimal linux-3.6.10/fs/xfs/xfs_itable.c linux-3.6.10-vs2.3.4.5/fs/xfs/xfs_itable.c
7783 --- linux-3.6.10/fs/xfs/xfs_itable.c    2012-10-04 15:27:44.000000000 +0200
7784 +++ linux-3.6.10-vs2.3.4.5/fs/xfs/xfs_itable.c  2012-10-04 18:47:00.000000000 +0200
7785 @@ -96,6 +96,7 @@ xfs_bulkstat_one_int(
7786         buf->bs_mode = dic->di_mode;
7787         buf->bs_uid = dic->di_uid;
7788         buf->bs_gid = dic->di_gid;
7789 +       buf->bs_tag = dic->di_tag;
7790         buf->bs_size = dic->di_size;
7791         buf->bs_atime.tv_sec = dic->di_atime.t_sec;
7792         buf->bs_atime.tv_nsec = dic->di_atime.t_nsec;
7793 diff -NurpP --minimal linux-3.6.10/fs/xfs/xfs_linux.h linux-3.6.10-vs2.3.4.5/fs/xfs/xfs_linux.h
7794 --- linux-3.6.10/fs/xfs/xfs_linux.h     2011-10-24 18:45:31.000000000 +0200
7795 +++ linux-3.6.10-vs2.3.4.5/fs/xfs/xfs_linux.h   2012-10-04 18:47:00.000000000 +0200
7796 @@ -121,6 +121,7 @@
7797  
7798  #define current_cpu()          (raw_smp_processor_id())
7799  #define current_pid()          (current->pid)
7800 +#define current_fstag(vp)      (dx_current_fstag((vp)->i_sb))
7801  #define current_test_flags(f)  (current->flags & (f))
7802  #define current_set_flags_nested(sp, f)                \
7803                 (*(sp) = current->flags, current->flags |= (f))
7804 diff -NurpP --minimal linux-3.6.10/fs/xfs/xfs_log_recover.c linux-3.6.10-vs2.3.4.5/fs/xfs/xfs_log_recover.c
7805 --- linux-3.6.10/fs/xfs/xfs_log_recover.c       2012-12-11 12:36:58.000000000 +0100
7806 +++ linux-3.6.10-vs2.3.4.5/fs/xfs/xfs_log_recover.c     2012-12-08 01:36:33.000000000 +0100
7807 @@ -2359,7 +2359,8 @@ xlog_recover_inode_pass2(
7808         }
7809  
7810         /* The core is in in-core format */
7811 -       xfs_dinode_to_disk(dip, item->ri_buf[1].i_addr);
7812 +       xfs_dinode_to_disk(dip, item->ri_buf[1].i_addr,
7813 +               mp->m_flags & XFS_MOUNT_TAGGED);
7814  
7815         /* the rest is in on-disk format */
7816         if (item->ri_buf[1].i_len > sizeof(struct xfs_icdinode)) {
7817 diff -NurpP --minimal linux-3.6.10/fs/xfs/xfs_mount.h linux-3.6.10-vs2.3.4.5/fs/xfs/xfs_mount.h
7818 --- linux-3.6.10/fs/xfs/xfs_mount.h     2012-10-04 15:27:44.000000000 +0200
7819 +++ linux-3.6.10-vs2.3.4.5/fs/xfs/xfs_mount.h   2012-10-04 18:47:00.000000000 +0200
7820 @@ -251,6 +251,7 @@ typedef struct xfs_mount {
7821                                                    allocator */
7822  #define XFS_MOUNT_NOATTR2      (1ULL << 25)    /* disable use of attr2 format */
7823  
7824 +#define XFS_MOUNT_TAGGED       (1ULL << 31)    /* context tagging */
7825  
7826  /*
7827   * Default minimum read and write sizes.
7828 diff -NurpP --minimal linux-3.6.10/fs/xfs/xfs_super.c linux-3.6.10-vs2.3.4.5/fs/xfs/xfs_super.c
7829 --- linux-3.6.10/fs/xfs/xfs_super.c     2012-10-04 15:27:44.000000000 +0200
7830 +++ linux-3.6.10-vs2.3.4.5/fs/xfs/xfs_super.c   2012-10-04 18:47:00.000000000 +0200
7831 @@ -112,6 +112,9 @@ mempool_t *xfs_ioend_pool;
7832  #define MNTOPT_NODELAYLOG  "nodelaylog"        /* Delayed logging disabled */
7833  #define MNTOPT_DISCARD    "discard"    /* Discard unused blocks */
7834  #define MNTOPT_NODISCARD   "nodiscard" /* Do not discard unused blocks */
7835 +#define MNTOPT_TAGXID  "tagxid"        /* context tagging for inodes */
7836 +#define MNTOPT_TAGGED  "tag"           /* context tagging for inodes */
7837 +#define MNTOPT_NOTAGTAG        "notag"         /* do not use context tagging */
7838  
7839  /*
7840   * Table driven mount option parser.
7841 @@ -120,10 +123,14 @@ mempool_t *xfs_ioend_pool;
7842   * in the future, too.
7843   */
7844  enum {
7845 +       Opt_tag, Opt_notag,
7846         Opt_barrier, Opt_nobarrier, Opt_err
7847  };
7848  
7849  static const match_table_t tokens = {
7850 +       {Opt_tag, "tagxid"},
7851 +       {Opt_tag, "tag"},
7852 +       {Opt_notag, "notag"},
7853         {Opt_barrier, "barrier"},
7854         {Opt_nobarrier, "nobarrier"},
7855         {Opt_err, NULL}
7856 @@ -371,6 +378,19 @@ xfs_parseargs(
7857                 } else if (!strcmp(this_char, "irixsgid")) {
7858                         xfs_warn(mp,
7859         "irixsgid is now a sysctl(2) variable, option is deprecated.");
7860 +#ifndef CONFIG_TAGGING_NONE
7861 +               } else if (!strcmp(this_char, MNTOPT_TAGGED)) {
7862 +                       mp->m_flags |= XFS_MOUNT_TAGGED;
7863 +               } else if (!strcmp(this_char, MNTOPT_NOTAGTAG)) {
7864 +                       mp->m_flags &= ~XFS_MOUNT_TAGGED;
7865 +               } else if (!strcmp(this_char, MNTOPT_TAGXID)) {
7866 +                       mp->m_flags |= XFS_MOUNT_TAGGED;
7867 +#endif
7868 +#ifdef CONFIG_PROPAGATE
7869 +               } else if (!strcmp(this_char, MNTOPT_TAGGED)) {
7870 +                       /* use value */
7871 +                       mp->m_flags |= XFS_MOUNT_TAGGED;
7872 +#endif
7873                 } else {
7874                         xfs_warn(mp, "unknown mount option [%s].", this_char);
7875                         return EINVAL;
7876 @@ -1056,6 +1076,16 @@ xfs_fs_remount(
7877                 case Opt_nobarrier:
7878                         mp->m_flags &= ~XFS_MOUNT_BARRIER;
7879                         break;
7880 +               case Opt_tag:
7881 +                       if (!(sb->s_flags & MS_TAGGED)) {
7882 +                               printk(KERN_INFO
7883 +                                       "XFS: %s: tagging not permitted on remount.\n",
7884 +                                       sb->s_id);
7885 +                               return -EINVAL;
7886 +                       }
7887 +                       break;
7888 +               case Opt_notag:
7889 +                       break;
7890                 default:
7891                         /*
7892                          * Logically we would return an error here to prevent
7893 @@ -1275,6 +1305,9 @@ xfs_fs_fill_super(
7894         if (error)
7895                 goto out_free_sb;
7896  
7897 +       if (mp->m_flags & XFS_MOUNT_TAGGED)
7898 +               sb->s_flags |= MS_TAGGED;
7899 +
7900         /*
7901          * we must configure the block size in the superblock before we run the
7902          * full mount process as the mount process can lookup and cache inodes.
7903 diff -NurpP --minimal linux-3.6.10/fs/xfs/xfs_vnodeops.c linux-3.6.10-vs2.3.4.5/fs/xfs/xfs_vnodeops.c
7904 --- linux-3.6.10/fs/xfs/xfs_vnodeops.c  2012-10-04 15:27:44.000000000 +0200
7905 +++ linux-3.6.10-vs2.3.4.5/fs/xfs/xfs_vnodeops.c        2012-10-04 18:47:00.000000000 +0200
7906 @@ -103,6 +103,77 @@ xfs_readlink_bmap(
7907         return error;
7908  }
7909  
7910 +
7911 +STATIC void
7912 +xfs_get_inode_flags(
7913 +       xfs_inode_t     *ip)
7914 +{
7915 +       struct inode    *inode = VFS_I(ip);
7916 +       unsigned int    flags = inode->i_flags;
7917 +       unsigned int    vflags = inode->i_vflags;
7918 +
7919 +       if (flags & S_IMMUTABLE)
7920 +               ip->i_d.di_flags |= XFS_DIFLAG_IMMUTABLE;
7921 +       else
7922 +               ip->i_d.di_flags &= ~XFS_DIFLAG_IMMUTABLE;
7923 +       if (flags & S_IXUNLINK)
7924 +               ip->i_d.di_flags |= XFS_DIFLAG_IXUNLINK;
7925 +       else
7926 +               ip->i_d.di_flags &= ~XFS_DIFLAG_IXUNLINK;
7927 +
7928 +       if (vflags & V_BARRIER)
7929 +               ip->i_d.di_vflags |= XFS_DIVFLAG_BARRIER;
7930 +       else
7931 +               ip->i_d.di_vflags &= ~XFS_DIVFLAG_BARRIER;
7932 +       if (vflags & V_COW)
7933 +               ip->i_d.di_vflags |= XFS_DIVFLAG_COW;
7934 +       else
7935 +               ip->i_d.di_vflags &= ~XFS_DIVFLAG_COW;
7936 +}
7937 +
7938 +int
7939 +xfs_sync_flags(
7940 +       struct inode            *inode,
7941 +       int                     flags,
7942 +       int                     vflags)
7943 +{
7944 +       struct xfs_inode        *ip = XFS_I(inode);
7945 +       struct xfs_mount        *mp = ip->i_mount;
7946 +       struct xfs_trans        *tp;
7947 +       unsigned int            lock_flags = 0;
7948 +       int                     code;
7949 +
7950 +       tp = xfs_trans_alloc(mp, XFS_TRANS_SETATTR_NOT_SIZE);
7951 +       code = xfs_trans_reserve(tp, 0, XFS_ICHANGE_LOG_RES(mp), 0, 0, 0);
7952 +       if (code)
7953 +               goto error_out;
7954 +
7955 +       xfs_ilock(ip, XFS_ILOCK_EXCL);
7956 +       xfs_trans_ijoin(tp, ip, 0);
7957 +
7958 +       inode->i_flags = flags;
7959 +       inode->i_vflags = vflags;
7960 +       xfs_get_inode_flags(ip);
7961 +
7962 +       xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE);
7963 +       xfs_trans_ichgtime(tp, ip, XFS_ICHGTIME_CHG);
7964 +
7965 +       XFS_STATS_INC(xs_ig_attrchg);
7966 +
7967 +       if (mp->m_flags & XFS_MOUNT_WSYNC)
7968 +               xfs_trans_set_sync(tp);
7969 +       code = xfs_trans_commit(tp, 0);
7970 +       xfs_iunlock(ip, XFS_ILOCK_EXCL);
7971 +       return code;
7972 +
7973 +error_out:
7974 +       xfs_trans_cancel(tp, 0);
7975 +       if (lock_flags)
7976 +               xfs_iunlock(ip, XFS_ILOCK_EXCL);
7977 +       return code;
7978 +}
7979 +
7980 +
7981  int
7982  xfs_readlink(
7983         xfs_inode_t     *ip,
7984 diff -NurpP --minimal linux-3.6.10/include/linux/Kbuild linux-3.6.10-vs2.3.4.5/include/linux/Kbuild
7985 --- linux-3.6.10/include/linux/Kbuild   2012-10-04 15:27:45.000000000 +0200
7986 +++ linux-3.6.10-vs2.3.4.5/include/linux/Kbuild 2012-10-04 18:47:00.000000000 +0200
7987 @@ -18,6 +18,7 @@ header-y += netfilter_bridge/
7988  header-y += netfilter_ipv4/
7989  header-y += netfilter_ipv6/
7990  header-y += usb/
7991 +header-y += vserver/
7992  header-y += wimax/
7993  
7994  objhdr-y += version.h
7995 diff -NurpP --minimal linux-3.6.10/include/linux/capability.h linux-3.6.10-vs2.3.4.5/include/linux/capability.h
7996 --- linux-3.6.10/include/linux/capability.h     2012-07-22 23:39:43.000000000 +0200
7997 +++ linux-3.6.10-vs2.3.4.5/include/linux/capability.h   2012-10-04 18:47:00.000000000 +0200
7998 @@ -280,6 +280,7 @@ struct cpu_vfs_cap_data {
7999     arbitrary SCSI commands */
8000  /* Allow setting encryption key on loopback filesystem */
8001  /* Allow setting zone reclaim policy */
8002 +/* Allow the selection of a security context */
8003  
8004  #define CAP_SYS_ADMIN        21
8005  
8006 @@ -366,7 +367,12 @@ struct cpu_vfs_cap_data {
8007  
8008  #define CAP_LAST_CAP         CAP_BLOCK_SUSPEND
8009  
8010 -#define cap_valid(x) ((x) >= 0 && (x) <= CAP_LAST_CAP)
8011 +/* Allow context manipulations */
8012 +/* Allow changing context info on files */
8013 +
8014 +#define CAP_CONTEXT         63
8015 +
8016 +#define cap_valid(x) ((x) >= 0 && ((x) <= CAP_LAST_CAP || (x) == CAP_CONTEXT))
8017  
8018  /*
8019   * Bit location of each capability (used by user-space library and kernel)
8020 diff -NurpP --minimal linux-3.6.10/include/linux/cred.h linux-3.6.10-vs2.3.4.5/include/linux/cred.h
8021 --- linux-3.6.10/include/linux/cred.h   2012-07-22 23:39:43.000000000 +0200
8022 +++ linux-3.6.10-vs2.3.4.5/include/linux/cred.h 2012-10-04 18:47:00.000000000 +0200
8023 @@ -157,6 +157,7 @@ extern void exit_creds(struct task_struc
8024  extern int copy_creds(struct task_struct *, unsigned long);
8025  extern const struct cred *get_task_cred(struct task_struct *);
8026  extern struct cred *cred_alloc_blank(void);
8027 +extern struct cred *__prepare_creds(const struct cred *);
8028  extern struct cred *prepare_creds(void);
8029  extern struct cred *prepare_exec_creds(void);
8030  extern int commit_creds(struct cred *);
8031 @@ -210,6 +211,31 @@ static inline void validate_process_cred
8032  }
8033  #endif
8034  
8035 +static inline void set_cred_subscribers(struct cred *cred, int n)
8036 +{
8037 +#ifdef CONFIG_DEBUG_CREDENTIALS
8038 +       atomic_set(&cred->subscribers, n);
8039 +#endif
8040 +}
8041 +
8042 +static inline int read_cred_subscribers(const struct cred *cred)
8043 +{
8044 +#ifdef CONFIG_DEBUG_CREDENTIALS
8045 +       return atomic_read(&cred->subscribers);
8046 +#else
8047 +       return 0;
8048 +#endif
8049 +}
8050 +
8051 +static inline void alter_cred_subscribers(const struct cred *_cred, int n)
8052 +{
8053 +#ifdef CONFIG_DEBUG_CREDENTIALS
8054 +       struct cred *cred = (struct cred *) _cred;
8055 +
8056 +       atomic_add(n, &cred->subscribers);
8057 +#endif
8058 +}
8059 +
8060  /**
8061   * get_new_cred - Get a reference on a new set of credentials
8062   * @cred: The new credentials to reference
8063 diff -NurpP --minimal linux-3.6.10/include/linux/devpts_fs.h linux-3.6.10-vs2.3.4.5/include/linux/devpts_fs.h
8064 --- linux-3.6.10/include/linux/devpts_fs.h      2008-12-25 00:26:37.000000000 +0100
8065 +++ linux-3.6.10-vs2.3.4.5/include/linux/devpts_fs.h    2012-10-04 18:47:00.000000000 +0200
8066 @@ -45,5 +45,4 @@ static inline void devpts_pty_kill(struc
8067  
8068  #endif
8069  
8070 -
8071  #endif /* _LINUX_DEVPTS_FS_H */
8072 diff -NurpP --minimal linux-3.6.10/include/linux/fs.h linux-3.6.10-vs2.3.4.5/include/linux/fs.h
8073 --- linux-3.6.10/include/linux/fs.h     2012-10-04 15:27:45.000000000 +0200
8074 +++ linux-3.6.10-vs2.3.4.5/include/linux/fs.h   2012-10-04 18:47:00.000000000 +0200
8075 @@ -225,6 +225,9 @@ struct inodes_stat_t {
8076  #define MS_KERNMOUNT   (1<<22) /* this is a kern_mount call */
8077  #define MS_I_VERSION   (1<<23) /* Update inode I_version field */
8078  #define MS_STRICTATIME (1<<24) /* Always perform atime updates */
8079 +#define MS_TAGGED      (1<<25) /* use generic inode tagging */
8080 +#define MS_TAGID       (1<<26) /* use specific tag for this mount */
8081 +#define MS_NOTAGCHECK  (1<<27) /* don't check tags */
8082  #define MS_NOSEC       (1<<28)
8083  #define MS_BORN                (1<<29)
8084  #define MS_ACTIVE      (1<<30)
8085 @@ -256,6 +259,14 @@ struct inodes_stat_t {
8086  #define S_IMA          1024    /* Inode has an associated IMA struct */
8087  #define S_AUTOMOUNT    2048    /* Automount/referral quasi-directory */
8088  #define S_NOSEC                4096    /* no suid or xattr security attributes */
8089 +#define S_IXUNLINK     8192    /* Immutable Invert on unlink */
8090 +
8091 +/* Linux-VServer related Inode flags */
8092 +
8093 +#define V_VALID                1
8094 +#define V_XATTR                2
8095 +#define V_BARRIER      4       /* Barrier for chroot() */
8096 +#define V_COW          8       /* Copy on Write */
8097  
8098  /*
8099   * Note that nosuid etc flags are inode-specific: setting some file-system
8100 @@ -278,12 +289,15 @@ struct inodes_stat_t {
8101  #define IS_DIRSYNC(inode)      (__IS_FLG(inode, MS_SYNCHRONOUS|MS_DIRSYNC) || \
8102                                         ((inode)->i_flags & (S_SYNC|S_DIRSYNC)))
8103  #define IS_MANDLOCK(inode)     __IS_FLG(inode, MS_MANDLOCK)
8104 -#define IS_NOATIME(inode)   __IS_FLG(inode, MS_RDONLY|MS_NOATIME)
8105 -#define IS_I_VERSION(inode)   __IS_FLG(inode, MS_I_VERSION)
8106 +#define IS_NOATIME(inode)      __IS_FLG(inode, MS_RDONLY|MS_NOATIME)
8107 +#define IS_I_VERSION(inode)    __IS_FLG(inode, MS_I_VERSION)
8108 +#define IS_TAGGED(inode)       __IS_FLG(inode, MS_TAGGED)
8109  
8110  #define IS_NOQUOTA(inode)      ((inode)->i_flags & S_NOQUOTA)
8111  #define IS_APPEND(inode)       ((inode)->i_flags & S_APPEND)
8112  #define IS_IMMUTABLE(inode)    ((inode)->i_flags & S_IMMUTABLE)
8113 +#define IS_IXUNLINK(inode)     ((inode)->i_flags & S_IXUNLINK)
8114 +#define IS_IXORUNLINK(inode)   ((IS_IXUNLINK(inode) ? S_IMMUTABLE : 0) ^ IS_IMMUTABLE(inode))
8115  #define IS_POSIXACL(inode)     __IS_FLG(inode, MS_POSIXACL)
8116  
8117  #define IS_DEADDIR(inode)      ((inode)->i_flags & S_DEAD)
8118 @@ -294,6 +308,16 @@ struct inodes_stat_t {
8119  #define IS_AUTOMOUNT(inode)    ((inode)->i_flags & S_AUTOMOUNT)
8120  #define IS_NOSEC(inode)                ((inode)->i_flags & S_NOSEC)
8121  
8122 +#define IS_BARRIER(inode)      (S_ISDIR((inode)->i_mode) && ((inode)->i_vflags & V_BARRIER))
8123 +
8124 +#ifdef CONFIG_VSERVER_COWBL
8125 +#  define IS_COW(inode)                (IS_IXUNLINK(inode) && IS_IMMUTABLE(inode))
8126 +#  define IS_COW_LINK(inode)   (S_ISREG((inode)->i_mode) && ((inode)->i_nlink > 1))
8127 +#else
8128 +#  define IS_COW(inode)                (0)
8129 +#  define IS_COW_LINK(inode)   (0)
8130 +#endif
8131 +
8132  /* the read-only stuff doesn't really belong here, but any other place is
8133     probably as bad and I don't want to create yet another include file. */
8134  
8135 @@ -380,11 +404,14 @@ struct inodes_stat_t {
8136  #define FS_EXTENT_FL                   0x00080000 /* Extents */
8137  #define FS_DIRECTIO_FL                 0x00100000 /* Use direct i/o */
8138  #define FS_NOCOW_FL                    0x00800000 /* Do not cow file */
8139 +#define FS_IXUNLINK_FL                 0x08000000 /* Immutable invert on unlink */
8140  #define FS_RESERVED_FL                 0x80000000 /* reserved for ext2 lib */
8141  
8142 -#define FS_FL_USER_VISIBLE             0x0003DFFF /* User visible flags */
8143 -#define FS_FL_USER_MODIFIABLE          0x000380FF /* User modifiable flags */
8144 +#define FS_BARRIER_FL                  0x04000000 /* Barrier for chroot() */
8145 +#define FS_COW_FL                      0x20000000 /* Copy on Write marker */
8146  
8147 +#define FS_FL_USER_VISIBLE             0x0103DFFF /* User visible flags */
8148 +#define FS_FL_USER_MODIFIABLE          0x010380FF /* User modifiable flags */
8149  
8150  #define SYNC_FILE_RANGE_WAIT_BEFORE    1
8151  #define SYNC_FILE_RANGE_WRITE          2
8152 @@ -472,6 +499,7 @@ typedef void (dio_iodone_t)(struct kiocb
8153  #define ATTR_KILL_PRIV (1 << 14)
8154  #define ATTR_OPEN      (1 << 15) /* Truncating from open(O_TRUNC) */
8155  #define ATTR_TIMES_SET (1 << 16)
8156 +#define ATTR_TAG       (1 << 17)
8157  
8158  /*
8159   * This is the Inode Attributes structure, used for notify_change().  It
8160 @@ -487,6 +515,7 @@ struct iattr {
8161         umode_t         ia_mode;
8162         kuid_t          ia_uid;
8163         kgid_t          ia_gid;
8164 +       tag_t           ia_tag;
8165         loff_t          ia_size;
8166         struct timespec ia_atime;
8167         struct timespec ia_mtime;
8168 @@ -500,6 +529,9 @@ struct iattr {
8169         struct file     *ia_file;
8170  };
8171  
8172 +#define ATTR_FLAG_BARRIER      512     /* Barrier for chroot() */
8173 +#define ATTR_FLAG_IXUNLINK     1024    /* Immutable invert on unlink */
8174 +
8175  /*
8176   * Includes for diskquotas.
8177   */
8178 @@ -784,7 +816,9 @@ struct inode {
8179         unsigned short          i_opflags;
8180         kuid_t                  i_uid;
8181         kgid_t                  i_gid;
8182 -       unsigned int            i_flags;
8183 +       tag_t                   i_tag;
8184 +       unsigned short          i_flags;
8185 +       unsigned short          i_vflags;
8186  
8187  #ifdef CONFIG_FS_POSIX_ACL
8188         struct posix_acl        *i_acl;
8189 @@ -813,6 +847,7 @@ struct inode {
8190                 unsigned int __i_nlink;
8191         };
8192         dev_t                   i_rdev;
8193 +       dev_t                   i_mdev;
8194         loff_t                  i_size;
8195         struct timespec         i_atime;
8196         struct timespec         i_mtime;
8197 @@ -975,12 +1010,12 @@ static inline void i_gid_write(struct in
8198  
8199  static inline unsigned iminor(const struct inode *inode)
8200  {
8201 -       return MINOR(inode->i_rdev);
8202 +       return MINOR(inode->i_mdev);
8203  }
8204  
8205  static inline unsigned imajor(const struct inode *inode)
8206  {
8207 -       return MAJOR(inode->i_rdev);
8208 +       return MAJOR(inode->i_mdev);
8209  }
8210  
8211  extern struct block_device *I_BDEV(struct inode *inode);
8212 @@ -1047,6 +1082,7 @@ struct file {
8213         loff_t                  f_pos;
8214         struct fown_struct      f_owner;
8215         const struct cred       *f_cred;
8216 +       xid_t                   f_xid;
8217         struct file_ra_state    f_ra;
8218  
8219         u64                     f_version;
8220 @@ -1194,6 +1230,7 @@ struct file_lock {
8221         struct file *fl_file;
8222         loff_t fl_start;
8223         loff_t fl_end;
8224 +       xid_t fl_xid;
8225  
8226         struct fasync_struct *  fl_fasync; /* for lease break notifications */
8227         /* for lease breaks: */
8228 @@ -1829,6 +1866,7 @@ struct inode_operations {
8229         ssize_t (*getxattr) (struct dentry *, const char *, void *, size_t);
8230         ssize_t (*listxattr) (struct dentry *, char *, size_t);
8231         int (*removexattr) (struct dentry *, const char *);
8232 +       int (*sync_flags) (struct inode *, int, int);
8233         int (*fiemap)(struct inode *, struct fiemap_extent_info *, u64 start,
8234                       u64 len);
8235         int (*update_time)(struct inode *, struct timespec *, int);
8236 @@ -1850,6 +1888,7 @@ extern ssize_t vfs_readv(struct file *, 
8237                 unsigned long, loff_t *);
8238  extern ssize_t vfs_writev(struct file *, const struct iovec __user *,
8239                 unsigned long, loff_t *);
8240 +ssize_t vfs_sendfile(struct file *, struct file *, loff_t *, size_t, loff_t);
8241  
8242  struct super_operations {
8243         struct inode *(*alloc_inode)(struct super_block *sb);
8244 @@ -2692,6 +2731,7 @@ extern int dcache_dir_open(struct inode 
8245  extern int dcache_dir_close(struct inode *, struct file *);
8246  extern loff_t dcache_dir_lseek(struct file *, loff_t, int);
8247  extern int dcache_readdir(struct file *, void *, filldir_t);
8248 +extern int dcache_readdir_filter(struct file *, void *, filldir_t, int (*)(struct dentry *));
8249  extern int simple_setattr(struct dentry *, struct iattr *);
8250  extern int simple_getattr(struct vfsmount *, struct dentry *, struct kstat *);
8251  extern int simple_statfs(struct dentry *, struct kstatfs *);
8252 diff -NurpP --minimal linux-3.6.10/include/linux/gfs2_ondisk.h linux-3.6.10-vs2.3.4.5/include/linux/gfs2_ondisk.h
8253 --- linux-3.6.10/include/linux/gfs2_ondisk.h    2012-10-04 15:27:45.000000000 +0200
8254 +++ linux-3.6.10-vs2.3.4.5/include/linux/gfs2_ondisk.h  2012-10-04 18:54:29.000000000 +0200
8255 @@ -225,6 +225,9 @@ enum {
8256         gfs2fl_Sync             = 8,
8257         gfs2fl_System           = 9,
8258         gfs2fl_TopLevel         = 10,
8259 +       gfs2fl_IXUnlink         = 16,
8260 +       gfs2fl_Barrier          = 17,
8261 +       gfs2fl_Cow              = 18,
8262         gfs2fl_TruncInProg      = 29,
8263         gfs2fl_InheritDirectio  = 30,
8264         gfs2fl_InheritJdata     = 31,
8265 @@ -242,6 +245,9 @@ enum {
8266  #define GFS2_DIF_SYNC                  0x00000100
8267  #define GFS2_DIF_SYSTEM                        0x00000200 /* New in gfs2 */
8268  #define GFS2_DIF_TOPDIR                        0x00000400 /* New in gfs2 */
8269 +#define GFS2_DIF_IXUNLINK              0x00010000
8270 +#define GFS2_DIF_BARRIER               0x00020000
8271 +#define GFS2_DIF_COW                   0x00040000
8272  #define GFS2_DIF_TRUNC_IN_PROG         0x20000000 /* New in gfs2 */
8273  #define GFS2_DIF_INHERIT_DIRECTIO      0x40000000 /* only in gfs1 */
8274  #define GFS2_DIF_INHERIT_JDATA         0x80000000
8275 diff -NurpP --minimal linux-3.6.10/include/linux/if_tun.h linux-3.6.10-vs2.3.4.5/include/linux/if_tun.h
8276 --- linux-3.6.10/include/linux/if_tun.h 2010-08-02 16:52:54.000000000 +0200
8277 +++ linux-3.6.10-vs2.3.4.5/include/linux/if_tun.h       2012-10-04 18:47:00.000000000 +0200
8278 @@ -53,6 +53,7 @@
8279  #define TUNDETACHFILTER _IOW('T', 214, struct sock_fprog)
8280  #define TUNGETVNETHDRSZ _IOR('T', 215, int)
8281  #define TUNSETVNETHDRSZ _IOW('T', 216, int)
8282 +#define TUNSETNID     _IOW('T', 217, int)
8283  
8284  /* TUNSETIFF ifr flags */
8285  #define IFF_TUN                0x0001
8286 diff -NurpP --minimal linux-3.6.10/include/linux/init_task.h linux-3.6.10-vs2.3.4.5/include/linux/init_task.h
8287 --- linux-3.6.10/include/linux/init_task.h      2012-10-04 15:27:45.000000000 +0200
8288 +++ linux-3.6.10-vs2.3.4.5/include/linux/init_task.h    2012-10-04 18:47:00.000000000 +0200
8289 @@ -210,6 +210,10 @@ extern struct task_group root_task_group
8290         INIT_TRACE_RECURSION                                            \
8291         INIT_TASK_RCU_PREEMPT(tsk)                                      \
8292         INIT_CPUSET_SEQ                                                 \
8293 +       .xid            = 0,                                            \
8294 +       .vx_info        = NULL,                                         \
8295 +       .nid            = 0,                                            \
8296 +       .nx_info        = NULL,                                         \
8297  }
8298  
8299  
8300 diff -NurpP --minimal linux-3.6.10/include/linux/ipc.h linux-3.6.10-vs2.3.4.5/include/linux/ipc.h
8301 --- linux-3.6.10/include/linux/ipc.h    2012-03-19 19:47:28.000000000 +0100
8302 +++ linux-3.6.10-vs2.3.4.5/include/linux/ipc.h  2012-10-04 18:47:00.000000000 +0200
8303 @@ -91,6 +91,7 @@ struct kern_ipc_perm
8304         key_t           key;
8305         uid_t           uid;
8306         gid_t           gid;
8307 +       xid_t           xid;
8308         uid_t           cuid;
8309         gid_t           cgid;
8310         umode_t         mode; 
8311 diff -NurpP --minimal linux-3.6.10/include/linux/ipc_namespace.h linux-3.6.10-vs2.3.4.5/include/linux/ipc_namespace.h
8312 --- linux-3.6.10/include/linux/ipc_namespace.h  2012-07-22 23:39:43.000000000 +0200
8313 +++ linux-3.6.10-vs2.3.4.5/include/linux/ipc_namespace.h        2012-10-04 18:47:00.000000000 +0200
8314 @@ -133,7 +133,8 @@ static inline int mq_init_ns(struct ipc_
8315  
8316  #if defined(CONFIG_IPC_NS)
8317  extern struct ipc_namespace *copy_ipcs(unsigned long flags,
8318 -                                      struct task_struct *tsk);
8319 +                                      struct ipc_namespace *old_ns,
8320 +                                      struct user_namespace *user_ns);
8321  static inline struct ipc_namespace *get_ipc_ns(struct ipc_namespace *ns)
8322  {
8323         if (ns)
8324 @@ -144,12 +145,13 @@ static inline struct ipc_namespace *get_
8325  extern void put_ipc_ns(struct ipc_namespace *ns);
8326  #else
8327  static inline struct ipc_namespace *copy_ipcs(unsigned long flags,
8328 -                                             struct task_struct *tsk)
8329 +                                             struct ipc_namespace *old_ns,
8330 +                                             struct user_namespace *user_ns)
8331  {
8332         if (flags & CLONE_NEWIPC)
8333                 return ERR_PTR(-EINVAL);
8334  
8335 -       return tsk->nsproxy->ipc_ns;
8336 +       return old_ns;
8337  }
8338  
8339  static inline struct ipc_namespace *get_ipc_ns(struct ipc_namespace *ns)
8340 diff -NurpP --minimal linux-3.6.10/include/linux/loop.h linux-3.6.10-vs2.3.4.5/include/linux/loop.h
8341 --- linux-3.6.10/include/linux/loop.h   2012-01-09 16:14:58.000000000 +0100
8342 +++ linux-3.6.10-vs2.3.4.5/include/linux/loop.h 2012-10-04 18:47:00.000000000 +0200
8343 @@ -45,6 +45,7 @@ struct loop_device {
8344         struct loop_func_table *lo_encryption;
8345         __u32           lo_init[2];
8346         uid_t           lo_key_owner;   /* Who set the key */
8347 +       xid_t           lo_xid;
8348         int             (*ioctl)(struct loop_device *, int cmd, 
8349                                  unsigned long arg); 
8350  
8351 diff -NurpP --minimal linux-3.6.10/include/linux/magic.h linux-3.6.10-vs2.3.4.5/include/linux/magic.h
8352 --- linux-3.6.10/include/linux/magic.h  2012-05-21 18:07:31.000000000 +0200
8353 +++ linux-3.6.10-vs2.3.4.5/include/linux/magic.h        2012-10-04 18:47:00.000000000 +0200
8354 @@ -3,7 +3,7 @@
8355  
8356  #define ADFS_SUPER_MAGIC       0xadf5
8357  #define AFFS_SUPER_MAGIC       0xadff
8358 -#define AFS_SUPER_MAGIC                0x5346414F
8359 +#define AFS_SUPER_MAGIC                0x5346414F
8360  #define AUTOFS_SUPER_MAGIC     0x0187
8361  #define CODA_SUPER_MAGIC       0x73757245
8362  #define CRAMFS_MAGIC           0x28cd3d45      /* some random number */
8363 diff -NurpP --minimal linux-3.6.10/include/linux/major.h linux-3.6.10-vs2.3.4.5/include/linux/major.h
8364 --- linux-3.6.10/include/linux/major.h  2009-09-10 15:26:25.000000000 +0200
8365 +++ linux-3.6.10-vs2.3.4.5/include/linux/major.h        2012-10-04 18:47:00.000000000 +0200
8366 @@ -15,6 +15,7 @@
8367  #define HD_MAJOR               IDE0_MAJOR
8368  #define PTY_SLAVE_MAJOR                3
8369  #define TTY_MAJOR              4
8370 +#define VROOT_MAJOR            4
8371  #define TTYAUX_MAJOR           5
8372  #define LP_MAJOR               6
8373  #define VCS_MAJOR              7
8374 diff -NurpP --minimal linux-3.6.10/include/linux/memcontrol.h linux-3.6.10-vs2.3.4.5/include/linux/memcontrol.h
8375 --- linux-3.6.10/include/linux/memcontrol.h     2012-10-04 15:27:45.000000000 +0200
8376 +++ linux-3.6.10-vs2.3.4.5/include/linux/memcontrol.h   2012-10-04 18:47:00.000000000 +0200
8377 @@ -83,6 +83,13 @@ extern struct mem_cgroup *try_get_mem_cg
8378  extern struct mem_cgroup *parent_mem_cgroup(struct mem_cgroup *memcg);
8379  extern struct mem_cgroup *mem_cgroup_from_cont(struct cgroup *cont);
8380  
8381 +extern u64 mem_cgroup_res_read_u64(struct mem_cgroup *mem, int member);
8382 +extern u64 mem_cgroup_memsw_read_u64(struct mem_cgroup *mem, int member);
8383 +
8384 +extern s64 mem_cgroup_stat_read_cache(struct mem_cgroup *mem);
8385 +extern s64 mem_cgroup_stat_read_anon(struct mem_cgroup *mem);
8386 +extern s64 mem_cgroup_stat_read_mapped(struct mem_cgroup *mem);
8387 +
8388  static inline
8389  int mm_match_cgroup(const struct mm_struct *mm, const struct mem_cgroup *cgroup)
8390  {
8391 diff -NurpP --minimal linux-3.6.10/include/linux/mm_types.h linux-3.6.10-vs2.3.4.5/include/linux/mm_types.h
8392 --- linux-3.6.10/include/linux/mm_types.h       2012-10-04 15:27:46.000000000 +0200
8393 +++ linux-3.6.10-vs2.3.4.5/include/linux/mm_types.h     2012-10-04 18:47:00.000000000 +0200
8394 @@ -370,6 +370,7 @@ struct mm_struct {
8395  
8396         /* Architecture-specific MM context */
8397         mm_context_t context;
8398 +       struct vx_info *mm_vx_info;
8399  
8400         unsigned long flags; /* Must use atomic bitops to access the bits */
8401  
8402 diff -NurpP --minimal linux-3.6.10/include/linux/mmzone.h linux-3.6.10-vs2.3.4.5/include/linux/mmzone.h
8403 --- linux-3.6.10/include/linux/mmzone.h 2012-12-11 12:36:59.000000000 +0100
8404 +++ linux-3.6.10-vs2.3.4.5/include/linux/mmzone.h       2012-12-08 01:36:33.000000000 +0100
8405 @@ -727,6 +727,13 @@ typedef struct pglist_data {
8406         __pgdat->node_start_pfn + __pgdat->node_spanned_pages;\
8407  })
8408  
8409 +#define node_start_pfn(nid)    (NODE_DATA(nid)->node_start_pfn)
8410 +
8411 +#define node_end_pfn(nid) ({\
8412 +       pg_data_t *__pgdat = NODE_DATA(nid);\
8413 +       __pgdat->node_start_pfn + __pgdat->node_spanned_pages;\
8414 +})
8415 +
8416  #include <linux/memory_hotplug.h>
8417  
8418  extern struct mutex zonelists_mutex;
8419 diff -NurpP --minimal linux-3.6.10/include/linux/mount.h linux-3.6.10-vs2.3.4.5/include/linux/mount.h
8420 --- linux-3.6.10/include/linux/mount.h  2012-03-19 19:47:28.000000000 +0100
8421 +++ linux-3.6.10-vs2.3.4.5/include/linux/mount.h        2012-10-04 18:47:00.000000000 +0200
8422 @@ -47,6 +47,9 @@ struct mnt_namespace;
8423  
8424  #define MNT_INTERNAL   0x4000
8425  
8426 +#define MNT_TAGID      0x10000
8427 +#define MNT_NOTAG      0x20000
8428 +
8429  struct vfsmount {
8430         struct dentry *mnt_root;        /* root of the mounted tree */
8431         struct super_block *mnt_sb;     /* pointer to superblock */
8432 diff -NurpP --minimal linux-3.6.10/include/linux/net.h linux-3.6.10-vs2.3.4.5/include/linux/net.h
8433 --- linux-3.6.10/include/linux/net.h    2012-10-04 15:27:46.000000000 +0200
8434 +++ linux-3.6.10-vs2.3.4.5/include/linux/net.h  2012-10-04 18:47:00.000000000 +0200
8435 @@ -73,6 +73,7 @@ struct net;
8436  #define SOCK_PASSCRED          3
8437  #define SOCK_PASSSEC           4
8438  #define SOCK_EXTERNALLY_ALLOCATED 5
8439 +#define SOCK_USER_SOCKET       6
8440  
8441  #ifndef ARCH_HAS_SOCKET_TYPES
8442  /**
8443 diff -NurpP --minimal linux-3.6.10/include/linux/netdevice.h linux-3.6.10-vs2.3.4.5/include/linux/netdevice.h
8444 --- linux-3.6.10/include/linux/netdevice.h      2012-10-04 15:27:46.000000000 +0200
8445 +++ linux-3.6.10-vs2.3.4.5/include/linux/netdevice.h    2012-10-04 18:47:00.000000000 +0200
8446 @@ -1651,6 +1651,7 @@ extern void               netdev_resync_ops(struct ne
8447  
8448  extern struct net_device       *dev_get_by_index(struct net *net, int ifindex);
8449  extern struct net_device       *__dev_get_by_index(struct net *net, int ifindex);
8450 +extern struct net_device       *dev_get_by_index_real_rcu(struct net *net, int ifindex);
8451  extern struct net_device       *dev_get_by_index_rcu(struct net *net, int ifindex);
8452  extern int             dev_restart(struct net_device *dev);
8453  #ifdef CONFIG_NETPOLL_TRAP
8454 diff -NurpP --minimal linux-3.6.10/include/linux/nfs_mount.h linux-3.6.10-vs2.3.4.5/include/linux/nfs_mount.h
8455 --- linux-3.6.10/include/linux/nfs_mount.h      2011-01-05 21:50:31.000000000 +0100
8456 +++ linux-3.6.10-vs2.3.4.5/include/linux/nfs_mount.h    2012-10-04 18:47:00.000000000 +0200
8457 @@ -63,7 +63,8 @@ struct nfs_mount_data {
8458  #define NFS_MOUNT_SECFLAVOUR   0x2000  /* 5 */
8459  #define NFS_MOUNT_NORDIRPLUS   0x4000  /* 5 */
8460  #define NFS_MOUNT_UNSHARED     0x8000  /* 5 */
8461 -#define NFS_MOUNT_FLAGMASK     0xFFFF
8462 +#define NFS_MOUNT_TAGGED       0x10000 /* context tagging */
8463 +#define NFS_MOUNT_FLAGMASK     0x1FFFF
8464  
8465  /* The following are for internal use only */
8466  #define NFS_MOUNT_LOOKUP_CACHE_NONEG   0x10000
8467 diff -NurpP --minimal linux-3.6.10/include/linux/nsproxy.h linux-3.6.10-vs2.3.4.5/include/linux/nsproxy.h
8468 --- linux-3.6.10/include/linux/nsproxy.h        2011-10-24 18:45:32.000000000 +0200
8469 +++ linux-3.6.10-vs2.3.4.5/include/linux/nsproxy.h      2012-10-04 18:47:00.000000000 +0200
8470 @@ -3,6 +3,7 @@
8471  
8472  #include <linux/spinlock.h>
8473  #include <linux/sched.h>
8474 +#include <linux/vserver/debug.h>
8475  
8476  struct mnt_namespace;
8477  struct uts_namespace;
8478 @@ -63,6 +64,7 @@ static inline struct nsproxy *task_nspro
8479  }
8480  
8481  int copy_namespaces(unsigned long flags, struct task_struct *tsk);
8482 +struct nsproxy *copy_nsproxy(struct nsproxy *orig);
8483  void exit_task_namespaces(struct task_struct *tsk);
8484  void switch_task_namespaces(struct task_struct *tsk, struct nsproxy *new);
8485  void free_nsproxy(struct nsproxy *ns);
8486 @@ -70,16 +72,26 @@ int unshare_nsproxy_namespaces(unsigned 
8487         struct fs_struct *);
8488  int __init nsproxy_cache_init(void);
8489  
8490 -static inline void put_nsproxy(struct nsproxy *ns)
8491 +#define        get_nsproxy(n)  __get_nsproxy(n, __FILE__, __LINE__)
8492 +
8493 +static inline void __get_nsproxy(struct nsproxy *ns,
8494 +       const char *_file, int _line)
8495  {
8496 -       if (atomic_dec_and_test(&ns->count)) {
8497 -               free_nsproxy(ns);
8498 -       }
8499 +       vxlprintk(VXD_CBIT(space, 0), "get_nsproxy(%p[%u])",
8500 +               ns, atomic_read(&ns->count), _file, _line);
8501 +       atomic_inc(&ns->count);
8502  }
8503  
8504 -static inline void get_nsproxy(struct nsproxy *ns)
8505 +#define        put_nsproxy(n)  __put_nsproxy(n, __FILE__, __LINE__)
8506 +
8507 +static inline void __put_nsproxy(struct nsproxy *ns,
8508 +       const char *_file, int _line)
8509  {
8510 -       atomic_inc(&ns->count);
8511 +       vxlprintk(VXD_CBIT(space, 0), "put_nsproxy(%p[%u])",
8512 +               ns, atomic_read(&ns->count), _file, _line);
8513 +       if (atomic_dec_and_test(&ns->count)) {
8514 +               free_nsproxy(ns);
8515 +       }
8516  }
8517  
8518  #endif
8519 diff -NurpP --minimal linux-3.6.10/include/linux/pid.h linux-3.6.10-vs2.3.4.5/include/linux/pid.h
8520 --- linux-3.6.10/include/linux/pid.h    2011-07-22 11:18:11.000000000 +0200
8521 +++ linux-3.6.10-vs2.3.4.5/include/linux/pid.h  2012-10-04 18:47:00.000000000 +0200
8522 @@ -8,7 +8,8 @@ enum pid_type
8523         PIDTYPE_PID,
8524         PIDTYPE_PGID,
8525         PIDTYPE_SID,
8526 -       PIDTYPE_MAX
8527 +       PIDTYPE_MAX,
8528 +       PIDTYPE_REALPID
8529  };
8530  
8531  /*
8532 @@ -171,6 +172,7 @@ static inline pid_t pid_nr(struct pid *p
8533  }
8534  
8535  pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns);
8536 +pid_t pid_unmapped_nr_ns(struct pid *pid, struct pid_namespace *ns);
8537  pid_t pid_vnr(struct pid *pid);
8538  
8539  #define do_each_pid_task(pid, type, task)                              \
8540 diff -NurpP --minimal linux-3.6.10/include/linux/proc_fs.h linux-3.6.10-vs2.3.4.5/include/linux/proc_fs.h
8541 --- linux-3.6.10/include/linux/proc_fs.h        2012-07-22 23:39:44.000000000 +0200
8542 +++ linux-3.6.10-vs2.3.4.5/include/linux/proc_fs.h      2012-10-04 18:47:00.000000000 +0200
8543 @@ -54,6 +54,7 @@ struct proc_dir_entry {
8544         nlink_t nlink;
8545         kuid_t uid;
8546         kgid_t gid;
8547 +       int vx_flags;
8548         loff_t size;
8549         const struct inode_operations *proc_iops;
8550         /*
8551 @@ -252,12 +253,18 @@ extern const struct proc_ns_operations n
8552  extern const struct proc_ns_operations utsns_operations;
8553  extern const struct proc_ns_operations ipcns_operations;
8554  
8555 +struct vx_info;
8556 +struct nx_info;
8557 +
8558  union proc_op {
8559         int (*proc_get_link)(struct dentry *, struct path *);
8560         int (*proc_read)(struct task_struct *task, char *page);
8561         int (*proc_show)(struct seq_file *m,
8562                 struct pid_namespace *ns, struct pid *pid,
8563                 struct task_struct *task);
8564 +       int (*proc_vs_read)(char *page);
8565 +       int (*proc_vxi_read)(struct vx_info *vxi, char *page);
8566 +       int (*proc_nxi_read)(struct nx_info *nxi, char *page);
8567  };
8568  
8569  struct ctl_table_header;
8570 @@ -265,6 +272,7 @@ struct ctl_table;
8571  
8572  struct proc_inode {
8573         struct pid *pid;
8574 +       int vx_flags;
8575         int fd;
8576         union proc_op op;
8577         struct proc_dir_entry *pde;
8578 diff -NurpP --minimal linux-3.6.10/include/linux/quotaops.h linux-3.6.10-vs2.3.4.5/include/linux/quotaops.h
8579 --- linux-3.6.10/include/linux/quotaops.h       2012-10-04 15:27:46.000000000 +0200
8580 +++ linux-3.6.10-vs2.3.4.5/include/linux/quotaops.h     2012-10-04 18:47:00.000000000 +0200
8581 @@ -8,6 +8,7 @@
8582  #define _LINUX_QUOTAOPS_
8583  
8584  #include <linux/fs.h>
8585 +#include <linux/vs_dlimit.h>
8586  
8587  #define DQUOT_SPACE_WARN       0x1
8588  #define DQUOT_SPACE_RESERVE    0x2
8589 @@ -205,11 +206,12 @@ static inline void dquot_drop(struct ino
8590  
8591  static inline int dquot_alloc_inode(const struct inode *inode)
8592  {
8593 -       return 0;
8594 +       return dl_alloc_inode(inode);
8595  }
8596  
8597  static inline void dquot_free_inode(const struct inode *inode)
8598  {
8599 +       dl_free_inode(inode);
8600  }
8601  
8602  static inline int dquot_transfer(struct inode *inode, struct iattr *iattr)
8603 @@ -220,6 +222,10 @@ static inline int dquot_transfer(struct 
8604  static inline int __dquot_alloc_space(struct inode *inode, qsize_t number,
8605                 int flags)
8606  {
8607 +       int ret = 0;
8608 +
8609 +       if ((ret = dl_alloc_space(inode, number)))
8610 +               return ret;
8611         if (!(flags & DQUOT_SPACE_RESERVE))
8612                 inode_add_bytes(inode, number);
8613         return 0;
8614 @@ -230,6 +236,7 @@ static inline void __dquot_free_space(st
8615  {
8616         if (!(flags & DQUOT_SPACE_RESERVE))
8617                 inode_sub_bytes(inode, number);
8618 +       dl_free_space(inode, number);
8619  }
8620  
8621  static inline int dquot_claim_space_nodirty(struct inode *inode, qsize_t number)
8622 diff -NurpP --minimal linux-3.6.10/include/linux/reboot.h linux-3.6.10-vs2.3.4.5/include/linux/reboot.h
8623 --- linux-3.6.10/include/linux/reboot.h 2011-10-24 18:45:32.000000000 +0200
8624 +++ linux-3.6.10-vs2.3.4.5/include/linux/reboot.h       2012-10-04 18:47:00.000000000 +0200
8625 @@ -33,6 +33,7 @@
8626  #define        LINUX_REBOOT_CMD_RESTART2       0xA1B2C3D4
8627  #define        LINUX_REBOOT_CMD_SW_SUSPEND     0xD000FCE2
8628  #define        LINUX_REBOOT_CMD_KEXEC          0x45584543
8629 +#define        LINUX_REBOOT_CMD_OOM            0xDEADBEEF
8630  
8631  
8632  #ifdef __KERNEL__
8633 diff -NurpP --minimal linux-3.6.10/include/linux/sched.h linux-3.6.10-vs2.3.4.5/include/linux/sched.h
8634 --- linux-3.6.10/include/linux/sched.h  2012-10-04 15:27:46.000000000 +0200
8635 +++ linux-3.6.10-vs2.3.4.5/include/linux/sched.h        2012-10-04 18:47:00.000000000 +0200
8636 @@ -1422,6 +1422,14 @@ struct task_struct {
8637  #endif
8638         struct seccomp seccomp;
8639  
8640 +/* vserver context data */
8641 +       struct vx_info *vx_info;
8642 +       struct nx_info *nx_info;
8643 +
8644 +       xid_t xid;
8645 +       nid_t nid;
8646 +       tag_t tag;
8647 +
8648  /* Thread group tracking */
8649         u32 parent_exec_id;
8650         u32 self_exec_id;
8651 @@ -1668,6 +1676,11 @@ struct pid_namespace;
8652  pid_t __task_pid_nr_ns(struct task_struct *task, enum pid_type type,
8653                         struct pid_namespace *ns);
8654  
8655 +#include <linux/vserver/base.h>
8656 +#include <linux/vserver/context.h>
8657 +#include <linux/vserver/debug.h>
8658 +#include <linux/vserver/pid.h>
8659 +
8660  static inline pid_t task_pid_nr(struct task_struct *tsk)
8661  {
8662         return tsk->pid;
8663 @@ -1681,7 +1694,8 @@ static inline pid_t task_pid_nr_ns(struc
8664  
8665  static inline pid_t task_pid_vnr(struct task_struct *tsk)
8666  {
8667 -       return __task_pid_nr_ns(tsk, PIDTYPE_PID, NULL);
8668 +       // return __task_pid_nr_ns(tsk, PIDTYPE_PID, NULL);
8669 +       return vx_map_pid(__task_pid_nr_ns(tsk, PIDTYPE_PID, NULL));
8670  }
8671  
8672  
8673 @@ -1694,7 +1708,7 @@ pid_t task_tgid_nr_ns(struct task_struct
8674  
8675  static inline pid_t task_tgid_vnr(struct task_struct *tsk)
8676  {
8677 -       return pid_vnr(task_tgid(tsk));
8678 +       return vx_map_tgid(pid_vnr(task_tgid(tsk)));
8679  }
8680  
8681  
8682 diff -NurpP --minimal linux-3.6.10/include/linux/shmem_fs.h linux-3.6.10-vs2.3.4.5/include/linux/shmem_fs.h
8683 --- linux-3.6.10/include/linux/shmem_fs.h       2012-07-22 23:39:44.000000000 +0200
8684 +++ linux-3.6.10-vs2.3.4.5/include/linux/shmem_fs.h     2012-10-04 18:47:00.000000000 +0200
8685 @@ -8,6 +8,9 @@
8686  
8687  /* inode in-kernel data */
8688  
8689 +#define TMPFS_SUPER_MAGIC      0x01021994
8690 +
8691 +
8692  struct shmem_inode_info {
8693         spinlock_t              lock;
8694         unsigned long           flags;
8695 diff -NurpP --minimal linux-3.6.10/include/linux/stat.h linux-3.6.10-vs2.3.4.5/include/linux/stat.h
8696 --- linux-3.6.10/include/linux/stat.h   2012-07-22 23:39:44.000000000 +0200
8697 +++ linux-3.6.10-vs2.3.4.5/include/linux/stat.h 2012-10-04 18:47:00.000000000 +0200
8698 @@ -67,6 +67,7 @@ struct kstat {
8699         unsigned int    nlink;
8700         kuid_t          uid;
8701         kgid_t          gid;
8702 +       tag_t           tag;
8703         dev_t           rdev;
8704         loff_t          size;
8705         struct timespec  atime;
8706 diff -NurpP --minimal linux-3.6.10/include/linux/sunrpc/auth.h linux-3.6.10-vs2.3.4.5/include/linux/sunrpc/auth.h
8707 --- linux-3.6.10/include/linux/sunrpc/auth.h    2012-10-04 15:27:46.000000000 +0200
8708 +++ linux-3.6.10-vs2.3.4.5/include/linux/sunrpc/auth.h  2012-10-04 18:47:00.000000000 +0200
8709 @@ -25,6 +25,7 @@
8710  struct auth_cred {
8711         uid_t   uid;
8712         gid_t   gid;
8713 +       tag_t   tag;
8714         struct group_info *group_info;
8715         const char *principal;
8716         unsigned char machine_cred : 1;
8717 diff -NurpP --minimal linux-3.6.10/include/linux/sunrpc/clnt.h linux-3.6.10-vs2.3.4.5/include/linux/sunrpc/clnt.h
8718 --- linux-3.6.10/include/linux/sunrpc/clnt.h    2012-05-21 18:07:32.000000000 +0200
8719 +++ linux-3.6.10-vs2.3.4.5/include/linux/sunrpc/clnt.h  2012-10-04 18:47:00.000000000 +0200
8720 @@ -49,7 +49,8 @@ struct rpc_clnt {
8721         unsigned int            cl_softrtry : 1,/* soft timeouts */
8722                                 cl_discrtry : 1,/* disconnect before retry */
8723                                 cl_autobind : 1,/* use getport() */
8724 -                               cl_chatty   : 1;/* be verbose */
8725 +                               cl_chatty   : 1,/* be verbose */
8726 +                               cl_tag      : 1;/* context tagging */
8727  
8728         struct rpc_rtt *        cl_rtt;         /* RTO estimator data */
8729         const struct rpc_timeout *cl_timeout;   /* Timeout strategy */
8730 diff -NurpP --minimal linux-3.6.10/include/linux/sysctl.h linux-3.6.10-vs2.3.4.5/include/linux/sysctl.h
8731 --- linux-3.6.10/include/linux/sysctl.h 2012-05-21 18:07:32.000000000 +0200
8732 +++ linux-3.6.10-vs2.3.4.5/include/linux/sysctl.h       2012-10-04 18:47:00.000000000 +0200
8733 @@ -60,6 +60,7 @@ enum
8734         CTL_ABI=9,              /* Binary emulation */
8735         CTL_CPU=10,             /* CPU stuff (speed scaling, etc) */
8736         CTL_ARLAN=254,          /* arlan wireless driver */
8737 +       CTL_VSERVER=4242,       /* Linux-VServer debug */
8738         CTL_S390DBF=5677,       /* s390 debug */
8739         CTL_SUNRPC=7249,        /* sunrpc debug */
8740         CTL_PM=9899,            /* frv power management */
8741 @@ -94,6 +95,7 @@ enum
8742  
8743         KERN_PANIC=15,          /* int: panic timeout */
8744         KERN_REALROOTDEV=16,    /* real root device to mount after initrd */
8745 +       KERN_VSHELPER=17,       /* string: path to vshelper policy agent */
8746  
8747         KERN_SPARC_REBOOT=21,   /* reboot command on Sparc */
8748         KERN_CTLALTDEL=22,      /* int: allow ctl-alt-del to reboot */
8749 diff -NurpP --minimal linux-3.6.10/include/linux/sysfs.h linux-3.6.10-vs2.3.4.5/include/linux/sysfs.h
8750 --- linux-3.6.10/include/linux/sysfs.h  2012-07-22 23:39:44.000000000 +0200
8751 +++ linux-3.6.10-vs2.3.4.5/include/linux/sysfs.h        2012-10-04 18:47:00.000000000 +0200
8752 @@ -19,6 +19,8 @@
8753  #include <linux/kobject_ns.h>
8754  #include <linux/atomic.h>
8755  
8756 +#define SYSFS_SUPER_MAGIC      0x62656572
8757 +
8758  struct kobject;
8759  struct module;
8760  enum kobj_ns_type;
8761 diff -NurpP --minimal linux-3.6.10/include/linux/time.h linux-3.6.10-vs2.3.4.5/include/linux/time.h
8762 --- linux-3.6.10/include/linux/time.h   2012-10-04 15:27:46.000000000 +0200
8763 +++ linux-3.6.10-vs2.3.4.5/include/linux/time.h 2012-10-04 18:47:00.000000000 +0200
8764 @@ -280,6 +280,8 @@ static __always_inline void timespec_add
8765         a->tv_nsec = ns;
8766  }
8767  
8768 +#include <linux/vs_time.h>
8769 +
8770  #endif /* __KERNEL__ */
8771  
8772  /*
8773 diff -NurpP --minimal linux-3.6.10/include/linux/types.h linux-3.6.10-vs2.3.4.5/include/linux/types.h
8774 --- linux-3.6.10/include/linux/types.h  2012-10-04 15:27:47.000000000 +0200
8775 +++ linux-3.6.10-vs2.3.4.5/include/linux/types.h        2012-10-04 18:47:00.000000000 +0200
8776 @@ -41,6 +41,9 @@ typedef __kernel_uid32_t      uid_t;
8777  typedef __kernel_gid32_t       gid_t;
8778  typedef __kernel_uid16_t        uid16_t;
8779  typedef __kernel_gid16_t        gid16_t;
8780 +typedef unsigned int           xid_t;
8781 +typedef unsigned int           nid_t;
8782 +typedef unsigned int           tag_t;
8783  
8784  typedef unsigned long          uintptr_t;
8785  
8786 diff -NurpP --minimal linux-3.6.10/include/linux/utsname.h linux-3.6.10-vs2.3.4.5/include/linux/utsname.h
8787 --- linux-3.6.10/include/linux/utsname.h        2012-01-09 16:14:59.000000000 +0100
8788 +++ linux-3.6.10-vs2.3.4.5/include/linux/utsname.h      2012-10-04 18:47:00.000000000 +0200
8789 @@ -62,7 +62,8 @@ static inline void get_uts_ns(struct uts
8790  }
8791  
8792  extern struct uts_namespace *copy_utsname(unsigned long flags,
8793 -                                         struct task_struct *tsk);
8794 +                                         struct uts_namespace *old_ns,
8795 +                                         struct user_namespace *user_ns);
8796  extern void free_uts_ns(struct kref *kref);
8797  
8798  static inline void put_uts_ns(struct uts_namespace *ns)
8799 @@ -79,12 +80,13 @@ static inline void put_uts_ns(struct uts
8800  }
8801  
8802  static inline struct uts_namespace *copy_utsname(unsigned long flags,
8803 -                                                struct task_struct *tsk)
8804 +                                                struct uts_namespace *old_ns,
8805 +                                                struct user_namespace *user_ns)
8806  {
8807         if (flags & CLONE_NEWUTS)
8808                 return ERR_PTR(-EINVAL);
8809  
8810 -       return tsk->nsproxy->uts_ns;
8811 +       return old_ns;
8812  }
8813  #endif
8814  
8815 diff -NurpP --minimal linux-3.6.10/include/linux/vroot.h linux-3.6.10-vs2.3.4.5/include/linux/vroot.h
8816 --- linux-3.6.10/include/linux/vroot.h  1970-01-01 01:00:00.000000000 +0100
8817 +++ linux-3.6.10-vs2.3.4.5/include/linux/vroot.h        2012-10-04 18:47:00.000000000 +0200
8818 @@ -0,0 +1,51 @@
8819 +
8820 +/*
8821 + * include/linux/vroot.h
8822 + *
8823 + * written by Herbert Pötzl, 9/11/2002
8824 + * ported to 2.6 by Herbert Pötzl, 30/12/2004
8825 + *
8826 + * Copyright (C) 2002-2007 by Herbert Pötzl.
8827 + * Redistribution of this file is permitted under the
8828 + * GNU General Public License.
8829 + */
8830 +
8831 +#ifndef _LINUX_VROOT_H
8832 +#define _LINUX_VROOT_H
8833 +
8834 +
8835 +#ifdef __KERNEL__
8836 +
8837 +/* Possible states of device */
8838 +enum {
8839 +       Vr_unbound,
8840 +       Vr_bound,
8841 +};
8842 +
8843 +struct vroot_device {
8844 +       int             vr_number;
8845 +       int             vr_refcnt;
8846 +
8847 +       struct semaphore        vr_ctl_mutex;
8848 +       struct block_device    *vr_device;
8849 +       int                     vr_state;
8850 +};
8851 +
8852 +
8853 +typedef struct block_device *(vroot_grb_func)(struct block_device *);
8854 +
8855 +extern int register_vroot_grb(vroot_grb_func *);
8856 +extern int unregister_vroot_grb(vroot_grb_func *);
8857 +
8858 +#endif /* __KERNEL__ */
8859 +
8860 +#define MAX_VROOT_DEFAULT      8
8861 +
8862 +/*
8863 + * IOCTL commands --- we will commandeer 0x56 ('V')
8864 + */
8865 +
8866 +#define VROOT_SET_DEV          0x5600
8867 +#define VROOT_CLR_DEV          0x5601
8868 +
8869 +#endif /* _LINUX_VROOT_H */
8870 diff -NurpP --minimal linux-3.6.10/include/linux/vs_base.h linux-3.6.10-vs2.3.4.5/include/linux/vs_base.h
8871 --- linux-3.6.10/include/linux/vs_base.h        1970-01-01 01:00:00.000000000 +0100
8872 +++ linux-3.6.10-vs2.3.4.5/include/linux/vs_base.h      2012-10-04 18:47:00.000000000 +0200
8873 @@ -0,0 +1,10 @@
8874 +#ifndef _VS_BASE_H
8875 +#define _VS_BASE_H
8876 +
8877 +#include "vserver/base.h"
8878 +#include "vserver/check.h"
8879 +#include "vserver/debug.h"
8880 +
8881 +#else
8882 +#warning duplicate inclusion
8883 +#endif
8884 diff -NurpP --minimal linux-3.6.10/include/linux/vs_context.h linux-3.6.10-vs2.3.4.5/include/linux/vs_context.h
8885 --- linux-3.6.10/include/linux/vs_context.h     1970-01-01 01:00:00.000000000 +0100
8886 +++ linux-3.6.10-vs2.3.4.5/include/linux/vs_context.h   2012-10-04 18:47:00.000000000 +0200
8887 @@ -0,0 +1,242 @@
8888 +#ifndef _VS_CONTEXT_H
8889 +#define _VS_CONTEXT_H
8890 +
8891 +#include "vserver/base.h"
8892 +#include "vserver/check.h"
8893 +#include "vserver/context.h"
8894 +#include "vserver/history.h"
8895 +#include "vserver/debug.h"
8896 +
8897 +#include <linux/sched.h>
8898 +
8899 +
8900 +#define get_vx_info(i) __get_vx_info(i, __FILE__, __LINE__, __HERE__)
8901 +
8902 +static inline struct vx_info *__get_vx_info(struct vx_info *vxi,
8903 +       const char *_file, int _line, void *_here)
8904 +{
8905 +       if (!vxi)
8906 +               return NULL;
8907 +
8908 +       vxlprintk(VXD_CBIT(xid, 2), "get_vx_info(%p[#%d.%d])",
8909 +               vxi, vxi ? vxi->vx_id : 0,
8910 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
8911 +               _file, _line);
8912 +       __vxh_get_vx_info(vxi, _here);
8913 +
8914 +       atomic_inc(&vxi->vx_usecnt);
8915 +       return vxi;
8916 +}
8917 +
8918 +
8919 +extern void free_vx_info(struct vx_info *);
8920 +
8921 +#define put_vx_info(i) __put_vx_info(i, __FILE__, __LINE__, __HERE__)
8922 +
8923 +static inline void __put_vx_info(struct vx_info *vxi,
8924 +       const char *_file, int _line, void *_here)
8925 +{
8926 +       if (!vxi)
8927 +               return;
8928 +
8929 +       vxlprintk(VXD_CBIT(xid, 2), "put_vx_info(%p[#%d.%d])",
8930 +               vxi, vxi ? vxi->vx_id : 0,
8931 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
8932 +               _file, _line);
8933 +       __vxh_put_vx_info(vxi, _here);
8934 +
8935 +       if (atomic_dec_and_test(&vxi->vx_usecnt))
8936 +               free_vx_info(vxi);
8937 +}
8938 +
8939 +
8940 +#define init_vx_info(p, i) \
8941 +       __init_vx_info(p, i, __FILE__, __LINE__, __HERE__)
8942 +
8943 +static inline void __init_vx_info(struct vx_info **vxp, struct vx_info *vxi,
8944 +       const char *_file, int _line, void *_here)
8945 +{
8946 +       if (vxi) {
8947 +               vxlprintk(VXD_CBIT(xid, 3),
8948 +                       "init_vx_info(%p[#%d.%d])",
8949 +                       vxi, vxi ? vxi->vx_id : 0,
8950 +                       vxi ? atomic_read(&vxi->vx_usecnt) : 0,
8951 +                       _file, _line);
8952 +               __vxh_init_vx_info(vxi, vxp, _here);
8953 +
8954 +               atomic_inc(&vxi->vx_usecnt);
8955 +       }
8956 +       *vxp = vxi;
8957 +}
8958 +
8959 +
8960 +#define set_vx_info(p, i) \
8961 +       __set_vx_info(p, i, __FILE__, __LINE__, __HERE__)
8962 +
8963 +static inline void __set_vx_info(struct vx_info **vxp, struct vx_info *vxi,
8964 +       const char *_file, int _line, void *_here)
8965 +{
8966 +       struct vx_info *vxo;
8967 +
8968 +       if (!vxi)
8969 +               return;
8970 +
8971 +       vxlprintk(VXD_CBIT(xid, 3), "set_vx_info(%p[#%d.%d])",
8972 +               vxi, vxi ? vxi->vx_id : 0,
8973 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
8974 +               _file, _line);
8975 +       __vxh_set_vx_info(vxi, vxp, _here);
8976 +
8977 +       atomic_inc(&vxi->vx_usecnt);
8978 +       vxo = xchg(vxp, vxi);
8979 +       BUG_ON(vxo);
8980 +}
8981 +
8982 +
8983 +#define clr_vx_info(p) __clr_vx_info(p, __FILE__, __LINE__, __HERE__)
8984 +
8985 +static inline void __clr_vx_info(struct vx_info **vxp,
8986 +       const char *_file, int _line, void *_here)
8987 +{
8988 +       struct vx_info *vxo;
8989 +
8990 +       vxo = xchg(vxp, NULL);
8991 +       if (!vxo)
8992 +               return;
8993 +
8994 +       vxlprintk(VXD_CBIT(xid, 3), "clr_vx_info(%p[#%d.%d])",
8995 +               vxo, vxo ? vxo->vx_id : 0,
8996 +               vxo ? atomic_read(&vxo->vx_usecnt) : 0,
8997 +               _file, _line);
8998 +       __vxh_clr_vx_info(vxo, vxp, _here);
8999 +
9000 +       if (atomic_dec_and_test(&vxo->vx_usecnt))
9001 +               free_vx_info(vxo);
9002 +}
9003 +
9004 +
9005 +#define claim_vx_info(v, p) \
9006 +       __claim_vx_info(v, p, __FILE__, __LINE__, __HERE__)
9007 +
9008 +static inline void __claim_vx_info(struct vx_info *vxi,
9009 +       struct task_struct *task,
9010 +       const char *_file, int _line, void *_here)
9011 +{
9012 +       vxlprintk(VXD_CBIT(xid, 3), "claim_vx_info(%p[#%d.%d.%d]) %p",
9013 +               vxi, vxi ? vxi->vx_id : 0,
9014 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
9015 +               vxi ? atomic_read(&vxi->vx_tasks) : 0,
9016 +               task, _file, _line);
9017 +       __vxh_claim_vx_info(vxi, task, _here);
9018 +
9019 +       atomic_inc(&vxi->vx_tasks);
9020 +}
9021 +
9022 +
9023 +extern void unhash_vx_info(struct vx_info *);
9024 +
9025 +#define release_vx_info(v, p) \
9026 +       __release_vx_info(v, p, __FILE__, __LINE__, __HERE__)
9027 +
9028 +static inline void __release_vx_info(struct vx_info *vxi,
9029 +       struct task_struct *task,
9030 +       const char *_file, int _line, void *_here)
9031 +{
9032 +       vxlprintk(VXD_CBIT(xid, 3), "release_vx_info(%p[#%d.%d.%d]) %p",
9033 +               vxi, vxi ? vxi->vx_id : 0,
9034 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
9035 +               vxi ? atomic_read(&vxi->vx_tasks) : 0,
9036 +               task, _file, _line);
9037 +       __vxh_release_vx_info(vxi, task, _here);
9038 +
9039 +       might_sleep();
9040 +
9041 +       if (atomic_dec_and_test(&vxi->vx_tasks))
9042 +               unhash_vx_info(vxi);
9043 +}
9044 +
9045 +
9046 +#define task_get_vx_info(p) \
9047 +       __task_get_vx_info(p, __FILE__, __LINE__, __HERE__)
9048 +
9049 +static inline struct vx_info *__task_get_vx_info(struct task_struct *p,
9050 +       const char *_file, int _line, void *_here)
9051 +{
9052 +       struct vx_info *vxi;
9053 +
9054 +       task_lock(p);
9055 +       vxlprintk(VXD_CBIT(xid, 5), "task_get_vx_info(%p)",
9056 +               p, _file, _line);
9057 +       vxi = __get_vx_info(p->vx_info, _file, _line, _here);
9058 +       task_unlock(p);
9059 +       return vxi;
9060 +}
9061 +
9062 +
9063 +static inline void __wakeup_vx_info(struct vx_info *vxi)
9064 +{
9065 +       if (waitqueue_active(&vxi->vx_wait))
9066 +               wake_up_interruptible(&vxi->vx_wait);
9067 +}
9068 +
9069 +
9070 +#define enter_vx_info(v, s) __enter_vx_info(v, s, __FILE__, __LINE__)
9071 +
9072 +static inline void __enter_vx_info(struct vx_info *vxi,
9073 +       struct vx_info_save *vxis, const char *_file, int _line)
9074 +{
9075 +       vxlprintk(VXD_CBIT(xid, 5), "enter_vx_info(%p[#%d],%p) %p[#%d,%p]",
9076 +               vxi, vxi ? vxi->vx_id : 0, vxis, current,
9077 +               current->xid, current->vx_info, _file, _line);
9078 +       vxis->vxi = xchg(&current->vx_info, vxi);
9079 +       vxis->xid = current->xid;
9080 +       current->xid = vxi ? vxi->vx_id : 0;
9081 +}
9082 +
9083 +#define leave_vx_info(s) __leave_vx_info(s, __FILE__, __LINE__)
9084 +
9085 +static inline void __leave_vx_info(struct vx_info_save *vxis,
9086 +       const char *_file, int _line)
9087 +{
9088 +       vxlprintk(VXD_CBIT(xid, 5), "leave_vx_info(%p[#%d,%p]) %p[#%d,%p]",
9089 +               vxis, vxis->xid, vxis->vxi, current,
9090 +               current->xid, current->vx_info, _file, _line);
9091 +       (void)xchg(&current->vx_info, vxis->vxi);
9092 +       current->xid = vxis->xid;
9093 +}
9094 +
9095 +
9096 +static inline void __enter_vx_admin(struct vx_info_save *vxis)
9097 +{
9098 +       vxis->vxi = xchg(&current->vx_info, NULL);
9099 +       vxis->xid = xchg(&current->xid, (xid_t)0);
9100 +}
9101 +
9102 +static inline void __leave_vx_admin(struct vx_info_save *vxis)
9103 +{
9104 +       (void)xchg(&current->xid, vxis->xid);
9105 +       (void)xchg(&current->vx_info, vxis->vxi);
9106 +}
9107 +
9108 +#define task_is_init(p) \
9109 +       __task_is_init(p, __FILE__, __LINE__, __HERE__)
9110 +
9111 +static inline int __task_is_init(struct task_struct *p,
9112 +       const char *_file, int _line, void *_here)
9113 +{
9114 +       int is_init = is_global_init(p);
9115 +
9116 +       task_lock(p);
9117 +       if (p->vx_info)
9118 +               is_init = p->vx_info->vx_initpid == p->pid;
9119 +       task_unlock(p);
9120 +       return is_init;
9121 +}
9122 +
9123 +extern void exit_vx_info(struct task_struct *, int);
9124 +extern void exit_vx_info_early(struct task_struct *, int);
9125 +
9126 +
9127 +#else
9128 +#warning duplicate inclusion
9129 +#endif
9130 diff -NurpP --minimal linux-3.6.10/include/linux/vs_cowbl.h linux-3.6.10-vs2.3.4.5/include/linux/vs_cowbl.h
9131 --- linux-3.6.10/include/linux/vs_cowbl.h       1970-01-01 01:00:00.000000000 +0100
9132 +++ linux-3.6.10-vs2.3.4.5/include/linux/vs_cowbl.h     2012-10-04 18:47:00.000000000 +0200
9133 @@ -0,0 +1,48 @@
9134 +#ifndef _VS_COWBL_H
9135 +#define _VS_COWBL_H
9136 +
9137 +#include <linux/fs.h>
9138 +#include <linux/dcache.h>
9139 +#include <linux/namei.h>
9140 +#include <linux/slab.h>
9141 +
9142 +extern struct dentry *cow_break_link(const char *pathname);
9143 +
9144 +static inline int cow_check_and_break(struct path *path)
9145 +{
9146 +       struct inode *inode = path->dentry->d_inode;
9147 +       int error = 0;
9148 +
9149 +       /* do we need this check? */
9150 +       if (IS_RDONLY(inode))
9151 +               return -EROFS;
9152 +
9153 +       if (IS_COW(inode)) {
9154 +               if (IS_COW_LINK(inode)) {
9155 +                       struct dentry *new_dentry, *old_dentry = path->dentry;
9156 +                       char *pp, *buf;
9157 +
9158 +                       buf = kmalloc(PATH_MAX, GFP_KERNEL);
9159 +                       if (!buf) {
9160 +                               return -ENOMEM;
9161 +                       }
9162 +                       pp = d_path(path, buf, PATH_MAX);
9163 +                       new_dentry = cow_break_link(pp);
9164 +                       kfree(buf);
9165 +                       if (!IS_ERR(new_dentry)) {
9166 +                               path->dentry = new_dentry;
9167 +                               dput(old_dentry);
9168 +                       } else
9169 +                               error = PTR_ERR(new_dentry);
9170 +               } else {
9171 +                       inode->i_flags &= ~(S_IXUNLINK | S_IMMUTABLE);
9172 +                       inode->i_ctime = CURRENT_TIME;
9173 +                       mark_inode_dirty(inode);
9174 +               }
9175 +       }
9176 +       return error;
9177 +}
9178 +
9179 +#else
9180 +#warning duplicate inclusion
9181 +#endif
9182 diff -NurpP --minimal linux-3.6.10/include/linux/vs_cvirt.h linux-3.6.10-vs2.3.4.5/include/linux/vs_cvirt.h
9183 --- linux-3.6.10/include/linux/vs_cvirt.h       1970-01-01 01:00:00.000000000 +0100
9184 +++ linux-3.6.10-vs2.3.4.5/include/linux/vs_cvirt.h     2012-10-04 18:47:00.000000000 +0200
9185 @@ -0,0 +1,50 @@
9186 +#ifndef _VS_CVIRT_H
9187 +#define _VS_CVIRT_H
9188 +
9189 +#include "vserver/cvirt.h"
9190 +#include "vserver/context.h"
9191 +#include "vserver/base.h"
9192 +#include "vserver/check.h"
9193 +#include "vserver/debug.h"
9194 +
9195 +
9196 +static inline void vx_activate_task(struct task_struct *p)
9197 +{
9198 +       struct vx_info *vxi;
9199 +
9200 +       if ((vxi = p->vx_info)) {
9201 +               vx_update_load(vxi);
9202 +               atomic_inc(&vxi->cvirt.nr_running);
9203 +       }
9204 +}
9205 +
9206 +static inline void vx_deactivate_task(struct task_struct *p)
9207 +{
9208 +       struct vx_info *vxi;
9209 +
9210 +       if ((vxi = p->vx_info)) {
9211 +               vx_update_load(vxi);
9212 +               atomic_dec(&vxi->cvirt.nr_running);
9213 +       }
9214 +}
9215 +
9216 +static inline void vx_uninterruptible_inc(struct task_struct *p)
9217 +{
9218 +       struct vx_info *vxi;
9219 +
9220 +       if ((vxi = p->vx_info))
9221 +               atomic_inc(&vxi->cvirt.nr_uninterruptible);
9222 +}
9223 +
9224 +static inline void vx_uninterruptible_dec(struct task_struct *p)
9225 +{
9226 +       struct vx_info *vxi;
9227 +
9228 +       if ((vxi = p->vx_info))
9229 +               atomic_dec(&vxi->cvirt.nr_uninterruptible);
9230 +}
9231 +
9232 +
9233 +#else
9234 +#warning duplicate inclusion
9235 +#endif
9236 diff -NurpP --minimal linux-3.6.10/include/linux/vs_device.h linux-3.6.10-vs2.3.4.5/include/linux/vs_device.h
9237 --- linux-3.6.10/include/linux/vs_device.h      1970-01-01 01:00:00.000000000 +0100
9238 +++ linux-3.6.10-vs2.3.4.5/include/linux/vs_device.h    2012-10-04 18:47:00.000000000 +0200
9239 @@ -0,0 +1,45 @@
9240 +#ifndef _VS_DEVICE_H
9241 +#define _VS_DEVICE_H
9242 +
9243 +#include "vserver/base.h"
9244 +#include "vserver/device.h"
9245 +#include "vserver/debug.h"
9246 +
9247 +
9248 +#ifdef CONFIG_VSERVER_DEVICE
9249 +
9250 +int vs_map_device(struct vx_info *, dev_t, dev_t *, umode_t);
9251 +
9252 +#define vs_device_perm(v, d, m, p) \
9253 +       ((vs_map_device(current_vx_info(), d, NULL, m) & (p)) == (p))
9254 +
9255 +#else
9256 +
9257 +static inline
9258 +int vs_map_device(struct vx_info *vxi,
9259 +       dev_t device, dev_t *target, umode_t mode)
9260 +{
9261 +       if (target)
9262 +               *target = device;
9263 +       return ~0;
9264 +}
9265 +
9266 +#define vs_device_perm(v, d, m, p) ((p) == (p))
9267 +
9268 +#endif
9269 +
9270 +
9271 +#define vs_map_chrdev(d, t, p) \
9272 +       ((vs_map_device(current_vx_info(), d, t, S_IFCHR) & (p)) == (p))
9273 +#define vs_map_blkdev(d, t, p) \
9274 +       ((vs_map_device(current_vx_info(), d, t, S_IFBLK) & (p)) == (p))
9275 +
9276 +#define vs_chrdev_perm(d, p) \
9277 +       vs_device_perm(current_vx_info(), d, S_IFCHR, p)
9278 +#define vs_blkdev_perm(d, p) \
9279 +       vs_device_perm(current_vx_info(), d, S_IFBLK, p)
9280 +
9281 +
9282 +#else
9283 +#warning duplicate inclusion
9284 +#endif
9285 diff -NurpP --minimal linux-3.6.10/include/linux/vs_dlimit.h linux-3.6.10-vs2.3.4.5/include/linux/vs_dlimit.h
9286 --- linux-3.6.10/include/linux/vs_dlimit.h      1970-01-01 01:00:00.000000000 +0100
9287 +++ linux-3.6.10-vs2.3.4.5/include/linux/vs_dlimit.h    2012-10-04 18:47:00.000000000 +0200
9288 @@ -0,0 +1,215 @@
9289 +#ifndef _VS_DLIMIT_H
9290 +#define _VS_DLIMIT_H
9291 +
9292 +#include <linux/fs.h>
9293 +
9294 +#include "vserver/dlimit.h"
9295 +#include "vserver/base.h"
9296 +#include "vserver/debug.h"
9297 +
9298 +
9299 +#define get_dl_info(i) __get_dl_info(i, __FILE__, __LINE__)
9300 +
9301 +static inline struct dl_info *__get_dl_info(struct dl_info *dli,
9302 +       const char *_file, int _line)
9303 +{
9304 +       if (!dli)
9305 +               return NULL;
9306 +       vxlprintk(VXD_CBIT(dlim, 4), "get_dl_info(%p[#%d.%d])",
9307 +               dli, dli ? dli->dl_tag : 0,
9308 +               dli ? atomic_read(&dli->dl_usecnt) : 0,
9309 +               _file, _line);
9310 +       atomic_inc(&dli->dl_usecnt);
9311 +       return dli;
9312 +}
9313 +
9314 +
9315 +#define free_dl_info(i) \
9316 +       call_rcu(&(i)->dl_rcu, rcu_free_dl_info)
9317 +
9318 +#define put_dl_info(i) __put_dl_info(i, __FILE__, __LINE__)
9319 +
9320 +static inline void __put_dl_info(struct dl_info *dli,
9321 +       const char *_file, int _line)
9322 +{
9323 +       if (!dli)
9324 +               return;
9325 +       vxlprintk(VXD_CBIT(dlim, 4), "put_dl_info(%p[#%d.%d])",
9326 +               dli, dli ? dli->dl_tag : 0,
9327 +               dli ? atomic_read(&dli->dl_usecnt) : 0,
9328 +               _file, _line);
9329 +       if (atomic_dec_and_test(&dli->dl_usecnt))
9330 +               free_dl_info(dli);
9331 +}
9332 +
9333 +
9334 +#define __dlimit_char(d)       ((d) ? '*' : ' ')
9335 +
9336 +static inline int __dl_alloc_space(struct super_block *sb,
9337 +       tag_t tag, dlsize_t nr, const char *file, int line)
9338 +{
9339 +       struct dl_info *dli = NULL;
9340 +       int ret = 0;
9341 +
9342 +       if (nr == 0)
9343 +               goto out;
9344 +       dli = locate_dl_info(sb, tag);
9345 +       if (!dli)
9346 +               goto out;
9347 +
9348 +       spin_lock(&dli->dl_lock);
9349 +       ret = (dli->dl_space_used + nr > dli->dl_space_total);
9350 +       if (!ret)
9351 +               dli->dl_space_used += nr;
9352 +       spin_unlock(&dli->dl_lock);
9353 +       put_dl_info(dli);
9354 +out:
9355 +       vxlprintk(VXD_CBIT(dlim, 1),
9356 +               "ALLOC (%p,#%d)%c %lld bytes (%d)",
9357 +               sb, tag, __dlimit_char(dli), (long long)nr,
9358 +               ret, file, line);
9359 +       return ret ? -ENOSPC : 0;
9360 +}
9361 +
9362 +static inline void __dl_free_space(struct super_block *sb,
9363 +       tag_t tag, dlsize_t nr, const char *_file, int _line)
9364 +{
9365 +       struct dl_info *dli = NULL;
9366 +
9367 +       if (nr == 0)
9368 +               goto out;
9369 +       dli = locate_dl_info(sb, tag);
9370 +       if (!dli)
9371 +               goto out;
9372 +
9373 +       spin_lock(&dli->dl_lock);
9374 +       if (dli->dl_space_used > nr)
9375 +               dli->dl_space_used -= nr;
9376 +       else
9377 +               dli->dl_space_used = 0;
9378 +       spin_unlock(&dli->dl_lock);
9379 +       put_dl_info(dli);
9380 +out:
9381 +       vxlprintk(VXD_CBIT(dlim, 1),
9382 +               "FREE  (%p,#%d)%c %lld bytes",
9383 +               sb, tag, __dlimit_char(dli), (long long)nr,
9384 +               _file, _line);
9385 +}
9386 +
9387 +static inline int __dl_alloc_inode(struct super_block *sb,
9388 +       tag_t tag, const char *_file, int _line)
9389 +{
9390 +       struct dl_info *dli;
9391 +       int ret = 0;
9392 +
9393 +       dli = locate_dl_info(sb, tag);
9394 +       if (!dli)
9395 +               goto out;
9396 +
9397 +       spin_lock(&dli->dl_lock);
9398 +       dli->dl_inodes_used++;
9399 +       ret = (dli->dl_inodes_used > dli->dl_inodes_total);
9400 +       spin_unlock(&dli->dl_lock);
9401 +       put_dl_info(dli);
9402 +out:
9403 +       vxlprintk(VXD_CBIT(dlim, 0),
9404 +               "ALLOC (%p,#%d)%c inode (%d)",
9405 +               sb, tag, __dlimit_char(dli), ret, _file, _line);
9406 +       return ret ? -ENOSPC : 0;
9407 +}
9408 +
9409 +static inline void __dl_free_inode(struct super_block *sb,
9410 +       tag_t tag, const char *_file, int _line)
9411 +{
9412 +       struct dl_info *dli;
9413 +
9414 +       dli = locate_dl_info(sb, tag);
9415 +       if (!dli)
9416 +               goto out;
9417 +
9418 +       spin_lock(&dli->dl_lock);
9419 +       if (dli->dl_inodes_used > 1)
9420 +               dli->dl_inodes_used--;
9421 +       else
9422 +               dli->dl_inodes_used = 0;
9423 +       spin_unlock(&dli->dl_lock);
9424 +       put_dl_info(dli);
9425 +out:
9426 +       vxlprintk(VXD_CBIT(dlim, 0),
9427 +               "FREE  (%p,#%d)%c inode",
9428 +               sb, tag, __dlimit_char(dli), _file, _line);
9429 +}
9430 +
9431 +static inline void __dl_adjust_block(struct super_block *sb, tag_t tag,
9432 +       unsigned long long *free_blocks, unsigned long long *root_blocks,
9433 +       const char *_file, int _line)
9434 +{
9435 +       struct dl_info *dli;
9436 +       uint64_t broot, bfree;
9437 +
9438 +       dli = locate_dl_info(sb, tag);
9439 +       if (!dli)
9440 +               return;
9441 +
9442 +       spin_lock(&dli->dl_lock);
9443 +       broot = (dli->dl_space_total -
9444 +               (dli->dl_space_total >> 10) * dli->dl_nrlmult)
9445 +               >> sb->s_blocksize_bits;
9446 +       bfree = (dli->dl_space_total - dli->dl_space_used)
9447 +                       >> sb->s_blocksize_bits;
9448 +       spin_unlock(&dli->dl_lock);
9449 +
9450 +       vxlprintk(VXD_CBIT(dlim, 2),
9451 +               "ADJUST: %lld,%lld on %lld,%lld [mult=%d]",
9452 +               (long long)bfree, (long long)broot,
9453 +               *free_blocks, *root_blocks, dli->dl_nrlmult,
9454 +               _file, _line);
9455 +       if (free_blocks) {
9456 +               if (*free_blocks > bfree)
9457 +                       *free_blocks = bfree;
9458 +       }
9459 +       if (root_blocks) {
9460 +               if (*root_blocks > broot)
9461 +                       *root_blocks = broot;
9462 +       }
9463 +       put_dl_info(dli);
9464 +}
9465 +
9466 +#define dl_prealloc_space(in, bytes) \
9467 +       __dl_alloc_space((in)->i_sb, (in)->i_tag, (dlsize_t)(bytes), \
9468 +               __FILE__, __LINE__ )
9469 +
9470 +#define dl_alloc_space(in, bytes) \
9471 +       __dl_alloc_space((in)->i_sb, (in)->i_tag, (dlsize_t)(bytes), \
9472 +               __FILE__, __LINE__ )
9473 +
9474 +#define dl_reserve_space(in, bytes) \
9475 +       __dl_alloc_space((in)->i_sb, (in)->i_tag, (dlsize_t)(bytes), \
9476 +               __FILE__, __LINE__ )
9477 +
9478 +#define dl_claim_space(in, bytes) (0)
9479 +
9480 +#define dl_release_space(in, bytes) \
9481 +       __dl_free_space((in)->i_sb, (in)->i_tag, (dlsize_t)(bytes), \
9482 +               __FILE__, __LINE__ )
9483 +
9484 +#define dl_free_space(in, bytes) \
9485 +       __dl_free_space((in)->i_sb, (in)->i_tag, (dlsize_t)(bytes), \
9486 +               __FILE__, __LINE__ )
9487 +
9488 +
9489 +
9490 +#define dl_alloc_inode(in) \
9491 +       __dl_alloc_inode((in)->i_sb, (in)->i_tag, __FILE__, __LINE__ )
9492 +
9493 +#define dl_free_inode(in) \
9494 +       __dl_free_inode((in)->i_sb, (in)->i_tag, __FILE__, __LINE__ )
9495 +
9496 +
9497 +#define dl_adjust_block(sb, tag, fb, rb) \
9498 +       __dl_adjust_block(sb, tag, fb, rb, __FILE__, __LINE__ )
9499 +
9500 +
9501 +#else
9502 +#warning duplicate inclusion
9503 +#endif
9504 diff -NurpP --minimal linux-3.6.10/include/linux/vs_inet.h linux-3.6.10-vs2.3.4.5/include/linux/vs_inet.h
9505 --- linux-3.6.10/include/linux/vs_inet.h        1970-01-01 01:00:00.000000000 +0100
9506 +++ linux-3.6.10-vs2.3.4.5/include/linux/vs_inet.h      2012-10-04 18:47:00.000000000 +0200
9507 @@ -0,0 +1,353 @@
9508 +#ifndef _VS_INET_H
9509 +#define _VS_INET_H
9510 +
9511 +#include "vserver/base.h"
9512 +#include "vserver/network.h"
9513 +#include "vserver/debug.h"
9514 +
9515 +#define IPI_LOOPBACK   htonl(INADDR_LOOPBACK)
9516 +
9517 +#define NXAV4(a)       NIPQUAD((a)->ip[0]), NIPQUAD((a)->ip[1]), \
9518 +                       NIPQUAD((a)->mask), (a)->type
9519 +#define NXAV4_FMT      "[" NIPQUAD_FMT "-" NIPQUAD_FMT "/" NIPQUAD_FMT ":%04x]"
9520 +
9521 +#define NIPQUAD(addr) \
9522 +       ((unsigned char *)&addr)[0], \
9523 +       ((unsigned char *)&addr)[1], \
9524 +       ((unsigned char *)&addr)[2], \
9525 +       ((unsigned char *)&addr)[3]
9526 +
9527 +#define NIPQUAD_FMT "%u.%u.%u.%u"
9528 +
9529 +
9530 +static inline
9531 +int v4_addr_match(struct nx_addr_v4 *nxa, __be32 addr, uint16_t tmask)
9532 +{
9533 +       __be32 ip = nxa->ip[0].s_addr;
9534 +       __be32 mask = nxa->mask.s_addr;
9535 +       __be32 bcast = ip | ~mask;
9536 +       int ret = 0;
9537 +
9538 +       switch (nxa->type & tmask) {
9539 +       case NXA_TYPE_MASK:
9540 +               ret = (ip == (addr & mask));
9541 +               break;
9542 +       case NXA_TYPE_ADDR:
9543 +               ret = 3;
9544 +               if (addr == ip)
9545 +                       break;
9546 +               /* fall through to broadcast */
9547 +       case NXA_MOD_BCAST:
9548 +               ret = ((tmask & NXA_MOD_BCAST) && (addr == bcast));
9549 +               break;
9550 +       case NXA_TYPE_RANGE:
9551 +               ret = ((nxa->ip[0].s_addr <= addr) &&
9552 +                       (nxa->ip[1].s_addr > addr));
9553 +               break;
9554 +       case NXA_TYPE_ANY:
9555 +               ret = 2;
9556 +               break;
9557 +       }
9558 +
9559 +       vxdprintk(VXD_CBIT(net, 0),
9560 +               "v4_addr_match(%p" NXAV4_FMT "," NIPQUAD_FMT ",%04x) = %d",
9561 +               nxa, NXAV4(nxa), NIPQUAD(addr), tmask, ret);
9562 +       return ret;
9563 +}
9564 +
9565 +static inline
9566 +int v4_addr_in_nx_info(struct nx_info *nxi, __be32 addr, uint16_t tmask)
9567 +{
9568 +       struct nx_addr_v4 *nxa;
9569 +       int ret = 1;
9570 +
9571 +       if (!nxi)
9572 +               goto out;
9573 +
9574 +       ret = 2;
9575 +       /* allow 127.0.0.1 when remapping lback */
9576 +       if ((tmask & NXA_LOOPBACK) &&
9577 +               (addr == IPI_LOOPBACK) &&
9578 +               nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
9579 +               goto out;
9580 +       ret = 3;
9581 +       /* check for lback address */
9582 +       if ((tmask & NXA_MOD_LBACK) &&
9583 +               (nxi->v4_lback.s_addr == addr))
9584 +               goto out;
9585 +       ret = 4;
9586 +       /* check for broadcast address */
9587 +       if ((tmask & NXA_MOD_BCAST) &&
9588 +               (nxi->v4_bcast.s_addr == addr))
9589 +               goto out;
9590 +       ret = 5;
9591 +       /* check for v4 addresses */
9592 +       for (nxa = &nxi->v4; nxa; nxa = nxa->next)
9593 +               if (v4_addr_match(nxa, addr, tmask))
9594 +                       goto out;
9595 +       ret = 0;
9596 +out:
9597 +       vxdprintk(VXD_CBIT(net, 0),
9598 +               "v4_addr_in_nx_info(%p[#%u]," NIPQUAD_FMT ",%04x) = %d",
9599 +               nxi, nxi ? nxi->nx_id : 0, NIPQUAD(addr), tmask, ret);
9600 +       return ret;
9601 +}
9602 +
9603 +static inline
9604 +int v4_nx_addr_match(struct nx_addr_v4 *nxa, struct nx_addr_v4 *addr, uint16_t mask)
9605 +{
9606 +       /* FIXME: needs full range checks */
9607 +       return v4_addr_match(nxa, addr->ip[0].s_addr, mask);
9608 +}
9609 +
9610 +static inline
9611 +int v4_nx_addr_in_nx_info(struct nx_info *nxi, struct nx_addr_v4 *nxa, uint16_t mask)
9612 +{
9613 +       struct nx_addr_v4 *ptr;
9614 +
9615 +       for (ptr = &nxi->v4; ptr; ptr = ptr->next)
9616 +               if (v4_nx_addr_match(ptr, nxa, mask))
9617 +                       return 1;
9618 +       return 0;
9619 +}
9620 +
9621 +#include <net/inet_sock.h>
9622 +
9623 +/*
9624 + *     Check if a given address matches for a socket
9625 + *
9626 + *     nxi:            the socket's nx_info if any
9627 + *     addr:           to be verified address
9628 + */
9629 +static inline
9630 +int v4_sock_addr_match (
9631 +       struct nx_info *nxi,
9632 +       struct inet_sock *inet,
9633 +       __be32 addr)
9634 +{
9635 +       __be32 saddr = inet->inet_rcv_saddr;
9636 +       __be32 bcast = nxi ? nxi->v4_bcast.s_addr : INADDR_BROADCAST;
9637 +
9638 +       if (addr && (saddr == addr || bcast == addr))
9639 +               return 1;
9640 +       if (!saddr)
9641 +               return v4_addr_in_nx_info(nxi, addr, NXA_MASK_BIND);
9642 +       return 0;
9643 +}
9644 +
9645 +
9646 +/* inet related checks and helpers */
9647 +
9648 +
9649 +struct in_ifaddr;
9650 +struct net_device;
9651 +struct sock;
9652 +
9653 +#ifdef CONFIG_INET
9654 +
9655 +#include <linux/netdevice.h>
9656 +#include <linux/inetdevice.h>
9657 +#include <net/inet_sock.h>
9658 +#include <net/inet_timewait_sock.h>
9659 +
9660 +
9661 +int dev_in_nx_info(struct net_device *, struct nx_info *);
9662 +int v4_dev_in_nx_info(struct net_device *, struct nx_info *);
9663 +int nx_v4_addr_conflict(struct nx_info *, struct nx_info *);
9664 +
9665 +
9666 +/*
9667 + *     check if address is covered by socket
9668 + *
9669 + *     sk:     the socket to check against
9670 + *     addr:   the address in question (must be != 0)
9671 + */
9672 +
9673 +static inline
9674 +int __v4_addr_match_socket(const struct sock *sk, struct nx_addr_v4 *nxa)
9675 +{
9676 +       struct nx_info *nxi = sk->sk_nx_info;
9677 +       __be32 saddr = sk_rcv_saddr(sk);
9678 +
9679 +       vxdprintk(VXD_CBIT(net, 5),
9680 +               "__v4_addr_in_socket(%p," NXAV4_FMT ") %p:" NIPQUAD_FMT " %p;%lx",
9681 +               sk, NXAV4(nxa), nxi, NIPQUAD(saddr), sk->sk_socket,
9682 +               (sk->sk_socket?sk->sk_socket->flags:0));
9683 +
9684 +       if (saddr) {            /* direct address match */
9685 +               return v4_addr_match(nxa, saddr, -1);
9686 +       } else if (nxi) {       /* match against nx_info */
9687 +               return v4_nx_addr_in_nx_info(nxi, nxa, -1);
9688 +       } else {                /* unrestricted any socket */
9689 +               return 1;
9690 +       }
9691 +}
9692 +
9693 +
9694 +
9695 +static inline
9696 +int nx_dev_visible(struct nx_info *nxi, struct net_device *dev)
9697 +{
9698 +       vxdprintk(VXD_CBIT(net, 1),
9699 +               "nx_dev_visible(%p[#%u],%p " VS_Q("%s") ") %d",
9700 +               nxi, nxi ? nxi->nx_id : 0, dev, dev->name,
9701 +               nxi ? dev_in_nx_info(dev, nxi) : 0);
9702 +
9703 +       if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
9704 +               return 1;
9705 +       if (dev_in_nx_info(dev, nxi))
9706 +               return 1;
9707 +       return 0;
9708 +}
9709 +
9710 +
9711 +static inline
9712 +int v4_ifa_in_nx_info(struct in_ifaddr *ifa, struct nx_info *nxi)
9713 +{
9714 +       if (!nxi)
9715 +               return 1;
9716 +       if (!ifa)
9717 +               return 0;
9718 +       return v4_addr_in_nx_info(nxi, ifa->ifa_local, NXA_MASK_SHOW);
9719 +}
9720 +
9721 +static inline
9722 +int nx_v4_ifa_visible(struct nx_info *nxi, struct in_ifaddr *ifa)
9723 +{
9724 +       vxdprintk(VXD_CBIT(net, 1), "nx_v4_ifa_visible(%p[#%u],%p) %d",
9725 +               nxi, nxi ? nxi->nx_id : 0, ifa,
9726 +               nxi ? v4_ifa_in_nx_info(ifa, nxi) : 0);
9727 +
9728 +       if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
9729 +               return 1;
9730 +       if (v4_ifa_in_nx_info(ifa, nxi))
9731 +               return 1;
9732 +       return 0;
9733 +}
9734 +
9735 +
9736 +struct nx_v4_sock_addr {
9737 +       __be32 saddr;   /* Address used for validation */
9738 +       __be32 baddr;   /* Address used for socket bind */
9739 +};
9740 +
9741 +static inline
9742 +int v4_map_sock_addr(struct inet_sock *inet, struct sockaddr_in *addr,
9743 +       struct nx_v4_sock_addr *nsa)
9744 +{
9745 +       struct sock *sk = &inet->sk;
9746 +       struct nx_info *nxi = sk->sk_nx_info;
9747 +       __be32 saddr = addr->sin_addr.s_addr;
9748 +       __be32 baddr = saddr;
9749 +
9750 +       vxdprintk(VXD_CBIT(net, 3),
9751 +               "inet_bind(%p)* %p,%p;%lx " NIPQUAD_FMT,
9752 +               sk, sk->sk_nx_info, sk->sk_socket,
9753 +               (sk->sk_socket ? sk->sk_socket->flags : 0),
9754 +               NIPQUAD(saddr));
9755 +
9756 +       if (nxi) {
9757 +               if (saddr == INADDR_ANY) {
9758 +                       if (nx_info_flags(nxi, NXF_SINGLE_IP, 0))
9759 +                               baddr = nxi->v4.ip[0].s_addr;
9760 +               } else if (saddr == IPI_LOOPBACK) {
9761 +                       if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
9762 +                               baddr = nxi->v4_lback.s_addr;
9763 +               } else if (!ipv4_is_multicast(saddr) ||
9764 +                       !nx_info_ncaps(nxi, NXC_MULTICAST)) {
9765 +                       /* normal address bind */
9766 +                       if (!v4_addr_in_nx_info(nxi, saddr, NXA_MASK_BIND))
9767 +                               return -EADDRNOTAVAIL;
9768 +               }
9769 +       }
9770 +
9771 +       vxdprintk(VXD_CBIT(net, 3),
9772 +               "inet_bind(%p) " NIPQUAD_FMT ", " NIPQUAD_FMT,
9773 +               sk, NIPQUAD(saddr), NIPQUAD(baddr));
9774 +
9775 +       nsa->saddr = saddr;
9776 +       nsa->baddr = baddr;
9777 +       return 0;
9778 +}
9779 +
9780 +static inline
9781 +void v4_set_sock_addr(struct inet_sock *inet, struct nx_v4_sock_addr *nsa)
9782 +{
9783 +       inet->inet_saddr = nsa->baddr;
9784 +       inet->inet_rcv_saddr = nsa->baddr;
9785 +}
9786 +
9787 +
9788 +/*
9789 + *      helper to simplify inet_lookup_listener
9790 + *
9791 + *      nxi:   the socket's nx_info if any
9792 + *      addr:  to be verified address
9793 + *      saddr: socket address
9794 + */
9795 +static inline int v4_inet_addr_match (
9796 +       struct nx_info *nxi,
9797 +       __be32 addr,
9798 +       __be32 saddr)
9799 +{
9800 +       if (addr && (saddr == addr))
9801 +               return 1;
9802 +       if (!saddr)
9803 +               return nxi ? v4_addr_in_nx_info(nxi, addr, NXA_MASK_BIND) : 1;
9804 +       return 0;
9805 +}
9806 +
9807 +static inline __be32 nx_map_sock_lback(struct nx_info *nxi, __be32 addr)
9808 +{
9809 +       if (nx_info_flags(nxi, NXF_HIDE_LBACK, 0) &&
9810 +               (addr == nxi->v4_lback.s_addr))
9811 +               return IPI_LOOPBACK;
9812 +       return addr;
9813 +}
9814 +
9815 +static inline
9816 +int nx_info_has_v4(struct nx_info *nxi)
9817 +{
9818 +       if (!nxi)
9819 +               return 1;
9820 +       if (NX_IPV4(nxi))
9821 +               return 1;
9822 +       if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
9823 +               return 1;
9824 +       return 0;
9825 +}
9826 +
9827 +#else /* CONFIG_INET */
9828 +
9829 +static inline
9830 +int nx_dev_visible(struct nx_info *n, struct net_device *d)
9831 +{
9832 +       return 1;
9833 +}
9834 +
9835 +static inline
9836 +int nx_v4_addr_conflict(struct nx_info *n, uint32_t a, const struct sock *s)
9837 +{
9838 +       return 1;
9839 +}
9840 +
9841 +static inline
9842 +int v4_ifa_in_nx_info(struct in_ifaddr *a, struct nx_info *n)
9843 +{
9844 +       return 1;
9845 +}
9846 +
9847 +static inline
9848 +int nx_info_has_v4(struct nx_info *nxi)
9849 +{
9850 +       return 0;
9851 +}
9852 +
9853 +#endif /* CONFIG_INET */
9854 +
9855 +#define current_nx_info_has_v4() \
9856 +       nx_info_has_v4(current_nx_info())
9857 +
9858 +#else
9859 +// #warning duplicate inclusion
9860 +#endif
9861 diff -NurpP --minimal linux-3.6.10/include/linux/vs_inet6.h linux-3.6.10-vs2.3.4.5/include/linux/vs_inet6.h
9862 --- linux-3.6.10/include/linux/vs_inet6.h       1970-01-01 01:00:00.000000000 +0100
9863 +++ linux-3.6.10-vs2.3.4.5/include/linux/vs_inet6.h     2012-10-04 18:47:00.000000000 +0200
9864 @@ -0,0 +1,246 @@
9865 +#ifndef _VS_INET6_H
9866 +#define _VS_INET6_H
9867 +
9868 +#include "vserver/base.h"
9869 +#include "vserver/network.h"
9870 +#include "vserver/debug.h"
9871 +
9872 +#include <net/ipv6.h>
9873 +
9874 +#define NXAV6(a)       &(a)->ip, &(a)->mask, (a)->prefix, (a)->type
9875 +#define NXAV6_FMT      "[%pI6/%pI6/%d:%04x]"
9876 +
9877 +
9878 +#ifdef CONFIG_IPV6
9879 +
9880 +static inline
9881 +int v6_addr_match(struct nx_addr_v6 *nxa,
9882 +       const struct in6_addr *addr, uint16_t mask)
9883 +{
9884 +       int ret = 0;
9885 +
9886 +       switch (nxa->type & mask) {
9887 +       case NXA_TYPE_MASK:
9888 +               ret = ipv6_masked_addr_cmp(&nxa->ip, &nxa->mask, addr);
9889 +               break;
9890 +       case NXA_TYPE_ADDR:
9891 +               ret = ipv6_addr_equal(&nxa->ip, addr);
9892 +               break;
9893 +       case NXA_TYPE_ANY:
9894 +               ret = 1;
9895 +               break;
9896 +       }
9897 +       vxdprintk(VXD_CBIT(net, 0),
9898 +               "v6_addr_match(%p" NXAV6_FMT ",%pI6,%04x) = %d",
9899 +               nxa, NXAV6(nxa), addr, mask, ret);
9900 +       return ret;
9901 +}
9902 +
9903 +static inline
9904 +int v6_addr_in_nx_info(struct nx_info *nxi,
9905 +       const struct in6_addr *addr, uint16_t mask)
9906 +{
9907 +       struct nx_addr_v6 *nxa;
9908 +       int ret = 1;
9909 +
9910 +       if (!nxi)
9911 +               goto out;
9912 +       for (nxa = &nxi->v6; nxa; nxa = nxa->next)
9913 +               if (v6_addr_match(nxa, addr, mask))
9914 +                       goto out;
9915 +       ret = 0;
9916 +out:
9917 +       vxdprintk(VXD_CBIT(net, 0),
9918 +               "v6_addr_in_nx_info(%p[#%u],%pI6,%04x) = %d",
9919 +               nxi, nxi ? nxi->nx_id : 0, addr, mask, ret);
9920 +       return ret;
9921 +}
9922 +
9923 +static inline
9924 +int v6_nx_addr_match(struct nx_addr_v6 *nxa, struct nx_addr_v6 *addr, uint16_t mask)
9925 +{
9926 +       /* FIXME: needs full range checks */
9927 +       return v6_addr_match(nxa, &addr->ip, mask);
9928 +}
9929 +
9930 +static inline
9931 +int v6_nx_addr_in_nx_info(struct nx_info *nxi, struct nx_addr_v6 *nxa, uint16_t mask)
9932 +{
9933 +       struct nx_addr_v6 *ptr;
9934 +
9935 +       for (ptr = &nxi->v6; ptr; ptr = ptr->next)
9936 +               if (v6_nx_addr_match(ptr, nxa, mask))
9937 +                       return 1;
9938 +       return 0;
9939 +}
9940 +
9941 +
9942 +/*
9943 + *     Check if a given address matches for a socket
9944 + *
9945 + *     nxi:            the socket's nx_info if any
9946 + *     addr:           to be verified address
9947 + */
9948 +static inline
9949 +int v6_sock_addr_match (
9950 +       struct nx_info *nxi,
9951 +       struct inet_sock *inet,
9952 +       struct in6_addr *addr)
9953 +{
9954 +       struct sock *sk = &inet->sk;
9955 +       struct in6_addr *saddr = inet6_rcv_saddr(sk);
9956 +
9957 +       if (!ipv6_addr_any(addr) &&
9958 +               ipv6_addr_equal(saddr, addr))
9959 +               return 1;
9960 +       if (ipv6_addr_any(saddr))
9961 +               return v6_addr_in_nx_info(nxi, addr, -1);
9962 +       return 0;
9963 +}
9964 +
9965 +/*
9966 + *     check if address is covered by socket
9967 + *
9968 + *     sk:     the socket to check against
9969 + *     addr:   the address in question (must be != 0)
9970 + */
9971 +
9972 +static inline
9973 +int __v6_addr_match_socket(const struct sock *sk, struct nx_addr_v6 *nxa)
9974 +{
9975 +       struct nx_info *nxi = sk->sk_nx_info;
9976 +       struct in6_addr *saddr = inet6_rcv_saddr(sk);
9977 +
9978 +       vxdprintk(VXD_CBIT(net, 5),
9979 +               "__v6_addr_in_socket(%p," NXAV6_FMT ") %p:%pI6 %p;%lx",
9980 +               sk, NXAV6(nxa), nxi, saddr, sk->sk_socket,
9981 +               (sk->sk_socket?sk->sk_socket->flags:0));
9982 +
9983 +       if (!ipv6_addr_any(saddr)) {    /* direct address match */
9984 +               return v6_addr_match(nxa, saddr, -1);
9985 +       } else if (nxi) {               /* match against nx_info */
9986 +               return v6_nx_addr_in_nx_info(nxi, nxa, -1);
9987 +       } else {                        /* unrestricted any socket */
9988 +               return 1;
9989 +       }
9990 +}
9991 +
9992 +
9993 +/* inet related checks and helpers */
9994 +
9995 +
9996 +struct in_ifaddr;
9997 +struct net_device;
9998 +struct sock;
9999 +
10000 +
10001 +#include <linux/netdevice.h>
10002 +#include <linux/inetdevice.h>
10003 +#include <net/inet_timewait_sock.h>
10004 +
10005 +
10006 +int dev_in_nx_info(struct net_device *, struct nx_info *);
10007 +int v6_dev_in_nx_info(struct net_device *, struct nx_info *);
10008 +int nx_v6_addr_conflict(struct nx_info *, struct nx_info *);
10009 +
10010 +
10011 +
10012 +static inline
10013 +int v6_ifa_in_nx_info(struct inet6_ifaddr *ifa, struct nx_info *nxi)
10014 +{
10015 +       if (!nxi)
10016 +               return 1;
10017 +       if (!ifa)
10018 +               return 0;
10019 +       return v6_addr_in_nx_info(nxi, &ifa->addr, -1);
10020 +}
10021 +
10022 +static inline
10023 +int nx_v6_ifa_visible(struct nx_info *nxi, struct inet6_ifaddr *ifa)
10024 +{
10025 +       vxdprintk(VXD_CBIT(net, 1), "nx_v6_ifa_visible(%p[#%u],%p) %d",
10026 +               nxi, nxi ? nxi->nx_id : 0, ifa,
10027 +               nxi ? v6_ifa_in_nx_info(ifa, nxi) : 0);
10028 +
10029 +       if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
10030 +               return 1;
10031 +       if (v6_ifa_in_nx_info(ifa, nxi))
10032 +               return 1;
10033 +       return 0;
10034 +}
10035 +
10036 +
10037 +struct nx_v6_sock_addr {
10038 +       struct in6_addr saddr;  /* Address used for validation */
10039 +       struct in6_addr baddr;  /* Address used for socket bind */
10040 +};
10041 +
10042 +static inline
10043 +int v6_map_sock_addr(struct inet_sock *inet, struct sockaddr_in6 *addr,
10044 +       struct nx_v6_sock_addr *nsa)
10045 +{
10046 +       // struct sock *sk = &inet->sk;
10047 +       // struct nx_info *nxi = sk->sk_nx_info;
10048 +       struct in6_addr saddr = addr->sin6_addr;
10049 +       struct in6_addr baddr = saddr;
10050 +
10051 +       nsa->saddr = saddr;
10052 +       nsa->baddr = baddr;
10053 +       return 0;
10054 +}
10055 +
10056 +static inline
10057 +void v6_set_sock_addr(struct inet_sock *inet, struct nx_v6_sock_addr *nsa)
10058 +{
10059 +       // struct sock *sk = &inet->sk;
10060 +       // struct in6_addr *saddr = inet6_rcv_saddr(sk);
10061 +
10062 +       // *saddr = nsa->baddr;
10063 +       // inet->inet_saddr = nsa->baddr;
10064 +}
10065 +
10066 +static inline
10067 +int nx_info_has_v6(struct nx_info *nxi)
10068 +{
10069 +       if (!nxi)
10070 +               return 1;
10071 +       if (NX_IPV6(nxi))
10072 +               return 1;
10073 +       return 0;
10074 +}
10075 +
10076 +#else /* CONFIG_IPV6 */
10077 +
10078 +static inline
10079 +int nx_v6_dev_visible(struct nx_info *n, struct net_device *d)
10080 +{
10081 +       return 1;
10082 +}
10083 +
10084 +
10085 +static inline
10086 +int nx_v6_addr_conflict(struct nx_info *n, uint32_t a, const struct sock *s)
10087 +{
10088 +       return 1;
10089 +}
10090 +
10091 +static inline
10092 +int v6_ifa_in_nx_info(struct in_ifaddr *a, struct nx_info *n)
10093 +{
10094 +       return 1;
10095 +}
10096 +
10097 +static inline
10098 +int nx_info_has_v6(struct nx_info *nxi)
10099 +{
10100 +       return 0;
10101 +}
10102 +
10103 +#endif /* CONFIG_IPV6 */
10104 +
10105 +#define current_nx_info_has_v6() \
10106 +       nx_info_has_v6(current_nx_info())
10107 +
10108 +#else
10109 +#warning duplicate inclusion
10110 +#endif
10111 diff -NurpP --minimal linux-3.6.10/include/linux/vs_limit.h linux-3.6.10-vs2.3.4.5/include/linux/vs_limit.h
10112 --- linux-3.6.10/include/linux/vs_limit.h       1970-01-01 01:00:00.000000000 +0100
10113 +++ linux-3.6.10-vs2.3.4.5/include/linux/vs_limit.h     2012-10-04 18:47:00.000000000 +0200
10114 @@ -0,0 +1,140 @@
10115 +#ifndef _VS_LIMIT_H
10116 +#define _VS_LIMIT_H
10117 +
10118 +#include "vserver/limit.h"
10119 +#include "vserver/base.h"
10120 +#include "vserver/context.h"
10121 +#include "vserver/debug.h"
10122 +#include "vserver/context.h"
10123 +#include "vserver/limit_int.h"
10124 +
10125 +
10126 +#define vx_acc_cres(v, d, p, r) \
10127 +       __vx_acc_cres(v, r, d, p, __FILE__, __LINE__)
10128 +
10129 +#define vx_acc_cres_cond(x, d, p, r) \
10130 +       __vx_acc_cres(((x) == vx_current_xid()) ? current_vx_info() : 0, \
10131 +       r, d, p, __FILE__, __LINE__)
10132 +
10133 +
10134 +#define vx_add_cres(v, a, p, r) \
10135 +       __vx_add_cres(v, r, a, p, __FILE__, __LINE__)
10136 +#define vx_sub_cres(v, a, p, r)                vx_add_cres(v, -(a), p, r)
10137 +
10138 +#define vx_add_cres_cond(x, a, p, r) \
10139 +       __vx_add_cres(((x) == vx_current_xid()) ? current_vx_info() : 0, \
10140 +       r, a, p, __FILE__, __LINE__)
10141 +#define vx_sub_cres_cond(x, a, p, r)   vx_add_cres_cond(x, -(a), p, r)
10142 +
10143 +
10144 +/* process and file limits */
10145 +
10146 +#define vx_nproc_inc(p) \
10147 +       vx_acc_cres((p)->vx_info, 1, p, RLIMIT_NPROC)
10148 +
10149 +#define vx_nproc_dec(p) \
10150 +       vx_acc_cres((p)->vx_info,-1, p, RLIMIT_NPROC)
10151 +
10152 +#define vx_files_inc(f) \
10153 +       vx_acc_cres_cond((f)->f_xid, 1, f, RLIMIT_NOFILE)
10154 +
10155 +#define vx_files_dec(f) \
10156 +       vx_acc_cres_cond((f)->f_xid,-1, f, RLIMIT_NOFILE)
10157 +
10158 +#define vx_locks_inc(l) \
10159 +       vx_acc_cres_cond((l)->fl_xid, 1, l, RLIMIT_LOCKS)
10160 +
10161 +#define vx_locks_dec(l) \
10162 +       vx_acc_cres_cond((l)->fl_xid,-1, l, RLIMIT_LOCKS)
10163 +
10164 +#define vx_openfd_inc(f) \
10165 +       vx_acc_cres(current_vx_info(), 1, (void *)(long)(f), VLIMIT_OPENFD)
10166 +
10167 +#define vx_openfd_dec(f) \
10168 +       vx_acc_cres(current_vx_info(),-1, (void *)(long)(f), VLIMIT_OPENFD)
10169 +
10170 +
10171 +#define vx_cres_avail(v, n, r) \
10172 +       __vx_cres_avail(v, r, n, __FILE__, __LINE__)
10173 +
10174 +
10175 +#define vx_nproc_avail(n) \
10176 +       vx_cres_avail(current_vx_info(), n, RLIMIT_NPROC)
10177 +
10178 +#define vx_files_avail(n) \
10179 +       vx_cres_avail(current_vx_info(), n, RLIMIT_NOFILE)
10180 +
10181 +#define vx_locks_avail(n) \
10182 +       vx_cres_avail(current_vx_info(), n, RLIMIT_LOCKS)
10183 +
10184 +#define vx_openfd_avail(n) \
10185 +       vx_cres_avail(current_vx_info(), n, VLIMIT_OPENFD)
10186 +
10187 +
10188 +/* dentry limits */
10189 +
10190 +#define vx_dentry_inc(d) do {                                          \
10191 +       if ((d)->d_count == 1)                                          \
10192 +               vx_acc_cres(current_vx_info(), 1, d, VLIMIT_DENTRY);    \
10193 +       } while (0)
10194 +
10195 +#define vx_dentry_dec(d) do {                                          \
10196 +       if ((d)->d_count == 0)                                          \
10197 +               vx_acc_cres(current_vx_info(),-1, d, VLIMIT_DENTRY);    \
10198 +       } while (0)
10199 +
10200 +#define vx_dentry_avail(n) \
10201 +       vx_cres_avail(current_vx_info(), n, VLIMIT_DENTRY)
10202 +
10203 +
10204 +/* socket limits */
10205 +
10206 +#define vx_sock_inc(s) \
10207 +       vx_acc_cres((s)->sk_vx_info, 1, s, VLIMIT_NSOCK)
10208 +
10209 +#define vx_sock_dec(s) \
10210 +       vx_acc_cres((s)->sk_vx_info,-1, s, VLIMIT_NSOCK)
10211 +
10212 +#define vx_sock_avail(n) \
10213 +       vx_cres_avail(current_vx_info(), n, VLIMIT_NSOCK)
10214 +
10215 +
10216 +/* ipc resource limits */
10217 +
10218 +#define vx_ipcmsg_add(v, u, a) \
10219 +       vx_add_cres(v, a, u, RLIMIT_MSGQUEUE)
10220 +
10221 +#define vx_ipcmsg_sub(v, u, a) \
10222 +       vx_sub_cres(v, a, u, RLIMIT_MSGQUEUE)
10223 +
10224 +#define vx_ipcmsg_avail(v, a) \
10225 +       vx_cres_avail(v, a, RLIMIT_MSGQUEUE)
10226 +
10227 +
10228 +#define vx_ipcshm_add(v, k, a) \
10229 +       vx_add_cres(v, a, (void *)(long)(k), VLIMIT_SHMEM)
10230 +
10231 +#define vx_ipcshm_sub(v, k, a) \
10232 +       vx_sub_cres(v, a, (void *)(long)(k), VLIMIT_SHMEM)
10233 +
10234 +#define vx_ipcshm_avail(v, a) \
10235 +       vx_cres_avail(v, a, VLIMIT_SHMEM)
10236 +
10237 +
10238 +#define vx_semary_inc(a) \
10239 +       vx_acc_cres(current_vx_info(), 1, a, VLIMIT_SEMARY)
10240 +
10241 +#define vx_semary_dec(a) \
10242 +       vx_acc_cres(current_vx_info(), -1, a, VLIMIT_SEMARY)
10243 +
10244 +
10245 +#define vx_nsems_add(a,n) \
10246 +       vx_add_cres(current_vx_info(), n, a, VLIMIT_NSEMS)
10247 +
10248 +#define vx_nsems_sub(a,n) \
10249 +       vx_sub_cres(current_vx_info(), n, a, VLIMIT_NSEMS)
10250 +
10251 +
10252 +#else
10253 +#warning duplicate inclusion
10254 +#endif
10255 diff -NurpP --minimal linux-3.6.10/include/linux/vs_network.h linux-3.6.10-vs2.3.4.5/include/linux/vs_network.h
10256 --- linux-3.6.10/include/linux/vs_network.h     1970-01-01 01:00:00.000000000 +0100
10257 +++ linux-3.6.10-vs2.3.4.5/include/linux/vs_network.h   2012-10-04 18:47:00.000000000 +0200
10258 @@ -0,0 +1,169 @@
10259 +#ifndef _NX_VS_NETWORK_H
10260 +#define _NX_VS_NETWORK_H
10261 +
10262 +#include "vserver/context.h"
10263 +#include "vserver/network.h"
10264 +#include "vserver/base.h"
10265 +#include "vserver/check.h"
10266 +#include "vserver/debug.h"
10267 +
10268 +#include <linux/sched.h>
10269 +
10270 +
10271 +#define get_nx_info(i) __get_nx_info(i, __FILE__, __LINE__)
10272 +
10273 +static inline struct nx_info *__get_nx_info(struct nx_info *nxi,
10274 +       const char *_file, int _line)
10275 +{
10276 +       if (!nxi)
10277 +               return NULL;
10278 +
10279 +       vxlprintk(VXD_CBIT(nid, 2), "get_nx_info(%p[#%d.%d])",
10280 +               nxi, nxi ? nxi->nx_id : 0,
10281 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
10282 +               _file, _line);
10283 +
10284 +       atomic_inc(&nxi->nx_usecnt);
10285 +       return nxi;
10286 +}
10287 +
10288 +
10289 +extern void free_nx_info(struct nx_info *);
10290 +
10291 +#define put_nx_info(i) __put_nx_info(i, __FILE__, __LINE__)
10292 +
10293 +static inline void __put_nx_info(struct nx_info *nxi, const char *_file, int _line)
10294 +{
10295 +       if (!nxi)
10296 +               return;
10297 +
10298 +       vxlprintk(VXD_CBIT(nid, 2), "put_nx_info(%p[#%d.%d])",
10299 +               nxi, nxi ? nxi->nx_id : 0,
10300 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
10301 +               _file, _line);
10302 +
10303 +       if (atomic_dec_and_test(&nxi->nx_usecnt))
10304 +               free_nx_info(nxi);
10305 +}
10306 +
10307 +
10308 +#define init_nx_info(p, i) __init_nx_info(p, i, __FILE__, __LINE__)
10309 +
10310 +static inline void __init_nx_info(struct nx_info **nxp, struct nx_info *nxi,
10311 +               const char *_file, int _line)
10312 +{
10313 +       if (nxi) {
10314 +               vxlprintk(VXD_CBIT(nid, 3),
10315 +                       "init_nx_info(%p[#%d.%d])",
10316 +                       nxi, nxi ? nxi->nx_id : 0,
10317 +                       nxi ? atomic_read(&nxi->nx_usecnt) : 0,
10318 +                       _file, _line);
10319 +
10320 +               atomic_inc(&nxi->nx_usecnt);
10321 +       }
10322 +       *nxp = nxi;
10323 +}
10324 +
10325 +
10326 +#define set_nx_info(p, i) __set_nx_info(p, i, __FILE__, __LINE__)
10327 +
10328 +static inline void __set_nx_info(struct nx_info **nxp, struct nx_info *nxi,
10329 +       const char *_file, int _line)
10330 +{
10331 +       struct nx_info *nxo;
10332 +
10333 +       if (!nxi)
10334 +               return;
10335 +
10336 +       vxlprintk(VXD_CBIT(nid, 3), "set_nx_info(%p[#%d.%d])",
10337 +               nxi, nxi ? nxi->nx_id : 0,
10338 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
10339 +               _file, _line);
10340 +
10341 +       atomic_inc(&nxi->nx_usecnt);
10342 +       nxo = xchg(nxp, nxi);
10343 +       BUG_ON(nxo);
10344 +}
10345 +
10346 +#define clr_nx_info(p) __clr_nx_info(p, __FILE__, __LINE__)
10347 +
10348 +static inline void __clr_nx_info(struct nx_info **nxp,
10349 +       const char *_file, int _line)
10350 +{
10351 +       struct nx_info *nxo;
10352 +
10353 +       nxo = xchg(nxp, NULL);
10354 +       if (!nxo)
10355 +               return;
10356 +
10357 +       vxlprintk(VXD_CBIT(nid, 3), "clr_nx_info(%p[#%d.%d])",
10358 +               nxo, nxo ? nxo->nx_id : 0,
10359 +               nxo ? atomic_read(&nxo->nx_usecnt) : 0,
10360 +               _file, _line);
10361 +
10362 +       if (atomic_dec_and_test(&nxo->nx_usecnt))
10363 +               free_nx_info(nxo);
10364 +}
10365 +
10366 +
10367 +#define claim_nx_info(v, p) __claim_nx_info(v, p, __FILE__, __LINE__)
10368 +
10369 +static inline void __claim_nx_info(struct nx_info *nxi,
10370 +       struct task_struct *task, const char *_file, int _line)
10371 +{
10372 +       vxlprintk(VXD_CBIT(nid, 3), "claim_nx_info(%p[#%d.%d.%d]) %p",
10373 +               nxi, nxi ? nxi->nx_id : 0,
10374 +               nxi?atomic_read(&nxi->nx_usecnt):0,
10375 +               nxi?atomic_read(&nxi->nx_tasks):0,
10376 +               task, _file, _line);
10377 +
10378 +       atomic_inc(&nxi->nx_tasks);
10379 +}
10380 +
10381 +
10382 +extern void unhash_nx_info(struct nx_info *);
10383 +
10384 +#define release_nx_info(v, p) __release_nx_info(v, p, __FILE__, __LINE__)
10385 +
10386 +static inline void __release_nx_info(struct nx_info *nxi,
10387 +       struct task_struct *task, const char *_file, int _line)
10388 +{
10389 +       vxlprintk(VXD_CBIT(nid, 3), "release_nx_info(%p[#%d.%d.%d]) %p",
10390 +               nxi, nxi ? nxi->nx_id : 0,
10391 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
10392 +               nxi ? atomic_read(&nxi->nx_tasks) : 0,
10393 +               task, _file, _line);
10394 +
10395 +       might_sleep();
10396 +
10397 +       if (atomic_dec_and_test(&nxi->nx_tasks))
10398 +               unhash_nx_info(nxi);
10399 +}
10400 +
10401 +
10402 +#define task_get_nx_info(i)    __task_get_nx_info(i, __FILE__, __LINE__)
10403 +
10404 +static __inline__ struct nx_info *__task_get_nx_info(struct task_struct *p,
10405 +       const char *_file, int _line)
10406 +{
10407 +       struct nx_info *nxi;
10408 +
10409 +       task_lock(p);
10410 +       vxlprintk(VXD_CBIT(nid, 5), "task_get_nx_info(%p)",
10411 +               p, _file, _line);
10412 +       nxi = __get_nx_info(p->nx_info, _file, _line);
10413 +       task_unlock(p);
10414 +       return nxi;
10415 +}
10416 +
10417 +
10418 +static inline void exit_nx_info(struct task_struct *p)
10419 +{
10420 +       if (p->nx_info)
10421 +               release_nx_info(p->nx_info, p);
10422 +}
10423 +
10424 +
10425 +#else
10426 +#warning duplicate inclusion
10427 +#endif
10428 diff -NurpP --minimal linux-3.6.10/include/linux/vs_pid.h linux-3.6.10-vs2.3.4.5/include/linux/vs_pid.h
10429 --- linux-3.6.10/include/linux/vs_pid.h 1970-01-01 01:00:00.000000000 +0100
10430 +++ linux-3.6.10-vs2.3.4.5/include/linux/vs_pid.h       2012-10-04 18:47:00.000000000 +0200
10431 @@ -0,0 +1,50 @@
10432 +#ifndef _VS_PID_H
10433 +#define _VS_PID_H
10434 +
10435 +#include "vserver/base.h"
10436 +#include "vserver/check.h"
10437 +#include "vserver/context.h"
10438 +#include "vserver/debug.h"
10439 +#include "vserver/pid.h"
10440 +#include <linux/pid_namespace.h>
10441 +
10442 +
10443 +#define VXF_FAKE_INIT  (VXF_INFO_INIT | VXF_STATE_INIT)
10444 +
10445 +static inline
10446 +int vx_proc_task_visible(struct task_struct *task)
10447 +{
10448 +       if ((task->pid == 1) &&
10449 +               !vx_flags(VXF_FAKE_INIT, VXF_FAKE_INIT))
10450 +               /* show a blend through init */
10451 +               goto visible;
10452 +       if (vx_check(vx_task_xid(task), VS_WATCH | VS_IDENT))
10453 +               goto visible;
10454 +       return 0;
10455 +visible:
10456 +       return 1;
10457 +}
10458 +
10459 +#define find_task_by_real_pid(pid) find_task_by_pid_ns(pid, &init_pid_ns)
10460 +
10461 +
10462 +static inline
10463 +struct task_struct *vx_get_proc_task(struct inode *inode, struct pid *pid)
10464 +{
10465 +       struct task_struct *task = get_pid_task(pid, PIDTYPE_PID);
10466 +
10467 +       if (task && !vx_proc_task_visible(task)) {
10468 +               vxdprintk(VXD_CBIT(misc, 6),
10469 +                       "dropping task (get) %p[#%u,%u] for %p[#%u,%u]",
10470 +                       task, task->xid, task->pid,
10471 +                       current, current->xid, current->pid);
10472 +               put_task_struct(task);
10473 +               task = NULL;
10474 +       }
10475 +       return task;
10476 +}
10477 +
10478 +
10479 +#else
10480 +#warning duplicate inclusion
10481 +#endif
10482 diff -NurpP --minimal linux-3.6.10/include/linux/vs_sched.h linux-3.6.10-vs2.3.4.5/include/linux/vs_sched.h
10483 --- linux-3.6.10/include/linux/vs_sched.h       1970-01-01 01:00:00.000000000 +0100
10484 +++ linux-3.6.10-vs2.3.4.5/include/linux/vs_sched.h     2012-10-04 18:47:00.000000000 +0200
10485 @@ -0,0 +1,40 @@
10486 +#ifndef _VS_SCHED_H
10487 +#define _VS_SCHED_H
10488 +
10489 +#include "vserver/base.h"
10490 +#include "vserver/context.h"
10491 +#include "vserver/sched.h"
10492 +
10493 +
10494 +#define MAX_PRIO_BIAS           20
10495 +#define MIN_PRIO_BIAS          -20
10496 +
10497 +static inline
10498 +int vx_adjust_prio(struct task_struct *p, int prio, int max_user)
10499 +{
10500 +       struct vx_info *vxi = p->vx_info;
10501 +
10502 +       if (vxi)
10503 +               prio += vx_cpu(vxi, sched_pc).prio_bias;
10504 +       return prio;
10505 +}
10506 +
10507 +static inline void vx_account_user(struct vx_info *vxi,
10508 +       cputime_t cputime, int nice)
10509 +{
10510 +       if (!vxi)
10511 +               return;
10512 +       vx_cpu(vxi, sched_pc).user_ticks += cputime;
10513 +}
10514 +
10515 +static inline void vx_account_system(struct vx_info *vxi,
10516 +       cputime_t cputime, int idle)
10517 +{
10518 +       if (!vxi)
10519 +               return;
10520 +       vx_cpu(vxi, sched_pc).sys_ticks += cputime;
10521 +}
10522 +
10523 +#else
10524 +#warning duplicate inclusion
10525 +#endif
10526 diff -NurpP --minimal linux-3.6.10/include/linux/vs_socket.h linux-3.6.10-vs2.3.4.5/include/linux/vs_socket.h
10527 --- linux-3.6.10/include/linux/vs_socket.h      1970-01-01 01:00:00.000000000 +0100
10528 +++ linux-3.6.10-vs2.3.4.5/include/linux/vs_socket.h    2012-10-04 18:47:00.000000000 +0200
10529 @@ -0,0 +1,67 @@
10530 +#ifndef _VS_SOCKET_H
10531 +#define _VS_SOCKET_H
10532 +
10533 +#include "vserver/debug.h"
10534 +#include "vserver/base.h"
10535 +#include "vserver/cacct.h"
10536 +#include "vserver/context.h"
10537 +#include "vserver/tag.h"
10538 +
10539 +
10540 +/* socket accounting */
10541 +
10542 +#include <linux/socket.h>
10543 +
10544 +static inline int vx_sock_type(int family)
10545 +{
10546 +       switch (family) {
10547 +       case PF_UNSPEC:
10548 +               return VXA_SOCK_UNSPEC;
10549 +       case PF_UNIX:
10550 +               return VXA_SOCK_UNIX;
10551 +       case PF_INET:
10552 +               return VXA_SOCK_INET;
10553 +       case PF_INET6:
10554 +               return VXA_SOCK_INET6;
10555 +       case PF_PACKET:
10556 +               return VXA_SOCK_PACKET;
10557 +       default:
10558 +               return VXA_SOCK_OTHER;
10559 +       }
10560 +}
10561 +
10562 +#define vx_acc_sock(v, f, p, s) \
10563 +       __vx_acc_sock(v, f, p, s, __FILE__, __LINE__)
10564 +
10565 +static inline void __vx_acc_sock(struct vx_info *vxi,
10566 +       int family, int pos, int size, char *file, int line)
10567 +{
10568 +       if (vxi) {
10569 +               int type = vx_sock_type(family);
10570 +
10571 +               atomic_long_inc(&vxi->cacct.sock[type][pos].count);
10572 +               atomic_long_add(size, &vxi->cacct.sock[type][pos].total);
10573 +       }
10574 +}
10575 +
10576 +#define vx_sock_recv(sk, s) \
10577 +       vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 0, s)
10578 +#define vx_sock_send(sk, s) \
10579 +       vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 1, s)
10580 +#define vx_sock_fail(sk, s) \
10581 +       vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 2, s)
10582 +
10583 +
10584 +#define sock_vx_init(s) do {           \
10585 +       (s)->sk_xid = 0;                \
10586 +       (s)->sk_vx_info = NULL;         \
10587 +       } while (0)
10588 +
10589 +#define sock_nx_init(s) do {           \
10590 +       (s)->sk_nid = 0;                \
10591 +       (s)->sk_nx_info = NULL;         \
10592 +       } while (0)
10593 +
10594 +#else
10595 +#warning duplicate inclusion
10596 +#endif
10597 diff -NurpP --minimal linux-3.6.10/include/linux/vs_tag.h linux-3.6.10-vs2.3.4.5/include/linux/vs_tag.h
10598 --- linux-3.6.10/include/linux/vs_tag.h 1970-01-01 01:00:00.000000000 +0100
10599 +++ linux-3.6.10-vs2.3.4.5/include/linux/vs_tag.h       2012-10-04 18:47:00.000000000 +0200
10600 @@ -0,0 +1,47 @@
10601 +#ifndef _VS_TAG_H
10602 +#define _VS_TAG_H
10603 +
10604 +#include <linux/vserver/tag.h>
10605 +
10606 +/* check conditions */
10607 +
10608 +#define DX_ADMIN       0x0001
10609 +#define DX_WATCH       0x0002
10610 +#define DX_HOSTID      0x0008
10611 +
10612 +#define DX_IDENT       0x0010
10613 +
10614 +#define DX_ARG_MASK    0x0010
10615 +
10616 +
10617 +#define dx_task_tag(t) ((t)->tag)
10618 +
10619 +#define dx_current_tag() dx_task_tag(current)
10620 +
10621 +#define dx_check(c, m) __dx_check(dx_current_tag(), c, m)
10622 +
10623 +#define dx_weak_check(c, m)    ((m) ? dx_check(c, m) : 1)
10624 +
10625 +
10626 +/*
10627 + * check current context for ADMIN/WATCH and
10628 + * optionally against supplied argument
10629 + */
10630 +static inline int __dx_check(tag_t cid, tag_t id, unsigned int mode)
10631 +{
10632 +       if (mode & DX_ARG_MASK) {
10633 +               if ((mode & DX_IDENT) && (id == cid))
10634 +                       return 1;
10635 +       }
10636 +       return (((mode & DX_ADMIN) && (cid == 0)) ||
10637 +               ((mode & DX_WATCH) && (cid == 1)) ||
10638 +               ((mode & DX_HOSTID) && (id == 0)));
10639 +}
10640 +
10641 +struct inode;
10642 +int dx_permission(const struct inode *inode, int mask);
10643 +
10644 +
10645 +#else
10646 +#warning duplicate inclusion
10647 +#endif
10648 diff -NurpP --minimal linux-3.6.10/include/linux/vs_time.h linux-3.6.10-vs2.3.4.5/include/linux/vs_time.h
10649 --- linux-3.6.10/include/linux/vs_time.h        1970-01-01 01:00:00.000000000 +0100
10650 +++ linux-3.6.10-vs2.3.4.5/include/linux/vs_time.h      2012-10-04 18:47:00.000000000 +0200
10651 @@ -0,0 +1,19 @@
10652 +#ifndef _VS_TIME_H
10653 +#define _VS_TIME_H
10654 +
10655 +
10656 +/* time faking stuff */
10657 +
10658 +#ifdef CONFIG_VSERVER_VTIME
10659 +
10660 +extern void vx_adjust_timespec(struct timespec *ts);
10661 +extern int vx_settimeofday(const struct timespec *ts);
10662 +
10663 +#else
10664 +#define        vx_adjust_timespec(t)   do { } while (0)
10665 +#define        vx_settimeofday(t)      do_settimeofday(t)
10666 +#endif
10667 +
10668 +#else
10669 +#warning duplicate inclusion
10670 +#endif
10671 diff -NurpP --minimal linux-3.6.10/include/linux/vserver/Kbuild linux-3.6.10-vs2.3.4.5/include/linux/vserver/Kbuild
10672 --- linux-3.6.10/include/linux/vserver/Kbuild   1970-01-01 01:00:00.000000000 +0100
10673 +++ linux-3.6.10-vs2.3.4.5/include/linux/vserver/Kbuild 2012-10-04 18:47:00.000000000 +0200
10674 @@ -0,0 +1,8 @@
10675 +
10676 +header-y += context_cmd.h network_cmd.h space_cmd.h \
10677 +       cacct_cmd.h cvirt_cmd.h limit_cmd.h dlimit_cmd.h \
10678 +       inode_cmd.h tag_cmd.h sched_cmd.h signal_cmd.h \
10679 +       debug_cmd.h device_cmd.h
10680 +
10681 +header-y += switch.h network.h monitor.h inode.h device.h
10682 +
10683 diff -NurpP --minimal linux-3.6.10/include/linux/vserver/base.h linux-3.6.10-vs2.3.4.5/include/linux/vserver/base.h
10684 --- linux-3.6.10/include/linux/vserver/base.h   1970-01-01 01:00:00.000000000 +0100
10685 +++ linux-3.6.10-vs2.3.4.5/include/linux/vserver/base.h 2012-10-04 18:47:00.000000000 +0200
10686 @@ -0,0 +1,178 @@
10687 +#ifndef _VX_BASE_H
10688 +#define _VX_BASE_H
10689 +
10690 +
10691 +/* context state changes */
10692 +
10693 +enum {
10694 +       VSC_STARTUP = 1,
10695 +       VSC_SHUTDOWN,
10696 +
10697 +       VSC_NETUP,
10698 +       VSC_NETDOWN,
10699 +};
10700 +
10701 +
10702 +
10703 +#define vx_task_xid(t) ((t)->xid)
10704 +
10705 +#define vx_current_xid() vx_task_xid(current)
10706 +
10707 +#define current_vx_info() (current->vx_info)
10708 +
10709 +
10710 +#define nx_task_nid(t) ((t)->nid)
10711 +
10712 +#define nx_current_nid() nx_task_nid(current)
10713 +
10714 +#define current_nx_info() (current->nx_info)
10715 +
10716 +
10717 +/* generic flag merging */
10718 +
10719 +#define vs_check_flags(v, m, f)        (((v) & (m)) ^ (f))
10720 +
10721 +#define vs_mask_flags(v, f, m) (((v) & ~(m)) | ((f) & (m)))
10722 +
10723 +#define vs_mask_mask(v, f, m)  (((v) & ~(m)) | ((v) & (f) & (m)))
10724 +
10725 +#define vs_check_bit(v, n)     ((v) & (1LL << (n)))
10726 +
10727 +
10728 +/* context flags */
10729 +
10730 +#define __vx_flags(v)  ((v) ? (v)->vx_flags : 0)
10731 +
10732 +#define vx_current_flags()     __vx_flags(current_vx_info())
10733 +
10734 +#define vx_info_flags(v, m, f) \
10735 +       vs_check_flags(__vx_flags(v), m, f)
10736 +
10737 +#define task_vx_flags(t, m, f) \
10738 +       ((t) && vx_info_flags((t)->vx_info, m, f))
10739 +
10740 +#define vx_flags(m, f) vx_info_flags(current_vx_info(), m, f)
10741 +
10742 +
10743 +/* context caps */
10744 +
10745 +#define __vx_ccaps(v)  ((v) ? (v)->vx_ccaps : 0)
10746 +
10747 +#define vx_current_ccaps()     __vx_ccaps(current_vx_info())
10748 +
10749 +#define vx_info_ccaps(v, c)    (__vx_ccaps(v) & (c))
10750 +
10751 +#define vx_ccaps(c)    vx_info_ccaps(current_vx_info(), (c))
10752 +
10753 +
10754 +
10755 +/* network flags */
10756 +
10757 +#define __nx_flags(n)  ((n) ? (n)->nx_flags : 0)
10758 +
10759 +#define nx_current_flags()     __nx_flags(current_nx_info())
10760 +
10761 +#define nx_info_flags(n, m, f) \
10762 +       vs_check_flags(__nx_flags(n), m, f)
10763 +
10764 +#define task_nx_flags(t, m, f) \
10765 +       ((t) && nx_info_flags((t)->nx_info, m, f))
10766 +
10767 +#define nx_flags(m, f) nx_info_flags(current_nx_info(), m, f)
10768 +
10769 +
10770 +/* network caps */
10771 +
10772 +#define __nx_ncaps(n)  ((n) ? (n)->nx_ncaps : 0)
10773 +
10774 +#define nx_current_ncaps()     __nx_ncaps(current_nx_info())
10775 +
10776 +#define nx_info_ncaps(n, c)    (__nx_ncaps(n) & (c))
10777 +
10778 +#define nx_ncaps(c)    nx_info_ncaps(current_nx_info(), c)
10779 +
10780 +
10781 +/* context mask capabilities */
10782 +
10783 +#define __vx_mcaps(v)  ((v) ? (v)->vx_ccaps >> 32UL : ~0 )
10784 +
10785 +#define vx_info_mcaps(v, c)    (__vx_mcaps(v) & (c))
10786 +
10787 +#define vx_mcaps(c)    vx_info_mcaps(current_vx_info(), c)
10788 +
10789 +
10790 +/* context bcap mask */
10791 +
10792 +#define __vx_bcaps(v)          ((v)->vx_bcaps)
10793 +
10794 +#define vx_current_bcaps()     __vx_bcaps(current_vx_info())
10795 +
10796 +
10797 +/* mask given bcaps */
10798 +
10799 +#define vx_info_mbcaps(v, c)   ((v) ? cap_intersect(__vx_bcaps(v), c) : c)
10800 +
10801 +#define vx_mbcaps(c)           vx_info_mbcaps(current_vx_info(), c)
10802 +
10803 +
10804 +/* masked cap_bset */
10805 +
10806 +#define vx_info_cap_bset(v)    vx_info_mbcaps(v, current->cap_bset)
10807 +
10808 +#define vx_current_cap_bset()  vx_info_cap_bset(current_vx_info())
10809 +
10810 +#if 0
10811 +#define vx_info_mbcap(v, b) \
10812 +       (!vx_info_flags(v, VXF_STATE_SETUP, 0) ? \
10813 +       vx_info_bcaps(v, b) : (b))
10814 +
10815 +#define task_vx_mbcap(t, b) \
10816 +       vx_info_mbcap((t)->vx_info, (t)->b)
10817 +
10818 +#define vx_mbcap(b)    task_vx_mbcap(current, b)
10819 +#endif
10820 +
10821 +#define vx_cap_raised(v, c, f) cap_raised(vx_info_mbcaps(v, c), f)
10822 +
10823 +#define vx_capable(b, c) (capable(b) || \
10824 +       (cap_raised(current_cap(), b) && vx_ccaps(c)))
10825 +
10826 +#define vx_ns_capable(n, b, c) (ns_capable(n, b) || \
10827 +       (cap_raised(current_cap(), b) && vx_ccaps(c)))
10828 +
10829 +#define nx_capable(b, c) (capable(b) || \
10830 +       (cap_raised(current_cap(), b) && nx_ncaps(c)))
10831 +
10832 +#define vx_task_initpid(t, n) \
10833 +       ((t)->vx_info && \
10834 +       ((t)->vx_info->vx_initpid == (n)))
10835 +
10836 +#define vx_current_initpid(n)  vx_task_initpid(current, n)
10837 +
10838 +
10839 +/* context unshare mask */
10840 +
10841 +#define __vx_umask(v)          ((v)->vx_umask)
10842 +
10843 +#define vx_current_umask()     __vx_umask(current_vx_info())
10844 +
10845 +#define vx_can_unshare(b, f) (capable(b) || \
10846 +       (cap_raised(current_cap(), b) && \
10847 +       !((f) & ~vx_current_umask())))
10848 +
10849 +
10850 +#define __vx_wmask(v)          ((v)->vx_wmask)
10851 +
10852 +#define vx_current_wmask()     __vx_wmask(current_vx_info())
10853 +
10854 +
10855 +#define __vx_state(v)  ((v) ? ((v)->vx_state) : 0)
10856 +
10857 +#define vx_info_state(v, m)    (__vx_state(v) & (m))
10858 +
10859 +
10860 +#define __nx_state(n)  ((n) ? ((n)->nx_state) : 0)
10861 +
10862 +#define nx_info_state(n, m)    (__nx_state(n) & (m))
10863 +
10864 +#endif
10865 diff -NurpP --minimal linux-3.6.10/include/linux/vserver/cacct.h linux-3.6.10-vs2.3.4.5/include/linux/vserver/cacct.h
10866 --- linux-3.6.10/include/linux/vserver/cacct.h  1970-01-01 01:00:00.000000000 +0100
10867 +++ linux-3.6.10-vs2.3.4.5/include/linux/vserver/cacct.h        2012-10-04 18:47:00.000000000 +0200
10868 @@ -0,0 +1,15 @@
10869 +#ifndef _VX_CACCT_H
10870 +#define _VX_CACCT_H
10871 +
10872 +
10873 +enum sock_acc_field {
10874 +       VXA_SOCK_UNSPEC = 0,
10875 +       VXA_SOCK_UNIX,
10876 +       VXA_SOCK_INET,
10877 +       VXA_SOCK_INET6,
10878 +       VXA_SOCK_PACKET,
10879 +       VXA_SOCK_OTHER,
10880 +       VXA_SOCK_SIZE   /* array size */
10881 +};
10882 +
10883 +#endif /* _VX_CACCT_H */
10884 diff -NurpP --minimal linux-3.6.10/include/linux/vserver/cacct_cmd.h linux-3.6.10-vs2.3.4.5/include/linux/vserver/cacct_cmd.h
10885 --- linux-3.6.10/include/linux/vserver/cacct_cmd.h      1970-01-01 01:00:00.000000000 +0100
10886 +++ linux-3.6.10-vs2.3.4.5/include/linux/vserver/cacct_cmd.h    2012-10-04 18:47:00.000000000 +0200
10887 @@ -0,0 +1,23 @@
10888 +#ifndef _VX_CACCT_CMD_H
10889 +#define _VX_CACCT_CMD_H
10890 +
10891 +
10892 +/* virtual host info name commands */
10893 +
10894 +#define VCMD_sock_stat         VC_CMD(VSTAT, 5, 0)
10895 +
10896 +struct vcmd_sock_stat_v0 {
10897 +       uint32_t field;
10898 +       uint32_t count[3];
10899 +       uint64_t total[3];
10900 +};
10901 +
10902 +
10903 +#ifdef __KERNEL__
10904 +
10905 +#include <linux/compiler.h>
10906 +
10907 +extern int vc_sock_stat(struct vx_info *, void __user *);
10908 +
10909 +#endif /* __KERNEL__ */
10910 +#endif /* _VX_CACCT_CMD_H */
10911 diff -NurpP --minimal linux-3.6.10/include/linux/vserver/cacct_def.h linux-3.6.10-vs2.3.4.5/include/linux/vserver/cacct_def.h
10912 --- linux-3.6.10/include/linux/vserver/cacct_def.h      1970-01-01 01:00:00.000000000 +0100
10913 +++ linux-3.6.10-vs2.3.4.5/include/linux/vserver/cacct_def.h    2012-10-04 18:47:00.000000000 +0200
10914 @@ -0,0 +1,43 @@
10915 +#ifndef _VX_CACCT_DEF_H
10916 +#define _VX_CACCT_DEF_H
10917 +
10918 +#include <asm/atomic.h>
10919 +#include <linux/vserver/cacct.h>
10920 +
10921 +
10922 +struct _vx_sock_acc {
10923 +       atomic_long_t count;
10924 +       atomic_long_t total;
10925 +};
10926 +
10927 +/* context sub struct */
10928 +
10929 +struct _vx_cacct {
10930 +       struct _vx_sock_acc sock[VXA_SOCK_SIZE][3];
10931 +       atomic_t slab[8];
10932 +       atomic_t page[6][8];
10933 +};
10934 +
10935 +#ifdef CONFIG_VSERVER_DEBUG
10936 +
10937 +static inline void __dump_vx_cacct(struct _vx_cacct *cacct)
10938 +{
10939 +       int i, j;
10940 +
10941 +       printk("\t_vx_cacct:");
10942 +       for (i = 0; i < 6; i++) {
10943 +               struct _vx_sock_acc *ptr = cacct->sock[i];
10944 +
10945 +               printk("\t [%d] =", i);
10946 +               for (j = 0; j < 3; j++) {
10947 +                       printk(" [%d] = %8lu, %8lu", j,
10948 +                               atomic_long_read(&ptr[j].count),
10949 +                               atomic_long_read(&ptr[j].total));
10950 +               }
10951 +               printk("\n");
10952 +       }
10953 +}
10954 +
10955 +#endif
10956 +
10957 +#endif /* _VX_CACCT_DEF_H */
10958 diff -NurpP --minimal linux-3.6.10/include/linux/vserver/cacct_int.h linux-3.6.10-vs2.3.4.5/include/linux/vserver/cacct_int.h
10959 --- linux-3.6.10/include/linux/vserver/cacct_int.h      1970-01-01 01:00:00.000000000 +0100
10960 +++ linux-3.6.10-vs2.3.4.5/include/linux/vserver/cacct_int.h    2012-10-04 18:47:00.000000000 +0200
10961 @@ -0,0 +1,21 @@
10962 +#ifndef _VX_CACCT_INT_H
10963 +#define _VX_CACCT_INT_H
10964 +
10965 +
10966 +#ifdef __KERNEL__
10967 +
10968 +static inline
10969 +unsigned long vx_sock_count(struct _vx_cacct *cacct, int type, int pos)
10970 +{
10971 +       return atomic_long_read(&cacct->sock[type][pos].count);
10972 +}
10973 +
10974 +
10975 +static inline
10976 +unsigned long vx_sock_total(struct _vx_cacct *cacct, int type, int pos)
10977 +{
10978 +       return atomic_long_read(&cacct->sock[type][pos].total);
10979 +}
10980 +
10981 +#endif /* __KERNEL__ */
10982 +#endif /* _VX_CACCT_INT_H */
10983 diff -NurpP --minimal linux-3.6.10/include/linux/vserver/check.h linux-3.6.10-vs2.3.4.5/include/linux/vserver/check.h
10984 --- linux-3.6.10/include/linux/vserver/check.h  1970-01-01 01:00:00.000000000 +0100
10985 +++ linux-3.6.10-vs2.3.4.5/include/linux/vserver/check.h        2012-10-04 18:47:00.000000000 +0200
10986 @@ -0,0 +1,89 @@
10987 +#ifndef _VS_CHECK_H
10988 +#define _VS_CHECK_H
10989 +
10990 +
10991 +#define MAX_S_CONTEXT  65535   /* Arbitrary limit */
10992 +
10993 +#ifdef CONFIG_VSERVER_DYNAMIC_IDS
10994 +#define MIN_D_CONTEXT  49152   /* dynamic contexts start here */
10995 +#else
10996 +#define MIN_D_CONTEXT  65536
10997 +#endif
10998 +
10999 +/* check conditions */
11000 +
11001 +#define VS_ADMIN       0x0001
11002 +#define VS_WATCH       0x0002
11003 +#define VS_HIDE                0x0004
11004 +#define VS_HOSTID      0x0008
11005 +
11006 +#define VS_IDENT       0x0010
11007 +#define VS_EQUIV       0x0020
11008 +#define VS_PARENT      0x0040
11009 +#define VS_CHILD       0x0080
11010 +
11011 +#define VS_ARG_MASK    0x00F0
11012 +
11013 +#define VS_DYNAMIC     0x0100
11014 +#define VS_STATIC      0x0200
11015 +
11016 +#define VS_ATR_MASK    0x0F00
11017 +
11018 +#ifdef CONFIG_VSERVER_PRIVACY
11019 +#define VS_ADMIN_P     (0)
11020 +#define VS_WATCH_P     (0)
11021 +#else
11022 +#define VS_ADMIN_P     VS_ADMIN
11023 +#define VS_WATCH_P     VS_WATCH
11024 +#endif
11025 +
11026 +#define VS_HARDIRQ     0x1000
11027 +#define VS_SOFTIRQ     0x2000
11028 +#define VS_IRQ         0x4000
11029 +
11030 +#define VS_IRQ_MASK    0xF000
11031 +
11032 +#include <linux/hardirq.h>
11033 +
11034 +/*
11035 + * check current context for ADMIN/WATCH and
11036 + * optionally against supplied argument
11037 + */
11038 +static inline int __vs_check(int cid, int id, unsigned int mode)
11039 +{
11040 +       if (mode & VS_ARG_MASK) {
11041 +               if ((mode & VS_IDENT) && (id == cid))
11042 +                       return 1;
11043 +       }
11044 +       if (mode & VS_ATR_MASK) {
11045 +               if ((mode & VS_DYNAMIC) &&
11046 +                       (id >= MIN_D_CONTEXT) &&
11047 +                       (id <= MAX_S_CONTEXT))
11048 +                       return 1;
11049 +               if ((mode & VS_STATIC) &&
11050 +                       (id > 1) && (id < MIN_D_CONTEXT))
11051 +                       return 1;
11052 +       }
11053 +       if (mode & VS_IRQ_MASK) {
11054 +               if ((mode & VS_IRQ) && unlikely(in_interrupt()))
11055 +                       return 1;
11056 +               if ((mode & VS_HARDIRQ) && unlikely(in_irq()))
11057 +                       return 1;
11058 +               if ((mode & VS_SOFTIRQ) && unlikely(in_softirq()))
11059 +                       return 1;
11060 +       }
11061 +       return (((mode & VS_ADMIN) && (cid == 0)) ||
11062 +               ((mode & VS_WATCH) && (cid == 1)) ||
11063 +               ((mode & VS_HOSTID) && (id == 0)));
11064 +}
11065 +
11066 +#define vx_check(c, m) __vs_check(vx_current_xid(), c, (m) | VS_IRQ)
11067 +
11068 +#define vx_weak_check(c, m)    ((m) ? vx_check(c, m) : 1)
11069 +
11070 +
11071 +#define nx_check(c, m) __vs_check(nx_current_nid(), c, m)
11072 +
11073 +#define nx_weak_check(c, m)    ((m) ? nx_check(c, m) : 1)
11074 +
11075 +#endif
11076 diff -NurpP --minimal linux-3.6.10/include/linux/vserver/context.h linux-3.6.10-vs2.3.4.5/include/linux/vserver/context.h
11077 --- linux-3.6.10/include/linux/vserver/context.h        1970-01-01 01:00:00.000000000 +0100
11078 +++ linux-3.6.10-vs2.3.4.5/include/linux/vserver/context.h      2012-10-04 18:47:00.000000000 +0200
11079 @@ -0,0 +1,188 @@
11080 +#ifndef _VX_CONTEXT_H
11081 +#define _VX_CONTEXT_H
11082 +
11083 +#include <linux/types.h>
11084 +#include <linux/capability.h>
11085 +
11086 +
11087 +/* context flags */
11088 +
11089 +#define VXF_INFO_SCHED         0x00000002
11090 +#define VXF_INFO_NPROC         0x00000004
11091 +#define VXF_INFO_PRIVATE       0x00000008
11092 +
11093 +#define VXF_INFO_INIT          0x00000010
11094 +#define VXF_INFO_HIDE          0x00000020
11095 +#define VXF_INFO_ULIMIT                0x00000040
11096 +#define VXF_INFO_NSPACE                0x00000080
11097 +
11098 +#define VXF_SCHED_HARD         0x00000100
11099 +#define VXF_SCHED_PRIO         0x00000200
11100 +#define VXF_SCHED_PAUSE                0x00000400
11101 +
11102 +#define VXF_VIRT_MEM           0x00010000
11103 +#define VXF_VIRT_UPTIME                0x00020000
11104 +#define VXF_VIRT_CPU           0x00040000
11105 +#define VXF_VIRT_LOAD          0x00080000
11106 +#define VXF_VIRT_TIME          0x00100000
11107 +
11108 +#define VXF_HIDE_MOUNT         0x01000000
11109 +/* was VXF_HIDE_NETIF          0x02000000 */
11110 +#define VXF_HIDE_VINFO         0x04000000
11111 +
11112 +#define VXF_STATE_SETUP                (1ULL << 32)
11113 +#define VXF_STATE_INIT         (1ULL << 33)
11114 +#define VXF_STATE_ADMIN                (1ULL << 34)
11115 +
11116 +#define VXF_SC_HELPER          (1ULL << 36)
11117 +#define VXF_REBOOT_KILL                (1ULL << 37)
11118 +#define VXF_PERSISTENT         (1ULL << 38)
11119 +
11120 +#define VXF_FORK_RSS           (1ULL << 48)
11121 +#define VXF_PROLIFIC           (1ULL << 49)
11122 +
11123 +#define VXF_IGNEG_NICE         (1ULL << 52)
11124 +
11125 +#define VXF_ONE_TIME           (0x0007ULL << 32)
11126 +
11127 +#define VXF_INIT_SET           (VXF_STATE_SETUP | VXF_STATE_INIT | VXF_STATE_ADMIN)
11128 +
11129 +
11130 +/* context migration */
11131 +
11132 +#define VXM_SET_INIT           0x00000001
11133 +#define VXM_SET_REAPER         0x00000002
11134 +
11135 +/* context caps */
11136 +
11137 +#define VXC_SET_UTSNAME                0x00000001
11138 +#define VXC_SET_RLIMIT         0x00000002
11139 +#define VXC_FS_SECURITY                0x00000004
11140 +#define VXC_FS_TRUSTED         0x00000008
11141 +#define VXC_TIOCSTI            0x00000010
11142 +
11143 +/* was VXC_RAW_ICMP            0x00000100 */
11144 +#define VXC_SYSLOG             0x00001000
11145 +#define VXC_OOM_ADJUST         0x00002000
11146 +#define VXC_AUDIT_CONTROL      0x00004000
11147 +
11148 +#define VXC_SECURE_MOUNT       0x00010000
11149 +#define VXC_SECURE_REMOUNT     0x00020000
11150 +#define VXC_BINARY_MOUNT       0x00040000
11151 +
11152 +#define VXC_QUOTA_CTL          0x00100000
11153 +#define VXC_ADMIN_MAPPER       0x00200000
11154 +#define VXC_ADMIN_CLOOP                0x00400000
11155 +
11156 +#define VXC_KTHREAD            0x01000000
11157 +#define VXC_NAMESPACE          0x02000000
11158 +
11159 +
11160 +#ifdef __KERNEL__
11161 +
11162 +#include <linux/list.h>
11163 +#include <linux/spinlock.h>
11164 +#include <linux/rcupdate.h>
11165 +
11166 +#include "limit_def.h"
11167 +#include "sched_def.h"
11168 +#include "cvirt_def.h"
11169 +#include "cacct_def.h"
11170 +#include "device_def.h"
11171 +
11172 +#define VX_SPACES      2
11173 +
11174 +struct _vx_info_pc {
11175 +       struct _vx_sched_pc sched_pc;
11176 +       struct _vx_cvirt_pc cvirt_pc;
11177 +};
11178 +
11179 +struct _vx_space {
11180 +       unsigned long vx_nsmask;                /* assignment mask */
11181 +       struct nsproxy *vx_nsproxy;             /* private namespaces */
11182 +       struct fs_struct *vx_fs;                /* private namespace fs */
11183 +       const struct cred *vx_cred;             /* task credentials */
11184 +};
11185 +
11186 +struct vx_info {
11187 +       struct hlist_node vx_hlist;             /* linked list of contexts */
11188 +       xid_t vx_id;                            /* context id */
11189 +       atomic_t vx_usecnt;                     /* usage count */
11190 +       atomic_t vx_tasks;                      /* tasks count */
11191 +       struct vx_info *vx_parent;              /* parent context */
11192 +       int vx_state;                           /* context state */
11193 +
11194 +       struct _vx_space space[VX_SPACES];      /* namespace store */
11195 +
11196 +       uint64_t vx_flags;                      /* context flags */
11197 +       uint64_t vx_ccaps;                      /* context caps (vserver) */
11198 +       uint64_t vx_umask;                      /* unshare mask (guest) */
11199 +       uint64_t vx_wmask;                      /* warn mask (guest) */
11200 +       kernel_cap_t vx_bcaps;                  /* bounding caps (system) */
11201 +
11202 +       struct task_struct *vx_reaper;          /* guest reaper process */
11203 +       pid_t vx_initpid;                       /* PID of guest init */
11204 +       int64_t vx_badness_bias;                /* OOM points bias */
11205 +
11206 +       struct _vx_limit limit;                 /* vserver limits */
11207 +       struct _vx_sched sched;                 /* vserver scheduler */
11208 +       struct _vx_cvirt cvirt;                 /* virtual/bias stuff */
11209 +       struct _vx_cacct cacct;                 /* context accounting */
11210 +
11211 +       struct _vx_device dmap;                 /* default device map targets */
11212 +
11213 +#ifndef CONFIG_SMP
11214 +       struct _vx_info_pc info_pc;             /* per cpu data */
11215 +#else
11216 +       struct _vx_info_pc *ptr_pc;             /* per cpu array */
11217 +#endif
11218 +
11219 +       wait_queue_head_t vx_wait;              /* context exit waitqueue */
11220 +       int reboot_cmd;                         /* last sys_reboot() cmd */
11221 +       int exit_code;                          /* last process exit code */
11222 +
11223 +       char vx_name[65];                       /* vserver name */
11224 +};
11225 +
11226 +#ifndef CONFIG_SMP
11227 +#define        vx_ptr_pc(vxi)          (&(vxi)->info_pc)
11228 +#define        vx_per_cpu(vxi, v, id)  vx_ptr_pc(vxi)->v
11229 +#else
11230 +#define        vx_ptr_pc(vxi)          ((vxi)->ptr_pc)
11231 +#define        vx_per_cpu(vxi, v, id)  per_cpu_ptr(vx_ptr_pc(vxi), id)->v
11232 +#endif
11233 +
11234 +#define        vx_cpu(vxi, v)          vx_per_cpu(vxi, v, smp_processor_id())
11235 +
11236 +
11237 +struct vx_info_save {
11238 +       struct vx_info *vxi;
11239 +       xid_t xid;
11240 +};
11241 +
11242 +
11243 +/* status flags */
11244 +
11245 +#define VXS_HASHED     0x0001
11246 +#define VXS_PAUSED     0x0010
11247 +#define VXS_SHUTDOWN   0x0100
11248 +#define VXS_HELPER     0x1000
11249 +#define VXS_RELEASED   0x8000
11250 +
11251 +
11252 +extern void claim_vx_info(struct vx_info *, struct task_struct *);
11253 +extern void release_vx_info(struct vx_info *, struct task_struct *);
11254 +
11255 +extern struct vx_info *lookup_vx_info(int);
11256 +extern struct vx_info *lookup_or_create_vx_info(int);
11257 +
11258 +extern int get_xid_list(int, unsigned int *, int);
11259 +extern int xid_is_hashed(xid_t);
11260 +
11261 +extern int vx_migrate_task(struct task_struct *, struct vx_info *, int);
11262 +
11263 +extern long vs_state_change(struct vx_info *, unsigned int);
11264 +
11265 +
11266 +#endif /* __KERNEL__ */
11267 +#endif /* _VX_CONTEXT_H */
11268 diff -NurpP --minimal linux-3.6.10/include/linux/vserver/context_cmd.h linux-3.6.10-vs2.3.4.5/include/linux/vserver/context_cmd.h
11269 --- linux-3.6.10/include/linux/vserver/context_cmd.h    1970-01-01 01:00:00.000000000 +0100
11270 +++ linux-3.6.10-vs2.3.4.5/include/linux/vserver/context_cmd.h  2012-10-04 18:47:00.000000000 +0200
11271 @@ -0,0 +1,162 @@
11272 +#ifndef _VX_CONTEXT_CMD_H
11273 +#define _VX_CONTEXT_CMD_H
11274 +
11275 +
11276 +/* vinfo commands */
11277 +
11278 +#define VCMD_task_xid          VC_CMD(VINFO, 1, 0)
11279 +
11280 +#ifdef __KERNEL__
11281 +extern int vc_task_xid(uint32_t);
11282 +
11283 +#endif /* __KERNEL__ */
11284 +
11285 +#define VCMD_vx_info           VC_CMD(VINFO, 5, 0)
11286 +
11287 +struct vcmd_vx_info_v0 {
11288 +       uint32_t xid;
11289 +       uint32_t initpid;
11290 +       /* more to come */
11291 +};
11292 +
11293 +#ifdef __KERNEL__
11294 +extern int vc_vx_info(struct vx_info *, void __user *);
11295 +
11296 +#endif /* __KERNEL__ */
11297 +
11298 +#define VCMD_ctx_stat          VC_CMD(VSTAT, 0, 0)
11299 +
11300 +struct vcmd_ctx_stat_v0 {
11301 +       uint32_t usecnt;
11302 +       uint32_t tasks;
11303 +       /* more to come */
11304 +};
11305 +
11306 +#ifdef __KERNEL__
11307 +extern int vc_ctx_stat(struct vx_info *, void __user *);
11308 +
11309 +#endif /* __KERNEL__ */
11310 +
11311 +/* context commands */
11312 +
11313 +#define VCMD_ctx_create_v0     VC_CMD(VPROC, 1, 0)
11314 +#define VCMD_ctx_create                VC_CMD(VPROC, 1, 1)
11315 +
11316 +struct vcmd_ctx_create {
11317 +       uint64_t flagword;
11318 +};
11319 +
11320 +#define VCMD_ctx_migrate_v0    VC_CMD(PROCMIG, 1, 0)
11321 +#define VCMD_ctx_migrate       VC_CMD(PROCMIG, 1, 1)
11322 +
11323 +struct vcmd_ctx_migrate {
11324 +       uint64_t flagword;
11325 +};
11326 +
11327 +#ifdef __KERNEL__
11328 +extern int vc_ctx_create(uint32_t, void __user *);
11329 +extern int vc_ctx_migrate(struct vx_info *, void __user *);
11330 +
11331 +#endif /* __KERNEL__ */
11332 +
11333 +
11334 +/* flag commands */
11335 +
11336 +#define VCMD_get_cflags                VC_CMD(FLAGS, 1, 0)
11337 +#define VCMD_set_cflags                VC_CMD(FLAGS, 2, 0)
11338 +
11339 +struct vcmd_ctx_flags_v0 {
11340 +       uint64_t flagword;
11341 +       uint64_t mask;
11342 +};
11343 +
11344 +#ifdef __KERNEL__
11345 +extern int vc_get_cflags(struct vx_info *, void __user *);
11346 +extern int vc_set_cflags(struct vx_info *, void __user *);
11347 +
11348 +#endif /* __KERNEL__ */
11349 +
11350 +
11351 +/* context caps commands */
11352 +
11353 +#define VCMD_get_ccaps         VC_CMD(FLAGS, 3, 1)
11354 +#define VCMD_set_ccaps         VC_CMD(FLAGS, 4, 1)
11355 +
11356 +struct vcmd_ctx_caps_v1 {
11357 +       uint64_t ccaps;
11358 +       uint64_t cmask;
11359 +};
11360 +
11361 +#ifdef __KERNEL__
11362 +extern int vc_get_ccaps(struct vx_info *, void __user *);
11363 +extern int vc_set_ccaps(struct vx_info *, void __user *);
11364 +
11365 +#endif /* __KERNEL__ */
11366 +
11367 +
11368 +/* bcaps commands */
11369 +
11370 +#define VCMD_get_bcaps         VC_CMD(FLAGS, 9, 0)
11371 +#define VCMD_set_bcaps         VC_CMD(FLAGS, 10, 0)
11372 +
11373 +struct vcmd_bcaps {
11374 +       uint64_t bcaps;
11375 +       uint64_t bmask;
11376 +};
11377 +
11378 +#ifdef __KERNEL__
11379 +extern int vc_get_bcaps(struct vx_info *, void __user *);
11380 +extern int vc_set_bcaps(struct vx_info *, void __user *);
11381 +
11382 +#endif /* __KERNEL__ */
11383 +
11384 +
11385 +/* umask commands */
11386 +
11387 +#define VCMD_get_umask         VC_CMD(FLAGS, 13, 0)
11388 +#define VCMD_set_umask         VC_CMD(FLAGS, 14, 0)
11389 +
11390 +struct vcmd_umask {
11391 +       uint64_t umask;
11392 +       uint64_t mask;
11393 +};
11394 +
11395 +#ifdef __KERNEL__
11396 +extern int vc_get_umask(struct vx_info *, void __user *);
11397 +extern int vc_set_umask(struct vx_info *, void __user *);
11398 +
11399 +#endif /* __KERNEL__ */
11400 +
11401 +
11402 +/* wmask commands */
11403 +
11404 +#define VCMD_get_wmask         VC_CMD(FLAGS, 15, 0)
11405 +#define VCMD_set_wmask         VC_CMD(FLAGS, 16, 0)
11406 +
11407 +struct vcmd_wmask {
11408 +       uint64_t wmask;
11409 +       uint64_t mask;
11410 +};
11411 +
11412 +#ifdef __KERNEL__
11413 +extern int vc_get_wmask(struct vx_info *, void __user *);
11414 +extern int vc_set_wmask(struct vx_info *, void __user *);
11415 +
11416 +#endif /* __KERNEL__ */
11417 +
11418 +
11419 +/* OOM badness */
11420 +
11421 +#define VCMD_get_badness       VC_CMD(MEMCTRL, 5, 0)
11422 +#define VCMD_set_badness       VC_CMD(MEMCTRL, 6, 0)
11423 +
11424 +struct vcmd_badness_v0 {
11425 +       int64_t bias;
11426 +};
11427 +
11428 +#ifdef __KERNEL__
11429 +extern int vc_get_badness(struct vx_info *, void __user *);
11430 +extern int vc_set_badness(struct vx_info *, void __user *);
11431 +
11432 +#endif /* __KERNEL__ */
11433 +#endif /* _VX_CONTEXT_CMD_H */
11434 diff -NurpP --minimal linux-3.6.10/include/linux/vserver/cvirt.h linux-3.6.10-vs2.3.4.5/include/linux/vserver/cvirt.h
11435 --- linux-3.6.10/include/linux/vserver/cvirt.h  1970-01-01 01:00:00.000000000 +0100
11436 +++ linux-3.6.10-vs2.3.4.5/include/linux/vserver/cvirt.h        2012-10-04 18:47:00.000000000 +0200
11437 @@ -0,0 +1,22 @@
11438 +#ifndef _VX_CVIRT_H
11439 +#define _VX_CVIRT_H
11440 +
11441 +
11442 +#ifdef __KERNEL__
11443 +
11444 +struct timespec;
11445 +
11446 +void vx_vsi_boottime(struct timespec *);
11447 +
11448 +void vx_vsi_uptime(struct timespec *, struct timespec *);
11449 +
11450 +
11451 +struct vx_info;
11452 +
11453 +void vx_update_load(struct vx_info *);
11454 +
11455 +
11456 +int vx_do_syslog(int, char __user *, int);
11457 +
11458 +#endif /* __KERNEL__ */
11459 +#endif /* _VX_CVIRT_H */
11460 diff -NurpP --minimal linux-3.6.10/include/linux/vserver/cvirt_cmd.h linux-3.6.10-vs2.3.4.5/include/linux/vserver/cvirt_cmd.h
11461 --- linux-3.6.10/include/linux/vserver/cvirt_cmd.h      1970-01-01 01:00:00.000000000 +0100
11462 +++ linux-3.6.10-vs2.3.4.5/include/linux/vserver/cvirt_cmd.h    2012-10-04 18:47:00.000000000 +0200
11463 @@ -0,0 +1,53 @@
11464 +#ifndef _VX_CVIRT_CMD_H
11465 +#define _VX_CVIRT_CMD_H
11466 +
11467 +
11468 +/* virtual host info name commands */
11469 +
11470 +#define VCMD_set_vhi_name      VC_CMD(VHOST, 1, 0)
11471 +#define VCMD_get_vhi_name      VC_CMD(VHOST, 2, 0)
11472 +
11473 +struct vcmd_vhi_name_v0 {
11474 +       uint32_t field;
11475 +       char name[65];
11476 +};
11477 +
11478 +
11479 +enum vhi_name_field {
11480 +       VHIN_CONTEXT = 0,
11481 +       VHIN_SYSNAME,
11482 +       VHIN_NODENAME,
11483 +       VHIN_RELEASE,
11484 +       VHIN_VERSION,
11485 +       VHIN_MACHINE,
11486 +       VHIN_DOMAINNAME,
11487 +};
11488 +
11489 +
11490 +#ifdef __KERNEL__
11491 +
11492 +#include <linux/compiler.h>
11493 +
11494 +extern int vc_set_vhi_name(struct vx_info *, void __user *);
11495 +extern int vc_get_vhi_name(struct vx_info *, void __user *);
11496 +
11497 +#endif /* __KERNEL__ */
11498 +
11499 +#define VCMD_virt_stat         VC_CMD(VSTAT, 3, 0)
11500 +
11501 +struct vcmd_virt_stat_v0 {
11502 +       uint64_t offset;
11503 +       uint64_t uptime;
11504 +       uint32_t nr_threads;
11505 +       uint32_t nr_running;
11506 +       uint32_t nr_uninterruptible;
11507 +       uint32_t nr_onhold;
11508 +       uint32_t nr_forks;
11509 +       uint32_t load[3];
11510 +};
11511 +
11512 +#ifdef __KERNEL__
11513 +extern int vc_virt_stat(struct vx_info *, void __user *);
11514 +
11515 +#endif /* __KERNEL__ */
11516 +#endif /* _VX_CVIRT_CMD_H */
11517 diff -NurpP --minimal linux-3.6.10/include/linux/vserver/cvirt_def.h linux-3.6.10-vs2.3.4.5/include/linux/vserver/cvirt_def.h
11518 --- linux-3.6.10/include/linux/vserver/cvirt_def.h      1970-01-01 01:00:00.000000000 +0100
11519 +++ linux-3.6.10-vs2.3.4.5/include/linux/vserver/cvirt_def.h    2012-10-04 18:47:00.000000000 +0200
11520 @@ -0,0 +1,80 @@
11521 +#ifndef _VX_CVIRT_DEF_H
11522 +#define _VX_CVIRT_DEF_H
11523 +
11524 +#include <linux/jiffies.h>
11525 +#include <linux/spinlock.h>
11526 +#include <linux/wait.h>
11527 +#include <linux/time.h>
11528 +#include <asm/atomic.h>
11529 +
11530 +
11531 +struct _vx_usage_stat {
11532 +       uint64_t user;
11533 +       uint64_t nice;
11534 +       uint64_t system;
11535 +       uint64_t softirq;
11536 +       uint64_t irq;
11537 +       uint64_t idle;
11538 +       uint64_t iowait;
11539 +};
11540 +
11541 +struct _vx_syslog {
11542 +       wait_queue_head_t log_wait;
11543 +       spinlock_t logbuf_lock;         /* lock for the log buffer */
11544 +
11545 +       unsigned long log_start;        /* next char to be read by syslog() */
11546 +       unsigned long con_start;        /* next char to be sent to consoles */
11547 +       unsigned long log_end;  /* most-recently-written-char + 1 */
11548 +       unsigned long logged_chars;     /* #chars since last read+clear operation */
11549 +
11550 +       char log_buf[1024];
11551 +};
11552 +
11553 +
11554 +/* context sub struct */
11555 +
11556 +struct _vx_cvirt {
11557 +       atomic_t nr_threads;            /* number of current threads */
11558 +       atomic_t nr_running;            /* number of running threads */
11559 +       atomic_t nr_uninterruptible;    /* number of uninterruptible threads */
11560 +
11561 +       atomic_t nr_onhold;             /* processes on hold */
11562 +       uint32_t onhold_last;           /* jiffies when put on hold */
11563 +
11564 +       struct timespec bias_ts;        /* time offset to the host */
11565 +       struct timespec bias_idle;
11566 +       struct timespec bias_uptime;    /* context creation point */
11567 +       uint64_t bias_clock;            /* offset in clock_t */
11568 +
11569 +       spinlock_t load_lock;           /* lock for the load averages */
11570 +       atomic_t load_updates;          /* nr of load updates done so far */
11571 +       uint32_t load_last;             /* last time load was calculated */
11572 +       uint32_t load[3];               /* load averages 1,5,15 */
11573 +
11574 +       atomic_t total_forks;           /* number of forks so far */
11575 +
11576 +       struct _vx_syslog syslog;
11577 +};
11578 +
11579 +struct _vx_cvirt_pc {
11580 +       struct _vx_usage_stat cpustat;
11581 +};
11582 +
11583 +
11584 +#ifdef CONFIG_VSERVER_DEBUG
11585 +
11586 +static inline void __dump_vx_cvirt(struct _vx_cvirt *cvirt)
11587 +{
11588 +       printk("\t_vx_cvirt:\n");
11589 +       printk("\t threads: %4d, %4d, %4d, %4d\n",
11590 +               atomic_read(&cvirt->nr_threads),
11591 +               atomic_read(&cvirt->nr_running),
11592 +               atomic_read(&cvirt->nr_uninterruptible),
11593 +               atomic_read(&cvirt->nr_onhold));
11594 +       /* add rest here */
11595 +       printk("\t total_forks = %d\n", atomic_read(&cvirt->total_forks));
11596 +}
11597 +
11598 +#endif
11599 +
11600 +#endif /* _VX_CVIRT_DEF_H */
11601 diff -NurpP --minimal linux-3.6.10/include/linux/vserver/debug.h linux-3.6.10-vs2.3.4.5/include/linux/vserver/debug.h
11602 --- linux-3.6.10/include/linux/vserver/debug.h  1970-01-01 01:00:00.000000000 +0100
11603 +++ linux-3.6.10-vs2.3.4.5/include/linux/vserver/debug.h        2012-10-04 18:47:00.000000000 +0200
11604 @@ -0,0 +1,145 @@
11605 +#ifndef _VX_DEBUG_H
11606 +#define _VX_DEBUG_H
11607 +
11608 +
11609 +#define VXD_CBIT(n, m) (vs_debug_ ## n & (1 << (m)))
11610 +#define VXD_CMIN(n, m) (vs_debug_ ## n > (m))
11611 +#define VXD_MASK(n, m) (vs_debug_ ## n & (m))
11612 +
11613 +#define VXD_DEV(d)     (d), (d)->bd_inode->i_ino,              \
11614 +                       imajor((d)->bd_inode), iminor((d)->bd_inode)
11615 +#define VXF_DEV                "%p[%lu,%d:%d]"
11616 +
11617 +#if    defined(CONFIG_QUOTES_UTF8)
11618 +#define        VS_Q_LQM        "\xc2\xbb"
11619 +#define        VS_Q_RQM        "\xc2\xab"
11620 +#elif  defined(CONFIG_QUOTES_ASCII)
11621 +#define        VS_Q_LQM        "\x27"
11622 +#define        VS_Q_RQM        "\x27"
11623 +#else
11624 +#define        VS_Q_LQM        "\xbb"
11625 +#define        VS_Q_RQM        "\xab"
11626 +#endif
11627 +
11628 +#define        VS_Q(f)         VS_Q_LQM f VS_Q_RQM
11629 +
11630 +
11631 +#define vxd_path(p)                                            \
11632 +       ({ static char _buffer[PATH_MAX];                       \
11633 +          d_path(p, _buffer, sizeof(_buffer)); })
11634 +
11635 +#define vxd_cond_path(n)                                       \
11636 +       ((n) ? vxd_path(&(n)->path) : "<null>" )
11637 +
11638 +
11639 +#ifdef CONFIG_VSERVER_DEBUG
11640 +
11641 +extern unsigned int vs_debug_switch;
11642 +extern unsigned int vs_debug_xid;
11643 +extern unsigned int vs_debug_nid;
11644 +extern unsigned int vs_debug_tag;
11645 +extern unsigned int vs_debug_net;
11646 +extern unsigned int vs_debug_limit;
11647 +extern unsigned int vs_debug_cres;
11648 +extern unsigned int vs_debug_dlim;
11649 +extern unsigned int vs_debug_quota;
11650 +extern unsigned int vs_debug_cvirt;
11651 +extern unsigned int vs_debug_space;
11652 +extern unsigned int vs_debug_perm;
11653 +extern unsigned int vs_debug_misc;
11654 +
11655 +
11656 +#define VX_LOGLEVEL    "vxD: "
11657 +#define VX_PROC_FMT    "%p: "
11658 +#define VX_PROCESS     current
11659 +
11660 +#define vxdprintk(c, f, x...)                                  \
11661 +       do {                                                    \
11662 +               if (c)                                          \
11663 +                       printk(VX_LOGLEVEL VX_PROC_FMT f "\n",  \
11664 +                               VX_PROCESS , ##x);              \
11665 +       } while (0)
11666 +
11667 +#define vxlprintk(c, f, x...)                                  \
11668 +       do {                                                    \
11669 +               if (c)                                          \
11670 +                       printk(VX_LOGLEVEL f " @%s:%d\n", x);   \
11671 +       } while (0)
11672 +
11673 +#define vxfprintk(c, f, x...)                                  \
11674 +       do {                                                    \
11675 +               if (c)                                          \
11676 +                       printk(VX_LOGLEVEL f " %s@%s:%d\n", x); \
11677 +       } while (0)
11678 +
11679 +
11680 +struct vx_info;
11681 +
11682 +void dump_vx_info(struct vx_info *, int);
11683 +void dump_vx_info_inactive(int);
11684 +
11685 +#else  /* CONFIG_VSERVER_DEBUG */
11686 +
11687 +#define vs_debug_switch        0
11688 +#define vs_debug_xid   0
11689 +#define vs_debug_nid   0
11690 +#define vs_debug_tag   0
11691 +#define vs_debug_net   0
11692 +#define vs_debug_limit 0
11693 +#define vs_debug_cres  0
11694 +#define vs_debug_dlim  0
11695 +#define vs_debug_quota 0
11696 +#define vs_debug_cvirt 0
11697 +#define vs_debug_space 0
11698 +#define vs_debug_perm  0
11699 +#define vs_debug_misc  0
11700 +
11701 +#define vxdprintk(x...) do { } while (0)
11702 +#define vxlprintk(x...) do { } while (0)
11703 +#define vxfprintk(x...) do { } while (0)
11704 +
11705 +#endif /* CONFIG_VSERVER_DEBUG */
11706 +
11707 +
11708 +#ifdef CONFIG_VSERVER_WARN
11709 +
11710 +#define VX_WARNLEVEL   KERN_WARNING "vxW: "
11711 +#define VX_WARN_TASK   "[" VS_Q("%s") ",%u:#%u|%u|%u] "
11712 +#define VX_WARN_XID    "[xid #%u] "
11713 +#define VX_WARN_NID    "[nid #%u] "
11714 +#define VX_WARN_TAG    "[tag #%u] "
11715 +
11716 +#define vxwprintk(c, f, x...)                                  \
11717 +       do {                                                    \
11718 +               if (c)                                          \
11719 +                       printk(VX_WARNLEVEL f "\n", ##x);       \
11720 +       } while (0)
11721 +
11722 +#else  /* CONFIG_VSERVER_WARN */
11723 +
11724 +#define vxwprintk(x...) do { } while (0)
11725 +
11726 +#endif /* CONFIG_VSERVER_WARN */
11727 +
11728 +#define vxwprintk_task(c, f, x...)                             \
11729 +       vxwprintk(c, VX_WARN_TASK f,                            \
11730 +               current->comm, current->pid,                    \
11731 +               current->xid, current->nid, current->tag, ##x)
11732 +#define vxwprintk_xid(c, f, x...)                              \
11733 +       vxwprintk(c, VX_WARN_XID f, current->xid, x)
11734 +#define vxwprintk_nid(c, f, x...)                              \
11735 +       vxwprintk(c, VX_WARN_NID f, current->nid, x)
11736 +#define vxwprintk_tag(c, f, x...)                              \
11737 +       vxwprintk(c, VX_WARN_TAG f, current->tag, x)
11738 +
11739 +#ifdef CONFIG_VSERVER_DEBUG
11740 +#define vxd_assert_lock(l)     assert_spin_locked(l)
11741 +#define vxd_assert(c, f, x...) vxlprintk(!(c), \
11742 +       "assertion [" f "] failed.", ##x, __FILE__, __LINE__)
11743 +#else
11744 +#define vxd_assert_lock(l)     do { } while (0)
11745 +#define vxd_assert(c, f, x...) do { } while (0)
11746 +#endif
11747 +
11748 +
11749 +#endif /* _VX_DEBUG_H */
11750 diff -NurpP --minimal linux-3.6.10/include/linux/vserver/debug_cmd.h linux-3.6.10-vs2.3.4.5/include/linux/vserver/debug_cmd.h
11751 --- linux-3.6.10/include/linux/vserver/debug_cmd.h      1970-01-01 01:00:00.000000000 +0100
11752 +++ linux-3.6.10-vs2.3.4.5/include/linux/vserver/debug_cmd.h    2012-10-04 18:47:00.000000000 +0200
11753 @@ -0,0 +1,58 @@
11754 +#ifndef _VX_DEBUG_CMD_H
11755 +#define _VX_DEBUG_CMD_H
11756 +
11757 +
11758 +/* debug commands */
11759 +
11760 +#define VCMD_dump_history      VC_CMD(DEBUG, 1, 0)
11761 +
11762 +#define VCMD_read_history      VC_CMD(DEBUG, 5, 0)
11763 +#define VCMD_read_monitor      VC_CMD(DEBUG, 6, 0)
11764 +
11765 +struct  vcmd_read_history_v0 {
11766 +       uint32_t index;
11767 +       uint32_t count;
11768 +       char __user *data;
11769 +};
11770 +
11771 +struct  vcmd_read_monitor_v0 {
11772 +       uint32_t index;
11773 +       uint32_t count;
11774 +       char __user *data;
11775 +};
11776 +
11777 +
11778 +#ifdef __KERNEL__
11779 +
11780 +#ifdef CONFIG_COMPAT
11781 +
11782 +#include <asm/compat.h>
11783 +
11784 +struct vcmd_read_history_v0_x32 {
11785 +       uint32_t index;
11786 +       uint32_t count;
11787 +       compat_uptr_t data_ptr;
11788 +};
11789 +
11790 +struct vcmd_read_monitor_v0_x32 {
11791 +       uint32_t index;
11792 +       uint32_t count;
11793 +       compat_uptr_t data_ptr;
11794 +};
11795 +
11796 +#endif  /* CONFIG_COMPAT */
11797 +
11798 +extern int vc_dump_history(uint32_t);
11799 +
11800 +extern int vc_read_history(uint32_t, void __user *);
11801 +extern int vc_read_monitor(uint32_t, void __user *);
11802 +
11803 +#ifdef CONFIG_COMPAT
11804 +
11805 +extern int vc_read_history_x32(uint32_t, void __user *);
11806 +extern int vc_read_monitor_x32(uint32_t, void __user *);
11807 +
11808 +#endif  /* CONFIG_COMPAT */
11809 +
11810 +#endif /* __KERNEL__ */
11811 +#endif /* _VX_DEBUG_CMD_H */
11812 diff -NurpP --minimal linux-3.6.10/include/linux/vserver/device.h linux-3.6.10-vs2.3.4.5/include/linux/vserver/device.h
11813 --- linux-3.6.10/include/linux/vserver/device.h 1970-01-01 01:00:00.000000000 +0100
11814 +++ linux-3.6.10-vs2.3.4.5/include/linux/vserver/device.h       2012-10-04 18:47:00.000000000 +0200
11815 @@ -0,0 +1,15 @@
11816 +#ifndef _VX_DEVICE_H
11817 +#define _VX_DEVICE_H
11818 +
11819 +
11820 +#define DATTR_CREATE   0x00000001
11821 +#define DATTR_OPEN     0x00000002
11822 +
11823 +#define DATTR_REMAP    0x00000010
11824 +
11825 +#define DATTR_MASK     0x00000013
11826 +
11827 +
11828 +#else  /* _VX_DEVICE_H */
11829 +#warning duplicate inclusion
11830 +#endif /* _VX_DEVICE_H */
11831 diff -NurpP --minimal linux-3.6.10/include/linux/vserver/device_cmd.h linux-3.6.10-vs2.3.4.5/include/linux/vserver/device_cmd.h
11832 --- linux-3.6.10/include/linux/vserver/device_cmd.h     1970-01-01 01:00:00.000000000 +0100
11833 +++ linux-3.6.10-vs2.3.4.5/include/linux/vserver/device_cmd.h   2012-10-04 18:47:00.000000000 +0200
11834 @@ -0,0 +1,44 @@
11835 +#ifndef _VX_DEVICE_CMD_H
11836 +#define _VX_DEVICE_CMD_H
11837 +
11838 +
11839 +/*  device vserver commands */
11840 +
11841 +#define VCMD_set_mapping       VC_CMD(DEVICE, 1, 0)
11842 +#define VCMD_unset_mapping     VC_CMD(DEVICE, 2, 0)
11843 +
11844 +struct vcmd_set_mapping_v0 {
11845 +       const char __user *device;
11846 +       const char __user *target;
11847 +       uint32_t flags;
11848 +};
11849 +
11850 +
11851 +#ifdef __KERNEL__
11852 +
11853 +#ifdef CONFIG_COMPAT
11854 +
11855 +#include <asm/compat.h>
11856 +
11857 +struct vcmd_set_mapping_v0_x32 {
11858 +       compat_uptr_t device_ptr;
11859 +       compat_uptr_t target_ptr;
11860 +       uint32_t flags;
11861 +};
11862 +
11863 +#endif /* CONFIG_COMPAT */
11864 +
11865 +#include <linux/compiler.h>
11866 +
11867 +extern int vc_set_mapping(struct vx_info *, void __user *);
11868 +extern int vc_unset_mapping(struct vx_info *, void __user *);
11869 +
11870 +#ifdef CONFIG_COMPAT
11871 +
11872 +extern int vc_set_mapping_x32(struct vx_info *, void __user *);
11873 +extern int vc_unset_mapping_x32(struct vx_info *, void __user *);
11874 +
11875 +#endif /* CONFIG_COMPAT */
11876 +
11877 +#endif /* __KERNEL__ */
11878 +#endif /* _VX_DEVICE_CMD_H */
11879 diff -NurpP --minimal linux-3.6.10/include/linux/vserver/device_def.h linux-3.6.10-vs2.3.4.5/include/linux/vserver/device_def.h
11880 --- linux-3.6.10/include/linux/vserver/device_def.h     1970-01-01 01:00:00.000000000 +0100
11881 +++ linux-3.6.10-vs2.3.4.5/include/linux/vserver/device_def.h   2012-10-04 18:47:00.000000000 +0200
11882 @@ -0,0 +1,17 @@
11883 +#ifndef _VX_DEVICE_DEF_H
11884 +#define _VX_DEVICE_DEF_H
11885 +
11886 +#include <linux/types.h>
11887 +
11888 +struct vx_dmap_target {
11889 +       dev_t target;
11890 +       uint32_t flags;
11891 +};
11892 +
11893 +struct _vx_device {
11894 +#ifdef CONFIG_VSERVER_DEVICE
11895 +       struct vx_dmap_target targets[2];
11896 +#endif
11897 +};
11898 +
11899 +#endif /* _VX_DEVICE_DEF_H */
11900 diff -NurpP --minimal linux-3.6.10/include/linux/vserver/dlimit.h linux-3.6.10-vs2.3.4.5/include/linux/vserver/dlimit.h
11901 --- linux-3.6.10/include/linux/vserver/dlimit.h 1970-01-01 01:00:00.000000000 +0100
11902 +++ linux-3.6.10-vs2.3.4.5/include/linux/vserver/dlimit.h       2012-10-04 18:47:00.000000000 +0200
11903 @@ -0,0 +1,54 @@
11904 +#ifndef _VX_DLIMIT_H
11905 +#define _VX_DLIMIT_H
11906 +
11907 +#include "switch.h"
11908 +
11909 +
11910 +#ifdef __KERNEL__
11911 +
11912 +/*      keep in sync with CDLIM_INFINITY       */
11913 +
11914 +#define DLIM_INFINITY          (~0ULL)
11915 +
11916 +#include <linux/spinlock.h>
11917 +#include <linux/rcupdate.h>
11918 +
11919 +struct super_block;
11920 +
11921 +struct dl_info {
11922 +       struct hlist_node dl_hlist;             /* linked list of contexts */
11923 +       struct rcu_head dl_rcu;                 /* the rcu head */
11924 +       tag_t dl_tag;                           /* context tag */
11925 +       atomic_t dl_usecnt;                     /* usage count */
11926 +       atomic_t dl_refcnt;                     /* reference count */
11927 +
11928 +       struct super_block *dl_sb;              /* associated superblock */
11929 +
11930 +       spinlock_t dl_lock;                     /* protect the values */
11931 +
11932 +       unsigned long long dl_space_used;       /* used space in bytes */
11933 +       unsigned long long dl_space_total;      /* maximum space in bytes */
11934 +       unsigned long dl_inodes_used;           /* used inodes */
11935 +       unsigned long dl_inodes_total;          /* maximum inodes */
11936 +
11937 +       unsigned int dl_nrlmult;                /* non root limit mult */
11938 +};
11939 +
11940 +struct rcu_head;
11941 +
11942 +extern void rcu_free_dl_info(struct rcu_head *);
11943 +extern void unhash_dl_info(struct dl_info *);
11944 +
11945 +extern struct dl_info *locate_dl_info(struct super_block *, tag_t);
11946 +
11947 +
11948 +struct kstatfs;
11949 +
11950 +extern void vx_vsi_statfs(struct super_block *, struct kstatfs *);
11951 +
11952 +typedef uint64_t dlsize_t;
11953 +
11954 +#endif /* __KERNEL__ */
11955 +#else  /* _VX_DLIMIT_H */
11956 +#warning duplicate inclusion
11957 +#endif /* _VX_DLIMIT_H */
11958 diff -NurpP --minimal linux-3.6.10/include/linux/vserver/dlimit_cmd.h linux-3.6.10-vs2.3.4.5/include/linux/vserver/dlimit_cmd.h
11959 --- linux-3.6.10/include/linux/vserver/dlimit_cmd.h     1970-01-01 01:00:00.000000000 +0100
11960 +++ linux-3.6.10-vs2.3.4.5/include/linux/vserver/dlimit_cmd.h   2012-10-04 18:47:00.000000000 +0200
11961 @@ -0,0 +1,109 @@
11962 +#ifndef _VX_DLIMIT_CMD_H
11963 +#define _VX_DLIMIT_CMD_H
11964 +
11965 +
11966 +/*  dlimit vserver commands */
11967 +
11968 +#define VCMD_add_dlimit                VC_CMD(DLIMIT, 1, 0)
11969 +#define VCMD_rem_dlimit                VC_CMD(DLIMIT, 2, 0)
11970 +
11971 +#define VCMD_set_dlimit                VC_CMD(DLIMIT, 5, 0)
11972 +#define VCMD_get_dlimit                VC_CMD(DLIMIT, 6, 0)
11973 +
11974 +struct vcmd_ctx_dlimit_base_v0 {
11975 +       const char __user *name;
11976 +       uint32_t flags;
11977 +};
11978 +
11979 +struct vcmd_ctx_dlimit_v0 {
11980 +       const char __user *name;
11981 +       uint32_t space_used;                    /* used space in kbytes */
11982 +       uint32_t space_total;                   /* maximum space in kbytes */
11983 +       uint32_t inodes_used;                   /* used inodes */
11984 +       uint32_t inodes_total;                  /* maximum inodes */
11985 +       uint32_t reserved;                      /* reserved for root in % */
11986 +       uint32_t flags;
11987 +};
11988 +
11989 +#define CDLIM_UNSET            ((uint32_t)0UL)
11990 +#define CDLIM_INFINITY         ((uint32_t)~0UL)
11991 +#define CDLIM_KEEP             ((uint32_t)~1UL)
11992 +
11993 +#define DLIME_UNIT     0
11994 +#define DLIME_KILO     1
11995 +#define DLIME_MEGA     2
11996 +#define DLIME_GIGA     3
11997 +
11998 +#define DLIMF_SHIFT    0x10
11999 +
12000 +#define DLIMS_USED     0
12001 +#define DLIMS_TOTAL    2
12002 +
12003 +static inline
12004 +uint64_t dlimit_space_32to64(uint32_t val, uint32_t flags, int shift)
12005 +{
12006 +       int exp = (flags & DLIMF_SHIFT) ?
12007 +               (flags >> shift) & DLIME_GIGA : DLIME_KILO;
12008 +       return ((uint64_t)val) << (10 * exp);
12009 +}
12010 +
12011 +static inline
12012 +uint32_t dlimit_space_64to32(uint64_t val, uint32_t *flags, int shift)
12013 +{
12014 +       int exp = 0;
12015 +
12016 +       if (*flags & DLIMF_SHIFT) {
12017 +               while (val > (1LL << 32) && (exp < 3)) {
12018 +                       val >>= 10;
12019 +                       exp++;
12020 +               }
12021 +               *flags &= ~(DLIME_GIGA << shift);
12022 +               *flags |= exp << shift;
12023 +       } else
12024 +               val >>= 10;
12025 +       return val;
12026 +}
12027 +
12028 +#ifdef __KERNEL__
12029 +
12030 +#ifdef CONFIG_COMPAT
12031 +
12032 +#include <asm/compat.h>
12033 +
12034 +struct vcmd_ctx_dlimit_base_v0_x32 {
12035 +       compat_uptr_t name_ptr;
12036 +       uint32_t flags;
12037 +};
12038 +
12039 +struct vcmd_ctx_dlimit_v0_x32 {
12040 +       compat_uptr_t name_ptr;
12041 +       uint32_t space_used;                    /* used space in kbytes */
12042 +       uint32_t space_total;                   /* maximum space in kbytes */
12043 +       uint32_t inodes_used;                   /* used inodes */
12044 +       uint32_t inodes_total;                  /* maximum inodes */
12045 +       uint32_t reserved;                      /* reserved for root in % */
12046 +       uint32_t flags;
12047 +};
12048 +
12049 +#endif /* CONFIG_COMPAT */
12050 +
12051 +#include <linux/compiler.h>
12052 +
12053 +extern int vc_add_dlimit(uint32_t, void __user *);
12054 +extern int vc_rem_dlimit(uint32_t, void __user *);
12055 +
12056 +extern int vc_set_dlimit(uint32_t, void __user *);
12057 +extern int vc_get_dlimit(uint32_t, void __user *);
12058 +
12059 +#ifdef CONFIG_COMPAT
12060 +
12061 +extern int vc_add_dlimit_x32(uint32_t, void __user *);
12062 +extern int vc_rem_dlimit_x32(uint32_t, void __user *);
12063 +
12064 +extern int vc_set_dlimit_x32(uint32_t, void __user *);
12065 +extern int vc_get_dlimit_x32(uint32_t, void __user *);
12066 +
12067 +#endif /* CONFIG_COMPAT */
12068 +
12069 +#endif /* __KERNEL__ */
12070 +#endif /* _VX_DLIMIT_CMD_H */
12071 diff -NurpP --minimal linux-3.6.10/include/linux/vserver/global.h linux-3.6.10-vs2.3.4.5/include/linux/vserver/global.h
12072 --- linux-3.6.10/include/linux/vserver/global.h 1970-01-01 01:00:00.000000000 +0100
12073 +++ linux-3.6.10-vs2.3.4.5/include/linux/vserver/global.h       2012-10-04 18:47:00.000000000 +0200
12074 @@ -0,0 +1,19 @@
12075 +#ifndef _VX_GLOBAL_H
12076 +#define _VX_GLOBAL_H
12077 +
12078 +
12079 +extern atomic_t vx_global_ctotal;
12080 +extern atomic_t vx_global_cactive;
12081 +
12082 +extern atomic_t nx_global_ctotal;
12083 +extern atomic_t nx_global_cactive;
12084 +
12085 +extern atomic_t vs_global_nsproxy;
12086 +extern atomic_t vs_global_fs;
12087 +extern atomic_t vs_global_mnt_ns;
12088 +extern atomic_t vs_global_uts_ns;
12089 +extern atomic_t vs_global_user_ns;
12090 +extern atomic_t vs_global_pid_ns;
12091 +
12092 +
12093 +#endif /* _VX_GLOBAL_H */
12094 diff -NurpP --minimal linux-3.6.10/include/linux/vserver/history.h linux-3.6.10-vs2.3.4.5/include/linux/vserver/history.h
12095 --- linux-3.6.10/include/linux/vserver/history.h        1970-01-01 01:00:00.000000000 +0100
12096 +++ linux-3.6.10-vs2.3.4.5/include/linux/vserver/history.h      2012-10-04 18:47:00.000000000 +0200
12097 @@ -0,0 +1,197 @@
12098 +#ifndef _VX_HISTORY_H
12099 +#define _VX_HISTORY_H
12100 +
12101 +
12102 +enum {
12103 +       VXH_UNUSED = 0,
12104 +       VXH_THROW_OOPS = 1,
12105 +
12106 +       VXH_GET_VX_INFO,
12107 +       VXH_PUT_VX_INFO,
12108 +       VXH_INIT_VX_INFO,
12109 +       VXH_SET_VX_INFO,
12110 +       VXH_CLR_VX_INFO,
12111 +       VXH_CLAIM_VX_INFO,
12112 +       VXH_RELEASE_VX_INFO,
12113 +       VXH_ALLOC_VX_INFO,
12114 +       VXH_DEALLOC_VX_INFO,
12115 +       VXH_HASH_VX_INFO,
12116 +       VXH_UNHASH_VX_INFO,
12117 +       VXH_LOC_VX_INFO,
12118 +       VXH_LOOKUP_VX_INFO,
12119 +       VXH_CREATE_VX_INFO,
12120 +};
12121 +
12122 +struct _vxhe_vxi {
12123 +       struct vx_info *ptr;
12124 +       unsigned xid;
12125 +       unsigned usecnt;
12126 +       unsigned tasks;
12127 +};
12128 +
12129 +struct _vxhe_set_clr {
12130 +       void *data;
12131 +};
12132 +
12133 +struct _vxhe_loc_lookup {
12134 +       unsigned arg;
12135 +};
12136 +
12137 +struct _vx_hist_entry {
12138 +       void *loc;
12139 +       unsigned short seq;
12140 +       unsigned short type;
12141 +       struct _vxhe_vxi vxi;
12142 +       union {
12143 +               struct _vxhe_set_clr sc;
12144 +               struct _vxhe_loc_lookup ll;
12145 +       };
12146 +};
12147 +
12148 +#ifdef CONFIG_VSERVER_HISTORY
12149 +
12150 +extern unsigned volatile int vxh_active;
12151 +
12152 +struct _vx_hist_entry *vxh_advance(void *loc);
12153 +
12154 +
12155 +static inline
12156 +void   __vxh_copy_vxi(struct _vx_hist_entry *entry, struct vx_info *vxi)
12157 +{
12158 +       entry->vxi.ptr = vxi;
12159 +       if (vxi) {
12160 +               entry->vxi.usecnt = atomic_read(&vxi->vx_usecnt);
12161 +               entry->vxi.tasks = atomic_read(&vxi->vx_tasks);
12162 +               entry->vxi.xid = vxi->vx_id;
12163 +       }
12164 +}
12165 +
12166 +
12167 +#define        __HERE__ current_text_addr()
12168 +
12169 +#define __VXH_BODY(__type, __data, __here)     \
12170 +       struct _vx_hist_entry *entry;           \
12171 +                                               \
12172 +       preempt_disable();                      \
12173 +       entry = vxh_advance(__here);            \
12174 +       __data;                                 \
12175 +       entry->type = __type;                   \
12176 +       preempt_enable();
12177 +
12178 +
12179 +       /* pass vxi only */
12180 +
12181 +#define __VXH_SMPL                             \
12182 +       __vxh_copy_vxi(entry, vxi)
12183 +
12184 +static inline
12185 +void   __vxh_smpl(struct vx_info *vxi, int __type, void *__here)
12186 +{
12187 +       __VXH_BODY(__type, __VXH_SMPL, __here)
12188 +}
12189 +
12190 +       /* pass vxi and data (void *) */
12191 +
12192 +#define __VXH_DATA                             \
12193 +       __vxh_copy_vxi(entry, vxi);             \
12194 +       entry->sc.data = data
12195 +
12196 +static inline
12197 +void   __vxh_data(struct vx_info *vxi, void *data,
12198 +                       int __type, void *__here)
12199 +{
12200 +       __VXH_BODY(__type, __VXH_DATA, __here)
12201 +}
12202 +
12203 +       /* pass vxi and arg (long) */
12204 +
12205 +#define __VXH_LONG                             \
12206 +       __vxh_copy_vxi(entry, vxi);             \
12207 +       entry->ll.arg = arg
12208 +
12209 +static inline
12210 +void   __vxh_long(struct vx_info *vxi, long arg,
12211 +                       int __type, void *__here)
12212 +{
12213 +       __VXH_BODY(__type, __VXH_LONG, __here)
12214 +}
12215 +
12216 +
12217 +static inline
12218 +void   __vxh_throw_oops(void *__here)
12219 +{
12220 +       __VXH_BODY(VXH_THROW_OOPS, {}, __here);
12221 +       /* prevent further acquisition */
12222 +       vxh_active = 0;
12223 +}
12224 +
12225 +
12226 +#define vxh_throw_oops()       __vxh_throw_oops(__HERE__);
12227 +
12228 +#define __vxh_get_vx_info(v, h)        __vxh_smpl(v, VXH_GET_VX_INFO, h);
12229 +#define __vxh_put_vx_info(v, h)        __vxh_smpl(v, VXH_PUT_VX_INFO, h);
12230 +
12231 +#define __vxh_init_vx_info(v, d, h) \
12232 +       __vxh_data(v, d, VXH_INIT_VX_INFO, h);
12233 +#define __vxh_set_vx_info(v, d, h) \
12234 +       __vxh_data(v, d, VXH_SET_VX_INFO, h);
12235 +#define __vxh_clr_vx_info(v, d, h) \
12236 +       __vxh_data(v, d, VXH_CLR_VX_INFO, h);
12237 +
12238 +#define __vxh_claim_vx_info(v, d, h) \
12239 +       __vxh_data(v, d, VXH_CLAIM_VX_INFO, h);
12240 +#define __vxh_release_vx_info(v, d, h) \
12241 +       __vxh_data(v, d, VXH_RELEASE_VX_INFO, h);
12242 +
12243 +#define vxh_alloc_vx_info(v) \
12244 +       __vxh_smpl(v, VXH_ALLOC_VX_INFO, __HERE__);
12245 +#define vxh_dealloc_vx_info(v) \
12246 +       __vxh_smpl(v, VXH_DEALLOC_VX_INFO, __HERE__);
12247 +
12248 +#define vxh_hash_vx_info(v) \
12249 +       __vxh_smpl(v, VXH_HASH_VX_INFO, __HERE__);
12250 +#define vxh_unhash_vx_info(v) \
12251 +       __vxh_smpl(v, VXH_UNHASH_VX_INFO, __HERE__);
12252 +
12253 +#define vxh_loc_vx_info(v, l) \
12254 +       __vxh_long(v, l, VXH_LOC_VX_INFO, __HERE__);
12255 +#define vxh_lookup_vx_info(v, l) \
12256 +       __vxh_long(v, l, VXH_LOOKUP_VX_INFO, __HERE__);
12257 +#define vxh_create_vx_info(v, l) \
12258 +       __vxh_long(v, l, VXH_CREATE_VX_INFO, __HERE__);
12259 +
12260 +extern void vxh_dump_history(void);
12261 +
12262 +
12263 +#else  /* CONFIG_VSERVER_HISTORY */
12264 +
12265 +#define        __HERE__        0
12266 +
12267 +#define vxh_throw_oops()               do { } while (0)
12268 +
12269 +#define __vxh_get_vx_info(v, h)                do { } while (0)
12270 +#define __vxh_put_vx_info(v, h)                do { } while (0)
12271 +
12272 +#define __vxh_init_vx_info(v, d, h)    do { } while (0)
12273 +#define __vxh_set_vx_info(v, d, h)     do { } while (0)
12274 +#define __vxh_clr_vx_info(v, d, h)     do { } while (0)
12275 +
12276 +#define __vxh_claim_vx_info(v, d, h)   do { } while (0)
12277 +#define __vxh_release_vx_info(v, d, h) do { } while (0)
12278 +
12279 +#define vxh_alloc_vx_info(v)           do { } while (0)
12280 +#define vxh_dealloc_vx_info(v)         do { } while (0)
12281 +
12282 +#define vxh_hash_vx_info(v)            do { } while (0)
12283 +#define vxh_unhash_vx_info(v)          do { } while (0)
12284 +
12285 +#define vxh_loc_vx_info(v, l)          do { } while (0)
12286 +#define vxh_lookup_vx_info(v, l)       do { } while (0)
12287 +#define vxh_create_vx_info(v, l)       do { } while (0)
12288 +
12289 +#define vxh_dump_history()             do { } while (0)
12290 +
12291 +
12292 +#endif /* CONFIG_VSERVER_HISTORY */
12293 +
12294 +#endif /* _VX_HISTORY_H */
12295 diff -NurpP --minimal linux-3.6.10/include/linux/vserver/inode.h linux-3.6.10-vs2.3.4.5/include/linux/vserver/inode.h
12296 --- linux-3.6.10/include/linux/vserver/inode.h  1970-01-01 01:00:00.000000000 +0100
12297 +++ linux-3.6.10-vs2.3.4.5/include/linux/vserver/inode.h        2012-10-04 18:47:00.000000000 +0200
12298 @@ -0,0 +1,39 @@
12299 +#ifndef _VX_INODE_H
12300 +#define _VX_INODE_H
12301 +
12302 +
12303 +#define IATTR_TAG      0x01000000
12304 +
12305 +#define IATTR_ADMIN    0x00000001
12306 +#define IATTR_WATCH    0x00000002
12307 +#define IATTR_HIDE     0x00000004
12308 +#define IATTR_FLAGS    0x00000007
12309 +
12310 +#define IATTR_BARRIER  0x00010000
12311 +#define IATTR_IXUNLINK 0x00020000
12312 +#define IATTR_IMMUTABLE 0x00040000
12313 +#define IATTR_COW      0x00080000
12314 +
12315 +#ifdef __KERNEL__
12316 +
12317 +
12318 +#ifdef CONFIG_VSERVER_PROC_SECURE
12319 +#define IATTR_PROC_DEFAULT     ( IATTR_ADMIN | IATTR_HIDE )
12320 +#define IATTR_PROC_SYMLINK     ( IATTR_ADMIN )
12321 +#else
12322 +#define IATTR_PROC_DEFAULT     ( IATTR_ADMIN )
12323 +#define IATTR_PROC_SYMLINK     ( IATTR_ADMIN )
12324 +#endif
12325 +
12326 +#define vx_hide_check(c, m)    (((m) & IATTR_HIDE) ? vx_check(c, m) : 1)
12327 +
12328 +#endif /* __KERNEL__ */
12329 +
12330 +/* inode ioctls */
12331 +
12332 +#define FIOC_GETXFLG   _IOR('x', 5, long)
12333 +#define FIOC_SETXFLG   _IOW('x', 6, long)
12334 +
12335 +#else  /* _VX_INODE_H */
12336 +#warning duplicate inclusion
12337 +#endif /* _VX_INODE_H */
12338 diff -NurpP --minimal linux-3.6.10/include/linux/vserver/inode_cmd.h linux-3.6.10-vs2.3.4.5/include/linux/vserver/inode_cmd.h
12339 --- linux-3.6.10/include/linux/vserver/inode_cmd.h      1970-01-01 01:00:00.000000000 +0100
12340 +++ linux-3.6.10-vs2.3.4.5/include/linux/vserver/inode_cmd.h    2012-10-04 18:47:00.000000000 +0200
12341 @@ -0,0 +1,59 @@
12342 +#ifndef _VX_INODE_CMD_H
12343 +#define _VX_INODE_CMD_H
12344 +
12345 +
12346 +/*  inode vserver commands */
12347 +
12348 +#define VCMD_get_iattr         VC_CMD(INODE, 1, 1)
12349 +#define VCMD_set_iattr         VC_CMD(INODE, 2, 1)
12350 +
12351 +#define VCMD_fget_iattr                VC_CMD(INODE, 3, 0)
12352 +#define VCMD_fset_iattr                VC_CMD(INODE, 4, 0)
12353 +
12354 +struct vcmd_ctx_iattr_v1 {
12355 +       const char __user *name;
12356 +       uint32_t tag;
12357 +       uint32_t flags;
12358 +       uint32_t mask;
12359 +};
12360 +
12361 +struct vcmd_ctx_fiattr_v0 {
12362 +       uint32_t tag;
12363 +       uint32_t flags;
12364 +       uint32_t mask;
12365 +};
12366 +
12367 +
12368 +#ifdef __KERNEL__
12369 +
12370 +
12371 +#ifdef CONFIG_COMPAT
12372 +
12373 +#include <asm/compat.h>
12374 +
12375 +struct vcmd_ctx_iattr_v1_x32 {
12376 +       compat_uptr_t name_ptr;
12377 +       uint32_t tag;
12378 +       uint32_t flags;
12379 +       uint32_t mask;
12380 +};
12381 +
12382 +#endif /* CONFIG_COMPAT */
12383 +
12384 +#include <linux/compiler.h>
12385 +
12386 +extern int vc_get_iattr(void __user *);
12387 +extern int vc_set_iattr(void __user *);
12388 +
12389 +extern int vc_fget_iattr(uint32_t, void __user *);
12390 +extern int vc_fset_iattr(uint32_t, void __user *);
12391 +
12392 +#ifdef CONFIG_COMPAT
12393 +
12394 +extern int vc_get_iattr_x32(void __user *);
12395 +extern int vc_set_iattr_x32(void __user *);
12396 +
12397 +#endif /* CONFIG_COMPAT */
12398 +
12399 +#endif /* __KERNEL__ */
12400 +#endif /* _VX_INODE_CMD_H */
12401 diff -NurpP --minimal linux-3.6.10/include/linux/vserver/limit.h linux-3.6.10-vs2.3.4.5/include/linux/vserver/limit.h
12402 --- linux-3.6.10/include/linux/vserver/limit.h  1970-01-01 01:00:00.000000000 +0100
12403 +++ linux-3.6.10-vs2.3.4.5/include/linux/vserver/limit.h        2012-10-04 18:47:00.000000000 +0200
12404 @@ -0,0 +1,71 @@
12405 +#ifndef _VX_LIMIT_H
12406 +#define _VX_LIMIT_H
12407 +
12408 +#define VLIMIT_NSOCK   16
12409 +#define VLIMIT_OPENFD  17
12410 +#define VLIMIT_ANON    18
12411 +#define VLIMIT_SHMEM   19
12412 +#define VLIMIT_SEMARY  20
12413 +#define VLIMIT_NSEMS   21
12414 +#define VLIMIT_DENTRY  22
12415 +#define VLIMIT_MAPPED  23
12416 +
12417 +
12418 +#ifdef __KERNEL__
12419 +
12420 +#define        VLIM_NOCHECK    ((1L << VLIMIT_DENTRY) | (1L << RLIMIT_RSS))
12421 +
12422 +/*     keep in sync with CRLIM_INFINITY */
12423 +
12424 +#define        VLIM_INFINITY   (~0ULL)
12425 +
12426 +#include <asm/atomic.h>
12427 +#include <asm/resource.h>
12428 +
12429 +#ifndef RLIM_INFINITY
12430 +#warning RLIM_INFINITY is undefined
12431 +#endif
12432 +
12433 +#define __rlim_val(l, r, v)    ((l)->res[r].v)
12434 +
12435 +#define __rlim_soft(l, r)      __rlim_val(l, r, soft)
12436 +#define __rlim_hard(l, r)      __rlim_val(l, r, hard)
12437 +
12438 +#define __rlim_rcur(l, r)      __rlim_val(l, r, rcur)
12439 +#define __rlim_rmin(l, r)      __rlim_val(l, r, rmin)
12440 +#define __rlim_rmax(l, r)      __rlim_val(l, r, rmax)
12441 +
12442 +#define __rlim_lhit(l, r)      __rlim_val(l, r, lhit)
12443 +#define __rlim_hit(l, r)       atomic_inc(&__rlim_lhit(l, r))
12444 +
12445 +typedef atomic_long_t rlim_atomic_t;
12446 +typedef unsigned long rlim_t;
12447 +
12448 +#define __rlim_get(l, r)       atomic_long_read(&__rlim_rcur(l, r))
12449 +#define __rlim_set(l, r, v)    atomic_long_set(&__rlim_rcur(l, r), v)
12450 +#define __rlim_inc(l, r)       atomic_long_inc(&__rlim_rcur(l, r))
12451 +#define __rlim_dec(l, r)       atomic_long_dec(&__rlim_rcur(l, r))
12452 +#define __rlim_add(l, r, v)    atomic_long_add(v, &__rlim_rcur(l, r))
12453 +#define __rlim_sub(l, r, v)    atomic_long_sub(v, &__rlim_rcur(l, r))
12454 +
12455 +
12456 +#if    (RLIM_INFINITY == VLIM_INFINITY)
12457 +#define        VX_VLIM(r) ((long long)(long)(r))
12458 +#define        VX_RLIM(v) ((rlim_t)(v))
12459 +#else
12460 +#define        VX_VLIM(r) (((r) == RLIM_INFINITY) \
12461 +               ? VLIM_INFINITY : (long long)(r))
12462 +#define        VX_RLIM(v) (((v) == VLIM_INFINITY) \
12463 +               ? RLIM_INFINITY : (rlim_t)(v))
12464 +#endif
12465 +
12466 +struct sysinfo;
12467 +
12468 +void vx_vsi_meminfo(struct sysinfo *);
12469 +void vx_vsi_swapinfo(struct sysinfo *);
12470 +long vx_vsi_cached(struct sysinfo *);
12471 +
12472 +#define NUM_LIMITS     24
12473 +
12474 +#endif /* __KERNEL__ */
12475 +#endif /* _VX_LIMIT_H */
12476 diff -NurpP --minimal linux-3.6.10/include/linux/vserver/limit_cmd.h linux-3.6.10-vs2.3.4.5/include/linux/vserver/limit_cmd.h
12477 --- linux-3.6.10/include/linux/vserver/limit_cmd.h      1970-01-01 01:00:00.000000000 +0100
12478 +++ linux-3.6.10-vs2.3.4.5/include/linux/vserver/limit_cmd.h    2012-10-04 18:47:00.000000000 +0200
12479 @@ -0,0 +1,71 @@
12480 +#ifndef _VX_LIMIT_CMD_H
12481 +#define _VX_LIMIT_CMD_H
12482 +
12483 +
12484 +/*  rlimit vserver commands */
12485 +
12486 +#define VCMD_get_rlimit                VC_CMD(RLIMIT, 1, 0)
12487 +#define VCMD_set_rlimit                VC_CMD(RLIMIT, 2, 0)
12488 +#define VCMD_get_rlimit_mask   VC_CMD(RLIMIT, 3, 0)
12489 +#define VCMD_reset_hits                VC_CMD(RLIMIT, 7, 0)
12490 +#define VCMD_reset_minmax      VC_CMD(RLIMIT, 9, 0)
12491 +
12492 +struct vcmd_ctx_rlimit_v0 {
12493 +       uint32_t id;
12494 +       uint64_t minimum;
12495 +       uint64_t softlimit;
12496 +       uint64_t maximum;
12497 +};
12498 +
12499 +struct vcmd_ctx_rlimit_mask_v0 {
12500 +       uint32_t minimum;
12501 +       uint32_t softlimit;
12502 +       uint32_t maximum;
12503 +};
12504 +
12505 +#define VCMD_rlimit_stat       VC_CMD(VSTAT, 1, 0)
12506 +
12507 +struct vcmd_rlimit_stat_v0 {
12508 +       uint32_t id;
12509 +       uint32_t hits;
12510 +       uint64_t value;
12511 +       uint64_t minimum;
12512 +       uint64_t maximum;
12513 +};
12514 +
12515 +#define CRLIM_UNSET            (0ULL)
12516 +#define CRLIM_INFINITY         (~0ULL)
12517 +#define CRLIM_KEEP             (~1ULL)
12518 +
12519 +#ifdef __KERNEL__
12520 +
12521 +#ifdef CONFIG_IA32_EMULATION
12522 +
12523 +struct vcmd_ctx_rlimit_v0_x32 {
12524 +       uint32_t id;
12525 +       uint64_t minimum;
12526 +       uint64_t softlimit;
12527 +       uint64_t maximum;
12528 +} __attribute__ ((packed));
12529 +
12530 +#endif /* CONFIG_IA32_EMULATION */
12531 +
12532 +#include <linux/compiler.h>
12533 +
12534 +extern int vc_get_rlimit_mask(uint32_t, void __user *);
12535 +extern int vc_get_rlimit(struct vx_info *, void __user *);
12536 +extern int vc_set_rlimit(struct vx_info *, void __user *);
12537 +extern int vc_reset_hits(struct vx_info *, void __user *);
12538 +extern int vc_reset_minmax(struct vx_info *, void __user *);
12539 +
12540 +extern int vc_rlimit_stat(struct vx_info *, void __user *);
12541 +
12542 +#ifdef CONFIG_IA32_EMULATION
12543 +
12544 +extern int vc_get_rlimit_x32(struct vx_info *, void __user *);
12545 +extern int vc_set_rlimit_x32(struct vx_info *, void __user *);
12546 +
12547 +#endif /* CONFIG_IA32_EMULATION */
12548 +
12549 +#endif /* __KERNEL__ */
12550 +#endif /* _VX_LIMIT_CMD_H */
12551 diff -NurpP --minimal linux-3.6.10/include/linux/vserver/limit_def.h linux-3.6.10-vs2.3.4.5/include/linux/vserver/limit_def.h
12552 --- linux-3.6.10/include/linux/vserver/limit_def.h      1970-01-01 01:00:00.000000000 +0100
12553 +++ linux-3.6.10-vs2.3.4.5/include/linux/vserver/limit_def.h    2012-10-04 18:47:00.000000000 +0200
12554 @@ -0,0 +1,47 @@
12555 +#ifndef _VX_LIMIT_DEF_H
12556 +#define _VX_LIMIT_DEF_H
12557 +
12558 +#include <asm/atomic.h>
12559 +#include <asm/resource.h>
12560 +
12561 +#include "limit.h"
12562 +
12563 +
12564 +struct _vx_res_limit {
12565 +       rlim_t soft;            /* Context soft limit */
12566 +       rlim_t hard;            /* Context hard limit */
12567 +
12568 +       rlim_atomic_t rcur;     /* Current value */
12569 +       rlim_t rmin;            /* Context minimum */
12570 +       rlim_t rmax;            /* Context maximum */
12571 +
12572 +       atomic_t lhit;          /* Limit hits */
12573 +};
12574 +
12575 +/* context sub struct */
12576 +
12577 +struct _vx_limit {
12578 +       struct _vx_res_limit res[NUM_LIMITS];
12579 +};
12580 +
12581 +#ifdef CONFIG_VSERVER_DEBUG
12582 +
12583 +static inline void __dump_vx_limit(struct _vx_limit *limit)
12584 +{
12585 +       int i;
12586 +
12587 +       printk("\t_vx_limit:");
12588 +       for (i = 0; i < NUM_LIMITS; i++) {
12589 +               printk("\t [%2d] = %8lu %8lu/%8lu, %8ld/%8ld, %8d\n",
12590 +                       i, (unsigned long)__rlim_get(limit, i),
12591 +                       (unsigned long)__rlim_rmin(limit, i),
12592 +                       (unsigned long)__rlim_rmax(limit, i),
12593 +                       (long)__rlim_soft(limit, i),
12594 +                       (long)__rlim_hard(limit, i),
12595 +                       atomic_read(&__rlim_lhit(limit, i)));
12596 +       }
12597 +}
12598 +
12599 +#endif
12600 +
12601 +#endif /* _VX_LIMIT_DEF_H */
12602 diff -NurpP --minimal linux-3.6.10/include/linux/vserver/limit_int.h linux-3.6.10-vs2.3.4.5/include/linux/vserver/limit_int.h
12603 --- linux-3.6.10/include/linux/vserver/limit_int.h      1970-01-01 01:00:00.000000000 +0100
12604 +++ linux-3.6.10-vs2.3.4.5/include/linux/vserver/limit_int.h    2012-10-04 18:47:00.000000000 +0200
12605 @@ -0,0 +1,198 @@
12606 +#ifndef _VX_LIMIT_INT_H
12607 +#define _VX_LIMIT_INT_H
12608 +
12609 +#include "context.h"
12610 +
12611 +#ifdef __KERNEL__
12612 +
12613 +#define VXD_RCRES_COND(r)      VXD_CBIT(cres, r)
12614 +#define VXD_RLIMIT_COND(r)     VXD_CBIT(limit, r)
12615 +
12616 +extern const char *vlimit_name[NUM_LIMITS];
12617 +
12618 +static inline void __vx_acc_cres(struct vx_info *vxi,
12619 +       int res, int dir, void *_data, char *_file, int _line)
12620 +{
12621 +       if (VXD_RCRES_COND(res))
12622 +               vxlprintk(1, "vx_acc_cres[%5d,%s,%2d]: %5ld%s (%p)",
12623 +                       (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
12624 +                       (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
12625 +                       (dir > 0) ? "++" : "--", _data, _file, _line);
12626 +       if (!vxi)
12627 +               return;
12628 +
12629 +       if (dir > 0)
12630 +               __rlim_inc(&vxi->limit, res);
12631 +       else
12632 +               __rlim_dec(&vxi->limit, res);
12633 +}
12634 +
12635 +static inline void __vx_add_cres(struct vx_info *vxi,
12636 +       int res, int amount, void *_data, char *_file, int _line)
12637 +{
12638 +       if (VXD_RCRES_COND(res))
12639 +               vxlprintk(1, "vx_add_cres[%5d,%s,%2d]: %5ld += %5d (%p)",
12640 +                       (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
12641 +                       (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
12642 +                       amount, _data, _file, _line);
12643 +       if (amount == 0)
12644 +               return;
12645 +       if (!vxi)
12646 +               return;
12647 +       __rlim_add(&vxi->limit, res, amount);
12648 +}
12649 +
12650 +static inline
12651 +int __vx_cres_adjust_max(struct _vx_limit *limit, int res, rlim_t value)
12652 +{
12653 +       int cond = (value > __rlim_rmax(limit, res));
12654 +
12655 +       if (cond)
12656 +               __rlim_rmax(limit, res) = value;
12657 +       return cond;
12658 +}
12659 +
12660 +static inline
12661 +int __vx_cres_adjust_min(struct _vx_limit *limit, int res, rlim_t value)
12662 +{
12663 +       int cond = (value < __rlim_rmin(limit, res));
12664 +
12665 +       if (cond)
12666 +               __rlim_rmin(limit, res) = value;
12667 +       return cond;
12668 +}
12669 +
12670 +static inline
12671 +void __vx_cres_fixup(struct _vx_limit *limit, int res, rlim_t value)
12672 +{
12673 +       if (!__vx_cres_adjust_max(limit, res, value))
12674 +               __vx_cres_adjust_min(limit, res, value);
12675 +}
12676 +
12677 +
12678 +/*     return values:
12679 +        +1 ... no limit hit
12680 +        -1 ... over soft limit
12681 +         0 ... over hard limit         */
12682 +
12683 +static inline int __vx_cres_avail(struct vx_info *vxi,
12684 +       int res, int num, char *_file, int _line)
12685 +{
12686 +       struct _vx_limit *limit;
12687 +       rlim_t value;
12688 +
12689 +       if (VXD_RLIMIT_COND(res))
12690 +               vxlprintk(1, "vx_cres_avail[%5d,%s,%2d]: %5ld/%5ld > %5ld + %5d",
12691 +                       (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
12692 +                       (vxi ? (long)__rlim_soft(&vxi->limit, res) : -1),
12693 +                       (vxi ? (long)__rlim_hard(&vxi->limit, res) : -1),
12694 +                       (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
12695 +                       num, _file, _line);
12696 +       if (!vxi)
12697 +               return 1;
12698 +
12699 +       limit = &vxi->limit;
12700 +       value = __rlim_get(limit, res);
12701 +
12702 +       if (!__vx_cres_adjust_max(limit, res, value))
12703 +               __vx_cres_adjust_min(limit, res, value);
12704 +
12705 +       if (num == 0)
12706 +               return 1;
12707 +
12708 +       if (__rlim_soft(limit, res) == RLIM_INFINITY)
12709 +               return -1;
12710 +       if (value + num <= __rlim_soft(limit, res))
12711 +               return -1;
12712 +
12713 +       if (__rlim_hard(limit, res) == RLIM_INFINITY)
12714 +               return 1;
12715 +       if (value + num <= __rlim_hard(limit, res))
12716 +               return 1;
12717 +
12718 +       __rlim_hit(limit, res);
12719 +       return 0;
12720 +}
12721 +
12722 +
12723 +static const int VLA_RSS[] = { RLIMIT_RSS, VLIMIT_ANON, VLIMIT_MAPPED, 0 };
12724 +
12725 +static inline
12726 +rlim_t __vx_cres_array_sum(struct _vx_limit *limit, const int *array)
12727 +{
12728 +       rlim_t value, sum = 0;
12729 +       int res;
12730 +
12731 +       while ((res = *array++)) {
12732 +               value = __rlim_get(limit, res);
12733 +               __vx_cres_fixup(limit, res, value);
12734 +               sum += value;
12735 +       }
12736 +       return sum;
12737 +}
12738 +
12739 +static inline
12740 +rlim_t __vx_cres_array_fixup(struct _vx_limit *limit, const int *array)
12741 +{
12742 +       rlim_t value = __vx_cres_array_sum(limit, array + 1);
12743 +       int res = *array;
12744 +
12745 +       if (value == __rlim_get(limit, res))
12746 +               return value;
12747 +
12748 +       __rlim_set(limit, res, value);
12749 +       /* now adjust min/max */
12750 +       if (!__vx_cres_adjust_max(limit, res, value))
12751 +               __vx_cres_adjust_min(limit, res, value);
12752 +
12753 +       return value;
12754 +}
12755 +
12756 +static inline int __vx_cres_array_avail(struct vx_info *vxi,
12757 +       const int *array, int num, char *_file, int _line)
12758 +{
12759 +       struct _vx_limit *limit;
12760 +       rlim_t value = 0;
12761 +       int res;
12762 +
12763 +       if (num == 0)
12764 +               return 1;
12765 +       if (!vxi)
12766 +               return 1;
12767 +
12768 +       limit = &vxi->limit;
12769 +       res = *array;
12770 +       value = __vx_cres_array_sum(limit, array + 1);
12771 +
12772 +       __rlim_set(limit, res, value);
12773 +       __vx_cres_fixup(limit, res, value);
12774 +
12775 +       return __vx_cres_avail(vxi, res, num, _file, _line);
12776 +}
12777 +
12778 +
12779 +static inline void vx_limit_fixup(struct _vx_limit *limit, int id)
12780 +{
12781 +       rlim_t value;
12782 +       int res;
12783 +
12784 +       /* complex resources first */
12785 +       if ((id < 0) || (id == RLIMIT_RSS))
12786 +               __vx_cres_array_fixup(limit, VLA_RSS);
12787 +
12788 +       for (res = 0; res < NUM_LIMITS; res++) {
12789 +               if ((id > 0) && (res != id))
12790 +                       continue;
12791 +
12792 +               value = __rlim_get(limit, res);
12793 +               __vx_cres_fixup(limit, res, value);
12794 +
12795 +               /* not supposed to happen, maybe warn? */
12796 +               if (__rlim_rmax(limit, res) > __rlim_hard(limit, res))
12797 +                       __rlim_rmax(limit, res) = __rlim_hard(limit, res);
12798 +       }
12799 +}
12800 +
12801 +
12802 +#endif /* __KERNEL__ */
12803 +#endif /* _VX_LIMIT_INT_H */
12804 diff -NurpP --minimal linux-3.6.10/include/linux/vserver/monitor.h linux-3.6.10-vs2.3.4.5/include/linux/vserver/monitor.h
12805 --- linux-3.6.10/include/linux/vserver/monitor.h        1970-01-01 01:00:00.000000000 +0100
12806 +++ linux-3.6.10-vs2.3.4.5/include/linux/vserver/monitor.h      2012-10-04 18:47:00.000000000 +0200
12807 @@ -0,0 +1,96 @@
12808 +#ifndef _VX_MONITOR_H
12809 +#define _VX_MONITOR_H
12810 +
12811 +#include <linux/types.h>
12812 +
12813 +enum {
12814 +       VXM_UNUSED = 0,
12815 +
12816 +       VXM_SYNC = 0x10,
12817 +
12818 +       VXM_UPDATE = 0x20,
12819 +       VXM_UPDATE_1,
12820 +       VXM_UPDATE_2,
12821 +
12822 +       VXM_RQINFO_1 = 0x24,
12823 +       VXM_RQINFO_2,
12824 +
12825 +       VXM_ACTIVATE = 0x40,
12826 +       VXM_DEACTIVATE,
12827 +       VXM_IDLE,
12828 +
12829 +       VXM_HOLD = 0x44,
12830 +       VXM_UNHOLD,
12831 +
12832 +       VXM_MIGRATE = 0x48,
12833 +       VXM_RESCHED,
12834 +
12835 +       /* all other bits are flags */
12836 +       VXM_SCHED = 0x80,
12837 +};
12838 +
12839 +struct _vxm_update_1 {
12840 +       uint32_t tokens_max;
12841 +       uint32_t fill_rate;
12842 +       uint32_t interval;
12843 +};
12844 +
12845 +struct _vxm_update_2 {
12846 +       uint32_t tokens_min;
12847 +       uint32_t fill_rate;
12848 +       uint32_t interval;
12849 +};
12850 +
12851 +struct _vxm_rqinfo_1 {
12852 +       uint16_t running;
12853 +       uint16_t onhold;
12854 +       uint16_t iowait;
12855 +       uint16_t uintr;
12856 +       uint32_t idle_tokens;
12857 +};
12858 +
12859 +struct _vxm_rqinfo_2 {
12860 +       uint32_t norm_time;
12861 +       uint32_t idle_time;
12862 +       uint32_t idle_skip;
12863 +};
12864 +
12865 +struct _vxm_sched {
12866 +       uint32_t tokens;
12867 +       uint32_t norm_time;
12868 +       uint32_t idle_time;
12869 +};
12870 +
12871 +struct _vxm_task {
12872 +       uint16_t pid;
12873 +       uint16_t state;
12874 +};
12875 +
12876 +struct _vxm_event {
12877 +       uint32_t jif;
12878 +       union {
12879 +               uint32_t seq;
12880 +               uint32_t sec;
12881 +       };
12882 +       union {
12883 +               uint32_t tokens;
12884 +               uint32_t nsec;
12885 +               struct _vxm_task tsk;
12886 +       };
12887 +};
12888 +
12889 +struct _vx_mon_entry {
12890 +       uint16_t type;
12891 +       uint16_t xid;
12892 +       union {
12893 +               struct _vxm_event ev;
12894 +               struct _vxm_sched sd;
12895 +               struct _vxm_update_1 u1;
12896 +               struct _vxm_update_2 u2;
12897 +               struct _vxm_rqinfo_1 q1;
12898 +               struct _vxm_rqinfo_2 q2;
12899 +       };
12900 +};
12901 +
12902 +
12903 +#endif /* _VX_MONITOR_H */
12904 diff -NurpP --minimal linux-3.6.10/include/linux/vserver/network.h linux-3.6.10-vs2.3.4.5/include/linux/vserver/network.h
12905 --- linux-3.6.10/include/linux/vserver/network.h        1970-01-01 01:00:00.000000000 +0100
12906 +++ linux-3.6.10-vs2.3.4.5/include/linux/vserver/network.h      2012-10-04 18:47:00.000000000 +0200
12907 @@ -0,0 +1,148 @@
12908 +#ifndef _VX_NETWORK_H
12909 +#define _VX_NETWORK_H
12910 +
12911 +#include <linux/types.h>
12912 +
12913 +
12914 +#define MAX_N_CONTEXT  65535   /* Arbitrary limit */
12915 +
12916 +
12917 +/* network flags */
12918 +
12919 +#define NXF_INFO_PRIVATE       0x00000008
12920 +
12921 +#define NXF_SINGLE_IP          0x00000100
12922 +#define NXF_LBACK_REMAP                0x00000200
12923 +#define NXF_LBACK_ALLOW                0x00000400
12924 +
12925 +#define NXF_HIDE_NETIF         0x02000000
12926 +#define NXF_HIDE_LBACK         0x04000000
12927 +
12928 +#define NXF_STATE_SETUP                (1ULL << 32)
12929 +#define NXF_STATE_ADMIN                (1ULL << 34)
12930 +
12931 +#define NXF_SC_HELPER          (1ULL << 36)
12932 +#define NXF_PERSISTENT         (1ULL << 38)
12933 +
12934 +#define NXF_ONE_TIME           (0x0005ULL << 32)
12935 +
12936 +
12937 +#define        NXF_INIT_SET            (__nxf_init_set())
12938 +
12939 +static inline uint64_t __nxf_init_set(void) {
12940 +       return    NXF_STATE_ADMIN
12941 +#ifdef CONFIG_VSERVER_AUTO_LBACK
12942 +               | NXF_LBACK_REMAP
12943 +               | NXF_HIDE_LBACK
12944 +#endif
12945 +#ifdef CONFIG_VSERVER_AUTO_SINGLE
12946 +               | NXF_SINGLE_IP
12947 +#endif
12948 +               | NXF_HIDE_NETIF;
12949 +}
12950 +
12951 +
12952 +/* network caps */
12953 +
12954 +#define NXC_TUN_CREATE         0x00000001
12955 +
12956 +#define NXC_RAW_ICMP           0x00000100
12957 +
12958 +#define NXC_MULTICAST          0x00001000
12959 +
12960 +
12961 +/* address types */
12962 +
12963 +#define NXA_TYPE_IPV4          0x0001
12964 +#define NXA_TYPE_IPV6          0x0002
12965 +
12966 +#define NXA_TYPE_NONE          0x0000
12967 +#define NXA_TYPE_ANY           0x00FF
12968 +
12969 +#define NXA_TYPE_ADDR          0x0010
12970 +#define NXA_TYPE_MASK          0x0020
12971 +#define NXA_TYPE_RANGE         0x0040
12972 +
12973 +#define NXA_MASK_ALL           (NXA_TYPE_ADDR | NXA_TYPE_MASK | NXA_TYPE_RANGE)
12974 +
12975 +#define NXA_MOD_BCAST          0x0100
12976 +#define NXA_MOD_LBACK          0x0200
12977 +
12978 +#define NXA_LOOPBACK           0x1000
12979 +
12980 +#define NXA_MASK_BIND          (NXA_MASK_ALL | NXA_MOD_BCAST | NXA_MOD_LBACK)
12981 +#define NXA_MASK_SHOW          (NXA_MASK_ALL | NXA_LOOPBACK)
12982 +
12983 +#ifdef __KERNEL__
12984 +
12985 +#include <linux/list.h>
12986 +#include <linux/spinlock.h>
12987 +#include <linux/rcupdate.h>
12988 +#include <linux/in.h>
12989 +#include <linux/in6.h>
12990 +#include <asm/atomic.h>
12991 +
12992 +struct nx_addr_v4 {
12993 +       struct nx_addr_v4 *next;
12994 +       struct in_addr ip[2];
12995 +       struct in_addr mask;
12996 +       uint16_t type;
12997 +       uint16_t flags;
12998 +};
12999 +
13000 +struct nx_addr_v6 {
13001 +       struct nx_addr_v6 *next;
13002 +       struct in6_addr ip;
13003 +       struct in6_addr mask;
13004 +       uint32_t prefix;
13005 +       uint16_t type;
13006 +       uint16_t flags;
13007 +};
13008 +
13009 +struct nx_info {
13010 +       struct hlist_node nx_hlist;     /* linked list of nxinfos */
13011 +       nid_t nx_id;                    /* vnet id */
13012 +       atomic_t nx_usecnt;             /* usage count */
13013 +       atomic_t nx_tasks;              /* tasks count */
13014 +       int nx_state;                   /* context state */
13015 +
13016 +       uint64_t nx_flags;              /* network flag word */
13017 +       uint64_t nx_ncaps;              /* network capabilities */
13018 +
13019 +       struct in_addr v4_lback;        /* Loopback address */
13020 +       struct in_addr v4_bcast;        /* Broadcast address */
13021 +       struct nx_addr_v4 v4;           /* First/Single ipv4 address */
13022 +#ifdef CONFIG_IPV6
13023 +       struct nx_addr_v6 v6;           /* First/Single ipv6 address */
13024 +#endif
13025 +       char nx_name[65];               /* network context name */
13026 +};
13027 +
13028 +
13029 +/* status flags */
13030 +
13031 +#define NXS_HASHED      0x0001
13032 +#define NXS_SHUTDOWN    0x0100
13033 +#define NXS_RELEASED    0x8000
13034 +
13035 +extern struct nx_info *lookup_nx_info(int);
13036 +
13037 +extern int get_nid_list(int, unsigned int *, int);
13038 +extern int nid_is_hashed(nid_t);
13039 +
13040 +extern int nx_migrate_task(struct task_struct *, struct nx_info *);
13041 +
13042 +extern long vs_net_change(struct nx_info *, unsigned int);
13043 +
13044 +struct sock;
13045 +
13046 +
13047 +#define NX_IPV4(n)     ((n)->v4.type != NXA_TYPE_NONE)
13048 +#ifdef  CONFIG_IPV6
13049 +#define NX_IPV6(n)     ((n)->v6.type != NXA_TYPE_NONE)
13050 +#else
13051 +#define NX_IPV6(n)     (0)
13052 +#endif
13053 +
13054 +#endif /* __KERNEL__ */
13055 +#endif /* _VX_NETWORK_H */
13056 diff -NurpP --minimal linux-3.6.10/include/linux/vserver/network_cmd.h linux-3.6.10-vs2.3.4.5/include/linux/vserver/network_cmd.h
13057 --- linux-3.6.10/include/linux/vserver/network_cmd.h    1970-01-01 01:00:00.000000000 +0100
13058 +++ linux-3.6.10-vs2.3.4.5/include/linux/vserver/network_cmd.h  2012-10-04 18:47:00.000000000 +0200
13059 @@ -0,0 +1,164 @@
13060 +#ifndef _VX_NETWORK_CMD_H
13061 +#define _VX_NETWORK_CMD_H
13062 +
13063 +
13064 +/* vinfo commands */
13065 +
13066 +#define VCMD_task_nid          VC_CMD(VINFO, 2, 0)
13067 +
13068 +#ifdef __KERNEL__
13069 +extern int vc_task_nid(uint32_t);
13070 +
13071 +#endif /* __KERNEL__ */
13072 +
13073 +#define VCMD_nx_info           VC_CMD(VINFO, 6, 0)
13074 +
13075 +struct vcmd_nx_info_v0 {
13076 +       uint32_t nid;
13077 +       /* more to come */
13078 +};
13079 +
13080 +#ifdef __KERNEL__
13081 +extern int vc_nx_info(struct nx_info *, void __user *);
13082 +
13083 +#endif /* __KERNEL__ */
13084 +
13085 +#include <linux/in.h>
13086 +#include <linux/in6.h>
13087 +
13088 +#define VCMD_net_create_v0     VC_CMD(VNET, 1, 0)
13089 +#define VCMD_net_create                VC_CMD(VNET, 1, 1)
13090 +
13091 +struct  vcmd_net_create {
13092 +       uint64_t flagword;
13093 +};
13094 +
13095 +#define VCMD_net_migrate       VC_CMD(NETMIG, 1, 0)
13096 +
13097 +#define VCMD_net_add           VC_CMD(NETALT, 1, 0)
13098 +#define VCMD_net_remove                VC_CMD(NETALT, 2, 0)
13099 +
13100 +struct vcmd_net_addr_v0 {
13101 +       uint16_t type;
13102 +       uint16_t count;
13103 +       struct in_addr ip[4];
13104 +       struct in_addr mask[4];
13105 +};
13106 +
13107 +#define VCMD_net_add_ipv4_v1   VC_CMD(NETALT, 1, 1)
13108 +#define VCMD_net_rem_ipv4_v1   VC_CMD(NETALT, 2, 1)
13109 +
13110 +struct vcmd_net_addr_ipv4_v1 {
13111 +       uint16_t type;
13112 +       uint16_t flags;
13113 +       struct in_addr ip;
13114 +       struct in_addr mask;
13115 +};
13116 +
13117 +#define VCMD_net_add_ipv4      VC_CMD(NETALT, 1, 2)
13118 +#define VCMD_net_rem_ipv4      VC_CMD(NETALT, 2, 2)
13119 +
13120 +struct vcmd_net_addr_ipv4_v2 {
13121 +       uint16_t type;
13122 +       uint16_t flags;
13123 +       struct in_addr ip;
13124 +       struct in_addr ip2;
13125 +       struct in_addr mask;
13126 +};
13127 +
13128 +#define VCMD_net_add_ipv6      VC_CMD(NETALT, 3, 1)
13129 +#define VCMD_net_remove_ipv6   VC_CMD(NETALT, 4, 1)
13130 +
13131 +struct vcmd_net_addr_ipv6_v1 {
13132 +       uint16_t type;
13133 +       uint16_t flags;
13134 +       uint32_t prefix;
13135 +       struct in6_addr ip;
13136 +       struct in6_addr mask;
13137 +};
13138 +
13139 +#define VCMD_add_match_ipv4    VC_CMD(NETALT, 5, 0)
13140 +#define VCMD_get_match_ipv4    VC_CMD(NETALT, 6, 0)
13141 +
13142 +struct vcmd_match_ipv4_v0 {
13143 +       uint16_t type;
13144 +       uint16_t flags;
13145 +       uint16_t parent;
13146 +       uint16_t prefix;
13147 +       struct in_addr ip;
13148 +       struct in_addr ip2;
13149 +       struct in_addr mask;
13150 +};
13151 +
13152 +#define VCMD_add_match_ipv6    VC_CMD(NETALT, 7, 0)
13153 +#define VCMD_get_match_ipv6    VC_CMD(NETALT, 8, 0)
13154 +
13155 +struct vcmd_match_ipv6_v0 {
13156 +       uint16_t type;
13157 +       uint16_t flags;
13158 +       uint16_t parent;
13159 +       uint16_t prefix;
13160 +       struct in6_addr ip;
13161 +       struct in6_addr ip2;
13162 +       struct in6_addr mask;
13163 +};
13164 +
13165 +
13166 +#ifdef __KERNEL__
13167 +extern int vc_net_create(uint32_t, void __user *);
13168 +extern int vc_net_migrate(struct nx_info *, void __user *);
13169 +
13170 +extern int vc_net_add(struct nx_info *, void __user *);
13171 +extern int vc_net_remove(struct nx_info *, void __user *);
13172 +
13173 +extern int vc_net_add_ipv4_v1(struct nx_info *, void __user *);
13174 +extern int vc_net_add_ipv4(struct nx_info *, void __user *);
13175 +
13176 +extern int vc_net_rem_ipv4_v1(struct nx_info *, void __user *);
13177 +extern int vc_net_rem_ipv4(struct nx_info *, void __user *);
13178 +
13179 +extern int vc_net_add_ipv6(struct nx_info *, void __user *);
13180 +extern int vc_net_remove_ipv6(struct nx_info *, void __user *);
13181 +
13182 +extern int vc_add_match_ipv4(struct nx_info *, void __user *);
13183 +extern int vc_get_match_ipv4(struct nx_info *, void __user *);
13184 +
13185 +extern int vc_add_match_ipv6(struct nx_info *, void __user *);
13186 +extern int vc_get_match_ipv6(struct nx_info *, void __user *);
13187 +
13188 +#endif /* __KERNEL__ */
13189 +
13190 +
13191 +/* flag commands */
13192 +
13193 +#define VCMD_get_nflags                VC_CMD(FLAGS, 5, 0)
13194 +#define VCMD_set_nflags                VC_CMD(FLAGS, 6, 0)
13195 +
13196 +struct vcmd_net_flags_v0 {
13197 +       uint64_t flagword;
13198 +       uint64_t mask;
13199 +};
13200 +
13201 +#ifdef __KERNEL__
13202 +extern int vc_get_nflags(struct nx_info *, void __user *);
13203 +extern int vc_set_nflags(struct nx_info *, void __user *);
13204 +
13205 +#endif /* __KERNEL__ */
13206 +
13207 +
13208 +/* network caps commands */
13209 +
13210 +#define VCMD_get_ncaps         VC_CMD(FLAGS, 7, 0)
13211 +#define VCMD_set_ncaps         VC_CMD(FLAGS, 8, 0)
13212 +
13213 +struct vcmd_net_caps_v0 {
13214 +       uint64_t ncaps;
13215 +       uint64_t cmask;
13216 +};
13217 +
13218 +#ifdef __KERNEL__
13219 +extern int vc_get_ncaps(struct nx_info *, void __user *);
13220 +extern int vc_set_ncaps(struct nx_info *, void __user *);
13221 +
13222 +#endif /* __KERNEL__ */
13223 +#endif /* _VX_CONTEXT_CMD_H */
13224 diff -NurpP --minimal linux-3.6.10/include/linux/vserver/percpu.h linux-3.6.10-vs2.3.4.5/include/linux/vserver/percpu.h
13225 --- linux-3.6.10/include/linux/vserver/percpu.h 1970-01-01 01:00:00.000000000 +0100
13226 +++ linux-3.6.10-vs2.3.4.5/include/linux/vserver/percpu.h       2012-10-04 18:47:00.000000000 +0200
13227 @@ -0,0 +1,14 @@
13228 +#ifndef _VX_PERCPU_H
13229 +#define _VX_PERCPU_H
13230 +
13231 +#include "cvirt_def.h"
13232 +#include "sched_def.h"
13233 +
13234 +struct _vx_percpu {
13235 +       struct _vx_cvirt_pc cvirt;
13236 +       struct _vx_sched_pc sched;
13237 +};
13238 +
13239 +#define        PERCPU_PERCTX   (sizeof(struct _vx_percpu))
13240 +
13241 +#endif /* _VX_PERCPU_H */
13242 diff -NurpP --minimal linux-3.6.10/include/linux/vserver/pid.h linux-3.6.10-vs2.3.4.5/include/linux/vserver/pid.h
13243 --- linux-3.6.10/include/linux/vserver/pid.h    1970-01-01 01:00:00.000000000 +0100
13244 +++ linux-3.6.10-vs2.3.4.5/include/linux/vserver/pid.h  2012-10-04 18:47:00.000000000 +0200
13245 @@ -0,0 +1,51 @@
13246 +#ifndef _VSERVER_PID_H
13247 +#define _VSERVER_PID_H
13248 +
13249 +/* pid faking stuff */
13250 +
13251 +#define vx_info_map_pid(v, p) \
13252 +       __vx_info_map_pid((v), (p), __func__, __FILE__, __LINE__)
13253 +#define vx_info_map_tgid(v,p)  vx_info_map_pid(v,p)
13254 +#define vx_map_pid(p) vx_info_map_pid(current_vx_info(), p)
13255 +#define vx_map_tgid(p) vx_map_pid(p)
13256 +
13257 +static inline int __vx_info_map_pid(struct vx_info *vxi, int pid,
13258 +       const char *func, const char *file, int line)
13259 +{
13260 +       if (vx_info_flags(vxi, VXF_INFO_INIT, 0)) {
13261 +               vxfprintk(VXD_CBIT(cvirt, 2),
13262 +                       "vx_map_tgid: %p/%llx: %d -> %d",
13263 +                       vxi, (long long)vxi->vx_flags, pid,
13264 +                       (pid && pid == vxi->vx_initpid) ? 1 : pid,
13265 +                       func, file, line);
13266 +               if (pid == 0)
13267 +                       return 0;
13268 +               if (pid == vxi->vx_initpid)
13269 +                       return 1;
13270 +       }
13271 +       return pid;
13272 +}
13273 +
13274 +#define vx_info_rmap_pid(v, p) \
13275 +       __vx_info_rmap_pid((v), (p), __func__, __FILE__, __LINE__)
13276 +#define vx_rmap_pid(p) vx_info_rmap_pid(current_vx_info(), p)
13277 +#define vx_rmap_tgid(p) vx_rmap_pid(p)
13278 +
13279 +static inline int __vx_info_rmap_pid(struct vx_info *vxi, int pid,
13280 +       const char *func, const char *file, int line)
13281 +{
13282 +       if (vx_info_flags(vxi, VXF_INFO_INIT, 0)) {
13283 +               vxfprintk(VXD_CBIT(cvirt, 2),
13284 +                       "vx_rmap_tgid: %p/%llx: %d -> %d",
13285 +                       vxi, (long long)vxi->vx_flags, pid,
13286 +                       (pid == 1) ? vxi->vx_initpid : pid,
13287 +                       func, file, line);
13288 +               if ((pid == 1) && vxi->vx_initpid)
13289 +                       return vxi->vx_initpid;
13290 +               if (pid == vxi->vx_initpid)
13291 +                       return ~0U;
13292 +       }
13293 +       return pid;
13294 +}
13295 +
13296 +#endif
13297 diff -NurpP --minimal linux-3.6.10/include/linux/vserver/sched.h linux-3.6.10-vs2.3.4.5/include/linux/vserver/sched.h
13298 --- linux-3.6.10/include/linux/vserver/sched.h  1970-01-01 01:00:00.000000000 +0100
13299 +++ linux-3.6.10-vs2.3.4.5/include/linux/vserver/sched.h        2012-10-04 18:47:00.000000000 +0200
13300 @@ -0,0 +1,23 @@
13301 +#ifndef _VX_SCHED_H
13302 +#define _VX_SCHED_H
13303 +
13304 +
13305 +#ifdef __KERNEL__
13306 +
13307 +struct timespec;
13308 +
13309 +void vx_vsi_uptime(struct timespec *, struct timespec *);
13310 +
13311 +
13312 +struct vx_info;
13313 +
13314 +void vx_update_load(struct vx_info *);
13315 +
13316 +
13317 +void vx_update_sched_param(struct _vx_sched *sched,
13318 +       struct _vx_sched_pc *sched_pc);
13319 +
13320 +#endif /* __KERNEL__ */
13321 +#else  /* _VX_SCHED_H */
13322 +#warning duplicate inclusion
13323 +#endif /* _VX_SCHED_H */
13324 diff -NurpP --minimal linux-3.6.10/include/linux/vserver/sched_cmd.h linux-3.6.10-vs2.3.4.5/include/linux/vserver/sched_cmd.h
13325 --- linux-3.6.10/include/linux/vserver/sched_cmd.h      1970-01-01 01:00:00.000000000 +0100
13326 +++ linux-3.6.10-vs2.3.4.5/include/linux/vserver/sched_cmd.h    2012-10-04 18:47:00.000000000 +0200
13327 @@ -0,0 +1,21 @@
13328 +#ifndef _VX_SCHED_CMD_H
13329 +#define _VX_SCHED_CMD_H
13330 +
13331 +
13332 +struct vcmd_prio_bias {
13333 +       int32_t cpu_id;
13334 +       int32_t prio_bias;
13335 +};
13336 +
13337 +#define VCMD_set_prio_bias     VC_CMD(SCHED, 4, 0)
13338 +#define VCMD_get_prio_bias     VC_CMD(SCHED, 5, 0)
13339 +
13340 +#ifdef __KERNEL__
13341 +
13342 +#include <linux/compiler.h>
13343 +
13344 +extern int vc_set_prio_bias(struct vx_info *, void __user *);
13345 +extern int vc_get_prio_bias(struct vx_info *, void __user *);
13346 +
13347 +#endif /* __KERNEL__ */
13348 +#endif /* _VX_SCHED_CMD_H */
13349 diff -NurpP --minimal linux-3.6.10/include/linux/vserver/sched_def.h linux-3.6.10-vs2.3.4.5/include/linux/vserver/sched_def.h
13350 --- linux-3.6.10/include/linux/vserver/sched_def.h      1970-01-01 01:00:00.000000000 +0100
13351 +++ linux-3.6.10-vs2.3.4.5/include/linux/vserver/sched_def.h    2012-10-04 18:47:00.000000000 +0200
13352 @@ -0,0 +1,38 @@
13353 +#ifndef _VX_SCHED_DEF_H
13354 +#define _VX_SCHED_DEF_H
13355 +
13356 +#include <linux/spinlock.h>
13357 +#include <linux/jiffies.h>
13358 +#include <linux/cpumask.h>
13359 +#include <asm/atomic.h>
13360 +#include <asm/param.h>
13361 +
13362 +
13363 +/* context sub struct */
13364 +
13365 +struct _vx_sched {
13366 +       int prio_bias;                  /* bias offset for priority */
13367 +
13368 +       cpumask_t update;               /* CPUs which should update */
13369 +};
13370 +
13371 +struct _vx_sched_pc {
13372 +       int prio_bias;                  /* bias offset for priority */
13373 +
13374 +       uint64_t user_ticks;            /* token tick events */
13375 +       uint64_t sys_ticks;             /* token tick events */
13376 +       uint64_t hold_ticks;            /* token ticks paused */
13377 +};
13378 +
13379 +
13380 +#ifdef CONFIG_VSERVER_DEBUG
13381 +
13382 +static inline void __dump_vx_sched(struct _vx_sched *sched)
13383 +{
13384 +       printk("\t_vx_sched:\n");
13385 +       printk("\t priority = %4d\n", sched->prio_bias);
13386 +}
13387 +
13388 +#endif
13389 +
13390 +#endif /* _VX_SCHED_DEF_H */
13391 diff -NurpP --minimal linux-3.6.10/include/linux/vserver/signal.h linux-3.6.10-vs2.3.4.5/include/linux/vserver/signal.h
13392 --- linux-3.6.10/include/linux/vserver/signal.h 1970-01-01 01:00:00.000000000 +0100
13393 +++ linux-3.6.10-vs2.3.4.5/include/linux/vserver/signal.h       2012-10-04 18:47:00.000000000 +0200
13394 @@ -0,0 +1,14 @@
13395 +#ifndef _VX_SIGNAL_H
13396 +#define _VX_SIGNAL_H
13397 +
13398 +
13399 +#ifdef __KERNEL__
13400 +
13401 +struct vx_info;
13402 +
13403 +int vx_info_kill(struct vx_info *, int, int);
13404 +
13405 +#endif /* __KERNEL__ */
13406 +#else  /* _VX_SIGNAL_H */
13407 +#warning duplicate inclusion
13408 +#endif /* _VX_SIGNAL_H */
13409 diff -NurpP --minimal linux-3.6.10/include/linux/vserver/signal_cmd.h linux-3.6.10-vs2.3.4.5/include/linux/vserver/signal_cmd.h
13410 --- linux-3.6.10/include/linux/vserver/signal_cmd.h     1970-01-01 01:00:00.000000000 +0100
13411 +++ linux-3.6.10-vs2.3.4.5/include/linux/vserver/signal_cmd.h   2012-10-04 18:47:00.000000000 +0200
13412 @@ -0,0 +1,43 @@
13413 +#ifndef _VX_SIGNAL_CMD_H
13414 +#define _VX_SIGNAL_CMD_H
13415 +
13416 +
13417 +/*  signalling vserver commands */
13418 +
13419 +#define VCMD_ctx_kill          VC_CMD(PROCTRL, 1, 0)
13420 +#define VCMD_wait_exit         VC_CMD(EVENT, 99, 0)
13421 +
13422 +struct vcmd_ctx_kill_v0 {
13423 +       int32_t pid;
13424 +       int32_t sig;
13425 +};
13426 +
13427 +struct vcmd_wait_exit_v0 {
13428 +       int32_t reboot_cmd;
13429 +       int32_t exit_code;
13430 +};
13431 +
13432 +#ifdef __KERNEL__
13433 +
13434 +extern int vc_ctx_kill(struct vx_info *, void __user *);
13435 +extern int vc_wait_exit(struct vx_info *, void __user *);
13436 +
13437 +#endif /* __KERNEL__ */
13438 +
13439 +/*  process alteration commands */
13440 +
13441 +#define VCMD_get_pflags                VC_CMD(PROCALT, 5, 0)
13442 +#define VCMD_set_pflags                VC_CMD(PROCALT, 6, 0)
13443 +
13444 +struct vcmd_pflags_v0 {
13445 +       uint32_t flagword;
13446 +       uint32_t mask;
13447 +};
13448 +
13449 +#ifdef __KERNEL__
13450 +
13451 +extern int vc_get_pflags(uint32_t pid, void __user *);
13452 +extern int vc_set_pflags(uint32_t pid, void __user *);
13453 +
13454 +#endif /* __KERNEL__ */
13455 +#endif /* _VX_SIGNAL_CMD_H */
13456 diff -NurpP --minimal linux-3.6.10/include/linux/vserver/space.h linux-3.6.10-vs2.3.4.5/include/linux/vserver/space.h
13457 --- linux-3.6.10/include/linux/vserver/space.h  1970-01-01 01:00:00.000000000 +0100
13458 +++ linux-3.6.10-vs2.3.4.5/include/linux/vserver/space.h        2012-10-04 18:47:00.000000000 +0200
13459 @@ -0,0 +1,12 @@
13460 +#ifndef _VX_SPACE_H
13461 +#define _VX_SPACE_H
13462 +
13463 +#include <linux/types.h>
13464 +
13465 +struct vx_info;
13466 +
13467 +int vx_set_space(struct vx_info *vxi, unsigned long mask, unsigned index);
13468 +
13469 +#else  /* _VX_SPACE_H */
13470 +#warning duplicate inclusion
13471 +#endif /* _VX_SPACE_H */
13472 diff -NurpP --minimal linux-3.6.10/include/linux/vserver/space_cmd.h linux-3.6.10-vs2.3.4.5/include/linux/vserver/space_cmd.h
13473 --- linux-3.6.10/include/linux/vserver/space_cmd.h      1970-01-01 01:00:00.000000000 +0100
13474 +++ linux-3.6.10-vs2.3.4.5/include/linux/vserver/space_cmd.h    2012-10-04 18:47:00.000000000 +0200
13475 @@ -0,0 +1,38 @@
13476 +#ifndef _VX_SPACE_CMD_H
13477 +#define _VX_SPACE_CMD_H
13478 +
13479 +
13480 +#define VCMD_enter_space_v0    VC_CMD(PROCALT, 1, 0)
13481 +#define VCMD_enter_space_v1    VC_CMD(PROCALT, 1, 1)
13482 +#define VCMD_enter_space       VC_CMD(PROCALT, 1, 2)
13483 +
13484 +#define VCMD_set_space_v0      VC_CMD(PROCALT, 3, 0)
13485 +#define VCMD_set_space_v1      VC_CMD(PROCALT, 3, 1)
13486 +#define VCMD_set_space         VC_CMD(PROCALT, 3, 2)
13487 +
13488 +#define VCMD_get_space_mask_v0 VC_CMD(PROCALT, 4, 0)
13489 +
13490 +#define VCMD_get_space_mask    VC_CMD(VSPACE, 0, 1)
13491 +#define VCMD_get_space_default VC_CMD(VSPACE, 1, 0)
13492 +
13493 +
13494 +struct vcmd_space_mask_v1 {
13495 +       uint64_t mask;
13496 +};
13497 +
13498 +struct vcmd_space_mask_v2 {
13499 +       uint64_t mask;
13500 +       uint32_t index;
13501 +};
13502 +
13503 +
13504 +#ifdef __KERNEL__
13505 +
13506 +extern int vc_enter_space_v1(struct vx_info *, void __user *);
13507 +extern int vc_set_space_v1(struct vx_info *, void __user *);
13508 +extern int vc_enter_space(struct vx_info *, void __user *);
13509 +extern int vc_set_space(struct vx_info *, void __user *);
13510 +extern int vc_get_space_mask(void __user *, int);
13511 +
13512 +#endif /* __KERNEL__ */
13513 +#endif /* _VX_SPACE_CMD_H */
13514 diff -NurpP --minimal linux-3.6.10/include/linux/vserver/switch.h linux-3.6.10-vs2.3.4.5/include/linux/vserver/switch.h
13515 --- linux-3.6.10/include/linux/vserver/switch.h 1970-01-01 01:00:00.000000000 +0100
13516 +++ linux-3.6.10-vs2.3.4.5/include/linux/vserver/switch.h       2012-10-04 18:47:00.000000000 +0200
13517 @@ -0,0 +1,98 @@
13518 +#ifndef _VX_SWITCH_H
13519 +#define _VX_SWITCH_H
13520 +
13521 +#include <linux/types.h>
13522 +
13523 +
13524 +#define VC_CATEGORY(c)         (((c) >> 24) & 0x3F)
13525 +#define VC_COMMAND(c)          (((c) >> 16) & 0xFF)
13526 +#define VC_VERSION(c)          ((c) & 0xFFF)
13527 +
13528 +#define VC_CMD(c, i, v)                ((((VC_CAT_ ## c) & 0x3F) << 24) \
13529 +                               | (((i) & 0xFF) << 16) | ((v) & 0xFFF))
13530 +
13531 +/*
13532 +
13533 +  Syscall Matrix V2.8
13534 +
13535 +        |VERSION|CREATE |MODIFY |MIGRATE|CONTROL|EXPERIM| |SPECIAL|SPECIAL|
13536 +        |STATS  |DESTROY|ALTER  |CHANGE |LIMIT  |TEST   | |       |       |
13537 +        |INFO   |SETUP  |       |MOVE   |       |       | |       |       |
13538 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13539 +  SYSTEM |VERSION|VSETUP |VHOST  |       |       |       | |DEVICE |       |
13540 +  HOST   |     00|     01|     02|     03|     04|     05| |     06|     07|
13541 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13542 +  CPU    |       |VPROC  |PROCALT|PROCMIG|PROCTRL|       | |SCHED. |       |
13543 +  PROCESS|     08|     09|     10|     11|     12|     13| |     14|     15|
13544 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13545 +  MEMORY |       |       |       |       |MEMCTRL|       | |SWAP   |       |
13546 +        |     16|     17|     18|     19|     20|     21| |     22|     23|
13547 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13548 +  NETWORK|       |VNET   |NETALT |NETMIG |NETCTL |       | |SERIAL |       |
13549 +        |     24|     25|     26|     27|     28|     29| |     30|     31|
13550 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13551 +  DISK   |       |       |       |TAGMIG |DLIMIT |       | |INODE  |       |
13552 +  VFS    |     32|     33|     34|     35|     36|     37| |     38|     39|
13553 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13554 +  OTHER  |VSTAT  |       |       |       |       |       | |VINFO  |       |
13555 +        |     40|     41|     42|     43|     44|     45| |     46|     47|
13556 +  =======+=======+=======+=======+=======+=======+=======+ +=======+=======+
13557 +  SPECIAL|EVENT  |       |       |       |FLAGS  |       | |VSPACE |       |
13558 +        |     48|     49|     50|     51|     52|     53| |     54|     55|
13559 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13560 +  SPECIAL|DEBUG  |       |       |       |RLIMIT |SYSCALL| |       |COMPAT |
13561 +        |     56|     57|     58|     59|     60|TEST 61| |     62|     63|
13562 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13563 +
13564 +*/
13565 +
13566 +#define VC_CAT_VERSION         0
13567 +
13568 +#define VC_CAT_VSETUP          1
13569 +#define VC_CAT_VHOST           2
13570 +
13571 +#define VC_CAT_DEVICE          6
13572 +
13573 +#define VC_CAT_VPROC           9
13574 +#define VC_CAT_PROCALT         10
13575 +#define VC_CAT_PROCMIG         11
13576 +#define VC_CAT_PROCTRL         12
13577 +
13578 +#define VC_CAT_SCHED           14
13579 +#define VC_CAT_MEMCTRL         20
13580 +
13581 +#define VC_CAT_VNET            25
13582 +#define VC_CAT_NETALT          26
13583 +#define VC_CAT_NETMIG          27
13584 +#define VC_CAT_NETCTRL         28
13585 +
13586 +#define VC_CAT_TAGMIG          35
13587 +#define VC_CAT_DLIMIT          36
13588 +#define VC_CAT_INODE           38
13589 +
13590 +#define VC_CAT_VSTAT           40
13591 +#define VC_CAT_VINFO           46
13592 +#define VC_CAT_EVENT           48
13593 +
13594 +#define VC_CAT_FLAGS           52
13595 +#define VC_CAT_VSPACE          54
13596 +#define VC_CAT_DEBUG           56
13597 +#define VC_CAT_RLIMIT          60
13598 +
13599 +#define VC_CAT_SYSTEST         61
13600 +#define VC_CAT_COMPAT          63
13601 +
13602 +/*  query version */
13603 +
13604 +#define VCMD_get_version       VC_CMD(VERSION, 0, 0)
13605 +#define VCMD_get_vci           VC_CMD(VERSION, 1, 0)
13606 +
13607 +
13608 +#ifdef __KERNEL__
13609 +
13610 +#include <linux/errno.h>
13611 +
13612 +#endif /* __KERNEL__ */
13613 +
13614 +#endif /* _VX_SWITCH_H */
13615 +
13616 diff -NurpP --minimal linux-3.6.10/include/linux/vserver/tag.h linux-3.6.10-vs2.3.4.5/include/linux/vserver/tag.h
13617 --- linux-3.6.10/include/linux/vserver/tag.h    1970-01-01 01:00:00.000000000 +0100
13618 +++ linux-3.6.10-vs2.3.4.5/include/linux/vserver/tag.h  2012-10-04 18:47:00.000000000 +0200
13619 @@ -0,0 +1,143 @@
13620 +#ifndef _DX_TAG_H
13621 +#define _DX_TAG_H
13622 +
13623 +#include <linux/types.h>
13624 +
13625 +
13626 +#define DX_TAG(in)     (IS_TAGGED(in))
13627 +
13628 +
13629 +#ifdef CONFIG_TAG_NFSD
13630 +#define DX_TAG_NFSD    1
13631 +#else
13632 +#define DX_TAG_NFSD    0
13633 +#endif
13634 +
13635 +
13636 +#ifdef CONFIG_TAGGING_NONE
13637 +
13638 +#define MAX_UID                0xFFFFFFFF
13639 +#define MAX_GID                0xFFFFFFFF
13640 +
13641 +#define INOTAG_TAG(cond, uid, gid, tag)        (0)
13642 +
13643 +#define TAGINO_UID(cond, uid, tag)     (uid)
13644 +#define TAGINO_GID(cond, gid, tag)     (gid)
13645 +
13646 +#endif
13647 +
13648 +
13649 +#ifdef CONFIG_TAGGING_GID16
13650 +
13651 +#define MAX_UID                0xFFFFFFFF
13652 +#define MAX_GID                0x0000FFFF
13653 +
13654 +#define INOTAG_TAG(cond, uid, gid, tag)        \
13655 +       ((cond) ? (((gid) >> 16) & 0xFFFF) : 0)
13656 +
13657 +#define TAGINO_UID(cond, uid, tag)     (uid)
13658 +#define TAGINO_GID(cond, gid, tag)     \
13659 +       ((cond) ? (((gid) & 0xFFFF) | ((tag) << 16)) : (gid))
13660 +
13661 +#endif
13662 +
13663 +
13664 +#ifdef CONFIG_TAGGING_ID24
13665 +
13666 +#define MAX_UID                0x00FFFFFF
13667 +#define MAX_GID                0x00FFFFFF
13668 +
13669 +#define INOTAG_TAG(cond, uid, gid, tag)        \
13670 +       ((cond) ? ((((uid) >> 16) & 0xFF00) | (((gid) >> 24) & 0xFF)) : 0)
13671 +
13672 +#define TAGINO_UID(cond, uid, tag)     \
13673 +       ((cond) ? (((uid) & 0xFFFFFF) | (((tag) & 0xFF00) << 16)) : (uid))
13674 +#define TAGINO_GID(cond, gid, tag)     \
13675 +       ((cond) ? (((gid) & 0xFFFFFF) | (((tag) & 0x00FF) << 24)) : (gid))
13676 +
13677 +#endif
13678 +
13679 +
13680 +#ifdef CONFIG_TAGGING_UID16
13681 +
13682 +#define MAX_UID                0x0000FFFF
13683 +#define MAX_GID                0xFFFFFFFF
13684 +
13685 +#define INOTAG_TAG(cond, uid, gid, tag)        \
13686 +       ((cond) ? (((uid) >> 16) & 0xFFFF) : 0)
13687 +
13688 +#define TAGINO_UID(cond, uid, tag)     \
13689 +       ((cond) ? (((uid) & 0xFFFF) | ((tag) << 16)) : (uid))
13690 +#define TAGINO_GID(cond, gid, tag)     (gid)
13691 +
13692 +#endif
13693 +
13694 +
13695 +#ifdef CONFIG_TAGGING_INTERN
13696 +
13697 +#define MAX_UID                0xFFFFFFFF
13698 +#define MAX_GID                0xFFFFFFFF
13699 +
13700 +#define INOTAG_TAG(cond, uid, gid, tag)        \
13701 +       ((cond) ? (tag) : 0)
13702 +
13703 +#define TAGINO_UID(cond, uid, tag)     (uid)
13704 +#define TAGINO_GID(cond, gid, tag)     (gid)
13705 +
13706 +#endif
13707 +
13708 +
13709 +#ifndef CONFIG_TAGGING_NONE
13710 +#define dx_current_fstag(sb)   \
13711 +       ((sb)->s_flags & MS_TAGGED ? dx_current_tag() : 0)
13712 +#else
13713 +#define dx_current_fstag(sb)   (0)
13714 +#endif
13715 +
13716 +#ifndef CONFIG_TAGGING_INTERN
13717 +#define TAGINO_TAG(cond, tag)  (0)
13718 +#else
13719 +#define TAGINO_TAG(cond, tag)  ((cond) ? (tag) : 0)
13720 +#endif
13721 +
13722 +#define INOTAG_UID(cond, uid, gid)     \
13723 +       ((cond) ? ((uid) & MAX_UID) : (uid))
13724 +#define INOTAG_GID(cond, uid, gid)     \
13725 +       ((cond) ? ((gid) & MAX_GID) : (gid))
13726 +
13727 +
13728 +static inline uid_t dx_map_uid(uid_t uid)
13729 +{
13730 +       if ((uid > MAX_UID) && (uid != -1))
13731 +               uid = -2;
13732 +       return (uid & MAX_UID);
13733 +}
13734 +
13735 +static inline gid_t dx_map_gid(gid_t gid)
13736 +{
13737 +       if ((gid > MAX_GID) && (gid != -1))
13738 +               gid = -2;
13739 +       return (gid & MAX_GID);
13740 +}
13741 +
13742 +struct peer_tag {
13743 +       int32_t xid;
13744 +       int32_t nid;
13745 +};
13746 +
13747 +#define dx_notagcheck(sb) ((sb) && ((sb)->s_flags & MS_NOTAGCHECK))
13748 +
13749 +int dx_parse_tag(char *string, tag_t *tag, int remove, int *mnt_flags,
13750 +                unsigned long *flags);
13751 +
13752 +#ifdef CONFIG_PROPAGATE
13753 +
13754 +void __dx_propagate_tag(struct nameidata *nd, struct inode *inode);
13755 +
13756 +#define dx_propagate_tag(n, i) __dx_propagate_tag(n, i)
13757 +
13758 +#else
13759 +#define dx_propagate_tag(n, i) do { } while (0)
13760 +#endif
13761 +
13762 +#endif /* _DX_TAG_H */
13763 diff -NurpP --minimal linux-3.6.10/include/linux/vserver/tag_cmd.h linux-3.6.10-vs2.3.4.5/include/linux/vserver/tag_cmd.h
13764 --- linux-3.6.10/include/linux/vserver/tag_cmd.h        1970-01-01 01:00:00.000000000 +0100
13765 +++ linux-3.6.10-vs2.3.4.5/include/linux/vserver/tag_cmd.h      2012-10-04 18:47:00.000000000 +0200
13766 @@ -0,0 +1,22 @@
13767 +#ifndef _VX_TAG_CMD_H
13768 +#define _VX_TAG_CMD_H
13769 +
13770 +
13771 +/* vinfo commands */
13772 +
13773 +#define VCMD_task_tag          VC_CMD(VINFO, 3, 0)
13774 +
13775 +#ifdef __KERNEL__
13776 +extern int vc_task_tag(uint32_t);
13777 +
13778 +#endif /* __KERNEL__ */
13779 +
13780 +/* context commands */
13781 +
13782 +#define VCMD_tag_migrate       VC_CMD(TAGMIG, 1, 0)
13783 +
13784 +#ifdef __KERNEL__
13785 +extern int vc_tag_migrate(uint32_t);
13786 +
13787 +#endif /* __KERNEL__ */
13788 +#endif /* _VX_TAG_CMD_H */
13789 diff -NurpP --minimal linux-3.6.10/include/net/addrconf.h linux-3.6.10-vs2.3.4.5/include/net/addrconf.h
13790 --- linux-3.6.10/include/net/addrconf.h 2012-10-04 15:27:47.000000000 +0200
13791 +++ linux-3.6.10-vs2.3.4.5/include/net/addrconf.h       2012-10-04 18:47:00.000000000 +0200
13792 @@ -81,7 +81,8 @@ extern int                    ipv6_dev_get_saddr(struct n
13793                                                struct net_device *dev,
13794                                                const struct in6_addr *daddr,
13795                                                unsigned int srcprefs,
13796 -                                              struct in6_addr *saddr);
13797 +                                              struct in6_addr *saddr,
13798 +                                              struct nx_info *nxi);
13799  extern int                     ipv6_get_lladdr(struct net_device *dev,
13800                                                 struct in6_addr *addr,
13801                                                 unsigned char banned_flags);
13802 diff -NurpP --minimal linux-3.6.10/include/net/af_unix.h linux-3.6.10-vs2.3.4.5/include/net/af_unix.h
13803 --- linux-3.6.10/include/net/af_unix.h  2012-10-04 15:27:47.000000000 +0200
13804 +++ linux-3.6.10-vs2.3.4.5/include/net/af_unix.h        2012-10-04 18:47:00.000000000 +0200
13805 @@ -4,6 +4,7 @@
13806  #include <linux/socket.h>
13807  #include <linux/un.h>
13808  #include <linux/mutex.h>
13809 +#include <linux/vs_base.h>
13810  #include <net/sock.h>
13811  
13812  extern void unix_inflight(struct file *fp);
13813 diff -NurpP --minimal linux-3.6.10/include/net/inet_timewait_sock.h linux-3.6.10-vs2.3.4.5/include/net/inet_timewait_sock.h
13814 --- linux-3.6.10/include/net/inet_timewait_sock.h       2012-03-19 19:47:29.000000000 +0100
13815 +++ linux-3.6.10-vs2.3.4.5/include/net/inet_timewait_sock.h     2012-10-04 18:47:00.000000000 +0200
13816 @@ -112,6 +112,10 @@ struct inet_timewait_sock {
13817  #define tw_net                 __tw_common.skc_net
13818  #define tw_daddr               __tw_common.skc_daddr
13819  #define tw_rcv_saddr           __tw_common.skc_rcv_saddr
13820 +#define tw_xid                 __tw_common.skc_xid
13821 +#define tw_vx_info             __tw_common.skc_vx_info
13822 +#define tw_nid                 __tw_common.skc_nid
13823 +#define tw_nx_info             __tw_common.skc_nx_info
13824         int                     tw_timeout;
13825         volatile unsigned char  tw_substate;
13826         unsigned char           tw_rcv_wscale;
13827 diff -NurpP --minimal linux-3.6.10/include/net/ip6_route.h linux-3.6.10-vs2.3.4.5/include/net/ip6_route.h
13828 --- linux-3.6.10/include/net/ip6_route.h        2012-10-04 15:27:47.000000000 +0200
13829 +++ linux-3.6.10-vs2.3.4.5/include/net/ip6_route.h      2012-10-04 18:47:00.000000000 +0200
13830 @@ -97,7 +97,8 @@ extern int                    ip6_route_get_saddr(struct 
13831                                                     struct rt6_info *rt,
13832                                                     const struct in6_addr *daddr,
13833                                                     unsigned int prefs,
13834 -                                                   struct in6_addr *saddr);
13835 +                                                   struct in6_addr *saddr,
13836 +                                                   struct nx_info *nxi);
13837  
13838  extern struct rt6_info         *rt6_lookup(struct net *net,
13839                                             const struct in6_addr *daddr,
13840 diff -NurpP --minimal linux-3.6.10/include/net/route.h linux-3.6.10-vs2.3.4.5/include/net/route.h
13841 --- linux-3.6.10/include/net/route.h    2012-12-11 12:36:59.000000000 +0100
13842 +++ linux-3.6.10-vs2.3.4.5/include/net/route.h  2012-11-06 18:43:41.000000000 +0100
13843 @@ -204,6 +204,9 @@ static inline void ip_rt_put(struct rtab
13844                 dst_release(&rt->dst);
13845  }
13846  
13847 +#include <linux/vs_base.h>
13848 +#include <linux/vs_inet.h>
13849 +
13850  #define IPTOS_RT_MASK  (IPTOS_TOS_MASK & ~3)
13851  
13852  extern const __u8 ip_tos2prio[16];
13853 @@ -253,6 +256,9 @@ static inline void ip_route_connect_init
13854                            protocol, flow_flags, dst, src, dport, sport);
13855  }
13856  
13857 +extern struct rtable *ip_v4_find_src(struct net *net, struct nx_info *,
13858 +       struct flowi4 *);
13859 +
13860  static inline struct rtable *ip_route_connect(struct flowi4 *fl4,
13861                                               __be32 dst, __be32 src, u32 tos,
13862                                               int oif, u8 protocol,
13863 @@ -261,11 +267,25 @@ static inline struct rtable *ip_route_co
13864  {
13865         struct net *net = sock_net(sk);
13866         struct rtable *rt;
13867 +       struct nx_info *nx_info = current_nx_info();
13868  
13869         ip_route_connect_init(fl4, dst, src, tos, oif, protocol,
13870                               sport, dport, sk, can_sleep);
13871  
13872 -       if (!dst || !src) {
13873 +       if (sk)
13874 +               nx_info = sk->sk_nx_info;
13875 +
13876 +       vxdprintk(VXD_CBIT(net, 4),
13877 +               "ip_route_connect(%p) %p,%p;%lx",
13878 +               sk, nx_info, sk->sk_socket,
13879 +               (sk->sk_socket?sk->sk_socket->flags:0));
13880 +
13881 +       rt = ip_v4_find_src(net, nx_info, fl4);
13882 +       if (IS_ERR(rt))
13883 +               return rt;
13884 +       ip_rt_put(rt);
13885 +
13886 +       if (!fl4->daddr || !fl4->saddr) {
13887                 rt = __ip_route_output_key(net, fl4);
13888                 if (IS_ERR(rt))
13889                         return rt;
13890 diff -NurpP --minimal linux-3.6.10/include/net/sock.h linux-3.6.10-vs2.3.4.5/include/net/sock.h
13891 --- linux-3.6.10/include/net/sock.h     2012-10-04 15:27:47.000000000 +0200
13892 +++ linux-3.6.10-vs2.3.4.5/include/net/sock.h   2012-10-04 18:47:00.000000000 +0200
13893 @@ -171,6 +171,10 @@ struct sock_common {
13894  #ifdef CONFIG_NET_NS
13895         struct net              *skc_net;
13896  #endif
13897 +       xid_t                   skc_xid;
13898 +       struct vx_info          *skc_vx_info;
13899 +       nid_t                   skc_nid;
13900 +       struct nx_info          *skc_nx_info;
13901         /*
13902          * fields between dontcopy_begin/dontcopy_end
13903          * are not copied in sock_copy()
13904 @@ -284,6 +288,10 @@ struct sock {
13905  #define sk_bind_node           __sk_common.skc_bind_node
13906  #define sk_prot                        __sk_common.skc_prot
13907  #define sk_net                 __sk_common.skc_net
13908 +#define sk_xid                 __sk_common.skc_xid
13909 +#define sk_vx_info             __sk_common.skc_vx_info
13910 +#define sk_nid                 __sk_common.skc_nid
13911 +#define sk_nx_info             __sk_common.skc_nx_info
13912         socket_lock_t           sk_lock;
13913         struct sk_buff_head     sk_receive_queue;
13914         /*
13915 diff -NurpP --minimal linux-3.6.10/init/Kconfig linux-3.6.10-vs2.3.4.5/init/Kconfig
13916 --- linux-3.6.10/init/Kconfig   2012-10-04 15:27:48.000000000 +0200
13917 +++ linux-3.6.10-vs2.3.4.5/init/Kconfig 2012-10-04 18:47:00.000000000 +0200
13918 @@ -624,6 +624,7 @@ config HAVE_UNSTABLE_SCHED_CLOCK
13919  menuconfig CGROUPS
13920         boolean "Control Group support"
13921         depends on EVENTFD
13922 +       default y
13923         help
13924           This option adds support for grouping sets of processes together, for
13925           use with process control subsystems such as Cpusets, CFS, memory
13926 @@ -889,6 +890,7 @@ config USER_NS
13927         bool "User namespace (EXPERIMENTAL)"
13928         depends on EXPERIMENTAL
13929         depends on UIDGID_CONVERTED
13930 +       depends on VSERVER_DISABLED
13931         select UIDGID_STRICT_TYPE_CHECKS
13932  
13933         default n
13934 diff -NurpP --minimal linux-3.6.10/init/main.c linux-3.6.10-vs2.3.4.5/init/main.c
13935 --- linux-3.6.10/init/main.c    2012-12-11 12:36:59.000000000 +0100
13936 +++ linux-3.6.10-vs2.3.4.5/init/main.c  2012-11-06 18:43:41.000000000 +0100
13937 @@ -69,6 +69,7 @@
13938  #include <linux/slab.h>
13939  #include <linux/perf_event.h>
13940  #include <linux/file.h>
13941 +#include <linux/vserver/percpu.h>
13942  
13943  #include <asm/io.h>
13944  #include <asm/bugs.h>
13945 diff -NurpP --minimal linux-3.6.10/ipc/mqueue.c linux-3.6.10-vs2.3.4.5/ipc/mqueue.c
13946 --- linux-3.6.10/ipc/mqueue.c   2012-10-04 15:27:48.000000000 +0200
13947 +++ linux-3.6.10-vs2.3.4.5/ipc/mqueue.c 2012-10-04 18:47:00.000000000 +0200
13948 @@ -35,6 +35,8 @@
13949  #include <linux/ipc_namespace.h>
13950  #include <linux/user_namespace.h>
13951  #include <linux/slab.h>
13952 +#include <linux/vs_context.h>
13953 +#include <linux/vs_limit.h>
13954  
13955  #include <net/sock.h>
13956  #include "util.h"
13957 @@ -76,6 +78,7 @@ struct mqueue_inode_info {
13958         struct pid* notify_owner;
13959         struct user_namespace *notify_user_ns;
13960         struct user_struct *user;       /* user who created, for accounting */
13961 +       struct vx_info *vxi;
13962         struct sock *notify_sock;
13963         struct sk_buff *notify_cookie;
13964  
13965 @@ -235,6 +238,7 @@ static struct inode *mqueue_get_inode(st
13966         if (S_ISREG(mode)) {
13967                 struct mqueue_inode_info *info;
13968                 unsigned long mq_bytes, mq_treesize;
13969 +               struct vx_info *vxi = current_vx_info();
13970  
13971                 inode->i_fop = &mqueue_file_operations;
13972                 inode->i_size = FILENT_SIZE;
13973 @@ -248,6 +252,7 @@ static struct inode *mqueue_get_inode(st
13974                 info->notify_user_ns = NULL;
13975                 info->qsize = 0;
13976                 info->user = NULL;      /* set when all is ok */
13977 +               info->vxi = NULL;
13978                 info->msg_tree = RB_ROOT;
13979                 info->node_cache = NULL;
13980                 memset(&info->attr, 0, sizeof(info->attr));
13981 @@ -281,17 +286,20 @@ static struct inode *mqueue_get_inode(st
13982  
13983                 spin_lock(&mq_lock);
13984                 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
13985 -                   u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE)) {
13986 +                   u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE) ||
13987 +                   !vx_ipcmsg_avail(vxi, mq_bytes)) {
13988                         spin_unlock(&mq_lock);
13989                         /* mqueue_evict_inode() releases info->messages */
13990                         ret = -EMFILE;
13991                         goto out_inode;
13992                 }
13993                 u->mq_bytes += mq_bytes;
13994 +               vx_ipcmsg_add(vxi, u, mq_bytes);
13995                 spin_unlock(&mq_lock);
13996  
13997                 /* all is ok */
13998                 info->user = get_uid(u);
13999 +               info->vxi = get_vx_info(vxi);
14000         } else if (S_ISDIR(mode)) {
14001                 inc_nlink(inode);
14002                 /* Some things misbehave if size == 0 on a directory */
14003 @@ -395,8 +403,11 @@ static void mqueue_evict_inode(struct in
14004  
14005         user = info->user;
14006         if (user) {
14007 +               struct vx_info *vxi = info->vxi;
14008 +
14009                 spin_lock(&mq_lock);
14010                 user->mq_bytes -= mq_bytes;
14011 +               vx_ipcmsg_sub(vxi, user, mq_bytes);
14012                 /*
14013                  * get_ns_from_inode() ensures that the
14014                  * (ipc_ns = sb->s_fs_info) is either a valid ipc_ns
14015 @@ -406,6 +417,7 @@ static void mqueue_evict_inode(struct in
14016                 if (ipc_ns)
14017                         ipc_ns->mq_queues_count--;
14018                 spin_unlock(&mq_lock);
14019 +               put_vx_info(vxi);
14020                 free_uid(user);
14021         }
14022         if (ipc_ns)
14023 diff -NurpP --minimal linux-3.6.10/ipc/msg.c linux-3.6.10-vs2.3.4.5/ipc/msg.c
14024 --- linux-3.6.10/ipc/msg.c      2011-05-22 16:17:59.000000000 +0200
14025 +++ linux-3.6.10-vs2.3.4.5/ipc/msg.c    2012-10-04 18:47:00.000000000 +0200
14026 @@ -37,6 +37,7 @@
14027  #include <linux/rwsem.h>
14028  #include <linux/nsproxy.h>
14029  #include <linux/ipc_namespace.h>
14030 +#include <linux/vs_base.h>
14031  
14032  #include <asm/current.h>
14033  #include <asm/uaccess.h>
14034 @@ -190,6 +191,7 @@ static int newque(struct ipc_namespace *
14035  
14036         msq->q_perm.mode = msgflg & S_IRWXUGO;
14037         msq->q_perm.key = key;
14038 +       msq->q_perm.xid = vx_current_xid();
14039  
14040         msq->q_perm.security = NULL;
14041         retval = security_msg_queue_alloc(msq);
14042 diff -NurpP --minimal linux-3.6.10/ipc/namespace.c linux-3.6.10-vs2.3.4.5/ipc/namespace.c
14043 --- linux-3.6.10/ipc/namespace.c        2012-07-22 23:39:46.000000000 +0200
14044 +++ linux-3.6.10-vs2.3.4.5/ipc/namespace.c      2012-10-04 18:47:00.000000000 +0200
14045 @@ -13,11 +13,12 @@
14046  #include <linux/mount.h>
14047  #include <linux/user_namespace.h>
14048  #include <linux/proc_fs.h>
14049 +#include <linux/vs_base.h>
14050 +#include <linux/vserver/global.h>
14051  
14052  #include "util.h"
14053  
14054 -static struct ipc_namespace *create_ipc_ns(struct task_struct *tsk,
14055 -                                          struct ipc_namespace *old_ns)
14056 +static struct ipc_namespace *create_ipc_ns(struct user_namespace *user_ns)
14057  {
14058         struct ipc_namespace *ns;
14059         int err;
14060 @@ -46,19 +47,19 @@ static struct ipc_namespace *create_ipc_
14061         ipcns_notify(IPCNS_CREATED);
14062         register_ipcns_notifier(ns);
14063  
14064 -       ns->user_ns = get_user_ns(task_cred_xxx(tsk, user_ns));
14065 +       // ns->user_ns = get_user_ns(task_cred_xxx(tsk, user_ns));
14066 +       ns->user_ns = get_user_ns(user_ns);
14067  
14068         return ns;
14069  }
14070  
14071  struct ipc_namespace *copy_ipcs(unsigned long flags,
14072 -                               struct task_struct *tsk)
14073 +                               struct ipc_namespace *old_ns,
14074 +                               struct user_namespace *user_ns)
14075  {
14076 -       struct ipc_namespace *ns = tsk->nsproxy->ipc_ns;
14077 -
14078         if (!(flags & CLONE_NEWIPC))
14079 -               return get_ipc_ns(ns);
14080 -       return create_ipc_ns(tsk, ns);
14081 +               return get_ipc_ns(old_ns);
14082 +       return create_ipc_ns(user_ns);
14083  }
14084  
14085  /*
14086 diff -NurpP --minimal linux-3.6.10/ipc/sem.c linux-3.6.10-vs2.3.4.5/ipc/sem.c
14087 --- linux-3.6.10/ipc/sem.c      2012-01-09 16:14:59.000000000 +0100
14088 +++ linux-3.6.10-vs2.3.4.5/ipc/sem.c    2012-10-04 18:47:00.000000000 +0200
14089 @@ -86,6 +86,8 @@
14090  #include <linux/rwsem.h>
14091  #include <linux/nsproxy.h>
14092  #include <linux/ipc_namespace.h>
14093 +#include <linux/vs_base.h>
14094 +#include <linux/vs_limit.h>
14095  
14096  #include <asm/uaccess.h>
14097  #include "util.h"
14098 @@ -306,6 +308,7 @@ static int newary(struct ipc_namespace *
14099  
14100         sma->sem_perm.mode = (semflg & S_IRWXUGO);
14101         sma->sem_perm.key = key;
14102 +       sma->sem_perm.xid = vx_current_xid();
14103  
14104         sma->sem_perm.security = NULL;
14105         retval = security_sem_alloc(sma);
14106 @@ -321,6 +324,9 @@ static int newary(struct ipc_namespace *
14107                 return id;
14108         }
14109         ns->used_sems += nsems;
14110 +       /* FIXME: obsoleted? */
14111 +       vx_semary_inc(sma);
14112 +       vx_nsems_add(sma, nsems);
14113  
14114         sma->sem_base = (struct sem *) &sma[1];
14115  
14116 @@ -770,6 +776,9 @@ static void freeary(struct ipc_namespace
14117  
14118         wake_up_sem_queue_do(&tasks);
14119         ns->used_sems -= sma->sem_nsems;
14120 +       /* FIXME: obsoleted? */
14121 +       vx_nsems_sub(sma, sma->sem_nsems);
14122 +       vx_semary_dec(sma);
14123         security_sem_free(sma);
14124         ipc_rcu_putref(sma);
14125  }
14126 diff -NurpP --minimal linux-3.6.10/ipc/shm.c linux-3.6.10-vs2.3.4.5/ipc/shm.c
14127 --- linux-3.6.10/ipc/shm.c      2012-10-04 15:27:48.000000000 +0200
14128 +++ linux-3.6.10-vs2.3.4.5/ipc/shm.c    2012-10-04 18:47:00.000000000 +0200
14129 @@ -39,6 +39,8 @@
14130  #include <linux/nsproxy.h>
14131  #include <linux/mount.h>
14132  #include <linux/ipc_namespace.h>
14133 +#include <linux/vs_context.h>
14134 +#include <linux/vs_limit.h>
14135  
14136  #include <asm/uaccess.h>
14137  
14138 @@ -187,7 +189,12 @@ static void shm_open(struct vm_area_stru
14139   */
14140  static void shm_destroy(struct ipc_namespace *ns, struct shmid_kernel *shp)
14141  {
14142 -       ns->shm_tot -= (shp->shm_segsz + PAGE_SIZE - 1) >> PAGE_SHIFT;
14143 +       struct vx_info *vxi = lookup_vx_info(shp->shm_perm.xid);
14144 +       int numpages = (shp->shm_segsz + PAGE_SIZE - 1) >> PAGE_SHIFT;
14145 +
14146 +       vx_ipcshm_sub(vxi, shp, numpages);
14147 +       ns->shm_tot -= numpages;
14148 +
14149         shm_rmid(ns, shp);
14150         shm_unlock(shp);
14151         if (!is_file_hugepages(shp->shm_file))
14152 @@ -197,6 +204,7 @@ static void shm_destroy(struct ipc_names
14153                                                 shp->mlock_user);
14154         fput (shp->shm_file);
14155         security_shm_free(shp);
14156 +       put_vx_info(vxi);
14157         ipc_rcu_putref(shp);
14158  }
14159  
14160 @@ -474,11 +482,15 @@ static int newseg(struct ipc_namespace *
14161         if (ns->shm_tot + numpages > ns->shm_ctlall)
14162                 return -ENOSPC;
14163  
14164 +       if (!vx_ipcshm_avail(current_vx_info(), numpages))
14165 +               return -ENOSPC;
14166 +
14167         shp = ipc_rcu_alloc(sizeof(*shp));
14168         if (!shp)
14169                 return -ENOMEM;
14170  
14171         shp->shm_perm.key = key;
14172 +       shp->shm_perm.xid = vx_current_xid();
14173         shp->shm_perm.mode = (shmflg & S_IRWXUGO);
14174         shp->mlock_user = NULL;
14175  
14176 @@ -533,6 +545,7 @@ static int newseg(struct ipc_namespace *
14177         ns->shm_tot += numpages;
14178         error = shp->shm_perm.id;
14179         shm_unlock(shp);
14180 +       vx_ipcshm_add(current_vx_info(), key, numpages);
14181         return error;
14182  
14183  no_id:
14184 diff -NurpP --minimal linux-3.6.10/kernel/Makefile linux-3.6.10-vs2.3.4.5/kernel/Makefile
14185 --- linux-3.6.10/kernel/Makefile        2012-07-22 23:39:46.000000000 +0200
14186 +++ linux-3.6.10-vs2.3.4.5/kernel/Makefile      2012-10-04 18:47:00.000000000 +0200
14187 @@ -24,6 +24,7 @@ endif
14188  
14189  obj-y += sched/
14190  obj-y += power/
14191 +obj-y += vserver/
14192  
14193  ifeq ($(CONFIG_CHECKPOINT_RESTORE),y)
14194  obj-$(CONFIG_X86) += kcmp.o
14195 diff -NurpP --minimal linux-3.6.10/kernel/auditsc.c linux-3.6.10-vs2.3.4.5/kernel/auditsc.c
14196 --- linux-3.6.10/kernel/auditsc.c       2012-07-22 23:39:46.000000000 +0200
14197 +++ linux-3.6.10-vs2.3.4.5/kernel/auditsc.c     2012-10-04 18:47:00.000000000 +0200
14198 @@ -2309,7 +2309,7 @@ int audit_set_loginuid(uid_t loginuid)
14199         if (task->loginuid != -1)
14200                 return -EPERM;
14201  #else /* CONFIG_AUDIT_LOGINUID_IMMUTABLE */
14202 -       if (!capable(CAP_AUDIT_CONTROL))
14203 +       if (!vx_capable(CAP_AUDIT_CONTROL, VXC_AUDIT_CONTROL))
14204                 return -EPERM;
14205  #endif  /* CONFIG_AUDIT_LOGINUID_IMMUTABLE */
14206  
14207 diff -NurpP --minimal linux-3.6.10/kernel/capability.c linux-3.6.10-vs2.3.4.5/kernel/capability.c
14208 --- linux-3.6.10/kernel/capability.c    2012-07-22 23:39:46.000000000 +0200
14209 +++ linux-3.6.10-vs2.3.4.5/kernel/capability.c  2012-10-04 18:47:00.000000000 +0200
14210 @@ -15,6 +15,7 @@
14211  #include <linux/syscalls.h>
14212  #include <linux/pid_namespace.h>
14213  #include <linux/user_namespace.h>
14214 +#include <linux/vs_context.h>
14215  #include <asm/uaccess.h>
14216  
14217  /*
14218 @@ -116,6 +117,7 @@ static int cap_validate_magic(cap_user_h
14219         return 0;
14220  }
14221  
14222 +
14223  /*
14224   * The only thing that can change the capabilities of the current
14225   * process is the current process. As such, we can't be in this code
14226 @@ -349,6 +351,8 @@ bool has_ns_capability_noaudit(struct ta
14227         return (ret == 0);
14228  }
14229  
14230 +#include <linux/vserver/base.h>
14231 +
14232  /**
14233   * has_capability_noaudit - Does a task have a capability (unaudited) in the
14234   * initial user ns
14235 diff -NurpP --minimal linux-3.6.10/kernel/compat.c linux-3.6.10-vs2.3.4.5/kernel/compat.c
14236 --- linux-3.6.10/kernel/compat.c        2012-07-22 23:39:46.000000000 +0200
14237 +++ linux-3.6.10-vs2.3.4.5/kernel/compat.c      2012-10-04 18:47:00.000000000 +0200
14238 @@ -1054,7 +1054,7 @@ asmlinkage long compat_sys_stime(compat_
14239         if (err)
14240                 return err;
14241  
14242 -       do_settimeofday(&tv);
14243 +       vx_settimeofday(&tv);
14244         return 0;
14245  }
14246  
14247 diff -NurpP --minimal linux-3.6.10/kernel/cred.c linux-3.6.10-vs2.3.4.5/kernel/cred.c
14248 --- linux-3.6.10/kernel/cred.c  2012-07-22 23:39:46.000000000 +0200
14249 +++ linux-3.6.10-vs2.3.4.5/kernel/cred.c        2012-10-04 18:47:00.000000000 +0200
14250 @@ -70,31 +70,6 @@ struct cred init_cred = {
14251  #endif
14252  };
14253  
14254 -static inline void set_cred_subscribers(struct cred *cred, int n)
14255 -{
14256 -#ifdef CONFIG_DEBUG_CREDENTIALS
14257 -       atomic_set(&cred->subscribers, n);
14258 -#endif
14259 -}
14260 -
14261 -static inline int read_cred_subscribers(const struct cred *cred)
14262 -{
14263 -#ifdef CONFIG_DEBUG_CREDENTIALS
14264 -       return atomic_read(&cred->subscribers);
14265 -#else
14266 -       return 0;
14267 -#endif
14268 -}
14269 -
14270 -static inline void alter_cred_subscribers(const struct cred *_cred, int n)
14271 -{
14272 -#ifdef CONFIG_DEBUG_CREDENTIALS
14273 -       struct cred *cred = (struct cred *) _cred;
14274 -
14275 -       atomic_add(n, &cred->subscribers);
14276 -#endif
14277 -}
14278 -
14279  /*
14280   * Dispose of the shared task group credentials
14281   */
14282 @@ -284,21 +259,16 @@ error:
14283   *
14284   * Call commit_creds() or abort_creds() to clean up.
14285   */
14286 -struct cred *prepare_creds(void)
14287 +struct cred *__prepare_creds(const struct cred *old)
14288  {
14289 -       struct task_struct *task = current;
14290 -       const struct cred *old;
14291         struct cred *new;
14292  
14293 -       validate_process_creds();
14294 -
14295         new = kmem_cache_alloc(cred_jar, GFP_KERNEL);
14296         if (!new)
14297                 return NULL;
14298  
14299         kdebug("prepare_creds() alloc %p", new);
14300  
14301 -       old = task->cred;
14302         memcpy(new, old, sizeof(struct cred));
14303  
14304         atomic_set(&new->usage, 1);
14305 @@ -326,6 +296,13 @@ error:
14306         abort_creds(new);
14307         return NULL;
14308  }
14309 +
14310 +struct cred *prepare_creds(void)
14311 +{
14312 +       validate_process_creds();
14313 +
14314 +       return __prepare_creds(current->cred);
14315 +}
14316  EXPORT_SYMBOL(prepare_creds);
14317  
14318  /*
14319 diff -NurpP --minimal linux-3.6.10/kernel/exit.c linux-3.6.10-vs2.3.4.5/kernel/exit.c
14320 --- linux-3.6.10/kernel/exit.c  2012-10-04 15:27:48.000000000 +0200
14321 +++ linux-3.6.10-vs2.3.4.5/kernel/exit.c        2012-12-08 01:20:39.000000000 +0100
14322 @@ -48,6 +48,10 @@
14323  #include <linux/fs_struct.h>
14324  #include <linux/init_task.h>
14325  #include <linux/perf_event.h>
14326 +#include <linux/vs_limit.h>
14327 +#include <linux/vs_context.h>
14328 +#include <linux/vs_network.h>
14329 +#include <linux/vs_pid.h>
14330  #include <trace/events/sched.h>
14331  #include <linux/hw_breakpoint.h>
14332  #include <linux/oom.h>
14333 @@ -494,9 +498,11 @@ static void close_files(struct files_str
14334                                         filp_close(file, files);
14335                                         cond_resched();
14336                                 }
14337 +                               vx_openfd_dec(i);
14338                         }
14339                         i++;
14340                         set >>= 1;
14341 +                       cond_resched();
14342                 }
14343         }
14344  }
14345 @@ -711,15 +717,25 @@ static struct task_struct *find_new_reap
14346         __acquires(&tasklist_lock)
14347  {
14348         struct pid_namespace *pid_ns = task_active_pid_ns(father);
14349 -       struct task_struct *thread;
14350 +       struct vx_info *vxi = task_get_vx_info(father);
14351 +       struct task_struct *thread = father;
14352 +       struct task_struct *reaper;
14353  
14354 -       thread = father;
14355         while_each_thread(father, thread) {
14356                 if (thread->flags & PF_EXITING)
14357                         continue;
14358                 if (unlikely(pid_ns->child_reaper == father))
14359                         pid_ns->child_reaper = thread;
14360 -               return thread;
14361 +               reaper = thread;
14362 +               goto out_put;
14363 +       }
14364 +
14365 +       reaper = pid_ns->child_reaper;
14366 +       if (vxi) {
14367 +               BUG_ON(!vxi->vx_reaper);
14368 +               if (vxi->vx_reaper != init_pid_ns.child_reaper &&
14369 +                   vxi->vx_reaper != father)
14370 +                       reaper = vxi->vx_reaper;
14371         }
14372  
14373         if (unlikely(pid_ns->child_reaper == father)) {
14374 @@ -757,7 +773,9 @@ static struct task_struct *find_new_reap
14375                 }
14376         }
14377  
14378 -       return pid_ns->child_reaper;
14379 +out_put:
14380 +       put_vx_info(vxi);
14381 +       return reaper;
14382  }
14383  
14384  /*
14385 @@ -808,10 +826,15 @@ static void forget_original_parent(struc
14386         list_for_each_entry_safe(p, n, &father->children, sibling) {
14387                 struct task_struct *t = p;
14388                 do {
14389 -                       t->real_parent = reaper;
14390 +                       struct task_struct *new_parent = reaper;
14391 +
14392 +                       if (unlikely(p == reaper))
14393 +                               new_parent = task_active_pid_ns(p)->child_reaper;
14394 +
14395 +                       t->real_parent = new_parent;
14396                         if (t->parent == father) {
14397                                 BUG_ON(t->ptrace);
14398 -                               t->parent = t->real_parent;
14399 +                               t->parent = new_parent;
14400                         }
14401                         if (t->pdeath_signal)
14402                                 group_send_sig_info(t->pdeath_signal,
14403 @@ -1018,6 +1041,9 @@ void do_exit(long code)
14404          */
14405         ptrace_put_breakpoints(tsk);
14406  
14407 +       /* needs to stay before exit_notify() */
14408 +       exit_vx_info_early(tsk, code);
14409 +
14410         exit_notify(tsk, group_dead);
14411  #ifdef CONFIG_NUMA
14412         task_lock(tsk);
14413 @@ -1068,10 +1094,15 @@ void do_exit(long code)
14414         smp_mb();
14415         raw_spin_unlock_wait(&tsk->pi_lock);
14416  
14417 +       /* needs to stay after exit_notify() */
14418 +       exit_vx_info(tsk, code);
14419 +       exit_nx_info(tsk);
14420 +
14421         /* causes final put_task_struct in finish_task_switch(). */
14422         tsk->state = TASK_DEAD;
14423         tsk->flags |= PF_NOFREEZE;      /* tell freezer to ignore us */
14424         schedule();
14425 +       printk("bad task: %p [%lx]\n", current, current->state);
14426         BUG();
14427         /* Avoid "noreturn function does return".  */
14428         for (;;)
14429 diff -NurpP --minimal linux-3.6.10/kernel/fork.c linux-3.6.10-vs2.3.4.5/kernel/fork.c
14430 --- linux-3.6.10/kernel/fork.c  2012-10-04 15:27:48.000000000 +0200
14431 +++ linux-3.6.10-vs2.3.4.5/kernel/fork.c        2012-10-04 18:47:00.000000000 +0200
14432 @@ -70,6 +70,9 @@
14433  #include <linux/khugepaged.h>
14434  #include <linux/signalfd.h>
14435  #include <linux/uprobes.h>
14436 +#include <linux/vs_context.h>
14437 +#include <linux/vs_network.h>
14438 +#include <linux/vs_limit.h>
14439  
14440  #include <asm/pgtable.h>
14441  #include <asm/pgalloc.h>
14442 @@ -210,6 +213,8 @@ void free_task(struct task_struct *tsk)
14443         arch_release_thread_info(tsk->stack);
14444         free_thread_info(tsk->stack);
14445         rt_mutex_debug_task_free(tsk);
14446 +       clr_vx_info(&tsk->vx_info);
14447 +       clr_nx_info(&tsk->nx_info);
14448         ftrace_graph_exit_task(tsk);
14449         put_seccomp_filter(tsk);
14450         arch_release_task_struct(tsk);
14451 @@ -541,6 +546,7 @@ static struct mm_struct *mm_init(struct 
14452         if (likely(!mm_alloc_pgd(mm))) {
14453                 mm->def_flags = 0;
14454                 mmu_notifier_mm_init(mm);
14455 +               set_vx_info(&mm->mm_vx_info, p->vx_info);
14456                 return mm;
14457         }
14458  
14459 @@ -593,6 +599,7 @@ void __mmdrop(struct mm_struct *mm)
14460         destroy_context(mm);
14461         mmu_notifier_mm_destroy(mm);
14462         check_mm(mm);
14463 +       clr_vx_info(&mm->mm_vx_info);
14464         free_mm(mm);
14465  }
14466  EXPORT_SYMBOL_GPL(__mmdrop);
14467 @@ -834,6 +841,7 @@ struct mm_struct *dup_mm(struct task_str
14468                 goto fail_nomem;
14469  
14470         memcpy(mm, oldmm, sizeof(*mm));
14471 +       mm->mm_vx_info = NULL;
14472         mm_init_cpumask(mm);
14473  
14474  #ifdef CONFIG_TRANSPARENT_HUGEPAGE
14475 @@ -874,6 +882,7 @@ fail_nocontext:
14476          * If init_new_context() failed, we cannot use mmput() to free the mm
14477          * because it calls destroy_context()
14478          */
14479 +       clr_vx_info(&mm->mm_vx_info);
14480         mm_free_pgd(mm);
14481         free_mm(mm);
14482         return NULL;
14483 @@ -1157,6 +1166,8 @@ static struct task_struct *copy_process(
14484         int retval;
14485         struct task_struct *p;
14486         int cgroup_callbacks_done = 0;
14487 +       struct vx_info *vxi;
14488 +       struct nx_info *nxi;
14489  
14490         if ((clone_flags & (CLONE_NEWNS|CLONE_FS)) == (CLONE_NEWNS|CLONE_FS))
14491                 return ERR_PTR(-EINVAL);
14492 @@ -1204,7 +1215,12 @@ static struct task_struct *copy_process(
14493         DEBUG_LOCKS_WARN_ON(!p->hardirqs_enabled);
14494         DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
14495  #endif
14496 +       init_vx_info(&p->vx_info, current_vx_info());
14497 +       init_nx_info(&p->nx_info, current_nx_info());
14498 +
14499         retval = -EAGAIN;
14500 +       if (!vx_nproc_avail(1))
14501 +               goto bad_fork_free;
14502         if (atomic_read(&p->real_cred->user->processes) >=
14503                         task_rlimit(p, RLIMIT_NPROC)) {
14504                 if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE) &&
14505 @@ -1483,6 +1499,18 @@ static struct task_struct *copy_process(
14506  
14507         total_forks++;
14508         spin_unlock(&current->sighand->siglock);
14509 +
14510 +       /* p is copy of current */
14511 +       vxi = p->vx_info;
14512 +       if (vxi) {
14513 +               claim_vx_info(vxi, p);
14514 +               atomic_inc(&vxi->cvirt.nr_threads);
14515 +               atomic_inc(&vxi->cvirt.total_forks);
14516 +               vx_nproc_inc(p);
14517 +       }
14518 +       nxi = p->nx_info;
14519 +       if (nxi)
14520 +               claim_nx_info(nxi, p);
14521         write_unlock_irq(&tasklist_lock);
14522         proc_fork_connector(p);
14523         cgroup_post_fork(p);
14524 diff -NurpP --minimal linux-3.6.10/kernel/kthread.c linux-3.6.10-vs2.3.4.5/kernel/kthread.c
14525 --- linux-3.6.10/kernel/kthread.c       2012-10-04 15:27:48.000000000 +0200
14526 +++ linux-3.6.10-vs2.3.4.5/kernel/kthread.c     2012-10-04 18:47:00.000000000 +0200
14527 @@ -16,6 +16,7 @@
14528  #include <linux/mutex.h>
14529  #include <linux/slab.h>
14530  #include <linux/freezer.h>
14531 +#include <linux/vs_pid.h>
14532  #include <trace/events/sched.h>
14533  
14534  static DEFINE_SPINLOCK(kthread_create_lock);
14535 diff -NurpP --minimal linux-3.6.10/kernel/nsproxy.c linux-3.6.10-vs2.3.4.5/kernel/nsproxy.c
14536 --- linux-3.6.10/kernel/nsproxy.c       2012-01-09 16:15:00.000000000 +0100
14537 +++ linux-3.6.10-vs2.3.4.5/kernel/nsproxy.c     2012-10-04 18:47:00.000000000 +0200
14538 @@ -20,11 +20,14 @@
14539  #include <linux/mnt_namespace.h>
14540  #include <linux/utsname.h>
14541  #include <linux/pid_namespace.h>
14542 +#include <linux/vserver/global.h>
14543 +#include <linux/vserver/debug.h>
14544  #include <net/net_namespace.h>
14545  #include <linux/ipc_namespace.h>
14546  #include <linux/proc_fs.h>
14547  #include <linux/file.h>
14548  #include <linux/syscalls.h>
14549 +#include "../fs/mount.h"
14550  
14551  static struct kmem_cache *nsproxy_cachep;
14552  
14553 @@ -46,8 +49,11 @@ static inline struct nsproxy *create_nsp
14554         struct nsproxy *nsproxy;
14555  
14556         nsproxy = kmem_cache_alloc(nsproxy_cachep, GFP_KERNEL);
14557 -       if (nsproxy)
14558 +       if (nsproxy) {
14559                 atomic_set(&nsproxy->count, 1);
14560 +               atomic_inc(&vs_global_nsproxy);
14561 +       }
14562 +       vxdprintk(VXD_CBIT(space, 2), "create_nsproxy = %p[1]", nsproxy);
14563         return nsproxy;
14564  }
14565  
14566 @@ -56,8 +62,11 @@ static inline struct nsproxy *create_nsp
14567   * Return the newly created nsproxy.  Do not attach this to the task,
14568   * leave it to the caller to do proper locking and attach it to task.
14569   */
14570 -static struct nsproxy *create_new_namespaces(unsigned long flags,
14571 -                       struct task_struct *tsk, struct fs_struct *new_fs)
14572 +static struct nsproxy *unshare_namespaces(unsigned long flags,
14573 +                       struct nsproxy *orig,
14574 +                       struct fs_struct *new_fs,
14575 +                       struct user_namespace *new_user,
14576 +                       struct pid_namespace *new_pid)
14577  {
14578         struct nsproxy *new_nsp;
14579         int err;
14580 @@ -66,31 +75,31 @@ static struct nsproxy *create_new_namesp
14581         if (!new_nsp)
14582                 return ERR_PTR(-ENOMEM);
14583  
14584 -       new_nsp->mnt_ns = copy_mnt_ns(flags, tsk->nsproxy->mnt_ns, new_fs);
14585 +       new_nsp->mnt_ns = copy_mnt_ns(flags, orig->mnt_ns, new_fs);
14586         if (IS_ERR(new_nsp->mnt_ns)) {
14587                 err = PTR_ERR(new_nsp->mnt_ns);
14588                 goto out_ns;
14589         }
14590  
14591 -       new_nsp->uts_ns = copy_utsname(flags, tsk);
14592 +       new_nsp->uts_ns = copy_utsname(flags, orig->uts_ns, new_user);
14593         if (IS_ERR(new_nsp->uts_ns)) {
14594                 err = PTR_ERR(new_nsp->uts_ns);
14595                 goto out_uts;
14596         }
14597  
14598 -       new_nsp->ipc_ns = copy_ipcs(flags, tsk);
14599 +       new_nsp->ipc_ns = copy_ipcs(flags, orig->ipc_ns, new_user);
14600         if (IS_ERR(new_nsp->ipc_ns)) {
14601                 err = PTR_ERR(new_nsp->ipc_ns);
14602                 goto out_ipc;
14603         }
14604  
14605 -       new_nsp->pid_ns = copy_pid_ns(flags, task_active_pid_ns(tsk));
14606 +       new_nsp->pid_ns = copy_pid_ns(flags, new_pid);
14607         if (IS_ERR(new_nsp->pid_ns)) {
14608                 err = PTR_ERR(new_nsp->pid_ns);
14609                 goto out_pid;
14610         }
14611  
14612 -       new_nsp->net_ns = copy_net_ns(flags, tsk->nsproxy->net_ns);
14613 +       new_nsp->net_ns = copy_net_ns(flags, orig->net_ns);
14614         if (IS_ERR(new_nsp->net_ns)) {
14615                 err = PTR_ERR(new_nsp->net_ns);
14616                 goto out_net;
14617 @@ -115,6 +124,40 @@ out_ns:
14618         return ERR_PTR(err);
14619  }
14620  
14621 +static struct nsproxy *create_new_namespaces(unsigned long flags,
14622 +                       struct task_struct *tsk, struct fs_struct *new_fs)
14623 +{
14624 +       return unshare_namespaces(flags, tsk->nsproxy,
14625 +               new_fs, task_cred_xxx(tsk, user_ns),
14626 +               task_active_pid_ns(tsk));
14627 +}
14628 +
14629 +/*
14630 + * copies the nsproxy, setting refcount to 1, and grabbing a
14631 + * reference to all contained namespaces.
14632 + */
14633 +struct nsproxy *copy_nsproxy(struct nsproxy *orig)
14634 +{
14635 +       struct nsproxy *ns = create_nsproxy();
14636 +
14637 +       if (ns) {
14638 +               memcpy(ns, orig, sizeof(struct nsproxy));
14639 +               atomic_set(&ns->count, 1);
14640 +
14641 +               if (ns->mnt_ns)
14642 +                       get_mnt_ns(ns->mnt_ns);
14643 +               if (ns->uts_ns)
14644 +                       get_uts_ns(ns->uts_ns);
14645 +               if (ns->ipc_ns)
14646 +                       get_ipc_ns(ns->ipc_ns);
14647 +               if (ns->pid_ns)
14648 +                       get_pid_ns(ns->pid_ns);
14649 +               if (ns->net_ns)
14650 +                       get_net(ns->net_ns);
14651 +       }
14652 +       return ns;
14653 +}
14654 +
14655  /*
14656   * called from clone.  This now handles copy for nsproxy and all
14657   * namespaces therein.
14658 @@ -122,9 +165,12 @@ out_ns:
14659  int copy_namespaces(unsigned long flags, struct task_struct *tsk)
14660  {
14661         struct nsproxy *old_ns = tsk->nsproxy;
14662 -       struct nsproxy *new_ns;
14663 +       struct nsproxy *new_ns = NULL;
14664         int err = 0;
14665  
14666 +       vxdprintk(VXD_CBIT(space, 7), "copy_namespaces(0x%08lx,%p[%p])",
14667 +               flags, tsk, old_ns);
14668 +
14669         if (!old_ns)
14670                 return 0;
14671  
14672 @@ -134,7 +180,7 @@ int copy_namespaces(unsigned long flags,
14673                                 CLONE_NEWPID | CLONE_NEWNET)))
14674                 return 0;
14675  
14676 -       if (!capable(CAP_SYS_ADMIN)) {
14677 +       if (!vx_can_unshare(CAP_SYS_ADMIN, flags)) {
14678                 err = -EPERM;
14679                 goto out;
14680         }
14681 @@ -161,6 +207,9 @@ int copy_namespaces(unsigned long flags,
14682  
14683  out:
14684         put_nsproxy(old_ns);
14685 +       vxdprintk(VXD_CBIT(space, 3),
14686 +               "copy_namespaces(0x%08lx,%p[%p]) = %d [%p]",
14687 +               flags, tsk, old_ns, err, new_ns);
14688         return err;
14689  }
14690  
14691 @@ -174,7 +223,9 @@ void free_nsproxy(struct nsproxy *ns)
14692                 put_ipc_ns(ns->ipc_ns);
14693         if (ns->pid_ns)
14694                 put_pid_ns(ns->pid_ns);
14695 -       put_net(ns->net_ns);
14696 +       if (ns->net_ns)
14697 +               put_net(ns->net_ns);
14698 +       atomic_dec(&vs_global_nsproxy);
14699         kmem_cache_free(nsproxy_cachep, ns);
14700  }
14701  
14702 @@ -187,11 +238,15 @@ int unshare_nsproxy_namespaces(unsigned 
14703  {
14704         int err = 0;
14705  
14706 +       vxdprintk(VXD_CBIT(space, 4),
14707 +               "unshare_nsproxy_namespaces(0x%08lx,[%p])",
14708 +               unshare_flags, current->nsproxy);
14709 +
14710         if (!(unshare_flags & (CLONE_NEWNS | CLONE_NEWUTS | CLONE_NEWIPC |
14711                                CLONE_NEWNET)))
14712                 return 0;
14713  
14714 -       if (!capable(CAP_SYS_ADMIN))
14715 +       if (!vx_can_unshare(CAP_SYS_ADMIN, unshare_flags))
14716                 return -EPERM;
14717  
14718         *new_nsp = create_new_namespaces(unshare_flags, current,
14719 diff -NurpP --minimal linux-3.6.10/kernel/pid.c linux-3.6.10-vs2.3.4.5/kernel/pid.c
14720 --- linux-3.6.10/kernel/pid.c   2012-07-22 23:39:46.000000000 +0200
14721 +++ linux-3.6.10-vs2.3.4.5/kernel/pid.c 2012-10-04 18:47:00.000000000 +0200
14722 @@ -36,6 +36,7 @@
14723  #include <linux/pid_namespace.h>
14724  #include <linux/init_task.h>
14725  #include <linux/syscalls.h>
14726 +#include <linux/vs_pid.h>
14727  
14728  #define pid_hashfn(nr, ns)     \
14729         hash_long((unsigned long)nr + (unsigned long)ns, pidhash_shift)
14730 @@ -344,7 +345,7 @@ EXPORT_SYMBOL_GPL(find_pid_ns);
14731  
14732  struct pid *find_vpid(int nr)
14733  {
14734 -       return find_pid_ns(nr, current->nsproxy->pid_ns);
14735 +       return find_pid_ns(vx_rmap_pid(nr), current->nsproxy->pid_ns);
14736  }
14737  EXPORT_SYMBOL_GPL(find_vpid);
14738  
14739 @@ -404,6 +405,9 @@ void transfer_pid(struct task_struct *ol
14740  struct task_struct *pid_task(struct pid *pid, enum pid_type type)
14741  {
14742         struct task_struct *result = NULL;
14743 +
14744 +       if (type == PIDTYPE_REALPID)
14745 +               type = PIDTYPE_PID;
14746         if (pid) {
14747                 struct hlist_node *first;
14748                 first = rcu_dereference_check(hlist_first_rcu(&pid->tasks[type]),
14749 @@ -423,7 +427,7 @@ struct task_struct *find_task_by_pid_ns(
14750         rcu_lockdep_assert(rcu_read_lock_held(),
14751                            "find_task_by_pid_ns() needs rcu_read_lock()"
14752                            " protection");
14753 -       return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
14754 +       return pid_task(find_pid_ns(vx_rmap_pid(nr), ns), PIDTYPE_PID);
14755  }
14756  
14757  struct task_struct *find_task_by_vpid(pid_t vnr)
14758 @@ -467,7 +471,7 @@ struct pid *find_get_pid(pid_t nr)
14759  }
14760  EXPORT_SYMBOL_GPL(find_get_pid);
14761  
14762 -pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns)
14763 +pid_t pid_unmapped_nr_ns(struct pid *pid, struct pid_namespace *ns)
14764  {
14765         struct upid *upid;
14766         pid_t nr = 0;
14767 @@ -480,6 +484,11 @@ pid_t pid_nr_ns(struct pid *pid, struct 
14768         return nr;
14769  }
14770  
14771 +pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns)
14772 +{
14773 +       return vx_map_pid(pid_unmapped_nr_ns(pid, ns));
14774 +}
14775 +
14776  pid_t pid_vnr(struct pid *pid)
14777  {
14778         return pid_nr_ns(pid, current->nsproxy->pid_ns);
14779 diff -NurpP --minimal linux-3.6.10/kernel/pid_namespace.c linux-3.6.10-vs2.3.4.5/kernel/pid_namespace.c
14780 --- linux-3.6.10/kernel/pid_namespace.c 2012-10-04 15:27:48.000000000 +0200
14781 +++ linux-3.6.10-vs2.3.4.5/kernel/pid_namespace.c       2012-10-04 18:47:00.000000000 +0200
14782 @@ -16,6 +16,7 @@
14783  #include <linux/slab.h>
14784  #include <linux/proc_fs.h>
14785  #include <linux/reboot.h>
14786 +#include <linux/vserver/global.h>
14787  
14788  #define BITS_PER_PAGE          (PAGE_SIZE*8)
14789  
14790 @@ -89,6 +90,7 @@ static struct pid_namespace *create_pid_
14791                 goto out_free_map;
14792  
14793         kref_init(&ns->kref);
14794 +       atomic_inc(&vs_global_pid_ns);
14795         ns->level = level;
14796         ns->parent = get_pid_ns(parent_pid_ns);
14797  
14798 @@ -120,6 +122,7 @@ static void destroy_pid_namespace(struct
14799  
14800         for (i = 0; i < PIDMAP_ENTRIES; i++)
14801                 kfree(ns->pidmap[i].page);
14802 +       atomic_dec(&vs_global_pid_ns);
14803         kmem_cache_free(pid_ns_cachep, ns);
14804  }
14805  
14806 diff -NurpP --minimal linux-3.6.10/kernel/posix-timers.c linux-3.6.10-vs2.3.4.5/kernel/posix-timers.c
14807 --- linux-3.6.10/kernel/posix-timers.c  2012-01-09 16:15:00.000000000 +0100
14808 +++ linux-3.6.10-vs2.3.4.5/kernel/posix-timers.c        2012-10-04 18:47:00.000000000 +0200
14809 @@ -47,6 +47,7 @@
14810  #include <linux/wait.h>
14811  #include <linux/workqueue.h>
14812  #include <linux/export.h>
14813 +#include <linux/vs_context.h>
14814  
14815  /*
14816   * Management arrays for POSIX timers.  Timers are kept in slab memory
14817 @@ -340,6 +341,7 @@ int posix_timer_event(struct k_itimer *t
14818  {
14819         struct task_struct *task;
14820         int shared, ret = -1;
14821 +
14822         /*
14823          * FIXME: if ->sigq is queued we can race with
14824          * dequeue_signal()->do_schedule_next_timer().
14825 @@ -356,10 +358,18 @@ int posix_timer_event(struct k_itimer *t
14826         rcu_read_lock();
14827         task = pid_task(timr->it_pid, PIDTYPE_PID);
14828         if (task) {
14829 +               struct vx_info_save vxis;
14830 +               struct vx_info *vxi;
14831 +
14832 +               vxi = get_vx_info(task->vx_info);
14833 +               enter_vx_info(vxi, &vxis);
14834                 shared = !(timr->it_sigev_notify & SIGEV_THREAD_ID);
14835                 ret = send_sigqueue(timr->sigq, task, shared);
14836 +               leave_vx_info(&vxis);
14837 +               put_vx_info(vxi);
14838         }
14839         rcu_read_unlock();
14840 +
14841         /* If we failed to send the signal the timer stops. */
14842         return ret > 0;
14843  }
14844 diff -NurpP --minimal linux-3.6.10/kernel/printk.c linux-3.6.10-vs2.3.4.5/kernel/printk.c
14845 --- linux-3.6.10/kernel/printk.c        2012-10-04 15:27:48.000000000 +0200
14846 +++ linux-3.6.10-vs2.3.4.5/kernel/printk.c      2012-10-04 18:47:00.000000000 +0200
14847 @@ -42,6 +42,7 @@
14848  #include <linux/notifier.h>
14849  #include <linux/rculist.h>
14850  #include <linux/poll.h>
14851 +#include <linux/vs_cvirt.h>
14852  
14853  #include <asm/uaccess.h>
14854  
14855 @@ -818,7 +819,7 @@ static int check_syslog_permissions(int 
14856                 return 0;
14857  
14858         if (syslog_action_restricted(type)) {
14859 -               if (capable(CAP_SYSLOG))
14860 +               if (vx_capable(CAP_SYSLOG, VXC_SYSLOG))
14861                         return 0;
14862                 /* For historical reasons, accept CAP_SYS_ADMIN too, with a warning */
14863                 if (capable(CAP_SYS_ADMIN)) {
14864 @@ -1111,12 +1112,9 @@ int do_syslog(int type, char __user *buf
14865         if (error)
14866                 return error;
14867  
14868 -       switch (type) {
14869 -       case SYSLOG_ACTION_CLOSE:       /* Close log */
14870 -               break;
14871 -       case SYSLOG_ACTION_OPEN:        /* Open log */
14872 -               break;
14873 -       case SYSLOG_ACTION_READ:        /* Read from log */
14874 +       if ((type == SYSLOG_ACTION_READ) ||
14875 +           (type == SYSLOG_ACTION_READ_ALL) ||
14876 +           (type == SYSLOG_ACTION_READ_CLEAR)) {
14877                 error = -EINVAL;
14878                 if (!buf || len < 0)
14879                         goto out;
14880 @@ -1127,6 +1125,16 @@ int do_syslog(int type, char __user *buf
14881                         error = -EFAULT;
14882                         goto out;
14883                 }
14884 +       }
14885 +       if (!vx_check(0, VS_ADMIN|VS_WATCH))
14886 +               return vx_do_syslog(type, buf, len);
14887 +
14888 +       switch (type) {
14889 +       case SYSLOG_ACTION_CLOSE:       /* Close log */
14890 +               break;
14891 +       case SYSLOG_ACTION_OPEN:        /* Open log */
14892 +               break;
14893 +       case SYSLOG_ACTION_READ:        /* Read from log */
14894                 error = wait_event_interruptible(log_wait,
14895                                                  syslog_seq != log_next_seq);
14896                 if (error)
14897 @@ -1139,16 +1147,6 @@ int do_syslog(int type, char __user *buf
14898                 /* FALL THRU */
14899         /* Read last kernel messages */
14900         case SYSLOG_ACTION_READ_ALL:
14901 -               error = -EINVAL;
14902 -               if (!buf || len < 0)
14903 -                       goto out;
14904 -               error = 0;
14905 -               if (!len)
14906 -                       goto out;
14907 -               if (!access_ok(VERIFY_WRITE, buf, len)) {
14908 -                       error = -EFAULT;
14909 -                       goto out;
14910 -               }
14911                 error = syslog_print_all(buf, len, clear);
14912                 break;
14913         /* Clear ring buffer */
14914 diff -NurpP --minimal linux-3.6.10/kernel/ptrace.c linux-3.6.10-vs2.3.4.5/kernel/ptrace.c
14915 --- linux-3.6.10/kernel/ptrace.c        2012-07-22 23:39:46.000000000 +0200
14916 +++ linux-3.6.10-vs2.3.4.5/kernel/ptrace.c      2012-10-04 18:47:00.000000000 +0200
14917 @@ -22,6 +22,7 @@
14918  #include <linux/syscalls.h>
14919  #include <linux/uaccess.h>
14920  #include <linux/regset.h>
14921 +#include <linux/vs_context.h>
14922  #include <linux/hw_breakpoint.h>
14923  #include <linux/cn_proc.h>
14924  
14925 @@ -216,6 +217,11 @@ ok:
14926                 dumpable = get_dumpable(task->mm);
14927         if (!dumpable  && !ptrace_has_cap(task_user_ns(task), mode))
14928                 return -EPERM;
14929 +       if (!vx_check(task->xid, VS_ADMIN_P|VS_WATCH_P|VS_IDENT))
14930 +               return -EPERM;
14931 +       if (!vx_check(task->xid, VS_IDENT) &&
14932 +               !task_vx_flags(task, VXF_STATE_ADMIN, 0))
14933 +               return -EACCES;
14934  
14935         return security_ptrace_access_check(task, mode);
14936  }
14937 diff -NurpP --minimal linux-3.6.10/kernel/sched/core.c linux-3.6.10-vs2.3.4.5/kernel/sched/core.c
14938 --- linux-3.6.10/kernel/sched/core.c    2012-12-11 12:37:02.000000000 +0100
14939 +++ linux-3.6.10-vs2.3.4.5/kernel/sched/core.c  2012-11-06 18:43:41.000000000 +0100
14940 @@ -72,6 +72,8 @@
14941  #include <linux/slab.h>
14942  #include <linux/init_task.h>
14943  #include <linux/binfmts.h>
14944 +#include <linux/vs_sched.h>
14945 +#include <linux/vs_cvirt.h>
14946  
14947  #include <asm/switch_to.h>
14948  #include <asm/tlb.h>
14949 @@ -2223,9 +2225,17 @@ EXPORT_SYMBOL(avenrun); /* should be rem
14950   */
14951  void get_avenrun(unsigned long *loads, unsigned long offset, int shift)
14952  {
14953 -       loads[0] = (avenrun[0] + offset) << shift;
14954 -       loads[1] = (avenrun[1] + offset) << shift;
14955 -       loads[2] = (avenrun[2] + offset) << shift;
14956 +       if (vx_flags(VXF_VIRT_LOAD, 0)) {
14957 +               struct vx_info *vxi = current_vx_info();
14958 +
14959 +               loads[0] = (vxi->cvirt.load[0] + offset) << shift;
14960 +               loads[1] = (vxi->cvirt.load[1] + offset) << shift;
14961 +               loads[2] = (vxi->cvirt.load[2] + offset) << shift;
14962 +       } else {
14963 +               loads[0] = (avenrun[0] + offset) << shift;
14964 +               loads[1] = (avenrun[1] + offset) << shift;
14965 +               loads[2] = (avenrun[2] + offset) << shift;
14966 +       }
14967  }
14968  
14969  static long calc_load_fold_active(struct rq *this_rq)
14970 @@ -2854,14 +2864,17 @@ static inline void task_group_account_fi
14971  void account_user_time(struct task_struct *p, cputime_t cputime,
14972                        cputime_t cputime_scaled)
14973  {
14974 +       struct vx_info *vxi = p->vx_info;  /* p is _always_ current */
14975 +       int nice = (TASK_NICE(p) > 0);
14976         int index;
14977  
14978         /* Add user time to process. */
14979         p->utime += cputime;
14980         p->utimescaled += cputime_scaled;
14981 +       vx_account_user(vxi, cputime, nice);
14982         account_group_user_time(p, cputime);
14983  
14984 -       index = (TASK_NICE(p) > 0) ? CPUTIME_NICE : CPUTIME_USER;
14985 +       index = (nice) ? CPUTIME_NICE : CPUTIME_USER;
14986  
14987         /* Add user time to cpustat. */
14988         task_group_account_field(p, index, (__force u64) cputime);
14989 @@ -2908,9 +2921,12 @@ static inline
14990  void __account_system_time(struct task_struct *p, cputime_t cputime,
14991                         cputime_t cputime_scaled, int index)
14992  {
14993 +       struct vx_info *vxi = p->vx_info;  /* p is _always_ current */
14994 +
14995         /* Add system time to process. */
14996         p->stime += cputime;
14997         p->stimescaled += cputime_scaled;
14998 +       vx_account_system(vxi, cputime, 0 /* do we have idle time? */);
14999         account_group_system_time(p, cputime);
15000  
15001         /* Add system time to cpustat. */
15002 @@ -4137,7 +4153,7 @@ SYSCALL_DEFINE1(nice, int, increment)
15003                 nice = 19;
15004  
15005         if (increment < 0 && !can_nice(current, nice))
15006 -               return -EPERM;
15007 +               return vx_flags(VXF_IGNEG_NICE, 0) ? 0 : -EPERM;
15008  
15009         retval = security_task_setnice(current, nice);
15010         if (retval)
15011 diff -NurpP --minimal linux-3.6.10/kernel/sched/fair.c linux-3.6.10-vs2.3.4.5/kernel/sched/fair.c
15012 --- linux-3.6.10/kernel/sched/fair.c    2012-10-04 15:27:48.000000000 +0200
15013 +++ linux-3.6.10-vs2.3.4.5/kernel/sched/fair.c  2012-10-04 18:47:00.000000000 +0200
15014 @@ -26,6 +26,7 @@
15015  #include <linux/slab.h>
15016  #include <linux/profile.h>
15017  #include <linux/interrupt.h>
15018 +#include <linux/vs_cvirt.h>
15019  
15020  #include <trace/events/sched.h>
15021  
15022 @@ -1111,6 +1112,8 @@ enqueue_entity(struct cfs_rq *cfs_rq, st
15023                 __enqueue_entity(cfs_rq, se);
15024         se->on_rq = 1;
15025  
15026 +       if (entity_is_task(se))
15027 +               vx_activate_task(task_of(se));
15028         if (cfs_rq->nr_running == 1) {
15029                 list_add_leaf_cfs_rq(cfs_rq);
15030                 check_enqueue_throttle(cfs_rq);
15031 @@ -1191,6 +1194,8 @@ dequeue_entity(struct cfs_rq *cfs_rq, st
15032         if (se != cfs_rq->curr)
15033                 __dequeue_entity(cfs_rq, se);
15034         se->on_rq = 0;
15035 +       if (entity_is_task(se))
15036 +               vx_deactivate_task(task_of(se));
15037         update_cfs_load(cfs_rq, 0);
15038         account_entity_dequeue(cfs_rq, se);
15039  
15040 diff -NurpP --minimal linux-3.6.10/kernel/signal.c linux-3.6.10-vs2.3.4.5/kernel/signal.c
15041 --- linux-3.6.10/kernel/signal.c        2012-10-04 15:27:48.000000000 +0200
15042 +++ linux-3.6.10-vs2.3.4.5/kernel/signal.c      2012-10-04 18:47:00.000000000 +0200
15043 @@ -30,6 +30,8 @@
15044  #include <linux/nsproxy.h>
15045  #include <linux/user_namespace.h>
15046  #include <linux/uprobes.h>
15047 +#include <linux/vs_context.h>
15048 +#include <linux/vs_pid.h>
15049  #define CREATE_TRACE_POINTS
15050  #include <trace/events/signal.h>
15051  
15052 @@ -790,9 +792,18 @@ static int check_kill_permission(int sig
15053         struct pid *sid;
15054         int error;
15055  
15056 +       vxdprintk(VXD_CBIT(misc, 7),
15057 +               "check_kill_permission(%d,%p,%p[#%u,%u])",
15058 +               sig, info, t, vx_task_xid(t), t->pid);
15059 +
15060         if (!valid_signal(sig))
15061                 return -EINVAL;
15062  
15063 +/*     FIXME: needed? if so, why?
15064 +       if ((info != SEND_SIG_NOINFO) &&
15065 +               (is_si_special(info) || !si_fromuser(info)))
15066 +               goto skip;      */
15067 +
15068         if (!si_fromuser(info))
15069                 return 0;
15070  
15071 @@ -816,6 +827,20 @@ static int check_kill_permission(int sig
15072                 }
15073         }
15074  
15075 +       error = -EPERM;
15076 +       if (t->pid == 1 && current->xid)
15077 +               return error;
15078 +
15079 +       error = -ESRCH;
15080 +       /* FIXME: we shouldn't return ESRCH ever, to avoid
15081 +                 loops, maybe ENOENT or EACCES? */
15082 +       if (!vx_check(vx_task_xid(t), VS_WATCH_P | VS_IDENT)) {
15083 +               vxdprintk(current->xid || VXD_CBIT(misc, 7),
15084 +                       "signal %d[%p] xid mismatch %p[#%u,%u] xid=#%u",
15085 +                       sig, info, t, vx_task_xid(t), t->pid, current->xid);
15086 +               return error;
15087 +       }
15088 +/* skip: */
15089         return security_task_kill(t, info, sig, 0);
15090  }
15091  
15092 @@ -1351,7 +1376,7 @@ int kill_pid_info(int sig, struct siginf
15093         rcu_read_lock();
15094  retry:
15095         p = pid_task(pid, PIDTYPE_PID);
15096 -       if (p) {
15097 +       if (p && vx_check(vx_task_xid(p), VS_IDENT)) {
15098                 error = group_send_sig_info(sig, info, p);
15099                 if (unlikely(error == -ESRCH))
15100                         /*
15101 @@ -1399,7 +1424,7 @@ int kill_pid_info_as_cred(int sig, struc
15102  
15103         rcu_read_lock();
15104         p = pid_task(pid, PIDTYPE_PID);
15105 -       if (!p) {
15106 +       if (!p || !vx_check(vx_task_xid(p), VS_IDENT)) {
15107                 ret = -ESRCH;
15108                 goto out_unlock;
15109         }
15110 @@ -1451,8 +1476,10 @@ static int kill_something_info(int sig, 
15111                 struct task_struct * p;
15112  
15113                 for_each_process(p) {
15114 -                       if (task_pid_vnr(p) > 1 &&
15115 -                                       !same_thread_group(p, current)) {
15116 +                       if (vx_check(vx_task_xid(p), VS_ADMIN|VS_IDENT) &&
15117 +                               task_pid_vnr(p) > 1 &&
15118 +                               !same_thread_group(p, current) &&
15119 +                               !vx_current_initpid(p->pid)) {
15120                                 int err = group_send_sig_info(sig, info, p);
15121                                 ++count;
15122                                 if (err != -EPERM)
15123 @@ -2317,6 +2344,11 @@ relock:
15124                                 !sig_kernel_only(signr))
15125                         continue;
15126  
15127 +               /* virtual init is protected against user signals */
15128 +               if ((info->si_code == SI_USER) &&
15129 +                       vx_current_initpid(current->pid))
15130 +                       continue;
15131 +
15132                 if (sig_kernel_stop(signr)) {
15133                         /*
15134                          * The default action is to stop all threads in
15135 diff -NurpP --minimal linux-3.6.10/kernel/softirq.c linux-3.6.10-vs2.3.4.5/kernel/softirq.c
15136 --- linux-3.6.10/kernel/softirq.c       2012-10-04 15:27:48.000000000 +0200
15137 +++ linux-3.6.10-vs2.3.4.5/kernel/softirq.c     2012-10-04 18:47:00.000000000 +0200
15138 @@ -24,6 +24,7 @@
15139  #include <linux/ftrace.h>
15140  #include <linux/smp.h>
15141  #include <linux/tick.h>
15142 +#include <linux/vs_context.h>
15143  
15144  #define CREATE_TRACE_POINTS
15145  #include <trace/events/irq.h>
15146 diff -NurpP --minimal linux-3.6.10/kernel/sys.c linux-3.6.10-vs2.3.4.5/kernel/sys.c
15147 --- linux-3.6.10/kernel/sys.c   2012-12-11 12:37:02.000000000 +0100
15148 +++ linux-3.6.10-vs2.3.4.5/kernel/sys.c 2012-11-06 18:43:41.000000000 +0100
15149 @@ -47,6 +47,7 @@
15150  #include <linux/syscalls.h>
15151  #include <linux/kprobes.h>
15152  #include <linux/user_namespace.h>
15153 +#include <linux/vs_pid.h>
15154  
15155  #include <linux/kmsg_dump.h>
15156  /* Move somewhere else to avoid recompiling? */
15157 @@ -154,7 +155,10 @@ static int set_one_prio(struct task_stru
15158                 goto out;
15159         }
15160         if (niceval < task_nice(p) && !can_nice(p, niceval)) {
15161 -               error = -EACCES;
15162 +               if (vx_flags(VXF_IGNEG_NICE, 0))
15163 +                       error = 0;
15164 +               else
15165 +                       error = -EACCES;
15166                 goto out;
15167         }
15168         no_nice = security_task_setnice(p, niceval);
15169 @@ -205,6 +209,8 @@ SYSCALL_DEFINE3(setpriority, int, which,
15170                         else
15171                                 pgrp = task_pgrp(current);
15172                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
15173 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
15174 +                                       continue;
15175                                 error = set_one_prio(p, niceval, error);
15176                         } while_each_pid_thread(pgrp, PIDTYPE_PGID, p);
15177                         break;
15178 @@ -270,6 +276,8 @@ SYSCALL_DEFINE2(getpriority, int, which,
15179                         else
15180                                 pgrp = task_pgrp(current);
15181                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
15182 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
15183 +                                       continue;
15184                                 niceval = 20 - task_nice(p);
15185                                 if (niceval > retval)
15186                                         retval = niceval;
15187 @@ -422,6 +430,8 @@ EXPORT_SYMBOL_GPL(kernel_power_off);
15188  
15189  static DEFINE_MUTEX(reboot_mutex);
15190  
15191 +long vs_reboot(unsigned int, void __user *);
15192 +
15193  /*
15194   * Reboot system call: for obvious reasons only root may call it,
15195   * and even root needs to set up some magic numbers in the registers
15196 @@ -463,6 +473,9 @@ SYSCALL_DEFINE4(reboot, int, magic1, int
15197         if ((cmd == LINUX_REBOOT_CMD_POWER_OFF) && !pm_power_off)
15198                 cmd = LINUX_REBOOT_CMD_HALT;
15199  
15200 +       if (!vx_check(0, VS_ADMIN|VS_WATCH))
15201 +               return vs_reboot(cmd, arg);
15202 +
15203         mutex_lock(&reboot_mutex);
15204         switch (cmd) {
15205         case LINUX_REBOOT_CMD_RESTART:
15206 @@ -1370,7 +1383,8 @@ SYSCALL_DEFINE2(sethostname, char __user
15207         int errno;
15208         char tmp[__NEW_UTS_LEN];
15209  
15210 -       if (!ns_capable(current->nsproxy->uts_ns->user_ns, CAP_SYS_ADMIN))
15211 +       if (!vx_ns_capable(current->nsproxy->uts_ns->user_ns,
15212 +               CAP_SYS_ADMIN, VXC_SET_UTSNAME))
15213                 return -EPERM;
15214  
15215         if (len < 0 || len > __NEW_UTS_LEN)
15216 @@ -1421,7 +1435,8 @@ SYSCALL_DEFINE2(setdomainname, char __us
15217         int errno;
15218         char tmp[__NEW_UTS_LEN];
15219  
15220 -       if (!ns_capable(current->nsproxy->uts_ns->user_ns, CAP_SYS_ADMIN))
15221 +       if (!vx_ns_capable(current->nsproxy->uts_ns->user_ns,
15222 +               CAP_SYS_ADMIN, VXC_SET_UTSNAME))
15223                 return -EPERM;
15224         if (len < 0 || len > __NEW_UTS_LEN)
15225                 return -EINVAL;
15226 @@ -1540,7 +1555,7 @@ int do_prlimit(struct task_struct *tsk, 
15227                 /* Keep the capable check against init_user_ns until
15228                    cgroups can contain all limits */
15229                 if (new_rlim->rlim_max > rlim->rlim_max &&
15230 -                               !capable(CAP_SYS_RESOURCE))
15231 +                       !vx_capable(CAP_SYS_RESOURCE, VXC_SET_RLIMIT))
15232                         retval = -EPERM;
15233                 if (!retval)
15234                         retval = security_task_setrlimit(tsk->group_leader,
15235 @@ -1593,7 +1608,8 @@ static int check_prlimit_permission(stru
15236             gid_eq(cred->gid, tcred->sgid) &&
15237             gid_eq(cred->gid, tcred->gid))
15238                 return 0;
15239 -       if (ns_capable(tcred->user_ns, CAP_SYS_RESOURCE))
15240 +       if (vx_ns_capable(tcred->user_ns,
15241 +               CAP_SYS_RESOURCE, VXC_SET_RLIMIT))
15242                 return 0;
15243  
15244         return -EPERM;
15245 diff -NurpP --minimal linux-3.6.10/kernel/sysctl.c linux-3.6.10-vs2.3.4.5/kernel/sysctl.c
15246 --- linux-3.6.10/kernel/sysctl.c        2012-10-04 15:27:48.000000000 +0200
15247 +++ linux-3.6.10-vs2.3.4.5/kernel/sysctl.c      2012-10-04 18:47:00.000000000 +0200
15248 @@ -82,6 +82,7 @@
15249  #if defined(CONFIG_PROVE_LOCKING) || defined(CONFIG_LOCK_STAT)
15250  #include <linux/lockdep.h>
15251  #endif
15252 +extern char vshelper_path[];
15253  #ifdef CONFIG_CHR_DEV_SG
15254  #include <scsi/sg.h>
15255  #endif
15256 @@ -568,6 +569,13 @@ static struct ctl_table kern_table[] = {
15257                 .proc_handler   = proc_dostring,
15258         },
15259  #endif
15260 +       {
15261 +               .procname       = "vshelper",
15262 +               .data           = &vshelper_path,
15263 +               .maxlen         = 256,
15264 +               .mode           = 0644,
15265 +               .proc_handler   = &proc_dostring,
15266 +       },
15267  #ifdef CONFIG_CHR_DEV_SG
15268         {
15269                 .procname       = "sg-big-buff",
15270 diff -NurpP --minimal linux-3.6.10/kernel/sysctl_binary.c linux-3.6.10-vs2.3.4.5/kernel/sysctl_binary.c
15271 --- linux-3.6.10/kernel/sysctl_binary.c 2012-10-04 15:27:48.000000000 +0200
15272 +++ linux-3.6.10-vs2.3.4.5/kernel/sysctl_binary.c       2012-10-04 18:47:00.000000000 +0200
15273 @@ -73,6 +73,7 @@ static const struct bin_table bin_kern_t
15274  
15275         { CTL_INT,      KERN_PANIC,                     "panic" },
15276         { CTL_INT,      KERN_REALROOTDEV,               "real-root-dev" },
15277 +       { CTL_STR,      KERN_VSHELPER,                  "vshelper" },
15278  
15279         { CTL_STR,      KERN_SPARC_REBOOT,              "reboot-cmd" },
15280         { CTL_INT,      KERN_CTLALTDEL,                 "ctrl-alt-del" },
15281 diff -NurpP --minimal linux-3.6.10/kernel/time/timekeeping.c linux-3.6.10-vs2.3.4.5/kernel/time/timekeeping.c
15282 --- linux-3.6.10/kernel/time/timekeeping.c      2012-12-11 12:37:02.000000000 +0100
15283 +++ linux-3.6.10-vs2.3.4.5/kernel/time/timekeeping.c    2012-11-06 18:43:41.000000000 +0100
15284 @@ -309,6 +309,7 @@ void getnstimeofday(struct timespec *ts)
15285  
15286         ts->tv_nsec = 0;
15287         timespec_add_ns(ts, nsecs);
15288 +       vx_adjust_timespec(ts);
15289  }
15290  EXPORT_SYMBOL(getnstimeofday);
15291  
15292 diff -NurpP --minimal linux-3.6.10/kernel/time.c linux-3.6.10-vs2.3.4.5/kernel/time.c
15293 --- linux-3.6.10/kernel/time.c  2012-05-21 18:07:34.000000000 +0200
15294 +++ linux-3.6.10-vs2.3.4.5/kernel/time.c        2012-10-04 18:47:00.000000000 +0200
15295 @@ -92,7 +92,7 @@ SYSCALL_DEFINE1(stime, time_t __user *, 
15296         if (err)
15297                 return err;
15298  
15299 -       do_settimeofday(&tv);
15300 +       vx_settimeofday(&tv);
15301         return 0;
15302  }
15303  
15304 @@ -172,7 +172,7 @@ int do_sys_settimeofday(const struct tim
15305                 }
15306         }
15307         if (tv)
15308 -               return do_settimeofday(tv);
15309 +               return vx_settimeofday(tv);
15310         return 0;
15311  }
15312  
15313 diff -NurpP --minimal linux-3.6.10/kernel/timer.c linux-3.6.10-vs2.3.4.5/kernel/timer.c
15314 --- linux-3.6.10/kernel/timer.c 2012-12-11 12:37:02.000000000 +0100
15315 +++ linux-3.6.10-vs2.3.4.5/kernel/timer.c       2012-11-06 18:43:41.000000000 +0100
15316 @@ -40,6 +40,10 @@
15317  #include <linux/irq_work.h>
15318  #include <linux/sched.h>
15319  #include <linux/slab.h>
15320 +#include <linux/vs_base.h>
15321 +#include <linux/vs_cvirt.h>
15322 +#include <linux/vs_pid.h>
15323 +#include <linux/vserver/sched.h>
15324  
15325  #include <asm/uaccess.h>
15326  #include <asm/unistd.h>
15327 diff -NurpP --minimal linux-3.6.10/kernel/user_namespace.c linux-3.6.10-vs2.3.4.5/kernel/user_namespace.c
15328 --- linux-3.6.10/kernel/user_namespace.c        2012-07-22 23:39:47.000000000 +0200
15329 +++ linux-3.6.10-vs2.3.4.5/kernel/user_namespace.c      2012-10-04 18:47:00.000000000 +0200
15330 @@ -19,6 +19,7 @@
15331  #include <linux/fs.h>
15332  #include <linux/uaccess.h>
15333  #include <linux/ctype.h>
15334 +#include <linux/vserver/global.h>
15335  
15336  static struct kmem_cache *user_ns_cachep __read_mostly;
15337  
15338 @@ -52,6 +53,7 @@ int create_user_ns(struct cred *new)
15339                 return -ENOMEM;
15340  
15341         kref_init(&ns->kref);
15342 +       atomic_inc(&vs_global_user_ns);
15343         ns->parent = parent_ns;
15344         ns->owner = owner;
15345         ns->group = group;
15346 @@ -84,6 +86,9 @@ void free_user_ns(struct kref *kref)
15347  
15348         parent = ns->parent;
15349         kmem_cache_free(user_ns_cachep, ns);
15350 +
15351 +       /* FIXME: maybe move into destroyer? */
15352 +       atomic_dec(&vs_global_user_ns);
15353         put_user_ns(parent);
15354  }
15355  EXPORT_SYMBOL(free_user_ns);
15356 diff -NurpP --minimal linux-3.6.10/kernel/utsname.c linux-3.6.10-vs2.3.4.5/kernel/utsname.c
15357 --- linux-3.6.10/kernel/utsname.c       2012-07-22 23:39:47.000000000 +0200
15358 +++ linux-3.6.10-vs2.3.4.5/kernel/utsname.c     2012-10-04 18:47:00.000000000 +0200
15359 @@ -16,14 +16,17 @@
15360  #include <linux/slab.h>
15361  #include <linux/user_namespace.h>
15362  #include <linux/proc_fs.h>
15363 +#include <linux/vserver/global.h>
15364  
15365  static struct uts_namespace *create_uts_ns(void)
15366  {
15367         struct uts_namespace *uts_ns;
15368  
15369         uts_ns = kmalloc(sizeof(struct uts_namespace), GFP_KERNEL);
15370 -       if (uts_ns)
15371 +       if (uts_ns) {
15372                 kref_init(&uts_ns->kref);
15373 +               atomic_inc(&vs_global_uts_ns);
15374 +       }
15375         return uts_ns;
15376  }
15377  
15378 @@ -32,8 +35,8 @@ static struct uts_namespace *create_uts_
15379   * @old_ns: namespace to clone
15380   * Return NULL on error (failure to kmalloc), new ns otherwise
15381   */
15382 -static struct uts_namespace *clone_uts_ns(struct task_struct *tsk,
15383 -                                         struct uts_namespace *old_ns)
15384 +static struct uts_namespace *clone_uts_ns(struct uts_namespace *old_ns,
15385 +                                         struct user_namespace *old_user)
15386  {
15387         struct uts_namespace *ns;
15388  
15389 @@ -43,7 +46,7 @@ static struct uts_namespace *clone_uts_n
15390  
15391         down_read(&uts_sem);
15392         memcpy(&ns->name, &old_ns->name, sizeof(ns->name));
15393 -       ns->user_ns = get_user_ns(task_cred_xxx(tsk, user_ns));
15394 +       ns->user_ns = get_user_ns(old_user);
15395         up_read(&uts_sem);
15396         return ns;
15397  }
15398 @@ -55,9 +58,9 @@ static struct uts_namespace *clone_uts_n
15399   * versa.
15400   */
15401  struct uts_namespace *copy_utsname(unsigned long flags,
15402 -                                  struct task_struct *tsk)
15403 +                                  struct uts_namespace *old_ns,
15404 +                                  struct user_namespace *user_ns)
15405  {
15406 -       struct uts_namespace *old_ns = tsk->nsproxy->uts_ns;
15407         struct uts_namespace *new_ns;
15408  
15409         BUG_ON(!old_ns);
15410 @@ -66,7 +69,7 @@ struct uts_namespace *copy_utsname(unsig
15411         if (!(flags & CLONE_NEWUTS))
15412                 return old_ns;
15413  
15414 -       new_ns = clone_uts_ns(tsk, old_ns);
15415 +       new_ns = clone_uts_ns(old_ns, user_ns);
15416  
15417         put_uts_ns(old_ns);
15418         return new_ns;
15419 @@ -78,6 +81,7 @@ void free_uts_ns(struct kref *kref)
15420  
15421         ns = container_of(kref, struct uts_namespace, kref);
15422         put_user_ns(ns->user_ns);
15423 +       atomic_dec(&vs_global_uts_ns);
15424         kfree(ns);
15425  }
15426  
15427 diff -NurpP --minimal linux-3.6.10/kernel/vserver/Kconfig linux-3.6.10-vs2.3.4.5/kernel/vserver/Kconfig
15428 --- linux-3.6.10/kernel/vserver/Kconfig 1970-01-01 01:00:00.000000000 +0100
15429 +++ linux-3.6.10-vs2.3.4.5/kernel/vserver/Kconfig       2012-12-10 18:21:15.000000000 +0100
15430 @@ -0,0 +1,233 @@
15431 +#
15432 +# Linux VServer configuration
15433 +#
15434 +
15435 +menu "Linux VServer"
15436 +
15437 +config VSERVER_AUTO_LBACK
15438 +       bool    "Automatically Assign Loopback IP"
15439 +       default y
15440 +       help
15441 +         Automatically assign a guest specific loopback
15442 +         IP and add it to the kernel network stack on
15443 +         startup.
15444 +
15445 +config VSERVER_AUTO_SINGLE
15446 +       bool    "Automatic Single IP Special Casing"
15447 +       depends on EXPERIMENTAL
15448 +       default y
15449 +       help
15450 +         This allows network contexts with a single IP to
15451 +         automatically remap 0.0.0.0 bindings to that IP,
15452 +         avoiding further network checks and improving
15453 +         performance.
15454 +
15455 +         (note: such guests do not allow to change the ip
15456 +          on the fly and do not show loopback addresses)
15457 +
15458 +config VSERVER_COWBL
15459 +       bool    "Enable COW Immutable Link Breaking"
15460 +       default y
15461 +       help
15462 +         This enables the COW (Copy-On-Write) link break code.
15463 +         It allows you to treat unified files like normal files
15464 +         when writing to them (which will implicitely break the
15465 +         link and create a copy of the unified file)
15466 +
15467 +config VSERVER_VTIME
15468 +       bool    "Enable Virtualized Guest Time"
15469 +       depends on EXPERIMENTAL
15470 +       default n
15471 +       help
15472 +         This enables per guest time offsets to allow for
15473 +         adjusting the system clock individually per guest.
15474 +         this adds some overhead to the time functions and
15475 +         therefore should not be enabled without good reason.
15476 +
15477 +config VSERVER_DEVICE
15478 +       bool    "Enable Guest Device Mapping"
15479 +       depends on EXPERIMENTAL
15480 +       default n
15481 +       help
15482 +         This enables generic device remapping.
15483 +
15484 +config VSERVER_PROC_SECURE
15485 +       bool    "Enable Proc Security"
15486 +       depends on PROC_FS
15487 +       default y
15488 +       help
15489 +         This configures ProcFS security to initially hide
15490 +         non-process entries for all contexts except the main and
15491 +         spectator context (i.e. for all guests), which is a secure
15492 +         default.
15493 +
15494 +         (note: on 1.2x the entries were visible by default)
15495 +
15496 +choice
15497 +       prompt  "Persistent Inode Tagging"
15498 +       default TAGGING_ID24
15499 +       help
15500 +         This adds persistent context information to filesystems
15501 +         mounted with the tagxid option. Tagging is a requirement
15502 +         for per-context disk limits and per-context quota.
15503 +
15504 +
15505 +config TAGGING_NONE
15506 +       bool    "Disabled"
15507 +       help
15508 +         do not store per-context information in inodes.
15509 +
15510 +config TAGGING_UID16
15511 +       bool    "UID16/GID32"
15512 +       help
15513 +         reduces UID to 16 bit, but leaves GID at 32 bit.
15514 +
15515 +config TAGGING_GID16
15516 +       bool    "UID32/GID16"
15517 +       help
15518 +         reduces GID to 16 bit, but leaves UID at 32 bit.
15519 +
15520 +config TAGGING_ID24
15521 +       bool    "UID24/GID24"
15522 +       help
15523 +         uses the upper 8bit from UID and GID for XID tagging
15524 +         which leaves 24bit for UID/GID each, which should be
15525 +         more than sufficient for normal use.
15526 +
15527 +config TAGGING_INTERN
15528 +       bool    "UID32/GID32"
15529 +       help
15530 +         this uses otherwise reserved inode fields in the on
15531 +         disk representation, which limits the use to a few
15532 +         filesystems (currently ext2 and ext3)
15533 +
15534 +endchoice
15535 +
15536 +config TAG_NFSD
15537 +       bool    "Tag NFSD User Auth and Files"
15538 +       default n
15539 +       help
15540 +         Enable this if you do want the in-kernel NFS
15541 +         Server to use the tagging specified above.
15542 +         (will require patched clients too)
15543 +
15544 +config VSERVER_PRIVACY
15545 +       bool    "Honor Privacy Aspects of Guests"
15546 +       default n
15547 +       help
15548 +         When enabled, most context checks will disallow
15549 +         access to structures assigned to a specific context,
15550 +         like ptys or loop devices.
15551 +
15552 +config VSERVER_CONTEXTS
15553 +       int     "Maximum number of Contexts (1-65533)"  if EMBEDDED
15554 +       range 1 65533
15555 +       default "768"   if 64BIT
15556 +       default "256"
15557 +       help
15558 +         This setting will optimize certain data structures
15559 +         and memory allocations according to the expected
15560 +         maximum.
15561 +
15562 +         note: this is not a strict upper limit.
15563 +
15564 +config VSERVER_WARN
15565 +       bool    "VServer Warnings"
15566 +       default y
15567 +       help
15568 +         This enables various runtime warnings, which will
15569 +         notify about potential manipulation attempts or
15570 +         resource shortage. It is generally considered to
15571 +         be a good idea to have that enabled.
15572 +
15573 +config VSERVER_WARN_DEVPTS
15574 +       bool    "VServer DevPTS Warnings"
15575 +       depends on VSERVER_WARN
15576 +       default y
15577 +       help
15578 +         This enables DevPTS related warnings, issued when a
15579 +         process inside a context tries to lookup or access
15580 +         a dynamic pts from the host or a different context.
15581 +
15582 +config VSERVER_DEBUG
15583 +       bool    "VServer Debugging Code"
15584 +       default n
15585 +       help
15586 +         Set this to yes if you want to be able to activate
15587 +         debugging output at runtime. It adds a very small
15588 +         overhead to all vserver related functions and
15589 +         increases the kernel size by about 20k.
15590 +
15591 +config VSERVER_HISTORY
15592 +       bool    "VServer History Tracing"
15593 +       depends on VSERVER_DEBUG
15594 +       default n
15595 +       help
15596 +         Set this to yes if you want to record the history of
15597 +         linux-vserver activities, so they can be replayed in
15598 +         the event of a kernel panic or oops.
15599 +
15600 +config VSERVER_HISTORY_SIZE
15601 +       int     "Per-CPU History Size (32-65536)"
15602 +       depends on VSERVER_HISTORY
15603 +       range 32 65536
15604 +       default 64
15605 +       help
15606 +         This allows you to specify the number of entries in
15607 +         the per-CPU history buffer.
15608 +
15609 +config VSERVER_EXTRA_MNT_CHECK
15610 +       bool    "Extra Checks for Reachability"
15611 +       default n
15612 +       help
15613 +         Set this to yes if you want to do extra checks for
15614 +         vfsmount reachability in the proc filesystem code.
15615 +         This shouldn't be required on any setup utilizing
15616 +         mnt namespaces.
15617 +
15618 +choice
15619 +       prompt  "Quotes used in debug and warn messages"
15620 +       default QUOTES_ISO8859
15621 +
15622 +config QUOTES_ISO8859
15623 +       bool    "Extended ASCII (ISO 8859) angle quotes"
15624 +       help
15625 +         This uses the extended ASCII characters \xbb
15626 +         and \xab for quoting file and process names.
15627 +
15628 +config QUOTES_UTF8
15629 +       bool    "UTF-8 angle quotes"
15630 +       help
15631 +         This uses the the UTF-8 sequences for angle
15632 +         quotes to quote file and process names.
15633 +
15634 +config QUOTES_ASCII
15635 +       bool    "ASCII single quotes"
15636 +       help
15637 +         This uses the ASCII single quote character
15638 +         (\x27) to quote file and process names.
15639 +
15640 +endchoice
15641 +
15642 +endmenu
15643 +
15644 +
15645 +config VSERVER
15646 +       bool
15647 +       default y
15648 +       select NAMESPACES
15649 +       select UTS_NS
15650 +       select IPC_NS
15651 +#      select USER_NS
15652 +       select SYSVIPC
15653 +
15654 +config VSERVER_SECURITY
15655 +       bool
15656 +       depends on SECURITY
15657 +       default y
15658 +       select SECURITY_CAPABILITIES
15659 +
15660 +config VSERVER_DISABLED
15661 +       bool
15662 +       default n
15663 +
15664 diff -NurpP --minimal linux-3.6.10/kernel/vserver/Makefile linux-3.6.10-vs2.3.4.5/kernel/vserver/Makefile
15665 --- linux-3.6.10/kernel/vserver/Makefile        1970-01-01 01:00:00.000000000 +0100
15666 +++ linux-3.6.10-vs2.3.4.5/kernel/vserver/Makefile      2012-10-04 18:47:00.000000000 +0200
15667 @@ -0,0 +1,18 @@
15668 +#
15669 +# Makefile for the Linux vserver routines.
15670 +#
15671 +
15672 +
15673 +obj-y          += vserver.o
15674 +
15675 +vserver-y      := switch.o context.o space.o sched.o network.o inode.o \
15676 +                  limit.o cvirt.o cacct.o signal.o helper.o init.o \
15677 +                  dlimit.o tag.o
15678 +
15679 +vserver-$(CONFIG_INET) += inet.o
15680 +vserver-$(CONFIG_PROC_FS) += proc.o
15681 +vserver-$(CONFIG_VSERVER_DEBUG) += sysctl.o debug.o
15682 +vserver-$(CONFIG_VSERVER_HISTORY) += history.o
15683 +vserver-$(CONFIG_VSERVER_MONITOR) += monitor.o
15684 +vserver-$(CONFIG_VSERVER_DEVICE) += device.o
15685 +
15686 diff -NurpP --minimal linux-3.6.10/kernel/vserver/cacct.c linux-3.6.10-vs2.3.4.5/kernel/vserver/cacct.c
15687 --- linux-3.6.10/kernel/vserver/cacct.c 1970-01-01 01:00:00.000000000 +0100
15688 +++ linux-3.6.10-vs2.3.4.5/kernel/vserver/cacct.c       2012-10-04 18:47:00.000000000 +0200
15689 @@ -0,0 +1,42 @@
15690 +/*
15691 + *  linux/kernel/vserver/cacct.c
15692 + *
15693 + *  Virtual Server: Context Accounting
15694 + *
15695 + *  Copyright (C) 2006-2007 Herbert Pötzl
15696 + *
15697 + *  V0.01  added accounting stats
15698 + *
15699 + */
15700 +
15701 +#include <linux/types.h>
15702 +#include <linux/vs_context.h>
15703 +#include <linux/vserver/cacct_cmd.h>
15704 +#include <linux/vserver/cacct_int.h>
15705 +
15706 +#include <asm/errno.h>
15707 +#include <asm/uaccess.h>
15708 +
15709 +
15710 +int vc_sock_stat(struct vx_info *vxi, void __user *data)
15711 +{
15712 +       struct vcmd_sock_stat_v0 vc_data;
15713 +       int j, field;
15714 +
15715 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
15716 +               return -EFAULT;
15717 +
15718 +       field = vc_data.field;
15719 +       if ((field < 0) || (field >= VXA_SOCK_SIZE))
15720 +               return -EINVAL;
15721 +
15722 +       for (j = 0; j < 3; j++) {
15723 +               vc_data.count[j] = vx_sock_count(&vxi->cacct, field, j);
15724 +               vc_data.total[j] = vx_sock_total(&vxi->cacct, field, j);
15725 +       }
15726 +
15727 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
15728 +               return -EFAULT;
15729 +       return 0;
15730 +}
15731 +
15732 diff -NurpP --minimal linux-3.6.10/kernel/vserver/cacct_init.h linux-3.6.10-vs2.3.4.5/kernel/vserver/cacct_init.h
15733 --- linux-3.6.10/kernel/vserver/cacct_init.h    1970-01-01 01:00:00.000000000 +0100
15734 +++ linux-3.6.10-vs2.3.4.5/kernel/vserver/cacct_init.h  2012-10-04 18:47:00.000000000 +0200
15735 @@ -0,0 +1,25 @@
15736 +
15737 +
15738 +static inline void vx_info_init_cacct(struct _vx_cacct *cacct)
15739 +{
15740 +       int i, j;
15741 +
15742 +
15743 +       for (i = 0; i < VXA_SOCK_SIZE; i++) {
15744 +               for (j = 0; j < 3; j++) {
15745 +                       atomic_long_set(&cacct->sock[i][j].count, 0);
15746 +                       atomic_long_set(&cacct->sock[i][j].total, 0);
15747 +               }
15748 +       }
15749 +       for (i = 0; i < 8; i++)
15750 +               atomic_set(&cacct->slab[i], 0);
15751 +       for (i = 0; i < 5; i++)
15752 +               for (j = 0; j < 4; j++)
15753 +                       atomic_set(&cacct->page[i][j], 0);
15754 +}
15755 +
15756 +static inline void vx_info_exit_cacct(struct _vx_cacct *cacct)
15757 +{
15758 +       return;
15759 +}
15760 +
15761 diff -NurpP --minimal linux-3.6.10/kernel/vserver/cacct_proc.h linux-3.6.10-vs2.3.4.5/kernel/vserver/cacct_proc.h
15762 --- linux-3.6.10/kernel/vserver/cacct_proc.h    1970-01-01 01:00:00.000000000 +0100
15763 +++ linux-3.6.10-vs2.3.4.5/kernel/vserver/cacct_proc.h  2012-10-04 18:47:00.000000000 +0200
15764 @@ -0,0 +1,53 @@
15765 +#ifndef _VX_CACCT_PROC_H
15766 +#define _VX_CACCT_PROC_H
15767 +
15768 +#include <linux/vserver/cacct_int.h>
15769 +
15770 +
15771 +#define VX_SOCKA_TOP   \
15772 +       "Type\t    recv #/bytes\t\t   send #/bytes\t\t    fail #/bytes\n"
15773 +
15774 +static inline int vx_info_proc_cacct(struct _vx_cacct *cacct, char *buffer)
15775 +{
15776 +       int i, j, length = 0;
15777 +       static char *type[VXA_SOCK_SIZE] = {
15778 +               "UNSPEC", "UNIX", "INET", "INET6", "PACKET", "OTHER"
15779 +       };
15780 +
15781 +       length += sprintf(buffer + length, VX_SOCKA_TOP);
15782 +       for (i = 0; i < VXA_SOCK_SIZE; i++) {
15783 +               length += sprintf(buffer + length, "%s:", type[i]);
15784 +               for (j = 0; j < 3; j++) {
15785 +                       length += sprintf(buffer + length,
15786 +                               "\t%10lu/%-10lu",
15787 +                               vx_sock_count(cacct, i, j),
15788 +                               vx_sock_total(cacct, i, j));
15789 +               }
15790 +               buffer[length++] = '\n';
15791 +       }
15792 +
15793 +       length += sprintf(buffer + length, "\n");
15794 +       length += sprintf(buffer + length,
15795 +               "slab:\t %8u %8u %8u %8u\n",
15796 +               atomic_read(&cacct->slab[1]),
15797 +               atomic_read(&cacct->slab[4]),
15798 +               atomic_read(&cacct->slab[0]),
15799 +               atomic_read(&cacct->slab[2]));
15800 +
15801 +       length += sprintf(buffer + length, "\n");
15802 +       for (i = 0; i < 5; i++) {
15803 +               length += sprintf(buffer + length,
15804 +                       "page[%d]: %8u %8u %8u %8u\t %8u %8u %8u %8u\n", i,
15805 +                       atomic_read(&cacct->page[i][0]),
15806 +                       atomic_read(&cacct->page[i][1]),
15807 +                       atomic_read(&cacct->page[i][2]),
15808 +                       atomic_read(&cacct->page[i][3]),
15809 +                       atomic_read(&cacct->page[i][4]),
15810 +                       atomic_read(&cacct->page[i][5]),
15811 +                       atomic_read(&cacct->page[i][6]),
15812 +                       atomic_read(&cacct->page[i][7]));
15813 +       }
15814 +       return length;
15815 +}
15816 +
15817 +#endif /* _VX_CACCT_PROC_H */
15818 diff -NurpP --minimal linux-3.6.10/kernel/vserver/context.c linux-3.6.10-vs2.3.4.5/kernel/vserver/context.c
15819 --- linux-3.6.10/kernel/vserver/context.c       1970-01-01 01:00:00.000000000 +0100
15820 +++ linux-3.6.10-vs2.3.4.5/kernel/vserver/context.c     2012-10-04 18:47:00.000000000 +0200
15821 @@ -0,0 +1,1119 @@
15822 +/*
15823 + *  linux/kernel/vserver/context.c
15824 + *
15825 + *  Virtual Server: Context Support
15826 + *
15827 + *  Copyright (C) 2003-2011  Herbert Pötzl
15828 + *
15829 + *  V0.01  context helper
15830 + *  V0.02  vx_ctx_kill syscall command
15831 + *  V0.03  replaced context_info calls
15832 + *  V0.04  redesign of struct (de)alloc
15833 + *  V0.05  rlimit basic implementation
15834 + *  V0.06  task_xid and info commands
15835 + *  V0.07  context flags and caps
15836 + *  V0.08  switch to RCU based hash
15837 + *  V0.09  revert to non RCU for now
15838 + *  V0.10  and back to working RCU hash
15839 + *  V0.11  and back to locking again
15840 + *  V0.12  referenced context store
15841 + *  V0.13  separate per cpu data
15842 + *  V0.14  changed vcmds to vxi arg
15843 + *  V0.15  added context stat
15844 + *  V0.16  have __create claim() the vxi
15845 + *  V0.17  removed older and legacy stuff
15846 + *  V0.18  added user credentials
15847 + *  V0.19  added warn mask
15848 + *
15849 + */
15850 +
15851 +#include <linux/slab.h>
15852 +#include <linux/types.h>
15853 +#include <linux/security.h>
15854 +#include <linux/pid_namespace.h>
15855 +#include <linux/capability.h>
15856 +
15857 +#include <linux/vserver/context.h>
15858 +#include <linux/vserver/network.h>
15859 +#include <linux/vserver/debug.h>
15860 +#include <linux/vserver/limit.h>
15861 +#include <linux/vserver/limit_int.h>
15862 +#include <linux/vserver/space.h>
15863 +#include <linux/init_task.h>
15864 +#include <linux/fs_struct.h>
15865 +#include <linux/cred.h>
15866 +
15867 +#include <linux/vs_context.h>
15868 +#include <linux/vs_limit.h>
15869 +#include <linux/vs_pid.h>
15870 +#include <linux/vserver/context_cmd.h>
15871 +
15872 +#include "cvirt_init.h"
15873 +#include "cacct_init.h"
15874 +#include "limit_init.h"
15875 +#include "sched_init.h"
15876 +
15877 +
15878 +atomic_t vx_global_ctotal      = ATOMIC_INIT(0);
15879 +atomic_t vx_global_cactive     = ATOMIC_INIT(0);
15880 +
15881 +
15882 +/*     now inactive context structures */
15883 +
15884 +static struct hlist_head vx_info_inactive = HLIST_HEAD_INIT;
15885 +
15886 +static DEFINE_SPINLOCK(vx_info_inactive_lock);
15887 +
15888 +
15889 +/*     __alloc_vx_info()
15890 +
15891 +       * allocate an initialized vx_info struct
15892 +       * doesn't make it visible (hash)                        */
15893 +
15894 +static struct vx_info *__alloc_vx_info(xid_t xid)
15895 +{
15896 +       struct vx_info *new = NULL;
15897 +       int cpu, index;
15898 +
15899 +       vxdprintk(VXD_CBIT(xid, 0), "alloc_vx_info(%d)*", xid);
15900 +
15901 +       /* would this benefit from a slab cache? */
15902 +       new = kmalloc(sizeof(struct vx_info), GFP_KERNEL);
15903 +       if (!new)
15904 +               return 0;
15905 +
15906 +       memset(new, 0, sizeof(struct vx_info));
15907 +#ifdef CONFIG_SMP
15908 +       new->ptr_pc = alloc_percpu(struct _vx_info_pc);
15909 +       if (!new->ptr_pc)
15910 +               goto error;
15911 +#endif
15912 +       new->vx_id = xid;
15913 +       INIT_HLIST_NODE(&new->vx_hlist);
15914 +       atomic_set(&new->vx_usecnt, 0);
15915 +       atomic_set(&new->vx_tasks, 0);
15916 +       new->vx_parent = NULL;
15917 +       new->vx_state = 0;
15918 +       init_waitqueue_head(&new->vx_wait);
15919 +
15920 +       /* prepare reaper */
15921 +       get_task_struct(init_pid_ns.child_reaper);
15922 +       new->vx_reaper = init_pid_ns.child_reaper;
15923 +       new->vx_badness_bias = 0;
15924 +
15925 +       /* rest of init goes here */
15926 +       vx_info_init_limit(&new->limit);
15927 +       vx_info_init_sched(&new->sched);
15928 +       vx_info_init_cvirt(&new->cvirt);
15929 +       vx_info_init_cacct(&new->cacct);
15930 +
15931 +       /* per cpu data structures */
15932 +       for_each_possible_cpu(cpu) {
15933 +               vx_info_init_sched_pc(
15934 +                       &vx_per_cpu(new, sched_pc, cpu), cpu);
15935 +               vx_info_init_cvirt_pc(
15936 +                       &vx_per_cpu(new, cvirt_pc, cpu), cpu);
15937 +       }
15938 +
15939 +       new->vx_flags = VXF_INIT_SET;
15940 +       new->vx_bcaps = CAP_FULL_SET;   // maybe ~CAP_SETPCAP
15941 +       new->vx_ccaps = 0;
15942 +       new->vx_umask = 0;
15943 +       new->vx_wmask = 0;
15944 +
15945 +       new->reboot_cmd = 0;
15946 +       new->exit_code = 0;
15947 +
15948 +       // preconfig spaces
15949 +       for (index = 0; index < VX_SPACES; index++) {
15950 +               struct _vx_space *space = &new->space[index];
15951 +
15952 +               // filesystem
15953 +               spin_lock(&init_fs.lock);
15954 +               init_fs.users++;
15955 +               spin_unlock(&init_fs.lock);
15956 +               space->vx_fs = &init_fs;
15957 +
15958 +               /* FIXME: do we want defaults? */
15959 +               // space->vx_real_cred = 0;
15960 +               // space->vx_cred = 0;
15961 +       }
15962 +
15963 +
15964 +       vxdprintk(VXD_CBIT(xid, 0),
15965 +               "alloc_vx_info(%d) = %p", xid, new);
15966 +       vxh_alloc_vx_info(new);
15967 +       atomic_inc(&vx_global_ctotal);
15968 +       return new;
15969 +#ifdef CONFIG_SMP
15970 +error:
15971 +       kfree(new);
15972 +       return 0;
15973 +#endif
15974 +}
15975 +
15976 +/*     __dealloc_vx_info()
15977 +
15978 +       * final disposal of vx_info                             */
15979 +
15980 +static void __dealloc_vx_info(struct vx_info *vxi)
15981 +{
15982 +#ifdef CONFIG_VSERVER_WARN
15983 +       struct vx_info_save vxis;
15984 +       int cpu;
15985 +#endif
15986 +       vxdprintk(VXD_CBIT(xid, 0),
15987 +               "dealloc_vx_info(%p)", vxi);
15988 +       vxh_dealloc_vx_info(vxi);
15989 +
15990 +#ifdef CONFIG_VSERVER_WARN
15991 +       enter_vx_info(vxi, &vxis);
15992 +       vx_info_exit_limit(&vxi->limit);
15993 +       vx_info_exit_sched(&vxi->sched);
15994 +       vx_info_exit_cvirt(&vxi->cvirt);
15995 +       vx_info_exit_cacct(&vxi->cacct);
15996 +
15997 +       for_each_possible_cpu(cpu) {
15998 +               vx_info_exit_sched_pc(
15999 +                       &vx_per_cpu(vxi, sched_pc, cpu), cpu);
16000 +               vx_info_exit_cvirt_pc(
16001 +                       &vx_per_cpu(vxi, cvirt_pc, cpu), cpu);
16002 +       }
16003 +       leave_vx_info(&vxis);
16004 +#endif
16005 +
16006 +       vxi->vx_id = -1;
16007 +       vxi->vx_state |= VXS_RELEASED;
16008 +
16009 +#ifdef CONFIG_SMP
16010 +       free_percpu(vxi->ptr_pc);
16011 +#endif
16012 +       kfree(vxi);
16013 +       atomic_dec(&vx_global_ctotal);
16014 +}
16015 +
16016 +static void __shutdown_vx_info(struct vx_info *vxi)
16017 +{
16018 +       struct nsproxy *nsproxy;
16019 +       struct fs_struct *fs;
16020 +       struct cred *cred;
16021 +       int index, kill;
16022 +
16023 +       might_sleep();
16024 +
16025 +       vxi->vx_state |= VXS_SHUTDOWN;
16026 +       vs_state_change(vxi, VSC_SHUTDOWN);
16027 +
16028 +       for (index = 0; index < VX_SPACES; index++) {
16029 +               struct _vx_space *space = &vxi->space[index];
16030 +
16031 +               nsproxy = xchg(&space->vx_nsproxy, NULL);
16032 +               if (nsproxy)
16033 +                       put_nsproxy(nsproxy);
16034 +
16035 +               fs = xchg(&space->vx_fs, NULL);
16036 +               spin_lock(&fs->lock);
16037 +               kill = !--fs->users;
16038 +               spin_unlock(&fs->lock);
16039 +               if (kill)
16040 +                       free_fs_struct(fs);
16041 +
16042 +               cred = (struct cred *)xchg(&space->vx_cred, NULL);
16043 +               if (cred)
16044 +                       abort_creds(cred);
16045 +       }
16046 +}
16047 +
16048 +/* exported stuff */
16049 +
16050 +void free_vx_info(struct vx_info *vxi)
16051 +{
16052 +       unsigned long flags;
16053 +       unsigned index;
16054 +
16055 +       /* check for reference counts first */
16056 +       BUG_ON(atomic_read(&vxi->vx_usecnt));
16057 +       BUG_ON(atomic_read(&vxi->vx_tasks));
16058 +
16059 +       /* context must not be hashed */
16060 +       BUG_ON(vx_info_state(vxi, VXS_HASHED));
16061 +
16062 +       /* context shutdown is mandatory */
16063 +       BUG_ON(!vx_info_state(vxi, VXS_SHUTDOWN));
16064 +
16065 +       /* spaces check */
16066 +       for (index = 0; index < VX_SPACES; index++) {
16067 +               struct _vx_space *space = &vxi->space[index];
16068 +
16069 +               BUG_ON(space->vx_nsproxy);
16070 +               BUG_ON(space->vx_fs);
16071 +               // BUG_ON(space->vx_real_cred);
16072 +               // BUG_ON(space->vx_cred);
16073 +       }
16074 +
16075 +       spin_lock_irqsave(&vx_info_inactive_lock, flags);
16076 +       hlist_del(&vxi->vx_hlist);
16077 +       spin_unlock_irqrestore(&vx_info_inactive_lock, flags);
16078 +
16079 +       __dealloc_vx_info(vxi);
16080 +}
16081 +
16082 +
16083 +/*     hash table for vx_info hash */
16084 +
16085 +#define VX_HASH_SIZE   13
16086 +
16087 +static struct hlist_head vx_info_hash[VX_HASH_SIZE] =
16088 +       { [0 ... VX_HASH_SIZE-1] = HLIST_HEAD_INIT };
16089 +
16090 +static DEFINE_SPINLOCK(vx_info_hash_lock);
16091 +
16092 +
16093 +static inline unsigned int __hashval(xid_t xid)
16094 +{
16095 +       return (xid % VX_HASH_SIZE);
16096 +}
16097 +
16098 +
16099 +
16100 +/*     __hash_vx_info()
16101 +
16102 +       * add the vxi to the global hash table
16103 +       * requires the hash_lock to be held                     */
16104 +
16105 +static inline void __hash_vx_info(struct vx_info *vxi)
16106 +{
16107 +       struct hlist_head *head;
16108 +
16109 +       vxd_assert_lock(&vx_info_hash_lock);
16110 +       vxdprintk(VXD_CBIT(xid, 4),
16111 +               "__hash_vx_info: %p[#%d]", vxi, vxi->vx_id);
16112 +       vxh_hash_vx_info(vxi);
16113 +
16114 +       /* context must not be hashed */
16115 +       BUG_ON(vx_info_state(vxi, VXS_HASHED));
16116 +
16117 +       vxi->vx_state |= VXS_HASHED;
16118 +       head = &vx_info_hash[__hashval(vxi->vx_id)];
16119 +       hlist_add_head(&vxi->vx_hlist, head);
16120 +       atomic_inc(&vx_global_cactive);
16121 +}
16122 +
16123 +/*     __unhash_vx_info()
16124 +
16125 +       * remove the vxi from the global hash table
16126 +       * requires the hash_lock to be held                     */
16127 +
16128 +static inline void __unhash_vx_info(struct vx_info *vxi)
16129 +{
16130 +       unsigned long flags;
16131 +
16132 +       vxd_assert_lock(&vx_info_hash_lock);
16133 +       vxdprintk(VXD_CBIT(xid, 4),
16134 +               "__unhash_vx_info: %p[#%d.%d.%d]", vxi, vxi->vx_id,
16135 +               atomic_read(&vxi->vx_usecnt), atomic_read(&vxi->vx_tasks));
16136 +       vxh_unhash_vx_info(vxi);
16137 +
16138 +       /* context must be hashed */
16139 +       BUG_ON(!vx_info_state(vxi, VXS_HASHED));
16140 +       /* but without tasks */
16141 +       BUG_ON(atomic_read(&vxi->vx_tasks));
16142 +
16143 +       vxi->vx_state &= ~VXS_HASHED;
16144 +       hlist_del_init(&vxi->vx_hlist);
16145 +       spin_lock_irqsave(&vx_info_inactive_lock, flags);
16146 +       hlist_add_head(&vxi->vx_hlist, &vx_info_inactive);
16147 +       spin_unlock_irqrestore(&vx_info_inactive_lock, flags);
16148 +       atomic_dec(&vx_global_cactive);
16149 +}
16150 +
16151 +
16152 +/*     __lookup_vx_info()
16153 +
16154 +       * requires the hash_lock to be held
16155 +       * doesn't increment the vx_refcnt                       */
16156 +
16157 +static inline struct vx_info *__lookup_vx_info(xid_t xid)
16158 +{
16159 +       struct hlist_head *head = &vx_info_hash[__hashval(xid)];
16160 +       struct hlist_node *pos;
16161 +       struct vx_info *vxi;
16162 +
16163 +       vxd_assert_lock(&vx_info_hash_lock);
16164 +       hlist_for_each(pos, head) {
16165 +               vxi = hlist_entry(pos, struct vx_info, vx_hlist);
16166 +
16167 +               if (vxi->vx_id == xid)
16168 +                       goto found;
16169 +       }
16170 +       vxi = NULL;
16171 +found:
16172 +       vxdprintk(VXD_CBIT(xid, 0),
16173 +               "__lookup_vx_info(#%u): %p[#%u]",
16174 +               xid, vxi, vxi ? vxi->vx_id : 0);
16175 +       vxh_lookup_vx_info(vxi, xid);
16176 +       return vxi;
16177 +}
16178 +
16179 +
16180 +/*     __create_vx_info()
16181 +
16182 +       * create the requested context
16183 +       * get(), claim() and hash it                            */
16184 +
16185 +static struct vx_info *__create_vx_info(int id)
16186 +{
16187 +       struct vx_info *new, *vxi = NULL;
16188 +
16189 +       vxdprintk(VXD_CBIT(xid, 1), "create_vx_info(%d)*", id);
16190 +
16191 +       if (!(new = __alloc_vx_info(id)))
16192 +               return ERR_PTR(-ENOMEM);
16193 +
16194 +       /* required to make dynamic xids unique */
16195 +       spin_lock(&vx_info_hash_lock);
16196 +
16197 +       /* static context requested */
16198 +       if ((vxi = __lookup_vx_info(id))) {
16199 +               vxdprintk(VXD_CBIT(xid, 0),
16200 +                       "create_vx_info(%d) = %p (already there)", id, vxi);
16201 +               if (vx_info_flags(vxi, VXF_STATE_SETUP, 0))
16202 +                       vxi = ERR_PTR(-EBUSY);
16203 +               else
16204 +                       vxi = ERR_PTR(-EEXIST);
16205 +               goto out_unlock;
16206 +       }
16207 +       /* new context */
16208 +       vxdprintk(VXD_CBIT(xid, 0),
16209 +               "create_vx_info(%d) = %p (new)", id, new);
16210 +       claim_vx_info(new, NULL);
16211 +       __hash_vx_info(get_vx_info(new));
16212 +       vxi = new, new = NULL;
16213 +
16214 +out_unlock:
16215 +       spin_unlock(&vx_info_hash_lock);
16216 +       vxh_create_vx_info(IS_ERR(vxi) ? NULL : vxi, id);
16217 +       if (new)
16218 +               __dealloc_vx_info(new);
16219 +       return vxi;
16220 +}
16221 +
16222 +
16223 +/*     exported stuff                                          */
16224 +
16225 +
16226 +void unhash_vx_info(struct vx_info *vxi)
16227 +{
16228 +       spin_lock(&vx_info_hash_lock);
16229 +       __unhash_vx_info(vxi);
16230 +       spin_unlock(&vx_info_hash_lock);
16231 +       __shutdown_vx_info(vxi);
16232 +       __wakeup_vx_info(vxi);
16233 +}
16234 +
16235 +
16236 +/*     lookup_vx_info()
16237 +
16238 +       * search for a vx_info and get() it
16239 +       * negative id means current                             */
16240 +
16241 +struct vx_info *lookup_vx_info(int id)
16242 +{
16243 +       struct vx_info *vxi = NULL;
16244 +
16245 +       if (id < 0) {
16246 +               vxi = get_vx_info(current_vx_info());
16247 +       } else if (id > 1) {
16248 +               spin_lock(&vx_info_hash_lock);
16249 +               vxi = get_vx_info(__lookup_vx_info(id));
16250 +               spin_unlock(&vx_info_hash_lock);
16251 +       }
16252 +       return vxi;
16253 +}
16254 +
16255 +/*     xid_is_hashed()
16256 +
16257 +       * verify that xid is still hashed                       */
16258 +
16259 +int xid_is_hashed(xid_t xid)
16260 +{
16261 +       int hashed;
16262 +
16263 +       spin_lock(&vx_info_hash_lock);
16264 +       hashed = (__lookup_vx_info(xid) != NULL);
16265 +       spin_unlock(&vx_info_hash_lock);
16266 +       return hashed;
16267 +}
16268 +
16269 +#ifdef CONFIG_PROC_FS
16270 +
16271 +/*     get_xid_list()
16272 +
16273 +       * get a subset of hashed xids for proc
16274 +       * assumes size is at least one                          */
16275 +
16276 +int get_xid_list(int index, unsigned int *xids, int size)
16277 +{
16278 +       int hindex, nr_xids = 0;
16279 +
16280 +       /* only show current and children */
16281 +       if (!vx_check(0, VS_ADMIN | VS_WATCH)) {
16282 +               if (index > 0)
16283 +                       return 0;
16284 +               xids[nr_xids] = vx_current_xid();
16285 +               return 1;
16286 +       }
16287 +
16288 +       for (hindex = 0; hindex < VX_HASH_SIZE; hindex++) {
16289 +               struct hlist_head *head = &vx_info_hash[hindex];
16290 +               struct hlist_node *pos;
16291 +
16292 +               spin_lock(&vx_info_hash_lock);
16293 +               hlist_for_each(pos, head) {
16294 +                       struct vx_info *vxi;
16295 +
16296 +                       if (--index > 0)
16297 +                               continue;
16298 +
16299 +                       vxi = hlist_entry(pos, struct vx_info, vx_hlist);
16300 +                       xids[nr_xids] = vxi->vx_id;
16301 +                       if (++nr_xids >= size) {
16302 +                               spin_unlock(&vx_info_hash_lock);
16303 +                               goto out;
16304 +                       }
16305 +               }
16306 +               /* keep the lock time short */
16307 +               spin_unlock(&vx_info_hash_lock);
16308 +       }
16309 +out:
16310 +       return nr_xids;
16311 +}
16312 +#endif
16313 +
16314 +#ifdef CONFIG_VSERVER_DEBUG
16315 +
16316 +void   dump_vx_info_inactive(int level)
16317 +{
16318 +       struct hlist_node *entry, *next;
16319 +
16320 +       hlist_for_each_safe(entry, next, &vx_info_inactive) {
16321 +               struct vx_info *vxi =
16322 +                       list_entry(entry, struct vx_info, vx_hlist);
16323 +
16324 +               dump_vx_info(vxi, level);
16325 +       }
16326 +}
16327 +
16328 +#endif
16329 +
16330 +#if 0
16331 +int vx_migrate_user(struct task_struct *p, struct vx_info *vxi)
16332 +{
16333 +       struct user_struct *new_user, *old_user;
16334 +
16335 +       if (!p || !vxi)
16336 +               BUG();
16337 +
16338 +       if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0))
16339 +               return -EACCES;
16340 +
16341 +       new_user = alloc_uid(vxi->vx_id, p->uid);
16342 +       if (!new_user)
16343 +               return -ENOMEM;
16344 +
16345 +       old_user = p->user;
16346 +       if (new_user != old_user) {
16347 +               atomic_inc(&new_user->processes);
16348 +               atomic_dec(&old_user->processes);
16349 +               p->user = new_user;
16350 +       }
16351 +       free_uid(old_user);
16352 +       return 0;
16353 +}
16354 +#endif
16355 +
16356 +#if 0
16357 +void vx_mask_cap_bset(struct vx_info *vxi, struct task_struct *p)
16358 +{
16359 +       // p->cap_effective &= vxi->vx_cap_bset;
16360 +       p->cap_effective =
16361 +               cap_intersect(p->cap_effective, vxi->cap_bset);
16362 +       // p->cap_inheritable &= vxi->vx_cap_bset;
16363 +       p->cap_inheritable =
16364 +               cap_intersect(p->cap_inheritable, vxi->cap_bset);
16365 +       // p->cap_permitted &= vxi->vx_cap_bset;
16366 +       p->cap_permitted =
16367 +               cap_intersect(p->cap_permitted, vxi->cap_bset);
16368 +}
16369 +#endif
16370 +
16371 +
16372 +#include <linux/file.h>
16373 +#include <linux/fdtable.h>
16374 +
16375 +static int vx_openfd_task(struct task_struct *tsk)
16376 +{
16377 +       struct files_struct *files = tsk->files;
16378 +       struct fdtable *fdt;
16379 +       const unsigned long *bptr;
16380 +       int count, total;
16381 +
16382 +       /* no rcu_read_lock() because of spin_lock() */
16383 +       spin_lock(&files->file_lock);
16384 +       fdt = files_fdtable(files);
16385 +       bptr = fdt->open_fds;
16386 +       count = fdt->max_fds / (sizeof(unsigned long) * 8);
16387 +       for (total = 0; count > 0; count--) {
16388 +               if (*bptr)
16389 +                       total += hweight_long(*bptr);
16390 +               bptr++;
16391 +       }
16392 +       spin_unlock(&files->file_lock);
16393 +       return total;
16394 +}
16395 +
16396 +
16397 +/*     for *space compatibility */
16398 +
16399 +asmlinkage long sys_unshare(unsigned long);
16400 +
16401 +/*
16402 + *     migrate task to new context
16403 + *     gets vxi, puts old_vxi on change
16404 + *     optionally unshares namespaces (hack)
16405 + */
16406 +
16407 +int vx_migrate_task(struct task_struct *p, struct vx_info *vxi, int unshare)
16408 +{
16409 +       struct vx_info *old_vxi;
16410 +       int ret = 0;
16411 +
16412 +       if (!p || !vxi)
16413 +               BUG();
16414 +
16415 +       vxdprintk(VXD_CBIT(xid, 5),
16416 +               "vx_migrate_task(%p,%p[#%d.%d])", p, vxi,
16417 +               vxi->vx_id, atomic_read(&vxi->vx_usecnt));
16418 +
16419 +       if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0) &&
16420 +               !vx_info_flags(vxi, VXF_STATE_SETUP, 0))
16421 +               return -EACCES;
16422 +
16423 +       if (vx_info_state(vxi, VXS_SHUTDOWN))
16424 +               return -EFAULT;
16425 +
16426 +       old_vxi = task_get_vx_info(p);
16427 +       if (old_vxi == vxi)
16428 +               goto out;
16429 +
16430 +//     if (!(ret = vx_migrate_user(p, vxi))) {
16431 +       {
16432 +               int openfd;
16433 +
16434 +               task_lock(p);
16435 +               openfd = vx_openfd_task(p);
16436 +
16437 +               if (old_vxi) {
16438 +                       atomic_dec(&old_vxi->cvirt.nr_threads);
16439 +                       atomic_dec(&old_vxi->cvirt.nr_running);
16440 +                       __rlim_dec(&old_vxi->limit, RLIMIT_NPROC);
16441 +                       /* FIXME: what about the struct files here? */
16442 +                       __rlim_sub(&old_vxi->limit, VLIMIT_OPENFD, openfd);
16443 +                       /* account for the executable */
16444 +                       __rlim_dec(&old_vxi->limit, VLIMIT_DENTRY);
16445 +               }
16446 +               atomic_inc(&vxi->cvirt.nr_threads);
16447 +               atomic_inc(&vxi->cvirt.nr_running);
16448 +               __rlim_inc(&vxi->limit, RLIMIT_NPROC);
16449 +               /* FIXME: what about the struct files here? */
16450 +               __rlim_add(&vxi->limit, VLIMIT_OPENFD, openfd);
16451 +               /* account for the executable */
16452 +               __rlim_inc(&vxi->limit, VLIMIT_DENTRY);
16453 +
16454 +               if (old_vxi) {
16455 +                       release_vx_info(old_vxi, p);
16456 +                       clr_vx_info(&p->vx_info);
16457 +               }
16458 +               claim_vx_info(vxi, p);
16459 +               set_vx_info(&p->vx_info, vxi);
16460 +               p->xid = vxi->vx_id;
16461 +
16462 +               vxdprintk(VXD_CBIT(xid, 5),
16463 +                       "moved task %p into vxi:%p[#%d]",
16464 +                       p, vxi, vxi->vx_id);
16465 +
16466 +               // vx_mask_cap_bset(vxi, p);
16467 +               task_unlock(p);
16468 +
16469 +               /* hack for *spaces to provide compatibility */
16470 +               if (unshare) {
16471 +                       struct nsproxy *old_nsp, *new_nsp;
16472 +
16473 +                       ret = unshare_nsproxy_namespaces(
16474 +                               CLONE_NEWUTS | CLONE_NEWIPC | CLONE_NEWUSER,
16475 +                               &new_nsp, NULL);
16476 +                       if (ret)
16477 +                               goto out;
16478 +
16479 +                       old_nsp = xchg(&p->nsproxy, new_nsp);
16480 +                       vx_set_space(vxi,
16481 +                               CLONE_NEWUTS | CLONE_NEWIPC | CLONE_NEWUSER, 0);
16482 +                       put_nsproxy(old_nsp);
16483 +               }
16484 +       }
16485 +out:
16486 +       put_vx_info(old_vxi);
16487 +       return ret;
16488 +}
16489 +
16490 +int vx_set_reaper(struct vx_info *vxi, struct task_struct *p)
16491 +{
16492 +       struct task_struct *old_reaper;
16493 +       struct vx_info *reaper_vxi;
16494 +
16495 +       if (!vxi)
16496 +               return -EINVAL;
16497 +
16498 +       vxdprintk(VXD_CBIT(xid, 6),
16499 +               "vx_set_reaper(%p[#%d],%p[#%d,%d])",
16500 +               vxi, vxi->vx_id, p, p->xid, p->pid);
16501 +
16502 +       old_reaper = vxi->vx_reaper;
16503 +       if (old_reaper == p)
16504 +               return 0;
16505 +
16506 +       reaper_vxi = task_get_vx_info(p);
16507 +       if (reaper_vxi && reaper_vxi != vxi) {
16508 +               vxwprintk(1,
16509 +                       "Unsuitable reaper [" VS_Q("%s") ",%u:#%u] "
16510 +                       "for [xid #%u]",
16511 +                       p->comm, p->pid, p->xid, vx_current_xid());
16512 +               goto out;
16513 +       }
16514 +
16515 +       /* set new child reaper */
16516 +       get_task_struct(p);
16517 +       vxi->vx_reaper = p;
16518 +       put_task_struct(old_reaper);
16519 +out:
16520 +       put_vx_info(reaper_vxi);
16521 +       return 0;
16522 +}
16523 +
16524 +int vx_set_init(struct vx_info *vxi, struct task_struct *p)
16525 +{
16526 +       if (!vxi)
16527 +               return -EINVAL;
16528 +
16529 +       vxdprintk(VXD_CBIT(xid, 6),
16530 +               "vx_set_init(%p[#%d],%p[#%d,%d,%d])",
16531 +               vxi, vxi->vx_id, p, p->xid, p->pid, p->tgid);
16532 +
16533 +       vxi->vx_flags &= ~VXF_STATE_INIT;
16534 +       // vxi->vx_initpid = p->tgid;
16535 +       vxi->vx_initpid = p->pid;
16536 +       return 0;
16537 +}
16538 +
16539 +void vx_exit_init(struct vx_info *vxi, struct task_struct *p, int code)
16540 +{
16541 +       vxdprintk(VXD_CBIT(xid, 6),
16542 +               "vx_exit_init(%p[#%d],%p[#%d,%d,%d])",
16543 +               vxi, vxi->vx_id, p, p->xid, p->pid, p->tgid);
16544 +
16545 +       vxi->exit_code = code;
16546 +       vxi->vx_initpid = 0;
16547 +}
16548 +
16549 +
16550 +void vx_set_persistent(struct vx_info *vxi)
16551 +{
16552 +       vxdprintk(VXD_CBIT(xid, 6),
16553 +               "vx_set_persistent(%p[#%d])", vxi, vxi->vx_id);
16554 +
16555 +       get_vx_info(vxi);
16556 +       claim_vx_info(vxi, NULL);
16557 +}
16558 +
16559 +void vx_clear_persistent(struct vx_info *vxi)
16560 +{
16561 +       vxdprintk(VXD_CBIT(xid, 6),
16562 +               "vx_clear_persistent(%p[#%d])", vxi, vxi->vx_id);
16563 +
16564 +       release_vx_info(vxi, NULL);
16565 +       put_vx_info(vxi);
16566 +}
16567 +
16568 +void vx_update_persistent(struct vx_info *vxi)
16569 +{
16570 +       if (vx_info_flags(vxi, VXF_PERSISTENT, 0))
16571 +               vx_set_persistent(vxi);
16572 +       else
16573 +               vx_clear_persistent(vxi);
16574 +}
16575 +
16576 +
16577 +/*     task must be current or locked          */
16578 +
16579 +void   exit_vx_info(struct task_struct *p, int code)
16580 +{
16581 +       struct vx_info *vxi = p->vx_info;
16582 +
16583 +       if (vxi) {
16584 +               atomic_dec(&vxi->cvirt.nr_threads);
16585 +               vx_nproc_dec(p);
16586 +
16587 +               vxi->exit_code = code;
16588 +               release_vx_info(vxi, p);
16589 +       }
16590 +}
16591 +
16592 +void   exit_vx_info_early(struct task_struct *p, int code)
16593 +{
16594 +       struct vx_info *vxi = p->vx_info;
16595 +
16596 +       if (vxi) {
16597 +               if (vxi->vx_initpid == p->pid)
16598 +                       vx_exit_init(vxi, p, code);
16599 +               if (vxi->vx_reaper == p)
16600 +                       vx_set_reaper(vxi, init_pid_ns.child_reaper);
16601 +       }
16602 +}
16603 +
16604 +
16605 +/* vserver syscall commands below here */
16606 +
16607 +/* taks xid and vx_info functions */
16608 +
16609 +#include <asm/uaccess.h>
16610 +
16611 +
16612 +int vc_task_xid(uint32_t id)
16613 +{
16614 +       xid_t xid;
16615 +
16616 +       if (id) {
16617 +               struct task_struct *tsk;
16618 +
16619 +               rcu_read_lock();
16620 +               tsk = find_task_by_real_pid(id);
16621 +               xid = (tsk) ? tsk->xid : -ESRCH;
16622 +               rcu_read_unlock();
16623 +       } else
16624 +               xid = vx_current_xid();
16625 +       return xid;
16626 +}
16627 +
16628 +
16629 +int vc_vx_info(struct vx_info *vxi, void __user *data)
16630 +{
16631 +       struct vcmd_vx_info_v0 vc_data;
16632 +
16633 +       vc_data.xid = vxi->vx_id;
16634 +       vc_data.initpid = vxi->vx_initpid;
16635 +
16636 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16637 +               return -EFAULT;
16638 +       return 0;
16639 +}
16640 +
16641 +
16642 +int vc_ctx_stat(struct vx_info *vxi, void __user *data)
16643 +{
16644 +       struct vcmd_ctx_stat_v0 vc_data;
16645 +
16646 +       vc_data.usecnt = atomic_read(&vxi->vx_usecnt);
16647 +       vc_data.tasks = atomic_read(&vxi->vx_tasks);
16648 +
16649 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16650 +               return -EFAULT;
16651 +       return 0;
16652 +}
16653 +
16654 +
16655 +/* context functions */
16656 +
16657 +int vc_ctx_create(uint32_t xid, void __user *data)
16658 +{
16659 +       struct vcmd_ctx_create vc_data = { .flagword = VXF_INIT_SET };
16660 +       struct vx_info *new_vxi;
16661 +       int ret;
16662 +
16663 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
16664 +               return -EFAULT;
16665 +
16666 +       if ((xid > MAX_S_CONTEXT) || (xid < 2))
16667 +               return -EINVAL;
16668 +
16669 +       new_vxi = __create_vx_info(xid);
16670 +       if (IS_ERR(new_vxi))
16671 +               return PTR_ERR(new_vxi);
16672 +
16673 +       /* initial flags */
16674 +       new_vxi->vx_flags = vc_data.flagword;
16675 +
16676 +       ret = -ENOEXEC;
16677 +       if (vs_state_change(new_vxi, VSC_STARTUP))
16678 +               goto out;
16679 +
16680 +       ret = vx_migrate_task(current, new_vxi, (!data));
16681 +       if (ret)
16682 +               goto out;
16683 +
16684 +       /* return context id on success */
16685 +       ret = new_vxi->vx_id;
16686 +
16687 +       /* get a reference for persistent contexts */
16688 +       if ((vc_data.flagword & VXF_PERSISTENT))
16689 +               vx_set_persistent(new_vxi);
16690 +out:
16691 +       release_vx_info(new_vxi, NULL);
16692 +       put_vx_info(new_vxi);
16693 +       return ret;
16694 +}
16695 +
16696 +
16697 +int vc_ctx_migrate(struct vx_info *vxi, void __user *data)
16698 +{
16699 +       struct vcmd_ctx_migrate vc_data = { .flagword = 0 };
16700 +       int ret;
16701 +
16702 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
16703 +               return -EFAULT;
16704 +
16705 +       ret = vx_migrate_task(current, vxi, 0);
16706 +       if (ret)
16707 +               return ret;
16708 +       if (vc_data.flagword & VXM_SET_INIT)
16709 +               ret = vx_set_init(vxi, current);
16710 +       if (ret)
16711 +               return ret;
16712 +       if (vc_data.flagword & VXM_SET_REAPER)
16713 +               ret = vx_set_reaper(vxi, current);
16714 +       return ret;
16715 +}
16716 +
16717 +
16718 +int vc_get_cflags(struct vx_info *vxi, void __user *data)
16719 +{
16720 +       struct vcmd_ctx_flags_v0 vc_data;
16721 +
16722 +       vc_data.flagword = vxi->vx_flags;
16723 +
16724 +       /* special STATE flag handling */
16725 +       vc_data.mask = vs_mask_flags(~0ULL, vxi->vx_flags, VXF_ONE_TIME);
16726 +
16727 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16728 +               return -EFAULT;
16729 +       return 0;
16730 +}
16731 +
16732 +int vc_set_cflags(struct vx_info *vxi, void __user *data)
16733 +{
16734 +       struct vcmd_ctx_flags_v0 vc_data;
16735 +       uint64_t mask, trigger;
16736 +
16737 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16738 +               return -EFAULT;
16739 +
16740 +       /* special STATE flag handling */
16741 +       mask = vs_mask_mask(vc_data.mask, vxi->vx_flags, VXF_ONE_TIME);
16742 +       trigger = (mask & vxi->vx_flags) ^ (mask & vc_data.flagword);
16743 +
16744 +       if (vxi == current_vx_info()) {
16745 +               /* if (trigger & VXF_STATE_SETUP)
16746 +                       vx_mask_cap_bset(vxi, current); */
16747 +               if (trigger & VXF_STATE_INIT) {
16748 +                       int ret;
16749 +
16750 +                       ret = vx_set_init(vxi, current);
16751 +                       if (ret)
16752 +                               return ret;
16753 +                       ret = vx_set_reaper(vxi, current);
16754 +                       if (ret)
16755 +                               return ret;
16756 +               }
16757 +       }
16758 +
16759 +       vxi->vx_flags = vs_mask_flags(vxi->vx_flags,
16760 +               vc_data.flagword, mask);
16761 +       if (trigger & VXF_PERSISTENT)
16762 +               vx_update_persistent(vxi);
16763 +
16764 +       return 0;
16765 +}
16766 +
16767 +
16768 +static inline uint64_t caps_from_cap_t(kernel_cap_t c)
16769 +{
16770 +       uint64_t v = c.cap[0] | ((uint64_t)c.cap[1] << 32);
16771 +
16772 +       // printk("caps_from_cap_t(%08x:%08x) = %016llx\n", c.cap[1], c.cap[0], v);
16773 +       return v;
16774 +}
16775 +
16776 +static inline kernel_cap_t cap_t_from_caps(uint64_t v)
16777 +{
16778 +       kernel_cap_t c = __cap_empty_set;
16779 +
16780 +       c.cap[0] = v & 0xFFFFFFFF;
16781 +       c.cap[1] = (v >> 32) & 0xFFFFFFFF;
16782 +
16783 +       // printk("cap_t_from_caps(%016llx) = %08x:%08x\n", v, c.cap[1], c.cap[0]);
16784 +       return c;
16785 +}
16786 +
16787 +
16788 +static int do_get_caps(struct vx_info *vxi, uint64_t *bcaps, uint64_t *ccaps)
16789 +{
16790 +       if (bcaps)
16791 +               *bcaps = caps_from_cap_t(vxi->vx_bcaps);
16792 +       if (ccaps)
16793 +               *ccaps = vxi->vx_ccaps;
16794 +
16795 +       return 0;
16796 +}
16797 +
16798 +int vc_get_ccaps(struct vx_info *vxi, void __user *data)
16799 +{
16800 +       struct vcmd_ctx_caps_v1 vc_data;
16801 +       int ret;
16802 +
16803 +       ret = do_get_caps(vxi, NULL, &vc_data.ccaps);
16804 +       if (ret)
16805 +               return ret;
16806 +       vc_data.cmask = ~0ULL;
16807 +
16808 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16809 +               return -EFAULT;
16810 +       return 0;
16811 +}
16812 +
16813 +static int do_set_caps(struct vx_info *vxi,
16814 +       uint64_t bcaps, uint64_t bmask, uint64_t ccaps, uint64_t cmask)
16815 +{
16816 +       uint64_t bcold = caps_from_cap_t(vxi->vx_bcaps);
16817 +
16818 +#if 0
16819 +       printk("do_set_caps(%16llx, %16llx, %16llx, %16llx)\n",
16820 +               bcaps, bmask, ccaps, cmask);
16821 +#endif
16822 +       vxi->vx_bcaps = cap_t_from_caps(
16823 +               vs_mask_flags(bcold, bcaps, bmask));
16824 +       vxi->vx_ccaps = vs_mask_flags(vxi->vx_ccaps, ccaps, cmask);
16825 +
16826 +       return 0;
16827 +}
16828 +
16829 +int vc_set_ccaps(struct vx_info *vxi, void __user *data)
16830 +{
16831 +       struct vcmd_ctx_caps_v1 vc_data;
16832 +
16833 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16834 +               return -EFAULT;
16835 +
16836 +       return do_set_caps(vxi, 0, 0, vc_data.ccaps, vc_data.cmask);
16837 +}
16838 +
16839 +int vc_get_bcaps(struct vx_info *vxi, void __user *data)
16840 +{
16841 +       struct vcmd_bcaps vc_data;
16842 +       int ret;
16843 +
16844 +       ret = do_get_caps(vxi, &vc_data.bcaps, NULL);
16845 +       if (ret)
16846 +               return ret;
16847 +       vc_data.bmask = ~0ULL;
16848 +
16849 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16850 +               return -EFAULT;
16851 +       return 0;
16852 +}
16853 +
16854 +int vc_set_bcaps(struct vx_info *vxi, void __user *data)
16855 +{
16856 +       struct vcmd_bcaps vc_data;
16857 +
16858 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16859 +               return -EFAULT;
16860 +
16861 +       return do_set_caps(vxi, vc_data.bcaps, vc_data.bmask, 0, 0);
16862 +}
16863 +
16864 +
16865 +int vc_get_umask(struct vx_info *vxi, void __user *data)
16866 +{
16867 +       struct vcmd_umask vc_data;
16868 +
16869 +       vc_data.umask = vxi->vx_umask;
16870 +       vc_data.mask = ~0ULL;
16871 +
16872 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16873 +               return -EFAULT;
16874 +       return 0;
16875 +}
16876 +
16877 +int vc_set_umask(struct vx_info *vxi, void __user *data)
16878 +{
16879 +       struct vcmd_umask vc_data;
16880 +
16881 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16882 +               return -EFAULT;
16883 +
16884 +       vxi->vx_umask = vs_mask_flags(vxi->vx_umask,
16885 +               vc_data.umask, vc_data.mask);
16886 +       return 0;
16887 +}
16888 +
16889 +
16890 +int vc_get_wmask(struct vx_info *vxi, void __user *data)
16891 +{
16892 +       struct vcmd_wmask vc_data;
16893 +
16894 +       vc_data.wmask = vxi->vx_wmask;
16895 +       vc_data.mask = ~0ULL;
16896 +
16897 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16898 +               return -EFAULT;
16899 +       return 0;
16900 +}
16901 +
16902 +int vc_set_wmask(struct vx_info *vxi, void __user *data)
16903 +{
16904 +       struct vcmd_wmask vc_data;
16905 +
16906 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16907 +               return -EFAULT;
16908 +
16909 +       vxi->vx_wmask = vs_mask_flags(vxi->vx_wmask,
16910 +               vc_data.wmask, vc_data.mask);
16911 +       return 0;
16912 +}
16913 +
16914 +
16915 +int vc_get_badness(struct vx_info *vxi, void __user *data)
16916 +{
16917 +       struct vcmd_badness_v0 vc_data;
16918 +
16919 +       vc_data.bias = vxi->vx_badness_bias;
16920 +
16921 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16922 +               return -EFAULT;
16923 +       return 0;
16924 +}
16925 +
16926 +int vc_set_badness(struct vx_info *vxi, void __user *data)
16927 +{
16928 +       struct vcmd_badness_v0 vc_data;
16929 +
16930 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16931 +               return -EFAULT;
16932 +
16933 +       vxi->vx_badness_bias = vc_data.bias;
16934 +       return 0;
16935 +}
16936 +
16937 +#include <linux/module.h>
16938 +
16939 +EXPORT_SYMBOL_GPL(free_vx_info);
16940 +
16941 diff -NurpP --minimal linux-3.6.10/kernel/vserver/cvirt.c linux-3.6.10-vs2.3.4.5/kernel/vserver/cvirt.c
16942 --- linux-3.6.10/kernel/vserver/cvirt.c 1970-01-01 01:00:00.000000000 +0100
16943 +++ linux-3.6.10-vs2.3.4.5/kernel/vserver/cvirt.c       2012-10-04 18:47:00.000000000 +0200
16944 @@ -0,0 +1,313 @@
16945 +/*
16946 + *  linux/kernel/vserver/cvirt.c
16947 + *
16948 + *  Virtual Server: Context Virtualization
16949 + *
16950 + *  Copyright (C) 2004-2007  Herbert Pötzl
16951 + *
16952 + *  V0.01  broken out from limit.c
16953 + *  V0.02  added utsname stuff
16954 + *  V0.03  changed vcmds to vxi arg
16955 + *
16956 + */
16957 +
16958 +#include <linux/types.h>
16959 +#include <linux/utsname.h>
16960 +#include <linux/vs_cvirt.h>
16961 +#include <linux/vserver/switch.h>
16962 +#include <linux/vserver/cvirt_cmd.h>
16963 +
16964 +#include <asm/uaccess.h>
16965 +
16966 +
16967 +void vx_vsi_boottime(struct timespec *boottime)
16968 +{
16969 +       struct vx_info *vxi = current_vx_info();
16970 +
16971 +       set_normalized_timespec(boottime,
16972 +               boottime->tv_sec + vxi->cvirt.bias_uptime.tv_sec,
16973 +               boottime->tv_nsec + vxi->cvirt.bias_uptime.tv_nsec);
16974 +       return;
16975 +}
16976 +
16977 +void vx_vsi_uptime(struct timespec *uptime, struct timespec *idle)
16978 +{
16979 +       struct vx_info *vxi = current_vx_info();
16980 +
16981 +       set_normalized_timespec(uptime,
16982 +               uptime->tv_sec - vxi->cvirt.bias_uptime.tv_sec,
16983 +               uptime->tv_nsec - vxi->cvirt.bias_uptime.tv_nsec);
16984 +       if (!idle)
16985 +               return;
16986 +       set_normalized_timespec(idle,
16987 +               idle->tv_sec - vxi->cvirt.bias_idle.tv_sec,
16988 +               idle->tv_nsec - vxi->cvirt.bias_idle.tv_nsec);
16989 +       return;
16990 +}
16991 +
16992 +uint64_t vx_idle_jiffies(void)
16993 +{
16994 +       return init_task.utime + init_task.stime;
16995 +}
16996 +
16997 +
16998 +
16999 +static inline uint32_t __update_loadavg(uint32_t load,
17000 +       int wsize, int delta, int n)
17001 +{
17002 +       unsigned long long calc, prev;
17003 +
17004 +       /* just set it to n */
17005 +       if (unlikely(delta >= wsize))
17006 +               return (n << FSHIFT);
17007 +
17008 +       calc = delta * n;
17009 +       calc <<= FSHIFT;
17010 +       prev = (wsize - delta);
17011 +       prev *= load;
17012 +       calc += prev;
17013 +       do_div(calc, wsize);
17014 +       return calc;
17015 +}
17016 +
17017 +
17018 +void vx_update_load(struct vx_info *vxi)
17019 +{
17020 +       uint32_t now, last, delta;
17021 +       unsigned int nr_running, nr_uninterruptible;
17022 +       unsigned int total;
17023 +       unsigned long flags;
17024 +
17025 +       spin_lock_irqsave(&vxi->cvirt.load_lock, flags);
17026 +
17027 +       now = jiffies;
17028 +       last = vxi->cvirt.load_last;
17029 +       delta = now - last;
17030 +
17031 +       if (delta < 5*HZ)
17032 +               goto out;
17033 +
17034 +       nr_running = atomic_read(&vxi->cvirt.nr_running);
17035 +       nr_uninterruptible = atomic_read(&vxi->cvirt.nr_uninterruptible);
17036 +       total = nr_running + nr_uninterruptible;
17037 +
17038 +       vxi->cvirt.load[0] = __update_loadavg(vxi->cvirt.load[0],
17039 +               60*HZ, delta, total);
17040 +       vxi->cvirt.load[1] = __update_loadavg(vxi->cvirt.load[1],
17041 +               5*60*HZ, delta, total);
17042 +       vxi->cvirt.load[2] = __update_loadavg(vxi->cvirt.load[2],
17043 +               15*60*HZ, delta, total);
17044 +
17045 +       vxi->cvirt.load_last = now;
17046 +out:
17047 +       atomic_inc(&vxi->cvirt.load_updates);
17048 +       spin_unlock_irqrestore(&vxi->cvirt.load_lock, flags);
17049 +}
17050 +
17051 +
17052 +/*
17053 + * Commands to do_syslog:
17054 + *
17055 + *      0 -- Close the log.  Currently a NOP.
17056 + *      1 -- Open the log. Currently a NOP.
17057 + *      2 -- Read from the log.
17058 + *      3 -- Read all messages remaining in the ring buffer.
17059 + *      4 -- Read and clear all messages remaining in the ring buffer
17060 + *      5 -- Clear ring buffer.
17061 + *      6 -- Disable printk's to console
17062 + *      7 -- Enable printk's to console
17063 + *      8 -- Set level of messages printed to console
17064 + *      9 -- Return number of unread characters in the log buffer
17065 + *     10 -- Return size of the log buffer
17066 + */
17067 +int vx_do_syslog(int type, char __user *buf, int len)
17068 +{
17069 +       int error = 0;
17070 +       int do_clear = 0;
17071 +       struct vx_info *vxi = current_vx_info();
17072 +       struct _vx_syslog *log;
17073 +
17074 +       if (!vxi)
17075 +               return -EINVAL;
17076 +       log = &vxi->cvirt.syslog;
17077 +
17078 +       switch (type) {
17079 +       case 0:         /* Close log */
17080 +       case 1:         /* Open log */
17081 +               break;
17082 +       case 2:         /* Read from log */
17083 +               error = wait_event_interruptible(log->log_wait,
17084 +                       (log->log_start - log->log_end));
17085 +               if (error)
17086 +                       break;
17087 +               spin_lock_irq(&log->logbuf_lock);
17088 +               spin_unlock_irq(&log->logbuf_lock);
17089 +               break;
17090 +       case 4:         /* Read/clear last kernel messages */
17091 +               do_clear = 1;
17092 +               /* fall through */
17093 +       case 3:         /* Read last kernel messages */
17094 +               return 0;
17095 +
17096 +       case 5:         /* Clear ring buffer */
17097 +               return 0;
17098 +
17099 +       case 6:         /* Disable logging to console */
17100 +       case 7:         /* Enable logging to console */
17101 +       case 8:         /* Set level of messages printed to console */
17102 +               break;
17103 +
17104 +       case 9:         /* Number of chars in the log buffer */
17105 +               return 0;
17106 +       case 10:        /* Size of the log buffer */
17107 +               return 0;
17108 +       default:
17109 +               error = -EINVAL;
17110 +               break;
17111 +       }
17112 +       return error;
17113 +}
17114 +
17115 +
17116 +/* virtual host info names */
17117 +
17118 +static char *vx_vhi_name(struct vx_info *vxi, int id)
17119 +{
17120 +       struct nsproxy *nsproxy;
17121 +       struct uts_namespace *uts;
17122 +
17123 +       if (id == VHIN_CONTEXT)
17124 +               return vxi->vx_name;
17125 +
17126 +       nsproxy = vxi->space[0].vx_nsproxy;
17127 +       if (!nsproxy)
17128 +               return NULL;
17129 +
17130 +       uts = nsproxy->uts_ns;
17131 +       if (!uts)
17132 +               return NULL;
17133 +
17134 +       switch (id) {
17135 +       case VHIN_SYSNAME:
17136 +               return uts->name.sysname;
17137 +       case VHIN_NODENAME:
17138 +               return uts->name.nodename;
17139 +       case VHIN_RELEASE:
17140 +               return uts->name.release;
17141 +       case VHIN_VERSION:
17142 +               return uts->name.version;
17143 +       case VHIN_MACHINE:
17144 +               return uts->name.machine;
17145 +       case VHIN_DOMAINNAME:
17146 +               return uts->name.domainname;
17147 +       default:
17148 +               return NULL;
17149 +       }
17150 +       return NULL;
17151 +}
17152 +
17153 +int vc_set_vhi_name(struct vx_info *vxi, void __user *data)
17154 +{
17155 +       struct vcmd_vhi_name_v0 vc_data;
17156 +       char *name;
17157 +
17158 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17159 +               return -EFAULT;
17160 +
17161 +       name = vx_vhi_name(vxi, vc_data.field);
17162 +       if (!name)
17163 +               return -EINVAL;
17164 +
17165 +       memcpy(name, vc_data.name, 65);
17166 +       return 0;
17167 +}
17168 +
17169 +int vc_get_vhi_name(struct vx_info *vxi, void __user *data)
17170 +{
17171 +       struct vcmd_vhi_name_v0 vc_data;
17172 +       char *name;
17173 +
17174 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17175 +               return -EFAULT;
17176 +
17177 +       name = vx_vhi_name(vxi, vc_data.field);
17178 +       if (!name)
17179 +               return -EINVAL;
17180 +
17181 +       memcpy(vc_data.name, name, 65);
17182 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
17183 +               return -EFAULT;
17184 +       return 0;
17185 +}
17186 +
17187 +
17188 +int vc_virt_stat(struct vx_info *vxi, void __user *data)
17189 +{
17190 +       struct vcmd_virt_stat_v0 vc_data;
17191 +       struct _vx_cvirt *cvirt = &vxi->cvirt;
17192 +       struct timespec uptime;
17193 +
17194 +       do_posix_clock_monotonic_gettime(&uptime);
17195 +       set_normalized_timespec(&uptime,
17196 +               uptime.tv_sec - cvirt->bias_uptime.tv_sec,
17197 +               uptime.tv_nsec - cvirt->bias_uptime.tv_nsec);
17198 +
17199 +       vc_data.offset = timespec_to_ns(&cvirt->bias_ts);
17200 +       vc_data.uptime = timespec_to_ns(&uptime);
17201 +       vc_data.nr_threads = atomic_read(&cvirt->nr_threads);
17202 +       vc_data.nr_running = atomic_read(&cvirt->nr_running);
17203 +       vc_data.nr_uninterruptible = atomic_read(&cvirt->nr_uninterruptible);
17204 +       vc_data.nr_onhold = atomic_read(&cvirt->nr_onhold);
17205 +       vc_data.nr_forks = atomic_read(&cvirt->total_forks);
17206 +       vc_data.load[0] = cvirt->load[0];
17207 +       vc_data.load[1] = cvirt->load[1];
17208 +       vc_data.load[2] = cvirt->load[2];
17209 +
17210 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
17211 +               return -EFAULT;
17212 +       return 0;
17213 +}
17214 +
17215 +
17216 +#ifdef CONFIG_VSERVER_VTIME
17217 +
17218 +/* virtualized time base */
17219 +
17220 +void vx_adjust_timespec(struct timespec *ts)
17221 +{
17222 +       struct vx_info *vxi;
17223 +
17224 +       if (!vx_flags(VXF_VIRT_TIME, 0))
17225 +               return;
17226 +
17227 +       vxi = current_vx_info();
17228 +       ts->tv_sec += vxi->cvirt.bias_ts.tv_sec;
17229 +       ts->tv_nsec += vxi->cvirt.bias_ts.tv_nsec;
17230 +
17231 +       if (ts->tv_nsec >= NSEC_PER_SEC) {
17232 +               ts->tv_sec++;
17233 +               ts->tv_nsec -= NSEC_PER_SEC;
17234 +       } else if (ts->tv_nsec < 0) {
17235 +               ts->tv_sec--;
17236 +               ts->tv_nsec += NSEC_PER_SEC;
17237 +       }
17238 +}
17239 +
17240 +int vx_settimeofday(const struct timespec *ts)
17241 +{
17242 +       struct timespec ats, delta;
17243 +       struct vx_info *vxi;
17244 +
17245 +       if (!vx_flags(VXF_VIRT_TIME, 0))
17246 +               return do_settimeofday(ts);
17247 +
17248 +       getnstimeofday(&ats);
17249 +       delta = timespec_sub(*ts, ats);
17250 +
17251 +       vxi = current_vx_info();
17252 +       vxi->cvirt.bias_ts = timespec_add(vxi->cvirt.bias_ts, delta);
17253 +       return 0;
17254 +}
17255 +
17256 +#endif
17257 +
17258 diff -NurpP --minimal linux-3.6.10/kernel/vserver/cvirt_init.h linux-3.6.10-vs2.3.4.5/kernel/vserver/cvirt_init.h
17259 --- linux-3.6.10/kernel/vserver/cvirt_init.h    1970-01-01 01:00:00.000000000 +0100
17260 +++ linux-3.6.10-vs2.3.4.5/kernel/vserver/cvirt_init.h  2012-10-04 18:47:00.000000000 +0200
17261 @@ -0,0 +1,70 @@
17262 +
17263 +
17264 +extern uint64_t vx_idle_jiffies(void);
17265 +
17266 +static inline void vx_info_init_cvirt(struct _vx_cvirt *cvirt)
17267 +{
17268 +       uint64_t idle_jiffies = vx_idle_jiffies();
17269 +       uint64_t nsuptime;
17270 +
17271 +       do_posix_clock_monotonic_gettime(&cvirt->bias_uptime);
17272 +       nsuptime = (unsigned long long)cvirt->bias_uptime.tv_sec
17273 +               * NSEC_PER_SEC + cvirt->bias_uptime.tv_nsec;
17274 +       cvirt->bias_clock = nsec_to_clock_t(nsuptime);
17275 +       cvirt->bias_ts.tv_sec = 0;
17276 +       cvirt->bias_ts.tv_nsec = 0;
17277 +
17278 +       jiffies_to_timespec(idle_jiffies, &cvirt->bias_idle);
17279 +       atomic_set(&cvirt->nr_threads, 0);
17280 +       atomic_set(&cvirt->nr_running, 0);
17281 +       atomic_set(&cvirt->nr_uninterruptible, 0);
17282 +       atomic_set(&cvirt->nr_onhold, 0);
17283 +
17284 +       spin_lock_init(&cvirt->load_lock);
17285 +       cvirt->load_last = jiffies;
17286 +       atomic_set(&cvirt->load_updates, 0);
17287 +       cvirt->load[0] = 0;
17288 +       cvirt->load[1] = 0;
17289 +       cvirt->load[2] = 0;
17290 +       atomic_set(&cvirt->total_forks, 0);
17291 +
17292 +       spin_lock_init(&cvirt->syslog.logbuf_lock);
17293 +       init_waitqueue_head(&cvirt->syslog.log_wait);
17294 +       cvirt->syslog.log_start = 0;
17295 +       cvirt->syslog.log_end = 0;
17296 +       cvirt->syslog.con_start = 0;
17297 +       cvirt->syslog.logged_chars = 0;
17298 +}
17299 +
17300 +static inline
17301 +void vx_info_init_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc, int cpu)
17302 +{
17303 +       // cvirt_pc->cpustat = { 0 };
17304 +}
17305 +
17306 +static inline void vx_info_exit_cvirt(struct _vx_cvirt *cvirt)
17307 +{
17308 +#ifdef CONFIG_VSERVER_WARN
17309 +       int value;
17310 +#endif
17311 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_threads)),
17312 +               "!!! cvirt: %p[nr_threads] = %d on exit.",
17313 +               cvirt, value);
17314 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_running)),
17315 +               "!!! cvirt: %p[nr_running] = %d on exit.",
17316 +               cvirt, value);
17317 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_uninterruptible)),
17318 +               "!!! cvirt: %p[nr_uninterruptible] = %d on exit.",
17319 +               cvirt, value);
17320 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_onhold)),
17321 +               "!!! cvirt: %p[nr_onhold] = %d on exit.",
17322 +               cvirt, value);
17323 +       return;
17324 +}
17325 +
17326 +static inline
17327 +void vx_info_exit_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc, int cpu)
17328 +{
17329 +       return;
17330 +}
17331 +
17332 diff -NurpP --minimal linux-3.6.10/kernel/vserver/cvirt_proc.h linux-3.6.10-vs2.3.4.5/kernel/vserver/cvirt_proc.h
17333 --- linux-3.6.10/kernel/vserver/cvirt_proc.h    1970-01-01 01:00:00.000000000 +0100
17334 +++ linux-3.6.10-vs2.3.4.5/kernel/vserver/cvirt_proc.h  2012-10-04 18:47:00.000000000 +0200
17335 @@ -0,0 +1,123 @@
17336 +#ifndef _VX_CVIRT_PROC_H
17337 +#define _VX_CVIRT_PROC_H
17338 +
17339 +#include <linux/nsproxy.h>
17340 +#include <linux/mnt_namespace.h>
17341 +#include <linux/ipc_namespace.h>
17342 +#include <linux/utsname.h>
17343 +#include <linux/ipc.h>
17344 +
17345 +extern int vx_info_mnt_namespace(struct mnt_namespace *, char *);
17346 +
17347 +static inline
17348 +int vx_info_proc_nsproxy(struct nsproxy *nsproxy, char *buffer)
17349 +{
17350 +       struct mnt_namespace *ns;
17351 +       struct uts_namespace *uts;
17352 +       struct ipc_namespace *ipc;
17353 +       int length = 0;
17354 +
17355 +       if (!nsproxy)
17356 +               goto out;
17357 +
17358 +       length += sprintf(buffer + length,
17359 +               "NSProxy:\t%p [%p,%p,%p]\n",
17360 +               nsproxy, nsproxy->mnt_ns,
17361 +               nsproxy->uts_ns, nsproxy->ipc_ns);
17362 +
17363 +       ns = nsproxy->mnt_ns;
17364 +       if (!ns)
17365 +               goto skip_ns;
17366 +
17367 +       length += vx_info_mnt_namespace(ns, buffer + length);
17368 +
17369 +skip_ns:
17370 +
17371 +       uts = nsproxy->uts_ns;
17372 +       if (!uts)
17373 +               goto skip_uts;
17374 +
17375 +       length += sprintf(buffer + length,
17376 +               "SysName:\t%.*s\n"
17377 +               "NodeName:\t%.*s\n"
17378 +               "Release:\t%.*s\n"
17379 +               "Version:\t%.*s\n"
17380 +               "Machine:\t%.*s\n"
17381 +               "DomainName:\t%.*s\n",
17382 +               __NEW_UTS_LEN, uts->name.sysname,
17383 +               __NEW_UTS_LEN, uts->name.nodename,
17384 +               __NEW_UTS_LEN, uts->name.release,
17385 +               __NEW_UTS_LEN, uts->name.version,
17386 +               __NEW_UTS_LEN, uts->name.machine,
17387 +               __NEW_UTS_LEN, uts->name.domainname);
17388 +skip_uts:
17389 +
17390 +       ipc = nsproxy->ipc_ns;
17391 +       if (!ipc)
17392 +               goto skip_ipc;
17393 +
17394 +       length += sprintf(buffer + length,
17395 +               "SEMS:\t\t%d %d %d %d  %d\n"
17396 +               "MSG:\t\t%d %d %d\n"
17397 +               "SHM:\t\t%lu %lu  %d %d\n",
17398 +               ipc->sem_ctls[0], ipc->sem_ctls[1],
17399 +               ipc->sem_ctls[2], ipc->sem_ctls[3],
17400 +               ipc->used_sems,
17401 +               ipc->msg_ctlmax, ipc->msg_ctlmnb, ipc->msg_ctlmni,
17402 +               (unsigned long)ipc->shm_ctlmax,
17403 +               (unsigned long)ipc->shm_ctlall,
17404 +               ipc->shm_ctlmni, ipc->shm_tot);
17405 +skip_ipc:
17406 +out:
17407 +       return length;
17408 +}
17409 +
17410 +
17411 +#include <linux/sched.h>
17412 +
17413 +#define LOAD_INT(x) ((x) >> FSHIFT)
17414 +#define LOAD_FRAC(x) LOAD_INT(((x) & (FIXED_1 - 1)) * 100)
17415 +
17416 +static inline
17417 +int vx_info_proc_cvirt(struct _vx_cvirt *cvirt, char *buffer)
17418 +{
17419 +       int length = 0;
17420 +       int a, b, c;
17421 +
17422 +       length += sprintf(buffer + length,
17423 +               "BiasUptime:\t%lu.%02lu\n",
17424 +               (unsigned long)cvirt->bias_uptime.tv_sec,
17425 +               (cvirt->bias_uptime.tv_nsec / (NSEC_PER_SEC / 100)));
17426 +
17427 +       a = cvirt->load[0] + (FIXED_1 / 200);
17428 +       b = cvirt->load[1] + (FIXED_1 / 200);
17429 +       c = cvirt->load[2] + (FIXED_1 / 200);
17430 +       length += sprintf(buffer + length,
17431 +               "nr_threads:\t%d\n"
17432 +               "nr_running:\t%d\n"
17433 +               "nr_unintr:\t%d\n"
17434 +               "nr_onhold:\t%d\n"
17435 +               "load_updates:\t%d\n"
17436 +               "loadavg:\t%d.%02d %d.%02d %d.%02d\n"
17437 +               "total_forks:\t%d\n",
17438 +               atomic_read(&cvirt->nr_threads),
17439 +               atomic_read(&cvirt->nr_running),
17440 +               atomic_read(&cvirt->nr_uninterruptible),
17441 +               atomic_read(&cvirt->nr_onhold),
17442 +               atomic_read(&cvirt->load_updates),
17443 +               LOAD_INT(a), LOAD_FRAC(a),
17444 +               LOAD_INT(b), LOAD_FRAC(b),
17445 +               LOAD_INT(c), LOAD_FRAC(c),
17446 +               atomic_read(&cvirt->total_forks));
17447 +       return length;
17448 +}
17449 +
17450 +static inline
17451 +int vx_info_proc_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc,
17452 +       char *buffer, int cpu)
17453 +{
17454 +       int length = 0;
17455 +       return length;
17456 +}
17457 +
17458 +#endif /* _VX_CVIRT_PROC_H */
17459 diff -NurpP --minimal linux-3.6.10/kernel/vserver/debug.c linux-3.6.10-vs2.3.4.5/kernel/vserver/debug.c
17460 --- linux-3.6.10/kernel/vserver/debug.c 1970-01-01 01:00:00.000000000 +0100
17461 +++ linux-3.6.10-vs2.3.4.5/kernel/vserver/debug.c       2012-10-04 18:47:00.000000000 +0200
17462 @@ -0,0 +1,32 @@
17463 +/*
17464 + *  kernel/vserver/debug.c
17465 + *
17466 + *  Copyright (C) 2005-2007 Herbert Pötzl
17467 + *
17468 + *  V0.01  vx_info dump support
17469 + *
17470 + */
17471 +
17472 +#include <linux/module.h>
17473 +
17474 +#include <linux/vserver/context.h>
17475 +
17476 +
17477 +void   dump_vx_info(struct vx_info *vxi, int level)
17478 +{
17479 +       printk("vx_info %p[#%d, %d.%d, %4x]\n", vxi, vxi->vx_id,
17480 +               atomic_read(&vxi->vx_usecnt),
17481 +               atomic_read(&vxi->vx_tasks),
17482 +               vxi->vx_state);
17483 +       if (level > 0) {
17484 +               __dump_vx_limit(&vxi->limit);
17485 +               __dump_vx_sched(&vxi->sched);
17486 +               __dump_vx_cvirt(&vxi->cvirt);
17487 +               __dump_vx_cacct(&vxi->cacct);
17488 +       }
17489 +       printk("---\n");
17490 +}
17491 +
17492 +
17493 +EXPORT_SYMBOL_GPL(dump_vx_info);
17494 +
17495 diff -NurpP --minimal linux-3.6.10/kernel/vserver/device.c linux-3.6.10-vs2.3.4.5/kernel/vserver/device.c
17496 --- linux-3.6.10/kernel/vserver/device.c        1970-01-01 01:00:00.000000000 +0100
17497 +++ linux-3.6.10-vs2.3.4.5/kernel/vserver/device.c      2012-10-04 18:47:00.000000000 +0200
17498 @@ -0,0 +1,443 @@
17499 +/*
17500 + *  linux/kernel/vserver/device.c
17501 + *
17502 + *  Linux-VServer: Device Support
17503 + *
17504 + *  Copyright (C) 2006  Herbert Pötzl
17505 + *  Copyright (C) 2007  Daniel Hokka Zakrisson
17506 + *
17507 + *  V0.01  device mapping basics
17508 + *  V0.02  added defaults
17509 + *
17510 + */
17511 +
17512 +#include <linux/slab.h>
17513 +#include <linux/rcupdate.h>
17514 +#include <linux/fs.h>
17515 +#include <linux/namei.h>
17516 +#include <linux/hash.h>
17517 +
17518 +#include <asm/errno.h>
17519 +#include <asm/uaccess.h>
17520 +#include <linux/vserver/base.h>
17521 +#include <linux/vserver/debug.h>
17522 +#include <linux/vserver/context.h>
17523 +#include <linux/vserver/device.h>
17524 +#include <linux/vserver/device_cmd.h>
17525 +
17526 +
17527 +#define DMAP_HASH_BITS 4
17528 +
17529 +
17530 +struct vs_mapping {
17531 +       union {
17532 +               struct hlist_node hlist;
17533 +               struct list_head list;
17534 +       } u;
17535 +#define dm_hlist       u.hlist
17536 +#define dm_list                u.list
17537 +       xid_t xid;
17538 +       dev_t device;
17539 +       struct vx_dmap_target target;
17540 +};
17541 +
17542 +
17543 +static struct hlist_head dmap_main_hash[1 << DMAP_HASH_BITS];
17544 +
17545 +static DEFINE_SPINLOCK(dmap_main_hash_lock);
17546 +
17547 +static struct vx_dmap_target dmap_defaults[2] = {
17548 +       { .flags = DATTR_OPEN },
17549 +       { .flags = DATTR_OPEN },
17550 +};
17551 +
17552 +
17553 +struct kmem_cache *dmap_cachep __read_mostly;
17554 +
17555 +int __init dmap_cache_init(void)
17556 +{
17557 +       dmap_cachep = kmem_cache_create("dmap_cache",
17558 +               sizeof(struct vs_mapping), 0,
17559 +               SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
17560 +       return 0;
17561 +}
17562 +
17563 +__initcall(dmap_cache_init);
17564 +
17565 +
17566 +static inline unsigned int __hashval(dev_t dev, int bits)
17567 +{
17568 +       return hash_long((unsigned long)dev, bits);
17569 +}
17570 +
17571 +
17572 +/*     __hash_mapping()
17573 + *     add the mapping to the hash table
17574 + */
17575 +static inline void __hash_mapping(struct vx_info *vxi, struct vs_mapping *vdm)
17576 +{
17577 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
17578 +       struct hlist_head *head, *hash = dmap_main_hash;
17579 +       int device = vdm->device;
17580 +
17581 +       spin_lock(hash_lock);
17582 +       vxdprintk(VXD_CBIT(misc, 8), "__hash_mapping: %p[#%d] %08x:%08x",
17583 +               vxi, vxi ? vxi->vx_id : 0, device, vdm->target.target);
17584 +
17585 +       head = &hash[__hashval(device, DMAP_HASH_BITS)];
17586 +       hlist_add_head(&vdm->dm_hlist, head);
17587 +       spin_unlock(hash_lock);
17588 +}
17589 +
17590 +
17591 +static inline int __mode_to_default(umode_t mode)
17592 +{
17593 +       switch (mode) {
17594 +       case S_IFBLK:
17595 +               return 0;
17596 +       case S_IFCHR:
17597 +               return 1;
17598 +       default:
17599 +               BUG();
17600 +       }
17601 +}
17602 +
17603 +
17604 +/*     __set_default()
17605 + *     set a default
17606 + */
17607 +static inline void __set_default(struct vx_info *vxi, umode_t mode,
17608 +       struct vx_dmap_target *vdmt)
17609 +{
17610 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
17611 +       spin_lock(hash_lock);
17612 +
17613 +       if (vxi)
17614 +               vxi->dmap.targets[__mode_to_default(mode)] = *vdmt;
17615 +       else
17616 +               dmap_defaults[__mode_to_default(mode)] = *vdmt;
17617 +
17618 +
17619 +       spin_unlock(hash_lock);
17620 +
17621 +       vxdprintk(VXD_CBIT(misc, 8), "__set_default: %p[#%u] %08x %04x",
17622 +                 vxi, vxi ? vxi->vx_id : 0, vdmt->target, vdmt->flags);
17623 +}
17624 +
17625 +
17626 +/*     __remove_default()
17627 + *     remove a default
17628 + */
17629 +static inline int __remove_default(struct vx_info *vxi, umode_t mode)
17630 +{
17631 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
17632 +       spin_lock(hash_lock);
17633 +
17634 +       if (vxi)
17635 +               vxi->dmap.targets[__mode_to_default(mode)].flags = 0;
17636 +       else    /* remove == reset */
17637 +               dmap_defaults[__mode_to_default(mode)].flags = DATTR_OPEN | mode;
17638 +
17639 +       spin_unlock(hash_lock);
17640 +       return 0;
17641 +}
17642 +
17643 +
17644 +/*     __find_mapping()
17645 + *     find a mapping in the hash table
17646 + *
17647 + *     caller must hold hash_lock
17648 + */
17649 +static inline int __find_mapping(xid_t xid, dev_t device, umode_t mode,
17650 +       struct vs_mapping **local, struct vs_mapping **global)
17651 +{
17652 +       struct hlist_head *hash = dmap_main_hash;
17653 +       struct hlist_head *head = &hash[__hashval(device, DMAP_HASH_BITS)];
17654 +       struct hlist_node *pos;
17655 +       struct vs_mapping *vdm;
17656 +
17657 +       *local = NULL;
17658 +       if (global)
17659 +               *global = NULL;
17660 +
17661 +       hlist_for_each(pos, head) {
17662 +               vdm = hlist_entry(pos, struct vs_mapping, dm_hlist);
17663 +
17664 +               if ((vdm->device == device) &&
17665 +                       !((vdm->target.flags ^ mode) & S_IFMT)) {
17666 +                       if (vdm->xid == xid) {
17667 +                               *local = vdm;
17668 +                               return 1;
17669 +                       } else if (global && vdm->xid == 0)
17670 +                               *global = vdm;
17671 +               }
17672 +       }
17673 +
17674 +       if (global && *global)
17675 +               return 0;
17676 +       else
17677 +               return -ENOENT;
17678 +}
17679 +
17680 +
17681 +/*     __lookup_mapping()
17682 + *     find a mapping and store the result in target and flags
17683 + */
17684 +static inline int __lookup_mapping(struct vx_info *vxi,
17685 +       dev_t device, dev_t *target, int *flags, umode_t mode)
17686 +{
17687 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
17688 +       struct vs_mapping *vdm, *global;
17689 +       struct vx_dmap_target *vdmt;
17690 +       int ret = 0;
17691 +       xid_t xid = vxi->vx_id;
17692 +       int index;
17693 +
17694 +       spin_lock(hash_lock);
17695 +       if (__find_mapping(xid, device, mode, &vdm, &global) > 0) {
17696 +               ret = 1;
17697 +               vdmt = &vdm->target;
17698 +               goto found;
17699 +       }
17700 +
17701 +       index = __mode_to_default(mode);
17702 +       if (vxi && vxi->dmap.targets[index].flags) {
17703 +               ret = 2;
17704 +               vdmt = &vxi->dmap.targets[index];
17705 +       } else if (global) {
17706 +               ret = 3;
17707 +               vdmt = &global->target;
17708 +               goto found;
17709 +       } else {
17710 +               ret = 4;
17711 +               vdmt = &dmap_defaults[index];
17712 +       }
17713 +
17714 +found:
17715 +       if (target && (vdmt->flags & DATTR_REMAP))
17716 +               *target = vdmt->target;
17717 +       else if (target)
17718 +               *target = device;
17719 +       if (flags)
17720 +               *flags = vdmt->flags;
17721 +
17722 +       spin_unlock(hash_lock);
17723 +
17724 +       return ret;
17725 +}
17726 +
17727 +
17728 +/*     __remove_mapping()
17729 + *     remove a mapping from the hash table
17730 + */
17731 +static inline int __remove_mapping(struct vx_info *vxi, dev_t device,
17732 +       umode_t mode)
17733 +{
17734 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
17735 +       struct vs_mapping *vdm = NULL;
17736 +       int ret = 0;
17737 +
17738 +       spin_lock(hash_lock);
17739 +
17740 +       ret = __find_mapping((vxi ? vxi->vx_id : 0), device, mode, &vdm,
17741 +               NULL);
17742 +       vxdprintk(VXD_CBIT(misc, 8), "__remove_mapping: %p[#%d] %08x %04x",
17743 +               vxi, vxi ? vxi->vx_id : 0, device, mode);
17744 +       if (ret < 0)
17745 +               goto out;
17746 +       hlist_del(&vdm->dm_hlist);
17747 +
17748 +out:
17749 +       spin_unlock(hash_lock);
17750 +       if (vdm)
17751 +               kmem_cache_free(dmap_cachep, vdm);
17752 +       return ret;
17753 +}
17754 +
17755 +
17756 +
17757 +int vs_map_device(struct vx_info *vxi,
17758 +       dev_t device, dev_t *target, umode_t mode)
17759 +{
17760 +       int ret, flags = DATTR_MASK;
17761 +
17762 +       if (!vxi) {
17763 +               if (target)
17764 +                       *target = device;
17765 +               goto out;
17766 +       }
17767 +       ret = __lookup_mapping(vxi, device, target, &flags, mode);
17768 +       vxdprintk(VXD_CBIT(misc, 8), "vs_map_device: %08x target: %08x flags: %04x mode: %04x mapped=%d",
17769 +               device, target ? *target : 0, flags, mode, ret);
17770 +out:
17771 +       return (flags & DATTR_MASK);
17772 +}
17773 +
17774 +
17775 +
17776 +static int do_set_mapping(struct vx_info *vxi,
17777 +       dev_t device, dev_t target, int flags, umode_t mode)
17778 +{
17779 +       if (device) {
17780 +               struct vs_mapping *new;
17781 +
17782 +               new = kmem_cache_alloc(dmap_cachep, GFP_KERNEL);
17783 +               if (!new)
17784 +                       return -ENOMEM;
17785 +
17786 +               INIT_HLIST_NODE(&new->dm_hlist);
17787 +               new->device = device;
17788 +               new->target.target = target;
17789 +               new->target.flags = flags | mode;
17790 +               new->xid = (vxi ? vxi->vx_id : 0);
17791 +
17792 +               vxdprintk(VXD_CBIT(misc, 8), "do_set_mapping: %08x target: %08x flags: %04x", device, target, flags);
17793 +               __hash_mapping(vxi, new);
17794 +       } else {
17795 +               struct vx_dmap_target new = {
17796 +                       .target = target,
17797 +                       .flags = flags | mode,
17798 +               };
17799 +               __set_default(vxi, mode, &new);
17800 +       }
17801 +       return 0;
17802 +}
17803 +
17804 +
17805 +static int do_unset_mapping(struct vx_info *vxi,
17806 +       dev_t device, dev_t target, int flags, umode_t mode)
17807 +{
17808 +       int ret = -EINVAL;
17809 +
17810 +       if (device) {
17811 +               ret = __remove_mapping(vxi, device, mode);
17812 +               if (ret < 0)
17813 +                       goto out;
17814 +       } else {
17815 +               ret = __remove_default(vxi, mode);
17816 +               if (ret < 0)
17817 +                       goto out;
17818 +       }
17819 +
17820 +out:
17821 +       return ret;
17822 +}
17823 +
17824 +
17825 +static inline int __user_device(const char __user *name, dev_t *dev,
17826 +       umode_t *mode)
17827 +{
17828 +       struct nameidata nd;
17829 +       int ret;
17830 +
17831 +       if (!name) {
17832 +               *dev = 0;
17833 +               return 0;
17834 +       }
17835 +       ret = user_lpath(name, &nd.path);
17836 +       if (ret)
17837 +               return ret;
17838 +       if (nd.path.dentry->d_inode) {
17839 +               *dev = nd.path.dentry->d_inode->i_rdev;
17840 +               *mode = nd.path.dentry->d_inode->i_mode;
17841 +       }
17842 +       path_put(&nd.path);
17843 +       return 0;
17844 +}
17845 +
17846 +static inline int __mapping_mode(dev_t device, dev_t target,
17847 +       umode_t device_mode, umode_t target_mode, umode_t *mode)
17848 +{
17849 +       if (device)
17850 +               *mode = device_mode & S_IFMT;
17851 +       else if (target)
17852 +               *mode = target_mode & S_IFMT;
17853 +       else
17854 +               return -EINVAL;
17855 +
17856 +       /* if both given, device and target mode have to match */
17857 +       if (device && target &&
17858 +               ((device_mode ^ target_mode) & S_IFMT))
17859 +               return -EINVAL;
17860 +       return 0;
17861 +}
17862 +
17863 +
17864 +static inline int do_mapping(struct vx_info *vxi, const char __user *device_path,
17865 +       const char __user *target_path, int flags, int set)
17866 +{
17867 +       dev_t device = ~0, target = ~0;
17868 +       umode_t device_mode = 0, target_mode = 0, mode;
17869 +       int ret;
17870 +
17871 +       ret = __user_device(device_path, &device, &device_mode);
17872 +       if (ret)
17873 +               return ret;
17874 +       ret = __user_device(target_path, &target, &target_mode);
17875 +       if (ret)
17876 +               return ret;
17877 +
17878 +       ret = __mapping_mode(device, target,
17879 +               device_mode, target_mode, &mode);
17880 +       if (ret)
17881 +               return ret;
17882 +
17883 +       if (set)
17884 +               return do_set_mapping(vxi, device, target,
17885 +                       flags, mode);
17886 +       else
17887 +               return do_unset_mapping(vxi, device, target,
17888 +                       flags, mode);
17889 +}
17890 +
17891 +
17892 +int vc_set_mapping(struct vx_info *vxi, void __user *data)
17893 +{
17894 +       struct vcmd_set_mapping_v0 vc_data;
17895 +
17896 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17897 +               return -EFAULT;
17898 +
17899 +       return do_mapping(vxi, vc_data.device, vc_data.target,
17900 +               vc_data.flags, 1);
17901 +}
17902 +
17903 +int vc_unset_mapping(struct vx_info *vxi, void __user *data)
17904 +{
17905 +       struct vcmd_set_mapping_v0 vc_data;
17906 +
17907 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17908 +               return -EFAULT;
17909 +
17910 +       return do_mapping(vxi, vc_data.device, vc_data.target,
17911 +               vc_data.flags, 0);
17912 +}
17913 +
17914 +
17915 +#ifdef CONFIG_COMPAT
17916 +
17917 +int vc_set_mapping_x32(struct vx_info *vxi, void __user *data)
17918 +{
17919 +       struct vcmd_set_mapping_v0_x32 vc_data;
17920 +
17921 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17922 +               return -EFAULT;
17923 +
17924 +       return do_mapping(vxi, compat_ptr(vc_data.device_ptr),
17925 +               compat_ptr(vc_data.target_ptr), vc_data.flags, 1);
17926 +}
17927 +
17928 +int vc_unset_mapping_x32(struct vx_info *vxi, void __user *data)
17929 +{
17930 +       struct vcmd_set_mapping_v0_x32 vc_data;
17931 +
17932 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17933 +               return -EFAULT;
17934 +
17935 +       return do_mapping(vxi, compat_ptr(vc_data.device_ptr),
17936 +               compat_ptr(vc_data.target_ptr), vc_data.flags, 0);
17937 +}
17938 +
17939 +#endif /* CONFIG_COMPAT */
17940 +
17941 +
17942 diff -NurpP --minimal linux-3.6.10/kernel/vserver/dlimit.c linux-3.6.10-vs2.3.4.5/kernel/vserver/dlimit.c
17943 --- linux-3.6.10/kernel/vserver/dlimit.c        1970-01-01 01:00:00.000000000 +0100
17944 +++ linux-3.6.10-vs2.3.4.5/kernel/vserver/dlimit.c      2012-10-04 18:47:00.000000000 +0200
17945 @@ -0,0 +1,531 @@
17946 +/*
17947 + *  linux/kernel/vserver/dlimit.c
17948 + *
17949 + *  Virtual Server: Context Disk Limits
17950 + *
17951 + *  Copyright (C) 2004-2009  Herbert Pötzl
17952 + *
17953 + *  V0.01  initial version
17954 + *  V0.02  compat32 splitup
17955 + *  V0.03  extended interface
17956 + *
17957 + */
17958 +
17959 +#include <linux/statfs.h>
17960 +#include <linux/sched.h>
17961 +#include <linux/namei.h>
17962 +#include <linux/vs_tag.h>
17963 +#include <linux/vs_dlimit.h>
17964 +#include <linux/vserver/dlimit_cmd.h>
17965 +#include <linux/slab.h>
17966 +// #include <linux/gfp.h>
17967 +
17968 +#include <asm/uaccess.h>
17969 +
17970 +/*     __alloc_dl_info()
17971 +
17972 +       * allocate an initialized dl_info struct
17973 +       * doesn't make it visible (hash)                        */
17974 +
17975 +static struct dl_info *__alloc_dl_info(struct super_block *sb, tag_t tag)
17976 +{
17977 +       struct dl_info *new = NULL;
17978 +
17979 +       vxdprintk(VXD_CBIT(dlim, 5),
17980 +               "alloc_dl_info(%p,%d)*", sb, tag);
17981 +
17982 +       /* would this benefit from a slab cache? */
17983 +       new = kmalloc(sizeof(struct dl_info), GFP_KERNEL);
17984 +       if (!new)
17985 +               return 0;
17986 +
17987 +       memset(new, 0, sizeof(struct dl_info));
17988 +       new->dl_tag = tag;
17989 +       new->dl_sb = sb;
17990 +       // INIT_RCU_HEAD(&new->dl_rcu);
17991 +       INIT_HLIST_NODE(&new->dl_hlist);
17992 +       spin_lock_init(&new->dl_lock);
17993 +       atomic_set(&new->dl_refcnt, 0);
17994 +       atomic_set(&new->dl_usecnt, 0);
17995 +
17996 +       /* rest of init goes here */
17997 +
17998 +       vxdprintk(VXD_CBIT(dlim, 4),
17999 +               "alloc_dl_info(%p,%d) = %p", sb, tag, new);
18000 +       return new;
18001 +}
18002 +
18003 +/*     __dealloc_dl_info()
18004 +
18005 +       * final disposal of dl_info                             */
18006 +
18007 +static void __dealloc_dl_info(struct dl_info *dli)
18008 +{
18009 +       vxdprintk(VXD_CBIT(dlim, 4),
18010 +               "dealloc_dl_info(%p)", dli);
18011 +
18012 +       dli->dl_hlist.next = LIST_POISON1;
18013 +       dli->dl_tag = -1;
18014 +       dli->dl_sb = 0;
18015 +
18016 +       BUG_ON(atomic_read(&dli->dl_usecnt));
18017 +       BUG_ON(atomic_read(&dli->dl_refcnt));
18018 +
18019 +       kfree(dli);
18020 +}
18021 +
18022 +
18023 +/*     hash table for dl_info hash */
18024 +
18025 +#define DL_HASH_SIZE   13
18026 +
18027 +struct hlist_head dl_info_hash[DL_HASH_SIZE];
18028 +
18029 +static DEFINE_SPINLOCK(dl_info_hash_lock);
18030 +
18031 +
18032 +static inline unsigned int __hashval(struct super_block *sb, tag_t tag)
18033 +{
18034 +       return ((tag ^ (unsigned long)sb) % DL_HASH_SIZE);
18035 +}
18036 +
18037 +
18038 +
18039 +/*     __hash_dl_info()
18040 +
18041 +       * add the dli to the global hash table
18042 +       * requires the hash_lock to be held                     */
18043 +
18044 +static inline void __hash_dl_info(struct dl_info *dli)
18045 +{
18046 +       struct hlist_head *head;
18047 +
18048 +       vxdprintk(VXD_CBIT(dlim, 6),
18049 +               "__hash_dl_info: %p[#%d]", dli, dli->dl_tag);
18050 +       get_dl_info(dli);
18051 +       head = &dl_info_hash[__hashval(dli->dl_sb, dli->dl_tag)];
18052 +       hlist_add_head_rcu(&dli->dl_hlist, head);
18053 +}
18054 +
18055 +/*     __unhash_dl_info()
18056 +
18057 +       * remove the dli from the global hash table
18058 +       * requires the hash_lock to be held                     */
18059 +
18060 +static inline void __unhash_dl_info(struct dl_info *dli)
18061 +{
18062 +       vxdprintk(VXD_CBIT(dlim, 6),
18063 +               "__unhash_dl_info: %p[#%d]", dli, dli->dl_tag);
18064 +       hlist_del_rcu(&dli->dl_hlist);
18065 +       put_dl_info(dli);
18066 +}
18067 +
18068 +
18069 +/*     __lookup_dl_info()
18070 +
18071 +       * requires the rcu_read_lock()
18072 +       * doesn't increment the dl_refcnt                       */
18073 +
18074 +static inline struct dl_info *__lookup_dl_info(struct super_block *sb, tag_t tag)
18075 +{
18076 +       struct hlist_head *head = &dl_info_hash[__hashval(sb, tag)];
18077 +       struct hlist_node *pos;
18078 +       struct dl_info *dli;
18079 +
18080 +       hlist_for_each_entry_rcu(dli, pos, head, dl_hlist) {
18081 +
18082 +               if (dli->dl_tag == tag && dli->dl_sb == sb) {
18083 +                       return dli;
18084 +               }
18085 +       }
18086 +       return NULL;
18087 +}
18088 +
18089 +
18090 +struct dl_info *locate_dl_info(struct super_block *sb, tag_t tag)
18091 +{
18092 +       struct dl_info *dli;
18093 +
18094 +       rcu_read_lock();
18095 +       dli = get_dl_info(__lookup_dl_info(sb, tag));
18096 +       vxdprintk(VXD_CBIT(dlim, 7),
18097 +               "locate_dl_info(%p,#%d) = %p", sb, tag, dli);
18098 +       rcu_read_unlock();
18099 +       return dli;
18100 +}
18101 +
18102 +void rcu_free_dl_info(struct rcu_head *head)
18103 +{
18104 +       struct dl_info *dli = container_of(head, struct dl_info, dl_rcu);
18105 +       int usecnt, refcnt;
18106 +
18107 +       BUG_ON(!dli || !head);
18108 +
18109 +       usecnt = atomic_read(&dli->dl_usecnt);
18110 +       BUG_ON(usecnt < 0);
18111 +
18112 +       refcnt = atomic_read(&dli->dl_refcnt);
18113 +       BUG_ON(refcnt < 0);
18114 +
18115 +       vxdprintk(VXD_CBIT(dlim, 3),
18116 +               "rcu_free_dl_info(%p)", dli);
18117 +       if (!usecnt)
18118 +               __dealloc_dl_info(dli);
18119 +       else
18120 +               printk("!!! rcu didn't free\n");
18121 +}
18122 +
18123 +
18124 +
18125 +
18126 +static int do_addrem_dlimit(uint32_t id, const char __user *name,
18127 +       uint32_t flags, int add)
18128 +{
18129 +       struct path path;
18130 +       int ret;
18131 +
18132 +       ret = user_lpath(name, &path);
18133 +       if (!ret) {
18134 +               struct super_block *sb;
18135 +               struct dl_info *dli;
18136 +
18137 +               ret = -EINVAL;
18138 +               if (!path.dentry->d_inode)
18139 +                       goto out_release;
18140 +               if (!(sb = path.dentry->d_inode->i_sb))
18141 +                       goto out_release;
18142 +
18143 +               if (add) {
18144 +                       dli = __alloc_dl_info(sb, id);
18145 +                       spin_lock(&dl_info_hash_lock);
18146 +
18147 +                       ret = -EEXIST;
18148 +                       if (__lookup_dl_info(sb, id))
18149 +                               goto out_unlock;
18150 +                       __hash_dl_info(dli);
18151 +                       dli = NULL;
18152 +               } else {
18153 +                       spin_lock(&dl_info_hash_lock);
18154 +                       dli = __lookup_dl_info(sb, id);
18155 +
18156 +                       ret = -ESRCH;
18157 +                       if (!dli)
18158 +                               goto out_unlock;
18159 +                       __unhash_dl_info(dli);
18160 +               }
18161 +               ret = 0;
18162 +       out_unlock:
18163 +               spin_unlock(&dl_info_hash_lock);
18164 +               if (add && dli)
18165 +                       __dealloc_dl_info(dli);
18166 +       out_release:
18167 +               path_put(&path);
18168 +       }
18169 +       return ret;
18170 +}
18171 +
18172 +int vc_add_dlimit(uint32_t id, void __user *data)
18173 +{
18174 +       struct vcmd_ctx_dlimit_base_v0 vc_data;
18175 +
18176 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18177 +               return -EFAULT;
18178 +
18179 +       return do_addrem_dlimit(id, vc_data.name, vc_data.flags, 1);
18180 +}
18181 +
18182 +int vc_rem_dlimit(uint32_t id, void __user *data)
18183 +{
18184 +       struct vcmd_ctx_dlimit_base_v0 vc_data;
18185 +
18186 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18187 +               return -EFAULT;
18188 +
18189 +       return do_addrem_dlimit(id, vc_data.name, vc_data.flags, 0);
18190 +}
18191 +
18192 +#ifdef CONFIG_COMPAT
18193 +
18194 +int vc_add_dlimit_x32(uint32_t id, void __user *data)
18195 +{
18196 +       struct vcmd_ctx_dlimit_base_v0_x32 vc_data;
18197 +
18198 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18199 +               return -EFAULT;
18200 +
18201 +       return do_addrem_dlimit(id,
18202 +               compat_ptr(vc_data.name_ptr), vc_data.flags, 1);
18203 +}
18204 +
18205 +int vc_rem_dlimit_x32(uint32_t id, void __user *data)
18206 +{
18207 +       struct vcmd_ctx_dlimit_base_v0_x32 vc_data;
18208 +
18209 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18210 +               return -EFAULT;
18211 +
18212 +       return do_addrem_dlimit(id,
18213 +               compat_ptr(vc_data.name_ptr), vc_data.flags, 0);
18214 +}
18215 +
18216 +#endif /* CONFIG_COMPAT */
18217 +
18218 +
18219 +static inline
18220 +int do_set_dlimit(uint32_t id, const char __user *name,
18221 +       uint32_t space_used, uint32_t space_total,
18222 +       uint32_t inodes_used, uint32_t inodes_total,
18223 +       uint32_t reserved, uint32_t flags)
18224 +{
18225 +       struct path path;
18226 +       int ret;
18227 +
18228 +       ret = user_lpath(name, &path);
18229 +       if (!ret) {
18230 +               struct super_block *sb;
18231 +               struct dl_info *dli;
18232 +
18233 +               ret = -EINVAL;
18234 +               if (!path.dentry->d_inode)
18235 +                       goto out_release;
18236 +               if (!(sb = path.dentry->d_inode->i_sb))
18237 +                       goto out_release;
18238 +
18239 +               /* sanity checks */
18240 +               if ((reserved != CDLIM_KEEP &&
18241 +                       reserved > 100) ||
18242 +                       (inodes_used != CDLIM_KEEP &&
18243 +                       inodes_used > inodes_total) ||
18244 +                       (space_used != CDLIM_KEEP &&
18245 +                       space_used > space_total))
18246 +                       goto out_release;
18247 +
18248 +               ret = -ESRCH;
18249 +               dli = locate_dl_info(sb, id);
18250 +               if (!dli)
18251 +                       goto out_release;
18252 +
18253 +               spin_lock(&dli->dl_lock);
18254 +
18255 +               if (inodes_used != CDLIM_KEEP)
18256 +                       dli->dl_inodes_used = inodes_used;
18257 +               if (inodes_total != CDLIM_KEEP)
18258 +                       dli->dl_inodes_total = inodes_total;
18259 +               if (space_used != CDLIM_KEEP)
18260 +                       dli->dl_space_used = dlimit_space_32to64(
18261 +                               space_used, flags, DLIMS_USED);
18262 +
18263 +               if (space_total == CDLIM_INFINITY)
18264 +                       dli->dl_space_total = DLIM_INFINITY;
18265 +               else if (space_total != CDLIM_KEEP)
18266 +                       dli->dl_space_total = dlimit_space_32to64(
18267 +                               space_total, flags, DLIMS_TOTAL);
18268 +
18269 +               if (reserved != CDLIM_KEEP)
18270 +                       dli->dl_nrlmult = (1 << 10) * (100 - reserved) / 100;
18271 +
18272 +               spin_unlock(&dli->dl_lock);
18273 +
18274 +               put_dl_info(dli);
18275 +               ret = 0;
18276 +
18277 +       out_release:
18278 +               path_put(&path);
18279 +       }
18280 +       return ret;
18281 +}
18282 +
18283 +int vc_set_dlimit(uint32_t id, void __user *data)
18284 +{
18285 +       struct vcmd_ctx_dlimit_v0 vc_data;
18286 +
18287 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18288 +               return -EFAULT;
18289 +
18290 +       return do_set_dlimit(id, vc_data.name,
18291 +               vc_data.space_used, vc_data.space_total,
18292 +               vc_data.inodes_used, vc_data.inodes_total,
18293 +               vc_data.reserved, vc_data.flags);
18294 +}
18295 +
18296 +#ifdef CONFIG_COMPAT
18297 +
18298 +int vc_set_dlimit_x32(uint32_t id, void __user *data)
18299 +{
18300 +       struct vcmd_ctx_dlimit_v0_x32 vc_data;
18301 +
18302 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18303 +               return -EFAULT;
18304 +
18305 +       return do_set_dlimit(id, compat_ptr(vc_data.name_ptr),
18306 +               vc_data.space_used, vc_data.space_total,
18307 +               vc_data.inodes_used, vc_data.inodes_total,
18308 +               vc_data.reserved, vc_data.flags);
18309 +}
18310 +
18311 +#endif /* CONFIG_COMPAT */
18312 +
18313 +
18314 +static inline
18315 +int do_get_dlimit(uint32_t id, const char __user *name,
18316 +       uint32_t *space_used, uint32_t *space_total,
18317 +       uint32_t *inodes_used, uint32_t *inodes_total,
18318 +       uint32_t *reserved, uint32_t *flags)
18319 +{
18320 +       struct path path;
18321 +       int ret;
18322 +
18323 +       ret = user_lpath(name, &path);
18324 +       if (!ret) {
18325 +               struct super_block *sb;
18326 +               struct dl_info *dli;
18327 +
18328 +               ret = -EINVAL;
18329 +               if (!path.dentry->d_inode)
18330 +                       goto out_release;
18331 +               if (!(sb = path.dentry->d_inode->i_sb))
18332 +                       goto out_release;
18333 +
18334 +               ret = -ESRCH;
18335 +               dli = locate_dl_info(sb, id);
18336 +               if (!dli)
18337 +                       goto out_release;
18338 +
18339 +               spin_lock(&dli->dl_lock);
18340 +               *inodes_used = dli->dl_inodes_used;
18341 +               *inodes_total = dli->dl_inodes_total;
18342 +
18343 +               *space_used = dlimit_space_64to32(
18344 +                       dli->dl_space_used, flags, DLIMS_USED);
18345 +
18346 +               if (dli->dl_space_total == DLIM_INFINITY)
18347 +                       *space_total = CDLIM_INFINITY;
18348 +               else
18349 +                       *space_total = dlimit_space_64to32(
18350 +                               dli->dl_space_total, flags, DLIMS_TOTAL);
18351 +
18352 +               *reserved = 100 - ((dli->dl_nrlmult * 100 + 512) >> 10);
18353 +               spin_unlock(&dli->dl_lock);
18354 +
18355 +               put_dl_info(dli);
18356 +               ret = -EFAULT;
18357 +
18358 +               ret = 0;
18359 +       out_release:
18360 +               path_put(&path);
18361 +       }
18362 +       return ret;
18363 +}
18364 +
18365 +
18366 +int vc_get_dlimit(uint32_t id, void __user *data)
18367 +{
18368 +       struct vcmd_ctx_dlimit_v0 vc_data;
18369 +       int ret;
18370 +
18371 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18372 +               return -EFAULT;
18373 +
18374 +       ret = do_get_dlimit(id, vc_data.name,
18375 +               &vc_data.space_used, &vc_data.space_total,
18376 +               &vc_data.inodes_used, &vc_data.inodes_total,
18377 +               &vc_data.reserved, &vc_data.flags);
18378 +       if (ret)
18379 +               return ret;
18380 +
18381 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18382 +               return -EFAULT;
18383 +       return 0;
18384 +}
18385 +
18386 +#ifdef CONFIG_COMPAT
18387 +
18388 +int vc_get_dlimit_x32(uint32_t id, void __user *data)
18389 +{
18390 +       struct vcmd_ctx_dlimit_v0_x32 vc_data;
18391 +       int ret;
18392 +
18393 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18394 +               return -EFAULT;
18395 +
18396 +       ret = do_get_dlimit(id, compat_ptr(vc_data.name_ptr),
18397 +               &vc_data.space_used, &vc_data.space_total,
18398 +               &vc_data.inodes_used, &vc_data.inodes_total,
18399 +               &vc_data.reserved, &vc_data.flags);
18400 +       if (ret)
18401 +               return ret;
18402 +
18403 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18404 +               return -EFAULT;
18405 +       return 0;
18406 +}
18407 +
18408 +#endif /* CONFIG_COMPAT */
18409 +
18410 +
18411 +void vx_vsi_statfs(struct super_block *sb, struct kstatfs *buf)
18412 +{
18413 +       struct dl_info *dli;
18414 +       __u64 blimit, bfree, bavail;
18415 +       __u32 ifree;
18416 +
18417 +       dli = locate_dl_info(sb, dx_current_tag());
18418 +       if (!dli)
18419 +               return;
18420 +
18421 +       spin_lock(&dli->dl_lock);
18422 +       if (dli->dl_inodes_total == (unsigned long)DLIM_INFINITY)
18423 +               goto no_ilim;
18424 +
18425 +       /* reduce max inodes available to limit */
18426 +       if (buf->f_files > dli->dl_inodes_total)
18427 +               buf->f_files = dli->dl_inodes_total;
18428 +
18429 +       ifree = dli->dl_inodes_total - dli->dl_inodes_used;
18430 +       /* reduce free inodes to min */
18431 +       if (ifree < buf->f_ffree)
18432 +               buf->f_ffree = ifree;
18433 +
18434 +no_ilim:
18435 +       if (dli->dl_space_total == DLIM_INFINITY)
18436 +               goto no_blim;
18437 +
18438 +       blimit = dli->dl_space_total >> sb->s_blocksize_bits;
18439 +
18440 +       if (dli->dl_space_total < dli->dl_space_used)
18441 +               bfree = 0;
18442 +       else
18443 +               bfree = (dli->dl_space_total - dli->dl_space_used)
18444 +                       >> sb->s_blocksize_bits;
18445 +
18446 +       bavail = ((dli->dl_space_total >> 10) * dli->dl_nrlmult);
18447 +       if (bavail < dli->dl_space_used)
18448 +               bavail = 0;
18449 +       else
18450 +               bavail = (bavail - dli->dl_space_used)
18451 +                       >> sb->s_blocksize_bits;
18452 +
18453 +       /* reduce max space available to limit */
18454 +       if (buf->f_blocks > blimit)
18455 +               buf->f_blocks = blimit;
18456 +
18457 +       /* reduce free space to min */
18458 +       if (bfree < buf->f_bfree)
18459 +               buf->f_bfree = bfree;
18460 +
18461 +       /* reduce avail space to min */
18462 +       if (bavail < buf->f_bavail)
18463 +               buf->f_bavail = bavail;
18464 +
18465 +no_blim:
18466 +       spin_unlock(&dli->dl_lock);
18467 +       put_dl_info(dli);
18468 +
18469 +       return;
18470 +}
18471 +
18472 +#include <linux/module.h>
18473 +
18474 +EXPORT_SYMBOL_GPL(locate_dl_info);
18475 +EXPORT_SYMBOL_GPL(rcu_free_dl_info);
18476 +
18477 diff -NurpP --minimal linux-3.6.10/kernel/vserver/helper.c linux-3.6.10-vs2.3.4.5/kernel/vserver/helper.c
18478 --- linux-3.6.10/kernel/vserver/helper.c        1970-01-01 01:00:00.000000000 +0100
18479 +++ linux-3.6.10-vs2.3.4.5/kernel/vserver/helper.c      2012-10-04 18:47:00.000000000 +0200
18480 @@ -0,0 +1,229 @@
18481 +/*
18482 + *  linux/kernel/vserver/helper.c
18483 + *
18484 + *  Virtual Context Support
18485 + *
18486 + *  Copyright (C) 2004-2007  Herbert Pötzl
18487 + *
18488 + *  V0.01  basic helper
18489 + *
18490 + */
18491 +
18492 +#include <linux/kmod.h>
18493 +#include <linux/reboot.h>
18494 +#include <linux/vs_context.h>
18495 +#include <linux/vs_network.h>
18496 +#include <linux/vserver/signal.h>
18497 +
18498 +
18499 +char vshelper_path[255] = "/sbin/vshelper";
18500 +
18501 +static int vshelper_init(struct subprocess_info *info, struct cred *new_cred)
18502 +{
18503 +       current->flags &= ~PF_THREAD_BOUND;
18504 +       return 0;
18505 +}
18506 +
18507 +static int do_vshelper(char *name, char *argv[], char *envp[], int sync)
18508 +{
18509 +       int ret;
18510 +
18511 +       if ((ret = call_usermodehelper_fns(name, argv, envp,
18512 +               sync ? UMH_WAIT_PROC : UMH_WAIT_EXEC,
18513 +               vshelper_init, NULL, NULL))) {
18514 +               printk(KERN_WARNING "%s: (%s %s) returned %s with %d\n",
18515 +                       name, argv[1], argv[2],
18516 +                       sync ? "sync" : "async", ret);
18517 +       }
18518 +       vxdprintk(VXD_CBIT(switch, 4),
18519 +               "%s: (%s %s) returned %s with %d",
18520 +               name, argv[1], argv[2], sync ? "sync" : "async", ret);
18521 +       return ret;
18522 +}
18523 +
18524 +/*
18525 + *      vshelper path is set via /proc/sys
18526 + *      invoked by vserver sys_reboot(), with
18527 + *      the following arguments
18528 + *
18529 + *      argv [0] = vshelper_path;
18530 + *      argv [1] = action: "restart", "halt", "poweroff", ...
18531 + *      argv [2] = context identifier
18532 + *
18533 + *      envp [*] = type-specific parameters
18534 + */
18535 +
18536 +long vs_reboot_helper(struct vx_info *vxi, int cmd, void __user *arg)
18537 +{
18538 +       char id_buf[8], cmd_buf[16];
18539 +       char uid_buf[16], pid_buf[16];
18540 +       int ret;
18541 +
18542 +       char *argv[] = {vshelper_path, NULL, id_buf, 0};
18543 +       char *envp[] = {"HOME=/", "TERM=linux",
18544 +                       "PATH=/sbin:/usr/sbin:/bin:/usr/bin",
18545 +                       uid_buf, pid_buf, cmd_buf, 0};
18546 +
18547 +       if (vx_info_state(vxi, VXS_HELPER))
18548 +               return -EAGAIN;
18549 +       vxi->vx_state |= VXS_HELPER;
18550 +
18551 +       snprintf(id_buf, sizeof(id_buf), "%d", vxi->vx_id);
18552 +
18553 +       snprintf(cmd_buf, sizeof(cmd_buf), "VS_CMD=%08x", cmd);
18554 +       snprintf(uid_buf, sizeof(uid_buf), "VS_UID=%d", current_uid());
18555 +       snprintf(pid_buf, sizeof(pid_buf), "VS_PID=%d", current->pid);
18556 +
18557 +       switch (cmd) {
18558 +       case LINUX_REBOOT_CMD_RESTART:
18559 +               argv[1] = "restart";
18560 +               break;
18561 +
18562 +       case LINUX_REBOOT_CMD_HALT:
18563 +               argv[1] = "halt";
18564 +               break;
18565 +
18566 +       case LINUX_REBOOT_CMD_POWER_OFF:
18567 +               argv[1] = "poweroff";
18568 +               break;
18569 +
18570 +       case LINUX_REBOOT_CMD_SW_SUSPEND:
18571 +               argv[1] = "swsusp";
18572 +               break;
18573 +
18574 +       case LINUX_REBOOT_CMD_OOM:
18575 +               argv[1] = "oom";
18576 +               break;
18577 +
18578 +       default:
18579 +               vxi->vx_state &= ~VXS_HELPER;
18580 +               return 0;
18581 +       }
18582 +
18583 +       ret = do_vshelper(vshelper_path, argv, envp, 0);
18584 +       vxi->vx_state &= ~VXS_HELPER;
18585 +       __wakeup_vx_info(vxi);
18586 +       return (ret) ? -EPERM : 0;
18587 +}
18588 +
18589 +
18590 +long vs_reboot(unsigned int cmd, void __user *arg)
18591 +{
18592 +       struct vx_info *vxi = current_vx_info();
18593 +       long ret = 0;
18594 +
18595 +       vxdprintk(VXD_CBIT(misc, 5),
18596 +               "vs_reboot(%p[#%d],%u)",
18597 +               vxi, vxi ? vxi->vx_id : 0, cmd);
18598 +
18599 +       ret = vs_reboot_helper(vxi, cmd, arg);
18600 +       if (ret)
18601 +               return ret;
18602 +
18603 +       vxi->reboot_cmd = cmd;
18604 +       if (vx_info_flags(vxi, VXF_REBOOT_KILL, 0)) {
18605 +               switch (cmd) {
18606 +               case LINUX_REBOOT_CMD_RESTART:
18607 +               case LINUX_REBOOT_CMD_HALT:
18608 +               case LINUX_REBOOT_CMD_POWER_OFF:
18609 +                       vx_info_kill(vxi, 0, SIGKILL);
18610 +                       vx_info_kill(vxi, 1, SIGKILL);
18611 +               default:
18612 +                       break;
18613 +               }
18614 +       }
18615 +       return 0;
18616 +}
18617 +
18618 +long vs_oom_action(unsigned int cmd)
18619 +{
18620 +       struct vx_info *vxi = current_vx_info();
18621 +       long ret = 0;
18622 +
18623 +       vxdprintk(VXD_CBIT(misc, 5),
18624 +               "vs_oom_action(%p[#%d],%u)",
18625 +               vxi, vxi ? vxi->vx_id : 0, cmd);
18626 +
18627 +       ret = vs_reboot_helper(vxi, cmd, NULL);
18628 +       if (ret)
18629 +               return ret;
18630 +
18631 +       vxi->reboot_cmd = cmd;
18632 +       if (vx_info_flags(vxi, VXF_REBOOT_KILL, 0)) {
18633 +               vx_info_kill(vxi, 0, SIGKILL);
18634 +               vx_info_kill(vxi, 1, SIGKILL);
18635 +       }
18636 +       return 0;
18637 +}
18638 +
18639 +/*
18640 + *      argv [0] = vshelper_path;
18641 + *      argv [1] = action: "startup", "shutdown"
18642 + *      argv [2] = context identifier
18643 + *
18644 + *      envp [*] = type-specific parameters
18645 + */
18646 +
18647 +long vs_state_change(struct vx_info *vxi, unsigned int cmd)
18648 +{
18649 +       char id_buf[8], cmd_buf[16];
18650 +       char *argv[] = {vshelper_path, NULL, id_buf, 0};
18651 +       char *envp[] = {"HOME=/", "TERM=linux",
18652 +                       "PATH=/sbin:/usr/sbin:/bin:/usr/bin", cmd_buf, 0};
18653 +
18654 +       if (!vx_info_flags(vxi, VXF_SC_HELPER, 0))
18655 +               return 0;
18656 +
18657 +       snprintf(id_buf, sizeof(id_buf), "%d", vxi->vx_id);
18658 +       snprintf(cmd_buf, sizeof(cmd_buf), "VS_CMD=%08x", cmd);
18659 +
18660 +       switch (cmd) {
18661 +       case VSC_STARTUP:
18662 +               argv[1] = "startup";
18663 +               break;
18664 +       case VSC_SHUTDOWN:
18665 +               argv[1] = "shutdown";
18666 +               break;
18667 +       default:
18668 +               return 0;
18669 +       }
18670 +
18671 +       return do_vshelper(vshelper_path, argv, envp, 1);
18672 +}
18673 +
18674 +
18675 +/*
18676 + *      argv [0] = vshelper_path;
18677 + *      argv [1] = action: "netup", "netdown"
18678 + *      argv [2] = context identifier
18679 + *
18680 + *      envp [*] = type-specific parameters
18681 + */
18682 +
18683 +long vs_net_change(struct nx_info *nxi, unsigned int cmd)
18684 +{
18685 +       char id_buf[8], cmd_buf[16];
18686 +       char *argv[] = {vshelper_path, NULL, id_buf, 0};
18687 +       char *envp[] = {"HOME=/", "TERM=linux",
18688 +                       "PATH=/sbin:/usr/sbin:/bin:/usr/bin", cmd_buf, 0};
18689 +
18690 +       if (!nx_info_flags(nxi, NXF_SC_HELPER, 0))
18691 +               return 0;
18692 +
18693 +       snprintf(id_buf, sizeof(id_buf), "%d", nxi->nx_id);
18694 +       snprintf(cmd_buf, sizeof(cmd_buf), "VS_CMD=%08x", cmd);
18695 +
18696 +       switch (cmd) {
18697 +       case VSC_NETUP:
18698 +               argv[1] = "netup";
18699 +               break;
18700 +       case VSC_NETDOWN:
18701 +               argv[1] = "netdown";
18702 +               break;
18703 +       default:
18704 +               return 0;
18705 +       }
18706 +
18707 +       return do_vshelper(vshelper_path, argv, envp, 1);
18708 +}
18709 +
18710 diff -NurpP --minimal linux-3.6.10/kernel/vserver/history.c linux-3.6.10-vs2.3.4.5/kernel/vserver/history.c
18711 --- linux-3.6.10/kernel/vserver/history.c       1970-01-01 01:00:00.000000000 +0100
18712 +++ linux-3.6.10-vs2.3.4.5/kernel/vserver/history.c     2012-10-04 18:47:00.000000000 +0200
18713 @@ -0,0 +1,258 @@
18714 +/*
18715 + *  kernel/vserver/history.c
18716 + *
18717 + *  Virtual Context History Backtrace
18718 + *
18719 + *  Copyright (C) 2004-2007  Herbert Pötzl
18720 + *
18721 + *  V0.01  basic structure
18722 + *  V0.02  hash/unhash and trace
18723 + *  V0.03  preemption fixes
18724 + *
18725 + */
18726 +
18727 +#include <linux/module.h>
18728 +#include <asm/uaccess.h>
18729 +
18730 +#include <linux/vserver/context.h>
18731 +#include <linux/vserver/debug.h>
18732 +#include <linux/vserver/debug_cmd.h>
18733 +#include <linux/vserver/history.h>
18734 +
18735 +
18736 +#ifdef CONFIG_VSERVER_HISTORY
18737 +#define VXH_SIZE       CONFIG_VSERVER_HISTORY_SIZE
18738 +#else
18739 +#define VXH_SIZE       64
18740 +#endif
18741 +
18742 +struct _vx_history {
18743 +       unsigned int counter;
18744 +
18745 +       struct _vx_hist_entry entry[VXH_SIZE + 1];
18746 +};
18747 +
18748 +
18749 +DEFINE_PER_CPU(struct _vx_history, vx_history_buffer);
18750 +
18751 +unsigned volatile int vxh_active = 1;
18752 +
18753 +static atomic_t sequence = ATOMIC_INIT(0);
18754 +
18755 +
18756 +/*     vxh_advance()
18757 +
18758 +       * requires disabled preemption                          */
18759 +
18760 +struct _vx_hist_entry *vxh_advance(void *loc)
18761 +{
18762 +       unsigned int cpu = smp_processor_id();
18763 +       struct _vx_history *hist = &per_cpu(vx_history_buffer, cpu);
18764 +       struct _vx_hist_entry *entry;
18765 +       unsigned int index;
18766 +
18767 +       index = vxh_active ? (hist->counter++ % VXH_SIZE) : VXH_SIZE;
18768 +       entry = &hist->entry[index];
18769 +
18770 +       entry->seq = atomic_inc_return(&sequence);
18771 +       entry->loc = loc;
18772 +       return entry;
18773 +}
18774 +
18775 +EXPORT_SYMBOL_GPL(vxh_advance);
18776 +
18777 +
18778 +#define VXH_LOC_FMTS   "(#%04x,*%d):%p"
18779 +
18780 +#define VXH_LOC_ARGS(e)        (e)->seq, cpu, (e)->loc
18781 +
18782 +
18783 +#define VXH_VXI_FMTS   "%p[#%d,%d.%d]"
18784 +
18785 +#define VXH_VXI_ARGS(e)        (e)->vxi.ptr,                           \
18786 +                       (e)->vxi.ptr ? (e)->vxi.xid : 0,        \
18787 +                       (e)->vxi.ptr ? (e)->vxi.usecnt : 0,     \
18788 +                       (e)->vxi.ptr ? (e)->vxi.tasks : 0
18789 +
18790 +void   vxh_dump_entry(struct _vx_hist_entry *e, unsigned cpu)
18791 +{
18792 +       switch (e->type) {
18793 +       case VXH_THROW_OOPS:
18794 +               printk( VXH_LOC_FMTS " oops \n", VXH_LOC_ARGS(e));
18795 +               break;
18796 +
18797 +       case VXH_GET_VX_INFO:
18798 +       case VXH_PUT_VX_INFO:
18799 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS "\n",
18800 +                       VXH_LOC_ARGS(e),
18801 +                       (e->type == VXH_GET_VX_INFO) ? "get" : "put",
18802 +                       VXH_VXI_ARGS(e));
18803 +               break;
18804 +
18805 +       case VXH_INIT_VX_INFO:
18806 +       case VXH_SET_VX_INFO:
18807 +       case VXH_CLR_VX_INFO:
18808 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS " @%p\n",
18809 +                       VXH_LOC_ARGS(e),
18810 +                       (e->type == VXH_INIT_VX_INFO) ? "init" :
18811 +                       ((e->type == VXH_SET_VX_INFO) ? "set" : "clr"),
18812 +                       VXH_VXI_ARGS(e), e->sc.data);
18813 +               break;
18814 +
18815 +       case VXH_CLAIM_VX_INFO:
18816 +       case VXH_RELEASE_VX_INFO:
18817 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS " @%p\n",
18818 +                       VXH_LOC_ARGS(e),
18819 +                       (e->type == VXH_CLAIM_VX_INFO) ? "claim" : "release",
18820 +                       VXH_VXI_ARGS(e), e->sc.data);
18821 +               break;
18822 +
18823 +       case VXH_ALLOC_VX_INFO:
18824 +       case VXH_DEALLOC_VX_INFO:
18825 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS "\n",
18826 +                       VXH_LOC_ARGS(e),
18827 +                       (e->type == VXH_ALLOC_VX_INFO) ? "alloc" : "dealloc",
18828 +                       VXH_VXI_ARGS(e));
18829 +               break;
18830 +
18831 +       case VXH_HASH_VX_INFO:
18832 +       case VXH_UNHASH_VX_INFO:
18833 +               printk( VXH_LOC_FMTS " __%s_vx_info " VXH_VXI_FMTS "\n",
18834 +                       VXH_LOC_ARGS(e),
18835 +                       (e->type == VXH_HASH_VX_INFO) ? "hash" : "unhash",
18836 +                       VXH_VXI_ARGS(e));
18837 +               break;
18838 +
18839 +       case VXH_LOC_VX_INFO:
18840 +       case VXH_LOOKUP_VX_INFO:
18841 +       case VXH_CREATE_VX_INFO:
18842 +               printk( VXH_LOC_FMTS " __%s_vx_info [#%d] -> " VXH_VXI_FMTS "\n",
18843 +                       VXH_LOC_ARGS(e),
18844 +                       (e->type == VXH_CREATE_VX_INFO) ? "create" :
18845 +                       ((e->type == VXH_LOC_VX_INFO) ? "loc" : "lookup"),
18846 +                       e->ll.arg, VXH_VXI_ARGS(e));
18847 +               break;
18848 +       }
18849 +}
18850 +
18851 +static void __vxh_dump_history(void)
18852 +{
18853 +       unsigned int i, cpu;
18854 +
18855 +       printk("History:\tSEQ: %8x\tNR_CPUS: %d\n",
18856 +               atomic_read(&sequence), NR_CPUS);
18857 +
18858 +       for (i = 0; i < VXH_SIZE; i++) {
18859 +               for_each_online_cpu(cpu) {
18860 +                       struct _vx_history *hist =
18861 +                               &per_cpu(vx_history_buffer, cpu);
18862 +                       unsigned int index = (hist->counter - i) % VXH_SIZE;
18863 +                       struct _vx_hist_entry *entry = &hist->entry[index];
18864 +
18865 +                       vxh_dump_entry(entry, cpu);
18866 +               }
18867 +       }
18868 +}
18869 +
18870 +void   vxh_dump_history(void)
18871 +{
18872 +       vxh_active = 0;
18873 +#ifdef CONFIG_SMP
18874 +       local_irq_enable();
18875 +       smp_send_stop();
18876 +       local_irq_disable();
18877 +#endif
18878 +       __vxh_dump_history();
18879 +}
18880 +
18881 +
18882 +/* vserver syscall commands below here */
18883 +
18884 +
18885 +int vc_dump_history(uint32_t id)
18886 +{
18887 +       vxh_active = 0;
18888 +       __vxh_dump_history();
18889 +       vxh_active = 1;
18890 +
18891 +       return 0;
18892 +}
18893 +
18894 +
18895 +int do_read_history(struct __user _vx_hist_entry *data,
18896 +       int cpu, uint32_t *index, uint32_t *count)
18897 +{
18898 +       int pos, ret = 0;
18899 +       struct _vx_history *hist = &per_cpu(vx_history_buffer, cpu);
18900 +       int end = hist->counter;
18901 +       int start = end - VXH_SIZE + 2;
18902 +       int idx = *index;
18903 +
18904 +       /* special case: get current pos */
18905 +       if (!*count) {
18906 +               *index = end;
18907 +               return 0;
18908 +       }
18909 +
18910 +       /* have we lost some data? */
18911 +       if (idx < start)
18912 +               idx = start;
18913 +
18914 +       for (pos = 0; (pos < *count) && (idx < end); pos++, idx++) {
18915 +               struct _vx_hist_entry *entry =
18916 +                       &hist->entry[idx % VXH_SIZE];
18917 +
18918 +               /* send entry to userspace */
18919 +               ret = copy_to_user(&data[pos], entry, sizeof(*entry));
18920 +               if (ret)
18921 +                       break;
18922 +       }
18923 +       /* save new index and count */
18924 +       *index = idx;
18925 +       *count = pos;
18926 +       return ret ? ret : (*index < end);
18927 +}
18928 +
18929 +int vc_read_history(uint32_t id, void __user *data)
18930 +{
18931 +       struct vcmd_read_history_v0 vc_data;
18932 +       int ret;
18933 +
18934 +       if (id >= NR_CPUS)
18935 +               return -EINVAL;
18936 +
18937 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18938 +               return -EFAULT;
18939 +
18940 +       ret = do_read_history((struct __user _vx_hist_entry *)vc_data.data,
18941 +               id, &vc_data.index, &vc_data.count);
18942 +
18943 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18944 +               return -EFAULT;
18945 +       return ret;
18946 +}
18947 +
18948 +#ifdef CONFIG_COMPAT
18949 +
18950 +int vc_read_history_x32(uint32_t id, void __user *data)
18951 +{
18952 +       struct vcmd_read_history_v0_x32 vc_data;
18953 +       int ret;
18954 +
18955 +       if (id >= NR_CPUS)
18956 +               return -EINVAL;
18957 +
18958 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18959 +               return -EFAULT;
18960 +
18961 +       ret = do_read_history((struct __user _vx_hist_entry *)
18962 +               compat_ptr(vc_data.data_ptr),
18963 +               id, &vc_data.index, &vc_data.count);
18964 +
18965 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18966 +               return -EFAULT;
18967 +       return ret;
18968 +}
18969 +
18970 +#endif /* CONFIG_COMPAT */
18971 +
18972 diff -NurpP --minimal linux-3.6.10/kernel/vserver/inet.c linux-3.6.10-vs2.3.4.5/kernel/vserver/inet.c
18973 --- linux-3.6.10/kernel/vserver/inet.c  1970-01-01 01:00:00.000000000 +0100
18974 +++ linux-3.6.10-vs2.3.4.5/kernel/vserver/inet.c        2012-10-04 18:47:00.000000000 +0200
18975 @@ -0,0 +1,226 @@
18976 +
18977 +#include <linux/in.h>
18978 +#include <linux/inetdevice.h>
18979 +#include <linux/export.h>
18980 +#include <linux/vs_inet.h>
18981 +#include <linux/vs_inet6.h>
18982 +#include <linux/vserver/debug.h>
18983 +#include <net/route.h>
18984 +#include <net/addrconf.h>
18985 +
18986 +
18987 +int nx_v4_addr_conflict(struct nx_info *nxi1, struct nx_info *nxi2)
18988 +{
18989 +       int ret = 0;
18990 +
18991 +       if (!nxi1 || !nxi2 || nxi1 == nxi2)
18992 +               ret = 1;
18993 +       else {
18994 +               struct nx_addr_v4 *ptr;
18995 +
18996 +               for (ptr = &nxi1->v4; ptr; ptr = ptr->next) {
18997 +                       if (v4_nx_addr_in_nx_info(nxi2, ptr, -1)) {
18998 +                               ret = 1;
18999 +                               break;
19000 +                       }
19001 +               }
19002 +       }
19003 +
19004 +       vxdprintk(VXD_CBIT(net, 2),
19005 +               "nx_v4_addr_conflict(%p,%p): %d",
19006 +               nxi1, nxi2, ret);
19007 +
19008 +       return ret;
19009 +}
19010 +
19011 +
19012 +#ifdef CONFIG_IPV6
19013 +
19014 +int nx_v6_addr_conflict(struct nx_info *nxi1, struct nx_info *nxi2)
19015 +{
19016 +       int ret = 0;
19017 +
19018 +       if (!nxi1 || !nxi2 || nxi1 == nxi2)
19019 +               ret = 1;
19020 +       else {
19021 +               struct nx_addr_v6 *ptr;
19022 +
19023 +               for (ptr = &nxi1->v6; ptr; ptr = ptr->next) {
19024 +                       if (v6_nx_addr_in_nx_info(nxi2, ptr, -1)) {
19025 +                               ret = 1;
19026 +                               break;
19027 +                       }
19028 +               }
19029 +       }
19030 +
19031 +       vxdprintk(VXD_CBIT(net, 2),
19032 +               "nx_v6_addr_conflict(%p,%p): %d",
19033 +               nxi1, nxi2, ret);
19034 +
19035 +       return ret;
19036 +}
19037 +
19038 +#endif
19039 +
19040 +int v4_dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
19041 +{
19042 +       struct in_device *in_dev;
19043 +       struct in_ifaddr **ifap;
19044 +       struct in_ifaddr *ifa;
19045 +       int ret = 0;
19046 +
19047 +       if (!dev)
19048 +               goto out;
19049 +       in_dev = in_dev_get(dev);
19050 +       if (!in_dev)
19051 +               goto out;
19052 +
19053 +       for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
19054 +               ifap = &ifa->ifa_next) {
19055 +               if (v4_addr_in_nx_info(nxi, ifa->ifa_local, NXA_MASK_SHOW)) {
19056 +                       ret = 1;
19057 +                       break;
19058 +               }
19059 +       }
19060 +       in_dev_put(in_dev);
19061 +out:
19062 +       return ret;
19063 +}
19064 +
19065 +
19066 +#ifdef CONFIG_IPV6
19067 +
19068 +int v6_dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
19069 +{
19070 +       struct inet6_dev *in_dev;
19071 +       struct inet6_ifaddr *ifa;
19072 +       int ret = 0;
19073 +
19074 +       if (!dev)
19075 +               goto out;
19076 +       in_dev = in6_dev_get(dev);
19077 +       if (!in_dev)
19078 +               goto out;
19079 +
19080 +       // for (ifap = &in_dev->addr_list; (ifa = *ifap) != NULL;
19081 +       list_for_each_entry(ifa, &in_dev->addr_list, if_list) {
19082 +               if (v6_addr_in_nx_info(nxi, &ifa->addr, -1)) {
19083 +                       ret = 1;
19084 +                       break;
19085 +               }
19086 +       }
19087 +       in6_dev_put(in_dev);
19088 +out:
19089 +       return ret;
19090 +}
19091 +
19092 +#endif
19093 +
19094 +int dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
19095 +{
19096 +       int ret = 1;
19097 +
19098 +       if (!nxi)
19099 +               goto out;
19100 +       if (nxi->v4.type && v4_dev_in_nx_info(dev, nxi))
19101 +               goto out;
19102 +#ifdef CONFIG_IPV6
19103 +       ret = 2;
19104 +       if (nxi->v6.type && v6_dev_in_nx_info(dev, nxi))
19105 +               goto out;
19106 +#endif
19107 +       ret = 0;
19108 +out:
19109 +       vxdprintk(VXD_CBIT(net, 3),
19110 +               "dev_in_nx_info(%p,%p[#%d]) = %d",
19111 +               dev, nxi, nxi ? nxi->nx_id : 0, ret);
19112 +       return ret;
19113 +}
19114 +
19115 +struct rtable *ip_v4_find_src(struct net *net, struct nx_info *nxi,
19116 +       struct flowi4 *fl4)
19117 +{
19118 +       struct rtable *rt;
19119 +
19120 +       if (!nxi)
19121 +               return NULL;
19122 +
19123 +       /* FIXME: handle lback only case */
19124 +       if (!NX_IPV4(nxi))
19125 +               return ERR_PTR(-EPERM);
19126 +
19127 +       vxdprintk(VXD_CBIT(net, 4),
19128 +               "ip_v4_find_src(%p[#%u]) " NIPQUAD_FMT " -> " NIPQUAD_FMT,
19129 +               nxi, nxi ? nxi->nx_id : 0,
19130 +               NIPQUAD(fl4->saddr), NIPQUAD(fl4->daddr));
19131 +
19132 +       /* single IP is unconditional */
19133 +       if (nx_info_flags(nxi, NXF_SINGLE_IP, 0) &&
19134 +               (fl4->saddr == INADDR_ANY))
19135 +               fl4->saddr = nxi->v4.ip[0].s_addr;
19136 +
19137 +       if (fl4->saddr == INADDR_ANY) {
19138 +               struct nx_addr_v4 *ptr;
19139 +               __be32 found = 0;
19140 +
19141 +               rt = __ip_route_output_key(net, fl4);
19142 +               if (!IS_ERR(rt)) {
19143 +                       found = fl4->saddr;
19144 +                       ip_rt_put(rt);
19145 +                       vxdprintk(VXD_CBIT(net, 4),
19146 +                               "ip_v4_find_src(%p[#%u]) rok[%u]: " NIPQUAD_FMT,
19147 +                               nxi, nxi ? nxi->nx_id : 0, fl4->flowi4_oif, NIPQUAD(found));
19148 +                       if (v4_addr_in_nx_info(nxi, found, NXA_MASK_BIND))
19149 +                               goto found;
19150 +               }
19151 +
19152 +               for (ptr = &nxi->v4; ptr; ptr = ptr->next) {
19153 +                       __be32 primary = ptr->ip[0].s_addr;
19154 +                       __be32 mask = ptr->mask.s_addr;
19155 +                       __be32 neta = primary & mask;
19156 +
19157 +                       vxdprintk(VXD_CBIT(net, 4), "ip_v4_find_src(%p[#%u]) chk: "
19158 +                               NIPQUAD_FMT "/" NIPQUAD_FMT "/" NIPQUAD_FMT,
19159 +                               nxi, nxi ? nxi->nx_id : 0, NIPQUAD(primary),
19160 +                               NIPQUAD(mask), NIPQUAD(neta));
19161 +                       if ((found & mask) != neta)
19162 +                               continue;
19163 +
19164 +                       fl4->saddr = primary;
19165 +                       rt = __ip_route_output_key(net, fl4);
19166 +                       vxdprintk(VXD_CBIT(net, 4),
19167 +                               "ip_v4_find_src(%p[#%u]) rok[%u]: " NIPQUAD_FMT,
19168 +                               nxi, nxi ? nxi->nx_id : 0, fl4->flowi4_oif, NIPQUAD(primary));
19169 +                       if (!IS_ERR(rt)) {
19170 +                               found = fl4->saddr;
19171 +                               ip_rt_put(rt);
19172 +                               if (found == primary)
19173 +                                       goto found;
19174 +                       }
19175 +               }
19176 +               /* still no source ip? */
19177 +               found = ipv4_is_loopback(fl4->daddr)
19178 +                       ? IPI_LOOPBACK : nxi->v4.ip[0].s_addr;
19179 +       found:
19180 +               /* assign src ip to flow */
19181 +               fl4->saddr = found;
19182 +
19183 +       } else {
19184 +               if (!v4_addr_in_nx_info(nxi, fl4->saddr, NXA_MASK_BIND))
19185 +                       return ERR_PTR(-EPERM);
19186 +       }
19187 +
19188 +       if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0)) {
19189 +               if (ipv4_is_loopback(fl4->daddr))
19190 +                       fl4->daddr = nxi->v4_lback.s_addr;
19191 +               if (ipv4_is_loopback(fl4->saddr))
19192 +                       fl4->saddr = nxi->v4_lback.s_addr;
19193 +       } else if (ipv4_is_loopback(fl4->daddr) &&
19194 +               !nx_info_flags(nxi, NXF_LBACK_ALLOW, 0))
19195 +               return ERR_PTR(-EPERM);
19196 +
19197 +       return NULL;
19198 +}
19199 +
19200 +EXPORT_SYMBOL_GPL(ip_v4_find_src);
19201 +
19202 diff -NurpP --minimal linux-3.6.10/kernel/vserver/init.c linux-3.6.10-vs2.3.4.5/kernel/vserver/init.c
19203 --- linux-3.6.10/kernel/vserver/init.c  1970-01-01 01:00:00.000000000 +0100
19204 +++ linux-3.6.10-vs2.3.4.5/kernel/vserver/init.c        2012-10-04 18:47:00.000000000 +0200
19205 @@ -0,0 +1,45 @@
19206 +/*
19207 + *  linux/kernel/init.c
19208 + *
19209 + *  Virtual Server Init
19210 + *
19211 + *  Copyright (C) 2004-2007  Herbert Pötzl
19212 + *
19213 + *  V0.01  basic structure
19214 + *
19215 + */
19216 +
19217 +#include <linux/init.h>
19218 +
19219 +int    vserver_register_sysctl(void);
19220 +void   vserver_unregister_sysctl(void);
19221 +
19222 +
19223 +static int __init init_vserver(void)
19224 +{
19225 +       int ret = 0;
19226 +
19227 +#ifdef CONFIG_VSERVER_DEBUG
19228 +       vserver_register_sysctl();
19229 +#endif
19230 +       return ret;
19231 +}
19232 +
19233 +
19234 +static void __exit exit_vserver(void)
19235 +{
19236 +
19237 +#ifdef CONFIG_VSERVER_DEBUG
19238 +       vserver_unregister_sysctl();
19239 +#endif
19240 +       return;
19241 +}
19242 +
19243 +/* FIXME: GFP_ZONETYPES gone
19244 +long vx_slab[GFP_ZONETYPES]; */
19245 +long vx_area;
19246 +
19247 +
19248 +module_init(init_vserver);
19249 +module_exit(exit_vserver);
19250 +
19251 diff -NurpP --minimal linux-3.6.10/kernel/vserver/inode.c linux-3.6.10-vs2.3.4.5/kernel/vserver/inode.c
19252 --- linux-3.6.10/kernel/vserver/inode.c 1970-01-01 01:00:00.000000000 +0100
19253 +++ linux-3.6.10-vs2.3.4.5/kernel/vserver/inode.c       2012-10-04 18:47:00.000000000 +0200
19254 @@ -0,0 +1,437 @@
19255 +/*
19256 + *  linux/kernel/vserver/inode.c
19257 + *
19258 + *  Virtual Server: File System Support
19259 + *
19260 + *  Copyright (C) 2004-2007  Herbert Pötzl
19261 + *
19262 + *  V0.01  separated from vcontext V0.05
19263 + *  V0.02  moved to tag (instead of xid)
19264 + *
19265 + */
19266 +
19267 +#include <linux/tty.h>
19268 +#include <linux/proc_fs.h>
19269 +#include <linux/devpts_fs.h>
19270 +#include <linux/fs.h>
19271 +#include <linux/file.h>
19272 +#include <linux/mount.h>
19273 +#include <linux/parser.h>
19274 +#include <linux/namei.h>
19275 +#include <linux/vserver/inode.h>
19276 +#include <linux/vserver/inode_cmd.h>
19277 +#include <linux/vs_base.h>
19278 +#include <linux/vs_tag.h>
19279 +
19280 +#include <asm/uaccess.h>
19281 +
19282 +
19283 +static int __vc_get_iattr(struct inode *in, uint32_t *tag, uint32_t *flags, uint32_t *mask)
19284 +{
19285 +       struct proc_dir_entry *entry;
19286 +
19287 +       if (!in || !in->i_sb)
19288 +               return -ESRCH;
19289 +
19290 +       *flags = IATTR_TAG
19291 +               | (IS_IMMUTABLE(in) ? IATTR_IMMUTABLE : 0)
19292 +               | (IS_IXUNLINK(in) ? IATTR_IXUNLINK : 0)
19293 +               | (IS_BARRIER(in) ? IATTR_BARRIER : 0)
19294 +               | (IS_COW(in) ? IATTR_COW : 0);
19295 +       *mask = IATTR_IXUNLINK | IATTR_IMMUTABLE | IATTR_COW;
19296 +
19297 +       if (S_ISDIR(in->i_mode))
19298 +               *mask |= IATTR_BARRIER;
19299 +
19300 +       if (IS_TAGGED(in)) {
19301 +               *tag = in->i_tag;
19302 +               *mask |= IATTR_TAG;
19303 +       }
19304 +
19305 +       switch (in->i_sb->s_magic) {
19306 +       case PROC_SUPER_MAGIC:
19307 +               entry = PROC_I(in)->pde;
19308 +
19309 +               /* check for specific inodes? */
19310 +               if (entry)
19311 +                       *mask |= IATTR_FLAGS;
19312 +               if (entry)
19313 +                       *flags |= (entry->vx_flags & IATTR_FLAGS);
19314 +               else
19315 +                       *flags |= (PROC_I(in)->vx_flags & IATTR_FLAGS);
19316 +               break;
19317 +
19318 +       case DEVPTS_SUPER_MAGIC:
19319 +               *tag = in->i_tag;
19320 +               *mask |= IATTR_TAG;
19321 +               break;
19322 +
19323 +       default:
19324 +               break;
19325 +       }
19326 +       return 0;
19327 +}
19328 +
19329 +int vc_get_iattr(void __user *data)
19330 +{
19331 +       struct path path;
19332 +       struct vcmd_ctx_iattr_v1 vc_data = { .tag = -1 };
19333 +       int ret;
19334 +
19335 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19336 +               return -EFAULT;
19337 +
19338 +       ret = user_lpath(vc_data.name, &path);
19339 +       if (!ret) {
19340 +               ret = __vc_get_iattr(path.dentry->d_inode,
19341 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
19342 +               path_put(&path);
19343 +       }
19344 +       if (ret)
19345 +               return ret;
19346 +
19347 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19348 +               ret = -EFAULT;
19349 +       return ret;
19350 +}
19351 +
19352 +#ifdef CONFIG_COMPAT
19353 +
19354 +int vc_get_iattr_x32(void __user *data)
19355 +{
19356 +       struct path path;
19357 +       struct vcmd_ctx_iattr_v1_x32 vc_data = { .tag = -1 };
19358 +       int ret;
19359 +
19360 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19361 +               return -EFAULT;
19362 +
19363 +       ret = user_lpath(compat_ptr(vc_data.name_ptr), &path);
19364 +       if (!ret) {
19365 +               ret = __vc_get_iattr(path.dentry->d_inode,
19366 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
19367 +               path_put(&path);
19368 +       }
19369 +       if (ret)
19370 +               return ret;
19371 +
19372 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19373 +               ret = -EFAULT;
19374 +       return ret;
19375 +}
19376 +
19377 +#endif /* CONFIG_COMPAT */
19378 +
19379 +
19380 +int vc_fget_iattr(uint32_t fd, void __user *data)
19381 +{
19382 +       struct file *filp;
19383 +       struct vcmd_ctx_fiattr_v0 vc_data = { .tag = -1 };
19384 +       int ret;
19385 +
19386 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19387 +               return -EFAULT;
19388 +
19389 +       filp = fget(fd);
19390 +       if (!filp || !filp->f_dentry || !filp->f_dentry->d_inode)
19391 +               return -EBADF;
19392 +
19393 +       ret = __vc_get_iattr(filp->f_dentry->d_inode,
19394 +               &vc_data.tag, &vc_data.flags, &vc_data.mask);
19395 +
19396 +       fput(filp);
19397 +
19398 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19399 +               ret = -EFAULT;
19400 +       return ret;
19401 +}
19402 +
19403 +
19404 +static int __vc_set_iattr(struct dentry *de, uint32_t *tag, uint32_t *flags, uint32_t *mask)
19405 +{
19406 +       struct inode *in = de->d_inode;
19407 +       int error = 0, is_proc = 0, has_tag = 0;
19408 +       struct iattr attr = { 0 };
19409 +
19410 +       if (!in || !in->i_sb)
19411 +               return -ESRCH;
19412 +
19413 +       is_proc = (in->i_sb->s_magic == PROC_SUPER_MAGIC);
19414 +       if ((*mask & IATTR_FLAGS) && !is_proc)
19415 +               return -EINVAL;
19416 +
19417 +       has_tag = IS_TAGGED(in) ||
19418 +               (in->i_sb->s_magic == DEVPTS_SUPER_MAGIC);
19419 +       if ((*mask & IATTR_TAG) && !has_tag)
19420 +               return -EINVAL;
19421 +
19422 +       mutex_lock(&in->i_mutex);
19423 +       if (*mask & IATTR_TAG) {
19424 +               attr.ia_tag = *tag;
19425 +               attr.ia_valid |= ATTR_TAG;
19426 +       }
19427 +
19428 +       if (*mask & IATTR_FLAGS) {
19429 +               struct proc_dir_entry *entry = PROC_I(in)->pde;
19430 +               unsigned int iflags = PROC_I(in)->vx_flags;
19431 +
19432 +               iflags = (iflags & ~(*mask & IATTR_FLAGS))
19433 +                       | (*flags & IATTR_FLAGS);
19434 +               PROC_I(in)->vx_flags = iflags;
19435 +               if (entry)
19436 +                       entry->vx_flags = iflags;
19437 +       }
19438 +
19439 +       if (*mask & (IATTR_IMMUTABLE | IATTR_IXUNLINK |
19440 +               IATTR_BARRIER | IATTR_COW)) {
19441 +               int iflags = in->i_flags;
19442 +               int vflags = in->i_vflags;
19443 +
19444 +               if (*mask & IATTR_IMMUTABLE) {
19445 +                       if (*flags & IATTR_IMMUTABLE)
19446 +                               iflags |= S_IMMUTABLE;
19447 +                       else
19448 +                               iflags &= ~S_IMMUTABLE;
19449 +               }
19450 +               if (*mask & IATTR_IXUNLINK) {
19451 +                       if (*flags & IATTR_IXUNLINK)
19452 +                               iflags |= S_IXUNLINK;
19453 +                       else
19454 +                               iflags &= ~S_IXUNLINK;
19455 +               }
19456 +               if (S_ISDIR(in->i_mode) && (*mask & IATTR_BARRIER)) {
19457 +                       if (*flags & IATTR_BARRIER)
19458 +                               vflags |= V_BARRIER;
19459 +                       else
19460 +                               vflags &= ~V_BARRIER;
19461 +               }
19462 +               if (S_ISREG(in->i_mode) && (*mask & IATTR_COW)) {
19463 +                       if (*flags & IATTR_COW)
19464 +                               vflags |= V_COW;
19465 +                       else
19466 +                               vflags &= ~V_COW;
19467 +               }
19468 +               if (in->i_op && in->i_op->sync_flags) {
19469 +                       error = in->i_op->sync_flags(in, iflags, vflags);
19470 +                       if (error)
19471 +                               goto out;
19472 +               }
19473 +       }
19474 +
19475 +       if (attr.ia_valid) {
19476 +               if (in->i_op && in->i_op->setattr)
19477 +                       error = in->i_op->setattr(de, &attr);
19478 +               else {
19479 +                       error = inode_change_ok(in, &attr);
19480 +                       if (!error) {
19481 +                               setattr_copy(in, &attr);
19482 +                               mark_inode_dirty(in);
19483 +                       }
19484 +               }
19485 +       }
19486 +
19487 +out:
19488 +       mutex_unlock(&in->i_mutex);
19489 +       return error;
19490 +}
19491 +
19492 +int vc_set_iattr(void __user *data)
19493 +{
19494 +       struct path path;
19495 +       struct vcmd_ctx_iattr_v1 vc_data;
19496 +       int ret;
19497 +
19498 +       if (!capable(CAP_LINUX_IMMUTABLE))
19499 +               return -EPERM;
19500 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19501 +               return -EFAULT;
19502 +
19503 +       ret = user_lpath(vc_data.name, &path);
19504 +       if (!ret) {
19505 +               ret = __vc_set_iattr(path.dentry,
19506 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
19507 +               path_put(&path);
19508 +       }
19509 +
19510 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19511 +               ret = -EFAULT;
19512 +       return ret;
19513 +}
19514 +
19515 +#ifdef CONFIG_COMPAT
19516 +
19517 +int vc_set_iattr_x32(void __user *data)
19518 +{
19519 +       struct path path;
19520 +       struct vcmd_ctx_iattr_v1_x32 vc_data;
19521 +       int ret;
19522 +
19523 +       if (!capable(CAP_LINUX_IMMUTABLE))
19524 +               return -EPERM;
19525 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19526 +               return -EFAULT;
19527 +
19528 +       ret = user_lpath(compat_ptr(vc_data.name_ptr), &path);
19529 +       if (!ret) {
19530 +               ret = __vc_set_iattr(path.dentry,
19531 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
19532 +               path_put(&path);
19533 +       }
19534 +
19535 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19536 +               ret = -EFAULT;
19537 +       return ret;
19538 +}
19539 +
19540 +#endif /* CONFIG_COMPAT */
19541 +
19542 +int vc_fset_iattr(uint32_t fd, void __user *data)
19543 +{
19544 +       struct file *filp;
19545 +       struct vcmd_ctx_fiattr_v0 vc_data;
19546 +       int ret;
19547 +
19548 +       if (!capable(CAP_LINUX_IMMUTABLE))
19549 +               return -EPERM;
19550 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19551 +               return -EFAULT;
19552 +
19553 +       filp = fget(fd);
19554 +       if (!filp || !filp->f_dentry || !filp->f_dentry->d_inode)
19555 +               return -EBADF;
19556 +
19557 +       ret = __vc_set_iattr(filp->f_dentry, &vc_data.tag,
19558 +               &vc_data.flags, &vc_data.mask);
19559 +
19560 +       fput(filp);
19561 +
19562 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19563 +               return -EFAULT;
19564 +       return ret;
19565 +}
19566 +
19567 +
19568 +enum { Opt_notagcheck, Opt_tag, Opt_notag, Opt_tagid, Opt_err };
19569 +
19570 +static match_table_t tokens = {
19571 +       {Opt_notagcheck, "notagcheck"},
19572 +#ifdef CONFIG_PROPAGATE
19573 +       {Opt_notag, "notag"},
19574 +       {Opt_tag, "tag"},
19575 +       {Opt_tagid, "tagid=%u"},
19576 +#endif
19577 +       {Opt_err, NULL}
19578 +};
19579 +
19580 +
19581 +static void __dx_parse_remove(char *string, char *opt)
19582 +{
19583 +       char *p = strstr(string, opt);
19584 +       char *q = p;
19585 +
19586 +       if (p) {
19587 +               while (*q != '\0' && *q != ',')
19588 +                       q++;
19589 +               while (*q)
19590 +                       *p++ = *q++;
19591 +               while (*p)
19592 +                       *p++ = '\0';
19593 +       }
19594 +}
19595 +
19596 +int dx_parse_tag(char *string, tag_t *tag, int remove, int *mnt_flags,
19597 +                unsigned long *flags)
19598 +{
19599 +       int set = 0;
19600 +       substring_t args[MAX_OPT_ARGS];
19601 +       int token;
19602 +       char *s, *p, *opts;
19603 +#if defined(CONFIG_PROPAGATE) || defined(CONFIG_VSERVER_DEBUG)
19604 +       int option = 0;
19605 +#endif
19606 +
19607 +       if (!string)
19608 +               return 0;
19609 +       s = kstrdup(string, GFP_KERNEL | GFP_ATOMIC);
19610 +       if (!s)
19611 +               return 0;
19612 +
19613 +       opts = s;
19614 +       while ((p = strsep(&opts, ",")) != NULL) {
19615 +               token = match_token(p, tokens, args);
19616 +
19617 +               switch (token) {
19618 +#ifdef CONFIG_PROPAGATE
19619 +               case Opt_tag:
19620 +                       if (tag)
19621 +                               *tag = 0;
19622 +                       if (remove)
19623 +                               __dx_parse_remove(s, "tag");
19624 +                       *mnt_flags |= MNT_TAGID;
19625 +                       set |= MNT_TAGID;
19626 +                       break;
19627 +               case Opt_notag:
19628 +                       if (remove)
19629 +                               __dx_parse_remove(s, "notag");
19630 +                       *mnt_flags |= MNT_NOTAG;
19631 +                       set |= MNT_NOTAG;
19632 +                       break;
19633 +               case Opt_tagid:
19634 +                       if (tag && !match_int(args, &option))
19635 +                               *tag = option;
19636 +                       if (remove)
19637 +                               __dx_parse_remove(s, "tagid");
19638 +                       *mnt_flags |= MNT_TAGID;
19639 +                       set |= MNT_TAGID;
19640 +                       break;
19641 +#endif /* CONFIG_PROPAGATE */
19642 +               case Opt_notagcheck:
19643 +                       if (remove)
19644 +                               __dx_parse_remove(s, "notagcheck");
19645 +                       *flags |= MS_NOTAGCHECK;
19646 +                       set |= MS_NOTAGCHECK;
19647 +                       break;
19648 +               }
19649 +               vxdprintk(VXD_CBIT(tag, 7),
19650 +                       "dx_parse_tag(" VS_Q("%s") "): %d:#%d",
19651 +                       p, token, option);
19652 +       }
19653 +       if (set)
19654 +               strcpy(string, s);
19655 +       kfree(s);
19656 +       return set;
19657 +}
19658 +
19659 +#ifdef CONFIG_PROPAGATE
19660 +
19661 +void __dx_propagate_tag(struct nameidata *nd, struct inode *inode)
19662 +{
19663 +       tag_t new_tag = 0;
19664 +       struct vfsmount *mnt;
19665 +       int propagate;
19666 +
19667 +       if (!nd)
19668 +               return;
19669 +       mnt = nd->path.mnt;
19670 +       if (!mnt)
19671 +               return;
19672 +
19673 +       propagate = (mnt->mnt_flags & MNT_TAGID);
19674 +       if (propagate)
19675 +               new_tag = mnt->mnt_tag;
19676 +
19677 +       vxdprintk(VXD_CBIT(tag, 7),
19678 +               "dx_propagate_tag(%p[#%lu.%d]): %d,%d",
19679 +               inode, inode->i_ino, inode->i_tag,
19680 +               new_tag, (propagate) ? 1 : 0);
19681 +
19682 +       if (propagate)
19683 +               inode->i_tag = new_tag;
19684 +}
19685 +
19686 +#include <linux/module.h>
19687 +
19688 +EXPORT_SYMBOL_GPL(__dx_propagate_tag);
19689 +
19690 +#endif /* CONFIG_PROPAGATE */
19691 +
19692 diff -NurpP --minimal linux-3.6.10/kernel/vserver/limit.c linux-3.6.10-vs2.3.4.5/kernel/vserver/limit.c
19693 --- linux-3.6.10/kernel/vserver/limit.c 1970-01-01 01:00:00.000000000 +0100
19694 +++ linux-3.6.10-vs2.3.4.5/kernel/vserver/limit.c       2012-10-04 18:47:00.000000000 +0200
19695 @@ -0,0 +1,345 @@
19696 +/*
19697 + *  linux/kernel/vserver/limit.c
19698 + *
19699 + *  Virtual Server: Context Limits
19700 + *
19701 + *  Copyright (C) 2004-2010  Herbert Pötzl
19702 + *
19703 + *  V0.01  broken out from vcontext V0.05
19704 + *  V0.02  changed vcmds to vxi arg
19705 + *  V0.03  added memory cgroup support
19706 + *
19707 + */
19708 +
19709 +#include <linux/sched.h>
19710 +#include <linux/module.h>
19711 +#include <linux/memcontrol.h>
19712 +#include <linux/res_counter.h>
19713 +#include <linux/vs_limit.h>
19714 +#include <linux/vserver/limit.h>
19715 +#include <linux/vserver/limit_cmd.h>
19716 +
19717 +#include <asm/uaccess.h>
19718 +
19719 +
19720 +const char *vlimit_name[NUM_LIMITS] = {
19721 +       [RLIMIT_CPU]            = "CPU",
19722 +       [RLIMIT_NPROC]          = "NPROC",
19723 +       [RLIMIT_NOFILE]         = "NOFILE",
19724 +       [RLIMIT_LOCKS]          = "LOCKS",
19725 +       [RLIMIT_SIGPENDING]     = "SIGP",
19726 +       [RLIMIT_MSGQUEUE]       = "MSGQ",
19727 +
19728 +       [VLIMIT_NSOCK]          = "NSOCK",
19729 +       [VLIMIT_OPENFD]         = "OPENFD",
19730 +       [VLIMIT_SHMEM]          = "SHMEM",
19731 +       [VLIMIT_DENTRY]         = "DENTRY",
19732 +};
19733 +
19734 +EXPORT_SYMBOL_GPL(vlimit_name);
19735 +
19736 +#define MASK_ENTRY(x)  (1 << (x))
19737 +
19738 +const struct vcmd_ctx_rlimit_mask_v0 vlimit_mask = {
19739 +               /* minimum */
19740 +       0
19741 +       ,       /* softlimit */
19742 +       0
19743 +       ,       /* maximum */
19744 +       MASK_ENTRY( RLIMIT_NPROC        ) |
19745 +       MASK_ENTRY( RLIMIT_NOFILE       ) |
19746 +       MASK_ENTRY( RLIMIT_LOCKS        ) |
19747 +       MASK_ENTRY( RLIMIT_MSGQUEUE     ) |
19748 +
19749 +       MASK_ENTRY( VLIMIT_NSOCK        ) |
19750 +       MASK_ENTRY( VLIMIT_OPENFD       ) |
19751 +       MASK_ENTRY( VLIMIT_SHMEM        ) |
19752 +       MASK_ENTRY( VLIMIT_DENTRY       ) |
19753 +       0
19754 +};
19755 +               /* accounting only */
19756 +uint32_t account_mask =
19757 +       MASK_ENTRY( VLIMIT_SEMARY       ) |
19758 +       MASK_ENTRY( VLIMIT_NSEMS        ) |
19759 +       MASK_ENTRY( VLIMIT_MAPPED       ) |
19760 +       0;
19761 +
19762 +
19763 +static int is_valid_vlimit(int id)
19764 +{
19765 +       uint32_t mask = vlimit_mask.minimum |
19766 +               vlimit_mask.softlimit | vlimit_mask.maximum;
19767 +       return mask & (1 << id);
19768 +}
19769 +
19770 +static int is_accounted_vlimit(int id)
19771 +{
19772 +       if (is_valid_vlimit(id))
19773 +               return 1;
19774 +       return account_mask & (1 << id);
19775 +}
19776 +
19777 +
19778 +static inline uint64_t vc_get_soft(struct vx_info *vxi, int id)
19779 +{
19780 +       rlim_t limit = __rlim_soft(&vxi->limit, id);
19781 +       return VX_VLIM(limit);
19782 +}
19783 +
19784 +static inline uint64_t vc_get_hard(struct vx_info *vxi, int id)
19785 +{
19786 +       rlim_t limit = __rlim_hard(&vxi->limit, id);
19787 +       return VX_VLIM(limit);
19788 +}
19789 +
19790 +static int do_get_rlimit(struct vx_info *vxi, uint32_t id,
19791 +       uint64_t *minimum, uint64_t *softlimit, uint64_t *maximum)
19792 +{
19793 +       if (!is_valid_vlimit(id))
19794 +               return -EINVAL;
19795 +
19796 +       if (minimum)
19797 +               *minimum = CRLIM_UNSET;
19798 +       if (softlimit)
19799 +               *softlimit = vc_get_soft(vxi, id);
19800 +       if (maximum)
19801 +               *maximum = vc_get_hard(vxi, id);
19802 +       return 0;
19803 +}
19804 +
19805 +int vc_get_rlimit(struct vx_info *vxi, void __user *data)
19806 +{
19807 +       struct vcmd_ctx_rlimit_v0 vc_data;
19808 +       int ret;
19809 +
19810 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19811 +               return -EFAULT;
19812 +
19813 +       ret = do_get_rlimit(vxi, vc_data.id,
19814 +               &vc_data.minimum, &vc_data.softlimit, &vc_data.maximum);
19815 +       if (ret)
19816 +               return ret;
19817 +
19818 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19819 +               return -EFAULT;
19820 +       return 0;
19821 +}
19822 +
19823 +static int do_set_rlimit(struct vx_info *vxi, uint32_t id,
19824 +       uint64_t minimum, uint64_t softlimit, uint64_t maximum)
19825 +{
19826 +       if (!is_valid_vlimit(id))
19827 +               return -EINVAL;
19828 +
19829 +       if (maximum != CRLIM_KEEP)
19830 +               __rlim_hard(&vxi->limit, id) = VX_RLIM(maximum);
19831 +       if (softlimit != CRLIM_KEEP)
19832 +               __rlim_soft(&vxi->limit, id) = VX_RLIM(softlimit);
19833 +
19834 +       /* clamp soft limit */
19835 +       if (__rlim_soft(&vxi->limit, id) > __rlim_hard(&vxi->limit, id))
19836 +               __rlim_soft(&vxi->limit, id) = __rlim_hard(&vxi->limit, id);
19837 +
19838 +       return 0;
19839 +}
19840 +
19841 +int vc_set_rlimit(struct vx_info *vxi, void __user *data)
19842 +{
19843 +       struct vcmd_ctx_rlimit_v0 vc_data;
19844 +
19845 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19846 +               return -EFAULT;
19847 +
19848 +       return do_set_rlimit(vxi, vc_data.id,
19849 +               vc_data.minimum, vc_data.softlimit, vc_data.maximum);
19850 +}
19851 +
19852 +#ifdef CONFIG_IA32_EMULATION
19853 +
19854 +int vc_set_rlimit_x32(struct vx_info *vxi, void __user *data)
19855 +{
19856 +       struct vcmd_ctx_rlimit_v0_x32 vc_data;
19857 +
19858 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19859 +               return -EFAULT;
19860 +
19861 +       return do_set_rlimit(vxi, vc_data.id,
19862 +               vc_data.minimum, vc_data.softlimit, vc_data.maximum);
19863 +}
19864 +
19865 +int vc_get_rlimit_x32(struct vx_info *vxi, void __user *data)
19866 +{
19867 +       struct vcmd_ctx_rlimit_v0_x32 vc_data;
19868 +       int ret;
19869 +
19870 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19871 +               return -EFAULT;
19872 +
19873 +       ret = do_get_rlimit(vxi, vc_data.id,
19874 +               &vc_data.minimum, &vc_data.softlimit, &vc_data.maximum);
19875 +       if (ret)
19876 +               return ret;
19877 +
19878 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19879 +               return -EFAULT;
19880 +       return 0;
19881 +}
19882 +
19883 +#endif /* CONFIG_IA32_EMULATION */
19884 +
19885 +
19886 +int vc_get_rlimit_mask(uint32_t id, void __user *data)
19887 +{
19888 +       if (copy_to_user(data, &vlimit_mask, sizeof(vlimit_mask)))
19889 +               return -EFAULT;
19890 +       return 0;
19891 +}
19892 +
19893 +
19894 +static inline void vx_reset_hits(struct _vx_limit *limit)
19895 +{
19896 +       int lim;
19897 +
19898 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
19899 +               atomic_set(&__rlim_lhit(limit, lim), 0);
19900 +       }
19901 +}
19902 +
19903 +int vc_reset_hits(struct vx_info *vxi, void __user *data)
19904 +{
19905 +       vx_reset_hits(&vxi->limit);
19906 +       return 0;
19907 +}
19908 +
19909 +static inline void vx_reset_minmax(struct _vx_limit *limit)
19910 +{
19911 +       rlim_t value;
19912 +       int lim;
19913 +
19914 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
19915 +               value = __rlim_get(limit, lim);
19916 +               __rlim_rmax(limit, lim) = value;
19917 +               __rlim_rmin(limit, lim) = value;
19918 +       }
19919 +}
19920 +
19921 +int vc_reset_minmax(struct vx_info *vxi, void __user *data)
19922 +{
19923 +       vx_reset_minmax(&vxi->limit);
19924 +       return 0;
19925 +}
19926 +
19927 +
19928 +int vc_rlimit_stat(struct vx_info *vxi, void __user *data)
19929 +{
19930 +       struct vcmd_rlimit_stat_v0 vc_data;
19931 +       struct _vx_limit *limit = &vxi->limit;
19932 +       int id;
19933 +
19934 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19935 +               return -EFAULT;
19936 +
19937 +       id = vc_data.id;
19938 +       if (!is_accounted_vlimit(id))
19939 +               return -EINVAL;
19940 +
19941 +       vx_limit_fixup(limit, id);
19942 +       vc_data.hits = atomic_read(&__rlim_lhit(limit, id));
19943 +       vc_data.value = __rlim_get(limit, id);
19944 +       vc_data.minimum = __rlim_rmin(limit, id);
19945 +       vc_data.maximum = __rlim_rmax(limit, id);
19946 +
19947 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19948 +               return -EFAULT;
19949 +       return 0;
19950 +}
19951 +
19952 +
19953 +void vx_vsi_meminfo(struct sysinfo *val)
19954 +{
19955 +#ifdef CONFIG_CGROUP_MEM_RES_CTLR
19956 +       struct mem_cgroup *mcg;
19957 +       u64 res_limit, res_usage;
19958 +
19959 +       rcu_read_lock();
19960 +       mcg = mem_cgroup_from_task(current);
19961 +       rcu_read_unlock();
19962 +       if (!mcg)
19963 +               goto out;
19964 +
19965 +       res_limit = mem_cgroup_res_read_u64(mcg, RES_LIMIT);
19966 +       res_usage = mem_cgroup_res_read_u64(mcg, RES_USAGE);
19967 +
19968 +       if (res_limit != RESOURCE_MAX)
19969 +               val->totalram = (res_limit >> PAGE_SHIFT);
19970 +       val->freeram = val->totalram - (res_usage >> PAGE_SHIFT);
19971 +       val->bufferram = 0;
19972 +       val->totalhigh = 0;
19973 +       val->freehigh = 0;
19974 +out:
19975 +#endif /* CONFIG_CGROUP_MEM_RES_CTLR */
19976 +       return;
19977 +}
19978 +
19979 +void vx_vsi_swapinfo(struct sysinfo *val)
19980 +{
19981 +#ifdef CONFIG_CGROUP_MEM_RES_CTLR
19982 +#ifdef CONFIG_CGROUP_MEM_RES_CTLR_SWAP
19983 +       struct mem_cgroup *mcg;
19984 +       u64 res_limit, res_usage, memsw_limit, memsw_usage;
19985 +       s64 swap_limit, swap_usage;
19986 +
19987 +       rcu_read_lock();
19988 +       mcg = mem_cgroup_from_task(current);
19989 +       rcu_read_unlock();
19990 +       if (!mcg)
19991 +               goto out;
19992 +
19993 +       res_limit = mem_cgroup_res_read_u64(mcg, RES_LIMIT);
19994 +       res_usage = mem_cgroup_res_read_u64(mcg, RES_USAGE);
19995 +       memsw_limit = mem_cgroup_memsw_read_u64(mcg, RES_LIMIT);
19996 +       memsw_usage = mem_cgroup_memsw_read_u64(mcg, RES_USAGE);
19997 +
19998 +       /* memory unlimited */
19999 +       if (res_limit == RESOURCE_MAX)
20000 +               goto out;
20001 +
20002 +       swap_limit = memsw_limit - res_limit;
20003 +       /* we have a swap limit? */
20004 +       if (memsw_limit != RESOURCE_MAX)
20005 +               val->totalswap = swap_limit >> PAGE_SHIFT;
20006 +
20007 +       /* calculate swap part */
20008 +       swap_usage = (memsw_usage > res_usage) ?
20009 +               memsw_usage - res_usage : 0;
20010 +
20011 +       /* total shown minus usage gives free swap */
20012 +       val->freeswap = (swap_usage < swap_limit) ?
20013 +               val->totalswap - (swap_usage >> PAGE_SHIFT) : 0;
20014 +out:
20015 +#else  /* !CONFIG_CGROUP_MEM_RES_CTLR_SWAP */
20016 +       val->totalswap = 0;
20017 +       val->freeswap = 0;
20018 +#endif /* !CONFIG_CGROUP_MEM_RES_CTLR_SWAP */
20019 +#endif /* CONFIG_CGROUP_MEM_RES_CTLR */
20020 +       return;
20021 +}
20022 +
20023 +long vx_vsi_cached(struct sysinfo *val)
20024 +{
20025 +       long cache = 0;
20026 +#ifdef CONFIG_CGROUP_MEM_RES_CTLR
20027 +       struct mem_cgroup *mcg;
20028 +
20029 +       rcu_read_lock();
20030 +       mcg = mem_cgroup_from_task(current);
20031 +       rcu_read_unlock();
20032 +       if (!mcg)
20033 +               goto out;
20034 +
20035 +       cache = mem_cgroup_stat_read_cache(mcg);
20036 +out:
20037 +#endif
20038 +       return cache;
20039 +}
20040 +
20041 diff -NurpP --minimal linux-3.6.10/kernel/vserver/limit_init.h linux-3.6.10-vs2.3.4.5/kernel/vserver/limit_init.h
20042 --- linux-3.6.10/kernel/vserver/limit_init.h    1970-01-01 01:00:00.000000000 +0100
20043 +++ linux-3.6.10-vs2.3.4.5/kernel/vserver/limit_init.h  2012-10-04 18:47:00.000000000 +0200
20044 @@ -0,0 +1,31 @@
20045 +
20046 +
20047 +static inline void vx_info_init_limit(struct _vx_limit *limit)
20048 +{
20049 +       int lim;
20050 +
20051 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
20052 +               __rlim_soft(limit, lim) = RLIM_INFINITY;
20053 +               __rlim_hard(limit, lim) = RLIM_INFINITY;
20054 +               __rlim_set(limit, lim, 0);
20055 +               atomic_set(&__rlim_lhit(limit, lim), 0);
20056 +               __rlim_rmin(limit, lim) = 0;
20057 +               __rlim_rmax(limit, lim) = 0;
20058 +       }
20059 +}
20060 +
20061 +static inline void vx_info_exit_limit(struct _vx_limit *limit)
20062 +{
20063 +       rlim_t value;
20064 +       int lim;
20065 +
20066 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
20067 +               if ((1 << lim) & VLIM_NOCHECK)
20068 +                       continue;
20069 +               value = __rlim_get(limit, lim);
20070 +               vxwprintk_xid(value,
20071 +                       "!!! limit: %p[%s,%d] = %ld on exit.",
20072 +                       limit, vlimit_name[lim], lim, (long)value);
20073 +       }
20074 +}
20075 +
20076 diff -NurpP --minimal linux-3.6.10/kernel/vserver/limit_proc.h linux-3.6.10-vs2.3.4.5/kernel/vserver/limit_proc.h
20077 --- linux-3.6.10/kernel/vserver/limit_proc.h    1970-01-01 01:00:00.000000000 +0100
20078 +++ linux-3.6.10-vs2.3.4.5/kernel/vserver/limit_proc.h  2012-10-04 18:47:00.000000000 +0200
20079 @@ -0,0 +1,57 @@
20080 +#ifndef _VX_LIMIT_PROC_H
20081 +#define _VX_LIMIT_PROC_H
20082 +
20083 +#include <linux/vserver/limit_int.h>
20084 +
20085 +
20086 +#define VX_LIMIT_FMT   ":\t%8ld\t%8ld/%8ld\t%8lld/%8lld\t%6d\n"
20087 +#define VX_LIMIT_TOP   \
20088 +       "Limit\t current\t     min/max\t\t    soft/hard\t\thits\n"
20089 +
20090 +#define VX_LIMIT_ARG(r)                                \
20091 +       (unsigned long)__rlim_get(limit, r),    \
20092 +       (unsigned long)__rlim_rmin(limit, r),   \
20093 +       (unsigned long)__rlim_rmax(limit, r),   \
20094 +       VX_VLIM(__rlim_soft(limit, r)),         \
20095 +       VX_VLIM(__rlim_hard(limit, r)),         \
20096 +       atomic_read(&__rlim_lhit(limit, r))
20097 +
20098 +static inline int vx_info_proc_limit(struct _vx_limit *limit, char *buffer)
20099 +{
20100 +       vx_limit_fixup(limit, -1);
20101 +       return sprintf(buffer, VX_LIMIT_TOP
20102 +               "PROC"  VX_LIMIT_FMT
20103 +               "VM"    VX_LIMIT_FMT
20104 +               "VML"   VX_LIMIT_FMT
20105 +               "RSS"   VX_LIMIT_FMT
20106 +               "ANON"  VX_LIMIT_FMT
20107 +               "RMAP"  VX_LIMIT_FMT
20108 +               "FILES" VX_LIMIT_FMT
20109 +               "OFD"   VX_LIMIT_FMT
20110 +               "LOCKS" VX_LIMIT_FMT
20111 +               "SOCK"  VX_LIMIT_FMT
20112 +               "MSGQ"  VX_LIMIT_FMT
20113 +               "SHM"   VX_LIMIT_FMT
20114 +               "SEMA"  VX_LIMIT_FMT
20115 +               "SEMS"  VX_LIMIT_FMT
20116 +               "DENT"  VX_LIMIT_FMT,
20117 +               VX_LIMIT_ARG(RLIMIT_NPROC),
20118 +               VX_LIMIT_ARG(RLIMIT_AS),
20119 +               VX_LIMIT_ARG(RLIMIT_MEMLOCK),
20120 +               VX_LIMIT_ARG(RLIMIT_RSS),
20121 +               VX_LIMIT_ARG(VLIMIT_ANON),
20122 +               VX_LIMIT_ARG(VLIMIT_MAPPED),
20123 +               VX_LIMIT_ARG(RLIMIT_NOFILE),
20124 +               VX_LIMIT_ARG(VLIMIT_OPENFD),
20125 +               VX_LIMIT_ARG(RLIMIT_LOCKS),
20126 +               VX_LIMIT_ARG(VLIMIT_NSOCK),
20127 +               VX_LIMIT_ARG(RLIMIT_MSGQUEUE),
20128 +               VX_LIMIT_ARG(VLIMIT_SHMEM),
20129 +               VX_LIMIT_ARG(VLIMIT_SEMARY),
20130 +               VX_LIMIT_ARG(VLIMIT_NSEMS),
20131 +               VX_LIMIT_ARG(VLIMIT_DENTRY));
20132 +}
20133 +
20134 +#endif /* _VX_LIMIT_PROC_H */
20135 +
20136 +
20137 diff -NurpP --minimal linux-3.6.10/kernel/vserver/network.c linux-3.6.10-vs2.3.4.5/kernel/vserver/network.c
20138 --- linux-3.6.10/kernel/vserver/network.c       1970-01-01 01:00:00.000000000 +0100
20139 +++ linux-3.6.10-vs2.3.4.5/kernel/vserver/network.c     2012-10-04 18:47:00.000000000 +0200
20140 @@ -0,0 +1,912 @@
20141 +/*
20142 + *  linux/kernel/vserver/network.c
20143 + *
20144 + *  Virtual Server: Network Support
20145 + *
20146 + *  Copyright (C) 2003-2007  Herbert Pötzl
20147 + *
20148 + *  V0.01  broken out from vcontext V0.05
20149 + *  V0.02  cleaned up implementation
20150 + *  V0.03  added equiv nx commands
20151 + *  V0.04  switch to RCU based hash
20152 + *  V0.05  and back to locking again
20153 + *  V0.06  changed vcmds to nxi arg
20154 + *  V0.07  have __create claim() the nxi
20155 + *
20156 + */
20157 +
20158 +#include <linux/err.h>
20159 +#include <linux/slab.h>
20160 +#include <linux/rcupdate.h>
20161 +
20162 +#include <linux/vs_network.h>
20163 +#include <linux/vs_pid.h>
20164 +#include <linux/vserver/network_cmd.h>
20165 +
20166 +
20167 +atomic_t nx_global_ctotal      = ATOMIC_INIT(0);
20168 +atomic_t nx_global_cactive     = ATOMIC_INIT(0);
20169 +
20170 +static struct kmem_cache *nx_addr_v4_cachep = NULL;
20171 +static struct kmem_cache *nx_addr_v6_cachep = NULL;
20172 +
20173 +
20174 +static int __init init_network(void)
20175 +{
20176 +       nx_addr_v4_cachep = kmem_cache_create("nx_v4_addr_cache",
20177 +               sizeof(struct nx_addr_v4), 0,
20178 +               SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
20179 +       nx_addr_v6_cachep = kmem_cache_create("nx_v6_addr_cache",
20180 +               sizeof(struct nx_addr_v6), 0,
20181 +               SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
20182 +       return 0;
20183 +}
20184 +
20185 +
20186 +/*     __alloc_nx_addr_v4()                                    */
20187 +
20188 +static inline struct nx_addr_v4 *__alloc_nx_addr_v4(void)
20189 +{
20190 +       struct nx_addr_v4 *nxa = kmem_cache_alloc(
20191 +               nx_addr_v4_cachep, GFP_KERNEL);
20192 +
20193 +       if (!IS_ERR(nxa))
20194 +               memset(nxa, 0, sizeof(*nxa));
20195 +       return nxa;
20196 +}
20197 +
20198 +/*     __dealloc_nx_addr_v4()                                  */
20199 +
20200 +static inline void __dealloc_nx_addr_v4(struct nx_addr_v4 *nxa)
20201 +{
20202 +       kmem_cache_free(nx_addr_v4_cachep, nxa);
20203 +}
20204 +
20205 +/*     __dealloc_nx_addr_v4_all()                              */
20206 +
20207 +static inline void __dealloc_nx_addr_v4_all(struct nx_addr_v4 *nxa)
20208 +{
20209 +       while (nxa) {
20210 +               struct nx_addr_v4 *next = nxa->next;
20211 +
20212 +               __dealloc_nx_addr_v4(nxa);
20213 +               nxa = next;
20214 +       }
20215 +}
20216 +
20217 +
20218 +#ifdef CONFIG_IPV6
20219 +
20220 +/*     __alloc_nx_addr_v6()                                    */
20221 +
20222 +static inline struct nx_addr_v6 *__alloc_nx_addr_v6(void)
20223 +{
20224 +       struct nx_addr_v6 *nxa = kmem_cache_alloc(
20225 +               nx_addr_v6_cachep, GFP_KERNEL);
20226 +
20227 +       if (!IS_ERR(nxa))
20228 +               memset(nxa, 0, sizeof(*nxa));
20229 +       return nxa;
20230 +}
20231 +
20232 +/*     __dealloc_nx_addr_v6()                                  */
20233 +
20234 +static inline void __dealloc_nx_addr_v6(struct nx_addr_v6 *nxa)
20235 +{
20236 +       kmem_cache_free(nx_addr_v6_cachep, nxa);
20237 +}
20238 +
20239 +/*     __dealloc_nx_addr_v6_all()                              */
20240 +
20241 +static inline void __dealloc_nx_addr_v6_all(struct nx_addr_v6 *nxa)
20242 +{
20243 +       while (nxa) {
20244 +               struct nx_addr_v6 *next = nxa->next;
20245 +
20246 +               __dealloc_nx_addr_v6(nxa);
20247 +               nxa = next;
20248 +       }
20249 +}
20250 +
20251 +#endif /* CONFIG_IPV6 */
20252 +
20253 +/*     __alloc_nx_info()
20254 +
20255 +       * allocate an initialized nx_info struct
20256 +       * doesn't make it visible (hash)                        */
20257 +
20258 +static struct nx_info *__alloc_nx_info(nid_t nid)
20259 +{
20260 +       struct nx_info *new = NULL;
20261 +
20262 +       vxdprintk(VXD_CBIT(nid, 1), "alloc_nx_info(%d)*", nid);
20263 +
20264 +       /* would this benefit from a slab cache? */
20265 +       new = kmalloc(sizeof(struct nx_info), GFP_KERNEL);
20266 +       if (!new)
20267 +               return 0;
20268 +
20269 +       memset(new, 0, sizeof(struct nx_info));
20270 +       new->nx_id = nid;
20271 +       INIT_HLIST_NODE(&new->nx_hlist);
20272 +       atomic_set(&new->nx_usecnt, 0);
20273 +       atomic_set(&new->nx_tasks, 0);
20274 +       new->nx_state = 0;
20275 +
20276 +       new->nx_flags = NXF_INIT_SET;
20277 +
20278 +       /* rest of init goes here */
20279 +
20280 +       new->v4_lback.s_addr = htonl(INADDR_LOOPBACK);
20281 +       new->v4_bcast.s_addr = htonl(INADDR_BROADCAST);
20282 +
20283 +       vxdprintk(VXD_CBIT(nid, 0),
20284 +               "alloc_nx_info(%d) = %p", nid, new);
20285 +       atomic_inc(&nx_global_ctotal);
20286 +       return new;
20287 +}
20288 +
20289 +/*     __dealloc_nx_info()
20290 +
20291 +       * final disposal of nx_info                             */
20292 +
20293 +static void __dealloc_nx_info(struct nx_info *nxi)
20294 +{
20295 +       vxdprintk(VXD_CBIT(nid, 0),
20296 +               "dealloc_nx_info(%p)", nxi);
20297 +
20298 +       nxi->nx_hlist.next = LIST_POISON1;
20299 +       nxi->nx_id = -1;
20300 +
20301 +       BUG_ON(atomic_read(&nxi->nx_usecnt));
20302 +       BUG_ON(atomic_read(&nxi->nx_tasks));
20303 +
20304 +       __dealloc_nx_addr_v4_all(nxi->v4.next);
20305 +
20306 +       nxi->nx_state |= NXS_RELEASED;
20307 +       kfree(nxi);
20308 +       atomic_dec(&nx_global_ctotal);
20309 +}
20310 +
20311 +static void __shutdown_nx_info(struct nx_info *nxi)
20312 +{
20313 +       nxi->nx_state |= NXS_SHUTDOWN;
20314 +       vs_net_change(nxi, VSC_NETDOWN);
20315 +}
20316 +
20317 +/*     exported stuff                                          */
20318 +
20319 +void free_nx_info(struct nx_info *nxi)
20320 +{
20321 +       /* context shutdown is mandatory */
20322 +       BUG_ON(nxi->nx_state != NXS_SHUTDOWN);
20323 +
20324 +       /* context must not be hashed */
20325 +       BUG_ON(nxi->nx_state & NXS_HASHED);
20326 +
20327 +       BUG_ON(atomic_read(&nxi->nx_usecnt));
20328 +       BUG_ON(atomic_read(&nxi->nx_tasks));
20329 +
20330 +       __dealloc_nx_info(nxi);
20331 +}
20332 +
20333 +
20334 +void __nx_set_lback(struct nx_info *nxi)
20335 +{
20336 +       int nid = nxi->nx_id;
20337 +       __be32 lback = htonl(INADDR_LOOPBACK ^ ((nid & 0xFFFF) << 8));
20338 +
20339 +       nxi->v4_lback.s_addr = lback;
20340 +}
20341 +
20342 +extern int __nx_inet_add_lback(__be32 addr);
20343 +extern int __nx_inet_del_lback(__be32 addr);
20344 +
20345 +
20346 +/*     hash table for nx_info hash */
20347 +
20348 +#define NX_HASH_SIZE   13
20349 +
20350 +struct hlist_head nx_info_hash[NX_HASH_SIZE];
20351 +
20352 +static DEFINE_SPINLOCK(nx_info_hash_lock);
20353 +
20354 +
20355 +static inline unsigned int __hashval(nid_t nid)
20356 +{
20357 +       return (nid % NX_HASH_SIZE);
20358 +}
20359 +
20360 +
20361 +
20362 +/*     __hash_nx_info()
20363 +
20364 +       * add the nxi to the global hash table
20365 +       * requires the hash_lock to be held                     */
20366 +
20367 +static inline void __hash_nx_info(struct nx_info *nxi)
20368 +{
20369 +       struct hlist_head *head;
20370 +
20371 +       vxd_assert_lock(&nx_info_hash_lock);
20372 +       vxdprintk(VXD_CBIT(nid, 4),
20373 +               "__hash_nx_info: %p[#%d]", nxi, nxi->nx_id);
20374 +
20375 +       /* context must not be hashed */
20376 +       BUG_ON(nx_info_state(nxi, NXS_HASHED));
20377 +
20378 +       nxi->nx_state |= NXS_HASHED;
20379 +       head = &nx_info_hash[__hashval(nxi->nx_id)];
20380 +       hlist_add_head(&nxi->nx_hlist, head);
20381 +       atomic_inc(&nx_global_cactive);
20382 +}
20383 +
20384 +/*     __unhash_nx_info()
20385 +
20386 +       * remove the nxi from the global hash table
20387 +       * requires the hash_lock to be held                     */
20388 +
20389 +static inline void __unhash_nx_info(struct nx_info *nxi)
20390 +{
20391 +       vxd_assert_lock(&nx_info_hash_lock);
20392 +       vxdprintk(VXD_CBIT(nid, 4),
20393 +               "__unhash_nx_info: %p[#%d.%d.%d]", nxi, nxi->nx_id,
20394 +               atomic_read(&nxi->nx_usecnt), atomic_read(&nxi->nx_tasks));
20395 +
20396 +       /* context must be hashed */
20397 +       BUG_ON(!nx_info_state(nxi, NXS_HASHED));
20398 +       /* but without tasks */
20399 +       BUG_ON(atomic_read(&nxi->nx_tasks));
20400 +
20401 +       nxi->nx_state &= ~NXS_HASHED;
20402 +       hlist_del(&nxi->nx_hlist);
20403 +       atomic_dec(&nx_global_cactive);
20404 +}
20405 +
20406 +
20407 +/*     __lookup_nx_info()
20408 +
20409 +       * requires the hash_lock to be held
20410 +       * doesn't increment the nx_refcnt                       */
20411 +
20412 +static inline struct nx_info *__lookup_nx_info(nid_t nid)
20413 +{
20414 +       struct hlist_head *head = &nx_info_hash[__hashval(nid)];
20415 +       struct hlist_node *pos;
20416 +       struct nx_info *nxi;
20417 +
20418 +       vxd_assert_lock(&nx_info_hash_lock);
20419 +       hlist_for_each(pos, head) {
20420 +               nxi = hlist_entry(pos, struct nx_info, nx_hlist);
20421 +
20422 +               if (nxi->nx_id == nid)
20423 +                       goto found;
20424 +       }
20425 +       nxi = NULL;
20426 +found:
20427 +       vxdprintk(VXD_CBIT(nid, 0),
20428 +               "__lookup_nx_info(#%u): %p[#%u]",
20429 +               nid, nxi, nxi ? nxi->nx_id : 0);
20430 +       return nxi;
20431 +}
20432 +
20433 +
20434 +/*     __create_nx_info()
20435 +
20436 +       * create the requested context
20437 +       * get(), claim() and hash it                            */
20438 +
20439 +static struct nx_info *__create_nx_info(int id)
20440 +{
20441 +       struct nx_info *new, *nxi = NULL;
20442 +
20443 +       vxdprintk(VXD_CBIT(nid, 1), "create_nx_info(%d)*", id);
20444 +
20445 +       if (!(new = __alloc_nx_info(id)))
20446 +               return ERR_PTR(-ENOMEM);
20447 +
20448 +       /* required to make dynamic xids unique */
20449 +       spin_lock(&nx_info_hash_lock);
20450 +
20451 +       /* static context requested */
20452 +       if ((nxi = __lookup_nx_info(id))) {
20453 +               vxdprintk(VXD_CBIT(nid, 0),
20454 +                       "create_nx_info(%d) = %p (already there)", id, nxi);
20455 +               if (nx_info_flags(nxi, NXF_STATE_SETUP, 0))
20456 +                       nxi = ERR_PTR(-EBUSY);
20457 +               else
20458 +                       nxi = ERR_PTR(-EEXIST);
20459 +               goto out_unlock;
20460 +       }
20461 +       /* new context */
20462 +       vxdprintk(VXD_CBIT(nid, 0),
20463 +               "create_nx_info(%d) = %p (new)", id, new);
20464 +       claim_nx_info(new, NULL);
20465 +       __nx_set_lback(new);
20466 +       __hash_nx_info(get_nx_info(new));
20467 +       nxi = new, new = NULL;
20468 +
20469 +out_unlock:
20470 +       spin_unlock(&nx_info_hash_lock);
20471 +       if (new)
20472 +               __dealloc_nx_info(new);
20473 +       return nxi;
20474 +}
20475 +
20476 +
20477 +
20478 +/*     exported stuff                                          */
20479 +
20480 +
20481 +void unhash_nx_info(struct nx_info *nxi)
20482 +{
20483 +       __shutdown_nx_info(nxi);
20484 +       spin_lock(&nx_info_hash_lock);
20485 +       __unhash_nx_info(nxi);
20486 +       spin_unlock(&nx_info_hash_lock);
20487 +}
20488 +
20489 +/*     lookup_nx_info()
20490 +
20491 +       * search for a nx_info and get() it
20492 +       * negative id means current                             */
20493 +
20494 +struct nx_info *lookup_nx_info(int id)
20495 +{
20496 +       struct nx_info *nxi = NULL;
20497 +
20498 +       if (id < 0) {
20499 +               nxi = get_nx_info(current_nx_info());
20500 +       } else if (id > 1) {
20501 +               spin_lock(&nx_info_hash_lock);
20502 +               nxi = get_nx_info(__lookup_nx_info(id));
20503 +               spin_unlock(&nx_info_hash_lock);
20504 +       }
20505 +       return nxi;
20506 +}
20507 +
20508 +/*     nid_is_hashed()
20509 +
20510 +       * verify that nid is still hashed                       */
20511 +
20512 +int nid_is_hashed(nid_t nid)
20513 +{
20514 +       int hashed;
20515 +
20516 +       spin_lock(&nx_info_hash_lock);
20517 +       hashed = (__lookup_nx_info(nid) != NULL);
20518 +       spin_unlock(&nx_info_hash_lock);
20519 +       return hashed;
20520 +}
20521 +
20522 +
20523 +#ifdef CONFIG_PROC_FS
20524 +
20525 +/*     get_nid_list()
20526 +
20527 +       * get a subset of hashed nids for proc
20528 +       * assumes size is at least one                          */
20529 +
20530 +int get_nid_list(int index, unsigned int *nids, int size)
20531 +{
20532 +       int hindex, nr_nids = 0;
20533 +
20534 +       /* only show current and children */
20535 +       if (!nx_check(0, VS_ADMIN | VS_WATCH)) {
20536 +               if (index > 0)
20537 +                       return 0;
20538 +               nids[nr_nids] = nx_current_nid();
20539 +               return 1;
20540 +       }
20541 +
20542 +       for (hindex = 0; hindex < NX_HASH_SIZE; hindex++) {
20543 +               struct hlist_head *head = &nx_info_hash[hindex];
20544 +               struct hlist_node *pos;
20545 +
20546 +               spin_lock(&nx_info_hash_lock);
20547 +               hlist_for_each(pos, head) {
20548 +                       struct nx_info *nxi;
20549 +
20550 +                       if (--index > 0)
20551 +                               continue;
20552 +
20553 +                       nxi = hlist_entry(pos, struct nx_info, nx_hlist);
20554 +                       nids[nr_nids] = nxi->nx_id;
20555 +                       if (++nr_nids >= size) {
20556 +                               spin_unlock(&nx_info_hash_lock);
20557 +                               goto out;
20558 +                       }
20559 +               }
20560 +               /* keep the lock time short */
20561 +               spin_unlock(&nx_info_hash_lock);
20562 +       }
20563 +out:
20564 +       return nr_nids;
20565 +}
20566 +#endif
20567 +
20568 +
20569 +/*
20570 + *     migrate task to new network
20571 + *     gets nxi, puts old_nxi on change
20572 + */
20573 +
20574 +int nx_migrate_task(struct task_struct *p, struct nx_info *nxi)
20575 +{
20576 +       struct nx_info *old_nxi;
20577 +       int ret = 0;
20578 +
20579 +       if (!p || !nxi)
20580 +               BUG();
20581 +
20582 +       vxdprintk(VXD_CBIT(nid, 5),
20583 +               "nx_migrate_task(%p,%p[#%d.%d.%d])",
20584 +               p, nxi, nxi->nx_id,
20585 +               atomic_read(&nxi->nx_usecnt),
20586 +               atomic_read(&nxi->nx_tasks));
20587 +
20588 +       if (nx_info_flags(nxi, NXF_INFO_PRIVATE, 0) &&
20589 +               !nx_info_flags(nxi, NXF_STATE_SETUP, 0))
20590 +               return -EACCES;
20591 +
20592 +       if (nx_info_state(nxi, NXS_SHUTDOWN))
20593 +               return -EFAULT;
20594 +
20595 +       /* maybe disallow this completely? */
20596 +       old_nxi = task_get_nx_info(p);
20597 +       if (old_nxi == nxi)
20598 +               goto out;
20599 +
20600 +       task_lock(p);
20601 +       if (old_nxi)
20602 +               clr_nx_info(&p->nx_info);
20603 +       claim_nx_info(nxi, p);
20604 +       set_nx_info(&p->nx_info, nxi);
20605 +       p->nid = nxi->nx_id;
20606 +       task_unlock(p);
20607 +
20608 +       vxdprintk(VXD_CBIT(nid, 5),
20609 +               "moved task %p into nxi:%p[#%d]",
20610 +               p, nxi, nxi->nx_id);
20611 +
20612 +       if (old_nxi)
20613 +               release_nx_info(old_nxi, p);
20614 +       ret = 0;
20615 +out:
20616 +       put_nx_info(old_nxi);
20617 +       return ret;
20618 +}
20619 +
20620 +
20621 +void nx_set_persistent(struct nx_info *nxi)
20622 +{
20623 +       vxdprintk(VXD_CBIT(nid, 6),
20624 +               "nx_set_persistent(%p[#%d])", nxi, nxi->nx_id);
20625 +
20626 +       get_nx_info(nxi);
20627 +       claim_nx_info(nxi, NULL);
20628 +}
20629 +
20630 +void nx_clear_persistent(struct nx_info *nxi)
20631 +{
20632 +       vxdprintk(VXD_CBIT(nid, 6),
20633 +               "nx_clear_persistent(%p[#%d])", nxi, nxi->nx_id);
20634 +
20635 +       release_nx_info(nxi, NULL);
20636 +       put_nx_info(nxi);
20637 +}
20638 +
20639 +void nx_update_persistent(struct nx_info *nxi)
20640 +{
20641 +       if (nx_info_flags(nxi, NXF_PERSISTENT, 0))
20642 +               nx_set_persistent(nxi);
20643 +       else
20644 +               nx_clear_persistent(nxi);
20645 +}
20646 +
20647 +/* vserver syscall commands below here */
20648 +
20649 +/* taks nid and nx_info functions */
20650 +
20651 +#include <asm/uaccess.h>
20652 +
20653 +
20654 +int vc_task_nid(uint32_t id)
20655 +{
20656 +       nid_t nid;
20657 +
20658 +       if (id) {
20659 +               struct task_struct *tsk;
20660 +
20661 +               rcu_read_lock();
20662 +               tsk = find_task_by_real_pid(id);
20663 +               nid = (tsk) ? tsk->nid : -ESRCH;
20664 +               rcu_read_unlock();
20665 +       } else
20666 +               nid = nx_current_nid();
20667 +       return nid;
20668 +}
20669 +
20670 +
20671 +int vc_nx_info(struct nx_info *nxi, void __user *data)
20672 +{
20673 +       struct vcmd_nx_info_v0 vc_data;
20674 +
20675 +       vc_data.nid = nxi->nx_id;
20676 +
20677 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20678 +               return -EFAULT;
20679 +       return 0;
20680 +}
20681 +
20682 +
20683 +/* network functions */
20684 +
20685 +int vc_net_create(uint32_t nid, void __user *data)
20686 +{
20687 +       struct vcmd_net_create vc_data = { .flagword = NXF_INIT_SET };
20688 +       struct nx_info *new_nxi;
20689 +       int ret;
20690 +
20691 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20692 +               return -EFAULT;
20693 +
20694 +       if ((nid > MAX_S_CONTEXT) || (nid < 2))
20695 +               return -EINVAL;
20696 +
20697 +       new_nxi = __create_nx_info(nid);
20698 +       if (IS_ERR(new_nxi))
20699 +               return PTR_ERR(new_nxi);
20700 +
20701 +       /* initial flags */
20702 +       new_nxi->nx_flags = vc_data.flagword;
20703 +
20704 +       ret = -ENOEXEC;
20705 +       if (vs_net_change(new_nxi, VSC_NETUP))
20706 +               goto out;
20707 +
20708 +       ret = nx_migrate_task(current, new_nxi);
20709 +       if (ret)
20710 +               goto out;
20711 +
20712 +       /* return context id on success */
20713 +       ret = new_nxi->nx_id;
20714 +
20715 +       /* get a reference for persistent contexts */
20716 +       if ((vc_data.flagword & NXF_PERSISTENT))
20717 +               nx_set_persistent(new_nxi);
20718 +out:
20719 +       release_nx_info(new_nxi, NULL);
20720 +       put_nx_info(new_nxi);
20721 +       return ret;
20722 +}
20723 +
20724 +
20725 +int vc_net_migrate(struct nx_info *nxi, void __user *data)
20726 +{
20727 +       return nx_migrate_task(current, nxi);
20728 +}
20729 +
20730 +
20731 +
20732 +int do_add_v4_addr(struct nx_info *nxi, __be32 ip, __be32 ip2, __be32 mask,
20733 +       uint16_t type, uint16_t flags)
20734 +{
20735 +       struct nx_addr_v4 *nxa = &nxi->v4;
20736 +
20737 +       if (NX_IPV4(nxi)) {
20738 +               /* locate last entry */
20739 +               for (; nxa->next; nxa = nxa->next);
20740 +               nxa->next = __alloc_nx_addr_v4();
20741 +               nxa = nxa->next;
20742 +
20743 +               if (IS_ERR(nxa))
20744 +                       return PTR_ERR(nxa);
20745 +       }
20746 +
20747 +       if (nxi->v4.next)
20748 +               /* remove single ip for ip list */
20749 +               nxi->nx_flags &= ~NXF_SINGLE_IP;
20750 +
20751 +       nxa->ip[0].s_addr = ip;
20752 +       nxa->ip[1].s_addr = ip2;
20753 +       nxa->mask.s_addr = mask;
20754 +       nxa->type = type;
20755 +       nxa->flags = flags;
20756 +       return 0;
20757 +}
20758 +
20759 +int do_remove_v4_addr(struct nx_info *nxi, __be32 ip, __be32 ip2, __be32 mask,
20760 +       uint16_t type, uint16_t flags)
20761 +{
20762 +       struct nx_addr_v4 *nxa = &nxi->v4;
20763 +
20764 +       switch (type) {
20765 +/*     case NXA_TYPE_ADDR:
20766 +               break;          */
20767 +
20768 +       case NXA_TYPE_ANY:
20769 +               __dealloc_nx_addr_v4_all(xchg(&nxa->next, NULL));
20770 +               memset(nxa, 0, sizeof(*nxa));
20771 +               break;
20772 +
20773 +       default:
20774 +               return -EINVAL;
20775 +       }
20776 +       return 0;
20777 +}
20778 +
20779 +
20780 +int vc_net_add(struct nx_info *nxi, void __user *data)
20781 +{
20782 +       struct vcmd_net_addr_v0 vc_data;
20783 +       int index, ret = 0;
20784 +
20785 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20786 +               return -EFAULT;
20787 +
20788 +       switch (vc_data.type) {
20789 +       case NXA_TYPE_IPV4:
20790 +               if ((vc_data.count < 1) || (vc_data.count > 4))
20791 +                       return -EINVAL;
20792 +
20793 +               index = 0;
20794 +               while (index < vc_data.count) {
20795 +                       ret = do_add_v4_addr(nxi, vc_data.ip[index].s_addr, 0,
20796 +                               vc_data.mask[index].s_addr, NXA_TYPE_ADDR, 0);
20797 +                       if (ret)
20798 +                               return ret;
20799 +                       index++;
20800 +               }
20801 +               ret = index;
20802 +               break;
20803 +
20804 +       case NXA_TYPE_IPV4|NXA_MOD_BCAST:
20805 +               nxi->v4_bcast = vc_data.ip[0];
20806 +               ret = 1;
20807 +               break;
20808 +
20809 +       case NXA_TYPE_IPV4|NXA_MOD_LBACK:
20810 +               nxi->v4_lback = vc_data.ip[0];
20811 +               ret = 1;
20812 +               break;
20813 +
20814 +       default:
20815 +               ret = -EINVAL;
20816 +               break;
20817 +       }
20818 +       return ret;
20819 +}
20820 +
20821 +int vc_net_remove(struct nx_info *nxi, void __user *data)
20822 +{
20823 +       struct vcmd_net_addr_v0 vc_data;
20824 +
20825 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20826 +               return -EFAULT;
20827 +
20828 +       switch (vc_data.type) {
20829 +       case NXA_TYPE_ANY:
20830 +               __dealloc_nx_addr_v4_all(xchg(&nxi->v4.next, NULL));
20831 +               memset(&nxi->v4, 0, sizeof(nxi->v4));
20832 +               break;
20833 +
20834 +       default:
20835 +               return -EINVAL;
20836 +       }
20837 +       return 0;
20838 +}
20839 +
20840 +
20841 +int vc_net_add_ipv4_v1(struct nx_info *nxi, void __user *data)
20842 +{
20843 +       struct vcmd_net_addr_ipv4_v1 vc_data;
20844 +
20845 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20846 +               return -EFAULT;
20847 +
20848 +       switch (vc_data.type) {
20849 +       case NXA_TYPE_ADDR:
20850 +       case NXA_TYPE_MASK:
20851 +               return do_add_v4_addr(nxi, vc_data.ip.s_addr, 0,
20852 +                       vc_data.mask.s_addr, vc_data.type, vc_data.flags);
20853 +
20854 +       case NXA_TYPE_ADDR | NXA_MOD_BCAST:
20855 +               nxi->v4_bcast = vc_data.ip;
20856 +               break;
20857 +
20858 +       case NXA_TYPE_ADDR | NXA_MOD_LBACK:
20859 +               nxi->v4_lback = vc_data.ip;
20860 +               break;
20861 +
20862 +       default:
20863 +               return -EINVAL;
20864 +       }
20865 +       return 0;
20866 +}
20867 +
20868 +int vc_net_add_ipv4(struct nx_info *nxi, void __user *data)
20869 +{
20870 +       struct vcmd_net_addr_ipv4_v2 vc_data;
20871 +
20872 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20873 +               return -EFAULT;
20874 +
20875 +       switch (vc_data.type) {
20876 +       case NXA_TYPE_ADDR:
20877 +       case NXA_TYPE_MASK:
20878 +       case NXA_TYPE_RANGE:
20879 +               return do_add_v4_addr(nxi, vc_data.ip.s_addr, vc_data.ip2.s_addr,
20880 +                       vc_data.mask.s_addr, vc_data.type, vc_data.flags);
20881 +
20882 +       case NXA_TYPE_ADDR | NXA_MOD_BCAST:
20883 +               nxi->v4_bcast = vc_data.ip;
20884 +               break;
20885 +
20886 +       case NXA_TYPE_ADDR | NXA_MOD_LBACK:
20887 +               nxi->v4_lback = vc_data.ip;
20888 +               break;
20889 +
20890 +       default:
20891 +               return -EINVAL;
20892 +       }
20893 +       return 0;
20894 +}
20895 +
20896 +int vc_net_rem_ipv4_v1(struct nx_info *nxi, void __user *data)
20897 +{
20898 +       struct vcmd_net_addr_ipv4_v1 vc_data;
20899 +
20900 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20901 +               return -EFAULT;
20902 +
20903 +       return do_remove_v4_addr(nxi, vc_data.ip.s_addr, 0,
20904 +               vc_data.mask.s_addr, vc_data.type, vc_data.flags);
20905 +}
20906 +
20907 +int vc_net_rem_ipv4(struct nx_info *nxi, void __user *data)
20908 +{
20909 +       struct vcmd_net_addr_ipv4_v2 vc_data;
20910 +
20911 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20912 +               return -EFAULT;
20913 +
20914 +       return do_remove_v4_addr(nxi, vc_data.ip.s_addr, vc_data.ip2.s_addr,
20915 +               vc_data.mask.s_addr, vc_data.type, vc_data.flags);
20916 +}
20917 +
20918 +#ifdef CONFIG_IPV6
20919 +
20920 +int do_add_v6_addr(struct nx_info *nxi,
20921 +       struct in6_addr *ip, struct in6_addr *mask,
20922 +       uint32_t prefix, uint16_t type, uint16_t flags)
20923 +{
20924 +       struct nx_addr_v6 *nxa = &nxi->v6;
20925 +
20926 +       if (NX_IPV6(nxi)) {
20927 +               /* locate last entry */
20928 +               for (; nxa->next; nxa = nxa->next);
20929 +               nxa->next = __alloc_nx_addr_v6();
20930 +               nxa = nxa->next;
20931 +
20932 +               if (IS_ERR(nxa))
20933 +                       return PTR_ERR(nxa);
20934 +       }
20935 +
20936 +       nxa->ip = *ip;
20937 +       nxa->mask = *mask;
20938 +       nxa->prefix = prefix;
20939 +       nxa->type = type;
20940 +       nxa->flags = flags;
20941 +       return 0;
20942 +}
20943 +
20944 +
20945 +int vc_net_add_ipv6(struct nx_info *nxi, void __user *data)
20946 +{
20947 +       struct vcmd_net_addr_ipv6_v1 vc_data;
20948 +
20949 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20950 +               return -EFAULT;
20951 +
20952 +       switch (vc_data.type) {
20953 +       case NXA_TYPE_ADDR:
20954 +               memset(&vc_data.mask, ~0, sizeof(vc_data.mask));
20955 +               /* fallthrough */
20956 +       case NXA_TYPE_MASK:
20957 +               return do_add_v6_addr(nxi, &vc_data.ip, &vc_data.mask,
20958 +                       vc_data.prefix, vc_data.type, vc_data.flags);
20959 +       default:
20960 +               return -EINVAL;
20961 +       }
20962 +       return 0;
20963 +}
20964 +
20965 +int vc_net_remove_ipv6(struct nx_info *nxi, void __user *data)
20966 +{
20967 +       struct vcmd_net_addr_ipv6_v1 vc_data;
20968 +
20969 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20970 +               return -EFAULT;
20971 +
20972 +       switch (vc_data.type) {
20973 +       case NXA_TYPE_ANY:
20974 +               __dealloc_nx_addr_v6_all(xchg(&nxi->v6.next, NULL));
20975 +               memset(&nxi->v6, 0, sizeof(nxi->v6));
20976 +               break;
20977 +
20978 +       default:
20979 +               return -EINVAL;
20980 +       }
20981 +       return 0;
20982 +}
20983 +
20984 +#endif /* CONFIG_IPV6 */
20985 +
20986 +
20987 +int vc_get_nflags(struct nx_info *nxi, void __user *data)
20988 +{
20989 +       struct vcmd_net_flags_v0 vc_data;
20990 +
20991 +       vc_data.flagword = nxi->nx_flags;
20992 +
20993 +       /* special STATE flag handling */
20994 +       vc_data.mask = vs_mask_flags(~0ULL, nxi->nx_flags, NXF_ONE_TIME);
20995 +
20996 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20997 +               return -EFAULT;
20998 +       return 0;
20999 +}
21000 +
21001 +int vc_set_nflags(struct nx_info *nxi, void __user *data)
21002 +{
21003 +       struct vcmd_net_flags_v0 vc_data;
21004 +       uint64_t mask, trigger;
21005 +
21006 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21007 +               return -EFAULT;
21008 +
21009 +       /* special STATE flag handling */
21010 +       mask = vs_mask_mask(vc_data.mask, nxi->nx_flags, NXF_ONE_TIME);
21011 +       trigger = (mask & nxi->nx_flags) ^ (mask & vc_data.flagword);
21012 +
21013 +       nxi->nx_flags = vs_mask_flags(nxi->nx_flags,
21014 +               vc_data.flagword, mask);
21015 +       if (trigger & NXF_PERSISTENT)
21016 +               nx_update_persistent(nxi);
21017 +
21018 +       return 0;
21019 +}
21020 +
21021 +int vc_get_ncaps(struct nx_info *nxi, void __user *data)
21022 +{
21023 +       struct vcmd_net_caps_v0 vc_data;
21024 +
21025 +       vc_data.ncaps = nxi->nx_ncaps;
21026 +       vc_data.cmask = ~0ULL;
21027 +
21028 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21029 +               return -EFAULT;
21030 +       return 0;
21031 +}
21032 +
21033 +int vc_set_ncaps(struct nx_info *nxi, void __user *data)
21034 +{
21035 +       struct vcmd_net_caps_v0 vc_data;
21036 +
21037 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21038 +               return -EFAULT;
21039 +
21040 +       nxi->nx_ncaps = vs_mask_flags(nxi->nx_ncaps,
21041 +               vc_data.ncaps, vc_data.cmask);
21042 +       return 0;
21043 +}
21044 +
21045 +
21046 +#include <linux/module.h>
21047 +
21048 +module_init(init_network);
21049 +
21050 +EXPORT_SYMBOL_GPL(free_nx_info);
21051 +EXPORT_SYMBOL_GPL(unhash_nx_info);
21052 +
21053 diff -NurpP --minimal linux-3.6.10/kernel/vserver/proc.c linux-3.6.10-vs2.3.4.5/kernel/vserver/proc.c
21054 --- linux-3.6.10/kernel/vserver/proc.c  1970-01-01 01:00:00.000000000 +0100
21055 +++ linux-3.6.10-vs2.3.4.5/kernel/vserver/proc.c        2012-10-09 14:19:59.000000000 +0200
21056 @@ -0,0 +1,1110 @@
21057 +/*
21058 + *  linux/kernel/vserver/proc.c
21059 + *
21060 + *  Virtual Context Support
21061 + *
21062 + *  Copyright (C) 2003-2011  Herbert Pötzl
21063 + *
21064 + *  V0.01  basic structure
21065 + *  V0.02  adaptation vs1.3.0
21066 + *  V0.03  proc permissions
21067 + *  V0.04  locking/generic
21068 + *  V0.05  next generation procfs
21069 + *  V0.06  inode validation
21070 + *  V0.07  generic rewrite vid
21071 + *  V0.08  remove inode type
21072 + *  V0.09  added u/wmask info
21073 + *
21074 + */
21075 +
21076 +#include <linux/proc_fs.h>
21077 +#include <linux/fs_struct.h>
21078 +#include <linux/mount.h>
21079 +#include <linux/namei.h>
21080 +#include <asm/unistd.h>
21081 +
21082 +#include <linux/vs_context.h>
21083 +#include <linux/vs_network.h>
21084 +#include <linux/vs_cvirt.h>
21085 +
21086 +#include <linux/in.h>
21087 +#include <linux/inetdevice.h>
21088 +#include <linux/vs_inet.h>
21089 +#include <linux/vs_inet6.h>
21090 +
21091 +#include <linux/vserver/global.h>
21092 +
21093 +#include "cvirt_proc.h"
21094 +#include "cacct_proc.h"
21095 +#include "limit_proc.h"
21096 +#include "sched_proc.h"
21097 +#include "vci_config.h"
21098 +
21099 +
21100 +static inline char *print_cap_t(char *buffer, kernel_cap_t *c)
21101 +{
21102 +       unsigned __capi;
21103 +
21104 +       CAP_FOR_EACH_U32(__capi) {
21105 +               buffer += sprintf(buffer, "%08x",
21106 +                       c->cap[(_KERNEL_CAPABILITY_U32S-1) - __capi]);
21107 +       }
21108 +       return buffer;
21109 +}
21110 +
21111 +
21112 +static struct proc_dir_entry *proc_virtual;
21113 +
21114 +static struct proc_dir_entry *proc_virtnet;
21115 +
21116 +
21117 +/* first the actual feeds */
21118 +
21119 +
21120 +static int proc_vci(char *buffer)
21121 +{
21122 +       return sprintf(buffer,
21123 +               "VCIVersion:\t%04x:%04x\n"
21124 +               "VCISyscall:\t%d\n"
21125 +               "VCIKernel:\t%08x\n",
21126 +               VCI_VERSION >> 16,
21127 +               VCI_VERSION & 0xFFFF,
21128 +               __NR_vserver,
21129 +               vci_kernel_config());
21130 +}
21131 +
21132 +static int proc_virtual_info(char *buffer)
21133 +{
21134 +       return proc_vci(buffer);
21135 +}
21136 +
21137 +static int proc_virtual_status(char *buffer)
21138 +{
21139 +       return sprintf(buffer,
21140 +               "#CTotal:\t%d\n"
21141 +               "#CActive:\t%d\n"
21142 +               "#NSProxy:\t%d\t%d %d %d %d %d %d\n"
21143 +               "#InitTask:\t%d\t%d %d\n",
21144 +               atomic_read(&vx_global_ctotal),
21145 +               atomic_read(&vx_global_cactive),
21146 +               atomic_read(&vs_global_nsproxy),
21147 +               atomic_read(&vs_global_fs),
21148 +               atomic_read(&vs_global_mnt_ns),
21149 +               atomic_read(&vs_global_uts_ns),
21150 +               atomic_read(&nr_ipc_ns),
21151 +               atomic_read(&vs_global_user_ns),
21152 +               atomic_read(&vs_global_pid_ns),
21153 +               atomic_read(&init_task.usage),
21154 +               atomic_read(&init_task.nsproxy->count),
21155 +               init_task.fs->users);
21156 +}
21157 +
21158 +
21159 +int proc_vxi_info(struct vx_info *vxi, char *buffer)
21160 +{
21161 +       int length;
21162 +
21163 +       length = sprintf(buffer,
21164 +               "ID:\t%d\n"
21165 +               "Info:\t%p\n"
21166 +               "Init:\t%d\n"
21167 +               "OOM:\t%lld\n",
21168 +               vxi->vx_id,
21169 +               vxi,
21170 +               vxi->vx_initpid,
21171 +               vxi->vx_badness_bias);
21172 +       return length;
21173 +}
21174 +
21175 +int proc_vxi_status(struct vx_info *vxi, char *buffer)
21176 +{
21177 +       char *orig = buffer;
21178 +
21179 +       buffer += sprintf(buffer,
21180 +               "UseCnt:\t%d\n"
21181 +               "Tasks:\t%d\n"
21182 +               "Flags:\t%016llx\n",
21183 +               atomic_read(&vxi->vx_usecnt),
21184 +               atomic_read(&vxi->vx_tasks),
21185 +               (unsigned long long)vxi->vx_flags);
21186 +
21187 +       buffer += sprintf(buffer, "BCaps:\t");
21188 +       buffer = print_cap_t(buffer, &vxi->vx_bcaps);
21189 +       buffer += sprintf(buffer, "\n");
21190 +
21191 +       buffer += sprintf(buffer,
21192 +               "CCaps:\t%016llx\n"
21193 +               "Umask:\t%16llx\n"
21194 +               "Wmask:\t%16llx\n"
21195 +               "Spaces:\t%08lx %08lx\n",
21196 +               (unsigned long long)vxi->vx_ccaps,
21197 +               (unsigned long long)vxi->vx_umask,
21198 +               (unsigned long long)vxi->vx_wmask,
21199 +               vxi->space[0].vx_nsmask, vxi->space[1].vx_nsmask);
21200 +       return buffer - orig;
21201 +}
21202 +
21203 +int proc_vxi_limit(struct vx_info *vxi, char *buffer)
21204 +{
21205 +       return vx_info_proc_limit(&vxi->limit, buffer);
21206 +}
21207 +
21208 +int proc_vxi_sched(struct vx_info *vxi, char *buffer)
21209 +{
21210 +       int cpu, length;
21211 +
21212 +       length = vx_info_proc_sched(&vxi->sched, buffer);
21213 +       for_each_online_cpu(cpu) {
21214 +               length += vx_info_proc_sched_pc(
21215 +                       &vx_per_cpu(vxi, sched_pc, cpu),
21216 +                       buffer + length, cpu);
21217 +       }
21218 +       return length;
21219 +}
21220 +
21221 +int proc_vxi_nsproxy0(struct vx_info *vxi, char *buffer)
21222 +{
21223 +       return vx_info_proc_nsproxy(vxi->space[0].vx_nsproxy, buffer);
21224 +}
21225 +
21226 +int proc_vxi_nsproxy1(struct vx_info *vxi, char *buffer)
21227 +{
21228 +       return vx_info_proc_nsproxy(vxi->space[1].vx_nsproxy, buffer);
21229 +}
21230 +
21231 +int proc_vxi_cvirt(struct vx_info *vxi, char *buffer)
21232 +{
21233 +       int cpu, length;
21234 +
21235 +       vx_update_load(vxi);
21236 +       length = vx_info_proc_cvirt(&vxi->cvirt, buffer);
21237 +       for_each_online_cpu(cpu) {
21238 +               length += vx_info_proc_cvirt_pc(
21239 +                       &vx_per_cpu(vxi, cvirt_pc, cpu),
21240 +                       buffer + length, cpu);
21241 +       }
21242 +       return length;
21243 +}
21244 +
21245 +int proc_vxi_cacct(struct vx_info *vxi, char *buffer)
21246 +{
21247 +       return vx_info_proc_cacct(&vxi->cacct, buffer);
21248 +}
21249 +
21250 +
21251 +static int proc_virtnet_info(char *buffer)
21252 +{
21253 +       return proc_vci(buffer);
21254 +}
21255 +
21256 +static int proc_virtnet_status(char *buffer)
21257 +{
21258 +       return sprintf(buffer,
21259 +               "#CTotal:\t%d\n"
21260 +               "#CActive:\t%d\n",
21261 +               atomic_read(&nx_global_ctotal),
21262 +               atomic_read(&nx_global_cactive));
21263 +}
21264 +
21265 +int proc_nxi_info(struct nx_info *nxi, char *buffer)
21266 +{
21267 +       struct nx_addr_v4 *v4a;
21268 +#ifdef CONFIG_IPV6
21269 +       struct nx_addr_v6 *v6a;
21270 +#endif
21271 +       int length, i;
21272 +
21273 +       length = sprintf(buffer,
21274 +               "ID:\t%d\n"
21275 +               "Info:\t%p\n"
21276 +               "Bcast:\t" NIPQUAD_FMT "\n"
21277 +               "Lback:\t" NIPQUAD_FMT "\n",
21278 +               nxi->nx_id,
21279 +               nxi,
21280 +               NIPQUAD(nxi->v4_bcast.s_addr),
21281 +               NIPQUAD(nxi->v4_lback.s_addr));
21282 +
21283 +       if (!NX_IPV4(nxi))
21284 +               goto skip_v4;
21285 +       for (i = 0, v4a = &nxi->v4; v4a; i++, v4a = v4a->next)
21286 +               length += sprintf(buffer + length, "%d:\t" NXAV4_FMT "\n",
21287 +                       i, NXAV4(v4a));
21288 +skip_v4:
21289 +#ifdef CONFIG_IPV6
21290 +       if (!NX_IPV6(nxi))
21291 +               goto skip_v6;
21292 +       for (i = 0, v6a = &nxi->v6; v6a; i++, v6a = v6a->next)
21293 +               length += sprintf(buffer + length, "%d:\t" NXAV6_FMT "\n",
21294 +                       i, NXAV6(v6a));
21295 +skip_v6:
21296 +#endif
21297 +       return length;
21298 +}
21299 +
21300 +int proc_nxi_status(struct nx_info *nxi, char *buffer)
21301 +{
21302 +       int length;
21303 +
21304 +       length = sprintf(buffer,
21305 +               "UseCnt:\t%d\n"
21306 +               "Tasks:\t%d\n"
21307 +               "Flags:\t%016llx\n"
21308 +               "NCaps:\t%016llx\n",
21309 +               atomic_read(&nxi->nx_usecnt),
21310 +               atomic_read(&nxi->nx_tasks),
21311 +               (unsigned long long)nxi->nx_flags,
21312 +               (unsigned long long)nxi->nx_ncaps);
21313 +       return length;
21314 +}
21315 +
21316 +
21317 +
21318 +/* here the inode helpers */
21319 +
21320 +struct vs_entry {
21321 +       int len;
21322 +       char *name;
21323 +       mode_t mode;
21324 +       struct inode_operations *iop;
21325 +       struct file_operations *fop;
21326 +       union proc_op op;
21327 +};
21328 +
21329 +static struct inode *vs_proc_make_inode(struct super_block *sb, struct vs_entry *p)
21330 +{
21331 +       struct inode *inode = new_inode(sb);
21332 +
21333 +       if (!inode)
21334 +               goto out;
21335 +
21336 +       inode->i_mode = p->mode;
21337 +       if (p->iop)
21338 +               inode->i_op = p->iop;
21339 +       if (p->fop)
21340 +               inode->i_fop = p->fop;
21341 +
21342 +       set_nlink(inode, (p->mode & S_IFDIR) ? 2 : 1);
21343 +       inode->i_flags |= S_IMMUTABLE;
21344 +
21345 +       inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
21346 +
21347 +       inode->i_uid = 0;
21348 +       inode->i_gid = 0;
21349 +       inode->i_tag = 0;
21350 +out:
21351 +       return inode;
21352 +}
21353 +
21354 +static struct dentry *vs_proc_instantiate(struct inode *dir,
21355 +       struct dentry *dentry, int id, void *ptr)
21356 +{
21357 +       struct vs_entry *p = ptr;
21358 +       struct inode *inode = vs_proc_make_inode(dir->i_sb, p);
21359 +       struct dentry *error = ERR_PTR(-EINVAL);
21360 +
21361 +       if (!inode)
21362 +               goto out;
21363 +
21364 +       PROC_I(inode)->op = p->op;
21365 +       PROC_I(inode)->fd = id;
21366 +       d_add(dentry, inode);
21367 +       error = NULL;
21368 +out:
21369 +       return error;
21370 +}
21371 +
21372 +/* Lookups */
21373 +
21374 +typedef struct dentry *instantiate_t(struct inode *, struct dentry *, int, void *);
21375 +
21376 +/*
21377 + * Fill a directory entry.
21378 + *
21379 + * If possible create the dcache entry and derive our inode number and
21380 + * file type from dcache entry.
21381 + *
21382 + * Since all of the proc inode numbers are dynamically generated, the inode
21383 + * numbers do not exist until the inode is cache.  This means creating the
21384 + * the dcache entry in readdir is necessary to keep the inode numbers
21385 + * reported by readdir in sync with the inode numbers reported
21386 + * by stat.
21387 + */
21388 +static int proc_fill_cache(struct file *filp, void *dirent, filldir_t filldir,
21389 +       char *name, int len, instantiate_t instantiate, int id, void *ptr)
21390 +{
21391 +       struct dentry *child, *dir = filp->f_dentry;
21392 +       struct inode *inode;
21393 +       struct qstr qname;
21394 +       ino_t ino = 0;
21395 +       unsigned type = DT_UNKNOWN;
21396 +
21397 +       qname.name = name;
21398 +       qname.len  = len;
21399 +       qname.hash = full_name_hash(name, len);
21400 +
21401 +       child = d_lookup(dir, &qname);
21402 +       if (!child) {
21403 +               struct dentry *new;
21404 +               new = d_alloc(dir, &qname);
21405 +               if (new) {
21406 +                       child = instantiate(dir->d_inode, new, id, ptr);
21407 +                       if (child)
21408 +                               dput(new);
21409 +                       else
21410 +                               child = new;
21411 +               }
21412 +       }
21413 +       if (!child || IS_ERR(child) || !child->d_inode)
21414 +               goto end_instantiate;
21415 +       inode = child->d_inode;
21416 +       if (inode) {
21417 +               ino = inode->i_ino;
21418 +               type = inode->i_mode >> 12;
21419 +       }
21420 +       dput(child);
21421 +end_instantiate:
21422 +       if (!ino)
21423 +               ino = find_inode_number(dir, &qname);
21424 +       if (!ino)
21425 +               ino = 1;
21426 +       return filldir(dirent, name, len, filp->f_pos, ino, type);
21427 +}
21428 +
21429 +
21430 +
21431 +/* get and revalidate vx_info/xid */
21432 +
21433 +static inline
21434 +struct vx_info *get_proc_vx_info(struct inode *inode)
21435 +{
21436 +       return lookup_vx_info(PROC_I(inode)->fd);
21437 +}
21438 +
21439 +static int proc_xid_revalidate(struct dentry *dentry, unsigned int flags)
21440 +{
21441 +       struct inode *inode = dentry->d_inode;
21442 +       xid_t xid = PROC_I(inode)->fd;
21443 +
21444 +       if (flags & LOOKUP_RCU) /* FIXME: can be dropped? */
21445 +               return -ECHILD;
21446 +
21447 +       if (!xid || xid_is_hashed(xid))
21448 +               return 1;
21449 +       d_drop(dentry);
21450 +       return 0;
21451 +}
21452 +
21453 +
21454 +/* get and revalidate nx_info/nid */
21455 +
21456 +static int proc_nid_revalidate(struct dentry *dentry, unsigned int flags)
21457 +{
21458 +       struct inode *inode = dentry->d_inode;
21459 +       nid_t nid = PROC_I(inode)->fd;
21460 +
21461 +       if (flags & LOOKUP_RCU) /* FIXME: can be dropped? */
21462 +               return -ECHILD;
21463 +
21464 +       if (!nid || nid_is_hashed(nid))
21465 +               return 1;
21466 +       d_drop(dentry);
21467 +       return 0;
21468 +}
21469 +
21470 +
21471 +
21472 +#define PROC_BLOCK_SIZE (PAGE_SIZE - 1024)
21473 +
21474 +static ssize_t proc_vs_info_read(struct file *file, char __user *buf,
21475 +                         size_t count, loff_t *ppos)
21476 +{
21477 +       struct inode *inode = file->f_dentry->d_inode;
21478 +       unsigned long page;
21479 +       ssize_t length = 0;
21480 +
21481 +       if (count > PROC_BLOCK_SIZE)
21482 +               count = PROC_BLOCK_SIZE;
21483 +
21484 +       /* fade that out as soon as stable */
21485 +       WARN_ON(PROC_I(inode)->fd);
21486 +
21487 +       if (!(page = __get_free_page(GFP_KERNEL)))
21488 +               return -ENOMEM;
21489 +
21490 +       BUG_ON(!PROC_I(inode)->op.proc_vs_read);
21491 +       length = PROC_I(inode)->op.proc_vs_read((char *)page);
21492 +
21493 +       if (length >= 0)
21494 +               length = simple_read_from_buffer(buf, count, ppos,
21495 +                       (char *)page, length);
21496 +
21497 +       free_page(page);
21498 +       return length;
21499 +}
21500 +
21501 +static ssize_t proc_vx_info_read(struct file *file, char __user *buf,
21502 +                         size_t count, loff_t *ppos)
21503 +{
21504 +       struct inode *inode = file->f_dentry->d_inode;
21505 +       struct vx_info *vxi = NULL;
21506 +       xid_t xid = PROC_I(inode)->fd;
21507 +       unsigned long page;
21508 +       ssize_t length = 0;
21509 +
21510 +       if (count > PROC_BLOCK_SIZE)
21511 +               count = PROC_BLOCK_SIZE;
21512 +
21513 +       /* fade that out as soon as stable */
21514 +       WARN_ON(!xid);
21515 +       vxi = lookup_vx_info(xid);
21516 +       if (!vxi)
21517 +               goto out;
21518 +
21519 +       length = -ENOMEM;
21520 +       if (!(page = __get_free_page(GFP_KERNEL)))
21521 +               goto out_put;
21522 +
21523 +       BUG_ON(!PROC_I(inode)->op.proc_vxi_read);
21524 +       length = PROC_I(inode)->op.proc_vxi_read(vxi, (char *)page);
21525 +
21526 +       if (length >= 0)
21527 +               length = simple_read_from_buffer(buf, count, ppos,
21528 +                       (char *)page, length);
21529 +
21530 +       free_page(page);
21531 +out_put:
21532 +       put_vx_info(vxi);
21533 +out:
21534 +       return length;
21535 +}
21536 +
21537 +static ssize_t proc_nx_info_read(struct file *file, char __user *buf,
21538 +                         size_t count, loff_t *ppos)
21539 +{
21540 +       struct inode *inode = file->f_dentry->d_inode;
21541 +       struct nx_info *nxi = NULL;
21542 +       nid_t nid = PROC_I(inode)->fd;
21543 +       unsigned long page;
21544 +       ssize_t length = 0;
21545 +
21546 +       if (count > PROC_BLOCK_SIZE)
21547 +               count = PROC_BLOCK_SIZE;
21548 +
21549 +       /* fade that out as soon as stable */
21550 +       WARN_ON(!nid);
21551 +       nxi = lookup_nx_info(nid);
21552 +       if (!nxi)
21553 +               goto out;
21554 +
21555 +       length = -ENOMEM;
21556 +       if (!(page = __get_free_page(GFP_KERNEL)))
21557 +               goto out_put;
21558 +
21559 +       BUG_ON(!PROC_I(inode)->op.proc_nxi_read);
21560 +       length = PROC_I(inode)->op.proc_nxi_read(nxi, (char *)page);
21561 +
21562 +       if (length >= 0)
21563 +               length = simple_read_from_buffer(buf, count, ppos,
21564 +                       (char *)page, length);
21565 +
21566 +       free_page(page);
21567 +out_put:
21568 +       put_nx_info(nxi);
21569 +out:
21570 +       return length;
21571 +}
21572 +
21573 +
21574 +
21575 +/* here comes the lower level */
21576 +
21577 +
21578 +#define NOD(NAME, MODE, IOP, FOP, OP) {        \
21579 +       .len  = sizeof(NAME) - 1,       \
21580 +       .name = (NAME),                 \
21581 +       .mode = MODE,                   \
21582 +       .iop  = IOP,                    \
21583 +       .fop  = FOP,                    \
21584 +       .op   = OP,                     \
21585 +}
21586 +
21587 +
21588 +#define DIR(NAME, MODE, OTYPE)                         \
21589 +       NOD(NAME, (S_IFDIR | (MODE)),                   \
21590 +               &proc_ ## OTYPE ## _inode_operations,   \
21591 +               &proc_ ## OTYPE ## _file_operations, { } )
21592 +
21593 +#define INF(NAME, MODE, OTYPE)                         \
21594 +       NOD(NAME, (S_IFREG | (MODE)), NULL,             \
21595 +               &proc_vs_info_file_operations,          \
21596 +               { .proc_vs_read = &proc_##OTYPE } )
21597 +
21598 +#define VINF(NAME, MODE, OTYPE)                                \
21599 +       NOD(NAME, (S_IFREG | (MODE)), NULL,             \
21600 +               &proc_vx_info_file_operations,          \
21601 +               { .proc_vxi_read = &proc_##OTYPE } )
21602 +
21603 +#define NINF(NAME, MODE, OTYPE)                                \
21604 +       NOD(NAME, (S_IFREG | (MODE)), NULL,             \
21605 +               &proc_nx_info_file_operations,          \
21606 +               { .proc_nxi_read = &proc_##OTYPE } )
21607 +
21608 +
21609 +static struct file_operations proc_vs_info_file_operations = {
21610 +       .read =         proc_vs_info_read,
21611 +};
21612 +
21613 +static struct file_operations proc_vx_info_file_operations = {
21614 +       .read =         proc_vx_info_read,
21615 +};
21616 +
21617 +static struct dentry_operations proc_xid_dentry_operations = {
21618 +       .d_revalidate = proc_xid_revalidate,
21619 +};
21620 +
21621 +static struct vs_entry vx_base_stuff[] = {
21622 +       VINF("info",    S_IRUGO, vxi_info),
21623 +       VINF("status",  S_IRUGO, vxi_status),
21624 +       VINF("limit",   S_IRUGO, vxi_limit),
21625 +       VINF("sched",   S_IRUGO, vxi_sched),
21626 +       VINF("nsproxy", S_IRUGO, vxi_nsproxy0),
21627 +       VINF("nsproxy1",S_IRUGO, vxi_nsproxy1),
21628 +       VINF("cvirt",   S_IRUGO, vxi_cvirt),
21629 +       VINF("cacct",   S_IRUGO, vxi_cacct),
21630 +       {}
21631 +};
21632 +
21633 +
21634 +
21635 +
21636 +static struct dentry *proc_xid_instantiate(struct inode *dir,
21637 +       struct dentry *dentry, int id, void *ptr)
21638 +{
21639 +       dentry->d_op = &proc_xid_dentry_operations;
21640 +       return vs_proc_instantiate(dir, dentry, id, ptr);
21641 +}
21642 +
21643 +static struct dentry *proc_xid_lookup(struct inode *dir,
21644 +       struct dentry *dentry, unsigned int flags)
21645 +{
21646 +       struct vs_entry *p = vx_base_stuff;
21647 +       struct dentry *error = ERR_PTR(-ENOENT);
21648 +
21649 +       for (; p->name; p++) {
21650 +               if (p->len != dentry->d_name.len)
21651 +                       continue;
21652 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
21653 +                       break;
21654 +       }
21655 +       if (!p->name)
21656 +               goto out;
21657 +
21658 +       error = proc_xid_instantiate(dir, dentry, PROC_I(dir)->fd, p);
21659 +out:
21660 +       return error;
21661 +}
21662 +
21663 +static int proc_xid_readdir(struct file *filp,
21664 +       void *dirent, filldir_t filldir)
21665 +{
21666 +       struct dentry *dentry = filp->f_dentry;
21667 +       struct inode *inode = dentry->d_inode;
21668 +       struct vs_entry *p = vx_base_stuff;
21669 +       int size = sizeof(vx_base_stuff) / sizeof(struct vs_entry);
21670 +       int pos, index;
21671 +       u64 ino;
21672 +
21673 +       pos = filp->f_pos;
21674 +       switch (pos) {
21675 +       case 0:
21676 +               ino = inode->i_ino;
21677 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
21678 +                       goto out;
21679 +               pos++;
21680 +               /* fall through */
21681 +       case 1:
21682 +               ino = parent_ino(dentry);
21683 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
21684 +                       goto out;
21685 +               pos++;
21686 +               /* fall through */
21687 +       default:
21688 +               index = pos - 2;
21689 +               if (index >= size)
21690 +                       goto out;
21691 +               for (p += index; p->name; p++) {
21692 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
21693 +                               vs_proc_instantiate, PROC_I(inode)->fd, p))
21694 +                               goto out;
21695 +                       pos++;
21696 +               }
21697 +       }
21698 +out:
21699 +       filp->f_pos = pos;
21700 +       return 1;
21701 +}
21702 +
21703 +
21704 +
21705 +static struct file_operations proc_nx_info_file_operations = {
21706 +       .read =         proc_nx_info_read,
21707 +};
21708 +
21709 +static struct dentry_operations proc_nid_dentry_operations = {
21710 +       .d_revalidate = proc_nid_revalidate,
21711 +};
21712 +
21713 +static struct vs_entry nx_base_stuff[] = {
21714 +       NINF("info",    S_IRUGO, nxi_info),
21715 +       NINF("status",  S_IRUGO, nxi_status),
21716 +       {}
21717 +};
21718 +
21719 +
21720 +static struct dentry *proc_nid_instantiate(struct inode *dir,
21721 +       struct dentry *dentry, int id, void *ptr)
21722 +{
21723 +       dentry->d_op = &proc_nid_dentry_operations;
21724 +       return vs_proc_instantiate(dir, dentry, id, ptr);
21725 +}
21726 +
21727 +static struct dentry *proc_nid_lookup(struct inode *dir,
21728 +       struct dentry *dentry, unsigned int flags)
21729 +{
21730 +       struct vs_entry *p = nx_base_stuff;
21731 +       struct dentry *error = ERR_PTR(-ENOENT);
21732 +
21733 +       for (; p->name; p++) {
21734 +               if (p->len != dentry->d_name.len)
21735 +                       continue;
21736 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
21737 +                       break;
21738 +       }
21739 +       if (!p->name)
21740 +               goto out;
21741 +
21742 +       error = proc_nid_instantiate(dir, dentry, PROC_I(dir)->fd, p);
21743 +out:
21744 +       return error;
21745 +}
21746 +
21747 +static int proc_nid_readdir(struct file *filp,
21748 +       void *dirent, filldir_t filldir)
21749 +{
21750 +       struct dentry *dentry = filp->f_dentry;
21751 +       struct inode *inode = dentry->d_inode;
21752 +       struct vs_entry *p = nx_base_stuff;
21753 +       int size = sizeof(nx_base_stuff) / sizeof(struct vs_entry);
21754 +       int pos, index;
21755 +       u64 ino;
21756 +
21757 +       pos = filp->f_pos;
21758 +       switch (pos) {
21759 +       case 0:
21760 +               ino = inode->i_ino;
21761 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
21762 +                       goto out;
21763 +               pos++;
21764 +               /* fall through */
21765 +       case 1:
21766 +               ino = parent_ino(dentry);
21767 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
21768 +                       goto out;
21769 +               pos++;
21770 +               /* fall through */
21771 +       default:
21772 +               index = pos - 2;
21773 +               if (index >= size)
21774 +                       goto out;
21775 +               for (p += index; p->name; p++) {
21776 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
21777 +                               vs_proc_instantiate, PROC_I(inode)->fd, p))
21778 +                               goto out;
21779 +                       pos++;
21780 +               }
21781 +       }
21782 +out:
21783 +       filp->f_pos = pos;
21784 +       return 1;
21785 +}
21786 +
21787 +
21788 +#define MAX_MULBY10    ((~0U - 9) / 10)
21789 +
21790 +static inline int atovid(const char *str, int len)
21791 +{
21792 +       int vid, c;
21793 +
21794 +       vid = 0;
21795 +       while (len-- > 0) {
21796 +               c = *str - '0';
21797 +               str++;
21798 +               if (c > 9)
21799 +                       return -1;
21800 +               if (vid >= MAX_MULBY10)
21801 +                       return -1;
21802 +               vid *= 10;
21803 +               vid += c;
21804 +               if (!vid)
21805 +                       return -1;
21806 +       }
21807 +       return vid;
21808 +}
21809 +
21810 +/* now the upper level (virtual) */
21811 +
21812 +
21813 +static struct file_operations proc_xid_file_operations = {
21814 +       .read =         generic_read_dir,
21815 +       .readdir =      proc_xid_readdir,
21816 +};
21817 +
21818 +static struct inode_operations proc_xid_inode_operations = {
21819 +       .lookup =       proc_xid_lookup,
21820 +};
21821 +
21822 +static struct vs_entry vx_virtual_stuff[] = {
21823 +       INF("info",     S_IRUGO, virtual_info),
21824 +       INF("status",   S_IRUGO, virtual_status),
21825 +       DIR(NULL,       S_IRUGO | S_IXUGO, xid),
21826 +};
21827 +
21828 +
21829 +static struct dentry *proc_virtual_lookup(struct inode *dir,
21830 +       struct dentry *dentry, unsigned int flags)
21831 +{
21832 +       struct vs_entry *p = vx_virtual_stuff;
21833 +       struct dentry *error = ERR_PTR(-ENOENT);
21834 +       int id = 0;
21835 +
21836 +       for (; p->name; p++) {
21837 +               if (p->len != dentry->d_name.len)
21838 +                       continue;
21839 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
21840 +                       break;
21841 +       }
21842 +       if (p->name)
21843 +               goto instantiate;
21844 +
21845 +       id = atovid(dentry->d_name.name, dentry->d_name.len);
21846 +       if ((id < 0) || !xid_is_hashed(id))
21847 +               goto out;
21848 +
21849 +instantiate:
21850 +       error = proc_xid_instantiate(dir, dentry, id, p);
21851 +out:
21852 +       return error;
21853 +}
21854 +
21855 +static struct file_operations proc_nid_file_operations = {
21856 +       .read =         generic_read_dir,
21857 +       .readdir =      proc_nid_readdir,
21858 +};
21859 +
21860 +static struct inode_operations proc_nid_inode_operations = {
21861 +       .lookup =       proc_nid_lookup,
21862 +};
21863 +
21864 +static struct vs_entry nx_virtnet_stuff[] = {
21865 +       INF("info",     S_IRUGO, virtnet_info),
21866 +       INF("status",   S_IRUGO, virtnet_status),
21867 +       DIR(NULL,       S_IRUGO | S_IXUGO, nid),
21868 +};
21869 +
21870 +
21871 +static struct dentry *proc_virtnet_lookup(struct inode *dir,
21872 +       struct dentry *dentry, unsigned int flags)
21873 +{
21874 +       struct vs_entry *p = nx_virtnet_stuff;
21875 +       struct dentry *error = ERR_PTR(-ENOENT);
21876 +       int id = 0;
21877 +
21878 +       for (; p->name; p++) {
21879 +               if (p->len != dentry->d_name.len)
21880 +                       continue;
21881 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
21882 +                       break;
21883 +       }
21884 +       if (p->name)
21885 +               goto instantiate;
21886 +
21887 +       id = atovid(dentry->d_name.name, dentry->d_name.len);
21888 +       if ((id < 0) || !nid_is_hashed(id))
21889 +               goto out;
21890 +
21891 +instantiate:
21892 +       error = proc_nid_instantiate(dir, dentry, id, p);
21893 +out:
21894 +       return error;
21895 +}
21896 +
21897 +
21898 +#define PROC_MAXVIDS 32
21899 +
21900 +int proc_virtual_readdir(struct file *filp,
21901 +       void *dirent, filldir_t filldir)
21902 +{
21903 +       struct dentry *dentry = filp->f_dentry;
21904 +       struct inode *inode = dentry->d_inode;
21905 +       struct vs_entry *p = vx_virtual_stuff;
21906 +       int size = sizeof(vx_virtual_stuff) / sizeof(struct vs_entry);
21907 +       int pos, index;
21908 +       unsigned int xid_array[PROC_MAXVIDS];
21909 +       char buf[PROC_NUMBUF];
21910 +       unsigned int nr_xids, i;
21911 +       u64 ino;
21912 +
21913 +       pos = filp->f_pos;
21914 +       switch (pos) {
21915 +       case 0:
21916 +               ino = inode->i_ino;
21917 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
21918 +                       goto out;
21919 +               pos++;
21920 +               /* fall through */
21921 +       case 1:
21922 +               ino = parent_ino(dentry);
21923 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
21924 +                       goto out;
21925 +               pos++;
21926 +               /* fall through */
21927 +       default:
21928 +               index = pos - 2;
21929 +               if (index >= size)
21930 +                       goto entries;
21931 +               for (p += index; p->name; p++) {
21932 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
21933 +                               vs_proc_instantiate, 0, p))
21934 +                               goto out;
21935 +                       pos++;
21936 +               }
21937 +       entries:
21938 +               index = pos - size;
21939 +               p = &vx_virtual_stuff[size - 1];
21940 +               nr_xids = get_xid_list(index, xid_array, PROC_MAXVIDS);
21941 +               for (i = 0; i < nr_xids; i++) {
21942 +                       int n, xid = xid_array[i];
21943 +                       unsigned int j = PROC_NUMBUF;
21944 +
21945 +                       n = xid;
21946 +                       do
21947 +                               buf[--j] = '0' + (n % 10);
21948 +                       while (n /= 10);
21949 +
21950 +                       if (proc_fill_cache(filp, dirent, filldir,
21951 +                               buf + j, PROC_NUMBUF - j,
21952 +                               vs_proc_instantiate, xid, p))
21953 +                               goto out;
21954 +                       pos++;
21955 +               }
21956 +       }
21957 +out:
21958 +       filp->f_pos = pos;
21959 +       return 0;
21960 +}
21961 +
21962 +static int proc_virtual_getattr(struct vfsmount *mnt,
21963 +       struct dentry *dentry, struct kstat *stat)
21964 +{
21965 +       struct inode *inode = dentry->d_inode;
21966 +
21967 +       generic_fillattr(inode, stat);
21968 +       stat->nlink = 2 + atomic_read(&vx_global_cactive);
21969 +       return 0;
21970 +}
21971 +
21972 +static struct file_operations proc_virtual_dir_operations = {
21973 +       .read =         generic_read_dir,
21974 +       .readdir =      proc_virtual_readdir,
21975 +};
21976 +
21977 +static struct inode_operations proc_virtual_dir_inode_operations = {
21978 +       .getattr =      proc_virtual_getattr,
21979 +       .lookup =       proc_virtual_lookup,
21980 +};
21981 +
21982 +
21983 +
21984 +
21985 +
21986 +int proc_virtnet_readdir(struct file *filp,
21987 +       void *dirent, filldir_t filldir)
21988 +{
21989 +       struct dentry *dentry = filp->f_dentry;
21990 +       struct inode *inode = dentry->d_inode;
21991 +       struct vs_entry *p = nx_virtnet_stuff;
21992 +       int size = sizeof(nx_virtnet_stuff) / sizeof(struct vs_entry);
21993 +       int pos, index;
21994 +       unsigned int nid_array[PROC_MAXVIDS];
21995 +       char buf[PROC_NUMBUF];
21996 +       unsigned int nr_nids, i;
21997 +       u64 ino;
21998 +
21999 +       pos = filp->f_pos;
22000 +       switch (pos) {
22001 +       case 0:
22002 +               ino = inode->i_ino;
22003 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
22004 +                       goto out;
22005 +               pos++;
22006 +               /* fall through */
22007 +       case 1:
22008 +               ino = parent_ino(dentry);
22009 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
22010 +                       goto out;
22011 +               pos++;
22012 +               /* fall through */
22013 +       default:
22014 +               index = pos - 2;
22015 +               if (index >= size)
22016 +                       goto entries;
22017 +               for (p += index; p->name; p++) {
22018 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
22019 +                               vs_proc_instantiate, 0, p))
22020 +                               goto out;
22021 +                       pos++;
22022 +               }
22023 +       entries:
22024 +               index = pos - size;
22025 +               p = &nx_virtnet_stuff[size - 1];
22026 +               nr_nids = get_nid_list(index, nid_array, PROC_MAXVIDS);
22027 +               for (i = 0; i < nr_nids; i++) {
22028 +                       int n, nid = nid_array[i];
22029 +                       unsigned int j = PROC_NUMBUF;
22030 +
22031 +                       n = nid;
22032 +                       do
22033 +                               buf[--j] = '0' + (n % 10);
22034 +                       while (n /= 10);
22035 +
22036 +                       if (proc_fill_cache(filp, dirent, filldir,
22037 +                               buf + j, PROC_NUMBUF - j,
22038 +                               vs_proc_instantiate, nid, p))
22039 +                               goto out;
22040 +                       pos++;
22041 +               }
22042 +       }
22043 +out:
22044 +       filp->f_pos = pos;
22045 +       return 0;
22046 +}
22047 +
22048 +static int proc_virtnet_getattr(struct vfsmount *mnt,
22049 +       struct dentry *dentry, struct kstat *stat)
22050 +{
22051 +       struct inode *inode = dentry->d_inode;
22052 +
22053 +       generic_fillattr(inode, stat);
22054 +       stat->nlink = 2 + atomic_read(&nx_global_cactive);
22055 +       return 0;
22056 +}
22057 +
22058 +static struct file_operations proc_virtnet_dir_operations = {
22059 +       .read =         generic_read_dir,
22060 +       .readdir =      proc_virtnet_readdir,
22061 +};
22062 +
22063 +static struct inode_operations proc_virtnet_dir_inode_operations = {
22064 +       .getattr =      proc_virtnet_getattr,
22065 +       .lookup =       proc_virtnet_lookup,
22066 +};
22067 +
22068 +
22069 +
22070 +void proc_vx_init(void)
22071 +{
22072 +       struct proc_dir_entry *ent;
22073 +
22074 +       ent = proc_mkdir("virtual", 0);
22075 +       if (ent) {
22076 +               ent->proc_fops = &proc_virtual_dir_operations;
22077 +               ent->proc_iops = &proc_virtual_dir_inode_operations;
22078 +       }
22079 +       proc_virtual = ent;
22080 +
22081 +       ent = proc_mkdir("virtnet", 0);
22082 +       if (ent) {
22083 +               ent->proc_fops = &proc_virtnet_dir_operations;
22084 +               ent->proc_iops = &proc_virtnet_dir_inode_operations;
22085 +       }
22086 +       proc_virtnet = ent;
22087 +}
22088 +
22089 +
22090 +
22091 +
22092 +/* per pid info */
22093 +
22094 +
22095 +int proc_pid_vx_info(struct task_struct *p, char *buffer)
22096 +{
22097 +       struct vx_info *vxi;
22098 +       char *orig = buffer;
22099 +
22100 +       buffer += sprintf(buffer, "XID:\t%d\n", vx_task_xid(p));
22101 +
22102 +       vxi = task_get_vx_info(p);
22103 +       if (!vxi)
22104 +               goto out;
22105 +
22106 +       buffer += sprintf(buffer, "BCaps:\t");
22107 +       buffer = print_cap_t(buffer, &vxi->vx_bcaps);
22108 +       buffer += sprintf(buffer, "\n");
22109 +       buffer += sprintf(buffer, "CCaps:\t%016llx\n",
22110 +               (unsigned long long)vxi->vx_ccaps);
22111 +       buffer += sprintf(buffer, "CFlags:\t%016llx\n",
22112 +               (unsigned long long)vxi->vx_flags);
22113 +       buffer += sprintf(buffer, "CIPid:\t%d\n", vxi->vx_initpid);
22114 +
22115 +       put_vx_info(vxi);
22116 +out:
22117 +       return buffer - orig;
22118 +}
22119 +
22120 +
22121 +int proc_pid_nx_info(struct task_struct *p, char *buffer)
22122 +{
22123 +       struct nx_info *nxi;
22124 +       struct nx_addr_v4 *v4a;
22125 +#ifdef CONFIG_IPV6
22126 +       struct nx_addr_v6 *v6a;
22127 +#endif
22128 +       char *orig = buffer;
22129 +       int i;
22130 +
22131 +       buffer += sprintf(buffer, "NID:\t%d\n", nx_task_nid(p));
22132 +
22133 +       nxi = task_get_nx_info(p);
22134 +       if (!nxi)
22135 +               goto out;
22136 +
22137 +       buffer += sprintf(buffer, "NCaps:\t%016llx\n",
22138 +               (unsigned long long)nxi->nx_ncaps);
22139 +       buffer += sprintf(buffer, "NFlags:\t%016llx\n",
22140 +               (unsigned long long)nxi->nx_flags);
22141 +
22142 +       buffer += sprintf(buffer,
22143 +               "V4Root[bcast]:\t" NIPQUAD_FMT "\n",
22144 +               NIPQUAD(nxi->v4_bcast.s_addr));
22145 +       buffer += sprintf (buffer,
22146 +               "V4Root[lback]:\t" NIPQUAD_FMT "\n",
22147 +               NIPQUAD(nxi->v4_lback.s_addr));
22148 +       if (!NX_IPV4(nxi))
22149 +               goto skip_v4;
22150 +       for (i = 0, v4a = &nxi->v4; v4a; i++, v4a = v4a->next)
22151 +               buffer += sprintf(buffer, "V4Root[%d]:\t" NXAV4_FMT "\n",
22152 +                       i, NXAV4(v4a));
22153 +skip_v4:
22154 +#ifdef CONFIG_IPV6
22155 +       if (!NX_IPV6(nxi))
22156 +               goto skip_v6;
22157 +       for (i = 0, v6a = &nxi->v6; v6a; i++, v6a = v6a->next)
22158 +               buffer += sprintf(buffer, "V6Root[%d]:\t" NXAV6_FMT "\n",
22159 +                       i, NXAV6(v6a));
22160 +skip_v6:
22161 +#endif
22162 +       put_nx_info(nxi);
22163 +out:
22164 +       return buffer - orig;
22165 +}
22166 +
22167 diff -NurpP --minimal linux-3.6.10/kernel/vserver/sched.c linux-3.6.10-vs2.3.4.5/kernel/vserver/sched.c
22168 --- linux-3.6.10/kernel/vserver/sched.c 1970-01-01 01:00:00.000000000 +0100
22169 +++ linux-3.6.10-vs2.3.4.5/kernel/vserver/sched.c       2012-10-04 18:47:00.000000000 +0200
22170 @@ -0,0 +1,83 @@
22171 +/*
22172 + *  linux/kernel/vserver/sched.c
22173 + *
22174 + *  Virtual Server: Scheduler Support
22175 + *
22176 + *  Copyright (C) 2004-2010  Herbert Pötzl
22177 + *
22178 + *  V0.01  adapted Sam Vilains version to 2.6.3
22179 + *  V0.02  removed legacy interface
22180 + *  V0.03  changed vcmds to vxi arg
22181 + *  V0.04  removed older and legacy interfaces
22182 + *  V0.05  removed scheduler code/commands
22183 + *
22184 + */
22185 +
22186 +#include <linux/vs_context.h>
22187 +#include <linux/vs_sched.h>
22188 +#include <linux/cpumask.h>
22189 +#include <linux/vserver/sched_cmd.h>
22190 +
22191 +#include <asm/uaccess.h>
22192 +
22193 +
22194 +void vx_update_sched_param(struct _vx_sched *sched,
22195 +       struct _vx_sched_pc *sched_pc)
22196 +{
22197 +       sched_pc->prio_bias = sched->prio_bias;
22198 +}
22199 +
22200 +static int do_set_prio_bias(struct vx_info *vxi, struct vcmd_prio_bias *data)
22201 +{
22202 +       int cpu;
22203 +
22204 +       if (data->prio_bias > MAX_PRIO_BIAS)
22205 +               data->prio_bias = MAX_PRIO_BIAS;
22206 +       if (data->prio_bias < MIN_PRIO_BIAS)
22207 +               data->prio_bias = MIN_PRIO_BIAS;
22208 +
22209 +       if (data->cpu_id != ~0) {
22210 +               vxi->sched.update = cpumask_of_cpu(data->cpu_id);
22211 +               cpumask_and(&vxi->sched.update, &vxi->sched.update,
22212 +                       cpu_online_mask);
22213 +       } else
22214 +               cpumask_copy(&vxi->sched.update, cpu_online_mask);
22215 +
22216 +       for_each_cpu_mask(cpu, vxi->sched.update)
22217 +               vx_update_sched_param(&vxi->sched,
22218 +                       &vx_per_cpu(vxi, sched_pc, cpu));
22219 +       return 0;
22220 +}
22221 +
22222 +int vc_set_prio_bias(struct vx_info *vxi, void __user *data)
22223 +{
22224 +       struct vcmd_prio_bias vc_data;
22225 +
22226 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
22227 +               return -EFAULT;
22228 +
22229 +       return do_set_prio_bias(vxi, &vc_data);
22230 +}
22231 +
22232 +int vc_get_prio_bias(struct vx_info *vxi, void __user *data)
22233 +{
22234 +       struct vcmd_prio_bias vc_data;
22235 +       struct _vx_sched_pc *pcd;
22236 +       int cpu;
22237 +
22238 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
22239 +               return -EFAULT;
22240 +
22241 +       cpu = vc_data.cpu_id;
22242 +
22243 +       if (!cpu_possible(cpu))
22244 +               return -EINVAL;
22245 +
22246 +       pcd = &vx_per_cpu(vxi, sched_pc, cpu);
22247 +       vc_data.prio_bias = pcd->prio_bias;
22248 +
22249 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
22250 +               return -EFAULT;
22251 +       return 0;
22252 +}
22253 +
22254 diff -NurpP --minimal linux-3.6.10/kernel/vserver/sched_init.h linux-3.6.10-vs2.3.4.5/kernel/vserver/sched_init.h
22255 --- linux-3.6.10/kernel/vserver/sched_init.h    1970-01-01 01:00:00.000000000 +0100
22256 +++ linux-3.6.10-vs2.3.4.5/kernel/vserver/sched_init.h  2012-10-04 18:47:00.000000000 +0200
22257 @@ -0,0 +1,27 @@
22258 +
22259 +static inline void vx_info_init_sched(struct _vx_sched *sched)
22260 +{
22261 +       /* scheduling; hard code starting values as constants */
22262 +       sched->prio_bias = 0;
22263 +}
22264 +
22265 +static inline
22266 +void vx_info_init_sched_pc(struct _vx_sched_pc *sched_pc, int cpu)
22267 +{
22268 +       sched_pc->prio_bias = 0;
22269 +
22270 +       sched_pc->user_ticks = 0;
22271 +       sched_pc->sys_ticks = 0;
22272 +       sched_pc->hold_ticks = 0;
22273 +}
22274 +
22275 +static inline void vx_info_exit_sched(struct _vx_sched *sched)
22276 +{
22277 +       return;
22278 +}
22279 +
22280 +static inline
22281 +void vx_info_exit_sched_pc(struct _vx_sched_pc *sched_pc, int cpu)
22282 +{
22283 +       return;
22284 +}
22285 diff -NurpP --minimal linux-3.6.10/kernel/vserver/sched_proc.h linux-3.6.10-vs2.3.4.5/kernel/vserver/sched_proc.h
22286 --- linux-3.6.10/kernel/vserver/sched_proc.h    1970-01-01 01:00:00.000000000 +0100
22287 +++ linux-3.6.10-vs2.3.4.5/kernel/vserver/sched_proc.h  2012-10-04 18:47:00.000000000 +0200
22288 @@ -0,0 +1,32 @@
22289 +#ifndef _VX_SCHED_PROC_H
22290 +#define _VX_SCHED_PROC_H
22291 +
22292 +
22293 +static inline
22294 +int vx_info_proc_sched(struct _vx_sched *sched, char *buffer)
22295 +{
22296 +       int length = 0;
22297 +
22298 +       length += sprintf(buffer,
22299 +               "PrioBias:\t%8d\n",
22300 +               sched->prio_bias);
22301 +       return length;
22302 +}
22303 +
22304 +static inline
22305 +int vx_info_proc_sched_pc(struct _vx_sched_pc *sched_pc,
22306 +       char *buffer, int cpu)
22307 +{
22308 +       int length = 0;
22309 +
22310 +       length += sprintf(buffer + length,
22311 +               "cpu %d: %lld %lld %lld", cpu,
22312 +               (unsigned long long)sched_pc->user_ticks,
22313 +               (unsigned long long)sched_pc->sys_ticks,
22314 +               (unsigned long long)sched_pc->hold_ticks);
22315 +       length += sprintf(buffer + length,
22316 +               " %d\n", sched_pc->prio_bias);
22317 +       return length;
22318 +}
22319 +
22320 +#endif /* _VX_SCHED_PROC_H */
22321 diff -NurpP --minimal linux-3.6.10/kernel/vserver/signal.c linux-3.6.10-vs2.3.4.5/kernel/vserver/signal.c
22322 --- linux-3.6.10/kernel/vserver/signal.c        1970-01-01 01:00:00.000000000 +0100
22323 +++ linux-3.6.10-vs2.3.4.5/kernel/vserver/signal.c      2012-10-04 18:47:00.000000000 +0200
22324 @@ -0,0 +1,134 @@
22325 +/*
22326 + *  linux/kernel/vserver/signal.c
22327 + *
22328 + *  Virtual Server: Signal Support
22329 + *
22330 + *  Copyright (C) 2003-2007  Herbert Pötzl
22331 + *
22332 + *  V0.01  broken out from vcontext V0.05
22333 + *  V0.02  changed vcmds to vxi arg
22334 + *  V0.03  adjusted siginfo for kill
22335 + *
22336 + */
22337 +
22338 +#include <asm/uaccess.h>
22339 +
22340 +#include <linux/vs_context.h>
22341 +#include <linux/vs_pid.h>
22342 +#include <linux/vserver/signal_cmd.h>
22343 +
22344 +
22345 +int vx_info_kill(struct vx_info *vxi, int pid, int sig)
22346 +{
22347 +       int retval, count = 0;
22348 +       struct task_struct *p;
22349 +       struct siginfo *sip = SEND_SIG_PRIV;
22350 +
22351 +       retval = -ESRCH;
22352 +       vxdprintk(VXD_CBIT(misc, 4),
22353 +               "vx_info_kill(%p[#%d],%d,%d)*",
22354 +               vxi, vxi->vx_id, pid, sig);
22355 +       read_lock(&tasklist_lock);
22356 +       switch (pid) {
22357 +       case  0:
22358 +       case -1:
22359 +               for_each_process(p) {
22360 +                       int err = 0;
22361 +
22362 +                       if (vx_task_xid(p) != vxi->vx_id || p->pid <= 1 ||
22363 +                               (pid && vxi->vx_initpid == p->pid))
22364 +                               continue;
22365 +
22366 +                       err = group_send_sig_info(sig, sip, p);
22367 +                       ++count;
22368 +                       if (err != -EPERM)
22369 +                               retval = err;
22370 +               }
22371 +               break;
22372 +
22373 +       case 1:
22374 +               if (vxi->vx_initpid) {
22375 +                       pid = vxi->vx_initpid;
22376 +                       /* for now, only SIGINT to private init ... */
22377 +                       if (!vx_info_flags(vxi, VXF_STATE_ADMIN, 0) &&
22378 +                               /* ... as long as there are tasks left */
22379 +                               (atomic_read(&vxi->vx_tasks) > 1))
22380 +                               sig = SIGINT;
22381 +               }
22382 +               /* fallthrough */
22383 +       default:
22384 +               rcu_read_lock();
22385 +               p = find_task_by_real_pid(pid);
22386 +               rcu_read_unlock();
22387 +               if (p) {
22388 +                       if (vx_task_xid(p) == vxi->vx_id)
22389 +                               retval = group_send_sig_info(sig, sip, p);
22390 +               }
22391 +               break;
22392 +       }
22393 +       read_unlock(&tasklist_lock);
22394 +       vxdprintk(VXD_CBIT(misc, 4),
22395 +               "vx_info_kill(%p[#%d],%d,%d,%ld) = %d",
22396 +               vxi, vxi->vx_id, pid, sig, (long)sip, retval);
22397 +       return retval;
22398 +}
22399 +
22400 +int vc_ctx_kill(struct vx_info *vxi, void __user *data)
22401 +{
22402 +       struct vcmd_ctx_kill_v0 vc_data;
22403 +
22404 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
22405 +               return -EFAULT;
22406 +
22407 +       /* special check to allow guest shutdown */
22408 +       if (!vx_info_flags(vxi, VXF_STATE_ADMIN, 0) &&
22409 +               /* forbid killall pid=0 when init is present */
22410 +               (((vc_data.pid < 1) && vxi->vx_initpid) ||
22411 +               (vc_data.pid > 1)))
22412 +               return -EACCES;
22413 +
22414 +       return vx_info_kill(vxi, vc_data.pid, vc_data.sig);
22415 +}
22416 +
22417 +
22418 +static int __wait_exit(struct vx_info *vxi)
22419 +{
22420 +       DECLARE_WAITQUEUE(wait, current);
22421 +       int ret = 0;
22422 +
22423 +       add_wait_queue(&vxi->vx_wait, &wait);
22424 +       set_current_state(TASK_INTERRUPTIBLE);
22425 +
22426 +wait:
22427 +       if (vx_info_state(vxi,
22428 +               VXS_SHUTDOWN | VXS_HASHED | VXS_HELPER) == VXS_SHUTDOWN)
22429 +               goto out;
22430 +       if (signal_pending(current)) {
22431 +               ret = -ERESTARTSYS;
22432 +               goto out;
22433 +       }
22434 +       schedule();
22435 +       goto wait;
22436 +
22437 +out:
22438 +       set_current_state(TASK_RUNNING);
22439 +       remove_wait_queue(&vxi->vx_wait, &wait);
22440 +       return ret;
22441 +}
22442 +
22443 +
22444 +
22445 +int vc_wait_exit(struct vx_info *vxi, void __user *data)
22446 +{
22447 +       struct vcmd_wait_exit_v0 vc_data;
22448 +       int ret;
22449 +
22450 +       ret = __wait_exit(vxi);
22451 +       vc_data.reboot_cmd = vxi->reboot_cmd;
22452 +       vc_data.exit_code = vxi->exit_code;
22453 +
22454 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
22455 +               ret = -EFAULT;
22456 +       return ret;
22457 +}
22458 +
22459 diff -NurpP --minimal linux-3.6.10/kernel/vserver/space.c linux-3.6.10-vs2.3.4.5/kernel/vserver/space.c
22460 --- linux-3.6.10/kernel/vserver/space.c 1970-01-01 01:00:00.000000000 +0100
22461 +++ linux-3.6.10-vs2.3.4.5/kernel/vserver/space.c       2012-10-04 18:47:00.000000000 +0200
22462 @@ -0,0 +1,436 @@
22463 +/*
22464 + *  linux/kernel/vserver/space.c
22465 + *
22466 + *  Virtual Server: Context Space Support
22467 + *
22468 + *  Copyright (C) 2003-2010  Herbert Pötzl
22469 + *
22470 + *  V0.01  broken out from context.c 0.07
22471 + *  V0.02  added task locking for namespace
22472 + *  V0.03  broken out vx_enter_namespace
22473 + *  V0.04  added *space support and commands
22474 + *  V0.05  added credential support
22475 + *
22476 + */
22477 +
22478 +#include <linux/utsname.h>
22479 +#include <linux/nsproxy.h>
22480 +#include <linux/err.h>
22481 +#include <linux/fs_struct.h>
22482 +#include <linux/cred.h>
22483 +#include <asm/uaccess.h>
22484 +
22485 +#include <linux/vs_context.h>
22486 +#include <linux/vserver/space.h>
22487 +#include <linux/vserver/space_cmd.h>
22488 +
22489 +atomic_t vs_global_nsproxy     = ATOMIC_INIT(0);
22490 +atomic_t vs_global_fs          = ATOMIC_INIT(0);
22491 +atomic_t vs_global_mnt_ns      = ATOMIC_INIT(0);
22492 +atomic_t vs_global_uts_ns      = ATOMIC_INIT(0);
22493 +atomic_t vs_global_user_ns     = ATOMIC_INIT(0);
22494 +atomic_t vs_global_pid_ns      = ATOMIC_INIT(0);
22495 +
22496 +
22497 +/* namespace functions */
22498 +
22499 +#include <linux/mnt_namespace.h>
22500 +#include <linux/user_namespace.h>
22501 +#include <linux/pid_namespace.h>
22502 +#include <linux/ipc_namespace.h>
22503 +#include <net/net_namespace.h>
22504 +#include "../fs/mount.h"
22505 +
22506 +
22507 +static const struct vcmd_space_mask_v1 space_mask_v0 = {
22508 +       .mask = CLONE_FS |
22509 +               CLONE_NEWNS |
22510 +#ifdef CONFIG_UTS_NS
22511 +               CLONE_NEWUTS |
22512 +#endif
22513 +#ifdef CONFIG_IPC_NS
22514 +               CLONE_NEWIPC |
22515 +#endif
22516 +#ifdef CONFIG_USER_NS
22517 +               CLONE_NEWUSER |
22518 +#endif
22519 +               0
22520 +};
22521 +
22522 +static const struct vcmd_space_mask_v1 space_mask = {
22523 +       .mask = CLONE_FS |
22524 +               CLONE_NEWNS |
22525 +#ifdef CONFIG_UTS_NS
22526 +               CLONE_NEWUTS |
22527 +#endif
22528 +#ifdef CONFIG_IPC_NS
22529 +               CLONE_NEWIPC |
22530 +#endif
22531 +#ifdef CONFIG_USER_NS
22532 +               CLONE_NEWUSER |
22533 +#endif
22534 +#ifdef CONFIG_PID_NS
22535 +               CLONE_NEWPID |
22536 +#endif
22537 +#ifdef CONFIG_NET_NS
22538 +               CLONE_NEWNET |
22539 +#endif
22540 +               0
22541 +};
22542 +
22543 +static const struct vcmd_space_mask_v1 default_space_mask = {
22544 +       .mask = CLONE_FS |
22545 +               CLONE_NEWNS |
22546 +#ifdef CONFIG_UTS_NS
22547 +               CLONE_NEWUTS |
22548 +#endif
22549 +#ifdef CONFIG_IPC_NS
22550 +               CLONE_NEWIPC |
22551 +#endif
22552 +#ifdef CONFIG_USER_NS
22553 +               CLONE_NEWUSER |
22554 +#endif
22555 +#ifdef CONFIG_PID_NS
22556 +//             CLONE_NEWPID |
22557 +#endif
22558 +               0
22559 +};
22560 +
22561 +/*
22562 + *     build a new nsproxy mix
22563 + *      assumes that both proxies are 'const'
22564 + *     does not touch nsproxy refcounts
22565 + *     will hold a reference on the result.
22566 + */
22567 +
22568 +struct nsproxy *vs_mix_nsproxy(struct nsproxy *old_nsproxy,
22569 +       struct nsproxy *new_nsproxy, unsigned long mask)
22570 +{
22571 +       struct mnt_namespace *old_ns;
22572 +       struct uts_namespace *old_uts;
22573 +       struct ipc_namespace *old_ipc;
22574 +#ifdef CONFIG_PID_NS
22575 +       struct pid_namespace *old_pid;
22576 +#endif
22577 +#ifdef CONFIG_NET_NS
22578 +       struct net *old_net;
22579 +#endif
22580 +       struct nsproxy *nsproxy;
22581 +
22582 +       nsproxy = copy_nsproxy(old_nsproxy);
22583 +       if (!nsproxy)
22584 +               goto out;
22585 +
22586 +       if (mask & CLONE_NEWNS) {
22587 +               old_ns = nsproxy->mnt_ns;
22588 +               nsproxy->mnt_ns = new_nsproxy->mnt_ns;
22589 +               if (nsproxy->mnt_ns)
22590 +                       get_mnt_ns(nsproxy->mnt_ns);
22591 +       } else
22592 +               old_ns = NULL;
22593 +
22594 +       if (mask & CLONE_NEWUTS) {
22595 +               old_uts = nsproxy->uts_ns;
22596 +               nsproxy->uts_ns = new_nsproxy->uts_ns;
22597 +               if (nsproxy->uts_ns)
22598 +                       get_uts_ns(nsproxy->uts_ns);
22599 +       } else
22600 +               old_uts = NULL;
22601 +
22602 +       if (mask & CLONE_NEWIPC) {
22603 +               old_ipc = nsproxy->ipc_ns;
22604 +               nsproxy->ipc_ns = new_nsproxy->ipc_ns;
22605 +               if (nsproxy->ipc_ns)
22606 +                       get_ipc_ns(nsproxy->ipc_ns);
22607 +       } else
22608 +               old_ipc = NULL;
22609 +
22610 +#ifdef CONFIG_PID_NS
22611 +       if (mask & CLONE_NEWPID) {
22612 +               old_pid = nsproxy->pid_ns;
22613 +               nsproxy->pid_ns = new_nsproxy->pid_ns;
22614 +               if (nsproxy->pid_ns)
22615 +                       get_pid_ns(nsproxy->pid_ns);
22616 +       } else
22617 +               old_pid = NULL;
22618 +#endif
22619 +#ifdef CONFIG_NET_NS
22620 +       if (mask & CLONE_NEWNET) {
22621 +               old_net = nsproxy->net_ns;
22622 +               nsproxy->net_ns = new_nsproxy->net_ns;
22623 +               if (nsproxy->net_ns)
22624 +                       get_net(nsproxy->net_ns);
22625 +       } else
22626 +               old_net = NULL;
22627 +#endif
22628 +       if (old_ns)
22629 +               put_mnt_ns(old_ns);
22630 +       if (old_uts)
22631 +               put_uts_ns(old_uts);
22632 +       if (old_ipc)
22633 +               put_ipc_ns(old_ipc);
22634 +#ifdef CONFIG_PID_NS
22635 +       if (old_pid)
22636 +               put_pid_ns(old_pid);
22637 +#endif
22638 +#ifdef CONFIG_NET_NS
22639 +       if (old_net)
22640 +               put_net(old_net);
22641 +#endif
22642 +out:
22643 +       return nsproxy;
22644 +}
22645 +
22646 +
22647 +/*
22648 + *     merge two nsproxy structs into a new one.
22649 + *     will hold a reference on the result.
22650 + */
22651 +
22652 +static inline
22653 +struct nsproxy *__vs_merge_nsproxy(struct nsproxy *old,
22654 +       struct nsproxy *proxy, unsigned long mask)
22655 +{
22656 +       struct nsproxy null_proxy = { .mnt_ns = NULL };
22657 +
22658 +       if (!proxy)
22659 +               return NULL;
22660 +
22661 +       if (mask) {
22662 +               /* vs_mix_nsproxy returns with reference */
22663 +               return vs_mix_nsproxy(old ? old : &null_proxy,
22664 +                       proxy, mask);
22665 +       }
22666 +       get_nsproxy(proxy);
22667 +       return proxy;
22668 +}
22669 +
22670 +
22671 +int vx_enter_space(struct vx_info *vxi, unsigned long mask, unsigned index)
22672 +{
22673 +       struct nsproxy *proxy, *proxy_cur, *proxy_new;
22674 +       struct fs_struct *fs_cur, *fs = NULL;
22675 +       struct _vx_space *space;
22676 +       int ret, kill = 0;
22677 +
22678 +       vxdprintk(VXD_CBIT(space, 8), "vx_enter_space(%p[#%u],0x%08lx,%d)",
22679 +               vxi, vxi->vx_id, mask, index);
22680 +
22681 +       if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0))
22682 +               return -EACCES;
22683 +
22684 +       if (index >= VX_SPACES)
22685 +               return -EINVAL;
22686 +
22687 +       space = &vxi->space[index];
22688 +
22689 +       if (!mask)
22690 +               mask = space->vx_nsmask;
22691 +
22692 +       if ((mask & space->vx_nsmask) != mask)
22693 +               return -EINVAL;
22694 +
22695 +       if (mask & CLONE_FS) {
22696 +               fs = copy_fs_struct(space->vx_fs);
22697 +               if (!fs)
22698 +                       return -ENOMEM;
22699 +       }
22700 +       proxy = space->vx_nsproxy;
22701 +
22702 +       vxdprintk(VXD_CBIT(space, 9),
22703 +               "vx_enter_space(%p[#%u],0x%08lx,%d) -> (%p,%p)",
22704 +               vxi, vxi->vx_id, mask, index, proxy, fs);
22705 +
22706 +       task_lock(current);
22707 +       fs_cur = current->fs;
22708 +
22709 +       if (mask & CLONE_FS) {
22710 +               spin_lock(&fs_cur->lock);
22711 +               current->fs = fs;
22712 +               kill = !--fs_cur->users;
22713 +               spin_unlock(&fs_cur->lock);
22714 +       }
22715 +
22716 +       proxy_cur = current->nsproxy;
22717 +       get_nsproxy(proxy_cur);
22718 +       task_unlock(current);
22719 +
22720 +       if (kill)
22721 +               free_fs_struct(fs_cur);
22722 +
22723 +       proxy_new = __vs_merge_nsproxy(proxy_cur, proxy, mask);
22724 +       if (IS_ERR(proxy_new)) {
22725 +               ret = PTR_ERR(proxy_new);
22726 +               goto out_put;
22727 +       }
22728 +
22729 +       proxy_new = xchg(&current->nsproxy, proxy_new);
22730 +
22731 +       if (mask & CLONE_NEWUSER) {
22732 +               struct cred *cred;
22733 +
22734 +               vxdprintk(VXD_CBIT(space, 10),
22735 +                       "vx_enter_space(%p[#%u],%p) cred (%p,%p)",
22736 +                       vxi, vxi->vx_id, space->vx_cred,
22737 +                       current->real_cred, current->cred);
22738 +
22739 +               if (space->vx_cred) {
22740 +                       cred = __prepare_creds(space->vx_cred);
22741 +                       if (cred)
22742 +                               commit_creds(cred);
22743 +               }
22744 +       }
22745 +
22746 +       ret = 0;
22747 +
22748 +       if (proxy_new)
22749 +               put_nsproxy(proxy_new);
22750 +out_put:
22751 +       if (proxy_cur)
22752 +               put_nsproxy(proxy_cur);
22753 +       return ret;
22754 +}
22755 +
22756 +
22757 +int vx_set_space(struct vx_info *vxi, unsigned long mask, unsigned index)
22758 +{
22759 +       struct nsproxy *proxy_vxi, *proxy_cur, *proxy_new;
22760 +       struct fs_struct *fs_vxi, *fs;
22761 +       struct _vx_space *space;
22762 +       int ret, kill = 0;
22763 +
22764 +       vxdprintk(VXD_CBIT(space, 8), "vx_set_space(%p[#%u],0x%08lx,%d)",
22765 +               vxi, vxi->vx_id, mask, index);
22766 +
22767 +       if ((mask & space_mask.mask) != mask)
22768 +               return -EINVAL;
22769 +
22770 +       if (index >= VX_SPACES)
22771 +               return -EINVAL;
22772 +
22773 +       space = &vxi->space[index];
22774 +
22775 +       proxy_vxi = space->vx_nsproxy;
22776 +       fs_vxi = space->vx_fs;
22777 +
22778 +       if (mask & CLONE_FS) {
22779 +               fs = copy_fs_struct(current->fs);
22780 +               if (!fs)
22781 +                       return -ENOMEM;
22782 +       }
22783 +
22784 +       task_lock(current);
22785 +
22786 +       if (mask & CLONE_FS) {
22787 +               spin_lock(&fs_vxi->lock);
22788 +               space->vx_fs = fs;
22789 +               kill = !--fs_vxi->users;
22790 +               spin_unlock(&fs_vxi->lock);
22791 +       }
22792 +
22793 +       proxy_cur = current->nsproxy;
22794 +       get_nsproxy(proxy_cur);
22795 +       task_unlock(current);
22796 +
22797 +       if (kill)
22798 +               free_fs_struct(fs_vxi);
22799 +
22800 +       proxy_new = __vs_merge_nsproxy(proxy_vxi, proxy_cur, mask);
22801 +       if (IS_ERR(proxy_new)) {
22802 +               ret = PTR_ERR(proxy_new);
22803 +               goto out_put;
22804 +       }
22805 +
22806 +       proxy_new = xchg(&space->vx_nsproxy, proxy_new);
22807 +       space->vx_nsmask |= mask;
22808 +
22809 +       if (mask & CLONE_NEWUSER) {
22810 +               struct cred *cred;
22811 +
22812 +               vxdprintk(VXD_CBIT(space, 10),
22813 +                       "vx_set_space(%p[#%u],%p) cred (%p,%p)",
22814 +                       vxi, vxi->vx_id, space->vx_cred,
22815 +                       current->real_cred, current->cred);
22816 +
22817 +               cred = prepare_creds();
22818 +               cred = (struct cred *)xchg(&space->vx_cred, cred);
22819 +               if (cred)
22820 +                       abort_creds(cred);
22821 +       }
22822 +
22823 +       ret = 0;
22824 +
22825 +       if (proxy_new)
22826 +               put_nsproxy(proxy_new);
22827 +out_put:
22828 +       if (proxy_cur)
22829 +               put_nsproxy(proxy_cur);
22830 +       return ret;
22831 +}
22832 +
22833 +
22834 +int vc_enter_space_v1(struct vx_info *vxi, void __user *data)
22835 +{
22836 +       struct vcmd_space_mask_v1 vc_data = { .mask = 0 };
22837 +
22838 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22839 +               return -EFAULT;
22840 +
22841 +       return vx_enter_space(vxi, vc_data.mask, 0);
22842 +}
22843 +
22844 +int vc_enter_space(struct vx_info *vxi, void __user *data)
22845 +{
22846 +       struct vcmd_space_mask_v2 vc_data = { .mask = 0 };
22847 +
22848 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22849 +               return -EFAULT;
22850 +
22851 +       if (vc_data.index >= VX_SPACES)
22852 +               return -EINVAL;
22853 +
22854 +       return vx_enter_space(vxi, vc_data.mask, vc_data.index);
22855 +}
22856 +
22857 +int vc_set_space_v1(struct vx_info *vxi, void __user *data)
22858 +{
22859 +       struct vcmd_space_mask_v1 vc_data = { .mask = 0 };
22860 +
22861 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22862 +               return -EFAULT;
22863 +
22864 +       return vx_set_space(vxi, vc_data.mask, 0);
22865 +}
22866 +
22867 +int vc_set_space(struct vx_info *vxi, void __user *data)
22868 +{
22869 +       struct vcmd_space_mask_v2 vc_data = { .mask = 0 };
22870 +
22871 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22872 +               return -EFAULT;
22873 +
22874 +       if (vc_data.index >= VX_SPACES)
22875 +               return -EINVAL;
22876 +
22877 +       return vx_set_space(vxi, vc_data.mask, vc_data.index);
22878 +}
22879 +
22880 +int vc_get_space_mask(void __user *data, int type)
22881 +{
22882 +       const struct vcmd_space_mask_v1 *mask;
22883 +
22884 +       if (type == 0)
22885 +               mask = &space_mask_v0;
22886 +       else if (type == 1)
22887 +               mask = &space_mask;
22888 +       else
22889 +               mask = &default_space_mask;
22890 +
22891 +       vxdprintk(VXD_CBIT(space, 10),
22892 +               "vc_get_space_mask(%d) = %08llx", type, mask->mask);
22893 +
22894 +       if (copy_to_user(data, mask, sizeof(*mask)))
22895 +               return -EFAULT;
22896 +       return 0;
22897 +}
22898 +
22899 diff -NurpP --minimal linux-3.6.10/kernel/vserver/switch.c linux-3.6.10-vs2.3.4.5/kernel/vserver/switch.c
22900 --- linux-3.6.10/kernel/vserver/switch.c        1970-01-01 01:00:00.000000000 +0100
22901 +++ linux-3.6.10-vs2.3.4.5/kernel/vserver/switch.c      2012-10-04 18:47:00.000000000 +0200
22902 @@ -0,0 +1,556 @@
22903 +/*
22904 + *  linux/kernel/vserver/switch.c
22905 + *
22906 + *  Virtual Server: Syscall Switch
22907 + *
22908 + *  Copyright (C) 2003-2011  Herbert Pötzl
22909 + *
22910 + *  V0.01  syscall switch
22911 + *  V0.02  added signal to context
22912 + *  V0.03  added rlimit functions
22913 + *  V0.04  added iattr, task/xid functions
22914 + *  V0.05  added debug/history stuff
22915 + *  V0.06  added compat32 layer
22916 + *  V0.07  vcmd args and perms
22917 + *  V0.08  added status commands
22918 + *  V0.09  added tag commands
22919 + *  V0.10  added oom bias
22920 + *  V0.11  added device commands
22921 + *  V0.12  added warn mask
22922 + *
22923 + */
22924 +
22925 +#include <linux/vs_context.h>
22926 +#include <linux/vs_network.h>
22927 +#include <linux/vserver/switch.h>
22928 +
22929 +#include "vci_config.h"
22930 +
22931 +
22932 +static inline
22933 +int vc_get_version(uint32_t id)
22934 +{
22935 +       return VCI_VERSION;
22936 +}
22937 +
22938 +static inline
22939 +int vc_get_vci(uint32_t id)
22940 +{
22941 +       return vci_kernel_config();
22942 +}
22943 +
22944 +#include <linux/vserver/context_cmd.h>
22945 +#include <linux/vserver/cvirt_cmd.h>
22946 +#include <linux/vserver/cacct_cmd.h>
22947 +#include <linux/vserver/limit_cmd.h>
22948 +#include <linux/vserver/network_cmd.h>
22949 +#include <linux/vserver/sched_cmd.h>
22950 +#include <linux/vserver/debug_cmd.h>
22951 +#include <linux/vserver/inode_cmd.h>
22952 +#include <linux/vserver/dlimit_cmd.h>
22953 +#include <linux/vserver/signal_cmd.h>
22954 +#include <linux/vserver/space_cmd.h>
22955 +#include <linux/vserver/tag_cmd.h>
22956 +#include <linux/vserver/device_cmd.h>
22957 +
22958 +#include <linux/vserver/inode.h>
22959 +#include <linux/vserver/dlimit.h>
22960 +
22961 +
22962 +#ifdef CONFIG_COMPAT
22963 +#define __COMPAT(name, id, data, compat)       \
22964 +       (compat) ? name ## _x32(id, data) : name(id, data)
22965 +#define __COMPAT_NO_ID(name, data, compat)     \
22966 +       (compat) ? name ## _x32(data) : name(data)
22967 +#else
22968 +#define __COMPAT(name, id, data, compat)       \
22969 +       name(id, data)
22970 +#define __COMPAT_NO_ID(name, data, compat)     \
22971 +       name(data)
22972 +#endif
22973 +
22974 +
22975 +static inline
22976 +long do_vcmd(uint32_t cmd, uint32_t id,
22977 +       struct vx_info *vxi, struct nx_info *nxi,
22978 +       void __user *data, int compat)
22979 +{
22980 +       switch (cmd) {
22981 +
22982 +       case VCMD_get_version:
22983 +               return vc_get_version(id);
22984 +       case VCMD_get_vci:
22985 +               return vc_get_vci(id);
22986 +
22987 +       case VCMD_task_xid:
22988 +               return vc_task_xid(id);
22989 +       case VCMD_vx_info:
22990 +               return vc_vx_info(vxi, data);
22991 +
22992 +       case VCMD_task_nid:
22993 +               return vc_task_nid(id);
22994 +       case VCMD_nx_info:
22995 +               return vc_nx_info(nxi, data);
22996 +
22997 +       case VCMD_task_tag:
22998 +               return vc_task_tag(id);
22999 +
23000 +       case VCMD_set_space_v1:
23001 +               return vc_set_space_v1(vxi, data);
23002 +       /* this is version 2 */
23003 +       case VCMD_set_space:
23004 +               return vc_set_space(vxi, data);
23005 +
23006 +       case VCMD_get_space_mask_v0:
23007 +               return vc_get_space_mask(data, 0);
23008 +       /* this is version 1 */
23009 +       case VCMD_get_space_mask:
23010 +               return vc_get_space_mask(data, 1);
23011 +
23012 +       case VCMD_get_space_default:
23013 +               return vc_get_space_mask(data, -1);
23014 +
23015 +       case VCMD_set_umask:
23016 +               return vc_set_umask(vxi, data);
23017 +
23018 +       case VCMD_get_umask:
23019 +               return vc_get_umask(vxi, data);
23020 +
23021 +       case VCMD_set_wmask:
23022 +               return vc_set_wmask(vxi, data);
23023 +
23024 +       case VCMD_get_wmask:
23025 +               return vc_get_wmask(vxi, data);
23026 +#ifdef CONFIG_IA32_EMULATION
23027 +       case VCMD_get_rlimit:
23028 +               return __COMPAT(vc_get_rlimit, vxi, data, compat);
23029 +       case VCMD_set_rlimit:
23030 +               return __COMPAT(vc_set_rlimit, vxi, data, compat);
23031 +#else
23032 +       case VCMD_get_rlimit:
23033 +               return vc_get_rlimit(vxi, data);
23034 +       case VCMD_set_rlimit:
23035 +               return vc_set_rlimit(vxi, data);
23036 +#endif
23037 +       case VCMD_get_rlimit_mask:
23038 +               return vc_get_rlimit_mask(id, data);
23039 +       case VCMD_reset_hits:
23040 +               return vc_reset_hits(vxi, data);
23041 +       case VCMD_reset_minmax:
23042 +               return vc_reset_minmax(vxi, data);
23043 +
23044 +       case VCMD_get_vhi_name:
23045 +               return vc_get_vhi_name(vxi, data);
23046 +       case VCMD_set_vhi_name:
23047 +               return vc_set_vhi_name(vxi, data);
23048 +
23049 +       case VCMD_ctx_stat:
23050 +               return vc_ctx_stat(vxi, data);
23051 +       case VCMD_virt_stat:
23052 +               return vc_virt_stat(vxi, data);
23053 +       case VCMD_sock_stat:
23054 +               return vc_sock_stat(vxi, data);
23055 +       case VCMD_rlimit_stat:
23056 +               return vc_rlimit_stat(vxi, data);
23057 +
23058 +       case VCMD_set_cflags:
23059 +               return vc_set_cflags(vxi, data);
23060 +       case VCMD_get_cflags:
23061 +               return vc_get_cflags(vxi, data);
23062 +
23063 +       /* this is version 1 */
23064 +       case VCMD_set_ccaps:
23065 +               return vc_set_ccaps(vxi, data);
23066 +       /* this is version 1 */
23067 +       case VCMD_get_ccaps:
23068 +               return vc_get_ccaps(vxi, data);
23069 +       case VCMD_set_bcaps:
23070 +               return vc_set_bcaps(vxi, data);
23071 +       case VCMD_get_bcaps:
23072 +               return vc_get_bcaps(vxi, data);
23073 +
23074 +       case VCMD_set_badness:
23075 +               return vc_set_badness(vxi, data);
23076 +       case VCMD_get_badness:
23077 +               return vc_get_badness(vxi, data);
23078 +
23079 +       case VCMD_set_nflags:
23080 +               return vc_set_nflags(nxi, data);
23081 +       case VCMD_get_nflags:
23082 +               return vc_get_nflags(nxi, data);
23083 +
23084 +       case VCMD_set_ncaps:
23085 +               return vc_set_ncaps(nxi, data);
23086 +       case VCMD_get_ncaps:
23087 +               return vc_get_ncaps(nxi, data);
23088 +
23089 +       case VCMD_set_prio_bias:
23090 +               return vc_set_prio_bias(vxi, data);
23091 +       case VCMD_get_prio_bias:
23092 +               return vc_get_prio_bias(vxi, data);
23093 +       case VCMD_add_dlimit:
23094 +               return __COMPAT(vc_add_dlimit, id, data, compat);
23095 +       case VCMD_rem_dlimit:
23096 +               return __COMPAT(vc_rem_dlimit, id, data, compat);
23097 +       case VCMD_set_dlimit:
23098 +               return __COMPAT(vc_set_dlimit, id, data, compat);
23099 +       case VCMD_get_dlimit:
23100 +               return __COMPAT(vc_get_dlimit, id, data, compat);
23101 +
23102 +       case VCMD_ctx_kill:
23103 +               return vc_ctx_kill(vxi, data);
23104 +
23105 +       case VCMD_wait_exit:
23106 +               return vc_wait_exit(vxi, data);
23107 +
23108 +       case VCMD_get_iattr:
23109 +               return __COMPAT_NO_ID(vc_get_iattr, data, compat);
23110 +       case VCMD_set_iattr:
23111 +               return __COMPAT_NO_ID(vc_set_iattr, data, compat);
23112 +
23113 +       case VCMD_fget_iattr:
23114 +               return vc_fget_iattr(id, data);
23115 +       case VCMD_fset_iattr:
23116 +               return vc_fset_iattr(id, data);
23117 +
23118 +       case VCMD_enter_space_v0:
23119 +               return vc_enter_space_v1(vxi, NULL);
23120 +       case VCMD_enter_space_v1:
23121 +               return vc_enter_space_v1(vxi, data);
23122 +       /* this is version 2 */
23123 +       case VCMD_enter_space:
23124 +               return vc_enter_space(vxi, data);
23125 +
23126 +       case VCMD_ctx_create_v0:
23127 +               return vc_ctx_create(id, NULL);
23128 +       case VCMD_ctx_create:
23129 +               return vc_ctx_create(id, data);
23130 +       case VCMD_ctx_migrate_v0:
23131 +               return vc_ctx_migrate(vxi, NULL);
23132 +       case VCMD_ctx_migrate:
23133 +               return vc_ctx_migrate(vxi, data);
23134 +
23135 +       case VCMD_net_create_v0:
23136 +               return vc_net_create(id, NULL);
23137 +       case VCMD_net_create:
23138 +               return vc_net_create(id, data);
23139 +       case VCMD_net_migrate:
23140 +               return vc_net_migrate(nxi, data);
23141 +
23142 +       case VCMD_tag_migrate:
23143 +               return vc_tag_migrate(id);
23144 +
23145 +       case VCMD_net_add:
23146 +               return vc_net_add(nxi, data);
23147 +       case VCMD_net_remove:
23148 +               return vc_net_remove(nxi, data);
23149 +
23150 +       case VCMD_net_add_ipv4_v1:
23151 +               return vc_net_add_ipv4_v1(nxi, data);
23152 +       /* this is version 2 */
23153 +       case VCMD_net_add_ipv4:
23154 +               return vc_net_add_ipv4(nxi, data);
23155 +
23156 +       case VCMD_net_rem_ipv4_v1:
23157 +               return vc_net_rem_ipv4_v1(nxi, data);
23158 +       /* this is version 2 */
23159 +       case VCMD_net_rem_ipv4:
23160 +               return vc_net_rem_ipv4(nxi, data);
23161 +#ifdef CONFIG_IPV6
23162 +       case VCMD_net_add_ipv6:
23163 +               return vc_net_add_ipv6(nxi, data);
23164 +       case VCMD_net_remove_ipv6:
23165 +               return vc_net_remove_ipv6(nxi, data);
23166 +#endif
23167 +/*     case VCMD_add_match_ipv4:
23168 +               return vc_add_match_ipv4(nxi, data);
23169 +       case VCMD_get_match_ipv4:
23170 +               return vc_get_match_ipv4(nxi, data);
23171 +#ifdef CONFIG_IPV6
23172 +       case VCMD_add_match_ipv6:
23173 +               return vc_add_match_ipv6(nxi, data);
23174 +       case VCMD_get_match_ipv6:
23175 +               return vc_get_match_ipv6(nxi, data);
23176 +#endif */
23177 +
23178 +#ifdef CONFIG_VSERVER_DEVICE
23179 +       case VCMD_set_mapping:
23180 +               return __COMPAT(vc_set_mapping, vxi, data, compat);
23181 +       case VCMD_unset_mapping:
23182 +               return __COMPAT(vc_unset_mapping, vxi, data, compat);
23183 +#endif
23184 +#ifdef CONFIG_VSERVER_HISTORY
23185 +       case VCMD_dump_history:
23186 +               return vc_dump_history(id);
23187 +       case VCMD_read_history:
23188 +               return __COMPAT(vc_read_history, id, data, compat);
23189 +#endif
23190 +       default:
23191 +               vxwprintk_task(1, "unimplemented VCMD_%02d_%d[%d]",
23192 +                       VC_CATEGORY(cmd), VC_COMMAND(cmd), VC_VERSION(cmd));
23193 +       }
23194 +       return -ENOSYS;
23195 +}
23196 +
23197 +
23198 +#define        __VCMD(vcmd, _perm, _args, _flags)              \
23199 +       case VCMD_ ## vcmd: perm = _perm;               \
23200 +               args = _args; flags = _flags; break
23201 +
23202 +
23203 +#define VCA_NONE       0x00
23204 +#define VCA_VXI                0x01
23205 +#define VCA_NXI                0x02
23206 +
23207 +#define VCF_NONE       0x00
23208 +#define VCF_INFO       0x01
23209 +#define VCF_ADMIN      0x02
23210 +#define VCF_ARES       0x06    /* includes admin */
23211 +#define VCF_SETUP      0x08
23212 +
23213 +#define VCF_ZIDOK      0x10    /* zero id okay */
23214 +
23215 +
23216 +static inline
23217 +long do_vserver(uint32_t cmd, uint32_t id, void __user *data, int compat)
23218 +{
23219 +       long ret;
23220 +       int permit = -1, state = 0;
23221 +       int perm = -1, args = 0, flags = 0;
23222 +       struct vx_info *vxi = NULL;
23223 +       struct nx_info *nxi = NULL;
23224 +
23225 +       switch (cmd) {
23226 +       /* unpriviledged commands */
23227 +       __VCMD(get_version,      0, VCA_NONE,   0);
23228 +       __VCMD(get_vci,          0, VCA_NONE,   0);
23229 +       __VCMD(get_rlimit_mask,  0, VCA_NONE,   0);
23230 +       __VCMD(get_space_mask_v0,0, VCA_NONE,   0);
23231 +       __VCMD(get_space_mask,   0, VCA_NONE,   0);
23232 +       __VCMD(get_space_default,0, VCA_NONE,   0);
23233 +
23234 +       /* info commands */
23235 +       __VCMD(task_xid,         2, VCA_NONE,   0);
23236 +       __VCMD(reset_hits,       2, VCA_VXI,    0);
23237 +       __VCMD(reset_minmax,     2, VCA_VXI,    0);
23238 +       __VCMD(vx_info,          3, VCA_VXI,    VCF_INFO);
23239 +       __VCMD(get_bcaps,        3, VCA_VXI,    VCF_INFO);
23240 +       __VCMD(get_ccaps,        3, VCA_VXI,    VCF_INFO);
23241 +       __VCMD(get_cflags,       3, VCA_VXI,    VCF_INFO);
23242 +       __VCMD(get_umask,        3, VCA_VXI,    VCF_INFO);
23243 +       __VCMD(get_wmask,        3, VCA_VXI,    VCF_INFO);
23244 +       __VCMD(get_badness,      3, VCA_VXI,    VCF_INFO);
23245 +       __VCMD(get_vhi_name,     3, VCA_VXI,    VCF_INFO);
23246 +       __VCMD(get_rlimit,       3, VCA_VXI,    VCF_INFO);
23247 +
23248 +       __VCMD(ctx_stat,         3, VCA_VXI,    VCF_INFO);
23249 +       __VCMD(virt_stat,        3, VCA_VXI,    VCF_INFO);
23250 +       __VCMD(sock_stat,        3, VCA_VXI,    VCF_INFO);
23251 +       __VCMD(rlimit_stat,      3, VCA_VXI,    VCF_INFO);
23252 +
23253 +       __VCMD(task_nid,         2, VCA_NONE,   0);
23254 +       __VCMD(nx_info,          3, VCA_NXI,    VCF_INFO);
23255 +       __VCMD(get_ncaps,        3, VCA_NXI,    VCF_INFO);
23256 +       __VCMD(get_nflags,       3, VCA_NXI,    VCF_INFO);
23257 +
23258 +       __VCMD(task_tag,         2, VCA_NONE,   0);
23259 +
23260 +       __VCMD(get_iattr,        2, VCA_NONE,   0);
23261 +       __VCMD(fget_iattr,       2, VCA_NONE,   0);
23262 +       __VCMD(get_dlimit,       3, VCA_NONE,   VCF_INFO);
23263 +       __VCMD(get_prio_bias,    3, VCA_VXI,    VCF_INFO);
23264 +
23265 +       /* lower admin commands */
23266 +       __VCMD(wait_exit,        4, VCA_VXI,    VCF_INFO);
23267 +       __VCMD(ctx_create_v0,    5, VCA_NONE,   0);
23268 +       __VCMD(ctx_create,       5, VCA_NONE,   0);
23269 +       __VCMD(ctx_migrate_v0,   5, VCA_VXI,    VCF_ADMIN);
23270 +       __VCMD(ctx_migrate,      5, VCA_VXI,    VCF_ADMIN);
23271 +       __VCMD(enter_space_v0,   5, VCA_VXI,    VCF_ADMIN);
23272 +       __VCMD(enter_space_v1,   5, VCA_VXI,    VCF_ADMIN);
23273 +       __VCMD(enter_space,      5, VCA_VXI,    VCF_ADMIN);
23274 +
23275 +       __VCMD(net_create_v0,    5, VCA_NONE,   0);
23276 +       __VCMD(net_create,       5, VCA_NONE,   0);
23277 +       __VCMD(net_migrate,      5, VCA_NXI,    VCF_ADMIN);
23278 +
23279 +       __VCMD(tag_migrate,      5, VCA_NONE,   VCF_ADMIN);
23280 +
23281 +       /* higher admin commands */
23282 +       __VCMD(ctx_kill,         6, VCA_VXI,    VCF_ARES);
23283 +       __VCMD(set_space_v1,     7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23284 +       __VCMD(set_space,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23285 +
23286 +       __VCMD(set_ccaps,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23287 +       __VCMD(set_bcaps,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23288 +       __VCMD(set_cflags,       7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23289 +       __VCMD(set_umask,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23290 +       __VCMD(set_wmask,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23291 +       __VCMD(set_badness,      7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23292 +
23293 +       __VCMD(set_vhi_name,     7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23294 +       __VCMD(set_rlimit,       7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23295 +       __VCMD(set_prio_bias,    7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23296 +
23297 +       __VCMD(set_ncaps,        7, VCA_NXI,    VCF_ARES | VCF_SETUP);
23298 +       __VCMD(set_nflags,       7, VCA_NXI,    VCF_ARES | VCF_SETUP);
23299 +       __VCMD(net_add,          8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23300 +       __VCMD(net_remove,       8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23301 +       __VCMD(net_add_ipv4_v1,  8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23302 +       __VCMD(net_rem_ipv4_v1,  8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23303 +       __VCMD(net_add_ipv4,     8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23304 +       __VCMD(net_rem_ipv4,     8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23305 +#ifdef CONFIG_IPV6
23306 +       __VCMD(net_add_ipv6,     8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23307 +       __VCMD(net_remove_ipv6,  8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23308 +#endif
23309 +       __VCMD(set_iattr,        7, VCA_NONE,   0);
23310 +       __VCMD(fset_iattr,       7, VCA_NONE,   0);
23311 +       __VCMD(set_dlimit,       7, VCA_NONE,   VCF_ARES);
23312 +       __VCMD(add_dlimit,       8, VCA_NONE,   VCF_ARES);
23313 +       __VCMD(rem_dlimit,       8, VCA_NONE,   VCF_ARES);
23314 +
23315 +#ifdef CONFIG_VSERVER_DEVICE
23316 +       __VCMD(set_mapping,      8, VCA_VXI,    VCF_ARES|VCF_ZIDOK);
23317 +       __VCMD(unset_mapping,    8, VCA_VXI,    VCF_ARES|VCF_ZIDOK);
23318 +#endif
23319 +       /* debug level admin commands */
23320 +#ifdef CONFIG_VSERVER_HISTORY
23321 +       __VCMD(dump_history,     9, VCA_NONE,   0);
23322 +       __VCMD(read_history,     9, VCA_NONE,   0);
23323 +#endif
23324 +
23325 +       default:
23326 +               perm = -1;
23327 +       }
23328 +
23329 +       vxdprintk(VXD_CBIT(switch, 0),
23330 +               "vc: VCMD_%02d_%d[%d], %d,%p [%d,%d,%x,%x]",
23331 +               VC_CATEGORY(cmd), VC_COMMAND(cmd),
23332 +               VC_VERSION(cmd), id, data, compat,
23333 +               perm, args, flags);
23334 +
23335 +       ret = -ENOSYS;
23336 +       if (perm < 0)
23337 +               goto out;
23338 +
23339 +       state = 1;
23340 +       if (!capable(CAP_CONTEXT))
23341 +               goto out;
23342 +
23343 +       state = 2;
23344 +       /* moved here from the individual commands */
23345 +       ret = -EPERM;
23346 +       if ((perm > 1) && !capable(CAP_SYS_ADMIN))
23347 +               goto out;
23348 +
23349 +       state = 3;
23350 +       /* vcmd involves resource management  */
23351 +       ret = -EPERM;
23352 +       if ((flags & VCF_ARES) && !capable(CAP_SYS_RESOURCE))
23353 +               goto out;
23354 +
23355 +       state = 4;
23356 +       /* various legacy exceptions */
23357 +       switch (cmd) {
23358 +       /* will go away when spectator is a cap */
23359 +       case VCMD_ctx_migrate_v0:
23360 +       case VCMD_ctx_migrate:
23361 +               if (id == 1) {
23362 +                       current->xid = 1;
23363 +                       ret = 1;
23364 +                       goto out;
23365 +               }
23366 +               break;
23367 +
23368 +       /* will go away when spectator is a cap */
23369 +       case VCMD_net_migrate:
23370 +               if (id == 1) {
23371 +                       current->nid = 1;
23372 +                       ret = 1;
23373 +                       goto out;
23374 +               }
23375 +               break;
23376 +       }
23377 +
23378 +       /* vcmds are fine by default */
23379 +       permit = 1;
23380 +
23381 +       /* admin type vcmds require admin ... */
23382 +       if (flags & VCF_ADMIN)
23383 +               permit = vx_check(0, VS_ADMIN) ? 1 : 0;
23384 +
23385 +       /* ... but setup type vcmds override that */
23386 +       if (!permit && (flags & VCF_SETUP))
23387 +               permit = vx_flags(VXF_STATE_SETUP, 0) ? 2 : 0;
23388 +
23389 +       state = 5;
23390 +       ret = -EPERM;
23391 +       if (!permit)
23392 +               goto out;
23393 +
23394 +       state = 6;
23395 +       if (!id && (flags & VCF_ZIDOK))
23396 +               goto skip_id;
23397 +
23398 +       ret = -ESRCH;
23399 +       if (args & VCA_VXI) {
23400 +               vxi = lookup_vx_info(id);
23401 +               if (!vxi)
23402 +                       goto out;
23403 +
23404 +               if ((flags & VCF_ADMIN) &&
23405 +                       /* special case kill for shutdown */
23406 +                       (cmd != VCMD_ctx_kill) &&
23407 +                       /* can context be administrated? */
23408 +                       !vx_info_flags(vxi, VXF_STATE_ADMIN, 0)) {
23409 +                       ret = -EACCES;
23410 +                       goto out_vxi;
23411 +               }
23412 +       }
23413 +       state = 7;
23414 +       if (args & VCA_NXI) {
23415 +               nxi = lookup_nx_info(id);
23416 +               if (!nxi)
23417 +                       goto out_vxi;
23418 +
23419 +               if ((flags & VCF_ADMIN) &&
23420 +                       /* can context be administrated? */
23421 +                       !nx_info_flags(nxi, NXF_STATE_ADMIN, 0)) {
23422 +                       ret = -EACCES;
23423 +                       goto out_nxi;
23424 +               }
23425 +       }
23426 +skip_id:
23427 +       state = 8;
23428 +       ret = do_vcmd(cmd, id, vxi, nxi, data, compat);
23429 +
23430 +out_nxi:
23431 +       if ((args & VCA_NXI) && nxi)
23432 +               put_nx_info(nxi);
23433 +out_vxi:
23434 +       if ((args & VCA_VXI) && vxi)
23435 +               put_vx_info(vxi);
23436 +out:
23437 +       vxdprintk(VXD_CBIT(switch, 1),
23438 +               "vc: VCMD_%02d_%d[%d] = %08lx(%ld) [%d,%d]",
23439 +               VC_CATEGORY(cmd), VC_COMMAND(cmd),
23440 +               VC_VERSION(cmd), ret, ret, state, permit);
23441 +       return ret;
23442 +}
23443 +
23444 +asmlinkage long
23445 +sys_vserver(uint32_t cmd, uint32_t id, void __user *data)
23446 +{
23447 +       return do_vserver(cmd, id, data, 0);
23448 +}
23449 +
23450 +#ifdef CONFIG_COMPAT
23451 +
23452 +asmlinkage long
23453 +sys32_vserver(uint32_t cmd, uint32_t id, void __user *data)
23454 +{
23455 +       return do_vserver(cmd, id, data, 1);
23456 +}
23457 +
23458 +#endif /* CONFIG_COMPAT */
23459 diff -NurpP --minimal linux-3.6.10/kernel/vserver/sysctl.c linux-3.6.10-vs2.3.4.5/kernel/vserver/sysctl.c
23460 --- linux-3.6.10/kernel/vserver/sysctl.c        1970-01-01 01:00:00.000000000 +0100
23461 +++ linux-3.6.10-vs2.3.4.5/kernel/vserver/sysctl.c      2012-10-04 18:47:00.000000000 +0200
23462 @@ -0,0 +1,247 @@
23463 +/*
23464 + *  kernel/vserver/sysctl.c
23465 + *
23466 + *  Virtual Context Support
23467 + *
23468 + *  Copyright (C) 2004-2007  Herbert Pötzl
23469 + *
23470 + *  V0.01  basic structure
23471 + *
23472 + */
23473 +
23474 +#include <linux/module.h>
23475 +#include <linux/ctype.h>
23476 +#include <linux/sysctl.h>
23477 +#include <linux/parser.h>
23478 +#include <asm/uaccess.h>
23479 +
23480 +enum {
23481 +       CTL_DEBUG_ERROR         = 0,
23482 +       CTL_DEBUG_SWITCH        = 1,
23483 +       CTL_DEBUG_XID,
23484 +       CTL_DEBUG_NID,
23485 +       CTL_DEBUG_TAG,
23486 +       CTL_DEBUG_NET,
23487 +       CTL_DEBUG_LIMIT,
23488 +       CTL_DEBUG_CRES,
23489 +       CTL_DEBUG_DLIM,
23490 +       CTL_DEBUG_QUOTA,
23491 +       CTL_DEBUG_CVIRT,
23492 +       CTL_DEBUG_SPACE,
23493 +       CTL_DEBUG_PERM,
23494 +       CTL_DEBUG_MISC,
23495 +};
23496 +
23497 +
23498 +unsigned int vs_debug_switch   = 0;
23499 +unsigned int vs_debug_xid      = 0;
23500 +unsigned int vs_debug_nid      = 0;
23501 +unsigned int vs_debug_tag      = 0;
23502 +unsigned int vs_debug_net      = 0;
23503 +unsigned int vs_debug_limit    = 0;
23504 +unsigned int vs_debug_cres     = 0;
23505 +unsigned int vs_debug_dlim     = 0;
23506 +unsigned int vs_debug_quota    = 0;
23507 +unsigned int vs_debug_cvirt    = 0;
23508 +unsigned int vs_debug_space    = 0;
23509 +unsigned int vs_debug_perm     = 0;
23510 +unsigned int vs_debug_misc     = 0;
23511 +
23512 +
23513 +static struct ctl_table_header *vserver_table_header;
23514 +static ctl_table vserver_root_table[];
23515 +
23516 +
23517 +void vserver_register_sysctl(void)
23518 +{
23519 +       if (!vserver_table_header) {
23520 +               vserver_table_header = register_sysctl_table(vserver_root_table);
23521 +       }
23522 +
23523 +}
23524 +
23525 +void vserver_unregister_sysctl(void)
23526 +{
23527 +       if (vserver_table_header) {
23528 +               unregister_sysctl_table(vserver_table_header);
23529 +               vserver_table_header = NULL;
23530 +       }
23531 +}
23532 +
23533 +
23534 +static int proc_dodebug(ctl_table *table, int write,
23535 +       void __user *buffer, size_t *lenp, loff_t *ppos)
23536 +{
23537 +       char            tmpbuf[20], *p, c;
23538 +       unsigned int    value;
23539 +       size_t          left, len;
23540 +
23541 +       if ((*ppos && !write) || !*lenp) {
23542 +               *lenp = 0;
23543 +               return 0;
23544 +       }
23545 +
23546 +       left = *lenp;
23547 +
23548 +       if (write) {
23549 +               if (!access_ok(VERIFY_READ, buffer, left))
23550 +                       return -EFAULT;
23551 +               p = (char *)buffer;
23552 +               while (left && __get_user(c, p) >= 0 && isspace(c))
23553 +                       left--, p++;
23554 +               if (!left)
23555 +                       goto done;
23556 +
23557 +               if (left > sizeof(tmpbuf) - 1)
23558 +                       return -EINVAL;
23559 +               if (copy_from_user(tmpbuf, p, left))
23560 +                       return -EFAULT;
23561 +               tmpbuf[left] = '\0';
23562 +
23563 +               for (p = tmpbuf, value = 0; '0' <= *p && *p <= '9'; p++, left--)
23564 +                       value = 10 * value + (*p - '0');
23565 +               if (*p && !isspace(*p))
23566 +                       return -EINVAL;
23567 +               while (left && isspace(*p))
23568 +                       left--, p++;
23569 +               *(unsigned int *)table->data = value;
23570 +       } else {
23571 +               if (!access_ok(VERIFY_WRITE, buffer, left))
23572 +                       return -EFAULT;
23573 +               len = sprintf(tmpbuf, "%d", *(unsigned int *)table->data);
23574 +               if (len > left)
23575 +                       len = left;
23576 +               if (__copy_to_user(buffer, tmpbuf, len))
23577 +                       return -EFAULT;
23578 +               if ((left -= len) > 0) {
23579 +                       if (put_user('\n', (char *)buffer + len))
23580 +                               return -EFAULT;
23581 +                       left--;
23582 +               }
23583 +       }
23584 +
23585 +done:
23586 +       *lenp -= left;
23587 +       *ppos += *lenp;
23588 +       return 0;
23589 +}
23590 +
23591 +static int zero;
23592 +
23593 +#define        CTL_ENTRY(ctl, name)                            \
23594 +       {                                               \
23595 +               .procname       = #name,                \
23596 +               .data           = &vs_ ## name,         \
23597 +               .maxlen         = sizeof(int),          \
23598 +               .mode           = 0644,                 \
23599 +               .proc_handler   = &proc_dodebug,        \
23600 +               .extra1         = &zero,                \
23601 +               .extra2         = &zero,                \
23602 +       }
23603 +
23604 +static ctl_table vserver_debug_table[] = {
23605 +       CTL_ENTRY(CTL_DEBUG_SWITCH,     debug_switch),
23606 +       CTL_ENTRY(CTL_DEBUG_XID,        debug_xid),
23607 +       CTL_ENTRY(CTL_DEBUG_NID,        debug_nid),
23608 +       CTL_ENTRY(CTL_DEBUG_TAG,        debug_tag),
23609 +       CTL_ENTRY(CTL_DEBUG_NET,        debug_net),
23610 +       CTL_ENTRY(CTL_DEBUG_LIMIT,      debug_limit),
23611 +       CTL_ENTRY(CTL_DEBUG_CRES,       debug_cres),
23612 +       CTL_ENTRY(CTL_DEBUG_DLIM,       debug_dlim),
23613 +       CTL_ENTRY(CTL_DEBUG_QUOTA,      debug_quota),
23614 +       CTL_ENTRY(CTL_DEBUG_CVIRT,      debug_cvirt),
23615 +       CTL_ENTRY(CTL_DEBUG_SPACE,      debug_space),
23616 +       CTL_ENTRY(CTL_DEBUG_PERM,       debug_perm),
23617 +       CTL_ENTRY(CTL_DEBUG_MISC,       debug_misc),
23618 +       { 0 }
23619 +};
23620 +
23621 +static ctl_table vserver_root_table[] = {
23622 +       {
23623 +               .procname       = "vserver",
23624 +               .mode           = 0555,
23625 +               .child          = vserver_debug_table
23626 +       },
23627 +       { 0 }
23628 +};
23629 +
23630 +
23631 +static match_table_t tokens = {
23632 +       { CTL_DEBUG_SWITCH,     "switch=%x"     },
23633 +       { CTL_DEBUG_XID,        "xid=%x"        },
23634 +       { CTL_DEBUG_NID,        "nid=%x"        },
23635 +       { CTL_DEBUG_TAG,        "tag=%x"        },
23636 +       { CTL_DEBUG_NET,        "net=%x"        },
23637 +       { CTL_DEBUG_LIMIT,      "limit=%x"      },
23638 +       { CTL_DEBUG_CRES,       "cres=%x"       },
23639 +       { CTL_DEBUG_DLIM,       "dlim=%x"       },
23640 +       { CTL_DEBUG_QUOTA,      "quota=%x"      },
23641 +       { CTL_DEBUG_CVIRT,      "cvirt=%x"      },
23642 +       { CTL_DEBUG_SPACE,      "space=%x"      },
23643 +       { CTL_DEBUG_PERM,       "perm=%x"       },
23644 +       { CTL_DEBUG_MISC,       "misc=%x"       },
23645 +       { CTL_DEBUG_ERROR,      NULL            }
23646 +};
23647 +
23648 +#define        HANDLE_CASE(id, name, val)                              \
23649 +       case CTL_DEBUG_ ## id:                                  \
23650 +               vs_debug_ ## name = val;                        \
23651 +               printk("vs_debug_" #name "=0x%x\n", val);       \
23652 +               break
23653 +
23654 +
23655 +static int __init vs_debug_setup(char *str)
23656 +{
23657 +       char *p;
23658 +       int token;
23659 +
23660 +       printk("vs_debug_setup(%s)\n", str);
23661 +       while ((p = strsep(&str, ",")) != NULL) {
23662 +               substring_t args[MAX_OPT_ARGS];
23663 +               unsigned int value;
23664 +
23665 +               if (!*p)
23666 +                       continue;
23667 +
23668 +               token = match_token(p, tokens, args);
23669 +               value = (token > 0) ? simple_strtoul(args[0].from, NULL, 0) : 0;
23670 +
23671 +               switch (token) {
23672 +               HANDLE_CASE(SWITCH, switch, value);
23673 +               HANDLE_CASE(XID,    xid,    value);
23674 +               HANDLE_CASE(NID,    nid,    value);
23675 +               HANDLE_CASE(TAG,    tag,    value);
23676 +               HANDLE_CASE(NET,    net,    value);
23677 +               HANDLE_CASE(LIMIT,  limit,  value);
23678 +               HANDLE_CASE(CRES,   cres,   value);
23679 +               HANDLE_CASE(DLIM,   dlim,   value);
23680 +               HANDLE_CASE(QUOTA,  quota,  value);
23681 +               HANDLE_CASE(CVIRT,  cvirt,  value);
23682 +               HANDLE_CASE(SPACE,  space,  value);
23683 +               HANDLE_CASE(PERM,   perm,   value);
23684 +               HANDLE_CASE(MISC,   misc,   value);
23685 +               default:
23686 +                       return -EINVAL;
23687 +                       break;
23688 +               }
23689 +       }
23690 +       return 1;
23691 +}
23692 +
23693 +__setup("vsdebug=", vs_debug_setup);
23694 +
23695 +
23696 +
23697 +EXPORT_SYMBOL_GPL(vs_debug_switch);
23698 +EXPORT_SYMBOL_GPL(vs_debug_xid);
23699 +EXPORT_SYMBOL_GPL(vs_debug_nid);
23700 +EXPORT_SYMBOL_GPL(vs_debug_net);
23701 +EXPORT_SYMBOL_GPL(vs_debug_limit);
23702 +EXPORT_SYMBOL_GPL(vs_debug_cres);
23703 +EXPORT_SYMBOL_GPL(vs_debug_dlim);
23704 +EXPORT_SYMBOL_GPL(vs_debug_quota);
23705 +EXPORT_SYMBOL_GPL(vs_debug_cvirt);
23706 +EXPORT_SYMBOL_GPL(vs_debug_space);
23707 +EXPORT_SYMBOL_GPL(vs_debug_perm);
23708 +EXPORT_SYMBOL_GPL(vs_debug_misc);
23709 +
23710 diff -NurpP --minimal linux-3.6.10/kernel/vserver/tag.c linux-3.6.10-vs2.3.4.5/kernel/vserver/tag.c
23711 --- linux-3.6.10/kernel/vserver/tag.c   1970-01-01 01:00:00.000000000 +0100
23712 +++ linux-3.6.10-vs2.3.4.5/kernel/vserver/tag.c 2012-10-04 18:47:00.000000000 +0200
23713 @@ -0,0 +1,63 @@
23714 +/*
23715 + *  linux/kernel/vserver/tag.c
23716 + *
23717 + *  Virtual Server: Shallow Tag Space
23718 + *
23719 + *  Copyright (C) 2007  Herbert Pötzl
23720 + *
23721 + *  V0.01  basic implementation
23722 + *
23723 + */
23724 +
23725 +#include <linux/sched.h>
23726 +#include <linux/vserver/debug.h>
23727 +#include <linux/vs_pid.h>
23728 +#include <linux/vs_tag.h>
23729 +
23730 +#include <linux/vserver/tag_cmd.h>
23731 +
23732 +
23733 +int dx_migrate_task(struct task_struct *p, tag_t tag)
23734 +{
23735 +       if (!p)
23736 +               BUG();
23737 +
23738 +       vxdprintk(VXD_CBIT(tag, 5),
23739 +               "dx_migrate_task(%p[#%d],#%d)", p, p->tag, tag);
23740 +
23741 +       task_lock(p);
23742 +       p->tag = tag;
23743 +       task_unlock(p);
23744 +
23745 +       vxdprintk(VXD_CBIT(tag, 5),
23746 +               "moved task %p into [#%d]", p, tag);
23747 +       return 0;
23748 +}
23749 +
23750 +/* vserver syscall commands below here */
23751 +
23752 +/* taks xid and vx_info functions */
23753 +
23754 +
23755 +int vc_task_tag(uint32_t id)
23756 +{
23757 +       tag_t tag;
23758 +
23759 +       if (id) {
23760 +               struct task_struct *tsk;
23761 +               rcu_read_lock();
23762 +               tsk = find_task_by_real_pid(id);
23763 +               tag = (tsk) ? tsk->tag : -ESRCH;
23764 +               rcu_read_unlock();
23765 +       } else
23766 +               tag = dx_current_tag();
23767 +       return tag;
23768 +}
23769 +
23770 +
23771 +int vc_tag_migrate(uint32_t tag)
23772 +{
23773 +       return dx_migrate_task(current, tag & 0xFFFF);
23774 +}
23775 +
23776 +
23777 diff -NurpP --minimal linux-3.6.10/kernel/vserver/vci_config.h linux-3.6.10-vs2.3.4.5/kernel/vserver/vci_config.h
23778 --- linux-3.6.10/kernel/vserver/vci_config.h    1970-01-01 01:00:00.000000000 +0100
23779 +++ linux-3.6.10-vs2.3.4.5/kernel/vserver/vci_config.h  2012-10-04 18:47:00.000000000 +0200
23780 @@ -0,0 +1,76 @@
23781 +
23782 +/*  interface version */
23783 +
23784 +#define VCI_VERSION            0x00020308
23785 +
23786 +
23787 +enum {
23788 +       VCI_KCBIT_NO_DYNAMIC = 0,
23789 +
23790 +       VCI_KCBIT_PROC_SECURE = 4,
23791 +       /* VCI_KCBIT_HARDCPU = 5, */
23792 +       /* VCI_KCBIT_IDLELIMIT = 6, */
23793 +       /* VCI_KCBIT_IDLETIME = 7, */
23794 +
23795 +       VCI_KCBIT_COWBL = 8,
23796 +       VCI_KCBIT_FULLCOWBL = 9,
23797 +       VCI_KCBIT_SPACES = 10,
23798 +       VCI_KCBIT_NETV2 = 11,
23799 +       VCI_KCBIT_MEMCG = 12,
23800 +
23801 +       VCI_KCBIT_DEBUG = 16,
23802 +       VCI_KCBIT_HISTORY = 20,
23803 +       VCI_KCBIT_TAGGED = 24,
23804 +       VCI_KCBIT_PPTAG = 28,
23805 +
23806 +       VCI_KCBIT_MORE = 31,
23807 +};
23808 +
23809 +
23810 +static inline uint32_t vci_kernel_config(void)
23811 +{
23812 +       return
23813 +       (1 << VCI_KCBIT_NO_DYNAMIC) |
23814 +
23815 +       /* configured features */
23816 +#ifdef CONFIG_VSERVER_PROC_SECURE
23817 +       (1 << VCI_KCBIT_PROC_SECURE) |
23818 +#endif
23819 +#ifdef CONFIG_VSERVER_COWBL
23820 +       (1 << VCI_KCBIT_COWBL) |
23821 +       (1 << VCI_KCBIT_FULLCOWBL) |
23822 +#endif
23823 +       (1 << VCI_KCBIT_SPACES) |
23824 +       (1 << VCI_KCBIT_NETV2) |
23825 +#ifdef CONFIG_CGROUP_MEM_RES_CTLR
23826 +       (1 << VCI_KCBIT_MEMCG) |
23827 +#endif
23828 +
23829 +       /* debug options */
23830 +#ifdef CONFIG_VSERVER_DEBUG
23831 +       (1 << VCI_KCBIT_DEBUG) |
23832 +#endif
23833 +#ifdef CONFIG_VSERVER_HISTORY
23834 +       (1 << VCI_KCBIT_HISTORY) |
23835 +#endif
23836 +
23837 +       /* inode context tagging */
23838 +#if    defined(CONFIG_TAGGING_NONE)
23839 +       (0 << VCI_KCBIT_TAGGED) |
23840 +#elif  defined(CONFIG_TAGGING_UID16)
23841 +       (1 << VCI_KCBIT_TAGGED) |
23842 +#elif  defined(CONFIG_TAGGING_GID16)
23843 +       (2 << VCI_KCBIT_TAGGED) |
23844 +#elif  defined(CONFIG_TAGGING_ID24)
23845 +       (3 << VCI_KCBIT_TAGGED) |
23846 +#elif  defined(CONFIG_TAGGING_INTERN)
23847 +       (4 << VCI_KCBIT_TAGGED) |
23848 +#elif  defined(CONFIG_TAGGING_RUNTIME)
23849 +       (5 << VCI_KCBIT_TAGGED) |
23850 +#else
23851 +       (7 << VCI_KCBIT_TAGGED) |
23852 +#endif
23853 +       (1 << VCI_KCBIT_PPTAG) |
23854 +       0;
23855 +}
23856 +
23857 diff -NurpP --minimal linux-3.6.10/mm/memcontrol.c linux-3.6.10-vs2.3.4.5/mm/memcontrol.c
23858 --- linux-3.6.10/mm/memcontrol.c        2012-12-11 12:37:02.000000000 +0100
23859 +++ linux-3.6.10-vs2.3.4.5/mm/memcontrol.c      2012-12-08 01:36:33.000000000 +0100
23860 @@ -885,6 +885,31 @@ struct mem_cgroup *mem_cgroup_from_task(
23861         return mem_cgroup_from_css(task_subsys_state(p, mem_cgroup_subsys_id));
23862  }
23863  
23864 +u64 mem_cgroup_res_read_u64(struct mem_cgroup *mem, int member)
23865 +{
23866 +       return res_counter_read_u64(&mem->res, member);
23867 +}
23868 +
23869 +u64 mem_cgroup_memsw_read_u64(struct mem_cgroup *mem, int member)
23870 +{
23871 +       return res_counter_read_u64(&mem->memsw, member);
23872 +}
23873 +
23874 +s64 mem_cgroup_stat_read_cache(struct mem_cgroup *mem)
23875 +{
23876 +       return mem_cgroup_read_stat(mem, MEM_CGROUP_STAT_CACHE);
23877 +}
23878 +
23879 +s64 mem_cgroup_stat_read_anon(struct mem_cgroup *mem)
23880 +{
23881 +       return mem_cgroup_read_stat(mem, MEM_CGROUP_STAT_RSS);
23882 +}
23883 +
23884 +s64 mem_cgroup_stat_read_mapped(struct mem_cgroup *mem)
23885 +{
23886 +       return mem_cgroup_read_stat(mem, MEM_CGROUP_STAT_FILE_MAPPED);
23887 +}
23888 +
23889  struct mem_cgroup *try_get_mem_cgroup_from_mm(struct mm_struct *mm)
23890  {
23891         struct mem_cgroup *memcg = NULL;
23892 diff -NurpP --minimal linux-3.6.10/mm/oom_kill.c linux-3.6.10-vs2.3.4.5/mm/oom_kill.c
23893 --- linux-3.6.10/mm/oom_kill.c  2012-10-04 15:27:48.000000000 +0200
23894 +++ linux-3.6.10-vs2.3.4.5/mm/oom_kill.c        2012-10-04 18:53:46.000000000 +0200
23895 @@ -35,6 +35,8 @@
23896  #include <linux/freezer.h>
23897  #include <linux/ftrace.h>
23898  #include <linux/ratelimit.h>
23899 +#include <linux/reboot.h>
23900 +#include <linux/vs_context.h>
23901  
23902  #define CREATE_TRACE_POINTS
23903  #include <trace/events/oom.h>
23904 @@ -155,11 +157,18 @@ struct task_struct *find_lock_task_mm(st
23905  static bool oom_unkillable_task(struct task_struct *p,
23906                 const struct mem_cgroup *memcg, const nodemask_t *nodemask)
23907  {
23908 -       if (is_global_init(p))
23909 +       unsigned xid = vx_current_xid();
23910 +
23911 +       /* skip the init task, global and per guest */
23912 +       if (task_is_init(p))
23913                 return true;
23914         if (p->flags & PF_KTHREAD)
23915                 return true;
23916  
23917 +       /* skip other guest and host processes if oom in guest */
23918 +       if (xid && vx_task_xid(p) != xid)
23919 +               return true;
23920 +
23921         /* When mem_cgroup_out_of_memory() and p is not member of the group */
23922         if (memcg && !task_in_mem_cgroup(p, memcg))
23923                 return true;
23924 @@ -472,8 +481,8 @@ void oom_kill_process(struct task_struct
23925                 dump_header(p, gfp_mask, order, memcg, nodemask);
23926  
23927         task_lock(p);
23928 -       pr_err("%s: Kill process %d (%s) score %d or sacrifice child\n",
23929 -               message, task_pid_nr(p), p->comm, points);
23930 +       pr_err("%s: Kill process %d:#%u (%s) score %d or sacrifice child\n",
23931 +               message, task_pid_nr(p), p->xid, p->comm, points);
23932         task_unlock(p);
23933  
23934         /*
23935 @@ -518,8 +527,8 @@ void oom_kill_process(struct task_struct
23936  
23937         /* mm cannot safely be dereferenced after task_unlock(victim) */
23938         mm = victim->mm;
23939 -       pr_err("Killed process %d (%s) total-vm:%lukB, anon-rss:%lukB, file-rss:%lukB\n",
23940 -               task_pid_nr(victim), victim->comm, K(victim->mm->total_vm),
23941 +       pr_err("Killed process %d:#%u (%s) total-vm:%lukB, anon-rss:%lukB, file-rss:%lukB\n",
23942 +               task_pid_nr(victim), victim->xid, victim->comm, K(victim->mm->total_vm),
23943                 K(get_mm_counter(victim->mm, MM_ANONPAGES)),
23944                 K(get_mm_counter(victim->mm, MM_FILEPAGES)));
23945         task_unlock(victim);
23946 @@ -589,6 +598,8 @@ int unregister_oom_notifier(struct notif
23947  }
23948  EXPORT_SYMBOL_GPL(unregister_oom_notifier);
23949  
23950 +long vs_oom_action(unsigned int);
23951 +
23952  /*
23953   * Try to acquire the OOM killer lock for the zones in zonelist.  Returns zero
23954   * if a parallel OOM killing is already taking place that includes a zone in
23955 @@ -738,7 +749,12 @@ void out_of_memory(struct zonelist *zone
23956         /* Found nothing?!?! Either we hang forever, or we panic. */
23957         if (!p) {
23958                 dump_header(NULL, gfp_mask, order, NULL, mpol_mask);
23959 -               panic("Out of memory and no killable processes...\n");
23960 +
23961 +               /* avoid panic for guest OOM */
23962 +               if (current->xid)
23963 +                       vs_oom_action(LINUX_REBOOT_CMD_OOM);
23964 +               else
23965 +                       panic("Out of memory and no killable processes...\n");
23966         }
23967         if (PTR_ERR(p) != -1UL) {
23968                 oom_kill_process(p, gfp_mask, order, points, totalpages, NULL,
23969 diff -NurpP --minimal linux-3.6.10/mm/page_alloc.c linux-3.6.10-vs2.3.4.5/mm/page_alloc.c
23970 --- linux-3.6.10/mm/page_alloc.c        2012-12-11 12:37:02.000000000 +0100
23971 +++ linux-3.6.10-vs2.3.4.5/mm/page_alloc.c      2012-12-08 01:36:33.000000000 +0100
23972 @@ -58,6 +58,8 @@
23973  #include <linux/prefetch.h>
23974  #include <linux/migrate.h>
23975  #include <linux/page-debug-flags.h>
23976 +#include <linux/vs_base.h>
23977 +#include <linux/vs_limit.h>
23978  
23979  #include <asm/tlbflush.h>
23980  #include <asm/div64.h>
23981 @@ -2773,6 +2775,9 @@ void si_meminfo(struct sysinfo *val)
23982         val->totalhigh = totalhigh_pages;
23983         val->freehigh = nr_free_highpages();
23984         val->mem_unit = PAGE_SIZE;
23985 +
23986 +       if (vx_flags(VXF_VIRT_MEM, 0))
23987 +               vx_vsi_meminfo(val);
23988  }
23989  
23990  EXPORT_SYMBOL(si_meminfo);
23991 @@ -2793,6 +2798,9 @@ void si_meminfo_node(struct sysinfo *val
23992         val->freehigh = 0;
23993  #endif
23994         val->mem_unit = PAGE_SIZE;
23995 +
23996 +       if (vx_flags(VXF_VIRT_MEM, 0))
23997 +               vx_vsi_meminfo(val);
23998  }
23999  #endif
24000  
24001 diff -NurpP --minimal linux-3.6.10/mm/pgtable-generic.c linux-3.6.10-vs2.3.4.5/mm/pgtable-generic.c
24002 --- linux-3.6.10/mm/pgtable-generic.c   2012-07-22 23:39:47.000000000 +0200
24003 +++ linux-3.6.10-vs2.3.4.5/mm/pgtable-generic.c 2012-10-04 18:47:00.000000000 +0200
24004 @@ -6,6 +6,8 @@
24005   *  Copyright (C) 2010  Linus Torvalds
24006   */
24007  
24008 +#include <linux/mm.h>
24009 +
24010  #include <linux/pagemap.h>
24011  #include <asm/tlb.h>
24012  #include <asm-generic/pgtable.h>
24013 diff -NurpP --minimal linux-3.6.10/mm/shmem.c linux-3.6.10-vs2.3.4.5/mm/shmem.c
24014 --- linux-3.6.10/mm/shmem.c     2012-12-11 12:37:02.000000000 +0100
24015 +++ linux-3.6.10-vs2.3.4.5/mm/shmem.c   2012-12-08 01:36:33.000000000 +0100
24016 @@ -1826,7 +1826,7 @@ static int shmem_statfs(struct dentry *d
24017  {
24018         struct shmem_sb_info *sbinfo = SHMEM_SB(dentry->d_sb);
24019  
24020 -       buf->f_type = TMPFS_MAGIC;
24021 +       buf->f_type = TMPFS_SUPER_MAGIC;
24022         buf->f_bsize = PAGE_CACHE_SIZE;
24023         buf->f_namelen = NAME_MAX;
24024         if (sbinfo->max_blocks) {
24025 @@ -2644,7 +2644,7 @@ int shmem_fill_super(struct super_block 
24026         sb->s_maxbytes = MAX_LFS_FILESIZE;
24027         sb->s_blocksize = PAGE_CACHE_SIZE;
24028         sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
24029 -       sb->s_magic = TMPFS_MAGIC;
24030 +       sb->s_magic = TMPFS_SUPER_MAGIC;
24031         sb->s_op = &shmem_ops;
24032         sb->s_time_gran = 1;
24033  #ifdef CONFIG_TMPFS_XATTR
24034 diff -NurpP --minimal linux-3.6.10/mm/slab.c linux-3.6.10-vs2.3.4.5/mm/slab.c
24035 --- linux-3.6.10/mm/slab.c      2012-12-11 12:37:03.000000000 +0100
24036 +++ linux-3.6.10-vs2.3.4.5/mm/slab.c    2012-11-06 18:43:41.000000000 +0100
24037 @@ -445,6 +445,8 @@ static void kmem_list3_init(struct kmem_
24038  #define STATS_INC_FREEMISS(x)  do { } while (0)
24039  #endif
24040  
24041 +#include "slab_vs.h"
24042 +
24043  #if DEBUG
24044  
24045  /*
24046 @@ -3539,6 +3541,7 @@ retry:
24047  
24048         obj = slab_get_obj(cachep, slabp, nodeid);
24049         check_slabp(cachep, slabp);
24050 +       vx_slab_alloc(cachep, flags);
24051         l3->free_objects--;
24052         /* move slabp to correct slabp list: */
24053         list_del(&slabp->list);
24054 @@ -3616,6 +3619,7 @@ __cache_alloc_node(struct kmem_cache *ca
24055         /* ___cache_alloc_node can fall back to other nodes */
24056         ptr = ____cache_alloc_node(cachep, flags, nodeid);
24057    out:
24058 +       vx_slab_alloc(cachep, flags);
24059         local_irq_restore(save_flags);
24060         ptr = cache_alloc_debugcheck_after(cachep, flags, ptr, caller);
24061         kmemleak_alloc_recursive(ptr, cachep->object_size, 1, cachep->flags,
24062 @@ -3806,6 +3810,7 @@ static inline void __cache_free(struct k
24063         check_irq_off();
24064         kmemleak_free_recursive(objp, cachep->flags);
24065         objp = cache_free_debugcheck(cachep, objp, caller);
24066 +       vx_slab_free(cachep);
24067  
24068         kmemcheck_slab_free(cachep, objp, cachep->object_size);
24069  
24070 diff -NurpP --minimal linux-3.6.10/mm/slab_vs.h linux-3.6.10-vs2.3.4.5/mm/slab_vs.h
24071 --- linux-3.6.10/mm/slab_vs.h   1970-01-01 01:00:00.000000000 +0100
24072 +++ linux-3.6.10-vs2.3.4.5/mm/slab_vs.h 2012-10-09 16:28:11.000000000 +0200
24073 @@ -0,0 +1,29 @@
24074 +
24075 +#include <linux/vserver/context.h>
24076 +
24077 +#include <linux/vs_context.h>
24078 +
24079 +static inline
24080 +void vx_slab_alloc(struct kmem_cache *cachep, gfp_t flags)
24081 +{
24082 +       int what = gfp_zone(cachep->allocflags);
24083 +       struct vx_info *vxi = current_vx_info();
24084 +
24085 +       if (!vxi)
24086 +               return;
24087 +
24088 +       atomic_add(cachep->size, &vxi->cacct.slab[what]);
24089 +}
24090 +
24091 +static inline
24092 +void vx_slab_free(struct kmem_cache *cachep)
24093 +{
24094 +       int what = gfp_zone(cachep->allocflags);
24095 +       struct vx_info *vxi = current_vx_info();
24096 +
24097 +       if (!vxi)
24098 +               return;
24099 +
24100 +       atomic_sub(cachep->size, &vxi->cacct.slab[what]);
24101 +}
24102 +
24103 diff -NurpP --minimal linux-3.6.10/mm/swapfile.c linux-3.6.10-vs2.3.4.5/mm/swapfile.c
24104 --- linux-3.6.10/mm/swapfile.c  2012-10-04 15:27:48.000000000 +0200
24105 +++ linux-3.6.10-vs2.3.4.5/mm/swapfile.c        2012-10-04 18:47:00.000000000 +0200
24106 @@ -39,6 +39,7 @@
24107  #include <asm/tlbflush.h>
24108  #include <linux/swapops.h>
24109  #include <linux/page_cgroup.h>
24110 +#include <linux/vs_base.h>
24111  
24112  static bool swap_count_continued(struct swap_info_struct *, pgoff_t,
24113                                  unsigned char);
24114 @@ -1686,6 +1687,16 @@ static int swap_show(struct seq_file *sw
24115  
24116         if (si == SEQ_START_TOKEN) {
24117                 seq_puts(swap,"Filename\t\t\t\tType\t\tSize\tUsed\tPriority\n");
24118 +               if (vx_flags(VXF_VIRT_MEM, 0)) {
24119 +                       struct sysinfo si;
24120 +
24121 +                       vx_vsi_swapinfo(&si);
24122 +                       if (si.totalswap < (1 << 10))
24123 +                               return 0;
24124 +                       seq_printf(swap, "%s\t\t\t\t\t%s\t%lu\t%lu\t%d\n",
24125 +                               "hdv0", "partition", si.totalswap >> 10,
24126 +                               (si.totalswap - si.freeswap) >> 10, -1);
24127 +               }
24128                 return 0;
24129         }
24130  
24131 @@ -2113,6 +2124,8 @@ void si_swapinfo(struct sysinfo *val)
24132         val->freeswap = nr_swap_pages + nr_to_be_unused;
24133         val->totalswap = total_swap_pages + nr_to_be_unused;
24134         spin_unlock(&swap_lock);
24135 +       if (vx_flags(VXF_VIRT_MEM, 0))
24136 +               vx_vsi_swapinfo(val);
24137  }
24138  
24139  /*
24140 diff -NurpP --minimal linux-3.6.10/net/bridge/br_multicast.c linux-3.6.10-vs2.3.4.5/net/bridge/br_multicast.c
24141 --- linux-3.6.10/net/bridge/br_multicast.c      2012-10-04 15:27:49.000000000 +0200
24142 +++ linux-3.6.10-vs2.3.4.5/net/bridge/br_multicast.c    2012-10-04 18:47:00.000000000 +0200
24143 @@ -447,7 +447,7 @@ static struct sk_buff *br_ip6_multicast_
24144         ip6h->hop_limit = 1;
24145         ipv6_addr_set(&ip6h->daddr, htonl(0xff020000), 0, 0, htonl(1));
24146         if (ipv6_dev_get_saddr(dev_net(br->dev), br->dev, &ip6h->daddr, 0,
24147 -                              &ip6h->saddr)) {
24148 +                              &ip6h->saddr, NULL)) {
24149                 kfree_skb(skb);
24150                 return NULL;
24151         }
24152 diff -NurpP --minimal linux-3.6.10/net/core/dev.c linux-3.6.10-vs2.3.4.5/net/core/dev.c
24153 --- linux-3.6.10/net/core/dev.c 2012-12-11 12:37:03.000000000 +0100
24154 +++ linux-3.6.10-vs2.3.4.5/net/core/dev.c       2012-12-08 01:36:33.000000000 +0100
24155 @@ -126,6 +126,7 @@
24156  #include <linux/in.h>
24157  #include <linux/jhash.h>
24158  #include <linux/random.h>
24159 +#include <linux/vs_inet.h>
24160  #include <trace/events/napi.h>
24161  #include <trace/events/net.h>
24162  #include <trace/events/skb.h>
24163 @@ -620,7 +621,8 @@ struct net_device *__dev_get_by_name(str
24164         struct hlist_head *head = dev_name_hash(net, name);
24165  
24166         hlist_for_each_entry(dev, p, head, name_hlist)
24167 -               if (!strncmp(dev->name, name, IFNAMSIZ))
24168 +               if (!strncmp(dev->name, name, IFNAMSIZ) &&
24169 +                   nx_dev_visible(current_nx_info(), dev))
24170                         return dev;
24171  
24172         return NULL;
24173 @@ -646,7 +648,8 @@ struct net_device *dev_get_by_name_rcu(s
24174         struct hlist_head *head = dev_name_hash(net, name);
24175  
24176         hlist_for_each_entry_rcu(dev, p, head, name_hlist)
24177 -               if (!strncmp(dev->name, name, IFNAMSIZ))
24178 +               if (!strncmp(dev->name, name, IFNAMSIZ) &&
24179 +                   nx_dev_visible(current_nx_info(), dev))
24180                         return dev;
24181  
24182         return NULL;
24183 @@ -697,7 +700,8 @@ struct net_device *__dev_get_by_index(st
24184         struct hlist_head *head = dev_index_hash(net, ifindex);
24185  
24186         hlist_for_each_entry(dev, p, head, index_hlist)
24187 -               if (dev->ifindex == ifindex)
24188 +               if ((dev->ifindex == ifindex) &&
24189 +                   nx_dev_visible(current_nx_info(), dev))
24190                         return dev;
24191  
24192         return NULL;
24193 @@ -715,7 +719,7 @@ EXPORT_SYMBOL(__dev_get_by_index);
24194   *     about locking. The caller must hold RCU lock.
24195   */
24196  
24197 -struct net_device *dev_get_by_index_rcu(struct net *net, int ifindex)
24198 +struct net_device *dev_get_by_index_real_rcu(struct net *net, int ifindex)
24199  {
24200         struct hlist_node *p;
24201         struct net_device *dev;
24202 @@ -727,6 +731,16 @@ struct net_device *dev_get_by_index_rcu(
24203  
24204         return NULL;
24205  }
24206 +EXPORT_SYMBOL(dev_get_by_index_real_rcu);
24207 +
24208 +struct net_device *dev_get_by_index_rcu(struct net *net, int ifindex)
24209 +{
24210 +       struct net_device *dev = dev_get_by_index_real_rcu(net, ifindex);
24211 +
24212 +       if (nx_dev_visible(current_nx_info(), dev))
24213 +               return dev;
24214 +       return NULL;
24215 +}
24216  EXPORT_SYMBOL(dev_get_by_index_rcu);
24217  
24218  
24219 @@ -775,7 +789,8 @@ struct net_device *dev_getbyhwaddr_rcu(s
24220  
24221         for_each_netdev_rcu(net, dev)
24222                 if (dev->type == type &&
24223 -                   !memcmp(dev->dev_addr, ha, dev->addr_len))
24224 +                   !memcmp(dev->dev_addr, ha, dev->addr_len) &&
24225 +                   nx_dev_visible(current_nx_info(), dev))
24226                         return dev;
24227  
24228         return NULL;
24229 @@ -787,9 +802,11 @@ struct net_device *__dev_getfirstbyhwtyp
24230         struct net_device *dev;
24231  
24232         ASSERT_RTNL();
24233 -       for_each_netdev(net, dev)
24234 -               if (dev->type == type)
24235 +       for_each_netdev(net, dev) {
24236 +               if ((dev->type == type) &&
24237 +                   nx_dev_visible(current_nx_info(), dev))
24238                         return dev;
24239 +       }
24240  
24241         return NULL;
24242  }
24243 @@ -907,6 +924,8 @@ static int __dev_alloc_name(struct net *
24244                                 continue;
24245                         if (i < 0 || i >= max_netdevices)
24246                                 continue;
24247 +                       if (!nx_dev_visible(current_nx_info(), d))
24248 +                               continue;
24249  
24250                         /*  avoid cases where sscanf is not exact inverse of printf */
24251                         snprintf(buf, IFNAMSIZ, name, i);
24252 @@ -4076,6 +4095,8 @@ static int dev_ifconf(struct net *net, c
24253  
24254         total = 0;
24255         for_each_netdev(net, dev) {
24256 +               if (!nx_dev_visible(current_nx_info(), dev))
24257 +                       continue;
24258                 for (i = 0; i < NPROTO; i++) {
24259                         if (gifconf_list[i]) {
24260                                 int done;
24261 @@ -4178,6 +4199,10 @@ static void dev_seq_printf_stats(struct 
24262         struct rtnl_link_stats64 temp;
24263         const struct rtnl_link_stats64 *stats = dev_get_stats(dev, &temp);
24264  
24265 +       /* device visible inside network context? */
24266 +       if (!nx_dev_visible(current_nx_info(), dev))
24267 +               return;
24268 +
24269         seq_printf(seq, "%6s: %7llu %7llu %4llu %4llu %4llu %5llu %10llu %9llu "
24270                    "%8llu %7llu %4llu %4llu %4llu %5llu %7llu %10llu\n",
24271                    dev->name, stats->rx_bytes, stats->rx_packets,
24272 diff -NurpP --minimal linux-3.6.10/net/core/rtnetlink.c linux-3.6.10-vs2.3.4.5/net/core/rtnetlink.c
24273 --- linux-3.6.10/net/core/rtnetlink.c   2012-10-04 15:27:49.000000000 +0200
24274 +++ linux-3.6.10-vs2.3.4.5/net/core/rtnetlink.c 2012-10-04 18:47:00.000000000 +0200
24275 @@ -1080,6 +1080,8 @@ static int rtnl_dump_ifinfo(struct sk_bu
24276                 hlist_for_each_entry_rcu(dev, node, head, index_hlist) {
24277                         if (idx < s_idx)
24278                                 goto cont;
24279 +                       if (!nx_dev_visible(skb->sk->sk_nx_info, dev))
24280 +                               continue;
24281                         if (rtnl_fill_ifinfo(skb, dev, RTM_NEWLINK,
24282                                              NETLINK_CB(cb->skb).pid,
24283                                              cb->nlh->nlmsg_seq, 0,
24284 @@ -1969,6 +1971,9 @@ void rtmsg_ifinfo(int type, struct net_d
24285         int err = -ENOBUFS;
24286         size_t if_info_size;
24287  
24288 +       if (!nx_dev_visible(current_nx_info(), dev))
24289 +               return;
24290 +
24291         skb = nlmsg_new((if_info_size = if_nlmsg_size(dev, 0)), GFP_KERNEL);
24292         if (skb == NULL)
24293                 goto errout;
24294 diff -NurpP --minimal linux-3.6.10/net/core/sock.c linux-3.6.10-vs2.3.4.5/net/core/sock.c
24295 --- linux-3.6.10/net/core/sock.c        2012-10-04 15:27:49.000000000 +0200
24296 +++ linux-3.6.10-vs2.3.4.5/net/core/sock.c      2012-10-04 18:47:00.000000000 +0200
24297 @@ -132,6 +132,10 @@
24298  #include <net/netprio_cgroup.h>
24299  
24300  #include <linux/filter.h>
24301 +#include <linux/vs_socket.h>
24302 +#include <linux/vs_limit.h>
24303 +#include <linux/vs_context.h>
24304 +#include <linux/vs_network.h>
24305  
24306  #include <trace/events/sock.h>
24307  
24308 @@ -1194,6 +1198,8 @@ static struct sock *sk_prot_alloc(struct
24309                         goto out_free_sec;
24310                 sk_tx_queue_clear(sk);
24311         }
24312 +               sock_vx_init(sk);
24313 +               sock_nx_init(sk);
24314  
24315         return sk;
24316  
24317 @@ -1302,6 +1308,11 @@ static void __sk_free(struct sock *sk)
24318                 put_cred(sk->sk_peer_cred);
24319         put_pid(sk->sk_peer_pid);
24320         put_net(sock_net(sk));
24321 +       vx_sock_dec(sk);
24322 +       clr_vx_info(&sk->sk_vx_info);
24323 +       sk->sk_xid = -1;
24324 +       clr_nx_info(&sk->sk_nx_info);
24325 +       sk->sk_nid = -1;
24326         sk_prot_free(sk->sk_prot_creator, sk);
24327  }
24328  
24329 @@ -1362,6 +1373,8 @@ struct sock *sk_clone_lock(const struct 
24330  
24331                 /* SANITY */
24332                 get_net(sock_net(newsk));
24333 +               sock_vx_init(newsk);
24334 +               sock_nx_init(newsk);
24335                 sk_node_init(&newsk->sk_node);
24336                 sock_lock_init(newsk);
24337                 bh_lock_sock(newsk);
24338 @@ -1418,6 +1431,12 @@ struct sock *sk_clone_lock(const struct 
24339                 smp_wmb();
24340                 atomic_set(&newsk->sk_refcnt, 2);
24341  
24342 +               set_vx_info(&newsk->sk_vx_info, sk->sk_vx_info);
24343 +               newsk->sk_xid = sk->sk_xid;
24344 +               vx_sock_inc(newsk);
24345 +               set_nx_info(&newsk->sk_nx_info, sk->sk_nx_info);
24346 +               newsk->sk_nid = sk->sk_nid;
24347 +
24348                 /*
24349                  * Increment the counter in the same struct proto as the master
24350                  * sock (sk_refcnt_debug_inc uses newsk->sk_prot->socks, that
24351 @@ -2187,6 +2206,12 @@ void sock_init_data(struct socket *sock,
24352  
24353         sk->sk_stamp = ktime_set(-1L, 0);
24354  
24355 +       set_vx_info(&sk->sk_vx_info, current_vx_info());
24356 +       sk->sk_xid = vx_current_xid();
24357 +       vx_sock_inc(sk);
24358 +       set_nx_info(&sk->sk_nx_info, current_nx_info());
24359 +       sk->sk_nid = nx_current_nid();
24360 +
24361         /*
24362          * Before updating sk_refcnt, we must commit prior changes to memory
24363          * (Documentation/RCU/rculist_nulls.txt for details)
24364 diff -NurpP --minimal linux-3.6.10/net/ipv4/af_inet.c linux-3.6.10-vs2.3.4.5/net/ipv4/af_inet.c
24365 --- linux-3.6.10/net/ipv4/af_inet.c     2012-10-04 15:27:49.000000000 +0200
24366 +++ linux-3.6.10-vs2.3.4.5/net/ipv4/af_inet.c   2012-10-04 18:47:00.000000000 +0200
24367 @@ -118,6 +118,7 @@
24368  #ifdef CONFIG_IP_MROUTE
24369  #include <linux/mroute.h>
24370  #endif
24371 +#include <linux/vs_limit.h>
24372  
24373  
24374  /* The inetsw table contains everything that inet_create needs to
24375 @@ -326,9 +327,13 @@ lookup_protocol:
24376         }
24377  
24378         err = -EPERM;
24379 +       if ((protocol == IPPROTO_ICMP) &&
24380 +               nx_capable(CAP_NET_RAW, NXC_RAW_ICMP))
24381 +               goto override;
24382 +
24383         if (sock->type == SOCK_RAW && !kern && !capable(CAP_NET_RAW))
24384                 goto out_rcu_unlock;
24385 -
24386 +override:
24387         err = -EAFNOSUPPORT;
24388         if (!inet_netns_ok(net, protocol))
24389                 goto out_rcu_unlock;
24390 @@ -453,6 +458,7 @@ int inet_bind(struct socket *sock, struc
24391         struct sockaddr_in *addr = (struct sockaddr_in *)uaddr;
24392         struct sock *sk = sock->sk;
24393         struct inet_sock *inet = inet_sk(sk);
24394 +       struct nx_v4_sock_addr nsa;
24395         unsigned short snum;
24396         int chk_addr_ret;
24397         int err;
24398 @@ -476,7 +482,11 @@ int inet_bind(struct socket *sock, struc
24399                         goto out;
24400         }
24401  
24402 -       chk_addr_ret = inet_addr_type(sock_net(sk), addr->sin_addr.s_addr);
24403 +       err = v4_map_sock_addr(inet, addr, &nsa);
24404 +       if (err)
24405 +               goto out;
24406 +
24407 +       chk_addr_ret = inet_addr_type(sock_net(sk), nsa.saddr);
24408  
24409         /* Not specified by any standard per-se, however it breaks too
24410          * many applications when removed.  It is unfortunate since
24411 @@ -488,7 +498,7 @@ int inet_bind(struct socket *sock, struc
24412         err = -EADDRNOTAVAIL;
24413         if (!sysctl_ip_nonlocal_bind &&
24414             !(inet->freebind || inet->transparent) &&
24415 -           addr->sin_addr.s_addr != htonl(INADDR_ANY) &&
24416 +           nsa.saddr != htonl(INADDR_ANY) &&
24417             chk_addr_ret != RTN_LOCAL &&
24418             chk_addr_ret != RTN_MULTICAST &&
24419             chk_addr_ret != RTN_BROADCAST)
24420 @@ -513,7 +523,7 @@ int inet_bind(struct socket *sock, struc
24421         if (sk->sk_state != TCP_CLOSE || inet->inet_num)
24422                 goto out_release_sock;
24423  
24424 -       inet->inet_rcv_saddr = inet->inet_saddr = addr->sin_addr.s_addr;
24425 +       v4_set_sock_addr(inet, &nsa);
24426         if (chk_addr_ret == RTN_MULTICAST || chk_addr_ret == RTN_BROADCAST)
24427                 inet->inet_saddr = 0;  /* Use device */
24428  
24429 @@ -731,11 +741,13 @@ int inet_getname(struct socket *sock, st
24430                      peer == 1))
24431                         return -ENOTCONN;
24432                 sin->sin_port = inet->inet_dport;
24433 -               sin->sin_addr.s_addr = inet->inet_daddr;
24434 +               sin->sin_addr.s_addr =
24435 +                       nx_map_sock_lback(sk->sk_nx_info, inet->inet_daddr);
24436         } else {
24437                 __be32 addr = inet->inet_rcv_saddr;
24438                 if (!addr)
24439                         addr = inet->inet_saddr;
24440 +               addr = nx_map_sock_lback(sk->sk_nx_info, addr);
24441                 sin->sin_port = inet->inet_sport;
24442                 sin->sin_addr.s_addr = addr;
24443         }
24444 diff -NurpP --minimal linux-3.6.10/net/ipv4/arp.c linux-3.6.10-vs2.3.4.5/net/ipv4/arp.c
24445 --- linux-3.6.10/net/ipv4/arp.c 2012-10-04 15:27:49.000000000 +0200
24446 +++ linux-3.6.10-vs2.3.4.5/net/ipv4/arp.c       2012-10-04 18:47:00.000000000 +0200
24447 @@ -1318,6 +1318,7 @@ static void arp_format_neigh_entry(struc
24448         struct net_device *dev = n->dev;
24449         int hatype = dev->type;
24450  
24451 +       /* FIXME: check for network context */
24452         read_lock(&n->lock);
24453         /* Convert hardware address to XX:XX:XX:XX ... form. */
24454  #if IS_ENABLED(CONFIG_AX25)
24455 @@ -1349,6 +1350,7 @@ static void arp_format_pneigh_entry(stru
24456         int hatype = dev ? dev->type : 0;
24457         char tbuf[16];
24458  
24459 +       /* FIXME: check for network context */
24460         sprintf(tbuf, "%pI4", n->key);
24461         seq_printf(seq, "%-16s 0x%-10x0x%-10x%s     *        %s\n",
24462                    tbuf, hatype, ATF_PUBL | ATF_PERM, "00:00:00:00:00:00",
24463 diff -NurpP --minimal linux-3.6.10/net/ipv4/devinet.c linux-3.6.10-vs2.3.4.5/net/ipv4/devinet.c
24464 --- linux-3.6.10/net/ipv4/devinet.c     2012-10-04 15:27:49.000000000 +0200
24465 +++ linux-3.6.10-vs2.3.4.5/net/ipv4/devinet.c   2012-10-04 18:47:00.000000000 +0200
24466 @@ -516,6 +516,7 @@ struct in_device *inetdev_by_index(struc
24467  }
24468  EXPORT_SYMBOL(inetdev_by_index);
24469  
24470 +
24471  /* Called only from RTNL semaphored context. No locks. */
24472  
24473  struct in_ifaddr *inet_ifa_byprefix(struct in_device *in_dev, __be32 prefix,
24474 @@ -757,6 +758,8 @@ int devinet_ioctl(struct net *net, unsig
24475  
24476         in_dev = __in_dev_get_rtnl(dev);
24477         if (in_dev) {
24478 +               struct nx_info *nxi = current_nx_info();
24479 +
24480                 if (tryaddrmatch) {
24481                         /* Matthias Andree */
24482                         /* compare label and address (4.4BSD style) */
24483 @@ -765,6 +768,8 @@ int devinet_ioctl(struct net *net, unsig
24484                            This is checked above. */
24485                         for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
24486                              ifap = &ifa->ifa_next) {
24487 +                               if (!nx_v4_ifa_visible(nxi, ifa))
24488 +                                       continue;
24489                                 if (!strcmp(ifr.ifr_name, ifa->ifa_label) &&
24490                                     sin_orig.sin_addr.s_addr ==
24491                                                         ifa->ifa_local) {
24492 @@ -777,9 +782,12 @@ int devinet_ioctl(struct net *net, unsig
24493                    comparing just the label */
24494                 if (!ifa) {
24495                         for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
24496 -                            ifap = &ifa->ifa_next)
24497 +                            ifap = &ifa->ifa_next) {
24498 +                               if (!nx_v4_ifa_visible(nxi, ifa))
24499 +                                       continue;
24500                                 if (!strcmp(ifr.ifr_name, ifa->ifa_label))
24501                                         break;
24502 +                       }
24503                 }
24504         }
24505  
24506 @@ -932,6 +940,8 @@ static int inet_gifconf(struct net_devic
24507                 goto out;
24508  
24509         for (ifa = in_dev->ifa_list; ifa; ifa = ifa->ifa_next) {
24510 +               if (!nx_v4_ifa_visible(current_nx_info(), ifa))
24511 +                       continue;
24512                 if (!buf) {
24513                         done += sizeof(ifr);
24514                         continue;
24515 @@ -1291,6 +1301,7 @@ static int inet_dump_ifaddr(struct sk_bu
24516         struct net_device *dev;
24517         struct in_device *in_dev;
24518         struct in_ifaddr *ifa;
24519 +       struct sock *sk = skb->sk;
24520         struct hlist_head *head;
24521         struct hlist_node *node;
24522  
24523 @@ -1313,6 +1324,8 @@ static int inet_dump_ifaddr(struct sk_bu
24524  
24525                         for (ifa = in_dev->ifa_list, ip_idx = 0; ifa;
24526                              ifa = ifa->ifa_next, ip_idx++) {
24527 +                       if (sk && !nx_v4_ifa_visible(sk->sk_nx_info, ifa))
24528 +                               continue;
24529                                 if (ip_idx < s_ip_idx)
24530                                         continue;
24531                                 if (inet_fill_ifaddr(skb, ifa,
24532 diff -NurpP --minimal linux-3.6.10/net/ipv4/fib_trie.c linux-3.6.10-vs2.3.4.5/net/ipv4/fib_trie.c
24533 --- linux-3.6.10/net/ipv4/fib_trie.c    2012-10-04 15:27:49.000000000 +0200
24534 +++ linux-3.6.10-vs2.3.4.5/net/ipv4/fib_trie.c  2012-10-04 18:47:00.000000000 +0200
24535 @@ -2554,6 +2554,7 @@ static int fib_route_seq_show(struct seq
24536                             || fa->fa_type == RTN_MULTICAST)
24537                                 continue;
24538  
24539 +                       /* FIXME: check for network context? */
24540                         if (fi)
24541                                 seq_printf(seq,
24542                                          "%s\t%08X\t%08X\t%04X\t%d\t%u\t"
24543 diff -NurpP --minimal linux-3.6.10/net/ipv4/inet_connection_sock.c linux-3.6.10-vs2.3.4.5/net/ipv4/inet_connection_sock.c
24544 --- linux-3.6.10/net/ipv4/inet_connection_sock.c        2012-12-11 12:37:03.000000000 +0100
24545 +++ linux-3.6.10-vs2.3.4.5/net/ipv4/inet_connection_sock.c      2012-11-06 18:43:41.000000000 +0100
24546 @@ -53,6 +53,37 @@ void inet_get_local_port_range(int *low,
24547  }
24548  EXPORT_SYMBOL(inet_get_local_port_range);
24549  
24550 +int ipv4_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2)
24551 +{
24552 +       __be32  sk1_rcv_saddr = sk_rcv_saddr(sk1),
24553 +               sk2_rcv_saddr = sk_rcv_saddr(sk2);
24554 +
24555 +       if (inet_v6_ipv6only(sk2))
24556 +               return 0;
24557 +
24558 +       if (sk1_rcv_saddr &&
24559 +           sk2_rcv_saddr &&
24560 +           sk1_rcv_saddr == sk2_rcv_saddr)
24561 +               return 1;
24562 +
24563 +       if (sk1_rcv_saddr &&
24564 +           !sk2_rcv_saddr &&
24565 +           v4_addr_in_nx_info(sk2->sk_nx_info, sk1_rcv_saddr, NXA_MASK_BIND))
24566 +               return 1;
24567 +
24568 +       if (sk2_rcv_saddr &&
24569 +           !sk1_rcv_saddr &&
24570 +           v4_addr_in_nx_info(sk1->sk_nx_info, sk2_rcv_saddr, NXA_MASK_BIND))
24571 +               return 1;
24572 +
24573 +       if (!sk1_rcv_saddr &&
24574 +           !sk2_rcv_saddr &&
24575 +           nx_v4_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info))
24576 +               return 1;
24577 +
24578 +       return 0;
24579 +}
24580 +
24581  int inet_csk_bind_conflict(const struct sock *sk,
24582                            const struct inet_bind_bucket *tb, bool relax)
24583  {
24584 @@ -75,9 +106,7 @@ int inet_csk_bind_conflict(const struct 
24585                      sk->sk_bound_dev_if == sk2->sk_bound_dev_if)) {
24586                         if (!reuse || !sk2->sk_reuse ||
24587                             sk2->sk_state == TCP_LISTEN) {
24588 -                               const __be32 sk2_rcv_saddr = sk_rcv_saddr(sk2);
24589 -                               if (!sk2_rcv_saddr || !sk_rcv_saddr(sk) ||
24590 -                                   sk2_rcv_saddr == sk_rcv_saddr(sk))
24591 +                               if (ipv4_rcv_saddr_equal(sk, sk2))
24592                                         break;
24593                         }
24594                         if (!relax && reuse && sk2->sk_reuse &&
24595 diff -NurpP --minimal linux-3.6.10/net/ipv4/inet_diag.c linux-3.6.10-vs2.3.4.5/net/ipv4/inet_diag.c
24596 --- linux-3.6.10/net/ipv4/inet_diag.c   2012-12-11 12:37:03.000000000 +0100
24597 +++ linux-3.6.10-vs2.3.4.5/net/ipv4/inet_diag.c 2012-12-08 01:36:33.000000000 +0100
24598 @@ -31,6 +31,8 @@
24599  
24600  #include <linux/inet.h>
24601  #include <linux/stddef.h>
24602 +#include <linux/vs_network.h>
24603 +#include <linux/vs_inet.h>
24604  
24605  #include <linux/inet_diag.h>
24606  #include <linux/sock_diag.h>
24607 @@ -101,8 +103,10 @@ int inet_sk_diag_fill(struct sock *sk, s
24608  
24609         r->id.idiag_sport = inet->inet_sport;
24610         r->id.idiag_dport = inet->inet_dport;
24611 -       r->id.idiag_src[0] = inet->inet_rcv_saddr;
24612 -       r->id.idiag_dst[0] = inet->inet_daddr;
24613 +       r->id.idiag_src[0] = nx_map_sock_lback(sk->sk_nx_info,
24614 +               inet->inet_rcv_saddr);
24615 +       r->id.idiag_dst[0] = nx_map_sock_lback(sk->sk_nx_info,
24616 +               inet->inet_daddr);
24617  
24618         /* IPv6 dual-stack sockets use inet->tos for IPv4 connections,
24619          * hence this needs to be included regardless of socket family.
24620 @@ -233,8 +237,8 @@ static int inet_twsk_diag_fill(struct in
24621         sock_diag_save_cookie(tw, r->id.idiag_cookie);
24622         r->id.idiag_sport     = tw->tw_sport;
24623         r->id.idiag_dport     = tw->tw_dport;
24624 -       r->id.idiag_src[0]    = tw->tw_rcv_saddr;
24625 -       r->id.idiag_dst[0]    = tw->tw_daddr;
24626 +       r->id.idiag_src[0]    = nx_map_sock_lback(tw->tw_nx_info, tw->tw_rcv_saddr);
24627 +       r->id.idiag_dst[0]    = nx_map_sock_lback(tw->tw_nx_info, tw->tw_daddr);
24628         r->idiag_state        = tw->tw_substate;
24629         r->idiag_timer        = 3;
24630         r->idiag_expires      = DIV_ROUND_UP(tmo * 1000, HZ);
24631 @@ -276,12 +280,14 @@ int inet_diag_dump_one_icsk(struct inet_
24632  
24633         err = -EINVAL;
24634         if (req->sdiag_family == AF_INET) {
24635 +               /* TODO: lback */
24636                 sk = inet_lookup(net, hashinfo, req->id.idiag_dst[0],
24637                                  req->id.idiag_dport, req->id.idiag_src[0],
24638                                  req->id.idiag_sport, req->id.idiag_if);
24639         }
24640  #if IS_ENABLED(CONFIG_IPV6)
24641         else if (req->sdiag_family == AF_INET6) {
24642 +               /* TODO: lback */
24643                 sk = inet6_lookup(net, hashinfo,
24644                                   (struct in6_addr *)req->id.idiag_dst,
24645                                   req->id.idiag_dport,
24646 @@ -476,6 +482,7 @@ int inet_diag_bc_sk(const struct nlattr 
24647         } else
24648  #endif
24649         {
24650 +                       /* TODO: lback */
24651                 entry.saddr = &inet->inet_rcv_saddr;
24652                 entry.daddr = &inet->inet_daddr;
24653         }
24654 @@ -574,6 +581,7 @@ static int inet_twsk_diag_dump(struct in
24655                 } else
24656  #endif
24657                 {
24658 +                       /* TODO: lback */
24659                         entry.saddr = &tw->tw_rcv_saddr;
24660                         entry.daddr = &tw->tw_daddr;
24661                 }
24662 @@ -620,8 +628,8 @@ static int inet_diag_fill_req(struct sk_
24663  
24664         r->id.idiag_sport = inet->inet_sport;
24665         r->id.idiag_dport = ireq->rmt_port;
24666 -       r->id.idiag_src[0] = ireq->loc_addr;
24667 -       r->id.idiag_dst[0] = ireq->rmt_addr;
24668 +       r->id.idiag_src[0] = nx_map_sock_lback(sk->sk_nx_info, ireq->loc_addr);
24669 +       r->id.idiag_dst[0] = nx_map_sock_lback(sk->sk_nx_info, ireq->rmt_addr);
24670         r->idiag_expires = jiffies_to_msecs(tmo);
24671         r->idiag_rqueue = 0;
24672         r->idiag_wqueue = 0;
24673 @@ -683,6 +691,7 @@ static int inet_diag_dump_reqs(struct sk
24674                                 continue;
24675  
24676                         if (bc) {
24677 +                               /* TODO: lback */
24678                                 entry.saddr =
24679  #if IS_ENABLED(CONFIG_IPV6)
24680                                         (entry.family == AF_INET6) ?
24681 @@ -748,6 +757,8 @@ void inet_diag_dump_icsk(struct inet_has
24682                                 if (!net_eq(sock_net(sk), net))
24683                                         continue;
24684  
24685 +                               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
24686 +                                       continue;
24687                                 if (num < s_num) {
24688                                         num++;
24689                                         continue;
24690 @@ -820,6 +831,8 @@ skip_listen_ht:
24691  
24692                         if (!net_eq(sock_net(sk), net))
24693                                 continue;
24694 +                       if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
24695 +                               continue;
24696                         if (num < s_num)
24697                                 goto next_normal;
24698                         if (!(r->idiag_states & (1 << sk->sk_state)))
24699 @@ -848,7 +861,8 @@ next_normal:
24700                                     &head->twchain) {
24701                                 if (!net_eq(twsk_net(tw), net))
24702                                         continue;
24703 -
24704 +                               if (!nx_check(tw->tw_nid, VS_WATCH_P | VS_IDENT))
24705 +                                       continue;
24706                                 if (num < s_num)
24707                                         goto next_dying;
24708                                 if (r->sdiag_family != AF_UNSPEC &&
24709 diff -NurpP --minimal linux-3.6.10/net/ipv4/inet_hashtables.c linux-3.6.10-vs2.3.4.5/net/ipv4/inet_hashtables.c
24710 --- linux-3.6.10/net/ipv4/inet_hashtables.c     2012-07-22 23:39:48.000000000 +0200
24711 +++ linux-3.6.10-vs2.3.4.5/net/ipv4/inet_hashtables.c   2012-10-04 18:47:00.000000000 +0200
24712 @@ -22,6 +22,7 @@
24713  #include <net/inet_connection_sock.h>
24714  #include <net/inet_hashtables.h>
24715  #include <net/secure_seq.h>
24716 +#include <net/route.h>
24717  #include <net/ip.h>
24718  
24719  /*
24720 @@ -156,6 +157,11 @@ static inline int compute_score(struct s
24721                         if (rcv_saddr != daddr)
24722                                 return -1;
24723                         score += 2;
24724 +               } else {
24725 +                       /* block non nx_info ips */
24726 +                       if (!v4_addr_in_nx_info(sk->sk_nx_info,
24727 +                               daddr, NXA_MASK_BIND))
24728 +                               return -1;
24729                 }
24730                 if (sk->sk_bound_dev_if) {
24731                         if (sk->sk_bound_dev_if != dif)
24732 @@ -173,7 +179,6 @@ static inline int compute_score(struct s
24733   * wildcarded during the search since they can never be otherwise.
24734   */
24735  
24736 -
24737  struct sock *__inet_lookup_listener(struct net *net,
24738                                     struct inet_hashinfo *hashinfo,
24739                                     const __be32 daddr, const unsigned short hnum,
24740 @@ -196,6 +201,7 @@ begin:
24741                         hiscore = score;
24742                 }
24743         }
24744 +
24745         /*
24746          * if the nulls value we got at the end of this lookup is
24747          * not the expected one, we must restart lookup.
24748 diff -NurpP --minimal linux-3.6.10/net/ipv4/netfilter/nf_nat_helper.c linux-3.6.10-vs2.3.4.5/net/ipv4/netfilter/nf_nat_helper.c
24749 --- linux-3.6.10/net/ipv4/netfilter/nf_nat_helper.c     2012-10-04 15:27:50.000000000 +0200
24750 +++ linux-3.6.10-vs2.3.4.5/net/ipv4/netfilter/nf_nat_helper.c   2012-10-04 18:47:00.000000000 +0200
24751 @@ -20,6 +20,7 @@
24752  #include <net/route.h>
24753  
24754  #include <linux/netfilter_ipv4.h>
24755 +#include <net/route.h>
24756  #include <net/netfilter/nf_conntrack.h>
24757  #include <net/netfilter/nf_conntrack_helper.h>
24758  #include <net/netfilter/nf_conntrack_ecache.h>
24759 diff -NurpP --minimal linux-3.6.10/net/ipv4/netfilter.c linux-3.6.10-vs2.3.4.5/net/ipv4/netfilter.c
24760 --- linux-3.6.10/net/ipv4/netfilter.c   2012-07-22 23:39:48.000000000 +0200
24761 +++ linux-3.6.10-vs2.3.4.5/net/ipv4/netfilter.c 2012-10-04 18:47:00.000000000 +0200
24762 @@ -6,7 +6,7 @@
24763  #include <linux/skbuff.h>
24764  #include <linux/gfp.h>
24765  #include <linux/export.h>
24766 -#include <net/route.h>
24767 +// #include <net/route.h>
24768  #include <net/xfrm.h>
24769  #include <net/ip.h>
24770  #include <net/netfilter/nf_queue.h>
24771 diff -NurpP --minimal linux-3.6.10/net/ipv4/raw.c linux-3.6.10-vs2.3.4.5/net/ipv4/raw.c
24772 --- linux-3.6.10/net/ipv4/raw.c 2012-10-04 15:27:50.000000000 +0200
24773 +++ linux-3.6.10-vs2.3.4.5/net/ipv4/raw.c       2012-10-04 18:47:00.000000000 +0200
24774 @@ -118,7 +118,7 @@ static struct sock *__raw_v4_lookup(stru
24775  
24776                 if (net_eq(sock_net(sk), net) && inet->inet_num == num  &&
24777                     !(inet->inet_daddr && inet->inet_daddr != raddr)    &&
24778 -                   !(inet->inet_rcv_saddr && inet->inet_rcv_saddr != laddr) &&
24779 +                   v4_sock_addr_match(sk->sk_nx_info, inet, laddr)     &&
24780                     !(sk->sk_bound_dev_if && sk->sk_bound_dev_if != dif))
24781                         goto found; /* gotcha */
24782         }
24783 @@ -397,6 +397,12 @@ static int raw_send_hdrinc(struct sock *
24784                 icmp_out_count(net, ((struct icmphdr *)
24785                         skb_transport_header(skb))->type);
24786  
24787 +       err = -EPERM;
24788 +       if (!nx_check(0, VS_ADMIN) && !capable(CAP_NET_RAW) &&
24789 +               sk->sk_nx_info &&
24790 +               !v4_addr_in_nx_info(sk->sk_nx_info, iph->saddr, NXA_MASK_BIND))
24791 +               goto error_free;
24792 +
24793         err = NF_HOOK(NFPROTO_IPV4, NF_INET_LOCAL_OUT, skb, NULL,
24794                       rt->dst.dev, dst_output);
24795         if (err > 0)
24796 @@ -582,6 +588,16 @@ static int raw_sendmsg(struct kiocb *ioc
24797                         goto done;
24798         }
24799  
24800 +       if (sk->sk_nx_info) {
24801 +               rt = ip_v4_find_src(sock_net(sk), sk->sk_nx_info, &fl4);
24802 +               if (IS_ERR(rt)) {
24803 +                       err = PTR_ERR(rt);
24804 +                       rt = NULL;
24805 +                       goto done;
24806 +               }
24807 +               ip_rt_put(rt);
24808 +       }
24809 +
24810         security_sk_classify_flow(sk, flowi4_to_flowi(&fl4));
24811         rt = ip_route_output_flow(sock_net(sk), &fl4, sk);
24812         if (IS_ERR(rt)) {
24813 @@ -658,17 +674,19 @@ static int raw_bind(struct sock *sk, str
24814  {
24815         struct inet_sock *inet = inet_sk(sk);
24816         struct sockaddr_in *addr = (struct sockaddr_in *) uaddr;
24817 +       struct nx_v4_sock_addr nsa = { 0 };
24818         int ret = -EINVAL;
24819         int chk_addr_ret;
24820  
24821         if (sk->sk_state != TCP_CLOSE || addr_len < sizeof(struct sockaddr_in))
24822                 goto out;
24823 -       chk_addr_ret = inet_addr_type(sock_net(sk), addr->sin_addr.s_addr);
24824 +       v4_map_sock_addr(inet, addr, &nsa);
24825 +       chk_addr_ret = inet_addr_type(sock_net(sk), nsa.saddr);
24826         ret = -EADDRNOTAVAIL;
24827 -       if (addr->sin_addr.s_addr && chk_addr_ret != RTN_LOCAL &&
24828 +       if (nsa.saddr && chk_addr_ret != RTN_LOCAL &&
24829             chk_addr_ret != RTN_MULTICAST && chk_addr_ret != RTN_BROADCAST)
24830                 goto out;
24831 -       inet->inet_rcv_saddr = inet->inet_saddr = addr->sin_addr.s_addr;
24832 +       v4_set_sock_addr(inet, &nsa);
24833         if (chk_addr_ret == RTN_MULTICAST || chk_addr_ret == RTN_BROADCAST)
24834                 inet->inet_saddr = 0;  /* Use device */
24835         sk_dst_reset(sk);
24836 @@ -720,7 +738,8 @@ static int raw_recvmsg(struct kiocb *ioc
24837         /* Copy the address. */
24838         if (sin) {
24839                 sin->sin_family = AF_INET;
24840 -               sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
24841 +               sin->sin_addr.s_addr =
24842 +                       nx_map_sock_lback(sk->sk_nx_info, ip_hdr(skb)->saddr);
24843                 sin->sin_port = 0;
24844                 memset(&sin->sin_zero, 0, sizeof(sin->sin_zero));
24845         }
24846 @@ -916,7 +935,8 @@ static struct sock *raw_get_first(struct
24847                 struct hlist_node *node;
24848  
24849                 sk_for_each(sk, node, &state->h->ht[state->bucket])
24850 -                       if (sock_net(sk) == seq_file_net(seq))
24851 +                       if ((sock_net(sk) == seq_file_net(seq)) &&
24852 +                               nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
24853                                 goto found;
24854         }
24855         sk = NULL;
24856 @@ -932,7 +952,8 @@ static struct sock *raw_get_next(struct 
24857                 sk = sk_next(sk);
24858  try_again:
24859                 ;
24860 -       } while (sk && sock_net(sk) != seq_file_net(seq));
24861 +       } while (sk && ((sock_net(sk) != seq_file_net(seq)) ||
24862 +               !nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT)));
24863  
24864         if (!sk && ++state->bucket < RAW_HTABLE_SIZE) {
24865                 sk = sk_head(&state->h->ht[state->bucket]);
24866 diff -NurpP --minimal linux-3.6.10/net/ipv4/route.c linux-3.6.10-vs2.3.4.5/net/ipv4/route.c
24867 --- linux-3.6.10/net/ipv4/route.c       2012-12-11 12:37:03.000000000 +0100
24868 +++ linux-3.6.10-vs2.3.4.5/net/ipv4/route.c     2012-12-08 01:36:33.000000000 +0100
24869 @@ -1949,7 +1949,7 @@ struct rtable *__ip_route_output_key(str
24870  
24871  
24872         if (fl4->flowi4_oif) {
24873 -               dev_out = dev_get_by_index_rcu(net, fl4->flowi4_oif);
24874 +               dev_out = dev_get_by_index_real_rcu(net, fl4->flowi4_oif);
24875                 rth = ERR_PTR(-ENODEV);
24876                 if (dev_out == NULL)
24877                         goto out;
24878 diff -NurpP --minimal linux-3.6.10/net/ipv4/tcp.c linux-3.6.10-vs2.3.4.5/net/ipv4/tcp.c
24879 --- linux-3.6.10/net/ipv4/tcp.c 2012-12-11 12:37:03.000000000 +0100
24880 +++ linux-3.6.10-vs2.3.4.5/net/ipv4/tcp.c       2012-12-08 01:36:33.000000000 +0100
24881 @@ -268,6 +268,7 @@
24882  #include <linux/crypto.h>
24883  #include <linux/time.h>
24884  #include <linux/slab.h>
24885 +#include <linux/in.h>
24886  
24887  #include <net/icmp.h>
24888  #include <net/inet_common.h>
24889 diff -NurpP --minimal linux-3.6.10/net/ipv4/tcp_ipv4.c linux-3.6.10-vs2.3.4.5/net/ipv4/tcp_ipv4.c
24890 --- linux-3.6.10/net/ipv4/tcp_ipv4.c    2012-12-11 12:37:03.000000000 +0100
24891 +++ linux-3.6.10-vs2.3.4.5/net/ipv4/tcp_ipv4.c  2012-11-06 18:43:41.000000000 +0100
24892 @@ -2034,6 +2034,12 @@ static void *listening_get_next(struct s
24893                 req = req->dl_next;
24894                 while (1) {
24895                         while (req) {
24896 +                               vxdprintk(VXD_CBIT(net, 6),
24897 +                                       "sk,req: %p [#%d] (from %d)", req->sk,
24898 +                                       (req->sk)?req->sk->sk_nid:0, nx_current_nid());
24899 +                               if (req->sk &&
24900 +                                       !nx_check(req->sk->sk_nid, VS_WATCH_P | VS_IDENT))
24901 +                                       continue;
24902                                 if (req->rsk_ops->family == st->family) {
24903                                         cur = req;
24904                                         goto out;
24905 @@ -2058,6 +2064,10 @@ get_req:
24906         }
24907  get_sk:
24908         sk_nulls_for_each_from(sk, node) {
24909 +               vxdprintk(VXD_CBIT(net, 6), "sk: %p [#%d] (from %d)",
24910 +                       sk, sk->sk_nid, nx_current_nid());
24911 +               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
24912 +                       continue;
24913                 if (!net_eq(sock_net(sk), net))
24914                         continue;
24915                 if (sk->sk_family == st->family) {
24916 @@ -2134,6 +2144,11 @@ static void *established_get_first(struc
24917  
24918                 spin_lock_bh(lock);
24919                 sk_nulls_for_each(sk, node, &tcp_hashinfo.ehash[st->bucket].chain) {
24920 +                       vxdprintk(VXD_CBIT(net, 6),
24921 +                               "sk,egf: %p [#%d] (from %d)",
24922 +                               sk, sk->sk_nid, nx_current_nid());
24923 +                       if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
24924 +                               continue;
24925                         if (sk->sk_family != st->family ||
24926                             !net_eq(sock_net(sk), net)) {
24927                                 continue;
24928 @@ -2144,6 +2159,11 @@ static void *established_get_first(struc
24929                 st->state = TCP_SEQ_STATE_TIME_WAIT;
24930                 inet_twsk_for_each(tw, node,
24931                                    &tcp_hashinfo.ehash[st->bucket].twchain) {
24932 +                       vxdprintk(VXD_CBIT(net, 6),
24933 +                               "tw: %p [#%d] (from %d)",
24934 +                               tw, tw->tw_nid, nx_current_nid());
24935 +                       if (!nx_check(tw->tw_nid, VS_WATCH_P | VS_IDENT))
24936 +                               continue;
24937                         if (tw->tw_family != st->family ||
24938                             !net_eq(twsk_net(tw), net)) {
24939                                 continue;
24940 @@ -2173,7 +2193,9 @@ static void *established_get_next(struct
24941                 tw = cur;
24942                 tw = tw_next(tw);
24943  get_tw:
24944 -               while (tw && (tw->tw_family != st->family || !net_eq(twsk_net(tw), net))) {
24945 +               while (tw && (tw->tw_family != st->family ||
24946 +                       !net_eq(twsk_net(tw), net) ||
24947 +                       !nx_check(tw->tw_nid, VS_WATCH_P | VS_IDENT))) {
24948                         tw = tw_next(tw);
24949                 }
24950                 if (tw) {
24951 @@ -2197,6 +2219,11 @@ get_tw:
24952                 sk = sk_nulls_next(sk);
24953  
24954         sk_nulls_for_each_from(sk, node) {
24955 +               vxdprintk(VXD_CBIT(net, 6),
24956 +                       "sk,egn: %p [#%d] (from %d)",
24957 +                       sk, sk->sk_nid, nx_current_nid());
24958 +               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
24959 +                       continue;
24960                 if (sk->sk_family == st->family && net_eq(sock_net(sk), net))
24961                         goto found;
24962         }
24963 @@ -2402,9 +2429,9 @@ static void get_openreq4(const struct so
24964         seq_printf(f, "%4d: %08X:%04X %08X:%04X"
24965                 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %u %d %pK%n",
24966                 i,
24967 -               ireq->loc_addr,
24968 +               nx_map_sock_lback(current_nx_info(), ireq->loc_addr),
24969                 ntohs(inet_sk(sk)->inet_sport),
24970 -               ireq->rmt_addr,
24971 +               nx_map_sock_lback(current_nx_info(), ireq->rmt_addr),
24972                 ntohs(ireq->rmt_port),
24973                 TCP_SYN_RECV,
24974                 0, 0, /* could print option size, but that is af dependent. */
24975 @@ -2426,8 +2453,8 @@ static void get_tcp4_sock(struct sock *s
24976         const struct tcp_sock *tp = tcp_sk(sk);
24977         const struct inet_connection_sock *icsk = inet_csk(sk);
24978         const struct inet_sock *inet = inet_sk(sk);
24979 -       __be32 dest = inet->inet_daddr;
24980 -       __be32 src = inet->inet_rcv_saddr;
24981 +       __be32 dest = nx_map_sock_lback(current_nx_info(), inet->inet_daddr);
24982 +       __be32 src = nx_map_sock_lback(current_nx_info(), inet->inet_rcv_saddr);
24983         __u16 destp = ntohs(inet->inet_dport);
24984         __u16 srcp = ntohs(inet->inet_sport);
24985         int rx_queue;
24986 @@ -2484,8 +2511,8 @@ static void get_timewait4_sock(const str
24987         if (ttd < 0)
24988                 ttd = 0;
24989  
24990 -       dest  = tw->tw_daddr;
24991 -       src   = tw->tw_rcv_saddr;
24992 +       dest  = nx_map_sock_lback(current_nx_info(), tw->tw_daddr);
24993 +       src   = nx_map_sock_lback(current_nx_info(), tw->tw_rcv_saddr);
24994         destp = ntohs(tw->tw_dport);
24995         srcp  = ntohs(tw->tw_sport);
24996  
24997 diff -NurpP --minimal linux-3.6.10/net/ipv4/tcp_minisocks.c linux-3.6.10-vs2.3.4.5/net/ipv4/tcp_minisocks.c
24998 --- linux-3.6.10/net/ipv4/tcp_minisocks.c       2012-10-04 15:27:50.000000000 +0200
24999 +++ linux-3.6.10-vs2.3.4.5/net/ipv4/tcp_minisocks.c     2012-10-04 18:47:00.000000000 +0200
25000 @@ -23,6 +23,9 @@
25001  #include <linux/slab.h>
25002  #include <linux/sysctl.h>
25003  #include <linux/workqueue.h>
25004 +#include <linux/vs_limit.h>
25005 +#include <linux/vs_socket.h>
25006 +#include <linux/vs_context.h>
25007  #include <net/tcp.h>
25008  #include <net/inet_common.h>
25009  #include <net/xfrm.h>
25010 @@ -287,6 +290,11 @@ void tcp_time_wait(struct sock *sk, int 
25011                 tcptw->tw_ts_recent     = tp->rx_opt.ts_recent;
25012                 tcptw->tw_ts_recent_stamp = tp->rx_opt.ts_recent_stamp;
25013  
25014 +               tw->tw_xid              = sk->sk_xid;
25015 +               tw->tw_vx_info          = NULL;
25016 +               tw->tw_nid              = sk->sk_nid;
25017 +               tw->tw_nx_info          = NULL;
25018 +
25019  #if IS_ENABLED(CONFIG_IPV6)
25020                 if (tw->tw_family == PF_INET6) {
25021                         struct ipv6_pinfo *np = inet6_sk(sk);
25022 diff -NurpP --minimal linux-3.6.10/net/ipv4/udp.c linux-3.6.10-vs2.3.4.5/net/ipv4/udp.c
25023 --- linux-3.6.10/net/ipv4/udp.c 2012-10-04 15:27:50.000000000 +0200
25024 +++ linux-3.6.10-vs2.3.4.5/net/ipv4/udp.c       2012-10-04 18:47:00.000000000 +0200
25025 @@ -300,14 +300,7 @@ fail:
25026  }
25027  EXPORT_SYMBOL(udp_lib_get_port);
25028  
25029 -static int ipv4_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2)
25030 -{
25031 -       struct inet_sock *inet1 = inet_sk(sk1), *inet2 = inet_sk(sk2);
25032 -
25033 -       return  (!ipv6_only_sock(sk2)  &&
25034 -                (!inet1->inet_rcv_saddr || !inet2->inet_rcv_saddr ||
25035 -                  inet1->inet_rcv_saddr == inet2->inet_rcv_saddr));
25036 -}
25037 +extern int ipv4_rcv_saddr_equal(const struct sock *, const struct sock *);
25038  
25039  static unsigned int udp4_portaddr_hash(struct net *net, __be32 saddr,
25040                                        unsigned int port)
25041 @@ -342,6 +335,11 @@ static inline int compute_score(struct s
25042                         if (inet->inet_rcv_saddr != daddr)
25043                                 return -1;
25044                         score += 2;
25045 +               } else {
25046 +                       /* block non nx_info ips */
25047 +                       if (!v4_addr_in_nx_info(sk->sk_nx_info,
25048 +                               daddr, NXA_MASK_BIND))
25049 +                               return -1;
25050                 }
25051                 if (inet->inet_daddr) {
25052                         if (inet->inet_daddr != saddr)
25053 @@ -445,6 +443,7 @@ exact_match:
25054         return result;
25055  }
25056  
25057 +
25058  /* UDP is nearly always wildcards out the wazoo, it makes no sense to try
25059   * harder than this. -DaveM
25060   */
25061 @@ -490,6 +489,11 @@ begin:
25062         sk_nulls_for_each_rcu(sk, node, &hslot->head) {
25063                 score = compute_score(sk, net, saddr, hnum, sport,
25064                                       daddr, dport, dif);
25065 +               /* FIXME: disabled?
25066 +               if (score == 9) {
25067 +                       result = sk;
25068 +                       break;
25069 +               } else */
25070                 if (score > badness) {
25071                         result = sk;
25072                         badness = score;
25073 @@ -503,6 +507,7 @@ begin:
25074         if (get_nulls_value(node) != slot)
25075                 goto begin;
25076  
25077 +
25078         if (result) {
25079                 if (unlikely(!atomic_inc_not_zero_hint(&result->sk_refcnt, 2)))
25080                         result = NULL;
25081 @@ -512,6 +517,7 @@ begin:
25082                         goto begin;
25083                 }
25084         }
25085 +
25086         rcu_read_unlock();
25087         return result;
25088  }
25089 @@ -555,8 +561,7 @@ static inline struct sock *udp_v4_mcast_
25090                     udp_sk(s)->udp_port_hash != hnum ||
25091                     (inet->inet_daddr && inet->inet_daddr != rmt_addr) ||
25092                     (inet->inet_dport != rmt_port && inet->inet_dport) ||
25093 -                   (inet->inet_rcv_saddr &&
25094 -                    inet->inet_rcv_saddr != loc_addr) ||
25095 +                   !v4_sock_addr_match(sk->sk_nx_info, inet, loc_addr) ||
25096                     ipv6_only_sock(s) ||
25097                     (s->sk_bound_dev_if && s->sk_bound_dev_if != dif))
25098                         continue;
25099 @@ -939,6 +944,16 @@ int udp_sendmsg(struct kiocb *iocb, stru
25100                                    inet_sk_flowi_flags(sk)|FLOWI_FLAG_CAN_SLEEP,
25101                                    faddr, saddr, dport, inet->inet_sport);
25102  
25103 +               if (sk->sk_nx_info) {
25104 +                       rt = ip_v4_find_src(net, sk->sk_nx_info, fl4);
25105 +                       if (IS_ERR(rt)) {
25106 +                               err = PTR_ERR(rt);
25107 +                               rt = NULL;
25108 +                               goto out;
25109 +                       }
25110 +                       ip_rt_put(rt);
25111 +               }
25112 +
25113                 security_sk_classify_flow(sk, flowi4_to_flowi(fl4));
25114                 rt = ip_route_output_flow(net, fl4, sk);
25115                 if (IS_ERR(rt)) {
25116 @@ -1244,7 +1259,8 @@ try_again:
25117         if (sin) {
25118                 sin->sin_family = AF_INET;
25119                 sin->sin_port = udp_hdr(skb)->source;
25120 -               sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
25121 +               sin->sin_addr.s_addr = nx_map_sock_lback(
25122 +                       skb->sk->sk_nx_info, ip_hdr(skb)->saddr);
25123                 memset(sin->sin_zero, 0, sizeof(sin->sin_zero));
25124         }
25125         if (inet->cmsg_flags)
25126 @@ -1992,6 +2008,8 @@ static struct sock *udp_get_first(struct
25127                 sk_nulls_for_each(sk, node, &hslot->head) {
25128                         if (!net_eq(sock_net(sk), net))
25129                                 continue;
25130 +                       if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
25131 +                               continue;
25132                         if (sk->sk_family == state->family)
25133                                 goto found;
25134                 }
25135 @@ -2009,7 +2027,9 @@ static struct sock *udp_get_next(struct 
25136  
25137         do {
25138                 sk = sk_nulls_next(sk);
25139 -       } while (sk && (!net_eq(sock_net(sk), net) || sk->sk_family != state->family));
25140 +       } while (sk && (!net_eq(sock_net(sk), net) ||
25141 +               sk->sk_family != state->family ||
25142 +               !nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT)));
25143  
25144         if (!sk) {
25145                 if (state->bucket <= state->udp_table->mask)
25146 @@ -2105,8 +2125,8 @@ static void udp4_format_sock(struct sock
25147                 int bucket, int *len)
25148  {
25149         struct inet_sock *inet = inet_sk(sp);
25150 -       __be32 dest = inet->inet_daddr;
25151 -       __be32 src  = inet->inet_rcv_saddr;
25152 +       __be32 dest = nx_map_sock_lback(current_nx_info(), inet->inet_daddr);
25153 +       __be32 src = nx_map_sock_lback(current_nx_info(), inet->inet_rcv_saddr);
25154         __u16 destp       = ntohs(inet->inet_dport);
25155         __u16 srcp        = ntohs(inet->inet_sport);
25156  
25157 diff -NurpP --minimal linux-3.6.10/net/ipv6/Kconfig linux-3.6.10-vs2.3.4.5/net/ipv6/Kconfig
25158 --- linux-3.6.10/net/ipv6/Kconfig       2012-07-22 23:39:48.000000000 +0200
25159 +++ linux-3.6.10-vs2.3.4.5/net/ipv6/Kconfig     2012-10-04 18:47:00.000000000 +0200
25160 @@ -4,8 +4,8 @@
25161  
25162  #   IPv6 as module will cause a CRASH if you try to unload it
25163  menuconfig IPV6
25164 -       tristate "The IPv6 protocol"
25165 -       default m
25166 +       bool "The IPv6 protocol"
25167 +       default n
25168         ---help---
25169           This is complemental support for the IP version 6.
25170           You will still be able to do traditional IPv4 networking as well.
25171 diff -NurpP --minimal linux-3.6.10/net/ipv6/addrconf.c linux-3.6.10-vs2.3.4.5/net/ipv6/addrconf.c
25172 --- linux-3.6.10/net/ipv6/addrconf.c    2012-12-11 12:37:04.000000000 +0100
25173 +++ linux-3.6.10-vs2.3.4.5/net/ipv6/addrconf.c  2012-11-06 18:43:41.000000000 +0100
25174 @@ -92,6 +92,8 @@
25175  #include <linux/proc_fs.h>
25176  #include <linux/seq_file.h>
25177  #include <linux/export.h>
25178 +#include <linux/vs_network.h>
25179 +#include <linux/vs_inet6.h>
25180  
25181  /* Set to 3 to get tracing... */
25182  #define ACONF_DEBUG 2
25183 @@ -1101,7 +1103,7 @@ out:
25184  
25185  int ipv6_dev_get_saddr(struct net *net, struct net_device *dst_dev,
25186                        const struct in6_addr *daddr, unsigned int prefs,
25187 -                      struct in6_addr *saddr)
25188 +                      struct in6_addr *saddr, struct nx_info *nxi)
25189  {
25190         struct ipv6_saddr_score scores[2],
25191                                 *score = &scores[0], *hiscore = &scores[1];
25192 @@ -1173,6 +1175,8 @@ int ipv6_dev_get_saddr(struct net *net, 
25193                                                dev->name);
25194                                 continue;
25195                         }
25196 +                       if (!v6_addr_in_nx_info(nxi, &score->ifa->addr, -1))
25197 +                               continue;
25198  
25199                         score->rule = -1;
25200                         bitmap_zero(score->scorebits, IPV6_SADDR_RULE_MAX);
25201 @@ -3159,7 +3163,10 @@ static void if6_seq_stop(struct seq_file
25202  static int if6_seq_show(struct seq_file *seq, void *v)
25203  {
25204         struct inet6_ifaddr *ifp = (struct inet6_ifaddr *)v;
25205 -       seq_printf(seq, "%pi6 %02x %02x %02x %02x %8s\n",
25206 +
25207 +       if (nx_check(0, VS_ADMIN|VS_WATCH) ||
25208 +           v6_addr_in_nx_info(current_nx_info(), &ifp->addr, -1))
25209 +               seq_printf(seq, "%pi6 %02x %02x %02x %02x %8s\n",
25210                    &ifp->addr,
25211                    ifp->idev->dev->ifindex,
25212                    ifp->prefix_len,
25213 @@ -3665,6 +3672,11 @@ static int in6_dump_addrs(struct inet6_d
25214         struct ifacaddr6 *ifaca;
25215         int err = 1;
25216         int ip_idx = *p_ip_idx;
25217 +       struct nx_info *nxi = skb->sk ? skb->sk->sk_nx_info : NULL;
25218 +
25219 +       /* disable ipv6 on non v6 guests */
25220 +       if (nxi && !nx_info_has_v6(nxi))
25221 +               return skb->len;
25222  
25223         read_lock_bh(&idev->lock);
25224         switch (type) {
25225 @@ -3675,6 +3687,8 @@ static int in6_dump_addrs(struct inet6_d
25226                 list_for_each_entry(ifa, &idev->addr_list, if_list) {
25227                         if (++ip_idx < s_ip_idx)
25228                                 continue;
25229 +                               if (!v6_addr_in_nx_info(nxi, &ifa->addr, -1))
25230 +                                       continue;
25231                         err = inet6_fill_ifaddr(skb, ifa,
25232                                                 NETLINK_CB(cb->skb).pid,
25233                                                 cb->nlh->nlmsg_seq,
25234 @@ -3691,6 +3705,8 @@ static int in6_dump_addrs(struct inet6_d
25235                      ifmca = ifmca->next, ip_idx++) {
25236                         if (ip_idx < s_ip_idx)
25237                                 continue;
25238 +                               if (!v6_addr_in_nx_info(nxi, &ifmca->mca_addr, -1))
25239 +                                       continue;
25240                         err = inet6_fill_ifmcaddr(skb, ifmca,
25241                                                   NETLINK_CB(cb->skb).pid,
25242                                                   cb->nlh->nlmsg_seq,
25243 @@ -3706,6 +3722,8 @@ static int in6_dump_addrs(struct inet6_d
25244                      ifaca = ifaca->aca_next, ip_idx++) {
25245                         if (ip_idx < s_ip_idx)
25246                                 continue;
25247 +                               if (!v6_addr_in_nx_info(nxi, &ifaca->aca_addr, -1))
25248 +                                       continue;
25249                         err = inet6_fill_ifacaddr(skb, ifaca,
25250                                                   NETLINK_CB(cb->skb).pid,
25251                                                   cb->nlh->nlmsg_seq,
25252 @@ -4089,6 +4107,11 @@ static int inet6_dump_ifinfo(struct sk_b
25253         struct inet6_dev *idev;
25254         struct hlist_head *head;
25255         struct hlist_node *node;
25256 +       struct nx_info *nxi = skb->sk ? skb->sk->sk_nx_info : NULL;
25257 +
25258 +       /* FIXME: maybe disable ipv6 on non v6 guests?
25259 +       if (skb->sk && skb->sk->sk_vx_info)
25260 +               return skb->len; */
25261  
25262         s_h = cb->args[0];
25263         s_idx = cb->args[1];
25264 @@ -4100,6 +4123,8 @@ static int inet6_dump_ifinfo(struct sk_b
25265                 hlist_for_each_entry_rcu(dev, node, head, index_hlist) {
25266                         if (idx < s_idx)
25267                                 goto cont;
25268 +                       if (!v6_dev_in_nx_info(dev, nxi))
25269 +                               goto cont;
25270                         idev = __in6_dev_get(dev);
25271                         if (!idev)
25272                                 goto cont;
25273 diff -NurpP --minimal linux-3.6.10/net/ipv6/af_inet6.c linux-3.6.10-vs2.3.4.5/net/ipv6/af_inet6.c
25274 --- linux-3.6.10/net/ipv6/af_inet6.c    2012-12-11 12:37:04.000000000 +0100
25275 +++ linux-3.6.10-vs2.3.4.5/net/ipv6/af_inet6.c  2012-11-06 18:43:41.000000000 +0100
25276 @@ -43,6 +43,8 @@
25277  #include <linux/netdevice.h>
25278  #include <linux/icmpv6.h>
25279  #include <linux/netfilter_ipv6.h>
25280 +#include <linux/vs_inet.h>
25281 +#include <linux/vs_inet6.h>
25282  
25283  #include <net/ip.h>
25284  #include <net/ipv6.h>
25285 @@ -160,9 +162,12 @@ lookup_protocol:
25286         }
25287  
25288         err = -EPERM;
25289 +       if ((protocol == IPPROTO_ICMPV6) &&
25290 +               nx_capable(CAP_NET_RAW, NXC_RAW_ICMP))
25291 +               goto override;
25292         if (sock->type == SOCK_RAW && !kern && !capable(CAP_NET_RAW))
25293                 goto out_rcu_unlock;
25294 -
25295 +override:
25296         sock->ops = answer->ops;
25297         answer_prot = answer->prot;
25298         answer_no_check = answer->no_check;
25299 @@ -262,6 +267,7 @@ int inet6_bind(struct socket *sock, stru
25300         struct inet_sock *inet = inet_sk(sk);
25301         struct ipv6_pinfo *np = inet6_sk(sk);
25302         struct net *net = sock_net(sk);
25303 +       struct nx_v6_sock_addr nsa;
25304         __be32 v4addr = 0;
25305         unsigned short snum;
25306         int addr_type = 0;
25307 @@ -277,6 +283,10 @@ int inet6_bind(struct socket *sock, stru
25308         if (addr->sin6_family != AF_INET6)
25309                 return -EAFNOSUPPORT;
25310  
25311 +       err = v6_map_sock_addr(inet, addr, &nsa);
25312 +       if (err)
25313 +               return err;
25314 +
25315         addr_type = ipv6_addr_type(&addr->sin6_addr);
25316         if ((addr_type & IPV6_ADDR_MULTICAST) && sock->type == SOCK_STREAM)
25317                 return -EINVAL;
25318 @@ -308,6 +318,7 @@ int inet6_bind(struct socket *sock, stru
25319                 /* Reproduce AF_INET checks to make the bindings consistent */
25320                 v4addr = addr->sin6_addr.s6_addr32[3];
25321                 chk_addr_ret = inet_addr_type(net, v4addr);
25322 +
25323                 if (!sysctl_ip_nonlocal_bind &&
25324                     !(inet->freebind || inet->transparent) &&
25325                     v4addr != htonl(INADDR_ANY) &&
25326 @@ -317,6 +328,10 @@ int inet6_bind(struct socket *sock, stru
25327                         err = -EADDRNOTAVAIL;
25328                         goto out;
25329                 }
25330 +               if (!v4_addr_in_nx_info(sk->sk_nx_info, v4addr, NXA_MASK_BIND)) {
25331 +                       err = -EADDRNOTAVAIL;
25332 +                       goto out;
25333 +               }
25334         } else {
25335                 if (addr_type != IPV6_ADDR_ANY) {
25336                         struct net_device *dev = NULL;
25337 @@ -343,6 +358,11 @@ int inet6_bind(struct socket *sock, stru
25338                                 }
25339                         }
25340  
25341 +                       if (!v6_addr_in_nx_info(sk->sk_nx_info, &addr->sin6_addr, -1)) {
25342 +                               err = -EADDRNOTAVAIL;
25343 +                               goto out_unlock;
25344 +                       }
25345 +
25346                         /* ipv4 addr of the socket is invalid.  Only the
25347                          * unspecified and mapped address have a v4 equivalent.
25348                          */
25349 @@ -359,6 +379,9 @@ int inet6_bind(struct socket *sock, stru
25350                 }
25351         }
25352  
25353 +       /* what's that for? */
25354 +       v6_set_sock_addr(inet, &nsa);
25355 +
25356         inet->inet_rcv_saddr = v4addr;
25357         inet->inet_saddr = v4addr;
25358  
25359 @@ -460,9 +483,11 @@ int inet6_getname(struct socket *sock, s
25360                         return -ENOTCONN;
25361                 sin->sin6_port = inet->inet_dport;
25362                 sin->sin6_addr = np->daddr;
25363 +               /* FIXME: remap lback? */
25364                 if (np->sndflow)
25365                         sin->sin6_flowinfo = np->flow_label;
25366         } else {
25367 +               /* FIXME: remap lback? */
25368                 if (ipv6_addr_any(&np->rcv_saddr))
25369                         sin->sin6_addr = np->saddr;
25370                 else
25371 diff -NurpP --minimal linux-3.6.10/net/ipv6/datagram.c linux-3.6.10-vs2.3.4.5/net/ipv6/datagram.c
25372 --- linux-3.6.10/net/ipv6/datagram.c    2012-07-22 23:39:48.000000000 +0200
25373 +++ linux-3.6.10-vs2.3.4.5/net/ipv6/datagram.c  2012-10-04 18:47:00.000000000 +0200
25374 @@ -645,7 +645,7 @@ int datagram_send_ctl(struct net *net, s
25375  
25376                         rcu_read_lock();
25377                         if (fl6->flowi6_oif) {
25378 -                               dev = dev_get_by_index_rcu(net, fl6->flowi6_oif);
25379 +                               dev = dev_get_by_index_real_rcu(net, fl6->flowi6_oif);
25380                                 if (!dev) {
25381                                         rcu_read_unlock();
25382                                         return -ENODEV;
25383 diff -NurpP --minimal linux-3.6.10/net/ipv6/fib6_rules.c linux-3.6.10-vs2.3.4.5/net/ipv6/fib6_rules.c
25384 --- linux-3.6.10/net/ipv6/fib6_rules.c  2012-07-22 23:39:48.000000000 +0200
25385 +++ linux-3.6.10-vs2.3.4.5/net/ipv6/fib6_rules.c        2012-10-04 18:47:00.000000000 +0200
25386 @@ -90,7 +90,7 @@ static int fib6_rule_action(struct fib_r
25387                                                ip6_dst_idev(&rt->dst)->dev,
25388                                                &flp6->daddr,
25389                                                rt6_flags2srcprefs(flags),
25390 -                                              &saddr))
25391 +                                              &saddr, NULL))
25392                                 goto again;
25393                         if (!ipv6_prefix_equal(&saddr, &r->src.addr,
25394                                                r->src.plen))
25395 diff -NurpP --minimal linux-3.6.10/net/ipv6/inet6_hashtables.c linux-3.6.10-vs2.3.4.5/net/ipv6/inet6_hashtables.c
25396 --- linux-3.6.10/net/ipv6/inet6_hashtables.c    2011-10-24 18:45:34.000000000 +0200
25397 +++ linux-3.6.10-vs2.3.4.5/net/ipv6/inet6_hashtables.c  2012-10-04 18:47:00.000000000 +0200
25398 @@ -16,6 +16,7 @@
25399  
25400  #include <linux/module.h>
25401  #include <linux/random.h>
25402 +#include <linux/vs_inet6.h>
25403  
25404  #include <net/inet_connection_sock.h>
25405  #include <net/inet_hashtables.h>
25406 @@ -83,7 +84,6 @@ struct sock *__inet6_lookup_established(
25407         unsigned int slot = hash & hashinfo->ehash_mask;
25408         struct inet_ehash_bucket *head = &hashinfo->ehash[slot];
25409  
25410 -
25411         rcu_read_lock();
25412  begin:
25413         sk_nulls_for_each_rcu(sk, node, &head->chain) {
25414 @@ -95,7 +95,7 @@ begin:
25415                                 sock_put(sk);
25416                                 goto begin;
25417                         }
25418 -               goto out;
25419 +                       goto out;
25420                 }
25421         }
25422         if (get_nulls_value(node) != slot)
25423 @@ -141,6 +141,9 @@ static inline int compute_score(struct s
25424                         if (!ipv6_addr_equal(&np->rcv_saddr, daddr))
25425                                 return -1;
25426                         score++;
25427 +               } else {
25428 +                       if (!v6_addr_in_nx_info(sk->sk_nx_info, daddr, -1))
25429 +                               return -1;
25430                 }
25431                 if (sk->sk_bound_dev_if) {
25432                         if (sk->sk_bound_dev_if != dif)
25433 diff -NurpP --minimal linux-3.6.10/net/ipv6/ip6_output.c linux-3.6.10-vs2.3.4.5/net/ipv6/ip6_output.c
25434 --- linux-3.6.10/net/ipv6/ip6_output.c  2012-10-04 15:27:50.000000000 +0200
25435 +++ linux-3.6.10-vs2.3.4.5/net/ipv6/ip6_output.c        2012-10-04 18:47:00.000000000 +0200
25436 @@ -966,7 +966,8 @@ static int ip6_dst_lookup_tail(struct so
25437                 struct rt6_info *rt = (struct rt6_info *) *dst;
25438                 err = ip6_route_get_saddr(net, rt, &fl6->daddr,
25439                                           sk ? inet6_sk(sk)->srcprefs : 0,
25440 -                                         &fl6->saddr);
25441 +                                         &fl6->saddr,
25442 +                                         sk ? sk->sk_nx_info : NULL);
25443                 if (err)
25444                         goto out_err_release;
25445         }
25446 diff -NurpP --minimal linux-3.6.10/net/ipv6/ndisc.c linux-3.6.10-vs2.3.4.5/net/ipv6/ndisc.c
25447 --- linux-3.6.10/net/ipv6/ndisc.c       2012-12-11 12:37:04.000000000 +0100
25448 +++ linux-3.6.10-vs2.3.4.5/net/ipv6/ndisc.c     2012-12-08 01:36:33.000000000 +0100
25449 @@ -517,7 +517,7 @@ static void ndisc_send_na(struct net_dev
25450         } else {
25451                 if (ipv6_dev_get_saddr(dev_net(dev), dev, daddr,
25452                                        inet6_sk(dev_net(dev)->ipv6.ndisc_sk)->srcprefs,
25453 -                                      &tmpaddr))
25454 +                                      &tmpaddr, NULL))
25455                         return;
25456                 src_addr = &tmpaddr;
25457         }
25458 diff -NurpP --minimal linux-3.6.10/net/ipv6/raw.c linux-3.6.10-vs2.3.4.5/net/ipv6/raw.c
25459 --- linux-3.6.10/net/ipv6/raw.c 2012-10-04 15:27:50.000000000 +0200
25460 +++ linux-3.6.10-vs2.3.4.5/net/ipv6/raw.c       2012-10-04 18:47:00.000000000 +0200
25461 @@ -30,6 +30,7 @@
25462  #include <linux/icmpv6.h>
25463  #include <linux/netfilter.h>
25464  #include <linux/netfilter_ipv6.h>
25465 +#include <linux/vs_inet6.h>
25466  #include <linux/skbuff.h>
25467  #include <linux/compat.h>
25468  #include <asm/uaccess.h>
25469 @@ -284,6 +285,13 @@ static int rawv6_bind(struct sock *sk, s
25470                                 goto out_unlock;
25471                 }
25472  
25473 +               if (!v6_addr_in_nx_info(sk->sk_nx_info, &addr->sin6_addr, -1)) {
25474 +                       err = -EADDRNOTAVAIL;
25475 +                       if (dev)
25476 +                               dev_put(dev);
25477 +                       goto out;
25478 +               }
25479 +
25480                 /* ipv4 addr of the socket is invalid.  Only the
25481                  * unspecified and mapped address have a v4 equivalent.
25482                  */
25483 diff -NurpP --minimal linux-3.6.10/net/ipv6/route.c linux-3.6.10-vs2.3.4.5/net/ipv6/route.c
25484 --- linux-3.6.10/net/ipv6/route.c       2012-12-11 12:37:04.000000000 +0100
25485 +++ linux-3.6.10-vs2.3.4.5/net/ipv6/route.c     2012-12-08 01:36:33.000000000 +0100
25486 @@ -57,6 +57,7 @@
25487  #include <net/xfrm.h>
25488  #include <net/netevent.h>
25489  #include <net/netlink.h>
25490 +#include <linux/vs_inet6.h>
25491  
25492  #include <asm/uaccess.h>
25493  
25494 @@ -2112,15 +2113,17 @@ int ip6_route_get_saddr(struct net *net,
25495                         struct rt6_info *rt,
25496                         const struct in6_addr *daddr,
25497                         unsigned int prefs,
25498 -                       struct in6_addr *saddr)
25499 +                       struct in6_addr *saddr,
25500 +                       struct nx_info *nxi)
25501  {
25502         struct inet6_dev *idev = ip6_dst_idev((struct dst_entry*)rt);
25503         int err = 0;
25504 -       if (rt->rt6i_prefsrc.plen)
25505 +       if (rt->rt6i_prefsrc.plen && (!nxi ||
25506 +           v6_addr_in_nx_info(nxi, &rt->rt6i_prefsrc.addr, NXA_TYPE_ADDR)))
25507                 *saddr = rt->rt6i_prefsrc.addr;
25508         else
25509                 err = ipv6_dev_get_saddr(net, idev ? idev->dev : NULL,
25510 -                                        daddr, prefs, saddr);
25511 +                                        daddr, prefs, saddr, nxi);
25512         return err;
25513  }
25514  
25515 @@ -2456,7 +2459,8 @@ static int rt6_fill_node(struct net *net
25516                                 goto nla_put_failure;
25517         } else if (dst) {
25518                 struct in6_addr saddr_buf;
25519 -               if (ip6_route_get_saddr(net, rt, dst, 0, &saddr_buf) == 0 &&
25520 +               if (ip6_route_get_saddr(net, rt, dst, 0, &saddr_buf,
25521 +                   (skb->sk ? skb->sk->sk_nx_info : NULL)) == 0 &&
25522                     nla_put(skb, RTA_PREFSRC, 16, &saddr_buf))
25523                         goto nla_put_failure;
25524         }
25525 @@ -2674,6 +2678,7 @@ static int rt6_info_route(struct rt6_inf
25526         struct seq_file *m = p_arg;
25527         struct neighbour *n;
25528  
25529 +       /* FIXME: check for network context? */
25530         seq_printf(m, "%pi6 %02x ", &rt->rt6i_dst.addr, rt->rt6i_dst.plen);
25531  
25532  #ifdef CONFIG_IPV6_SUBTREES
25533 diff -NurpP --minimal linux-3.6.10/net/ipv6/tcp_ipv6.c linux-3.6.10-vs2.3.4.5/net/ipv6/tcp_ipv6.c
25534 --- linux-3.6.10/net/ipv6/tcp_ipv6.c    2012-12-11 12:37:04.000000000 +0100
25535 +++ linux-3.6.10-vs2.3.4.5/net/ipv6/tcp_ipv6.c  2012-11-06 18:43:41.000000000 +0100
25536 @@ -71,6 +71,7 @@
25537  
25538  #include <linux/crypto.h>
25539  #include <linux/scatterlist.h>
25540 +#include <linux/vs_inet6.h>
25541  
25542  static void    tcp_v6_send_reset(struct sock *sk, struct sk_buff *skb);
25543  static void    tcp_v6_reqsk_send_ack(struct sock *sk, struct sk_buff *skb,
25544 @@ -175,8 +176,15 @@ static int tcp_v6_connect(struct sock *s
25545          *      connect() to INADDR_ANY means loopback (BSD'ism).
25546          */
25547  
25548 -       if(ipv6_addr_any(&usin->sin6_addr))
25549 -               usin->sin6_addr.s6_addr[15] = 0x1;
25550 +       if(ipv6_addr_any(&usin->sin6_addr)) {
25551 +               struct nx_info *nxi =  sk->sk_nx_info;
25552 +
25553 +               if (nxi && nx_info_has_v6(nxi))
25554 +                       /* FIXME: remap lback? */
25555 +                       usin->sin6_addr = nxi->v6.ip;
25556 +               else
25557 +                       usin->sin6_addr.s6_addr[15] = 0x1;
25558 +       }
25559  
25560         addr_type = ipv6_addr_type(&usin->sin6_addr);
25561  
25562 diff -NurpP --minimal linux-3.6.10/net/ipv6/udp.c linux-3.6.10-vs2.3.4.5/net/ipv6/udp.c
25563 --- linux-3.6.10/net/ipv6/udp.c 2012-10-04 15:27:50.000000000 +0200
25564 +++ linux-3.6.10-vs2.3.4.5/net/ipv6/udp.c       2012-10-04 18:56:03.000000000 +0200
25565 @@ -45,42 +45,68 @@
25566  #include <net/tcp_states.h>
25567  #include <net/ip6_checksum.h>
25568  #include <net/xfrm.h>
25569 +#include <linux/vs_inet6.h>
25570  
25571  #include <linux/proc_fs.h>
25572  #include <linux/seq_file.h>
25573  #include <trace/events/skb.h>
25574  #include "udp_impl.h"
25575  
25576 -int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
25577 +int ipv6_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2)
25578  {
25579 -       const struct in6_addr *sk_rcv_saddr6 = &inet6_sk(sk)->rcv_saddr;
25580 +       const struct in6_addr *sk1_rcv_saddr6 = &inet6_sk(sk1)->rcv_saddr;
25581         const struct in6_addr *sk2_rcv_saddr6 = inet6_rcv_saddr(sk2);
25582 -       __be32 sk1_rcv_saddr = sk_rcv_saddr(sk);
25583 +       __be32 sk1_rcv_saddr = sk_rcv_saddr(sk1);
25584         __be32 sk2_rcv_saddr = sk_rcv_saddr(sk2);
25585 -       int sk_ipv6only = ipv6_only_sock(sk);
25586 +       int sk1_ipv6only = ipv6_only_sock(sk1);
25587         int sk2_ipv6only = inet_v6_ipv6only(sk2);
25588 -       int addr_type = ipv6_addr_type(sk_rcv_saddr6);
25589 +       int addr_type = ipv6_addr_type(sk1_rcv_saddr6);
25590         int addr_type2 = sk2_rcv_saddr6 ? ipv6_addr_type(sk2_rcv_saddr6) : IPV6_ADDR_MAPPED;
25591  
25592         /* if both are mapped, treat as IPv4 */
25593 -       if (addr_type == IPV6_ADDR_MAPPED && addr_type2 == IPV6_ADDR_MAPPED)
25594 -               return (!sk2_ipv6only &&
25595 +       if (addr_type == IPV6_ADDR_MAPPED && addr_type2 == IPV6_ADDR_MAPPED) {
25596 +               if (!sk2_ipv6only &&
25597                         (!sk1_rcv_saddr || !sk2_rcv_saddr ||
25598 -                         sk1_rcv_saddr == sk2_rcv_saddr));
25599 +                         sk1_rcv_saddr == sk2_rcv_saddr))
25600 +                       goto vs_v4;
25601 +               else
25602 +                       return 0;
25603 +       }
25604  
25605         if (addr_type2 == IPV6_ADDR_ANY &&
25606             !(sk2_ipv6only && addr_type == IPV6_ADDR_MAPPED))
25607 -               return 1;
25608 +               goto vs;
25609  
25610         if (addr_type == IPV6_ADDR_ANY &&
25611 -           !(sk_ipv6only && addr_type2 == IPV6_ADDR_MAPPED))
25612 -               return 1;
25613 +           !(sk1_ipv6only && addr_type2 == IPV6_ADDR_MAPPED))
25614 +               goto vs;
25615  
25616         if (sk2_rcv_saddr6 &&
25617 -           ipv6_addr_equal(sk_rcv_saddr6, sk2_rcv_saddr6))
25618 -               return 1;
25619 +           ipv6_addr_equal(sk1_rcv_saddr6, sk2_rcv_saddr6))
25620 +               goto vs;
25621  
25622         return 0;
25623 +
25624 +vs_v4:
25625 +       if (!sk1_rcv_saddr && !sk2_rcv_saddr)
25626 +               return nx_v4_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info);
25627 +       if (!sk2_rcv_saddr)
25628 +               return v4_addr_in_nx_info(sk1->sk_nx_info, sk2_rcv_saddr, -1);
25629 +       if (!sk1_rcv_saddr)
25630 +               return v4_addr_in_nx_info(sk2->sk_nx_info, sk1_rcv_saddr, -1);
25631 +       return 1;
25632 +vs:
25633 +       if (addr_type2 == IPV6_ADDR_ANY && addr_type == IPV6_ADDR_ANY)
25634 +               return nx_v6_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info);
25635 +       else if (addr_type2 == IPV6_ADDR_ANY)
25636 +               return v6_addr_in_nx_info(sk2->sk_nx_info, sk1_rcv_saddr6, -1);
25637 +       else if (addr_type == IPV6_ADDR_ANY) {
25638 +               if (addr_type2 == IPV6_ADDR_MAPPED)
25639 +                       return nx_v4_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info);
25640 +               else
25641 +                       return v6_addr_in_nx_info(sk1->sk_nx_info, sk2_rcv_saddr6, -1);
25642 +       }
25643 +       return 1;
25644  }
25645  
25646  static unsigned int udp6_portaddr_hash(struct net *net,
25647 @@ -144,6 +170,10 @@ static inline int compute_score(struct s
25648                         if (!ipv6_addr_equal(&np->rcv_saddr, daddr))
25649                                 return -1;
25650                         score++;
25651 +               } else {
25652 +                       /* block non nx_info ips */
25653 +                       if (!v6_addr_in_nx_info(sk->sk_nx_info, daddr, -1))
25654 +                               return -1;
25655                 }
25656                 if (!ipv6_addr_any(&np->daddr)) {
25657                         if (!ipv6_addr_equal(&np->daddr, saddr))
25658 diff -NurpP --minimal linux-3.6.10/net/ipv6/xfrm6_policy.c linux-3.6.10-vs2.3.4.5/net/ipv6/xfrm6_policy.c
25659 --- linux-3.6.10/net/ipv6/xfrm6_policy.c        2012-10-04 15:27:50.000000000 +0200
25660 +++ linux-3.6.10-vs2.3.4.5/net/ipv6/xfrm6_policy.c      2012-10-04 18:47:00.000000000 +0200
25661 @@ -63,7 +63,7 @@ static int xfrm6_get_saddr(struct net *n
25662         dev = ip6_dst_idev(dst)->dev;
25663         ipv6_dev_get_saddr(dev_net(dev), dev,
25664                            (struct in6_addr *)&daddr->a6, 0,
25665 -                          (struct in6_addr *)&saddr->a6);
25666 +                          (struct in6_addr *)&saddr->a6, NULL);
25667         dst_release(dst);
25668         return 0;
25669  }
25670 diff -NurpP --minimal linux-3.6.10/net/netfilter/ipvs/ip_vs_xmit.c linux-3.6.10-vs2.3.4.5/net/netfilter/ipvs/ip_vs_xmit.c
25671 --- linux-3.6.10/net/netfilter/ipvs/ip_vs_xmit.c        2012-12-11 12:37:04.000000000 +0100
25672 +++ linux-3.6.10-vs2.3.4.5/net/netfilter/ipvs/ip_vs_xmit.c      2012-11-06 18:43:41.000000000 +0100
25673 @@ -231,7 +231,7 @@ __ip_vs_route_output_v6(struct net *net,
25674                 return dst;
25675         if (ipv6_addr_any(&fl6.saddr) &&
25676             ipv6_dev_get_saddr(net, ip6_dst_idev(dst)->dev,
25677 -                              &fl6.daddr, 0, &fl6.saddr) < 0)
25678 +                              &fl6.daddr, 0, &fl6.saddr, NULL) < 0)
25679                 goto out_err;
25680         if (do_xfrm) {
25681                 dst = xfrm_lookup(net, dst, flowi6_to_flowi(&fl6), NULL, 0);
25682 diff -NurpP --minimal linux-3.6.10/net/netlink/af_netlink.c linux-3.6.10-vs2.3.4.5/net/netlink/af_netlink.c
25683 --- linux-3.6.10/net/netlink/af_netlink.c       2012-12-11 12:37:04.000000000 +0100
25684 +++ linux-3.6.10-vs2.3.4.5/net/netlink/af_netlink.c     2012-12-08 01:36:33.000000000 +0100
25685 @@ -55,6 +55,9 @@
25686  #include <linux/types.h>
25687  #include <linux/audit.h>
25688  #include <linux/mutex.h>
25689 +#include <linux/vs_context.h>
25690 +#include <linux/vs_network.h>
25691 +#include <linux/vs_limit.h>
25692  
25693  #include <net/net_namespace.h>
25694  #include <net/sock.h>
25695 @@ -1983,6 +1986,8 @@ static struct sock *netlink_seq_socket_i
25696                         sk_for_each(s, node, &hash->table[j]) {
25697                                 if (sock_net(s) != seq_file_net(seq))
25698                                         continue;
25699 +                               if (!nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT))
25700 +                                       continue;
25701                                 if (off == pos) {
25702                                         iter->link = i;
25703                                         iter->hash_idx = j;
25704 @@ -2017,7 +2022,8 @@ static void *netlink_seq_next(struct seq
25705         s = v;
25706         do {
25707                 s = sk_next(s);
25708 -       } while (s && sock_net(s) != seq_file_net(seq));
25709 +       } while (s && (sock_net(s) != seq_file_net(seq) ||
25710 +               !nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT)));
25711         if (s)
25712                 return s;
25713  
25714 @@ -2029,7 +2035,8 @@ static void *netlink_seq_next(struct seq
25715  
25716                 for (; j <= hash->mask; j++) {
25717                         s = sk_head(&hash->table[j]);
25718 -                       while (s && sock_net(s) != seq_file_net(seq))
25719 +                       while (s && (sock_net(s) != seq_file_net(seq) ||
25720 +                               !nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT)))
25721                                 s = sk_next(s);
25722                         if (s) {
25723                                 iter->link = i;
25724 diff -NurpP --minimal linux-3.6.10/net/socket.c linux-3.6.10-vs2.3.4.5/net/socket.c
25725 --- linux-3.6.10/net/socket.c   2012-10-04 15:27:51.000000000 +0200
25726 +++ linux-3.6.10-vs2.3.4.5/net/socket.c 2012-10-04 18:47:00.000000000 +0200
25727 @@ -98,6 +98,10 @@
25728  
25729  #include <net/sock.h>
25730  #include <linux/netfilter.h>
25731 +#include <linux/vs_base.h>
25732 +#include <linux/vs_socket.h>
25733 +#include <linux/vs_inet.h>
25734 +#include <linux/vs_inet6.h>
25735  
25736  #include <linux/if_tun.h>
25737  #include <linux/ipv6_route.h>
25738 @@ -552,6 +556,7 @@ static inline int __sock_sendmsg_nosec(s
25739                                        struct msghdr *msg, size_t size)
25740  {
25741         struct sock_iocb *si = kiocb_to_siocb(iocb);
25742 +       size_t len;
25743  
25744         sock_update_classid(sock->sk);
25745  
25746 @@ -560,7 +565,22 @@ static inline int __sock_sendmsg_nosec(s
25747         si->msg = msg;
25748         si->size = size;
25749  
25750 -       return sock->ops->sendmsg(iocb, sock, msg, size);
25751 +       len = sock->ops->sendmsg(iocb, sock, msg, size);
25752 +       if (sock->sk) {
25753 +               if (len == size)
25754 +                       vx_sock_send(sock->sk, size);
25755 +               else
25756 +                       vx_sock_fail(sock->sk, size);
25757 +       }
25758 +       vxdprintk(VXD_CBIT(net, 7),
25759 +               "__sock_sendmsg: %p[%p,%p,%p;%d/%d]:%d/%zu",
25760 +               sock, sock->sk,
25761 +               (sock->sk)?sock->sk->sk_nx_info:0,
25762 +               (sock->sk)?sock->sk->sk_vx_info:0,
25763 +               (sock->sk)?sock->sk->sk_xid:0,
25764 +               (sock->sk)?sock->sk->sk_nid:0,
25765 +               (unsigned int)size, len);
25766 +       return len;
25767  }
25768  
25769  static inline int __sock_sendmsg(struct kiocb *iocb, struct socket *sock,
25770 @@ -716,6 +736,7 @@ static inline int __sock_recvmsg_nosec(s
25771                                        struct msghdr *msg, size_t size, int flags)
25772  {
25773         struct sock_iocb *si = kiocb_to_siocb(iocb);
25774 +       int len;
25775  
25776         sock_update_classid(sock->sk);
25777  
25778 @@ -725,7 +746,18 @@ static inline int __sock_recvmsg_nosec(s
25779         si->size = size;
25780         si->flags = flags;
25781  
25782 -       return sock->ops->recvmsg(iocb, sock, msg, size, flags);
25783 +       len = sock->ops->recvmsg(iocb, sock, msg, size, flags);
25784 +       if ((len >= 0) && sock->sk)
25785 +               vx_sock_recv(sock->sk, len);
25786 +       vxdprintk(VXD_CBIT(net, 7),
25787 +               "__sock_recvmsg: %p[%p,%p,%p;%d/%d]:%d/%d",
25788 +               sock, sock->sk,
25789 +               (sock->sk)?sock->sk->sk_nx_info:0,
25790 +               (sock->sk)?sock->sk->sk_vx_info:0,
25791 +               (sock->sk)?sock->sk->sk_xid:0,
25792 +               (sock->sk)?sock->sk->sk_nid:0,
25793 +               (unsigned int)size, len);
25794 +       return len;
25795  }
25796  
25797  static inline int __sock_recvmsg(struct kiocb *iocb, struct socket *sock,
25798 @@ -1210,6 +1242,13 @@ int __sock_create(struct net *net, int f
25799         if (type < 0 || type >= SOCK_MAX)
25800                 return -EINVAL;
25801  
25802 +       if (!nx_check(0, VS_ADMIN)) {
25803 +               if (family == PF_INET && !current_nx_info_has_v4())
25804 +                       return -EAFNOSUPPORT;
25805 +               if (family == PF_INET6 && !current_nx_info_has_v6())
25806 +                       return -EAFNOSUPPORT;
25807 +       }
25808 +
25809         /* Compatibility.
25810  
25811            This uglymoron is moved from INET layer to here to avoid
25812 @@ -1344,6 +1383,7 @@ SYSCALL_DEFINE3(socket, int, family, int
25813         if (retval < 0)
25814                 goto out;
25815  
25816 +       set_bit(SOCK_USER_SOCKET, &sock->flags);
25817         retval = sock_map_fd(sock, flags & (O_CLOEXEC | O_NONBLOCK));
25818         if (retval < 0)
25819                 goto out_release;
25820 @@ -1385,10 +1425,12 @@ SYSCALL_DEFINE4(socketpair, int, family,
25821         err = sock_create(family, type, protocol, &sock1);
25822         if (err < 0)
25823                 goto out;
25824 +       set_bit(SOCK_USER_SOCKET, &sock1->flags);
25825  
25826         err = sock_create(family, type, protocol, &sock2);
25827         if (err < 0)
25828                 goto out_release_1;
25829 +       set_bit(SOCK_USER_SOCKET, &sock2->flags);
25830  
25831         err = sock1->ops->socketpair(sock1, sock2);
25832         if (err < 0)
25833 diff -NurpP --minimal linux-3.6.10/net/sunrpc/auth.c linux-3.6.10-vs2.3.4.5/net/sunrpc/auth.c
25834 --- linux-3.6.10/net/sunrpc/auth.c      2012-10-04 15:27:51.000000000 +0200
25835 +++ linux-3.6.10-vs2.3.4.5/net/sunrpc/auth.c    2012-10-04 18:47:00.000000000 +0200
25836 @@ -15,6 +15,7 @@
25837  #include <linux/sunrpc/clnt.h>
25838  #include <linux/sunrpc/gss_api.h>
25839  #include <linux/spinlock.h>
25840 +#include <linux/vs_tag.h>
25841  
25842  #ifdef RPC_DEBUG
25843  # define RPCDBG_FACILITY       RPCDBG_AUTH
25844 @@ -481,6 +482,7 @@ rpcauth_lookupcred(struct rpc_auth *auth
25845         memset(&acred, 0, sizeof(acred));
25846         acred.uid = cred->fsuid;
25847         acred.gid = cred->fsgid;
25848 +       acred.tag = dx_current_tag();
25849         acred.group_info = get_group_info(((struct cred *)cred)->group_info);
25850  
25851         ret = auth->au_ops->lookup_cred(auth, &acred, flags);
25852 @@ -521,6 +523,7 @@ rpcauth_bind_root_cred(struct rpc_task *
25853         struct auth_cred acred = {
25854                 .uid = 0,
25855                 .gid = 0,
25856 +               .tag = dx_current_tag(),
25857         };
25858  
25859         dprintk("RPC: %5u looking up %s cred\n",
25860 diff -NurpP --minimal linux-3.6.10/net/sunrpc/auth_unix.c linux-3.6.10-vs2.3.4.5/net/sunrpc/auth_unix.c
25861 --- linux-3.6.10/net/sunrpc/auth_unix.c 2012-07-22 23:39:49.000000000 +0200
25862 +++ linux-3.6.10-vs2.3.4.5/net/sunrpc/auth_unix.c       2012-10-04 18:47:00.000000000 +0200
25863 @@ -13,11 +13,13 @@
25864  #include <linux/sunrpc/clnt.h>
25865  #include <linux/sunrpc/auth.h>
25866  #include <linux/user_namespace.h>
25867 +#include <linux/vs_tag.h>
25868  
25869  #define NFS_NGROUPS    16
25870  
25871  struct unx_cred {
25872         struct rpc_cred         uc_base;
25873 +       tag_t                   uc_tag;
25874         gid_t                   uc_gid;
25875         gid_t                   uc_gids[NFS_NGROUPS];
25876  };
25877 @@ -79,6 +81,7 @@ unx_create_cred(struct rpc_auth *auth, s
25878                 groups = NFS_NGROUPS;
25879  
25880         cred->uc_gid = acred->gid;
25881 +       cred->uc_tag = acred->tag;
25882         for (i = 0; i < groups; i++) {
25883                 gid_t gid;
25884                 gid = from_kgid(&init_user_ns, GROUP_AT(acred->group_info, i));
25885 @@ -123,7 +126,9 @@ unx_match(struct auth_cred *acred, struc
25886         unsigned int i;
25887  
25888  
25889 -       if (cred->uc_uid != acred->uid || cred->uc_gid != acred->gid)
25890 +       if (cred->uc_uid != acred->uid ||
25891 +               cred->uc_gid != acred->gid ||
25892 +               cred->uc_tag != acred->tag)
25893                 return 0;
25894  
25895         if (acred->group_info != NULL)
25896 @@ -152,7 +157,7 @@ unx_marshal(struct rpc_task *task, __be3
25897         struct rpc_clnt *clnt = task->tk_client;
25898         struct unx_cred *cred = container_of(task->tk_rqstp->rq_cred, struct unx_cred, uc_base);
25899         __be32          *base, *hold;
25900 -       int             i;
25901 +       int             i, tag;
25902  
25903         *p++ = htonl(RPC_AUTH_UNIX);
25904         base = p++;
25905 @@ -162,9 +167,12 @@ unx_marshal(struct rpc_task *task, __be3
25906          * Copy the UTS nodename captured when the client was created.
25907          */
25908         p = xdr_encode_array(p, clnt->cl_nodename, clnt->cl_nodelen);
25909 +       tag = task->tk_client->cl_tag;
25910  
25911 -       *p++ = htonl((u32) cred->uc_uid);
25912 -       *p++ = htonl((u32) cred->uc_gid);
25913 +       *p++ = htonl((u32) TAGINO_UID(tag,
25914 +               cred->uc_uid, cred->uc_tag));
25915 +       *p++ = htonl((u32) TAGINO_GID(tag,
25916 +               cred->uc_gid, cred->uc_tag));
25917         hold = p++;
25918         for (i = 0; i < 16 && cred->uc_gids[i] != (gid_t) NOGROUP; i++)
25919                 *p++ = htonl((u32) cred->uc_gids[i]);
25920 diff -NurpP --minimal linux-3.6.10/net/sunrpc/clnt.c linux-3.6.10-vs2.3.4.5/net/sunrpc/clnt.c
25921 --- linux-3.6.10/net/sunrpc/clnt.c      2012-10-04 15:27:51.000000000 +0200
25922 +++ linux-3.6.10-vs2.3.4.5/net/sunrpc/clnt.c    2012-10-04 18:47:00.000000000 +0200
25923 @@ -31,6 +31,7 @@
25924  #include <linux/in6.h>
25925  #include <linux/un.h>
25926  #include <linux/rcupdate.h>
25927 +#include <linux/vs_cvirt.h>
25928  
25929  #include <linux/sunrpc/clnt.h>
25930  #include <linux/sunrpc/rpc_pipe_fs.h>
25931 @@ -481,6 +482,9 @@ struct rpc_clnt *rpc_create(struct rpc_c
25932         if (!(args->flags & RPC_CLNT_CREATE_QUIET))
25933                 clnt->cl_chatty = 1;
25934  
25935 +       /* TODO: handle RPC_CLNT_CREATE_TAGGED
25936 +       if (args->flags & RPC_CLNT_CREATE_TAGGED)
25937 +               clnt->cl_tag = 1; */
25938         return clnt;
25939  }
25940  EXPORT_SYMBOL_GPL(rpc_create);
25941 diff -NurpP --minimal linux-3.6.10/net/unix/af_unix.c linux-3.6.10-vs2.3.4.5/net/unix/af_unix.c
25942 --- linux-3.6.10/net/unix/af_unix.c     2012-10-04 15:27:51.000000000 +0200
25943 +++ linux-3.6.10-vs2.3.4.5/net/unix/af_unix.c   2012-10-04 18:59:36.000000000 +0200
25944 @@ -114,6 +114,8 @@
25945  #include <linux/mount.h>
25946  #include <net/checksum.h>
25947  #include <linux/security.h>
25948 +#include <linux/vs_context.h>
25949 +#include <linux/vs_limit.h>
25950  
25951  struct hlist_head unix_socket_table[2 * UNIX_HASH_SIZE];
25952  EXPORT_SYMBOL_GPL(unix_socket_table);
25953 @@ -271,6 +273,8 @@ static struct sock *__unix_find_socket_b
25954                 if (!net_eq(sock_net(s), net))
25955                         continue;
25956  
25957 +               if (!nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT))
25958 +                       continue;
25959                 if (u->addr->len == len &&
25960                     !memcmp(u->addr->name, sunname, len))
25961                         goto found;
25962 @@ -2258,6 +2262,8 @@ static struct sock *unix_from_bucket(str
25963         for (sk = sk_head(&unix_socket_table[bucket]); sk; sk = sk_next(sk)) {
25964                 if (sock_net(sk) != seq_file_net(seq))
25965                         continue;
25966 +               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
25967 +                       continue;
25968                 if (++count == offset)
25969                         break;
25970         }
25971 @@ -2275,6 +2281,8 @@ static struct sock *unix_next_socket(str
25972                 sk = sk_next(sk);
25973                 if (!sk)
25974                         goto next_bucket;
25975 +               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
25976 +                       continue;
25977                 if (sock_net(sk) == seq_file_net(seq))
25978                         return sk;
25979         }
25980 diff -NurpP --minimal linux-3.6.10/scripts/checksyscalls.sh linux-3.6.10-vs2.3.4.5/scripts/checksyscalls.sh
25981 --- linux-3.6.10/scripts/checksyscalls.sh       2012-10-04 15:27:51.000000000 +0200
25982 +++ linux-3.6.10-vs2.3.4.5/scripts/checksyscalls.sh     2012-10-04 18:47:00.000000000 +0200
25983 @@ -193,7 +193,6 @@ cat << EOF
25984  #define __IGNORE_afs_syscall
25985  #define __IGNORE_getpmsg
25986  #define __IGNORE_putpmsg
25987 -#define __IGNORE_vserver
25988  EOF
25989  }
25990  
25991 diff -NurpP --minimal linux-3.6.10/security/commoncap.c linux-3.6.10-vs2.3.4.5/security/commoncap.c
25992 --- linux-3.6.10/security/commoncap.c   2012-07-22 23:39:51.000000000 +0200
25993 +++ linux-3.6.10-vs2.3.4.5/security/commoncap.c 2012-10-04 18:47:00.000000000 +0200
25994 @@ -76,14 +76,20 @@ int cap_netlink_send(struct sock *sk, st
25995  int cap_capable(const struct cred *cred, struct user_namespace *targ_ns,
25996                 int cap, int audit)
25997  {
25998 +       struct vx_info *vxi = current_vx_info(); /* FIXME: get vxi from cred? */
25999 +
26000         for (;;) {
26001                 /* The owner of the user namespace has all caps. */
26002                 if (targ_ns != &init_user_ns && uid_eq(targ_ns->owner, cred->euid))
26003                         return 0;
26004  
26005                 /* Do we have the necessary capabilities? */
26006 -               if (targ_ns == cred->user_ns)
26007 -                       return cap_raised(cred->cap_effective, cap) ? 0 : -EPERM;
26008 +               if (targ_ns == cred->user_ns) {
26009 +                       if (vx_info_flags(vxi, VXF_STATE_SETUP, 0) &&
26010 +                           cap_raised(cred->cap_effective, cap))
26011 +                               return 0;
26012 +                       return vx_cap_raised(vxi, cred->cap_effective, cap) ? 0 : -EPERM;
26013 +               }
26014  
26015                 /* Have we tried all of the parent namespaces? */
26016                 if (targ_ns == &init_user_ns)
26017 @@ -619,7 +625,7 @@ int cap_inode_setxattr(struct dentry *de
26018  
26019         if (!strncmp(name, XATTR_SECURITY_PREFIX,
26020                      sizeof(XATTR_SECURITY_PREFIX) - 1) &&
26021 -           !capable(CAP_SYS_ADMIN))
26022 +               !vx_capable(CAP_SYS_ADMIN, VXC_FS_SECURITY))
26023                 return -EPERM;
26024         return 0;
26025  }
26026 @@ -645,7 +651,7 @@ int cap_inode_removexattr(struct dentry 
26027  
26028         if (!strncmp(name, XATTR_SECURITY_PREFIX,
26029                      sizeof(XATTR_SECURITY_PREFIX) - 1) &&
26030 -           !capable(CAP_SYS_ADMIN))
26031 +               !vx_capable(CAP_SYS_ADMIN, VXC_FS_SECURITY))
26032                 return -EPERM;
26033         return 0;
26034  }
26035 diff -NurpP --minimal linux-3.6.10/security/selinux/hooks.c linux-3.6.10-vs2.3.4.5/security/selinux/hooks.c
26036 --- linux-3.6.10/security/selinux/hooks.c       2012-10-04 15:27:53.000000000 +0200
26037 +++ linux-3.6.10-vs2.3.4.5/security/selinux/hooks.c     2012-10-04 18:47:00.000000000 +0200
26038 @@ -66,7 +66,6 @@
26039  #include <linux/dccp.h>
26040  #include <linux/quota.h>
26041  #include <linux/un.h>          /* for Unix socket types */
26042 -#include <net/af_unix.h>       /* for Unix socket types */
26043  #include <linux/parser.h>
26044  #include <linux/nfs_mount.h>
26045  #include <net/ipv6.h>
This page took 2.365486 seconds and 3 git commands to generate.