]> git.pld-linux.org Git - packages/kernel.git/blob - kernel-vserver-2.3.patch
up to 3.0.50
[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 --- linux-3.0.50/kernel/exit.c~ 2012-11-03 12:37:12.001220335 +0200
14644 +++ linux-3.0.50/kernel/exit.c  2012-11-03 12:44:28.779379101 +0200
14645 @@ -48,6 +48,10 @@
14646  #include <linux/fs_struct.h>
14647  #include <linux/init_task.h>
14648  #include <linux/perf_event.h>
14649 +#include <linux/vs_limit.h>
14650 +#include <linux/vs_context.h>
14651 +#include <linux/vs_network.h>
14652 +#include <linux/vs_pid.h>
14653  #include <trace/events/sched.h>
14654  #include <linux/hw_breakpoint.h>
14655  #include <linux/oom.h>
14656 @@ -494,9 +498,11 @@ static void close_files(struct files_str
14657                                         filp_close(file, files);
14658                                         cond_resched();
14659                                 }
14660 +                               vx_openfd_dec(i);
14661                         }
14662                         i++;
14663                         set >>= 1;
14664 +                       cond_resched();
14665                 }
14666         }
14667  }
14668 @@ -1053,6 +1053,10 @@
14669  
14670         validate_creds_for_do_exit(tsk);
14671  
14672 +       /* needs to stay after exit_notify() */
14673 +       exit_vx_info(tsk, code);
14674 +       exit_nx_info(tsk);
14675 +
14676         preempt_disable();
14677         exit_rcu();
14678  
14679 @@ -1074,6 +1078,7 @@
14680         /* causes final put_task_struct in finish_task_switch(). */
14681         tsk->state = TASK_DEAD;
14682         schedule();
14683 +       printk("bad task: %p [%lx]\n", current, current->state);
14684         BUG();
14685         /* Avoid "noreturn function does return".  */
14686         for (;;)
14687 diff -NurpP --minimal linux-3.0.25/kernel/fork.c linux-3.0.25-vs2.3.2.3/kernel/fork.c
14688 --- linux-3.0.25/kernel/fork.c  2012-03-19 21:16:56.000000000 +0100
14689 +++ linux-3.0.25-vs2.3.2.3/kernel/fork.c        2012-03-01 21:52:38.000000000 +0100
14690 @@ -68,6 +68,10 @@
14691  #include <linux/oom.h>
14692  #include <linux/khugepaged.h>
14693  #include <linux/signalfd.h>
14694 +#include <linux/vs_context.h>
14695 +#include <linux/vs_network.h>
14696 +#include <linux/vs_limit.h>
14697 +#include <linux/vs_memory.h>
14698  
14699  #include <asm/pgtable.h>
14700  #include <asm/pgalloc.h>
14701 @@ -168,6 +172,8 @@ void free_task(struct task_struct *tsk)
14702         account_kernel_stack(tsk->stack, -1);
14703         free_thread_info(tsk->stack);
14704         rt_mutex_debug_task_free(tsk);
14705 +       clr_vx_info(&tsk->vx_info);
14706 +       clr_nx_info(&tsk->nx_info);
14707         ftrace_graph_exit_task(tsk);
14708         free_task_struct(tsk);
14709  }
14710 @@ -506,6 +512,7 @@ static struct mm_struct * mm_init(struct
14711         if (likely(!mm_alloc_pgd(mm))) {
14712                 mm->def_flags = 0;
14713                 mmu_notifier_mm_init(mm);
14714 +               set_vx_info(&mm->mm_vx_info, p->vx_info);
14715                 return mm;
14716         }
14717  
14718 @@ -543,6 +550,7 @@ void __mmdrop(struct mm_struct *mm)
14719  #ifdef CONFIG_TRANSPARENT_HUGEPAGE
14720         VM_BUG_ON(mm->pmd_huge_pte);
14721  #endif
14722 +       clr_vx_info(&mm->mm_vx_info);
14723         free_mm(mm);
14724  }
14725  EXPORT_SYMBOL_GPL(__mmdrop);
14726 @@ -730,6 +738,7 @@ struct mm_struct *dup_mm(struct task_str
14727                 goto fail_nomem;
14728  
14729         memcpy(mm, oldmm, sizeof(*mm));
14730 +       mm->mm_vx_info = NULL;
14731         mm_init_cpumask(mm);
14732  
14733         /* Initializing for Swap token stuff */
14734 @@ -773,6 +782,7 @@ fail_nocontext:
14735          * If init_new_context() failed, we cannot use mmput() to free the mm
14736          * because it calls destroy_context()
14737          */
14738 +       clr_vx_info(&mm->mm_vx_info);
14739         mm_free_pgd(mm);
14740         free_mm(mm);
14741         return NULL;
14742 @@ -1060,6 +1070,8 @@ static struct task_struct *copy_process(
14743         int retval;
14744         struct task_struct *p;
14745         int cgroup_callbacks_done = 0;
14746 +       struct vx_info *vxi;
14747 +       struct nx_info *nxi;
14748  
14749         if ((clone_flags & (CLONE_NEWNS|CLONE_FS)) == (CLONE_NEWNS|CLONE_FS))
14750                 return ERR_PTR(-EINVAL);
14751 @@ -1106,7 +1118,12 @@ static struct task_struct *copy_process(
14752         DEBUG_LOCKS_WARN_ON(!p->hardirqs_enabled);
14753         DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
14754  #endif
14755 +       init_vx_info(&p->vx_info, current_vx_info());
14756 +       init_nx_info(&p->nx_info, current_nx_info());
14757 +
14758         retval = -EAGAIN;
14759 +       if (!vx_nproc_avail(1))
14760 +               goto bad_fork_free;
14761         if (atomic_read(&p->real_cred->user->processes) >=
14762                         task_rlimit(p, RLIMIT_NPROC)) {
14763                 if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE) &&
14764 @@ -1363,6 +1380,18 @@ static struct task_struct *copy_process(
14765  
14766         total_forks++;
14767         spin_unlock(&current->sighand->siglock);
14768 +
14769 +       /* p is copy of current */
14770 +       vxi = p->vx_info;
14771 +       if (vxi) {
14772 +               claim_vx_info(vxi, p);
14773 +               atomic_inc(&vxi->cvirt.nr_threads);
14774 +               atomic_inc(&vxi->cvirt.total_forks);
14775 +               vx_nproc_inc(p);
14776 +       }
14777 +       nxi = p->nx_info;
14778 +       if (nxi)
14779 +               claim_nx_info(nxi, p);
14780         write_unlock_irq(&tasklist_lock);
14781         proc_fork_connector(p);
14782         cgroup_post_fork(p);
14783 diff -NurpP --minimal linux-3.0.25/kernel/kthread.c linux-3.0.25-vs2.3.2.3/kernel/kthread.c
14784 --- linux-3.0.25/kernel/kthread.c       2011-07-22 11:18:12.000000000 +0200
14785 +++ linux-3.0.25-vs2.3.2.3/kernel/kthread.c     2011-06-10 22:11:24.000000000 +0200
14786 @@ -16,6 +16,7 @@
14787  #include <linux/mutex.h>
14788  #include <linux/slab.h>
14789  #include <linux/freezer.h>
14790 +#include <linux/vs_pid.h>
14791  #include <trace/events/sched.h>
14792  
14793  static DEFINE_SPINLOCK(kthread_create_lock);
14794 diff -NurpP --minimal linux-3.0.25/kernel/nsproxy.c linux-3.0.25-vs2.3.2.3/kernel/nsproxy.c
14795 --- linux-3.0.25/kernel/nsproxy.c       2011-07-22 11:18:12.000000000 +0200
14796 +++ linux-3.0.25-vs2.3.2.3/kernel/nsproxy.c     2011-06-13 14:09:44.000000000 +0200
14797 @@ -20,6 +20,8 @@
14798  #include <linux/mnt_namespace.h>
14799  #include <linux/utsname.h>
14800  #include <linux/pid_namespace.h>
14801 +#include <linux/vserver/global.h>
14802 +#include <linux/vserver/debug.h>
14803  #include <net/net_namespace.h>
14804  #include <linux/ipc_namespace.h>
14805  #include <linux/proc_fs.h>
14806 @@ -46,8 +48,11 @@ static inline struct nsproxy *create_nsp
14807         struct nsproxy *nsproxy;
14808  
14809         nsproxy = kmem_cache_alloc(nsproxy_cachep, GFP_KERNEL);
14810 -       if (nsproxy)
14811 +       if (nsproxy) {
14812                 atomic_set(&nsproxy->count, 1);
14813 +               atomic_inc(&vs_global_nsproxy);
14814 +       }
14815 +       vxdprintk(VXD_CBIT(space, 2), "create_nsproxy = %p[1]", nsproxy);
14816         return nsproxy;
14817  }
14818  
14819 @@ -56,8 +61,11 @@ static inline struct nsproxy *create_nsp
14820   * Return the newly created nsproxy.  Do not attach this to the task,
14821   * leave it to the caller to do proper locking and attach it to task.
14822   */
14823 -static struct nsproxy *create_new_namespaces(unsigned long flags,
14824 -                       struct task_struct *tsk, struct fs_struct *new_fs)
14825 +static struct nsproxy *unshare_namespaces(unsigned long flags,
14826 +                       struct nsproxy *orig,
14827 +                       struct fs_struct *new_fs,
14828 +                       struct user_namespace *new_user,
14829 +                       struct pid_namespace *new_pid)
14830  {
14831         struct nsproxy *new_nsp;
14832         int err;
14833 @@ -66,31 +74,31 @@ static struct nsproxy *create_new_namesp
14834         if (!new_nsp)
14835                 return ERR_PTR(-ENOMEM);
14836  
14837 -       new_nsp->mnt_ns = copy_mnt_ns(flags, tsk->nsproxy->mnt_ns, new_fs);
14838 +       new_nsp->mnt_ns = copy_mnt_ns(flags, orig->mnt_ns, new_fs);
14839         if (IS_ERR(new_nsp->mnt_ns)) {
14840                 err = PTR_ERR(new_nsp->mnt_ns);
14841                 goto out_ns;
14842         }
14843  
14844 -       new_nsp->uts_ns = copy_utsname(flags, tsk);
14845 +       new_nsp->uts_ns = copy_utsname(flags, orig->uts_ns, new_user);
14846         if (IS_ERR(new_nsp->uts_ns)) {
14847                 err = PTR_ERR(new_nsp->uts_ns);
14848                 goto out_uts;
14849         }
14850  
14851 -       new_nsp->ipc_ns = copy_ipcs(flags, tsk);
14852 +       new_nsp->ipc_ns = copy_ipcs(flags, orig->ipc_ns, new_user);
14853         if (IS_ERR(new_nsp->ipc_ns)) {
14854                 err = PTR_ERR(new_nsp->ipc_ns);
14855                 goto out_ipc;
14856         }
14857  
14858 -       new_nsp->pid_ns = copy_pid_ns(flags, task_active_pid_ns(tsk));
14859 +       new_nsp->pid_ns = copy_pid_ns(flags, new_pid);
14860         if (IS_ERR(new_nsp->pid_ns)) {
14861                 err = PTR_ERR(new_nsp->pid_ns);
14862                 goto out_pid;
14863         }
14864  
14865 -       new_nsp->net_ns = copy_net_ns(flags, tsk->nsproxy->net_ns);
14866 +       new_nsp->net_ns = copy_net_ns(flags, orig->net_ns);
14867         if (IS_ERR(new_nsp->net_ns)) {
14868                 err = PTR_ERR(new_nsp->net_ns);
14869                 goto out_net;
14870 @@ -115,6 +123,40 @@ out_ns:
14871         return ERR_PTR(err);
14872  }
14873  
14874 +static struct nsproxy *create_new_namespaces(unsigned long flags,
14875 +                       struct task_struct *tsk, struct fs_struct *new_fs)
14876 +{
14877 +       return unshare_namespaces(flags, tsk->nsproxy,
14878 +               new_fs, task_cred_xxx(tsk, user)->user_ns,
14879 +               task_active_pid_ns(tsk));
14880 +}
14881 +
14882 +/*
14883 + * copies the nsproxy, setting refcount to 1, and grabbing a
14884 + * reference to all contained namespaces.
14885 + */
14886 +struct nsproxy *copy_nsproxy(struct nsproxy *orig)
14887 +{
14888 +       struct nsproxy *ns = create_nsproxy();
14889 +
14890 +       if (ns) {
14891 +               memcpy(ns, orig, sizeof(struct nsproxy));
14892 +               atomic_set(&ns->count, 1);
14893 +
14894 +               if (ns->mnt_ns)
14895 +                       get_mnt_ns(ns->mnt_ns);
14896 +               if (ns->uts_ns)
14897 +                       get_uts_ns(ns->uts_ns);
14898 +               if (ns->ipc_ns)
14899 +                       get_ipc_ns(ns->ipc_ns);
14900 +               if (ns->pid_ns)
14901 +                       get_pid_ns(ns->pid_ns);
14902 +               if (ns->net_ns)
14903 +                       get_net(ns->net_ns);
14904 +       }
14905 +       return ns;
14906 +}
14907 +
14908  /*
14909   * called from clone.  This now handles copy for nsproxy and all
14910   * namespaces therein.
14911 @@ -122,9 +164,12 @@ out_ns:
14912  int copy_namespaces(unsigned long flags, struct task_struct *tsk)
14913  {
14914         struct nsproxy *old_ns = tsk->nsproxy;
14915 -       struct nsproxy *new_ns;
14916 +       struct nsproxy *new_ns = NULL;
14917         int err = 0;
14918  
14919 +       vxdprintk(VXD_CBIT(space, 7), "copy_namespaces(0x%08lx,%p[%p])",
14920 +               flags, tsk, old_ns);
14921 +
14922         if (!old_ns)
14923                 return 0;
14924  
14925 @@ -134,7 +179,7 @@ int copy_namespaces(unsigned long flags,
14926                                 CLONE_NEWPID | CLONE_NEWNET)))
14927                 return 0;
14928  
14929 -       if (!capable(CAP_SYS_ADMIN)) {
14930 +       if (!vx_can_unshare(CAP_SYS_ADMIN, flags)) {
14931                 err = -EPERM;
14932                 goto out;
14933         }
14934 @@ -161,6 +206,9 @@ int copy_namespaces(unsigned long flags,
14935  
14936  out:
14937         put_nsproxy(old_ns);
14938 +       vxdprintk(VXD_CBIT(space, 3),
14939 +               "copy_namespaces(0x%08lx,%p[%p]) = %d [%p]",
14940 +               flags, tsk, old_ns, err, new_ns);
14941         return err;
14942  }
14943  
14944 @@ -174,7 +222,9 @@ void free_nsproxy(struct nsproxy *ns)
14945                 put_ipc_ns(ns->ipc_ns);
14946         if (ns->pid_ns)
14947                 put_pid_ns(ns->pid_ns);
14948 -       put_net(ns->net_ns);
14949 +       if (ns->net_ns)
14950 +               put_net(ns->net_ns);
14951 +       atomic_dec(&vs_global_nsproxy);
14952         kmem_cache_free(nsproxy_cachep, ns);
14953  }
14954  
14955 @@ -187,11 +237,15 @@ int unshare_nsproxy_namespaces(unsigned 
14956  {
14957         int err = 0;
14958  
14959 +       vxdprintk(VXD_CBIT(space, 4),
14960 +               "unshare_nsproxy_namespaces(0x%08lx,[%p])",
14961 +               unshare_flags, current->nsproxy);
14962 +
14963         if (!(unshare_flags & (CLONE_NEWNS | CLONE_NEWUTS | CLONE_NEWIPC |
14964                                CLONE_NEWNET)))
14965                 return 0;
14966  
14967 -       if (!capable(CAP_SYS_ADMIN))
14968 +       if (!vx_can_unshare(CAP_SYS_ADMIN, unshare_flags))
14969                 return -EPERM;
14970  
14971         *new_nsp = create_new_namespaces(unshare_flags, current,
14972 diff -NurpP --minimal linux-3.0.25/kernel/pid.c linux-3.0.25-vs2.3.2.3/kernel/pid.c
14973 --- linux-3.0.25/kernel/pid.c   2011-05-22 16:17:59.000000000 +0200
14974 +++ linux-3.0.25-vs2.3.2.3/kernel/pid.c 2011-06-10 22:11:24.000000000 +0200
14975 @@ -36,6 +36,7 @@
14976  #include <linux/pid_namespace.h>
14977  #include <linux/init_task.h>
14978  #include <linux/syscalls.h>
14979 +#include <linux/vs_pid.h>
14980  
14981  #define pid_hashfn(nr, ns)     \
14982         hash_long((unsigned long)nr + (unsigned long)ns, pidhash_shift)
14983 @@ -342,7 +343,7 @@ EXPORT_SYMBOL_GPL(find_pid_ns);
14984  
14985  struct pid *find_vpid(int nr)
14986  {
14987 -       return find_pid_ns(nr, current->nsproxy->pid_ns);
14988 +       return find_pid_ns(vx_rmap_pid(nr), current->nsproxy->pid_ns);
14989  }
14990  EXPORT_SYMBOL_GPL(find_vpid);
14991  
14992 @@ -402,6 +403,9 @@ void transfer_pid(struct task_struct *ol
14993  struct task_struct *pid_task(struct pid *pid, enum pid_type type)
14994  {
14995         struct task_struct *result = NULL;
14996 +
14997 +       if (type == PIDTYPE_REALPID)
14998 +               type = PIDTYPE_PID;
14999         if (pid) {
15000                 struct hlist_node *first;
15001                 first = rcu_dereference_check(hlist_first_rcu(&pid->tasks[type]),
15002 @@ -420,7 +424,7 @@ EXPORT_SYMBOL(pid_task);
15003  struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
15004  {
15005         rcu_lockdep_assert(rcu_read_lock_held());
15006 -       return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
15007 +       return pid_task(find_pid_ns(vx_rmap_pid(nr), ns), PIDTYPE_PID);
15008  }
15009  
15010  struct task_struct *find_task_by_vpid(pid_t vnr)
15011 @@ -464,7 +468,7 @@ struct pid *find_get_pid(pid_t nr)
15012  }
15013  EXPORT_SYMBOL_GPL(find_get_pid);
15014  
15015 -pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns)
15016 +pid_t pid_unmapped_nr_ns(struct pid *pid, struct pid_namespace *ns)
15017  {
15018         struct upid *upid;
15019         pid_t nr = 0;
15020 @@ -477,6 +481,11 @@ pid_t pid_nr_ns(struct pid *pid, struct 
15021         return nr;
15022  }
15023  
15024 +pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns)
15025 +{
15026 +       return vx_map_pid(pid_unmapped_nr_ns(pid, ns));
15027 +}
15028 +
15029  pid_t pid_vnr(struct pid *pid)
15030  {
15031         return pid_nr_ns(pid, current->nsproxy->pid_ns);
15032 diff -NurpP --minimal linux-3.0.25/kernel/pid_namespace.c linux-3.0.25-vs2.3.2.3/kernel/pid_namespace.c
15033 --- linux-3.0.25/kernel/pid_namespace.c 2011-05-22 16:17:59.000000000 +0200
15034 +++ linux-3.0.25-vs2.3.2.3/kernel/pid_namespace.c       2011-06-10 22:17:45.000000000 +0200
15035 @@ -15,6 +15,7 @@
15036  #include <linux/acct.h>
15037  #include <linux/slab.h>
15038  #include <linux/proc_fs.h>
15039 +#include <linux/vserver/global.h>
15040  
15041  #define BITS_PER_PAGE          (PAGE_SIZE*8)
15042  
15043 @@ -88,6 +89,7 @@ static struct pid_namespace *create_pid_
15044                 goto out_free_map;
15045  
15046         kref_init(&ns->kref);
15047 +       atomic_inc(&vs_global_pid_ns);
15048         ns->level = level;
15049         ns->parent = get_pid_ns(parent_pid_ns);
15050  
15051 @@ -119,6 +121,7 @@ static void destroy_pid_namespace(struct
15052  
15053         for (i = 0; i < PIDMAP_ENTRIES; i++)
15054                 kfree(ns->pidmap[i].page);
15055 +       atomic_dec(&vs_global_pid_ns);
15056         kmem_cache_free(pid_ns_cachep, ns);
15057  }
15058  
15059 diff -NurpP --minimal linux-3.0.25/kernel/posix-timers.c linux-3.0.25-vs2.3.2.3/kernel/posix-timers.c
15060 --- linux-3.0.25/kernel/posix-timers.c  2011-07-22 11:18:12.000000000 +0200
15061 +++ linux-3.0.25-vs2.3.2.3/kernel/posix-timers.c        2011-06-10 22:11:24.000000000 +0200
15062 @@ -47,6 +47,7 @@
15063  #include <linux/wait.h>
15064  #include <linux/workqueue.h>
15065  #include <linux/module.h>
15066 +#include <linux/vs_context.h>
15067  
15068  /*
15069   * Management arrays for POSIX timers.  Timers are kept in slab memory
15070 @@ -340,6 +341,7 @@ int posix_timer_event(struct k_itimer *t
15071  {
15072         struct task_struct *task;
15073         int shared, ret = -1;
15074 +
15075         /*
15076          * FIXME: if ->sigq is queued we can race with
15077          * dequeue_signal()->do_schedule_next_timer().
15078 @@ -356,10 +358,18 @@ int posix_timer_event(struct k_itimer *t
15079         rcu_read_lock();
15080         task = pid_task(timr->it_pid, PIDTYPE_PID);
15081         if (task) {
15082 +               struct vx_info_save vxis;
15083 +               struct vx_info *vxi;
15084 +
15085 +               vxi = get_vx_info(task->vx_info);
15086 +               enter_vx_info(vxi, &vxis);
15087                 shared = !(timr->it_sigev_notify & SIGEV_THREAD_ID);
15088                 ret = send_sigqueue(timr->sigq, task, shared);
15089 +               leave_vx_info(&vxis);
15090 +               put_vx_info(vxi);
15091         }
15092         rcu_read_unlock();
15093 +
15094         /* If we failed to send the signal the timer stops. */
15095         return ret > 0;
15096  }
15097 diff -NurpP --minimal linux-3.0.25/kernel/printk.c linux-3.0.25-vs2.3.2.3/kernel/printk.c
15098 --- linux-3.0.25/kernel/printk.c        2012-03-19 21:16:56.000000000 +0100
15099 +++ linux-3.0.25-vs2.3.2.3/kernel/printk.c      2012-02-07 02:05:58.000000000 +0100
15100 @@ -41,6 +41,7 @@
15101  #include <linux/cpu.h>
15102  #include <linux/notifier.h>
15103  #include <linux/rculist.h>
15104 +#include <linux/vs_cvirt.h>
15105  
15106  #include <asm/uaccess.h>
15107  
15108 @@ -314,7 +315,7 @@ static int check_syslog_permissions(int 
15109                 return 0;
15110  
15111         if (syslog_action_restricted(type)) {
15112 -               if (capable(CAP_SYSLOG))
15113 +               if (vx_capable(CAP_SYSLOG, VXC_SYSLOG))
15114                         return 0;
15115                 /* For historical reasons, accept CAP_SYS_ADMIN too, with a warning */
15116                 if (capable(CAP_SYS_ADMIN)) {
15117 @@ -344,12 +345,9 @@ int do_syslog(int type, char __user *buf
15118         if (error)
15119                 return error;
15120  
15121 -       switch (type) {
15122 -       case SYSLOG_ACTION_CLOSE:       /* Close log */
15123 -               break;
15124 -       case SYSLOG_ACTION_OPEN:        /* Open log */
15125 -               break;
15126 -       case SYSLOG_ACTION_READ:        /* Read from log */
15127 +       if ((type == SYSLOG_ACTION_READ) ||
15128 +           (type == SYSLOG_ACTION_READ_ALL) ||
15129 +           (type == SYSLOG_ACTION_READ_CLEAR)) {
15130                 error = -EINVAL;
15131                 if (!buf || len < 0)
15132                         goto out;
15133 @@ -360,6 +358,16 @@ int do_syslog(int type, char __user *buf
15134                         error = -EFAULT;
15135                         goto out;
15136                 }
15137 +       }
15138 +       if (!vx_check(0, VS_ADMIN|VS_WATCH))
15139 +               return vx_do_syslog(type, buf, len);
15140 +
15141 +       switch (type) {
15142 +       case SYSLOG_ACTION_CLOSE:       /* Close log */
15143 +               break;
15144 +       case SYSLOG_ACTION_OPEN:        /* Open log */
15145 +               break;
15146 +       case SYSLOG_ACTION_READ:        /* Read from log */
15147                 error = wait_event_interruptible(log_wait,
15148                                                         (log_start - log_end));
15149                 if (error)
15150 @@ -386,16 +394,6 @@ int do_syslog(int type, char __user *buf
15151                 /* FALL THRU */
15152         /* Read last kernel messages */
15153         case SYSLOG_ACTION_READ_ALL:
15154 -               error = -EINVAL;
15155 -               if (!buf || len < 0)
15156 -                       goto out;
15157 -               error = 0;
15158 -               if (!len)
15159 -                       goto out;
15160 -               if (!access_ok(VERIFY_WRITE, buf, len)) {
15161 -                       error = -EFAULT;
15162 -                       goto out;
15163 -               }
15164                 count = len;
15165                 if (count > log_buf_len)
15166                         count = log_buf_len;
15167 diff -NurpP --minimal linux-3.0.25/kernel/ptrace.c linux-3.0.25-vs2.3.2.3/kernel/ptrace.c
15168 --- linux-3.0.25/kernel/ptrace.c        2011-07-22 11:18:12.000000000 +0200
15169 +++ linux-3.0.25-vs2.3.2.3/kernel/ptrace.c      2011-11-21 16:29:59.000000000 +0100
15170 @@ -22,6 +22,7 @@
15171  #include <linux/syscalls.h>
15172  #include <linux/uaccess.h>
15173  #include <linux/regset.h>
15174 +#include <linux/vs_context.h>
15175  #include <linux/hw_breakpoint.h>
15176  
15177  
15178 @@ -145,9 +146,15 @@ int __ptrace_may_access(struct task_stru
15179          * or halting the specified task is impossible.
15180          */
15181         int dumpable = 0;
15182 +
15183         /* Don't let security modules deny introspection */
15184         if (task == current)
15185                 return 0;
15186 +
15187 +       vxdprintk(VXD_CBIT(perm, 8),
15188 +               "__ptrace_may_access(%p[#%d,%d,%d], %d)",
15189 +               task, task->xid, task->pid, task->tgid, mode);
15190 +
15191         rcu_read_lock();
15192         tcred = __task_cred(task);
15193         if (cred->user->user_ns == tcred->user->user_ns &&
15194 @@ -161,6 +168,8 @@ int __ptrace_may_access(struct task_stru
15195         if (ns_capable(tcred->user->user_ns, CAP_SYS_PTRACE))
15196                 goto ok;
15197         rcu_read_unlock();
15198 +       vxdprintk(VXD_CBIT(perm, 8),
15199 +               "__ptrace_may_access(%p) cred/cap failed", task);
15200         return -EPERM;
15201  ok:
15202         rcu_read_unlock();
15203 @@ -169,6 +178,19 @@ ok:
15204                 dumpable = get_dumpable(task->mm);
15205         if (!dumpable && !task_ns_capable(task, CAP_SYS_PTRACE))
15206                 return -EPERM;
15207 +       vxdprintk(VXD_CBIT(perm, 8),
15208 +               "__ptrace_may_access(%p) cap/dump ok", task);
15209 +
15210 +       if (!vx_check(task->xid, VS_ADMIN_P|VS_WATCH_P|VS_IDENT))
15211 +               return -EPERM;
15212 +       vxdprintk(VXD_CBIT(perm, 8),
15213 +               "__ptrace_may_access(%p) check ok", task);
15214 +
15215 +       if (!vx_check(task->xid, VS_IDENT) &&
15216 +               !task_vx_flags(task, VXF_STATE_ADMIN, 0))
15217 +               return -EACCES;
15218 +       vxdprintk(VXD_CBIT(perm, 8),
15219 +               "__ptrace_may_access(%p) admin ok", task);
15220  
15221         return security_ptrace_access_check(task, mode);
15222  }
15223 diff -NurpP --minimal linux-3.0.25/kernel/sched.c linux-3.0.25-vs2.3.2.3/kernel/sched.c
15224 --- linux-3.0.25/kernel/sched.c 2012-03-19 21:16:56.000000000 +0100
15225 +++ linux-3.0.25-vs2.3.2.3/kernel/sched.c       2011-10-18 13:51:13.000000000 +0200
15226 @@ -71,6 +71,8 @@
15227  #include <linux/ctype.h>
15228  #include <linux/ftrace.h>
15229  #include <linux/slab.h>
15230 +#include <linux/vs_sched.h>
15231 +#include <linux/vs_cvirt.h>
15232  
15233  #include <asm/tlb.h>
15234  #include <asm/irq_regs.h>
15235 @@ -3461,9 +3463,17 @@ static void calc_global_nohz(unsigned lo
15236   */
15237  void get_avenrun(unsigned long *loads, unsigned long offset, int shift)
15238  {
15239 -       loads[0] = (avenrun[0] + offset) << shift;
15240 -       loads[1] = (avenrun[1] + offset) << shift;
15241 -       loads[2] = (avenrun[2] + offset) << shift;
15242 +       if (vx_flags(VXF_VIRT_LOAD, 0)) {
15243 +               struct vx_info *vxi = current_vx_info();
15244 +
15245 +               loads[0] = (vxi->cvirt.load[0] + offset) << shift;
15246 +               loads[1] = (vxi->cvirt.load[1] + offset) << shift;
15247 +               loads[2] = (vxi->cvirt.load[2] + offset) << shift;
15248 +       } else {
15249 +               loads[0] = (avenrun[0] + offset) << shift;
15250 +               loads[1] = (avenrun[1] + offset) << shift;
15251 +               loads[2] = (avenrun[2] + offset) << shift;
15252 +       }
15253  }
15254  
15255  /*
15256 @@ -3722,16 +3732,19 @@ void account_user_time(struct task_struc
15257                        cputime_t cputime_scaled)
15258  {
15259         struct cpu_usage_stat *cpustat = &kstat_this_cpu.cpustat;
15260 +       struct vx_info *vxi = p->vx_info;  /* p is _always_ current */
15261         cputime64_t tmp;
15262 +       int nice = (TASK_NICE(p) > 0);
15263  
15264         /* Add user time to process. */
15265         p->utime = cputime_add(p->utime, cputime);
15266         p->utimescaled = cputime_add(p->utimescaled, cputime_scaled);
15267 +       vx_account_user(vxi, cputime, nice);
15268         account_group_user_time(p, cputime);
15269  
15270         /* Add user time to cpustat. */
15271         tmp = cputime_to_cputime64(cputime);
15272 -       if (TASK_NICE(p) > 0)
15273 +       if (nice)
15274                 cpustat->nice = cputime64_add(cpustat->nice, tmp);
15275         else
15276                 cpustat->user = cputime64_add(cpustat->user, tmp);
15277 @@ -3783,10 +3796,12 @@ void __account_system_time(struct task_s
15278                         cputime_t cputime_scaled, cputime64_t *target_cputime64)
15279  {
15280         cputime64_t tmp = cputime_to_cputime64(cputime);
15281 +       struct vx_info *vxi = p->vx_info;  /* p is _always_ current */
15282  
15283         /* Add system time to process. */
15284         p->stime = cputime_add(p->stime, cputime);
15285         p->stimescaled = cputime_add(p->stimescaled, cputime_scaled);
15286 +       vx_account_system(vxi, cputime, 0 /* do we have idle time? */);
15287         account_group_system_time(p, cputime);
15288  
15289         /* Add system time to cpustat. */
15290 @@ -4954,7 +4969,7 @@ SYSCALL_DEFINE1(nice, int, increment)
15291                 nice = 19;
15292  
15293         if (increment < 0 && !can_nice(current, nice))
15294 -               return -EPERM;
15295 +               return vx_flags(VXF_IGNEG_NICE, 0) ? 0 : -EPERM;
15296  
15297         retval = security_task_setnice(current, nice);
15298         if (retval)
15299 diff -NurpP --minimal linux-3.0.25/kernel/sched_fair.c linux-3.0.25-vs2.3.2.3/kernel/sched_fair.c
15300 --- linux-3.0.25/kernel/sched_fair.c    2011-07-22 11:18:12.000000000 +0200
15301 +++ linux-3.0.25-vs2.3.2.3/kernel/sched_fair.c  2011-07-22 11:20:39.000000000 +0200
15302 @@ -998,6 +998,8 @@ enqueue_entity(struct cfs_rq *cfs_rq, st
15303                 __enqueue_entity(cfs_rq, se);
15304         se->on_rq = 1;
15305  
15306 +       if (entity_is_task(se))
15307 +               vx_activate_task(task_of(se));
15308         if (cfs_rq->nr_running == 1)
15309                 list_add_leaf_cfs_rq(cfs_rq);
15310  }
15311 @@ -1074,6 +1076,8 @@ dequeue_entity(struct cfs_rq *cfs_rq, st
15312         if (se != cfs_rq->curr)
15313                 __dequeue_entity(cfs_rq, se);
15314         se->on_rq = 0;
15315 +       if (entity_is_task(se))
15316 +               vx_deactivate_task(task_of(se));
15317         update_cfs_load(cfs_rq, 0);
15318         account_entity_dequeue(cfs_rq, se);
15319  
15320 diff -NurpP --minimal linux-3.0.25/kernel/signal.c linux-3.0.25-vs2.3.2.3/kernel/signal.c
15321 --- linux-3.0.25/kernel/signal.c        2012-03-19 21:16:56.000000000 +0100
15322 +++ linux-3.0.25-vs2.3.2.3/kernel/signal.c      2011-11-15 17:37:07.000000000 +0100
15323 @@ -28,6 +28,8 @@
15324  #include <linux/freezer.h>
15325  #include <linux/pid_namespace.h>
15326  #include <linux/nsproxy.h>
15327 +#include <linux/vs_context.h>
15328 +#include <linux/vs_pid.h>
15329  #define CREATE_TRACE_POINTS
15330  #include <trace/events/signal.h>
15331  
15332 @@ -744,9 +746,18 @@ static int check_kill_permission(int sig
15333         struct pid *sid;
15334         int error;
15335  
15336 +       vxdprintk(VXD_CBIT(misc, 7),
15337 +               "check_kill_permission(%d,%p,%p[#%u,%u])",
15338 +               sig, info, t, vx_task_xid(t), t->pid);
15339 +
15340         if (!valid_signal(sig))
15341                 return -EINVAL;
15342  
15343 +/*     FIXME: needed? if so, why?
15344 +       if ((info != SEND_SIG_NOINFO) &&
15345 +               (is_si_special(info) || !si_fromuser(info)))
15346 +               goto skip;      */
15347 +
15348         if (!si_fromuser(info))
15349                 return 0;
15350  
15351 @@ -770,6 +781,20 @@ static int check_kill_permission(int sig
15352                 }
15353         }
15354  
15355 +       error = -EPERM;
15356 +       if (t->pid == 1 && current->xid)
15357 +               return error;
15358 +
15359 +       error = -ESRCH;
15360 +       /* FIXME: we shouldn't return ESRCH ever, to avoid
15361 +                 loops, maybe ENOENT or EACCES? */
15362 +       if (!vx_check(vx_task_xid(t), VS_WATCH_P | VS_IDENT)) {
15363 +               vxdprintk(current->xid || VXD_CBIT(misc, 7),
15364 +                       "signal %d[%p] xid mismatch %p[#%u,%u] xid=#%u",
15365 +                       sig, info, t, vx_task_xid(t), t->pid, current->xid);
15366 +               return error;
15367 +       }
15368 +/* skip: */
15369         return security_task_kill(t, info, sig, 0);
15370  }
15371  
15372 @@ -1246,7 +1271,7 @@ int kill_pid_info(int sig, struct siginf
15373         rcu_read_lock();
15374  retry:
15375         p = pid_task(pid, PIDTYPE_PID);
15376 -       if (p) {
15377 +       if (p && vx_check(vx_task_xid(p), VS_IDENT)) {
15378                 error = group_send_sig_info(sig, info, p);
15379                 if (unlikely(error == -ESRCH))
15380                         /*
15381 @@ -1285,7 +1310,7 @@ int kill_pid_info_as_uid(int sig, struct
15382  
15383         rcu_read_lock();
15384         p = pid_task(pid, PIDTYPE_PID);
15385 -       if (!p) {
15386 +       if (!p || !vx_check(vx_task_xid(p), VS_IDENT)) {
15387                 ret = -ESRCH;
15388                 goto out_unlock;
15389         }
15390 @@ -1340,8 +1365,10 @@ static int kill_something_info(int sig, 
15391                 struct task_struct * p;
15392  
15393                 for_each_process(p) {
15394 -                       if (task_pid_vnr(p) > 1 &&
15395 -                                       !same_thread_group(p, current)) {
15396 +                       if (vx_check(vx_task_xid(p), VS_ADMIN|VS_IDENT) &&
15397 +                               task_pid_vnr(p) > 1 &&
15398 +                               !same_thread_group(p, current) &&
15399 +                               !vx_current_initpid(p->pid)) {
15400                                 int err = group_send_sig_info(sig, info, p);
15401                                 ++count;
15402                                 if (err != -EPERM)
15403 @@ -2138,6 +2165,11 @@ relock:
15404                                 !sig_kernel_only(signr))
15405                         continue;
15406  
15407 +               /* virtual init is protected against user signals */
15408 +               if ((info->si_code == SI_USER) &&
15409 +                       vx_current_initpid(current->pid))
15410 +                       continue;
15411 +
15412                 if (sig_kernel_stop(signr)) {
15413                         /*
15414                          * The default action is to stop all threads in
15415 diff -NurpP --minimal linux-3.0.25/kernel/softirq.c linux-3.0.25-vs2.3.2.3/kernel/softirq.c
15416 --- linux-3.0.25/kernel/softirq.c       2011-07-22 11:18:12.000000000 +0200
15417 +++ linux-3.0.25-vs2.3.2.3/kernel/softirq.c     2011-07-22 11:20:39.000000000 +0200
15418 @@ -24,6 +24,7 @@
15419  #include <linux/ftrace.h>
15420  #include <linux/smp.h>
15421  #include <linux/tick.h>
15422 +#include <linux/vs_context.h>
15423  
15424  #define CREATE_TRACE_POINTS
15425  #include <trace/events/irq.h>
15426 diff -NurpP --minimal linux-3.0.25/kernel/sys.c linux-3.0.25-vs2.3.2.3/kernel/sys.c
15427 --- linux-3.0.25/kernel/sys.c   2012-03-19 21:16:56.000000000 +0100
15428 +++ linux-3.0.25-vs2.3.2.3/kernel/sys.c 2011-11-15 17:37:07.000000000 +0100
15429 @@ -45,6 +45,7 @@
15430  #include <linux/syscalls.h>
15431  #include <linux/kprobes.h>
15432  #include <linux/user_namespace.h>
15433 +#include <linux/vs_pid.h>
15434  
15435  #include <linux/kmsg_dump.h>
15436  /* Move somewhere else to avoid recompiling? */
15437 @@ -155,7 +156,10 @@ static int set_one_prio(struct task_stru
15438                 goto out;
15439         }
15440         if (niceval < task_nice(p) && !can_nice(p, niceval)) {
15441 -               error = -EACCES;
15442 +               if (vx_flags(VXF_IGNEG_NICE, 0))
15443 +                       error = 0;
15444 +               else
15445 +                       error = -EACCES;
15446                 goto out;
15447         }
15448         no_nice = security_task_setnice(p, niceval);
15449 @@ -205,6 +209,8 @@ SYSCALL_DEFINE3(setpriority, int, which,
15450                         else
15451                                 pgrp = task_pgrp(current);
15452                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
15453 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
15454 +                                       continue;
15455                                 error = set_one_prio(p, niceval, error);
15456                         } while_each_pid_thread(pgrp, PIDTYPE_PGID, p);
15457                         break;
15458 @@ -268,6 +274,8 @@ SYSCALL_DEFINE2(getpriority, int, which,
15459                         else
15460                                 pgrp = task_pgrp(current);
15461                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
15462 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
15463 +                                       continue;
15464                                 niceval = 20 - task_nice(p);
15465                                 if (niceval > retval)
15466                                         retval = niceval;
15467 @@ -387,6 +395,8 @@ EXPORT_SYMBOL_GPL(kernel_power_off);
15468  
15469  static DEFINE_MUTEX(reboot_mutex);
15470  
15471 +long vs_reboot(unsigned int, void __user *);
15472 +
15473  /*
15474   * Reboot system call: for obvious reasons only root may call it,
15475   * and even root needs to set up some magic numbers in the registers
15476 @@ -419,6 +429,9 @@ SYSCALL_DEFINE4(reboot, int, magic1, int
15477         if ((cmd == LINUX_REBOOT_CMD_POWER_OFF) && !pm_power_off)
15478                 cmd = LINUX_REBOOT_CMD_HALT;
15479  
15480 +       if (!vx_check(0, VS_ADMIN|VS_WATCH))
15481 +               return vs_reboot(cmd, arg);
15482 +
15483         mutex_lock(&reboot_mutex);
15484         switch (cmd) {
15485         case LINUX_REBOOT_CMD_RESTART:
15486 @@ -1235,7 +1248,8 @@ SYSCALL_DEFINE2(sethostname, char __user
15487         int errno;
15488         char tmp[__NEW_UTS_LEN];
15489  
15490 -       if (!ns_capable(current->nsproxy->uts_ns->user_ns, CAP_SYS_ADMIN))
15491 +       if (!vx_ns_capable(current->nsproxy->uts_ns->user_ns,
15492 +               CAP_SYS_ADMIN, VXC_SET_UTSNAME))
15493                 return -EPERM;
15494  
15495         if (len < 0 || len > __NEW_UTS_LEN)
15496 @@ -1285,7 +1299,8 @@ SYSCALL_DEFINE2(setdomainname, char __us
15497         int errno;
15498         char tmp[__NEW_UTS_LEN];
15499  
15500 -       if (!ns_capable(current->nsproxy->uts_ns->user_ns, CAP_SYS_ADMIN))
15501 +       if (!vx_ns_capable(current->nsproxy->uts_ns->user_ns,
15502 +               CAP_SYS_ADMIN, VXC_SET_UTSNAME))
15503                 return -EPERM;
15504         if (len < 0 || len > __NEW_UTS_LEN)
15505                 return -EINVAL;
15506 @@ -1403,7 +1418,7 @@ int do_prlimit(struct task_struct *tsk, 
15507                 /* Keep the capable check against init_user_ns until
15508                    cgroups can contain all limits */
15509                 if (new_rlim->rlim_max > rlim->rlim_max &&
15510 -                               !capable(CAP_SYS_RESOURCE))
15511 +                       !vx_capable(CAP_SYS_RESOURCE, VXC_SET_RLIMIT))
15512                         retval = -EPERM;
15513                 if (!retval)
15514                         retval = security_task_setrlimit(tsk->group_leader,
15515 @@ -1457,7 +1472,8 @@ static int check_prlimit_permission(stru
15516              cred->gid == tcred->sgid &&
15517              cred->gid == tcred->gid))
15518                 return 0;
15519 -       if (ns_capable(tcred->user->user_ns, CAP_SYS_RESOURCE))
15520 +       if (vx_ns_capable(tcred->user->user_ns,
15521 +               CAP_SYS_RESOURCE, VXC_SET_RLIMIT))
15522                 return 0;
15523  
15524         return -EPERM;
15525 diff -NurpP --minimal linux-3.0.25/kernel/sysctl.c linux-3.0.25-vs2.3.2.3/kernel/sysctl.c
15526 --- linux-3.0.25/kernel/sysctl.c        2011-07-22 11:18:12.000000000 +0200
15527 +++ linux-3.0.25-vs2.3.2.3/kernel/sysctl.c      2011-06-15 02:40:14.000000000 +0200
15528 @@ -75,6 +75,7 @@
15529  #if defined(CONFIG_PROVE_LOCKING) || defined(CONFIG_LOCK_STAT)
15530  #include <linux/lockdep.h>
15531  #endif
15532 +extern char vshelper_path[];
15533  #ifdef CONFIG_CHR_DEV_SG
15534  #include <scsi/sg.h>
15535  #endif
15536 @@ -568,6 +569,13 @@ static struct ctl_table kern_table[] = {
15537                 .proc_handler   = proc_dostring,
15538         },
15539  #endif
15540 +       {
15541 +               .procname       = "vshelper",
15542 +               .data           = &vshelper_path,
15543 +               .maxlen         = 256,
15544 +               .mode           = 0644,
15545 +               .proc_handler   = &proc_dostring,
15546 +       },
15547  #ifdef CONFIG_CHR_DEV_SG
15548         {
15549                 .procname       = "sg-big-buff",
15550 diff -NurpP --minimal linux-3.0.25/kernel/sysctl_binary.c linux-3.0.25-vs2.3.2.3/kernel/sysctl_binary.c
15551 --- linux-3.0.25/kernel/sysctl_binary.c 2012-03-19 21:16:56.000000000 +0100
15552 +++ linux-3.0.25-vs2.3.2.3/kernel/sysctl_binary.c       2012-01-10 09:19:13.000000000 +0100
15553 @@ -73,6 +73,7 @@ static const struct bin_table bin_kern_t
15554  
15555         { CTL_INT,      KERN_PANIC,                     "panic" },
15556         { CTL_INT,      KERN_REALROOTDEV,               "real-root-dev" },
15557 +       { CTL_STR,      KERN_VSHELPER,                  "vshelper" },
15558  
15559         { CTL_STR,      KERN_SPARC_REBOOT,              "reboot-cmd" },
15560         { CTL_INT,      KERN_CTLALTDEL,                 "ctrl-alt-del" },
15561 diff -NurpP --minimal linux-3.0.25/kernel/time/timekeeping.c linux-3.0.25-vs2.3.2.3/kernel/time/timekeeping.c
15562 --- linux-3.0.25/kernel/time/timekeeping.c      2012-03-19 21:16:56.000000000 +0100
15563 +++ linux-3.0.25-vs2.3.2.3/kernel/time/timekeeping.c    2011-12-19 15:55:53.000000000 +0100
15564 @@ -233,6 +233,7 @@ void getnstimeofday(struct timespec *ts)
15565         } while (read_seqretry(&xtime_lock, seq));
15566  
15567         timespec_add_ns(ts, nsecs);
15568 +       vx_adjust_timespec(ts);
15569  }
15570  
15571  EXPORT_SYMBOL(getnstimeofday);
15572 diff -NurpP --minimal linux-3.0.25/kernel/time.c linux-3.0.25-vs2.3.2.3/kernel/time.c
15573 --- linux-3.0.25/kernel/time.c  2012-03-19 21:16:56.000000000 +0100
15574 +++ linux-3.0.25-vs2.3.2.3/kernel/time.c        2011-11-15 17:37:07.000000000 +0100
15575 @@ -92,7 +92,7 @@ SYSCALL_DEFINE1(stime, time_t __user *, 
15576         if (err)
15577                 return err;
15578  
15579 -       do_settimeofday(&tv);
15580 +       vx_settimeofday(&tv);
15581         return 0;
15582  }
15583  
15584 @@ -177,7 +177,7 @@ int do_sys_settimeofday(const struct tim
15585                 /* SMP safe, again the code in arch/foo/time.c should
15586                  * globally block out interrupts when it runs.
15587                  */
15588 -               return do_settimeofday(tv);
15589 +               return vx_settimeofday(tv);
15590         }
15591         return 0;
15592  }
15593 diff -NurpP --minimal linux-3.0.25/kernel/timer.c linux-3.0.25-vs2.3.2.3/kernel/timer.c
15594 --- linux-3.0.25/kernel/timer.c 2011-07-22 11:18:12.000000000 +0200
15595 +++ linux-3.0.25-vs2.3.2.3/kernel/timer.c       2011-06-15 02:40:14.000000000 +0200
15596 @@ -40,6 +40,10 @@
15597  #include <linux/irq_work.h>
15598  #include <linux/sched.h>
15599  #include <linux/slab.h>
15600 +#include <linux/vs_base.h>
15601 +#include <linux/vs_cvirt.h>
15602 +#include <linux/vs_pid.h>
15603 +#include <linux/vserver/sched.h>
15604  
15605  #include <asm/uaccess.h>
15606  #include <asm/unistd.h>
15607 @@ -1336,12 +1340,6 @@ SYSCALL_DEFINE1(alarm, unsigned int, sec
15608  
15609  #endif
15610  
15611 -#ifndef __alpha__
15612 -
15613 -/*
15614 - * The Alpha uses getxpid, getxuid, and getxgid instead.  Maybe this
15615 - * should be moved into arch/i386 instead?
15616 - */
15617  
15618  /**
15619   * sys_getpid - return the thread group id of the current process
15620 @@ -1370,10 +1368,23 @@ SYSCALL_DEFINE0(getppid)
15621         rcu_read_lock();
15622         pid = task_tgid_vnr(current->real_parent);
15623         rcu_read_unlock();
15624 +       return vx_map_pid(pid);
15625 +}
15626  
15627 -       return pid;
15628 +#ifdef __alpha__
15629 +
15630 +/*
15631 + * The Alpha uses getxpid, getxuid, and getxgid instead.
15632 + */
15633 +
15634 +asmlinkage long do_getxpid(long *ppid)
15635 +{
15636 +       *ppid = sys_getppid();
15637 +       return sys_getpid();
15638  }
15639  
15640 +#else /* _alpha_ */
15641 +
15642  SYSCALL_DEFINE0(getuid)
15643  {
15644         /* Only we change this so SMP safe */
15645 diff -NurpP --minimal linux-3.0.25/kernel/user_namespace.c linux-3.0.25-vs2.3.2.3/kernel/user_namespace.c
15646 --- linux-3.0.25/kernel/user_namespace.c        2011-03-15 18:07:42.000000000 +0100
15647 +++ linux-3.0.25-vs2.3.2.3/kernel/user_namespace.c      2011-06-10 22:11:24.000000000 +0200
15648 @@ -11,6 +11,7 @@
15649  #include <linux/user_namespace.h>
15650  #include <linux/highuid.h>
15651  #include <linux/cred.h>
15652 +#include <linux/vserver/global.h>
15653  
15654  static struct kmem_cache *user_ns_cachep __read_mostly;
15655  
15656 @@ -33,6 +34,7 @@ int create_user_ns(struct cred *new)
15657                 return -ENOMEM;
15658  
15659         kref_init(&ns->kref);
15660 +       atomic_inc(&vs_global_user_ns);
15661  
15662         for (n = 0; n < UIDHASH_SZ; ++n)
15663                 INIT_HLIST_HEAD(ns->uidhash_table + n);
15664 @@ -81,6 +83,8 @@ void free_user_ns(struct kref *kref)
15665         struct user_namespace *ns =
15666                 container_of(kref, struct user_namespace, kref);
15667  
15668 +       /* FIXME: maybe move into destroyer? */
15669 +       atomic_dec(&vs_global_user_ns);
15670         INIT_WORK(&ns->destroyer, free_user_ns_work);
15671         schedule_work(&ns->destroyer);
15672  }
15673 diff -NurpP --minimal linux-3.0.25/kernel/utsname.c linux-3.0.25-vs2.3.2.3/kernel/utsname.c
15674 --- linux-3.0.25/kernel/utsname.c       2011-07-22 11:18:12.000000000 +0200
15675 +++ linux-3.0.25-vs2.3.2.3/kernel/utsname.c     2011-06-13 14:09:44.000000000 +0200
15676 @@ -16,14 +16,17 @@
15677  #include <linux/slab.h>
15678  #include <linux/user_namespace.h>
15679  #include <linux/proc_fs.h>
15680 +#include <linux/vserver/global.h>
15681  
15682  static struct uts_namespace *create_uts_ns(void)
15683  {
15684         struct uts_namespace *uts_ns;
15685  
15686         uts_ns = kmalloc(sizeof(struct uts_namespace), GFP_KERNEL);
15687 -       if (uts_ns)
15688 +       if (uts_ns) {
15689                 kref_init(&uts_ns->kref);
15690 +               atomic_inc(&vs_global_uts_ns);
15691 +       }
15692         return uts_ns;
15693  }
15694  
15695 @@ -32,8 +35,8 @@ static struct uts_namespace *create_uts_
15696   * @old_ns: namespace to clone
15697   * Return NULL on error (failure to kmalloc), new ns otherwise
15698   */
15699 -static struct uts_namespace *clone_uts_ns(struct task_struct *tsk,
15700 -                                         struct uts_namespace *old_ns)
15701 +static struct uts_namespace *clone_uts_ns(struct uts_namespace *old_ns,
15702 +                                         struct user_namespace *old_user)
15703  {
15704         struct uts_namespace *ns;
15705  
15706 @@ -43,7 +46,7 @@ static struct uts_namespace *clone_uts_n
15707  
15708         down_read(&uts_sem);
15709         memcpy(&ns->name, &old_ns->name, sizeof(ns->name));
15710 -       ns->user_ns = get_user_ns(task_cred_xxx(tsk, user)->user_ns);
15711 +       ns->user_ns = get_user_ns(old_user);
15712         up_read(&uts_sem);
15713         return ns;
15714  }
15715 @@ -55,9 +58,9 @@ static struct uts_namespace *clone_uts_n
15716   * versa.
15717   */
15718  struct uts_namespace *copy_utsname(unsigned long flags,
15719 -                                  struct task_struct *tsk)
15720 +                                  struct uts_namespace *old_ns,
15721 +                                  struct user_namespace *user_ns)
15722  {
15723 -       struct uts_namespace *old_ns = tsk->nsproxy->uts_ns;
15724         struct uts_namespace *new_ns;
15725  
15726         BUG_ON(!old_ns);
15727 @@ -66,7 +69,7 @@ struct uts_namespace *copy_utsname(unsig
15728         if (!(flags & CLONE_NEWUTS))
15729                 return old_ns;
15730  
15731 -       new_ns = clone_uts_ns(tsk, old_ns);
15732 +       new_ns = clone_uts_ns(old_ns, user_ns);
15733  
15734         put_uts_ns(old_ns);
15735         return new_ns;
15736 @@ -78,6 +81,7 @@ void free_uts_ns(struct kref *kref)
15737  
15738         ns = container_of(kref, struct uts_namespace, kref);
15739         put_user_ns(ns->user_ns);
15740 +       atomic_dec(&vs_global_uts_ns);
15741         kfree(ns);
15742  }
15743  
15744 diff -NurpP --minimal linux-3.0.25/kernel/vserver/Kconfig linux-3.0.25-vs2.3.2.3/kernel/vserver/Kconfig
15745 --- linux-3.0.25/kernel/vserver/Kconfig 1970-01-01 01:00:00.000000000 +0100
15746 +++ linux-3.0.25-vs2.3.2.3/kernel/vserver/Kconfig       2011-08-08 18:06:22.000000000 +0200
15747 @@ -0,0 +1,232 @@
15748 +#
15749 +# Linux VServer configuration
15750 +#
15751 +
15752 +menu "Linux VServer"
15753 +
15754 +config VSERVER_AUTO_LBACK
15755 +       bool    "Automatically Assign Loopback IP"
15756 +       default y
15757 +       help
15758 +         Automatically assign a guest specific loopback
15759 +         IP and add it to the kernel network stack on
15760 +         startup.
15761 +
15762 +config VSERVER_AUTO_SINGLE
15763 +       bool    "Automatic Single IP Special Casing"
15764 +       depends on EXPERIMENTAL
15765 +       default y
15766 +       help
15767 +         This allows network contexts with a single IP to
15768 +         automatically remap 0.0.0.0 bindings to that IP,
15769 +         avoiding further network checks and improving
15770 +         performance.
15771 +
15772 +         (note: such guests do not allow to change the ip
15773 +          on the fly and do not show loopback addresses)
15774 +
15775 +config VSERVER_COWBL
15776 +       bool    "Enable COW Immutable Link Breaking"
15777 +       default y
15778 +       help
15779 +         This enables the COW (Copy-On-Write) link break code.
15780 +         It allows you to treat unified files like normal files
15781 +         when writing to them (which will implicitely break the
15782 +         link and create a copy of the unified file)
15783 +
15784 +config VSERVER_VTIME
15785 +       bool    "Enable Virtualized Guest Time"
15786 +       depends on EXPERIMENTAL
15787 +       default n
15788 +       help
15789 +         This enables per guest time offsets to allow for
15790 +         adjusting the system clock individually per guest.
15791 +         this adds some overhead to the time functions and
15792 +         therefore should not be enabled without good reason.
15793 +
15794 +config VSERVER_DEVICE
15795 +       bool    "Enable Guest Device Mapping"
15796 +       depends on EXPERIMENTAL
15797 +       default n
15798 +       help
15799 +         This enables generic device remapping.
15800 +
15801 +config VSERVER_PROC_SECURE
15802 +       bool    "Enable Proc Security"
15803 +       depends on PROC_FS
15804 +       default y
15805 +       help
15806 +         This configures ProcFS security to initially hide
15807 +         non-process entries for all contexts except the main and
15808 +         spectator context (i.e. for all guests), which is a secure
15809 +         default.
15810 +
15811 +         (note: on 1.2x the entries were visible by default)
15812 +
15813 +choice
15814 +       prompt  "Persistent Inode Tagging"
15815 +       default TAGGING_ID24
15816 +       help
15817 +         This adds persistent context information to filesystems
15818 +         mounted with the tagxid option. Tagging is a requirement
15819 +         for per-context disk limits and per-context quota.
15820 +
15821 +
15822 +config TAGGING_NONE
15823 +       bool    "Disabled"
15824 +       help
15825 +         do not store per-context information in inodes.
15826 +
15827 +config TAGGING_UID16
15828 +       bool    "UID16/GID32"
15829 +       help
15830 +         reduces UID to 16 bit, but leaves GID at 32 bit.
15831 +
15832 +config TAGGING_GID16
15833 +       bool    "UID32/GID16"
15834 +       help
15835 +         reduces GID to 16 bit, but leaves UID at 32 bit.
15836 +
15837 +config TAGGING_ID24
15838 +       bool    "UID24/GID24"
15839 +       help
15840 +         uses the upper 8bit from UID and GID for XID tagging
15841 +         which leaves 24bit for UID/GID each, which should be
15842 +         more than sufficient for normal use.
15843 +
15844 +config TAGGING_INTERN
15845 +       bool    "UID32/GID32"
15846 +       help
15847 +         this uses otherwise reserved inode fields in the on
15848 +         disk representation, which limits the use to a few
15849 +         filesystems (currently ext2 and ext3)
15850 +
15851 +endchoice
15852 +
15853 +config TAG_NFSD
15854 +       bool    "Tag NFSD User Auth and Files"
15855 +       default n
15856 +       help
15857 +         Enable this if you do want the in-kernel NFS
15858 +         Server to use the tagging specified above.
15859 +         (will require patched clients too)
15860 +
15861 +config VSERVER_PRIVACY
15862 +       bool    "Honor Privacy Aspects of Guests"
15863 +       default n
15864 +       help
15865 +         When enabled, most context checks will disallow
15866 +         access to structures assigned to a specific context,
15867 +         like ptys or loop devices.
15868 +
15869 +config VSERVER_CONTEXTS
15870 +       int     "Maximum number of Contexts (1-65533)"  if EMBEDDED
15871 +       range 1 65533
15872 +       default "768"   if 64BIT
15873 +       default "256"
15874 +       help
15875 +         This setting will optimize certain data structures
15876 +         and memory allocations according to the expected
15877 +         maximum.
15878 +
15879 +         note: this is not a strict upper limit.
15880 +
15881 +config VSERVER_WARN
15882 +       bool    "VServer Warnings"
15883 +       default y
15884 +       help
15885 +         This enables various runtime warnings, which will
15886 +         notify about potential manipulation attempts or
15887 +         resource shortage. It is generally considered to
15888 +         be a good idea to have that enabled.
15889 +
15890 +config VSERVER_WARN_DEVPTS
15891 +       bool    "VServer DevPTS Warnings"
15892 +       depends on VSERVER_WARN
15893 +       default y
15894 +       help
15895 +         This enables DevPTS related warnings, issued when a
15896 +         process inside a context tries to lookup or access
15897 +         a dynamic pts from the host or a different context.
15898 +
15899 +config VSERVER_DEBUG
15900 +       bool    "VServer Debugging Code"
15901 +       default n
15902 +       help
15903 +         Set this to yes if you want to be able to activate
15904 +         debugging output at runtime. It adds a very small
15905 +         overhead to all vserver related functions and
15906 +         increases the kernel size by about 20k.
15907 +
15908 +config VSERVER_HISTORY
15909 +       bool    "VServer History Tracing"
15910 +       depends on VSERVER_DEBUG
15911 +       default n
15912 +       help
15913 +         Set this to yes if you want to record the history of
15914 +         linux-vserver activities, so they can be replayed in
15915 +         the event of a kernel panic or oops.
15916 +
15917 +config VSERVER_HISTORY_SIZE
15918 +       int     "Per-CPU History Size (32-65536)"
15919 +       depends on VSERVER_HISTORY
15920 +       range 32 65536
15921 +       default 64
15922 +       help
15923 +         This allows you to specify the number of entries in
15924 +         the per-CPU history buffer.
15925 +
15926 +config VSERVER_LEGACY_MEM
15927 +       bool    "Legacy Memory Limits"
15928 +       default n
15929 +       help
15930 +         This provides fake memory limits to keep
15931 +         older tools happy in the face of memory
15932 +         cgroups
15933 +
15934 +choice
15935 +       prompt  "Quotes used in debug and warn messages"
15936 +       default QUOTES_ISO8859
15937 +
15938 +config QUOTES_ISO8859
15939 +       bool    "Extended ASCII (ISO 8859) angle quotes"
15940 +       help
15941 +         This uses the extended ASCII characters \xbb
15942 +         and \xab for quoting file and process names.
15943 +
15944 +config QUOTES_UTF8
15945 +       bool    "UTF-8 angle quotes"
15946 +       help
15947 +         This uses the the UTF-8 sequences for angle
15948 +         quotes to quote file and process names.
15949 +
15950 +config QUOTES_ASCII
15951 +       bool    "ASCII single quotes"
15952 +       help
15953 +         This uses the ASCII single quote character
15954 +         (\x27) to quote file and process names.
15955 +
15956 +endchoice
15957 +
15958 +endmenu
15959 +
15960 +
15961 +config VSERVER
15962 +       bool
15963 +       default y
15964 +       select NAMESPACES
15965 +       select UTS_NS
15966 +       select IPC_NS
15967 +#      select USER_NS
15968 +       select SYSVIPC
15969 +
15970 +config VSERVER_SECURITY
15971 +       bool
15972 +       depends on SECURITY
15973 +       default y
15974 +       select SECURITY_CAPABILITIES
15975 +
15976 +config VSERVER_DISABLED
15977 +       bool
15978 +       default n
15979 +
15980 diff -NurpP --minimal linux-3.0.25/kernel/vserver/Makefile linux-3.0.25-vs2.3.2.3/kernel/vserver/Makefile
15981 --- linux-3.0.25/kernel/vserver/Makefile        1970-01-01 01:00:00.000000000 +0100
15982 +++ linux-3.0.25-vs2.3.2.3/kernel/vserver/Makefile      2011-06-10 22:11:24.000000000 +0200
15983 @@ -0,0 +1,18 @@
15984 +#
15985 +# Makefile for the Linux vserver routines.
15986 +#
15987 +
15988 +
15989 +obj-y          += vserver.o
15990 +
15991 +vserver-y      := switch.o context.o space.o sched.o network.o inode.o \
15992 +                  limit.o cvirt.o cacct.o signal.o helper.o init.o \
15993 +                  dlimit.o tag.o
15994 +
15995 +vserver-$(CONFIG_INET) += inet.o
15996 +vserver-$(CONFIG_PROC_FS) += proc.o
15997 +vserver-$(CONFIG_VSERVER_DEBUG) += sysctl.o debug.o
15998 +vserver-$(CONFIG_VSERVER_HISTORY) += history.o
15999 +vserver-$(CONFIG_VSERVER_MONITOR) += monitor.o
16000 +vserver-$(CONFIG_VSERVER_DEVICE) += device.o
16001 +
16002 diff -NurpP --minimal linux-3.0.25/kernel/vserver/cacct.c linux-3.0.25-vs2.3.2.3/kernel/vserver/cacct.c
16003 --- linux-3.0.25/kernel/vserver/cacct.c 1970-01-01 01:00:00.000000000 +0100
16004 +++ linux-3.0.25-vs2.3.2.3/kernel/vserver/cacct.c       2011-06-10 22:11:24.000000000 +0200
16005 @@ -0,0 +1,42 @@
16006 +/*
16007 + *  linux/kernel/vserver/cacct.c
16008 + *
16009 + *  Virtual Server: Context Accounting
16010 + *
16011 + *  Copyright (C) 2006-2007 Herbert Pötzl
16012 + *
16013 + *  V0.01  added accounting stats
16014 + *
16015 + */
16016 +
16017 +#include <linux/types.h>
16018 +#include <linux/vs_context.h>
16019 +#include <linux/vserver/cacct_cmd.h>
16020 +#include <linux/vserver/cacct_int.h>
16021 +
16022 +#include <asm/errno.h>
16023 +#include <asm/uaccess.h>
16024 +
16025 +
16026 +int vc_sock_stat(struct vx_info *vxi, void __user *data)
16027 +{
16028 +       struct vcmd_sock_stat_v0 vc_data;
16029 +       int j, field;
16030 +
16031 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16032 +               return -EFAULT;
16033 +
16034 +       field = vc_data.field;
16035 +       if ((field < 0) || (field >= VXA_SOCK_SIZE))
16036 +               return -EINVAL;
16037 +
16038 +       for (j = 0; j < 3; j++) {
16039 +               vc_data.count[j] = vx_sock_count(&vxi->cacct, field, j);
16040 +               vc_data.total[j] = vx_sock_total(&vxi->cacct, field, j);
16041 +       }
16042 +
16043 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16044 +               return -EFAULT;
16045 +       return 0;
16046 +}
16047 +
16048 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
16049 --- linux-3.0.25/kernel/vserver/cacct_init.h    1970-01-01 01:00:00.000000000 +0100
16050 +++ linux-3.0.25-vs2.3.2.3/kernel/vserver/cacct_init.h  2011-06-10 22:11:24.000000000 +0200
16051 @@ -0,0 +1,25 @@
16052 +
16053 +
16054 +static inline void vx_info_init_cacct(struct _vx_cacct *cacct)
16055 +{
16056 +       int i, j;
16057 +
16058 +
16059 +       for (i = 0; i < VXA_SOCK_SIZE; i++) {
16060 +               for (j = 0; j < 3; j++) {
16061 +                       atomic_long_set(&cacct->sock[i][j].count, 0);
16062 +                       atomic_long_set(&cacct->sock[i][j].total, 0);
16063 +               }
16064 +       }
16065 +       for (i = 0; i < 8; i++)
16066 +               atomic_set(&cacct->slab[i], 0);
16067 +       for (i = 0; i < 5; i++)
16068 +               for (j = 0; j < 4; j++)
16069 +                       atomic_set(&cacct->page[i][j], 0);
16070 +}
16071 +
16072 +static inline void vx_info_exit_cacct(struct _vx_cacct *cacct)
16073 +{
16074 +       return;
16075 +}
16076 +
16077 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
16078 --- linux-3.0.25/kernel/vserver/cacct_proc.h    1970-01-01 01:00:00.000000000 +0100
16079 +++ linux-3.0.25-vs2.3.2.3/kernel/vserver/cacct_proc.h  2011-06-10 22:11:24.000000000 +0200
16080 @@ -0,0 +1,53 @@
16081 +#ifndef _VX_CACCT_PROC_H
16082 +#define _VX_CACCT_PROC_H
16083 +
16084 +#include <linux/vserver/cacct_int.h>
16085 +
16086 +
16087 +#define VX_SOCKA_TOP   \
16088 +       "Type\t    recv #/bytes\t\t   send #/bytes\t\t    fail #/bytes\n"
16089 +
16090 +static inline int vx_info_proc_cacct(struct _vx_cacct *cacct, char *buffer)
16091 +{
16092 +       int i, j, length = 0;
16093 +       static char *type[VXA_SOCK_SIZE] = {
16094 +               "UNSPEC", "UNIX", "INET", "INET6", "PACKET", "OTHER"
16095 +       };
16096 +
16097 +       length += sprintf(buffer + length, VX_SOCKA_TOP);
16098 +       for (i = 0; i < VXA_SOCK_SIZE; i++) {
16099 +               length += sprintf(buffer + length, "%s:", type[i]);
16100 +               for (j = 0; j < 3; j++) {
16101 +                       length += sprintf(buffer + length,
16102 +                               "\t%10lu/%-10lu",
16103 +                               vx_sock_count(cacct, i, j),
16104 +                               vx_sock_total(cacct, i, j));
16105 +               }
16106 +               buffer[length++] = '\n';
16107 +       }
16108 +
16109 +       length += sprintf(buffer + length, "\n");
16110 +       length += sprintf(buffer + length,
16111 +               "slab:\t %8u %8u %8u %8u\n",
16112 +               atomic_read(&cacct->slab[1]),
16113 +               atomic_read(&cacct->slab[4]),
16114 +               atomic_read(&cacct->slab[0]),
16115 +               atomic_read(&cacct->slab[2]));
16116 +
16117 +       length += sprintf(buffer + length, "\n");
16118 +       for (i = 0; i < 5; i++) {
16119 +               length += sprintf(buffer + length,
16120 +                       "page[%d]: %8u %8u %8u %8u\t %8u %8u %8u %8u\n", i,
16121 +                       atomic_read(&cacct->page[i][0]),
16122 +                       atomic_read(&cacct->page[i][1]),
16123 +                       atomic_read(&cacct->page[i][2]),
16124 +                       atomic_read(&cacct->page[i][3]),
16125 +                       atomic_read(&cacct->page[i][4]),
16126 +                       atomic_read(&cacct->page[i][5]),
16127 +                       atomic_read(&cacct->page[i][6]),
16128 +                       atomic_read(&cacct->page[i][7]));
16129 +       }
16130 +       return length;
16131 +}
16132 +
16133 +#endif /* _VX_CACCT_PROC_H */
16134 diff -NurpP --minimal linux-3.0.25/kernel/vserver/context.c linux-3.0.25-vs2.3.2.3/kernel/vserver/context.c
16135 --- linux-3.0.25/kernel/vserver/context.c       1970-01-01 01:00:00.000000000 +0100
16136 +++ linux-3.0.25-vs2.3.2.3/kernel/vserver/context.c     2011-08-01 18:28:12.000000000 +0200
16137 @@ -0,0 +1,1107 @@
16138 +/*
16139 + *  linux/kernel/vserver/context.c
16140 + *
16141 + *  Virtual Server: Context Support
16142 + *
16143 + *  Copyright (C) 2003-2011  Herbert Pötzl
16144 + *
16145 + *  V0.01  context helper
16146 + *  V0.02  vx_ctx_kill syscall command
16147 + *  V0.03  replaced context_info calls
16148 + *  V0.04  redesign of struct (de)alloc
16149 + *  V0.05  rlimit basic implementation
16150 + *  V0.06  task_xid and info commands
16151 + *  V0.07  context flags and caps
16152 + *  V0.08  switch to RCU based hash
16153 + *  V0.09  revert to non RCU for now
16154 + *  V0.10  and back to working RCU hash
16155 + *  V0.11  and back to locking again
16156 + *  V0.12  referenced context store
16157 + *  V0.13  separate per cpu data
16158 + *  V0.14  changed vcmds to vxi arg
16159 + *  V0.15  added context stat
16160 + *  V0.16  have __create claim() the vxi
16161 + *  V0.17  removed older and legacy stuff
16162 + *  V0.18  added user credentials
16163 + *  V0.19  added warn mask
16164 + *
16165 + */
16166 +
16167 +#include <linux/slab.h>
16168 +#include <linux/types.h>
16169 +#include <linux/security.h>
16170 +#include <linux/pid_namespace.h>
16171 +#include <linux/capability.h>
16172 +
16173 +#include <linux/vserver/context.h>
16174 +#include <linux/vserver/network.h>
16175 +#include <linux/vserver/debug.h>
16176 +#include <linux/vserver/limit.h>
16177 +#include <linux/vserver/limit_int.h>
16178 +#include <linux/vserver/space.h>
16179 +#include <linux/init_task.h>
16180 +#include <linux/fs_struct.h>
16181 +#include <linux/cred.h>
16182 +
16183 +#include <linux/vs_context.h>
16184 +#include <linux/vs_limit.h>
16185 +#include <linux/vs_pid.h>
16186 +#include <linux/vserver/context_cmd.h>
16187 +
16188 +#include "cvirt_init.h"
16189 +#include "cacct_init.h"
16190 +#include "limit_init.h"
16191 +#include "sched_init.h"
16192 +
16193 +
16194 +atomic_t vx_global_ctotal      = ATOMIC_INIT(0);
16195 +atomic_t vx_global_cactive     = ATOMIC_INIT(0);
16196 +
16197 +
16198 +/*     now inactive context structures */
16199 +
16200 +static struct hlist_head vx_info_inactive = HLIST_HEAD_INIT;
16201 +
16202 +static DEFINE_SPINLOCK(vx_info_inactive_lock);
16203 +
16204 +
16205 +/*     __alloc_vx_info()
16206 +
16207 +       * allocate an initialized vx_info struct
16208 +       * doesn't make it visible (hash)                        */
16209 +
16210 +static struct vx_info *__alloc_vx_info(xid_t xid)
16211 +{
16212 +       struct vx_info *new = NULL;
16213 +       int cpu, index;
16214 +
16215 +       vxdprintk(VXD_CBIT(xid, 0), "alloc_vx_info(%d)*", xid);
16216 +
16217 +       /* would this benefit from a slab cache? */
16218 +       new = kmalloc(sizeof(struct vx_info), GFP_KERNEL);
16219 +       if (!new)
16220 +               return 0;
16221 +
16222 +       memset(new, 0, sizeof(struct vx_info));
16223 +#ifdef CONFIG_SMP
16224 +       new->ptr_pc = alloc_percpu(struct _vx_info_pc);
16225 +       if (!new->ptr_pc)
16226 +               goto error;
16227 +#endif
16228 +       new->vx_id = xid;
16229 +       INIT_HLIST_NODE(&new->vx_hlist);
16230 +       atomic_set(&new->vx_usecnt, 0);
16231 +       atomic_set(&new->vx_tasks, 0);
16232 +       new->vx_parent = NULL;
16233 +       new->vx_state = 0;
16234 +       init_waitqueue_head(&new->vx_wait);
16235 +
16236 +       /* prepare reaper */
16237 +       get_task_struct(init_pid_ns.child_reaper);
16238 +       new->vx_reaper = init_pid_ns.child_reaper;
16239 +       new->vx_badness_bias = 0;
16240 +
16241 +       /* rest of init goes here */
16242 +       vx_info_init_limit(&new->limit);
16243 +       vx_info_init_sched(&new->sched);
16244 +       vx_info_init_cvirt(&new->cvirt);
16245 +       vx_info_init_cacct(&new->cacct);
16246 +
16247 +       /* per cpu data structures */
16248 +       for_each_possible_cpu(cpu) {
16249 +               vx_info_init_sched_pc(
16250 +                       &vx_per_cpu(new, sched_pc, cpu), cpu);
16251 +               vx_info_init_cvirt_pc(
16252 +                       &vx_per_cpu(new, cvirt_pc, cpu), cpu);
16253 +       }
16254 +
16255 +       new->vx_flags = VXF_INIT_SET;
16256 +       new->vx_bcaps = CAP_FULL_SET;   // maybe ~CAP_SETPCAP
16257 +       new->vx_ccaps = 0;
16258 +       new->vx_umask = 0;
16259 +       new->vx_wmask = 0;
16260 +
16261 +       new->reboot_cmd = 0;
16262 +       new->exit_code = 0;
16263 +
16264 +       // preconfig spaces
16265 +       for (index = 0; index < VX_SPACES; index++) {
16266 +               struct _vx_space *space = &new->space[index];
16267 +
16268 +               // filesystem
16269 +               spin_lock(&init_fs.lock);
16270 +               init_fs.users++;
16271 +               spin_unlock(&init_fs.lock);
16272 +               space->vx_fs = &init_fs;
16273 +
16274 +               /* FIXME: do we want defaults? */
16275 +               // space->vx_real_cred = 0;
16276 +               // space->vx_cred = 0;
16277 +       }
16278 +
16279 +
16280 +       vxdprintk(VXD_CBIT(xid, 0),
16281 +               "alloc_vx_info(%d) = %p", xid, new);
16282 +       vxh_alloc_vx_info(new);
16283 +       atomic_inc(&vx_global_ctotal);
16284 +       return new;
16285 +#ifdef CONFIG_SMP
16286 +error:
16287 +       kfree(new);
16288 +       return 0;
16289 +#endif
16290 +}
16291 +
16292 +/*     __dealloc_vx_info()
16293 +
16294 +       * final disposal of vx_info                             */
16295 +
16296 +static void __dealloc_vx_info(struct vx_info *vxi)
16297 +{
16298 +#ifdef CONFIG_VSERVER_WARN
16299 +       struct vx_info_save vxis;
16300 +       int cpu;
16301 +#endif
16302 +       vxdprintk(VXD_CBIT(xid, 0),
16303 +               "dealloc_vx_info(%p)", vxi);
16304 +       vxh_dealloc_vx_info(vxi);
16305 +
16306 +#ifdef CONFIG_VSERVER_WARN
16307 +       enter_vx_info(vxi, &vxis);
16308 +       vx_info_exit_limit(&vxi->limit);
16309 +       vx_info_exit_sched(&vxi->sched);
16310 +       vx_info_exit_cvirt(&vxi->cvirt);
16311 +       vx_info_exit_cacct(&vxi->cacct);
16312 +
16313 +       for_each_possible_cpu(cpu) {
16314 +               vx_info_exit_sched_pc(
16315 +                       &vx_per_cpu(vxi, sched_pc, cpu), cpu);
16316 +               vx_info_exit_cvirt_pc(
16317 +                       &vx_per_cpu(vxi, cvirt_pc, cpu), cpu);
16318 +       }
16319 +       leave_vx_info(&vxis);
16320 +#endif
16321 +
16322 +       vxi->vx_id = -1;
16323 +       vxi->vx_state |= VXS_RELEASED;
16324 +
16325 +#ifdef CONFIG_SMP
16326 +       free_percpu(vxi->ptr_pc);
16327 +#endif
16328 +       kfree(vxi);
16329 +       atomic_dec(&vx_global_ctotal);
16330 +}
16331 +
16332 +static void __shutdown_vx_info(struct vx_info *vxi)
16333 +{
16334 +       struct nsproxy *nsproxy;
16335 +       struct fs_struct *fs;
16336 +       struct cred *cred;
16337 +       int index, kill;
16338 +
16339 +       might_sleep();
16340 +
16341 +       vxi->vx_state |= VXS_SHUTDOWN;
16342 +       vs_state_change(vxi, VSC_SHUTDOWN);
16343 +
16344 +       for (index = 0; index < VX_SPACES; index++) {
16345 +               struct _vx_space *space = &vxi->space[index];
16346 +
16347 +               nsproxy = xchg(&space->vx_nsproxy, NULL);
16348 +               if (nsproxy)
16349 +                       put_nsproxy(nsproxy);
16350 +
16351 +               fs = xchg(&space->vx_fs, NULL);
16352 +               spin_lock(&fs->lock);
16353 +               kill = !--fs->users;
16354 +               spin_unlock(&fs->lock);
16355 +               if (kill)
16356 +                       free_fs_struct(fs);
16357 +
16358 +               cred = (struct cred *)xchg(&space->vx_cred, NULL);
16359 +               if (cred)
16360 +                       abort_creds(cred);
16361 +       }
16362 +}
16363 +
16364 +/* exported stuff */
16365 +
16366 +void free_vx_info(struct vx_info *vxi)
16367 +{
16368 +       unsigned long flags;
16369 +       unsigned index;
16370 +
16371 +       /* check for reference counts first */
16372 +       BUG_ON(atomic_read(&vxi->vx_usecnt));
16373 +       BUG_ON(atomic_read(&vxi->vx_tasks));
16374 +
16375 +       /* context must not be hashed */
16376 +       BUG_ON(vx_info_state(vxi, VXS_HASHED));
16377 +
16378 +       /* context shutdown is mandatory */
16379 +       BUG_ON(!vx_info_state(vxi, VXS_SHUTDOWN));
16380 +
16381 +       /* spaces check */
16382 +       for (index = 0; index < VX_SPACES; index++) {
16383 +               struct _vx_space *space = &vxi->space[index];
16384 +
16385 +               BUG_ON(space->vx_nsproxy);
16386 +               BUG_ON(space->vx_fs);
16387 +               // BUG_ON(space->vx_real_cred);
16388 +               // BUG_ON(space->vx_cred);
16389 +       }
16390 +
16391 +       spin_lock_irqsave(&vx_info_inactive_lock, flags);
16392 +       hlist_del(&vxi->vx_hlist);
16393 +       spin_unlock_irqrestore(&vx_info_inactive_lock, flags);
16394 +
16395 +       __dealloc_vx_info(vxi);
16396 +}
16397 +
16398 +
16399 +/*     hash table for vx_info hash */
16400 +
16401 +#define VX_HASH_SIZE   13
16402 +
16403 +static struct hlist_head vx_info_hash[VX_HASH_SIZE] =
16404 +       { [0 ... VX_HASH_SIZE-1] = HLIST_HEAD_INIT };
16405 +
16406 +static DEFINE_SPINLOCK(vx_info_hash_lock);
16407 +
16408 +
16409 +static inline unsigned int __hashval(xid_t xid)
16410 +{
16411 +       return (xid % VX_HASH_SIZE);
16412 +}
16413 +
16414 +
16415 +
16416 +/*     __hash_vx_info()
16417 +
16418 +       * add the vxi to the global hash table
16419 +       * requires the hash_lock to be held                     */
16420 +
16421 +static inline void __hash_vx_info(struct vx_info *vxi)
16422 +{
16423 +       struct hlist_head *head;
16424 +
16425 +       vxd_assert_lock(&vx_info_hash_lock);
16426 +       vxdprintk(VXD_CBIT(xid, 4),
16427 +               "__hash_vx_info: %p[#%d]", vxi, vxi->vx_id);
16428 +       vxh_hash_vx_info(vxi);
16429 +
16430 +       /* context must not be hashed */
16431 +       BUG_ON(vx_info_state(vxi, VXS_HASHED));
16432 +
16433 +       vxi->vx_state |= VXS_HASHED;
16434 +       head = &vx_info_hash[__hashval(vxi->vx_id)];
16435 +       hlist_add_head(&vxi->vx_hlist, head);
16436 +       atomic_inc(&vx_global_cactive);
16437 +}
16438 +
16439 +/*     __unhash_vx_info()
16440 +
16441 +       * remove the vxi from the global hash table
16442 +       * requires the hash_lock to be held                     */
16443 +
16444 +static inline void __unhash_vx_info(struct vx_info *vxi)
16445 +{
16446 +       unsigned long flags;
16447 +
16448 +       vxd_assert_lock(&vx_info_hash_lock);
16449 +       vxdprintk(VXD_CBIT(xid, 4),
16450 +               "__unhash_vx_info: %p[#%d.%d.%d]", vxi, vxi->vx_id,
16451 +               atomic_read(&vxi->vx_usecnt), atomic_read(&vxi->vx_tasks));
16452 +       vxh_unhash_vx_info(vxi);
16453 +
16454 +       /* context must be hashed */
16455 +       BUG_ON(!vx_info_state(vxi, VXS_HASHED));
16456 +       /* but without tasks */
16457 +       BUG_ON(atomic_read(&vxi->vx_tasks));
16458 +
16459 +       vxi->vx_state &= ~VXS_HASHED;
16460 +       hlist_del_init(&vxi->vx_hlist);
16461 +       spin_lock_irqsave(&vx_info_inactive_lock, flags);
16462 +       hlist_add_head(&vxi->vx_hlist, &vx_info_inactive);
16463 +       spin_unlock_irqrestore(&vx_info_inactive_lock, flags);
16464 +       atomic_dec(&vx_global_cactive);
16465 +}
16466 +
16467 +
16468 +/*     __lookup_vx_info()
16469 +
16470 +       * requires the hash_lock to be held
16471 +       * doesn't increment the vx_refcnt                       */
16472 +
16473 +static inline struct vx_info *__lookup_vx_info(xid_t xid)
16474 +{
16475 +       struct hlist_head *head = &vx_info_hash[__hashval(xid)];
16476 +       struct hlist_node *pos;
16477 +       struct vx_info *vxi;
16478 +
16479 +       vxd_assert_lock(&vx_info_hash_lock);
16480 +       hlist_for_each(pos, head) {
16481 +               vxi = hlist_entry(pos, struct vx_info, vx_hlist);
16482 +
16483 +               if (vxi->vx_id == xid)
16484 +                       goto found;
16485 +       }
16486 +       vxi = NULL;
16487 +found:
16488 +       vxdprintk(VXD_CBIT(xid, 0),
16489 +               "__lookup_vx_info(#%u): %p[#%u]",
16490 +               xid, vxi, vxi ? vxi->vx_id : 0);
16491 +       vxh_lookup_vx_info(vxi, xid);
16492 +       return vxi;
16493 +}
16494 +
16495 +
16496 +/*     __create_vx_info()
16497 +
16498 +       * create the requested context
16499 +       * get(), claim() and hash it                            */
16500 +
16501 +static struct vx_info *__create_vx_info(int id)
16502 +{
16503 +       struct vx_info *new, *vxi = NULL;
16504 +
16505 +       vxdprintk(VXD_CBIT(xid, 1), "create_vx_info(%d)*", id);
16506 +
16507 +       if (!(new = __alloc_vx_info(id)))
16508 +               return ERR_PTR(-ENOMEM);
16509 +
16510 +       /* required to make dynamic xids unique */
16511 +       spin_lock(&vx_info_hash_lock);
16512 +
16513 +       /* static context requested */
16514 +       if ((vxi = __lookup_vx_info(id))) {
16515 +               vxdprintk(VXD_CBIT(xid, 0),
16516 +                       "create_vx_info(%d) = %p (already there)", id, vxi);
16517 +               if (vx_info_flags(vxi, VXF_STATE_SETUP, 0))
16518 +                       vxi = ERR_PTR(-EBUSY);
16519 +               else
16520 +                       vxi = ERR_PTR(-EEXIST);
16521 +               goto out_unlock;
16522 +       }
16523 +       /* new context */
16524 +       vxdprintk(VXD_CBIT(xid, 0),
16525 +               "create_vx_info(%d) = %p (new)", id, new);
16526 +       claim_vx_info(new, NULL);
16527 +       __hash_vx_info(get_vx_info(new));
16528 +       vxi = new, new = NULL;
16529 +
16530 +out_unlock:
16531 +       spin_unlock(&vx_info_hash_lock);
16532 +       vxh_create_vx_info(IS_ERR(vxi) ? NULL : vxi, id);
16533 +       if (new)
16534 +               __dealloc_vx_info(new);
16535 +       return vxi;
16536 +}
16537 +
16538 +
16539 +/*     exported stuff                                          */
16540 +
16541 +
16542 +void unhash_vx_info(struct vx_info *vxi)
16543 +{
16544 +       spin_lock(&vx_info_hash_lock);
16545 +       __unhash_vx_info(vxi);
16546 +       spin_unlock(&vx_info_hash_lock);
16547 +       __shutdown_vx_info(vxi);
16548 +       __wakeup_vx_info(vxi);
16549 +}
16550 +
16551 +
16552 +/*     lookup_vx_info()
16553 +
16554 +       * search for a vx_info and get() it
16555 +       * negative id means current                             */
16556 +
16557 +struct vx_info *lookup_vx_info(int id)
16558 +{
16559 +       struct vx_info *vxi = NULL;
16560 +
16561 +       if (id < 0) {
16562 +               vxi = get_vx_info(current_vx_info());
16563 +       } else if (id > 1) {
16564 +               spin_lock(&vx_info_hash_lock);
16565 +               vxi = get_vx_info(__lookup_vx_info(id));
16566 +               spin_unlock(&vx_info_hash_lock);
16567 +       }
16568 +       return vxi;
16569 +}
16570 +
16571 +/*     xid_is_hashed()
16572 +
16573 +       * verify that xid is still hashed                       */
16574 +
16575 +int xid_is_hashed(xid_t xid)
16576 +{
16577 +       int hashed;
16578 +
16579 +       spin_lock(&vx_info_hash_lock);
16580 +       hashed = (__lookup_vx_info(xid) != NULL);
16581 +       spin_unlock(&vx_info_hash_lock);
16582 +       return hashed;
16583 +}
16584 +
16585 +#ifdef CONFIG_PROC_FS
16586 +
16587 +/*     get_xid_list()
16588 +
16589 +       * get a subset of hashed xids for proc
16590 +       * assumes size is at least one                          */
16591 +
16592 +int get_xid_list(int index, unsigned int *xids, int size)
16593 +{
16594 +       int hindex, nr_xids = 0;
16595 +
16596 +       /* only show current and children */
16597 +       if (!vx_check(0, VS_ADMIN | VS_WATCH)) {
16598 +               if (index > 0)
16599 +                       return 0;
16600 +               xids[nr_xids] = vx_current_xid();
16601 +               return 1;
16602 +       }
16603 +
16604 +       for (hindex = 0; hindex < VX_HASH_SIZE; hindex++) {
16605 +               struct hlist_head *head = &vx_info_hash[hindex];
16606 +               struct hlist_node *pos;
16607 +
16608 +               spin_lock(&vx_info_hash_lock);
16609 +               hlist_for_each(pos, head) {
16610 +                       struct vx_info *vxi;
16611 +
16612 +                       if (--index > 0)
16613 +                               continue;
16614 +
16615 +                       vxi = hlist_entry(pos, struct vx_info, vx_hlist);
16616 +                       xids[nr_xids] = vxi->vx_id;
16617 +                       if (++nr_xids >= size) {
16618 +                               spin_unlock(&vx_info_hash_lock);
16619 +                               goto out;
16620 +                       }
16621 +               }
16622 +               /* keep the lock time short */
16623 +               spin_unlock(&vx_info_hash_lock);
16624 +       }
16625 +out:
16626 +       return nr_xids;
16627 +}
16628 +#endif
16629 +
16630 +#ifdef CONFIG_VSERVER_DEBUG
16631 +
16632 +void   dump_vx_info_inactive(int level)
16633 +{
16634 +       struct hlist_node *entry, *next;
16635 +
16636 +       hlist_for_each_safe(entry, next, &vx_info_inactive) {
16637 +               struct vx_info *vxi =
16638 +                       list_entry(entry, struct vx_info, vx_hlist);
16639 +
16640 +               dump_vx_info(vxi, level);
16641 +       }
16642 +}
16643 +
16644 +#endif
16645 +
16646 +#if 0
16647 +int vx_migrate_user(struct task_struct *p, struct vx_info *vxi)
16648 +{
16649 +       struct user_struct *new_user, *old_user;
16650 +
16651 +       if (!p || !vxi)
16652 +               BUG();
16653 +
16654 +       if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0))
16655 +               return -EACCES;
16656 +
16657 +       new_user = alloc_uid(vxi->vx_id, p->uid);
16658 +       if (!new_user)
16659 +               return -ENOMEM;
16660 +
16661 +       old_user = p->user;
16662 +       if (new_user != old_user) {
16663 +               atomic_inc(&new_user->processes);
16664 +               atomic_dec(&old_user->processes);
16665 +               p->user = new_user;
16666 +       }
16667 +       free_uid(old_user);
16668 +       return 0;
16669 +}
16670 +#endif
16671 +
16672 +#if 0
16673 +void vx_mask_cap_bset(struct vx_info *vxi, struct task_struct *p)
16674 +{
16675 +       // p->cap_effective &= vxi->vx_cap_bset;
16676 +       p->cap_effective =
16677 +               cap_intersect(p->cap_effective, vxi->cap_bset);
16678 +       // p->cap_inheritable &= vxi->vx_cap_bset;
16679 +       p->cap_inheritable =
16680 +               cap_intersect(p->cap_inheritable, vxi->cap_bset);
16681 +       // p->cap_permitted &= vxi->vx_cap_bset;
16682 +       p->cap_permitted =
16683 +               cap_intersect(p->cap_permitted, vxi->cap_bset);
16684 +}
16685 +#endif
16686 +
16687 +
16688 +#include <linux/file.h>
16689 +#include <linux/fdtable.h>
16690 +
16691 +static int vx_openfd_task(struct task_struct *tsk)
16692 +{
16693 +       struct files_struct *files = tsk->files;
16694 +       struct fdtable *fdt;
16695 +       const unsigned long *bptr;
16696 +       int count, total;
16697 +
16698 +       /* no rcu_read_lock() because of spin_lock() */
16699 +       spin_lock(&files->file_lock);
16700 +       fdt = files_fdtable(files);
16701 +       bptr = fdt->open_fds->fds_bits;
16702 +       count = fdt->max_fds / (sizeof(unsigned long) * 8);
16703 +       for (total = 0; count > 0; count--) {
16704 +               if (*bptr)
16705 +                       total += hweight_long(*bptr);
16706 +               bptr++;
16707 +       }
16708 +       spin_unlock(&files->file_lock);
16709 +       return total;
16710 +}
16711 +
16712 +
16713 +/*     for *space compatibility */
16714 +
16715 +asmlinkage long sys_unshare(unsigned long);
16716 +
16717 +/*
16718 + *     migrate task to new context
16719 + *     gets vxi, puts old_vxi on change
16720 + *     optionally unshares namespaces (hack)
16721 + */
16722 +
16723 +int vx_migrate_task(struct task_struct *p, struct vx_info *vxi, int unshare)
16724 +{
16725 +       struct vx_info *old_vxi;
16726 +       int ret = 0;
16727 +
16728 +       if (!p || !vxi)
16729 +               BUG();
16730 +
16731 +       vxdprintk(VXD_CBIT(xid, 5),
16732 +               "vx_migrate_task(%p,%p[#%d.%d])", p, vxi,
16733 +               vxi->vx_id, atomic_read(&vxi->vx_usecnt));
16734 +
16735 +       if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0) &&
16736 +               !vx_info_flags(vxi, VXF_STATE_SETUP, 0))
16737 +               return -EACCES;
16738 +
16739 +       if (vx_info_state(vxi, VXS_SHUTDOWN))
16740 +               return -EFAULT;
16741 +
16742 +       old_vxi = task_get_vx_info(p);
16743 +       if (old_vxi == vxi)
16744 +               goto out;
16745 +
16746 +//     if (!(ret = vx_migrate_user(p, vxi))) {
16747 +       {
16748 +               int openfd;
16749 +
16750 +               task_lock(p);
16751 +               openfd = vx_openfd_task(p);
16752 +
16753 +               if (old_vxi) {
16754 +                       atomic_dec(&old_vxi->cvirt.nr_threads);
16755 +                       atomic_dec(&old_vxi->cvirt.nr_running);
16756 +                       __rlim_dec(&old_vxi->limit, RLIMIT_NPROC);
16757 +                       /* FIXME: what about the struct files here? */
16758 +                       __rlim_sub(&old_vxi->limit, VLIMIT_OPENFD, openfd);
16759 +                       /* account for the executable */
16760 +                       __rlim_dec(&old_vxi->limit, VLIMIT_DENTRY);
16761 +               }
16762 +               atomic_inc(&vxi->cvirt.nr_threads);
16763 +               atomic_inc(&vxi->cvirt.nr_running);
16764 +               __rlim_inc(&vxi->limit, RLIMIT_NPROC);
16765 +               /* FIXME: what about the struct files here? */
16766 +               __rlim_add(&vxi->limit, VLIMIT_OPENFD, openfd);
16767 +               /* account for the executable */
16768 +               __rlim_inc(&vxi->limit, VLIMIT_DENTRY);
16769 +
16770 +               if (old_vxi) {
16771 +                       release_vx_info(old_vxi, p);
16772 +                       clr_vx_info(&p->vx_info);
16773 +               }
16774 +               claim_vx_info(vxi, p);
16775 +               set_vx_info(&p->vx_info, vxi);
16776 +               p->xid = vxi->vx_id;
16777 +
16778 +               vxdprintk(VXD_CBIT(xid, 5),
16779 +                       "moved task %p into vxi:%p[#%d]",
16780 +                       p, vxi, vxi->vx_id);
16781 +
16782 +               // vx_mask_cap_bset(vxi, p);
16783 +               task_unlock(p);
16784 +
16785 +               /* hack for *spaces to provide compatibility */
16786 +               if (unshare) {
16787 +                       struct nsproxy *old_nsp, *new_nsp;
16788 +
16789 +                       ret = unshare_nsproxy_namespaces(
16790 +                               CLONE_NEWUTS | CLONE_NEWIPC | CLONE_NEWUSER,
16791 +                               &new_nsp, NULL);
16792 +                       if (ret)
16793 +                               goto out;
16794 +
16795 +                       old_nsp = xchg(&p->nsproxy, new_nsp);
16796 +                       vx_set_space(vxi,
16797 +                               CLONE_NEWUTS | CLONE_NEWIPC | CLONE_NEWUSER, 0);
16798 +                       put_nsproxy(old_nsp);
16799 +               }
16800 +       }
16801 +out:
16802 +       put_vx_info(old_vxi);
16803 +       return ret;
16804 +}
16805 +
16806 +int vx_set_reaper(struct vx_info *vxi, struct task_struct *p)
16807 +{
16808 +       struct task_struct *old_reaper;
16809 +
16810 +       if (!vxi)
16811 +               return -EINVAL;
16812 +
16813 +       vxdprintk(VXD_CBIT(xid, 6),
16814 +               "vx_set_reaper(%p[#%d],%p[#%d,%d])",
16815 +               vxi, vxi->vx_id, p, p->xid, p->pid);
16816 +
16817 +       old_reaper = vxi->vx_reaper;
16818 +       if (old_reaper == p)
16819 +               return 0;
16820 +
16821 +       /* set new child reaper */
16822 +       get_task_struct(p);
16823 +       vxi->vx_reaper = p;
16824 +       put_task_struct(old_reaper);
16825 +       return 0;
16826 +}
16827 +
16828 +int vx_set_init(struct vx_info *vxi, struct task_struct *p)
16829 +{
16830 +       if (!vxi)
16831 +               return -EINVAL;
16832 +
16833 +       vxdprintk(VXD_CBIT(xid, 6),
16834 +               "vx_set_init(%p[#%d],%p[#%d,%d,%d])",
16835 +               vxi, vxi->vx_id, p, p->xid, p->pid, p->tgid);
16836 +
16837 +       vxi->vx_flags &= ~VXF_STATE_INIT;
16838 +       // vxi->vx_initpid = p->tgid;
16839 +       vxi->vx_initpid = p->pid;
16840 +       return 0;
16841 +}
16842 +
16843 +void vx_exit_init(struct vx_info *vxi, struct task_struct *p, int code)
16844 +{
16845 +       vxdprintk(VXD_CBIT(xid, 6),
16846 +               "vx_exit_init(%p[#%d],%p[#%d,%d,%d])",
16847 +               vxi, vxi->vx_id, p, p->xid, p->pid, p->tgid);
16848 +
16849 +       vxi->exit_code = code;
16850 +       vxi->vx_initpid = 0;
16851 +}
16852 +
16853 +
16854 +void vx_set_persistent(struct vx_info *vxi)
16855 +{
16856 +       vxdprintk(VXD_CBIT(xid, 6),
16857 +               "vx_set_persistent(%p[#%d])", vxi, vxi->vx_id);
16858 +
16859 +       get_vx_info(vxi);
16860 +       claim_vx_info(vxi, NULL);
16861 +}
16862 +
16863 +void vx_clear_persistent(struct vx_info *vxi)
16864 +{
16865 +       vxdprintk(VXD_CBIT(xid, 6),
16866 +               "vx_clear_persistent(%p[#%d])", vxi, vxi->vx_id);
16867 +
16868 +       release_vx_info(vxi, NULL);
16869 +       put_vx_info(vxi);
16870 +}
16871 +
16872 +void vx_update_persistent(struct vx_info *vxi)
16873 +{
16874 +       if (vx_info_flags(vxi, VXF_PERSISTENT, 0))
16875 +               vx_set_persistent(vxi);
16876 +       else
16877 +               vx_clear_persistent(vxi);
16878 +}
16879 +
16880 +
16881 +/*     task must be current or locked          */
16882 +
16883 +void   exit_vx_info(struct task_struct *p, int code)
16884 +{
16885 +       struct vx_info *vxi = p->vx_info;
16886 +
16887 +       if (vxi) {
16888 +               atomic_dec(&vxi->cvirt.nr_threads);
16889 +               vx_nproc_dec(p);
16890 +
16891 +               vxi->exit_code = code;
16892 +               release_vx_info(vxi, p);
16893 +       }
16894 +}
16895 +
16896 +void   exit_vx_info_early(struct task_struct *p, int code)
16897 +{
16898 +       struct vx_info *vxi = p->vx_info;
16899 +
16900 +       if (vxi) {
16901 +               if (vxi->vx_initpid == p->pid)
16902 +                       vx_exit_init(vxi, p, code);
16903 +               if (vxi->vx_reaper == p)
16904 +                       vx_set_reaper(vxi, init_pid_ns.child_reaper);
16905 +       }
16906 +}
16907 +
16908 +
16909 +/* vserver syscall commands below here */
16910 +
16911 +/* taks xid and vx_info functions */
16912 +
16913 +#include <asm/uaccess.h>
16914 +
16915 +
16916 +int vc_task_xid(uint32_t id)
16917 +{
16918 +       xid_t xid;
16919 +
16920 +       if (id) {
16921 +               struct task_struct *tsk;
16922 +
16923 +               rcu_read_lock();
16924 +               tsk = find_task_by_real_pid(id);
16925 +               xid = (tsk) ? tsk->xid : -ESRCH;
16926 +               rcu_read_unlock();
16927 +       } else
16928 +               xid = vx_current_xid();
16929 +       return xid;
16930 +}
16931 +
16932 +
16933 +int vc_vx_info(struct vx_info *vxi, void __user *data)
16934 +{
16935 +       struct vcmd_vx_info_v0 vc_data;
16936 +
16937 +       vc_data.xid = vxi->vx_id;
16938 +       vc_data.initpid = vxi->vx_initpid;
16939 +
16940 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16941 +               return -EFAULT;
16942 +       return 0;
16943 +}
16944 +
16945 +
16946 +int vc_ctx_stat(struct vx_info *vxi, void __user *data)
16947 +{
16948 +       struct vcmd_ctx_stat_v0 vc_data;
16949 +
16950 +       vc_data.usecnt = atomic_read(&vxi->vx_usecnt);
16951 +       vc_data.tasks = atomic_read(&vxi->vx_tasks);
16952 +
16953 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16954 +               return -EFAULT;
16955 +       return 0;
16956 +}
16957 +
16958 +
16959 +/* context functions */
16960 +
16961 +int vc_ctx_create(uint32_t xid, void __user *data)
16962 +{
16963 +       struct vcmd_ctx_create vc_data = { .flagword = VXF_INIT_SET };
16964 +       struct vx_info *new_vxi;
16965 +       int ret;
16966 +
16967 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
16968 +               return -EFAULT;
16969 +
16970 +       if ((xid > MAX_S_CONTEXT) || (xid < 2))
16971 +               return -EINVAL;
16972 +
16973 +       new_vxi = __create_vx_info(xid);
16974 +       if (IS_ERR(new_vxi))
16975 +               return PTR_ERR(new_vxi);
16976 +
16977 +       /* initial flags */
16978 +       new_vxi->vx_flags = vc_data.flagword;
16979 +
16980 +       ret = -ENOEXEC;
16981 +       if (vs_state_change(new_vxi, VSC_STARTUP))
16982 +               goto out;
16983 +
16984 +       ret = vx_migrate_task(current, new_vxi, (!data));
16985 +       if (ret)
16986 +               goto out;
16987 +
16988 +       /* return context id on success */
16989 +       ret = new_vxi->vx_id;
16990 +
16991 +       /* get a reference for persistent contexts */
16992 +       if ((vc_data.flagword & VXF_PERSISTENT))
16993 +               vx_set_persistent(new_vxi);
16994 +out:
16995 +       release_vx_info(new_vxi, NULL);
16996 +       put_vx_info(new_vxi);
16997 +       return ret;
16998 +}
16999 +
17000 +
17001 +int vc_ctx_migrate(struct vx_info *vxi, void __user *data)
17002 +{
17003 +       struct vcmd_ctx_migrate vc_data = { .flagword = 0 };
17004 +       int ret;
17005 +
17006 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
17007 +               return -EFAULT;
17008 +
17009 +       ret = vx_migrate_task(current, vxi, 0);
17010 +       if (ret)
17011 +               return ret;
17012 +       if (vc_data.flagword & VXM_SET_INIT)
17013 +               ret = vx_set_init(vxi, current);
17014 +       if (ret)
17015 +               return ret;
17016 +       if (vc_data.flagword & VXM_SET_REAPER)
17017 +               ret = vx_set_reaper(vxi, current);
17018 +       return ret;
17019 +}
17020 +
17021 +
17022 +int vc_get_cflags(struct vx_info *vxi, void __user *data)
17023 +{
17024 +       struct vcmd_ctx_flags_v0 vc_data;
17025 +
17026 +       vc_data.flagword = vxi->vx_flags;
17027 +
17028 +       /* special STATE flag handling */
17029 +       vc_data.mask = vs_mask_flags(~0ULL, vxi->vx_flags, VXF_ONE_TIME);
17030 +
17031 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
17032 +               return -EFAULT;
17033 +       return 0;
17034 +}
17035 +
17036 +int vc_set_cflags(struct vx_info *vxi, void __user *data)
17037 +{
17038 +       struct vcmd_ctx_flags_v0 vc_data;
17039 +       uint64_t mask, trigger;
17040 +
17041 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17042 +               return -EFAULT;
17043 +
17044 +       /* special STATE flag handling */
17045 +       mask = vs_mask_mask(vc_data.mask, vxi->vx_flags, VXF_ONE_TIME);
17046 +       trigger = (mask & vxi->vx_flags) ^ (mask & vc_data.flagword);
17047 +
17048 +       if (vxi == current_vx_info()) {
17049 +               /* if (trigger & VXF_STATE_SETUP)
17050 +                       vx_mask_cap_bset(vxi, current); */
17051 +               if (trigger & VXF_STATE_INIT) {
17052 +                       int ret;
17053 +
17054 +                       ret = vx_set_init(vxi, current);
17055 +                       if (ret)
17056 +                               return ret;
17057 +                       ret = vx_set_reaper(vxi, current);
17058 +                       if (ret)
17059 +                               return ret;
17060 +               }
17061 +       }
17062 +
17063 +       vxi->vx_flags = vs_mask_flags(vxi->vx_flags,
17064 +               vc_data.flagword, mask);
17065 +       if (trigger & VXF_PERSISTENT)
17066 +               vx_update_persistent(vxi);
17067 +
17068 +       return 0;
17069 +}
17070 +
17071 +
17072 +static inline uint64_t caps_from_cap_t(kernel_cap_t c)
17073 +{
17074 +       uint64_t v = c.cap[0] | ((uint64_t)c.cap[1] << 32);
17075 +
17076 +       // printk("caps_from_cap_t(%08x:%08x) = %016llx\n", c.cap[1], c.cap[0], v);
17077 +       return v;
17078 +}
17079 +
17080 +static inline kernel_cap_t cap_t_from_caps(uint64_t v)
17081 +{
17082 +       kernel_cap_t c = __cap_empty_set;
17083 +
17084 +       c.cap[0] = v & 0xFFFFFFFF;
17085 +       c.cap[1] = (v >> 32) & 0xFFFFFFFF;
17086 +
17087 +       // printk("cap_t_from_caps(%016llx) = %08x:%08x\n", v, c.cap[1], c.cap[0]);
17088 +       return c;
17089 +}
17090 +
17091 +
17092 +static int do_get_caps(struct vx_info *vxi, uint64_t *bcaps, uint64_t *ccaps)
17093 +{
17094 +       if (bcaps)
17095 +               *bcaps = caps_from_cap_t(vxi->vx_bcaps);
17096 +       if (ccaps)
17097 +               *ccaps = vxi->vx_ccaps;
17098 +
17099 +       return 0;
17100 +}
17101 +
17102 +int vc_get_ccaps(struct vx_info *vxi, void __user *data)
17103 +{
17104 +       struct vcmd_ctx_caps_v1 vc_data;
17105 +       int ret;
17106 +
17107 +       ret = do_get_caps(vxi, NULL, &vc_data.ccaps);
17108 +       if (ret)
17109 +               return ret;
17110 +       vc_data.cmask = ~0ULL;
17111 +
17112 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
17113 +               return -EFAULT;
17114 +       return 0;
17115 +}
17116 +
17117 +static int do_set_caps(struct vx_info *vxi,
17118 +       uint64_t bcaps, uint64_t bmask, uint64_t ccaps, uint64_t cmask)
17119 +{
17120 +       uint64_t bcold = caps_from_cap_t(vxi->vx_bcaps);
17121 +
17122 +#if 0
17123 +       printk("do_set_caps(%16llx, %16llx, %16llx, %16llx)\n",
17124 +               bcaps, bmask, ccaps, cmask);
17125 +#endif
17126 +       vxi->vx_bcaps = cap_t_from_caps(
17127 +               vs_mask_flags(bcold, bcaps, bmask));
17128 +       vxi->vx_ccaps = vs_mask_flags(vxi->vx_ccaps, ccaps, cmask);
17129 +
17130 +       return 0;
17131 +}
17132 +
17133 +int vc_set_ccaps(struct vx_info *vxi, void __user *data)
17134 +{
17135 +       struct vcmd_ctx_caps_v1 vc_data;
17136 +
17137 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17138 +               return -EFAULT;
17139 +
17140 +       return do_set_caps(vxi, 0, 0, vc_data.ccaps, vc_data.cmask);
17141 +}
17142 +
17143 +int vc_get_bcaps(struct vx_info *vxi, void __user *data)
17144 +{
17145 +       struct vcmd_bcaps vc_data;
17146 +       int ret;
17147 +
17148 +       ret = do_get_caps(vxi, &vc_data.bcaps, NULL);
17149 +       if (ret)
17150 +               return ret;
17151 +       vc_data.bmask = ~0ULL;
17152 +
17153 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
17154 +               return -EFAULT;
17155 +       return 0;
17156 +}
17157 +
17158 +int vc_set_bcaps(struct vx_info *vxi, void __user *data)
17159 +{
17160 +       struct vcmd_bcaps vc_data;
17161 +
17162 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17163 +               return -EFAULT;
17164 +
17165 +       return do_set_caps(vxi, vc_data.bcaps, vc_data.bmask, 0, 0);
17166 +}
17167 +
17168 +
17169 +int vc_get_umask(struct vx_info *vxi, void __user *data)
17170 +{
17171 +       struct vcmd_umask vc_data;
17172 +
17173 +       vc_data.umask = vxi->vx_umask;
17174 +       vc_data.mask = ~0ULL;
17175 +
17176 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
17177 +               return -EFAULT;
17178 +       return 0;
17179 +}
17180 +
17181 +int vc_set_umask(struct vx_info *vxi, void __user *data)
17182 +{
17183 +       struct vcmd_umask vc_data;
17184 +
17185 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17186 +               return -EFAULT;
17187 +
17188 +       vxi->vx_umask = vs_mask_flags(vxi->vx_umask,
17189 +               vc_data.umask, vc_data.mask);
17190 +       return 0;
17191 +}
17192 +
17193 +
17194 +int vc_get_wmask(struct vx_info *vxi, void __user *data)
17195 +{
17196 +       struct vcmd_wmask vc_data;
17197 +
17198 +       vc_data.wmask = vxi->vx_wmask;
17199 +       vc_data.mask = ~0ULL;
17200 +
17201 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
17202 +               return -EFAULT;
17203 +       return 0;
17204 +}
17205 +
17206 +int vc_set_wmask(struct vx_info *vxi, void __user *data)
17207 +{
17208 +       struct vcmd_wmask vc_data;
17209 +
17210 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17211 +               return -EFAULT;
17212 +
17213 +       vxi->vx_wmask = vs_mask_flags(vxi->vx_wmask,
17214 +               vc_data.wmask, vc_data.mask);
17215 +       return 0;
17216 +}
17217 +
17218 +
17219 +int vc_get_badness(struct vx_info *vxi, void __user *data)
17220 +{
17221 +       struct vcmd_badness_v0 vc_data;
17222 +
17223 +       vc_data.bias = vxi->vx_badness_bias;
17224 +
17225 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
17226 +               return -EFAULT;
17227 +       return 0;
17228 +}
17229 +
17230 +int vc_set_badness(struct vx_info *vxi, void __user *data)
17231 +{
17232 +       struct vcmd_badness_v0 vc_data;
17233 +
17234 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17235 +               return -EFAULT;
17236 +
17237 +       vxi->vx_badness_bias = vc_data.bias;
17238 +       return 0;
17239 +}
17240 +
17241 +#include <linux/module.h>
17242 +
17243 +EXPORT_SYMBOL_GPL(free_vx_info);
17244 +
17245 diff -NurpP --minimal linux-3.0.25/kernel/vserver/cvirt.c linux-3.0.25-vs2.3.2.3/kernel/vserver/cvirt.c
17246 --- linux-3.0.25/kernel/vserver/cvirt.c 1970-01-01 01:00:00.000000000 +0100
17247 +++ linux-3.0.25-vs2.3.2.3/kernel/vserver/cvirt.c       2011-06-13 14:57:26.000000000 +0200
17248 @@ -0,0 +1,303 @@
17249 +/*
17250 + *  linux/kernel/vserver/cvirt.c
17251 + *
17252 + *  Virtual Server: Context Virtualization
17253 + *
17254 + *  Copyright (C) 2004-2007  Herbert Pötzl
17255 + *
17256 + *  V0.01  broken out from limit.c
17257 + *  V0.02  added utsname stuff
17258 + *  V0.03  changed vcmds to vxi arg
17259 + *
17260 + */
17261 +
17262 +#include <linux/types.h>
17263 +#include <linux/utsname.h>
17264 +#include <linux/vs_cvirt.h>
17265 +#include <linux/vserver/switch.h>
17266 +#include <linux/vserver/cvirt_cmd.h>
17267 +
17268 +#include <asm/uaccess.h>
17269 +
17270 +
17271 +void vx_vsi_uptime(struct timespec *uptime, struct timespec *idle)
17272 +{
17273 +       struct vx_info *vxi = current_vx_info();
17274 +
17275 +       set_normalized_timespec(uptime,
17276 +               uptime->tv_sec - vxi->cvirt.bias_uptime.tv_sec,
17277 +               uptime->tv_nsec - vxi->cvirt.bias_uptime.tv_nsec);
17278 +       if (!idle)
17279 +               return;
17280 +       set_normalized_timespec(idle,
17281 +               idle->tv_sec - vxi->cvirt.bias_idle.tv_sec,
17282 +               idle->tv_nsec - vxi->cvirt.bias_idle.tv_nsec);
17283 +       return;
17284 +}
17285 +
17286 +uint64_t vx_idle_jiffies(void)
17287 +{
17288 +       return init_task.utime + init_task.stime;
17289 +}
17290 +
17291 +
17292 +
17293 +static inline uint32_t __update_loadavg(uint32_t load,
17294 +       int wsize, int delta, int n)
17295 +{
17296 +       unsigned long long calc, prev;
17297 +
17298 +       /* just set it to n */
17299 +       if (unlikely(delta >= wsize))
17300 +               return (n << FSHIFT);
17301 +
17302 +       calc = delta * n;
17303 +       calc <<= FSHIFT;
17304 +       prev = (wsize - delta);
17305 +       prev *= load;
17306 +       calc += prev;
17307 +       do_div(calc, wsize);
17308 +       return calc;
17309 +}
17310 +
17311 +
17312 +void vx_update_load(struct vx_info *vxi)
17313 +{
17314 +       uint32_t now, last, delta;
17315 +       unsigned int nr_running, nr_uninterruptible;
17316 +       unsigned int total;
17317 +       unsigned long flags;
17318 +
17319 +       spin_lock_irqsave(&vxi->cvirt.load_lock, flags);
17320 +
17321 +       now = jiffies;
17322 +       last = vxi->cvirt.load_last;
17323 +       delta = now - last;
17324 +
17325 +       if (delta < 5*HZ)
17326 +               goto out;
17327 +
17328 +       nr_running = atomic_read(&vxi->cvirt.nr_running);
17329 +       nr_uninterruptible = atomic_read(&vxi->cvirt.nr_uninterruptible);
17330 +       total = nr_running + nr_uninterruptible;
17331 +
17332 +       vxi->cvirt.load[0] = __update_loadavg(vxi->cvirt.load[0],
17333 +               60*HZ, delta, total);
17334 +       vxi->cvirt.load[1] = __update_loadavg(vxi->cvirt.load[1],
17335 +               5*60*HZ, delta, total);
17336 +       vxi->cvirt.load[2] = __update_loadavg(vxi->cvirt.load[2],
17337 +               15*60*HZ, delta, total);
17338 +
17339 +       vxi->cvirt.load_last = now;
17340 +out:
17341 +       atomic_inc(&vxi->cvirt.load_updates);
17342 +       spin_unlock_irqrestore(&vxi->cvirt.load_lock, flags);
17343 +}
17344 +
17345 +
17346 +/*
17347 + * Commands to do_syslog:
17348 + *
17349 + *      0 -- Close the log.  Currently a NOP.
17350 + *      1 -- Open the log. Currently a NOP.
17351 + *      2 -- Read from the log.
17352 + *      3 -- Read all messages remaining in the ring buffer.
17353 + *      4 -- Read and clear all messages remaining in the ring buffer
17354 + *      5 -- Clear ring buffer.
17355 + *      6 -- Disable printk's to console
17356 + *      7 -- Enable printk's to console
17357 + *      8 -- Set level of messages printed to console
17358 + *      9 -- Return number of unread characters in the log buffer
17359 + *     10 -- Return size of the log buffer
17360 + */
17361 +int vx_do_syslog(int type, char __user *buf, int len)
17362 +{
17363 +       int error = 0;
17364 +       int do_clear = 0;
17365 +       struct vx_info *vxi = current_vx_info();
17366 +       struct _vx_syslog *log;
17367 +
17368 +       if (!vxi)
17369 +               return -EINVAL;
17370 +       log = &vxi->cvirt.syslog;
17371 +
17372 +       switch (type) {
17373 +       case 0:         /* Close log */
17374 +       case 1:         /* Open log */
17375 +               break;
17376 +       case 2:         /* Read from log */
17377 +               error = wait_event_interruptible(log->log_wait,
17378 +                       (log->log_start - log->log_end));
17379 +               if (error)
17380 +                       break;
17381 +               spin_lock_irq(&log->logbuf_lock);
17382 +               spin_unlock_irq(&log->logbuf_lock);
17383 +               break;
17384 +       case 4:         /* Read/clear last kernel messages */
17385 +               do_clear = 1;
17386 +               /* fall through */
17387 +       case 3:         /* Read last kernel messages */
17388 +               return 0;
17389 +
17390 +       case 5:         /* Clear ring buffer */
17391 +               return 0;
17392 +
17393 +       case 6:         /* Disable logging to console */
17394 +       case 7:         /* Enable logging to console */
17395 +       case 8:         /* Set level of messages printed to console */
17396 +               break;
17397 +
17398 +       case 9:         /* Number of chars in the log buffer */
17399 +               return 0;
17400 +       case 10:        /* Size of the log buffer */
17401 +               return 0;
17402 +       default:
17403 +               error = -EINVAL;
17404 +               break;
17405 +       }
17406 +       return error;
17407 +}
17408 +
17409 +
17410 +/* virtual host info names */
17411 +
17412 +static char *vx_vhi_name(struct vx_info *vxi, int id)
17413 +{
17414 +       struct nsproxy *nsproxy;
17415 +       struct uts_namespace *uts;
17416 +
17417 +       if (id == VHIN_CONTEXT)
17418 +               return vxi->vx_name;
17419 +
17420 +       nsproxy = vxi->space[0].vx_nsproxy;
17421 +       if (!nsproxy)
17422 +               return NULL;
17423 +
17424 +       uts = nsproxy->uts_ns;
17425 +       if (!uts)
17426 +               return NULL;
17427 +
17428 +       switch (id) {
17429 +       case VHIN_SYSNAME:
17430 +               return uts->name.sysname;
17431 +       case VHIN_NODENAME:
17432 +               return uts->name.nodename;
17433 +       case VHIN_RELEASE:
17434 +               return uts->name.release;
17435 +       case VHIN_VERSION:
17436 +               return uts->name.version;
17437 +       case VHIN_MACHINE:
17438 +               return uts->name.machine;
17439 +       case VHIN_DOMAINNAME:
17440 +               return uts->name.domainname;
17441 +       default:
17442 +               return NULL;
17443 +       }
17444 +       return NULL;
17445 +}
17446 +
17447 +int vc_set_vhi_name(struct vx_info *vxi, void __user *data)
17448 +{
17449 +       struct vcmd_vhi_name_v0 vc_data;
17450 +       char *name;
17451 +
17452 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17453 +               return -EFAULT;
17454 +
17455 +       name = vx_vhi_name(vxi, vc_data.field);
17456 +       if (!name)
17457 +               return -EINVAL;
17458 +
17459 +       memcpy(name, vc_data.name, 65);
17460 +       return 0;
17461 +}
17462 +
17463 +int vc_get_vhi_name(struct vx_info *vxi, void __user *data)
17464 +{
17465 +       struct vcmd_vhi_name_v0 vc_data;
17466 +       char *name;
17467 +
17468 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17469 +               return -EFAULT;
17470 +
17471 +       name = vx_vhi_name(vxi, vc_data.field);
17472 +       if (!name)
17473 +               return -EINVAL;
17474 +
17475 +       memcpy(vc_data.name, name, 65);
17476 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
17477 +               return -EFAULT;
17478 +       return 0;
17479 +}
17480 +
17481 +
17482 +int vc_virt_stat(struct vx_info *vxi, void __user *data)
17483 +{
17484 +       struct vcmd_virt_stat_v0 vc_data;
17485 +       struct _vx_cvirt *cvirt = &vxi->cvirt;
17486 +       struct timespec uptime;
17487 +
17488 +       do_posix_clock_monotonic_gettime(&uptime);
17489 +       set_normalized_timespec(&uptime,
17490 +               uptime.tv_sec - cvirt->bias_uptime.tv_sec,
17491 +               uptime.tv_nsec - cvirt->bias_uptime.tv_nsec);
17492 +
17493 +       vc_data.offset = timespec_to_ns(&cvirt->bias_ts);
17494 +       vc_data.uptime = timespec_to_ns(&uptime);
17495 +       vc_data.nr_threads = atomic_read(&cvirt->nr_threads);
17496 +       vc_data.nr_running = atomic_read(&cvirt->nr_running);
17497 +       vc_data.nr_uninterruptible = atomic_read(&cvirt->nr_uninterruptible);
17498 +       vc_data.nr_onhold = atomic_read(&cvirt->nr_onhold);
17499 +       vc_data.nr_forks = atomic_read(&cvirt->total_forks);
17500 +       vc_data.load[0] = cvirt->load[0];
17501 +       vc_data.load[1] = cvirt->load[1];
17502 +       vc_data.load[2] = cvirt->load[2];
17503 +
17504 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
17505 +               return -EFAULT;
17506 +       return 0;
17507 +}
17508 +
17509 +
17510 +#ifdef CONFIG_VSERVER_VTIME
17511 +
17512 +/* virtualized time base */
17513 +
17514 +void vx_adjust_timespec(struct timespec *ts)
17515 +{
17516 +       struct vx_info *vxi;
17517 +
17518 +       if (!vx_flags(VXF_VIRT_TIME, 0))
17519 +               return;
17520 +
17521 +       vxi = current_vx_info();
17522 +       ts->tv_sec += vxi->cvirt.bias_ts.tv_sec;
17523 +       ts->tv_nsec += vxi->cvirt.bias_ts.tv_nsec;
17524 +
17525 +       if (ts->tv_nsec >= NSEC_PER_SEC) {
17526 +               ts->tv_sec++;
17527 +               ts->tv_nsec -= NSEC_PER_SEC;
17528 +       } else if (ts->tv_nsec < 0) {
17529 +               ts->tv_sec--;
17530 +               ts->tv_nsec += NSEC_PER_SEC;
17531 +       }
17532 +}
17533 +
17534 +int vx_settimeofday(const struct timespec *ts)
17535 +{
17536 +       struct timespec ats, delta;
17537 +       struct vx_info *vxi;
17538 +
17539 +       if (!vx_flags(VXF_VIRT_TIME, 0))
17540 +               return do_settimeofday(ts);
17541 +
17542 +       getnstimeofday(&ats);
17543 +       delta = timespec_sub(*ts, ats);
17544 +
17545 +       vxi = current_vx_info();
17546 +       vxi->cvirt.bias_ts = timespec_add(vxi->cvirt.bias_ts, delta);
17547 +       return 0;
17548 +}
17549 +
17550 +#endif
17551 +
17552 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
17553 --- linux-3.0.25/kernel/vserver/cvirt_init.h    1970-01-01 01:00:00.000000000 +0100
17554 +++ linux-3.0.25-vs2.3.2.3/kernel/vserver/cvirt_init.h  2011-06-10 22:11:24.000000000 +0200
17555 @@ -0,0 +1,70 @@
17556 +
17557 +
17558 +extern uint64_t vx_idle_jiffies(void);
17559 +
17560 +static inline void vx_info_init_cvirt(struct _vx_cvirt *cvirt)
17561 +{
17562 +       uint64_t idle_jiffies = vx_idle_jiffies();
17563 +       uint64_t nsuptime;
17564 +
17565 +       do_posix_clock_monotonic_gettime(&cvirt->bias_uptime);
17566 +       nsuptime = (unsigned long long)cvirt->bias_uptime.tv_sec
17567 +               * NSEC_PER_SEC + cvirt->bias_uptime.tv_nsec;
17568 +       cvirt->bias_clock = nsec_to_clock_t(nsuptime);
17569 +       cvirt->bias_ts.tv_sec = 0;
17570 +       cvirt->bias_ts.tv_nsec = 0;
17571 +
17572 +       jiffies_to_timespec(idle_jiffies, &cvirt->bias_idle);
17573 +       atomic_set(&cvirt->nr_threads, 0);
17574 +       atomic_set(&cvirt->nr_running, 0);
17575 +       atomic_set(&cvirt->nr_uninterruptible, 0);
17576 +       atomic_set(&cvirt->nr_onhold, 0);
17577 +
17578 +       spin_lock_init(&cvirt->load_lock);
17579 +       cvirt->load_last = jiffies;
17580 +       atomic_set(&cvirt->load_updates, 0);
17581 +       cvirt->load[0] = 0;
17582 +       cvirt->load[1] = 0;
17583 +       cvirt->load[2] = 0;
17584 +       atomic_set(&cvirt->total_forks, 0);
17585 +
17586 +       spin_lock_init(&cvirt->syslog.logbuf_lock);
17587 +       init_waitqueue_head(&cvirt->syslog.log_wait);
17588 +       cvirt->syslog.log_start = 0;
17589 +       cvirt->syslog.log_end = 0;
17590 +       cvirt->syslog.con_start = 0;
17591 +       cvirt->syslog.logged_chars = 0;
17592 +}
17593 +
17594 +static inline
17595 +void vx_info_init_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc, int cpu)
17596 +{
17597 +       // cvirt_pc->cpustat = { 0 };
17598 +}
17599 +
17600 +static inline void vx_info_exit_cvirt(struct _vx_cvirt *cvirt)
17601 +{
17602 +#ifdef CONFIG_VSERVER_WARN
17603 +       int value;
17604 +#endif
17605 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_threads)),
17606 +               "!!! cvirt: %p[nr_threads] = %d on exit.",
17607 +               cvirt, value);
17608 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_running)),
17609 +               "!!! cvirt: %p[nr_running] = %d on exit.",
17610 +               cvirt, value);
17611 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_uninterruptible)),
17612 +               "!!! cvirt: %p[nr_uninterruptible] = %d on exit.",
17613 +               cvirt, value);
17614 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_onhold)),
17615 +               "!!! cvirt: %p[nr_onhold] = %d on exit.",
17616 +               cvirt, value);
17617 +       return;
17618 +}
17619 +
17620 +static inline
17621 +void vx_info_exit_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc, int cpu)
17622 +{
17623 +       return;
17624 +}
17625 +
17626 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
17627 --- linux-3.0.25/kernel/vserver/cvirt_proc.h    1970-01-01 01:00:00.000000000 +0100
17628 +++ linux-3.0.25-vs2.3.2.3/kernel/vserver/cvirt_proc.h  2011-06-10 22:11:24.000000000 +0200
17629 @@ -0,0 +1,135 @@
17630 +#ifndef _VX_CVIRT_PROC_H
17631 +#define _VX_CVIRT_PROC_H
17632 +
17633 +#include <linux/nsproxy.h>
17634 +#include <linux/mnt_namespace.h>
17635 +#include <linux/ipc_namespace.h>
17636 +#include <linux/utsname.h>
17637 +#include <linux/ipc.h>
17638 +
17639 +
17640 +static inline
17641 +int vx_info_proc_nsproxy(struct nsproxy *nsproxy, char *buffer)
17642 +{
17643 +       struct mnt_namespace *ns;
17644 +       struct uts_namespace *uts;
17645 +       struct ipc_namespace *ipc;
17646 +       struct path path;
17647 +       char *pstr, *root;
17648 +       int length = 0;
17649 +
17650 +       if (!nsproxy)
17651 +               goto out;
17652 +
17653 +       length += sprintf(buffer + length,
17654 +               "NSProxy:\t%p [%p,%p,%p]\n",
17655 +               nsproxy, nsproxy->mnt_ns,
17656 +               nsproxy->uts_ns, nsproxy->ipc_ns);
17657 +
17658 +       ns = nsproxy->mnt_ns;
17659 +       if (!ns)
17660 +               goto skip_ns;
17661 +
17662 +       pstr = kmalloc(PATH_MAX, GFP_KERNEL);
17663 +       if (!pstr)
17664 +               goto skip_ns;
17665 +
17666 +       path.mnt = ns->root;
17667 +       path.dentry = ns->root->mnt_root;
17668 +       root = d_path(&path, pstr, PATH_MAX - 2);
17669 +       length += sprintf(buffer + length,
17670 +               "Namespace:\t%p [#%u]\n"
17671 +               "RootPath:\t%s\n",
17672 +               ns, atomic_read(&ns->count),
17673 +               root);
17674 +       kfree(pstr);
17675 +skip_ns:
17676 +
17677 +       uts = nsproxy->uts_ns;
17678 +       if (!uts)
17679 +               goto skip_uts;
17680 +
17681 +       length += sprintf(buffer + length,
17682 +               "SysName:\t%.*s\n"
17683 +               "NodeName:\t%.*s\n"
17684 +               "Release:\t%.*s\n"
17685 +               "Version:\t%.*s\n"
17686 +               "Machine:\t%.*s\n"
17687 +               "DomainName:\t%.*s\n",
17688 +               __NEW_UTS_LEN, uts->name.sysname,
17689 +               __NEW_UTS_LEN, uts->name.nodename,
17690 +               __NEW_UTS_LEN, uts->name.release,
17691 +               __NEW_UTS_LEN, uts->name.version,
17692 +               __NEW_UTS_LEN, uts->name.machine,
17693 +               __NEW_UTS_LEN, uts->name.domainname);
17694 +skip_uts:
17695 +
17696 +       ipc = nsproxy->ipc_ns;
17697 +       if (!ipc)
17698 +               goto skip_ipc;
17699 +
17700 +       length += sprintf(buffer + length,
17701 +               "SEMS:\t\t%d %d %d %d  %d\n"
17702 +               "MSG:\t\t%d %d %d\n"
17703 +               "SHM:\t\t%lu %lu  %d %d\n",
17704 +               ipc->sem_ctls[0], ipc->sem_ctls[1],
17705 +               ipc->sem_ctls[2], ipc->sem_ctls[3],
17706 +               ipc->used_sems,
17707 +               ipc->msg_ctlmax, ipc->msg_ctlmnb, ipc->msg_ctlmni,
17708 +               (unsigned long)ipc->shm_ctlmax,
17709 +               (unsigned long)ipc->shm_ctlall,
17710 +               ipc->shm_ctlmni, ipc->shm_tot);
17711 +skip_ipc:
17712 +out:
17713 +       return length;
17714 +}
17715 +
17716 +
17717 +#include <linux/sched.h>
17718 +
17719 +#define LOAD_INT(x) ((x) >> FSHIFT)
17720 +#define LOAD_FRAC(x) LOAD_INT(((x) & (FIXED_1 - 1)) * 100)
17721 +
17722 +static inline
17723 +int vx_info_proc_cvirt(struct _vx_cvirt *cvirt, char *buffer)
17724 +{
17725 +       int length = 0;
17726 +       int a, b, c;
17727 +
17728 +       length += sprintf(buffer + length,
17729 +               "BiasUptime:\t%lu.%02lu\n",
17730 +               (unsigned long)cvirt->bias_uptime.tv_sec,
17731 +               (cvirt->bias_uptime.tv_nsec / (NSEC_PER_SEC / 100)));
17732 +
17733 +       a = cvirt->load[0] + (FIXED_1 / 200);
17734 +       b = cvirt->load[1] + (FIXED_1 / 200);
17735 +       c = cvirt->load[2] + (FIXED_1 / 200);
17736 +       length += sprintf(buffer + length,
17737 +               "nr_threads:\t%d\n"
17738 +               "nr_running:\t%d\n"
17739 +               "nr_unintr:\t%d\n"
17740 +               "nr_onhold:\t%d\n"
17741 +               "load_updates:\t%d\n"
17742 +               "loadavg:\t%d.%02d %d.%02d %d.%02d\n"
17743 +               "total_forks:\t%d\n",
17744 +               atomic_read(&cvirt->nr_threads),
17745 +               atomic_read(&cvirt->nr_running),
17746 +               atomic_read(&cvirt->nr_uninterruptible),
17747 +               atomic_read(&cvirt->nr_onhold),
17748 +               atomic_read(&cvirt->load_updates),
17749 +               LOAD_INT(a), LOAD_FRAC(a),
17750 +               LOAD_INT(b), LOAD_FRAC(b),
17751 +               LOAD_INT(c), LOAD_FRAC(c),
17752 +               atomic_read(&cvirt->total_forks));
17753 +       return length;
17754 +}
17755 +
17756 +static inline
17757 +int vx_info_proc_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc,
17758 +       char *buffer, int cpu)
17759 +{
17760 +       int length = 0;
17761 +       return length;
17762 +}
17763 +
17764 +#endif /* _VX_CVIRT_PROC_H */
17765 diff -NurpP --minimal linux-3.0.25/kernel/vserver/debug.c linux-3.0.25-vs2.3.2.3/kernel/vserver/debug.c
17766 --- linux-3.0.25/kernel/vserver/debug.c 1970-01-01 01:00:00.000000000 +0100
17767 +++ linux-3.0.25-vs2.3.2.3/kernel/vserver/debug.c       2011-06-10 22:11:24.000000000 +0200
17768 @@ -0,0 +1,32 @@
17769 +/*
17770 + *  kernel/vserver/debug.c
17771 + *
17772 + *  Copyright (C) 2005-2007 Herbert Pötzl
17773 + *
17774 + *  V0.01  vx_info dump support
17775 + *
17776 + */
17777 +
17778 +#include <linux/module.h>
17779 +
17780 +#include <linux/vserver/context.h>
17781 +
17782 +
17783 +void   dump_vx_info(struct vx_info *vxi, int level)
17784 +{
17785 +       printk("vx_info %p[#%d, %d.%d, %4x]\n", vxi, vxi->vx_id,
17786 +               atomic_read(&vxi->vx_usecnt),
17787 +               atomic_read(&vxi->vx_tasks),
17788 +               vxi->vx_state);
17789 +       if (level > 0) {
17790 +               __dump_vx_limit(&vxi->limit);
17791 +               __dump_vx_sched(&vxi->sched);
17792 +               __dump_vx_cvirt(&vxi->cvirt);
17793 +               __dump_vx_cacct(&vxi->cacct);
17794 +       }
17795 +       printk("---\n");
17796 +}
17797 +
17798 +
17799 +EXPORT_SYMBOL_GPL(dump_vx_info);
17800 +
17801 diff -NurpP --minimal linux-3.0.25/kernel/vserver/device.c linux-3.0.25-vs2.3.2.3/kernel/vserver/device.c
17802 --- linux-3.0.25/kernel/vserver/device.c        1970-01-01 01:00:00.000000000 +0100
17803 +++ linux-3.0.25-vs2.3.2.3/kernel/vserver/device.c      2011-06-10 23:20:56.000000000 +0200
17804 @@ -0,0 +1,443 @@
17805 +/*
17806 + *  linux/kernel/vserver/device.c
17807 + *
17808 + *  Linux-VServer: Device Support
17809 + *
17810 + *  Copyright (C) 2006  Herbert Pötzl
17811 + *  Copyright (C) 2007  Daniel Hokka Zakrisson
17812 + *
17813 + *  V0.01  device mapping basics
17814 + *  V0.02  added defaults
17815 + *
17816 + */
17817 +
17818 +#include <linux/slab.h>
17819 +#include <linux/rcupdate.h>
17820 +#include <linux/fs.h>
17821 +#include <linux/namei.h>
17822 +#include <linux/hash.h>
17823 +
17824 +#include <asm/errno.h>
17825 +#include <asm/uaccess.h>
17826 +#include <linux/vserver/base.h>
17827 +#include <linux/vserver/debug.h>
17828 +#include <linux/vserver/context.h>
17829 +#include <linux/vserver/device.h>
17830 +#include <linux/vserver/device_cmd.h>
17831 +
17832 +
17833 +#define DMAP_HASH_BITS 4
17834 +
17835 +
17836 +struct vs_mapping {
17837 +       union {
17838 +               struct hlist_node hlist;
17839 +               struct list_head list;
17840 +       } u;
17841 +#define dm_hlist       u.hlist
17842 +#define dm_list                u.list
17843 +       xid_t xid;
17844 +       dev_t device;
17845 +       struct vx_dmap_target target;
17846 +};
17847 +
17848 +
17849 +static struct hlist_head dmap_main_hash[1 << DMAP_HASH_BITS];
17850 +
17851 +static DEFINE_SPINLOCK(dmap_main_hash_lock);
17852 +
17853 +static struct vx_dmap_target dmap_defaults[2] = {
17854 +       { .flags = DATTR_OPEN },
17855 +       { .flags = DATTR_OPEN },
17856 +};
17857 +
17858 +
17859 +struct kmem_cache *dmap_cachep __read_mostly;
17860 +
17861 +int __init dmap_cache_init(void)
17862 +{
17863 +       dmap_cachep = kmem_cache_create("dmap_cache",
17864 +               sizeof(struct vs_mapping), 0,
17865 +               SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
17866 +       return 0;
17867 +}
17868 +
17869 +__initcall(dmap_cache_init);
17870 +
17871 +
17872 +static inline unsigned int __hashval(dev_t dev, int bits)
17873 +{
17874 +       return hash_long((unsigned long)dev, bits);
17875 +}
17876 +
17877 +
17878 +/*     __hash_mapping()
17879 + *     add the mapping to the hash table
17880 + */
17881 +static inline void __hash_mapping(struct vx_info *vxi, struct vs_mapping *vdm)
17882 +{
17883 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
17884 +       struct hlist_head *head, *hash = dmap_main_hash;
17885 +       int device = vdm->device;
17886 +
17887 +       spin_lock(hash_lock);
17888 +       vxdprintk(VXD_CBIT(misc, 8), "__hash_mapping: %p[#%d] %08x:%08x",
17889 +               vxi, vxi ? vxi->vx_id : 0, device, vdm->target.target);
17890 +
17891 +       head = &hash[__hashval(device, DMAP_HASH_BITS)];
17892 +       hlist_add_head(&vdm->dm_hlist, head);
17893 +       spin_unlock(hash_lock);
17894 +}
17895 +
17896 +
17897 +static inline int __mode_to_default(umode_t mode)
17898 +{
17899 +       switch (mode) {
17900 +       case S_IFBLK:
17901 +               return 0;
17902 +       case S_IFCHR:
17903 +               return 1;
17904 +       default:
17905 +               BUG();
17906 +       }
17907 +}
17908 +
17909 +
17910 +/*     __set_default()
17911 + *     set a default
17912 + */
17913 +static inline void __set_default(struct vx_info *vxi, umode_t mode,
17914 +       struct vx_dmap_target *vdmt)
17915 +{
17916 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
17917 +       spin_lock(hash_lock);
17918 +
17919 +       if (vxi)
17920 +               vxi->dmap.targets[__mode_to_default(mode)] = *vdmt;
17921 +       else
17922 +               dmap_defaults[__mode_to_default(mode)] = *vdmt;
17923 +
17924 +
17925 +       spin_unlock(hash_lock);
17926 +
17927 +       vxdprintk(VXD_CBIT(misc, 8), "__set_default: %p[#%u] %08x %04x",
17928 +                 vxi, vxi ? vxi->vx_id : 0, vdmt->target, vdmt->flags);
17929 +}
17930 +
17931 +
17932 +/*     __remove_default()
17933 + *     remove a default
17934 + */
17935 +static inline int __remove_default(struct vx_info *vxi, umode_t mode)
17936 +{
17937 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
17938 +       spin_lock(hash_lock);
17939 +
17940 +       if (vxi)
17941 +               vxi->dmap.targets[__mode_to_default(mode)].flags = 0;
17942 +       else    /* remove == reset */
17943 +               dmap_defaults[__mode_to_default(mode)].flags = DATTR_OPEN | mode;
17944 +
17945 +       spin_unlock(hash_lock);
17946 +       return 0;
17947 +}
17948 +
17949 +
17950 +/*     __find_mapping()
17951 + *     find a mapping in the hash table
17952 + *
17953 + *     caller must hold hash_lock
17954 + */
17955 +static inline int __find_mapping(xid_t xid, dev_t device, umode_t mode,
17956 +       struct vs_mapping **local, struct vs_mapping **global)
17957 +{
17958 +       struct hlist_head *hash = dmap_main_hash;
17959 +       struct hlist_head *head = &hash[__hashval(device, DMAP_HASH_BITS)];
17960 +       struct hlist_node *pos;
17961 +       struct vs_mapping *vdm;
17962 +
17963 +       *local = NULL;
17964 +       if (global)
17965 +               *global = NULL;
17966 +
17967 +       hlist_for_each(pos, head) {
17968 +               vdm = hlist_entry(pos, struct vs_mapping, dm_hlist);
17969 +
17970 +               if ((vdm->device == device) &&
17971 +                       !((vdm->target.flags ^ mode) & S_IFMT)) {
17972 +                       if (vdm->xid == xid) {
17973 +                               *local = vdm;
17974 +                               return 1;
17975 +                       } else if (global && vdm->xid == 0)
17976 +                               *global = vdm;
17977 +               }
17978 +       }
17979 +
17980 +       if (global && *global)
17981 +               return 0;
17982 +       else
17983 +               return -ENOENT;
17984 +}
17985 +
17986 +
17987 +/*     __lookup_mapping()
17988 + *     find a mapping and store the result in target and flags
17989 + */
17990 +static inline int __lookup_mapping(struct vx_info *vxi,
17991 +       dev_t device, dev_t *target, int *flags, umode_t mode)
17992 +{
17993 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
17994 +       struct vs_mapping *vdm, *global;
17995 +       struct vx_dmap_target *vdmt;
17996 +       int ret = 0;
17997 +       xid_t xid = vxi->vx_id;
17998 +       int index;
17999 +
18000 +       spin_lock(hash_lock);
18001 +       if (__find_mapping(xid, device, mode, &vdm, &global) > 0) {
18002 +               ret = 1;
18003 +               vdmt = &vdm->target;
18004 +               goto found;
18005 +       }
18006 +
18007 +       index = __mode_to_default(mode);
18008 +       if (vxi && vxi->dmap.targets[index].flags) {
18009 +               ret = 2;
18010 +               vdmt = &vxi->dmap.targets[index];
18011 +       } else if (global) {
18012 +               ret = 3;
18013 +               vdmt = &global->target;
18014 +               goto found;
18015 +       } else {
18016 +               ret = 4;
18017 +               vdmt = &dmap_defaults[index];
18018 +       }
18019 +
18020 +found:
18021 +       if (target && (vdmt->flags & DATTR_REMAP))
18022 +               *target = vdmt->target;
18023 +       else if (target)
18024 +               *target = device;
18025 +       if (flags)
18026 +               *flags = vdmt->flags;
18027 +
18028 +       spin_unlock(hash_lock);
18029 +
18030 +       return ret;
18031 +}
18032 +
18033 +
18034 +/*     __remove_mapping()
18035 + *     remove a mapping from the hash table
18036 + */
18037 +static inline int __remove_mapping(struct vx_info *vxi, dev_t device,
18038 +       umode_t mode)
18039 +{
18040 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
18041 +       struct vs_mapping *vdm = NULL;
18042 +       int ret = 0;
18043 +
18044 +       spin_lock(hash_lock);
18045 +
18046 +       ret = __find_mapping((vxi ? vxi->vx_id : 0), device, mode, &vdm,
18047 +               NULL);
18048 +       vxdprintk(VXD_CBIT(misc, 8), "__remove_mapping: %p[#%d] %08x %04x",
18049 +               vxi, vxi ? vxi->vx_id : 0, device, mode);
18050 +       if (ret < 0)
18051 +               goto out;
18052 +       hlist_del(&vdm->dm_hlist);
18053 +
18054 +out:
18055 +       spin_unlock(hash_lock);
18056 +       if (vdm)
18057 +               kmem_cache_free(dmap_cachep, vdm);
18058 +       return ret;
18059 +}
18060 +
18061 +
18062 +
18063 +int vs_map_device(struct vx_info *vxi,
18064 +       dev_t device, dev_t *target, umode_t mode)
18065 +{
18066 +       int ret, flags = DATTR_MASK;
18067 +
18068 +       if (!vxi) {
18069 +               if (target)
18070 +                       *target = device;
18071 +               goto out;
18072 +       }
18073 +       ret = __lookup_mapping(vxi, device, target, &flags, mode);
18074 +       vxdprintk(VXD_CBIT(misc, 8), "vs_map_device: %08x target: %08x flags: %04x mode: %04x mapped=%d",
18075 +               device, target ? *target : 0, flags, mode, ret);
18076 +out:
18077 +       return (flags & DATTR_MASK);
18078 +}
18079 +
18080 +
18081 +
18082 +static int do_set_mapping(struct vx_info *vxi,
18083 +       dev_t device, dev_t target, int flags, umode_t mode)
18084 +{
18085 +       if (device) {
18086 +               struct vs_mapping *new;
18087 +
18088 +               new = kmem_cache_alloc(dmap_cachep, GFP_KERNEL);
18089 +               if (!new)
18090 +                       return -ENOMEM;
18091 +
18092 +               INIT_HLIST_NODE(&new->dm_hlist);
18093 +               new->device = device;
18094 +               new->target.target = target;
18095 +               new->target.flags = flags | mode;
18096 +               new->xid = (vxi ? vxi->vx_id : 0);
18097 +
18098 +               vxdprintk(VXD_CBIT(misc, 8), "do_set_mapping: %08x target: %08x flags: %04x", device, target, flags);
18099 +               __hash_mapping(vxi, new);
18100 +       } else {
18101 +               struct vx_dmap_target new = {
18102 +                       .target = target,
18103 +                       .flags = flags | mode,
18104 +               };
18105 +               __set_default(vxi, mode, &new);
18106 +       }
18107 +       return 0;
18108 +}
18109 +
18110 +
18111 +static int do_unset_mapping(struct vx_info *vxi,
18112 +       dev_t device, dev_t target, int flags, umode_t mode)
18113 +{
18114 +       int ret = -EINVAL;
18115 +
18116 +       if (device) {
18117 +               ret = __remove_mapping(vxi, device, mode);
18118 +               if (ret < 0)
18119 +                       goto out;
18120 +       } else {
18121 +               ret = __remove_default(vxi, mode);
18122 +               if (ret < 0)
18123 +                       goto out;
18124 +       }
18125 +
18126 +out:
18127 +       return ret;
18128 +}
18129 +
18130 +
18131 +static inline int __user_device(const char __user *name, dev_t *dev,
18132 +       umode_t *mode)
18133 +{
18134 +       struct nameidata nd;
18135 +       int ret;
18136 +
18137 +       if (!name) {
18138 +               *dev = 0;
18139 +               return 0;
18140 +       }
18141 +       ret = user_lpath(name, &nd.path);
18142 +       if (ret)
18143 +               return ret;
18144 +       if (nd.path.dentry->d_inode) {
18145 +               *dev = nd.path.dentry->d_inode->i_rdev;
18146 +               *mode = nd.path.dentry->d_inode->i_mode;
18147 +       }
18148 +       path_put(&nd.path);
18149 +       return 0;
18150 +}
18151 +
18152 +static inline int __mapping_mode(dev_t device, dev_t target,
18153 +       umode_t device_mode, umode_t target_mode, umode_t *mode)
18154 +{
18155 +       if (device)
18156 +               *mode = device_mode & S_IFMT;
18157 +       else if (target)
18158 +               *mode = target_mode & S_IFMT;
18159 +       else
18160 +               return -EINVAL;
18161 +
18162 +       /* if both given, device and target mode have to match */
18163 +       if (device && target &&
18164 +               ((device_mode ^ target_mode) & S_IFMT))
18165 +               return -EINVAL;
18166 +       return 0;
18167 +}
18168 +
18169 +
18170 +static inline int do_mapping(struct vx_info *vxi, const char __user *device_path,
18171 +       const char __user *target_path, int flags, int set)
18172 +{
18173 +       dev_t device = ~0, target = ~0;
18174 +       umode_t device_mode = 0, target_mode = 0, mode;
18175 +       int ret;
18176 +
18177 +       ret = __user_device(device_path, &device, &device_mode);
18178 +       if (ret)
18179 +               return ret;
18180 +       ret = __user_device(target_path, &target, &target_mode);
18181 +       if (ret)
18182 +               return ret;
18183 +
18184 +       ret = __mapping_mode(device, target,
18185 +               device_mode, target_mode, &mode);
18186 +       if (ret)
18187 +               return ret;
18188 +
18189 +       if (set)
18190 +               return do_set_mapping(vxi, device, target,
18191 +                       flags, mode);
18192 +       else
18193 +               return do_unset_mapping(vxi, device, target,
18194 +                       flags, mode);
18195 +}
18196 +
18197 +
18198 +int vc_set_mapping(struct vx_info *vxi, void __user *data)
18199 +{
18200 +       struct vcmd_set_mapping_v0 vc_data;
18201 +
18202 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18203 +               return -EFAULT;
18204 +
18205 +       return do_mapping(vxi, vc_data.device, vc_data.target,
18206 +               vc_data.flags, 1);
18207 +}
18208 +
18209 +int vc_unset_mapping(struct vx_info *vxi, void __user *data)
18210 +{
18211 +       struct vcmd_set_mapping_v0 vc_data;
18212 +
18213 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18214 +               return -EFAULT;
18215 +
18216 +       return do_mapping(vxi, vc_data.device, vc_data.target,
18217 +               vc_data.flags, 0);
18218 +}
18219 +
18220 +
18221 +#ifdef CONFIG_COMPAT
18222 +
18223 +int vc_set_mapping_x32(struct vx_info *vxi, void __user *data)
18224 +{
18225 +       struct vcmd_set_mapping_v0_x32 vc_data;
18226 +
18227 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18228 +               return -EFAULT;
18229 +
18230 +       return do_mapping(vxi, compat_ptr(vc_data.device_ptr),
18231 +               compat_ptr(vc_data.target_ptr), vc_data.flags, 1);
18232 +}
18233 +
18234 +int vc_unset_mapping_x32(struct vx_info *vxi, void __user *data)
18235 +{
18236 +       struct vcmd_set_mapping_v0_x32 vc_data;
18237 +
18238 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18239 +               return -EFAULT;
18240 +
18241 +       return do_mapping(vxi, compat_ptr(vc_data.device_ptr),
18242 +               compat_ptr(vc_data.target_ptr), vc_data.flags, 0);
18243 +}
18244 +
18245 +#endif /* CONFIG_COMPAT */
18246 +
18247 +
18248 diff -NurpP --minimal linux-3.0.25/kernel/vserver/dlimit.c linux-3.0.25-vs2.3.2.3/kernel/vserver/dlimit.c
18249 --- linux-3.0.25/kernel/vserver/dlimit.c        1970-01-01 01:00:00.000000000 +0100
18250 +++ linux-3.0.25-vs2.3.2.3/kernel/vserver/dlimit.c      2011-06-10 23:20:56.000000000 +0200
18251 @@ -0,0 +1,531 @@
18252 +/*
18253 + *  linux/kernel/vserver/dlimit.c
18254 + *
18255 + *  Virtual Server: Context Disk Limits
18256 + *
18257 + *  Copyright (C) 2004-2009  Herbert Pötzl
18258 + *
18259 + *  V0.01  initial version
18260 + *  V0.02  compat32 splitup
18261 + *  V0.03  extended interface
18262 + *
18263 + */
18264 +
18265 +#include <linux/statfs.h>
18266 +#include <linux/sched.h>
18267 +#include <linux/namei.h>
18268 +#include <linux/vs_tag.h>
18269 +#include <linux/vs_dlimit.h>
18270 +#include <linux/vserver/dlimit_cmd.h>
18271 +#include <linux/slab.h>
18272 +// #include <linux/gfp.h>
18273 +
18274 +#include <asm/uaccess.h>
18275 +
18276 +/*     __alloc_dl_info()
18277 +
18278 +       * allocate an initialized dl_info struct
18279 +       * doesn't make it visible (hash)                        */
18280 +
18281 +static struct dl_info *__alloc_dl_info(struct super_block *sb, tag_t tag)
18282 +{
18283 +       struct dl_info *new = NULL;
18284 +
18285 +       vxdprintk(VXD_CBIT(dlim, 5),
18286 +               "alloc_dl_info(%p,%d)*", sb, tag);
18287 +
18288 +       /* would this benefit from a slab cache? */
18289 +       new = kmalloc(sizeof(struct dl_info), GFP_KERNEL);
18290 +       if (!new)
18291 +               return 0;
18292 +
18293 +       memset(new, 0, sizeof(struct dl_info));
18294 +       new->dl_tag = tag;
18295 +       new->dl_sb = sb;
18296 +       // INIT_RCU_HEAD(&new->dl_rcu);
18297 +       INIT_HLIST_NODE(&new->dl_hlist);
18298 +       spin_lock_init(&new->dl_lock);
18299 +       atomic_set(&new->dl_refcnt, 0);
18300 +       atomic_set(&new->dl_usecnt, 0);
18301 +
18302 +       /* rest of init goes here */
18303 +
18304 +       vxdprintk(VXD_CBIT(dlim, 4),
18305 +               "alloc_dl_info(%p,%d) = %p", sb, tag, new);
18306 +       return new;
18307 +}
18308 +
18309 +/*     __dealloc_dl_info()
18310 +
18311 +       * final disposal of dl_info                             */
18312 +
18313 +static void __dealloc_dl_info(struct dl_info *dli)
18314 +{
18315 +       vxdprintk(VXD_CBIT(dlim, 4),
18316 +               "dealloc_dl_info(%p)", dli);
18317 +
18318 +       dli->dl_hlist.next = LIST_POISON1;
18319 +       dli->dl_tag = -1;
18320 +       dli->dl_sb = 0;
18321 +
18322 +       BUG_ON(atomic_read(&dli->dl_usecnt));
18323 +       BUG_ON(atomic_read(&dli->dl_refcnt));
18324 +
18325 +       kfree(dli);
18326 +}
18327 +
18328 +
18329 +/*     hash table for dl_info hash */
18330 +
18331 +#define DL_HASH_SIZE   13
18332 +
18333 +struct hlist_head dl_info_hash[DL_HASH_SIZE];
18334 +
18335 +static DEFINE_SPINLOCK(dl_info_hash_lock);
18336 +
18337 +
18338 +static inline unsigned int __hashval(struct super_block *sb, tag_t tag)
18339 +{
18340 +       return ((tag ^ (unsigned long)sb) % DL_HASH_SIZE);
18341 +}
18342 +
18343 +
18344 +
18345 +/*     __hash_dl_info()
18346 +
18347 +       * add the dli to the global hash table
18348 +       * requires the hash_lock to be held                     */
18349 +
18350 +static inline void __hash_dl_info(struct dl_info *dli)
18351 +{
18352 +       struct hlist_head *head;
18353 +
18354 +       vxdprintk(VXD_CBIT(dlim, 6),
18355 +               "__hash_dl_info: %p[#%d]", dli, dli->dl_tag);
18356 +       get_dl_info(dli);
18357 +       head = &dl_info_hash[__hashval(dli->dl_sb, dli->dl_tag)];
18358 +       hlist_add_head_rcu(&dli->dl_hlist, head);
18359 +}
18360 +
18361 +/*     __unhash_dl_info()
18362 +
18363 +       * remove the dli from the global hash table
18364 +       * requires the hash_lock to be held                     */
18365 +
18366 +static inline void __unhash_dl_info(struct dl_info *dli)
18367 +{
18368 +       vxdprintk(VXD_CBIT(dlim, 6),
18369 +               "__unhash_dl_info: %p[#%d]", dli, dli->dl_tag);
18370 +       hlist_del_rcu(&dli->dl_hlist);
18371 +       put_dl_info(dli);
18372 +}
18373 +
18374 +
18375 +/*     __lookup_dl_info()
18376 +
18377 +       * requires the rcu_read_lock()
18378 +       * doesn't increment the dl_refcnt                       */
18379 +
18380 +static inline struct dl_info *__lookup_dl_info(struct super_block *sb, tag_t tag)
18381 +{
18382 +       struct hlist_head *head = &dl_info_hash[__hashval(sb, tag)];
18383 +       struct hlist_node *pos;
18384 +       struct dl_info *dli;
18385 +
18386 +       hlist_for_each_entry_rcu(dli, pos, head, dl_hlist) {
18387 +
18388 +               if (dli->dl_tag == tag && dli->dl_sb == sb) {
18389 +                       return dli;
18390 +               }
18391 +       }
18392 +       return NULL;
18393 +}
18394 +
18395 +
18396 +struct dl_info *locate_dl_info(struct super_block *sb, tag_t tag)
18397 +{
18398 +       struct dl_info *dli;
18399 +
18400 +       rcu_read_lock();
18401 +       dli = get_dl_info(__lookup_dl_info(sb, tag));
18402 +       vxdprintk(VXD_CBIT(dlim, 7),
18403 +               "locate_dl_info(%p,#%d) = %p", sb, tag, dli);
18404 +       rcu_read_unlock();
18405 +       return dli;
18406 +}
18407 +
18408 +void rcu_free_dl_info(struct rcu_head *head)
18409 +{
18410 +       struct dl_info *dli = container_of(head, struct dl_info, dl_rcu);
18411 +       int usecnt, refcnt;
18412 +
18413 +       BUG_ON(!dli || !head);
18414 +
18415 +       usecnt = atomic_read(&dli->dl_usecnt);
18416 +       BUG_ON(usecnt < 0);
18417 +
18418 +       refcnt = atomic_read(&dli->dl_refcnt);
18419 +       BUG_ON(refcnt < 0);
18420 +
18421 +       vxdprintk(VXD_CBIT(dlim, 3),
18422 +               "rcu_free_dl_info(%p)", dli);
18423 +       if (!usecnt)
18424 +               __dealloc_dl_info(dli);
18425 +       else
18426 +               printk("!!! rcu didn't free\n");
18427 +}
18428 +
18429 +
18430 +
18431 +
18432 +static int do_addrem_dlimit(uint32_t id, const char __user *name,
18433 +       uint32_t flags, int add)
18434 +{
18435 +       struct path path;
18436 +       int ret;
18437 +
18438 +       ret = user_lpath(name, &path);
18439 +       if (!ret) {
18440 +               struct super_block *sb;
18441 +               struct dl_info *dli;
18442 +
18443 +               ret = -EINVAL;
18444 +               if (!path.dentry->d_inode)
18445 +                       goto out_release;
18446 +               if (!(sb = path.dentry->d_inode->i_sb))
18447 +                       goto out_release;
18448 +
18449 +               if (add) {
18450 +                       dli = __alloc_dl_info(sb, id);
18451 +                       spin_lock(&dl_info_hash_lock);
18452 +
18453 +                       ret = -EEXIST;
18454 +                       if (__lookup_dl_info(sb, id))
18455 +                               goto out_unlock;
18456 +                       __hash_dl_info(dli);
18457 +                       dli = NULL;
18458 +               } else {
18459 +                       spin_lock(&dl_info_hash_lock);
18460 +                       dli = __lookup_dl_info(sb, id);
18461 +
18462 +                       ret = -ESRCH;
18463 +                       if (!dli)
18464 +                               goto out_unlock;
18465 +                       __unhash_dl_info(dli);
18466 +               }
18467 +               ret = 0;
18468 +       out_unlock:
18469 +               spin_unlock(&dl_info_hash_lock);
18470 +               if (add && dli)
18471 +                       __dealloc_dl_info(dli);
18472 +       out_release:
18473 +               path_put(&path);
18474 +       }
18475 +       return ret;
18476 +}
18477 +
18478 +int vc_add_dlimit(uint32_t id, void __user *data)
18479 +{
18480 +       struct vcmd_ctx_dlimit_base_v0 vc_data;
18481 +
18482 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18483 +               return -EFAULT;
18484 +
18485 +       return do_addrem_dlimit(id, vc_data.name, vc_data.flags, 1);
18486 +}
18487 +
18488 +int vc_rem_dlimit(uint32_t id, void __user *data)
18489 +{
18490 +       struct vcmd_ctx_dlimit_base_v0 vc_data;
18491 +
18492 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18493 +               return -EFAULT;
18494 +
18495 +       return do_addrem_dlimit(id, vc_data.name, vc_data.flags, 0);
18496 +}
18497 +
18498 +#ifdef CONFIG_COMPAT
18499 +
18500 +int vc_add_dlimit_x32(uint32_t id, void __user *data)
18501 +{
18502 +       struct vcmd_ctx_dlimit_base_v0_x32 vc_data;
18503 +
18504 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18505 +               return -EFAULT;
18506 +
18507 +       return do_addrem_dlimit(id,
18508 +               compat_ptr(vc_data.name_ptr), vc_data.flags, 1);
18509 +}
18510 +
18511 +int vc_rem_dlimit_x32(uint32_t id, void __user *data)
18512 +{
18513 +       struct vcmd_ctx_dlimit_base_v0_x32 vc_data;
18514 +
18515 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18516 +               return -EFAULT;
18517 +
18518 +       return do_addrem_dlimit(id,
18519 +               compat_ptr(vc_data.name_ptr), vc_data.flags, 0);
18520 +}
18521 +
18522 +#endif /* CONFIG_COMPAT */
18523 +
18524 +
18525 +static inline
18526 +int do_set_dlimit(uint32_t id, const char __user *name,
18527 +       uint32_t space_used, uint32_t space_total,
18528 +       uint32_t inodes_used, uint32_t inodes_total,
18529 +       uint32_t reserved, uint32_t flags)
18530 +{
18531 +       struct path path;
18532 +       int ret;
18533 +
18534 +       ret = user_lpath(name, &path);
18535 +       if (!ret) {
18536 +               struct super_block *sb;
18537 +               struct dl_info *dli;
18538 +
18539 +               ret = -EINVAL;
18540 +               if (!path.dentry->d_inode)
18541 +                       goto out_release;
18542 +               if (!(sb = path.dentry->d_inode->i_sb))
18543 +                       goto out_release;
18544 +
18545 +               /* sanity checks */
18546 +               if ((reserved != CDLIM_KEEP &&
18547 +                       reserved > 100) ||
18548 +                       (inodes_used != CDLIM_KEEP &&
18549 +                       inodes_used > inodes_total) ||
18550 +                       (space_used != CDLIM_KEEP &&
18551 +                       space_used > space_total))
18552 +                       goto out_release;
18553 +
18554 +               ret = -ESRCH;
18555 +               dli = locate_dl_info(sb, id);
18556 +               if (!dli)
18557 +                       goto out_release;
18558 +
18559 +               spin_lock(&dli->dl_lock);
18560 +
18561 +               if (inodes_used != CDLIM_KEEP)
18562 +                       dli->dl_inodes_used = inodes_used;
18563 +               if (inodes_total != CDLIM_KEEP)
18564 +                       dli->dl_inodes_total = inodes_total;
18565 +               if (space_used != CDLIM_KEEP)
18566 +                       dli->dl_space_used = dlimit_space_32to64(
18567 +                               space_used, flags, DLIMS_USED);
18568 +
18569 +               if (space_total == CDLIM_INFINITY)
18570 +                       dli->dl_space_total = DLIM_INFINITY;
18571 +               else if (space_total != CDLIM_KEEP)
18572 +                       dli->dl_space_total = dlimit_space_32to64(
18573 +                               space_total, flags, DLIMS_TOTAL);
18574 +
18575 +               if (reserved != CDLIM_KEEP)
18576 +                       dli->dl_nrlmult = (1 << 10) * (100 - reserved) / 100;
18577 +
18578 +               spin_unlock(&dli->dl_lock);
18579 +
18580 +               put_dl_info(dli);
18581 +               ret = 0;
18582 +
18583 +       out_release:
18584 +               path_put(&path);
18585 +       }
18586 +       return ret;
18587 +}
18588 +
18589 +int vc_set_dlimit(uint32_t id, void __user *data)
18590 +{
18591 +       struct vcmd_ctx_dlimit_v0 vc_data;
18592 +
18593 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18594 +               return -EFAULT;
18595 +
18596 +       return do_set_dlimit(id, vc_data.name,
18597 +               vc_data.space_used, vc_data.space_total,
18598 +               vc_data.inodes_used, vc_data.inodes_total,
18599 +               vc_data.reserved, vc_data.flags);
18600 +}
18601 +
18602 +#ifdef CONFIG_COMPAT
18603 +
18604 +int vc_set_dlimit_x32(uint32_t id, void __user *data)
18605 +{
18606 +       struct vcmd_ctx_dlimit_v0_x32 vc_data;
18607 +
18608 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18609 +               return -EFAULT;
18610 +
18611 +       return do_set_dlimit(id, compat_ptr(vc_data.name_ptr),
18612 +               vc_data.space_used, vc_data.space_total,
18613 +               vc_data.inodes_used, vc_data.inodes_total,
18614 +               vc_data.reserved, vc_data.flags);
18615 +}
18616 +
18617 +#endif /* CONFIG_COMPAT */
18618 +
18619 +
18620 +static inline
18621 +int do_get_dlimit(uint32_t id, const char __user *name,
18622 +       uint32_t *space_used, uint32_t *space_total,
18623 +       uint32_t *inodes_used, uint32_t *inodes_total,
18624 +       uint32_t *reserved, uint32_t *flags)
18625 +{
18626 +       struct path path;
18627 +       int ret;
18628 +
18629 +       ret = user_lpath(name, &path);
18630 +       if (!ret) {
18631 +               struct super_block *sb;
18632 +               struct dl_info *dli;
18633 +
18634 +               ret = -EINVAL;
18635 +               if (!path.dentry->d_inode)
18636 +                       goto out_release;
18637 +               if (!(sb = path.dentry->d_inode->i_sb))
18638 +                       goto out_release;
18639 +
18640 +               ret = -ESRCH;
18641 +               dli = locate_dl_info(sb, id);
18642 +               if (!dli)
18643 +                       goto out_release;
18644 +
18645 +               spin_lock(&dli->dl_lock);
18646 +               *inodes_used = dli->dl_inodes_used;
18647 +               *inodes_total = dli->dl_inodes_total;
18648 +
18649 +               *space_used = dlimit_space_64to32(
18650 +                       dli->dl_space_used, flags, DLIMS_USED);
18651 +
18652 +               if (dli->dl_space_total == DLIM_INFINITY)
18653 +                       *space_total = CDLIM_INFINITY;
18654 +               else
18655 +                       *space_total = dlimit_space_64to32(
18656 +                               dli->dl_space_total, flags, DLIMS_TOTAL);
18657 +
18658 +               *reserved = 100 - ((dli->dl_nrlmult * 100 + 512) >> 10);
18659 +               spin_unlock(&dli->dl_lock);
18660 +
18661 +               put_dl_info(dli);
18662 +               ret = -EFAULT;
18663 +
18664 +               ret = 0;
18665 +       out_release:
18666 +               path_put(&path);
18667 +       }
18668 +       return ret;
18669 +}
18670 +
18671 +
18672 +int vc_get_dlimit(uint32_t id, void __user *data)
18673 +{
18674 +       struct vcmd_ctx_dlimit_v0 vc_data;
18675 +       int ret;
18676 +
18677 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18678 +               return -EFAULT;
18679 +
18680 +       ret = do_get_dlimit(id, vc_data.name,
18681 +               &vc_data.space_used, &vc_data.space_total,
18682 +               &vc_data.inodes_used, &vc_data.inodes_total,
18683 +               &vc_data.reserved, &vc_data.flags);
18684 +       if (ret)
18685 +               return ret;
18686 +
18687 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18688 +               return -EFAULT;
18689 +       return 0;
18690 +}
18691 +
18692 +#ifdef CONFIG_COMPAT
18693 +
18694 +int vc_get_dlimit_x32(uint32_t id, void __user *data)
18695 +{
18696 +       struct vcmd_ctx_dlimit_v0_x32 vc_data;
18697 +       int ret;
18698 +
18699 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18700 +               return -EFAULT;
18701 +
18702 +       ret = do_get_dlimit(id, compat_ptr(vc_data.name_ptr),
18703 +               &vc_data.space_used, &vc_data.space_total,
18704 +               &vc_data.inodes_used, &vc_data.inodes_total,
18705 +               &vc_data.reserved, &vc_data.flags);
18706 +       if (ret)
18707 +               return ret;
18708 +
18709 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18710 +               return -EFAULT;
18711 +       return 0;
18712 +}
18713 +
18714 +#endif /* CONFIG_COMPAT */
18715 +
18716 +
18717 +void vx_vsi_statfs(struct super_block *sb, struct kstatfs *buf)
18718 +{
18719 +       struct dl_info *dli;
18720 +       __u64 blimit, bfree, bavail;
18721 +       __u32 ifree;
18722 +
18723 +       dli = locate_dl_info(sb, dx_current_tag());
18724 +       if (!dli)
18725 +               return;
18726 +
18727 +       spin_lock(&dli->dl_lock);
18728 +       if (dli->dl_inodes_total == (unsigned long)DLIM_INFINITY)
18729 +               goto no_ilim;
18730 +
18731 +       /* reduce max inodes available to limit */
18732 +       if (buf->f_files > dli->dl_inodes_total)
18733 +               buf->f_files = dli->dl_inodes_total;
18734 +
18735 +       ifree = dli->dl_inodes_total - dli->dl_inodes_used;
18736 +       /* reduce free inodes to min */
18737 +       if (ifree < buf->f_ffree)
18738 +               buf->f_ffree = ifree;
18739 +
18740 +no_ilim:
18741 +       if (dli->dl_space_total == DLIM_INFINITY)
18742 +               goto no_blim;
18743 +
18744 +       blimit = dli->dl_space_total >> sb->s_blocksize_bits;
18745 +
18746 +       if (dli->dl_space_total < dli->dl_space_used)
18747 +               bfree = 0;
18748 +       else
18749 +               bfree = (dli->dl_space_total - dli->dl_space_used)
18750 +                       >> sb->s_blocksize_bits;
18751 +
18752 +       bavail = ((dli->dl_space_total >> 10) * dli->dl_nrlmult);
18753 +       if (bavail < dli->dl_space_used)
18754 +               bavail = 0;
18755 +       else
18756 +               bavail = (bavail - dli->dl_space_used)
18757 +                       >> sb->s_blocksize_bits;
18758 +
18759 +       /* reduce max space available to limit */
18760 +       if (buf->f_blocks > blimit)
18761 +               buf->f_blocks = blimit;
18762 +
18763 +       /* reduce free space to min */
18764 +       if (bfree < buf->f_bfree)
18765 +               buf->f_bfree = bfree;
18766 +
18767 +       /* reduce avail space to min */
18768 +       if (bavail < buf->f_bavail)
18769 +               buf->f_bavail = bavail;
18770 +
18771 +no_blim:
18772 +       spin_unlock(&dli->dl_lock);
18773 +       put_dl_info(dli);
18774 +
18775 +       return;
18776 +}
18777 +
18778 +#include <linux/module.h>
18779 +
18780 +EXPORT_SYMBOL_GPL(locate_dl_info);
18781 +EXPORT_SYMBOL_GPL(rcu_free_dl_info);
18782 +
18783 diff -NurpP --minimal linux-3.0.25/kernel/vserver/helper.c linux-3.0.25-vs2.3.2.3/kernel/vserver/helper.c
18784 --- linux-3.0.25/kernel/vserver/helper.c        1970-01-01 01:00:00.000000000 +0100
18785 +++ linux-3.0.25-vs2.3.2.3/kernel/vserver/helper.c      2011-06-10 22:11:24.000000000 +0200
18786 @@ -0,0 +1,223 @@
18787 +/*
18788 + *  linux/kernel/vserver/helper.c
18789 + *
18790 + *  Virtual Context Support
18791 + *
18792 + *  Copyright (C) 2004-2007  Herbert Pötzl
18793 + *
18794 + *  V0.01  basic helper
18795 + *
18796 + */
18797 +
18798 +#include <linux/kmod.h>
18799 +#include <linux/reboot.h>
18800 +#include <linux/vs_context.h>
18801 +#include <linux/vs_network.h>
18802 +#include <linux/vserver/signal.h>
18803 +
18804 +
18805 +char vshelper_path[255] = "/sbin/vshelper";
18806 +
18807 +
18808 +static int do_vshelper(char *name, char *argv[], char *envp[], int sync)
18809 +{
18810 +       int ret;
18811 +
18812 +       if ((ret = call_usermodehelper(name, argv, envp, sync))) {
18813 +               printk( KERN_WARNING
18814 +                       "%s: (%s %s) returned %s with %d\n",
18815 +                       name, argv[1], argv[2],
18816 +                       sync ? "sync" : "async", ret);
18817 +       }
18818 +       vxdprintk(VXD_CBIT(switch, 4),
18819 +               "%s: (%s %s) returned %s with %d",
18820 +               name, argv[1], argv[2], sync ? "sync" : "async", ret);
18821 +       return ret;
18822 +}
18823 +
18824 +/*
18825 + *      vshelper path is set via /proc/sys
18826 + *      invoked by vserver sys_reboot(), with
18827 + *      the following arguments
18828 + *
18829 + *      argv [0] = vshelper_path;
18830 + *      argv [1] = action: "restart", "halt", "poweroff", ...
18831 + *      argv [2] = context identifier
18832 + *
18833 + *      envp [*] = type-specific parameters
18834 + */
18835 +
18836 +long vs_reboot_helper(struct vx_info *vxi, int cmd, void __user *arg)
18837 +{
18838 +       char id_buf[8], cmd_buf[16];
18839 +       char uid_buf[16], pid_buf[16];
18840 +       int ret;
18841 +
18842 +       char *argv[] = {vshelper_path, NULL, id_buf, 0};
18843 +       char *envp[] = {"HOME=/", "TERM=linux",
18844 +                       "PATH=/sbin:/usr/sbin:/bin:/usr/bin",
18845 +                       uid_buf, pid_buf, cmd_buf, 0};
18846 +
18847 +       if (vx_info_state(vxi, VXS_HELPER))
18848 +               return -EAGAIN;
18849 +       vxi->vx_state |= VXS_HELPER;
18850 +
18851 +       snprintf(id_buf, sizeof(id_buf)-1, "%d", vxi->vx_id);
18852 +
18853 +       snprintf(cmd_buf, sizeof(cmd_buf)-1, "VS_CMD=%08x", cmd);
18854 +       snprintf(uid_buf, sizeof(uid_buf)-1, "VS_UID=%d", current_uid());
18855 +       snprintf(pid_buf, sizeof(pid_buf)-1, "VS_PID=%d", current->pid);
18856 +
18857 +       switch (cmd) {
18858 +       case LINUX_REBOOT_CMD_RESTART:
18859 +               argv[1] = "restart";
18860 +               break;
18861 +
18862 +       case LINUX_REBOOT_CMD_HALT:
18863 +               argv[1] = "halt";
18864 +               break;
18865 +
18866 +       case LINUX_REBOOT_CMD_POWER_OFF:
18867 +               argv[1] = "poweroff";
18868 +               break;
18869 +
18870 +       case LINUX_REBOOT_CMD_SW_SUSPEND:
18871 +               argv[1] = "swsusp";
18872 +               break;
18873 +
18874 +       case LINUX_REBOOT_CMD_OOM:
18875 +               argv[1] = "oom";
18876 +               break;
18877 +
18878 +       default:
18879 +               vxi->vx_state &= ~VXS_HELPER;
18880 +               return 0;
18881 +       }
18882 +
18883 +       ret = do_vshelper(vshelper_path, argv, envp, 0);
18884 +       vxi->vx_state &= ~VXS_HELPER;
18885 +       __wakeup_vx_info(vxi);
18886 +       return (ret) ? -EPERM : 0;
18887 +}
18888 +
18889 +
18890 +long vs_reboot(unsigned int cmd, void __user *arg)
18891 +{
18892 +       struct vx_info *vxi = current_vx_info();
18893 +       long ret = 0;
18894 +
18895 +       vxdprintk(VXD_CBIT(misc, 5),
18896 +               "vs_reboot(%p[#%d],%u)",
18897 +               vxi, vxi ? vxi->vx_id : 0, cmd);
18898 +
18899 +       ret = vs_reboot_helper(vxi, cmd, arg);
18900 +       if (ret)
18901 +               return ret;
18902 +
18903 +       vxi->reboot_cmd = cmd;
18904 +       if (vx_info_flags(vxi, VXF_REBOOT_KILL, 0)) {
18905 +               switch (cmd) {
18906 +               case LINUX_REBOOT_CMD_RESTART:
18907 +               case LINUX_REBOOT_CMD_HALT:
18908 +               case LINUX_REBOOT_CMD_POWER_OFF:
18909 +                       vx_info_kill(vxi, 0, SIGKILL);
18910 +                       vx_info_kill(vxi, 1, SIGKILL);
18911 +               default:
18912 +                       break;
18913 +               }
18914 +       }
18915 +       return 0;
18916 +}
18917 +
18918 +long vs_oom_action(unsigned int cmd)
18919 +{
18920 +       struct vx_info *vxi = current_vx_info();
18921 +       long ret = 0;
18922 +
18923 +       vxdprintk(VXD_CBIT(misc, 5),
18924 +               "vs_oom_action(%p[#%d],%u)",
18925 +               vxi, vxi ? vxi->vx_id : 0, cmd);
18926 +
18927 +       ret = vs_reboot_helper(vxi, cmd, NULL);
18928 +       if (ret)
18929 +               return ret;
18930 +
18931 +       vxi->reboot_cmd = cmd;
18932 +       if (vx_info_flags(vxi, VXF_REBOOT_KILL, 0)) {
18933 +               vx_info_kill(vxi, 0, SIGKILL);
18934 +               vx_info_kill(vxi, 1, SIGKILL);
18935 +       }
18936 +       return 0;
18937 +}
18938 +
18939 +/*
18940 + *      argv [0] = vshelper_path;
18941 + *      argv [1] = action: "startup", "shutdown"
18942 + *      argv [2] = context identifier
18943 + *
18944 + *      envp [*] = type-specific parameters
18945 + */
18946 +
18947 +long vs_state_change(struct vx_info *vxi, unsigned int cmd)
18948 +{
18949 +       char id_buf[8], cmd_buf[16];
18950 +       char *argv[] = {vshelper_path, NULL, id_buf, 0};
18951 +       char *envp[] = {"HOME=/", "TERM=linux",
18952 +                       "PATH=/sbin:/usr/sbin:/bin:/usr/bin", cmd_buf, 0};
18953 +
18954 +       if (!vx_info_flags(vxi, VXF_SC_HELPER, 0))
18955 +               return 0;
18956 +
18957 +       snprintf(id_buf, sizeof(id_buf)-1, "%d", vxi->vx_id);
18958 +       snprintf(cmd_buf, sizeof(cmd_buf)-1, "VS_CMD=%08x", cmd);
18959 +
18960 +       switch (cmd) {
18961 +       case VSC_STARTUP:
18962 +               argv[1] = "startup";
18963 +               break;
18964 +       case VSC_SHUTDOWN:
18965 +               argv[1] = "shutdown";
18966 +               break;
18967 +       default:
18968 +               return 0;
18969 +       }
18970 +
18971 +       return do_vshelper(vshelper_path, argv, envp, 1);
18972 +}
18973 +
18974 +
18975 +/*
18976 + *      argv [0] = vshelper_path;
18977 + *      argv [1] = action: "netup", "netdown"
18978 + *      argv [2] = context identifier
18979 + *
18980 + *      envp [*] = type-specific parameters
18981 + */
18982 +
18983 +long vs_net_change(struct nx_info *nxi, unsigned int cmd)
18984 +{
18985 +       char id_buf[8], cmd_buf[16];
18986 +       char *argv[] = {vshelper_path, NULL, id_buf, 0};
18987 +       char *envp[] = {"HOME=/", "TERM=linux",
18988 +                       "PATH=/sbin:/usr/sbin:/bin:/usr/bin", cmd_buf, 0};
18989 +
18990 +       if (!nx_info_flags(nxi, NXF_SC_HELPER, 0))
18991 +               return 0;
18992 +
18993 +       snprintf(id_buf, sizeof(id_buf)-1, "%d", nxi->nx_id);
18994 +       snprintf(cmd_buf, sizeof(cmd_buf)-1, "VS_CMD=%08x", cmd);
18995 +
18996 +       switch (cmd) {
18997 +       case VSC_NETUP:
18998 +               argv[1] = "netup";
18999 +               break;
19000 +       case VSC_NETDOWN:
19001 +               argv[1] = "netdown";
19002 +               break;
19003 +       default:
19004 +               return 0;
19005 +       }
19006 +
19007 +       return do_vshelper(vshelper_path, argv, envp, 1);
19008 +}
19009 +
19010 diff -NurpP --minimal linux-3.0.25/kernel/vserver/history.c linux-3.0.25-vs2.3.2.3/kernel/vserver/history.c
19011 --- linux-3.0.25/kernel/vserver/history.c       1970-01-01 01:00:00.000000000 +0100
19012 +++ linux-3.0.25-vs2.3.2.3/kernel/vserver/history.c     2011-06-10 22:11:24.000000000 +0200
19013 @@ -0,0 +1,258 @@
19014 +/*
19015 + *  kernel/vserver/history.c
19016 + *
19017 + *  Virtual Context History Backtrace
19018 + *
19019 + *  Copyright (C) 2004-2007  Herbert Pötzl
19020 + *
19021 + *  V0.01  basic structure
19022 + *  V0.02  hash/unhash and trace
19023 + *  V0.03  preemption fixes
19024 + *
19025 + */
19026 +
19027 +#include <linux/module.h>
19028 +#include <asm/uaccess.h>
19029 +
19030 +#include <linux/vserver/context.h>
19031 +#include <linux/vserver/debug.h>
19032 +#include <linux/vserver/debug_cmd.h>
19033 +#include <linux/vserver/history.h>
19034 +
19035 +
19036 +#ifdef CONFIG_VSERVER_HISTORY
19037 +#define VXH_SIZE       CONFIG_VSERVER_HISTORY_SIZE
19038 +#else
19039 +#define VXH_SIZE       64
19040 +#endif
19041 +
19042 +struct _vx_history {
19043 +       unsigned int counter;
19044 +
19045 +       struct _vx_hist_entry entry[VXH_SIZE + 1];
19046 +};
19047 +
19048 +
19049 +DEFINE_PER_CPU(struct _vx_history, vx_history_buffer);
19050 +
19051 +unsigned volatile int vxh_active = 1;
19052 +
19053 +static atomic_t sequence = ATOMIC_INIT(0);
19054 +
19055 +
19056 +/*     vxh_advance()
19057 +
19058 +       * requires disabled preemption                          */
19059 +
19060 +struct _vx_hist_entry *vxh_advance(void *loc)
19061 +{
19062 +       unsigned int cpu = smp_processor_id();
19063 +       struct _vx_history *hist = &per_cpu(vx_history_buffer, cpu);
19064 +       struct _vx_hist_entry *entry;
19065 +       unsigned int index;
19066 +
19067 +       index = vxh_active ? (hist->counter++ % VXH_SIZE) : VXH_SIZE;
19068 +       entry = &hist->entry[index];
19069 +
19070 +       entry->seq = atomic_inc_return(&sequence);
19071 +       entry->loc = loc;
19072 +       return entry;
19073 +}
19074 +
19075 +EXPORT_SYMBOL_GPL(vxh_advance);
19076 +
19077 +
19078 +#define VXH_LOC_FMTS   "(#%04x,*%d):%p"
19079 +
19080 +#define VXH_LOC_ARGS(e)        (e)->seq, cpu, (e)->loc
19081 +
19082 +
19083 +#define VXH_VXI_FMTS   "%p[#%d,%d.%d]"
19084 +
19085 +#define VXH_VXI_ARGS(e)        (e)->vxi.ptr,                           \
19086 +                       (e)->vxi.ptr ? (e)->vxi.xid : 0,        \
19087 +                       (e)->vxi.ptr ? (e)->vxi.usecnt : 0,     \
19088 +                       (e)->vxi.ptr ? (e)->vxi.tasks : 0
19089 +
19090 +void   vxh_dump_entry(struct _vx_hist_entry *e, unsigned cpu)
19091 +{
19092 +       switch (e->type) {
19093 +       case VXH_THROW_OOPS:
19094 +               printk( VXH_LOC_FMTS " oops \n", VXH_LOC_ARGS(e));
19095 +               break;
19096 +
19097 +       case VXH_GET_VX_INFO:
19098 +       case VXH_PUT_VX_INFO:
19099 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS "\n",
19100 +                       VXH_LOC_ARGS(e),
19101 +                       (e->type == VXH_GET_VX_INFO) ? "get" : "put",
19102 +                       VXH_VXI_ARGS(e));
19103 +               break;
19104 +
19105 +       case VXH_INIT_VX_INFO:
19106 +       case VXH_SET_VX_INFO:
19107 +       case VXH_CLR_VX_INFO:
19108 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS " @%p\n",
19109 +                       VXH_LOC_ARGS(e),
19110 +                       (e->type == VXH_INIT_VX_INFO) ? "init" :
19111 +                       ((e->type == VXH_SET_VX_INFO) ? "set" : "clr"),
19112 +                       VXH_VXI_ARGS(e), e->sc.data);
19113 +               break;
19114 +
19115 +       case VXH_CLAIM_VX_INFO:
19116 +       case VXH_RELEASE_VX_INFO:
19117 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS " @%p\n",
19118 +                       VXH_LOC_ARGS(e),
19119 +                       (e->type == VXH_CLAIM_VX_INFO) ? "claim" : "release",
19120 +                       VXH_VXI_ARGS(e), e->sc.data);
19121 +               break;
19122 +
19123 +       case VXH_ALLOC_VX_INFO:
19124 +       case VXH_DEALLOC_VX_INFO:
19125 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS "\n",
19126 +                       VXH_LOC_ARGS(e),
19127 +                       (e->type == VXH_ALLOC_VX_INFO) ? "alloc" : "dealloc",
19128 +                       VXH_VXI_ARGS(e));
19129 +               break;
19130 +
19131 +       case VXH_HASH_VX_INFO:
19132 +       case VXH_UNHASH_VX_INFO:
19133 +               printk( VXH_LOC_FMTS " __%s_vx_info " VXH_VXI_FMTS "\n",
19134 +                       VXH_LOC_ARGS(e),
19135 +                       (e->type == VXH_HASH_VX_INFO) ? "hash" : "unhash",
19136 +                       VXH_VXI_ARGS(e));
19137 +               break;
19138 +
19139 +       case VXH_LOC_VX_INFO:
19140 +       case VXH_LOOKUP_VX_INFO:
19141 +       case VXH_CREATE_VX_INFO:
19142 +               printk( VXH_LOC_FMTS " __%s_vx_info [#%d] -> " VXH_VXI_FMTS "\n",
19143 +                       VXH_LOC_ARGS(e),
19144 +                       (e->type == VXH_CREATE_VX_INFO) ? "create" :
19145 +                       ((e->type == VXH_LOC_VX_INFO) ? "loc" : "lookup"),
19146 +                       e->ll.arg, VXH_VXI_ARGS(e));
19147 +               break;
19148 +       }
19149 +}
19150 +
19151 +static void __vxh_dump_history(void)
19152 +{
19153 +       unsigned int i, cpu;
19154 +
19155 +       printk("History:\tSEQ: %8x\tNR_CPUS: %d\n",
19156 +               atomic_read(&sequence), NR_CPUS);
19157 +
19158 +       for (i = 0; i < VXH_SIZE; i++) {
19159 +               for_each_online_cpu(cpu) {
19160 +                       struct _vx_history *hist =
19161 +                               &per_cpu(vx_history_buffer, cpu);
19162 +                       unsigned int index = (hist->counter - i) % VXH_SIZE;
19163 +                       struct _vx_hist_entry *entry = &hist->entry[index];
19164 +
19165 +                       vxh_dump_entry(entry, cpu);
19166 +               }
19167 +       }
19168 +}
19169 +
19170 +void   vxh_dump_history(void)
19171 +{
19172 +       vxh_active = 0;
19173 +#ifdef CONFIG_SMP
19174 +       local_irq_enable();
19175 +       smp_send_stop();
19176 +       local_irq_disable();
19177 +#endif
19178 +       __vxh_dump_history();
19179 +}
19180 +
19181 +
19182 +/* vserver syscall commands below here */
19183 +
19184 +
19185 +int vc_dump_history(uint32_t id)
19186 +{
19187 +       vxh_active = 0;
19188 +       __vxh_dump_history();
19189 +       vxh_active = 1;
19190 +
19191 +       return 0;
19192 +}
19193 +
19194 +
19195 +int do_read_history(struct __user _vx_hist_entry *data,
19196 +       int cpu, uint32_t *index, uint32_t *count)
19197 +{
19198 +       int pos, ret = 0;
19199 +       struct _vx_history *hist = &per_cpu(vx_history_buffer, cpu);
19200 +       int end = hist->counter;
19201 +       int start = end - VXH_SIZE + 2;
19202 +       int idx = *index;
19203 +
19204 +       /* special case: get current pos */
19205 +       if (!*count) {
19206 +               *index = end;
19207 +               return 0;
19208 +       }
19209 +
19210 +       /* have we lost some data? */
19211 +       if (idx < start)
19212 +               idx = start;
19213 +
19214 +       for (pos = 0; (pos < *count) && (idx < end); pos++, idx++) {
19215 +               struct _vx_hist_entry *entry =
19216 +                       &hist->entry[idx % VXH_SIZE];
19217 +
19218 +               /* send entry to userspace */
19219 +               ret = copy_to_user(&data[pos], entry, sizeof(*entry));
19220 +               if (ret)
19221 +                       break;
19222 +       }
19223 +       /* save new index and count */
19224 +       *index = idx;
19225 +       *count = pos;
19226 +       return ret ? ret : (*index < end);
19227 +}
19228 +
19229 +int vc_read_history(uint32_t id, void __user *data)
19230 +{
19231 +       struct vcmd_read_history_v0 vc_data;
19232 +       int ret;
19233 +
19234 +       if (id >= NR_CPUS)
19235 +               return -EINVAL;
19236 +
19237 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19238 +               return -EFAULT;
19239 +
19240 +       ret = do_read_history((struct __user _vx_hist_entry *)vc_data.data,
19241 +               id, &vc_data.index, &vc_data.count);
19242 +
19243 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19244 +               return -EFAULT;
19245 +       return ret;
19246 +}
19247 +
19248 +#ifdef CONFIG_COMPAT
19249 +
19250 +int vc_read_history_x32(uint32_t id, void __user *data)
19251 +{
19252 +       struct vcmd_read_history_v0_x32 vc_data;
19253 +       int ret;
19254 +
19255 +       if (id >= NR_CPUS)
19256 +               return -EINVAL;
19257 +
19258 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19259 +               return -EFAULT;
19260 +
19261 +       ret = do_read_history((struct __user _vx_hist_entry *)
19262 +               compat_ptr(vc_data.data_ptr),
19263 +               id, &vc_data.index, &vc_data.count);
19264 +
19265 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19266 +               return -EFAULT;
19267 +       return ret;
19268 +}
19269 +
19270 +#endif /* CONFIG_COMPAT */
19271 +
19272 diff -NurpP --minimal linux-3.0.25/kernel/vserver/inet.c linux-3.0.25-vs2.3.2.3/kernel/vserver/inet.c
19273 --- linux-3.0.25/kernel/vserver/inet.c  1970-01-01 01:00:00.000000000 +0100
19274 +++ linux-3.0.25-vs2.3.2.3/kernel/vserver/inet.c        2011-08-30 20:14:33.000000000 +0200
19275 @@ -0,0 +1,225 @@
19276 +
19277 +#include <linux/in.h>
19278 +#include <linux/inetdevice.h>
19279 +#include <linux/vs_inet.h>
19280 +#include <linux/vs_inet6.h>
19281 +#include <linux/vserver/debug.h>
19282 +#include <net/route.h>
19283 +#include <net/addrconf.h>
19284 +
19285 +
19286 +int nx_v4_addr_conflict(struct nx_info *nxi1, struct nx_info *nxi2)
19287 +{
19288 +       int ret = 0;
19289 +
19290 +       if (!nxi1 || !nxi2 || nxi1 == nxi2)
19291 +               ret = 1;
19292 +       else {
19293 +               struct nx_addr_v4 *ptr;
19294 +
19295 +               for (ptr = &nxi1->v4; ptr; ptr = ptr->next) {
19296 +                       if (v4_nx_addr_in_nx_info(nxi2, ptr, -1)) {
19297 +                               ret = 1;
19298 +                               break;
19299 +                       }
19300 +               }
19301 +       }
19302 +
19303 +       vxdprintk(VXD_CBIT(net, 2),
19304 +               "nx_v4_addr_conflict(%p,%p): %d",
19305 +               nxi1, nxi2, ret);
19306 +
19307 +       return ret;
19308 +}
19309 +
19310 +
19311 +#ifdef CONFIG_IPV6
19312 +
19313 +int nx_v6_addr_conflict(struct nx_info *nxi1, struct nx_info *nxi2)
19314 +{
19315 +       int ret = 0;
19316 +
19317 +       if (!nxi1 || !nxi2 || nxi1 == nxi2)
19318 +               ret = 1;
19319 +       else {
19320 +               struct nx_addr_v6 *ptr;
19321 +
19322 +               for (ptr = &nxi1->v6; ptr; ptr = ptr->next) {
19323 +                       if (v6_nx_addr_in_nx_info(nxi2, ptr, -1)) {
19324 +                               ret = 1;
19325 +                               break;
19326 +                       }
19327 +               }
19328 +       }
19329 +
19330 +       vxdprintk(VXD_CBIT(net, 2),
19331 +               "nx_v6_addr_conflict(%p,%p): %d",
19332 +               nxi1, nxi2, ret);
19333 +
19334 +       return ret;
19335 +}
19336 +
19337 +#endif
19338 +
19339 +int v4_dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
19340 +{
19341 +       struct in_device *in_dev;
19342 +       struct in_ifaddr **ifap;
19343 +       struct in_ifaddr *ifa;
19344 +       int ret = 0;
19345 +
19346 +       if (!dev)
19347 +               goto out;
19348 +       in_dev = in_dev_get(dev);
19349 +       if (!in_dev)
19350 +               goto out;
19351 +
19352 +       for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
19353 +               ifap = &ifa->ifa_next) {
19354 +               if (v4_addr_in_nx_info(nxi, ifa->ifa_local, NXA_MASK_SHOW)) {
19355 +                       ret = 1;
19356 +                       break;
19357 +               }
19358 +       }
19359 +       in_dev_put(in_dev);
19360 +out:
19361 +       return ret;
19362 +}
19363 +
19364 +
19365 +#ifdef CONFIG_IPV6
19366 +
19367 +int v6_dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
19368 +{
19369 +       struct inet6_dev *in_dev;
19370 +       struct inet6_ifaddr *ifa;
19371 +       int ret = 0;
19372 +
19373 +       if (!dev)
19374 +               goto out;
19375 +       in_dev = in6_dev_get(dev);
19376 +       if (!in_dev)
19377 +               goto out;
19378 +
19379 +       // for (ifap = &in_dev->addr_list; (ifa = *ifap) != NULL;
19380 +       list_for_each_entry(ifa, &in_dev->addr_list, if_list) {
19381 +               if (v6_addr_in_nx_info(nxi, &ifa->addr, -1)) {
19382 +                       ret = 1;
19383 +                       break;
19384 +               }
19385 +       }
19386 +       in6_dev_put(in_dev);
19387 +out:
19388 +       return ret;
19389 +}
19390 +
19391 +#endif
19392 +
19393 +int dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
19394 +{
19395 +       int ret = 1;
19396 +
19397 +       if (!nxi)
19398 +               goto out;
19399 +       if (nxi->v4.type && v4_dev_in_nx_info(dev, nxi))
19400 +               goto out;
19401 +#ifdef CONFIG_IPV6
19402 +       ret = 2;
19403 +       if (nxi->v6.type && v6_dev_in_nx_info(dev, nxi))
19404 +               goto out;
19405 +#endif
19406 +       ret = 0;
19407 +out:
19408 +       vxdprintk(VXD_CBIT(net, 3),
19409 +               "dev_in_nx_info(%p,%p[#%d]) = %d",
19410 +               dev, nxi, nxi ? nxi->nx_id : 0, ret);
19411 +       return ret;
19412 +}
19413 +
19414 +struct rtable *ip_v4_find_src(struct net *net, struct nx_info *nxi,
19415 +       struct flowi4 *fl4)
19416 +{
19417 +       struct rtable *rt;
19418 +
19419 +       if (!nxi)
19420 +               return NULL;
19421 +
19422 +       /* FIXME: handle lback only case */
19423 +       if (!NX_IPV4(nxi))
19424 +               return ERR_PTR(-EPERM);
19425 +
19426 +       vxdprintk(VXD_CBIT(net, 4),
19427 +               "ip_v4_find_src(%p[#%u]) " NIPQUAD_FMT " -> " NIPQUAD_FMT,
19428 +               nxi, nxi ? nxi->nx_id : 0,
19429 +               NIPQUAD(fl4->saddr), NIPQUAD(fl4->daddr));
19430 +
19431 +       /* single IP is unconditional */
19432 +       if (nx_info_flags(nxi, NXF_SINGLE_IP, 0) &&
19433 +               (fl4->saddr == INADDR_ANY))
19434 +               fl4->saddr = nxi->v4.ip[0].s_addr;
19435 +
19436 +       if (fl4->saddr == INADDR_ANY) {
19437 +               struct nx_addr_v4 *ptr;
19438 +               __be32 found = 0;
19439 +
19440 +               rt = __ip_route_output_key(net, fl4);
19441 +               if (!IS_ERR(rt)) {
19442 +                       found = fl4->saddr;
19443 +                       ip_rt_put(rt);
19444 +                       vxdprintk(VXD_CBIT(net, 4),
19445 +                               "ip_v4_find_src(%p[#%u]) rok[%u]: " NIPQUAD_FMT,
19446 +                               nxi, nxi ? nxi->nx_id : 0, fl4->flowi4_oif, NIPQUAD(found));
19447 +                       if (v4_addr_in_nx_info(nxi, found, NXA_MASK_BIND))
19448 +                               goto found;
19449 +               }
19450 +
19451 +               for (ptr = &nxi->v4; ptr; ptr = ptr->next) {
19452 +                       __be32 primary = ptr->ip[0].s_addr;
19453 +                       __be32 mask = ptr->mask.s_addr;
19454 +                       __be32 neta = primary & mask;
19455 +
19456 +                       vxdprintk(VXD_CBIT(net, 4), "ip_v4_find_src(%p[#%u]) chk: "
19457 +                               NIPQUAD_FMT "/" NIPQUAD_FMT "/" NIPQUAD_FMT,
19458 +                               nxi, nxi ? nxi->nx_id : 0, NIPQUAD(primary),
19459 +                               NIPQUAD(mask), NIPQUAD(neta));
19460 +                       if ((found & mask) != neta)
19461 +                               continue;
19462 +
19463 +                       fl4->saddr = primary;
19464 +                       rt = __ip_route_output_key(net, fl4);
19465 +                       vxdprintk(VXD_CBIT(net, 4),
19466 +                               "ip_v4_find_src(%p[#%u]) rok[%u]: " NIPQUAD_FMT,
19467 +                               nxi, nxi ? nxi->nx_id : 0, fl4->flowi4_oif, NIPQUAD(primary));
19468 +                       if (!IS_ERR(rt)) {
19469 +                               found = fl4->saddr;
19470 +                               ip_rt_put(rt);
19471 +                               if (found == primary)
19472 +                                       goto found;
19473 +                       }
19474 +               }
19475 +               /* still no source ip? */
19476 +               found = ipv4_is_loopback(fl4->daddr)
19477 +                       ? IPI_LOOPBACK : nxi->v4.ip[0].s_addr;
19478 +       found:
19479 +               /* assign src ip to flow */
19480 +               fl4->saddr = found;
19481 +
19482 +       } else {
19483 +               if (!v4_addr_in_nx_info(nxi, fl4->saddr, NXA_MASK_BIND))
19484 +                       return ERR_PTR(-EPERM);
19485 +       }
19486 +
19487 +       if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0)) {
19488 +               if (ipv4_is_loopback(fl4->daddr))
19489 +                       fl4->daddr = nxi->v4_lback.s_addr;
19490 +               if (ipv4_is_loopback(fl4->saddr))
19491 +                       fl4->saddr = nxi->v4_lback.s_addr;
19492 +       } else if (ipv4_is_loopback(fl4->daddr) &&
19493 +               !nx_info_flags(nxi, NXF_LBACK_ALLOW, 0))
19494 +               return ERR_PTR(-EPERM);
19495 +
19496 +       return NULL;
19497 +}
19498 +
19499 +EXPORT_SYMBOL_GPL(ip_v4_find_src);
19500 +
19501 diff -NurpP --minimal linux-3.0.25/kernel/vserver/init.c linux-3.0.25-vs2.3.2.3/kernel/vserver/init.c
19502 --- linux-3.0.25/kernel/vserver/init.c  1970-01-01 01:00:00.000000000 +0100
19503 +++ linux-3.0.25-vs2.3.2.3/kernel/vserver/init.c        2011-06-10 22:11:24.000000000 +0200
19504 @@ -0,0 +1,45 @@
19505 +/*
19506 + *  linux/kernel/init.c
19507 + *
19508 + *  Virtual Server Init
19509 + *
19510 + *  Copyright (C) 2004-2007  Herbert Pötzl
19511 + *
19512 + *  V0.01  basic structure
19513 + *
19514 + */
19515 +
19516 +#include <linux/init.h>
19517 +
19518 +int    vserver_register_sysctl(void);
19519 +void   vserver_unregister_sysctl(void);
19520 +
19521 +
19522 +static int __init init_vserver(void)
19523 +{
19524 +       int ret = 0;
19525 +
19526 +#ifdef CONFIG_VSERVER_DEBUG
19527 +       vserver_register_sysctl();
19528 +#endif
19529 +       return ret;
19530 +}
19531 +
19532 +
19533 +static void __exit exit_vserver(void)
19534 +{
19535 +
19536 +#ifdef CONFIG_VSERVER_DEBUG
19537 +       vserver_unregister_sysctl();
19538 +#endif
19539 +       return;
19540 +}
19541 +
19542 +/* FIXME: GFP_ZONETYPES gone
19543 +long vx_slab[GFP_ZONETYPES]; */
19544 +long vx_area;
19545 +
19546 +
19547 +module_init(init_vserver);
19548 +module_exit(exit_vserver);
19549 +
19550 diff -NurpP --minimal linux-3.0.25/kernel/vserver/inode.c linux-3.0.25-vs2.3.2.3/kernel/vserver/inode.c
19551 --- linux-3.0.25/kernel/vserver/inode.c 1970-01-01 01:00:00.000000000 +0100
19552 +++ linux-3.0.25-vs2.3.2.3/kernel/vserver/inode.c       2012-01-24 01:46:36.000000000 +0100
19553 @@ -0,0 +1,437 @@
19554 +/*
19555 + *  linux/kernel/vserver/inode.c
19556 + *
19557 + *  Virtual Server: File System Support
19558 + *
19559 + *  Copyright (C) 2004-2007  Herbert Pötzl
19560 + *
19561 + *  V0.01  separated from vcontext V0.05
19562 + *  V0.02  moved to tag (instead of xid)
19563 + *
19564 + */
19565 +
19566 +#include <linux/tty.h>
19567 +#include <linux/proc_fs.h>
19568 +#include <linux/devpts_fs.h>
19569 +#include <linux/fs.h>
19570 +#include <linux/file.h>
19571 +#include <linux/mount.h>
19572 +#include <linux/parser.h>
19573 +#include <linux/namei.h>
19574 +#include <linux/vserver/inode.h>
19575 +#include <linux/vserver/inode_cmd.h>
19576 +#include <linux/vs_base.h>
19577 +#include <linux/vs_tag.h>
19578 +
19579 +#include <asm/uaccess.h>
19580 +
19581 +
19582 +static int __vc_get_iattr(struct inode *in, uint32_t *tag, uint32_t *flags, uint32_t *mask)
19583 +{
19584 +       struct proc_dir_entry *entry;
19585 +
19586 +       if (!in || !in->i_sb)
19587 +               return -ESRCH;
19588 +
19589 +       *flags = IATTR_TAG
19590 +               | (IS_IMMUTABLE(in) ? IATTR_IMMUTABLE : 0)
19591 +               | (IS_IXUNLINK(in) ? IATTR_IXUNLINK : 0)
19592 +               | (IS_BARRIER(in) ? IATTR_BARRIER : 0)
19593 +               | (IS_COW(in) ? IATTR_COW : 0);
19594 +       *mask = IATTR_IXUNLINK | IATTR_IMMUTABLE | IATTR_COW;
19595 +
19596 +       if (S_ISDIR(in->i_mode))
19597 +               *mask |= IATTR_BARRIER;
19598 +
19599 +       if (IS_TAGGED(in)) {
19600 +               *tag = in->i_tag;
19601 +               *mask |= IATTR_TAG;
19602 +       }
19603 +
19604 +       switch (in->i_sb->s_magic) {
19605 +       case PROC_SUPER_MAGIC:
19606 +               entry = PROC_I(in)->pde;
19607 +
19608 +               /* check for specific inodes? */
19609 +               if (entry)
19610 +                       *mask |= IATTR_FLAGS;
19611 +               if (entry)
19612 +                       *flags |= (entry->vx_flags & IATTR_FLAGS);
19613 +               else
19614 +                       *flags |= (PROC_I(in)->vx_flags & IATTR_FLAGS);
19615 +               break;
19616 +
19617 +       case DEVPTS_SUPER_MAGIC:
19618 +               *tag = in->i_tag;
19619 +               *mask |= IATTR_TAG;
19620 +               break;
19621 +
19622 +       default:
19623 +               break;
19624 +       }
19625 +       return 0;
19626 +}
19627 +
19628 +int vc_get_iattr(void __user *data)
19629 +{
19630 +       struct path path;
19631 +       struct vcmd_ctx_iattr_v1 vc_data = { .tag = -1 };
19632 +       int ret;
19633 +
19634 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19635 +               return -EFAULT;
19636 +
19637 +       ret = user_lpath(vc_data.name, &path);
19638 +       if (!ret) {
19639 +               ret = __vc_get_iattr(path.dentry->d_inode,
19640 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
19641 +               path_put(&path);
19642 +       }
19643 +       if (ret)
19644 +               return ret;
19645 +
19646 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19647 +               ret = -EFAULT;
19648 +       return ret;
19649 +}
19650 +
19651 +#ifdef CONFIG_COMPAT
19652 +
19653 +int vc_get_iattr_x32(void __user *data)
19654 +{
19655 +       struct path path;
19656 +       struct vcmd_ctx_iattr_v1_x32 vc_data = { .tag = -1 };
19657 +       int ret;
19658 +
19659 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19660 +               return -EFAULT;
19661 +
19662 +       ret = user_lpath(compat_ptr(vc_data.name_ptr), &path);
19663 +       if (!ret) {
19664 +               ret = __vc_get_iattr(path.dentry->d_inode,
19665 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
19666 +               path_put(&path);
19667 +       }
19668 +       if (ret)
19669 +               return ret;
19670 +
19671 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19672 +               ret = -EFAULT;
19673 +       return ret;
19674 +}
19675 +
19676 +#endif /* CONFIG_COMPAT */
19677 +
19678 +
19679 +int vc_fget_iattr(uint32_t fd, void __user *data)
19680 +{
19681 +       struct file *filp;
19682 +       struct vcmd_ctx_fiattr_v0 vc_data = { .tag = -1 };
19683 +       int ret;
19684 +
19685 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19686 +               return -EFAULT;
19687 +
19688 +       filp = fget(fd);
19689 +       if (!filp || !filp->f_dentry || !filp->f_dentry->d_inode)
19690 +               return -EBADF;
19691 +
19692 +       ret = __vc_get_iattr(filp->f_dentry->d_inode,
19693 +               &vc_data.tag, &vc_data.flags, &vc_data.mask);
19694 +
19695 +       fput(filp);
19696 +
19697 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19698 +               ret = -EFAULT;
19699 +       return ret;
19700 +}
19701 +
19702 +
19703 +static int __vc_set_iattr(struct dentry *de, uint32_t *tag, uint32_t *flags, uint32_t *mask)
19704 +{
19705 +       struct inode *in = de->d_inode;
19706 +       int error = 0, is_proc = 0, has_tag = 0;
19707 +       struct iattr attr = { 0 };
19708 +
19709 +       if (!in || !in->i_sb)
19710 +               return -ESRCH;
19711 +
19712 +       is_proc = (in->i_sb->s_magic == PROC_SUPER_MAGIC);
19713 +       if ((*mask & IATTR_FLAGS) && !is_proc)
19714 +               return -EINVAL;
19715 +
19716 +       has_tag = IS_TAGGED(in) ||
19717 +               (in->i_sb->s_magic == DEVPTS_SUPER_MAGIC);
19718 +       if ((*mask & IATTR_TAG) && !has_tag)
19719 +               return -EINVAL;
19720 +
19721 +       mutex_lock(&in->i_mutex);
19722 +       if (*mask & IATTR_TAG) {
19723 +               attr.ia_tag = *tag;
19724 +               attr.ia_valid |= ATTR_TAG;
19725 +       }
19726 +
19727 +       if (*mask & IATTR_FLAGS) {
19728 +               struct proc_dir_entry *entry = PROC_I(in)->pde;
19729 +               unsigned int iflags = PROC_I(in)->vx_flags;
19730 +
19731 +               iflags = (iflags & ~(*mask & IATTR_FLAGS))
19732 +                       | (*flags & IATTR_FLAGS);
19733 +               PROC_I(in)->vx_flags = iflags;
19734 +               if (entry)
19735 +                       entry->vx_flags = iflags;
19736 +       }
19737 +
19738 +       if (*mask & (IATTR_IMMUTABLE | IATTR_IXUNLINK |
19739 +               IATTR_BARRIER | IATTR_COW)) {
19740 +               int iflags = in->i_flags;
19741 +               int vflags = in->i_vflags;
19742 +
19743 +               if (*mask & IATTR_IMMUTABLE) {
19744 +                       if (*flags & IATTR_IMMUTABLE)
19745 +                               iflags |= S_IMMUTABLE;
19746 +                       else
19747 +                               iflags &= ~S_IMMUTABLE;
19748 +               }
19749 +               if (*mask & IATTR_IXUNLINK) {
19750 +                       if (*flags & IATTR_IXUNLINK)
19751 +                               iflags |= S_IXUNLINK;
19752 +                       else
19753 +                               iflags &= ~S_IXUNLINK;
19754 +               }
19755 +               if (S_ISDIR(in->i_mode) && (*mask & IATTR_BARRIER)) {
19756 +                       if (*flags & IATTR_BARRIER)
19757 +                               vflags |= V_BARRIER;
19758 +                       else
19759 +                               vflags &= ~V_BARRIER;
19760 +               }
19761 +               if (S_ISREG(in->i_mode) && (*mask & IATTR_COW)) {
19762 +                       if (*flags & IATTR_COW)
19763 +                               vflags |= V_COW;
19764 +                       else
19765 +                               vflags &= ~V_COW;
19766 +               }
19767 +               if (in->i_op && in->i_op->sync_flags) {
19768 +                       error = in->i_op->sync_flags(in, iflags, vflags);
19769 +                       if (error)
19770 +                               goto out;
19771 +               }
19772 +       }
19773 +
19774 +       if (attr.ia_valid) {
19775 +               if (in->i_op && in->i_op->setattr)
19776 +                       error = in->i_op->setattr(de, &attr);
19777 +               else {
19778 +                       error = inode_change_ok(in, &attr);
19779 +                       if (!error) {
19780 +                               setattr_copy(in, &attr);
19781 +                               mark_inode_dirty(in);
19782 +                       }
19783 +               }
19784 +       }
19785 +
19786 +out:
19787 +       mutex_unlock(&in->i_mutex);
19788 +       return error;
19789 +}
19790 +
19791 +int vc_set_iattr(void __user *data)
19792 +{
19793 +       struct path path;
19794 +       struct vcmd_ctx_iattr_v1 vc_data;
19795 +       int ret;
19796 +
19797 +       if (!capable(CAP_LINUX_IMMUTABLE))
19798 +               return -EPERM;
19799 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19800 +               return -EFAULT;
19801 +
19802 +       ret = user_lpath(vc_data.name, &path);
19803 +       if (!ret) {
19804 +               ret = __vc_set_iattr(path.dentry,
19805 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
19806 +               path_put(&path);
19807 +       }
19808 +
19809 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19810 +               ret = -EFAULT;
19811 +       return ret;
19812 +}
19813 +
19814 +#ifdef CONFIG_COMPAT
19815 +
19816 +int vc_set_iattr_x32(void __user *data)
19817 +{
19818 +       struct path path;
19819 +       struct vcmd_ctx_iattr_v1_x32 vc_data;
19820 +       int ret;
19821 +
19822 +       if (!capable(CAP_LINUX_IMMUTABLE))
19823 +               return -EPERM;
19824 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19825 +               return -EFAULT;
19826 +
19827 +       ret = user_lpath(compat_ptr(vc_data.name_ptr), &path);
19828 +       if (!ret) {
19829 +               ret = __vc_set_iattr(path.dentry,
19830 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
19831 +               path_put(&path);
19832 +       }
19833 +
19834 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19835 +               ret = -EFAULT;
19836 +       return ret;
19837 +}
19838 +
19839 +#endif /* CONFIG_COMPAT */
19840 +
19841 +int vc_fset_iattr(uint32_t fd, void __user *data)
19842 +{
19843 +       struct file *filp;
19844 +       struct vcmd_ctx_fiattr_v0 vc_data;
19845 +       int ret;
19846 +
19847 +       if (!capable(CAP_LINUX_IMMUTABLE))
19848 +               return -EPERM;
19849 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19850 +               return -EFAULT;
19851 +
19852 +       filp = fget(fd);
19853 +       if (!filp || !filp->f_dentry || !filp->f_dentry->d_inode)
19854 +               return -EBADF;
19855 +
19856 +       ret = __vc_set_iattr(filp->f_dentry, &vc_data.tag,
19857 +               &vc_data.flags, &vc_data.mask);
19858 +
19859 +       fput(filp);
19860 +
19861 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19862 +               return -EFAULT;
19863 +       return ret;
19864 +}
19865 +
19866 +
19867 +enum { Opt_notagcheck, Opt_tag, Opt_notag, Opt_tagid, Opt_err };
19868 +
19869 +static match_table_t tokens = {
19870 +       {Opt_notagcheck, "notagcheck"},
19871 +#ifdef CONFIG_PROPAGATE
19872 +       {Opt_notag, "notag"},
19873 +       {Opt_tag, "tag"},
19874 +       {Opt_tagid, "tagid=%u"},
19875 +#endif
19876 +       {Opt_err, NULL}
19877 +};
19878 +
19879 +
19880 +static void __dx_parse_remove(char *string, char *opt)
19881 +{
19882 +       char *p = strstr(string, opt);
19883 +       char *q = p;
19884 +
19885 +       if (p) {
19886 +               while (*q != '\0' && *q != ',')
19887 +                       q++;
19888 +               while (*q)
19889 +                       *p++ = *q++;
19890 +               while (*p)
19891 +                       *p++ = '\0';
19892 +       }
19893 +}
19894 +
19895 +int dx_parse_tag(char *string, tag_t *tag, int remove, int *mnt_flags,
19896 +                unsigned long *flags)
19897 +{
19898 +       int set = 0;
19899 +       substring_t args[MAX_OPT_ARGS];
19900 +       int token;
19901 +       char *s, *p, *opts;
19902 +#if defined(CONFIG_PROPAGATE) || defined(CONFIG_VSERVER_DEBUG)
19903 +       int option = 0;
19904 +#endif
19905 +
19906 +       if (!string)
19907 +               return 0;
19908 +       s = kstrdup(string, GFP_KERNEL | GFP_ATOMIC);
19909 +       if (!s)
19910 +               return 0;
19911 +
19912 +       opts = s;
19913 +       while ((p = strsep(&opts, ",")) != NULL) {
19914 +               token = match_token(p, tokens, args);
19915 +
19916 +               switch (token) {
19917 +#ifdef CONFIG_PROPAGATE
19918 +               case Opt_tag:
19919 +                       if (tag)
19920 +                               *tag = 0;
19921 +                       if (remove)
19922 +                               __dx_parse_remove(s, "tag");
19923 +                       *mnt_flags |= MNT_TAGID;
19924 +                       set |= MNT_TAGID;
19925 +                       break;
19926 +               case Opt_notag:
19927 +                       if (remove)
19928 +                               __dx_parse_remove(s, "notag");
19929 +                       *mnt_flags |= MNT_NOTAG;
19930 +                       set |= MNT_NOTAG;
19931 +                       break;
19932 +               case Opt_tagid:
19933 +                       if (tag && !match_int(args, &option))
19934 +                               *tag = option;
19935 +                       if (remove)
19936 +                               __dx_parse_remove(s, "tagid");
19937 +                       *mnt_flags |= MNT_TAGID;
19938 +                       set |= MNT_TAGID;
19939 +                       break;
19940 +#endif
19941 +               case Opt_notagcheck:
19942 +                       if (remove)
19943 +                               __dx_parse_remove(s, "notagcheck");
19944 +                       *flags |= MS_NOTAGCHECK;
19945 +                       set |= MS_NOTAGCHECK;
19946 +                       break;
19947 +               }
19948 +               vxdprintk(VXD_CBIT(tag, 7),
19949 +                       "dx_parse_tag(" VS_Q("%s") "): %d:#%d",
19950 +                       p, token, option);
19951 +       }
19952 +       if (set)
19953 +               strcpy(string, s);
19954 +       kfree(s);
19955 +       return set;
19956 +}
19957 +
19958 +#ifdef CONFIG_PROPAGATE
19959 +
19960 +void __dx_propagate_tag(struct nameidata *nd, struct inode *inode)
19961 +{
19962 +       tag_t new_tag = 0;
19963 +       struct vfsmount *mnt;
19964 +       int propagate;
19965 +
19966 +       if (!nd)
19967 +               return;
19968 +       mnt = nd->path.mnt;
19969 +       if (!mnt)
19970 +               return;
19971 +
19972 +       propagate = (mnt->mnt_flags & MNT_TAGID);
19973 +       if (propagate)
19974 +               new_tag = mnt->mnt_tag;
19975 +
19976 +       vxdprintk(VXD_CBIT(tag, 7),
19977 +               "dx_propagate_tag(%p[#%lu.%d]): %d,%d",
19978 +               inode, inode->i_ino, inode->i_tag,
19979 +               new_tag, (propagate) ? 1 : 0);
19980 +
19981 +       if (propagate)
19982 +               inode->i_tag = new_tag;
19983 +}
19984 +
19985 +#include <linux/module.h>
19986 +
19987 +EXPORT_SYMBOL_GPL(__dx_propagate_tag);
19988 +
19989 +#endif /* CONFIG_PROPAGATE */
19990 +
19991 diff -NurpP --minimal linux-3.0.25/kernel/vserver/limit.c linux-3.0.25-vs2.3.2.3/kernel/vserver/limit.c
19992 --- linux-3.0.25/kernel/vserver/limit.c 1970-01-01 01:00:00.000000000 +0100
19993 +++ linux-3.0.25-vs2.3.2.3/kernel/vserver/limit.c       2011-10-11 20:48:08.000000000 +0200
19994 @@ -0,0 +1,360 @@
19995 +/*
19996 + *  linux/kernel/vserver/limit.c
19997 + *
19998 + *  Virtual Server: Context Limits
19999 + *
20000 + *  Copyright (C) 2004-2010  Herbert Pötzl
20001 + *
20002 + *  V0.01  broken out from vcontext V0.05
20003 + *  V0.02  changed vcmds to vxi arg
20004 + *  V0.03  added memory cgroup support
20005 + *
20006 + */
20007 +
20008 +#include <linux/sched.h>
20009 +#include <linux/module.h>
20010 +#include <linux/memcontrol.h>
20011 +#include <linux/res_counter.h>
20012 +#include <linux/vs_limit.h>
20013 +#include <linux/vserver/limit.h>
20014 +#include <linux/vserver/limit_cmd.h>
20015 +
20016 +#include <asm/uaccess.h>
20017 +
20018 +
20019 +const char *vlimit_name[NUM_LIMITS] = {
20020 +#ifdef CONFIG_VSERVER_LEGACY_MEM
20021 +       [RLIMIT_RSS]            = "RSS",
20022 +       [RLIMIT_AS]             = "VM",
20023 +#endif /* CONFIG_VSERVER_LEGACY_MEM */
20024 +       [RLIMIT_CPU]            = "CPU",
20025 +       [RLIMIT_NPROC]          = "NPROC",
20026 +       [RLIMIT_NOFILE]         = "NOFILE",
20027 +       [RLIMIT_LOCKS]          = "LOCKS",
20028 +       [RLIMIT_SIGPENDING]     = "SIGP",
20029 +       [RLIMIT_MSGQUEUE]       = "MSGQ",
20030 +
20031 +       [VLIMIT_NSOCK]          = "NSOCK",
20032 +       [VLIMIT_OPENFD]         = "OPENFD",
20033 +       [VLIMIT_SHMEM]          = "SHMEM",
20034 +       [VLIMIT_DENTRY]         = "DENTRY",
20035 +};
20036 +
20037 +EXPORT_SYMBOL_GPL(vlimit_name);
20038 +
20039 +#define MASK_ENTRY(x)  (1 << (x))
20040 +
20041 +const struct vcmd_ctx_rlimit_mask_v0 vlimit_mask = {
20042 +               /* minimum */
20043 +       0
20044 +       ,       /* softlimit */
20045 +#ifdef CONFIG_VSERVER_LEGACY_MEM
20046 +       MASK_ENTRY( RLIMIT_RSS          ) |
20047 +#endif /* CONFIG_VSERVER_LEGACY_MEM */
20048 +       0
20049 +       ,       /* maximum */
20050 +#ifdef CONFIG_VSERVER_LEGACY_MEM
20051 +       MASK_ENTRY( RLIMIT_RSS          ) |
20052 +       MASK_ENTRY( RLIMIT_AS           ) |
20053 +#endif /* CONFIG_VSERVER_LEGACY_MEM */
20054 +       MASK_ENTRY( RLIMIT_NPROC        ) |
20055 +       MASK_ENTRY( RLIMIT_NOFILE       ) |
20056 +       MASK_ENTRY( RLIMIT_LOCKS        ) |
20057 +       MASK_ENTRY( RLIMIT_MSGQUEUE     ) |
20058 +
20059 +       MASK_ENTRY( VLIMIT_NSOCK        ) |
20060 +       MASK_ENTRY( VLIMIT_OPENFD       ) |
20061 +       MASK_ENTRY( VLIMIT_SHMEM        ) |
20062 +       MASK_ENTRY( VLIMIT_DENTRY       ) |
20063 +       0
20064 +};
20065 +               /* accounting only */
20066 +uint32_t account_mask =
20067 +       MASK_ENTRY( VLIMIT_SEMARY       ) |
20068 +       MASK_ENTRY( VLIMIT_NSEMS        ) |
20069 +       MASK_ENTRY( VLIMIT_MAPPED       ) |
20070 +       0;
20071 +
20072 +
20073 +static int is_valid_vlimit(int id)
20074 +{
20075 +       uint32_t mask = vlimit_mask.minimum |
20076 +               vlimit_mask.softlimit | vlimit_mask.maximum;
20077 +       return mask & (1 << id);
20078 +}
20079 +
20080 +static int is_accounted_vlimit(int id)
20081 +{
20082 +       if (is_valid_vlimit(id))
20083 +               return 1;
20084 +       return account_mask & (1 << id);
20085 +}
20086 +
20087 +
20088 +static inline uint64_t vc_get_soft(struct vx_info *vxi, int id)
20089 +{
20090 +       rlim_t limit = __rlim_soft(&vxi->limit, id);
20091 +       return VX_VLIM(limit);
20092 +}
20093 +
20094 +static inline uint64_t vc_get_hard(struct vx_info *vxi, int id)
20095 +{
20096 +       rlim_t limit = __rlim_hard(&vxi->limit, id);
20097 +       return VX_VLIM(limit);
20098 +}
20099 +
20100 +static int do_get_rlimit(struct vx_info *vxi, uint32_t id,
20101 +       uint64_t *minimum, uint64_t *softlimit, uint64_t *maximum)
20102 +{
20103 +       if (!is_valid_vlimit(id))
20104 +               return -EINVAL;
20105 +
20106 +       if (minimum)
20107 +               *minimum = CRLIM_UNSET;
20108 +       if (softlimit)
20109 +               *softlimit = vc_get_soft(vxi, id);
20110 +       if (maximum)
20111 +               *maximum = vc_get_hard(vxi, id);
20112 +       return 0;
20113 +}
20114 +
20115 +int vc_get_rlimit(struct vx_info *vxi, void __user *data)
20116 +{
20117 +       struct vcmd_ctx_rlimit_v0 vc_data;
20118 +       int ret;
20119 +
20120 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20121 +               return -EFAULT;
20122 +
20123 +       ret = do_get_rlimit(vxi, vc_data.id,
20124 +               &vc_data.minimum, &vc_data.softlimit, &vc_data.maximum);
20125 +       if (ret)
20126 +               return ret;
20127 +
20128 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20129 +               return -EFAULT;
20130 +       return 0;
20131 +}
20132 +
20133 +static int do_set_rlimit(struct vx_info *vxi, uint32_t id,
20134 +       uint64_t minimum, uint64_t softlimit, uint64_t maximum)
20135 +{
20136 +       if (!is_valid_vlimit(id))
20137 +               return -EINVAL;
20138 +
20139 +       if (maximum != CRLIM_KEEP)
20140 +               __rlim_hard(&vxi->limit, id) = VX_RLIM(maximum);
20141 +       if (softlimit != CRLIM_KEEP)
20142 +               __rlim_soft(&vxi->limit, id) = VX_RLIM(softlimit);
20143 +
20144 +       /* clamp soft limit */
20145 +       if (__rlim_soft(&vxi->limit, id) > __rlim_hard(&vxi->limit, id))
20146 +               __rlim_soft(&vxi->limit, id) = __rlim_hard(&vxi->limit, id);
20147 +
20148 +       return 0;
20149 +}
20150 +
20151 +int vc_set_rlimit(struct vx_info *vxi, void __user *data)
20152 +{
20153 +       struct vcmd_ctx_rlimit_v0 vc_data;
20154 +
20155 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20156 +               return -EFAULT;
20157 +
20158 +       return do_set_rlimit(vxi, vc_data.id,
20159 +               vc_data.minimum, vc_data.softlimit, vc_data.maximum);
20160 +}
20161 +
20162 +#ifdef CONFIG_IA32_EMULATION
20163 +
20164 +int vc_set_rlimit_x32(struct vx_info *vxi, void __user *data)
20165 +{
20166 +       struct vcmd_ctx_rlimit_v0_x32 vc_data;
20167 +
20168 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20169 +               return -EFAULT;
20170 +
20171 +       return do_set_rlimit(vxi, vc_data.id,
20172 +               vc_data.minimum, vc_data.softlimit, vc_data.maximum);
20173 +}
20174 +
20175 +int vc_get_rlimit_x32(struct vx_info *vxi, void __user *data)
20176 +{
20177 +       struct vcmd_ctx_rlimit_v0_x32 vc_data;
20178 +       int ret;
20179 +
20180 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20181 +               return -EFAULT;
20182 +
20183 +       ret = do_get_rlimit(vxi, vc_data.id,
20184 +               &vc_data.minimum, &vc_data.softlimit, &vc_data.maximum);
20185 +       if (ret)
20186 +               return ret;
20187 +
20188 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20189 +               return -EFAULT;
20190 +       return 0;
20191 +}
20192 +
20193 +#endif /* CONFIG_IA32_EMULATION */
20194 +
20195 +
20196 +int vc_get_rlimit_mask(uint32_t id, void __user *data)
20197 +{
20198 +       if (copy_to_user(data, &vlimit_mask, sizeof(vlimit_mask)))
20199 +               return -EFAULT;
20200 +       return 0;
20201 +}
20202 +
20203 +
20204 +static inline void vx_reset_hits(struct _vx_limit *limit)
20205 +{
20206 +       int lim;
20207 +
20208 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
20209 +               atomic_set(&__rlim_lhit(limit, lim), 0);
20210 +       }
20211 +}
20212 +
20213 +int vc_reset_hits(struct vx_info *vxi, void __user *data)
20214 +{
20215 +       vx_reset_hits(&vxi->limit);
20216 +       return 0;
20217 +}
20218 +
20219 +static inline void vx_reset_minmax(struct _vx_limit *limit)
20220 +{
20221 +       rlim_t value;
20222 +       int lim;
20223 +
20224 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
20225 +               value = __rlim_get(limit, lim);
20226 +               __rlim_rmax(limit, lim) = value;
20227 +               __rlim_rmin(limit, lim) = value;
20228 +       }
20229 +}
20230 +
20231 +int vc_reset_minmax(struct vx_info *vxi, void __user *data)
20232 +{
20233 +       vx_reset_minmax(&vxi->limit);
20234 +       return 0;
20235 +}
20236 +
20237 +
20238 +int vc_rlimit_stat(struct vx_info *vxi, void __user *data)
20239 +{
20240 +       struct vcmd_rlimit_stat_v0 vc_data;
20241 +       struct _vx_limit *limit = &vxi->limit;
20242 +       int id;
20243 +
20244 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20245 +               return -EFAULT;
20246 +
20247 +       id = vc_data.id;
20248 +       if (!is_accounted_vlimit(id))
20249 +               return -EINVAL;
20250 +
20251 +       vx_limit_fixup(limit, id);
20252 +       vc_data.hits = atomic_read(&__rlim_lhit(limit, id));
20253 +       vc_data.value = __rlim_get(limit, id);
20254 +       vc_data.minimum = __rlim_rmin(limit, id);
20255 +       vc_data.maximum = __rlim_rmax(limit, id);
20256 +
20257 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20258 +               return -EFAULT;
20259 +       return 0;
20260 +}
20261 +
20262 +
20263 +void vx_vsi_meminfo(struct sysinfo *val)
20264 +{
20265 +#ifdef CONFIG_CGROUP_MEM_RES_CTLR
20266 +       struct mem_cgroup *mcg = mem_cgroup_from_task(current);
20267 +       u64 res_limit, res_usage;
20268 +
20269 +       if (!mcg)
20270 +               return;
20271 +
20272 +       res_limit = mem_cgroup_res_read_u64(mcg, RES_LIMIT);
20273 +       res_usage = mem_cgroup_res_read_u64(mcg, RES_USAGE);
20274 +
20275 +       if (res_limit != RESOURCE_MAX)
20276 +               val->totalram = (res_limit >> PAGE_SHIFT);
20277 +       val->freeram = val->totalram - (res_usage >> PAGE_SHIFT);
20278 +       val->bufferram = 0;
20279 +       val->totalhigh = 0;
20280 +       val->freehigh = 0;
20281 +#endif /* CONFIG_CGROUP_MEM_RES_CTLR */
20282 +       return;
20283 +}
20284 +
20285 +void vx_vsi_swapinfo(struct sysinfo *val)
20286 +{
20287 +#ifdef CONFIG_CGROUP_MEM_RES_CTLR
20288 +#ifdef CONFIG_CGROUP_MEM_RES_CTLR_SWAP
20289 +       struct mem_cgroup *mcg = mem_cgroup_from_task(current);
20290 +       u64 res_limit, res_usage, memsw_limit, memsw_usage;
20291 +       s64 swap_limit, swap_usage;
20292 +
20293 +       if (!mcg)
20294 +               return;
20295 +
20296 +       res_limit = mem_cgroup_res_read_u64(mcg, RES_LIMIT);
20297 +       res_usage = mem_cgroup_res_read_u64(mcg, RES_USAGE);
20298 +       memsw_limit = mem_cgroup_memsw_read_u64(mcg, RES_LIMIT);
20299 +       memsw_usage = mem_cgroup_memsw_read_u64(mcg, RES_USAGE);
20300 +
20301 +       /* memory unlimited */
20302 +       if (res_limit == RESOURCE_MAX)
20303 +               return;
20304 +
20305 +       swap_limit = memsw_limit - res_limit;
20306 +       /* we have a swap limit? */
20307 +       if (memsw_limit != RESOURCE_MAX)
20308 +               val->totalswap = swap_limit >> PAGE_SHIFT;
20309 +
20310 +       /* calculate swap part */
20311 +       swap_usage = (memsw_usage > res_usage) ?
20312 +               memsw_usage - res_usage : 0;
20313 +
20314 +       /* total shown minus usage gives free swap */
20315 +       val->freeswap = (swap_usage < swap_limit) ?
20316 +               val->totalswap - (swap_usage >> PAGE_SHIFT) : 0;
20317 +#else  /* !CONFIG_CGROUP_MEM_RES_CTLR_SWAP */
20318 +       val->totalswap = 0;
20319 +       val->freeswap = 0;
20320 +#endif /* !CONFIG_CGROUP_MEM_RES_CTLR_SWAP */
20321 +#endif /* CONFIG_CGROUP_MEM_RES_CTLR */
20322 +       return;
20323 +}
20324 +
20325 +long vx_vsi_cached(struct sysinfo *val)
20326 +{
20327 +#ifdef CONFIG_CGROUP_MEM_RES_CTLR
20328 +       struct mem_cgroup *mcg = mem_cgroup_from_task(current);
20329 +
20330 +       return mem_cgroup_stat_read_cache(mcg);
20331 +#else
20332 +       return 0;
20333 +#endif
20334 +}
20335 +
20336 +
20337 +unsigned long vx_badness(struct task_struct *task, struct mm_struct *mm)
20338 +{
20339 +       struct vx_info *vxi = mm->mm_vx_info;
20340 +       unsigned long points;
20341 +       rlim_t v, w;
20342 +
20343 +       if (!vxi)
20344 +               return 0;
20345 +
20346 +       points = vxi->vx_badness_bias;
20347 +
20348 +       v = __vx_cres_array_fixup(&vxi->limit, VLA_RSS);
20349 +       w = __rlim_soft(&vxi->limit, RLIMIT_RSS);
20350 +       points += (v > w) ? (v - w) : 0;
20351 +
20352 +       return points;
20353 +}
20354 +
20355 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
20356 --- linux-3.0.25/kernel/vserver/limit_init.h    1970-01-01 01:00:00.000000000 +0100
20357 +++ linux-3.0.25-vs2.3.2.3/kernel/vserver/limit_init.h  2011-06-10 22:11:24.000000000 +0200
20358 @@ -0,0 +1,31 @@
20359 +
20360 +
20361 +static inline void vx_info_init_limit(struct _vx_limit *limit)
20362 +{
20363 +       int lim;
20364 +
20365 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
20366 +               __rlim_soft(limit, lim) = RLIM_INFINITY;
20367 +               __rlim_hard(limit, lim) = RLIM_INFINITY;
20368 +               __rlim_set(limit, lim, 0);
20369 +               atomic_set(&__rlim_lhit(limit, lim), 0);
20370 +               __rlim_rmin(limit, lim) = 0;
20371 +               __rlim_rmax(limit, lim) = 0;
20372 +       }
20373 +}
20374 +
20375 +static inline void vx_info_exit_limit(struct _vx_limit *limit)
20376 +{
20377 +       rlim_t value;
20378 +       int lim;
20379 +
20380 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
20381 +               if ((1 << lim) & VLIM_NOCHECK)
20382 +                       continue;
20383 +               value = __rlim_get(limit, lim);
20384 +               vxwprintk_xid(value,
20385 +                       "!!! limit: %p[%s,%d] = %ld on exit.",
20386 +                       limit, vlimit_name[lim], lim, (long)value);
20387 +       }
20388 +}
20389 +
20390 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
20391 --- linux-3.0.25/kernel/vserver/limit_proc.h    1970-01-01 01:00:00.000000000 +0100
20392 +++ linux-3.0.25-vs2.3.2.3/kernel/vserver/limit_proc.h  2011-06-10 22:11:24.000000000 +0200
20393 @@ -0,0 +1,57 @@
20394 +#ifndef _VX_LIMIT_PROC_H
20395 +#define _VX_LIMIT_PROC_H
20396 +
20397 +#include <linux/vserver/limit_int.h>
20398 +
20399 +
20400 +#define VX_LIMIT_FMT   ":\t%8ld\t%8ld/%8ld\t%8lld/%8lld\t%6d\n"
20401 +#define VX_LIMIT_TOP   \
20402 +       "Limit\t current\t     min/max\t\t    soft/hard\t\thits\n"
20403 +
20404 +#define VX_LIMIT_ARG(r)                                \
20405 +       (unsigned long)__rlim_get(limit, r),    \
20406 +       (unsigned long)__rlim_rmin(limit, r),   \
20407 +       (unsigned long)__rlim_rmax(limit, r),   \
20408 +       VX_VLIM(__rlim_soft(limit, r)),         \
20409 +       VX_VLIM(__rlim_hard(limit, r)),         \
20410 +       atomic_read(&__rlim_lhit(limit, r))
20411 +
20412 +static inline int vx_info_proc_limit(struct _vx_limit *limit, char *buffer)
20413 +{
20414 +       vx_limit_fixup(limit, -1);
20415 +       return sprintf(buffer, VX_LIMIT_TOP
20416 +               "PROC"  VX_LIMIT_FMT
20417 +               "VM"    VX_LIMIT_FMT
20418 +               "VML"   VX_LIMIT_FMT
20419 +               "RSS"   VX_LIMIT_FMT
20420 +               "ANON"  VX_LIMIT_FMT
20421 +               "RMAP"  VX_LIMIT_FMT
20422 +               "FILES" VX_LIMIT_FMT
20423 +               "OFD"   VX_LIMIT_FMT
20424 +               "LOCKS" VX_LIMIT_FMT
20425 +               "SOCK"  VX_LIMIT_FMT
20426 +               "MSGQ"  VX_LIMIT_FMT
20427 +               "SHM"   VX_LIMIT_FMT
20428 +               "SEMA"  VX_LIMIT_FMT
20429 +               "SEMS"  VX_LIMIT_FMT
20430 +               "DENT"  VX_LIMIT_FMT,
20431 +               VX_LIMIT_ARG(RLIMIT_NPROC),
20432 +               VX_LIMIT_ARG(RLIMIT_AS),
20433 +               VX_LIMIT_ARG(RLIMIT_MEMLOCK),
20434 +               VX_LIMIT_ARG(RLIMIT_RSS),
20435 +               VX_LIMIT_ARG(VLIMIT_ANON),
20436 +               VX_LIMIT_ARG(VLIMIT_MAPPED),
20437 +               VX_LIMIT_ARG(RLIMIT_NOFILE),
20438 +               VX_LIMIT_ARG(VLIMIT_OPENFD),
20439 +               VX_LIMIT_ARG(RLIMIT_LOCKS),
20440 +               VX_LIMIT_ARG(VLIMIT_NSOCK),
20441 +               VX_LIMIT_ARG(RLIMIT_MSGQUEUE),
20442 +               VX_LIMIT_ARG(VLIMIT_SHMEM),
20443 +               VX_LIMIT_ARG(VLIMIT_SEMARY),
20444 +               VX_LIMIT_ARG(VLIMIT_NSEMS),
20445 +               VX_LIMIT_ARG(VLIMIT_DENTRY));
20446 +}
20447 +
20448 +#endif /* _VX_LIMIT_PROC_H */
20449 +
20450 +
20451 diff -NurpP --minimal linux-3.0.25/kernel/vserver/network.c linux-3.0.25-vs2.3.2.3/kernel/vserver/network.c
20452 --- linux-3.0.25/kernel/vserver/network.c       1970-01-01 01:00:00.000000000 +0100
20453 +++ linux-3.0.25-vs2.3.2.3/kernel/vserver/network.c     2011-06-10 23:20:56.000000000 +0200
20454 @@ -0,0 +1,912 @@
20455 +/*
20456 + *  linux/kernel/vserver/network.c
20457 + *
20458 + *  Virtual Server: Network Support
20459 + *
20460 + *  Copyright (C) 2003-2007  Herbert Pötzl
20461 + *
20462 + *  V0.01  broken out from vcontext V0.05
20463 + *  V0.02  cleaned up implementation
20464 + *  V0.03  added equiv nx commands
20465 + *  V0.04  switch to RCU based hash
20466 + *  V0.05  and back to locking again
20467 + *  V0.06  changed vcmds to nxi arg
20468 + *  V0.07  have __create claim() the nxi
20469 + *
20470 + */
20471 +
20472 +#include <linux/err.h>
20473 +#include <linux/slab.h>
20474 +#include <linux/rcupdate.h>
20475 +
20476 +#include <linux/vs_network.h>
20477 +#include <linux/vs_pid.h>
20478 +#include <linux/vserver/network_cmd.h>
20479 +
20480 +
20481 +atomic_t nx_global_ctotal      = ATOMIC_INIT(0);
20482 +atomic_t nx_global_cactive     = ATOMIC_INIT(0);
20483 +
20484 +static struct kmem_cache *nx_addr_v4_cachep = NULL;
20485 +static struct kmem_cache *nx_addr_v6_cachep = NULL;
20486 +
20487 +
20488 +static int __init init_network(void)
20489 +{
20490 +       nx_addr_v4_cachep = kmem_cache_create("nx_v4_addr_cache",
20491 +               sizeof(struct nx_addr_v4), 0,
20492 +               SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
20493 +       nx_addr_v6_cachep = kmem_cache_create("nx_v6_addr_cache",
20494 +               sizeof(struct nx_addr_v6), 0,
20495 +               SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
20496 +       return 0;
20497 +}
20498 +
20499 +
20500 +/*     __alloc_nx_addr_v4()                                    */
20501 +
20502 +static inline struct nx_addr_v4 *__alloc_nx_addr_v4(void)
20503 +{
20504 +       struct nx_addr_v4 *nxa = kmem_cache_alloc(
20505 +               nx_addr_v4_cachep, GFP_KERNEL);
20506 +
20507 +       if (!IS_ERR(nxa))
20508 +               memset(nxa, 0, sizeof(*nxa));
20509 +       return nxa;
20510 +}
20511 +
20512 +/*     __dealloc_nx_addr_v4()                                  */
20513 +
20514 +static inline void __dealloc_nx_addr_v4(struct nx_addr_v4 *nxa)
20515 +{
20516 +       kmem_cache_free(nx_addr_v4_cachep, nxa);
20517 +}
20518 +
20519 +/*     __dealloc_nx_addr_v4_all()                              */
20520 +
20521 +static inline void __dealloc_nx_addr_v4_all(struct nx_addr_v4 *nxa)
20522 +{
20523 +       while (nxa) {
20524 +               struct nx_addr_v4 *next = nxa->next;
20525 +
20526 +               __dealloc_nx_addr_v4(nxa);
20527 +               nxa = next;
20528 +       }
20529 +}
20530 +
20531 +
20532 +#ifdef CONFIG_IPV6
20533 +
20534 +/*     __alloc_nx_addr_v6()                                    */
20535 +
20536 +static inline struct nx_addr_v6 *__alloc_nx_addr_v6(void)
20537 +{
20538 +       struct nx_addr_v6 *nxa = kmem_cache_alloc(
20539 +               nx_addr_v6_cachep, GFP_KERNEL);
20540 +
20541 +       if (!IS_ERR(nxa))
20542 +               memset(nxa, 0, sizeof(*nxa));
20543 +       return nxa;
20544 +}
20545 +
20546 +/*     __dealloc_nx_addr_v6()                                  */
20547 +
20548 +static inline void __dealloc_nx_addr_v6(struct nx_addr_v6 *nxa)
20549 +{
20550 +       kmem_cache_free(nx_addr_v6_cachep, nxa);
20551 +}
20552 +
20553 +/*     __dealloc_nx_addr_v6_all()                              */
20554 +
20555 +static inline void __dealloc_nx_addr_v6_all(struct nx_addr_v6 *nxa)
20556 +{
20557 +       while (nxa) {
20558 +               struct nx_addr_v6 *next = nxa->next;
20559 +
20560 +               __dealloc_nx_addr_v6(nxa);
20561 +               nxa = next;
20562 +       }
20563 +}
20564 +
20565 +#endif /* CONFIG_IPV6 */
20566 +
20567 +/*     __alloc_nx_info()
20568 +
20569 +       * allocate an initialized nx_info struct
20570 +       * doesn't make it visible (hash)                        */
20571 +
20572 +static struct nx_info *__alloc_nx_info(nid_t nid)
20573 +{
20574 +       struct nx_info *new = NULL;
20575 +
20576 +       vxdprintk(VXD_CBIT(nid, 1), "alloc_nx_info(%d)*", nid);
20577 +
20578 +       /* would this benefit from a slab cache? */
20579 +       new = kmalloc(sizeof(struct nx_info), GFP_KERNEL);
20580 +       if (!new)
20581 +               return 0;
20582 +
20583 +       memset(new, 0, sizeof(struct nx_info));
20584 +       new->nx_id = nid;
20585 +       INIT_HLIST_NODE(&new->nx_hlist);
20586 +       atomic_set(&new->nx_usecnt, 0);
20587 +       atomic_set(&new->nx_tasks, 0);
20588 +       new->nx_state = 0;
20589 +
20590 +       new->nx_flags = NXF_INIT_SET;
20591 +
20592 +       /* rest of init goes here */
20593 +
20594 +       new->v4_lback.s_addr = htonl(INADDR_LOOPBACK);
20595 +       new->v4_bcast.s_addr = htonl(INADDR_BROADCAST);
20596 +
20597 +       vxdprintk(VXD_CBIT(nid, 0),
20598 +               "alloc_nx_info(%d) = %p", nid, new);
20599 +       atomic_inc(&nx_global_ctotal);
20600 +       return new;
20601 +}
20602 +
20603 +/*     __dealloc_nx_info()
20604 +
20605 +       * final disposal of nx_info                             */
20606 +
20607 +static void __dealloc_nx_info(struct nx_info *nxi)
20608 +{
20609 +       vxdprintk(VXD_CBIT(nid, 0),
20610 +               "dealloc_nx_info(%p)", nxi);
20611 +
20612 +       nxi->nx_hlist.next = LIST_POISON1;
20613 +       nxi->nx_id = -1;
20614 +
20615 +       BUG_ON(atomic_read(&nxi->nx_usecnt));
20616 +       BUG_ON(atomic_read(&nxi->nx_tasks));
20617 +
20618 +       __dealloc_nx_addr_v4_all(nxi->v4.next);
20619 +
20620 +       nxi->nx_state |= NXS_RELEASED;
20621 +       kfree(nxi);
20622 +       atomic_dec(&nx_global_ctotal);
20623 +}
20624 +
20625 +static void __shutdown_nx_info(struct nx_info *nxi)
20626 +{
20627 +       nxi->nx_state |= NXS_SHUTDOWN;
20628 +       vs_net_change(nxi, VSC_NETDOWN);
20629 +}
20630 +
20631 +/*     exported stuff                                          */
20632 +
20633 +void free_nx_info(struct nx_info *nxi)
20634 +{
20635 +       /* context shutdown is mandatory */
20636 +       BUG_ON(nxi->nx_state != NXS_SHUTDOWN);
20637 +
20638 +       /* context must not be hashed */
20639 +       BUG_ON(nxi->nx_state & NXS_HASHED);
20640 +
20641 +       BUG_ON(atomic_read(&nxi->nx_usecnt));
20642 +       BUG_ON(atomic_read(&nxi->nx_tasks));
20643 +
20644 +       __dealloc_nx_info(nxi);
20645 +}
20646 +
20647 +
20648 +void __nx_set_lback(struct nx_info *nxi)
20649 +{
20650 +       int nid = nxi->nx_id;
20651 +       __be32 lback = htonl(INADDR_LOOPBACK ^ ((nid & 0xFFFF) << 8));
20652 +
20653 +       nxi->v4_lback.s_addr = lback;
20654 +}
20655 +
20656 +extern int __nx_inet_add_lback(__be32 addr);
20657 +extern int __nx_inet_del_lback(__be32 addr);
20658 +
20659 +
20660 +/*     hash table for nx_info hash */
20661 +
20662 +#define NX_HASH_SIZE   13
20663 +
20664 +struct hlist_head nx_info_hash[NX_HASH_SIZE];
20665 +
20666 +static DEFINE_SPINLOCK(nx_info_hash_lock);
20667 +
20668 +
20669 +static inline unsigned int __hashval(nid_t nid)
20670 +{
20671 +       return (nid % NX_HASH_SIZE);
20672 +}
20673 +
20674 +
20675 +
20676 +/*     __hash_nx_info()
20677 +
20678 +       * add the nxi to the global hash table
20679 +       * requires the hash_lock to be held                     */
20680 +
20681 +static inline void __hash_nx_info(struct nx_info *nxi)
20682 +{
20683 +       struct hlist_head *head;
20684 +
20685 +       vxd_assert_lock(&nx_info_hash_lock);
20686 +       vxdprintk(VXD_CBIT(nid, 4),
20687 +               "__hash_nx_info: %p[#%d]", nxi, nxi->nx_id);
20688 +
20689 +       /* context must not be hashed */
20690 +       BUG_ON(nx_info_state(nxi, NXS_HASHED));
20691 +
20692 +       nxi->nx_state |= NXS_HASHED;
20693 +       head = &nx_info_hash[__hashval(nxi->nx_id)];
20694 +       hlist_add_head(&nxi->nx_hlist, head);
20695 +       atomic_inc(&nx_global_cactive);
20696 +}
20697 +
20698 +/*     __unhash_nx_info()
20699 +
20700 +       * remove the nxi from the global hash table
20701 +       * requires the hash_lock to be held                     */
20702 +
20703 +static inline void __unhash_nx_info(struct nx_info *nxi)
20704 +{
20705 +       vxd_assert_lock(&nx_info_hash_lock);
20706 +       vxdprintk(VXD_CBIT(nid, 4),
20707 +               "__unhash_nx_info: %p[#%d.%d.%d]", nxi, nxi->nx_id,
20708 +               atomic_read(&nxi->nx_usecnt), atomic_read(&nxi->nx_tasks));
20709 +
20710 +       /* context must be hashed */
20711 +       BUG_ON(!nx_info_state(nxi, NXS_HASHED));
20712 +       /* but without tasks */
20713 +       BUG_ON(atomic_read(&nxi->nx_tasks));
20714 +
20715 +       nxi->nx_state &= ~NXS_HASHED;
20716 +       hlist_del(&nxi->nx_hlist);
20717 +       atomic_dec(&nx_global_cactive);
20718 +}
20719 +
20720 +
20721 +/*     __lookup_nx_info()
20722 +
20723 +       * requires the hash_lock to be held
20724 +       * doesn't increment the nx_refcnt                       */
20725 +
20726 +static inline struct nx_info *__lookup_nx_info(nid_t nid)
20727 +{
20728 +       struct hlist_head *head = &nx_info_hash[__hashval(nid)];
20729 +       struct hlist_node *pos;
20730 +       struct nx_info *nxi;
20731 +
20732 +       vxd_assert_lock(&nx_info_hash_lock);
20733 +       hlist_for_each(pos, head) {
20734 +               nxi = hlist_entry(pos, struct nx_info, nx_hlist);
20735 +
20736 +               if (nxi->nx_id == nid)
20737 +                       goto found;
20738 +       }
20739 +       nxi = NULL;
20740 +found:
20741 +       vxdprintk(VXD_CBIT(nid, 0),
20742 +               "__lookup_nx_info(#%u): %p[#%u]",
20743 +               nid, nxi, nxi ? nxi->nx_id : 0);
20744 +       return nxi;
20745 +}
20746 +
20747 +
20748 +/*     __create_nx_info()
20749 +
20750 +       * create the requested context
20751 +       * get(), claim() and hash it                            */
20752 +
20753 +static struct nx_info *__create_nx_info(int id)
20754 +{
20755 +       struct nx_info *new, *nxi = NULL;
20756 +
20757 +       vxdprintk(VXD_CBIT(nid, 1), "create_nx_info(%d)*", id);
20758 +
20759 +       if (!(new = __alloc_nx_info(id)))
20760 +               return ERR_PTR(-ENOMEM);
20761 +
20762 +       /* required to make dynamic xids unique */
20763 +       spin_lock(&nx_info_hash_lock);
20764 +
20765 +       /* static context requested */
20766 +       if ((nxi = __lookup_nx_info(id))) {
20767 +               vxdprintk(VXD_CBIT(nid, 0),
20768 +                       "create_nx_info(%d) = %p (already there)", id, nxi);
20769 +               if (nx_info_flags(nxi, NXF_STATE_SETUP, 0))
20770 +                       nxi = ERR_PTR(-EBUSY);
20771 +               else
20772 +                       nxi = ERR_PTR(-EEXIST);
20773 +               goto out_unlock;
20774 +       }
20775 +       /* new context */
20776 +       vxdprintk(VXD_CBIT(nid, 0),
20777 +               "create_nx_info(%d) = %p (new)", id, new);
20778 +       claim_nx_info(new, NULL);
20779 +       __nx_set_lback(new);
20780 +       __hash_nx_info(get_nx_info(new));
20781 +       nxi = new, new = NULL;
20782 +
20783 +out_unlock:
20784 +       spin_unlock(&nx_info_hash_lock);
20785 +       if (new)
20786 +               __dealloc_nx_info(new);
20787 +       return nxi;
20788 +}
20789 +
20790 +
20791 +
20792 +/*     exported stuff                                          */
20793 +
20794 +
20795 +void unhash_nx_info(struct nx_info *nxi)
20796 +{
20797 +       __shutdown_nx_info(nxi);
20798 +       spin_lock(&nx_info_hash_lock);
20799 +       __unhash_nx_info(nxi);
20800 +       spin_unlock(&nx_info_hash_lock);
20801 +}
20802 +
20803 +/*     lookup_nx_info()
20804 +
20805 +       * search for a nx_info and get() it
20806 +       * negative id means current                             */
20807 +
20808 +struct nx_info *lookup_nx_info(int id)
20809 +{
20810 +       struct nx_info *nxi = NULL;
20811 +
20812 +       if (id < 0) {
20813 +               nxi = get_nx_info(current_nx_info());
20814 +       } else if (id > 1) {
20815 +               spin_lock(&nx_info_hash_lock);
20816 +               nxi = get_nx_info(__lookup_nx_info(id));
20817 +               spin_unlock(&nx_info_hash_lock);
20818 +       }
20819 +       return nxi;
20820 +}
20821 +
20822 +/*     nid_is_hashed()
20823 +
20824 +       * verify that nid is still hashed                       */
20825 +
20826 +int nid_is_hashed(nid_t nid)
20827 +{
20828 +       int hashed;
20829 +
20830 +       spin_lock(&nx_info_hash_lock);
20831 +       hashed = (__lookup_nx_info(nid) != NULL);
20832 +       spin_unlock(&nx_info_hash_lock);
20833 +       return hashed;
20834 +}
20835 +
20836 +
20837 +#ifdef CONFIG_PROC_FS
20838 +
20839 +/*     get_nid_list()
20840 +
20841 +       * get a subset of hashed nids for proc
20842 +       * assumes size is at least one                          */
20843 +
20844 +int get_nid_list(int index, unsigned int *nids, int size)
20845 +{
20846 +       int hindex, nr_nids = 0;
20847 +
20848 +       /* only show current and children */
20849 +       if (!nx_check(0, VS_ADMIN | VS_WATCH)) {
20850 +               if (index > 0)
20851 +                       return 0;
20852 +               nids[nr_nids] = nx_current_nid();
20853 +               return 1;
20854 +       }
20855 +
20856 +       for (hindex = 0; hindex < NX_HASH_SIZE; hindex++) {
20857 +               struct hlist_head *head = &nx_info_hash[hindex];
20858 +               struct hlist_node *pos;
20859 +
20860 +               spin_lock(&nx_info_hash_lock);
20861 +               hlist_for_each(pos, head) {
20862 +                       struct nx_info *nxi;
20863 +
20864 +                       if (--index > 0)
20865 +                               continue;
20866 +
20867 +                       nxi = hlist_entry(pos, struct nx_info, nx_hlist);
20868 +                       nids[nr_nids] = nxi->nx_id;
20869 +                       if (++nr_nids >= size) {
20870 +                               spin_unlock(&nx_info_hash_lock);
20871 +                               goto out;
20872 +                       }
20873 +               }
20874 +               /* keep the lock time short */
20875 +               spin_unlock(&nx_info_hash_lock);
20876 +       }
20877 +out:
20878 +       return nr_nids;
20879 +}
20880 +#endif
20881 +
20882 +
20883 +/*
20884 + *     migrate task to new network
20885 + *     gets nxi, puts old_nxi on change
20886 + */
20887 +
20888 +int nx_migrate_task(struct task_struct *p, struct nx_info *nxi)
20889 +{
20890 +       struct nx_info *old_nxi;
20891 +       int ret = 0;
20892 +
20893 +       if (!p || !nxi)
20894 +               BUG();
20895 +
20896 +       vxdprintk(VXD_CBIT(nid, 5),
20897 +               "nx_migrate_task(%p,%p[#%d.%d.%d])",
20898 +               p, nxi, nxi->nx_id,
20899 +               atomic_read(&nxi->nx_usecnt),
20900 +               atomic_read(&nxi->nx_tasks));
20901 +
20902 +       if (nx_info_flags(nxi, NXF_INFO_PRIVATE, 0) &&
20903 +               !nx_info_flags(nxi, NXF_STATE_SETUP, 0))
20904 +               return -EACCES;
20905 +
20906 +       if (nx_info_state(nxi, NXS_SHUTDOWN))
20907 +               return -EFAULT;
20908 +
20909 +       /* maybe disallow this completely? */
20910 +       old_nxi = task_get_nx_info(p);
20911 +       if (old_nxi == nxi)
20912 +               goto out;
20913 +
20914 +       task_lock(p);
20915 +       if (old_nxi)
20916 +               clr_nx_info(&p->nx_info);
20917 +       claim_nx_info(nxi, p);
20918 +       set_nx_info(&p->nx_info, nxi);
20919 +       p->nid = nxi->nx_id;
20920 +       task_unlock(p);
20921 +
20922 +       vxdprintk(VXD_CBIT(nid, 5),
20923 +               "moved task %p into nxi:%p[#%d]",
20924 +               p, nxi, nxi->nx_id);
20925 +
20926 +       if (old_nxi)
20927 +               release_nx_info(old_nxi, p);
20928 +       ret = 0;
20929 +out:
20930 +       put_nx_info(old_nxi);
20931 +       return ret;
20932 +}
20933 +
20934 +
20935 +void nx_set_persistent(struct nx_info *nxi)
20936 +{
20937 +       vxdprintk(VXD_CBIT(nid, 6),
20938 +               "nx_set_persistent(%p[#%d])", nxi, nxi->nx_id);
20939 +
20940 +       get_nx_info(nxi);
20941 +       claim_nx_info(nxi, NULL);
20942 +}
20943 +
20944 +void nx_clear_persistent(struct nx_info *nxi)
20945 +{
20946 +       vxdprintk(VXD_CBIT(nid, 6),
20947 +               "nx_clear_persistent(%p[#%d])", nxi, nxi->nx_id);
20948 +
20949 +       release_nx_info(nxi, NULL);
20950 +       put_nx_info(nxi);
20951 +}
20952 +
20953 +void nx_update_persistent(struct nx_info *nxi)
20954 +{
20955 +       if (nx_info_flags(nxi, NXF_PERSISTENT, 0))
20956 +               nx_set_persistent(nxi);
20957 +       else
20958 +               nx_clear_persistent(nxi);
20959 +}
20960 +
20961 +/* vserver syscall commands below here */
20962 +
20963 +/* taks nid and nx_info functions */
20964 +
20965 +#include <asm/uaccess.h>
20966 +
20967 +
20968 +int vc_task_nid(uint32_t id)
20969 +{
20970 +       nid_t nid;
20971 +
20972 +       if (id) {
20973 +               struct task_struct *tsk;
20974 +
20975 +               rcu_read_lock();
20976 +               tsk = find_task_by_real_pid(id);
20977 +               nid = (tsk) ? tsk->nid : -ESRCH;
20978 +               rcu_read_unlock();
20979 +       } else
20980 +               nid = nx_current_nid();
20981 +       return nid;
20982 +}
20983 +
20984 +
20985 +int vc_nx_info(struct nx_info *nxi, void __user *data)
20986 +{
20987 +       struct vcmd_nx_info_v0 vc_data;
20988 +
20989 +       vc_data.nid = nxi->nx_id;
20990 +
20991 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20992 +               return -EFAULT;
20993 +       return 0;
20994 +}
20995 +
20996 +
20997 +/* network functions */
20998 +
20999 +int vc_net_create(uint32_t nid, void __user *data)
21000 +{
21001 +       struct vcmd_net_create vc_data = { .flagword = NXF_INIT_SET };
21002 +       struct nx_info *new_nxi;
21003 +       int ret;
21004 +
21005 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
21006 +               return -EFAULT;
21007 +
21008 +       if ((nid > MAX_S_CONTEXT) || (nid < 2))
21009 +               return -EINVAL;
21010 +
21011 +       new_nxi = __create_nx_info(nid);
21012 +       if (IS_ERR(new_nxi))
21013 +               return PTR_ERR(new_nxi);
21014 +
21015 +       /* initial flags */
21016 +       new_nxi->nx_flags = vc_data.flagword;
21017 +
21018 +       ret = -ENOEXEC;
21019 +       if (vs_net_change(new_nxi, VSC_NETUP))
21020 +               goto out;
21021 +
21022 +       ret = nx_migrate_task(current, new_nxi);
21023 +       if (ret)
21024 +               goto out;
21025 +
21026 +       /* return context id on success */
21027 +       ret = new_nxi->nx_id;
21028 +
21029 +       /* get a reference for persistent contexts */
21030 +       if ((vc_data.flagword & NXF_PERSISTENT))
21031 +               nx_set_persistent(new_nxi);
21032 +out:
21033 +       release_nx_info(new_nxi, NULL);
21034 +       put_nx_info(new_nxi);
21035 +       return ret;
21036 +}
21037 +
21038 +
21039 +int vc_net_migrate(struct nx_info *nxi, void __user *data)
21040 +{
21041 +       return nx_migrate_task(current, nxi);
21042 +}
21043 +
21044 +
21045 +
21046 +int do_add_v4_addr(struct nx_info *nxi, __be32 ip, __be32 ip2, __be32 mask,
21047 +       uint16_t type, uint16_t flags)
21048 +{
21049 +       struct nx_addr_v4 *nxa = &nxi->v4;
21050 +
21051 +       if (NX_IPV4(nxi)) {
21052 +               /* locate last entry */
21053 +               for (; nxa->next; nxa = nxa->next);
21054 +               nxa->next = __alloc_nx_addr_v4();
21055 +               nxa = nxa->next;
21056 +
21057 +               if (IS_ERR(nxa))
21058 +                       return PTR_ERR(nxa);
21059 +       }
21060 +
21061 +       if (nxi->v4.next)
21062 +               /* remove single ip for ip list */
21063 +               nxi->nx_flags &= ~NXF_SINGLE_IP;
21064 +
21065 +       nxa->ip[0].s_addr = ip;
21066 +       nxa->ip[1].s_addr = ip2;
21067 +       nxa->mask.s_addr = mask;
21068 +       nxa->type = type;
21069 +       nxa->flags = flags;
21070 +       return 0;
21071 +}
21072 +
21073 +int do_remove_v4_addr(struct nx_info *nxi, __be32 ip, __be32 ip2, __be32 mask,
21074 +       uint16_t type, uint16_t flags)
21075 +{
21076 +       struct nx_addr_v4 *nxa = &nxi->v4;
21077 +
21078 +       switch (type) {
21079 +/*     case NXA_TYPE_ADDR:
21080 +               break;          */
21081 +
21082 +       case NXA_TYPE_ANY:
21083 +               __dealloc_nx_addr_v4_all(xchg(&nxa->next, NULL));
21084 +               memset(nxa, 0, sizeof(*nxa));
21085 +               break;
21086 +
21087 +       default:
21088 +               return -EINVAL;
21089 +       }
21090 +       return 0;
21091 +}
21092 +
21093 +
21094 +int vc_net_add(struct nx_info *nxi, void __user *data)
21095 +{
21096 +       struct vcmd_net_addr_v0 vc_data;
21097 +       int index, ret = 0;
21098 +
21099 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
21100 +               return -EFAULT;
21101 +
21102 +       switch (vc_data.type) {
21103 +       case NXA_TYPE_IPV4:
21104 +               if ((vc_data.count < 1) || (vc_data.count > 4))
21105 +                       return -EINVAL;
21106 +
21107 +               index = 0;
21108 +               while (index < vc_data.count) {
21109 +                       ret = do_add_v4_addr(nxi, vc_data.ip[index].s_addr, 0,
21110 +                               vc_data.mask[index].s_addr, NXA_TYPE_ADDR, 0);
21111 +                       if (ret)
21112 +                               return ret;
21113 +                       index++;
21114 +               }
21115 +               ret = index;
21116 +               break;
21117 +
21118 +       case NXA_TYPE_IPV4|NXA_MOD_BCAST:
21119 +               nxi->v4_bcast = vc_data.ip[0];
21120 +               ret = 1;
21121 +               break;
21122 +
21123 +       case NXA_TYPE_IPV4|NXA_MOD_LBACK:
21124 +               nxi->v4_lback = vc_data.ip[0];
21125 +               ret = 1;
21126 +               break;
21127 +
21128 +       default:
21129 +               ret = -EINVAL;
21130 +               break;
21131 +       }
21132 +       return ret;
21133 +}
21134 +
21135 +int vc_net_remove(struct nx_info *nxi, void __user *data)
21136 +{
21137 +       struct vcmd_net_addr_v0 vc_data;
21138 +
21139 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
21140 +               return -EFAULT;
21141 +
21142 +       switch (vc_data.type) {
21143 +       case NXA_TYPE_ANY:
21144 +               __dealloc_nx_addr_v4_all(xchg(&nxi->v4.next, NULL));
21145 +               memset(&nxi->v4, 0, sizeof(nxi->v4));
21146 +               break;
21147 +
21148 +       default:
21149 +               return -EINVAL;
21150 +       }
21151 +       return 0;
21152 +}
21153 +
21154 +
21155 +int vc_net_add_ipv4_v1(struct nx_info *nxi, void __user *data)
21156 +{
21157 +       struct vcmd_net_addr_ipv4_v1 vc_data;
21158 +
21159 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
21160 +               return -EFAULT;
21161 +
21162 +       switch (vc_data.type) {
21163 +       case NXA_TYPE_ADDR:
21164 +       case NXA_TYPE_MASK:
21165 +               return do_add_v4_addr(nxi, vc_data.ip.s_addr, 0,
21166 +                       vc_data.mask.s_addr, vc_data.type, vc_data.flags);
21167 +
21168 +       case NXA_TYPE_ADDR | NXA_MOD_BCAST:
21169 +               nxi->v4_bcast = vc_data.ip;
21170 +               break;
21171 +
21172 +       case NXA_TYPE_ADDR | NXA_MOD_LBACK:
21173 +               nxi->v4_lback = vc_data.ip;
21174 +               break;
21175 +
21176 +       default:
21177 +               return -EINVAL;
21178 +       }
21179 +       return 0;
21180 +}
21181 +
21182 +int vc_net_add_ipv4(struct nx_info *nxi, void __user *data)
21183 +{
21184 +       struct vcmd_net_addr_ipv4_v2 vc_data;
21185 +
21186 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
21187 +               return -EFAULT;
21188 +
21189 +       switch (vc_data.type) {
21190 +       case NXA_TYPE_ADDR:
21191 +       case NXA_TYPE_MASK:
21192 +       case NXA_TYPE_RANGE:
21193 +               return do_add_v4_addr(nxi, vc_data.ip.s_addr, vc_data.ip2.s_addr,
21194 +                       vc_data.mask.s_addr, vc_data.type, vc_data.flags);
21195 +
21196 +       case NXA_TYPE_ADDR | NXA_MOD_BCAST:
21197 +               nxi->v4_bcast = vc_data.ip;
21198 +               break;
21199 +
21200 +       case NXA_TYPE_ADDR | NXA_MOD_LBACK:
21201 +               nxi->v4_lback = vc_data.ip;
21202 +               break;
21203 +
21204 +       default:
21205 +               return -EINVAL;
21206 +       }
21207 +       return 0;
21208 +}
21209 +
21210 +int vc_net_rem_ipv4_v1(struct nx_info *nxi, void __user *data)
21211 +{
21212 +       struct vcmd_net_addr_ipv4_v1 vc_data;
21213 +
21214 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
21215 +               return -EFAULT;
21216 +
21217 +       return do_remove_v4_addr(nxi, vc_data.ip.s_addr, 0,
21218 +               vc_data.mask.s_addr, vc_data.type, vc_data.flags);
21219 +}
21220 +
21221 +int vc_net_rem_ipv4(struct nx_info *nxi, void __user *data)
21222 +{
21223 +       struct vcmd_net_addr_ipv4_v2 vc_data;
21224 +
21225 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
21226 +               return -EFAULT;
21227 +
21228 +       return do_remove_v4_addr(nxi, vc_data.ip.s_addr, vc_data.ip2.s_addr,
21229 +               vc_data.mask.s_addr, vc_data.type, vc_data.flags);
21230 +}
21231 +
21232 +#ifdef CONFIG_IPV6
21233 +
21234 +int do_add_v6_addr(struct nx_info *nxi,
21235 +       struct in6_addr *ip, struct in6_addr *mask,
21236 +       uint32_t prefix, uint16_t type, uint16_t flags)
21237 +{
21238 +       struct nx_addr_v6 *nxa = &nxi->v6;
21239 +
21240 +       if (NX_IPV6(nxi)) {
21241 +               /* locate last entry */
21242 +               for (; nxa->next; nxa = nxa->next);
21243 +               nxa->next = __alloc_nx_addr_v6();
21244 +               nxa = nxa->next;
21245 +
21246 +               if (IS_ERR(nxa))
21247 +                       return PTR_ERR(nxa);
21248 +       }
21249 +
21250 +       nxa->ip = *ip;
21251 +       nxa->mask = *mask;
21252 +       nxa->prefix = prefix;
21253 +       nxa->type = type;
21254 +       nxa->flags = flags;
21255 +       return 0;
21256 +}
21257 +
21258 +
21259 +int vc_net_add_ipv6(struct nx_info *nxi, void __user *data)
21260 +{
21261 +       struct vcmd_net_addr_ipv6_v1 vc_data;
21262 +
21263 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
21264 +               return -EFAULT;
21265 +
21266 +       switch (vc_data.type) {
21267 +       case NXA_TYPE_ADDR:
21268 +               memset(&vc_data.mask, ~0, sizeof(vc_data.mask));
21269 +               /* fallthrough */
21270 +       case NXA_TYPE_MASK:
21271 +               return do_add_v6_addr(nxi, &vc_data.ip, &vc_data.mask,
21272 +                       vc_data.prefix, vc_data.type, vc_data.flags);
21273 +       default:
21274 +               return -EINVAL;
21275 +       }
21276 +       return 0;
21277 +}
21278 +
21279 +int vc_net_remove_ipv6(struct nx_info *nxi, void __user *data)
21280 +{
21281 +       struct vcmd_net_addr_ipv6_v1 vc_data;
21282 +
21283 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
21284 +               return -EFAULT;
21285 +
21286 +       switch (vc_data.type) {
21287 +       case NXA_TYPE_ANY:
21288 +               __dealloc_nx_addr_v6_all(xchg(&nxi->v6.next, NULL));
21289 +               memset(&nxi->v6, 0, sizeof(nxi->v6));
21290 +               break;
21291 +
21292 +       default:
21293 +               return -EINVAL;
21294 +       }
21295 +       return 0;
21296 +}
21297 +
21298 +#endif /* CONFIG_IPV6 */
21299 +
21300 +
21301 +int vc_get_nflags(struct nx_info *nxi, void __user *data)
21302 +{
21303 +       struct vcmd_net_flags_v0 vc_data;
21304 +
21305 +       vc_data.flagword = nxi->nx_flags;
21306 +
21307 +       /* special STATE flag handling */
21308 +       vc_data.mask = vs_mask_flags(~0ULL, nxi->nx_flags, NXF_ONE_TIME);
21309 +
21310 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21311 +               return -EFAULT;
21312 +       return 0;
21313 +}
21314 +
21315 +int vc_set_nflags(struct nx_info *nxi, void __user *data)
21316 +{
21317 +       struct vcmd_net_flags_v0 vc_data;
21318 +       uint64_t mask, trigger;
21319 +
21320 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21321 +               return -EFAULT;
21322 +
21323 +       /* special STATE flag handling */
21324 +       mask = vs_mask_mask(vc_data.mask, nxi->nx_flags, NXF_ONE_TIME);
21325 +       trigger = (mask & nxi->nx_flags) ^ (mask & vc_data.flagword);
21326 +
21327 +       nxi->nx_flags = vs_mask_flags(nxi->nx_flags,
21328 +               vc_data.flagword, mask);
21329 +       if (trigger & NXF_PERSISTENT)
21330 +               nx_update_persistent(nxi);
21331 +
21332 +       return 0;
21333 +}
21334 +
21335 +int vc_get_ncaps(struct nx_info *nxi, void __user *data)
21336 +{
21337 +       struct vcmd_net_caps_v0 vc_data;
21338 +
21339 +       vc_data.ncaps = nxi->nx_ncaps;
21340 +       vc_data.cmask = ~0ULL;
21341 +
21342 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21343 +               return -EFAULT;
21344 +       return 0;
21345 +}
21346 +
21347 +int vc_set_ncaps(struct nx_info *nxi, void __user *data)
21348 +{
21349 +       struct vcmd_net_caps_v0 vc_data;
21350 +
21351 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21352 +               return -EFAULT;
21353 +
21354 +       nxi->nx_ncaps = vs_mask_flags(nxi->nx_ncaps,
21355 +               vc_data.ncaps, vc_data.cmask);
21356 +       return 0;
21357 +}
21358 +
21359 +
21360 +#include <linux/module.h>
21361 +
21362 +module_init(init_network);
21363 +
21364 +EXPORT_SYMBOL_GPL(free_nx_info);
21365 +EXPORT_SYMBOL_GPL(unhash_nx_info);
21366 +
21367 diff -NurpP --minimal linux-3.0.25/kernel/vserver/proc.c linux-3.0.25-vs2.3.2.3/kernel/vserver/proc.c
21368 --- linux-3.0.25/kernel/vserver/proc.c  1970-01-01 01:00:00.000000000 +0100
21369 +++ linux-3.0.25-vs2.3.2.3/kernel/vserver/proc.c        2011-08-01 19:57:21.000000000 +0200
21370 @@ -0,0 +1,1103 @@
21371 +/*
21372 + *  linux/kernel/vserver/proc.c
21373 + *
21374 + *  Virtual Context Support
21375 + *
21376 + *  Copyright (C) 2003-2011  Herbert Pötzl
21377 + *
21378 + *  V0.01  basic structure
21379 + *  V0.02  adaptation vs1.3.0
21380 + *  V0.03  proc permissions
21381 + *  V0.04  locking/generic
21382 + *  V0.05  next generation procfs
21383 + *  V0.06  inode validation
21384 + *  V0.07  generic rewrite vid
21385 + *  V0.08  remove inode type
21386 + *  V0.09  added u/wmask info
21387 + *
21388 + */
21389 +
21390 +#include <linux/proc_fs.h>
21391 +#include <linux/fs_struct.h>
21392 +#include <linux/mount.h>
21393 +#include <asm/unistd.h>
21394 +
21395 +#include <linux/vs_context.h>
21396 +#include <linux/vs_network.h>
21397 +#include <linux/vs_cvirt.h>
21398 +
21399 +#include <linux/in.h>
21400 +#include <linux/inetdevice.h>
21401 +#include <linux/vs_inet.h>
21402 +#include <linux/vs_inet6.h>
21403 +
21404 +#include <linux/vserver/global.h>
21405 +
21406 +#include "cvirt_proc.h"
21407 +#include "cacct_proc.h"
21408 +#include "limit_proc.h"
21409 +#include "sched_proc.h"
21410 +#include "vci_config.h"
21411 +
21412 +
21413 +static inline char *print_cap_t(char *buffer, kernel_cap_t *c)
21414 +{
21415 +       unsigned __capi;
21416 +
21417 +       CAP_FOR_EACH_U32(__capi) {
21418 +               buffer += sprintf(buffer, "%08x",
21419 +                       c->cap[(_KERNEL_CAPABILITY_U32S-1) - __capi]);
21420 +       }
21421 +       return buffer;
21422 +}
21423 +
21424 +
21425 +static struct proc_dir_entry *proc_virtual;
21426 +
21427 +static struct proc_dir_entry *proc_virtnet;
21428 +
21429 +
21430 +/* first the actual feeds */
21431 +
21432 +
21433 +static int proc_vci(char *buffer)
21434 +{
21435 +       return sprintf(buffer,
21436 +               "VCIVersion:\t%04x:%04x\n"
21437 +               "VCISyscall:\t%d\n"
21438 +               "VCIKernel:\t%08x\n",
21439 +               VCI_VERSION >> 16,
21440 +               VCI_VERSION & 0xFFFF,
21441 +               __NR_vserver,
21442 +               vci_kernel_config());
21443 +}
21444 +
21445 +static int proc_virtual_info(char *buffer)
21446 +{
21447 +       return proc_vci(buffer);
21448 +}
21449 +
21450 +static int proc_virtual_status(char *buffer)
21451 +{
21452 +       return sprintf(buffer,
21453 +               "#CTotal:\t%d\n"
21454 +               "#CActive:\t%d\n"
21455 +               "#NSProxy:\t%d\t%d %d %d %d %d %d\n"
21456 +               "#InitTask:\t%d\t%d %d\n",
21457 +               atomic_read(&vx_global_ctotal),
21458 +               atomic_read(&vx_global_cactive),
21459 +               atomic_read(&vs_global_nsproxy),
21460 +               atomic_read(&vs_global_fs),
21461 +               atomic_read(&vs_global_mnt_ns),
21462 +               atomic_read(&vs_global_uts_ns),
21463 +               atomic_read(&nr_ipc_ns),
21464 +               atomic_read(&vs_global_user_ns),
21465 +               atomic_read(&vs_global_pid_ns),
21466 +               atomic_read(&init_task.usage),
21467 +               atomic_read(&init_task.nsproxy->count),
21468 +               init_task.fs->users);
21469 +}
21470 +
21471 +
21472 +int proc_vxi_info(struct vx_info *vxi, char *buffer)
21473 +{
21474 +       int length;
21475 +
21476 +       length = sprintf(buffer,
21477 +               "ID:\t%d\n"
21478 +               "Info:\t%p\n"
21479 +               "Init:\t%d\n"
21480 +               "OOM:\t%lld\n",
21481 +               vxi->vx_id,
21482 +               vxi,
21483 +               vxi->vx_initpid,
21484 +               vxi->vx_badness_bias);
21485 +       return length;
21486 +}
21487 +
21488 +int proc_vxi_status(struct vx_info *vxi, char *buffer)
21489 +{
21490 +       char *orig = buffer;
21491 +
21492 +       buffer += sprintf(buffer,
21493 +               "UseCnt:\t%d\n"
21494 +               "Tasks:\t%d\n"
21495 +               "Flags:\t%016llx\n",
21496 +               atomic_read(&vxi->vx_usecnt),
21497 +               atomic_read(&vxi->vx_tasks),
21498 +               (unsigned long long)vxi->vx_flags);
21499 +
21500 +       buffer += sprintf(buffer, "BCaps:\t");
21501 +       buffer = print_cap_t(buffer, &vxi->vx_bcaps);
21502 +       buffer += sprintf(buffer, "\n");
21503 +
21504 +       buffer += sprintf(buffer,
21505 +               "CCaps:\t%016llx\n"
21506 +               "Umask:\t%16llx\n"
21507 +               "Wmask:\t%16llx\n"
21508 +               "Spaces:\t%08lx %08lx\n",
21509 +               (unsigned long long)vxi->vx_ccaps,
21510 +               (unsigned long long)vxi->vx_umask,
21511 +               (unsigned long long)vxi->vx_wmask,
21512 +               vxi->space[0].vx_nsmask, vxi->space[1].vx_nsmask);
21513 +       return buffer - orig;
21514 +}
21515 +
21516 +int proc_vxi_limit(struct vx_info *vxi, char *buffer)
21517 +{
21518 +       return vx_info_proc_limit(&vxi->limit, buffer);
21519 +}
21520 +
21521 +int proc_vxi_sched(struct vx_info *vxi, char *buffer)
21522 +{
21523 +       int cpu, length;
21524 +
21525 +       length = vx_info_proc_sched(&vxi->sched, buffer);
21526 +       for_each_online_cpu(cpu) {
21527 +               length += vx_info_proc_sched_pc(
21528 +                       &vx_per_cpu(vxi, sched_pc, cpu),
21529 +                       buffer + length, cpu);
21530 +       }
21531 +       return length;
21532 +}
21533 +
21534 +int proc_vxi_nsproxy0(struct vx_info *vxi, char *buffer)
21535 +{
21536 +       return vx_info_proc_nsproxy(vxi->space[0].vx_nsproxy, buffer);
21537 +}
21538 +
21539 +int proc_vxi_nsproxy1(struct vx_info *vxi, char *buffer)
21540 +{
21541 +       return vx_info_proc_nsproxy(vxi->space[1].vx_nsproxy, buffer);
21542 +}
21543 +
21544 +int proc_vxi_cvirt(struct vx_info *vxi, char *buffer)
21545 +{
21546 +       int cpu, length;
21547 +
21548 +       vx_update_load(vxi);
21549 +       length = vx_info_proc_cvirt(&vxi->cvirt, buffer);
21550 +       for_each_online_cpu(cpu) {
21551 +               length += vx_info_proc_cvirt_pc(
21552 +                       &vx_per_cpu(vxi, cvirt_pc, cpu),
21553 +                       buffer + length, cpu);
21554 +       }
21555 +       return length;
21556 +}
21557 +
21558 +int proc_vxi_cacct(struct vx_info *vxi, char *buffer)
21559 +{
21560 +       return vx_info_proc_cacct(&vxi->cacct, buffer);
21561 +}
21562 +
21563 +
21564 +static int proc_virtnet_info(char *buffer)
21565 +{
21566 +       return proc_vci(buffer);
21567 +}
21568 +
21569 +static int proc_virtnet_status(char *buffer)
21570 +{
21571 +       return sprintf(buffer,
21572 +               "#CTotal:\t%d\n"
21573 +               "#CActive:\t%d\n",
21574 +               atomic_read(&nx_global_ctotal),
21575 +               atomic_read(&nx_global_cactive));
21576 +}
21577 +
21578 +int proc_nxi_info(struct nx_info *nxi, char *buffer)
21579 +{
21580 +       struct nx_addr_v4 *v4a;
21581 +#ifdef CONFIG_IPV6
21582 +       struct nx_addr_v6 *v6a;
21583 +#endif
21584 +       int length, i;
21585 +
21586 +       length = sprintf(buffer,
21587 +               "ID:\t%d\n"
21588 +               "Info:\t%p\n"
21589 +               "Bcast:\t" NIPQUAD_FMT "\n"
21590 +               "Lback:\t" NIPQUAD_FMT "\n",
21591 +               nxi->nx_id,
21592 +               nxi,
21593 +               NIPQUAD(nxi->v4_bcast.s_addr),
21594 +               NIPQUAD(nxi->v4_lback.s_addr));
21595 +
21596 +       if (!NX_IPV4(nxi))
21597 +               goto skip_v4;
21598 +       for (i = 0, v4a = &nxi->v4; v4a; i++, v4a = v4a->next)
21599 +               length += sprintf(buffer + length, "%d:\t" NXAV4_FMT "\n",
21600 +                       i, NXAV4(v4a));
21601 +skip_v4:
21602 +#ifdef CONFIG_IPV6
21603 +       if (!NX_IPV6(nxi))
21604 +               goto skip_v6;
21605 +       for (i = 0, v6a = &nxi->v6; v6a; i++, v6a = v6a->next)
21606 +               length += sprintf(buffer + length, "%d:\t" NXAV6_FMT "\n",
21607 +                       i, NXAV6(v6a));
21608 +skip_v6:
21609 +#endif
21610 +       return length;
21611 +}
21612 +
21613 +int proc_nxi_status(struct nx_info *nxi, char *buffer)
21614 +{
21615 +       int length;
21616 +
21617 +       length = sprintf(buffer,
21618 +               "UseCnt:\t%d\n"
21619 +               "Tasks:\t%d\n"
21620 +               "Flags:\t%016llx\n"
21621 +               "NCaps:\t%016llx\n",
21622 +               atomic_read(&nxi->nx_usecnt),
21623 +               atomic_read(&nxi->nx_tasks),
21624 +               (unsigned long long)nxi->nx_flags,
21625 +               (unsigned long long)nxi->nx_ncaps);
21626 +       return length;
21627 +}
21628 +
21629 +
21630 +
21631 +/* here the inode helpers */
21632 +
21633 +struct vs_entry {
21634 +       int len;
21635 +       char *name;
21636 +       mode_t mode;
21637 +       struct inode_operations *iop;
21638 +       struct file_operations *fop;
21639 +       union proc_op op;
21640 +};
21641 +
21642 +static struct inode *vs_proc_make_inode(struct super_block *sb, struct vs_entry *p)
21643 +{
21644 +       struct inode *inode = new_inode(sb);
21645 +
21646 +       if (!inode)
21647 +               goto out;
21648 +
21649 +       inode->i_mode = p->mode;
21650 +       if (p->iop)
21651 +               inode->i_op = p->iop;
21652 +       if (p->fop)
21653 +               inode->i_fop = p->fop;
21654 +
21655 +       inode->i_nlink = (p->mode & S_IFDIR) ? 2 : 1;
21656 +       inode->i_flags |= S_IMMUTABLE;
21657 +
21658 +       inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
21659 +
21660 +       inode->i_uid = 0;
21661 +       inode->i_gid = 0;
21662 +       inode->i_tag = 0;
21663 +out:
21664 +       return inode;
21665 +}
21666 +
21667 +static struct dentry *vs_proc_instantiate(struct inode *dir,
21668 +       struct dentry *dentry, int id, void *ptr)
21669 +{
21670 +       struct vs_entry *p = ptr;
21671 +       struct inode *inode = vs_proc_make_inode(dir->i_sb, p);
21672 +       struct dentry *error = ERR_PTR(-EINVAL);
21673 +
21674 +       if (!inode)
21675 +               goto out;
21676 +
21677 +       PROC_I(inode)->op = p->op;
21678 +       PROC_I(inode)->fd = id;
21679 +       d_add(dentry, inode);
21680 +       error = NULL;
21681 +out:
21682 +       return error;
21683 +}
21684 +
21685 +/* Lookups */
21686 +
21687 +typedef struct dentry *instantiate_t(struct inode *, struct dentry *, int, void *);
21688 +
21689 +/*
21690 + * Fill a directory entry.
21691 + *
21692 + * If possible create the dcache entry and derive our inode number and
21693 + * file type from dcache entry.
21694 + *
21695 + * Since all of the proc inode numbers are dynamically generated, the inode
21696 + * numbers do not exist until the inode is cache.  This means creating the
21697 + * the dcache entry in readdir is necessary to keep the inode numbers
21698 + * reported by readdir in sync with the inode numbers reported
21699 + * by stat.
21700 + */
21701 +static int proc_fill_cache(struct file *filp, void *dirent, filldir_t filldir,
21702 +       char *name, int len, instantiate_t instantiate, int id, void *ptr)
21703 +{
21704 +       struct dentry *child, *dir = filp->f_dentry;
21705 +       struct inode *inode;
21706 +       struct qstr qname;
21707 +       ino_t ino = 0;
21708 +       unsigned type = DT_UNKNOWN;
21709 +
21710 +       qname.name = name;
21711 +       qname.len  = len;
21712 +       qname.hash = full_name_hash(name, len);
21713 +
21714 +       child = d_lookup(dir, &qname);
21715 +       if (!child) {
21716 +               struct dentry *new;
21717 +               new = d_alloc(dir, &qname);
21718 +               if (new) {
21719 +                       child = instantiate(dir->d_inode, new, id, ptr);
21720 +                       if (child)
21721 +                               dput(new);
21722 +                       else
21723 +                               child = new;
21724 +               }
21725 +       }
21726 +       if (!child || IS_ERR(child) || !child->d_inode)
21727 +               goto end_instantiate;
21728 +       inode = child->d_inode;
21729 +       if (inode) {
21730 +               ino = inode->i_ino;
21731 +               type = inode->i_mode >> 12;
21732 +       }
21733 +       dput(child);
21734 +end_instantiate:
21735 +       if (!ino)
21736 +               ino = find_inode_number(dir, &qname);
21737 +       if (!ino)
21738 +               ino = 1;
21739 +       return filldir(dirent, name, len, filp->f_pos, ino, type);
21740 +}
21741 +
21742 +
21743 +
21744 +/* get and revalidate vx_info/xid */
21745 +
21746 +static inline
21747 +struct vx_info *get_proc_vx_info(struct inode *inode)
21748 +{
21749 +       return lookup_vx_info(PROC_I(inode)->fd);
21750 +}
21751 +
21752 +static int proc_xid_revalidate(struct dentry *dentry, struct nameidata *nd)
21753 +{
21754 +       struct inode *inode = dentry->d_inode;
21755 +       xid_t xid = PROC_I(inode)->fd;
21756 +
21757 +       if (!xid || xid_is_hashed(xid))
21758 +               return 1;
21759 +       d_drop(dentry);
21760 +       return 0;
21761 +}
21762 +
21763 +
21764 +/* get and revalidate nx_info/nid */
21765 +
21766 +static int proc_nid_revalidate(struct dentry *dentry, struct nameidata *nd)
21767 +{
21768 +       struct inode *inode = dentry->d_inode;
21769 +       nid_t nid = PROC_I(inode)->fd;
21770 +
21771 +       if (!nid || nid_is_hashed(nid))
21772 +               return 1;
21773 +       d_drop(dentry);
21774 +       return 0;
21775 +}
21776 +
21777 +
21778 +
21779 +#define PROC_BLOCK_SIZE (PAGE_SIZE - 1024)
21780 +
21781 +static ssize_t proc_vs_info_read(struct file *file, char __user *buf,
21782 +                         size_t count, loff_t *ppos)
21783 +{
21784 +       struct inode *inode = file->f_dentry->d_inode;
21785 +       unsigned long page;
21786 +       ssize_t length = 0;
21787 +
21788 +       if (count > PROC_BLOCK_SIZE)
21789 +               count = PROC_BLOCK_SIZE;
21790 +
21791 +       /* fade that out as soon as stable */
21792 +       WARN_ON(PROC_I(inode)->fd);
21793 +
21794 +       if (!(page = __get_free_page(GFP_KERNEL)))
21795 +               return -ENOMEM;
21796 +
21797 +       BUG_ON(!PROC_I(inode)->op.proc_vs_read);
21798 +       length = PROC_I(inode)->op.proc_vs_read((char *)page);
21799 +
21800 +       if (length >= 0)
21801 +               length = simple_read_from_buffer(buf, count, ppos,
21802 +                       (char *)page, length);
21803 +
21804 +       free_page(page);
21805 +       return length;
21806 +}
21807 +
21808 +static ssize_t proc_vx_info_read(struct file *file, char __user *buf,
21809 +                         size_t count, loff_t *ppos)
21810 +{
21811 +       struct inode *inode = file->f_dentry->d_inode;
21812 +       struct vx_info *vxi = NULL;
21813 +       xid_t xid = PROC_I(inode)->fd;
21814 +       unsigned long page;
21815 +       ssize_t length = 0;
21816 +
21817 +       if (count > PROC_BLOCK_SIZE)
21818 +               count = PROC_BLOCK_SIZE;
21819 +
21820 +       /* fade that out as soon as stable */
21821 +       WARN_ON(!xid);
21822 +       vxi = lookup_vx_info(xid);
21823 +       if (!vxi)
21824 +               goto out;
21825 +
21826 +       length = -ENOMEM;
21827 +       if (!(page = __get_free_page(GFP_KERNEL)))
21828 +               goto out_put;
21829 +
21830 +       BUG_ON(!PROC_I(inode)->op.proc_vxi_read);
21831 +       length = PROC_I(inode)->op.proc_vxi_read(vxi, (char *)page);
21832 +
21833 +       if (length >= 0)
21834 +               length = simple_read_from_buffer(buf, count, ppos,
21835 +                       (char *)page, length);
21836 +
21837 +       free_page(page);
21838 +out_put:
21839 +       put_vx_info(vxi);
21840 +out:
21841 +       return length;
21842 +}
21843 +
21844 +static ssize_t proc_nx_info_read(struct file *file, char __user *buf,
21845 +                         size_t count, loff_t *ppos)
21846 +{
21847 +       struct inode *inode = file->f_dentry->d_inode;
21848 +       struct nx_info *nxi = NULL;
21849 +       nid_t nid = PROC_I(inode)->fd;
21850 +       unsigned long page;
21851 +       ssize_t length = 0;
21852 +
21853 +       if (count > PROC_BLOCK_SIZE)
21854 +               count = PROC_BLOCK_SIZE;
21855 +
21856 +       /* fade that out as soon as stable */
21857 +       WARN_ON(!nid);
21858 +       nxi = lookup_nx_info(nid);
21859 +       if (!nxi)
21860 +               goto out;
21861 +
21862 +       length = -ENOMEM;
21863 +       if (!(page = __get_free_page(GFP_KERNEL)))
21864 +               goto out_put;
21865 +
21866 +       BUG_ON(!PROC_I(inode)->op.proc_nxi_read);
21867 +       length = PROC_I(inode)->op.proc_nxi_read(nxi, (char *)page);
21868 +
21869 +       if (length >= 0)
21870 +               length = simple_read_from_buffer(buf, count, ppos,
21871 +                       (char *)page, length);
21872 +
21873 +       free_page(page);
21874 +out_put:
21875 +       put_nx_info(nxi);
21876 +out:
21877 +       return length;
21878 +}
21879 +
21880 +
21881 +
21882 +/* here comes the lower level */
21883 +
21884 +
21885 +#define NOD(NAME, MODE, IOP, FOP, OP) {        \
21886 +       .len  = sizeof(NAME) - 1,       \
21887 +       .name = (NAME),                 \
21888 +       .mode = MODE,                   \
21889 +       .iop  = IOP,                    \
21890 +       .fop  = FOP,                    \
21891 +       .op   = OP,                     \
21892 +}
21893 +
21894 +
21895 +#define DIR(NAME, MODE, OTYPE)                         \
21896 +       NOD(NAME, (S_IFDIR | (MODE)),                   \
21897 +               &proc_ ## OTYPE ## _inode_operations,   \
21898 +               &proc_ ## OTYPE ## _file_operations, { } )
21899 +
21900 +#define INF(NAME, MODE, OTYPE)                         \
21901 +       NOD(NAME, (S_IFREG | (MODE)), NULL,             \
21902 +               &proc_vs_info_file_operations,          \
21903 +               { .proc_vs_read = &proc_##OTYPE } )
21904 +
21905 +#define VINF(NAME, MODE, OTYPE)                                \
21906 +       NOD(NAME, (S_IFREG | (MODE)), NULL,             \
21907 +               &proc_vx_info_file_operations,          \
21908 +               { .proc_vxi_read = &proc_##OTYPE } )
21909 +
21910 +#define NINF(NAME, MODE, OTYPE)                                \
21911 +       NOD(NAME, (S_IFREG | (MODE)), NULL,             \
21912 +               &proc_nx_info_file_operations,          \
21913 +               { .proc_nxi_read = &proc_##OTYPE } )
21914 +
21915 +
21916 +static struct file_operations proc_vs_info_file_operations = {
21917 +       .read =         proc_vs_info_read,
21918 +};
21919 +
21920 +static struct file_operations proc_vx_info_file_operations = {
21921 +       .read =         proc_vx_info_read,
21922 +};
21923 +
21924 +static struct dentry_operations proc_xid_dentry_operations = {
21925 +       .d_revalidate = proc_xid_revalidate,
21926 +};
21927 +
21928 +static struct vs_entry vx_base_stuff[] = {
21929 +       VINF("info",    S_IRUGO, vxi_info),
21930 +       VINF("status",  S_IRUGO, vxi_status),
21931 +       VINF("limit",   S_IRUGO, vxi_limit),
21932 +       VINF("sched",   S_IRUGO, vxi_sched),
21933 +       VINF("nsproxy", S_IRUGO, vxi_nsproxy0),
21934 +       VINF("nsproxy1",S_IRUGO, vxi_nsproxy1),
21935 +       VINF("cvirt",   S_IRUGO, vxi_cvirt),
21936 +       VINF("cacct",   S_IRUGO, vxi_cacct),
21937 +       {}
21938 +};
21939 +
21940 +
21941 +
21942 +
21943 +static struct dentry *proc_xid_instantiate(struct inode *dir,
21944 +       struct dentry *dentry, int id, void *ptr)
21945 +{
21946 +       dentry->d_op = &proc_xid_dentry_operations;
21947 +       return vs_proc_instantiate(dir, dentry, id, ptr);
21948 +}
21949 +
21950 +static struct dentry *proc_xid_lookup(struct inode *dir,
21951 +       struct dentry *dentry, struct nameidata *nd)
21952 +{
21953 +       struct vs_entry *p = vx_base_stuff;
21954 +       struct dentry *error = ERR_PTR(-ENOENT);
21955 +
21956 +       for (; p->name; p++) {
21957 +               if (p->len != dentry->d_name.len)
21958 +                       continue;
21959 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
21960 +                       break;
21961 +       }
21962 +       if (!p->name)
21963 +               goto out;
21964 +
21965 +       error = proc_xid_instantiate(dir, dentry, PROC_I(dir)->fd, p);
21966 +out:
21967 +       return error;
21968 +}
21969 +
21970 +static int proc_xid_readdir(struct file *filp,
21971 +       void *dirent, filldir_t filldir)
21972 +{
21973 +       struct dentry *dentry = filp->f_dentry;
21974 +       struct inode *inode = dentry->d_inode;
21975 +       struct vs_entry *p = vx_base_stuff;
21976 +       int size = sizeof(vx_base_stuff) / sizeof(struct vs_entry);
21977 +       int pos, index;
21978 +       u64 ino;
21979 +
21980 +       pos = filp->f_pos;
21981 +       switch (pos) {
21982 +       case 0:
21983 +               ino = inode->i_ino;
21984 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
21985 +                       goto out;
21986 +               pos++;
21987 +               /* fall through */
21988 +       case 1:
21989 +               ino = parent_ino(dentry);
21990 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
21991 +                       goto out;
21992 +               pos++;
21993 +               /* fall through */
21994 +       default:
21995 +               index = pos - 2;
21996 +               if (index >= size)
21997 +                       goto out;
21998 +               for (p += index; p->name; p++) {
21999 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
22000 +                               vs_proc_instantiate, PROC_I(inode)->fd, p))
22001 +                               goto out;
22002 +                       pos++;
22003 +               }
22004 +       }
22005 +out:
22006 +       filp->f_pos = pos;
22007 +       return 1;
22008 +}
22009 +
22010 +
22011 +
22012 +static struct file_operations proc_nx_info_file_operations = {
22013 +       .read =         proc_nx_info_read,
22014 +};
22015 +
22016 +static struct dentry_operations proc_nid_dentry_operations = {
22017 +       .d_revalidate = proc_nid_revalidate,
22018 +};
22019 +
22020 +static struct vs_entry nx_base_stuff[] = {
22021 +       NINF("info",    S_IRUGO, nxi_info),
22022 +       NINF("status",  S_IRUGO, nxi_status),
22023 +       {}
22024 +};
22025 +
22026 +
22027 +static struct dentry *proc_nid_instantiate(struct inode *dir,
22028 +       struct dentry *dentry, int id, void *ptr)
22029 +{
22030 +       dentry->d_op = &proc_nid_dentry_operations;
22031 +       return vs_proc_instantiate(dir, dentry, id, ptr);
22032 +}
22033 +
22034 +static struct dentry *proc_nid_lookup(struct inode *dir,
22035 +       struct dentry *dentry, struct nameidata *nd)
22036 +{
22037 +       struct vs_entry *p = nx_base_stuff;
22038 +       struct dentry *error = ERR_PTR(-ENOENT);
22039 +
22040 +       for (; p->name; p++) {
22041 +               if (p->len != dentry->d_name.len)
22042 +                       continue;
22043 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
22044 +                       break;
22045 +       }
22046 +       if (!p->name)
22047 +               goto out;
22048 +
22049 +       error = proc_nid_instantiate(dir, dentry, PROC_I(dir)->fd, p);
22050 +out:
22051 +       return error;
22052 +}
22053 +
22054 +static int proc_nid_readdir(struct file *filp,
22055 +       void *dirent, filldir_t filldir)
22056 +{
22057 +       struct dentry *dentry = filp->f_dentry;
22058 +       struct inode *inode = dentry->d_inode;
22059 +       struct vs_entry *p = nx_base_stuff;
22060 +       int size = sizeof(nx_base_stuff) / sizeof(struct vs_entry);
22061 +       int pos, index;
22062 +       u64 ino;
22063 +
22064 +       pos = filp->f_pos;
22065 +       switch (pos) {
22066 +       case 0:
22067 +               ino = inode->i_ino;
22068 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
22069 +                       goto out;
22070 +               pos++;
22071 +               /* fall through */
22072 +       case 1:
22073 +               ino = parent_ino(dentry);
22074 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
22075 +                       goto out;
22076 +               pos++;
22077 +               /* fall through */
22078 +       default:
22079 +               index = pos - 2;
22080 +               if (index >= size)
22081 +                       goto out;
22082 +               for (p += index; p->name; p++) {
22083 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
22084 +                               vs_proc_instantiate, PROC_I(inode)->fd, p))
22085 +                               goto out;
22086 +                       pos++;
22087 +               }
22088 +       }
22089 +out:
22090 +       filp->f_pos = pos;
22091 +       return 1;
22092 +}
22093 +
22094 +
22095 +#define MAX_MULBY10    ((~0U - 9) / 10)
22096 +
22097 +static inline int atovid(const char *str, int len)
22098 +{
22099 +       int vid, c;
22100 +
22101 +       vid = 0;
22102 +       while (len-- > 0) {
22103 +               c = *str - '0';
22104 +               str++;
22105 +               if (c > 9)
22106 +                       return -1;
22107 +               if (vid >= MAX_MULBY10)
22108 +                       return -1;
22109 +               vid *= 10;
22110 +               vid += c;
22111 +               if (!vid)
22112 +                       return -1;
22113 +       }
22114 +       return vid;
22115 +}
22116 +
22117 +/* now the upper level (virtual) */
22118 +
22119 +
22120 +static struct file_operations proc_xid_file_operations = {
22121 +       .read =         generic_read_dir,
22122 +       .readdir =      proc_xid_readdir,
22123 +};
22124 +
22125 +static struct inode_operations proc_xid_inode_operations = {
22126 +       .lookup =       proc_xid_lookup,
22127 +};
22128 +
22129 +static struct vs_entry vx_virtual_stuff[] = {
22130 +       INF("info",     S_IRUGO, virtual_info),
22131 +       INF("status",   S_IRUGO, virtual_status),
22132 +       DIR(NULL,       S_IRUGO | S_IXUGO, xid),
22133 +};
22134 +
22135 +
22136 +static struct dentry *proc_virtual_lookup(struct inode *dir,
22137 +       struct dentry *dentry, struct nameidata *nd)
22138 +{
22139 +       struct vs_entry *p = vx_virtual_stuff;
22140 +       struct dentry *error = ERR_PTR(-ENOENT);
22141 +       int id = 0;
22142 +
22143 +       for (; p->name; p++) {
22144 +               if (p->len != dentry->d_name.len)
22145 +                       continue;
22146 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
22147 +                       break;
22148 +       }
22149 +       if (p->name)
22150 +               goto instantiate;
22151 +
22152 +       id = atovid(dentry->d_name.name, dentry->d_name.len);
22153 +       if ((id < 0) || !xid_is_hashed(id))
22154 +               goto out;
22155 +
22156 +instantiate:
22157 +       error = proc_xid_instantiate(dir, dentry, id, p);
22158 +out:
22159 +       return error;
22160 +}
22161 +
22162 +static struct file_operations proc_nid_file_operations = {
22163 +       .read =         generic_read_dir,
22164 +       .readdir =      proc_nid_readdir,
22165 +};
22166 +
22167 +static struct inode_operations proc_nid_inode_operations = {
22168 +       .lookup =       proc_nid_lookup,
22169 +};
22170 +
22171 +static struct vs_entry nx_virtnet_stuff[] = {
22172 +       INF("info",     S_IRUGO, virtnet_info),
22173 +       INF("status",   S_IRUGO, virtnet_status),
22174 +       DIR(NULL,       S_IRUGO | S_IXUGO, nid),
22175 +};
22176 +
22177 +
22178 +static struct dentry *proc_virtnet_lookup(struct inode *dir,
22179 +       struct dentry *dentry, struct nameidata *nd)
22180 +{
22181 +       struct vs_entry *p = nx_virtnet_stuff;
22182 +       struct dentry *error = ERR_PTR(-ENOENT);
22183 +       int id = 0;
22184 +
22185 +       for (; p->name; p++) {
22186 +               if (p->len != dentry->d_name.len)
22187 +                       continue;
22188 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
22189 +                       break;
22190 +       }
22191 +       if (p->name)
22192 +               goto instantiate;
22193 +
22194 +       id = atovid(dentry->d_name.name, dentry->d_name.len);
22195 +       if ((id < 0) || !nid_is_hashed(id))
22196 +               goto out;
22197 +
22198 +instantiate:
22199 +       error = proc_nid_instantiate(dir, dentry, id, p);
22200 +out:
22201 +       return error;
22202 +}
22203 +
22204 +
22205 +#define PROC_MAXVIDS 32
22206 +
22207 +int proc_virtual_readdir(struct file *filp,
22208 +       void *dirent, filldir_t filldir)
22209 +{
22210 +       struct dentry *dentry = filp->f_dentry;
22211 +       struct inode *inode = dentry->d_inode;
22212 +       struct vs_entry *p = vx_virtual_stuff;
22213 +       int size = sizeof(vx_virtual_stuff) / sizeof(struct vs_entry);
22214 +       int pos, index;
22215 +       unsigned int xid_array[PROC_MAXVIDS];
22216 +       char buf[PROC_NUMBUF];
22217 +       unsigned int nr_xids, i;
22218 +       u64 ino;
22219 +
22220 +       pos = filp->f_pos;
22221 +       switch (pos) {
22222 +       case 0:
22223 +               ino = inode->i_ino;
22224 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
22225 +                       goto out;
22226 +               pos++;
22227 +               /* fall through */
22228 +       case 1:
22229 +               ino = parent_ino(dentry);
22230 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
22231 +                       goto out;
22232 +               pos++;
22233 +               /* fall through */
22234 +       default:
22235 +               index = pos - 2;
22236 +               if (index >= size)
22237 +                       goto entries;
22238 +               for (p += index; p->name; p++) {
22239 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
22240 +                               vs_proc_instantiate, 0, p))
22241 +                               goto out;
22242 +                       pos++;
22243 +               }
22244 +       entries:
22245 +               index = pos - size;
22246 +               p = &vx_virtual_stuff[size - 1];
22247 +               nr_xids = get_xid_list(index, xid_array, PROC_MAXVIDS);
22248 +               for (i = 0; i < nr_xids; i++) {
22249 +                       int n, xid = xid_array[i];
22250 +                       unsigned int j = PROC_NUMBUF;
22251 +
22252 +                       n = xid;
22253 +                       do
22254 +                               buf[--j] = '0' + (n % 10);
22255 +                       while (n /= 10);
22256 +
22257 +                       if (proc_fill_cache(filp, dirent, filldir,
22258 +                               buf + j, PROC_NUMBUF - j,
22259 +                               vs_proc_instantiate, xid, p))
22260 +                               goto out;
22261 +                       pos++;
22262 +               }
22263 +       }
22264 +out:
22265 +       filp->f_pos = pos;
22266 +       return 0;
22267 +}
22268 +
22269 +static int proc_virtual_getattr(struct vfsmount *mnt,
22270 +       struct dentry *dentry, struct kstat *stat)
22271 +{
22272 +       struct inode *inode = dentry->d_inode;
22273 +
22274 +       generic_fillattr(inode, stat);
22275 +       stat->nlink = 2 + atomic_read(&vx_global_cactive);
22276 +       return 0;
22277 +}
22278 +
22279 +static struct file_operations proc_virtual_dir_operations = {
22280 +       .read =         generic_read_dir,
22281 +       .readdir =      proc_virtual_readdir,
22282 +};
22283 +
22284 +static struct inode_operations proc_virtual_dir_inode_operations = {
22285 +       .getattr =      proc_virtual_getattr,
22286 +       .lookup =       proc_virtual_lookup,
22287 +};
22288 +
22289 +
22290 +
22291 +
22292 +
22293 +int proc_virtnet_readdir(struct file *filp,
22294 +       void *dirent, filldir_t filldir)
22295 +{
22296 +       struct dentry *dentry = filp->f_dentry;
22297 +       struct inode *inode = dentry->d_inode;
22298 +       struct vs_entry *p = nx_virtnet_stuff;
22299 +       int size = sizeof(nx_virtnet_stuff) / sizeof(struct vs_entry);
22300 +       int pos, index;
22301 +       unsigned int nid_array[PROC_MAXVIDS];
22302 +       char buf[PROC_NUMBUF];
22303 +       unsigned int nr_nids, i;
22304 +       u64 ino;
22305 +
22306 +       pos = filp->f_pos;
22307 +       switch (pos) {
22308 +       case 0:
22309 +               ino = inode->i_ino;
22310 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
22311 +                       goto out;
22312 +               pos++;
22313 +               /* fall through */
22314 +       case 1:
22315 +               ino = parent_ino(dentry);
22316 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
22317 +                       goto out;
22318 +               pos++;
22319 +               /* fall through */
22320 +       default:
22321 +               index = pos - 2;
22322 +               if (index >= size)
22323 +                       goto entries;
22324 +               for (p += index; p->name; p++) {
22325 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
22326 +                               vs_proc_instantiate, 0, p))
22327 +                               goto out;
22328 +                       pos++;
22329 +               }
22330 +       entries:
22331 +               index = pos - size;
22332 +               p = &nx_virtnet_stuff[size - 1];
22333 +               nr_nids = get_nid_list(index, nid_array, PROC_MAXVIDS);
22334 +               for (i = 0; i < nr_nids; i++) {
22335 +                       int n, nid = nid_array[i];
22336 +                       unsigned int j = PROC_NUMBUF;
22337 +
22338 +                       n = nid;
22339 +                       do
22340 +                               buf[--j] = '0' + (n % 10);
22341 +                       while (n /= 10);
22342 +
22343 +                       if (proc_fill_cache(filp, dirent, filldir,
22344 +                               buf + j, PROC_NUMBUF - j,
22345 +                               vs_proc_instantiate, nid, p))
22346 +                               goto out;
22347 +                       pos++;
22348 +               }
22349 +       }
22350 +out:
22351 +       filp->f_pos = pos;
22352 +       return 0;
22353 +}
22354 +
22355 +static int proc_virtnet_getattr(struct vfsmount *mnt,
22356 +       struct dentry *dentry, struct kstat *stat)
22357 +{
22358 +       struct inode *inode = dentry->d_inode;
22359 +
22360 +       generic_fillattr(inode, stat);
22361 +       stat->nlink = 2 + atomic_read(&nx_global_cactive);
22362 +       return 0;
22363 +}
22364 +
22365 +static struct file_operations proc_virtnet_dir_operations = {
22366 +       .read =         generic_read_dir,
22367 +       .readdir =      proc_virtnet_readdir,
22368 +};
22369 +
22370 +static struct inode_operations proc_virtnet_dir_inode_operations = {
22371 +       .getattr =      proc_virtnet_getattr,
22372 +       .lookup =       proc_virtnet_lookup,
22373 +};
22374 +
22375 +
22376 +
22377 +void proc_vx_init(void)
22378 +{
22379 +       struct proc_dir_entry *ent;
22380 +
22381 +       ent = proc_mkdir("virtual", 0);
22382 +       if (ent) {
22383 +               ent->proc_fops = &proc_virtual_dir_operations;
22384 +               ent->proc_iops = &proc_virtual_dir_inode_operations;
22385 +       }
22386 +       proc_virtual = ent;
22387 +
22388 +       ent = proc_mkdir("virtnet", 0);
22389 +       if (ent) {
22390 +               ent->proc_fops = &proc_virtnet_dir_operations;
22391 +               ent->proc_iops = &proc_virtnet_dir_inode_operations;
22392 +       }
22393 +       proc_virtnet = ent;
22394 +}
22395 +
22396 +
22397 +
22398 +
22399 +/* per pid info */
22400 +
22401 +
22402 +int proc_pid_vx_info(struct task_struct *p, char *buffer)
22403 +{
22404 +       struct vx_info *vxi;
22405 +       char *orig = buffer;
22406 +
22407 +       buffer += sprintf(buffer, "XID:\t%d\n", vx_task_xid(p));
22408 +
22409 +       vxi = task_get_vx_info(p);
22410 +       if (!vxi)
22411 +               goto out;
22412 +
22413 +       buffer += sprintf(buffer, "BCaps:\t");
22414 +       buffer = print_cap_t(buffer, &vxi->vx_bcaps);
22415 +       buffer += sprintf(buffer, "\n");
22416 +       buffer += sprintf(buffer, "CCaps:\t%016llx\n",
22417 +               (unsigned long long)vxi->vx_ccaps);
22418 +       buffer += sprintf(buffer, "CFlags:\t%016llx\n",
22419 +               (unsigned long long)vxi->vx_flags);
22420 +       buffer += sprintf(buffer, "CIPid:\t%d\n", vxi->vx_initpid);
22421 +
22422 +       put_vx_info(vxi);
22423 +out:
22424 +       return buffer - orig;
22425 +}
22426 +
22427 +
22428 +int proc_pid_nx_info(struct task_struct *p, char *buffer)
22429 +{
22430 +       struct nx_info *nxi;
22431 +       struct nx_addr_v4 *v4a;
22432 +#ifdef CONFIG_IPV6
22433 +       struct nx_addr_v6 *v6a;
22434 +#endif
22435 +       char *orig = buffer;
22436 +       int i;
22437 +
22438 +       buffer += sprintf(buffer, "NID:\t%d\n", nx_task_nid(p));
22439 +
22440 +       nxi = task_get_nx_info(p);
22441 +       if (!nxi)
22442 +               goto out;
22443 +
22444 +       buffer += sprintf(buffer, "NCaps:\t%016llx\n",
22445 +               (unsigned long long)nxi->nx_ncaps);
22446 +       buffer += sprintf(buffer, "NFlags:\t%016llx\n",
22447 +               (unsigned long long)nxi->nx_flags);
22448 +
22449 +       buffer += sprintf(buffer,
22450 +               "V4Root[bcast]:\t" NIPQUAD_FMT "\n",
22451 +               NIPQUAD(nxi->v4_bcast.s_addr));
22452 +       buffer += sprintf (buffer,
22453 +               "V4Root[lback]:\t" NIPQUAD_FMT "\n",
22454 +               NIPQUAD(nxi->v4_lback.s_addr));
22455 +       if (!NX_IPV4(nxi))
22456 +               goto skip_v4;
22457 +       for (i = 0, v4a = &nxi->v4; v4a; i++, v4a = v4a->next)
22458 +               buffer += sprintf(buffer, "V4Root[%d]:\t" NXAV4_FMT "\n",
22459 +                       i, NXAV4(v4a));
22460 +skip_v4:
22461 +#ifdef CONFIG_IPV6
22462 +       if (!NX_IPV6(nxi))
22463 +               goto skip_v6;
22464 +       for (i = 0, v6a = &nxi->v6; v6a; i++, v6a = v6a->next)
22465 +               buffer += sprintf(buffer, "V6Root[%d]:\t" NXAV6_FMT "\n",
22466 +                       i, NXAV6(v6a));
22467 +skip_v6:
22468 +#endif
22469 +       put_nx_info(nxi);
22470 +out:
22471 +       return buffer - orig;
22472 +}
22473 +
22474 diff -NurpP --minimal linux-3.0.25/kernel/vserver/sched.c linux-3.0.25-vs2.3.2.3/kernel/vserver/sched.c
22475 --- linux-3.0.25/kernel/vserver/sched.c 1970-01-01 01:00:00.000000000 +0100
22476 +++ linux-3.0.25-vs2.3.2.3/kernel/vserver/sched.c       2011-06-10 22:11:24.000000000 +0200
22477 @@ -0,0 +1,82 @@
22478 +/*
22479 + *  linux/kernel/vserver/sched.c
22480 + *
22481 + *  Virtual Server: Scheduler Support
22482 + *
22483 + *  Copyright (C) 2004-2010  Herbert Pötzl
22484 + *
22485 + *  V0.01  adapted Sam Vilains version to 2.6.3
22486 + *  V0.02  removed legacy interface
22487 + *  V0.03  changed vcmds to vxi arg
22488 + *  V0.04  removed older and legacy interfaces
22489 + *  V0.05  removed scheduler code/commands
22490 + *
22491 + */
22492 +
22493 +#include <linux/vs_context.h>
22494 +#include <linux/vs_sched.h>
22495 +#include <linux/vserver/sched_cmd.h>
22496 +
22497 +#include <asm/uaccess.h>
22498 +
22499 +
22500 +void vx_update_sched_param(struct _vx_sched *sched,
22501 +       struct _vx_sched_pc *sched_pc)
22502 +{
22503 +       sched_pc->prio_bias = sched->prio_bias;
22504 +}
22505 +
22506 +static int do_set_prio_bias(struct vx_info *vxi, struct vcmd_prio_bias *data)
22507 +{
22508 +       int cpu;
22509 +
22510 +       if (data->prio_bias > MAX_PRIO_BIAS)
22511 +               data->prio_bias = MAX_PRIO_BIAS;
22512 +       if (data->prio_bias < MIN_PRIO_BIAS)
22513 +               data->prio_bias = MIN_PRIO_BIAS;
22514 +
22515 +       if (data->cpu_id != ~0) {
22516 +               vxi->sched.update = cpumask_of_cpu(data->cpu_id);
22517 +               cpus_and(vxi->sched.update, cpu_online_map,
22518 +                       vxi->sched.update);
22519 +       } else
22520 +               vxi->sched.update = cpu_online_map;
22521 +
22522 +       for_each_cpu_mask(cpu, vxi->sched.update)
22523 +               vx_update_sched_param(&vxi->sched,
22524 +                       &vx_per_cpu(vxi, sched_pc, cpu));
22525 +       return 0;
22526 +}
22527 +
22528 +int vc_set_prio_bias(struct vx_info *vxi, void __user *data)
22529 +{
22530 +       struct vcmd_prio_bias vc_data;
22531 +
22532 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
22533 +               return -EFAULT;
22534 +
22535 +       return do_set_prio_bias(vxi, &vc_data);
22536 +}
22537 +
22538 +int vc_get_prio_bias(struct vx_info *vxi, void __user *data)
22539 +{
22540 +       struct vcmd_prio_bias vc_data;
22541 +       struct _vx_sched_pc *pcd;
22542 +       int cpu;
22543 +
22544 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
22545 +               return -EFAULT;
22546 +
22547 +       cpu = vc_data.cpu_id;
22548 +
22549 +       if (!cpu_possible(cpu))
22550 +               return -EINVAL;
22551 +
22552 +       pcd = &vx_per_cpu(vxi, sched_pc, cpu);
22553 +       vc_data.prio_bias = pcd->prio_bias;
22554 +
22555 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
22556 +               return -EFAULT;
22557 +       return 0;
22558 +}
22559 +
22560 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
22561 --- linux-3.0.25/kernel/vserver/sched_init.h    1970-01-01 01:00:00.000000000 +0100
22562 +++ linux-3.0.25-vs2.3.2.3/kernel/vserver/sched_init.h  2011-06-10 22:11:24.000000000 +0200
22563 @@ -0,0 +1,27 @@
22564 +
22565 +static inline void vx_info_init_sched(struct _vx_sched *sched)
22566 +{
22567 +       /* scheduling; hard code starting values as constants */
22568 +       sched->prio_bias = 0;
22569 +}
22570 +
22571 +static inline
22572 +void vx_info_init_sched_pc(struct _vx_sched_pc *sched_pc, int cpu)
22573 +{
22574 +       sched_pc->prio_bias = 0;
22575 +
22576 +       sched_pc->user_ticks = 0;
22577 +       sched_pc->sys_ticks = 0;
22578 +       sched_pc->hold_ticks = 0;
22579 +}
22580 +
22581 +static inline void vx_info_exit_sched(struct _vx_sched *sched)
22582 +{
22583 +       return;
22584 +}
22585 +
22586 +static inline
22587 +void vx_info_exit_sched_pc(struct _vx_sched_pc *sched_pc, int cpu)
22588 +{
22589 +       return;
22590 +}
22591 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
22592 --- linux-3.0.25/kernel/vserver/sched_proc.h    1970-01-01 01:00:00.000000000 +0100
22593 +++ linux-3.0.25-vs2.3.2.3/kernel/vserver/sched_proc.h  2011-06-10 22:11:24.000000000 +0200
22594 @@ -0,0 +1,32 @@
22595 +#ifndef _VX_SCHED_PROC_H
22596 +#define _VX_SCHED_PROC_H
22597 +
22598 +
22599 +static inline
22600 +int vx_info_proc_sched(struct _vx_sched *sched, char *buffer)
22601 +{
22602 +       int length = 0;
22603 +
22604 +       length += sprintf(buffer,
22605 +               "PrioBias:\t%8d\n",
22606 +               sched->prio_bias);
22607 +       return length;
22608 +}
22609 +
22610 +static inline
22611 +int vx_info_proc_sched_pc(struct _vx_sched_pc *sched_pc,
22612 +       char *buffer, int cpu)
22613 +{
22614 +       int length = 0;
22615 +
22616 +       length += sprintf(buffer + length,
22617 +               "cpu %d: %lld %lld %lld", cpu,
22618 +               (unsigned long long)sched_pc->user_ticks,
22619 +               (unsigned long long)sched_pc->sys_ticks,
22620 +               (unsigned long long)sched_pc->hold_ticks);
22621 +       length += sprintf(buffer + length,
22622 +               " %d\n", sched_pc->prio_bias);
22623 +       return length;
22624 +}
22625 +
22626 +#endif /* _VX_SCHED_PROC_H */
22627 diff -NurpP --minimal linux-3.0.25/kernel/vserver/signal.c linux-3.0.25-vs2.3.2.3/kernel/vserver/signal.c
22628 --- linux-3.0.25/kernel/vserver/signal.c        1970-01-01 01:00:00.000000000 +0100
22629 +++ linux-3.0.25-vs2.3.2.3/kernel/vserver/signal.c      2011-06-10 22:11:24.000000000 +0200
22630 @@ -0,0 +1,134 @@
22631 +/*
22632 + *  linux/kernel/vserver/signal.c
22633 + *
22634 + *  Virtual Server: Signal Support
22635 + *
22636 + *  Copyright (C) 2003-2007  Herbert Pötzl
22637 + *
22638 + *  V0.01  broken out from vcontext V0.05
22639 + *  V0.02  changed vcmds to vxi arg
22640 + *  V0.03  adjusted siginfo for kill
22641 + *
22642 + */
22643 +
22644 +#include <asm/uaccess.h>
22645 +
22646 +#include <linux/vs_context.h>
22647 +#include <linux/vs_pid.h>
22648 +#include <linux/vserver/signal_cmd.h>
22649 +
22650 +
22651 +int vx_info_kill(struct vx_info *vxi, int pid, int sig)
22652 +{
22653 +       int retval, count = 0;
22654 +       struct task_struct *p;
22655 +       struct siginfo *sip = SEND_SIG_PRIV;
22656 +
22657 +       retval = -ESRCH;
22658 +       vxdprintk(VXD_CBIT(misc, 4),
22659 +               "vx_info_kill(%p[#%d],%d,%d)*",
22660 +               vxi, vxi->vx_id, pid, sig);
22661 +       read_lock(&tasklist_lock);
22662 +       switch (pid) {
22663 +       case  0:
22664 +       case -1:
22665 +               for_each_process(p) {
22666 +                       int err = 0;
22667 +
22668 +                       if (vx_task_xid(p) != vxi->vx_id || p->pid <= 1 ||
22669 +                               (pid && vxi->vx_initpid == p->pid))
22670 +                               continue;
22671 +
22672 +                       err = group_send_sig_info(sig, sip, p);
22673 +                       ++count;
22674 +                       if (err != -EPERM)
22675 +                               retval = err;
22676 +               }
22677 +               break;
22678 +
22679 +       case 1:
22680 +               if (vxi->vx_initpid) {
22681 +                       pid = vxi->vx_initpid;
22682 +                       /* for now, only SIGINT to private init ... */
22683 +                       if (!vx_info_flags(vxi, VXF_STATE_ADMIN, 0) &&
22684 +                               /* ... as long as there are tasks left */
22685 +                               (atomic_read(&vxi->vx_tasks) > 1))
22686 +                               sig = SIGINT;
22687 +               }
22688 +               /* fallthrough */
22689 +       default:
22690 +               rcu_read_lock();
22691 +               p = find_task_by_real_pid(pid);
22692 +               rcu_read_unlock();
22693 +               if (p) {
22694 +                       if (vx_task_xid(p) == vxi->vx_id)
22695 +                               retval = group_send_sig_info(sig, sip, p);
22696 +               }
22697 +               break;
22698 +       }
22699 +       read_unlock(&tasklist_lock);
22700 +       vxdprintk(VXD_CBIT(misc, 4),
22701 +               "vx_info_kill(%p[#%d],%d,%d,%ld) = %d",
22702 +               vxi, vxi->vx_id, pid, sig, (long)sip, retval);
22703 +       return retval;
22704 +}
22705 +
22706 +int vc_ctx_kill(struct vx_info *vxi, void __user *data)
22707 +{
22708 +       struct vcmd_ctx_kill_v0 vc_data;
22709 +
22710 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
22711 +               return -EFAULT;
22712 +
22713 +       /* special check to allow guest shutdown */
22714 +       if (!vx_info_flags(vxi, VXF_STATE_ADMIN, 0) &&
22715 +               /* forbid killall pid=0 when init is present */
22716 +               (((vc_data.pid < 1) && vxi->vx_initpid) ||
22717 +               (vc_data.pid > 1)))
22718 +               return -EACCES;
22719 +
22720 +       return vx_info_kill(vxi, vc_data.pid, vc_data.sig);
22721 +}
22722 +
22723 +
22724 +static int __wait_exit(struct vx_info *vxi)
22725 +{
22726 +       DECLARE_WAITQUEUE(wait, current);
22727 +       int ret = 0;
22728 +
22729 +       add_wait_queue(&vxi->vx_wait, &wait);
22730 +       set_current_state(TASK_INTERRUPTIBLE);
22731 +
22732 +wait:
22733 +       if (vx_info_state(vxi,
22734 +               VXS_SHUTDOWN | VXS_HASHED | VXS_HELPER) == VXS_SHUTDOWN)
22735 +               goto out;
22736 +       if (signal_pending(current)) {
22737 +               ret = -ERESTARTSYS;
22738 +               goto out;
22739 +       }
22740 +       schedule();
22741 +       goto wait;
22742 +
22743 +out:
22744 +       set_current_state(TASK_RUNNING);
22745 +       remove_wait_queue(&vxi->vx_wait, &wait);
22746 +       return ret;
22747 +}
22748 +
22749 +
22750 +
22751 +int vc_wait_exit(struct vx_info *vxi, void __user *data)
22752 +{
22753 +       struct vcmd_wait_exit_v0 vc_data;
22754 +       int ret;
22755 +
22756 +       ret = __wait_exit(vxi);
22757 +       vc_data.reboot_cmd = vxi->reboot_cmd;
22758 +       vc_data.exit_code = vxi->exit_code;
22759 +
22760 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
22761 +               ret = -EFAULT;
22762 +       return ret;
22763 +}
22764 +
22765 diff -NurpP --minimal linux-3.0.25/kernel/vserver/space.c linux-3.0.25-vs2.3.2.3/kernel/vserver/space.c
22766 --- linux-3.0.25/kernel/vserver/space.c 1970-01-01 01:00:00.000000000 +0100
22767 +++ linux-3.0.25-vs2.3.2.3/kernel/vserver/space.c       2011-07-20 02:11:49.000000000 +0200
22768 @@ -0,0 +1,435 @@
22769 +/*
22770 + *  linux/kernel/vserver/space.c
22771 + *
22772 + *  Virtual Server: Context Space Support
22773 + *
22774 + *  Copyright (C) 2003-2010  Herbert Pötzl
22775 + *
22776 + *  V0.01  broken out from context.c 0.07
22777 + *  V0.02  added task locking for namespace
22778 + *  V0.03  broken out vx_enter_namespace
22779 + *  V0.04  added *space support and commands
22780 + *  V0.05  added credential support
22781 + *
22782 + */
22783 +
22784 +#include <linux/utsname.h>
22785 +#include <linux/nsproxy.h>
22786 +#include <linux/err.h>
22787 +#include <linux/fs_struct.h>
22788 +#include <linux/cred.h>
22789 +#include <asm/uaccess.h>
22790 +
22791 +#include <linux/vs_context.h>
22792 +#include <linux/vserver/space.h>
22793 +#include <linux/vserver/space_cmd.h>
22794 +
22795 +atomic_t vs_global_nsproxy     = ATOMIC_INIT(0);
22796 +atomic_t vs_global_fs          = ATOMIC_INIT(0);
22797 +atomic_t vs_global_mnt_ns      = ATOMIC_INIT(0);
22798 +atomic_t vs_global_uts_ns      = ATOMIC_INIT(0);
22799 +atomic_t vs_global_user_ns     = ATOMIC_INIT(0);
22800 +atomic_t vs_global_pid_ns      = ATOMIC_INIT(0);
22801 +
22802 +
22803 +/* namespace functions */
22804 +
22805 +#include <linux/mnt_namespace.h>
22806 +#include <linux/user_namespace.h>
22807 +#include <linux/pid_namespace.h>
22808 +#include <linux/ipc_namespace.h>
22809 +#include <net/net_namespace.h>
22810 +
22811 +
22812 +static const struct vcmd_space_mask_v1 space_mask_v0 = {
22813 +       .mask = CLONE_FS |
22814 +               CLONE_NEWNS |
22815 +#ifdef CONFIG_UTS_NS
22816 +               CLONE_NEWUTS |
22817 +#endif
22818 +#ifdef CONFIG_IPC_NS
22819 +               CLONE_NEWIPC |
22820 +#endif
22821 +#ifdef CONFIG_USER_NS
22822 +               CLONE_NEWUSER |
22823 +#endif
22824 +               0
22825 +};
22826 +
22827 +static const struct vcmd_space_mask_v1 space_mask = {
22828 +       .mask = CLONE_FS |
22829 +               CLONE_NEWNS |
22830 +#ifdef CONFIG_UTS_NS
22831 +               CLONE_NEWUTS |
22832 +#endif
22833 +#ifdef CONFIG_IPC_NS
22834 +               CLONE_NEWIPC |
22835 +#endif
22836 +#ifdef CONFIG_USER_NS
22837 +               CLONE_NEWUSER |
22838 +#endif
22839 +#ifdef CONFIG_PID_NS
22840 +               CLONE_NEWPID |
22841 +#endif
22842 +#ifdef CONFIG_NET_NS
22843 +               CLONE_NEWNET |
22844 +#endif
22845 +               0
22846 +};
22847 +
22848 +static const struct vcmd_space_mask_v1 default_space_mask = {
22849 +       .mask = CLONE_FS |
22850 +               CLONE_NEWNS |
22851 +#ifdef CONFIG_UTS_NS
22852 +               CLONE_NEWUTS |
22853 +#endif
22854 +#ifdef CONFIG_IPC_NS
22855 +               CLONE_NEWIPC |
22856 +#endif
22857 +#ifdef CONFIG_USER_NS
22858 +               CLONE_NEWUSER |
22859 +#endif
22860 +#ifdef CONFIG_PID_NS
22861 +//             CLONE_NEWPID |
22862 +#endif
22863 +               0
22864 +};
22865 +
22866 +/*
22867 + *     build a new nsproxy mix
22868 + *      assumes that both proxies are 'const'
22869 + *     does not touch nsproxy refcounts
22870 + *     will hold a reference on the result.
22871 + */
22872 +
22873 +struct nsproxy *vs_mix_nsproxy(struct nsproxy *old_nsproxy,
22874 +       struct nsproxy *new_nsproxy, unsigned long mask)
22875 +{
22876 +       struct mnt_namespace *old_ns;
22877 +       struct uts_namespace *old_uts;
22878 +       struct ipc_namespace *old_ipc;
22879 +#ifdef CONFIG_PID_NS
22880 +       struct pid_namespace *old_pid;
22881 +#endif
22882 +#ifdef CONFIG_NET_NS
22883 +       struct net *old_net;
22884 +#endif
22885 +       struct nsproxy *nsproxy;
22886 +
22887 +       nsproxy = copy_nsproxy(old_nsproxy);
22888 +       if (!nsproxy)
22889 +               goto out;
22890 +
22891 +       if (mask & CLONE_NEWNS) {
22892 +               old_ns = nsproxy->mnt_ns;
22893 +               nsproxy->mnt_ns = new_nsproxy->mnt_ns;
22894 +               if (nsproxy->mnt_ns)
22895 +                       get_mnt_ns(nsproxy->mnt_ns);
22896 +       } else
22897 +               old_ns = NULL;
22898 +
22899 +       if (mask & CLONE_NEWUTS) {
22900 +               old_uts = nsproxy->uts_ns;
22901 +               nsproxy->uts_ns = new_nsproxy->uts_ns;
22902 +               if (nsproxy->uts_ns)
22903 +                       get_uts_ns(nsproxy->uts_ns);
22904 +       } else
22905 +               old_uts = NULL;
22906 +
22907 +       if (mask & CLONE_NEWIPC) {
22908 +               old_ipc = nsproxy->ipc_ns;
22909 +               nsproxy->ipc_ns = new_nsproxy->ipc_ns;
22910 +               if (nsproxy->ipc_ns)
22911 +                       get_ipc_ns(nsproxy->ipc_ns);
22912 +       } else
22913 +               old_ipc = NULL;
22914 +
22915 +#ifdef CONFIG_PID_NS
22916 +       if (mask & CLONE_NEWPID) {
22917 +               old_pid = nsproxy->pid_ns;
22918 +               nsproxy->pid_ns = new_nsproxy->pid_ns;
22919 +               if (nsproxy->pid_ns)
22920 +                       get_pid_ns(nsproxy->pid_ns);
22921 +       } else
22922 +               old_pid = NULL;
22923 +#endif
22924 +#ifdef CONFIG_NET_NS
22925 +       if (mask & CLONE_NEWNET) {
22926 +               old_net = nsproxy->net_ns;
22927 +               nsproxy->net_ns = new_nsproxy->net_ns;
22928 +               if (nsproxy->net_ns)
22929 +                       get_net(nsproxy->net_ns);
22930 +       } else
22931 +               old_net = NULL;
22932 +#endif
22933 +       if (old_ns)
22934 +               put_mnt_ns(old_ns);
22935 +       if (old_uts)
22936 +               put_uts_ns(old_uts);
22937 +       if (old_ipc)
22938 +               put_ipc_ns(old_ipc);
22939 +#ifdef CONFIG_PID_NS
22940 +       if (old_pid)
22941 +               put_pid_ns(old_pid);
22942 +#endif
22943 +#ifdef CONFIG_NET_NS
22944 +       if (old_net)
22945 +               put_net(old_net);
22946 +#endif
22947 +out:
22948 +       return nsproxy;
22949 +}
22950 +
22951 +
22952 +/*
22953 + *     merge two nsproxy structs into a new one.
22954 + *     will hold a reference on the result.
22955 + */
22956 +
22957 +static inline
22958 +struct nsproxy *__vs_merge_nsproxy(struct nsproxy *old,
22959 +       struct nsproxy *proxy, unsigned long mask)
22960 +{
22961 +       struct nsproxy null_proxy = { .mnt_ns = NULL };
22962 +
22963 +       if (!proxy)
22964 +               return NULL;
22965 +
22966 +       if (mask) {
22967 +               /* vs_mix_nsproxy returns with reference */
22968 +               return vs_mix_nsproxy(old ? old : &null_proxy,
22969 +                       proxy, mask);
22970 +       }
22971 +       get_nsproxy(proxy);
22972 +       return proxy;
22973 +}
22974 +
22975 +
22976 +int vx_enter_space(struct vx_info *vxi, unsigned long mask, unsigned index)
22977 +{
22978 +       struct nsproxy *proxy, *proxy_cur, *proxy_new;
22979 +       struct fs_struct *fs_cur, *fs = NULL;
22980 +       struct _vx_space *space;
22981 +       int ret, kill = 0;
22982 +
22983 +       vxdprintk(VXD_CBIT(space, 8), "vx_enter_space(%p[#%u],0x%08lx,%d)",
22984 +               vxi, vxi->vx_id, mask, index);
22985 +
22986 +       if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0))
22987 +               return -EACCES;
22988 +
22989 +       if (index >= VX_SPACES)
22990 +               return -EINVAL;
22991 +
22992 +       space = &vxi->space[index];
22993 +
22994 +       if (!mask)
22995 +               mask = space->vx_nsmask;
22996 +
22997 +       if ((mask & space->vx_nsmask) != mask)
22998 +               return -EINVAL;
22999 +
23000 +       if (mask & CLONE_FS) {
23001 +               fs = copy_fs_struct(space->vx_fs);
23002 +               if (!fs)
23003 +                       return -ENOMEM;
23004 +       }
23005 +       proxy = space->vx_nsproxy;
23006 +
23007 +       vxdprintk(VXD_CBIT(space, 9),
23008 +               "vx_enter_space(%p[#%u],0x%08lx,%d) -> (%p,%p)",
23009 +               vxi, vxi->vx_id, mask, index, proxy, fs);
23010 +
23011 +       task_lock(current);
23012 +       fs_cur = current->fs;
23013 +
23014 +       if (mask & CLONE_FS) {
23015 +               spin_lock(&fs_cur->lock);
23016 +               current->fs = fs;
23017 +               kill = !--fs_cur->users;
23018 +               spin_unlock(&fs_cur->lock);
23019 +       }
23020 +
23021 +       proxy_cur = current->nsproxy;
23022 +       get_nsproxy(proxy_cur);
23023 +       task_unlock(current);
23024 +
23025 +       if (kill)
23026 +               free_fs_struct(fs_cur);
23027 +
23028 +       proxy_new = __vs_merge_nsproxy(proxy_cur, proxy, mask);
23029 +       if (IS_ERR(proxy_new)) {
23030 +               ret = PTR_ERR(proxy_new);
23031 +               goto out_put;
23032 +       }
23033 +
23034 +       proxy_new = xchg(&current->nsproxy, proxy_new);
23035 +
23036 +       if (mask & CLONE_NEWUSER) {
23037 +               struct cred *cred;
23038 +
23039 +               vxdprintk(VXD_CBIT(space, 10),
23040 +                       "vx_enter_space(%p[#%u],%p) cred (%p,%p)",
23041 +                       vxi, vxi->vx_id, space->vx_cred,
23042 +                       current->real_cred, current->cred);
23043 +
23044 +               if (space->vx_cred) {
23045 +                       cred = __prepare_creds(space->vx_cred);
23046 +                       if (cred)
23047 +                               commit_creds(cred);
23048 +               }
23049 +       }
23050 +
23051 +       ret = 0;
23052 +
23053 +       if (proxy_new)
23054 +               put_nsproxy(proxy_new);
23055 +out_put:
23056 +       if (proxy_cur)
23057 +               put_nsproxy(proxy_cur);
23058 +       return ret;
23059 +}
23060 +
23061 +
23062 +int vx_set_space(struct vx_info *vxi, unsigned long mask, unsigned index)
23063 +{
23064 +       struct nsproxy *proxy_vxi, *proxy_cur, *proxy_new;
23065 +       struct fs_struct *fs_vxi, *fs;
23066 +       struct _vx_space *space;
23067 +       int ret, kill = 0;
23068 +
23069 +       vxdprintk(VXD_CBIT(space, 8), "vx_set_space(%p[#%u],0x%08lx,%d)",
23070 +               vxi, vxi->vx_id, mask, index);
23071 +
23072 +       if ((mask & space_mask.mask) != mask)
23073 +               return -EINVAL;
23074 +
23075 +       if (index >= VX_SPACES)
23076 +               return -EINVAL;
23077 +
23078 +       space = &vxi->space[index];
23079 +
23080 +       proxy_vxi = space->vx_nsproxy;
23081 +       fs_vxi = space->vx_fs;
23082 +
23083 +       if (mask & CLONE_FS) {
23084 +               fs = copy_fs_struct(current->fs);
23085 +               if (!fs)
23086 +                       return -ENOMEM;
23087 +       }
23088 +
23089 +       task_lock(current);
23090 +
23091 +       if (mask & CLONE_FS) {
23092 +               spin_lock(&fs_vxi->lock);
23093 +               space->vx_fs = fs;
23094 +               kill = !--fs_vxi->users;
23095 +               spin_unlock(&fs_vxi->lock);
23096 +       }
23097 +
23098 +       proxy_cur = current->nsproxy;
23099 +       get_nsproxy(proxy_cur);
23100 +       task_unlock(current);
23101 +
23102 +       if (kill)
23103 +               free_fs_struct(fs_vxi);
23104 +
23105 +       proxy_new = __vs_merge_nsproxy(proxy_vxi, proxy_cur, mask);
23106 +       if (IS_ERR(proxy_new)) {
23107 +               ret = PTR_ERR(proxy_new);
23108 +               goto out_put;
23109 +       }
23110 +
23111 +       proxy_new = xchg(&space->vx_nsproxy, proxy_new);
23112 +       space->vx_nsmask |= mask;
23113 +
23114 +       if (mask & CLONE_NEWUSER) {
23115 +               struct cred *cred;
23116 +
23117 +               vxdprintk(VXD_CBIT(space, 10),
23118 +                       "vx_set_space(%p[#%u],%p) cred (%p,%p)",
23119 +                       vxi, vxi->vx_id, space->vx_cred,
23120 +                       current->real_cred, current->cred);
23121 +
23122 +               cred = prepare_creds();
23123 +               cred = (struct cred *)xchg(&space->vx_cred, cred);
23124 +               if (cred)
23125 +                       abort_creds(cred);
23126 +       }
23127 +
23128 +       ret = 0;
23129 +
23130 +       if (proxy_new)
23131 +               put_nsproxy(proxy_new);
23132 +out_put:
23133 +       if (proxy_cur)
23134 +               put_nsproxy(proxy_cur);
23135 +       return ret;
23136 +}
23137 +
23138 +
23139 +int vc_enter_space_v1(struct vx_info *vxi, void __user *data)
23140 +{
23141 +       struct vcmd_space_mask_v1 vc_data = { .mask = 0 };
23142 +
23143 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
23144 +               return -EFAULT;
23145 +
23146 +       return vx_enter_space(vxi, vc_data.mask, 0);
23147 +}
23148 +
23149 +int vc_enter_space(struct vx_info *vxi, void __user *data)
23150 +{
23151 +       struct vcmd_space_mask_v2 vc_data = { .mask = 0 };
23152 +
23153 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
23154 +               return -EFAULT;
23155 +
23156 +       if (vc_data.index >= VX_SPACES)
23157 +               return -EINVAL;
23158 +
23159 +       return vx_enter_space(vxi, vc_data.mask, vc_data.index);
23160 +}
23161 +
23162 +int vc_set_space_v1(struct vx_info *vxi, void __user *data)
23163 +{
23164 +       struct vcmd_space_mask_v1 vc_data = { .mask = 0 };
23165 +
23166 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
23167 +               return -EFAULT;
23168 +
23169 +       return vx_set_space(vxi, vc_data.mask, 0);
23170 +}
23171 +
23172 +int vc_set_space(struct vx_info *vxi, void __user *data)
23173 +{
23174 +       struct vcmd_space_mask_v2 vc_data = { .mask = 0 };
23175 +
23176 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
23177 +               return -EFAULT;
23178 +
23179 +       if (vc_data.index >= VX_SPACES)
23180 +               return -EINVAL;
23181 +
23182 +       return vx_set_space(vxi, vc_data.mask, vc_data.index);
23183 +}
23184 +
23185 +int vc_get_space_mask(void __user *data, int type)
23186 +{
23187 +       const struct vcmd_space_mask_v1 *mask;
23188 +
23189 +       if (type == 0)
23190 +               mask = &space_mask_v0;
23191 +       else if (type == 1)
23192 +               mask = &space_mask;
23193 +       else
23194 +               mask = &default_space_mask;
23195 +
23196 +       vxdprintk(VXD_CBIT(space, 10),
23197 +               "vc_get_space_mask(%d) = %08llx", type, mask->mask);
23198 +
23199 +       if (copy_to_user(data, mask, sizeof(*mask)))
23200 +               return -EFAULT;
23201 +       return 0;
23202 +}
23203 +
23204 diff -NurpP --minimal linux-3.0.25/kernel/vserver/switch.c linux-3.0.25-vs2.3.2.3/kernel/vserver/switch.c
23205 --- linux-3.0.25/kernel/vserver/switch.c        1970-01-01 01:00:00.000000000 +0100
23206 +++ linux-3.0.25-vs2.3.2.3/kernel/vserver/switch.c      2011-08-01 18:28:26.000000000 +0200
23207 @@ -0,0 +1,556 @@
23208 +/*
23209 + *  linux/kernel/vserver/switch.c
23210 + *
23211 + *  Virtual Server: Syscall Switch
23212 + *
23213 + *  Copyright (C) 2003-2011  Herbert Pötzl
23214 + *
23215 + *  V0.01  syscall switch
23216 + *  V0.02  added signal to context
23217 + *  V0.03  added rlimit functions
23218 + *  V0.04  added iattr, task/xid functions
23219 + *  V0.05  added debug/history stuff
23220 + *  V0.06  added compat32 layer
23221 + *  V0.07  vcmd args and perms
23222 + *  V0.08  added status commands
23223 + *  V0.09  added tag commands
23224 + *  V0.10  added oom bias
23225 + *  V0.11  added device commands
23226 + *  V0.12  added warn mask
23227 + *
23228 + */
23229 +
23230 +#include <linux/vs_context.h>
23231 +#include <linux/vs_network.h>
23232 +#include <linux/vserver/switch.h>
23233 +
23234 +#include "vci_config.h"
23235 +
23236 +
23237 +static inline
23238 +int vc_get_version(uint32_t id)
23239 +{
23240 +       return VCI_VERSION;
23241 +}
23242 +
23243 +static inline
23244 +int vc_get_vci(uint32_t id)
23245 +{
23246 +       return vci_kernel_config();
23247 +}
23248 +
23249 +#include <linux/vserver/context_cmd.h>
23250 +#include <linux/vserver/cvirt_cmd.h>
23251 +#include <linux/vserver/cacct_cmd.h>
23252 +#include <linux/vserver/limit_cmd.h>
23253 +#include <linux/vserver/network_cmd.h>
23254 +#include <linux/vserver/sched_cmd.h>
23255 +#include <linux/vserver/debug_cmd.h>
23256 +#include <linux/vserver/inode_cmd.h>
23257 +#include <linux/vserver/dlimit_cmd.h>
23258 +#include <linux/vserver/signal_cmd.h>
23259 +#include <linux/vserver/space_cmd.h>
23260 +#include <linux/vserver/tag_cmd.h>
23261 +#include <linux/vserver/device_cmd.h>
23262 +
23263 +#include <linux/vserver/inode.h>
23264 +#include <linux/vserver/dlimit.h>
23265 +
23266 +
23267 +#ifdef CONFIG_COMPAT
23268 +#define __COMPAT(name, id, data, compat)       \
23269 +       (compat) ? name ## _x32(id, data) : name(id, data)
23270 +#define __COMPAT_NO_ID(name, data, compat)     \
23271 +       (compat) ? name ## _x32(data) : name(data)
23272 +#else
23273 +#define __COMPAT(name, id, data, compat)       \
23274 +       name(id, data)
23275 +#define __COMPAT_NO_ID(name, data, compat)     \
23276 +       name(data)
23277 +#endif
23278 +
23279 +
23280 +static inline
23281 +long do_vcmd(uint32_t cmd, uint32_t id,
23282 +       struct vx_info *vxi, struct nx_info *nxi,
23283 +       void __user *data, int compat)
23284 +{
23285 +       switch (cmd) {
23286 +
23287 +       case VCMD_get_version:
23288 +               return vc_get_version(id);
23289 +       case VCMD_get_vci:
23290 +               return vc_get_vci(id);
23291 +
23292 +       case VCMD_task_xid:
23293 +               return vc_task_xid(id);
23294 +       case VCMD_vx_info:
23295 +               return vc_vx_info(vxi, data);
23296 +
23297 +       case VCMD_task_nid:
23298 +               return vc_task_nid(id);
23299 +       case VCMD_nx_info:
23300 +               return vc_nx_info(nxi, data);
23301 +
23302 +       case VCMD_task_tag:
23303 +               return vc_task_tag(id);
23304 +
23305 +       case VCMD_set_space_v1:
23306 +               return vc_set_space_v1(vxi, data);
23307 +       /* this is version 2 */
23308 +       case VCMD_set_space:
23309 +               return vc_set_space(vxi, data);
23310 +
23311 +       case VCMD_get_space_mask_v0:
23312 +               return vc_get_space_mask(data, 0);
23313 +       /* this is version 1 */
23314 +       case VCMD_get_space_mask:
23315 +               return vc_get_space_mask(data, 1);
23316 +
23317 +       case VCMD_get_space_default:
23318 +               return vc_get_space_mask(data, -1);
23319 +
23320 +       case VCMD_set_umask:
23321 +               return vc_set_umask(vxi, data);
23322 +
23323 +       case VCMD_get_umask:
23324 +               return vc_get_umask(vxi, data);
23325 +
23326 +       case VCMD_set_wmask:
23327 +               return vc_set_wmask(vxi, data);
23328 +
23329 +       case VCMD_get_wmask:
23330 +               return vc_get_wmask(vxi, data);
23331 +#ifdef CONFIG_IA32_EMULATION
23332 +       case VCMD_get_rlimit:
23333 +               return __COMPAT(vc_get_rlimit, vxi, data, compat);
23334 +       case VCMD_set_rlimit:
23335 +               return __COMPAT(vc_set_rlimit, vxi, data, compat);
23336 +#else
23337 +       case VCMD_get_rlimit:
23338 +               return vc_get_rlimit(vxi, data);
23339 +       case VCMD_set_rlimit:
23340 +               return vc_set_rlimit(vxi, data);
23341 +#endif
23342 +       case VCMD_get_rlimit_mask:
23343 +               return vc_get_rlimit_mask(id, data);
23344 +       case VCMD_reset_hits:
23345 +               return vc_reset_hits(vxi, data);
23346 +       case VCMD_reset_minmax:
23347 +               return vc_reset_minmax(vxi, data);
23348 +
23349 +       case VCMD_get_vhi_name:
23350 +               return vc_get_vhi_name(vxi, data);
23351 +       case VCMD_set_vhi_name:
23352 +               return vc_set_vhi_name(vxi, data);
23353 +
23354 +       case VCMD_ctx_stat:
23355 +               return vc_ctx_stat(vxi, data);
23356 +       case VCMD_virt_stat:
23357 +               return vc_virt_stat(vxi, data);
23358 +       case VCMD_sock_stat:
23359 +               return vc_sock_stat(vxi, data);
23360 +       case VCMD_rlimit_stat:
23361 +               return vc_rlimit_stat(vxi, data);
23362 +
23363 +       case VCMD_set_cflags:
23364 +               return vc_set_cflags(vxi, data);
23365 +       case VCMD_get_cflags:
23366 +               return vc_get_cflags(vxi, data);
23367 +
23368 +       /* this is version 1 */
23369 +       case VCMD_set_ccaps:
23370 +               return vc_set_ccaps(vxi, data);
23371 +       /* this is version 1 */
23372 +       case VCMD_get_ccaps:
23373 +               return vc_get_ccaps(vxi, data);
23374 +       case VCMD_set_bcaps:
23375 +               return vc_set_bcaps(vxi, data);
23376 +       case VCMD_get_bcaps:
23377 +               return vc_get_bcaps(vxi, data);
23378 +
23379 +       case VCMD_set_badness:
23380 +               return vc_set_badness(vxi, data);
23381 +       case VCMD_get_badness:
23382 +               return vc_get_badness(vxi, data);
23383 +
23384 +       case VCMD_set_nflags:
23385 +               return vc_set_nflags(nxi, data);
23386 +       case VCMD_get_nflags:
23387 +               return vc_get_nflags(nxi, data);
23388 +
23389 +       case VCMD_set_ncaps:
23390 +               return vc_set_ncaps(nxi, data);
23391 +       case VCMD_get_ncaps:
23392 +               return vc_get_ncaps(nxi, data);
23393 +
23394 +       case VCMD_set_prio_bias:
23395 +               return vc_set_prio_bias(vxi, data);
23396 +       case VCMD_get_prio_bias:
23397 +               return vc_get_prio_bias(vxi, data);
23398 +       case VCMD_add_dlimit:
23399 +               return __COMPAT(vc_add_dlimit, id, data, compat);
23400 +       case VCMD_rem_dlimit:
23401 +               return __COMPAT(vc_rem_dlimit, id, data, compat);
23402 +       case VCMD_set_dlimit:
23403 +               return __COMPAT(vc_set_dlimit, id, data, compat);
23404 +       case VCMD_get_dlimit:
23405 +               return __COMPAT(vc_get_dlimit, id, data, compat);
23406 +
23407 +       case VCMD_ctx_kill:
23408 +               return vc_ctx_kill(vxi, data);
23409 +
23410 +       case VCMD_wait_exit:
23411 +               return vc_wait_exit(vxi, data);
23412 +
23413 +       case VCMD_get_iattr:
23414 +               return __COMPAT_NO_ID(vc_get_iattr, data, compat);
23415 +       case VCMD_set_iattr:
23416 +               return __COMPAT_NO_ID(vc_set_iattr, data, compat);
23417 +
23418 +       case VCMD_fget_iattr:
23419 +               return vc_fget_iattr(id, data);
23420 +       case VCMD_fset_iattr:
23421 +               return vc_fset_iattr(id, data);
23422 +
23423 +       case VCMD_enter_space_v0:
23424 +               return vc_enter_space_v1(vxi, NULL);
23425 +       case VCMD_enter_space_v1:
23426 +               return vc_enter_space_v1(vxi, data);
23427 +       /* this is version 2 */
23428 +       case VCMD_enter_space:
23429 +               return vc_enter_space(vxi, data);
23430 +
23431 +       case VCMD_ctx_create_v0:
23432 +               return vc_ctx_create(id, NULL);
23433 +       case VCMD_ctx_create:
23434 +               return vc_ctx_create(id, data);
23435 +       case VCMD_ctx_migrate_v0:
23436 +               return vc_ctx_migrate(vxi, NULL);
23437 +       case VCMD_ctx_migrate:
23438 +               return vc_ctx_migrate(vxi, data);
23439 +
23440 +       case VCMD_net_create_v0:
23441 +               return vc_net_create(id, NULL);
23442 +       case VCMD_net_create:
23443 +               return vc_net_create(id, data);
23444 +       case VCMD_net_migrate:
23445 +               return vc_net_migrate(nxi, data);
23446 +
23447 +       case VCMD_tag_migrate:
23448 +               return vc_tag_migrate(id);
23449 +
23450 +       case VCMD_net_add:
23451 +               return vc_net_add(nxi, data);
23452 +       case VCMD_net_remove:
23453 +               return vc_net_remove(nxi, data);
23454 +
23455 +       case VCMD_net_add_ipv4_v1:
23456 +               return vc_net_add_ipv4_v1(nxi, data);
23457 +       /* this is version 2 */
23458 +       case VCMD_net_add_ipv4:
23459 +               return vc_net_add_ipv4(nxi, data);
23460 +
23461 +       case VCMD_net_rem_ipv4_v1:
23462 +               return vc_net_rem_ipv4_v1(nxi, data);
23463 +       /* this is version 2 */
23464 +       case VCMD_net_rem_ipv4:
23465 +               return vc_net_rem_ipv4(nxi, data);
23466 +#ifdef CONFIG_IPV6
23467 +       case VCMD_net_add_ipv6:
23468 +               return vc_net_add_ipv6(nxi, data);
23469 +       case VCMD_net_remove_ipv6:
23470 +               return vc_net_remove_ipv6(nxi, data);
23471 +#endif
23472 +/*     case VCMD_add_match_ipv4:
23473 +               return vc_add_match_ipv4(nxi, data);
23474 +       case VCMD_get_match_ipv4:
23475 +               return vc_get_match_ipv4(nxi, data);
23476 +#ifdef CONFIG_IPV6
23477 +       case VCMD_add_match_ipv6:
23478 +               return vc_add_match_ipv6(nxi, data);
23479 +       case VCMD_get_match_ipv6:
23480 +               return vc_get_match_ipv6(nxi, data);
23481 +#endif */
23482 +
23483 +#ifdef CONFIG_VSERVER_DEVICE
23484 +       case VCMD_set_mapping:
23485 +               return __COMPAT(vc_set_mapping, vxi, data, compat);
23486 +       case VCMD_unset_mapping:
23487 +               return __COMPAT(vc_unset_mapping, vxi, data, compat);
23488 +#endif
23489 +#ifdef CONFIG_VSERVER_HISTORY
23490 +       case VCMD_dump_history:
23491 +               return vc_dump_history(id);
23492 +       case VCMD_read_history:
23493 +               return __COMPAT(vc_read_history, id, data, compat);
23494 +#endif
23495 +       default:
23496 +               vxwprintk_task(1, "unimplemented VCMD_%02d_%d[%d]",
23497 +                       VC_CATEGORY(cmd), VC_COMMAND(cmd), VC_VERSION(cmd));
23498 +       }
23499 +       return -ENOSYS;
23500 +}
23501 +
23502 +
23503 +#define        __VCMD(vcmd, _perm, _args, _flags)              \
23504 +       case VCMD_ ## vcmd: perm = _perm;               \
23505 +               args = _args; flags = _flags; break
23506 +
23507 +
23508 +#define VCA_NONE       0x00
23509 +#define VCA_VXI                0x01
23510 +#define VCA_NXI                0x02
23511 +
23512 +#define VCF_NONE       0x00
23513 +#define VCF_INFO       0x01
23514 +#define VCF_ADMIN      0x02
23515 +#define VCF_ARES       0x06    /* includes admin */
23516 +#define VCF_SETUP      0x08
23517 +
23518 +#define VCF_ZIDOK      0x10    /* zero id okay */
23519 +
23520 +
23521 +static inline
23522 +long do_vserver(uint32_t cmd, uint32_t id, void __user *data, int compat)
23523 +{
23524 +       long ret;
23525 +       int permit = -1, state = 0;
23526 +       int perm = -1, args = 0, flags = 0;
23527 +       struct vx_info *vxi = NULL;
23528 +       struct nx_info *nxi = NULL;
23529 +
23530 +       switch (cmd) {
23531 +       /* unpriviledged commands */
23532 +       __VCMD(get_version,      0, VCA_NONE,   0);
23533 +       __VCMD(get_vci,          0, VCA_NONE,   0);
23534 +       __VCMD(get_rlimit_mask,  0, VCA_NONE,   0);
23535 +       __VCMD(get_space_mask_v0,0, VCA_NONE,   0);
23536 +       __VCMD(get_space_mask,   0, VCA_NONE,   0);
23537 +       __VCMD(get_space_default,0, VCA_NONE,   0);
23538 +
23539 +       /* info commands */
23540 +       __VCMD(task_xid,         2, VCA_NONE,   0);
23541 +       __VCMD(reset_hits,       2, VCA_VXI,    0);
23542 +       __VCMD(reset_minmax,     2, VCA_VXI,    0);
23543 +       __VCMD(vx_info,          3, VCA_VXI,    VCF_INFO);
23544 +       __VCMD(get_bcaps,        3, VCA_VXI,    VCF_INFO);
23545 +       __VCMD(get_ccaps,        3, VCA_VXI,    VCF_INFO);
23546 +       __VCMD(get_cflags,       3, VCA_VXI,    VCF_INFO);
23547 +       __VCMD(get_umask,        3, VCA_VXI,    VCF_INFO);
23548 +       __VCMD(get_wmask,        3, VCA_VXI,    VCF_INFO);
23549 +       __VCMD(get_badness,      3, VCA_VXI,    VCF_INFO);
23550 +       __VCMD(get_vhi_name,     3, VCA_VXI,    VCF_INFO);
23551 +       __VCMD(get_rlimit,       3, VCA_VXI,    VCF_INFO);
23552 +
23553 +       __VCMD(ctx_stat,         3, VCA_VXI,    VCF_INFO);
23554 +       __VCMD(virt_stat,        3, VCA_VXI,    VCF_INFO);
23555 +       __VCMD(sock_stat,        3, VCA_VXI,    VCF_INFO);
23556 +       __VCMD(rlimit_stat,      3, VCA_VXI,    VCF_INFO);
23557 +
23558 +       __VCMD(task_nid,         2, VCA_NONE,   0);
23559 +       __VCMD(nx_info,          3, VCA_NXI,    VCF_INFO);
23560 +       __VCMD(get_ncaps,        3, VCA_NXI,    VCF_INFO);
23561 +       __VCMD(get_nflags,       3, VCA_NXI,    VCF_INFO);
23562 +
23563 +       __VCMD(task_tag,         2, VCA_NONE,   0);
23564 +
23565 +       __VCMD(get_iattr,        2, VCA_NONE,   0);
23566 +       __VCMD(fget_iattr,       2, VCA_NONE,   0);
23567 +       __VCMD(get_dlimit,       3, VCA_NONE,   VCF_INFO);
23568 +       __VCMD(get_prio_bias,    3, VCA_VXI,    VCF_INFO);
23569 +
23570 +       /* lower admin commands */
23571 +       __VCMD(wait_exit,        4, VCA_VXI,    VCF_INFO);
23572 +       __VCMD(ctx_create_v0,    5, VCA_NONE,   0);
23573 +       __VCMD(ctx_create,       5, VCA_NONE,   0);
23574 +       __VCMD(ctx_migrate_v0,   5, VCA_VXI,    VCF_ADMIN);
23575 +       __VCMD(ctx_migrate,      5, VCA_VXI,    VCF_ADMIN);
23576 +       __VCMD(enter_space_v0,   5, VCA_VXI,    VCF_ADMIN);
23577 +       __VCMD(enter_space_v1,   5, VCA_VXI,    VCF_ADMIN);
23578 +       __VCMD(enter_space,      5, VCA_VXI,    VCF_ADMIN);
23579 +
23580 +       __VCMD(net_create_v0,    5, VCA_NONE,   0);
23581 +       __VCMD(net_create,       5, VCA_NONE,   0);
23582 +       __VCMD(net_migrate,      5, VCA_NXI,    VCF_ADMIN);
23583 +
23584 +       __VCMD(tag_migrate,      5, VCA_NONE,   VCF_ADMIN);
23585 +
23586 +       /* higher admin commands */
23587 +       __VCMD(ctx_kill,         6, VCA_VXI,    VCF_ARES);
23588 +       __VCMD(set_space_v1,     7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23589 +       __VCMD(set_space,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23590 +
23591 +       __VCMD(set_ccaps,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23592 +       __VCMD(set_bcaps,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23593 +       __VCMD(set_cflags,       7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23594 +       __VCMD(set_umask,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23595 +       __VCMD(set_wmask,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23596 +       __VCMD(set_badness,      7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23597 +
23598 +       __VCMD(set_vhi_name,     7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23599 +       __VCMD(set_rlimit,       7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23600 +       __VCMD(set_prio_bias,    7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23601 +
23602 +       __VCMD(set_ncaps,        7, VCA_NXI,    VCF_ARES | VCF_SETUP);
23603 +       __VCMD(set_nflags,       7, VCA_NXI,    VCF_ARES | VCF_SETUP);
23604 +       __VCMD(net_add,          8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23605 +       __VCMD(net_remove,       8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23606 +       __VCMD(net_add_ipv4_v1,  8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23607 +       __VCMD(net_rem_ipv4_v1,  8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23608 +       __VCMD(net_add_ipv4,     8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23609 +       __VCMD(net_rem_ipv4,     8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23610 +#ifdef CONFIG_IPV6
23611 +       __VCMD(net_add_ipv6,     8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23612 +       __VCMD(net_remove_ipv6,  8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23613 +#endif
23614 +       __VCMD(set_iattr,        7, VCA_NONE,   0);
23615 +       __VCMD(fset_iattr,       7, VCA_NONE,   0);
23616 +       __VCMD(set_dlimit,       7, VCA_NONE,   VCF_ARES);
23617 +       __VCMD(add_dlimit,       8, VCA_NONE,   VCF_ARES);
23618 +       __VCMD(rem_dlimit,       8, VCA_NONE,   VCF_ARES);
23619 +
23620 +#ifdef CONFIG_VSERVER_DEVICE
23621 +       __VCMD(set_mapping,      8, VCA_VXI,    VCF_ARES|VCF_ZIDOK);
23622 +       __VCMD(unset_mapping,    8, VCA_VXI,    VCF_ARES|VCF_ZIDOK);
23623 +#endif
23624 +       /* debug level admin commands */
23625 +#ifdef CONFIG_VSERVER_HISTORY
23626 +       __VCMD(dump_history,     9, VCA_NONE,   0);
23627 +       __VCMD(read_history,     9, VCA_NONE,   0);
23628 +#endif
23629 +
23630 +       default:
23631 +               perm = -1;
23632 +       }
23633 +
23634 +       vxdprintk(VXD_CBIT(switch, 0),
23635 +               "vc: VCMD_%02d_%d[%d], %d,%p [%d,%d,%x,%x]",
23636 +               VC_CATEGORY(cmd), VC_COMMAND(cmd),
23637 +               VC_VERSION(cmd), id, data, compat,
23638 +               perm, args, flags);
23639 +
23640 +       ret = -ENOSYS;
23641 +       if (perm < 0)
23642 +               goto out;
23643 +
23644 +       state = 1;
23645 +       if (!capable(CAP_CONTEXT))
23646 +               goto out;
23647 +
23648 +       state = 2;
23649 +       /* moved here from the individual commands */
23650 +       ret = -EPERM;
23651 +       if ((perm > 1) && !capable(CAP_SYS_ADMIN))
23652 +               goto out;
23653 +
23654 +       state = 3;
23655 +       /* vcmd involves resource management  */
23656 +       ret = -EPERM;
23657 +       if ((flags & VCF_ARES) && !capable(CAP_SYS_RESOURCE))
23658 +               goto out;
23659 +
23660 +       state = 4;
23661 +       /* various legacy exceptions */
23662 +       switch (cmd) {
23663 +       /* will go away when spectator is a cap */
23664 +       case VCMD_ctx_migrate_v0:
23665 +       case VCMD_ctx_migrate:
23666 +               if (id == 1) {
23667 +                       current->xid = 1;
23668 +                       ret = 1;
23669 +                       goto out;
23670 +               }
23671 +               break;
23672 +
23673 +       /* will go away when spectator is a cap */
23674 +       case VCMD_net_migrate:
23675 +               if (id == 1) {
23676 +                       current->nid = 1;
23677 +                       ret = 1;
23678 +                       goto out;
23679 +               }
23680 +               break;
23681 +       }
23682 +
23683 +       /* vcmds are fine by default */
23684 +       permit = 1;
23685 +
23686 +       /* admin type vcmds require admin ... */
23687 +       if (flags & VCF_ADMIN)
23688 +               permit = vx_check(0, VS_ADMIN) ? 1 : 0;
23689 +
23690 +       /* ... but setup type vcmds override that */
23691 +       if (!permit && (flags & VCF_SETUP))
23692 +               permit = vx_flags(VXF_STATE_SETUP, 0) ? 2 : 0;
23693 +
23694 +       state = 5;
23695 +       ret = -EPERM;
23696 +       if (!permit)
23697 +               goto out;
23698 +
23699 +       state = 6;
23700 +       if (!id && (flags & VCF_ZIDOK))
23701 +               goto skip_id;
23702 +
23703 +       ret = -ESRCH;
23704 +       if (args & VCA_VXI) {
23705 +               vxi = lookup_vx_info(id);
23706 +               if (!vxi)
23707 +                       goto out;
23708 +
23709 +               if ((flags & VCF_ADMIN) &&
23710 +                       /* special case kill for shutdown */
23711 +                       (cmd != VCMD_ctx_kill) &&
23712 +                       /* can context be administrated? */
23713 +                       !vx_info_flags(vxi, VXF_STATE_ADMIN, 0)) {
23714 +                       ret = -EACCES;
23715 +                       goto out_vxi;
23716 +               }
23717 +       }
23718 +       state = 7;
23719 +       if (args & VCA_NXI) {
23720 +               nxi = lookup_nx_info(id);
23721 +               if (!nxi)
23722 +                       goto out_vxi;
23723 +
23724 +               if ((flags & VCF_ADMIN) &&
23725 +                       /* can context be administrated? */
23726 +                       !nx_info_flags(nxi, NXF_STATE_ADMIN, 0)) {
23727 +                       ret = -EACCES;
23728 +                       goto out_nxi;
23729 +               }
23730 +       }
23731 +skip_id:
23732 +       state = 8;
23733 +       ret = do_vcmd(cmd, id, vxi, nxi, data, compat);
23734 +
23735 +out_nxi:
23736 +       if ((args & VCA_NXI) && nxi)
23737 +               put_nx_info(nxi);
23738 +out_vxi:
23739 +       if ((args & VCA_VXI) && vxi)
23740 +               put_vx_info(vxi);
23741 +out:
23742 +       vxdprintk(VXD_CBIT(switch, 1),
23743 +               "vc: VCMD_%02d_%d[%d] = %08lx(%ld) [%d,%d]",
23744 +               VC_CATEGORY(cmd), VC_COMMAND(cmd),
23745 +               VC_VERSION(cmd), ret, ret, state, permit);
23746 +       return ret;
23747 +}
23748 +
23749 +asmlinkage long
23750 +sys_vserver(uint32_t cmd, uint32_t id, void __user *data)
23751 +{
23752 +       return do_vserver(cmd, id, data, 0);
23753 +}
23754 +
23755 +#ifdef CONFIG_COMPAT
23756 +
23757 +asmlinkage long
23758 +sys32_vserver(uint32_t cmd, uint32_t id, void __user *data)
23759 +{
23760 +       return do_vserver(cmd, id, data, 1);
23761 +}
23762 +
23763 +#endif /* CONFIG_COMPAT */
23764 diff -NurpP --minimal linux-3.0.25/kernel/vserver/sysctl.c linux-3.0.25-vs2.3.2.3/kernel/vserver/sysctl.c
23765 --- linux-3.0.25/kernel/vserver/sysctl.c        1970-01-01 01:00:00.000000000 +0100
23766 +++ linux-3.0.25-vs2.3.2.3/kernel/vserver/sysctl.c      2011-10-27 15:18:40.000000000 +0200
23767 @@ -0,0 +1,247 @@
23768 +/*
23769 + *  kernel/vserver/sysctl.c
23770 + *
23771 + *  Virtual Context Support
23772 + *
23773 + *  Copyright (C) 2004-2007  Herbert Pötzl
23774 + *
23775 + *  V0.01  basic structure
23776 + *
23777 + */
23778 +
23779 +#include <linux/module.h>
23780 +#include <linux/ctype.h>
23781 +#include <linux/sysctl.h>
23782 +#include <linux/parser.h>
23783 +#include <asm/uaccess.h>
23784 +
23785 +enum {
23786 +       CTL_DEBUG_ERROR         = 0,
23787 +       CTL_DEBUG_SWITCH        = 1,
23788 +       CTL_DEBUG_XID,
23789 +       CTL_DEBUG_NID,
23790 +       CTL_DEBUG_TAG,
23791 +       CTL_DEBUG_NET,
23792 +       CTL_DEBUG_LIMIT,
23793 +       CTL_DEBUG_CRES,
23794 +       CTL_DEBUG_DLIM,
23795 +       CTL_DEBUG_QUOTA,
23796 +       CTL_DEBUG_CVIRT,
23797 +       CTL_DEBUG_SPACE,
23798 +       CTL_DEBUG_PERM,
23799 +       CTL_DEBUG_MISC,
23800 +};
23801 +
23802 +
23803 +unsigned int vs_debug_switch   = 0;
23804 +unsigned int vs_debug_xid      = 0;
23805 +unsigned int vs_debug_nid      = 0;
23806 +unsigned int vs_debug_tag      = 0;
23807 +unsigned int vs_debug_net      = 0;
23808 +unsigned int vs_debug_limit    = 0;
23809 +unsigned int vs_debug_cres     = 0;
23810 +unsigned int vs_debug_dlim     = 0;
23811 +unsigned int vs_debug_quota    = 0;
23812 +unsigned int vs_debug_cvirt    = 0;
23813 +unsigned int vs_debug_space    = 0;
23814 +unsigned int vs_debug_perm     = 0;
23815 +unsigned int vs_debug_misc     = 0;
23816 +
23817 +
23818 +static struct ctl_table_header *vserver_table_header;
23819 +static ctl_table vserver_root_table[];
23820 +
23821 +
23822 +void vserver_register_sysctl(void)
23823 +{
23824 +       if (!vserver_table_header) {
23825 +               vserver_table_header = register_sysctl_table(vserver_root_table);
23826 +       }
23827 +
23828 +}
23829 +
23830 +void vserver_unregister_sysctl(void)
23831 +{
23832 +       if (vserver_table_header) {
23833 +               unregister_sysctl_table(vserver_table_header);
23834 +               vserver_table_header = NULL;
23835 +       }
23836 +}
23837 +
23838 +
23839 +static int proc_dodebug(ctl_table *table, int write,
23840 +       void __user *buffer, size_t *lenp, loff_t *ppos)
23841 +{
23842 +       char            tmpbuf[20], *p, c;
23843 +       unsigned int    value;
23844 +       size_t          left, len;
23845 +
23846 +       if ((*ppos && !write) || !*lenp) {
23847 +               *lenp = 0;
23848 +               return 0;
23849 +       }
23850 +
23851 +       left = *lenp;
23852 +
23853 +       if (write) {
23854 +               if (!access_ok(VERIFY_READ, buffer, left))
23855 +                       return -EFAULT;
23856 +               p = (char *)buffer;
23857 +               while (left && __get_user(c, p) >= 0 && isspace(c))
23858 +                       left--, p++;
23859 +               if (!left)
23860 +                       goto done;
23861 +
23862 +               if (left > sizeof(tmpbuf) - 1)
23863 +                       return -EINVAL;
23864 +               if (copy_from_user(tmpbuf, p, left))
23865 +                       return -EFAULT;
23866 +               tmpbuf[left] = '\0';
23867 +
23868 +               for (p = tmpbuf, value = 0; '0' <= *p && *p <= '9'; p++, left--)
23869 +                       value = 10 * value + (*p - '0');
23870 +               if (*p && !isspace(*p))
23871 +                       return -EINVAL;
23872 +               while (left && isspace(*p))
23873 +                       left--, p++;
23874 +               *(unsigned int *)table->data = value;
23875 +       } else {
23876 +               if (!access_ok(VERIFY_WRITE, buffer, left))
23877 +                       return -EFAULT;
23878 +               len = sprintf(tmpbuf, "%d", *(unsigned int *)table->data);
23879 +               if (len > left)
23880 +                       len = left;
23881 +               if (__copy_to_user(buffer, tmpbuf, len))
23882 +                       return -EFAULT;
23883 +               if ((left -= len) > 0) {
23884 +                       if (put_user('\n', (char *)buffer + len))
23885 +                               return -EFAULT;
23886 +                       left--;
23887 +               }
23888 +       }
23889 +
23890 +done:
23891 +       *lenp -= left;
23892 +       *ppos += *lenp;
23893 +       return 0;
23894 +}
23895 +
23896 +static int zero;
23897 +
23898 +#define        CTL_ENTRY(ctl, name)                            \
23899 +       {                                               \
23900 +               .procname       = #name,                \
23901 +               .data           = &vs_ ## name,         \
23902 +               .maxlen         = sizeof(int),          \
23903 +               .mode           = 0644,                 \
23904 +               .proc_handler   = &proc_dodebug,        \
23905 +               .extra1         = &zero,                \
23906 +               .extra2         = &zero,                \
23907 +       }
23908 +
23909 +static ctl_table vserver_debug_table[] = {
23910 +       CTL_ENTRY(CTL_DEBUG_SWITCH,     debug_switch),
23911 +       CTL_ENTRY(CTL_DEBUG_XID,        debug_xid),
23912 +       CTL_ENTRY(CTL_DEBUG_NID,        debug_nid),
23913 +       CTL_ENTRY(CTL_DEBUG_TAG,        debug_tag),
23914 +       CTL_ENTRY(CTL_DEBUG_NET,        debug_net),
23915 +       CTL_ENTRY(CTL_DEBUG_LIMIT,      debug_limit),
23916 +       CTL_ENTRY(CTL_DEBUG_CRES,       debug_cres),
23917 +       CTL_ENTRY(CTL_DEBUG_DLIM,       debug_dlim),
23918 +       CTL_ENTRY(CTL_DEBUG_QUOTA,      debug_quota),
23919 +       CTL_ENTRY(CTL_DEBUG_CVIRT,      debug_cvirt),
23920 +       CTL_ENTRY(CTL_DEBUG_SPACE,      debug_space),
23921 +       CTL_ENTRY(CTL_DEBUG_PERM,       debug_perm),
23922 +       CTL_ENTRY(CTL_DEBUG_MISC,       debug_misc),
23923 +       { 0 }
23924 +};
23925 +
23926 +static ctl_table vserver_root_table[] = {
23927 +       {
23928 +               .procname       = "vserver",
23929 +               .mode           = 0555,
23930 +               .child          = vserver_debug_table
23931 +       },
23932 +       { 0 }
23933 +};
23934 +
23935 +
23936 +static match_table_t tokens = {
23937 +       { CTL_DEBUG_SWITCH,     "switch=%x"     },
23938 +       { CTL_DEBUG_XID,        "xid=%x"        },
23939 +       { CTL_DEBUG_NID,        "nid=%x"        },
23940 +       { CTL_DEBUG_TAG,        "tag=%x"        },
23941 +       { CTL_DEBUG_NET,        "net=%x"        },
23942 +       { CTL_DEBUG_LIMIT,      "limit=%x"      },
23943 +       { CTL_DEBUG_CRES,       "cres=%x"       },
23944 +       { CTL_DEBUG_DLIM,       "dlim=%x"       },
23945 +       { CTL_DEBUG_QUOTA,      "quota=%x"      },
23946 +       { CTL_DEBUG_CVIRT,      "cvirt=%x"      },
23947 +       { CTL_DEBUG_SPACE,      "space=%x"      },
23948 +       { CTL_DEBUG_PERM,       "perm=%x"       },
23949 +       { CTL_DEBUG_MISC,       "misc=%x"       },
23950 +       { CTL_DEBUG_ERROR,      NULL            }
23951 +};
23952 +
23953 +#define        HANDLE_CASE(id, name, val)                              \
23954 +       case CTL_DEBUG_ ## id:                                  \
23955 +               vs_debug_ ## name = val;                        \
23956 +               printk("vs_debug_" #name "=0x%x\n", val);       \
23957 +               break
23958 +
23959 +
23960 +static int __init vs_debug_setup(char *str)
23961 +{
23962 +       char *p;
23963 +       int token;
23964 +
23965 +       printk("vs_debug_setup(%s)\n", str);
23966 +       while ((p = strsep(&str, ",")) != NULL) {
23967 +               substring_t args[MAX_OPT_ARGS];
23968 +               unsigned int value;
23969 +
23970 +               if (!*p)
23971 +                       continue;
23972 +
23973 +               token = match_token(p, tokens, args);
23974 +               value = (token > 0) ? simple_strtoul(args[0].from, NULL, 0) : 0;
23975 +
23976 +               switch (token) {
23977 +               HANDLE_CASE(SWITCH, switch, value);
23978 +               HANDLE_CASE(XID,    xid,    value);
23979 +               HANDLE_CASE(NID,    nid,    value);
23980 +               HANDLE_CASE(TAG,    tag,    value);
23981 +               HANDLE_CASE(NET,    net,    value);
23982 +               HANDLE_CASE(LIMIT,  limit,  value);
23983 +               HANDLE_CASE(CRES,   cres,   value);
23984 +               HANDLE_CASE(DLIM,   dlim,   value);
23985 +               HANDLE_CASE(QUOTA,  quota,  value);
23986 +               HANDLE_CASE(CVIRT,  cvirt,  value);
23987 +               HANDLE_CASE(SPACE,  space,  value);
23988 +               HANDLE_CASE(PERM,   perm,   value);
23989 +               HANDLE_CASE(MISC,   misc,   value);
23990 +               default:
23991 +                       return -EINVAL;
23992 +                       break;
23993 +               }
23994 +       }
23995 +       return 1;
23996 +}
23997 +
23998 +__setup("vsdebug=", vs_debug_setup);
23999 +
24000 +
24001 +
24002 +EXPORT_SYMBOL_GPL(vs_debug_switch);
24003 +EXPORT_SYMBOL_GPL(vs_debug_xid);
24004 +EXPORT_SYMBOL_GPL(vs_debug_nid);
24005 +EXPORT_SYMBOL_GPL(vs_debug_net);
24006 +EXPORT_SYMBOL_GPL(vs_debug_limit);
24007 +EXPORT_SYMBOL_GPL(vs_debug_cres);
24008 +EXPORT_SYMBOL_GPL(vs_debug_dlim);
24009 +EXPORT_SYMBOL_GPL(vs_debug_quota);
24010 +EXPORT_SYMBOL_GPL(vs_debug_cvirt);
24011 +EXPORT_SYMBOL_GPL(vs_debug_space);
24012 +EXPORT_SYMBOL_GPL(vs_debug_perm);
24013 +EXPORT_SYMBOL_GPL(vs_debug_misc);
24014 +
24015 diff -NurpP --minimal linux-3.0.25/kernel/vserver/tag.c linux-3.0.25-vs2.3.2.3/kernel/vserver/tag.c
24016 --- linux-3.0.25/kernel/vserver/tag.c   1970-01-01 01:00:00.000000000 +0100
24017 +++ linux-3.0.25-vs2.3.2.3/kernel/vserver/tag.c 2011-06-10 22:11:24.000000000 +0200
24018 @@ -0,0 +1,63 @@
24019 +/*
24020 + *  linux/kernel/vserver/tag.c
24021 + *
24022 + *  Virtual Server: Shallow Tag Space
24023 + *
24024 + *  Copyright (C) 2007  Herbert Pötzl
24025 + *
24026 + *  V0.01  basic implementation
24027 + *
24028 + */
24029 +
24030 +#include <linux/sched.h>
24031 +#include <linux/vserver/debug.h>
24032 +#include <linux/vs_pid.h>
24033 +#include <linux/vs_tag.h>
24034 +
24035 +#include <linux/vserver/tag_cmd.h>
24036 +
24037 +
24038 +int dx_migrate_task(struct task_struct *p, tag_t tag)
24039 +{
24040 +       if (!p)
24041 +               BUG();
24042 +
24043 +       vxdprintk(VXD_CBIT(tag, 5),
24044 +               "dx_migrate_task(%p[#%d],#%d)", p, p->tag, tag);
24045 +
24046 +       task_lock(p);
24047 +       p->tag = tag;
24048 +       task_unlock(p);
24049 +
24050 +       vxdprintk(VXD_CBIT(tag, 5),
24051 +               "moved task %p into [#%d]", p, tag);
24052 +       return 0;
24053 +}
24054 +
24055 +/* vserver syscall commands below here */
24056 +
24057 +/* taks xid and vx_info functions */
24058 +
24059 +
24060 +int vc_task_tag(uint32_t id)
24061 +{
24062 +       tag_t tag;
24063 +
24064 +       if (id) {
24065 +               struct task_struct *tsk;
24066 +               rcu_read_lock();
24067 +               tsk = find_task_by_real_pid(id);
24068 +               tag = (tsk) ? tsk->tag : -ESRCH;
24069 +               rcu_read_unlock();
24070 +       } else
24071 +               tag = dx_current_tag();
24072 +       return tag;
24073 +}
24074 +
24075 +
24076 +int vc_tag_migrate(uint32_t tag)
24077 +{
24078 +       return dx_migrate_task(current, tag & 0xFFFF);
24079 +}
24080 +
24081 +
24082 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
24083 --- linux-3.0.25/kernel/vserver/vci_config.h    1970-01-01 01:00:00.000000000 +0100
24084 +++ linux-3.0.25-vs2.3.2.3/kernel/vserver/vci_config.h  2011-06-10 22:11:24.000000000 +0200
24085 @@ -0,0 +1,76 @@
24086 +
24087 +/*  interface version */
24088 +
24089 +#define VCI_VERSION            0x00020308
24090 +
24091 +
24092 +enum {
24093 +       VCI_KCBIT_NO_DYNAMIC = 0,
24094 +
24095 +       VCI_KCBIT_PROC_SECURE = 4,
24096 +       /* VCI_KCBIT_HARDCPU = 5, */
24097 +       /* VCI_KCBIT_IDLELIMIT = 6, */
24098 +       /* VCI_KCBIT_IDLETIME = 7, */
24099 +
24100 +       VCI_KCBIT_COWBL = 8,
24101 +       VCI_KCBIT_FULLCOWBL = 9,
24102 +       VCI_KCBIT_SPACES = 10,
24103 +       VCI_KCBIT_NETV2 = 11,
24104 +       VCI_KCBIT_MEMCG = 12,
24105 +
24106 +       VCI_KCBIT_DEBUG = 16,
24107 +       VCI_KCBIT_HISTORY = 20,
24108 +       VCI_KCBIT_TAGGED = 24,
24109 +       VCI_KCBIT_PPTAG = 28,
24110 +
24111 +       VCI_KCBIT_MORE = 31,
24112 +};
24113 +
24114 +
24115 +static inline uint32_t vci_kernel_config(void)
24116 +{
24117 +       return
24118 +       (1 << VCI_KCBIT_NO_DYNAMIC) |
24119 +
24120 +       /* configured features */
24121 +#ifdef CONFIG_VSERVER_PROC_SECURE
24122 +       (1 << VCI_KCBIT_PROC_SECURE) |
24123 +#endif
24124 +#ifdef CONFIG_VSERVER_COWBL
24125 +       (1 << VCI_KCBIT_COWBL) |
24126 +       (1 << VCI_KCBIT_FULLCOWBL) |
24127 +#endif
24128 +       (1 << VCI_KCBIT_SPACES) |
24129 +       (1 << VCI_KCBIT_NETV2) |
24130 +#ifdef CONFIG_CGROUP_MEM_RES_CTLR
24131 +       (1 << VCI_KCBIT_MEMCG) |
24132 +#endif
24133 +
24134 +       /* debug options */
24135 +#ifdef CONFIG_VSERVER_DEBUG
24136 +       (1 << VCI_KCBIT_DEBUG) |
24137 +#endif
24138 +#ifdef CONFIG_VSERVER_HISTORY
24139 +       (1 << VCI_KCBIT_HISTORY) |
24140 +#endif
24141 +
24142 +       /* inode context tagging */
24143 +#if    defined(CONFIG_TAGGING_NONE)
24144 +       (0 << VCI_KCBIT_TAGGED) |
24145 +#elif  defined(CONFIG_TAGGING_UID16)
24146 +       (1 << VCI_KCBIT_TAGGED) |
24147 +#elif  defined(CONFIG_TAGGING_GID16)
24148 +       (2 << VCI_KCBIT_TAGGED) |
24149 +#elif  defined(CONFIG_TAGGING_ID24)
24150 +       (3 << VCI_KCBIT_TAGGED) |
24151 +#elif  defined(CONFIG_TAGGING_INTERN)
24152 +       (4 << VCI_KCBIT_TAGGED) |
24153 +#elif  defined(CONFIG_TAGGING_RUNTIME)
24154 +       (5 << VCI_KCBIT_TAGGED) |
24155 +#else
24156 +       (7 << VCI_KCBIT_TAGGED) |
24157 +#endif
24158 +       (1 << VCI_KCBIT_PPTAG) |
24159 +       0;
24160 +}
24161 +
24162 diff -NurpP --minimal linux-3.0.25/mm/filemap_xip.c linux-3.0.25-vs2.3.2.3/mm/filemap_xip.c
24163 --- linux-3.0.25/mm/filemap_xip.c       2012-03-19 21:16:56.000000000 +0100
24164 +++ linux-3.0.25-vs2.3.2.3/mm/filemap_xip.c     2012-02-15 05:20:43.000000000 +0100
24165 @@ -18,6 +18,7 @@
24166  #include <linux/seqlock.h>
24167  #include <linux/mutex.h>
24168  #include <linux/gfp.h>
24169 +#include <linux/vs_memory.h>
24170  #include <asm/tlbflush.h>
24171  #include <asm/io.h>
24172  
24173 diff -NurpP --minimal linux-3.0.25/mm/fremap.c linux-3.0.25-vs2.3.2.3/mm/fremap.c
24174 --- linux-3.0.25/mm/fremap.c    2011-07-22 11:18:12.000000000 +0200
24175 +++ linux-3.0.25-vs2.3.2.3/mm/fremap.c  2011-06-10 22:11:24.000000000 +0200
24176 @@ -16,6 +16,7 @@
24177  #include <linux/module.h>
24178  #include <linux/syscalls.h>
24179  #include <linux/mmu_notifier.h>
24180 +#include <linux/vs_memory.h>
24181  
24182  #include <asm/mmu_context.h>
24183  #include <asm/cacheflush.h>
24184 diff -NurpP --minimal linux-3.0.25/mm/hugetlb.c linux-3.0.25-vs2.3.2.3/mm/hugetlb.c
24185 --- linux-3.0.25/mm/hugetlb.c   2012-03-19 21:16:56.000000000 +0100
24186 +++ linux-3.0.25-vs2.3.2.3/mm/hugetlb.c 2012-01-10 09:19:13.000000000 +0100
24187 @@ -28,6 +28,7 @@
24188  
24189  #include <linux/hugetlb.h>
24190  #include <linux/node.h>
24191 +#include <linux/vs_memory.h>
24192  #include "internal.h"
24193  
24194  const unsigned long hugetlb_zero = 0, hugetlb_infinity = ~0UL;
24195 diff -NurpP --minimal linux-3.0.25/mm/memcontrol.c linux-3.0.25-vs2.3.2.3/mm/memcontrol.c
24196 --- linux-3.0.25/mm/memcontrol.c        2012-03-19 21:16:56.000000000 +0100
24197 +++ linux-3.0.25-vs2.3.2.3/mm/memcontrol.c      2012-03-15 13:32:35.000000000 +0100
24198 @@ -741,6 +741,31 @@ struct mem_cgroup *mem_cgroup_from_task(
24199                                 struct mem_cgroup, css);
24200  }
24201  
24202 +u64 mem_cgroup_res_read_u64(struct mem_cgroup *mem, int member)
24203 +{
24204 +       return res_counter_read_u64(&mem->res, member);
24205 +}
24206 +
24207 +u64 mem_cgroup_memsw_read_u64(struct mem_cgroup *mem, int member)
24208 +{
24209 +       return res_counter_read_u64(&mem->memsw, member);
24210 +}
24211 +
24212 +s64 mem_cgroup_stat_read_cache(struct mem_cgroup *mem)
24213 +{
24214 +       return mem_cgroup_read_stat(mem, MEM_CGROUP_STAT_CACHE);
24215 +}
24216 +
24217 +s64 mem_cgroup_stat_read_anon(struct mem_cgroup *mem)
24218 +{
24219 +       return mem_cgroup_read_stat(mem, MEM_CGROUP_STAT_RSS);
24220 +}
24221 +
24222 +s64 mem_cgroup_stat_read_mapped(struct mem_cgroup *mem)
24223 +{
24224 +       return mem_cgroup_read_stat(mem, MEM_CGROUP_STAT_FILE_MAPPED);
24225 +}
24226 +
24227  struct mem_cgroup *try_get_mem_cgroup_from_mm(struct mm_struct *mm)
24228  {
24229         struct mem_cgroup *mem = NULL;
24230 diff -NurpP --minimal linux-3.0.25/mm/memory.c linux-3.0.25-vs2.3.2.3/mm/memory.c
24231 --- linux-3.0.25/mm/memory.c    2012-03-19 21:16:56.000000000 +0100
24232 +++ linux-3.0.25-vs2.3.2.3/mm/memory.c  2011-11-15 17:37:07.000000000 +0100
24233 @@ -3388,6 +3388,7 @@ int handle_pte_fault(struct mm_struct *m
24234  {
24235         pte_t entry;
24236         spinlock_t *ptl;
24237 +       int ret = 0, type = VXPT_UNKNOWN;
24238  
24239         entry = *pte;
24240         if (!pte_present(entry)) {
24241 @@ -3412,9 +3413,12 @@ int handle_pte_fault(struct mm_struct *m
24242         if (unlikely(!pte_same(*pte, entry)))
24243                 goto unlock;
24244         if (flags & FAULT_FLAG_WRITE) {
24245 -               if (!pte_write(entry))
24246 -                       return do_wp_page(mm, vma, address,
24247 +               if (!pte_write(entry)) {
24248 +                       ret = do_wp_page(mm, vma, address,
24249                                         pte, pmd, ptl, entry);
24250 +                       type = VXPT_WRITE;
24251 +                       goto out;
24252 +               }
24253                 entry = pte_mkdirty(entry);
24254         }
24255         entry = pte_mkyoung(entry);
24256 @@ -3432,7 +3436,10 @@ int handle_pte_fault(struct mm_struct *m
24257         }
24258  unlock:
24259         pte_unmap_unlock(pte, ptl);
24260 -       return 0;
24261 +       ret = 0;
24262 +out:
24263 +       vx_page_fault(mm, vma, type, ret);
24264 +       return ret;
24265  }
24266  
24267  /*
24268 diff -NurpP --minimal linux-3.0.25/mm/mremap.c linux-3.0.25-vs2.3.2.3/mm/mremap.c
24269 --- linux-3.0.25/mm/mremap.c    2011-07-22 11:18:12.000000000 +0200
24270 +++ linux-3.0.25-vs2.3.2.3/mm/mremap.c  2011-06-10 22:11:24.000000000 +0200
24271 @@ -19,6 +19,7 @@
24272  #include <linux/security.h>
24273  #include <linux/syscalls.h>
24274  #include <linux/mmu_notifier.h>
24275 +#include <linux/vs_memory.h>
24276  
24277  #include <asm/uaccess.h>
24278  #include <asm/cacheflush.h>
24279 diff -NurpP --minimal linux-3.0.25/mm/oom_kill.c linux-3.0.25-vs2.3.2.3/mm/oom_kill.c
24280 --- linux-3.0.25/mm/oom_kill.c  2012-03-19 21:16:56.000000000 +0100
24281 +++ linux-3.0.25-vs2.3.2.3/mm/oom_kill.c        2012-01-10 09:19:13.000000000 +0100
24282 @@ -32,6 +32,9 @@
24283  #include <linux/mempolicy.h>
24284  #include <linux/security.h>
24285  #include <linux/ptrace.h>
24286 +#include <linux/reboot.h>
24287 +#include <linux/vs_memory.h>
24288 +#include <linux/vs_context.h>
24289  
24290  int sysctl_panic_on_oom;
24291  int sysctl_oom_kill_allocating_task;
24292 @@ -134,11 +137,18 @@ struct task_struct *find_lock_task_mm(st
24293  static bool oom_unkillable_task(struct task_struct *p,
24294                 const struct mem_cgroup *mem, const nodemask_t *nodemask)
24295  {
24296 -       if (is_global_init(p))
24297 +       unsigned xid = vx_current_xid();
24298 +
24299 +       /* skip the init task, global and per guest */
24300 +       if (task_is_init(p))
24301                 return true;
24302         if (p->flags & PF_KTHREAD)
24303                 return true;
24304  
24305 +       /* skip other guest and host processes if oom in guest */
24306 +       if (xid && vx_task_xid(p) != xid)
24307 +               return true;
24308 +
24309         /* When mem_cgroup_out_of_memory() and p is not member of the group */
24310         if (mem && !task_in_mem_cgroup(p, mem))
24311                 return true;
24312 @@ -214,6 +224,18 @@ unsigned int oom_badness(struct task_str
24313         points += p->signal->oom_score_adj;
24314  
24315         /*
24316 +        * add points for context badness and
24317 +        * reduce badness for processes belonging to
24318 +        * a different context
24319 +        */
24320 +
24321 +       points += vx_badness(p, p->mm);
24322 +
24323 +       if ((vx_current_xid() > 1) &&
24324 +               vx_current_xid() != vx_task_xid(p))
24325 +               points /= 16;
24326 +
24327 +       /*
24328          * Never return 0 for an eligible task that may be killed since it's
24329          * possible that no single user task uses more than 0.1% of memory and
24330          * no single admin tasks uses more than 3.0%.
24331 @@ -429,8 +451,8 @@ static int oom_kill_task(struct task_str
24332         /* mm cannot be safely dereferenced after task_unlock(p) */
24333         mm = p->mm;
24334  
24335 -       pr_err("Killed process %d (%s) total-vm:%lukB, anon-rss:%lukB, file-rss:%lukB\n",
24336 -               task_pid_nr(p), p->comm, K(p->mm->total_vm),
24337 +       pr_err("Killed process %d:#%u (%s) total-vm:%lukB, anon-rss:%lukB, file-rss:%lukB\n",
24338 +               task_pid_nr(p), p->xid, p->comm, K(p->mm->total_vm),
24339                 K(get_mm_counter(p->mm, MM_ANONPAGES)),
24340                 K(get_mm_counter(p->mm, MM_FILEPAGES)));
24341         task_unlock(p);
24342 @@ -484,8 +506,8 @@ static int oom_kill_process(struct task_
24343         }
24344  
24345         task_lock(p);
24346 -       pr_err("%s: Kill process %d (%s) score %d or sacrifice child\n",
24347 -               message, task_pid_nr(p), p->comm, points);
24348 +       pr_err("%s: Kill process %d:#%u (%s) score %d or sacrifice child\n",
24349 +               message, task_pid_nr(p), p->xid, p->comm, points);
24350         task_unlock(p);
24351  
24352         /*
24353 @@ -586,6 +608,8 @@ int unregister_oom_notifier(struct notif
24354  }
24355  EXPORT_SYMBOL_GPL(unregister_oom_notifier);
24356  
24357 +long vs_oom_action(unsigned int);
24358 +
24359  /*
24360   * Try to acquire the OOM killer lock for the zones in zonelist.  Returns zero
24361   * if a parallel OOM killing is already taking place that includes a zone in
24362 @@ -744,7 +768,12 @@ retry:
24363         if (!p) {
24364                 dump_header(NULL, gfp_mask, order, NULL, mpol_mask);
24365                 read_unlock(&tasklist_lock);
24366 -               panic("Out of memory and no killable processes...\n");
24367 +
24368 +               /* avoid panic for guest OOM */
24369 +               if (current->xid)
24370 +                       vs_oom_action(LINUX_REBOOT_CMD_OOM);
24371 +               else
24372 +                       panic("Out of memory and no killable processes...\n");
24373         }
24374  
24375         if (oom_kill_process(p, gfp_mask, order, points, totalpages, NULL,
24376 diff -NurpP --minimal linux-3.0.25/mm/page_alloc.c linux-3.0.25-vs2.3.2.3/mm/page_alloc.c
24377 --- linux-3.0.25/mm/page_alloc.c        2012-03-19 21:16:56.000000000 +0100
24378 +++ linux-3.0.25-vs2.3.2.3/mm/page_alloc.c      2012-01-26 08:39:53.000000000 +0100
24379 @@ -57,6 +57,8 @@
24380  #include <linux/ftrace_event.h>
24381  #include <linux/memcontrol.h>
24382  #include <linux/prefetch.h>
24383 +#include <linux/vs_base.h>
24384 +#include <linux/vs_limit.h>
24385  
24386  #include <asm/tlbflush.h>
24387  #include <asm/div64.h>
24388 @@ -2502,6 +2504,9 @@ void si_meminfo(struct sysinfo *val)
24389         val->totalhigh = totalhigh_pages;
24390         val->freehigh = nr_free_highpages();
24391         val->mem_unit = PAGE_SIZE;
24392 +
24393 +       if (vx_flags(VXF_VIRT_MEM, 0))
24394 +               vx_vsi_meminfo(val);
24395  }
24396  
24397  EXPORT_SYMBOL(si_meminfo);
24398 @@ -2522,6 +2527,9 @@ void si_meminfo_node(struct sysinfo *val
24399         val->freehigh = 0;
24400  #endif
24401         val->mem_unit = PAGE_SIZE;
24402 +
24403 +       if (vx_flags(VXF_VIRT_MEM, 0))
24404 +               vx_vsi_meminfo(val);
24405  }
24406  #endif
24407  
24408 diff -NurpP --minimal linux-3.0.25/mm/pgtable-generic.c linux-3.0.25-vs2.3.2.3/mm/pgtable-generic.c
24409 --- linux-3.0.25/mm/pgtable-generic.c   2011-03-15 18:07:42.000000000 +0100
24410 +++ linux-3.0.25-vs2.3.2.3/mm/pgtable-generic.c 2011-06-10 22:11:24.000000000 +0200
24411 @@ -6,6 +6,8 @@
24412   *  Copyright (C) 2010  Linus Torvalds
24413   */
24414  
24415 +#include <linux/mm.h>
24416 +
24417  #include <linux/pagemap.h>
24418  #include <asm/tlb.h>
24419  #include <asm-generic/pgtable.h>
24420 diff -NurpP --minimal linux-3.0.25/mm/rmap.c linux-3.0.25-vs2.3.2.3/mm/rmap.c
24421 --- linux-3.0.25/mm/rmap.c      2011-07-22 11:18:12.000000000 +0200
24422 +++ linux-3.0.25-vs2.3.2.3/mm/rmap.c    2011-07-01 11:35:35.000000000 +0200
24423 @@ -57,6 +57,7 @@
24424  #include <linux/mmu_notifier.h>
24425  #include <linux/migrate.h>
24426  #include <linux/hugetlb.h>
24427 +#include <linux/vs_memory.h>
24428  
24429  #include <asm/tlbflush.h>
24430  
24431 diff -NurpP --minimal linux-3.0.25/mm/shmem.c linux-3.0.25-vs2.3.2.3/mm/shmem.c
24432 --- linux-3.0.25/mm/shmem.c     2011-07-22 11:18:12.000000000 +0200
24433 +++ linux-3.0.25-vs2.3.2.3/mm/shmem.c   2011-07-01 11:35:35.000000000 +0200
24434 @@ -1850,7 +1850,7 @@ static int shmem_statfs(struct dentry *d
24435  {
24436         struct shmem_sb_info *sbinfo = SHMEM_SB(dentry->d_sb);
24437  
24438 -       buf->f_type = TMPFS_MAGIC;
24439 +       buf->f_type = TMPFS_SUPER_MAGIC;
24440         buf->f_bsize = PAGE_CACHE_SIZE;
24441         buf->f_namelen = NAME_MAX;
24442         if (sbinfo->max_blocks) {
24443 @@ -2605,7 +2605,7 @@ int shmem_fill_super(struct super_block 
24444         sb->s_maxbytes = SHMEM_MAX_BYTES;
24445         sb->s_blocksize = PAGE_CACHE_SIZE;
24446         sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
24447 -       sb->s_magic = TMPFS_MAGIC;
24448 +       sb->s_magic = TMPFS_SUPER_MAGIC;
24449         sb->s_op = &shmem_ops;
24450         sb->s_time_gran = 1;
24451  #ifdef CONFIG_TMPFS_XATTR
24452 diff -NurpP --minimal linux-3.0.25/mm/slab.c linux-3.0.25-vs2.3.2.3/mm/slab.c
24453 --- linux-3.0.25/mm/slab.c      2011-07-22 11:18:12.000000000 +0200
24454 +++ linux-3.0.25-vs2.3.2.3/mm/slab.c    2011-06-15 02:41:23.000000000 +0200
24455 @@ -411,6 +411,8 @@ static void kmem_list3_init(struct kmem_
24456  #define STATS_INC_FREEMISS(x)  do { } while (0)
24457  #endif
24458  
24459 +#include "slab_vs.h"
24460 +
24461  #if DEBUG
24462  
24463  /*
24464 @@ -3348,6 +3350,7 @@ retry:
24465  
24466         obj = slab_get_obj(cachep, slabp, nodeid);
24467         check_slabp(cachep, slabp);
24468 +       vx_slab_alloc(cachep, flags);
24469         l3->free_objects--;
24470         /* move slabp to correct slabp list: */
24471         list_del(&slabp->list);
24472 @@ -3425,6 +3428,7 @@ __cache_alloc_node(struct kmem_cache *ca
24473         /* ___cache_alloc_node can fall back to other nodes */
24474         ptr = ____cache_alloc_node(cachep, flags, nodeid);
24475    out:
24476 +       vx_slab_alloc(cachep, flags);
24477         local_irq_restore(save_flags);
24478         ptr = cache_alloc_debugcheck_after(cachep, flags, ptr, caller);
24479         kmemleak_alloc_recursive(ptr, obj_size(cachep), 1, cachep->flags,
24480 @@ -3612,6 +3616,7 @@ static inline void __cache_free(struct k
24481         check_irq_off();
24482         kmemleak_free_recursive(objp, cachep->flags);
24483         objp = cache_free_debugcheck(cachep, objp, caller);
24484 +       vx_slab_free(cachep);
24485  
24486         kmemcheck_slab_free(cachep, objp, obj_size(cachep));
24487  
24488 diff -NurpP --minimal linux-3.0.25/mm/slab_vs.h linux-3.0.25-vs2.3.2.3/mm/slab_vs.h
24489 --- linux-3.0.25/mm/slab_vs.h   1970-01-01 01:00:00.000000000 +0100
24490 +++ linux-3.0.25-vs2.3.2.3/mm/slab_vs.h 2011-06-10 22:11:24.000000000 +0200
24491 @@ -0,0 +1,29 @@
24492 +
24493 +#include <linux/vserver/context.h>
24494 +
24495 +#include <linux/vs_context.h>
24496 +
24497 +static inline
24498 +void vx_slab_alloc(struct kmem_cache *cachep, gfp_t flags)
24499 +{
24500 +       int what = gfp_zone(cachep->gfpflags);
24501 +       struct vx_info *vxi = current_vx_info();
24502 +
24503 +       if (!vxi)
24504 +               return;
24505 +
24506 +       atomic_add(cachep->buffer_size, &vxi->cacct.slab[what]);
24507 +}
24508 +
24509 +static inline
24510 +void vx_slab_free(struct kmem_cache *cachep)
24511 +{
24512 +       int what = gfp_zone(cachep->gfpflags);
24513 +       struct vx_info *vxi = current_vx_info();
24514 +
24515 +       if (!vxi)
24516 +               return;
24517 +
24518 +       atomic_sub(cachep->buffer_size, &vxi->cacct.slab[what]);
24519 +}
24520 +
24521 diff -NurpP --minimal linux-3.0.25/mm/swapfile.c linux-3.0.25-vs2.3.2.3/mm/swapfile.c
24522 --- linux-3.0.25/mm/swapfile.c  2011-07-22 11:18:12.000000000 +0200
24523 +++ linux-3.0.25-vs2.3.2.3/mm/swapfile.c        2011-07-01 11:35:35.000000000 +0200
24524 @@ -37,6 +37,8 @@
24525  #include <asm/tlbflush.h>
24526  #include <linux/swapops.h>
24527  #include <linux/page_cgroup.h>
24528 +#include <linux/vs_base.h>
24529 +#include <linux/vs_memory.h>
24530  
24531  static bool swap_count_continued(struct swap_info_struct *, pgoff_t,
24532                                  unsigned char);
24533 @@ -1759,6 +1761,16 @@ static int swap_show(struct seq_file *sw
24534  
24535         if (si == SEQ_START_TOKEN) {
24536                 seq_puts(swap,"Filename\t\t\t\tType\t\tSize\tUsed\tPriority\n");
24537 +               if (vx_flags(VXF_VIRT_MEM, 0)) {
24538 +                       struct sysinfo si;
24539 +
24540 +                       vx_vsi_swapinfo(&si);
24541 +                       if (si.totalswap < (1 << 10))
24542 +                               return 0;
24543 +                       seq_printf(swap, "%s\t\t\t\t\t%s\t%lu\t%lu\t%d\n",
24544 +                               "hdv0", "partition", si.totalswap >> 10,
24545 +                               (si.totalswap - si.freeswap) >> 10, -1);
24546 +               }
24547                 return 0;
24548         }
24549  
24550 @@ -2186,6 +2198,8 @@ void si_swapinfo(struct sysinfo *val)
24551         val->freeswap = nr_swap_pages + nr_to_be_unused;
24552         val->totalswap = total_swap_pages + nr_to_be_unused;
24553         spin_unlock(&swap_lock);
24554 +       if (vx_flags(VXF_VIRT_MEM, 0))
24555 +               vx_vsi_swapinfo(val);
24556  }
24557  
24558  /*
24559 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
24560 --- linux-3.0.25/net/bridge/br_multicast.c      2012-03-19 21:16:57.000000000 +0100
24561 +++ linux-3.0.25-vs2.3.2.3/net/bridge/br_multicast.c    2012-03-23 14:55:24.000000000 +0100
24562 @@ -447,7 +447,7 @@ static struct sk_buff *br_ip6_multicast_
24563         ip6h->hop_limit = 1;
24564         ipv6_addr_set(&ip6h->daddr, htonl(0xff020000), 0, 0, htonl(1));
24565         if (ipv6_dev_get_saddr(dev_net(br->dev), br->dev, &ip6h->daddr, 0,
24566 -                              &ip6h->saddr)) {
24567 +                              &ip6h->saddr, NULL)) {
24568                 kfree_skb(skb);
24569                 return NULL;
24570         }
24571 diff -NurpP --minimal linux-3.0.25/net/core/dev.c linux-3.0.25-vs2.3.2.3/net/core/dev.c
24572 --- linux-3.0.25/net/core/dev.c 2012-03-19 21:16:57.000000000 +0100
24573 +++ linux-3.0.25-vs2.3.2.3/net/core/dev.c       2012-03-01 21:51:50.000000000 +0100
24574 @@ -127,6 +127,7 @@
24575  #include <linux/in.h>
24576  #include <linux/jhash.h>
24577  #include <linux/random.h>
24578 +#include <linux/vs_inet.h>
24579  #include <trace/events/napi.h>
24580  #include <trace/events/net.h>
24581  #include <trace/events/skb.h>
24582 @@ -609,7 +610,8 @@ struct net_device *__dev_get_by_name(str
24583         struct hlist_head *head = dev_name_hash(net, name);
24584  
24585         hlist_for_each_entry(dev, p, head, name_hlist)
24586 -               if (!strncmp(dev->name, name, IFNAMSIZ))
24587 +               if (!strncmp(dev->name, name, IFNAMSIZ) &&
24588 +                   nx_dev_visible(current_nx_info(), dev))
24589                         return dev;
24590  
24591         return NULL;
24592 @@ -635,7 +637,8 @@ struct net_device *dev_get_by_name_rcu(s
24593         struct hlist_head *head = dev_name_hash(net, name);
24594  
24595         hlist_for_each_entry_rcu(dev, p, head, name_hlist)
24596 -               if (!strncmp(dev->name, name, IFNAMSIZ))
24597 +               if (!strncmp(dev->name, name, IFNAMSIZ) &&
24598 +                   nx_dev_visible(current_nx_info(), dev))
24599                         return dev;
24600  
24601         return NULL;
24602 @@ -686,7 +689,8 @@ struct net_device *__dev_get_by_index(st
24603         struct hlist_head *head = dev_index_hash(net, ifindex);
24604  
24605         hlist_for_each_entry(dev, p, head, index_hlist)
24606 -               if (dev->ifindex == ifindex)
24607 +               if ((dev->ifindex == ifindex) &&
24608 +                   nx_dev_visible(current_nx_info(), dev))
24609                         return dev;
24610  
24611         return NULL;
24612 @@ -704,7 +708,7 @@ EXPORT_SYMBOL(__dev_get_by_index);
24613   *     about locking. The caller must hold RCU lock.
24614   */
24615  
24616 -struct net_device *dev_get_by_index_rcu(struct net *net, int ifindex)
24617 +struct net_device *dev_get_by_index_real_rcu(struct net *net, int ifindex)
24618  {
24619         struct hlist_node *p;
24620         struct net_device *dev;
24621 @@ -716,6 +720,16 @@ struct net_device *dev_get_by_index_rcu(
24622  
24623         return NULL;
24624  }
24625 +EXPORT_SYMBOL(dev_get_by_index_real_rcu);
24626 +
24627 +struct net_device *dev_get_by_index_rcu(struct net *net, int ifindex)
24628 +{
24629 +       struct net_device *dev = dev_get_by_index_real_rcu(net, ifindex);
24630 +
24631 +       if (nx_dev_visible(current_nx_info(), dev))
24632 +               return dev;
24633 +       return NULL;
24634 +}
24635  EXPORT_SYMBOL(dev_get_by_index_rcu);
24636  
24637  
24638 @@ -764,7 +778,8 @@ struct net_device *dev_getbyhwaddr_rcu(s
24639  
24640         for_each_netdev_rcu(net, dev)
24641                 if (dev->type == type &&
24642 -                   !memcmp(dev->dev_addr, ha, dev->addr_len))
24643 +                   !memcmp(dev->dev_addr, ha, dev->addr_len) &&
24644 +                   nx_dev_visible(current_nx_info(), dev))
24645                         return dev;
24646  
24647         return NULL;
24648 @@ -776,9 +791,11 @@ struct net_device *__dev_getfirstbyhwtyp
24649         struct net_device *dev;
24650  
24651         ASSERT_RTNL();
24652 -       for_each_netdev(net, dev)
24653 -               if (dev->type == type)
24654 +       for_each_netdev(net, dev) {
24655 +               if ((dev->type == type) &&
24656 +                   nx_dev_visible(current_nx_info(), dev))
24657                         return dev;
24658 +       }
24659  
24660         return NULL;
24661  }
24662 @@ -896,6 +913,8 @@ static int __dev_alloc_name(struct net *
24663                                 continue;
24664                         if (i < 0 || i >= max_netdevices)
24665                                 continue;
24666 +                       if (!nx_dev_visible(current_nx_info(), d))
24667 +                               continue;
24668  
24669                         /*  avoid cases where sscanf is not exact inverse of printf */
24670                         snprintf(buf, IFNAMSIZ, name, i);
24671 @@ -3943,6 +3962,8 @@ static int dev_ifconf(struct net *net, c
24672  
24673         total = 0;
24674         for_each_netdev(net, dev) {
24675 +               if (!nx_dev_visible(current_nx_info(), dev))
24676 +                       continue;
24677                 for (i = 0; i < NPROTO; i++) {
24678                         if (gifconf_list[i]) {
24679                                 int done;
24680 @@ -4017,6 +4038,10 @@ static void dev_seq_printf_stats(struct 
24681         struct rtnl_link_stats64 temp;
24682         const struct rtnl_link_stats64 *stats = dev_get_stats(dev, &temp);
24683  
24684 +       /* device visible inside network context? */
24685 +       if (!nx_dev_visible(current_nx_info(), dev))
24686 +               return;
24687 +
24688         seq_printf(seq, "%6s: %7llu %7llu %4llu %4llu %4llu %5llu %10llu %9llu "
24689                    "%8llu %7llu %4llu %4llu %4llu %5llu %7llu %10llu\n",
24690                    dev->name, stats->rx_bytes, stats->rx_packets,
24691 diff -NurpP --minimal linux-3.0.25/net/core/rtnetlink.c linux-3.0.25-vs2.3.2.3/net/core/rtnetlink.c
24692 --- linux-3.0.25/net/core/rtnetlink.c   2011-07-22 11:18:13.000000000 +0200
24693 +++ linux-3.0.25-vs2.3.2.3/net/core/rtnetlink.c 2011-06-10 22:11:24.000000000 +0200
24694 @@ -1015,6 +1015,8 @@ static int rtnl_dump_ifinfo(struct sk_bu
24695                 hlist_for_each_entry_rcu(dev, node, head, index_hlist) {
24696                         if (idx < s_idx)
24697                                 goto cont;
24698 +                       if (!nx_dev_visible(skb->sk->sk_nx_info, dev))
24699 +                               continue;
24700                         if (rtnl_fill_ifinfo(skb, dev, RTM_NEWLINK,
24701                                              NETLINK_CB(cb->skb).pid,
24702                                              cb->nlh->nlmsg_seq, 0,
24703 @@ -1848,6 +1850,9 @@ void rtmsg_ifinfo(int type, struct net_d
24704         struct sk_buff *skb;
24705         int err = -ENOBUFS;
24706  
24707 +       if (!nx_dev_visible(current_nx_info(), dev))
24708 +               return;
24709 +
24710         skb = nlmsg_new(if_nlmsg_size(dev), GFP_KERNEL);
24711         if (skb == NULL)
24712                 goto errout;
24713 diff -NurpP --minimal linux-3.0.25/net/core/sock.c linux-3.0.25-vs2.3.2.3/net/core/sock.c
24714 --- linux-3.0.25/net/core/sock.c        2012-03-19 21:16:57.000000000 +0100
24715 +++ linux-3.0.25-vs2.3.2.3/net/core/sock.c      2011-11-15 17:37:07.000000000 +0100
24716 @@ -127,6 +127,10 @@
24717  #include <net/cls_cgroup.h>
24718  
24719  #include <linux/filter.h>
24720 +#include <linux/vs_socket.h>
24721 +#include <linux/vs_limit.h>
24722 +#include <linux/vs_context.h>
24723 +#include <linux/vs_network.h>
24724  
24725  #ifdef CONFIG_INET
24726  #include <net/tcp.h>
24727 @@ -1070,6 +1074,8 @@ static struct sock *sk_prot_alloc(struct
24728                         goto out_free_sec;
24729                 sk_tx_queue_clear(sk);
24730         }
24731 +               sock_vx_init(sk);
24732 +               sock_nx_init(sk);
24733  
24734         return sk;
24735  
24736 @@ -1169,6 +1175,11 @@ static void __sk_free(struct sock *sk)
24737                 put_cred(sk->sk_peer_cred);
24738         put_pid(sk->sk_peer_pid);
24739         put_net(sock_net(sk));
24740 +       vx_sock_dec(sk);
24741 +       clr_vx_info(&sk->sk_vx_info);
24742 +       sk->sk_xid = -1;
24743 +       clr_nx_info(&sk->sk_nx_info);
24744 +       sk->sk_nid = -1;
24745         sk_prot_free(sk->sk_prot_creator, sk);
24746  }
24747  
24748 @@ -1216,6 +1227,8 @@ struct sock *sk_clone(const struct sock 
24749  
24750                 /* SANITY */
24751                 get_net(sock_net(newsk));
24752 +               sock_vx_init(newsk);
24753 +               sock_nx_init(newsk);
24754                 sk_node_init(&newsk->sk_node);
24755                 sock_lock_init(newsk);
24756                 bh_lock_sock(newsk);
24757 @@ -1272,6 +1285,12 @@ struct sock *sk_clone(const struct sock 
24758                 smp_wmb();
24759                 atomic_set(&newsk->sk_refcnt, 2);
24760  
24761 +               set_vx_info(&newsk->sk_vx_info, sk->sk_vx_info);
24762 +               newsk->sk_xid = sk->sk_xid;
24763 +               vx_sock_inc(newsk);
24764 +               set_nx_info(&newsk->sk_nx_info, sk->sk_nx_info);
24765 +               newsk->sk_nid = sk->sk_nid;
24766 +
24767                 /*
24768                  * Increment the counter in the same struct proto as the master
24769                  * sock (sk_refcnt_debug_inc uses newsk->sk_prot->socks, that
24770 @@ -2018,6 +2037,12 @@ void sock_init_data(struct socket *sock,
24771  
24772         sk->sk_stamp = ktime_set(-1L, 0);
24773  
24774 +       set_vx_info(&sk->sk_vx_info, current_vx_info());
24775 +       sk->sk_xid = vx_current_xid();
24776 +       vx_sock_inc(sk);
24777 +       set_nx_info(&sk->sk_nx_info, current_nx_info());
24778 +       sk->sk_nid = nx_current_nid();
24779 +
24780         /*
24781          * Before updating sk_refcnt, we must commit prior changes to memory
24782          * (Documentation/RCU/rculist_nulls.txt for details)
24783 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
24784 --- linux-3.0.25/net/ipv4/af_inet.c     2011-07-22 11:18:13.000000000 +0200
24785 +++ linux-3.0.25-vs2.3.2.3/net/ipv4/af_inet.c   2011-07-19 00:44:39.000000000 +0200
24786 @@ -117,6 +117,7 @@
24787  #ifdef CONFIG_IP_MROUTE
24788  #include <linux/mroute.h>
24789  #endif
24790 +#include <linux/vs_limit.h>
24791  
24792  
24793  /* The inetsw table contains everything that inet_create needs to
24794 @@ -326,9 +327,13 @@ lookup_protocol:
24795         }
24796  
24797         err = -EPERM;
24798 +       if ((protocol == IPPROTO_ICMP) &&
24799 +               nx_capable(CAP_NET_RAW, NXC_RAW_ICMP))
24800 +               goto override;
24801 +
24802         if (sock->type == SOCK_RAW && !kern && !capable(CAP_NET_RAW))
24803                 goto out_rcu_unlock;
24804 -
24805 +override:
24806         err = -EAFNOSUPPORT;
24807         if (!inet_netns_ok(net, protocol))
24808                 goto out_rcu_unlock;
24809 @@ -452,6 +457,7 @@ int inet_bind(struct socket *sock, struc
24810         struct sockaddr_in *addr = (struct sockaddr_in *)uaddr;
24811         struct sock *sk = sock->sk;
24812         struct inet_sock *inet = inet_sk(sk);
24813 +       struct nx_v4_sock_addr nsa;
24814         unsigned short snum;
24815         int chk_addr_ret;
24816         int err;
24817 @@ -470,7 +476,11 @@ int inet_bind(struct socket *sock, struc
24818                 goto out;
24819         }
24820  
24821 -       chk_addr_ret = inet_addr_type(sock_net(sk), addr->sin_addr.s_addr);
24822 +       err = v4_map_sock_addr(inet, addr, &nsa);
24823 +       if (err)
24824 +               goto out;
24825 +
24826 +       chk_addr_ret = inet_addr_type(sock_net(sk), nsa.saddr);
24827  
24828         /* Not specified by any standard per-se, however it breaks too
24829          * many applications when removed.  It is unfortunate since
24830 @@ -482,7 +492,7 @@ int inet_bind(struct socket *sock, struc
24831         err = -EADDRNOTAVAIL;
24832         if (!sysctl_ip_nonlocal_bind &&
24833             !(inet->freebind || inet->transparent) &&
24834 -           addr->sin_addr.s_addr != htonl(INADDR_ANY) &&
24835 +           nsa.saddr != htonl(INADDR_ANY) &&
24836             chk_addr_ret != RTN_LOCAL &&
24837             chk_addr_ret != RTN_MULTICAST &&
24838             chk_addr_ret != RTN_BROADCAST)
24839 @@ -507,7 +517,7 @@ int inet_bind(struct socket *sock, struc
24840         if (sk->sk_state != TCP_CLOSE || inet->inet_num)
24841                 goto out_release_sock;
24842  
24843 -       inet->inet_rcv_saddr = inet->inet_saddr = addr->sin_addr.s_addr;
24844 +       v4_set_sock_addr(inet, &nsa);
24845         if (chk_addr_ret == RTN_MULTICAST || chk_addr_ret == RTN_BROADCAST)
24846                 inet->inet_saddr = 0;  /* Use device */
24847  
24848 @@ -710,11 +720,13 @@ int inet_getname(struct socket *sock, st
24849                      peer == 1))
24850                         return -ENOTCONN;
24851                 sin->sin_port = inet->inet_dport;
24852 -               sin->sin_addr.s_addr = inet->inet_daddr;
24853 +               sin->sin_addr.s_addr =
24854 +                       nx_map_sock_lback(sk->sk_nx_info, inet->inet_daddr);
24855         } else {
24856                 __be32 addr = inet->inet_rcv_saddr;
24857                 if (!addr)
24858                         addr = inet->inet_saddr;
24859 +               addr = nx_map_sock_lback(sk->sk_nx_info, addr);
24860                 sin->sin_port = inet->inet_sport;
24861                 sin->sin_addr.s_addr = addr;
24862         }
24863 diff -NurpP --minimal linux-3.0.25/net/ipv4/arp.c linux-3.0.25-vs2.3.2.3/net/ipv4/arp.c
24864 --- linux-3.0.25/net/ipv4/arp.c 2012-03-19 21:16:57.000000000 +0100
24865 +++ linux-3.0.25-vs2.3.2.3/net/ipv4/arp.c       2012-03-01 21:51:50.000000000 +0100
24866 @@ -1372,6 +1372,7 @@ static void arp_format_neigh_entry(struc
24867         struct net_device *dev = n->dev;
24868         int hatype = dev->type;
24869  
24870 +       /* FIXME: check for network context */
24871         read_lock(&n->lock);
24872         /* Convert hardware address to XX:XX:XX:XX ... form. */
24873  #if defined(CONFIG_AX25) || defined(CONFIG_AX25_MODULE)
24874 @@ -1403,6 +1404,7 @@ static void arp_format_pneigh_entry(stru
24875         int hatype = dev ? dev->type : 0;
24876         char tbuf[16];
24877  
24878 +       /* FIXME: check for network context */
24879         sprintf(tbuf, "%pI4", n->key);
24880         seq_printf(seq, "%-16s 0x%-10x0x%-10x%s     *        %s\n",
24881                    tbuf, hatype, ATF_PUBL | ATF_PERM, "00:00:00:00:00:00",
24882 diff -NurpP --minimal linux-3.0.25/net/ipv4/devinet.c linux-3.0.25-vs2.3.2.3/net/ipv4/devinet.c
24883 --- linux-3.0.25/net/ipv4/devinet.c     2012-03-19 21:16:57.000000000 +0100
24884 +++ linux-3.0.25-vs2.3.2.3/net/ipv4/devinet.c   2012-01-10 09:19:13.000000000 +0100
24885 @@ -518,6 +518,7 @@ struct in_device *inetdev_by_index(struc
24886  }
24887  EXPORT_SYMBOL(inetdev_by_index);
24888  
24889 +
24890  /* Called only from RTNL semaphored context. No locks. */
24891  
24892  struct in_ifaddr *inet_ifa_byprefix(struct in_device *in_dev, __be32 prefix,
24893 @@ -759,6 +760,8 @@ int devinet_ioctl(struct net *net, unsig
24894  
24895         in_dev = __in_dev_get_rtnl(dev);
24896         if (in_dev) {
24897 +               struct nx_info *nxi = current_nx_info();
24898 +
24899                 if (tryaddrmatch) {
24900                         /* Matthias Andree */
24901                         /* compare label and address (4.4BSD style) */
24902 @@ -767,6 +770,8 @@ int devinet_ioctl(struct net *net, unsig
24903                            This is checked above. */
24904                         for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
24905                              ifap = &ifa->ifa_next) {
24906 +                               if (!nx_v4_ifa_visible(nxi, ifa))
24907 +                                       continue;
24908                                 if (!strcmp(ifr.ifr_name, ifa->ifa_label) &&
24909                                     sin_orig.sin_addr.s_addr ==
24910                                                         ifa->ifa_local) {
24911 @@ -779,9 +784,12 @@ int devinet_ioctl(struct net *net, unsig
24912                    comparing just the label */
24913                 if (!ifa) {
24914                         for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
24915 -                            ifap = &ifa->ifa_next)
24916 +                            ifap = &ifa->ifa_next) {
24917 +                               if (!nx_v4_ifa_visible(nxi, ifa))
24918 +                                       continue;
24919                                 if (!strcmp(ifr.ifr_name, ifa->ifa_label))
24920                                         break;
24921 +                       }
24922                 }
24923         }
24924  
24925 @@ -934,6 +942,8 @@ static int inet_gifconf(struct net_devic
24926                 goto out;
24927  
24928         for (ifa = in_dev->ifa_list; ifa; ifa = ifa->ifa_next) {
24929 +               if (!nx_v4_ifa_visible(current_nx_info(), ifa))
24930 +                       continue;
24931                 if (!buf) {
24932                         done += sizeof(ifr);
24933                         continue;
24934 @@ -1294,6 +1304,7 @@ static int inet_dump_ifaddr(struct sk_bu
24935         struct net_device *dev;
24936         struct in_device *in_dev;
24937         struct in_ifaddr *ifa;
24938 +       struct sock *sk = skb->sk;
24939         struct hlist_head *head;
24940         struct hlist_node *node;
24941  
24942 @@ -1316,6 +1327,8 @@ static int inet_dump_ifaddr(struct sk_bu
24943  
24944                         for (ifa = in_dev->ifa_list, ip_idx = 0; ifa;
24945                              ifa = ifa->ifa_next, ip_idx++) {
24946 +                       if (sk && !nx_v4_ifa_visible(sk->sk_nx_info, ifa))
24947 +                               continue;
24948                                 if (ip_idx < s_ip_idx)
24949                                         continue;
24950                                 if (inet_fill_ifaddr(skb, ifa,
24951 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
24952 --- linux-3.0.25/net/ipv4/fib_trie.c    2011-07-22 11:18:13.000000000 +0200
24953 +++ linux-3.0.25-vs2.3.2.3/net/ipv4/fib_trie.c  2011-08-29 04:56:47.000000000 +0200
24954 @@ -2554,6 +2554,7 @@ static int fib_route_seq_show(struct seq
24955                             || fa->fa_type == RTN_MULTICAST)
24956                                 continue;
24957  
24958 +                       /* FIXME: check for network context? */
24959                         if (fi)
24960                                 seq_printf(seq,
24961                                          "%s\t%08X\t%08X\t%04X\t%d\t%u\t"
24962 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
24963 --- linux-3.0.25/net/ipv4/inet_connection_sock.c        2011-07-22 11:18:13.000000000 +0200
24964 +++ linux-3.0.25-vs2.3.2.3/net/ipv4/inet_connection_sock.c      2011-06-10 22:11:24.000000000 +0200
24965 @@ -52,6 +52,37 @@ void inet_get_local_port_range(int *low,
24966  }
24967  EXPORT_SYMBOL(inet_get_local_port_range);
24968  
24969 +int ipv4_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2)
24970 +{
24971 +       __be32  sk1_rcv_saddr = sk_rcv_saddr(sk1),
24972 +               sk2_rcv_saddr = sk_rcv_saddr(sk2);
24973 +
24974 +       if (inet_v6_ipv6only(sk2))
24975 +               return 0;
24976 +
24977 +       if (sk1_rcv_saddr &&
24978 +           sk2_rcv_saddr &&
24979 +           sk1_rcv_saddr == sk2_rcv_saddr)
24980 +               return 1;
24981 +
24982 +       if (sk1_rcv_saddr &&
24983 +           !sk2_rcv_saddr &&
24984 +           v4_addr_in_nx_info(sk2->sk_nx_info, sk1_rcv_saddr, NXA_MASK_BIND))
24985 +               return 1;
24986 +
24987 +       if (sk2_rcv_saddr &&
24988 +           !sk1_rcv_saddr &&
24989 +           v4_addr_in_nx_info(sk1->sk_nx_info, sk2_rcv_saddr, NXA_MASK_BIND))
24990 +               return 1;
24991 +
24992 +       if (!sk1_rcv_saddr &&
24993 +           !sk2_rcv_saddr &&
24994 +           nx_v4_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info))
24995 +               return 1;
24996 +
24997 +       return 0;
24998 +}
24999 +
25000  int inet_csk_bind_conflict(const struct sock *sk,
25001                            const struct inet_bind_bucket *tb)
25002  {
25003 @@ -74,9 +105,7 @@ int inet_csk_bind_conflict(const struct 
25004                      sk->sk_bound_dev_if == sk2->sk_bound_dev_if)) {
25005                         if (!reuse || !sk2->sk_reuse ||
25006                             sk2->sk_state == TCP_LISTEN) {
25007 -                               const __be32 sk2_rcv_saddr = sk_rcv_saddr(sk2);
25008 -                               if (!sk2_rcv_saddr || !sk_rcv_saddr(sk) ||
25009 -                                   sk2_rcv_saddr == sk_rcv_saddr(sk))
25010 +                               if (ipv4_rcv_saddr_equal(sk, sk2))
25011                                         break;
25012                         }
25013                 }
25014 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
25015 --- linux-3.0.25/net/ipv4/inet_diag.c   2011-07-22 11:18:13.000000000 +0200
25016 +++ linux-3.0.25-vs2.3.2.3/net/ipv4/inet_diag.c 2011-06-22 12:39:16.000000000 +0200
25017 @@ -33,6 +33,8 @@
25018  #include <linux/stddef.h>
25019  
25020  #include <linux/inet_diag.h>
25021 +#include <linux/vs_network.h>
25022 +#include <linux/vs_inet.h>
25023  
25024  static const struct inet_diag_handler **inet_diag_table;
25025  
25026 @@ -119,8 +121,10 @@ static int inet_csk_diag_fill(struct soc
25027  
25028         r->id.idiag_sport = inet->inet_sport;
25029         r->id.idiag_dport = inet->inet_dport;
25030 -       r->id.idiag_src[0] = inet->inet_rcv_saddr;
25031 -       r->id.idiag_dst[0] = inet->inet_daddr;
25032 +       r->id.idiag_src[0] = nx_map_sock_lback(sk->sk_nx_info,
25033 +               inet->inet_rcv_saddr);
25034 +       r->id.idiag_dst[0] = nx_map_sock_lback(sk->sk_nx_info,
25035 +               inet->inet_daddr);
25036  
25037  #if defined(CONFIG_IPV6) || defined (CONFIG_IPV6_MODULE)
25038         if (r->idiag_family == AF_INET6) {
25039 @@ -205,8 +209,8 @@ static int inet_twsk_diag_fill(struct in
25040         r->id.idiag_cookie[1] = (u32)(((unsigned long)tw >> 31) >> 1);
25041         r->id.idiag_sport     = tw->tw_sport;
25042         r->id.idiag_dport     = tw->tw_dport;
25043 -       r->id.idiag_src[0]    = tw->tw_rcv_saddr;
25044 -       r->id.idiag_dst[0]    = tw->tw_daddr;
25045 +       r->id.idiag_src[0]    = nx_map_sock_lback(tw->tw_nx_info, tw->tw_rcv_saddr);
25046 +       r->id.idiag_dst[0]    = nx_map_sock_lback(tw->tw_nx_info, tw->tw_daddr);
25047         r->idiag_state        = tw->tw_substate;
25048         r->idiag_timer        = 3;
25049         r->idiag_expires      = DIV_ROUND_UP(tmo * 1000, HZ);
25050 @@ -263,6 +267,7 @@ static int inet_diag_get_exact(struct sk
25051         err = -EINVAL;
25052  
25053         if (req->idiag_family == AF_INET) {
25054 +               /* TODO: lback */
25055                 sk = inet_lookup(&init_net, hashinfo, req->id.idiag_dst[0],
25056                                  req->id.idiag_dport, req->id.idiag_src[0],
25057                                  req->id.idiag_sport, req->id.idiag_if);
25058 @@ -505,6 +510,7 @@ static int inet_csk_diag_dump(struct soc
25059                 } else
25060  #endif
25061                 {
25062 +                       /* TODO: lback */
25063                         entry.saddr = &inet->inet_rcv_saddr;
25064                         entry.daddr = &inet->inet_daddr;
25065                 }
25066 @@ -543,6 +549,7 @@ static int inet_twsk_diag_dump(struct in
25067                 } else
25068  #endif
25069                 {
25070 +                       /* TODO: lback */
25071                         entry.saddr = &tw->tw_rcv_saddr;
25072                         entry.daddr = &tw->tw_daddr;
25073                 }
25074 @@ -589,8 +596,8 @@ static int inet_diag_fill_req(struct sk_
25075  
25076         r->id.idiag_sport = inet->inet_sport;
25077         r->id.idiag_dport = ireq->rmt_port;
25078 -       r->id.idiag_src[0] = ireq->loc_addr;
25079 -       r->id.idiag_dst[0] = ireq->rmt_addr;
25080 +       r->id.idiag_src[0] = nx_map_sock_lback(sk->sk_nx_info, ireq->loc_addr);
25081 +       r->id.idiag_dst[0] = nx_map_sock_lback(sk->sk_nx_info, ireq->rmt_addr);
25082         r->idiag_expires = jiffies_to_msecs(tmo);
25083         r->idiag_rqueue = 0;
25084         r->idiag_wqueue = 0;
25085 @@ -661,6 +668,7 @@ static int inet_diag_dump_reqs(struct sk
25086                                 continue;
25087  
25088                         if (bc) {
25089 +                               /* TODO: lback */
25090                                 entry.saddr =
25091  #if defined(CONFIG_IPV6) || defined (CONFIG_IPV6_MODULE)
25092                                         (entry.family == AF_INET6) ?
25093 @@ -731,6 +739,8 @@ static int inet_diag_dump(struct sk_buff
25094                         sk_nulls_for_each(sk, node, &ilb->head) {
25095                                 struct inet_sock *inet = inet_sk(sk);
25096  
25097 +                               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
25098 +                                       continue;
25099                                 if (num < s_num) {
25100                                         num++;
25101                                         continue;
25102 @@ -797,6 +807,8 @@ skip_listen_ht:
25103                 sk_nulls_for_each(sk, node, &head->chain) {
25104                         struct inet_sock *inet = inet_sk(sk);
25105  
25106 +                       if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
25107 +                               continue;
25108                         if (num < s_num)
25109                                 goto next_normal;
25110                         if (!(r->idiag_states & (1 << sk->sk_state)))
25111 @@ -821,6 +833,8 @@ next_normal:
25112                         inet_twsk_for_each(tw, node,
25113                                     &head->twchain) {
25114  
25115 +                               if (!nx_check(tw->tw_nid, VS_WATCH_P | VS_IDENT))
25116 +                                       continue;
25117                                 if (num < s_num)
25118                                         goto next_dying;
25119                                 if (r->id.idiag_sport != tw->tw_sport &&
25120 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
25121 --- linux-3.0.25/net/ipv4/inet_hashtables.c     2012-03-19 21:16:57.000000000 +0100
25122 +++ linux-3.0.25-vs2.3.2.3/net/ipv4/inet_hashtables.c   2011-08-29 03:45:56.000000000 +0200
25123 @@ -22,6 +22,7 @@
25124  #include <net/inet_connection_sock.h>
25125  #include <net/inet_hashtables.h>
25126  #include <net/secure_seq.h>
25127 +#include <net/route.h>
25128  #include <net/ip.h>
25129  
25130  /*
25131 @@ -156,6 +157,11 @@ static inline int compute_score(struct s
25132                         if (rcv_saddr != daddr)
25133                                 return -1;
25134                         score += 2;
25135 +               } else {
25136 +                       /* block non nx_info ips */
25137 +                       if (!v4_addr_in_nx_info(sk->sk_nx_info,
25138 +                               daddr, NXA_MASK_BIND))
25139 +                               return -1;
25140                 }
25141                 if (sk->sk_bound_dev_if) {
25142                         if (sk->sk_bound_dev_if != dif)
25143 @@ -173,7 +179,6 @@ static inline int compute_score(struct s
25144   * wildcarded during the search since they can never be otherwise.
25145   */
25146  
25147 -
25148  struct sock *__inet_lookup_listener(struct net *net,
25149                                     struct inet_hashinfo *hashinfo,
25150                                     const __be32 daddr, const unsigned short hnum,
25151 @@ -196,6 +201,7 @@ begin:
25152                         hiscore = score;
25153                 }
25154         }
25155 +
25156         /*
25157          * if the nulls value we got at the end of this lookup is
25158          * not the expected one, we must restart lookup.
25159 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
25160 --- linux-3.0.25/net/ipv4/netfilter/nf_nat_helper.c     2011-07-22 11:18:13.000000000 +0200
25161 +++ linux-3.0.25-vs2.3.2.3/net/ipv4/netfilter/nf_nat_helper.c   2011-06-15 02:40:14.000000000 +0200
25162 @@ -20,6 +20,7 @@
25163  #include <net/route.h>
25164  
25165  #include <linux/netfilter_ipv4.h>
25166 +#include <net/route.h>
25167  #include <net/netfilter/nf_conntrack.h>
25168  #include <net/netfilter/nf_conntrack_helper.h>
25169  #include <net/netfilter/nf_conntrack_ecache.h>
25170 diff -NurpP --minimal linux-3.0.25/net/ipv4/netfilter.c linux-3.0.25-vs2.3.2.3/net/ipv4/netfilter.c
25171 --- linux-3.0.25/net/ipv4/netfilter.c   2012-03-19 21:16:57.000000000 +0100
25172 +++ linux-3.0.25-vs2.3.2.3/net/ipv4/netfilter.c 2011-10-18 13:51:13.000000000 +0200
25173 @@ -5,7 +5,7 @@
25174  #include <linux/ip.h>
25175  #include <linux/skbuff.h>
25176  #include <linux/gfp.h>
25177 -#include <net/route.h>
25178 +// #include <net/route.h>
25179  #include <net/xfrm.h>
25180  #include <net/ip.h>
25181  #include <net/netfilter/nf_queue.h>
25182 diff -NurpP --minimal linux-3.0.25/net/ipv4/raw.c linux-3.0.25-vs2.3.2.3/net/ipv4/raw.c
25183 --- linux-3.0.25/net/ipv4/raw.c 2011-07-22 11:18:13.000000000 +0200
25184 +++ linux-3.0.25-vs2.3.2.3/net/ipv4/raw.c       2011-07-27 20:26:04.000000000 +0200
25185 @@ -117,7 +117,7 @@ static struct sock *__raw_v4_lookup(stru
25186  
25187                 if (net_eq(sock_net(sk), net) && inet->inet_num == num  &&
25188                     !(inet->inet_daddr && inet->inet_daddr != raddr)    &&
25189 -                   !(inet->inet_rcv_saddr && inet->inet_rcv_saddr != laddr) &&
25190 +                   v4_sock_addr_match(sk->sk_nx_info, inet, laddr)     &&
25191                     !(sk->sk_bound_dev_if && sk->sk_bound_dev_if != dif))
25192                         goto found; /* gotcha */
25193         }
25194 @@ -385,6 +385,12 @@ static int raw_send_hdrinc(struct sock *
25195                 icmp_out_count(net, ((struct icmphdr *)
25196                         skb_transport_header(skb))->type);
25197  
25198 +       err = -EPERM;
25199 +       if (!nx_check(0, VS_ADMIN) && !capable(CAP_NET_RAW) &&
25200 +               sk->sk_nx_info &&
25201 +               !v4_addr_in_nx_info(sk->sk_nx_info, iph->saddr, NXA_MASK_BIND))
25202 +               goto error_free;
25203 +
25204         err = NF_HOOK(NFPROTO_IPV4, NF_INET_LOCAL_OUT, skb, NULL,
25205                       rt->dst.dev, dst_output);
25206         if (err > 0)
25207 @@ -571,6 +577,16 @@ static int raw_sendmsg(struct kiocb *ioc
25208                         goto done;
25209         }
25210  
25211 +       if (sk->sk_nx_info) {
25212 +               rt = ip_v4_find_src(sock_net(sk), sk->sk_nx_info, &fl4);
25213 +               if (IS_ERR(rt)) {
25214 +                       err = PTR_ERR(rt);
25215 +                       rt = NULL;
25216 +                       goto done;
25217 +               }
25218 +               ip_rt_put(rt);
25219 +       }
25220 +
25221         security_sk_classify_flow(sk, flowi4_to_flowi(&fl4));
25222         rt = ip_route_output_flow(sock_net(sk), &fl4, sk);
25223         if (IS_ERR(rt)) {
25224 @@ -647,17 +663,19 @@ static int raw_bind(struct sock *sk, str
25225  {
25226         struct inet_sock *inet = inet_sk(sk);
25227         struct sockaddr_in *addr = (struct sockaddr_in *) uaddr;
25228 +       struct nx_v4_sock_addr nsa = { 0 };
25229         int ret = -EINVAL;
25230         int chk_addr_ret;
25231  
25232         if (sk->sk_state != TCP_CLOSE || addr_len < sizeof(struct sockaddr_in))
25233                 goto out;
25234 -       chk_addr_ret = inet_addr_type(sock_net(sk), addr->sin_addr.s_addr);
25235 +       v4_map_sock_addr(inet, addr, &nsa);
25236 +       chk_addr_ret = inet_addr_type(sock_net(sk), nsa.saddr);
25237         ret = -EADDRNOTAVAIL;
25238 -       if (addr->sin_addr.s_addr && chk_addr_ret != RTN_LOCAL &&
25239 +       if (nsa.saddr && chk_addr_ret != RTN_LOCAL &&
25240             chk_addr_ret != RTN_MULTICAST && chk_addr_ret != RTN_BROADCAST)
25241                 goto out;
25242 -       inet->inet_rcv_saddr = inet->inet_saddr = addr->sin_addr.s_addr;
25243 +       v4_set_sock_addr(inet, &nsa);
25244         if (chk_addr_ret == RTN_MULTICAST || chk_addr_ret == RTN_BROADCAST)
25245                 inet->inet_saddr = 0;  /* Use device */
25246         sk_dst_reset(sk);
25247 @@ -709,7 +727,8 @@ static int raw_recvmsg(struct kiocb *ioc
25248         /* Copy the address. */
25249         if (sin) {
25250                 sin->sin_family = AF_INET;
25251 -               sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
25252 +               sin->sin_addr.s_addr =
25253 +                       nx_map_sock_lback(sk->sk_nx_info, ip_hdr(skb)->saddr);
25254                 sin->sin_port = 0;
25255                 memset(&sin->sin_zero, 0, sizeof(sin->sin_zero));
25256         }
25257 @@ -905,7 +924,8 @@ static struct sock *raw_get_first(struct
25258                 struct hlist_node *node;
25259  
25260                 sk_for_each(sk, node, &state->h->ht[state->bucket])
25261 -                       if (sock_net(sk) == seq_file_net(seq))
25262 +                       if ((sock_net(sk) == seq_file_net(seq)) &&
25263 +                               nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
25264                                 goto found;
25265         }
25266         sk = NULL;
25267 @@ -921,7 +941,8 @@ static struct sock *raw_get_next(struct 
25268                 sk = sk_next(sk);
25269  try_again:
25270                 ;
25271 -       } while (sk && sock_net(sk) != seq_file_net(seq));
25272 +       } while (sk && ((sock_net(sk) != seq_file_net(seq)) ||
25273 +               !nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT)));
25274  
25275         if (!sk && ++state->bucket < RAW_HTABLE_SIZE) {
25276                 sk = sk_head(&state->h->ht[state->bucket]);
25277 diff -NurpP --minimal linux-3.0.25/net/ipv4/route.c linux-3.0.25-vs2.3.2.3/net/ipv4/route.c
25278 --- linux-3.0.25/net/ipv4/route.c       2012-03-19 21:16:57.000000000 +0100
25279 +++ linux-3.0.25-vs2.3.2.3/net/ipv4/route.c     2012-03-01 21:51:50.000000000 +0100
25280 @@ -2658,7 +2658,7 @@ static struct rtable *ip_route_output_sl
25281  
25282  
25283         if (fl4->flowi4_oif) {
25284 -               dev_out = dev_get_by_index_rcu(net, fl4->flowi4_oif);
25285 +               dev_out = dev_get_by_index_real_rcu(net, fl4->flowi4_oif);
25286                 rth = ERR_PTR(-ENODEV);
25287                 if (dev_out == NULL)
25288                         goto out;
25289 diff -NurpP --minimal linux-3.0.25/net/ipv4/tcp.c linux-3.0.25-vs2.3.2.3/net/ipv4/tcp.c
25290 --- linux-3.0.25/net/ipv4/tcp.c 2011-07-22 11:18:13.000000000 +0200
25291 +++ linux-3.0.25-vs2.3.2.3/net/ipv4/tcp.c       2011-07-19 00:44:39.000000000 +0200
25292 @@ -266,6 +266,7 @@
25293  #include <linux/crypto.h>
25294  #include <linux/time.h>
25295  #include <linux/slab.h>
25296 +#include <linux/in.h>
25297  
25298  #include <net/icmp.h>
25299  #include <net/tcp.h>
25300 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
25301 --- linux-3.0.25/net/ipv4/tcp_ipv4.c    2012-03-19 21:16:57.000000000 +0100
25302 +++ linux-3.0.25-vs2.3.2.3/net/ipv4/tcp_ipv4.c  2012-03-01 21:51:50.000000000 +0100
25303 @@ -2011,6 +2011,12 @@ static void *listening_get_next(struct s
25304                 req = req->dl_next;
25305                 while (1) {
25306                         while (req) {
25307 +                               vxdprintk(VXD_CBIT(net, 6),
25308 +                                       "sk,req: %p [#%d] (from %d)", req->sk,
25309 +                                       (req->sk)?req->sk->sk_nid:0, nx_current_nid());
25310 +                               if (req->sk &&
25311 +                                       !nx_check(req->sk->sk_nid, VS_WATCH_P | VS_IDENT))
25312 +                                       continue;
25313                                 if (req->rsk_ops->family == st->family) {
25314                                         cur = req;
25315                                         goto out;
25316 @@ -2035,6 +2041,10 @@ get_req:
25317         }
25318  get_sk:
25319         sk_nulls_for_each_from(sk, node) {
25320 +               vxdprintk(VXD_CBIT(net, 6), "sk: %p [#%d] (from %d)",
25321 +                       sk, sk->sk_nid, nx_current_nid());
25322 +               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
25323 +                       continue;
25324                 if (!net_eq(sock_net(sk), net))
25325                         continue;
25326                 if (sk->sk_family == st->family) {
25327 @@ -2111,6 +2121,11 @@ static void *established_get_first(struc
25328  
25329                 spin_lock_bh(lock);
25330                 sk_nulls_for_each(sk, node, &tcp_hashinfo.ehash[st->bucket].chain) {
25331 +                       vxdprintk(VXD_CBIT(net, 6),
25332 +                               "sk,egf: %p [#%d] (from %d)",
25333 +                               sk, sk->sk_nid, nx_current_nid());
25334 +                       if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
25335 +                               continue;
25336                         if (sk->sk_family != st->family ||
25337                             !net_eq(sock_net(sk), net)) {
25338                                 continue;
25339 @@ -2121,6 +2136,11 @@ static void *established_get_first(struc
25340                 st->state = TCP_SEQ_STATE_TIME_WAIT;
25341                 inet_twsk_for_each(tw, node,
25342                                    &tcp_hashinfo.ehash[st->bucket].twchain) {
25343 +                       vxdprintk(VXD_CBIT(net, 6),
25344 +                               "tw: %p [#%d] (from %d)",
25345 +                               tw, tw->tw_nid, nx_current_nid());
25346 +                       if (!nx_check(tw->tw_nid, VS_WATCH_P | VS_IDENT))
25347 +                               continue;
25348                         if (tw->tw_family != st->family ||
25349                             !net_eq(twsk_net(tw), net)) {
25350                                 continue;
25351 @@ -2150,7 +2170,9 @@ static void *established_get_next(struct
25352                 tw = cur;
25353                 tw = tw_next(tw);
25354  get_tw:
25355 -               while (tw && (tw->tw_family != st->family || !net_eq(twsk_net(tw), net))) {
25356 +               while (tw && (tw->tw_family != st->family ||
25357 +                       !net_eq(twsk_net(tw), net) ||
25358 +                       !nx_check(tw->tw_nid, VS_WATCH_P | VS_IDENT))) {
25359                         tw = tw_next(tw);
25360                 }
25361                 if (tw) {
25362 @@ -2174,6 +2196,11 @@ get_tw:
25363                 sk = sk_nulls_next(sk);
25364  
25365         sk_nulls_for_each_from(sk, node) {
25366 +               vxdprintk(VXD_CBIT(net, 6),
25367 +                       "sk,egn: %p [#%d] (from %d)",
25368 +                       sk, sk->sk_nid, nx_current_nid());
25369 +               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
25370 +                       continue;
25371                 if (sk->sk_family == st->family && net_eq(sock_net(sk), net))
25372                         goto found;
25373         }
25374 @@ -2383,9 +2410,9 @@ static void get_openreq4(struct sock *sk
25375         seq_printf(f, "%4d: %08X:%04X %08X:%04X"
25376                 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %u %d %pK%n",
25377                 i,
25378 -               ireq->loc_addr,
25379 +               nx_map_sock_lback(current_nx_info(), ireq->loc_addr),
25380                 ntohs(inet_sk(sk)->inet_sport),
25381 -               ireq->rmt_addr,
25382 +               nx_map_sock_lback(current_nx_info(), ireq->rmt_addr),
25383                 ntohs(ireq->rmt_port),
25384                 TCP_SYN_RECV,
25385                 0, 0, /* could print option size, but that is af dependent. */
25386 @@ -2407,8 +2434,8 @@ static void get_tcp4_sock(struct sock *s
25387         struct tcp_sock *tp = tcp_sk(sk);
25388         const struct inet_connection_sock *icsk = inet_csk(sk);
25389         struct inet_sock *inet = inet_sk(sk);
25390 -       __be32 dest = inet->inet_daddr;
25391 -       __be32 src = inet->inet_rcv_saddr;
25392 +       __be32 dest = nx_map_sock_lback(current_nx_info(), inet->inet_daddr);
25393 +       __be32 src = nx_map_sock_lback(current_nx_info(), inet->inet_rcv_saddr);
25394         __u16 destp = ntohs(inet->inet_dport);
25395         __u16 srcp = ntohs(inet->inet_sport);
25396         int rx_queue;
25397 @@ -2465,8 +2492,8 @@ static void get_timewait4_sock(struct in
25398         if (ttd < 0)
25399                 ttd = 0;
25400  
25401 -       dest  = tw->tw_daddr;
25402 -       src   = tw->tw_rcv_saddr;
25403 +       dest  = nx_map_sock_lback(current_nx_info(), tw->tw_daddr);
25404 +       src   = nx_map_sock_lback(current_nx_info(), tw->tw_rcv_saddr);
25405         destp = ntohs(tw->tw_dport);
25406         srcp  = ntohs(tw->tw_sport);
25407  
25408 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
25409 --- linux-3.0.25/net/ipv4/tcp_minisocks.c       2011-03-15 18:07:45.000000000 +0100
25410 +++ linux-3.0.25-vs2.3.2.3/net/ipv4/tcp_minisocks.c     2011-06-10 22:11:24.000000000 +0200
25411 @@ -23,6 +23,9 @@
25412  #include <linux/slab.h>
25413  #include <linux/sysctl.h>
25414  #include <linux/workqueue.h>
25415 +#include <linux/vs_limit.h>
25416 +#include <linux/vs_socket.h>
25417 +#include <linux/vs_context.h>
25418  #include <net/tcp.h>
25419  #include <net/inet_common.h>
25420  #include <net/xfrm.h>
25421 @@ -335,6 +338,11 @@ void tcp_time_wait(struct sock *sk, int 
25422                 tcptw->tw_ts_recent     = tp->rx_opt.ts_recent;
25423                 tcptw->tw_ts_recent_stamp = tp->rx_opt.ts_recent_stamp;
25424  
25425 +               tw->tw_xid              = sk->sk_xid;
25426 +               tw->tw_vx_info          = NULL;
25427 +               tw->tw_nid              = sk->sk_nid;
25428 +               tw->tw_nx_info          = NULL;
25429 +
25430  #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
25431                 if (tw->tw_family == PF_INET6) {
25432                         struct ipv6_pinfo *np = inet6_sk(sk);
25433 diff -NurpP --minimal linux-3.0.25/net/ipv4/udp.c linux-3.0.25-vs2.3.2.3/net/ipv4/udp.c
25434 --- linux-3.0.25/net/ipv4/udp.c 2011-07-22 11:18:13.000000000 +0200
25435 +++ linux-3.0.25-vs2.3.2.3/net/ipv4/udp.c       2011-07-27 20:26:14.000000000 +0200
25436 @@ -296,14 +296,7 @@ fail:
25437  }
25438  EXPORT_SYMBOL(udp_lib_get_port);
25439  
25440 -static int ipv4_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2)
25441 -{
25442 -       struct inet_sock *inet1 = inet_sk(sk1), *inet2 = inet_sk(sk2);
25443 -
25444 -       return  (!ipv6_only_sock(sk2)  &&
25445 -                (!inet1->inet_rcv_saddr || !inet2->inet_rcv_saddr ||
25446 -                  inet1->inet_rcv_saddr == inet2->inet_rcv_saddr));
25447 -}
25448 +extern int ipv4_rcv_saddr_equal(const struct sock *, const struct sock *);
25449  
25450  static unsigned int udp4_portaddr_hash(struct net *net, __be32 saddr,
25451                                        unsigned int port)
25452 @@ -338,6 +331,11 @@ static inline int compute_score(struct s
25453                         if (inet->inet_rcv_saddr != daddr)
25454                                 return -1;
25455                         score += 2;
25456 +               } else {
25457 +                       /* block non nx_info ips */
25458 +                       if (!v4_addr_in_nx_info(sk->sk_nx_info,
25459 +                               daddr, NXA_MASK_BIND))
25460 +                               return -1;
25461                 }
25462                 if (inet->inet_daddr) {
25463                         if (inet->inet_daddr != saddr)
25464 @@ -441,6 +439,7 @@ exact_match:
25465         return result;
25466  }
25467  
25468 +
25469  /* UDP is nearly always wildcards out the wazoo, it makes no sense to try
25470   * harder than this. -DaveM
25471   */
25472 @@ -486,6 +485,11 @@ begin:
25473         sk_nulls_for_each_rcu(sk, node, &hslot->head) {
25474                 score = compute_score(sk, net, saddr, hnum, sport,
25475                                       daddr, dport, dif);
25476 +               /* FIXME: disabled?
25477 +               if (score == 9) {
25478 +                       result = sk;
25479 +                       break;
25480 +               } else */
25481                 if (score > badness) {
25482                         result = sk;
25483                         badness = score;
25484 @@ -499,6 +503,7 @@ begin:
25485         if (get_nulls_value(node) != slot)
25486                 goto begin;
25487  
25488 +
25489         if (result) {
25490                 if (unlikely(!atomic_inc_not_zero_hint(&result->sk_refcnt, 2)))
25491                         result = NULL;
25492 @@ -508,6 +513,7 @@ begin:
25493                         goto begin;
25494                 }
25495         }
25496 +
25497         rcu_read_unlock();
25498         return result;
25499  }
25500 @@ -550,8 +556,7 @@ static inline struct sock *udp_v4_mcast_
25501                     udp_sk(s)->udp_port_hash != hnum ||
25502                     (inet->inet_daddr && inet->inet_daddr != rmt_addr) ||
25503                     (inet->inet_dport != rmt_port && inet->inet_dport) ||
25504 -                   (inet->inet_rcv_saddr &&
25505 -                    inet->inet_rcv_saddr != loc_addr) ||
25506 +                   !v4_sock_addr_match(sk->sk_nx_info, inet, loc_addr) ||
25507                     ipv6_only_sock(s) ||
25508                     (s->sk_bound_dev_if && s->sk_bound_dev_if != dif))
25509                         continue;
25510 @@ -929,6 +934,16 @@ int udp_sendmsg(struct kiocb *iocb, stru
25511                                    inet_sk_flowi_flags(sk)|FLOWI_FLAG_CAN_SLEEP,
25512                                    faddr, saddr, dport, inet->inet_sport);
25513  
25514 +               if (sk->sk_nx_info) {
25515 +                       rt = ip_v4_find_src(net, sk->sk_nx_info, fl4);
25516 +                       if (IS_ERR(rt)) {
25517 +                               err = PTR_ERR(rt);
25518 +                               rt = NULL;
25519 +                               goto out;
25520 +                       }
25521 +                       ip_rt_put(rt);
25522 +               }
25523 +
25524                 security_sk_classify_flow(sk, flowi4_to_flowi(fl4));
25525                 rt = ip_route_output_flow(net, fl4, sk);
25526                 if (IS_ERR(rt)) {
25527 @@ -1226,7 +1241,8 @@ try_again:
25528         if (sin) {
25529                 sin->sin_family = AF_INET;
25530                 sin->sin_port = udp_hdr(skb)->source;
25531 -               sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
25532 +               sin->sin_addr.s_addr = nx_map_sock_lback(
25533 +                       skb->sk->sk_nx_info, ip_hdr(skb)->saddr);
25534                 memset(sin->sin_zero, 0, sizeof(sin->sin_zero));
25535         }
25536         if (inet->cmsg_flags)
25537 @@ -1970,6 +1986,8 @@ static struct sock *udp_get_first(struct
25538                 sk_nulls_for_each(sk, node, &hslot->head) {
25539                         if (!net_eq(sock_net(sk), net))
25540                                 continue;
25541 +                       if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
25542 +                               continue;
25543                         if (sk->sk_family == state->family)
25544                                 goto found;
25545                 }
25546 @@ -1987,7 +2005,9 @@ static struct sock *udp_get_next(struct 
25547  
25548         do {
25549                 sk = sk_nulls_next(sk);
25550 -       } while (sk && (!net_eq(sock_net(sk), net) || sk->sk_family != state->family));
25551 +       } while (sk && (!net_eq(sock_net(sk), net) ||
25552 +               sk->sk_family != state->family ||
25553 +               !nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT)));
25554  
25555         if (!sk) {
25556                 if (state->bucket <= state->udp_table->mask)
25557 diff -NurpP --minimal linux-3.0.25/net/ipv6/Kconfig linux-3.0.25-vs2.3.2.3/net/ipv6/Kconfig
25558 --- linux-3.0.25/net/ipv6/Kconfig       2010-08-02 16:52:59.000000000 +0200
25559 +++ linux-3.0.25-vs2.3.2.3/net/ipv6/Kconfig     2011-06-10 22:11:24.000000000 +0200
25560 @@ -4,8 +4,8 @@
25561  
25562  #   IPv6 as module will cause a CRASH if you try to unload it
25563  menuconfig IPV6
25564 -       tristate "The IPv6 protocol"
25565 -       default m
25566 +       bool "The IPv6 protocol"
25567 +       default n
25568         ---help---
25569           This is complemental support for the IP version 6.
25570           You will still be able to do traditional IPv4 networking as well.
25571 diff -NurpP --minimal linux-3.0.25/net/ipv6/addrconf.c linux-3.0.25-vs2.3.2.3/net/ipv6/addrconf.c
25572 --- linux-3.0.25/net/ipv6/addrconf.c    2012-03-19 21:16:57.000000000 +0100
25573 +++ linux-3.0.25-vs2.3.2.3/net/ipv6/addrconf.c  2012-03-23 14:54:00.000000000 +0100
25574 @@ -87,6 +87,8 @@
25575  
25576  #include <linux/proc_fs.h>
25577  #include <linux/seq_file.h>
25578 +#include <linux/vs_network.h>
25579 +#include <linux/vs_inet6.h>
25580  
25581  /* Set to 3 to get tracing... */
25582  #define ACONF_DEBUG 2
25583 @@ -1112,7 +1114,7 @@ out:
25584  
25585  int ipv6_dev_get_saddr(struct net *net, struct net_device *dst_dev,
25586                        const struct in6_addr *daddr, unsigned int prefs,
25587 -                      struct in6_addr *saddr)
25588 +                      struct in6_addr *saddr, struct nx_info *nxi)
25589  {
25590         struct ipv6_saddr_score scores[2],
25591                                 *score = &scores[0], *hiscore = &scores[1];
25592 @@ -1184,6 +1186,8 @@ int ipv6_dev_get_saddr(struct net *net, 
25593                                                dev->name);
25594                                 continue;
25595                         }
25596 +                       if (!v6_addr_in_nx_info(nxi, &score->ifa->addr, -1))
25597 +                               continue;
25598  
25599                         score->rule = -1;
25600                         bitmap_zero(score->scorebits, IPV6_SADDR_RULE_MAX);
25601 @@ -3052,7 +3056,10 @@ static void if6_seq_stop(struct seq_file
25602  static int if6_seq_show(struct seq_file *seq, void *v)
25603  {
25604         struct inet6_ifaddr *ifp = (struct inet6_ifaddr *)v;
25605 -       seq_printf(seq, "%pi6 %02x %02x %02x %02x %8s\n",
25606 +
25607 +       if (nx_check(0, VS_ADMIN|VS_WATCH) ||
25608 +           v6_addr_in_nx_info(current_nx_info(), &ifp->addr, -1))
25609 +               seq_printf(seq, "%pi6 %02x %02x %02x %02x %8s\n",
25610                    &ifp->addr,
25611                    ifp->idev->dev->ifindex,
25612                    ifp->prefix_len,
25613 @@ -3558,6 +3565,11 @@ static int in6_dump_addrs(struct inet6_d
25614         struct ifacaddr6 *ifaca;
25615         int err = 1;
25616         int ip_idx = *p_ip_idx;
25617 +       struct nx_info *nxi = skb->sk ? skb->sk->sk_nx_info : NULL;
25618 +
25619 +       /* disable ipv6 on non v6 guests */
25620 +       if (nxi && !nx_info_has_v6(nxi))
25621 +               return skb->len;
25622  
25623         read_lock_bh(&idev->lock);
25624         switch (type) {
25625 @@ -3568,6 +3580,8 @@ static int in6_dump_addrs(struct inet6_d
25626                 list_for_each_entry(ifa, &idev->addr_list, if_list) {
25627                         if (++ip_idx < s_ip_idx)
25628                                 continue;
25629 +                               if (!v6_addr_in_nx_info(nxi, &ifa->addr, -1))
25630 +                                       continue;
25631                         err = inet6_fill_ifaddr(skb, ifa,
25632                                                 NETLINK_CB(cb->skb).pid,
25633                                                 cb->nlh->nlmsg_seq,
25634 @@ -3584,6 +3598,8 @@ static int in6_dump_addrs(struct inet6_d
25635                      ifmca = ifmca->next, ip_idx++) {
25636                         if (ip_idx < s_ip_idx)
25637                                 continue;
25638 +                               if (!v6_addr_in_nx_info(nxi, &ifmca->mca_addr, -1))
25639 +                                       continue;
25640                         err = inet6_fill_ifmcaddr(skb, ifmca,
25641                                                   NETLINK_CB(cb->skb).pid,
25642                                                   cb->nlh->nlmsg_seq,
25643 @@ -3599,6 +3615,8 @@ static int in6_dump_addrs(struct inet6_d
25644                      ifaca = ifaca->aca_next, ip_idx++) {
25645                         if (ip_idx < s_ip_idx)
25646                                 continue;
25647 +                               if (!v6_addr_in_nx_info(nxi, &ifaca->aca_addr, -1))
25648 +                                       continue;
25649                         err = inet6_fill_ifacaddr(skb, ifaca,
25650                                                   NETLINK_CB(cb->skb).pid,
25651                                                   cb->nlh->nlmsg_seq,
25652 @@ -3984,6 +4002,11 @@ static int inet6_dump_ifinfo(struct sk_b
25653         struct inet6_dev *idev;
25654         struct hlist_head *head;
25655         struct hlist_node *node;
25656 +       struct nx_info *nxi = skb->sk ? skb->sk->sk_nx_info : NULL;
25657 +
25658 +       /* FIXME: maybe disable ipv6 on non v6 guests?
25659 +       if (skb->sk && skb->sk->sk_vx_info)
25660 +               return skb->len; */
25661  
25662         s_h = cb->args[0];
25663         s_idx = cb->args[1];
25664 @@ -3995,6 +4018,8 @@ static int inet6_dump_ifinfo(struct sk_b
25665                 hlist_for_each_entry_rcu(dev, node, head, index_hlist) {
25666                         if (idx < s_idx)
25667                                 goto cont;
25668 +                       if (!v6_dev_in_nx_info(dev, nxi))
25669 +                               goto cont;
25670                         idev = __in6_dev_get(dev);
25671                         if (!idev)
25672                                 goto cont;
25673 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
25674 --- linux-3.0.25/net/ipv6/af_inet6.c    2012-03-19 21:16:57.000000000 +0100
25675 +++ linux-3.0.25-vs2.3.2.3/net/ipv6/af_inet6.c  2011-08-29 03:45:10.000000000 +0200
25676 @@ -42,6 +42,8 @@
25677  #include <linux/netdevice.h>
25678  #include <linux/icmpv6.h>
25679  #include <linux/netfilter_ipv6.h>
25680 +#include <linux/vs_inet.h>
25681 +#include <linux/vs_inet6.h>
25682  
25683  #include <net/ip.h>
25684  #include <net/ipv6.h>
25685 @@ -160,9 +162,12 @@ lookup_protocol:
25686         }
25687  
25688         err = -EPERM;
25689 +       if ((protocol == IPPROTO_ICMPV6) &&
25690 +               nx_capable(CAP_NET_RAW, NXC_RAW_ICMP))
25691 +               goto override;
25692         if (sock->type == SOCK_RAW && !kern && !capable(CAP_NET_RAW))
25693                 goto out_rcu_unlock;
25694 -
25695 +override:
25696         sock->ops = answer->ops;
25697         answer_prot = answer->prot;
25698         answer_no_check = answer->no_check;
25699 @@ -261,6 +266,7 @@ int inet6_bind(struct socket *sock, stru
25700         struct inet_sock *inet = inet_sk(sk);
25701         struct ipv6_pinfo *np = inet6_sk(sk);
25702         struct net *net = sock_net(sk);
25703 +       struct nx_v6_sock_addr nsa;
25704         __be32 v4addr = 0;
25705         unsigned short snum;
25706         int addr_type = 0;
25707 @@ -276,6 +282,10 @@ int inet6_bind(struct socket *sock, stru
25708         if (addr->sin6_family != AF_INET6)
25709                 return -EAFNOSUPPORT;
25710  
25711 +       err = v6_map_sock_addr(inet, addr, &nsa);
25712 +       if (err)
25713 +               return err;
25714 +
25715         addr_type = ipv6_addr_type(&addr->sin6_addr);
25716         if ((addr_type & IPV6_ADDR_MULTICAST) && sock->type == SOCK_STREAM)
25717                 return -EINVAL;
25718 @@ -307,6 +317,7 @@ int inet6_bind(struct socket *sock, stru
25719                 /* Reproduce AF_INET checks to make the bindings consistent */
25720                 v4addr = addr->sin6_addr.s6_addr32[3];
25721                 chk_addr_ret = inet_addr_type(net, v4addr);
25722 +
25723                 if (!sysctl_ip_nonlocal_bind &&
25724                     !(inet->freebind || inet->transparent) &&
25725                     v4addr != htonl(INADDR_ANY) &&
25726 @@ -316,6 +327,10 @@ int inet6_bind(struct socket *sock, stru
25727                         err = -EADDRNOTAVAIL;
25728                         goto out;
25729                 }
25730 +               if (!v4_addr_in_nx_info(sk->sk_nx_info, v4addr, NXA_MASK_BIND)) {
25731 +                       err = -EADDRNOTAVAIL;
25732 +                       goto out;
25733 +               }
25734         } else {
25735                 if (addr_type != IPV6_ADDR_ANY) {
25736                         struct net_device *dev = NULL;
25737 @@ -342,6 +357,11 @@ int inet6_bind(struct socket *sock, stru
25738                                 }
25739                         }
25740  
25741 +                       if (!v6_addr_in_nx_info(sk->sk_nx_info, &addr->sin6_addr, -1)) {
25742 +                               err = -EADDRNOTAVAIL;
25743 +                               goto out;
25744 +                       }
25745 +
25746                         /* ipv4 addr of the socket is invalid.  Only the
25747                          * unspecified and mapped address have a v4 equivalent.
25748                          */
25749 @@ -358,6 +378,9 @@ int inet6_bind(struct socket *sock, stru
25750                 }
25751         }
25752  
25753 +       /* what's that for? */
25754 +       v6_set_sock_addr(inet, &nsa);
25755 +
25756         inet->inet_rcv_saddr = v4addr;
25757         inet->inet_saddr = v4addr;
25758  
25759 @@ -459,9 +482,11 @@ int inet6_getname(struct socket *sock, s
25760                         return -ENOTCONN;
25761                 sin->sin6_port = inet->inet_dport;
25762                 ipv6_addr_copy(&sin->sin6_addr, &np->daddr);
25763 +               /* FIXME: remap lback? */
25764                 if (np->sndflow)
25765                         sin->sin6_flowinfo = np->flow_label;
25766         } else {
25767 +               /* FIXME: remap lback? */
25768                 if (ipv6_addr_any(&np->rcv_saddr))
25769                         ipv6_addr_copy(&sin->sin6_addr, &np->saddr);
25770                 else
25771 diff -NurpP --minimal linux-3.0.25/net/ipv6/datagram.c linux-3.0.25-vs2.3.2.3/net/ipv6/datagram.c
25772 --- linux-3.0.25/net/ipv6/datagram.c    2011-05-22 16:18:00.000000000 +0200
25773 +++ linux-3.0.25-vs2.3.2.3/net/ipv6/datagram.c  2011-09-17 19:24:15.000000000 +0200
25774 @@ -639,7 +639,7 @@ int datagram_send_ctl(struct net *net,
25775  
25776                         rcu_read_lock();
25777                         if (fl6->flowi6_oif) {
25778 -                               dev = dev_get_by_index_rcu(net, fl6->flowi6_oif);
25779 +                               dev = dev_get_by_index_real_rcu(net, fl6->flowi6_oif);
25780                                 if (!dev) {
25781                                         rcu_read_unlock();
25782                                         return -ENODEV;
25783 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
25784 --- linux-3.0.25/net/ipv6/fib6_rules.c  2011-05-22 16:18:00.000000000 +0200
25785 +++ linux-3.0.25-vs2.3.2.3/net/ipv6/fib6_rules.c        2011-06-10 22:11:24.000000000 +0200
25786 @@ -90,7 +90,7 @@ static int fib6_rule_action(struct fib_r
25787                                                ip6_dst_idev(&rt->dst)->dev,
25788                                                &flp6->daddr,
25789                                                rt6_flags2srcprefs(flags),
25790 -                                              &saddr))
25791 +                                              &saddr, NULL))
25792                                 goto again;
25793                         if (!ipv6_prefix_equal(&saddr, &r->src.addr,
25794                                                r->src.plen))
25795 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
25796 --- linux-3.0.25/net/ipv6/inet6_hashtables.c    2012-03-19 21:16:57.000000000 +0100
25797 +++ linux-3.0.25-vs2.3.2.3/net/ipv6/inet6_hashtables.c  2011-08-29 03:45:10.000000000 +0200
25798 @@ -16,6 +16,7 @@
25799  
25800  #include <linux/module.h>
25801  #include <linux/random.h>
25802 +#include <linux/vs_inet6.h>
25803  
25804  #include <net/inet_connection_sock.h>
25805  #include <net/inet_hashtables.h>
25806 @@ -83,7 +84,6 @@ struct sock *__inet6_lookup_established(
25807         unsigned int slot = hash & hashinfo->ehash_mask;
25808         struct inet_ehash_bucket *head = &hashinfo->ehash[slot];
25809  
25810 -
25811         rcu_read_lock();
25812  begin:
25813         sk_nulls_for_each_rcu(sk, node, &head->chain) {
25814 @@ -95,7 +95,7 @@ begin:
25815                                 sock_put(sk);
25816                                 goto begin;
25817                         }
25818 -               goto out;
25819 +                       goto out;
25820                 }
25821         }
25822         if (get_nulls_value(node) != slot)
25823 @@ -141,6 +141,9 @@ static inline int compute_score(struct s
25824                         if (!ipv6_addr_equal(&np->rcv_saddr, daddr))
25825                                 return -1;
25826                         score++;
25827 +               } else {
25828 +                       if (!v6_addr_in_nx_info(sk->sk_nx_info, daddr, -1))
25829 +                               return -1;
25830                 }
25831                 if (sk->sk_bound_dev_if) {
25832                         if (sk->sk_bound_dev_if != dif)
25833 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
25834 --- linux-3.0.25/net/ipv6/ip6_output.c  2012-03-19 21:16:57.000000000 +0100
25835 +++ linux-3.0.25-vs2.3.2.3/net/ipv6/ip6_output.c        2012-02-15 05:20:43.000000000 +0100
25836 @@ -979,7 +979,8 @@ static int ip6_dst_lookup_tail(struct so
25837                 struct rt6_info *rt = (struct rt6_info *) *dst;
25838                 err = ip6_route_get_saddr(net, rt, &fl6->daddr,
25839                                           sk ? inet6_sk(sk)->srcprefs : 0,
25840 -                                         &fl6->saddr);
25841 +                                         &fl6->saddr,
25842 +                                         sk ? sk->sk_nx_info : NULL);
25843                 if (err)
25844                         goto out_err_release;
25845         }
25846 diff -NurpP --minimal linux-3.0.25/net/ipv6/ndisc.c linux-3.0.25-vs2.3.2.3/net/ipv6/ndisc.c
25847 --- linux-3.0.25/net/ipv6/ndisc.c       2012-03-19 21:16:57.000000000 +0100
25848 +++ linux-3.0.25-vs2.3.2.3/net/ipv6/ndisc.c     2012-02-15 05:20:43.000000000 +0100
25849 @@ -597,7 +597,7 @@ static void ndisc_send_na(struct net_dev
25850         } else {
25851                 if (ipv6_dev_get_saddr(dev_net(dev), dev, daddr,
25852                                        inet6_sk(dev_net(dev)->ipv6.ndisc_sk)->srcprefs,
25853 -                                      &tmpaddr))
25854 +                                      &tmpaddr, NULL))
25855                         return;
25856                 src_addr = &tmpaddr;
25857         }
25858 diff -NurpP --minimal linux-3.0.25/net/ipv6/raw.c linux-3.0.25-vs2.3.2.3/net/ipv6/raw.c
25859 --- linux-3.0.25/net/ipv6/raw.c 2011-07-22 11:18:13.000000000 +0200
25860 +++ linux-3.0.25-vs2.3.2.3/net/ipv6/raw.c       2011-06-10 22:11:24.000000000 +0200
25861 @@ -30,6 +30,7 @@
25862  #include <linux/icmpv6.h>
25863  #include <linux/netfilter.h>
25864  #include <linux/netfilter_ipv6.h>
25865 +#include <linux/vs_inet6.h>
25866  #include <linux/skbuff.h>
25867  #include <linux/compat.h>
25868  #include <asm/uaccess.h>
25869 @@ -284,6 +285,13 @@ static int rawv6_bind(struct sock *sk, s
25870                                 goto out_unlock;
25871                 }
25872  
25873 +               if (!v6_addr_in_nx_info(sk->sk_nx_info, &addr->sin6_addr, -1)) {
25874 +                       err = -EADDRNOTAVAIL;
25875 +                       if (dev)
25876 +                               dev_put(dev);
25877 +                       goto out;
25878 +               }
25879 +
25880                 /* ipv4 addr of the socket is invalid.  Only the
25881                  * unspecified and mapped address have a v4 equivalent.
25882                  */
25883 diff -NurpP --minimal linux-3.0.25/net/ipv6/route.c linux-3.0.25-vs2.3.2.3/net/ipv6/route.c
25884 --- linux-3.0.25/net/ipv6/route.c       2012-03-19 21:16:57.000000000 +0100
25885 +++ linux-3.0.25-vs2.3.2.3/net/ipv6/route.c     2012-02-15 05:20:43.000000000 +0100
25886 @@ -54,6 +54,7 @@
25887  #include <net/xfrm.h>
25888  #include <net/netevent.h>
25889  #include <net/netlink.h>
25890 +#include <linux/vs_inet6.h>
25891  
25892  #include <asm/uaccess.h>
25893  
25894 @@ -2058,15 +2059,17 @@ int ip6_route_get_saddr(struct net *net,
25895                         struct rt6_info *rt,
25896                         const struct in6_addr *daddr,
25897                         unsigned int prefs,
25898 -                       struct in6_addr *saddr)
25899 +                       struct in6_addr *saddr,
25900 +                       struct nx_info *nxi)
25901  {
25902         struct inet6_dev *idev = ip6_dst_idev((struct dst_entry*)rt);
25903         int err = 0;
25904 -       if (rt->rt6i_prefsrc.plen)
25905 +       if (rt->rt6i_prefsrc.plen && (!nxi ||
25906 +           v6_addr_in_nx_info(nxi, &rt->rt6i_prefsrc.addr, NXA_TYPE_ADDR)))
25907                 ipv6_addr_copy(saddr, &rt->rt6i_prefsrc.addr);
25908         else
25909                 err = ipv6_dev_get_saddr(net, idev ? idev->dev : NULL,
25910 -                                        daddr, prefs, saddr);
25911 +                                        daddr, prefs, saddr, nxi);
25912         return err;
25913  }
25914  
25915 @@ -2396,7 +2399,8 @@ static int rt6_fill_node(struct net *net
25916                         NLA_PUT_U32(skb, RTA_IIF, iif);
25917         } else if (dst) {
25918                 struct in6_addr saddr_buf;
25919 -               if (ip6_route_get_saddr(net, rt, dst, 0, &saddr_buf) == 0)
25920 +               if (ip6_route_get_saddr(net, rt, dst, 0, &saddr_buf,
25921 +                                       (skb->sk ? skb->sk->sk_nx_info : NULL)) == 0)
25922                         NLA_PUT(skb, RTA_PREFSRC, 16, &saddr_buf);
25923         }
25924  
25925 @@ -2599,6 +2603,7 @@ static int rt6_info_route(struct rt6_inf
25926         struct seq_file *m = p_arg;
25927         struct neighbour *n;
25928  
25929 +       /* FIXME: check for network context? */
25930         seq_printf(m, "%pi6 %02x ", &rt->rt6i_dst.addr, rt->rt6i_dst.plen);
25931  
25932  #ifdef CONFIG_IPV6_SUBTREES
25933 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
25934 --- linux-3.0.25/net/ipv6/tcp_ipv6.c    2012-03-19 21:16:57.000000000 +0100
25935 +++ linux-3.0.25-vs2.3.2.3/net/ipv6/tcp_ipv6.c  2012-02-07 02:05:58.000000000 +0100
25936 @@ -70,6 +70,7 @@
25937  
25938  #include <linux/crypto.h>
25939  #include <linux/scatterlist.h>
25940 +#include <linux/vs_inet6.h>
25941  
25942  static void    tcp_v6_send_reset(struct sock *sk, struct sk_buff *skb);
25943  static void    tcp_v6_reqsk_send_ack(struct sock *sk, struct sk_buff *skb,
25944 @@ -162,8 +163,15 @@ static int tcp_v6_connect(struct sock *s
25945          *      connect() to INADDR_ANY means loopback (BSD'ism).
25946          */
25947  
25948 -       if(ipv6_addr_any(&usin->sin6_addr))
25949 -               usin->sin6_addr.s6_addr[15] = 0x1;
25950 +       if(ipv6_addr_any(&usin->sin6_addr)) {
25951 +               struct nx_info *nxi =  sk->sk_nx_info;
25952 +
25953 +               if (nxi && nx_info_has_v6(nxi))
25954 +                       /* FIXME: remap lback? */
25955 +                       usin->sin6_addr = nxi->v6.ip;
25956 +               else
25957 +                       usin->sin6_addr.s6_addr[15] = 0x1;
25958 +       }
25959  
25960         addr_type = ipv6_addr_type(&usin->sin6_addr);
25961  
25962 diff -NurpP --minimal linux-3.0.25/net/ipv6/udp.c linux-3.0.25-vs2.3.2.3/net/ipv6/udp.c
25963 --- linux-3.0.25/net/ipv6/udp.c 2012-03-19 21:16:57.000000000 +0100
25964 +++ linux-3.0.25-vs2.3.2.3/net/ipv6/udp.c       2011-10-18 13:51:13.000000000 +0200
25965 @@ -45,41 +45,67 @@
25966  #include <net/tcp_states.h>
25967  #include <net/ip6_checksum.h>
25968  #include <net/xfrm.h>
25969 +#include <linux/vs_inet6.h>
25970  
25971  #include <linux/proc_fs.h>
25972  #include <linux/seq_file.h>
25973  #include "udp_impl.h"
25974  
25975 -int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
25976 +int ipv6_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2)
25977  {
25978 -       const struct in6_addr *sk_rcv_saddr6 = &inet6_sk(sk)->rcv_saddr;
25979 +       const struct in6_addr *sk1_rcv_saddr6 = &inet6_sk(sk1)->rcv_saddr;
25980         const struct in6_addr *sk2_rcv_saddr6 = inet6_rcv_saddr(sk2);
25981 -       __be32 sk1_rcv_saddr = sk_rcv_saddr(sk);
25982 +       __be32 sk1_rcv_saddr = sk_rcv_saddr(sk1);
25983         __be32 sk2_rcv_saddr = sk_rcv_saddr(sk2);
25984 -       int sk_ipv6only = ipv6_only_sock(sk);
25985 +       int sk1_ipv6only = ipv6_only_sock(sk1);
25986         int sk2_ipv6only = inet_v6_ipv6only(sk2);
25987 -       int addr_type = ipv6_addr_type(sk_rcv_saddr6);
25988 +       int addr_type = ipv6_addr_type(sk1_rcv_saddr6);
25989         int addr_type2 = sk2_rcv_saddr6 ? ipv6_addr_type(sk2_rcv_saddr6) : IPV6_ADDR_MAPPED;
25990  
25991         /* if both are mapped, treat as IPv4 */
25992 -       if (addr_type == IPV6_ADDR_MAPPED && addr_type2 == IPV6_ADDR_MAPPED)
25993 -               return (!sk2_ipv6only &&
25994 +       if (addr_type == IPV6_ADDR_MAPPED && addr_type2 == IPV6_ADDR_MAPPED) {
25995 +               if (!sk2_ipv6only &&
25996                         (!sk1_rcv_saddr || !sk2_rcv_saddr ||
25997 -                         sk1_rcv_saddr == sk2_rcv_saddr));
25998 +                         sk1_rcv_saddr == sk2_rcv_saddr))
25999 +                       goto vs_v4;
26000 +               else
26001 +                       return 0;
26002 +       }
26003  
26004         if (addr_type2 == IPV6_ADDR_ANY &&
26005             !(sk2_ipv6only && addr_type == IPV6_ADDR_MAPPED))
26006 -               return 1;
26007 +               goto vs;
26008  
26009         if (addr_type == IPV6_ADDR_ANY &&
26010 -           !(sk_ipv6only && addr_type2 == IPV6_ADDR_MAPPED))
26011 -               return 1;
26012 +           !(sk1_ipv6only && addr_type2 == IPV6_ADDR_MAPPED))
26013 +               goto vs;
26014  
26015         if (sk2_rcv_saddr6 &&
26016 -           ipv6_addr_equal(sk_rcv_saddr6, sk2_rcv_saddr6))
26017 -               return 1;
26018 +           ipv6_addr_equal(sk1_rcv_saddr6, sk2_rcv_saddr6))
26019 +               goto vs;
26020  
26021         return 0;
26022 +
26023 +vs_v4:
26024 +       if (!sk1_rcv_saddr && !sk2_rcv_saddr)
26025 +               return nx_v4_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info);
26026 +       if (!sk2_rcv_saddr)
26027 +               return v4_addr_in_nx_info(sk1->sk_nx_info, sk2_rcv_saddr, -1);
26028 +       if (!sk1_rcv_saddr)
26029 +               return v4_addr_in_nx_info(sk2->sk_nx_info, sk1_rcv_saddr, -1);
26030 +       return 1;
26031 +vs:
26032 +       if (addr_type2 == IPV6_ADDR_ANY && addr_type == IPV6_ADDR_ANY)
26033 +               return nx_v6_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info);
26034 +       else if (addr_type2 == IPV6_ADDR_ANY)
26035 +               return v6_addr_in_nx_info(sk2->sk_nx_info, sk1_rcv_saddr6, -1);
26036 +       else if (addr_type == IPV6_ADDR_ANY) {
26037 +               if (addr_type2 == IPV6_ADDR_MAPPED)
26038 +                       return nx_v4_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info);
26039 +               else
26040 +                       return v6_addr_in_nx_info(sk1->sk_nx_info, sk2_rcv_saddr6, -1);
26041 +       }
26042 +       return 1;
26043  }
26044  
26045  static unsigned int udp6_portaddr_hash(struct net *net,
26046 @@ -143,6 +169,10 @@ static inline int compute_score(struct s
26047                         if (!ipv6_addr_equal(&np->rcv_saddr, daddr))
26048                                 return -1;
26049                         score++;
26050 +               } else {
26051 +                       /* block non nx_info ips */
26052 +                       if (!v6_addr_in_nx_info(sk->sk_nx_info, daddr, -1))
26053 +                               return -1;
26054                 }
26055                 if (!ipv6_addr_any(&np->daddr)) {
26056                         if (!ipv6_addr_equal(&np->daddr, saddr))
26057 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
26058 --- linux-3.0.25/net/ipv6/xfrm6_policy.c        2011-07-22 11:18:13.000000000 +0200
26059 +++ linux-3.0.25-vs2.3.2.3/net/ipv6/xfrm6_policy.c      2011-06-10 22:11:24.000000000 +0200
26060 @@ -63,7 +63,7 @@ static int xfrm6_get_saddr(struct net *n
26061         dev = ip6_dst_idev(dst)->dev;
26062         ipv6_dev_get_saddr(dev_net(dev), dev,
26063                            (struct in6_addr *)&daddr->a6, 0,
26064 -                          (struct in6_addr *)&saddr->a6);
26065 +                          (struct in6_addr *)&saddr->a6, NULL);
26066         dst_release(dst);
26067         return 0;
26068  }
26069 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
26070 --- linux-3.0.25/net/netfilter/ipvs/ip_vs_xmit.c        2011-07-22 11:18:13.000000000 +0200
26071 +++ linux-3.0.25-vs2.3.2.3/net/netfilter/ipvs/ip_vs_xmit.c      2011-07-22 15:27:52.000000000 +0200
26072 @@ -226,7 +226,7 @@ __ip_vs_route_output_v6(struct net *net,
26073                 return dst;
26074         if (ipv6_addr_any(&fl6.saddr) &&
26075             ipv6_dev_get_saddr(net, ip6_dst_idev(dst)->dev,
26076 -                              &fl6.daddr, 0, &fl6.saddr) < 0)
26077 +                              &fl6.daddr, 0, &fl6.saddr, NULL) < 0)
26078                 goto out_err;
26079         if (do_xfrm) {
26080                 dst = xfrm_lookup(net, dst, flowi6_to_flowi(&fl6), NULL, 0);
26081 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
26082 --- linux-3.0.25/net/netlink/af_netlink.c       2011-07-22 11:18:13.000000000 +0200
26083 +++ linux-3.0.25-vs2.3.2.3/net/netlink/af_netlink.c     2011-06-10 22:11:24.000000000 +0200
26084 @@ -55,6 +55,9 @@
26085  #include <linux/types.h>
26086  #include <linux/audit.h>
26087  #include <linux/mutex.h>
26088 +#include <linux/vs_context.h>
26089 +#include <linux/vs_network.h>
26090 +#include <linux/vs_limit.h>
26091  
26092  #include <net/net_namespace.h>
26093  #include <net/sock.h>
26094 @@ -1907,6 +1910,8 @@ static struct sock *netlink_seq_socket_i
26095                         sk_for_each(s, node, &hash->table[j]) {
26096                                 if (sock_net(s) != seq_file_net(seq))
26097                                         continue;
26098 +                               if (!nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT))
26099 +                                       continue;
26100                                 if (off == pos) {
26101                                         iter->link = i;
26102                                         iter->hash_idx = j;
26103 @@ -1941,7 +1946,8 @@ static void *netlink_seq_next(struct seq
26104         s = v;
26105         do {
26106                 s = sk_next(s);
26107 -       } while (s && sock_net(s) != seq_file_net(seq));
26108 +       } while (s && (sock_net(s) != seq_file_net(seq) ||
26109 +               !nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT)));
26110         if (s)
26111                 return s;
26112  
26113 @@ -1953,7 +1959,8 @@ static void *netlink_seq_next(struct seq
26114  
26115                 for (; j <= hash->mask; j++) {
26116                         s = sk_head(&hash->table[j]);
26117 -                       while (s && sock_net(s) != seq_file_net(seq))
26118 +                       while (s && (sock_net(s) != seq_file_net(seq) ||
26119 +                               !nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT)))
26120                                 s = sk_next(s);
26121                         if (s) {
26122                                 iter->link = i;
26123 diff -NurpP --minimal linux-3.0.25/net/socket.c linux-3.0.25-vs2.3.2.3/net/socket.c
26124 --- linux-3.0.25/net/socket.c   2012-03-19 21:16:58.000000000 +0100
26125 +++ linux-3.0.25-vs2.3.2.3/net/socket.c 2011-10-18 13:51:13.000000000 +0200
26126 @@ -98,6 +98,10 @@
26127  
26128  #include <net/sock.h>
26129  #include <linux/netfilter.h>
26130 +#include <linux/vs_base.h>
26131 +#include <linux/vs_socket.h>
26132 +#include <linux/vs_inet.h>
26133 +#include <linux/vs_inet6.h>
26134  
26135  #include <linux/if_tun.h>
26136  #include <linux/ipv6_route.h>
26137 @@ -546,6 +550,7 @@ static inline int __sock_sendmsg_nosec(s
26138                                        struct msghdr *msg, size_t size)
26139  {
26140         struct sock_iocb *si = kiocb_to_siocb(iocb);
26141 +       size_t len;
26142  
26143         sock_update_classid(sock->sk);
26144  
26145 @@ -554,7 +559,22 @@ static inline int __sock_sendmsg_nosec(s
26146         si->msg = msg;
26147         si->size = size;
26148  
26149 -       return sock->ops->sendmsg(iocb, sock, msg, size);
26150 +       len = sock->ops->sendmsg(iocb, sock, msg, size);
26151 +       if (sock->sk) {
26152 +               if (len == size)
26153 +                       vx_sock_send(sock->sk, size);
26154 +               else
26155 +                       vx_sock_fail(sock->sk, size);
26156 +       }
26157 +       vxdprintk(VXD_CBIT(net, 7),
26158 +               "__sock_sendmsg: %p[%p,%p,%p;%d/%d]:%d/%zu",
26159 +               sock, sock->sk,
26160 +               (sock->sk)?sock->sk->sk_nx_info:0,
26161 +               (sock->sk)?sock->sk->sk_vx_info:0,
26162 +               (sock->sk)?sock->sk->sk_xid:0,
26163 +               (sock->sk)?sock->sk->sk_nid:0,
26164 +               (unsigned int)size, len);
26165 +       return len;
26166  }
26167  
26168  static inline int __sock_sendmsg(struct kiocb *iocb, struct socket *sock,
26169 @@ -694,6 +714,7 @@ static inline int __sock_recvmsg_nosec(s
26170                                        struct msghdr *msg, size_t size, int flags)
26171  {
26172         struct sock_iocb *si = kiocb_to_siocb(iocb);
26173 +       int len;
26174  
26175         sock_update_classid(sock->sk);
26176  
26177 @@ -703,7 +724,18 @@ static inline int __sock_recvmsg_nosec(s
26178         si->size = size;
26179         si->flags = flags;
26180  
26181 -       return sock->ops->recvmsg(iocb, sock, msg, size, flags);
26182 +       len = sock->ops->recvmsg(iocb, sock, msg, size, flags);
26183 +       if ((len >= 0) && sock->sk)
26184 +               vx_sock_recv(sock->sk, len);
26185 +       vxdprintk(VXD_CBIT(net, 7),
26186 +               "__sock_recvmsg: %p[%p,%p,%p;%d/%d]:%d/%d",
26187 +               sock, sock->sk,
26188 +               (sock->sk)?sock->sk->sk_nx_info:0,
26189 +               (sock->sk)?sock->sk->sk_vx_info:0,
26190 +               (sock->sk)?sock->sk->sk_xid:0,
26191 +               (sock->sk)?sock->sk->sk_nid:0,
26192 +               (unsigned int)size, len);
26193 +       return len;
26194  }
26195  
26196  static inline int __sock_recvmsg(struct kiocb *iocb, struct socket *sock,
26197 @@ -1188,6 +1220,13 @@ int __sock_create(struct net *net, int f
26198         if (type < 0 || type >= SOCK_MAX)
26199                 return -EINVAL;
26200  
26201 +       if (!nx_check(0, VS_ADMIN)) {
26202 +               if (family == PF_INET && !current_nx_info_has_v4())
26203 +                       return -EAFNOSUPPORT;
26204 +               if (family == PF_INET6 && !current_nx_info_has_v6())
26205 +                       return -EAFNOSUPPORT;
26206 +       }
26207 +
26208         /* Compatibility.
26209  
26210            This uglymoron is moved from INET layer to here to avoid
26211 @@ -1323,6 +1362,7 @@ SYSCALL_DEFINE3(socket, int, family, int
26212         if (retval < 0)
26213                 goto out;
26214  
26215 +       set_bit(SOCK_USER_SOCKET, &sock->flags);
26216         retval = sock_map_fd(sock, flags & (O_CLOEXEC | O_NONBLOCK));
26217         if (retval < 0)
26218                 goto out_release;
26219 @@ -1364,10 +1404,12 @@ SYSCALL_DEFINE4(socketpair, int, family,
26220         err = sock_create(family, type, protocol, &sock1);
26221         if (err < 0)
26222                 goto out;
26223 +       set_bit(SOCK_USER_SOCKET, &sock1->flags);
26224  
26225         err = sock_create(family, type, protocol, &sock2);
26226         if (err < 0)
26227                 goto out_release_1;
26228 +       set_bit(SOCK_USER_SOCKET, &sock2->flags);
26229  
26230         err = sock1->ops->socketpair(sock1, sock2);
26231         if (err < 0)
26232 diff -NurpP --minimal linux-3.0.25/net/sunrpc/auth.c linux-3.0.25-vs2.3.2.3/net/sunrpc/auth.c
26233 --- linux-3.0.25/net/sunrpc/auth.c      2011-07-22 11:18:13.000000000 +0200
26234 +++ linux-3.0.25-vs2.3.2.3/net/sunrpc/auth.c    2011-06-10 22:11:24.000000000 +0200
26235 @@ -14,6 +14,7 @@
26236  #include <linux/hash.h>
26237  #include <linux/sunrpc/clnt.h>
26238  #include <linux/spinlock.h>
26239 +#include <linux/vs_tag.h>
26240  
26241  #ifdef RPC_DEBUG
26242  # define RPCDBG_FACILITY       RPCDBG_AUTH
26243 @@ -427,6 +428,7 @@ rpcauth_lookupcred(struct rpc_auth *auth
26244         memset(&acred, 0, sizeof(acred));
26245         acred.uid = cred->fsuid;
26246         acred.gid = cred->fsgid;
26247 +       acred.tag = dx_current_tag();
26248         acred.group_info = get_group_info(((struct cred *)cred)->group_info);
26249  
26250         ret = auth->au_ops->lookup_cred(auth, &acred, flags);
26251 @@ -467,6 +469,7 @@ rpcauth_bind_root_cred(struct rpc_task *
26252         struct auth_cred acred = {
26253                 .uid = 0,
26254                 .gid = 0,
26255 +               .tag = dx_current_tag(),
26256         };
26257  
26258         dprintk("RPC: %5u looking up %s cred\n",
26259 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
26260 --- linux-3.0.25/net/sunrpc/auth_unix.c 2012-03-19 21:16:58.000000000 +0100
26261 +++ linux-3.0.25-vs2.3.2.3/net/sunrpc/auth_unix.c       2011-11-15 17:37:07.000000000 +0100
26262 @@ -12,12 +12,14 @@
26263  #include <linux/module.h>
26264  #include <linux/sunrpc/clnt.h>
26265  #include <linux/sunrpc/auth.h>
26266 +#include <linux/vs_tag.h>
26267  
26268  #define NFS_NGROUPS    16
26269  
26270  struct unx_cred {
26271         struct rpc_cred         uc_base;
26272         gid_t                   uc_gid;
26273 +       tag_t                   uc_tag;
26274         gid_t                   uc_gids[NFS_NGROUPS];
26275  };
26276  #define uc_uid                 uc_base.cr_uid
26277 @@ -78,6 +80,7 @@ unx_create_cred(struct rpc_auth *auth, s
26278                 groups = NFS_NGROUPS;
26279  
26280         cred->uc_gid = acred->gid;
26281 +       cred->uc_tag = acred->tag;
26282         for (i = 0; i < groups; i++)
26283                 cred->uc_gids[i] = GROUP_AT(acred->group_info, i);
26284         if (i < NFS_NGROUPS)
26285 @@ -119,7 +122,9 @@ unx_match(struct auth_cred *acred, struc
26286         unsigned int i;
26287  
26288  
26289 -       if (cred->uc_uid != acred->uid || cred->uc_gid != acred->gid)
26290 +       if (cred->uc_uid != acred->uid ||
26291 +               cred->uc_gid != acred->gid ||
26292 +               cred->uc_tag != acred->tag)
26293                 return 0;
26294  
26295         if (acred->group_info != NULL)
26296 @@ -145,7 +150,7 @@ unx_marshal(struct rpc_task *task, __be3
26297         struct rpc_clnt *clnt = task->tk_client;
26298         struct unx_cred *cred = container_of(task->tk_rqstp->rq_cred, struct unx_cred, uc_base);
26299         __be32          *base, *hold;
26300 -       int             i;
26301 +       int             i, tag;
26302  
26303         *p++ = htonl(RPC_AUTH_UNIX);
26304         base = p++;
26305 @@ -155,9 +160,12 @@ unx_marshal(struct rpc_task *task, __be3
26306          * Copy the UTS nodename captured when the client was created.
26307          */
26308         p = xdr_encode_array(p, clnt->cl_nodename, clnt->cl_nodelen);
26309 +       tag = task->tk_client->cl_tag;
26310  
26311 -       *p++ = htonl((u32) cred->uc_uid);
26312 -       *p++ = htonl((u32) cred->uc_gid);
26313 +       *p++ = htonl((u32) TAGINO_UID(tag,
26314 +               cred->uc_uid, cred->uc_tag));
26315 +       *p++ = htonl((u32) TAGINO_GID(tag,
26316 +               cred->uc_gid, cred->uc_tag));
26317         hold = p++;
26318         for (i = 0; i < 16 && cred->uc_gids[i] != (gid_t) NOGROUP; i++)
26319                 *p++ = htonl((u32) cred->uc_gids[i]);
26320 diff -NurpP --minimal linux-3.0.25/net/sunrpc/clnt.c linux-3.0.25-vs2.3.2.3/net/sunrpc/clnt.c
26321 --- linux-3.0.25/net/sunrpc/clnt.c      2011-07-22 11:18:13.000000000 +0200
26322 +++ linux-3.0.25-vs2.3.2.3/net/sunrpc/clnt.c    2011-07-01 11:35:35.000000000 +0200
26323 @@ -31,6 +31,7 @@
26324  #include <linux/in.h>
26325  #include <linux/in6.h>
26326  #include <linux/un.h>
26327 +#include <linux/vs_cvirt.h>
26328  
26329  #include <linux/sunrpc/clnt.h>
26330  #include <linux/sunrpc/rpc_pipe_fs.h>
26331 @@ -362,6 +363,9 @@ struct rpc_clnt *rpc_create(struct rpc_c
26332         if (!(args->flags & RPC_CLNT_CREATE_QUIET))
26333                 clnt->cl_chatty = 1;
26334  
26335 +       /* TODO: handle RPC_CLNT_CREATE_TAGGED
26336 +       if (args->flags & RPC_CLNT_CREATE_TAGGED)
26337 +               clnt->cl_tag = 1; */
26338         return clnt;
26339  }
26340  EXPORT_SYMBOL_GPL(rpc_create);
26341 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
26342 --- linux-3.0.25/net/unix/af_unix.c     2011-07-22 11:18:13.000000000 +0200
26343 +++ linux-3.0.25-vs2.3.2.3/net/unix/af_unix.c   2011-06-10 22:11:24.000000000 +0200
26344 @@ -114,6 +114,8 @@
26345  #include <linux/mount.h>
26346  #include <net/checksum.h>
26347  #include <linux/security.h>
26348 +#include <linux/vs_context.h>
26349 +#include <linux/vs_limit.h>
26350  
26351  static struct hlist_head unix_socket_table[UNIX_HASH_SIZE + 1];
26352  static DEFINE_SPINLOCK(unix_table_lock);
26353 @@ -258,6 +260,8 @@ static struct sock *__unix_find_socket_b
26354                 if (!net_eq(sock_net(s), net))
26355                         continue;
26356  
26357 +               if (!nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT))
26358 +                       continue;
26359                 if (u->addr->len == len &&
26360                     !memcmp(u->addr->name, sunname, len))
26361                         goto found;
26362 @@ -2208,6 +2212,8 @@ static struct sock *unix_seq_idx(struct 
26363         for (s = first_unix_socket(&iter->i); s; s = next_unix_socket(&iter->i, s)) {
26364                 if (sock_net(s) != seq_file_net(seq))
26365                         continue;
26366 +               if (!nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT))
26367 +                       continue;
26368                 if (off == pos)
26369                         return s;
26370                 ++off;
26371 @@ -2232,7 +2238,8 @@ static void *unix_seq_next(struct seq_fi
26372                 sk = first_unix_socket(&iter->i);
26373         else
26374                 sk = next_unix_socket(&iter->i, sk);
26375 -       while (sk && (sock_net(sk) != seq_file_net(seq)))
26376 +       while (sk && (sock_net(sk) != seq_file_net(seq) ||
26377 +               !nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT)))
26378                 sk = next_unix_socket(&iter->i, sk);
26379         return sk;
26380  }
26381 diff -NurpP --minimal linux-3.0.25/scripts/checksyscalls.sh linux-3.0.25-vs2.3.2.3/scripts/checksyscalls.sh
26382 --- linux-3.0.25/scripts/checksyscalls.sh       2011-03-15 18:07:46.000000000 +0100
26383 +++ linux-3.0.25-vs2.3.2.3/scripts/checksyscalls.sh     2011-06-10 22:11:24.000000000 +0200
26384 @@ -193,7 +193,6 @@ cat << EOF
26385  #define __IGNORE_afs_syscall
26386  #define __IGNORE_getpmsg
26387  #define __IGNORE_putpmsg
26388 -#define __IGNORE_vserver
26389  EOF
26390  }
26391  
26392 diff -NurpP --minimal linux-3.0.25/security/commoncap.c linux-3.0.25-vs2.3.2.3/security/commoncap.c
26393 --- linux-3.0.25/security/commoncap.c   2011-07-22 11:18:14.000000000 +0200
26394 +++ linux-3.0.25-vs2.3.2.3/security/commoncap.c 2011-08-30 15:42:43.000000000 +0200
26395 @@ -62,6 +62,7 @@ int cap_netlink_recv(struct sk_buff *skb
26396                 return -EPERM;
26397         return 0;
26398  }
26399 +
26400  EXPORT_SYMBOL(cap_netlink_recv);
26401  
26402  /**
26403 @@ -83,14 +84,20 @@ EXPORT_SYMBOL(cap_netlink_recv);
26404  int cap_capable(struct task_struct *tsk, const struct cred *cred,
26405                 struct user_namespace *targ_ns, int cap, int audit)
26406  {
26407 +       struct vx_info *vxi = tsk->vx_info;
26408 +
26409         for (;;) {
26410                 /* The creator of the user namespace has all caps. */
26411                 if (targ_ns != &init_user_ns && targ_ns->creator == cred->user)
26412                         return 0;
26413  
26414                 /* Do we have the necessary capabilities? */
26415 -               if (targ_ns == cred->user->user_ns)
26416 -                       return cap_raised(cred->cap_effective, cap) ? 0 : -EPERM;
26417 +               if (targ_ns == cred->user->user_ns) {
26418 +                       if (vx_info_flags(vxi, VXF_STATE_SETUP, 0) &&
26419 +                           cap_raised(cred->cap_effective, cap))
26420 +                               return 0;
26421 +                       return vx_cap_raised(vxi, cred->cap_effective, cap) ? 0 : -EPERM;
26422 +               }
26423  
26424                 /* Have we tried all of the parent namespaces? */
26425                 if (targ_ns == &init_user_ns)
26426 @@ -611,7 +618,7 @@ int cap_inode_setxattr(struct dentry *de
26427  
26428         if (!strncmp(name, XATTR_SECURITY_PREFIX,
26429                      sizeof(XATTR_SECURITY_PREFIX) - 1) &&
26430 -           !capable(CAP_SYS_ADMIN))
26431 +               !vx_capable(CAP_SYS_ADMIN, VXC_FS_SECURITY))
26432                 return -EPERM;
26433         return 0;
26434  }
26435 @@ -637,7 +644,7 @@ int cap_inode_removexattr(struct dentry 
26436  
26437         if (!strncmp(name, XATTR_SECURITY_PREFIX,
26438                      sizeof(XATTR_SECURITY_PREFIX) - 1) &&
26439 -           !capable(CAP_SYS_ADMIN))
26440 +               !vx_capable(CAP_SYS_ADMIN, VXC_FS_SECURITY))
26441                 return -EPERM;
26442         return 0;
26443  }
26444 diff -NurpP --minimal linux-3.0.25/security/selinux/hooks.c linux-3.0.25-vs2.3.2.3/security/selinux/hooks.c
26445 --- linux-3.0.25/security/selinux/hooks.c       2011-07-22 11:18:14.000000000 +0200
26446 +++ linux-3.0.25-vs2.3.2.3/security/selinux/hooks.c     2011-06-15 02:40:14.000000000 +0200
26447 @@ -67,7 +67,6 @@
26448  #include <linux/dccp.h>
26449  #include <linux/quota.h>
26450  #include <linux/un.h>          /* for Unix socket types */
26451 -#include <net/af_unix.h>       /* for Unix socket types */
26452  #include <linux/parser.h>
26453  #include <linux/nfs_mount.h>
26454  #include <net/ipv6.h>
This page took 2.307953 seconds and 3 git commands to generate.