]> git.pld-linux.org Git - packages/kernel.git/blob - kernel-vserver-2.3.patch
a4fe6a856568cc168406237192c5256ec3c90e08
[packages/kernel.git] / kernel-vserver-2.3.patch
1 diff -NurpP --minimal linux-3.0.25/Documentation/vserver/debug.txt linux-3.0.25-vs2.3.2.3/Documentation/vserver/debug.txt
2 --- linux-3.0.25/Documentation/vserver/debug.txt        1970-01-01 01:00:00.000000000 +0100
3 +++ linux-3.0.25-vs2.3.2.3/Documentation/vserver/debug.txt      2011-06-10 22:11:24.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.0.25/arch/alpha/Kconfig linux-3.0.25-vs2.3.2.3/arch/alpha/Kconfig
160 --- linux-3.0.25/arch/alpha/Kconfig     2011-07-22 11:17:32.000000000 +0200
161 +++ linux-3.0.25-vs2.3.2.3/arch/alpha/Kconfig   2011-06-10 22:11:24.000000000 +0200
162 @@ -668,6 +668,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.0.25/arch/alpha/kernel/entry.S linux-3.0.25-vs2.3.2.3/arch/alpha/kernel/entry.S
172 --- linux-3.0.25/arch/alpha/kernel/entry.S      2010-10-21 13:06:45.000000000 +0200
173 +++ linux-3.0.25-vs2.3.2.3/arch/alpha/kernel/entry.S    2011-06-10 22:11:24.000000000 +0200
174 @@ -860,24 +860,15 @@ sys_getxgid:
175         .globl  sys_getxpid
176         .ent    sys_getxpid
177  sys_getxpid:
178 +       lda     $sp, -16($sp)
179 +       stq     $26, 0($sp)
180         .prologue 0
181 -       ldq     $2, TI_TASK($8)
182  
183 -       /* See linux/kernel/timer.c sys_getppid for discussion
184 -          about this loop.  */
185 -       ldq     $3, TASK_GROUP_LEADER($2)
186 -       ldq     $4, TASK_REAL_PARENT($3)
187 -       ldl     $0, TASK_TGID($2)
188 -1:     ldl     $1, TASK_TGID($4)
189 -#ifdef CONFIG_SMP
190 -       mov     $4, $5
191 -       mb
192 -       ldq     $3, TASK_GROUP_LEADER($2)
193 -       ldq     $4, TASK_REAL_PARENT($3)
194 -       cmpeq   $4, $5, $5
195 -       beq     $5, 1b
196 -#endif
197 -       stq     $1, 80($sp)
198 +       lda     $16, 96($sp)
199 +       jsr     $26, do_getxpid
200 +       ldq     $26, 0($sp)
201 +
202 +       lda     $sp, 16($sp)
203         ret
204  .end sys_getxpid
205  
206 diff -NurpP --minimal linux-3.0.25/arch/alpha/kernel/ptrace.c linux-3.0.25-vs2.3.2.3/arch/alpha/kernel/ptrace.c
207 --- linux-3.0.25/arch/alpha/kernel/ptrace.c     2011-01-05 21:48:40.000000000 +0100
208 +++ linux-3.0.25-vs2.3.2.3/arch/alpha/kernel/ptrace.c   2011-06-10 22:11:24.000000000 +0200
209 @@ -13,6 +13,7 @@
210  #include <linux/user.h>
211  #include <linux/security.h>
212  #include <linux/signal.h>
213 +#include <linux/vs_base.h>
214  
215  #include <asm/uaccess.h>
216  #include <asm/pgtable.h>
217 diff -NurpP --minimal linux-3.0.25/arch/alpha/kernel/systbls.S linux-3.0.25-vs2.3.2.3/arch/alpha/kernel/systbls.S
218 --- linux-3.0.25/arch/alpha/kernel/systbls.S    2011-07-22 11:17:32.000000000 +0200
219 +++ linux-3.0.25-vs2.3.2.3/arch/alpha/kernel/systbls.S  2011-06-10 22:11:24.000000000 +0200
220 @@ -446,7 +446,7 @@ sys_call_table:
221         .quad sys_stat64                        /* 425 */
222         .quad sys_lstat64
223         .quad sys_fstat64
224 -       .quad sys_ni_syscall                    /* sys_vserver */
225 +       .quad sys_vserver                       /* sys_vserver */
226         .quad sys_ni_syscall                    /* sys_mbind */
227         .quad sys_ni_syscall                    /* sys_get_mempolicy */
228         .quad sys_ni_syscall                    /* sys_set_mempolicy */
229 diff -NurpP --minimal linux-3.0.25/arch/alpha/kernel/traps.c linux-3.0.25-vs2.3.2.3/arch/alpha/kernel/traps.c
230 --- linux-3.0.25/arch/alpha/kernel/traps.c      2010-10-21 13:06:46.000000000 +0200
231 +++ linux-3.0.25-vs2.3.2.3/arch/alpha/kernel/traps.c    2011-06-10 22:11:24.000000000 +0200
232 @@ -183,7 +183,8 @@ die_if_kernel(char * str, struct pt_regs
233  #ifdef CONFIG_SMP
234         printk("CPU %d ", hard_smp_processor_id());
235  #endif
236 -       printk("%s(%d): %s %ld\n", current->comm, task_pid_nr(current), str, err);
237 +       printk("%s(%d[#%u]): %s %ld\n", current->comm,
238 +               task_pid_nr(current), current->xid, str, err);
239         dik_show_regs(regs, r9_15);
240         add_taint(TAINT_DIE);
241         dik_show_trace((unsigned long *)(regs+1));
242 diff -NurpP --minimal linux-3.0.25/arch/arm/Kconfig linux-3.0.25-vs2.3.2.3/arch/arm/Kconfig
243 --- linux-3.0.25/arch/arm/Kconfig       2012-03-19 21:16:33.000000000 +0100
244 +++ linux-3.0.25-vs2.3.2.3/arch/arm/Kconfig     2012-03-15 13:32:35.000000000 +0100
245 @@ -2061,6 +2061,8 @@ source "fs/Kconfig"
246  
247  source "arch/arm/Kconfig.debug"
248  
249 +source "kernel/vserver/Kconfig"
250 +
251  source "security/Kconfig"
252  
253  source "crypto/Kconfig"
254 diff -NurpP --minimal linux-3.0.25/arch/arm/kernel/calls.S linux-3.0.25-vs2.3.2.3/arch/arm/kernel/calls.S
255 --- linux-3.0.25/arch/arm/kernel/calls.S        2011-07-22 11:17:32.000000000 +0200
256 +++ linux-3.0.25-vs2.3.2.3/arch/arm/kernel/calls.S      2011-06-10 22:11:24.000000000 +0200
257 @@ -322,7 +322,7 @@
258  /* 310 */      CALL(sys_request_key)
259                 CALL(sys_keyctl)
260                 CALL(ABI(sys_semtimedop, sys_oabi_semtimedop))
261 -/* vserver */  CALL(sys_ni_syscall)
262 +               CALL(sys_vserver)
263                 CALL(sys_ioprio_set)
264  /* 315 */      CALL(sys_ioprio_get)
265                 CALL(sys_inotify_init)
266 diff -NurpP --minimal linux-3.0.25/arch/arm/kernel/process.c linux-3.0.25-vs2.3.2.3/arch/arm/kernel/process.c
267 --- linux-3.0.25/arch/arm/kernel/process.c      2012-03-19 21:16:33.000000000 +0100
268 +++ linux-3.0.25-vs2.3.2.3/arch/arm/kernel/process.c    2011-12-19 15:55:53.000000000 +0100
269 @@ -318,7 +318,8 @@ void __show_regs(struct pt_regs *regs)
270  void show_regs(struct pt_regs * regs)
271  {
272         printk("\n");
273 -       printk("Pid: %d, comm: %20s\n", task_pid_nr(current), current->comm);
274 +       printk("Pid: %d[#%u], comm: %20s\n",
275 +               task_pid_nr(current), current->xid, current->comm);
276         __show_regs(regs);
277         __backtrace();
278  }
279 diff -NurpP --minimal linux-3.0.25/arch/arm/kernel/traps.c linux-3.0.25-vs2.3.2.3/arch/arm/kernel/traps.c
280 --- linux-3.0.25/arch/arm/kernel/traps.c        2011-07-22 11:17:32.000000000 +0200
281 +++ linux-3.0.25-vs2.3.2.3/arch/arm/kernel/traps.c      2011-06-22 12:39:12.000000000 +0200
282 @@ -242,8 +242,8 @@ static int __die(const char *str, int er
283  
284         print_modules();
285         __show_regs(regs);
286 -       printk(KERN_EMERG "Process %.*s (pid: %d, stack limit = 0x%p)\n",
287 -               TASK_COMM_LEN, tsk->comm, task_pid_nr(tsk), thread + 1);
288 +       printk(KERN_EMERG "Process %.*s (pid: %d:#%u, stack limit = 0x%p)\n",
289 +               TASK_COMM_LEN, tsk->comm, task_pid_nr(tsk), tsk->xid, thread + 1);
290  
291         if (!user_mode(regs) || in_interrupt()) {
292                 dump_mem(KERN_EMERG, "Stack: ", regs->ARM_sp,
293 diff -NurpP --minimal linux-3.0.25/arch/cris/Kconfig linux-3.0.25-vs2.3.2.3/arch/cris/Kconfig
294 --- linux-3.0.25/arch/cris/Kconfig      2011-07-22 11:17:35.000000000 +0200
295 +++ linux-3.0.25-vs2.3.2.3/arch/cris/Kconfig    2011-06-10 22:11:24.000000000 +0200
296 @@ -678,6 +678,8 @@ source "drivers/staging/Kconfig"
297  
298  source "arch/cris/Kconfig.debug"
299  
300 +source "kernel/vserver/Kconfig"
301 +
302  source "security/Kconfig"
303  
304  source "crypto/Kconfig"
305 diff -NurpP --minimal linux-3.0.25/arch/frv/kernel/kernel_thread.S linux-3.0.25-vs2.3.2.3/arch/frv/kernel/kernel_thread.S
306 --- linux-3.0.25/arch/frv/kernel/kernel_thread.S        2008-12-25 00:26:37.000000000 +0100
307 +++ linux-3.0.25-vs2.3.2.3/arch/frv/kernel/kernel_thread.S      2011-06-10 22:11:24.000000000 +0200
308 @@ -37,7 +37,7 @@ kernel_thread:
309  
310         # start by forking the current process, but with shared VM
311         setlos.p        #__NR_clone,gr7         ; syscall number
312 -       ori             gr10,#CLONE_VM,gr8      ; first syscall arg     [clone_flags]
313 +       ori             gr10,#CLONE_KT,gr8      ; first syscall arg     [clone_flags]
314         sethi.p         #0xe4e4,gr9             ; second syscall arg    [newsp]
315         setlo           #0xe4e4,gr9
316         setlos.p        #0,gr10                 ; third syscall arg     [parent_tidptr]
317 diff -NurpP --minimal linux-3.0.25/arch/h8300/Kconfig linux-3.0.25-vs2.3.2.3/arch/h8300/Kconfig
318 --- linux-3.0.25/arch/h8300/Kconfig     2011-07-22 11:17:35.000000000 +0200
319 +++ linux-3.0.25-vs2.3.2.3/arch/h8300/Kconfig   2011-06-10 22:11:24.000000000 +0200
320 @@ -213,6 +213,8 @@ source "fs/Kconfig"
321  
322  source "arch/h8300/Kconfig.debug"
323  
324 +source "kernel/vserver/Kconfig"
325 +
326  source "security/Kconfig"
327  
328  source "crypto/Kconfig"
329 diff -NurpP --minimal linux-3.0.25/arch/ia64/Kconfig linux-3.0.25-vs2.3.2.3/arch/ia64/Kconfig
330 --- linux-3.0.25/arch/ia64/Kconfig      2011-07-22 11:17:35.000000000 +0200
331 +++ linux-3.0.25-vs2.3.2.3/arch/ia64/Kconfig    2011-06-10 22:11:24.000000000 +0200
332 @@ -671,6 +671,8 @@ source "fs/Kconfig"
333  
334  source "arch/ia64/Kconfig.debug"
335  
336 +source "kernel/vserver/Kconfig"
337 +
338  source "security/Kconfig"
339  
340  source "crypto/Kconfig"
341 diff -NurpP --minimal linux-3.0.25/arch/ia64/include/asm/tlb.h linux-3.0.25-vs2.3.2.3/arch/ia64/include/asm/tlb.h
342 --- linux-3.0.25/arch/ia64/include/asm/tlb.h    2011-07-22 11:17:35.000000000 +0200
343 +++ linux-3.0.25-vs2.3.2.3/arch/ia64/include/asm/tlb.h  2011-06-10 22:11:24.000000000 +0200
344 @@ -40,6 +40,7 @@
345  #include <linux/mm.h>
346  #include <linux/pagemap.h>
347  #include <linux/swap.h>
348 +#include <linux/vs_memory.h>
349  
350  #include <asm/pgalloc.h>
351  #include <asm/processor.h>
352 diff -NurpP --minimal linux-3.0.25/arch/ia64/kernel/entry.S linux-3.0.25-vs2.3.2.3/arch/ia64/kernel/entry.S
353 --- linux-3.0.25/arch/ia64/kernel/entry.S       2011-07-22 11:17:35.000000000 +0200
354 +++ linux-3.0.25-vs2.3.2.3/arch/ia64/kernel/entry.S     2011-06-10 22:11:24.000000000 +0200
355 @@ -1714,7 +1714,7 @@ sys_call_table:
356         data8 sys_mq_notify
357         data8 sys_mq_getsetattr
358         data8 sys_kexec_load
359 -       data8 sys_ni_syscall                    // reserved for vserver
360 +       data8 sys_vserver
361         data8 sys_waitid                        // 1270
362         data8 sys_add_key
363         data8 sys_request_key
364 diff -NurpP --minimal linux-3.0.25/arch/ia64/kernel/perfmon.c linux-3.0.25-vs2.3.2.3/arch/ia64/kernel/perfmon.c
365 --- linux-3.0.25/arch/ia64/kernel/perfmon.c     2011-03-15 18:06:39.000000000 +0100
366 +++ linux-3.0.25-vs2.3.2.3/arch/ia64/kernel/perfmon.c   2011-06-10 22:11:24.000000000 +0200
367 @@ -42,6 +42,7 @@
368  #include <linux/completion.h>
369  #include <linux/tracehook.h>
370  #include <linux/slab.h>
371 +#include <linux/vs_memory.h>
372  
373  #include <asm/errno.h>
374  #include <asm/intrinsics.h>
375 diff -NurpP --minimal linux-3.0.25/arch/ia64/kernel/process.c linux-3.0.25-vs2.3.2.3/arch/ia64/kernel/process.c
376 --- linux-3.0.25/arch/ia64/kernel/process.c     2011-03-15 18:06:39.000000000 +0100
377 +++ linux-3.0.25-vs2.3.2.3/arch/ia64/kernel/process.c   2011-06-10 22:11:24.000000000 +0200
378 @@ -109,8 +109,8 @@ show_regs (struct pt_regs *regs)
379         unsigned long ip = regs->cr_iip + ia64_psr(regs)->ri;
380  
381         print_modules();
382 -       printk("\nPid: %d, CPU %d, comm: %20s\n", task_pid_nr(current),
383 -                       smp_processor_id(), current->comm);
384 +       printk("\nPid: %d[#%u], CPU %d, comm: %20s\n", task_pid_nr(current),
385 +                       current->xid, smp_processor_id(), current->comm);
386         printk("psr : %016lx ifs : %016lx ip  : [<%016lx>]    %s (%s)\n",
387                regs->cr_ipsr, regs->cr_ifs, ip, print_tainted(),
388                init_utsname()->release);
389 diff -NurpP --minimal linux-3.0.25/arch/ia64/kernel/ptrace.c linux-3.0.25-vs2.3.2.3/arch/ia64/kernel/ptrace.c
390 --- linux-3.0.25/arch/ia64/kernel/ptrace.c      2011-01-05 21:48:59.000000000 +0100
391 +++ linux-3.0.25-vs2.3.2.3/arch/ia64/kernel/ptrace.c    2011-06-10 22:11:24.000000000 +0200
392 @@ -21,6 +21,7 @@
393  #include <linux/regset.h>
394  #include <linux/elf.h>
395  #include <linux/tracehook.h>
396 +#include <linux/vs_base.h>
397  
398  #include <asm/pgtable.h>
399  #include <asm/processor.h>
400 diff -NurpP --minimal linux-3.0.25/arch/ia64/kernel/traps.c linux-3.0.25-vs2.3.2.3/arch/ia64/kernel/traps.c
401 --- linux-3.0.25/arch/ia64/kernel/traps.c       2010-07-07 18:31:01.000000000 +0200
402 +++ linux-3.0.25-vs2.3.2.3/arch/ia64/kernel/traps.c     2011-06-10 22:11:24.000000000 +0200
403 @@ -59,8 +59,9 @@ die (const char *str, struct pt_regs *re
404         put_cpu();
405  
406         if (++die.lock_owner_depth < 3) {
407 -               printk("%s[%d]: %s %ld [%d]\n",
408 -               current->comm, task_pid_nr(current), str, err, ++die_counter);
409 +               printk("%s[%d[#%u]]: %s %ld [%d]\n",
410 +                       current->comm, task_pid_nr(current), current->xid,
411 +                       str, err, ++die_counter);
412                 if (notify_die(DIE_OOPS, str, regs, err, 255, SIGSEGV)
413                     != NOTIFY_STOP)
414                         show_regs(regs);
415 @@ -323,8 +324,9 @@ handle_fpu_swa (int fp_fault, struct pt_
416                         if ((last.count & 15) < 5 && (ia64_fetchadd(1, &last.count, acq) & 15) < 5) {
417                                 last.time = current_jiffies + 5 * HZ;
418                                 printk(KERN_WARNING
419 -                                       "%s(%d): floating-point assist fault at ip %016lx, isr %016lx\n",
420 -                                       current->comm, task_pid_nr(current), regs->cr_iip + ia64_psr(regs)->ri, isr);
421 +                                       "%s(%d[#%u]): floating-point assist fault at ip %016lx, isr %016lx\n",
422 +                                       current->comm, task_pid_nr(current), current->xid,
423 +                                       regs->cr_iip + ia64_psr(regs)->ri, isr);
424                         }
425                 }
426         }
427 diff -NurpP --minimal linux-3.0.25/arch/ia64/mm/fault.c linux-3.0.25-vs2.3.2.3/arch/ia64/mm/fault.c
428 --- linux-3.0.25/arch/ia64/mm/fault.c   2011-07-22 11:17:35.000000000 +0200
429 +++ linux-3.0.25-vs2.3.2.3/arch/ia64/mm/fault.c 2011-06-10 22:28:23.000000000 +0200
430 @@ -11,6 +11,7 @@
431  #include <linux/kprobes.h>
432  #include <linux/kdebug.h>
433  #include <linux/prefetch.h>
434 +#include <linux/vs_memory.h>
435  
436  #include <asm/pgtable.h>
437  #include <asm/processor.h>
438 diff -NurpP --minimal linux-3.0.25/arch/m32r/kernel/traps.c linux-3.0.25-vs2.3.2.3/arch/m32r/kernel/traps.c
439 --- linux-3.0.25/arch/m32r/kernel/traps.c       2009-12-03 20:01:57.000000000 +0100
440 +++ linux-3.0.25-vs2.3.2.3/arch/m32r/kernel/traps.c     2011-06-10 22:11:24.000000000 +0200
441 @@ -196,8 +196,9 @@ static void show_registers(struct pt_reg
442         } else {
443                 printk("SPI: %08lx\n", sp);
444         }
445 -       printk("Process %s (pid: %d, process nr: %d, stackpage=%08lx)",
446 -               current->comm, task_pid_nr(current), 0xffff & i, 4096+(unsigned long)current);
447 +       printk("Process %s (pid: %d[#%u], process nr: %d, stackpage=%08lx)",
448 +               current->comm, task_pid_nr(current), current->xid,
449 +               0xffff & i, 4096+(unsigned long)current);
450  
451         /*
452          * When in-kernel, we also print out the stack and code at the
453 diff -NurpP --minimal linux-3.0.25/arch/m68k/Kconfig linux-3.0.25-vs2.3.2.3/arch/m68k/Kconfig
454 --- linux-3.0.25/arch/m68k/Kconfig      2011-07-22 11:17:35.000000000 +0200
455 +++ linux-3.0.25-vs2.3.2.3/arch/m68k/Kconfig    2011-06-10 22:11:24.000000000 +0200
456 @@ -241,6 +241,8 @@ source "fs/Kconfig"
457  
458  source "arch/m68k/Kconfig.debug"
459  
460 +source "kernel/vserver/Kconfig"
461 +
462  source "security/Kconfig"
463  
464  source "crypto/Kconfig"
465 diff -NurpP --minimal linux-3.0.25/arch/mips/Kconfig linux-3.0.25-vs2.3.2.3/arch/mips/Kconfig
466 --- linux-3.0.25/arch/mips/Kconfig      2011-07-22 11:17:35.000000000 +0200
467 +++ linux-3.0.25-vs2.3.2.3/arch/mips/Kconfig    2011-06-10 22:11:24.000000000 +0200
468 @@ -2485,6 +2485,8 @@ source "fs/Kconfig"
469  
470  source "arch/mips/Kconfig.debug"
471  
472 +source "kernel/vserver/Kconfig"
473 +
474  source "security/Kconfig"
475  
476  source "crypto/Kconfig"
477 diff -NurpP --minimal linux-3.0.25/arch/mips/kernel/ptrace.c linux-3.0.25-vs2.3.2.3/arch/mips/kernel/ptrace.c
478 --- linux-3.0.25/arch/mips/kernel/ptrace.c      2011-07-22 11:17:36.000000000 +0200
479 +++ linux-3.0.25-vs2.3.2.3/arch/mips/kernel/ptrace.c    2011-06-10 22:11:24.000000000 +0200
480 @@ -25,6 +25,7 @@
481  #include <linux/security.h>
482  #include <linux/audit.h>
483  #include <linux/seccomp.h>
484 +#include <linux/vs_base.h>
485  
486  #include <asm/byteorder.h>
487  #include <asm/cpu.h>
488 @@ -263,6 +264,9 @@ long arch_ptrace(struct task_struct *chi
489         void __user *datavp = (void __user *) data;
490         unsigned long __user *datalp = (void __user *) data;
491  
492 +       if (!vx_check(vx_task_xid(child), VS_WATCH_P | VS_IDENT))
493 +               goto out;
494 +
495         switch (request) {
496         /* when I and D space are separate, these will need to be fixed. */
497         case PTRACE_PEEKTEXT: /* read word at location addr. */
498 diff -NurpP --minimal linux-3.0.25/arch/mips/kernel/scall32-o32.S linux-3.0.25-vs2.3.2.3/arch/mips/kernel/scall32-o32.S
499 --- linux-3.0.25/arch/mips/kernel/scall32-o32.S 2011-07-22 11:17:36.000000000 +0200
500 +++ linux-3.0.25-vs2.3.2.3/arch/mips/kernel/scall32-o32.S       2011-06-10 22:11:24.000000000 +0200
501 @@ -523,7 +523,7 @@ einval:     li      v0, -ENOSYS
502         sys     sys_mq_timedreceive     5
503         sys     sys_mq_notify           2       /* 4275 */
504         sys     sys_mq_getsetattr       3
505 -       sys     sys_ni_syscall          0       /* sys_vserver */
506 +       sys     sys_vserver             3
507         sys     sys_waitid              5
508         sys     sys_ni_syscall          0       /* available, was setaltroot */
509         sys     sys_add_key             5       /* 4280 */
510 diff -NurpP --minimal linux-3.0.25/arch/mips/kernel/scall64-64.S linux-3.0.25-vs2.3.2.3/arch/mips/kernel/scall64-64.S
511 --- linux-3.0.25/arch/mips/kernel/scall64-64.S  2011-07-22 11:17:36.000000000 +0200
512 +++ linux-3.0.25-vs2.3.2.3/arch/mips/kernel/scall64-64.S        2011-06-10 22:11:24.000000000 +0200
513 @@ -362,7 +362,7 @@ sys_call_table:
514         PTR     sys_mq_timedreceive
515         PTR     sys_mq_notify
516         PTR     sys_mq_getsetattr               /* 5235 */
517 -       PTR     sys_ni_syscall                  /* sys_vserver */
518 +       PTR     sys_vserver
519         PTR     sys_waitid
520         PTR     sys_ni_syscall                  /* available, was setaltroot */
521         PTR     sys_add_key
522 diff -NurpP --minimal linux-3.0.25/arch/mips/kernel/scall64-n32.S linux-3.0.25-vs2.3.2.3/arch/mips/kernel/scall64-n32.S
523 --- linux-3.0.25/arch/mips/kernel/scall64-n32.S 2011-07-22 11:17:36.000000000 +0200
524 +++ linux-3.0.25-vs2.3.2.3/arch/mips/kernel/scall64-n32.S       2011-06-10 22:11:24.000000000 +0200
525 @@ -361,7 +361,7 @@ EXPORT(sysn32_call_table)
526         PTR     compat_sys_mq_timedreceive
527         PTR     compat_sys_mq_notify
528         PTR     compat_sys_mq_getsetattr
529 -       PTR     sys_ni_syscall                  /* 6240, sys_vserver */
530 +       PTR     sys32_vserver                   /* 6240 */
531         PTR     compat_sys_waitid
532         PTR     sys_ni_syscall                  /* available, was setaltroot */
533         PTR     sys_add_key
534 diff -NurpP --minimal linux-3.0.25/arch/mips/kernel/scall64-o32.S linux-3.0.25-vs2.3.2.3/arch/mips/kernel/scall64-o32.S
535 --- linux-3.0.25/arch/mips/kernel/scall64-o32.S 2011-07-22 11:17:36.000000000 +0200
536 +++ linux-3.0.25-vs2.3.2.3/arch/mips/kernel/scall64-o32.S       2011-06-10 22:11:24.000000000 +0200
537 @@ -480,7 +480,7 @@ sys_call_table:
538         PTR     compat_sys_mq_timedreceive
539         PTR     compat_sys_mq_notify            /* 4275 */
540         PTR     compat_sys_mq_getsetattr
541 -       PTR     sys_ni_syscall                  /* sys_vserver */
542 +       PTR     sys32_vserver
543         PTR     sys_32_waitid
544         PTR     sys_ni_syscall                  /* available, was setaltroot */
545         PTR     sys_add_key                     /* 4280 */
546 diff -NurpP --minimal linux-3.0.25/arch/mips/kernel/traps.c linux-3.0.25-vs2.3.2.3/arch/mips/kernel/traps.c
547 --- linux-3.0.25/arch/mips/kernel/traps.c       2011-05-22 16:17:00.000000000 +0200
548 +++ linux-3.0.25-vs2.3.2.3/arch/mips/kernel/traps.c     2011-06-10 22:11:24.000000000 +0200
549 @@ -343,9 +343,10 @@ void show_registers(struct pt_regs *regs
550  
551         __show_regs(regs);
552         print_modules();
553 -       printk("Process %s (pid: %d, threadinfo=%p, task=%p, tls=%0*lx)\n",
554 -              current->comm, current->pid, current_thread_info(), current,
555 -             field, current_thread_info()->tp_value);
556 +       printk("Process %s (pid: %d:#%u, threadinfo=%p, task=%p, tls=%0*lx)\n",
557 +               current->comm, task_pid_nr(current), current->xid,
558 +               current_thread_info(), current,
559 +               field, current_thread_info()->tp_value);
560         if (cpu_has_userlocal) {
561                 unsigned long tls;
562  
563 diff -NurpP --minimal linux-3.0.25/arch/parisc/Kconfig linux-3.0.25-vs2.3.2.3/arch/parisc/Kconfig
564 --- linux-3.0.25/arch/parisc/Kconfig    2011-07-22 11:17:36.000000000 +0200
565 +++ linux-3.0.25-vs2.3.2.3/arch/parisc/Kconfig  2011-06-10 22:11:24.000000000 +0200
566 @@ -279,6 +279,8 @@ source "fs/Kconfig"
567  
568  source "arch/parisc/Kconfig.debug"
569  
570 +source "kernel/vserver/Kconfig"
571 +
572  source "security/Kconfig"
573  
574  source "crypto/Kconfig"
575 diff -NurpP --minimal linux-3.0.25/arch/parisc/kernel/syscall_table.S linux-3.0.25-vs2.3.2.3/arch/parisc/kernel/syscall_table.S
576 --- linux-3.0.25/arch/parisc/kernel/syscall_table.S     2012-03-19 21:16:35.000000000 +0100
577 +++ linux-3.0.25-vs2.3.2.3/arch/parisc/kernel/syscall_table.S   2011-08-29 03:45:07.000000000 +0200
578 @@ -361,7 +361,7 @@
579         ENTRY_COMP(mbind)               /* 260 */
580         ENTRY_COMP(get_mempolicy)
581         ENTRY_COMP(set_mempolicy)
582 -       ENTRY_SAME(ni_syscall)  /* 263: reserved for vserver */
583 +       ENTRY_DIFF(vserver)
584         ENTRY_SAME(add_key)
585         ENTRY_SAME(request_key)         /* 265 */
586         ENTRY_SAME(keyctl)
587 diff -NurpP --minimal linux-3.0.25/arch/parisc/kernel/traps.c linux-3.0.25-vs2.3.2.3/arch/parisc/kernel/traps.c
588 --- linux-3.0.25/arch/parisc/kernel/traps.c     2009-09-10 15:25:40.000000000 +0200
589 +++ linux-3.0.25-vs2.3.2.3/arch/parisc/kernel/traps.c   2011-06-10 22:11:24.000000000 +0200
590 @@ -236,8 +236,9 @@ void die_if_kernel(char *str, struct pt_
591                 if (err == 0)
592                         return; /* STFU */
593  
594 -               printk(KERN_CRIT "%s (pid %d): %s (code %ld) at " RFMT "\n",
595 -                       current->comm, task_pid_nr(current), str, err, regs->iaoq[0]);
596 +               printk(KERN_CRIT "%s (pid %d:#%u): %s (code %ld) at " RFMT "\n",
597 +                       current->comm, task_pid_nr(current), current->xid,
598 +                       str, err, regs->iaoq[0]);
599  #ifdef PRINT_USER_FAULTS
600                 /* XXX for debugging only */
601                 show_regs(regs);
602 @@ -270,8 +271,8 @@ void die_if_kernel(char *str, struct pt_
603                 pdc_console_restart();
604         
605         if (err)
606 -               printk(KERN_CRIT "%s (pid %d): %s (code %ld)\n",
607 -                       current->comm, task_pid_nr(current), str, err);
608 +               printk(KERN_CRIT "%s (pid %d:#%u): %s (code %ld)\n",
609 +                       current->comm, task_pid_nr(current), current->xid, str, err);
610  
611         /* Wot's wrong wif bein' racy? */
612         if (current->thread.flags & PARISC_KERNEL_DEATH) {
613 diff -NurpP --minimal linux-3.0.25/arch/parisc/mm/fault.c linux-3.0.25-vs2.3.2.3/arch/parisc/mm/fault.c
614 --- linux-3.0.25/arch/parisc/mm/fault.c 2010-08-02 16:52:06.000000000 +0200
615 +++ linux-3.0.25-vs2.3.2.3/arch/parisc/mm/fault.c       2011-06-10 22:11:24.000000000 +0200
616 @@ -237,8 +237,9 @@ bad_area:
617  
618  #ifdef PRINT_USER_FAULTS
619                 printk(KERN_DEBUG "\n");
620 -               printk(KERN_DEBUG "do_page_fault() pid=%d command='%s' type=%lu address=0x%08lx\n",
621 -                   task_pid_nr(tsk), tsk->comm, code, address);
622 +               printk(KERN_DEBUG "do_page_fault() pid=%d:#%u "
623 +                   "command='%s' type=%lu address=0x%08lx\n",
624 +                   task_pid_nr(tsk), tsk->xid, tsk->comm, code, address);
625                 if (vma) {
626                         printk(KERN_DEBUG "vm_start = 0x%08lx, vm_end = 0x%08lx\n",
627                                         vma->vm_start, vma->vm_end);
628 diff -NurpP --minimal linux-3.0.25/arch/powerpc/Kconfig linux-3.0.25-vs2.3.2.3/arch/powerpc/Kconfig
629 --- linux-3.0.25/arch/powerpc/Kconfig   2011-07-22 11:17:36.000000000 +0200
630 +++ linux-3.0.25-vs2.3.2.3/arch/powerpc/Kconfig 2011-06-10 22:11:24.000000000 +0200
631 @@ -978,6 +978,8 @@ source "lib/Kconfig"
632  
633  source "arch/powerpc/Kconfig.debug"
634  
635 +source "kernel/vserver/Kconfig"
636 +
637  source "security/Kconfig"
638  
639  config KEYS_COMPAT
640 diff -NurpP --minimal linux-3.0.25/arch/powerpc/include/asm/unistd.h linux-3.0.25-vs2.3.2.3/arch/powerpc/include/asm/unistd.h
641 --- linux-3.0.25/arch/powerpc/include/asm/unistd.h      2011-07-22 11:17:40.000000000 +0200
642 +++ linux-3.0.25-vs2.3.2.3/arch/powerpc/include/asm/unistd.h    2011-06-10 22:11:24.000000000 +0200
643 @@ -275,7 +275,7 @@
644  #endif
645  #define __NR_rtas              255
646  #define __NR_sys_debug_setcontext 256
647 -/* Number 257 is reserved for vserver */
648 +#define __NR_vserver           257
649  #define __NR_migrate_pages     258
650  #define __NR_mbind             259
651  #define __NR_get_mempolicy     260
652 diff -NurpP --minimal linux-3.0.25/arch/powerpc/kernel/process.c linux-3.0.25-vs2.3.2.3/arch/powerpc/kernel/process.c
653 --- linux-3.0.25/arch/powerpc/kernel/process.c  2011-07-22 11:17:40.000000000 +0200
654 +++ linux-3.0.25-vs2.3.2.3/arch/powerpc/kernel/process.c        2011-06-10 22:11:24.000000000 +0200
655 @@ -656,8 +656,9 @@ void show_regs(struct pt_regs * regs)
656  #else
657                 printk("DAR: "REG", DSISR: %08lx\n", regs->dar, regs->dsisr);
658  #endif
659 -       printk("TASK = %p[%d] '%s' THREAD: %p",
660 -              current, task_pid_nr(current), current->comm, task_thread_info(current));
661 +       printk("TASK = %p[%d,#%u] '%s' THREAD: %p",
662 +              current, task_pid_nr(current), current->xid,
663 +              current->comm, task_thread_info(current));
664  
665  #ifdef CONFIG_SMP
666         printk(" CPU: %d", raw_smp_processor_id());
667 diff -NurpP --minimal linux-3.0.25/arch/powerpc/kernel/traps.c linux-3.0.25-vs2.3.2.3/arch/powerpc/kernel/traps.c
668 --- linux-3.0.25/arch/powerpc/kernel/traps.c    2011-07-22 11:17:40.000000000 +0200
669 +++ linux-3.0.25-vs2.3.2.3/arch/powerpc/kernel/traps.c  2011-07-19 00:44:39.000000000 +0200
670 @@ -1075,8 +1075,9 @@ void nonrecoverable_exception(struct pt_
671  
672  void trace_syscall(struct pt_regs *regs)
673  {
674 -       printk("Task: %p(%d), PC: %08lX/%08lX, Syscall: %3ld, Result: %s%ld    %s\n",
675 -              current, task_pid_nr(current), regs->nip, regs->link, regs->gpr[0],
676 +       printk("Task: %p(%d[#%u]), PC: %08lX/%08lX, Syscall: %3ld, Result: %s%ld    %s\n",
677 +              current, task_pid_nr(current), current->xid,
678 +              regs->nip, regs->link, regs->gpr[0],
679                regs->ccr&0x10000000?"Error=":"", regs->gpr[3], print_tainted());
680  }
681  
682 diff -NurpP --minimal linux-3.0.25/arch/powerpc/kernel/vdso.c linux-3.0.25-vs2.3.2.3/arch/powerpc/kernel/vdso.c
683 --- linux-3.0.25/arch/powerpc/kernel/vdso.c     2011-05-22 16:17:02.000000000 +0200
684 +++ linux-3.0.25-vs2.3.2.3/arch/powerpc/kernel/vdso.c   2011-06-10 22:11:24.000000000 +0200
685 @@ -23,6 +23,7 @@
686  #include <linux/security.h>
687  #include <linux/bootmem.h>
688  #include <linux/memblock.h>
689 +#include <linux/vs_memory.h>
690  
691  #include <asm/pgtable.h>
692  #include <asm/system.h>
693 diff -NurpP --minimal linux-3.0.25/arch/s390/Kconfig linux-3.0.25-vs2.3.2.3/arch/s390/Kconfig
694 --- linux-3.0.25/arch/s390/Kconfig      2012-03-19 21:16:36.000000000 +0100
695 +++ linux-3.0.25-vs2.3.2.3/arch/s390/Kconfig    2012-03-15 13:32:35.000000000 +0100
696 @@ -631,6 +631,8 @@ source "fs/Kconfig"
697  
698  source "arch/s390/Kconfig.debug"
699  
700 +source "kernel/vserver/Kconfig"
701 +
702  source "security/Kconfig"
703  
704  source "crypto/Kconfig"
705 diff -NurpP --minimal linux-3.0.25/arch/s390/include/asm/tlb.h linux-3.0.25-vs2.3.2.3/arch/s390/include/asm/tlb.h
706 --- linux-3.0.25/arch/s390/include/asm/tlb.h    2011-07-22 11:17:41.000000000 +0200
707 +++ linux-3.0.25-vs2.3.2.3/arch/s390/include/asm/tlb.h  2011-06-15 02:40:14.000000000 +0200
708 @@ -24,6 +24,8 @@
709  #include <linux/mm.h>
710  #include <linux/pagemap.h>
711  #include <linux/swap.h>
712 +#include <linux/vs_memory.h>
713 +
714  #include <asm/processor.h>
715  #include <asm/pgalloc.h>
716  #include <asm/tlbflush.h>
717 diff -NurpP --minimal linux-3.0.25/arch/s390/include/asm/unistd.h linux-3.0.25-vs2.3.2.3/arch/s390/include/asm/unistd.h
718 --- linux-3.0.25/arch/s390/include/asm/unistd.h 2011-07-22 11:17:41.000000000 +0200
719 +++ linux-3.0.25-vs2.3.2.3/arch/s390/include/asm/unistd.h       2011-06-10 22:11:24.000000000 +0200
720 @@ -202,7 +202,7 @@
721  #define __NR_clock_gettime     (__NR_timer_create+6)
722  #define __NR_clock_getres      (__NR_timer_create+7)
723  #define __NR_clock_nanosleep   (__NR_timer_create+8)
724 -/* Number 263 is reserved for vserver */
725 +#define __NR_vserver           263
726  #define __NR_statfs64          265
727  #define __NR_fstatfs64         266
728  #define __NR_remap_file_pages  267
729 diff -NurpP --minimal linux-3.0.25/arch/s390/kernel/ptrace.c linux-3.0.25-vs2.3.2.3/arch/s390/kernel/ptrace.c
730 --- linux-3.0.25/arch/s390/kernel/ptrace.c      2012-03-19 21:16:36.000000000 +0100
731 +++ linux-3.0.25-vs2.3.2.3/arch/s390/kernel/ptrace.c    2012-03-15 13:33:10.000000000 +0100
732 @@ -21,6 +21,7 @@
733  #include <linux/tracehook.h>
734  #include <linux/seccomp.h>
735  #include <linux/compat.h>
736 +#include <linux/vs_base.h>
737  #include <trace/syscall.h>
738  #include <asm/segment.h>
739  #include <asm/page.h>
740 diff -NurpP --minimal linux-3.0.25/arch/s390/kernel/syscalls.S linux-3.0.25-vs2.3.2.3/arch/s390/kernel/syscalls.S
741 --- linux-3.0.25/arch/s390/kernel/syscalls.S    2011-07-22 11:17:41.000000000 +0200
742 +++ linux-3.0.25-vs2.3.2.3/arch/s390/kernel/syscalls.S  2011-06-10 22:11:24.000000000 +0200
743 @@ -271,7 +271,7 @@ SYSCALL(sys_clock_settime,sys_clock_sett
744  SYSCALL(sys_clock_gettime,sys_clock_gettime,sys32_clock_gettime_wrapper)       /* 260 */
745  SYSCALL(sys_clock_getres,sys_clock_getres,sys32_clock_getres_wrapper)
746  SYSCALL(sys_clock_nanosleep,sys_clock_nanosleep,sys32_clock_nanosleep_wrapper)
747 -NI_SYSCALL                                                     /* reserved for vserver */
748 +SYSCALL(sys_vserver,sys_vserver,sys32_vserver)
749  SYSCALL(sys_s390_fadvise64_64,sys_ni_syscall,sys32_fadvise64_64_wrapper)
750  SYSCALL(sys_statfs64,sys_statfs64,compat_sys_statfs64_wrapper)
751  SYSCALL(sys_fstatfs64,sys_fstatfs64,compat_sys_fstatfs64_wrapper)
752 diff -NurpP --minimal linux-3.0.25/arch/sh/Kconfig linux-3.0.25-vs2.3.2.3/arch/sh/Kconfig
753 --- linux-3.0.25/arch/sh/Kconfig        2011-07-22 11:17:41.000000000 +0200
754 +++ linux-3.0.25-vs2.3.2.3/arch/sh/Kconfig      2011-07-19 00:44:39.000000000 +0200
755 @@ -893,6 +893,8 @@ source "fs/Kconfig"
756  
757  source "arch/sh/Kconfig.debug"
758  
759 +source "kernel/vserver/Kconfig"
760 +
761  source "security/Kconfig"
762  
763  source "crypto/Kconfig"
764 diff -NurpP --minimal linux-3.0.25/arch/sh/kernel/irq.c linux-3.0.25-vs2.3.2.3/arch/sh/kernel/irq.c
765 --- linux-3.0.25/arch/sh/kernel/irq.c   2011-07-22 11:17:41.000000000 +0200
766 +++ linux-3.0.25-vs2.3.2.3/arch/sh/kernel/irq.c 2011-07-19 00:45:06.000000000 +0200
767 @@ -14,6 +14,7 @@
768  #include <linux/ftrace.h>
769  #include <linux/delay.h>
770  #include <linux/ratelimit.h>
771 +// #include <linux/vs_context.h>
772  #include <asm/processor.h>
773  #include <asm/machvec.h>
774  #include <asm/uaccess.h>
775 diff -NurpP --minimal linux-3.0.25/arch/sh/kernel/vsyscall/vsyscall.c linux-3.0.25-vs2.3.2.3/arch/sh/kernel/vsyscall/vsyscall.c
776 --- linux-3.0.25/arch/sh/kernel/vsyscall/vsyscall.c     2011-05-22 16:17:07.000000000 +0200
777 +++ linux-3.0.25-vs2.3.2.3/arch/sh/kernel/vsyscall/vsyscall.c   2011-06-10 22:11:24.000000000 +0200
778 @@ -18,6 +18,7 @@
779  #include <linux/elf.h>
780  #include <linux/sched.h>
781  #include <linux/err.h>
782 +#include <linux/vs_memory.h>
783  
784  /*
785   * Should the kernel map a VDSO page into processes and pass its
786 diff -NurpP --minimal linux-3.0.25/arch/sparc/Kconfig linux-3.0.25-vs2.3.2.3/arch/sparc/Kconfig
787 --- linux-3.0.25/arch/sparc/Kconfig     2012-03-19 21:16:36.000000000 +0100
788 +++ linux-3.0.25-vs2.3.2.3/arch/sparc/Kconfig   2011-10-18 13:51:13.000000000 +0200
789 @@ -602,6 +602,8 @@ source "fs/Kconfig"
790  
791  source "arch/sparc/Kconfig.debug"
792  
793 +source "kernel/vserver/Kconfig"
794 +
795  source "security/Kconfig"
796  
797  source "crypto/Kconfig"
798 diff -NurpP --minimal linux-3.0.25/arch/sparc/include/asm/tlb_64.h linux-3.0.25-vs2.3.2.3/arch/sparc/include/asm/tlb_64.h
799 --- linux-3.0.25/arch/sparc/include/asm/tlb_64.h        2011-07-22 11:17:42.000000000 +0200
800 +++ linux-3.0.25-vs2.3.2.3/arch/sparc/include/asm/tlb_64.h      2011-06-10 22:11:24.000000000 +0200
801 @@ -3,6 +3,7 @@
802  
803  #include <linux/swap.h>
804  #include <linux/pagemap.h>
805 +#include <linux/vs_memory.h>
806  #include <asm/pgalloc.h>
807  #include <asm/tlbflush.h>
808  #include <asm/mmu_context.h>
809 diff -NurpP --minimal linux-3.0.25/arch/sparc/include/asm/unistd.h linux-3.0.25-vs2.3.2.3/arch/sparc/include/asm/unistd.h
810 --- linux-3.0.25/arch/sparc/include/asm/unistd.h        2011-07-22 11:17:42.000000000 +0200
811 +++ linux-3.0.25-vs2.3.2.3/arch/sparc/include/asm/unistd.h      2011-06-10 22:11:24.000000000 +0200
812 @@ -335,7 +335,7 @@
813  #define __NR_timer_getoverrun  264
814  #define __NR_timer_delete      265
815  #define __NR_timer_create      266
816 -/* #define __NR_vserver                267 Reserved for VSERVER */
817 +#define __NR_vserver           267
818  #define __NR_io_setup          268
819  #define __NR_io_destroy                269
820  #define __NR_io_submit         270
821 diff -NurpP --minimal linux-3.0.25/arch/sparc/kernel/systbls_32.S linux-3.0.25-vs2.3.2.3/arch/sparc/kernel/systbls_32.S
822 --- linux-3.0.25/arch/sparc/kernel/systbls_32.S 2011-07-22 11:17:42.000000000 +0200
823 +++ linux-3.0.25-vs2.3.2.3/arch/sparc/kernel/systbls_32.S       2011-06-10 22:11:24.000000000 +0200
824 @@ -70,7 +70,7 @@ sys_call_table:
825  /*250*/        .long sys_mremap, sys_sysctl, sys_getsid, sys_fdatasync, sys_nfsservctl
826  /*255*/        .long sys_sync_file_range, sys_clock_settime, sys_clock_gettime, sys_clock_getres, sys_clock_nanosleep
827  /*260*/        .long sys_sched_getaffinity, sys_sched_setaffinity, sys_timer_settime, sys_timer_gettime, sys_timer_getoverrun
828 -/*265*/        .long sys_timer_delete, sys_timer_create, sys_nis_syscall, sys_io_setup, sys_io_destroy
829 +/*265*/        .long sys_timer_delete, sys_timer_create, sys_vserver, sys_io_setup, sys_io_destroy
830  /*270*/        .long sys_io_submit, sys_io_cancel, sys_io_getevents, sys_mq_open, sys_mq_unlink
831  /*275*/        .long sys_mq_timedsend, sys_mq_timedreceive, sys_mq_notify, sys_mq_getsetattr, sys_waitid
832  /*280*/        .long sys_tee, sys_add_key, sys_request_key, sys_keyctl, sys_openat
833 diff -NurpP --minimal linux-3.0.25/arch/sparc/kernel/systbls_64.S linux-3.0.25-vs2.3.2.3/arch/sparc/kernel/systbls_64.S
834 --- linux-3.0.25/arch/sparc/kernel/systbls_64.S 2011-07-22 11:17:42.000000000 +0200
835 +++ linux-3.0.25-vs2.3.2.3/arch/sparc/kernel/systbls_64.S       2011-06-10 22:11:24.000000000 +0200
836 @@ -71,7 +71,7 @@ sys_call_table32:
837  /*250*/        .word sys_mremap, compat_sys_sysctl, sys32_getsid, sys_fdatasync, sys32_nfsservctl
838         .word sys32_sync_file_range, compat_sys_clock_settime, compat_sys_clock_gettime, compat_sys_clock_getres, sys32_clock_nanosleep
839  /*260*/        .word compat_sys_sched_getaffinity, compat_sys_sched_setaffinity, sys32_timer_settime, compat_sys_timer_gettime, sys_timer_getoverrun
840 -       .word sys_timer_delete, compat_sys_timer_create, sys_ni_syscall, compat_sys_io_setup, sys_io_destroy
841 +       .word sys_timer_delete, compat_sys_timer_create, sys32_vserver, compat_sys_io_setup, sys_io_destroy
842  /*270*/        .word sys32_io_submit, sys_io_cancel, compat_sys_io_getevents, sys32_mq_open, sys_mq_unlink
843         .word compat_sys_mq_timedsend, compat_sys_mq_timedreceive, compat_sys_mq_notify, compat_sys_mq_getsetattr, compat_sys_waitid
844  /*280*/        .word sys32_tee, sys_add_key, sys_request_key, sys_keyctl, compat_sys_openat
845 @@ -148,7 +148,7 @@ sys_call_table:
846  /*250*/        .word sys_64_mremap, sys_sysctl, sys_getsid, sys_fdatasync, sys_nfsservctl
847         .word sys_sync_file_range, sys_clock_settime, sys_clock_gettime, sys_clock_getres, sys_clock_nanosleep
848  /*260*/        .word sys_sched_getaffinity, sys_sched_setaffinity, sys_timer_settime, sys_timer_gettime, sys_timer_getoverrun
849 -       .word sys_timer_delete, sys_timer_create, sys_ni_syscall, sys_io_setup, sys_io_destroy
850 +       .word sys_timer_delete, sys_timer_create, sys_vserver, sys_io_setup, sys_io_destroy
851  /*270*/        .word sys_io_submit, sys_io_cancel, sys_io_getevents, sys_mq_open, sys_mq_unlink
852         .word sys_mq_timedsend, sys_mq_timedreceive, sys_mq_notify, sys_mq_getsetattr, sys_waitid
853  /*280*/        .word sys_tee, sys_add_key, sys_request_key, sys_keyctl, sys_openat
854 diff -NurpP --minimal linux-3.0.25/arch/um/Kconfig.rest linux-3.0.25-vs2.3.2.3/arch/um/Kconfig.rest
855 --- linux-3.0.25/arch/um/Kconfig.rest   2009-06-11 17:12:19.000000000 +0200
856 +++ linux-3.0.25-vs2.3.2.3/arch/um/Kconfig.rest 2011-06-10 22:11:24.000000000 +0200
857 @@ -18,6 +18,8 @@ source "drivers/connector/Kconfig"
858  
859  source "fs/Kconfig"
860  
861 +source "kernel/vserver/Kconfig"
862 +
863  source "security/Kconfig"
864  
865  source "crypto/Kconfig"
866 diff -NurpP --minimal linux-3.0.25/arch/um/include/asm/tlb.h linux-3.0.25-vs2.3.2.3/arch/um/include/asm/tlb.h
867 --- linux-3.0.25/arch/um/include/asm/tlb.h      2011-07-22 11:17:42.000000000 +0200
868 +++ linux-3.0.25-vs2.3.2.3/arch/um/include/asm/tlb.h    2011-06-10 22:11:24.000000000 +0200
869 @@ -3,6 +3,7 @@
870  
871  #include <linux/pagemap.h>
872  #include <linux/swap.h>
873 +#include <linux/vs_memory.h>
874  #include <asm/percpu.h>
875  #include <asm/pgalloc.h>
876  #include <asm/tlbflush.h>
877 diff -NurpP --minimal linux-3.0.25/arch/x86/Kconfig linux-3.0.25-vs2.3.2.3/arch/x86/Kconfig
878 --- linux-3.0.25/arch/x86/Kconfig       2011-07-22 11:17:42.000000000 +0200
879 +++ linux-3.0.25-vs2.3.2.3/arch/x86/Kconfig     2011-07-22 11:20:39.000000000 +0200
880 @@ -2159,6 +2159,8 @@ source "fs/Kconfig"
881  
882  source "arch/x86/Kconfig.debug"
883  
884 +source "kernel/vserver/Kconfig"
885 +
886  source "security/Kconfig"
887  
888  source "crypto/Kconfig"
889 diff -NurpP --minimal linux-3.0.25/arch/x86/ia32/ia32entry.S linux-3.0.25-vs2.3.2.3/arch/x86/ia32/ia32entry.S
890 --- linux-3.0.25/arch/x86/ia32/ia32entry.S      2011-07-22 11:17:42.000000000 +0200
891 +++ linux-3.0.25-vs2.3.2.3/arch/x86/ia32/ia32entry.S    2011-06-10 22:11:24.000000000 +0200
892 @@ -776,7 +776,7 @@ ia32_sys_call_table:
893         .quad sys_tgkill                /* 270 */
894         .quad compat_sys_utimes
895         .quad sys32_fadvise64_64
896 -       .quad quiet_ni_syscall  /* sys_vserver */
897 +       .quad sys32_vserver
898         .quad sys_mbind
899         .quad compat_sys_get_mempolicy  /* 275 */
900         .quad sys_set_mempolicy
901 diff -NurpP --minimal linux-3.0.25/arch/x86/include/asm/unistd_64.h linux-3.0.25-vs2.3.2.3/arch/x86/include/asm/unistd_64.h
902 --- linux-3.0.25/arch/x86/include/asm/unistd_64.h       2011-07-22 11:17:43.000000000 +0200
903 +++ linux-3.0.25-vs2.3.2.3/arch/x86/include/asm/unistd_64.h     2011-06-10 22:11:24.000000000 +0200
904 @@ -535,7 +535,7 @@ __SYSCALL(__NR_tgkill, sys_tgkill)
905  #define __NR_utimes                            235
906  __SYSCALL(__NR_utimes, sys_utimes)
907  #define __NR_vserver                           236
908 -__SYSCALL(__NR_vserver, sys_ni_syscall)
909 +__SYSCALL(__NR_vserver, sys_vserver)
910  #define __NR_mbind                             237
911  __SYSCALL(__NR_mbind, sys_mbind)
912  #define __NR_set_mempolicy                     238
913 diff -NurpP --minimal linux-3.0.25/arch/x86/kernel/syscall_table_32.S linux-3.0.25-vs2.3.2.3/arch/x86/kernel/syscall_table_32.S
914 --- linux-3.0.25/arch/x86/kernel/syscall_table_32.S     2011-07-22 11:17:43.000000000 +0200
915 +++ linux-3.0.25-vs2.3.2.3/arch/x86/kernel/syscall_table_32.S   2011-06-10 22:11:24.000000000 +0200
916 @@ -272,7 +272,7 @@ ENTRY(sys_call_table)
917         .long sys_tgkill        /* 270 */
918         .long sys_utimes
919         .long sys_fadvise64_64
920 -       .long sys_ni_syscall    /* sys_vserver */
921 +       .long sys_vserver
922         .long sys_mbind
923         .long sys_get_mempolicy
924         .long sys_set_mempolicy
925 diff -NurpP --minimal linux-3.0.25/block/genhd.c linux-3.0.25-vs2.3.2.3/block/genhd.c
926 --- linux-3.0.25/block/genhd.c  2012-03-19 21:16:38.000000000 +0100
927 +++ linux-3.0.25-vs2.3.2.3/block/genhd.c        2012-03-23 14:54:00.000000000 +0100
928 @@ -1165,17 +1165,17 @@ static int diskstats_show(struct seq_fil
929                 cpu = part_stat_lock();
930                 part_round_stats(cpu, hd);
931                 part_stat_unlock();
932 -               seq_printf(seqf, "%4d %7d %s %lu %lu %llu "
933 -                          "%u %lu %lu %llu %u %u %u %u\n",
934 +               seq_printf(seqf, "%4d %7d %s %lu %lu %lu "
935 +                          "%u %lu %lu %lu %u %u %u %u\n",
936                            MAJOR(part_devt(hd)), MINOR(part_devt(hd)),
937                            disk_name(gp, hd->partno, buf),
938                            part_stat_read(hd, ios[READ]),
939                            part_stat_read(hd, merges[READ]),
940 -                          (unsigned long long)part_stat_read(hd, sectors[READ]),
941 +                          part_stat_read(hd, sectors[READ]),
942                            jiffies_to_msecs(part_stat_read(hd, ticks[READ])),
943                            part_stat_read(hd, ios[WRITE]),
944                            part_stat_read(hd, merges[WRITE]),
945 -                          (unsigned long long)part_stat_read(hd, sectors[WRITE]),
946 +                          part_stat_read(hd, sectors[WRITE]),
947                            jiffies_to_msecs(part_stat_read(hd, ticks[WRITE])),
948                            part_in_flight(hd),
949                            jiffies_to_msecs(part_stat_read(hd, io_ticks)),
950 diff -NurpP --minimal linux-3.0.25/drivers/block/Kconfig linux-3.0.25-vs2.3.2.3/drivers/block/Kconfig
951 --- linux-3.0.25/drivers/block/Kconfig  2011-07-22 11:17:44.000000000 +0200
952 +++ linux-3.0.25-vs2.3.2.3/drivers/block/Kconfig        2011-06-10 22:11:24.000000000 +0200
953 @@ -273,6 +273,13 @@ config BLK_DEV_CRYPTOLOOP
954  
955  source "drivers/block/drbd/Kconfig"
956  
957 +config BLK_DEV_VROOT
958 +       tristate "Virtual Root device support"
959 +       depends on QUOTACTL
960 +       ---help---
961 +         Saying Y here will allow you to use quota/fs ioctls on a shared
962 +         partition within a virtual server without compromising security.
963 +
964  config BLK_DEV_NBD
965         tristate "Network block device support"
966         depends on NET
967 diff -NurpP --minimal linux-3.0.25/drivers/block/Makefile linux-3.0.25-vs2.3.2.3/drivers/block/Makefile
968 --- linux-3.0.25/drivers/block/Makefile 2011-07-22 11:17:44.000000000 +0200
969 +++ linux-3.0.25-vs2.3.2.3/drivers/block/Makefile       2011-06-10 22:11:24.000000000 +0200
970 @@ -34,6 +34,7 @@ obj-$(CONFIG_VIODASD)         += viodasd.o
971  obj-$(CONFIG_BLK_DEV_SX8)      += sx8.o
972  obj-$(CONFIG_BLK_DEV_UB)       += ub.o
973  obj-$(CONFIG_BLK_DEV_HD)       += hd.o
974 +obj-$(CONFIG_BLK_DEV_VROOT)    += vroot.o
975  
976  obj-$(CONFIG_XEN_BLKDEV_FRONTEND)      += xen-blkfront.o
977  obj-$(CONFIG_XEN_BLKDEV_BACKEND)       += xen-blkback/
978 diff -NurpP --minimal linux-3.0.25/drivers/block/loop.c linux-3.0.25-vs2.3.2.3/drivers/block/loop.c
979 --- linux-3.0.25/drivers/block/loop.c   2012-03-19 21:16:39.000000000 +0100
980 +++ linux-3.0.25-vs2.3.2.3/drivers/block/loop.c 2011-08-31 19:37:44.000000000 +0200
981 @@ -75,6 +75,7 @@
982  #include <linux/kthread.h>
983  #include <linux/splice.h>
984  #include <linux/sysfs.h>
985 +#include <linux/vs_context.h>
986  
987  #include <asm/uaccess.h>
988  
989 @@ -891,6 +892,7 @@ static int loop_set_fd(struct loop_devic
990         lo->lo_blocksize = lo_blocksize;
991         lo->lo_device = bdev;
992         lo->lo_flags = lo_flags;
993 +       lo->lo_xid = vx_current_xid();
994         lo->lo_backing_file = file;
995         lo->transfer = transfer_none;
996         lo->ioctl = NULL;
997 @@ -1021,6 +1023,7 @@ static int loop_clr_fd(struct loop_devic
998         lo->lo_encrypt_key_size = 0;
999         lo->lo_flags = 0;
1000         lo->lo_thread = NULL;
1001 +       lo->lo_xid = 0;
1002         memset(lo->lo_encrypt_key, 0, LO_KEY_SIZE);
1003         memset(lo->lo_crypt_name, 0, LO_NAME_SIZE);
1004         memset(lo->lo_file_name, 0, LO_NAME_SIZE);
1005 @@ -1059,7 +1062,7 @@ loop_set_status(struct loop_device *lo, 
1006  
1007         if (lo->lo_encrypt_key_size &&
1008             lo->lo_key_owner != uid &&
1009 -           !capable(CAP_SYS_ADMIN))
1010 +           !vx_capable(CAP_SYS_ADMIN, VXC_ADMIN_CLOOP))
1011                 return -EPERM;
1012         if (lo->lo_state != Lo_bound)
1013                 return -ENXIO;
1014 @@ -1143,7 +1146,8 @@ loop_get_status(struct loop_device *lo, 
1015         memcpy(info->lo_crypt_name, lo->lo_crypt_name, LO_NAME_SIZE);
1016         info->lo_encrypt_type =
1017                 lo->lo_encryption ? lo->lo_encryption->number : 0;
1018 -       if (lo->lo_encrypt_key_size && capable(CAP_SYS_ADMIN)) {
1019 +       if (lo->lo_encrypt_key_size &&
1020 +               vx_capable(CAP_SYS_ADMIN, VXC_ADMIN_CLOOP)) {
1021                 info->lo_encrypt_key_size = lo->lo_encrypt_key_size;
1022                 memcpy(info->lo_encrypt_key, lo->lo_encrypt_key,
1023                        lo->lo_encrypt_key_size);
1024 @@ -1489,6 +1493,9 @@ static int lo_open(struct block_device *
1025  {
1026         struct loop_device *lo = bdev->bd_disk->private_data;
1027  
1028 +       if (!vx_check(lo->lo_xid, VS_IDENT|VS_HOSTID|VS_ADMIN_P))
1029 +               return -EACCES;
1030 +
1031         mutex_lock(&lo->lo_ctl_mutex);
1032         lo->lo_refcnt++;
1033         mutex_unlock(&lo->lo_ctl_mutex);
1034 diff -NurpP --minimal linux-3.0.25/drivers/block/vroot.c linux-3.0.25-vs2.3.2.3/drivers/block/vroot.c
1035 --- linux-3.0.25/drivers/block/vroot.c  1970-01-01 01:00:00.000000000 +0100
1036 +++ linux-3.0.25-vs2.3.2.3/drivers/block/vroot.c        2011-06-10 22:11:24.000000000 +0200
1037 @@ -0,0 +1,292 @@
1038 +/*
1039 + *  linux/drivers/block/vroot.c
1040 + *
1041 + *  written by Herbert Pötzl, 9/11/2002
1042 + *  ported to 2.6.10 by Herbert Pötzl, 30/12/2004
1043 + *
1044 + *  based on the loop.c code by Theodore Ts'o.
1045 + *
1046 + * Copyright (C) 2002-2007 by Herbert Pötzl.
1047 + * Redistribution of this file is permitted under the
1048 + * GNU General Public License.
1049 + *
1050 + */
1051 +
1052 +#include <linux/module.h>
1053 +#include <linux/moduleparam.h>
1054 +#include <linux/file.h>
1055 +#include <linux/major.h>
1056 +#include <linux/blkdev.h>
1057 +#include <linux/slab.h>
1058 +
1059 +#include <linux/vroot.h>
1060 +#include <linux/vs_context.h>
1061 +
1062 +
1063 +static int max_vroot = 8;
1064 +
1065 +static struct vroot_device *vroot_dev;
1066 +static struct gendisk **disks;
1067 +
1068 +
1069 +static int vroot_set_dev(
1070 +       struct vroot_device *vr,
1071 +       struct block_device *bdev,
1072 +       unsigned int arg)
1073 +{
1074 +       struct block_device *real_bdev;
1075 +       struct file *file;
1076 +       struct inode *inode;
1077 +       int error;
1078 +
1079 +       error = -EBUSY;
1080 +       if (vr->vr_state != Vr_unbound)
1081 +               goto out;
1082 +
1083 +       error = -EBADF;
1084 +       file = fget(arg);
1085 +       if (!file)
1086 +               goto out;
1087 +
1088 +       error = -EINVAL;
1089 +       inode = file->f_dentry->d_inode;
1090 +
1091 +
1092 +       if (S_ISBLK(inode->i_mode)) {
1093 +               real_bdev = inode->i_bdev;
1094 +               vr->vr_device = real_bdev;
1095 +               __iget(real_bdev->bd_inode);
1096 +       } else
1097 +               goto out_fput;
1098 +
1099 +       vxdprintk(VXD_CBIT(misc, 0),
1100 +               "vroot[%d]_set_dev: dev=" VXF_DEV,
1101 +               vr->vr_number, VXD_DEV(real_bdev));
1102 +
1103 +       vr->vr_state = Vr_bound;
1104 +       error = 0;
1105 +
1106 + out_fput:
1107 +       fput(file);
1108 + out:
1109 +       return error;
1110 +}
1111 +
1112 +static int vroot_clr_dev(
1113 +       struct vroot_device *vr,
1114 +       struct block_device *bdev)
1115 +{
1116 +       struct block_device *real_bdev;
1117 +
1118 +       if (vr->vr_state != Vr_bound)
1119 +               return -ENXIO;
1120 +       if (vr->vr_refcnt > 1)  /* we needed one fd for the ioctl */
1121 +               return -EBUSY;
1122 +
1123 +       real_bdev = vr->vr_device;
1124 +
1125 +       vxdprintk(VXD_CBIT(misc, 0),
1126 +               "vroot[%d]_clr_dev: dev=" VXF_DEV,
1127 +               vr->vr_number, VXD_DEV(real_bdev));
1128 +
1129 +       bdput(real_bdev);
1130 +       vr->vr_state = Vr_unbound;
1131 +       vr->vr_device = NULL;
1132 +       return 0;
1133 +}
1134 +
1135 +
1136 +static int vr_ioctl(struct block_device *bdev, fmode_t mode,
1137 +       unsigned int cmd, unsigned long arg)
1138 +{
1139 +       struct vroot_device *vr = bdev->bd_disk->private_data;
1140 +       int err;
1141 +
1142 +       down(&vr->vr_ctl_mutex);
1143 +       switch (cmd) {
1144 +       case VROOT_SET_DEV:
1145 +               err = vroot_set_dev(vr, bdev, arg);
1146 +               break;
1147 +       case VROOT_CLR_DEV:
1148 +               err = vroot_clr_dev(vr, bdev);
1149 +               break;
1150 +       default:
1151 +               err = -EINVAL;
1152 +               break;
1153 +       }
1154 +       up(&vr->vr_ctl_mutex);
1155 +       return err;
1156 +}
1157 +
1158 +static int vr_open(struct block_device *bdev, fmode_t mode)
1159 +{
1160 +       struct vroot_device *vr = bdev->bd_disk->private_data;
1161 +
1162 +       down(&vr->vr_ctl_mutex);
1163 +       vr->vr_refcnt++;
1164 +       up(&vr->vr_ctl_mutex);
1165 +       return 0;
1166 +}
1167 +
1168 +static int vr_release(struct gendisk *disk, fmode_t mode)
1169 +{
1170 +       struct vroot_device *vr = disk->private_data;
1171 +
1172 +       down(&vr->vr_ctl_mutex);
1173 +       --vr->vr_refcnt;
1174 +       up(&vr->vr_ctl_mutex);
1175 +       return 0;
1176 +}
1177 +
1178 +static struct block_device_operations vr_fops = {
1179 +       .owner =        THIS_MODULE,
1180 +       .open =         vr_open,
1181 +       .release =      vr_release,
1182 +       .ioctl =        vr_ioctl,
1183 +};
1184 +
1185 +static int vroot_make_request(struct request_queue *q, struct bio *bio)
1186 +{
1187 +       printk("vroot_make_request %p, %p\n", q, bio);
1188 +       bio_io_error(bio);
1189 +       return 0;
1190 +}
1191 +
1192 +struct block_device *__vroot_get_real_bdev(struct block_device *bdev)
1193 +{
1194 +       struct inode *inode = bdev->bd_inode;
1195 +       struct vroot_device *vr;
1196 +       struct block_device *real_bdev;
1197 +       int minor = iminor(inode);
1198 +
1199 +       vr = &vroot_dev[minor];
1200 +       real_bdev = vr->vr_device;
1201 +
1202 +       vxdprintk(VXD_CBIT(misc, 0),
1203 +               "vroot[%d]_get_real_bdev: dev=" VXF_DEV,
1204 +               vr->vr_number, VXD_DEV(real_bdev));
1205 +
1206 +       if (vr->vr_state != Vr_bound)
1207 +               return ERR_PTR(-ENXIO);
1208 +
1209 +       __iget(real_bdev->bd_inode);
1210 +       return real_bdev;
1211 +}
1212 +
1213 +
1214 +
1215 +/*
1216 + * And now the modules code and kernel interface.
1217 + */
1218 +
1219 +module_param(max_vroot, int, 0);
1220 +
1221 +MODULE_PARM_DESC(max_vroot, "Maximum number of vroot devices (1-256)");
1222 +MODULE_LICENSE("GPL");
1223 +MODULE_ALIAS_BLOCKDEV_MAJOR(VROOT_MAJOR);
1224 +
1225 +MODULE_AUTHOR ("Herbert Pötzl");
1226 +MODULE_DESCRIPTION ("Virtual Root Device Mapper");
1227 +
1228 +
1229 +int __init vroot_init(void)
1230 +{
1231 +       int err, i;
1232 +
1233 +       if (max_vroot < 1 || max_vroot > 256) {
1234 +               max_vroot = MAX_VROOT_DEFAULT;
1235 +               printk(KERN_WARNING "vroot: invalid max_vroot "
1236 +                       "(must be between 1 and 256), "
1237 +                       "using default (%d)\n", max_vroot);
1238 +       }
1239 +
1240 +       if (register_blkdev(VROOT_MAJOR, "vroot"))
1241 +               return -EIO;
1242 +
1243 +       err = -ENOMEM;
1244 +       vroot_dev = kmalloc(max_vroot * sizeof(struct vroot_device), GFP_KERNEL);
1245 +       if (!vroot_dev)
1246 +               goto out_mem1;
1247 +       memset(vroot_dev, 0, max_vroot * sizeof(struct vroot_device));
1248 +
1249 +       disks = kmalloc(max_vroot * sizeof(struct gendisk *), GFP_KERNEL);
1250 +       if (!disks)
1251 +               goto out_mem2;
1252 +
1253 +       for (i = 0; i < max_vroot; i++) {
1254 +               disks[i] = alloc_disk(1);
1255 +               if (!disks[i])
1256 +                       goto out_mem3;
1257 +               disks[i]->queue = blk_alloc_queue(GFP_KERNEL);
1258 +               if (!disks[i]->queue)
1259 +                       goto out_mem3;
1260 +               blk_queue_make_request(disks[i]->queue, vroot_make_request);
1261 +       }
1262 +
1263 +       for (i = 0; i < max_vroot; i++) {
1264 +               struct vroot_device *vr = &vroot_dev[i];
1265 +               struct gendisk *disk = disks[i];
1266 +
1267 +               memset(vr, 0, sizeof(*vr));
1268 +               sema_init(&vr->vr_ctl_mutex, 1);
1269 +               vr->vr_number = i;
1270 +               disk->major = VROOT_MAJOR;
1271 +               disk->first_minor = i;
1272 +               disk->fops = &vr_fops;
1273 +               sprintf(disk->disk_name, "vroot%d", i);
1274 +               disk->private_data = vr;
1275 +       }
1276 +
1277 +       err = register_vroot_grb(&__vroot_get_real_bdev);
1278 +       if (err)
1279 +               goto out_mem3;
1280 +
1281 +       for (i = 0; i < max_vroot; i++)
1282 +               add_disk(disks[i]);
1283 +       printk(KERN_INFO "vroot: loaded (max %d devices)\n", max_vroot);
1284 +       return 0;
1285 +
1286 +out_mem3:
1287 +       while (i--)
1288 +               put_disk(disks[i]);
1289 +       kfree(disks);
1290 +out_mem2:
1291 +       kfree(vroot_dev);
1292 +out_mem1:
1293 +       unregister_blkdev(VROOT_MAJOR, "vroot");
1294 +       printk(KERN_ERR "vroot: ran out of memory\n");
1295 +       return err;
1296 +}
1297 +
1298 +void vroot_exit(void)
1299 +{
1300 +       int i;
1301 +
1302 +       if (unregister_vroot_grb(&__vroot_get_real_bdev))
1303 +               printk(KERN_WARNING "vroot: cannot unregister grb\n");
1304 +
1305 +       for (i = 0; i < max_vroot; i++) {
1306 +               del_gendisk(disks[i]);
1307 +               put_disk(disks[i]);
1308 +       }
1309 +       unregister_blkdev(VROOT_MAJOR, "vroot");
1310 +
1311 +       kfree(disks);
1312 +       kfree(vroot_dev);
1313 +}
1314 +
1315 +module_init(vroot_init);
1316 +module_exit(vroot_exit);
1317 +
1318 +#ifndef MODULE
1319 +
1320 +static int __init max_vroot_setup(char *str)
1321 +{
1322 +       max_vroot = simple_strtol(str, NULL, 0);
1323 +       return 1;
1324 +}
1325 +
1326 +__setup("max_vroot=", max_vroot_setup);
1327 +
1328 +#endif
1329 +
1330 diff -NurpP --minimal linux-3.0.25/drivers/infiniband/Kconfig linux-3.0.25-vs2.3.2.3/drivers/infiniband/Kconfig
1331 --- linux-3.0.25/drivers/infiniband/Kconfig     2011-07-22 11:17:45.000000000 +0200
1332 +++ linux-3.0.25-vs2.3.2.3/drivers/infiniband/Kconfig   2012-02-15 05:19:42.000000000 +0100
1333 @@ -39,7 +39,7 @@ config INFINIBAND_USER_MEM
1334  config INFINIBAND_ADDR_TRANS
1335         bool
1336         depends on INET
1337 -       depends on !(INFINIBAND = y && IPV6 = m)
1338 +       depends on !(INFINIBAND = y && IPV6 = y)
1339         default y
1340  
1341  source "drivers/infiniband/hw/mthca/Kconfig"
1342 diff -NurpP --minimal linux-3.0.25/drivers/infiniband/core/addr.c linux-3.0.25-vs2.3.2.3/drivers/infiniband/core/addr.c
1343 --- linux-3.0.25/drivers/infiniband/core/addr.c 2012-03-19 21:16:40.000000000 +0100
1344 +++ linux-3.0.25-vs2.3.2.3/drivers/infiniband/core/addr.c       2012-02-15 05:20:43.000000000 +0100
1345 @@ -254,7 +254,7 @@ static int addr6_resolve(struct sockaddr
1346  
1347         if (ipv6_addr_any(&fl6.saddr)) {
1348                 ret = ipv6_dev_get_saddr(&init_net, ip6_dst_idev(dst)->dev,
1349 -                                        &fl6.daddr, 0, &fl6.saddr);
1350 +                                        &fl6.daddr, 0, &fl6.saddr, NULL);
1351                 if (ret)
1352                         goto put;
1353  
1354 diff -NurpP --minimal linux-3.0.25/drivers/infiniband/hw/ipath/ipath_user_pages.c linux-3.0.25-vs2.3.2.3/drivers/infiniband/hw/ipath/ipath_user_pages.c
1355 --- linux-3.0.25/drivers/infiniband/hw/ipath/ipath_user_pages.c 2011-05-22 16:17:16.000000000 +0200
1356 +++ linux-3.0.25-vs2.3.2.3/drivers/infiniband/hw/ipath/ipath_user_pages.c       2011-06-10 22:11:24.000000000 +0200
1357 @@ -35,6 +35,7 @@
1358  #include <linux/device.h>
1359  #include <linux/slab.h>
1360  #include <linux/sched.h>
1361 +#include <linux/vs_memory.h>
1362  
1363  #include "ipath_kernel.h"
1364  
1365 diff -NurpP --minimal linux-3.0.25/drivers/md/dm-ioctl.c linux-3.0.25-vs2.3.2.3/drivers/md/dm-ioctl.c
1366 --- linux-3.0.25/drivers/md/dm-ioctl.c  2011-05-22 16:17:18.000000000 +0200
1367 +++ linux-3.0.25-vs2.3.2.3/drivers/md/dm-ioctl.c        2011-06-10 22:11:24.000000000 +0200
1368 @@ -16,6 +16,7 @@
1369  #include <linux/dm-ioctl.h>
1370  #include <linux/hdreg.h>
1371  #include <linux/compat.h>
1372 +#include <linux/vs_context.h>
1373  
1374  #include <asm/uaccess.h>
1375  
1376 @@ -106,7 +107,8 @@ static struct hash_cell *__get_name_cell
1377         unsigned int h = hash_str(str);
1378  
1379         list_for_each_entry (hc, _name_buckets + h, name_list)
1380 -               if (!strcmp(hc->name, str)) {
1381 +               if (vx_check(dm_get_xid(hc->md), VS_WATCH_P | VS_IDENT) &&
1382 +                       !strcmp(hc->name, str)) {
1383                         dm_get(hc->md);
1384                         return hc;
1385                 }
1386 @@ -120,7 +122,8 @@ static struct hash_cell *__get_uuid_cell
1387         unsigned int h = hash_str(str);
1388  
1389         list_for_each_entry (hc, _uuid_buckets + h, uuid_list)
1390 -               if (!strcmp(hc->uuid, str)) {
1391 +               if (vx_check(dm_get_xid(hc->md), VS_WATCH_P | VS_IDENT) &&
1392 +                       !strcmp(hc->uuid, str)) {
1393                         dm_get(hc->md);
1394                         return hc;
1395                 }
1396 @@ -427,6 +430,9 @@ typedef int (*ioctl_fn)(struct dm_ioctl 
1397  
1398  static int remove_all(struct dm_ioctl *param, size_t param_size)
1399  {
1400 +       if (!vx_check(0, VS_ADMIN))
1401 +               return -EPERM;
1402 +
1403         dm_hash_remove_all(1);
1404         param->data_size = 0;
1405         return 0;
1406 @@ -474,6 +480,8 @@ static int list_devices(struct dm_ioctl 
1407          */
1408         for (i = 0; i < NUM_BUCKETS; i++) {
1409                 list_for_each_entry (hc, _name_buckets + i, name_list) {
1410 +                       if (!vx_check(dm_get_xid(hc->md), VS_WATCH_P | VS_IDENT))
1411 +                               continue;
1412                         needed += sizeof(struct dm_name_list);
1413                         needed += strlen(hc->name) + 1;
1414                         needed += ALIGN_MASK;
1415 @@ -497,6 +505,8 @@ static int list_devices(struct dm_ioctl 
1416          */
1417         for (i = 0; i < NUM_BUCKETS; i++) {
1418                 list_for_each_entry (hc, _name_buckets + i, name_list) {
1419 +                       if (!vx_check(dm_get_xid(hc->md), VS_WATCH_P | VS_IDENT))
1420 +                               continue;
1421                         if (old_nl)
1422                                 old_nl->next = (uint32_t) ((void *) nl -
1423                                                            (void *) old_nl);
1424 @@ -731,10 +741,11 @@ static struct hash_cell *__find_device_h
1425         if (!md)
1426                 goto out;
1427  
1428 -       mdptr = dm_get_mdptr(md);
1429 +       if (vx_check(dm_get_xid(md), VS_WATCH_P | VS_IDENT))
1430 +               mdptr = dm_get_mdptr(md);
1431 +
1432         if (!mdptr)
1433                 dm_put(md);
1434 -
1435  out:
1436         return mdptr;
1437  }
1438 @@ -1577,8 +1588,8 @@ static int ctl_ioctl(uint command, struc
1439         ioctl_fn fn = NULL;
1440         size_t input_param_size;
1441  
1442 -       /* only root can play with this */
1443 -       if (!capable(CAP_SYS_ADMIN))
1444 +       /* only root and certain contexts can play with this */
1445 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_ADMIN_MAPPER))
1446                 return -EACCES;
1447  
1448         if (_IOC_TYPE(command) != DM_IOCTL)
1449 diff -NurpP --minimal linux-3.0.25/drivers/md/dm.c linux-3.0.25-vs2.3.2.3/drivers/md/dm.c
1450 --- linux-3.0.25/drivers/md/dm.c        2012-03-19 21:16:41.000000000 +0100
1451 +++ linux-3.0.25-vs2.3.2.3/drivers/md/dm.c      2011-08-08 23:04:47.000000000 +0200
1452 @@ -20,6 +20,7 @@
1453  #include <linux/idr.h>
1454  #include <linux/hdreg.h>
1455  #include <linux/delay.h>
1456 +#include <linux/vs_base.h>
1457  
1458  #include <trace/events/block.h>
1459  
1460 @@ -121,6 +122,7 @@ struct mapped_device {
1461         rwlock_t map_lock;
1462         atomic_t holders;
1463         atomic_t open_count;
1464 +       xid_t xid;
1465  
1466         unsigned long flags;
1467  
1468 @@ -334,6 +336,7 @@ int dm_deleting_md(struct mapped_device 
1469  static int dm_blk_open(struct block_device *bdev, fmode_t mode)
1470  {
1471         struct mapped_device *md;
1472 +       int ret = -ENXIO;
1473  
1474         spin_lock(&_minor_lock);
1475  
1476 @@ -342,18 +345,19 @@ static int dm_blk_open(struct block_devi
1477                 goto out;
1478  
1479         if (test_bit(DMF_FREEING, &md->flags) ||
1480 -           dm_deleting_md(md)) {
1481 -               md = NULL;
1482 +           dm_deleting_md(md))
1483 +               goto out;
1484 +
1485 +       ret = -EACCES;
1486 +       if (!vx_check(md->xid, VS_IDENT|VS_HOSTID))
1487                 goto out;
1488 -       }
1489  
1490         dm_get(md);
1491         atomic_inc(&md->open_count);
1492 -
1493 +       ret = 0;
1494  out:
1495         spin_unlock(&_minor_lock);
1496 -
1497 -       return md ? 0 : -ENXIO;
1498 +       return ret;
1499  }
1500  
1501  static int dm_blk_close(struct gendisk *disk, fmode_t mode)
1502 @@ -574,6 +578,14 @@ int dm_set_geometry(struct mapped_device
1503         return 0;
1504  }
1505  
1506 +/*
1507 + * Get the xid associated with a dm device
1508 + */
1509 +xid_t dm_get_xid(struct mapped_device *md)
1510 +{
1511 +       return md->xid;
1512 +}
1513 +
1514  /*-----------------------------------------------------------------
1515   * CRUD START:
1516   *   A more elegant soln is in the works that uses the queue
1517 @@ -1847,6 +1859,7 @@ static struct mapped_device *alloc_dev(i
1518         INIT_LIST_HEAD(&md->uevent_list);
1519         spin_lock_init(&md->uevent_lock);
1520  
1521 +       md->xid = vx_current_xid();
1522         md->queue = blk_alloc_queue(GFP_KERNEL);
1523         if (!md->queue)
1524                 goto bad_queue;
1525 diff -NurpP --minimal linux-3.0.25/drivers/md/dm.h linux-3.0.25-vs2.3.2.3/drivers/md/dm.h
1526 --- linux-3.0.25/drivers/md/dm.h        2011-05-22 16:17:18.000000000 +0200
1527 +++ linux-3.0.25-vs2.3.2.3/drivers/md/dm.h      2011-06-10 22:11:24.000000000 +0200
1528 @@ -41,6 +41,8 @@ struct dm_dev_internal {
1529  struct dm_table;
1530  struct dm_md_mempools;
1531  
1532 +xid_t dm_get_xid(struct mapped_device *md);
1533 +
1534  /*-----------------------------------------------------------------
1535   * Internal table functions.
1536   *---------------------------------------------------------------*/
1537 diff -NurpP --minimal linux-3.0.25/drivers/net/tun.c linux-3.0.25-vs2.3.2.3/drivers/net/tun.c
1538 --- linux-3.0.25/drivers/net/tun.c      2012-03-19 21:16:45.000000000 +0100
1539 +++ linux-3.0.25-vs2.3.2.3/drivers/net/tun.c    2011-08-29 03:45:08.000000000 +0200
1540 @@ -64,6 +64,7 @@
1541  #include <linux/nsproxy.h>
1542  #include <linux/virtio_net.h>
1543  #include <linux/rcupdate.h>
1544 +#include <linux/vs_network.h>
1545  #include <net/net_namespace.h>
1546  #include <net/netns/generic.h>
1547  #include <net/rtnetlink.h>
1548 @@ -121,6 +122,7 @@ struct tun_struct {
1549         unsigned int            flags;
1550         uid_t                   owner;
1551         gid_t                   group;
1552 +       nid_t                   nid;
1553  
1554         struct net_device       *dev;
1555         u32                     set_features;
1556 @@ -905,6 +907,7 @@ static void tun_setup(struct net_device 
1557  
1558         tun->owner = -1;
1559         tun->group = -1;
1560 +       tun->nid = current->nid;
1561  
1562         dev->ethtool_ops = &tun_ethtool_ops;
1563         dev->destructor = tun_free_netdev;
1564 @@ -1055,7 +1058,7 @@ static int tun_set_iff(struct net *net, 
1565  
1566                 if (((tun->owner != -1 && cred->euid != tun->owner) ||
1567                      (tun->group != -1 && !in_egroup_p(tun->group))) &&
1568 -                   !capable(CAP_NET_ADMIN))
1569 +               !cap_raised(current_cap(), CAP_NET_ADMIN))
1570                         return -EPERM;
1571                 err = security_tun_dev_attach(tun->socket.sk);
1572                 if (err < 0)
1573 @@ -1069,7 +1072,7 @@ static int tun_set_iff(struct net *net, 
1574                 char *name;
1575                 unsigned long flags = 0;
1576  
1577 -               if (!capable(CAP_NET_ADMIN))
1578 +               if (!nx_capable(CAP_NET_ADMIN, NXC_TUN_CREATE))
1579                         return -EPERM;
1580                 err = security_tun_dev_create();
1581                 if (err < 0)
1582 @@ -1137,6 +1140,9 @@ static int tun_set_iff(struct net *net, 
1583  
1584                 sk->sk_destruct = tun_sock_destruct;
1585  
1586 +               if (!nx_check(tun->nid, VS_IDENT | VS_HOSTID | VS_ADMIN_P))
1587 +                       return -EPERM;
1588 +
1589                 err = tun_attach(tun, file);
1590                 if (err < 0)
1591                         goto failed;
1592 @@ -1318,6 +1324,16 @@ static long __tun_chr_ioctl(struct file 
1593                 tun_debug(KERN_INFO, tun, "group set to %d\n", tun->group);
1594                 break;
1595  
1596 +       case TUNSETNID:
1597 +               if (!capable(CAP_CONTEXT))
1598 +                       return -EPERM;
1599 +
1600 +               /* Set nid owner of the device */
1601 +               tun->nid = (nid_t) arg;
1602 +
1603 +               tun_debug(KERN_INFO, tun, "nid owner set to %u\n", tun->nid);
1604 +               break;
1605 +
1606         case TUNSETLINK:
1607                 /* Only allow setting the type when the interface is down */
1608                 if (tun->dev->flags & IFF_UP) {
1609 diff -NurpP --minimal linux-3.0.25/drivers/tty/sysrq.c linux-3.0.25-vs2.3.2.3/drivers/tty/sysrq.c
1610 --- linux-3.0.25/drivers/tty/sysrq.c    2011-05-22 16:17:44.000000000 +0200
1611 +++ linux-3.0.25-vs2.3.2.3/drivers/tty/sysrq.c  2011-06-10 22:11:24.000000000 +0200
1612 @@ -41,6 +41,7 @@
1613  #include <linux/oom.h>
1614  #include <linux/slab.h>
1615  #include <linux/input.h>
1616 +#include <linux/vserver/debug.h>
1617  
1618  #include <asm/ptrace.h>
1619  #include <asm/irq_regs.h>
1620 @@ -395,6 +396,21 @@ static struct sysrq_key_op sysrq_unrt_op
1621         .enable_mask    = SYSRQ_ENABLE_RTNICE,
1622  };
1623  
1624 +
1625 +#ifdef CONFIG_VSERVER_DEBUG
1626 +static void sysrq_handle_vxinfo(int key)
1627 +{
1628 +       dump_vx_info_inactive((key == 'x') ? 0 : 1);
1629 +}
1630 +
1631 +static struct sysrq_key_op sysrq_showvxinfo_op = {
1632 +       .handler        = sysrq_handle_vxinfo,
1633 +       .help_msg       = "conteXt",
1634 +       .action_msg     = "Show Context Info",
1635 +       .enable_mask    = SYSRQ_ENABLE_DUMP,
1636 +};
1637 +#endif
1638 +
1639  /* Key Operations table and lock */
1640  static DEFINE_SPINLOCK(sysrq_key_table_lock);
1641  
1642 @@ -449,7 +465,11 @@ static struct sysrq_key_op *sysrq_key_ta
1643         NULL,                           /* v */
1644         &sysrq_showstate_blocked_op,    /* w */
1645         /* x: May be registered on ppc/powerpc for xmon */
1646 +#ifdef CONFIG_VSERVER_DEBUG
1647 +       &sysrq_showvxinfo_op,           /* x */
1648 +#else
1649         NULL,                           /* x */
1650 +#endif
1651         /* y: May be registered on sparc64 for global register dump */
1652         NULL,                           /* y */
1653         &sysrq_ftrace_dump_op,          /* z */
1654 @@ -464,6 +484,8 @@ static int sysrq_key_table_key2index(int
1655                 retval = key - '0';
1656         else if ((key >= 'a') && (key <= 'z'))
1657                 retval = key + 10 - 'a';
1658 +       else if ((key >= 'A') && (key <= 'Z'))
1659 +               retval = key + 10 - 'A';
1660         else
1661                 retval = -1;
1662         return retval;
1663 diff -NurpP --minimal linux-3.0.25/drivers/tty/tty_io.c linux-3.0.25-vs2.3.2.3/drivers/tty/tty_io.c
1664 --- linux-3.0.25/drivers/tty/tty_io.c   2012-03-19 21:16:50.000000000 +0100
1665 +++ linux-3.0.25-vs2.3.2.3/drivers/tty/tty_io.c 2011-11-15 17:37:05.000000000 +0100
1666 @@ -104,6 +104,7 @@
1667  
1668  #include <linux/kmod.h>
1669  #include <linux/nsproxy.h>
1670 +#include <linux/vs_pid.h>
1671  
1672  #undef TTY_DEBUG_HANGUP
1673  
1674 @@ -2080,7 +2081,8 @@ static int tiocsti(struct tty_struct *tt
1675         char ch, mbz = 0;
1676         struct tty_ldisc *ld;
1677  
1678 -       if ((current->signal->tty != tty) && !capable(CAP_SYS_ADMIN))
1679 +       if (((current->signal->tty != tty) &&
1680 +               !vx_capable(CAP_SYS_ADMIN, VXC_TIOCSTI)))
1681                 return -EPERM;
1682         if (get_user(ch, p))
1683                 return -EFAULT;
1684 @@ -2368,6 +2370,7 @@ static int tiocspgrp(struct tty_struct *
1685                 return -ENOTTY;
1686         if (get_user(pgrp_nr, p))
1687                 return -EFAULT;
1688 +       pgrp_nr = vx_rmap_pid(pgrp_nr);
1689         if (pgrp_nr < 0)
1690                 return -EINVAL;
1691         rcu_read_lock();
1692 diff -NurpP --minimal linux-3.0.25/fs/attr.c linux-3.0.25-vs2.3.2.3/fs/attr.c
1693 --- linux-3.0.25/fs/attr.c      2011-07-22 11:18:05.000000000 +0200
1694 +++ linux-3.0.25-vs2.3.2.3/fs/attr.c    2011-06-10 22:11:24.000000000 +0200
1695 @@ -13,6 +13,9 @@
1696  #include <linux/fsnotify.h>
1697  #include <linux/fcntl.h>
1698  #include <linux/security.h>
1699 +#include <linux/proc_fs.h>
1700 +#include <linux/devpts_fs.h>
1701 +#include <linux/vs_tag.h>
1702  
1703  /**
1704   * inode_change_ok - check if attribute changes to an inode are allowed
1705 @@ -73,6 +76,10 @@ int inode_change_ok(const struct inode *
1706                         return -EPERM;
1707         }
1708  
1709 +       /* check for inode tag permission */
1710 +       if (dx_permission(inode, MAY_WRITE))
1711 +               return -EACCES;
1712 +
1713         return 0;
1714  }
1715  EXPORT_SYMBOL(inode_change_ok);
1716 @@ -143,6 +150,8 @@ void setattr_copy(struct inode *inode, c
1717                 inode->i_uid = attr->ia_uid;
1718         if (ia_valid & ATTR_GID)
1719                 inode->i_gid = attr->ia_gid;
1720 +       if ((ia_valid & ATTR_TAG) && IS_TAGGED(inode))
1721 +               inode->i_tag = attr->ia_tag;
1722         if (ia_valid & ATTR_ATIME)
1723                 inode->i_atime = timespec_trunc(attr->ia_atime,
1724                                                 inode->i_sb->s_time_gran);
1725 @@ -170,7 +179,8 @@ int notify_change(struct dentry * dentry
1726         struct timespec now;
1727         unsigned int ia_valid = attr->ia_valid;
1728  
1729 -       if (ia_valid & (ATTR_MODE | ATTR_UID | ATTR_GID | ATTR_TIMES_SET)) {
1730 +       if (ia_valid & (ATTR_MODE | ATTR_UID | ATTR_GID |
1731 +               ATTR_TAG | ATTR_TIMES_SET)) {
1732                 if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
1733                         return -EPERM;
1734         }
1735 diff -NurpP --minimal linux-3.0.25/fs/binfmt_aout.c linux-3.0.25-vs2.3.2.3/fs/binfmt_aout.c
1736 --- linux-3.0.25/fs/binfmt_aout.c       2010-10-21 13:07:47.000000000 +0200
1737 +++ linux-3.0.25-vs2.3.2.3/fs/binfmt_aout.c     2011-06-10 22:11:24.000000000 +0200
1738 @@ -25,6 +25,7 @@
1739  #include <linux/init.h>
1740  #include <linux/coredump.h>
1741  #include <linux/slab.h>
1742 +#include <linux/vs_memory.h>
1743  
1744  #include <asm/system.h>
1745  #include <asm/uaccess.h>
1746 diff -NurpP --minimal linux-3.0.25/fs/binfmt_elf.c linux-3.0.25-vs2.3.2.3/fs/binfmt_elf.c
1747 --- linux-3.0.25/fs/binfmt_elf.c        2012-03-19 21:16:51.000000000 +0100
1748 +++ linux-3.0.25-vs2.3.2.3/fs/binfmt_elf.c      2012-03-15 13:32:35.000000000 +0100
1749 @@ -32,6 +32,7 @@
1750  #include <linux/elf.h>
1751  #include <linux/utsname.h>
1752  #include <linux/coredump.h>
1753 +#include <linux/vs_memory.h>
1754  #include <asm/uaccess.h>
1755  #include <asm/param.h>
1756  #include <asm/page.h>
1757 diff -NurpP --minimal linux-3.0.25/fs/binfmt_flat.c linux-3.0.25-vs2.3.2.3/fs/binfmt_flat.c
1758 --- linux-3.0.25/fs/binfmt_flat.c       2011-07-22 11:18:05.000000000 +0200
1759 +++ linux-3.0.25-vs2.3.2.3/fs/binfmt_flat.c     2011-06-10 22:11:24.000000000 +0200
1760 @@ -35,6 +35,7 @@
1761  #include <linux/init.h>
1762  #include <linux/flat.h>
1763  #include <linux/syscalls.h>
1764 +#include <linux/vs_memory.h>
1765  
1766  #include <asm/byteorder.h>
1767  #include <asm/system.h>
1768 diff -NurpP --minimal linux-3.0.25/fs/binfmt_som.c linux-3.0.25-vs2.3.2.3/fs/binfmt_som.c
1769 --- linux-3.0.25/fs/binfmt_som.c        2010-02-25 11:52:04.000000000 +0100
1770 +++ linux-3.0.25-vs2.3.2.3/fs/binfmt_som.c      2011-06-10 22:11:24.000000000 +0200
1771 @@ -28,6 +28,7 @@
1772  #include <linux/shm.h>
1773  #include <linux/personality.h>
1774  #include <linux/init.h>
1775 +#include <linux/vs_memory.h>
1776  
1777  #include <asm/uaccess.h>
1778  #include <asm/pgtable.h>
1779 diff -NurpP --minimal linux-3.0.25/fs/block_dev.c linux-3.0.25-vs2.3.2.3/fs/block_dev.c
1780 --- linux-3.0.25/fs/block_dev.c 2012-03-19 21:16:51.000000000 +0100
1781 +++ linux-3.0.25-vs2.3.2.3/fs/block_dev.c       2012-03-23 14:54:00.000000000 +0100
1782 @@ -25,6 +25,7 @@
1783  #include <linux/namei.h>
1784  #include <linux/log2.h>
1785  #include <linux/kmemleak.h>
1786 +#include <linux/vs_device.h>
1787  #include <asm/uaccess.h>
1788  #include "internal.h"
1789  
1790 @@ -553,6 +554,7 @@ struct block_device *bdget(dev_t dev)
1791                 bdev->bd_invalidated = 0;
1792                 inode->i_mode = S_IFBLK;
1793                 inode->i_rdev = dev;
1794 +               inode->i_mdev = dev;
1795                 inode->i_bdev = bdev;
1796                 inode->i_data.a_ops = &def_blk_aops;
1797                 mapping_set_gfp_mask(&inode->i_data, GFP_USER);
1798 @@ -599,6 +601,11 @@ EXPORT_SYMBOL(bdput);
1799  static struct block_device *bd_acquire(struct inode *inode)
1800  {
1801         struct block_device *bdev;
1802 +       dev_t mdev;
1803 +
1804 +       if (!vs_map_blkdev(inode->i_rdev, &mdev, DATTR_OPEN))
1805 +               return NULL;
1806 +       inode->i_mdev = mdev;
1807  
1808         spin_lock(&bdev_lock);
1809         bdev = inode->i_bdev;
1810 @@ -609,7 +616,7 @@ static struct block_device *bd_acquire(s
1811         }
1812         spin_unlock(&bdev_lock);
1813  
1814 -       bdev = bdget(inode->i_rdev);
1815 +       bdev = bdget(mdev);
1816         if (bdev) {
1817                 spin_lock(&bdev_lock);
1818                 if (!inode->i_bdev) {
1819 diff -NurpP --minimal linux-3.0.25/fs/btrfs/ctree.h linux-3.0.25-vs2.3.2.3/fs/btrfs/ctree.h
1820 --- linux-3.0.25/fs/btrfs/ctree.h       2011-07-22 11:18:05.000000000 +0200
1821 +++ linux-3.0.25-vs2.3.2.3/fs/btrfs/ctree.h     2011-07-19 00:44:39.000000000 +0200
1822 @@ -600,11 +600,14 @@ struct btrfs_inode_item {
1823         /* modification sequence number for NFS */
1824         __le64 sequence;
1825  
1826 +       __le16 tag;
1827         /*
1828          * a little future expansion, for more than this we can
1829          * just grow the inode item and version it
1830          */
1831 -       __le64 reserved[4];
1832 +       __le16 reserved16;
1833 +       __le32 reserved32;
1834 +       __le64 reserved[3];
1835         struct btrfs_timespec atime;
1836         struct btrfs_timespec ctime;
1837         struct btrfs_timespec mtime;
1838 @@ -1359,6 +1362,8 @@ struct btrfs_ioctl_defrag_range_args {
1839  #define BTRFS_MOUNT_AUTO_DEFRAG                (1 << 16)
1840  #define BTRFS_MOUNT_INODE_MAP_CACHE    (1 << 17)
1841  
1842 +#define BTRFS_MOUNT_TAGGED             (1 << 24)
1843 +
1844  #define btrfs_clear_opt(o, opt)                ((o) &= ~BTRFS_MOUNT_##opt)
1845  #define btrfs_set_opt(o, opt)          ((o) |= BTRFS_MOUNT_##opt)
1846  #define btrfs_test_opt(root, opt)      ((root)->fs_info->mount_opt & \
1847 @@ -1568,6 +1573,7 @@ BTRFS_SETGET_FUNCS(inode_block_group, st
1848  BTRFS_SETGET_FUNCS(inode_nlink, struct btrfs_inode_item, nlink, 32);
1849  BTRFS_SETGET_FUNCS(inode_uid, struct btrfs_inode_item, uid, 32);
1850  BTRFS_SETGET_FUNCS(inode_gid, struct btrfs_inode_item, gid, 32);
1851 +BTRFS_SETGET_FUNCS(inode_tag, struct btrfs_inode_item, tag, 16);
1852  BTRFS_SETGET_FUNCS(inode_mode, struct btrfs_inode_item, mode, 32);
1853  BTRFS_SETGET_FUNCS(inode_rdev, struct btrfs_inode_item, rdev, 64);
1854  BTRFS_SETGET_FUNCS(inode_flags, struct btrfs_inode_item, flags, 64);
1855 @@ -1621,6 +1627,10 @@ BTRFS_SETGET_FUNCS(extent_flags, struct 
1856  
1857  BTRFS_SETGET_FUNCS(extent_refs_v0, struct btrfs_extent_item_v0, refs, 32);
1858  
1859 +#define BTRFS_INODE_IXUNLINK           (1 << 24)
1860 +#define BTRFS_INODE_BARRIER            (1 << 25)
1861 +#define BTRFS_INODE_COW                        (1 << 26)
1862 +
1863  
1864  BTRFS_SETGET_FUNCS(tree_block_level, struct btrfs_tree_block_info, level, 8);
1865  
1866 @@ -2595,6 +2605,7 @@ extern const struct dentry_operations bt
1867  long btrfs_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
1868  void btrfs_update_iflags(struct inode *inode);
1869  void btrfs_inherit_iflags(struct inode *inode, struct inode *dir);
1870 +int btrfs_sync_flags(struct inode *inode, int, int);
1871  int btrfs_defrag_file(struct inode *inode, struct file *file,
1872                       struct btrfs_ioctl_defrag_range_args *range,
1873                       u64 newer_than, unsigned long max_pages);
1874 diff -NurpP --minimal linux-3.0.25/fs/btrfs/disk-io.c linux-3.0.25-vs2.3.2.3/fs/btrfs/disk-io.c
1875 --- linux-3.0.25/fs/btrfs/disk-io.c     2011-07-22 11:18:05.000000000 +0200
1876 +++ linux-3.0.25-vs2.3.2.3/fs/btrfs/disk-io.c   2011-06-22 12:39:15.000000000 +0200
1877 @@ -1765,6 +1765,9 @@ struct btrfs_root *open_ctree(struct sup
1878                 goto fail_alloc;
1879         }
1880  
1881 +       if (btrfs_test_opt(tree_root, TAGGED))
1882 +               sb->s_flags |= MS_TAGGED;
1883 +
1884         features = btrfs_super_incompat_flags(disk_super) &
1885                 ~BTRFS_FEATURE_INCOMPAT_SUPP;
1886         if (features) {
1887 diff -NurpP --minimal linux-3.0.25/fs/btrfs/inode.c linux-3.0.25-vs2.3.2.3/fs/btrfs/inode.c
1888 --- linux-3.0.25/fs/btrfs/inode.c       2012-03-19 21:16:51.000000000 +0100
1889 +++ linux-3.0.25-vs2.3.2.3/fs/btrfs/inode.c     2011-10-18 13:51:13.000000000 +0200
1890 @@ -38,6 +38,7 @@
1891  #include <linux/falloc.h>
1892  #include <linux/slab.h>
1893  #include <linux/ratelimit.h>
1894 +#include <linux/vs_tag.h>
1895  #include "compat.h"
1896  #include "ctree.h"
1897  #include "disk-io.h"
1898 @@ -2508,6 +2509,8 @@ static void btrfs_read_locked_inode(stru
1899         struct btrfs_key location;
1900         int maybe_acls;
1901         u32 rdev;
1902 +       uid_t uid;
1903 +       gid_t gid;
1904         int ret;
1905         bool filled = false;
1906  
1907 @@ -2540,8 +2543,13 @@ static void btrfs_read_locked_inode(stru
1908  
1909         inode->i_mode = btrfs_inode_mode(leaf, inode_item);
1910         inode->i_nlink = btrfs_inode_nlink(leaf, inode_item);
1911 -       inode->i_uid = btrfs_inode_uid(leaf, inode_item);
1912 -       inode->i_gid = btrfs_inode_gid(leaf, inode_item);
1913 +
1914 +       uid = btrfs_inode_uid(leaf, inode_item);
1915 +       gid = btrfs_inode_gid(leaf, inode_item);
1916 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
1917 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
1918 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid,
1919 +               btrfs_inode_tag(leaf, inode_item));
1920         btrfs_i_size_write(inode, btrfs_inode_size(leaf, inode_item));
1921  
1922         tspec = btrfs_inode_atime(inode_item);
1923 @@ -2624,6 +2632,9 @@ static void fill_inode_item(struct btrfs
1924                             struct btrfs_inode_item *item,
1925                             struct inode *inode)
1926  {
1927 +       uid_t uid = TAGINO_UID(DX_TAG(inode), inode->i_uid, inode->i_tag);
1928 +       gid_t gid = TAGINO_GID(DX_TAG(inode), inode->i_gid, inode->i_tag);
1929 +
1930         if (!leaf->map_token)
1931                 map_private_extent_buffer(leaf, (unsigned long)item,
1932                                           sizeof(struct btrfs_inode_item),
1933 @@ -2631,8 +2642,11 @@ static void fill_inode_item(struct btrfs
1934                                           &leaf->map_start, &leaf->map_len,
1935                                           KM_USER1);
1936  
1937 -       btrfs_set_inode_uid(leaf, item, inode->i_uid);
1938 -       btrfs_set_inode_gid(leaf, item, inode->i_gid);
1939 +       btrfs_set_inode_uid(leaf, item, uid);
1940 +       btrfs_set_inode_gid(leaf, item, gid);
1941 +#ifdef CONFIG_TAGGING_INTERN
1942 +       btrfs_set_inode_tag(leaf, item, inode->i_tag);
1943 +#endif
1944         btrfs_set_inode_size(leaf, item, BTRFS_I(inode)->disk_i_size);
1945         btrfs_set_inode_mode(leaf, item, inode->i_mode);
1946         btrfs_set_inode_nlink(leaf, item, inode->i_nlink);
1947 @@ -7360,6 +7374,7 @@ static const struct inode_operations btr
1948         .listxattr      = btrfs_listxattr,
1949         .removexattr    = btrfs_removexattr,
1950         .permission     = btrfs_permission,
1951 +       .sync_flags     = btrfs_sync_flags,
1952  };
1953  static const struct inode_operations btrfs_dir_ro_inode_operations = {
1954         .lookup         = btrfs_lookup,
1955 @@ -7432,6 +7447,7 @@ static const struct inode_operations btr
1956         .removexattr    = btrfs_removexattr,
1957         .permission     = btrfs_permission,
1958         .fiemap         = btrfs_fiemap,
1959 +       .sync_flags     = btrfs_sync_flags,
1960  };
1961  static const struct inode_operations btrfs_special_inode_operations = {
1962         .getattr        = btrfs_getattr,
1963 diff -NurpP --minimal linux-3.0.25/fs/btrfs/ioctl.c linux-3.0.25-vs2.3.2.3/fs/btrfs/ioctl.c
1964 --- linux-3.0.25/fs/btrfs/ioctl.c       2011-07-22 11:18:05.000000000 +0200
1965 +++ linux-3.0.25-vs2.3.2.3/fs/btrfs/ioctl.c     2011-06-22 12:39:15.000000000 +0200
1966 @@ -70,10 +70,13 @@ static unsigned int btrfs_flags_to_ioctl
1967  {
1968         unsigned int iflags = 0;
1969  
1970 -       if (flags & BTRFS_INODE_SYNC)
1971 -               iflags |= FS_SYNC_FL;
1972         if (flags & BTRFS_INODE_IMMUTABLE)
1973                 iflags |= FS_IMMUTABLE_FL;
1974 +       if (flags & BTRFS_INODE_IXUNLINK)
1975 +               iflags |= FS_IXUNLINK_FL;
1976 +
1977 +       if (flags & BTRFS_INODE_SYNC)
1978 +               iflags |= FS_SYNC_FL;
1979         if (flags & BTRFS_INODE_APPEND)
1980                 iflags |= FS_APPEND_FL;
1981         if (flags & BTRFS_INODE_NODUMP)
1982 @@ -90,28 +93,78 @@ static unsigned int btrfs_flags_to_ioctl
1983         else if (flags & BTRFS_INODE_NOCOMPRESS)
1984                 iflags |= FS_NOCOMP_FL;
1985  
1986 +       if (flags & BTRFS_INODE_BARRIER)
1987 +               iflags |= FS_BARRIER_FL;
1988 +       if (flags & BTRFS_INODE_COW)
1989 +               iflags |= FS_COW_FL;
1990         return iflags;
1991  }
1992  
1993  /*
1994 - * Update inode->i_flags based on the btrfs internal flags.
1995 + * Update inode->i_(v)flags based on the btrfs internal flags.
1996   */
1997  void btrfs_update_iflags(struct inode *inode)
1998  {
1999         struct btrfs_inode *ip = BTRFS_I(inode);
2000  
2001 -       inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
2002 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
2003 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
2004  
2005 -       if (ip->flags & BTRFS_INODE_SYNC)
2006 -               inode->i_flags |= S_SYNC;
2007         if (ip->flags & BTRFS_INODE_IMMUTABLE)
2008                 inode->i_flags |= S_IMMUTABLE;
2009 +       if (ip->flags & BTRFS_INODE_IXUNLINK)
2010 +               inode->i_flags |= S_IXUNLINK;
2011 +
2012 +       if (ip->flags & BTRFS_INODE_SYNC)
2013 +               inode->i_flags |= S_SYNC;
2014         if (ip->flags & BTRFS_INODE_APPEND)
2015                 inode->i_flags |= S_APPEND;
2016         if (ip->flags & BTRFS_INODE_NOATIME)
2017                 inode->i_flags |= S_NOATIME;
2018         if (ip->flags & BTRFS_INODE_DIRSYNC)
2019                 inode->i_flags |= S_DIRSYNC;
2020 +
2021 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
2022 +
2023 +       if (ip->flags & BTRFS_INODE_BARRIER)
2024 +               inode->i_vflags |= V_BARRIER;
2025 +       if (ip->flags & BTRFS_INODE_COW)
2026 +               inode->i_vflags |= V_COW;
2027 +}
2028 +
2029 +/*
2030 + * Update btrfs internal flags from inode->i_(v)flags.
2031 + */
2032 +void btrfs_update_flags(struct inode *inode)
2033 +{
2034 +       struct btrfs_inode *ip = BTRFS_I(inode);
2035 +
2036 +       unsigned int flags = inode->i_flags;
2037 +       unsigned int vflags = inode->i_vflags;
2038 +
2039 +       ip->flags &= ~(BTRFS_INODE_SYNC | BTRFS_INODE_APPEND |
2040 +                       BTRFS_INODE_IMMUTABLE | BTRFS_INODE_IXUNLINK |
2041 +                       BTRFS_INODE_NOATIME | BTRFS_INODE_DIRSYNC |
2042 +                       BTRFS_INODE_BARRIER | BTRFS_INODE_COW);
2043 +
2044 +       if (flags & S_IMMUTABLE)
2045 +               ip->flags |= BTRFS_INODE_IMMUTABLE;
2046 +       if (flags & S_IXUNLINK)
2047 +               ip->flags |= BTRFS_INODE_IXUNLINK;
2048 +
2049 +       if (flags & S_SYNC)
2050 +               ip->flags |= BTRFS_INODE_SYNC;
2051 +       if (flags & S_APPEND)
2052 +               ip->flags |= BTRFS_INODE_APPEND;
2053 +       if (flags & S_NOATIME)
2054 +               ip->flags |= BTRFS_INODE_NOATIME;
2055 +       if (flags & S_DIRSYNC)
2056 +               ip->flags |= BTRFS_INODE_DIRSYNC;
2057 +
2058 +       if (vflags & V_BARRIER)
2059 +               ip->flags |= BTRFS_INODE_BARRIER;
2060 +       if (vflags & V_COW)
2061 +               ip->flags |= BTRFS_INODE_COW;
2062  }
2063  
2064  /*
2065 @@ -129,7 +182,7 @@ void btrfs_inherit_iflags(struct inode *
2066         flags = BTRFS_I(dir)->flags;
2067  
2068         if (S_ISREG(inode->i_mode))
2069 -               flags &= ~BTRFS_INODE_DIRSYNC;
2070 +               flags &= ~(BTRFS_INODE_DIRSYNC | BTRFS_INODE_BARRIER);
2071         else if (!S_ISDIR(inode->i_mode))
2072                 flags &= (BTRFS_INODE_NODUMP | BTRFS_INODE_NOATIME);
2073  
2074 @@ -137,6 +190,30 @@ void btrfs_inherit_iflags(struct inode *
2075         btrfs_update_iflags(inode);
2076  }
2077  
2078 +int btrfs_sync_flags(struct inode *inode, int flags, int vflags)
2079 +{
2080 +       struct btrfs_inode *ip = BTRFS_I(inode);
2081 +       struct btrfs_root *root = ip->root;
2082 +       struct btrfs_trans_handle *trans;
2083 +       int ret;
2084 +
2085 +       trans = btrfs_join_transaction(root);
2086 +       BUG_ON(!trans);
2087 +
2088 +       inode->i_flags = flags;
2089 +       inode->i_vflags = vflags;
2090 +       btrfs_update_flags(inode);
2091 +
2092 +       ret = btrfs_update_inode(trans, root, inode);
2093 +       BUG_ON(ret);
2094 +
2095 +       btrfs_update_iflags(inode);
2096 +       inode->i_ctime = CURRENT_TIME;
2097 +       btrfs_end_transaction(trans, root);
2098 +
2099 +       return 0;
2100 +}
2101 +
2102  static int btrfs_ioctl_getflags(struct file *file, void __user *arg)
2103  {
2104         struct btrfs_inode *ip = BTRFS_I(file->f_path.dentry->d_inode);
2105 @@ -188,7 +265,8 @@ static int btrfs_ioctl_setflags(struct f
2106  
2107         flags = btrfs_mask_flags(inode->i_mode, flags);
2108         oldflags = btrfs_flags_to_ioctl(ip->flags);
2109 -       if ((flags ^ oldflags) & (FS_APPEND_FL | FS_IMMUTABLE_FL)) {
2110 +       if ((flags ^ oldflags) & (FS_APPEND_FL |
2111 +               FS_IMMUTABLE_FL | FS_IXUNLINK_FL)) {
2112                 if (!capable(CAP_LINUX_IMMUTABLE)) {
2113                         ret = -EPERM;
2114                         goto out_unlock;
2115 @@ -199,14 +277,19 @@ static int btrfs_ioctl_setflags(struct f
2116         if (ret)
2117                 goto out_unlock;
2118  
2119 -       if (flags & FS_SYNC_FL)
2120 -               ip->flags |= BTRFS_INODE_SYNC;
2121 -       else
2122 -               ip->flags &= ~BTRFS_INODE_SYNC;
2123         if (flags & FS_IMMUTABLE_FL)
2124                 ip->flags |= BTRFS_INODE_IMMUTABLE;
2125         else
2126                 ip->flags &= ~BTRFS_INODE_IMMUTABLE;
2127 +       if (flags & FS_IXUNLINK_FL)
2128 +               ip->flags |= BTRFS_INODE_IXUNLINK;
2129 +       else
2130 +               ip->flags &= ~BTRFS_INODE_IXUNLINK;
2131 +
2132 +       if (flags & FS_SYNC_FL)
2133 +               ip->flags |= BTRFS_INODE_SYNC;
2134 +       else
2135 +               ip->flags &= ~BTRFS_INODE_SYNC;
2136         if (flags & FS_APPEND_FL)
2137                 ip->flags |= BTRFS_INODE_APPEND;
2138         else
2139 diff -NurpP --minimal linux-3.0.25/fs/btrfs/super.c linux-3.0.25-vs2.3.2.3/fs/btrfs/super.c
2140 --- linux-3.0.25/fs/btrfs/super.c       2011-07-22 11:18:05.000000000 +0200
2141 +++ linux-3.0.25-vs2.3.2.3/fs/btrfs/super.c     2011-07-19 00:44:39.000000000 +0200
2142 @@ -162,7 +162,7 @@ enum {
2143         Opt_notreelog, Opt_ratio, Opt_flushoncommit, Opt_discard,
2144         Opt_space_cache, Opt_clear_cache, Opt_user_subvol_rm_allowed,
2145         Opt_enospc_debug, Opt_subvolrootid, Opt_defrag,
2146 -       Opt_inode_cache, Opt_err,
2147 +       Opt_inode_cache, Opt_tag, Opt_notag, Opt_tagid, Opt_err,
2148  };
2149  
2150  static match_table_t tokens = {
2151 @@ -195,6 +195,9 @@ static match_table_t tokens = {
2152         {Opt_subvolrootid, "subvolrootid=%d"},
2153         {Opt_defrag, "autodefrag"},
2154         {Opt_inode_cache, "inode_cache"},
2155 +       {Opt_tag, "tag"},
2156 +       {Opt_notag, "notag"},
2157 +       {Opt_tagid, "tagid=%u"},
2158         {Opt_err, NULL},
2159  };
2160  
2161 @@ -381,6 +384,22 @@ int btrfs_parse_options(struct btrfs_roo
2162                         printk(KERN_INFO "btrfs: enabling auto defrag");
2163                         btrfs_set_opt(info->mount_opt, AUTO_DEFRAG);
2164                         break;
2165 +#ifndef CONFIG_TAGGING_NONE
2166 +               case Opt_tag:
2167 +                       printk(KERN_INFO "btrfs: use tagging\n");
2168 +                       btrfs_set_opt(info->mount_opt, TAGGED);
2169 +                       break;
2170 +               case Opt_notag:
2171 +                       printk(KERN_INFO "btrfs: disabled tagging\n");
2172 +                       btrfs_clear_opt(info->mount_opt, TAGGED);
2173 +                       break;
2174 +#endif
2175 +#ifdef CONFIG_PROPAGATE
2176 +               case Opt_tagid:
2177 +                       /* use args[0] */
2178 +                       btrfs_set_opt(info->mount_opt, TAGGED);
2179 +                       break;
2180 +#endif
2181                 case Opt_err:
2182                         printk(KERN_INFO "btrfs: unrecognized mount option "
2183                                "'%s'\n", p);
2184 @@ -907,6 +926,12 @@ static int btrfs_remount(struct super_bl
2185         if (ret)
2186                 return -EINVAL;
2187  
2188 +       if (btrfs_test_opt(root, TAGGED) && !(sb->s_flags & MS_TAGGED)) {
2189 +               printk("btrfs: %s: tagging not permitted on remount.\n",
2190 +                       sb->s_id);
2191 +               return -EINVAL;
2192 +       }
2193 +
2194         if ((*flags & MS_RDONLY) == (sb->s_flags & MS_RDONLY))
2195                 return 0;
2196  
2197 diff -NurpP --minimal linux-3.0.25/fs/char_dev.c linux-3.0.25-vs2.3.2.3/fs/char_dev.c
2198 --- linux-3.0.25/fs/char_dev.c  2011-03-15 18:07:31.000000000 +0100
2199 +++ linux-3.0.25-vs2.3.2.3/fs/char_dev.c        2011-06-10 22:11:24.000000000 +0200
2200 @@ -21,6 +21,8 @@
2201  #include <linux/mutex.h>
2202  #include <linux/backing-dev.h>
2203  #include <linux/tty.h>
2204 +#include <linux/vs_context.h>
2205 +#include <linux/vs_device.h>
2206  
2207  #include "internal.h"
2208  
2209 @@ -371,14 +373,21 @@ static int chrdev_open(struct inode *ino
2210         struct cdev *p;
2211         struct cdev *new = NULL;
2212         int ret = 0;
2213 +       dev_t mdev;
2214 +
2215 +       if (!vs_map_chrdev(inode->i_rdev, &mdev, DATTR_OPEN))
2216 +               return -EPERM;
2217 +       inode->i_mdev = mdev;
2218  
2219         spin_lock(&cdev_lock);
2220         p = inode->i_cdev;
2221         if (!p) {
2222                 struct kobject *kobj;
2223                 int idx;
2224 +
2225                 spin_unlock(&cdev_lock);
2226 -               kobj = kobj_lookup(cdev_map, inode->i_rdev, &idx);
2227 +
2228 +               kobj = kobj_lookup(cdev_map, mdev, &idx);
2229                 if (!kobj)
2230                         return -ENXIO;
2231                 new = container_of(kobj, struct cdev, kobj);
2232 diff -NurpP --minimal linux-3.0.25/fs/dcache.c linux-3.0.25-vs2.3.2.3/fs/dcache.c
2233 --- linux-3.0.25/fs/dcache.c    2012-03-19 21:16:51.000000000 +0100
2234 +++ linux-3.0.25-vs2.3.2.3/fs/dcache.c  2012-01-26 08:39:53.000000000 +0100
2235 @@ -36,6 +36,7 @@
2236  #include <linux/bit_spinlock.h>
2237  #include <linux/rculist_bl.h>
2238  #include <linux/prefetch.h>
2239 +#include <linux/vs_limit.h>
2240  #include "internal.h"
2241  
2242  /*
2243 @@ -480,6 +481,8 @@ int d_invalidate(struct dentry * dentry)
2244                 spin_lock(&dentry->d_lock);
2245         }
2246  
2247 +       vx_dentry_dec(dentry);
2248 +
2249         /*
2250          * Somebody else still using it?
2251          *
2252 @@ -507,6 +510,7 @@ EXPORT_SYMBOL(d_invalidate);
2253  static inline void __dget_dlock(struct dentry *dentry)
2254  {
2255         dentry->d_count++;
2256 +       vx_dentry_inc(dentry);
2257  }
2258  
2259  static inline void __dget(struct dentry *dentry)
2260 @@ -1272,6 +1276,9 @@ struct dentry *d_alloc(struct dentry * p
2261         struct dentry *dentry;
2262         char *dname;
2263  
2264 +       if (!vx_dentry_avail(1))
2265 +               return NULL;
2266 +
2267         dentry = kmem_cache_alloc(dentry_cache, GFP_KERNEL);
2268         if (!dentry)
2269                 return NULL;
2270 @@ -1294,6 +1301,7 @@ struct dentry *d_alloc(struct dentry * p
2271  
2272         dentry->d_count = 1;
2273         dentry->d_flags = 0;
2274 +       vx_dentry_inc(dentry);
2275         spin_lock_init(&dentry->d_lock);
2276         seqcount_init(&dentry->d_seq);
2277         dentry->d_inode = NULL;
2278 @@ -1951,6 +1959,7 @@ struct dentry *__d_lookup(struct dentry 
2279                 }
2280  
2281                 dentry->d_count++;
2282 +               vx_dentry_inc(dentry);
2283                 found = dentry;
2284                 spin_unlock(&dentry->d_lock);
2285                 break;
2286 diff -NurpP --minimal linux-3.0.25/fs/devpts/inode.c linux-3.0.25-vs2.3.2.3/fs/devpts/inode.c
2287 --- linux-3.0.25/fs/devpts/inode.c      2011-05-22 16:17:50.000000000 +0200
2288 +++ linux-3.0.25-vs2.3.2.3/fs/devpts/inode.c    2011-06-10 22:11:24.000000000 +0200
2289 @@ -25,6 +25,7 @@
2290  #include <linux/parser.h>
2291  #include <linux/fsnotify.h>
2292  #include <linux/seq_file.h>
2293 +#include <linux/vs_base.h>
2294  
2295  #define DEVPTS_DEFAULT_MODE 0600
2296  /*
2297 @@ -36,6 +37,20 @@
2298  #define DEVPTS_DEFAULT_PTMX_MODE 0000
2299  #define PTMX_MINOR     2
2300  
2301 +static int devpts_permission(struct inode *inode, int mask, unsigned int flags)
2302 +{
2303 +       int ret = -EACCES;
2304 +
2305 +       /* devpts is xid tagged */
2306 +       if (vx_check((xid_t)inode->i_tag, VS_WATCH_P | VS_IDENT))
2307 +               ret = generic_permission(inode, mask, flags, NULL);
2308 +       return ret;
2309 +}
2310 +
2311 +static struct inode_operations devpts_file_inode_operations = {
2312 +       .permission     = devpts_permission,
2313 +};
2314 +
2315  extern int pty_limit;                  /* Config limit on Unix98 ptys */
2316  static DEFINE_MUTEX(allocated_ptys_lock);
2317  
2318 @@ -263,6 +278,34 @@ static int devpts_show_options(struct se
2319         return 0;
2320  }
2321  
2322 +static int devpts_filter(struct dentry *de)
2323 +{
2324 +       xid_t xid = 0;
2325 +
2326 +       /* devpts is xid tagged */
2327 +       if (de && de->d_inode)
2328 +               xid = (xid_t)de->d_inode->i_tag;
2329 +#ifdef CONFIG_VSERVER_WARN_DEVPTS
2330 +       else
2331 +               vxwprintk_task(1, "devpts " VS_Q("%.*s") " without inode.",
2332 +                       de->d_name.len, de->d_name.name);
2333 +#endif
2334 +       return vx_check(xid, VS_WATCH_P | VS_IDENT);
2335 +}
2336 +
2337 +static int devpts_readdir(struct file * filp, void * dirent, filldir_t filldir)
2338 +{
2339 +       return dcache_readdir_filter(filp, dirent, filldir, devpts_filter);
2340 +}
2341 +
2342 +static struct file_operations devpts_dir_operations = {
2343 +       .open           = dcache_dir_open,
2344 +       .release        = dcache_dir_close,
2345 +       .llseek         = dcache_dir_lseek,
2346 +       .read           = generic_read_dir,
2347 +       .readdir        = devpts_readdir,
2348 +};
2349 +
2350  static const struct super_operations devpts_sops = {
2351         .statfs         = simple_statfs,
2352         .remount_fs     = devpts_remount,
2353 @@ -302,12 +345,15 @@ devpts_fill_super(struct super_block *s,
2354         inode = new_inode(s);
2355         if (!inode)
2356                 goto free_fsi;
2357 +
2358         inode->i_ino = 1;
2359         inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
2360         inode->i_mode = S_IFDIR | S_IRUGO | S_IXUGO | S_IWUSR;
2361         inode->i_op = &simple_dir_inode_operations;
2362 -       inode->i_fop = &simple_dir_operations;
2363 +       inode->i_fop = &devpts_dir_operations;
2364         inode->i_nlink = 2;
2365 +       /* devpts is xid tagged */
2366 +       inode->i_tag = (tag_t)vx_current_xid();
2367  
2368         s->s_root = d_alloc_root(inode);
2369         if (s->s_root)
2370 @@ -494,6 +540,9 @@ int devpts_pty_new(struct inode *ptmx_in
2371         inode->i_gid = opts->setgid ? opts->gid : current_fsgid();
2372         inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
2373         init_special_inode(inode, S_IFCHR|opts->mode, device);
2374 +       /* devpts is xid tagged */
2375 +       inode->i_tag = (tag_t)vx_current_xid();
2376 +       inode->i_op = &devpts_file_inode_operations;
2377         inode->i_private = tty;
2378         tty->driver_data = inode;
2379  
2380 diff -NurpP --minimal linux-3.0.25/fs/ext2/balloc.c linux-3.0.25-vs2.3.2.3/fs/ext2/balloc.c
2381 --- linux-3.0.25/fs/ext2/balloc.c       2011-05-22 16:17:51.000000000 +0200
2382 +++ linux-3.0.25-vs2.3.2.3/fs/ext2/balloc.c     2011-06-10 22:11:24.000000000 +0200
2383 @@ -701,7 +701,6 @@ ext2_try_to_allocate(struct super_block 
2384                         start = 0;
2385                 end = EXT2_BLOCKS_PER_GROUP(sb);
2386         }
2387 -
2388         BUG_ON(start > EXT2_BLOCKS_PER_GROUP(sb));
2389  
2390  repeat:
2391 diff -NurpP --minimal linux-3.0.25/fs/ext2/ext2.h linux-3.0.25-vs2.3.2.3/fs/ext2/ext2.h
2392 --- linux-3.0.25/fs/ext2/ext2.h 2011-05-22 16:17:51.000000000 +0200
2393 +++ linux-3.0.25-vs2.3.2.3/fs/ext2/ext2.h       2011-06-10 22:11:24.000000000 +0200
2394 @@ -126,6 +126,7 @@ extern void ext2_set_inode_flags(struct 
2395  extern void ext2_get_inode_flags(struct ext2_inode_info *);
2396  extern int ext2_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
2397                        u64 start, u64 len);
2398 +extern int ext2_sync_flags(struct inode *, int, int);
2399  
2400  /* ioctl.c */
2401  extern long ext2_ioctl(struct file *, unsigned int, unsigned long);
2402 diff -NurpP --minimal linux-3.0.25/fs/ext2/file.c linux-3.0.25-vs2.3.2.3/fs/ext2/file.c
2403 --- linux-3.0.25/fs/ext2/file.c 2010-08-02 16:52:48.000000000 +0200
2404 +++ linux-3.0.25-vs2.3.2.3/fs/ext2/file.c       2011-06-10 22:11:24.000000000 +0200
2405 @@ -104,4 +104,5 @@ const struct inode_operations ext2_file_
2406         .setattr        = ext2_setattr,
2407         .check_acl      = ext2_check_acl,
2408         .fiemap         = ext2_fiemap,
2409 +       .sync_flags     = ext2_sync_flags,
2410  };
2411 diff -NurpP --minimal linux-3.0.25/fs/ext2/ialloc.c linux-3.0.25-vs2.3.2.3/fs/ext2/ialloc.c
2412 --- linux-3.0.25/fs/ext2/ialloc.c       2011-05-22 16:17:51.000000000 +0200
2413 +++ linux-3.0.25-vs2.3.2.3/fs/ext2/ialloc.c     2011-06-10 22:11:24.000000000 +0200
2414 @@ -17,6 +17,7 @@
2415  #include <linux/backing-dev.h>
2416  #include <linux/buffer_head.h>
2417  #include <linux/random.h>
2418 +#include <linux/vs_tag.h>
2419  #include "ext2.h"
2420  #include "xattr.h"
2421  #include "acl.h"
2422 @@ -549,6 +550,7 @@ got:
2423                 inode->i_mode = mode;
2424                 inode->i_uid = current_fsuid();
2425                 inode->i_gid = dir->i_gid;
2426 +               inode->i_tag = dx_current_fstag(sb);
2427         } else
2428                 inode_init_owner(inode, dir, mode);
2429  
2430 diff -NurpP --minimal linux-3.0.25/fs/ext2/inode.c linux-3.0.25-vs2.3.2.3/fs/ext2/inode.c
2431 --- linux-3.0.25/fs/ext2/inode.c        2011-05-22 16:17:51.000000000 +0200
2432 +++ linux-3.0.25-vs2.3.2.3/fs/ext2/inode.c      2011-06-10 22:11:24.000000000 +0200
2433 @@ -32,6 +32,7 @@
2434  #include <linux/mpage.h>
2435  #include <linux/fiemap.h>
2436  #include <linux/namei.h>
2437 +#include <linux/vs_tag.h>
2438  #include "ext2.h"
2439  #include "acl.h"
2440  #include "xip.h"
2441 @@ -1167,7 +1168,7 @@ static void ext2_truncate_blocks(struct 
2442                 return;
2443         if (ext2_inode_is_fast_symlink(inode))
2444                 return;
2445 -       if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
2446 +       if (IS_APPEND(inode) || IS_IXORUNLINK(inode))
2447                 return;
2448         __ext2_truncate_blocks(inode, offset);
2449  }
2450 @@ -1256,36 +1257,61 @@ void ext2_set_inode_flags(struct inode *
2451  {
2452         unsigned int flags = EXT2_I(inode)->i_flags;
2453  
2454 -       inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
2455 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
2456 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
2457 +
2458 +
2459 +       if (flags & EXT2_IMMUTABLE_FL)
2460 +               inode->i_flags |= S_IMMUTABLE;
2461 +       if (flags & EXT2_IXUNLINK_FL)
2462 +               inode->i_flags |= S_IXUNLINK;
2463 +
2464         if (flags & EXT2_SYNC_FL)
2465                 inode->i_flags |= S_SYNC;
2466         if (flags & EXT2_APPEND_FL)
2467                 inode->i_flags |= S_APPEND;
2468 -       if (flags & EXT2_IMMUTABLE_FL)
2469 -               inode->i_flags |= S_IMMUTABLE;
2470         if (flags & EXT2_NOATIME_FL)
2471                 inode->i_flags |= S_NOATIME;
2472         if (flags & EXT2_DIRSYNC_FL)
2473                 inode->i_flags |= S_DIRSYNC;
2474 +
2475 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
2476 +
2477 +       if (flags & EXT2_BARRIER_FL)
2478 +               inode->i_vflags |= V_BARRIER;
2479 +       if (flags & EXT2_COW_FL)
2480 +               inode->i_vflags |= V_COW;
2481  }
2482  
2483  /* Propagate flags from i_flags to EXT2_I(inode)->i_flags */
2484  void ext2_get_inode_flags(struct ext2_inode_info *ei)
2485  {
2486         unsigned int flags = ei->vfs_inode.i_flags;
2487 +       unsigned int vflags = ei->vfs_inode.i_vflags;
2488 +
2489 +       ei->i_flags &= ~(EXT2_SYNC_FL | EXT2_APPEND_FL |
2490 +                       EXT2_IMMUTABLE_FL | EXT2_IXUNLINK_FL |
2491 +                       EXT2_NOATIME_FL | EXT2_DIRSYNC_FL |
2492 +                       EXT2_BARRIER_FL | EXT2_COW_FL);
2493 +
2494 +       if (flags & S_IMMUTABLE)
2495 +               ei->i_flags |= EXT2_IMMUTABLE_FL;
2496 +       if (flags & S_IXUNLINK)
2497 +               ei->i_flags |= EXT2_IXUNLINK_FL;
2498  
2499 -       ei->i_flags &= ~(EXT2_SYNC_FL|EXT2_APPEND_FL|
2500 -                       EXT2_IMMUTABLE_FL|EXT2_NOATIME_FL|EXT2_DIRSYNC_FL);
2501         if (flags & S_SYNC)
2502                 ei->i_flags |= EXT2_SYNC_FL;
2503         if (flags & S_APPEND)
2504                 ei->i_flags |= EXT2_APPEND_FL;
2505 -       if (flags & S_IMMUTABLE)
2506 -               ei->i_flags |= EXT2_IMMUTABLE_FL;
2507         if (flags & S_NOATIME)
2508                 ei->i_flags |= EXT2_NOATIME_FL;
2509         if (flags & S_DIRSYNC)
2510                 ei->i_flags |= EXT2_DIRSYNC_FL;
2511 +
2512 +       if (vflags & V_BARRIER)
2513 +               ei->i_flags |= EXT2_BARRIER_FL;
2514 +       if (vflags & V_COW)
2515 +               ei->i_flags |= EXT2_COW_FL;
2516  }
2517  
2518  struct inode *ext2_iget (struct super_block *sb, unsigned long ino)
2519 @@ -1295,6 +1321,8 @@ struct inode *ext2_iget (struct super_bl
2520         struct ext2_inode *raw_inode;
2521         struct inode *inode;
2522         long ret = -EIO;
2523 +       uid_t uid;
2524 +       gid_t gid;
2525         int n;
2526  
2527         inode = iget_locked(sb, ino);
2528 @@ -1313,12 +1341,17 @@ struct inode *ext2_iget (struct super_bl
2529         }
2530  
2531         inode->i_mode = le16_to_cpu(raw_inode->i_mode);
2532 -       inode->i_uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
2533 -       inode->i_gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
2534 +       uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
2535 +       gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
2536         if (!(test_opt (inode->i_sb, NO_UID32))) {
2537 -               inode->i_uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
2538 -               inode->i_gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
2539 +               uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
2540 +               gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
2541         }
2542 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
2543 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
2544 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid,
2545 +               le16_to_cpu(raw_inode->i_raw_tag));
2546 +
2547         inode->i_nlink = le16_to_cpu(raw_inode->i_links_count);
2548         inode->i_size = le32_to_cpu(raw_inode->i_size);
2549         inode->i_atime.tv_sec = (signed)le32_to_cpu(raw_inode->i_atime);
2550 @@ -1416,8 +1449,8 @@ static int __ext2_write_inode(struct ino
2551         struct ext2_inode_info *ei = EXT2_I(inode);
2552         struct super_block *sb = inode->i_sb;
2553         ino_t ino = inode->i_ino;
2554 -       uid_t uid = inode->i_uid;
2555 -       gid_t gid = inode->i_gid;
2556 +       uid_t uid = TAGINO_UID(DX_TAG(inode), inode->i_uid, inode->i_tag);
2557 +       gid_t gid = TAGINO_GID(DX_TAG(inode), inode->i_gid, inode->i_tag);
2558         struct buffer_head * bh;
2559         struct ext2_inode * raw_inode = ext2_get_inode(sb, ino, &bh);
2560         int n;
2561 @@ -1453,6 +1486,9 @@ static int __ext2_write_inode(struct ino
2562                 raw_inode->i_uid_high = 0;
2563                 raw_inode->i_gid_high = 0;
2564         }
2565 +#ifdef CONFIG_TAGGING_INTERN
2566 +       raw_inode->i_raw_tag = cpu_to_le16(inode->i_tag);
2567 +#endif
2568         raw_inode->i_links_count = cpu_to_le16(inode->i_nlink);
2569         raw_inode->i_size = cpu_to_le32(inode->i_size);
2570         raw_inode->i_atime = cpu_to_le32(inode->i_atime.tv_sec);
2571 @@ -1533,7 +1569,8 @@ int ext2_setattr(struct dentry *dentry, 
2572         if (is_quota_modification(inode, iattr))
2573                 dquot_initialize(inode);
2574         if ((iattr->ia_valid & ATTR_UID && iattr->ia_uid != inode->i_uid) ||
2575 -           (iattr->ia_valid & ATTR_GID && iattr->ia_gid != inode->i_gid)) {
2576 +           (iattr->ia_valid & ATTR_GID && iattr->ia_gid != inode->i_gid) ||
2577 +           (iattr->ia_valid & ATTR_TAG && iattr->ia_tag != inode->i_tag)) {
2578                 error = dquot_transfer(inode, iattr);
2579                 if (error)
2580                         return error;
2581 diff -NurpP --minimal linux-3.0.25/fs/ext2/ioctl.c linux-3.0.25-vs2.3.2.3/fs/ext2/ioctl.c
2582 --- linux-3.0.25/fs/ext2/ioctl.c        2011-05-22 16:17:51.000000000 +0200
2583 +++ linux-3.0.25-vs2.3.2.3/fs/ext2/ioctl.c      2011-06-10 22:11:24.000000000 +0200
2584 @@ -17,6 +17,16 @@
2585  #include <asm/uaccess.h>
2586  
2587  
2588 +int ext2_sync_flags(struct inode *inode, int flags, int vflags)
2589 +{
2590 +       inode->i_flags = flags;
2591 +       inode->i_vflags = vflags;
2592 +       ext2_get_inode_flags(EXT2_I(inode));
2593 +       inode->i_ctime = CURRENT_TIME_SEC;
2594 +       mark_inode_dirty(inode);
2595 +       return 0;
2596 +}
2597 +
2598  long ext2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
2599  {
2600         struct inode *inode = filp->f_dentry->d_inode;
2601 @@ -51,6 +61,11 @@ long ext2_ioctl(struct file *filp, unsig
2602  
2603                 flags = ext2_mask_flags(inode->i_mode, flags);
2604  
2605 +               if (IS_BARRIER(inode)) {
2606 +                       vxwprintk_task(1, "messing with the barrier.");
2607 +                       return -EACCES;
2608 +               }
2609 +
2610                 mutex_lock(&inode->i_mutex);
2611                 /* Is it quota file? Do not allow user to mess with it */
2612                 if (IS_NOQUOTA(inode)) {
2613 @@ -66,7 +81,9 @@ long ext2_ioctl(struct file *filp, unsig
2614                  *
2615                  * This test looks nicer. Thanks to Pauline Middelink
2616                  */
2617 -               if ((flags ^ oldflags) & (EXT2_APPEND_FL | EXT2_IMMUTABLE_FL)) {
2618 +               if ((oldflags & EXT2_IMMUTABLE_FL) ||
2619 +                       ((flags ^ oldflags) & (EXT2_APPEND_FL |
2620 +                       EXT2_IMMUTABLE_FL | EXT2_IXUNLINK_FL))) {
2621                         if (!capable(CAP_LINUX_IMMUTABLE)) {
2622                                 mutex_unlock(&inode->i_mutex);
2623                                 ret = -EPERM;
2624 @@ -74,7 +91,7 @@ long ext2_ioctl(struct file *filp, unsig
2625                         }
2626                 }
2627  
2628 -               flags = flags & EXT2_FL_USER_MODIFIABLE;
2629 +               flags &= EXT2_FL_USER_MODIFIABLE;
2630                 flags |= oldflags & ~EXT2_FL_USER_MODIFIABLE;
2631                 ei->i_flags = flags;
2632                 mutex_unlock(&inode->i_mutex);
2633 diff -NurpP --minimal linux-3.0.25/fs/ext2/namei.c linux-3.0.25-vs2.3.2.3/fs/ext2/namei.c
2634 --- linux-3.0.25/fs/ext2/namei.c        2011-05-22 16:17:51.000000000 +0200
2635 +++ linux-3.0.25-vs2.3.2.3/fs/ext2/namei.c      2011-06-10 22:11:24.000000000 +0200
2636 @@ -32,6 +32,7 @@
2637  
2638  #include <linux/pagemap.h>
2639  #include <linux/quotaops.h>
2640 +#include <linux/vs_tag.h>
2641  #include "ext2.h"
2642  #include "xattr.h"
2643  #include "acl.h"
2644 @@ -75,6 +76,7 @@ static struct dentry *ext2_lookup(struct
2645                                 return ERR_PTR(-EIO);
2646                         } else {
2647                                 return ERR_CAST(inode);
2648 +               dx_propagate_tag(nd, inode);
2649                         }
2650                 }
2651         }
2652 @@ -413,6 +415,7 @@ const struct inode_operations ext2_dir_i
2653  #endif
2654         .setattr        = ext2_setattr,
2655         .check_acl      = ext2_check_acl,
2656 +       .sync_flags     = ext2_sync_flags,
2657  };
2658  
2659  const struct inode_operations ext2_special_inode_operations = {
2660 diff -NurpP --minimal linux-3.0.25/fs/ext2/super.c linux-3.0.25-vs2.3.2.3/fs/ext2/super.c
2661 --- linux-3.0.25/fs/ext2/super.c        2011-07-22 11:18:05.000000000 +0200
2662 +++ linux-3.0.25-vs2.3.2.3/fs/ext2/super.c      2011-06-10 22:11:24.000000000 +0200
2663 @@ -394,7 +394,8 @@ enum {
2664         Opt_err_ro, Opt_nouid32, Opt_nocheck, Opt_debug,
2665         Opt_oldalloc, Opt_orlov, Opt_nobh, Opt_user_xattr, Opt_nouser_xattr,
2666         Opt_acl, Opt_noacl, Opt_xip, Opt_ignore, Opt_err, Opt_quota,
2667 -       Opt_usrquota, Opt_grpquota, Opt_reservation, Opt_noreservation
2668 +       Opt_usrquota, Opt_grpquota, Opt_reservation, Opt_noreservation,
2669 +       Opt_tag, Opt_notag, Opt_tagid
2670  };
2671  
2672  static const match_table_t tokens = {
2673 @@ -422,6 +423,9 @@ static const match_table_t tokens = {
2674         {Opt_acl, "acl"},
2675         {Opt_noacl, "noacl"},
2676         {Opt_xip, "xip"},
2677 +       {Opt_tag, "tag"},
2678 +       {Opt_notag, "notag"},
2679 +       {Opt_tagid, "tagid=%u"},
2680         {Opt_grpquota, "grpquota"},
2681         {Opt_ignore, "noquota"},
2682         {Opt_quota, "quota"},
2683 @@ -492,6 +496,20 @@ static int parse_options(char *options, 
2684                 case Opt_nouid32:
2685                         set_opt (sbi->s_mount_opt, NO_UID32);
2686                         break;
2687 +#ifndef CONFIG_TAGGING_NONE
2688 +               case Opt_tag:
2689 +                       set_opt (sbi->s_mount_opt, TAGGED);
2690 +                       break;
2691 +               case Opt_notag:
2692 +                       clear_opt (sbi->s_mount_opt, TAGGED);
2693 +                       break;
2694 +#endif
2695 +#ifdef CONFIG_PROPAGATE
2696 +               case Opt_tagid:
2697 +                       /* use args[0] */
2698 +                       set_opt (sbi->s_mount_opt, TAGGED);
2699 +                       break;
2700 +#endif
2701                 case Opt_nocheck:
2702                         clear_opt (sbi->s_mount_opt, CHECK);
2703                         break;
2704 @@ -850,6 +868,8 @@ static int ext2_fill_super(struct super_
2705         if (!parse_options((char *) data, sb))
2706                 goto failed_mount;
2707  
2708 +       if (EXT2_SB(sb)->s_mount_opt & EXT2_MOUNT_TAGGED)
2709 +               sb->s_flags |= MS_TAGGED;
2710         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
2711                 ((EXT2_SB(sb)->s_mount_opt & EXT2_MOUNT_POSIX_ACL) ?
2712                  MS_POSIXACL : 0);
2713 @@ -1224,6 +1244,14 @@ static int ext2_remount (struct super_bl
2714                 goto restore_opts;
2715         }
2716  
2717 +       if ((sbi->s_mount_opt & EXT2_MOUNT_TAGGED) &&
2718 +               !(sb->s_flags & MS_TAGGED)) {
2719 +               printk("EXT2-fs: %s: tagging not permitted on remount.\n",
2720 +                      sb->s_id);
2721 +               err = -EINVAL;
2722 +               goto restore_opts;
2723 +       }
2724 +
2725         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
2726                 ((sbi->s_mount_opt & EXT2_MOUNT_POSIX_ACL) ? MS_POSIXACL : 0);
2727  
2728 diff -NurpP --minimal linux-3.0.25/fs/ext3/file.c linux-3.0.25-vs2.3.2.3/fs/ext3/file.c
2729 --- linux-3.0.25/fs/ext3/file.c 2010-07-07 18:31:51.000000000 +0200
2730 +++ linux-3.0.25-vs2.3.2.3/fs/ext3/file.c       2011-06-10 22:11:24.000000000 +0200
2731 @@ -81,5 +81,6 @@ const struct inode_operations ext3_file_
2732  #endif
2733         .check_acl      = ext3_check_acl,
2734         .fiemap         = ext3_fiemap,
2735 +       .sync_flags     = ext3_sync_flags,
2736  };
2737  
2738 diff -NurpP --minimal linux-3.0.25/fs/ext3/ialloc.c linux-3.0.25-vs2.3.2.3/fs/ext3/ialloc.c
2739 --- linux-3.0.25/fs/ext3/ialloc.c       2011-05-22 16:17:52.000000000 +0200
2740 +++ linux-3.0.25-vs2.3.2.3/fs/ext3/ialloc.c     2011-06-10 22:11:24.000000000 +0200
2741 @@ -23,6 +23,7 @@
2742  #include <linux/buffer_head.h>
2743  #include <linux/random.h>
2744  #include <linux/bitops.h>
2745 +#include <linux/vs_tag.h>
2746  
2747  #include <asm/byteorder.h>
2748  
2749 @@ -532,6 +533,7 @@ got:
2750                 inode->i_mode = mode;
2751                 inode->i_uid = current_fsuid();
2752                 inode->i_gid = dir->i_gid;
2753 +               inode->i_tag = dx_current_fstag(sb);
2754         } else
2755                 inode_init_owner(inode, dir, mode);
2756  
2757 diff -NurpP --minimal linux-3.0.25/fs/ext3/inode.c linux-3.0.25-vs2.3.2.3/fs/ext3/inode.c
2758 --- linux-3.0.25/fs/ext3/inode.c        2012-03-19 21:16:51.000000000 +0100
2759 +++ linux-3.0.25-vs2.3.2.3/fs/ext3/inode.c      2012-01-18 02:58:46.000000000 +0100
2760 @@ -38,6 +38,7 @@
2761  #include <linux/bio.h>
2762  #include <linux/fiemap.h>
2763  #include <linux/namei.h>
2764 +#include <linux/vs_tag.h>
2765  #include "xattr.h"
2766  #include "acl.h"
2767  
2768 @@ -2409,7 +2410,7 @@ static void ext3_free_branches(handle_t 
2769  
2770  int ext3_can_truncate(struct inode *inode)
2771  {
2772 -       if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
2773 +       if (IS_APPEND(inode) || IS_IXORUNLINK(inode))
2774                 return 0;
2775         if (S_ISREG(inode->i_mode))
2776                 return 1;
2777 @@ -2793,36 +2794,60 @@ void ext3_set_inode_flags(struct inode *
2778  {
2779         unsigned int flags = EXT3_I(inode)->i_flags;
2780  
2781 -       inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
2782 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
2783 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
2784 +
2785 +       if (flags & EXT3_IMMUTABLE_FL)
2786 +               inode->i_flags |= S_IMMUTABLE;
2787 +       if (flags & EXT3_IXUNLINK_FL)
2788 +               inode->i_flags |= S_IXUNLINK;
2789 +
2790         if (flags & EXT3_SYNC_FL)
2791                 inode->i_flags |= S_SYNC;
2792         if (flags & EXT3_APPEND_FL)
2793                 inode->i_flags |= S_APPEND;
2794 -       if (flags & EXT3_IMMUTABLE_FL)
2795 -               inode->i_flags |= S_IMMUTABLE;
2796         if (flags & EXT3_NOATIME_FL)
2797                 inode->i_flags |= S_NOATIME;
2798         if (flags & EXT3_DIRSYNC_FL)
2799                 inode->i_flags |= S_DIRSYNC;
2800 +
2801 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
2802 +
2803 +       if (flags & EXT3_BARRIER_FL)
2804 +               inode->i_vflags |= V_BARRIER;
2805 +       if (flags & EXT3_COW_FL)
2806 +               inode->i_vflags |= V_COW;
2807  }
2808  
2809  /* Propagate flags from i_flags to EXT3_I(inode)->i_flags */
2810  void ext3_get_inode_flags(struct ext3_inode_info *ei)
2811  {
2812         unsigned int flags = ei->vfs_inode.i_flags;
2813 +       unsigned int vflags = ei->vfs_inode.i_vflags;
2814 +
2815 +       ei->i_flags &= ~(EXT3_SYNC_FL | EXT3_APPEND_FL |
2816 +                       EXT3_IMMUTABLE_FL | EXT3_IXUNLINK_FL |
2817 +                       EXT3_NOATIME_FL | EXT3_DIRSYNC_FL |
2818 +                       EXT3_BARRIER_FL | EXT3_COW_FL);
2819 +
2820 +       if (flags & S_IMMUTABLE)
2821 +               ei->i_flags |= EXT3_IMMUTABLE_FL;
2822 +       if (flags & S_IXUNLINK)
2823 +               ei->i_flags |= EXT3_IXUNLINK_FL;
2824  
2825 -       ei->i_flags &= ~(EXT3_SYNC_FL|EXT3_APPEND_FL|
2826 -                       EXT3_IMMUTABLE_FL|EXT3_NOATIME_FL|EXT3_DIRSYNC_FL);
2827         if (flags & S_SYNC)
2828                 ei->i_flags |= EXT3_SYNC_FL;
2829         if (flags & S_APPEND)
2830                 ei->i_flags |= EXT3_APPEND_FL;
2831 -       if (flags & S_IMMUTABLE)
2832 -               ei->i_flags |= EXT3_IMMUTABLE_FL;
2833         if (flags & S_NOATIME)
2834                 ei->i_flags |= EXT3_NOATIME_FL;
2835         if (flags & S_DIRSYNC)
2836                 ei->i_flags |= EXT3_DIRSYNC_FL;
2837 +
2838 +       if (vflags & V_BARRIER)
2839 +               ei->i_flags |= EXT3_BARRIER_FL;
2840 +       if (vflags & V_COW)
2841 +               ei->i_flags |= EXT3_COW_FL;
2842  }
2843  
2844  struct inode *ext3_iget(struct super_block *sb, unsigned long ino)
2845 @@ -2836,6 +2861,8 @@ struct inode *ext3_iget(struct super_blo
2846         transaction_t *transaction;
2847         long ret;
2848         int block;
2849 +       uid_t uid;
2850 +       gid_t gid;
2851  
2852         inode = iget_locked(sb, ino);
2853         if (!inode)
2854 @@ -2852,12 +2879,17 @@ struct inode *ext3_iget(struct super_blo
2855         bh = iloc.bh;
2856         raw_inode = ext3_raw_inode(&iloc);
2857         inode->i_mode = le16_to_cpu(raw_inode->i_mode);
2858 -       inode->i_uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
2859 -       inode->i_gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
2860 +       uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
2861 +       gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
2862         if(!(test_opt (inode->i_sb, NO_UID32))) {
2863 -               inode->i_uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
2864 -               inode->i_gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
2865 +               uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
2866 +               gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
2867         }
2868 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
2869 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
2870 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid,
2871 +               le16_to_cpu(raw_inode->i_raw_tag));
2872 +
2873         inode->i_nlink = le16_to_cpu(raw_inode->i_links_count);
2874         inode->i_size = le32_to_cpu(raw_inode->i_size);
2875         inode->i_atime.tv_sec = (signed)le32_to_cpu(raw_inode->i_atime);
2876 @@ -3012,6 +3044,8 @@ static int ext3_do_update_inode(handle_t
2877         struct ext3_inode *raw_inode = ext3_raw_inode(iloc);
2878         struct ext3_inode_info *ei = EXT3_I(inode);
2879         struct buffer_head *bh = iloc->bh;
2880 +       uid_t uid = TAGINO_UID(DX_TAG(inode), inode->i_uid, inode->i_tag);
2881 +       gid_t gid = TAGINO_GID(DX_TAG(inode), inode->i_gid, inode->i_tag);
2882         int err = 0, rc, block;
2883  
2884  again:
2885 @@ -3026,29 +3060,32 @@ again:
2886         ext3_get_inode_flags(ei);
2887         raw_inode->i_mode = cpu_to_le16(inode->i_mode);
2888         if(!(test_opt(inode->i_sb, NO_UID32))) {
2889 -               raw_inode->i_uid_low = cpu_to_le16(low_16_bits(inode->i_uid));
2890 -               raw_inode->i_gid_low = cpu_to_le16(low_16_bits(inode->i_gid));
2891 +               raw_inode->i_uid_low = cpu_to_le16(low_16_bits(uid));
2892 +               raw_inode->i_gid_low = cpu_to_le16(low_16_bits(gid));
2893  /*
2894   * Fix up interoperability with old kernels. Otherwise, old inodes get
2895   * re-used with the upper 16 bits of the uid/gid intact
2896   */
2897                 if(!ei->i_dtime) {
2898                         raw_inode->i_uid_high =
2899 -                               cpu_to_le16(high_16_bits(inode->i_uid));
2900 +                               cpu_to_le16(high_16_bits(uid));
2901                         raw_inode->i_gid_high =
2902 -                               cpu_to_le16(high_16_bits(inode->i_gid));
2903 +                               cpu_to_le16(high_16_bits(gid));
2904                 } else {
2905                         raw_inode->i_uid_high = 0;
2906                         raw_inode->i_gid_high = 0;
2907                 }
2908         } else {
2909                 raw_inode->i_uid_low =
2910 -                       cpu_to_le16(fs_high2lowuid(inode->i_uid));
2911 +                       cpu_to_le16(fs_high2lowuid(uid));
2912                 raw_inode->i_gid_low =
2913 -                       cpu_to_le16(fs_high2lowgid(inode->i_gid));
2914 +                       cpu_to_le16(fs_high2lowgid(gid));
2915                 raw_inode->i_uid_high = 0;
2916                 raw_inode->i_gid_high = 0;
2917         }
2918 +#ifdef CONFIG_TAGGING_INTERN
2919 +       raw_inode->i_raw_tag = cpu_to_le16(inode->i_tag);
2920 +#endif
2921         raw_inode->i_links_count = cpu_to_le16(inode->i_nlink);
2922         raw_inode->i_size = cpu_to_le32(ei->i_disksize);
2923         raw_inode->i_atime = cpu_to_le32(inode->i_atime.tv_sec);
2924 @@ -3208,7 +3245,8 @@ int ext3_setattr(struct dentry *dentry, 
2925         if (is_quota_modification(inode, attr))
2926                 dquot_initialize(inode);
2927         if ((ia_valid & ATTR_UID && attr->ia_uid != inode->i_uid) ||
2928 -               (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid)) {
2929 +               (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid) ||
2930 +               (ia_valid & ATTR_TAG && attr->ia_tag != inode->i_tag)) {
2931                 handle_t *handle;
2932  
2933                 /* (user+group)*(old+new) structure, inode write (sb,
2934 @@ -3230,6 +3268,8 @@ int ext3_setattr(struct dentry *dentry, 
2935                         inode->i_uid = attr->ia_uid;
2936                 if (attr->ia_valid & ATTR_GID)
2937                         inode->i_gid = attr->ia_gid;
2938 +               if ((attr->ia_valid & ATTR_TAG) && IS_TAGGED(inode))
2939 +                       inode->i_tag = attr->ia_tag;
2940                 error = ext3_mark_inode_dirty(handle, inode);
2941                 ext3_journal_stop(handle);
2942         }
2943 diff -NurpP --minimal linux-3.0.25/fs/ext3/ioctl.c linux-3.0.25-vs2.3.2.3/fs/ext3/ioctl.c
2944 --- linux-3.0.25/fs/ext3/ioctl.c        2011-05-22 16:17:52.000000000 +0200
2945 +++ linux-3.0.25-vs2.3.2.3/fs/ext3/ioctl.c      2011-06-10 22:11:24.000000000 +0200
2946 @@ -8,6 +8,7 @@
2947   */
2948  
2949  #include <linux/fs.h>
2950 +#include <linux/mount.h>
2951  #include <linux/jbd.h>
2952  #include <linux/capability.h>
2953  #include <linux/ext3_fs.h>
2954 @@ -17,6 +18,34 @@
2955  #include <linux/compat.h>
2956  #include <asm/uaccess.h>
2957  
2958 +
2959 +int ext3_sync_flags(struct inode *inode, int flags, int vflags)
2960 +{
2961 +       handle_t *handle = NULL;
2962 +       struct ext3_iloc iloc;
2963 +       int err;
2964 +
2965 +       handle = ext3_journal_start(inode, 1);
2966 +       if (IS_ERR(handle))
2967 +               return PTR_ERR(handle);
2968 +
2969 +       if (IS_SYNC(inode))
2970 +               handle->h_sync = 1;
2971 +       err = ext3_reserve_inode_write(handle, inode, &iloc);
2972 +       if (err)
2973 +               goto flags_err;
2974 +
2975 +       inode->i_flags = flags;
2976 +       inode->i_vflags = vflags;
2977 +       ext3_get_inode_flags(EXT3_I(inode));
2978 +       inode->i_ctime = CURRENT_TIME_SEC;
2979 +
2980 +       err = ext3_mark_iloc_dirty(handle, inode, &iloc);
2981 +flags_err:
2982 +       ext3_journal_stop(handle);
2983 +       return err;
2984 +}
2985 +
2986  long ext3_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
2987  {
2988         struct inode *inode = filp->f_dentry->d_inode;
2989 @@ -50,6 +79,11 @@ long ext3_ioctl(struct file *filp, unsig
2990  
2991                 flags = ext3_mask_flags(inode->i_mode, flags);
2992  
2993 +               if (IS_BARRIER(inode)) {
2994 +                       vxwprintk_task(1, "messing with the barrier.");
2995 +                       return -EACCES;
2996 +               }
2997 +
2998                 mutex_lock(&inode->i_mutex);
2999  
3000                 /* Is it quota file? Do not allow user to mess with it */
3001 @@ -68,7 +102,9 @@ long ext3_ioctl(struct file *filp, unsig
3002                  *
3003                  * This test looks nicer. Thanks to Pauline Middelink
3004                  */
3005 -               if ((flags ^ oldflags) & (EXT3_APPEND_FL | EXT3_IMMUTABLE_FL)) {
3006 +               if ((oldflags & EXT3_IMMUTABLE_FL) ||
3007 +                       ((flags ^ oldflags) & (EXT3_APPEND_FL |
3008 +                       EXT3_IMMUTABLE_FL | EXT3_IXUNLINK_FL))) {
3009                         if (!capable(CAP_LINUX_IMMUTABLE))
3010                                 goto flags_out;
3011                 }
3012 @@ -93,7 +129,7 @@ long ext3_ioctl(struct file *filp, unsig
3013                 if (err)
3014                         goto flags_err;
3015  
3016 -               flags = flags & EXT3_FL_USER_MODIFIABLE;
3017 +               flags &= EXT3_FL_USER_MODIFIABLE;
3018                 flags |= oldflags & ~EXT3_FL_USER_MODIFIABLE;
3019                 ei->i_flags = flags;
3020  
3021 diff -NurpP --minimal linux-3.0.25/fs/ext3/namei.c linux-3.0.25-vs2.3.2.3/fs/ext3/namei.c
3022 --- linux-3.0.25/fs/ext3/namei.c        2012-03-19 21:16:51.000000000 +0100
3023 +++ linux-3.0.25-vs2.3.2.3/fs/ext3/namei.c      2011-08-29 03:45:09.000000000 +0200
3024 @@ -36,6 +36,7 @@
3025  #include <linux/quotaops.h>
3026  #include <linux/buffer_head.h>
3027  #include <linux/bio.h>
3028 +#include <linux/vs_tag.h>
3029  
3030  #include "namei.h"
3031  #include "xattr.h"
3032 @@ -923,6 +924,7 @@ restart:
3033                                 if (bh)
3034                                         ll_rw_block(READ_META, 1, &bh);
3035                         }
3036 +               dx_propagate_tag(nd, inode);
3037                 }
3038                 if ((bh = bh_use[ra_ptr++]) == NULL)
3039                         goto next;
3040 @@ -2536,6 +2538,7 @@ const struct inode_operations ext3_dir_i
3041         .removexattr    = generic_removexattr,
3042  #endif
3043         .check_acl      = ext3_check_acl,
3044 +       .sync_flags     = ext3_sync_flags,
3045  };
3046  
3047  const struct inode_operations ext3_special_inode_operations = {
3048 diff -NurpP --minimal linux-3.0.25/fs/ext3/super.c linux-3.0.25-vs2.3.2.3/fs/ext3/super.c
3049 --- linux-3.0.25/fs/ext3/super.c        2011-07-22 11:18:05.000000000 +0200
3050 +++ linux-3.0.25-vs2.3.2.3/fs/ext3/super.c      2011-06-10 22:11:24.000000000 +0200
3051 @@ -821,7 +821,8 @@ enum {
3052         Opt_usrjquota, Opt_grpjquota, Opt_offusrjquota, Opt_offgrpjquota,
3053         Opt_jqfmt_vfsold, Opt_jqfmt_vfsv0, Opt_jqfmt_vfsv1, Opt_quota,
3054         Opt_noquota, Opt_ignore, Opt_barrier, Opt_nobarrier, Opt_err,
3055 -       Opt_resize, Opt_usrquota, Opt_grpquota
3056 +       Opt_resize, Opt_usrquota, Opt_grpquota,
3057 +       Opt_tag, Opt_notag, Opt_tagid
3058  };
3059  
3060  static const match_table_t tokens = {
3061 @@ -878,6 +879,9 @@ static const match_table_t tokens = {
3062         {Opt_barrier, "barrier"},
3063         {Opt_nobarrier, "nobarrier"},
3064         {Opt_resize, "resize"},
3065 +       {Opt_tag, "tag"},
3066 +       {Opt_notag, "notag"},
3067 +       {Opt_tagid, "tagid=%u"},
3068         {Opt_err, NULL},
3069  };
3070  
3071 @@ -1030,6 +1034,20 @@ static int parse_options (char *options,
3072                 case Opt_nouid32:
3073                         set_opt (sbi->s_mount_opt, NO_UID32);
3074                         break;
3075 +#ifndef CONFIG_TAGGING_NONE
3076 +               case Opt_tag:
3077 +                       set_opt (sbi->s_mount_opt, TAGGED);
3078 +                       break;
3079 +               case Opt_notag:
3080 +                       clear_opt (sbi->s_mount_opt, TAGGED);
3081 +                       break;
3082 +#endif
3083 +#ifdef CONFIG_PROPAGATE
3084 +               case Opt_tagid:
3085 +                       /* use args[0] */
3086 +                       set_opt (sbi->s_mount_opt, TAGGED);
3087 +                       break;
3088 +#endif
3089                 case Opt_nocheck:
3090                         clear_opt (sbi->s_mount_opt, CHECK);
3091                         break;
3092 @@ -1724,6 +1742,9 @@ static int ext3_fill_super (struct super
3093                             NULL, 0))
3094                 goto failed_mount;
3095  
3096 +       if (EXT3_SB(sb)->s_mount_opt & EXT3_MOUNT_TAGGED)
3097 +               sb->s_flags |= MS_TAGGED;
3098 +
3099         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
3100                 (test_opt(sb, POSIX_ACL) ? MS_POSIXACL : 0);
3101  
3102 @@ -2604,6 +2625,14 @@ static int ext3_remount (struct super_bl
3103         if (test_opt(sb, ABORT))
3104                 ext3_abort(sb, __func__, "Abort forced by user");
3105  
3106 +       if ((sbi->s_mount_opt & EXT3_MOUNT_TAGGED) &&
3107 +               !(sb->s_flags & MS_TAGGED)) {
3108 +               printk("EXT3-fs: %s: tagging not permitted on remount.\n",
3109 +                       sb->s_id);
3110 +               err = -EINVAL;
3111 +               goto restore_opts;
3112 +       }
3113 +
3114         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
3115                 (test_opt(sb, POSIX_ACL) ? MS_POSIXACL : 0);
3116  
3117 diff -NurpP --minimal linux-3.0.25/fs/ext4/ext4.h linux-3.0.25-vs2.3.2.3/fs/ext4/ext4.h
3118 --- linux-3.0.25/fs/ext4/ext4.h 2012-03-19 21:16:51.000000000 +0100
3119 +++ linux-3.0.25-vs2.3.2.3/fs/ext4/ext4.h       2011-11-15 17:37:06.000000000 +0100
3120 @@ -351,8 +351,12 @@ struct flex_groups {
3121  #define EXT4_EXTENTS_FL                        0x00080000 /* Inode uses extents */
3122  #define EXT4_EA_INODE_FL               0x00200000 /* Inode used for large EA */
3123  #define EXT4_EOFBLOCKS_FL              0x00400000 /* Blocks allocated beyond EOF */
3124 +#define EXT4_IXUNLINK_FL               0x08000000 /* Immutable invert on unlink */
3125  #define EXT4_RESERVED_FL               0x80000000 /* reserved for ext4 lib */
3126  
3127 +#define EXT4_BARRIER_FL                        0x04000000 /* Barrier for chroot() */
3128 +#define EXT4_COW_FL                    0x20000000 /* Copy on Write marker */
3129 +
3130  #define EXT4_FL_USER_VISIBLE           0x004BDFFF /* User visible flags */
3131  #define EXT4_FL_USER_MODIFIABLE                0x004B80FF /* User modifiable flags */
3132  
3133 @@ -609,7 +613,8 @@ struct ext4_inode {
3134                         __le16  l_i_file_acl_high;
3135                         __le16  l_i_uid_high;   /* these 2 fields */
3136                         __le16  l_i_gid_high;   /* were reserved2[0] */
3137 -                       __u32   l_i_reserved2;
3138 +                       __le16  l_i_tag;        /* Context Tag */
3139 +                       __u16   l_i_reserved2;
3140                 } linux2;
3141                 struct {
3142                         __le16  h_i_reserved1;  /* Obsoleted fragment number/size which are removed in ext4 */
3143 @@ -727,6 +732,7 @@ do {                                                                               \
3144  #define i_gid_low      i_gid
3145  #define i_uid_high     osd2.linux2.l_i_uid_high
3146  #define i_gid_high     osd2.linux2.l_i_gid_high
3147 +#define i_raw_tag      osd2.linux2.l_i_tag
3148  #define i_reserved2    osd2.linux2.l_i_reserved2
3149  
3150  #elif defined(__GNU__)
3151 @@ -903,6 +909,7 @@ struct ext4_inode_info {
3152  #define EXT4_MOUNT_POSIX_ACL           0x08000 /* POSIX Access Control Lists */
3153  #define EXT4_MOUNT_NO_AUTO_DA_ALLOC    0x10000 /* No auto delalloc mapping */
3154  #define EXT4_MOUNT_BARRIER             0x20000 /* Use block barriers */
3155 +#define EXT4_MOUNT_TAGGED              0x40000 /* Enable Context Tags */
3156  #define EXT4_MOUNT_QUOTA               0x80000 /* Some quota option set */
3157  #define EXT4_MOUNT_USRQUOTA            0x100000 /* "old" user quota */
3158  #define EXT4_MOUNT_GRPQUOTA            0x200000 /* "old" group quota */
3159 @@ -2173,6 +2180,7 @@ extern int ext4_map_blocks(handle_t *han
3160                            struct ext4_map_blocks *map, int flags);
3161  extern int ext4_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
3162                         __u64 start, __u64 len);
3163 +extern int ext4_sync_flags(struct inode *, int, int);
3164  /* move_extent.c */
3165  extern int ext4_move_extents(struct file *o_filp, struct file *d_filp,
3166                              __u64 start_orig, __u64 start_donor,
3167 diff -NurpP --minimal linux-3.0.25/fs/ext4/file.c linux-3.0.25-vs2.3.2.3/fs/ext4/file.c
3168 --- linux-3.0.25/fs/ext4/file.c 2011-07-22 11:18:05.000000000 +0200
3169 +++ linux-3.0.25-vs2.3.2.3/fs/ext4/file.c       2011-06-10 22:11:24.000000000 +0200
3170 @@ -282,5 +282,6 @@ const struct inode_operations ext4_file_
3171  #endif
3172         .check_acl      = ext4_check_acl,
3173         .fiemap         = ext4_fiemap,
3174 +       .sync_flags     = ext4_sync_flags,
3175  };
3176  
3177 diff -NurpP --minimal linux-3.0.25/fs/ext4/ialloc.c linux-3.0.25-vs2.3.2.3/fs/ext4/ialloc.c
3178 --- linux-3.0.25/fs/ext4/ialloc.c       2011-05-22 16:17:52.000000000 +0200
3179 +++ linux-3.0.25-vs2.3.2.3/fs/ext4/ialloc.c     2011-06-10 22:11:24.000000000 +0200
3180 @@ -22,6 +22,7 @@
3181  #include <linux/random.h>
3182  #include <linux/bitops.h>
3183  #include <linux/blkdev.h>
3184 +#include <linux/vs_tag.h>
3185  #include <asm/byteorder.h>
3186  
3187  #include "ext4.h"
3188 @@ -992,6 +993,7 @@ got:
3189                 inode->i_mode = mode;
3190                 inode->i_uid = current_fsuid();
3191                 inode->i_gid = dir->i_gid;
3192 +               inode->i_tag = dx_current_fstag(sb);
3193         } else
3194                 inode_init_owner(inode, dir, mode);
3195  
3196 diff -NurpP --minimal linux-3.0.25/fs/ext4/inode.c linux-3.0.25-vs2.3.2.3/fs/ext4/inode.c
3197 --- linux-3.0.25/fs/ext4/inode.c        2012-03-19 21:16:51.000000000 +0100
3198 +++ linux-3.0.25-vs2.3.2.3/fs/ext4/inode.c      2011-12-23 16:09:00.000000000 +0100
3199 @@ -42,6 +42,7 @@
3200  #include <linux/printk.h>
3201  #include <linux/slab.h>
3202  #include <linux/ratelimit.h>
3203 +#include <linux/vs_tag.h>
3204  
3205  #include "ext4_jbd2.h"
3206  #include "xattr.h"
3207 @@ -4819,41 +4820,64 @@ void ext4_set_inode_flags(struct inode *
3208  {
3209         unsigned int flags = EXT4_I(inode)->i_flags;
3210  
3211 -       inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
3212 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
3213 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
3214 +
3215 +       if (flags & EXT4_IMMUTABLE_FL)
3216 +               inode->i_flags |= S_IMMUTABLE;
3217 +       if (flags & EXT4_IXUNLINK_FL)
3218 +               inode->i_flags |= S_IXUNLINK;
3219 +
3220         if (flags & EXT4_SYNC_FL)
3221                 inode->i_flags |= S_SYNC;
3222         if (flags & EXT4_APPEND_FL)
3223                 inode->i_flags |= S_APPEND;
3224 -       if (flags & EXT4_IMMUTABLE_FL)
3225 -               inode->i_flags |= S_IMMUTABLE;
3226         if (flags & EXT4_NOATIME_FL)
3227                 inode->i_flags |= S_NOATIME;
3228         if (flags & EXT4_DIRSYNC_FL)
3229                 inode->i_flags |= S_DIRSYNC;
3230 +
3231 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
3232 +
3233 +       if (flags & EXT4_BARRIER_FL)
3234 +               inode->i_vflags |= V_BARRIER;
3235 +       if (flags & EXT4_COW_FL)
3236 +               inode->i_vflags |= V_COW;
3237  }
3238  
3239  /* Propagate flags from i_flags to EXT4_I(inode)->i_flags */
3240  void ext4_get_inode_flags(struct ext4_inode_info *ei)
3241  {
3242 -       unsigned int vfs_fl;
3243 +       unsigned int vfs_fl, vfs_vf;
3244         unsigned long old_fl, new_fl;
3245  
3246         do {
3247                 vfs_fl = ei->vfs_inode.i_flags;
3248 +               vfs_vf = ei->vfs_inode.i_vflags;
3249                 old_fl = ei->i_flags;
3250                 new_fl = old_fl & ~(EXT4_SYNC_FL|EXT4_APPEND_FL|
3251                                 EXT4_IMMUTABLE_FL|EXT4_NOATIME_FL|
3252 -                               EXT4_DIRSYNC_FL);
3253 +                               EXT4_DIRSYNC_FL|EXT4_BARRIER_FL|
3254 +                               EXT4_COW_FL);
3255 +
3256 +               if (vfs_fl & S_IMMUTABLE)
3257 +                       new_fl |= EXT4_IMMUTABLE_FL;
3258 +               if (vfs_fl & S_IXUNLINK)
3259 +                       new_fl |= EXT4_IXUNLINK_FL;
3260 +
3261                 if (vfs_fl & S_SYNC)
3262                         new_fl |= EXT4_SYNC_FL;
3263                 if (vfs_fl & S_APPEND)
3264                         new_fl |= EXT4_APPEND_FL;
3265 -               if (vfs_fl & S_IMMUTABLE)
3266 -                       new_fl |= EXT4_IMMUTABLE_FL;
3267                 if (vfs_fl & S_NOATIME)
3268                         new_fl |= EXT4_NOATIME_FL;
3269                 if (vfs_fl & S_DIRSYNC)
3270                         new_fl |= EXT4_DIRSYNC_FL;
3271 +
3272 +               if (vfs_vf & V_BARRIER)
3273 +                       new_fl |= EXT4_BARRIER_FL;
3274 +               if (vfs_vf & V_COW)
3275 +                       new_fl |= EXT4_COW_FL;
3276         } while (cmpxchg(&ei->i_flags, old_fl, new_fl) != old_fl);
3277  }
3278  
3279 @@ -4889,6 +4913,8 @@ struct inode *ext4_iget(struct super_blo
3280         journal_t *journal = EXT4_SB(sb)->s_journal;
3281         long ret;
3282         int block;
3283 +       uid_t uid;
3284 +       gid_t gid;
3285  
3286         inode = iget_locked(sb, ino);
3287         if (!inode)
3288 @@ -4904,12 +4930,16 @@ struct inode *ext4_iget(struct super_blo
3289                 goto bad_inode;
3290         raw_inode = ext4_raw_inode(&iloc);
3291         inode->i_mode = le16_to_cpu(raw_inode->i_mode);
3292 -       inode->i_uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
3293 -       inode->i_gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
3294 +       uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
3295 +       gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
3296         if (!(test_opt(inode->i_sb, NO_UID32))) {
3297 -               inode->i_uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
3298 -               inode->i_gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
3299 +               uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
3300 +               gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
3301         }
3302 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
3303 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
3304 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid,
3305 +               le16_to_cpu(raw_inode->i_raw_tag));
3306         inode->i_nlink = le16_to_cpu(raw_inode->i_links_count);
3307  
3308         ext4_clear_state_flags(ei);     /* Only relevant on 32-bit archs */
3309 @@ -5128,6 +5158,8 @@ static int ext4_do_update_inode(handle_t
3310         struct ext4_inode *raw_inode = ext4_raw_inode(iloc);
3311         struct ext4_inode_info *ei = EXT4_I(inode);
3312         struct buffer_head *bh = iloc->bh;
3313 +       uid_t uid = TAGINO_UID(DX_TAG(inode), inode->i_uid, inode->i_tag);
3314 +       gid_t gid = TAGINO_GID(DX_TAG(inode), inode->i_gid, inode->i_tag);
3315         int err = 0, rc, block;
3316  
3317         /* For fields not not tracking in the in-memory inode,
3318 @@ -5138,29 +5170,32 @@ static int ext4_do_update_inode(handle_t
3319         ext4_get_inode_flags(ei);
3320         raw_inode->i_mode = cpu_to_le16(inode->i_mode);
3321         if (!(test_opt(inode->i_sb, NO_UID32))) {
3322 -               raw_inode->i_uid_low = cpu_to_le16(low_16_bits(inode->i_uid));
3323 -               raw_inode->i_gid_low = cpu_to_le16(low_16_bits(inode->i_gid));
3324 +               raw_inode->i_uid_low = cpu_to_le16(low_16_bits(uid));
3325 +               raw_inode->i_gid_low = cpu_to_le16(low_16_bits(gid));
3326  /*
3327   * Fix up interoperability with old kernels. Otherwise, old inodes get
3328   * re-used with the upper 16 bits of the uid/gid intact
3329   */
3330                 if (!ei->i_dtime) {
3331                         raw_inode->i_uid_high =
3332 -                               cpu_to_le16(high_16_bits(inode->i_uid));
3333 +                               cpu_to_le16(high_16_bits(uid));
3334                         raw_inode->i_gid_high =
3335 -                               cpu_to_le16(high_16_bits(inode->i_gid));
3336 +                               cpu_to_le16(high_16_bits(gid));
3337                 } else {
3338                         raw_inode->i_uid_high = 0;
3339                         raw_inode->i_gid_high = 0;
3340                 }
3341         } else {
3342                 raw_inode->i_uid_low =
3343 -                       cpu_to_le16(fs_high2lowuid(inode->i_uid));
3344 +                       cpu_to_le16(fs_high2lowuid(uid));
3345                 raw_inode->i_gid_low =
3346 -                       cpu_to_le16(fs_high2lowgid(inode->i_gid));
3347 +                       cpu_to_le16(fs_high2lowgid(gid));
3348                 raw_inode->i_uid_high = 0;
3349                 raw_inode->i_gid_high = 0;
3350         }
3351 +#ifdef CONFIG_TAGGING_INTERN
3352 +       raw_inode->i_raw_tag = cpu_to_le16(inode->i_tag);
3353 +#endif
3354         raw_inode->i_links_count = cpu_to_le16(inode->i_nlink);
3355  
3356         EXT4_INODE_SET_XTIME(i_ctime, inode, raw_inode);
3357 @@ -5346,7 +5381,8 @@ int ext4_setattr(struct dentry *dentry, 
3358         if (is_quota_modification(inode, attr))
3359                 dquot_initialize(inode);
3360         if ((ia_valid & ATTR_UID && attr->ia_uid != inode->i_uid) ||
3361 -               (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid)) {
3362 +               (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid) ||
3363 +               (ia_valid & ATTR_TAG && attr->ia_tag != inode->i_tag)) {
3364                 handle_t *handle;
3365  
3366                 /* (user+group)*(old+new) structure, inode write (sb,
3367 @@ -5368,6 +5404,8 @@ int ext4_setattr(struct dentry *dentry, 
3368                         inode->i_uid = attr->ia_uid;
3369                 if (attr->ia_valid & ATTR_GID)
3370                         inode->i_gid = attr->ia_gid;
3371 +               if ((attr->ia_valid & ATTR_TAG) && IS_TAGGED(inode))
3372 +                       inode->i_tag = attr->ia_tag;
3373                 error = ext4_mark_inode_dirty(handle, inode);
3374                 ext4_journal_stop(handle);
3375         }
3376 diff -NurpP --minimal linux-3.0.25/fs/ext4/ioctl.c linux-3.0.25-vs2.3.2.3/fs/ext4/ioctl.c
3377 --- linux-3.0.25/fs/ext4/ioctl.c        2011-05-22 16:17:52.000000000 +0200
3378 +++ linux-3.0.25-vs2.3.2.3/fs/ext4/ioctl.c      2011-06-10 22:11:24.000000000 +0200
3379 @@ -14,10 +14,39 @@
3380  #include <linux/compat.h>
3381  #include <linux/mount.h>
3382  #include <linux/file.h>
3383 +#include <linux/vs_tag.h>
3384  #include <asm/uaccess.h>
3385  #include "ext4_jbd2.h"
3386  #include "ext4.h"
3387  
3388 +
3389 +int ext4_sync_flags(struct inode *inode, int flags, int vflags)
3390 +{
3391 +       handle_t *handle = NULL;
3392 +       struct ext4_iloc iloc;
3393 +       int err;
3394 +
3395 +       handle = ext4_journal_start(inode, 1);
3396 +       if (IS_ERR(handle))
3397 +               return PTR_ERR(handle);
3398 +
3399 +       if (IS_SYNC(inode))
3400 +               ext4_handle_sync(handle);
3401 +       err = ext4_reserve_inode_write(handle, inode, &iloc);
3402 +       if (err)
3403 +               goto flags_err;
3404 +
3405 +       inode->i_flags = flags;
3406 +       inode->i_vflags = vflags;
3407 +       ext4_get_inode_flags(EXT4_I(inode));
3408 +       inode->i_ctime = ext4_current_time(inode);
3409 +
3410 +       err = ext4_mark_iloc_dirty(handle, inode, &iloc);
3411 +flags_err:
3412 +       ext4_journal_stop(handle);
3413 +       return err;
3414 +}
3415 +
3416  long ext4_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
3417  {
3418         struct inode *inode = filp->f_dentry->d_inode;
3419 @@ -50,6 +79,11 @@ long ext4_ioctl(struct file *filp, unsig
3420  
3421                 flags = ext4_mask_flags(inode->i_mode, flags);
3422  
3423 +               if (IS_BARRIER(inode)) {
3424 +                       vxwprintk_task(1, "messing with the barrier.");
3425 +                       return -EACCES;
3426 +               }
3427 +
3428                 err = -EPERM;
3429                 mutex_lock(&inode->i_mutex);
3430                 /* Is it quota file? Do not allow user to mess with it */
3431 @@ -67,7 +101,9 @@ long ext4_ioctl(struct file *filp, unsig
3432                  *
3433                  * This test looks nicer. Thanks to Pauline Middelink
3434                  */
3435 -               if ((flags ^ oldflags) & (EXT4_APPEND_FL | EXT4_IMMUTABLE_FL)) {
3436 +               if ((oldflags & EXT4_IMMUTABLE_FL) ||
3437 +                       ((flags ^ oldflags) & (EXT4_APPEND_FL |
3438 +                       EXT4_IMMUTABLE_FL | EXT4_IXUNLINK_FL))) {
3439                         if (!capable(CAP_LINUX_IMMUTABLE))
3440                                 goto flags_out;
3441                 }
3442 diff -NurpP --minimal linux-3.0.25/fs/ext4/namei.c linux-3.0.25-vs2.3.2.3/fs/ext4/namei.c
3443 --- linux-3.0.25/fs/ext4/namei.c        2012-03-19 21:16:51.000000000 +0100
3444 +++ linux-3.0.25-vs2.3.2.3/fs/ext4/namei.c      2011-11-15 17:37:06.000000000 +0100
3445 @@ -34,6 +34,7 @@
3446  #include <linux/quotaops.h>
3447  #include <linux/buffer_head.h>
3448  #include <linux/bio.h>
3449 +#include <linux/vs_tag.h>
3450  #include "ext4.h"
3451  #include "ext4_jbd2.h"
3452  
3453 @@ -924,6 +925,7 @@ restart:
3454                                 if (bh)
3455                                         ll_rw_block(READ_META, 1, &bh);
3456                         }
3457 +               dx_propagate_tag(nd, inode);
3458                 }
3459                 if ((bh = bh_use[ra_ptr++]) == NULL)
3460                         goto next;
3461 @@ -2598,6 +2600,7 @@ const struct inode_operations ext4_dir_i
3462  #endif
3463         .check_acl      = ext4_check_acl,
3464         .fiemap         = ext4_fiemap,
3465 +       .sync_flags     = ext4_sync_flags,
3466  };
3467  
3468  const struct inode_operations ext4_special_inode_operations = {
3469 diff -NurpP --minimal linux-3.0.25/fs/ext4/super.c linux-3.0.25-vs2.3.2.3/fs/ext4/super.c
3470 --- linux-3.0.25/fs/ext4/super.c        2012-03-19 21:16:51.000000000 +0100
3471 +++ linux-3.0.25-vs2.3.2.3/fs/ext4/super.c      2012-01-26 08:39:53.000000000 +0100
3472 @@ -1292,6 +1292,7 @@ enum {
3473         Opt_inode_readahead_blks, Opt_journal_ioprio,
3474         Opt_dioread_nolock, Opt_dioread_lock,
3475         Opt_discard, Opt_nodiscard, Opt_init_itable, Opt_noinit_itable,
3476 +       Opt_tag, Opt_notag, Opt_tagid
3477  };
3478  
3479  static const match_table_t tokens = {
3480 @@ -1367,6 +1368,9 @@ static const match_table_t tokens = {
3481         {Opt_init_itable, "init_itable=%u"},
3482         {Opt_init_itable, "init_itable"},
3483         {Opt_noinit_itable, "noinit_itable"},
3484 +       {Opt_tag, "tag"},
3485 +       {Opt_notag, "notag"},
3486 +       {Opt_tagid, "tagid=%u"},
3487         {Opt_err, NULL},
3488  };
3489  
3490 @@ -1535,6 +1539,20 @@ static int parse_options(char *options, 
3491                 case Opt_nouid32:
3492                         set_opt(sb, NO_UID32);
3493                         break;
3494 +#ifndef CONFIG_TAGGING_NONE
3495 +               case Opt_tag:
3496 +                       set_opt(sb, TAGGED);
3497 +                       break;
3498 +               case Opt_notag:
3499 +                       clear_opt(sb, TAGGED);
3500 +                       break;
3501 +#endif
3502 +#ifdef CONFIG_PROPAGATE
3503 +               case Opt_tagid:
3504 +                       /* use args[0] */
3505 +                       set_opt(sb, TAGGED);
3506 +                       break;
3507 +#endif
3508                 case Opt_debug:
3509                         set_opt(sb, DEBUG);
3510                         break;
3511 @@ -3191,6 +3209,9 @@ static int ext4_fill_super(struct super_
3512                            &journal_ioprio, NULL, 0))
3513                 goto failed_mount;
3514  
3515 +       if (EXT4_SB(sb)->s_mount_opt & EXT4_MOUNT_TAGGED)
3516 +               sb->s_flags |= MS_TAGGED;
3517 +
3518         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
3519                 (test_opt(sb, POSIX_ACL) ? MS_POSIXACL : 0);
3520  
3521 @@ -4321,6 +4342,14 @@ static int ext4_remount(struct super_blo
3522         if (sbi->s_mount_flags & EXT4_MF_FS_ABORTED)
3523                 ext4_abort(sb, "Abort forced by user");
3524  
3525 +       if ((sbi->s_mount_opt & EXT4_MOUNT_TAGGED) &&
3526 +               !(sb->s_flags & MS_TAGGED)) {
3527 +               printk("EXT4-fs: %s: tagging not permitted on remount.\n",
3528 +                       sb->s_id);
3529 +               err = -EINVAL;
3530 +               goto restore_opts;
3531 +       }
3532 +
3533         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
3534                 (test_opt(sb, POSIX_ACL) ? MS_POSIXACL : 0);
3535  
3536 diff -NurpP --minimal linux-3.0.25/fs/fcntl.c linux-3.0.25-vs2.3.2.3/fs/fcntl.c
3537 --- linux-3.0.25/fs/fcntl.c     2011-05-22 16:17:52.000000000 +0200
3538 +++ linux-3.0.25-vs2.3.2.3/fs/fcntl.c   2011-06-10 22:11:24.000000000 +0200
3539 @@ -20,6 +20,7 @@
3540  #include <linux/signal.h>
3541  #include <linux/rcupdate.h>
3542  #include <linux/pid_namespace.h>
3543 +#include <linux/vs_limit.h>
3544  
3545  #include <asm/poll.h>
3546  #include <asm/siginfo.h>
3547 @@ -103,6 +104,8 @@ SYSCALL_DEFINE3(dup3, unsigned int, oldf
3548  
3549         if (tofree)
3550                 filp_close(tofree, files);
3551 +       else
3552 +               vx_openfd_inc(newfd);   /* fd was unused */
3553  
3554         return newfd;
3555  
3556 @@ -447,6 +450,8 @@ SYSCALL_DEFINE3(fcntl, unsigned int, fd,
3557         filp = fget_raw(fd);
3558         if (!filp)
3559                 goto out;
3560 +       if (!vx_files_avail(1))
3561 +               goto out;
3562  
3563         if (unlikely(filp->f_mode & FMODE_PATH)) {
3564                 if (!check_fcntl_cmd(cmd)) {
3565 diff -NurpP --minimal linux-3.0.25/fs/file.c linux-3.0.25-vs2.3.2.3/fs/file.c
3566 --- linux-3.0.25/fs/file.c      2011-05-22 16:17:52.000000000 +0200
3567 +++ linux-3.0.25-vs2.3.2.3/fs/file.c    2011-06-10 22:11:24.000000000 +0200
3568 @@ -21,6 +21,7 @@
3569  #include <linux/spinlock.h>
3570  #include <linux/rcupdate.h>
3571  #include <linux/workqueue.h>
3572 +#include <linux/vs_limit.h>
3573  
3574  struct fdtable_defer {
3575         spinlock_t lock;
3576 @@ -359,6 +360,8 @@ struct files_struct *dup_fd(struct files
3577                 struct file *f = *old_fds++;
3578                 if (f) {
3579                         get_file(f);
3580 +                       /* TODO: sum it first for check and performance */
3581 +                       vx_openfd_inc(open_files - i);
3582                 } else {
3583                         /*
3584                          * The fd may be claimed in the fd bitmap but not yet
3585 @@ -466,6 +469,7 @@ repeat:
3586         else
3587                 FD_CLR(fd, fdt->close_on_exec);
3588         error = fd;
3589 +       vx_openfd_inc(fd);
3590  #if 1
3591         /* Sanity check */
3592         if (rcu_dereference_raw(fdt->fd[fd]) != NULL) {
3593 diff -NurpP --minimal linux-3.0.25/fs/file_table.c linux-3.0.25-vs2.3.2.3/fs/file_table.c
3594 --- linux-3.0.25/fs/file_table.c        2011-05-22 16:17:52.000000000 +0200
3595 +++ linux-3.0.25-vs2.3.2.3/fs/file_table.c      2011-06-10 22:11:24.000000000 +0200
3596 @@ -24,6 +24,8 @@
3597  #include <linux/percpu_counter.h>
3598  #include <linux/percpu.h>
3599  #include <linux/ima.h>
3600 +#include <linux/vs_limit.h>
3601 +#include <linux/vs_context.h>
3602  
3603  #include <asm/atomic.h>
3604  
3605 @@ -135,6 +137,8 @@ struct file *get_empty_filp(void)
3606         spin_lock_init(&f->f_lock);
3607         eventpoll_init_file(f);
3608         /* f->f_version: 0 */
3609 +       f->f_xid = vx_current_xid();
3610 +       vx_files_inc(f);
3611         return f;
3612  
3613  over:
3614 @@ -253,6 +257,8 @@ static void __fput(struct file *file)
3615         }
3616         fops_put(file->f_op);
3617         put_pid(file->f_owner.pid);
3618 +       vx_files_dec(file);
3619 +       file->f_xid = 0;
3620         file_sb_list_del(file);
3621         if ((file->f_mode & (FMODE_READ | FMODE_WRITE)) == FMODE_READ)
3622                 i_readcount_dec(inode);
3623 @@ -383,6 +389,8 @@ void put_filp(struct file *file)
3624  {
3625         if (atomic_long_dec_and_test(&file->f_count)) {
3626                 security_file_free(file);
3627 +               vx_files_dec(file);
3628 +               file->f_xid = 0;
3629                 file_sb_list_del(file);
3630                 file_free(file);
3631         }
3632 diff -NurpP --minimal linux-3.0.25/fs/fs_struct.c linux-3.0.25-vs2.3.2.3/fs/fs_struct.c
3633 --- linux-3.0.25/fs/fs_struct.c 2011-03-15 18:07:31.000000000 +0100
3634 +++ linux-3.0.25-vs2.3.2.3/fs/fs_struct.c       2011-06-10 22:11:24.000000000 +0200
3635 @@ -4,6 +4,7 @@
3636  #include <linux/path.h>
3637  #include <linux/slab.h>
3638  #include <linux/fs_struct.h>
3639 +#include <linux/vserver/global.h>
3640  #include "internal.h"
3641  
3642  static inline void path_get_longterm(struct path *path)
3643 @@ -96,6 +97,7 @@ void free_fs_struct(struct fs_struct *fs
3644  {
3645         path_put_longterm(&fs->root);
3646         path_put_longterm(&fs->pwd);
3647 +       atomic_dec(&vs_global_fs);
3648         kmem_cache_free(fs_cachep, fs);
3649  }
3650  
3651 @@ -135,6 +137,7 @@ struct fs_struct *copy_fs_struct(struct 
3652                 fs->pwd = old->pwd;
3653                 path_get_longterm(&fs->pwd);
3654                 spin_unlock(&old->lock);
3655 +               atomic_inc(&vs_global_fs);
3656         }
3657         return fs;
3658  }
3659 diff -NurpP --minimal linux-3.0.25/fs/gfs2/file.c linux-3.0.25-vs2.3.2.3/fs/gfs2/file.c
3660 --- linux-3.0.25/fs/gfs2/file.c 2011-07-22 11:18:05.000000000 +0200
3661 +++ linux-3.0.25-vs2.3.2.3/fs/gfs2/file.c       2011-06-10 22:11:24.000000000 +0200
3662 @@ -134,6 +134,9 @@ static const u32 fsflags_to_gfs2[32] = {
3663         [7] = GFS2_DIF_NOATIME,
3664         [12] = GFS2_DIF_EXHASH,
3665         [14] = GFS2_DIF_INHERIT_JDATA,
3666 +       [27] = GFS2_DIF_IXUNLINK,
3667 +       [26] = GFS2_DIF_BARRIER,
3668 +       [29] = GFS2_DIF_COW,
3669  };
3670  
3671  static const u32 gfs2_to_fsflags[32] = {
3672 @@ -143,6 +146,9 @@ static const u32 gfs2_to_fsflags[32] = {
3673         [gfs2fl_NoAtime] = FS_NOATIME_FL,
3674         [gfs2fl_ExHash] = FS_INDEX_FL,
3675         [gfs2fl_InheritJdata] = FS_JOURNAL_DATA_FL,
3676 +       [gfs2fl_IXUnlink] = FS_IXUNLINK_FL,
3677 +       [gfs2fl_Barrier] = FS_BARRIER_FL,
3678 +       [gfs2fl_Cow] = FS_COW_FL,
3679  };
3680  
3681  static int gfs2_get_flags(struct file *filp, u32 __user *ptr)
3682 @@ -173,10 +179,16 @@ void gfs2_set_inode_flags(struct inode *
3683  {
3684         struct gfs2_inode *ip = GFS2_I(inode);
3685         unsigned int flags = inode->i_flags;
3686 +       unsigned int vflags = inode->i_vflags;
3687 +
3688 +       flags &= ~(S_IMMUTABLE | S_IXUNLINK |
3689 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
3690  
3691 -       flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
3692         if (ip->i_diskflags & GFS2_DIF_IMMUTABLE)
3693                 flags |= S_IMMUTABLE;
3694 +       if (ip->i_diskflags & GFS2_DIF_IXUNLINK)
3695 +               flags |= S_IXUNLINK;
3696 +
3697         if (ip->i_diskflags & GFS2_DIF_APPENDONLY)
3698                 flags |= S_APPEND;
3699         if (ip->i_diskflags & GFS2_DIF_NOATIME)
3700 @@ -184,6 +196,43 @@ void gfs2_set_inode_flags(struct inode *
3701         if (ip->i_diskflags & GFS2_DIF_SYNC)
3702                 flags |= S_SYNC;
3703         inode->i_flags = flags;
3704 +
3705 +       vflags &= ~(V_BARRIER | V_COW);
3706 +
3707 +       if (ip->i_diskflags & GFS2_DIF_BARRIER)
3708 +               vflags |= V_BARRIER;
3709 +       if (ip->i_diskflags & GFS2_DIF_COW)
3710 +               vflags |= V_COW;
3711 +       inode->i_vflags = vflags;
3712 +}
3713 +
3714 +void gfs2_get_inode_flags(struct inode *inode)
3715 +{
3716 +       struct gfs2_inode *ip = GFS2_I(inode);
3717 +       unsigned int flags = inode->i_flags;
3718 +       unsigned int vflags = inode->i_vflags;
3719 +
3720 +       ip->i_diskflags &= ~(GFS2_DIF_APPENDONLY |
3721 +                       GFS2_DIF_NOATIME | GFS2_DIF_SYNC |
3722 +                       GFS2_DIF_IMMUTABLE | GFS2_DIF_IXUNLINK |
3723 +                       GFS2_DIF_BARRIER | GFS2_DIF_COW);
3724 +
3725 +       if (flags & S_IMMUTABLE)
3726 +               ip->i_diskflags |= GFS2_DIF_IMMUTABLE;
3727 +       if (flags & S_IXUNLINK)
3728 +               ip->i_diskflags |= GFS2_DIF_IXUNLINK;
3729 +
3730 +       if (flags & S_APPEND)
3731 +               ip->i_diskflags |= GFS2_DIF_APPENDONLY;
3732 +       if (flags & S_NOATIME)
3733 +               ip->i_diskflags |= GFS2_DIF_NOATIME;
3734 +       if (flags & S_SYNC)
3735 +               ip->i_diskflags |= GFS2_DIF_SYNC;
3736 +
3737 +       if (vflags & V_BARRIER)
3738 +               ip->i_diskflags |= GFS2_DIF_BARRIER;
3739 +       if (vflags & V_COW)
3740 +               ip->i_diskflags |= GFS2_DIF_COW;
3741  }
3742  
3743  /* Flags that can be set by user space */
3744 @@ -295,6 +344,37 @@ static int gfs2_set_flags(struct file *f
3745         return do_gfs2_set_flags(filp, gfsflags, ~GFS2_DIF_JDATA);
3746  }
3747  
3748 +int gfs2_sync_flags(struct inode *inode, int flags, int vflags)
3749 +{
3750 +       struct gfs2_inode *ip = GFS2_I(inode);
3751 +       struct gfs2_sbd *sdp = GFS2_SB(inode);
3752 +       struct buffer_head *bh;
3753 +       struct gfs2_holder gh;
3754 +       int error;
3755 +
3756 +       error = gfs2_glock_nq_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &gh);
3757 +       if (error)
3758 +               return error;
3759 +       error = gfs2_trans_begin(sdp, RES_DINODE, 0);
3760 +       if (error)
3761 +               goto out;
3762 +       error = gfs2_meta_inode_buffer(ip, &bh);
3763 +       if (error)
3764 +               goto out_trans_end;
3765 +       gfs2_trans_add_bh(ip->i_gl, bh, 1);
3766 +       inode->i_flags = flags;
3767 +       inode->i_vflags = vflags;
3768 +       gfs2_get_inode_flags(inode);
3769 +       gfs2_dinode_out(ip, bh->b_data);
3770 +       brelse(bh);
3771 +       gfs2_set_aops(inode);
3772 +out_trans_end:
3773 +       gfs2_trans_end(sdp);
3774 +out:
3775 +       gfs2_glock_dq_uninit(&gh);
3776 +       return error;
3777 +}
3778 +
3779  static long gfs2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
3780  {
3781         switch(cmd) {
3782 diff -NurpP --minimal linux-3.0.25/fs/gfs2/inode.h linux-3.0.25-vs2.3.2.3/fs/gfs2/inode.h
3783 --- linux-3.0.25/fs/gfs2/inode.h        2011-07-22 11:18:05.000000000 +0200
3784 +++ linux-3.0.25-vs2.3.2.3/fs/gfs2/inode.h      2011-06-10 22:11:24.000000000 +0200
3785 @@ -120,6 +120,7 @@ extern const struct file_operations gfs2
3786  extern const struct file_operations gfs2_dir_fops_nolock;
3787  
3788  extern void gfs2_set_inode_flags(struct inode *inode);
3789 +extern int gfs2_sync_flags(struct inode *inode, int flags, int vflags);
3790   
3791  #ifdef CONFIG_GFS2_FS_LOCKING_DLM
3792  extern const struct file_operations gfs2_file_fops;
3793 diff -NurpP --minimal linux-3.0.25/fs/inode.c linux-3.0.25-vs2.3.2.3/fs/inode.c
3794 --- linux-3.0.25/fs/inode.c     2011-07-22 11:18:05.000000000 +0200
3795 +++ linux-3.0.25-vs2.3.2.3/fs/inode.c   2011-07-01 11:35:34.000000000 +0200
3796 @@ -26,6 +26,7 @@
3797  #include <linux/ima.h>
3798  #include <linux/cred.h>
3799  #include <linux/buffer_head.h> /* for inode_has_buffers */
3800 +#include <linux/vs_tag.h>
3801  #include "internal.h"
3802  
3803  /*
3804 @@ -146,6 +147,9 @@ int inode_init_always(struct super_block
3805         struct address_space *const mapping = &inode->i_data;
3806  
3807         inode->i_sb = sb;
3808 +
3809 +       /* essential because of inode slab reuse */
3810 +       inode->i_tag = 0;
3811         inode->i_blkbits = sb->s_blocksize_bits;
3812         inode->i_flags = 0;
3813         atomic_set(&inode->i_count, 1);
3814 @@ -166,6 +170,7 @@ int inode_init_always(struct super_block
3815         inode->i_bdev = NULL;
3816         inode->i_cdev = NULL;
3817         inode->i_rdev = 0;
3818 +       inode->i_mdev = 0;
3819         inode->dirtied_when = 0;
3820  
3821         if (security_inode_alloc(inode))
3822 @@ -404,6 +409,8 @@ void __insert_inode_hash(struct inode *i
3823  }
3824  EXPORT_SYMBOL(__insert_inode_hash);
3825  
3826 +EXPORT_SYMBOL_GPL(__iget);
3827 +
3828  /**
3829   *     remove_inode_hash - remove an inode from the hash
3830   *     @inode: inode to unhash
3831 @@ -1643,9 +1650,11 @@ void init_special_inode(struct inode *in
3832         if (S_ISCHR(mode)) {
3833                 inode->i_fop = &def_chr_fops;
3834                 inode->i_rdev = rdev;
3835 +               inode->i_mdev = rdev;
3836         } else if (S_ISBLK(mode)) {
3837                 inode->i_fop = &def_blk_fops;
3838                 inode->i_rdev = rdev;
3839 +               inode->i_mdev = rdev;
3840         } else if (S_ISFIFO(mode))
3841                 inode->i_fop = &def_fifo_fops;
3842         else if (S_ISSOCK(mode))
3843 @@ -1674,6 +1683,7 @@ void inode_init_owner(struct inode *inod
3844         } else
3845                 inode->i_gid = current_fsgid();
3846         inode->i_mode = mode;
3847 +       inode->i_tag = dx_current_fstag(inode->i_sb);
3848  }
3849  EXPORT_SYMBOL(inode_init_owner);
3850  
3851 diff -NurpP --minimal linux-3.0.25/fs/ioctl.c linux-3.0.25-vs2.3.2.3/fs/ioctl.c
3852 --- linux-3.0.25/fs/ioctl.c     2011-05-22 16:17:52.000000000 +0200
3853 +++ linux-3.0.25-vs2.3.2.3/fs/ioctl.c   2011-06-10 22:11:24.000000000 +0200
3854 @@ -15,6 +15,9 @@
3855  #include <linux/writeback.h>
3856  #include <linux/buffer_head.h>
3857  #include <linux/falloc.h>
3858 +#include <linux/proc_fs.h>
3859 +#include <linux/vserver/inode.h>
3860 +#include <linux/vs_tag.h>
3861  
3862  #include <asm/ioctls.h>
3863  
3864 diff -NurpP --minimal linux-3.0.25/fs/ioprio.c linux-3.0.25-vs2.3.2.3/fs/ioprio.c
3865 --- linux-3.0.25/fs/ioprio.c    2011-01-05 21:50:24.000000000 +0100
3866 +++ linux-3.0.25-vs2.3.2.3/fs/ioprio.c  2011-06-10 22:11:24.000000000 +0200
3867 @@ -27,6 +27,7 @@
3868  #include <linux/syscalls.h>
3869  #include <linux/security.h>
3870  #include <linux/pid_namespace.h>
3871 +#include <linux/vs_base.h>
3872  
3873  int set_task_ioprio(struct task_struct *task, int ioprio)
3874  {
3875 @@ -119,6 +120,8 @@ SYSCALL_DEFINE3(ioprio_set, int, which, 
3876                         else
3877                                 pgrp = find_vpid(who);
3878                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
3879 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
3880 +                                       continue;
3881                                 ret = set_task_ioprio(p, ioprio);
3882                                 if (ret)
3883                                         break;
3884 @@ -208,6 +211,8 @@ SYSCALL_DEFINE2(ioprio_get, int, which, 
3885                         else
3886                                 pgrp = find_vpid(who);
3887                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
3888 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
3889 +                                       continue;
3890                                 tmpio = get_task_ioprio(p);
3891                                 if (tmpio < 0)
3892                                         continue;
3893 diff -NurpP --minimal linux-3.0.25/fs/jfs/file.c linux-3.0.25-vs2.3.2.3/fs/jfs/file.c
3894 --- linux-3.0.25/fs/jfs/file.c  2011-07-22 11:18:05.000000000 +0200
3895 +++ linux-3.0.25-vs2.3.2.3/fs/jfs/file.c        2011-07-01 11:35:34.000000000 +0200
3896 @@ -102,7 +102,8 @@ int jfs_setattr(struct dentry *dentry, s
3897         if (is_quota_modification(inode, iattr))
3898                 dquot_initialize(inode);
3899         if ((iattr->ia_valid & ATTR_UID && iattr->ia_uid != inode->i_uid) ||
3900 -           (iattr->ia_valid & ATTR_GID && iattr->ia_gid != inode->i_gid)) {
3901 +           (iattr->ia_valid & ATTR_GID && iattr->ia_gid != inode->i_gid) ||
3902 +           (iattr->ia_valid & ATTR_TAG && iattr->ia_tag != inode->i_tag)) {
3903                 rc = dquot_transfer(inode, iattr);
3904                 if (rc)
3905                         return rc;
3906 @@ -133,6 +134,7 @@ const struct inode_operations jfs_file_i
3907  #ifdef CONFIG_JFS_POSIX_ACL
3908         .check_acl      = jfs_check_acl,
3909  #endif
3910 +       .sync_flags     = jfs_sync_flags,
3911  };
3912  
3913  const struct file_operations jfs_file_operations = {
3914 diff -NurpP --minimal linux-3.0.25/fs/jfs/ioctl.c linux-3.0.25-vs2.3.2.3/fs/jfs/ioctl.c
3915 --- linux-3.0.25/fs/jfs/ioctl.c 2011-05-22 16:17:52.000000000 +0200
3916 +++ linux-3.0.25-vs2.3.2.3/fs/jfs/ioctl.c       2011-06-10 22:11:24.000000000 +0200
3917 @@ -11,6 +11,7 @@
3918  #include <linux/mount.h>
3919  #include <linux/time.h>
3920  #include <linux/sched.h>
3921 +#include <linux/mount.h>
3922  #include <asm/current.h>
3923  #include <asm/uaccess.h>
3924  
3925 @@ -52,6 +53,16 @@ static long jfs_map_ext2(unsigned long f
3926  }
3927  
3928  
3929 +int jfs_sync_flags(struct inode *inode, int flags, int vflags)
3930 +{
3931 +       inode->i_flags = flags;
3932 +       inode->i_vflags = vflags;
3933 +       jfs_get_inode_flags(JFS_IP(inode));
3934 +       inode->i_ctime = CURRENT_TIME_SEC;
3935 +       mark_inode_dirty(inode);
3936 +       return 0;
3937 +}
3938 +
3939  long jfs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
3940  {
3941         struct inode *inode = filp->f_dentry->d_inode;
3942 @@ -85,6 +96,11 @@ long jfs_ioctl(struct file *filp, unsign
3943                 if (!S_ISDIR(inode->i_mode))
3944                         flags &= ~JFS_DIRSYNC_FL;
3945  
3946 +               if (IS_BARRIER(inode)) {
3947 +                       vxwprintk_task(1, "messing with the barrier.");
3948 +                       return -EACCES;
3949 +               }
3950 +
3951                 /* Is it quota file? Do not allow user to mess with it */
3952                 if (IS_NOQUOTA(inode)) {
3953                         err = -EPERM;
3954 @@ -102,8 +118,8 @@ long jfs_ioctl(struct file *filp, unsign
3955                  * the relevant capability.
3956                  */
3957                 if ((oldflags & JFS_IMMUTABLE_FL) ||
3958 -                       ((flags ^ oldflags) &
3959 -                       (JFS_APPEND_FL | JFS_IMMUTABLE_FL))) {
3960 +                       ((flags ^ oldflags) & (JFS_APPEND_FL |
3961 +                       JFS_IMMUTABLE_FL | JFS_IXUNLINK_FL))) {
3962                         if (!capable(CAP_LINUX_IMMUTABLE)) {
3963                                 mutex_unlock(&inode->i_mutex);
3964                                 err = -EPERM;
3965 @@ -111,7 +127,7 @@ long jfs_ioctl(struct file *filp, unsign
3966                         }
3967                 }
3968  
3969 -               flags = flags & JFS_FL_USER_MODIFIABLE;
3970 +               flags &= JFS_FL_USER_MODIFIABLE;
3971                 flags |= oldflags & ~JFS_FL_USER_MODIFIABLE;
3972                 jfs_inode->mode2 = flags;
3973  
3974 diff -NurpP --minimal linux-3.0.25/fs/jfs/jfs_dinode.h linux-3.0.25-vs2.3.2.3/fs/jfs/jfs_dinode.h
3975 --- linux-3.0.25/fs/jfs/jfs_dinode.h    2008-12-25 00:26:37.000000000 +0100
3976 +++ linux-3.0.25-vs2.3.2.3/fs/jfs/jfs_dinode.h  2011-06-10 22:11:24.000000000 +0200
3977 @@ -161,9 +161,13 @@ struct dinode {
3978  
3979  #define JFS_APPEND_FL          0x01000000 /* writes to file may only append */
3980  #define JFS_IMMUTABLE_FL       0x02000000 /* Immutable file */
3981 +#define JFS_IXUNLINK_FL                0x08000000 /* Immutable invert on unlink */
3982  
3983 -#define JFS_FL_USER_VISIBLE    0x03F80000
3984 -#define JFS_FL_USER_MODIFIABLE 0x03F80000
3985 +#define JFS_BARRIER_FL         0x04000000 /* Barrier for chroot() */
3986 +#define JFS_COW_FL             0x20000000 /* Copy on Write marker */
3987 +
3988 +#define JFS_FL_USER_VISIBLE    0x07F80000
3989 +#define JFS_FL_USER_MODIFIABLE 0x07F80000
3990  #define JFS_FL_INHERIT         0x03C80000
3991  
3992  /* These are identical to EXT[23]_IOC_GETFLAGS/SETFLAGS */
3993 diff -NurpP --minimal linux-3.0.25/fs/jfs/jfs_filsys.h linux-3.0.25-vs2.3.2.3/fs/jfs/jfs_filsys.h
3994 --- linux-3.0.25/fs/jfs/jfs_filsys.h    2008-12-25 00:26:37.000000000 +0100
3995 +++ linux-3.0.25-vs2.3.2.3/fs/jfs/jfs_filsys.h  2011-06-10 22:11:24.000000000 +0200
3996 @@ -263,6 +263,7 @@
3997  #define JFS_NAME_MAX   255
3998  #define JFS_PATH_MAX   BPSIZE
3999  
4000 +#define JFS_TAGGED             0x00800000      /* Context Tagging */
4001  
4002  /*
4003   *     file system state (superblock state)
4004 diff -NurpP --minimal linux-3.0.25/fs/jfs/jfs_imap.c linux-3.0.25-vs2.3.2.3/fs/jfs/jfs_imap.c
4005 --- linux-3.0.25/fs/jfs/jfs_imap.c      2011-07-22 11:18:05.000000000 +0200
4006 +++ linux-3.0.25-vs2.3.2.3/fs/jfs/jfs_imap.c    2011-07-01 11:35:34.000000000 +0200
4007 @@ -46,6 +46,7 @@
4008  #include <linux/pagemap.h>
4009  #include <linux/quotaops.h>
4010  #include <linux/slab.h>
4011 +#include <linux/vs_tag.h>
4012  
4013  #include "jfs_incore.h"
4014  #include "jfs_inode.h"
4015 @@ -3058,6 +3059,8 @@ static int copy_from_dinode(struct dinod
4016  {
4017         struct jfs_inode_info *jfs_ip = JFS_IP(ip);
4018         struct jfs_sb_info *sbi = JFS_SBI(ip->i_sb);
4019 +       uid_t uid;
4020 +       gid_t gid;
4021  
4022         jfs_ip->fileset = le32_to_cpu(dip->di_fileset);
4023         jfs_ip->mode2 = le32_to_cpu(dip->di_mode);
4024 @@ -3078,14 +3081,18 @@ static int copy_from_dinode(struct dinod
4025         }
4026         ip->i_nlink = le32_to_cpu(dip->di_nlink);
4027  
4028 -       jfs_ip->saved_uid = le32_to_cpu(dip->di_uid);
4029 +       uid = le32_to_cpu(dip->di_uid);
4030 +       gid = le32_to_cpu(dip->di_gid);
4031 +       ip->i_tag = INOTAG_TAG(DX_TAG(ip), uid, gid, 0);
4032 +
4033 +       jfs_ip->saved_uid = INOTAG_UID(DX_TAG(ip), uid, gid);
4034         if (sbi->uid == -1)
4035                 ip->i_uid = jfs_ip->saved_uid;
4036         else {
4037                 ip->i_uid = sbi->uid;
4038         }
4039  
4040 -       jfs_ip->saved_gid = le32_to_cpu(dip->di_gid);
4041 +       jfs_ip->saved_gid = INOTAG_GID(DX_TAG(ip), uid, gid);
4042         if (sbi->gid == -1)
4043                 ip->i_gid = jfs_ip->saved_gid;
4044         else {
4045 @@ -3150,14 +3157,12 @@ static void copy_to_dinode(struct dinode
4046         dip->di_size = cpu_to_le64(ip->i_size);
4047         dip->di_nblocks = cpu_to_le64(PBLK2LBLK(ip->i_sb, ip->i_blocks));
4048         dip->di_nlink = cpu_to_le32(ip->i_nlink);
4049 -       if (sbi->uid == -1)
4050 -               dip->di_uid = cpu_to_le32(ip->i_uid);
4051 -       else
4052 -               dip->di_uid = cpu_to_le32(jfs_ip->saved_uid);
4053 -       if (sbi->gid == -1)
4054 -               dip->di_gid = cpu_to_le32(ip->i_gid);
4055 -       else
4056 -               dip->di_gid = cpu_to_le32(jfs_ip->saved_gid);
4057 +
4058 +       dip->di_uid = cpu_to_le32(TAGINO_UID(DX_TAG(ip),
4059 +               (sbi->uid == -1) ? ip->i_uid : jfs_ip->saved_uid, ip->i_tag));
4060 +       dip->di_gid = cpu_to_le32(TAGINO_GID(DX_TAG(ip),
4061 +               (sbi->gid == -1) ? ip->i_gid : jfs_ip->saved_gid, ip->i_tag));
4062 +
4063         jfs_get_inode_flags(jfs_ip);
4064         /*
4065          * mode2 is only needed for storing the higher order bits.
4066 diff -NurpP --minimal linux-3.0.25/fs/jfs/jfs_inode.c linux-3.0.25-vs2.3.2.3/fs/jfs/jfs_inode.c
4067 --- linux-3.0.25/fs/jfs/jfs_inode.c     2010-08-02 16:52:49.000000000 +0200
4068 +++ linux-3.0.25-vs2.3.2.3/fs/jfs/jfs_inode.c   2011-06-10 22:11:24.000000000 +0200
4069 @@ -18,6 +18,7 @@
4070  
4071  #include <linux/fs.h>
4072  #include <linux/quotaops.h>
4073 +#include <linux/vs_tag.h>
4074  #include "jfs_incore.h"
4075  #include "jfs_inode.h"
4076  #include "jfs_filsys.h"
4077 @@ -30,29 +31,46 @@ void jfs_set_inode_flags(struct inode *i
4078  {
4079         unsigned int flags = JFS_IP(inode)->mode2;
4080  
4081 -       inode->i_flags &= ~(S_IMMUTABLE | S_APPEND |
4082 -               S_NOATIME | S_DIRSYNC | S_SYNC);
4083 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
4084 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
4085  
4086         if (flags & JFS_IMMUTABLE_FL)
4087                 inode->i_flags |= S_IMMUTABLE;
4088 +       if (flags & JFS_IXUNLINK_FL)
4089 +               inode->i_flags |= S_IXUNLINK;
4090 +
4091 +       if (flags & JFS_SYNC_FL)
4092 +               inode->i_flags |= S_SYNC;
4093         if (flags & JFS_APPEND_FL)
4094                 inode->i_flags |= S_APPEND;
4095         if (flags & JFS_NOATIME_FL)
4096                 inode->i_flags |= S_NOATIME;
4097         if (flags & JFS_DIRSYNC_FL)
4098                 inode->i_flags |= S_DIRSYNC;
4099 -       if (flags & JFS_SYNC_FL)
4100 -               inode->i_flags |= S_SYNC;
4101 +
4102 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
4103 +
4104 +       if (flags & JFS_BARRIER_FL)
4105 +               inode->i_vflags |= V_BARRIER;
4106 +       if (flags & JFS_COW_FL)
4107 +               inode->i_vflags |= V_COW;
4108  }
4109  
4110  void jfs_get_inode_flags(struct jfs_inode_info *jfs_ip)
4111  {
4112         unsigned int flags = jfs_ip->vfs_inode.i_flags;
4113 +       unsigned int vflags = jfs_ip->vfs_inode.i_vflags;
4114 +
4115 +       jfs_ip->mode2 &= ~(JFS_IMMUTABLE_FL | JFS_IXUNLINK_FL |
4116 +                          JFS_APPEND_FL | JFS_NOATIME_FL |
4117 +                          JFS_DIRSYNC_FL | JFS_SYNC_FL |
4118 +                          JFS_BARRIER_FL | JFS_COW_FL);
4119  
4120 -       jfs_ip->mode2 &= ~(JFS_IMMUTABLE_FL | JFS_APPEND_FL | JFS_NOATIME_FL |
4121 -                          JFS_DIRSYNC_FL | JFS_SYNC_FL);
4122         if (flags & S_IMMUTABLE)
4123                 jfs_ip->mode2 |= JFS_IMMUTABLE_FL;
4124 +       if (flags & S_IXUNLINK)
4125 +               jfs_ip->mode2 |= JFS_IXUNLINK_FL;
4126 +
4127         if (flags & S_APPEND)
4128                 jfs_ip->mode2 |= JFS_APPEND_FL;
4129         if (flags & S_NOATIME)
4130 @@ -61,6 +79,11 @@ void jfs_get_inode_flags(struct jfs_inod
4131                 jfs_ip->mode2 |= JFS_DIRSYNC_FL;
4132         if (flags & S_SYNC)
4133                 jfs_ip->mode2 |= JFS_SYNC_FL;
4134 +
4135 +       if (vflags & V_BARRIER)
4136 +               jfs_ip->mode2 |= JFS_BARRIER_FL;
4137 +       if (vflags & V_COW)
4138 +               jfs_ip->mode2 |= JFS_COW_FL;
4139  }
4140  
4141  /*
4142 diff -NurpP --minimal linux-3.0.25/fs/jfs/jfs_inode.h linux-3.0.25-vs2.3.2.3/fs/jfs/jfs_inode.h
4143 --- linux-3.0.25/fs/jfs/jfs_inode.h     2011-07-22 11:18:05.000000000 +0200
4144 +++ linux-3.0.25-vs2.3.2.3/fs/jfs/jfs_inode.h   2011-06-10 22:11:24.000000000 +0200
4145 @@ -39,6 +39,7 @@ extern struct dentry *jfs_fh_to_dentry(s
4146  extern struct dentry *jfs_fh_to_parent(struct super_block *sb, struct fid *fid,
4147         int fh_len, int fh_type);
4148  extern void jfs_set_inode_flags(struct inode *);
4149 +extern int jfs_sync_flags(struct inode *, int, int);
4150  extern int jfs_get_block(struct inode *, sector_t, struct buffer_head *, int);
4151  extern int jfs_setattr(struct dentry *, struct iattr *);
4152  
4153 diff -NurpP --minimal linux-3.0.25/fs/jfs/namei.c linux-3.0.25-vs2.3.2.3/fs/jfs/namei.c
4154 --- linux-3.0.25/fs/jfs/namei.c 2011-05-22 16:17:53.000000000 +0200
4155 +++ linux-3.0.25-vs2.3.2.3/fs/jfs/namei.c       2011-06-10 22:11:24.000000000 +0200
4156 @@ -22,6 +22,7 @@
4157  #include <linux/ctype.h>
4158  #include <linux/quotaops.h>
4159  #include <linux/exportfs.h>
4160 +#include <linux/vs_tag.h>
4161  #include "jfs_incore.h"
4162  #include "jfs_superblock.h"
4163  #include "jfs_inode.h"
4164 @@ -1486,6 +1487,7 @@ static struct dentry *jfs_lookup(struct 
4165                 return ERR_CAST(ip);
4166         }
4167  
4168 +       dx_propagate_tag(nd, ip);
4169         return d_splice_alias(ip, dentry);
4170  }
4171  
4172 @@ -1550,6 +1552,7 @@ const struct inode_operations jfs_dir_in
4173  #ifdef CONFIG_JFS_POSIX_ACL
4174         .check_acl      = jfs_check_acl,
4175  #endif
4176 +       .sync_flags     = jfs_sync_flags,
4177  };
4178  
4179  const struct file_operations jfs_dir_operations = {
4180 diff -NurpP --minimal linux-3.0.25/fs/jfs/super.c linux-3.0.25-vs2.3.2.3/fs/jfs/super.c
4181 --- linux-3.0.25/fs/jfs/super.c 2011-05-22 16:17:53.000000000 +0200
4182 +++ linux-3.0.25-vs2.3.2.3/fs/jfs/super.c       2011-06-10 22:11:24.000000000 +0200
4183 @@ -198,7 +198,8 @@ static void jfs_put_super(struct super_b
4184  enum {
4185         Opt_integrity, Opt_nointegrity, Opt_iocharset, Opt_resize,
4186         Opt_resize_nosize, Opt_errors, Opt_ignore, Opt_err, Opt_quota,
4187 -       Opt_usrquota, Opt_grpquota, Opt_uid, Opt_gid, Opt_umask
4188 +       Opt_usrquota, Opt_grpquota, Opt_uid, Opt_gid, Opt_umask,
4189 +       Opt_tag, Opt_notag, Opt_tagid
4190  };
4191  
4192  static const match_table_t tokens = {
4193 @@ -208,6 +209,10 @@ static const match_table_t tokens = {
4194         {Opt_resize, "resize=%u"},
4195         {Opt_resize_nosize, "resize"},
4196         {Opt_errors, "errors=%s"},
4197 +       {Opt_tag, "tag"},
4198 +       {Opt_notag, "notag"},
4199 +       {Opt_tagid, "tagid=%u"},
4200 +       {Opt_tag, "tagxid"},
4201         {Opt_ignore, "noquota"},
4202         {Opt_ignore, "quota"},
4203         {Opt_usrquota, "usrquota"},
4204 @@ -342,6 +347,20 @@ static int parse_options(char *options, 
4205                         }
4206                         break;
4207                 }
4208 +#ifndef CONFIG_TAGGING_NONE
4209 +               case Opt_tag:
4210 +                       *flag |= JFS_TAGGED;
4211 +                       break;
4212 +               case Opt_notag:
4213 +                       *flag &= JFS_TAGGED;
4214 +                       break;
4215 +#endif
4216 +#ifdef CONFIG_PROPAGATE
4217 +               case Opt_tagid:
4218 +                       /* use args[0] */
4219 +                       *flag |= JFS_TAGGED;
4220 +                       break;
4221 +#endif
4222                 default:
4223                         printk("jfs: Unrecognized mount option \"%s\" "
4224                                         " or missing value\n", p);
4225 @@ -373,6 +392,12 @@ static int jfs_remount(struct super_bloc
4226                 return -EINVAL;
4227         }
4228  
4229 +       if ((flag & JFS_TAGGED) && !(sb->s_flags & MS_TAGGED)) {
4230 +               printk(KERN_ERR "JFS: %s: tagging not permitted on remount.\n",
4231 +                       sb->s_id);
4232 +               return -EINVAL;
4233 +       }
4234 +
4235         if (newLVSize) {
4236                 if (sb->s_flags & MS_RDONLY) {
4237                         printk(KERN_ERR
4238 @@ -455,6 +480,9 @@ static int jfs_fill_super(struct super_b
4239  #ifdef CONFIG_JFS_POSIX_ACL
4240         sb->s_flags |= MS_POSIXACL;
4241  #endif
4242 +       /* map mount option tagxid */
4243 +       if (sbi->flag & JFS_TAGGED)
4244 +               sb->s_flags |= MS_TAGGED;
4245  
4246         if (newLVSize) {
4247                 printk(KERN_ERR "resize option for remount only\n");
4248 diff -NurpP --minimal linux-3.0.25/fs/libfs.c linux-3.0.25-vs2.3.2.3/fs/libfs.c
4249 --- linux-3.0.25/fs/libfs.c     2011-07-22 11:18:05.000000000 +0200
4250 +++ linux-3.0.25-vs2.3.2.3/fs/libfs.c   2011-07-22 11:20:39.000000000 +0200
4251 @@ -133,7 +133,8 @@ static inline unsigned char dt_type(stru
4252   * both impossible due to the lock on directory.
4253   */
4254  
4255 -int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
4256 +static inline int do_dcache_readdir_filter(struct file *filp,
4257 +       void *dirent, filldir_t filldir, int (*filter)(struct dentry *dentry))
4258  {
4259         struct dentry *dentry = filp->f_path.dentry;
4260         struct dentry *cursor = filp->private_data;
4261 @@ -164,6 +165,8 @@ int dcache_readdir(struct file * filp, v
4262                         for (p=q->next; p != &dentry->d_subdirs; p=p->next) {
4263                                 struct dentry *next;
4264                                 next = list_entry(p, struct dentry, d_u.d_child);
4265 +                               if (filter && !filter(next))
4266 +                                       continue;
4267                                 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
4268                                 if (!simple_positive(next)) {
4269                                         spin_unlock(&next->d_lock);
4270 @@ -190,6 +193,17 @@ int dcache_readdir(struct file * filp, v
4271         return 0;
4272  }
4273  
4274 +int dcache_readdir(struct file *filp, void *dirent, filldir_t filldir)
4275 +{
4276 +       return do_dcache_readdir_filter(filp, dirent, filldir, NULL);
4277 +}
4278 +
4279 +int dcache_readdir_filter(struct file *filp, void *dirent, filldir_t filldir,
4280 +       int (*filter)(struct dentry *))
4281 +{
4282 +       return do_dcache_readdir_filter(filp, dirent, filldir, filter);
4283 +}
4284 +
4285  ssize_t generic_read_dir(struct file *filp, char __user *buf, size_t siz, loff_t *ppos)
4286  {
4287         return -EISDIR;
4288 @@ -965,6 +979,7 @@ EXPORT_SYMBOL(dcache_dir_close);
4289  EXPORT_SYMBOL(dcache_dir_lseek);
4290  EXPORT_SYMBOL(dcache_dir_open);
4291  EXPORT_SYMBOL(dcache_readdir);
4292 +EXPORT_SYMBOL(dcache_readdir_filter);
4293  EXPORT_SYMBOL(generic_read_dir);
4294  EXPORT_SYMBOL(mount_pseudo);
4295  EXPORT_SYMBOL(simple_write_begin);
4296 diff -NurpP --minimal linux-3.0.25/fs/locks.c linux-3.0.25-vs2.3.2.3/fs/locks.c
4297 --- linux-3.0.25/fs/locks.c     2011-07-22 11:18:05.000000000 +0200
4298 +++ linux-3.0.25-vs2.3.2.3/fs/locks.c   2011-07-19 00:51:58.000000000 +0200
4299 @@ -126,6 +126,8 @@
4300  #include <linux/time.h>
4301  #include <linux/rcupdate.h>
4302  #include <linux/pid_namespace.h>
4303 +#include <linux/vs_base.h>
4304 +#include <linux/vs_limit.h>
4305  
4306  #include <asm/uaccess.h>
4307  
4308 @@ -171,13 +173,19 @@ static void locks_init_lock_always(struc
4309         fl->fl_flags = 0;
4310         fl->fl_type = 0;
4311         fl->fl_start = fl->fl_end = 0;
4312 +       fl->fl_xid = -1;
4313  }
4314  
4315 +
4316  /* Allocate an empty lock structure. */
4317  struct file_lock *locks_alloc_lock(void)
4318  {
4319 -       struct file_lock *fl = kmem_cache_alloc(filelock_cache, GFP_KERNEL);
4320 +       struct file_lock *fl;
4321 +
4322 +       if (!vx_locks_avail(1))
4323 +               return NULL;
4324  
4325 +       fl = kmem_cache_alloc(filelock_cache, GFP_KERNEL);
4326         if (fl)
4327                 locks_init_lock_always(fl);
4328  
4329 @@ -208,6 +216,7 @@ void locks_free_lock(struct file_lock *f
4330         BUG_ON(!list_empty(&fl->fl_block));
4331         BUG_ON(!list_empty(&fl->fl_link));
4332  
4333 +       vx_locks_dec(fl);
4334         locks_release_private(fl);
4335         kmem_cache_free(filelock_cache, fl);
4336  }
4337 @@ -272,6 +281,7 @@ void locks_copy_lock(struct file_lock *n
4338         new->fl_file = fl->fl_file;
4339         new->fl_ops = fl->fl_ops;
4340         new->fl_lmops = fl->fl_lmops;
4341 +       new->fl_xid = fl->fl_xid;
4342  
4343         locks_copy_private(new, fl);
4344  }
4345 @@ -310,6 +320,11 @@ static int flock_make_lock(struct file *
4346         fl->fl_flags = FL_FLOCK;
4347         fl->fl_type = type;
4348         fl->fl_end = OFFSET_MAX;
4349 +
4350 +       vxd_assert(filp->f_xid == vx_current_xid(),
4351 +               "f_xid(%d) == current(%d)", filp->f_xid, vx_current_xid());
4352 +       fl->fl_xid = filp->f_xid;
4353 +       vx_locks_inc(fl);
4354         
4355         *lock = fl;
4356         return 0;
4357 @@ -459,6 +474,7 @@ static int lease_init(struct file *filp,
4358  
4359         fl->fl_owner = current->files;
4360         fl->fl_pid = current->tgid;
4361 +       fl->fl_xid = vx_current_xid();
4362  
4363         fl->fl_file = filp;
4364         fl->fl_flags = FL_LEASE;
4365 @@ -478,6 +494,11 @@ static struct file_lock *lease_alloc(str
4366         if (fl == NULL)
4367                 return ERR_PTR(error);
4368  
4369 +       fl->fl_xid = vx_current_xid();
4370 +       if (filp)
4371 +               vxd_assert(filp->f_xid == fl->fl_xid,
4372 +                       "f_xid(%d) == fl_xid(%d)", filp->f_xid, fl->fl_xid);
4373 +       vx_locks_inc(fl);
4374         error = lease_init(filp, type, fl);
4375         if (error) {
4376                 locks_free_lock(fl);
4377 @@ -779,6 +800,7 @@ static int flock_lock_file(struct file *
4378                 lock_flocks();
4379         }
4380  
4381 +       new_fl->fl_xid = -1;
4382  find_conflict:
4383         for_each_lock(inode, before) {
4384                 struct file_lock *fl = *before;
4385 @@ -799,6 +821,7 @@ find_conflict:
4386                 goto out;
4387         locks_copy_lock(new_fl, request);
4388         locks_insert_lock(before, new_fl);
4389 +       vx_locks_inc(new_fl);
4390         new_fl = NULL;
4391         error = 0;
4392  
4393 @@ -809,7 +832,8 @@ out:
4394         return error;
4395  }
4396  
4397 -static int __posix_lock_file(struct inode *inode, struct file_lock *request, struct file_lock *conflock)
4398 +static int __posix_lock_file(struct inode *inode, struct file_lock *request,
4399 +       struct file_lock *conflock, xid_t xid)
4400  {
4401         struct file_lock *fl;
4402         struct file_lock *new_fl = NULL;
4403 @@ -819,6 +843,8 @@ static int __posix_lock_file(struct inod
4404         struct file_lock **before;
4405         int error, added = 0;
4406  
4407 +       vxd_assert(xid == vx_current_xid(),
4408 +               "xid(%d) == current(%d)", xid, vx_current_xid());
4409         /*
4410          * We may need two file_lock structures for this operation,
4411          * so we get them in advance to avoid races.
4412 @@ -829,7 +855,11 @@ static int __posix_lock_file(struct inod
4413             (request->fl_type != F_UNLCK ||
4414              request->fl_start != 0 || request->fl_end != OFFSET_MAX)) {
4415                 new_fl = locks_alloc_lock();
4416 +               new_fl->fl_xid = xid;
4417 +               vx_locks_inc(new_fl);
4418                 new_fl2 = locks_alloc_lock();
4419 +               new_fl2->fl_xid = xid;
4420 +               vx_locks_inc(new_fl2);
4421         }
4422  
4423         lock_flocks();
4424 @@ -1028,7 +1058,8 @@ static int __posix_lock_file(struct inod
4425  int posix_lock_file(struct file *filp, struct file_lock *fl,
4426                         struct file_lock *conflock)
4427  {
4428 -       return __posix_lock_file(filp->f_path.dentry->d_inode, fl, conflock);
4429 +       return __posix_lock_file(filp->f_path.dentry->d_inode,
4430 +               fl, conflock, filp->f_xid);
4431  }
4432  EXPORT_SYMBOL(posix_lock_file);
4433  
4434 @@ -1118,7 +1149,7 @@ int locks_mandatory_area(int read_write,
4435         fl.fl_end = offset + count - 1;
4436  
4437         for (;;) {
4438 -               error = __posix_lock_file(inode, &fl, NULL);
4439 +               error = __posix_lock_file(inode, &fl, NULL, filp->f_xid);
4440                 if (error != FILE_LOCK_DEFERRED)
4441                         break;
4442                 error = wait_event_interruptible(fl.fl_wait, !fl.fl_next);
4443 @@ -1431,6 +1462,7 @@ int generic_setlease(struct file *filp, 
4444                 goto out;
4445  
4446         locks_insert_lock(before, lease);
4447 +       vx_locks_inc(lease);
4448         return 0;
4449  
4450  out:
4451 @@ -1815,6 +1847,11 @@ int fcntl_setlk(unsigned int fd, struct 
4452         if (file_lock == NULL)
4453                 return -ENOLCK;
4454  
4455 +       vxd_assert(filp->f_xid == vx_current_xid(),
4456 +               "f_xid(%d) == current(%d)", filp->f_xid, vx_current_xid());
4457 +       file_lock->fl_xid = filp->f_xid;
4458 +       vx_locks_inc(file_lock);
4459 +
4460         /*
4461          * This might block, so we do it before checking the inode.
4462          */
4463 @@ -1933,6 +1970,11 @@ int fcntl_setlk64(unsigned int fd, struc
4464         if (file_lock == NULL)
4465                 return -ENOLCK;
4466  
4467 +       vxd_assert(filp->f_xid == vx_current_xid(),
4468 +               "f_xid(%d) == current(%d)", filp->f_xid, vx_current_xid());
4469 +       file_lock->fl_xid = filp->f_xid;
4470 +       vx_locks_inc(file_lock);
4471 +
4472         /*
4473          * This might block, so we do it before checking the inode.
4474          */
4475 @@ -2198,8 +2240,11 @@ static int locks_show(struct seq_file *f
4476  
4477         lock_get_status(f, fl, *((loff_t *)f->private), "");
4478  
4479 -       list_for_each_entry(bfl, &fl->fl_block, fl_block)
4480 +       list_for_each_entry(bfl, &fl->fl_block, fl_block) {
4481 +               if (!vx_check(fl->fl_xid, VS_WATCH_P | VS_IDENT))
4482 +                       continue;
4483                 lock_get_status(f, bfl, *((loff_t *)f->private), " ->");
4484 +       }
4485  
4486         return 0;
4487  }
4488 diff -NurpP --minimal linux-3.0.25/fs/namei.c linux-3.0.25-vs2.3.2.3/fs/namei.c
4489 --- linux-3.0.25/fs/namei.c     2012-03-19 21:16:51.000000000 +0100
4490 +++ linux-3.0.25-vs2.3.2.3/fs/namei.c   2012-03-23 14:54:00.000000000 +0100
4491 @@ -32,6 +32,14 @@
4492  #include <linux/fcntl.h>
4493  #include <linux/device_cgroup.h>
4494  #include <linux/fs_struct.h>
4495 +#include <linux/proc_fs.h>
4496 +#include <linux/vserver/inode.h>
4497 +#include <linux/vs_base.h>
4498 +#include <linux/vs_tag.h>
4499 +#include <linux/vs_cowbl.h>
4500 +#include <linux/vs_device.h>
4501 +#include <linux/vs_context.h>
4502 +#include <linux/pid_namespace.h>
4503  #include <asm/uaccess.h>
4504  
4505  #include "internal.h"
4506 @@ -175,6 +183,89 @@ void putname(const char *name)
4507  EXPORT_SYMBOL(putname);
4508  #endif
4509  
4510 +static inline int dx_barrier(const struct inode *inode)
4511 +{
4512 +       if (IS_BARRIER(inode) && !vx_check(0, VS_ADMIN | VS_WATCH)) {
4513 +               vxwprintk_task(1, "did hit the barrier.");
4514 +               return 1;
4515 +       }
4516 +       return 0;
4517 +}
4518 +
4519 +static int __dx_permission(const struct inode *inode, int mask)
4520 +{
4521 +       if (dx_barrier(inode))
4522 +               return -EACCES;
4523 +
4524 +       if (inode->i_sb->s_magic == DEVPTS_SUPER_MAGIC) {
4525 +               /* devpts is xid tagged */
4526 +               if (S_ISDIR(inode->i_mode) ||
4527 +                   vx_check((xid_t)inode->i_tag, VS_IDENT | VS_WATCH_P))
4528 +                       return 0;
4529 +
4530 +               /* just pretend we didn't find anything */
4531 +               return -ENOENT;
4532 +       }
4533 +       else if (inode->i_sb->s_magic == PROC_SUPER_MAGIC) {
4534 +               struct proc_dir_entry *de = PDE(inode);
4535 +
4536 +               if (de && !vx_hide_check(0, de->vx_flags))
4537 +                       goto out;
4538 +
4539 +               if ((mask & (MAY_WRITE | MAY_APPEND))) {
4540 +                       struct pid *pid;
4541 +                       struct task_struct *tsk;
4542 +
4543 +                       if (vx_check(0, VS_ADMIN | VS_WATCH_P) ||
4544 +                           vx_flags(VXF_STATE_SETUP, 0))
4545 +                               return 0;
4546 +
4547 +                       pid = PROC_I(inode)->pid;
4548 +                       if (!pid)
4549 +                               goto out;
4550 +
4551 +                       rcu_read_lock();
4552 +                       tsk = pid_task(pid, PIDTYPE_PID);
4553 +                       vxdprintk(VXD_CBIT(tag, 0), "accessing %p[#%u]",
4554 +                                 tsk, (tsk ? vx_task_xid(tsk) : 0));
4555 +                       if (tsk &&
4556 +                               vx_check(vx_task_xid(tsk), VS_IDENT | VS_WATCH_P)) {
4557 +                               rcu_read_unlock();
4558 +                               return 0;
4559 +                       }
4560 +                       rcu_read_unlock();
4561 +               }
4562 +               else {
4563 +                       /* FIXME: Should we block some entries here? */
4564 +                       return 0;
4565 +               }
4566 +       }
4567 +       else {
4568 +               if (dx_notagcheck(inode->i_sb) ||
4569 +                   dx_check(inode->i_tag, DX_HOSTID | DX_ADMIN | DX_WATCH |
4570 +                            DX_IDENT))
4571 +                       return 0;
4572 +       }
4573 +
4574 +out:
4575 +       return -EACCES;
4576 +}
4577 +
4578 +int dx_permission(const struct inode *inode, int mask)
4579 +{
4580 +       int ret = __dx_permission(inode, mask);
4581 +       if (unlikely(ret)) {
4582 +#ifndef        CONFIG_VSERVER_WARN_DEVPTS
4583 +               if (inode->i_sb->s_magic != DEVPTS_SUPER_MAGIC)
4584 +#endif
4585 +                   vxwprintk_task(1,
4586 +                       "denied [0x%x] access to inode %s:%p[#%d,%lu]",
4587 +                       mask, inode->i_sb->s_id, inode, inode->i_tag,
4588 +                       inode->i_ino);
4589 +       }
4590 +       return ret;
4591 +}
4592 +
4593  /*
4594   * This does basic POSIX ACL permission checking
4595   */
4596 @@ -285,10 +376,14 @@ int inode_permission(struct inode *inode
4597                 /*
4598                  * Nobody gets write access to an immutable file.
4599                  */
4600 -               if (IS_IMMUTABLE(inode))
4601 +               if (IS_IMMUTABLE(inode) && !IS_COW(inode))
4602                         return -EACCES;
4603         }
4604  
4605 +       retval = dx_permission(inode, mask);
4606 +       if (retval)
4607 +               return retval;
4608 +
4609         if (inode->i_op->permission)
4610                 retval = inode->i_op->permission(inode, mask, 0);
4611         else
4612 @@ -584,6 +679,9 @@ static inline int exec_permission(struct
4613         int ret;
4614         struct user_namespace *ns = inode_userns(inode);
4615  
4616 +       if (dx_barrier(inode))
4617 +               return -EACCES;
4618 +
4619         if (inode->i_op->permission) {
4620                 ret = inode->i_op->permission(inode, MAY_EXEC, flags);
4621         } else {
4622 @@ -1095,7 +1193,8 @@ static void follow_dotdot(struct nameida
4623  
4624                 if (nd->path.dentry == nd->root.dentry &&
4625                     nd->path.mnt == nd->root.mnt) {
4626 -                       break;
4627 +                       /* for sane '/' avoid follow_mount() */
4628 +                       return;
4629                 }
4630                 if (nd->path.dentry != nd->path.mnt->mnt_root) {
4631                         /* rare case of legitimate dget_parent()... */
4632 @@ -1178,6 +1277,9 @@ static int do_lookup(struct nameidata *n
4633                                 goto unlazy;
4634                         }
4635                 }
4636 +
4637 +               /* FIXME: check dx permission */
4638 +
4639                 path->mnt = mnt;
4640                 path->dentry = dentry;
4641                 if (unlikely(!__follow_mount_rcu(nd, path, inode)))
4642 @@ -1226,6 +1328,8 @@ retry:
4643                 }
4644         }
4645  
4646 +       /* FIXME: check dx permission */
4647 +
4648         path->mnt = mnt;
4649         path->dentry = dentry;
4650         err = follow_managed(path, nd->flags);
4651 @@ -1853,7 +1957,7 @@ static int may_delete(struct inode *dir,
4652         if (IS_APPEND(dir))
4653                 return -EPERM;
4654         if (check_sticky(dir, victim->d_inode)||IS_APPEND(victim->d_inode)||
4655 -           IS_IMMUTABLE(victim->d_inode) || IS_SWAPFILE(victim->d_inode))
4656 +               IS_IXORUNLINK(victim->d_inode) || IS_SWAPFILE(victim->d_inode))
4657                 return -EPERM;
4658         if (isdir) {
4659                 if (!S_ISDIR(victim->d_inode->i_mode))
4660 @@ -1980,6 +2084,15 @@ static int may_open(struct path *path, i
4661                 break;
4662         }
4663  
4664 +#ifdef CONFIG_VSERVER_COWBL
4665 +       if (IS_COW(inode) &&
4666 +               ((flag & O_ACCMODE) != O_RDONLY)) {
4667 +               if (IS_COW_LINK(inode))
4668 +                       return -EMLINK;
4669 +               inode->i_flags &= ~(S_IXUNLINK|S_IMMUTABLE);
4670 +               mark_inode_dirty(inode);
4671 +       }
4672 +#endif
4673         error = inode_permission(inode, acc_mode);
4674         if (error)
4675                 return error;
4676 @@ -2224,6 +2337,16 @@ ok:
4677         }
4678  common:
4679         error = may_open(&nd->path, acc_mode, open_flag);
4680 +#ifdef CONFIG_VSERVER_COWBL
4681 +       if (error == -EMLINK) {
4682 +               struct dentry *dentry;
4683 +               dentry = cow_break_link(pathname);
4684 +               if (IS_ERR(dentry))
4685 +                       error = PTR_ERR(dentry);
4686 +               else
4687 +                       dput(dentry);
4688 +       }
4689 +#endif
4690         if (error)
4691                 goto exit;
4692         filp = nameidata_to_filp(nd);
4693 @@ -2266,6 +2389,7 @@ static struct file *path_openat(int dfd,
4694         struct path path;
4695         int error;
4696  
4697 +restart:
4698         filp = get_empty_filp();
4699         if (!filp)
4700                 return ERR_PTR(-ENFILE);
4701 @@ -2303,6 +2427,17 @@ static struct file *path_openat(int dfd,
4702                         filp = do_last(nd, &path, op, pathname);
4703                 put_link(nd, &link, cookie);
4704         }
4705 +
4706 +#ifdef CONFIG_VSERVER_COWBL
4707 +       if (filp == ERR_PTR(-EMLINK)) {
4708 +               if (nd->root.mnt && !(nd->flags & LOOKUP_ROOT))
4709 +                       path_put(&nd->root);
4710 +               if (base)
4711 +                       fput(base);
4712 +               release_open_intent(nd);
4713 +               goto restart;
4714 +       }
4715 +#endif
4716  out:
4717         if (nd->root.mnt && !(nd->flags & LOOKUP_ROOT))
4718                 path_put(&nd->root);
4719 @@ -2886,7 +3021,7 @@ int vfs_link(struct dentry *old_dentry, 
4720         /*
4721          * A link to an append-only or immutable file cannot be created.
4722          */
4723 -       if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
4724 +       if (IS_APPEND(inode) || IS_IXORUNLINK(inode))
4725                 return -EPERM;
4726         if (!dir->i_op->link)
4727                 return -EPERM;
4728 @@ -3274,6 +3409,227 @@ int vfs_follow_link(struct nameidata *nd
4729         return __vfs_follow_link(nd, link);
4730  }
4731  
4732 +
4733 +#ifdef CONFIG_VSERVER_COWBL
4734 +
4735 +static inline
4736 +long do_cow_splice(struct file *in, struct file *out, size_t len)
4737 +{
4738 +       loff_t ppos = 0;
4739 +
4740 +       return do_splice_direct(in, &ppos, out, len, 0);
4741 +}
4742 +
4743 +struct dentry *cow_break_link(const char *pathname)
4744 +{
4745 +       int ret, mode, pathlen, redo = 0;
4746 +       struct nameidata old_nd, dir_nd;
4747 +       struct path old_path;
4748 +       struct dentry *dir, *old_dentry, *new_dentry = NULL;
4749 +       struct file *old_file;
4750 +       struct file *new_file;
4751 +       char *to, *path, pad='\251';
4752 +       loff_t size;
4753 +
4754 +       vxdprintk(VXD_CBIT(misc, 1),
4755 +               "cow_break_link(" VS_Q("%s") ")", pathname);
4756 +       path = kmalloc(PATH_MAX, GFP_KERNEL);
4757 +       ret = -ENOMEM;
4758 +       if (!path)
4759 +               goto out;
4760 +
4761 +       /* old_nd will have refs to dentry and mnt */
4762 +       ret = do_path_lookup(AT_FDCWD, pathname, LOOKUP_FOLLOW, &old_nd);
4763 +       vxdprintk(VXD_CBIT(misc, 2),
4764 +               "do_path_lookup(old): %d [r=%d]",
4765 +               ret, mnt_get_count(old_nd.path.mnt));
4766 +       if (ret < 0)
4767 +               goto out_free_path;
4768 +
4769 +       old_path = old_nd.path;
4770 +       old_dentry = old_path.dentry;
4771 +       mode = old_dentry->d_inode->i_mode;
4772 +
4773 +       to = d_path(&old_path, path, PATH_MAX-2);
4774 +       pathlen = strlen(to);
4775 +       vxdprintk(VXD_CBIT(misc, 2),
4776 +               "old path " VS_Q("%s") " [%p:" VS_Q("%.*s") ":%d]", to,
4777 +               old_dentry,
4778 +               old_dentry->d_name.len, old_dentry->d_name.name,
4779 +               old_dentry->d_name.len);
4780 +
4781 +       to[pathlen + 1] = 0;
4782 +retry:
4783 +       new_dentry = NULL;
4784 +       to[pathlen] = pad--;
4785 +       ret = -ELOOP;
4786 +       if (pad <= '\240')
4787 +               goto out_rel_old;
4788 +
4789 +       vxdprintk(VXD_CBIT(misc, 1), "temp copy " VS_Q("%s"), to);
4790 +       /* dir_nd will have refs to dentry and mnt */
4791 +       ret = do_path_lookup(AT_FDCWD, to,
4792 +               LOOKUP_PARENT | LOOKUP_OPEN | LOOKUP_CREATE, &dir_nd);
4793 +       vxdprintk(VXD_CBIT(misc, 2), "do_path_lookup(new): %d", ret);
4794 +       if (ret < 0)
4795 +               goto retry;
4796 +
4797 +       /* this puppy downs the inode mutex */
4798 +       new_dentry = lookup_create(&dir_nd, 0);
4799 +       if (!new_dentry || IS_ERR(new_dentry)) {
4800 +               path_put(&dir_nd.path);
4801 +               vxdprintk(VXD_CBIT(misc, 2),
4802 +                       "lookup_create(new): failed with %ld",
4803 +                       PTR_ERR(new_dentry));
4804 +               mutex_unlock(&dir_nd.path.dentry->d_inode->i_mutex);
4805 +               goto retry;
4806 +       }
4807 +       vxdprintk(VXD_CBIT(misc, 2),
4808 +               "lookup_create(new): %p [" VS_Q("%.*s") ":%d]",
4809 +               new_dentry,
4810 +               new_dentry->d_name.len, new_dentry->d_name.name,
4811 +               new_dentry->d_name.len);
4812 +
4813 +       dir = dir_nd.path.dentry;
4814 +
4815 +       ret = vfs_create(dir->d_inode, new_dentry, mode, &dir_nd);
4816 +       vxdprintk(VXD_CBIT(misc, 2),
4817 +               "vfs_create(new): %d", ret);
4818 +       if (ret == -EEXIST) {
4819 +               mutex_unlock(&dir->d_inode->i_mutex);
4820 +               path_put(&dir_nd.path);
4821 +               dput(new_dentry);
4822 +               goto retry;
4823 +       }
4824 +       else if (ret < 0)
4825 +               goto out_unlock_new;
4826 +
4827 +       /* drop out early, ret passes ENOENT */
4828 +       ret = -ENOENT;
4829 +       if ((redo = d_unhashed(old_dentry)))
4830 +               goto out_unlock_new;
4831 +
4832 +       path_get(&old_path);
4833 +       /* this one cleans up the dentry/mnt in case of failure */
4834 +       old_file = dentry_open(old_dentry, old_path.mnt,
4835 +               O_RDONLY, current_cred());
4836 +       vxdprintk(VXD_CBIT(misc, 2),
4837 +               "dentry_open(old): %p", old_file);
4838 +       if (IS_ERR(old_file)) {
4839 +               ret = PTR_ERR(old_file);
4840 +               goto out_unlock_new;
4841 +       }
4842 +
4843 +       dget(new_dentry);
4844 +       mntget(old_path.mnt);
4845 +       /* this one cleans up the dentry/mnt in case of failure */
4846 +       new_file = dentry_open(new_dentry, old_path.mnt,
4847 +               O_WRONLY, current_cred());
4848 +       vxdprintk(VXD_CBIT(misc, 2),
4849 +               "dentry_open(new): %p", new_file);
4850 +       if (IS_ERR(new_file)) {
4851 +               ret = PTR_ERR(new_file);
4852 +               goto out_fput_old;
4853 +       }
4854 +
4855 +       size = i_size_read(old_file->f_dentry->d_inode);
4856 +       ret = do_cow_splice(old_file, new_file, size);
4857 +       vxdprintk(VXD_CBIT(misc, 2), "do_splice_direct: %d", ret);
4858 +       if (ret < 0) {
4859 +               goto out_fput_both;
4860 +       } else if (ret < size) {
4861 +               ret = -ENOSPC;
4862 +               goto out_fput_both;
4863 +       } else {
4864 +               struct inode *old_inode = old_dentry->d_inode;
4865 +               struct inode *new_inode = new_dentry->d_inode;
4866 +               struct iattr attr = {
4867 +                       .ia_uid = old_inode->i_uid,
4868 +                       .ia_gid = old_inode->i_gid,
4869 +                       .ia_valid = ATTR_UID | ATTR_GID
4870 +                       };
4871 +
4872 +               setattr_copy(new_inode, &attr);
4873 +               mark_inode_dirty(new_inode);
4874 +       }
4875 +
4876 +       mutex_lock(&old_dentry->d_inode->i_sb->s_vfs_rename_mutex);
4877 +
4878 +       /* drop out late */
4879 +       ret = -ENOENT;
4880 +       if ((redo = d_unhashed(old_dentry)))
4881 +               goto out_unlock;
4882 +
4883 +       vxdprintk(VXD_CBIT(misc, 2),
4884 +               "vfs_rename: [" VS_Q("%*s") ":%d] -> [" VS_Q("%*s") ":%d]",
4885 +               new_dentry->d_name.len, new_dentry->d_name.name,
4886 +               new_dentry->d_name.len,
4887 +               old_dentry->d_name.len, old_dentry->d_name.name,
4888 +               old_dentry->d_name.len);
4889 +       ret = vfs_rename(dir_nd.path.dentry->d_inode, new_dentry,
4890 +               old_dentry->d_parent->d_inode, old_dentry);
4891 +       vxdprintk(VXD_CBIT(misc, 2), "vfs_rename: %d", ret);
4892 +
4893 +out_unlock:
4894 +       mutex_unlock(&old_dentry->d_inode->i_sb->s_vfs_rename_mutex);
4895 +
4896 +out_fput_both:
4897 +       vxdprintk(VXD_CBIT(misc, 3),
4898 +               "fput(new_file=%p[#%ld])", new_file,
4899 +               atomic_long_read(&new_file->f_count));
4900 +       fput(new_file);
4901 +
4902 +out_fput_old:
4903 +       vxdprintk(VXD_CBIT(misc, 3),
4904 +               "fput(old_file=%p[#%ld])", old_file,
4905 +               atomic_long_read(&old_file->f_count));
4906 +       fput(old_file);
4907 +
4908 +out_unlock_new:
4909 +       mutex_unlock(&dir->d_inode->i_mutex);
4910 +       if (!ret)
4911 +               goto out_redo;
4912 +
4913 +       /* error path cleanup */
4914 +       vfs_unlink(dir->d_inode, new_dentry);
4915 +
4916 +out_redo:
4917 +       if (!redo)
4918 +               goto out_rel_both;
4919 +       /* lookup dentry once again */
4920 +       /* old_nd.path is freed as old_path in out_rel_old */
4921 +       ret = do_path_lookup(AT_FDCWD, pathname, LOOKUP_FOLLOW, &old_nd);
4922 +       if (ret)
4923 +               goto out_rel_both;
4924 +
4925 +       dput(new_dentry);
4926 +       new_dentry = old_nd.path.dentry;
4927 +       vxdprintk(VXD_CBIT(misc, 2),
4928 +               "do_path_lookup(redo): %p [" VS_Q("%.*s") ":%d]",
4929 +               new_dentry,
4930 +               new_dentry->d_name.len, new_dentry->d_name.name,
4931 +               new_dentry->d_name.len);
4932 +       dget(new_dentry);
4933 +
4934 +out_rel_both:
4935 +       path_put(&dir_nd.path);
4936 +out_rel_old:
4937 +       path_put(&old_path);
4938 +out_free_path:
4939 +       kfree(path);
4940 +out:
4941 +       if (ret) {
4942 +               dput(new_dentry);
4943 +               new_dentry = ERR_PTR(ret);
4944 +       }
4945 +       vxdprintk(VXD_CBIT(misc, 3),
4946 +               "cow_break_link returning with %p [r=%d]",
4947 +               new_dentry, mnt_get_count(old_nd.path.mnt));
4948 +       return new_dentry;
4949 +}
4950 +
4951 +#endif
4952 +
4953  /* get the link contents into pagecache */
4954  static char *page_getlink(struct dentry * dentry, struct page **ppage)
4955  {
4956 diff -NurpP --minimal linux-3.0.25/fs/namespace.c linux-3.0.25-vs2.3.2.3/fs/namespace.c
4957 --- linux-3.0.25/fs/namespace.c 2012-03-19 21:16:51.000000000 +0100
4958 +++ linux-3.0.25-vs2.3.2.3/fs/namespace.c       2011-12-23 16:09:00.000000000 +0100
4959 @@ -31,6 +31,11 @@
4960  #include <linux/idr.h>
4961  #include <linux/fs_struct.h>
4962  #include <linux/fsnotify.h>
4963 +#include <linux/vs_base.h>
4964 +#include <linux/vs_context.h>
4965 +#include <linux/vs_tag.h>
4966 +#include <linux/vserver/space.h>
4967 +#include <linux/vserver/global.h>
4968  #include <asm/uaccess.h>
4969  #include <asm/unistd.h>
4970  #include "pnode.h"
4971 @@ -679,6 +684,10 @@ vfs_kern_mount(struct file_system_type *
4972         if (!type)
4973                 return ERR_PTR(-ENODEV);
4974  
4975 +       if ((type->fs_flags & FS_BINARY_MOUNTDATA) &&
4976 +               !vx_capable(CAP_SYS_ADMIN, VXC_BINARY_MOUNT))
4977 +               return ERR_PTR(-EPERM);
4978 +
4979         mnt = alloc_vfsmnt(name);
4980         if (!mnt)
4981                 return ERR_PTR(-ENOMEM);
4982 @@ -724,6 +733,7 @@ static struct vfsmount *clone_mnt(struct
4983                 mnt->mnt_root = dget(root);
4984                 mnt->mnt_mountpoint = mnt->mnt_root;
4985                 mnt->mnt_parent = mnt;
4986 +               mnt->mnt_tag = old->mnt_tag;
4987  
4988                 if (flag & CL_SLAVE) {
4989                         list_add(&mnt->mnt_slave, &old->mnt_slave_list);
4990 @@ -852,6 +862,31 @@ static inline void mangle(struct seq_fil
4991         seq_escape(m, s, " \t\n\\");
4992  }
4993  
4994 +static int mnt_is_reachable(struct vfsmount *mnt)
4995 +{
4996 +       struct path root;
4997 +       struct dentry *point;
4998 +       int ret;
4999 +
5000 +       if (mnt == mnt->mnt_ns->root)
5001 +               return 1;
5002 +
5003 +       br_read_lock(vfsmount_lock);
5004 +       root = current->fs->root;
5005 +       point = root.dentry;
5006 +
5007 +       while ((mnt != mnt->mnt_parent) && (mnt != root.mnt)) {
5008 +               point = mnt->mnt_mountpoint;
5009 +               mnt = mnt->mnt_parent;
5010 +       }
5011 +
5012 +       ret = (mnt == root.mnt) && is_subdir(point, root.dentry);
5013 +
5014 +       br_read_unlock(vfsmount_lock);
5015 +
5016 +       return ret;
5017 +}
5018 +
5019  /*
5020   * Simple .show_options callback for filesystems which don't want to
5021   * implement more complex mount option showing.
5022 @@ -954,6 +989,8 @@ static int show_sb_opts(struct seq_file 
5023                 { MS_SYNCHRONOUS, ",sync" },
5024                 { MS_DIRSYNC, ",dirsync" },
5025                 { MS_MANDLOCK, ",mand" },
5026 +               { MS_TAGGED, ",tag" },
5027 +               { MS_NOTAGCHECK, ",notagcheck" },
5028                 { 0, NULL }
5029         };
5030         const struct proc_fs_info *fs_infop;
5031 @@ -1000,16 +1037,26 @@ static int show_vfsmnt(struct seq_file *
5032         int err = 0;
5033         struct path mnt_path = { .dentry = mnt->mnt_root, .mnt = mnt };
5034  
5035 -       if (mnt->mnt_sb->s_op->show_devname) {
5036 -               err = mnt->mnt_sb->s_op->show_devname(m, mnt);
5037 -               if (err)
5038 -                       goto out;
5039 +       if (vx_flags(VXF_HIDE_MOUNT, 0))
5040 +               return SEQ_SKIP;
5041 +       if (!mnt_is_reachable(mnt) && !vx_check(0, VS_WATCH_P))
5042 +               return SEQ_SKIP;
5043 +
5044 +       if (!vx_check(0, VS_ADMIN|VS_WATCH) &&
5045 +               mnt == current->fs->root.mnt) {
5046 +               seq_puts(m, "/dev/root / ");
5047         } else {
5048 -               mangle(m, mnt->mnt_devname ? mnt->mnt_devname : "none");
5049 +               if (mnt->mnt_sb->s_op->show_devname) {
5050 +                       err = mnt->mnt_sb->s_op->show_devname(m, mnt);
5051 +                       if (err)
5052 +                               goto out;
5053 +               } else {
5054 +                       mangle(m, mnt->mnt_devname ? mnt->mnt_devname : "none");
5055 +               }
5056 +               seq_putc(m, ' ');
5057 +               seq_path(m, &mnt_path, " \t\n\\");
5058 +               seq_putc(m, ' ');
5059         }
5060 -       seq_putc(m, ' ');
5061 -       seq_path(m, &mnt_path, " \t\n\\");
5062 -       seq_putc(m, ' ');
5063         show_type(m, mnt->mnt_sb);
5064         seq_puts(m, __mnt_is_readonly(mnt) ? " ro" : " rw");
5065         err = show_sb_opts(m, mnt->mnt_sb);
5066 @@ -1039,6 +1086,11 @@ static int show_mountinfo(struct seq_fil
5067         struct path root = p->root;
5068         int err = 0;
5069  
5070 +       if (vx_flags(VXF_HIDE_MOUNT, 0))
5071 +               return SEQ_SKIP;
5072 +       if (!mnt_is_reachable(mnt) && !vx_check(0, VS_WATCH_P))
5073 +               return SEQ_SKIP;
5074 +
5075         seq_printf(m, "%i %i %u:%u ", mnt->mnt_id, mnt->mnt_parent->mnt_id,
5076                    MAJOR(sb->s_dev), MINOR(sb->s_dev));
5077         if (sb->s_op->show_path)
5078 @@ -1104,22 +1156,32 @@ static int show_vfsstat(struct seq_file 
5079         struct path mnt_path = { .dentry = mnt->mnt_root, .mnt = mnt };
5080         int err = 0;
5081  
5082 -       /* device */
5083 -       if (mnt->mnt_sb->s_op->show_devname) {
5084 -               seq_puts(m, "device ");
5085 -               err = mnt->mnt_sb->s_op->show_devname(m, mnt);
5086 +       if (vx_flags(VXF_HIDE_MOUNT, 0))
5087 +               return SEQ_SKIP;
5088 +       if (!mnt_is_reachable(mnt) && !vx_check(0, VS_WATCH_P))
5089 +               return SEQ_SKIP;
5090 +
5091 +       if (!vx_check(0, VS_ADMIN|VS_WATCH) &&
5092 +               mnt == current->fs->root.mnt) {
5093 +               seq_puts(m, "device /dev/root mounted on / ");
5094         } else {
5095 -               if (mnt->mnt_devname) {
5096 +               /* device */
5097 +               if (mnt->mnt_sb->s_op->show_devname) {
5098                         seq_puts(m, "device ");
5099 -                       mangle(m, mnt->mnt_devname);
5100 -               } else
5101 -                       seq_puts(m, "no device");
5102 -       }
5103 +                       err = mnt->mnt_sb->s_op->show_devname(m, mnt);
5104 +               } else {
5105 +                       if (mnt->mnt_devname) {
5106 +                               seq_puts(m, "device ");
5107 +                               mangle(m, mnt->mnt_devname);
5108 +                       } else
5109 +                               seq_puts(m, "no device");
5110 +               }
5111  
5112 -       /* mount point */
5113 -       seq_puts(m, " mounted on ");
5114 -       seq_path(m, &mnt_path, " \t\n\\");
5115 -       seq_putc(m, ' ');
5116 +               /* mount point */
5117 +               seq_puts(m, " mounted on ");
5118 +               seq_path(m, &mnt_path, " \t\n\\");
5119 +               seq_putc(m, ' ');
5120 +       }
5121  
5122         /* file system type */
5123         seq_puts(m, "with fstype ");
5124 @@ -1378,7 +1440,7 @@ SYSCALL_DEFINE2(umount, char __user *, n
5125                 goto dput_and_out;
5126  
5127         retval = -EPERM;
5128 -       if (!capable(CAP_SYS_ADMIN))
5129 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SECURE_MOUNT))
5130                 goto dput_and_out;
5131  
5132         retval = do_umount(path.mnt, flags);
5133 @@ -1404,7 +1466,7 @@ SYSCALL_DEFINE1(oldumount, char __user *
5134  
5135  static int mount_is_safe(struct path *path)
5136  {
5137 -       if (capable(CAP_SYS_ADMIN))
5138 +       if (vx_capable(CAP_SYS_ADMIN, VXC_SECURE_MOUNT))
5139                 return 0;
5140         return -EPERM;
5141  #ifdef notyet
5142 @@ -1714,7 +1776,7 @@ static int do_change_type(struct path *p
5143         int type;
5144         int err = 0;
5145  
5146 -       if (!capable(CAP_SYS_ADMIN))
5147 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_NAMESPACE))
5148                 return -EPERM;
5149  
5150         if (path->dentry != path->mnt->mnt_root)
5151 @@ -1730,6 +1792,7 @@ static int do_change_type(struct path *p
5152                 if (err)
5153                         goto out_unlock;
5154         }
5155 +       // mnt->mnt_flags = mnt_flags;
5156  
5157         br_write_lock(vfsmount_lock);
5158         for (m = mnt; m; m = (recurse ? next_mnt(m, mnt) : NULL))
5159 @@ -1745,12 +1808,14 @@ static int do_change_type(struct path *p
5160   * do loopback mount.
5161   */
5162  static int do_loopback(struct path *path, char *old_name,
5163 -                               int recurse)
5164 +       tag_t tag, unsigned long flags, int mnt_flags)
5165  {
5166         LIST_HEAD(umount_list);
5167         struct path old_path;
5168         struct vfsmount *mnt = NULL;
5169         int err = mount_is_safe(path);
5170 +       int recurse = flags & MS_REC;
5171 +
5172         if (err)
5173                 return err;
5174         if (!old_name || !*old_name)
5175 @@ -1816,12 +1881,12 @@ static int change_mount_flags(struct vfs
5176   * on it - tough luck.
5177   */
5178  static int do_remount(struct path *path, int flags, int mnt_flags,
5179 -                     void *data)
5180 +       void *data, xid_t xid)
5181  {
5182         int err;
5183         struct super_block *sb = path->mnt->mnt_sb;
5184  
5185 -       if (!capable(CAP_SYS_ADMIN))
5186 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SECURE_REMOUNT))
5187                 return -EPERM;
5188  
5189         if (!check_mnt(path->mnt))
5190 @@ -1869,7 +1934,7 @@ static int do_move_mount(struct path *pa
5191         struct path old_path, parent_path;
5192         struct vfsmount *p;
5193         int err = 0;
5194 -       if (!capable(CAP_SYS_ADMIN))
5195 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SECURE_MOUNT))
5196                 return -EPERM;
5197         if (!old_name || !*old_name)
5198                 return -EINVAL;
5199 @@ -2020,7 +2085,7 @@ static int do_new_mount(struct path *pat
5200                 return -EINVAL;
5201  
5202         /* we need capabilities... */
5203 -       if (!capable(CAP_SYS_ADMIN))
5204 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SECURE_MOUNT))
5205                 return -EPERM;
5206  
5207         mnt = do_kern_mount(type, flags, name, data);
5208 @@ -2289,6 +2354,7 @@ long do_mount(char *dev_name, char *dir_
5209         struct path path;
5210         int retval = 0;
5211         int mnt_flags = 0;
5212 +       tag_t tag = 0;
5213  
5214         /* Discard magic */
5215         if ((flags & MS_MGC_MSK) == MS_MGC_VAL)
5216 @@ -2316,6 +2382,12 @@ long do_mount(char *dev_name, char *dir_
5217         if (!(flags & MS_NOATIME))
5218                 mnt_flags |= MNT_RELATIME;
5219  
5220 +       if (dx_parse_tag(data_page, &tag, 1, &mnt_flags, &flags)) {
5221 +               /* FIXME: bind and re-mounts get the tag flag? */
5222 +               if (flags & (MS_BIND|MS_REMOUNT))
5223 +                       flags |= MS_TAGID;
5224 +       }
5225 +
5226         /* Separate the per-mountpoint flags */
5227         if (flags & MS_NOSUID)
5228                 mnt_flags |= MNT_NOSUID;
5229 @@ -2332,15 +2404,17 @@ long do_mount(char *dev_name, char *dir_
5230         if (flags & MS_RDONLY)
5231                 mnt_flags |= MNT_READONLY;
5232  
5233 +       if (!capable(CAP_SYS_ADMIN))
5234 +               mnt_flags |= MNT_NODEV;
5235         flags &= ~(MS_NOSUID | MS_NOEXEC | MS_NODEV | MS_ACTIVE | MS_BORN |
5236                    MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
5237                    MS_STRICTATIME);
5238  
5239         if (flags & MS_REMOUNT)
5240                 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
5241 -                                   data_page);
5242 +                                   data_page, tag);
5243         else if (flags & MS_BIND)
5244 -               retval = do_loopback(&path, dev_name, flags & MS_REC);
5245 +               retval = do_loopback(&path, dev_name, tag, flags, mnt_flags);
5246         else if (flags & (MS_SHARED | MS_PRIVATE | MS_SLAVE | MS_UNBINDABLE))
5247                 retval = do_change_type(&path, flags);
5248         else if (flags & MS_MOVE)
5249 @@ -2440,6 +2514,7 @@ static struct mnt_namespace *dup_mnt_ns(
5250                 q = next_mnt(q, new_ns->root);
5251         }
5252         up_write(&namespace_sem);
5253 +       atomic_inc(&vs_global_mnt_ns);
5254  
5255         if (rootmnt)
5256                 mntput(rootmnt);
5257 @@ -2579,9 +2654,10 @@ SYSCALL_DEFINE2(pivot_root, const char _
5258                 goto out3;
5259  
5260         error = -EINVAL;
5261 -       if (IS_MNT_SHARED(old.mnt) ||
5262 -               IS_MNT_SHARED(new.mnt->mnt_parent) ||
5263 -               IS_MNT_SHARED(root.mnt->mnt_parent))
5264 +       if ((IS_MNT_SHARED(old.mnt) ||
5265 +               IS_MNT_SHARED(new.mnt->mnt_parent) ||
5266 +               IS_MNT_SHARED(root.mnt->mnt_parent)) &&
5267 +               !vx_flags(VXF_STATE_SETUP, 0))
5268                 goto out4;
5269         if (!check_mnt(root.mnt) || !check_mnt(new.mnt))
5270                 goto out4;
5271 @@ -2713,6 +2789,7 @@ void put_mnt_ns(struct mnt_namespace *ns
5272         br_write_unlock(vfsmount_lock);
5273         up_write(&namespace_sem);
5274         release_mounts(&umount_list);
5275 +       atomic_dec(&vs_global_mnt_ns);
5276         kfree(ns);
5277  }
5278  EXPORT_SYMBOL(put_mnt_ns);
5279 diff -NurpP --minimal linux-3.0.25/fs/nfs/client.c linux-3.0.25-vs2.3.2.3/fs/nfs/client.c
5280 --- linux-3.0.25/fs/nfs/client.c        2011-07-22 11:18:05.000000000 +0200
5281 +++ linux-3.0.25-vs2.3.2.3/fs/nfs/client.c      2011-06-10 22:11:24.000000000 +0200
5282 @@ -780,6 +780,9 @@ static int nfs_init_server_rpcclient(str
5283         if (server->flags & NFS_MOUNT_SOFT)
5284                 server->client->cl_softrtry = 1;
5285  
5286 +       server->client->cl_tag = 0;
5287 +       if (server->flags & NFS_MOUNT_TAGGED)
5288 +               server->client->cl_tag = 1;
5289         return 0;
5290  }
5291  
5292 @@ -951,6 +954,10 @@ static void nfs_server_set_fsinfo(struct
5293                 server->acdirmin = server->acdirmax = 0;
5294         }
5295  
5296 +       /* FIXME: needs fsinfo
5297 +       if (server->flags & NFS_MOUNT_TAGGED)
5298 +               sb->s_flags |= MS_TAGGED;       */
5299 +
5300         server->maxfilesize = fsinfo->maxfilesize;
5301  
5302         server->time_delta = fsinfo->time_delta;
5303 diff -NurpP --minimal linux-3.0.25/fs/nfs/dir.c linux-3.0.25-vs2.3.2.3/fs/nfs/dir.c
5304 --- linux-3.0.25/fs/nfs/dir.c   2012-03-19 21:16:51.000000000 +0100
5305 +++ linux-3.0.25-vs2.3.2.3/fs/nfs/dir.c 2011-12-19 15:55:53.000000000 +0100
5306 @@ -35,6 +35,7 @@
5307  #include <linux/sched.h>
5308  #include <linux/kmemleak.h>
5309  #include <linux/xattr.h>
5310 +#include <linux/vs_tag.h>
5311  
5312  #include "delegation.h"
5313  #include "iostat.h"
5314 @@ -1308,6 +1309,7 @@ static struct dentry *nfs_lookup(struct 
5315         if (IS_ERR(res))
5316                 goto out_unblock_sillyrename;
5317  
5318 +       dx_propagate_tag(nd, inode);
5319  no_entry:
5320         res = d_materialise_unique(dentry, inode);
5321         if (res != NULL) {
5322 diff -NurpP --minimal linux-3.0.25/fs/nfs/inode.c linux-3.0.25-vs2.3.2.3/fs/nfs/inode.c
5323 --- linux-3.0.25/fs/nfs/inode.c 2012-03-19 21:16:51.000000000 +0100
5324 +++ linux-3.0.25-vs2.3.2.3/fs/nfs/inode.c       2011-12-19 15:55:53.000000000 +0100
5325 @@ -38,6 +38,7 @@
5326  #include <linux/nfs_xdr.h>
5327  #include <linux/slab.h>
5328  #include <linux/compat.h>
5329 +#include <linux/vs_tag.h>
5330  
5331  #include <asm/system.h>
5332  #include <asm/uaccess.h>
5333 @@ -273,6 +274,8 @@ nfs_fhget(struct super_block *sb, struct
5334         if (inode->i_state & I_NEW) {
5335                 struct nfs_inode *nfsi = NFS_I(inode);
5336                 unsigned long now = jiffies;
5337 +               uid_t uid;
5338 +               gid_t gid;
5339  
5340                 /* We set i_ino for the few things that still rely on it,
5341                  * such as stat(2) */
5342 @@ -321,8 +324,8 @@ nfs_fhget(struct super_block *sb, struct
5343                 nfsi->change_attr = 0;
5344                 inode->i_size = 0;
5345                 inode->i_nlink = 0;
5346 -               inode->i_uid = -2;
5347 -               inode->i_gid = -2;
5348 +               uid = -2;
5349 +               gid = -2;
5350                 inode->i_blocks = 0;
5351                 memset(nfsi->cookieverf, 0, sizeof(nfsi->cookieverf));
5352  
5353 @@ -359,13 +362,13 @@ nfs_fhget(struct super_block *sb, struct
5354                 else if (nfs_server_capable(inode, NFS_CAP_NLINK))
5355                         nfsi->cache_validity |= NFS_INO_INVALID_ATTR;
5356                 if (fattr->valid & NFS_ATTR_FATTR_OWNER)
5357 -                       inode->i_uid = fattr->uid;
5358 +                       uid = fattr->uid;
5359                 else if (nfs_server_capable(inode, NFS_CAP_OWNER))
5360                         nfsi->cache_validity |= NFS_INO_INVALID_ATTR
5361                                 | NFS_INO_INVALID_ACCESS
5362                                 | NFS_INO_INVALID_ACL;
5363                 if (fattr->valid & NFS_ATTR_FATTR_GROUP)
5364 -                       inode->i_gid = fattr->gid;
5365 +                       gid = fattr->gid;
5366                 else if (nfs_server_capable(inode, NFS_CAP_OWNER_GROUP))
5367                         nfsi->cache_validity |= NFS_INO_INVALID_ATTR
5368                                 | NFS_INO_INVALID_ACCESS
5369 @@ -378,6 +381,11 @@ nfs_fhget(struct super_block *sb, struct
5370                          */
5371                         inode->i_blocks = nfs_calc_block_size(fattr->du.nfs3.used);
5372                 }
5373 +               inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
5374 +               inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
5375 +               inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid, 0);
5376 +                               /* maybe fattr->xid someday */
5377 +
5378                 nfsi->attrtimeo = NFS_MINATTRTIMEO(inode);
5379                 nfsi->attrtimeo_timestamp = now;
5380                 nfsi->access_cache = RB_ROOT;
5381 @@ -494,6 +502,8 @@ void nfs_setattr_update_inode(struct ino
5382                         inode->i_uid = attr->ia_uid;
5383                 if ((attr->ia_valid & ATTR_GID) != 0)
5384                         inode->i_gid = attr->ia_gid;
5385 +               if ((attr->ia_valid & ATTR_TAG) && IS_TAGGED(inode))
5386 +                       inode->i_tag = attr->ia_tag;
5387                 NFS_I(inode)->cache_validity |= NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL;
5388                 spin_unlock(&inode->i_lock);
5389         }
5390 @@ -941,6 +951,9 @@ static int nfs_check_inode_attributes(st
5391         struct nfs_inode *nfsi = NFS_I(inode);
5392         loff_t cur_size, new_isize;
5393         unsigned long invalid = 0;
5394 +       uid_t uid;
5395 +       gid_t gid;
5396 +       tag_t tag;
5397  
5398  
5399         /* Has the inode gone and changed behind our back? */
5400 @@ -964,13 +977,18 @@ static int nfs_check_inode_attributes(st
5401                         invalid |= NFS_INO_INVALID_ATTR|NFS_INO_REVAL_PAGECACHE;
5402         }
5403  
5404 +       uid = INOTAG_UID(DX_TAG(inode), fattr->uid, fattr->gid);
5405 +       gid = INOTAG_GID(DX_TAG(inode), fattr->uid, fattr->gid);
5406 +       tag = INOTAG_TAG(DX_TAG(inode), fattr->uid, fattr->gid, 0);
5407 +
5408         /* Have any file permissions changed? */
5409         if ((fattr->valid & NFS_ATTR_FATTR_MODE) && (inode->i_mode & S_IALLUGO) != (fattr->mode & S_IALLUGO))
5410                 invalid |= NFS_INO_INVALID_ATTR | NFS_INO_INVALID_ACCESS | NFS_INO_INVALID_ACL;
5411 -       if ((fattr->valid & NFS_ATTR_FATTR_OWNER) && inode->i_uid != fattr->uid)
5412 +       if ((fattr->valid & NFS_ATTR_FATTR_OWNER) && uid != fattr->uid)
5413                 invalid |= NFS_INO_INVALID_ATTR | NFS_INO_INVALID_ACCESS | NFS_INO_INVALID_ACL;
5414 -       if ((fattr->valid & NFS_ATTR_FATTR_GROUP) && inode->i_gid != fattr->gid)
5415 +       if ((fattr->valid & NFS_ATTR_FATTR_GROUP) && gid != fattr->gid)
5416                 invalid |= NFS_INO_INVALID_ATTR | NFS_INO_INVALID_ACCESS | NFS_INO_INVALID_ACL;
5417 +               /* maybe check for tag too? */
5418  
5419         /* Has the link count changed? */
5420         if ((fattr->valid & NFS_ATTR_FATTR_NLINK) && inode->i_nlink != fattr->nlink)
5421 @@ -1205,6 +1223,9 @@ static int nfs_update_inode(struct inode
5422         unsigned long invalid = 0;
5423         unsigned long now = jiffies;
5424         unsigned long save_cache_validity;
5425 +       uid_t uid;
5426 +       gid_t gid;
5427 +       tag_t tag;
5428  
5429         dfprintk(VFS, "NFS: %s(%s/%ld ct=%d info=0x%x)\n",
5430                         __func__, inode->i_sb->s_id, inode->i_ino,
5431 @@ -1312,6 +1333,9 @@ static int nfs_update_inode(struct inode
5432                                 | NFS_INO_REVAL_PAGECACHE
5433                                 | NFS_INO_REVAL_FORCED);
5434  
5435 +       uid = TAGINO_UID(DX_TAG(inode), inode->i_uid, inode->i_tag);
5436 +       gid = TAGINO_GID(DX_TAG(inode), inode->i_gid, inode->i_tag);
5437 +       tag = inode->i_tag;
5438  
5439         if (fattr->valid & NFS_ATTR_FATTR_ATIME)
5440                 memcpy(&inode->i_atime, &fattr->atime, sizeof(inode->i_atime));
5441 @@ -1333,9 +1357,9 @@ static int nfs_update_inode(struct inode
5442                                 | NFS_INO_REVAL_FORCED);
5443  
5444         if (fattr->valid & NFS_ATTR_FATTR_OWNER) {
5445 -               if (inode->i_uid != fattr->uid) {
5446 +               if (uid != fattr->uid) {
5447                         invalid |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL;
5448 -                       inode->i_uid = fattr->uid;
5449 +                       uid = fattr->uid;
5450                 }
5451         } else if (server->caps & NFS_CAP_OWNER)
5452                 invalid |= save_cache_validity & (NFS_INO_INVALID_ATTR
5453 @@ -1344,9 +1368,9 @@ static int nfs_update_inode(struct inode
5454                                 | NFS_INO_REVAL_FORCED);
5455  
5456         if (fattr->valid & NFS_ATTR_FATTR_GROUP) {
5457 -               if (inode->i_gid != fattr->gid) {
5458 +               if (gid != fattr->gid) {
5459                         invalid |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL;
5460 -                       inode->i_gid = fattr->gid;
5461 +                       gid = fattr->gid;
5462                 }
5463         } else if (server->caps & NFS_CAP_OWNER_GROUP)
5464                 invalid |= save_cache_validity & (NFS_INO_INVALID_ATTR
5465 @@ -1354,6 +1378,10 @@ static int nfs_update_inode(struct inode
5466                                 | NFS_INO_INVALID_ACL
5467                                 | NFS_INO_REVAL_FORCED);
5468  
5469 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
5470 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
5471 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid, tag);
5472 +
5473         if (fattr->valid & NFS_ATTR_FATTR_NLINK) {
5474                 if (inode->i_nlink != fattr->nlink) {
5475                         invalid |= NFS_INO_INVALID_ATTR;
5476 diff -NurpP --minimal linux-3.0.25/fs/nfs/nfs3xdr.c linux-3.0.25-vs2.3.2.3/fs/nfs/nfs3xdr.c
5477 --- linux-3.0.25/fs/nfs/nfs3xdr.c       2011-03-15 18:07:32.000000000 +0100
5478 +++ linux-3.0.25-vs2.3.2.3/fs/nfs/nfs3xdr.c     2011-06-10 22:11:24.000000000 +0200
5479 @@ -20,6 +20,7 @@
5480  #include <linux/nfs3.h>
5481  #include <linux/nfs_fs.h>
5482  #include <linux/nfsacl.h>
5483 +#include <linux/vs_tag.h>
5484  #include "internal.h"
5485  
5486  #define NFSDBG_FACILITY                NFSDBG_XDR
5487 @@ -562,7 +563,8 @@ static __be32 *xdr_decode_nfstime3(__be3
5488   *             set_mtime       mtime;
5489   *     };
5490   */
5491 -static void encode_sattr3(struct xdr_stream *xdr, const struct iattr *attr)
5492 +static void encode_sattr3(struct xdr_stream *xdr,
5493 +       const struct iattr *attr, int tag)
5494  {
5495         u32 nbytes;
5496         __be32 *p;
5497 @@ -594,15 +596,19 @@ static void encode_sattr3(struct xdr_str
5498         } else
5499                 *p++ = xdr_zero;
5500  
5501 -       if (attr->ia_valid & ATTR_UID) {
5502 +       if (attr->ia_valid & ATTR_UID ||
5503 +               (tag && (attr->ia_valid & ATTR_TAG))) {
5504                 *p++ = xdr_one;
5505 -               *p++ = cpu_to_be32(attr->ia_uid);
5506 +               *p++ = cpu_to_be32(TAGINO_UID(tag,
5507 +                       attr->ia_uid, attr->ia_tag));
5508         } else
5509                 *p++ = xdr_zero;
5510  
5511 -       if (attr->ia_valid & ATTR_GID) {
5512 +       if (attr->ia_valid & ATTR_GID ||
5513 +               (tag && (attr->ia_valid & ATTR_TAG))) {
5514                 *p++ = xdr_one;
5515 -               *p++ = cpu_to_be32(attr->ia_gid);
5516 +               *p++ = cpu_to_be32(TAGINO_GID(tag,
5517 +                       attr->ia_gid, attr->ia_tag));
5518         } else
5519                 *p++ = xdr_zero;
5520  
5521 @@ -878,7 +884,7 @@ static void nfs3_xdr_enc_setattr3args(st
5522                                       const struct nfs3_sattrargs *args)
5523  {
5524         encode_nfs_fh3(xdr, args->fh);
5525 -       encode_sattr3(xdr, args->sattr);
5526 +       encode_sattr3(xdr, args->sattr, req->rq_task->tk_client->cl_tag);
5527         encode_sattrguard3(xdr, args);
5528  }
5529  
5530 @@ -1028,13 +1034,13 @@ static void nfs3_xdr_enc_write3args(stru
5531   *     };
5532   */
5533  static void encode_createhow3(struct xdr_stream *xdr,
5534 -                             const struct nfs3_createargs *args)
5535 +       const struct nfs3_createargs *args, int tag)
5536  {
5537         encode_uint32(xdr, args->createmode);
5538         switch (args->createmode) {
5539         case NFS3_CREATE_UNCHECKED:
5540         case NFS3_CREATE_GUARDED:
5541 -               encode_sattr3(xdr, args->sattr);
5542 +               encode_sattr3(xdr, args->sattr, tag);
5543                 break;
5544         case NFS3_CREATE_EXCLUSIVE:
5545                 encode_createverf3(xdr, args->verifier);
5546 @@ -1049,7 +1055,7 @@ static void nfs3_xdr_enc_create3args(str
5547                                      const struct nfs3_createargs *args)
5548  {
5549         encode_diropargs3(xdr, args->fh, args->name, args->len);
5550 -       encode_createhow3(xdr, args);
5551 +       encode_createhow3(xdr, args, req->rq_task->tk_client->cl_tag);
5552  }
5553  
5554  /*
5555 @@ -1065,7 +1071,7 @@ static void nfs3_xdr_enc_mkdir3args(stru
5556                                     const struct nfs3_mkdirargs *args)
5557  {
5558         encode_diropargs3(xdr, args->fh, args->name, args->len);
5559 -       encode_sattr3(xdr, args->sattr);
5560 +       encode_sattr3(xdr, args->sattr, req->rq_task->tk_client->cl_tag);
5561  }
5562  
5563  /*
5564 @@ -1082,9 +1088,9 @@ static void nfs3_xdr_enc_mkdir3args(stru
5565   *     };
5566   */
5567  static void encode_symlinkdata3(struct xdr_stream *xdr,
5568 -                               const struct nfs3_symlinkargs *args)
5569 +       const struct nfs3_symlinkargs *args, int tag)
5570  {
5571 -       encode_sattr3(xdr, args->sattr);
5572 +       encode_sattr3(xdr, args->sattr, tag);
5573         encode_nfspath3(xdr, args->pages, args->pathlen);
5574  }
5575  
5576 @@ -1093,7 +1099,7 @@ static void nfs3_xdr_enc_symlink3args(st
5577                                       const struct nfs3_symlinkargs *args)
5578  {
5579         encode_diropargs3(xdr, args->fromfh, args->fromname, args->fromlen);
5580 -       encode_symlinkdata3(xdr, args);
5581 +       encode_symlinkdata3(xdr, args, req->rq_task->tk_client->cl_tag);
5582  }
5583  
5584  /*
5585 @@ -1121,24 +1127,24 @@ static void nfs3_xdr_enc_symlink3args(st
5586   *     };
5587   */
5588  static void encode_devicedata3(struct xdr_stream *xdr,
5589 -                              const struct nfs3_mknodargs *args)
5590 +       const struct nfs3_mknodargs *args, int tag)
5591  {
5592 -       encode_sattr3(xdr, args->sattr);
5593 +       encode_sattr3(xdr, args->sattr, tag);
5594         encode_specdata3(xdr, args->rdev);
5595  }
5596  
5597  static void encode_mknoddata3(struct xdr_stream *xdr,
5598 -                             const struct nfs3_mknodargs *args)
5599 +       const struct nfs3_mknodargs *args, int tag)
5600  {
5601         encode_ftype3(xdr, args->type);
5602         switch (args->type) {
5603         case NF3CHR:
5604         case NF3BLK:
5605 -               encode_devicedata3(xdr, args);
5606 +               encode_devicedata3(xdr, args, tag);
5607                 break;
5608         case NF3SOCK:
5609         case NF3FIFO:
5610 -               encode_sattr3(xdr, args->sattr);
5611 +               encode_sattr3(xdr, args->sattr, tag);
5612                 break;
5613         case NF3REG:
5614         case NF3DIR:
5615 @@ -1153,7 +1159,7 @@ static void nfs3_xdr_enc_mknod3args(stru
5616                                     const struct nfs3_mknodargs *args)
5617  {
5618         encode_diropargs3(xdr, args->fh, args->name, args->len);
5619 -       encode_mknoddata3(xdr, args);
5620 +       encode_mknoddata3(xdr, args, req->rq_task->tk_client->cl_tag);
5621  }
5622  
5623  /*
5624 diff -NurpP --minimal linux-3.0.25/fs/nfs/super.c linux-3.0.25-vs2.3.2.3/fs/nfs/super.c
5625 --- linux-3.0.25/fs/nfs/super.c 2012-03-19 21:16:52.000000000 +0100
5626 +++ linux-3.0.25-vs2.3.2.3/fs/nfs/super.c       2012-01-26 08:39:53.000000000 +0100
5627 @@ -53,6 +53,7 @@
5628  #include <linux/nfs_xdr.h>
5629  #include <linux/magic.h>
5630  #include <linux/parser.h>
5631 +#include <linux/vs_tag.h>
5632  
5633  #include <asm/system.h>
5634  #include <asm/uaccess.h>
5635 @@ -87,6 +88,7 @@ enum {
5636         Opt_sharecache, Opt_nosharecache,
5637         Opt_resvport, Opt_noresvport,
5638         Opt_fscache, Opt_nofscache,
5639 +       Opt_tag, Opt_notag,
5640  
5641         /* Mount options that take integer arguments */
5642         Opt_port,
5643 @@ -100,6 +102,7 @@ enum {
5644         Opt_mountvers,
5645         Opt_nfsvers,
5646         Opt_minorversion,
5647 +       Opt_tagid,
5648  
5649         /* Mount options that take string arguments */
5650         Opt_sec, Opt_proto, Opt_mountproto, Opt_mounthost,
5651 @@ -180,6 +183,10 @@ static const match_table_t nfs_mount_opt
5652         { Opt_fscache_uniq, "fsc=%s" },
5653         { Opt_local_lock, "local_lock=%s" },
5654  
5655 +       { Opt_tag, "tag" },
5656 +       { Opt_notag, "notag" },
5657 +       { Opt_tagid, "tagid=%u" },
5658 +
5659         { Opt_err, NULL }
5660  };
5661  
5662 @@ -650,6 +657,7 @@ static void nfs_show_mount_options(struc
5663                 { NFS_MOUNT_NORDIRPLUS, ",nordirplus", "" },
5664                 { NFS_MOUNT_UNSHARED, ",nosharecache", "" },
5665                 { NFS_MOUNT_NORESVPORT, ",noresvport", "" },
5666 +               { NFS_MOUNT_TAGGED, ",tag", "" },
5667                 { 0, NULL, NULL }
5668         };
5669         const struct proc_nfs_info *nfs_infop;
5670 @@ -1212,6 +1220,14 @@ static int nfs_parse_mount_options(char 
5671                         kfree(mnt->fscache_uniq);
5672                         mnt->fscache_uniq = NULL;
5673                         break;
5674 +#ifndef CONFIG_TAGGING_NONE
5675 +               case Opt_tag:
5676 +                       mnt->flags |= NFS_MOUNT_TAGGED;
5677 +                       break;
5678 +               case Opt_notag:
5679 +                       mnt->flags &= ~NFS_MOUNT_TAGGED;
5680 +                       break;
5681 +#endif
5682  
5683                 /*
5684                  * options that take numeric values
5685 @@ -1318,6 +1334,12 @@ static int nfs_parse_mount_options(char 
5686                                 goto out_invalid_value;
5687                         mnt->minorversion = option;
5688                         break;
5689 +#ifdef CONFIG_PROPAGATE
5690 +               case Opt_tagid:
5691 +                       /* use args[0] */
5692 +                       nfs_data.flags |= NFS_MOUNT_TAGGED;
5693 +                       break;
5694 +#endif
5695  
5696                 /*
5697                  * options that take text values
5698 diff -NurpP --minimal linux-3.0.25/fs/nfsd/auth.c linux-3.0.25-vs2.3.2.3/fs/nfsd/auth.c
5699 --- linux-3.0.25/fs/nfsd/auth.c 2010-02-25 11:52:05.000000000 +0100
5700 +++ linux-3.0.25-vs2.3.2.3/fs/nfsd/auth.c       2011-06-10 22:11:24.000000000 +0200
5701 @@ -1,6 +1,7 @@
5702  /* Copyright (C) 1995, 1996 Olaf Kirch <okir@monad.swb.de> */
5703  
5704  #include <linux/sched.h>
5705 +#include <linux/vs_tag.h>
5706  #include "nfsd.h"
5707  #include "auth.h"
5708  
5709 @@ -36,6 +37,9 @@ int nfsd_setuser(struct svc_rqst *rqstp,
5710  
5711         new->fsuid = rqstp->rq_cred.cr_uid;
5712         new->fsgid = rqstp->rq_cred.cr_gid;
5713 +       /* FIXME: this desperately needs a tag :)
5714 +       new->xid = (xid_t)INOTAG_TAG(DX_TAG_NFSD, cred.cr_uid, cred.cr_gid, 0);
5715 +                       */
5716  
5717         rqgi = rqstp->rq_cred.cr_group_info;
5718  
5719 diff -NurpP --minimal linux-3.0.25/fs/nfsd/nfs3xdr.c linux-3.0.25-vs2.3.2.3/fs/nfsd/nfs3xdr.c
5720 --- linux-3.0.25/fs/nfsd/nfs3xdr.c      2011-07-22 11:18:05.000000000 +0200
5721 +++ linux-3.0.25-vs2.3.2.3/fs/nfsd/nfs3xdr.c    2011-06-10 22:11:24.000000000 +0200
5722 @@ -7,6 +7,7 @@
5723   */
5724  
5725  #include <linux/namei.h>
5726 +#include <linux/vs_tag.h>
5727  #include "xdr3.h"
5728  #include "auth.h"
5729  
5730 @@ -95,6 +96,8 @@ static __be32 *
5731  decode_sattr3(__be32 *p, struct iattr *iap)
5732  {
5733         u32     tmp;
5734 +       uid_t   uid = 0;
5735 +       gid_t   gid = 0;
5736  
5737         iap->ia_valid = 0;
5738  
5739 @@ -104,12 +107,15 @@ decode_sattr3(__be32 *p, struct iattr *i
5740         }
5741         if (*p++) {
5742                 iap->ia_valid |= ATTR_UID;
5743 -               iap->ia_uid = ntohl(*p++);
5744 +               uid = ntohl(*p++);
5745         }
5746         if (*p++) {
5747                 iap->ia_valid |= ATTR_GID;
5748 -               iap->ia_gid = ntohl(*p++);
5749 +               gid = ntohl(*p++);
5750         }
5751 +       iap->ia_uid = INOTAG_UID(DX_TAG_NFSD, uid, gid);
5752 +       iap->ia_gid = INOTAG_GID(DX_TAG_NFSD, uid, gid);
5753 +       iap->ia_tag = INOTAG_TAG(DX_TAG_NFSD, uid, gid, 0);
5754         if (*p++) {
5755                 u64     newsize;
5756  
5757 @@ -165,8 +171,12 @@ encode_fattr3(struct svc_rqst *rqstp, __
5758         *p++ = htonl(nfs3_ftypes[(stat->mode & S_IFMT) >> 12]);
5759         *p++ = htonl((u32) stat->mode);
5760         *p++ = htonl((u32) stat->nlink);
5761 -       *p++ = htonl((u32) nfsd_ruid(rqstp, stat->uid));
5762 -       *p++ = htonl((u32) nfsd_rgid(rqstp, stat->gid));
5763 +       *p++ = htonl((u32) nfsd_ruid(rqstp,
5764 +               TAGINO_UID(0 /* FIXME: DX_TAG(dentry->d_inode) */,
5765 +               stat->uid, stat->tag)));
5766 +       *p++ = htonl((u32) nfsd_rgid(rqstp,
5767 +               TAGINO_GID(0 /* FIXME: DX_TAG(dentry->d_inode) */,
5768 +               stat->gid, stat->tag)));
5769         if (S_ISLNK(stat->mode) && stat->size > NFS3_MAXPATHLEN) {
5770                 p = xdr_encode_hyper(p, (u64) NFS3_MAXPATHLEN);
5771         } else {
5772 diff -NurpP --minimal linux-3.0.25/fs/nfsd/nfs4xdr.c linux-3.0.25-vs2.3.2.3/fs/nfsd/nfs4xdr.c
5773 --- linux-3.0.25/fs/nfsd/nfs4xdr.c      2012-03-19 21:16:52.000000000 +0100
5774 +++ linux-3.0.25-vs2.3.2.3/fs/nfsd/nfs4xdr.c    2011-11-15 17:37:07.000000000 +0100
5775 @@ -45,6 +45,7 @@
5776  #include <linux/statfs.h>
5777  #include <linux/utsname.h>
5778  #include <linux/sunrpc/svcauth_gss.h>
5779 +#include <linux/vs_tag.h>
5780  
5781  #include "idmap.h"
5782  #include "acl.h"
5783 @@ -2102,14 +2103,18 @@ out_acl:
5784                 WRITE32(stat.nlink);
5785         }
5786         if (bmval1 & FATTR4_WORD1_OWNER) {
5787 -               status = nfsd4_encode_user(rqstp, stat.uid, &p, &buflen);
5788 +               status = nfsd4_encode_user(rqstp,
5789 +                       TAGINO_UID(DX_TAG(dentry->d_inode),
5790 +                       stat.uid, stat.tag), &p, &buflen);
5791                 if (status == nfserr_resource)
5792                         goto out_resource;
5793                 if (status)
5794                         goto out;
5795         }
5796         if (bmval1 & FATTR4_WORD1_OWNER_GROUP) {
5797 -               status = nfsd4_encode_group(rqstp, stat.gid, &p, &buflen);
5798 +               status = nfsd4_encode_group(rqstp,
5799 +                       TAGINO_GID(DX_TAG(dentry->d_inode),
5800 +                       stat.gid, stat.tag), &p, &buflen);
5801                 if (status == nfserr_resource)
5802                         goto out_resource;
5803                 if (status)
5804 diff -NurpP --minimal linux-3.0.25/fs/nfsd/nfsxdr.c linux-3.0.25-vs2.3.2.3/fs/nfsd/nfsxdr.c
5805 --- linux-3.0.25/fs/nfsd/nfsxdr.c       2011-05-22 16:17:53.000000000 +0200
5806 +++ linux-3.0.25-vs2.3.2.3/fs/nfsd/nfsxdr.c     2011-06-10 22:11:24.000000000 +0200
5807 @@ -6,6 +6,7 @@
5808  
5809  #include "xdr.h"
5810  #include "auth.h"
5811 +#include <linux/vs_tag.h>
5812  
5813  #define NFSDDBG_FACILITY               NFSDDBG_XDR
5814  
5815 @@ -88,6 +89,8 @@ static __be32 *
5816  decode_sattr(__be32 *p, struct iattr *iap)
5817  {
5818         u32     tmp, tmp1;
5819 +       uid_t   uid = 0;
5820 +       gid_t   gid = 0;
5821  
5822         iap->ia_valid = 0;
5823  
5824 @@ -101,12 +104,15 @@ decode_sattr(__be32 *p, struct iattr *ia
5825         }
5826         if ((tmp = ntohl(*p++)) != (u32)-1) {
5827                 iap->ia_valid |= ATTR_UID;
5828 -               iap->ia_uid = tmp;
5829 +               uid = tmp;
5830         }
5831         if ((tmp = ntohl(*p++)) != (u32)-1) {
5832                 iap->ia_valid |= ATTR_GID;
5833 -               iap->ia_gid = tmp;
5834 +               gid = tmp;
5835         }
5836 +       iap->ia_uid = INOTAG_UID(DX_TAG_NFSD, uid, gid);
5837 +       iap->ia_gid = INOTAG_GID(DX_TAG_NFSD, uid, gid);
5838 +       iap->ia_tag = INOTAG_TAG(DX_TAG_NFSD, uid, gid, 0);
5839         if ((tmp = ntohl(*p++)) != (u32)-1) {
5840                 iap->ia_valid |= ATTR_SIZE;
5841                 iap->ia_size = tmp;
5842 @@ -151,8 +157,10 @@ encode_fattr(struct svc_rqst *rqstp, __b
5843         *p++ = htonl(nfs_ftypes[type >> 12]);
5844         *p++ = htonl((u32) stat->mode);
5845         *p++ = htonl((u32) stat->nlink);
5846 -       *p++ = htonl((u32) nfsd_ruid(rqstp, stat->uid));
5847 -       *p++ = htonl((u32) nfsd_rgid(rqstp, stat->gid));
5848 +       *p++ = htonl((u32) nfsd_ruid(rqstp,
5849 +               TAGINO_UID(DX_TAG(dentry->d_inode), stat->uid, stat->tag)));
5850 +       *p++ = htonl((u32) nfsd_rgid(rqstp,
5851 +               TAGINO_GID(DX_TAG(dentry->d_inode), stat->gid, stat->tag)));
5852  
5853         if (S_ISLNK(type) && stat->size > NFS_MAXPATHLEN) {
5854                 *p++ = htonl(NFS_MAXPATHLEN);
5855 diff -NurpP --minimal linux-3.0.25/fs/ocfs2/dlmglue.c linux-3.0.25-vs2.3.2.3/fs/ocfs2/dlmglue.c
5856 --- linux-3.0.25/fs/ocfs2/dlmglue.c     2011-05-22 16:17:53.000000000 +0200
5857 +++ linux-3.0.25-vs2.3.2.3/fs/ocfs2/dlmglue.c   2011-06-10 22:11:24.000000000 +0200
5858 @@ -2041,6 +2041,7 @@ static void __ocfs2_stuff_meta_lvb(struc
5859         lvb->lvb_iclusters = cpu_to_be32(oi->ip_clusters);
5860         lvb->lvb_iuid      = cpu_to_be32(inode->i_uid);
5861         lvb->lvb_igid      = cpu_to_be32(inode->i_gid);
5862 +       lvb->lvb_itag      = cpu_to_be16(inode->i_tag);
5863         lvb->lvb_imode     = cpu_to_be16(inode->i_mode);
5864         lvb->lvb_inlink    = cpu_to_be16(inode->i_nlink);
5865         lvb->lvb_iatime_packed  =
5866 @@ -2091,6 +2092,7 @@ static void ocfs2_refresh_inode_from_lvb
5867  
5868         inode->i_uid     = be32_to_cpu(lvb->lvb_iuid);
5869         inode->i_gid     = be32_to_cpu(lvb->lvb_igid);
5870 +       inode->i_tag     = be16_to_cpu(lvb->lvb_itag);
5871         inode->i_mode    = be16_to_cpu(lvb->lvb_imode);
5872         inode->i_nlink   = be16_to_cpu(lvb->lvb_inlink);
5873         ocfs2_unpack_timespec(&inode->i_atime,
5874 diff -NurpP --minimal linux-3.0.25/fs/ocfs2/dlmglue.h linux-3.0.25-vs2.3.2.3/fs/ocfs2/dlmglue.h
5875 --- linux-3.0.25/fs/ocfs2/dlmglue.h     2010-10-21 13:07:50.000000000 +0200
5876 +++ linux-3.0.25-vs2.3.2.3/fs/ocfs2/dlmglue.h   2011-06-10 22:11:24.000000000 +0200
5877 @@ -46,7 +46,8 @@ struct ocfs2_meta_lvb {
5878         __be16       lvb_inlink;
5879         __be32       lvb_iattr;
5880         __be32       lvb_igeneration;
5881 -       __be32       lvb_reserved2;
5882 +       __be16       lvb_itag;
5883 +       __be16       lvb_reserved2;
5884  };
5885  
5886  #define OCFS2_QINFO_LVB_VERSION 1
5887 diff -NurpP --minimal linux-3.0.25/fs/ocfs2/file.c linux-3.0.25-vs2.3.2.3/fs/ocfs2/file.c
5888 --- linux-3.0.25/fs/ocfs2/file.c        2011-07-22 11:18:06.000000000 +0200
5889 +++ linux-3.0.25-vs2.3.2.3/fs/ocfs2/file.c      2011-06-10 22:43:33.000000000 +0200
5890 @@ -1111,7 +1111,7 @@ int ocfs2_setattr(struct dentry *dentry,
5891                 attr->ia_valid &= ~ATTR_SIZE;
5892  
5893  #define OCFS2_VALID_ATTRS (ATTR_ATIME | ATTR_MTIME | ATTR_CTIME | ATTR_SIZE \
5894 -                          | ATTR_GID | ATTR_UID | ATTR_MODE)
5895 +                          | ATTR_GID | ATTR_UID | ATTR_TAG | ATTR_MODE)
5896         if (!(attr->ia_valid & OCFS2_VALID_ATTRS))
5897                 return 0;
5898  
5899 diff -NurpP --minimal linux-3.0.25/fs/ocfs2/inode.c linux-3.0.25-vs2.3.2.3/fs/ocfs2/inode.c
5900 --- linux-3.0.25/fs/ocfs2/inode.c       2011-05-22 16:17:53.000000000 +0200
5901 +++ linux-3.0.25-vs2.3.2.3/fs/ocfs2/inode.c     2011-06-10 22:11:24.000000000 +0200
5902 @@ -28,6 +28,7 @@
5903  #include <linux/highmem.h>
5904  #include <linux/pagemap.h>
5905  #include <linux/quotaops.h>
5906 +#include <linux/vs_tag.h>
5907  
5908  #include <asm/byteorder.h>
5909  
5910 @@ -78,11 +79,13 @@ void ocfs2_set_inode_flags(struct inode 
5911  {
5912         unsigned int flags = OCFS2_I(inode)->ip_attr;
5913  
5914 -       inode->i_flags &= ~(S_IMMUTABLE |
5915 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
5916                 S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
5917  
5918         if (flags & OCFS2_IMMUTABLE_FL)
5919                 inode->i_flags |= S_IMMUTABLE;
5920 +       if (flags & OCFS2_IXUNLINK_FL)
5921 +               inode->i_flags |= S_IXUNLINK;
5922  
5923         if (flags & OCFS2_SYNC_FL)
5924                 inode->i_flags |= S_SYNC;
5925 @@ -92,25 +95,44 @@ void ocfs2_set_inode_flags(struct inode 
5926                 inode->i_flags |= S_NOATIME;
5927         if (flags & OCFS2_DIRSYNC_FL)
5928                 inode->i_flags |= S_DIRSYNC;
5929 +
5930 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
5931 +
5932 +       if (flags & OCFS2_BARRIER_FL)
5933 +               inode->i_vflags |= V_BARRIER;
5934 +       if (flags & OCFS2_COW_FL)
5935 +               inode->i_vflags |= V_COW;
5936  }
5937  
5938  /* Propagate flags from i_flags to OCFS2_I(inode)->ip_attr */
5939  void ocfs2_get_inode_flags(struct ocfs2_inode_info *oi)
5940  {
5941         unsigned int flags = oi->vfs_inode.i_flags;
5942 +       unsigned int vflags = oi->vfs_inode.i_vflags;
5943 +
5944 +       oi->ip_attr &= ~(OCFS2_SYNC_FL | OCFS2_APPEND_FL |
5945 +                       OCFS2_IMMUTABLE_FL | OCFS2_IXUNLINK_FL |
5946 +                       OCFS2_NOATIME_FL | OCFS2_DIRSYNC_FL |
5947 +                       OCFS2_BARRIER_FL | OCFS2_COW_FL);
5948 +
5949 +       if (flags & S_IMMUTABLE)
5950 +               oi->ip_attr |= OCFS2_IMMUTABLE_FL;
5951 +       if (flags & S_IXUNLINK)
5952 +               oi->ip_attr |= OCFS2_IXUNLINK_FL;
5953  
5954 -       oi->ip_attr &= ~(OCFS2_SYNC_FL|OCFS2_APPEND_FL|
5955 -                       OCFS2_IMMUTABLE_FL|OCFS2_NOATIME_FL|OCFS2_DIRSYNC_FL);
5956         if (flags & S_SYNC)
5957                 oi->ip_attr |= OCFS2_SYNC_FL;
5958         if (flags & S_APPEND)
5959                 oi->ip_attr |= OCFS2_APPEND_FL;
5960 -       if (flags & S_IMMUTABLE)
5961 -               oi->ip_attr |= OCFS2_IMMUTABLE_FL;
5962         if (flags & S_NOATIME)
5963                 oi->ip_attr |= OCFS2_NOATIME_FL;
5964         if (flags & S_DIRSYNC)
5965                 oi->ip_attr |= OCFS2_DIRSYNC_FL;
5966 +
5967 +       if (vflags & V_BARRIER)
5968 +               oi->ip_attr |= OCFS2_BARRIER_FL;
5969 +       if (vflags & V_COW)
5970 +               oi->ip_attr |= OCFS2_COW_FL;
5971  }
5972  
5973  struct inode *ocfs2_ilookup(struct super_block *sb, u64 blkno)
5974 @@ -241,6 +263,8 @@ void ocfs2_populate_inode(struct inode *
5975         struct super_block *sb;
5976         struct ocfs2_super *osb;
5977         int use_plocks = 1;
5978 +       uid_t uid;
5979 +       gid_t gid;
5980  
5981         sb = inode->i_sb;
5982         osb = OCFS2_SB(sb);
5983 @@ -269,8 +293,12 @@ void ocfs2_populate_inode(struct inode *
5984         inode->i_generation = le32_to_cpu(fe->i_generation);
5985         inode->i_rdev = huge_decode_dev(le64_to_cpu(fe->id1.dev1.i_rdev));
5986         inode->i_mode = le16_to_cpu(fe->i_mode);
5987 -       inode->i_uid = le32_to_cpu(fe->i_uid);
5988 -       inode->i_gid = le32_to_cpu(fe->i_gid);
5989 +       uid = le32_to_cpu(fe->i_uid);
5990 +       gid = le32_to_cpu(fe->i_gid);
5991 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
5992 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
5993 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid,
5994 +               /* le16_to_cpu(raw_inode->i_raw_tag)i */ 0);
5995  
5996         /* Fast symlinks will have i_size but no allocated clusters. */
5997         if (S_ISLNK(inode->i_mode) && !fe->i_clusters)
5998 diff -NurpP --minimal linux-3.0.25/fs/ocfs2/inode.h linux-3.0.25-vs2.3.2.3/fs/ocfs2/inode.h
5999 --- linux-3.0.25/fs/ocfs2/inode.h       2011-01-05 21:50:26.000000000 +0100
6000 +++ linux-3.0.25-vs2.3.2.3/fs/ocfs2/inode.h     2011-06-10 22:11:24.000000000 +0200
6001 @@ -151,6 +151,7 @@ struct buffer_head *ocfs2_bread(struct i
6002  
6003  void ocfs2_set_inode_flags(struct inode *inode);
6004  void ocfs2_get_inode_flags(struct ocfs2_inode_info *oi);
6005 +int ocfs2_sync_flags(struct inode *inode, int, int);
6006  
6007  static inline blkcnt_t ocfs2_inode_sector_count(struct inode *inode)
6008  {
6009 diff -NurpP --minimal linux-3.0.25/fs/ocfs2/ioctl.c linux-3.0.25-vs2.3.2.3/fs/ocfs2/ioctl.c
6010 --- linux-3.0.25/fs/ocfs2/ioctl.c       2011-07-22 11:18:06.000000000 +0200
6011 +++ linux-3.0.25-vs2.3.2.3/fs/ocfs2/ioctl.c     2011-06-10 22:11:24.000000000 +0200
6012 @@ -78,7 +78,41 @@ static int ocfs2_get_inode_attr(struct i
6013         return status;
6014  }
6015  
6016 -static int ocfs2_set_inode_attr(struct inode *inode, unsigned flags,
6017 +int ocfs2_sync_flags(struct inode *inode, int flags, int vflags)
6018 +{
6019 +       struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
6020 +       struct buffer_head *bh = NULL;
6021 +       handle_t *handle = NULL;
6022 +       int status;
6023 +
6024 +       status = ocfs2_inode_lock(inode, &bh, 1);
6025 +       if (status < 0) {
6026 +               mlog_errno(status);
6027 +               return status;
6028 +       }
6029 +       handle = ocfs2_start_trans(osb, OCFS2_INODE_UPDATE_CREDITS);
6030 +       if (IS_ERR(handle)) {
6031 +               status = PTR_ERR(handle);
6032 +               mlog_errno(status);
6033 +               goto bail_unlock;
6034 +       }
6035 +
6036 +       inode->i_flags = flags;
6037 +       inode->i_vflags = vflags;
6038 +       ocfs2_get_inode_flags(OCFS2_I(inode));
6039 +
6040 +       status = ocfs2_mark_inode_dirty(handle, inode, bh);
6041 +       if (status < 0)
6042 +               mlog_errno(status);
6043 +
6044 +       ocfs2_commit_trans(osb, handle);
6045 +bail_unlock:
6046 +       ocfs2_inode_unlock(inode, 1);
6047 +       brelse(bh);
6048 +       return status;
6049 +}
6050 +
6051 +int ocfs2_set_inode_attr(struct inode *inode, unsigned flags,
6052                                 unsigned mask)
6053  {
6054         struct ocfs2_inode_info *ocfs2_inode = OCFS2_I(inode);
6055 @@ -103,6 +137,11 @@ static int ocfs2_set_inode_attr(struct i
6056         if (!S_ISDIR(inode->i_mode))
6057                 flags &= ~OCFS2_DIRSYNC_FL;
6058  
6059 +       if (IS_BARRIER(inode)) {
6060 +               vxwprintk_task(1, "messing with the barrier.");
6061 +               goto bail_unlock;
6062 +       }
6063 +
6064         handle = ocfs2_start_trans(osb, OCFS2_INODE_UPDATE_CREDITS);
6065         if (IS_ERR(handle)) {
6066                 status = PTR_ERR(handle);
6067 @@ -880,6 +919,7 @@ bail:
6068         return status;
6069  }
6070  
6071 +
6072  long ocfs2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
6073  {
6074         struct inode *inode = filp->f_path.dentry->d_inode;
6075 diff -NurpP --minimal linux-3.0.25/fs/ocfs2/namei.c linux-3.0.25-vs2.3.2.3/fs/ocfs2/namei.c
6076 --- linux-3.0.25/fs/ocfs2/namei.c       2011-05-22 16:17:53.000000000 +0200
6077 +++ linux-3.0.25-vs2.3.2.3/fs/ocfs2/namei.c     2011-06-10 22:11:24.000000000 +0200
6078 @@ -41,6 +41,7 @@
6079  #include <linux/slab.h>
6080  #include <linux/highmem.h>
6081  #include <linux/quotaops.h>
6082 +#include <linux/vs_tag.h>
6083  
6084  #include <cluster/masklog.h>
6085  
6086 @@ -477,6 +478,7 @@ static int __ocfs2_mknod_locked(struct i
6087         struct ocfs2_dinode *fe = NULL;
6088         struct ocfs2_extent_list *fel;
6089         u16 feat;
6090 +       tag_t tag;
6091  
6092         *new_fe_bh = NULL;
6093  
6094 @@ -514,8 +516,11 @@ static int __ocfs2_mknod_locked(struct i
6095         fe->i_suballoc_loc = cpu_to_le64(suballoc_loc);
6096         fe->i_suballoc_bit = cpu_to_le16(suballoc_bit);
6097         fe->i_suballoc_slot = cpu_to_le16(inode_ac->ac_alloc_slot);
6098 -       fe->i_uid = cpu_to_le32(inode->i_uid);
6099 -       fe->i_gid = cpu_to_le32(inode->i_gid);
6100 +
6101 +       tag = dx_current_fstag(osb->sb);
6102 +       fe->i_uid = cpu_to_le32(TAGINO_UID(DX_TAG(inode), inode->i_uid, tag));
6103 +       fe->i_gid = cpu_to_le32(TAGINO_GID(DX_TAG(inode), inode->i_gid, tag));
6104 +       inode->i_tag = tag;
6105         fe->i_mode = cpu_to_le16(inode->i_mode);
6106         if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode))
6107                 fe->id1.dev1.i_rdev = cpu_to_le64(huge_encode_dev(dev));
6108 diff -NurpP --minimal linux-3.0.25/fs/ocfs2/ocfs2.h linux-3.0.25-vs2.3.2.3/fs/ocfs2/ocfs2.h
6109 --- linux-3.0.25/fs/ocfs2/ocfs2.h       2011-05-22 16:17:53.000000000 +0200
6110 +++ linux-3.0.25-vs2.3.2.3/fs/ocfs2/ocfs2.h     2011-06-10 22:11:24.000000000 +0200
6111 @@ -272,6 +272,7 @@ enum ocfs2_mount_options
6112                                                      writes */
6113         OCFS2_MOUNT_HB_NONE = 1 << 13, /* No heartbeat */
6114         OCFS2_MOUNT_HB_GLOBAL = 1 << 14, /* Global heartbeat */
6115 +       OCFS2_MOUNT_TAGGED = 1 << 15, /* use tagging */
6116  };
6117  
6118  #define OCFS2_OSB_SOFT_RO                      0x0001
6119 diff -NurpP --minimal linux-3.0.25/fs/ocfs2/ocfs2_fs.h linux-3.0.25-vs2.3.2.3/fs/ocfs2/ocfs2_fs.h
6120 --- linux-3.0.25/fs/ocfs2/ocfs2_fs.h    2011-05-22 16:17:53.000000000 +0200
6121 +++ linux-3.0.25-vs2.3.2.3/fs/ocfs2/ocfs2_fs.h  2011-06-10 22:11:24.000000000 +0200
6122 @@ -266,6 +266,11 @@
6123  #define OCFS2_TOPDIR_FL                        FS_TOPDIR_FL    /* Top of directory hierarchies*/
6124  #define OCFS2_RESERVED_FL              FS_RESERVED_FL  /* reserved for ext2 lib */
6125  
6126 +#define OCFS2_IXUNLINK_FL              FS_IXUNLINK_FL  /* Immutable invert on unlink */
6127 +
6128 +#define OCFS2_BARRIER_FL               FS_BARRIER_FL   /* Barrier for chroot() */
6129 +#define OCFS2_COW_FL                   FS_COW_FL       /* Copy on Write marker */
6130 +
6131  #define OCFS2_FL_VISIBLE               FS_FL_USER_VISIBLE      /* User visible flags */
6132  #define OCFS2_FL_MODIFIABLE            FS_FL_USER_MODIFIABLE   /* User modifiable flags */
6133  
6134 diff -NurpP --minimal linux-3.0.25/fs/ocfs2/super.c linux-3.0.25-vs2.3.2.3/fs/ocfs2/super.c
6135 --- linux-3.0.25/fs/ocfs2/super.c       2011-07-22 11:18:06.000000000 +0200
6136 +++ linux-3.0.25-vs2.3.2.3/fs/ocfs2/super.c     2011-06-15 02:40:14.000000000 +0200
6137 @@ -184,6 +184,7 @@ enum {
6138         Opt_coherency_full,
6139         Opt_resv_level,
6140         Opt_dir_resv_level,
6141 +       Opt_tag, Opt_notag, Opt_tagid,
6142         Opt_err,
6143  };
6144  
6145 @@ -215,6 +216,9 @@ static const match_table_t tokens = {
6146         {Opt_coherency_full, "coherency=full"},
6147         {Opt_resv_level, "resv_level=%u"},
6148         {Opt_dir_resv_level, "dir_resv_level=%u"},
6149 +       {Opt_tag, "tag"},
6150 +       {Opt_notag, "notag"},
6151 +       {Opt_tagid, "tagid=%u"},
6152         {Opt_err, NULL}
6153  };
6154  
6155 @@ -662,6 +666,13 @@ static int ocfs2_remount(struct super_bl
6156                 goto out;
6157         }
6158  
6159 +       if ((osb->s_mount_opt & OCFS2_MOUNT_TAGGED) !=
6160 +           (parsed_options.mount_opt & OCFS2_MOUNT_TAGGED)) {
6161 +               ret = -EINVAL;
6162 +               mlog(ML_ERROR, "Cannot change tagging on remount\n");
6163 +               goto out;
6164 +       }
6165 +
6166         /* We're going to/from readonly mode. */
6167         if ((*flags & MS_RDONLY) != (sb->s_flags & MS_RDONLY)) {
6168                 /* Disable quota accounting before remounting RO */
6169 @@ -1177,6 +1188,9 @@ static int ocfs2_fill_super(struct super
6170  
6171         ocfs2_complete_mount_recovery(osb);
6172  
6173 +       if (osb->s_mount_opt & OCFS2_MOUNT_TAGGED)
6174 +               sb->s_flags |= MS_TAGGED;
6175 +
6176         if (ocfs2_mount_local(osb))
6177                 snprintf(nodestr, sizeof(nodestr), "local");
6178         else
6179 @@ -1506,6 +1520,20 @@ static int ocfs2_parse_options(struct su
6180                             option < OCFS2_MAX_RESV_LEVEL)
6181                                 mopt->dir_resv_level = option;
6182                         break;
6183 +#ifndef CONFIG_TAGGING_NONE
6184 +               case Opt_tag:
6185 +                       mopt->mount_opt |= OCFS2_MOUNT_TAGGED;
6186 +                       break;
6187 +               case Opt_notag:
6188 +                       mopt->mount_opt &= ~OCFS2_MOUNT_TAGGED;
6189 +                       break;
6190 +#endif
6191 +#ifdef CONFIG_PROPAGATE
6192 +               case Opt_tagid:
6193 +                       /* use args[0] */
6194 +                       mopt->mount_opt |= OCFS2_MOUNT_TAGGED;
6195 +                       break;
6196 +#endif
6197                 default:
6198                         mlog(ML_ERROR,
6199                              "Unrecognized mount option \"%s\" "
6200 diff -NurpP --minimal linux-3.0.25/fs/open.c linux-3.0.25-vs2.3.2.3/fs/open.c
6201 --- linux-3.0.25/fs/open.c      2011-05-22 16:17:53.000000000 +0200
6202 +++ linux-3.0.25-vs2.3.2.3/fs/open.c    2011-06-10 22:11:24.000000000 +0200
6203 @@ -30,6 +30,11 @@
6204  #include <linux/fs_struct.h>
6205  #include <linux/ima.h>
6206  #include <linux/dnotify.h>
6207 +#include <linux/vs_base.h>
6208 +#include <linux/vs_limit.h>
6209 +#include <linux/vs_tag.h>
6210 +#include <linux/vs_cowbl.h>
6211 +#include <linux/vserver/dlimit.h>
6212  
6213  #include "internal.h"
6214  
6215 @@ -494,6 +499,12 @@ SYSCALL_DEFINE3(fchmodat, int, dfd, cons
6216         error = user_path_at(dfd, filename, LOOKUP_FOLLOW, &path);
6217         if (error)
6218                 goto out;
6219 +
6220 +#ifdef CONFIG_VSERVER_COWBL
6221 +       error = cow_check_and_break(&path);
6222 +       if (error)
6223 +               goto dput_and_out;
6224 +#endif
6225         inode = path.dentry->d_inode;
6226  
6227         error = mnt_want_write(path.mnt);
6228 @@ -531,11 +542,11 @@ static int chown_common(struct path *pat
6229         newattrs.ia_valid =  ATTR_CTIME;
6230         if (user != (uid_t) -1) {
6231                 newattrs.ia_valid |= ATTR_UID;
6232 -               newattrs.ia_uid = user;
6233 +               newattrs.ia_uid = dx_map_uid(user);
6234         }
6235         if (group != (gid_t) -1) {
6236                 newattrs.ia_valid |= ATTR_GID;
6237 -               newattrs.ia_gid = group;
6238 +               newattrs.ia_gid = dx_map_gid(group);
6239         }
6240         if (!S_ISDIR(inode->i_mode))
6241                 newattrs.ia_valid |=
6242 @@ -560,6 +571,10 @@ SYSCALL_DEFINE3(chown, const char __user
6243         error = mnt_want_write(path.mnt);
6244         if (error)
6245                 goto out_release;
6246 +#ifdef CONFIG_VSERVER_COWBL
6247 +       error = cow_check_and_break(&path);
6248 +       if (!error)
6249 +#endif
6250         error = chown_common(&path, user, group);
6251         mnt_drop_write(path.mnt);
6252  out_release:
6253 @@ -587,6 +602,10 @@ SYSCALL_DEFINE5(fchownat, int, dfd, cons
6254         error = mnt_want_write(path.mnt);
6255         if (error)
6256                 goto out_release;
6257 +#ifdef CONFIG_VSERVER_COWBL
6258 +       error = cow_check_and_break(&path);
6259 +       if (!error)
6260 +#endif
6261         error = chown_common(&path, user, group);
6262         mnt_drop_write(path.mnt);
6263  out_release:
6264 @@ -606,6 +625,10 @@ SYSCALL_DEFINE3(lchown, const char __use
6265         error = mnt_want_write(path.mnt);
6266         if (error)
6267                 goto out_release;
6268 +#ifdef CONFIG_VSERVER_COWBL
6269 +       error = cow_check_and_break(&path);
6270 +       if (!error)
6271 +#endif
6272         error = chown_common(&path, user, group);
6273         mnt_drop_write(path.mnt);
6274  out_release:
6275 @@ -857,6 +880,7 @@ static void __put_unused_fd(struct files
6276         __FD_CLR(fd, fdt->open_fds);
6277         if (fd < files->next_fd)
6278                 files->next_fd = fd;
6279 +       vx_openfd_dec(fd);
6280  }
6281  
6282  void put_unused_fd(unsigned int fd)
6283 diff -NurpP --minimal linux-3.0.25/fs/proc/array.c linux-3.0.25-vs2.3.2.3/fs/proc/array.c
6284 --- linux-3.0.25/fs/proc/array.c        2011-07-22 11:18:06.000000000 +0200
6285 +++ linux-3.0.25-vs2.3.2.3/fs/proc/array.c      2011-06-10 22:11:24.000000000 +0200
6286 @@ -81,6 +81,8 @@
6287  #include <linux/pid_namespace.h>
6288  #include <linux/ptrace.h>
6289  #include <linux/tracehook.h>
6290 +#include <linux/vs_context.h>
6291 +#include <linux/vs_network.h>
6292  
6293  #include <asm/pgtable.h>
6294  #include <asm/processor.h>
6295 @@ -170,6 +172,9 @@ static inline void task_state(struct seq
6296         rcu_read_lock();
6297         ppid = pid_alive(p) ?
6298                 task_tgid_nr_ns(rcu_dereference(p->real_parent), ns) : 0;
6299 +       if (unlikely(vx_current_initpid(p->pid)))
6300 +               ppid = 0;
6301 +
6302         tpid = 0;
6303         if (pid_alive(p)) {
6304                 struct task_struct *tracer = tracehook_tracer_task(p);
6305 @@ -287,7 +292,7 @@ static inline void task_sig(struct seq_f
6306  }
6307  
6308  static void render_cap_t(struct seq_file *m, const char *header,
6309 -                       kernel_cap_t *a)
6310 +                       struct vx_info *vxi, kernel_cap_t *a)
6311  {
6312         unsigned __capi;
6313  
6314 @@ -312,10 +317,11 @@ static inline void task_cap(struct seq_f
6315         cap_bset        = cred->cap_bset;
6316         rcu_read_unlock();
6317  
6318 -       render_cap_t(m, "CapInh:\t", &cap_inheritable);
6319 -       render_cap_t(m, "CapPrm:\t", &cap_permitted);
6320 -       render_cap_t(m, "CapEff:\t", &cap_effective);
6321 -       render_cap_t(m, "CapBnd:\t", &cap_bset);
6322 +       /* FIXME: maybe move the p->vx_info masking to __task_cred() ? */
6323 +       render_cap_t(m, "CapInh:\t", p->vx_info, &cap_inheritable);
6324 +       render_cap_t(m, "CapPrm:\t", p->vx_info, &cap_permitted);
6325 +       render_cap_t(m, "CapEff:\t", p->vx_info, &cap_effective);
6326 +       render_cap_t(m, "CapBnd:\t", p->vx_info, &cap_bset);
6327  }
6328  
6329  static inline void task_context_switch_counts(struct seq_file *m,
6330 @@ -337,6 +343,42 @@ static void task_cpus_allowed(struct seq
6331         seq_putc(m, '\n');
6332  }
6333  
6334 +int proc_pid_nsproxy(struct seq_file *m, struct pid_namespace *ns,
6335 +                       struct pid *pid, struct task_struct *task)
6336 +{
6337 +       seq_printf(m,   "Proxy:\t%p(%c)\n"
6338 +                       "Count:\t%u\n"
6339 +                       "uts:\t%p(%c)\n"
6340 +                       "ipc:\t%p(%c)\n"
6341 +                       "mnt:\t%p(%c)\n"
6342 +                       "pid:\t%p(%c)\n"
6343 +                       "net:\t%p(%c)\n",
6344 +                       task->nsproxy,
6345 +                       (task->nsproxy == init_task.nsproxy ? 'I' : '-'),
6346 +                       atomic_read(&task->nsproxy->count),
6347 +                       task->nsproxy->uts_ns,
6348 +                       (task->nsproxy->uts_ns == init_task.nsproxy->uts_ns ? 'I' : '-'),
6349 +                       task->nsproxy->ipc_ns,
6350 +                       (task->nsproxy->ipc_ns == init_task.nsproxy->ipc_ns ? 'I' : '-'),
6351 +                       task->nsproxy->mnt_ns,
6352 +                       (task->nsproxy->mnt_ns == init_task.nsproxy->mnt_ns ? 'I' : '-'),
6353 +                       task->nsproxy->pid_ns,
6354 +                       (task->nsproxy->pid_ns == init_task.nsproxy->pid_ns ? 'I' : '-'),
6355 +                       task->nsproxy->net_ns,
6356 +                       (task->nsproxy->net_ns == init_task.nsproxy->net_ns ? 'I' : '-'));
6357 +       return 0;
6358 +}
6359 +
6360 +void task_vs_id(struct seq_file *m, struct task_struct *task)
6361 +{
6362 +       if (task_vx_flags(task, VXF_HIDE_VINFO, 0))
6363 +               return;
6364 +
6365 +       seq_printf(m, "VxID: %d\n", vx_task_xid(task));
6366 +       seq_printf(m, "NxID: %d\n", nx_task_nid(task));
6367 +}
6368 +
6369 +
6370  int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
6371                         struct pid *pid, struct task_struct *task)
6372  {
6373 @@ -353,6 +395,7 @@ int proc_pid_status(struct seq_file *m, 
6374         task_cap(m, task);
6375         task_cpus_allowed(m, task);
6376         cpuset_task_status_allowed(m, task);
6377 +       task_vs_id(m, task);
6378         task_context_switch_counts(m, task);
6379         return 0;
6380  }
6381 @@ -462,6 +505,17 @@ static int do_task_stat(struct seq_file 
6382         /* convert nsec -> ticks */
6383         start_time = nsec_to_clock_t(start_time);
6384  
6385 +       /* fixup start time for virt uptime */
6386 +       if (vx_flags(VXF_VIRT_UPTIME, 0)) {
6387 +               unsigned long long bias =
6388 +                       current->vx_info->cvirt.bias_clock;
6389 +
6390 +               if (start_time > bias)
6391 +                       start_time -= bias;
6392 +               else
6393 +                       start_time = 0;
6394 +       }
6395 +
6396         seq_printf(m, "%d (%s) %c %d %d %d %d %d %u %lu \
6397  %lu %lu %lu %lu %lu %ld %ld %ld %ld %d 0 %llu %lu %ld %lu %lu %lu %lu %lu \
6398  %lu %lu %lu %lu %lu %lu %lu %lu %d %d %u %u %llu %lu %ld\n",
6399 diff -NurpP --minimal linux-3.0.25/fs/proc/base.c linux-3.0.25-vs2.3.2.3/fs/proc/base.c
6400 --- linux-3.0.25/fs/proc/base.c 2012-03-19 21:16:52.000000000 +0100
6401 +++ linux-3.0.25-vs2.3.2.3/fs/proc/base.c       2012-02-15 05:20:43.000000000 +0100
6402 @@ -83,6 +83,8 @@
6403  #include <linux/pid_namespace.h>
6404  #include <linux/fs_struct.h>
6405  #include <linux/slab.h>
6406 +#include <linux/vs_context.h>
6407 +#include <linux/vs_network.h>
6408  #ifdef CONFIG_HARDWALL
6409  #include <asm/hardwall.h>
6410  #endif
6411 @@ -1021,11 +1023,16 @@ static ssize_t oom_adjust_write(struct f
6412                 goto err_task_lock;
6413         }
6414  
6415 -       if (oom_adjust < task->signal->oom_adj && !capable(CAP_SYS_RESOURCE)) {
6416 +       if (oom_adjust < task->signal->oom_adj &&
6417 +               !vx_capable(CAP_SYS_RESOURCE, VXC_OOM_ADJUST)) {
6418                 err = -EACCES;
6419                 goto err_sighand;
6420         }
6421  
6422 +       /* prevent guest processes from circumventing the oom killer */
6423 +       if (vx_current_xid() && (oom_adjust == OOM_DISABLE))
6424 +               oom_adjust = OOM_ADJUST_MIN;
6425 +
6426         if (oom_adjust != task->signal->oom_adj) {
6427                 if (oom_adjust == OOM_DISABLE)
6428                         atomic_inc(&task->mm->oom_disable_count);
6429 @@ -1194,7 +1201,7 @@ static ssize_t proc_loginuid_write(struc
6430         ssize_t length;
6431         uid_t loginuid;
6432  
6433 -       if (!capable(CAP_AUDIT_CONTROL))
6434 +       if (!vx_capable(CAP_AUDIT_CONTROL, VXC_AUDIT_CONTROL))
6435                 return -EPERM;
6436  
6437         rcu_read_lock();
6438 @@ -1641,6 +1648,8 @@ struct inode *proc_pid_make_inode(struct
6439                 inode->i_gid = cred->egid;
6440                 rcu_read_unlock();
6441         }
6442 +       /* procfs is xid tagged */
6443 +       inode->i_tag = (tag_t)vx_task_xid(task);
6444         security_task_to_inode(task, inode);
6445  
6446  out:
6447 @@ -1677,6 +1686,8 @@ int pid_getattr(struct vfsmount *mnt, st
6448  
6449  /* dentry stuff */
6450  
6451 +static unsigned name_to_int(struct dentry *dentry);
6452 +
6453  /*
6454   *     Exceptional case: normally we are not allowed to unhash a busy
6455   * directory. In this case, however, we can do it - no aliasing problems
6456 @@ -1705,6 +1716,12 @@ int pid_revalidate(struct dentry *dentry
6457         task = get_proc_task(inode);
6458  
6459         if (task) {
6460 +               unsigned pid = name_to_int(dentry);
6461 +
6462 +               if (pid != ~0U && pid != vx_map_pid(task->pid)) {
6463 +                       put_task_struct(task);
6464 +                       goto drop;
6465 +               }
6466                 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
6467                     task_dumpable(task)) {
6468                         rcu_read_lock();
6469 @@ -1721,6 +1738,7 @@ int pid_revalidate(struct dentry *dentry
6470                 put_task_struct(task);
6471                 return 1;
6472         }
6473 +drop:
6474         d_drop(dentry);
6475         return 0;
6476  }
6477 @@ -2210,6 +2228,13 @@ static struct dentry *proc_pident_lookup
6478         if (!task)
6479                 goto out_no_task;
6480  
6481 +       /* TODO: maybe we can come up with a generic approach? */
6482 +       if (task_vx_flags(task, VXF_HIDE_VINFO, 0) &&
6483 +               (dentry->d_name.len == 5) &&
6484 +               (!memcmp(dentry->d_name.name, "vinfo", 5) ||
6485 +               !memcmp(dentry->d_name.name, "ninfo", 5)))
6486 +               goto out;
6487 +
6488         /*
6489          * Yes, it does not scale. And it should not. Don't add
6490          * new entries into /proc/<tgid>/ without very good reasons.
6491 @@ -2595,7 +2620,7 @@ out_iput:
6492  static struct dentry *proc_base_lookup(struct inode *dir, struct dentry *dentry)
6493  {
6494         struct dentry *error;
6495 -       struct task_struct *task = get_proc_task(dir);
6496 +       struct task_struct *task = get_proc_task_real(dir);
6497         const struct pid_entry *p, *last;
6498  
6499         error = ERR_PTR(-ENOENT);
6500 @@ -2702,6 +2727,9 @@ static int proc_pid_personality(struct s
6501  static const struct file_operations proc_task_operations;
6502  static const struct inode_operations proc_task_inode_operations;
6503  
6504 +extern int proc_pid_vx_info(struct task_struct *, char *);
6505 +extern int proc_pid_nx_info(struct task_struct *, char *);
6506 +
6507  static const struct pid_entry tgid_base_stuff[] = {
6508         DIR("task",       S_IRUGO|S_IXUGO, proc_task_inode_operations, proc_task_operations),
6509         DIR("fd",         S_IRUSR|S_IXUSR, proc_fd_inode_operations, proc_fd_operations),
6510 @@ -2765,6 +2793,8 @@ static const struct pid_entry tgid_base_
6511  #ifdef CONFIG_CGROUPS
6512         REG("cgroup",  S_IRUGO, proc_cgroup_operations),
6513  #endif
6514 +       INF("vinfo",      S_IRUGO, proc_pid_vx_info),
6515 +       INF("ninfo",      S_IRUGO, proc_pid_nx_info),
6516         INF("oom_score",  S_IRUGO, proc_oom_score),
6517         REG("oom_adj",    S_IRUGO|S_IWUSR, proc_oom_adjust_operations),
6518         REG("oom_score_adj", S_IRUGO|S_IWUSR, proc_oom_score_adj_operations),
6519 @@ -2784,6 +2814,7 @@ static const struct pid_entry tgid_base_
6520  #ifdef CONFIG_HARDWALL
6521         INF("hardwall",   S_IRUGO, proc_pid_hardwall),
6522  #endif
6523 +       ONE("nsproxy",  S_IRUGO, proc_pid_nsproxy),
6524  };
6525  
6526  static int proc_tgid_base_readdir(struct file * filp,
6527 @@ -2976,7 +3007,7 @@ retry:
6528         iter.task = NULL;
6529         pid = find_ge_pid(iter.tgid, ns);
6530         if (pid) {
6531 -               iter.tgid = pid_nr_ns(pid, ns);
6532 +               iter.tgid = pid_unmapped_nr_ns(pid, ns);
6533                 iter.task = pid_task(pid, PIDTYPE_PID);
6534                 /* What we to know is if the pid we have find is the
6535                  * pid of a thread_group_leader.  Testing for task
6536 @@ -3006,7 +3037,7 @@ static int proc_pid_fill_cache(struct fi
6537         struct tgid_iter iter)
6538  {
6539         char name[PROC_NUMBUF];
6540 -       int len = snprintf(name, sizeof(name), "%d", iter.tgid);
6541 +       int len = snprintf(name, sizeof(name), "%d", vx_map_tgid(iter.tgid));
6542         return proc_fill_cache(filp, dirent, filldir, name, len,
6543                                 proc_pid_instantiate, iter.task, NULL);
6544  }
6545 @@ -3023,7 +3054,7 @@ int proc_pid_readdir(struct file * filp,
6546                 goto out_no_task;
6547         nr = filp->f_pos - FIRST_PROCESS_ENTRY;
6548  
6549 -       reaper = get_proc_task(filp->f_path.dentry->d_inode);
6550 +       reaper = get_proc_task_real(filp->f_path.dentry->d_inode);
6551         if (!reaper)
6552                 goto out_no_task;
6553  
6554 @@ -3040,6 +3071,8 @@ int proc_pid_readdir(struct file * filp,
6555              iter.task;
6556              iter.tgid += 1, iter = next_tgid(ns, iter)) {
6557                 filp->f_pos = iter.tgid + TGID_OFFSET;
6558 +               if (!vx_proc_task_visible(iter.task))
6559 +                       continue;
6560                 if (proc_pid_fill_cache(filp, dirent, filldir, iter) < 0) {
6561                         put_task_struct(iter.task);
6562                         goto out;
6563 @@ -3193,6 +3226,8 @@ static struct dentry *proc_task_lookup(s
6564         tid = name_to_int(dentry);
6565         if (tid == ~0U)
6566                 goto out;
6567 +       if (vx_current_initpid(tid))
6568 +               goto out;
6569  
6570         ns = dentry->d_sb->s_fs_info;
6571         rcu_read_lock();
6572 diff -NurpP --minimal linux-3.0.25/fs/proc/generic.c linux-3.0.25-vs2.3.2.3/fs/proc/generic.c
6573 --- linux-3.0.25/fs/proc/generic.c      2011-07-22 11:18:06.000000000 +0200
6574 +++ linux-3.0.25-vs2.3.2.3/fs/proc/generic.c    2011-06-10 22:11:24.000000000 +0200
6575 @@ -22,6 +22,7 @@
6576  #include <linux/bitops.h>
6577  #include <linux/spinlock.h>
6578  #include <linux/completion.h>
6579 +#include <linux/vserver/inode.h>
6580  #include <asm/uaccess.h>
6581  
6582  #include "internal.h"
6583 @@ -424,11 +425,15 @@ struct dentry *proc_lookup_de(struct pro
6584         for (de = de->subdir; de ; de = de->next) {
6585                 if (de->namelen != dentry->d_name.len)
6586                         continue;
6587 +               if (!vx_hide_check(0, de->vx_flags))
6588 +                       continue;
6589                 if (!memcmp(dentry->d_name.name, de->name, de->namelen)) {
6590                         pde_get(de);
6591                         spin_unlock(&proc_subdir_lock);
6592                         error = -EINVAL;
6593                         inode = proc_get_inode(dir->i_sb, de);
6594 +                       /* generic proc entries belong to the host */
6595 +                       inode->i_tag = 0;
6596                         goto out_unlock;
6597                 }
6598         }
6599 @@ -506,6 +511,8 @@ int proc_readdir_de(struct proc_dir_entr
6600  
6601                                 /* filldir passes info to user space */
6602                                 pde_get(de);
6603 +                               if (!vx_hide_check(0, de->vx_flags))
6604 +                                       goto skip;
6605                                 spin_unlock(&proc_subdir_lock);
6606                                 if (filldir(dirent, de->name, de->namelen, filp->f_pos,
6607                                             de->low_ino, de->mode >> 12) < 0) {
6608 @@ -513,6 +520,7 @@ int proc_readdir_de(struct proc_dir_entr
6609                                         goto out;
6610                                 }
6611                                 spin_lock(&proc_subdir_lock);
6612 +                       skip:
6613                                 filp->f_pos++;
6614                                 next = de->next;
6615                                 pde_put(de);
6616 @@ -627,6 +635,7 @@ static struct proc_dir_entry *__proc_cre
6617         ent->nlink = nlink;
6618         atomic_set(&ent->count, 1);
6619         ent->pde_users = 0;
6620 +       ent->vx_flags = IATTR_PROC_DEFAULT;
6621         spin_lock_init(&ent->pde_unload_lock);
6622         ent->pde_unload_completion = NULL;
6623         INIT_LIST_HEAD(&ent->pde_openers);
6624 @@ -650,7 +659,8 @@ struct proc_dir_entry *proc_symlink(cons
6625                                 kfree(ent->data);
6626                                 kfree(ent);
6627                                 ent = NULL;
6628 -                       }
6629 +                       } else
6630 +                               ent->vx_flags = IATTR_PROC_SYMLINK;
6631                 } else {
6632                         kfree(ent);
6633                         ent = NULL;
6634 diff -NurpP --minimal linux-3.0.25/fs/proc/inode.c linux-3.0.25-vs2.3.2.3/fs/proc/inode.c
6635 --- linux-3.0.25/fs/proc/inode.c        2011-07-22 11:18:06.000000000 +0200
6636 +++ linux-3.0.25-vs2.3.2.3/fs/proc/inode.c      2011-06-10 22:11:24.000000000 +0200
6637 @@ -442,6 +442,8 @@ struct inode *proc_get_inode(struct supe
6638                         inode->i_uid = de->uid;
6639                         inode->i_gid = de->gid;
6640                 }
6641 +               if (de->vx_flags)
6642 +                       PROC_I(inode)->vx_flags = de->vx_flags;
6643                 if (de->size)
6644                         inode->i_size = de->size;
6645                 if (de->nlink)
6646 diff -NurpP --minimal linux-3.0.25/fs/proc/internal.h linux-3.0.25-vs2.3.2.3/fs/proc/internal.h
6647 --- linux-3.0.25/fs/proc/internal.h     2011-07-22 11:18:06.000000000 +0200
6648 +++ linux-3.0.25-vs2.3.2.3/fs/proc/internal.h   2011-06-10 22:11:24.000000000 +0200
6649 @@ -10,6 +10,7 @@
6650   */
6651  
6652  #include <linux/proc_fs.h>
6653 +#include <linux/vs_pid.h>
6654  
6655  extern struct proc_dir_entry proc_root;
6656  #ifdef CONFIG_PROC_SYSCTL
6657 @@ -51,6 +52,9 @@ extern int proc_pid_status(struct seq_fi
6658                                 struct pid *pid, struct task_struct *task);
6659  extern int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
6660                                 struct pid *pid, struct task_struct *task);
6661 +extern int proc_pid_nsproxy(struct seq_file *m, struct pid_namespace *ns,
6662 +                               struct pid *pid, struct task_struct *task);
6663 +
6664  extern loff_t mem_lseek(struct file *file, loff_t offset, int orig);
6665  
6666  extern const struct file_operations proc_maps_operations;
6667 @@ -76,11 +80,16 @@ static inline struct pid *proc_pid(struc
6668         return PROC_I(inode)->pid;
6669  }
6670  
6671 -static inline struct task_struct *get_proc_task(struct inode *inode)
6672 +static inline struct task_struct *get_proc_task_real(struct inode *inode)
6673  {
6674         return get_pid_task(proc_pid(inode), PIDTYPE_PID);
6675  }
6676  
6677 +static inline struct task_struct *get_proc_task(struct inode *inode)
6678 +{
6679 +       return vx_get_proc_task(inode, proc_pid(inode));
6680 +}
6681 +
6682  static inline int proc_fd(struct inode *inode)
6683  {
6684         return PROC_I(inode)->fd;
6685 diff -NurpP --minimal linux-3.0.25/fs/proc/loadavg.c linux-3.0.25-vs2.3.2.3/fs/proc/loadavg.c
6686 --- linux-3.0.25/fs/proc/loadavg.c      2009-09-10 15:26:23.000000000 +0200
6687 +++ linux-3.0.25-vs2.3.2.3/fs/proc/loadavg.c    2011-06-10 22:11:24.000000000 +0200
6688 @@ -12,15 +12,27 @@
6689  
6690  static int loadavg_proc_show(struct seq_file *m, void *v)
6691  {
6692 +       unsigned long running;
6693 +       unsigned int threads;
6694         unsigned long avnrun[3];
6695  
6696         get_avenrun(avnrun, FIXED_1/200, 0);
6697  
6698 +       if (vx_flags(VXF_VIRT_LOAD, 0)) {
6699 +               struct vx_info *vxi = current_vx_info();
6700 +
6701 +               running = atomic_read(&vxi->cvirt.nr_running);
6702 +               threads = atomic_read(&vxi->cvirt.nr_threads);
6703 +       } else {
6704 +               running = nr_running();
6705 +               threads = nr_threads;
6706 +       }
6707 +
6708         seq_printf(m, "%lu.%02lu %lu.%02lu %lu.%02lu %ld/%d %d\n",
6709                 LOAD_INT(avnrun[0]), LOAD_FRAC(avnrun[0]),
6710                 LOAD_INT(avnrun[1]), LOAD_FRAC(avnrun[1]),
6711                 LOAD_INT(avnrun[2]), LOAD_FRAC(avnrun[2]),
6712 -               nr_running(), nr_threads,
6713 +               running, threads,
6714                 task_active_pid_ns(current)->last_pid);
6715         return 0;
6716  }
6717 diff -NurpP --minimal linux-3.0.25/fs/proc/meminfo.c linux-3.0.25-vs2.3.2.3/fs/proc/meminfo.c
6718 --- linux-3.0.25/fs/proc/meminfo.c      2012-03-19 21:16:52.000000000 +0100
6719 +++ linux-3.0.25-vs2.3.2.3/fs/proc/meminfo.c    2011-12-23 16:09:00.000000000 +0100
6720 @@ -39,7 +39,8 @@ static int meminfo_proc_show(struct seq_
6721         allowed = ((totalram_pages - hugetlb_total_pages())
6722                 * sysctl_overcommit_ratio / 100) + total_swap_pages;
6723  
6724 -       cached = global_page_state(NR_FILE_PAGES) -
6725 +       cached = vx_flags(VXF_VIRT_MEM, 0) ?
6726 +               vx_vsi_cached(&i) : global_page_state(NR_FILE_PAGES) -
6727                         total_swapcache_pages - i.bufferram;
6728         if (cached < 0)
6729                 cached = 0;
6730 diff -NurpP --minimal linux-3.0.25/fs/proc/root.c linux-3.0.25-vs2.3.2.3/fs/proc/root.c
6731 --- linux-3.0.25/fs/proc/root.c 2011-07-22 11:18:06.000000000 +0200
6732 +++ linux-3.0.25-vs2.3.2.3/fs/proc/root.c       2011-06-22 12:39:15.000000000 +0200
6733 @@ -18,9 +18,14 @@
6734  #include <linux/bitops.h>
6735  #include <linux/mount.h>
6736  #include <linux/pid_namespace.h>
6737 +#include <linux/vserver/inode.h>
6738  
6739  #include "internal.h"
6740  
6741 +struct proc_dir_entry *proc_virtual;
6742 +
6743 +extern void proc_vx_init(void);
6744 +
6745  static int proc_test_super(struct super_block *sb, void *data)
6746  {
6747         return sb->s_fs_info == data;
6748 @@ -125,6 +130,7 @@ void __init proc_root_init(void)
6749  #endif
6750         proc_mkdir("bus", NULL);
6751         proc_sys_init();
6752 +       proc_vx_init();
6753  }
6754  
6755  static int proc_root_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat
6756 @@ -193,6 +199,7 @@ struct proc_dir_entry proc_root = {
6757         .proc_iops      = &proc_root_inode_operations, 
6758         .proc_fops      = &proc_root_operations,
6759         .parent         = &proc_root,
6760 +       .vx_flags       = IATTR_ADMIN | IATTR_WATCH,
6761  };
6762  
6763  int pid_ns_prepare_proc(struct pid_namespace *ns)
6764 diff -NurpP --minimal linux-3.0.25/fs/proc/uptime.c linux-3.0.25-vs2.3.2.3/fs/proc/uptime.c
6765 --- linux-3.0.25/fs/proc/uptime.c       2012-03-19 21:16:52.000000000 +0100
6766 +++ linux-3.0.25-vs2.3.2.3/fs/proc/uptime.c     2012-01-26 08:56:00.000000000 +0100
6767 @@ -5,6 +5,7 @@
6768  #include <linux/seq_file.h>
6769  #include <linux/time.h>
6770  #include <linux/kernel_stat.h>
6771 +#include <linux/vserver/cvirt.h>
6772  #include <asm/cputime.h>
6773  
6774  static int uptime_proc_show(struct seq_file *m, void *v)
6775 @@ -25,6 +26,10 @@ static int uptime_proc_show(struct seq_f
6776         nsec = cputime64_to_jiffies64(idletime) * TICK_NSEC;
6777         idle.tv_sec = div_u64_rem(nsec, NSEC_PER_SEC, &rem);
6778         idle.tv_nsec = rem;
6779 +
6780 +       if (vx_flags(VXF_VIRT_UPTIME, 0))
6781 +               vx_vsi_uptime(&uptime, &idle);
6782 +
6783         seq_printf(m, "%lu.%02lu %lu.%02lu\n",
6784                         (unsigned long) uptime.tv_sec,
6785                         (uptime.tv_nsec / (NSEC_PER_SEC / 100)),
6786 diff -NurpP --minimal linux-3.0.25/fs/quota/dquot.c linux-3.0.25-vs2.3.2.3/fs/quota/dquot.c
6787 --- linux-3.0.25/fs/quota/dquot.c       2011-07-22 11:18:06.000000000 +0200
6788 +++ linux-3.0.25-vs2.3.2.3/fs/quota/dquot.c     2011-06-10 22:11:24.000000000 +0200
6789 @@ -1548,6 +1548,9 @@ int __dquot_alloc_space(struct inode *in
6790         int reserve = flags & DQUOT_SPACE_RESERVE;
6791         int nofail = flags & DQUOT_SPACE_NOFAIL;
6792  
6793 +       if ((ret = dl_alloc_space(inode, number)))
6794 +               return ret;
6795 +
6796         /*
6797          * First test before acquiring mutex - solves deadlocks when we
6798          * re-enter the quota code and are already holding the mutex
6799 @@ -1602,6 +1605,9 @@ int dquot_alloc_inode(const struct inode
6800         int cnt, ret = 0;
6801         char warntype[MAXQUOTAS];
6802  
6803 +       if ((ret = dl_alloc_inode(inode)))
6804 +               return ret;
6805 +
6806         /* First test before acquiring mutex - solves deadlocks when we
6807           * re-enter the quota code and are already holding the mutex */
6808         if (!dquot_active(inode))
6809 @@ -1672,6 +1678,8 @@ void __dquot_free_space(struct inode *in
6810         char warntype[MAXQUOTAS];
6811         int reserve = flags & DQUOT_SPACE_RESERVE;
6812  
6813 +       dl_free_space(inode, number);
6814 +
6815         /* First test before acquiring mutex - solves deadlocks when we
6816           * re-enter the quota code and are already holding the mutex */
6817         if (!dquot_active(inode)) {
6818 @@ -1710,6 +1718,8 @@ void dquot_free_inode(const struct inode
6819         unsigned int cnt;
6820         char warntype[MAXQUOTAS];
6821  
6822 +       dl_free_inode(inode);
6823 +
6824         /* First test before acquiring mutex - solves deadlocks when we
6825           * re-enter the quota code and are already holding the mutex */
6826         if (!dquot_active(inode))
6827 diff -NurpP --minimal linux-3.0.25/fs/quota/quota.c linux-3.0.25-vs2.3.2.3/fs/quota/quota.c
6828 --- linux-3.0.25/fs/quota/quota.c       2012-03-19 21:16:52.000000000 +0100
6829 +++ linux-3.0.25-vs2.3.2.3/fs/quota/quota.c     2011-11-15 17:37:07.000000000 +0100
6830 @@ -8,6 +8,7 @@
6831  #include <linux/fs.h>
6832  #include <linux/namei.h>
6833  #include <linux/slab.h>
6834 +#include <linux/vs_context.h>
6835  #include <asm/current.h>
6836  #include <asm/uaccess.h>
6837  #include <linux/kernel.h>
6838 @@ -38,7 +39,7 @@ static int check_quotactl_permission(str
6839                         break;
6840                 /*FALLTHROUGH*/
6841         default:
6842 -               if (!capable(CAP_SYS_ADMIN))
6843 +               if (!vx_capable(CAP_SYS_ADMIN, VXC_QUOTA_CTL))
6844                         return -EPERM;
6845         }
6846  
6847 @@ -293,6 +294,46 @@ static int do_quotactl(struct super_bloc
6848         }
6849  }
6850  
6851 +#if defined(CONFIG_BLK_DEV_VROOT) || defined(CONFIG_BLK_DEV_VROOT_MODULE)
6852 +
6853 +#include <linux/vroot.h>
6854 +#include <linux/major.h>
6855 +#include <linux/module.h>
6856 +#include <linux/kallsyms.h>
6857 +#include <linux/vserver/debug.h>
6858 +
6859 +static vroot_grb_func *vroot_get_real_bdev = NULL;
6860 +
6861 +static DEFINE_SPINLOCK(vroot_grb_lock);
6862 +
6863 +int register_vroot_grb(vroot_grb_func *func) {
6864 +       int ret = -EBUSY;
6865 +
6866 +       spin_lock(&vroot_grb_lock);
6867 +       if (!vroot_get_real_bdev) {
6868 +               vroot_get_real_bdev = func;
6869 +               ret = 0;
6870 +       }
6871 +       spin_unlock(&vroot_grb_lock);
6872 +       return ret;
6873 +}
6874 +EXPORT_SYMBOL(register_vroot_grb);
6875 +
6876 +int unregister_vroot_grb(vroot_grb_func *func) {
6877 +       int ret = -EINVAL;
6878 +
6879 +       spin_lock(&vroot_grb_lock);
6880 +       if (vroot_get_real_bdev) {
6881 +               vroot_get_real_bdev = NULL;
6882 +               ret = 0;
6883 +       }
6884 +       spin_unlock(&vroot_grb_lock);
6885 +       return ret;
6886 +}
6887 +EXPORT_SYMBOL(unregister_vroot_grb);
6888 +
6889 +#endif
6890 +
6891  /*
6892   * look up a superblock on which quota ops will be performed
6893   * - use the name of a block device to find the superblock thereon
6894 @@ -310,6 +351,22 @@ static struct super_block *quotactl_bloc
6895         putname(tmp);
6896         if (IS_ERR(bdev))
6897                 return ERR_CAST(bdev);
6898 +#if defined(CONFIG_BLK_DEV_VROOT) || defined(CONFIG_BLK_DEV_VROOT_MODULE)
6899 +       if (bdev && bdev->bd_inode &&
6900 +                       imajor(bdev->bd_inode) == VROOT_MAJOR) {
6901 +               struct block_device *bdnew = (void *)-EINVAL;
6902 +
6903 +               if (vroot_get_real_bdev)
6904 +                       bdnew = vroot_get_real_bdev(bdev);
6905 +               else
6906 +                       vxdprintk(VXD_CBIT(misc, 0),
6907 +                                       "vroot_get_real_bdev not set");
6908 +               bdput(bdev);
6909 +               if (IS_ERR(bdnew))
6910 +                       return ERR_PTR(PTR_ERR(bdnew));
6911 +               bdev = bdnew;
6912 +       }
6913 +#endif
6914         sb = get_super(bdev);
6915         bdput(bdev);
6916         if (!sb)
6917 diff -NurpP --minimal linux-3.0.25/fs/reiserfs/file.c linux-3.0.25-vs2.3.2.3/fs/reiserfs/file.c
6918 --- linux-3.0.25/fs/reiserfs/file.c     2011-01-05 21:50:26.000000000 +0100
6919 +++ linux-3.0.25-vs2.3.2.3/fs/reiserfs/file.c   2011-06-10 22:11:24.000000000 +0200
6920 @@ -312,4 +312,5 @@ const struct inode_operations reiserfs_f
6921         .listxattr = reiserfs_listxattr,
6922         .removexattr = reiserfs_removexattr,
6923         .permission = reiserfs_permission,
6924 +       .sync_flags = reiserfs_sync_flags,
6925  };
6926 diff -NurpP --minimal linux-3.0.25/fs/reiserfs/inode.c linux-3.0.25-vs2.3.2.3/fs/reiserfs/inode.c
6927 --- linux-3.0.25/fs/reiserfs/inode.c    2011-05-22 16:17:53.000000000 +0200
6928 +++ linux-3.0.25-vs2.3.2.3/fs/reiserfs/inode.c  2011-06-10 22:11:24.000000000 +0200
6929 @@ -18,6 +18,7 @@
6930  #include <linux/writeback.h>
6931  #include <linux/quotaops.h>
6932  #include <linux/swap.h>
6933 +#include <linux/vs_tag.h>
6934  
6935  int reiserfs_commit_write(struct file *f, struct page *page,
6936                           unsigned from, unsigned to);
6937 @@ -1131,6 +1132,8 @@ static void init_inode(struct inode *ino
6938         struct buffer_head *bh;
6939         struct item_head *ih;
6940         __u32 rdev;
6941 +       uid_t uid;
6942 +       gid_t gid;
6943         //int version = ITEM_VERSION_1;
6944  
6945         bh = PATH_PLAST_BUFFER(path);
6946 @@ -1151,12 +1154,13 @@ static void init_inode(struct inode *ino
6947                     (struct stat_data_v1 *)B_I_PITEM(bh, ih);
6948                 unsigned long blocks;
6949  
6950 +               uid = sd_v1_uid(sd);
6951 +               gid = sd_v1_gid(sd);
6952 +
6953                 set_inode_item_key_version(inode, KEY_FORMAT_3_5);
6954                 set_inode_sd_version(inode, STAT_DATA_V1);
6955                 inode->i_mode = sd_v1_mode(sd);
6956                 inode->i_nlink = sd_v1_nlink(sd);
6957 -               inode->i_uid = sd_v1_uid(sd);
6958 -               inode->i_gid = sd_v1_gid(sd);
6959                 inode->i_size = sd_v1_size(sd);
6960                 inode->i_atime.tv_sec = sd_v1_atime(sd);
6961                 inode->i_mtime.tv_sec = sd_v1_mtime(sd);
6962 @@ -1198,11 +1202,12 @@ static void init_inode(struct inode *ino
6963                 // (directories and symlinks)
6964                 struct stat_data *sd = (struct stat_data *)B_I_PITEM(bh, ih);
6965  
6966 +               uid    = sd_v2_uid(sd);
6967 +               gid    = sd_v2_gid(sd);
6968 +
6969                 inode->i_mode = sd_v2_mode(sd);
6970                 inode->i_nlink = sd_v2_nlink(sd);
6971 -               inode->i_uid = sd_v2_uid(sd);
6972                 inode->i_size = sd_v2_size(sd);
6973 -               inode->i_gid = sd_v2_gid(sd);
6974                 inode->i_mtime.tv_sec = sd_v2_mtime(sd);
6975                 inode->i_atime.tv_sec = sd_v2_atime(sd);
6976                 inode->i_ctime.tv_sec = sd_v2_ctime(sd);
6977 @@ -1232,6 +1237,10 @@ static void init_inode(struct inode *ino
6978                 sd_attrs_to_i_attrs(sd_v2_attrs(sd), inode);
6979         }
6980  
6981 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
6982 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
6983 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid, 0);
6984 +
6985         pathrelse(path);
6986         if (S_ISREG(inode->i_mode)) {
6987                 inode->i_op = &reiserfs_file_inode_operations;
6988 @@ -1254,13 +1263,15 @@ static void init_inode(struct inode *ino
6989  static void inode2sd(void *sd, struct inode *inode, loff_t size)
6990  {
6991         struct stat_data *sd_v2 = (struct stat_data *)sd;
6992 +       uid_t uid = TAGINO_UID(DX_TAG(inode), inode->i_uid, inode->i_tag);
6993 +       gid_t gid = TAGINO_GID(DX_TAG(inode), inode->i_gid, inode->i_tag);
6994         __u16 flags;
6995  
6996 +       set_sd_v2_uid(sd_v2, uid);
6997 +       set_sd_v2_gid(sd_v2, gid);
6998         set_sd_v2_mode(sd_v2, inode->i_mode);
6999         set_sd_v2_nlink(sd_v2, inode->i_nlink);
7000 -       set_sd_v2_uid(sd_v2, inode->i_uid);
7001         set_sd_v2_size(sd_v2, size);
7002 -       set_sd_v2_gid(sd_v2, inode->i_gid);
7003         set_sd_v2_mtime(sd_v2, inode->i_mtime.tv_sec);
7004         set_sd_v2_atime(sd_v2, inode->i_atime.tv_sec);
7005         set_sd_v2_ctime(sd_v2, inode->i_ctime.tv_sec);
7006 @@ -2863,14 +2874,19 @@ int reiserfs_commit_write(struct file *f
7007  void sd_attrs_to_i_attrs(__u16 sd_attrs, struct inode *inode)
7008  {
7009         if (reiserfs_attrs(inode->i_sb)) {
7010 -               if (sd_attrs & REISERFS_SYNC_FL)
7011 -                       inode->i_flags |= S_SYNC;
7012 -               else
7013 -                       inode->i_flags &= ~S_SYNC;
7014                 if (sd_attrs & REISERFS_IMMUTABLE_FL)
7015                         inode->i_flags |= S_IMMUTABLE;
7016                 else
7017                         inode->i_flags &= ~S_IMMUTABLE;
7018 +               if (sd_attrs & REISERFS_IXUNLINK_FL)
7019 +                       inode->i_flags |= S_IXUNLINK;
7020 +               else
7021 +                       inode->i_flags &= ~S_IXUNLINK;
7022 +
7023 +               if (sd_attrs & REISERFS_SYNC_FL)
7024 +                       inode->i_flags |= S_SYNC;
7025 +               else
7026 +                       inode->i_flags &= ~S_SYNC;
7027                 if (sd_attrs & REISERFS_APPEND_FL)
7028                         inode->i_flags |= S_APPEND;
7029                 else
7030 @@ -2883,6 +2899,15 @@ void sd_attrs_to_i_attrs(__u16 sd_attrs,
7031                         REISERFS_I(inode)->i_flags |= i_nopack_mask;
7032                 else
7033                         REISERFS_I(inode)->i_flags &= ~i_nopack_mask;
7034 +
7035 +               if (sd_attrs & REISERFS_BARRIER_FL)
7036 +                       inode->i_vflags |= V_BARRIER;
7037 +               else
7038 +                       inode->i_vflags &= ~V_BARRIER;
7039 +               if (sd_attrs & REISERFS_COW_FL)
7040 +                       inode->i_vflags |= V_COW;
7041 +               else
7042 +                       inode->i_vflags &= ~V_COW;
7043         }
7044  }
7045  
7046 @@ -2893,6 +2918,11 @@ void i_attrs_to_sd_attrs(struct inode *i
7047                         *sd_attrs |= REISERFS_IMMUTABLE_FL;
7048                 else
7049                         *sd_attrs &= ~REISERFS_IMMUTABLE_FL;
7050 +               if (inode->i_flags & S_IXUNLINK)
7051 +                       *sd_attrs |= REISERFS_IXUNLINK_FL;
7052 +               else
7053 +                       *sd_attrs &= ~REISERFS_IXUNLINK_FL;
7054 +
7055                 if (inode->i_flags & S_SYNC)
7056                         *sd_attrs |= REISERFS_SYNC_FL;
7057                 else
7058 @@ -2905,6 +2935,15 @@ void i_attrs_to_sd_attrs(struct inode *i
7059                         *sd_attrs |= REISERFS_NOTAIL_FL;
7060                 else
7061                         *sd_attrs &= ~REISERFS_NOTAIL_FL;
7062 +
7063 +               if (inode->i_vflags & V_BARRIER)
7064 +                       *sd_attrs |= REISERFS_BARRIER_FL;
7065 +               else
7066 +                       *sd_attrs &= ~REISERFS_BARRIER_FL;
7067 +               if (inode->i_vflags & V_COW)
7068 +                       *sd_attrs |= REISERFS_COW_FL;
7069 +               else
7070 +                       *sd_attrs &= ~REISERFS_COW_FL;
7071         }
7072  }
7073  
7074 @@ -3148,7 +3187,8 @@ int reiserfs_setattr(struct dentry *dent
7075         }
7076  
7077         if ((ia_valid & ATTR_UID && attr->ia_uid != inode->i_uid) ||
7078 -           (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid)) {
7079 +           (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid) ||
7080 +           (ia_valid & ATTR_TAG && attr->ia_tag != inode->i_tag)) {
7081                 struct reiserfs_transaction_handle th;
7082                 int jbegin_count =
7083                     2 *
7084 @@ -3177,6 +3217,9 @@ int reiserfs_setattr(struct dentry *dent
7085                         inode->i_uid = attr->ia_uid;
7086                 if (attr->ia_valid & ATTR_GID)
7087                         inode->i_gid = attr->ia_gid;
7088 +                               if ((attr->ia_valid & ATTR_TAG) &&
7089 +                                       IS_TAGGED(inode))
7090 +                                       inode->i_tag = attr->ia_tag;
7091                 mark_inode_dirty(inode);
7092                 error = journal_end(&th, inode->i_sb, jbegin_count);
7093                 if (error)
7094 diff -NurpP --minimal linux-3.0.25/fs/reiserfs/ioctl.c linux-3.0.25-vs2.3.2.3/fs/reiserfs/ioctl.c
7095 --- linux-3.0.25/fs/reiserfs/ioctl.c    2011-05-22 16:17:53.000000000 +0200
7096 +++ linux-3.0.25-vs2.3.2.3/fs/reiserfs/ioctl.c  2011-06-10 22:11:24.000000000 +0200
7097 @@ -11,6 +11,21 @@
7098  #include <linux/pagemap.h>
7099  #include <linux/compat.h>
7100  
7101 +
7102 +int reiserfs_sync_flags(struct inode *inode, int flags, int vflags)
7103 +{
7104 +       __u16 sd_attrs = 0;
7105 +
7106 +       inode->i_flags = flags;
7107 +       inode->i_vflags = vflags;
7108 +
7109 +       i_attrs_to_sd_attrs(inode, &sd_attrs);
7110 +       REISERFS_I(inode)->i_attrs = sd_attrs;
7111 +       inode->i_ctime = CURRENT_TIME_SEC;
7112 +       mark_inode_dirty(inode);
7113 +       return 0;
7114 +}
7115 +
7116  /*
7117   * reiserfs_ioctl - handler for ioctl for inode
7118   * supported commands:
7119 @@ -22,7 +37,7 @@
7120  long reiserfs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
7121  {
7122         struct inode *inode = filp->f_path.dentry->d_inode;
7123 -       unsigned int flags;
7124 +       unsigned int flags, oldflags;
7125         int err = 0;
7126  
7127         reiserfs_write_lock(inode->i_sb);
7128 @@ -47,6 +62,7 @@ long reiserfs_ioctl(struct file *filp, u
7129  
7130                 flags = REISERFS_I(inode)->i_attrs;
7131                 i_attrs_to_sd_attrs(inode, (__u16 *) & flags);
7132 +               flags &= REISERFS_FL_USER_VISIBLE;
7133                 err = put_user(flags, (int __user *)arg);
7134                 break;
7135         case REISERFS_IOC_SETFLAGS:{
7136 @@ -67,6 +83,10 @@ long reiserfs_ioctl(struct file *filp, u
7137                                 err = -EFAULT;
7138                                 goto setflags_out;
7139                         }
7140 +                       if (IS_BARRIER(inode)) {
7141 +                               vxwprintk_task(1, "messing with the barrier.");
7142 +                               return -EACCES;
7143 +                       }
7144                         /*
7145                          * Is it quota file? Do not allow user to mess with it
7146                          */
7147 @@ -91,6 +111,10 @@ long reiserfs_ioctl(struct file *filp, u
7148                                         goto setflags_out;
7149                                 }
7150                         }
7151 +
7152 +                       oldflags = REISERFS_I(inode)->i_attrs;
7153 +                       flags &= REISERFS_FL_USER_MODIFIABLE;
7154 +                       flags |= oldflags & ~REISERFS_FL_USER_MODIFIABLE;
7155                         sd_attrs_to_i_attrs(flags, inode);
7156                         REISERFS_I(inode)->i_attrs = flags;
7157                         inode->i_ctime = CURRENT_TIME_SEC;
7158 diff -NurpP --minimal linux-3.0.25/fs/reiserfs/namei.c linux-3.0.25-vs2.3.2.3/fs/reiserfs/namei.c
7159 --- linux-3.0.25/fs/reiserfs/namei.c    2011-05-22 16:17:53.000000000 +0200
7160 +++ linux-3.0.25-vs2.3.2.3/fs/reiserfs/namei.c  2011-06-10 22:11:24.000000000 +0200
7161 @@ -18,6 +18,7 @@
7162  #include <linux/reiserfs_acl.h>
7163  #include <linux/reiserfs_xattr.h>
7164  #include <linux/quotaops.h>
7165 +#include <linux/vs_tag.h>
7166  
7167  #define INC_DIR_INODE_NLINK(i) if (i->i_nlink != 1) { inc_nlink(i); if (i->i_nlink >= REISERFS_LINK_MAX) i->i_nlink=1; }
7168  #define DEC_DIR_INODE_NLINK(i) if (i->i_nlink != 1) drop_nlink(i);
7169 @@ -362,6 +363,7 @@ static struct dentry *reiserfs_lookup(st
7170         if (retval == IO_ERROR) {
7171                 return ERR_PTR(-EIO);
7172         }
7173 +               dx_propagate_tag(nd, inode);
7174  
7175         return d_splice_alias(inode, dentry);
7176  }
7177 @@ -1529,6 +1531,7 @@ const struct inode_operations reiserfs_d
7178         .listxattr = reiserfs_listxattr,
7179         .removexattr = reiserfs_removexattr,
7180         .permission = reiserfs_permission,
7181 +       .sync_flags = reiserfs_sync_flags,
7182  };
7183  
7184  /*
7185 diff -NurpP --minimal linux-3.0.25/fs/reiserfs/super.c linux-3.0.25-vs2.3.2.3/fs/reiserfs/super.c
7186 --- linux-3.0.25/fs/reiserfs/super.c    2012-03-19 21:16:52.000000000 +0100
7187 +++ linux-3.0.25-vs2.3.2.3/fs/reiserfs/super.c  2012-01-18 02:58:46.000000000 +0100
7188 @@ -903,6 +903,14 @@ static int reiserfs_parse_options(struct
7189                 {"user_xattr",.setmask = 1 << REISERFS_UNSUPPORTED_OPT},
7190                 {"nouser_xattr",.clrmask = 1 << REISERFS_UNSUPPORTED_OPT},
7191  #endif
7192 +#ifndef CONFIG_TAGGING_NONE
7193 +               {"tagxid",.setmask = 1 << REISERFS_TAGGED},
7194 +               {"tag",.setmask = 1 << REISERFS_TAGGED},
7195 +               {"notag",.clrmask = 1 << REISERFS_TAGGED},
7196 +#endif
7197 +#ifdef CONFIG_PROPAGATE
7198 +               {"tag",.arg_required = 'T',.values = NULL},
7199 +#endif
7200  #ifdef CONFIG_REISERFS_FS_POSIX_ACL
7201                 {"acl",.setmask = 1 << REISERFS_POSIXACL},
7202                 {"noacl",.clrmask = 1 << REISERFS_POSIXACL},
7203 @@ -1213,6 +1221,14 @@ static int reiserfs_remount(struct super
7204         handle_quota_files(s, qf_names, &qfmt);
7205  #endif
7206  
7207 +       if ((mount_options & (1 << REISERFS_TAGGED)) &&
7208 +               !(s->s_flags & MS_TAGGED)) {
7209 +               reiserfs_warning(s, "super-vs01",
7210 +                       "reiserfs: tagging not permitted on remount.");
7211 +               err = -EINVAL;
7212 +               goto out_err;
7213 +       }
7214 +
7215         handle_attrs(s);
7216  
7217         /* Add options that are safe here */
7218 @@ -1695,6 +1711,10 @@ static int reiserfs_fill_super(struct su
7219                 goto error;
7220         }
7221  
7222 +       /* map mount option tagxid */
7223 +       if (REISERFS_SB(s)->s_mount_opt & (1 << REISERFS_TAGGED))
7224 +               s->s_flags |= MS_TAGGED;
7225 +
7226         rs = SB_DISK_SUPER_BLOCK(s);
7227         /* Let's do basic sanity check to verify that underlying device is not
7228            smaller than the filesystem. If the check fails then abort and scream,
7229 diff -NurpP --minimal linux-3.0.25/fs/reiserfs/xattr.c linux-3.0.25-vs2.3.2.3/fs/reiserfs/xattr.c
7230 --- linux-3.0.25/fs/reiserfs/xattr.c    2011-07-22 11:18:06.000000000 +0200
7231 +++ linux-3.0.25-vs2.3.2.3/fs/reiserfs/xattr.c  2011-06-22 12:39:15.000000000 +0200
7232 @@ -40,6 +40,7 @@
7233  #include <linux/errno.h>
7234  #include <linux/gfp.h>
7235  #include <linux/fs.h>
7236 +#include <linux/mount.h>
7237  #include <linux/file.h>
7238  #include <linux/pagemap.h>
7239  #include <linux/xattr.h>
7240 diff -NurpP --minimal linux-3.0.25/fs/stat.c linux-3.0.25-vs2.3.2.3/fs/stat.c
7241 --- linux-3.0.25/fs/stat.c      2012-03-19 21:16:52.000000000 +0100
7242 +++ linux-3.0.25-vs2.3.2.3/fs/stat.c    2011-11-15 17:37:07.000000000 +0100
7243 @@ -26,6 +26,7 @@ void generic_fillattr(struct inode *inod
7244         stat->nlink = inode->i_nlink;
7245         stat->uid = inode->i_uid;
7246         stat->gid = inode->i_gid;
7247 +       stat->tag = inode->i_tag;
7248         stat->rdev = inode->i_rdev;
7249         stat->atime = inode->i_atime;
7250         stat->mtime = inode->i_mtime;
7251 diff -NurpP --minimal linux-3.0.25/fs/statfs.c linux-3.0.25-vs2.3.2.3/fs/statfs.c
7252 --- linux-3.0.25/fs/statfs.c    2012-03-19 21:16:52.000000000 +0100
7253 +++ linux-3.0.25-vs2.3.2.3/fs/statfs.c  2011-11-15 17:37:07.000000000 +0100
7254 @@ -7,6 +7,8 @@
7255  #include <linux/statfs.h>
7256  #include <linux/security.h>
7257  #include <linux/uaccess.h>
7258 +#include <linux/vs_base.h>
7259 +#include <linux/vs_dlimit.h>
7260  
7261  static int flags_by_mnt(int mnt_flags)
7262  {
7263 @@ -59,6 +61,8 @@ int statfs_by_dentry(struct dentry *dent
7264         retval = dentry->d_sb->s_op->statfs(dentry, buf);
7265         if (retval == 0 && buf->f_frsize == 0)
7266                 buf->f_frsize = buf->f_bsize;
7267 +       if (!vx_check(0, VS_ADMIN|VS_WATCH))
7268 +               vx_vsi_statfs(dentry->d_sb, buf);
7269         return retval;
7270  }
7271  
7272 diff -NurpP --minimal linux-3.0.25/fs/super.c linux-3.0.25-vs2.3.2.3/fs/super.c
7273 --- linux-3.0.25/fs/super.c     2011-07-22 11:18:06.000000000 +0200
7274 +++ linux-3.0.25-vs2.3.2.3/fs/super.c   2011-07-23 16:49:09.000000000 +0200
7275 @@ -32,6 +32,9 @@
7276  #include <linux/backing-dev.h>
7277  #include <linux/rculist_bl.h>
7278  #include <linux/cleancache.h>
7279 +#include <linux/devpts_fs.h>
7280 +#include <linux/proc_fs.h>
7281 +#include <linux/vs_context.h>
7282  #include "internal.h"
7283  
7284  
7285 @@ -943,6 +946,13 @@ mount_fs(struct file_system_type *type, 
7286         WARN_ON(sb->s_bdi == &default_backing_dev_info);
7287         sb->s_flags |= MS_BORN;
7288  
7289 +       error = -EPERM;
7290 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_BINARY_MOUNT) &&
7291 +               !sb->s_bdev &&
7292 +               (sb->s_magic != PROC_SUPER_MAGIC) &&
7293 +               (sb->s_magic != DEVPTS_SUPER_MAGIC))
7294 +               goto out_sb;
7295 +
7296         error = security_sb_kern_mount(sb, flags, secdata);
7297         if (error)
7298                 goto out_sb;
7299 diff -NurpP --minimal linux-3.0.25/fs/sysfs/mount.c linux-3.0.25-vs2.3.2.3/fs/sysfs/mount.c
7300 --- linux-3.0.25/fs/sysfs/mount.c       2011-07-22 11:18:06.000000000 +0200
7301 +++ linux-3.0.25-vs2.3.2.3/fs/sysfs/mount.c     2011-06-22 12:39:15.000000000 +0200
7302 @@ -47,7 +47,7 @@ static int sysfs_fill_super(struct super
7303  
7304         sb->s_blocksize = PAGE_CACHE_SIZE;
7305         sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
7306 -       sb->s_magic = SYSFS_MAGIC;
7307 +       sb->s_magic = SYSFS_SUPER_MAGIC;
7308         sb->s_op = &sysfs_ops;
7309         sb->s_time_gran = 1;
7310  
7311 diff -NurpP --minimal linux-3.0.25/fs/utimes.c linux-3.0.25-vs2.3.2.3/fs/utimes.c
7312 --- linux-3.0.25/fs/utimes.c    2011-05-22 16:17:54.000000000 +0200
7313 +++ linux-3.0.25-vs2.3.2.3/fs/utimes.c  2011-06-10 22:11:24.000000000 +0200
7314 @@ -8,6 +8,8 @@
7315  #include <linux/stat.h>
7316  #include <linux/utime.h>
7317  #include <linux/syscalls.h>
7318 +#include <linux/mount.h>
7319 +#include <linux/vs_cowbl.h>
7320  #include <asm/uaccess.h>
7321  #include <asm/unistd.h>
7322  
7323 @@ -52,12 +54,18 @@ static int utimes_common(struct path *pa
7324  {
7325         int error;
7326         struct iattr newattrs;
7327 -       struct inode *inode = path->dentry->d_inode;
7328 +       struct inode *inode;
7329  
7330         error = mnt_want_write(path->mnt);
7331         if (error)
7332                 goto out;
7333  
7334 +       error = cow_check_and_break(path);
7335 +       if (error)
7336 +               goto mnt_drop_write_and_out;
7337 +
7338 +       inode = path->dentry->d_inode;
7339 +
7340         if (times && times[0].tv_nsec == UTIME_NOW &&
7341                      times[1].tv_nsec == UTIME_NOW)
7342                 times = NULL;
7343 diff -NurpP --minimal linux-3.0.25/fs/xattr.c linux-3.0.25-vs2.3.2.3/fs/xattr.c
7344 --- linux-3.0.25/fs/xattr.c     2011-07-22 11:18:09.000000000 +0200
7345 +++ linux-3.0.25-vs2.3.2.3/fs/xattr.c   2011-06-10 23:10:19.000000000 +0200
7346 @@ -18,6 +18,7 @@
7347  #include <linux/module.h>
7348  #include <linux/fsnotify.h>
7349  #include <linux/audit.h>
7350 +#include <linux/mount.h>
7351  #include <asm/uaccess.h>
7352  
7353  
7354 @@ -49,7 +50,7 @@ xattr_permission(struct inode *inode, co
7355          * The trusted.* namespace can only be accessed by privileged users.
7356          */
7357         if (!strncmp(name, XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN)) {
7358 -               if (!capable(CAP_SYS_ADMIN))
7359 +               if (!vx_capable(CAP_SYS_ADMIN, VXC_FS_TRUSTED))
7360                         return (mask & MAY_WRITE) ? -EPERM : -ENODATA;
7361                 return 0;
7362         }
7363 diff -NurpP --minimal linux-3.0.25/fs/xfs/linux-2.6/xfs_ioctl.c linux-3.0.25-vs2.3.2.3/fs/xfs/linux-2.6/xfs_ioctl.c
7364 --- linux-3.0.25/fs/xfs/linux-2.6/xfs_ioctl.c   2011-05-22 16:17:54.000000000 +0200
7365 +++ linux-3.0.25-vs2.3.2.3/fs/xfs/linux-2.6/xfs_ioctl.c 2011-06-10 22:11:24.000000000 +0200
7366 @@ -28,7 +28,7 @@
7367  #include "xfs_bmap_btree.h"
7368  #include "xfs_dinode.h"
7369  #include "xfs_inode.h"
7370 -#include "xfs_ioctl.h"
7371 +// #include "xfs_ioctl.h"
7372  #include "xfs_rtalloc.h"
7373  #include "xfs_itable.h"
7374  #include "xfs_error.h"
7375 @@ -748,6 +748,10 @@ xfs_merge_ioc_xflags(
7376                 xflags |= XFS_XFLAG_IMMUTABLE;
7377         else
7378                 xflags &= ~XFS_XFLAG_IMMUTABLE;
7379 +       if (flags & FS_IXUNLINK_FL)
7380 +               xflags |= XFS_XFLAG_IXUNLINK;
7381 +       else
7382 +               xflags &= ~XFS_XFLAG_IXUNLINK;
7383         if (flags & FS_APPEND_FL)
7384                 xflags |= XFS_XFLAG_APPEND;
7385         else
7386 @@ -776,6 +780,8 @@ xfs_di2lxflags(
7387  
7388         if (di_flags & XFS_DIFLAG_IMMUTABLE)
7389                 flags |= FS_IMMUTABLE_FL;
7390 +       if (di_flags & XFS_DIFLAG_IXUNLINK)
7391 +               flags |= FS_IXUNLINK_FL;
7392         if (di_flags & XFS_DIFLAG_APPEND)
7393                 flags |= FS_APPEND_FL;
7394         if (di_flags & XFS_DIFLAG_SYNC)
7395 @@ -836,6 +842,8 @@ xfs_set_diflags(
7396         di_flags = (ip->i_d.di_flags & XFS_DIFLAG_PREALLOC);
7397         if (xflags & XFS_XFLAG_IMMUTABLE)
7398                 di_flags |= XFS_DIFLAG_IMMUTABLE;
7399 +       if (xflags & XFS_XFLAG_IXUNLINK)
7400 +               di_flags |= XFS_DIFLAG_IXUNLINK;
7401         if (xflags & XFS_XFLAG_APPEND)
7402                 di_flags |= XFS_DIFLAG_APPEND;
7403         if (xflags & XFS_XFLAG_SYNC)
7404 @@ -878,6 +886,10 @@ xfs_diflags_to_linux(
7405                 inode->i_flags |= S_IMMUTABLE;
7406         else
7407                 inode->i_flags &= ~S_IMMUTABLE;
7408 +       if (xflags & XFS_XFLAG_IXUNLINK)
7409 +               inode->i_flags |= S_IXUNLINK;
7410 +       else
7411 +               inode->i_flags &= ~S_IXUNLINK;
7412         if (xflags & XFS_XFLAG_APPEND)
7413                 inode->i_flags |= S_APPEND;
7414         else
7415 @@ -1370,10 +1382,18 @@ xfs_file_ioctl(
7416         case XFS_IOC_FSGETXATTRA:
7417                 return xfs_ioc_fsgetxattr(ip, 1, arg);
7418         case XFS_IOC_FSSETXATTR:
7419 +               if (IS_BARRIER(inode)) {
7420 +                       vxwprintk_task(1, "messing with the barrier.");
7421 +                       return -XFS_ERROR(EACCES);
7422 +               }
7423                 return xfs_ioc_fssetxattr(ip, filp, arg);
7424         case XFS_IOC_GETXFLAGS:
7425                 return xfs_ioc_getxflags(ip, arg);
7426         case XFS_IOC_SETXFLAGS:
7427 +               if (IS_BARRIER(inode)) {
7428 +                       vxwprintk_task(1, "messing with the barrier.");
7429 +                       return -XFS_ERROR(EACCES);
7430 +               }
7431                 return xfs_ioc_setxflags(ip, filp, arg);
7432  
7433         case XFS_IOC_FSSETDM: {
7434 diff -NurpP --minimal linux-3.0.25/fs/xfs/linux-2.6/xfs_ioctl.h linux-3.0.25-vs2.3.2.3/fs/xfs/linux-2.6/xfs_ioctl.h
7435 --- linux-3.0.25/fs/xfs/linux-2.6/xfs_ioctl.h   2010-07-07 18:31:54.000000000 +0200
7436 +++ linux-3.0.25-vs2.3.2.3/fs/xfs/linux-2.6/xfs_ioctl.h 2011-06-10 22:11:24.000000000 +0200
7437 @@ -70,6 +70,12 @@ xfs_handle_to_dentry(
7438         void __user             *uhandle,
7439         u32                     hlen);
7440  
7441 +extern int
7442 +xfs_sync_flags(
7443 +       struct inode            *inode,
7444 +       int                     flags,
7445 +       int                     vflags);
7446 +
7447  extern long
7448  xfs_file_ioctl(
7449         struct file             *filp,
7450 diff -NurpP --minimal linux-3.0.25/fs/xfs/linux-2.6/xfs_iops.c linux-3.0.25-vs2.3.2.3/fs/xfs/linux-2.6/xfs_iops.c
7451 --- linux-3.0.25/fs/xfs/linux-2.6/xfs_iops.c    2012-03-19 21:16:52.000000000 +0100
7452 +++ linux-3.0.25-vs2.3.2.3/fs/xfs/linux-2.6/xfs_iops.c  2011-12-19 15:55:53.000000000 +0100
7453 @@ -30,6 +30,7 @@
7454  #include "xfs_bmap_btree.h"
7455  #include "xfs_dinode.h"
7456  #include "xfs_inode.h"
7457 +#include "xfs_ioctl.h"
7458  #include "xfs_bmap.h"
7459  #include "xfs_rtalloc.h"
7460  #include "xfs_error.h"
7461 @@ -48,6 +49,7 @@
7462  #include <linux/security.h>
7463  #include <linux/fiemap.h>
7464  #include <linux/slab.h>
7465 +#include <linux/vs_tag.h>
7466  
7467  /*
7468   * Bring the timestamps in the XFS inode uptodate.
7469 @@ -472,6 +474,7 @@ xfs_vn_getattr(
7470         stat->nlink = ip->i_d.di_nlink;
7471         stat->uid = ip->i_d.di_uid;
7472         stat->gid = ip->i_d.di_gid;
7473 +       stat->tag = ip->i_d.di_tag;
7474         stat->ino = ip->i_ino;
7475         stat->atime = inode->i_atime;
7476         stat->mtime = inode->i_mtime;
7477 @@ -607,6 +610,7 @@ static const struct inode_operations xfs
7478         .removexattr            = generic_removexattr,
7479         .listxattr              = xfs_vn_listxattr,
7480         .fiemap                 = xfs_vn_fiemap,
7481 +       .sync_flags             = xfs_sync_flags,
7482  };
7483  
7484  static const struct inode_operations xfs_dir_inode_operations = {
7485 @@ -632,6 +636,7 @@ static const struct inode_operations xfs
7486         .getxattr               = generic_getxattr,
7487         .removexattr            = generic_removexattr,
7488         .listxattr              = xfs_vn_listxattr,
7489 +       .sync_flags             = xfs_sync_flags,
7490  };
7491  
7492  static const struct inode_operations xfs_dir_ci_inode_operations = {
7493 @@ -681,6 +686,10 @@ xfs_diflags_to_iflags(
7494                 inode->i_flags |= S_IMMUTABLE;
7495         else
7496                 inode->i_flags &= ~S_IMMUTABLE;
7497 +       if (ip->i_d.di_flags & XFS_DIFLAG_IXUNLINK)
7498 +               inode->i_flags |= S_IXUNLINK;
7499 +       else
7500 +               inode->i_flags &= ~S_IXUNLINK;
7501         if (ip->i_d.di_flags & XFS_DIFLAG_APPEND)
7502                 inode->i_flags |= S_APPEND;
7503         else
7504 @@ -693,6 +702,15 @@ xfs_diflags_to_iflags(
7505                 inode->i_flags |= S_NOATIME;
7506         else
7507                 inode->i_flags &= ~S_NOATIME;
7508 +
7509 +       if (ip->i_d.di_vflags & XFS_DIVFLAG_BARRIER)
7510 +               inode->i_vflags |= V_BARRIER;
7511 +       else
7512 +               inode->i_vflags &= ~V_BARRIER;
7513 +       if (ip->i_d.di_vflags & XFS_DIVFLAG_COW)
7514 +               inode->i_vflags |= V_COW;
7515 +       else
7516 +               inode->i_vflags &= ~V_COW;
7517  }
7518  
7519  /*
7520 @@ -724,6 +742,7 @@ xfs_setup_inode(
7521         inode->i_nlink  = ip->i_d.di_nlink;
7522         inode->i_uid    = ip->i_d.di_uid;
7523         inode->i_gid    = ip->i_d.di_gid;
7524 +       inode->i_tag    = ip->i_d.di_tag;
7525  
7526         switch (inode->i_mode & S_IFMT) {
7527         case S_IFBLK:
7528 diff -NurpP --minimal linux-3.0.25/fs/xfs/linux-2.6/xfs_linux.h linux-3.0.25-vs2.3.2.3/fs/xfs/linux-2.6/xfs_linux.h
7529 --- linux-3.0.25/fs/xfs/linux-2.6/xfs_linux.h   2012-03-19 21:16:52.000000000 +0100
7530 +++ linux-3.0.25-vs2.3.2.3/fs/xfs/linux-2.6/xfs_linux.h 2011-11-15 17:37:07.000000000 +0100
7531 @@ -117,6 +117,7 @@
7532  
7533  #define current_cpu()          (raw_smp_processor_id())
7534  #define current_pid()          (current->pid)
7535 +#define current_fstag(vp)      (dx_current_fstag((vp)->i_sb))
7536  #define current_test_flags(f)  (current->flags & (f))
7537  #define current_set_flags_nested(sp, f)                \
7538                 (*(sp) = current->flags, current->flags |= (f))
7539 diff -NurpP --minimal linux-3.0.25/fs/xfs/linux-2.6/xfs_super.c linux-3.0.25-vs2.3.2.3/fs/xfs/linux-2.6/xfs_super.c
7540 --- linux-3.0.25/fs/xfs/linux-2.6/xfs_super.c   2012-03-19 21:16:52.000000000 +0100
7541 +++ linux-3.0.25-vs2.3.2.3/fs/xfs/linux-2.6/xfs_super.c 2012-01-10 09:19:13.000000000 +0100
7542 @@ -114,6 +114,9 @@ mempool_t *xfs_ioend_pool;
7543  #define MNTOPT_NODELAYLOG  "nodelaylog"        /* Delayed logging disabled */
7544  #define MNTOPT_DISCARD    "discard"    /* Discard unused blocks */
7545  #define MNTOPT_NODISCARD   "nodiscard" /* Do not discard unused blocks */
7546 +#define MNTOPT_TAGXID  "tagxid"        /* context tagging for inodes */
7547 +#define MNTOPT_TAGGED  "tag"           /* context tagging for inodes */
7548 +#define MNTOPT_NOTAGTAG        "notag"         /* do not use context tagging */
7549  
7550  /*
7551   * Table driven mount option parser.
7552 @@ -122,10 +125,14 @@ mempool_t *xfs_ioend_pool;
7553   * in the future, too.
7554   */
7555  enum {
7556 +       Opt_tag, Opt_notag,
7557         Opt_barrier, Opt_nobarrier, Opt_err
7558  };
7559  
7560  static const match_table_t tokens = {
7561 +       {Opt_tag, "tagxid"},
7562 +       {Opt_tag, "tag"},
7563 +       {Opt_notag, "notag"},
7564         {Opt_barrier, "barrier"},
7565         {Opt_nobarrier, "nobarrier"},
7566         {Opt_err, NULL}
7567 @@ -373,6 +380,19 @@ xfs_parseargs(
7568                 } else if (!strcmp(this_char, "irixsgid")) {
7569                         xfs_warn(mp,
7570         "irixsgid is now a sysctl(2) variable, option is deprecated.");
7571 +#ifndef CONFIG_TAGGING_NONE
7572 +               } else if (!strcmp(this_char, MNTOPT_TAGGED)) {
7573 +                       mp->m_flags |= XFS_MOUNT_TAGGED;
7574 +               } else if (!strcmp(this_char, MNTOPT_NOTAGTAG)) {
7575 +                       mp->m_flags &= ~XFS_MOUNT_TAGGED;
7576 +               } else if (!strcmp(this_char, MNTOPT_TAGXID)) {
7577 +                       mp->m_flags |= XFS_MOUNT_TAGGED;
7578 +#endif
7579 +#ifdef CONFIG_PROPAGATE
7580 +               } else if (!strcmp(this_char, MNTOPT_TAGGED)) {
7581 +                       /* use value */
7582 +                       mp->m_flags |= XFS_MOUNT_TAGGED;
7583 +#endif
7584                 } else {
7585                         xfs_warn(mp, "unknown mount option [%s].", this_char);
7586                         return EINVAL;
7587 @@ -1146,6 +1166,16 @@ xfs_fs_remount(
7588                 case Opt_nobarrier:
7589                         mp->m_flags &= ~XFS_MOUNT_BARRIER;
7590                         break;
7591 +               case Opt_tag:
7592 +                       if (!(sb->s_flags & MS_TAGGED)) {
7593 +                               printk(KERN_INFO
7594 +                                       "XFS: %s: tagging not permitted on remount.\n",
7595 +                                       sb->s_id);
7596 +                               return -EINVAL;
7597 +                       }
7598 +                       break;
7599 +               case Opt_notag:
7600 +                       break;
7601                 default:
7602                         /*
7603                          * Logically we would return an error here to prevent
7604 @@ -1361,6 +1391,9 @@ xfs_fs_fill_super(
7605         if (error)
7606                 goto out_free_sb;
7607  
7608 +       if (mp->m_flags & XFS_MOUNT_TAGGED)
7609 +               sb->s_flags |= MS_TAGGED;
7610 +
7611         /*
7612          * we must configure the block size in the superblock before we run the
7613          * full mount process as the mount process can lookup and cache inodes.
7614 diff -NurpP --minimal linux-3.0.25/fs/xfs/xfs_dinode.h linux-3.0.25-vs2.3.2.3/fs/xfs/xfs_dinode.h
7615 --- linux-3.0.25/fs/xfs/xfs_dinode.h    2011-01-05 21:50:28.000000000 +0100
7616 +++ linux-3.0.25-vs2.3.2.3/fs/xfs/xfs_dinode.h  2011-06-10 22:11:24.000000000 +0200
7617 @@ -51,7 +51,9 @@ typedef struct xfs_dinode {
7618         __be32          di_nlink;       /* number of links to file */
7619         __be16          di_projid_lo;   /* lower part of owner's project id */
7620         __be16          di_projid_hi;   /* higher part owner's project id */
7621 -       __u8            di_pad[6];      /* unused, zeroed space */
7622 +       __u8            di_pad[2];      /* unused, zeroed space */
7623 +       __be16          di_tag;         /* context tagging */
7624 +       __be16          di_vflags;      /* vserver specific flags */
7625         __be16          di_flushiter;   /* incremented on flush */
7626         xfs_timestamp_t di_atime;       /* time last accessed */
7627         xfs_timestamp_t di_mtime;       /* time last modified */
7628 @@ -184,6 +186,8 @@ static inline void xfs_dinode_put_rdev(s
7629  #define XFS_DIFLAG_EXTSZINHERIT_BIT 12 /* inherit inode extent size */
7630  #define XFS_DIFLAG_NODEFRAG_BIT     13 /* do not reorganize/defragment */
7631  #define XFS_DIFLAG_FILESTREAM_BIT   14  /* use filestream allocator */
7632 +#define XFS_DIFLAG_IXUNLINK_BIT     15 /* Immutable inver on unlink */
7633 +
7634  #define XFS_DIFLAG_REALTIME      (1 << XFS_DIFLAG_REALTIME_BIT)
7635  #define XFS_DIFLAG_PREALLOC      (1 << XFS_DIFLAG_PREALLOC_BIT)
7636  #define XFS_DIFLAG_NEWRTBM       (1 << XFS_DIFLAG_NEWRTBM_BIT)
7637 @@ -199,6 +203,7 @@ static inline void xfs_dinode_put_rdev(s
7638  #define XFS_DIFLAG_EXTSZINHERIT  (1 << XFS_DIFLAG_EXTSZINHERIT_BIT)
7639  #define XFS_DIFLAG_NODEFRAG      (1 << XFS_DIFLAG_NODEFRAG_BIT)
7640  #define XFS_DIFLAG_FILESTREAM    (1 << XFS_DIFLAG_FILESTREAM_BIT)
7641 +#define XFS_DIFLAG_IXUNLINK      (1 << XFS_DIFLAG_IXUNLINK_BIT)
7642  
7643  #ifdef CONFIG_XFS_RT
7644  #define XFS_IS_REALTIME_INODE(ip) ((ip)->i_d.di_flags & XFS_DIFLAG_REALTIME)
7645 @@ -211,6 +216,10 @@ static inline void xfs_dinode_put_rdev(s
7646          XFS_DIFLAG_IMMUTABLE | XFS_DIFLAG_APPEND | XFS_DIFLAG_SYNC | \
7647          XFS_DIFLAG_NOATIME | XFS_DIFLAG_NODUMP | XFS_DIFLAG_RTINHERIT | \
7648          XFS_DIFLAG_PROJINHERIT | XFS_DIFLAG_NOSYMLINKS | XFS_DIFLAG_EXTSIZE | \
7649 -        XFS_DIFLAG_EXTSZINHERIT | XFS_DIFLAG_NODEFRAG | XFS_DIFLAG_FILESTREAM)
7650 +        XFS_DIFLAG_EXTSZINHERIT | XFS_DIFLAG_NODEFRAG | XFS_DIFLAG_FILESTREAM | \
7651 +        XFS_DIFLAG_IXUNLINK)
7652 +
7653 +#define XFS_DIVFLAG_BARRIER    0x01
7654 +#define XFS_DIVFLAG_COW                0x02
7655  
7656  #endif /* __XFS_DINODE_H__ */
7657 diff -NurpP --minimal linux-3.0.25/fs/xfs/xfs_fs.h linux-3.0.25-vs2.3.2.3/fs/xfs/xfs_fs.h
7658 --- linux-3.0.25/fs/xfs/xfs_fs.h        2011-01-05 21:50:28.000000000 +0100
7659 +++ linux-3.0.25-vs2.3.2.3/fs/xfs/xfs_fs.h      2011-06-10 22:11:24.000000000 +0200
7660 @@ -67,6 +67,9 @@ struct fsxattr {
7661  #define XFS_XFLAG_EXTSZINHERIT 0x00001000      /* inherit inode extent size */
7662  #define XFS_XFLAG_NODEFRAG     0x00002000      /* do not defragment */
7663  #define XFS_XFLAG_FILESTREAM   0x00004000      /* use filestream allocator */
7664 +#define XFS_XFLAG_IXUNLINK     0x00008000      /* immutable invert on unlink */
7665 +#define XFS_XFLAG_BARRIER      0x10000000      /* chroot() barrier */
7666 +#define XFS_XFLAG_COW          0x20000000      /* copy on write mark */
7667  #define XFS_XFLAG_HASATTR      0x80000000      /* no DIFLAG for this   */
7668  
7669  /*
7670 @@ -297,7 +300,8 @@ typedef struct xfs_bstat {
7671  #define        bs_projid       bs_projid_lo    /* (previously just bs_projid)  */
7672         __u16           bs_forkoff;     /* inode fork offset in bytes   */
7673         __u16           bs_projid_hi;   /* higher part of project id    */
7674 -       unsigned char   bs_pad[10];     /* pad space, unused            */
7675 +       unsigned char   bs_pad[8];      /* pad space, unused            */
7676 +       __u16           bs_tag;         /* context tagging              */
7677         __u32           bs_dmevmask;    /* DMIG event mask              */
7678         __u16           bs_dmstate;     /* DMIG state info              */
7679         __u16           bs_aextents;    /* attribute number of extents  */
7680 diff -NurpP --minimal linux-3.0.25/fs/xfs/xfs_ialloc.c linux-3.0.25-vs2.3.2.3/fs/xfs/xfs_ialloc.c
7681 --- linux-3.0.25/fs/xfs/xfs_ialloc.c    2011-05-22 16:17:54.000000000 +0200
7682 +++ linux-3.0.25-vs2.3.2.3/fs/xfs/xfs_ialloc.c  2011-06-10 22:11:24.000000000 +0200
7683 @@ -37,7 +37,6 @@
7684  #include "xfs_error.h"
7685  #include "xfs_bmap.h"
7686  
7687 -
7688  /*
7689   * Allocation group level functions.
7690   */
7691 diff -NurpP --minimal linux-3.0.25/fs/xfs/xfs_inode.c linux-3.0.25-vs2.3.2.3/fs/xfs/xfs_inode.c
7692 --- linux-3.0.25/fs/xfs/xfs_inode.c     2012-03-19 21:16:52.000000000 +0100
7693 +++ linux-3.0.25-vs2.3.2.3/fs/xfs/xfs_inode.c   2011-12-23 16:09:00.000000000 +0100
7694 @@ -243,6 +243,7 @@ xfs_inotobp(
7695         return 0;
7696  }
7697  
7698 +#include <linux/vs_tag.h>
7699  
7700  /*
7701   * This routine is called to map an inode to the buffer containing
7702 @@ -641,15 +642,25 @@ xfs_iformat_btree(
7703  STATIC void
7704  xfs_dinode_from_disk(
7705         xfs_icdinode_t          *to,
7706 -       xfs_dinode_t            *from)
7707 +       xfs_dinode_t            *from,
7708 +       int tagged)
7709  {
7710 +       uint32_t uid, gid, tag;
7711 +
7712         to->di_magic = be16_to_cpu(from->di_magic);
7713         to->di_mode = be16_to_cpu(from->di_mode);
7714         to->di_version = from ->di_version;
7715         to->di_format = from->di_format;
7716         to->di_onlink = be16_to_cpu(from->di_onlink);
7717 -       to->di_uid = be32_to_cpu(from->di_uid);
7718 -       to->di_gid = be32_to_cpu(from->di_gid);
7719 +
7720 +       uid = be32_to_cpu(from->di_uid);
7721 +       gid = be32_to_cpu(from->di_gid);
7722 +       tag = be16_to_cpu(from->di_tag);
7723 +
7724 +       to->di_uid = INOTAG_UID(tagged, uid, gid);
7725 +       to->di_gid = INOTAG_GID(tagged, uid, gid);
7726 +       to->di_tag = INOTAG_TAG(tagged, uid, gid, tag);
7727 +
7728         to->di_nlink = be32_to_cpu(from->di_nlink);
7729         to->di_projid_lo = be16_to_cpu(from->di_projid_lo);
7730         to->di_projid_hi = be16_to_cpu(from->di_projid_hi);
7731 @@ -671,21 +682,26 @@ xfs_dinode_from_disk(
7732         to->di_dmevmask = be32_to_cpu(from->di_dmevmask);
7733         to->di_dmstate  = be16_to_cpu(from->di_dmstate);
7734         to->di_flags    = be16_to_cpu(from->di_flags);
7735 +       to->di_vflags   = be16_to_cpu(from->di_vflags);
7736         to->di_gen      = be32_to_cpu(from->di_gen);
7737  }
7738  
7739  void
7740  xfs_dinode_to_disk(
7741         xfs_dinode_t            *to,
7742 -       xfs_icdinode_t          *from)
7743 +       xfs_icdinode_t          *from,
7744 +       int tagged)
7745  {
7746         to->di_magic = cpu_to_be16(from->di_magic);
7747         to->di_mode = cpu_to_be16(from->di_mode);
7748         to->di_version = from ->di_version;
7749         to->di_format = from->di_format;
7750         to->di_onlink = cpu_to_be16(from->di_onlink);
7751 -       to->di_uid = cpu_to_be32(from->di_uid);
7752 -       to->di_gid = cpu_to_be32(from->di_gid);
7753 +
7754 +       to->di_uid = cpu_to_be32(TAGINO_UID(tagged, from->di_uid, from->di_tag));
7755 +       to->di_gid = cpu_to_be32(TAGINO_GID(tagged, from->di_gid, from->di_tag));
7756 +       to->di_tag = cpu_to_be16(TAGINO_TAG(tagged, from->di_tag));
7757 +
7758         to->di_nlink = cpu_to_be32(from->di_nlink);
7759         to->di_projid_lo = cpu_to_be16(from->di_projid_lo);
7760         to->di_projid_hi = cpu_to_be16(from->di_projid_hi);
7761 @@ -707,12 +723,14 @@ xfs_dinode_to_disk(
7762         to->di_dmevmask = cpu_to_be32(from->di_dmevmask);
7763         to->di_dmstate = cpu_to_be16(from->di_dmstate);
7764         to->di_flags = cpu_to_be16(from->di_flags);
7765 +       to->di_vflags = cpu_to_be16(from->di_vflags);
7766         to->di_gen = cpu_to_be32(from->di_gen);
7767  }
7768  
7769  STATIC uint
7770  _xfs_dic2xflags(
7771 -       __uint16_t              di_flags)
7772 +       __uint16_t              di_flags,
7773 +       __uint16_t              di_vflags)
7774  {
7775         uint                    flags = 0;
7776  
7777 @@ -723,6 +741,8 @@ _xfs_dic2xflags(
7778                         flags |= XFS_XFLAG_PREALLOC;
7779                 if (di_flags & XFS_DIFLAG_IMMUTABLE)
7780                         flags |= XFS_XFLAG_IMMUTABLE;
7781 +               if (di_flags & XFS_DIFLAG_IXUNLINK)
7782 +                       flags |= XFS_XFLAG_IXUNLINK;
7783                 if (di_flags & XFS_DIFLAG_APPEND)
7784                         flags |= XFS_XFLAG_APPEND;
7785                 if (di_flags & XFS_DIFLAG_SYNC)
7786 @@ -747,6 +767,10 @@ _xfs_dic2xflags(
7787                         flags |= XFS_XFLAG_FILESTREAM;
7788         }
7789  
7790 +       if (di_vflags & XFS_DIVFLAG_BARRIER)
7791 +               flags |= FS_BARRIER_FL;
7792 +       if (di_vflags & XFS_DIVFLAG_COW)
7793 +               flags |= FS_COW_FL;
7794         return flags;
7795  }
7796  
7797 @@ -756,7 +780,7 @@ xfs_ip2xflags(
7798  {
7799         xfs_icdinode_t          *dic = &ip->i_d;
7800  
7801 -       return _xfs_dic2xflags(dic->di_flags) |
7802 +       return _xfs_dic2xflags(dic->di_flags, dic->di_vflags) |
7803                                 (XFS_IFORK_Q(ip) ? XFS_XFLAG_HASATTR : 0);
7804  }
7805  
7806 @@ -764,7 +788,8 @@ uint
7807  xfs_dic2xflags(
7808         xfs_dinode_t            *dip)
7809  {
7810 -       return _xfs_dic2xflags(be16_to_cpu(dip->di_flags)) |
7811 +       return _xfs_dic2xflags(be16_to_cpu(dip->di_flags),
7812 +                               be16_to_cpu(dip->di_vflags)) |
7813                                 (XFS_DFORK_Q(dip) ? XFS_XFLAG_HASATTR : 0);
7814  }
7815  
7816 @@ -797,7 +822,6 @@ xfs_iread(
7817         if (error)
7818                 return error;
7819         dip = (xfs_dinode_t *)xfs_buf_offset(bp, ip->i_imap.im_boffset);
7820 -
7821         /*
7822          * If we got something that isn't an inode it means someone
7823          * (nfs or dmi) has a stale handle.
7824 @@ -820,7 +844,8 @@ xfs_iread(
7825          * Otherwise, just get the truly permanent information.
7826          */
7827         if (dip->di_mode) {
7828 -               xfs_dinode_from_disk(&ip->i_d, dip);
7829 +               xfs_dinode_from_disk(&ip->i_d, dip,
7830 +                       mp->m_flags & XFS_MOUNT_TAGGED);
7831                 error = xfs_iformat(ip, dip);
7832                 if (error)  {
7833  #ifdef DEBUG
7834 @@ -1015,6 +1040,7 @@ xfs_ialloc(
7835         ASSERT(ip->i_d.di_nlink == nlink);
7836         ip->i_d.di_uid = current_fsuid();
7837         ip->i_d.di_gid = current_fsgid();
7838 +       ip->i_d.di_tag = current_fstag(&ip->i_vnode);
7839         xfs_set_projid(ip, prid);
7840         memset(&(ip->i_d.di_pad[0]), 0, sizeof(ip->i_d.di_pad));
7841  
7842 @@ -1075,6 +1101,7 @@ xfs_ialloc(
7843         ip->i_d.di_dmevmask = 0;
7844         ip->i_d.di_dmstate = 0;
7845         ip->i_d.di_flags = 0;
7846 +       ip->i_d.di_vflags = 0;
7847         flags = XFS_ILOG_CORE;
7848         switch (mode & S_IFMT) {
7849         case S_IFIFO:
7850 @@ -2100,6 +2127,7 @@ xfs_ifree(
7851         }
7852         ip->i_d.di_mode = 0;            /* mark incore inode as free */
7853         ip->i_d.di_flags = 0;
7854 +       ip->i_d.di_vflags = 0;
7855         ip->i_d.di_dmevmask = 0;
7856         ip->i_d.di_forkoff = 0;         /* mark the attr fork not in use */
7857         ip->i_df.if_ext_max =
7858 @@ -2979,7 +3007,8 @@ xfs_iflush_int(
7859          * because if the inode is dirty at all the core must
7860          * be.
7861          */
7862 -       xfs_dinode_to_disk(dip, &ip->i_d);
7863 +       xfs_dinode_to_disk(dip, &ip->i_d,
7864 +               mp->m_flags & XFS_MOUNT_TAGGED);
7865  
7866         /* Wrap, we never let the log put out DI_MAX_FLUSH */
7867         if (ip->i_d.di_flushiter == DI_MAX_FLUSH)
7868 diff -NurpP --minimal linux-3.0.25/fs/xfs/xfs_inode.h linux-3.0.25-vs2.3.2.3/fs/xfs/xfs_inode.h
7869 --- linux-3.0.25/fs/xfs/xfs_inode.h     2012-03-19 21:16:52.000000000 +0100
7870 +++ linux-3.0.25-vs2.3.2.3/fs/xfs/xfs_inode.h   2011-12-19 15:55:53.000000000 +0100
7871 @@ -135,7 +135,9 @@ typedef struct xfs_icdinode {
7872         __uint32_t      di_nlink;       /* number of links to file */
7873         __uint16_t      di_projid_lo;   /* lower part of owner's project id */
7874         __uint16_t      di_projid_hi;   /* higher part of owner's project id */
7875 -       __uint8_t       di_pad[6];      /* unused, zeroed space */
7876 +       __uint8_t       di_pad[2];      /* unused, zeroed space */
7877 +       __uint16_t      di_tag;         /* context tagging */
7878 +       __uint16_t      di_vflags;      /* vserver specific flags */
7879         __uint16_t      di_flushiter;   /* incremented on flush */
7880         xfs_ictimestamp_t di_atime;     /* time last accessed */
7881         xfs_ictimestamp_t di_mtime;     /* time last modified */
7882 @@ -547,7 +549,7 @@ int         xfs_itobp(struct xfs_mount *, struc
7883  int            xfs_iread(struct xfs_mount *, struct xfs_trans *,
7884                           struct xfs_inode *, uint);
7885  void           xfs_dinode_to_disk(struct xfs_dinode *,
7886 -                                  struct xfs_icdinode *);
7887 +                                  struct xfs_icdinode *, int);
7888  void           xfs_idestroy_fork(struct xfs_inode *, int);
7889  void           xfs_idata_realloc(struct xfs_inode *, int, int);
7890  void           xfs_iroot_realloc(struct xfs_inode *, int, int);
7891 diff -NurpP --minimal linux-3.0.25/fs/xfs/xfs_itable.c linux-3.0.25-vs2.3.2.3/fs/xfs/xfs_itable.c
7892 --- linux-3.0.25/fs/xfs/xfs_itable.c    2011-05-22 16:17:54.000000000 +0200
7893 +++ linux-3.0.25-vs2.3.2.3/fs/xfs/xfs_itable.c  2011-06-10 22:11:24.000000000 +0200
7894 @@ -98,6 +98,7 @@ xfs_bulkstat_one_int(
7895         buf->bs_mode = dic->di_mode;
7896         buf->bs_uid = dic->di_uid;
7897         buf->bs_gid = dic->di_gid;
7898 +       buf->bs_tag = dic->di_tag;
7899         buf->bs_size = dic->di_size;
7900  
7901         /*
7902 diff -NurpP --minimal linux-3.0.25/fs/xfs/xfs_log_recover.c linux-3.0.25-vs2.3.2.3/fs/xfs/xfs_log_recover.c
7903 --- linux-3.0.25/fs/xfs/xfs_log_recover.c       2011-07-22 11:18:10.000000000 +0200
7904 +++ linux-3.0.25-vs2.3.2.3/fs/xfs/xfs_log_recover.c     2011-06-10 22:11:24.000000000 +0200
7905 @@ -2343,7 +2343,8 @@ xlog_recover_inode_pass2(
7906         }
7907  
7908         /* The core is in in-core format */
7909 -       xfs_dinode_to_disk(dip, item->ri_buf[1].i_addr);
7910 +       xfs_dinode_to_disk(dip, item->ri_buf[1].i_addr,
7911 +               mp->m_flags & XFS_MOUNT_TAGGED);
7912  
7913         /* the rest is in on-disk format */
7914         if (item->ri_buf[1].i_len > sizeof(struct xfs_icdinode)) {
7915 diff -NurpP --minimal linux-3.0.25/fs/xfs/xfs_mount.h linux-3.0.25-vs2.3.2.3/fs/xfs/xfs_mount.h
7916 --- linux-3.0.25/fs/xfs/xfs_mount.h     2011-07-22 11:18:10.000000000 +0200
7917 +++ linux-3.0.25-vs2.3.2.3/fs/xfs/xfs_mount.h   2011-06-10 22:11:24.000000000 +0200
7918 @@ -249,6 +249,7 @@ typedef struct xfs_mount {
7919                                                    allocator */
7920  #define XFS_MOUNT_NOATTR2      (1ULL << 25)    /* disable use of attr2 format */
7921  
7922 +#define XFS_MOUNT_TAGGED       (1ULL << 31)    /* context tagging */
7923  
7924  /*
7925   * Default minimum read and write sizes.
7926 diff -NurpP --minimal linux-3.0.25/fs/xfs/xfs_vnodeops.c linux-3.0.25-vs2.3.2.3/fs/xfs/xfs_vnodeops.c
7927 --- linux-3.0.25/fs/xfs/xfs_vnodeops.c  2012-03-19 21:16:52.000000000 +0100
7928 +++ linux-3.0.25-vs2.3.2.3/fs/xfs/xfs_vnodeops.c        2012-02-07 02:05:58.000000000 +0100
7929 @@ -50,6 +50,78 @@
7930  #include "xfs_vnodeops.h"
7931  #include "xfs_trace.h"
7932  
7933 +
7934 +STATIC void
7935 +xfs_get_inode_flags(
7936 +       xfs_inode_t     *ip)
7937 +{
7938 +       struct inode    *inode = VFS_I(ip);
7939 +       unsigned int    flags = inode->i_flags;
7940 +       unsigned int    vflags = inode->i_vflags;
7941 +
7942 +       if (flags & S_IMMUTABLE)
7943 +               ip->i_d.di_flags |= XFS_DIFLAG_IMMUTABLE;
7944 +       else
7945 +               ip->i_d.di_flags &= ~XFS_DIFLAG_IMMUTABLE;
7946 +       if (flags & S_IXUNLINK)
7947 +               ip->i_d.di_flags |= XFS_DIFLAG_IXUNLINK;
7948 +       else
7949 +               ip->i_d.di_flags &= ~XFS_DIFLAG_IXUNLINK;
7950 +
7951 +       if (vflags & V_BARRIER)
7952 +               ip->i_d.di_vflags |= XFS_DIVFLAG_BARRIER;
7953 +       else
7954 +               ip->i_d.di_vflags &= ~XFS_DIVFLAG_BARRIER;
7955 +       if (vflags & V_COW)
7956 +               ip->i_d.di_vflags |= XFS_DIVFLAG_COW;
7957 +       else
7958 +               ip->i_d.di_vflags &= ~XFS_DIVFLAG_COW;
7959 +}
7960 +
7961 +int
7962 +xfs_sync_flags(
7963 +       struct inode            *inode,
7964 +       int                     flags,
7965 +       int                     vflags)
7966 +{
7967 +       struct xfs_inode        *ip = XFS_I(inode);
7968 +       struct xfs_mount        *mp = ip->i_mount;
7969 +       struct xfs_trans        *tp;
7970 +       unsigned int            lock_flags = 0;
7971 +       int                     code;
7972 +
7973 +       tp = xfs_trans_alloc(mp, XFS_TRANS_SETATTR_NOT_SIZE);
7974 +       code = xfs_trans_reserve(tp, 0, XFS_ICHANGE_LOG_RES(mp), 0, 0, 0);
7975 +       if (code)
7976 +               goto error_out;
7977 +
7978 +       xfs_ilock(ip, XFS_ILOCK_EXCL);
7979 +
7980 +       xfs_trans_ijoin(tp, ip);
7981 +
7982 +       inode->i_flags = flags;
7983 +       inode->i_vflags = vflags;
7984 +       xfs_get_inode_flags(ip);
7985 +
7986 +       xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE);
7987 +       xfs_trans_ichgtime(tp, ip, XFS_ICHGTIME_CHG);
7988 +
7989 +       XFS_STATS_INC(xs_ig_attrchg);
7990 +
7991 +       if (mp->m_flags & XFS_MOUNT_WSYNC)
7992 +               xfs_trans_set_sync(tp);
7993 +       code = xfs_trans_commit(tp, 0);
7994 +       xfs_iunlock(ip, XFS_ILOCK_EXCL);
7995 +       return code;
7996 +
7997 +error_out:
7998 +       xfs_trans_cancel(tp, 0);
7999 +       if (lock_flags)
8000 +               xfs_iunlock(ip, XFS_ILOCK_EXCL);
8001 +       return code;
8002 +}
8003 +
8004 +
8005  int
8006  xfs_setattr(
8007         struct xfs_inode        *ip,
8008 @@ -65,6 +137,7 @@ xfs_setattr(
8009         uint                    commit_flags=0;
8010         uid_t                   uid=0, iuid=0;
8011         gid_t                   gid=0, igid=0;
8012 +       tag_t                   tag=0, itag=0;
8013         struct xfs_dquot        *udqp, *gdqp, *olddquot1, *olddquot2;
8014         int                     need_iolock = 1;
8015  
8016 @@ -147,7 +220,7 @@ xfs_setattr(
8017         /*
8018          * Change file ownership.  Must be the owner or privileged.
8019          */
8020 -       if (mask & (ATTR_UID|ATTR_GID)) {
8021 +       if (mask & (ATTR_UID|ATTR_GID|ATTR_TAG)) {
8022                 /*
8023                  * These IDs could have changed since we last looked at them.
8024                  * But, we're assured that if the ownership did change
8025 @@ -156,8 +229,10 @@ xfs_setattr(
8026                  */
8027                 iuid = ip->i_d.di_uid;
8028                 igid = ip->i_d.di_gid;
8029 +               itag = ip->i_d.di_tag;
8030                 gid = (mask & ATTR_GID) ? iattr->ia_gid : igid;
8031                 uid = (mask & ATTR_UID) ? iattr->ia_uid : iuid;
8032 +               tag = (mask & ATTR_TAG) ? iattr->ia_tag : itag;
8033  
8034                 /*
8035                  * Do a quota reservation only if uid/gid is actually
8036 @@ -165,7 +240,8 @@ xfs_setattr(
8037                  */
8038                 if (XFS_IS_QUOTA_RUNNING(mp) &&
8039                     ((XFS_IS_UQUOTA_ON(mp) && iuid != uid) ||
8040 -                    (XFS_IS_GQUOTA_ON(mp) && igid != gid))) {
8041 +                    (XFS_IS_GQUOTA_ON(mp) && igid != gid) ||
8042 +                    (XFS_IS_GQUOTA_ON(mp) && itag != tag))) {
8043                         ASSERT(tp);
8044                         code = xfs_qm_vop_chown_reserve(tp, ip, udqp, gdqp,
8045                                                 capable(CAP_FOWNER) ?
8046 @@ -329,7 +405,7 @@ xfs_setattr(
8047         /*
8048          * Change file ownership.  Must be the owner or privileged.
8049          */
8050 -       if (mask & (ATTR_UID|ATTR_GID)) {
8051 +       if (mask & (ATTR_UID|ATTR_GID|ATTR_TAG)) {
8052                 /*
8053                  * CAP_FSETID overrides the following restrictions:
8054                  *
8055 @@ -345,6 +421,10 @@ xfs_setattr(
8056                  * Change the ownerships and register quota modifications
8057                  * in the transaction.
8058                  */
8059 +               if (itag != tag) {
8060 +                       ip->i_d.di_tag = tag;
8061 +                       inode->i_tag = tag;
8062 +               }
8063                 if (iuid != uid) {
8064                         if (XFS_IS_QUOTA_RUNNING(mp) && XFS_IS_UQUOTA_ON(mp)) {
8065                                 ASSERT(mask & ATTR_UID);
8066 diff -NurpP --minimal linux-3.0.25/fs/xfs/xfs_vnodeops.h linux-3.0.25-vs2.3.2.3/fs/xfs/xfs_vnodeops.h
8067 --- linux-3.0.25/fs/xfs/xfs_vnodeops.h  2011-05-22 16:17:54.000000000 +0200
8068 +++ linux-3.0.25-vs2.3.2.3/fs/xfs/xfs_vnodeops.h        2011-06-10 22:11:24.000000000 +0200
8069 @@ -13,6 +13,7 @@ struct xfs_inode;
8070  struct xfs_iomap;
8071  
8072  
8073 +int xfs_sync_xflags(struct xfs_inode *ip);
8074  int xfs_setattr(struct xfs_inode *ip, struct iattr *vap, int flags);
8075  #define        XFS_ATTR_DMI            0x01    /* invocation from a DMI function */
8076  #define        XFS_ATTR_NONBLOCK       0x02    /* return EAGAIN if operation would block */
8077 diff -NurpP --minimal linux-3.0.25/include/asm-generic/tlb.h linux-3.0.25-vs2.3.2.3/include/asm-generic/tlb.h
8078 --- linux-3.0.25/include/asm-generic/tlb.h      2011-07-22 11:18:10.000000000 +0200
8079 +++ linux-3.0.25-vs2.3.2.3/include/asm-generic/tlb.h    2011-06-10 22:11:24.000000000 +0200
8080 @@ -16,6 +16,7 @@
8081  #define _ASM_GENERIC__TLB_H
8082  
8083  #include <linux/swap.h>
8084 +#include <linux/vs_memory.h>
8085  #include <asm/pgalloc.h>
8086  #include <asm/tlbflush.h>
8087  
8088 diff -NurpP --minimal linux-3.0.25/include/linux/Kbuild linux-3.0.25-vs2.3.2.3/include/linux/Kbuild
8089 --- linux-3.0.25/include/linux/Kbuild   2011-07-22 11:18:10.000000000 +0200
8090 +++ linux-3.0.25-vs2.3.2.3/include/linux/Kbuild 2011-06-10 22:11:24.000000000 +0200
8091 @@ -17,6 +17,7 @@ header-y += netfilter_bridge/
8092  header-y += netfilter_ipv4/
8093  header-y += netfilter_ipv6/
8094  header-y += usb/
8095 +header-y += vserver/
8096  header-y += wimax/
8097  
8098  objhdr-y += version.h
8099 diff -NurpP --minimal linux-3.0.25/include/linux/capability.h linux-3.0.25-vs2.3.2.3/include/linux/capability.h
8100 --- linux-3.0.25/include/linux/capability.h     2011-07-22 11:18:10.000000000 +0200
8101 +++ linux-3.0.25-vs2.3.2.3/include/linux/capability.h   2011-06-10 22:11:24.000000000 +0200
8102 @@ -279,6 +279,7 @@ struct cpu_vfs_cap_data {
8103     arbitrary SCSI commands */
8104  /* Allow setting encryption key on loopback filesystem */
8105  /* Allow setting zone reclaim policy */
8106 +/* Allow the selection of a security context */
8107  
8108  #define CAP_SYS_ADMIN        21
8109  
8110 @@ -362,7 +363,12 @@ struct cpu_vfs_cap_data {
8111  
8112  #define CAP_LAST_CAP         CAP_WAKE_ALARM
8113  
8114 -#define cap_valid(x) ((x) >= 0 && (x) <= CAP_LAST_CAP)
8115 +/* Allow context manipulations */
8116 +/* Allow changing context info on files */
8117 +
8118 +#define CAP_CONTEXT         63
8119 +
8120 +#define cap_valid(x) ((x) >= 0 && ((x) <= CAP_LAST_CAP || (x) == CAP_CONTEXT))
8121  
8122  /*
8123   * Bit location of each capability (used by user-space library and kernel)
8124 diff -NurpP --minimal linux-3.0.25/include/linux/cred.h linux-3.0.25-vs2.3.2.3/include/linux/cred.h
8125 --- linux-3.0.25/include/linux/cred.h   2011-07-22 11:18:10.000000000 +0200
8126 +++ linux-3.0.25-vs2.3.2.3/include/linux/cred.h 2011-06-10 22:11:24.000000000 +0200
8127 @@ -156,6 +156,7 @@ extern void exit_creds(struct task_struc
8128  extern int copy_creds(struct task_struct *, unsigned long);
8129  extern const struct cred *get_task_cred(struct task_struct *);
8130  extern struct cred *cred_alloc_blank(void);
8131 +extern struct cred *__prepare_creds(const struct cred *);
8132  extern struct cred *prepare_creds(void);
8133  extern struct cred *prepare_exec_creds(void);
8134  extern int commit_creds(struct cred *);
8135 @@ -209,6 +210,31 @@ static inline void validate_process_cred
8136  }
8137  #endif
8138  
8139 +static inline void set_cred_subscribers(struct cred *cred, int n)
8140 +{
8141 +#ifdef CONFIG_DEBUG_CREDENTIALS
8142 +       atomic_set(&cred->subscribers, n);
8143 +#endif
8144 +}
8145 +
8146 +static inline int read_cred_subscribers(const struct cred *cred)
8147 +{
8148 +#ifdef CONFIG_DEBUG_CREDENTIALS
8149 +       return atomic_read(&cred->subscribers);
8150 +#else
8151 +       return 0;
8152 +#endif
8153 +}
8154 +
8155 +static inline void alter_cred_subscribers(const struct cred *_cred, int n)
8156 +{
8157 +#ifdef CONFIG_DEBUG_CREDENTIALS
8158 +       struct cred *cred = (struct cred *) _cred;
8159 +
8160 +       atomic_add(n, &cred->subscribers);
8161 +#endif
8162 +}
8163 +
8164  /**
8165   * get_new_cred - Get a reference on a new set of credentials
8166   * @cred: The new credentials to reference
8167 diff -NurpP --minimal linux-3.0.25/include/linux/devpts_fs.h linux-3.0.25-vs2.3.2.3/include/linux/devpts_fs.h
8168 --- linux-3.0.25/include/linux/devpts_fs.h      2008-12-25 00:26:37.000000000 +0100
8169 +++ linux-3.0.25-vs2.3.2.3/include/linux/devpts_fs.h    2011-06-10 22:11:24.000000000 +0200
8170 @@ -45,5 +45,4 @@ static inline void devpts_pty_kill(struc
8171  
8172  #endif
8173  
8174 -
8175  #endif /* _LINUX_DEVPTS_FS_H */
8176 diff -NurpP --minimal linux-3.0.25/include/linux/ext2_fs.h linux-3.0.25-vs2.3.2.3/include/linux/ext2_fs.h
8177 --- linux-3.0.25/include/linux/ext2_fs.h        2012-03-19 21:16:53.000000000 +0100
8178 +++ linux-3.0.25-vs2.3.2.3/include/linux/ext2_fs.h      2011-11-15 17:37:07.000000000 +0100
8179 @@ -189,8 +189,12 @@ struct ext2_group_desc
8180  #define EXT2_NOTAIL_FL                 FS_NOTAIL_FL    /* file tail should not be merged */
8181  #define EXT2_DIRSYNC_FL                        FS_DIRSYNC_FL   /* dirsync behaviour (directories only) */
8182  #define EXT2_TOPDIR_FL                 FS_TOPDIR_FL    /* Top of directory hierarchies*/
8183 +#define EXT2_IXUNLINK_FL               FS_IXUNLINK_FL  /* Immutable invert on unlink */
8184  #define EXT2_RESERVED_FL               FS_RESERVED_FL  /* reserved for ext2 lib */
8185  
8186 +#define EXT2_BARRIER_FL                        FS_BARRIER_FL   /* Barrier for chroot() */
8187 +#define EXT2_COW_FL                    FS_COW_FL       /* Copy on Write marker */
8188 +
8189  #define EXT2_FL_USER_VISIBLE           FS_FL_USER_VISIBLE      /* User visible flags */
8190  #define EXT2_FL_USER_MODIFIABLE                FS_FL_USER_MODIFIABLE   /* User modifiable flags */
8191  
8192 @@ -274,7 +278,8 @@ struct ext2_inode {
8193                         __u16   i_pad1;
8194                         __le16  l_i_uid_high;   /* these 2 fields    */
8195                         __le16  l_i_gid_high;   /* were reserved2[0] */
8196 -                       __u32   l_i_reserved2;
8197 +                       __le16  l_i_tag;        /* Context Tag */
8198 +                       __u16   l_i_reserved2;
8199                 } linux2;
8200                 struct {
8201                         __u8    h_i_frag;       /* Fragment number */
8202 @@ -303,6 +308,7 @@ struct ext2_inode {
8203  #define i_gid_low      i_gid
8204  #define i_uid_high     osd2.linux2.l_i_uid_high
8205  #define i_gid_high     osd2.linux2.l_i_gid_high
8206 +#define i_raw_tag      osd2.linux2.l_i_tag
8207  #define i_reserved2    osd2.linux2.l_i_reserved2
8208  #endif
8209  
8210 @@ -347,6 +353,7 @@ struct ext2_inode {
8211  #define EXT2_MOUNT_USRQUOTA            0x020000  /* user quota */
8212  #define EXT2_MOUNT_GRPQUOTA            0x040000  /* group quota */
8213  #define EXT2_MOUNT_RESERVATION         0x080000  /* Preallocation */
8214 +#define EXT2_MOUNT_TAGGED              (1<<24)   /* Enable Context Tags */
8215  
8216  
8217  #define clear_opt(o, opt)              o &= ~EXT2_MOUNT_##opt
8218 diff -NurpP --minimal linux-3.0.25/include/linux/ext3_fs.h linux-3.0.25-vs2.3.2.3/include/linux/ext3_fs.h
8219 --- linux-3.0.25/include/linux/ext3_fs.h        2012-03-19 21:16:53.000000000 +0100
8220 +++ linux-3.0.25-vs2.3.2.3/include/linux/ext3_fs.h      2011-11-15 17:37:07.000000000 +0100
8221 @@ -173,10 +173,14 @@ struct ext3_group_desc
8222  #define EXT3_NOTAIL_FL                 0x00008000 /* file tail should not be merged */
8223  #define EXT3_DIRSYNC_FL                        0x00010000 /* dirsync behaviour (directories only) */
8224  #define EXT3_TOPDIR_FL                 0x00020000 /* Top of directory hierarchies*/
8225 +#define EXT3_IXUNLINK_FL               0x08000000 /* Immutable invert on unlink */
8226  #define EXT3_RESERVED_FL               0x80000000 /* reserved for ext3 lib */
8227  
8228 -#define EXT3_FL_USER_VISIBLE           0x0003DFFF /* User visible flags */
8229 -#define EXT3_FL_USER_MODIFIABLE                0x000380FF /* User modifiable flags */
8230 +#define EXT3_BARRIER_FL                        0x04000000 /* Barrier for chroot() */
8231 +#define EXT3_COW_FL                    0x20000000 /* Copy on Write marker */
8232 +
8233 +#define EXT3_FL_USER_VISIBLE           0x0103DFFF /* User visible flags */
8234 +#define EXT3_FL_USER_MODIFIABLE                0x010380FF /* User modifiable flags */
8235  
8236  /* Flags that should be inherited by new inodes from their parent. */
8237  #define EXT3_FL_INHERITED (EXT3_SECRM_FL | EXT3_UNRM_FL | EXT3_COMPR_FL |\
8238 @@ -312,7 +316,8 @@ struct ext3_inode {
8239                         __u16   i_pad1;
8240                         __le16  l_i_uid_high;   /* these 2 fields    */
8241                         __le16  l_i_gid_high;   /* were reserved2[0] */
8242 -                       __u32   l_i_reserved2;
8243 +                       __le16  l_i_tag;        /* Context Tag */
8244 +                       __u16   l_i_reserved2;
8245                 } linux2;
8246                 struct {
8247                         __u8    h_i_frag;       /* Fragment number */
8248 @@ -343,6 +348,7 @@ struct ext3_inode {
8249  #define i_gid_low      i_gid
8250  #define i_uid_high     osd2.linux2.l_i_uid_high
8251  #define i_gid_high     osd2.linux2.l_i_gid_high
8252 +#define i_raw_tag      osd2.linux2.l_i_tag
8253  #define i_reserved2    osd2.linux2.l_i_reserved2
8254  
8255  #elif defined(__GNU__)
8256 @@ -405,6 +411,7 @@ struct ext3_inode {
8257  #define EXT3_MOUNT_GRPQUOTA            0x200000 /* "old" group quota */
8258  #define EXT3_MOUNT_DATA_ERR_ABORT      0x400000 /* Abort on file data write
8259                                                   * error in ordered mode */
8260 +#define EXT3_MOUNT_TAGGED              (1<<24) /* Enable Context Tags */
8261  
8262  /* Compatibility, for having both ext2_fs.h and ext3_fs.h included at once */
8263  #ifndef _LINUX_EXT2_FS_H
8264 @@ -919,6 +926,7 @@ extern void ext3_get_inode_flags(struct 
8265  extern void ext3_set_aops(struct inode *inode);
8266  extern int ext3_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
8267                        u64 start, u64 len);
8268 +extern int ext3_sync_flags(struct inode *, int, int);
8269  
8270  /* ioctl.c */
8271  extern long ext3_ioctl(struct file *, unsigned int, unsigned long);
8272 diff -NurpP --minimal linux-3.0.25/include/linux/fs.h linux-3.0.25-vs2.3.2.3/include/linux/fs.h
8273 --- linux-3.0.25/include/linux/fs.h     2012-03-19 21:16:53.000000000 +0100
8274 +++ linux-3.0.25-vs2.3.2.3/include/linux/fs.h   2012-03-01 21:51:50.000000000 +0100
8275 @@ -208,6 +208,9 @@ struct inodes_stat_t {
8276  #define MS_KERNMOUNT   (1<<22) /* this is a kern_mount call */
8277  #define MS_I_VERSION   (1<<23) /* Update inode I_version field */
8278  #define MS_STRICTATIME (1<<24) /* Always perform atime updates */
8279 +#define MS_TAGGED      (1<<25) /* use generic inode tagging */
8280 +#define MS_TAGID       (1<<26) /* use specific tag for this mount */
8281 +#define MS_NOTAGCHECK  (1<<27) /* don't check tags */
8282  #define MS_NOSEC       (1<<28)
8283  #define MS_BORN                (1<<29)
8284  #define MS_ACTIVE      (1<<30)
8285 @@ -239,6 +242,14 @@ struct inodes_stat_t {
8286  #define S_IMA          1024    /* Inode has an associated IMA struct */
8287  #define S_AUTOMOUNT    2048    /* Automount/referral quasi-directory */
8288  #define S_NOSEC                4096    /* no suid or xattr security attributes */
8289 +#define S_IXUNLINK     8192    /* Immutable Invert on unlink */
8290 +
8291 +/* Linux-VServer related Inode flags */
8292 +
8293 +#define V_VALID                1
8294 +#define V_XATTR                2
8295 +#define V_BARRIER      4       /* Barrier for chroot() */
8296 +#define V_COW          8       /* Copy on Write */
8297  
8298  /*
8299   * Note that nosuid etc flags are inode-specific: setting some file-system
8300 @@ -261,12 +272,15 @@ struct inodes_stat_t {
8301  #define IS_DIRSYNC(inode)      (__IS_FLG(inode, MS_SYNCHRONOUS|MS_DIRSYNC) || \
8302                                         ((inode)->i_flags & (S_SYNC|S_DIRSYNC)))
8303  #define IS_MANDLOCK(inode)     __IS_FLG(inode, MS_MANDLOCK)
8304 -#define IS_NOATIME(inode)   __IS_FLG(inode, MS_RDONLY|MS_NOATIME)
8305 -#define IS_I_VERSION(inode)   __IS_FLG(inode, MS_I_VERSION)
8306 +#define IS_NOATIME(inode)      __IS_FLG(inode, MS_RDONLY|MS_NOATIME)
8307 +#define IS_I_VERSION(inode)    __IS_FLG(inode, MS_I_VERSION)
8308 +#define IS_TAGGED(inode)       __IS_FLG(inode, MS_TAGGED)
8309  
8310  #define IS_NOQUOTA(inode)      ((inode)->i_flags & S_NOQUOTA)
8311  #define IS_APPEND(inode)       ((inode)->i_flags & S_APPEND)
8312  #define IS_IMMUTABLE(inode)    ((inode)->i_flags & S_IMMUTABLE)
8313 +#define IS_IXUNLINK(inode)     ((inode)->i_flags & S_IXUNLINK)
8314 +#define IS_IXORUNLINK(inode)   ((IS_IXUNLINK(inode) ? S_IMMUTABLE : 0) ^ IS_IMMUTABLE(inode))
8315  #define IS_POSIXACL(inode)     __IS_FLG(inode, MS_POSIXACL)
8316  
8317  #define IS_DEADDIR(inode)      ((inode)->i_flags & S_DEAD)
8318 @@ -277,6 +291,16 @@ struct inodes_stat_t {
8319  #define IS_AUTOMOUNT(inode)    ((inode)->i_flags & S_AUTOMOUNT)
8320  #define IS_NOSEC(inode)                ((inode)->i_flags & S_NOSEC)
8321  
8322 +#define IS_BARRIER(inode)      (S_ISDIR((inode)->i_mode) && ((inode)->i_vflags & V_BARRIER))
8323 +
8324 +#ifdef CONFIG_VSERVER_COWBL
8325 +#  define IS_COW(inode)                (IS_IXUNLINK(inode) && IS_IMMUTABLE(inode))
8326 +#  define IS_COW_LINK(inode)   (S_ISREG((inode)->i_mode) && ((inode)->i_nlink > 1))
8327 +#else
8328 +#  define IS_COW(inode)                (0)
8329 +#  define IS_COW_LINK(inode)   (0)
8330 +#endif
8331 +
8332  /* the read-only stuff doesn't really belong here, but any other place is
8333     probably as bad and I don't want to create yet another include file. */
8334  
8335 @@ -362,11 +386,14 @@ struct inodes_stat_t {
8336  #define FS_EXTENT_FL                   0x00080000 /* Extents */
8337  #define FS_DIRECTIO_FL                 0x00100000 /* Use direct i/o */
8338  #define FS_NOCOW_FL                    0x00800000 /* Do not cow file */
8339 +#define FS_IXUNLINK_FL                 0x08000000 /* Immutable invert on unlink */
8340  #define FS_RESERVED_FL                 0x80000000 /* reserved for ext2 lib */
8341  
8342 -#define FS_FL_USER_VISIBLE             0x0003DFFF /* User visible flags */
8343 -#define FS_FL_USER_MODIFIABLE          0x000380FF /* User modifiable flags */
8344 -
8345 +#define FS_BARRIER_FL                  0x04000000 /* Barrier for chroot() */
8346 +#define FS_COW_FL                      0x20000000 /* Copy on Write marker */
8347 +
8348 +#define FS_FL_USER_VISIBLE             0x0103DFFF /* User visible flags */
8349 +#define FS_FL_USER_MODIFIABLE          0x010380FF /* User modifiable flags */
8350  
8351  #define SYNC_FILE_RANGE_WAIT_BEFORE    1
8352  #define SYNC_FILE_RANGE_WRITE          2
8353 @@ -447,6 +474,7 @@ typedef void (dio_iodone_t)(struct kiocb
8354  #define ATTR_KILL_PRIV (1 << 14)
8355  #define ATTR_OPEN      (1 << 15) /* Truncating from open(O_TRUNC) */
8356  #define ATTR_TIMES_SET (1 << 16)
8357 +#define ATTR_TAG       (1 << 17)
8358  
8359  /*
8360   * This is the Inode Attributes structure, used for notify_change().  It
8361 @@ -462,6 +490,7 @@ struct iattr {
8362         umode_t         ia_mode;
8363         uid_t           ia_uid;
8364         gid_t           ia_gid;
8365 +       tag_t           ia_tag;
8366         loff_t          ia_size;
8367         struct timespec ia_atime;
8368         struct timespec ia_mtime;
8369 @@ -475,6 +504,9 @@ struct iattr {
8370         struct file     *ia_file;
8371  };
8372  
8373 +#define ATTR_FLAG_BARRIER      512     /* Barrier for chroot() */
8374 +#define ATTR_FLAG_IXUNLINK     1024    /* Immutable invert on unlink */
8375 +
8376  /*
8377   * Includes for diskquotas.
8378   */
8379 @@ -740,11 +772,13 @@ struct inode {
8380         umode_t                 i_mode;
8381         uid_t                   i_uid;
8382         gid_t                   i_gid;
8383 +       tag_t                   i_tag;
8384         const struct inode_operations   *i_op;
8385         struct super_block      *i_sb;
8386  
8387         spinlock_t              i_lock; /* i_blocks, i_bytes, maybe i_size */
8388 -       unsigned int            i_flags;
8389 +       unsigned short          i_flags;
8390 +       unsigned short          i_vflags;
8391         unsigned long           i_state;
8392  #ifdef CONFIG_SECURITY
8393         void                    *i_security;
8394 @@ -766,6 +800,7 @@ struct inode {
8395         atomic_t                i_count;
8396         unsigned int            i_nlink;
8397         dev_t                   i_rdev;
8398 +       dev_t                   i_mdev;
8399         unsigned int            i_blkbits;
8400         u64                     i_version;
8401         loff_t                  i_size;
8402 @@ -890,12 +925,12 @@ static inline void i_size_write(struct i
8403  
8404  static inline unsigned iminor(const struct inode *inode)
8405  {
8406 -       return MINOR(inode->i_rdev);
8407 +       return MINOR(inode->i_mdev);
8408  }
8409  
8410  static inline unsigned imajor(const struct inode *inode)
8411  {
8412 -       return MAJOR(inode->i_rdev);
8413 +       return MAJOR(inode->i_mdev);
8414  }
8415  
8416  extern struct block_device *I_BDEV(struct inode *inode);
8417 @@ -957,6 +992,7 @@ struct file {
8418         loff_t                  f_pos;
8419         struct fown_struct      f_owner;
8420         const struct cred       *f_cred;
8421 +       xid_t                   f_xid;
8422         struct file_ra_state    f_ra;
8423  
8424         u64                     f_version;
8425 @@ -1102,6 +1138,7 @@ struct file_lock {
8426         struct file *fl_file;
8427         loff_t fl_start;
8428         loff_t fl_end;
8429 +       xid_t fl_xid;
8430  
8431         struct fasync_struct *  fl_fasync; /* for lease break notifications */
8432         unsigned long fl_break_time;    /* for nonblocking lease breaks */
8433 @@ -1601,6 +1638,7 @@ struct inode_operations {
8434         ssize_t (*getxattr) (struct dentry *, const char *, void *, size_t);
8435         ssize_t (*listxattr) (struct dentry *, char *, size_t);
8436         int (*removexattr) (struct dentry *, const char *);
8437 +       int (*sync_flags) (struct inode *, int, int);
8438         void (*truncate_range)(struct inode *, loff_t, loff_t);
8439         int (*fiemap)(struct inode *, struct fiemap_extent_info *, u64 start,
8440                       u64 len);
8441 @@ -1619,6 +1657,7 @@ extern ssize_t vfs_readv(struct file *, 
8442                 unsigned long, loff_t *);
8443  extern ssize_t vfs_writev(struct file *, const struct iovec __user *,
8444                 unsigned long, loff_t *);
8445 +ssize_t vfs_sendfile(struct file *, struct file *, loff_t *, size_t, loff_t);
8446  
8447  struct super_operations {
8448         struct inode *(*alloc_inode)(struct super_block *sb);
8449 @@ -2439,6 +2478,7 @@ extern int dcache_dir_open(struct inode 
8450  extern int dcache_dir_close(struct inode *, struct file *);
8451  extern loff_t dcache_dir_lseek(struct file *, loff_t, int);
8452  extern int dcache_readdir(struct file *, void *, filldir_t);
8453 +extern int dcache_readdir_filter(struct file *, void *, filldir_t, int (*)(struct dentry *));
8454  extern int simple_setattr(struct dentry *, struct iattr *);
8455  extern int simple_getattr(struct vfsmount *, struct dentry *, struct kstat *);
8456  extern int simple_statfs(struct dentry *, struct kstatfs *);
8457 diff -NurpP --minimal linux-3.0.25/include/linux/gfs2_ondisk.h linux-3.0.25-vs2.3.2.3/include/linux/gfs2_ondisk.h
8458 --- linux-3.0.25/include/linux/gfs2_ondisk.h    2010-07-07 18:31:55.000000000 +0200
8459 +++ linux-3.0.25-vs2.3.2.3/include/linux/gfs2_ondisk.h  2011-06-10 22:11:24.000000000 +0200
8460 @@ -211,6 +211,9 @@ enum {
8461         gfs2fl_NoAtime          = 7,
8462         gfs2fl_Sync             = 8,
8463         gfs2fl_System           = 9,
8464 +       gfs2fl_IXUnlink         = 16,
8465 +       gfs2fl_Barrier          = 17,
8466 +       gfs2fl_Cow              = 18,
8467         gfs2fl_TruncInProg      = 29,
8468         gfs2fl_InheritDirectio  = 30,
8469         gfs2fl_InheritJdata     = 31,
8470 @@ -227,6 +230,9 @@ enum {
8471  #define GFS2_DIF_NOATIME               0x00000080
8472  #define GFS2_DIF_SYNC                  0x00000100
8473  #define GFS2_DIF_SYSTEM                        0x00000200 /* New in gfs2 */
8474 +#define GFS2_DIF_IXUNLINK              0x00010000
8475 +#define GFS2_DIF_BARRIER               0x00020000
8476 +#define GFS2_DIF_COW                   0x00040000
8477  #define GFS2_DIF_TRUNC_IN_PROG         0x20000000 /* New in gfs2 */
8478  #define GFS2_DIF_INHERIT_DIRECTIO      0x40000000
8479  #define GFS2_DIF_INHERIT_JDATA         0x80000000
8480 diff -NurpP --minimal linux-3.0.25/include/linux/if_tun.h linux-3.0.25-vs2.3.2.3/include/linux/if_tun.h
8481 --- linux-3.0.25/include/linux/if_tun.h 2010-08-02 16:52:54.000000000 +0200
8482 +++ linux-3.0.25-vs2.3.2.3/include/linux/if_tun.h       2011-06-10 22:11:24.000000000 +0200
8483 @@ -53,6 +53,7 @@
8484  #define TUNDETACHFILTER _IOW('T', 214, struct sock_fprog)
8485  #define TUNGETVNETHDRSZ _IOR('T', 215, int)
8486  #define TUNSETVNETHDRSZ _IOW('T', 216, int)
8487 +#define TUNSETNID     _IOW('T', 217, int)
8488  
8489  /* TUNSETIFF ifr flags */
8490  #define IFF_TUN                0x0001
8491 diff -NurpP --minimal linux-3.0.25/include/linux/init_task.h linux-3.0.25-vs2.3.2.3/include/linux/init_task.h
8492 --- linux-3.0.25/include/linux/init_task.h      2011-07-22 11:18:10.000000000 +0200
8493 +++ linux-3.0.25-vs2.3.2.3/include/linux/init_task.h    2011-06-10 22:11:24.000000000 +0200
8494 @@ -193,6 +193,10 @@ extern struct cred init_cred;
8495         INIT_TRACE_RECURSION                                            \
8496         INIT_TASK_RCU_PREEMPT(tsk)                                      \
8497         INIT_CPUSET_SEQ                                                 \
8498 +       .xid            = 0,                                            \
8499 +       .vx_info        = NULL,                                         \
8500 +       .nid            = 0,                                            \
8501 +       .nx_info        = NULL,                                         \
8502  }
8503  
8504  
8505 diff -NurpP --minimal linux-3.0.25/include/linux/ipc.h linux-3.0.25-vs2.3.2.3/include/linux/ipc.h
8506 --- linux-3.0.25/include/linux/ipc.h    2009-12-03 20:02:55.000000000 +0100
8507 +++ linux-3.0.25-vs2.3.2.3/include/linux/ipc.h  2011-06-10 22:11:24.000000000 +0200
8508 @@ -91,6 +91,7 @@ struct kern_ipc_perm
8509         key_t           key;
8510         uid_t           uid;
8511         gid_t           gid;
8512 +       xid_t           xid;
8513         uid_t           cuid;
8514         gid_t           cgid;
8515         mode_t          mode; 
8516 diff -NurpP --minimal linux-3.0.25/include/linux/ipc_namespace.h linux-3.0.25-vs2.3.2.3/include/linux/ipc_namespace.h
8517 --- linux-3.0.25/include/linux/ipc_namespace.h  2011-05-22 16:17:55.000000000 +0200
8518 +++ linux-3.0.25-vs2.3.2.3/include/linux/ipc_namespace.h        2011-06-13 14:09:44.000000000 +0200
8519 @@ -94,7 +94,8 @@ static inline int mq_init_ns(struct ipc_
8520  
8521  #if defined(CONFIG_IPC_NS)
8522  extern struct ipc_namespace *copy_ipcs(unsigned long flags,
8523 -                                      struct task_struct *tsk);
8524 +                                      struct ipc_namespace *old_ns,
8525 +                                      struct user_namespace *user_ns);
8526  static inline struct ipc_namespace *get_ipc_ns(struct ipc_namespace *ns)
8527  {
8528         if (ns)
8529 @@ -105,12 +106,13 @@ static inline struct ipc_namespace *get_
8530  extern void put_ipc_ns(struct ipc_namespace *ns);
8531  #else
8532  static inline struct ipc_namespace *copy_ipcs(unsigned long flags,
8533 -                                             struct task_struct *tsk)
8534 +                                             struct ipc_namespace *old_ns,
8535 +                                             struct user_namespace *user_ns)
8536  {
8537         if (flags & CLONE_NEWIPC)
8538                 return ERR_PTR(-EINVAL);
8539  
8540 -       return tsk->nsproxy->ipc_ns;
8541 +       return old_ns;
8542  }
8543  
8544  static inline struct ipc_namespace *get_ipc_ns(struct ipc_namespace *ns)
8545 diff -NurpP --minimal linux-3.0.25/include/linux/loop.h linux-3.0.25-vs2.3.2.3/include/linux/loop.h
8546 --- linux-3.0.25/include/linux/loop.h   2009-09-10 15:26:25.000000000 +0200
8547 +++ linux-3.0.25-vs2.3.2.3/include/linux/loop.h 2011-06-10 22:11:24.000000000 +0200
8548 @@ -45,6 +45,7 @@ struct loop_device {
8549         struct loop_func_table *lo_encryption;
8550         __u32           lo_init[2];
8551         uid_t           lo_key_owner;   /* Who set the key */
8552 +       xid_t           lo_xid;
8553         int             (*ioctl)(struct loop_device *, int cmd, 
8554                                  unsigned long arg); 
8555  
8556 diff -NurpP --minimal linux-3.0.25/include/linux/magic.h linux-3.0.25-vs2.3.2.3/include/linux/magic.h
8557 --- linux-3.0.25/include/linux/magic.h  2011-05-22 16:17:55.000000000 +0200
8558 +++ linux-3.0.25-vs2.3.2.3/include/linux/magic.h        2011-06-10 22:11:24.000000000 +0200
8559 @@ -3,7 +3,7 @@
8560  
8561  #define ADFS_SUPER_MAGIC       0xadf5
8562  #define AFFS_SUPER_MAGIC       0xadff
8563 -#define AFS_SUPER_MAGIC                0x5346414F
8564 +#define AFS_SUPER_MAGIC                0x5346414F
8565  #define AUTOFS_SUPER_MAGIC     0x0187
8566  #define CODA_SUPER_MAGIC       0x73757245
8567  #define CRAMFS_MAGIC           0x28cd3d45      /* some random number */
8568 @@ -41,6 +41,7 @@
8569  #define NFS_SUPER_MAGIC                0x6969
8570  #define OPENPROM_SUPER_MAGIC   0x9fa1
8571  #define PROC_SUPER_MAGIC       0x9fa0
8572 +#define DEVPTS_SUPER_MAGIC     0x1cd1
8573  #define QNX4_SUPER_MAGIC       0x002f          /* qnx4 fs detection */
8574  
8575  #define REISERFS_SUPER_MAGIC   0x52654973      /* used by gcc */
8576 diff -NurpP --minimal linux-3.0.25/include/linux/major.h linux-3.0.25-vs2.3.2.3/include/linux/major.h
8577 --- linux-3.0.25/include/linux/major.h  2009-09-10 15:26:25.000000000 +0200
8578 +++ linux-3.0.25-vs2.3.2.3/include/linux/major.h        2011-06-10 22:11:24.000000000 +0200
8579 @@ -15,6 +15,7 @@
8580  #define HD_MAJOR               IDE0_MAJOR
8581  #define PTY_SLAVE_MAJOR                3
8582  #define TTY_MAJOR              4
8583 +#define VROOT_MAJOR            4
8584  #define TTYAUX_MAJOR           5
8585  #define LP_MAJOR               6
8586  #define VCS_MAJOR              7
8587 diff -NurpP --minimal linux-3.0.25/include/linux/memcontrol.h linux-3.0.25-vs2.3.2.3/include/linux/memcontrol.h
8588 --- linux-3.0.25/include/linux/memcontrol.h     2012-03-19 21:16:55.000000000 +0100
8589 +++ linux-3.0.25-vs2.3.2.3/include/linux/memcontrol.h   2012-01-26 08:39:53.000000000 +0100
8590 @@ -86,6 +86,13 @@ extern struct mem_cgroup *try_get_mem_cg
8591  extern struct mem_cgroup *mem_cgroup_from_task(struct task_struct *p);
8592  extern struct mem_cgroup *try_get_mem_cgroup_from_mm(struct mm_struct *mm);
8593  
8594 +extern u64 mem_cgroup_res_read_u64(struct mem_cgroup *mem, int member);
8595 +extern u64 mem_cgroup_memsw_read_u64(struct mem_cgroup *mem, int member);
8596 +
8597 +extern s64 mem_cgroup_stat_read_cache(struct mem_cgroup *mem);
8598 +extern s64 mem_cgroup_stat_read_anon(struct mem_cgroup *mem);
8599 +extern s64 mem_cgroup_stat_read_mapped(struct mem_cgroup *mem);
8600 +
8601  static inline
8602  int mm_match_cgroup(const struct mm_struct *mm, const struct mem_cgroup *cgroup)
8603  {
8604 diff -NurpP --minimal linux-3.0.25/include/linux/mm_types.h linux-3.0.25-vs2.3.2.3/include/linux/mm_types.h
8605 --- linux-3.0.25/include/linux/mm_types.h       2012-03-19 21:16:55.000000000 +0100
8606 +++ linux-3.0.25-vs2.3.2.3/include/linux/mm_types.h     2011-11-15 17:37:07.000000000 +0100
8607 @@ -282,6 +282,7 @@ struct mm_struct {
8608  
8609         /* Architecture-specific MM context */
8610         mm_context_t context;
8611 +       struct vx_info *mm_vx_info;
8612  
8613         /* Swap token stuff */
8614         /*
8615 diff -NurpP --minimal linux-3.0.25/include/linux/mmzone.h linux-3.0.25-vs2.3.2.3/include/linux/mmzone.h
8616 --- linux-3.0.25/include/linux/mmzone.h 2011-07-22 11:18:11.000000000 +0200
8617 +++ linux-3.0.25-vs2.3.2.3/include/linux/mmzone.h       2011-07-01 11:35:35.000000000 +0200
8618 @@ -654,6 +654,13 @@ typedef struct pglist_data {
8619         __pgdat->node_start_pfn + __pgdat->node_spanned_pages;\
8620  })
8621  
8622 +#define node_start_pfn(nid)    (NODE_DATA(nid)->node_start_pfn)
8623 +
8624 +#define node_end_pfn(nid) ({\
8625 +       pg_data_t *__pgdat = NODE_DATA(nid);\
8626 +       __pgdat->node_start_pfn + __pgdat->node_spanned_pages;\
8627 +})
8628 +
8629  #include <linux/memory_hotplug.h>
8630  
8631  extern struct mutex zonelists_mutex;
8632 diff -NurpP --minimal linux-3.0.25/include/linux/mount.h linux-3.0.25-vs2.3.2.3/include/linux/mount.h
8633 --- linux-3.0.25/include/linux/mount.h  2011-03-15 18:07:39.000000000 +0100
8634 +++ linux-3.0.25-vs2.3.2.3/include/linux/mount.h        2011-06-10 22:11:24.000000000 +0200
8635 @@ -52,6 +52,9 @@ struct mnt_pcp {
8636         int mnt_writers;
8637  };
8638  
8639 +#define MNT_TAGID      0x10000
8640 +#define MNT_NOTAG      0x20000
8641 +
8642  struct vfsmount {
8643         struct list_head mnt_hash;
8644         struct vfsmount *mnt_parent;    /* fs we are mounted on */
8645 @@ -86,6 +89,7 @@ struct vfsmount {
8646         int mnt_expiry_mark;            /* true if marked for expiry */
8647         int mnt_pinned;
8648         int mnt_ghosts;
8649 +       tag_t mnt_tag;                  /* tagging used for vfsmount */
8650  };
8651  
8652  struct file; /* forward dec */
8653 diff -NurpP --minimal linux-3.0.25/include/linux/net.h linux-3.0.25-vs2.3.2.3/include/linux/net.h
8654 --- linux-3.0.25/include/linux/net.h    2011-07-22 11:18:11.000000000 +0200
8655 +++ linux-3.0.25-vs2.3.2.3/include/linux/net.h  2011-06-10 22:11:24.000000000 +0200
8656 @@ -72,6 +72,7 @@ struct net;
8657  #define SOCK_NOSPACE           2
8658  #define SOCK_PASSCRED          3
8659  #define SOCK_PASSSEC           4
8660 +#define SOCK_USER_SOCKET       5
8661  
8662  #ifndef ARCH_HAS_SOCKET_TYPES
8663  /**
8664 diff -NurpP --minimal linux-3.0.25/include/linux/netdevice.h linux-3.0.25-vs2.3.2.3/include/linux/netdevice.h
8665 --- linux-3.0.25/include/linux/netdevice.h      2012-03-19 21:16:55.000000000 +0100
8666 +++ linux-3.0.25-vs2.3.2.3/include/linux/netdevice.h    2011-09-17 19:22:49.000000000 +0200
8667 @@ -1650,6 +1650,7 @@ extern void               netdev_resync_ops(struct ne
8668  extern int call_netdevice_notifiers(unsigned long val, struct net_device *dev);
8669  extern struct net_device       *dev_get_by_index(struct net *net, int ifindex);
8670  extern struct net_device       *__dev_get_by_index(struct net *net, int ifindex);
8671 +extern struct net_device       *dev_get_by_index_real_rcu(struct net *net, int ifindex);
8672  extern struct net_device       *dev_get_by_index_rcu(struct net *net, int ifindex);
8673  extern int             dev_restart(struct net_device *dev);
8674  #ifdef CONFIG_NETPOLL_TRAP
8675 diff -NurpP --minimal linux-3.0.25/include/linux/nfs_mount.h linux-3.0.25-vs2.3.2.3/include/linux/nfs_mount.h
8676 --- linux-3.0.25/include/linux/nfs_mount.h      2011-01-05 21:50:31.000000000 +0100
8677 +++ linux-3.0.25-vs2.3.2.3/include/linux/nfs_mount.h    2011-06-10 22:11:24.000000000 +0200
8678 @@ -63,7 +63,8 @@ struct nfs_mount_data {
8679  #define NFS_MOUNT_SECFLAVOUR   0x2000  /* 5 */
8680  #define NFS_MOUNT_NORDIRPLUS   0x4000  /* 5 */
8681  #define NFS_MOUNT_UNSHARED     0x8000  /* 5 */
8682 -#define NFS_MOUNT_FLAGMASK     0xFFFF
8683 +#define NFS_MOUNT_TAGGED       0x10000 /* context tagging */
8684 +#define NFS_MOUNT_FLAGMASK     0x1FFFF
8685  
8686  /* The following are for internal use only */
8687  #define NFS_MOUNT_LOOKUP_CACHE_NONEG   0x10000
8688 diff -NurpP --minimal linux-3.0.25/include/linux/nsproxy.h linux-3.0.25-vs2.3.2.3/include/linux/nsproxy.h
8689 --- linux-3.0.25/include/linux/nsproxy.h        2011-07-22 11:18:11.000000000 +0200
8690 +++ linux-3.0.25-vs2.3.2.3/include/linux/nsproxy.h      2011-06-10 22:11:24.000000000 +0200
8691 @@ -3,6 +3,7 @@
8692  
8693  #include <linux/spinlock.h>
8694  #include <linux/sched.h>
8695 +#include <linux/vserver/debug.h>
8696  
8697  struct mnt_namespace;
8698  struct uts_namespace;
8699 @@ -63,22 +64,33 @@ static inline struct nsproxy *task_nspro
8700  }
8701  
8702  int copy_namespaces(unsigned long flags, struct task_struct *tsk);
8703 +struct nsproxy *copy_nsproxy(struct nsproxy *orig);
8704  void exit_task_namespaces(struct task_struct *tsk);
8705  void switch_task_namespaces(struct task_struct *tsk, struct nsproxy *new);
8706  void free_nsproxy(struct nsproxy *ns);
8707  int unshare_nsproxy_namespaces(unsigned long, struct nsproxy **,
8708         struct fs_struct *);
8709  
8710 -static inline void put_nsproxy(struct nsproxy *ns)
8711 +#define        get_nsproxy(n)  __get_nsproxy(n, __FILE__, __LINE__)
8712 +
8713 +static inline void __get_nsproxy(struct nsproxy *ns,
8714 +       const char *_file, int _line)
8715  {
8716 -       if (atomic_dec_and_test(&ns->count)) {
8717 -               free_nsproxy(ns);
8718 -       }
8719 +       vxlprintk(VXD_CBIT(space, 0), "get_nsproxy(%p[%u])",
8720 +               ns, atomic_read(&ns->count), _file, _line);
8721 +       atomic_inc(&ns->count);
8722  }
8723  
8724 -static inline void get_nsproxy(struct nsproxy *ns)
8725 +#define        put_nsproxy(n)  __put_nsproxy(n, __FILE__, __LINE__)
8726 +
8727 +static inline void __put_nsproxy(struct nsproxy *ns,
8728 +       const char *_file, int _line)
8729  {
8730 -       atomic_inc(&ns->count);
8731 +       vxlprintk(VXD_CBIT(space, 0), "put_nsproxy(%p[%u])",
8732 +               ns, atomic_read(&ns->count), _file, _line);
8733 +       if (atomic_dec_and_test(&ns->count)) {
8734 +               free_nsproxy(ns);
8735 +       }
8736  }
8737  
8738  #endif
8739 diff -NurpP --minimal linux-3.0.25/include/linux/pid.h linux-3.0.25-vs2.3.2.3/include/linux/pid.h
8740 --- linux-3.0.25/include/linux/pid.h    2011-07-22 11:18:11.000000000 +0200
8741 +++ linux-3.0.25-vs2.3.2.3/include/linux/pid.h  2011-06-10 22:11:24.000000000 +0200
8742 @@ -8,7 +8,8 @@ enum pid_type
8743         PIDTYPE_PID,
8744         PIDTYPE_PGID,
8745         PIDTYPE_SID,
8746 -       PIDTYPE_MAX
8747 +       PIDTYPE_MAX,
8748 +       PIDTYPE_REALPID
8749  };
8750  
8751  /*
8752 @@ -171,6 +172,7 @@ static inline pid_t pid_nr(struct pid *p
8753  }
8754  
8755  pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns);
8756 +pid_t pid_unmapped_nr_ns(struct pid *pid, struct pid_namespace *ns);
8757  pid_t pid_vnr(struct pid *pid);
8758  
8759  #define do_each_pid_task(pid, type, task)                              \
8760 diff -NurpP --minimal linux-3.0.25/include/linux/proc_fs.h linux-3.0.25-vs2.3.2.3/include/linux/proc_fs.h
8761 --- linux-3.0.25/include/linux/proc_fs.h        2011-07-22 11:18:11.000000000 +0200
8762 +++ linux-3.0.25-vs2.3.2.3/include/linux/proc_fs.h      2011-06-10 22:11:24.000000000 +0200
8763 @@ -56,6 +56,7 @@ struct proc_dir_entry {
8764         nlink_t nlink;
8765         uid_t uid;
8766         gid_t gid;
8767 +       int vx_flags;
8768         loff_t size;
8769         const struct inode_operations *proc_iops;
8770         /*
8771 @@ -252,12 +253,18 @@ extern const struct proc_ns_operations n
8772  extern const struct proc_ns_operations utsns_operations;
8773  extern const struct proc_ns_operations ipcns_operations;
8774  
8775 +struct vx_info;
8776 +struct nx_info;
8777 +
8778  union proc_op {
8779         int (*proc_get_link)(struct inode *, struct path *);
8780         int (*proc_read)(struct task_struct *task, char *page);
8781         int (*proc_show)(struct seq_file *m,
8782                 struct pid_namespace *ns, struct pid *pid,
8783                 struct task_struct *task);
8784 +       int (*proc_vs_read)(char *page);
8785 +       int (*proc_vxi_read)(struct vx_info *vxi, char *page);
8786 +       int (*proc_nxi_read)(struct nx_info *nxi, char *page);
8787  };
8788  
8789  struct ctl_table_header;
8790 @@ -265,6 +272,7 @@ struct ctl_table;
8791  
8792  struct proc_inode {
8793         struct pid *pid;
8794 +       int vx_flags;
8795         int fd;
8796         union proc_op op;
8797         struct proc_dir_entry *pde;
8798 diff -NurpP --minimal linux-3.0.25/include/linux/quotaops.h linux-3.0.25-vs2.3.2.3/include/linux/quotaops.h
8799 --- linux-3.0.25/include/linux/quotaops.h       2011-05-22 16:17:57.000000000 +0200
8800 +++ linux-3.0.25-vs2.3.2.3/include/linux/quotaops.h     2011-06-10 22:11:24.000000000 +0200
8801 @@ -8,6 +8,7 @@
8802  #define _LINUX_QUOTAOPS_
8803  
8804  #include <linux/fs.h>
8805 +#include <linux/vs_dlimit.h>
8806  
8807  #define DQUOT_SPACE_WARN       0x1
8808  #define DQUOT_SPACE_RESERVE    0x2
8809 @@ -204,11 +205,12 @@ static inline void dquot_drop(struct ino
8810  
8811  static inline int dquot_alloc_inode(const struct inode *inode)
8812  {
8813 -       return 0;
8814 +       return dl_alloc_inode(inode);
8815  }
8816  
8817  static inline void dquot_free_inode(const struct inode *inode)
8818  {
8819 +       dl_free_inode(inode);
8820  }
8821  
8822  static inline int dquot_transfer(struct inode *inode, struct iattr *iattr)
8823 @@ -219,6 +221,10 @@ static inline int dquot_transfer(struct 
8824  static inline int __dquot_alloc_space(struct inode *inode, qsize_t number,
8825                 int flags)
8826  {
8827 +       int ret = 0;
8828 +
8829 +       if ((ret = dl_alloc_space(inode, number)))
8830 +               return ret;
8831         if (!(flags & DQUOT_SPACE_RESERVE))
8832                 inode_add_bytes(inode, number);
8833         return 0;
8834 @@ -229,6 +235,7 @@ static inline void __dquot_free_space(st
8835  {
8836         if (!(flags & DQUOT_SPACE_RESERVE))
8837                 inode_sub_bytes(inode, number);
8838 +       dl_free_space(inode, number);
8839  }
8840  
8841  static inline int dquot_claim_space_nodirty(struct inode *inode, qsize_t number)
8842 diff -NurpP --minimal linux-3.0.25/include/linux/reboot.h linux-3.0.25-vs2.3.2.3/include/linux/reboot.h
8843 --- linux-3.0.25/include/linux/reboot.h 2010-07-07 18:31:56.000000000 +0200
8844 +++ linux-3.0.25-vs2.3.2.3/include/linux/reboot.h       2011-06-10 22:11:24.000000000 +0200
8845 @@ -33,6 +33,7 @@
8846  #define        LINUX_REBOOT_CMD_RESTART2       0xA1B2C3D4
8847  #define        LINUX_REBOOT_CMD_SW_SUSPEND     0xD000FCE2
8848  #define        LINUX_REBOOT_CMD_KEXEC          0x45584543
8849 +#define        LINUX_REBOOT_CMD_OOM            0xDEADBEEF
8850  
8851  
8852  #ifdef __KERNEL__
8853 diff -NurpP --minimal linux-3.0.25/include/linux/reiserfs_fs.h linux-3.0.25-vs2.3.2.3/include/linux/reiserfs_fs.h
8854 --- linux-3.0.25/include/linux/reiserfs_fs.h    2011-05-22 16:17:58.000000000 +0200
8855 +++ linux-3.0.25-vs2.3.2.3/include/linux/reiserfs_fs.h  2011-06-10 22:11:24.000000000 +0200
8856 @@ -976,6 +976,11 @@ struct stat_data_v1 {
8857  #define REISERFS_COMPR_FL     FS_COMPR_FL
8858  #define REISERFS_NOTAIL_FL    FS_NOTAIL_FL
8859  
8860 +/* unfortunately reiserfs sdattr is only 16 bit */
8861 +#define REISERFS_IXUNLINK_FL  (FS_IXUNLINK_FL >> 16)
8862 +#define REISERFS_BARRIER_FL   (FS_BARRIER_FL >> 16)
8863 +#define REISERFS_COW_FL       (FS_COW_FL >> 16)
8864 +
8865  /* persistent flags that file inherits from the parent directory */
8866  #define REISERFS_INHERIT_MASK ( REISERFS_IMMUTABLE_FL |        \
8867                                 REISERFS_SYNC_FL |      \
8868 @@ -985,6 +990,9 @@ struct stat_data_v1 {
8869                                 REISERFS_COMPR_FL |     \
8870                                 REISERFS_NOTAIL_FL )
8871  
8872 +#define REISERFS_FL_USER_VISIBLE       0x80FF
8873 +#define REISERFS_FL_USER_MODIFIABLE    0x80FF
8874 +
8875  /* Stat Data on disk (reiserfs version of UFS disk inode minus the
8876     address blocks) */
8877  struct stat_data {
8878 @@ -2073,6 +2081,7 @@ static inline void reiserfs_update_sd(st
8879  void sd_attrs_to_i_attrs(__u16 sd_attrs, struct inode *inode);
8880  void i_attrs_to_sd_attrs(struct inode *inode, __u16 * sd_attrs);
8881  int reiserfs_setattr(struct dentry *dentry, struct iattr *attr);
8882 +int reiserfs_sync_flags(struct inode *inode, int, int);
8883  
8884  int __reiserfs_write_begin(struct page *page, unsigned from, unsigned len);
8885  
8886 diff -NurpP --minimal linux-3.0.25/include/linux/reiserfs_fs_sb.h linux-3.0.25-vs2.3.2.3/include/linux/reiserfs_fs_sb.h
8887 --- linux-3.0.25/include/linux/reiserfs_fs_sb.h 2010-02-25 11:52:07.000000000 +0100
8888 +++ linux-3.0.25-vs2.3.2.3/include/linux/reiserfs_fs_sb.h       2011-06-10 22:11:24.000000000 +0200
8889 @@ -476,6 +476,7 @@ enum reiserfs_mount_options {
8890         REISERFS_EXPOSE_PRIVROOT,
8891         REISERFS_BARRIER_NONE,
8892         REISERFS_BARRIER_FLUSH,
8893 +       REISERFS_TAGGED,
8894  
8895         /* Actions on error */
8896         REISERFS_ERROR_PANIC,
8897 diff -NurpP --minimal linux-3.0.25/include/linux/sched.h linux-3.0.25-vs2.3.2.3/include/linux/sched.h
8898 --- linux-3.0.25/include/linux/sched.h  2012-03-19 21:16:55.000000000 +0100
8899 +++ linux-3.0.25-vs2.3.2.3/include/linux/sched.h        2011-10-18 13:51:13.000000000 +0200
8900 @@ -1406,6 +1406,14 @@ struct task_struct {
8901  #endif
8902         seccomp_t seccomp;
8903  
8904 +/* vserver context data */
8905 +       struct vx_info *vx_info;
8906 +       struct nx_info *nx_info;
8907 +
8908 +       xid_t xid;
8909 +       nid_t nid;
8910 +       tag_t tag;
8911 +
8912  /* Thread group tracking */
8913         u32 parent_exec_id;
8914         u32 self_exec_id;
8915 @@ -1649,6 +1657,11 @@ struct pid_namespace;
8916  pid_t __task_pid_nr_ns(struct task_struct *task, enum pid_type type,
8917                         struct pid_namespace *ns);
8918  
8919 +#include <linux/vserver/base.h>
8920 +#include <linux/vserver/context.h>
8921 +#include <linux/vserver/debug.h>
8922 +#include <linux/vserver/pid.h>
8923 +
8924  static inline pid_t task_pid_nr(struct task_struct *tsk)
8925  {
8926         return tsk->pid;
8927 @@ -1662,7 +1675,8 @@ static inline pid_t task_pid_nr_ns(struc
8928  
8929  static inline pid_t task_pid_vnr(struct task_struct *tsk)
8930  {
8931 -       return __task_pid_nr_ns(tsk, PIDTYPE_PID, NULL);
8932 +       // return __task_pid_nr_ns(tsk, PIDTYPE_PID, NULL);
8933 +       return vx_map_pid(__task_pid_nr_ns(tsk, PIDTYPE_PID, NULL));
8934  }
8935  
8936  
8937 @@ -1675,7 +1689,7 @@ pid_t task_tgid_nr_ns(struct task_struct
8938  
8939  static inline pid_t task_tgid_vnr(struct task_struct *tsk)
8940  {
8941 -       return pid_vnr(task_tgid(tsk));
8942 +       return vx_map_tgid(pid_vnr(task_tgid(tsk)));
8943  }
8944  
8945  
8946 diff -NurpP --minimal linux-3.0.25/include/linux/shmem_fs.h linux-3.0.25-vs2.3.2.3/include/linux/shmem_fs.h
8947 --- linux-3.0.25/include/linux/shmem_fs.h       2011-07-22 11:18:11.000000000 +0200
8948 +++ linux-3.0.25-vs2.3.2.3/include/linux/shmem_fs.h     2011-07-01 11:35:35.000000000 +0200
8949 @@ -12,6 +12,9 @@
8950  
8951  #define SHMEM_SYMLINK_INLINE_LEN (SHMEM_NR_DIRECT * sizeof(swp_entry_t))
8952  
8953 +#define TMPFS_SUPER_MAGIC      0x01021994
8954 +
8955 +
8956  struct shmem_inode_info {
8957         spinlock_t              lock;
8958         unsigned long           flags;
8959 diff -NurpP --minimal linux-3.0.25/include/linux/stat.h linux-3.0.25-vs2.3.2.3/include/linux/stat.h
8960 --- linux-3.0.25/include/linux/stat.h   2008-12-25 00:26:37.000000000 +0100
8961 +++ linux-3.0.25-vs2.3.2.3/include/linux/stat.h 2011-06-10 22:11:24.000000000 +0200
8962 @@ -66,6 +66,7 @@ struct kstat {
8963         unsigned int    nlink;
8964         uid_t           uid;
8965         gid_t           gid;
8966 +       tag_t           tag;
8967         dev_t           rdev;
8968         loff_t          size;
8969         struct timespec  atime;
8970 diff -NurpP --minimal linux-3.0.25/include/linux/sunrpc/auth.h linux-3.0.25-vs2.3.2.3/include/linux/sunrpc/auth.h
8971 --- linux-3.0.25/include/linux/sunrpc/auth.h    2011-03-15 18:07:39.000000000 +0100
8972 +++ linux-3.0.25-vs2.3.2.3/include/linux/sunrpc/auth.h  2011-06-10 22:11:24.000000000 +0200
8973 @@ -25,6 +25,7 @@
8974  struct auth_cred {
8975         uid_t   uid;
8976         gid_t   gid;
8977 +       tag_t   tag;
8978         struct group_info *group_info;
8979         unsigned char machine_cred : 1;
8980  };
8981 diff -NurpP --minimal linux-3.0.25/include/linux/sunrpc/clnt.h linux-3.0.25-vs2.3.2.3/include/linux/sunrpc/clnt.h
8982 --- linux-3.0.25/include/linux/sunrpc/clnt.h    2011-05-22 16:17:58.000000000 +0200
8983 +++ linux-3.0.25-vs2.3.2.3/include/linux/sunrpc/clnt.h  2011-06-10 22:11:24.000000000 +0200
8984 @@ -49,7 +49,8 @@ struct rpc_clnt {
8985         unsigned int            cl_softrtry : 1,/* soft timeouts */
8986                                 cl_discrtry : 1,/* disconnect before retry */
8987                                 cl_autobind : 1,/* use getport() */
8988 -                               cl_chatty   : 1;/* be verbose */
8989 +                               cl_chatty   : 1,/* be verbose */
8990 +                               cl_tag      : 1;/* context tagging */
8991  
8992         struct rpc_rtt *        cl_rtt;         /* RTO estimator data */
8993         const struct rpc_timeout *cl_timeout;   /* Timeout strategy */
8994 diff -NurpP --minimal linux-3.0.25/include/linux/syscalls.h linux-3.0.25-vs2.3.2.3/include/linux/syscalls.h
8995 --- linux-3.0.25/include/linux/syscalls.h       2011-07-22 11:18:11.000000000 +0200
8996 +++ linux-3.0.25-vs2.3.2.3/include/linux/syscalls.h     2011-06-10 22:11:24.000000000 +0200
8997 @@ -483,6 +483,8 @@ asmlinkage long sys_symlink(const char _
8998  asmlinkage long sys_unlink(const char __user *pathname);
8999  asmlinkage long sys_rename(const char __user *oldname,
9000                                 const char __user *newname);
9001 +asmlinkage long sys_copyfile(const char __user *from, const char __user *to,
9002 +                               umode_t mode);
9003  asmlinkage long sys_chmod(const char __user *filename, mode_t mode);
9004  asmlinkage long sys_fchmod(unsigned int fd, mode_t mode);
9005  
9006 diff -NurpP --minimal linux-3.0.25/include/linux/sysctl.h linux-3.0.25-vs2.3.2.3/include/linux/sysctl.h
9007 --- linux-3.0.25/include/linux/sysctl.h 2011-03-15 18:07:40.000000000 +0100
9008 +++ linux-3.0.25-vs2.3.2.3/include/linux/sysctl.h       2011-06-10 22:11:24.000000000 +0200
9009 @@ -60,6 +60,7 @@ enum
9010         CTL_ABI=9,              /* Binary emulation */
9011         CTL_CPU=10,             /* CPU stuff (speed scaling, etc) */
9012         CTL_ARLAN=254,          /* arlan wireless driver */
9013 +       CTL_VSERVER=4242,       /* Linux-VServer debug */
9014         CTL_S390DBF=5677,       /* s390 debug */
9015         CTL_SUNRPC=7249,        /* sunrpc debug */
9016         CTL_PM=9899,            /* frv power management */
9017 @@ -94,6 +95,7 @@ enum
9018  
9019         KERN_PANIC=15,          /* int: panic timeout */
9020         KERN_REALROOTDEV=16,    /* real root device to mount after initrd */
9021 +       KERN_VSHELPER=17,       /* string: path to vshelper policy agent */
9022  
9023         KERN_SPARC_REBOOT=21,   /* reboot command on Sparc */
9024         KERN_CTLALTDEL=22,      /* int: allow ctl-alt-del to reboot */
9025 diff -NurpP --minimal linux-3.0.25/include/linux/sysfs.h linux-3.0.25-vs2.3.2.3/include/linux/sysfs.h
9026 --- linux-3.0.25/include/linux/sysfs.h  2011-07-22 11:18:11.000000000 +0200
9027 +++ linux-3.0.25-vs2.3.2.3/include/linux/sysfs.h        2011-06-22 12:39:15.000000000 +0200
9028 @@ -19,6 +19,8 @@
9029  #include <linux/kobject_ns.h>
9030  #include <asm/atomic.h>
9031  
9032 +#define SYSFS_SUPER_MAGIC      0x62656572
9033 +
9034  struct kobject;
9035  struct module;
9036  enum kobj_ns_type;
9037 diff -NurpP --minimal linux-3.0.25/include/linux/time.h linux-3.0.25-vs2.3.2.3/include/linux/time.h
9038 --- linux-3.0.25/include/linux/time.h   2011-07-22 11:18:11.000000000 +0200
9039 +++ linux-3.0.25-vs2.3.2.3/include/linux/time.h 2011-06-10 22:11:24.000000000 +0200
9040 @@ -256,6 +256,9 @@ static __always_inline void timespec_add
9041         a->tv_sec += __iter_div_u64_rem(a->tv_nsec + ns, NSEC_PER_SEC, &ns);
9042         a->tv_nsec = ns;
9043  }
9044 +
9045 +#include <linux/vs_time.h>
9046 +
9047  #endif /* __KERNEL__ */
9048  
9049  #define NFDBITS                        __NFDBITS
9050 diff -NurpP --minimal linux-3.0.25/include/linux/types.h linux-3.0.25-vs2.3.2.3/include/linux/types.h
9051 --- linux-3.0.25/include/linux/types.h  2011-05-22 16:17:58.000000000 +0200
9052 +++ linux-3.0.25-vs2.3.2.3/include/linux/types.h        2011-06-10 22:11:24.000000000 +0200
9053 @@ -40,6 +40,9 @@ typedef __kernel_uid32_t      uid_t;
9054  typedef __kernel_gid32_t       gid_t;
9055  typedef __kernel_uid16_t        uid16_t;
9056  typedef __kernel_gid16_t        gid16_t;
9057 +typedef unsigned int           xid_t;
9058 +typedef unsigned int           nid_t;
9059 +typedef unsigned int           tag_t;
9060  
9061  typedef unsigned long          uintptr_t;
9062  
9063 diff -NurpP --minimal linux-3.0.25/include/linux/utsname.h linux-3.0.25-vs2.3.2.3/include/linux/utsname.h
9064 --- linux-3.0.25/include/linux/utsname.h        2011-05-22 16:17:58.000000000 +0200
9065 +++ linux-3.0.25-vs2.3.2.3/include/linux/utsname.h      2011-06-13 14:36:48.000000000 +0200
9066 @@ -54,7 +54,8 @@ static inline void get_uts_ns(struct uts
9067  }
9068  
9069  extern struct uts_namespace *copy_utsname(unsigned long flags,
9070 -                                         struct task_struct *tsk);
9071 +                                         struct uts_namespace *old_ns,
9072 +                                         struct user_namespace *user_ns);
9073  extern void free_uts_ns(struct kref *kref);
9074  
9075  static inline void put_uts_ns(struct uts_namespace *ns)
9076 @@ -71,12 +72,13 @@ static inline void put_uts_ns(struct uts
9077  }
9078  
9079  static inline struct uts_namespace *copy_utsname(unsigned long flags,
9080 -                                                struct task_struct *tsk)
9081 +                                                struct uts_namespace *old_ns,
9082 +                                                struct user_namespace *user_ns)
9083  {
9084         if (flags & CLONE_NEWUTS)
9085                 return ERR_PTR(-EINVAL);
9086  
9087 -       return tsk->nsproxy->uts_ns;
9088 +       return old_ns;
9089  }
9090  #endif
9091  
9092 diff -NurpP --minimal linux-3.0.25/include/linux/vroot.h linux-3.0.25-vs2.3.2.3/include/linux/vroot.h
9093 --- linux-3.0.25/include/linux/vroot.h  1970-01-01 01:00:00.000000000 +0100
9094 +++ linux-3.0.25-vs2.3.2.3/include/linux/vroot.h        2011-06-10 22:11:24.000000000 +0200
9095 @@ -0,0 +1,51 @@
9096 +
9097 +/*
9098 + * include/linux/vroot.h
9099 + *
9100 + * written by Herbert Pötzl, 9/11/2002
9101 + * ported to 2.6 by Herbert Pötzl, 30/12/2004
9102 + *
9103 + * Copyright (C) 2002-2007 by Herbert Pötzl.
9104 + * Redistribution of this file is permitted under the
9105 + * GNU General Public License.
9106 + */
9107 +
9108 +#ifndef _LINUX_VROOT_H
9109 +#define _LINUX_VROOT_H
9110 +
9111 +
9112 +#ifdef __KERNEL__
9113 +
9114 +/* Possible states of device */
9115 +enum {
9116 +       Vr_unbound,
9117 +       Vr_bound,
9118 +};
9119 +
9120 +struct vroot_device {
9121 +       int             vr_number;
9122 +       int             vr_refcnt;
9123 +
9124 +       struct semaphore        vr_ctl_mutex;
9125 +       struct block_device    *vr_device;
9126 +       int                     vr_state;
9127 +};
9128 +
9129 +
9130 +typedef struct block_device *(vroot_grb_func)(struct block_device *);
9131 +
9132 +extern int register_vroot_grb(vroot_grb_func *);
9133 +extern int unregister_vroot_grb(vroot_grb_func *);
9134 +
9135 +#endif /* __KERNEL__ */
9136 +
9137 +#define MAX_VROOT_DEFAULT      8
9138 +
9139 +/*
9140 + * IOCTL commands --- we will commandeer 0x56 ('V')
9141 + */
9142 +
9143 +#define VROOT_SET_DEV          0x5600
9144 +#define VROOT_CLR_DEV          0x5601
9145 +
9146 +#endif /* _LINUX_VROOT_H */
9147 diff -NurpP --minimal linux-3.0.25/include/linux/vs_base.h linux-3.0.25-vs2.3.2.3/include/linux/vs_base.h
9148 --- linux-3.0.25/include/linux/vs_base.h        1970-01-01 01:00:00.000000000 +0100
9149 +++ linux-3.0.25-vs2.3.2.3/include/linux/vs_base.h      2011-06-10 22:11:24.000000000 +0200
9150 @@ -0,0 +1,10 @@
9151 +#ifndef _VS_BASE_H
9152 +#define _VS_BASE_H
9153 +
9154 +#include "vserver/base.h"
9155 +#include "vserver/check.h"
9156 +#include "vserver/debug.h"
9157 +
9158 +#else
9159 +#warning duplicate inclusion
9160 +#endif
9161 diff -NurpP --minimal linux-3.0.25/include/linux/vs_context.h linux-3.0.25-vs2.3.2.3/include/linux/vs_context.h
9162 --- linux-3.0.25/include/linux/vs_context.h     1970-01-01 01:00:00.000000000 +0100
9163 +++ linux-3.0.25-vs2.3.2.3/include/linux/vs_context.h   2011-06-10 22:11:24.000000000 +0200
9164 @@ -0,0 +1,242 @@
9165 +#ifndef _VS_CONTEXT_H
9166 +#define _VS_CONTEXT_H
9167 +
9168 +#include "vserver/base.h"
9169 +#include "vserver/check.h"
9170 +#include "vserver/context.h"
9171 +#include "vserver/history.h"
9172 +#include "vserver/debug.h"
9173 +
9174 +#include <linux/sched.h>
9175 +
9176 +
9177 +#define get_vx_info(i) __get_vx_info(i, __FILE__, __LINE__, __HERE__)
9178 +
9179 +static inline struct vx_info *__get_vx_info(struct vx_info *vxi,
9180 +       const char *_file, int _line, void *_here)
9181 +{
9182 +       if (!vxi)
9183 +               return NULL;
9184 +
9185 +       vxlprintk(VXD_CBIT(xid, 2), "get_vx_info(%p[#%d.%d])",
9186 +               vxi, vxi ? vxi->vx_id : 0,
9187 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
9188 +               _file, _line);
9189 +       __vxh_get_vx_info(vxi, _here);
9190 +
9191 +       atomic_inc(&vxi->vx_usecnt);
9192 +       return vxi;
9193 +}
9194 +
9195 +
9196 +extern void free_vx_info(struct vx_info *);
9197 +
9198 +#define put_vx_info(i) __put_vx_info(i, __FILE__, __LINE__, __HERE__)
9199 +
9200 +static inline void __put_vx_info(struct vx_info *vxi,
9201 +       const char *_file, int _line, void *_here)
9202 +{
9203 +       if (!vxi)
9204 +               return;
9205 +
9206 +       vxlprintk(VXD_CBIT(xid, 2), "put_vx_info(%p[#%d.%d])",
9207 +               vxi, vxi ? vxi->vx_id : 0,
9208 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
9209 +               _file, _line);
9210 +       __vxh_put_vx_info(vxi, _here);
9211 +
9212 +       if (atomic_dec_and_test(&vxi->vx_usecnt))
9213 +               free_vx_info(vxi);
9214 +}
9215 +
9216 +
9217 +#define init_vx_info(p, i) \
9218 +       __init_vx_info(p, i, __FILE__, __LINE__, __HERE__)
9219 +
9220 +static inline void __init_vx_info(struct vx_info **vxp, struct vx_info *vxi,
9221 +       const char *_file, int _line, void *_here)
9222 +{
9223 +       if (vxi) {
9224 +               vxlprintk(VXD_CBIT(xid, 3),
9225 +                       "init_vx_info(%p[#%d.%d])",
9226 +                       vxi, vxi ? vxi->vx_id : 0,
9227 +                       vxi ? atomic_read(&vxi->vx_usecnt) : 0,
9228 +                       _file, _line);
9229 +               __vxh_init_vx_info(vxi, vxp, _here);
9230 +
9231 +               atomic_inc(&vxi->vx_usecnt);
9232 +       }
9233 +       *vxp = vxi;
9234 +}
9235 +
9236 +
9237 +#define set_vx_info(p, i) \
9238 +       __set_vx_info(p, i, __FILE__, __LINE__, __HERE__)
9239 +
9240 +static inline void __set_vx_info(struct vx_info **vxp, struct vx_info *vxi,
9241 +       const char *_file, int _line, void *_here)
9242 +{
9243 +       struct vx_info *vxo;
9244 +
9245 +       if (!vxi)
9246 +               return;
9247 +
9248 +       vxlprintk(VXD_CBIT(xid, 3), "set_vx_info(%p[#%d.%d])",
9249 +               vxi, vxi ? vxi->vx_id : 0,
9250 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
9251 +               _file, _line);
9252 +       __vxh_set_vx_info(vxi, vxp, _here);
9253 +
9254 +       atomic_inc(&vxi->vx_usecnt);
9255 +       vxo = xchg(vxp, vxi);
9256 +       BUG_ON(vxo);
9257 +}
9258 +
9259 +
9260 +#define clr_vx_info(p) __clr_vx_info(p, __FILE__, __LINE__, __HERE__)
9261 +
9262 +static inline void __clr_vx_info(struct vx_info **vxp,
9263 +       const char *_file, int _line, void *_here)
9264 +{
9265 +       struct vx_info *vxo;
9266 +
9267 +       vxo = xchg(vxp, NULL);
9268 +       if (!vxo)
9269 +               return;
9270 +
9271 +       vxlprintk(VXD_CBIT(xid, 3), "clr_vx_info(%p[#%d.%d])",
9272 +               vxo, vxo ? vxo->vx_id : 0,
9273 +               vxo ? atomic_read(&vxo->vx_usecnt) : 0,
9274 +               _file, _line);
9275 +       __vxh_clr_vx_info(vxo, vxp, _here);
9276 +
9277 +       if (atomic_dec_and_test(&vxo->vx_usecnt))
9278 +               free_vx_info(vxo);
9279 +}
9280 +
9281 +
9282 +#define claim_vx_info(v, p) \
9283 +       __claim_vx_info(v, p, __FILE__, __LINE__, __HERE__)
9284 +
9285 +static inline void __claim_vx_info(struct vx_info *vxi,
9286 +       struct task_struct *task,
9287 +       const char *_file, int _line, void *_here)
9288 +{
9289 +       vxlprintk(VXD_CBIT(xid, 3), "claim_vx_info(%p[#%d.%d.%d]) %p",
9290 +               vxi, vxi ? vxi->vx_id : 0,
9291 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
9292 +               vxi ? atomic_read(&vxi->vx_tasks) : 0,
9293 +               task, _file, _line);
9294 +       __vxh_claim_vx_info(vxi, task, _here);
9295 +
9296 +       atomic_inc(&vxi->vx_tasks);
9297 +}
9298 +
9299 +
9300 +extern void unhash_vx_info(struct vx_info *);
9301 +
9302 +#define release_vx_info(v, p) \
9303 +       __release_vx_info(v, p, __FILE__, __LINE__, __HERE__)
9304 +
9305 +static inline void __release_vx_info(struct vx_info *vxi,
9306 +       struct task_struct *task,
9307 +       const char *_file, int _line, void *_here)
9308 +{
9309 +       vxlprintk(VXD_CBIT(xid, 3), "release_vx_info(%p[#%d.%d.%d]) %p",
9310 +               vxi, vxi ? vxi->vx_id : 0,
9311 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
9312 +               vxi ? atomic_read(&vxi->vx_tasks) : 0,
9313 +               task, _file, _line);
9314 +       __vxh_release_vx_info(vxi, task, _here);
9315 +
9316 +       might_sleep();
9317 +
9318 +       if (atomic_dec_and_test(&vxi->vx_tasks))
9319 +               unhash_vx_info(vxi);
9320 +}
9321 +
9322 +
9323 +#define task_get_vx_info(p) \
9324 +       __task_get_vx_info(p, __FILE__, __LINE__, __HERE__)
9325 +
9326 +static inline struct vx_info *__task_get_vx_info(struct task_struct *p,
9327 +       const char *_file, int _line, void *_here)
9328 +{
9329 +       struct vx_info *vxi;
9330 +
9331 +       task_lock(p);
9332 +       vxlprintk(VXD_CBIT(xid, 5), "task_get_vx_info(%p)",
9333 +               p, _file, _line);
9334 +       vxi = __get_vx_info(p->vx_info, _file, _line, _here);
9335 +       task_unlock(p);
9336 +       return vxi;
9337 +}
9338 +
9339 +
9340 +static inline void __wakeup_vx_info(struct vx_info *vxi)
9341 +{
9342 +       if (waitqueue_active(&vxi->vx_wait))
9343 +               wake_up_interruptible(&vxi->vx_wait);
9344 +}
9345 +
9346 +
9347 +#define enter_vx_info(v, s) __enter_vx_info(v, s, __FILE__, __LINE__)
9348 +
9349 +static inline void __enter_vx_info(struct vx_info *vxi,
9350 +       struct vx_info_save *vxis, const char *_file, int _line)
9351 +{
9352 +       vxlprintk(VXD_CBIT(xid, 5), "enter_vx_info(%p[#%d],%p) %p[#%d,%p]",
9353 +               vxi, vxi ? vxi->vx_id : 0, vxis, current,
9354 +               current->xid, current->vx_info, _file, _line);
9355 +       vxis->vxi = xchg(&current->vx_info, vxi);
9356 +       vxis->xid = current->xid;
9357 +       current->xid = vxi ? vxi->vx_id : 0;
9358 +}
9359 +
9360 +#define leave_vx_info(s) __leave_vx_info(s, __FILE__, __LINE__)
9361 +
9362 +static inline void __leave_vx_info(struct vx_info_save *vxis,
9363 +       const char *_file, int _line)
9364 +{
9365 +       vxlprintk(VXD_CBIT(xid, 5), "leave_vx_info(%p[#%d,%p]) %p[#%d,%p]",
9366 +               vxis, vxis->xid, vxis->vxi, current,
9367 +               current->xid, current->vx_info, _file, _line);
9368 +       (void)xchg(&current->vx_info, vxis->vxi);
9369 +       current->xid = vxis->xid;
9370 +}
9371 +
9372 +
9373 +static inline void __enter_vx_admin(struct vx_info_save *vxis)
9374 +{
9375 +       vxis->vxi = xchg(&current->vx_info, NULL);
9376 +       vxis->xid = xchg(&current->xid, (xid_t)0);
9377 +}
9378 +
9379 +static inline void __leave_vx_admin(struct vx_info_save *vxis)
9380 +{
9381 +       (void)xchg(&current->xid, vxis->xid);
9382 +       (void)xchg(&current->vx_info, vxis->vxi);
9383 +}
9384 +
9385 +#define task_is_init(p) \
9386 +       __task_is_init(p, __FILE__, __LINE__, __HERE__)
9387 +
9388 +static inline int __task_is_init(struct task_struct *p,
9389 +       const char *_file, int _line, void *_here)
9390 +{
9391 +       int is_init = is_global_init(p);
9392 +
9393 +       task_lock(p);
9394 +       if (p->vx_info)
9395 +               is_init = p->vx_info->vx_initpid == p->pid;
9396 +       task_unlock(p);
9397 +       return is_init;
9398 +}
9399 +
9400 +extern void exit_vx_info(struct task_struct *, int);
9401 +extern void exit_vx_info_early(struct task_struct *, int);
9402 +
9403 +
9404 +#else
9405 +#warning duplicate inclusion
9406 +#endif
9407 diff -NurpP --minimal linux-3.0.25/include/linux/vs_cowbl.h linux-3.0.25-vs2.3.2.3/include/linux/vs_cowbl.h
9408 --- linux-3.0.25/include/linux/vs_cowbl.h       1970-01-01 01:00:00.000000000 +0100
9409 +++ linux-3.0.25-vs2.3.2.3/include/linux/vs_cowbl.h     2011-06-10 22:11:24.000000000 +0200
9410 @@ -0,0 +1,48 @@
9411 +#ifndef _VS_COWBL_H
9412 +#define _VS_COWBL_H
9413 +
9414 +#include <linux/fs.h>
9415 +#include <linux/dcache.h>
9416 +#include <linux/namei.h>
9417 +#include <linux/slab.h>
9418 +
9419 +extern struct dentry *cow_break_link(const char *pathname);
9420 +
9421 +static inline int cow_check_and_break(struct path *path)
9422 +{
9423 +       struct inode *inode = path->dentry->d_inode;
9424 +       int error = 0;
9425 +
9426 +       /* do we need this check? */
9427 +       if (IS_RDONLY(inode))
9428 +               return -EROFS;
9429 +
9430 +       if (IS_COW(inode)) {
9431 +               if (IS_COW_LINK(inode)) {
9432 +                       struct dentry *new_dentry, *old_dentry = path->dentry;
9433 +                       char *pp, *buf;
9434 +
9435 +                       buf = kmalloc(PATH_MAX, GFP_KERNEL);
9436 +                       if (!buf) {
9437 +                               return -ENOMEM;
9438 +                       }
9439 +                       pp = d_path(path, buf, PATH_MAX);
9440 +                       new_dentry = cow_break_link(pp);
9441 +                       kfree(buf);
9442 +                       if (!IS_ERR(new_dentry)) {
9443 +                               path->dentry = new_dentry;
9444 +                               dput(old_dentry);
9445 +                       } else
9446 +                               error = PTR_ERR(new_dentry);
9447 +               } else {
9448 +                       inode->i_flags &= ~(S_IXUNLINK | S_IMMUTABLE);
9449 +                       inode->i_ctime = CURRENT_TIME;
9450 +                       mark_inode_dirty(inode);
9451 +               }
9452 +       }
9453 +       return error;
9454 +}
9455 +
9456 +#else
9457 +#warning duplicate inclusion
9458 +#endif
9459 diff -NurpP --minimal linux-3.0.25/include/linux/vs_cvirt.h linux-3.0.25-vs2.3.2.3/include/linux/vs_cvirt.h
9460 --- linux-3.0.25/include/linux/vs_cvirt.h       1970-01-01 01:00:00.000000000 +0100
9461 +++ linux-3.0.25-vs2.3.2.3/include/linux/vs_cvirt.h     2011-06-10 22:11:24.000000000 +0200
9462 @@ -0,0 +1,50 @@
9463 +#ifndef _VS_CVIRT_H
9464 +#define _VS_CVIRT_H
9465 +
9466 +#include "vserver/cvirt.h"
9467 +#include "vserver/context.h"
9468 +#include "vserver/base.h"
9469 +#include "vserver/check.h"
9470 +#include "vserver/debug.h"
9471 +
9472 +
9473 +static inline void vx_activate_task(struct task_struct *p)
9474 +{
9475 +       struct vx_info *vxi;
9476 +
9477 +       if ((vxi = p->vx_info)) {
9478 +               vx_update_load(vxi);
9479 +               atomic_inc(&vxi->cvirt.nr_running);
9480 +       }
9481 +}
9482 +
9483 +static inline void vx_deactivate_task(struct task_struct *p)
9484 +{
9485 +       struct vx_info *vxi;
9486 +
9487 +       if ((vxi = p->vx_info)) {
9488 +               vx_update_load(vxi);
9489 +               atomic_dec(&vxi->cvirt.nr_running);
9490 +       }
9491 +}
9492 +
9493 +static inline void vx_uninterruptible_inc(struct task_struct *p)
9494 +{
9495 +       struct vx_info *vxi;
9496 +
9497 +       if ((vxi = p->vx_info))
9498 +               atomic_inc(&vxi->cvirt.nr_uninterruptible);
9499 +}
9500 +
9501 +static inline void vx_uninterruptible_dec(struct task_struct *p)
9502 +{
9503 +       struct vx_info *vxi;
9504 +
9505 +       if ((vxi = p->vx_info))
9506 +               atomic_dec(&vxi->cvirt.nr_uninterruptible);
9507 +}
9508 +
9509 +
9510 +#else
9511 +#warning duplicate inclusion
9512 +#endif
9513 diff -NurpP --minimal linux-3.0.25/include/linux/vs_device.h linux-3.0.25-vs2.3.2.3/include/linux/vs_device.h
9514 --- linux-3.0.25/include/linux/vs_device.h      1970-01-01 01:00:00.000000000 +0100
9515 +++ linux-3.0.25-vs2.3.2.3/include/linux/vs_device.h    2011-06-10 22:11:24.000000000 +0200
9516 @@ -0,0 +1,45 @@
9517 +#ifndef _VS_DEVICE_H
9518 +#define _VS_DEVICE_H
9519 +
9520 +#include "vserver/base.h"
9521 +#include "vserver/device.h"
9522 +#include "vserver/debug.h"
9523 +
9524 +
9525 +#ifdef CONFIG_VSERVER_DEVICE
9526 +
9527 +int vs_map_device(struct vx_info *, dev_t, dev_t *, umode_t);
9528 +
9529 +#define vs_device_perm(v, d, m, p) \
9530 +       ((vs_map_device(current_vx_info(), d, NULL, m) & (p)) == (p))
9531 +
9532 +#else
9533 +
9534 +static inline
9535 +int vs_map_device(struct vx_info *vxi,
9536 +       dev_t device, dev_t *target, umode_t mode)
9537 +{
9538 +       if (target)
9539 +               *target = device;
9540 +       return ~0;
9541 +}
9542 +
9543 +#define vs_device_perm(v, d, m, p) ((p) == (p))
9544 +
9545 +#endif
9546 +
9547 +
9548 +#define vs_map_chrdev(d, t, p) \
9549 +       ((vs_map_device(current_vx_info(), d, t, S_IFCHR) & (p)) == (p))
9550 +#define vs_map_blkdev(d, t, p) \
9551 +       ((vs_map_device(current_vx_info(), d, t, S_IFBLK) & (p)) == (p))
9552 +
9553 +#define vs_chrdev_perm(d, p) \
9554 +       vs_device_perm(current_vx_info(), d, S_IFCHR, p)
9555 +#define vs_blkdev_perm(d, p) \
9556 +       vs_device_perm(current_vx_info(), d, S_IFBLK, p)
9557 +
9558 +
9559 +#else
9560 +#warning duplicate inclusion
9561 +#endif
9562 diff -NurpP --minimal linux-3.0.25/include/linux/vs_dlimit.h linux-3.0.25-vs2.3.2.3/include/linux/vs_dlimit.h
9563 --- linux-3.0.25/include/linux/vs_dlimit.h      1970-01-01 01:00:00.000000000 +0100
9564 +++ linux-3.0.25-vs2.3.2.3/include/linux/vs_dlimit.h    2011-06-10 22:11:24.000000000 +0200
9565 @@ -0,0 +1,215 @@
9566 +#ifndef _VS_DLIMIT_H
9567 +#define _VS_DLIMIT_H
9568 +
9569 +#include <linux/fs.h>
9570 +
9571 +#include "vserver/dlimit.h"
9572 +#include "vserver/base.h"
9573 +#include "vserver/debug.h"
9574 +
9575 +
9576 +#define get_dl_info(i) __get_dl_info(i, __FILE__, __LINE__)
9577 +
9578 +static inline struct dl_info *__get_dl_info(struct dl_info *dli,
9579 +       const char *_file, int _line)
9580 +{
9581 +       if (!dli)
9582 +               return NULL;
9583 +       vxlprintk(VXD_CBIT(dlim, 4), "get_dl_info(%p[#%d.%d])",
9584 +               dli, dli ? dli->dl_tag : 0,
9585 +               dli ? atomic_read(&dli->dl_usecnt) : 0,
9586 +               _file, _line);
9587 +       atomic_inc(&dli->dl_usecnt);
9588 +       return dli;
9589 +}
9590 +
9591 +
9592 +#define free_dl_info(i) \
9593 +       call_rcu(&(i)->dl_rcu, rcu_free_dl_info)
9594 +
9595 +#define put_dl_info(i) __put_dl_info(i, __FILE__, __LINE__)
9596 +
9597 +static inline void __put_dl_info(struct dl_info *dli,
9598 +       const char *_file, int _line)
9599 +{
9600 +       if (!dli)
9601 +               return;
9602 +       vxlprintk(VXD_CBIT(dlim, 4), "put_dl_info(%p[#%d.%d])",
9603 +               dli, dli ? dli->dl_tag : 0,
9604 +               dli ? atomic_read(&dli->dl_usecnt) : 0,
9605 +               _file, _line);
9606 +       if (atomic_dec_and_test(&dli->dl_usecnt))
9607 +               free_dl_info(dli);
9608 +}
9609 +
9610 +
9611 +#define __dlimit_char(d)       ((d) ? '*' : ' ')
9612 +
9613 +static inline int __dl_alloc_space(struct super_block *sb,
9614 +       tag_t tag, dlsize_t nr, const char *file, int line)
9615 +{
9616 +       struct dl_info *dli = NULL;
9617 +       int ret = 0;
9618 +
9619 +       if (nr == 0)
9620 +               goto out;
9621 +       dli = locate_dl_info(sb, tag);
9622 +       if (!dli)
9623 +               goto out;
9624 +
9625 +       spin_lock(&dli->dl_lock);
9626 +       ret = (dli->dl_space_used + nr > dli->dl_space_total);
9627 +       if (!ret)
9628 +               dli->dl_space_used += nr;
9629 +       spin_unlock(&dli->dl_lock);
9630 +       put_dl_info(dli);
9631 +out:
9632 +       vxlprintk(VXD_CBIT(dlim, 1),
9633 +               "ALLOC (%p,#%d)%c %lld bytes (%d)",
9634 +               sb, tag, __dlimit_char(dli), (long long)nr,
9635 +               ret, file, line);
9636 +       return ret ? -ENOSPC : 0;
9637 +}
9638 +
9639 +static inline void __dl_free_space(struct super_block *sb,
9640 +       tag_t tag, dlsize_t nr, const char *_file, int _line)
9641 +{
9642 +       struct dl_info *dli = NULL;
9643 +
9644 +       if (nr == 0)
9645 +               goto out;
9646 +       dli = locate_dl_info(sb, tag);
9647 +       if (!dli)
9648 +               goto out;
9649 +
9650 +       spin_lock(&dli->dl_lock);
9651 +       if (dli->dl_space_used > nr)
9652 +               dli->dl_space_used -= nr;
9653 +       else
9654 +               dli->dl_space_used = 0;
9655 +       spin_unlock(&dli->dl_lock);
9656 +       put_dl_info(dli);
9657 +out:
9658 +       vxlprintk(VXD_CBIT(dlim, 1),
9659 +               "FREE  (%p,#%d)%c %lld bytes",
9660 +               sb, tag, __dlimit_char(dli), (long long)nr,
9661 +               _file, _line);
9662 +}
9663 +
9664 +static inline int __dl_alloc_inode(struct super_block *sb,
9665 +       tag_t tag, const char *_file, int _line)
9666 +{
9667 +       struct dl_info *dli;
9668 +       int ret = 0;
9669 +
9670 +       dli = locate_dl_info(sb, tag);
9671 +       if (!dli)
9672 +               goto out;
9673 +
9674 +       spin_lock(&dli->dl_lock);
9675 +       dli->dl_inodes_used++;
9676 +       ret = (dli->dl_inodes_used > dli->dl_inodes_total);
9677 +       spin_unlock(&dli->dl_lock);
9678 +       put_dl_info(dli);
9679 +out:
9680 +       vxlprintk(VXD_CBIT(dlim, 0),
9681 +               "ALLOC (%p,#%d)%c inode (%d)",
9682 +               sb, tag, __dlimit_char(dli), ret, _file, _line);
9683 +       return ret ? -ENOSPC : 0;
9684 +}
9685 +
9686 +static inline void __dl_free_inode(struct super_block *sb,
9687 +       tag_t tag, const char *_file, int _line)
9688 +{
9689 +       struct dl_info *dli;
9690 +
9691 +       dli = locate_dl_info(sb, tag);
9692 +       if (!dli)
9693 +               goto out;
9694 +
9695 +       spin_lock(&dli->dl_lock);
9696 +       if (dli->dl_inodes_used > 1)
9697 +               dli->dl_inodes_used--;
9698 +       else
9699 +               dli->dl_inodes_used = 0;
9700 +       spin_unlock(&dli->dl_lock);
9701 +       put_dl_info(dli);
9702 +out:
9703 +       vxlprintk(VXD_CBIT(dlim, 0),
9704 +               "FREE  (%p,#%d)%c inode",
9705 +               sb, tag, __dlimit_char(dli), _file, _line);
9706 +}
9707 +
9708 +static inline void __dl_adjust_block(struct super_block *sb, tag_t tag,
9709 +       unsigned long long *free_blocks, unsigned long long *root_blocks,
9710 +       const char *_file, int _line)
9711 +{
9712 +       struct dl_info *dli;
9713 +       uint64_t broot, bfree;
9714 +
9715 +       dli = locate_dl_info(sb, tag);
9716 +       if (!dli)
9717 +               return;
9718 +
9719 +       spin_lock(&dli->dl_lock);
9720 +       broot = (dli->dl_space_total -
9721 +               (dli->dl_space_total >> 10) * dli->dl_nrlmult)
9722 +               >> sb->s_blocksize_bits;
9723 +       bfree = (dli->dl_space_total - dli->dl_space_used)
9724 +                       >> sb->s_blocksize_bits;
9725 +       spin_unlock(&dli->dl_lock);
9726 +
9727 +       vxlprintk(VXD_CBIT(dlim, 2),
9728 +               "ADJUST: %lld,%lld on %lld,%lld [mult=%d]",
9729 +               (long long)bfree, (long long)broot,
9730 +               *free_blocks, *root_blocks, dli->dl_nrlmult,
9731 +               _file, _line);
9732 +       if (free_blocks) {
9733 +               if (*free_blocks > bfree)
9734 +                       *free_blocks = bfree;
9735 +       }
9736 +       if (root_blocks) {
9737 +               if (*root_blocks > broot)
9738 +                       *root_blocks = broot;
9739 +       }
9740 +       put_dl_info(dli);
9741 +}
9742 +
9743 +#define dl_prealloc_space(in, bytes) \
9744 +       __dl_alloc_space((in)->i_sb, (in)->i_tag, (dlsize_t)(bytes), \
9745 +               __FILE__, __LINE__ )
9746 +
9747 +#define dl_alloc_space(in, bytes) \
9748 +       __dl_alloc_space((in)->i_sb, (in)->i_tag, (dlsize_t)(bytes), \
9749 +               __FILE__, __LINE__ )
9750 +
9751 +#define dl_reserve_space(in, bytes) \
9752 +       __dl_alloc_space((in)->i_sb, (in)->i_tag, (dlsize_t)(bytes), \
9753 +               __FILE__, __LINE__ )
9754 +
9755 +#define dl_claim_space(in, bytes) (0)
9756 +
9757 +#define dl_release_space(in, bytes) \
9758 +       __dl_free_space((in)->i_sb, (in)->i_tag, (dlsize_t)(bytes), \
9759 +               __FILE__, __LINE__ )
9760 +
9761 +#define dl_free_space(in, bytes) \
9762 +       __dl_free_space((in)->i_sb, (in)->i_tag, (dlsize_t)(bytes), \
9763 +               __FILE__, __LINE__ )
9764 +
9765 +
9766 +
9767 +#define dl_alloc_inode(in) \
9768 +       __dl_alloc_inode((in)->i_sb, (in)->i_tag, __FILE__, __LINE__ )
9769 +
9770 +#define dl_free_inode(in) \
9771 +       __dl_free_inode((in)->i_sb, (in)->i_tag, __FILE__, __LINE__ )
9772 +
9773 +
9774 +#define dl_adjust_block(sb, tag, fb, rb) \
9775 +       __dl_adjust_block(sb, tag, fb, rb, __FILE__, __LINE__ )
9776 +
9777 +
9778 +#else
9779 +#warning duplicate inclusion
9780 +#endif
9781 diff -NurpP --minimal linux-3.0.25/include/linux/vs_inet.h linux-3.0.25-vs2.3.2.3/include/linux/vs_inet.h
9782 --- linux-3.0.25/include/linux/vs_inet.h        1970-01-01 01:00:00.000000000 +0100
9783 +++ linux-3.0.25-vs2.3.2.3/include/linux/vs_inet.h      2011-08-18 17:01:00.000000000 +0200
9784 @@ -0,0 +1,353 @@
9785 +#ifndef _VS_INET_H
9786 +#define _VS_INET_H
9787 +
9788 +#include "vserver/base.h"
9789 +#include "vserver/network.h"
9790 +#include "vserver/debug.h"
9791 +
9792 +#define IPI_LOOPBACK   htonl(INADDR_LOOPBACK)
9793 +
9794 +#define NXAV4(a)       NIPQUAD((a)->ip[0]), NIPQUAD((a)->ip[1]), \
9795 +                       NIPQUAD((a)->mask), (a)->type
9796 +#define NXAV4_FMT      "[" NIPQUAD_FMT "-" NIPQUAD_FMT "/" NIPQUAD_FMT ":%04x]"
9797 +
9798 +#define NIPQUAD(addr) \
9799 +       ((unsigned char *)&addr)[0], \
9800 +       ((unsigned char *)&addr)[1], \
9801 +       ((unsigned char *)&addr)[2], \
9802 +       ((unsigned char *)&addr)[3]
9803 +
9804 +#define NIPQUAD_FMT "%u.%u.%u.%u"
9805 +
9806 +
9807 +static inline
9808 +int v4_addr_match(struct nx_addr_v4 *nxa, __be32 addr, uint16_t tmask)
9809 +{
9810 +       __be32 ip = nxa->ip[0].s_addr;
9811 +       __be32 mask = nxa->mask.s_addr;
9812 +       __be32 bcast = ip | ~mask;
9813 +       int ret = 0;
9814 +
9815 +       switch (nxa->type & tmask) {
9816 +       case NXA_TYPE_MASK:
9817 +               ret = (ip == (addr & mask));
9818 +               break;
9819 +       case NXA_TYPE_ADDR:
9820 +               ret = 3;
9821 +               if (addr == ip)
9822 +                       break;
9823 +               /* fall through to broadcast */
9824 +       case NXA_MOD_BCAST:
9825 +               ret = ((tmask & NXA_MOD_BCAST) && (addr == bcast));
9826 +               break;
9827 +       case NXA_TYPE_RANGE:
9828 +               ret = ((nxa->ip[0].s_addr <= addr) &&
9829 +                       (nxa->ip[1].s_addr > addr));
9830 +               break;
9831 +       case NXA_TYPE_ANY:
9832 +               ret = 2;
9833 +               break;
9834 +       }
9835 +
9836 +       vxdprintk(VXD_CBIT(net, 0),
9837 +               "v4_addr_match(%p" NXAV4_FMT "," NIPQUAD_FMT ",%04x) = %d",
9838 +               nxa, NXAV4(nxa), NIPQUAD(addr), tmask, ret);
9839 +       return ret;
9840 +}
9841 +
9842 +static inline
9843 +int v4_addr_in_nx_info(struct nx_info *nxi, __be32 addr, uint16_t tmask)
9844 +{
9845 +       struct nx_addr_v4 *nxa;
9846 +       int ret = 1;
9847 +
9848 +       if (!nxi)
9849 +               goto out;
9850 +
9851 +       ret = 2;
9852 +       /* allow 127.0.0.1 when remapping lback */
9853 +       if ((tmask & NXA_LOOPBACK) &&
9854 +               (addr == IPI_LOOPBACK) &&
9855 +               nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
9856 +               goto out;
9857 +       ret = 3;
9858 +       /* check for lback address */
9859 +       if ((tmask & NXA_MOD_LBACK) &&
9860 +               (nxi->v4_lback.s_addr == addr))
9861 +               goto out;
9862 +       ret = 4;
9863 +       /* check for broadcast address */
9864 +       if ((tmask & NXA_MOD_BCAST) &&
9865 +               (nxi->v4_bcast.s_addr == addr))
9866 +               goto out;
9867 +       ret = 5;
9868 +       /* check for v4 addresses */
9869 +       for (nxa = &nxi->v4; nxa; nxa = nxa->next)
9870 +               if (v4_addr_match(nxa, addr, tmask))
9871 +                       goto out;
9872 +       ret = 0;
9873 +out:
9874 +       vxdprintk(VXD_CBIT(net, 0),
9875 +               "v4_addr_in_nx_info(%p[#%u]," NIPQUAD_FMT ",%04x) = %d",
9876 +               nxi, nxi ? nxi->nx_id : 0, NIPQUAD(addr), tmask, ret);
9877 +       return ret;
9878 +}
9879 +
9880 +static inline
9881 +int v4_nx_addr_match(struct nx_addr_v4 *nxa, struct nx_addr_v4 *addr, uint16_t mask)
9882 +{
9883 +       /* FIXME: needs full range checks */
9884 +       return v4_addr_match(nxa, addr->ip[0].s_addr, mask);
9885 +}
9886 +
9887 +static inline
9888 +int v4_nx_addr_in_nx_info(struct nx_info *nxi, struct nx_addr_v4 *nxa, uint16_t mask)
9889 +{
9890 +       struct nx_addr_v4 *ptr;
9891 +
9892 +       for (ptr = &nxi->v4; ptr; ptr = ptr->next)
9893 +               if (v4_nx_addr_match(ptr, nxa, mask))
9894 +                       return 1;
9895 +       return 0;
9896 +}
9897 +
9898 +#include <net/inet_sock.h>
9899 +
9900 +/*
9901 + *     Check if a given address matches for a socket
9902 + *
9903 + *     nxi:            the socket's nx_info if any
9904 + *     addr:           to be verified address
9905 + */
9906 +static inline
9907 +int v4_sock_addr_match (
9908 +       struct nx_info *nxi,
9909 +       struct inet_sock *inet,
9910 +       __be32 addr)
9911 +{
9912 +       __be32 saddr = inet->inet_rcv_saddr;
9913 +       __be32 bcast = nxi ? nxi->v4_bcast.s_addr : INADDR_BROADCAST;
9914 +
9915 +       if (addr && (saddr == addr || bcast == addr))
9916 +               return 1;
9917 +       if (!saddr)
9918 +               return v4_addr_in_nx_info(nxi, addr, NXA_MASK_BIND);
9919 +       return 0;
9920 +}
9921 +
9922 +
9923 +/* inet related checks and helpers */
9924 +
9925 +
9926 +struct in_ifaddr;
9927 +struct net_device;
9928 +struct sock;
9929 +
9930 +#ifdef CONFIG_INET
9931 +
9932 +#include <linux/netdevice.h>
9933 +#include <linux/inetdevice.h>
9934 +#include <net/inet_sock.h>
9935 +#include <net/inet_timewait_sock.h>
9936 +
9937 +
9938 +int dev_in_nx_info(struct net_device *, struct nx_info *);
9939 +int v4_dev_in_nx_info(struct net_device *, struct nx_info *);
9940 +int nx_v4_addr_conflict(struct nx_info *, struct nx_info *);
9941 +
9942 +
9943 +/*
9944 + *     check if address is covered by socket
9945 + *
9946 + *     sk:     the socket to check against
9947 + *     addr:   the address in question (must be != 0)
9948 + */
9949 +
9950 +static inline
9951 +int __v4_addr_match_socket(const struct sock *sk, struct nx_addr_v4 *nxa)
9952 +{
9953 +       struct nx_info *nxi = sk->sk_nx_info;
9954 +       __be32 saddr = sk_rcv_saddr(sk);
9955 +
9956 +       vxdprintk(VXD_CBIT(net, 5),
9957 +               "__v4_addr_in_socket(%p," NXAV4_FMT ") %p:" NIPQUAD_FMT " %p;%lx",
9958 +               sk, NXAV4(nxa), nxi, NIPQUAD(saddr), sk->sk_socket,
9959 +               (sk->sk_socket?sk->sk_socket->flags:0));
9960 +
9961 +       if (saddr) {            /* direct address match */
9962 +               return v4_addr_match(nxa, saddr, -1);
9963 +       } else if (nxi) {       /* match against nx_info */
9964 +               return v4_nx_addr_in_nx_info(nxi, nxa, -1);
9965 +       } else {                /* unrestricted any socket */
9966 +               return 1;
9967 +       }
9968 +}
9969 +
9970 +
9971 +
9972 +static inline
9973 +int nx_dev_visible(struct nx_info *nxi, struct net_device *dev)
9974 +{
9975 +       vxdprintk(VXD_CBIT(net, 1),
9976 +               "nx_dev_visible(%p[#%u],%p " VS_Q("%s") ") %d",
9977 +               nxi, nxi ? nxi->nx_id : 0, dev, dev->name,
9978 +               nxi ? dev_in_nx_info(dev, nxi) : 0);
9979 +
9980 +       if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
9981 +               return 1;
9982 +       if (dev_in_nx_info(dev, nxi))
9983 +               return 1;
9984 +       return 0;
9985 +}
9986 +
9987 +
9988 +static inline
9989 +int v4_ifa_in_nx_info(struct in_ifaddr *ifa, struct nx_info *nxi)
9990 +{
9991 +       if (!nxi)
9992 +               return 1;
9993 +       if (!ifa)
9994 +               return 0;
9995 +       return v4_addr_in_nx_info(nxi, ifa->ifa_local, NXA_MASK_SHOW);
9996 +}
9997 +
9998 +static inline
9999 +int nx_v4_ifa_visible(struct nx_info *nxi, struct in_ifaddr *ifa)
10000 +{
10001 +       vxdprintk(VXD_CBIT(net, 1), "nx_v4_ifa_visible(%p[#%u],%p) %d",
10002 +               nxi, nxi ? nxi->nx_id : 0, ifa,
10003 +               nxi ? v4_ifa_in_nx_info(ifa, nxi) : 0);
10004 +
10005 +       if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
10006 +               return 1;
10007 +       if (v4_ifa_in_nx_info(ifa, nxi))
10008 +               return 1;
10009 +       return 0;
10010 +}
10011 +
10012 +
10013 +struct nx_v4_sock_addr {
10014 +       __be32 saddr;   /* Address used for validation */
10015 +       __be32 baddr;   /* Address used for socket bind */
10016 +};
10017 +
10018 +static inline
10019 +int v4_map_sock_addr(struct inet_sock *inet, struct sockaddr_in *addr,
10020 +       struct nx_v4_sock_addr *nsa)
10021 +{
10022 +       struct sock *sk = &inet->sk;
10023 +       struct nx_info *nxi = sk->sk_nx_info;
10024 +       __be32 saddr = addr->sin_addr.s_addr;
10025 +       __be32 baddr = saddr;
10026 +
10027 +       vxdprintk(VXD_CBIT(net, 3),
10028 +               "inet_bind(%p)* %p,%p;%lx " NIPQUAD_FMT,
10029 +               sk, sk->sk_nx_info, sk->sk_socket,
10030 +               (sk->sk_socket ? sk->sk_socket->flags : 0),
10031 +               NIPQUAD(saddr));
10032 +
10033 +       if (nxi) {
10034 +               if (saddr == INADDR_ANY) {
10035 +                       if (nx_info_flags(nxi, NXF_SINGLE_IP, 0))
10036 +                               baddr = nxi->v4.ip[0].s_addr;
10037 +               } else if (saddr == IPI_LOOPBACK) {
10038 +                       if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
10039 +                               baddr = nxi->v4_lback.s_addr;
10040 +               } else if (!ipv4_is_multicast(saddr) ||
10041 +                       !nx_info_ncaps(nxi, NXC_MULTICAST)) {
10042 +                       /* normal address bind */
10043 +                       if (!v4_addr_in_nx_info(nxi, saddr, NXA_MASK_BIND))
10044 +                               return -EADDRNOTAVAIL;
10045 +               }
10046 +       }
10047 +
10048 +       vxdprintk(VXD_CBIT(net, 3),
10049 +               "inet_bind(%p) " NIPQUAD_FMT ", " NIPQUAD_FMT,
10050 +               sk, NIPQUAD(saddr), NIPQUAD(baddr));
10051 +
10052 +       nsa->saddr = saddr;
10053 +       nsa->baddr = baddr;
10054 +       return 0;
10055 +}
10056 +
10057 +static inline
10058 +void v4_set_sock_addr(struct inet_sock *inet, struct nx_v4_sock_addr *nsa)
10059 +{
10060 +       inet->inet_saddr = nsa->baddr;
10061 +       inet->inet_rcv_saddr = nsa->baddr;
10062 +}
10063 +
10064 +
10065 +/*
10066 + *      helper to simplify inet_lookup_listener
10067 + *
10068 + *      nxi:   the socket's nx_info if any
10069 + *      addr:  to be verified address
10070 + *      saddr: socket address
10071 + */
10072 +static inline int v4_inet_addr_match (
10073 +       struct nx_info *nxi,
10074 +       __be32 addr,
10075 +       __be32 saddr)
10076 +{
10077 +       if (addr && (saddr == addr))
10078 +               return 1;
10079 +       if (!saddr)
10080 +               return nxi ? v4_addr_in_nx_info(nxi, addr, NXA_MASK_BIND) : 1;
10081 +       return 0;
10082 +}
10083 +
10084 +static inline __be32 nx_map_sock_lback(struct nx_info *nxi, __be32 addr)
10085 +{
10086 +       if (nx_info_flags(nxi, NXF_HIDE_LBACK, 0) &&
10087 +               (addr == nxi->v4_lback.s_addr))
10088 +               return IPI_LOOPBACK;
10089 +       return addr;
10090 +}
10091 +
10092 +static inline
10093 +int nx_info_has_v4(struct nx_info *nxi)
10094 +{
10095 +       if (!nxi)
10096 +               return 1;
10097 +       if (NX_IPV4(nxi))
10098 +               return 1;
10099 +       if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
10100 +               return 1;
10101 +       return 0;
10102 +}
10103 +
10104 +#else /* CONFIG_INET */
10105 +
10106 +static inline
10107 +int nx_dev_visible(struct nx_info *n, struct net_device *d)
10108 +{
10109 +       return 1;
10110 +}
10111 +
10112 +static inline
10113 +int nx_v4_addr_conflict(struct nx_info *n, uint32_t a, const struct sock *s)
10114 +{
10115 +       return 1;
10116 +}
10117 +
10118 +static inline
10119 +int v4_ifa_in_nx_info(struct in_ifaddr *a, struct nx_info *n)
10120 +{
10121 +       return 1;
10122 +}
10123 +
10124 +static inline
10125 +int nx_info_has_v4(struct nx_info *nxi)
10126 +{
10127 +       return 0;
10128 +}
10129 +
10130 +#endif /* CONFIG_INET */
10131 +
10132 +#define current_nx_info_has_v4() \
10133 +       nx_info_has_v4(current_nx_info())
10134 +
10135 +#else
10136 +// #warning duplicate inclusion
10137 +#endif
10138 diff -NurpP --minimal linux-3.0.25/include/linux/vs_inet6.h linux-3.0.25-vs2.3.2.3/include/linux/vs_inet6.h
10139 --- linux-3.0.25/include/linux/vs_inet6.h       1970-01-01 01:00:00.000000000 +0100
10140 +++ linux-3.0.25-vs2.3.2.3/include/linux/vs_inet6.h     2011-06-10 22:11:24.000000000 +0200
10141 @@ -0,0 +1,246 @@
10142 +#ifndef _VS_INET6_H
10143 +#define _VS_INET6_H
10144 +
10145 +#include "vserver/base.h"
10146 +#include "vserver/network.h"
10147 +#include "vserver/debug.h"
10148 +
10149 +#include <net/ipv6.h>
10150 +
10151 +#define NXAV6(a)       &(a)->ip, &(a)->mask, (a)->prefix, (a)->type
10152 +#define NXAV6_FMT      "[%pI6/%pI6/%d:%04x]"
10153 +
10154 +
10155 +#ifdef CONFIG_IPV6
10156 +
10157 +static inline
10158 +int v6_addr_match(struct nx_addr_v6 *nxa,
10159 +       const struct in6_addr *addr, uint16_t mask)
10160 +{
10161 +       int ret = 0;
10162 +
10163 +       switch (nxa->type & mask) {
10164 +       case NXA_TYPE_MASK:
10165 +               ret = ipv6_masked_addr_cmp(&nxa->ip, &nxa->mask, addr);
10166 +               break;
10167 +       case NXA_TYPE_ADDR:
10168 +               ret = ipv6_addr_equal(&nxa->ip, addr);
10169 +               break;
10170 +       case NXA_TYPE_ANY:
10171 +               ret = 1;
10172 +               break;
10173 +       }
10174 +       vxdprintk(VXD_CBIT(net, 0),
10175 +               "v6_addr_match(%p" NXAV6_FMT ",%pI6,%04x) = %d",
10176 +               nxa, NXAV6(nxa), addr, mask, ret);
10177 +       return ret;
10178 +}
10179 +
10180 +static inline
10181 +int v6_addr_in_nx_info(struct nx_info *nxi,
10182 +       const struct in6_addr *addr, uint16_t mask)
10183 +{
10184 +       struct nx_addr_v6 *nxa;
10185 +       int ret = 1;
10186 +
10187 +       if (!nxi)
10188 +               goto out;
10189 +       for (nxa = &nxi->v6; nxa; nxa = nxa->next)
10190 +               if (v6_addr_match(nxa, addr, mask))
10191 +                       goto out;
10192 +       ret = 0;
10193 +out:
10194 +       vxdprintk(VXD_CBIT(net, 0),
10195 +               "v6_addr_in_nx_info(%p[#%u],%pI6,%04x) = %d",
10196 +               nxi, nxi ? nxi->nx_id : 0, addr, mask, ret);
10197 +       return ret;
10198 +}
10199 +
10200 +static inline
10201 +int v6_nx_addr_match(struct nx_addr_v6 *nxa, struct nx_addr_v6 *addr, uint16_t mask)
10202 +{
10203 +       /* FIXME: needs full range checks */
10204 +       return v6_addr_match(nxa, &addr->ip, mask);
10205 +}
10206 +
10207 +static inline
10208 +int v6_nx_addr_in_nx_info(struct nx_info *nxi, struct nx_addr_v6 *nxa, uint16_t mask)
10209 +{
10210 +       struct nx_addr_v6 *ptr;
10211 +
10212 +       for (ptr = &nxi->v6; ptr; ptr = ptr->next)
10213 +               if (v6_nx_addr_match(ptr, nxa, mask))
10214 +                       return 1;
10215 +       return 0;
10216 +}
10217 +
10218 +
10219 +/*
10220 + *     Check if a given address matches for a socket
10221 + *
10222 + *     nxi:            the socket's nx_info if any
10223 + *     addr:           to be verified address
10224 + */
10225 +static inline
10226 +int v6_sock_addr_match (
10227 +       struct nx_info *nxi,
10228 +       struct inet_sock *inet,
10229 +       struct in6_addr *addr)
10230 +{
10231 +       struct sock *sk = &inet->sk;
10232 +       struct in6_addr *saddr = inet6_rcv_saddr(sk);
10233 +
10234 +       if (!ipv6_addr_any(addr) &&
10235 +               ipv6_addr_equal(saddr, addr))
10236 +               return 1;
10237 +       if (ipv6_addr_any(saddr))
10238 +               return v6_addr_in_nx_info(nxi, addr, -1);
10239 +       return 0;
10240 +}
10241 +
10242 +/*
10243 + *     check if address is covered by socket
10244 + *
10245 + *     sk:     the socket to check against
10246 + *     addr:   the address in question (must be != 0)
10247 + */
10248 +
10249 +static inline
10250 +int __v6_addr_match_socket(const struct sock *sk, struct nx_addr_v6 *nxa)
10251 +{
10252 +       struct nx_info *nxi = sk->sk_nx_info;
10253 +       struct in6_addr *saddr = inet6_rcv_saddr(sk);
10254 +
10255 +       vxdprintk(VXD_CBIT(net, 5),
10256 +               "__v6_addr_in_socket(%p," NXAV6_FMT ") %p:%pI6 %p;%lx",
10257 +               sk, NXAV6(nxa), nxi, saddr, sk->sk_socket,
10258 +               (sk->sk_socket?sk->sk_socket->flags:0));
10259 +
10260 +       if (!ipv6_addr_any(saddr)) {    /* direct address match */
10261 +               return v6_addr_match(nxa, saddr, -1);
10262 +       } else if (nxi) {               /* match against nx_info */
10263 +               return v6_nx_addr_in_nx_info(nxi, nxa, -1);
10264 +       } else {                        /* unrestricted any socket */
10265 +               return 1;
10266 +       }
10267 +}
10268 +
10269 +
10270 +/* inet related checks and helpers */
10271 +
10272 +
10273 +struct in_ifaddr;
10274 +struct net_device;
10275 +struct sock;
10276 +
10277 +
10278 +#include <linux/netdevice.h>
10279 +#include <linux/inetdevice.h>
10280 +#include <net/inet_timewait_sock.h>
10281 +
10282 +
10283 +int dev_in_nx_info(struct net_device *, struct nx_info *);
10284 +int v6_dev_in_nx_info(struct net_device *, struct nx_info *);
10285 +int nx_v6_addr_conflict(struct nx_info *, struct nx_info *);
10286 +
10287 +
10288 +
10289 +static inline
10290 +int v6_ifa_in_nx_info(struct inet6_ifaddr *ifa, struct nx_info *nxi)
10291 +{
10292 +       if (!nxi)
10293 +               return 1;
10294 +       if (!ifa)
10295 +               return 0;
10296 +       return v6_addr_in_nx_info(nxi, &ifa->addr, -1);
10297 +}
10298 +
10299 +static inline
10300 +int nx_v6_ifa_visible(struct nx_info *nxi, struct inet6_ifaddr *ifa)
10301 +{
10302 +       vxdprintk(VXD_CBIT(net, 1), "nx_v6_ifa_visible(%p[#%u],%p) %d",
10303 +               nxi, nxi ? nxi->nx_id : 0, ifa,
10304 +               nxi ? v6_ifa_in_nx_info(ifa, nxi) : 0);
10305 +
10306 +       if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
10307 +               return 1;
10308 +       if (v6_ifa_in_nx_info(ifa, nxi))
10309 +               return 1;
10310 +       return 0;
10311 +}
10312 +
10313 +
10314 +struct nx_v6_sock_addr {
10315 +       struct in6_addr saddr;  /* Address used for validation */
10316 +       struct in6_addr baddr;  /* Address used for socket bind */
10317 +};
10318 +
10319 +static inline
10320 +int v6_map_sock_addr(struct inet_sock *inet, struct sockaddr_in6 *addr,
10321 +       struct nx_v6_sock_addr *nsa)
10322 +{
10323 +       // struct sock *sk = &inet->sk;
10324 +       // struct nx_info *nxi = sk->sk_nx_info;
10325 +       struct in6_addr saddr = addr->sin6_addr;
10326 +       struct in6_addr baddr = saddr;
10327 +
10328 +       nsa->saddr = saddr;
10329 +       nsa->baddr = baddr;
10330 +       return 0;
10331 +}
10332 +
10333 +static inline
10334 +void v6_set_sock_addr(struct inet_sock *inet, struct nx_v6_sock_addr *nsa)
10335 +{
10336 +       // struct sock *sk = &inet->sk;
10337 +       // struct in6_addr *saddr = inet6_rcv_saddr(sk);
10338 +
10339 +       // *saddr = nsa->baddr;
10340 +       // inet->inet_saddr = nsa->baddr;
10341 +}
10342 +
10343 +static inline
10344 +int nx_info_has_v6(struct nx_info *nxi)
10345 +{
10346 +       if (!nxi)
10347 +               return 1;
10348 +       if (NX_IPV6(nxi))
10349 +               return 1;
10350 +       return 0;
10351 +}
10352 +
10353 +#else /* CONFIG_IPV6 */
10354 +
10355 +static inline
10356 +int nx_v6_dev_visible(struct nx_info *n, struct net_device *d)
10357 +{
10358 +       return 1;
10359 +}
10360 +
10361 +
10362 +static inline
10363 +int nx_v6_addr_conflict(struct nx_info *n, uint32_t a, const struct sock *s)
10364 +{
10365 +       return 1;
10366 +}
10367 +
10368 +static inline
10369 +int v6_ifa_in_nx_info(struct in_ifaddr *a, struct nx_info *n)
10370 +{
10371 +       return 1;
10372 +}
10373 +
10374 +static inline
10375 +int nx_info_has_v6(struct nx_info *nxi)
10376 +{
10377 +       return 0;
10378 +}
10379 +
10380 +#endif /* CONFIG_IPV6 */
10381 +
10382 +#define current_nx_info_has_v6() \
10383 +       nx_info_has_v6(current_nx_info())
10384 +
10385 +#else
10386 +#warning duplicate inclusion
10387 +#endif
10388 diff -NurpP --minimal linux-3.0.25/include/linux/vs_limit.h linux-3.0.25-vs2.3.2.3/include/linux/vs_limit.h
10389 --- linux-3.0.25/include/linux/vs_limit.h       1970-01-01 01:00:00.000000000 +0100
10390 +++ linux-3.0.25-vs2.3.2.3/include/linux/vs_limit.h     2011-06-10 22:11:24.000000000 +0200
10391 @@ -0,0 +1,140 @@
10392 +#ifndef _VS_LIMIT_H
10393 +#define _VS_LIMIT_H
10394 +
10395 +#include "vserver/limit.h"
10396 +#include "vserver/base.h"
10397 +#include "vserver/context.h"
10398 +#include "vserver/debug.h"
10399 +#include "vserver/context.h"
10400 +#include "vserver/limit_int.h"
10401 +
10402 +
10403 +#define vx_acc_cres(v, d, p, r) \
10404 +       __vx_acc_cres(v, r, d, p, __FILE__, __LINE__)
10405 +
10406 +#define vx_acc_cres_cond(x, d, p, r) \
10407 +       __vx_acc_cres(((x) == vx_current_xid()) ? current_vx_info() : 0, \
10408 +       r, d, p, __FILE__, __LINE__)
10409 +
10410 +
10411 +#define vx_add_cres(v, a, p, r) \
10412 +       __vx_add_cres(v, r, a, p, __FILE__, __LINE__)
10413 +#define vx_sub_cres(v, a, p, r)                vx_add_cres(v, -(a), p, r)
10414 +
10415 +#define vx_add_cres_cond(x, a, p, r) \
10416 +       __vx_add_cres(((x) == vx_current_xid()) ? current_vx_info() : 0, \
10417 +       r, a, p, __FILE__, __LINE__)
10418 +#define vx_sub_cres_cond(x, a, p, r)   vx_add_cres_cond(x, -(a), p, r)
10419 +
10420 +
10421 +/* process and file limits */
10422 +
10423 +#define vx_nproc_inc(p) \
10424 +       vx_acc_cres((p)->vx_info, 1, p, RLIMIT_NPROC)
10425 +
10426 +#define vx_nproc_dec(p) \
10427 +       vx_acc_cres((p)->vx_info,-1, p, RLIMIT_NPROC)
10428 +
10429 +#define vx_files_inc(f) \
10430 +       vx_acc_cres_cond((f)->f_xid, 1, f, RLIMIT_NOFILE)
10431 +
10432 +#define vx_files_dec(f) \
10433 +       vx_acc_cres_cond((f)->f_xid,-1, f, RLIMIT_NOFILE)
10434 +
10435 +#define vx_locks_inc(l) \
10436 +       vx_acc_cres_cond((l)->fl_xid, 1, l, RLIMIT_LOCKS)
10437 +
10438 +#define vx_locks_dec(l) \
10439 +       vx_acc_cres_cond((l)->fl_xid,-1, l, RLIMIT_LOCKS)
10440 +
10441 +#define vx_openfd_inc(f) \
10442 +       vx_acc_cres(current_vx_info(), 1, (void *)(long)(f), VLIMIT_OPENFD)
10443 +
10444 +#define vx_openfd_dec(f) \
10445 +       vx_acc_cres(current_vx_info(),-1, (void *)(long)(f), VLIMIT_OPENFD)
10446 +
10447 +
10448 +#define vx_cres_avail(v, n, r) \
10449 +       __vx_cres_avail(v, r, n, __FILE__, __LINE__)
10450 +
10451 +
10452 +#define vx_nproc_avail(n) \
10453 +       vx_cres_avail(current_vx_info(), n, RLIMIT_NPROC)
10454 +
10455 +#define vx_files_avail(n) \
10456 +       vx_cres_avail(current_vx_info(), n, RLIMIT_NOFILE)
10457 +
10458 +#define vx_locks_avail(n) \
10459 +       vx_cres_avail(current_vx_info(), n, RLIMIT_LOCKS)
10460 +
10461 +#define vx_openfd_avail(n) \
10462 +       vx_cres_avail(current_vx_info(), n, VLIMIT_OPENFD)
10463 +
10464 +
10465 +/* dentry limits */
10466 +
10467 +#define vx_dentry_inc(d) do {                                          \
10468 +       if ((d)->d_count == 1)                                          \
10469 +               vx_acc_cres(current_vx_info(), 1, d, VLIMIT_DENTRY);    \
10470 +       } while (0)
10471 +
10472 +#define vx_dentry_dec(d) do {                                          \
10473 +       if ((d)->d_count == 0)                                          \
10474 +               vx_acc_cres(current_vx_info(),-1, d, VLIMIT_DENTRY);    \
10475 +       } while (0)
10476 +
10477 +#define vx_dentry_avail(n) \
10478 +       vx_cres_avail(current_vx_info(), n, VLIMIT_DENTRY)
10479 +
10480 +
10481 +/* socket limits */
10482 +
10483 +#define vx_sock_inc(s) \
10484 +       vx_acc_cres((s)->sk_vx_info, 1, s, VLIMIT_NSOCK)
10485 +
10486 +#define vx_sock_dec(s) \
10487 +       vx_acc_cres((s)->sk_vx_info,-1, s, VLIMIT_NSOCK)
10488 +
10489 +#define vx_sock_avail(n) \
10490 +       vx_cres_avail(current_vx_info(), n, VLIMIT_NSOCK)
10491 +
10492 +
10493 +/* ipc resource limits */
10494 +
10495 +#define vx_ipcmsg_add(v, u, a) \
10496 +       vx_add_cres(v, a, u, RLIMIT_MSGQUEUE)
10497 +
10498 +#define vx_ipcmsg_sub(v, u, a) \
10499 +       vx_sub_cres(v, a, u, RLIMIT_MSGQUEUE)
10500 +
10501 +#define vx_ipcmsg_avail(v, a) \
10502 +       vx_cres_avail(v, a, RLIMIT_MSGQUEUE)
10503 +
10504 +
10505 +#define vx_ipcshm_add(v, k, a) \
10506 +       vx_add_cres(v, a, (void *)(long)(k), VLIMIT_SHMEM)
10507 +
10508 +#define vx_ipcshm_sub(v, k, a) \
10509 +       vx_sub_cres(v, a, (void *)(long)(k), VLIMIT_SHMEM)
10510 +
10511 +#define vx_ipcshm_avail(v, a) \
10512 +       vx_cres_avail(v, a, VLIMIT_SHMEM)
10513 +
10514 +
10515 +#define vx_semary_inc(a) \
10516 +       vx_acc_cres(current_vx_info(), 1, a, VLIMIT_SEMARY)
10517 +
10518 +#define vx_semary_dec(a) \
10519 +       vx_acc_cres(current_vx_info(), -1, a, VLIMIT_SEMARY)
10520 +
10521 +
10522 +#define vx_nsems_add(a,n) \
10523 +       vx_add_cres(current_vx_info(), n, a, VLIMIT_NSEMS)
10524 +
10525 +#define vx_nsems_sub(a,n) \
10526 +       vx_sub_cres(current_vx_info(), n, a, VLIMIT_NSEMS)
10527 +
10528 +
10529 +#else
10530 +#warning duplicate inclusion
10531 +#endif
10532 diff -NurpP --minimal linux-3.0.25/include/linux/vs_memory.h linux-3.0.25-vs2.3.2.3/include/linux/vs_memory.h
10533 --- linux-3.0.25/include/linux/vs_memory.h      1970-01-01 01:00:00.000000000 +0100
10534 +++ linux-3.0.25-vs2.3.2.3/include/linux/vs_memory.h    2011-06-10 22:11:24.000000000 +0200
10535 @@ -0,0 +1,58 @@
10536 +#ifndef _VS_MEMORY_H
10537 +#define _VS_MEMORY_H
10538 +
10539 +#include "vserver/limit.h"
10540 +#include "vserver/base.h"
10541 +#include "vserver/context.h"
10542 +#include "vserver/debug.h"
10543 +#include "vserver/context.h"
10544 +#include "vserver/limit_int.h"
10545 +
10546 +enum {
10547 +       VXPT_UNKNOWN = 0,
10548 +       VXPT_ANON,
10549 +       VXPT_NONE,
10550 +       VXPT_FILE,
10551 +       VXPT_SWAP,
10552 +       VXPT_WRITE
10553 +};
10554 +
10555 +#if 0
10556 +#define        vx_page_fault(mm, vma, type, ret)
10557 +#else
10558 +
10559 +static inline
10560 +void __vx_page_fault(struct mm_struct *mm,
10561 +       struct vm_area_struct *vma, int type, int ret)
10562 +{
10563 +       struct vx_info *vxi = mm->mm_vx_info;
10564 +       int what;
10565 +/*
10566 +       static char *page_type[6] =
10567 +               { "UNKNOWN", "ANON", "NONE", "FILE", "SWAP", "WRITE" };
10568 +       static char *page_what[4] =
10569 +               { "FAULT_OOM", "FAULT_SIGBUS", "FAULT_MINOR", "FAULT_MAJOR" };
10570 +*/
10571 +
10572 +       if (!vxi)
10573 +               return;
10574 +
10575 +       what = (ret & 0x3);
10576 +
10577 +/*     printk("[%d] page[%d][%d] %2x %s %s\n", vxi->vx_id,
10578 +               type, what, ret, page_type[type], page_what[what]);
10579 +*/
10580 +       if (ret & VM_FAULT_WRITE)
10581 +               what |= 0x4;
10582 +       atomic_inc(&vxi->cacct.page[type][what]);
10583 +}
10584 +
10585 +#define        vx_page_fault(mm, vma, type, ret)       __vx_page_fault(mm, vma, type, ret)
10586 +#endif
10587 +
10588 +
10589 +extern unsigned long vx_badness(struct task_struct *task, struct mm_struct *mm);
10590 +
10591 +#else
10592 +#warning duplicate inclusion
10593 +#endif
10594 diff -NurpP --minimal linux-3.0.25/include/linux/vs_network.h linux-3.0.25-vs2.3.2.3/include/linux/vs_network.h
10595 --- linux-3.0.25/include/linux/vs_network.h     1970-01-01 01:00:00.000000000 +0100
10596 +++ linux-3.0.25-vs2.3.2.3/include/linux/vs_network.h   2011-06-10 22:11:24.000000000 +0200
10597 @@ -0,0 +1,169 @@
10598 +#ifndef _NX_VS_NETWORK_H
10599 +#define _NX_VS_NETWORK_H
10600 +
10601 +#include "vserver/context.h"
10602 +#include "vserver/network.h"
10603 +#include "vserver/base.h"
10604 +#include "vserver/check.h"
10605 +#include "vserver/debug.h"
10606 +
10607 +#include <linux/sched.h>
10608 +
10609 +
10610 +#define get_nx_info(i) __get_nx_info(i, __FILE__, __LINE__)
10611 +
10612 +static inline struct nx_info *__get_nx_info(struct nx_info *nxi,
10613 +       const char *_file, int _line)
10614 +{
10615 +       if (!nxi)
10616 +               return NULL;
10617 +
10618 +       vxlprintk(VXD_CBIT(nid, 2), "get_nx_info(%p[#%d.%d])",
10619 +               nxi, nxi ? nxi->nx_id : 0,
10620 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
10621 +               _file, _line);
10622 +
10623 +       atomic_inc(&nxi->nx_usecnt);
10624 +       return nxi;
10625 +}
10626 +
10627 +
10628 +extern void free_nx_info(struct nx_info *);
10629 +
10630 +#define put_nx_info(i) __put_nx_info(i, __FILE__, __LINE__)
10631 +
10632 +static inline void __put_nx_info(struct nx_info *nxi, const char *_file, int _line)
10633 +{
10634 +       if (!nxi)
10635 +               return;
10636 +
10637 +       vxlprintk(VXD_CBIT(nid, 2), "put_nx_info(%p[#%d.%d])",
10638 +               nxi, nxi ? nxi->nx_id : 0,
10639 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
10640 +               _file, _line);
10641 +
10642 +       if (atomic_dec_and_test(&nxi->nx_usecnt))
10643 +               free_nx_info(nxi);
10644 +}
10645 +
10646 +
10647 +#define init_nx_info(p, i) __init_nx_info(p, i, __FILE__, __LINE__)
10648 +
10649 +static inline void __init_nx_info(struct nx_info **nxp, struct nx_info *nxi,
10650 +               const char *_file, int _line)
10651 +{
10652 +       if (nxi) {
10653 +               vxlprintk(VXD_CBIT(nid, 3),
10654 +                       "init_nx_info(%p[#%d.%d])",
10655 +                       nxi, nxi ? nxi->nx_id : 0,
10656 +                       nxi ? atomic_read(&nxi->nx_usecnt) : 0,
10657 +                       _file, _line);
10658 +
10659 +               atomic_inc(&nxi->nx_usecnt);
10660 +       }
10661 +       *nxp = nxi;
10662 +}
10663 +
10664 +
10665 +#define set_nx_info(p, i) __set_nx_info(p, i, __FILE__, __LINE__)
10666 +
10667 +static inline void __set_nx_info(struct nx_info **nxp, struct nx_info *nxi,
10668 +       const char *_file, int _line)
10669 +{
10670 +       struct nx_info *nxo;
10671 +
10672 +       if (!nxi)
10673 +               return;
10674 +
10675 +       vxlprintk(VXD_CBIT(nid, 3), "set_nx_info(%p[#%d.%d])",
10676 +               nxi, nxi ? nxi->nx_id : 0,
10677 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
10678 +               _file, _line);
10679 +
10680 +       atomic_inc(&nxi->nx_usecnt);
10681 +       nxo = xchg(nxp, nxi);
10682 +       BUG_ON(nxo);
10683 +}
10684 +
10685 +#define clr_nx_info(p) __clr_nx_info(p, __FILE__, __LINE__)
10686 +
10687 +static inline void __clr_nx_info(struct nx_info **nxp,
10688 +       const char *_file, int _line)
10689 +{
10690 +       struct nx_info *nxo;
10691 +
10692 +       nxo = xchg(nxp, NULL);
10693 +       if (!nxo)
10694 +               return;
10695 +
10696 +       vxlprintk(VXD_CBIT(nid, 3), "clr_nx_info(%p[#%d.%d])",
10697 +               nxo, nxo ? nxo->nx_id : 0,
10698 +               nxo ? atomic_read(&nxo->nx_usecnt) : 0,
10699 +               _file, _line);
10700 +
10701 +       if (atomic_dec_and_test(&nxo->nx_usecnt))
10702 +               free_nx_info(nxo);
10703 +}
10704 +
10705 +
10706 +#define claim_nx_info(v, p) __claim_nx_info(v, p, __FILE__, __LINE__)
10707 +
10708 +static inline void __claim_nx_info(struct nx_info *nxi,
10709 +       struct task_struct *task, const char *_file, int _line)
10710 +{
10711 +       vxlprintk(VXD_CBIT(nid, 3), "claim_nx_info(%p[#%d.%d.%d]) %p",
10712 +               nxi, nxi ? nxi->nx_id : 0,
10713 +               nxi?atomic_read(&nxi->nx_usecnt):0,
10714 +               nxi?atomic_read(&nxi->nx_tasks):0,
10715 +               task, _file, _line);
10716 +
10717 +       atomic_inc(&nxi->nx_tasks);
10718 +}
10719 +
10720 +
10721 +extern void unhash_nx_info(struct nx_info *);
10722 +
10723 +#define release_nx_info(v, p) __release_nx_info(v, p, __FILE__, __LINE__)
10724 +
10725 +static inline void __release_nx_info(struct nx_info *nxi,
10726 +       struct task_struct *task, const char *_file, int _line)
10727 +{
10728 +       vxlprintk(VXD_CBIT(nid, 3), "release_nx_info(%p[#%d.%d.%d]) %p",
10729 +               nxi, nxi ? nxi->nx_id : 0,
10730 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
10731 +               nxi ? atomic_read(&nxi->nx_tasks) : 0,
10732 +               task, _file, _line);
10733 +
10734 +       might_sleep();
10735 +
10736 +       if (atomic_dec_and_test(&nxi->nx_tasks))
10737 +               unhash_nx_info(nxi);
10738 +}
10739 +
10740 +
10741 +#define task_get_nx_info(i)    __task_get_nx_info(i, __FILE__, __LINE__)
10742 +
10743 +static __inline__ struct nx_info *__task_get_nx_info(struct task_struct *p,
10744 +       const char *_file, int _line)
10745 +{
10746 +       struct nx_info *nxi;
10747 +
10748 +       task_lock(p);
10749 +       vxlprintk(VXD_CBIT(nid, 5), "task_get_nx_info(%p)",
10750 +               p, _file, _line);
10751 +       nxi = __get_nx_info(p->nx_info, _file, _line);
10752 +       task_unlock(p);
10753 +       return nxi;
10754 +}
10755 +
10756 +
10757 +static inline void exit_nx_info(struct task_struct *p)
10758 +{
10759 +       if (p->nx_info)
10760 +               release_nx_info(p->nx_info, p);
10761 +}
10762 +
10763 +
10764 +#else
10765 +#warning duplicate inclusion
10766 +#endif
10767 diff -NurpP --minimal linux-3.0.25/include/linux/vs_pid.h linux-3.0.25-vs2.3.2.3/include/linux/vs_pid.h
10768 --- linux-3.0.25/include/linux/vs_pid.h 1970-01-01 01:00:00.000000000 +0100
10769 +++ linux-3.0.25-vs2.3.2.3/include/linux/vs_pid.h       2011-06-10 22:11:24.000000000 +0200
10770 @@ -0,0 +1,50 @@
10771 +#ifndef _VS_PID_H
10772 +#define _VS_PID_H
10773 +
10774 +#include "vserver/base.h"
10775 +#include "vserver/check.h"
10776 +#include "vserver/context.h"
10777 +#include "vserver/debug.h"
10778 +#include "vserver/pid.h"
10779 +#include <linux/pid_namespace.h>
10780 +
10781 +
10782 +#define VXF_FAKE_INIT  (VXF_INFO_INIT | VXF_STATE_INIT)
10783 +
10784 +static inline
10785 +int vx_proc_task_visible(struct task_struct *task)
10786 +{
10787 +       if ((task->pid == 1) &&
10788 +               !vx_flags(VXF_FAKE_INIT, VXF_FAKE_INIT))
10789 +               /* show a blend through init */
10790 +               goto visible;
10791 +       if (vx_check(vx_task_xid(task), VS_WATCH | VS_IDENT))
10792 +               goto visible;
10793 +       return 0;
10794 +visible:
10795 +       return 1;
10796 +}
10797 +
10798 +#define find_task_by_real_pid(pid) find_task_by_pid_ns(pid, &init_pid_ns)
10799 +
10800 +
10801 +static inline
10802 +struct task_struct *vx_get_proc_task(struct inode *inode, struct pid *pid)
10803 +{
10804 +       struct task_struct *task = get_pid_task(pid, PIDTYPE_PID);
10805 +
10806 +       if (task && !vx_proc_task_visible(task)) {
10807 +               vxdprintk(VXD_CBIT(misc, 6),
10808 +                       "dropping task (get) %p[#%u,%u] for %p[#%u,%u]",
10809 +                       task, task->xid, task->pid,
10810 +                       current, current->xid, current->pid);
10811 +               put_task_struct(task);
10812 +               task = NULL;
10813 +       }
10814 +       return task;
10815 +}
10816 +
10817 +
10818 +#else
10819 +#warning duplicate inclusion
10820 +#endif
10821 diff -NurpP --minimal linux-3.0.25/include/linux/vs_sched.h linux-3.0.25-vs2.3.2.3/include/linux/vs_sched.h
10822 --- linux-3.0.25/include/linux/vs_sched.h       1970-01-01 01:00:00.000000000 +0100
10823 +++ linux-3.0.25-vs2.3.2.3/include/linux/vs_sched.h     2011-06-10 22:11:24.000000000 +0200
10824 @@ -0,0 +1,40 @@
10825 +#ifndef _VS_SCHED_H
10826 +#define _VS_SCHED_H
10827 +
10828 +#include "vserver/base.h"
10829 +#include "vserver/context.h"
10830 +#include "vserver/sched.h"
10831 +
10832 +
10833 +#define MAX_PRIO_BIAS           20
10834 +#define MIN_PRIO_BIAS          -20
10835 +
10836 +static inline
10837 +int vx_adjust_prio(struct task_struct *p, int prio, int max_user)
10838 +{
10839 +       struct vx_info *vxi = p->vx_info;
10840 +
10841 +       if (vxi)
10842 +               prio += vx_cpu(vxi, sched_pc).prio_bias;
10843 +       return prio;
10844 +}
10845 +
10846 +static inline void vx_account_user(struct vx_info *vxi,
10847 +       cputime_t cputime, int nice)
10848 +{
10849 +       if (!vxi)
10850 +               return;
10851 +       vx_cpu(vxi, sched_pc).user_ticks += cputime;
10852 +}
10853 +
10854 +static inline void vx_account_system(struct vx_info *vxi,
10855 +       cputime_t cputime, int idle)
10856 +{
10857 +       if (!vxi)
10858 +               return;
10859 +       vx_cpu(vxi, sched_pc).sys_ticks += cputime;
10860 +}
10861 +
10862 +#else
10863 +#warning duplicate inclusion
10864 +#endif
10865 diff -NurpP --minimal linux-3.0.25/include/linux/vs_socket.h linux-3.0.25-vs2.3.2.3/include/linux/vs_socket.h
10866 --- linux-3.0.25/include/linux/vs_socket.h      1970-01-01 01:00:00.000000000 +0100
10867 +++ linux-3.0.25-vs2.3.2.3/include/linux/vs_socket.h    2011-06-10 22:11:24.000000000 +0200
10868 @@ -0,0 +1,67 @@
10869 +#ifndef _VS_SOCKET_H
10870 +#define _VS_SOCKET_H
10871 +
10872 +#include "vserver/debug.h"
10873 +#include "vserver/base.h"
10874 +#include "vserver/cacct.h"
10875 +#include "vserver/context.h"
10876 +#include "vserver/tag.h"
10877 +
10878 +
10879 +/* socket accounting */
10880 +
10881 +#include <linux/socket.h>
10882 +
10883 +static inline int vx_sock_type(int family)
10884 +{
10885 +       switch (family) {
10886 +       case PF_UNSPEC:
10887 +               return VXA_SOCK_UNSPEC;
10888 +       case PF_UNIX:
10889 +               return VXA_SOCK_UNIX;
10890 +       case PF_INET:
10891 +               return VXA_SOCK_INET;
10892 +       case PF_INET6:
10893 +               return VXA_SOCK_INET6;
10894 +       case PF_PACKET:
10895 +               return VXA_SOCK_PACKET;
10896 +       default:
10897 +               return VXA_SOCK_OTHER;
10898 +       }
10899 +}
10900 +
10901 +#define vx_acc_sock(v, f, p, s) \
10902 +       __vx_acc_sock(v, f, p, s, __FILE__, __LINE__)
10903 +
10904 +static inline void __vx_acc_sock(struct vx_info *vxi,
10905 +       int family, int pos, int size, char *file, int line)
10906 +{
10907 +       if (vxi) {
10908 +               int type = vx_sock_type(family);
10909 +
10910 +               atomic_long_inc(&vxi->cacct.sock[type][pos].count);
10911 +               atomic_long_add(size, &vxi->cacct.sock[type][pos].total);
10912 +       }
10913 +}
10914 +
10915 +#define vx_sock_recv(sk, s) \
10916 +       vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 0, s)
10917 +#define vx_sock_send(sk, s) \
10918 +       vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 1, s)
10919 +#define vx_sock_fail(sk, s) \
10920 +       vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 2, s)
10921 +
10922 +
10923 +#define sock_vx_init(s) do {           \
10924 +       (s)->sk_xid = 0;                \
10925 +       (s)->sk_vx_info = NULL;         \
10926 +       } while (0)
10927 +
10928 +#define sock_nx_init(s) do {           \
10929 +       (s)->sk_nid = 0;                \
10930 +       (s)->sk_nx_info = NULL;         \
10931 +       } while (0)
10932 +
10933 +#else
10934 +#warning duplicate inclusion
10935 +#endif
10936 diff -NurpP --minimal linux-3.0.25/include/linux/vs_tag.h linux-3.0.25-vs2.3.2.3/include/linux/vs_tag.h
10937 --- linux-3.0.25/include/linux/vs_tag.h 1970-01-01 01:00:00.000000000 +0100
10938 +++ linux-3.0.25-vs2.3.2.3/include/linux/vs_tag.h       2011-06-10 22:11:24.000000000 +0200
10939 @@ -0,0 +1,47 @@
10940 +#ifndef _VS_TAG_H
10941 +#define _VS_TAG_H
10942 +
10943 +#include <linux/vserver/tag.h>
10944 +
10945 +/* check conditions */
10946 +
10947 +#define DX_ADMIN       0x0001
10948 +#define DX_WATCH       0x0002
10949 +#define DX_HOSTID      0x0008
10950 +
10951 +#define DX_IDENT       0x0010
10952 +
10953 +#define DX_ARG_MASK    0x0010
10954 +
10955 +
10956 +#define dx_task_tag(t) ((t)->tag)
10957 +
10958 +#define dx_current_tag() dx_task_tag(current)
10959 +
10960 +#define dx_check(c, m) __dx_check(dx_current_tag(), c, m)
10961 +
10962 +#define dx_weak_check(c, m)    ((m) ? dx_check(c, m) : 1)
10963 +
10964 +
10965 +/*
10966 + * check current context for ADMIN/WATCH and
10967 + * optionally against supplied argument
10968 + */
10969 +static inline int __dx_check(tag_t cid, tag_t id, unsigned int mode)
10970 +{
10971 +       if (mode & DX_ARG_MASK) {
10972 +               if ((mode & DX_IDENT) && (id == cid))
10973 +                       return 1;
10974 +       }
10975 +       return (((mode & DX_ADMIN) && (cid == 0)) ||
10976 +               ((mode & DX_WATCH) && (cid == 1)) ||
10977 +               ((mode & DX_HOSTID) && (id == 0)));
10978 +}
10979 +
10980 +struct inode;
10981 +int dx_permission(const struct inode *inode, int mask);
10982 +
10983 +
10984 +#else
10985 +#warning duplicate inclusion
10986 +#endif
10987 diff -NurpP --minimal linux-3.0.25/include/linux/vs_time.h linux-3.0.25-vs2.3.2.3/include/linux/vs_time.h
10988 --- linux-3.0.25/include/linux/vs_time.h        1970-01-01 01:00:00.000000000 +0100
10989 +++ linux-3.0.25-vs2.3.2.3/include/linux/vs_time.h      2011-06-13 14:57:45.000000000 +0200
10990 @@ -0,0 +1,19 @@
10991 +#ifndef _VS_TIME_H
10992 +#define _VS_TIME_H
10993 +
10994 +
10995 +/* time faking stuff */
10996 +
10997 +#ifdef CONFIG_VSERVER_VTIME
10998 +
10999 +extern void vx_adjust_timespec(struct timespec *ts);
11000 +extern int vx_settimeofday(const struct timespec *ts);
11001 +
11002 +#else
11003 +#define        vx_adjust_timespec(t)   do { } while (0)
11004 +#define        vx_settimeofday(t)      do_settimeofday(t)
11005 +#endif
11006 +
11007 +#else
11008 +#warning duplicate inclusion
11009 +#endif
11010 diff -NurpP --minimal linux-3.0.25/include/linux/vserver/Kbuild linux-3.0.25-vs2.3.2.3/include/linux/vserver/Kbuild
11011 --- linux-3.0.25/include/linux/vserver/Kbuild   1970-01-01 01:00:00.000000000 +0100
11012 +++ linux-3.0.25-vs2.3.2.3/include/linux/vserver/Kbuild 2011-08-08 18:02:46.000000000 +0200
11013 @@ -0,0 +1,8 @@
11014 +
11015 +header-y += context_cmd.h network_cmd.h space_cmd.h \
11016 +       cacct_cmd.h cvirt_cmd.h limit_cmd.h dlimit_cmd.h \
11017 +       inode_cmd.h tag_cmd.h sched_cmd.h signal_cmd.h \
11018 +       debug_cmd.h device_cmd.h
11019 +
11020 +header-y += switch.h network.h monitor.h inode.h device.h
11021 +
11022 diff -NurpP --minimal linux-3.0.25/include/linux/vserver/base.h linux-3.0.25-vs2.3.2.3/include/linux/vserver/base.h
11023 --- linux-3.0.25/include/linux/vserver/base.h   1970-01-01 01:00:00.000000000 +0100
11024 +++ linux-3.0.25-vs2.3.2.3/include/linux/vserver/base.h 2011-08-01 18:26:07.000000000 +0200
11025 @@ -0,0 +1,178 @@
11026 +#ifndef _VX_BASE_H
11027 +#define _VX_BASE_H
11028 +
11029 +
11030 +/* context state changes */
11031 +
11032 +enum {
11033 +       VSC_STARTUP = 1,
11034 +       VSC_SHUTDOWN,
11035 +
11036 +       VSC_NETUP,
11037 +       VSC_NETDOWN,
11038 +};
11039 +
11040 +
11041 +
11042 +#define vx_task_xid(t) ((t)->xid)
11043 +
11044 +#define vx_current_xid() vx_task_xid(current)
11045 +
11046 +#define current_vx_info() (current->vx_info)
11047 +
11048 +
11049 +#define nx_task_nid(t) ((t)->nid)
11050 +
11051 +#define nx_current_nid() nx_task_nid(current)
11052 +
11053 +#define current_nx_info() (current->nx_info)
11054 +
11055 +
11056 +/* generic flag merging */
11057 +
11058 +#define vs_check_flags(v, m, f)        (((v) & (m)) ^ (f))
11059 +
11060 +#define vs_mask_flags(v, f, m) (((v) & ~(m)) | ((f) & (m)))
11061 +
11062 +#define vs_mask_mask(v, f, m)  (((v) & ~(m)) | ((v) & (f) & (m)))
11063 +
11064 +#define vs_check_bit(v, n)     ((v) & (1LL << (n)))
11065 +
11066 +
11067 +/* context flags */
11068 +
11069 +#define __vx_flags(v)  ((v) ? (v)->vx_flags : 0)
11070 +
11071 +#define vx_current_flags()     __vx_flags(current_vx_info())
11072 +
11073 +#define vx_info_flags(v, m, f) \
11074 +       vs_check_flags(__vx_flags(v), m, f)
11075 +
11076 +#define task_vx_flags(t, m, f) \
11077 +       ((t) && vx_info_flags((t)->vx_info, m, f))
11078 +
11079 +#define vx_flags(m, f) vx_info_flags(current_vx_info(), m, f)
11080 +
11081 +
11082 +/* context caps */
11083 +
11084 +#define __vx_ccaps(v)  ((v) ? (v)->vx_ccaps : 0)
11085 +
11086 +#define vx_current_ccaps()     __vx_ccaps(current_vx_info())
11087 +
11088 +#define vx_info_ccaps(v, c)    (__vx_ccaps(v) & (c))
11089 +
11090 +#define vx_ccaps(c)    vx_info_ccaps(current_vx_info(), (c))
11091 +
11092 +
11093 +
11094 +/* network flags */
11095 +
11096 +#define __nx_flags(n)  ((n) ? (n)->nx_flags : 0)
11097 +
11098 +#define nx_current_flags()     __nx_flags(current_nx_info())
11099 +
11100 +#define nx_info_flags(n, m, f) \
11101 +       vs_check_flags(__nx_flags(n), m, f)
11102 +
11103 +#define task_nx_flags(t, m, f) \
11104 +       ((t) && nx_info_flags((t)->nx_info, m, f))
11105 +
11106 +#define nx_flags(m, f) nx_info_flags(current_nx_info(), m, f)
11107 +
11108 +
11109 +/* network caps */
11110 +
11111 +#define __nx_ncaps(n)  ((n) ? (n)->nx_ncaps : 0)
11112 +
11113 +#define nx_current_ncaps()     __nx_ncaps(current_nx_info())
11114 +
11115 +#define nx_info_ncaps(n, c)    (__nx_ncaps(n) & (c))
11116 +
11117 +#define nx_ncaps(c)    nx_info_ncaps(current_nx_info(), c)
11118 +
11119 +
11120 +/* context mask capabilities */
11121 +
11122 +#define __vx_mcaps(v)  ((v) ? (v)->vx_ccaps >> 32UL : ~0 )
11123 +
11124 +#define vx_info_mcaps(v, c)    (__vx_mcaps(v) & (c))
11125 +
11126 +#define vx_mcaps(c)    vx_info_mcaps(current_vx_info(), c)
11127 +
11128 +
11129 +/* context bcap mask */
11130 +
11131 +#define __vx_bcaps(v)          ((v)->vx_bcaps)
11132 +
11133 +#define vx_current_bcaps()     __vx_bcaps(current_vx_info())
11134 +
11135 +
11136 +/* mask given bcaps */
11137 +
11138 +#define vx_info_mbcaps(v, c)   ((v) ? cap_intersect(__vx_bcaps(v), c) : c)
11139 +
11140 +#define vx_mbcaps(c)           vx_info_mbcaps(current_vx_info(), c)
11141 +
11142 +
11143 +/* masked cap_bset */
11144 +
11145 +#define vx_info_cap_bset(v)    vx_info_mbcaps(v, current->cap_bset)
11146 +
11147 +#define vx_current_cap_bset()  vx_info_cap_bset(current_vx_info())
11148 +
11149 +#if 0
11150 +#define vx_info_mbcap(v, b) \
11151 +       (!vx_info_flags(v, VXF_STATE_SETUP, 0) ? \
11152 +       vx_info_bcaps(v, b) : (b))
11153 +
11154 +#define task_vx_mbcap(t, b) \
11155 +       vx_info_mbcap((t)->vx_info, (t)->b)
11156 +
11157 +#define vx_mbcap(b)    task_vx_mbcap(current, b)
11158 +#endif
11159 +
11160 +#define vx_cap_raised(v, c, f) cap_raised(vx_info_mbcaps(v, c), f)
11161 +
11162 +#define vx_capable(b, c) (capable(b) || \
11163 +       (cap_raised(current_cap(), b) && vx_ccaps(c)))
11164 +
11165 +#define vx_ns_capable(n, b, c) (ns_capable(n, b) || \
11166 +       (cap_raised(current_cap(), b) && vx_ccaps(c)))
11167 +
11168 +#define nx_capable(b, c) (capable(b) || \
11169 +       (cap_raised(current_cap(), b) && nx_ncaps(c)))
11170 +
11171 +#define vx_task_initpid(t, n) \
11172 +       ((t)->vx_info && \
11173 +       ((t)->vx_info->vx_initpid == (n)))
11174 +
11175 +#define vx_current_initpid(n)  vx_task_initpid(current, n)
11176 +
11177 +
11178 +/* context unshare mask */
11179 +
11180 +#define __vx_umask(v)          ((v)->vx_umask)
11181 +
11182 +#define vx_current_umask()     __vx_umask(current_vx_info())
11183 +
11184 +#define vx_can_unshare(b, f) (capable(b) || \
11185 +       (cap_raised(current_cap(), b) && \
11186 +       !((f) & ~vx_current_umask())))
11187 +
11188 +
11189 +#define __vx_wmask(v)          ((v)->vx_wmask)
11190 +
11191 +#define vx_current_wmask()     __vx_wmask(current_vx_info())
11192 +
11193 +
11194 +#define __vx_state(v)  ((v) ? ((v)->vx_state) : 0)
11195 +
11196 +#define vx_info_state(v, m)    (__vx_state(v) & (m))
11197 +
11198 +
11199 +#define __nx_state(n)  ((n) ? ((n)->nx_state) : 0)
11200 +
11201 +#define nx_info_state(n, m)    (__nx_state(n) & (m))
11202 +
11203 +#endif
11204 diff -NurpP --minimal linux-3.0.25/include/linux/vserver/cacct.h linux-3.0.25-vs2.3.2.3/include/linux/vserver/cacct.h
11205 --- linux-3.0.25/include/linux/vserver/cacct.h  1970-01-01 01:00:00.000000000 +0100
11206 +++ linux-3.0.25-vs2.3.2.3/include/linux/vserver/cacct.h        2011-06-10 22:11:24.000000000 +0200
11207 @@ -0,0 +1,15 @@
11208 +#ifndef _VX_CACCT_H
11209 +#define _VX_CACCT_H
11210 +
11211 +
11212 +enum sock_acc_field {
11213 +       VXA_SOCK_UNSPEC = 0,
11214 +       VXA_SOCK_UNIX,
11215 +       VXA_SOCK_INET,
11216 +       VXA_SOCK_INET6,
11217 +       VXA_SOCK_PACKET,
11218 +       VXA_SOCK_OTHER,
11219 +       VXA_SOCK_SIZE   /* array size */
11220 +};
11221 +
11222 +#endif /* _VX_CACCT_H */
11223 diff -NurpP --minimal linux-3.0.25/include/linux/vserver/cacct_cmd.h linux-3.0.25-vs2.3.2.3/include/linux/vserver/cacct_cmd.h
11224 --- linux-3.0.25/include/linux/vserver/cacct_cmd.h      1970-01-01 01:00:00.000000000 +0100
11225 +++ linux-3.0.25-vs2.3.2.3/include/linux/vserver/cacct_cmd.h    2011-06-10 22:11:24.000000000 +0200
11226 @@ -0,0 +1,23 @@
11227 +#ifndef _VX_CACCT_CMD_H
11228 +#define _VX_CACCT_CMD_H
11229 +
11230 +
11231 +/* virtual host info name commands */
11232 +
11233 +#define VCMD_sock_stat         VC_CMD(VSTAT, 5, 0)
11234 +
11235 +struct vcmd_sock_stat_v0 {
11236 +       uint32_t field;
11237 +       uint32_t count[3];
11238 +       uint64_t total[3];
11239 +};
11240 +
11241 +
11242 +#ifdef __KERNEL__
11243 +
11244 +#include <linux/compiler.h>
11245 +
11246 +extern int vc_sock_stat(struct vx_info *, void __user *);
11247 +
11248 +#endif /* __KERNEL__ */
11249 +#endif /* _VX_CACCT_CMD_H */
11250 diff -NurpP --minimal linux-3.0.25/include/linux/vserver/cacct_def.h linux-3.0.25-vs2.3.2.3/include/linux/vserver/cacct_def.h
11251 --- linux-3.0.25/include/linux/vserver/cacct_def.h      1970-01-01 01:00:00.000000000 +0100
11252 +++ linux-3.0.25-vs2.3.2.3/include/linux/vserver/cacct_def.h    2011-06-10 22:11:24.000000000 +0200
11253 @@ -0,0 +1,43 @@
11254 +#ifndef _VX_CACCT_DEF_H
11255 +#define _VX_CACCT_DEF_H
11256 +
11257 +#include <asm/atomic.h>
11258 +#include <linux/vserver/cacct.h>
11259 +
11260 +
11261 +struct _vx_sock_acc {
11262 +       atomic_long_t count;
11263 +       atomic_long_t total;
11264 +};
11265 +
11266 +/* context sub struct */
11267 +
11268 +struct _vx_cacct {
11269 +       struct _vx_sock_acc sock[VXA_SOCK_SIZE][3];
11270 +       atomic_t slab[8];
11271 +       atomic_t page[6][8];
11272 +};
11273 +
11274 +#ifdef CONFIG_VSERVER_DEBUG
11275 +
11276 +static inline void __dump_vx_cacct(struct _vx_cacct *cacct)
11277 +{
11278 +       int i, j;
11279 +
11280 +       printk("\t_vx_cacct:");
11281 +       for (i = 0; i < 6; i++) {
11282 +               struct _vx_sock_acc *ptr = cacct->sock[i];
11283 +
11284 +               printk("\t [%d] =", i);
11285 +               for (j = 0; j < 3; j++) {
11286 +                       printk(" [%d] = %8lu, %8lu", j,
11287 +                               atomic_long_read(&ptr[j].count),
11288 +                               atomic_long_read(&ptr[j].total));
11289 +               }
11290 +               printk("\n");
11291 +       }
11292 +}
11293 +
11294 +#endif
11295 +
11296 +#endif /* _VX_CACCT_DEF_H */
11297 diff -NurpP --minimal linux-3.0.25/include/linux/vserver/cacct_int.h linux-3.0.25-vs2.3.2.3/include/linux/vserver/cacct_int.h
11298 --- linux-3.0.25/include/linux/vserver/cacct_int.h      1970-01-01 01:00:00.000000000 +0100
11299 +++ linux-3.0.25-vs2.3.2.3/include/linux/vserver/cacct_int.h    2011-06-10 22:11:24.000000000 +0200
11300 @@ -0,0 +1,21 @@
11301 +#ifndef _VX_CACCT_INT_H
11302 +#define _VX_CACCT_INT_H
11303 +
11304 +
11305 +#ifdef __KERNEL__
11306 +
11307 +static inline
11308 +unsigned long vx_sock_count(struct _vx_cacct *cacct, int type, int pos)
11309 +{
11310 +       return atomic_long_read(&cacct->sock[type][pos].count);
11311 +}
11312 +
11313 +
11314 +static inline
11315 +unsigned long vx_sock_total(struct _vx_cacct *cacct, int type, int pos)
11316 +{
11317 +       return atomic_long_read(&cacct->sock[type][pos].total);
11318 +}
11319 +
11320 +#endif /* __KERNEL__ */
11321 +#endif /* _VX_CACCT_INT_H */
11322 diff -NurpP --minimal linux-3.0.25/include/linux/vserver/check.h linux-3.0.25-vs2.3.2.3/include/linux/vserver/check.h
11323 --- linux-3.0.25/include/linux/vserver/check.h  1970-01-01 01:00:00.000000000 +0100
11324 +++ linux-3.0.25-vs2.3.2.3/include/linux/vserver/check.h        2011-06-10 22:11:24.000000000 +0200
11325 @@ -0,0 +1,89 @@
11326 +#ifndef _VS_CHECK_H
11327 +#define _VS_CHECK_H
11328 +
11329 +
11330 +#define MAX_S_CONTEXT  65535   /* Arbitrary limit */
11331 +
11332 +#ifdef CONFIG_VSERVER_DYNAMIC_IDS
11333 +#define MIN_D_CONTEXT  49152   /* dynamic contexts start here */
11334 +#else
11335 +#define MIN_D_CONTEXT  65536
11336 +#endif
11337 +
11338 +/* check conditions */
11339 +
11340 +#define VS_ADMIN       0x0001
11341 +#define VS_WATCH       0x0002
11342 +#define VS_HIDE                0x0004
11343 +#define VS_HOSTID      0x0008
11344 +
11345 +#define VS_IDENT       0x0010
11346 +#define VS_EQUIV       0x0020
11347 +#define VS_PARENT      0x0040
11348 +#define VS_CHILD       0x0080
11349 +
11350 +#define VS_ARG_MASK    0x00F0
11351 +
11352 +#define VS_DYNAMIC     0x0100
11353 +#define VS_STATIC      0x0200
11354 +
11355 +#define VS_ATR_MASK    0x0F00
11356 +
11357 +#ifdef CONFIG_VSERVER_PRIVACY
11358 +#define VS_ADMIN_P     (0)
11359 +#define VS_WATCH_P     (0)
11360 +#else
11361 +#define VS_ADMIN_P     VS_ADMIN
11362 +#define VS_WATCH_P     VS_WATCH
11363 +#endif
11364 +
11365 +#define VS_HARDIRQ     0x1000
11366 +#define VS_SOFTIRQ     0x2000
11367 +#define VS_IRQ         0x4000
11368 +
11369 +#define VS_IRQ_MASK    0xF000
11370 +
11371 +#include <linux/hardirq.h>
11372 +
11373 +/*
11374 + * check current context for ADMIN/WATCH and
11375 + * optionally against supplied argument
11376 + */
11377 +static inline int __vs_check(int cid, int id, unsigned int mode)
11378 +{
11379 +       if (mode & VS_ARG_MASK) {
11380 +               if ((mode & VS_IDENT) && (id == cid))
11381 +                       return 1;
11382 +       }
11383 +       if (mode & VS_ATR_MASK) {
11384 +               if ((mode & VS_DYNAMIC) &&
11385 +                       (id >= MIN_D_CONTEXT) &&
11386 +                       (id <= MAX_S_CONTEXT))
11387 +                       return 1;
11388 +               if ((mode & VS_STATIC) &&
11389 +                       (id > 1) && (id < MIN_D_CONTEXT))
11390 +                       return 1;
11391 +       }
11392 +       if (mode & VS_IRQ_MASK) {
11393 +               if ((mode & VS_IRQ) && unlikely(in_interrupt()))
11394 +                       return 1;
11395 +               if ((mode & VS_HARDIRQ) && unlikely(in_irq()))
11396 +                       return 1;
11397 +               if ((mode & VS_SOFTIRQ) && unlikely(in_softirq()))
11398 +                       return 1;
11399 +       }
11400 +       return (((mode & VS_ADMIN) && (cid == 0)) ||
11401 +               ((mode & VS_WATCH) && (cid == 1)) ||
11402 +               ((mode & VS_HOSTID) && (id == 0)));
11403 +}
11404 +
11405 +#define vx_check(c, m) __vs_check(vx_current_xid(), c, (m) | VS_IRQ)
11406 +
11407 +#define vx_weak_check(c, m)    ((m) ? vx_check(c, m) : 1)
11408 +
11409 +
11410 +#define nx_check(c, m) __vs_check(nx_current_nid(), c, m)
11411 +
11412 +#define nx_weak_check(c, m)    ((m) ? nx_check(c, m) : 1)
11413 +
11414 +#endif
11415 diff -NurpP --minimal linux-3.0.25/include/linux/vserver/context.h linux-3.0.25-vs2.3.2.3/include/linux/vserver/context.h
11416 --- linux-3.0.25/include/linux/vserver/context.h        1970-01-01 01:00:00.000000000 +0100
11417 +++ linux-3.0.25-vs2.3.2.3/include/linux/vserver/context.h      2011-10-27 13:59:29.000000000 +0200
11418 @@ -0,0 +1,188 @@
11419 +#ifndef _VX_CONTEXT_H
11420 +#define _VX_CONTEXT_H
11421 +
11422 +#include <linux/types.h>
11423 +#include <linux/capability.h>
11424 +
11425 +
11426 +/* context flags */
11427 +
11428 +#define VXF_INFO_SCHED         0x00000002
11429 +#define VXF_INFO_NPROC         0x00000004
11430 +#define VXF_INFO_PRIVATE       0x00000008
11431 +
11432 +#define VXF_INFO_INIT          0x00000010
11433 +#define VXF_INFO_HIDE          0x00000020
11434 +#define VXF_INFO_ULIMIT                0x00000040
11435 +#define VXF_INFO_NSPACE                0x00000080
11436 +
11437 +#define VXF_SCHED_HARD         0x00000100
11438 +#define VXF_SCHED_PRIO         0x00000200
11439 +#define VXF_SCHED_PAUSE                0x00000400
11440 +
11441 +#define VXF_VIRT_MEM           0x00010000
11442 +#define VXF_VIRT_UPTIME                0x00020000
11443 +#define VXF_VIRT_CPU           0x00040000
11444 +#define VXF_VIRT_LOAD          0x00080000
11445 +#define VXF_VIRT_TIME          0x00100000
11446 +
11447 +#define VXF_HIDE_MOUNT         0x01000000
11448 +/* was VXF_HIDE_NETIF          0x02000000 */
11449 +#define VXF_HIDE_VINFO         0x04000000
11450 +
11451 +#define VXF_STATE_SETUP                (1ULL << 32)
11452 +#define VXF_STATE_INIT         (1ULL << 33)
11453 +#define VXF_STATE_ADMIN                (1ULL << 34)
11454 +
11455 +#define VXF_SC_HELPER          (1ULL << 36)
11456 +#define VXF_REBOOT_KILL                (1ULL << 37)
11457 +#define VXF_PERSISTENT         (1ULL << 38)
11458 +
11459 +#define VXF_FORK_RSS           (1ULL << 48)
11460 +#define VXF_PROLIFIC           (1ULL << 49)
11461 +
11462 +#define VXF_IGNEG_NICE         (1ULL << 52)
11463 +
11464 +#define VXF_ONE_TIME           (0x0007ULL << 32)
11465 +
11466 +#define VXF_INIT_SET           (VXF_STATE_SETUP | VXF_STATE_INIT | VXF_STATE_ADMIN)
11467 +
11468 +
11469 +/* context migration */
11470 +
11471 +#define VXM_SET_INIT           0x00000001
11472 +#define VXM_SET_REAPER         0x00000002
11473 +
11474 +/* context caps */
11475 +
11476 +#define VXC_SET_UTSNAME                0x00000001
11477 +#define VXC_SET_RLIMIT         0x00000002
11478 +#define VXC_FS_SECURITY                0x00000004
11479 +#define VXC_FS_TRUSTED         0x00000008
11480 +#define VXC_TIOCSTI            0x00000010
11481 +
11482 +/* was VXC_RAW_ICMP            0x00000100 */
11483 +#define VXC_SYSLOG             0x00001000
11484 +#define VXC_OOM_ADJUST         0x00002000
11485 +#define VXC_AUDIT_CONTROL      0x00004000
11486 +
11487 +#define VXC_SECURE_MOUNT       0x00010000
11488 +#define VXC_SECURE_REMOUNT     0x00020000
11489 +#define VXC_BINARY_MOUNT       0x00040000
11490 +
11491 +#define VXC_QUOTA_CTL          0x00100000
11492 +#define VXC_ADMIN_MAPPER       0x00200000
11493 +#define VXC_ADMIN_CLOOP                0x00400000
11494 +
11495 +#define VXC_KTHREAD            0x01000000
11496 +#define VXC_NAMESPACE          0x02000000
11497 +
11498 +
11499 +#ifdef __KERNEL__
11500 +
11501 +#include <linux/list.h>
11502 +#include <linux/spinlock.h>
11503 +#include <linux/rcupdate.h>
11504 +
11505 +#include "limit_def.h"
11506 +#include "sched_def.h"
11507 +#include "cvirt_def.h"
11508 +#include "cacct_def.h"
11509 +#include "device_def.h"
11510 +
11511 +#define VX_SPACES      2
11512 +
11513 +struct _vx_info_pc {
11514 +       struct _vx_sched_pc sched_pc;
11515 +       struct _vx_cvirt_pc cvirt_pc;
11516 +};
11517 +
11518 +struct _vx_space {
11519 +       unsigned long vx_nsmask;                /* assignment mask */
11520 +       struct nsproxy *vx_nsproxy;             /* private namespaces */
11521 +       struct fs_struct *vx_fs;                /* private namespace fs */
11522 +       const struct cred *vx_cred;             /* task credentials */
11523 +};
11524 +
11525 +struct vx_info {
11526 +       struct hlist_node vx_hlist;             /* linked list of contexts */
11527 +       xid_t vx_id;                            /* context id */
11528 +       atomic_t vx_usecnt;                     /* usage count */
11529 +       atomic_t vx_tasks;                      /* tasks count */
11530 +       struct vx_info *vx_parent;              /* parent context */
11531 +       int vx_state;                           /* context state */
11532 +
11533 +       struct _vx_space space[VX_SPACES];      /* namespace store */
11534 +
11535 +       uint64_t vx_flags;                      /* context flags */
11536 +       uint64_t vx_ccaps;                      /* context caps (vserver) */
11537 +       uint64_t vx_umask;                      /* unshare mask (guest) */
11538 +       uint64_t vx_wmask;                      /* warn mask (guest) */
11539 +       kernel_cap_t vx_bcaps;                  /* bounding caps (system) */
11540 +
11541 +       struct task_struct *vx_reaper;          /* guest reaper process */
11542 +       pid_t vx_initpid;                       /* PID of guest init */
11543 +       int64_t vx_badness_bias;                /* OOM points bias */
11544 +
11545 +       struct _vx_limit limit;                 /* vserver limits */
11546 +       struct _vx_sched sched;                 /* vserver scheduler */
11547 +       struct _vx_cvirt cvirt;                 /* virtual/bias stuff */
11548 +       struct _vx_cacct cacct;                 /* context accounting */
11549 +
11550 +       struct _vx_device dmap;                 /* default device map targets */
11551 +
11552 +#ifndef CONFIG_SMP
11553 +       struct _vx_info_pc info_pc;             /* per cpu data */
11554 +#else
11555 +       struct _vx_info_pc *ptr_pc;             /* per cpu array */
11556 +#endif
11557 +
11558 +       wait_queue_head_t vx_wait;              /* context exit waitqueue */
11559 +       int reboot_cmd;                         /* last sys_reboot() cmd */
11560 +       int exit_code;                          /* last process exit code */
11561 +
11562 +       char vx_name[65];                       /* vserver name */
11563 +};
11564 +
11565 +#ifndef CONFIG_SMP
11566 +#define        vx_ptr_pc(vxi)          (&(vxi)->info_pc)
11567 +#define        vx_per_cpu(vxi, v, id)  vx_ptr_pc(vxi)->v
11568 +#else
11569 +#define        vx_ptr_pc(vxi)          ((vxi)->ptr_pc)
11570 +#define        vx_per_cpu(vxi, v, id)  per_cpu_ptr(vx_ptr_pc(vxi), id)->v
11571 +#endif
11572 +
11573 +#define        vx_cpu(vxi, v)          vx_per_cpu(vxi, v, smp_processor_id())
11574 +
11575 +
11576 +struct vx_info_save {
11577 +       struct vx_info *vxi;
11578 +       xid_t xid;
11579 +};
11580 +
11581 +
11582 +/* status flags */
11583 +
11584 +#define VXS_HASHED     0x0001
11585 +#define VXS_PAUSED     0x0010
11586 +#define VXS_SHUTDOWN   0x0100
11587 +#define VXS_HELPER     0x1000
11588 +#define VXS_RELEASED   0x8000
11589 +
11590 +
11591 +extern void claim_vx_info(struct vx_info *, struct task_struct *);
11592 +extern void release_vx_info(struct vx_info *, struct task_struct *);
11593 +
11594 +extern struct vx_info *lookup_vx_info(int);
11595 +extern struct vx_info *lookup_or_create_vx_info(int);
11596 +
11597 +extern int get_xid_list(int, unsigned int *, int);
11598 +extern int xid_is_hashed(xid_t);
11599 +
11600 +extern int vx_migrate_task(struct task_struct *, struct vx_info *, int);
11601 +
11602 +extern long vs_state_change(struct vx_info *, unsigned int);
11603 +
11604 +
11605 +#endif /* __KERNEL__ */
11606 +#endif /* _VX_CONTEXT_H */
11607 diff -NurpP --minimal linux-3.0.25/include/linux/vserver/context_cmd.h linux-3.0.25-vs2.3.2.3/include/linux/vserver/context_cmd.h
11608 --- linux-3.0.25/include/linux/vserver/context_cmd.h    1970-01-01 01:00:00.000000000 +0100
11609 +++ linux-3.0.25-vs2.3.2.3/include/linux/vserver/context_cmd.h  2011-08-01 18:25:07.000000000 +0200
11610 @@ -0,0 +1,162 @@
11611 +#ifndef _VX_CONTEXT_CMD_H
11612 +#define _VX_CONTEXT_CMD_H
11613 +
11614 +
11615 +/* vinfo commands */
11616 +
11617 +#define VCMD_task_xid          VC_CMD(VINFO, 1, 0)
11618 +
11619 +#ifdef __KERNEL__
11620 +extern int vc_task_xid(uint32_t);
11621 +
11622 +#endif /* __KERNEL__ */
11623 +
11624 +#define VCMD_vx_info           VC_CMD(VINFO, 5, 0)
11625 +
11626 +struct vcmd_vx_info_v0 {
11627 +       uint32_t xid;
11628 +       uint32_t initpid;
11629 +       /* more to come */
11630 +};
11631 +
11632 +#ifdef __KERNEL__
11633 +extern int vc_vx_info(struct vx_info *, void __user *);
11634 +
11635 +#endif /* __KERNEL__ */
11636 +
11637 +#define VCMD_ctx_stat          VC_CMD(VSTAT, 0, 0)
11638 +
11639 +struct vcmd_ctx_stat_v0 {
11640 +       uint32_t usecnt;
11641 +       uint32_t tasks;
11642 +       /* more to come */
11643 +};
11644 +
11645 +#ifdef __KERNEL__
11646 +extern int vc_ctx_stat(struct vx_info *, void __user *);
11647 +
11648 +#endif /* __KERNEL__ */
11649 +
11650 +/* context commands */
11651 +
11652 +#define VCMD_ctx_create_v0     VC_CMD(VPROC, 1, 0)
11653 +#define VCMD_ctx_create                VC_CMD(VPROC, 1, 1)
11654 +
11655 +struct vcmd_ctx_create {
11656 +       uint64_t flagword;
11657 +};
11658 +
11659 +#define VCMD_ctx_migrate_v0    VC_CMD(PROCMIG, 1, 0)
11660 +#define VCMD_ctx_migrate       VC_CMD(PROCMIG, 1, 1)
11661 +
11662 +struct vcmd_ctx_migrate {
11663 +       uint64_t flagword;
11664 +};
11665 +
11666 +#ifdef __KERNEL__
11667 +extern int vc_ctx_create(uint32_t, void __user *);
11668 +extern int vc_ctx_migrate(struct vx_info *, void __user *);
11669 +
11670 +#endif /* __KERNEL__ */
11671 +
11672 +
11673 +/* flag commands */
11674 +
11675 +#define VCMD_get_cflags                VC_CMD(FLAGS, 1, 0)
11676 +#define VCMD_set_cflags                VC_CMD(FLAGS, 2, 0)
11677 +
11678 +struct vcmd_ctx_flags_v0 {
11679 +       uint64_t flagword;
11680 +       uint64_t mask;
11681 +};
11682 +
11683 +#ifdef __KERNEL__
11684 +extern int vc_get_cflags(struct vx_info *, void __user *);
11685 +extern int vc_set_cflags(struct vx_info *, void __user *);
11686 +
11687 +#endif /* __KERNEL__ */
11688 +
11689 +
11690 +/* context caps commands */
11691 +
11692 +#define VCMD_get_ccaps         VC_CMD(FLAGS, 3, 1)
11693 +#define VCMD_set_ccaps         VC_CMD(FLAGS, 4, 1)
11694 +
11695 +struct vcmd_ctx_caps_v1 {
11696 +       uint64_t ccaps;
11697 +       uint64_t cmask;
11698 +};
11699 +
11700 +#ifdef __KERNEL__
11701 +extern int vc_get_ccaps(struct vx_info *, void __user *);
11702 +extern int vc_set_ccaps(struct vx_info *, void __user *);
11703 +
11704 +#endif /* __KERNEL__ */
11705 +
11706 +
11707 +/* bcaps commands */
11708 +
11709 +#define VCMD_get_bcaps         VC_CMD(FLAGS, 9, 0)
11710 +#define VCMD_set_bcaps         VC_CMD(FLAGS, 10, 0)
11711 +
11712 +struct vcmd_bcaps {
11713 +       uint64_t bcaps;
11714 +       uint64_t bmask;
11715 +};
11716 +
11717 +#ifdef __KERNEL__
11718 +extern int vc_get_bcaps(struct vx_info *, void __user *);
11719 +extern int vc_set_bcaps(struct vx_info *, void __user *);
11720 +
11721 +#endif /* __KERNEL__ */
11722 +
11723 +
11724 +/* umask commands */
11725 +
11726 +#define VCMD_get_umask         VC_CMD(FLAGS, 13, 0)
11727 +#define VCMD_set_umask         VC_CMD(FLAGS, 14, 0)
11728 +
11729 +struct vcmd_umask {
11730 +       uint64_t umask;
11731 +       uint64_t mask;
11732 +};
11733 +
11734 +#ifdef __KERNEL__
11735 +extern int vc_get_umask(struct vx_info *, void __user *);
11736 +extern int vc_set_umask(struct vx_info *, void __user *);
11737 +
11738 +#endif /* __KERNEL__ */
11739 +
11740 +
11741 +/* wmask commands */
11742 +
11743 +#define VCMD_get_wmask         VC_CMD(FLAGS, 15, 0)
11744 +#define VCMD_set_wmask         VC_CMD(FLAGS, 16, 0)
11745 +
11746 +struct vcmd_wmask {
11747 +       uint64_t wmask;
11748 +       uint64_t mask;
11749 +};
11750 +
11751 +#ifdef __KERNEL__
11752 +extern int vc_get_wmask(struct vx_info *, void __user *);
11753 +extern int vc_set_wmask(struct vx_info *, void __user *);
11754 +
11755 +#endif /* __KERNEL__ */
11756 +
11757 +
11758 +/* OOM badness */
11759 +
11760 +#define VCMD_get_badness       VC_CMD(MEMCTRL, 5, 0)
11761 +#define VCMD_set_badness       VC_CMD(MEMCTRL, 6, 0)
11762 +
11763 +struct vcmd_badness_v0 {
11764 +       int64_t bias;
11765 +};
11766 +
11767 +#ifdef __KERNEL__
11768 +extern int vc_get_badness(struct vx_info *, void __user *);
11769 +extern int vc_set_badness(struct vx_info *, void __user *);
11770 +
11771 +#endif /* __KERNEL__ */
11772 +#endif /* _VX_CONTEXT_CMD_H */
11773 diff -NurpP --minimal linux-3.0.25/include/linux/vserver/cvirt.h linux-3.0.25-vs2.3.2.3/include/linux/vserver/cvirt.h
11774 --- linux-3.0.25/include/linux/vserver/cvirt.h  1970-01-01 01:00:00.000000000 +0100
11775 +++ linux-3.0.25-vs2.3.2.3/include/linux/vserver/cvirt.h        2011-06-10 22:11:24.000000000 +0200
11776 @@ -0,0 +1,20 @@
11777 +#ifndef _VX_CVIRT_H
11778 +#define _VX_CVIRT_H
11779 +
11780 +
11781 +#ifdef __KERNEL__
11782 +
11783 +struct timespec;
11784 +
11785 +void vx_vsi_uptime(struct timespec *, struct timespec *);
11786 +
11787 +
11788 +struct vx_info;
11789 +
11790 +void vx_update_load(struct vx_info *);
11791 +
11792 +
11793 +int vx_do_syslog(int, char __user *, int);
11794 +
11795 +#endif /* __KERNEL__ */
11796 +#endif /* _VX_CVIRT_H */
11797 diff -NurpP --minimal linux-3.0.25/include/linux/vserver/cvirt_cmd.h linux-3.0.25-vs2.3.2.3/include/linux/vserver/cvirt_cmd.h
11798 --- linux-3.0.25/include/linux/vserver/cvirt_cmd.h      1970-01-01 01:00:00.000000000 +0100
11799 +++ linux-3.0.25-vs2.3.2.3/include/linux/vserver/cvirt_cmd.h    2011-06-10 22:11:24.000000000 +0200
11800 @@ -0,0 +1,53 @@
11801 +#ifndef _VX_CVIRT_CMD_H
11802 +#define _VX_CVIRT_CMD_H
11803 +
11804 +
11805 +/* virtual host info name commands */
11806 +
11807 +#define VCMD_set_vhi_name      VC_CMD(VHOST, 1, 0)
11808 +#define VCMD_get_vhi_name      VC_CMD(VHOST, 2, 0)
11809 +
11810 +struct vcmd_vhi_name_v0 {
11811 +       uint32_t field;
11812 +       char name[65];
11813 +};
11814 +
11815 +
11816 +enum vhi_name_field {
11817 +       VHIN_CONTEXT = 0,
11818 +       VHIN_SYSNAME,
11819 +       VHIN_NODENAME,
11820 +       VHIN_RELEASE,
11821 +       VHIN_VERSION,
11822 +       VHIN_MACHINE,
11823 +       VHIN_DOMAINNAME,
11824 +};
11825 +
11826 +
11827 +#ifdef __KERNEL__
11828 +
11829 +#include <linux/compiler.h>
11830 +
11831 +extern int vc_set_vhi_name(struct vx_info *, void __user *);
11832 +extern int vc_get_vhi_name(struct vx_info *, void __user *);
11833 +
11834 +#endif /* __KERNEL__ */
11835 +
11836 +#define VCMD_virt_stat         VC_CMD(VSTAT, 3, 0)
11837 +
11838 +struct vcmd_virt_stat_v0 {
11839 +       uint64_t offset;
11840 +       uint64_t uptime;
11841 +       uint32_t nr_threads;
11842 +       uint32_t nr_running;
11843 +       uint32_t nr_uninterruptible;
11844 +       uint32_t nr_onhold;
11845 +       uint32_t nr_forks;
11846 +       uint32_t load[3];
11847 +};
11848 +
11849 +#ifdef __KERNEL__
11850 +extern int vc_virt_stat(struct vx_info *, void __user *);
11851 +
11852 +#endif /* __KERNEL__ */
11853 +#endif /* _VX_CVIRT_CMD_H */
11854 diff -NurpP --minimal linux-3.0.25/include/linux/vserver/cvirt_def.h linux-3.0.25-vs2.3.2.3/include/linux/vserver/cvirt_def.h
11855 --- linux-3.0.25/include/linux/vserver/cvirt_def.h      1970-01-01 01:00:00.000000000 +0100
11856 +++ linux-3.0.25-vs2.3.2.3/include/linux/vserver/cvirt_def.h    2011-06-10 22:11:24.000000000 +0200
11857 @@ -0,0 +1,80 @@
11858 +#ifndef _VX_CVIRT_DEF_H
11859 +#define _VX_CVIRT_DEF_H
11860 +
11861 +#include <linux/jiffies.h>
11862 +#include <linux/spinlock.h>
11863 +#include <linux/wait.h>
11864 +#include <linux/time.h>
11865 +#include <asm/atomic.h>
11866 +
11867 +
11868 +struct _vx_usage_stat {
11869 +       uint64_t user;
11870 +       uint64_t nice;
11871 +       uint64_t system;
11872 +       uint64_t softirq;
11873 +       uint64_t irq;
11874 +       uint64_t idle;
11875 +       uint64_t iowait;
11876 +};
11877 +
11878 +struct _vx_syslog {
11879 +       wait_queue_head_t log_wait;
11880 +       spinlock_t logbuf_lock;         /* lock for the log buffer */
11881 +
11882 +       unsigned long log_start;        /* next char to be read by syslog() */
11883 +       unsigned long con_start;        /* next char to be sent to consoles */
11884 +       unsigned long log_end;  /* most-recently-written-char + 1 */
11885 +       unsigned long logged_chars;     /* #chars since last read+clear operation */
11886 +
11887 +       char log_buf[1024];
11888 +};
11889 +
11890 +
11891 +/* context sub struct */
11892 +
11893 +struct _vx_cvirt {
11894 +       atomic_t nr_threads;            /* number of current threads */
11895 +       atomic_t nr_running;            /* number of running threads */
11896 +       atomic_t nr_uninterruptible;    /* number of uninterruptible threads */
11897 +
11898 +       atomic_t nr_onhold;             /* processes on hold */
11899 +       uint32_t onhold_last;           /* jiffies when put on hold */
11900 +
11901 +       struct timespec bias_ts;        /* time offset to the host */
11902 +       struct timespec bias_idle;
11903 +       struct timespec bias_uptime;    /* context creation point */
11904 +       uint64_t bias_clock;            /* offset in clock_t */
11905 +
11906 +       spinlock_t load_lock;           /* lock for the load averages */
11907 +       atomic_t load_updates;          /* nr of load updates done so far */
11908 +       uint32_t load_last;             /* last time load was calculated */
11909 +       uint32_t load[3];               /* load averages 1,5,15 */
11910 +
11911 +       atomic_t total_forks;           /* number of forks so far */
11912 +
11913 +       struct _vx_syslog syslog;
11914 +};
11915 +
11916 +struct _vx_cvirt_pc {
11917 +       struct _vx_usage_stat cpustat;
11918 +};
11919 +
11920 +
11921 +#ifdef CONFIG_VSERVER_DEBUG
11922 +
11923 +static inline void __dump_vx_cvirt(struct _vx_cvirt *cvirt)
11924 +{
11925 +       printk("\t_vx_cvirt:\n");
11926 +       printk("\t threads: %4d, %4d, %4d, %4d\n",
11927 +               atomic_read(&cvirt->nr_threads),
11928 +               atomic_read(&cvirt->nr_running),
11929 +               atomic_read(&cvirt->nr_uninterruptible),
11930 +               atomic_read(&cvirt->nr_onhold));
11931 +       /* add rest here */
11932 +       printk("\t total_forks = %d\n", atomic_read(&cvirt->total_forks));
11933 +}
11934 +
11935 +#endif
11936 +
11937 +#endif /* _VX_CVIRT_DEF_H */
11938 diff -NurpP --minimal linux-3.0.25/include/linux/vserver/debug.h linux-3.0.25-vs2.3.2.3/include/linux/vserver/debug.h
11939 --- linux-3.0.25/include/linux/vserver/debug.h  1970-01-01 01:00:00.000000000 +0100
11940 +++ linux-3.0.25-vs2.3.2.3/include/linux/vserver/debug.h        2011-11-17 21:25:04.000000000 +0100
11941 @@ -0,0 +1,145 @@
11942 +#ifndef _VX_DEBUG_H
11943 +#define _VX_DEBUG_H
11944 +
11945 +
11946 +#define VXD_CBIT(n, m) (vs_debug_ ## n & (1 << (m)))
11947 +#define VXD_CMIN(n, m) (vs_debug_ ## n > (m))
11948 +#define VXD_MASK(n, m) (vs_debug_ ## n & (m))
11949 +
11950 +#define VXD_DEV(d)     (d), (d)->bd_inode->i_ino,              \
11951 +                       imajor((d)->bd_inode), iminor((d)->bd_inode)
11952 +#define VXF_DEV                "%p[%lu,%d:%d]"
11953 +
11954 +#if    defined(CONFIG_QUOTES_UTF8)
11955 +#define        VS_Q_LQM        "\xc2\xbb"
11956 +#define        VS_Q_RQM        "\xc2\xab"
11957 +#elif  defined(CONFIG_QUOTES_ASCII)
11958 +#define        VS_Q_LQM        "\x27"
11959 +#define        VS_Q_RQM        "\x27"
11960 +#else
11961 +#define        VS_Q_LQM        "\xbb"
11962 +#define        VS_Q_RQM        "\xab"
11963 +#endif
11964 +
11965 +#define        VS_Q(f)         VS_Q_LQM f VS_Q_RQM
11966 +
11967 +
11968 +#define vxd_path(p)                                            \
11969 +       ({ static char _buffer[PATH_MAX];                       \
11970 +          d_path(p, _buffer, sizeof(_buffer)); })
11971 +
11972 +#define vxd_cond_path(n)                                       \
11973 +       ((n) ? vxd_path(&(n)->path) : "<null>" )
11974 +
11975 +
11976 +#ifdef CONFIG_VSERVER_DEBUG
11977 +
11978 +extern unsigned int vs_debug_switch;
11979 +extern unsigned int vs_debug_xid;
11980 +extern unsigned int vs_debug_nid;
11981 +extern unsigned int vs_debug_tag;
11982 +extern unsigned int vs_debug_net;
11983 +extern unsigned int vs_debug_limit;
11984 +extern unsigned int vs_debug_cres;
11985 +extern unsigned int vs_debug_dlim;
11986 +extern unsigned int vs_debug_quota;
11987 +extern unsigned int vs_debug_cvirt;
11988 +extern unsigned int vs_debug_space;
11989 +extern unsigned int vs_debug_perm;
11990 +extern unsigned int vs_debug_misc;
11991 +
11992 +
11993 +#define VX_LOGLEVEL    "vxD: "
11994 +#define VX_PROC_FMT    "%p: "
11995 +#define VX_PROCESS     current
11996 +
11997 +#define vxdprintk(c, f, x...)                                  \
11998 +       do {                                                    \
11999 +               if (c)                                          \
12000 +                       printk(VX_LOGLEVEL VX_PROC_FMT f "\n",  \
12001 +                               VX_PROCESS , ##x);              \
12002 +       } while (0)
12003 +
12004 +#define vxlprintk(c, f, x...)                                  \
12005 +       do {                                                    \
12006 +               if (c)                                          \
12007 +                       printk(VX_LOGLEVEL f " @%s:%d\n", x);   \
12008 +       } while (0)
12009 +
12010 +#define vxfprintk(c, f, x...)                                  \
12011 +       do {                                                    \
12012 +               if (c)                                          \
12013 +                       printk(VX_LOGLEVEL f " %s@%s:%d\n", x); \
12014 +       } while (0)
12015 +
12016 +
12017 +struct vx_info;
12018 +
12019 +void dump_vx_info(struct vx_info *, int);
12020 +void dump_vx_info_inactive(int);
12021 +
12022 +#else  /* CONFIG_VSERVER_DEBUG */
12023 +
12024 +#define vs_debug_switch        0
12025 +#define vs_debug_xid   0
12026 +#define vs_debug_nid   0
12027 +#define vs_debug_tag   0
12028 +#define vs_debug_net   0
12029 +#define vs_debug_limit 0
12030 +#define vs_debug_cres  0
12031 +#define vs_debug_dlim  0
12032 +#define vs_debug_quota 0
12033 +#define vs_debug_cvirt 0
12034 +#define vs_debug_space 0
12035 +#define vs_debug_perm  0
12036 +#define vs_debug_misc  0
12037 +
12038 +#define vxdprintk(x...) do { } while (0)
12039 +#define vxlprintk(x...) do { } while (0)
12040 +#define vxfprintk(x...) do { } while (0)
12041 +
12042 +#endif /* CONFIG_VSERVER_DEBUG */
12043 +
12044 +
12045 +#ifdef CONFIG_VSERVER_WARN
12046 +
12047 +#define VX_WARNLEVEL   KERN_WARNING "vxW: "
12048 +#define VX_WARN_TASK   "[" VS_Q("%s") ",%u:#%u|%u|%u] "
12049 +#define VX_WARN_XID    "[xid #%u] "
12050 +#define VX_WARN_NID    "[nid #%u] "
12051 +#define VX_WARN_TAG    "[tag #%u] "
12052 +
12053 +#define vxwprintk(c, f, x...)                                  \
12054 +       do {                                                    \
12055 +               if (c)                                          \
12056 +                       printk(VX_WARNLEVEL f "\n", ##x);       \
12057 +       } while (0)
12058 +
12059 +#else  /* CONFIG_VSERVER_WARN */
12060 +
12061 +#define vxwprintk(x...) do { } while (0)
12062 +
12063 +#endif /* CONFIG_VSERVER_WARN */
12064 +
12065 +#define vxwprintk_task(c, f, x...)                             \
12066 +       vxwprintk(c, VX_WARN_TASK f,                            \
12067 +               current->comm, current->pid,                    \
12068 +               current->xid, current->nid, current->tag, ##x)
12069 +#define vxwprintk_xid(c, f, x...)                              \
12070 +       vxwprintk(c, VX_WARN_XID f, current->xid, x)
12071 +#define vxwprintk_nid(c, f, x...)                              \
12072 +       vxwprintk(c, VX_WARN_NID f, current->nid, x)
12073 +#define vxwprintk_tag(c, f, x...)                              \
12074 +       vxwprintk(c, VX_WARN_TAG f, current->tag, x)
12075 +
12076 +#ifdef CONFIG_VSERVER_DEBUG
12077 +#define vxd_assert_lock(l)     assert_spin_locked(l)
12078 +#define vxd_assert(c, f, x...) vxlprintk(!(c), \
12079 +       "assertion [" f "] failed.", ##x, __FILE__, __LINE__)
12080 +#else
12081 +#define vxd_assert_lock(l)     do { } while (0)
12082 +#define vxd_assert(c, f, x...) do { } while (0)
12083 +#endif
12084 +
12085 +
12086 +#endif /* _VX_DEBUG_H */
12087 diff -NurpP --minimal linux-3.0.25/include/linux/vserver/debug_cmd.h linux-3.0.25-vs2.3.2.3/include/linux/vserver/debug_cmd.h
12088 --- linux-3.0.25/include/linux/vserver/debug_cmd.h      1970-01-01 01:00:00.000000000 +0100
12089 +++ linux-3.0.25-vs2.3.2.3/include/linux/vserver/debug_cmd.h    2011-06-10 22:11:24.000000000 +0200
12090 @@ -0,0 +1,58 @@
12091 +#ifndef _VX_DEBUG_CMD_H
12092 +#define _VX_DEBUG_CMD_H
12093 +
12094 +
12095 +/* debug commands */
12096 +
12097 +#define VCMD_dump_history      VC_CMD(DEBUG, 1, 0)
12098 +
12099 +#define VCMD_read_history      VC_CMD(DEBUG, 5, 0)
12100 +#define VCMD_read_monitor      VC_CMD(DEBUG, 6, 0)
12101 +
12102 +struct  vcmd_read_history_v0 {
12103 +       uint32_t index;
12104 +       uint32_t count;
12105 +       char __user *data;
12106 +};
12107 +
12108 +struct  vcmd_read_monitor_v0 {
12109 +       uint32_t index;
12110 +       uint32_t count;
12111 +       char __user *data;
12112 +};
12113 +
12114 +
12115 +#ifdef __KERNEL__
12116 +
12117 +#ifdef CONFIG_COMPAT
12118 +
12119 +#include <asm/compat.h>
12120 +
12121 +struct vcmd_read_history_v0_x32 {
12122 +       uint32_t index;
12123 +       uint32_t count;
12124 +       compat_uptr_t data_ptr;
12125 +};
12126 +
12127 +struct vcmd_read_monitor_v0_x32 {
12128 +       uint32_t index;
12129 +       uint32_t count;
12130 +       compat_uptr_t data_ptr;
12131 +};
12132 +
12133 +#endif  /* CONFIG_COMPAT */
12134 +
12135 +extern int vc_dump_history(uint32_t);
12136 +
12137 +extern int vc_read_history(uint32_t, void __user *);
12138 +extern int vc_read_monitor(uint32_t, void __user *);
12139 +
12140 +#ifdef CONFIG_COMPAT
12141 +
12142 +extern int vc_read_history_x32(uint32_t, void __user *);
12143 +extern int vc_read_monitor_x32(uint32_t, void __user *);
12144 +
12145 +#endif  /* CONFIG_COMPAT */
12146 +
12147 +#endif /* __KERNEL__ */
12148 +#endif /* _VX_DEBUG_CMD_H */
12149 diff -NurpP --minimal linux-3.0.25/include/linux/vserver/device.h linux-3.0.25-vs2.3.2.3/include/linux/vserver/device.h
12150 --- linux-3.0.25/include/linux/vserver/device.h 1970-01-01 01:00:00.000000000 +0100
12151 +++ linux-3.0.25-vs2.3.2.3/include/linux/vserver/device.h       2011-06-10 22:11:24.000000000 +0200
12152 @@ -0,0 +1,15 @@
12153 +#ifndef _VX_DEVICE_H
12154 +#define _VX_DEVICE_H
12155 +
12156 +
12157 +#define DATTR_CREATE   0x00000001
12158 +#define DATTR_OPEN     0x00000002
12159 +
12160 +#define DATTR_REMAP    0x00000010
12161 +
12162 +#define DATTR_MASK     0x00000013
12163 +
12164 +
12165 +#else  /* _VX_DEVICE_H */
12166 +#warning duplicate inclusion
12167 +#endif /* _VX_DEVICE_H */
12168 diff -NurpP --minimal linux-3.0.25/include/linux/vserver/device_cmd.h linux-3.0.25-vs2.3.2.3/include/linux/vserver/device_cmd.h
12169 --- linux-3.0.25/include/linux/vserver/device_cmd.h     1970-01-01 01:00:00.000000000 +0100
12170 +++ linux-3.0.25-vs2.3.2.3/include/linux/vserver/device_cmd.h   2011-06-10 22:11:24.000000000 +0200
12171 @@ -0,0 +1,44 @@
12172 +#ifndef _VX_DEVICE_CMD_H
12173 +#define _VX_DEVICE_CMD_H
12174 +
12175 +
12176 +/*  device vserver commands */
12177 +
12178 +#define VCMD_set_mapping       VC_CMD(DEVICE, 1, 0)
12179 +#define VCMD_unset_mapping     VC_CMD(DEVICE, 2, 0)
12180 +
12181 +struct vcmd_set_mapping_v0 {
12182 +       const char __user *device;
12183 +       const char __user *target;
12184 +       uint32_t flags;
12185 +};
12186 +
12187 +
12188 +#ifdef __KERNEL__
12189 +
12190 +#ifdef CONFIG_COMPAT
12191 +
12192 +#include <asm/compat.h>
12193 +
12194 +struct vcmd_set_mapping_v0_x32 {
12195 +       compat_uptr_t device_ptr;
12196 +       compat_uptr_t target_ptr;
12197 +       uint32_t flags;
12198 +};
12199 +
12200 +#endif /* CONFIG_COMPAT */
12201 +
12202 +#include <linux/compiler.h>
12203 +
12204 +extern int vc_set_mapping(struct vx_info *, void __user *);
12205 +extern int vc_unset_mapping(struct vx_info *, void __user *);
12206 +
12207 +#ifdef CONFIG_COMPAT
12208 +
12209 +extern int vc_set_mapping_x32(struct vx_info *, void __user *);
12210 +extern int vc_unset_mapping_x32(struct vx_info *, void __user *);
12211 +
12212 +#endif /* CONFIG_COMPAT */
12213 +
12214 +#endif /* __KERNEL__ */
12215 +#endif /* _VX_DEVICE_CMD_H */
12216 diff -NurpP --minimal linux-3.0.25/include/linux/vserver/device_def.h linux-3.0.25-vs2.3.2.3/include/linux/vserver/device_def.h
12217 --- linux-3.0.25/include/linux/vserver/device_def.h     1970-01-01 01:00:00.000000000 +0100
12218 +++ linux-3.0.25-vs2.3.2.3/include/linux/vserver/device_def.h   2011-06-10 22:11:24.000000000 +0200
12219 @@ -0,0 +1,17 @@
12220 +#ifndef _VX_DEVICE_DEF_H
12221 +#define _VX_DEVICE_DEF_H
12222 +
12223 +#include <linux/types.h>
12224 +
12225 +struct vx_dmap_target {
12226 +       dev_t target;
12227 +       uint32_t flags;
12228 +};
12229 +
12230 +struct _vx_device {
12231 +#ifdef CONFIG_VSERVER_DEVICE
12232 +       struct vx_dmap_target targets[2];
12233 +#endif
12234 +};
12235 +
12236 +#endif /* _VX_DEVICE_DEF_H */
12237 diff -NurpP --minimal linux-3.0.25/include/linux/vserver/dlimit.h linux-3.0.25-vs2.3.2.3/include/linux/vserver/dlimit.h
12238 --- linux-3.0.25/include/linux/vserver/dlimit.h 1970-01-01 01:00:00.000000000 +0100
12239 +++ linux-3.0.25-vs2.3.2.3/include/linux/vserver/dlimit.h       2011-06-10 22:11:24.000000000 +0200
12240 @@ -0,0 +1,54 @@
12241 +#ifndef _VX_DLIMIT_H
12242 +#define _VX_DLIMIT_H
12243 +
12244 +#include "switch.h"
12245 +
12246 +
12247 +#ifdef __KERNEL__
12248 +
12249 +/*      keep in sync with CDLIM_INFINITY       */
12250 +
12251 +#define DLIM_INFINITY          (~0ULL)
12252 +
12253 +#include <linux/spinlock.h>
12254 +#include <linux/rcupdate.h>
12255 +
12256 +struct super_block;
12257 +
12258 +struct dl_info {
12259 +       struct hlist_node dl_hlist;             /* linked list of contexts */
12260 +       struct rcu_head dl_rcu;                 /* the rcu head */
12261 +       tag_t dl_tag;                           /* context tag */
12262 +       atomic_t dl_usecnt;                     /* usage count */
12263 +       atomic_t dl_refcnt;                     /* reference count */
12264 +
12265 +       struct super_block *dl_sb;              /* associated superblock */
12266 +
12267 +       spinlock_t dl_lock;                     /* protect the values */
12268 +
12269 +       unsigned long long dl_space_used;       /* used space in bytes */
12270 +       unsigned long long dl_space_total;      /* maximum space in bytes */
12271 +       unsigned long dl_inodes_used;           /* used inodes */
12272 +       unsigned long dl_inodes_total;          /* maximum inodes */
12273 +
12274 +       unsigned int dl_nrlmult;                /* non root limit mult */
12275 +};
12276 +
12277 +struct rcu_head;
12278 +
12279 +extern void rcu_free_dl_info(struct rcu_head *);
12280 +extern void unhash_dl_info(struct dl_info *);
12281 +
12282 +extern struct dl_info *locate_dl_info(struct super_block *, tag_t);
12283 +
12284 +
12285 +struct kstatfs;
12286 +
12287 +extern void vx_vsi_statfs(struct super_block *, struct kstatfs *);
12288 +
12289 +typedef uint64_t dlsize_t;
12290 +
12291 +#endif /* __KERNEL__ */
12292 +#else  /* _VX_DLIMIT_H */
12293 +#warning duplicate inclusion
12294 +#endif /* _VX_DLIMIT_H */
12295 diff -NurpP --minimal linux-3.0.25/include/linux/vserver/dlimit_cmd.h linux-3.0.25-vs2.3.2.3/include/linux/vserver/dlimit_cmd.h
12296 --- linux-3.0.25/include/linux/vserver/dlimit_cmd.h     1970-01-01 01:00:00.000000000 +0100
12297 +++ linux-3.0.25-vs2.3.2.3/include/linux/vserver/dlimit_cmd.h   2011-06-10 22:11:24.000000000 +0200
12298 @@ -0,0 +1,109 @@
12299 +#ifndef _VX_DLIMIT_CMD_H
12300 +#define _VX_DLIMIT_CMD_H
12301 +
12302 +
12303 +/*  dlimit vserver commands */
12304 +
12305 +#define VCMD_add_dlimit                VC_CMD(DLIMIT, 1, 0)
12306 +#define VCMD_rem_dlimit                VC_CMD(DLIMIT, 2, 0)
12307 +
12308 +#define VCMD_set_dlimit                VC_CMD(DLIMIT, 5, 0)
12309 +#define VCMD_get_dlimit                VC_CMD(DLIMIT, 6, 0)
12310 +
12311 +struct vcmd_ctx_dlimit_base_v0 {
12312 +       const char __user *name;
12313 +       uint32_t flags;
12314 +};
12315 +
12316 +struct vcmd_ctx_dlimit_v0 {
12317 +       const char __user *name;
12318 +       uint32_t space_used;                    /* used space in kbytes */
12319 +       uint32_t space_total;                   /* maximum space in kbytes */
12320 +       uint32_t inodes_used;                   /* used inodes */
12321 +       uint32_t inodes_total;                  /* maximum inodes */
12322 +       uint32_t reserved;                      /* reserved for root in % */
12323 +       uint32_t flags;
12324 +};
12325 +
12326 +#define CDLIM_UNSET            ((uint32_t)0UL)
12327 +#define CDLIM_INFINITY         ((uint32_t)~0UL)
12328 +#define CDLIM_KEEP             ((uint32_t)~1UL)
12329 +
12330 +#define DLIME_UNIT     0
12331 +#define DLIME_KILO     1
12332 +#define DLIME_MEGA     2
12333 +#define DLIME_GIGA     3
12334 +
12335 +#define DLIMF_SHIFT    0x10
12336 +
12337 +#define DLIMS_USED     0
12338 +#define DLIMS_TOTAL    2
12339 +
12340 +static inline
12341 +uint64_t dlimit_space_32to64(uint32_t val, uint32_t flags, int shift)
12342 +{
12343 +       int exp = (flags & DLIMF_SHIFT) ?
12344 +               (flags >> shift) & DLIME_GIGA : DLIME_KILO;
12345 +       return ((uint64_t)val) << (10 * exp);
12346 +}
12347 +
12348 +static inline
12349 +uint32_t dlimit_space_64to32(uint64_t val, uint32_t *flags, int shift)
12350 +{
12351 +       int exp = 0;
12352 +
12353 +       if (*flags & DLIMF_SHIFT) {
12354 +               while (val > (1LL << 32) && (exp < 3)) {
12355 +                       val >>= 10;
12356 +                       exp++;
12357 +               }
12358 +               *flags &= ~(DLIME_GIGA << shift);
12359 +               *flags |= exp << shift;
12360 +       } else
12361 +               val >>= 10;
12362 +       return val;
12363 +}
12364 +
12365 +#ifdef __KERNEL__
12366 +
12367 +#ifdef CONFIG_COMPAT
12368 +
12369 +#include <asm/compat.h>
12370 +
12371 +struct vcmd_ctx_dlimit_base_v0_x32 {
12372 +       compat_uptr_t name_ptr;
12373 +       uint32_t flags;
12374 +};
12375 +
12376 +struct vcmd_ctx_dlimit_v0_x32 {
12377 +       compat_uptr_t name_ptr;
12378 +       uint32_t space_used;                    /* used space in kbytes */
12379 +       uint32_t space_total;                   /* maximum space in kbytes */
12380 +       uint32_t inodes_used;                   /* used inodes */
12381 +       uint32_t inodes_total;                  /* maximum inodes */
12382 +       uint32_t reserved;                      /* reserved for root in % */
12383 +       uint32_t flags;
12384 +};
12385 +
12386 +#endif /* CONFIG_COMPAT */
12387 +
12388 +#include <linux/compiler.h>
12389 +
12390 +extern int vc_add_dlimit(uint32_t, void __user *);
12391 +extern int vc_rem_dlimit(uint32_t, void __user *);
12392 +
12393 +extern int vc_set_dlimit(uint32_t, void __user *);
12394 +extern int vc_get_dlimit(uint32_t, void __user *);
12395 +
12396 +#ifdef CONFIG_COMPAT
12397 +
12398 +extern int vc_add_dlimit_x32(uint32_t, void __user *);
12399 +extern int vc_rem_dlimit_x32(uint32_t, void __user *);
12400 +
12401 +extern int vc_set_dlimit_x32(uint32_t, void __user *);
12402 +extern int vc_get_dlimit_x32(uint32_t, void __user *);
12403 +
12404 +#endif /* CONFIG_COMPAT */
12405 +
12406 +#endif /* __KERNEL__ */
12407 +#endif /* _VX_DLIMIT_CMD_H */
12408 diff -NurpP --minimal linux-3.0.25/include/linux/vserver/global.h linux-3.0.25-vs2.3.2.3/include/linux/vserver/global.h
12409 --- linux-3.0.25/include/linux/vserver/global.h 1970-01-01 01:00:00.000000000 +0100
12410 +++ linux-3.0.25-vs2.3.2.3/include/linux/vserver/global.h       2011-06-10 22:11:24.000000000 +0200
12411 @@ -0,0 +1,19 @@
12412 +#ifndef _VX_GLOBAL_H
12413 +#define _VX_GLOBAL_H
12414 +
12415 +
12416 +extern atomic_t vx_global_ctotal;
12417 +extern atomic_t vx_global_cactive;
12418 +
12419 +extern atomic_t nx_global_ctotal;
12420 +extern atomic_t nx_global_cactive;
12421 +
12422 +extern atomic_t vs_global_nsproxy;
12423 +extern atomic_t vs_global_fs;
12424 +extern atomic_t vs_global_mnt_ns;
12425 +extern atomic_t vs_global_uts_ns;
12426 +extern atomic_t vs_global_user_ns;
12427 +extern atomic_t vs_global_pid_ns;
12428 +
12429 +
12430 +#endif /* _VX_GLOBAL_H */
12431 diff -NurpP --minimal linux-3.0.25/include/linux/vserver/history.h linux-3.0.25-vs2.3.2.3/include/linux/vserver/history.h
12432 --- linux-3.0.25/include/linux/vserver/history.h        1970-01-01 01:00:00.000000000 +0100
12433 +++ linux-3.0.25-vs2.3.2.3/include/linux/vserver/history.h      2011-06-10 22:11:24.000000000 +0200
12434 @@ -0,0 +1,197 @@
12435 +#ifndef _VX_HISTORY_H
12436 +#define _VX_HISTORY_H
12437 +
12438 +
12439 +enum {
12440 +       VXH_UNUSED = 0,
12441 +       VXH_THROW_OOPS = 1,
12442 +
12443 +       VXH_GET_VX_INFO,
12444 +       VXH_PUT_VX_INFO,
12445 +       VXH_INIT_VX_INFO,
12446 +       VXH_SET_VX_INFO,
12447 +       VXH_CLR_VX_INFO,
12448 +       VXH_CLAIM_VX_INFO,
12449 +       VXH_RELEASE_VX_INFO,
12450 +       VXH_ALLOC_VX_INFO,
12451 +       VXH_DEALLOC_VX_INFO,
12452 +       VXH_HASH_VX_INFO,
12453 +       VXH_UNHASH_VX_INFO,
12454 +       VXH_LOC_VX_INFO,
12455 +       VXH_LOOKUP_VX_INFO,
12456 +       VXH_CREATE_VX_INFO,
12457 +};
12458 +
12459 +struct _vxhe_vxi {
12460 +       struct vx_info *ptr;
12461 +       unsigned xid;
12462 +       unsigned usecnt;
12463 +       unsigned tasks;
12464 +};
12465 +
12466 +struct _vxhe_set_clr {
12467 +       void *data;
12468 +};
12469 +
12470 +struct _vxhe_loc_lookup {
12471 +       unsigned arg;
12472 +};
12473 +
12474 +struct _vx_hist_entry {
12475 +       void *loc;
12476 +       unsigned short seq;
12477 +       unsigned short type;
12478 +       struct _vxhe_vxi vxi;
12479 +       union {
12480 +               struct _vxhe_set_clr sc;
12481 +               struct _vxhe_loc_lookup ll;
12482 +       };
12483 +};
12484 +
12485 +#ifdef CONFIG_VSERVER_HISTORY
12486 +
12487 +extern unsigned volatile int vxh_active;
12488 +
12489 +struct _vx_hist_entry *vxh_advance(void *loc);
12490 +
12491 +
12492 +static inline
12493 +void   __vxh_copy_vxi(struct _vx_hist_entry *entry, struct vx_info *vxi)
12494 +{
12495 +       entry->vxi.ptr = vxi;
12496 +       if (vxi) {
12497 +               entry->vxi.usecnt = atomic_read(&vxi->vx_usecnt);
12498 +               entry->vxi.tasks = atomic_read(&vxi->vx_tasks);
12499 +               entry->vxi.xid = vxi->vx_id;
12500 +       }
12501 +}
12502 +
12503 +
12504 +#define        __HERE__ current_text_addr()
12505 +
12506 +#define __VXH_BODY(__type, __data, __here)     \
12507 +       struct _vx_hist_entry *entry;           \
12508 +                                               \
12509 +       preempt_disable();                      \
12510 +       entry = vxh_advance(__here);            \
12511 +       __data;                                 \
12512 +       entry->type = __type;                   \
12513 +       preempt_enable();
12514 +
12515 +
12516 +       /* pass vxi only */
12517 +
12518 +#define __VXH_SMPL                             \
12519 +       __vxh_copy_vxi(entry, vxi)
12520 +
12521 +static inline
12522 +void   __vxh_smpl(struct vx_info *vxi, int __type, void *__here)
12523 +{
12524 +       __VXH_BODY(__type, __VXH_SMPL, __here)
12525 +}
12526 +
12527 +       /* pass vxi and data (void *) */
12528 +
12529 +#define __VXH_DATA                             \
12530 +       __vxh_copy_vxi(entry, vxi);             \
12531 +       entry->sc.data = data
12532 +
12533 +static inline
12534 +void   __vxh_data(struct vx_info *vxi, void *data,
12535 +                       int __type, void *__here)
12536 +{
12537 +       __VXH_BODY(__type, __VXH_DATA, __here)
12538 +}
12539 +
12540 +       /* pass vxi and arg (long) */
12541 +
12542 +#define __VXH_LONG                             \
12543 +       __vxh_copy_vxi(entry, vxi);             \
12544 +       entry->ll.arg = arg
12545 +
12546 +static inline
12547 +void   __vxh_long(struct vx_info *vxi, long arg,
12548 +                       int __type, void *__here)
12549 +{
12550 +       __VXH_BODY(__type, __VXH_LONG, __here)
12551 +}
12552 +
12553 +
12554 +static inline
12555 +void   __vxh_throw_oops(void *__here)
12556 +{
12557 +       __VXH_BODY(VXH_THROW_OOPS, {}, __here);
12558 +       /* prevent further acquisition */
12559 +       vxh_active = 0;
12560 +}
12561 +
12562 +
12563 +#define vxh_throw_oops()       __vxh_throw_oops(__HERE__);
12564 +
12565 +#define __vxh_get_vx_info(v, h)        __vxh_smpl(v, VXH_GET_VX_INFO, h);
12566 +#define __vxh_put_vx_info(v, h)        __vxh_smpl(v, VXH_PUT_VX_INFO, h);
12567 +
12568 +#define __vxh_init_vx_info(v, d, h) \
12569 +       __vxh_data(v, d, VXH_INIT_VX_INFO, h);
12570 +#define __vxh_set_vx_info(v, d, h) \
12571 +       __vxh_data(v, d, VXH_SET_VX_INFO, h);
12572 +#define __vxh_clr_vx_info(v, d, h) \
12573 +       __vxh_data(v, d, VXH_CLR_VX_INFO, h);
12574 +
12575 +#define __vxh_claim_vx_info(v, d, h) \
12576 +       __vxh_data(v, d, VXH_CLAIM_VX_INFO, h);
12577 +#define __vxh_release_vx_info(v, d, h) \
12578 +       __vxh_data(v, d, VXH_RELEASE_VX_INFO, h);
12579 +
12580 +#define vxh_alloc_vx_info(v) \
12581 +       __vxh_smpl(v, VXH_ALLOC_VX_INFO, __HERE__);
12582 +#define vxh_dealloc_vx_info(v) \
12583 +       __vxh_smpl(v, VXH_DEALLOC_VX_INFO, __HERE__);
12584 +
12585 +#define vxh_hash_vx_info(v) \
12586 +       __vxh_smpl(v, VXH_HASH_VX_INFO, __HERE__);
12587 +#define vxh_unhash_vx_info(v) \
12588 +       __vxh_smpl(v, VXH_UNHASH_VX_INFO, __HERE__);
12589 +
12590 +#define vxh_loc_vx_info(v, l) \
12591 +       __vxh_long(v, l, VXH_LOC_VX_INFO, __HERE__);
12592 +#define vxh_lookup_vx_info(v, l) \
12593 +       __vxh_long(v, l, VXH_LOOKUP_VX_INFO, __HERE__);
12594 +#define vxh_create_vx_info(v, l) \
12595 +       __vxh_long(v, l, VXH_CREATE_VX_INFO, __HERE__);
12596 +
12597 +extern void vxh_dump_history(void);
12598 +
12599 +
12600 +#else  /* CONFIG_VSERVER_HISTORY */
12601 +
12602 +#define        __HERE__        0
12603 +
12604 +#define vxh_throw_oops()               do { } while (0)
12605 +
12606 +#define __vxh_get_vx_info(v, h)                do { } while (0)
12607 +#define __vxh_put_vx_info(v, h)                do { } while (0)
12608 +
12609 +#define __vxh_init_vx_info(v, d, h)    do { } while (0)
12610 +#define __vxh_set_vx_info(v, d, h)     do { } while (0)
12611 +#define __vxh_clr_vx_info(v, d, h)     do { } while (0)
12612 +
12613 +#define __vxh_claim_vx_info(v, d, h)   do { } while (0)
12614 +#define __vxh_release_vx_info(v, d, h) do { } while (0)
12615 +
12616 +#define vxh_alloc_vx_info(v)           do { } while (0)
12617 +#define vxh_dealloc_vx_info(v)         do { } while (0)
12618 +
12619 +#define vxh_hash_vx_info(v)            do { } while (0)
12620 +#define vxh_unhash_vx_info(v)          do { } while (0)
12621 +
12622 +#define vxh_loc_vx_info(v, l)          do { } while (0)
12623 +#define vxh_lookup_vx_info(v, l)       do { } while (0)
12624 +#define vxh_create_vx_info(v, l)       do { } while (0)
12625 +
12626 +#define vxh_dump_history()             do { } while (0)
12627 +
12628 +
12629 +#endif /* CONFIG_VSERVER_HISTORY */
12630 +
12631 +#endif /* _VX_HISTORY_H */
12632 diff -NurpP --minimal linux-3.0.25/include/linux/vserver/inode.h linux-3.0.25-vs2.3.2.3/include/linux/vserver/inode.h
12633 --- linux-3.0.25/include/linux/vserver/inode.h  1970-01-01 01:00:00.000000000 +0100
12634 +++ linux-3.0.25-vs2.3.2.3/include/linux/vserver/inode.h        2011-06-10 22:11:24.000000000 +0200
12635 @@ -0,0 +1,39 @@
12636 +#ifndef _VX_INODE_H
12637 +#define _VX_INODE_H
12638 +
12639 +
12640 +#define IATTR_TAG      0x01000000
12641 +
12642 +#define IATTR_ADMIN    0x00000001
12643 +#define IATTR_WATCH    0x00000002
12644 +#define IATTR_HIDE     0x00000004
12645 +#define IATTR_FLAGS    0x00000007
12646 +
12647 +#define IATTR_BARRIER  0x00010000
12648 +#define IATTR_IXUNLINK 0x00020000
12649 +#define IATTR_IMMUTABLE 0x00040000
12650 +#define IATTR_COW      0x00080000
12651 +
12652 +#ifdef __KERNEL__
12653 +
12654 +
12655 +#ifdef CONFIG_VSERVER_PROC_SECURE
12656 +#define IATTR_PROC_DEFAULT     ( IATTR_ADMIN | IATTR_HIDE )
12657 +#define IATTR_PROC_SYMLINK     ( IATTR_ADMIN )
12658 +#else
12659 +#define IATTR_PROC_DEFAULT     ( IATTR_ADMIN )
12660 +#define IATTR_PROC_SYMLINK     ( IATTR_ADMIN )
12661 +#endif
12662 +
12663 +#define vx_hide_check(c, m)    (((m) & IATTR_HIDE) ? vx_check(c, m) : 1)
12664 +
12665 +#endif /* __KERNEL__ */
12666 +
12667 +/* inode ioctls */
12668 +
12669 +#define FIOC_GETXFLG   _IOR('x', 5, long)
12670 +#define FIOC_SETXFLG   _IOW('x', 6, long)
12671 +
12672 +#else  /* _VX_INODE_H */
12673 +#warning duplicate inclusion
12674 +#endif /* _VX_INODE_H */
12675 diff -NurpP --minimal linux-3.0.25/include/linux/vserver/inode_cmd.h linux-3.0.25-vs2.3.2.3/include/linux/vserver/inode_cmd.h
12676 --- linux-3.0.25/include/linux/vserver/inode_cmd.h      1970-01-01 01:00:00.000000000 +0100
12677 +++ linux-3.0.25-vs2.3.2.3/include/linux/vserver/inode_cmd.h    2011-06-10 22:11:24.000000000 +0200
12678 @@ -0,0 +1,59 @@
12679 +#ifndef _VX_INODE_CMD_H
12680 +#define _VX_INODE_CMD_H
12681 +
12682 +
12683 +/*  inode vserver commands */
12684 +
12685 +#define VCMD_get_iattr         VC_CMD(INODE, 1, 1)
12686 +#define VCMD_set_iattr         VC_CMD(INODE, 2, 1)
12687 +
12688 +#define VCMD_fget_iattr                VC_CMD(INODE, 3, 0)
12689 +#define VCMD_fset_iattr                VC_CMD(INODE, 4, 0)
12690 +
12691 +struct vcmd_ctx_iattr_v1 {
12692 +       const char __user *name;
12693 +       uint32_t tag;
12694 +       uint32_t flags;
12695 +       uint32_t mask;
12696 +};
12697 +
12698 +struct vcmd_ctx_fiattr_v0 {
12699 +       uint32_t tag;
12700 +       uint32_t flags;
12701 +       uint32_t mask;
12702 +};
12703 +
12704 +
12705 +#ifdef __KERNEL__
12706 +
12707 +
12708 +#ifdef CONFIG_COMPAT
12709 +
12710 +#include <asm/compat.h>
12711 +
12712 +struct vcmd_ctx_iattr_v1_x32 {
12713 +       compat_uptr_t name_ptr;
12714 +       uint32_t tag;
12715 +       uint32_t flags;
12716 +       uint32_t mask;
12717 +};
12718 +
12719 +#endif /* CONFIG_COMPAT */
12720 +
12721 +#include <linux/compiler.h>
12722 +
12723 +extern int vc_get_iattr(void __user *);
12724 +extern int vc_set_iattr(void __user *);
12725 +
12726 +extern int vc_fget_iattr(uint32_t, void __user *);
12727 +extern int vc_fset_iattr(uint32_t, void __user *);
12728 +
12729 +#ifdef CONFIG_COMPAT
12730 +
12731 +extern int vc_get_iattr_x32(void __user *);
12732 +extern int vc_set_iattr_x32(void __user *);
12733 +
12734 +#endif /* CONFIG_COMPAT */
12735 +
12736 +#endif /* __KERNEL__ */
12737 +#endif /* _VX_INODE_CMD_H */
12738 diff -NurpP --minimal linux-3.0.25/include/linux/vserver/limit.h linux-3.0.25-vs2.3.2.3/include/linux/vserver/limit.h
12739 --- linux-3.0.25/include/linux/vserver/limit.h  1970-01-01 01:00:00.000000000 +0100
12740 +++ linux-3.0.25-vs2.3.2.3/include/linux/vserver/limit.h        2011-06-10 22:11:24.000000000 +0200
12741 @@ -0,0 +1,71 @@
12742 +#ifndef _VX_LIMIT_H
12743 +#define _VX_LIMIT_H
12744 +
12745 +#define VLIMIT_NSOCK   16
12746 +#define VLIMIT_OPENFD  17
12747 +#define VLIMIT_ANON    18
12748 +#define VLIMIT_SHMEM   19
12749 +#define VLIMIT_SEMARY  20
12750 +#define VLIMIT_NSEMS   21
12751 +#define VLIMIT_DENTRY  22
12752 +#define VLIMIT_MAPPED  23
12753 +
12754 +
12755 +#ifdef __KERNEL__
12756 +
12757 +#define        VLIM_NOCHECK    ((1L << VLIMIT_DENTRY) | (1L << RLIMIT_RSS))
12758 +
12759 +/*     keep in sync with CRLIM_INFINITY */
12760 +
12761 +#define        VLIM_INFINITY   (~0ULL)
12762 +
12763 +#include <asm/atomic.h>
12764 +#include <asm/resource.h>
12765 +
12766 +#ifndef RLIM_INFINITY
12767 +#warning RLIM_INFINITY is undefined
12768 +#endif
12769 +
12770 +#define __rlim_val(l, r, v)    ((l)->res[r].v)
12771 +
12772 +#define __rlim_soft(l, r)      __rlim_val(l, r, soft)
12773 +#define __rlim_hard(l, r)      __rlim_val(l, r, hard)
12774 +
12775 +#define __rlim_rcur(l, r)      __rlim_val(l, r, rcur)
12776 +#define __rlim_rmin(l, r)      __rlim_val(l, r, rmin)
12777 +#define __rlim_rmax(l, r)      __rlim_val(l, r, rmax)
12778 +
12779 +#define __rlim_lhit(l, r)      __rlim_val(l, r, lhit)
12780 +#define __rlim_hit(l, r)       atomic_inc(&__rlim_lhit(l, r))
12781 +
12782 +typedef atomic_long_t rlim_atomic_t;
12783 +typedef unsigned long rlim_t;
12784 +
12785 +#define __rlim_get(l, r)       atomic_long_read(&__rlim_rcur(l, r))
12786 +#define __rlim_set(l, r, v)    atomic_long_set(&__rlim_rcur(l, r), v)
12787 +#define __rlim_inc(l, r)       atomic_long_inc(&__rlim_rcur(l, r))
12788 +#define __rlim_dec(l, r)       atomic_long_dec(&__rlim_rcur(l, r))
12789 +#define __rlim_add(l, r, v)    atomic_long_add(v, &__rlim_rcur(l, r))
12790 +#define __rlim_sub(l, r, v)    atomic_long_sub(v, &__rlim_rcur(l, r))
12791 +
12792 +
12793 +#if    (RLIM_INFINITY == VLIM_INFINITY)
12794 +#define        VX_VLIM(r) ((long long)(long)(r))
12795 +#define        VX_RLIM(v) ((rlim_t)(v))
12796 +#else
12797 +#define        VX_VLIM(r) (((r) == RLIM_INFINITY) \
12798 +               ? VLIM_INFINITY : (long long)(r))
12799 +#define        VX_RLIM(v) (((v) == VLIM_INFINITY) \
12800 +               ? RLIM_INFINITY : (rlim_t)(v))
12801 +#endif
12802 +
12803 +struct sysinfo;
12804 +
12805 +void vx_vsi_meminfo(struct sysinfo *);
12806 +void vx_vsi_swapinfo(struct sysinfo *);
12807 +long vx_vsi_cached(struct sysinfo *);
12808 +
12809 +#define NUM_LIMITS     24
12810 +
12811 +#endif /* __KERNEL__ */
12812 +#endif /* _VX_LIMIT_H */
12813 diff -NurpP --minimal linux-3.0.25/include/linux/vserver/limit_cmd.h linux-3.0.25-vs2.3.2.3/include/linux/vserver/limit_cmd.h
12814 --- linux-3.0.25/include/linux/vserver/limit_cmd.h      1970-01-01 01:00:00.000000000 +0100
12815 +++ linux-3.0.25-vs2.3.2.3/include/linux/vserver/limit_cmd.h    2011-06-10 22:11:24.000000000 +0200
12816 @@ -0,0 +1,71 @@
12817 +#ifndef _VX_LIMIT_CMD_H
12818 +#define _VX_LIMIT_CMD_H
12819 +
12820 +
12821 +/*  rlimit vserver commands */
12822 +
12823 +#define VCMD_get_rlimit                VC_CMD(RLIMIT, 1, 0)
12824 +#define VCMD_set_rlimit                VC_CMD(RLIMIT, 2, 0)
12825 +#define VCMD_get_rlimit_mask   VC_CMD(RLIMIT, 3, 0)
12826 +#define VCMD_reset_hits                VC_CMD(RLIMIT, 7, 0)
12827 +#define VCMD_reset_minmax      VC_CMD(RLIMIT, 9, 0)
12828 +
12829 +struct vcmd_ctx_rlimit_v0 {
12830 +       uint32_t id;
12831 +       uint64_t minimum;
12832 +       uint64_t softlimit;
12833 +       uint64_t maximum;
12834 +};
12835 +
12836 +struct vcmd_ctx_rlimit_mask_v0 {
12837 +       uint32_t minimum;
12838 +       uint32_t softlimit;
12839 +       uint32_t maximum;
12840 +};
12841 +
12842 +#define VCMD_rlimit_stat       VC_CMD(VSTAT, 1, 0)
12843 +
12844 +struct vcmd_rlimit_stat_v0 {
12845 +       uint32_t id;
12846 +       uint32_t hits;
12847 +       uint64_t value;
12848 +       uint64_t minimum;
12849 +       uint64_t maximum;
12850 +};
12851 +
12852 +#define CRLIM_UNSET            (0ULL)
12853 +#define CRLIM_INFINITY         (~0ULL)
12854 +#define CRLIM_KEEP             (~1ULL)
12855 +
12856 +#ifdef __KERNEL__
12857 +
12858 +#ifdef CONFIG_IA32_EMULATION
12859 +
12860 +struct vcmd_ctx_rlimit_v0_x32 {
12861 +       uint32_t id;
12862 +       uint64_t minimum;
12863 +       uint64_t softlimit;
12864 +       uint64_t maximum;
12865 +} __attribute__ ((packed));
12866 +
12867 +#endif /* CONFIG_IA32_EMULATION */
12868 +
12869 +#include <linux/compiler.h>
12870 +
12871 +extern int vc_get_rlimit_mask(uint32_t, void __user *);
12872 +extern int vc_get_rlimit(struct vx_info *, void __user *);
12873 +extern int vc_set_rlimit(struct vx_info *, void __user *);
12874 +extern int vc_reset_hits(struct vx_info *, void __user *);
12875 +extern int vc_reset_minmax(struct vx_info *, void __user *);
12876 +
12877 +extern int vc_rlimit_stat(struct vx_info *, void __user *);
12878 +
12879 +#ifdef CONFIG_IA32_EMULATION
12880 +
12881 +extern int vc_get_rlimit_x32(struct vx_info *, void __user *);
12882 +extern int vc_set_rlimit_x32(struct vx_info *, void __user *);
12883 +
12884 +#endif /* CONFIG_IA32_EMULATION */
12885 +
12886 +#endif /* __KERNEL__ */
12887 +#endif /* _VX_LIMIT_CMD_H */
12888 diff -NurpP --minimal linux-3.0.25/include/linux/vserver/limit_def.h linux-3.0.25-vs2.3.2.3/include/linux/vserver/limit_def.h
12889 --- linux-3.0.25/include/linux/vserver/limit_def.h      1970-01-01 01:00:00.000000000 +0100
12890 +++ linux-3.0.25-vs2.3.2.3/include/linux/vserver/limit_def.h    2011-06-10 22:11:24.000000000 +0200
12891 @@ -0,0 +1,47 @@
12892 +#ifndef _VX_LIMIT_DEF_H
12893 +#define _VX_LIMIT_DEF_H
12894 +
12895 +#include <asm/atomic.h>
12896 +#include <asm/resource.h>
12897 +
12898 +#include "limit.h"
12899 +
12900 +
12901 +struct _vx_res_limit {
12902 +       rlim_t soft;            /* Context soft limit */
12903 +       rlim_t hard;            /* Context hard limit */
12904 +
12905 +       rlim_atomic_t rcur;     /* Current value */
12906 +       rlim_t rmin;            /* Context minimum */
12907 +       rlim_t rmax;            /* Context maximum */
12908 +
12909 +       atomic_t lhit;          /* Limit hits */
12910 +};
12911 +
12912 +/* context sub struct */
12913 +
12914 +struct _vx_limit {
12915 +       struct _vx_res_limit res[NUM_LIMITS];
12916 +};
12917 +
12918 +#ifdef CONFIG_VSERVER_DEBUG
12919 +
12920 +static inline void __dump_vx_limit(struct _vx_limit *limit)
12921 +{
12922 +       int i;
12923 +
12924 +       printk("\t_vx_limit:");
12925 +       for (i = 0; i < NUM_LIMITS; i++) {
12926 +               printk("\t [%2d] = %8lu %8lu/%8lu, %8ld/%8ld, %8d\n",
12927 +                       i, (unsigned long)__rlim_get(limit, i),
12928 +                       (unsigned long)__rlim_rmin(limit, i),
12929 +                       (unsigned long)__rlim_rmax(limit, i),
12930 +                       (long)__rlim_soft(limit, i),
12931 +                       (long)__rlim_hard(limit, i),
12932 +                       atomic_read(&__rlim_lhit(limit, i)));
12933 +       }
12934 +}
12935 +
12936 +#endif
12937 +
12938 +#endif /* _VX_LIMIT_DEF_H */
12939 diff -NurpP --minimal linux-3.0.25/include/linux/vserver/limit_int.h linux-3.0.25-vs2.3.2.3/include/linux/vserver/limit_int.h
12940 --- linux-3.0.25/include/linux/vserver/limit_int.h      1970-01-01 01:00:00.000000000 +0100
12941 +++ linux-3.0.25-vs2.3.2.3/include/linux/vserver/limit_int.h    2011-06-10 22:11:24.000000000 +0200
12942 @@ -0,0 +1,198 @@
12943 +#ifndef _VX_LIMIT_INT_H
12944 +#define _VX_LIMIT_INT_H
12945 +
12946 +#include "context.h"
12947 +
12948 +#ifdef __KERNEL__
12949 +
12950 +#define VXD_RCRES_COND(r)      VXD_CBIT(cres, r)
12951 +#define VXD_RLIMIT_COND(r)     VXD_CBIT(limit, r)
12952 +
12953 +extern const char *vlimit_name[NUM_LIMITS];
12954 +
12955 +static inline void __vx_acc_cres(struct vx_info *vxi,
12956 +       int res, int dir, void *_data, char *_file, int _line)
12957 +{
12958 +       if (VXD_RCRES_COND(res))
12959 +               vxlprintk(1, "vx_acc_cres[%5d,%s,%2d]: %5ld%s (%p)",
12960 +                       (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
12961 +                       (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
12962 +                       (dir > 0) ? "++" : "--", _data, _file, _line);
12963 +       if (!vxi)
12964 +               return;
12965 +
12966 +       if (dir > 0)
12967 +               __rlim_inc(&vxi->limit, res);
12968 +       else
12969 +               __rlim_dec(&vxi->limit, res);
12970 +}
12971 +
12972 +static inline void __vx_add_cres(struct vx_info *vxi,
12973 +       int res, int amount, void *_data, char *_file, int _line)
12974 +{
12975 +       if (VXD_RCRES_COND(res))
12976 +               vxlprintk(1, "vx_add_cres[%5d,%s,%2d]: %5ld += %5d (%p)",
12977 +                       (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
12978 +                       (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
12979 +                       amount, _data, _file, _line);
12980 +       if (amount == 0)
12981 +               return;
12982 +       if (!vxi)
12983 +               return;
12984 +       __rlim_add(&vxi->limit, res, amount);
12985 +}
12986 +
12987 +static inline
12988 +int __vx_cres_adjust_max(struct _vx_limit *limit, int res, rlim_t value)
12989 +{
12990 +       int cond = (value > __rlim_rmax(limit, res));
12991 +
12992 +       if (cond)
12993 +               __rlim_rmax(limit, res) = value;
12994 +       return cond;
12995 +}
12996 +
12997 +static inline
12998 +int __vx_cres_adjust_min(struct _vx_limit *limit, int res, rlim_t value)
12999 +{
13000 +       int cond = (value < __rlim_rmin(limit, res));
13001 +
13002 +       if (cond)
13003 +               __rlim_rmin(limit, res) = value;
13004 +       return cond;
13005 +}
13006 +
13007 +static inline
13008 +void __vx_cres_fixup(struct _vx_limit *limit, int res, rlim_t value)
13009 +{
13010 +       if (!__vx_cres_adjust_max(limit, res, value))
13011 +               __vx_cres_adjust_min(limit, res, value);
13012 +}
13013 +
13014 +
13015 +/*     return values:
13016 +        +1 ... no limit hit
13017 +        -1 ... over soft limit
13018 +         0 ... over hard limit         */
13019 +
13020 +static inline int __vx_cres_avail(struct vx_info *vxi,
13021 +       int res, int num, char *_file, int _line)
13022 +{
13023 +       struct _vx_limit *limit;
13024 +       rlim_t value;
13025 +
13026 +       if (VXD_RLIMIT_COND(res))
13027 +               vxlprintk(1, "vx_cres_avail[%5d,%s,%2d]: %5ld/%5ld > %5ld + %5d",
13028 +                       (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
13029 +                       (vxi ? (long)__rlim_soft(&vxi->limit, res) : -1),
13030 +                       (vxi ? (long)__rlim_hard(&vxi->limit, res) : -1),
13031 +                       (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
13032 +                       num, _file, _line);
13033 +       if (!vxi)
13034 +               return 1;
13035 +
13036 +       limit = &vxi->limit;
13037 +       value = __rlim_get(limit, res);
13038 +
13039 +       if (!__vx_cres_adjust_max(limit, res, value))
13040 +               __vx_cres_adjust_min(limit, res, value);
13041 +
13042 +       if (num == 0)
13043 +               return 1;
13044 +
13045 +       if (__rlim_soft(limit, res) == RLIM_INFINITY)
13046 +               return -1;
13047 +       if (value + num <= __rlim_soft(limit, res))
13048 +               return -1;
13049 +
13050 +       if (__rlim_hard(limit, res) == RLIM_INFINITY)
13051 +               return 1;
13052 +       if (value + num <= __rlim_hard(limit, res))
13053 +               return 1;
13054 +
13055 +       __rlim_hit(limit, res);
13056 +       return 0;
13057 +}
13058 +
13059 +
13060 +static const int VLA_RSS[] = { RLIMIT_RSS, VLIMIT_ANON, VLIMIT_MAPPED, 0 };
13061 +
13062 +static inline
13063 +rlim_t __vx_cres_array_sum(struct _vx_limit *limit, const int *array)
13064 +{
13065 +       rlim_t value, sum = 0;
13066 +       int res;
13067 +
13068 +       while ((res = *array++)) {
13069 +               value = __rlim_get(limit, res);
13070 +               __vx_cres_fixup(limit, res, value);
13071 +               sum += value;
13072 +       }
13073 +       return sum;
13074 +}
13075 +
13076 +static inline
13077 +rlim_t __vx_cres_array_fixup(struct _vx_limit *limit, const int *array)
13078 +{
13079 +       rlim_t value = __vx_cres_array_sum(limit, array + 1);
13080 +       int res = *array;
13081 +
13082 +       if (value == __rlim_get(limit, res))
13083 +               return value;
13084 +
13085 +       __rlim_set(limit, res, value);
13086 +       /* now adjust min/max */
13087 +       if (!__vx_cres_adjust_max(limit, res, value))
13088 +               __vx_cres_adjust_min(limit, res, value);
13089 +
13090 +       return value;
13091 +}
13092 +
13093 +static inline int __vx_cres_array_avail(struct vx_info *vxi,
13094 +       const int *array, int num, char *_file, int _line)
13095 +{
13096 +       struct _vx_limit *limit;
13097 +       rlim_t value = 0;
13098 +       int res;
13099 +
13100 +       if (num == 0)
13101 +               return 1;
13102 +       if (!vxi)
13103 +               return 1;
13104 +
13105 +       limit = &vxi->limit;
13106 +       res = *array;
13107 +       value = __vx_cres_array_sum(limit, array + 1);
13108 +
13109 +       __rlim_set(limit, res, value);
13110 +       __vx_cres_fixup(limit, res, value);
13111 +
13112 +       return __vx_cres_avail(vxi, res, num, _file, _line);
13113 +}
13114 +
13115 +
13116 +static inline void vx_limit_fixup(struct _vx_limit *limit, int id)
13117 +{
13118 +       rlim_t value;
13119 +       int res;
13120 +
13121 +       /* complex resources first */
13122 +       if ((id < 0) || (id == RLIMIT_RSS))
13123 +               __vx_cres_array_fixup(limit, VLA_RSS);
13124 +
13125 +       for (res = 0; res < NUM_LIMITS; res++) {
13126 +               if ((id > 0) && (res != id))
13127 +                       continue;
13128 +
13129 +               value = __rlim_get(limit, res);
13130 +               __vx_cres_fixup(limit, res, value);
13131 +
13132 +               /* not supposed to happen, maybe warn? */
13133 +               if (__rlim_rmax(limit, res) > __rlim_hard(limit, res))
13134 +                       __rlim_rmax(limit, res) = __rlim_hard(limit, res);
13135 +       }
13136 +}
13137 +
13138 +
13139 +#endif /* __KERNEL__ */
13140 +#endif /* _VX_LIMIT_INT_H */
13141 diff -NurpP --minimal linux-3.0.25/include/linux/vserver/monitor.h linux-3.0.25-vs2.3.2.3/include/linux/vserver/monitor.h
13142 --- linux-3.0.25/include/linux/vserver/monitor.h        1970-01-01 01:00:00.000000000 +0100
13143 +++ linux-3.0.25-vs2.3.2.3/include/linux/vserver/monitor.h      2011-06-10 22:11:24.000000000 +0200
13144 @@ -0,0 +1,96 @@
13145 +#ifndef _VX_MONITOR_H
13146 +#define _VX_MONITOR_H
13147 +
13148 +#include <linux/types.h>
13149 +
13150 +enum {
13151 +       VXM_UNUSED = 0,
13152 +
13153 +       VXM_SYNC = 0x10,
13154 +
13155 +       VXM_UPDATE = 0x20,
13156 +       VXM_UPDATE_1,
13157 +       VXM_UPDATE_2,
13158 +
13159 +       VXM_RQINFO_1 = 0x24,
13160 +       VXM_RQINFO_2,
13161 +
13162 +       VXM_ACTIVATE = 0x40,
13163 +       VXM_DEACTIVATE,
13164 +       VXM_IDLE,
13165 +
13166 +       VXM_HOLD = 0x44,
13167 +       VXM_UNHOLD,
13168 +
13169 +       VXM_MIGRATE = 0x48,
13170 +       VXM_RESCHED,
13171 +
13172 +       /* all other bits are flags */
13173 +       VXM_SCHED = 0x80,
13174 +};
13175 +
13176 +struct _vxm_update_1 {
13177 +       uint32_t tokens_max;
13178 +       uint32_t fill_rate;
13179 +       uint32_t interval;
13180 +};
13181 +
13182 +struct _vxm_update_2 {
13183 +       uint32_t tokens_min;
13184 +       uint32_t fill_rate;
13185 +       uint32_t interval;
13186 +};
13187 +
13188 +struct _vxm_rqinfo_1 {
13189 +       uint16_t running;
13190 +       uint16_t onhold;
13191 +       uint16_t iowait;
13192 +       uint16_t uintr;
13193 +       uint32_t idle_tokens;
13194 +};
13195 +
13196 +struct _vxm_rqinfo_2 {
13197 +       uint32_t norm_time;
13198 +       uint32_t idle_time;
13199 +       uint32_t idle_skip;
13200 +};
13201 +
13202 +struct _vxm_sched {
13203 +       uint32_t tokens;
13204 +       uint32_t norm_time;
13205 +       uint32_t idle_time;
13206 +};
13207 +
13208 +struct _vxm_task {
13209 +       uint16_t pid;
13210 +       uint16_t state;
13211 +};
13212 +
13213 +struct _vxm_event {
13214 +       uint32_t jif;
13215 +       union {
13216 +               uint32_t seq;
13217 +               uint32_t sec;
13218 +       };
13219 +       union {
13220 +               uint32_t tokens;
13221 +               uint32_t nsec;
13222 +               struct _vxm_task tsk;
13223 +       };
13224 +};
13225 +
13226 +struct _vx_mon_entry {
13227 +       uint16_t type;
13228 +       uint16_t xid;
13229 +       union {
13230 +               struct _vxm_event ev;
13231 +               struct _vxm_sched sd;
13232 +               struct _vxm_update_1 u1;
13233 +               struct _vxm_update_2 u2;
13234 +               struct _vxm_rqinfo_1 q1;
13235 +               struct _vxm_rqinfo_2 q2;
13236 +       };
13237 +};
13238 +
13239 +
13240 +#endif /* _VX_MONITOR_H */
13241 diff -NurpP --minimal linux-3.0.25/include/linux/vserver/network.h linux-3.0.25-vs2.3.2.3/include/linux/vserver/network.h
13242 --- linux-3.0.25/include/linux/vserver/network.h        1970-01-01 01:00:00.000000000 +0100
13243 +++ linux-3.0.25-vs2.3.2.3/include/linux/vserver/network.h      2011-08-18 16:30:48.000000000 +0200
13244 @@ -0,0 +1,148 @@
13245 +#ifndef _VX_NETWORK_H
13246 +#define _VX_NETWORK_H
13247 +
13248 +#include <linux/types.h>
13249 +
13250 +
13251 +#define MAX_N_CONTEXT  65535   /* Arbitrary limit */
13252 +
13253 +
13254 +/* network flags */
13255 +
13256 +#define NXF_INFO_PRIVATE       0x00000008
13257 +
13258 +#define NXF_SINGLE_IP          0x00000100
13259 +#define NXF_LBACK_REMAP                0x00000200
13260 +#define NXF_LBACK_ALLOW                0x00000400
13261 +
13262 +#define NXF_HIDE_NETIF         0x02000000
13263 +#define NXF_HIDE_LBACK         0x04000000
13264 +
13265 +#define NXF_STATE_SETUP                (1ULL << 32)
13266 +#define NXF_STATE_ADMIN                (1ULL << 34)
13267 +
13268 +#define NXF_SC_HELPER          (1ULL << 36)
13269 +#define NXF_PERSISTENT         (1ULL << 38)
13270 +
13271 +#define NXF_ONE_TIME           (0x0005ULL << 32)
13272 +
13273 +
13274 +#define        NXF_INIT_SET            (__nxf_init_set())
13275 +
13276 +static inline uint64_t __nxf_init_set(void) {
13277 +       return    NXF_STATE_ADMIN
13278 +#ifdef CONFIG_VSERVER_AUTO_LBACK
13279 +               | NXF_LBACK_REMAP
13280 +               | NXF_HIDE_LBACK
13281 +#endif
13282 +#ifdef CONFIG_VSERVER_AUTO_SINGLE
13283 +               | NXF_SINGLE_IP
13284 +#endif
13285 +               | NXF_HIDE_NETIF;
13286 +}
13287 +
13288 +
13289 +/* network caps */
13290 +
13291 +#define NXC_TUN_CREATE         0x00000001
13292 +
13293 +#define NXC_RAW_ICMP           0x00000100
13294 +
13295 +#define NXC_MULTICAST          0x00001000
13296 +
13297 +
13298 +/* address types */
13299 +
13300 +#define NXA_TYPE_IPV4          0x0001
13301 +#define NXA_TYPE_IPV6          0x0002
13302 +
13303 +#define NXA_TYPE_NONE          0x0000
13304 +#define NXA_TYPE_ANY           0x00FF
13305 +
13306 +#define NXA_TYPE_ADDR          0x0010
13307 +#define NXA_TYPE_MASK          0x0020
13308 +#define NXA_TYPE_RANGE         0x0040
13309 +
13310 +#define NXA_MASK_ALL           (NXA_TYPE_ADDR | NXA_TYPE_MASK | NXA_TYPE_RANGE)
13311 +
13312 +#define NXA_MOD_BCAST          0x0100
13313 +#define NXA_MOD_LBACK          0x0200
13314 +
13315 +#define NXA_LOOPBACK           0x1000
13316 +
13317 +#define NXA_MASK_BIND          (NXA_MASK_ALL | NXA_MOD_BCAST | NXA_MOD_LBACK)
13318 +#define NXA_MASK_SHOW          (NXA_MASK_ALL | NXA_LOOPBACK)
13319 +
13320 +#ifdef __KERNEL__
13321 +
13322 +#include <linux/list.h>
13323 +#include <linux/spinlock.h>
13324 +#include <linux/rcupdate.h>
13325 +#include <linux/in.h>
13326 +#include <linux/in6.h>
13327 +#include <asm/atomic.h>
13328 +
13329 +struct nx_addr_v4 {
13330 +       struct nx_addr_v4 *next;
13331 +       struct in_addr ip[2];
13332 +       struct in_addr mask;
13333 +       uint16_t type;
13334 +       uint16_t flags;
13335 +};
13336 +
13337 +struct nx_addr_v6 {
13338 +       struct nx_addr_v6 *next;
13339 +       struct in6_addr ip;
13340 +       struct in6_addr mask;
13341 +       uint32_t prefix;
13342 +       uint16_t type;
13343 +       uint16_t flags;
13344 +};
13345 +
13346 +struct nx_info {
13347 +       struct hlist_node nx_hlist;     /* linked list of nxinfos */
13348 +       nid_t nx_id;                    /* vnet id */
13349 +       atomic_t nx_usecnt;             /* usage count */
13350 +       atomic_t nx_tasks;              /* tasks count */
13351 +       int nx_state;                   /* context state */
13352 +
13353 +       uint64_t nx_flags;              /* network flag word */
13354 +       uint64_t nx_ncaps;              /* network capabilities */
13355 +
13356 +       struct in_addr v4_lback;        /* Loopback address */
13357 +       struct in_addr v4_bcast;        /* Broadcast address */
13358 +       struct nx_addr_v4 v4;           /* First/Single ipv4 address */
13359 +#ifdef CONFIG_IPV6
13360 +       struct nx_addr_v6 v6;           /* First/Single ipv6 address */
13361 +#endif
13362 +       char nx_name[65];               /* network context name */
13363 +};
13364 +
13365 +
13366 +/* status flags */
13367 +
13368 +#define NXS_HASHED      0x0001
13369 +#define NXS_SHUTDOWN    0x0100
13370 +#define NXS_RELEASED    0x8000
13371 +
13372 +extern struct nx_info *lookup_nx_info(int);
13373 +
13374 +extern int get_nid_list(int, unsigned int *, int);
13375 +extern int nid_is_hashed(nid_t);
13376 +
13377 +extern int nx_migrate_task(struct task_struct *, struct nx_info *);
13378 +
13379 +extern long vs_net_change(struct nx_info *, unsigned int);
13380 +
13381 +struct sock;
13382 +
13383 +
13384 +#define NX_IPV4(n)     ((n)->v4.type != NXA_TYPE_NONE)
13385 +#ifdef  CONFIG_IPV6
13386 +#define NX_IPV6(n)     ((n)->v6.type != NXA_TYPE_NONE)
13387 +#else
13388 +#define NX_IPV6(n)     (0)
13389 +#endif
13390 +
13391 +#endif /* __KERNEL__ */
13392 +#endif /* _VX_NETWORK_H */
13393 diff -NurpP --minimal linux-3.0.25/include/linux/vserver/network_cmd.h linux-3.0.25-vs2.3.2.3/include/linux/vserver/network_cmd.h
13394 --- linux-3.0.25/include/linux/vserver/network_cmd.h    1970-01-01 01:00:00.000000000 +0100
13395 +++ linux-3.0.25-vs2.3.2.3/include/linux/vserver/network_cmd.h  2011-06-10 22:11:24.000000000 +0200
13396 @@ -0,0 +1,164 @@
13397 +#ifndef _VX_NETWORK_CMD_H
13398 +#define _VX_NETWORK_CMD_H
13399 +
13400 +
13401 +/* vinfo commands */
13402 +
13403 +#define VCMD_task_nid          VC_CMD(VINFO, 2, 0)
13404 +
13405 +#ifdef __KERNEL__
13406 +extern int vc_task_nid(uint32_t);
13407 +
13408 +#endif /* __KERNEL__ */
13409 +
13410 +#define VCMD_nx_info           VC_CMD(VINFO, 6, 0)
13411 +
13412 +struct vcmd_nx_info_v0 {
13413 +       uint32_t nid;
13414 +       /* more to come */
13415 +};
13416 +
13417 +#ifdef __KERNEL__
13418 +extern int vc_nx_info(struct nx_info *, void __user *);
13419 +
13420 +#endif /* __KERNEL__ */
13421 +
13422 +#include <linux/in.h>
13423 +#include <linux/in6.h>
13424 +
13425 +#define VCMD_net_create_v0     VC_CMD(VNET, 1, 0)
13426 +#define VCMD_net_create                VC_CMD(VNET, 1, 1)
13427 +
13428 +struct  vcmd_net_create {
13429 +       uint64_t flagword;
13430 +};
13431 +
13432 +#define VCMD_net_migrate       VC_CMD(NETMIG, 1, 0)
13433 +
13434 +#define VCMD_net_add           VC_CMD(NETALT, 1, 0)
13435 +#define VCMD_net_remove                VC_CMD(NETALT, 2, 0)
13436 +
13437 +struct vcmd_net_addr_v0 {
13438 +       uint16_t type;
13439 +       uint16_t count;
13440 +       struct in_addr ip[4];
13441 +       struct in_addr mask[4];
13442 +};
13443 +
13444 +#define VCMD_net_add_ipv4_v1   VC_CMD(NETALT, 1, 1)
13445 +#define VCMD_net_rem_ipv4_v1   VC_CMD(NETALT, 2, 1)
13446 +
13447 +struct vcmd_net_addr_ipv4_v1 {
13448 +       uint16_t type;
13449 +       uint16_t flags;
13450 +       struct in_addr ip;
13451 +       struct in_addr mask;
13452 +};
13453 +
13454 +#define VCMD_net_add_ipv4      VC_CMD(NETALT, 1, 2)
13455 +#define VCMD_net_rem_ipv4      VC_CMD(NETALT, 2, 2)
13456 +
13457 +struct vcmd_net_addr_ipv4_v2 {
13458 +       uint16_t type;
13459 +       uint16_t flags;
13460 +       struct in_addr ip;
13461 +       struct in_addr ip2;
13462 +       struct in_addr mask;
13463 +};
13464 +
13465 +#define VCMD_net_add_ipv6      VC_CMD(NETALT, 3, 1)
13466 +#define VCMD_net_remove_ipv6   VC_CMD(NETALT, 4, 1)
13467 +
13468 +struct vcmd_net_addr_ipv6_v1 {
13469 +       uint16_t type;
13470 +       uint16_t flags;
13471 +       uint32_t prefix;
13472 +       struct in6_addr ip;
13473 +       struct in6_addr mask;
13474 +};
13475 +
13476 +#define VCMD_add_match_ipv4    VC_CMD(NETALT, 5, 0)
13477 +#define VCMD_get_match_ipv4    VC_CMD(NETALT, 6, 0)
13478 +
13479 +struct vcmd_match_ipv4_v0 {
13480 +       uint16_t type;
13481 +       uint16_t flags;
13482 +       uint16_t parent;
13483 +       uint16_t prefix;
13484 +       struct in_addr ip;
13485 +       struct in_addr ip2;
13486 +       struct in_addr mask;
13487 +};
13488 +
13489 +#define VCMD_add_match_ipv6    VC_CMD(NETALT, 7, 0)
13490 +#define VCMD_get_match_ipv6    VC_CMD(NETALT, 8, 0)
13491 +
13492 +struct vcmd_match_ipv6_v0 {
13493 +       uint16_t type;
13494 +       uint16_t flags;
13495 +       uint16_t parent;
13496 +       uint16_t prefix;
13497 +       struct in6_addr ip;
13498 +       struct in6_addr ip2;
13499 +       struct in6_addr mask;
13500 +};
13501 +
13502 +
13503 +#ifdef __KERNEL__
13504 +extern int vc_net_create(uint32_t, void __user *);
13505 +extern int vc_net_migrate(struct nx_info *, void __user *);
13506 +
13507 +extern int vc_net_add(struct nx_info *, void __user *);
13508 +extern int vc_net_remove(struct nx_info *, void __user *);
13509 +
13510 +extern int vc_net_add_ipv4_v1(struct nx_info *, void __user *);
13511 +extern int vc_net_add_ipv4(struct nx_info *, void __user *);
13512 +
13513 +extern int vc_net_rem_ipv4_v1(struct nx_info *, void __user *);
13514 +extern int vc_net_rem_ipv4(struct nx_info *, void __user *);
13515 +
13516 +extern int vc_net_add_ipv6(struct nx_info *, void __user *);
13517 +extern int vc_net_remove_ipv6(struct nx_info *, void __user *);
13518 +
13519 +extern int vc_add_match_ipv4(struct nx_info *, void __user *);
13520 +extern int vc_get_match_ipv4(struct nx_info *, void __user *);
13521 +
13522 +extern int vc_add_match_ipv6(struct nx_info *, void __user *);
13523 +extern int vc_get_match_ipv6(struct nx_info *, void __user *);
13524 +
13525 +#endif /* __KERNEL__ */
13526 +
13527 +
13528 +/* flag commands */
13529 +
13530 +#define VCMD_get_nflags                VC_CMD(FLAGS, 5, 0)
13531 +#define VCMD_set_nflags                VC_CMD(FLAGS, 6, 0)
13532 +
13533 +struct vcmd_net_flags_v0 {
13534 +       uint64_t flagword;
13535 +       uint64_t mask;
13536 +};
13537 +
13538 +#ifdef __KERNEL__
13539 +extern int vc_get_nflags(struct nx_info *, void __user *);
13540 +extern int vc_set_nflags(struct nx_info *, void __user *);
13541 +
13542 +#endif /* __KERNEL__ */
13543 +
13544 +
13545 +/* network caps commands */
13546 +
13547 +#define VCMD_get_ncaps         VC_CMD(FLAGS, 7, 0)
13548 +#define VCMD_set_ncaps         VC_CMD(FLAGS, 8, 0)
13549 +
13550 +struct vcmd_net_caps_v0 {
13551 +       uint64_t ncaps;
13552 +       uint64_t cmask;
13553 +};
13554 +
13555 +#ifdef __KERNEL__
13556 +extern int vc_get_ncaps(struct nx_info *, void __user *);
13557 +extern int vc_set_ncaps(struct nx_info *, void __user *);
13558 +
13559 +#endif /* __KERNEL__ */
13560 +#endif /* _VX_CONTEXT_CMD_H */
13561 diff -NurpP --minimal linux-3.0.25/include/linux/vserver/percpu.h linux-3.0.25-vs2.3.2.3/include/linux/vserver/percpu.h
13562 --- linux-3.0.25/include/linux/vserver/percpu.h 1970-01-01 01:00:00.000000000 +0100
13563 +++ linux-3.0.25-vs2.3.2.3/include/linux/vserver/percpu.h       2011-06-10 22:11:24.000000000 +0200
13564 @@ -0,0 +1,14 @@
13565 +#ifndef _VX_PERCPU_H
13566 +#define _VX_PERCPU_H
13567 +
13568 +#include "cvirt_def.h"
13569 +#include "sched_def.h"
13570 +
13571 +struct _vx_percpu {
13572 +       struct _vx_cvirt_pc cvirt;
13573 +       struct _vx_sched_pc sched;
13574 +};
13575 +
13576 +#define        PERCPU_PERCTX   (sizeof(struct _vx_percpu))
13577 +
13578 +#endif /* _VX_PERCPU_H */
13579 diff -NurpP --minimal linux-3.0.25/include/linux/vserver/pid.h linux-3.0.25-vs2.3.2.3/include/linux/vserver/pid.h
13580 --- linux-3.0.25/include/linux/vserver/pid.h    1970-01-01 01:00:00.000000000 +0100
13581 +++ linux-3.0.25-vs2.3.2.3/include/linux/vserver/pid.h  2011-06-10 22:11:24.000000000 +0200
13582 @@ -0,0 +1,51 @@
13583 +#ifndef _VSERVER_PID_H
13584 +#define _VSERVER_PID_H
13585 +
13586 +/* pid faking stuff */
13587 +
13588 +#define vx_info_map_pid(v, p) \
13589 +       __vx_info_map_pid((v), (p), __func__, __FILE__, __LINE__)
13590 +#define vx_info_map_tgid(v,p)  vx_info_map_pid(v,p)
13591 +#define vx_map_pid(p) vx_info_map_pid(current_vx_info(), p)
13592 +#define vx_map_tgid(p) vx_map_pid(p)
13593 +
13594 +static inline int __vx_info_map_pid(struct vx_info *vxi, int pid,
13595 +       const char *func, const char *file, int line)
13596 +{
13597 +       if (vx_info_flags(vxi, VXF_INFO_INIT, 0)) {
13598 +               vxfprintk(VXD_CBIT(cvirt, 2),
13599 +                       "vx_map_tgid: %p/%llx: %d -> %d",
13600 +                       vxi, (long long)vxi->vx_flags, pid,
13601 +                       (pid && pid == vxi->vx_initpid) ? 1 : pid,
13602 +                       func, file, line);
13603 +               if (pid == 0)
13604 +                       return 0;
13605 +               if (pid == vxi->vx_initpid)
13606 +                       return 1;
13607 +       }
13608 +       return pid;
13609 +}
13610 +
13611 +#define vx_info_rmap_pid(v, p) \
13612 +       __vx_info_rmap_pid((v), (p), __func__, __FILE__, __LINE__)
13613 +#define vx_rmap_pid(p) vx_info_rmap_pid(current_vx_info(), p)
13614 +#define vx_rmap_tgid(p) vx_rmap_pid(p)
13615 +
13616 +static inline int __vx_info_rmap_pid(struct vx_info *vxi, int pid,
13617 +       const char *func, const char *file, int line)
13618 +{
13619 +       if (vx_info_flags(vxi, VXF_INFO_INIT, 0)) {
13620 +               vxfprintk(VXD_CBIT(cvirt, 2),
13621 +                       "vx_rmap_tgid: %p/%llx: %d -> %d",
13622 +                       vxi, (long long)vxi->vx_flags, pid,
13623 +                       (pid == 1) ? vxi->vx_initpid : pid,
13624 +                       func, file, line);
13625 +               if ((pid == 1) && vxi->vx_initpid)
13626 +                       return vxi->vx_initpid;
13627 +               if (pid == vxi->vx_initpid)
13628 +                       return ~0U;
13629 +       }
13630 +       return pid;
13631 +}
13632 +
13633 +#endif
13634 diff -NurpP --minimal linux-3.0.25/include/linux/vserver/sched.h linux-3.0.25-vs2.3.2.3/include/linux/vserver/sched.h
13635 --- linux-3.0.25/include/linux/vserver/sched.h  1970-01-01 01:00:00.000000000 +0100
13636 +++ linux-3.0.25-vs2.3.2.3/include/linux/vserver/sched.h        2011-06-10 22:11:24.000000000 +0200
13637 @@ -0,0 +1,23 @@
13638 +#ifndef _VX_SCHED_H
13639 +#define _VX_SCHED_H
13640 +
13641 +
13642 +#ifdef __KERNEL__
13643 +
13644 +struct timespec;
13645 +
13646 +void vx_vsi_uptime(struct timespec *, struct timespec *);
13647 +
13648 +
13649 +struct vx_info;
13650 +
13651 +void vx_update_load(struct vx_info *);
13652 +
13653 +
13654 +void vx_update_sched_param(struct _vx_sched *sched,
13655 +       struct _vx_sched_pc *sched_pc);
13656 +
13657 +#endif /* __KERNEL__ */
13658 +#else  /* _VX_SCHED_H */
13659 +#warning duplicate inclusion
13660 +#endif /* _VX_SCHED_H */
13661 diff -NurpP --minimal linux-3.0.25/include/linux/vserver/sched_cmd.h linux-3.0.25-vs2.3.2.3/include/linux/vserver/sched_cmd.h
13662 --- linux-3.0.25/include/linux/vserver/sched_cmd.h      1970-01-01 01:00:00.000000000 +0100
13663 +++ linux-3.0.25-vs2.3.2.3/include/linux/vserver/sched_cmd.h    2011-06-10 22:11:24.000000000 +0200
13664 @@ -0,0 +1,21 @@
13665 +#ifndef _VX_SCHED_CMD_H
13666 +#define _VX_SCHED_CMD_H
13667 +
13668 +
13669 +struct vcmd_prio_bias {
13670 +       int32_t cpu_id;
13671 +       int32_t prio_bias;
13672 +};
13673 +
13674 +#define VCMD_set_prio_bias     VC_CMD(SCHED, 4, 0)
13675 +#define VCMD_get_prio_bias     VC_CMD(SCHED, 5, 0)
13676 +
13677 +#ifdef __KERNEL__
13678 +
13679 +#include <linux/compiler.h>
13680 +
13681 +extern int vc_set_prio_bias(struct vx_info *, void __user *);
13682 +extern int vc_get_prio_bias(struct vx_info *, void __user *);
13683 +
13684 +#endif /* __KERNEL__ */
13685 +#endif /* _VX_SCHED_CMD_H */
13686 diff -NurpP --minimal linux-3.0.25/include/linux/vserver/sched_def.h linux-3.0.25-vs2.3.2.3/include/linux/vserver/sched_def.h
13687 --- linux-3.0.25/include/linux/vserver/sched_def.h      1970-01-01 01:00:00.000000000 +0100
13688 +++ linux-3.0.25-vs2.3.2.3/include/linux/vserver/sched_def.h    2011-06-10 22:11:24.000000000 +0200
13689 @@ -0,0 +1,38 @@
13690 +#ifndef _VX_SCHED_DEF_H
13691 +#define _VX_SCHED_DEF_H
13692 +
13693 +#include <linux/spinlock.h>
13694 +#include <linux/jiffies.h>
13695 +#include <linux/cpumask.h>
13696 +#include <asm/atomic.h>
13697 +#include <asm/param.h>
13698 +
13699 +
13700 +/* context sub struct */
13701 +
13702 +struct _vx_sched {
13703 +       int prio_bias;                  /* bias offset for priority */
13704 +
13705 +       cpumask_t update;               /* CPUs which should update */
13706 +};
13707 +
13708 +struct _vx_sched_pc {
13709 +       int prio_bias;                  /* bias offset for priority */
13710 +
13711 +       uint64_t user_ticks;            /* token tick events */
13712 +       uint64_t sys_ticks;             /* token tick events */
13713 +       uint64_t hold_ticks;            /* token ticks paused */
13714 +};
13715 +
13716 +
13717 +#ifdef CONFIG_VSERVER_DEBUG
13718 +
13719 +static inline void __dump_vx_sched(struct _vx_sched *sched)
13720 +{
13721 +       printk("\t_vx_sched:\n");
13722 +       printk("\t priority = %4d\n", sched->prio_bias);
13723 +}
13724 +
13725 +#endif
13726 +
13727 +#endif /* _VX_SCHED_DEF_H */
13728 diff -NurpP --minimal linux-3.0.25/include/linux/vserver/signal.h linux-3.0.25-vs2.3.2.3/include/linux/vserver/signal.h
13729 --- linux-3.0.25/include/linux/vserver/signal.h 1970-01-01 01:00:00.000000000 +0100
13730 +++ linux-3.0.25-vs2.3.2.3/include/linux/vserver/signal.h       2011-06-10 22:11:24.000000000 +0200
13731 @@ -0,0 +1,14 @@
13732 +#ifndef _VX_SIGNAL_H
13733 +#define _VX_SIGNAL_H
13734 +
13735 +
13736 +#ifdef __KERNEL__
13737 +
13738 +struct vx_info;
13739 +
13740 +int vx_info_kill(struct vx_info *, int, int);
13741 +
13742 +#endif /* __KERNEL__ */
13743 +#else  /* _VX_SIGNAL_H */
13744 +#warning duplicate inclusion
13745 +#endif /* _VX_SIGNAL_H */
13746 diff -NurpP --minimal linux-3.0.25/include/linux/vserver/signal_cmd.h linux-3.0.25-vs2.3.2.3/include/linux/vserver/signal_cmd.h
13747 --- linux-3.0.25/include/linux/vserver/signal_cmd.h     1970-01-01 01:00:00.000000000 +0100
13748 +++ linux-3.0.25-vs2.3.2.3/include/linux/vserver/signal_cmd.h   2011-06-10 22:11:24.000000000 +0200
13749 @@ -0,0 +1,43 @@
13750 +#ifndef _VX_SIGNAL_CMD_H
13751 +#define _VX_SIGNAL_CMD_H
13752 +
13753 +
13754 +/*  signalling vserver commands */
13755 +
13756 +#define VCMD_ctx_kill          VC_CMD(PROCTRL, 1, 0)
13757 +#define VCMD_wait_exit         VC_CMD(EVENT, 99, 0)
13758 +
13759 +struct vcmd_ctx_kill_v0 {
13760 +       int32_t pid;
13761 +       int32_t sig;
13762 +};
13763 +
13764 +struct vcmd_wait_exit_v0 {
13765 +       int32_t reboot_cmd;
13766 +       int32_t exit_code;
13767 +};
13768 +
13769 +#ifdef __KERNEL__
13770 +
13771 +extern int vc_ctx_kill(struct vx_info *, void __user *);
13772 +extern int vc_wait_exit(struct vx_info *, void __user *);
13773 +
13774 +#endif /* __KERNEL__ */
13775 +
13776 +/*  process alteration commands */
13777 +
13778 +#define VCMD_get_pflags                VC_CMD(PROCALT, 5, 0)
13779 +#define VCMD_set_pflags                VC_CMD(PROCALT, 6, 0)
13780 +
13781 +struct vcmd_pflags_v0 {
13782 +       uint32_t flagword;
13783 +       uint32_t mask;
13784 +};
13785 +
13786 +#ifdef __KERNEL__
13787 +
13788 +extern int vc_get_pflags(uint32_t pid, void __user *);
13789 +extern int vc_set_pflags(uint32_t pid, void __user *);
13790 +
13791 +#endif /* __KERNEL__ */
13792 +#endif /* _VX_SIGNAL_CMD_H */
13793 diff -NurpP --minimal linux-3.0.25/include/linux/vserver/space.h linux-3.0.25-vs2.3.2.3/include/linux/vserver/space.h
13794 --- linux-3.0.25/include/linux/vserver/space.h  1970-01-01 01:00:00.000000000 +0100
13795 +++ linux-3.0.25-vs2.3.2.3/include/linux/vserver/space.h        2011-06-10 22:11:24.000000000 +0200
13796 @@ -0,0 +1,12 @@
13797 +#ifndef _VX_SPACE_H
13798 +#define _VX_SPACE_H
13799 +
13800 +#include <linux/types.h>
13801 +
13802 +struct vx_info;
13803 +
13804 +int vx_set_space(struct vx_info *vxi, unsigned long mask, unsigned index);
13805 +
13806 +#else  /* _VX_SPACE_H */
13807 +#warning duplicate inclusion
13808 +#endif /* _VX_SPACE_H */
13809 diff -NurpP --minimal linux-3.0.25/include/linux/vserver/space_cmd.h linux-3.0.25-vs2.3.2.3/include/linux/vserver/space_cmd.h
13810 --- linux-3.0.25/include/linux/vserver/space_cmd.h      1970-01-01 01:00:00.000000000 +0100
13811 +++ linux-3.0.25-vs2.3.2.3/include/linux/vserver/space_cmd.h    2011-06-10 22:11:24.000000000 +0200
13812 @@ -0,0 +1,38 @@
13813 +#ifndef _VX_SPACE_CMD_H
13814 +#define _VX_SPACE_CMD_H
13815 +
13816 +
13817 +#define VCMD_enter_space_v0    VC_CMD(PROCALT, 1, 0)
13818 +#define VCMD_enter_space_v1    VC_CMD(PROCALT, 1, 1)
13819 +#define VCMD_enter_space       VC_CMD(PROCALT, 1, 2)
13820 +
13821 +#define VCMD_set_space_v0      VC_CMD(PROCALT, 3, 0)
13822 +#define VCMD_set_space_v1      VC_CMD(PROCALT, 3, 1)
13823 +#define VCMD_set_space         VC_CMD(PROCALT, 3, 2)
13824 +
13825 +#define VCMD_get_space_mask_v0 VC_CMD(PROCALT, 4, 0)
13826 +
13827 +#define VCMD_get_space_mask    VC_CMD(VSPACE, 0, 1)
13828 +#define VCMD_get_space_default VC_CMD(VSPACE, 1, 0)
13829 +
13830 +
13831 +struct vcmd_space_mask_v1 {
13832 +       uint64_t mask;
13833 +};
13834 +
13835 +struct vcmd_space_mask_v2 {
13836 +       uint64_t mask;
13837 +       uint32_t index;
13838 +};
13839 +
13840 +
13841 +#ifdef __KERNEL__
13842 +
13843 +extern int vc_enter_space_v1(struct vx_info *, void __user *);
13844 +extern int vc_set_space_v1(struct vx_info *, void __user *);
13845 +extern int vc_enter_space(struct vx_info *, void __user *);
13846 +extern int vc_set_space(struct vx_info *, void __user *);
13847 +extern int vc_get_space_mask(void __user *, int);
13848 +
13849 +#endif /* __KERNEL__ */
13850 +#endif /* _VX_SPACE_CMD_H */
13851 diff -NurpP --minimal linux-3.0.25/include/linux/vserver/switch.h linux-3.0.25-vs2.3.2.3/include/linux/vserver/switch.h
13852 --- linux-3.0.25/include/linux/vserver/switch.h 1970-01-01 01:00:00.000000000 +0100
13853 +++ linux-3.0.25-vs2.3.2.3/include/linux/vserver/switch.h       2011-06-10 22:11:24.000000000 +0200
13854 @@ -0,0 +1,98 @@
13855 +#ifndef _VX_SWITCH_H
13856 +#define _VX_SWITCH_H
13857 +
13858 +#include <linux/types.h>
13859 +
13860 +
13861 +#define VC_CATEGORY(c)         (((c) >> 24) & 0x3F)
13862 +#define VC_COMMAND(c)          (((c) >> 16) & 0xFF)
13863 +#define VC_VERSION(c)          ((c) & 0xFFF)
13864 +
13865 +#define VC_CMD(c, i, v)                ((((VC_CAT_ ## c) & 0x3F) << 24) \
13866 +                               | (((i) & 0xFF) << 16) | ((v) & 0xFFF))
13867 +
13868 +/*
13869 +
13870 +  Syscall Matrix V2.8
13871 +
13872 +        |VERSION|CREATE |MODIFY |MIGRATE|CONTROL|EXPERIM| |SPECIAL|SPECIAL|
13873 +        |STATS  |DESTROY|ALTER  |CHANGE |LIMIT  |TEST   | |       |       |
13874 +        |INFO   |SETUP  |       |MOVE   |       |       | |       |       |
13875 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13876 +  SYSTEM |VERSION|VSETUP |VHOST  |       |       |       | |DEVICE |       |
13877 +  HOST   |     00|     01|     02|     03|     04|     05| |     06|     07|
13878 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13879 +  CPU    |       |VPROC  |PROCALT|PROCMIG|PROCTRL|       | |SCHED. |       |
13880 +  PROCESS|     08|     09|     10|     11|     12|     13| |     14|     15|
13881 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13882 +  MEMORY |       |       |       |       |MEMCTRL|       | |SWAP   |       |
13883 +        |     16|     17|     18|     19|     20|     21| |     22|     23|
13884 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13885 +  NETWORK|       |VNET   |NETALT |NETMIG |NETCTL |       | |SERIAL |       |
13886 +        |     24|     25|     26|     27|     28|     29| |     30|     31|
13887 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13888 +  DISK   |       |       |       |TAGMIG |DLIMIT |       | |INODE  |       |
13889 +  VFS    |     32|     33|     34|     35|     36|     37| |     38|     39|
13890 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13891 +  OTHER  |VSTAT  |       |       |       |       |       | |VINFO  |       |
13892 +        |     40|     41|     42|     43|     44|     45| |     46|     47|
13893 +  =======+=======+=======+=======+=======+=======+=======+ +=======+=======+
13894 +  SPECIAL|EVENT  |       |       |       |FLAGS  |       | |VSPACE |       |
13895 +        |     48|     49|     50|     51|     52|     53| |     54|     55|
13896 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13897 +  SPECIAL|DEBUG  |       |       |       |RLIMIT |SYSCALL| |       |COMPAT |
13898 +        |     56|     57|     58|     59|     60|TEST 61| |     62|     63|
13899 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13900 +
13901 +*/
13902 +
13903 +#define VC_CAT_VERSION         0
13904 +
13905 +#define VC_CAT_VSETUP          1
13906 +#define VC_CAT_VHOST           2
13907 +
13908 +#define VC_CAT_DEVICE          6
13909 +
13910 +#define VC_CAT_VPROC           9
13911 +#define VC_CAT_PROCALT         10
13912 +#define VC_CAT_PROCMIG         11
13913 +#define VC_CAT_PROCTRL         12
13914 +
13915 +#define VC_CAT_SCHED           14
13916 +#define VC_CAT_MEMCTRL         20
13917 +
13918 +#define VC_CAT_VNET            25
13919 +#define VC_CAT_NETALT          26
13920 +#define VC_CAT_NETMIG          27
13921 +#define VC_CAT_NETCTRL         28
13922 +
13923 +#define VC_CAT_TAGMIG          35
13924 +#define VC_CAT_DLIMIT          36
13925 +#define VC_CAT_INODE           38
13926 +
13927 +#define VC_CAT_VSTAT           40
13928 +#define VC_CAT_VINFO           46
13929 +#define VC_CAT_EVENT           48
13930 +
13931 +#define VC_CAT_FLAGS           52
13932 +#define VC_CAT_VSPACE          54
13933 +#define VC_CAT_DEBUG           56
13934 +#define VC_CAT_RLIMIT          60
13935 +
13936 +#define VC_CAT_SYSTEST         61
13937 +#define VC_CAT_COMPAT          63
13938 +
13939 +/*  query version */
13940 +
13941 +#define VCMD_get_version       VC_CMD(VERSION, 0, 0)
13942 +#define VCMD_get_vci           VC_CMD(VERSION, 1, 0)
13943 +
13944 +
13945 +#ifdef __KERNEL__
13946 +
13947 +#include <linux/errno.h>
13948 +
13949 +#endif /* __KERNEL__ */
13950 +
13951 +#endif /* _VX_SWITCH_H */
13952 +
13953 diff -NurpP --minimal linux-3.0.25/include/linux/vserver/tag.h linux-3.0.25-vs2.3.2.3/include/linux/vserver/tag.h
13954 --- linux-3.0.25/include/linux/vserver/tag.h    1970-01-01 01:00:00.000000000 +0100
13955 +++ linux-3.0.25-vs2.3.2.3/include/linux/vserver/tag.h  2011-06-10 22:11:24.000000000 +0200
13956 @@ -0,0 +1,143 @@
13957 +#ifndef _DX_TAG_H
13958 +#define _DX_TAG_H
13959 +
13960 +#include <linux/types.h>
13961 +
13962 +
13963 +#define DX_TAG(in)     (IS_TAGGED(in))
13964 +
13965 +
13966 +#ifdef CONFIG_TAG_NFSD
13967 +#define DX_TAG_NFSD    1
13968 +#else
13969 +#define DX_TAG_NFSD    0
13970 +#endif
13971 +
13972 +
13973 +#ifdef CONFIG_TAGGING_NONE
13974 +
13975 +#define MAX_UID                0xFFFFFFFF
13976 +#define MAX_GID                0xFFFFFFFF
13977 +
13978 +#define INOTAG_TAG(cond, uid, gid, tag)        (0)
13979 +
13980 +#define TAGINO_UID(cond, uid, tag)     (uid)
13981 +#define TAGINO_GID(cond, gid, tag)     (gid)
13982 +
13983 +#endif
13984 +
13985 +
13986 +#ifdef CONFIG_TAGGING_GID16
13987 +
13988 +#define MAX_UID                0xFFFFFFFF
13989 +#define MAX_GID                0x0000FFFF
13990 +
13991 +#define INOTAG_TAG(cond, uid, gid, tag)        \
13992 +       ((cond) ? (((gid) >> 16) & 0xFFFF) : 0)
13993 +
13994 +#define TAGINO_UID(cond, uid, tag)     (uid)
13995 +#define TAGINO_GID(cond, gid, tag)     \
13996 +       ((cond) ? (((gid) & 0xFFFF) | ((tag) << 16)) : (gid))
13997 +
13998 +#endif
13999 +
14000 +
14001 +#ifdef CONFIG_TAGGING_ID24
14002 +
14003 +#define MAX_UID                0x00FFFFFF
14004 +#define MAX_GID                0x00FFFFFF
14005 +
14006 +#define INOTAG_TAG(cond, uid, gid, tag)        \
14007 +       ((cond) ? ((((uid) >> 16) & 0xFF00) | (((gid) >> 24) & 0xFF)) : 0)
14008 +
14009 +#define TAGINO_UID(cond, uid, tag)     \
14010 +       ((cond) ? (((uid) & 0xFFFFFF) | (((tag) & 0xFF00) << 16)) : (uid))
14011 +#define TAGINO_GID(cond, gid, tag)     \
14012 +       ((cond) ? (((gid) & 0xFFFFFF) | (((tag) & 0x00FF) << 24)) : (gid))
14013 +
14014 +#endif
14015 +
14016 +
14017 +#ifdef CONFIG_TAGGING_UID16
14018 +
14019 +#define MAX_UID                0x0000FFFF
14020 +#define MAX_GID                0xFFFFFFFF
14021 +
14022 +#define INOTAG_TAG(cond, uid, gid, tag)        \
14023 +       ((cond) ? (((uid) >> 16) & 0xFFFF) : 0)
14024 +
14025 +#define TAGINO_UID(cond, uid, tag)     \
14026 +       ((cond) ? (((uid) & 0xFFFF) | ((tag) << 16)) : (uid))
14027 +#define TAGINO_GID(cond, gid, tag)     (gid)
14028 +
14029 +#endif
14030 +
14031 +
14032 +#ifdef CONFIG_TAGGING_INTERN
14033 +
14034 +#define MAX_UID                0xFFFFFFFF
14035 +#define MAX_GID                0xFFFFFFFF
14036 +
14037 +#define INOTAG_TAG(cond, uid, gid, tag)        \
14038 +       ((cond) ? (tag) : 0)
14039 +
14040 +#define TAGINO_UID(cond, uid, tag)     (uid)
14041 +#define TAGINO_GID(cond, gid, tag)     (gid)
14042 +
14043 +#endif
14044 +
14045 +
14046 +#ifndef CONFIG_TAGGING_NONE
14047 +#define dx_current_fstag(sb)   \
14048 +       ((sb)->s_flags & MS_TAGGED ? dx_current_tag() : 0)
14049 +#else
14050 +#define dx_current_fstag(sb)   (0)
14051 +#endif
14052 +
14053 +#ifndef CONFIG_TAGGING_INTERN
14054 +#define TAGINO_TAG(cond, tag)  (0)
14055 +#else
14056 +#define TAGINO_TAG(cond, tag)  ((cond) ? (tag) : 0)
14057 +#endif
14058 +
14059 +#define INOTAG_UID(cond, uid, gid)     \
14060 +       ((cond) ? ((uid) & MAX_UID) : (uid))
14061 +#define INOTAG_GID(cond, uid, gid)     \
14062 +       ((cond) ? ((gid) & MAX_GID) : (gid))
14063 +
14064 +
14065 +static inline uid_t dx_map_uid(uid_t uid)
14066 +{
14067 +       if ((uid > MAX_UID) && (uid != -1))
14068 +               uid = -2;
14069 +       return (uid & MAX_UID);
14070 +}
14071 +
14072 +static inline gid_t dx_map_gid(gid_t gid)
14073 +{
14074 +       if ((gid > MAX_GID) && (gid != -1))
14075 +               gid = -2;
14076 +       return (gid & MAX_GID);
14077 +}
14078 +
14079 +struct peer_tag {
14080 +       int32_t xid;
14081 +       int32_t nid;
14082 +};
14083 +
14084 +#define dx_notagcheck(sb) ((sb) && ((sb)->s_flags & MS_NOTAGCHECK))
14085 +
14086 +int dx_parse_tag(char *string, tag_t *tag, int remove, int *mnt_flags,
14087 +                unsigned long *flags);
14088 +
14089 +#ifdef CONFIG_PROPAGATE
14090 +
14091 +void __dx_propagate_tag(struct nameidata *nd, struct inode *inode);
14092 +
14093 +#define dx_propagate_tag(n, i) __dx_propagate_tag(n, i)
14094 +
14095 +#else
14096 +#define dx_propagate_tag(n, i) do { } while (0)
14097 +#endif
14098 +
14099 +#endif /* _DX_TAG_H */
14100 diff -NurpP --minimal linux-3.0.25/include/linux/vserver/tag_cmd.h linux-3.0.25-vs2.3.2.3/include/linux/vserver/tag_cmd.h
14101 --- linux-3.0.25/include/linux/vserver/tag_cmd.h        1970-01-01 01:00:00.000000000 +0100
14102 +++ linux-3.0.25-vs2.3.2.3/include/linux/vserver/tag_cmd.h      2011-06-10 22:11:24.000000000 +0200
14103 @@ -0,0 +1,22 @@
14104 +#ifndef _VX_TAG_CMD_H
14105 +#define _VX_TAG_CMD_H
14106 +
14107 +
14108 +/* vinfo commands */
14109 +
14110 +#define VCMD_task_tag          VC_CMD(VINFO, 3, 0)
14111 +
14112 +#ifdef __KERNEL__
14113 +extern int vc_task_tag(uint32_t);
14114 +
14115 +#endif /* __KERNEL__ */
14116 +
14117 +/* context commands */
14118 +
14119 +#define VCMD_tag_migrate       VC_CMD(TAGMIG, 1, 0)
14120 +
14121 +#ifdef __KERNEL__
14122 +extern int vc_tag_migrate(uint32_t);
14123 +
14124 +#endif /* __KERNEL__ */
14125 +#endif /* _VX_TAG_CMD_H */
14126 diff -NurpP --minimal linux-3.0.25/include/net/addrconf.h linux-3.0.25-vs2.3.2.3/include/net/addrconf.h
14127 --- linux-3.0.25/include/net/addrconf.h 2011-07-22 11:18:11.000000000 +0200
14128 +++ linux-3.0.25-vs2.3.2.3/include/net/addrconf.h       2011-06-10 22:11:24.000000000 +0200
14129 @@ -80,7 +80,8 @@ extern int                    ipv6_dev_get_saddr(struct n
14130                                                struct net_device *dev,
14131                                                const struct in6_addr *daddr,
14132                                                unsigned int srcprefs,
14133 -                                              struct in6_addr *saddr);
14134 +                                              struct in6_addr *saddr,
14135 +                                              struct nx_info *nxi);
14136  extern int                     ipv6_get_lladdr(struct net_device *dev,
14137                                                 struct in6_addr *addr,
14138                                                 unsigned char banned_flags);
14139 diff -NurpP --minimal linux-3.0.25/include/net/af_unix.h linux-3.0.25-vs2.3.2.3/include/net/af_unix.h
14140 --- linux-3.0.25/include/net/af_unix.h  2011-07-22 11:18:11.000000000 +0200
14141 +++ linux-3.0.25-vs2.3.2.3/include/net/af_unix.h        2011-06-10 22:11:24.000000000 +0200
14142 @@ -4,6 +4,7 @@
14143  #include <linux/socket.h>
14144  #include <linux/un.h>
14145  #include <linux/mutex.h>
14146 +#include <linux/vs_base.h>
14147  #include <net/sock.h>
14148  
14149  extern void unix_inflight(struct file *fp);
14150 diff -NurpP --minimal linux-3.0.25/include/net/inet_timewait_sock.h linux-3.0.25-vs2.3.2.3/include/net/inet_timewait_sock.h
14151 --- linux-3.0.25/include/net/inet_timewait_sock.h       2011-03-15 18:07:40.000000000 +0100
14152 +++ linux-3.0.25-vs2.3.2.3/include/net/inet_timewait_sock.h     2011-06-10 22:11:24.000000000 +0200
14153 @@ -113,6 +113,10 @@ struct inet_timewait_sock {
14154  #define tw_net                 __tw_common.skc_net
14155  #define tw_daddr               __tw_common.skc_daddr
14156  #define tw_rcv_saddr           __tw_common.skc_rcv_saddr
14157 +#define tw_xid                 __tw_common.skc_xid
14158 +#define tw_vx_info             __tw_common.skc_vx_info
14159 +#define tw_nid                 __tw_common.skc_nid
14160 +#define tw_nx_info             __tw_common.skc_nx_info
14161         int                     tw_timeout;
14162         volatile unsigned char  tw_substate;
14163         unsigned char           tw_rcv_wscale;
14164 diff -NurpP --minimal linux-3.0.25/include/net/ip6_route.h linux-3.0.25-vs2.3.2.3/include/net/ip6_route.h
14165 --- linux-3.0.25/include/net/ip6_route.h        2011-07-22 11:18:11.000000000 +0200
14166 +++ linux-3.0.25-vs2.3.2.3/include/net/ip6_route.h      2011-06-16 14:16:51.000000000 +0200
14167 @@ -86,7 +86,8 @@ extern int                    ip6_route_get_saddr(struct 
14168                                                     struct rt6_info *rt,
14169                                                     const struct in6_addr *daddr,
14170                                                     unsigned int prefs,
14171 -                                                   struct in6_addr *saddr);
14172 +                                                   struct in6_addr *saddr,
14173 +                                                   struct nx_info *nxi);
14174  
14175  extern struct rt6_info         *rt6_lookup(struct net *net,
14176                                             const struct in6_addr *daddr,
14177 diff -NurpP --minimal linux-3.0.25/include/net/route.h linux-3.0.25-vs2.3.2.3/include/net/route.h
14178 --- linux-3.0.25/include/net/route.h    2012-03-19 21:16:56.000000000 +0100
14179 +++ linux-3.0.25-vs2.3.2.3/include/net/route.h  2012-03-01 21:51:50.000000000 +0100
14180 @@ -202,6 +202,9 @@ static inline void ip_rt_put(struct rtab
14181                 dst_release(&rt->dst);
14182  }
14183  
14184 +#include <linux/vs_base.h>
14185 +#include <linux/vs_inet.h>
14186 +
14187  #define IPTOS_RT_MASK  (IPTOS_TOS_MASK & ~3)
14188  
14189  extern const __u8 ip_tos2prio[16];
14190 @@ -253,6 +256,9 @@ static inline void ip_route_connect_init
14191                            protocol, flow_flags, dst, src, dport, sport);
14192  }
14193  
14194 +extern struct rtable *ip_v4_find_src(struct net *net, struct nx_info *,
14195 +       struct flowi4 *);
14196 +
14197  static inline struct rtable *ip_route_connect(struct flowi4 *fl4,
14198                                               __be32 dst, __be32 src, u32 tos,
14199                                               int oif, u8 protocol,
14200 @@ -261,11 +267,25 @@ static inline struct rtable *ip_route_co
14201  {
14202         struct net *net = sock_net(sk);
14203         struct rtable *rt;
14204 +       struct nx_info *nx_info = current_nx_info();
14205  
14206         ip_route_connect_init(fl4, dst, src, tos, oif, protocol,
14207                               sport, dport, sk, can_sleep);
14208  
14209 -       if (!dst || !src) {
14210 +       if (sk)
14211 +               nx_info = sk->sk_nx_info;
14212 +
14213 +       vxdprintk(VXD_CBIT(net, 4),
14214 +               "ip_route_connect(%p) %p,%p;%lx",
14215 +               sk, nx_info, sk->sk_socket,
14216 +               (sk->sk_socket?sk->sk_socket->flags:0));
14217 +
14218 +       rt = ip_v4_find_src(net, nx_info, fl4);
14219 +       if (IS_ERR(rt))
14220 +               return rt;
14221 +       ip_rt_put(rt);
14222 +
14223 +       if (!fl4->daddr || !fl4->saddr) {
14224                 rt = __ip_route_output_key(net, fl4);
14225                 if (IS_ERR(rt))
14226                         return rt;
14227 diff -NurpP --minimal linux-3.0.25/include/net/sock.h linux-3.0.25-vs2.3.2.3/include/net/sock.h
14228 --- linux-3.0.25/include/net/sock.h     2011-07-22 11:18:12.000000000 +0200
14229 +++ linux-3.0.25-vs2.3.2.3/include/net/sock.h   2011-07-01 11:35:35.000000000 +0200
14230 @@ -149,6 +149,10 @@ struct sock_common {
14231  #ifdef CONFIG_NET_NS
14232         struct net              *skc_net;
14233  #endif
14234 +       xid_t                   skc_xid;
14235 +       struct vx_info          *skc_vx_info;
14236 +       nid_t                   skc_nid;
14237 +       struct nx_info          *skc_nx_info;
14238         /*
14239          * fields between dontcopy_begin/dontcopy_end
14240          * are not copied in sock_copy()
14241 @@ -256,6 +260,10 @@ struct sock {
14242  #define sk_bind_node           __sk_common.skc_bind_node
14243  #define sk_prot                        __sk_common.skc_prot
14244  #define sk_net                 __sk_common.skc_net
14245 +#define sk_xid                 __sk_common.skc_xid
14246 +#define sk_vx_info             __sk_common.skc_vx_info
14247 +#define sk_nid                 __sk_common.skc_nid
14248 +#define sk_nx_info             __sk_common.skc_nx_info
14249         socket_lock_t           sk_lock;
14250         struct sk_buff_head     sk_receive_queue;
14251         /*
14252 diff -NurpP --minimal linux-3.0.25/init/Kconfig linux-3.0.25-vs2.3.2.3/init/Kconfig
14253 --- linux-3.0.25/init/Kconfig   2011-07-22 11:18:12.000000000 +0200
14254 +++ linux-3.0.25-vs2.3.2.3/init/Kconfig 2011-08-08 18:08:57.000000000 +0200
14255 @@ -574,6 +574,7 @@ config HAVE_UNSTABLE_SCHED_CLOCK
14256  menuconfig CGROUPS
14257         boolean "Control Group support"
14258         depends on EVENTFD
14259 +       default y
14260         help
14261           This option adds support for grouping sets of processes together, for
14262           use with process control subsystems such as Cpusets, CFS, memory
14263 @@ -790,6 +791,7 @@ config IPC_NS
14264  config USER_NS
14265         bool "User namespace (EXPERIMENTAL)"
14266         depends on EXPERIMENTAL
14267 +       depends on VSERVER_DISABLED
14268         default y
14269         help
14270           This allows containers, i.e. vservers, to use user namespaces
14271 diff -NurpP --minimal linux-3.0.25/init/main.c linux-3.0.25-vs2.3.2.3/init/main.c
14272 --- linux-3.0.25/init/main.c    2011-07-22 11:18:12.000000000 +0200
14273 +++ linux-3.0.25-vs2.3.2.3/init/main.c  2011-06-22 12:39:15.000000000 +0200
14274 @@ -68,6 +68,7 @@
14275  #include <linux/shmem_fs.h>
14276  #include <linux/slab.h>
14277  #include <linux/perf_event.h>
14278 +#include <linux/vserver/percpu.h>
14279  
14280  #include <asm/io.h>
14281  #include <asm/bugs.h>
14282 diff -NurpP --minimal linux-3.0.25/ipc/mqueue.c linux-3.0.25-vs2.3.2.3/ipc/mqueue.c
14283 --- linux-3.0.25/ipc/mqueue.c   2012-03-19 21:16:56.000000000 +0100
14284 +++ linux-3.0.25-vs2.3.2.3/ipc/mqueue.c 2011-10-18 14:03:46.000000000 +0200
14285 @@ -33,6 +33,8 @@
14286  #include <linux/pid.h>
14287  #include <linux/ipc_namespace.h>
14288  #include <linux/slab.h>
14289 +#include <linux/vs_context.h>
14290 +#include <linux/vs_limit.h>
14291  
14292  #include <net/sock.h>
14293  #include "util.h"
14294 @@ -66,6 +68,7 @@ struct mqueue_inode_info {
14295         struct sigevent notify;
14296         struct pid* notify_owner;
14297         struct user_struct *user;       /* user who created, for accounting */
14298 +       struct vx_info *vxi;
14299         struct sock *notify_sock;
14300         struct sk_buff *notify_cookie;
14301  
14302 @@ -128,6 +131,7 @@ static struct inode *mqueue_get_inode(st
14303         if (S_ISREG(mode)) {
14304                 struct mqueue_inode_info *info;
14305                 struct task_struct *p = current;
14306 +               struct vx_info *vxi = p->vx_info;
14307                 unsigned long mq_bytes, mq_msg_tblsz;
14308  
14309                 inode->i_fop = &mqueue_file_operations;
14310 @@ -141,6 +145,7 @@ static struct inode *mqueue_get_inode(st
14311                 info->notify_owner = NULL;
14312                 info->qsize = 0;
14313                 info->user = NULL;      /* set when all is ok */
14314 +               info->vxi = NULL;
14315                 memset(&info->attr, 0, sizeof(info->attr));
14316                 info->attr.mq_maxmsg = ipc_ns->mq_msg_max;
14317                 info->attr.mq_msgsize = ipc_ns->mq_msgsize_max;
14318 @@ -158,17 +163,20 @@ static struct inode *mqueue_get_inode(st
14319  
14320                 spin_lock(&mq_lock);
14321                 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
14322 -                   u->mq_bytes + mq_bytes > task_rlimit(p, RLIMIT_MSGQUEUE)) {
14323 +                   u->mq_bytes + mq_bytes > task_rlimit(p, RLIMIT_MSGQUEUE) ||
14324 +                   !vx_ipcmsg_avail(vxi, mq_bytes)) {
14325                         spin_unlock(&mq_lock);
14326                         /* mqueue_evict_inode() releases info->messages */
14327                         ret = -EMFILE;
14328                         goto out_inode;
14329                 }
14330                 u->mq_bytes += mq_bytes;
14331 +               vx_ipcmsg_add(vxi, u, mq_bytes);
14332                 spin_unlock(&mq_lock);
14333  
14334                 /* all is ok */
14335                 info->user = get_uid(u);
14336 +               info->vxi = get_vx_info(vxi);
14337         } else if (S_ISDIR(mode)) {
14338                 inc_nlink(inode);
14339                 /* Some things misbehave if size == 0 on a directory */
14340 @@ -278,8 +286,11 @@ static void mqueue_evict_inode(struct in
14341             + info->attr.mq_msgsize);
14342         user = info->user;
14343         if (user) {
14344 +               struct vx_info *vxi = info->vxi;
14345 +
14346                 spin_lock(&mq_lock);
14347                 user->mq_bytes -= mq_bytes;
14348 +               vx_ipcmsg_sub(vxi, user, mq_bytes);
14349                 /*
14350                  * get_ns_from_inode() ensures that the
14351                  * (ipc_ns = sb->s_fs_info) is either a valid ipc_ns
14352 @@ -289,6 +300,7 @@ static void mqueue_evict_inode(struct in
14353                 if (ipc_ns)
14354                         ipc_ns->mq_queues_count--;
14355                 spin_unlock(&mq_lock);
14356 +               put_vx_info(vxi);
14357                 free_uid(user);
14358         }
14359         if (ipc_ns)
14360 diff -NurpP --minimal linux-3.0.25/ipc/msg.c linux-3.0.25-vs2.3.2.3/ipc/msg.c
14361 --- linux-3.0.25/ipc/msg.c      2011-05-22 16:17:59.000000000 +0200
14362 +++ linux-3.0.25-vs2.3.2.3/ipc/msg.c    2011-06-10 22:11:24.000000000 +0200
14363 @@ -37,6 +37,7 @@
14364  #include <linux/rwsem.h>
14365  #include <linux/nsproxy.h>
14366  #include <linux/ipc_namespace.h>
14367 +#include <linux/vs_base.h>
14368  
14369  #include <asm/current.h>
14370  #include <asm/uaccess.h>
14371 @@ -190,6 +191,7 @@ static int newque(struct ipc_namespace *
14372  
14373         msq->q_perm.mode = msgflg & S_IRWXUGO;
14374         msq->q_perm.key = key;
14375 +       msq->q_perm.xid = vx_current_xid();
14376  
14377         msq->q_perm.security = NULL;
14378         retval = security_msg_queue_alloc(msq);
14379 diff -NurpP --minimal linux-3.0.25/ipc/namespace.c linux-3.0.25-vs2.3.2.3/ipc/namespace.c
14380 --- linux-3.0.25/ipc/namespace.c        2011-07-22 11:18:12.000000000 +0200
14381 +++ linux-3.0.25-vs2.3.2.3/ipc/namespace.c      2011-06-13 14:09:44.000000000 +0200
14382 @@ -13,11 +13,12 @@
14383  #include <linux/mount.h>
14384  #include <linux/user_namespace.h>
14385  #include <linux/proc_fs.h>
14386 +#include <linux/vs_base.h>
14387 +#include <linux/vserver/global.h>
14388  
14389  #include "util.h"
14390  
14391 -static struct ipc_namespace *create_ipc_ns(struct task_struct *tsk,
14392 -                                          struct ipc_namespace *old_ns)
14393 +static struct ipc_namespace *create_ipc_ns(struct user_namespace *user_ns)
14394  {
14395         struct ipc_namespace *ns;
14396         int err;
14397 @@ -46,19 +47,18 @@ static struct ipc_namespace *create_ipc_
14398         ipcns_notify(IPCNS_CREATED);
14399         register_ipcns_notifier(ns);
14400  
14401 -       ns->user_ns = get_user_ns(task_cred_xxx(tsk, user)->user_ns);
14402 +       ns->user_ns = get_user_ns(user_ns);
14403  
14404         return ns;
14405  }
14406  
14407  struct ipc_namespace *copy_ipcs(unsigned long flags,
14408 -                               struct task_struct *tsk)
14409 +                               struct ipc_namespace *old_ns,
14410 +                               struct user_namespace *user_ns)
14411  {
14412 -       struct ipc_namespace *ns = tsk->nsproxy->ipc_ns;
14413 -
14414         if (!(flags & CLONE_NEWIPC))
14415 -               return get_ipc_ns(ns);
14416 -       return create_ipc_ns(tsk, ns);
14417 +               return get_ipc_ns(old_ns);
14418 +       return create_ipc_ns(user_ns);
14419  }
14420  
14421  /*
14422 diff -NurpP --minimal linux-3.0.25/ipc/sem.c linux-3.0.25-vs2.3.2.3/ipc/sem.c
14423 --- linux-3.0.25/ipc/sem.c      2012-03-19 21:16:56.000000000 +0100
14424 +++ linux-3.0.25-vs2.3.2.3/ipc/sem.c    2011-08-08 23:04:47.000000000 +0200
14425 @@ -86,6 +86,8 @@
14426  #include <linux/rwsem.h>
14427  #include <linux/nsproxy.h>
14428  #include <linux/ipc_namespace.h>
14429 +#include <linux/vs_base.h>
14430 +#include <linux/vs_limit.h>
14431  
14432  #include <asm/uaccess.h>
14433  #include "util.h"
14434 @@ -260,6 +262,7 @@ static int newary(struct ipc_namespace *
14435  
14436         sma->sem_perm.mode = (semflg & S_IRWXUGO);
14437         sma->sem_perm.key = key;
14438 +       sma->sem_perm.xid = vx_current_xid();
14439  
14440         sma->sem_perm.security = NULL;
14441         retval = security_sem_alloc(sma);
14442 @@ -275,6 +278,9 @@ static int newary(struct ipc_namespace *
14443                 return id;
14444         }
14445         ns->used_sems += nsems;
14446 +       /* FIXME: obsoleted? */
14447 +       vx_semary_inc(sma);
14448 +       vx_nsems_add(sma, nsems);
14449  
14450         sma->sem_base = (struct sem *) &sma[1];
14451  
14452 @@ -730,6 +736,9 @@ static void freeary(struct ipc_namespace
14453  
14454         wake_up_sem_queue_do(&tasks);
14455         ns->used_sems -= sma->sem_nsems;
14456 +       /* FIXME: obsoleted? */
14457 +       vx_nsems_sub(sma, sma->sem_nsems);
14458 +       vx_semary_dec(sma);
14459         security_sem_free(sma);
14460         ipc_rcu_putref(sma);
14461  }
14462 diff -NurpP --minimal linux-3.0.25/ipc/shm.c linux-3.0.25-vs2.3.2.3/ipc/shm.c
14463 --- linux-3.0.25/ipc/shm.c      2011-07-22 11:18:12.000000000 +0200
14464 +++ linux-3.0.25-vs2.3.2.3/ipc/shm.c    2011-06-10 22:11:24.000000000 +0200
14465 @@ -39,6 +39,8 @@
14466  #include <linux/nsproxy.h>
14467  #include <linux/mount.h>
14468  #include <linux/ipc_namespace.h>
14469 +#include <linux/vs_context.h>
14470 +#include <linux/vs_limit.h>
14471  
14472  #include <asm/uaccess.h>
14473  
14474 @@ -173,7 +175,12 @@ static void shm_open(struct vm_area_stru
14475   */
14476  static void shm_destroy(struct ipc_namespace *ns, struct shmid_kernel *shp)
14477  {
14478 -       ns->shm_tot -= (shp->shm_segsz + PAGE_SIZE - 1) >> PAGE_SHIFT;
14479 +       struct vx_info *vxi = lookup_vx_info(shp->shm_perm.xid);
14480 +       int numpages = (shp->shm_segsz + PAGE_SIZE - 1) >> PAGE_SHIFT;
14481 +
14482 +       vx_ipcshm_sub(vxi, shp, numpages);
14483 +       ns->shm_tot -= numpages;
14484 +
14485         shm_rmid(ns, shp);
14486         shm_unlock(shp);
14487         if (!is_file_hugepages(shp->shm_file))
14488 @@ -183,6 +190,7 @@ static void shm_destroy(struct ipc_names
14489                                                 shp->mlock_user);
14490         fput (shp->shm_file);
14491         security_shm_free(shp);
14492 +       put_vx_info(vxi);
14493         ipc_rcu_putref(shp);
14494  }
14495  
14496 @@ -355,11 +363,15 @@ static int newseg(struct ipc_namespace *
14497         if (ns->shm_tot + numpages > ns->shm_ctlall)
14498                 return -ENOSPC;
14499  
14500 +       if (!vx_ipcshm_avail(current_vx_info(), numpages))
14501 +               return -ENOSPC;
14502 +
14503         shp = ipc_rcu_alloc(sizeof(*shp));
14504         if (!shp)
14505                 return -ENOMEM;
14506  
14507         shp->shm_perm.key = key;
14508 +       shp->shm_perm.xid = vx_current_xid();
14509         shp->shm_perm.mode = (shmflg & S_IRWXUGO);
14510         shp->mlock_user = NULL;
14511  
14512 @@ -413,6 +425,7 @@ static int newseg(struct ipc_namespace *
14513         ns->shm_tot += numpages;
14514         error = shp->shm_perm.id;
14515         shm_unlock(shp);
14516 +       vx_ipcshm_add(current_vx_info(), key, numpages);
14517         return error;
14518  
14519  no_id:
14520 diff -NurpP --minimal linux-3.0.25/kernel/Makefile linux-3.0.25-vs2.3.2.3/kernel/Makefile
14521 --- linux-3.0.25/kernel/Makefile        2011-07-22 11:18:12.000000000 +0200
14522 +++ linux-3.0.25-vs2.3.2.3/kernel/Makefile      2011-06-10 22:11:24.000000000 +0200
14523 @@ -24,6 +24,7 @@ CFLAGS_REMOVE_sched_clock.o = -pg
14524  CFLAGS_REMOVE_irq_work.o = -pg
14525  endif
14526  
14527 +obj-y += vserver/
14528  obj-$(CONFIG_FREEZER) += freezer.o
14529  obj-$(CONFIG_PROFILING) += profile.o
14530  obj-$(CONFIG_SYSCTL_SYSCALL_CHECK) += sysctl_check.o
14531 diff -NurpP --minimal linux-3.0.25/kernel/capability.c linux-3.0.25-vs2.3.2.3/kernel/capability.c
14532 --- linux-3.0.25/kernel/capability.c    2011-07-22 11:18:12.000000000 +0200
14533 +++ linux-3.0.25-vs2.3.2.3/kernel/capability.c  2011-10-27 13:59:20.000000000 +0200
14534 @@ -15,6 +15,7 @@
14535  #include <linux/syscalls.h>
14536  #include <linux/pid_namespace.h>
14537  #include <linux/user_namespace.h>
14538 +#include <linux/vs_context.h>
14539  #include <asm/uaccess.h>
14540  
14541  /*
14542 @@ -116,6 +117,7 @@ static int cap_validate_magic(cap_user_h
14543         return 0;
14544  }
14545  
14546 +
14547  /*
14548   * The only thing that can change the capabilities of the current
14549   * process is the current process. As such, we can't be in this code
14550 @@ -340,6 +342,8 @@ bool has_capability_noaudit(struct task_
14551         return (ret == 0);
14552  }
14553  
14554 +#include <linux/vserver/base.h>
14555 +
14556  /**
14557   * capable - Determine if the current task has a superior capability in effect
14558   * @cap: The capability to be tested for
14559 diff -NurpP --minimal linux-3.0.25/kernel/compat.c linux-3.0.25-vs2.3.2.3/kernel/compat.c
14560 --- linux-3.0.25/kernel/compat.c        2011-07-22 11:18:12.000000000 +0200
14561 +++ linux-3.0.25-vs2.3.2.3/kernel/compat.c      2011-06-10 22:11:24.000000000 +0200
14562 @@ -970,7 +970,7 @@ asmlinkage long compat_sys_stime(compat_
14563         if (err)
14564                 return err;
14565  
14566 -       do_settimeofday(&tv);
14567 +       vx_settimeofday(&tv);
14568         return 0;
14569  }
14570  
14571 diff -NurpP --minimal linux-3.0.25/kernel/cred.c linux-3.0.25-vs2.3.2.3/kernel/cred.c
14572 --- linux-3.0.25/kernel/cred.c  2011-07-22 11:18:12.000000000 +0200
14573 +++ linux-3.0.25-vs2.3.2.3/kernel/cred.c        2011-06-10 22:11:24.000000000 +0200
14574 @@ -61,31 +61,6 @@ struct cred init_cred = {
14575  #endif
14576  };
14577  
14578 -static inline void set_cred_subscribers(struct cred *cred, int n)
14579 -{
14580 -#ifdef CONFIG_DEBUG_CREDENTIALS
14581 -       atomic_set(&cred->subscribers, n);
14582 -#endif
14583 -}
14584 -
14585 -static inline int read_cred_subscribers(const struct cred *cred)
14586 -{
14587 -#ifdef CONFIG_DEBUG_CREDENTIALS
14588 -       return atomic_read(&cred->subscribers);
14589 -#else
14590 -       return 0;
14591 -#endif
14592 -}
14593 -
14594 -static inline void alter_cred_subscribers(const struct cred *_cred, int n)
14595 -{
14596 -#ifdef CONFIG_DEBUG_CREDENTIALS
14597 -       struct cred *cred = (struct cred *) _cred;
14598 -
14599 -       atomic_add(n, &cred->subscribers);
14600 -#endif
14601 -}
14602 -
14603  /*
14604   * Dispose of the shared task group credentials
14605   */
14606 @@ -281,21 +256,16 @@ error:
14607   *
14608   * Call commit_creds() or abort_creds() to clean up.
14609   */
14610 -struct cred *prepare_creds(void)
14611 +struct cred *__prepare_creds(const struct cred *old)
14612  {
14613 -       struct task_struct *task = current;
14614 -       const struct cred *old;
14615         struct cred *new;
14616  
14617 -       validate_process_creds();
14618 -
14619         new = kmem_cache_alloc(cred_jar, GFP_KERNEL);
14620         if (!new)
14621                 return NULL;
14622  
14623         kdebug("prepare_creds() alloc %p", new);
14624  
14625 -       old = task->cred;
14626         memcpy(new, old, sizeof(struct cred));
14627  
14628         atomic_set(&new->usage, 1);
14629 @@ -322,6 +292,13 @@ error:
14630         abort_creds(new);
14631         return NULL;
14632  }
14633 +
14634 +struct cred *prepare_creds(void)
14635 +{
14636 +       validate_process_creds();
14637 +
14638 +       return __prepare_creds(current->cred);
14639 +}
14640  EXPORT_SYMBOL(prepare_creds);
14641  
14642  /*
14643 diff -NurpP --minimal linux-3.0.25/kernel/exit.c linux-3.0.25-vs2.3.2.3/kernel/exit.c
14644 --- linux-3.0.25/kernel/exit.c  2012-03-19 21:16:56.000000000 +0100
14645 +++ linux-3.0.25-vs2.3.2.3/kernel/exit.c        2012-01-10 09:19:13.000000000 +0100
14646 @@ -48,6 +48,10 @@
14647  #include <linux/fs_struct.h>
14648  #include <linux/init_task.h>
14649  #include <linux/perf_event.h>
14650 +#include <linux/vs_limit.h>
14651 +#include <linux/vs_context.h>
14652 +#include <linux/vs_network.h>
14653 +#include <linux/vs_pid.h>
14654  #include <trace/events/sched.h>
14655  #include <linux/hw_breakpoint.h>
14656  #include <linux/oom.h>
14657 @@ -494,9 +498,11 @@ static void close_files(struct files_str
14658                                         filp_close(file, files);
14659                                         cond_resched();
14660                                 }
14661 +                               vx_openfd_dec(i);
14662                         }
14663                         i++;
14664                         set >>= 1;
14665 +                       cond_resched();
14666                 }
14667         }
14668  }
14669 @@ -1047,11 +1053,16 @@ NORET_TYPE void do_exit(long code)
14670  
14671         validate_creds_for_do_exit(tsk);
14672  
14673 +       /* needs to stay after exit_notify() */
14674 +       exit_vx_info(tsk, code);
14675 +       exit_nx_info(tsk);
14676 +
14677         preempt_disable();
14678         exit_rcu();
14679         /* causes final put_task_struct in finish_task_switch(). */
14680         tsk->state = TASK_DEAD;
14681         schedule();
14682 +       printk("bad task: %p [%lx]\n", current, current->state);
14683         BUG();
14684         /* Avoid "noreturn function does return".  */
14685         for (;;)
14686 diff -NurpP --minimal linux-3.0.25/kernel/fork.c linux-3.0.25-vs2.3.2.3/kernel/fork.c
14687 --- linux-3.0.25/kernel/fork.c  2012-03-19 21:16:56.000000000 +0100
14688 +++ linux-3.0.25-vs2.3.2.3/kernel/fork.c        2012-03-01 21:52:38.000000000 +0100
14689 @@ -68,6 +68,10 @@
14690  #include <linux/oom.h>
14691  #include <linux/khugepaged.h>
14692  #include <linux/signalfd.h>
14693 +#include <linux/vs_context.h>
14694 +#include <linux/vs_network.h>
14695 +#include <linux/vs_limit.h>
14696 +#include <linux/vs_memory.h>
14697  
14698  #include <asm/pgtable.h>
14699  #include <asm/pgalloc.h>
14700 @@ -168,6 +172,8 @@ void free_task(struct task_struct *tsk)
14701         account_kernel_stack(tsk->stack, -1);
14702         free_thread_info(tsk->stack);
14703         rt_mutex_debug_task_free(tsk);
14704 +       clr_vx_info(&tsk->vx_info);
14705 +       clr_nx_info(&tsk->nx_info);
14706         ftrace_graph_exit_task(tsk);
14707         free_task_struct(tsk);
14708  }
14709 @@ -506,6 +512,7 @@ static struct mm_struct * mm_init(struct
14710         if (likely(!mm_alloc_pgd(mm))) {
14711                 mm->def_flags = 0;
14712                 mmu_notifier_mm_init(mm);
14713 +               set_vx_info(&mm->mm_vx_info, p->vx_info);
14714                 return mm;
14715         }
14716  
14717 @@ -543,6 +550,7 @@ void __mmdrop(struct mm_struct *mm)
14718  #ifdef CONFIG_TRANSPARENT_HUGEPAGE
14719         VM_BUG_ON(mm->pmd_huge_pte);
14720  #endif
14721 +       clr_vx_info(&mm->mm_vx_info);
14722         free_mm(mm);
14723  }
14724  EXPORT_SYMBOL_GPL(__mmdrop);
14725 @@ -730,6 +738,7 @@ struct mm_struct *dup_mm(struct task_str
14726                 goto fail_nomem;
14727  
14728         memcpy(mm, oldmm, sizeof(*mm));
14729 +       mm->mm_vx_info = NULL;
14730         mm_init_cpumask(mm);
14731  
14732         /* Initializing for Swap token stuff */
14733 @@ -773,6 +782,7 @@ fail_nocontext:
14734          * If init_new_context() failed, we cannot use mmput() to free the mm
14735          * because it calls destroy_context()
14736          */
14737 +       clr_vx_info(&mm->mm_vx_info);
14738         mm_free_pgd(mm);
14739         free_mm(mm);
14740         return NULL;
14741 @@ -1060,6 +1070,8 @@ static struct task_struct *copy_process(
14742         int retval;
14743         struct task_struct *p;
14744         int cgroup_callbacks_done = 0;
14745 +       struct vx_info *vxi;
14746 +       struct nx_info *nxi;
14747  
14748         if ((clone_flags & (CLONE_NEWNS|CLONE_FS)) == (CLONE_NEWNS|CLONE_FS))
14749                 return ERR_PTR(-EINVAL);
14750 @@ -1106,7 +1118,12 @@ static struct task_struct *copy_process(
14751         DEBUG_LOCKS_WARN_ON(!p->hardirqs_enabled);
14752         DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
14753  #endif
14754 +       init_vx_info(&p->vx_info, current_vx_info());
14755 +       init_nx_info(&p->nx_info, current_nx_info());
14756 +
14757         retval = -EAGAIN;
14758 +       if (!vx_nproc_avail(1))
14759 +               goto bad_fork_free;
14760         if (atomic_read(&p->real_cred->user->processes) >=
14761                         task_rlimit(p, RLIMIT_NPROC)) {
14762                 if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE) &&
14763 @@ -1363,6 +1380,18 @@ static struct task_struct *copy_process(
14764  
14765         total_forks++;
14766         spin_unlock(&current->sighand->siglock);
14767 +
14768 +       /* p is copy of current */
14769 +       vxi = p->vx_info;
14770 +       if (vxi) {
14771 +               claim_vx_info(vxi, p);
14772 +               atomic_inc(&vxi->cvirt.nr_threads);
14773 +               atomic_inc(&vxi->cvirt.total_forks);
14774 +               vx_nproc_inc(p);
14775 +       }
14776 +       nxi = p->nx_info;
14777 +       if (nxi)
14778 +               claim_nx_info(nxi, p);
14779         write_unlock_irq(&tasklist_lock);
14780         proc_fork_connector(p);
14781         cgroup_post_fork(p);
14782 diff -NurpP --minimal linux-3.0.25/kernel/kthread.c linux-3.0.25-vs2.3.2.3/kernel/kthread.c
14783 --- linux-3.0.25/kernel/kthread.c       2011-07-22 11:18:12.000000000 +0200
14784 +++ linux-3.0.25-vs2.3.2.3/kernel/kthread.c     2011-06-10 22:11:24.000000000 +0200
14785 @@ -16,6 +16,7 @@
14786  #include <linux/mutex.h>
14787  #include <linux/slab.h>
14788  #include <linux/freezer.h>
14789 +#include <linux/vs_pid.h>
14790  #include <trace/events/sched.h>
14791  
14792  static DEFINE_SPINLOCK(kthread_create_lock);
14793 diff -NurpP --minimal linux-3.0.25/kernel/nsproxy.c linux-3.0.25-vs2.3.2.3/kernel/nsproxy.c
14794 --- linux-3.0.25/kernel/nsproxy.c       2011-07-22 11:18:12.000000000 +0200
14795 +++ linux-3.0.25-vs2.3.2.3/kernel/nsproxy.c     2011-06-13 14:09:44.000000000 +0200
14796 @@ -20,6 +20,8 @@
14797  #include <linux/mnt_namespace.h>
14798  #include <linux/utsname.h>
14799  #include <linux/pid_namespace.h>
14800 +#include <linux/vserver/global.h>
14801 +#include <linux/vserver/debug.h>
14802  #include <net/net_namespace.h>
14803  #include <linux/ipc_namespace.h>
14804  #include <linux/proc_fs.h>
14805 @@ -46,8 +48,11 @@ static inline struct nsproxy *create_nsp
14806         struct nsproxy *nsproxy;
14807  
14808         nsproxy = kmem_cache_alloc(nsproxy_cachep, GFP_KERNEL);
14809 -       if (nsproxy)
14810 +       if (nsproxy) {
14811                 atomic_set(&nsproxy->count, 1);
14812 +               atomic_inc(&vs_global_nsproxy);
14813 +       }
14814 +       vxdprintk(VXD_CBIT(space, 2), "create_nsproxy = %p[1]", nsproxy);
14815         return nsproxy;
14816  }
14817  
14818 @@ -56,8 +61,11 @@ static inline struct nsproxy *create_nsp
14819   * Return the newly created nsproxy.  Do not attach this to the task,
14820   * leave it to the caller to do proper locking and attach it to task.
14821   */
14822 -static struct nsproxy *create_new_namespaces(unsigned long flags,
14823 -                       struct task_struct *tsk, struct fs_struct *new_fs)
14824 +static struct nsproxy *unshare_namespaces(unsigned long flags,
14825 +                       struct nsproxy *orig,
14826 +                       struct fs_struct *new_fs,
14827 +                       struct user_namespace *new_user,
14828 +                       struct pid_namespace *new_pid)
14829  {
14830         struct nsproxy *new_nsp;
14831         int err;
14832 @@ -66,31 +74,31 @@ static struct nsproxy *create_new_namesp
14833         if (!new_nsp)
14834                 return ERR_PTR(-ENOMEM);
14835  
14836 -       new_nsp->mnt_ns = copy_mnt_ns(flags, tsk->nsproxy->mnt_ns, new_fs);
14837 +       new_nsp->mnt_ns = copy_mnt_ns(flags, orig->mnt_ns, new_fs);
14838         if (IS_ERR(new_nsp->mnt_ns)) {
14839                 err = PTR_ERR(new_nsp->mnt_ns);
14840                 goto out_ns;
14841         }
14842  
14843 -       new_nsp->uts_ns = copy_utsname(flags, tsk);
14844 +       new_nsp->uts_ns = copy_utsname(flags, orig->uts_ns, new_user);
14845         if (IS_ERR(new_nsp->uts_ns)) {
14846                 err = PTR_ERR(new_nsp->uts_ns);
14847                 goto out_uts;
14848         }
14849  
14850 -       new_nsp->ipc_ns = copy_ipcs(flags, tsk);
14851 +       new_nsp->ipc_ns = copy_ipcs(flags, orig->ipc_ns, new_user);
14852         if (IS_ERR(new_nsp->ipc_ns)) {
14853                 err = PTR_ERR(new_nsp->ipc_ns);
14854                 goto out_ipc;
14855         }
14856  
14857 -       new_nsp->pid_ns = copy_pid_ns(flags, task_active_pid_ns(tsk));
14858 +       new_nsp->pid_ns = copy_pid_ns(flags, new_pid);
14859         if (IS_ERR(new_nsp->pid_ns)) {
14860                 err = PTR_ERR(new_nsp->pid_ns);
14861                 goto out_pid;
14862         }
14863  
14864 -       new_nsp->net_ns = copy_net_ns(flags, tsk->nsproxy->net_ns);
14865 +       new_nsp->net_ns = copy_net_ns(flags, orig->net_ns);
14866         if (IS_ERR(new_nsp->net_ns)) {
14867                 err = PTR_ERR(new_nsp->net_ns);
14868                 goto out_net;
14869 @@ -115,6 +123,40 @@ out_ns:
14870         return ERR_PTR(err);
14871  }
14872  
14873 +static struct nsproxy *create_new_namespaces(unsigned long flags,
14874 +                       struct task_struct *tsk, struct fs_struct *new_fs)
14875 +{
14876 +       return unshare_namespaces(flags, tsk->nsproxy,
14877 +               new_fs, task_cred_xxx(tsk, user)->user_ns,
14878 +               task_active_pid_ns(tsk));
14879 +}
14880 +
14881 +/*
14882 + * copies the nsproxy, setting refcount to 1, and grabbing a
14883 + * reference to all contained namespaces.
14884 + */
14885 +struct nsproxy *copy_nsproxy(struct nsproxy *orig)
14886 +{
14887 +       struct nsproxy *ns = create_nsproxy();
14888 +
14889 +       if (ns) {
14890 +               memcpy(ns, orig, sizeof(struct nsproxy));
14891 +               atomic_set(&ns->count, 1);
14892 +
14893 +               if (ns->mnt_ns)
14894 +                       get_mnt_ns(ns->mnt_ns);
14895 +               if (ns->uts_ns)
14896 +                       get_uts_ns(ns->uts_ns);
14897 +               if (ns->ipc_ns)
14898 +                       get_ipc_ns(ns->ipc_ns);
14899 +               if (ns->pid_ns)
14900 +                       get_pid_ns(ns->pid_ns);
14901 +               if (ns->net_ns)
14902 +                       get_net(ns->net_ns);
14903 +       }
14904 +       return ns;
14905 +}
14906 +
14907  /*
14908   * called from clone.  This now handles copy for nsproxy and all
14909   * namespaces therein.
14910 @@ -122,9 +164,12 @@ out_ns:
14911  int copy_namespaces(unsigned long flags, struct task_struct *tsk)
14912  {
14913         struct nsproxy *old_ns = tsk->nsproxy;
14914 -       struct nsproxy *new_ns;
14915 +       struct nsproxy *new_ns = NULL;
14916         int err = 0;
14917  
14918 +       vxdprintk(VXD_CBIT(space, 7), "copy_namespaces(0x%08lx,%p[%p])",
14919 +               flags, tsk, old_ns);
14920 +
14921         if (!old_ns)
14922                 return 0;
14923  
14924 @@ -134,7 +179,7 @@ int copy_namespaces(unsigned long flags,
14925                                 CLONE_NEWPID | CLONE_NEWNET)))
14926                 return 0;
14927  
14928 -       if (!capable(CAP_SYS_ADMIN)) {
14929 +       if (!vx_can_unshare(CAP_SYS_ADMIN, flags)) {
14930                 err = -EPERM;
14931                 goto out;
14932         }
14933 @@ -161,6 +206,9 @@ int copy_namespaces(unsigned long flags,
14934  
14935  out:
14936         put_nsproxy(old_ns);
14937 +       vxdprintk(VXD_CBIT(space, 3),
14938 +               "copy_namespaces(0x%08lx,%p[%p]) = %d [%p]",
14939 +               flags, tsk, old_ns, err, new_ns);
14940         return err;
14941  }
14942  
14943 @@ -174,7 +222,9 @@ void free_nsproxy(struct nsproxy *ns)
14944                 put_ipc_ns(ns->ipc_ns);
14945         if (ns->pid_ns)
14946                 put_pid_ns(ns->pid_ns);
14947 -       put_net(ns->net_ns);
14948 +       if (ns->net_ns)
14949 +               put_net(ns->net_ns);
14950 +       atomic_dec(&vs_global_nsproxy);
14951         kmem_cache_free(nsproxy_cachep, ns);
14952  }
14953  
14954 @@ -187,11 +237,15 @@ int unshare_nsproxy_namespaces(unsigned 
14955  {
14956         int err = 0;
14957  
14958 +       vxdprintk(VXD_CBIT(space, 4),
14959 +               "unshare_nsproxy_namespaces(0x%08lx,[%p])",
14960 +               unshare_flags, current->nsproxy);
14961 +
14962         if (!(unshare_flags & (CLONE_NEWNS | CLONE_NEWUTS | CLONE_NEWIPC |
14963                                CLONE_NEWNET)))
14964                 return 0;
14965  
14966 -       if (!capable(CAP_SYS_ADMIN))
14967 +       if (!vx_can_unshare(CAP_SYS_ADMIN, unshare_flags))
14968                 return -EPERM;
14969  
14970         *new_nsp = create_new_namespaces(unshare_flags, current,
14971 diff -NurpP --minimal linux-3.0.25/kernel/pid.c linux-3.0.25-vs2.3.2.3/kernel/pid.c
14972 --- linux-3.0.25/kernel/pid.c   2011-05-22 16:17:59.000000000 +0200
14973 +++ linux-3.0.25-vs2.3.2.3/kernel/pid.c 2011-06-10 22:11:24.000000000 +0200
14974 @@ -36,6 +36,7 @@
14975  #include <linux/pid_namespace.h>
14976  #include <linux/init_task.h>
14977  #include <linux/syscalls.h>
14978 +#include <linux/vs_pid.h>
14979  
14980  #define pid_hashfn(nr, ns)     \
14981         hash_long((unsigned long)nr + (unsigned long)ns, pidhash_shift)
14982 @@ -342,7 +343,7 @@ EXPORT_SYMBOL_GPL(find_pid_ns);
14983  
14984  struct pid *find_vpid(int nr)
14985  {
14986 -       return find_pid_ns(nr, current->nsproxy->pid_ns);
14987 +       return find_pid_ns(vx_rmap_pid(nr), current->nsproxy->pid_ns);
14988  }
14989  EXPORT_SYMBOL_GPL(find_vpid);
14990  
14991 @@ -402,6 +403,9 @@ void transfer_pid(struct task_struct *ol
14992  struct task_struct *pid_task(struct pid *pid, enum pid_type type)
14993  {
14994         struct task_struct *result = NULL;
14995 +
14996 +       if (type == PIDTYPE_REALPID)
14997 +               type = PIDTYPE_PID;
14998         if (pid) {
14999                 struct hlist_node *first;
15000                 first = rcu_dereference_check(hlist_first_rcu(&pid->tasks[type]),
15001 @@ -420,7 +424,7 @@ EXPORT_SYMBOL(pid_task);
15002  struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
15003  {
15004         rcu_lockdep_assert(rcu_read_lock_held());
15005 -       return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
15006 +       return pid_task(find_pid_ns(vx_rmap_pid(nr), ns), PIDTYPE_PID);
15007  }
15008  
15009  struct task_struct *find_task_by_vpid(pid_t vnr)
15010 @@ -464,7 +468,7 @@ struct pid *find_get_pid(pid_t nr)
15011  }
15012  EXPORT_SYMBOL_GPL(find_get_pid);
15013  
15014 -pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns)
15015 +pid_t pid_unmapped_nr_ns(struct pid *pid, struct pid_namespace *ns)
15016  {
15017         struct upid *upid;
15018         pid_t nr = 0;
15019 @@ -477,6 +481,11 @@ pid_t pid_nr_ns(struct pid *pid, struct 
15020         return nr;
15021  }
15022  
15023 +pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns)
15024 +{
15025 +       return vx_map_pid(pid_unmapped_nr_ns(pid, ns));
15026 +}
15027 +
15028  pid_t pid_vnr(struct pid *pid)
15029  {
15030         return pid_nr_ns(pid, current->nsproxy->pid_ns);
15031 diff -NurpP --minimal linux-3.0.25/kernel/pid_namespace.c linux-3.0.25-vs2.3.2.3/kernel/pid_namespace.c
15032 --- linux-3.0.25/kernel/pid_namespace.c 2011-05-22 16:17:59.000000000 +0200
15033 +++ linux-3.0.25-vs2.3.2.3/kernel/pid_namespace.c       2011-06-10 22:17:45.000000000 +0200
15034 @@ -15,6 +15,7 @@
15035  #include <linux/acct.h>
15036  #include <linux/slab.h>
15037  #include <linux/proc_fs.h>
15038 +#include <linux/vserver/global.h>
15039  
15040  #define BITS_PER_PAGE          (PAGE_SIZE*8)
15041  
15042 @@ -88,6 +89,7 @@ static struct pid_namespace *create_pid_
15043                 goto out_free_map;
15044  
15045         kref_init(&ns->kref);
15046 +       atomic_inc(&vs_global_pid_ns);
15047         ns->level = level;
15048         ns->parent = get_pid_ns(parent_pid_ns);
15049  
15050 @@ -119,6 +121,7 @@ static void destroy_pid_namespace(struct
15051  
15052         for (i = 0; i < PIDMAP_ENTRIES; i++)
15053                 kfree(ns->pidmap[i].page);
15054 +       atomic_dec(&vs_global_pid_ns);
15055         kmem_cache_free(pid_ns_cachep, ns);
15056  }
15057  
15058 diff -NurpP --minimal linux-3.0.25/kernel/posix-timers.c linux-3.0.25-vs2.3.2.3/kernel/posix-timers.c
15059 --- linux-3.0.25/kernel/posix-timers.c  2011-07-22 11:18:12.000000000 +0200
15060 +++ linux-3.0.25-vs2.3.2.3/kernel/posix-timers.c        2011-06-10 22:11:24.000000000 +0200
15061 @@ -47,6 +47,7 @@
15062  #include <linux/wait.h>
15063  #include <linux/workqueue.h>
15064  #include <linux/module.h>
15065 +#include <linux/vs_context.h>
15066  
15067  /*
15068   * Management arrays for POSIX timers.  Timers are kept in slab memory
15069 @@ -340,6 +341,7 @@ int posix_timer_event(struct k_itimer *t
15070  {
15071         struct task_struct *task;
15072         int shared, ret = -1;
15073 +
15074         /*
15075          * FIXME: if ->sigq is queued we can race with
15076          * dequeue_signal()->do_schedule_next_timer().
15077 @@ -356,10 +358,18 @@ int posix_timer_event(struct k_itimer *t
15078         rcu_read_lock();
15079         task = pid_task(timr->it_pid, PIDTYPE_PID);
15080         if (task) {
15081 +               struct vx_info_save vxis;
15082 +               struct vx_info *vxi;
15083 +
15084 +               vxi = get_vx_info(task->vx_info);
15085 +               enter_vx_info(vxi, &vxis);
15086                 shared = !(timr->it_sigev_notify & SIGEV_THREAD_ID);
15087                 ret = send_sigqueue(timr->sigq, task, shared);
15088 +               leave_vx_info(&vxis);
15089 +               put_vx_info(vxi);
15090         }
15091         rcu_read_unlock();
15092 +
15093         /* If we failed to send the signal the timer stops. */
15094         return ret > 0;
15095  }
15096 diff -NurpP --minimal linux-3.0.25/kernel/printk.c linux-3.0.25-vs2.3.2.3/kernel/printk.c
15097 --- linux-3.0.25/kernel/printk.c        2012-03-19 21:16:56.000000000 +0100
15098 +++ linux-3.0.25-vs2.3.2.3/kernel/printk.c      2012-02-07 02:05:58.000000000 +0100
15099 @@ -41,6 +41,7 @@
15100  #include <linux/cpu.h>
15101  #include <linux/notifier.h>
15102  #include <linux/rculist.h>
15103 +#include <linux/vs_cvirt.h>
15104  
15105  #include <asm/uaccess.h>
15106  
15107 @@ -314,7 +315,7 @@ static int check_syslog_permissions(int 
15108                 return 0;
15109  
15110         if (syslog_action_restricted(type)) {
15111 -               if (capable(CAP_SYSLOG))
15112 +               if (vx_capable(CAP_SYSLOG, VXC_SYSLOG))
15113                         return 0;
15114                 /* For historical reasons, accept CAP_SYS_ADMIN too, with a warning */
15115                 if (capable(CAP_SYS_ADMIN)) {
15116 @@ -344,12 +345,9 @@ int do_syslog(int type, char __user *buf
15117         if (error)
15118                 return error;
15119  
15120 -       switch (type) {
15121 -       case SYSLOG_ACTION_CLOSE:       /* Close log */
15122 -               break;
15123 -       case SYSLOG_ACTION_OPEN:        /* Open log */
15124 -               break;
15125 -       case SYSLOG_ACTION_READ:        /* Read from log */
15126 +       if ((type == SYSLOG_ACTION_READ) ||
15127 +           (type == SYSLOG_ACTION_READ_ALL) ||
15128 +           (type == SYSLOG_ACTION_READ_CLEAR)) {
15129                 error = -EINVAL;
15130                 if (!buf || len < 0)
15131                         goto out;
15132 @@ -360,6 +358,16 @@ int do_syslog(int type, char __user *buf
15133                         error = -EFAULT;
15134                         goto out;
15135                 }
15136 +       }
15137 +       if (!vx_check(0, VS_ADMIN|VS_WATCH))
15138 +               return vx_do_syslog(type, buf, len);
15139 +
15140 +       switch (type) {
15141 +       case SYSLOG_ACTION_CLOSE:       /* Close log */
15142 +               break;
15143 +       case SYSLOG_ACTION_OPEN:        /* Open log */
15144 +               break;
15145 +       case SYSLOG_ACTION_READ:        /* Read from log */
15146                 error = wait_event_interruptible(log_wait,
15147                                                         (log_start - log_end));
15148                 if (error)
15149 @@ -386,16 +394,6 @@ int do_syslog(int type, char __user *buf
15150                 /* FALL THRU */
15151         /* Read last kernel messages */
15152         case SYSLOG_ACTION_READ_ALL:
15153 -               error = -EINVAL;
15154 -               if (!buf || len < 0)
15155 -                       goto out;
15156 -               error = 0;
15157 -               if (!len)
15158 -                       goto out;
15159 -               if (!access_ok(VERIFY_WRITE, buf, len)) {
15160 -                       error = -EFAULT;
15161 -                       goto out;
15162 -               }
15163                 count = len;
15164                 if (count > log_buf_len)
15165                         count = log_buf_len;
15166 diff -NurpP --minimal linux-3.0.25/kernel/ptrace.c linux-3.0.25-vs2.3.2.3/kernel/ptrace.c
15167 --- linux-3.0.25/kernel/ptrace.c        2011-07-22 11:18:12.000000000 +0200
15168 +++ linux-3.0.25-vs2.3.2.3/kernel/ptrace.c      2011-11-21 16:29:59.000000000 +0100
15169 @@ -22,6 +22,7 @@
15170  #include <linux/syscalls.h>
15171  #include <linux/uaccess.h>
15172  #include <linux/regset.h>
15173 +#include <linux/vs_context.h>
15174  #include <linux/hw_breakpoint.h>
15175  
15176  
15177 @@ -145,9 +146,15 @@ int __ptrace_may_access(struct task_stru
15178          * or halting the specified task is impossible.
15179          */
15180         int dumpable = 0;
15181 +
15182         /* Don't let security modules deny introspection */
15183         if (task == current)
15184                 return 0;
15185 +
15186 +       vxdprintk(VXD_CBIT(perm, 8),
15187 +               "__ptrace_may_access(%p[#%d,%d,%d], %d)",
15188 +               task, task->xid, task->pid, task->tgid, mode);
15189 +
15190         rcu_read_lock();
15191         tcred = __task_cred(task);
15192         if (cred->user->user_ns == tcred->user->user_ns &&
15193 @@ -161,6 +168,8 @@ int __ptrace_may_access(struct task_stru
15194         if (ns_capable(tcred->user->user_ns, CAP_SYS_PTRACE))
15195                 goto ok;
15196         rcu_read_unlock();
15197 +       vxdprintk(VXD_CBIT(perm, 8),
15198 +               "__ptrace_may_access(%p) cred/cap failed", task);
15199         return -EPERM;
15200  ok:
15201         rcu_read_unlock();
15202 @@ -169,6 +178,19 @@ ok:
15203                 dumpable = get_dumpable(task->mm);
15204         if (!dumpable && !task_ns_capable(task, CAP_SYS_PTRACE))
15205                 return -EPERM;
15206 +       vxdprintk(VXD_CBIT(perm, 8),
15207 +               "__ptrace_may_access(%p) cap/dump ok", task);
15208 +
15209 +       if (!vx_check(task->xid, VS_ADMIN_P|VS_WATCH_P|VS_IDENT))
15210 +               return -EPERM;
15211 +       vxdprintk(VXD_CBIT(perm, 8),
15212 +               "__ptrace_may_access(%p) check ok", task);
15213 +
15214 +       if (!vx_check(task->xid, VS_IDENT) &&
15215 +               !task_vx_flags(task, VXF_STATE_ADMIN, 0))
15216 +               return -EACCES;
15217 +       vxdprintk(VXD_CBIT(perm, 8),
15218 +               "__ptrace_may_access(%p) admin ok", task);
15219  
15220         return security_ptrace_access_check(task, mode);
15221  }
15222 diff -NurpP --minimal linux-3.0.25/kernel/sched.c linux-3.0.25-vs2.3.2.3/kernel/sched.c
15223 --- linux-3.0.25/kernel/sched.c 2012-03-19 21:16:56.000000000 +0100
15224 +++ linux-3.0.25-vs2.3.2.3/kernel/sched.c       2011-10-18 13:51:13.000000000 +0200
15225 @@ -71,6 +71,8 @@
15226  #include <linux/ctype.h>
15227  #include <linux/ftrace.h>
15228  #include <linux/slab.h>
15229 +#include <linux/vs_sched.h>
15230 +#include <linux/vs_cvirt.h>
15231  
15232  #include <asm/tlb.h>
15233  #include <asm/irq_regs.h>
15234 @@ -3461,9 +3463,17 @@ static void calc_global_nohz(unsigned lo
15235   */
15236  void get_avenrun(unsigned long *loads, unsigned long offset, int shift)
15237  {
15238 -       loads[0] = (avenrun[0] + offset) << shift;
15239 -       loads[1] = (avenrun[1] + offset) << shift;
15240 -       loads[2] = (avenrun[2] + offset) << shift;
15241 +       if (vx_flags(VXF_VIRT_LOAD, 0)) {
15242 +               struct vx_info *vxi = current_vx_info();
15243 +
15244 +               loads[0] = (vxi->cvirt.load[0] + offset) << shift;
15245 +               loads[1] = (vxi->cvirt.load[1] + offset) << shift;
15246 +               loads[2] = (vxi->cvirt.load[2] + offset) << shift;
15247 +       } else {
15248 +               loads[0] = (avenrun[0] + offset) << shift;
15249 +               loads[1] = (avenrun[1] + offset) << shift;
15250 +               loads[2] = (avenrun[2] + offset) << shift;
15251 +       }
15252  }
15253  
15254  /*
15255 @@ -3722,16 +3732,19 @@ void account_user_time(struct task_struc
15256                        cputime_t cputime_scaled)
15257  {
15258         struct cpu_usage_stat *cpustat = &kstat_this_cpu.cpustat;
15259 +       struct vx_info *vxi = p->vx_info;  /* p is _always_ current */
15260         cputime64_t tmp;
15261 +       int nice = (TASK_NICE(p) > 0);
15262  
15263         /* Add user time to process. */
15264         p->utime = cputime_add(p->utime, cputime);
15265         p->utimescaled = cputime_add(p->utimescaled, cputime_scaled);
15266 +       vx_account_user(vxi, cputime, nice);
15267         account_group_user_time(p, cputime);
15268  
15269         /* Add user time to cpustat. */
15270         tmp = cputime_to_cputime64(cputime);
15271 -       if (TASK_NICE(p) > 0)
15272 +       if (nice)
15273                 cpustat->nice = cputime64_add(cpustat->nice, tmp);
15274         else
15275                 cpustat->user = cputime64_add(cpustat->user, tmp);
15276 @@ -3783,10 +3796,12 @@ void __account_system_time(struct task_s
15277                         cputime_t cputime_scaled, cputime64_t *target_cputime64)
15278  {
15279         cputime64_t tmp = cputime_to_cputime64(cputime);
15280 +       struct vx_info *vxi = p->vx_info;  /* p is _always_ current */
15281  
15282         /* Add system time to process. */
15283         p->stime = cputime_add(p->stime, cputime);
15284         p->stimescaled = cputime_add(p->stimescaled, cputime_scaled);
15285 +       vx_account_system(vxi, cputime, 0 /* do we have idle time? */);
15286         account_group_system_time(p, cputime);
15287  
15288         /* Add system time to cpustat. */
15289 @@ -4954,7 +4969,7 @@ SYSCALL_DEFINE1(nice, int, increment)
15290                 nice = 19;
15291  
15292         if (increment < 0 && !can_nice(current, nice))
15293 -               return -EPERM;
15294 +               return vx_flags(VXF_IGNEG_NICE, 0) ? 0 : -EPERM;
15295  
15296         retval = security_task_setnice(current, nice);
15297         if (retval)
15298 diff -NurpP --minimal linux-3.0.25/kernel/sched_fair.c linux-3.0.25-vs2.3.2.3/kernel/sched_fair.c
15299 --- linux-3.0.25/kernel/sched_fair.c    2011-07-22 11:18:12.000000000 +0200
15300 +++ linux-3.0.25-vs2.3.2.3/kernel/sched_fair.c  2011-07-22 11:20:39.000000000 +0200
15301 @@ -998,6 +998,8 @@ enqueue_entity(struct cfs_rq *cfs_rq, st
15302                 __enqueue_entity(cfs_rq, se);
15303         se->on_rq = 1;
15304  
15305 +       if (entity_is_task(se))
15306 +               vx_activate_task(task_of(se));
15307         if (cfs_rq->nr_running == 1)
15308                 list_add_leaf_cfs_rq(cfs_rq);
15309  }
15310 @@ -1074,6 +1076,8 @@ dequeue_entity(struct cfs_rq *cfs_rq, st
15311         if (se != cfs_rq->curr)
15312                 __dequeue_entity(cfs_rq, se);
15313         se->on_rq = 0;
15314 +       if (entity_is_task(se))
15315 +               vx_deactivate_task(task_of(se));
15316         update_cfs_load(cfs_rq, 0);
15317         account_entity_dequeue(cfs_rq, se);
15318  
15319 diff -NurpP --minimal linux-3.0.25/kernel/signal.c linux-3.0.25-vs2.3.2.3/kernel/signal.c
15320 --- linux-3.0.25/kernel/signal.c        2012-03-19 21:16:56.000000000 +0100
15321 +++ linux-3.0.25-vs2.3.2.3/kernel/signal.c      2011-11-15 17:37:07.000000000 +0100
15322 @@ -28,6 +28,8 @@
15323  #include <linux/freezer.h>
15324  #include <linux/pid_namespace.h>
15325  #include <linux/nsproxy.h>
15326 +#include <linux/vs_context.h>
15327 +#include <linux/vs_pid.h>
15328  #define CREATE_TRACE_POINTS
15329  #include <trace/events/signal.h>
15330  
15331 @@ -744,9 +746,18 @@ static int check_kill_permission(int sig
15332         struct pid *sid;
15333         int error;
15334  
15335 +       vxdprintk(VXD_CBIT(misc, 7),
15336 +               "check_kill_permission(%d,%p,%p[#%u,%u])",
15337 +               sig, info, t, vx_task_xid(t), t->pid);
15338 +
15339         if (!valid_signal(sig))
15340                 return -EINVAL;
15341  
15342 +/*     FIXME: needed? if so, why?
15343 +       if ((info != SEND_SIG_NOINFO) &&
15344 +               (is_si_special(info) || !si_fromuser(info)))
15345 +               goto skip;      */
15346 +
15347         if (!si_fromuser(info))
15348                 return 0;
15349  
15350 @@ -770,6 +781,20 @@ static int check_kill_permission(int sig
15351                 }
15352         }
15353  
15354 +       error = -EPERM;
15355 +       if (t->pid == 1 && current->xid)
15356 +               return error;
15357 +
15358 +       error = -ESRCH;
15359 +       /* FIXME: we shouldn't return ESRCH ever, to avoid
15360 +                 loops, maybe ENOENT or EACCES? */
15361 +       if (!vx_check(vx_task_xid(t), VS_WATCH_P | VS_IDENT)) {
15362 +               vxdprintk(current->xid || VXD_CBIT(misc, 7),
15363 +                       "signal %d[%p] xid mismatch %p[#%u,%u] xid=#%u",
15364 +                       sig, info, t, vx_task_xid(t), t->pid, current->xid);
15365 +               return error;
15366 +       }
15367 +/* skip: */
15368         return security_task_kill(t, info, sig, 0);
15369  }
15370  
15371 @@ -1246,7 +1271,7 @@ int kill_pid_info(int sig, struct siginf
15372         rcu_read_lock();
15373  retry:
15374         p = pid_task(pid, PIDTYPE_PID);
15375 -       if (p) {
15376 +       if (p && vx_check(vx_task_xid(p), VS_IDENT)) {
15377                 error = group_send_sig_info(sig, info, p);
15378                 if (unlikely(error == -ESRCH))
15379                         /*
15380 @@ -1285,7 +1310,7 @@ int kill_pid_info_as_uid(int sig, struct
15381  
15382         rcu_read_lock();
15383         p = pid_task(pid, PIDTYPE_PID);
15384 -       if (!p) {
15385 +       if (!p || !vx_check(vx_task_xid(p), VS_IDENT)) {
15386                 ret = -ESRCH;
15387                 goto out_unlock;
15388         }
15389 @@ -1340,8 +1365,10 @@ static int kill_something_info(int sig, 
15390                 struct task_struct * p;
15391  
15392                 for_each_process(p) {
15393 -                       if (task_pid_vnr(p) > 1 &&
15394 -                                       !same_thread_group(p, current)) {
15395 +                       if (vx_check(vx_task_xid(p), VS_ADMIN|VS_IDENT) &&
15396 +                               task_pid_vnr(p) > 1 &&
15397 +                               !same_thread_group(p, current) &&
15398 +                               !vx_current_initpid(p->pid)) {
15399                                 int err = group_send_sig_info(sig, info, p);
15400                                 ++count;
15401                                 if (err != -EPERM)
15402 @@ -2138,6 +2165,11 @@ relock:
15403                                 !sig_kernel_only(signr))
15404                         continue;
15405  
15406 +               /* virtual init is protected against user signals */
15407 +               if ((info->si_code == SI_USER) &&
15408 +                       vx_current_initpid(current->pid))
15409 +                       continue;
15410 +
15411                 if (sig_kernel_stop(signr)) {
15412                         /*
15413                          * The default action is to stop all threads in
15414 diff -NurpP --minimal linux-3.0.25/kernel/softirq.c linux-3.0.25-vs2.3.2.3/kernel/softirq.c
15415 --- linux-3.0.25/kernel/softirq.c       2011-07-22 11:18:12.000000000 +0200
15416 +++ linux-3.0.25-vs2.3.2.3/kernel/softirq.c     2011-07-22 11:20:39.000000000 +0200
15417 @@ -24,6 +24,7 @@
15418  #include <linux/ftrace.h>
15419  #include <linux/smp.h>
15420  #include <linux/tick.h>
15421 +#include <linux/vs_context.h>
15422  
15423  #define CREATE_TRACE_POINTS
15424  #include <trace/events/irq.h>
15425 diff -NurpP --minimal linux-3.0.25/kernel/sys.c linux-3.0.25-vs2.3.2.3/kernel/sys.c
15426 --- linux-3.0.25/kernel/sys.c   2012-03-19 21:16:56.000000000 +0100
15427 +++ linux-3.0.25-vs2.3.2.3/kernel/sys.c 2011-11-15 17:37:07.000000000 +0100
15428 @@ -45,6 +45,7 @@
15429  #include <linux/syscalls.h>
15430  #include <linux/kprobes.h>
15431  #include <linux/user_namespace.h>
15432 +#include <linux/vs_pid.h>
15433  
15434  #include <linux/kmsg_dump.h>
15435  /* Move somewhere else to avoid recompiling? */
15436 @@ -155,7 +156,10 @@ static int set_one_prio(struct task_stru
15437                 goto out;
15438         }
15439         if (niceval < task_nice(p) && !can_nice(p, niceval)) {
15440 -               error = -EACCES;
15441 +               if (vx_flags(VXF_IGNEG_NICE, 0))
15442 +                       error = 0;
15443 +               else
15444 +                       error = -EACCES;
15445                 goto out;
15446         }
15447         no_nice = security_task_setnice(p, niceval);
15448 @@ -205,6 +209,8 @@ SYSCALL_DEFINE3(setpriority, int, which,
15449                         else
15450                                 pgrp = task_pgrp(current);
15451                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
15452 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
15453 +                                       continue;
15454                                 error = set_one_prio(p, niceval, error);
15455                         } while_each_pid_thread(pgrp, PIDTYPE_PGID, p);
15456                         break;
15457 @@ -268,6 +274,8 @@ SYSCALL_DEFINE2(getpriority, int, which,
15458                         else
15459                                 pgrp = task_pgrp(current);
15460                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
15461 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
15462 +                                       continue;
15463                                 niceval = 20 - task_nice(p);
15464                                 if (niceval > retval)
15465                                         retval = niceval;
15466 @@ -387,6 +395,8 @@ EXPORT_SYMBOL_GPL(kernel_power_off);
15467  
15468  static DEFINE_MUTEX(reboot_mutex);
15469  
15470 +long vs_reboot(unsigned int, void __user *);
15471 +
15472  /*
15473   * Reboot system call: for obvious reasons only root may call it,
15474   * and even root needs to set up some magic numbers in the registers
15475 @@ -419,6 +429,9 @@ SYSCALL_DEFINE4(reboot, int, magic1, int
15476         if ((cmd == LINUX_REBOOT_CMD_POWER_OFF) && !pm_power_off)
15477                 cmd = LINUX_REBOOT_CMD_HALT;
15478  
15479 +       if (!vx_check(0, VS_ADMIN|VS_WATCH))
15480 +               return vs_reboot(cmd, arg);
15481 +
15482         mutex_lock(&reboot_mutex);
15483         switch (cmd) {
15484         case LINUX_REBOOT_CMD_RESTART:
15485 @@ -1235,7 +1248,8 @@ SYSCALL_DEFINE2(sethostname, char __user
15486         int errno;
15487         char tmp[__NEW_UTS_LEN];
15488  
15489 -       if (!ns_capable(current->nsproxy->uts_ns->user_ns, CAP_SYS_ADMIN))
15490 +       if (!vx_ns_capable(current->nsproxy->uts_ns->user_ns,
15491 +               CAP_SYS_ADMIN, VXC_SET_UTSNAME))
15492                 return -EPERM;
15493  
15494         if (len < 0 || len > __NEW_UTS_LEN)
15495 @@ -1285,7 +1299,8 @@ SYSCALL_DEFINE2(setdomainname, char __us
15496         int errno;
15497         char tmp[__NEW_UTS_LEN];
15498  
15499 -       if (!ns_capable(current->nsproxy->uts_ns->user_ns, CAP_SYS_ADMIN))
15500 +       if (!vx_ns_capable(current->nsproxy->uts_ns->user_ns,
15501 +               CAP_SYS_ADMIN, VXC_SET_UTSNAME))
15502                 return -EPERM;
15503         if (len < 0 || len > __NEW_UTS_LEN)
15504                 return -EINVAL;
15505 @@ -1403,7 +1418,7 @@ int do_prlimit(struct task_struct *tsk, 
15506                 /* Keep the capable check against init_user_ns until
15507                    cgroups can contain all limits */
15508                 if (new_rlim->rlim_max > rlim->rlim_max &&
15509 -                               !capable(CAP_SYS_RESOURCE))
15510 +                       !vx_capable(CAP_SYS_RESOURCE, VXC_SET_RLIMIT))
15511                         retval = -EPERM;
15512                 if (!retval)
15513                         retval = security_task_setrlimit(tsk->group_leader,
15514 @@ -1457,7 +1472,8 @@ static int check_prlimit_permission(stru
15515              cred->gid == tcred->sgid &&
15516              cred->gid == tcred->gid))
15517                 return 0;
15518 -       if (ns_capable(tcred->user->user_ns, CAP_SYS_RESOURCE))
15519 +       if (vx_ns_capable(tcred->user->user_ns,
15520 +               CAP_SYS_RESOURCE, VXC_SET_RLIMIT))
15521                 return 0;
15522  
15523         return -EPERM;
15524 diff -NurpP --minimal linux-3.0.25/kernel/sysctl.c linux-3.0.25-vs2.3.2.3/kernel/sysctl.c
15525 --- linux-3.0.25/kernel/sysctl.c        2011-07-22 11:18:12.000000000 +0200
15526 +++ linux-3.0.25-vs2.3.2.3/kernel/sysctl.c      2011-06-15 02:40:14.000000000 +0200
15527 @@ -75,6 +75,7 @@
15528  #if defined(CONFIG_PROVE_LOCKING) || defined(CONFIG_LOCK_STAT)
15529  #include <linux/lockdep.h>
15530  #endif
15531 +extern char vshelper_path[];
15532  #ifdef CONFIG_CHR_DEV_SG
15533  #include <scsi/sg.h>
15534  #endif
15535 @@ -568,6 +569,13 @@ static struct ctl_table kern_table[] = {
15536                 .proc_handler   = proc_dostring,
15537         },
15538  #endif
15539 +       {
15540 +               .procname       = "vshelper",
15541 +               .data           = &vshelper_path,
15542 +               .maxlen         = 256,
15543 +               .mode           = 0644,
15544 +               .proc_handler   = &proc_dostring,
15545 +       },
15546  #ifdef CONFIG_CHR_DEV_SG
15547         {
15548                 .procname       = "sg-big-buff",
15549 diff -NurpP --minimal linux-3.0.25/kernel/sysctl_binary.c linux-3.0.25-vs2.3.2.3/kernel/sysctl_binary.c
15550 --- linux-3.0.25/kernel/sysctl_binary.c 2012-03-19 21:16:56.000000000 +0100
15551 +++ linux-3.0.25-vs2.3.2.3/kernel/sysctl_binary.c       2012-01-10 09:19:13.000000000 +0100
15552 @@ -73,6 +73,7 @@ static const struct bin_table bin_kern_t
15553  
15554         { CTL_INT,      KERN_PANIC,                     "panic" },
15555         { CTL_INT,      KERN_REALROOTDEV,               "real-root-dev" },
15556 +       { CTL_STR,      KERN_VSHELPER,                  "vshelper" },
15557  
15558         { CTL_STR,      KERN_SPARC_REBOOT,              "reboot-cmd" },
15559         { CTL_INT,      KERN_CTLALTDEL,                 "ctrl-alt-del" },
15560 diff -NurpP --minimal linux-3.0.25/kernel/time/timekeeping.c linux-3.0.25-vs2.3.2.3/kernel/time/timekeeping.c
15561 --- linux-3.0.25/kernel/time/timekeeping.c      2012-03-19 21:16:56.000000000 +0100
15562 +++ linux-3.0.25-vs2.3.2.3/kernel/time/timekeeping.c    2011-12-19 15:55:53.000000000 +0100
15563 @@ -233,6 +233,7 @@ void getnstimeofday(struct timespec *ts)
15564         } while (read_seqretry(&xtime_lock, seq));
15565  
15566         timespec_add_ns(ts, nsecs);
15567 +       vx_adjust_timespec(ts);
15568  }
15569  
15570  EXPORT_SYMBOL(getnstimeofday);
15571 diff -NurpP --minimal linux-3.0.25/kernel/time.c linux-3.0.25-vs2.3.2.3/kernel/time.c
15572 --- linux-3.0.25/kernel/time.c  2012-03-19 21:16:56.000000000 +0100
15573 +++ linux-3.0.25-vs2.3.2.3/kernel/time.c        2011-11-15 17:37:07.000000000 +0100
15574 @@ -92,7 +92,7 @@ SYSCALL_DEFINE1(stime, time_t __user *, 
15575         if (err)
15576                 return err;
15577  
15578 -       do_settimeofday(&tv);
15579 +       vx_settimeofday(&tv);
15580         return 0;
15581  }
15582  
15583 @@ -177,7 +177,7 @@ int do_sys_settimeofday(const struct tim
15584                 /* SMP safe, again the code in arch/foo/time.c should
15585                  * globally block out interrupts when it runs.
15586                  */
15587 -               return do_settimeofday(tv);
15588 +               return vx_settimeofday(tv);
15589         }
15590         return 0;
15591  }
15592 diff -NurpP --minimal linux-3.0.25/kernel/timer.c linux-3.0.25-vs2.3.2.3/kernel/timer.c
15593 --- linux-3.0.25/kernel/timer.c 2011-07-22 11:18:12.000000000 +0200
15594 +++ linux-3.0.25-vs2.3.2.3/kernel/timer.c       2011-06-15 02:40:14.000000000 +0200
15595 @@ -40,6 +40,10 @@
15596  #include <linux/irq_work.h>
15597  #include <linux/sched.h>
15598  #include <linux/slab.h>
15599 +#include <linux/vs_base.h>
15600 +#include <linux/vs_cvirt.h>
15601 +#include <linux/vs_pid.h>
15602 +#include <linux/vserver/sched.h>
15603  
15604  #include <asm/uaccess.h>
15605  #include <asm/unistd.h>
15606 @@ -1336,12 +1340,6 @@ SYSCALL_DEFINE1(alarm, unsigned int, sec
15607  
15608  #endif
15609  
15610 -#ifndef __alpha__
15611 -
15612 -/*
15613 - * The Alpha uses getxpid, getxuid, and getxgid instead.  Maybe this
15614 - * should be moved into arch/i386 instead?
15615 - */
15616  
15617  /**
15618   * sys_getpid - return the thread group id of the current process
15619 @@ -1370,10 +1368,23 @@ SYSCALL_DEFINE0(getppid)
15620         rcu_read_lock();
15621         pid = task_tgid_vnr(current->real_parent);
15622         rcu_read_unlock();
15623 +       return vx_map_pid(pid);
15624 +}
15625  
15626 -       return pid;
15627 +#ifdef __alpha__
15628 +
15629 +/*
15630 + * The Alpha uses getxpid, getxuid, and getxgid instead.
15631 + */
15632 +
15633 +asmlinkage long do_getxpid(long *ppid)
15634 +{
15635 +       *ppid = sys_getppid();
15636 +       return sys_getpid();
15637  }
15638  
15639 +#else /* _alpha_ */
15640 +
15641  SYSCALL_DEFINE0(getuid)
15642  {
15643         /* Only we change this so SMP safe */
15644 diff -NurpP --minimal linux-3.0.25/kernel/user_namespace.c linux-3.0.25-vs2.3.2.3/kernel/user_namespace.c
15645 --- linux-3.0.25/kernel/user_namespace.c        2011-03-15 18:07:42.000000000 +0100
15646 +++ linux-3.0.25-vs2.3.2.3/kernel/user_namespace.c      2011-06-10 22:11:24.000000000 +0200
15647 @@ -11,6 +11,7 @@
15648  #include <linux/user_namespace.h>
15649  #include <linux/highuid.h>
15650  #include <linux/cred.h>
15651 +#include <linux/vserver/global.h>
15652  
15653  static struct kmem_cache *user_ns_cachep __read_mostly;
15654  
15655 @@ -33,6 +34,7 @@ int create_user_ns(struct cred *new)
15656                 return -ENOMEM;
15657  
15658         kref_init(&ns->kref);
15659 +       atomic_inc(&vs_global_user_ns);
15660  
15661         for (n = 0; n < UIDHASH_SZ; ++n)
15662                 INIT_HLIST_HEAD(ns->uidhash_table + n);
15663 @@ -81,6 +83,8 @@ void free_user_ns(struct kref *kref)
15664         struct user_namespace *ns =
15665                 container_of(kref, struct user_namespace, kref);
15666  
15667 +       /* FIXME: maybe move into destroyer? */
15668 +       atomic_dec(&vs_global_user_ns);
15669         INIT_WORK(&ns->destroyer, free_user_ns_work);
15670         schedule_work(&ns->destroyer);
15671  }
15672 diff -NurpP --minimal linux-3.0.25/kernel/utsname.c linux-3.0.25-vs2.3.2.3/kernel/utsname.c
15673 --- linux-3.0.25/kernel/utsname.c       2011-07-22 11:18:12.000000000 +0200
15674 +++ linux-3.0.25-vs2.3.2.3/kernel/utsname.c     2011-06-13 14:09:44.000000000 +0200
15675 @@ -16,14 +16,17 @@
15676  #include <linux/slab.h>
15677  #include <linux/user_namespace.h>
15678  #include <linux/proc_fs.h>
15679 +#include <linux/vserver/global.h>
15680  
15681  static struct uts_namespace *create_uts_ns(void)
15682  {
15683         struct uts_namespace *uts_ns;
15684  
15685         uts_ns = kmalloc(sizeof(struct uts_namespace), GFP_KERNEL);
15686 -       if (uts_ns)
15687 +       if (uts_ns) {
15688                 kref_init(&uts_ns->kref);
15689 +               atomic_inc(&vs_global_uts_ns);
15690 +       }
15691         return uts_ns;
15692  }
15693  
15694 @@ -32,8 +35,8 @@ static struct uts_namespace *create_uts_
15695   * @old_ns: namespace to clone
15696   * Return NULL on error (failure to kmalloc), new ns otherwise
15697   */
15698 -static struct uts_namespace *clone_uts_ns(struct task_struct *tsk,
15699 -                                         struct uts_namespace *old_ns)
15700 +static struct uts_namespace *clone_uts_ns(struct uts_namespace *old_ns,
15701 +                                         struct user_namespace *old_user)
15702  {
15703         struct uts_namespace *ns;
15704  
15705 @@ -43,7 +46,7 @@ static struct uts_namespace *clone_uts_n
15706  
15707         down_read(&uts_sem);
15708         memcpy(&ns->name, &old_ns->name, sizeof(ns->name));
15709 -       ns->user_ns = get_user_ns(task_cred_xxx(tsk, user)->user_ns);
15710 +       ns->user_ns = get_user_ns(old_user);
15711         up_read(&uts_sem);
15712         return ns;
15713  }
15714 @@ -55,9 +58,9 @@ static struct uts_namespace *clone_uts_n
15715   * versa.
15716   */
15717  struct uts_namespace *copy_utsname(unsigned long flags,
15718 -                                  struct task_struct *tsk)
15719 +                                  struct uts_namespace *old_ns,
15720 +                                  struct user_namespace *user_ns)
15721  {
15722 -       struct uts_namespace *old_ns = tsk->nsproxy->uts_ns;
15723         struct uts_namespace *new_ns;
15724  
15725         BUG_ON(!old_ns);
15726 @@ -66,7 +69,7 @@ struct uts_namespace *copy_utsname(unsig
15727         if (!(flags & CLONE_NEWUTS))
15728                 return old_ns;
15729  
15730 -       new_ns = clone_uts_ns(tsk, old_ns);
15731 +       new_ns = clone_uts_ns(old_ns, user_ns);
15732  
15733         put_uts_ns(old_ns);
15734         return new_ns;
15735 @@ -78,6 +81,7 @@ void free_uts_ns(struct kref *kref)
15736  
15737         ns = container_of(kref, struct uts_namespace, kref);
15738         put_user_ns(ns->user_ns);
15739 +       atomic_dec(&vs_global_uts_ns);
15740         kfree(ns);
15741  }
15742  
15743 diff -NurpP --minimal linux-3.0.25/kernel/vserver/Kconfig linux-3.0.25-vs2.3.2.3/kernel/vserver/Kconfig
15744 --- linux-3.0.25/kernel/vserver/Kconfig 1970-01-01 01:00:00.000000000 +0100
15745 +++ linux-3.0.25-vs2.3.2.3/kernel/vserver/Kconfig       2011-08-08 18:06:22.000000000 +0200
15746 @@ -0,0 +1,232 @@
15747 +#
15748 +# Linux VServer configuration
15749 +#
15750 +
15751 +menu "Linux VServer"
15752 +
15753 +config VSERVER_AUTO_LBACK
15754 +       bool    "Automatically Assign Loopback IP"
15755 +       default y
15756 +       help
15757 +         Automatically assign a guest specific loopback
15758 +         IP and add it to the kernel network stack on
15759 +         startup.
15760 +
15761 +config VSERVER_AUTO_SINGLE
15762 +       bool    "Automatic Single IP Special Casing"
15763 +       depends on EXPERIMENTAL
15764 +       default y
15765 +       help
15766 +         This allows network contexts with a single IP to
15767 +         automatically remap 0.0.0.0 bindings to that IP,
15768 +         avoiding further network checks and improving
15769 +         performance.
15770 +
15771 +         (note: such guests do not allow to change the ip
15772 +          on the fly and do not show loopback addresses)
15773 +
15774 +config VSERVER_COWBL
15775 +       bool    "Enable COW Immutable Link Breaking"
15776 +       default y
15777 +       help
15778 +         This enables the COW (Copy-On-Write) link break code.
15779 +         It allows you to treat unified files like normal files
15780 +         when writing to them (which will implicitely break the
15781 +         link and create a copy of the unified file)
15782 +
15783 +config VSERVER_VTIME
15784 +       bool    "Enable Virtualized Guest Time"
15785 +       depends on EXPERIMENTAL
15786 +       default n
15787 +       help
15788 +         This enables per guest time offsets to allow for
15789 +         adjusting the system clock individually per guest.
15790 +         this adds some overhead to the time functions and
15791 +         therefore should not be enabled without good reason.
15792 +
15793 +config VSERVER_DEVICE
15794 +       bool    "Enable Guest Device Mapping"
15795 +       depends on EXPERIMENTAL
15796 +       default n
15797 +       help
15798 +         This enables generic device remapping.
15799 +
15800 +config VSERVER_PROC_SECURE
15801 +       bool    "Enable Proc Security"
15802 +       depends on PROC_FS
15803 +       default y
15804 +       help
15805 +         This configures ProcFS security to initially hide
15806 +         non-process entries for all contexts except the main and
15807 +         spectator context (i.e. for all guests), which is a secure
15808 +         default.
15809 +
15810 +         (note: on 1.2x the entries were visible by default)
15811 +
15812 +choice
15813 +       prompt  "Persistent Inode Tagging"
15814 +       default TAGGING_ID24
15815 +       help
15816 +         This adds persistent context information to filesystems
15817 +         mounted with the tagxid option. Tagging is a requirement
15818 +         for per-context disk limits and per-context quota.
15819 +
15820 +
15821 +config TAGGING_NONE
15822 +       bool    "Disabled"
15823 +       help
15824 +         do not store per-context information in inodes.
15825 +
15826 +config TAGGING_UID16
15827 +       bool    "UID16/GID32"
15828 +       help
15829 +         reduces UID to 16 bit, but leaves GID at 32 bit.
15830 +
15831 +config TAGGING_GID16
15832 +       bool    "UID32/GID16"
15833 +       help
15834 +         reduces GID to 16 bit, but leaves UID at 32 bit.
15835 +
15836 +config TAGGING_ID24
15837 +       bool    "UID24/GID24"
15838 +       help
15839 +         uses the upper 8bit from UID and GID for XID tagging
15840 +         which leaves 24bit for UID/GID each, which should be
15841 +         more than sufficient for normal use.
15842 +
15843 +config TAGGING_INTERN
15844 +       bool    "UID32/GID32"
15845 +       help
15846 +         this uses otherwise reserved inode fields in the on
15847 +         disk representation, which limits the use to a few
15848 +         filesystems (currently ext2 and ext3)
15849 +
15850 +endchoice
15851 +
15852 +config TAG_NFSD
15853 +       bool    "Tag NFSD User Auth and Files"
15854 +       default n
15855 +       help
15856 +         Enable this if you do want the in-kernel NFS
15857 +         Server to use the tagging specified above.
15858 +         (will require patched clients too)
15859 +
15860 +config VSERVER_PRIVACY
15861 +       bool    "Honor Privacy Aspects of Guests"
15862 +       default n
15863 +       help
15864 +         When enabled, most context checks will disallow
15865 +         access to structures assigned to a specific context,
15866 +         like ptys or loop devices.
15867 +
15868 +config VSERVER_CONTEXTS
15869 +       int     "Maximum number of Contexts (1-65533)"  if EMBEDDED
15870 +       range 1 65533
15871 +       default "768"   if 64BIT
15872 +       default "256"
15873 +       help
15874 +         This setting will optimize certain data structures
15875 +         and memory allocations according to the expected
15876 +         maximum.
15877 +
15878 +         note: this is not a strict upper limit.
15879 +
15880 +config VSERVER_WARN
15881 +       bool    "VServer Warnings"
15882 +       default y
15883 +       help
15884 +         This enables various runtime warnings, which will
15885 +         notify about potential manipulation attempts or
15886 +         resource shortage. It is generally considered to
15887 +         be a good idea to have that enabled.
15888 +
15889 +config VSERVER_WARN_DEVPTS
15890 +       bool    "VServer DevPTS Warnings"
15891 +       depends on VSERVER_WARN
15892 +       default y
15893 +       help
15894 +         This enables DevPTS related warnings, issued when a
15895 +         process inside a context tries to lookup or access
15896 +         a dynamic pts from the host or a different context.
15897 +
15898 +config VSERVER_DEBUG
15899 +       bool    "VServer Debugging Code"
15900 +       default n
15901 +       help
15902 +         Set this to yes if you want to be able to activate
15903 +         debugging output at runtime. It adds a very small
15904 +         overhead to all vserver related functions and
15905 +         increases the kernel size by about 20k.
15906 +
15907 +config VSERVER_HISTORY
15908 +       bool    "VServer History Tracing"
15909 +       depends on VSERVER_DEBUG
15910 +       default n
15911 +       help
15912 +         Set this to yes if you want to record the history of
15913 +         linux-vserver activities, so they can be replayed in
15914 +         the event of a kernel panic or oops.
15915 +
15916 +config VSERVER_HISTORY_SIZE
15917 +       int     "Per-CPU History Size (32-65536)"
15918 +       depends on VSERVER_HISTORY
15919 +       range 32 65536
15920 +       default 64
15921 +       help
15922 +         This allows you to specify the number of entries in
15923 +         the per-CPU history buffer.
15924 +
15925 +config VSERVER_LEGACY_MEM
15926 +       bool    "Legacy Memory Limits"
15927 +       default n
15928 +       help
15929 +         This provides fake memory limits to keep
15930 +         older tools happy in the face of memory
15931 +         cgroups
15932 +
15933 +choice
15934 +       prompt  "Quotes used in debug and warn messages"
15935 +       default QUOTES_ISO8859
15936 +
15937 +config QUOTES_ISO8859
15938 +       bool    "Extended ASCII (ISO 8859) angle quotes"
15939 +       help
15940 +         This uses the extended ASCII characters \xbb
15941 +         and \xab for quoting file and process names.
15942 +
15943 +config QUOTES_UTF8
15944 +       bool    "UTF-8 angle quotes"
15945 +       help
15946 +         This uses the the UTF-8 sequences for angle
15947 +         quotes to quote file and process names.
15948 +
15949 +config QUOTES_ASCII
15950 +       bool    "ASCII single quotes"
15951 +       help
15952 +         This uses the ASCII single quote character
15953 +         (\x27) to quote file and process names.
15954 +
15955 +endchoice
15956 +
15957 +endmenu
15958 +
15959 +
15960 +config VSERVER
15961 +       bool
15962 +       default y
15963 +       select NAMESPACES
15964 +       select UTS_NS
15965 +       select IPC_NS
15966 +#      select USER_NS
15967 +       select SYSVIPC
15968 +
15969 +config VSERVER_SECURITY
15970 +       bool
15971 +       depends on SECURITY
15972 +       default y
15973 +       select SECURITY_CAPABILITIES
15974 +
15975 +config VSERVER_DISABLED
15976 +       bool
15977 +       default n
15978 +
15979 diff -NurpP --minimal linux-3.0.25/kernel/vserver/Makefile linux-3.0.25-vs2.3.2.3/kernel/vserver/Makefile
15980 --- linux-3.0.25/kernel/vserver/Makefile        1970-01-01 01:00:00.000000000 +0100
15981 +++ linux-3.0.25-vs2.3.2.3/kernel/vserver/Makefile      2011-06-10 22:11:24.000000000 +0200
15982 @@ -0,0 +1,18 @@
15983 +#
15984 +# Makefile for the Linux vserver routines.
15985 +#
15986 +
15987 +
15988 +obj-y          += vserver.o
15989 +
15990 +vserver-y      := switch.o context.o space.o sched.o network.o inode.o \
15991 +                  limit.o cvirt.o cacct.o signal.o helper.o init.o \
15992 +                  dlimit.o tag.o
15993 +
15994 +vserver-$(CONFIG_INET) += inet.o
15995 +vserver-$(CONFIG_PROC_FS) += proc.o
15996 +vserver-$(CONFIG_VSERVER_DEBUG) += sysctl.o debug.o
15997 +vserver-$(CONFIG_VSERVER_HISTORY) += history.o
15998 +vserver-$(CONFIG_VSERVER_MONITOR) += monitor.o
15999 +vserver-$(CONFIG_VSERVER_DEVICE) += device.o
16000 +
16001 diff -NurpP --minimal linux-3.0.25/kernel/vserver/cacct.c linux-3.0.25-vs2.3.2.3/kernel/vserver/cacct.c
16002 --- linux-3.0.25/kernel/vserver/cacct.c 1970-01-01 01:00:00.000000000 +0100
16003 +++ linux-3.0.25-vs2.3.2.3/kernel/vserver/cacct.c       2011-06-10 22:11:24.000000000 +0200
16004 @@ -0,0 +1,42 @@
16005 +/*
16006 + *  linux/kernel/vserver/cacct.c
16007 + *
16008 + *  Virtual Server: Context Accounting
16009 + *
16010 + *  Copyright (C) 2006-2007 Herbert Pötzl
16011 + *
16012 + *  V0.01  added accounting stats
16013 + *
16014 + */
16015 +
16016 +#include <linux/types.h>
16017 +#include <linux/vs_context.h>
16018 +#include <linux/vserver/cacct_cmd.h>
16019 +#include <linux/vserver/cacct_int.h>
16020 +
16021 +#include <asm/errno.h>
16022 +#include <asm/uaccess.h>
16023 +
16024 +
16025 +int vc_sock_stat(struct vx_info *vxi, void __user *data)
16026 +{
16027 +       struct vcmd_sock_stat_v0 vc_data;
16028 +       int j, field;
16029 +
16030 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16031 +               return -EFAULT;
16032 +
16033 +       field = vc_data.field;
16034 +       if ((field < 0) || (field >= VXA_SOCK_SIZE))
16035 +               return -EINVAL;
16036 +
16037 +       for (j = 0; j < 3; j++) {
16038 +               vc_data.count[j] = vx_sock_count(&vxi->cacct, field, j);
16039 +               vc_data.total[j] = vx_sock_total(&vxi->cacct, field, j);
16040 +       }
16041 +
16042 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16043 +               return -EFAULT;
16044 +       return 0;
16045 +}
16046 +
16047 diff -NurpP --minimal linux-3.0.25/kernel/vserver/cacct_init.h linux-3.0.25-vs2.3.2.3/kernel/vserver/cacct_init.h
16048 --- linux-3.0.25/kernel/vserver/cacct_init.h    1970-01-01 01:00:00.000000000 +0100
16049 +++ linux-3.0.25-vs2.3.2.3/kernel/vserver/cacct_init.h  2011-06-10 22:11:24.000000000 +0200
16050 @@ -0,0 +1,25 @@
16051 +
16052 +
16053 +static inline void vx_info_init_cacct(struct _vx_cacct *cacct)
16054 +{
16055 +       int i, j;
16056 +
16057 +
16058 +       for (i = 0; i < VXA_SOCK_SIZE; i++) {
16059 +               for (j = 0; j < 3; j++) {
16060 +                       atomic_long_set(&cacct->sock[i][j].count, 0);
16061 +                       atomic_long_set(&cacct->sock[i][j].total, 0);
16062 +               }
16063 +       }
16064 +       for (i = 0; i < 8; i++)
16065 +               atomic_set(&cacct->slab[i], 0);
16066 +       for (i = 0; i < 5; i++)
16067 +               for (j = 0; j < 4; j++)
16068 +                       atomic_set(&cacct->page[i][j], 0);
16069 +}
16070 +
16071 +static inline void vx_info_exit_cacct(struct _vx_cacct *cacct)
16072 +{
16073 +       return;
16074 +}
16075 +
16076 diff -NurpP --minimal linux-3.0.25/kernel/vserver/cacct_proc.h linux-3.0.25-vs2.3.2.3/kernel/vserver/cacct_proc.h
16077 --- linux-3.0.25/kernel/vserver/cacct_proc.h    1970-01-01 01:00:00.000000000 +0100
16078 +++ linux-3.0.25-vs2.3.2.3/kernel/vserver/cacct_proc.h  2011-06-10 22:11:24.000000000 +0200
16079 @@ -0,0 +1,53 @@
16080 +#ifndef _VX_CACCT_PROC_H
16081 +#define _VX_CACCT_PROC_H
16082 +
16083 +#include <linux/vserver/cacct_int.h>
16084 +
16085 +
16086 +#define VX_SOCKA_TOP   \
16087 +       "Type\t    recv #/bytes\t\t   send #/bytes\t\t    fail #/bytes\n"
16088 +
16089 +static inline int vx_info_proc_cacct(struct _vx_cacct *cacct, char *buffer)
16090 +{
16091 +       int i, j, length = 0;
16092 +       static char *type[VXA_SOCK_SIZE] = {
16093 +               "UNSPEC", "UNIX", "INET", "INET6", "PACKET", "OTHER"
16094 +       };
16095 +
16096 +       length += sprintf(buffer + length, VX_SOCKA_TOP);
16097 +       for (i = 0; i < VXA_SOCK_SIZE; i++) {
16098 +               length += sprintf(buffer + length, "%s:", type[i]);
16099 +               for (j = 0; j < 3; j++) {
16100 +                       length += sprintf(buffer + length,
16101 +                               "\t%10lu/%-10lu",
16102 +                               vx_sock_count(cacct, i, j),
16103 +                               vx_sock_total(cacct, i, j));
16104 +               }
16105 +               buffer[length++] = '\n';
16106 +       }
16107 +
16108 +       length += sprintf(buffer + length, "\n");
16109 +       length += sprintf(buffer + length,
16110 +               "slab:\t %8u %8u %8u %8u\n",
16111 +               atomic_read(&cacct->slab[1]),
16112 +               atomic_read(&cacct->slab[4]),
16113 +               atomic_read(&cacct->slab[0]),
16114 +               atomic_read(&cacct->slab[2]));
16115 +
16116 +       length += sprintf(buffer + length, "\n");
16117 +       for (i = 0; i < 5; i++) {
16118 +               length += sprintf(buffer + length,
16119 +                       "page[%d]: %8u %8u %8u %8u\t %8u %8u %8u %8u\n", i,
16120 +                       atomic_read(&cacct->page[i][0]),
16121 +                       atomic_read(&cacct->page[i][1]),
16122 +                       atomic_read(&cacct->page[i][2]),
16123 +                       atomic_read(&cacct->page[i][3]),
16124 +                       atomic_read(&cacct->page[i][4]),
16125 +                       atomic_read(&cacct->page[i][5]),
16126 +                       atomic_read(&cacct->page[i][6]),
16127 +                       atomic_read(&cacct->page[i][7]));
16128 +       }
16129 +       return length;
16130 +}
16131 +
16132 +#endif /* _VX_CACCT_PROC_H */
16133 diff -NurpP --minimal linux-3.0.25/kernel/vserver/context.c linux-3.0.25-vs2.3.2.3/kernel/vserver/context.c
16134 --- linux-3.0.25/kernel/vserver/context.c       1970-01-01 01:00:00.000000000 +0100
16135 +++ linux-3.0.25-vs2.3.2.3/kernel/vserver/context.c     2011-08-01 18:28:12.000000000 +0200
16136 @@ -0,0 +1,1107 @@
16137 +/*
16138 + *  linux/kernel/vserver/context.c
16139 + *
16140 + *  Virtual Server: Context Support
16141 + *
16142 + *  Copyright (C) 2003-2011  Herbert Pötzl
16143 + *
16144 + *  V0.01  context helper
16145 + *  V0.02  vx_ctx_kill syscall command
16146 + *  V0.03  replaced context_info calls
16147 + *  V0.04  redesign of struct (de)alloc
16148 + *  V0.05  rlimit basic implementation
16149 + *  V0.06  task_xid and info commands
16150 + *  V0.07  context flags and caps
16151 + *  V0.08  switch to RCU based hash
16152 + *  V0.09  revert to non RCU for now
16153 + *  V0.10  and back to working RCU hash
16154 + *  V0.11  and back to locking again
16155 + *  V0.12  referenced context store
16156 + *  V0.13  separate per cpu data
16157 + *  V0.14  changed vcmds to vxi arg
16158 + *  V0.15  added context stat
16159 + *  V0.16  have __create claim() the vxi
16160 + *  V0.17  removed older and legacy stuff
16161 + *  V0.18  added user credentials
16162 + *  V0.19  added warn mask
16163 + *
16164 + */
16165 +
16166 +#include <linux/slab.h>
16167 +#include <linux/types.h>
16168 +#include <linux/security.h>
16169 +#include <linux/pid_namespace.h>
16170 +#include <linux/capability.h>
16171 +
16172 +#include <linux/vserver/context.h>
16173 +#include <linux/vserver/network.h>
16174 +#include <linux/vserver/debug.h>
16175 +#include <linux/vserver/limit.h>
16176 +#include <linux/vserver/limit_int.h>
16177 +#include <linux/vserver/space.h>
16178 +#include <linux/init_task.h>
16179 +#include <linux/fs_struct.h>
16180 +#include <linux/cred.h>
16181 +
16182 +#include <linux/vs_context.h>
16183 +#include <linux/vs_limit.h>
16184 +#include <linux/vs_pid.h>
16185 +#include <linux/vserver/context_cmd.h>
16186 +
16187 +#include "cvirt_init.h"
16188 +#include "cacct_init.h"
16189 +#include "limit_init.h"
16190 +#include "sched_init.h"
16191 +
16192 +
16193 +atomic_t vx_global_ctotal      = ATOMIC_INIT(0);
16194 +atomic_t vx_global_cactive     = ATOMIC_INIT(0);
16195 +
16196 +
16197 +/*     now inactive context structures */
16198 +
16199 +static struct hlist_head vx_info_inactive = HLIST_HEAD_INIT;
16200 +
16201 +static DEFINE_SPINLOCK(vx_info_inactive_lock);
16202 +
16203 +
16204 +/*     __alloc_vx_info()
16205 +
16206 +       * allocate an initialized vx_info struct
16207 +       * doesn't make it visible (hash)                        */
16208 +
16209 +static struct vx_info *__alloc_vx_info(xid_t xid)
16210 +{
16211 +       struct vx_info *new = NULL;
16212 +       int cpu, index;
16213 +
16214 +       vxdprintk(VXD_CBIT(xid, 0), "alloc_vx_info(%d)*", xid);
16215 +
16216 +       /* would this benefit from a slab cache? */
16217 +       new = kmalloc(sizeof(struct vx_info), GFP_KERNEL);
16218 +       if (!new)
16219 +               return 0;
16220 +
16221 +       memset(new, 0, sizeof(struct vx_info));
16222 +#ifdef CONFIG_SMP
16223 +       new->ptr_pc = alloc_percpu(struct _vx_info_pc);
16224 +       if (!new->ptr_pc)
16225 +               goto error;
16226 +#endif
16227 +       new->vx_id = xid;
16228 +       INIT_HLIST_NODE(&new->vx_hlist);
16229 +       atomic_set(&new->vx_usecnt, 0);
16230 +       atomic_set(&new->vx_tasks, 0);
16231 +       new->vx_parent = NULL;
16232 +       new->vx_state = 0;
16233 +       init_waitqueue_head(&new->vx_wait);
16234 +
16235 +       /* prepare reaper */
16236 +       get_task_struct(init_pid_ns.child_reaper);
16237 +       new->vx_reaper = init_pid_ns.child_reaper;
16238 +       new->vx_badness_bias = 0;
16239 +
16240 +       /* rest of init goes here */
16241 +       vx_info_init_limit(&new->limit);
16242 +       vx_info_init_sched(&new->sched);
16243 +       vx_info_init_cvirt(&new->cvirt);
16244 +       vx_info_init_cacct(&new->cacct);
16245 +
16246 +       /* per cpu data structures */
16247 +       for_each_possible_cpu(cpu) {
16248 +               vx_info_init_sched_pc(
16249 +                       &vx_per_cpu(new, sched_pc, cpu), cpu);
16250 +               vx_info_init_cvirt_pc(
16251 +                       &vx_per_cpu(new, cvirt_pc, cpu), cpu);
16252 +       }
16253 +
16254 +       new->vx_flags = VXF_INIT_SET;
16255 +       new->vx_bcaps = CAP_FULL_SET;   // maybe ~CAP_SETPCAP
16256 +       new->vx_ccaps = 0;
16257 +       new->vx_umask = 0;
16258 +       new->vx_wmask = 0;
16259 +
16260 +       new->reboot_cmd = 0;
16261 +       new->exit_code = 0;
16262 +
16263 +       // preconfig spaces
16264 +       for (index = 0; index < VX_SPACES; index++) {
16265 +               struct _vx_space *space = &new->space[index];
16266 +
16267 +               // filesystem
16268 +               spin_lock(&init_fs.lock);
16269 +               init_fs.users++;
16270 +               spin_unlock(&init_fs.lock);
16271 +               space->vx_fs = &init_fs;
16272 +
16273 +               /* FIXME: do we want defaults? */
16274 +               // space->vx_real_cred = 0;
16275 +               // space->vx_cred = 0;
16276 +       }
16277 +
16278 +
16279 +       vxdprintk(VXD_CBIT(xid, 0),
16280 +               "alloc_vx_info(%d) = %p", xid, new);
16281 +       vxh_alloc_vx_info(new);
16282 +       atomic_inc(&vx_global_ctotal);
16283 +       return new;
16284 +#ifdef CONFIG_SMP
16285 +error:
16286 +       kfree(new);
16287 +       return 0;
16288 +#endif
16289 +}
16290 +
16291 +/*     __dealloc_vx_info()
16292 +
16293 +       * final disposal of vx_info                             */
16294 +
16295 +static void __dealloc_vx_info(struct vx_info *vxi)
16296 +{
16297 +#ifdef CONFIG_VSERVER_WARN
16298 +       struct vx_info_save vxis;
16299 +       int cpu;
16300 +#endif
16301 +       vxdprintk(VXD_CBIT(xid, 0),
16302 +               "dealloc_vx_info(%p)", vxi);
16303 +       vxh_dealloc_vx_info(vxi);
16304 +
16305 +#ifdef CONFIG_VSERVER_WARN
16306 +       enter_vx_info(vxi, &vxis);
16307 +       vx_info_exit_limit(&vxi->limit);
16308 +       vx_info_exit_sched(&vxi->sched);
16309 +       vx_info_exit_cvirt(&vxi->cvirt);
16310 +       vx_info_exit_cacct(&vxi->cacct);
16311 +
16312 +       for_each_possible_cpu(cpu) {
16313 +               vx_info_exit_sched_pc(
16314 +                       &vx_per_cpu(vxi, sched_pc, cpu), cpu);
16315 +               vx_info_exit_cvirt_pc(
16316 +                       &vx_per_cpu(vxi, cvirt_pc, cpu), cpu);
16317 +       }
16318 +       leave_vx_info(&vxis);
16319 +#endif
16320 +
16321 +       vxi->vx_id = -1;
16322 +       vxi->vx_state |= VXS_RELEASED;
16323 +
16324 +#ifdef CONFIG_SMP
16325 +       free_percpu(vxi->ptr_pc);
16326 +#endif
16327 +       kfree(vxi);
16328 +       atomic_dec(&vx_global_ctotal);
16329 +}
16330 +
16331 +static void __shutdown_vx_info(struct vx_info *vxi)
16332 +{
16333 +       struct nsproxy *nsproxy;
16334 +       struct fs_struct *fs;
16335 +       struct cred *cred;
16336 +       int index, kill;
16337 +
16338 +       might_sleep();
16339 +
16340 +       vxi->vx_state |= VXS_SHUTDOWN;
16341 +       vs_state_change(vxi, VSC_SHUTDOWN);
16342 +
16343 +       for (index = 0; index < VX_SPACES; index++) {
16344 +               struct _vx_space *space = &vxi->space[index];
16345 +
16346 +               nsproxy = xchg(&space->vx_nsproxy, NULL);
16347 +               if (nsproxy)
16348 +                       put_nsproxy(nsproxy);
16349 +
16350 +               fs = xchg(&space->vx_fs, NULL);
16351 +               spin_lock(&fs->lock);
16352 +               kill = !--fs->users;
16353 +               spin_unlock(&fs->lock);
16354 +               if (kill)
16355 +                       free_fs_struct(fs);
16356 +
16357 +               cred = (struct cred *)xchg(&space->vx_cred, NULL);
16358 +               if (cred)
16359 +                       abort_creds(cred);
16360 +       }
16361 +}
16362 +
16363 +/* exported stuff */
16364 +
16365 +void free_vx_info(struct vx_info *vxi)
16366 +{
16367 +       unsigned long flags;
16368 +       unsigned index;
16369 +
16370 +       /* check for reference counts first */
16371 +       BUG_ON(atomic_read(&vxi->vx_usecnt));
16372 +       BUG_ON(atomic_read(&vxi->vx_tasks));
16373 +
16374 +       /* context must not be hashed */
16375 +       BUG_ON(vx_info_state(vxi, VXS_HASHED));
16376 +
16377 +       /* context shutdown is mandatory */
16378 +       BUG_ON(!vx_info_state(vxi, VXS_SHUTDOWN));
16379 +
16380 +       /* spaces check */
16381 +       for (index = 0; index < VX_SPACES; index++) {
16382 +               struct _vx_space *space = &vxi->space[index];
16383 +
16384 +               BUG_ON(space->vx_nsproxy);
16385 +               BUG_ON(space->vx_fs);
16386 +               // BUG_ON(space->vx_real_cred);
16387 +               // BUG_ON(space->vx_cred);
16388 +       }
16389 +
16390 +       spin_lock_irqsave(&vx_info_inactive_lock, flags);
16391 +       hlist_del(&vxi->vx_hlist);
16392 +       spin_unlock_irqrestore(&vx_info_inactive_lock, flags);
16393 +
16394 +       __dealloc_vx_info(vxi);
16395 +}
16396 +
16397 +
16398 +/*     hash table for vx_info hash */
16399 +
16400 +#define VX_HASH_SIZE   13
16401 +
16402 +static struct hlist_head vx_info_hash[VX_HASH_SIZE] =
16403 +       { [0 ... VX_HASH_SIZE-1] = HLIST_HEAD_INIT };
16404 +
16405 +static DEFINE_SPINLOCK(vx_info_hash_lock);
16406 +
16407 +
16408 +static inline unsigned int __hashval(xid_t xid)
16409 +{
16410 +       return (xid % VX_HASH_SIZE);
16411 +}
16412 +
16413 +
16414 +
16415 +/*     __hash_vx_info()
16416 +
16417 +       * add the vxi to the global hash table
16418 +       * requires the hash_lock to be held                     */
16419 +
16420 +static inline void __hash_vx_info(struct vx_info *vxi)
16421 +{
16422 +       struct hlist_head *head;
16423 +
16424 +       vxd_assert_lock(&vx_info_hash_lock);
16425 +       vxdprintk(VXD_CBIT(xid, 4),
16426 +               "__hash_vx_info: %p[#%d]", vxi, vxi->vx_id);
16427 +       vxh_hash_vx_info(vxi);
16428 +
16429 +       /* context must not be hashed */
16430 +       BUG_ON(vx_info_state(vxi, VXS_HASHED));
16431 +
16432 +       vxi->vx_state |= VXS_HASHED;
16433 +       head = &vx_info_hash[__hashval(vxi->vx_id)];
16434 +       hlist_add_head(&vxi->vx_hlist, head);
16435 +       atomic_inc(&vx_global_cactive);
16436 +}
16437 +
16438 +/*     __unhash_vx_info()
16439 +
16440 +       * remove the vxi from the global hash table
16441 +       * requires the hash_lock to be held                     */
16442 +
16443 +static inline void __unhash_vx_info(struct vx_info *vxi)
16444 +{
16445 +       unsigned long flags;
16446 +
16447 +       vxd_assert_lock(&vx_info_hash_lock);
16448 +       vxdprintk(VXD_CBIT(xid, 4),
16449 +               "__unhash_vx_info: %p[#%d.%d.%d]", vxi, vxi->vx_id,
16450 +               atomic_read(&vxi->vx_usecnt), atomic_read(&vxi->vx_tasks));
16451 +       vxh_unhash_vx_info(vxi);
16452 +
16453 +       /* context must be hashed */
16454 +       BUG_ON(!vx_info_state(vxi, VXS_HASHED));
16455 +       /* but without tasks */
16456 +       BUG_ON(atomic_read(&vxi->vx_tasks));
16457 +
16458 +       vxi->vx_state &= ~VXS_HASHED;
16459 +       hlist_del_init(&vxi->vx_hlist);
16460 +       spin_lock_irqsave(&vx_info_inactive_lock, flags);
16461 +       hlist_add_head(&vxi->vx_hlist, &vx_info_inactive);
16462 +       spin_unlock_irqrestore(&vx_info_inactive_lock, flags);
16463 +       atomic_dec(&vx_global_cactive);
16464 +}
16465 +
16466 +
16467 +/*     __lookup_vx_info()
16468 +
16469 +       * requires the hash_lock to be held
16470 +       * doesn't increment the vx_refcnt                       */
16471 +
16472 +static inline struct vx_info *__lookup_vx_info(xid_t xid)
16473 +{
16474 +       struct hlist_head *head = &vx_info_hash[__hashval(xid)];
16475 +       struct hlist_node *pos;
16476 +       struct vx_info *vxi;
16477 +
16478 +       vxd_assert_lock(&vx_info_hash_lock);
16479 +       hlist_for_each(pos, head) {
16480 +               vxi = hlist_entry(pos, struct vx_info, vx_hlist);
16481 +
16482 +               if (vxi->vx_id == xid)
16483 +                       goto found;
16484 +       }
16485 +       vxi = NULL;
16486 +found:
16487 +       vxdprintk(VXD_CBIT(xid, 0),
16488 +               "__lookup_vx_info(#%u): %p[#%u]",
16489 +               xid, vxi, vxi ? vxi->vx_id : 0);
16490 +       vxh_lookup_vx_info(vxi, xid);
16491 +       return vxi;
16492 +}
16493 +
16494 +
16495 +/*     __create_vx_info()
16496 +
16497 +       * create the requested context
16498 +       * get(), claim() and hash it                            */
16499 +
16500 +static struct vx_info *__create_vx_info(int id)
16501 +{
16502 +       struct vx_info *new, *vxi = NULL;
16503 +
16504 +       vxdprintk(VXD_CBIT(xid, 1), "create_vx_info(%d)*", id);
16505 +
16506 +       if (!(new = __alloc_vx_info(id)))
16507 +               return ERR_PTR(-ENOMEM);
16508 +
16509 +       /* required to make dynamic xids unique */
16510 +       spin_lock(&vx_info_hash_lock);
16511 +
16512 +       /* static context requested */
16513 +       if ((vxi = __lookup_vx_info(id))) {
16514 +               vxdprintk(VXD_CBIT(xid, 0),
16515 +                       "create_vx_info(%d) = %p (already there)", id, vxi);
16516 +               if (vx_info_flags(vxi, VXF_STATE_SETUP, 0))
16517 +                       vxi = ERR_PTR(-EBUSY);
16518 +               else
16519 +                       vxi = ERR_PTR(-EEXIST);
16520 +               goto out_unlock;
16521 +       }
16522 +       /* new context */
16523 +       vxdprintk(VXD_CBIT(xid, 0),
16524 +               "create_vx_info(%d) = %p (new)", id, new);
16525 +       claim_vx_info(new, NULL);
16526 +       __hash_vx_info(get_vx_info(new));
16527 +       vxi = new, new = NULL;
16528 +
16529 +out_unlock:
16530 +       spin_unlock(&vx_info_hash_lock);
16531 +       vxh_create_vx_info(IS_ERR(vxi) ? NULL : vxi, id);
16532 +       if (new)
16533 +               __dealloc_vx_info(new);
16534 +       return vxi;
16535 +}
16536 +
16537 +
16538 +/*     exported stuff                                          */
16539 +
16540 +
16541 +void unhash_vx_info(struct vx_info *vxi)
16542 +{
16543 +       spin_lock(&vx_info_hash_lock);
16544 +       __unhash_vx_info(vxi);
16545 +       spin_unlock(&vx_info_hash_lock);
16546 +       __shutdown_vx_info(vxi);
16547 +       __wakeup_vx_info(vxi);
16548 +}
16549 +
16550 +
16551 +/*     lookup_vx_info()
16552 +
16553 +       * search for a vx_info and get() it
16554 +       * negative id means current                             */
16555 +
16556 +struct vx_info *lookup_vx_info(int id)
16557 +{
16558 +       struct vx_info *vxi = NULL;
16559 +
16560 +       if (id < 0) {
16561 +               vxi = get_vx_info(current_vx_info());
16562 +       } else if (id > 1) {
16563 +               spin_lock(&vx_info_hash_lock);
16564 +               vxi = get_vx_info(__lookup_vx_info(id));
16565 +               spin_unlock(&vx_info_hash_lock);
16566 +       }
16567 +       return vxi;
16568 +}
16569 +
16570 +/*     xid_is_hashed()
16571 +
16572 +       * verify that xid is still hashed                       */
16573 +
16574 +int xid_is_hashed(xid_t xid)
16575 +{
16576 +       int hashed;
16577 +
16578 +       spin_lock(&vx_info_hash_lock);
16579 +       hashed = (__lookup_vx_info(xid) != NULL);
16580 +       spin_unlock(&vx_info_hash_lock);
16581 +       return hashed;
16582 +}
16583 +
16584 +#ifdef CONFIG_PROC_FS
16585 +
16586 +/*     get_xid_list()
16587 +
16588 +       * get a subset of hashed xids for proc
16589 +       * assumes size is at least one                          */
16590 +
16591 +int get_xid_list(int index, unsigned int *xids, int size)
16592 +{
16593 +       int hindex, nr_xids = 0;
16594 +
16595 +       /* only show current and children */
16596 +       if (!vx_check(0, VS_ADMIN | VS_WATCH)) {
16597 +               if (index > 0)
16598 +                       return 0;
16599 +               xids[nr_xids] = vx_current_xid();
16600 +               return 1;
16601 +       }
16602 +
16603 +       for (hindex = 0; hindex < VX_HASH_SIZE; hindex++) {
16604 +               struct hlist_head *head = &vx_info_hash[hindex];
16605 +               struct hlist_node *pos;
16606 +
16607 +               spin_lock(&vx_info_hash_lock);
16608 +               hlist_for_each(pos, head) {
16609 +                       struct vx_info *vxi;
16610 +
16611 +                       if (--index > 0)
16612 +                               continue;
16613 +
16614 +                       vxi = hlist_entry(pos, struct vx_info, vx_hlist);
16615 +                       xids[nr_xids] = vxi->vx_id;
16616 +                       if (++nr_xids >= size) {
16617 +                               spin_unlock(&vx_info_hash_lock);
16618 +                               goto out;
16619 +                       }
16620 +               }
16621 +               /* keep the lock time short */
16622 +               spin_unlock(&vx_info_hash_lock);
16623 +       }
16624 +out:
16625 +       return nr_xids;
16626 +}
16627 +#endif
16628 +
16629 +#ifdef CONFIG_VSERVER_DEBUG
16630 +
16631 +void   dump_vx_info_inactive(int level)
16632 +{
16633 +       struct hlist_node *entry, *next;
16634 +
16635 +       hlist_for_each_safe(entry, next, &vx_info_inactive) {
16636 +               struct vx_info *vxi =
16637 +                       list_entry(entry, struct vx_info, vx_hlist);
16638 +
16639 +               dump_vx_info(vxi, level);
16640 +       }
16641 +}
16642 +
16643 +#endif
16644 +
16645 +#if 0
16646 +int vx_migrate_user(struct task_struct *p, struct vx_info *vxi)
16647 +{
16648 +       struct user_struct *new_user, *old_user;
16649 +
16650 +       if (!p || !vxi)
16651 +               BUG();
16652 +
16653 +       if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0))
16654 +               return -EACCES;
16655 +
16656 +       new_user = alloc_uid(vxi->vx_id, p->uid);
16657 +       if (!new_user)
16658 +               return -ENOMEM;
16659 +
16660 +       old_user = p->user;
16661 +       if (new_user != old_user) {
16662 +               atomic_inc(&new_user->processes);
16663 +               atomic_dec(&old_user->processes);
16664 +               p->user = new_user;
16665 +       }
16666 +       free_uid(old_user);
16667 +       return 0;
16668 +}
16669 +#endif
16670 +
16671 +#if 0
16672 +void vx_mask_cap_bset(struct vx_info *vxi, struct task_struct *p)
16673 +{
16674 +       // p->cap_effective &= vxi->vx_cap_bset;
16675 +       p->cap_effective =
16676 +               cap_intersect(p->cap_effective, vxi->cap_bset);
16677 +       // p->cap_inheritable &= vxi->vx_cap_bset;
16678 +       p->cap_inheritable =
16679 +               cap_intersect(p->cap_inheritable, vxi->cap_bset);
16680 +       // p->cap_permitted &= vxi->vx_cap_bset;
16681 +       p->cap_permitted =
16682 +               cap_intersect(p->cap_permitted, vxi->cap_bset);
16683 +}
16684 +#endif
16685 +
16686 +
16687 +#include <linux/file.h>
16688 +#include <linux/fdtable.h>
16689 +
16690 +static int vx_openfd_task(struct task_struct *tsk)
16691 +{
16692 +       struct files_struct *files = tsk->files;
16693 +       struct fdtable *fdt;
16694 +       const unsigned long *bptr;
16695 +       int count, total;
16696 +
16697 +       /* no rcu_read_lock() because of spin_lock() */
16698 +       spin_lock(&files->file_lock);
16699 +       fdt = files_fdtable(files);
16700 +       bptr = fdt->open_fds->fds_bits;
16701 +       count = fdt->max_fds / (sizeof(unsigned long) * 8);
16702 +       for (total = 0; count > 0; count--) {
16703 +               if (*bptr)
16704 +                       total += hweight_long(*bptr);
16705 +               bptr++;
16706 +       }
16707 +       spin_unlock(&files->file_lock);
16708 +       return total;
16709 +}
16710 +
16711 +
16712 +/*     for *space compatibility */
16713 +
16714 +asmlinkage long sys_unshare(unsigned long);
16715 +
16716 +/*
16717 + *     migrate task to new context
16718 + *     gets vxi, puts old_vxi on change
16719 + *     optionally unshares namespaces (hack)
16720 + */
16721 +
16722 +int vx_migrate_task(struct task_struct *p, struct vx_info *vxi, int unshare)
16723 +{
16724 +       struct vx_info *old_vxi;
16725 +       int ret = 0;
16726 +
16727 +       if (!p || !vxi)
16728 +               BUG();
16729 +
16730 +       vxdprintk(VXD_CBIT(xid, 5),
16731 +               "vx_migrate_task(%p,%p[#%d.%d])", p, vxi,
16732 +               vxi->vx_id, atomic_read(&vxi->vx_usecnt));
16733 +
16734 +       if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0) &&
16735 +               !vx_info_flags(vxi, VXF_STATE_SETUP, 0))
16736 +               return -EACCES;
16737 +
16738 +       if (vx_info_state(vxi, VXS_SHUTDOWN))
16739 +               return -EFAULT;
16740 +
16741 +       old_vxi = task_get_vx_info(p);
16742 +       if (old_vxi == vxi)
16743 +               goto out;
16744 +
16745 +//     if (!(ret = vx_migrate_user(p, vxi))) {
16746 +       {
16747 +               int openfd;
16748 +
16749 +               task_lock(p);
16750 +               openfd = vx_openfd_task(p);
16751 +
16752 +               if (old_vxi) {
16753 +                       atomic_dec(&old_vxi->cvirt.nr_threads);
16754 +                       atomic_dec(&old_vxi->cvirt.nr_running);
16755 +                       __rlim_dec(&old_vxi->limit, RLIMIT_NPROC);
16756 +                       /* FIXME: what about the struct files here? */
16757 +                       __rlim_sub(&old_vxi->limit, VLIMIT_OPENFD, openfd);
16758 +                       /* account for the executable */
16759 +                       __rlim_dec(&old_vxi->limit, VLIMIT_DENTRY);
16760 +               }
16761 +               atomic_inc(&vxi->cvirt.nr_threads);
16762 +               atomic_inc(&vxi->cvirt.nr_running);
16763 +               __rlim_inc(&vxi->limit, RLIMIT_NPROC);
16764 +               /* FIXME: what about the struct files here? */
16765 +               __rlim_add(&vxi->limit, VLIMIT_OPENFD, openfd);
16766 +               /* account for the executable */
16767 +               __rlim_inc(&vxi->limit, VLIMIT_DENTRY);
16768 +
16769 +               if (old_vxi) {
16770 +                       release_vx_info(old_vxi, p);
16771 +                       clr_vx_info(&p->vx_info);
16772 +               }
16773 +               claim_vx_info(vxi, p);
16774 +               set_vx_info(&p->vx_info, vxi);
16775 +               p->xid = vxi->vx_id;
16776 +
16777 +               vxdprintk(VXD_CBIT(xid, 5),
16778 +                       "moved task %p into vxi:%p[#%d]",
16779 +                       p, vxi, vxi->vx_id);
16780 +
16781 +               // vx_mask_cap_bset(vxi, p);
16782 +               task_unlock(p);
16783 +
16784 +               /* hack for *spaces to provide compatibility */
16785 +               if (unshare) {
16786 +                       struct nsproxy *old_nsp, *new_nsp;
16787 +
16788 +                       ret = unshare_nsproxy_namespaces(
16789 +                               CLONE_NEWUTS | CLONE_NEWIPC | CLONE_NEWUSER,
16790 +                               &new_nsp, NULL);
16791 +                       if (ret)
16792 +                               goto out;
16793 +
16794 +                       old_nsp = xchg(&p->nsproxy, new_nsp);
16795 +                       vx_set_space(vxi,
16796 +                               CLONE_NEWUTS | CLONE_NEWIPC | CLONE_NEWUSER, 0);
16797 +                       put_nsproxy(old_nsp);
16798 +               }
16799 +       }
16800 +out:
16801 +       put_vx_info(old_vxi);
16802 +       return ret;
16803 +}
16804 +
16805 +int vx_set_reaper(struct vx_info *vxi, struct task_struct *p)
16806 +{
16807 +       struct task_struct *old_reaper;
16808 +
16809 +       if (!vxi)
16810 +               return -EINVAL;
16811 +
16812 +       vxdprintk(VXD_CBIT(xid, 6),
16813 +               "vx_set_reaper(%p[#%d],%p[#%d,%d])",
16814 +               vxi, vxi->vx_id, p, p->xid, p->pid);
16815 +
16816 +       old_reaper = vxi->vx_reaper;
16817 +       if (old_reaper == p)
16818 +               return 0;
16819 +
16820 +       /* set new child reaper */
16821 +       get_task_struct(p);
16822 +       vxi->vx_reaper = p;
16823 +       put_task_struct(old_reaper);
16824 +       return 0;
16825 +}
16826 +
16827 +int vx_set_init(struct vx_info *vxi, struct task_struct *p)
16828 +{
16829 +       if (!vxi)
16830 +               return -EINVAL;
16831 +
16832 +       vxdprintk(VXD_CBIT(xid, 6),
16833 +               "vx_set_init(%p[#%d],%p[#%d,%d,%d])",
16834 +               vxi, vxi->vx_id, p, p->xid, p->pid, p->tgid);
16835 +
16836 +       vxi->vx_flags &= ~VXF_STATE_INIT;
16837 +       // vxi->vx_initpid = p->tgid;
16838 +       vxi->vx_initpid = p->pid;
16839 +       return 0;
16840 +}
16841 +
16842 +void vx_exit_init(struct vx_info *vxi, struct task_struct *p, int code)
16843 +{
16844 +       vxdprintk(VXD_CBIT(xid, 6),
16845 +               "vx_exit_init(%p[#%d],%p[#%d,%d,%d])",
16846 +               vxi, vxi->vx_id, p, p->xid, p->pid, p->tgid);
16847 +
16848 +       vxi->exit_code = code;
16849 +       vxi->vx_initpid = 0;
16850 +}
16851 +
16852 +
16853 +void vx_set_persistent(struct vx_info *vxi)
16854 +{
16855 +       vxdprintk(VXD_CBIT(xid, 6),
16856 +               "vx_set_persistent(%p[#%d])", vxi, vxi->vx_id);
16857 +
16858 +       get_vx_info(vxi);
16859 +       claim_vx_info(vxi, NULL);
16860 +}
16861 +
16862 +void vx_clear_persistent(struct vx_info *vxi)
16863 +{
16864 +       vxdprintk(VXD_CBIT(xid, 6),
16865 +               "vx_clear_persistent(%p[#%d])", vxi, vxi->vx_id);
16866 +
16867 +       release_vx_info(vxi, NULL);
16868 +       put_vx_info(vxi);
16869 +}
16870 +
16871 +void vx_update_persistent(struct vx_info *vxi)
16872 +{
16873 +       if (vx_info_flags(vxi, VXF_PERSISTENT, 0))
16874 +               vx_set_persistent(vxi);
16875 +       else
16876 +               vx_clear_persistent(vxi);
16877 +}
16878 +
16879 +
16880 +/*     task must be current or locked          */
16881 +
16882 +void   exit_vx_info(struct task_struct *p, int code)
16883 +{
16884 +       struct vx_info *vxi = p->vx_info;
16885 +
16886 +       if (vxi) {
16887 +               atomic_dec(&vxi->cvirt.nr_threads);
16888 +               vx_nproc_dec(p);
16889 +
16890 +               vxi->exit_code = code;
16891 +               release_vx_info(vxi, p);
16892 +       }
16893 +}
16894 +
16895 +void   exit_vx_info_early(struct task_struct *p, int code)
16896 +{
16897 +       struct vx_info *vxi = p->vx_info;
16898 +
16899 +       if (vxi) {
16900 +               if (vxi->vx_initpid == p->pid)
16901 +                       vx_exit_init(vxi, p, code);
16902 +               if (vxi->vx_reaper == p)
16903 +                       vx_set_reaper(vxi, init_pid_ns.child_reaper);
16904 +       }
16905 +}
16906 +
16907 +
16908 +/* vserver syscall commands below here */
16909 +
16910 +/* taks xid and vx_info functions */
16911 +
16912 +#include <asm/uaccess.h>
16913 +
16914 +
16915 +int vc_task_xid(uint32_t id)
16916 +{
16917 +       xid_t xid;
16918 +
16919 +       if (id) {
16920 +               struct task_struct *tsk;
16921 +
16922 +               rcu_read_lock();
16923 +               tsk = find_task_by_real_pid(id);
16924 +               xid = (tsk) ? tsk->xid : -ESRCH;
16925 +               rcu_read_unlock();
16926 +       } else
16927 +               xid = vx_current_xid();
16928 +       return xid;
16929 +}
16930 +
16931 +
16932 +int vc_vx_info(struct vx_info *vxi, void __user *data)
16933 +{
16934 +       struct vcmd_vx_info_v0 vc_data;
16935 +
16936 +       vc_data.xid = vxi->vx_id;
16937 +       vc_data.initpid = vxi->vx_initpid;
16938 +
16939 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16940 +               return -EFAULT;
16941 +       return 0;
16942 +}
16943 +
16944 +
16945 +int vc_ctx_stat(struct vx_info *vxi, void __user *data)
16946 +{
16947 +       struct vcmd_ctx_stat_v0 vc_data;
16948 +
16949 +       vc_data.usecnt = atomic_read(&vxi->vx_usecnt);
16950 +       vc_data.tasks = atomic_read(&vxi->vx_tasks);
16951 +
16952 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16953 +               return -EFAULT;
16954 +       return 0;
16955 +}
16956 +
16957 +
16958 +/* context functions */
16959 +
16960 +int vc_ctx_create(uint32_t xid, void __user *data)
16961 +{
16962 +       struct vcmd_ctx_create vc_data = { .flagword = VXF_INIT_SET };
16963 +       struct vx_info *new_vxi;
16964 +       int ret;
16965 +
16966 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
16967 +               return -EFAULT;
16968 +
16969 +       if ((xid > MAX_S_CONTEXT) || (xid < 2))
16970 +               return -EINVAL;
16971 +
16972 +       new_vxi = __create_vx_info(xid);
16973 +       if (IS_ERR(new_vxi))
16974 +               return PTR_ERR(new_vxi);
16975 +
16976 +       /* initial flags */
16977 +       new_vxi->vx_flags = vc_data.flagword;
16978 +
16979 +       ret = -ENOEXEC;
16980 +       if (vs_state_change(new_vxi, VSC_STARTUP))
16981 +               goto out;
16982 +
16983 +       ret = vx_migrate_task(current, new_vxi, (!data));
16984 +       if (ret)
16985 +               goto out;
16986 +
16987 +       /* return context id on success */
16988 +       ret = new_vxi->vx_id;
16989 +
16990 +       /* get a reference for persistent contexts */
16991 +       if ((vc_data.flagword & VXF_PERSISTENT))
16992 +               vx_set_persistent(new_vxi);
16993 +out:
16994 +       release_vx_info(new_vxi, NULL);
16995 +       put_vx_info(new_vxi);
16996 +       return ret;
16997 +}
16998 +
16999 +
17000 +int vc_ctx_migrate(struct vx_info *vxi, void __user *data)
17001 +{
17002 +       struct vcmd_ctx_migrate vc_data = { .flagword = 0 };
17003 +       int ret;
17004 +
17005 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
17006 +               return -EFAULT;
17007 +
17008 +       ret = vx_migrate_task(current, vxi, 0);
17009 +       if (ret)
17010 +               return ret;
17011 +       if (vc_data.flagword & VXM_SET_INIT)
17012 +               ret = vx_set_init(vxi, current);
17013 +       if (ret)
17014 +               return ret;
17015 +       if (vc_data.flagword & VXM_SET_REAPER)
17016 +               ret = vx_set_reaper(vxi, current);
17017 +       return ret;
17018 +}
17019 +
17020 +
17021 +int vc_get_cflags(struct vx_info *vxi, void __user *data)
17022 +{
17023 +       struct vcmd_ctx_flags_v0 vc_data;
17024 +
17025 +       vc_data.flagword = vxi->vx_flags;
17026 +
17027 +       /* special STATE flag handling */
17028 +       vc_data.mask = vs_mask_flags(~0ULL, vxi->vx_flags, VXF_ONE_TIME);
17029 +
17030 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
17031 +               return -EFAULT;
17032 +       return 0;
17033 +}
17034 +
17035 +int vc_set_cflags(struct vx_info *vxi, void __user *data)
17036 +{
17037 +       struct vcmd_ctx_flags_v0 vc_data;
17038 +       uint64_t mask, trigger;
17039 +
17040 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17041 +               return -EFAULT;
17042 +
17043 +       /* special STATE flag handling */
17044 +       mask = vs_mask_mask(vc_data.mask, vxi->vx_flags, VXF_ONE_TIME);
17045 +       trigger = (mask & vxi->vx_flags) ^ (mask & vc_data.flagword);
17046 +
17047 +       if (vxi == current_vx_info()) {
17048 +               /* if (trigger & VXF_STATE_SETUP)
17049 +                       vx_mask_cap_bset(vxi, current); */
17050 +               if (trigger & VXF_STATE_INIT) {
17051 +                       int ret;
17052 +
17053 +                       ret = vx_set_init(vxi, current);
17054 +                       if (ret)
17055 +                               return ret;
17056 +                       ret = vx_set_reaper(vxi, current);
17057 +                       if (ret)
17058 +                               return ret;
17059 +               }
17060 +       }
17061 +
17062 +       vxi->vx_flags = vs_mask_flags(vxi->vx_flags,
17063 +               vc_data.flagword, mask);
17064 +       if (trigger & VXF_PERSISTENT)
17065 +               vx_update_persistent(vxi);
17066 +
17067 +       return 0;
17068 +}
17069 +
17070 +
17071 +static inline uint64_t caps_from_cap_t(kernel_cap_t c)
17072 +{
17073 +       uint64_t v = c.cap[0] | ((uint64_t)c.cap[1] << 32);
17074 +
17075 +       // printk("caps_from_cap_t(%08x:%08x) = %016llx\n", c.cap[1], c.cap[0], v);
17076 +       return v;
17077 +}
17078 +
17079 +static inline kernel_cap_t cap_t_from_caps(uint64_t v)
17080 +{
17081 +       kernel_cap_t c = __cap_empty_set;
17082 +
17083 +       c.cap[0] = v & 0xFFFFFFFF;
17084 +       c.cap[1] = (v >> 32) & 0xFFFFFFFF;
17085 +
17086 +       // printk("cap_t_from_caps(%016llx) = %08x:%08x\n", v, c.cap[1], c.cap[0]);
17087 +       return c;
17088 +}
17089 +
17090 +
17091 +static int do_get_caps(struct vx_info *vxi, uint64_t *bcaps, uint64_t *ccaps)
17092 +{
17093 +       if (bcaps)
17094 +               *bcaps = caps_from_cap_t(vxi->vx_bcaps);
17095 +       if (ccaps)
17096 +               *ccaps = vxi->vx_ccaps;
17097 +
17098 +       return 0;
17099 +}
17100 +
17101 +int vc_get_ccaps(struct vx_info *vxi, void __user *data)
17102 +{
17103 +       struct vcmd_ctx_caps_v1 vc_data;
17104 +       int ret;
17105 +
17106 +       ret = do_get_caps(vxi, NULL, &vc_data.ccaps);
17107 +       if (ret)
17108 +               return ret;
17109 +       vc_data.cmask = ~0ULL;
17110 +
17111 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
17112 +               return -EFAULT;
17113 +       return 0;
17114 +}
17115 +
17116 +static int do_set_caps(struct vx_info *vxi,
17117 +       uint64_t bcaps, uint64_t bmask, uint64_t ccaps, uint64_t cmask)
17118 +{
17119 +       uint64_t bcold = caps_from_cap_t(vxi->vx_bcaps);
17120 +
17121 +#if 0
17122 +       printk("do_set_caps(%16llx, %16llx, %16llx, %16llx)\n",
17123 +               bcaps, bmask, ccaps, cmask);
17124 +#endif
17125 +       vxi->vx_bcaps = cap_t_from_caps(
17126 +               vs_mask_flags(bcold, bcaps, bmask));
17127 +       vxi->vx_ccaps = vs_mask_flags(vxi->vx_ccaps, ccaps, cmask);
17128 +
17129 +       return 0;
17130 +}
17131 +
17132 +int vc_set_ccaps(struct vx_info *vxi, void __user *data)
17133 +{
17134 +       struct vcmd_ctx_caps_v1 vc_data;
17135 +
17136 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17137 +               return -EFAULT;
17138 +
17139 +       return do_set_caps(vxi, 0, 0, vc_data.ccaps, vc_data.cmask);
17140 +}
17141 +
17142 +int vc_get_bcaps(struct vx_info *vxi, void __user *data)
17143 +{
17144 +       struct vcmd_bcaps vc_data;
17145 +       int ret;
17146 +
17147 +       ret = do_get_caps(vxi, &vc_data.bcaps, NULL);
17148 +       if (ret)
17149 +               return ret;
17150 +       vc_data.bmask = ~0ULL;
17151 +
17152 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
17153 +               return -EFAULT;
17154 +       return 0;
17155 +}
17156 +
17157 +int vc_set_bcaps(struct vx_info *vxi, void __user *data)
17158 +{
17159 +       struct vcmd_bcaps vc_data;
17160 +
17161 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17162 +               return -EFAULT;
17163 +
17164 +       return do_set_caps(vxi, vc_data.bcaps, vc_data.bmask, 0, 0);
17165 +}
17166 +
17167 +
17168 +int vc_get_umask(struct vx_info *vxi, void __user *data)
17169 +{
17170 +       struct vcmd_umask vc_data;
17171 +
17172 +       vc_data.umask = vxi->vx_umask;
17173 +       vc_data.mask = ~0ULL;
17174 +
17175 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
17176 +               return -EFAULT;
17177 +       return 0;
17178 +}
17179 +
17180 +int vc_set_umask(struct vx_info *vxi, void __user *data)
17181 +{
17182 +       struct vcmd_umask vc_data;
17183 +
17184 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17185 +               return -EFAULT;
17186 +
17187 +       vxi->vx_umask = vs_mask_flags(vxi->vx_umask,
17188 +               vc_data.umask, vc_data.mask);
17189 +       return 0;
17190 +}
17191 +
17192 +
17193 +int vc_get_wmask(struct vx_info *vxi, void __user *data)
17194 +{
17195 +       struct vcmd_wmask vc_data;
17196 +
17197 +       vc_data.wmask = vxi->vx_wmask;
17198 +       vc_data.mask = ~0ULL;
17199 +
17200 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
17201 +               return -EFAULT;
17202 +       return 0;
17203 +}
17204 +
17205 +int vc_set_wmask(struct vx_info *vxi, void __user *data)
17206 +{
17207 +       struct vcmd_wmask vc_data;
17208 +
17209 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17210 +               return -EFAULT;
17211 +
17212 +       vxi->vx_wmask = vs_mask_flags(vxi->vx_wmask,
17213 +               vc_data.wmask, vc_data.mask);
17214 +       return 0;
17215 +}
17216 +
17217 +
17218 +int vc_get_badness(struct vx_info *vxi, void __user *data)
17219 +{
17220 +       struct vcmd_badness_v0 vc_data;
17221 +
17222 +       vc_data.bias = vxi->vx_badness_bias;
17223 +
17224 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
17225 +               return -EFAULT;
17226 +       return 0;
17227 +}
17228 +
17229 +int vc_set_badness(struct vx_info *vxi, void __user *data)
17230 +{
17231 +       struct vcmd_badness_v0 vc_data;
17232 +
17233 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17234 +               return -EFAULT;
17235 +
17236 +       vxi->vx_badness_bias = vc_data.bias;
17237 +       return 0;
17238 +}
17239 +
17240 +#include <linux/module.h>
17241 +
17242 +EXPORT_SYMBOL_GPL(free_vx_info);
17243 +
17244 diff -NurpP --minimal linux-3.0.25/kernel/vserver/cvirt.c linux-3.0.25-vs2.3.2.3/kernel/vserver/cvirt.c
17245 --- linux-3.0.25/kernel/vserver/cvirt.c 1970-01-01 01:00:00.000000000 +0100
17246 +++ linux-3.0.25-vs2.3.2.3/kernel/vserver/cvirt.c       2011-06-13 14:57:26.000000000 +0200
17247 @@ -0,0 +1,303 @@
17248 +/*
17249 + *  linux/kernel/vserver/cvirt.c
17250 + *
17251 + *  Virtual Server: Context Virtualization
17252 + *
17253 + *  Copyright (C) 2004-2007  Herbert Pötzl
17254 + *
17255 + *  V0.01  broken out from limit.c
17256 + *  V0.02  added utsname stuff
17257 + *  V0.03  changed vcmds to vxi arg
17258 + *
17259 + */
17260 +
17261 +#include <linux/types.h>
17262 +#include <linux/utsname.h>
17263 +#include <linux/vs_cvirt.h>
17264 +#include <linux/vserver/switch.h>
17265 +#include <linux/vserver/cvirt_cmd.h>
17266 +
17267 +#include <asm/uaccess.h>
17268 +
17269 +
17270 +void vx_vsi_uptime(struct timespec *uptime, struct timespec *idle)
17271 +{
17272 +       struct vx_info *vxi = current_vx_info();
17273 +
17274 +       set_normalized_timespec(uptime,
17275 +               uptime->tv_sec - vxi->cvirt.bias_uptime.tv_sec,
17276 +               uptime->tv_nsec - vxi->cvirt.bias_uptime.tv_nsec);
17277 +       if (!idle)
17278 +               return;
17279 +       set_normalized_timespec(idle,
17280 +               idle->tv_sec - vxi->cvirt.bias_idle.tv_sec,
17281 +               idle->tv_nsec - vxi->cvirt.bias_idle.tv_nsec);
17282 +       return;
17283 +}
17284 +
17285 +uint64_t vx_idle_jiffies(void)
17286 +{
17287 +       return init_task.utime + init_task.stime;
17288 +}
17289 +
17290 +
17291 +
17292 +static inline uint32_t __update_loadavg(uint32_t load,
17293 +       int wsize, int delta, int n)
17294 +{
17295 +       unsigned long long calc, prev;
17296 +
17297 +       /* just set it to n */
17298 +       if (unlikely(delta >= wsize))
17299 +               return (n << FSHIFT);
17300 +
17301 +       calc = delta * n;
17302 +       calc <<= FSHIFT;
17303 +       prev = (wsize - delta);
17304 +       prev *= load;
17305 +       calc += prev;
17306 +       do_div(calc, wsize);
17307 +       return calc;
17308 +}
17309 +
17310 +
17311 +void vx_update_load(struct vx_info *vxi)
17312 +{
17313 +       uint32_t now, last, delta;
17314 +       unsigned int nr_running, nr_uninterruptible;
17315 +       unsigned int total;
17316 +       unsigned long flags;
17317 +
17318 +       spin_lock_irqsave(&vxi->cvirt.load_lock, flags);
17319 +
17320 +       now = jiffies;
17321 +       last = vxi->cvirt.load_last;
17322 +       delta = now - last;
17323 +
17324 +       if (delta < 5*HZ)
17325 +               goto out;
17326 +
17327 +       nr_running = atomic_read(&vxi->cvirt.nr_running);
17328 +       nr_uninterruptible = atomic_read(&vxi->cvirt.nr_uninterruptible);
17329 +       total = nr_running + nr_uninterruptible;
17330 +
17331 +       vxi->cvirt.load[0] = __update_loadavg(vxi->cvirt.load[0],
17332 +               60*HZ, delta, total);
17333 +       vxi->cvirt.load[1] = __update_loadavg(vxi->cvirt.load[1],
17334 +               5*60*HZ, delta, total);
17335 +       vxi->cvirt.load[2] = __update_loadavg(vxi->cvirt.load[2],
17336 +               15*60*HZ, delta, total);
17337 +
17338 +       vxi->cvirt.load_last = now;
17339 +out:
17340 +       atomic_inc(&vxi->cvirt.load_updates);
17341 +       spin_unlock_irqrestore(&vxi->cvirt.load_lock, flags);
17342 +}
17343 +
17344 +
17345 +/*
17346 + * Commands to do_syslog:
17347 + *
17348 + *      0 -- Close the log.  Currently a NOP.
17349 + *      1 -- Open the log. Currently a NOP.
17350 + *      2 -- Read from the log.
17351 + *      3 -- Read all messages remaining in the ring buffer.
17352 + *      4 -- Read and clear all messages remaining in the ring buffer
17353 + *      5 -- Clear ring buffer.
17354 + *      6 -- Disable printk's to console
17355 + *      7 -- Enable printk's to console
17356 + *      8 -- Set level of messages printed to console
17357 + *      9 -- Return number of unread characters in the log buffer
17358 + *     10 -- Return size of the log buffer
17359 + */
17360 +int vx_do_syslog(int type, char __user *buf, int len)
17361 +{
17362 +       int error = 0;
17363 +       int do_clear = 0;
17364 +       struct vx_info *vxi = current_vx_info();
17365 +       struct _vx_syslog *log;
17366 +
17367 +       if (!vxi)
17368 +               return -EINVAL;
17369 +       log = &vxi->cvirt.syslog;
17370 +
17371 +       switch (type) {
17372 +       case 0:         /* Close log */
17373 +       case 1:         /* Open log */
17374 +               break;
17375 +       case 2:         /* Read from log */
17376 +               error = wait_event_interruptible(log->log_wait,
17377 +                       (log->log_start - log->log_end));
17378 +               if (error)
17379 +                       break;
17380 +               spin_lock_irq(&log->logbuf_lock);
17381 +               spin_unlock_irq(&log->logbuf_lock);
17382 +               break;
17383 +       case 4:         /* Read/clear last kernel messages */
17384 +               do_clear = 1;
17385 +               /* fall through */
17386 +       case 3:         /* Read last kernel messages */
17387 +               return 0;
17388 +
17389 +       case 5:         /* Clear ring buffer */
17390 +               return 0;
17391 +
17392 +       case 6:         /* Disable logging to console */
17393 +       case 7:         /* Enable logging to console */
17394 +       case 8:         /* Set level of messages printed to console */
17395 +               break;
17396 +
17397 +       case 9:         /* Number of chars in the log buffer */
17398 +               return 0;
17399 +       case 10:        /* Size of the log buffer */
17400 +               return 0;
17401 +       default:
17402 +               error = -EINVAL;
17403 +               break;
17404 +       }
17405 +       return error;
17406 +}
17407 +
17408 +
17409 +/* virtual host info names */
17410 +
17411 +static char *vx_vhi_name(struct vx_info *vxi, int id)
17412 +{
17413 +       struct nsproxy *nsproxy;
17414 +       struct uts_namespace *uts;
17415 +
17416 +       if (id == VHIN_CONTEXT)
17417 +               return vxi->vx_name;
17418 +
17419 +       nsproxy = vxi->space[0].vx_nsproxy;
17420 +       if (!nsproxy)
17421 +               return NULL;
17422 +
17423 +       uts = nsproxy->uts_ns;
17424 +       if (!uts)
17425 +               return NULL;
17426 +
17427 +       switch (id) {
17428 +       case VHIN_SYSNAME:
17429 +               return uts->name.sysname;
17430 +       case VHIN_NODENAME:
17431 +               return uts->name.nodename;
17432 +       case VHIN_RELEASE:
17433 +               return uts->name.release;
17434 +       case VHIN_VERSION:
17435 +               return uts->name.version;
17436 +       case VHIN_MACHINE:
17437 +               return uts->name.machine;
17438 +       case VHIN_DOMAINNAME:
17439 +               return uts->name.domainname;
17440 +       default:
17441 +               return NULL;
17442 +       }
17443 +       return NULL;
17444 +}
17445 +
17446 +int vc_set_vhi_name(struct vx_info *vxi, void __user *data)
17447 +{
17448 +       struct vcmd_vhi_name_v0 vc_data;
17449 +       char *name;
17450 +
17451 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17452 +               return -EFAULT;
17453 +
17454 +       name = vx_vhi_name(vxi, vc_data.field);
17455 +       if (!name)
17456 +               return -EINVAL;
17457 +
17458 +       memcpy(name, vc_data.name, 65);
17459 +       return 0;
17460 +}
17461 +
17462 +int vc_get_vhi_name(struct vx_info *vxi, void __user *data)
17463 +{
17464 +       struct vcmd_vhi_name_v0 vc_data;
17465 +       char *name;
17466 +
17467 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17468 +               return -EFAULT;
17469 +
17470 +       name = vx_vhi_name(vxi, vc_data.field);
17471 +       if (!name)
17472 +               return -EINVAL;
17473 +
17474 +       memcpy(vc_data.name, name, 65);
17475 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
17476 +               return -EFAULT;
17477 +       return 0;
17478 +}
17479 +
17480 +
17481 +int vc_virt_stat(struct vx_info *vxi, void __user *data)
17482 +{
17483 +       struct vcmd_virt_stat_v0 vc_data;
17484 +       struct _vx_cvirt *cvirt = &vxi->cvirt;
17485 +       struct timespec uptime;
17486 +
17487 +       do_posix_clock_monotonic_gettime(&uptime);
17488 +       set_normalized_timespec(&uptime,
17489 +               uptime.tv_sec - cvirt->bias_uptime.tv_sec,
17490 +               uptime.tv_nsec - cvirt->bias_uptime.tv_nsec);
17491 +
17492 +       vc_data.offset = timespec_to_ns(&cvirt->bias_ts);
17493 +       vc_data.uptime = timespec_to_ns(&uptime);
17494 +       vc_data.nr_threads = atomic_read(&cvirt->nr_threads);
17495 +       vc_data.nr_running = atomic_read(&cvirt->nr_running);
17496 +       vc_data.nr_uninterruptible = atomic_read(&cvirt->nr_uninterruptible);
17497 +       vc_data.nr_onhold = atomic_read(&cvirt->nr_onhold);
17498 +       vc_data.nr_forks = atomic_read(&cvirt->total_forks);
17499 +       vc_data.load[0] = cvirt->load[0];
17500 +       vc_data.load[1] = cvirt->load[1];
17501 +       vc_data.load[2] = cvirt->load[2];
17502 +
17503 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
17504 +               return -EFAULT;
17505 +       return 0;
17506 +}
17507 +
17508 +
17509 +#ifdef CONFIG_VSERVER_VTIME
17510 +
17511 +/* virtualized time base */
17512 +
17513 +void vx_adjust_timespec(struct timespec *ts)
17514 +{
17515 +       struct vx_info *vxi;
17516 +
17517 +       if (!vx_flags(VXF_VIRT_TIME, 0))
17518 +               return;
17519 +
17520 +       vxi = current_vx_info();
17521 +       ts->tv_sec += vxi->cvirt.bias_ts.tv_sec;
17522 +       ts->tv_nsec += vxi->cvirt.bias_ts.tv_nsec;
17523 +
17524 +       if (ts->tv_nsec >= NSEC_PER_SEC) {
17525 +               ts->tv_sec++;
17526 +               ts->tv_nsec -= NSEC_PER_SEC;
17527 +       } else if (ts->tv_nsec < 0) {
17528 +               ts->tv_sec--;
17529 +               ts->tv_nsec += NSEC_PER_SEC;
17530 +       }
17531 +}
17532 +
17533 +int vx_settimeofday(const struct timespec *ts)
17534 +{
17535 +       struct timespec ats, delta;
17536 +       struct vx_info *vxi;
17537 +
17538 +       if (!vx_flags(VXF_VIRT_TIME, 0))
17539 +               return do_settimeofday(ts);
17540 +
17541 +       getnstimeofday(&ats);
17542 +       delta = timespec_sub(*ts, ats);
17543 +
17544 +       vxi = current_vx_info();
17545 +       vxi->cvirt.bias_ts = timespec_add(vxi->cvirt.bias_ts, delta);
17546 +       return 0;
17547 +}
17548 +
17549 +#endif
17550 +
17551 diff -NurpP --minimal linux-3.0.25/kernel/vserver/cvirt_init.h linux-3.0.25-vs2.3.2.3/kernel/vserver/cvirt_init.h
17552 --- linux-3.0.25/kernel/vserver/cvirt_init.h    1970-01-01 01:00:00.000000000 +0100
17553 +++ linux-3.0.25-vs2.3.2.3/kernel/vserver/cvirt_init.h  2011-06-10 22:11:24.000000000 +0200
17554 @@ -0,0 +1,70 @@
17555 +
17556 +
17557 +extern uint64_t vx_idle_jiffies(void);
17558 +
17559 +static inline void vx_info_init_cvirt(struct _vx_cvirt *cvirt)
17560 +{
17561 +       uint64_t idle_jiffies = vx_idle_jiffies();
17562 +       uint64_t nsuptime;
17563 +
17564 +       do_posix_clock_monotonic_gettime(&cvirt->bias_uptime);
17565 +       nsuptime = (unsigned long long)cvirt->bias_uptime.tv_sec
17566 +               * NSEC_PER_SEC + cvirt->bias_uptime.tv_nsec;
17567 +       cvirt->bias_clock = nsec_to_clock_t(nsuptime);
17568 +       cvirt->bias_ts.tv_sec = 0;
17569 +       cvirt->bias_ts.tv_nsec = 0;
17570 +
17571 +       jiffies_to_timespec(idle_jiffies, &cvirt->bias_idle);
17572 +       atomic_set(&cvirt->nr_threads, 0);
17573 +       atomic_set(&cvirt->nr_running, 0);
17574 +       atomic_set(&cvirt->nr_uninterruptible, 0);
17575 +       atomic_set(&cvirt->nr_onhold, 0);
17576 +
17577 +       spin_lock_init(&cvirt->load_lock);
17578 +       cvirt->load_last = jiffies;
17579 +       atomic_set(&cvirt->load_updates, 0);
17580 +       cvirt->load[0] = 0;
17581 +       cvirt->load[1] = 0;
17582 +       cvirt->load[2] = 0;
17583 +       atomic_set(&cvirt->total_forks, 0);
17584 +
17585 +       spin_lock_init(&cvirt->syslog.logbuf_lock);
17586 +       init_waitqueue_head(&cvirt->syslog.log_wait);
17587 +       cvirt->syslog.log_start = 0;
17588 +       cvirt->syslog.log_end = 0;
17589 +       cvirt->syslog.con_start = 0;
17590 +       cvirt->syslog.logged_chars = 0;
17591 +}
17592 +
17593 +static inline
17594 +void vx_info_init_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc, int cpu)
17595 +{
17596 +       // cvirt_pc->cpustat = { 0 };
17597 +}
17598 +
17599 +static inline void vx_info_exit_cvirt(struct _vx_cvirt *cvirt)
17600 +{
17601 +#ifdef CONFIG_VSERVER_WARN
17602 +       int value;
17603 +#endif
17604 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_threads)),
17605 +               "!!! cvirt: %p[nr_threads] = %d on exit.",
17606 +               cvirt, value);
17607 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_running)),
17608 +               "!!! cvirt: %p[nr_running] = %d on exit.",
17609 +               cvirt, value);
17610 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_uninterruptible)),
17611 +               "!!! cvirt: %p[nr_uninterruptible] = %d on exit.",
17612 +               cvirt, value);
17613 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_onhold)),
17614 +               "!!! cvirt: %p[nr_onhold] = %d on exit.",
17615 +               cvirt, value);
17616 +       return;
17617 +}
17618 +
17619 +static inline
17620 +void vx_info_exit_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc, int cpu)
17621 +{
17622 +       return;
17623 +}
17624 +
17625 diff -NurpP --minimal linux-3.0.25/kernel/vserver/cvirt_proc.h linux-3.0.25-vs2.3.2.3/kernel/vserver/cvirt_proc.h
17626 --- linux-3.0.25/kernel/vserver/cvirt_proc.h    1970-01-01 01:00:00.000000000 +0100
17627 +++ linux-3.0.25-vs2.3.2.3/kernel/vserver/cvirt_proc.h  2011-06-10 22:11:24.000000000 +0200
17628 @@ -0,0 +1,135 @@
17629 +#ifndef _VX_CVIRT_PROC_H
17630 +#define _VX_CVIRT_PROC_H
17631 +
17632 +#include <linux/nsproxy.h>
17633 +#include <linux/mnt_namespace.h>
17634 +#include <linux/ipc_namespace.h>
17635 +#include <linux/utsname.h>
17636 +#include <linux/ipc.h>
17637 +
17638 +
17639 +static inline
17640 +int vx_info_proc_nsproxy(struct nsproxy *nsproxy, char *buffer)
17641 +{
17642 +       struct mnt_namespace *ns;
17643 +       struct uts_namespace *uts;
17644 +       struct ipc_namespace *ipc;
17645 +       struct path path;
17646 +       char *pstr, *root;
17647 +       int length = 0;
17648 +
17649 +       if (!nsproxy)
17650 +               goto out;
17651 +
17652 +       length += sprintf(buffer + length,
17653 +               "NSProxy:\t%p [%p,%p,%p]\n",
17654 +               nsproxy, nsproxy->mnt_ns,
17655 +               nsproxy->uts_ns, nsproxy->ipc_ns);
17656 +
17657 +       ns = nsproxy->mnt_ns;
17658 +       if (!ns)
17659 +               goto skip_ns;
17660 +
17661 +       pstr = kmalloc(PATH_MAX, GFP_KERNEL);
17662 +       if (!pstr)
17663 +               goto skip_ns;
17664 +
17665 +       path.mnt = ns->root;
17666 +       path.dentry = ns->root->mnt_root;
17667 +       root = d_path(&path, pstr, PATH_MAX - 2);
17668 +       length += sprintf(buffer + length,
17669 +               "Namespace:\t%p [#%u]\n"
17670 +               "RootPath:\t%s\n",
17671 +               ns, atomic_read(&ns->count),
17672 +               root);
17673 +       kfree(pstr);
17674 +skip_ns:
17675 +
17676 +       uts = nsproxy->uts_ns;
17677 +       if (!uts)
17678 +               goto skip_uts;
17679 +
17680 +       length += sprintf(buffer + length,
17681 +               "SysName:\t%.*s\n"
17682 +               "NodeName:\t%.*s\n"
17683 +               "Release:\t%.*s\n"
17684 +               "Version:\t%.*s\n"
17685 +               "Machine:\t%.*s\n"
17686 +               "DomainName:\t%.*s\n",
17687 +               __NEW_UTS_LEN, uts->name.sysname,
17688 +               __NEW_UTS_LEN, uts->name.nodename,
17689 +               __NEW_UTS_LEN, uts->name.release,
17690 +               __NEW_UTS_LEN, uts->name.version,
17691 +               __NEW_UTS_LEN, uts->name.machine,
17692 +               __NEW_UTS_LEN, uts->name.domainname);
17693 +skip_uts:
17694 +
17695 +       ipc = nsproxy->ipc_ns;
17696 +       if (!ipc)
17697 +               goto skip_ipc;
17698 +
17699 +       length += sprintf(buffer + length,
17700 +               "SEMS:\t\t%d %d %d %d  %d\n"
17701 +               "MSG:\t\t%d %d %d\n"
17702 +               "SHM:\t\t%lu %lu  %d %d\n",
17703 +               ipc->sem_ctls[0], ipc->sem_ctls[1],
17704 +               ipc->sem_ctls[2], ipc->sem_ctls[3],
17705 +               ipc->used_sems,
17706 +               ipc->msg_ctlmax, ipc->msg_ctlmnb, ipc->msg_ctlmni,
17707 +               (unsigned long)ipc->shm_ctlmax,
17708 +               (unsigned long)ipc->shm_ctlall,
17709 +               ipc->shm_ctlmni, ipc->shm_tot);
17710 +skip_ipc:
17711 +out:
17712 +       return length;
17713 +}
17714 +
17715 +
17716 +#include <linux/sched.h>
17717 +
17718 +#define LOAD_INT(x) ((x) >> FSHIFT)
17719 +#define LOAD_FRAC(x) LOAD_INT(((x) & (FIXED_1 - 1)) * 100)
17720 +
17721 +static inline
17722 +int vx_info_proc_cvirt(struct _vx_cvirt *cvirt, char *buffer)
17723 +{
17724 +       int length = 0;
17725 +       int a, b, c;
17726 +
17727 +       length += sprintf(buffer + length,
17728 +               "BiasUptime:\t%lu.%02lu\n",
17729 +               (unsigned long)cvirt->bias_uptime.tv_sec,
17730 +               (cvirt->bias_uptime.tv_nsec / (NSEC_PER_SEC / 100)));
17731 +
17732 +       a = cvirt->load[0] + (FIXED_1 / 200);
17733 +       b = cvirt->load[1] + (FIXED_1 / 200);
17734 +       c = cvirt->load[2] + (FIXED_1 / 200);
17735 +       length += sprintf(buffer + length,
17736 +               "nr_threads:\t%d\n"
17737 +               "nr_running:\t%d\n"
17738 +               "nr_unintr:\t%d\n"
17739 +               "nr_onhold:\t%d\n"
17740 +               "load_updates:\t%d\n"
17741 +               "loadavg:\t%d.%02d %d.%02d %d.%02d\n"
17742 +               "total_forks:\t%d\n",
17743 +               atomic_read(&cvirt->nr_threads),
17744 +               atomic_read(&cvirt->nr_running),
17745 +               atomic_read(&cvirt->nr_uninterruptible),
17746 +               atomic_read(&cvirt->nr_onhold),
17747 +               atomic_read(&cvirt->load_updates),
17748 +               LOAD_INT(a), LOAD_FRAC(a),
17749 +               LOAD_INT(b), LOAD_FRAC(b),
17750 +               LOAD_INT(c), LOAD_FRAC(c),
17751 +               atomic_read(&cvirt->total_forks));
17752 +       return length;
17753 +}
17754 +
17755 +static inline
17756 +int vx_info_proc_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc,
17757 +       char *buffer, int cpu)
17758 +{
17759 +       int length = 0;
17760 +       return length;
17761 +}
17762 +
17763 +#endif /* _VX_CVIRT_PROC_H */
17764 diff -NurpP --minimal linux-3.0.25/kernel/vserver/debug.c linux-3.0.25-vs2.3.2.3/kernel/vserver/debug.c
17765 --- linux-3.0.25/kernel/vserver/debug.c 1970-01-01 01:00:00.000000000 +0100
17766 +++ linux-3.0.25-vs2.3.2.3/kernel/vserver/debug.c       2011-06-10 22:11:24.000000000 +0200
17767 @@ -0,0 +1,32 @@
17768 +/*
17769 + *  kernel/vserver/debug.c
17770 + *
17771 + *  Copyright (C) 2005-2007 Herbert Pötzl
17772 + *
17773 + *  V0.01  vx_info dump support
17774 + *
17775 + */
17776 +
17777 +#include <linux/module.h>
17778 +
17779 +#include <linux/vserver/context.h>
17780 +
17781 +
17782 +void   dump_vx_info(struct vx_info *vxi, int level)
17783 +{
17784 +       printk("vx_info %p[#%d, %d.%d, %4x]\n", vxi, vxi->vx_id,
17785 +               atomic_read(&vxi->vx_usecnt),
17786 +               atomic_read(&vxi->vx_tasks),
17787 +               vxi->vx_state);
17788 +       if (level > 0) {
17789 +               __dump_vx_limit(&vxi->limit);
17790 +               __dump_vx_sched(&vxi->sched);
17791 +               __dump_vx_cvirt(&vxi->cvirt);
17792 +               __dump_vx_cacct(&vxi->cacct);
17793 +       }
17794 +       printk("---\n");
17795 +}
17796 +
17797 +
17798 +EXPORT_SYMBOL_GPL(dump_vx_info);
17799 +
17800 diff -NurpP --minimal linux-3.0.25/kernel/vserver/device.c linux-3.0.25-vs2.3.2.3/kernel/vserver/device.c
17801 --- linux-3.0.25/kernel/vserver/device.c        1970-01-01 01:00:00.000000000 +0100
17802 +++ linux-3.0.25-vs2.3.2.3/kernel/vserver/device.c      2011-06-10 23:20:56.000000000 +0200
17803 @@ -0,0 +1,443 @@
17804 +/*
17805 + *  linux/kernel/vserver/device.c
17806 + *
17807 + *  Linux-VServer: Device Support
17808 + *
17809 + *  Copyright (C) 2006  Herbert Pötzl
17810 + *  Copyright (C) 2007  Daniel Hokka Zakrisson
17811 + *
17812 + *  V0.01  device mapping basics
17813 + *  V0.02  added defaults
17814 + *
17815 + */
17816 +
17817 +#include <linux/slab.h>
17818 +#include <linux/rcupdate.h>
17819 +#include <linux/fs.h>
17820 +#include <linux/namei.h>
17821 +#include <linux/hash.h>
17822 +
17823 +#include <asm/errno.h>
17824 +#include <asm/uaccess.h>
17825 +#include <linux/vserver/base.h>
17826 +#include <linux/vserver/debug.h>
17827 +#include <linux/vserver/context.h>
17828 +#include <linux/vserver/device.h>
17829 +#include <linux/vserver/device_cmd.h>
17830 +
17831 +
17832 +#define DMAP_HASH_BITS 4
17833 +
17834 +
17835 +struct vs_mapping {
17836 +       union {
17837 +               struct hlist_node hlist;
17838 +               struct list_head list;
17839 +       } u;
17840 +#define dm_hlist       u.hlist
17841 +#define dm_list                u.list
17842 +       xid_t xid;
17843 +       dev_t device;
17844 +       struct vx_dmap_target target;
17845 +};
17846 +
17847 +
17848 +static struct hlist_head dmap_main_hash[1 << DMAP_HASH_BITS];
17849 +
17850 +static DEFINE_SPINLOCK(dmap_main_hash_lock);
17851 +
17852 +static struct vx_dmap_target dmap_defaults[2] = {
17853 +       { .flags = DATTR_OPEN },
17854 +       { .flags = DATTR_OPEN },
17855 +};
17856 +
17857 +
17858 +struct kmem_cache *dmap_cachep __read_mostly;
17859 +
17860 +int __init dmap_cache_init(void)
17861 +{
17862 +       dmap_cachep = kmem_cache_create("dmap_cache",
17863 +               sizeof(struct vs_mapping), 0,
17864 +               SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
17865 +       return 0;
17866 +}
17867 +
17868 +__initcall(dmap_cache_init);
17869 +
17870 +
17871 +static inline unsigned int __hashval(dev_t dev, int bits)
17872 +{
17873 +       return hash_long((unsigned long)dev, bits);
17874 +}
17875 +
17876 +
17877 +/*     __hash_mapping()
17878 + *     add the mapping to the hash table
17879 + */
17880 +static inline void __hash_mapping(struct vx_info *vxi, struct vs_mapping *vdm)
17881 +{
17882 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
17883 +       struct hlist_head *head, *hash = dmap_main_hash;
17884 +       int device = vdm->device;
17885 +
17886 +       spin_lock(hash_lock);
17887 +       vxdprintk(VXD_CBIT(misc, 8), "__hash_mapping: %p[#%d] %08x:%08x",
17888 +               vxi, vxi ? vxi->vx_id : 0, device, vdm->target.target);
17889 +
17890 +       head = &hash[__hashval(device, DMAP_HASH_BITS)];
17891 +       hlist_add_head(&vdm->dm_hlist, head);
17892 +       spin_unlock(hash_lock);
17893 +}
17894 +
17895 +
17896 +static inline int __mode_to_default(umode_t mode)
17897 +{
17898 +       switch (mode) {
17899 +       case S_IFBLK:
17900 +               return 0;
17901 +       case S_IFCHR:
17902 +               return 1;
17903 +       default:
17904 +               BUG();
17905 +       }
17906 +}
17907 +
17908 +
17909 +/*     __set_default()
17910 + *     set a default
17911 + */
17912 +static inline void __set_default(struct vx_info *vxi, umode_t mode,
17913 +       struct vx_dmap_target *vdmt)
17914 +{
17915 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
17916 +       spin_lock(hash_lock);
17917 +
17918 +       if (vxi)
17919 +               vxi->dmap.targets[__mode_to_default(mode)] = *vdmt;
17920 +       else
17921 +               dmap_defaults[__mode_to_default(mode)] = *vdmt;
17922 +
17923 +
17924 +       spin_unlock(hash_lock);
17925 +
17926 +       vxdprintk(VXD_CBIT(misc, 8), "__set_default: %p[#%u] %08x %04x",
17927 +                 vxi, vxi ? vxi->vx_id : 0, vdmt->target, vdmt->flags);
17928 +}
17929 +
17930 +
17931 +/*     __remove_default()
17932 + *     remove a default
17933 + */
17934 +static inline int __remove_default(struct vx_info *vxi, umode_t mode)
17935 +{
17936 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
17937 +       spin_lock(hash_lock);
17938 +
17939 +       if (vxi)
17940 +               vxi->dmap.targets[__mode_to_default(mode)].flags = 0;
17941 +       else    /* remove == reset */
17942 +               dmap_defaults[__mode_to_default(mode)].flags = DATTR_OPEN | mode;
17943 +
17944 +       spin_unlock(hash_lock);
17945 +       return 0;
17946 +}
17947 +
17948 +
17949 +/*     __find_mapping()
17950 + *     find a mapping in the hash table
17951 + *
17952 + *     caller must hold hash_lock
17953 + */
17954 +static inline int __find_mapping(xid_t xid, dev_t device, umode_t mode,
17955 +       struct vs_mapping **local, struct vs_mapping **global)
17956 +{
17957 +       struct hlist_head *hash = dmap_main_hash;
17958 +       struct hlist_head *head = &hash[__hashval(device, DMAP_HASH_BITS)];
17959 +       struct hlist_node *pos;
17960 +       struct vs_mapping *vdm;
17961 +
17962 +       *local = NULL;
17963 +       if (global)
17964 +               *global = NULL;
17965 +
17966 +       hlist_for_each(pos, head) {
17967 +               vdm = hlist_entry(pos, struct vs_mapping, dm_hlist);
17968 +
17969 +               if ((vdm->device == device) &&
17970 +                       !((vdm->target.flags ^ mode) & S_IFMT)) {
17971 +                       if (vdm->xid == xid) {
17972 +                               *local = vdm;
17973 +                               return 1;
17974 +                       } else if (global && vdm->xid == 0)
17975 +                               *global = vdm;
17976 +               }
17977 +       }
17978 +
17979 +       if (global && *global)
17980 +               return 0;
17981 +       else
17982 +               return -ENOENT;
17983 +}
17984 +
17985 +
17986 +/*     __lookup_mapping()
17987 + *     find a mapping and store the result in target and flags
17988 + */
17989 +static inline int __lookup_mapping(struct vx_info *vxi,
17990 +       dev_t device, dev_t *target, int *flags, umode_t mode)
17991 +{
17992 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
17993 +       struct vs_mapping *vdm, *global;
17994 +       struct vx_dmap_target *vdmt;
17995 +       int ret = 0;
17996 +       xid_t xid = vxi->vx_id;
17997 +       int index;
17998 +
17999 +       spin_lock(hash_lock);
18000 +       if (__find_mapping(xid, device, mode, &vdm, &global) > 0) {
18001 +               ret = 1;
18002 +               vdmt = &vdm->target;
18003 +               goto found;
18004 +       }
18005 +
18006 +       index = __mode_to_default(mode);
18007 +       if (vxi && vxi->dmap.targets[index].flags) {
18008 +               ret = 2;
18009 +               vdmt = &vxi->dmap.targets[index];
18010 +       } else if (global) {
18011 +               ret = 3;
18012 +               vdmt = &global->target;
18013 +               goto found;
18014 +       } else {
18015 +               ret = 4;
18016 +               vdmt = &dmap_defaults[index];
18017 +       }
18018 +
18019 +found:
18020 +       if (target && (vdmt->flags & DATTR_REMAP))
18021 +               *target = vdmt->target;
18022 +       else if (target)
18023 +               *target = device;
18024 +       if (flags)
18025 +               *flags = vdmt->flags;
18026 +
18027 +       spin_unlock(hash_lock);
18028 +
18029 +       return ret;
18030 +}
18031 +
18032 +
18033 +/*     __remove_mapping()
18034 + *     remove a mapping from the hash table
18035 + */
18036 +static inline int __remove_mapping(struct vx_info *vxi, dev_t device,
18037 +       umode_t mode)
18038 +{
18039 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
18040 +       struct vs_mapping *vdm = NULL;
18041 +       int ret = 0;
18042 +
18043 +       spin_lock(hash_lock);
18044 +
18045 +       ret = __find_mapping((vxi ? vxi->vx_id : 0), device, mode, &vdm,
18046 +               NULL);
18047 +       vxdprintk(VXD_CBIT(misc, 8), "__remove_mapping: %p[#%d] %08x %04x",
18048 +               vxi, vxi ? vxi->vx_id : 0, device, mode);
18049 +       if (ret < 0)
18050 +               goto out;
18051 +       hlist_del(&vdm->dm_hlist);
18052 +
18053 +out:
18054 +       spin_unlock(hash_lock);
18055 +       if (vdm)
18056 +               kmem_cache_free(dmap_cachep, vdm);
18057 +       return ret;
18058 +}
18059 +
18060 +
18061 +
18062 +int vs_map_device(struct vx_info *vxi,
18063 +       dev_t device, dev_t *target, umode_t mode)
18064 +{
18065 +       int ret, flags = DATTR_MASK;
18066 +
18067 +       if (!vxi) {
18068 +               if (target)
18069 +                       *target = device;
18070 +               goto out;
18071 +       }
18072 +       ret = __lookup_mapping(vxi, device, target, &flags, mode);
18073 +       vxdprintk(VXD_CBIT(misc, 8), "vs_map_device: %08x target: %08x flags: %04x mode: %04x mapped=%d",
18074 +               device, target ? *target : 0, flags, mode, ret);
18075 +out:
18076 +       return (flags & DATTR_MASK);
18077 +}
18078 +
18079 +
18080 +
18081 +static int do_set_mapping(struct vx_info *vxi,
18082 +       dev_t device, dev_t target, int flags, umode_t mode)
18083 +{
18084 +       if (device) {
18085 +               struct vs_mapping *new;
18086 +
18087 +               new = kmem_cache_alloc(dmap_cachep, GFP_KERNEL);
18088 +               if (!new)
18089 +                       return -ENOMEM;
18090 +
18091 +               INIT_HLIST_NODE(&new->dm_hlist);
18092 +               new->device = device;
18093 +               new->target.target = target;
18094 +               new->target.flags = flags | mode;
18095 +               new->xid = (vxi ? vxi->vx_id : 0);
18096 +
18097 +               vxdprintk(VXD_CBIT(misc, 8), "do_set_mapping: %08x target: %08x flags: %04x", device, target, flags);
18098 +               __hash_mapping(vxi, new);
18099 +       } else {
18100 +               struct vx_dmap_target new = {
18101 +                       .target = target,
18102 +                       .flags = flags | mode,
18103 +               };
18104 +               __set_default(vxi, mode, &new);
18105 +       }
18106 +       return 0;
18107 +}
18108 +
18109 +
18110 +static int do_unset_mapping(struct vx_info *vxi,
18111 +       dev_t device, dev_t target, int flags, umode_t mode)
18112 +{
18113 +       int ret = -EINVAL;
18114 +
18115 +       if (device) {
18116 +               ret = __remove_mapping(vxi, device, mode);
18117 +               if (ret < 0)
18118 +                       goto out;
18119 +       } else {
18120 +               ret = __remove_default(vxi, mode);
18121 +               if (ret < 0)
18122 +                       goto out;
18123 +       }
18124 +
18125 +out:
18126 +       return ret;
18127 +}
18128 +
18129 +
18130 +static inline int __user_device(const char __user *name, dev_t *dev,
18131 +       umode_t *mode)
18132 +{
18133 +       struct nameidata nd;
18134 +       int ret;
18135 +
18136 +       if (!name) {
18137 +               *dev = 0;
18138 +               return 0;
18139 +       }
18140 +       ret = user_lpath(name, &nd.path);
18141 +       if (ret)
18142 +               return ret;
18143 +       if (nd.path.dentry->d_inode) {
18144 +               *dev = nd.path.dentry->d_inode->i_rdev;
18145 +               *mode = nd.path.dentry->d_inode->i_mode;
18146 +       }
18147 +       path_put(&nd.path);
18148 +       return 0;
18149 +}
18150 +
18151 +static inline int __mapping_mode(dev_t device, dev_t target,
18152 +       umode_t device_mode, umode_t target_mode, umode_t *mode)
18153 +{
18154 +       if (device)
18155 +               *mode = device_mode & S_IFMT;
18156 +       else if (target)
18157 +               *mode = target_mode & S_IFMT;
18158 +       else
18159 +               return -EINVAL;
18160 +
18161 +       /* if both given, device and target mode have to match */
18162 +       if (device && target &&
18163 +               ((device_mode ^ target_mode) & S_IFMT))
18164 +               return -EINVAL;
18165 +       return 0;
18166 +}
18167 +
18168 +
18169 +static inline int do_mapping(struct vx_info *vxi, const char __user *device_path,
18170 +       const char __user *target_path, int flags, int set)
18171 +{
18172 +       dev_t device = ~0, target = ~0;
18173 +       umode_t device_mode = 0, target_mode = 0, mode;
18174 +       int ret;
18175 +
18176 +       ret = __user_device(device_path, &device, &device_mode);
18177 +       if (ret)
18178 +               return ret;
18179 +       ret = __user_device(target_path, &target, &target_mode);
18180 +       if (ret)
18181 +               return ret;
18182 +
18183 +       ret = __mapping_mode(device, target,
18184 +               device_mode, target_mode, &mode);
18185 +       if (ret)
18186 +               return ret;
18187 +
18188 +       if (set)
18189 +               return do_set_mapping(vxi, device, target,
18190 +                       flags, mode);
18191 +       else
18192 +               return do_unset_mapping(vxi, device, target,
18193 +                       flags, mode);
18194 +}
18195 +
18196 +
18197 +int vc_set_mapping(struct vx_info *vxi, void __user *data)
18198 +{
18199 +       struct vcmd_set_mapping_v0 vc_data;
18200 +
18201 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18202 +               return -EFAULT;
18203 +
18204 +       return do_mapping(vxi, vc_data.device, vc_data.target,
18205 +               vc_data.flags, 1);
18206 +}
18207 +
18208 +int vc_unset_mapping(struct vx_info *vxi, void __user *data)
18209 +{
18210 +       struct vcmd_set_mapping_v0 vc_data;
18211 +
18212 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18213 +               return -EFAULT;
18214 +
18215 +       return do_mapping(vxi, vc_data.device, vc_data.target,
18216 +               vc_data.flags, 0);
18217 +}
18218 +
18219 +
18220 +#ifdef CONFIG_COMPAT
18221 +
18222 +int vc_set_mapping_x32(struct vx_info *vxi, void __user *data)
18223 +{
18224 +       struct vcmd_set_mapping_v0_x32 vc_data;
18225 +
18226 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18227 +               return -EFAULT;
18228 +
18229 +       return do_mapping(vxi, compat_ptr(vc_data.device_ptr),
18230 +               compat_ptr(vc_data.target_ptr), vc_data.flags, 1);
18231 +}
18232 +
18233 +int vc_unset_mapping_x32(struct vx_info *vxi, void __user *data)
18234 +{
18235 +       struct vcmd_set_mapping_v0_x32 vc_data;
18236 +
18237 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18238 +               return -EFAULT;
18239 +
18240 +       return do_mapping(vxi, compat_ptr(vc_data.device_ptr),
18241 +               compat_ptr(vc_data.target_ptr), vc_data.flags, 0);
18242 +}
18243 +
18244 +#endif /* CONFIG_COMPAT */
18245 +
18246 +
18247 diff -NurpP --minimal linux-3.0.25/kernel/vserver/dlimit.c linux-3.0.25-vs2.3.2.3/kernel/vserver/dlimit.c
18248 --- linux-3.0.25/kernel/vserver/dlimit.c        1970-01-01 01:00:00.000000000 +0100
18249 +++ linux-3.0.25-vs2.3.2.3/kernel/vserver/dlimit.c      2011-06-10 23:20:56.000000000 +0200
18250 @@ -0,0 +1,531 @@
18251 +/*
18252 + *  linux/kernel/vserver/dlimit.c
18253 + *
18254 + *  Virtual Server: Context Disk Limits
18255 + *
18256 + *  Copyright (C) 2004-2009  Herbert Pötzl
18257 + *
18258 + *  V0.01  initial version
18259 + *  V0.02  compat32 splitup
18260 + *  V0.03  extended interface
18261 + *
18262 + */
18263 +
18264 +#include <linux/statfs.h>
18265 +#include <linux/sched.h>
18266 +#include <linux/namei.h>
18267 +#include <linux/vs_tag.h>
18268 +#include <linux/vs_dlimit.h>
18269 +#include <linux/vserver/dlimit_cmd.h>
18270 +#include <linux/slab.h>
18271 +// #include <linux/gfp.h>
18272 +
18273 +#include <asm/uaccess.h>
18274 +
18275 +/*     __alloc_dl_info()
18276 +
18277 +       * allocate an initialized dl_info struct
18278 +       * doesn't make it visible (hash)                        */
18279 +
18280 +static struct dl_info *__alloc_dl_info(struct super_block *sb, tag_t tag)
18281 +{
18282 +       struct dl_info *new = NULL;
18283 +
18284 +       vxdprintk(VXD_CBIT(dlim, 5),
18285 +               "alloc_dl_info(%p,%d)*", sb, tag);
18286 +
18287 +       /* would this benefit from a slab cache? */
18288 +       new = kmalloc(sizeof(struct dl_info), GFP_KERNEL);
18289 +       if (!new)
18290 +               return 0;
18291 +
18292 +       memset(new, 0, sizeof(struct dl_info));
18293 +       new->dl_tag = tag;
18294 +       new->dl_sb = sb;
18295 +       // INIT_RCU_HEAD(&new->dl_rcu);
18296 +       INIT_HLIST_NODE(&new->dl_hlist);
18297 +       spin_lock_init(&new->dl_lock);
18298 +       atomic_set(&new->dl_refcnt, 0);
18299 +       atomic_set(&new->dl_usecnt, 0);
18300 +
18301 +       /* rest of init goes here */
18302 +
18303 +       vxdprintk(VXD_CBIT(dlim, 4),
18304 +               "alloc_dl_info(%p,%d) = %p", sb, tag, new);
18305 +       return new;
18306 +}
18307 +
18308 +/*     __dealloc_dl_info()
18309 +
18310 +       * final disposal of dl_info                             */
18311 +
18312 +static void __dealloc_dl_info(struct dl_info *dli)
18313 +{
18314 +       vxdprintk(VXD_CBIT(dlim, 4),
18315 +               "dealloc_dl_info(%p)", dli);
18316 +
18317 +       dli->dl_hlist.next = LIST_POISON1;
18318 +       dli->dl_tag = -1;
18319 +       dli->dl_sb = 0;
18320 +
18321 +       BUG_ON(atomic_read(&dli->dl_usecnt));
18322 +       BUG_ON(atomic_read(&dli->dl_refcnt));
18323 +
18324 +       kfree(dli);
18325 +}
18326 +
18327 +
18328 +/*     hash table for dl_info hash */
18329 +
18330 +#define DL_HASH_SIZE   13
18331 +
18332 +struct hlist_head dl_info_hash[DL_HASH_SIZE];
18333 +
18334 +static DEFINE_SPINLOCK(dl_info_hash_lock);
18335 +
18336 +
18337 +static inline unsigned int __hashval(struct super_block *sb, tag_t tag)
18338 +{
18339 +       return ((tag ^ (unsigned long)sb) % DL_HASH_SIZE);
18340 +}
18341 +
18342 +
18343 +
18344 +/*     __hash_dl_info()
18345 +
18346 +       * add the dli to the global hash table
18347 +       * requires the hash_lock to be held                     */
18348 +
18349 +static inline void __hash_dl_info(struct dl_info *dli)
18350 +{
18351 +       struct hlist_head *head;
18352 +
18353 +       vxdprintk(VXD_CBIT(dlim, 6),
18354 +               "__hash_dl_info: %p[#%d]", dli, dli->dl_tag);
18355 +       get_dl_info(dli);
18356 +       head = &dl_info_hash[__hashval(dli->dl_sb, dli->dl_tag)];
18357 +       hlist_add_head_rcu(&dli->dl_hlist, head);
18358 +}
18359 +
18360 +/*     __unhash_dl_info()
18361 +
18362 +       * remove the dli from the global hash table
18363 +       * requires the hash_lock to be held                     */
18364 +
18365 +static inline void __unhash_dl_info(struct dl_info *dli)
18366 +{
18367 +       vxdprintk(VXD_CBIT(dlim, 6),
18368 +               "__unhash_dl_info: %p[#%d]", dli, dli->dl_tag);
18369 +       hlist_del_rcu(&dli->dl_hlist);
18370 +       put_dl_info(dli);
18371 +}
18372 +
18373 +
18374 +/*     __lookup_dl_info()
18375 +
18376 +       * requires the rcu_read_lock()
18377 +       * doesn't increment the dl_refcnt                       */
18378 +
18379 +static inline struct dl_info *__lookup_dl_info(struct super_block *sb, tag_t tag)
18380 +{
18381 +       struct hlist_head *head = &dl_info_hash[__hashval(sb, tag)];
18382 +       struct hlist_node *pos;
18383 +       struct dl_info *dli;
18384 +
18385 +       hlist_for_each_entry_rcu(dli, pos, head, dl_hlist) {
18386 +
18387 +               if (dli->dl_tag == tag && dli->dl_sb == sb) {
18388 +                       return dli;
18389 +               }
18390 +       }
18391 +       return NULL;
18392 +}
18393 +
18394 +
18395 +struct dl_info *locate_dl_info(struct super_block *sb, tag_t tag)
18396 +{
18397 +       struct dl_info *dli;
18398 +
18399 +       rcu_read_lock();
18400 +       dli = get_dl_info(__lookup_dl_info(sb, tag));
18401 +       vxdprintk(VXD_CBIT(dlim, 7),
18402 +               "locate_dl_info(%p,#%d) = %p", sb, tag, dli);
18403 +       rcu_read_unlock();
18404 +       return dli;
18405 +}
18406 +
18407 +void rcu_free_dl_info(struct rcu_head *head)
18408 +{
18409 +       struct dl_info *dli = container_of(head, struct dl_info, dl_rcu);
18410 +       int usecnt, refcnt;
18411 +
18412 +       BUG_ON(!dli || !head);
18413 +
18414 +       usecnt = atomic_read(&dli->dl_usecnt);
18415 +       BUG_ON(usecnt < 0);
18416 +
18417 +       refcnt = atomic_read(&dli->dl_refcnt);
18418 +       BUG_ON(refcnt < 0);
18419 +
18420 +       vxdprintk(VXD_CBIT(dlim, 3),
18421 +               "rcu_free_dl_info(%p)", dli);
18422 +       if (!usecnt)
18423 +               __dealloc_dl_info(dli);
18424 +       else
18425 +               printk("!!! rcu didn't free\n");
18426 +}
18427 +
18428 +
18429 +
18430 +
18431 +static int do_addrem_dlimit(uint32_t id, const char __user *name,
18432 +       uint32_t flags, int add)
18433 +{
18434 +       struct path path;
18435 +       int ret;
18436 +
18437 +       ret = user_lpath(name, &path);
18438 +       if (!ret) {
18439 +               struct super_block *sb;
18440 +               struct dl_info *dli;
18441 +
18442 +               ret = -EINVAL;
18443 +               if (!path.dentry->d_inode)
18444 +                       goto out_release;
18445 +               if (!(sb = path.dentry->d_inode->i_sb))
18446 +                       goto out_release;
18447 +
18448 +               if (add) {
18449 +                       dli = __alloc_dl_info(sb, id);
18450 +                       spin_lock(&dl_info_hash_lock);
18451 +
18452 +                       ret = -EEXIST;
18453 +                       if (__lookup_dl_info(sb, id))
18454 +                               goto out_unlock;
18455 +                       __hash_dl_info(dli);
18456 +                       dli = NULL;
18457 +               } else {
18458 +                       spin_lock(&dl_info_hash_lock);
18459 +                       dli = __lookup_dl_info(sb, id);
18460 +
18461 +                       ret = -ESRCH;
18462 +                       if (!dli)
18463 +                               goto out_unlock;
18464 +                       __unhash_dl_info(dli);
18465 +               }
18466 +               ret = 0;
18467 +       out_unlock:
18468 +               spin_unlock(&dl_info_hash_lock);
18469 +               if (add && dli)
18470 +                       __dealloc_dl_info(dli);
18471 +       out_release:
18472 +               path_put(&path);
18473 +       }
18474 +       return ret;
18475 +}
18476 +
18477 +int vc_add_dlimit(uint32_t id, void __user *data)
18478 +{
18479 +       struct vcmd_ctx_dlimit_base_v0 vc_data;
18480 +
18481 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18482 +               return -EFAULT;
18483 +
18484 +       return do_addrem_dlimit(id, vc_data.name, vc_data.flags, 1);
18485 +}
18486 +
18487 +int vc_rem_dlimit(uint32_t id, void __user *data)
18488 +{
18489 +       struct vcmd_ctx_dlimit_base_v0 vc_data;
18490 +
18491 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18492 +               return -EFAULT;
18493 +
18494 +       return do_addrem_dlimit(id, vc_data.name, vc_data.flags, 0);
18495 +}
18496 +
18497 +#ifdef CONFIG_COMPAT
18498 +
18499 +int vc_add_dlimit_x32(uint32_t id, void __user *data)
18500 +{
18501 +       struct vcmd_ctx_dlimit_base_v0_x32 vc_data;
18502 +
18503 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18504 +               return -EFAULT;
18505 +
18506 +       return do_addrem_dlimit(id,
18507 +               compat_ptr(vc_data.name_ptr), vc_data.flags, 1);
18508 +}
18509 +
18510 +int vc_rem_dlimit_x32(uint32_t id, void __user *data)
18511 +{
18512 +       struct vcmd_ctx_dlimit_base_v0_x32 vc_data;
18513 +
18514 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18515 +               return -EFAULT;
18516 +
18517 +       return do_addrem_dlimit(id,
18518 +               compat_ptr(vc_data.name_ptr), vc_data.flags, 0);
18519 +}
18520 +
18521 +#endif /* CONFIG_COMPAT */
18522 +
18523 +
18524 +static inline
18525 +int do_set_dlimit(uint32_t id, const char __user *name,
18526 +       uint32_t space_used, uint32_t space_total,
18527 +       uint32_t inodes_used, uint32_t inodes_total,
18528 +       uint32_t reserved, uint32_t flags)
18529 +{
18530 +       struct path path;
18531 +       int ret;
18532 +
18533 +       ret = user_lpath(name, &path);
18534 +       if (!ret) {
18535 +               struct super_block *sb;
18536 +               struct dl_info *dli;
18537 +
18538 +               ret = -EINVAL;
18539 +               if (!path.dentry->d_inode)
18540 +                       goto out_release;
18541 +               if (!(sb = path.dentry->d_inode->i_sb))
18542 +                       goto out_release;
18543 +
18544 +               /* sanity checks */
18545 +               if ((reserved != CDLIM_KEEP &&
18546 +                       reserved > 100) ||
18547 +                       (inodes_used != CDLIM_KEEP &&
18548 +                       inodes_used > inodes_total) ||
18549 +                       (space_used != CDLIM_KEEP &&
18550 +                       space_used > space_total))
18551 +                       goto out_release;
18552 +
18553 +               ret = -ESRCH;
18554 +               dli = locate_dl_info(sb, id);
18555 +               if (!dli)
18556 +                       goto out_release;
18557 +
18558 +               spin_lock(&dli->dl_lock);
18559 +
18560 +               if (inodes_used != CDLIM_KEEP)
18561 +                       dli->dl_inodes_used = inodes_used;
18562 +               if (inodes_total != CDLIM_KEEP)
18563 +                       dli->dl_inodes_total = inodes_total;
18564 +               if (space_used != CDLIM_KEEP)
18565 +                       dli->dl_space_used = dlimit_space_32to64(
18566 +                               space_used, flags, DLIMS_USED);
18567 +
18568 +               if (space_total == CDLIM_INFINITY)
18569 +                       dli->dl_space_total = DLIM_INFINITY;
18570 +               else if (space_total != CDLIM_KEEP)
18571 +                       dli->dl_space_total = dlimit_space_32to64(
18572 +                               space_total, flags, DLIMS_TOTAL);
18573 +
18574 +               if (reserved != CDLIM_KEEP)
18575 +                       dli->dl_nrlmult = (1 << 10) * (100 - reserved) / 100;
18576 +
18577 +               spin_unlock(&dli->dl_lock);
18578 +
18579 +               put_dl_info(dli);
18580 +               ret = 0;
18581 +
18582 +       out_release:
18583 +               path_put(&path);
18584 +       }
18585 +       return ret;
18586 +}
18587 +
18588 +int vc_set_dlimit(uint32_t id, void __user *data)
18589 +{
18590 +       struct vcmd_ctx_dlimit_v0 vc_data;
18591 +
18592 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18593 +               return -EFAULT;
18594 +
18595 +       return do_set_dlimit(id, vc_data.name,
18596 +               vc_data.space_used, vc_data.space_total,
18597 +               vc_data.inodes_used, vc_data.inodes_total,
18598 +               vc_data.reserved, vc_data.flags);
18599 +}
18600 +
18601 +#ifdef CONFIG_COMPAT
18602 +
18603 +int vc_set_dlimit_x32(uint32_t id, void __user *data)
18604 +{
18605 +       struct vcmd_ctx_dlimit_v0_x32 vc_data;
18606 +
18607 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18608 +               return -EFAULT;
18609 +
18610 +       return do_set_dlimit(id, compat_ptr(vc_data.name_ptr),
18611 +               vc_data.space_used, vc_data.space_total,
18612 +               vc_data.inodes_used, vc_data.inodes_total,
18613 +               vc_data.reserved, vc_data.flags);
18614 +}
18615 +
18616 +#endif /* CONFIG_COMPAT */
18617 +
18618 +
18619 +static inline
18620 +int do_get_dlimit(uint32_t id, const char __user *name,
18621 +       uint32_t *space_used, uint32_t *space_total,
18622 +       uint32_t *inodes_used, uint32_t *inodes_total,
18623 +       uint32_t *reserved, uint32_t *flags)
18624 +{
18625 +       struct path path;
18626 +       int ret;
18627 +
18628 +       ret = user_lpath(name, &path);
18629 +       if (!ret) {
18630 +               struct super_block *sb;
18631 +               struct dl_info *dli;
18632 +
18633 +               ret = -EINVAL;
18634 +               if (!path.dentry->d_inode)
18635 +                       goto out_release;
18636 +               if (!(sb = path.dentry->d_inode->i_sb))
18637 +                       goto out_release;
18638 +
18639 +               ret = -ESRCH;
18640 +               dli = locate_dl_info(sb, id);
18641 +               if (!dli)
18642 +                       goto out_release;
18643 +
18644 +               spin_lock(&dli->dl_lock);
18645 +               *inodes_used = dli->dl_inodes_used;
18646 +               *inodes_total = dli->dl_inodes_total;
18647 +
18648 +               *space_used = dlimit_space_64to32(
18649 +                       dli->dl_space_used, flags, DLIMS_USED);
18650 +
18651 +               if (dli->dl_space_total == DLIM_INFINITY)
18652 +                       *space_total = CDLIM_INFINITY;
18653 +               else
18654 +                       *space_total = dlimit_space_64to32(
18655 +                               dli->dl_space_total, flags, DLIMS_TOTAL);
18656 +
18657 +               *reserved = 100 - ((dli->dl_nrlmult * 100 + 512) >> 10);
18658 +               spin_unlock(&dli->dl_lock);
18659 +
18660 +               put_dl_info(dli);
18661 +               ret = -EFAULT;
18662 +
18663 +               ret = 0;
18664 +       out_release:
18665 +               path_put(&path);
18666 +       }
18667 +       return ret;
18668 +}
18669 +
18670 +
18671 +int vc_get_dlimit(uint32_t id, void __user *data)
18672 +{
18673 +       struct vcmd_ctx_dlimit_v0 vc_data;
18674 +       int ret;
18675 +
18676 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18677 +               return -EFAULT;
18678 +
18679 +       ret = do_get_dlimit(id, vc_data.name,
18680 +               &vc_data.space_used, &vc_data.space_total,
18681 +               &vc_data.inodes_used, &vc_data.inodes_total,
18682 +               &vc_data.reserved, &vc_data.flags);
18683 +       if (ret)
18684 +               return ret;
18685 +
18686 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18687 +               return -EFAULT;
18688 +       return 0;
18689 +}
18690 +
18691 +#ifdef CONFIG_COMPAT
18692 +
18693 +int vc_get_dlimit_x32(uint32_t id, void __user *data)
18694 +{
18695 +       struct vcmd_ctx_dlimit_v0_x32 vc_data;
18696 +       int ret;
18697 +
18698 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18699 +               return -EFAULT;
18700 +
18701 +       ret = do_get_dlimit(id, compat_ptr(vc_data.name_ptr),
18702 +               &vc_data.space_used, &vc_data.space_total,
18703 +               &vc_data.inodes_used, &vc_data.inodes_total,
18704 +               &vc_data.reserved, &vc_data.flags);
18705 +       if (ret)
18706 +               return ret;
18707 +
18708 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18709 +               return -EFAULT;
18710 +       return 0;
18711 +}
18712 +
18713 +#endif /* CONFIG_COMPAT */
18714 +
18715 +
18716 +void vx_vsi_statfs(struct super_block *sb, struct kstatfs *buf)
18717 +{
18718 +       struct dl_info *dli;
18719 +       __u64 blimit, bfree, bavail;
18720 +       __u32 ifree;
18721 +
18722 +       dli = locate_dl_info(sb, dx_current_tag());
18723 +       if (!dli)
18724 +               return;
18725 +
18726 +       spin_lock(&dli->dl_lock);
18727 +       if (dli->dl_inodes_total == (unsigned long)DLIM_INFINITY)
18728 +               goto no_ilim;
18729 +
18730 +       /* reduce max inodes available to limit */
18731 +       if (buf->f_files > dli->dl_inodes_total)
18732 +               buf->f_files = dli->dl_inodes_total;
18733 +
18734 +       ifree = dli->dl_inodes_total - dli->dl_inodes_used;
18735 +       /* reduce free inodes to min */
18736 +       if (ifree < buf->f_ffree)
18737 +               buf->f_ffree = ifree;
18738 +
18739 +no_ilim:
18740 +       if (dli->dl_space_total == DLIM_INFINITY)
18741 +               goto no_blim;
18742 +
18743 +       blimit = dli->dl_space_total >> sb->s_blocksize_bits;
18744 +
18745 +       if (dli->dl_space_total < dli->dl_space_used)
18746 +               bfree = 0;
18747 +       else
18748 +               bfree = (dli->dl_space_total - dli->dl_space_used)
18749 +                       >> sb->s_blocksize_bits;
18750 +
18751 +       bavail = ((dli->dl_space_total >> 10) * dli->dl_nrlmult);
18752 +       if (bavail < dli->dl_space_used)
18753 +               bavail = 0;
18754 +       else
18755 +               bavail = (bavail - dli->dl_space_used)
18756 +                       >> sb->s_blocksize_bits;
18757 +
18758 +       /* reduce max space available to limit */
18759 +       if (buf->f_blocks > blimit)
18760 +               buf->f_blocks = blimit;
18761 +
18762 +       /* reduce free space to min */
18763 +       if (bfree < buf->f_bfree)
18764 +               buf->f_bfree = bfree;
18765 +
18766 +       /* reduce avail space to min */
18767 +       if (bavail < buf->f_bavail)
18768 +               buf->f_bavail = bavail;
18769 +
18770 +no_blim:
18771 +       spin_unlock(&dli->dl_lock);
18772 +       put_dl_info(dli);
18773 +
18774 +       return;
18775 +}
18776 +
18777 +#include <linux/module.h>
18778 +
18779 +EXPORT_SYMBOL_GPL(locate_dl_info);
18780 +EXPORT_SYMBOL_GPL(rcu_free_dl_info);
18781 +
18782 diff -NurpP --minimal linux-3.0.25/kernel/vserver/helper.c linux-3.0.25-vs2.3.2.3/kernel/vserver/helper.c
18783 --- linux-3.0.25/kernel/vserver/helper.c        1970-01-01 01:00:00.000000000 +0100
18784 +++ linux-3.0.25-vs2.3.2.3/kernel/vserver/helper.c      2011-06-10 22:11:24.000000000 +0200
18785 @@ -0,0 +1,223 @@
18786 +/*
18787 + *  linux/kernel/vserver/helper.c
18788 + *
18789 + *  Virtual Context Support
18790 + *
18791 + *  Copyright (C) 2004-2007  Herbert Pötzl
18792 + *
18793 + *  V0.01  basic helper
18794 + *
18795 + */
18796 +
18797 +#include <linux/kmod.h>
18798 +#include <linux/reboot.h>
18799 +#include <linux/vs_context.h>
18800 +#include <linux/vs_network.h>
18801 +#include <linux/vserver/signal.h>
18802 +
18803 +
18804 +char vshelper_path[255] = "/sbin/vshelper";
18805 +
18806 +
18807 +static int do_vshelper(char *name, char *argv[], char *envp[], int sync)
18808 +{
18809 +       int ret;
18810 +
18811 +       if ((ret = call_usermodehelper(name, argv, envp, sync))) {
18812 +               printk( KERN_WARNING
18813 +                       "%s: (%s %s) returned %s with %d\n",
18814 +                       name, argv[1], argv[2],
18815 +                       sync ? "sync" : "async", ret);
18816 +       }
18817 +       vxdprintk(VXD_CBIT(switch, 4),
18818 +               "%s: (%s %s) returned %s with %d",
18819 +               name, argv[1], argv[2], sync ? "sync" : "async", ret);
18820 +       return ret;
18821 +}
18822 +
18823 +/*
18824 + *      vshelper path is set via /proc/sys
18825 + *      invoked by vserver sys_reboot(), with
18826 + *      the following arguments
18827 + *
18828 + *      argv [0] = vshelper_path;
18829 + *      argv [1] = action: "restart", "halt", "poweroff", ...
18830 + *      argv [2] = context identifier
18831 + *
18832 + *      envp [*] = type-specific parameters
18833 + */
18834 +
18835 +long vs_reboot_helper(struct vx_info *vxi, int cmd, void __user *arg)
18836 +{
18837 +       char id_buf[8], cmd_buf[16];
18838 +       char uid_buf[16], pid_buf[16];
18839 +       int ret;
18840 +
18841 +       char *argv[] = {vshelper_path, NULL, id_buf, 0};
18842 +       char *envp[] = {"HOME=/", "TERM=linux",
18843 +                       "PATH=/sbin:/usr/sbin:/bin:/usr/bin",
18844 +                       uid_buf, pid_buf, cmd_buf, 0};
18845 +
18846 +       if (vx_info_state(vxi, VXS_HELPER))
18847 +               return -EAGAIN;
18848 +       vxi->vx_state |= VXS_HELPER;
18849 +
18850 +       snprintf(id_buf, sizeof(id_buf)-1, "%d", vxi->vx_id);
18851 +
18852 +       snprintf(cmd_buf, sizeof(cmd_buf)-1, "VS_CMD=%08x", cmd);
18853 +       snprintf(uid_buf, sizeof(uid_buf)-1, "VS_UID=%d", current_uid());
18854 +       snprintf(pid_buf, sizeof(pid_buf)-1, "VS_PID=%d", current->pid);
18855 +
18856 +       switch (cmd) {
18857 +       case LINUX_REBOOT_CMD_RESTART:
18858 +               argv[1] = "restart";
18859 +               break;
18860 +
18861 +       case LINUX_REBOOT_CMD_HALT:
18862 +               argv[1] = "halt";
18863 +               break;
18864 +
18865 +       case LINUX_REBOOT_CMD_POWER_OFF:
18866 +               argv[1] = "poweroff";
18867 +               break;
18868 +
18869 +       case LINUX_REBOOT_CMD_SW_SUSPEND:
18870 +               argv[1] = "swsusp";
18871 +               break;
18872 +
18873 +       case LINUX_REBOOT_CMD_OOM:
18874 +               argv[1] = "oom";
18875 +               break;
18876 +
18877 +       default:
18878 +               vxi->vx_state &= ~VXS_HELPER;
18879 +               return 0;
18880 +       }
18881 +
18882 +       ret = do_vshelper(vshelper_path, argv, envp, 0);
18883 +       vxi->vx_state &= ~VXS_HELPER;
18884 +       __wakeup_vx_info(vxi);
18885 +       return (ret) ? -EPERM : 0;
18886 +}
18887 +
18888 +
18889 +long vs_reboot(unsigned int cmd, void __user *arg)
18890 +{
18891 +       struct vx_info *vxi = current_vx_info();
18892 +       long ret = 0;
18893 +
18894 +       vxdprintk(VXD_CBIT(misc, 5),
18895 +               "vs_reboot(%p[#%d],%u)",
18896 +               vxi, vxi ? vxi->vx_id : 0, cmd);
18897 +
18898 +       ret = vs_reboot_helper(vxi, cmd, arg);
18899 +       if (ret)
18900 +               return ret;
18901 +
18902 +       vxi->reboot_cmd = cmd;
18903 +       if (vx_info_flags(vxi, VXF_REBOOT_KILL, 0)) {
18904 +               switch (cmd) {
18905 +               case LINUX_REBOOT_CMD_RESTART:
18906 +               case LINUX_REBOOT_CMD_HALT:
18907 +               case LINUX_REBOOT_CMD_POWER_OFF:
18908 +                       vx_info_kill(vxi, 0, SIGKILL);
18909 +                       vx_info_kill(vxi, 1, SIGKILL);
18910 +               default:
18911 +                       break;
18912 +               }
18913 +       }
18914 +       return 0;
18915 +}
18916 +
18917 +long vs_oom_action(unsigned int cmd)
18918 +{
18919 +       struct vx_info *vxi = current_vx_info();
18920 +       long ret = 0;
18921 +
18922 +       vxdprintk(VXD_CBIT(misc, 5),
18923 +               "vs_oom_action(%p[#%d],%u)",
18924 +               vxi, vxi ? vxi->vx_id : 0, cmd);
18925 +
18926 +       ret = vs_reboot_helper(vxi, cmd, NULL);
18927 +       if (ret)
18928 +               return ret;
18929 +
18930 +       vxi->reboot_cmd = cmd;
18931 +       if (vx_info_flags(vxi, VXF_REBOOT_KILL, 0)) {
18932 +               vx_info_kill(vxi, 0, SIGKILL);
18933 +               vx_info_kill(vxi, 1, SIGKILL);
18934 +       }
18935 +       return 0;
18936 +}
18937 +
18938 +/*
18939 + *      argv [0] = vshelper_path;
18940 + *      argv [1] = action: "startup", "shutdown"
18941 + *      argv [2] = context identifier
18942 + *
18943 + *      envp [*] = type-specific parameters
18944 + */
18945 +
18946 +long vs_state_change(struct vx_info *vxi, unsigned int cmd)
18947 +{
18948 +       char id_buf[8], cmd_buf[16];
18949 +       char *argv[] = {vshelper_path, NULL, id_buf, 0};
18950 +       char *envp[] = {"HOME=/", "TERM=linux",
18951 +                       "PATH=/sbin:/usr/sbin:/bin:/usr/bin", cmd_buf, 0};
18952 +
18953 +       if (!vx_info_flags(vxi, VXF_SC_HELPER, 0))
18954 +               return 0;
18955 +
18956 +       snprintf(id_buf, sizeof(id_buf)-1, "%d", vxi->vx_id);
18957 +       snprintf(cmd_buf, sizeof(cmd_buf)-1, "VS_CMD=%08x", cmd);
18958 +
18959 +       switch (cmd) {
18960 +       case VSC_STARTUP:
18961 +               argv[1] = "startup";
18962 +               break;
18963 +       case VSC_SHUTDOWN:
18964 +               argv[1] = "shutdown";
18965 +               break;
18966 +       default:
18967 +               return 0;
18968 +       }
18969 +
18970 +       return do_vshelper(vshelper_path, argv, envp, 1);
18971 +}
18972 +
18973 +
18974 +/*
18975 + *      argv [0] = vshelper_path;
18976 + *      argv [1] = action: "netup", "netdown"
18977 + *      argv [2] = context identifier
18978 + *
18979 + *      envp [*] = type-specific parameters
18980 + */
18981 +
18982 +long vs_net_change(struct nx_info *nxi, unsigned int cmd)
18983 +{
18984 +       char id_buf[8], cmd_buf[16];
18985 +       char *argv[] = {vshelper_path, NULL, id_buf, 0};
18986 +       char *envp[] = {"HOME=/", "TERM=linux",
18987 +                       "PATH=/sbin:/usr/sbin:/bin:/usr/bin", cmd_buf, 0};
18988 +
18989 +       if (!nx_info_flags(nxi, NXF_SC_HELPER, 0))
18990 +               return 0;
18991 +
18992 +       snprintf(id_buf, sizeof(id_buf)-1, "%d", nxi->nx_id);
18993 +       snprintf(cmd_buf, sizeof(cmd_buf)-1, "VS_CMD=%08x", cmd);
18994 +
18995 +       switch (cmd) {
18996 +       case VSC_NETUP:
18997 +               argv[1] = "netup";
18998 +               break;
18999 +       case VSC_NETDOWN:
19000 +               argv[1] = "netdown";
19001 +               break;
19002 +       default:
19003 +               return 0;
19004 +       }
19005 +
19006 +       return do_vshelper(vshelper_path, argv, envp, 1);
19007 +}
19008 +
19009 diff -NurpP --minimal linux-3.0.25/kernel/vserver/history.c linux-3.0.25-vs2.3.2.3/kernel/vserver/history.c
19010 --- linux-3.0.25/kernel/vserver/history.c       1970-01-01 01:00:00.000000000 +0100
19011 +++ linux-3.0.25-vs2.3.2.3/kernel/vserver/history.c     2011-06-10 22:11:24.000000000 +0200
19012 @@ -0,0 +1,258 @@
19013 +/*
19014 + *  kernel/vserver/history.c
19015 + *
19016 + *  Virtual Context History Backtrace
19017 + *
19018 + *  Copyright (C) 2004-2007  Herbert Pötzl
19019 + *
19020 + *  V0.01  basic structure
19021 + *  V0.02  hash/unhash and trace
19022 + *  V0.03  preemption fixes
19023 + *
19024 + */
19025 +
19026 +#include <linux/module.h>
19027 +#include <asm/uaccess.h>
19028 +
19029 +#include <linux/vserver/context.h>
19030 +#include <linux/vserver/debug.h>
19031 +#include <linux/vserver/debug_cmd.h>
19032 +#include <linux/vserver/history.h>
19033 +
19034 +
19035 +#ifdef CONFIG_VSERVER_HISTORY
19036 +#define VXH_SIZE       CONFIG_VSERVER_HISTORY_SIZE
19037 +#else
19038 +#define VXH_SIZE       64
19039 +#endif
19040 +
19041 +struct _vx_history {
19042 +       unsigned int counter;
19043 +
19044 +       struct _vx_hist_entry entry[VXH_SIZE + 1];
19045 +};
19046 +
19047 +
19048 +DEFINE_PER_CPU(struct _vx_history, vx_history_buffer);
19049 +
19050 +unsigned volatile int vxh_active = 1;
19051 +
19052 +static atomic_t sequence = ATOMIC_INIT(0);
19053 +
19054 +
19055 +/*     vxh_advance()
19056 +
19057 +       * requires disabled preemption                          */
19058 +
19059 +struct _vx_hist_entry *vxh_advance(void *loc)
19060 +{
19061 +       unsigned int cpu = smp_processor_id();
19062 +       struct _vx_history *hist = &per_cpu(vx_history_buffer, cpu);
19063 +       struct _vx_hist_entry *entry;
19064 +       unsigned int index;
19065 +
19066 +       index = vxh_active ? (hist->counter++ % VXH_SIZE) : VXH_SIZE;
19067 +       entry = &hist->entry[index];
19068 +
19069 +       entry->seq = atomic_inc_return(&sequence);
19070 +       entry->loc = loc;
19071 +       return entry;
19072 +}
19073 +
19074 +EXPORT_SYMBOL_GPL(vxh_advance);
19075 +
19076 +
19077 +#define VXH_LOC_FMTS   "(#%04x,*%d):%p"
19078 +
19079 +#define VXH_LOC_ARGS(e)        (e)->seq, cpu, (e)->loc
19080 +
19081 +
19082 +#define VXH_VXI_FMTS   "%p[#%d,%d.%d]"
19083 +
19084 +#define VXH_VXI_ARGS(e)        (e)->vxi.ptr,                           \
19085 +                       (e)->vxi.ptr ? (e)->vxi.xid : 0,        \
19086 +                       (e)->vxi.ptr ? (e)->vxi.usecnt : 0,     \
19087 +                       (e)->vxi.ptr ? (e)->vxi.tasks : 0
19088 +
19089 +void   vxh_dump_entry(struct _vx_hist_entry *e, unsigned cpu)
19090 +{
19091 +       switch (e->type) {
19092 +       case VXH_THROW_OOPS:
19093 +               printk( VXH_LOC_FMTS " oops \n", VXH_LOC_ARGS(e));
19094 +               break;
19095 +
19096 +       case VXH_GET_VX_INFO:
19097 +       case VXH_PUT_VX_INFO:
19098 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS "\n",
19099 +                       VXH_LOC_ARGS(e),
19100 +                       (e->type == VXH_GET_VX_INFO) ? "get" : "put",
19101 +                       VXH_VXI_ARGS(e));
19102 +               break;
19103 +
19104 +       case VXH_INIT_VX_INFO:
19105 +       case VXH_SET_VX_INFO:
19106 +       case VXH_CLR_VX_INFO:
19107 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS " @%p\n",
19108 +                       VXH_LOC_ARGS(e),
19109 +                       (e->type == VXH_INIT_VX_INFO) ? "init" :
19110 +                       ((e->type == VXH_SET_VX_INFO) ? "set" : "clr"),
19111 +                       VXH_VXI_ARGS(e), e->sc.data);
19112 +               break;
19113 +
19114 +       case VXH_CLAIM_VX_INFO:
19115 +       case VXH_RELEASE_VX_INFO:
19116 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS " @%p\n",
19117 +                       VXH_LOC_ARGS(e),
19118 +                       (e->type == VXH_CLAIM_VX_INFO) ? "claim" : "release",
19119 +                       VXH_VXI_ARGS(e), e->sc.data);
19120 +               break;
19121 +
19122 +       case VXH_ALLOC_VX_INFO:
19123 +       case VXH_DEALLOC_VX_INFO:
19124 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS "\n",
19125 +                       VXH_LOC_ARGS(e),
19126 +                       (e->type == VXH_ALLOC_VX_INFO) ? "alloc" : "dealloc",
19127 +                       VXH_VXI_ARGS(e));
19128 +               break;
19129 +
19130 +       case VXH_HASH_VX_INFO:
19131 +       case VXH_UNHASH_VX_INFO:
19132 +               printk( VXH_LOC_FMTS " __%s_vx_info " VXH_VXI_FMTS "\n",
19133 +                       VXH_LOC_ARGS(e),
19134 +                       (e->type == VXH_HASH_VX_INFO) ? "hash" : "unhash",
19135 +                       VXH_VXI_ARGS(e));
19136 +               break;
19137 +
19138 +       case VXH_LOC_VX_INFO:
19139 +       case VXH_LOOKUP_VX_INFO:
19140 +       case VXH_CREATE_VX_INFO:
19141 +               printk( VXH_LOC_FMTS " __%s_vx_info [#%d] -> " VXH_VXI_FMTS "\n",
19142 +                       VXH_LOC_ARGS(e),
19143 +                       (e->type == VXH_CREATE_VX_INFO) ? "create" :
19144 +                       ((e->type == VXH_LOC_VX_INFO) ? "loc" : "lookup"),
19145 +                       e->ll.arg, VXH_VXI_ARGS(e));
19146 +               break;
19147 +       }
19148 +}
19149 +
19150 +static void __vxh_dump_history(void)
19151 +{
19152 +       unsigned int i, cpu;
19153 +
19154 +       printk("History:\tSEQ: %8x\tNR_CPUS: %d\n",
19155 +               atomic_read(&sequence), NR_CPUS);
19156 +
19157 +       for (i = 0; i < VXH_SIZE; i++) {
19158 +               for_each_online_cpu(cpu) {
19159 +                       struct _vx_history *hist =
19160 +                               &per_cpu(vx_history_buffer, cpu);
19161 +                       unsigned int index = (hist->counter - i) % VXH_SIZE;
19162 +                       struct _vx_hist_entry *entry = &hist->entry[index];
19163 +
19164 +                       vxh_dump_entry(entry, cpu);
19165 +               }
19166 +       }
19167 +}
19168 +
19169 +void   vxh_dump_history(void)
19170 +{
19171 +       vxh_active = 0;
19172 +#ifdef CONFIG_SMP
19173 +       local_irq_enable();
19174 +       smp_send_stop();
19175 +       local_irq_disable();
19176 +#endif
19177 +       __vxh_dump_history();
19178 +}
19179 +
19180 +
19181 +/* vserver syscall commands below here */
19182 +
19183 +
19184 +int vc_dump_history(uint32_t id)
19185 +{
19186 +       vxh_active = 0;
19187 +       __vxh_dump_history();
19188 +       vxh_active = 1;
19189 +
19190 +       return 0;
19191 +}
19192 +
19193 +
19194 +int do_read_history(struct __user _vx_hist_entry *data,
19195 +       int cpu, uint32_t *index, uint32_t *count)
19196 +{
19197 +       int pos, ret = 0;
19198 +       struct _vx_history *hist = &per_cpu(vx_history_buffer, cpu);
19199 +       int end = hist->counter;
19200 +       int start = end - VXH_SIZE + 2;
19201 +       int idx = *index;
19202 +
19203 +       /* special case: get current pos */
19204 +       if (!*count) {
19205 +               *index = end;
19206 +               return 0;
19207 +       }
19208 +
19209 +       /* have we lost some data? */
19210 +       if (idx < start)
19211 +               idx = start;
19212 +
19213 +       for (pos = 0; (pos < *count) && (idx < end); pos++, idx++) {
19214 +               struct _vx_hist_entry *entry =
19215 +                       &hist->entry[idx % VXH_SIZE];
19216 +
19217 +               /* send entry to userspace */
19218 +               ret = copy_to_user(&data[pos], entry, sizeof(*entry));
19219 +               if (ret)
19220 +                       break;
19221 +       }
19222 +       /* save new index and count */
19223 +       *index = idx;
19224 +       *count = pos;
19225 +       return ret ? ret : (*index < end);
19226 +}
19227 +
19228 +int vc_read_history(uint32_t id, void __user *data)
19229 +{
19230 +       struct vcmd_read_history_v0 vc_data;
19231 +       int ret;
19232 +
19233 +       if (id >= NR_CPUS)
19234 +               return -EINVAL;
19235 +
19236 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19237 +               return -EFAULT;
19238 +
19239 +       ret = do_read_history((struct __user _vx_hist_entry *)vc_data.data,
19240 +               id, &vc_data.index, &vc_data.count);
19241 +
19242 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19243 +               return -EFAULT;
19244 +       return ret;
19245 +}
19246 +
19247 +#ifdef CONFIG_COMPAT
19248 +
19249 +int vc_read_history_x32(uint32_t id, void __user *data)
19250 +{
19251 +       struct vcmd_read_history_v0_x32 vc_data;
19252 +       int ret;
19253 +
19254 +       if (id >= NR_CPUS)
19255 +               return -EINVAL;
19256 +
19257 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19258 +               return -EFAULT;
19259 +
19260 +       ret = do_read_history((struct __user _vx_hist_entry *)
19261 +               compat_ptr(vc_data.data_ptr),
19262 +               id, &vc_data.index, &vc_data.count);
19263 +
19264 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19265 +               return -EFAULT;
19266 +       return ret;
19267 +}
19268 +
19269 +#endif /* CONFIG_COMPAT */
19270 +
19271 diff -NurpP --minimal linux-3.0.25/kernel/vserver/inet.c linux-3.0.25-vs2.3.2.3/kernel/vserver/inet.c
19272 --- linux-3.0.25/kernel/vserver/inet.c  1970-01-01 01:00:00.000000000 +0100
19273 +++ linux-3.0.25-vs2.3.2.3/kernel/vserver/inet.c        2011-08-30 20:14:33.000000000 +0200
19274 @@ -0,0 +1,225 @@
19275 +
19276 +#include <linux/in.h>
19277 +#include <linux/inetdevice.h>
19278 +#include <linux/vs_inet.h>
19279 +#include <linux/vs_inet6.h>
19280 +#include <linux/vserver/debug.h>
19281 +#include <net/route.h>
19282 +#include <net/addrconf.h>
19283 +
19284 +
19285 +int nx_v4_addr_conflict(struct nx_info *nxi1, struct nx_info *nxi2)
19286 +{
19287 +       int ret = 0;
19288 +
19289 +       if (!nxi1 || !nxi2 || nxi1 == nxi2)
19290 +               ret = 1;
19291 +       else {
19292 +               struct nx_addr_v4 *ptr;
19293 +
19294 +               for (ptr = &nxi1->v4; ptr; ptr = ptr->next) {
19295 +                       if (v4_nx_addr_in_nx_info(nxi2, ptr, -1)) {
19296 +                               ret = 1;
19297 +                               break;
19298 +                       }
19299 +               }
19300 +       }
19301 +
19302 +       vxdprintk(VXD_CBIT(net, 2),
19303 +               "nx_v4_addr_conflict(%p,%p): %d",
19304 +               nxi1, nxi2, ret);
19305 +
19306 +       return ret;
19307 +}
19308 +
19309 +
19310 +#ifdef CONFIG_IPV6
19311 +
19312 +int nx_v6_addr_conflict(struct nx_info *nxi1, struct nx_info *nxi2)
19313 +{
19314 +       int ret = 0;
19315 +
19316 +       if (!nxi1 || !nxi2 || nxi1 == nxi2)
19317 +               ret = 1;
19318 +       else {
19319 +               struct nx_addr_v6 *ptr;
19320 +
19321 +               for (ptr = &nxi1->v6; ptr; ptr = ptr->next) {
19322 +                       if (v6_nx_addr_in_nx_info(nxi2, ptr, -1)) {
19323 +                               ret = 1;
19324 +                               break;
19325 +                       }
19326 +               }
19327 +       }
19328 +
19329 +       vxdprintk(VXD_CBIT(net, 2),
19330 +               "nx_v6_addr_conflict(%p,%p): %d",
19331 +               nxi1, nxi2, ret);
19332 +
19333 +       return ret;
19334 +}
19335 +
19336 +#endif
19337 +
19338 +int v4_dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
19339 +{
19340 +       struct in_device *in_dev;
19341 +       struct in_ifaddr **ifap;
19342 +       struct in_ifaddr *ifa;
19343 +       int ret = 0;
19344 +
19345 +       if (!dev)
19346 +               goto out;
19347 +       in_dev = in_dev_get(dev);
19348 +       if (!in_dev)
19349 +               goto out;
19350 +
19351 +       for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
19352 +               ifap = &ifa->ifa_next) {
19353 +               if (v4_addr_in_nx_info(nxi, ifa->ifa_local, NXA_MASK_SHOW)) {
19354 +                       ret = 1;
19355 +                       break;
19356 +               }
19357 +       }
19358 +       in_dev_put(in_dev);
19359 +out:
19360 +       return ret;
19361 +}
19362 +
19363 +
19364 +#ifdef CONFIG_IPV6
19365 +
19366 +int v6_dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
19367 +{
19368 +       struct inet6_dev *in_dev;
19369 +       struct inet6_ifaddr *ifa;
19370 +       int ret = 0;
19371 +
19372 +       if (!dev)
19373 +               goto out;
19374 +       in_dev = in6_dev_get(dev);
19375 +       if (!in_dev)
19376 +               goto out;
19377 +
19378 +       // for (ifap = &in_dev->addr_list; (ifa = *ifap) != NULL;
19379 +       list_for_each_entry(ifa, &in_dev->addr_list, if_list) {
19380 +               if (v6_addr_in_nx_info(nxi, &ifa->addr, -1)) {
19381 +                       ret = 1;
19382 +                       break;
19383 +               }
19384 +       }
19385 +       in6_dev_put(in_dev);
19386 +out:
19387 +       return ret;
19388 +}
19389 +
19390 +#endif
19391 +
19392 +int dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
19393 +{
19394 +       int ret = 1;
19395 +
19396 +       if (!nxi)
19397 +               goto out;
19398 +       if (nxi->v4.type && v4_dev_in_nx_info(dev, nxi))
19399 +               goto out;
19400 +#ifdef CONFIG_IPV6
19401 +       ret = 2;
19402 +       if (nxi->v6.type && v6_dev_in_nx_info(dev, nxi))
19403 +               goto out;
19404 +#endif
19405 +       ret = 0;
19406 +out:
19407 +       vxdprintk(VXD_CBIT(net, 3),
19408 +               "dev_in_nx_info(%p,%p[#%d]) = %d",
19409 +               dev, nxi, nxi ? nxi->nx_id : 0, ret);
19410 +       return ret;
19411 +}
19412 +
19413 +struct rtable *ip_v4_find_src(struct net *net, struct nx_info *nxi,
19414 +       struct flowi4 *fl4)
19415 +{
19416 +       struct rtable *rt;
19417 +
19418 +       if (!nxi)
19419 +               return NULL;
19420 +
19421 +       /* FIXME: handle lback only case */
19422 +       if (!NX_IPV4(nxi))
19423 +               return ERR_PTR(-EPERM);
19424 +
19425 +       vxdprintk(VXD_CBIT(net, 4),
19426 +               "ip_v4_find_src(%p[#%u]) " NIPQUAD_FMT " -> " NIPQUAD_FMT,
19427 +               nxi, nxi ? nxi->nx_id : 0,
19428 +               NIPQUAD(fl4->saddr), NIPQUAD(fl4->daddr));
19429 +
19430 +       /* single IP is unconditional */
19431 +       if (nx_info_flags(nxi, NXF_SINGLE_IP, 0) &&
19432 +               (fl4->saddr == INADDR_ANY))
19433 +               fl4->saddr = nxi->v4.ip[0].s_addr;
19434 +
19435 +       if (fl4->saddr == INADDR_ANY) {
19436 +               struct nx_addr_v4 *ptr;
19437 +               __be32 found = 0;
19438 +
19439 +               rt = __ip_route_output_key(net, fl4);
19440 +               if (!IS_ERR(rt)) {
19441 +                       found = fl4->saddr;
19442 +                       ip_rt_put(rt);
19443 +                       vxdprintk(VXD_CBIT(net, 4),
19444 +                               "ip_v4_find_src(%p[#%u]) rok[%u]: " NIPQUAD_FMT,
19445 +                               nxi, nxi ? nxi->nx_id : 0, fl4->flowi4_oif, NIPQUAD(found));
19446 +                       if (v4_addr_in_nx_info(nxi, found, NXA_MASK_BIND))
19447 +                               goto found;
19448 +               }
19449 +
19450 +               for (ptr = &nxi->v4; ptr; ptr = ptr->next) {
19451 +                       __be32 primary = ptr->ip[0].s_addr;
19452 +                       __be32 mask = ptr->mask.s_addr;
19453 +                       __be32 neta = primary & mask;
19454 +
19455 +                       vxdprintk(VXD_CBIT(net, 4), "ip_v4_find_src(%p[#%u]) chk: "
19456 +                               NIPQUAD_FMT "/" NIPQUAD_FMT "/" NIPQUAD_FMT,
19457 +                               nxi, nxi ? nxi->nx_id : 0, NIPQUAD(primary),
19458 +                               NIPQUAD(mask), NIPQUAD(neta));
19459 +                       if ((found & mask) != neta)
19460 +                               continue;
19461 +
19462 +                       fl4->saddr = primary;
19463 +                       rt = __ip_route_output_key(net, fl4);
19464 +                       vxdprintk(VXD_CBIT(net, 4),
19465 +                               "ip_v4_find_src(%p[#%u]) rok[%u]: " NIPQUAD_FMT,
19466 +                               nxi, nxi ? nxi->nx_id : 0, fl4->flowi4_oif, NIPQUAD(primary));
19467 +                       if (!IS_ERR(rt)) {
19468 +                               found = fl4->saddr;
19469 +                               ip_rt_put(rt);
19470 +                               if (found == primary)
19471 +                                       goto found;
19472 +                       }
19473 +               }
19474 +               /* still no source ip? */
19475 +               found = ipv4_is_loopback(fl4->daddr)
19476 +                       ? IPI_LOOPBACK : nxi->v4.ip[0].s_addr;
19477 +       found:
19478 +               /* assign src ip to flow */
19479 +               fl4->saddr = found;
19480 +
19481 +       } else {
19482 +               if (!v4_addr_in_nx_info(nxi, fl4->saddr, NXA_MASK_BIND))
19483 +                       return ERR_PTR(-EPERM);
19484 +       }
19485 +
19486 +       if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0)) {
19487 +               if (ipv4_is_loopback(fl4->daddr))
19488 +                       fl4->daddr = nxi->v4_lback.s_addr;
19489 +               if (ipv4_is_loopback(fl4->saddr))
19490 +                       fl4->saddr = nxi->v4_lback.s_addr;
19491 +       } else if (ipv4_is_loopback(fl4->daddr) &&
19492 +               !nx_info_flags(nxi, NXF_LBACK_ALLOW, 0))
19493 +               return ERR_PTR(-EPERM);
19494 +
19495 +       return NULL;
19496 +}
19497 +
19498 +EXPORT_SYMBOL_GPL(ip_v4_find_src);
19499 +
19500 diff -NurpP --minimal linux-3.0.25/kernel/vserver/init.c linux-3.0.25-vs2.3.2.3/kernel/vserver/init.c
19501 --- linux-3.0.25/kernel/vserver/init.c  1970-01-01 01:00:00.000000000 +0100
19502 +++ linux-3.0.25-vs2.3.2.3/kernel/vserver/init.c        2011-06-10 22:11:24.000000000 +0200
19503 @@ -0,0 +1,45 @@
19504 +/*
19505 + *  linux/kernel/init.c
19506 + *
19507 + *  Virtual Server Init
19508 + *
19509 + *  Copyright (C) 2004-2007  Herbert Pötzl
19510 + *
19511 + *  V0.01  basic structure
19512 + *
19513 + */
19514 +
19515 +#include <linux/init.h>
19516 +
19517 +int    vserver_register_sysctl(void);
19518 +void   vserver_unregister_sysctl(void);
19519 +
19520 +
19521 +static int __init init_vserver(void)
19522 +{
19523 +       int ret = 0;
19524 +
19525 +#ifdef CONFIG_VSERVER_DEBUG
19526 +       vserver_register_sysctl();
19527 +#endif
19528 +       return ret;
19529 +}
19530 +
19531 +
19532 +static void __exit exit_vserver(void)
19533 +{
19534 +
19535 +#ifdef CONFIG_VSERVER_DEBUG
19536 +       vserver_unregister_sysctl();
19537 +#endif
19538 +       return;
19539 +}
19540 +
19541 +/* FIXME: GFP_ZONETYPES gone
19542 +long vx_slab[GFP_ZONETYPES]; */
19543 +long vx_area;
19544 +
19545 +
19546 +module_init(init_vserver);
19547 +module_exit(exit_vserver);
19548 +
19549 diff -NurpP --minimal linux-3.0.25/kernel/vserver/inode.c linux-3.0.25-vs2.3.2.3/kernel/vserver/inode.c
19550 --- linux-3.0.25/kernel/vserver/inode.c 1970-01-01 01:00:00.000000000 +0100
19551 +++ linux-3.0.25-vs2.3.2.3/kernel/vserver/inode.c       2012-01-24 01:46:36.000000000 +0100
19552 @@ -0,0 +1,437 @@
19553 +/*
19554 + *  linux/kernel/vserver/inode.c
19555 + *
19556 + *  Virtual Server: File System Support
19557 + *
19558 + *  Copyright (C) 2004-2007  Herbert Pötzl
19559 + *
19560 + *  V0.01  separated from vcontext V0.05
19561 + *  V0.02  moved to tag (instead of xid)
19562 + *
19563 + */
19564 +
19565 +#include <linux/tty.h>
19566 +#include <linux/proc_fs.h>
19567 +#include <linux/devpts_fs.h>
19568 +#include <linux/fs.h>
19569 +#include <linux/file.h>
19570 +#include <linux/mount.h>
19571 +#include <linux/parser.h>
19572 +#include <linux/namei.h>
19573 +#include <linux/vserver/inode.h>
19574 +#include <linux/vserver/inode_cmd.h>
19575 +#include <linux/vs_base.h>
19576 +#include <linux/vs_tag.h>
19577 +
19578 +#include <asm/uaccess.h>
19579 +
19580 +
19581 +static int __vc_get_iattr(struct inode *in, uint32_t *tag, uint32_t *flags, uint32_t *mask)
19582 +{
19583 +       struct proc_dir_entry *entry;
19584 +
19585 +       if (!in || !in->i_sb)
19586 +               return -ESRCH;
19587 +
19588 +       *flags = IATTR_TAG
19589 +               | (IS_IMMUTABLE(in) ? IATTR_IMMUTABLE : 0)
19590 +               | (IS_IXUNLINK(in) ? IATTR_IXUNLINK : 0)
19591 +               | (IS_BARRIER(in) ? IATTR_BARRIER : 0)
19592 +               | (IS_COW(in) ? IATTR_COW : 0);
19593 +       *mask = IATTR_IXUNLINK | IATTR_IMMUTABLE | IATTR_COW;
19594 +
19595 +       if (S_ISDIR(in->i_mode))
19596 +               *mask |= IATTR_BARRIER;
19597 +
19598 +       if (IS_TAGGED(in)) {
19599 +               *tag = in->i_tag;
19600 +               *mask |= IATTR_TAG;
19601 +       }
19602 +
19603 +       switch (in->i_sb->s_magic) {
19604 +       case PROC_SUPER_MAGIC:
19605 +               entry = PROC_I(in)->pde;
19606 +
19607 +               /* check for specific inodes? */
19608 +               if (entry)
19609 +                       *mask |= IATTR_FLAGS;
19610 +               if (entry)
19611 +                       *flags |= (entry->vx_flags & IATTR_FLAGS);
19612 +               else
19613 +                       *flags |= (PROC_I(in)->vx_flags & IATTR_FLAGS);
19614 +               break;
19615 +
19616 +       case DEVPTS_SUPER_MAGIC:
19617 +               *tag = in->i_tag;
19618 +               *mask |= IATTR_TAG;
19619 +               break;
19620 +
19621 +       default:
19622 +               break;
19623 +       }
19624 +       return 0;
19625 +}
19626 +
19627 +int vc_get_iattr(void __user *data)
19628 +{
19629 +       struct path path;
19630 +       struct vcmd_ctx_iattr_v1 vc_data = { .tag = -1 };
19631 +       int ret;
19632 +
19633 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19634 +               return -EFAULT;
19635 +
19636 +       ret = user_lpath(vc_data.name, &path);
19637 +       if (!ret) {
19638 +               ret = __vc_get_iattr(path.dentry->d_inode,
19639 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
19640 +               path_put(&path);
19641 +       }
19642 +       if (ret)
19643 +               return ret;
19644 +
19645 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19646 +               ret = -EFAULT;
19647 +       return ret;
19648 +}
19649 +
19650 +#ifdef CONFIG_COMPAT
19651 +
19652 +int vc_get_iattr_x32(void __user *data)
19653 +{
19654 +       struct path path;
19655 +       struct vcmd_ctx_iattr_v1_x32 vc_data = { .tag = -1 };
19656 +       int ret;
19657 +
19658 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19659 +               return -EFAULT;
19660 +
19661 +       ret = user_lpath(compat_ptr(vc_data.name_ptr), &path);
19662 +       if (!ret) {
19663 +               ret = __vc_get_iattr(path.dentry->d_inode,
19664 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
19665 +               path_put(&path);
19666 +       }
19667 +       if (ret)
19668 +               return ret;
19669 +
19670 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19671 +               ret = -EFAULT;
19672 +       return ret;
19673 +}
19674 +
19675 +#endif /* CONFIG_COMPAT */
19676 +
19677 +
19678 +int vc_fget_iattr(uint32_t fd, void __user *data)
19679 +{
19680 +       struct file *filp;
19681 +       struct vcmd_ctx_fiattr_v0 vc_data = { .tag = -1 };
19682 +       int ret;
19683 +
19684 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19685 +               return -EFAULT;
19686 +
19687 +       filp = fget(fd);
19688 +       if (!filp || !filp->f_dentry || !filp->f_dentry->d_inode)
19689 +               return -EBADF;
19690 +
19691 +       ret = __vc_get_iattr(filp->f_dentry->d_inode,
19692 +               &vc_data.tag, &vc_data.flags, &vc_data.mask);
19693 +
19694 +       fput(filp);
19695 +
19696 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19697 +               ret = -EFAULT;
19698 +       return ret;
19699 +}
19700 +
19701 +
19702 +static int __vc_set_iattr(struct dentry *de, uint32_t *tag, uint32_t *flags, uint32_t *mask)
19703 +{
19704 +       struct inode *in = de->d_inode;
19705 +       int error = 0, is_proc = 0, has_tag = 0;
19706 +       struct iattr attr = { 0 };
19707 +
19708 +       if (!in || !in->i_sb)
19709 +               return -ESRCH;
19710 +
19711 +       is_proc = (in->i_sb->s_magic == PROC_SUPER_MAGIC);
19712 +       if ((*mask & IATTR_FLAGS) && !is_proc)
19713 +               return -EINVAL;
19714 +
19715 +       has_tag = IS_TAGGED(in) ||
19716 +               (in->i_sb->s_magic == DEVPTS_SUPER_MAGIC);
19717 +       if ((*mask & IATTR_TAG) && !has_tag)
19718 +               return -EINVAL;
19719 +
19720 +       mutex_lock(&in->i_mutex);
19721 +       if (*mask & IATTR_TAG) {
19722 +               attr.ia_tag = *tag;
19723 +               attr.ia_valid |= ATTR_TAG;
19724 +       }
19725 +
19726 +       if (*mask & IATTR_FLAGS) {
19727 +               struct proc_dir_entry *entry = PROC_I(in)->pde;
19728 +               unsigned int iflags = PROC_I(in)->vx_flags;
19729 +
19730 +               iflags = (iflags & ~(*mask & IATTR_FLAGS))
19731 +                       | (*flags & IATTR_FLAGS);
19732 +               PROC_I(in)->vx_flags = iflags;
19733 +               if (entry)
19734 +                       entry->vx_flags = iflags;
19735 +       }
19736 +
19737 +       if (*mask & (IATTR_IMMUTABLE | IATTR_IXUNLINK |
19738 +               IATTR_BARRIER | IATTR_COW)) {
19739 +               int iflags = in->i_flags;
19740 +               int vflags = in->i_vflags;
19741 +
19742 +               if (*mask & IATTR_IMMUTABLE) {
19743 +                       if (*flags & IATTR_IMMUTABLE)
19744 +                               iflags |= S_IMMUTABLE;
19745 +                       else
19746 +                               iflags &= ~S_IMMUTABLE;
19747 +               }
19748 +               if (*mask & IATTR_IXUNLINK) {
19749 +                       if (*flags & IATTR_IXUNLINK)
19750 +                               iflags |= S_IXUNLINK;
19751 +                       else
19752 +                               iflags &= ~S_IXUNLINK;
19753 +               }
19754 +               if (S_ISDIR(in->i_mode) && (*mask & IATTR_BARRIER)) {
19755 +                       if (*flags & IATTR_BARRIER)
19756 +                               vflags |= V_BARRIER;
19757 +                       else
19758 +                               vflags &= ~V_BARRIER;
19759 +               }
19760 +               if (S_ISREG(in->i_mode) && (*mask & IATTR_COW)) {
19761 +                       if (*flags & IATTR_COW)
19762 +                               vflags |= V_COW;
19763 +                       else
19764 +                               vflags &= ~V_COW;
19765 +               }
19766 +               if (in->i_op && in->i_op->sync_flags) {
19767 +                       error = in->i_op->sync_flags(in, iflags, vflags);
19768 +                       if (error)
19769 +                               goto out;
19770 +               }
19771 +       }
19772 +
19773 +       if (attr.ia_valid) {
19774 +               if (in->i_op && in->i_op->setattr)
19775 +                       error = in->i_op->setattr(de, &attr);
19776 +               else {
19777 +                       error = inode_change_ok(in, &attr);
19778 +                       if (!error) {
19779 +                               setattr_copy(in, &attr);
19780 +                               mark_inode_dirty(in);
19781 +                       }
19782 +               }
19783 +       }
19784 +
19785 +out:
19786 +       mutex_unlock(&in->i_mutex);
19787 +       return error;
19788 +}
19789 +
19790 +int vc_set_iattr(void __user *data)
19791 +{
19792 +       struct path path;
19793 +       struct vcmd_ctx_iattr_v1 vc_data;
19794 +       int ret;
19795 +
19796 +       if (!capable(CAP_LINUX_IMMUTABLE))
19797 +               return -EPERM;
19798 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19799 +               return -EFAULT;
19800 +
19801 +       ret = user_lpath(vc_data.name, &path);
19802 +       if (!ret) {
19803 +               ret = __vc_set_iattr(path.dentry,
19804 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
19805 +               path_put(&path);
19806 +       }
19807 +
19808 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19809 +               ret = -EFAULT;
19810 +       return ret;
19811 +}
19812 +
19813 +#ifdef CONFIG_COMPAT
19814 +
19815 +int vc_set_iattr_x32(void __user *data)
19816 +{
19817 +       struct path path;
19818 +       struct vcmd_ctx_iattr_v1_x32 vc_data;
19819 +       int ret;
19820 +
19821 +       if (!capable(CAP_LINUX_IMMUTABLE))
19822 +               return -EPERM;
19823 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19824 +               return -EFAULT;
19825 +
19826 +       ret = user_lpath(compat_ptr(vc_data.name_ptr), &path);
19827 +       if (!ret) {
19828 +               ret = __vc_set_iattr(path.dentry,
19829 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
19830 +               path_put(&path);
19831 +       }
19832 +
19833 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19834 +               ret = -EFAULT;
19835 +       return ret;
19836 +}
19837 +
19838 +#endif /* CONFIG_COMPAT */
19839 +
19840 +int vc_fset_iattr(uint32_t fd, void __user *data)
19841 +{
19842 +       struct file *filp;
19843 +       struct vcmd_ctx_fiattr_v0 vc_data;
19844 +       int ret;
19845 +
19846 +       if (!capable(CAP_LINUX_IMMUTABLE))
19847 +               return -EPERM;
19848 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19849 +               return -EFAULT;
19850 +
19851 +       filp = fget(fd);
19852 +       if (!filp || !filp->f_dentry || !filp->f_dentry->d_inode)
19853 +               return -EBADF;
19854 +
19855 +       ret = __vc_set_iattr(filp->f_dentry, &vc_data.tag,
19856 +               &vc_data.flags, &vc_data.mask);
19857 +
19858 +       fput(filp);
19859 +
19860 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19861 +               return -EFAULT;
19862 +       return ret;
19863 +}
19864 +
19865 +
19866 +enum { Opt_notagcheck, Opt_tag, Opt_notag, Opt_tagid, Opt_err };
19867 +
19868 +static match_table_t tokens = {
19869 +       {Opt_notagcheck, "notagcheck"},
19870 +#ifdef CONFIG_PROPAGATE
19871 +       {Opt_notag, "notag"},
19872 +       {Opt_tag, "tag"},
19873 +       {Opt_tagid, "tagid=%u"},
19874 +#endif
19875 +       {Opt_err, NULL}
19876 +};
19877 +
19878 +
19879 +static void __dx_parse_remove(char *string, char *opt)
19880 +{
19881 +       char *p = strstr(string, opt);
19882 +       char *q = p;
19883 +
19884 +       if (p) {
19885 +               while (*q != '\0' && *q != ',')
19886 +                       q++;
19887 +               while (*q)
19888 +                       *p++ = *q++;
19889 +               while (*p)
19890 +                       *p++ = '\0';
19891 +       }
19892 +}
19893 +
19894 +int dx_parse_tag(char *string, tag_t *tag, int remove, int *mnt_flags,
19895 +                unsigned long *flags)
19896 +{
19897 +       int set = 0;
19898 +       substring_t args[MAX_OPT_ARGS];
19899 +       int token;
19900 +       char *s, *p, *opts;
19901 +#if defined(CONFIG_PROPAGATE) || defined(CONFIG_VSERVER_DEBUG)
19902 +       int option = 0;
19903 +#endif
19904 +
19905 +       if (!string)
19906 +               return 0;
19907 +       s = kstrdup(string, GFP_KERNEL | GFP_ATOMIC);
19908 +       if (!s)
19909 +               return 0;
19910 +
19911 +       opts = s;
19912 +       while ((p = strsep(&opts, ",")) != NULL) {
19913 +               token = match_token(p, tokens, args);
19914 +
19915 +               switch (token) {
19916 +#ifdef CONFIG_PROPAGATE
19917 +               case Opt_tag:
19918 +                       if (tag)
19919 +                               *tag = 0;
19920 +                       if (remove)
19921 +                               __dx_parse_remove(s, "tag");
19922 +                       *mnt_flags |= MNT_TAGID;
19923 +                       set |= MNT_TAGID;
19924 +                       break;
19925 +               case Opt_notag:
19926 +                       if (remove)
19927 +                               __dx_parse_remove(s, "notag");
19928 +                       *mnt_flags |= MNT_NOTAG;
19929 +                       set |= MNT_NOTAG;
19930 +                       break;
19931 +               case Opt_tagid:
19932 +                       if (tag && !match_int(args, &option))
19933 +                               *tag = option;
19934 +                       if (remove)
19935 +                               __dx_parse_remove(s, "tagid");
19936 +                       *mnt_flags |= MNT_TAGID;
19937 +                       set |= MNT_TAGID;
19938 +                       break;
19939 +#endif
19940 +               case Opt_notagcheck:
19941 +                       if (remove)
19942 +                               __dx_parse_remove(s, "notagcheck");
19943 +                       *flags |= MS_NOTAGCHECK;
19944 +                       set |= MS_NOTAGCHECK;
19945 +                       break;
19946 +               }
19947 +               vxdprintk(VXD_CBIT(tag, 7),
19948 +                       "dx_parse_tag(" VS_Q("%s") "): %d:#%d",
19949 +                       p, token, option);
19950 +       }
19951 +       if (set)
19952 +               strcpy(string, s);
19953 +       kfree(s);
19954 +       return set;
19955 +}
19956 +
19957 +#ifdef CONFIG_PROPAGATE
19958 +
19959 +void __dx_propagate_tag(struct nameidata *nd, struct inode *inode)
19960 +{
19961 +       tag_t new_tag = 0;
19962 +       struct vfsmount *mnt;
19963 +       int propagate;
19964 +
19965 +       if (!nd)
19966 +               return;
19967 +       mnt = nd->path.mnt;
19968 +       if (!mnt)
19969 +               return;
19970 +
19971 +       propagate = (mnt->mnt_flags & MNT_TAGID);
19972 +       if (propagate)
19973 +               new_tag = mnt->mnt_tag;
19974 +
19975 +       vxdprintk(VXD_CBIT(tag, 7),
19976 +               "dx_propagate_tag(%p[#%lu.%d]): %d,%d",
19977 +               inode, inode->i_ino, inode->i_tag,
19978 +               new_tag, (propagate) ? 1 : 0);
19979 +
19980 +       if (propagate)
19981 +               inode->i_tag = new_tag;
19982 +}
19983 +
19984 +#include <linux/module.h>
19985 +
19986 +EXPORT_SYMBOL_GPL(__dx_propagate_tag);
19987 +
19988 +#endif /* CONFIG_PROPAGATE */
19989 +
19990 diff -NurpP --minimal linux-3.0.25/kernel/vserver/limit.c linux-3.0.25-vs2.3.2.3/kernel/vserver/limit.c
19991 --- linux-3.0.25/kernel/vserver/limit.c 1970-01-01 01:00:00.000000000 +0100
19992 +++ linux-3.0.25-vs2.3.2.3/kernel/vserver/limit.c       2011-10-11 20:48:08.000000000 +0200
19993 @@ -0,0 +1,360 @@
19994 +/*
19995 + *  linux/kernel/vserver/limit.c
19996 + *
19997 + *  Virtual Server: Context Limits
19998 + *
19999 + *  Copyright (C) 2004-2010  Herbert Pötzl
20000 + *
20001 + *  V0.01  broken out from vcontext V0.05
20002 + *  V0.02  changed vcmds to vxi arg
20003 + *  V0.03  added memory cgroup support
20004 + *
20005 + */
20006 +
20007 +#include <linux/sched.h>
20008 +#include <linux/module.h>
20009 +#include <linux/memcontrol.h>
20010 +#include <linux/res_counter.h>
20011 +#include <linux/vs_limit.h>
20012 +#include <linux/vserver/limit.h>
20013 +#include <linux/vserver/limit_cmd.h>
20014 +
20015 +#include <asm/uaccess.h>
20016 +
20017 +
20018 +const char *vlimit_name[NUM_LIMITS] = {
20019 +#ifdef CONFIG_VSERVER_LEGACY_MEM
20020 +       [RLIMIT_RSS]            = "RSS",
20021 +       [RLIMIT_AS]             = "VM",
20022 +#endif /* CONFIG_VSERVER_LEGACY_MEM */
20023 +       [RLIMIT_CPU]            = "CPU",
20024 +       [RLIMIT_NPROC]          = "NPROC",
20025 +       [RLIMIT_NOFILE]         = "NOFILE",
20026 +       [RLIMIT_LOCKS]          = "LOCKS",
20027 +       [RLIMIT_SIGPENDING]     = "SIGP",
20028 +       [RLIMIT_MSGQUEUE]       = "MSGQ",
20029 +
20030 +       [VLIMIT_NSOCK]          = "NSOCK",
20031 +       [VLIMIT_OPENFD]         = "OPENFD",
20032 +       [VLIMIT_SHMEM]          = "SHMEM",
20033 +       [VLIMIT_DENTRY]         = "DENTRY",
20034 +};
20035 +
20036 +EXPORT_SYMBOL_GPL(vlimit_name);
20037 +
20038 +#define MASK_ENTRY(x)  (1 << (x))
20039 +
20040 +const struct vcmd_ctx_rlimit_mask_v0 vlimit_mask = {
20041 +               /* minimum */
20042 +       0
20043 +       ,       /* softlimit */
20044 +#ifdef CONFIG_VSERVER_LEGACY_MEM
20045 +       MASK_ENTRY( RLIMIT_RSS          ) |
20046 +#endif /* CONFIG_VSERVER_LEGACY_MEM */
20047 +       0
20048 +       ,       /* maximum */
20049 +#ifdef CONFIG_VSERVER_LEGACY_MEM
20050 +       MASK_ENTRY( RLIMIT_RSS          ) |
20051 +       MASK_ENTRY( RLIMIT_AS           ) |
20052 +#endif /* CONFIG_VSERVER_LEGACY_MEM */
20053 +       MASK_ENTRY( RLIMIT_NPROC        ) |
20054 +       MASK_ENTRY( RLIMIT_NOFILE       ) |
20055 +       MASK_ENTRY( RLIMIT_LOCKS        ) |
20056 +       MASK_ENTRY( RLIMIT_MSGQUEUE     ) |
20057 +
20058 +       MASK_ENTRY( VLIMIT_NSOCK        ) |
20059 +       MASK_ENTRY( VLIMIT_OPENFD       ) |
20060 +       MASK_ENTRY( VLIMIT_SHMEM        ) |
20061 +       MASK_ENTRY( VLIMIT_DENTRY       ) |
20062 +       0
20063 +};
20064 +               /* accounting only */
20065 +uint32_t account_mask =
20066 +       MASK_ENTRY( VLIMIT_SEMARY       ) |
20067 +       MASK_ENTRY( VLIMIT_NSEMS        ) |
20068 +       MASK_ENTRY( VLIMIT_MAPPED       ) |
20069 +       0;
20070 +
20071 +
20072 +static int is_valid_vlimit(int id)
20073 +{
20074 +       uint32_t mask = vlimit_mask.minimum |
20075 +               vlimit_mask.softlimit | vlimit_mask.maximum;
20076 +       return mask & (1 << id);
20077 +}
20078 +
20079 +static int is_accounted_vlimit(int id)
20080 +{
20081 +       if (is_valid_vlimit(id))
20082 +               return 1;
20083 +       return account_mask & (1 << id);
20084 +}
20085 +
20086 +
20087 +static inline uint64_t vc_get_soft(struct vx_info *vxi, int id)
20088 +{
20089 +       rlim_t limit = __rlim_soft(&vxi->limit, id);
20090 +       return VX_VLIM(limit);
20091 +}
20092 +
20093 +static inline uint64_t vc_get_hard(struct vx_info *vxi, int id)
20094 +{
20095 +       rlim_t limit = __rlim_hard(&vxi->limit, id);
20096 +       return VX_VLIM(limit);
20097 +}
20098 +
20099 +static int do_get_rlimit(struct vx_info *vxi, uint32_t id,
20100 +       uint64_t *minimum, uint64_t *softlimit, uint64_t *maximum)
20101 +{
20102 +       if (!is_valid_vlimit(id))
20103 +               return -EINVAL;
20104 +
20105 +       if (minimum)
20106 +               *minimum = CRLIM_UNSET;
20107 +       if (softlimit)
20108 +               *softlimit = vc_get_soft(vxi, id);
20109 +       if (maximum)
20110 +               *maximum = vc_get_hard(vxi, id);
20111 +       return 0;
20112 +}
20113 +
20114 +int vc_get_rlimit(struct vx_info *vxi, void __user *data)
20115 +{
20116 +       struct vcmd_ctx_rlimit_v0 vc_data;
20117 +       int ret;
20118 +
20119 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20120 +               return -EFAULT;
20121 +
20122 +       ret = do_get_rlimit(vxi, vc_data.id,
20123 +               &vc_data.minimum, &vc_data.softlimit, &vc_data.maximum);
20124 +       if (ret)
20125 +               return ret;
20126 +
20127 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20128 +               return -EFAULT;
20129 +       return 0;
20130 +}
20131 +
20132 +static int do_set_rlimit(struct vx_info *vxi, uint32_t id,
20133 +       uint64_t minimum, uint64_t softlimit, uint64_t maximum)
20134 +{
20135 +       if (!is_valid_vlimit(id))
20136 +               return -EINVAL;
20137 +
20138 +       if (maximum != CRLIM_KEEP)
20139 +               __rlim_hard(&vxi->limit, id) = VX_RLIM(maximum);
20140 +       if (softlimit != CRLIM_KEEP)
20141 +               __rlim_soft(&vxi->limit, id) = VX_RLIM(softlimit);
20142 +
20143 +       /* clamp soft limit */
20144 +       if (__rlim_soft(&vxi->limit, id) > __rlim_hard(&vxi->limit, id))
20145 +               __rlim_soft(&vxi->limit, id) = __rlim_hard(&vxi->limit, id);
20146 +
20147 +       return 0;
20148 +}
20149 +
20150 +int vc_set_rlimit(struct vx_info *vxi, void __user *data)
20151 +{
20152 +       struct vcmd_ctx_rlimit_v0 vc_data;
20153 +
20154 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20155 +               return -EFAULT;
20156 +
20157 +       return do_set_rlimit(vxi, vc_data.id,
20158 +               vc_data.minimum, vc_data.softlimit, vc_data.maximum);
20159 +}
20160 +
20161 +#ifdef CONFIG_IA32_EMULATION
20162 +
20163 +int vc_set_rlimit_x32(struct vx_info *vxi, void __user *data)
20164 +{
20165 +       struct vcmd_ctx_rlimit_v0_x32 vc_data;
20166 +
20167 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20168 +               return -EFAULT;
20169 +
20170 +       return do_set_rlimit(vxi, vc_data.id,
20171 +               vc_data.minimum, vc_data.softlimit, vc_data.maximum);
20172 +}
20173 +
20174 +int vc_get_rlimit_x32(struct vx_info *vxi, void __user *data)
20175 +{
20176 +       struct vcmd_ctx_rlimit_v0_x32 vc_data;
20177 +       int ret;
20178 +
20179 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20180 +               return -EFAULT;
20181 +
20182 +       ret = do_get_rlimit(vxi, vc_data.id,
20183 +               &vc_data.minimum, &vc_data.softlimit, &vc_data.maximum);
20184 +       if (ret)
20185 +               return ret;
20186 +
20187 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20188 +               return -EFAULT;
20189 +       return 0;
20190 +}
20191 +
20192 +#endif /* CONFIG_IA32_EMULATION */
20193 +
20194 +
20195 +int vc_get_rlimit_mask(uint32_t id, void __user *data)
20196 +{
20197 +       if (copy_to_user(data, &vlimit_mask, sizeof(vlimit_mask)))
20198 +               return -EFAULT;
20199 +       return 0;
20200 +}
20201 +
20202 +
20203 +static inline void vx_reset_hits(struct _vx_limit *limit)
20204 +{
20205 +       int lim;
20206 +
20207 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
20208 +               atomic_set(&__rlim_lhit(limit, lim), 0);
20209 +       }
20210 +}
20211 +
20212 +int vc_reset_hits(struct vx_info *vxi, void __user *data)
20213 +{
20214 +       vx_reset_hits(&vxi->limit);
20215 +       return 0;
20216 +}
20217 +
20218 +static inline void vx_reset_minmax(struct _vx_limit *limit)
20219 +{
20220 +       rlim_t value;
20221 +       int lim;
20222 +
20223 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
20224 +               value = __rlim_get(limit, lim);
20225 +               __rlim_rmax(limit, lim) = value;
20226 +               __rlim_rmin(limit, lim) = value;
20227 +       }
20228 +}
20229 +
20230 +int vc_reset_minmax(struct vx_info *vxi, void __user *data)
20231 +{
20232 +       vx_reset_minmax(&vxi->limit);
20233 +       return 0;
20234 +}
20235 +
20236 +
20237 +int vc_rlimit_stat(struct vx_info *vxi, void __user *data)
20238 +{
20239 +       struct vcmd_rlimit_stat_v0 vc_data;
20240 +       struct _vx_limit *limit = &vxi->limit;
20241 +       int id;
20242 +
20243 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20244 +               return -EFAULT;
20245 +
20246 +       id = vc_data.id;
20247 +       if (!is_accounted_vlimit(id))
20248 +               return -EINVAL;
20249 +
20250 +       vx_limit_fixup(limit, id);
20251 +       vc_data.hits = atomic_read(&__rlim_lhit(limit, id));
20252 +       vc_data.value = __rlim_get(limit, id);
20253 +       vc_data.minimum = __rlim_rmin(limit, id);
20254 +       vc_data.maximum = __rlim_rmax(limit, id);
20255 +
20256 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20257 +               return -EFAULT;
20258 +       return 0;
20259 +}
20260 +
20261 +
20262 +void vx_vsi_meminfo(struct sysinfo *val)
20263 +{
20264 +#ifdef CONFIG_CGROUP_MEM_RES_CTLR
20265 +       struct mem_cgroup *mcg = mem_cgroup_from_task(current);
20266 +       u64 res_limit, res_usage;
20267 +
20268 +       if (!mcg)
20269 +               return;
20270 +
20271 +       res_limit = mem_cgroup_res_read_u64(mcg, RES_LIMIT);
20272 +       res_usage = mem_cgroup_res_read_u64(mcg, RES_USAGE);
20273 +
20274 +       if (res_limit != RESOURCE_MAX)
20275 +               val->totalram = (res_limit >> PAGE_SHIFT);
20276 +       val->freeram = val->totalram - (res_usage >> PAGE_SHIFT);
20277 +       val->bufferram = 0;
20278 +       val->totalhigh = 0;
20279 +       val->freehigh = 0;
20280 +#endif /* CONFIG_CGROUP_MEM_RES_CTLR */
20281 +       return;
20282 +}
20283 +
20284 +void vx_vsi_swapinfo(struct sysinfo *val)
20285 +{
20286 +#ifdef CONFIG_CGROUP_MEM_RES_CTLR
20287 +#ifdef CONFIG_CGROUP_MEM_RES_CTLR_SWAP
20288 +       struct mem_cgroup *mcg = mem_cgroup_from_task(current);
20289 +       u64 res_limit, res_usage, memsw_limit, memsw_usage;
20290 +       s64 swap_limit, swap_usage;
20291 +
20292 +       if (!mcg)
20293 +               return;
20294 +
20295 +       res_limit = mem_cgroup_res_read_u64(mcg, RES_LIMIT);
20296 +       res_usage = mem_cgroup_res_read_u64(mcg, RES_USAGE);
20297 +       memsw_limit = mem_cgroup_memsw_read_u64(mcg, RES_LIMIT);
20298 +       memsw_usage = mem_cgroup_memsw_read_u64(mcg, RES_USAGE);
20299 +
20300 +       /* memory unlimited */
20301 +       if (res_limit == RESOURCE_MAX)
20302 +               return;
20303 +
20304 +       swap_limit = memsw_limit - res_limit;
20305 +       /* we have a swap limit? */
20306 +       if (memsw_limit != RESOURCE_MAX)
20307 +               val->totalswap = swap_limit >> PAGE_SHIFT;
20308 +
20309 +       /* calculate swap part */
20310 +       swap_usage = (memsw_usage > res_usage) ?
20311 +               memsw_usage - res_usage : 0;
20312 +
20313 +       /* total shown minus usage gives free swap */
20314 +       val->freeswap = (swap_usage < swap_limit) ?
20315 +               val->totalswap - (swap_usage >> PAGE_SHIFT) : 0;
20316 +#else  /* !CONFIG_CGROUP_MEM_RES_CTLR_SWAP */
20317 +       val->totalswap = 0;
20318 +       val->freeswap = 0;
20319 +#endif /* !CONFIG_CGROUP_MEM_RES_CTLR_SWAP */
20320 +#endif /* CONFIG_CGROUP_MEM_RES_CTLR */
20321 +       return;
20322 +}
20323 +
20324 +long vx_vsi_cached(struct sysinfo *val)
20325 +{
20326 +#ifdef CONFIG_CGROUP_MEM_RES_CTLR
20327 +       struct mem_cgroup *mcg = mem_cgroup_from_task(current);
20328 +
20329 +       return mem_cgroup_stat_read_cache(mcg);
20330 +#else
20331 +       return 0;
20332 +#endif
20333 +}
20334 +
20335 +
20336 +unsigned long vx_badness(struct task_struct *task, struct mm_struct *mm)
20337 +{
20338 +       struct vx_info *vxi = mm->mm_vx_info;
20339 +       unsigned long points;
20340 +       rlim_t v, w;
20341 +
20342 +       if (!vxi)
20343 +               return 0;
20344 +
20345 +       points = vxi->vx_badness_bias;
20346 +
20347 +       v = __vx_cres_array_fixup(&vxi->limit, VLA_RSS);
20348 +       w = __rlim_soft(&vxi->limit, RLIMIT_RSS);
20349 +       points += (v > w) ? (v - w) : 0;
20350 +
20351 +       return points;
20352 +}
20353 +
20354 diff -NurpP --minimal linux-3.0.25/kernel/vserver/limit_init.h linux-3.0.25-vs2.3.2.3/kernel/vserver/limit_init.h
20355 --- linux-3.0.25/kernel/vserver/limit_init.h    1970-01-01 01:00:00.000000000 +0100
20356 +++ linux-3.0.25-vs2.3.2.3/kernel/vserver/limit_init.h  2011-06-10 22:11:24.000000000 +0200
20357 @@ -0,0 +1,31 @@
20358 +
20359 +
20360 +static inline void vx_info_init_limit(struct _vx_limit *limit)
20361 +{
20362 +       int lim;
20363 +
20364 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
20365 +               __rlim_soft(limit, lim) = RLIM_INFINITY;
20366 +               __rlim_hard(limit, lim) = RLIM_INFINITY;
20367 +               __rlim_set(limit, lim, 0);
20368 +               atomic_set(&__rlim_lhit(limit, lim), 0);
20369 +               __rlim_rmin(limit, lim) = 0;
20370 +               __rlim_rmax(limit, lim) = 0;
20371 +       }
20372 +}
20373 +
20374 +static inline void vx_info_exit_limit(struct _vx_limit *limit)
20375 +{
20376 +       rlim_t value;
20377 +       int lim;
20378 +
20379 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
20380 +               if ((1 << lim) & VLIM_NOCHECK)
20381 +                       continue;
20382 +               value = __rlim_get(limit, lim);
20383 +               vxwprintk_xid(value,
20384 +                       "!!! limit: %p[%s,%d] = %ld on exit.",
20385 +                       limit, vlimit_name[lim], lim, (long)value);
20386 +       }
20387 +}
20388 +
20389 diff -NurpP --minimal linux-3.0.25/kernel/vserver/limit_proc.h linux-3.0.25-vs2.3.2.3/kernel/vserver/limit_proc.h
20390 --- linux-3.0.25/kernel/vserver/limit_proc.h    1970-01-01 01:00:00.000000000 +0100
20391 +++ linux-3.0.25-vs2.3.2.3/kernel/vserver/limit_proc.h  2011-06-10 22:11:24.000000000 +0200
20392 @@ -0,0 +1,57 @@
20393 +#ifndef _VX_LIMIT_PROC_H
20394 +#define _VX_LIMIT_PROC_H
20395 +
20396 +#include <linux/vserver/limit_int.h>
20397 +
20398 +
20399 +#define VX_LIMIT_FMT   ":\t%8ld\t%8ld/%8ld\t%8lld/%8lld\t%6d\n"
20400 +#define VX_LIMIT_TOP   \
20401 +       "Limit\t current\t     min/max\t\t    soft/hard\t\thits\n"
20402 +
20403 +#define VX_LIMIT_ARG(r)                                \
20404 +       (unsigned long)__rlim_get(limit, r),    \
20405 +       (unsigned long)__rlim_rmin(limit, r),   \
20406 +       (unsigned long)__rlim_rmax(limit, r),   \
20407 +       VX_VLIM(__rlim_soft(limit, r)),         \
20408 +       VX_VLIM(__rlim_hard(limit, r)),         \
20409 +       atomic_read(&__rlim_lhit(limit, r))
20410 +
20411 +static inline int vx_info_proc_limit(struct _vx_limit *limit, char *buffer)
20412 +{
20413 +       vx_limit_fixup(limit, -1);
20414 +       return sprintf(buffer, VX_LIMIT_TOP
20415 +               "PROC"  VX_LIMIT_FMT
20416 +               "VM"    VX_LIMIT_FMT
20417 +               "VML"   VX_LIMIT_FMT
20418 +               "RSS"   VX_LIMIT_FMT
20419 +               "ANON"  VX_LIMIT_FMT
20420 +               "RMAP"  VX_LIMIT_FMT
20421 +               "FILES" VX_LIMIT_FMT
20422 +               "OFD"   VX_LIMIT_FMT
20423 +               "LOCKS" VX_LIMIT_FMT
20424 +               "SOCK"  VX_LIMIT_FMT
20425 +               "MSGQ"  VX_LIMIT_FMT
20426 +               "SHM"   VX_LIMIT_FMT
20427 +               "SEMA"  VX_LIMIT_FMT
20428 +               "SEMS"  VX_LIMIT_FMT
20429 +               "DENT"  VX_LIMIT_FMT,
20430 +               VX_LIMIT_ARG(RLIMIT_NPROC),
20431 +               VX_LIMIT_ARG(RLIMIT_AS),
20432 +               VX_LIMIT_ARG(RLIMIT_MEMLOCK),
20433 +               VX_LIMIT_ARG(RLIMIT_RSS),
20434 +               VX_LIMIT_ARG(VLIMIT_ANON),
20435 +               VX_LIMIT_ARG(VLIMIT_MAPPED),
20436 +               VX_LIMIT_ARG(RLIMIT_NOFILE),
20437 +               VX_LIMIT_ARG(VLIMIT_OPENFD),
20438 +               VX_LIMIT_ARG(RLIMIT_LOCKS),
20439 +               VX_LIMIT_ARG(VLIMIT_NSOCK),
20440 +               VX_LIMIT_ARG(RLIMIT_MSGQUEUE),
20441 +               VX_LIMIT_ARG(VLIMIT_SHMEM),
20442 +               VX_LIMIT_ARG(VLIMIT_SEMARY),
20443 +               VX_LIMIT_ARG(VLIMIT_NSEMS),
20444 +               VX_LIMIT_ARG(VLIMIT_DENTRY));
20445 +}
20446 +
20447 +#endif /* _VX_LIMIT_PROC_H */
20448 +
20449 +
20450 diff -NurpP --minimal linux-3.0.25/kernel/vserver/network.c linux-3.0.25-vs2.3.2.3/kernel/vserver/network.c
20451 --- linux-3.0.25/kernel/vserver/network.c       1970-01-01 01:00:00.000000000 +0100
20452 +++ linux-3.0.25-vs2.3.2.3/kernel/vserver/network.c     2011-06-10 23:20:56.000000000 +0200
20453 @@ -0,0 +1,912 @@
20454 +/*
20455 + *  linux/kernel/vserver/network.c
20456 + *
20457 + *  Virtual Server: Network Support
20458 + *
20459 + *  Copyright (C) 2003-2007  Herbert Pötzl
20460 + *
20461 + *  V0.01  broken out from vcontext V0.05
20462 + *  V0.02  cleaned up implementation
20463 + *  V0.03  added equiv nx commands
20464 + *  V0.04  switch to RCU based hash
20465 + *  V0.05  and back to locking again
20466 + *  V0.06  changed vcmds to nxi arg
20467 + *  V0.07  have __create claim() the nxi
20468 + *
20469 + */
20470 +
20471 +#include <linux/err.h>
20472 +#include <linux/slab.h>
20473 +#include <linux/rcupdate.h>
20474 +
20475 +#include <linux/vs_network.h>
20476 +#include <linux/vs_pid.h>
20477 +#include <linux/vserver/network_cmd.h>
20478 +
20479 +
20480 +atomic_t nx_global_ctotal      = ATOMIC_INIT(0);
20481 +atomic_t nx_global_cactive     = ATOMIC_INIT(0);
20482 +
20483 +static struct kmem_cache *nx_addr_v4_cachep = NULL;
20484 +static struct kmem_cache *nx_addr_v6_cachep = NULL;
20485 +
20486 +
20487 +static int __init init_network(void)
20488 +{
20489 +       nx_addr_v4_cachep = kmem_cache_create("nx_v4_addr_cache",
20490 +               sizeof(struct nx_addr_v4), 0,
20491 +               SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
20492 +       nx_addr_v6_cachep = kmem_cache_create("nx_v6_addr_cache",
20493 +               sizeof(struct nx_addr_v6), 0,
20494 +               SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
20495 +       return 0;
20496 +}
20497 +
20498 +
20499 +/*     __alloc_nx_addr_v4()                                    */
20500 +
20501 +static inline struct nx_addr_v4 *__alloc_nx_addr_v4(void)
20502 +{
20503 +       struct nx_addr_v4 *nxa = kmem_cache_alloc(
20504 +               nx_addr_v4_cachep, GFP_KERNEL);
20505 +
20506 +       if (!IS_ERR(nxa))
20507 +               memset(nxa, 0, sizeof(*nxa));
20508 +       return nxa;
20509 +}
20510 +
20511 +/*     __dealloc_nx_addr_v4()                                  */
20512 +
20513 +static inline void __dealloc_nx_addr_v4(struct nx_addr_v4 *nxa)
20514 +{
20515 +       kmem_cache_free(nx_addr_v4_cachep, nxa);
20516 +}
20517 +
20518 +/*     __dealloc_nx_addr_v4_all()                              */
20519 +
20520 +static inline void __dealloc_nx_addr_v4_all(struct nx_addr_v4 *nxa)
20521 +{
20522 +       while (nxa) {
20523 +               struct nx_addr_v4 *next = nxa->next;
20524 +
20525 +               __dealloc_nx_addr_v4(nxa);
20526 +               nxa = next;
20527 +       }
20528 +}
20529 +
20530 +
20531 +#ifdef CONFIG_IPV6
20532 +
20533 +/*     __alloc_nx_addr_v6()                                    */
20534 +
20535 +static inline struct nx_addr_v6 *__alloc_nx_addr_v6(void)
20536 +{
20537 +       struct nx_addr_v6 *nxa = kmem_cache_alloc(
20538 +               nx_addr_v6_cachep, GFP_KERNEL);
20539 +
20540 +       if (!IS_ERR(nxa))
20541 +               memset(nxa, 0, sizeof(*nxa));
20542 +       return nxa;
20543 +}
20544 +
20545 +/*     __dealloc_nx_addr_v6()                                  */
20546 +
20547 +static inline void __dealloc_nx_addr_v6(struct nx_addr_v6 *nxa)
20548 +{
20549 +       kmem_cache_free(nx_addr_v6_cachep, nxa);
20550 +}
20551 +
20552 +/*     __dealloc_nx_addr_v6_all()                              */
20553 +
20554 +static inline void __dealloc_nx_addr_v6_all(struct nx_addr_v6 *nxa)
20555 +{
20556 +       while (nxa) {
20557 +               struct nx_addr_v6 *next = nxa->next;
20558 +
20559 +               __dealloc_nx_addr_v6(nxa);
20560 +               nxa = next;
20561 +       }
20562 +}
20563 +
20564 +#endif /* CONFIG_IPV6 */
20565 +
20566 +/*     __alloc_nx_info()
20567 +
20568 +       * allocate an initialized nx_info struct
20569 +       * doesn't make it visible (hash)                        */
20570 +
20571 +static struct nx_info *__alloc_nx_info(nid_t nid)
20572 +{
20573 +       struct nx_info *new = NULL;
20574 +
20575 +       vxdprintk(VXD_CBIT(nid, 1), "alloc_nx_info(%d)*", nid);
20576 +
20577 +       /* would this benefit from a slab cache? */
20578 +       new = kmalloc(sizeof(struct nx_info), GFP_KERNEL);
20579 +       if (!new)
20580 +               return 0;
20581 +
20582 +       memset(new, 0, sizeof(struct nx_info));
20583 +       new->nx_id = nid;
20584 +       INIT_HLIST_NODE(&new->nx_hlist);
20585 +       atomic_set(&new->nx_usecnt, 0);
20586 +       atomic_set(&new->nx_tasks, 0);
20587 +       new->nx_state = 0;
20588 +
20589 +       new->nx_flags = NXF_INIT_SET;
20590 +
20591 +       /* rest of init goes here */
20592 +
20593 +       new->v4_lback.s_addr = htonl(INADDR_LOOPBACK);
20594 +       new->v4_bcast.s_addr = htonl(INADDR_BROADCAST);
20595 +
20596 +       vxdprintk(VXD_CBIT(nid, 0),
20597 +               "alloc_nx_info(%d) = %p", nid, new);
20598 +       atomic_inc(&nx_global_ctotal);
20599 +       return new;
20600 +}
20601 +
20602 +/*     __dealloc_nx_info()
20603 +
20604 +       * final disposal of nx_info                             */
20605 +
20606 +static void __dealloc_nx_info(struct nx_info *nxi)
20607 +{
20608 +       vxdprintk(VXD_CBIT(nid, 0),
20609 +               "dealloc_nx_info(%p)", nxi);
20610 +
20611 +       nxi->nx_hlist.next = LIST_POISON1;
20612 +       nxi->nx_id = -1;
20613 +
20614 +       BUG_ON(atomic_read(&nxi->nx_usecnt));
20615 +       BUG_ON(atomic_read(&nxi->nx_tasks));
20616 +
20617 +       __dealloc_nx_addr_v4_all(nxi->v4.next);
20618 +
20619 +       nxi->nx_state |= NXS_RELEASED;
20620 +       kfree(nxi);
20621 +       atomic_dec(&nx_global_ctotal);
20622 +}
20623 +
20624 +static void __shutdown_nx_info(struct nx_info *nxi)
20625 +{
20626 +       nxi->nx_state |= NXS_SHUTDOWN;
20627 +       vs_net_change(nxi, VSC_NETDOWN);
20628 +}
20629 +
20630 +/*     exported stuff                                          */
20631 +
20632 +void free_nx_info(struct nx_info *nxi)
20633 +{
20634 +       /* context shutdown is mandatory */
20635 +       BUG_ON(nxi->nx_state != NXS_SHUTDOWN);
20636 +
20637 +       /* context must not be hashed */
20638 +       BUG_ON(nxi->nx_state & NXS_HASHED);
20639 +
20640 +       BUG_ON(atomic_read(&nxi->nx_usecnt));
20641 +       BUG_ON(atomic_read(&nxi->nx_tasks));
20642 +
20643 +       __dealloc_nx_info(nxi);
20644 +}
20645 +
20646 +
20647 +void __nx_set_lback(struct nx_info *nxi)
20648 +{
20649 +       int nid = nxi->nx_id;
20650 +       __be32 lback = htonl(INADDR_LOOPBACK ^ ((nid & 0xFFFF) << 8));
20651 +
20652 +       nxi->v4_lback.s_addr = lback;
20653 +}
20654 +
20655 +extern int __nx_inet_add_lback(__be32 addr);
20656 +extern int __nx_inet_del_lback(__be32 addr);
20657 +
20658 +
20659 +/*     hash table for nx_info hash */
20660 +
20661 +#define NX_HASH_SIZE   13
20662 +
20663 +struct hlist_head nx_info_hash[NX_HASH_SIZE];
20664 +
20665 +static DEFINE_SPINLOCK(nx_info_hash_lock);
20666 +
20667 +
20668 +static inline unsigned int __hashval(nid_t nid)
20669 +{
20670 +       return (nid % NX_HASH_SIZE);
20671 +}
20672 +
20673 +
20674 +
20675 +/*     __hash_nx_info()
20676 +
20677 +       * add the nxi to the global hash table
20678 +       * requires the hash_lock to be held                     */
20679 +
20680 +static inline void __hash_nx_info(struct nx_info *nxi)
20681 +{
20682 +       struct hlist_head *head;
20683 +
20684 +       vxd_assert_lock(&nx_info_hash_lock);
20685 +       vxdprintk(VXD_CBIT(nid, 4),
20686 +               "__hash_nx_info: %p[#%d]", nxi, nxi->nx_id);
20687 +
20688 +       /* context must not be hashed */
20689 +       BUG_ON(nx_info_state(nxi, NXS_HASHED));
20690 +
20691 +       nxi->nx_state |= NXS_HASHED;
20692 +       head = &nx_info_hash[__hashval(nxi->nx_id)];
20693 +       hlist_add_head(&nxi->nx_hlist, head);
20694 +       atomic_inc(&nx_global_cactive);
20695 +}
20696 +
20697 +/*     __unhash_nx_info()
20698 +
20699 +       * remove the nxi from the global hash table
20700 +       * requires the hash_lock to be held                     */
20701 +
20702 +static inline void __unhash_nx_info(struct nx_info *nxi)
20703 +{
20704 +       vxd_assert_lock(&nx_info_hash_lock);
20705 +       vxdprintk(VXD_CBIT(nid, 4),
20706 +               "__unhash_nx_info: %p[#%d.%d.%d]", nxi, nxi->nx_id,
20707 +               atomic_read(&nxi->nx_usecnt), atomic_read(&nxi->nx_tasks));
20708 +
20709 +       /* context must be hashed */
20710 +       BUG_ON(!nx_info_state(nxi, NXS_HASHED));
20711 +       /* but without tasks */
20712 +       BUG_ON(atomic_read(&nxi->nx_tasks));
20713 +
20714 +       nxi->nx_state &= ~NXS_HASHED;
20715 +       hlist_del(&nxi->nx_hlist);
20716 +       atomic_dec(&nx_global_cactive);
20717 +}
20718 +
20719 +
20720 +/*     __lookup_nx_info()
20721 +
20722 +       * requires the hash_lock to be held
20723 +       * doesn't increment the nx_refcnt                       */
20724 +
20725 +static inline struct nx_info *__lookup_nx_info(nid_t nid)
20726 +{
20727 +       struct hlist_head *head = &nx_info_hash[__hashval(nid)];
20728 +       struct hlist_node *pos;
20729 +       struct nx_info *nxi;
20730 +
20731 +       vxd_assert_lock(&nx_info_hash_lock);
20732 +       hlist_for_each(pos, head) {
20733 +               nxi = hlist_entry(pos, struct nx_info, nx_hlist);
20734 +
20735 +               if (nxi->nx_id == nid)
20736 +                       goto found;
20737 +       }
20738 +       nxi = NULL;
20739 +found:
20740 +       vxdprintk(VXD_CBIT(nid, 0),
20741 +               "__lookup_nx_info(#%u): %p[#%u]",
20742 +               nid, nxi, nxi ? nxi->nx_id : 0);
20743 +       return nxi;
20744 +}
20745 +
20746 +
20747 +/*     __create_nx_info()
20748 +
20749 +       * create the requested context
20750 +       * get(), claim() and hash it                            */
20751 +
20752 +static struct nx_info *__create_nx_info(int id)
20753 +{
20754 +       struct nx_info *new, *nxi = NULL;
20755 +
20756 +       vxdprintk(VXD_CBIT(nid, 1), "create_nx_info(%d)*", id);
20757 +
20758 +       if (!(new = __alloc_nx_info(id)))
20759 +               return ERR_PTR(-ENOMEM);
20760 +
20761 +       /* required to make dynamic xids unique */
20762 +       spin_lock(&nx_info_hash_lock);
20763 +
20764 +       /* static context requested */
20765 +       if ((nxi = __lookup_nx_info(id))) {
20766 +               vxdprintk(VXD_CBIT(nid, 0),
20767 +                       "create_nx_info(%d) = %p (already there)", id, nxi);
20768 +               if (nx_info_flags(nxi, NXF_STATE_SETUP, 0))
20769 +                       nxi = ERR_PTR(-EBUSY);
20770 +               else
20771 +                       nxi = ERR_PTR(-EEXIST);
20772 +               goto out_unlock;
20773 +       }
20774 +       /* new context */
20775 +       vxdprintk(VXD_CBIT(nid, 0),
20776 +               "create_nx_info(%d) = %p (new)", id, new);
20777 +       claim_nx_info(new, NULL);
20778 +       __nx_set_lback(new);
20779 +       __hash_nx_info(get_nx_info(new));
20780 +       nxi = new, new = NULL;
20781 +
20782 +out_unlock:
20783 +       spin_unlock(&nx_info_hash_lock);
20784 +       if (new)
20785 +               __dealloc_nx_info(new);
20786 +       return nxi;
20787 +}
20788 +
20789 +
20790 +
20791 +/*     exported stuff                                          */
20792 +
20793 +
20794 +void unhash_nx_info(struct nx_info *nxi)
20795 +{
20796 +       __shutdown_nx_info(nxi);
20797 +       spin_lock(&nx_info_hash_lock);
20798 +       __unhash_nx_info(nxi);
20799 +       spin_unlock(&nx_info_hash_lock);
20800 +}
20801 +
20802 +/*     lookup_nx_info()
20803 +
20804 +       * search for a nx_info and get() it
20805 +       * negative id means current                             */
20806 +
20807 +struct nx_info *lookup_nx_info(int id)
20808 +{
20809 +       struct nx_info *nxi = NULL;
20810 +
20811 +       if (id < 0) {
20812 +               nxi = get_nx_info(current_nx_info());
20813 +       } else if (id > 1) {
20814 +               spin_lock(&nx_info_hash_lock);
20815 +               nxi = get_nx_info(__lookup_nx_info(id));
20816 +               spin_unlock(&nx_info_hash_lock);
20817 +       }
20818 +       return nxi;
20819 +}
20820 +
20821 +/*     nid_is_hashed()
20822 +
20823 +       * verify that nid is still hashed                       */
20824 +
20825 +int nid_is_hashed(nid_t nid)
20826 +{
20827 +       int hashed;
20828 +
20829 +       spin_lock(&nx_info_hash_lock);
20830 +       hashed = (__lookup_nx_info(nid) != NULL);
20831 +       spin_unlock(&nx_info_hash_lock);
20832 +       return hashed;
20833 +}
20834 +
20835 +
20836 +#ifdef CONFIG_PROC_FS
20837 +
20838 +/*     get_nid_list()
20839 +
20840 +       * get a subset of hashed nids for proc
20841 +       * assumes size is at least one                          */
20842 +
20843 +int get_nid_list(int index, unsigned int *nids, int size)
20844 +{
20845 +       int hindex, nr_nids = 0;
20846 +
20847 +       /* only show current and children */
20848 +       if (!nx_check(0, VS_ADMIN | VS_WATCH)) {
20849 +               if (index > 0)
20850 +                       return 0;
20851 +               nids[nr_nids] = nx_current_nid();
20852 +               return 1;
20853 +       }
20854 +
20855 +       for (hindex = 0; hindex < NX_HASH_SIZE; hindex++) {
20856 +               struct hlist_head *head = &nx_info_hash[hindex];
20857 +               struct hlist_node *pos;
20858 +
20859 +               spin_lock(&nx_info_hash_lock);
20860 +               hlist_for_each(pos, head) {
20861 +                       struct nx_info *nxi;
20862 +
20863 +                       if (--index > 0)
20864 +                               continue;
20865 +
20866 +                       nxi = hlist_entry(pos, struct nx_info, nx_hlist);
20867 +                       nids[nr_nids] = nxi->nx_id;
20868 +                       if (++nr_nids >= size) {
20869 +                               spin_unlock(&nx_info_hash_lock);
20870 +                               goto out;
20871 +                       }
20872 +               }
20873 +               /* keep the lock time short */
20874 +               spin_unlock(&nx_info_hash_lock);
20875 +       }
20876 +out:
20877 +       return nr_nids;
20878 +}
20879 +#endif
20880 +
20881 +
20882 +/*
20883 + *     migrate task to new network
20884 + *     gets nxi, puts old_nxi on change
20885 + */
20886 +
20887 +int nx_migrate_task(struct task_struct *p, struct nx_info *nxi)
20888 +{
20889 +       struct nx_info *old_nxi;
20890 +       int ret = 0;
20891 +
20892 +       if (!p || !nxi)
20893 +               BUG();
20894 +
20895 +       vxdprintk(VXD_CBIT(nid, 5),
20896 +               "nx_migrate_task(%p,%p[#%d.%d.%d])",
20897 +               p, nxi, nxi->nx_id,
20898 +               atomic_read(&nxi->nx_usecnt),
20899 +               atomic_read(&nxi->nx_tasks));
20900 +
20901 +       if (nx_info_flags(nxi, NXF_INFO_PRIVATE, 0) &&
20902 +               !nx_info_flags(nxi, NXF_STATE_SETUP, 0))
20903 +               return -EACCES;
20904 +
20905 +       if (nx_info_state(nxi, NXS_SHUTDOWN))
20906 +               return -EFAULT;
20907 +
20908 +       /* maybe disallow this completely? */
20909 +       old_nxi = task_get_nx_info(p);
20910 +       if (old_nxi == nxi)
20911 +               goto out;
20912 +
20913 +       task_lock(p);
20914 +       if (old_nxi)
20915 +               clr_nx_info(&p->nx_info);
20916 +       claim_nx_info(nxi, p);
20917 +       set_nx_info(&p->nx_info, nxi);
20918 +       p->nid = nxi->nx_id;
20919 +       task_unlock(p);
20920 +
20921 +       vxdprintk(VXD_CBIT(nid, 5),
20922 +               "moved task %p into nxi:%p[#%d]",
20923 +               p, nxi, nxi->nx_id);
20924 +
20925 +       if (old_nxi)
20926 +               release_nx_info(old_nxi, p);
20927 +       ret = 0;
20928 +out:
20929 +       put_nx_info(old_nxi);
20930 +       return ret;
20931 +}
20932 +
20933 +
20934 +void nx_set_persistent(struct nx_info *nxi)
20935 +{
20936 +       vxdprintk(VXD_CBIT(nid, 6),
20937 +               "nx_set_persistent(%p[#%d])", nxi, nxi->nx_id);
20938 +
20939 +       get_nx_info(nxi);
20940 +       claim_nx_info(nxi, NULL);
20941 +}
20942 +
20943 +void nx_clear_persistent(struct nx_info *nxi)
20944 +{
20945 +       vxdprintk(VXD_CBIT(nid, 6),
20946 +               "nx_clear_persistent(%p[#%d])", nxi, nxi->nx_id);
20947 +
20948 +       release_nx_info(nxi, NULL);
20949 +       put_nx_info(nxi);
20950 +}
20951 +
20952 +void nx_update_persistent(struct nx_info *nxi)
20953 +{
20954 +       if (nx_info_flags(nxi, NXF_PERSISTENT, 0))
20955 +               nx_set_persistent(nxi);
20956 +       else
20957 +               nx_clear_persistent(nxi);
20958 +}
20959 +
20960 +/* vserver syscall commands below here */
20961 +
20962 +/* taks nid and nx_info functions */
20963 +
20964 +#include <asm/uaccess.h>
20965 +
20966 +
20967 +int vc_task_nid(uint32_t id)
20968 +{
20969 +       nid_t nid;
20970 +
20971 +       if (id) {
20972 +               struct task_struct *tsk;
20973 +
20974 +               rcu_read_lock();
20975 +               tsk = find_task_by_real_pid(id);
20976 +               nid = (tsk) ? tsk->nid : -ESRCH;
20977 +               rcu_read_unlock();
20978 +       } else
20979 +               nid = nx_current_nid();
20980 +       return nid;
20981 +}
20982 +
20983 +
20984 +int vc_nx_info(struct nx_info *nxi, void __user *data)
20985 +{
20986 +       struct vcmd_nx_info_v0 vc_data;
20987 +
20988 +       vc_data.nid = nxi->nx_id;
20989 +
20990 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20991 +               return -EFAULT;
20992 +       return 0;
20993 +}
20994 +
20995 +
20996 +/* network functions */
20997 +
20998 +int vc_net_create(uint32_t nid, void __user *data)
20999 +{
21000 +       struct vcmd_net_create vc_data = { .flagword = NXF_INIT_SET };
21001 +       struct nx_info *new_nxi;
21002 +       int ret;
21003 +
21004 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
21005 +               return -EFAULT;
21006 +
21007 +       if ((nid > MAX_S_CONTEXT) || (nid < 2))
21008 +               return -EINVAL;
21009 +
21010 +       new_nxi = __create_nx_info(nid);
21011 +       if (IS_ERR(new_nxi))
21012 +               return PTR_ERR(new_nxi);
21013 +
21014 +       /* initial flags */
21015 +       new_nxi->nx_flags = vc_data.flagword;
21016 +
21017 +       ret = -ENOEXEC;
21018 +       if (vs_net_change(new_nxi, VSC_NETUP))
21019 +               goto out;
21020 +
21021 +       ret = nx_migrate_task(current, new_nxi);
21022 +       if (ret)
21023 +               goto out;
21024 +
21025 +       /* return context id on success */
21026 +       ret = new_nxi->nx_id;
21027 +
21028 +       /* get a reference for persistent contexts */
21029 +       if ((vc_data.flagword & NXF_PERSISTENT))
21030 +               nx_set_persistent(new_nxi);
21031 +out:
21032 +       release_nx_info(new_nxi, NULL);
21033 +       put_nx_info(new_nxi);
21034 +       return ret;
21035 +}
21036 +
21037 +
21038 +int vc_net_migrate(struct nx_info *nxi, void __user *data)
21039 +{
21040 +       return nx_migrate_task(current, nxi);
21041 +}
21042 +
21043 +
21044 +
21045 +int do_add_v4_addr(struct nx_info *nxi, __be32 ip, __be32 ip2, __be32 mask,
21046 +       uint16_t type, uint16_t flags)
21047 +{
21048 +       struct nx_addr_v4 *nxa = &nxi->v4;
21049 +
21050 +       if (NX_IPV4(nxi)) {
21051 +               /* locate last entry */
21052 +               for (; nxa->next; nxa = nxa->next);
21053 +               nxa->next = __alloc_nx_addr_v4();
21054 +               nxa = nxa->next;
21055 +
21056 +               if (IS_ERR(nxa))
21057 +                       return PTR_ERR(nxa);
21058 +       }
21059 +
21060 +       if (nxi->v4.next)
21061 +               /* remove single ip for ip list */
21062 +               nxi->nx_flags &= ~NXF_SINGLE_IP;
21063 +
21064 +       nxa->ip[0].s_addr = ip;
21065 +       nxa->ip[1].s_addr = ip2;
21066 +       nxa->mask.s_addr = mask;
21067 +       nxa->type = type;
21068 +       nxa->flags = flags;
21069 +       return 0;
21070 +}
21071 +
21072 +int do_remove_v4_addr(struct nx_info *nxi, __be32 ip, __be32 ip2, __be32 mask,
21073 +       uint16_t type, uint16_t flags)
21074 +{
21075 +       struct nx_addr_v4 *nxa = &nxi->v4;
21076 +
21077 +       switch (type) {
21078 +/*     case NXA_TYPE_ADDR:
21079 +               break;          */
21080 +
21081 +       case NXA_TYPE_ANY:
21082 +               __dealloc_nx_addr_v4_all(xchg(&nxa->next, NULL));
21083 +               memset(nxa, 0, sizeof(*nxa));
21084 +               break;
21085 +
21086 +       default:
21087 +               return -EINVAL;
21088 +       }
21089 +       return 0;
21090 +}
21091 +
21092 +
21093 +int vc_net_add(struct nx_info *nxi, void __user *data)
21094 +{
21095 +       struct vcmd_net_addr_v0 vc_data;
21096 +       int index, ret = 0;
21097 +
21098 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
21099 +               return -EFAULT;
21100 +
21101 +       switch (vc_data.type) {
21102 +       case NXA_TYPE_IPV4:
21103 +               if ((vc_data.count < 1) || (vc_data.count > 4))
21104 +                       return -EINVAL;
21105 +
21106 +               index = 0;
21107 +               while (index < vc_data.count) {
21108 +                       ret = do_add_v4_addr(nxi, vc_data.ip[index].s_addr, 0,
21109 +                               vc_data.mask[index].s_addr, NXA_TYPE_ADDR, 0);
21110 +                       if (ret)
21111 +                               return ret;
21112 +                       index++;
21113 +               }
21114 +               ret = index;
21115 +               break;
21116 +
21117 +       case NXA_TYPE_IPV4|NXA_MOD_BCAST:
21118 +               nxi->v4_bcast = vc_data.ip[0];
21119 +               ret = 1;
21120 +               break;
21121 +
21122 +       case NXA_TYPE_IPV4|NXA_MOD_LBACK:
21123 +               nxi->v4_lback = vc_data.ip[0];
21124 +               ret = 1;
21125 +               break;
21126 +
21127 +       default:
21128 +               ret = -EINVAL;
21129 +               break;
21130 +       }
21131 +       return ret;
21132 +}
21133 +
21134 +int vc_net_remove(struct nx_info *nxi, void __user *data)
21135 +{
21136 +       struct vcmd_net_addr_v0 vc_data;
21137 +
21138 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
21139 +               return -EFAULT;
21140 +
21141 +       switch (vc_data.type) {
21142 +       case NXA_TYPE_ANY:
21143 +               __dealloc_nx_addr_v4_all(xchg(&nxi->v4.next, NULL));
21144 +               memset(&nxi->v4, 0, sizeof(nxi->v4));
21145 +               break;
21146 +
21147 +       default:
21148 +               return -EINVAL;
21149 +       }
21150 +       return 0;
21151 +}
21152 +
21153 +
21154 +int vc_net_add_ipv4_v1(struct nx_info *nxi, void __user *data)
21155 +{
21156 +       struct vcmd_net_addr_ipv4_v1 vc_data;
21157 +
21158 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
21159 +               return -EFAULT;
21160 +
21161 +       switch (vc_data.type) {
21162 +       case NXA_TYPE_ADDR:
21163 +       case NXA_TYPE_MASK:
21164 +               return do_add_v4_addr(nxi, vc_data.ip.s_addr, 0,
21165 +                       vc_data.mask.s_addr, vc_data.type, vc_data.flags);
21166 +
21167 +       case NXA_TYPE_ADDR | NXA_MOD_BCAST:
21168 +               nxi->v4_bcast = vc_data.ip;
21169 +               break;
21170 +
21171 +       case NXA_TYPE_ADDR | NXA_MOD_LBACK:
21172 +               nxi->v4_lback = vc_data.ip;
21173 +               break;
21174 +
21175 +       default:
21176 +               return -EINVAL;
21177 +       }
21178 +       return 0;
21179 +}
21180 +
21181 +int vc_net_add_ipv4(struct nx_info *nxi, void __user *data)
21182 +{
21183 +       struct vcmd_net_addr_ipv4_v2 vc_data;
21184 +
21185 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
21186 +               return -EFAULT;
21187 +
21188 +       switch (vc_data.type) {
21189 +       case NXA_TYPE_ADDR:
21190 +       case NXA_TYPE_MASK:
21191 +       case NXA_TYPE_RANGE:
21192 +               return do_add_v4_addr(nxi, vc_data.ip.s_addr, vc_data.ip2.s_addr,
21193 +                       vc_data.mask.s_addr, vc_data.type, vc_data.flags);
21194 +
21195 +       case NXA_TYPE_ADDR | NXA_MOD_BCAST:
21196 +               nxi->v4_bcast = vc_data.ip;
21197 +               break;
21198 +
21199 +       case NXA_TYPE_ADDR | NXA_MOD_LBACK:
21200 +               nxi->v4_lback = vc_data.ip;
21201 +               break;
21202 +
21203 +       default:
21204 +               return -EINVAL;
21205 +       }
21206 +       return 0;
21207 +}
21208 +
21209 +int vc_net_rem_ipv4_v1(struct nx_info *nxi, void __user *data)
21210 +{
21211 +       struct vcmd_net_addr_ipv4_v1 vc_data;
21212 +
21213 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
21214 +               return -EFAULT;
21215 +
21216 +       return do_remove_v4_addr(nxi, vc_data.ip.s_addr, 0,
21217 +               vc_data.mask.s_addr, vc_data.type, vc_data.flags);
21218 +}
21219 +
21220 +int vc_net_rem_ipv4(struct nx_info *nxi, void __user *data)
21221 +{
21222 +       struct vcmd_net_addr_ipv4_v2 vc_data;
21223 +
21224 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
21225 +               return -EFAULT;
21226 +
21227 +       return do_remove_v4_addr(nxi, vc_data.ip.s_addr, vc_data.ip2.s_addr,
21228 +               vc_data.mask.s_addr, vc_data.type, vc_data.flags);
21229 +}
21230 +
21231 +#ifdef CONFIG_IPV6
21232 +
21233 +int do_add_v6_addr(struct nx_info *nxi,
21234 +       struct in6_addr *ip, struct in6_addr *mask,
21235 +       uint32_t prefix, uint16_t type, uint16_t flags)
21236 +{
21237 +       struct nx_addr_v6 *nxa = &nxi->v6;
21238 +
21239 +       if (NX_IPV6(nxi)) {
21240 +               /* locate last entry */
21241 +               for (; nxa->next; nxa = nxa->next);
21242 +               nxa->next = __alloc_nx_addr_v6();
21243 +               nxa = nxa->next;
21244 +
21245 +               if (IS_ERR(nxa))
21246 +                       return PTR_ERR(nxa);
21247 +       }
21248 +
21249 +       nxa->ip = *ip;
21250 +       nxa->mask = *mask;
21251 +       nxa->prefix = prefix;
21252 +       nxa->type = type;
21253 +       nxa->flags = flags;
21254 +       return 0;
21255 +}
21256 +
21257 +
21258 +int vc_net_add_ipv6(struct nx_info *nxi, void __user *data)
21259 +{
21260 +       struct vcmd_net_addr_ipv6_v1 vc_data;
21261 +
21262 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
21263 +               return -EFAULT;
21264 +
21265 +       switch (vc_data.type) {
21266 +       case NXA_TYPE_ADDR:
21267 +               memset(&vc_data.mask, ~0, sizeof(vc_data.mask));
21268 +               /* fallthrough */
21269 +       case NXA_TYPE_MASK:
21270 +               return do_add_v6_addr(nxi, &vc_data.ip, &vc_data.mask,
21271 +                       vc_data.prefix, vc_data.type, vc_data.flags);
21272 +       default:
21273 +               return -EINVAL;
21274 +       }
21275 +       return 0;
21276 +}
21277 +
21278 +int vc_net_remove_ipv6(struct nx_info *nxi, void __user *data)
21279 +{
21280 +       struct vcmd_net_addr_ipv6_v1 vc_data;
21281 +
21282 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
21283 +               return -EFAULT;
21284 +
21285 +       switch (vc_data.type) {
21286 +       case NXA_TYPE_ANY:
21287 +               __dealloc_nx_addr_v6_all(xchg(&nxi->v6.next, NULL));
21288 +               memset(&nxi->v6, 0, sizeof(nxi->v6));
21289 +               break;
21290 +
21291 +       default:
21292 +               return -EINVAL;
21293 +       }
21294 +       return 0;
21295 +}
21296 +
21297 +#endif /* CONFIG_IPV6 */
21298 +
21299 +
21300 +int vc_get_nflags(struct nx_info *nxi, void __user *data)
21301 +{
21302 +       struct vcmd_net_flags_v0 vc_data;
21303 +
21304 +       vc_data.flagword = nxi->nx_flags;
21305 +
21306 +       /* special STATE flag handling */
21307 +       vc_data.mask = vs_mask_flags(~0ULL, nxi->nx_flags, NXF_ONE_TIME);
21308 +
21309 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21310 +               return -EFAULT;
21311 +       return 0;
21312 +}
21313 +
21314 +int vc_set_nflags(struct nx_info *nxi, void __user *data)
21315 +{
21316 +       struct vcmd_net_flags_v0 vc_data;
21317 +       uint64_t mask, trigger;
21318 +
21319 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21320 +               return -EFAULT;
21321 +
21322 +       /* special STATE flag handling */
21323 +       mask = vs_mask_mask(vc_data.mask, nxi->nx_flags, NXF_ONE_TIME);
21324 +       trigger = (mask & nxi->nx_flags) ^ (mask & vc_data.flagword);
21325 +
21326 +       nxi->nx_flags = vs_mask_flags(nxi->nx_flags,
21327 +               vc_data.flagword, mask);
21328 +       if (trigger & NXF_PERSISTENT)
21329 +               nx_update_persistent(nxi);
21330 +
21331 +       return 0;
21332 +}
21333 +
21334 +int vc_get_ncaps(struct nx_info *nxi, void __user *data)
21335 +{
21336 +       struct vcmd_net_caps_v0 vc_data;
21337 +
21338 +       vc_data.ncaps = nxi->nx_ncaps;
21339 +       vc_data.cmask = ~0ULL;
21340 +
21341 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21342 +               return -EFAULT;
21343 +       return 0;
21344 +}
21345 +
21346 +int vc_set_ncaps(struct nx_info *nxi, void __user *data)
21347 +{
21348 +       struct vcmd_net_caps_v0 vc_data;
21349 +
21350 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21351 +               return -EFAULT;
21352 +
21353 +       nxi->nx_ncaps = vs_mask_flags(nxi->nx_ncaps,
21354 +               vc_data.ncaps, vc_data.cmask);
21355 +       return 0;
21356 +}
21357 +
21358 +
21359 +#include <linux/module.h>
21360 +
21361 +module_init(init_network);
21362 +
21363 +EXPORT_SYMBOL_GPL(free_nx_info);
21364 +EXPORT_SYMBOL_GPL(unhash_nx_info);
21365 +
21366 diff -NurpP --minimal linux-3.0.25/kernel/vserver/proc.c linux-3.0.25-vs2.3.2.3/kernel/vserver/proc.c
21367 --- linux-3.0.25/kernel/vserver/proc.c  1970-01-01 01:00:00.000000000 +0100
21368 +++ linux-3.0.25-vs2.3.2.3/kernel/vserver/proc.c        2011-08-01 19:57:21.000000000 +0200
21369 @@ -0,0 +1,1103 @@
21370 +/*
21371 + *  linux/kernel/vserver/proc.c
21372 + *
21373 + *  Virtual Context Support
21374 + *
21375 + *  Copyright (C) 2003-2011  Herbert Pötzl
21376 + *
21377 + *  V0.01  basic structure
21378 + *  V0.02  adaptation vs1.3.0
21379 + *  V0.03  proc permissions
21380 + *  V0.04  locking/generic
21381 + *  V0.05  next generation procfs
21382 + *  V0.06  inode validation
21383 + *  V0.07  generic rewrite vid
21384 + *  V0.08  remove inode type
21385 + *  V0.09  added u/wmask info
21386 + *
21387 + */
21388 +
21389 +#include <linux/proc_fs.h>
21390 +#include <linux/fs_struct.h>
21391 +#include <linux/mount.h>
21392 +#include <asm/unistd.h>
21393 +
21394 +#include <linux/vs_context.h>
21395 +#include <linux/vs_network.h>
21396 +#include <linux/vs_cvirt.h>
21397 +
21398 +#include <linux/in.h>
21399 +#include <linux/inetdevice.h>
21400 +#include <linux/vs_inet.h>
21401 +#include <linux/vs_inet6.h>
21402 +
21403 +#include <linux/vserver/global.h>
21404 +
21405 +#include "cvirt_proc.h"
21406 +#include "cacct_proc.h"
21407 +#include "limit_proc.h"
21408 +#include "sched_proc.h"
21409 +#include "vci_config.h"
21410 +
21411 +
21412 +static inline char *print_cap_t(char *buffer, kernel_cap_t *c)
21413 +{
21414 +       unsigned __capi;
21415 +
21416 +       CAP_FOR_EACH_U32(__capi) {
21417 +               buffer += sprintf(buffer, "%08x",
21418 +                       c->cap[(_KERNEL_CAPABILITY_U32S-1) - __capi]);
21419 +       }
21420 +       return buffer;
21421 +}
21422 +
21423 +
21424 +static struct proc_dir_entry *proc_virtual;
21425 +
21426 +static struct proc_dir_entry *proc_virtnet;
21427 +
21428 +
21429 +/* first the actual feeds */
21430 +
21431 +
21432 +static int proc_vci(char *buffer)
21433 +{
21434 +       return sprintf(buffer,
21435 +               "VCIVersion:\t%04x:%04x\n"
21436 +               "VCISyscall:\t%d\n"
21437 +               "VCIKernel:\t%08x\n",
21438 +               VCI_VERSION >> 16,
21439 +               VCI_VERSION & 0xFFFF,
21440 +               __NR_vserver,
21441 +               vci_kernel_config());
21442 +}
21443 +
21444 +static int proc_virtual_info(char *buffer)
21445 +{
21446 +       return proc_vci(buffer);
21447 +}
21448 +
21449 +static int proc_virtual_status(char *buffer)
21450 +{
21451 +       return sprintf(buffer,
21452 +               "#CTotal:\t%d\n"
21453 +               "#CActive:\t%d\n"
21454 +               "#NSProxy:\t%d\t%d %d %d %d %d %d\n"
21455 +               "#InitTask:\t%d\t%d %d\n",
21456 +               atomic_read(&vx_global_ctotal),
21457 +               atomic_read(&vx_global_cactive),
21458 +               atomic_read(&vs_global_nsproxy),
21459 +               atomic_read(&vs_global_fs),
21460 +               atomic_read(&vs_global_mnt_ns),
21461 +               atomic_read(&vs_global_uts_ns),
21462 +               atomic_read(&nr_ipc_ns),
21463 +               atomic_read(&vs_global_user_ns),
21464 +               atomic_read(&vs_global_pid_ns),
21465 +               atomic_read(&init_task.usage),
21466 +               atomic_read(&init_task.nsproxy->count),
21467 +               init_task.fs->users);
21468 +}
21469 +
21470 +
21471 +int proc_vxi_info(struct vx_info *vxi, char *buffer)
21472 +{
21473 +       int length;
21474 +
21475 +       length = sprintf(buffer,
21476 +               "ID:\t%d\n"
21477 +               "Info:\t%p\n"
21478 +               "Init:\t%d\n"
21479 +               "OOM:\t%lld\n",
21480 +               vxi->vx_id,
21481 +               vxi,
21482 +               vxi->vx_initpid,
21483 +               vxi->vx_badness_bias);
21484 +       return length;
21485 +}
21486 +
21487 +int proc_vxi_status(struct vx_info *vxi, char *buffer)
21488 +{
21489 +       char *orig = buffer;
21490 +
21491 +       buffer += sprintf(buffer,
21492 +               "UseCnt:\t%d\n"
21493 +               "Tasks:\t%d\n"
21494 +               "Flags:\t%016llx\n",
21495 +               atomic_read(&vxi->vx_usecnt),
21496 +               atomic_read(&vxi->vx_tasks),
21497 +               (unsigned long long)vxi->vx_flags);
21498 +
21499 +       buffer += sprintf(buffer, "BCaps:\t");
21500 +       buffer = print_cap_t(buffer, &vxi->vx_bcaps);
21501 +       buffer += sprintf(buffer, "\n");
21502 +
21503 +       buffer += sprintf(buffer,
21504 +               "CCaps:\t%016llx\n"
21505 +               "Umask:\t%16llx\n"
21506 +               "Wmask:\t%16llx\n"
21507 +               "Spaces:\t%08lx %08lx\n",
21508 +               (unsigned long long)vxi->vx_ccaps,
21509 +               (unsigned long long)vxi->vx_umask,
21510 +               (unsigned long long)vxi->vx_wmask,
21511 +               vxi->space[0].vx_nsmask, vxi->space[1].vx_nsmask);
21512 +       return buffer - orig;
21513 +}
21514 +
21515 +int proc_vxi_limit(struct vx_info *vxi, char *buffer)
21516 +{
21517 +       return vx_info_proc_limit(&vxi->limit, buffer);
21518 +}
21519 +
21520 +int proc_vxi_sched(struct vx_info *vxi, char *buffer)
21521 +{
21522 +       int cpu, length;
21523 +
21524 +       length = vx_info_proc_sched(&vxi->sched, buffer);
21525 +       for_each_online_cpu(cpu) {
21526 +               length += vx_info_proc_sched_pc(
21527 +                       &vx_per_cpu(vxi, sched_pc, cpu),
21528 +                       buffer + length, cpu);
21529 +       }
21530 +       return length;
21531 +}
21532 +
21533 +int proc_vxi_nsproxy0(struct vx_info *vxi, char *buffer)
21534 +{
21535 +       return vx_info_proc_nsproxy(vxi->space[0].vx_nsproxy, buffer);
21536 +}
21537 +
21538 +int proc_vxi_nsproxy1(struct vx_info *vxi, char *buffer)
21539 +{
21540 +       return vx_info_proc_nsproxy(vxi->space[1].vx_nsproxy, buffer);
21541 +}
21542 +
21543 +int proc_vxi_cvirt(struct vx_info *vxi, char *buffer)
21544 +{
21545 +       int cpu, length;
21546 +
21547 +       vx_update_load(vxi);
21548 +       length = vx_info_proc_cvirt(&vxi->cvirt, buffer);
21549 +       for_each_online_cpu(cpu) {
21550 +               length += vx_info_proc_cvirt_pc(
21551 +                       &vx_per_cpu(vxi, cvirt_pc, cpu),
21552 +                       buffer + length, cpu);
21553 +       }
21554 +       return length;
21555 +}
21556 +
21557 +int proc_vxi_cacct(struct vx_info *vxi, char *buffer)
21558 +{
21559 +       return vx_info_proc_cacct(&vxi->cacct, buffer);
21560 +}
21561 +
21562 +
21563 +static int proc_virtnet_info(char *buffer)
21564 +{
21565 +       return proc_vci(buffer);
21566 +}
21567 +
21568 +static int proc_virtnet_status(char *buffer)
21569 +{
21570 +       return sprintf(buffer,
21571 +               "#CTotal:\t%d\n"
21572 +               "#CActive:\t%d\n",
21573 +               atomic_read(&nx_global_ctotal),
21574 +               atomic_read(&nx_global_cactive));
21575 +}
21576 +
21577 +int proc_nxi_info(struct nx_info *nxi, char *buffer)
21578 +{
21579 +       struct nx_addr_v4 *v4a;
21580 +#ifdef CONFIG_IPV6
21581 +       struct nx_addr_v6 *v6a;
21582 +#endif
21583 +       int length, i;
21584 +
21585 +       length = sprintf(buffer,
21586 +               "ID:\t%d\n"
21587 +               "Info:\t%p\n"
21588 +               "Bcast:\t" NIPQUAD_FMT "\n"
21589 +               "Lback:\t" NIPQUAD_FMT "\n",
21590 +               nxi->nx_id,
21591 +               nxi,
21592 +               NIPQUAD(nxi->v4_bcast.s_addr),
21593 +               NIPQUAD(nxi->v4_lback.s_addr));
21594 +
21595 +       if (!NX_IPV4(nxi))
21596 +               goto skip_v4;
21597 +       for (i = 0, v4a = &nxi->v4; v4a; i++, v4a = v4a->next)
21598 +               length += sprintf(buffer + length, "%d:\t" NXAV4_FMT "\n",
21599 +                       i, NXAV4(v4a));
21600 +skip_v4:
21601 +#ifdef CONFIG_IPV6
21602 +       if (!NX_IPV6(nxi))
21603 +               goto skip_v6;
21604 +       for (i = 0, v6a = &nxi->v6; v6a; i++, v6a = v6a->next)
21605 +               length += sprintf(buffer + length, "%d:\t" NXAV6_FMT "\n",
21606 +                       i, NXAV6(v6a));
21607 +skip_v6:
21608 +#endif
21609 +       return length;
21610 +}
21611 +
21612 +int proc_nxi_status(struct nx_info *nxi, char *buffer)
21613 +{
21614 +       int length;
21615 +
21616 +       length = sprintf(buffer,
21617 +               "UseCnt:\t%d\n"
21618 +               "Tasks:\t%d\n"
21619 +               "Flags:\t%016llx\n"
21620 +               "NCaps:\t%016llx\n",
21621 +               atomic_read(&nxi->nx_usecnt),
21622 +               atomic_read(&nxi->nx_tasks),
21623 +               (unsigned long long)nxi->nx_flags,
21624 +               (unsigned long long)nxi->nx_ncaps);
21625 +       return length;
21626 +}
21627 +
21628 +
21629 +
21630 +/* here the inode helpers */
21631 +
21632 +struct vs_entry {
21633 +       int len;
21634 +       char *name;
21635 +       mode_t mode;
21636 +       struct inode_operations *iop;
21637 +       struct file_operations *fop;
21638 +       union proc_op op;
21639 +};
21640 +
21641 +static struct inode *vs_proc_make_inode(struct super_block *sb, struct vs_entry *p)
21642 +{
21643 +       struct inode *inode = new_inode(sb);
21644 +
21645 +       if (!inode)
21646 +               goto out;
21647 +
21648 +       inode->i_mode = p->mode;
21649 +       if (p->iop)
21650 +               inode->i_op = p->iop;
21651 +       if (p->fop)
21652 +               inode->i_fop = p->fop;
21653 +
21654 +       inode->i_nlink = (p->mode & S_IFDIR) ? 2 : 1;
21655 +       inode->i_flags |= S_IMMUTABLE;
21656 +
21657 +       inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
21658 +
21659 +       inode->i_uid = 0;
21660 +       inode->i_gid = 0;
21661 +       inode->i_tag = 0;
21662 +out:
21663 +       return inode;
21664 +}
21665 +
21666 +static struct dentry *vs_proc_instantiate(struct inode *dir,
21667 +       struct dentry *dentry, int id, void *ptr)
21668 +{
21669 +       struct vs_entry *p = ptr;
21670 +       struct inode *inode = vs_proc_make_inode(dir->i_sb, p);
21671 +       struct dentry *error = ERR_PTR(-EINVAL);
21672 +
21673 +       if (!inode)
21674 +               goto out;
21675 +
21676 +       PROC_I(inode)->op = p->op;
21677 +       PROC_I(inode)->fd = id;
21678 +       d_add(dentry, inode);
21679 +       error = NULL;
21680 +out:
21681 +       return error;
21682 +}
21683 +
21684 +/* Lookups */
21685 +
21686 +typedef struct dentry *instantiate_t(struct inode *, struct dentry *, int, void *);
21687 +
21688 +/*
21689 + * Fill a directory entry.
21690 + *
21691 + * If possible create the dcache entry and derive our inode number and
21692 + * file type from dcache entry.
21693 + *
21694 + * Since all of the proc inode numbers are dynamically generated, the inode
21695 + * numbers do not exist until the inode is cache.  This means creating the
21696 + * the dcache entry in readdir is necessary to keep the inode numbers
21697 + * reported by readdir in sync with the inode numbers reported
21698 + * by stat.
21699 + */
21700 +static int proc_fill_cache(struct file *filp, void *dirent, filldir_t filldir,
21701 +       char *name, int len, instantiate_t instantiate, int id, void *ptr)
21702 +{
21703 +       struct dentry *child, *dir = filp->f_dentry;
21704 +       struct inode *inode;
21705 +       struct qstr qname;
21706 +       ino_t ino = 0;
21707 +       unsigned type = DT_UNKNOWN;
21708 +
21709 +       qname.name = name;
21710 +       qname.len  = len;
21711 +       qname.hash = full_name_hash(name, len);
21712 +
21713 +       child = d_lookup(dir, &qname);
21714 +       if (!child) {
21715 +               struct dentry *new;
21716 +               new = d_alloc(dir, &qname);
21717 +               if (new) {
21718 +                       child = instantiate(dir->d_inode, new, id, ptr);
21719 +                       if (child)
21720 +                               dput(new);
21721 +                       else
21722 +                               child = new;
21723 +               }
21724 +       }
21725 +       if (!child || IS_ERR(child) || !child->d_inode)
21726 +               goto end_instantiate;
21727 +       inode = child->d_inode;
21728 +       if (inode) {
21729 +               ino = inode->i_ino;
21730 +               type = inode->i_mode >> 12;
21731 +       }
21732 +       dput(child);
21733 +end_instantiate:
21734 +       if (!ino)
21735 +               ino = find_inode_number(dir, &qname);
21736 +       if (!ino)
21737 +               ino = 1;
21738 +       return filldir(dirent, name, len, filp->f_pos, ino, type);
21739 +}
21740 +
21741 +
21742 +
21743 +/* get and revalidate vx_info/xid */
21744 +
21745 +static inline
21746 +struct vx_info *get_proc_vx_info(struct inode *inode)
21747 +{
21748 +       return lookup_vx_info(PROC_I(inode)->fd);
21749 +}
21750 +
21751 +static int proc_xid_revalidate(struct dentry *dentry, struct nameidata *nd)
21752 +{
21753 +       struct inode *inode = dentry->d_inode;
21754 +       xid_t xid = PROC_I(inode)->fd;
21755 +
21756 +       if (!xid || xid_is_hashed(xid))
21757 +               return 1;
21758 +       d_drop(dentry);
21759 +       return 0;
21760 +}
21761 +
21762 +
21763 +/* get and revalidate nx_info/nid */
21764 +
21765 +static int proc_nid_revalidate(struct dentry *dentry, struct nameidata *nd)
21766 +{
21767 +       struct inode *inode = dentry->d_inode;
21768 +       nid_t nid = PROC_I(inode)->fd;
21769 +
21770 +       if (!nid || nid_is_hashed(nid))
21771 +               return 1;
21772 +       d_drop(dentry);
21773 +       return 0;
21774 +}
21775 +
21776 +
21777 +
21778 +#define PROC_BLOCK_SIZE (PAGE_SIZE - 1024)
21779 +
21780 +static ssize_t proc_vs_info_read(struct file *file, char __user *buf,
21781 +                         size_t count, loff_t *ppos)
21782 +{
21783 +       struct inode *inode = file->f_dentry->d_inode;
21784 +       unsigned long page;
21785 +       ssize_t length = 0;
21786 +
21787 +       if (count > PROC_BLOCK_SIZE)
21788 +               count = PROC_BLOCK_SIZE;
21789 +
21790 +       /* fade that out as soon as stable */
21791 +       WARN_ON(PROC_I(inode)->fd);
21792 +
21793 +       if (!(page = __get_free_page(GFP_KERNEL)))
21794 +               return -ENOMEM;
21795 +
21796 +       BUG_ON(!PROC_I(inode)->op.proc_vs_read);
21797 +       length = PROC_I(inode)->op.proc_vs_read((char *)page);
21798 +
21799 +       if (length >= 0)
21800 +               length = simple_read_from_buffer(buf, count, ppos,
21801 +                       (char *)page, length);
21802 +
21803 +       free_page(page);
21804 +       return length;
21805 +}
21806 +
21807 +static ssize_t proc_vx_info_read(struct file *file, char __user *buf,
21808 +                         size_t count, loff_t *ppos)
21809 +{
21810 +       struct inode *inode = file->f_dentry->d_inode;
21811 +       struct vx_info *vxi = NULL;
21812 +       xid_t xid = PROC_I(inode)->fd;
21813 +       unsigned long page;
21814 +       ssize_t length = 0;
21815 +
21816 +       if (count > PROC_BLOCK_SIZE)
21817 +               count = PROC_BLOCK_SIZE;
21818 +
21819 +       /* fade that out as soon as stable */
21820 +       WARN_ON(!xid);
21821 +       vxi = lookup_vx_info(xid);
21822 +       if (!vxi)
21823 +               goto out;
21824 +
21825 +       length = -ENOMEM;
21826 +       if (!(page = __get_free_page(GFP_KERNEL)))
21827 +               goto out_put;
21828 +
21829 +       BUG_ON(!PROC_I(inode)->op.proc_vxi_read);
21830 +       length = PROC_I(inode)->op.proc_vxi_read(vxi, (char *)page);
21831 +
21832 +       if (length >= 0)
21833 +               length = simple_read_from_buffer(buf, count, ppos,
21834 +                       (char *)page, length);
21835 +
21836 +       free_page(page);
21837 +out_put:
21838 +       put_vx_info(vxi);
21839 +out:
21840 +       return length;
21841 +}
21842 +
21843 +static ssize_t proc_nx_info_read(struct file *file, char __user *buf,
21844 +                         size_t count, loff_t *ppos)
21845 +{
21846 +       struct inode *inode = file->f_dentry->d_inode;
21847 +       struct nx_info *nxi = NULL;
21848 +       nid_t nid = PROC_I(inode)->fd;
21849 +       unsigned long page;
21850 +       ssize_t length = 0;
21851 +
21852 +       if (count > PROC_BLOCK_SIZE)
21853 +               count = PROC_BLOCK_SIZE;
21854 +
21855 +       /* fade that out as soon as stable */
21856 +       WARN_ON(!nid);
21857 +       nxi = lookup_nx_info(nid);
21858 +       if (!nxi)
21859 +               goto out;
21860 +
21861 +       length = -ENOMEM;
21862 +       if (!(page = __get_free_page(GFP_KERNEL)))
21863 +               goto out_put;
21864 +
21865 +       BUG_ON(!PROC_I(inode)->op.proc_nxi_read);
21866 +       length = PROC_I(inode)->op.proc_nxi_read(nxi, (char *)page);
21867 +
21868 +       if (length >= 0)
21869 +               length = simple_read_from_buffer(buf, count, ppos,
21870 +                       (char *)page, length);
21871 +
21872 +       free_page(page);
21873 +out_put:
21874 +       put_nx_info(nxi);
21875 +out:
21876 +       return length;
21877 +}
21878 +
21879 +
21880 +
21881 +/* here comes the lower level */
21882 +
21883 +
21884 +#define NOD(NAME, MODE, IOP, FOP, OP) {        \
21885 +       .len  = sizeof(NAME) - 1,       \
21886 +       .name = (NAME),                 \
21887 +       .mode = MODE,                   \
21888 +       .iop  = IOP,                    \
21889 +       .fop  = FOP,                    \
21890 +       .op   = OP,                     \
21891 +}
21892 +
21893 +
21894 +#define DIR(NAME, MODE, OTYPE)                         \
21895 +       NOD(NAME, (S_IFDIR | (MODE)),                   \
21896 +               &proc_ ## OTYPE ## _inode_operations,   \
21897 +               &proc_ ## OTYPE ## _file_operations, { } )
21898 +
21899 +#define INF(NAME, MODE, OTYPE)                         \
21900 +       NOD(NAME, (S_IFREG | (MODE)), NULL,             \
21901 +               &proc_vs_info_file_operations,          \
21902 +               { .proc_vs_read = &proc_##OTYPE } )
21903 +
21904 +#define VINF(NAME, MODE, OTYPE)                                \
21905 +       NOD(NAME, (S_IFREG | (MODE)), NULL,             \
21906 +               &proc_vx_info_file_operations,          \
21907 +               { .proc_vxi_read = &proc_##OTYPE } )
21908 +
21909 +#define NINF(NAME, MODE, OTYPE)                                \
21910 +       NOD(NAME, (S_IFREG | (MODE)), NULL,             \
21911 +               &proc_nx_info_file_operations,          \
21912 +               { .proc_nxi_read = &proc_##OTYPE } )
21913 +
21914 +
21915 +static struct file_operations proc_vs_info_file_operations = {
21916 +       .read =         proc_vs_info_read,
21917 +};
21918 +
21919 +static struct file_operations proc_vx_info_file_operations = {
21920 +       .read =         proc_vx_info_read,
21921 +};
21922 +
21923 +static struct dentry_operations proc_xid_dentry_operations = {
21924 +       .d_revalidate = proc_xid_revalidate,
21925 +};
21926 +
21927 +static struct vs_entry vx_base_stuff[] = {
21928 +       VINF("info",    S_IRUGO, vxi_info),
21929 +       VINF("status",  S_IRUGO, vxi_status),
21930 +       VINF("limit",   S_IRUGO, vxi_limit),
21931 +       VINF("sched",   S_IRUGO, vxi_sched),
21932 +       VINF("nsproxy", S_IRUGO, vxi_nsproxy0),
21933 +       VINF("nsproxy1",S_IRUGO, vxi_nsproxy1),
21934 +       VINF("cvirt",   S_IRUGO, vxi_cvirt),
21935 +       VINF("cacct",   S_IRUGO, vxi_cacct),
21936 +       {}
21937 +};
21938 +
21939 +
21940 +
21941 +
21942 +static struct dentry *proc_xid_instantiate(struct inode *dir,
21943 +       struct dentry *dentry, int id, void *ptr)
21944 +{
21945 +       dentry->d_op = &proc_xid_dentry_operations;
21946 +       return vs_proc_instantiate(dir, dentry, id, ptr);
21947 +}
21948 +
21949 +static struct dentry *proc_xid_lookup(struct inode *dir,
21950 +       struct dentry *dentry, struct nameidata *nd)
21951 +{
21952 +       struct vs_entry *p = vx_base_stuff;
21953 +       struct dentry *error = ERR_PTR(-ENOENT);
21954 +
21955 +       for (; p->name; p++) {
21956 +               if (p->len != dentry->d_name.len)
21957 +                       continue;
21958 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
21959 +                       break;
21960 +       }
21961 +       if (!p->name)
21962 +               goto out;
21963 +
21964 +       error = proc_xid_instantiate(dir, dentry, PROC_I(dir)->fd, p);
21965 +out:
21966 +       return error;
21967 +}
21968 +
21969 +static int proc_xid_readdir(struct file *filp,
21970 +       void *dirent, filldir_t filldir)
21971 +{
21972 +       struct dentry *dentry = filp->f_dentry;
21973 +       struct inode *inode = dentry->d_inode;
21974 +       struct vs_entry *p = vx_base_stuff;
21975 +       int size = sizeof(vx_base_stuff) / sizeof(struct vs_entry);
21976 +       int pos, index;
21977 +       u64 ino;
21978 +
21979 +       pos = filp->f_pos;
21980 +       switch (pos) {
21981 +       case 0:
21982 +               ino = inode->i_ino;
21983 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
21984 +                       goto out;
21985 +               pos++;
21986 +               /* fall through */
21987 +       case 1:
21988 +               ino = parent_ino(dentry);
21989 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
21990 +                       goto out;
21991 +               pos++;
21992 +               /* fall through */
21993 +       default:
21994 +               index = pos - 2;
21995 +               if (index >= size)
21996 +                       goto out;
21997 +               for (p += index; p->name; p++) {
21998 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
21999 +                               vs_proc_instantiate, PROC_I(inode)->fd, p))
22000 +                               goto out;
22001 +                       pos++;
22002 +               }
22003 +       }
22004 +out:
22005 +       filp->f_pos = pos;
22006 +       return 1;
22007 +}
22008 +
22009 +
22010 +
22011 +static struct file_operations proc_nx_info_file_operations = {
22012 +       .read =         proc_nx_info_read,
22013 +};
22014 +
22015 +static struct dentry_operations proc_nid_dentry_operations = {
22016 +       .d_revalidate = proc_nid_revalidate,
22017 +};
22018 +
22019 +static struct vs_entry nx_base_stuff[] = {
22020 +       NINF("info",    S_IRUGO, nxi_info),
22021 +       NINF("status",  S_IRUGO, nxi_status),
22022 +       {}
22023 +};
22024 +
22025 +
22026 +static struct dentry *proc_nid_instantiate(struct inode *dir,
22027 +       struct dentry *dentry, int id, void *ptr)
22028 +{
22029 +       dentry->d_op = &proc_nid_dentry_operations;
22030 +       return vs_proc_instantiate(dir, dentry, id, ptr);
22031 +}
22032 +
22033 +static struct dentry *proc_nid_lookup(struct inode *dir,
22034 +       struct dentry *dentry, struct nameidata *nd)
22035 +{
22036 +       struct vs_entry *p = nx_base_stuff;
22037 +       struct dentry *error = ERR_PTR(-ENOENT);
22038 +
22039 +       for (; p->name; p++) {
22040 +               if (p->len != dentry->d_name.len)
22041 +                       continue;
22042 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
22043 +                       break;
22044 +       }
22045 +       if (!p->name)
22046 +               goto out;
22047 +
22048 +       error = proc_nid_instantiate(dir, dentry, PROC_I(dir)->fd, p);
22049 +out:
22050 +       return error;
22051 +}
22052 +
22053 +static int proc_nid_readdir(struct file *filp,
22054 +       void *dirent, filldir_t filldir)
22055 +{
22056 +       struct dentry *dentry = filp->f_dentry;
22057 +       struct inode *inode = dentry->d_inode;
22058 +       struct vs_entry *p = nx_base_stuff;
22059 +       int size = sizeof(nx_base_stuff) / sizeof(struct vs_entry);
22060 +       int pos, index;
22061 +       u64 ino;
22062 +
22063 +       pos = filp->f_pos;
22064 +       switch (pos) {
22065 +       case 0:
22066 +               ino = inode->i_ino;
22067 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
22068 +                       goto out;
22069 +               pos++;
22070 +               /* fall through */
22071 +       case 1:
22072 +               ino = parent_ino(dentry);
22073 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
22074 +                       goto out;
22075 +               pos++;
22076 +               /* fall through */
22077 +       default:
22078 +               index = pos - 2;
22079 +               if (index >= size)
22080 +                       goto out;
22081 +               for (p += index; p->name; p++) {
22082 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
22083 +                               vs_proc_instantiate, PROC_I(inode)->fd, p))
22084 +                               goto out;
22085 +                       pos++;
22086 +               }
22087 +       }
22088 +out:
22089 +       filp->f_pos = pos;
22090 +       return 1;
22091 +}
22092 +
22093 +
22094 +#define MAX_MULBY10    ((~0U - 9) / 10)
22095 +
22096 +static inline int atovid(const char *str, int len)
22097 +{
22098 +       int vid, c;
22099 +
22100 +       vid = 0;
22101 +       while (len-- > 0) {
22102 +               c = *str - '0';
22103 +               str++;
22104 +               if (c > 9)
22105 +                       return -1;
22106 +               if (vid >= MAX_MULBY10)
22107 +                       return -1;
22108 +               vid *= 10;
22109 +               vid += c;
22110 +               if (!vid)
22111 +                       return -1;
22112 +       }
22113 +       return vid;
22114 +}
22115 +
22116 +/* now the upper level (virtual) */
22117 +
22118 +
22119 +static struct file_operations proc_xid_file_operations = {
22120 +       .read =         generic_read_dir,
22121 +       .readdir =      proc_xid_readdir,
22122 +};
22123 +
22124 +static struct inode_operations proc_xid_inode_operations = {
22125 +       .lookup =       proc_xid_lookup,
22126 +};
22127 +
22128 +static struct vs_entry vx_virtual_stuff[] = {
22129 +       INF("info",     S_IRUGO, virtual_info),
22130 +       INF("status",   S_IRUGO, virtual_status),
22131 +       DIR(NULL,       S_IRUGO | S_IXUGO, xid),
22132 +};
22133 +
22134 +
22135 +static struct dentry *proc_virtual_lookup(struct inode *dir,
22136 +       struct dentry *dentry, struct nameidata *nd)
22137 +{
22138 +       struct vs_entry *p = vx_virtual_stuff;
22139 +       struct dentry *error = ERR_PTR(-ENOENT);
22140 +       int id = 0;
22141 +
22142 +       for (; p->name; p++) {
22143 +               if (p->len != dentry->d_name.len)
22144 +                       continue;
22145 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
22146 +                       break;
22147 +       }
22148 +       if (p->name)
22149 +               goto instantiate;
22150 +
22151 +       id = atovid(dentry->d_name.name, dentry->d_name.len);
22152 +       if ((id < 0) || !xid_is_hashed(id))
22153 +               goto out;
22154 +
22155 +instantiate:
22156 +       error = proc_xid_instantiate(dir, dentry, id, p);
22157 +out:
22158 +       return error;
22159 +}
22160 +
22161 +static struct file_operations proc_nid_file_operations = {
22162 +       .read =         generic_read_dir,
22163 +       .readdir =      proc_nid_readdir,
22164 +};
22165 +
22166 +static struct inode_operations proc_nid_inode_operations = {
22167 +       .lookup =       proc_nid_lookup,
22168 +};
22169 +
22170 +static struct vs_entry nx_virtnet_stuff[] = {
22171 +       INF("info",     S_IRUGO, virtnet_info),
22172 +       INF("status",   S_IRUGO, virtnet_status),
22173 +       DIR(NULL,       S_IRUGO | S_IXUGO, nid),
22174 +};
22175 +
22176 +
22177 +static struct dentry *proc_virtnet_lookup(struct inode *dir,
22178 +       struct dentry *dentry, struct nameidata *nd)
22179 +{
22180 +       struct vs_entry *p = nx_virtnet_stuff;
22181 +       struct dentry *error = ERR_PTR(-ENOENT);
22182 +       int id = 0;
22183 +
22184 +       for (; p->name; p++) {
22185 +               if (p->len != dentry->d_name.len)
22186 +                       continue;
22187 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
22188 +                       break;
22189 +       }
22190 +       if (p->name)
22191 +               goto instantiate;
22192 +
22193 +       id = atovid(dentry->d_name.name, dentry->d_name.len);
22194 +       if ((id < 0) || !nid_is_hashed(id))
22195 +               goto out;
22196 +
22197 +instantiate:
22198 +       error = proc_nid_instantiate(dir, dentry, id, p);
22199 +out:
22200 +       return error;
22201 +}
22202 +
22203 +
22204 +#define PROC_MAXVIDS 32
22205 +
22206 +int proc_virtual_readdir(struct file *filp,
22207 +       void *dirent, filldir_t filldir)
22208 +{
22209 +       struct dentry *dentry = filp->f_dentry;
22210 +       struct inode *inode = dentry->d_inode;
22211 +       struct vs_entry *p = vx_virtual_stuff;
22212 +       int size = sizeof(vx_virtual_stuff) / sizeof(struct vs_entry);
22213 +       int pos, index;
22214 +       unsigned int xid_array[PROC_MAXVIDS];
22215 +       char buf[PROC_NUMBUF];
22216 +       unsigned int nr_xids, i;
22217 +       u64 ino;
22218 +
22219 +       pos = filp->f_pos;
22220 +       switch (pos) {
22221 +       case 0:
22222 +               ino = inode->i_ino;
22223 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
22224 +                       goto out;
22225 +               pos++;
22226 +               /* fall through */
22227 +       case 1:
22228 +               ino = parent_ino(dentry);
22229 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
22230 +                       goto out;
22231 +               pos++;
22232 +               /* fall through */
22233 +       default:
22234 +               index = pos - 2;
22235 +               if (index >= size)
22236 +                       goto entries;
22237 +               for (p += index; p->name; p++) {
22238 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
22239 +                               vs_proc_instantiate, 0, p))
22240 +                               goto out;
22241 +                       pos++;
22242 +               }
22243 +       entries:
22244 +               index = pos - size;
22245 +               p = &vx_virtual_stuff[size - 1];
22246 +               nr_xids = get_xid_list(index, xid_array, PROC_MAXVIDS);
22247 +               for (i = 0; i < nr_xids; i++) {
22248 +                       int n, xid = xid_array[i];
22249 +                       unsigned int j = PROC_NUMBUF;
22250 +
22251 +                       n = xid;
22252 +                       do
22253 +                               buf[--j] = '0' + (n % 10);
22254 +                       while (n /= 10);
22255 +
22256 +                       if (proc_fill_cache(filp, dirent, filldir,
22257 +                               buf + j, PROC_NUMBUF - j,
22258 +                               vs_proc_instantiate, xid, p))
22259 +                               goto out;
22260 +                       pos++;
22261 +               }
22262 +       }
22263 +out:
22264 +       filp->f_pos = pos;
22265 +       return 0;
22266 +}
22267 +
22268 +static int proc_virtual_getattr(struct vfsmount *mnt,
22269 +       struct dentry *dentry, struct kstat *stat)
22270 +{
22271 +       struct inode *inode = dentry->d_inode;
22272 +
22273 +       generic_fillattr(inode, stat);
22274 +       stat->nlink = 2 + atomic_read(&vx_global_cactive);
22275 +       return 0;
22276 +}
22277 +
22278 +static struct file_operations proc_virtual_dir_operations = {
22279 +       .read =         generic_read_dir,
22280 +       .readdir =      proc_virtual_readdir,
22281 +};
22282 +
22283 +static struct inode_operations proc_virtual_dir_inode_operations = {
22284 +       .getattr =      proc_virtual_getattr,
22285 +       .lookup =       proc_virtual_lookup,
22286 +};
22287 +
22288 +
22289 +
22290 +
22291 +
22292 +int proc_virtnet_readdir(struct file *filp,
22293 +       void *dirent, filldir_t filldir)
22294 +{
22295 +       struct dentry *dentry = filp->f_dentry;
22296 +       struct inode *inode = dentry->d_inode;
22297 +       struct vs_entry *p = nx_virtnet_stuff;
22298 +       int size = sizeof(nx_virtnet_stuff) / sizeof(struct vs_entry);
22299 +       int pos, index;
22300 +       unsigned int nid_array[PROC_MAXVIDS];
22301 +       char buf[PROC_NUMBUF];
22302 +       unsigned int nr_nids, i;
22303 +       u64 ino;
22304 +
22305 +       pos = filp->f_pos;
22306 +       switch (pos) {
22307 +       case 0:
22308 +               ino = inode->i_ino;
22309 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
22310 +                       goto out;
22311 +               pos++;
22312 +               /* fall through */
22313 +       case 1:
22314 +               ino = parent_ino(dentry);
22315 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
22316 +                       goto out;
22317 +               pos++;
22318 +               /* fall through */
22319 +       default:
22320 +               index = pos - 2;
22321 +               if (index >= size)
22322 +                       goto entries;
22323 +               for (p += index; p->name; p++) {
22324 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
22325 +                               vs_proc_instantiate, 0, p))
22326 +                               goto out;
22327 +                       pos++;
22328 +               }
22329 +       entries:
22330 +               index = pos - size;
22331 +               p = &nx_virtnet_stuff[size - 1];
22332 +               nr_nids = get_nid_list(index, nid_array, PROC_MAXVIDS);
22333 +               for (i = 0; i < nr_nids; i++) {
22334 +                       int n, nid = nid_array[i];
22335 +                       unsigned int j = PROC_NUMBUF;
22336 +
22337 +                       n = nid;
22338 +                       do
22339 +                               buf[--j] = '0' + (n % 10);
22340 +                       while (n /= 10);
22341 +
22342 +                       if (proc_fill_cache(filp, dirent, filldir,
22343 +                               buf + j, PROC_NUMBUF - j,
22344 +                               vs_proc_instantiate, nid, p))
22345 +                               goto out;
22346 +                       pos++;
22347 +               }
22348 +       }
22349 +out:
22350 +       filp->f_pos = pos;
22351 +       return 0;
22352 +}
22353 +
22354 +static int proc_virtnet_getattr(struct vfsmount *mnt,
22355 +       struct dentry *dentry, struct kstat *stat)
22356 +{
22357 +       struct inode *inode = dentry->d_inode;
22358 +
22359 +       generic_fillattr(inode, stat);
22360 +       stat->nlink = 2 + atomic_read(&nx_global_cactive);
22361 +       return 0;
22362 +}
22363 +
22364 +static struct file_operations proc_virtnet_dir_operations = {
22365 +       .read =         generic_read_dir,
22366 +       .readdir =      proc_virtnet_readdir,
22367 +};
22368 +
22369 +static struct inode_operations proc_virtnet_dir_inode_operations = {
22370 +       .getattr =      proc_virtnet_getattr,
22371 +       .lookup =       proc_virtnet_lookup,
22372 +};
22373 +
22374 +
22375 +
22376 +void proc_vx_init(void)
22377 +{
22378 +       struct proc_dir_entry *ent;
22379 +
22380 +       ent = proc_mkdir("virtual", 0);
22381 +       if (ent) {
22382 +               ent->proc_fops = &proc_virtual_dir_operations;
22383 +               ent->proc_iops = &proc_virtual_dir_inode_operations;
22384 +       }
22385 +       proc_virtual = ent;
22386 +
22387 +       ent = proc_mkdir("virtnet", 0);
22388 +       if (ent) {
22389 +               ent->proc_fops = &proc_virtnet_dir_operations;
22390 +               ent->proc_iops = &proc_virtnet_dir_inode_operations;
22391 +       }
22392 +       proc_virtnet = ent;
22393 +}
22394 +
22395 +
22396 +
22397 +
22398 +/* per pid info */
22399 +
22400 +
22401 +int proc_pid_vx_info(struct task_struct *p, char *buffer)
22402 +{
22403 +       struct vx_info *vxi;
22404 +       char *orig = buffer;
22405 +
22406 +       buffer += sprintf(buffer, "XID:\t%d\n", vx_task_xid(p));
22407 +
22408 +       vxi = task_get_vx_info(p);
22409 +       if (!vxi)
22410 +               goto out;
22411 +
22412 +       buffer += sprintf(buffer, "BCaps:\t");
22413 +       buffer = print_cap_t(buffer, &vxi->vx_bcaps);
22414 +       buffer += sprintf(buffer, "\n");
22415 +       buffer += sprintf(buffer, "CCaps:\t%016llx\n",
22416 +               (unsigned long long)vxi->vx_ccaps);
22417 +       buffer += sprintf(buffer, "CFlags:\t%016llx\n",
22418 +               (unsigned long long)vxi->vx_flags);
22419 +       buffer += sprintf(buffer, "CIPid:\t%d\n", vxi->vx_initpid);
22420 +
22421 +       put_vx_info(vxi);
22422 +out:
22423 +       return buffer - orig;
22424 +}
22425 +
22426 +
22427 +int proc_pid_nx_info(struct task_struct *p, char *buffer)
22428 +{
22429 +       struct nx_info *nxi;
22430 +       struct nx_addr_v4 *v4a;
22431 +#ifdef CONFIG_IPV6
22432 +       struct nx_addr_v6 *v6a;
22433 +#endif
22434 +       char *orig = buffer;
22435 +       int i;
22436 +
22437 +       buffer += sprintf(buffer, "NID:\t%d\n", nx_task_nid(p));
22438 +
22439 +       nxi = task_get_nx_info(p);
22440 +       if (!nxi)
22441 +               goto out;
22442 +
22443 +       buffer += sprintf(buffer, "NCaps:\t%016llx\n",
22444 +               (unsigned long long)nxi->nx_ncaps);
22445 +       buffer += sprintf(buffer, "NFlags:\t%016llx\n",
22446 +               (unsigned long long)nxi->nx_flags);
22447 +
22448 +       buffer += sprintf(buffer,
22449 +               "V4Root[bcast]:\t" NIPQUAD_FMT "\n",
22450 +               NIPQUAD(nxi->v4_bcast.s_addr));
22451 +       buffer += sprintf (buffer,
22452 +               "V4Root[lback]:\t" NIPQUAD_FMT "\n",
22453 +               NIPQUAD(nxi->v4_lback.s_addr));
22454 +       if (!NX_IPV4(nxi))
22455 +               goto skip_v4;
22456 +       for (i = 0, v4a = &nxi->v4; v4a; i++, v4a = v4a->next)
22457 +               buffer += sprintf(buffer, "V4Root[%d]:\t" NXAV4_FMT "\n",
22458 +                       i, NXAV4(v4a));
22459 +skip_v4:
22460 +#ifdef CONFIG_IPV6
22461 +       if (!NX_IPV6(nxi))
22462 +               goto skip_v6;
22463 +       for (i = 0, v6a = &nxi->v6; v6a; i++, v6a = v6a->next)
22464 +               buffer += sprintf(buffer, "V6Root[%d]:\t" NXAV6_FMT "\n",
22465 +                       i, NXAV6(v6a));
22466 +skip_v6:
22467 +#endif
22468 +       put_nx_info(nxi);
22469 +out:
22470 +       return buffer - orig;
22471 +}
22472 +
22473 diff -NurpP --minimal linux-3.0.25/kernel/vserver/sched.c linux-3.0.25-vs2.3.2.3/kernel/vserver/sched.c
22474 --- linux-3.0.25/kernel/vserver/sched.c 1970-01-01 01:00:00.000000000 +0100
22475 +++ linux-3.0.25-vs2.3.2.3/kernel/vserver/sched.c       2011-06-10 22:11:24.000000000 +0200
22476 @@ -0,0 +1,82 @@
22477 +/*
22478 + *  linux/kernel/vserver/sched.c
22479 + *
22480 + *  Virtual Server: Scheduler Support
22481 + *
22482 + *  Copyright (C) 2004-2010  Herbert Pötzl
22483 + *
22484 + *  V0.01  adapted Sam Vilains version to 2.6.3
22485 + *  V0.02  removed legacy interface
22486 + *  V0.03  changed vcmds to vxi arg
22487 + *  V0.04  removed older and legacy interfaces
22488 + *  V0.05  removed scheduler code/commands
22489 + *
22490 + */
22491 +
22492 +#include <linux/vs_context.h>
22493 +#include <linux/vs_sched.h>
22494 +#include <linux/vserver/sched_cmd.h>
22495 +
22496 +#include <asm/uaccess.h>
22497 +
22498 +
22499 +void vx_update_sched_param(struct _vx_sched *sched,
22500 +       struct _vx_sched_pc *sched_pc)
22501 +{
22502 +       sched_pc->prio_bias = sched->prio_bias;
22503 +}
22504 +
22505 +static int do_set_prio_bias(struct vx_info *vxi, struct vcmd_prio_bias *data)
22506 +{
22507 +       int cpu;
22508 +
22509 +       if (data->prio_bias > MAX_PRIO_BIAS)
22510 +               data->prio_bias = MAX_PRIO_BIAS;
22511 +       if (data->prio_bias < MIN_PRIO_BIAS)
22512 +               data->prio_bias = MIN_PRIO_BIAS;
22513 +
22514 +       if (data->cpu_id != ~0) {
22515 +               vxi->sched.update = cpumask_of_cpu(data->cpu_id);
22516 +               cpus_and(vxi->sched.update, cpu_online_map,
22517 +                       vxi->sched.update);
22518 +       } else
22519 +               vxi->sched.update = cpu_online_map;
22520 +
22521 +       for_each_cpu_mask(cpu, vxi->sched.update)
22522 +               vx_update_sched_param(&vxi->sched,
22523 +                       &vx_per_cpu(vxi, sched_pc, cpu));
22524 +       return 0;
22525 +}
22526 +
22527 +int vc_set_prio_bias(struct vx_info *vxi, void __user *data)
22528 +{
22529 +       struct vcmd_prio_bias vc_data;
22530 +
22531 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
22532 +               return -EFAULT;
22533 +
22534 +       return do_set_prio_bias(vxi, &vc_data);
22535 +}
22536 +
22537 +int vc_get_prio_bias(struct vx_info *vxi, void __user *data)
22538 +{
22539 +       struct vcmd_prio_bias vc_data;
22540 +       struct _vx_sched_pc *pcd;
22541 +       int cpu;
22542 +
22543 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
22544 +               return -EFAULT;
22545 +
22546 +       cpu = vc_data.cpu_id;
22547 +
22548 +       if (!cpu_possible(cpu))
22549 +               return -EINVAL;
22550 +
22551 +       pcd = &vx_per_cpu(vxi, sched_pc, cpu);
22552 +       vc_data.prio_bias = pcd->prio_bias;
22553 +
22554 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
22555 +               return -EFAULT;
22556 +       return 0;
22557 +}
22558 +
22559 diff -NurpP --minimal linux-3.0.25/kernel/vserver/sched_init.h linux-3.0.25-vs2.3.2.3/kernel/vserver/sched_init.h
22560 --- linux-3.0.25/kernel/vserver/sched_init.h    1970-01-01 01:00:00.000000000 +0100
22561 +++ linux-3.0.25-vs2.3.2.3/kernel/vserver/sched_init.h  2011-06-10 22:11:24.000000000 +0200
22562 @@ -0,0 +1,27 @@
22563 +
22564 +static inline void vx_info_init_sched(struct _vx_sched *sched)
22565 +{
22566 +       /* scheduling; hard code starting values as constants */
22567 +       sched->prio_bias = 0;
22568 +}
22569 +
22570 +static inline
22571 +void vx_info_init_sched_pc(struct _vx_sched_pc *sched_pc, int cpu)
22572 +{
22573 +       sched_pc->prio_bias = 0;
22574 +
22575 +       sched_pc->user_ticks = 0;
22576 +       sched_pc->sys_ticks = 0;
22577 +       sched_pc->hold_ticks = 0;
22578 +}
22579 +
22580 +static inline void vx_info_exit_sched(struct _vx_sched *sched)
22581 +{
22582 +       return;
22583 +}
22584 +
22585 +static inline
22586 +void vx_info_exit_sched_pc(struct _vx_sched_pc *sched_pc, int cpu)
22587 +{
22588 +       return;
22589 +}
22590 diff -NurpP --minimal linux-3.0.25/kernel/vserver/sched_proc.h linux-3.0.25-vs2.3.2.3/kernel/vserver/sched_proc.h
22591 --- linux-3.0.25/kernel/vserver/sched_proc.h    1970-01-01 01:00:00.000000000 +0100
22592 +++ linux-3.0.25-vs2.3.2.3/kernel/vserver/sched_proc.h  2011-06-10 22:11:24.000000000 +0200
22593 @@ -0,0 +1,32 @@
22594 +#ifndef _VX_SCHED_PROC_H
22595 +#define _VX_SCHED_PROC_H
22596 +
22597 +
22598 +static inline
22599 +int vx_info_proc_sched(struct _vx_sched *sched, char *buffer)
22600 +{
22601 +       int length = 0;
22602 +
22603 +       length += sprintf(buffer,
22604 +               "PrioBias:\t%8d\n",
22605 +               sched->prio_bias);
22606 +       return length;
22607 +}
22608 +
22609 +static inline
22610 +int vx_info_proc_sched_pc(struct _vx_sched_pc *sched_pc,
22611 +       char *buffer, int cpu)
22612 +{
22613 +       int length = 0;
22614 +
22615 +       length += sprintf(buffer + length,
22616 +               "cpu %d: %lld %lld %lld", cpu,
22617 +               (unsigned long long)sched_pc->user_ticks,
22618 +               (unsigned long long)sched_pc->sys_ticks,
22619 +               (unsigned long long)sched_pc->hold_ticks);
22620 +       length += sprintf(buffer + length,
22621 +               " %d\n", sched_pc->prio_bias);
22622 +       return length;
22623 +}
22624 +
22625 +#endif /* _VX_SCHED_PROC_H */
22626 diff -NurpP --minimal linux-3.0.25/kernel/vserver/signal.c linux-3.0.25-vs2.3.2.3/kernel/vserver/signal.c
22627 --- linux-3.0.25/kernel/vserver/signal.c        1970-01-01 01:00:00.000000000 +0100
22628 +++ linux-3.0.25-vs2.3.2.3/kernel/vserver/signal.c      2011-06-10 22:11:24.000000000 +0200
22629 @@ -0,0 +1,134 @@
22630 +/*
22631 + *  linux/kernel/vserver/signal.c
22632 + *
22633 + *  Virtual Server: Signal Support
22634 + *
22635 + *  Copyright (C) 2003-2007  Herbert Pötzl
22636 + *
22637 + *  V0.01  broken out from vcontext V0.05
22638 + *  V0.02  changed vcmds to vxi arg
22639 + *  V0.03  adjusted siginfo for kill
22640 + *
22641 + */
22642 +
22643 +#include <asm/uaccess.h>
22644 +
22645 +#include <linux/vs_context.h>
22646 +#include <linux/vs_pid.h>
22647 +#include <linux/vserver/signal_cmd.h>
22648 +
22649 +
22650 +int vx_info_kill(struct vx_info *vxi, int pid, int sig)
22651 +{
22652 +       int retval, count = 0;
22653 +       struct task_struct *p;
22654 +       struct siginfo *sip = SEND_SIG_PRIV;
22655 +
22656 +       retval = -ESRCH;
22657 +       vxdprintk(VXD_CBIT(misc, 4),
22658 +               "vx_info_kill(%p[#%d],%d,%d)*",
22659 +               vxi, vxi->vx_id, pid, sig);
22660 +       read_lock(&tasklist_lock);
22661 +       switch (pid) {
22662 +       case  0:
22663 +       case -1:
22664 +               for_each_process(p) {
22665 +                       int err = 0;
22666 +
22667 +                       if (vx_task_xid(p) != vxi->vx_id || p->pid <= 1 ||
22668 +                               (pid && vxi->vx_initpid == p->pid))
22669 +                               continue;
22670 +
22671 +                       err = group_send_sig_info(sig, sip, p);
22672 +                       ++count;
22673 +                       if (err != -EPERM)
22674 +                               retval = err;
22675 +               }
22676 +               break;
22677 +
22678 +       case 1:
22679 +               if (vxi->vx_initpid) {
22680 +                       pid = vxi->vx_initpid;
22681 +                       /* for now, only SIGINT to private init ... */
22682 +                       if (!vx_info_flags(vxi, VXF_STATE_ADMIN, 0) &&
22683 +                               /* ... as long as there are tasks left */
22684 +                               (atomic_read(&vxi->vx_tasks) > 1))
22685 +                               sig = SIGINT;
22686 +               }
22687 +               /* fallthrough */
22688 +       default:
22689 +               rcu_read_lock();
22690 +               p = find_task_by_real_pid(pid);
22691 +               rcu_read_unlock();
22692 +               if (p) {
22693 +                       if (vx_task_xid(p) == vxi->vx_id)
22694 +                               retval = group_send_sig_info(sig, sip, p);
22695 +               }
22696 +               break;
22697 +       }
22698 +       read_unlock(&tasklist_lock);
22699 +       vxdprintk(VXD_CBIT(misc, 4),
22700 +               "vx_info_kill(%p[#%d],%d,%d,%ld) = %d",
22701 +               vxi, vxi->vx_id, pid, sig, (long)sip, retval);
22702 +       return retval;
22703 +}
22704 +
22705 +int vc_ctx_kill(struct vx_info *vxi, void __user *data)
22706 +{
22707 +       struct vcmd_ctx_kill_v0 vc_data;
22708 +
22709 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
22710 +               return -EFAULT;
22711 +
22712 +       /* special check to allow guest shutdown */
22713 +       if (!vx_info_flags(vxi, VXF_STATE_ADMIN, 0) &&
22714 +               /* forbid killall pid=0 when init is present */
22715 +               (((vc_data.pid < 1) && vxi->vx_initpid) ||
22716 +               (vc_data.pid > 1)))
22717 +               return -EACCES;
22718 +
22719 +       return vx_info_kill(vxi, vc_data.pid, vc_data.sig);
22720 +}
22721 +
22722 +
22723 +static int __wait_exit(struct vx_info *vxi)
22724 +{
22725 +       DECLARE_WAITQUEUE(wait, current);
22726 +       int ret = 0;
22727 +
22728 +       add_wait_queue(&vxi->vx_wait, &wait);
22729 +       set_current_state(TASK_INTERRUPTIBLE);
22730 +
22731 +wait:
22732 +       if (vx_info_state(vxi,
22733 +               VXS_SHUTDOWN | VXS_HASHED | VXS_HELPER) == VXS_SHUTDOWN)
22734 +               goto out;
22735 +       if (signal_pending(current)) {
22736 +               ret = -ERESTARTSYS;
22737 +               goto out;
22738 +       }
22739 +       schedule();
22740 +       goto wait;
22741 +
22742 +out:
22743 +       set_current_state(TASK_RUNNING);
22744 +       remove_wait_queue(&vxi->vx_wait, &wait);
22745 +       return ret;
22746 +}
22747 +
22748 +
22749 +
22750 +int vc_wait_exit(struct vx_info *vxi, void __user *data)
22751 +{
22752 +       struct vcmd_wait_exit_v0 vc_data;
22753 +       int ret;
22754 +
22755 +       ret = __wait_exit(vxi);
22756 +       vc_data.reboot_cmd = vxi->reboot_cmd;
22757 +       vc_data.exit_code = vxi->exit_code;
22758 +
22759 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
22760 +               ret = -EFAULT;
22761 +       return ret;
22762 +}
22763 +
22764 diff -NurpP --minimal linux-3.0.25/kernel/vserver/space.c linux-3.0.25-vs2.3.2.3/kernel/vserver/space.c
22765 --- linux-3.0.25/kernel/vserver/space.c 1970-01-01 01:00:00.000000000 +0100
22766 +++ linux-3.0.25-vs2.3.2.3/kernel/vserver/space.c       2011-07-20 02:11:49.000000000 +0200
22767 @@ -0,0 +1,435 @@
22768 +/*
22769 + *  linux/kernel/vserver/space.c
22770 + *
22771 + *  Virtual Server: Context Space Support
22772 + *
22773 + *  Copyright (C) 2003-2010  Herbert Pötzl
22774 + *
22775 + *  V0.01  broken out from context.c 0.07
22776 + *  V0.02  added task locking for namespace
22777 + *  V0.03  broken out vx_enter_namespace
22778 + *  V0.04  added *space support and commands
22779 + *  V0.05  added credential support
22780 + *
22781 + */
22782 +
22783 +#include <linux/utsname.h>
22784 +#include <linux/nsproxy.h>
22785 +#include <linux/err.h>
22786 +#include <linux/fs_struct.h>
22787 +#include <linux/cred.h>
22788 +#include <asm/uaccess.h>
22789 +
22790 +#include <linux/vs_context.h>
22791 +#include <linux/vserver/space.h>
22792 +#include <linux/vserver/space_cmd.h>
22793 +
22794 +atomic_t vs_global_nsproxy     = ATOMIC_INIT(0);
22795 +atomic_t vs_global_fs          = ATOMIC_INIT(0);
22796 +atomic_t vs_global_mnt_ns      = ATOMIC_INIT(0);
22797 +atomic_t vs_global_uts_ns      = ATOMIC_INIT(0);
22798 +atomic_t vs_global_user_ns     = ATOMIC_INIT(0);
22799 +atomic_t vs_global_pid_ns      = ATOMIC_INIT(0);
22800 +
22801 +
22802 +/* namespace functions */
22803 +
22804 +#include <linux/mnt_namespace.h>
22805 +#include <linux/user_namespace.h>
22806 +#include <linux/pid_namespace.h>
22807 +#include <linux/ipc_namespace.h>
22808 +#include <net/net_namespace.h>
22809 +
22810 +
22811 +static const struct vcmd_space_mask_v1 space_mask_v0 = {
22812 +       .mask = CLONE_FS |
22813 +               CLONE_NEWNS |
22814 +#ifdef CONFIG_UTS_NS
22815 +               CLONE_NEWUTS |
22816 +#endif
22817 +#ifdef CONFIG_IPC_NS
22818 +               CLONE_NEWIPC |
22819 +#endif
22820 +#ifdef CONFIG_USER_NS
22821 +               CLONE_NEWUSER |
22822 +#endif
22823 +               0
22824 +};
22825 +
22826 +static const struct vcmd_space_mask_v1 space_mask = {
22827 +       .mask = CLONE_FS |
22828 +               CLONE_NEWNS |
22829 +#ifdef CONFIG_UTS_NS
22830 +               CLONE_NEWUTS |
22831 +#endif
22832 +#ifdef CONFIG_IPC_NS
22833 +               CLONE_NEWIPC |
22834 +#endif
22835 +#ifdef CONFIG_USER_NS
22836 +               CLONE_NEWUSER |
22837 +#endif
22838 +#ifdef CONFIG_PID_NS
22839 +               CLONE_NEWPID |
22840 +#endif
22841 +#ifdef CONFIG_NET_NS
22842 +               CLONE_NEWNET |
22843 +#endif
22844 +               0
22845 +};
22846 +
22847 +static const struct vcmd_space_mask_v1 default_space_mask = {
22848 +       .mask = CLONE_FS |
22849 +               CLONE_NEWNS |
22850 +#ifdef CONFIG_UTS_NS
22851 +               CLONE_NEWUTS |
22852 +#endif
22853 +#ifdef CONFIG_IPC_NS
22854 +               CLONE_NEWIPC |
22855 +#endif
22856 +#ifdef CONFIG_USER_NS
22857 +               CLONE_NEWUSER |
22858 +#endif
22859 +#ifdef CONFIG_PID_NS
22860 +//             CLONE_NEWPID |
22861 +#endif
22862 +               0
22863 +};
22864 +
22865 +/*
22866 + *     build a new nsproxy mix
22867 + *      assumes that both proxies are 'const'
22868 + *     does not touch nsproxy refcounts
22869 + *     will hold a reference on the result.
22870 + */
22871 +
22872 +struct nsproxy *vs_mix_nsproxy(struct nsproxy *old_nsproxy,
22873 +       struct nsproxy *new_nsproxy, unsigned long mask)
22874 +{
22875 +       struct mnt_namespace *old_ns;
22876 +       struct uts_namespace *old_uts;
22877 +       struct ipc_namespace *old_ipc;
22878 +#ifdef CONFIG_PID_NS
22879 +       struct pid_namespace *old_pid;
22880 +#endif
22881 +#ifdef CONFIG_NET_NS
22882 +       struct net *old_net;
22883 +#endif
22884 +       struct nsproxy *nsproxy;
22885 +
22886 +       nsproxy = copy_nsproxy(old_nsproxy);
22887 +       if (!nsproxy)
22888 +               goto out;
22889 +
22890 +       if (mask & CLONE_NEWNS) {
22891 +               old_ns = nsproxy->mnt_ns;
22892 +               nsproxy->mnt_ns = new_nsproxy->mnt_ns;
22893 +               if (nsproxy->mnt_ns)
22894 +                       get_mnt_ns(nsproxy->mnt_ns);
22895 +       } else
22896 +               old_ns = NULL;
22897 +
22898 +       if (mask & CLONE_NEWUTS) {
22899 +               old_uts = nsproxy->uts_ns;
22900 +               nsproxy->uts_ns = new_nsproxy->uts_ns;
22901 +               if (nsproxy->uts_ns)
22902 +                       get_uts_ns(nsproxy->uts_ns);
22903 +       } else
22904 +               old_uts = NULL;
22905 +
22906 +       if (mask & CLONE_NEWIPC) {
22907 +               old_ipc = nsproxy->ipc_ns;
22908 +               nsproxy->ipc_ns = new_nsproxy->ipc_ns;
22909 +               if (nsproxy->ipc_ns)
22910 +                       get_ipc_ns(nsproxy->ipc_ns);
22911 +       } else
22912 +               old_ipc = NULL;
22913 +
22914 +#ifdef CONFIG_PID_NS
22915 +       if (mask & CLONE_NEWPID) {
22916 +               old_pid = nsproxy->pid_ns;
22917 +               nsproxy->pid_ns = new_nsproxy->pid_ns;
22918 +               if (nsproxy->pid_ns)
22919 +                       get_pid_ns(nsproxy->pid_ns);
22920 +       } else
22921 +               old_pid = NULL;
22922 +#endif
22923 +#ifdef CONFIG_NET_NS
22924 +       if (mask & CLONE_NEWNET) {
22925 +               old_net = nsproxy->net_ns;
22926 +               nsproxy->net_ns = new_nsproxy->net_ns;
22927 +               if (nsproxy->net_ns)
22928 +                       get_net(nsproxy->net_ns);
22929 +       } else
22930 +               old_net = NULL;
22931 +#endif
22932 +       if (old_ns)
22933 +               put_mnt_ns(old_ns);
22934 +       if (old_uts)
22935 +               put_uts_ns(old_uts);
22936 +       if (old_ipc)
22937 +               put_ipc_ns(old_ipc);
22938 +#ifdef CONFIG_PID_NS
22939 +       if (old_pid)
22940 +               put_pid_ns(old_pid);
22941 +#endif
22942 +#ifdef CONFIG_NET_NS
22943 +       if (old_net)
22944 +               put_net(old_net);
22945 +#endif
22946 +out:
22947 +       return nsproxy;
22948 +}
22949 +
22950 +
22951 +/*
22952 + *     merge two nsproxy structs into a new one.
22953 + *     will hold a reference on the result.
22954 + */
22955 +
22956 +static inline
22957 +struct nsproxy *__vs_merge_nsproxy(struct nsproxy *old,
22958 +       struct nsproxy *proxy, unsigned long mask)
22959 +{
22960 +       struct nsproxy null_proxy = { .mnt_ns = NULL };
22961 +
22962 +       if (!proxy)
22963 +               return NULL;
22964 +
22965 +       if (mask) {
22966 +               /* vs_mix_nsproxy returns with reference */
22967 +               return vs_mix_nsproxy(old ? old : &null_proxy,
22968 +                       proxy, mask);
22969 +       }
22970 +       get_nsproxy(proxy);
22971 +       return proxy;
22972 +}
22973 +
22974 +
22975 +int vx_enter_space(struct vx_info *vxi, unsigned long mask, unsigned index)
22976 +{
22977 +       struct nsproxy *proxy, *proxy_cur, *proxy_new;
22978 +       struct fs_struct *fs_cur, *fs = NULL;
22979 +       struct _vx_space *space;
22980 +       int ret, kill = 0;
22981 +
22982 +       vxdprintk(VXD_CBIT(space, 8), "vx_enter_space(%p[#%u],0x%08lx,%d)",
22983 +               vxi, vxi->vx_id, mask, index);
22984 +
22985 +       if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0))
22986 +               return -EACCES;
22987 +
22988 +       if (index >= VX_SPACES)
22989 +               return -EINVAL;
22990 +
22991 +       space = &vxi->space[index];
22992 +
22993 +       if (!mask)
22994 +               mask = space->vx_nsmask;
22995 +
22996 +       if ((mask & space->vx_nsmask) != mask)
22997 +               return -EINVAL;
22998 +
22999 +       if (mask & CLONE_FS) {
23000 +               fs = copy_fs_struct(space->vx_fs);
23001 +               if (!fs)
23002 +                       return -ENOMEM;
23003 +       }
23004 +       proxy = space->vx_nsproxy;
23005 +
23006 +       vxdprintk(VXD_CBIT(space, 9),
23007 +               "vx_enter_space(%p[#%u],0x%08lx,%d) -> (%p,%p)",
23008 +               vxi, vxi->vx_id, mask, index, proxy, fs);
23009 +
23010 +       task_lock(current);
23011 +       fs_cur = current->fs;
23012 +
23013 +       if (mask & CLONE_FS) {
23014 +               spin_lock(&fs_cur->lock);
23015 +               current->fs = fs;
23016 +               kill = !--fs_cur->users;
23017 +               spin_unlock(&fs_cur->lock);
23018 +       }
23019 +
23020 +       proxy_cur = current->nsproxy;
23021 +       get_nsproxy(proxy_cur);
23022 +       task_unlock(current);
23023 +
23024 +       if (kill)
23025 +               free_fs_struct(fs_cur);
23026 +
23027 +       proxy_new = __vs_merge_nsproxy(proxy_cur, proxy, mask);
23028 +       if (IS_ERR(proxy_new)) {
23029 +               ret = PTR_ERR(proxy_new);
23030 +               goto out_put;
23031 +       }
23032 +
23033 +       proxy_new = xchg(&current->nsproxy, proxy_new);
23034 +
23035 +       if (mask & CLONE_NEWUSER) {
23036 +               struct cred *cred;
23037 +
23038 +               vxdprintk(VXD_CBIT(space, 10),
23039 +                       "vx_enter_space(%p[#%u],%p) cred (%p,%p)",
23040 +                       vxi, vxi->vx_id, space->vx_cred,
23041 +                       current->real_cred, current->cred);
23042 +
23043 +               if (space->vx_cred) {
23044 +                       cred = __prepare_creds(space->vx_cred);
23045 +                       if (cred)
23046 +                               commit_creds(cred);
23047 +               }
23048 +       }
23049 +
23050 +       ret = 0;
23051 +
23052 +       if (proxy_new)
23053 +               put_nsproxy(proxy_new);
23054 +out_put:
23055 +       if (proxy_cur)
23056 +               put_nsproxy(proxy_cur);
23057 +       return ret;
23058 +}
23059 +
23060 +
23061 +int vx_set_space(struct vx_info *vxi, unsigned long mask, unsigned index)
23062 +{
23063 +       struct nsproxy *proxy_vxi, *proxy_cur, *proxy_new;
23064 +       struct fs_struct *fs_vxi, *fs;
23065 +       struct _vx_space *space;
23066 +       int ret, kill = 0;
23067 +
23068 +       vxdprintk(VXD_CBIT(space, 8), "vx_set_space(%p[#%u],0x%08lx,%d)",
23069 +               vxi, vxi->vx_id, mask, index);
23070 +
23071 +       if ((mask & space_mask.mask) != mask)
23072 +               return -EINVAL;
23073 +
23074 +       if (index >= VX_SPACES)
23075 +               return -EINVAL;
23076 +
23077 +       space = &vxi->space[index];
23078 +
23079 +       proxy_vxi = space->vx_nsproxy;
23080 +       fs_vxi = space->vx_fs;
23081 +
23082 +       if (mask & CLONE_FS) {
23083 +               fs = copy_fs_struct(current->fs);
23084 +               if (!fs)
23085 +                       return -ENOMEM;
23086 +       }
23087 +
23088 +       task_lock(current);
23089 +
23090 +       if (mask & CLONE_FS) {
23091 +               spin_lock(&fs_vxi->lock);
23092 +               space->vx_fs = fs;
23093 +               kill = !--fs_vxi->users;
23094 +               spin_unlock(&fs_vxi->lock);
23095 +       }
23096 +
23097 +       proxy_cur = current->nsproxy;
23098 +       get_nsproxy(proxy_cur);
23099 +       task_unlock(current);
23100 +
23101 +       if (kill)
23102 +               free_fs_struct(fs_vxi);
23103 +
23104 +       proxy_new = __vs_merge_nsproxy(proxy_vxi, proxy_cur, mask);
23105 +       if (IS_ERR(proxy_new)) {
23106 +               ret = PTR_ERR(proxy_new);
23107 +               goto out_put;
23108 +       }
23109 +
23110 +       proxy_new = xchg(&space->vx_nsproxy, proxy_new);
23111 +       space->vx_nsmask |= mask;
23112 +
23113 +       if (mask & CLONE_NEWUSER) {
23114 +               struct cred *cred;
23115 +
23116 +               vxdprintk(VXD_CBIT(space, 10),
23117 +                       "vx_set_space(%p[#%u],%p) cred (%p,%p)",
23118 +                       vxi, vxi->vx_id, space->vx_cred,
23119 +                       current->real_cred, current->cred);
23120 +
23121 +               cred = prepare_creds();
23122 +               cred = (struct cred *)xchg(&space->vx_cred, cred);
23123 +               if (cred)
23124 +                       abort_creds(cred);
23125 +       }
23126 +
23127 +       ret = 0;
23128 +
23129 +       if (proxy_new)
23130 +               put_nsproxy(proxy_new);
23131 +out_put:
23132 +       if (proxy_cur)
23133 +               put_nsproxy(proxy_cur);
23134 +       return ret;
23135 +}
23136 +
23137 +
23138 +int vc_enter_space_v1(struct vx_info *vxi, void __user *data)
23139 +{
23140 +       struct vcmd_space_mask_v1 vc_data = { .mask = 0 };
23141 +
23142 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
23143 +               return -EFAULT;
23144 +
23145 +       return vx_enter_space(vxi, vc_data.mask, 0);
23146 +}
23147 +
23148 +int vc_enter_space(struct vx_info *vxi, void __user *data)
23149 +{
23150 +       struct vcmd_space_mask_v2 vc_data = { .mask = 0 };
23151 +
23152 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
23153 +               return -EFAULT;
23154 +
23155 +       if (vc_data.index >= VX_SPACES)
23156 +               return -EINVAL;
23157 +
23158 +       return vx_enter_space(vxi, vc_data.mask, vc_data.index);
23159 +}
23160 +
23161 +int vc_set_space_v1(struct vx_info *vxi, void __user *data)
23162 +{
23163 +       struct vcmd_space_mask_v1 vc_data = { .mask = 0 };
23164 +
23165 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
23166 +               return -EFAULT;
23167 +
23168 +       return vx_set_space(vxi, vc_data.mask, 0);
23169 +}
23170 +
23171 +int vc_set_space(struct vx_info *vxi, void __user *data)
23172 +{
23173 +       struct vcmd_space_mask_v2 vc_data = { .mask = 0 };
23174 +
23175 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
23176 +               return -EFAULT;
23177 +
23178 +       if (vc_data.index >= VX_SPACES)
23179 +               return -EINVAL;
23180 +
23181 +       return vx_set_space(vxi, vc_data.mask, vc_data.index);
23182 +}
23183 +
23184 +int vc_get_space_mask(void __user *data, int type)
23185 +{
23186 +       const struct vcmd_space_mask_v1 *mask;
23187 +
23188 +       if (type == 0)
23189 +               mask = &space_mask_v0;
23190 +       else if (type == 1)
23191 +               mask = &space_mask;
23192 +       else
23193 +               mask = &default_space_mask;
23194 +
23195 +       vxdprintk(VXD_CBIT(space, 10),
23196 +               "vc_get_space_mask(%d) = %08llx", type, mask->mask);
23197 +
23198 +       if (copy_to_user(data, mask, sizeof(*mask)))
23199 +               return -EFAULT;
23200 +       return 0;
23201 +}
23202 +
23203 diff -NurpP --minimal linux-3.0.25/kernel/vserver/switch.c linux-3.0.25-vs2.3.2.3/kernel/vserver/switch.c
23204 --- linux-3.0.25/kernel/vserver/switch.c        1970-01-01 01:00:00.000000000 +0100
23205 +++ linux-3.0.25-vs2.3.2.3/kernel/vserver/switch.c      2011-08-01 18:28:26.000000000 +0200
23206 @@ -0,0 +1,556 @@
23207 +/*
23208 + *  linux/kernel/vserver/switch.c
23209 + *
23210 + *  Virtual Server: Syscall Switch
23211 + *
23212 + *  Copyright (C) 2003-2011  Herbert Pötzl
23213 + *
23214 + *  V0.01  syscall switch
23215 + *  V0.02  added signal to context
23216 + *  V0.03  added rlimit functions
23217 + *  V0.04  added iattr, task/xid functions
23218 + *  V0.05  added debug/history stuff
23219 + *  V0.06  added compat32 layer
23220 + *  V0.07  vcmd args and perms
23221 + *  V0.08  added status commands
23222 + *  V0.09  added tag commands
23223 + *  V0.10  added oom bias
23224 + *  V0.11  added device commands
23225 + *  V0.12  added warn mask
23226 + *
23227 + */
23228 +
23229 +#include <linux/vs_context.h>
23230 +#include <linux/vs_network.h>
23231 +#include <linux/vserver/switch.h>
23232 +
23233 +#include "vci_config.h"
23234 +
23235 +
23236 +static inline
23237 +int vc_get_version(uint32_t id)
23238 +{
23239 +       return VCI_VERSION;
23240 +}
23241 +
23242 +static inline
23243 +int vc_get_vci(uint32_t id)
23244 +{
23245 +       return vci_kernel_config();
23246 +}
23247 +
23248 +#include <linux/vserver/context_cmd.h>
23249 +#include <linux/vserver/cvirt_cmd.h>
23250 +#include <linux/vserver/cacct_cmd.h>
23251 +#include <linux/vserver/limit_cmd.h>
23252 +#include <linux/vserver/network_cmd.h>
23253 +#include <linux/vserver/sched_cmd.h>
23254 +#include <linux/vserver/debug_cmd.h>
23255 +#include <linux/vserver/inode_cmd.h>
23256 +#include <linux/vserver/dlimit_cmd.h>
23257 +#include <linux/vserver/signal_cmd.h>
23258 +#include <linux/vserver/space_cmd.h>
23259 +#include <linux/vserver/tag_cmd.h>
23260 +#include <linux/vserver/device_cmd.h>
23261 +
23262 +#include <linux/vserver/inode.h>
23263 +#include <linux/vserver/dlimit.h>
23264 +
23265 +
23266 +#ifdef CONFIG_COMPAT
23267 +#define __COMPAT(name, id, data, compat)       \
23268 +       (compat) ? name ## _x32(id, data) : name(id, data)
23269 +#define __COMPAT_NO_ID(name, data, compat)     \
23270 +       (compat) ? name ## _x32(data) : name(data)
23271 +#else
23272 +#define __COMPAT(name, id, data, compat)       \
23273 +       name(id, data)
23274 +#define __COMPAT_NO_ID(name, data, compat)     \
23275 +       name(data)
23276 +#endif
23277 +
23278 +
23279 +static inline
23280 +long do_vcmd(uint32_t cmd, uint32_t id,
23281 +       struct vx_info *vxi, struct nx_info *nxi,
23282 +       void __user *data, int compat)
23283 +{
23284 +       switch (cmd) {
23285 +
23286 +       case VCMD_get_version:
23287 +               return vc_get_version(id);
23288 +       case VCMD_get_vci:
23289 +               return vc_get_vci(id);
23290 +
23291 +       case VCMD_task_xid:
23292 +               return vc_task_xid(id);
23293 +       case VCMD_vx_info:
23294 +               return vc_vx_info(vxi, data);
23295 +
23296 +       case VCMD_task_nid:
23297 +               return vc_task_nid(id);
23298 +       case VCMD_nx_info:
23299 +               return vc_nx_info(nxi, data);
23300 +
23301 +       case VCMD_task_tag:
23302 +               return vc_task_tag(id);
23303 +
23304 +       case VCMD_set_space_v1:
23305 +               return vc_set_space_v1(vxi, data);
23306 +       /* this is version 2 */
23307 +       case VCMD_set_space:
23308 +               return vc_set_space(vxi, data);
23309 +
23310 +       case VCMD_get_space_mask_v0:
23311 +               return vc_get_space_mask(data, 0);
23312 +       /* this is version 1 */
23313 +       case VCMD_get_space_mask:
23314 +               return vc_get_space_mask(data, 1);
23315 +
23316 +       case VCMD_get_space_default:
23317 +               return vc_get_space_mask(data, -1);
23318 +
23319 +       case VCMD_set_umask:
23320 +               return vc_set_umask(vxi, data);
23321 +
23322 +       case VCMD_get_umask:
23323 +               return vc_get_umask(vxi, data);
23324 +
23325 +       case VCMD_set_wmask:
23326 +               return vc_set_wmask(vxi, data);
23327 +
23328 +       case VCMD_get_wmask:
23329 +               return vc_get_wmask(vxi, data);
23330 +#ifdef CONFIG_IA32_EMULATION
23331 +       case VCMD_get_rlimit:
23332 +               return __COMPAT(vc_get_rlimit, vxi, data, compat);
23333 +       case VCMD_set_rlimit:
23334 +               return __COMPAT(vc_set_rlimit, vxi, data, compat);
23335 +#else
23336 +       case VCMD_get_rlimit:
23337 +               return vc_get_rlimit(vxi, data);
23338 +       case VCMD_set_rlimit:
23339 +               return vc_set_rlimit(vxi, data);
23340 +#endif
23341 +       case VCMD_get_rlimit_mask:
23342 +               return vc_get_rlimit_mask(id, data);
23343 +       case VCMD_reset_hits:
23344 +               return vc_reset_hits(vxi, data);
23345 +       case VCMD_reset_minmax:
23346 +               return vc_reset_minmax(vxi, data);
23347 +
23348 +       case VCMD_get_vhi_name:
23349 +               return vc_get_vhi_name(vxi, data);
23350 +       case VCMD_set_vhi_name:
23351 +               return vc_set_vhi_name(vxi, data);
23352 +
23353 +       case VCMD_ctx_stat:
23354 +               return vc_ctx_stat(vxi, data);
23355 +       case VCMD_virt_stat:
23356 +               return vc_virt_stat(vxi, data);
23357 +       case VCMD_sock_stat:
23358 +               return vc_sock_stat(vxi, data);
23359 +       case VCMD_rlimit_stat:
23360 +               return vc_rlimit_stat(vxi, data);
23361 +
23362 +       case VCMD_set_cflags:
23363 +               return vc_set_cflags(vxi, data);
23364 +       case VCMD_get_cflags:
23365 +               return vc_get_cflags(vxi, data);
23366 +
23367 +       /* this is version 1 */
23368 +       case VCMD_set_ccaps:
23369 +               return vc_set_ccaps(vxi, data);
23370 +       /* this is version 1 */
23371 +       case VCMD_get_ccaps:
23372 +               return vc_get_ccaps(vxi, data);
23373 +       case VCMD_set_bcaps:
23374 +               return vc_set_bcaps(vxi, data);
23375 +       case VCMD_get_bcaps:
23376 +               return vc_get_bcaps(vxi, data);
23377 +
23378 +       case VCMD_set_badness:
23379 +               return vc_set_badness(vxi, data);
23380 +       case VCMD_get_badness:
23381 +               return vc_get_badness(vxi, data);
23382 +
23383 +       case VCMD_set_nflags:
23384 +               return vc_set_nflags(nxi, data);
23385 +       case VCMD_get_nflags:
23386 +               return vc_get_nflags(nxi, data);
23387 +
23388 +       case VCMD_set_ncaps:
23389 +               return vc_set_ncaps(nxi, data);
23390 +       case VCMD_get_ncaps:
23391 +               return vc_get_ncaps(nxi, data);
23392 +
23393 +       case VCMD_set_prio_bias:
23394 +               return vc_set_prio_bias(vxi, data);
23395 +       case VCMD_get_prio_bias:
23396 +               return vc_get_prio_bias(vxi, data);
23397 +       case VCMD_add_dlimit:
23398 +               return __COMPAT(vc_add_dlimit, id, data, compat);
23399 +       case VCMD_rem_dlimit:
23400 +               return __COMPAT(vc_rem_dlimit, id, data, compat);
23401 +       case VCMD_set_dlimit:
23402 +               return __COMPAT(vc_set_dlimit, id, data, compat);
23403 +       case VCMD_get_dlimit:
23404 +               return __COMPAT(vc_get_dlimit, id, data, compat);
23405 +
23406 +       case VCMD_ctx_kill:
23407 +               return vc_ctx_kill(vxi, data);
23408 +
23409 +       case VCMD_wait_exit:
23410 +               return vc_wait_exit(vxi, data);
23411 +
23412 +       case VCMD_get_iattr:
23413 +               return __COMPAT_NO_ID(vc_get_iattr, data, compat);
23414 +       case VCMD_set_iattr:
23415 +               return __COMPAT_NO_ID(vc_set_iattr, data, compat);
23416 +
23417 +       case VCMD_fget_iattr:
23418 +               return vc_fget_iattr(id, data);
23419 +       case VCMD_fset_iattr:
23420 +               return vc_fset_iattr(id, data);
23421 +
23422 +       case VCMD_enter_space_v0:
23423 +               return vc_enter_space_v1(vxi, NULL);
23424 +       case VCMD_enter_space_v1:
23425 +               return vc_enter_space_v1(vxi, data);
23426 +       /* this is version 2 */
23427 +       case VCMD_enter_space:
23428 +               return vc_enter_space(vxi, data);
23429 +
23430 +       case VCMD_ctx_create_v0:
23431 +               return vc_ctx_create(id, NULL);
23432 +       case VCMD_ctx_create:
23433 +               return vc_ctx_create(id, data);
23434 +       case VCMD_ctx_migrate_v0:
23435 +               return vc_ctx_migrate(vxi, NULL);
23436 +       case VCMD_ctx_migrate:
23437 +               return vc_ctx_migrate(vxi, data);
23438 +
23439 +       case VCMD_net_create_v0:
23440 +               return vc_net_create(id, NULL);
23441 +       case VCMD_net_create:
23442 +               return vc_net_create(id, data);
23443 +       case VCMD_net_migrate:
23444 +               return vc_net_migrate(nxi, data);
23445 +
23446 +       case VCMD_tag_migrate:
23447 +               return vc_tag_migrate(id);
23448 +
23449 +       case VCMD_net_add:
23450 +               return vc_net_add(nxi, data);
23451 +       case VCMD_net_remove:
23452 +               return vc_net_remove(nxi, data);
23453 +
23454 +       case VCMD_net_add_ipv4_v1:
23455 +               return vc_net_add_ipv4_v1(nxi, data);
23456 +       /* this is version 2 */
23457 +       case VCMD_net_add_ipv4:
23458 +               return vc_net_add_ipv4(nxi, data);
23459 +
23460 +       case VCMD_net_rem_ipv4_v1:
23461 +               return vc_net_rem_ipv4_v1(nxi, data);
23462 +       /* this is version 2 */
23463 +       case VCMD_net_rem_ipv4:
23464 +               return vc_net_rem_ipv4(nxi, data);
23465 +#ifdef CONFIG_IPV6
23466 +       case VCMD_net_add_ipv6:
23467 +               return vc_net_add_ipv6(nxi, data);
23468 +       case VCMD_net_remove_ipv6:
23469 +               return vc_net_remove_ipv6(nxi, data);
23470 +#endif
23471 +/*     case VCMD_add_match_ipv4:
23472 +               return vc_add_match_ipv4(nxi, data);
23473 +       case VCMD_get_match_ipv4:
23474 +               return vc_get_match_ipv4(nxi, data);
23475 +#ifdef CONFIG_IPV6
23476 +       case VCMD_add_match_ipv6:
23477 +               return vc_add_match_ipv6(nxi, data);
23478 +       case VCMD_get_match_ipv6:
23479 +               return vc_get_match_ipv6(nxi, data);
23480 +#endif */
23481 +
23482 +#ifdef CONFIG_VSERVER_DEVICE
23483 +       case VCMD_set_mapping:
23484 +               return __COMPAT(vc_set_mapping, vxi, data, compat);
23485 +       case VCMD_unset_mapping:
23486 +               return __COMPAT(vc_unset_mapping, vxi, data, compat);
23487 +#endif
23488 +#ifdef CONFIG_VSERVER_HISTORY
23489 +       case VCMD_dump_history:
23490 +               return vc_dump_history(id);
23491 +       case VCMD_read_history:
23492 +               return __COMPAT(vc_read_history, id, data, compat);
23493 +#endif
23494 +       default:
23495 +               vxwprintk_task(1, "unimplemented VCMD_%02d_%d[%d]",
23496 +                       VC_CATEGORY(cmd), VC_COMMAND(cmd), VC_VERSION(cmd));
23497 +       }
23498 +       return -ENOSYS;
23499 +}
23500 +
23501 +
23502 +#define        __VCMD(vcmd, _perm, _args, _flags)              \
23503 +       case VCMD_ ## vcmd: perm = _perm;               \
23504 +               args = _args; flags = _flags; break
23505 +
23506 +
23507 +#define VCA_NONE       0x00
23508 +#define VCA_VXI                0x01
23509 +#define VCA_NXI                0x02
23510 +
23511 +#define VCF_NONE       0x00
23512 +#define VCF_INFO       0x01
23513 +#define VCF_ADMIN      0x02
23514 +#define VCF_ARES       0x06    /* includes admin */
23515 +#define VCF_SETUP      0x08
23516 +
23517 +#define VCF_ZIDOK      0x10    /* zero id okay */
23518 +
23519 +
23520 +static inline
23521 +long do_vserver(uint32_t cmd, uint32_t id, void __user *data, int compat)
23522 +{
23523 +       long ret;
23524 +       int permit = -1, state = 0;
23525 +       int perm = -1, args = 0, flags = 0;
23526 +       struct vx_info *vxi = NULL;
23527 +       struct nx_info *nxi = NULL;
23528 +
23529 +       switch (cmd) {
23530 +       /* unpriviledged commands */
23531 +       __VCMD(get_version,      0, VCA_NONE,   0);
23532 +       __VCMD(get_vci,          0, VCA_NONE,   0);
23533 +       __VCMD(get_rlimit_mask,  0, VCA_NONE,   0);
23534 +       __VCMD(get_space_mask_v0,0, VCA_NONE,   0);
23535 +       __VCMD(get_space_mask,   0, VCA_NONE,   0);
23536 +       __VCMD(get_space_default,0, VCA_NONE,   0);
23537 +
23538 +       /* info commands */
23539 +       __VCMD(task_xid,         2, VCA_NONE,   0);
23540 +       __VCMD(reset_hits,       2, VCA_VXI,    0);
23541 +       __VCMD(reset_minmax,     2, VCA_VXI,    0);
23542 +       __VCMD(vx_info,          3, VCA_VXI,    VCF_INFO);
23543 +       __VCMD(get_bcaps,        3, VCA_VXI,    VCF_INFO);
23544 +       __VCMD(get_ccaps,        3, VCA_VXI,    VCF_INFO);
23545 +       __VCMD(get_cflags,       3, VCA_VXI,    VCF_INFO);
23546 +       __VCMD(get_umask,        3, VCA_VXI,    VCF_INFO);
23547 +       __VCMD(get_wmask,        3, VCA_VXI,    VCF_INFO);
23548 +       __VCMD(get_badness,      3, VCA_VXI,    VCF_INFO);
23549 +       __VCMD(get_vhi_name,     3, VCA_VXI,    VCF_INFO);
23550 +       __VCMD(get_rlimit,       3, VCA_VXI,    VCF_INFO);
23551 +
23552 +       __VCMD(ctx_stat,         3, VCA_VXI,    VCF_INFO);
23553 +       __VCMD(virt_stat,        3, VCA_VXI,    VCF_INFO);
23554 +       __VCMD(sock_stat,        3, VCA_VXI,    VCF_INFO);
23555 +       __VCMD(rlimit_stat,      3, VCA_VXI,    VCF_INFO);
23556 +
23557 +       __VCMD(task_nid,         2, VCA_NONE,   0);
23558 +       __VCMD(nx_info,          3, VCA_NXI,    VCF_INFO);
23559 +       __VCMD(get_ncaps,        3, VCA_NXI,    VCF_INFO);
23560 +       __VCMD(get_nflags,       3, VCA_NXI,    VCF_INFO);
23561 +
23562 +       __VCMD(task_tag,         2, VCA_NONE,   0);
23563 +
23564 +       __VCMD(get_iattr,        2, VCA_NONE,   0);
23565 +       __VCMD(fget_iattr,       2, VCA_NONE,   0);
23566 +       __VCMD(get_dlimit,       3, VCA_NONE,   VCF_INFO);
23567 +       __VCMD(get_prio_bias,    3, VCA_VXI,    VCF_INFO);
23568 +
23569 +       /* lower admin commands */
23570 +       __VCMD(wait_exit,        4, VCA_VXI,    VCF_INFO);
23571 +       __VCMD(ctx_create_v0,    5, VCA_NONE,   0);
23572 +       __VCMD(ctx_create,       5, VCA_NONE,   0);
23573 +       __VCMD(ctx_migrate_v0,   5, VCA_VXI,    VCF_ADMIN);
23574 +       __VCMD(ctx_migrate,      5, VCA_VXI,    VCF_ADMIN);
23575 +       __VCMD(enter_space_v0,   5, VCA_VXI,    VCF_ADMIN);
23576 +       __VCMD(enter_space_v1,   5, VCA_VXI,    VCF_ADMIN);
23577 +       __VCMD(enter_space,      5, VCA_VXI,    VCF_ADMIN);
23578 +
23579 +       __VCMD(net_create_v0,    5, VCA_NONE,   0);
23580 +       __VCMD(net_create,       5, VCA_NONE,   0);
23581 +       __VCMD(net_migrate,      5, VCA_NXI,    VCF_ADMIN);
23582 +
23583 +       __VCMD(tag_migrate,      5, VCA_NONE,   VCF_ADMIN);
23584 +
23585 +       /* higher admin commands */
23586 +       __VCMD(ctx_kill,         6, VCA_VXI,    VCF_ARES);
23587 +       __VCMD(set_space_v1,     7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23588 +       __VCMD(set_space,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23589 +
23590 +       __VCMD(set_ccaps,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23591 +       __VCMD(set_bcaps,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23592 +       __VCMD(set_cflags,       7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23593 +       __VCMD(set_umask,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23594 +       __VCMD(set_wmask,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23595 +       __VCMD(set_badness,      7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23596 +
23597 +       __VCMD(set_vhi_name,     7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23598 +       __VCMD(set_rlimit,       7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23599 +       __VCMD(set_prio_bias,    7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23600 +
23601 +       __VCMD(set_ncaps,        7, VCA_NXI,    VCF_ARES | VCF_SETUP);
23602 +       __VCMD(set_nflags,       7, VCA_NXI,    VCF_ARES | VCF_SETUP);
23603 +       __VCMD(net_add,          8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23604 +       __VCMD(net_remove,       8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23605 +       __VCMD(net_add_ipv4_v1,  8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23606 +       __VCMD(net_rem_ipv4_v1,  8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23607 +       __VCMD(net_add_ipv4,     8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23608 +       __VCMD(net_rem_ipv4,     8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23609 +#ifdef CONFIG_IPV6
23610 +       __VCMD(net_add_ipv6,     8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23611 +       __VCMD(net_remove_ipv6,  8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23612 +#endif
23613 +       __VCMD(set_iattr,        7, VCA_NONE,   0);
23614 +       __VCMD(fset_iattr,       7, VCA_NONE,   0);
23615 +       __VCMD(set_dlimit,       7, VCA_NONE,   VCF_ARES);
23616 +       __VCMD(add_dlimit,       8, VCA_NONE,   VCF_ARES);
23617 +       __VCMD(rem_dlimit,       8, VCA_NONE,   VCF_ARES);
23618 +
23619 +#ifdef CONFIG_VSERVER_DEVICE
23620 +       __VCMD(set_mapping,      8, VCA_VXI,    VCF_ARES|VCF_ZIDOK);
23621 +       __VCMD(unset_mapping,    8, VCA_VXI,    VCF_ARES|VCF_ZIDOK);
23622 +#endif
23623 +       /* debug level admin commands */
23624 +#ifdef CONFIG_VSERVER_HISTORY
23625 +       __VCMD(dump_history,     9, VCA_NONE,   0);
23626 +       __VCMD(read_history,     9, VCA_NONE,   0);
23627 +#endif
23628 +
23629 +       default:
23630 +               perm = -1;
23631 +       }
23632 +
23633 +       vxdprintk(VXD_CBIT(switch, 0),
23634 +               "vc: VCMD_%02d_%d[%d], %d,%p [%d,%d,%x,%x]",
23635 +               VC_CATEGORY(cmd), VC_COMMAND(cmd),
23636 +               VC_VERSION(cmd), id, data, compat,
23637 +               perm, args, flags);
23638 +
23639 +       ret = -ENOSYS;
23640 +       if (perm < 0)
23641 +               goto out;
23642 +
23643 +       state = 1;
23644 +       if (!capable(CAP_CONTEXT))
23645 +               goto out;
23646 +
23647 +       state = 2;
23648 +       /* moved here from the individual commands */
23649 +       ret = -EPERM;
23650 +       if ((perm > 1) && !capable(CAP_SYS_ADMIN))
23651 +               goto out;
23652 +
23653 +       state = 3;
23654 +       /* vcmd involves resource management  */
23655 +       ret = -EPERM;
23656 +       if ((flags & VCF_ARES) && !capable(CAP_SYS_RESOURCE))
23657 +               goto out;
23658 +
23659 +       state = 4;
23660 +       /* various legacy exceptions */
23661 +       switch (cmd) {
23662 +       /* will go away when spectator is a cap */
23663 +       case VCMD_ctx_migrate_v0:
23664 +       case VCMD_ctx_migrate:
23665 +               if (id == 1) {
23666 +                       current->xid = 1;
23667 +                       ret = 1;
23668 +                       goto out;
23669 +               }
23670 +               break;
23671 +
23672 +       /* will go away when spectator is a cap */
23673 +       case VCMD_net_migrate:
23674 +               if (id == 1) {
23675 +                       current->nid = 1;
23676 +                       ret = 1;
23677 +                       goto out;
23678 +               }
23679 +               break;
23680 +       }
23681 +
23682 +       /* vcmds are fine by default */
23683 +       permit = 1;
23684 +
23685 +       /* admin type vcmds require admin ... */
23686 +       if (flags & VCF_ADMIN)
23687 +               permit = vx_check(0, VS_ADMIN) ? 1 : 0;
23688 +
23689 +       /* ... but setup type vcmds override that */
23690 +       if (!permit && (flags & VCF_SETUP))
23691 +               permit = vx_flags(VXF_STATE_SETUP, 0) ? 2 : 0;
23692 +
23693 +       state = 5;
23694 +       ret = -EPERM;
23695 +       if (!permit)
23696 +               goto out;
23697 +
23698 +       state = 6;
23699 +       if (!id && (flags & VCF_ZIDOK))
23700 +               goto skip_id;
23701 +
23702 +       ret = -ESRCH;
23703 +       if (args & VCA_VXI) {
23704 +               vxi = lookup_vx_info(id);
23705 +               if (!vxi)
23706 +                       goto out;
23707 +
23708 +               if ((flags & VCF_ADMIN) &&
23709 +                       /* special case kill for shutdown */
23710 +                       (cmd != VCMD_ctx_kill) &&
23711 +                       /* can context be administrated? */
23712 +                       !vx_info_flags(vxi, VXF_STATE_ADMIN, 0)) {
23713 +                       ret = -EACCES;
23714 +                       goto out_vxi;
23715 +               }
23716 +       }
23717 +       state = 7;
23718 +       if (args & VCA_NXI) {
23719 +               nxi = lookup_nx_info(id);
23720 +               if (!nxi)
23721 +                       goto out_vxi;
23722 +
23723 +               if ((flags & VCF_ADMIN) &&
23724 +                       /* can context be administrated? */
23725 +                       !nx_info_flags(nxi, NXF_STATE_ADMIN, 0)) {
23726 +                       ret = -EACCES;
23727 +                       goto out_nxi;
23728 +               }
23729 +       }
23730 +skip_id:
23731 +       state = 8;
23732 +       ret = do_vcmd(cmd, id, vxi, nxi, data, compat);
23733 +
23734 +out_nxi:
23735 +       if ((args & VCA_NXI) && nxi)
23736 +               put_nx_info(nxi);
23737 +out_vxi:
23738 +       if ((args & VCA_VXI) && vxi)
23739 +               put_vx_info(vxi);
23740 +out:
23741 +       vxdprintk(VXD_CBIT(switch, 1),
23742 +               "vc: VCMD_%02d_%d[%d] = %08lx(%ld) [%d,%d]",
23743 +               VC_CATEGORY(cmd), VC_COMMAND(cmd),
23744 +               VC_VERSION(cmd), ret, ret, state, permit);
23745 +       return ret;
23746 +}
23747 +
23748 +asmlinkage long
23749 +sys_vserver(uint32_t cmd, uint32_t id, void __user *data)
23750 +{
23751 +       return do_vserver(cmd, id, data, 0);
23752 +}
23753 +
23754 +#ifdef CONFIG_COMPAT
23755 +
23756 +asmlinkage long
23757 +sys32_vserver(uint32_t cmd, uint32_t id, void __user *data)
23758 +{
23759 +       return do_vserver(cmd, id, data, 1);
23760 +}
23761 +
23762 +#endif /* CONFIG_COMPAT */
23763 diff -NurpP --minimal linux-3.0.25/kernel/vserver/sysctl.c linux-3.0.25-vs2.3.2.3/kernel/vserver/sysctl.c
23764 --- linux-3.0.25/kernel/vserver/sysctl.c        1970-01-01 01:00:00.000000000 +0100
23765 +++ linux-3.0.25-vs2.3.2.3/kernel/vserver/sysctl.c      2011-10-27 15:18:40.000000000 +0200
23766 @@ -0,0 +1,247 @@
23767 +/*
23768 + *  kernel/vserver/sysctl.c
23769 + *
23770 + *  Virtual Context Support
23771 + *
23772 + *  Copyright (C) 2004-2007  Herbert Pötzl
23773 + *
23774 + *  V0.01  basic structure
23775 + *
23776 + */
23777 +
23778 +#include <linux/module.h>
23779 +#include <linux/ctype.h>
23780 +#include <linux/sysctl.h>
23781 +#include <linux/parser.h>
23782 +#include <asm/uaccess.h>
23783 +
23784 +enum {
23785 +       CTL_DEBUG_ERROR         = 0,
23786 +       CTL_DEBUG_SWITCH        = 1,
23787 +       CTL_DEBUG_XID,
23788 +       CTL_DEBUG_NID,
23789 +       CTL_DEBUG_TAG,
23790 +       CTL_DEBUG_NET,
23791 +       CTL_DEBUG_LIMIT,
23792 +       CTL_DEBUG_CRES,
23793 +       CTL_DEBUG_DLIM,
23794 +       CTL_DEBUG_QUOTA,
23795 +       CTL_DEBUG_CVIRT,
23796 +       CTL_DEBUG_SPACE,
23797 +       CTL_DEBUG_PERM,
23798 +       CTL_DEBUG_MISC,
23799 +};
23800 +
23801 +
23802 +unsigned int vs_debug_switch   = 0;
23803 +unsigned int vs_debug_xid      = 0;
23804 +unsigned int vs_debug_nid      = 0;
23805 +unsigned int vs_debug_tag      = 0;
23806 +unsigned int vs_debug_net      = 0;
23807 +unsigned int vs_debug_limit    = 0;
23808 +unsigned int vs_debug_cres     = 0;
23809 +unsigned int vs_debug_dlim     = 0;
23810 +unsigned int vs_debug_quota    = 0;
23811 +unsigned int vs_debug_cvirt    = 0;
23812 +unsigned int vs_debug_space    = 0;
23813 +unsigned int vs_debug_perm     = 0;
23814 +unsigned int vs_debug_misc     = 0;
23815 +
23816 +
23817 +static struct ctl_table_header *vserver_table_header;
23818 +static ctl_table vserver_root_table[];
23819 +
23820 +
23821 +void vserver_register_sysctl(void)
23822 +{
23823 +       if (!vserver_table_header) {
23824 +               vserver_table_header = register_sysctl_table(vserver_root_table);
23825 +       }
23826 +
23827 +}
23828 +
23829 +void vserver_unregister_sysctl(void)
23830 +{
23831 +       if (vserver_table_header) {
23832 +               unregister_sysctl_table(vserver_table_header);
23833 +               vserver_table_header = NULL;
23834 +       }
23835 +}
23836 +
23837 +
23838 +static int proc_dodebug(ctl_table *table, int write,
23839 +       void __user *buffer, size_t *lenp, loff_t *ppos)
23840 +{
23841 +       char            tmpbuf[20], *p, c;
23842 +       unsigned int    value;
23843 +       size_t          left, len;
23844 +
23845 +       if ((*ppos && !write) || !*lenp) {
23846 +               *lenp = 0;
23847 +               return 0;
23848 +       }
23849 +
23850 +       left = *lenp;
23851 +
23852 +       if (write) {
23853 +               if (!access_ok(VERIFY_READ, buffer, left))
23854 +                       return -EFAULT;
23855 +               p = (char *)buffer;
23856 +               while (left && __get_user(c, p) >= 0 && isspace(c))
23857 +                       left--, p++;
23858 +               if (!left)
23859 +                       goto done;
23860 +
23861 +               if (left > sizeof(tmpbuf) - 1)
23862 +                       return -EINVAL;
23863 +               if (copy_from_user(tmpbuf, p, left))
23864 +                       return -EFAULT;
23865 +               tmpbuf[left] = '\0';
23866 +
23867 +               for (p = tmpbuf, value = 0; '0' <= *p && *p <= '9'; p++, left--)
23868 +                       value = 10 * value + (*p - '0');
23869 +               if (*p && !isspace(*p))
23870 +                       return -EINVAL;
23871 +               while (left && isspace(*p))
23872 +                       left--, p++;
23873 +               *(unsigned int *)table->data = value;
23874 +       } else {
23875 +               if (!access_ok(VERIFY_WRITE, buffer, left))
23876 +                       return -EFAULT;
23877 +               len = sprintf(tmpbuf, "%d", *(unsigned int *)table->data);
23878 +               if (len > left)
23879 +                       len = left;
23880 +               if (__copy_to_user(buffer, tmpbuf, len))
23881 +                       return -EFAULT;
23882 +               if ((left -= len) > 0) {
23883 +                       if (put_user('\n', (char *)buffer + len))
23884 +                               return -EFAULT;
23885 +                       left--;
23886 +               }
23887 +       }
23888 +
23889 +done:
23890 +       *lenp -= left;
23891 +       *ppos += *lenp;
23892 +       return 0;
23893 +}
23894 +
23895 +static int zero;
23896 +
23897 +#define        CTL_ENTRY(ctl, name)                            \
23898 +       {                                               \
23899 +               .procname       = #name,                \
23900 +               .data           = &vs_ ## name,         \
23901 +               .maxlen         = sizeof(int),          \
23902 +               .mode           = 0644,                 \
23903 +               .proc_handler   = &proc_dodebug,        \
23904 +               .extra1         = &zero,                \
23905 +               .extra2         = &zero,                \
23906 +       }
23907 +
23908 +static ctl_table vserver_debug_table[] = {
23909 +       CTL_ENTRY(CTL_DEBUG_SWITCH,     debug_switch),
23910 +       CTL_ENTRY(CTL_DEBUG_XID,        debug_xid),
23911 +       CTL_ENTRY(CTL_DEBUG_NID,        debug_nid),
23912 +       CTL_ENTRY(CTL_DEBUG_TAG,        debug_tag),
23913 +       CTL_ENTRY(CTL_DEBUG_NET,        debug_net),
23914 +       CTL_ENTRY(CTL_DEBUG_LIMIT,      debug_limit),
23915 +       CTL_ENTRY(CTL_DEBUG_CRES,       debug_cres),
23916 +       CTL_ENTRY(CTL_DEBUG_DLIM,       debug_dlim),
23917 +       CTL_ENTRY(CTL_DEBUG_QUOTA,      debug_quota),
23918 +       CTL_ENTRY(CTL_DEBUG_CVIRT,      debug_cvirt),
23919 +       CTL_ENTRY(CTL_DEBUG_SPACE,      debug_space),
23920 +       CTL_ENTRY(CTL_DEBUG_PERM,       debug_perm),
23921 +       CTL_ENTRY(CTL_DEBUG_MISC,       debug_misc),
23922 +       { 0 }
23923 +};
23924 +
23925 +static ctl_table vserver_root_table[] = {
23926 +       {
23927 +               .procname       = "vserver",
23928 +               .mode           = 0555,
23929 +               .child          = vserver_debug_table
23930 +       },
23931 +       { 0 }
23932 +};
23933 +
23934 +
23935 +static match_table_t tokens = {
23936 +       { CTL_DEBUG_SWITCH,     "switch=%x"     },
23937 +       { CTL_DEBUG_XID,        "xid=%x"        },
23938 +       { CTL_DEBUG_NID,        "nid=%x"        },
23939 +       { CTL_DEBUG_TAG,        "tag=%x"        },
23940 +       { CTL_DEBUG_NET,        "net=%x"        },
23941 +       { CTL_DEBUG_LIMIT,      "limit=%x"      },
23942 +       { CTL_DEBUG_CRES,       "cres=%x"       },
23943 +       { CTL_DEBUG_DLIM,       "dlim=%x"       },
23944 +       { CTL_DEBUG_QUOTA,      "quota=%x"      },
23945 +       { CTL_DEBUG_CVIRT,      "cvirt=%x"      },
23946 +       { CTL_DEBUG_SPACE,      "space=%x"      },
23947 +       { CTL_DEBUG_PERM,       "perm=%x"       },
23948 +       { CTL_DEBUG_MISC,       "misc=%x"       },
23949 +       { CTL_DEBUG_ERROR,      NULL            }
23950 +};
23951 +
23952 +#define        HANDLE_CASE(id, name, val)                              \
23953 +       case CTL_DEBUG_ ## id:                                  \
23954 +               vs_debug_ ## name = val;                        \
23955 +               printk("vs_debug_" #name "=0x%x\n", val);       \
23956 +               break
23957 +
23958 +
23959 +static int __init vs_debug_setup(char *str)
23960 +{
23961 +       char *p;
23962 +       int token;
23963 +
23964 +       printk("vs_debug_setup(%s)\n", str);
23965 +       while ((p = strsep(&str, ",")) != NULL) {
23966 +               substring_t args[MAX_OPT_ARGS];
23967 +               unsigned int value;
23968 +
23969 +               if (!*p)
23970 +                       continue;
23971 +
23972 +               token = match_token(p, tokens, args);
23973 +               value = (token > 0) ? simple_strtoul(args[0].from, NULL, 0) : 0;
23974 +
23975 +               switch (token) {
23976 +               HANDLE_CASE(SWITCH, switch, value);
23977 +               HANDLE_CASE(XID,    xid,    value);
23978 +               HANDLE_CASE(NID,    nid,    value);
23979 +               HANDLE_CASE(TAG,    tag,    value);
23980 +               HANDLE_CASE(NET,    net,    value);
23981 +               HANDLE_CASE(LIMIT,  limit,  value);
23982 +               HANDLE_CASE(CRES,   cres,   value);
23983 +               HANDLE_CASE(DLIM,   dlim,   value);
23984 +               HANDLE_CASE(QUOTA,  quota,  value);
23985 +               HANDLE_CASE(CVIRT,  cvirt,  value);
23986 +               HANDLE_CASE(SPACE,  space,  value);
23987 +               HANDLE_CASE(PERM,   perm,   value);
23988 +               HANDLE_CASE(MISC,   misc,   value);
23989 +               default:
23990 +                       return -EINVAL;
23991 +                       break;
23992 +               }
23993 +       }
23994 +       return 1;
23995 +}
23996 +
23997 +__setup("vsdebug=", vs_debug_setup);
23998 +
23999 +
24000 +
24001 +EXPORT_SYMBOL_GPL(vs_debug_switch);
24002 +EXPORT_SYMBOL_GPL(vs_debug_xid);
24003 +EXPORT_SYMBOL_GPL(vs_debug_nid);
24004 +EXPORT_SYMBOL_GPL(vs_debug_net);
24005 +EXPORT_SYMBOL_GPL(vs_debug_limit);
24006 +EXPORT_SYMBOL_GPL(vs_debug_cres);
24007 +EXPORT_SYMBOL_GPL(vs_debug_dlim);
24008 +EXPORT_SYMBOL_GPL(vs_debug_quota);
24009 +EXPORT_SYMBOL_GPL(vs_debug_cvirt);
24010 +EXPORT_SYMBOL_GPL(vs_debug_space);
24011 +EXPORT_SYMBOL_GPL(vs_debug_perm);
24012 +EXPORT_SYMBOL_GPL(vs_debug_misc);
24013 +
24014 diff -NurpP --minimal linux-3.0.25/kernel/vserver/tag.c linux-3.0.25-vs2.3.2.3/kernel/vserver/tag.c
24015 --- linux-3.0.25/kernel/vserver/tag.c   1970-01-01 01:00:00.000000000 +0100
24016 +++ linux-3.0.25-vs2.3.2.3/kernel/vserver/tag.c 2011-06-10 22:11:24.000000000 +0200
24017 @@ -0,0 +1,63 @@
24018 +/*
24019 + *  linux/kernel/vserver/tag.c
24020 + *
24021 + *  Virtual Server: Shallow Tag Space
24022 + *
24023 + *  Copyright (C) 2007  Herbert Pötzl
24024 + *
24025 + *  V0.01  basic implementation
24026 + *
24027 + */
24028 +
24029 +#include <linux/sched.h>
24030 +#include <linux/vserver/debug.h>
24031 +#include <linux/vs_pid.h>
24032 +#include <linux/vs_tag.h>
24033 +
24034 +#include <linux/vserver/tag_cmd.h>
24035 +
24036 +
24037 +int dx_migrate_task(struct task_struct *p, tag_t tag)
24038 +{
24039 +       if (!p)
24040 +               BUG();
24041 +
24042 +       vxdprintk(VXD_CBIT(tag, 5),
24043 +               "dx_migrate_task(%p[#%d],#%d)", p, p->tag, tag);
24044 +
24045 +       task_lock(p);
24046 +       p->tag = tag;
24047 +       task_unlock(p);
24048 +
24049 +       vxdprintk(VXD_CBIT(tag, 5),
24050 +               "moved task %p into [#%d]", p, tag);
24051 +       return 0;
24052 +}
24053 +
24054 +/* vserver syscall commands below here */
24055 +
24056 +/* taks xid and vx_info functions */
24057 +
24058 +
24059 +int vc_task_tag(uint32_t id)
24060 +{
24061 +       tag_t tag;
24062 +
24063 +       if (id) {
24064 +               struct task_struct *tsk;
24065 +               rcu_read_lock();
24066 +               tsk = find_task_by_real_pid(id);
24067 +               tag = (tsk) ? tsk->tag : -ESRCH;
24068 +               rcu_read_unlock();
24069 +       } else
24070 +               tag = dx_current_tag();
24071 +       return tag;
24072 +}
24073 +
24074 +
24075 +int vc_tag_migrate(uint32_t tag)
24076 +{
24077 +       return dx_migrate_task(current, tag & 0xFFFF);
24078 +}
24079 +
24080 +
24081 diff -NurpP --minimal linux-3.0.25/kernel/vserver/vci_config.h linux-3.0.25-vs2.3.2.3/kernel/vserver/vci_config.h
24082 --- linux-3.0.25/kernel/vserver/vci_config.h    1970-01-01 01:00:00.000000000 +0100
24083 +++ linux-3.0.25-vs2.3.2.3/kernel/vserver/vci_config.h  2011-06-10 22:11:24.000000000 +0200
24084 @@ -0,0 +1,76 @@
24085 +
24086 +/*  interface version */
24087 +
24088 +#define VCI_VERSION            0x00020308
24089 +
24090 +
24091 +enum {
24092 +       VCI_KCBIT_NO_DYNAMIC = 0,
24093 +
24094 +       VCI_KCBIT_PROC_SECURE = 4,
24095 +       /* VCI_KCBIT_HARDCPU = 5, */
24096 +       /* VCI_KCBIT_IDLELIMIT = 6, */
24097 +       /* VCI_KCBIT_IDLETIME = 7, */
24098 +
24099 +       VCI_KCBIT_COWBL = 8,
24100 +       VCI_KCBIT_FULLCOWBL = 9,
24101 +       VCI_KCBIT_SPACES = 10,
24102 +       VCI_KCBIT_NETV2 = 11,
24103 +       VCI_KCBIT_MEMCG = 12,
24104 +
24105 +       VCI_KCBIT_DEBUG = 16,
24106 +       VCI_KCBIT_HISTORY = 20,
24107 +       VCI_KCBIT_TAGGED = 24,
24108 +       VCI_KCBIT_PPTAG = 28,
24109 +
24110 +       VCI_KCBIT_MORE = 31,
24111 +};
24112 +
24113 +
24114 +static inline uint32_t vci_kernel_config(void)
24115 +{
24116 +       return
24117 +       (1 << VCI_KCBIT_NO_DYNAMIC) |
24118 +
24119 +       /* configured features */
24120 +#ifdef CONFIG_VSERVER_PROC_SECURE
24121 +       (1 << VCI_KCBIT_PROC_SECURE) |
24122 +#endif
24123 +#ifdef CONFIG_VSERVER_COWBL
24124 +       (1 << VCI_KCBIT_COWBL) |
24125 +       (1 << VCI_KCBIT_FULLCOWBL) |
24126 +#endif
24127 +       (1 << VCI_KCBIT_SPACES) |
24128 +       (1 << VCI_KCBIT_NETV2) |
24129 +#ifdef CONFIG_CGROUP_MEM_RES_CTLR
24130 +       (1 << VCI_KCBIT_MEMCG) |
24131 +#endif
24132 +
24133 +       /* debug options */
24134 +#ifdef CONFIG_VSERVER_DEBUG
24135 +       (1 << VCI_KCBIT_DEBUG) |
24136 +#endif
24137 +#ifdef CONFIG_VSERVER_HISTORY
24138 +       (1 << VCI_KCBIT_HISTORY) |
24139 +#endif
24140 +
24141 +       /* inode context tagging */
24142 +#if    defined(CONFIG_TAGGING_NONE)
24143 +       (0 << VCI_KCBIT_TAGGED) |
24144 +#elif  defined(CONFIG_TAGGING_UID16)
24145 +       (1 << VCI_KCBIT_TAGGED) |
24146 +#elif  defined(CONFIG_TAGGING_GID16)
24147 +       (2 << VCI_KCBIT_TAGGED) |
24148 +#elif  defined(CONFIG_TAGGING_ID24)
24149 +       (3 << VCI_KCBIT_TAGGED) |
24150 +#elif  defined(CONFIG_TAGGING_INTERN)
24151 +       (4 << VCI_KCBIT_TAGGED) |
24152 +#elif  defined(CONFIG_TAGGING_RUNTIME)
24153 +       (5 << VCI_KCBIT_TAGGED) |
24154 +#else
24155 +       (7 << VCI_KCBIT_TAGGED) |
24156 +#endif
24157 +       (1 << VCI_KCBIT_PPTAG) |
24158 +       0;
24159 +}
24160 +
24161 diff -NurpP --minimal linux-3.0.25/mm/filemap_xip.c linux-3.0.25-vs2.3.2.3/mm/filemap_xip.c
24162 --- linux-3.0.25/mm/filemap_xip.c       2012-03-19 21:16:56.000000000 +0100
24163 +++ linux-3.0.25-vs2.3.2.3/mm/filemap_xip.c     2012-02-15 05:20:43.000000000 +0100
24164 @@ -18,6 +18,7 @@
24165  #include <linux/seqlock.h>
24166  #include <linux/mutex.h>
24167  #include <linux/gfp.h>
24168 +#include <linux/vs_memory.h>
24169  #include <asm/tlbflush.h>
24170  #include <asm/io.h>
24171  
24172 diff -NurpP --minimal linux-3.0.25/mm/fremap.c linux-3.0.25-vs2.3.2.3/mm/fremap.c
24173 --- linux-3.0.25/mm/fremap.c    2011-07-22 11:18:12.000000000 +0200
24174 +++ linux-3.0.25-vs2.3.2.3/mm/fremap.c  2011-06-10 22:11:24.000000000 +0200
24175 @@ -16,6 +16,7 @@
24176  #include <linux/module.h>
24177  #include <linux/syscalls.h>
24178  #include <linux/mmu_notifier.h>
24179 +#include <linux/vs_memory.h>
24180  
24181  #include <asm/mmu_context.h>
24182  #include <asm/cacheflush.h>
24183 diff -NurpP --minimal linux-3.0.25/mm/hugetlb.c linux-3.0.25-vs2.3.2.3/mm/hugetlb.c
24184 --- linux-3.0.25/mm/hugetlb.c   2012-03-19 21:16:56.000000000 +0100
24185 +++ linux-3.0.25-vs2.3.2.3/mm/hugetlb.c 2012-01-10 09:19:13.000000000 +0100
24186 @@ -28,6 +28,7 @@
24187  
24188  #include <linux/hugetlb.h>
24189  #include <linux/node.h>
24190 +#include <linux/vs_memory.h>
24191  #include "internal.h"
24192  
24193  const unsigned long hugetlb_zero = 0, hugetlb_infinity = ~0UL;
24194 diff -NurpP --minimal linux-3.0.25/mm/memcontrol.c linux-3.0.25-vs2.3.2.3/mm/memcontrol.c
24195 --- linux-3.0.25/mm/memcontrol.c        2012-03-19 21:16:56.000000000 +0100
24196 +++ linux-3.0.25-vs2.3.2.3/mm/memcontrol.c      2012-03-15 13:32:35.000000000 +0100
24197 @@ -741,6 +741,31 @@ struct mem_cgroup *mem_cgroup_from_task(
24198                                 struct mem_cgroup, css);
24199  }
24200  
24201 +u64 mem_cgroup_res_read_u64(struct mem_cgroup *mem, int member)
24202 +{
24203 +       return res_counter_read_u64(&mem->res, member);
24204 +}
24205 +
24206 +u64 mem_cgroup_memsw_read_u64(struct mem_cgroup *mem, int member)
24207 +{
24208 +       return res_counter_read_u64(&mem->memsw, member);
24209 +}
24210 +
24211 +s64 mem_cgroup_stat_read_cache(struct mem_cgroup *mem)
24212 +{
24213 +       return mem_cgroup_read_stat(mem, MEM_CGROUP_STAT_CACHE);
24214 +}
24215 +
24216 +s64 mem_cgroup_stat_read_anon(struct mem_cgroup *mem)
24217 +{
24218 +       return mem_cgroup_read_stat(mem, MEM_CGROUP_STAT_RSS);
24219 +}
24220 +
24221 +s64 mem_cgroup_stat_read_mapped(struct mem_cgroup *mem)
24222 +{
24223 +       return mem_cgroup_read_stat(mem, MEM_CGROUP_STAT_FILE_MAPPED);
24224 +}
24225 +
24226  struct mem_cgroup *try_get_mem_cgroup_from_mm(struct mm_struct *mm)
24227  {
24228         struct mem_cgroup *mem = NULL;
24229 diff -NurpP --minimal linux-3.0.25/mm/memory.c linux-3.0.25-vs2.3.2.3/mm/memory.c
24230 --- linux-3.0.25/mm/memory.c    2012-03-19 21:16:56.000000000 +0100
24231 +++ linux-3.0.25-vs2.3.2.3/mm/memory.c  2011-11-15 17:37:07.000000000 +0100
24232 @@ -3388,6 +3388,7 @@ int handle_pte_fault(struct mm_struct *m
24233  {
24234         pte_t entry;
24235         spinlock_t *ptl;
24236 +       int ret = 0, type = VXPT_UNKNOWN;
24237  
24238         entry = *pte;
24239         if (!pte_present(entry)) {
24240 @@ -3412,9 +3413,12 @@ int handle_pte_fault(struct mm_struct *m
24241         if (unlikely(!pte_same(*pte, entry)))
24242                 goto unlock;
24243         if (flags & FAULT_FLAG_WRITE) {
24244 -               if (!pte_write(entry))
24245 -                       return do_wp_page(mm, vma, address,
24246 +               if (!pte_write(entry)) {
24247 +                       ret = do_wp_page(mm, vma, address,
24248                                         pte, pmd, ptl, entry);
24249 +                       type = VXPT_WRITE;
24250 +                       goto out;
24251 +               }
24252                 entry = pte_mkdirty(entry);
24253         }
24254         entry = pte_mkyoung(entry);
24255 @@ -3432,7 +3436,10 @@ int handle_pte_fault(struct mm_struct *m
24256         }
24257  unlock:
24258         pte_unmap_unlock(pte, ptl);
24259 -       return 0;
24260 +       ret = 0;
24261 +out:
24262 +       vx_page_fault(mm, vma, type, ret);
24263 +       return ret;
24264  }
24265  
24266  /*
24267 diff -NurpP --minimal linux-3.0.25/mm/mremap.c linux-3.0.25-vs2.3.2.3/mm/mremap.c
24268 --- linux-3.0.25/mm/mremap.c    2011-07-22 11:18:12.000000000 +0200
24269 +++ linux-3.0.25-vs2.3.2.3/mm/mremap.c  2011-06-10 22:11:24.000000000 +0200
24270 @@ -19,6 +19,7 @@
24271  #include <linux/security.h>
24272  #include <linux/syscalls.h>
24273  #include <linux/mmu_notifier.h>
24274 +#include <linux/vs_memory.h>
24275  
24276  #include <asm/uaccess.h>
24277  #include <asm/cacheflush.h>
24278 diff -NurpP --minimal linux-3.0.25/mm/oom_kill.c linux-3.0.25-vs2.3.2.3/mm/oom_kill.c
24279 --- linux-3.0.25/mm/oom_kill.c  2012-03-19 21:16:56.000000000 +0100
24280 +++ linux-3.0.25-vs2.3.2.3/mm/oom_kill.c        2012-01-10 09:19:13.000000000 +0100
24281 @@ -32,6 +32,9 @@
24282  #include <linux/mempolicy.h>
24283  #include <linux/security.h>
24284  #include <linux/ptrace.h>
24285 +#include <linux/reboot.h>
24286 +#include <linux/vs_memory.h>
24287 +#include <linux/vs_context.h>
24288  
24289  int sysctl_panic_on_oom;
24290  int sysctl_oom_kill_allocating_task;
24291 @@ -134,11 +137,18 @@ struct task_struct *find_lock_task_mm(st
24292  static bool oom_unkillable_task(struct task_struct *p,
24293                 const struct mem_cgroup *mem, const nodemask_t *nodemask)
24294  {
24295 -       if (is_global_init(p))
24296 +       unsigned xid = vx_current_xid();
24297 +
24298 +       /* skip the init task, global and per guest */
24299 +       if (task_is_init(p))
24300                 return true;
24301         if (p->flags & PF_KTHREAD)
24302                 return true;
24303  
24304 +       /* skip other guest and host processes if oom in guest */
24305 +       if (xid && vx_task_xid(p) != xid)
24306 +               return true;
24307 +
24308         /* When mem_cgroup_out_of_memory() and p is not member of the group */
24309         if (mem && !task_in_mem_cgroup(p, mem))
24310                 return true;
24311 @@ -214,6 +224,18 @@ unsigned int oom_badness(struct task_str
24312         points += p->signal->oom_score_adj;
24313  
24314         /*
24315 +        * add points for context badness and
24316 +        * reduce badness for processes belonging to
24317 +        * a different context
24318 +        */
24319 +
24320 +       points += vx_badness(p, p->mm);
24321 +
24322 +       if ((vx_current_xid() > 1) &&
24323 +               vx_current_xid() != vx_task_xid(p))
24324 +               points /= 16;
24325 +
24326 +       /*
24327          * Never return 0 for an eligible task that may be killed since it's
24328          * possible that no single user task uses more than 0.1% of memory and
24329          * no single admin tasks uses more than 3.0%.
24330 @@ -429,8 +451,8 @@ static int oom_kill_task(struct task_str
24331         /* mm cannot be safely dereferenced after task_unlock(p) */
24332         mm = p->mm;
24333  
24334 -       pr_err("Killed process %d (%s) total-vm:%lukB, anon-rss:%lukB, file-rss:%lukB\n",
24335 -               task_pid_nr(p), p->comm, K(p->mm->total_vm),
24336 +       pr_err("Killed process %d:#%u (%s) total-vm:%lukB, anon-rss:%lukB, file-rss:%lukB\n",
24337 +               task_pid_nr(p), p->xid, p->comm, K(p->mm->total_vm),
24338                 K(get_mm_counter(p->mm, MM_ANONPAGES)),
24339                 K(get_mm_counter(p->mm, MM_FILEPAGES)));
24340         task_unlock(p);
24341 @@ -484,8 +506,8 @@ static int oom_kill_process(struct task_
24342         }
24343  
24344         task_lock(p);
24345 -       pr_err("%s: Kill process %d (%s) score %d or sacrifice child\n",
24346 -               message, task_pid_nr(p), p->comm, points);
24347 +       pr_err("%s: Kill process %d:#%u (%s) score %d or sacrifice child\n",
24348 +               message, task_pid_nr(p), p->xid, p->comm, points);
24349         task_unlock(p);
24350  
24351         /*
24352 @@ -586,6 +608,8 @@ int unregister_oom_notifier(struct notif
24353  }
24354  EXPORT_SYMBOL_GPL(unregister_oom_notifier);
24355  
24356 +long vs_oom_action(unsigned int);
24357 +
24358  /*
24359   * Try to acquire the OOM killer lock for the zones in zonelist.  Returns zero
24360   * if a parallel OOM killing is already taking place that includes a zone in
24361 @@ -744,7 +768,12 @@ retry:
24362         if (!p) {
24363                 dump_header(NULL, gfp_mask, order, NULL, mpol_mask);
24364                 read_unlock(&tasklist_lock);
24365 -               panic("Out of memory and no killable processes...\n");
24366 +
24367 +               /* avoid panic for guest OOM */
24368 +               if (current->xid)
24369 +                       vs_oom_action(LINUX_REBOOT_CMD_OOM);
24370 +               else
24371 +                       panic("Out of memory and no killable processes...\n");
24372         }
24373  
24374         if (oom_kill_process(p, gfp_mask, order, points, totalpages, NULL,
24375 diff -NurpP --minimal linux-3.0.25/mm/page_alloc.c linux-3.0.25-vs2.3.2.3/mm/page_alloc.c
24376 --- linux-3.0.25/mm/page_alloc.c        2012-03-19 21:16:56.000000000 +0100
24377 +++ linux-3.0.25-vs2.3.2.3/mm/page_alloc.c      2012-01-26 08:39:53.000000000 +0100
24378 @@ -57,6 +57,8 @@
24379  #include <linux/ftrace_event.h>
24380  #include <linux/memcontrol.h>
24381  #include <linux/prefetch.h>
24382 +#include <linux/vs_base.h>
24383 +#include <linux/vs_limit.h>
24384  
24385  #include <asm/tlbflush.h>
24386  #include <asm/div64.h>
24387 @@ -2502,6 +2504,9 @@ void si_meminfo(struct sysinfo *val)
24388         val->totalhigh = totalhigh_pages;
24389         val->freehigh = nr_free_highpages();
24390         val->mem_unit = PAGE_SIZE;
24391 +
24392 +       if (vx_flags(VXF_VIRT_MEM, 0))
24393 +               vx_vsi_meminfo(val);
24394  }
24395  
24396  EXPORT_SYMBOL(si_meminfo);
24397 @@ -2522,6 +2527,9 @@ void si_meminfo_node(struct sysinfo *val
24398         val->freehigh = 0;
24399  #endif
24400         val->mem_unit = PAGE_SIZE;
24401 +
24402 +       if (vx_flags(VXF_VIRT_MEM, 0))
24403 +               vx_vsi_meminfo(val);
24404  }
24405  #endif
24406  
24407 diff -NurpP --minimal linux-3.0.25/mm/pgtable-generic.c linux-3.0.25-vs2.3.2.3/mm/pgtable-generic.c
24408 --- linux-3.0.25/mm/pgtable-generic.c   2011-03-15 18:07:42.000000000 +0100
24409 +++ linux-3.0.25-vs2.3.2.3/mm/pgtable-generic.c 2011-06-10 22:11:24.000000000 +0200
24410 @@ -6,6 +6,8 @@
24411   *  Copyright (C) 2010  Linus Torvalds
24412   */
24413  
24414 +#include <linux/mm.h>
24415 +
24416  #include <linux/pagemap.h>
24417  #include <asm/tlb.h>
24418  #include <asm-generic/pgtable.h>
24419 diff -NurpP --minimal linux-3.0.25/mm/rmap.c linux-3.0.25-vs2.3.2.3/mm/rmap.c
24420 --- linux-3.0.25/mm/rmap.c      2011-07-22 11:18:12.000000000 +0200
24421 +++ linux-3.0.25-vs2.3.2.3/mm/rmap.c    2011-07-01 11:35:35.000000000 +0200
24422 @@ -57,6 +57,7 @@
24423  #include <linux/mmu_notifier.h>
24424  #include <linux/migrate.h>
24425  #include <linux/hugetlb.h>
24426 +#include <linux/vs_memory.h>
24427  
24428  #include <asm/tlbflush.h>
24429  
24430 diff -NurpP --minimal linux-3.0.25/mm/shmem.c linux-3.0.25-vs2.3.2.3/mm/shmem.c
24431 --- linux-3.0.25/mm/shmem.c     2011-07-22 11:18:12.000000000 +0200
24432 +++ linux-3.0.25-vs2.3.2.3/mm/shmem.c   2011-07-01 11:35:35.000000000 +0200
24433 @@ -1850,7 +1850,7 @@ static int shmem_statfs(struct dentry *d
24434  {
24435         struct shmem_sb_info *sbinfo = SHMEM_SB(dentry->d_sb);
24436  
24437 -       buf->f_type = TMPFS_MAGIC;
24438 +       buf->f_type = TMPFS_SUPER_MAGIC;
24439         buf->f_bsize = PAGE_CACHE_SIZE;
24440         buf->f_namelen = NAME_MAX;
24441         if (sbinfo->max_blocks) {
24442 @@ -2605,7 +2605,7 @@ int shmem_fill_super(struct super_block 
24443         sb->s_maxbytes = SHMEM_MAX_BYTES;
24444         sb->s_blocksize = PAGE_CACHE_SIZE;
24445         sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
24446 -       sb->s_magic = TMPFS_MAGIC;
24447 +       sb->s_magic = TMPFS_SUPER_MAGIC;
24448         sb->s_op = &shmem_ops;
24449         sb->s_time_gran = 1;
24450  #ifdef CONFIG_TMPFS_XATTR
24451 diff -NurpP --minimal linux-3.0.25/mm/slab.c linux-3.0.25-vs2.3.2.3/mm/slab.c
24452 --- linux-3.0.25/mm/slab.c      2011-07-22 11:18:12.000000000 +0200
24453 +++ linux-3.0.25-vs2.3.2.3/mm/slab.c    2011-06-15 02:41:23.000000000 +0200
24454 @@ -411,6 +411,8 @@ static void kmem_list3_init(struct kmem_
24455  #define STATS_INC_FREEMISS(x)  do { } while (0)
24456  #endif
24457  
24458 +#include "slab_vs.h"
24459 +
24460  #if DEBUG
24461  
24462  /*
24463 @@ -3348,6 +3350,7 @@ retry:
24464  
24465         obj = slab_get_obj(cachep, slabp, nodeid);
24466         check_slabp(cachep, slabp);
24467 +       vx_slab_alloc(cachep, flags);
24468         l3->free_objects--;
24469         /* move slabp to correct slabp list: */
24470         list_del(&slabp->list);
24471 @@ -3425,6 +3428,7 @@ __cache_alloc_node(struct kmem_cache *ca
24472         /* ___cache_alloc_node can fall back to other nodes */
24473         ptr = ____cache_alloc_node(cachep, flags, nodeid);
24474    out:
24475 +       vx_slab_alloc(cachep, flags);
24476         local_irq_restore(save_flags);
24477         ptr = cache_alloc_debugcheck_after(cachep, flags, ptr, caller);
24478         kmemleak_alloc_recursive(ptr, obj_size(cachep), 1, cachep->flags,
24479 @@ -3612,6 +3616,7 @@ static inline void __cache_free(struct k
24480         check_irq_off();
24481         kmemleak_free_recursive(objp, cachep->flags);
24482         objp = cache_free_debugcheck(cachep, objp, caller);
24483 +       vx_slab_free(cachep);
24484  
24485         kmemcheck_slab_free(cachep, objp, obj_size(cachep));
24486  
24487 diff -NurpP --minimal linux-3.0.25/mm/slab_vs.h linux-3.0.25-vs2.3.2.3/mm/slab_vs.h
24488 --- linux-3.0.25/mm/slab_vs.h   1970-01-01 01:00:00.000000000 +0100
24489 +++ linux-3.0.25-vs2.3.2.3/mm/slab_vs.h 2011-06-10 22:11:24.000000000 +0200
24490 @@ -0,0 +1,29 @@
24491 +
24492 +#include <linux/vserver/context.h>
24493 +
24494 +#include <linux/vs_context.h>
24495 +
24496 +static inline
24497 +void vx_slab_alloc(struct kmem_cache *cachep, gfp_t flags)
24498 +{
24499 +       int what = gfp_zone(cachep->gfpflags);
24500 +       struct vx_info *vxi = current_vx_info();
24501 +
24502 +       if (!vxi)
24503 +               return;
24504 +
24505 +       atomic_add(cachep->buffer_size, &vxi->cacct.slab[what]);
24506 +}
24507 +
24508 +static inline
24509 +void vx_slab_free(struct kmem_cache *cachep)
24510 +{
24511 +       int what = gfp_zone(cachep->gfpflags);
24512 +       struct vx_info *vxi = current_vx_info();
24513 +
24514 +       if (!vxi)
24515 +               return;
24516 +
24517 +       atomic_sub(cachep->buffer_size, &vxi->cacct.slab[what]);
24518 +}
24519 +
24520 diff -NurpP --minimal linux-3.0.25/mm/swapfile.c linux-3.0.25-vs2.3.2.3/mm/swapfile.c
24521 --- linux-3.0.25/mm/swapfile.c  2011-07-22 11:18:12.000000000 +0200
24522 +++ linux-3.0.25-vs2.3.2.3/mm/swapfile.c        2011-07-01 11:35:35.000000000 +0200
24523 @@ -37,6 +37,8 @@
24524  #include <asm/tlbflush.h>
24525  #include <linux/swapops.h>
24526  #include <linux/page_cgroup.h>
24527 +#include <linux/vs_base.h>
24528 +#include <linux/vs_memory.h>
24529  
24530  static bool swap_count_continued(struct swap_info_struct *, pgoff_t,
24531                                  unsigned char);
24532 @@ -1759,6 +1761,16 @@ static int swap_show(struct seq_file *sw
24533  
24534         if (si == SEQ_START_TOKEN) {
24535                 seq_puts(swap,"Filename\t\t\t\tType\t\tSize\tUsed\tPriority\n");
24536 +               if (vx_flags(VXF_VIRT_MEM, 0)) {
24537 +                       struct sysinfo si;
24538 +
24539 +                       vx_vsi_swapinfo(&si);
24540 +                       if (si.totalswap < (1 << 10))
24541 +                               return 0;
24542 +                       seq_printf(swap, "%s\t\t\t\t\t%s\t%lu\t%lu\t%d\n",
24543 +                               "hdv0", "partition", si.totalswap >> 10,
24544 +                               (si.totalswap - si.freeswap) >> 10, -1);
24545 +               }
24546                 return 0;
24547         }
24548  
24549 @@ -2186,6 +2198,8 @@ void si_swapinfo(struct sysinfo *val)
24550         val->freeswap = nr_swap_pages + nr_to_be_unused;
24551         val->totalswap = total_swap_pages + nr_to_be_unused;
24552         spin_unlock(&swap_lock);
24553 +       if (vx_flags(VXF_VIRT_MEM, 0))
24554 +               vx_vsi_swapinfo(val);
24555  }
24556  
24557  /*
24558 diff -NurpP --minimal linux-3.0.25/net/bridge/br_multicast.c linux-3.0.25-vs2.3.2.3/net/bridge/br_multicast.c
24559 --- linux-3.0.25/net/bridge/br_multicast.c      2012-03-19 21:16:57.000000000 +0100
24560 +++ linux-3.0.25-vs2.3.2.3/net/bridge/br_multicast.c    2012-03-23 14:55:24.000000000 +0100
24561 @@ -447,7 +447,7 @@ static struct sk_buff *br_ip6_multicast_
24562         ip6h->hop_limit = 1;
24563         ipv6_addr_set(&ip6h->daddr, htonl(0xff020000), 0, 0, htonl(1));
24564         if (ipv6_dev_get_saddr(dev_net(br->dev), br->dev, &ip6h->daddr, 0,
24565 -                              &ip6h->saddr)) {
24566 +                              &ip6h->saddr, NULL)) {
24567                 kfree_skb(skb);
24568                 return NULL;
24569         }
24570 diff -NurpP --minimal linux-3.0.25/net/core/dev.c linux-3.0.25-vs2.3.2.3/net/core/dev.c
24571 --- linux-3.0.25/net/core/dev.c 2012-03-19 21:16:57.000000000 +0100
24572 +++ linux-3.0.25-vs2.3.2.3/net/core/dev.c       2012-03-01 21:51:50.000000000 +0100
24573 @@ -127,6 +127,7 @@
24574  #include <linux/in.h>
24575  #include <linux/jhash.h>
24576  #include <linux/random.h>
24577 +#include <linux/vs_inet.h>
24578  #include <trace/events/napi.h>
24579  #include <trace/events/net.h>
24580  #include <trace/events/skb.h>
24581 @@ -609,7 +610,8 @@ struct net_device *__dev_get_by_name(str
24582         struct hlist_head *head = dev_name_hash(net, name);
24583  
24584         hlist_for_each_entry(dev, p, head, name_hlist)
24585 -               if (!strncmp(dev->name, name, IFNAMSIZ))
24586 +               if (!strncmp(dev->name, name, IFNAMSIZ) &&
24587 +                   nx_dev_visible(current_nx_info(), dev))
24588                         return dev;
24589  
24590         return NULL;
24591 @@ -635,7 +637,8 @@ struct net_device *dev_get_by_name_rcu(s
24592         struct hlist_head *head = dev_name_hash(net, name);
24593  
24594         hlist_for_each_entry_rcu(dev, p, head, name_hlist)
24595 -               if (!strncmp(dev->name, name, IFNAMSIZ))
24596 +               if (!strncmp(dev->name, name, IFNAMSIZ) &&
24597 +                   nx_dev_visible(current_nx_info(), dev))
24598                         return dev;
24599  
24600         return NULL;
24601 @@ -686,7 +689,8 @@ struct net_device *__dev_get_by_index(st
24602         struct hlist_head *head = dev_index_hash(net, ifindex);
24603  
24604         hlist_for_each_entry(dev, p, head, index_hlist)
24605 -               if (dev->ifindex == ifindex)
24606 +               if ((dev->ifindex == ifindex) &&
24607 +                   nx_dev_visible(current_nx_info(), dev))
24608                         return dev;
24609  
24610         return NULL;
24611 @@ -704,7 +708,7 @@ EXPORT_SYMBOL(__dev_get_by_index);
24612   *     about locking. The caller must hold RCU lock.
24613   */
24614  
24615 -struct net_device *dev_get_by_index_rcu(struct net *net, int ifindex)
24616 +struct net_device *dev_get_by_index_real_rcu(struct net *net, int ifindex)
24617  {
24618         struct hlist_node *p;
24619         struct net_device *dev;
24620 @@ -716,6 +720,16 @@ struct net_device *dev_get_by_index_rcu(
24621  
24622         return NULL;
24623  }
24624 +EXPORT_SYMBOL(dev_get_by_index_real_rcu);
24625 +
24626 +struct net_device *dev_get_by_index_rcu(struct net *net, int ifindex)
24627 +{
24628 +       struct net_device *dev = dev_get_by_index_real_rcu(net, ifindex);
24629 +
24630 +       if (nx_dev_visible(current_nx_info(), dev))
24631 +               return dev;
24632 +       return NULL;
24633 +}
24634  EXPORT_SYMBOL(dev_get_by_index_rcu);
24635  
24636  
24637 @@ -764,7 +778,8 @@ struct net_device *dev_getbyhwaddr_rcu(s
24638  
24639         for_each_netdev_rcu(net, dev)
24640                 if (dev->type == type &&
24641 -                   !memcmp(dev->dev_addr, ha, dev->addr_len))
24642 +                   !memcmp(dev->dev_addr, ha, dev->addr_len) &&
24643 +                   nx_dev_visible(current_nx_info(), dev))
24644                         return dev;
24645  
24646         return NULL;
24647 @@ -776,9 +791,11 @@ struct net_device *__dev_getfirstbyhwtyp
24648         struct net_device *dev;
24649  
24650         ASSERT_RTNL();
24651 -       for_each_netdev(net, dev)
24652 -               if (dev->type == type)
24653 +       for_each_netdev(net, dev) {
24654 +               if ((dev->type == type) &&
24655 +                   nx_dev_visible(current_nx_info(), dev))
24656                         return dev;
24657 +       }
24658  
24659         return NULL;
24660  }
24661 @@ -896,6 +913,8 @@ static int __dev_alloc_name(struct net *
24662                                 continue;
24663                         if (i < 0 || i >= max_netdevices)
24664                                 continue;
24665 +                       if (!nx_dev_visible(current_nx_info(), d))
24666 +                               continue;
24667  
24668                         /*  avoid cases where sscanf is not exact inverse of printf */
24669                         snprintf(buf, IFNAMSIZ, name, i);
24670 @@ -3943,6 +3962,8 @@ static int dev_ifconf(struct net *net, c
24671  
24672         total = 0;
24673         for_each_netdev(net, dev) {
24674 +               if (!nx_dev_visible(current_nx_info(), dev))
24675 +                       continue;
24676                 for (i = 0; i < NPROTO; i++) {
24677                         if (gifconf_list[i]) {
24678                                 int done;
24679 @@ -4017,6 +4038,10 @@ static void dev_seq_printf_stats(struct 
24680         struct rtnl_link_stats64 temp;
24681         const struct rtnl_link_stats64 *stats = dev_get_stats(dev, &temp);
24682  
24683 +       /* device visible inside network context? */
24684 +       if (!nx_dev_visible(current_nx_info(), dev))
24685 +               return;
24686 +
24687         seq_printf(seq, "%6s: %7llu %7llu %4llu %4llu %4llu %5llu %10llu %9llu "
24688                    "%8llu %7llu %4llu %4llu %4llu %5llu %7llu %10llu\n",
24689                    dev->name, stats->rx_bytes, stats->rx_packets,
24690 diff -NurpP --minimal linux-3.0.25/net/core/rtnetlink.c linux-3.0.25-vs2.3.2.3/net/core/rtnetlink.c
24691 --- linux-3.0.25/net/core/rtnetlink.c   2011-07-22 11:18:13.000000000 +0200
24692 +++ linux-3.0.25-vs2.3.2.3/net/core/rtnetlink.c 2011-06-10 22:11:24.000000000 +0200
24693 @@ -1015,6 +1015,8 @@ static int rtnl_dump_ifinfo(struct sk_bu
24694                 hlist_for_each_entry_rcu(dev, node, head, index_hlist) {
24695                         if (idx < s_idx)
24696                                 goto cont;
24697 +                       if (!nx_dev_visible(skb->sk->sk_nx_info, dev))
24698 +                               continue;
24699                         if (rtnl_fill_ifinfo(skb, dev, RTM_NEWLINK,
24700                                              NETLINK_CB(cb->skb).pid,
24701                                              cb->nlh->nlmsg_seq, 0,
24702 @@ -1848,6 +1850,9 @@ void rtmsg_ifinfo(int type, struct net_d
24703         struct sk_buff *skb;
24704         int err = -ENOBUFS;
24705  
24706 +       if (!nx_dev_visible(current_nx_info(), dev))
24707 +               return;
24708 +
24709         skb = nlmsg_new(if_nlmsg_size(dev), GFP_KERNEL);
24710         if (skb == NULL)
24711                 goto errout;
24712 diff -NurpP --minimal linux-3.0.25/net/core/sock.c linux-3.0.25-vs2.3.2.3/net/core/sock.c
24713 --- linux-3.0.25/net/core/sock.c        2012-03-19 21:16:57.000000000 +0100
24714 +++ linux-3.0.25-vs2.3.2.3/net/core/sock.c      2011-11-15 17:37:07.000000000 +0100
24715 @@ -127,6 +127,10 @@
24716  #include <net/cls_cgroup.h>
24717  
24718  #include <linux/filter.h>
24719 +#include <linux/vs_socket.h>
24720 +#include <linux/vs_limit.h>
24721 +#include <linux/vs_context.h>
24722 +#include <linux/vs_network.h>
24723  
24724  #ifdef CONFIG_INET
24725  #include <net/tcp.h>
24726 @@ -1070,6 +1074,8 @@ static struct sock *sk_prot_alloc(struct
24727                         goto out_free_sec;
24728                 sk_tx_queue_clear(sk);
24729         }
24730 +               sock_vx_init(sk);
24731 +               sock_nx_init(sk);
24732  
24733         return sk;
24734  
24735 @@ -1169,6 +1175,11 @@ static void __sk_free(struct sock *sk)
24736                 put_cred(sk->sk_peer_cred);
24737         put_pid(sk->sk_peer_pid);
24738         put_net(sock_net(sk));
24739 +       vx_sock_dec(sk);
24740 +       clr_vx_info(&sk->sk_vx_info);
24741 +       sk->sk_xid = -1;
24742 +       clr_nx_info(&sk->sk_nx_info);
24743 +       sk->sk_nid = -1;
24744         sk_prot_free(sk->sk_prot_creator, sk);
24745  }
24746  
24747 @@ -1216,6 +1227,8 @@ struct sock *sk_clone(const struct sock 
24748  
24749                 /* SANITY */
24750                 get_net(sock_net(newsk));
24751 +               sock_vx_init(newsk);
24752 +               sock_nx_init(newsk);
24753                 sk_node_init(&newsk->sk_node);
24754                 sock_lock_init(newsk);
24755                 bh_lock_sock(newsk);
24756 @@ -1272,6 +1285,12 @@ struct sock *sk_clone(const struct sock 
24757                 smp_wmb();
24758                 atomic_set(&newsk->sk_refcnt, 2);
24759  
24760 +               set_vx_info(&newsk->sk_vx_info, sk->sk_vx_info);
24761 +               newsk->sk_xid = sk->sk_xid;
24762 +               vx_sock_inc(newsk);
24763 +               set_nx_info(&newsk->sk_nx_info, sk->sk_nx_info);
24764 +               newsk->sk_nid = sk->sk_nid;
24765 +
24766                 /*
24767                  * Increment the counter in the same struct proto as the master
24768                  * sock (sk_refcnt_debug_inc uses newsk->sk_prot->socks, that
24769 @@ -2018,6 +2037,12 @@ void sock_init_data(struct socket *sock,
24770  
24771         sk->sk_stamp = ktime_set(-1L, 0);
24772  
24773 +       set_vx_info(&sk->sk_vx_info, current_vx_info());
24774 +       sk->sk_xid = vx_current_xid();
24775 +       vx_sock_inc(sk);
24776 +       set_nx_info(&sk->sk_nx_info, current_nx_info());
24777 +       sk->sk_nid = nx_current_nid();
24778 +
24779         /*
24780          * Before updating sk_refcnt, we must commit prior changes to memory
24781          * (Documentation/RCU/rculist_nulls.txt for details)
24782 diff -NurpP --minimal linux-3.0.25/net/ipv4/af_inet.c linux-3.0.25-vs2.3.2.3/net/ipv4/af_inet.c
24783 --- linux-3.0.25/net/ipv4/af_inet.c     2011-07-22 11:18:13.000000000 +0200
24784 +++ linux-3.0.25-vs2.3.2.3/net/ipv4/af_inet.c   2011-07-19 00:44:39.000000000 +0200
24785 @@ -117,6 +117,7 @@
24786  #ifdef CONFIG_IP_MROUTE
24787  #include <linux/mroute.h>
24788  #endif
24789 +#include <linux/vs_limit.h>
24790  
24791  
24792  /* The inetsw table contains everything that inet_create needs to
24793 @@ -326,9 +327,13 @@ lookup_protocol:
24794         }
24795  
24796         err = -EPERM;
24797 +       if ((protocol == IPPROTO_ICMP) &&
24798 +               nx_capable(CAP_NET_RAW, NXC_RAW_ICMP))
24799 +               goto override;
24800 +
24801         if (sock->type == SOCK_RAW && !kern && !capable(CAP_NET_RAW))
24802                 goto out_rcu_unlock;
24803 -
24804 +override:
24805         err = -EAFNOSUPPORT;
24806         if (!inet_netns_ok(net, protocol))
24807                 goto out_rcu_unlock;
24808 @@ -452,6 +457,7 @@ int inet_bind(struct socket *sock, struc
24809         struct sockaddr_in *addr = (struct sockaddr_in *)uaddr;
24810         struct sock *sk = sock->sk;
24811         struct inet_sock *inet = inet_sk(sk);
24812 +       struct nx_v4_sock_addr nsa;
24813         unsigned short snum;
24814         int chk_addr_ret;
24815         int err;
24816 @@ -470,7 +476,11 @@ int inet_bind(struct socket *sock, struc
24817                 goto out;
24818         }
24819  
24820 -       chk_addr_ret = inet_addr_type(sock_net(sk), addr->sin_addr.s_addr);
24821 +       err = v4_map_sock_addr(inet, addr, &nsa);
24822 +       if (err)
24823 +               goto out;
24824 +
24825 +       chk_addr_ret = inet_addr_type(sock_net(sk), nsa.saddr);
24826  
24827         /* Not specified by any standard per-se, however it breaks too
24828          * many applications when removed.  It is unfortunate since
24829 @@ -482,7 +492,7 @@ int inet_bind(struct socket *sock, struc
24830         err = -EADDRNOTAVAIL;
24831         if (!sysctl_ip_nonlocal_bind &&
24832             !(inet->freebind || inet->transparent) &&
24833 -           addr->sin_addr.s_addr != htonl(INADDR_ANY) &&
24834 +           nsa.saddr != htonl(INADDR_ANY) &&
24835             chk_addr_ret != RTN_LOCAL &&
24836             chk_addr_ret != RTN_MULTICAST &&
24837             chk_addr_ret != RTN_BROADCAST)
24838 @@ -507,7 +517,7 @@ int inet_bind(struct socket *sock, struc
24839         if (sk->sk_state != TCP_CLOSE || inet->inet_num)
24840                 goto out_release_sock;
24841  
24842 -       inet->inet_rcv_saddr = inet->inet_saddr = addr->sin_addr.s_addr;
24843 +       v4_set_sock_addr(inet, &nsa);
24844         if (chk_addr_ret == RTN_MULTICAST || chk_addr_ret == RTN_BROADCAST)
24845                 inet->inet_saddr = 0;  /* Use device */
24846  
24847 @@ -710,11 +720,13 @@ int inet_getname(struct socket *sock, st
24848                      peer == 1))
24849                         return -ENOTCONN;
24850                 sin->sin_port = inet->inet_dport;
24851 -               sin->sin_addr.s_addr = inet->inet_daddr;
24852 +               sin->sin_addr.s_addr =
24853 +                       nx_map_sock_lback(sk->sk_nx_info, inet->inet_daddr);
24854         } else {
24855                 __be32 addr = inet->inet_rcv_saddr;
24856                 if (!addr)
24857                         addr = inet->inet_saddr;
24858 +               addr = nx_map_sock_lback(sk->sk_nx_info, addr);
24859                 sin->sin_port = inet->inet_sport;
24860                 sin->sin_addr.s_addr = addr;
24861         }
24862 diff -NurpP --minimal linux-3.0.25/net/ipv4/arp.c linux-3.0.25-vs2.3.2.3/net/ipv4/arp.c
24863 --- linux-3.0.25/net/ipv4/arp.c 2012-03-19 21:16:57.000000000 +0100
24864 +++ linux-3.0.25-vs2.3.2.3/net/ipv4/arp.c       2012-03-01 21:51:50.000000000 +0100
24865 @@ -1372,6 +1372,7 @@ static void arp_format_neigh_entry(struc
24866         struct net_device *dev = n->dev;
24867         int hatype = dev->type;
24868  
24869 +       /* FIXME: check for network context */
24870         read_lock(&n->lock);
24871         /* Convert hardware address to XX:XX:XX:XX ... form. */
24872  #if defined(CONFIG_AX25) || defined(CONFIG_AX25_MODULE)
24873 @@ -1403,6 +1404,7 @@ static void arp_format_pneigh_entry(stru
24874         int hatype = dev ? dev->type : 0;
24875         char tbuf[16];
24876  
24877 +       /* FIXME: check for network context */
24878         sprintf(tbuf, "%pI4", n->key);
24879         seq_printf(seq, "%-16s 0x%-10x0x%-10x%s     *        %s\n",
24880                    tbuf, hatype, ATF_PUBL | ATF_PERM, "00:00:00:00:00:00",
24881 diff -NurpP --minimal linux-3.0.25/net/ipv4/devinet.c linux-3.0.25-vs2.3.2.3/net/ipv4/devinet.c
24882 --- linux-3.0.25/net/ipv4/devinet.c     2012-03-19 21:16:57.000000000 +0100
24883 +++ linux-3.0.25-vs2.3.2.3/net/ipv4/devinet.c   2012-01-10 09:19:13.000000000 +0100
24884 @@ -518,6 +518,7 @@ struct in_device *inetdev_by_index(struc
24885  }
24886  EXPORT_SYMBOL(inetdev_by_index);
24887  
24888 +
24889  /* Called only from RTNL semaphored context. No locks. */
24890  
24891  struct in_ifaddr *inet_ifa_byprefix(struct in_device *in_dev, __be32 prefix,
24892 @@ -759,6 +760,8 @@ int devinet_ioctl(struct net *net, unsig
24893  
24894         in_dev = __in_dev_get_rtnl(dev);
24895         if (in_dev) {
24896 +               struct nx_info *nxi = current_nx_info();
24897 +
24898                 if (tryaddrmatch) {
24899                         /* Matthias Andree */
24900                         /* compare label and address (4.4BSD style) */
24901 @@ -767,6 +770,8 @@ int devinet_ioctl(struct net *net, unsig
24902                            This is checked above. */
24903                         for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
24904                              ifap = &ifa->ifa_next) {
24905 +                               if (!nx_v4_ifa_visible(nxi, ifa))
24906 +                                       continue;
24907                                 if (!strcmp(ifr.ifr_name, ifa->ifa_label) &&
24908                                     sin_orig.sin_addr.s_addr ==
24909                                                         ifa->ifa_local) {
24910 @@ -779,9 +784,12 @@ int devinet_ioctl(struct net *net, unsig
24911                    comparing just the label */
24912                 if (!ifa) {
24913                         for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
24914 -                            ifap = &ifa->ifa_next)
24915 +                            ifap = &ifa->ifa_next) {
24916 +                               if (!nx_v4_ifa_visible(nxi, ifa))
24917 +                                       continue;
24918                                 if (!strcmp(ifr.ifr_name, ifa->ifa_label))
24919                                         break;
24920 +                       }
24921                 }
24922         }
24923  
24924 @@ -934,6 +942,8 @@ static int inet_gifconf(struct net_devic
24925                 goto out;
24926  
24927         for (ifa = in_dev->ifa_list; ifa; ifa = ifa->ifa_next) {
24928 +               if (!nx_v4_ifa_visible(current_nx_info(), ifa))
24929 +                       continue;
24930                 if (!buf) {
24931                         done += sizeof(ifr);
24932                         continue;
24933 @@ -1294,6 +1304,7 @@ static int inet_dump_ifaddr(struct sk_bu
24934         struct net_device *dev;
24935         struct in_device *in_dev;
24936         struct in_ifaddr *ifa;
24937 +       struct sock *sk = skb->sk;
24938         struct hlist_head *head;
24939         struct hlist_node *node;
24940  
24941 @@ -1316,6 +1327,8 @@ static int inet_dump_ifaddr(struct sk_bu
24942  
24943                         for (ifa = in_dev->ifa_list, ip_idx = 0; ifa;
24944                              ifa = ifa->ifa_next, ip_idx++) {
24945 +                       if (sk && !nx_v4_ifa_visible(sk->sk_nx_info, ifa))
24946 +                               continue;
24947                                 if (ip_idx < s_ip_idx)
24948                                         continue;
24949                                 if (inet_fill_ifaddr(skb, ifa,
24950 diff -NurpP --minimal linux-3.0.25/net/ipv4/fib_trie.c linux-3.0.25-vs2.3.2.3/net/ipv4/fib_trie.c
24951 --- linux-3.0.25/net/ipv4/fib_trie.c    2011-07-22 11:18:13.000000000 +0200
24952 +++ linux-3.0.25-vs2.3.2.3/net/ipv4/fib_trie.c  2011-08-29 04:56:47.000000000 +0200
24953 @@ -2554,6 +2554,7 @@ static int fib_route_seq_show(struct seq
24954                             || fa->fa_type == RTN_MULTICAST)
24955                                 continue;
24956  
24957 +                       /* FIXME: check for network context? */
24958                         if (fi)
24959                                 seq_printf(seq,
24960                                          "%s\t%08X\t%08X\t%04X\t%d\t%u\t"
24961 diff -NurpP --minimal linux-3.0.25/net/ipv4/inet_connection_sock.c linux-3.0.25-vs2.3.2.3/net/ipv4/inet_connection_sock.c
24962 --- linux-3.0.25/net/ipv4/inet_connection_sock.c        2011-07-22 11:18:13.000000000 +0200
24963 +++ linux-3.0.25-vs2.3.2.3/net/ipv4/inet_connection_sock.c      2011-06-10 22:11:24.000000000 +0200
24964 @@ -52,6 +52,37 @@ void inet_get_local_port_range(int *low,
24965  }
24966  EXPORT_SYMBOL(inet_get_local_port_range);
24967  
24968 +int ipv4_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2)
24969 +{
24970 +       __be32  sk1_rcv_saddr = sk_rcv_saddr(sk1),
24971 +               sk2_rcv_saddr = sk_rcv_saddr(sk2);
24972 +
24973 +       if (inet_v6_ipv6only(sk2))
24974 +               return 0;
24975 +
24976 +       if (sk1_rcv_saddr &&
24977 +           sk2_rcv_saddr &&
24978 +           sk1_rcv_saddr == sk2_rcv_saddr)
24979 +               return 1;
24980 +
24981 +       if (sk1_rcv_saddr &&
24982 +           !sk2_rcv_saddr &&
24983 +           v4_addr_in_nx_info(sk2->sk_nx_info, sk1_rcv_saddr, NXA_MASK_BIND))
24984 +               return 1;
24985 +
24986 +       if (sk2_rcv_saddr &&
24987 +           !sk1_rcv_saddr &&
24988 +           v4_addr_in_nx_info(sk1->sk_nx_info, sk2_rcv_saddr, NXA_MASK_BIND))
24989 +               return 1;
24990 +
24991 +       if (!sk1_rcv_saddr &&
24992 +           !sk2_rcv_saddr &&
24993 +           nx_v4_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info))
24994 +               return 1;
24995 +
24996 +       return 0;
24997 +}
24998 +
24999  int inet_csk_bind_conflict(const struct sock *sk,
25000                            const struct inet_bind_bucket *tb)
25001  {
25002 @@ -74,9 +105,7 @@ int inet_csk_bind_conflict(const struct 
25003                      sk->sk_bound_dev_if == sk2->sk_bound_dev_if)) {
25004                         if (!reuse || !sk2->sk_reuse ||
25005                             sk2->sk_state == TCP_LISTEN) {
25006 -                               const __be32 sk2_rcv_saddr = sk_rcv_saddr(sk2);
25007 -                               if (!sk2_rcv_saddr || !sk_rcv_saddr(sk) ||
25008 -                                   sk2_rcv_saddr == sk_rcv_saddr(sk))
25009 +                               if (ipv4_rcv_saddr_equal(sk, sk2))
25010                                         break;
25011                         }
25012                 }
25013 diff -NurpP --minimal linux-3.0.25/net/ipv4/inet_diag.c linux-3.0.25-vs2.3.2.3/net/ipv4/inet_diag.c
25014 --- linux-3.0.25/net/ipv4/inet_diag.c   2011-07-22 11:18:13.000000000 +0200
25015 +++ linux-3.0.25-vs2.3.2.3/net/ipv4/inet_diag.c 2011-06-22 12:39:16.000000000 +0200
25016 @@ -33,6 +33,8 @@
25017  #include <linux/stddef.h>
25018  
25019  #include <linux/inet_diag.h>
25020 +#include <linux/vs_network.h>
25021 +#include <linux/vs_inet.h>
25022  
25023  static const struct inet_diag_handler **inet_diag_table;
25024  
25025 @@ -119,8 +121,10 @@ static int inet_csk_diag_fill(struct soc
25026  
25027         r->id.idiag_sport = inet->inet_sport;
25028         r->id.idiag_dport = inet->inet_dport;
25029 -       r->id.idiag_src[0] = inet->inet_rcv_saddr;
25030 -       r->id.idiag_dst[0] = inet->inet_daddr;
25031 +       r->id.idiag_src[0] = nx_map_sock_lback(sk->sk_nx_info,
25032 +               inet->inet_rcv_saddr);
25033 +       r->id.idiag_dst[0] = nx_map_sock_lback(sk->sk_nx_info,
25034 +               inet->inet_daddr);
25035  
25036  #if defined(CONFIG_IPV6) || defined (CONFIG_IPV6_MODULE)
25037         if (r->idiag_family == AF_INET6) {
25038 @@ -205,8 +209,8 @@ static int inet_twsk_diag_fill(struct in
25039         r->id.idiag_cookie[1] = (u32)(((unsigned long)tw >> 31) >> 1);
25040         r->id.idiag_sport     = tw->tw_sport;
25041         r->id.idiag_dport     = tw->tw_dport;
25042 -       r->id.idiag_src[0]    = tw->tw_rcv_saddr;
25043 -       r->id.idiag_dst[0]    = tw->tw_daddr;
25044 +       r->id.idiag_src[0]    = nx_map_sock_lback(tw->tw_nx_info, tw->tw_rcv_saddr);
25045 +       r->id.idiag_dst[0]    = nx_map_sock_lback(tw->tw_nx_info, tw->tw_daddr);
25046         r->idiag_state        = tw->tw_substate;
25047         r->idiag_timer        = 3;
25048         r->idiag_expires      = DIV_ROUND_UP(tmo * 1000, HZ);
25049 @@ -263,6 +267,7 @@ static int inet_diag_get_exact(struct sk
25050         err = -EINVAL;
25051  
25052         if (req->idiag_family == AF_INET) {
25053 +               /* TODO: lback */
25054                 sk = inet_lookup(&init_net, hashinfo, req->id.idiag_dst[0],
25055                                  req->id.idiag_dport, req->id.idiag_src[0],
25056                                  req->id.idiag_sport, req->id.idiag_if);
25057 @@ -505,6 +510,7 @@ static int inet_csk_diag_dump(struct soc
25058                 } else
25059  #endif
25060                 {
25061 +                       /* TODO: lback */
25062                         entry.saddr = &inet->inet_rcv_saddr;
25063                         entry.daddr = &inet->inet_daddr;
25064                 }
25065 @@ -543,6 +549,7 @@ static int inet_twsk_diag_dump(struct in
25066                 } else
25067  #endif
25068                 {
25069 +                       /* TODO: lback */
25070                         entry.saddr = &tw->tw_rcv_saddr;
25071                         entry.daddr = &tw->tw_daddr;
25072                 }
25073 @@ -589,8 +596,8 @@ static int inet_diag_fill_req(struct sk_
25074  
25075         r->id.idiag_sport = inet->inet_sport;
25076         r->id.idiag_dport = ireq->rmt_port;
25077 -       r->id.idiag_src[0] = ireq->loc_addr;
25078 -       r->id.idiag_dst[0] = ireq->rmt_addr;
25079 +       r->id.idiag_src[0] = nx_map_sock_lback(sk->sk_nx_info, ireq->loc_addr);
25080 +       r->id.idiag_dst[0] = nx_map_sock_lback(sk->sk_nx_info, ireq->rmt_addr);
25081         r->idiag_expires = jiffies_to_msecs(tmo);
25082         r->idiag_rqueue = 0;
25083         r->idiag_wqueue = 0;
25084 @@ -661,6 +668,7 @@ static int inet_diag_dump_reqs(struct sk
25085                                 continue;
25086  
25087                         if (bc) {
25088 +                               /* TODO: lback */
25089                                 entry.saddr =
25090  #if defined(CONFIG_IPV6) || defined (CONFIG_IPV6_MODULE)
25091                                         (entry.family == AF_INET6) ?
25092 @@ -731,6 +739,8 @@ static int inet_diag_dump(struct sk_buff
25093                         sk_nulls_for_each(sk, node, &ilb->head) {
25094                                 struct inet_sock *inet = inet_sk(sk);
25095  
25096 +                               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
25097 +                                       continue;
25098                                 if (num < s_num) {
25099                                         num++;
25100                                         continue;
25101 @@ -797,6 +807,8 @@ skip_listen_ht:
25102                 sk_nulls_for_each(sk, node, &head->chain) {
25103                         struct inet_sock *inet = inet_sk(sk);
25104  
25105 +                       if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
25106 +                               continue;
25107                         if (num < s_num)
25108                                 goto next_normal;
25109                         if (!(r->idiag_states & (1 << sk->sk_state)))
25110 @@ -821,6 +833,8 @@ next_normal:
25111                         inet_twsk_for_each(tw, node,
25112                                     &head->twchain) {
25113  
25114 +                               if (!nx_check(tw->tw_nid, VS_WATCH_P | VS_IDENT))
25115 +                                       continue;
25116                                 if (num < s_num)
25117                                         goto next_dying;
25118                                 if (r->id.idiag_sport != tw->tw_sport &&
25119 diff -NurpP --minimal linux-3.0.25/net/ipv4/inet_hashtables.c linux-3.0.25-vs2.3.2.3/net/ipv4/inet_hashtables.c
25120 --- linux-3.0.25/net/ipv4/inet_hashtables.c     2012-03-19 21:16:57.000000000 +0100
25121 +++ linux-3.0.25-vs2.3.2.3/net/ipv4/inet_hashtables.c   2011-08-29 03:45:56.000000000 +0200
25122 @@ -22,6 +22,7 @@
25123  #include <net/inet_connection_sock.h>
25124  #include <net/inet_hashtables.h>
25125  #include <net/secure_seq.h>
25126 +#include <net/route.h>
25127  #include <net/ip.h>
25128  
25129  /*
25130 @@ -156,6 +157,11 @@ static inline int compute_score(struct s
25131                         if (rcv_saddr != daddr)
25132                                 return -1;
25133                         score += 2;
25134 +               } else {
25135 +                       /* block non nx_info ips */
25136 +                       if (!v4_addr_in_nx_info(sk->sk_nx_info,
25137 +                               daddr, NXA_MASK_BIND))
25138 +                               return -1;
25139                 }
25140                 if (sk->sk_bound_dev_if) {
25141                         if (sk->sk_bound_dev_if != dif)
25142 @@ -173,7 +179,6 @@ static inline int compute_score(struct s
25143   * wildcarded during the search since they can never be otherwise.
25144   */
25145  
25146 -
25147  struct sock *__inet_lookup_listener(struct net *net,
25148                                     struct inet_hashinfo *hashinfo,
25149                                     const __be32 daddr, const unsigned short hnum,
25150 @@ -196,6 +201,7 @@ begin:
25151                         hiscore = score;
25152                 }
25153         }
25154 +
25155         /*
25156          * if the nulls value we got at the end of this lookup is
25157          * not the expected one, we must restart lookup.
25158 diff -NurpP --minimal linux-3.0.25/net/ipv4/netfilter/nf_nat_helper.c linux-3.0.25-vs2.3.2.3/net/ipv4/netfilter/nf_nat_helper.c
25159 --- linux-3.0.25/net/ipv4/netfilter/nf_nat_helper.c     2011-07-22 11:18:13.000000000 +0200
25160 +++ linux-3.0.25-vs2.3.2.3/net/ipv4/netfilter/nf_nat_helper.c   2011-06-15 02:40:14.000000000 +0200
25161 @@ -20,6 +20,7 @@
25162  #include <net/route.h>
25163  
25164  #include <linux/netfilter_ipv4.h>
25165 +#include <net/route.h>
25166  #include <net/netfilter/nf_conntrack.h>
25167  #include <net/netfilter/nf_conntrack_helper.h>
25168  #include <net/netfilter/nf_conntrack_ecache.h>
25169 diff -NurpP --minimal linux-3.0.25/net/ipv4/netfilter.c linux-3.0.25-vs2.3.2.3/net/ipv4/netfilter.c
25170 --- linux-3.0.25/net/ipv4/netfilter.c   2012-03-19 21:16:57.000000000 +0100
25171 +++ linux-3.0.25-vs2.3.2.3/net/ipv4/netfilter.c 2011-10-18 13:51:13.000000000 +0200
25172 @@ -5,7 +5,7 @@
25173  #include <linux/ip.h>
25174  #include <linux/skbuff.h>
25175  #include <linux/gfp.h>
25176 -#include <net/route.h>
25177 +// #include <net/route.h>
25178  #include <net/xfrm.h>
25179  #include <net/ip.h>
25180  #include <net/netfilter/nf_queue.h>
25181 diff -NurpP --minimal linux-3.0.25/net/ipv4/raw.c linux-3.0.25-vs2.3.2.3/net/ipv4/raw.c
25182 --- linux-3.0.25/net/ipv4/raw.c 2011-07-22 11:18:13.000000000 +0200
25183 +++ linux-3.0.25-vs2.3.2.3/net/ipv4/raw.c       2011-07-27 20:26:04.000000000 +0200
25184 @@ -117,7 +117,7 @@ static struct sock *__raw_v4_lookup(stru
25185  
25186                 if (net_eq(sock_net(sk), net) && inet->inet_num == num  &&
25187                     !(inet->inet_daddr && inet->inet_daddr != raddr)    &&
25188 -                   !(inet->inet_rcv_saddr && inet->inet_rcv_saddr != laddr) &&
25189 +                   v4_sock_addr_match(sk->sk_nx_info, inet, laddr)     &&
25190                     !(sk->sk_bound_dev_if && sk->sk_bound_dev_if != dif))
25191                         goto found; /* gotcha */
25192         }
25193 @@ -385,6 +385,12 @@ static int raw_send_hdrinc(struct sock *
25194                 icmp_out_count(net, ((struct icmphdr *)
25195                         skb_transport_header(skb))->type);
25196  
25197 +       err = -EPERM;
25198 +       if (!nx_check(0, VS_ADMIN) && !capable(CAP_NET_RAW) &&
25199 +               sk->sk_nx_info &&
25200 +               !v4_addr_in_nx_info(sk->sk_nx_info, iph->saddr, NXA_MASK_BIND))
25201 +               goto error_free;
25202 +
25203         err = NF_HOOK(NFPROTO_IPV4, NF_INET_LOCAL_OUT, skb, NULL,
25204                       rt->dst.dev, dst_output);
25205         if (err > 0)
25206 @@ -571,6 +577,16 @@ static int raw_sendmsg(struct kiocb *ioc
25207                         goto done;
25208         }
25209  
25210 +       if (sk->sk_nx_info) {
25211 +               rt = ip_v4_find_src(sock_net(sk), sk->sk_nx_info, &fl4);
25212 +               if (IS_ERR(rt)) {
25213 +                       err = PTR_ERR(rt);
25214 +                       rt = NULL;
25215 +                       goto done;
25216 +               }
25217 +               ip_rt_put(rt);
25218 +       }
25219 +
25220         security_sk_classify_flow(sk, flowi4_to_flowi(&fl4));
25221         rt = ip_route_output_flow(sock_net(sk), &fl4, sk);
25222         if (IS_ERR(rt)) {
25223 @@ -647,17 +663,19 @@ static int raw_bind(struct sock *sk, str
25224  {
25225         struct inet_sock *inet = inet_sk(sk);
25226         struct sockaddr_in *addr = (struct sockaddr_in *) uaddr;
25227 +       struct nx_v4_sock_addr nsa = { 0 };
25228         int ret = -EINVAL;
25229         int chk_addr_ret;
25230  
25231         if (sk->sk_state != TCP_CLOSE || addr_len < sizeof(struct sockaddr_in))
25232                 goto out;
25233 -       chk_addr_ret = inet_addr_type(sock_net(sk), addr->sin_addr.s_addr);
25234 +       v4_map_sock_addr(inet, addr, &nsa);
25235 +       chk_addr_ret = inet_addr_type(sock_net(sk), nsa.saddr);
25236         ret = -EADDRNOTAVAIL;
25237 -       if (addr->sin_addr.s_addr && chk_addr_ret != RTN_LOCAL &&
25238 +       if (nsa.saddr && chk_addr_ret != RTN_LOCAL &&
25239             chk_addr_ret != RTN_MULTICAST && chk_addr_ret != RTN_BROADCAST)
25240                 goto out;
25241 -       inet->inet_rcv_saddr = inet->inet_saddr = addr->sin_addr.s_addr;
25242 +       v4_set_sock_addr(inet, &nsa);
25243         if (chk_addr_ret == RTN_MULTICAST || chk_addr_ret == RTN_BROADCAST)
25244                 inet->inet_saddr = 0;  /* Use device */
25245         sk_dst_reset(sk);
25246 @@ -709,7 +727,8 @@ static int raw_recvmsg(struct kiocb *ioc
25247         /* Copy the address. */
25248         if (sin) {
25249                 sin->sin_family = AF_INET;
25250 -               sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
25251 +               sin->sin_addr.s_addr =
25252 +                       nx_map_sock_lback(sk->sk_nx_info, ip_hdr(skb)->saddr);
25253                 sin->sin_port = 0;
25254                 memset(&sin->sin_zero, 0, sizeof(sin->sin_zero));
25255         }
25256 @@ -905,7 +924,8 @@ static struct sock *raw_get_first(struct
25257                 struct hlist_node *node;
25258  
25259                 sk_for_each(sk, node, &state->h->ht[state->bucket])
25260 -                       if (sock_net(sk) == seq_file_net(seq))
25261 +                       if ((sock_net(sk) == seq_file_net(seq)) &&
25262 +                               nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
25263                                 goto found;
25264         }
25265         sk = NULL;
25266 @@ -921,7 +941,8 @@ static struct sock *raw_get_next(struct 
25267                 sk = sk_next(sk);
25268  try_again:
25269                 ;
25270 -       } while (sk && sock_net(sk) != seq_file_net(seq));
25271 +       } while (sk && ((sock_net(sk) != seq_file_net(seq)) ||
25272 +               !nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT)));
25273  
25274         if (!sk && ++state->bucket < RAW_HTABLE_SIZE) {
25275                 sk = sk_head(&state->h->ht[state->bucket]);
25276 diff -NurpP --minimal linux-3.0.25/net/ipv4/route.c linux-3.0.25-vs2.3.2.3/net/ipv4/route.c
25277 --- linux-3.0.25/net/ipv4/route.c       2012-03-19 21:16:57.000000000 +0100
25278 +++ linux-3.0.25-vs2.3.2.3/net/ipv4/route.c     2012-03-01 21:51:50.000000000 +0100
25279 @@ -2658,7 +2658,7 @@ static struct rtable *ip_route_output_sl
25280  
25281  
25282         if (fl4->flowi4_oif) {
25283 -               dev_out = dev_get_by_index_rcu(net, fl4->flowi4_oif);
25284 +               dev_out = dev_get_by_index_real_rcu(net, fl4->flowi4_oif);
25285                 rth = ERR_PTR(-ENODEV);
25286                 if (dev_out == NULL)
25287                         goto out;
25288 diff -NurpP --minimal linux-3.0.25/net/ipv4/tcp.c linux-3.0.25-vs2.3.2.3/net/ipv4/tcp.c
25289 --- linux-3.0.25/net/ipv4/tcp.c 2011-07-22 11:18:13.000000000 +0200
25290 +++ linux-3.0.25-vs2.3.2.3/net/ipv4/tcp.c       2011-07-19 00:44:39.000000000 +0200
25291 @@ -266,6 +266,7 @@
25292  #include <linux/crypto.h>
25293  #include <linux/time.h>
25294  #include <linux/slab.h>
25295 +#include <linux/in.h>
25296  
25297  #include <net/icmp.h>
25298  #include <net/tcp.h>
25299 diff -NurpP --minimal linux-3.0.25/net/ipv4/tcp_ipv4.c linux-3.0.25-vs2.3.2.3/net/ipv4/tcp_ipv4.c
25300 --- linux-3.0.25/net/ipv4/tcp_ipv4.c    2012-03-19 21:16:57.000000000 +0100
25301 +++ linux-3.0.25-vs2.3.2.3/net/ipv4/tcp_ipv4.c  2012-03-01 21:51:50.000000000 +0100
25302 @@ -2011,6 +2011,12 @@ static void *listening_get_next(struct s
25303                 req = req->dl_next;
25304                 while (1) {
25305                         while (req) {
25306 +                               vxdprintk(VXD_CBIT(net, 6),
25307 +                                       "sk,req: %p [#%d] (from %d)", req->sk,
25308 +                                       (req->sk)?req->sk->sk_nid:0, nx_current_nid());
25309 +                               if (req->sk &&
25310 +                                       !nx_check(req->sk->sk_nid, VS_WATCH_P | VS_IDENT))
25311 +                                       continue;
25312                                 if (req->rsk_ops->family == st->family) {
25313                                         cur = req;
25314                                         goto out;
25315 @@ -2035,6 +2041,10 @@ get_req:
25316         }
25317  get_sk:
25318         sk_nulls_for_each_from(sk, node) {
25319 +               vxdprintk(VXD_CBIT(net, 6), "sk: %p [#%d] (from %d)",
25320 +                       sk, sk->sk_nid, nx_current_nid());
25321 +               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
25322 +                       continue;
25323                 if (!net_eq(sock_net(sk), net))
25324                         continue;
25325                 if (sk->sk_family == st->family) {
25326 @@ -2111,6 +2121,11 @@ static void *established_get_first(struc
25327  
25328                 spin_lock_bh(lock);
25329                 sk_nulls_for_each(sk, node, &tcp_hashinfo.ehash[st->bucket].chain) {
25330 +                       vxdprintk(VXD_CBIT(net, 6),
25331 +                               "sk,egf: %p [#%d] (from %d)",
25332 +                               sk, sk->sk_nid, nx_current_nid());
25333 +                       if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
25334 +                               continue;
25335                         if (sk->sk_family != st->family ||
25336                             !net_eq(sock_net(sk), net)) {
25337                                 continue;
25338 @@ -2121,6 +2136,11 @@ static void *established_get_first(struc
25339                 st->state = TCP_SEQ_STATE_TIME_WAIT;
25340                 inet_twsk_for_each(tw, node,
25341                                    &tcp_hashinfo.ehash[st->bucket].twchain) {
25342 +                       vxdprintk(VXD_CBIT(net, 6),
25343 +                               "tw: %p [#%d] (from %d)",
25344 +                               tw, tw->tw_nid, nx_current_nid());
25345 +                       if (!nx_check(tw->tw_nid, VS_WATCH_P | VS_IDENT))
25346 +                               continue;
25347                         if (tw->tw_family != st->family ||
25348                             !net_eq(twsk_net(tw), net)) {
25349                                 continue;
25350 @@ -2150,7 +2170,9 @@ static void *established_get_next(struct
25351                 tw = cur;
25352                 tw = tw_next(tw);
25353  get_tw:
25354 -               while (tw && (tw->tw_family != st->family || !net_eq(twsk_net(tw), net))) {
25355 +               while (tw && (tw->tw_family != st->family ||
25356 +                       !net_eq(twsk_net(tw), net) ||
25357 +                       !nx_check(tw->tw_nid, VS_WATCH_P | VS_IDENT))) {
25358                         tw = tw_next(tw);
25359                 }
25360                 if (tw) {
25361 @@ -2174,6 +2196,11 @@ get_tw:
25362                 sk = sk_nulls_next(sk);
25363  
25364         sk_nulls_for_each_from(sk, node) {
25365 +               vxdprintk(VXD_CBIT(net, 6),
25366 +                       "sk,egn: %p [#%d] (from %d)",
25367 +                       sk, sk->sk_nid, nx_current_nid());
25368 +               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
25369 +                       continue;
25370                 if (sk->sk_family == st->family && net_eq(sock_net(sk), net))
25371                         goto found;
25372         }
25373 @@ -2383,9 +2410,9 @@ static void get_openreq4(struct sock *sk
25374         seq_printf(f, "%4d: %08X:%04X %08X:%04X"
25375                 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %u %d %pK%n",
25376                 i,
25377 -               ireq->loc_addr,
25378 +               nx_map_sock_lback(current_nx_info(), ireq->loc_addr),
25379                 ntohs(inet_sk(sk)->inet_sport),
25380 -               ireq->rmt_addr,
25381 +               nx_map_sock_lback(current_nx_info(), ireq->rmt_addr),
25382                 ntohs(ireq->rmt_port),
25383                 TCP_SYN_RECV,
25384                 0, 0, /* could print option size, but that is af dependent. */
25385 @@ -2407,8 +2434,8 @@ static void get_tcp4_sock(struct sock *s
25386         struct tcp_sock *tp = tcp_sk(sk);
25387         const struct inet_connection_sock *icsk = inet_csk(sk);
25388         struct inet_sock *inet = inet_sk(sk);
25389 -       __be32 dest = inet->inet_daddr;
25390 -       __be32 src = inet->inet_rcv_saddr;
25391 +       __be32 dest = nx_map_sock_lback(current_nx_info(), inet->inet_daddr);
25392 +       __be32 src = nx_map_sock_lback(current_nx_info(), inet->inet_rcv_saddr);
25393         __u16 destp = ntohs(inet->inet_dport);
25394         __u16 srcp = ntohs(inet->inet_sport);
25395         int rx_queue;
25396 @@ -2465,8 +2492,8 @@ static void get_timewait4_sock(struct in
25397         if (ttd < 0)
25398                 ttd = 0;
25399  
25400 -       dest  = tw->tw_daddr;
25401 -       src   = tw->tw_rcv_saddr;
25402 +       dest  = nx_map_sock_lback(current_nx_info(), tw->tw_daddr);
25403 +       src   = nx_map_sock_lback(current_nx_info(), tw->tw_rcv_saddr);
25404         destp = ntohs(tw->tw_dport);
25405         srcp  = ntohs(tw->tw_sport);
25406  
25407 diff -NurpP --minimal linux-3.0.25/net/ipv4/tcp_minisocks.c linux-3.0.25-vs2.3.2.3/net/ipv4/tcp_minisocks.c
25408 --- linux-3.0.25/net/ipv4/tcp_minisocks.c       2011-03-15 18:07:45.000000000 +0100
25409 +++ linux-3.0.25-vs2.3.2.3/net/ipv4/tcp_minisocks.c     2011-06-10 22:11:24.000000000 +0200
25410 @@ -23,6 +23,9 @@
25411  #include <linux/slab.h>
25412  #include <linux/sysctl.h>
25413  #include <linux/workqueue.h>
25414 +#include <linux/vs_limit.h>
25415 +#include <linux/vs_socket.h>
25416 +#include <linux/vs_context.h>
25417  #include <net/tcp.h>
25418  #include <net/inet_common.h>
25419  #include <net/xfrm.h>
25420 @@ -335,6 +338,11 @@ void tcp_time_wait(struct sock *sk, int 
25421                 tcptw->tw_ts_recent     = tp->rx_opt.ts_recent;
25422                 tcptw->tw_ts_recent_stamp = tp->rx_opt.ts_recent_stamp;
25423  
25424 +               tw->tw_xid              = sk->sk_xid;
25425 +               tw->tw_vx_info          = NULL;
25426 +               tw->tw_nid              = sk->sk_nid;
25427 +               tw->tw_nx_info          = NULL;
25428 +
25429  #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
25430                 if (tw->tw_family == PF_INET6) {
25431                         struct ipv6_pinfo *np = inet6_sk(sk);
25432 diff -NurpP --minimal linux-3.0.25/net/ipv4/udp.c linux-3.0.25-vs2.3.2.3/net/ipv4/udp.c
25433 --- linux-3.0.25/net/ipv4/udp.c 2011-07-22 11:18:13.000000000 +0200
25434 +++ linux-3.0.25-vs2.3.2.3/net/ipv4/udp.c       2011-07-27 20:26:14.000000000 +0200
25435 @@ -296,14 +296,7 @@ fail:
25436  }
25437  EXPORT_SYMBOL(udp_lib_get_port);
25438  
25439 -static int ipv4_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2)
25440 -{
25441 -       struct inet_sock *inet1 = inet_sk(sk1), *inet2 = inet_sk(sk2);
25442 -
25443 -       return  (!ipv6_only_sock(sk2)  &&
25444 -                (!inet1->inet_rcv_saddr || !inet2->inet_rcv_saddr ||
25445 -                  inet1->inet_rcv_saddr == inet2->inet_rcv_saddr));
25446 -}
25447 +extern int ipv4_rcv_saddr_equal(const struct sock *, const struct sock *);
25448  
25449  static unsigned int udp4_portaddr_hash(struct net *net, __be32 saddr,
25450                                        unsigned int port)
25451 @@ -338,6 +331,11 @@ static inline int compute_score(struct s
25452                         if (inet->inet_rcv_saddr != daddr)
25453                                 return -1;
25454                         score += 2;
25455 +               } else {
25456 +                       /* block non nx_info ips */
25457 +                       if (!v4_addr_in_nx_info(sk->sk_nx_info,
25458 +                               daddr, NXA_MASK_BIND))
25459 +                               return -1;
25460                 }
25461                 if (inet->inet_daddr) {
25462                         if (inet->inet_daddr != saddr)
25463 @@ -441,6 +439,7 @@ exact_match:
25464         return result;
25465  }
25466  
25467 +
25468  /* UDP is nearly always wildcards out the wazoo, it makes no sense to try
25469   * harder than this. -DaveM
25470   */
25471 @@ -486,6 +485,11 @@ begin:
25472         sk_nulls_for_each_rcu(sk, node, &hslot->head) {
25473                 score = compute_score(sk, net, saddr, hnum, sport,
25474                                       daddr, dport, dif);
25475 +               /* FIXME: disabled?
25476 +               if (score == 9) {
25477 +                       result = sk;
25478 +                       break;
25479 +               } else */
25480                 if (score > badness) {
25481                         result = sk;
25482                         badness = score;
25483 @@ -499,6 +503,7 @@ begin:
25484         if (get_nulls_value(node) != slot)
25485                 goto begin;
25486  
25487 +
25488         if (result) {
25489                 if (unlikely(!atomic_inc_not_zero_hint(&result->sk_refcnt, 2)))
25490                         result = NULL;
25491 @@ -508,6 +513,7 @@ begin:
25492                         goto begin;
25493                 }
25494         }
25495 +
25496         rcu_read_unlock();
25497         return result;
25498  }
25499 @@ -550,8 +556,7 @@ static inline struct sock *udp_v4_mcast_
25500                     udp_sk(s)->udp_port_hash != hnum ||
25501                     (inet->inet_daddr && inet->inet_daddr != rmt_addr) ||
25502                     (inet->inet_dport != rmt_port && inet->inet_dport) ||
25503 -                   (inet->inet_rcv_saddr &&
25504 -                    inet->inet_rcv_saddr != loc_addr) ||
25505 +                   !v4_sock_addr_match(sk->sk_nx_info, inet, loc_addr) ||
25506                     ipv6_only_sock(s) ||
25507                     (s->sk_bound_dev_if && s->sk_bound_dev_if != dif))
25508                         continue;
25509 @@ -929,6 +934,16 @@ int udp_sendmsg(struct kiocb *iocb, stru
25510                                    inet_sk_flowi_flags(sk)|FLOWI_FLAG_CAN_SLEEP,
25511                                    faddr, saddr, dport, inet->inet_sport);
25512  
25513 +               if (sk->sk_nx_info) {
25514 +                       rt = ip_v4_find_src(net, sk->sk_nx_info, fl4);
25515 +                       if (IS_ERR(rt)) {
25516 +                               err = PTR_ERR(rt);
25517 +                               rt = NULL;
25518 +                               goto out;
25519 +                       }
25520 +                       ip_rt_put(rt);
25521 +               }
25522 +
25523                 security_sk_classify_flow(sk, flowi4_to_flowi(fl4));
25524                 rt = ip_route_output_flow(net, fl4, sk);
25525                 if (IS_ERR(rt)) {
25526 @@ -1226,7 +1241,8 @@ try_again:
25527         if (sin) {
25528                 sin->sin_family = AF_INET;
25529                 sin->sin_port = udp_hdr(skb)->source;
25530 -               sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
25531 +               sin->sin_addr.s_addr = nx_map_sock_lback(
25532 +                       skb->sk->sk_nx_info, ip_hdr(skb)->saddr);
25533                 memset(sin->sin_zero, 0, sizeof(sin->sin_zero));
25534         }
25535         if (inet->cmsg_flags)
25536 @@ -1970,6 +1986,8 @@ static struct sock *udp_get_first(struct
25537                 sk_nulls_for_each(sk, node, &hslot->head) {
25538                         if (!net_eq(sock_net(sk), net))
25539                                 continue;
25540 +                       if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
25541 +                               continue;
25542                         if (sk->sk_family == state->family)
25543                                 goto found;
25544                 }
25545 @@ -1987,7 +2005,9 @@ static struct sock *udp_get_next(struct 
25546  
25547         do {
25548                 sk = sk_nulls_next(sk);
25549 -       } while (sk && (!net_eq(sock_net(sk), net) || sk->sk_family != state->family));
25550 +       } while (sk && (!net_eq(sock_net(sk), net) ||
25551 +               sk->sk_family != state->family ||
25552 +               !nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT)));
25553  
25554         if (!sk) {
25555                 if (state->bucket <= state->udp_table->mask)
25556 diff -NurpP --minimal linux-3.0.25/net/ipv6/Kconfig linux-3.0.25-vs2.3.2.3/net/ipv6/Kconfig
25557 --- linux-3.0.25/net/ipv6/Kconfig       2010-08-02 16:52:59.000000000 +0200
25558 +++ linux-3.0.25-vs2.3.2.3/net/ipv6/Kconfig     2011-06-10 22:11:24.000000000 +0200
25559 @@ -4,8 +4,8 @@
25560  
25561  #   IPv6 as module will cause a CRASH if you try to unload it
25562  menuconfig IPV6
25563 -       tristate "The IPv6 protocol"
25564 -       default m
25565 +       bool "The IPv6 protocol"
25566 +       default n
25567         ---help---
25568           This is complemental support for the IP version 6.
25569           You will still be able to do traditional IPv4 networking as well.
25570 diff -NurpP --minimal linux-3.0.25/net/ipv6/addrconf.c linux-3.0.25-vs2.3.2.3/net/ipv6/addrconf.c
25571 --- linux-3.0.25/net/ipv6/addrconf.c    2012-03-19 21:16:57.000000000 +0100
25572 +++ linux-3.0.25-vs2.3.2.3/net/ipv6/addrconf.c  2012-03-23 14:54:00.000000000 +0100
25573 @@ -87,6 +87,8 @@
25574  
25575  #include <linux/proc_fs.h>
25576  #include <linux/seq_file.h>
25577 +#include <linux/vs_network.h>
25578 +#include <linux/vs_inet6.h>
25579  
25580  /* Set to 3 to get tracing... */
25581  #define ACONF_DEBUG 2
25582 @@ -1112,7 +1114,7 @@ out:
25583  
25584  int ipv6_dev_get_saddr(struct net *net, struct net_device *dst_dev,
25585                        const struct in6_addr *daddr, unsigned int prefs,
25586 -                      struct in6_addr *saddr)
25587 +                      struct in6_addr *saddr, struct nx_info *nxi)
25588  {
25589         struct ipv6_saddr_score scores[2],
25590                                 *score = &scores[0], *hiscore = &scores[1];
25591 @@ -1184,6 +1186,8 @@ int ipv6_dev_get_saddr(struct net *net, 
25592                                                dev->name);
25593                                 continue;
25594                         }
25595 +                       if (!v6_addr_in_nx_info(nxi, &score->ifa->addr, -1))
25596 +                               continue;
25597  
25598                         score->rule = -1;
25599                         bitmap_zero(score->scorebits, IPV6_SADDR_RULE_MAX);
25600 @@ -3052,7 +3056,10 @@ static void if6_seq_stop(struct seq_file
25601  static int if6_seq_show(struct seq_file *seq, void *v)
25602  {
25603         struct inet6_ifaddr *ifp = (struct inet6_ifaddr *)v;
25604 -       seq_printf(seq, "%pi6 %02x %02x %02x %02x %8s\n",
25605 +
25606 +       if (nx_check(0, VS_ADMIN|VS_WATCH) ||
25607 +           v6_addr_in_nx_info(current_nx_info(), &ifp->addr, -1))
25608 +               seq_printf(seq, "%pi6 %02x %02x %02x %02x %8s\n",
25609                    &ifp->addr,
25610                    ifp->idev->dev->ifindex,
25611                    ifp->prefix_len,
25612 @@ -3558,6 +3565,11 @@ static int in6_dump_addrs(struct inet6_d
25613         struct ifacaddr6 *ifaca;
25614         int err = 1;
25615         int ip_idx = *p_ip_idx;
25616 +       struct nx_info *nxi = skb->sk ? skb->sk->sk_nx_info : NULL;
25617 +
25618 +       /* disable ipv6 on non v6 guests */
25619 +       if (nxi && !nx_info_has_v6(nxi))
25620 +               return skb->len;
25621  
25622         read_lock_bh(&idev->lock);
25623         switch (type) {
25624 @@ -3568,6 +3580,8 @@ static int in6_dump_addrs(struct inet6_d
25625                 list_for_each_entry(ifa, &idev->addr_list, if_list) {
25626                         if (++ip_idx < s_ip_idx)
25627                                 continue;
25628 +                               if (!v6_addr_in_nx_info(nxi, &ifa->addr, -1))
25629 +                                       continue;
25630                         err = inet6_fill_ifaddr(skb, ifa,
25631                                                 NETLINK_CB(cb->skb).pid,
25632                                                 cb->nlh->nlmsg_seq,
25633 @@ -3584,6 +3598,8 @@ static int in6_dump_addrs(struct inet6_d
25634                      ifmca = ifmca->next, ip_idx++) {
25635                         if (ip_idx < s_ip_idx)
25636                                 continue;
25637 +                               if (!v6_addr_in_nx_info(nxi, &ifmca->mca_addr, -1))
25638 +                                       continue;
25639                         err = inet6_fill_ifmcaddr(skb, ifmca,
25640                                                   NETLINK_CB(cb->skb).pid,
25641                                                   cb->nlh->nlmsg_seq,
25642 @@ -3599,6 +3615,8 @@ static int in6_dump_addrs(struct inet6_d
25643                      ifaca = ifaca->aca_next, ip_idx++) {
25644                         if (ip_idx < s_ip_idx)
25645                                 continue;
25646 +                               if (!v6_addr_in_nx_info(nxi, &ifaca->aca_addr, -1))
25647 +                                       continue;
25648                         err = inet6_fill_ifacaddr(skb, ifaca,
25649                                                   NETLINK_CB(cb->skb).pid,
25650                                                   cb->nlh->nlmsg_seq,
25651 @@ -3984,6 +4002,11 @@ static int inet6_dump_ifinfo(struct sk_b
25652         struct inet6_dev *idev;
25653         struct hlist_head *head;
25654         struct hlist_node *node;
25655 +       struct nx_info *nxi = skb->sk ? skb->sk->sk_nx_info : NULL;
25656 +
25657 +       /* FIXME: maybe disable ipv6 on non v6 guests?
25658 +       if (skb->sk && skb->sk->sk_vx_info)
25659 +               return skb->len; */
25660  
25661         s_h = cb->args[0];
25662         s_idx = cb->args[1];
25663 @@ -3995,6 +4018,8 @@ static int inet6_dump_ifinfo(struct sk_b
25664                 hlist_for_each_entry_rcu(dev, node, head, index_hlist) {
25665                         if (idx < s_idx)
25666                                 goto cont;
25667 +                       if (!v6_dev_in_nx_info(dev, nxi))
25668 +                               goto cont;
25669                         idev = __in6_dev_get(dev);
25670                         if (!idev)
25671                                 goto cont;
25672 diff -NurpP --minimal linux-3.0.25/net/ipv6/af_inet6.c linux-3.0.25-vs2.3.2.3/net/ipv6/af_inet6.c
25673 --- linux-3.0.25/net/ipv6/af_inet6.c    2012-03-19 21:16:57.000000000 +0100
25674 +++ linux-3.0.25-vs2.3.2.3/net/ipv6/af_inet6.c  2011-08-29 03:45:10.000000000 +0200
25675 @@ -42,6 +42,8 @@
25676  #include <linux/netdevice.h>
25677  #include <linux/icmpv6.h>
25678  #include <linux/netfilter_ipv6.h>
25679 +#include <linux/vs_inet.h>
25680 +#include <linux/vs_inet6.h>
25681  
25682  #include <net/ip.h>
25683  #include <net/ipv6.h>
25684 @@ -160,9 +162,12 @@ lookup_protocol:
25685         }
25686  
25687         err = -EPERM;
25688 +       if ((protocol == IPPROTO_ICMPV6) &&
25689 +               nx_capable(CAP_NET_RAW, NXC_RAW_ICMP))
25690 +               goto override;
25691         if (sock->type == SOCK_RAW && !kern && !capable(CAP_NET_RAW))
25692                 goto out_rcu_unlock;
25693 -
25694 +override:
25695         sock->ops = answer->ops;
25696         answer_prot = answer->prot;
25697         answer_no_check = answer->no_check;
25698 @@ -261,6 +266,7 @@ int inet6_bind(struct socket *sock, stru
25699         struct inet_sock *inet = inet_sk(sk);
25700         struct ipv6_pinfo *np = inet6_sk(sk);
25701         struct net *net = sock_net(sk);
25702 +       struct nx_v6_sock_addr nsa;
25703         __be32 v4addr = 0;
25704         unsigned short snum;
25705         int addr_type = 0;
25706 @@ -276,6 +282,10 @@ int inet6_bind(struct socket *sock, stru
25707         if (addr->sin6_family != AF_INET6)
25708                 return -EAFNOSUPPORT;
25709  
25710 +       err = v6_map_sock_addr(inet, addr, &nsa);
25711 +       if (err)
25712 +               return err;
25713 +
25714         addr_type = ipv6_addr_type(&addr->sin6_addr);
25715         if ((addr_type & IPV6_ADDR_MULTICAST) && sock->type == SOCK_STREAM)
25716                 return -EINVAL;
25717 @@ -307,6 +317,7 @@ int inet6_bind(struct socket *sock, stru
25718                 /* Reproduce AF_INET checks to make the bindings consistent */
25719                 v4addr = addr->sin6_addr.s6_addr32[3];
25720                 chk_addr_ret = inet_addr_type(net, v4addr);
25721 +
25722                 if (!sysctl_ip_nonlocal_bind &&
25723                     !(inet->freebind || inet->transparent) &&
25724                     v4addr != htonl(INADDR_ANY) &&
25725 @@ -316,6 +327,10 @@ int inet6_bind(struct socket *sock, stru
25726                         err = -EADDRNOTAVAIL;
25727                         goto out;
25728                 }
25729 +               if (!v4_addr_in_nx_info(sk->sk_nx_info, v4addr, NXA_MASK_BIND)) {
25730 +                       err = -EADDRNOTAVAIL;
25731 +                       goto out;
25732 +               }
25733         } else {
25734                 if (addr_type != IPV6_ADDR_ANY) {
25735                         struct net_device *dev = NULL;
25736 @@ -342,6 +357,11 @@ int inet6_bind(struct socket *sock, stru
25737                                 }
25738                         }
25739  
25740 +                       if (!v6_addr_in_nx_info(sk->sk_nx_info, &addr->sin6_addr, -1)) {
25741 +                               err = -EADDRNOTAVAIL;
25742 +                               goto out;
25743 +                       }
25744 +
25745                         /* ipv4 addr of the socket is invalid.  Only the
25746                          * unspecified and mapped address have a v4 equivalent.
25747                          */
25748 @@ -358,6 +378,9 @@ int inet6_bind(struct socket *sock, stru
25749                 }
25750         }
25751  
25752 +       /* what's that for? */
25753 +       v6_set_sock_addr(inet, &nsa);
25754 +
25755         inet->inet_rcv_saddr = v4addr;
25756         inet->inet_saddr = v4addr;
25757  
25758 @@ -459,9 +482,11 @@ int inet6_getname(struct socket *sock, s
25759                         return -ENOTCONN;
25760                 sin->sin6_port = inet->inet_dport;
25761                 ipv6_addr_copy(&sin->sin6_addr, &np->daddr);
25762 +               /* FIXME: remap lback? */
25763                 if (np->sndflow)
25764                         sin->sin6_flowinfo = np->flow_label;
25765         } else {
25766 +               /* FIXME: remap lback? */
25767                 if (ipv6_addr_any(&np->rcv_saddr))
25768                         ipv6_addr_copy(&sin->sin6_addr, &np->saddr);
25769                 else
25770 diff -NurpP --minimal linux-3.0.25/net/ipv6/datagram.c linux-3.0.25-vs2.3.2.3/net/ipv6/datagram.c
25771 --- linux-3.0.25/net/ipv6/datagram.c    2011-05-22 16:18:00.000000000 +0200
25772 +++ linux-3.0.25-vs2.3.2.3/net/ipv6/datagram.c  2011-09-17 19:24:15.000000000 +0200
25773 @@ -639,7 +639,7 @@ int datagram_send_ctl(struct net *net,
25774  
25775                         rcu_read_lock();
25776                         if (fl6->flowi6_oif) {
25777 -                               dev = dev_get_by_index_rcu(net, fl6->flowi6_oif);
25778 +                               dev = dev_get_by_index_real_rcu(net, fl6->flowi6_oif);
25779                                 if (!dev) {
25780                                         rcu_read_unlock();
25781                                         return -ENODEV;
25782 diff -NurpP --minimal linux-3.0.25/net/ipv6/fib6_rules.c linux-3.0.25-vs2.3.2.3/net/ipv6/fib6_rules.c
25783 --- linux-3.0.25/net/ipv6/fib6_rules.c  2011-05-22 16:18:00.000000000 +0200
25784 +++ linux-3.0.25-vs2.3.2.3/net/ipv6/fib6_rules.c        2011-06-10 22:11:24.000000000 +0200
25785 @@ -90,7 +90,7 @@ static int fib6_rule_action(struct fib_r
25786                                                ip6_dst_idev(&rt->dst)->dev,
25787                                                &flp6->daddr,
25788                                                rt6_flags2srcprefs(flags),
25789 -                                              &saddr))
25790 +                                              &saddr, NULL))
25791                                 goto again;
25792                         if (!ipv6_prefix_equal(&saddr, &r->src.addr,
25793                                                r->src.plen))
25794 diff -NurpP --minimal linux-3.0.25/net/ipv6/inet6_hashtables.c linux-3.0.25-vs2.3.2.3/net/ipv6/inet6_hashtables.c
25795 --- linux-3.0.25/net/ipv6/inet6_hashtables.c    2012-03-19 21:16:57.000000000 +0100
25796 +++ linux-3.0.25-vs2.3.2.3/net/ipv6/inet6_hashtables.c  2011-08-29 03:45:10.000000000 +0200
25797 @@ -16,6 +16,7 @@
25798  
25799  #include <linux/module.h>
25800  #include <linux/random.h>
25801 +#include <linux/vs_inet6.h>
25802  
25803  #include <net/inet_connection_sock.h>
25804  #include <net/inet_hashtables.h>
25805 @@ -83,7 +84,6 @@ struct sock *__inet6_lookup_established(
25806         unsigned int slot = hash & hashinfo->ehash_mask;
25807         struct inet_ehash_bucket *head = &hashinfo->ehash[slot];
25808  
25809 -
25810         rcu_read_lock();
25811  begin:
25812         sk_nulls_for_each_rcu(sk, node, &head->chain) {
25813 @@ -95,7 +95,7 @@ begin:
25814                                 sock_put(sk);
25815                                 goto begin;
25816                         }
25817 -               goto out;
25818 +                       goto out;
25819                 }
25820         }
25821         if (get_nulls_value(node) != slot)
25822 @@ -141,6 +141,9 @@ static inline int compute_score(struct s
25823                         if (!ipv6_addr_equal(&np->rcv_saddr, daddr))
25824                                 return -1;
25825                         score++;
25826 +               } else {
25827 +                       if (!v6_addr_in_nx_info(sk->sk_nx_info, daddr, -1))
25828 +                               return -1;
25829                 }
25830                 if (sk->sk_bound_dev_if) {
25831                         if (sk->sk_bound_dev_if != dif)
25832 diff -NurpP --minimal linux-3.0.25/net/ipv6/ip6_output.c linux-3.0.25-vs2.3.2.3/net/ipv6/ip6_output.c
25833 --- linux-3.0.25/net/ipv6/ip6_output.c  2012-03-19 21:16:57.000000000 +0100
25834 +++ linux-3.0.25-vs2.3.2.3/net/ipv6/ip6_output.c        2012-02-15 05:20:43.000000000 +0100
25835 @@ -979,7 +979,8 @@ static int ip6_dst_lookup_tail(struct so
25836                 struct rt6_info *rt = (struct rt6_info *) *dst;
25837                 err = ip6_route_get_saddr(net, rt, &fl6->daddr,
25838                                           sk ? inet6_sk(sk)->srcprefs : 0,
25839 -                                         &fl6->saddr);
25840 +                                         &fl6->saddr,
25841 +                                         sk ? sk->sk_nx_info : NULL);
25842                 if (err)
25843                         goto out_err_release;
25844         }
25845 diff -NurpP --minimal linux-3.0.25/net/ipv6/ndisc.c linux-3.0.25-vs2.3.2.3/net/ipv6/ndisc.c
25846 --- linux-3.0.25/net/ipv6/ndisc.c       2012-03-19 21:16:57.000000000 +0100
25847 +++ linux-3.0.25-vs2.3.2.3/net/ipv6/ndisc.c     2012-02-15 05:20:43.000000000 +0100
25848 @@ -597,7 +597,7 @@ static void ndisc_send_na(struct net_dev
25849         } else {
25850                 if (ipv6_dev_get_saddr(dev_net(dev), dev, daddr,
25851                                        inet6_sk(dev_net(dev)->ipv6.ndisc_sk)->srcprefs,
25852 -                                      &tmpaddr))
25853 +                                      &tmpaddr, NULL))
25854                         return;
25855                 src_addr = &tmpaddr;
25856         }
25857 diff -NurpP --minimal linux-3.0.25/net/ipv6/raw.c linux-3.0.25-vs2.3.2.3/net/ipv6/raw.c
25858 --- linux-3.0.25/net/ipv6/raw.c 2011-07-22 11:18:13.000000000 +0200
25859 +++ linux-3.0.25-vs2.3.2.3/net/ipv6/raw.c       2011-06-10 22:11:24.000000000 +0200
25860 @@ -30,6 +30,7 @@
25861  #include <linux/icmpv6.h>
25862  #include <linux/netfilter.h>
25863  #include <linux/netfilter_ipv6.h>
25864 +#include <linux/vs_inet6.h>
25865  #include <linux/skbuff.h>
25866  #include <linux/compat.h>
25867  #include <asm/uaccess.h>
25868 @@ -284,6 +285,13 @@ static int rawv6_bind(struct sock *sk, s
25869                                 goto out_unlock;
25870                 }
25871  
25872 +               if (!v6_addr_in_nx_info(sk->sk_nx_info, &addr->sin6_addr, -1)) {
25873 +                       err = -EADDRNOTAVAIL;
25874 +                       if (dev)
25875 +                               dev_put(dev);
25876 +                       goto out;
25877 +               }
25878 +
25879                 /* ipv4 addr of the socket is invalid.  Only the
25880                  * unspecified and mapped address have a v4 equivalent.
25881                  */
25882 diff -NurpP --minimal linux-3.0.25/net/ipv6/route.c linux-3.0.25-vs2.3.2.3/net/ipv6/route.c
25883 --- linux-3.0.25/net/ipv6/route.c       2012-03-19 21:16:57.000000000 +0100
25884 +++ linux-3.0.25-vs2.3.2.3/net/ipv6/route.c     2012-02-15 05:20:43.000000000 +0100
25885 @@ -54,6 +54,7 @@
25886  #include <net/xfrm.h>
25887  #include <net/netevent.h>
25888  #include <net/netlink.h>
25889 +#include <linux/vs_inet6.h>
25890  
25891  #include <asm/uaccess.h>
25892  
25893 @@ -2058,15 +2059,17 @@ int ip6_route_get_saddr(struct net *net,
25894                         struct rt6_info *rt,
25895                         const struct in6_addr *daddr,
25896                         unsigned int prefs,
25897 -                       struct in6_addr *saddr)
25898 +                       struct in6_addr *saddr,
25899 +                       struct nx_info *nxi)
25900  {
25901         struct inet6_dev *idev = ip6_dst_idev((struct dst_entry*)rt);
25902         int err = 0;
25903 -       if (rt->rt6i_prefsrc.plen)
25904 +       if (rt->rt6i_prefsrc.plen && (!nxi ||
25905 +           v6_addr_in_nx_info(nxi, &rt->rt6i_prefsrc.addr, NXA_TYPE_ADDR)))
25906                 ipv6_addr_copy(saddr, &rt->rt6i_prefsrc.addr);
25907         else
25908                 err = ipv6_dev_get_saddr(net, idev ? idev->dev : NULL,
25909 -                                        daddr, prefs, saddr);
25910 +                                        daddr, prefs, saddr, nxi);
25911         return err;
25912  }
25913  
25914 @@ -2396,7 +2399,8 @@ static int rt6_fill_node(struct net *net
25915                         NLA_PUT_U32(skb, RTA_IIF, iif);
25916         } else if (dst) {
25917                 struct in6_addr saddr_buf;
25918 -               if (ip6_route_get_saddr(net, rt, dst, 0, &saddr_buf) == 0)
25919 +               if (ip6_route_get_saddr(net, rt, dst, 0, &saddr_buf,
25920 +                                       (skb->sk ? skb->sk->sk_nx_info : NULL)) == 0)
25921                         NLA_PUT(skb, RTA_PREFSRC, 16, &saddr_buf);
25922         }
25923  
25924 @@ -2599,6 +2603,7 @@ static int rt6_info_route(struct rt6_inf
25925         struct seq_file *m = p_arg;
25926         struct neighbour *n;
25927  
25928 +       /* FIXME: check for network context? */
25929         seq_printf(m, "%pi6 %02x ", &rt->rt6i_dst.addr, rt->rt6i_dst.plen);
25930  
25931  #ifdef CONFIG_IPV6_SUBTREES
25932 diff -NurpP --minimal linux-3.0.25/net/ipv6/tcp_ipv6.c linux-3.0.25-vs2.3.2.3/net/ipv6/tcp_ipv6.c
25933 --- linux-3.0.25/net/ipv6/tcp_ipv6.c    2012-03-19 21:16:57.000000000 +0100
25934 +++ linux-3.0.25-vs2.3.2.3/net/ipv6/tcp_ipv6.c  2012-02-07 02:05:58.000000000 +0100
25935 @@ -70,6 +70,7 @@
25936  
25937  #include <linux/crypto.h>
25938  #include <linux/scatterlist.h>
25939 +#include <linux/vs_inet6.h>
25940  
25941  static void    tcp_v6_send_reset(struct sock *sk, struct sk_buff *skb);
25942  static void    tcp_v6_reqsk_send_ack(struct sock *sk, struct sk_buff *skb,
25943 @@ -162,8 +163,15 @@ static int tcp_v6_connect(struct sock *s
25944          *      connect() to INADDR_ANY means loopback (BSD'ism).
25945          */
25946  
25947 -       if(ipv6_addr_any(&usin->sin6_addr))
25948 -               usin->sin6_addr.s6_addr[15] = 0x1;
25949 +       if(ipv6_addr_any(&usin->sin6_addr)) {
25950 +               struct nx_info *nxi =  sk->sk_nx_info;
25951 +
25952 +               if (nxi && nx_info_has_v6(nxi))
25953 +                       /* FIXME: remap lback? */
25954 +                       usin->sin6_addr = nxi->v6.ip;
25955 +               else
25956 +                       usin->sin6_addr.s6_addr[15] = 0x1;
25957 +       }
25958  
25959         addr_type = ipv6_addr_type(&usin->sin6_addr);
25960  
25961 diff -NurpP --minimal linux-3.0.25/net/ipv6/udp.c linux-3.0.25-vs2.3.2.3/net/ipv6/udp.c
25962 --- linux-3.0.25/net/ipv6/udp.c 2012-03-19 21:16:57.000000000 +0100
25963 +++ linux-3.0.25-vs2.3.2.3/net/ipv6/udp.c       2011-10-18 13:51:13.000000000 +0200
25964 @@ -45,41 +45,67 @@
25965  #include <net/tcp_states.h>
25966  #include <net/ip6_checksum.h>
25967  #include <net/xfrm.h>
25968 +#include <linux/vs_inet6.h>
25969  
25970  #include <linux/proc_fs.h>
25971  #include <linux/seq_file.h>
25972  #include "udp_impl.h"
25973  
25974 -int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
25975 +int ipv6_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2)
25976  {
25977 -       const struct in6_addr *sk_rcv_saddr6 = &inet6_sk(sk)->rcv_saddr;
25978 +       const struct in6_addr *sk1_rcv_saddr6 = &inet6_sk(sk1)->rcv_saddr;
25979         const struct in6_addr *sk2_rcv_saddr6 = inet6_rcv_saddr(sk2);
25980 -       __be32 sk1_rcv_saddr = sk_rcv_saddr(sk);
25981 +       __be32 sk1_rcv_saddr = sk_rcv_saddr(sk1);
25982         __be32 sk2_rcv_saddr = sk_rcv_saddr(sk2);
25983 -       int sk_ipv6only = ipv6_only_sock(sk);
25984 +       int sk1_ipv6only = ipv6_only_sock(sk1);
25985         int sk2_ipv6only = inet_v6_ipv6only(sk2);
25986 -       int addr_type = ipv6_addr_type(sk_rcv_saddr6);
25987 +       int addr_type = ipv6_addr_type(sk1_rcv_saddr6);
25988         int addr_type2 = sk2_rcv_saddr6 ? ipv6_addr_type(sk2_rcv_saddr6) : IPV6_ADDR_MAPPED;
25989  
25990         /* if both are mapped, treat as IPv4 */
25991 -       if (addr_type == IPV6_ADDR_MAPPED && addr_type2 == IPV6_ADDR_MAPPED)
25992 -               return (!sk2_ipv6only &&
25993 +       if (addr_type == IPV6_ADDR_MAPPED && addr_type2 == IPV6_ADDR_MAPPED) {
25994 +               if (!sk2_ipv6only &&
25995                         (!sk1_rcv_saddr || !sk2_rcv_saddr ||
25996 -                         sk1_rcv_saddr == sk2_rcv_saddr));
25997 +                         sk1_rcv_saddr == sk2_rcv_saddr))
25998 +                       goto vs_v4;
25999 +               else
26000 +                       return 0;
26001 +       }
26002  
26003         if (addr_type2 == IPV6_ADDR_ANY &&
26004             !(sk2_ipv6only && addr_type == IPV6_ADDR_MAPPED))
26005 -               return 1;
26006 +               goto vs;
26007  
26008         if (addr_type == IPV6_ADDR_ANY &&
26009 -           !(sk_ipv6only && addr_type2 == IPV6_ADDR_MAPPED))
26010 -               return 1;
26011 +           !(sk1_ipv6only && addr_type2 == IPV6_ADDR_MAPPED))
26012 +               goto vs;
26013  
26014         if (sk2_rcv_saddr6 &&
26015 -           ipv6_addr_equal(sk_rcv_saddr6, sk2_rcv_saddr6))
26016 -               return 1;
26017 +           ipv6_addr_equal(sk1_rcv_saddr6, sk2_rcv_saddr6))
26018 +               goto vs;
26019  
26020         return 0;
26021 +
26022 +vs_v4:
26023 +       if (!sk1_rcv_saddr && !sk2_rcv_saddr)
26024 +               return nx_v4_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info);
26025 +       if (!sk2_rcv_saddr)
26026 +               return v4_addr_in_nx_info(sk1->sk_nx_info, sk2_rcv_saddr, -1);
26027 +       if (!sk1_rcv_saddr)
26028 +               return v4_addr_in_nx_info(sk2->sk_nx_info, sk1_rcv_saddr, -1);
26029 +       return 1;
26030 +vs:
26031 +       if (addr_type2 == IPV6_ADDR_ANY && addr_type == IPV6_ADDR_ANY)
26032 +               return nx_v6_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info);
26033 +       else if (addr_type2 == IPV6_ADDR_ANY)
26034 +               return v6_addr_in_nx_info(sk2->sk_nx_info, sk1_rcv_saddr6, -1);
26035 +       else if (addr_type == IPV6_ADDR_ANY) {
26036 +               if (addr_type2 == IPV6_ADDR_MAPPED)
26037 +                       return nx_v4_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info);
26038 +               else
26039 +                       return v6_addr_in_nx_info(sk1->sk_nx_info, sk2_rcv_saddr6, -1);
26040 +       }
26041 +       return 1;
26042  }
26043  
26044  static unsigned int udp6_portaddr_hash(struct net *net,
26045 @@ -143,6 +169,10 @@ static inline int compute_score(struct s
26046                         if (!ipv6_addr_equal(&np->rcv_saddr, daddr))
26047                                 return -1;
26048                         score++;
26049 +               } else {
26050 +                       /* block non nx_info ips */
26051 +                       if (!v6_addr_in_nx_info(sk->sk_nx_info, daddr, -1))
26052 +                               return -1;
26053                 }
26054                 if (!ipv6_addr_any(&np->daddr)) {
26055                         if (!ipv6_addr_equal(&np->daddr, saddr))
26056 diff -NurpP --minimal linux-3.0.25/net/ipv6/xfrm6_policy.c linux-3.0.25-vs2.3.2.3/net/ipv6/xfrm6_policy.c
26057 --- linux-3.0.25/net/ipv6/xfrm6_policy.c        2011-07-22 11:18:13.000000000 +0200
26058 +++ linux-3.0.25-vs2.3.2.3/net/ipv6/xfrm6_policy.c      2011-06-10 22:11:24.000000000 +0200
26059 @@ -63,7 +63,7 @@ static int xfrm6_get_saddr(struct net *n
26060         dev = ip6_dst_idev(dst)->dev;
26061         ipv6_dev_get_saddr(dev_net(dev), dev,
26062                            (struct in6_addr *)&daddr->a6, 0,
26063 -                          (struct in6_addr *)&saddr->a6);
26064 +                          (struct in6_addr *)&saddr->a6, NULL);
26065         dst_release(dst);
26066         return 0;
26067  }
26068 diff -NurpP --minimal linux-3.0.25/net/netfilter/ipvs/ip_vs_xmit.c linux-3.0.25-vs2.3.2.3/net/netfilter/ipvs/ip_vs_xmit.c
26069 --- linux-3.0.25/net/netfilter/ipvs/ip_vs_xmit.c        2011-07-22 11:18:13.000000000 +0200
26070 +++ linux-3.0.25-vs2.3.2.3/net/netfilter/ipvs/ip_vs_xmit.c      2011-07-22 15:27:52.000000000 +0200
26071 @@ -226,7 +226,7 @@ __ip_vs_route_output_v6(struct net *net,
26072                 return dst;
26073         if (ipv6_addr_any(&fl6.saddr) &&
26074             ipv6_dev_get_saddr(net, ip6_dst_idev(dst)->dev,
26075 -                              &fl6.daddr, 0, &fl6.saddr) < 0)
26076 +                              &fl6.daddr, 0, &fl6.saddr, NULL) < 0)
26077                 goto out_err;
26078         if (do_xfrm) {
26079                 dst = xfrm_lookup(net, dst, flowi6_to_flowi(&fl6), NULL, 0);
26080 diff -NurpP --minimal linux-3.0.25/net/netlink/af_netlink.c linux-3.0.25-vs2.3.2.3/net/netlink/af_netlink.c
26081 --- linux-3.0.25/net/netlink/af_netlink.c       2011-07-22 11:18:13.000000000 +0200
26082 +++ linux-3.0.25-vs2.3.2.3/net/netlink/af_netlink.c     2011-06-10 22:11:24.000000000 +0200
26083 @@ -55,6 +55,9 @@
26084  #include <linux/types.h>
26085  #include <linux/audit.h>
26086  #include <linux/mutex.h>
26087 +#include <linux/vs_context.h>
26088 +#include <linux/vs_network.h>
26089 +#include <linux/vs_limit.h>
26090  
26091  #include <net/net_namespace.h>
26092  #include <net/sock.h>
26093 @@ -1907,6 +1910,8 @@ static struct sock *netlink_seq_socket_i
26094                         sk_for_each(s, node, &hash->table[j]) {
26095                                 if (sock_net(s) != seq_file_net(seq))
26096                                         continue;
26097 +                               if (!nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT))
26098 +                                       continue;
26099                                 if (off == pos) {
26100                                         iter->link = i;
26101                                         iter->hash_idx = j;
26102 @@ -1941,7 +1946,8 @@ static void *netlink_seq_next(struct seq
26103         s = v;
26104         do {
26105                 s = sk_next(s);
26106 -       } while (s && sock_net(s) != seq_file_net(seq));
26107 +       } while (s && (sock_net(s) != seq_file_net(seq) ||
26108 +               !nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT)));
26109         if (s)
26110                 return s;
26111  
26112 @@ -1953,7 +1959,8 @@ static void *netlink_seq_next(struct seq
26113  
26114                 for (; j <= hash->mask; j++) {
26115                         s = sk_head(&hash->table[j]);
26116 -                       while (s && sock_net(s) != seq_file_net(seq))
26117 +                       while (s && (sock_net(s) != seq_file_net(seq) ||
26118 +                               !nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT)))
26119                                 s = sk_next(s);
26120                         if (s) {
26121                                 iter->link = i;
26122 diff -NurpP --minimal linux-3.0.25/net/socket.c linux-3.0.25-vs2.3.2.3/net/socket.c
26123 --- linux-3.0.25/net/socket.c   2012-03-19 21:16:58.000000000 +0100
26124 +++ linux-3.0.25-vs2.3.2.3/net/socket.c 2011-10-18 13:51:13.000000000 +0200
26125 @@ -98,6 +98,10 @@
26126  
26127  #include <net/sock.h>
26128  #include <linux/netfilter.h>
26129 +#include <linux/vs_base.h>
26130 +#include <linux/vs_socket.h>
26131 +#include <linux/vs_inet.h>
26132 +#include <linux/vs_inet6.h>
26133  
26134  #include <linux/if_tun.h>
26135  #include <linux/ipv6_route.h>
26136 @@ -546,6 +550,7 @@ static inline int __sock_sendmsg_nosec(s
26137                                        struct msghdr *msg, size_t size)
26138  {
26139         struct sock_iocb *si = kiocb_to_siocb(iocb);
26140 +       size_t len;
26141  
26142         sock_update_classid(sock->sk);
26143  
26144 @@ -554,7 +559,22 @@ static inline int __sock_sendmsg_nosec(s
26145         si->msg = msg;
26146         si->size = size;
26147  
26148 -       return sock->ops->sendmsg(iocb, sock, msg, size);
26149 +       len = sock->ops->sendmsg(iocb, sock, msg, size);
26150 +       if (sock->sk) {
26151 +               if (len == size)
26152 +                       vx_sock_send(sock->sk, size);
26153 +               else
26154 +                       vx_sock_fail(sock->sk, size);
26155 +       }
26156 +       vxdprintk(VXD_CBIT(net, 7),
26157 +               "__sock_sendmsg: %p[%p,%p,%p;%d/%d]:%d/%zu",
26158 +               sock, sock->sk,
26159 +               (sock->sk)?sock->sk->sk_nx_info:0,
26160 +               (sock->sk)?sock->sk->sk_vx_info:0,
26161 +               (sock->sk)?sock->sk->sk_xid:0,
26162 +               (sock->sk)?sock->sk->sk_nid:0,
26163 +               (unsigned int)size, len);
26164 +       return len;
26165  }
26166  
26167  static inline int __sock_sendmsg(struct kiocb *iocb, struct socket *sock,
26168 @@ -694,6 +714,7 @@ static inline int __sock_recvmsg_nosec(s
26169                                        struct msghdr *msg, size_t size, int flags)
26170  {
26171         struct sock_iocb *si = kiocb_to_siocb(iocb);
26172 +       int len;
26173  
26174         sock_update_classid(sock->sk);
26175  
26176 @@ -703,7 +724,18 @@ static inline int __sock_recvmsg_nosec(s
26177         si->size = size;
26178         si->flags = flags;
26179  
26180 -       return sock->ops->recvmsg(iocb, sock, msg, size, flags);
26181 +       len = sock->ops->recvmsg(iocb, sock, msg, size, flags);
26182 +       if ((len >= 0) && sock->sk)
26183 +               vx_sock_recv(sock->sk, len);
26184 +       vxdprintk(VXD_CBIT(net, 7),
26185 +               "__sock_recvmsg: %p[%p,%p,%p;%d/%d]:%d/%d",
26186 +               sock, sock->sk,
26187 +               (sock->sk)?sock->sk->sk_nx_info:0,
26188 +               (sock->sk)?sock->sk->sk_vx_info:0,
26189 +               (sock->sk)?sock->sk->sk_xid:0,
26190 +               (sock->sk)?sock->sk->sk_nid:0,
26191 +               (unsigned int)size, len);
26192 +       return len;
26193  }
26194  
26195  static inline int __sock_recvmsg(struct kiocb *iocb, struct socket *sock,
26196 @@ -1188,6 +1220,13 @@ int __sock_create(struct net *net, int f
26197         if (type < 0 || type >= SOCK_MAX)
26198                 return -EINVAL;
26199  
26200 +       if (!nx_check(0, VS_ADMIN)) {
26201 +               if (family == PF_INET && !current_nx_info_has_v4())
26202 +                       return -EAFNOSUPPORT;
26203 +               if (family == PF_INET6 && !current_nx_info_has_v6())
26204 +                       return -EAFNOSUPPORT;
26205 +       }
26206 +
26207         /* Compatibility.
26208  
26209            This uglymoron is moved from INET layer to here to avoid
26210 @@ -1323,6 +1362,7 @@ SYSCALL_DEFINE3(socket, int, family, int
26211         if (retval < 0)
26212                 goto out;
26213  
26214 +       set_bit(SOCK_USER_SOCKET, &sock->flags);
26215         retval = sock_map_fd(sock, flags & (O_CLOEXEC | O_NONBLOCK));
26216         if (retval < 0)
26217                 goto out_release;
26218 @@ -1364,10 +1404,12 @@ SYSCALL_DEFINE4(socketpair, int, family,
26219         err = sock_create(family, type, protocol, &sock1);
26220         if (err < 0)
26221                 goto out;
26222 +       set_bit(SOCK_USER_SOCKET, &sock1->flags);
26223  
26224         err = sock_create(family, type, protocol, &sock2);
26225         if (err < 0)
26226                 goto out_release_1;
26227 +       set_bit(SOCK_USER_SOCKET, &sock2->flags);
26228  
26229         err = sock1->ops->socketpair(sock1, sock2);
26230         if (err < 0)
26231 diff -NurpP --minimal linux-3.0.25/net/sunrpc/auth.c linux-3.0.25-vs2.3.2.3/net/sunrpc/auth.c
26232 --- linux-3.0.25/net/sunrpc/auth.c      2011-07-22 11:18:13.000000000 +0200
26233 +++ linux-3.0.25-vs2.3.2.3/net/sunrpc/auth.c    2011-06-10 22:11:24.000000000 +0200
26234 @@ -14,6 +14,7 @@
26235  #include <linux/hash.h>
26236  #include <linux/sunrpc/clnt.h>
26237  #include <linux/spinlock.h>
26238 +#include <linux/vs_tag.h>
26239  
26240  #ifdef RPC_DEBUG
26241  # define RPCDBG_FACILITY       RPCDBG_AUTH
26242 @@ -427,6 +428,7 @@ rpcauth_lookupcred(struct rpc_auth *auth
26243         memset(&acred, 0, sizeof(acred));
26244         acred.uid = cred->fsuid;
26245         acred.gid = cred->fsgid;
26246 +       acred.tag = dx_current_tag();
26247         acred.group_info = get_group_info(((struct cred *)cred)->group_info);
26248  
26249         ret = auth->au_ops->lookup_cred(auth, &acred, flags);
26250 @@ -467,6 +469,7 @@ rpcauth_bind_root_cred(struct rpc_task *
26251         struct auth_cred acred = {
26252                 .uid = 0,
26253                 .gid = 0,
26254 +               .tag = dx_current_tag(),
26255         };
26256  
26257         dprintk("RPC: %5u looking up %s cred\n",
26258 diff -NurpP --minimal linux-3.0.25/net/sunrpc/auth_unix.c linux-3.0.25-vs2.3.2.3/net/sunrpc/auth_unix.c
26259 --- linux-3.0.25/net/sunrpc/auth_unix.c 2012-03-19 21:16:58.000000000 +0100
26260 +++ linux-3.0.25-vs2.3.2.3/net/sunrpc/auth_unix.c       2011-11-15 17:37:07.000000000 +0100
26261 @@ -12,12 +12,14 @@
26262  #include <linux/module.h>
26263  #include <linux/sunrpc/clnt.h>
26264  #include <linux/sunrpc/auth.h>
26265 +#include <linux/vs_tag.h>
26266  
26267  #define NFS_NGROUPS    16
26268  
26269  struct unx_cred {
26270         struct rpc_cred         uc_base;
26271         gid_t                   uc_gid;
26272 +       tag_t                   uc_tag;
26273         gid_t                   uc_gids[NFS_NGROUPS];
26274  };
26275  #define uc_uid                 uc_base.cr_uid
26276 @@ -78,6 +80,7 @@ unx_create_cred(struct rpc_auth *auth, s
26277                 groups = NFS_NGROUPS;
26278  
26279         cred->uc_gid = acred->gid;
26280 +       cred->uc_tag = acred->tag;
26281         for (i = 0; i < groups; i++)
26282                 cred->uc_gids[i] = GROUP_AT(acred->group_info, i);
26283         if (i < NFS_NGROUPS)
26284 @@ -119,7 +122,9 @@ unx_match(struct auth_cred *acred, struc
26285         unsigned int i;
26286  
26287  
26288 -       if (cred->uc_uid != acred->uid || cred->uc_gid != acred->gid)
26289 +       if (cred->uc_uid != acred->uid ||
26290 +               cred->uc_gid != acred->gid ||
26291 +               cred->uc_tag != acred->tag)
26292                 return 0;
26293  
26294         if (acred->group_info != NULL)
26295 @@ -145,7 +150,7 @@ unx_marshal(struct rpc_task *task, __be3
26296         struct rpc_clnt *clnt = task->tk_client;
26297         struct unx_cred *cred = container_of(task->tk_rqstp->rq_cred, struct unx_cred, uc_base);
26298         __be32          *base, *hold;
26299 -       int             i;
26300 +       int             i, tag;
26301  
26302         *p++ = htonl(RPC_AUTH_UNIX);
26303         base = p++;
26304 @@ -155,9 +160,12 @@ unx_marshal(struct rpc_task *task, __be3
26305          * Copy the UTS nodename captured when the client was created.
26306          */
26307         p = xdr_encode_array(p, clnt->cl_nodename, clnt->cl_nodelen);
26308 +       tag = task->tk_client->cl_tag;
26309  
26310 -       *p++ = htonl((u32) cred->uc_uid);
26311 -       *p++ = htonl((u32) cred->uc_gid);
26312 +       *p++ = htonl((u32) TAGINO_UID(tag,
26313 +               cred->uc_uid, cred->uc_tag));
26314 +       *p++ = htonl((u32) TAGINO_GID(tag,
26315 +               cred->uc_gid, cred->uc_tag));
26316         hold = p++;
26317         for (i = 0; i < 16 && cred->uc_gids[i] != (gid_t) NOGROUP; i++)
26318                 *p++ = htonl((u32) cred->uc_gids[i]);
26319 diff -NurpP --minimal linux-3.0.25/net/sunrpc/clnt.c linux-3.0.25-vs2.3.2.3/net/sunrpc/clnt.c
26320 --- linux-3.0.25/net/sunrpc/clnt.c      2011-07-22 11:18:13.000000000 +0200
26321 +++ linux-3.0.25-vs2.3.2.3/net/sunrpc/clnt.c    2011-07-01 11:35:35.000000000 +0200
26322 @@ -31,6 +31,7 @@
26323  #include <linux/in.h>
26324  #include <linux/in6.h>
26325  #include <linux/un.h>
26326 +#include <linux/vs_cvirt.h>
26327  
26328  #include <linux/sunrpc/clnt.h>
26329  #include <linux/sunrpc/rpc_pipe_fs.h>
26330 @@ -362,6 +363,9 @@ struct rpc_clnt *rpc_create(struct rpc_c
26331         if (!(args->flags & RPC_CLNT_CREATE_QUIET))
26332                 clnt->cl_chatty = 1;
26333  
26334 +       /* TODO: handle RPC_CLNT_CREATE_TAGGED
26335 +       if (args->flags & RPC_CLNT_CREATE_TAGGED)
26336 +               clnt->cl_tag = 1; */
26337         return clnt;
26338  }
26339  EXPORT_SYMBOL_GPL(rpc_create);
26340 diff -NurpP --minimal linux-3.0.25/net/unix/af_unix.c linux-3.0.25-vs2.3.2.3/net/unix/af_unix.c
26341 --- linux-3.0.25/net/unix/af_unix.c     2011-07-22 11:18:13.000000000 +0200
26342 +++ linux-3.0.25-vs2.3.2.3/net/unix/af_unix.c   2011-06-10 22:11:24.000000000 +0200
26343 @@ -114,6 +114,8 @@
26344  #include <linux/mount.h>
26345  #include <net/checksum.h>
26346  #include <linux/security.h>
26347 +#include <linux/vs_context.h>
26348 +#include <linux/vs_limit.h>
26349  
26350  static struct hlist_head unix_socket_table[UNIX_HASH_SIZE + 1];
26351  static DEFINE_SPINLOCK(unix_table_lock);
26352 @@ -258,6 +260,8 @@ static struct sock *__unix_find_socket_b
26353                 if (!net_eq(sock_net(s), net))
26354                         continue;
26355  
26356 +               if (!nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT))
26357 +                       continue;
26358                 if (u->addr->len == len &&
26359                     !memcmp(u->addr->name, sunname, len))
26360                         goto found;
26361 @@ -2208,6 +2212,8 @@ static struct sock *unix_seq_idx(struct 
26362         for (s = first_unix_socket(&iter->i); s; s = next_unix_socket(&iter->i, s)) {
26363                 if (sock_net(s) != seq_file_net(seq))
26364                         continue;
26365 +               if (!nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT))
26366 +                       continue;
26367                 if (off == pos)
26368                         return s;
26369                 ++off;
26370 @@ -2232,7 +2238,8 @@ static void *unix_seq_next(struct seq_fi
26371                 sk = first_unix_socket(&iter->i);
26372         else
26373                 sk = next_unix_socket(&iter->i, sk);
26374 -       while (sk && (sock_net(sk) != seq_file_net(seq)))
26375 +       while (sk && (sock_net(sk) != seq_file_net(seq) ||
26376 +               !nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT)))
26377                 sk = next_unix_socket(&iter->i, sk);
26378         return sk;
26379  }
26380 diff -NurpP --minimal linux-3.0.25/scripts/checksyscalls.sh linux-3.0.25-vs2.3.2.3/scripts/checksyscalls.sh
26381 --- linux-3.0.25/scripts/checksyscalls.sh       2011-03-15 18:07:46.000000000 +0100
26382 +++ linux-3.0.25-vs2.3.2.3/scripts/checksyscalls.sh     2011-06-10 22:11:24.000000000 +0200
26383 @@ -193,7 +193,6 @@ cat << EOF
26384  #define __IGNORE_afs_syscall
26385  #define __IGNORE_getpmsg
26386  #define __IGNORE_putpmsg
26387 -#define __IGNORE_vserver
26388  EOF
26389  }
26390  
26391 diff -NurpP --minimal linux-3.0.25/security/commoncap.c linux-3.0.25-vs2.3.2.3/security/commoncap.c
26392 --- linux-3.0.25/security/commoncap.c   2011-07-22 11:18:14.000000000 +0200
26393 +++ linux-3.0.25-vs2.3.2.3/security/commoncap.c 2011-08-30 15:42:43.000000000 +0200
26394 @@ -62,6 +62,7 @@ int cap_netlink_recv(struct sk_buff *skb
26395                 return -EPERM;
26396         return 0;
26397  }
26398 +
26399  EXPORT_SYMBOL(cap_netlink_recv);
26400  
26401  /**
26402 @@ -83,14 +84,20 @@ EXPORT_SYMBOL(cap_netlink_recv);
26403  int cap_capable(struct task_struct *tsk, const struct cred *cred,
26404                 struct user_namespace *targ_ns, int cap, int audit)
26405  {
26406 +       struct vx_info *vxi = tsk->vx_info;
26407 +
26408         for (;;) {
26409                 /* The creator of the user namespace has all caps. */
26410                 if (targ_ns != &init_user_ns && targ_ns->creator == cred->user)
26411                         return 0;
26412  
26413                 /* Do we have the necessary capabilities? */
26414 -               if (targ_ns == cred->user->user_ns)
26415 -                       return cap_raised(cred->cap_effective, cap) ? 0 : -EPERM;
26416 +               if (targ_ns == cred->user->user_ns) {
26417 +                       if (vx_info_flags(vxi, VXF_STATE_SETUP, 0) &&
26418 +                           cap_raised(cred->cap_effective, cap))
26419 +                               return 0;
26420 +                       return vx_cap_raised(vxi, cred->cap_effective, cap) ? 0 : -EPERM;
26421 +               }
26422  
26423                 /* Have we tried all of the parent namespaces? */
26424                 if (targ_ns == &init_user_ns)
26425 @@ -611,7 +618,7 @@ int cap_inode_setxattr(struct dentry *de
26426  
26427         if (!strncmp(name, XATTR_SECURITY_PREFIX,
26428                      sizeof(XATTR_SECURITY_PREFIX) - 1) &&
26429 -           !capable(CAP_SYS_ADMIN))
26430 +               !vx_capable(CAP_SYS_ADMIN, VXC_FS_SECURITY))
26431                 return -EPERM;
26432         return 0;
26433  }
26434 @@ -637,7 +644,7 @@ int cap_inode_removexattr(struct dentry 
26435  
26436         if (!strncmp(name, XATTR_SECURITY_PREFIX,
26437                      sizeof(XATTR_SECURITY_PREFIX) - 1) &&
26438 -           !capable(CAP_SYS_ADMIN))
26439 +               !vx_capable(CAP_SYS_ADMIN, VXC_FS_SECURITY))
26440                 return -EPERM;
26441         return 0;
26442  }
26443 diff -NurpP --minimal linux-3.0.25/security/selinux/hooks.c linux-3.0.25-vs2.3.2.3/security/selinux/hooks.c
26444 --- linux-3.0.25/security/selinux/hooks.c       2011-07-22 11:18:14.000000000 +0200
26445 +++ linux-3.0.25-vs2.3.2.3/security/selinux/hooks.c     2011-06-15 02:40:14.000000000 +0200
26446 @@ -67,7 +67,6 @@
26447  #include <linux/dccp.h>
26448  #include <linux/quota.h>
26449  #include <linux/un.h>          /* for Unix socket types */
26450 -#include <net/af_unix.h>       /* for Unix socket types */
26451  #include <linux/parser.h>
26452  #include <linux/nfs_mount.h>
26453  #include <net/ipv6.h>
This page took 1.929494 seconds and 2 git commands to generate.