]> git.pld-linux.org Git - packages/kernel.git/blob - kernel-vserver-2.3.patch
- rel 1; update vserver to patch-2.6.38.1-vs2.3.0.37-rc9.dif; up grsec to grsecurity...
[packages/kernel.git] / kernel-vserver-2.3.patch
1 diff -NurpP --minimal linux-2.6.38.1/Documentation/vserver/debug.txt linux-2.6.38.1-vs2.3.0.37-rc9/Documentation/vserver/debug.txt
2 --- linux-2.6.38.1/Documentation/vserver/debug.txt      1970-01-01 01:00:00.000000000 +0100
3 +++ linux-2.6.38.1-vs2.3.0.37-rc9/Documentation/vserver/debug.txt       2011-01-29 02:01:07.000000000 +0100
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-2.6.38.1/arch/alpha/Kconfig linux-2.6.38.1-vs2.3.0.37-rc9/arch/alpha/Kconfig
160 --- linux-2.6.38.1/arch/alpha/Kconfig   2011-03-15 18:06:23.000000000 +0100
161 +++ linux-2.6.38.1-vs2.3.0.37-rc9/arch/alpha/Kconfig    2011-03-10 17:21:19.000000000 +0100
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-2.6.38.1/arch/alpha/kernel/entry.S linux-2.6.38.1-vs2.3.0.37-rc9/arch/alpha/kernel/entry.S
172 --- linux-2.6.38.1/arch/alpha/kernel/entry.S    2010-10-21 13:06:45.000000000 +0200
173 +++ linux-2.6.38.1-vs2.3.0.37-rc9/arch/alpha/kernel/entry.S     2011-01-29 02:01:07.000000000 +0100
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-2.6.38.1/arch/alpha/kernel/ptrace.c linux-2.6.38.1-vs2.3.0.37-rc9/arch/alpha/kernel/ptrace.c
207 --- linux-2.6.38.1/arch/alpha/kernel/ptrace.c   2011-01-05 21:48:40.000000000 +0100
208 +++ linux-2.6.38.1-vs2.3.0.37-rc9/arch/alpha/kernel/ptrace.c    2011-01-29 02:01:07.000000000 +0100
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-2.6.38.1/arch/alpha/kernel/systbls.S linux-2.6.38.1-vs2.3.0.37-rc9/arch/alpha/kernel/systbls.S
218 --- linux-2.6.38.1/arch/alpha/kernel/systbls.S  2010-10-21 13:06:46.000000000 +0200
219 +++ linux-2.6.38.1-vs2.3.0.37-rc9/arch/alpha/kernel/systbls.S   2011-01-29 02:01:07.000000000 +0100
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-2.6.38.1/arch/alpha/kernel/traps.c linux-2.6.38.1-vs2.3.0.37-rc9/arch/alpha/kernel/traps.c
230 --- linux-2.6.38.1/arch/alpha/kernel/traps.c    2010-10-21 13:06:46.000000000 +0200
231 +++ linux-2.6.38.1-vs2.3.0.37-rc9/arch/alpha/kernel/traps.c     2011-01-29 02:01:07.000000000 +0100
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-2.6.38.1/arch/arm/Kconfig linux-2.6.38.1-vs2.3.0.37-rc9/arch/arm/Kconfig
243 --- linux-2.6.38.1/arch/arm/Kconfig     2011-03-15 18:06:23.000000000 +0100
244 +++ linux-2.6.38.1-vs2.3.0.37-rc9/arch/arm/Kconfig      2011-03-07 16:53:25.000000000 +0100
245 @@ -1934,6 +1934,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-2.6.38.1/arch/arm/kernel/calls.S linux-2.6.38.1-vs2.3.0.37-rc9/arch/arm/kernel/calls.S
255 --- linux-2.6.38.1/arch/arm/kernel/calls.S      2010-10-21 13:06:46.000000000 +0200
256 +++ linux-2.6.38.1-vs2.3.0.37-rc9/arch/arm/kernel/calls.S       2011-01-29 02:01:07.000000000 +0100
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-2.6.38.1/arch/arm/kernel/process.c linux-2.6.38.1-vs2.3.0.37-rc9/arch/arm/kernel/process.c
267 --- linux-2.6.38.1/arch/arm/kernel/process.c    2011-03-15 18:06:25.000000000 +0100
268 +++ linux-2.6.38.1-vs2.3.0.37-rc9/arch/arm/kernel/process.c     2011-01-29 02:01:07.000000000 +0100
269 @@ -315,7 +315,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-2.6.38.1/arch/arm/kernel/traps.c linux-2.6.38.1-vs2.3.0.37-rc9/arch/arm/kernel/traps.c
280 --- linux-2.6.38.1/arch/arm/kernel/traps.c      2011-03-15 18:06:25.000000000 +0100
281 +++ linux-2.6.38.1-vs2.3.0.37-rc9/arch/arm/kernel/traps.c       2011-01-29 02:01:07.000000000 +0100
282 @@ -243,8 +243,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-2.6.38.1/arch/cris/Kconfig linux-2.6.38.1-vs2.3.0.37-rc9/arch/cris/Kconfig
294 --- linux-2.6.38.1/arch/cris/Kconfig    2011-03-15 18:06:38.000000000 +0100
295 +++ linux-2.6.38.1-vs2.3.0.37-rc9/arch/cris/Kconfig     2011-01-29 02:01:07.000000000 +0100
296 @@ -685,6 +685,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-2.6.38.1/arch/frv/kernel/kernel_thread.S linux-2.6.38.1-vs2.3.0.37-rc9/arch/frv/kernel/kernel_thread.S
306 --- linux-2.6.38.1/arch/frv/kernel/kernel_thread.S      2008-12-25 00:26:37.000000000 +0100
307 +++ linux-2.6.38.1-vs2.3.0.37-rc9/arch/frv/kernel/kernel_thread.S       2011-01-29 02:01:07.000000000 +0100
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-2.6.38.1/arch/h8300/Kconfig linux-2.6.38.1-vs2.3.0.37-rc9/arch/h8300/Kconfig
318 --- linux-2.6.38.1/arch/h8300/Kconfig   2011-03-15 18:06:38.000000000 +0100
319 +++ linux-2.6.38.1-vs2.3.0.37-rc9/arch/h8300/Kconfig    2011-01-29 02:01:07.000000000 +0100
320 @@ -217,6 +217,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-2.6.38.1/arch/ia64/Kconfig linux-2.6.38.1-vs2.3.0.37-rc9/arch/ia64/Kconfig
330 --- linux-2.6.38.1/arch/ia64/Kconfig    2011-03-15 18:06:38.000000000 +0100
331 +++ linux-2.6.38.1-vs2.3.0.37-rc9/arch/ia64/Kconfig     2011-01-29 02:01:07.000000000 +0100
332 @@ -674,6 +674,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-2.6.38.1/arch/ia64/include/asm/tlb.h linux-2.6.38.1-vs2.3.0.37-rc9/arch/ia64/include/asm/tlb.h
342 --- linux-2.6.38.1/arch/ia64/include/asm/tlb.h  2010-02-25 11:51:26.000000000 +0100
343 +++ linux-2.6.38.1-vs2.3.0.37-rc9/arch/ia64/include/asm/tlb.h   2011-01-29 02:01:07.000000000 +0100
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-2.6.38.1/arch/ia64/kernel/entry.S linux-2.6.38.1-vs2.3.0.37-rc9/arch/ia64/kernel/entry.S
353 --- linux-2.6.38.1/arch/ia64/kernel/entry.S     2010-10-21 13:06:52.000000000 +0200
354 +++ linux-2.6.38.1-vs2.3.0.37-rc9/arch/ia64/kernel/entry.S      2011-01-29 02:01:07.000000000 +0100
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-2.6.38.1/arch/ia64/kernel/perfmon.c linux-2.6.38.1-vs2.3.0.37-rc9/arch/ia64/kernel/perfmon.c
365 --- linux-2.6.38.1/arch/ia64/kernel/perfmon.c   2011-03-15 18:06:39.000000000 +0100
366 +++ linux-2.6.38.1-vs2.3.0.37-rc9/arch/ia64/kernel/perfmon.c    2011-01-29 02:01:07.000000000 +0100
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-2.6.38.1/arch/ia64/kernel/process.c linux-2.6.38.1-vs2.3.0.37-rc9/arch/ia64/kernel/process.c
376 --- linux-2.6.38.1/arch/ia64/kernel/process.c   2011-03-15 18:06:39.000000000 +0100
377 +++ linux-2.6.38.1-vs2.3.0.37-rc9/arch/ia64/kernel/process.c    2011-01-29 02:01:07.000000000 +0100
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-2.6.38.1/arch/ia64/kernel/ptrace.c linux-2.6.38.1-vs2.3.0.37-rc9/arch/ia64/kernel/ptrace.c
390 --- linux-2.6.38.1/arch/ia64/kernel/ptrace.c    2011-01-05 21:48:59.000000000 +0100
391 +++ linux-2.6.38.1-vs2.3.0.37-rc9/arch/ia64/kernel/ptrace.c     2011-01-29 02:01:07.000000000 +0100
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-2.6.38.1/arch/ia64/kernel/traps.c linux-2.6.38.1-vs2.3.0.37-rc9/arch/ia64/kernel/traps.c
401 --- linux-2.6.38.1/arch/ia64/kernel/traps.c     2010-07-07 18:31:01.000000000 +0200
402 +++ linux-2.6.38.1-vs2.3.0.37-rc9/arch/ia64/kernel/traps.c      2011-01-29 02:01:07.000000000 +0100
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-2.6.38.1/arch/ia64/mm/fault.c linux-2.6.38.1-vs2.3.0.37-rc9/arch/ia64/mm/fault.c
428 --- linux-2.6.38.1/arch/ia64/mm/fault.c 2010-08-02 16:52:04.000000000 +0200
429 +++ linux-2.6.38.1-vs2.3.0.37-rc9/arch/ia64/mm/fault.c  2011-01-29 02:01:07.000000000 +0100
430 @@ -10,6 +10,7 @@
431  #include <linux/interrupt.h>
432  #include <linux/kprobes.h>
433  #include <linux/kdebug.h>
434 +#include <linux/vs_memory.h>
435  
436  #include <asm/pgtable.h>
437  #include <asm/processor.h>
438 diff -NurpP --minimal linux-2.6.38.1/arch/m32r/kernel/traps.c linux-2.6.38.1-vs2.3.0.37-rc9/arch/m32r/kernel/traps.c
439 --- linux-2.6.38.1/arch/m32r/kernel/traps.c     2009-12-03 20:01:57.000000000 +0100
440 +++ linux-2.6.38.1-vs2.3.0.37-rc9/arch/m32r/kernel/traps.c      2011-01-29 02:01:07.000000000 +0100
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-2.6.38.1/arch/m68k/Kconfig linux-2.6.38.1-vs2.3.0.37-rc9/arch/m68k/Kconfig
454 --- linux-2.6.38.1/arch/m68k/Kconfig    2011-01-05 21:49:00.000000000 +0100
455 +++ linux-2.6.38.1-vs2.3.0.37-rc9/arch/m68k/Kconfig     2011-01-29 02:01:07.000000000 +0100
456 @@ -610,6 +610,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-2.6.38.1/arch/m68k/kernel/ptrace.c linux-2.6.38.1-vs2.3.0.37-rc9/arch/m68k/kernel/ptrace.c
466 --- linux-2.6.38.1/arch/m68k/kernel/ptrace.c    2011-01-05 21:49:01.000000000 +0100
467 +++ linux-2.6.38.1-vs2.3.0.37-rc9/arch/m68k/kernel/ptrace.c     2011-01-29 02:01:07.000000000 +0100
468 @@ -18,6 +18,7 @@
469  #include <linux/ptrace.h>
470  #include <linux/user.h>
471  #include <linux/signal.h>
472 +#include <linux/vs_base.h>
473  
474  #include <asm/uaccess.h>
475  #include <asm/page.h>
476 @@ -255,6 +256,8 @@ long arch_ptrace(struct task_struct *chi
477                 ret = ptrace_request(child, request, addr, data);
478                 break;
479         }
480 +       if (!vx_check(vx_task_xid(child), VS_WATCH_P | VS_IDENT))
481 +               goto out_tsk;
482  
483         return ret;
484  out_eio:
485 diff -NurpP --minimal linux-2.6.38.1/arch/m68k/kernel/traps.c linux-2.6.38.1-vs2.3.0.37-rc9/arch/m68k/kernel/traps.c
486 --- linux-2.6.38.1/arch/m68k/kernel/traps.c     2010-08-02 16:52:04.000000000 +0200
487 +++ linux-2.6.38.1-vs2.3.0.37-rc9/arch/m68k/kernel/traps.c      2011-01-29 02:01:07.000000000 +0100
488 @@ -906,8 +906,8 @@ void show_registers(struct pt_regs *regs
489         printk("d4: %08lx    d5: %08lx    a0: %08lx    a1: %08lx\n",
490                regs->d4, regs->d5, regs->a0, regs->a1);
491  
492 -       printk("Process %s (pid: %d, task=%p)\n",
493 -               current->comm, task_pid_nr(current), current);
494 +       printk("Process %s (pid: %d[#%u], task=%p)\n",
495 +               current->comm, task_pid_nr(current), current->xid, current);
496         addr = (unsigned long)&fp->un;
497         printk("Frame format=%X ", regs->format);
498         switch (regs->format) {
499 diff -NurpP --minimal linux-2.6.38.1/arch/m68knommu/Kconfig linux-2.6.38.1-vs2.3.0.37-rc9/arch/m68knommu/Kconfig
500 --- linux-2.6.38.1/arch/m68knommu/Kconfig       2011-03-15 18:06:41.000000000 +0100
501 +++ linux-2.6.38.1-vs2.3.0.37-rc9/arch/m68knommu/Kconfig        2011-01-29 02:01:07.000000000 +0100
502 @@ -801,6 +801,8 @@ source "fs/Kconfig"
503  
504  source "arch/m68knommu/Kconfig.debug"
505  
506 +source "kernel/vserver/Kconfig"
507 +
508  source "security/Kconfig"
509  
510  source "crypto/Kconfig"
511 diff -NurpP --minimal linux-2.6.38.1/arch/m68knommu/kernel/traps.c linux-2.6.38.1-vs2.3.0.37-rc9/arch/m68knommu/kernel/traps.c
512 --- linux-2.6.38.1/arch/m68knommu/kernel/traps.c        2011-01-05 21:49:01.000000000 +0100
513 +++ linux-2.6.38.1-vs2.3.0.37-rc9/arch/m68knommu/kernel/traps.c 2011-01-29 02:01:07.000000000 +0100
514 @@ -78,8 +78,9 @@ void die_if_kernel(char *str, struct pt_
515         printk(KERN_EMERG "d4: %08lx    d5: %08lx    a0: %08lx    a1: %08lx\n",
516                fp->d4, fp->d5, fp->a0, fp->a1);
517  
518 -       printk(KERN_EMERG "Process %s (pid: %d, stackpage=%08lx)\n",
519 -               current->comm, current->pid, PAGE_SIZE+(unsigned long)current);
520 +       printk(KERN_EMERG "Process %s (pid: %d[#%u], stackpage=%08lx)\n",
521 +               current->comm, task_pid_nr(current), current->xid,
522 +               PAGE_SIZE+(unsigned long)current);
523         show_stack(NULL, (unsigned long *)(fp + 1));
524         add_taint(TAINT_DIE);
525         do_exit(SIGSEGV);
526 diff -NurpP --minimal linux-2.6.38.1/arch/mips/Kconfig linux-2.6.38.1-vs2.3.0.37-rc9/arch/mips/Kconfig
527 --- linux-2.6.38.1/arch/mips/Kconfig    2011-03-15 18:06:42.000000000 +0100
528 +++ linux-2.6.38.1-vs2.3.0.37-rc9/arch/mips/Kconfig     2011-03-15 18:15:06.000000000 +0100
529 @@ -2418,6 +2418,8 @@ source "fs/Kconfig"
530  
531  source "arch/mips/Kconfig.debug"
532  
533 +source "kernel/vserver/Kconfig"
534 +
535  source "security/Kconfig"
536  
537  source "crypto/Kconfig"
538 diff -NurpP --minimal linux-2.6.38.1/arch/mips/kernel/ptrace.c linux-2.6.38.1-vs2.3.0.37-rc9/arch/mips/kernel/ptrace.c
539 --- linux-2.6.38.1/arch/mips/kernel/ptrace.c    2011-01-05 21:49:06.000000000 +0100
540 +++ linux-2.6.38.1-vs2.3.0.37-rc9/arch/mips/kernel/ptrace.c     2011-01-29 02:01:07.000000000 +0100
541 @@ -25,6 +25,7 @@
542  #include <linux/security.h>
543  #include <linux/audit.h>
544  #include <linux/seccomp.h>
545 +#include <linux/vs_base.h>
546  
547  #include <asm/byteorder.h>
548  #include <asm/cpu.h>
549 @@ -263,6 +264,9 @@ long arch_ptrace(struct task_struct *chi
550         void __user *datavp = (void __user *) data;
551         unsigned long __user *datalp = (void __user *) data;
552  
553 +       if (!vx_check(vx_task_xid(child), VS_WATCH_P | VS_IDENT))
554 +               goto out;
555 +
556         switch (request) {
557         /* when I and D space are separate, these will need to be fixed. */
558         case PTRACE_PEEKTEXT: /* read word at location addr. */
559 diff -NurpP --minimal linux-2.6.38.1/arch/mips/kernel/scall32-o32.S linux-2.6.38.1-vs2.3.0.37-rc9/arch/mips/kernel/scall32-o32.S
560 --- linux-2.6.38.1/arch/mips/kernel/scall32-o32.S       2010-10-21 13:06:54.000000000 +0200
561 +++ linux-2.6.38.1-vs2.3.0.37-rc9/arch/mips/kernel/scall32-o32.S        2011-01-29 02:01:07.000000000 +0100
562 @@ -524,7 +524,7 @@ einval:     li      v0, -ENOSYS
563         sys     sys_mq_timedreceive     5
564         sys     sys_mq_notify           2       /* 4275 */
565         sys     sys_mq_getsetattr       3
566 -       sys     sys_ni_syscall          0       /* sys_vserver */
567 +       sys     sys_vserver             3
568         sys     sys_waitid              5
569         sys     sys_ni_syscall          0       /* available, was setaltroot */
570         sys     sys_add_key             5       /* 4280 */
571 diff -NurpP --minimal linux-2.6.38.1/arch/mips/kernel/scall64-64.S linux-2.6.38.1-vs2.3.0.37-rc9/arch/mips/kernel/scall64-64.S
572 --- linux-2.6.38.1/arch/mips/kernel/scall64-64.S        2010-10-21 13:06:54.000000000 +0200
573 +++ linux-2.6.38.1-vs2.3.0.37-rc9/arch/mips/kernel/scall64-64.S 2011-01-29 02:01:07.000000000 +0100
574 @@ -363,7 +363,7 @@ sys_call_table:
575         PTR     sys_mq_timedreceive
576         PTR     sys_mq_notify
577         PTR     sys_mq_getsetattr               /* 5235 */
578 -       PTR     sys_ni_syscall                  /* sys_vserver */
579 +       PTR     sys_vserver
580         PTR     sys_waitid
581         PTR     sys_ni_syscall                  /* available, was setaltroot */
582         PTR     sys_add_key
583 diff -NurpP --minimal linux-2.6.38.1/arch/mips/kernel/scall64-n32.S linux-2.6.38.1-vs2.3.0.37-rc9/arch/mips/kernel/scall64-n32.S
584 --- linux-2.6.38.1/arch/mips/kernel/scall64-n32.S       2010-10-21 13:06:54.000000000 +0200
585 +++ linux-2.6.38.1-vs2.3.0.37-rc9/arch/mips/kernel/scall64-n32.S        2011-01-29 02:01:07.000000000 +0100
586 @@ -362,7 +362,7 @@ EXPORT(sysn32_call_table)
587         PTR     compat_sys_mq_timedreceive
588         PTR     compat_sys_mq_notify
589         PTR     compat_sys_mq_getsetattr
590 -       PTR     sys_ni_syscall                  /* 6240, sys_vserver */
591 +       PTR     sys32_vserver                   /* 6240 */
592         PTR     compat_sys_waitid
593         PTR     sys_ni_syscall                  /* available, was setaltroot */
594         PTR     sys_add_key
595 diff -NurpP --minimal linux-2.6.38.1/arch/mips/kernel/scall64-o32.S linux-2.6.38.1-vs2.3.0.37-rc9/arch/mips/kernel/scall64-o32.S
596 --- linux-2.6.38.1/arch/mips/kernel/scall64-o32.S       2010-10-21 13:06:54.000000000 +0200
597 +++ linux-2.6.38.1-vs2.3.0.37-rc9/arch/mips/kernel/scall64-o32.S        2011-01-29 02:01:07.000000000 +0100
598 @@ -481,7 +481,7 @@ sys_call_table:
599         PTR     compat_sys_mq_timedreceive
600         PTR     compat_sys_mq_notify            /* 4275 */
601         PTR     compat_sys_mq_getsetattr
602 -       PTR     sys_ni_syscall                  /* sys_vserver */
603 +       PTR     sys32_vserver
604         PTR     sys_32_waitid
605         PTR     sys_ni_syscall                  /* available, was setaltroot */
606         PTR     sys_add_key                     /* 4280 */
607 diff -NurpP --minimal linux-2.6.38.1/arch/mips/kernel/traps.c linux-2.6.38.1-vs2.3.0.37-rc9/arch/mips/kernel/traps.c
608 --- linux-2.6.38.1/arch/mips/kernel/traps.c     2011-03-15 18:06:42.000000000 +0100
609 +++ linux-2.6.38.1-vs2.3.0.37-rc9/arch/mips/kernel/traps.c      2011-01-29 02:01:07.000000000 +0100
610 @@ -343,9 +343,10 @@ void show_registers(struct pt_regs *regs
611  
612         __show_regs(regs);
613         print_modules();
614 -       printk("Process %s (pid: %d, threadinfo=%p, task=%p, tls=%0*lx)\n",
615 -              current->comm, current->pid, current_thread_info(), current,
616 -             field, current_thread_info()->tp_value);
617 +       printk("Process %s (pid: %d:#%u, threadinfo=%p, task=%p, tls=%0*lx)\n",
618 +               current->comm, task_pid_nr(current), current->xid,
619 +               current_thread_info(), current,
620 +               field, current_thread_info()->tp_value);
621         if (cpu_has_userlocal) {
622                 unsigned long tls;
623  
624 diff -NurpP --minimal linux-2.6.38.1/arch/parisc/Kconfig linux-2.6.38.1-vs2.3.0.37-rc9/arch/parisc/Kconfig
625 --- linux-2.6.38.1/arch/parisc/Kconfig  2011-03-15 18:06:43.000000000 +0100
626 +++ linux-2.6.38.1-vs2.3.0.37-rc9/arch/parisc/Kconfig   2011-01-29 02:01:07.000000000 +0100
627 @@ -283,6 +283,8 @@ source "fs/Kconfig"
628  
629  source "arch/parisc/Kconfig.debug"
630  
631 +source "kernel/vserver/Kconfig"
632 +
633  source "security/Kconfig"
634  
635  source "crypto/Kconfig"
636 diff -NurpP --minimal linux-2.6.38.1/arch/parisc/kernel/syscall_table.S linux-2.6.38.1-vs2.3.0.37-rc9/arch/parisc/kernel/syscall_table.S
637 --- linux-2.6.38.1/arch/parisc/kernel/syscall_table.S   2011-01-05 21:49:09.000000000 +0100
638 +++ linux-2.6.38.1-vs2.3.0.37-rc9/arch/parisc/kernel/syscall_table.S    2011-01-29 02:01:07.000000000 +0100
639 @@ -361,7 +361,7 @@
640         ENTRY_COMP(mbind)               /* 260 */
641         ENTRY_COMP(get_mempolicy)
642         ENTRY_COMP(set_mempolicy)
643 -       ENTRY_SAME(ni_syscall)  /* 263: reserved for vserver */
644 +       ENTRY_DIFF(vserver)
645         ENTRY_SAME(add_key)
646         ENTRY_SAME(request_key)         /* 265 */
647         ENTRY_SAME(keyctl)
648 diff -NurpP --minimal linux-2.6.38.1/arch/parisc/kernel/traps.c linux-2.6.38.1-vs2.3.0.37-rc9/arch/parisc/kernel/traps.c
649 --- linux-2.6.38.1/arch/parisc/kernel/traps.c   2009-09-10 15:25:40.000000000 +0200
650 +++ linux-2.6.38.1-vs2.3.0.37-rc9/arch/parisc/kernel/traps.c    2011-01-29 02:01:07.000000000 +0100
651 @@ -236,8 +236,9 @@ void die_if_kernel(char *str, struct pt_
652                 if (err == 0)
653                         return; /* STFU */
654  
655 -               printk(KERN_CRIT "%s (pid %d): %s (code %ld) at " RFMT "\n",
656 -                       current->comm, task_pid_nr(current), str, err, regs->iaoq[0]);
657 +               printk(KERN_CRIT "%s (pid %d:#%u): %s (code %ld) at " RFMT "\n",
658 +                       current->comm, task_pid_nr(current), current->xid,
659 +                       str, err, regs->iaoq[0]);
660  #ifdef PRINT_USER_FAULTS
661                 /* XXX for debugging only */
662                 show_regs(regs);
663 @@ -270,8 +271,8 @@ void die_if_kernel(char *str, struct pt_
664                 pdc_console_restart();
665         
666         if (err)
667 -               printk(KERN_CRIT "%s (pid %d): %s (code %ld)\n",
668 -                       current->comm, task_pid_nr(current), str, err);
669 +               printk(KERN_CRIT "%s (pid %d:#%u): %s (code %ld)\n",
670 +                       current->comm, task_pid_nr(current), current->xid, str, err);
671  
672         /* Wot's wrong wif bein' racy? */
673         if (current->thread.flags & PARISC_KERNEL_DEATH) {
674 diff -NurpP --minimal linux-2.6.38.1/arch/parisc/mm/fault.c linux-2.6.38.1-vs2.3.0.37-rc9/arch/parisc/mm/fault.c
675 --- linux-2.6.38.1/arch/parisc/mm/fault.c       2010-08-02 16:52:06.000000000 +0200
676 +++ linux-2.6.38.1-vs2.3.0.37-rc9/arch/parisc/mm/fault.c        2011-01-29 02:01:07.000000000 +0100
677 @@ -237,8 +237,9 @@ bad_area:
678  
679  #ifdef PRINT_USER_FAULTS
680                 printk(KERN_DEBUG "\n");
681 -               printk(KERN_DEBUG "do_page_fault() pid=%d command='%s' type=%lu address=0x%08lx\n",
682 -                   task_pid_nr(tsk), tsk->comm, code, address);
683 +               printk(KERN_DEBUG "do_page_fault() pid=%d:#%u "
684 +                   "command='%s' type=%lu address=0x%08lx\n",
685 +                   task_pid_nr(tsk), tsk->xid, tsk->comm, code, address);
686                 if (vma) {
687                         printk(KERN_DEBUG "vm_start = 0x%08lx, vm_end = 0x%08lx\n",
688                                         vma->vm_start, vma->vm_end);
689 diff -NurpP --minimal linux-2.6.38.1/arch/powerpc/Kconfig linux-2.6.38.1-vs2.3.0.37-rc9/arch/powerpc/Kconfig
690 --- linux-2.6.38.1/arch/powerpc/Kconfig 2011-03-15 18:06:43.000000000 +0100
691 +++ linux-2.6.38.1-vs2.3.0.37-rc9/arch/powerpc/Kconfig  2011-01-29 02:01:07.000000000 +0100
692 @@ -964,6 +964,8 @@ source "lib/Kconfig"
693  
694  source "arch/powerpc/Kconfig.debug"
695  
696 +source "kernel/vserver/Kconfig"
697 +
698  source "security/Kconfig"
699  
700  config KEYS_COMPAT
701 diff -NurpP --minimal linux-2.6.38.1/arch/powerpc/include/asm/unistd.h linux-2.6.38.1-vs2.3.0.37-rc9/arch/powerpc/include/asm/unistd.h
702 --- linux-2.6.38.1/arch/powerpc/include/asm/unistd.h    2011-01-05 21:49:10.000000000 +0100
703 +++ linux-2.6.38.1-vs2.3.0.37-rc9/arch/powerpc/include/asm/unistd.h     2011-01-29 02:01:07.000000000 +0100
704 @@ -275,7 +275,7 @@
705  #endif
706  #define __NR_rtas              255
707  #define __NR_sys_debug_setcontext 256
708 -/* Number 257 is reserved for vserver */
709 +#define __NR_vserver           257
710  #define __NR_migrate_pages     258
711  #define __NR_mbind             259
712  #define __NR_get_mempolicy     260
713 diff -NurpP --minimal linux-2.6.38.1/arch/powerpc/kernel/process.c linux-2.6.38.1-vs2.3.0.37-rc9/arch/powerpc/kernel/process.c
714 --- linux-2.6.38.1/arch/powerpc/kernel/process.c        2011-03-15 18:06:44.000000000 +0100
715 +++ linux-2.6.38.1-vs2.3.0.37-rc9/arch/powerpc/kernel/process.c 2011-03-10 17:21:19.000000000 +0100
716 @@ -635,8 +635,9 @@ void show_regs(struct pt_regs * regs)
717  #else
718                 printk("DAR: "REG", DSISR: %08lx\n", regs->dar, regs->dsisr);
719  #endif
720 -       printk("TASK = %p[%d] '%s' THREAD: %p",
721 -              current, task_pid_nr(current), current->comm, task_thread_info(current));
722 +       printk("TASK = %p[%d,#%u] '%s' THREAD: %p",
723 +              current, task_pid_nr(current), current->xid,
724 +              current->comm, task_thread_info(current));
725  
726  #ifdef CONFIG_SMP
727         printk(" CPU: %d", raw_smp_processor_id());
728 diff -NurpP --minimal linux-2.6.38.1/arch/powerpc/kernel/traps.c linux-2.6.38.1-vs2.3.0.37-rc9/arch/powerpc/kernel/traps.c
729 --- linux-2.6.38.1/arch/powerpc/kernel/traps.c  2011-03-15 18:06:44.000000000 +0100
730 +++ linux-2.6.38.1-vs2.3.0.37-rc9/arch/powerpc/kernel/traps.c   2011-01-29 02:01:07.000000000 +0100
731 @@ -1043,8 +1043,9 @@ void nonrecoverable_exception(struct pt_
732  
733  void trace_syscall(struct pt_regs *regs)
734  {
735 -       printk("Task: %p(%d), PC: %08lX/%08lX, Syscall: %3ld, Result: %s%ld    %s\n",
736 -              current, task_pid_nr(current), regs->nip, regs->link, regs->gpr[0],
737 +       printk("Task: %p(%d[#%u]), PC: %08lX/%08lX, Syscall: %3ld, Result: %s%ld    %s\n",
738 +              current, task_pid_nr(current), current->xid,
739 +              regs->nip, regs->link, regs->gpr[0],
740                regs->ccr&0x10000000?"Error=":"", regs->gpr[3], print_tainted());
741  }
742  
743 diff -NurpP --minimal linux-2.6.38.1/arch/powerpc/kernel/vdso.c linux-2.6.38.1-vs2.3.0.37-rc9/arch/powerpc/kernel/vdso.c
744 --- linux-2.6.38.1/arch/powerpc/kernel/vdso.c   2011-01-05 21:49:11.000000000 +0100
745 +++ linux-2.6.38.1-vs2.3.0.37-rc9/arch/powerpc/kernel/vdso.c    2011-01-29 02:01:07.000000000 +0100
746 @@ -23,6 +23,7 @@
747  #include <linux/security.h>
748  #include <linux/bootmem.h>
749  #include <linux/memblock.h>
750 +#include <linux/vs_memory.h>
751  
752  #include <asm/pgtable.h>
753  #include <asm/system.h>
754 diff -NurpP --minimal linux-2.6.38.1/arch/s390/Kconfig linux-2.6.38.1-vs2.3.0.37-rc9/arch/s390/Kconfig
755 --- linux-2.6.38.1/arch/s390/Kconfig    2011-03-15 18:06:45.000000000 +0100
756 +++ linux-2.6.38.1-vs2.3.0.37-rc9/arch/s390/Kconfig     2011-02-17 02:17:45.000000000 +0100
757 @@ -645,6 +645,8 @@ source "fs/Kconfig"
758  
759  source "arch/s390/Kconfig.debug"
760  
761 +source "kernel/vserver/Kconfig"
762 +
763  source "security/Kconfig"
764  
765  source "crypto/Kconfig"
766 diff -NurpP --minimal linux-2.6.38.1/arch/s390/include/asm/tlb.h linux-2.6.38.1-vs2.3.0.37-rc9/arch/s390/include/asm/tlb.h
767 --- linux-2.6.38.1/arch/s390/include/asm/tlb.h  2011-03-15 18:06:45.000000000 +0100
768 +++ linux-2.6.38.1-vs2.3.0.37-rc9/arch/s390/include/asm/tlb.h   2011-02-17 02:17:45.000000000 +0100
769 @@ -24,6 +24,8 @@
770  #include <linux/mm.h>
771  #include <linux/pagemap.h>
772  #include <linux/swap.h>
773 +#include <linux/vs_memory.h>
774 +
775  #include <asm/processor.h>
776  #include <asm/pgalloc.h>
777  #include <asm/smp.h>
778 diff -NurpP --minimal linux-2.6.38.1/arch/s390/include/asm/unistd.h linux-2.6.38.1-vs2.3.0.37-rc9/arch/s390/include/asm/unistd.h
779 --- linux-2.6.38.1/arch/s390/include/asm/unistd.h       2010-10-21 13:06:58.000000000 +0200
780 +++ linux-2.6.38.1-vs2.3.0.37-rc9/arch/s390/include/asm/unistd.h        2011-01-29 02:01:07.000000000 +0100
781 @@ -202,7 +202,7 @@
782  #define __NR_clock_gettime     (__NR_timer_create+6)
783  #define __NR_clock_getres      (__NR_timer_create+7)
784  #define __NR_clock_nanosleep   (__NR_timer_create+8)
785 -/* Number 263 is reserved for vserver */
786 +#define __NR_vserver           263
787  #define __NR_statfs64          265
788  #define __NR_fstatfs64         266
789  #define __NR_remap_file_pages  267
790 diff -NurpP --minimal linux-2.6.38.1/arch/s390/kernel/ptrace.c linux-2.6.38.1-vs2.3.0.37-rc9/arch/s390/kernel/ptrace.c
791 --- linux-2.6.38.1/arch/s390/kernel/ptrace.c    2011-03-15 18:06:45.000000000 +0100
792 +++ linux-2.6.38.1-vs2.3.0.37-rc9/arch/s390/kernel/ptrace.c     2011-01-29 02:01:07.000000000 +0100
793 @@ -20,6 +20,7 @@
794  #include <linux/regset.h>
795  #include <linux/tracehook.h>
796  #include <linux/seccomp.h>
797 +#include <linux/vs_base.h>
798  #include <trace/syscall.h>
799  #include <asm/compat.h>
800  #include <asm/segment.h>
801 diff -NurpP --minimal linux-2.6.38.1/arch/s390/kernel/syscalls.S linux-2.6.38.1-vs2.3.0.37-rc9/arch/s390/kernel/syscalls.S
802 --- linux-2.6.38.1/arch/s390/kernel/syscalls.S  2010-10-21 13:06:58.000000000 +0200
803 +++ linux-2.6.38.1-vs2.3.0.37-rc9/arch/s390/kernel/syscalls.S   2011-01-29 02:01:07.000000000 +0100
804 @@ -271,7 +271,7 @@ SYSCALL(sys_clock_settime,sys_clock_sett
805  SYSCALL(sys_clock_gettime,sys_clock_gettime,sys32_clock_gettime_wrapper)       /* 260 */
806  SYSCALL(sys_clock_getres,sys_clock_getres,sys32_clock_getres_wrapper)
807  SYSCALL(sys_clock_nanosleep,sys_clock_nanosleep,sys32_clock_nanosleep_wrapper)
808 -NI_SYSCALL                                                     /* reserved for vserver */
809 +SYSCALL(sys_vserver,sys_vserver,sys32_vserver)
810  SYSCALL(sys_s390_fadvise64_64,sys_ni_syscall,sys32_fadvise64_64_wrapper)
811  SYSCALL(sys_statfs64,sys_statfs64,compat_sys_statfs64_wrapper)
812  SYSCALL(sys_fstatfs64,sys_fstatfs64,compat_sys_fstatfs64_wrapper)
813 diff -NurpP --minimal linux-2.6.38.1/arch/sh/Kconfig linux-2.6.38.1-vs2.3.0.37-rc9/arch/sh/Kconfig
814 --- linux-2.6.38.1/arch/sh/Kconfig      2011-03-15 18:06:46.000000000 +0100
815 +++ linux-2.6.38.1-vs2.3.0.37-rc9/arch/sh/Kconfig       2011-02-02 22:20:22.000000000 +0100
816 @@ -889,6 +889,8 @@ source "fs/Kconfig"
817  
818  source "arch/sh/Kconfig.debug"
819  
820 +source "kernel/vserver/Kconfig"
821 +
822  source "security/Kconfig"
823  
824  source "crypto/Kconfig"
825 diff -NurpP --minimal linux-2.6.38.1/arch/sh/kernel/irq.c linux-2.6.38.1-vs2.3.0.37-rc9/arch/sh/kernel/irq.c
826 --- linux-2.6.38.1/arch/sh/kernel/irq.c 2011-01-05 21:49:16.000000000 +0100
827 +++ linux-2.6.38.1-vs2.3.0.37-rc9/arch/sh/kernel/irq.c  2011-01-29 02:01:07.000000000 +0100
828 @@ -13,6 +13,7 @@
829  #include <linux/seq_file.h>
830  #include <linux/ftrace.h>
831  #include <linux/delay.h>
832 +// #include <linux/vs_context.h>
833  #include <asm/processor.h>
834  #include <asm/machvec.h>
835  #include <asm/uaccess.h>
836 diff -NurpP --minimal linux-2.6.38.1/arch/sh/kernel/vsyscall/vsyscall.c linux-2.6.38.1-vs2.3.0.37-rc9/arch/sh/kernel/vsyscall/vsyscall.c
837 --- linux-2.6.38.1/arch/sh/kernel/vsyscall/vsyscall.c   2010-07-07 18:31:10.000000000 +0200
838 +++ linux-2.6.38.1-vs2.3.0.37-rc9/arch/sh/kernel/vsyscall/vsyscall.c    2011-01-29 02:01:07.000000000 +0100
839 @@ -18,6 +18,7 @@
840  #include <linux/elf.h>
841  #include <linux/sched.h>
842  #include <linux/err.h>
843 +#include <linux/vs_memory.h>
844  
845  /*
846   * Should the kernel map a VDSO page into processes and pass its
847 diff -NurpP --minimal linux-2.6.38.1/arch/sparc/Kconfig linux-2.6.38.1-vs2.3.0.37-rc9/arch/sparc/Kconfig
848 --- linux-2.6.38.1/arch/sparc/Kconfig   2011-03-15 18:06:47.000000000 +0100
849 +++ linux-2.6.38.1-vs2.3.0.37-rc9/arch/sparc/Kconfig    2011-01-29 02:01:07.000000000 +0100
850 @@ -553,6 +553,8 @@ source "fs/Kconfig"
851  
852  source "arch/sparc/Kconfig.debug"
853  
854 +source "kernel/vserver/Kconfig"
855 +
856  source "security/Kconfig"
857  
858  source "crypto/Kconfig"
859 diff -NurpP --minimal linux-2.6.38.1/arch/sparc/include/asm/tlb_64.h linux-2.6.38.1-vs2.3.0.37-rc9/arch/sparc/include/asm/tlb_64.h
860 --- linux-2.6.38.1/arch/sparc/include/asm/tlb_64.h      2009-09-10 15:25:45.000000000 +0200
861 +++ linux-2.6.38.1-vs2.3.0.37-rc9/arch/sparc/include/asm/tlb_64.h       2011-01-29 02:01:07.000000000 +0100
862 @@ -3,6 +3,7 @@
863  
864  #include <linux/swap.h>
865  #include <linux/pagemap.h>
866 +#include <linux/vs_memory.h>
867  #include <asm/pgalloc.h>
868  #include <asm/tlbflush.h>
869  #include <asm/mmu_context.h>
870 diff -NurpP --minimal linux-2.6.38.1/arch/sparc/include/asm/unistd.h linux-2.6.38.1-vs2.3.0.37-rc9/arch/sparc/include/asm/unistd.h
871 --- linux-2.6.38.1/arch/sparc/include/asm/unistd.h      2010-10-21 13:06:58.000000000 +0200
872 +++ linux-2.6.38.1-vs2.3.0.37-rc9/arch/sparc/include/asm/unistd.h       2011-01-29 02:01:07.000000000 +0100
873 @@ -335,7 +335,7 @@
874  #define __NR_timer_getoverrun  264
875  #define __NR_timer_delete      265
876  #define __NR_timer_create      266
877 -/* #define __NR_vserver                267 Reserved for VSERVER */
878 +#define __NR_vserver           267
879  #define __NR_io_setup          268
880  #define __NR_io_destroy                269
881  #define __NR_io_submit         270
882 diff -NurpP --minimal linux-2.6.38.1/arch/sparc/kernel/systbls_32.S linux-2.6.38.1-vs2.3.0.37-rc9/arch/sparc/kernel/systbls_32.S
883 --- linux-2.6.38.1/arch/sparc/kernel/systbls_32.S       2010-10-21 13:06:59.000000000 +0200
884 +++ linux-2.6.38.1-vs2.3.0.37-rc9/arch/sparc/kernel/systbls_32.S        2011-01-29 02:01:07.000000000 +0100
885 @@ -70,7 +70,7 @@ sys_call_table:
886  /*250*/        .long sys_mremap, sys_sysctl, sys_getsid, sys_fdatasync, sys_nfsservctl
887  /*255*/        .long sys_sync_file_range, sys_clock_settime, sys_clock_gettime, sys_clock_getres, sys_clock_nanosleep
888  /*260*/        .long sys_sched_getaffinity, sys_sched_setaffinity, sys_timer_settime, sys_timer_gettime, sys_timer_getoverrun
889 -/*265*/        .long sys_timer_delete, sys_timer_create, sys_nis_syscall, sys_io_setup, sys_io_destroy
890 +/*265*/        .long sys_timer_delete, sys_timer_create, sys_vserver, sys_io_setup, sys_io_destroy
891  /*270*/        .long sys_io_submit, sys_io_cancel, sys_io_getevents, sys_mq_open, sys_mq_unlink
892  /*275*/        .long sys_mq_timedsend, sys_mq_timedreceive, sys_mq_notify, sys_mq_getsetattr, sys_waitid
893  /*280*/        .long sys_tee, sys_add_key, sys_request_key, sys_keyctl, sys_openat
894 diff -NurpP --minimal linux-2.6.38.1/arch/sparc/kernel/systbls_64.S linux-2.6.38.1-vs2.3.0.37-rc9/arch/sparc/kernel/systbls_64.S
895 --- linux-2.6.38.1/arch/sparc/kernel/systbls_64.S       2010-10-21 13:06:59.000000000 +0200
896 +++ linux-2.6.38.1-vs2.3.0.37-rc9/arch/sparc/kernel/systbls_64.S        2011-01-29 02:01:07.000000000 +0100
897 @@ -71,7 +71,7 @@ sys_call_table32:
898  /*250*/        .word sys_mremap, compat_sys_sysctl, sys32_getsid, sys_fdatasync, sys32_nfsservctl
899         .word sys32_sync_file_range, compat_sys_clock_settime, compat_sys_clock_gettime, compat_sys_clock_getres, sys32_clock_nanosleep
900  /*260*/        .word compat_sys_sched_getaffinity, compat_sys_sched_setaffinity, sys32_timer_settime, compat_sys_timer_gettime, sys_timer_getoverrun
901 -       .word sys_timer_delete, compat_sys_timer_create, sys_ni_syscall, compat_sys_io_setup, sys_io_destroy
902 +       .word sys_timer_delete, compat_sys_timer_create, sys32_vserver, compat_sys_io_setup, sys_io_destroy
903  /*270*/        .word sys32_io_submit, sys_io_cancel, compat_sys_io_getevents, sys32_mq_open, sys_mq_unlink
904         .word compat_sys_mq_timedsend, compat_sys_mq_timedreceive, compat_sys_mq_notify, compat_sys_mq_getsetattr, compat_sys_waitid
905  /*280*/        .word sys32_tee, sys_add_key, sys_request_key, sys_keyctl, compat_sys_openat
906 @@ -147,7 +147,7 @@ sys_call_table:
907  /*250*/        .word sys_64_mremap, sys_sysctl, sys_getsid, sys_fdatasync, sys_nfsservctl
908         .word sys_sync_file_range, sys_clock_settime, sys_clock_gettime, sys_clock_getres, sys_clock_nanosleep
909  /*260*/        .word sys_sched_getaffinity, sys_sched_setaffinity, sys_timer_settime, sys_timer_gettime, sys_timer_getoverrun
910 -       .word sys_timer_delete, sys_timer_create, sys_ni_syscall, sys_io_setup, sys_io_destroy
911 +       .word sys_timer_delete, sys_timer_create, sys_vserver, sys_io_setup, sys_io_destroy
912  /*270*/        .word sys_io_submit, sys_io_cancel, sys_io_getevents, sys_mq_open, sys_mq_unlink
913         .word sys_mq_timedsend, sys_mq_timedreceive, sys_mq_notify, sys_mq_getsetattr, sys_waitid
914  /*280*/        .word sys_tee, sys_add_key, sys_request_key, sys_keyctl, sys_openat
915 diff -NurpP --minimal linux-2.6.38.1/arch/um/Kconfig.rest linux-2.6.38.1-vs2.3.0.37-rc9/arch/um/Kconfig.rest
916 --- linux-2.6.38.1/arch/um/Kconfig.rest 2009-06-11 17:12:19.000000000 +0200
917 +++ linux-2.6.38.1-vs2.3.0.37-rc9/arch/um/Kconfig.rest  2011-01-29 02:01:07.000000000 +0100
918 @@ -18,6 +18,8 @@ source "drivers/connector/Kconfig"
919  
920  source "fs/Kconfig"
921  
922 +source "kernel/vserver/Kconfig"
923 +
924  source "security/Kconfig"
925  
926  source "crypto/Kconfig"
927 diff -NurpP --minimal linux-2.6.38.1/arch/um/include/asm/tlb.h linux-2.6.38.1-vs2.3.0.37-rc9/arch/um/include/asm/tlb.h
928 --- linux-2.6.38.1/arch/um/include/asm/tlb.h    2009-09-10 15:25:46.000000000 +0200
929 +++ linux-2.6.38.1-vs2.3.0.37-rc9/arch/um/include/asm/tlb.h     2011-01-29 02:01:07.000000000 +0100
930 @@ -3,6 +3,7 @@
931  
932  #include <linux/pagemap.h>
933  #include <linux/swap.h>
934 +#include <linux/vs_memory.h>
935  #include <asm/percpu.h>
936  #include <asm/pgalloc.h>
937  #include <asm/tlbflush.h>
938 diff -NurpP --minimal linux-2.6.38.1/arch/um/include/shared/kern_constants.h linux-2.6.38.1-vs2.3.0.37-rc9/arch/um/include/shared/kern_constants.h
939 --- linux-2.6.38.1/arch/um/include/shared/kern_constants.h      1970-01-01 01:00:00.000000000 +0100
940 +++ linux-2.6.38.1-vs2.3.0.37-rc9/arch/um/include/shared/kern_constants.h       2011-01-29 02:01:07.000000000 +0100
941 @@ -0,0 +1 @@
942 +#include "../../../../include/generated/asm-offsets.h"
943 diff -NurpP --minimal linux-2.6.38.1/arch/um/include/shared/user_constants.h linux-2.6.38.1-vs2.3.0.37-rc9/arch/um/include/shared/user_constants.h
944 --- linux-2.6.38.1/arch/um/include/shared/user_constants.h      1970-01-01 01:00:00.000000000 +0100
945 +++ linux-2.6.38.1-vs2.3.0.37-rc9/arch/um/include/shared/user_constants.h       2011-01-29 02:01:07.000000000 +0100
946 @@ -0,0 +1,40 @@
947 +/*
948 + * DO NOT MODIFY.
949 + *
950 + * This file was generated by arch/um/Makefile
951 + *
952 + */
953 +
954 +#define HOST_SC_CR2 176 /* offsetof(struct sigcontext, cr2)    # */
955 +#define HOST_SC_ERR 152 /* offsetof(struct sigcontext, err)    # */
956 +#define HOST_SC_TRAPNO 160 /* offsetof(struct sigcontext, trapno)      # */
957 +#define HOST_FP_SIZE 64 /* sizeof(struct _fpstate) / sizeof(unsigned long)     # */
958 +#define HOST_RBX 5 /* RBX      # */
959 +#define HOST_RCX 11 /* RCX     # */
960 +#define HOST_RDI 14 /* RDI     # */
961 +#define HOST_RSI 13 /* RSI     # */
962 +#define HOST_RDX 12 /* RDX     # */
963 +#define HOST_RBP 4 /* RBP      # */
964 +#define HOST_RAX 10 /* RAX     # */
965 +#define HOST_R8 9 /* R8        # */
966 +#define HOST_R9 8 /* R9        # */
967 +#define HOST_R10 7 /* R10      # */
968 +#define HOST_R11 6 /* R11      # */
969 +#define HOST_R12 3 /* R12      # */
970 +#define HOST_R13 2 /* R13      # */
971 +#define HOST_R14 1 /* R14      # */
972 +#define HOST_R15 0 /* R15      # */
973 +#define HOST_ORIG_RAX 15 /* ORIG_RAX   # */
974 +#define HOST_CS 17 /* CS       # */
975 +#define HOST_SS 20 /* SS       # */
976 +#define HOST_EFLAGS 18 /* EFLAGS       # */
977 +#define HOST_IP 16 /* RIP      # */
978 +#define HOST_SP 19 /* RSP      # */
979 +#define UM_FRAME_SIZE 216 /* sizeof(struct user_regs_struct)   # */
980 +#define UM_POLLIN 1 /* POLLIN  # */
981 +#define UM_POLLPRI 2 /* POLLPRI        # */
982 +#define UM_POLLOUT 4 /* POLLOUT        # */
983 +#define UM_PROT_READ 1 /* PROT_READ    # */
984 +#define UM_PROT_WRITE 2 /* PROT_WRITE  # */
985 +#define UM_PROT_EXEC 4 /* PROT_EXEC    # */
986 +
987 diff -NurpP --minimal linux-2.6.38.1/arch/x86/Kconfig linux-2.6.38.1-vs2.3.0.37-rc9/arch/x86/Kconfig
988 --- linux-2.6.38.1/arch/x86/Kconfig     2011-03-15 18:06:48.000000000 +0100
989 +++ linux-2.6.38.1-vs2.3.0.37-rc9/arch/x86/Kconfig      2011-01-29 02:01:07.000000000 +0100
990 @@ -2159,6 +2159,8 @@ source "fs/Kconfig"
991  
992  source "arch/x86/Kconfig.debug"
993  
994 +source "kernel/vserver/Kconfig"
995 +
996  source "security/Kconfig"
997  
998  source "crypto/Kconfig"
999 diff -NurpP --minimal linux-2.6.38.1/arch/x86/ia32/ia32entry.S linux-2.6.38.1-vs2.3.0.37-rc9/arch/x86/ia32/ia32entry.S
1000 --- linux-2.6.38.1/arch/x86/ia32/ia32entry.S    2010-10-21 13:06:59.000000000 +0200
1001 +++ linux-2.6.38.1-vs2.3.0.37-rc9/arch/x86/ia32/ia32entry.S     2011-01-29 02:01:07.000000000 +0100
1002 @@ -783,7 +783,7 @@ ia32_sys_call_table:
1003         .quad sys_tgkill                /* 270 */
1004         .quad compat_sys_utimes
1005         .quad sys32_fadvise64_64
1006 -       .quad quiet_ni_syscall  /* sys_vserver */
1007 +       .quad sys32_vserver
1008         .quad sys_mbind
1009         .quad compat_sys_get_mempolicy  /* 275 */
1010         .quad sys_set_mempolicy
1011 diff -NurpP --minimal linux-2.6.38.1/arch/x86/include/asm/unistd_64.h linux-2.6.38.1-vs2.3.0.37-rc9/arch/x86/include/asm/unistd_64.h
1012 --- linux-2.6.38.1/arch/x86/include/asm/unistd_64.h     2010-10-21 13:06:59.000000000 +0200
1013 +++ linux-2.6.38.1-vs2.3.0.37-rc9/arch/x86/include/asm/unistd_64.h      2011-01-29 02:01:07.000000000 +0100
1014 @@ -535,7 +535,7 @@ __SYSCALL(__NR_tgkill, sys_tgkill)
1015  #define __NR_utimes                            235
1016  __SYSCALL(__NR_utimes, sys_utimes)
1017  #define __NR_vserver                           236
1018 -__SYSCALL(__NR_vserver, sys_ni_syscall)
1019 +__SYSCALL(__NR_vserver, sys_vserver)
1020  #define __NR_mbind                             237
1021  __SYSCALL(__NR_mbind, sys_mbind)
1022  #define __NR_set_mempolicy                     238
1023 diff -NurpP --minimal linux-2.6.38.1/arch/x86/kernel/syscall_table_32.S linux-2.6.38.1-vs2.3.0.37-rc9/arch/x86/kernel/syscall_table_32.S
1024 --- linux-2.6.38.1/arch/x86/kernel/syscall_table_32.S   2010-10-21 13:07:00.000000000 +0200
1025 +++ linux-2.6.38.1-vs2.3.0.37-rc9/arch/x86/kernel/syscall_table_32.S    2011-01-29 02:01:07.000000000 +0100
1026 @@ -272,7 +272,7 @@ ENTRY(sys_call_table)
1027         .long sys_tgkill        /* 270 */
1028         .long sys_utimes
1029         .long sys_fadvise64_64
1030 -       .long sys_ni_syscall    /* sys_vserver */
1031 +       .long sys_vserver
1032         .long sys_mbind
1033         .long sys_get_mempolicy
1034         .long sys_set_mempolicy
1035 diff -NurpP --minimal linux-2.6.38.1/drivers/block/Kconfig linux-2.6.38.1-vs2.3.0.37-rc9/drivers/block/Kconfig
1036 --- linux-2.6.38.1/drivers/block/Kconfig        2011-03-15 18:06:54.000000000 +0100
1037 +++ linux-2.6.38.1-vs2.3.0.37-rc9/drivers/block/Kconfig 2011-01-29 02:01:07.000000000 +0100
1038 @@ -273,6 +273,13 @@ config BLK_DEV_CRYPTOLOOP
1039  
1040  source "drivers/block/drbd/Kconfig"
1041  
1042 +config BLK_DEV_VROOT
1043 +       tristate "Virtual Root device support"
1044 +       depends on QUOTACTL
1045 +       ---help---
1046 +         Saying Y here will allow you to use quota/fs ioctls on a shared
1047 +         partition within a virtual server without compromising security.
1048 +
1049  config BLK_DEV_NBD
1050         tristate "Network block device support"
1051         depends on NET
1052 diff -NurpP --minimal linux-2.6.38.1/drivers/block/Makefile linux-2.6.38.1-vs2.3.0.37-rc9/drivers/block/Makefile
1053 --- linux-2.6.38.1/drivers/block/Makefile       2011-03-15 18:06:54.000000000 +0100
1054 +++ linux-2.6.38.1-vs2.3.0.37-rc9/drivers/block/Makefile        2011-02-17 02:17:45.000000000 +0100
1055 @@ -34,6 +34,7 @@ obj-$(CONFIG_VIODASD)         += viodasd.o
1056  obj-$(CONFIG_BLK_DEV_SX8)      += sx8.o
1057  obj-$(CONFIG_BLK_DEV_UB)       += ub.o
1058  obj-$(CONFIG_BLK_DEV_HD)       += hd.o
1059 +obj-$(CONFIG_BLK_DEV_VROOT)    += vroot.o
1060  
1061  obj-$(CONFIG_XEN_BLKDEV_FRONTEND)      += xen-blkfront.o
1062  obj-$(CONFIG_BLK_DEV_DRBD)     += drbd/
1063 diff -NurpP --minimal linux-2.6.38.1/drivers/block/loop.c linux-2.6.38.1-vs2.3.0.37-rc9/drivers/block/loop.c
1064 --- linux-2.6.38.1/drivers/block/loop.c 2011-03-15 18:06:54.000000000 +0100
1065 +++ linux-2.6.38.1-vs2.3.0.37-rc9/drivers/block/loop.c  2011-03-10 17:21:19.000000000 +0100
1066 @@ -75,6 +75,7 @@
1067  #include <linux/kthread.h>
1068  #include <linux/splice.h>
1069  #include <linux/sysfs.h>
1070 +#include <linux/vs_context.h>
1071  
1072  #include <asm/uaccess.h>
1073  
1074 @@ -902,6 +903,7 @@ static int loop_set_fd(struct loop_devic
1075         lo->lo_blocksize = lo_blocksize;
1076         lo->lo_device = bdev;
1077         lo->lo_flags = lo_flags;
1078 +       lo->lo_xid = vx_current_xid();
1079         lo->lo_backing_file = file;
1080         lo->transfer = transfer_none;
1081         lo->ioctl = NULL;
1082 @@ -1032,6 +1034,7 @@ static int loop_clr_fd(struct loop_devic
1083         lo->lo_encrypt_key_size = 0;
1084         lo->lo_flags = 0;
1085         lo->lo_thread = NULL;
1086 +       lo->lo_xid = 0;
1087         memset(lo->lo_encrypt_key, 0, LO_KEY_SIZE);
1088         memset(lo->lo_crypt_name, 0, LO_NAME_SIZE);
1089         memset(lo->lo_file_name, 0, LO_NAME_SIZE);
1090 @@ -1070,7 +1073,7 @@ loop_set_status(struct loop_device *lo, 
1091  
1092         if (lo->lo_encrypt_key_size &&
1093             lo->lo_key_owner != uid &&
1094 -           !capable(CAP_SYS_ADMIN))
1095 +           !vx_capable(CAP_SYS_ADMIN, VXC_ADMIN_CLOOP))
1096                 return -EPERM;
1097         if (lo->lo_state != Lo_bound)
1098                 return -ENXIO;
1099 @@ -1154,7 +1157,8 @@ loop_get_status(struct loop_device *lo, 
1100         memcpy(info->lo_crypt_name, lo->lo_crypt_name, LO_NAME_SIZE);
1101         info->lo_encrypt_type =
1102                 lo->lo_encryption ? lo->lo_encryption->number : 0;
1103 -       if (lo->lo_encrypt_key_size && capable(CAP_SYS_ADMIN)) {
1104 +       if (lo->lo_encrypt_key_size &&
1105 +               vx_capable(CAP_SYS_ADMIN, VXC_ADMIN_CLOOP)) {
1106                 info->lo_encrypt_key_size = lo->lo_encrypt_key_size;
1107                 memcpy(info->lo_encrypt_key, lo->lo_encrypt_key,
1108                        lo->lo_encrypt_key_size);
1109 @@ -1500,6 +1504,9 @@ static int lo_open(struct block_device *
1110  {
1111         struct loop_device *lo = bdev->bd_disk->private_data;
1112  
1113 +       if (!vx_check(lo->lo_xid, VS_IDENT|VS_HOSTID|VS_ADMIN_P))
1114 +               return -EACCES;
1115 +
1116         mutex_lock(&lo->lo_ctl_mutex);
1117         lo->lo_refcnt++;
1118         mutex_unlock(&lo->lo_ctl_mutex);
1119 diff -NurpP --minimal linux-2.6.38.1/drivers/block/vroot.c linux-2.6.38.1-vs2.3.0.37-rc9/drivers/block/vroot.c
1120 --- linux-2.6.38.1/drivers/block/vroot.c        1970-01-01 01:00:00.000000000 +0100
1121 +++ linux-2.6.38.1-vs2.3.0.37-rc9/drivers/block/vroot.c 2011-03-17 18:14:05.000000000 +0100
1122 @@ -0,0 +1,292 @@
1123 +/*
1124 + *  linux/drivers/block/vroot.c
1125 + *
1126 + *  written by Herbert Pötzl, 9/11/2002
1127 + *  ported to 2.6.10 by Herbert Pötzl, 30/12/2004
1128 + *
1129 + *  based on the loop.c code by Theodore Ts'o.
1130 + *
1131 + * Copyright (C) 2002-2007 by Herbert Pötzl.
1132 + * Redistribution of this file is permitted under the
1133 + * GNU General Public License.
1134 + *
1135 + */
1136 +
1137 +#include <linux/module.h>
1138 +#include <linux/moduleparam.h>
1139 +#include <linux/file.h>
1140 +#include <linux/major.h>
1141 +#include <linux/blkdev.h>
1142 +#include <linux/slab.h>
1143 +
1144 +#include <linux/vroot.h>
1145 +#include <linux/vs_context.h>
1146 +
1147 +
1148 +static int max_vroot = 8;
1149 +
1150 +static struct vroot_device *vroot_dev;
1151 +static struct gendisk **disks;
1152 +
1153 +
1154 +static int vroot_set_dev(
1155 +       struct vroot_device *vr,
1156 +       struct block_device *bdev,
1157 +       unsigned int arg)
1158 +{
1159 +       struct block_device *real_bdev;
1160 +       struct file *file;
1161 +       struct inode *inode;
1162 +       int error;
1163 +
1164 +       error = -EBUSY;
1165 +       if (vr->vr_state != Vr_unbound)
1166 +               goto out;
1167 +
1168 +       error = -EBADF;
1169 +       file = fget(arg);
1170 +       if (!file)
1171 +               goto out;
1172 +
1173 +       error = -EINVAL;
1174 +       inode = file->f_dentry->d_inode;
1175 +
1176 +
1177 +       if (S_ISBLK(inode->i_mode)) {
1178 +               real_bdev = inode->i_bdev;
1179 +               vr->vr_device = real_bdev;
1180 +               __iget(real_bdev->bd_inode);
1181 +       } else
1182 +               goto out_fput;
1183 +
1184 +       vxdprintk(VXD_CBIT(misc, 0),
1185 +               "vroot[%d]_set_dev: dev=" VXF_DEV,
1186 +               vr->vr_number, VXD_DEV(real_bdev));
1187 +
1188 +       vr->vr_state = Vr_bound;
1189 +       error = 0;
1190 +
1191 + out_fput:
1192 +       fput(file);
1193 + out:
1194 +       return error;
1195 +}
1196 +
1197 +static int vroot_clr_dev(
1198 +       struct vroot_device *vr,
1199 +       struct block_device *bdev)
1200 +{
1201 +       struct block_device *real_bdev;
1202 +
1203 +       if (vr->vr_state != Vr_bound)
1204 +               return -ENXIO;
1205 +       if (vr->vr_refcnt > 1)  /* we needed one fd for the ioctl */
1206 +               return -EBUSY;
1207 +
1208 +       real_bdev = vr->vr_device;
1209 +
1210 +       vxdprintk(VXD_CBIT(misc, 0),
1211 +               "vroot[%d]_clr_dev: dev=" VXF_DEV,
1212 +               vr->vr_number, VXD_DEV(real_bdev));
1213 +
1214 +       bdput(real_bdev);
1215 +       vr->vr_state = Vr_unbound;
1216 +       vr->vr_device = NULL;
1217 +       return 0;
1218 +}
1219 +
1220 +
1221 +static int vr_ioctl(struct block_device *bdev, fmode_t mode,
1222 +       unsigned int cmd, unsigned long arg)
1223 +{
1224 +       struct vroot_device *vr = bdev->bd_disk->private_data;
1225 +       int err;
1226 +
1227 +       down(&vr->vr_ctl_mutex);
1228 +       switch (cmd) {
1229 +       case VROOT_SET_DEV:
1230 +               err = vroot_set_dev(vr, bdev, arg);
1231 +               break;
1232 +       case VROOT_CLR_DEV:
1233 +               err = vroot_clr_dev(vr, bdev);
1234 +               break;
1235 +       default:
1236 +               err = -EINVAL;
1237 +               break;
1238 +       }
1239 +       up(&vr->vr_ctl_mutex);
1240 +       return err;
1241 +}
1242 +
1243 +static int vr_open(struct block_device *bdev, fmode_t mode)
1244 +{
1245 +       struct vroot_device *vr = bdev->bd_disk->private_data;
1246 +
1247 +       down(&vr->vr_ctl_mutex);
1248 +       vr->vr_refcnt++;
1249 +       up(&vr->vr_ctl_mutex);
1250 +       return 0;
1251 +}
1252 +
1253 +static int vr_release(struct gendisk *disk, fmode_t mode)
1254 +{
1255 +       struct vroot_device *vr = disk->private_data;
1256 +
1257 +       down(&vr->vr_ctl_mutex);
1258 +       --vr->vr_refcnt;
1259 +       up(&vr->vr_ctl_mutex);
1260 +       return 0;
1261 +}
1262 +
1263 +static struct block_device_operations vr_fops = {
1264 +       .owner =        THIS_MODULE,
1265 +       .open =         vr_open,
1266 +       .release =      vr_release,
1267 +       .ioctl =        vr_ioctl,
1268 +};
1269 +
1270 +static int vroot_make_request(struct request_queue *q, struct bio *bio)
1271 +{
1272 +       printk("vroot_make_request %p, %p\n", q, bio);
1273 +       bio_io_error(bio);
1274 +       return 0;
1275 +}
1276 +
1277 +struct block_device *__vroot_get_real_bdev(struct block_device *bdev)
1278 +{
1279 +       struct inode *inode = bdev->bd_inode;
1280 +       struct vroot_device *vr;
1281 +       struct block_device *real_bdev;
1282 +       int minor = iminor(inode);
1283 +
1284 +       vr = &vroot_dev[minor];
1285 +       real_bdev = vr->vr_device;
1286 +
1287 +       vxdprintk(VXD_CBIT(misc, 0),
1288 +               "vroot[%d]_get_real_bdev: dev=" VXF_DEV,
1289 +               vr->vr_number, VXD_DEV(real_bdev));
1290 +
1291 +       if (vr->vr_state != Vr_bound)
1292 +               return ERR_PTR(-ENXIO);
1293 +
1294 +       __iget(real_bdev->bd_inode);
1295 +       return real_bdev;
1296 +}
1297 +
1298 +
1299 +
1300 +/*
1301 + * And now the modules code and kernel interface.
1302 + */
1303 +
1304 +module_param(max_vroot, int, 0);
1305 +
1306 +MODULE_PARM_DESC(max_vroot, "Maximum number of vroot devices (1-256)");
1307 +MODULE_LICENSE("GPL");
1308 +MODULE_ALIAS_BLOCKDEV_MAJOR(VROOT_MAJOR);
1309 +
1310 +MODULE_AUTHOR ("Herbert Pötzl");
1311 +MODULE_DESCRIPTION ("Virtual Root Device Mapper");
1312 +
1313 +
1314 +int __init vroot_init(void)
1315 +{
1316 +       int err, i;
1317 +
1318 +       if (max_vroot < 1 || max_vroot > 256) {
1319 +               max_vroot = MAX_VROOT_DEFAULT;
1320 +               printk(KERN_WARNING "vroot: invalid max_vroot "
1321 +                       "(must be between 1 and 256), "
1322 +                       "using default (%d)\n", max_vroot);
1323 +       }
1324 +
1325 +       if (register_blkdev(VROOT_MAJOR, "vroot"))
1326 +               return -EIO;
1327 +
1328 +       err = -ENOMEM;
1329 +       vroot_dev = kmalloc(max_vroot * sizeof(struct vroot_device), GFP_KERNEL);
1330 +       if (!vroot_dev)
1331 +               goto out_mem1;
1332 +       memset(vroot_dev, 0, max_vroot * sizeof(struct vroot_device));
1333 +
1334 +       disks = kmalloc(max_vroot * sizeof(struct gendisk *), GFP_KERNEL);
1335 +       if (!disks)
1336 +               goto out_mem2;
1337 +
1338 +       for (i = 0; i < max_vroot; i++) {
1339 +               disks[i] = alloc_disk(1);
1340 +               if (!disks[i])
1341 +                       goto out_mem3;
1342 +               disks[i]->queue = blk_alloc_queue(GFP_KERNEL);
1343 +               if (!disks[i]->queue)
1344 +                       goto out_mem3;
1345 +               blk_queue_make_request(disks[i]->queue, vroot_make_request);
1346 +       }
1347 +
1348 +       for (i = 0; i < max_vroot; i++) {
1349 +               struct vroot_device *vr = &vroot_dev[i];
1350 +               struct gendisk *disk = disks[i];
1351 +
1352 +               memset(vr, 0, sizeof(*vr));
1353 +               sema_init(&vr->vr_ctl_mutex, 1);
1354 +               vr->vr_number = i;
1355 +               disk->major = VROOT_MAJOR;
1356 +               disk->first_minor = i;
1357 +               disk->fops = &vr_fops;
1358 +               sprintf(disk->disk_name, "vroot%d", i);
1359 +               disk->private_data = vr;
1360 +       }
1361 +
1362 +       err = register_vroot_grb(&__vroot_get_real_bdev);
1363 +       if (err)
1364 +               goto out_mem3;
1365 +
1366 +       for (i = 0; i < max_vroot; i++)
1367 +               add_disk(disks[i]);
1368 +       printk(KERN_INFO "vroot: loaded (max %d devices)\n", max_vroot);
1369 +       return 0;
1370 +
1371 +out_mem3:
1372 +       while (i--)
1373 +               put_disk(disks[i]);
1374 +       kfree(disks);
1375 +out_mem2:
1376 +       kfree(vroot_dev);
1377 +out_mem1:
1378 +       unregister_blkdev(VROOT_MAJOR, "vroot");
1379 +       printk(KERN_ERR "vroot: ran out of memory\n");
1380 +       return err;
1381 +}
1382 +
1383 +void vroot_exit(void)
1384 +{
1385 +       int i;
1386 +
1387 +       if (unregister_vroot_grb(&__vroot_get_real_bdev))
1388 +               printk(KERN_WARNING "vroot: cannot unregister grb\n");
1389 +
1390 +       for (i = 0; i < max_vroot; i++) {
1391 +               del_gendisk(disks[i]);
1392 +               put_disk(disks[i]);
1393 +       }
1394 +       unregister_blkdev(VROOT_MAJOR, "vroot");
1395 +
1396 +       kfree(disks);
1397 +       kfree(vroot_dev);
1398 +}
1399 +
1400 +module_init(vroot_init);
1401 +module_exit(vroot_exit);
1402 +
1403 +#ifndef MODULE
1404 +
1405 +static int __init max_vroot_setup(char *str)
1406 +{
1407 +       max_vroot = simple_strtol(str, NULL, 0);
1408 +       return 1;
1409 +}
1410 +
1411 +__setup("max_vroot=", max_vroot_setup);
1412 +
1413 +#endif
1414 +
1415 diff -NurpP --minimal linux-2.6.38.1/drivers/gpu/drm/radeon/r100_reg_safe.h linux-2.6.38.1-vs2.3.0.37-rc9/drivers/gpu/drm/radeon/r100_reg_safe.h
1416 --- linux-2.6.38.1/drivers/gpu/drm/radeon/r100_reg_safe.h       1970-01-01 01:00:00.000000000 +0100
1417 +++ linux-2.6.38.1-vs2.3.0.37-rc9/drivers/gpu/drm/radeon/r100_reg_safe.h        2011-01-29 02:01:07.000000000 +0100
1418 @@ -0,0 +1,28 @@
1419 +static const unsigned r100_reg_safe_bm[102] = {
1420 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1421 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1422 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1423 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1424 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1425 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1426 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1427 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1428 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1429 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1430 +       0x17FF1FFF, 0xFFFFFFFC, 0xFFFFFFFF, 0xFF30FFBF,
1431 +       0xFFFFFFF8, 0xC3E6FFFF, 0xFFFFF6DF, 0xFFFFFFFF,
1432 +       0xFFFFFFCF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1433 +       0xFFFFFF9F, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1434 +       0x38E7FE1F, 0xFFC3FF8E, 0x7FF8FFFF, 0xFFFF803C,
1435 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1436 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFEFFFF, 0xFFFFFFFF,
1437 +       0x00000000, 0xFFFFFFFD, 0xFFFFFFFF, 0xFFFFFFFF,
1438 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1439 +       0xFFFFFFFF, 0xFFFCFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1440 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1441 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1442 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1443 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1444 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1445 +       0xFFFFFFFF, 0xFFFFFFEF,
1446 +};
1447 diff -NurpP --minimal linux-2.6.38.1/drivers/gpu/drm/radeon/r200_reg_safe.h linux-2.6.38.1-vs2.3.0.37-rc9/drivers/gpu/drm/radeon/r200_reg_safe.h
1448 --- linux-2.6.38.1/drivers/gpu/drm/radeon/r200_reg_safe.h       1970-01-01 01:00:00.000000000 +0100
1449 +++ linux-2.6.38.1-vs2.3.0.37-rc9/drivers/gpu/drm/radeon/r200_reg_safe.h        2011-01-29 02:01:07.000000000 +0100
1450 @@ -0,0 +1,28 @@
1451 +static const unsigned r200_reg_safe_bm[102] = {
1452 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1453 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1454 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1455 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1456 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1457 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1458 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1459 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1460 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1461 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1462 +       0x17FF1FFF, 0xFFFFFFFC, 0xFFFFFFFF, 0xFF30FFBF,
1463 +       0xFFFFFFF8, 0xC3E6FFFF, 0xFFFFF6DF, 0xFFFFFFFF,
1464 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1465 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1466 +       0xFFE7FE1F, 0xF003FFFF, 0x7EFFFFFF, 0xFFFF803C,
1467 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1468 +       0xFFFFFFFF, 0xFFFFEFCE, 0xFFFEFFFF, 0xFFFFFFFE,
1469 +       0x020E0FF0, 0xFFCC83FD, 0xFFFFFFFF, 0xFFFFFFFF,
1470 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1471 +       0xFFFBFFFF, 0xEFFCFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1472 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1473 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1474 +       0xDFDFDFDF, 0x3FFDDFDF, 0xFFFFFFFF, 0xFFFFFF7F,
1475 +       0xFFFFFFFF, 0x00FFFFFF, 0x00000000, 0x00000000,
1476 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1477 +       0xFFFFFE3F, 0xFFFFFFEF,
1478 +};
1479 diff -NurpP --minimal linux-2.6.38.1/drivers/gpu/drm/radeon/r300_reg_safe.h linux-2.6.38.1-vs2.3.0.37-rc9/drivers/gpu/drm/radeon/r300_reg_safe.h
1480 --- linux-2.6.38.1/drivers/gpu/drm/radeon/r300_reg_safe.h       1970-01-01 01:00:00.000000000 +0100
1481 +++ linux-2.6.38.1-vs2.3.0.37-rc9/drivers/gpu/drm/radeon/r300_reg_safe.h        2011-01-29 02:01:07.000000000 +0100
1482 @@ -0,0 +1,42 @@
1483 +static const unsigned r300_reg_safe_bm[159] = {
1484 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1485 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1486 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1487 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1488 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1489 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1490 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1491 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1492 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1493 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1494 +       0x17FF1FFF, 0xFFFFFFFC, 0xFFFFFFFF, 0xFF30FFBF,
1495 +       0xFFFFFFF8, 0xC3E6FFFF, 0xFFFFF6DF, 0xFFFFFFFF,
1496 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1497 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1498 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFF03F,
1499 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1500 +       0xFFFFFFFF, 0xFFFFEFCE, 0xF00EBFFF, 0x007C0000,
1501 +       0xF0000078, 0xFF000009, 0xFFFFFFFF, 0xFFFFFFFF,
1502 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1503 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1504 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1505 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1506 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1507 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1508 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1509 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1510 +       0xFFFFF7FF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1511 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1512 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1513 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1514 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1515 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1516 +       0xFFFFFC78, 0xFFFFFFFF, 0xFFFFFFFE, 0xFFFFFFFF,
1517 +       0x38FF8F50, 0xFFF88082, 0xF000000C, 0xFAE009FF,
1518 +       0x0000FFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0x00000000,
1519 +       0x00000000, 0x0000C100, 0x00000000, 0x00000000,
1520 +       0x00000000, 0x00000000, 0x00000000, 0x00000000,
1521 +       0x00000000, 0xFFFF0000, 0xFFFFFFFF, 0xFF80FFFF,
1522 +       0x00000000, 0x00000000, 0x00000000, 0x00000000,
1523 +       0x0003FC01, 0xFFFFFCF8, 0xFF800B19,
1524 +};
1525 diff -NurpP --minimal linux-2.6.38.1/drivers/gpu/drm/radeon/r420_reg_safe.h linux-2.6.38.1-vs2.3.0.37-rc9/drivers/gpu/drm/radeon/r420_reg_safe.h
1526 --- linux-2.6.38.1/drivers/gpu/drm/radeon/r420_reg_safe.h       1970-01-01 01:00:00.000000000 +0100
1527 +++ linux-2.6.38.1-vs2.3.0.37-rc9/drivers/gpu/drm/radeon/r420_reg_safe.h        2011-01-29 02:01:07.000000000 +0100
1528 @@ -0,0 +1,42 @@
1529 +static const unsigned r420_reg_safe_bm[159] = {
1530 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1531 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1532 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1533 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1534 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1535 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1536 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1537 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1538 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1539 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1540 +       0x17FF1FFF, 0xFFFFFFFC, 0xFFFFFFFF, 0xFF30FFBF,
1541 +       0xFFFFFFF8, 0xC3E6FFFF, 0xFFFFF6DF, 0xFFFFFFFF,
1542 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1543 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1544 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFF03F,
1545 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1546 +       0xFFFFFFFF, 0xFFFFEFCE, 0xF00EBFFF, 0x007C0000,
1547 +       0xF0000078, 0xFF000009, 0xFFFFFFFF, 0xFFFFFFFF,
1548 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1549 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1550 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1551 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1552 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1553 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1554 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1555 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1556 +       0xFFFFF7FF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1557 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1558 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1559 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1560 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1561 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1562 +       0xFFFFFC78, 0xFFFFFFFF, 0xFFFFFFFE, 0xFFFFFFFF,
1563 +       0x38FF8F50, 0xFFF88082, 0xF000000C, 0xFAE009FF,
1564 +       0x0000FFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0x00000000,
1565 +       0x00000000, 0x00000100, 0x00000000, 0x00000000,
1566 +       0x00000000, 0x00000000, 0x00000000, 0x00000000,
1567 +       0x00000000, 0x00000000, 0x00000000, 0xFF800000,
1568 +       0x00000000, 0x00000000, 0x00000000, 0x00000000,
1569 +       0x0003FC01, 0xFFFFFCF8, 0xFF800B19,
1570 +};
1571 diff -NurpP --minimal linux-2.6.38.1/drivers/gpu/drm/radeon/rn50_reg_safe.h linux-2.6.38.1-vs2.3.0.37-rc9/drivers/gpu/drm/radeon/rn50_reg_safe.h
1572 --- linux-2.6.38.1/drivers/gpu/drm/radeon/rn50_reg_safe.h       1970-01-01 01:00:00.000000000 +0100
1573 +++ linux-2.6.38.1-vs2.3.0.37-rc9/drivers/gpu/drm/radeon/rn50_reg_safe.h        2011-01-29 02:01:07.000000000 +0100
1574 @@ -0,0 +1,28 @@
1575 +static const unsigned rn50_reg_safe_bm[102] = {
1576 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1577 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1578 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1579 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1580 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1581 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1582 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1583 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1584 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1585 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1586 +       0x17FF1FFF, 0xFFFFFFFC, 0xFFFFFFFF, 0xFF30FFBF,
1587 +       0xFFFFFFF8, 0xC3E6FFFF, 0xFFFFF6DF, 0xFFFFFFFF,
1588 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1589 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1590 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1591 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1592 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1593 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1594 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1595 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1596 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1597 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1598 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1599 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1600 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1601 +       0xFFFFFFFF, 0xFFFFFFFF,
1602 +};
1603 diff -NurpP --minimal linux-2.6.38.1/drivers/gpu/drm/radeon/rs600_reg_safe.h linux-2.6.38.1-vs2.3.0.37-rc9/drivers/gpu/drm/radeon/rs600_reg_safe.h
1604 --- linux-2.6.38.1/drivers/gpu/drm/radeon/rs600_reg_safe.h      1970-01-01 01:00:00.000000000 +0100
1605 +++ linux-2.6.38.1-vs2.3.0.37-rc9/drivers/gpu/drm/radeon/rs600_reg_safe.h       2011-01-29 02:01:07.000000000 +0100
1606 @@ -0,0 +1,57 @@
1607 +static const unsigned rs600_reg_safe_bm[219] = {
1608 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1609 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1610 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1611 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1612 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1613 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1614 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1615 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1616 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1617 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1618 +       0x17FF1FFF, 0xFFFFFFFC, 0xFFFFFFFF, 0xFF30FFBF,
1619 +       0xFFFFFFF8, 0xC3E6FFFF, 0xFFFFF6DF, 0xFFFFFFFF,
1620 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1621 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1622 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFF03F,
1623 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1624 +       0xFFFFFFFF, 0xFFFFEFCE, 0xF00EBFFF, 0x007C0000,
1625 +       0xF0000078, 0xFF000009, 0xFFFFFFFF, 0xFFFFFFFF,
1626 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1627 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1628 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1629 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1630 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1631 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1632 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1633 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1634 +       0xFFFFF7FF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1635 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1636 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1637 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1638 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1639 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1640 +       0xFFFFFC78, 0xFFFFFFFF, 0xFFFFFFFE, 0xFFFFFFFF,
1641 +       0x38FF8F50, 0xFFF88082, 0xF000000C, 0xFAE009FF,
1642 +       0x0000FFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0x00000000,
1643 +       0x00000000, 0x00000100, 0x00000000, 0x00000000,
1644 +       0x00000000, 0x00000000, 0x00000000, 0x00000000,
1645 +       0x00000000, 0x00000000, 0x00000000, 0xFF800000,
1646 +       0x00000000, 0x00000000, 0x00000000, 0x00000000,
1647 +       0x0003FC01, 0xFFFFFCF8, 0xFF800B19, 0xFFFFFFFF,
1648 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1649 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1650 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1651 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1652 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1653 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1654 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1655 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1656 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1657 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1658 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1659 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1660 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1661 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1662 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1663 +};
1664 diff -NurpP --minimal linux-2.6.38.1/drivers/gpu/drm/radeon/rv515_reg_safe.h linux-2.6.38.1-vs2.3.0.37-rc9/drivers/gpu/drm/radeon/rv515_reg_safe.h
1665 --- linux-2.6.38.1/drivers/gpu/drm/radeon/rv515_reg_safe.h      1970-01-01 01:00:00.000000000 +0100
1666 +++ linux-2.6.38.1-vs2.3.0.37-rc9/drivers/gpu/drm/radeon/rv515_reg_safe.h       2011-01-29 02:01:07.000000000 +0100
1667 @@ -0,0 +1,57 @@
1668 +static const unsigned rv515_reg_safe_bm[219] = {
1669 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1670 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1671 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1672 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1673 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1674 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1675 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1676 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1677 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1678 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1679 +       0x17FF1FFF, 0xFFFFFFFC, 0xFFFFFFFF, 0xFF30FFBF,
1680 +       0xFFFFFFF8, 0xC3E6FFFF, 0xFFFFF6DF, 0xFFFFFFFF,
1681 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1682 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1683 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFF03F,
1684 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1685 +       0xFFFFFFFF, 0xFFFFEFCE, 0xF00EBFFF, 0x007C0000,
1686 +       0xF0000038, 0xFF000009, 0xFFFFFFFF, 0xFFFFFFFF,
1687 +       0xFFFFFFFF, 0xFFFFFFFF, 0x00000000, 0xFFFFFFFF,
1688 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1689 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1690 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1691 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1692 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1693 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1694 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1695 +       0xFFFFF7FF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1696 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1697 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1698 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1699 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1700 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1701 +       0x1FFFF878, 0xFFFFE000, 0xFFFFFE1E, 0xFFFFFFFF,
1702 +       0x388F8F50, 0xFFF88082, 0xFF0000FC, 0xFAE009FF,
1703 +       0x0000FFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0x00000000,
1704 +       0xFFFF8CFC, 0xFFFFC1FF, 0xFFFFFFFF, 0xFFFFFFFF,
1705 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1706 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFF80FFFF,
1707 +       0x00000000, 0x00000000, 0x00000000, 0x00000000,
1708 +       0x0003FC01, 0x3FFFFCF8, 0xFF800B19, 0xFFDFFFFF,
1709 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1710 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1711 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1712 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1713 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1714 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1715 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1716 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1717 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1718 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1719 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1720 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1721 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1722 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1723 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1724 +};
1725 diff -NurpP --minimal linux-2.6.38.1/drivers/infiniband/core/addr.c linux-2.6.38.1-vs2.3.0.37-rc9/drivers/infiniband/core/addr.c
1726 --- linux-2.6.38.1/drivers/infiniband/core/addr.c       2011-03-15 18:06:57.000000000 +0100
1727 +++ linux-2.6.38.1-vs2.3.0.37-rc9/drivers/infiniband/core/addr.c        2011-01-29 02:01:07.000000000 +0100
1728 @@ -252,7 +252,7 @@ static int addr6_resolve(struct sockaddr
1729  
1730         if (ipv6_addr_any(&fl.fl6_src)) {
1731                 ret = ipv6_dev_get_saddr(&init_net, ip6_dst_idev(dst)->dev,
1732 -                                        &fl.fl6_dst, 0, &fl.fl6_src);
1733 +                                        &fl.fl6_dst, 0, &fl.fl6_src, NULL);
1734                 if (ret)
1735                         goto put;
1736  
1737 diff -NurpP --minimal linux-2.6.38.1/drivers/infiniband/hw/ipath/ipath_user_pages.c linux-2.6.38.1-vs2.3.0.37-rc9/drivers/infiniband/hw/ipath/ipath_user_pages.c
1738 --- linux-2.6.38.1/drivers/infiniband/hw/ipath/ipath_user_pages.c       2011-03-15 18:06:58.000000000 +0100
1739 +++ linux-2.6.38.1-vs2.3.0.37-rc9/drivers/infiniband/hw/ipath/ipath_user_pages.c        2011-01-29 02:01:07.000000000 +0100
1740 @@ -35,6 +35,7 @@
1741  #include <linux/device.h>
1742  #include <linux/slab.h>
1743  #include <linux/sched.h>
1744 +#include <linux/vs_memory.h>
1745  
1746  #include "ipath_kernel.h"
1747  
1748 diff -NurpP --minimal linux-2.6.38.1/drivers/md/dm-ioctl.c linux-2.6.38.1-vs2.3.0.37-rc9/drivers/md/dm-ioctl.c
1749 --- linux-2.6.38.1/drivers/md/dm-ioctl.c        2011-03-15 18:07:02.000000000 +0100
1750 +++ linux-2.6.38.1-vs2.3.0.37-rc9/drivers/md/dm-ioctl.c 2011-01-29 02:01:07.000000000 +0100
1751 @@ -16,6 +16,7 @@
1752  #include <linux/dm-ioctl.h>
1753  #include <linux/hdreg.h>
1754  #include <linux/compat.h>
1755 +#include <linux/vs_context.h>
1756  
1757  #include <asm/uaccess.h>
1758  
1759 @@ -106,7 +107,8 @@ static struct hash_cell *__get_name_cell
1760         unsigned int h = hash_str(str);
1761  
1762         list_for_each_entry (hc, _name_buckets + h, name_list)
1763 -               if (!strcmp(hc->name, str)) {
1764 +               if (vx_check(dm_get_xid(hc->md), VS_WATCH_P | VS_IDENT) &&
1765 +                       !strcmp(hc->name, str)) {
1766                         dm_get(hc->md);
1767                         return hc;
1768                 }
1769 @@ -120,7 +122,8 @@ static struct hash_cell *__get_uuid_cell
1770         unsigned int h = hash_str(str);
1771  
1772         list_for_each_entry (hc, _uuid_buckets + h, uuid_list)
1773 -               if (!strcmp(hc->uuid, str)) {
1774 +               if (vx_check(dm_get_xid(hc->md), VS_WATCH_P | VS_IDENT) &&
1775 +                       !strcmp(hc->uuid, str)) {
1776                         dm_get(hc->md);
1777                         return hc;
1778                 }
1779 @@ -427,6 +430,9 @@ typedef int (*ioctl_fn)(struct dm_ioctl 
1780  
1781  static int remove_all(struct dm_ioctl *param, size_t param_size)
1782  {
1783 +       if (!vx_check(0, VS_ADMIN))
1784 +               return -EPERM;
1785 +
1786         dm_hash_remove_all(1);
1787         param->data_size = 0;
1788         return 0;
1789 @@ -474,6 +480,8 @@ static int list_devices(struct dm_ioctl 
1790          */
1791         for (i = 0; i < NUM_BUCKETS; i++) {
1792                 list_for_each_entry (hc, _name_buckets + i, name_list) {
1793 +                       if (!vx_check(dm_get_xid(hc->md), VS_WATCH_P | VS_IDENT))
1794 +                               continue;
1795                         needed += sizeof(struct dm_name_list);
1796                         needed += strlen(hc->name) + 1;
1797                         needed += ALIGN_MASK;
1798 @@ -497,6 +505,8 @@ static int list_devices(struct dm_ioctl 
1799          */
1800         for (i = 0; i < NUM_BUCKETS; i++) {
1801                 list_for_each_entry (hc, _name_buckets + i, name_list) {
1802 +                       if (!vx_check(dm_get_xid(hc->md), VS_WATCH_P | VS_IDENT))
1803 +                               continue;
1804                         if (old_nl)
1805                                 old_nl->next = (uint32_t) ((void *) nl -
1806                                                            (void *) old_nl);
1807 @@ -731,10 +741,11 @@ static struct hash_cell *__find_device_h
1808         if (!md)
1809                 goto out;
1810  
1811 -       mdptr = dm_get_mdptr(md);
1812 +       if (vx_check(dm_get_xid(md), VS_WATCH_P | VS_IDENT))
1813 +               mdptr = dm_get_mdptr(md);
1814 +
1815         if (!mdptr)
1816                 dm_put(md);
1817 -
1818  out:
1819         return mdptr;
1820  }
1821 @@ -1566,8 +1577,8 @@ static int ctl_ioctl(uint command, struc
1822         ioctl_fn fn = NULL;
1823         size_t param_size;
1824  
1825 -       /* only root can play with this */
1826 -       if (!capable(CAP_SYS_ADMIN))
1827 +       /* only root and certain contexts can play with this */
1828 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_ADMIN_MAPPER))
1829                 return -EACCES;
1830  
1831         if (_IOC_TYPE(command) != DM_IOCTL)
1832 diff -NurpP --minimal linux-2.6.38.1/drivers/md/dm.c linux-2.6.38.1-vs2.3.0.37-rc9/drivers/md/dm.c
1833 --- linux-2.6.38.1/drivers/md/dm.c      2011-03-15 18:07:02.000000000 +0100
1834 +++ linux-2.6.38.1-vs2.3.0.37-rc9/drivers/md/dm.c       2011-01-29 03:26:19.000000000 +0100
1835 @@ -20,6 +20,7 @@
1836  #include <linux/idr.h>
1837  #include <linux/hdreg.h>
1838  #include <linux/delay.h>
1839 +#include <linux/vs_base.h>
1840  
1841  #include <trace/events/block.h>
1842  
1843 @@ -119,6 +120,7 @@ struct mapped_device {
1844         rwlock_t map_lock;
1845         atomic_t holders;
1846         atomic_t open_count;
1847 +       xid_t xid;
1848  
1849         unsigned long flags;
1850  
1851 @@ -326,6 +328,7 @@ int dm_deleting_md(struct mapped_device 
1852  static int dm_blk_open(struct block_device *bdev, fmode_t mode)
1853  {
1854         struct mapped_device *md;
1855 +       int ret = -ENXIO;
1856  
1857         spin_lock(&_minor_lock);
1858  
1859 @@ -334,18 +337,19 @@ static int dm_blk_open(struct block_devi
1860                 goto out;
1861  
1862         if (test_bit(DMF_FREEING, &md->flags) ||
1863 -           dm_deleting_md(md)) {
1864 -               md = NULL;
1865 +           dm_deleting_md(md))
1866 +               goto out;
1867 +
1868 +       ret = -EACCES;
1869 +       if (!vx_check(md->xid, VS_IDENT|VS_HOSTID))
1870                 goto out;
1871 -       }
1872  
1873         dm_get(md);
1874         atomic_inc(&md->open_count);
1875 -
1876 +       ret = 0;
1877  out:
1878         spin_unlock(&_minor_lock);
1879 -
1880 -       return md ? 0 : -ENXIO;
1881 +       return ret;
1882  }
1883  
1884  static int dm_blk_close(struct gendisk *disk, fmode_t mode)
1885 @@ -565,6 +569,14 @@ int dm_set_geometry(struct mapped_device
1886         return 0;
1887  }
1888  
1889 +/*
1890 + * Get the xid associated with a dm device
1891 + */
1892 +xid_t dm_get_xid(struct mapped_device *md)
1893 +{
1894 +       return md->xid;
1895 +}
1896 +
1897  /*-----------------------------------------------------------------
1898   * CRUD START:
1899   *   A more elegant soln is in the works that uses the queue
1900 @@ -1860,6 +1872,7 @@ static struct mapped_device *alloc_dev(i
1901         INIT_LIST_HEAD(&md->uevent_list);
1902         spin_lock_init(&md->uevent_lock);
1903  
1904 +       md->xid = vx_current_xid();
1905         md->queue = blk_alloc_queue(GFP_KERNEL);
1906         if (!md->queue)
1907                 goto bad_queue;
1908 diff -NurpP --minimal linux-2.6.38.1/drivers/md/dm.h linux-2.6.38.1-vs2.3.0.37-rc9/drivers/md/dm.h
1909 --- linux-2.6.38.1/drivers/md/dm.h      2010-10-21 13:07:07.000000000 +0200
1910 +++ linux-2.6.38.1-vs2.3.0.37-rc9/drivers/md/dm.h       2011-01-29 02:01:07.000000000 +0100
1911 @@ -41,6 +41,8 @@ struct dm_dev_internal {
1912  struct dm_table;
1913  struct dm_md_mempools;
1914  
1915 +xid_t dm_get_xid(struct mapped_device *md);
1916 +
1917  /*-----------------------------------------------------------------
1918   * Internal table functions.
1919   *---------------------------------------------------------------*/
1920 diff -NurpP --minimal linux-2.6.38.1/drivers/net/tun.c linux-2.6.38.1-vs2.3.0.37-rc9/drivers/net/tun.c
1921 --- linux-2.6.38.1/drivers/net/tun.c    2011-03-15 18:07:12.000000000 +0100
1922 +++ linux-2.6.38.1-vs2.3.0.37-rc9/drivers/net/tun.c     2011-01-29 02:01:07.000000000 +0100
1923 @@ -62,6 +62,7 @@
1924  #include <linux/nsproxy.h>
1925  #include <linux/virtio_net.h>
1926  #include <linux/rcupdate.h>
1927 +#include <linux/vs_network.h>
1928  #include <net/net_namespace.h>
1929  #include <net/netns/generic.h>
1930  #include <net/rtnetlink.h>
1931 @@ -103,6 +104,7 @@ struct tun_struct {
1932         unsigned int            flags;
1933         uid_t                   owner;
1934         gid_t                   group;
1935 +       nid_t                   nid;
1936  
1937         struct net_device       *dev;
1938         struct fasync_struct    *fasync;
1939 @@ -853,6 +855,7 @@ static void tun_setup(struct net_device 
1940  
1941         tun->owner = -1;
1942         tun->group = -1;
1943 +       tun->nid = current->nid;
1944  
1945         dev->ethtool_ops = &tun_ethtool_ops;
1946         dev->destructor = tun_free_netdev;
1947 @@ -1003,7 +1006,7 @@ static int tun_set_iff(struct net *net, 
1948  
1949                 if (((tun->owner != -1 && cred->euid != tun->owner) ||
1950                      (tun->group != -1 && !in_egroup_p(tun->group))) &&
1951 -                   !capable(CAP_NET_ADMIN))
1952 +               !cap_raised(current_cap(), CAP_NET_ADMIN))
1953                         return -EPERM;
1954                 err = security_tun_dev_attach(tun->socket.sk);
1955                 if (err < 0)
1956 @@ -1017,7 +1020,7 @@ static int tun_set_iff(struct net *net, 
1957                 char *name;
1958                 unsigned long flags = 0;
1959  
1960 -               if (!capable(CAP_NET_ADMIN))
1961 +               if (!nx_capable(CAP_NET_ADMIN, NXC_TUN_CREATE))
1962                         return -EPERM;
1963                 err = security_tun_dev_create();
1964                 if (err < 0)
1965 @@ -1087,6 +1090,9 @@ static int tun_set_iff(struct net *net, 
1966  
1967                 sk->sk_destruct = tun_sock_destruct;
1968  
1969 +               if (!nx_check(tun->nid, VS_IDENT | VS_HOSTID | VS_ADMIN_P))
1970 +                       return -EPERM;
1971 +
1972                 err = tun_attach(tun, file);
1973                 if (err < 0)
1974                         goto failed;
1975 @@ -1278,6 +1284,16 @@ static long __tun_chr_ioctl(struct file 
1976                 DBG(KERN_INFO "%s: group set to %d\n", tun->dev->name, tun->group);
1977                 break;
1978  
1979 +       case TUNSETNID:
1980 +               if (!capable(CAP_CONTEXT))
1981 +                       return -EPERM;
1982 +
1983 +               /* Set nid owner of the device */
1984 +               tun->nid = (nid_t) arg;
1985 +
1986 +               DBG(KERN_INFO "%s: nid owner set to %u\n", tun->dev->name, tun->nid);
1987 +               break;
1988 +
1989         case TUNSETLINK:
1990                 /* Only allow setting the type when the interface is down */
1991                 if (tun->dev->flags & IFF_UP) {
1992 diff -NurpP --minimal linux-2.6.38.1/drivers/tty/sysrq.c linux-2.6.38.1-vs2.3.0.37-rc9/drivers/tty/sysrq.c
1993 --- linux-2.6.38.1/drivers/tty/sysrq.c  2011-03-15 18:07:26.000000000 +0100
1994 +++ linux-2.6.38.1-vs2.3.0.37-rc9/drivers/tty/sysrq.c   2011-02-17 02:17:49.000000000 +0100
1995 @@ -41,6 +41,7 @@
1996  #include <linux/oom.h>
1997  #include <linux/slab.h>
1998  #include <linux/input.h>
1999 +#include <linux/vserver/debug.h>
2000  
2001  #include <asm/ptrace.h>
2002  #include <asm/irq_regs.h>
2003 @@ -395,6 +396,21 @@ static struct sysrq_key_op sysrq_unrt_op
2004         .enable_mask    = SYSRQ_ENABLE_RTNICE,
2005  };
2006  
2007 +
2008 +#ifdef CONFIG_VSERVER_DEBUG
2009 +static void sysrq_handle_vxinfo(int key)
2010 +{
2011 +       dump_vx_info_inactive((key == 'x') ? 0 : 1);
2012 +}
2013 +
2014 +static struct sysrq_key_op sysrq_showvxinfo_op = {
2015 +       .handler        = sysrq_handle_vxinfo,
2016 +       .help_msg       = "conteXt",
2017 +       .action_msg     = "Show Context Info",
2018 +       .enable_mask    = SYSRQ_ENABLE_DUMP,
2019 +};
2020 +#endif
2021 +
2022  /* Key Operations table and lock */
2023  static DEFINE_SPINLOCK(sysrq_key_table_lock);
2024  
2025 @@ -449,7 +465,11 @@ static struct sysrq_key_op *sysrq_key_ta
2026         NULL,                           /* v */
2027         &sysrq_showstate_blocked_op,    /* w */
2028         /* x: May be registered on ppc/powerpc for xmon */
2029 +#ifdef CONFIG_VSERVER_DEBUG
2030 +       &sysrq_showvxinfo_op,           /* x */
2031 +#else
2032         NULL,                           /* x */
2033 +#endif
2034         /* y: May be registered on sparc64 for global register dump */
2035         NULL,                           /* y */
2036         &sysrq_ftrace_dump_op,          /* z */
2037 @@ -464,6 +484,8 @@ static int sysrq_key_table_key2index(int
2038                 retval = key - '0';
2039         else if ((key >= 'a') && (key <= 'z'))
2040                 retval = key + 10 - 'a';
2041 +       else if ((key >= 'A') && (key <= 'Z'))
2042 +               retval = key + 10 - 'A';
2043         else
2044                 retval = -1;
2045         return retval;
2046 diff -NurpP --minimal linux-2.6.38.1/drivers/tty/tty_io.c linux-2.6.38.1-vs2.3.0.37-rc9/drivers/tty/tty_io.c
2047 --- linux-2.6.38.1/drivers/tty/tty_io.c 2011-03-15 18:07:26.000000000 +0100
2048 +++ linux-2.6.38.1-vs2.3.0.37-rc9/drivers/tty/tty_io.c  2011-02-02 22:20:24.000000000 +0100
2049 @@ -107,6 +107,7 @@
2050  
2051  #include <linux/kmod.h>
2052  #include <linux/nsproxy.h>
2053 +#include <linux/vs_pid.h>
2054  
2055  #undef TTY_DEBUG_HANGUP
2056  
2057 @@ -2057,7 +2058,8 @@ static int tiocsti(struct tty_struct *tt
2058         char ch, mbz = 0;
2059         struct tty_ldisc *ld;
2060  
2061 -       if ((current->signal->tty != tty) && !capable(CAP_SYS_ADMIN))
2062 +       if (((current->signal->tty != tty) &&
2063 +               !vx_capable(CAP_SYS_ADMIN, VXC_TIOCSTI)))
2064                 return -EPERM;
2065         if (get_user(ch, p))
2066                 return -EFAULT;
2067 @@ -2345,6 +2347,7 @@ static int tiocspgrp(struct tty_struct *
2068                 return -ENOTTY;
2069         if (get_user(pgrp_nr, p))
2070                 return -EFAULT;
2071 +       pgrp_nr = vx_rmap_pid(pgrp_nr);
2072         if (pgrp_nr < 0)
2073                 return -EINVAL;
2074         rcu_read_lock();
2075 diff -NurpP --minimal linux-2.6.38.1/fs/attr.c linux-2.6.38.1-vs2.3.0.37-rc9/fs/attr.c
2076 --- linux-2.6.38.1/fs/attr.c    2010-10-21 13:07:47.000000000 +0200
2077 +++ linux-2.6.38.1-vs2.3.0.37-rc9/fs/attr.c     2011-01-29 02:01:07.000000000 +0100
2078 @@ -13,6 +13,9 @@
2079  #include <linux/fsnotify.h>
2080  #include <linux/fcntl.h>
2081  #include <linux/security.h>
2082 +#include <linux/proc_fs.h>
2083 +#include <linux/devpts_fs.h>
2084 +#include <linux/vs_tag.h>
2085  
2086  /**
2087   * inode_change_ok - check if attribute changes to an inode are allowed
2088 @@ -73,6 +76,10 @@ int inode_change_ok(const struct inode *
2089                         return -EPERM;
2090         }
2091  
2092 +       /* check for inode tag permission */
2093 +       if (dx_permission(inode, MAY_WRITE))
2094 +               return -EACCES;
2095 +
2096         return 0;
2097  }
2098  EXPORT_SYMBOL(inode_change_ok);
2099 @@ -143,6 +150,8 @@ void setattr_copy(struct inode *inode, c
2100                 inode->i_uid = attr->ia_uid;
2101         if (ia_valid & ATTR_GID)
2102                 inode->i_gid = attr->ia_gid;
2103 +       if ((ia_valid & ATTR_TAG) && IS_TAGGED(inode))
2104 +               inode->i_tag = attr->ia_tag;
2105         if (ia_valid & ATTR_ATIME)
2106                 inode->i_atime = timespec_trunc(attr->ia_atime,
2107                                                 inode->i_sb->s_time_gran);
2108 @@ -170,7 +179,8 @@ int notify_change(struct dentry * dentry
2109         struct timespec now;
2110         unsigned int ia_valid = attr->ia_valid;
2111  
2112 -       if (ia_valid & (ATTR_MODE | ATTR_UID | ATTR_GID | ATTR_TIMES_SET)) {
2113 +       if (ia_valid & (ATTR_MODE | ATTR_UID | ATTR_GID |
2114 +               ATTR_TAG | ATTR_TIMES_SET)) {
2115                 if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
2116                         return -EPERM;
2117         }
2118 diff -NurpP --minimal linux-2.6.38.1/fs/binfmt_aout.c linux-2.6.38.1-vs2.3.0.37-rc9/fs/binfmt_aout.c
2119 --- linux-2.6.38.1/fs/binfmt_aout.c     2010-10-21 13:07:47.000000000 +0200
2120 +++ linux-2.6.38.1-vs2.3.0.37-rc9/fs/binfmt_aout.c      2011-01-29 02:01:07.000000000 +0100
2121 @@ -25,6 +25,7 @@
2122  #include <linux/init.h>
2123  #include <linux/coredump.h>
2124  #include <linux/slab.h>
2125 +#include <linux/vs_memory.h>
2126  
2127  #include <asm/system.h>
2128  #include <asm/uaccess.h>
2129 diff -NurpP --minimal linux-2.6.38.1/fs/binfmt_elf.c linux-2.6.38.1-vs2.3.0.37-rc9/fs/binfmt_elf.c
2130 --- linux-2.6.38.1/fs/binfmt_elf.c      2011-03-15 18:07:31.000000000 +0100
2131 +++ linux-2.6.38.1-vs2.3.0.37-rc9/fs/binfmt_elf.c       2011-01-29 02:01:07.000000000 +0100
2132 @@ -32,6 +32,7 @@
2133  #include <linux/elf.h>
2134  #include <linux/utsname.h>
2135  #include <linux/coredump.h>
2136 +#include <linux/vs_memory.h>
2137  #include <asm/uaccess.h>
2138  #include <asm/param.h>
2139  #include <asm/page.h>
2140 diff -NurpP --minimal linux-2.6.38.1/fs/binfmt_flat.c linux-2.6.38.1-vs2.3.0.37-rc9/fs/binfmt_flat.c
2141 --- linux-2.6.38.1/fs/binfmt_flat.c     2010-08-02 16:52:47.000000000 +0200
2142 +++ linux-2.6.38.1-vs2.3.0.37-rc9/fs/binfmt_flat.c      2011-01-29 02:01:07.000000000 +0100
2143 @@ -35,6 +35,7 @@
2144  #include <linux/init.h>
2145  #include <linux/flat.h>
2146  #include <linux/syscalls.h>
2147 +#include <linux/vs_memory.h>
2148  
2149  #include <asm/byteorder.h>
2150  #include <asm/system.h>
2151 diff -NurpP --minimal linux-2.6.38.1/fs/binfmt_som.c linux-2.6.38.1-vs2.3.0.37-rc9/fs/binfmt_som.c
2152 --- linux-2.6.38.1/fs/binfmt_som.c      2010-02-25 11:52:04.000000000 +0100
2153 +++ linux-2.6.38.1-vs2.3.0.37-rc9/fs/binfmt_som.c       2011-01-29 02:01:07.000000000 +0100
2154 @@ -28,6 +28,7 @@
2155  #include <linux/shm.h>
2156  #include <linux/personality.h>
2157  #include <linux/init.h>
2158 +#include <linux/vs_memory.h>
2159  
2160  #include <asm/uaccess.h>
2161  #include <asm/pgtable.h>
2162 diff -NurpP --minimal linux-2.6.38.1/fs/block_dev.c linux-2.6.38.1-vs2.3.0.37-rc9/fs/block_dev.c
2163 --- linux-2.6.38.1/fs/block_dev.c       2011-03-15 18:07:31.000000000 +0100
2164 +++ linux-2.6.38.1-vs2.3.0.37-rc9/fs/block_dev.c        2011-03-07 16:53:27.000000000 +0100
2165 @@ -25,6 +25,7 @@
2166  #include <linux/namei.h>
2167  #include <linux/log2.h>
2168  #include <linux/kmemleak.h>
2169 +#include <linux/vs_device.h>
2170  #include <asm/uaccess.h>
2171  #include "internal.h"
2172  
2173 @@ -551,6 +552,7 @@ struct block_device *bdget(dev_t dev)
2174                 bdev->bd_invalidated = 0;
2175                 inode->i_mode = S_IFBLK;
2176                 inode->i_rdev = dev;
2177 +               inode->i_mdev = dev;
2178                 inode->i_bdev = bdev;
2179                 inode->i_data.a_ops = &def_blk_aops;
2180                 mapping_set_gfp_mask(&inode->i_data, GFP_USER);
2181 @@ -597,6 +599,11 @@ EXPORT_SYMBOL(bdput);
2182  static struct block_device *bd_acquire(struct inode *inode)
2183  {
2184         struct block_device *bdev;
2185 +       dev_t mdev;
2186 +
2187 +       if (!vs_map_blkdev(inode->i_rdev, &mdev, DATTR_OPEN))
2188 +               return NULL;
2189 +       inode->i_mdev = mdev;
2190  
2191         spin_lock(&bdev_lock);
2192         bdev = inode->i_bdev;
2193 @@ -607,7 +614,7 @@ static struct block_device *bd_acquire(s
2194         }
2195         spin_unlock(&bdev_lock);
2196  
2197 -       bdev = bdget(inode->i_rdev);
2198 +       bdev = bdget(mdev);
2199         if (bdev) {
2200                 spin_lock(&bdev_lock);
2201                 if (!inode->i_bdev) {
2202 diff -NurpP --minimal linux-2.6.38.1/fs/btrfs/ctree.h linux-2.6.38.1-vs2.3.0.37-rc9/fs/btrfs/ctree.h
2203 --- linux-2.6.38.1/fs/btrfs/ctree.h     2011-03-15 18:07:31.000000000 +0100
2204 +++ linux-2.6.38.1-vs2.3.0.37-rc9/fs/btrfs/ctree.h      2011-03-15 18:15:06.000000000 +0100
2205 @@ -587,11 +587,14 @@ struct btrfs_inode_item {
2206         /* modification sequence number for NFS */
2207         __le64 sequence;
2208  
2209 +       __le16 tag;
2210         /*
2211          * a little future expansion, for more than this we can
2212          * just grow the inode item and version it
2213          */
2214 -       __le64 reserved[4];
2215 +       __le16 reserved16;
2216 +       __le32 reserved32;
2217 +       __le64 reserved[3];
2218         struct btrfs_timespec atime;
2219         struct btrfs_timespec ctime;
2220         struct btrfs_timespec mtime;
2221 @@ -1265,6 +1268,8 @@ struct btrfs_root {
2222  #define BTRFS_MOUNT_USER_SUBVOL_RM_ALLOWED (1 << 14)
2223  #define BTRFS_MOUNT_ENOSPC_DEBUG        (1 << 15)
2224  
2225 +#define BTRFS_MOUNT_TAGGED             (1 << 24)
2226 +
2227  #define btrfs_clear_opt(o, opt)                ((o) &= ~BTRFS_MOUNT_##opt)
2228  #define btrfs_set_opt(o, opt)          ((o) |= BTRFS_MOUNT_##opt)
2229  #define btrfs_test_opt(root, opt)      ((root)->fs_info->mount_opt & \
2230 @@ -1485,6 +1490,7 @@ BTRFS_SETGET_FUNCS(inode_block_group, st
2231  BTRFS_SETGET_FUNCS(inode_nlink, struct btrfs_inode_item, nlink, 32);
2232  BTRFS_SETGET_FUNCS(inode_uid, struct btrfs_inode_item, uid, 32);
2233  BTRFS_SETGET_FUNCS(inode_gid, struct btrfs_inode_item, gid, 32);
2234 +BTRFS_SETGET_FUNCS(inode_tag, struct btrfs_inode_item, tag, 16);
2235  BTRFS_SETGET_FUNCS(inode_mode, struct btrfs_inode_item, mode, 32);
2236  BTRFS_SETGET_FUNCS(inode_rdev, struct btrfs_inode_item, rdev, 64);
2237  BTRFS_SETGET_FUNCS(inode_flags, struct btrfs_inode_item, flags, 64);
2238 @@ -1546,6 +1552,10 @@ BTRFS_SETGET_FUNCS(extent_flags, struct 
2239  
2240  BTRFS_SETGET_FUNCS(extent_refs_v0, struct btrfs_extent_item_v0, refs, 32);
2241  
2242 +#define BTRFS_INODE_IXUNLINK           (1 << 24)
2243 +#define BTRFS_INODE_BARRIER            (1 << 25)
2244 +#define BTRFS_INODE_COW                        (1 << 26)
2245 +
2246  
2247  BTRFS_SETGET_FUNCS(tree_block_level, struct btrfs_tree_block_info, level, 8);
2248  
2249 @@ -2553,6 +2563,7 @@ extern const struct dentry_operations bt
2250  long btrfs_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
2251  void btrfs_update_iflags(struct inode *inode);
2252  void btrfs_inherit_iflags(struct inode *inode, struct inode *dir);
2253 +int btrfs_sync_flags(struct inode *inode, int, int);
2254  
2255  /* file.c */
2256  int btrfs_sync_file(struct file *file, int datasync);
2257 diff -NurpP --minimal linux-2.6.38.1/fs/btrfs/disk-io.c linux-2.6.38.1-vs2.3.0.37-rc9/fs/btrfs/disk-io.c
2258 --- linux-2.6.38.1/fs/btrfs/disk-io.c   2011-03-15 18:07:31.000000000 +0100
2259 +++ linux-2.6.38.1-vs2.3.0.37-rc9/fs/btrfs/disk-io.c    2011-02-17 02:17:50.000000000 +0100
2260 @@ -1768,6 +1768,9 @@ struct btrfs_root *open_ctree(struct sup
2261                 goto fail_iput;
2262         }
2263  
2264 +       if (btrfs_test_opt(tree_root, TAGGED))
2265 +               sb->s_flags |= MS_TAGGED;
2266 +
2267         features = btrfs_super_incompat_flags(disk_super) &
2268                 ~BTRFS_FEATURE_INCOMPAT_SUPP;
2269         if (features) {
2270 diff -NurpP --minimal linux-2.6.38.1/fs/btrfs/inode.c linux-2.6.38.1-vs2.3.0.37-rc9/fs/btrfs/inode.c
2271 --- linux-2.6.38.1/fs/btrfs/inode.c     2011-03-15 18:07:31.000000000 +0100
2272 +++ linux-2.6.38.1-vs2.3.0.37-rc9/fs/btrfs/inode.c      2011-03-15 18:15:06.000000000 +0100
2273 @@ -37,6 +37,8 @@
2274  #include <linux/posix_acl.h>
2275  #include <linux/falloc.h>
2276  #include <linux/slab.h>
2277 +#include <linux/vs_tag.h>
2278 +
2279  #include "compat.h"
2280  #include "ctree.h"
2281  #include "disk-io.h"
2282 @@ -2463,6 +2465,8 @@ static void btrfs_read_locked_inode(stru
2283         int maybe_acls;
2284         u64 alloc_group_block;
2285         u32 rdev;
2286 +       uid_t uid;
2287 +       gid_t gid;
2288         int ret;
2289  
2290         path = btrfs_alloc_path();
2291 @@ -2479,8 +2483,13 @@ static void btrfs_read_locked_inode(stru
2292  
2293         inode->i_mode = btrfs_inode_mode(leaf, inode_item);
2294         inode->i_nlink = btrfs_inode_nlink(leaf, inode_item);
2295 -       inode->i_uid = btrfs_inode_uid(leaf, inode_item);
2296 -       inode->i_gid = btrfs_inode_gid(leaf, inode_item);
2297 +
2298 +       uid = btrfs_inode_uid(leaf, inode_item);
2299 +       gid = btrfs_inode_gid(leaf, inode_item);
2300 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
2301 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
2302 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid,
2303 +               btrfs_inode_tag(leaf, inode_item));
2304         btrfs_i_size_write(inode, btrfs_inode_size(leaf, inode_item));
2305  
2306         tspec = btrfs_inode_atime(inode_item);
2307 @@ -2562,8 +2571,15 @@ static void fill_inode_item(struct btrfs
2308                             struct btrfs_inode_item *item,
2309                             struct inode *inode)
2310  {
2311 -       btrfs_set_inode_uid(leaf, item, inode->i_uid);
2312 -       btrfs_set_inode_gid(leaf, item, inode->i_gid);
2313 +       uid_t uid = TAGINO_UID(DX_TAG(inode), inode->i_uid, inode->i_tag);
2314 +       gid_t gid = TAGINO_GID(DX_TAG(inode), inode->i_gid, inode->i_tag);
2315 +
2316 +       btrfs_set_inode_uid(leaf, item, uid);
2317 +       btrfs_set_inode_gid(leaf, item, gid);
2318 +#ifdef CONFIG_TAGGING_INTERN
2319 +       btrfs_set_inode_tag(leaf, item, inode->i_tag);
2320 +#endif
2321 +
2322         btrfs_set_inode_size(leaf, item, BTRFS_I(inode)->disk_i_size);
2323         btrfs_set_inode_mode(leaf, item, inode->i_mode);
2324         btrfs_set_inode_nlink(leaf, item, inode->i_nlink);
2325 @@ -7293,6 +7309,7 @@ static const struct inode_operations btr
2326         .listxattr      = btrfs_listxattr,
2327         .removexattr    = btrfs_removexattr,
2328         .permission     = btrfs_permission,
2329 +       .sync_flags     = btrfs_sync_flags,
2330  };
2331  static const struct inode_operations btrfs_dir_ro_inode_operations = {
2332         .lookup         = btrfs_lookup,
2333 @@ -7367,6 +7384,7 @@ static const struct inode_operations btr
2334         .removexattr    = btrfs_removexattr,
2335         .permission     = btrfs_permission,
2336         .fiemap         = btrfs_fiemap,
2337 +       .sync_flags     = btrfs_sync_flags,
2338  };
2339  static const struct inode_operations btrfs_special_inode_operations = {
2340         .getattr        = btrfs_getattr,
2341 diff -NurpP --minimal linux-2.6.38.1/fs/btrfs/ioctl.c linux-2.6.38.1-vs2.3.0.37-rc9/fs/btrfs/ioctl.c
2342 --- linux-2.6.38.1/fs/btrfs/ioctl.c     2011-03-15 18:07:31.000000000 +0100
2343 +++ linux-2.6.38.1-vs2.3.0.37-rc9/fs/btrfs/ioctl.c      2011-03-07 16:53:27.000000000 +0100
2344 @@ -68,10 +68,13 @@ static unsigned int btrfs_flags_to_ioctl
2345  {
2346         unsigned int iflags = 0;
2347  
2348 -       if (flags & BTRFS_INODE_SYNC)
2349 -               iflags |= FS_SYNC_FL;
2350         if (flags & BTRFS_INODE_IMMUTABLE)
2351                 iflags |= FS_IMMUTABLE_FL;
2352 +       if (flags & BTRFS_INODE_IXUNLINK)
2353 +               iflags |= FS_IXUNLINK_FL;
2354 +
2355 +       if (flags & BTRFS_INODE_SYNC)
2356 +               iflags |= FS_SYNC_FL;
2357         if (flags & BTRFS_INODE_APPEND)
2358                 iflags |= FS_APPEND_FL;
2359         if (flags & BTRFS_INODE_NODUMP)
2360 @@ -81,28 +84,78 @@ static unsigned int btrfs_flags_to_ioctl
2361         if (flags & BTRFS_INODE_DIRSYNC)
2362                 iflags |= FS_DIRSYNC_FL;
2363  
2364 +       if (flags & BTRFS_INODE_BARRIER)
2365 +               iflags |= FS_BARRIER_FL;
2366 +       if (flags & BTRFS_INODE_COW)
2367 +               iflags |= FS_COW_FL;
2368         return iflags;
2369  }
2370  
2371  /*
2372 - * Update inode->i_flags based on the btrfs internal flags.
2373 + * Update inode->i_(v)flags based on the btrfs internal flags.
2374   */
2375  void btrfs_update_iflags(struct inode *inode)
2376  {
2377         struct btrfs_inode *ip = BTRFS_I(inode);
2378  
2379 -       inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
2380 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
2381 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
2382  
2383 -       if (ip->flags & BTRFS_INODE_SYNC)
2384 -               inode->i_flags |= S_SYNC;
2385         if (ip->flags & BTRFS_INODE_IMMUTABLE)
2386                 inode->i_flags |= S_IMMUTABLE;
2387 +       if (ip->flags & BTRFS_INODE_IXUNLINK)
2388 +               inode->i_flags |= S_IXUNLINK;
2389 +
2390 +       if (ip->flags & BTRFS_INODE_SYNC)
2391 +               inode->i_flags |= S_SYNC;
2392         if (ip->flags & BTRFS_INODE_APPEND)
2393                 inode->i_flags |= S_APPEND;
2394         if (ip->flags & BTRFS_INODE_NOATIME)
2395                 inode->i_flags |= S_NOATIME;
2396         if (ip->flags & BTRFS_INODE_DIRSYNC)
2397                 inode->i_flags |= S_DIRSYNC;
2398 +
2399 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
2400 +
2401 +       if (ip->flags & BTRFS_INODE_BARRIER)
2402 +               inode->i_vflags |= V_BARRIER;
2403 +       if (ip->flags & BTRFS_INODE_COW)
2404 +               inode->i_vflags |= V_COW;
2405 +}
2406 +
2407 +/*
2408 + * Update btrfs internal flags from inode->i_(v)flags.
2409 + */
2410 +void btrfs_update_flags(struct inode *inode)
2411 +{
2412 +       struct btrfs_inode *ip = BTRFS_I(inode);
2413 +
2414 +       unsigned int flags = inode->i_flags;
2415 +       unsigned int vflags = inode->i_vflags;
2416 +
2417 +       ip->flags &= ~(BTRFS_INODE_SYNC | BTRFS_INODE_APPEND |
2418 +                       BTRFS_INODE_IMMUTABLE | BTRFS_INODE_IXUNLINK |
2419 +                       BTRFS_INODE_NOATIME | BTRFS_INODE_DIRSYNC |
2420 +                       BTRFS_INODE_BARRIER | BTRFS_INODE_COW);
2421 +
2422 +       if (flags & S_IMMUTABLE)
2423 +               ip->flags |= BTRFS_INODE_IMMUTABLE;
2424 +       if (flags & S_IXUNLINK)
2425 +               ip->flags |= BTRFS_INODE_IXUNLINK;
2426 +
2427 +       if (flags & S_SYNC)
2428 +               ip->flags |= BTRFS_INODE_SYNC;
2429 +       if (flags & S_APPEND)
2430 +               ip->flags |= BTRFS_INODE_APPEND;
2431 +       if (flags & S_NOATIME)
2432 +               ip->flags |= BTRFS_INODE_NOATIME;
2433 +       if (flags & S_DIRSYNC)
2434 +               ip->flags |= BTRFS_INODE_DIRSYNC;
2435 +
2436 +       if (vflags & V_BARRIER)
2437 +               ip->flags |= BTRFS_INODE_BARRIER;
2438 +       if (vflags & V_COW)
2439 +               ip->flags |= BTRFS_INODE_COW;
2440  }
2441  
2442  /*
2443 @@ -120,7 +173,7 @@ void btrfs_inherit_iflags(struct inode *
2444         flags = BTRFS_I(dir)->flags;
2445  
2446         if (S_ISREG(inode->i_mode))
2447 -               flags &= ~BTRFS_INODE_DIRSYNC;
2448 +               flags &= ~(BTRFS_INODE_DIRSYNC | BTRFS_INODE_BARRIER);
2449         else if (!S_ISDIR(inode->i_mode))
2450                 flags &= (BTRFS_INODE_NODUMP | BTRFS_INODE_NOATIME);
2451  
2452 @@ -128,6 +181,30 @@ void btrfs_inherit_iflags(struct inode *
2453         btrfs_update_iflags(inode);
2454  }
2455  
2456 +int btrfs_sync_flags(struct inode *inode, int flags, int vflags)
2457 +{
2458 +       struct btrfs_inode *ip = BTRFS_I(inode);
2459 +       struct btrfs_root *root = ip->root;
2460 +       struct btrfs_trans_handle *trans;
2461 +       int ret;
2462 +
2463 +       trans = btrfs_join_transaction(root, 1);
2464 +       BUG_ON(!trans);
2465 +
2466 +       inode->i_flags = flags;
2467 +       inode->i_vflags = vflags;
2468 +       btrfs_update_flags(inode);
2469 +
2470 +       ret = btrfs_update_inode(trans, root, inode);
2471 +       BUG_ON(ret);
2472 +
2473 +       btrfs_update_iflags(inode);
2474 +       inode->i_ctime = CURRENT_TIME;
2475 +       btrfs_end_transaction(trans, root);
2476 +
2477 +       return 0;
2478 +}
2479 +
2480  static int btrfs_ioctl_getflags(struct file *file, void __user *arg)
2481  {
2482         struct btrfs_inode *ip = BTRFS_I(file->f_path.dentry->d_inode);
2483 @@ -153,6 +230,7 @@ static int btrfs_ioctl_setflags(struct f
2484         if (copy_from_user(&flags, arg, sizeof(flags)))
2485                 return -EFAULT;
2486  
2487 +       /* maybe add FS_IXUNLINK_FL ? */
2488         if (flags & ~(FS_IMMUTABLE_FL | FS_APPEND_FL | \
2489                       FS_NOATIME_FL | FS_NODUMP_FL | \
2490                       FS_SYNC_FL | FS_DIRSYNC_FL))
2491 @@ -165,7 +243,8 @@ static int btrfs_ioctl_setflags(struct f
2492  
2493         flags = btrfs_mask_flags(inode->i_mode, flags);
2494         oldflags = btrfs_flags_to_ioctl(ip->flags);
2495 -       if ((flags ^ oldflags) & (FS_APPEND_FL | FS_IMMUTABLE_FL)) {
2496 +       if ((flags ^ oldflags) & (FS_APPEND_FL |
2497 +               FS_IMMUTABLE_FL | FS_IXUNLINK_FL)) {
2498                 if (!capable(CAP_LINUX_IMMUTABLE)) {
2499                         ret = -EPERM;
2500                         goto out_unlock;
2501 @@ -176,14 +255,19 @@ static int btrfs_ioctl_setflags(struct f
2502         if (ret)
2503                 goto out_unlock;
2504  
2505 -       if (flags & FS_SYNC_FL)
2506 -               ip->flags |= BTRFS_INODE_SYNC;
2507 -       else
2508 -               ip->flags &= ~BTRFS_INODE_SYNC;
2509         if (flags & FS_IMMUTABLE_FL)
2510                 ip->flags |= BTRFS_INODE_IMMUTABLE;
2511         else
2512                 ip->flags &= ~BTRFS_INODE_IMMUTABLE;
2513 +       if (flags & FS_IXUNLINK_FL)
2514 +               ip->flags |= BTRFS_INODE_IXUNLINK;
2515 +       else
2516 +               ip->flags &= ~BTRFS_INODE_IXUNLINK;
2517 +
2518 +       if (flags & FS_SYNC_FL)
2519 +               ip->flags |= BTRFS_INODE_SYNC;
2520 +       else
2521 +               ip->flags &= ~BTRFS_INODE_SYNC;
2522         if (flags & FS_APPEND_FL)
2523                 ip->flags |= BTRFS_INODE_APPEND;
2524         else
2525 diff -NurpP --minimal linux-2.6.38.1/fs/btrfs/super.c linux-2.6.38.1-vs2.3.0.37-rc9/fs/btrfs/super.c
2526 --- linux-2.6.38.1/fs/btrfs/super.c     2011-03-15 18:07:31.000000000 +0100
2527 +++ linux-2.6.38.1-vs2.3.0.37-rc9/fs/btrfs/super.c      2011-03-07 17:04:18.000000000 +0100
2528 @@ -155,8 +155,8 @@ enum {
2529         Opt_nossd, Opt_ssd_spread, Opt_thread_pool, Opt_noacl, Opt_compress,
2530         Opt_compress_type, Opt_compress_force, Opt_compress_force_type,
2531         Opt_notreelog, Opt_ratio, Opt_flushoncommit, Opt_discard,
2532 -       Opt_space_cache, Opt_clear_cache, Opt_user_subvol_rm_allowed,
2533 -       Opt_enospc_debug, Opt_err,
2534 +       Opt_space_cache, Opt_clear_cache, Opt_user_subvol_rm_allowed,
2535 +       Opt_enospc_debug, Opt_tag, Opt_notag, Opt_tagid, Opt_err,
2536  };
2537  
2538  static match_table_t tokens = {
2539 @@ -186,6 +186,9 @@ static match_table_t tokens = {
2540         {Opt_clear_cache, "clear_cache"},
2541         {Opt_user_subvol_rm_allowed, "user_subvol_rm_allowed"},
2542         {Opt_enospc_debug, "enospc_debug"},
2543 +       {Opt_tag, "tag"},
2544 +       {Opt_notag, "notag"},
2545 +       {Opt_tagid, "tagid=%u"},
2546         {Opt_err, NULL},
2547  };
2548  
2549 @@ -363,6 +366,22 @@ int btrfs_parse_options(struct btrfs_roo
2550                 case Opt_enospc_debug:
2551                         btrfs_set_opt(info->mount_opt, ENOSPC_DEBUG);
2552                         break;
2553 +#ifndef CONFIG_TAGGING_NONE
2554 +               case Opt_tag:
2555 +                       printk(KERN_INFO "btrfs: use tagging\n");
2556 +                       btrfs_set_opt(info->mount_opt, TAGGED);
2557 +                       break;
2558 +               case Opt_notag:
2559 +                       printk(KERN_INFO "btrfs: disabled tagging\n");
2560 +                       btrfs_clear_opt(info->mount_opt, TAGGED);
2561 +                       break;
2562 +#endif
2563 +#ifdef CONFIG_PROPAGATE
2564 +               case Opt_tagid:
2565 +                       /* use args[0] */
2566 +                       btrfs_set_opt(info->mount_opt, TAGGED);
2567 +                       break;
2568 +#endif
2569                 case Opt_err:
2570                         printk(KERN_INFO "btrfs: unrecognized mount option "
2571                                "'%s'\n", p);
2572 @@ -841,6 +860,12 @@ static int btrfs_remount(struct super_bl
2573         if (ret)
2574                 return -EINVAL;
2575  
2576 +       if (btrfs_test_opt(root, TAGGED) && !(sb->s_flags & MS_TAGGED)) {
2577 +               printk("btrfs: %s: tagging not permitted on remount.\n",
2578 +                       sb->s_id);
2579 +               return -EINVAL;
2580 +       }
2581 +
2582         if ((*flags & MS_RDONLY) == (sb->s_flags & MS_RDONLY))
2583                 return 0;
2584  
2585 diff -NurpP --minimal linux-2.6.38.1/fs/char_dev.c linux-2.6.38.1-vs2.3.0.37-rc9/fs/char_dev.c
2586 --- linux-2.6.38.1/fs/char_dev.c        2011-03-15 18:07:31.000000000 +0100
2587 +++ linux-2.6.38.1-vs2.3.0.37-rc9/fs/char_dev.c 2011-01-29 02:01:07.000000000 +0100
2588 @@ -21,6 +21,8 @@
2589  #include <linux/mutex.h>
2590  #include <linux/backing-dev.h>
2591  #include <linux/tty.h>
2592 +#include <linux/vs_context.h>
2593 +#include <linux/vs_device.h>
2594  
2595  #include "internal.h"
2596  
2597 @@ -371,14 +373,21 @@ static int chrdev_open(struct inode *ino
2598         struct cdev *p;
2599         struct cdev *new = NULL;
2600         int ret = 0;
2601 +       dev_t mdev;
2602 +
2603 +       if (!vs_map_chrdev(inode->i_rdev, &mdev, DATTR_OPEN))
2604 +               return -EPERM;
2605 +       inode->i_mdev = mdev;
2606  
2607         spin_lock(&cdev_lock);
2608         p = inode->i_cdev;
2609         if (!p) {
2610                 struct kobject *kobj;
2611                 int idx;
2612 +
2613                 spin_unlock(&cdev_lock);
2614 -               kobj = kobj_lookup(cdev_map, inode->i_rdev, &idx);
2615 +
2616 +               kobj = kobj_lookup(cdev_map, mdev, &idx);
2617                 if (!kobj)
2618                         return -ENXIO;
2619                 new = container_of(kobj, struct cdev, kobj);
2620 diff -NurpP --minimal linux-2.6.38.1/fs/dcache.c linux-2.6.38.1-vs2.3.0.37-rc9/fs/dcache.c
2621 --- linux-2.6.38.1/fs/dcache.c  2011-03-26 01:10:17.000000000 +0100
2622 +++ linux-2.6.38.1-vs2.3.0.37-rc9/fs/dcache.c   2011-03-25 22:52:15.000000000 +0100
2623 @@ -35,6 +35,7 @@
2624  #include <linux/hardirq.h>
2625  #include <linux/bit_spinlock.h>
2626  #include <linux/rculist_bl.h>
2627 +#include <linux/vs_limit.h>
2628  #include "internal.h"
2629  
2630  /*
2631 @@ -500,6 +501,8 @@ int d_invalidate(struct dentry * dentry)
2632                 spin_lock(&dentry->d_lock);
2633         }
2634  
2635 +       vx_dentry_dec(dentry);
2636 +
2637         /*
2638          * Somebody else still using it?
2639          *
2640 @@ -527,6 +530,7 @@ EXPORT_SYMBOL(d_invalidate);
2641  static inline void __dget_dlock(struct dentry *dentry)
2642  {
2643         dentry->d_count++;
2644 +       vx_dentry_inc(dentry);
2645  }
2646  
2647  static inline void __dget(struct dentry *dentry)
2648 @@ -1283,6 +1287,9 @@ struct dentry *d_alloc(struct dentry * p
2649         struct dentry *dentry;
2650         char *dname;
2651  
2652 +       if (!vx_dentry_avail(1))
2653 +               return NULL;
2654 +
2655         dentry = kmem_cache_alloc(dentry_cache, GFP_KERNEL);
2656         if (!dentry)
2657                 return NULL;
2658 @@ -1304,6 +1311,7 @@ struct dentry *d_alloc(struct dentry * p
2659         dname[name->len] = 0;
2660  
2661         dentry->d_count = 1;
2662 +       vx_dentry_inc(dentry);
2663         dentry->d_flags = DCACHE_UNHASHED;
2664         spin_lock_init(&dentry->d_lock);
2665         seqcount_init(&dentry->d_seq);
2666 @@ -1962,6 +1970,7 @@ struct dentry *__d_lookup(struct dentry 
2667                 }
2668  
2669                 dentry->d_count++;
2670 +               vx_dentry_inc(dentry);
2671                 found = dentry;
2672                 spin_unlock(&dentry->d_lock);
2673                 break;
2674 diff -NurpP --minimal linux-2.6.38.1/fs/devpts/inode.c linux-2.6.38.1-vs2.3.0.37-rc9/fs/devpts/inode.c
2675 --- linux-2.6.38.1/fs/devpts/inode.c    2011-01-05 21:50:22.000000000 +0100
2676 +++ linux-2.6.38.1-vs2.3.0.37-rc9/fs/devpts/inode.c     2011-03-17 02:17:19.000000000 +0100
2677 @@ -25,6 +25,7 @@
2678  #include <linux/parser.h>
2679  #include <linux/fsnotify.h>
2680  #include <linux/seq_file.h>
2681 +#include <linux/vs_base.h>
2682  
2683  #define DEVPTS_DEFAULT_MODE 0600
2684  /*
2685 @@ -36,6 +37,20 @@
2686  #define DEVPTS_DEFAULT_PTMX_MODE 0000
2687  #define PTMX_MINOR     2
2688  
2689 +static int devpts_permission(struct inode *inode, int mask, unsigned int flags)
2690 +{
2691 +       int ret = -EACCES;
2692 +
2693 +       /* devpts is xid tagged */
2694 +       if (vx_check((xid_t)inode->i_tag, VS_WATCH_P | VS_IDENT))
2695 +               ret = generic_permission(inode, mask, flags, NULL);
2696 +       return ret;
2697 +}
2698 +
2699 +static struct inode_operations devpts_file_inode_operations = {
2700 +       .permission     = devpts_permission,
2701 +};
2702 +
2703  extern int pty_limit;                  /* Config limit on Unix98 ptys */
2704  static DEFINE_MUTEX(allocated_ptys_lock);
2705  
2706 @@ -263,6 +278,34 @@ static int devpts_show_options(struct se
2707         return 0;
2708  }
2709  
2710 +static int devpts_filter(struct dentry *de)
2711 +{
2712 +       xid_t xid = 0;
2713 +
2714 +       /* devpts is xid tagged */
2715 +       if (de && de->d_inode)
2716 +               xid = (xid_t)de->d_inode->i_tag;
2717 +#ifdef CONFIG_VSERVER_WARN_DEVPTS
2718 +       else
2719 +               vxwprintk_task(1, "devpts " VS_Q("%.*s") " without inode.",
2720 +                       de->d_name.len, de->d_name.name);
2721 +#endif
2722 +       return vx_check(xid, VS_WATCH_P | VS_IDENT);
2723 +}
2724 +
2725 +static int devpts_readdir(struct file * filp, void * dirent, filldir_t filldir)
2726 +{
2727 +       return dcache_readdir_filter(filp, dirent, filldir, devpts_filter);
2728 +}
2729 +
2730 +static struct file_operations devpts_dir_operations = {
2731 +       .open           = dcache_dir_open,
2732 +       .release        = dcache_dir_close,
2733 +       .llseek         = dcache_dir_lseek,
2734 +       .read           = generic_read_dir,
2735 +       .readdir        = devpts_readdir,
2736 +};
2737 +
2738  static const struct super_operations devpts_sops = {
2739         .statfs         = simple_statfs,
2740         .remount_fs     = devpts_remount,
2741 @@ -302,12 +345,15 @@ devpts_fill_super(struct super_block *s,
2742         inode = new_inode(s);
2743         if (!inode)
2744                 goto free_fsi;
2745 +
2746         inode->i_ino = 1;
2747         inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
2748         inode->i_mode = S_IFDIR | S_IRUGO | S_IXUGO | S_IWUSR;
2749         inode->i_op = &simple_dir_inode_operations;
2750 -       inode->i_fop = &simple_dir_operations;
2751 +       inode->i_fop = &devpts_dir_operations;
2752         inode->i_nlink = 2;
2753 +       /* devpts is xid tagged */
2754 +       inode->i_tag = (tag_t)vx_current_xid();
2755  
2756         s->s_root = d_alloc_root(inode);
2757         if (s->s_root)
2758 @@ -493,6 +539,9 @@ int devpts_pty_new(struct inode *ptmx_in
2759         inode->i_gid = opts->setgid ? opts->gid : current_fsgid();
2760         inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
2761         init_special_inode(inode, S_IFCHR|opts->mode, device);
2762 +       /* devpts is xid tagged */
2763 +       inode->i_tag = (tag_t)vx_current_xid();
2764 +       inode->i_op = &devpts_file_inode_operations;
2765         inode->i_private = tty;
2766         tty->driver_data = inode;
2767  
2768 diff -NurpP --minimal linux-2.6.38.1/fs/ext2/balloc.c linux-2.6.38.1-vs2.3.0.37-rc9/fs/ext2/balloc.c
2769 --- linux-2.6.38.1/fs/ext2/balloc.c     2011-01-05 21:50:22.000000000 +0100
2770 +++ linux-2.6.38.1-vs2.3.0.37-rc9/fs/ext2/balloc.c      2011-01-29 02:01:07.000000000 +0100
2771 @@ -701,7 +701,6 @@ ext2_try_to_allocate(struct super_block 
2772                         start = 0;
2773                 end = EXT2_BLOCKS_PER_GROUP(sb);
2774         }
2775 -
2776         BUG_ON(start > EXT2_BLOCKS_PER_GROUP(sb));
2777  
2778  repeat:
2779 diff -NurpP --minimal linux-2.6.38.1/fs/ext2/ext2.h linux-2.6.38.1-vs2.3.0.37-rc9/fs/ext2/ext2.h
2780 --- linux-2.6.38.1/fs/ext2/ext2.h       2011-01-05 21:50:22.000000000 +0100
2781 +++ linux-2.6.38.1-vs2.3.0.37-rc9/fs/ext2/ext2.h        2011-01-29 02:01:07.000000000 +0100
2782 @@ -126,6 +126,7 @@ extern void ext2_set_inode_flags(struct 
2783  extern void ext2_get_inode_flags(struct ext2_inode_info *);
2784  extern int ext2_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
2785                        u64 start, u64 len);
2786 +extern int ext2_sync_flags(struct inode *, int, int);
2787  
2788  /* ioctl.c */
2789  extern long ext2_ioctl(struct file *, unsigned int, unsigned long);
2790 diff -NurpP --minimal linux-2.6.38.1/fs/ext2/file.c linux-2.6.38.1-vs2.3.0.37-rc9/fs/ext2/file.c
2791 --- linux-2.6.38.1/fs/ext2/file.c       2010-08-02 16:52:48.000000000 +0200
2792 +++ linux-2.6.38.1-vs2.3.0.37-rc9/fs/ext2/file.c        2011-01-29 02:01:07.000000000 +0100
2793 @@ -104,4 +104,5 @@ const struct inode_operations ext2_file_
2794         .setattr        = ext2_setattr,
2795         .check_acl      = ext2_check_acl,
2796         .fiemap         = ext2_fiemap,
2797 +       .sync_flags     = ext2_sync_flags,
2798  };
2799 diff -NurpP --minimal linux-2.6.38.1/fs/ext2/ialloc.c linux-2.6.38.1-vs2.3.0.37-rc9/fs/ext2/ialloc.c
2800 --- linux-2.6.38.1/fs/ext2/ialloc.c     2010-10-21 13:07:48.000000000 +0200
2801 +++ linux-2.6.38.1-vs2.3.0.37-rc9/fs/ext2/ialloc.c      2011-01-29 02:01:07.000000000 +0100
2802 @@ -17,6 +17,7 @@
2803  #include <linux/backing-dev.h>
2804  #include <linux/buffer_head.h>
2805  #include <linux/random.h>
2806 +#include <linux/vs_tag.h>
2807  #include "ext2.h"
2808  #include "xattr.h"
2809  #include "acl.h"
2810 @@ -548,6 +549,7 @@ got:
2811                 inode->i_mode = mode;
2812                 inode->i_uid = current_fsuid();
2813                 inode->i_gid = dir->i_gid;
2814 +               inode->i_tag = dx_current_fstag(sb);
2815         } else
2816                 inode_init_owner(inode, dir, mode);
2817  
2818 diff -NurpP --minimal linux-2.6.38.1/fs/ext2/inode.c linux-2.6.38.1-vs2.3.0.37-rc9/fs/ext2/inode.c
2819 --- linux-2.6.38.1/fs/ext2/inode.c      2011-01-05 21:50:22.000000000 +0100
2820 +++ linux-2.6.38.1-vs2.3.0.37-rc9/fs/ext2/inode.c       2011-01-29 02:01:07.000000000 +0100
2821 @@ -32,6 +32,7 @@
2822  #include <linux/mpage.h>
2823  #include <linux/fiemap.h>
2824  #include <linux/namei.h>
2825 +#include <linux/vs_tag.h>
2826  #include "ext2.h"
2827  #include "acl.h"
2828  #include "xip.h"
2829 @@ -1169,7 +1170,7 @@ static void ext2_truncate_blocks(struct 
2830                 return;
2831         if (ext2_inode_is_fast_symlink(inode))
2832                 return;
2833 -       if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
2834 +       if (IS_APPEND(inode) || IS_IXORUNLINK(inode))
2835                 return;
2836         __ext2_truncate_blocks(inode, offset);
2837  }
2838 @@ -1258,36 +1259,61 @@ void ext2_set_inode_flags(struct inode *
2839  {
2840         unsigned int flags = EXT2_I(inode)->i_flags;
2841  
2842 -       inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
2843 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
2844 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
2845 +
2846 +
2847 +       if (flags & EXT2_IMMUTABLE_FL)
2848 +               inode->i_flags |= S_IMMUTABLE;
2849 +       if (flags & EXT2_IXUNLINK_FL)
2850 +               inode->i_flags |= S_IXUNLINK;
2851 +
2852         if (flags & EXT2_SYNC_FL)
2853                 inode->i_flags |= S_SYNC;
2854         if (flags & EXT2_APPEND_FL)
2855                 inode->i_flags |= S_APPEND;
2856 -       if (flags & EXT2_IMMUTABLE_FL)
2857 -               inode->i_flags |= S_IMMUTABLE;
2858         if (flags & EXT2_NOATIME_FL)
2859                 inode->i_flags |= S_NOATIME;
2860         if (flags & EXT2_DIRSYNC_FL)
2861                 inode->i_flags |= S_DIRSYNC;
2862 +
2863 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
2864 +
2865 +       if (flags & EXT2_BARRIER_FL)
2866 +               inode->i_vflags |= V_BARRIER;
2867 +       if (flags & EXT2_COW_FL)
2868 +               inode->i_vflags |= V_COW;
2869  }
2870  
2871  /* Propagate flags from i_flags to EXT2_I(inode)->i_flags */
2872  void ext2_get_inode_flags(struct ext2_inode_info *ei)
2873  {
2874         unsigned int flags = ei->vfs_inode.i_flags;
2875 +       unsigned int vflags = ei->vfs_inode.i_vflags;
2876 +
2877 +       ei->i_flags &= ~(EXT2_SYNC_FL | EXT2_APPEND_FL |
2878 +                       EXT2_IMMUTABLE_FL | EXT2_IXUNLINK_FL |
2879 +                       EXT2_NOATIME_FL | EXT2_DIRSYNC_FL |
2880 +                       EXT2_BARRIER_FL | EXT2_COW_FL);
2881 +
2882 +       if (flags & S_IMMUTABLE)
2883 +               ei->i_flags |= EXT2_IMMUTABLE_FL;
2884 +       if (flags & S_IXUNLINK)
2885 +               ei->i_flags |= EXT2_IXUNLINK_FL;
2886  
2887 -       ei->i_flags &= ~(EXT2_SYNC_FL|EXT2_APPEND_FL|
2888 -                       EXT2_IMMUTABLE_FL|EXT2_NOATIME_FL|EXT2_DIRSYNC_FL);
2889         if (flags & S_SYNC)
2890                 ei->i_flags |= EXT2_SYNC_FL;
2891         if (flags & S_APPEND)
2892                 ei->i_flags |= EXT2_APPEND_FL;
2893 -       if (flags & S_IMMUTABLE)
2894 -               ei->i_flags |= EXT2_IMMUTABLE_FL;
2895         if (flags & S_NOATIME)
2896                 ei->i_flags |= EXT2_NOATIME_FL;
2897         if (flags & S_DIRSYNC)
2898                 ei->i_flags |= EXT2_DIRSYNC_FL;
2899 +
2900 +       if (vflags & V_BARRIER)
2901 +               ei->i_flags |= EXT2_BARRIER_FL;
2902 +       if (vflags & V_COW)
2903 +               ei->i_flags |= EXT2_COW_FL;
2904  }
2905  
2906  struct inode *ext2_iget (struct super_block *sb, unsigned long ino)
2907 @@ -1297,6 +1323,8 @@ struct inode *ext2_iget (struct super_bl
2908         struct ext2_inode *raw_inode;
2909         struct inode *inode;
2910         long ret = -EIO;
2911 +       uid_t uid;
2912 +       gid_t gid;
2913         int n;
2914  
2915         inode = iget_locked(sb, ino);
2916 @@ -1315,12 +1343,17 @@ struct inode *ext2_iget (struct super_bl
2917         }
2918  
2919         inode->i_mode = le16_to_cpu(raw_inode->i_mode);
2920 -       inode->i_uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
2921 -       inode->i_gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
2922 +       uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
2923 +       gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
2924         if (!(test_opt (inode->i_sb, NO_UID32))) {
2925 -               inode->i_uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
2926 -               inode->i_gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
2927 +               uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
2928 +               gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
2929         }
2930 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
2931 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
2932 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid,
2933 +               le16_to_cpu(raw_inode->i_raw_tag));
2934 +
2935         inode->i_nlink = le16_to_cpu(raw_inode->i_links_count);
2936         inode->i_size = le32_to_cpu(raw_inode->i_size);
2937         inode->i_atime.tv_sec = (signed)le32_to_cpu(raw_inode->i_atime);
2938 @@ -1418,8 +1451,8 @@ static int __ext2_write_inode(struct ino
2939         struct ext2_inode_info *ei = EXT2_I(inode);
2940         struct super_block *sb = inode->i_sb;
2941         ino_t ino = inode->i_ino;
2942 -       uid_t uid = inode->i_uid;
2943 -       gid_t gid = inode->i_gid;
2944 +       uid_t uid = TAGINO_UID(DX_TAG(inode), inode->i_uid, inode->i_tag);
2945 +       gid_t gid = TAGINO_GID(DX_TAG(inode), inode->i_gid, inode->i_tag);
2946         struct buffer_head * bh;
2947         struct ext2_inode * raw_inode = ext2_get_inode(sb, ino, &bh);
2948         int n;
2949 @@ -1455,6 +1488,9 @@ static int __ext2_write_inode(struct ino
2950                 raw_inode->i_uid_high = 0;
2951                 raw_inode->i_gid_high = 0;
2952         }
2953 +#ifdef CONFIG_TAGGING_INTERN
2954 +       raw_inode->i_raw_tag = cpu_to_le16(inode->i_tag);
2955 +#endif
2956         raw_inode->i_links_count = cpu_to_le16(inode->i_nlink);
2957         raw_inode->i_size = cpu_to_le32(inode->i_size);
2958         raw_inode->i_atime = cpu_to_le32(inode->i_atime.tv_sec);
2959 @@ -1535,7 +1571,8 @@ int ext2_setattr(struct dentry *dentry, 
2960         if (is_quota_modification(inode, iattr))
2961                 dquot_initialize(inode);
2962         if ((iattr->ia_valid & ATTR_UID && iattr->ia_uid != inode->i_uid) ||
2963 -           (iattr->ia_valid & ATTR_GID && iattr->ia_gid != inode->i_gid)) {
2964 +           (iattr->ia_valid & ATTR_GID && iattr->ia_gid != inode->i_gid) ||
2965 +           (iattr->ia_valid & ATTR_TAG && iattr->ia_tag != inode->i_tag)) {
2966                 error = dquot_transfer(inode, iattr);
2967                 if (error)
2968                         return error;
2969 diff -NurpP --minimal linux-2.6.38.1/fs/ext2/ioctl.c linux-2.6.38.1-vs2.3.0.37-rc9/fs/ext2/ioctl.c
2970 --- linux-2.6.38.1/fs/ext2/ioctl.c      2009-09-10 15:26:21.000000000 +0200
2971 +++ linux-2.6.38.1-vs2.3.0.37-rc9/fs/ext2/ioctl.c       2011-01-29 02:01:07.000000000 +0100
2972 @@ -17,6 +17,16 @@
2973  #include <asm/uaccess.h>
2974  
2975  
2976 +int ext2_sync_flags(struct inode *inode, int flags, int vflags)
2977 +{
2978 +       inode->i_flags = flags;
2979 +       inode->i_vflags = vflags;
2980 +       ext2_get_inode_flags(EXT2_I(inode));
2981 +       inode->i_ctime = CURRENT_TIME_SEC;
2982 +       mark_inode_dirty(inode);
2983 +       return 0;
2984 +}
2985 +
2986  long ext2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
2987  {
2988         struct inode *inode = filp->f_dentry->d_inode;
2989 @@ -51,6 +61,11 @@ long ext2_ioctl(struct file *filp, unsig
2990  
2991                 flags = ext2_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                 /* Is it quota file? Do not allow user to mess with it */
3000                 if (IS_NOQUOTA(inode)) {
3001 @@ -66,7 +81,9 @@ long ext2_ioctl(struct file *filp, unsig
3002                  *
3003                  * This test looks nicer. Thanks to Pauline Middelink
3004                  */
3005 -               if ((flags ^ oldflags) & (EXT2_APPEND_FL | EXT2_IMMUTABLE_FL)) {
3006 +               if ((oldflags & EXT2_IMMUTABLE_FL) ||
3007 +                       ((flags ^ oldflags) & (EXT2_APPEND_FL |
3008 +                       EXT2_IMMUTABLE_FL | EXT2_IXUNLINK_FL))) {
3009                         if (!capable(CAP_LINUX_IMMUTABLE)) {
3010                                 mutex_unlock(&inode->i_mutex);
3011                                 ret = -EPERM;
3012 @@ -74,7 +91,7 @@ long ext2_ioctl(struct file *filp, unsig
3013                         }
3014                 }
3015  
3016 -               flags = flags & EXT2_FL_USER_MODIFIABLE;
3017 +               flags &= EXT2_FL_USER_MODIFIABLE;
3018                 flags |= oldflags & ~EXT2_FL_USER_MODIFIABLE;
3019                 ei->i_flags = flags;
3020                 mutex_unlock(&inode->i_mutex);
3021 diff -NurpP --minimal linux-2.6.38.1/fs/ext2/namei.c linux-2.6.38.1-vs2.3.0.37-rc9/fs/ext2/namei.c
3022 --- linux-2.6.38.1/fs/ext2/namei.c      2011-03-15 18:07:31.000000000 +0100
3023 +++ linux-2.6.38.1-vs2.3.0.37-rc9/fs/ext2/namei.c       2011-03-10 17:21:19.000000000 +0100
3024 @@ -32,6 +32,7 @@
3025  
3026  #include <linux/pagemap.h>
3027  #include <linux/quotaops.h>
3028 +#include <linux/vs_tag.h>
3029  #include "ext2.h"
3030  #include "xattr.h"
3031  #include "acl.h"
3032 @@ -75,6 +76,7 @@ static struct dentry *ext2_lookup(struct
3033                                 return ERR_PTR(-EIO);
3034                         } else {
3035                                 return ERR_CAST(inode);
3036 +               dx_propagate_tag(nd, inode);
3037                         }
3038                 }
3039         }
3040 @@ -413,6 +415,7 @@ const struct inode_operations ext2_dir_i
3041  #endif
3042         .setattr        = ext2_setattr,
3043         .check_acl      = ext2_check_acl,
3044 +       .sync_flags     = ext2_sync_flags,
3045  };
3046  
3047  const struct inode_operations ext2_special_inode_operations = {
3048 diff -NurpP --minimal linux-2.6.38.1/fs/ext2/super.c linux-2.6.38.1-vs2.3.0.37-rc9/fs/ext2/super.c
3049 --- linux-2.6.38.1/fs/ext2/super.c      2011-03-15 18:07:31.000000000 +0100
3050 +++ linux-2.6.38.1-vs2.3.0.37-rc9/fs/ext2/super.c       2011-01-29 02:01:07.000000000 +0100
3051 @@ -394,7 +394,8 @@ enum {
3052         Opt_err_ro, Opt_nouid32, Opt_nocheck, Opt_debug,
3053         Opt_oldalloc, Opt_orlov, Opt_nobh, Opt_user_xattr, Opt_nouser_xattr,
3054         Opt_acl, Opt_noacl, Opt_xip, Opt_ignore, Opt_err, Opt_quota,
3055 -       Opt_usrquota, Opt_grpquota, Opt_reservation, Opt_noreservation
3056 +       Opt_usrquota, Opt_grpquota, Opt_reservation, Opt_noreservation,
3057 +       Opt_tag, Opt_notag, Opt_tagid
3058  };
3059  
3060  static const match_table_t tokens = {
3061 @@ -422,6 +423,9 @@ static const match_table_t tokens = {
3062         {Opt_acl, "acl"},
3063         {Opt_noacl, "noacl"},
3064         {Opt_xip, "xip"},
3065 +       {Opt_tag, "tag"},
3066 +       {Opt_notag, "notag"},
3067 +       {Opt_tagid, "tagid=%u"},
3068         {Opt_grpquota, "grpquota"},
3069         {Opt_ignore, "noquota"},
3070         {Opt_quota, "quota"},
3071 @@ -492,6 +496,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 @@ -850,6 +868,8 @@ static int ext2_fill_super(struct super_
3093         if (!parse_options((char *) data, sb))
3094                 goto failed_mount;
3095  
3096 +       if (EXT2_SB(sb)->s_mount_opt & EXT2_MOUNT_TAGGED)
3097 +               sb->s_flags |= MS_TAGGED;
3098         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
3099                 ((EXT2_SB(sb)->s_mount_opt & EXT2_MOUNT_POSIX_ACL) ?
3100                  MS_POSIXACL : 0);
3101 @@ -1223,6 +1243,14 @@ static int ext2_remount (struct super_bl
3102                 goto restore_opts;
3103         }
3104  
3105 +       if ((sbi->s_mount_opt & EXT2_MOUNT_TAGGED) &&
3106 +               !(sb->s_flags & MS_TAGGED)) {
3107 +               printk("EXT2-fs: %s: tagging not permitted on remount.\n",
3108 +                      sb->s_id);
3109 +               err = -EINVAL;
3110 +               goto restore_opts;
3111 +       }
3112 +
3113         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
3114                 ((sbi->s_mount_opt & EXT2_MOUNT_POSIX_ACL) ? MS_POSIXACL : 0);
3115  
3116 diff -NurpP --minimal linux-2.6.38.1/fs/ext3/file.c linux-2.6.38.1-vs2.3.0.37-rc9/fs/ext3/file.c
3117 --- linux-2.6.38.1/fs/ext3/file.c       2010-07-07 18:31:51.000000000 +0200
3118 +++ linux-2.6.38.1-vs2.3.0.37-rc9/fs/ext3/file.c        2011-01-29 02:01:07.000000000 +0100
3119 @@ -81,5 +81,6 @@ const struct inode_operations ext3_file_
3120  #endif
3121         .check_acl      = ext3_check_acl,
3122         .fiemap         = ext3_fiemap,
3123 +       .sync_flags     = ext3_sync_flags,
3124  };
3125  
3126 diff -NurpP --minimal linux-2.6.38.1/fs/ext3/ialloc.c linux-2.6.38.1-vs2.3.0.37-rc9/fs/ext3/ialloc.c
3127 --- linux-2.6.38.1/fs/ext3/ialloc.c     2011-01-05 21:50:22.000000000 +0100
3128 +++ linux-2.6.38.1-vs2.3.0.37-rc9/fs/ext3/ialloc.c      2011-01-29 02:01:07.000000000 +0100
3129 @@ -23,6 +23,7 @@
3130  #include <linux/buffer_head.h>
3131  #include <linux/random.h>
3132  #include <linux/bitops.h>
3133 +#include <linux/vs_tag.h>
3134  
3135  #include <asm/byteorder.h>
3136  
3137 @@ -531,6 +532,7 @@ got:
3138                 inode->i_mode = mode;
3139                 inode->i_uid = current_fsuid();
3140                 inode->i_gid = dir->i_gid;
3141 +               inode->i_tag = dx_current_fstag(sb);
3142         } else
3143                 inode_init_owner(inode, dir, mode);
3144  
3145 diff -NurpP --minimal linux-2.6.38.1/fs/ext3/inode.c linux-2.6.38.1-vs2.3.0.37-rc9/fs/ext3/inode.c
3146 --- linux-2.6.38.1/fs/ext3/inode.c      2011-03-15 18:07:31.000000000 +0100
3147 +++ linux-2.6.38.1-vs2.3.0.37-rc9/fs/ext3/inode.c       2011-01-29 02:01:07.000000000 +0100
3148 @@ -38,6 +38,7 @@
3149  #include <linux/bio.h>
3150  #include <linux/fiemap.h>
3151  #include <linux/namei.h>
3152 +#include <linux/vs_tag.h>
3153  #include "xattr.h"
3154  #include "acl.h"
3155  
3156 @@ -2394,7 +2395,7 @@ static void ext3_free_branches(handle_t 
3157  
3158  int ext3_can_truncate(struct inode *inode)
3159  {
3160 -       if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
3161 +       if (IS_APPEND(inode) || IS_IXORUNLINK(inode))
3162                 return 0;
3163         if (S_ISREG(inode->i_mode))
3164                 return 1;
3165 @@ -2778,36 +2779,60 @@ void ext3_set_inode_flags(struct inode *
3166  {
3167         unsigned int flags = EXT3_I(inode)->i_flags;
3168  
3169 -       inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
3170 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
3171 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
3172 +
3173 +       if (flags & EXT3_IMMUTABLE_FL)
3174 +               inode->i_flags |= S_IMMUTABLE;
3175 +       if (flags & EXT3_IXUNLINK_FL)
3176 +               inode->i_flags |= S_IXUNLINK;
3177 +
3178         if (flags & EXT3_SYNC_FL)
3179                 inode->i_flags |= S_SYNC;
3180         if (flags & EXT3_APPEND_FL)
3181                 inode->i_flags |= S_APPEND;
3182 -       if (flags & EXT3_IMMUTABLE_FL)
3183 -               inode->i_flags |= S_IMMUTABLE;
3184         if (flags & EXT3_NOATIME_FL)
3185                 inode->i_flags |= S_NOATIME;
3186         if (flags & EXT3_DIRSYNC_FL)
3187                 inode->i_flags |= S_DIRSYNC;
3188 +
3189 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
3190 +
3191 +       if (flags & EXT3_BARRIER_FL)
3192 +               inode->i_vflags |= V_BARRIER;
3193 +       if (flags & EXT3_COW_FL)
3194 +               inode->i_vflags |= V_COW;
3195  }
3196  
3197  /* Propagate flags from i_flags to EXT3_I(inode)->i_flags */
3198  void ext3_get_inode_flags(struct ext3_inode_info *ei)
3199  {
3200         unsigned int flags = ei->vfs_inode.i_flags;
3201 +       unsigned int vflags = ei->vfs_inode.i_vflags;
3202 +
3203 +       ei->i_flags &= ~(EXT3_SYNC_FL | EXT3_APPEND_FL |
3204 +                       EXT3_IMMUTABLE_FL | EXT3_IXUNLINK_FL |
3205 +                       EXT3_NOATIME_FL | EXT3_DIRSYNC_FL |
3206 +                       EXT3_BARRIER_FL | EXT3_COW_FL);
3207 +
3208 +       if (flags & S_IMMUTABLE)
3209 +               ei->i_flags |= EXT3_IMMUTABLE_FL;
3210 +       if (flags & S_IXUNLINK)
3211 +               ei->i_flags |= EXT3_IXUNLINK_FL;
3212  
3213 -       ei->i_flags &= ~(EXT3_SYNC_FL|EXT3_APPEND_FL|
3214 -                       EXT3_IMMUTABLE_FL|EXT3_NOATIME_FL|EXT3_DIRSYNC_FL);
3215         if (flags & S_SYNC)
3216                 ei->i_flags |= EXT3_SYNC_FL;
3217         if (flags & S_APPEND)
3218                 ei->i_flags |= EXT3_APPEND_FL;
3219 -       if (flags & S_IMMUTABLE)
3220 -               ei->i_flags |= EXT3_IMMUTABLE_FL;
3221         if (flags & S_NOATIME)
3222                 ei->i_flags |= EXT3_NOATIME_FL;
3223         if (flags & S_DIRSYNC)
3224                 ei->i_flags |= EXT3_DIRSYNC_FL;
3225 +
3226 +       if (vflags & V_BARRIER)
3227 +               ei->i_flags |= EXT3_BARRIER_FL;
3228 +       if (vflags & V_COW)
3229 +               ei->i_flags |= EXT3_COW_FL;
3230  }
3231  
3232  struct inode *ext3_iget(struct super_block *sb, unsigned long ino)
3233 @@ -2821,6 +2846,8 @@ struct inode *ext3_iget(struct super_blo
3234         transaction_t *transaction;
3235         long ret;
3236         int block;
3237 +       uid_t uid;
3238 +       gid_t gid;
3239  
3240         inode = iget_locked(sb, ino);
3241         if (!inode)
3242 @@ -2837,12 +2864,17 @@ struct inode *ext3_iget(struct super_blo
3243         bh = iloc.bh;
3244         raw_inode = ext3_raw_inode(&iloc);
3245         inode->i_mode = le16_to_cpu(raw_inode->i_mode);
3246 -       inode->i_uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
3247 -       inode->i_gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
3248 +       uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
3249 +       gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
3250         if(!(test_opt (inode->i_sb, NO_UID32))) {
3251 -               inode->i_uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
3252 -               inode->i_gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
3253 +               uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
3254 +               gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
3255         }
3256 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
3257 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
3258 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid,
3259 +               le16_to_cpu(raw_inode->i_raw_tag));
3260 +
3261         inode->i_nlink = le16_to_cpu(raw_inode->i_links_count);
3262         inode->i_size = le32_to_cpu(raw_inode->i_size);
3263         inode->i_atime.tv_sec = (signed)le32_to_cpu(raw_inode->i_atime);
3264 @@ -2997,6 +3029,8 @@ static int ext3_do_update_inode(handle_t
3265         struct ext3_inode *raw_inode = ext3_raw_inode(iloc);
3266         struct ext3_inode_info *ei = EXT3_I(inode);
3267         struct buffer_head *bh = iloc->bh;
3268 +       uid_t uid = TAGINO_UID(DX_TAG(inode), inode->i_uid, inode->i_tag);
3269 +       gid_t gid = TAGINO_GID(DX_TAG(inode), inode->i_gid, inode->i_tag);
3270         int err = 0, rc, block;
3271  
3272  again:
3273 @@ -3011,29 +3045,32 @@ again:
3274         ext3_get_inode_flags(ei);
3275         raw_inode->i_mode = cpu_to_le16(inode->i_mode);
3276         if(!(test_opt(inode->i_sb, NO_UID32))) {
3277 -               raw_inode->i_uid_low = cpu_to_le16(low_16_bits(inode->i_uid));
3278 -               raw_inode->i_gid_low = cpu_to_le16(low_16_bits(inode->i_gid));
3279 +               raw_inode->i_uid_low = cpu_to_le16(low_16_bits(uid));
3280 +               raw_inode->i_gid_low = cpu_to_le16(low_16_bits(gid));
3281  /*
3282   * Fix up interoperability with old kernels. Otherwise, old inodes get
3283   * re-used with the upper 16 bits of the uid/gid intact
3284   */
3285                 if(!ei->i_dtime) {
3286                         raw_inode->i_uid_high =
3287 -                               cpu_to_le16(high_16_bits(inode->i_uid));
3288 +                               cpu_to_le16(high_16_bits(uid));
3289                         raw_inode->i_gid_high =
3290 -                               cpu_to_le16(high_16_bits(inode->i_gid));
3291 +                               cpu_to_le16(high_16_bits(gid));
3292                 } else {
3293                         raw_inode->i_uid_high = 0;
3294                         raw_inode->i_gid_high = 0;
3295                 }
3296         } else {
3297                 raw_inode->i_uid_low =
3298 -                       cpu_to_le16(fs_high2lowuid(inode->i_uid));
3299 +                       cpu_to_le16(fs_high2lowuid(uid));
3300                 raw_inode->i_gid_low =
3301 -                       cpu_to_le16(fs_high2lowgid(inode->i_gid));
3302 +                       cpu_to_le16(fs_high2lowgid(gid));
3303                 raw_inode->i_uid_high = 0;
3304                 raw_inode->i_gid_high = 0;
3305         }
3306 +#ifdef CONFIG_TAGGING_INTERN
3307 +       raw_inode->i_raw_tag = cpu_to_le16(inode->i_tag);
3308 +#endif
3309         raw_inode->i_links_count = cpu_to_le16(inode->i_nlink);
3310         raw_inode->i_size = cpu_to_le32(ei->i_disksize);
3311         raw_inode->i_atime = cpu_to_le32(inode->i_atime.tv_sec);
3312 @@ -3193,7 +3230,8 @@ int ext3_setattr(struct dentry *dentry, 
3313         if (is_quota_modification(inode, attr))
3314                 dquot_initialize(inode);
3315         if ((ia_valid & ATTR_UID && attr->ia_uid != inode->i_uid) ||
3316 -               (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid)) {
3317 +               (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid) ||
3318 +               (ia_valid & ATTR_TAG && attr->ia_tag != inode->i_tag)) {
3319                 handle_t *handle;
3320  
3321                 /* (user+group)*(old+new) structure, inode write (sb,
3322 @@ -3215,6 +3253,8 @@ int ext3_setattr(struct dentry *dentry, 
3323                         inode->i_uid = attr->ia_uid;
3324                 if (attr->ia_valid & ATTR_GID)
3325                         inode->i_gid = attr->ia_gid;
3326 +               if ((attr->ia_valid & ATTR_TAG) && IS_TAGGED(inode))
3327 +                       inode->i_tag = attr->ia_tag;
3328                 error = ext3_mark_inode_dirty(handle, inode);
3329                 ext3_journal_stop(handle);
3330         }
3331 diff -NurpP --minimal linux-2.6.38.1/fs/ext3/ioctl.c linux-2.6.38.1-vs2.3.0.37-rc9/fs/ext3/ioctl.c
3332 --- linux-2.6.38.1/fs/ext3/ioctl.c      2011-03-15 18:07:31.000000000 +0100
3333 +++ linux-2.6.38.1-vs2.3.0.37-rc9/fs/ext3/ioctl.c       2011-01-29 02:01:07.000000000 +0100
3334 @@ -8,6 +8,7 @@
3335   */
3336  
3337  #include <linux/fs.h>
3338 +#include <linux/mount.h>
3339  #include <linux/jbd.h>
3340  #include <linux/capability.h>
3341  #include <linux/ext3_fs.h>
3342 @@ -17,6 +18,34 @@
3343  #include <linux/compat.h>
3344  #include <asm/uaccess.h>
3345  
3346 +
3347 +int ext3_sync_flags(struct inode *inode, int flags, int vflags)
3348 +{
3349 +       handle_t *handle = NULL;
3350 +       struct ext3_iloc iloc;
3351 +       int err;
3352 +
3353 +       handle = ext3_journal_start(inode, 1);
3354 +       if (IS_ERR(handle))
3355 +               return PTR_ERR(handle);
3356 +
3357 +       if (IS_SYNC(inode))
3358 +               handle->h_sync = 1;
3359 +       err = ext3_reserve_inode_write(handle, inode, &iloc);
3360 +       if (err)
3361 +               goto flags_err;
3362 +
3363 +       inode->i_flags = flags;
3364 +       inode->i_vflags = vflags;
3365 +       ext3_get_inode_flags(EXT3_I(inode));
3366 +       inode->i_ctime = CURRENT_TIME_SEC;
3367 +
3368 +       err = ext3_mark_iloc_dirty(handle, inode, &iloc);
3369 +flags_err:
3370 +       ext3_journal_stop(handle);
3371 +       return err;
3372 +}
3373 +
3374  long ext3_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
3375  {
3376         struct inode *inode = filp->f_dentry->d_inode;
3377 @@ -50,6 +79,11 @@ long ext3_ioctl(struct file *filp, unsig
3378  
3379                 flags = ext3_mask_flags(inode->i_mode, flags);
3380  
3381 +               if (IS_BARRIER(inode)) {
3382 +                       vxwprintk_task(1, "messing with the barrier.");
3383 +                       return -EACCES;
3384 +               }
3385 +
3386                 mutex_lock(&inode->i_mutex);
3387  
3388                 /* Is it quota file? Do not allow user to mess with it */
3389 @@ -68,7 +102,9 @@ long ext3_ioctl(struct file *filp, unsig
3390                  *
3391                  * This test looks nicer. Thanks to Pauline Middelink
3392                  */
3393 -               if ((flags ^ oldflags) & (EXT3_APPEND_FL | EXT3_IMMUTABLE_FL)) {
3394 +               if ((oldflags & EXT3_IMMUTABLE_FL) ||
3395 +                       ((flags ^ oldflags) & (EXT3_APPEND_FL |
3396 +                       EXT3_IMMUTABLE_FL | EXT3_IXUNLINK_FL))) {
3397                         if (!capable(CAP_LINUX_IMMUTABLE))
3398                                 goto flags_out;
3399                 }
3400 @@ -93,7 +129,7 @@ long ext3_ioctl(struct file *filp, unsig
3401                 if (err)
3402                         goto flags_err;
3403  
3404 -               flags = flags & EXT3_FL_USER_MODIFIABLE;
3405 +               flags &= EXT3_FL_USER_MODIFIABLE;
3406                 flags |= oldflags & ~EXT3_FL_USER_MODIFIABLE;
3407                 ei->i_flags = flags;
3408  
3409 diff -NurpP --minimal linux-2.6.38.1/fs/ext3/namei.c linux-2.6.38.1-vs2.3.0.37-rc9/fs/ext3/namei.c
3410 --- linux-2.6.38.1/fs/ext3/namei.c      2011-03-26 01:10:17.000000000 +0100
3411 +++ linux-2.6.38.1-vs2.3.0.37-rc9/fs/ext3/namei.c       2011-03-25 22:52:15.000000000 +0100
3412 @@ -36,6 +36,7 @@
3413  #include <linux/quotaops.h>
3414  #include <linux/buffer_head.h>
3415  #include <linux/bio.h>
3416 +#include <linux/vs_tag.h>
3417  
3418  #include "namei.h"
3419  #include "xattr.h"
3420 @@ -923,6 +924,7 @@ restart:
3421                                 if (bh)
3422                                         ll_rw_block(READ_META, 1, &bh);
3423                         }
3424 +               dx_propagate_tag(nd, inode);
3425                 }
3426                 if ((bh = bh_use[ra_ptr++]) == NULL)
3427                         goto next;
3428 @@ -2487,6 +2489,7 @@ const struct inode_operations ext3_dir_i
3429         .removexattr    = generic_removexattr,
3430  #endif
3431         .check_acl      = ext3_check_acl,
3432 +       .sync_flags     = ext3_sync_flags,
3433  };
3434  
3435  const struct inode_operations ext3_special_inode_operations = {
3436 diff -NurpP --minimal linux-2.6.38.1/fs/ext3/super.c linux-2.6.38.1-vs2.3.0.37-rc9/fs/ext3/super.c
3437 --- linux-2.6.38.1/fs/ext3/super.c      2011-03-15 18:07:31.000000000 +0100
3438 +++ linux-2.6.38.1-vs2.3.0.37-rc9/fs/ext3/super.c       2011-01-29 02:01:07.000000000 +0100
3439 @@ -820,7 +820,8 @@ enum {
3440         Opt_usrjquota, Opt_grpjquota, Opt_offusrjquota, Opt_offgrpjquota,
3441         Opt_jqfmt_vfsold, Opt_jqfmt_vfsv0, Opt_jqfmt_vfsv1, Opt_quota,
3442         Opt_noquota, Opt_ignore, Opt_barrier, Opt_nobarrier, Opt_err,
3443 -       Opt_resize, Opt_usrquota, Opt_grpquota
3444 +       Opt_resize, Opt_usrquota, Opt_grpquota,
3445 +       Opt_tag, Opt_notag, Opt_tagid
3446  };
3447  
3448  static const match_table_t tokens = {
3449 @@ -877,6 +878,9 @@ static const match_table_t tokens = {
3450         {Opt_barrier, "barrier"},
3451         {Opt_nobarrier, "nobarrier"},
3452         {Opt_resize, "resize"},
3453 +       {Opt_tag, "tag"},
3454 +       {Opt_notag, "notag"},
3455 +       {Opt_tagid, "tagid=%u"},
3456         {Opt_err, NULL},
3457  };
3458  
3459 @@ -1029,6 +1033,20 @@ static int parse_options (char *options,
3460                 case Opt_nouid32:
3461                         set_opt (sbi->s_mount_opt, NO_UID32);
3462                         break;
3463 +#ifndef CONFIG_TAGGING_NONE
3464 +               case Opt_tag:
3465 +                       set_opt (sbi->s_mount_opt, TAGGED);
3466 +                       break;
3467 +               case Opt_notag:
3468 +                       clear_opt (sbi->s_mount_opt, TAGGED);
3469 +                       break;
3470 +#endif
3471 +#ifdef CONFIG_PROPAGATE
3472 +               case Opt_tagid:
3473 +                       /* use args[0] */
3474 +                       set_opt (sbi->s_mount_opt, TAGGED);
3475 +                       break;
3476 +#endif
3477                 case Opt_nocheck:
3478                         clear_opt (sbi->s_mount_opt, CHECK);
3479                         break;
3480 @@ -1715,6 +1733,9 @@ static int ext3_fill_super (struct super
3481                             NULL, 0))
3482                 goto failed_mount;
3483  
3484 +       if (EXT3_SB(sb)->s_mount_opt & EXT3_MOUNT_TAGGED)
3485 +               sb->s_flags |= MS_TAGGED;
3486 +
3487         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
3488                 (test_opt(sb, POSIX_ACL) ? MS_POSIXACL : 0);
3489  
3490 @@ -2594,6 +2615,14 @@ static int ext3_remount (struct super_bl
3491         if (test_opt(sb, ABORT))
3492                 ext3_abort(sb, __func__, "Abort forced by user");
3493  
3494 +       if ((sbi->s_mount_opt & EXT3_MOUNT_TAGGED) &&
3495 +               !(sb->s_flags & MS_TAGGED)) {
3496 +               printk("EXT3-fs: %s: tagging not permitted on remount.\n",
3497 +                       sb->s_id);
3498 +               err = -EINVAL;
3499 +               goto restore_opts;
3500 +       }
3501 +
3502         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
3503                 (test_opt(sb, POSIX_ACL) ? MS_POSIXACL : 0);
3504  
3505 diff -NurpP --minimal linux-2.6.38.1/fs/ext4/ext4.h linux-2.6.38.1-vs2.3.0.37-rc9/fs/ext4/ext4.h
3506 --- linux-2.6.38.1/fs/ext4/ext4.h       2011-03-15 18:07:31.000000000 +0100
3507 +++ linux-2.6.38.1-vs2.3.0.37-rc9/fs/ext4/ext4.h        2011-02-17 02:17:50.000000000 +0100
3508 @@ -347,8 +347,12 @@ struct flex_groups {
3509  #define EXT4_EXTENTS_FL                        0x00080000 /* Inode uses extents */
3510  #define EXT4_EA_INODE_FL               0x00200000 /* Inode used for large EA */
3511  #define EXT4_EOFBLOCKS_FL              0x00400000 /* Blocks allocated beyond EOF */
3512 +#define EXT4_IXUNLINK_FL               0x08000000 /* Immutable invert on unlink */
3513  #define EXT4_RESERVED_FL               0x80000000 /* reserved for ext4 lib */
3514  
3515 +#define EXT4_BARRIER_FL                        0x04000000 /* Barrier for chroot() */
3516 +#define EXT4_COW_FL                    0x20000000 /* Copy on Write marker */
3517 +
3518  #define EXT4_FL_USER_VISIBLE           0x004BDFFF /* User visible flags */
3519  #define EXT4_FL_USER_MODIFIABLE                0x004B80FF /* User modifiable flags */
3520  
3521 @@ -601,7 +605,8 @@ struct ext4_inode {
3522                         __le16  l_i_file_acl_high;
3523                         __le16  l_i_uid_high;   /* these 2 fields */
3524                         __le16  l_i_gid_high;   /* were reserved2[0] */
3525 -                       __u32   l_i_reserved2;
3526 +                       __le16  l_i_tag;        /* Context Tag */
3527 +                       __u16   l_i_reserved2;
3528                 } linux2;
3529                 struct {
3530                         __le16  h_i_reserved1;  /* Obsoleted fragment number/size which are removed in ext4 */
3531 @@ -719,6 +724,7 @@ do {                                                                               \
3532  #define i_gid_low      i_gid
3533  #define i_uid_high     osd2.linux2.l_i_uid_high
3534  #define i_gid_high     osd2.linux2.l_i_gid_high
3535 +#define i_raw_tag      osd2.linux2.l_i_tag
3536  #define i_reserved2    osd2.linux2.l_i_reserved2
3537  
3538  #elif defined(__GNU__)
3539 @@ -895,6 +901,7 @@ struct ext4_inode_info {
3540  #define EXT4_MOUNT_POSIX_ACL           0x08000 /* POSIX Access Control Lists */
3541  #define EXT4_MOUNT_NO_AUTO_DA_ALLOC    0x10000 /* No auto delalloc mapping */
3542  #define EXT4_MOUNT_BARRIER             0x20000 /* Use block barriers */
3543 +#define EXT4_MOUNT_TAGGED              0x40000 /* Enable Context Tags */
3544  #define EXT4_MOUNT_QUOTA               0x80000 /* Some quota option set */
3545  #define EXT4_MOUNT_USRQUOTA            0x100000 /* "old" user quota */
3546  #define EXT4_MOUNT_GRPQUOTA            0x200000 /* "old" group quota */
3547 @@ -2074,6 +2081,7 @@ extern int ext4_map_blocks(handle_t *han
3548                            struct ext4_map_blocks *map, int flags);
3549  extern int ext4_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
3550                         __u64 start, __u64 len);
3551 +extern int ext4_sync_flags(struct inode *, int, int);
3552  /* move_extent.c */
3553  extern int ext4_move_extents(struct file *o_filp, struct file *d_filp,
3554                              __u64 start_orig, __u64 start_donor,
3555 diff -NurpP --minimal linux-2.6.38.1/fs/ext4/file.c linux-2.6.38.1-vs2.3.0.37-rc9/fs/ext4/file.c
3556 --- linux-2.6.38.1/fs/ext4/file.c       2011-03-15 18:07:31.000000000 +0100
3557 +++ linux-2.6.38.1-vs2.3.0.37-rc9/fs/ext4/file.c        2011-02-17 02:17:50.000000000 +0100
3558 @@ -283,5 +283,6 @@ const struct inode_operations ext4_file_
3559  #endif
3560         .check_acl      = ext4_check_acl,
3561         .fiemap         = ext4_fiemap,
3562 +       .sync_flags     = ext4_sync_flags,
3563  };
3564  
3565 diff -NurpP --minimal linux-2.6.38.1/fs/ext4/ialloc.c linux-2.6.38.1-vs2.3.0.37-rc9/fs/ext4/ialloc.c
3566 --- linux-2.6.38.1/fs/ext4/ialloc.c     2011-03-15 18:07:31.000000000 +0100
3567 +++ linux-2.6.38.1-vs2.3.0.37-rc9/fs/ext4/ialloc.c      2011-01-29 02:01:07.000000000 +0100
3568 @@ -22,6 +22,7 @@
3569  #include <linux/random.h>
3570  #include <linux/bitops.h>
3571  #include <linux/blkdev.h>
3572 +#include <linux/vs_tag.h>
3573  #include <asm/byteorder.h>
3574  
3575  #include "ext4.h"
3576 @@ -991,6 +992,7 @@ got:
3577                 inode->i_mode = mode;
3578                 inode->i_uid = current_fsuid();
3579                 inode->i_gid = dir->i_gid;
3580 +               inode->i_tag = dx_current_fstag(sb);
3581         } else
3582                 inode_init_owner(inode, dir, mode);
3583  
3584 diff -NurpP --minimal linux-2.6.38.1/fs/ext4/inode.c linux-2.6.38.1-vs2.3.0.37-rc9/fs/ext4/inode.c
3585 --- linux-2.6.38.1/fs/ext4/inode.c      2011-03-15 18:07:31.000000000 +0100
3586 +++ linux-2.6.38.1-vs2.3.0.37-rc9/fs/ext4/inode.c       2011-01-29 02:27:03.000000000 +0100
3587 @@ -42,6 +42,7 @@
3588  #include <linux/printk.h>
3589  #include <linux/slab.h>
3590  #include <linux/ratelimit.h>
3591 +#include <linux/vs_tag.h>
3592  
3593  #include "ext4_jbd2.h"
3594  #include "xattr.h"
3595 @@ -4446,7 +4447,7 @@ static void ext4_free_branches(handle_t 
3596  
3597  int ext4_can_truncate(struct inode *inode)
3598  {
3599 -       if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
3600 +       if (IS_APPEND(inode) || IS_IXORUNLINK(inode))
3601                 return 0;
3602         if (S_ISREG(inode->i_mode))
3603                 return 1;
3604 @@ -4797,41 +4798,64 @@ void ext4_set_inode_flags(struct inode *
3605  {
3606         unsigned int flags = EXT4_I(inode)->i_flags;
3607  
3608 -       inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
3609 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
3610 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
3611 +
3612 +       if (flags & EXT4_IMMUTABLE_FL)
3613 +               inode->i_flags |= S_IMMUTABLE;
3614 +       if (flags & EXT4_IXUNLINK_FL)
3615 +               inode->i_flags |= S_IXUNLINK;
3616 +
3617         if (flags & EXT4_SYNC_FL)
3618                 inode->i_flags |= S_SYNC;
3619         if (flags & EXT4_APPEND_FL)
3620                 inode->i_flags |= S_APPEND;
3621 -       if (flags & EXT4_IMMUTABLE_FL)
3622 -               inode->i_flags |= S_IMMUTABLE;
3623         if (flags & EXT4_NOATIME_FL)
3624                 inode->i_flags |= S_NOATIME;
3625         if (flags & EXT4_DIRSYNC_FL)
3626                 inode->i_flags |= S_DIRSYNC;
3627 +
3628 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
3629 +
3630 +       if (flags & EXT4_BARRIER_FL)
3631 +               inode->i_vflags |= V_BARRIER;
3632 +       if (flags & EXT4_COW_FL)
3633 +               inode->i_vflags |= V_COW;
3634  }
3635  
3636  /* Propagate flags from i_flags to EXT4_I(inode)->i_flags */
3637  void ext4_get_inode_flags(struct ext4_inode_info *ei)
3638  {
3639 -       unsigned int vfs_fl;
3640 +       unsigned int vfs_fl, vfs_vf;
3641         unsigned long old_fl, new_fl;
3642  
3643         do {
3644                 vfs_fl = ei->vfs_inode.i_flags;
3645 +               vfs_vf = ei->vfs_inode.i_vflags;
3646                 old_fl = ei->i_flags;
3647                 new_fl = old_fl & ~(EXT4_SYNC_FL|EXT4_APPEND_FL|
3648                                 EXT4_IMMUTABLE_FL|EXT4_NOATIME_FL|
3649 -                               EXT4_DIRSYNC_FL);
3650 +                               EXT4_DIRSYNC_FL|EXT4_BARRIER_FL|
3651 +                               EXT4_COW_FL);
3652 +
3653 +               if (vfs_fl & S_IMMUTABLE)
3654 +                       new_fl |= EXT4_IMMUTABLE_FL;
3655 +               if (vfs_fl & S_IXUNLINK)
3656 +                       new_fl |= EXT4_IXUNLINK_FL;
3657 +
3658                 if (vfs_fl & S_SYNC)
3659                         new_fl |= EXT4_SYNC_FL;
3660                 if (vfs_fl & S_APPEND)
3661                         new_fl |= EXT4_APPEND_FL;
3662 -               if (vfs_fl & S_IMMUTABLE)
3663 -                       new_fl |= EXT4_IMMUTABLE_FL;
3664                 if (vfs_fl & S_NOATIME)
3665                         new_fl |= EXT4_NOATIME_FL;
3666                 if (vfs_fl & S_DIRSYNC)
3667                         new_fl |= EXT4_DIRSYNC_FL;
3668 +
3669 +               if (vfs_vf & V_BARRIER)
3670 +                       new_fl |= EXT4_BARRIER_FL;
3671 +               if (vfs_vf & V_COW)
3672 +                       new_fl |= EXT4_COW_FL;
3673         } while (cmpxchg(&ei->i_flags, old_fl, new_fl) != old_fl);
3674  }
3675  
3676 @@ -4867,6 +4891,8 @@ struct inode *ext4_iget(struct super_blo
3677         journal_t *journal = EXT4_SB(sb)->s_journal;
3678         long ret;
3679         int block;
3680 +       uid_t uid;
3681 +       gid_t gid;
3682  
3683         inode = iget_locked(sb, ino);
3684         if (!inode)
3685 @@ -4882,12 +4908,16 @@ struct inode *ext4_iget(struct super_blo
3686                 goto bad_inode;
3687         raw_inode = ext4_raw_inode(&iloc);
3688         inode->i_mode = le16_to_cpu(raw_inode->i_mode);
3689 -       inode->i_uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
3690 -       inode->i_gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
3691 +       uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
3692 +       gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
3693         if (!(test_opt(inode->i_sb, NO_UID32))) {
3694 -               inode->i_uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
3695 -               inode->i_gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
3696 +               uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
3697 +               gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
3698         }
3699 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
3700 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
3701 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid,
3702 +               le16_to_cpu(raw_inode->i_raw_tag));
3703         inode->i_nlink = le16_to_cpu(raw_inode->i_links_count);
3704  
3705         ext4_clear_state_flags(ei);     /* Only relevant on 32-bit archs */
3706 @@ -5106,6 +5136,8 @@ static int ext4_do_update_inode(handle_t
3707         struct ext4_inode *raw_inode = ext4_raw_inode(iloc);
3708         struct ext4_inode_info *ei = EXT4_I(inode);
3709         struct buffer_head *bh = iloc->bh;
3710 +       uid_t uid = TAGINO_UID(DX_TAG(inode), inode->i_uid, inode->i_tag);
3711 +       gid_t gid = TAGINO_GID(DX_TAG(inode), inode->i_gid, inode->i_tag);
3712         int err = 0, rc, block;
3713  
3714         /* For fields not not tracking in the in-memory inode,
3715 @@ -5116,29 +5148,32 @@ static int ext4_do_update_inode(handle_t
3716         ext4_get_inode_flags(ei);
3717         raw_inode->i_mode = cpu_to_le16(inode->i_mode);
3718         if (!(test_opt(inode->i_sb, NO_UID32))) {
3719 -               raw_inode->i_uid_low = cpu_to_le16(low_16_bits(inode->i_uid));
3720 -               raw_inode->i_gid_low = cpu_to_le16(low_16_bits(inode->i_gid));
3721 +               raw_inode->i_uid_low = cpu_to_le16(low_16_bits(uid));
3722 +               raw_inode->i_gid_low = cpu_to_le16(low_16_bits(gid));
3723  /*
3724   * Fix up interoperability with old kernels. Otherwise, old inodes get
3725   * re-used with the upper 16 bits of the uid/gid intact
3726   */
3727                 if (!ei->i_dtime) {
3728                         raw_inode->i_uid_high =
3729 -                               cpu_to_le16(high_16_bits(inode->i_uid));
3730 +                               cpu_to_le16(high_16_bits(uid));
3731                         raw_inode->i_gid_high =
3732 -                               cpu_to_le16(high_16_bits(inode->i_gid));
3733 +                               cpu_to_le16(high_16_bits(gid));
3734                 } else {
3735                         raw_inode->i_uid_high = 0;
3736                         raw_inode->i_gid_high = 0;
3737                 }
3738         } else {
3739                 raw_inode->i_uid_low =
3740 -                       cpu_to_le16(fs_high2lowuid(inode->i_uid));
3741 +                       cpu_to_le16(fs_high2lowuid(uid));
3742                 raw_inode->i_gid_low =
3743 -                       cpu_to_le16(fs_high2lowgid(inode->i_gid));
3744 +                       cpu_to_le16(fs_high2lowgid(gid));
3745                 raw_inode->i_uid_high = 0;
3746                 raw_inode->i_gid_high = 0;
3747         }
3748 +#ifdef CONFIG_TAGGING_INTERN
3749 +       raw_inode->i_raw_tag = cpu_to_le16(inode->i_tag);
3750 +#endif
3751         raw_inode->i_links_count = cpu_to_le16(inode->i_nlink);
3752  
3753         EXT4_INODE_SET_XTIME(i_ctime, inode, raw_inode);
3754 @@ -5324,7 +5359,8 @@ int ext4_setattr(struct dentry *dentry, 
3755         if (is_quota_modification(inode, attr))
3756                 dquot_initialize(inode);
3757         if ((ia_valid & ATTR_UID && attr->ia_uid != inode->i_uid) ||
3758 -               (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid)) {
3759 +               (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid) ||
3760 +               (ia_valid & ATTR_TAG && attr->ia_tag != inode->i_tag)) {
3761                 handle_t *handle;
3762  
3763                 /* (user+group)*(old+new) structure, inode write (sb,
3764 @@ -5346,6 +5382,8 @@ int ext4_setattr(struct dentry *dentry, 
3765                         inode->i_uid = attr->ia_uid;
3766                 if (attr->ia_valid & ATTR_GID)
3767                         inode->i_gid = attr->ia_gid;
3768 +               if ((attr->ia_valid & ATTR_TAG) && IS_TAGGED(inode))
3769 +                       inode->i_tag = attr->ia_tag;
3770                 error = ext4_mark_inode_dirty(handle, inode);
3771                 ext4_journal_stop(handle);
3772         }
3773 diff -NurpP --minimal linux-2.6.38.1/fs/ext4/ioctl.c linux-2.6.38.1-vs2.3.0.37-rc9/fs/ext4/ioctl.c
3774 --- linux-2.6.38.1/fs/ext4/ioctl.c      2011-01-05 21:50:23.000000000 +0100
3775 +++ linux-2.6.38.1-vs2.3.0.37-rc9/fs/ext4/ioctl.c       2011-01-29 02:01:07.000000000 +0100
3776 @@ -14,10 +14,39 @@
3777  #include <linux/compat.h>
3778  #include <linux/mount.h>
3779  #include <linux/file.h>
3780 +#include <linux/vs_tag.h>
3781  #include <asm/uaccess.h>
3782  #include "ext4_jbd2.h"
3783  #include "ext4.h"
3784  
3785 +
3786 +int ext4_sync_flags(struct inode *inode, int flags, int vflags)
3787 +{
3788 +       handle_t *handle = NULL;
3789 +       struct ext4_iloc iloc;
3790 +       int err;
3791 +
3792 +       handle = ext4_journal_start(inode, 1);
3793 +       if (IS_ERR(handle))
3794 +               return PTR_ERR(handle);
3795 +
3796 +       if (IS_SYNC(inode))
3797 +               ext4_handle_sync(handle);
3798 +       err = ext4_reserve_inode_write(handle, inode, &iloc);
3799 +       if (err)
3800 +               goto flags_err;
3801 +
3802 +       inode->i_flags = flags;
3803 +       inode->i_vflags = vflags;
3804 +       ext4_get_inode_flags(EXT4_I(inode));
3805 +       inode->i_ctime = ext4_current_time(inode);
3806 +
3807 +       err = ext4_mark_iloc_dirty(handle, inode, &iloc);
3808 +flags_err:
3809 +       ext4_journal_stop(handle);
3810 +       return err;
3811 +}
3812 +
3813  long ext4_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
3814  {
3815         struct inode *inode = filp->f_dentry->d_inode;
3816 @@ -50,6 +79,11 @@ long ext4_ioctl(struct file *filp, unsig
3817  
3818                 flags = ext4_mask_flags(inode->i_mode, flags);
3819  
3820 +               if (IS_BARRIER(inode)) {
3821 +                       vxwprintk_task(1, "messing with the barrier.");
3822 +                       return -EACCES;
3823 +               }
3824 +
3825                 err = -EPERM;
3826                 mutex_lock(&inode->i_mutex);
3827                 /* Is it quota file? Do not allow user to mess with it */
3828 @@ -67,7 +101,9 @@ long ext4_ioctl(struct file *filp, unsig
3829                  *
3830                  * This test looks nicer. Thanks to Pauline Middelink
3831                  */
3832 -               if ((flags ^ oldflags) & (EXT4_APPEND_FL | EXT4_IMMUTABLE_FL)) {
3833 +               if ((oldflags & EXT4_IMMUTABLE_FL) ||
3834 +                       ((flags ^ oldflags) & (EXT4_APPEND_FL |
3835 +                       EXT4_IMMUTABLE_FL | EXT4_IXUNLINK_FL))) {
3836                         if (!capable(CAP_LINUX_IMMUTABLE))
3837                                 goto flags_out;
3838                 }
3839 diff -NurpP --minimal linux-2.6.38.1/fs/ext4/namei.c linux-2.6.38.1-vs2.3.0.37-rc9/fs/ext4/namei.c
3840 --- linux-2.6.38.1/fs/ext4/namei.c      2011-03-15 18:07:31.000000000 +0100
3841 +++ linux-2.6.38.1-vs2.3.0.37-rc9/fs/ext4/namei.c       2011-01-29 02:01:07.000000000 +0100
3842 @@ -34,6 +34,7 @@
3843  #include <linux/quotaops.h>
3844  #include <linux/buffer_head.h>
3845  #include <linux/bio.h>
3846 +#include <linux/vs_tag.h>
3847  #include "ext4.h"
3848  #include "ext4_jbd2.h"
3849  
3850 @@ -923,6 +924,7 @@ restart:
3851                                 if (bh)
3852                                         ll_rw_block(READ_META, 1, &bh);
3853                         }
3854 +               dx_propagate_tag(nd, inode);
3855                 }
3856                 if ((bh = bh_use[ra_ptr++]) == NULL)
3857                         goto next;
3858 @@ -2540,6 +2542,7 @@ const struct inode_operations ext4_dir_i
3859  #endif
3860         .check_acl      = ext4_check_acl,
3861         .fiemap         = ext4_fiemap,
3862 +       .sync_flags     = ext4_sync_flags,
3863  };
3864  
3865  const struct inode_operations ext4_special_inode_operations = {
3866 diff -NurpP --minimal linux-2.6.38.1/fs/ext4/super.c linux-2.6.38.1-vs2.3.0.37-rc9/fs/ext4/super.c
3867 --- linux-2.6.38.1/fs/ext4/super.c      2011-03-15 18:07:31.000000000 +0100
3868 +++ linux-2.6.38.1-vs2.3.0.37-rc9/fs/ext4/super.c       2011-02-17 02:17:50.000000000 +0100
3869 @@ -1262,6 +1262,7 @@ enum {
3870         Opt_dioread_nolock, Opt_dioread_lock,
3871         Opt_discard, Opt_nodiscard,
3872         Opt_init_inode_table, Opt_noinit_inode_table,
3873 +       Opt_tag, Opt_notag, Opt_tagid
3874  };
3875  
3876  static const match_table_t tokens = {
3877 @@ -1337,6 +1338,9 @@ static const match_table_t tokens = {
3878         {Opt_init_inode_table, "init_itable=%u"},
3879         {Opt_init_inode_table, "init_itable"},
3880         {Opt_noinit_inode_table, "noinit_itable"},
3881 +       {Opt_tag, "tag"},
3882 +       {Opt_notag, "notag"},
3883 +       {Opt_tagid, "tagid=%u"},
3884         {Opt_err, NULL},
3885  };
3886  
3887 @@ -1505,6 +1509,20 @@ static int parse_options(char *options, 
3888                 case Opt_nouid32:
3889                         set_opt(sb, NO_UID32);
3890                         break;
3891 +#ifndef CONFIG_TAGGING_NONE
3892 +               case Opt_tag:
3893 +                       set_opt(sb, TAGGED);
3894 +                       break;
3895 +               case Opt_notag:
3896 +                       clear_opt(sb, TAGGED);
3897 +                       break;
3898 +#endif
3899 +#ifdef CONFIG_PROPAGATE
3900 +               case Opt_tagid:
3901 +                       /* use args[0] */
3902 +                       set_opt(sb, TAGGED);
3903 +                       break;
3904 +#endif
3905                 case Opt_debug:
3906                         set_opt(sb, DEBUG);
3907                         break;
3908 @@ -3148,6 +3166,9 @@ static int ext4_fill_super(struct super_
3909                            &journal_ioprio, NULL, 0))
3910                 goto failed_mount;
3911  
3912 +       if (EXT4_SB(sb)->s_mount_opt & EXT4_MOUNT_TAGGED)
3913 +               sb->s_flags |= MS_TAGGED;
3914 +
3915         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
3916                 (test_opt(sb, POSIX_ACL) ? MS_POSIXACL : 0);
3917  
3918 @@ -4235,6 +4256,14 @@ static int ext4_remount(struct super_blo
3919         if (sbi->s_mount_flags & EXT4_MF_FS_ABORTED)
3920                 ext4_abort(sb, "Abort forced by user");
3921  
3922 +       if ((sbi->s_mount_opt & EXT4_MOUNT_TAGGED) &&
3923 +               !(sb->s_flags & MS_TAGGED)) {
3924 +               printk("EXT4-fs: %s: tagging not permitted on remount.\n",
3925 +                       sb->s_id);
3926 +               err = -EINVAL;
3927 +               goto restore_opts;
3928 +       }
3929 +
3930         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
3931                 (test_opt(sb, POSIX_ACL) ? MS_POSIXACL : 0);
3932  
3933 diff -NurpP --minimal linux-2.6.38.1/fs/fcntl.c linux-2.6.38.1-vs2.3.0.37-rc9/fs/fcntl.c
3934 --- linux-2.6.38.1/fs/fcntl.c   2011-03-15 18:07:31.000000000 +0100
3935 +++ linux-2.6.38.1-vs2.3.0.37-rc9/fs/fcntl.c    2011-02-17 02:17:50.000000000 +0100
3936 @@ -20,6 +20,7 @@
3937  #include <linux/signal.h>
3938  #include <linux/rcupdate.h>
3939  #include <linux/pid_namespace.h>
3940 +#include <linux/vs_limit.h>
3941  
3942  #include <asm/poll.h>
3943  #include <asm/siginfo.h>
3944 @@ -103,6 +104,8 @@ SYSCALL_DEFINE3(dup3, unsigned int, oldf
3945  
3946         if (tofree)
3947                 filp_close(tofree, files);
3948 +       else
3949 +               vx_openfd_inc(newfd);   /* fd was unused */
3950  
3951         return newfd;
3952  
3953 @@ -434,6 +437,8 @@ SYSCALL_DEFINE3(fcntl, unsigned int, fd,
3954         filp = fget(fd);
3955         if (!filp)
3956                 goto out;
3957 +       if (!vx_files_avail(1))
3958 +               goto out;
3959  
3960         err = security_file_fcntl(filp, cmd, arg);
3961         if (err) {
3962 diff -NurpP --minimal linux-2.6.38.1/fs/file.c linux-2.6.38.1-vs2.3.0.37-rc9/fs/file.c
3963 --- linux-2.6.38.1/fs/file.c    2010-10-21 13:07:48.000000000 +0200
3964 +++ linux-2.6.38.1-vs2.3.0.37-rc9/fs/file.c     2011-01-29 02:01:07.000000000 +0100
3965 @@ -20,6 +20,7 @@
3966  #include <linux/spinlock.h>
3967  #include <linux/rcupdate.h>
3968  #include <linux/workqueue.h>
3969 +#include <linux/vs_limit.h>
3970  
3971  struct fdtable_defer {
3972         spinlock_t lock;
3973 @@ -355,6 +356,8 @@ struct files_struct *dup_fd(struct files
3974                 struct file *f = *old_fds++;
3975                 if (f) {
3976                         get_file(f);
3977 +                       /* TODO: sum it first for check and performance */
3978 +                       vx_openfd_inc(open_files - i);
3979                 } else {
3980                         /*
3981                          * The fd may be claimed in the fd bitmap but not yet
3982 @@ -462,6 +465,7 @@ repeat:
3983         else
3984                 FD_CLR(fd, fdt->close_on_exec);
3985         error = fd;
3986 +       vx_openfd_inc(fd);
3987  #if 1
3988         /* Sanity check */
3989         if (rcu_dereference_raw(fdt->fd[fd]) != NULL) {
3990 diff -NurpP --minimal linux-2.6.38.1/fs/file_table.c linux-2.6.38.1-vs2.3.0.37-rc9/fs/file_table.c
3991 --- linux-2.6.38.1/fs/file_table.c      2011-03-15 18:07:31.000000000 +0100
3992 +++ linux-2.6.38.1-vs2.3.0.37-rc9/fs/file_table.c       2011-02-17 02:17:50.000000000 +0100
3993 @@ -24,6 +24,8 @@
3994  #include <linux/percpu_counter.h>
3995  #include <linux/percpu.h>
3996  #include <linux/ima.h>
3997 +#include <linux/vs_limit.h>
3998 +#include <linux/vs_context.h>
3999  
4000  #include <asm/atomic.h>
4001  
4002 @@ -135,6 +137,8 @@ struct file *get_empty_filp(void)
4003         spin_lock_init(&f->f_lock);
4004         eventpoll_init_file(f);
4005         /* f->f_version: 0 */
4006 +       f->f_xid = vx_current_xid();
4007 +       vx_files_inc(f);
4008         return f;
4009  
4010  over:
4011 @@ -250,6 +254,8 @@ static void __fput(struct file *file)
4012                 cdev_put(inode->i_cdev);
4013         fops_put(file->f_op);
4014         put_pid(file->f_owner.pid);
4015 +       vx_files_dec(file);
4016 +       file->f_xid = 0;
4017         file_sb_list_del(file);
4018         if (file->f_mode & FMODE_WRITE)
4019                 drop_file_write_access(file);
4020 @@ -333,6 +339,8 @@ void put_filp(struct file *file)
4021  {
4022         if (atomic_long_dec_and_test(&file->f_count)) {
4023                 security_file_free(file);
4024 +               vx_files_dec(file);
4025 +               file->f_xid = 0;
4026                 file_sb_list_del(file);
4027                 file_free(file);
4028         }
4029 diff -NurpP --minimal linux-2.6.38.1/fs/fs_struct.c linux-2.6.38.1-vs2.3.0.37-rc9/fs/fs_struct.c
4030 --- linux-2.6.38.1/fs/fs_struct.c       2011-03-15 18:07:31.000000000 +0100
4031 +++ linux-2.6.38.1-vs2.3.0.37-rc9/fs/fs_struct.c        2011-01-29 02:35:02.000000000 +0100
4032 @@ -4,6 +4,7 @@
4033  #include <linux/path.h>
4034  #include <linux/slab.h>
4035  #include <linux/fs_struct.h>
4036 +#include <linux/vserver/global.h>
4037  #include "internal.h"
4038  
4039  static inline void path_get_longterm(struct path *path)
4040 @@ -96,6 +97,7 @@ void free_fs_struct(struct fs_struct *fs
4041  {
4042         path_put_longterm(&fs->root);
4043         path_put_longterm(&fs->pwd);
4044 +       atomic_dec(&vs_global_fs);
4045         kmem_cache_free(fs_cachep, fs);
4046  }
4047  
4048 @@ -135,6 +137,7 @@ struct fs_struct *copy_fs_struct(struct 
4049                 fs->pwd = old->pwd;
4050                 path_get_longterm(&fs->pwd);
4051                 spin_unlock(&old->lock);
4052 +               atomic_inc(&vs_global_fs);
4053         }
4054         return fs;
4055  }
4056 diff -NurpP --minimal linux-2.6.38.1/fs/gfs2/file.c linux-2.6.38.1-vs2.3.0.37-rc9/fs/gfs2/file.c
4057 --- linux-2.6.38.1/fs/gfs2/file.c       2011-03-15 18:07:32.000000000 +0100
4058 +++ linux-2.6.38.1-vs2.3.0.37-rc9/fs/gfs2/file.c        2011-01-29 02:01:07.000000000 +0100
4059 @@ -134,6 +134,9 @@ static const u32 fsflags_to_gfs2[32] = {
4060         [7] = GFS2_DIF_NOATIME,
4061         [12] = GFS2_DIF_EXHASH,
4062         [14] = GFS2_DIF_INHERIT_JDATA,
4063 +       [27] = GFS2_DIF_IXUNLINK,
4064 +       [26] = GFS2_DIF_BARRIER,
4065 +       [29] = GFS2_DIF_COW,
4066  };
4067  
4068  static const u32 gfs2_to_fsflags[32] = {
4069 @@ -143,6 +146,9 @@ static const u32 gfs2_to_fsflags[32] = {
4070         [gfs2fl_NoAtime] = FS_NOATIME_FL,
4071         [gfs2fl_ExHash] = FS_INDEX_FL,
4072         [gfs2fl_InheritJdata] = FS_JOURNAL_DATA_FL,
4073 +       [gfs2fl_IXUnlink] = FS_IXUNLINK_FL,
4074 +       [gfs2fl_Barrier] = FS_BARRIER_FL,
4075 +       [gfs2fl_Cow] = FS_COW_FL,
4076  };
4077  
4078  static int gfs2_get_flags(struct file *filp, u32 __user *ptr)
4079 @@ -173,10 +179,16 @@ void gfs2_set_inode_flags(struct inode *
4080  {
4081         struct gfs2_inode *ip = GFS2_I(inode);
4082         unsigned int flags = inode->i_flags;
4083 +       unsigned int vflags = inode->i_vflags;
4084 +
4085 +       flags &= ~(S_IMMUTABLE | S_IXUNLINK |
4086 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
4087  
4088 -       flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
4089         if (ip->i_diskflags & GFS2_DIF_IMMUTABLE)
4090                 flags |= S_IMMUTABLE;
4091 +       if (ip->i_diskflags & GFS2_DIF_IXUNLINK)
4092 +               flags |= S_IXUNLINK;
4093 +
4094         if (ip->i_diskflags & GFS2_DIF_APPENDONLY)
4095                 flags |= S_APPEND;
4096         if (ip->i_diskflags & GFS2_DIF_NOATIME)
4097 @@ -184,6 +196,43 @@ void gfs2_set_inode_flags(struct inode *
4098         if (ip->i_diskflags & GFS2_DIF_SYNC)
4099                 flags |= S_SYNC;
4100         inode->i_flags = flags;
4101 +
4102 +       vflags &= ~(V_BARRIER | V_COW);
4103 +
4104 +       if (ip->i_diskflags & GFS2_DIF_BARRIER)
4105 +               vflags |= V_BARRIER;
4106 +       if (ip->i_diskflags & GFS2_DIF_COW)
4107 +               vflags |= V_COW;
4108 +       inode->i_vflags = vflags;
4109 +}
4110 +
4111 +void gfs2_get_inode_flags(struct inode *inode)
4112 +{
4113 +       struct gfs2_inode *ip = GFS2_I(inode);
4114 +       unsigned int flags = inode->i_flags;
4115 +       unsigned int vflags = inode->i_vflags;
4116 +
4117 +       ip->i_diskflags &= ~(GFS2_DIF_APPENDONLY |
4118 +                       GFS2_DIF_NOATIME | GFS2_DIF_SYNC |
4119 +                       GFS2_DIF_IMMUTABLE | GFS2_DIF_IXUNLINK |
4120 +                       GFS2_DIF_BARRIER | GFS2_DIF_COW);
4121 +
4122 +       if (flags & S_IMMUTABLE)
4123 +               ip->i_diskflags |= GFS2_DIF_IMMUTABLE;
4124 +       if (flags & S_IXUNLINK)
4125 +               ip->i_diskflags |= GFS2_DIF_IXUNLINK;
4126 +
4127 +       if (flags & S_APPEND)
4128 +               ip->i_diskflags |= GFS2_DIF_APPENDONLY;
4129 +       if (flags & S_NOATIME)
4130 +               ip->i_diskflags |= GFS2_DIF_NOATIME;
4131 +       if (flags & S_SYNC)
4132 +               ip->i_diskflags |= GFS2_DIF_SYNC;
4133 +
4134 +       if (vflags & V_BARRIER)
4135 +               ip->i_diskflags |= GFS2_DIF_BARRIER;
4136 +       if (vflags & V_COW)
4137 +               ip->i_diskflags |= GFS2_DIF_COW;
4138  }
4139  
4140  /* Flags that can be set by user space */
4141 @@ -295,6 +344,37 @@ static int gfs2_set_flags(struct file *f
4142         return do_gfs2_set_flags(filp, gfsflags, ~GFS2_DIF_JDATA);
4143  }
4144  
4145 +int gfs2_sync_flags(struct inode *inode, int flags, int vflags)
4146 +{
4147 +       struct gfs2_inode *ip = GFS2_I(inode);
4148 +       struct gfs2_sbd *sdp = GFS2_SB(inode);
4149 +       struct buffer_head *bh;
4150 +       struct gfs2_holder gh;
4151 +       int error;
4152 +
4153 +       error = gfs2_glock_nq_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &gh);
4154 +       if (error)
4155 +               return error;
4156 +       error = gfs2_trans_begin(sdp, RES_DINODE, 0);
4157 +       if (error)
4158 +               goto out;
4159 +       error = gfs2_meta_inode_buffer(ip, &bh);
4160 +       if (error)
4161 +               goto out_trans_end;
4162 +       gfs2_trans_add_bh(ip->i_gl, bh, 1);
4163 +       inode->i_flags = flags;
4164 +       inode->i_vflags = vflags;
4165 +       gfs2_get_inode_flags(inode);
4166 +       gfs2_dinode_out(ip, bh->b_data);
4167 +       brelse(bh);
4168 +       gfs2_set_aops(inode);
4169 +out_trans_end:
4170 +       gfs2_trans_end(sdp);
4171 +out:
4172 +       gfs2_glock_dq_uninit(&gh);
4173 +       return error;
4174 +}
4175 +
4176  static long gfs2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
4177  {
4178         switch(cmd) {
4179 diff -NurpP --minimal linux-2.6.38.1/fs/gfs2/inode.h linux-2.6.38.1-vs2.3.0.37-rc9/fs/gfs2/inode.h
4180 --- linux-2.6.38.1/fs/gfs2/inode.h      2011-03-15 18:07:32.000000000 +0100
4181 +++ linux-2.6.38.1-vs2.3.0.37-rc9/fs/gfs2/inode.h       2011-01-29 02:01:07.000000000 +0100
4182 @@ -125,6 +125,7 @@ extern const struct file_operations gfs2
4183  extern const struct file_operations gfs2_dir_fops_nolock;
4184  
4185  extern void gfs2_set_inode_flags(struct inode *inode);
4186 +extern int gfs2_sync_flags(struct inode *inode, int flags, int vflags);
4187   
4188  #ifdef CONFIG_GFS2_FS_LOCKING_DLM
4189  extern const struct file_operations gfs2_file_fops;
4190 diff -NurpP --minimal linux-2.6.38.1/fs/gfs2/ops_inode.c linux-2.6.38.1-vs2.3.0.37-rc9/fs/gfs2/ops_inode.c
4191 --- linux-2.6.38.1/fs/gfs2/ops_inode.c  2011-03-15 18:07:32.000000000 +0100
4192 +++ linux-2.6.38.1-vs2.3.0.37-rc9/fs/gfs2/ops_inode.c   2011-01-29 02:01:07.000000000 +0100
4193 @@ -1326,6 +1326,8 @@ const struct inode_operations gfs2_dir_i
4194         .listxattr = gfs2_listxattr,
4195         .removexattr = gfs2_removexattr,
4196         .fiemap = gfs2_fiemap,
4197 +       .sync_flags = gfs2_sync_flags,
4198 +       .sync_flags = gfs2_sync_flags,
4199  };
4200  
4201  const struct inode_operations gfs2_symlink_iops = {
4202 diff -NurpP --minimal linux-2.6.38.1/fs/inode.c linux-2.6.38.1-vs2.3.0.37-rc9/fs/inode.c
4203 --- linux-2.6.38.1/fs/inode.c   2011-03-15 18:07:32.000000000 +0100
4204 +++ linux-2.6.38.1-vs2.3.0.37-rc9/fs/inode.c    2011-03-07 16:53:27.000000000 +0100
4205 @@ -25,6 +25,7 @@
4206  #include <linux/async.h>
4207  #include <linux/posix_acl.h>
4208  #include <linux/ima.h>
4209 +#include <linux/vs_tag.h>
4210  
4211  /*
4212   * This is needed for the following functions:
4213 @@ -164,6 +165,9 @@ int inode_init_always(struct super_block
4214         struct address_space *const mapping = &inode->i_data;
4215  
4216         inode->i_sb = sb;
4217 +
4218 +       /* essential because of inode slab reuse */
4219 +       inode->i_tag = 0;
4220         inode->i_blkbits = sb->s_blocksize_bits;
4221         inode->i_flags = 0;
4222         atomic_set(&inode->i_count, 1);
4223 @@ -184,6 +188,7 @@ int inode_init_always(struct super_block
4224         inode->i_bdev = NULL;
4225         inode->i_cdev = NULL;
4226         inode->i_rdev = 0;
4227 +       inode->i_mdev = 0;
4228         inode->dirtied_when = 0;
4229  
4230         if (security_inode_alloc(inode))
4231 @@ -431,6 +436,8 @@ static void __remove_inode_hash(struct i
4232         hlist_del_init(&inode->i_hash);
4233  }
4234  
4235 +EXPORT_SYMBOL_GPL(__iget);
4236 +
4237  /**
4238   *     remove_inode_hash - remove an inode from the hash
4239   *     @inode: inode to unhash
4240 @@ -1704,9 +1711,11 @@ void init_special_inode(struct inode *in
4241         if (S_ISCHR(mode)) {
4242                 inode->i_fop = &def_chr_fops;
4243                 inode->i_rdev = rdev;
4244 +               inode->i_mdev = rdev;
4245         } else if (S_ISBLK(mode)) {
4246                 inode->i_fop = &def_blk_fops;
4247                 inode->i_rdev = rdev;
4248 +               inode->i_mdev = rdev;
4249         } else if (S_ISFIFO(mode))
4250                 inode->i_fop = &def_fifo_fops;
4251         else if (S_ISSOCK(mode))
4252 @@ -1735,5 +1744,6 @@ void inode_init_owner(struct inode *inod
4253         } else
4254                 inode->i_gid = current_fsgid();
4255         inode->i_mode = mode;
4256 +       inode->i_tag = dx_current_fstag(inode->i_sb);
4257  }
4258  EXPORT_SYMBOL(inode_init_owner);
4259 diff -NurpP --minimal linux-2.6.38.1/fs/ioctl.c linux-2.6.38.1-vs2.3.0.37-rc9/fs/ioctl.c
4260 --- linux-2.6.38.1/fs/ioctl.c   2011-03-15 18:07:32.000000000 +0100
4261 +++ linux-2.6.38.1-vs2.3.0.37-rc9/fs/ioctl.c    2011-02-17 02:17:50.000000000 +0100
4262 @@ -15,6 +15,9 @@
4263  #include <linux/writeback.h>
4264  #include <linux/buffer_head.h>
4265  #include <linux/falloc.h>
4266 +#include <linux/proc_fs.h>
4267 +#include <linux/vserver/inode.h>
4268 +#include <linux/vs_tag.h>
4269  
4270  #include <asm/ioctls.h>
4271  
4272 diff -NurpP --minimal linux-2.6.38.1/fs/ioprio.c linux-2.6.38.1-vs2.3.0.37-rc9/fs/ioprio.c
4273 --- linux-2.6.38.1/fs/ioprio.c  2011-01-05 21:50:24.000000000 +0100
4274 +++ linux-2.6.38.1-vs2.3.0.37-rc9/fs/ioprio.c   2011-01-29 02:01:07.000000000 +0100
4275 @@ -27,6 +27,7 @@
4276  #include <linux/syscalls.h>
4277  #include <linux/security.h>
4278  #include <linux/pid_namespace.h>
4279 +#include <linux/vs_base.h>
4280  
4281  int set_task_ioprio(struct task_struct *task, int ioprio)
4282  {
4283 @@ -119,6 +120,8 @@ SYSCALL_DEFINE3(ioprio_set, int, which, 
4284                         else
4285                                 pgrp = find_vpid(who);
4286                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
4287 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
4288 +                                       continue;
4289                                 ret = set_task_ioprio(p, ioprio);
4290                                 if (ret)
4291                                         break;
4292 @@ -208,6 +211,8 @@ SYSCALL_DEFINE2(ioprio_get, int, which, 
4293                         else
4294                                 pgrp = find_vpid(who);
4295                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
4296 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
4297 +                                       continue;
4298                                 tmpio = get_task_ioprio(p);
4299                                 if (tmpio < 0)
4300                                         continue;
4301 diff -NurpP --minimal linux-2.6.38.1/fs/jfs/file.c linux-2.6.38.1-vs2.3.0.37-rc9/fs/jfs/file.c
4302 --- linux-2.6.38.1/fs/jfs/file.c        2010-10-21 13:07:50.000000000 +0200
4303 +++ linux-2.6.38.1-vs2.3.0.37-rc9/fs/jfs/file.c 2011-01-29 02:01:07.000000000 +0100
4304 @@ -102,7 +102,8 @@ int jfs_setattr(struct dentry *dentry, s
4305         if (is_quota_modification(inode, iattr))
4306                 dquot_initialize(inode);
4307         if ((iattr->ia_valid & ATTR_UID && iattr->ia_uid != inode->i_uid) ||
4308 -           (iattr->ia_valid & ATTR_GID && iattr->ia_gid != inode->i_gid)) {
4309 +           (iattr->ia_valid & ATTR_GID && iattr->ia_gid != inode->i_gid) ||
4310 +           (iattr->ia_valid & ATTR_TAG && iattr->ia_tag != inode->i_tag)) {
4311                 rc = dquot_transfer(inode, iattr);
4312                 if (rc)
4313                         return rc;
4314 @@ -133,6 +134,7 @@ const struct inode_operations jfs_file_i
4315  #ifdef CONFIG_JFS_POSIX_ACL
4316         .check_acl      = jfs_check_acl,
4317  #endif
4318 +       .sync_flags     = jfs_sync_flags,
4319  };
4320  
4321  const struct file_operations jfs_file_operations = {
4322 diff -NurpP --minimal linux-2.6.38.1/fs/jfs/ioctl.c linux-2.6.38.1-vs2.3.0.37-rc9/fs/jfs/ioctl.c
4323 --- linux-2.6.38.1/fs/jfs/ioctl.c       2008-12-25 00:26:37.000000000 +0100
4324 +++ linux-2.6.38.1-vs2.3.0.37-rc9/fs/jfs/ioctl.c        2011-01-29 02:01:07.000000000 +0100
4325 @@ -11,6 +11,7 @@
4326  #include <linux/mount.h>
4327  #include <linux/time.h>
4328  #include <linux/sched.h>
4329 +#include <linux/mount.h>
4330  #include <asm/current.h>
4331  #include <asm/uaccess.h>
4332  
4333 @@ -52,6 +53,16 @@ static long jfs_map_ext2(unsigned long f
4334  }
4335  
4336  
4337 +int jfs_sync_flags(struct inode *inode, int flags, int vflags)
4338 +{
4339 +       inode->i_flags = flags;
4340 +       inode->i_vflags = vflags;
4341 +       jfs_get_inode_flags(JFS_IP(inode));
4342 +       inode->i_ctime = CURRENT_TIME_SEC;
4343 +       mark_inode_dirty(inode);
4344 +       return 0;
4345 +}
4346 +
4347  long jfs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
4348  {
4349         struct inode *inode = filp->f_dentry->d_inode;
4350 @@ -85,6 +96,11 @@ long jfs_ioctl(struct file *filp, unsign
4351                 if (!S_ISDIR(inode->i_mode))
4352                         flags &= ~JFS_DIRSYNC_FL;
4353  
4354 +               if (IS_BARRIER(inode)) {
4355 +                       vxwprintk_task(1, "messing with the barrier.");
4356 +                       return -EACCES;
4357 +               }
4358 +
4359                 /* Is it quota file? Do not allow user to mess with it */
4360                 if (IS_NOQUOTA(inode)) {
4361                         err = -EPERM;
4362 @@ -102,8 +118,8 @@ long jfs_ioctl(struct file *filp, unsign
4363                  * the relevant capability.
4364                  */
4365                 if ((oldflags & JFS_IMMUTABLE_FL) ||
4366 -                       ((flags ^ oldflags) &
4367 -                       (JFS_APPEND_FL | JFS_IMMUTABLE_FL))) {
4368 +                       ((flags ^ oldflags) & (JFS_APPEND_FL |
4369 +                       JFS_IMMUTABLE_FL | JFS_IXUNLINK_FL))) {
4370                         if (!capable(CAP_LINUX_IMMUTABLE)) {
4371                                 mutex_unlock(&inode->i_mutex);
4372                                 err = -EPERM;
4373 @@ -111,7 +127,7 @@ long jfs_ioctl(struct file *filp, unsign
4374                         }
4375                 }
4376  
4377 -               flags = flags & JFS_FL_USER_MODIFIABLE;
4378 +               flags &= JFS_FL_USER_MODIFIABLE;
4379                 flags |= oldflags & ~JFS_FL_USER_MODIFIABLE;
4380                 jfs_inode->mode2 = flags;
4381  
4382 diff -NurpP --minimal linux-2.6.38.1/fs/jfs/jfs_dinode.h linux-2.6.38.1-vs2.3.0.37-rc9/fs/jfs/jfs_dinode.h
4383 --- linux-2.6.38.1/fs/jfs/jfs_dinode.h  2008-12-25 00:26:37.000000000 +0100
4384 +++ linux-2.6.38.1-vs2.3.0.37-rc9/fs/jfs/jfs_dinode.h   2011-01-29 02:01:07.000000000 +0100
4385 @@ -161,9 +161,13 @@ struct dinode {
4386  
4387  #define JFS_APPEND_FL          0x01000000 /* writes to file may only append */
4388  #define JFS_IMMUTABLE_FL       0x02000000 /* Immutable file */
4389 +#define JFS_IXUNLINK_FL                0x08000000 /* Immutable invert on unlink */
4390  
4391 -#define JFS_FL_USER_VISIBLE    0x03F80000
4392 -#define JFS_FL_USER_MODIFIABLE 0x03F80000
4393 +#define JFS_BARRIER_FL         0x04000000 /* Barrier for chroot() */
4394 +#define JFS_COW_FL             0x20000000 /* Copy on Write marker */
4395 +
4396 +#define JFS_FL_USER_VISIBLE    0x07F80000
4397 +#define JFS_FL_USER_MODIFIABLE 0x07F80000
4398  #define JFS_FL_INHERIT         0x03C80000
4399  
4400  /* These are identical to EXT[23]_IOC_GETFLAGS/SETFLAGS */
4401 diff -NurpP --minimal linux-2.6.38.1/fs/jfs/jfs_filsys.h linux-2.6.38.1-vs2.3.0.37-rc9/fs/jfs/jfs_filsys.h
4402 --- linux-2.6.38.1/fs/jfs/jfs_filsys.h  2008-12-25 00:26:37.000000000 +0100
4403 +++ linux-2.6.38.1-vs2.3.0.37-rc9/fs/jfs/jfs_filsys.h   2011-01-29 02:01:07.000000000 +0100
4404 @@ -263,6 +263,7 @@
4405  #define JFS_NAME_MAX   255
4406  #define JFS_PATH_MAX   BPSIZE
4407  
4408 +#define JFS_TAGGED             0x00800000      /* Context Tagging */
4409  
4410  /*
4411   *     file system state (superblock state)
4412 diff -NurpP --minimal linux-2.6.38.1/fs/jfs/jfs_imap.c linux-2.6.38.1-vs2.3.0.37-rc9/fs/jfs/jfs_imap.c
4413 --- linux-2.6.38.1/fs/jfs/jfs_imap.c    2011-01-05 21:50:24.000000000 +0100
4414 +++ linux-2.6.38.1-vs2.3.0.37-rc9/fs/jfs/jfs_imap.c     2011-01-29 02:01:07.000000000 +0100
4415 @@ -46,6 +46,7 @@
4416  #include <linux/pagemap.h>
4417  #include <linux/quotaops.h>
4418  #include <linux/slab.h>
4419 +#include <linux/vs_tag.h>
4420  
4421  #include "jfs_incore.h"
4422  #include "jfs_inode.h"
4423 @@ -3060,6 +3061,8 @@ static int copy_from_dinode(struct dinod
4424  {
4425         struct jfs_inode_info *jfs_ip = JFS_IP(ip);
4426         struct jfs_sb_info *sbi = JFS_SBI(ip->i_sb);
4427 +       uid_t uid;
4428 +       gid_t gid;
4429  
4430         jfs_ip->fileset = le32_to_cpu(dip->di_fileset);
4431         jfs_ip->mode2 = le32_to_cpu(dip->di_mode);
4432 @@ -3080,14 +3083,18 @@ static int copy_from_dinode(struct dinod
4433         }
4434         ip->i_nlink = le32_to_cpu(dip->di_nlink);
4435  
4436 -       jfs_ip->saved_uid = le32_to_cpu(dip->di_uid);
4437 +       uid = le32_to_cpu(dip->di_uid);
4438 +       gid = le32_to_cpu(dip->di_gid);
4439 +       ip->i_tag = INOTAG_TAG(DX_TAG(ip), uid, gid, 0);
4440 +
4441 +       jfs_ip->saved_uid = INOTAG_UID(DX_TAG(ip), uid, gid);
4442         if (sbi->uid == -1)
4443                 ip->i_uid = jfs_ip->saved_uid;
4444         else {
4445                 ip->i_uid = sbi->uid;
4446         }
4447  
4448 -       jfs_ip->saved_gid = le32_to_cpu(dip->di_gid);
4449 +       jfs_ip->saved_gid = INOTAG_GID(DX_TAG(ip), uid, gid);
4450         if (sbi->gid == -1)
4451                 ip->i_gid = jfs_ip->saved_gid;
4452         else {
4453 @@ -3152,14 +3159,12 @@ static void copy_to_dinode(struct dinode
4454         dip->di_size = cpu_to_le64(ip->i_size);
4455         dip->di_nblocks = cpu_to_le64(PBLK2LBLK(ip->i_sb, ip->i_blocks));
4456         dip->di_nlink = cpu_to_le32(ip->i_nlink);
4457 -       if (sbi->uid == -1)
4458 -               dip->di_uid = cpu_to_le32(ip->i_uid);
4459 -       else
4460 -               dip->di_uid = cpu_to_le32(jfs_ip->saved_uid);
4461 -       if (sbi->gid == -1)
4462 -               dip->di_gid = cpu_to_le32(ip->i_gid);
4463 -       else
4464 -               dip->di_gid = cpu_to_le32(jfs_ip->saved_gid);
4465 +
4466 +       dip->di_uid = cpu_to_le32(TAGINO_UID(DX_TAG(ip),
4467 +               (sbi->uid == -1) ? ip->i_uid : jfs_ip->saved_uid, ip->i_tag));
4468 +       dip->di_gid = cpu_to_le32(TAGINO_GID(DX_TAG(ip),
4469 +               (sbi->gid == -1) ? ip->i_gid : jfs_ip->saved_gid, ip->i_tag));
4470 +
4471         jfs_get_inode_flags(jfs_ip);
4472         /*
4473          * mode2 is only needed for storing the higher order bits.
4474 diff -NurpP --minimal linux-2.6.38.1/fs/jfs/jfs_inode.c linux-2.6.38.1-vs2.3.0.37-rc9/fs/jfs/jfs_inode.c
4475 --- linux-2.6.38.1/fs/jfs/jfs_inode.c   2010-08-02 16:52:49.000000000 +0200
4476 +++ linux-2.6.38.1-vs2.3.0.37-rc9/fs/jfs/jfs_inode.c    2011-01-29 02:01:07.000000000 +0100
4477 @@ -18,6 +18,7 @@
4478  
4479  #include <linux/fs.h>
4480  #include <linux/quotaops.h>
4481 +#include <linux/vs_tag.h>
4482  #include "jfs_incore.h"
4483  #include "jfs_inode.h"
4484  #include "jfs_filsys.h"
4485 @@ -30,29 +31,46 @@ void jfs_set_inode_flags(struct inode *i
4486  {
4487         unsigned int flags = JFS_IP(inode)->mode2;
4488  
4489 -       inode->i_flags &= ~(S_IMMUTABLE | S_APPEND |
4490 -               S_NOATIME | S_DIRSYNC | S_SYNC);
4491 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
4492 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
4493  
4494         if (flags & JFS_IMMUTABLE_FL)
4495                 inode->i_flags |= S_IMMUTABLE;
4496 +       if (flags & JFS_IXUNLINK_FL)
4497 +               inode->i_flags |= S_IXUNLINK;
4498 +
4499 +       if (flags & JFS_SYNC_FL)
4500 +               inode->i_flags |= S_SYNC;
4501         if (flags & JFS_APPEND_FL)
4502                 inode->i_flags |= S_APPEND;
4503         if (flags & JFS_NOATIME_FL)
4504                 inode->i_flags |= S_NOATIME;
4505         if (flags & JFS_DIRSYNC_FL)
4506                 inode->i_flags |= S_DIRSYNC;
4507 -       if (flags & JFS_SYNC_FL)
4508 -               inode->i_flags |= S_SYNC;
4509 +
4510 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
4511 +
4512 +       if (flags & JFS_BARRIER_FL)
4513 +               inode->i_vflags |= V_BARRIER;
4514 +       if (flags & JFS_COW_FL)
4515 +               inode->i_vflags |= V_COW;
4516  }
4517  
4518  void jfs_get_inode_flags(struct jfs_inode_info *jfs_ip)
4519  {
4520         unsigned int flags = jfs_ip->vfs_inode.i_flags;
4521 +       unsigned int vflags = jfs_ip->vfs_inode.i_vflags;
4522 +
4523 +       jfs_ip->mode2 &= ~(JFS_IMMUTABLE_FL | JFS_IXUNLINK_FL |
4524 +                          JFS_APPEND_FL | JFS_NOATIME_FL |
4525 +                          JFS_DIRSYNC_FL | JFS_SYNC_FL |
4526 +                          JFS_BARRIER_FL | JFS_COW_FL);
4527  
4528 -       jfs_ip->mode2 &= ~(JFS_IMMUTABLE_FL | JFS_APPEND_FL | JFS_NOATIME_FL |
4529 -                          JFS_DIRSYNC_FL | JFS_SYNC_FL);
4530         if (flags & S_IMMUTABLE)
4531                 jfs_ip->mode2 |= JFS_IMMUTABLE_FL;
4532 +       if (flags & S_IXUNLINK)
4533 +               jfs_ip->mode2 |= JFS_IXUNLINK_FL;
4534 +
4535         if (flags & S_APPEND)
4536                 jfs_ip->mode2 |= JFS_APPEND_FL;
4537         if (flags & S_NOATIME)
4538 @@ -61,6 +79,11 @@ void jfs_get_inode_flags(struct jfs_inod
4539                 jfs_ip->mode2 |= JFS_DIRSYNC_FL;
4540         if (flags & S_SYNC)
4541                 jfs_ip->mode2 |= JFS_SYNC_FL;
4542 +
4543 +       if (vflags & V_BARRIER)
4544 +               jfs_ip->mode2 |= JFS_BARRIER_FL;
4545 +       if (vflags & V_COW)
4546 +               jfs_ip->mode2 |= JFS_COW_FL;
4547  }
4548  
4549  /*
4550 diff -NurpP --minimal linux-2.6.38.1/fs/jfs/jfs_inode.h linux-2.6.38.1-vs2.3.0.37-rc9/fs/jfs/jfs_inode.h
4551 --- linux-2.6.38.1/fs/jfs/jfs_inode.h   2010-10-21 13:07:50.000000000 +0200
4552 +++ linux-2.6.38.1-vs2.3.0.37-rc9/fs/jfs/jfs_inode.h    2011-01-29 02:01:07.000000000 +0100
4553 @@ -39,6 +39,7 @@ extern struct dentry *jfs_fh_to_dentry(s
4554  extern struct dentry *jfs_fh_to_parent(struct super_block *sb, struct fid *fid,
4555         int fh_len, int fh_type);
4556  extern void jfs_set_inode_flags(struct inode *);
4557 +extern int jfs_sync_flags(struct inode *, int, int);
4558  extern int jfs_get_block(struct inode *, sector_t, struct buffer_head *, int);
4559  extern int jfs_setattr(struct dentry *, struct iattr *);
4560  
4561 diff -NurpP --minimal linux-2.6.38.1/fs/jfs/namei.c linux-2.6.38.1-vs2.3.0.37-rc9/fs/jfs/namei.c
4562 --- linux-2.6.38.1/fs/jfs/namei.c       2011-03-15 18:07:32.000000000 +0100
4563 +++ linux-2.6.38.1-vs2.3.0.37-rc9/fs/jfs/namei.c        2011-03-15 18:15:06.000000000 +0100
4564 @@ -22,6 +22,7 @@
4565  #include <linux/ctype.h>
4566  #include <linux/quotaops.h>
4567  #include <linux/exportfs.h>
4568 +#include <linux/vs_tag.h>
4569  #include "jfs_incore.h"
4570  #include "jfs_superblock.h"
4571  #include "jfs_inode.h"
4572 @@ -1489,6 +1490,7 @@ static struct dentry *jfs_lookup(struct 
4573                 return ERR_CAST(ip);
4574         }
4575  
4576 +       dx_propagate_tag(nd, ip);
4577         return d_splice_alias(ip, dentry);
4578  }
4579  
4580 @@ -1553,6 +1555,7 @@ const struct inode_operations jfs_dir_in
4581  #ifdef CONFIG_JFS_POSIX_ACL
4582         .check_acl      = jfs_check_acl,
4583  #endif
4584 +       .sync_flags     = jfs_sync_flags,
4585  };
4586  
4587  const struct file_operations jfs_dir_operations = {
4588 diff -NurpP --minimal linux-2.6.38.1/fs/jfs/super.c linux-2.6.38.1-vs2.3.0.37-rc9/fs/jfs/super.c
4589 --- linux-2.6.38.1/fs/jfs/super.c       2011-03-15 18:07:32.000000000 +0100
4590 +++ linux-2.6.38.1-vs2.3.0.37-rc9/fs/jfs/super.c        2011-01-29 02:01:07.000000000 +0100
4591 @@ -198,7 +198,8 @@ static void jfs_put_super(struct super_b
4592  enum {
4593         Opt_integrity, Opt_nointegrity, Opt_iocharset, Opt_resize,
4594         Opt_resize_nosize, Opt_errors, Opt_ignore, Opt_err, Opt_quota,
4595 -       Opt_usrquota, Opt_grpquota, Opt_uid, Opt_gid, Opt_umask
4596 +       Opt_usrquota, Opt_grpquota, Opt_uid, Opt_gid, Opt_umask,
4597 +       Opt_tag, Opt_notag, Opt_tagid
4598  };
4599  
4600  static const match_table_t tokens = {
4601 @@ -208,6 +209,10 @@ static const match_table_t tokens = {
4602         {Opt_resize, "resize=%u"},
4603         {Opt_resize_nosize, "resize"},
4604         {Opt_errors, "errors=%s"},
4605 +       {Opt_tag, "tag"},
4606 +       {Opt_notag, "notag"},
4607 +       {Opt_tagid, "tagid=%u"},
4608 +       {Opt_tag, "tagxid"},
4609         {Opt_ignore, "noquota"},
4610         {Opt_ignore, "quota"},
4611         {Opt_usrquota, "usrquota"},
4612 @@ -342,6 +347,20 @@ static int parse_options(char *options, 
4613                         }
4614                         break;
4615                 }
4616 +#ifndef CONFIG_TAGGING_NONE
4617 +               case Opt_tag:
4618 +                       *flag |= JFS_TAGGED;
4619 +                       break;
4620 +               case Opt_notag:
4621 +                       *flag &= JFS_TAGGED;
4622 +                       break;
4623 +#endif
4624 +#ifdef CONFIG_PROPAGATE
4625 +               case Opt_tagid:
4626 +                       /* use args[0] */
4627 +                       *flag |= JFS_TAGGED;
4628 +                       break;
4629 +#endif
4630                 default:
4631                         printk("jfs: Unrecognized mount option \"%s\" "
4632                                         " or missing value\n", p);
4633 @@ -373,6 +392,12 @@ static int jfs_remount(struct super_bloc
4634                 return -EINVAL;
4635         }
4636  
4637 +       if ((flag & JFS_TAGGED) && !(sb->s_flags & MS_TAGGED)) {
4638 +               printk(KERN_ERR "JFS: %s: tagging not permitted on remount.\n",
4639 +                       sb->s_id);
4640 +               return -EINVAL;
4641 +       }
4642 +
4643         if (newLVSize) {
4644                 if (sb->s_flags & MS_RDONLY) {
4645                         printk(KERN_ERR
4646 @@ -455,6 +480,9 @@ static int jfs_fill_super(struct super_b
4647  #ifdef CONFIG_JFS_POSIX_ACL
4648         sb->s_flags |= MS_POSIXACL;
4649  #endif
4650 +       /* map mount option tagxid */
4651 +       if (sbi->flag & JFS_TAGGED)
4652 +               sb->s_flags |= MS_TAGGED;
4653  
4654         if (newLVSize) {
4655                 printk(KERN_ERR "resize option for remount only\n");
4656 diff -NurpP --minimal linux-2.6.38.1/fs/libfs.c linux-2.6.38.1-vs2.3.0.37-rc9/fs/libfs.c
4657 --- linux-2.6.38.1/fs/libfs.c   2011-03-15 18:07:32.000000000 +0100
4658 +++ linux-2.6.38.1-vs2.3.0.37-rc9/fs/libfs.c    2011-01-29 05:03:51.000000000 +0100
4659 @@ -133,7 +133,8 @@ static inline unsigned char dt_type(stru
4660   * both impossible due to the lock on directory.
4661   */
4662  
4663 -int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
4664 +static inline int do_dcache_readdir_filter(struct file *filp,
4665 +       void *dirent, filldir_t filldir, int (*filter)(struct dentry *dentry))
4666  {
4667         struct dentry *dentry = filp->f_path.dentry;
4668         struct dentry *cursor = filp->private_data;
4669 @@ -164,6 +165,8 @@ int dcache_readdir(struct file * filp, v
4670                         for (p=q->next; p != &dentry->d_subdirs; p=p->next) {
4671                                 struct dentry *next;
4672                                 next = list_entry(p, struct dentry, d_u.d_child);
4673 +                               if (filter && !filter(next))
4674 +                                       continue;
4675                                 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
4676                                 if (!simple_positive(next)) {
4677                                         spin_unlock(&next->d_lock);
4678 @@ -190,6 +193,17 @@ int dcache_readdir(struct file * filp, v
4679         return 0;
4680  }
4681  
4682 +int dcache_readdir(struct file *filp, void *dirent, filldir_t filldir)
4683 +{
4684 +       return do_dcache_readdir_filter(filp, dirent, filldir, NULL);
4685 +}
4686 +
4687 +int dcache_readdir_filter(struct file *filp, void *dirent, filldir_t filldir,
4688 +       int (*filter)(struct dentry *))
4689 +{
4690 +       return do_dcache_readdir_filter(filp, dirent, filldir, filter);
4691 +}
4692 +
4693  ssize_t generic_read_dir(struct file *filp, char __user *buf, size_t siz, loff_t *ppos)
4694  {
4695         return -EISDIR;
4696 @@ -965,6 +979,7 @@ EXPORT_SYMBOL(dcache_dir_close);
4697  EXPORT_SYMBOL(dcache_dir_lseek);
4698  EXPORT_SYMBOL(dcache_dir_open);
4699  EXPORT_SYMBOL(dcache_readdir);
4700 +EXPORT_SYMBOL(dcache_readdir_filter);
4701  EXPORT_SYMBOL(generic_read_dir);
4702  EXPORT_SYMBOL(mount_pseudo);
4703  EXPORT_SYMBOL(simple_write_begin);
4704 diff -NurpP --minimal linux-2.6.38.1/fs/locks.c linux-2.6.38.1-vs2.3.0.37-rc9/fs/locks.c
4705 --- linux-2.6.38.1/fs/locks.c   2011-03-15 18:07:32.000000000 +0100
4706 +++ linux-2.6.38.1-vs2.3.0.37-rc9/fs/locks.c    2011-01-29 02:01:07.000000000 +0100
4707 @@ -126,6 +126,8 @@
4708  #include <linux/time.h>
4709  #include <linux/rcupdate.h>
4710  #include <linux/pid_namespace.h>
4711 +#include <linux/vs_base.h>
4712 +#include <linux/vs_limit.h>
4713  
4714  #include <asm/uaccess.h>
4715  
4716 @@ -164,6 +166,8 @@ static struct kmem_cache *filelock_cache
4717  /* Allocate an empty lock structure. */
4718  struct file_lock *locks_alloc_lock(void)
4719  {
4720 +       if (!vx_locks_avail(1))
4721 +               return NULL;
4722         return kmem_cache_alloc(filelock_cache, GFP_KERNEL);
4723  }
4724  EXPORT_SYMBOL_GPL(locks_alloc_lock);
4725 @@ -191,6 +195,7 @@ void locks_free_lock(struct file_lock *f
4726         BUG_ON(!list_empty(&fl->fl_block));
4727         BUG_ON(!list_empty(&fl->fl_link));
4728  
4729 +       vx_locks_dec(fl);
4730         locks_release_private(fl);
4731         kmem_cache_free(filelock_cache, fl);
4732  }
4733 @@ -212,6 +217,7 @@ void locks_init_lock(struct file_lock *f
4734         fl->fl_start = fl->fl_end = 0;
4735         fl->fl_ops = NULL;
4736         fl->fl_lmops = NULL;
4737 +       fl->fl_xid = -1;
4738  }
4739  
4740  EXPORT_SYMBOL(locks_init_lock);
4741 @@ -263,6 +269,7 @@ void locks_copy_lock(struct file_lock *n
4742         new->fl_file = fl->fl_file;
4743         new->fl_ops = fl->fl_ops;
4744         new->fl_lmops = fl->fl_lmops;
4745 +       new->fl_xid = fl->fl_xid;
4746  
4747         locks_copy_private(new, fl);
4748  }
4749 @@ -301,6 +308,11 @@ static int flock_make_lock(struct file *
4750         fl->fl_flags = FL_FLOCK;
4751         fl->fl_type = type;
4752         fl->fl_end = OFFSET_MAX;
4753 +
4754 +       vxd_assert(filp->f_xid == vx_current_xid(),
4755 +               "f_xid(%d) == current(%d)", filp->f_xid, vx_current_xid());
4756 +       fl->fl_xid = filp->f_xid;
4757 +       vx_locks_inc(fl);
4758         
4759         *lock = fl;
4760         return 0;
4761 @@ -460,6 +472,7 @@ static int lease_init(struct file *filp,
4762  
4763         fl->fl_owner = current->files;
4764         fl->fl_pid = current->tgid;
4765 +       fl->fl_xid = vx_current_xid();
4766  
4767         fl->fl_file = filp;
4768         fl->fl_flags = FL_LEASE;
4769 @@ -479,6 +492,11 @@ static struct file_lock *lease_alloc(str
4770         if (fl == NULL)
4771                 return ERR_PTR(error);
4772  
4773 +       fl->fl_xid = vx_current_xid();
4774 +       if (filp)
4775 +               vxd_assert(filp->f_xid == fl->fl_xid,
4776 +                       "f_xid(%d) == fl_xid(%d)", filp->f_xid, fl->fl_xid);
4777 +       vx_locks_inc(fl);
4778         error = lease_init(filp, type, fl);
4779         if (error) {
4780                 locks_free_lock(fl);
4781 @@ -780,6 +798,7 @@ static int flock_lock_file(struct file *
4782                 lock_flocks();
4783         }
4784  
4785 +       new_fl->fl_xid = -1;
4786  find_conflict:
4787         for_each_lock(inode, before) {
4788                 struct file_lock *fl = *before;
4789 @@ -800,6 +819,7 @@ find_conflict:
4790                 goto out;
4791         locks_copy_lock(new_fl, request);
4792         locks_insert_lock(before, new_fl);
4793 +       vx_locks_inc(new_fl);
4794         new_fl = NULL;
4795         error = 0;
4796  
4797 @@ -810,7 +830,8 @@ out:
4798         return error;
4799  }
4800  
4801 -static int __posix_lock_file(struct inode *inode, struct file_lock *request, struct file_lock *conflock)
4802 +static int __posix_lock_file(struct inode *inode, struct file_lock *request,
4803 +       struct file_lock *conflock, xid_t xid)
4804  {
4805         struct file_lock *fl;
4806         struct file_lock *new_fl = NULL;
4807 @@ -820,6 +841,8 @@ static int __posix_lock_file(struct inod
4808         struct file_lock **before;
4809         int error, added = 0;
4810  
4811 +       vxd_assert(xid == vx_current_xid(),
4812 +               "xid(%d) == current(%d)", xid, vx_current_xid());
4813         /*
4814          * We may need two file_lock structures for this operation,
4815          * so we get them in advance to avoid races.
4816 @@ -830,7 +853,11 @@ static int __posix_lock_file(struct inod
4817             (request->fl_type != F_UNLCK ||
4818              request->fl_start != 0 || request->fl_end != OFFSET_MAX)) {
4819                 new_fl = locks_alloc_lock();
4820 +               new_fl->fl_xid = xid;
4821 +               vx_locks_inc(new_fl);
4822                 new_fl2 = locks_alloc_lock();
4823 +               new_fl2->fl_xid = xid;
4824 +               vx_locks_inc(new_fl2);
4825         }
4826  
4827         lock_flocks();
4828 @@ -1029,7 +1056,8 @@ static int __posix_lock_file(struct inod
4829  int posix_lock_file(struct file *filp, struct file_lock *fl,
4830                         struct file_lock *conflock)
4831  {
4832 -       return __posix_lock_file(filp->f_path.dentry->d_inode, fl, conflock);
4833 +       return __posix_lock_file(filp->f_path.dentry->d_inode,
4834 +               fl, conflock, filp->f_xid);
4835  }
4836  EXPORT_SYMBOL(posix_lock_file);
4837  
4838 @@ -1119,7 +1147,7 @@ int locks_mandatory_area(int read_write,
4839         fl.fl_end = offset + count - 1;
4840  
4841         for (;;) {
4842 -               error = __posix_lock_file(inode, &fl, NULL);
4843 +               error = __posix_lock_file(inode, &fl, NULL, filp->f_xid);
4844                 if (error != FILE_LOCK_DEFERRED)
4845                         break;
4846                 error = wait_event_interruptible(fl.fl_wait, !fl.fl_next);
4847 @@ -1432,6 +1460,7 @@ int generic_setlease(struct file *filp, 
4848                 goto out;
4849  
4850         locks_insert_lock(before, lease);
4851 +       vx_locks_inc(lease);
4852         return 0;
4853  
4854  out:
4855 @@ -1816,6 +1845,11 @@ int fcntl_setlk(unsigned int fd, struct 
4856         if (file_lock == NULL)
4857                 return -ENOLCK;
4858  
4859 +       vxd_assert(filp->f_xid == vx_current_xid(),
4860 +               "f_xid(%d) == current(%d)", filp->f_xid, vx_current_xid());
4861 +       file_lock->fl_xid = filp->f_xid;
4862 +       vx_locks_inc(file_lock);
4863 +
4864         /*
4865          * This might block, so we do it before checking the inode.
4866          */
4867 @@ -1934,6 +1968,11 @@ int fcntl_setlk64(unsigned int fd, struc
4868         if (file_lock == NULL)
4869                 return -ENOLCK;
4870  
4871 +       vxd_assert(filp->f_xid == vx_current_xid(),
4872 +               "f_xid(%d) == current(%d)", filp->f_xid, vx_current_xid());
4873 +       file_lock->fl_xid = filp->f_xid;
4874 +       vx_locks_inc(file_lock);
4875 +
4876         /*
4877          * This might block, so we do it before checking the inode.
4878          */
4879 @@ -2199,8 +2238,11 @@ static int locks_show(struct seq_file *f
4880  
4881         lock_get_status(f, fl, *((loff_t *)f->private), "");
4882  
4883 -       list_for_each_entry(bfl, &fl->fl_block, fl_block)
4884 +       list_for_each_entry(bfl, &fl->fl_block, fl_block) {
4885 +               if (!vx_check(fl->fl_xid, VS_WATCH_P | VS_IDENT))
4886 +                       continue;
4887                 lock_get_status(f, bfl, *((loff_t *)f->private), " ->");
4888 +       }
4889  
4890         return 0;
4891  }
4892 diff -NurpP --minimal linux-2.6.38.1/fs/namei.c linux-2.6.38.1-vs2.3.0.37-rc9/fs/namei.c
4893 --- linux-2.6.38.1/fs/namei.c   2011-03-15 18:07:32.000000000 +0100
4894 +++ linux-2.6.38.1-vs2.3.0.37-rc9/fs/namei.c    2011-03-15 18:17:37.000000000 +0100
4895 @@ -32,6 +32,14 @@
4896  #include <linux/fcntl.h>
4897  #include <linux/device_cgroup.h>
4898  #include <linux/fs_struct.h>
4899 +#include <linux/proc_fs.h>
4900 +#include <linux/vserver/inode.h>
4901 +#include <linux/vs_base.h>
4902 +#include <linux/vs_tag.h>
4903 +#include <linux/vs_cowbl.h>
4904 +#include <linux/vs_device.h>
4905 +#include <linux/vs_context.h>
4906 +#include <linux/pid_namespace.h>
4907  #include <asm/uaccess.h>
4908  
4909  #include "internal.h"
4910 @@ -166,6 +174,84 @@ void putname(const char *name)
4911  EXPORT_SYMBOL(putname);
4912  #endif
4913  
4914 +static inline int dx_barrier(const struct inode *inode)
4915 +{
4916 +       if (IS_BARRIER(inode) && !vx_check(0, VS_ADMIN | VS_WATCH)) {
4917 +               vxwprintk_task(1, "did hit the barrier.");
4918 +               return 1;
4919 +       }
4920 +       return 0;
4921 +}
4922 +
4923 +static int __dx_permission(const struct inode *inode, int mask)
4924 +{
4925 +       if (dx_barrier(inode))
4926 +               return -EACCES;
4927 +
4928 +       if (inode->i_sb->s_magic == DEVPTS_SUPER_MAGIC) {
4929 +               /* devpts is xid tagged */
4930 +               if (S_ISDIR(inode->i_mode) ||
4931 +                   vx_check((xid_t)inode->i_tag, VS_IDENT | VS_WATCH_P))
4932 +                       return 0;
4933 +
4934 +               /* just pretend we didn't find anything */
4935 +               return -ENOENT;
4936 +       }
4937 +       else if (inode->i_sb->s_magic == PROC_SUPER_MAGIC) {
4938 +               struct proc_dir_entry *de = PDE(inode);
4939 +
4940 +               if (de && !vx_hide_check(0, de->vx_flags))
4941 +                       goto out;
4942 +
4943 +               if ((mask & (MAY_WRITE | MAY_APPEND))) {
4944 +                       struct pid *pid;
4945 +                       struct task_struct *tsk;
4946 +
4947 +                       if (vx_check(0, VS_ADMIN | VS_WATCH_P) ||
4948 +                           vx_flags(VXF_STATE_SETUP, 0))
4949 +                               return 0;
4950 +
4951 +                       pid = PROC_I(inode)->pid;
4952 +                       if (!pid)
4953 +                               goto out;
4954 +
4955 +                       tsk = pid_task(pid, PIDTYPE_PID);
4956 +                       vxdprintk(VXD_CBIT(tag, 0), "accessing %p[#%u]",
4957 +                                 tsk, (tsk ? vx_task_xid(tsk) : 0));
4958 +                       if (tsk && vx_check(vx_task_xid(tsk), VS_IDENT | VS_WATCH_P))
4959 +                               return 0;
4960 +               }
4961 +               else {
4962 +                       /* FIXME: Should we block some entries here? */
4963 +                       return 0;
4964 +               }
4965 +       }
4966 +       else {
4967 +               if (dx_notagcheck(inode->i_sb) ||
4968 +                   dx_check(inode->i_tag, DX_HOSTID | DX_ADMIN | DX_WATCH |
4969 +                            DX_IDENT))
4970 +                       return 0;
4971 +       }
4972 +
4973 +out:
4974 +       return -EACCES;
4975 +}
4976 +
4977 +int dx_permission(const struct inode *inode, int mask)
4978 +{
4979 +       int ret = __dx_permission(inode, mask);
4980 +       if (unlikely(ret)) {
4981 +#ifndef        CONFIG_VSERVER_WARN_DEVPTS
4982 +               if (inode->i_sb->s_magic != DEVPTS_SUPER_MAGIC)
4983 +#endif
4984 +                   vxwprintk_task(1,
4985 +                       "denied [0x%x] access to inode %s:%p[#%d,%lu]",
4986 +                       mask, inode->i_sb->s_id, inode, inode->i_tag,
4987 +                       inode->i_ino);
4988 +       }
4989 +       return ret;
4990 +}
4991 +
4992  /*
4993   * This does basic POSIX ACL permission checking
4994   */
4995 @@ -271,10 +357,14 @@ int inode_permission(struct inode *inode
4996                 /*
4997                  * Nobody gets write access to an immutable file.
4998                  */
4999 -               if (IS_IMMUTABLE(inode))
5000 +               if (IS_IMMUTABLE(inode) && !IS_COW(inode))
5001                         return -EACCES;
5002         }
5003  
5004 +       retval = dx_permission(inode, mask);
5005 +       if (retval)
5006 +               return retval;
5007 +
5008         if (inode->i_op->permission)
5009                 retval = inode->i_op->permission(inode, mask, 0);
5010         else
5011 @@ -676,6 +766,9 @@ static inline int exec_permission(struct
5012  {
5013         int ret;
5014  
5015 +       if (dx_barrier(inode))
5016 +               return -EACCES;
5017 +
5018         if (inode->i_op->permission) {
5019                 ret = inode->i_op->permission(inode, MAY_EXEC, flags);
5020         } else {
5021 @@ -1162,7 +1255,8 @@ static void follow_dotdot(struct nameida
5022  
5023                 if (nd->path.dentry == nd->root.dentry &&
5024                     nd->path.mnt == nd->root.mnt) {
5025 -                       break;
5026 +                       /* for sane '/' avoid follow_mount() */
5027 +                       return;
5028                 }
5029                 if (nd->path.dentry != nd->path.mnt->mnt_root) {
5030                         /* rare case of legitimate dget_parent()... */
5031 @@ -1216,7 +1310,7 @@ static int do_lookup(struct nameidata *n
5032  {
5033         struct vfsmount *mnt = nd->path.mnt;
5034         struct dentry *dentry, *parent = nd->path.dentry;
5035 -       struct inode *dir;
5036 +       struct inode *dir, *d_inode;
5037         int err;
5038  
5039         /*
5040 @@ -1277,6 +1371,13 @@ found:
5041                 if (IS_ERR(dentry))
5042                         goto fail;
5043         }
5044 +
5045 +       d_inode = dentry->d_inode;
5046 +       if (!d_inode)
5047 +               goto done;
5048 +
5049 +       if (__dx_permission(d_inode, MAY_ACCESS))
5050 +               goto hidden;
5051  done:
5052         path->mnt = mnt;
5053         path->dentry = dentry;
5054 @@ -1288,6 +1389,18 @@ done:
5055         *inode = path->dentry->d_inode;
5056         return 0;
5057  
5058 +hidden:
5059 +#ifndef        CONFIG_VSERVER_WARN_DEVPTS
5060 +       if (d_inode->i_sb->s_magic != DEVPTS_SUPER_MAGIC)
5061 +#endif
5062 +           vxwprintk_task(1,
5063 +               "did lookup hidden %s:%p[#%d,%lu] " VS_Q("%s/%.*s") ".",
5064 +               d_inode->i_sb->s_id, d_inode, d_inode->i_tag, d_inode->i_ino,
5065 +               vxd_path(&nd->path), name->len, name->name);
5066 +
5067 +       dput(dentry);
5068 +       return -ENOENT;
5069 +
5070  need_lookup:
5071         dir = parent->d_inode;
5072         BUG_ON(nd->inode != dir);
5073 @@ -1982,7 +2095,7 @@ static int may_delete(struct inode *dir,
5074         if (IS_APPEND(dir))
5075                 return -EPERM;
5076         if (check_sticky(dir, victim->d_inode)||IS_APPEND(victim->d_inode)||
5077 -           IS_IMMUTABLE(victim->d_inode) || IS_SWAPFILE(victim->d_inode))
5078 +               IS_IXORUNLINK(victim->d_inode) || IS_SWAPFILE(victim->d_inode))
5079                 return -EPERM;
5080         if (isdir) {
5081                 if (!S_ISDIR(victim->d_inode->i_mode))
5082 @@ -2105,6 +2218,14 @@ int may_open(struct path *path, int acc_
5083                 break;
5084         }
5085  
5086 +#ifdef CONFIG_VSERVER_COWBL
5087 +       if (IS_COW(inode) && (flag & FMODE_WRITE)) {
5088 +               if (IS_COW_LINK(inode))
5089 +                       return -EMLINK;
5090 +               inode->i_flags &= ~(S_IXUNLINK|S_IMMUTABLE);
5091 +               mark_inode_dirty(inode);
5092 +       }
5093 +#endif
5094         error = inode_permission(inode, acc_mode);
5095         if (error)
5096                 return error;
5097 @@ -2215,7 +2336,8 @@ static int open_will_truncate(int flag, 
5098  }
5099  
5100  static struct file *finish_open(struct nameidata *nd,
5101 -                               int open_flag, int acc_mode)
5102 +                               int open_flag, int acc_mode,
5103 +                               const char *pathname)
5104  {
5105         struct file *filp;
5106         int will_truncate;
5107 @@ -2228,6 +2350,23 @@ static struct file *finish_open(struct n
5108                         goto exit;
5109         }
5110         error = may_open(&nd->path, acc_mode, open_flag);
5111 +#ifdef CONFIG_VSERVER_COWBL
5112 +       if (error == -EMLINK) {
5113 +               struct dentry *dentry;
5114 +               dentry = cow_break_link(pathname);
5115 +               if (IS_ERR(dentry)) {
5116 +                       error = PTR_ERR(dentry);
5117 +                       goto exit_cow;
5118 +               }
5119 +               dput(dentry);
5120 +               if (will_truncate)
5121 +                       mnt_drop_write(nd->path.mnt);
5122 +               release_open_intent(nd);
5123 +               path_put(&nd->path);
5124 +               return ERR_PTR(-EMLINK);
5125 +       }
5126 +exit_cow:
5127 +#endif
5128         if (error) {
5129                 if (will_truncate)
5130                         mnt_drop_write(nd->path.mnt);
5131 @@ -2375,7 +2514,7 @@ static struct file *do_last(struct namei
5132         if (S_ISDIR(nd->inode->i_mode))
5133                 goto exit;
5134  ok:
5135 -       filp = finish_open(nd, open_flag, acc_mode);
5136 +       filp = finish_open(nd, open_flag, acc_mode, pathname);
5137         return filp;
5138  
5139  exit_mutex_unlock:
5140 @@ -2402,7 +2541,12 @@ struct file *do_filp_open(int dfd, const
5141         int count = 0;
5142         int flag = open_to_namei_flags(open_flag);
5143         int flags;
5144 +#ifdef CONFIG_VSERVER_COWBL
5145 +       int rflag = flag;
5146 +       int rmode = mode;
5147  
5148 +restart:
5149 +#endif
5150         if (!(open_flag & O_CREAT))
5151                 mode = 0;
5152  
5153 @@ -2468,7 +2612,7 @@ struct file *do_filp_open(int dfd, const
5154                         goto out_path2;
5155         }
5156         audit_inode(pathname, nd.path.dentry);
5157 -       filp = finish_open(&nd, open_flag, acc_mode);
5158 +       filp = finish_open(&nd, open_flag, acc_mode, pathname);
5159  out2:
5160         release_open_intent(&nd);
5161         return filp;
5162 @@ -2510,6 +2654,13 @@ reval:
5163          */
5164         nd.flags = flags;
5165         filp = do_last(&nd, &path, open_flag, acc_mode, mode, pathname);
5166 +#ifdef CONFIG_VSERVER_COWBL
5167 +       if (unlikely(IS_ERR(filp) && PTR_ERR(filp) == -EMLINK)) {
5168 +               flag = rflag;
5169 +               mode = rmode;
5170 +               goto restart;
5171 +       }
5172 +#endif
5173         while (unlikely(!filp)) { /* trailing symlink */
5174                 struct path link = path;
5175                 struct inode *linki = link.dentry->d_inode;
5176 @@ -2544,6 +2695,13 @@ reval:
5177                 }
5178                 nd.flags &= ~LOOKUP_PARENT;
5179                 filp = do_last(&nd, &path, open_flag, acc_mode, mode, pathname);
5180 +#ifdef CONFIG_VSERVER_COWBL
5181 +               if (unlikely(IS_ERR(filp) && PTR_ERR(filp) == -EMLINK)) {
5182 +                       flag = rflag;
5183 +                       mode = rmode;
5184 +                       goto restart;
5185 +               }
5186 +#endif
5187                 if (linki->i_op->put_link)
5188                         linki->i_op->put_link(link.dentry, &nd, cookie);
5189                 path_put(&link);
5190 @@ -2642,9 +2800,17 @@ int vfs_mknod(struct inode *dir, struct 
5191         if (error)
5192                 return error;
5193  
5194 -       if ((S_ISCHR(mode) || S_ISBLK(mode)) && !capable(CAP_MKNOD))
5195 +       if (!(S_ISCHR(mode) || S_ISBLK(mode)))
5196 +               goto okay;
5197 +
5198 +       if (!capable(CAP_MKNOD))
5199                 return -EPERM;
5200  
5201 +       if (S_ISCHR(mode) && !vs_chrdev_perm(dev, DATTR_CREATE))
5202 +               return -EPERM;
5203 +       if (S_ISBLK(mode) && !vs_blkdev_perm(dev, DATTR_CREATE))
5204 +               return -EPERM;
5205 +okay:
5206         if (!dir->i_op->mknod)
5207                 return -EPERM;
5208  
5209 @@ -3107,7 +3273,7 @@ int vfs_link(struct dentry *old_dentry, 
5210         /*
5211          * A link to an append-only or immutable file cannot be created.
5212          */
5213 -       if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
5214 +       if (IS_APPEND(inode) || IS_IXORUNLINK(inode))
5215                 return -EPERM;
5216         if (!dir->i_op->link)
5217                 return -EPERM;
5218 @@ -3479,6 +3645,222 @@ int vfs_follow_link(struct nameidata *nd
5219         return __vfs_follow_link(nd, link);
5220  }
5221  
5222 +
5223 +#ifdef CONFIG_VSERVER_COWBL
5224 +
5225 +#include <linux/file.h>
5226 +
5227 +static inline
5228 +long do_cow_splice(struct file *in, struct file *out, size_t len)
5229 +{
5230 +       loff_t ppos = 0;
5231 +
5232 +       return do_splice_direct(in, &ppos, out, len, 0);
5233 +}
5234 +
5235 +struct dentry *cow_break_link(const char *pathname)
5236 +{
5237 +       int ret, mode, pathlen, redo = 0;
5238 +       struct nameidata old_nd, dir_nd;
5239 +       struct path old_path, new_path;
5240 +       struct dentry *dir, *res = NULL;
5241 +       struct file *old_file;
5242 +       struct file *new_file;
5243 +       char *to, *path, pad='\251';
5244 +       loff_t size;
5245 +
5246 +       vxdprintk(VXD_CBIT(misc, 1),
5247 +               "cow_break_link(" VS_Q("%s") ")", pathname);
5248 +       path = kmalloc(PATH_MAX, GFP_KERNEL);
5249 +       ret = -ENOMEM;
5250 +       if (!path)
5251 +               goto out;
5252 +
5253 +       /* old_nd will have refs to dentry and mnt */
5254 +       ret = path_lookup(pathname, LOOKUP_FOLLOW, &old_nd);
5255 +       vxdprintk(VXD_CBIT(misc, 2), "path_lookup(old): %d", ret);
5256 +       if (ret < 0)
5257 +               goto out_free_path;
5258 +
5259 +       old_path = old_nd.path;
5260 +       mode = old_path.dentry->d_inode->i_mode;
5261 +
5262 +       to = d_path(&old_path, path, PATH_MAX-2);
5263 +       pathlen = strlen(to);
5264 +       vxdprintk(VXD_CBIT(misc, 2),
5265 +               "old path " VS_Q("%s") " [" VS_Q("%.*s") ":%d]", to,
5266 +               old_path.dentry->d_name.len, old_path.dentry->d_name.name,
5267 +               old_path.dentry->d_name.len);
5268 +
5269 +       to[pathlen + 1] = 0;
5270 +retry:
5271 +       to[pathlen] = pad--;
5272 +       ret = -EMLINK;
5273 +       if (pad <= '\240')
5274 +               goto out_rel_old;
5275 +
5276 +       vxdprintk(VXD_CBIT(misc, 1), "temp copy " VS_Q("%s"), to);
5277 +       /* dir_nd will have refs to dentry and mnt */
5278 +       ret = path_lookup(to,
5279 +               LOOKUP_PARENT | LOOKUP_OPEN | LOOKUP_CREATE, &dir_nd);
5280 +       vxdprintk(VXD_CBIT(misc, 2),
5281 +               "path_lookup(new): %d", ret);
5282 +       if (ret < 0)
5283 +               goto retry;
5284 +
5285 +       /* this puppy downs the inode mutex */
5286 +       new_path.dentry = lookup_create(&dir_nd, 0);
5287 +       if (!new_path.dentry || IS_ERR(new_path.dentry)) {
5288 +               vxdprintk(VXD_CBIT(misc, 2),
5289 +                       "lookup_create(new): %p", new_path.dentry);
5290 +               mutex_unlock(&dir_nd.path.dentry->d_inode->i_mutex);
5291 +               path_put(&dir_nd.path);
5292 +               goto retry;
5293 +       }
5294 +       vxdprintk(VXD_CBIT(misc, 2),
5295 +               "lookup_create(new): %p [" VS_Q("%.*s") ":%d]",
5296 +               new_path.dentry,
5297 +               new_path.dentry->d_name.len, new_path.dentry->d_name.name,
5298 +               new_path.dentry->d_name.len);
5299 +       dir = dir_nd.path.dentry;
5300 +
5301 +       ret = vfs_create(dir_nd.path.dentry->d_inode, new_path.dentry, mode, &dir_nd);
5302 +       vxdprintk(VXD_CBIT(misc, 2),
5303 +               "vfs_create(new): %d", ret);
5304 +       if (ret == -EEXIST) {
5305 +               mutex_unlock(&dir->d_inode->i_mutex);
5306 +               dput(new_path.dentry);
5307 +               path_put(&dir_nd.path);
5308 +               goto retry;
5309 +       }
5310 +       else if (ret < 0)
5311 +               goto out_unlock_new;
5312 +
5313 +       /* drop out early, ret passes ENOENT */
5314 +       ret = -ENOENT;
5315 +       if ((redo = d_unhashed(old_path.dentry)))
5316 +               goto out_unlock_new;
5317 +
5318 +       new_path.mnt = dir_nd.path.mnt;
5319 +       dget(old_path.dentry);
5320 +       mntget(old_path.mnt);
5321 +       /* this one cleans up the dentry/mnt in case of failure */
5322 +       old_file = dentry_open(old_path.dentry, old_path.mnt,
5323 +               O_RDONLY, current_cred());
5324 +       vxdprintk(VXD_CBIT(misc, 2),
5325 +               "dentry_open(old): %p", old_file);
5326 +       if (!old_file || IS_ERR(old_file)) {
5327 +               res = IS_ERR(old_file) ? (void *) old_file : res;
5328 +               goto out_unlock_new;
5329 +       }
5330 +
5331 +       dget(new_path.dentry);
5332 +       mntget(new_path.mnt);
5333 +       /* this one cleans up the dentry/mnt in case of failure */
5334 +       new_file = dentry_open(new_path.dentry, new_path.mnt,
5335 +               O_WRONLY, current_cred());
5336 +       vxdprintk(VXD_CBIT(misc, 2),
5337 +               "dentry_open(new): %p", new_file);
5338 +
5339 +       ret = IS_ERR(new_file) ? PTR_ERR(new_file) : -ENOENT;
5340 +       if (!new_file || IS_ERR(new_file))
5341 +               goto out_fput_old;
5342 +
5343 +       size = i_size_read(old_file->f_dentry->d_inode);
5344 +       ret = do_cow_splice(old_file, new_file, size);
5345 +       vxdprintk(VXD_CBIT(misc, 2), "do_splice_direct: %d", ret);
5346 +       if (ret < 0) {
5347 +               goto out_fput_both;
5348 +       } else if (ret < size) {
5349 +               ret = -ENOSPC;
5350 +               goto out_fput_both;
5351 +       } else {
5352 +               struct inode *old_inode = old_path.dentry->d_inode;
5353 +               struct inode *new_inode = new_path.dentry->d_inode;
5354 +               struct iattr attr = {
5355 +                       .ia_uid = old_inode->i_uid,
5356 +                       .ia_gid = old_inode->i_gid,
5357 +                       .ia_valid = ATTR_UID | ATTR_GID
5358 +                       };
5359 +
5360 +               setattr_copy(new_inode, &attr);
5361 +               mark_inode_dirty(new_inode);
5362 +       }
5363 +
5364 +       mutex_lock(&old_path.dentry->d_inode->i_sb->s_vfs_rename_mutex);
5365 +
5366 +       /* drop out late */
5367 +       ret = -ENOENT;
5368 +       if ((redo = d_unhashed(old_path.dentry)))
5369 +               goto out_unlock;
5370 +
5371 +       vxdprintk(VXD_CBIT(misc, 2),
5372 +               "vfs_rename: [" VS_Q("%*s") ":%d] -> [" VS_Q("%*s") ":%d]",
5373 +               new_path.dentry->d_name.len, new_path.dentry->d_name.name,
5374 +               new_path.dentry->d_name.len,
5375 +               old_path.dentry->d_name.len, old_path.dentry->d_name.name,
5376 +               old_path.dentry->d_name.len);
5377 +       ret = vfs_rename(dir_nd.path.dentry->d_inode, new_path.dentry,
5378 +               old_nd.path.dentry->d_parent->d_inode, old_path.dentry);
5379 +       vxdprintk(VXD_CBIT(misc, 2), "vfs_rename: %d", ret);
5380 +       res = new_path.dentry;
5381 +
5382 +out_unlock:
5383 +       mutex_unlock(&old_path.dentry->d_inode->i_sb->s_vfs_rename_mutex);
5384 +
5385 +out_fput_both:
5386 +       vxdprintk(VXD_CBIT(misc, 3),
5387 +               "fput(new_file=%p[#%ld])", new_file,
5388 +               atomic_long_read(&new_file->f_count));
5389 +       fput(new_file);
5390 +
5391 +out_fput_old:
5392 +       vxdprintk(VXD_CBIT(misc, 3),
5393 +               "fput(old_file=%p[#%ld])", old_file,
5394 +               atomic_long_read(&old_file->f_count));
5395 +       fput(old_file);
5396 +
5397 +out_unlock_new:
5398 +       mutex_unlock(&dir->d_inode->i_mutex);
5399 +       if (!ret)
5400 +               goto out_redo;
5401 +
5402 +       /* error path cleanup */
5403 +       vfs_unlink(dir->d_inode, new_path.dentry);
5404 +       dput(new_path.dentry);
5405 +
5406 +out_redo:
5407 +       if (!redo)
5408 +               goto out_rel_both;
5409 +       /* lookup dentry once again */
5410 +       path_put(&old_nd.path);
5411 +       ret = path_lookup(pathname, LOOKUP_FOLLOW, &old_nd);
5412 +       if (ret)
5413 +               goto out_rel_both;
5414 +
5415 +       new_path.dentry = old_nd.path.dentry;
5416 +       vxdprintk(VXD_CBIT(misc, 2),
5417 +               "path_lookup(redo): %p [" VS_Q("%.*s") ":%d]",
5418 +               new_path.dentry,
5419 +               new_path.dentry->d_name.len, new_path.dentry->d_name.name,
5420 +               new_path.dentry->d_name.len);
5421 +       dget(new_path.dentry);
5422 +       res = new_path.dentry;
5423 +
5424 +out_rel_both:
5425 +       path_put(&dir_nd.path);
5426 +out_rel_old:
5427 +       path_put(&old_nd.path);
5428 +out_free_path:
5429 +       kfree(path);
5430 +out:
5431 +       if (ret)
5432 +               res = ERR_PTR(ret);
5433 +       return res;
5434 +}
5435 +
5436 +#endif
5437 +
5438  /* get the link contents into pagecache */
5439  static char *page_getlink(struct dentry * dentry, struct page **ppage)
5440  {
5441 diff -NurpP --minimal linux-2.6.38.1/fs/namespace.c linux-2.6.38.1-vs2.3.0.37-rc9/fs/namespace.c
5442 --- linux-2.6.38.1/fs/namespace.c       2011-03-15 18:07:32.000000000 +0100
5443 +++ linux-2.6.38.1-vs2.3.0.37-rc9/fs/namespace.c        2011-03-07 16:53:27.000000000 +0100
5444 @@ -31,6 +31,11 @@
5445  #include <linux/idr.h>
5446  #include <linux/fs_struct.h>
5447  #include <linux/fsnotify.h>
5448 +#include <linux/vs_base.h>
5449 +#include <linux/vs_context.h>
5450 +#include <linux/vs_tag.h>
5451 +#include <linux/vserver/space.h>
5452 +#include <linux/vserver/global.h>
5453  #include <asm/uaccess.h>
5454  #include <asm/unistd.h>
5455  #include "pnode.h"
5456 @@ -702,6 +707,7 @@ static struct vfsmount *clone_mnt(struct
5457                 mnt->mnt_root = dget(root);
5458                 mnt->mnt_mountpoint = mnt->mnt_root;
5459                 mnt->mnt_parent = mnt;
5460 +               mnt->mnt_tag = old->mnt_tag;
5461  
5462                 if (flag & CL_SLAVE) {
5463                         list_add(&mnt->mnt_slave, &old->mnt_slave_list);
5464 @@ -830,6 +836,31 @@ static inline void mangle(struct seq_fil
5465         seq_escape(m, s, " \t\n\\");
5466  }
5467  
5468 +static int mnt_is_reachable(struct vfsmount *mnt)
5469 +{
5470 +       struct path root;
5471 +       struct dentry *point;
5472 +       int ret;
5473 +
5474 +       if (mnt == mnt->mnt_ns->root)
5475 +               return 1;
5476 +
5477 +       br_read_lock(vfsmount_lock);
5478 +       root = current->fs->root;
5479 +       point = root.dentry;
5480 +
5481 +       while ((mnt != mnt->mnt_parent) && (mnt != root.mnt)) {
5482 +               point = mnt->mnt_mountpoint;
5483 +               mnt = mnt->mnt_parent;
5484 +       }
5485 +
5486 +       ret = (mnt == root.mnt) && is_subdir(point, root.dentry);
5487 +
5488 +       br_read_unlock(vfsmount_lock);
5489 +
5490 +       return ret;
5491 +}
5492 +
5493  /*
5494   * Simple .show_options callback for filesystems which don't want to
5495   * implement more complex mount option showing.
5496 @@ -932,6 +963,8 @@ static int show_sb_opts(struct seq_file 
5497                 { MS_SYNCHRONOUS, ",sync" },
5498                 { MS_DIRSYNC, ",dirsync" },
5499                 { MS_MANDLOCK, ",mand" },
5500 +               { MS_TAGGED, ",tag" },
5501 +               { MS_NOTAGCHECK, ",notagcheck" },
5502                 { 0, NULL }
5503         };
5504         const struct proc_fs_info *fs_infop;
5505 @@ -978,10 +1011,20 @@ static int show_vfsmnt(struct seq_file *
5506         int err = 0;
5507         struct path mnt_path = { .dentry = mnt->mnt_root, .mnt = mnt };
5508  
5509 -       mangle(m, mnt->mnt_devname ? mnt->mnt_devname : "none");
5510 -       seq_putc(m, ' ');
5511 -       seq_path(m, &mnt_path, " \t\n\\");
5512 -       seq_putc(m, ' ');
5513 +       if (vx_flags(VXF_HIDE_MOUNT, 0))
5514 +               return SEQ_SKIP;
5515 +       if (!mnt_is_reachable(mnt) && !vx_check(0, VS_WATCH_P))
5516 +               return SEQ_SKIP;
5517 +
5518 +       if (!vx_check(0, VS_ADMIN|VS_WATCH) &&
5519 +               mnt == current->fs->root.mnt) {
5520 +               seq_puts(m, "/dev/root / ");
5521 +       } else {
5522 +               mangle(m, mnt->mnt_devname ? mnt->mnt_devname : "none");
5523 +               seq_putc(m, ' ');
5524 +               seq_path(m, &mnt_path, " \t\n\\");
5525 +               seq_putc(m, ' ');
5526 +       }
5527         show_type(m, mnt->mnt_sb);
5528         seq_puts(m, __mnt_is_readonly(mnt) ? " ro" : " rw");
5529         err = show_sb_opts(m, mnt->mnt_sb);
5530 @@ -1011,6 +1054,11 @@ static int show_mountinfo(struct seq_fil
5531         struct path root = p->root;
5532         int err = 0;
5533  
5534 +       if (vx_flags(VXF_HIDE_MOUNT, 0))
5535 +               return SEQ_SKIP;
5536 +       if (!mnt_is_reachable(mnt) && !vx_check(0, VS_WATCH_P))
5537 +               return SEQ_SKIP;
5538 +
5539         seq_printf(m, "%i %i %u:%u ", mnt->mnt_id, mnt->mnt_parent->mnt_id,
5540                    MAJOR(sb->s_dev), MINOR(sb->s_dev));
5541         seq_dentry(m, mnt->mnt_root, " \t\n\\");
5542 @@ -1069,17 +1117,27 @@ static int show_vfsstat(struct seq_file 
5543         struct path mnt_path = { .dentry = mnt->mnt_root, .mnt = mnt };
5544         int err = 0;
5545  
5546 -       /* device */
5547 -       if (mnt->mnt_devname) {
5548 -               seq_puts(m, "device ");
5549 -               mangle(m, mnt->mnt_devname);
5550 -       } else
5551 -               seq_puts(m, "no device");
5552 +       if (vx_flags(VXF_HIDE_MOUNT, 0))
5553 +               return SEQ_SKIP;
5554 +       if (!mnt_is_reachable(mnt) && !vx_check(0, VS_WATCH_P))
5555 +               return SEQ_SKIP;
5556  
5557 -       /* mount point */
5558 -       seq_puts(m, " mounted on ");
5559 -       seq_path(m, &mnt_path, " \t\n\\");
5560 -       seq_putc(m, ' ');
5561 +       if (!vx_check(0, VS_ADMIN|VS_WATCH) &&
5562 +               mnt == current->fs->root.mnt) {
5563 +               seq_puts(m, "device /dev/root mounted on / ");
5564 +       } else {
5565 +               /* device */
5566 +               if (mnt->mnt_devname) {
5567 +                       seq_puts(m, "device ");
5568 +                       mangle(m, mnt->mnt_devname);
5569 +               } else
5570 +                       seq_puts(m, "no device");
5571 +
5572 +               /* mount point */
5573 +               seq_puts(m, " mounted on ");
5574 +               seq_path(m, &mnt_path, " \t\n\\");
5575 +               seq_putc(m, ' ');
5576 +       }
5577  
5578         /* file system type */
5579         seq_puts(m, "with fstype ");
5580 @@ -1337,7 +1395,7 @@ SYSCALL_DEFINE2(umount, char __user *, n
5581                 goto dput_and_out;
5582  
5583         retval = -EPERM;
5584 -       if (!capable(CAP_SYS_ADMIN))
5585 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SECURE_MOUNT))
5586                 goto dput_and_out;
5587  
5588         retval = do_umount(path.mnt, flags);
5589 @@ -1363,7 +1421,7 @@ SYSCALL_DEFINE1(oldumount, char __user *
5590  
5591  static int mount_is_safe(struct path *path)
5592  {
5593 -       if (capable(CAP_SYS_ADMIN))
5594 +       if (vx_capable(CAP_SYS_ADMIN, VXC_SECURE_MOUNT))
5595                 return 0;
5596         return -EPERM;
5597  #ifdef notyet
5598 @@ -1653,7 +1711,7 @@ static int do_change_type(struct path *p
5599         int type;
5600         int err = 0;
5601  
5602 -       if (!capable(CAP_SYS_ADMIN))
5603 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_NAMESPACE))
5604                 return -EPERM;
5605  
5606         if (path->dentry != path->mnt->mnt_root)
5607 @@ -1684,11 +1742,13 @@ static int do_change_type(struct path *p
5608   * do loopback mount.
5609   */
5610  static int do_loopback(struct path *path, char *old_name,
5611 -                               int recurse)
5612 +       tag_t tag, unsigned long flags, int mnt_flags)
5613  {
5614         struct path old_path;
5615         struct vfsmount *mnt = NULL;
5616         int err = mount_is_safe(path);
5617 +       int recurse = flags & MS_REC;
5618 +
5619         if (err)
5620                 return err;
5621         if (!old_name || !*old_name)
5622 @@ -1723,6 +1783,7 @@ static int do_loopback(struct path *path
5623                 br_write_unlock(vfsmount_lock);
5624                 release_mounts(&umount_list);
5625         }
5626 +       mnt->mnt_flags = mnt_flags;
5627  
5628  out:
5629         up_write(&namespace_sem);
5630 @@ -1753,12 +1814,12 @@ static int change_mount_flags(struct vfs
5631   * on it - tough luck.
5632   */
5633  static int do_remount(struct path *path, int flags, int mnt_flags,
5634 -                     void *data)
5635 +       void *data, xid_t xid)
5636  {
5637         int err;
5638         struct super_block *sb = path->mnt->mnt_sb;
5639  
5640 -       if (!capable(CAP_SYS_ADMIN))
5641 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SECURE_REMOUNT))
5642                 return -EPERM;
5643  
5644         if (!check_mnt(path->mnt))
5645 @@ -1802,7 +1863,7 @@ static int do_move_mount(struct path *pa
5646         struct path old_path, parent_path;
5647         struct vfsmount *p;
5648         int err = 0;
5649 -       if (!capable(CAP_SYS_ADMIN))
5650 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SECURE_MOUNT))
5651                 return -EPERM;
5652         if (!old_name || !*old_name)
5653                 return -EINVAL;
5654 @@ -1888,7 +1949,7 @@ static int do_new_mount(struct path *pat
5655                 return -EINVAL;
5656  
5657         /* we need capabilities... */
5658 -       if (!capable(CAP_SYS_ADMIN))
5659 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SECURE_MOUNT))
5660                 return -EPERM;
5661  
5662         mnt = do_kern_mount(type, flags, name, data);
5663 @@ -2194,6 +2255,7 @@ long do_mount(char *dev_name, char *dir_
5664         struct path path;
5665         int retval = 0;
5666         int mnt_flags = 0;
5667 +       tag_t tag = 0;
5668  
5669         /* Discard magic */
5670         if ((flags & MS_MGC_MSK) == MS_MGC_VAL)
5671 @@ -2221,6 +2283,12 @@ long do_mount(char *dev_name, char *dir_
5672         if (!(flags & MS_NOATIME))
5673                 mnt_flags |= MNT_RELATIME;
5674  
5675 +       if (dx_parse_tag(data_page, &tag, 1, &mnt_flags, &flags)) {
5676 +               /* FIXME: bind and re-mounts get the tag flag? */
5677 +               if (flags & (MS_BIND|MS_REMOUNT))
5678 +                       flags |= MS_TAGID;
5679 +       }
5680 +
5681         /* Separate the per-mountpoint flags */
5682         if (flags & MS_NOSUID)
5683                 mnt_flags |= MNT_NOSUID;
5684 @@ -2237,15 +2305,17 @@ long do_mount(char *dev_name, char *dir_
5685         if (flags & MS_RDONLY)
5686                 mnt_flags |= MNT_READONLY;
5687  
5688 +       if (!capable(CAP_SYS_ADMIN))
5689 +               mnt_flags |= MNT_NODEV;
5690         flags &= ~(MS_NOSUID | MS_NOEXEC | MS_NODEV | MS_ACTIVE | MS_BORN |
5691                    MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
5692                    MS_STRICTATIME);
5693  
5694         if (flags & MS_REMOUNT)
5695                 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
5696 -                                   data_page);
5697 +                                   data_page, tag);
5698         else if (flags & MS_BIND)
5699 -               retval = do_loopback(&path, dev_name, flags & MS_REC);
5700 +               retval = do_loopback(&path, dev_name, tag, flags, mnt_flags);
5701         else if (flags & (MS_SHARED | MS_PRIVATE | MS_SLAVE | MS_UNBINDABLE))
5702                 retval = do_change_type(&path, flags);
5703         else if (flags & MS_MOVE)
5704 @@ -2345,6 +2415,7 @@ static struct mnt_namespace *dup_mnt_ns(
5705                 q = next_mnt(q, new_ns->root);
5706         }
5707         up_write(&namespace_sem);
5708 +       atomic_inc(&vs_global_mnt_ns);
5709  
5710         if (rootmnt)
5711                 mntput(rootmnt);
5712 @@ -2487,9 +2558,10 @@ SYSCALL_DEFINE2(pivot_root, const char _
5713         down_write(&namespace_sem);
5714         mutex_lock(&old.dentry->d_inode->i_mutex);
5715         error = -EINVAL;
5716 -       if (IS_MNT_SHARED(old.mnt) ||
5717 +       if ((IS_MNT_SHARED(old.mnt) ||
5718                 IS_MNT_SHARED(new.mnt->mnt_parent) ||
5719 -               IS_MNT_SHARED(root.mnt->mnt_parent))
5720 +               IS_MNT_SHARED(root.mnt->mnt_parent)) &&
5721 +               !vx_flags(VXF_STATE_SETUP, 0))
5722                 goto out2;
5723         if (!check_mnt(root.mnt))
5724                 goto out2;
5725 @@ -2624,6 +2696,7 @@ void put_mnt_ns(struct mnt_namespace *ns
5726         br_write_unlock(vfsmount_lock);
5727         up_write(&namespace_sem);
5728         release_mounts(&umount_list);
5729 +       atomic_dec(&vs_global_mnt_ns);
5730         kfree(ns);
5731  }
5732  EXPORT_SYMBOL(put_mnt_ns);
5733 diff -NurpP --minimal linux-2.6.38.1/fs/nfs/client.c linux-2.6.38.1-vs2.3.0.37-rc9/fs/nfs/client.c
5734 --- linux-2.6.38.1/fs/nfs/client.c      2011-03-15 18:07:32.000000000 +0100
5735 +++ linux-2.6.38.1-vs2.3.0.37-rc9/fs/nfs/client.c       2011-02-02 22:20:25.000000000 +0100
5736 @@ -761,6 +761,9 @@ static int nfs_init_server_rpcclient(str
5737         if (server->flags & NFS_MOUNT_SOFT)
5738                 server->client->cl_softrtry = 1;
5739  
5740 +       server->client->cl_tag = 0;
5741 +       if (server->flags & NFS_MOUNT_TAGGED)
5742 +               server->client->cl_tag = 1;
5743         return 0;
5744  }
5745  
5746 @@ -934,6 +937,10 @@ static void nfs_server_set_fsinfo(struct
5747                 server->acdirmin = server->acdirmax = 0;
5748         }
5749  
5750 +       /* FIXME: needs fsinfo
5751 +       if (server->flags & NFS_MOUNT_TAGGED)
5752 +               sb->s_flags |= MS_TAGGED;       */
5753 +
5754         server->maxfilesize = fsinfo->maxfilesize;
5755  
5756         server->time_delta = fsinfo->time_delta;
5757 diff -NurpP --minimal linux-2.6.38.1/fs/nfs/dir.c linux-2.6.38.1-vs2.3.0.37-rc9/fs/nfs/dir.c
5758 --- linux-2.6.38.1/fs/nfs/dir.c 2011-03-15 18:07:32.000000000 +0100
5759 +++ linux-2.6.38.1-vs2.3.0.37-rc9/fs/nfs/dir.c  2011-01-29 02:49:21.000000000 +0100
5760 @@ -35,6 +35,7 @@
5761  #include <linux/sched.h>
5762  #include <linux/kmemleak.h>
5763  #include <linux/xattr.h>
5764 +#include <linux/vs_tag.h>
5765  
5766  #include "delegation.h"
5767  #include "iostat.h"
5768 @@ -1224,6 +1225,7 @@ static struct dentry *nfs_lookup(struct 
5769         if (IS_ERR(res))
5770                 goto out_unblock_sillyrename;
5771  
5772 +       dx_propagate_tag(nd, inode);
5773  no_entry:
5774         res = d_materialise_unique(dentry, inode);
5775         if (res != NULL) {
5776 diff -NurpP --minimal linux-2.6.38.1/fs/nfs/inode.c linux-2.6.38.1-vs2.3.0.37-rc9/fs/nfs/inode.c
5777 --- linux-2.6.38.1/fs/nfs/inode.c       2011-03-15 18:07:32.000000000 +0100
5778 +++ linux-2.6.38.1-vs2.3.0.37-rc9/fs/nfs/inode.c        2011-03-15 18:17:58.000000000 +0100
5779 @@ -38,6 +38,7 @@
5780  #include <linux/nfs_xdr.h>
5781  #include <linux/slab.h>
5782  #include <linux/compat.h>
5783 +#include <linux/vs_tag.h>
5784  
5785  #include <asm/system.h>
5786  #include <asm/uaccess.h>
5787 @@ -270,6 +271,8 @@ nfs_fhget(struct super_block *sb, struct
5788         if (inode->i_state & I_NEW) {
5789                 struct nfs_inode *nfsi = NFS_I(inode);
5790                 unsigned long now = jiffies;
5791 +               uid_t uid;
5792 +               gid_t gid;
5793  
5794                 /* We set i_ino for the few things that still rely on it,
5795                  * such as stat(2) */
5796 @@ -318,8 +321,8 @@ nfs_fhget(struct super_block *sb, struct
5797                 nfsi->change_attr = 0;
5798                 inode->i_size = 0;
5799                 inode->i_nlink = 0;
5800 -               inode->i_uid = -2;
5801 -               inode->i_gid = -2;
5802 +               uid = -2;
5803 +               gid = -2;
5804                 inode->i_blocks = 0;
5805                 memset(nfsi->cookieverf, 0, sizeof(nfsi->cookieverf));
5806  
5807 @@ -356,13 +359,13 @@ nfs_fhget(struct super_block *sb, struct
5808                 else if (nfs_server_capable(inode, NFS_CAP_NLINK))
5809                         nfsi->cache_validity |= NFS_INO_INVALID_ATTR;
5810                 if (fattr->valid & NFS_ATTR_FATTR_OWNER)
5811 -                       inode->i_uid = fattr->uid;
5812 +                       uid = fattr->uid;
5813                 else if (nfs_server_capable(inode, NFS_CAP_OWNER))
5814                         nfsi->cache_validity |= NFS_INO_INVALID_ATTR
5815                                 | NFS_INO_INVALID_ACCESS
5816                                 | NFS_INO_INVALID_ACL;
5817                 if (fattr->valid & NFS_ATTR_FATTR_GROUP)
5818 -                       inode->i_gid = fattr->gid;
5819 +                       gid = fattr->gid;
5820                 else if (nfs_server_capable(inode, NFS_CAP_OWNER_GROUP))
5821                         nfsi->cache_validity |= NFS_INO_INVALID_ATTR
5822                                 | NFS_INO_INVALID_ACCESS
5823 @@ -375,6 +378,11 @@ nfs_fhget(struct super_block *sb, struct
5824                          */
5825                         inode->i_blocks = nfs_calc_block_size(fattr->du.nfs3.used);
5826                 }
5827 +               inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
5828 +               inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
5829 +               inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid, 0);
5830 +                               /* maybe fattr->xid someday */
5831 +
5832                 nfsi->attrtimeo = NFS_MINATTRTIMEO(inode);
5833                 nfsi->attrtimeo_timestamp = now;
5834                 nfsi->access_cache = RB_ROOT;
5835 @@ -491,6 +499,8 @@ void nfs_setattr_update_inode(struct ino
5836                         inode->i_uid = attr->ia_uid;
5837                 if ((attr->ia_valid & ATTR_GID) != 0)
5838                         inode->i_gid = attr->ia_gid;
5839 +               if ((attr->ia_valid & ATTR_TAG) && IS_TAGGED(inode))
5840 +                       inode->i_tag = attr->ia_tag;
5841                 NFS_I(inode)->cache_validity |= NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL;
5842                 spin_unlock(&inode->i_lock);
5843         }
5844 @@ -939,6 +949,9 @@ static int nfs_check_inode_attributes(st
5845         struct nfs_inode *nfsi = NFS_I(inode);
5846         loff_t cur_size, new_isize;
5847         unsigned long invalid = 0;
5848 +       uid_t uid;
5849 +       gid_t gid;
5850 +       tag_t tag;
5851  
5852  
5853         /* Has the inode gone and changed behind our back? */
5854 @@ -962,13 +975,18 @@ static int nfs_check_inode_attributes(st
5855                         invalid |= NFS_INO_INVALID_ATTR|NFS_INO_REVAL_PAGECACHE;
5856         }
5857  
5858 +       uid = INOTAG_UID(DX_TAG(inode), fattr->uid, fattr->gid);
5859 +       gid = INOTAG_GID(DX_TAG(inode), fattr->uid, fattr->gid);
5860 +       tag = INOTAG_TAG(DX_TAG(inode), fattr->uid, fattr->gid, 0);
5861 +
5862         /* Have any file permissions changed? */
5863         if ((fattr->valid & NFS_ATTR_FATTR_MODE) && (inode->i_mode & S_IALLUGO) != (fattr->mode & S_IALLUGO))
5864                 invalid |= NFS_INO_INVALID_ATTR | NFS_INO_INVALID_ACCESS | NFS_INO_INVALID_ACL;
5865 -       if ((fattr->valid & NFS_ATTR_FATTR_OWNER) && inode->i_uid != fattr->uid)
5866 +       if ((fattr->valid & NFS_ATTR_FATTR_OWNER) && uid != fattr->uid)
5867                 invalid |= NFS_INO_INVALID_ATTR | NFS_INO_INVALID_ACCESS | NFS_INO_INVALID_ACL;
5868 -       if ((fattr->valid & NFS_ATTR_FATTR_GROUP) && inode->i_gid != fattr->gid)
5869 +       if ((fattr->valid & NFS_ATTR_FATTR_GROUP) && gid != fattr->gid)
5870                 invalid |= NFS_INO_INVALID_ATTR | NFS_INO_INVALID_ACCESS | NFS_INO_INVALID_ACL;
5871 +               /* maybe check for tag too? */
5872  
5873         /* Has the link count changed? */
5874         if ((fattr->valid & NFS_ATTR_FATTR_NLINK) && inode->i_nlink != fattr->nlink)
5875 @@ -1203,6 +1221,9 @@ static int nfs_update_inode(struct inode
5876         unsigned long invalid = 0;
5877         unsigned long now = jiffies;
5878         unsigned long save_cache_validity;
5879 +       uid_t uid;
5880 +       gid_t gid;
5881 +       tag_t tag;
5882  
5883         dfprintk(VFS, "NFS: %s(%s/%ld ct=%d info=0x%x)\n",
5884                         __func__, inode->i_sb->s_id, inode->i_ino,
5885 @@ -1305,6 +1326,9 @@ static int nfs_update_inode(struct inode
5886                                 | NFS_INO_REVAL_PAGECACHE
5887                                 | NFS_INO_REVAL_FORCED);
5888  
5889 +       uid = INOTAG_UID(DX_TAG(inode), fattr->uid, fattr->gid);
5890 +       gid = INOTAG_GID(DX_TAG(inode), fattr->uid, fattr->gid);
5891 +       tag = INOTAG_TAG(DX_TAG(inode), fattr->uid, fattr->gid, 0);
5892  
5893         if (fattr->valid & NFS_ATTR_FATTR_ATIME)
5894                 memcpy(&inode->i_atime, &fattr->atime, sizeof(inode->i_atime));
5895 @@ -1326,9 +1350,9 @@ static int nfs_update_inode(struct inode
5896                                 | NFS_INO_REVAL_FORCED);
5897  
5898         if (fattr->valid & NFS_ATTR_FATTR_OWNER) {
5899 -               if (inode->i_uid != fattr->uid) {
5900 +               if (uid != fattr->uid) {
5901                         invalid |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL;
5902 -                       inode->i_uid = fattr->uid;
5903 +                       uid = fattr->uid;
5904                 }
5905         } else if (server->caps & NFS_CAP_OWNER)
5906                 invalid |= save_cache_validity & (NFS_INO_INVALID_ATTR
5907 @@ -1337,9 +1361,9 @@ static int nfs_update_inode(struct inode
5908                                 | NFS_INO_REVAL_FORCED);
5909  
5910         if (fattr->valid & NFS_ATTR_FATTR_GROUP) {
5911 -               if (inode->i_gid != fattr->gid) {
5912 +               if (gid != fattr->gid) {
5913                         invalid |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL;
5914 -                       inode->i_gid = fattr->gid;
5915 +                       gid = fattr->gid;
5916                 }
5917         } else if (server->caps & NFS_CAP_OWNER_GROUP)
5918                 invalid |= save_cache_validity & (NFS_INO_INVALID_ATTR
5919 @@ -1347,6 +1371,10 @@ static int nfs_update_inode(struct inode
5920                                 | NFS_INO_INVALID_ACL
5921                                 | NFS_INO_REVAL_FORCED);
5922  
5923 +       inode->i_uid = uid;
5924 +       inode->i_gid = gid;
5925 +       inode->i_tag = tag;
5926 +
5927         if (fattr->valid & NFS_ATTR_FATTR_NLINK) {
5928                 if (inode->i_nlink != fattr->nlink) {
5929                         invalid |= NFS_INO_INVALID_ATTR;
5930 diff -NurpP --minimal linux-2.6.38.1/fs/nfs/nfs3xdr.c linux-2.6.38.1-vs2.3.0.37-rc9/fs/nfs/nfs3xdr.c
5931 --- linux-2.6.38.1/fs/nfs/nfs3xdr.c     2011-03-15 18:07:32.000000000 +0100
5932 +++ linux-2.6.38.1-vs2.3.0.37-rc9/fs/nfs/nfs3xdr.c      2011-02-02 22:20:25.000000000 +0100
5933 @@ -20,6 +20,7 @@
5934  #include <linux/nfs3.h>
5935  #include <linux/nfs_fs.h>
5936  #include <linux/nfsacl.h>
5937 +#include <linux/vs_tag.h>
5938  #include "internal.h"
5939  
5940  #define NFSDBG_FACILITY                NFSDBG_XDR
5941 @@ -562,7 +563,8 @@ static __be32 *xdr_decode_nfstime3(__be3
5942   *             set_mtime       mtime;
5943   *     };
5944   */
5945 -static void encode_sattr3(struct xdr_stream *xdr, const struct iattr *attr)
5946 +static void encode_sattr3(struct xdr_stream *xdr,
5947 +       const struct iattr *attr, int tag)
5948  {
5949         u32 nbytes;
5950         __be32 *p;
5951 @@ -594,15 +596,19 @@ static void encode_sattr3(struct xdr_str
5952         } else
5953                 *p++ = xdr_zero;
5954  
5955 -       if (attr->ia_valid & ATTR_UID) {
5956 +       if (attr->ia_valid & ATTR_UID ||
5957 +               (tag && (attr->ia_valid & ATTR_TAG))) {
5958                 *p++ = xdr_one;
5959 -               *p++ = cpu_to_be32(attr->ia_uid);
5960 +               *p++ = cpu_to_be32(TAGINO_UID(tag,
5961 +                       attr->ia_uid, attr->ia_tag));
5962         } else
5963                 *p++ = xdr_zero;
5964  
5965 -       if (attr->ia_valid & ATTR_GID) {
5966 +       if (attr->ia_valid & ATTR_GID ||
5967 +               (tag && (attr->ia_valid & ATTR_TAG))) {
5968                 *p++ = xdr_one;
5969 -               *p++ = cpu_to_be32(attr->ia_gid);
5970 +               *p++ = cpu_to_be32(TAGINO_GID(tag,
5971 +                       attr->ia_gid, attr->ia_tag));
5972         } else
5973                 *p++ = xdr_zero;
5974  
5975 @@ -878,7 +884,7 @@ static void nfs3_xdr_enc_setattr3args(st
5976                                       const struct nfs3_sattrargs *args)
5977  {
5978         encode_nfs_fh3(xdr, args->fh);
5979 -       encode_sattr3(xdr, args->sattr);
5980 +       encode_sattr3(xdr, args->sattr, req->rq_task->tk_client->cl_tag);
5981         encode_sattrguard3(xdr, args);
5982  }
5983  
5984 @@ -1028,13 +1034,13 @@ static void nfs3_xdr_enc_write3args(stru
5985   *     };
5986   */
5987  static void encode_createhow3(struct xdr_stream *xdr,
5988 -                             const struct nfs3_createargs *args)
5989 +       const struct nfs3_createargs *args, int tag)
5990  {
5991         encode_uint32(xdr, args->createmode);
5992         switch (args->createmode) {
5993         case NFS3_CREATE_UNCHECKED:
5994         case NFS3_CREATE_GUARDED:
5995 -               encode_sattr3(xdr, args->sattr);
5996 +               encode_sattr3(xdr, args->sattr, tag);
5997                 break;
5998         case NFS3_CREATE_EXCLUSIVE:
5999                 encode_createverf3(xdr, args->verifier);
6000 @@ -1049,7 +1055,7 @@ static void nfs3_xdr_enc_create3args(str
6001                                      const struct nfs3_createargs *args)
6002  {
6003         encode_diropargs3(xdr, args->fh, args->name, args->len);
6004 -       encode_createhow3(xdr, args);
6005 +       encode_createhow3(xdr, args, req->rq_task->tk_client->cl_tag);
6006  }
6007  
6008  /*
6009 @@ -1065,7 +1071,7 @@ static void nfs3_xdr_enc_mkdir3args(stru
6010                                     const struct nfs3_mkdirargs *args)
6011  {
6012         encode_diropargs3(xdr, args->fh, args->name, args->len);
6013 -       encode_sattr3(xdr, args->sattr);
6014 +       encode_sattr3(xdr, args->sattr, req->rq_task->tk_client->cl_tag);
6015  }
6016  
6017  /*
6018 @@ -1082,9 +1088,9 @@ static void nfs3_xdr_enc_mkdir3args(stru
6019   *     };
6020   */
6021  static void encode_symlinkdata3(struct xdr_stream *xdr,
6022 -                               const struct nfs3_symlinkargs *args)
6023 +       const struct nfs3_symlinkargs *args, int tag)
6024  {
6025 -       encode_sattr3(xdr, args->sattr);
6026 +       encode_sattr3(xdr, args->sattr, tag);
6027         encode_nfspath3(xdr, args->pages, args->pathlen);
6028  }
6029  
6030 @@ -1093,7 +1099,7 @@ static void nfs3_xdr_enc_symlink3args(st
6031                                       const struct nfs3_symlinkargs *args)
6032  {
6033         encode_diropargs3(xdr, args->fromfh, args->fromname, args->fromlen);
6034 -       encode_symlinkdata3(xdr, args);
6035 +       encode_symlinkdata3(xdr, args, req->rq_task->tk_client->cl_tag);
6036  }
6037  
6038  /*
6039 @@ -1121,24 +1127,24 @@ static void nfs3_xdr_enc_symlink3args(st
6040   *     };
6041   */
6042  static void encode_devicedata3(struct xdr_stream *xdr,
6043 -                              const struct nfs3_mknodargs *args)
6044 +       const struct nfs3_mknodargs *args, int tag)
6045  {
6046 -       encode_sattr3(xdr, args->sattr);
6047 +       encode_sattr3(xdr, args->sattr, tag);
6048         encode_specdata3(xdr, args->rdev);
6049  }
6050  
6051  static void encode_mknoddata3(struct xdr_stream *xdr,
6052 -                             const struct nfs3_mknodargs *args)
6053 +       const struct nfs3_mknodargs *args, int tag)
6054  {
6055         encode_ftype3(xdr, args->type);
6056         switch (args->type) {
6057         case NF3CHR:
6058         case NF3BLK:
6059 -               encode_devicedata3(xdr, args);
6060 +               encode_devicedata3(xdr, args, tag);
6061                 break;
6062         case NF3SOCK:
6063         case NF3FIFO:
6064 -               encode_sattr3(xdr, args->sattr);
6065 +               encode_sattr3(xdr, args->sattr, tag);
6066                 break;
6067         case NF3REG:
6068         case NF3DIR:
6069 @@ -1153,7 +1159,7 @@ static void nfs3_xdr_enc_mknod3args(stru
6070                                     const struct nfs3_mknodargs *args)
6071  {
6072         encode_diropargs3(xdr, args->fh, args->name, args->len);
6073 -       encode_mknoddata3(xdr, args);
6074 +       encode_mknoddata3(xdr, args, req->rq_task->tk_client->cl_tag);
6075  }
6076  
6077  /*
6078 diff -NurpP --minimal linux-2.6.38.1/fs/nfs/super.c linux-2.6.38.1-vs2.3.0.37-rc9/fs/nfs/super.c
6079 --- linux-2.6.38.1/fs/nfs/super.c       2011-03-15 18:07:32.000000000 +0100
6080 +++ linux-2.6.38.1-vs2.3.0.37-rc9/fs/nfs/super.c        2011-01-29 02:01:07.000000000 +0100
6081 @@ -53,6 +53,7 @@
6082  #include <linux/nfs_xdr.h>
6083  #include <linux/magic.h>
6084  #include <linux/parser.h>
6085 +#include <linux/vs_tag.h>
6086  
6087  #include <asm/system.h>
6088  #include <asm/uaccess.h>
6089 @@ -86,6 +87,7 @@ enum {
6090         Opt_sharecache, Opt_nosharecache,
6091         Opt_resvport, Opt_noresvport,
6092         Opt_fscache, Opt_nofscache,
6093 +       Opt_tag, Opt_notag,
6094  
6095         /* Mount options that take integer arguments */
6096         Opt_port,
6097 @@ -99,6 +101,7 @@ enum {
6098         Opt_mountvers,
6099         Opt_nfsvers,
6100         Opt_minorversion,
6101 +       Opt_tagid,
6102  
6103         /* Mount options that take string arguments */
6104         Opt_sec, Opt_proto, Opt_mountproto, Opt_mounthost,
6105 @@ -179,6 +182,10 @@ static const match_table_t nfs_mount_opt
6106         { Opt_fscache_uniq, "fsc=%s" },
6107         { Opt_local_lock, "local_lock=%s" },
6108  
6109 +       { Opt_tag, "tag" },
6110 +       { Opt_notag, "notag" },
6111 +       { Opt_tagid, "tagid=%u" },
6112 +
6113         { Opt_err, NULL }
6114  };
6115  
6116 @@ -642,6 +649,7 @@ static void nfs_show_mount_options(struc
6117                 { NFS_MOUNT_NORDIRPLUS, ",nordirplus", "" },
6118                 { NFS_MOUNT_UNSHARED, ",nosharecache", "" },
6119                 { NFS_MOUNT_NORESVPORT, ",noresvport", "" },
6120 +               { NFS_MOUNT_TAGGED, ",tag", "" },
6121                 { 0, NULL, NULL }
6122         };
6123         const struct proc_nfs_info *nfs_infop;
6124 @@ -1122,6 +1130,14 @@ static int nfs_parse_mount_options(char 
6125                         kfree(mnt->fscache_uniq);
6126                         mnt->fscache_uniq = NULL;
6127                         break;
6128 +#ifndef CONFIG_TAGGING_NONE
6129 +               case Opt_tag:
6130 +                       mnt->flags |= NFS_MOUNT_TAGGED;
6131 +                       break;
6132 +               case Opt_notag:
6133 +                       mnt->flags &= ~NFS_MOUNT_TAGGED;
6134 +                       break;
6135 +#endif
6136  
6137                 /*
6138                  * options that take numeric values
6139 @@ -1306,6 +1322,12 @@ static int nfs_parse_mount_options(char 
6140                                 goto out_invalid_value;
6141                         mnt->minorversion = option;
6142                         break;
6143 +#ifdef CONFIG_PROPAGATE
6144 +               case Opt_tagid:
6145 +                       /* use args[0] */
6146 +                       nfs_data.flags |= NFS_MOUNT_TAGGED;
6147 +                       break;
6148 +#endif
6149  
6150                 /*
6151                  * options that take text values
6152 diff -NurpP --minimal linux-2.6.38.1/fs/nfsd/auth.c linux-2.6.38.1-vs2.3.0.37-rc9/fs/nfsd/auth.c
6153 --- linux-2.6.38.1/fs/nfsd/auth.c       2010-02-25 11:52:05.000000000 +0100
6154 +++ linux-2.6.38.1-vs2.3.0.37-rc9/fs/nfsd/auth.c        2011-01-29 02:01:07.000000000 +0100
6155 @@ -1,6 +1,7 @@
6156  /* Copyright (C) 1995, 1996 Olaf Kirch <okir@monad.swb.de> */
6157  
6158  #include <linux/sched.h>
6159 +#include <linux/vs_tag.h>
6160  #include "nfsd.h"
6161  #include "auth.h"
6162  
6163 @@ -36,6 +37,9 @@ int nfsd_setuser(struct svc_rqst *rqstp,
6164  
6165         new->fsuid = rqstp->rq_cred.cr_uid;
6166         new->fsgid = rqstp->rq_cred.cr_gid;
6167 +       /* FIXME: this desperately needs a tag :)
6168 +       new->xid = (xid_t)INOTAG_TAG(DX_TAG_NFSD, cred.cr_uid, cred.cr_gid, 0);
6169 +                       */
6170  
6171         rqgi = rqstp->rq_cred.cr_group_info;
6172  
6173 diff -NurpP --minimal linux-2.6.38.1/fs/nfsd/nfs3xdr.c linux-2.6.38.1-vs2.3.0.37-rc9/fs/nfsd/nfs3xdr.c
6174 --- linux-2.6.38.1/fs/nfsd/nfs3xdr.c    2011-01-05 21:50:25.000000000 +0100
6175 +++ linux-2.6.38.1-vs2.3.0.37-rc9/fs/nfsd/nfs3xdr.c     2011-01-29 02:01:07.000000000 +0100
6176 @@ -7,6 +7,7 @@
6177   */
6178  
6179  #include <linux/namei.h>
6180 +#include <linux/vs_tag.h>
6181  #include "xdr3.h"
6182  #include "auth.h"
6183  
6184 @@ -95,6 +96,8 @@ static __be32 *
6185  decode_sattr3(__be32 *p, struct iattr *iap)
6186  {
6187         u32     tmp;
6188 +       uid_t   uid = 0;
6189 +       gid_t   gid = 0;
6190  
6191         iap->ia_valid = 0;
6192  
6193 @@ -104,12 +107,15 @@ decode_sattr3(__be32 *p, struct iattr *i
6194         }
6195         if (*p++) {
6196                 iap->ia_valid |= ATTR_UID;
6197 -               iap->ia_uid = ntohl(*p++);
6198 +               uid = ntohl(*p++);
6199         }
6200         if (*p++) {
6201                 iap->ia_valid |= ATTR_GID;
6202 -               iap->ia_gid = ntohl(*p++);
6203 +               gid = ntohl(*p++);
6204         }
6205 +       iap->ia_uid = INOTAG_UID(DX_TAG_NFSD, uid, gid);
6206 +       iap->ia_gid = INOTAG_GID(DX_TAG_NFSD, uid, gid);
6207 +       iap->ia_tag = INOTAG_TAG(DX_TAG_NFSD, uid, gid, 0);
6208         if (*p++) {
6209                 u64     newsize;
6210  
6211 @@ -165,8 +171,12 @@ encode_fattr3(struct svc_rqst *rqstp, __
6212         *p++ = htonl(nfs3_ftypes[(stat->mode & S_IFMT) >> 12]);
6213         *p++ = htonl((u32) stat->mode);
6214         *p++ = htonl((u32) stat->nlink);
6215 -       *p++ = htonl((u32) nfsd_ruid(rqstp, stat->uid));
6216 -       *p++ = htonl((u32) nfsd_rgid(rqstp, stat->gid));
6217 +       *p++ = htonl((u32) nfsd_ruid(rqstp,
6218 +               TAGINO_UID(0 /* FIXME: DX_TAG(dentry->d_inode) */,
6219 +               stat->uid, stat->tag)));
6220 +       *p++ = htonl((u32) nfsd_rgid(rqstp,
6221 +               TAGINO_GID(0 /* FIXME: DX_TAG(dentry->d_inode) */,
6222 +               stat->gid, stat->tag)));
6223         if (S_ISLNK(stat->mode) && stat->size > NFS3_MAXPATHLEN) {
6224                 p = xdr_encode_hyper(p, (u64) NFS3_MAXPATHLEN);
6225         } else {
6226 diff -NurpP --minimal linux-2.6.38.1/fs/nfsd/nfs4xdr.c linux-2.6.38.1-vs2.3.0.37-rc9/fs/nfsd/nfs4xdr.c
6227 --- linux-2.6.38.1/fs/nfsd/nfs4xdr.c    2011-03-15 18:07:32.000000000 +0100
6228 +++ linux-2.6.38.1-vs2.3.0.37-rc9/fs/nfsd/nfs4xdr.c     2011-03-15 18:15:06.000000000 +0100
6229 @@ -45,6 +45,7 @@
6230  #include <linux/statfs.h>
6231  #include <linux/utsname.h>
6232  #include <linux/sunrpc/svcauth_gss.h>
6233 +#include <linux/vs_tag.h>
6234  
6235  #include "idmap.h"
6236  #include "acl.h"
6237 @@ -2098,14 +2099,18 @@ out_acl:
6238                 WRITE32(stat.nlink);
6239         }
6240         if (bmval1 & FATTR4_WORD1_OWNER) {
6241 -               status = nfsd4_encode_user(rqstp, stat.uid, &p, &buflen);
6242 +               status = nfsd4_encode_user(rqstp,
6243 +                       TAGINO_UID(DX_TAG(dentry->d_inode),
6244 +                       stat.uid, stat.tag), &p, &buflen);
6245                 if (status == nfserr_resource)
6246                         goto out_resource;
6247                 if (status)
6248                         goto out;
6249         }
6250         if (bmval1 & FATTR4_WORD1_OWNER_GROUP) {
6251 -               status = nfsd4_encode_group(rqstp, stat.gid, &p, &buflen);
6252 +               status = nfsd4_encode_group(rqstp,
6253 +                       TAGINO_GID(DX_TAG(dentry->d_inode),
6254 +                       stat.gid, stat.tag), &p, &buflen);
6255                 if (status == nfserr_resource)
6256                         goto out_resource;
6257                 if (status)
6258 diff -NurpP --minimal linux-2.6.38.1/fs/nfsd/nfsxdr.c linux-2.6.38.1-vs2.3.0.37-rc9/fs/nfsd/nfsxdr.c
6259 --- linux-2.6.38.1/fs/nfsd/nfsxdr.c     2010-02-25 11:52:05.000000000 +0100
6260 +++ linux-2.6.38.1-vs2.3.0.37-rc9/fs/nfsd/nfsxdr.c      2011-01-29 02:01:07.000000000 +0100
6261 @@ -6,6 +6,7 @@
6262  
6263  #include "xdr.h"
6264  #include "auth.h"
6265 +#include <linux/vs_tag.h>
6266  
6267  #define NFSDDBG_FACILITY               NFSDDBG_XDR
6268  
6269 @@ -88,6 +89,8 @@ static __be32 *
6270  decode_sattr(__be32 *p, struct iattr *iap)
6271  {
6272         u32     tmp, tmp1;
6273 +       uid_t   uid = 0;
6274 +       gid_t   gid = 0;
6275  
6276         iap->ia_valid = 0;
6277  
6278 @@ -101,12 +104,15 @@ decode_sattr(__be32 *p, struct iattr *ia
6279         }
6280         if ((tmp = ntohl(*p++)) != (u32)-1) {
6281                 iap->ia_valid |= ATTR_UID;
6282 -               iap->ia_uid = tmp;
6283 +               uid = tmp;
6284         }
6285         if ((tmp = ntohl(*p++)) != (u32)-1) {
6286                 iap->ia_valid |= ATTR_GID;
6287 -               iap->ia_gid = tmp;
6288 +               gid = tmp;
6289         }
6290 +       iap->ia_uid = INOTAG_UID(DX_TAG_NFSD, uid, gid);
6291 +       iap->ia_gid = INOTAG_GID(DX_TAG_NFSD, uid, gid);
6292 +       iap->ia_tag = INOTAG_TAG(DX_TAG_NFSD, uid, gid, 0);
6293         if ((tmp = ntohl(*p++)) != (u32)-1) {
6294                 iap->ia_valid |= ATTR_SIZE;
6295                 iap->ia_size = tmp;
6296 @@ -151,8 +157,10 @@ encode_fattr(struct svc_rqst *rqstp, __b
6297         *p++ = htonl(nfs_ftypes[type >> 12]);
6298         *p++ = htonl((u32) stat->mode);
6299         *p++ = htonl((u32) stat->nlink);
6300 -       *p++ = htonl((u32) nfsd_ruid(rqstp, stat->uid));
6301 -       *p++ = htonl((u32) nfsd_rgid(rqstp, stat->gid));
6302 +       *p++ = htonl((u32) nfsd_ruid(rqstp,
6303 +               TAGINO_UID(DX_TAG(dentry->d_inode), stat->uid, stat->tag)));
6304 +       *p++ = htonl((u32) nfsd_rgid(rqstp,
6305 +               TAGINO_GID(DX_TAG(dentry->d_inode), stat->gid, stat->tag)));
6306  
6307         if (S_ISLNK(type) && stat->size > NFS_MAXPATHLEN) {
6308                 *p++ = htonl(NFS_MAXPATHLEN);
6309 diff -NurpP --minimal linux-2.6.38.1/fs/ocfs2/dlmglue.c linux-2.6.38.1-vs2.3.0.37-rc9/fs/ocfs2/dlmglue.c
6310 --- linux-2.6.38.1/fs/ocfs2/dlmglue.c   2011-01-05 21:50:26.000000000 +0100
6311 +++ linux-2.6.38.1-vs2.3.0.37-rc9/fs/ocfs2/dlmglue.c    2011-01-29 02:01:07.000000000 +0100
6312 @@ -2114,6 +2114,7 @@ static void __ocfs2_stuff_meta_lvb(struc
6313         lvb->lvb_iclusters = cpu_to_be32(oi->ip_clusters);
6314         lvb->lvb_iuid      = cpu_to_be32(inode->i_uid);
6315         lvb->lvb_igid      = cpu_to_be32(inode->i_gid);
6316 +       lvb->lvb_itag      = cpu_to_be16(inode->i_tag);
6317         lvb->lvb_imode     = cpu_to_be16(inode->i_mode);
6318         lvb->lvb_inlink    = cpu_to_be16(inode->i_nlink);
6319         lvb->lvb_iatime_packed  =
6320 @@ -2168,6 +2169,7 @@ static void ocfs2_refresh_inode_from_lvb
6321  
6322         inode->i_uid     = be32_to_cpu(lvb->lvb_iuid);
6323         inode->i_gid     = be32_to_cpu(lvb->lvb_igid);
6324 +       inode->i_tag     = be16_to_cpu(lvb->lvb_itag);
6325         inode->i_mode    = be16_to_cpu(lvb->lvb_imode);
6326         inode->i_nlink   = be16_to_cpu(lvb->lvb_inlink);
6327         ocfs2_unpack_timespec(&inode->i_atime,
6328 diff -NurpP --minimal linux-2.6.38.1/fs/ocfs2/dlmglue.h linux-2.6.38.1-vs2.3.0.37-rc9/fs/ocfs2/dlmglue.h
6329 --- linux-2.6.38.1/fs/ocfs2/dlmglue.h   2010-10-21 13:07:50.000000000 +0200
6330 +++ linux-2.6.38.1-vs2.3.0.37-rc9/fs/ocfs2/dlmglue.h    2011-01-29 02:01:07.000000000 +0100
6331 @@ -46,7 +46,8 @@ struct ocfs2_meta_lvb {
6332         __be16       lvb_inlink;
6333         __be32       lvb_iattr;
6334         __be32       lvb_igeneration;
6335 -       __be32       lvb_reserved2;
6336 +       __be16       lvb_itag;
6337 +       __be16       lvb_reserved2;
6338  };
6339  
6340  #define OCFS2_QINFO_LVB_VERSION 1
6341 diff -NurpP --minimal linux-2.6.38.1/fs/ocfs2/file.c linux-2.6.38.1-vs2.3.0.37-rc9/fs/ocfs2/file.c
6342 --- linux-2.6.38.1/fs/ocfs2/file.c      2011-03-15 18:07:33.000000000 +0100
6343 +++ linux-2.6.38.1-vs2.3.0.37-rc9/fs/ocfs2/file.c       2011-01-29 02:01:07.000000000 +0100
6344 @@ -1126,13 +1126,15 @@ int ocfs2_setattr(struct dentry *dentry,
6345                 mlog(0, "uid change: %d\n", attr->ia_uid);
6346         if (attr->ia_valid & ATTR_GID)
6347                 mlog(0, "gid change: %d\n", attr->ia_gid);
6348 +       if (attr->ia_valid & ATTR_TAG)
6349 +               mlog(0, "tag change: %d\n", attr->ia_tag);
6350         if (attr->ia_valid & ATTR_SIZE)
6351                 mlog(0, "size change...\n");
6352         if (attr->ia_valid & (ATTR_ATIME | ATTR_MTIME | ATTR_CTIME))
6353                 mlog(0, "time change...\n");
6354  
6355  #define OCFS2_VALID_ATTRS (ATTR_ATIME | ATTR_MTIME | ATTR_CTIME | ATTR_SIZE \
6356 -                          | ATTR_GID | ATTR_UID | ATTR_MODE)
6357 +                          | ATTR_GID | ATTR_UID | ATTR_TAG | ATTR_MODE)
6358         if (!(attr->ia_valid & OCFS2_VALID_ATTRS)) {
6359                 mlog(0, "can't handle attrs: 0x%x\n", attr->ia_valid);
6360                 return 0;
6361 diff -NurpP --minimal linux-2.6.38.1/fs/ocfs2/inode.c linux-2.6.38.1-vs2.3.0.37-rc9/fs/ocfs2/inode.c
6362 --- linux-2.6.38.1/fs/ocfs2/inode.c     2011-03-15 18:07:33.000000000 +0100
6363 +++ linux-2.6.38.1-vs2.3.0.37-rc9/fs/ocfs2/inode.c      2011-01-29 02:01:07.000000000 +0100
6364 @@ -28,6 +28,7 @@
6365  #include <linux/highmem.h>
6366  #include <linux/pagemap.h>
6367  #include <linux/quotaops.h>
6368 +#include <linux/vs_tag.h>
6369  
6370  #include <asm/byteorder.h>
6371  
6372 @@ -78,11 +79,13 @@ void ocfs2_set_inode_flags(struct inode 
6373  {
6374         unsigned int flags = OCFS2_I(inode)->ip_attr;
6375  
6376 -       inode->i_flags &= ~(S_IMMUTABLE |
6377 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
6378                 S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
6379  
6380         if (flags & OCFS2_IMMUTABLE_FL)
6381                 inode->i_flags |= S_IMMUTABLE;
6382 +       if (flags & OCFS2_IXUNLINK_FL)
6383 +               inode->i_flags |= S_IXUNLINK;
6384  
6385         if (flags & OCFS2_SYNC_FL)
6386                 inode->i_flags |= S_SYNC;
6387 @@ -92,25 +95,44 @@ void ocfs2_set_inode_flags(struct inode 
6388                 inode->i_flags |= S_NOATIME;
6389         if (flags & OCFS2_DIRSYNC_FL)
6390                 inode->i_flags |= S_DIRSYNC;
6391 +
6392 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
6393 +
6394 +       if (flags & OCFS2_BARRIER_FL)
6395 +               inode->i_vflags |= V_BARRIER;
6396 +       if (flags & OCFS2_COW_FL)
6397 +               inode->i_vflags |= V_COW;
6398  }
6399  
6400  /* Propagate flags from i_flags to OCFS2_I(inode)->ip_attr */
6401  void ocfs2_get_inode_flags(struct ocfs2_inode_info *oi)
6402  {
6403         unsigned int flags = oi->vfs_inode.i_flags;
6404 +       unsigned int vflags = oi->vfs_inode.i_vflags;
6405 +
6406 +       oi->ip_attr &= ~(OCFS2_SYNC_FL | OCFS2_APPEND_FL |
6407 +                       OCFS2_IMMUTABLE_FL | OCFS2_IXUNLINK_FL |
6408 +                       OCFS2_NOATIME_FL | OCFS2_DIRSYNC_FL |
6409 +                       OCFS2_BARRIER_FL | OCFS2_COW_FL);
6410 +
6411 +       if (flags & S_IMMUTABLE)
6412 +               oi->ip_attr |= OCFS2_IMMUTABLE_FL;
6413 +       if (flags & S_IXUNLINK)
6414 +               oi->ip_attr |= OCFS2_IXUNLINK_FL;
6415  
6416 -       oi->ip_attr &= ~(OCFS2_SYNC_FL|OCFS2_APPEND_FL|
6417 -                       OCFS2_IMMUTABLE_FL|OCFS2_NOATIME_FL|OCFS2_DIRSYNC_FL);
6418         if (flags & S_SYNC)
6419                 oi->ip_attr |= OCFS2_SYNC_FL;
6420         if (flags & S_APPEND)
6421                 oi->ip_attr |= OCFS2_APPEND_FL;
6422 -       if (flags & S_IMMUTABLE)
6423 -               oi->ip_attr |= OCFS2_IMMUTABLE_FL;
6424         if (flags & S_NOATIME)
6425                 oi->ip_attr |= OCFS2_NOATIME_FL;
6426         if (flags & S_DIRSYNC)
6427                 oi->ip_attr |= OCFS2_DIRSYNC_FL;
6428 +
6429 +       if (vflags & V_BARRIER)
6430 +               oi->ip_attr |= OCFS2_BARRIER_FL;
6431 +       if (vflags & V_COW)
6432 +               oi->ip_attr |= OCFS2_COW_FL;
6433  }
6434  
6435  struct inode *ocfs2_ilookup(struct super_block *sb, u64 blkno)
6436 @@ -245,6 +267,8 @@ void ocfs2_populate_inode(struct inode *
6437         struct super_block *sb;
6438         struct ocfs2_super *osb;
6439         int use_plocks = 1;
6440 +       uid_t uid;
6441 +       gid_t gid;
6442  
6443         mlog_entry("(0x%p, size:%llu)\n", inode,
6444                    (unsigned long long)le64_to_cpu(fe->i_size));
6445 @@ -276,8 +300,12 @@ void ocfs2_populate_inode(struct inode *
6446         inode->i_generation = le32_to_cpu(fe->i_generation);
6447         inode->i_rdev = huge_decode_dev(le64_to_cpu(fe->id1.dev1.i_rdev));
6448         inode->i_mode = le16_to_cpu(fe->i_mode);
6449 -       inode->i_uid = le32_to_cpu(fe->i_uid);
6450 -       inode->i_gid = le32_to_cpu(fe->i_gid);
6451 +       uid = le32_to_cpu(fe->i_uid);
6452 +       gid = le32_to_cpu(fe->i_gid);
6453 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
6454 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
6455 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid,
6456 +               /* le16_to_cpu(raw_inode->i_raw_tag)i */ 0);
6457  
6458         /* Fast symlinks will have i_size but no allocated clusters. */
6459         if (S_ISLNK(inode->i_mode) && !fe->i_clusters)
6460 diff -NurpP --minimal linux-2.6.38.1/fs/ocfs2/inode.h linux-2.6.38.1-vs2.3.0.37-rc9/fs/ocfs2/inode.h
6461 --- linux-2.6.38.1/fs/ocfs2/inode.h     2011-01-05 21:50:26.000000000 +0100
6462 +++ linux-2.6.38.1-vs2.3.0.37-rc9/fs/ocfs2/inode.h      2011-01-29 02:01:07.000000000 +0100
6463 @@ -151,6 +151,7 @@ struct buffer_head *ocfs2_bread(struct i
6464  
6465  void ocfs2_set_inode_flags(struct inode *inode);
6466  void ocfs2_get_inode_flags(struct ocfs2_inode_info *oi);
6467 +int ocfs2_sync_flags(struct inode *inode, int, int);
6468  
6469  static inline blkcnt_t ocfs2_inode_sector_count(struct inode *inode)
6470  {
6471 diff -NurpP --minimal linux-2.6.38.1/fs/ocfs2/ioctl.c linux-2.6.38.1-vs2.3.0.37-rc9/fs/ocfs2/ioctl.c
6472 --- linux-2.6.38.1/fs/ocfs2/ioctl.c     2011-01-05 21:50:26.000000000 +0100
6473 +++ linux-2.6.38.1-vs2.3.0.37-rc9/fs/ocfs2/ioctl.c      2011-01-29 02:01:07.000000000 +0100
6474 @@ -63,7 +63,41 @@ static int ocfs2_get_inode_attr(struct i
6475         return status;
6476  }
6477  
6478 -static int ocfs2_set_inode_attr(struct inode *inode, unsigned flags,
6479 +int ocfs2_sync_flags(struct inode *inode, int flags, int vflags)
6480 +{
6481 +       struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
6482 +       struct buffer_head *bh = NULL;
6483 +       handle_t *handle = NULL;
6484 +       int status;
6485 +
6486 +       status = ocfs2_inode_lock(inode, &bh, 1);
6487 +       if (status < 0) {
6488 +               mlog_errno(status);
6489 +               return status;
6490 +       }
6491 +       handle = ocfs2_start_trans(osb, OCFS2_INODE_UPDATE_CREDITS);
6492 +       if (IS_ERR(handle)) {
6493 +               status = PTR_ERR(handle);
6494 +               mlog_errno(status);
6495 +               goto bail_unlock;
6496 +       }
6497 +
6498 +       inode->i_flags = flags;
6499 +       inode->i_vflags = vflags;
6500 +       ocfs2_get_inode_flags(OCFS2_I(inode));
6501 +
6502 +       status = ocfs2_mark_inode_dirty(handle, inode, bh);
6503 +       if (status < 0)
6504 +               mlog_errno(status);
6505 +
6506 +       ocfs2_commit_trans(osb, handle);
6507 +bail_unlock:
6508 +       ocfs2_inode_unlock(inode, 1);
6509 +       brelse(bh);
6510 +       return status;
6511 +}
6512 +
6513 +int ocfs2_set_inode_attr(struct inode *inode, unsigned flags,
6514                                 unsigned mask)
6515  {
6516         struct ocfs2_inode_info *ocfs2_inode = OCFS2_I(inode);
6517 @@ -88,6 +122,11 @@ static int ocfs2_set_inode_attr(struct i
6518         if (!S_ISDIR(inode->i_mode))
6519                 flags &= ~OCFS2_DIRSYNC_FL;
6520  
6521 +       if (IS_BARRIER(inode)) {
6522 +               vxwprintk_task(1, "messing with the barrier.");
6523 +               goto bail_unlock;
6524 +       }
6525 +
6526         handle = ocfs2_start_trans(osb, OCFS2_INODE_UPDATE_CREDITS);
6527         if (IS_ERR(handle)) {
6528                 status = PTR_ERR(handle);
6529 @@ -451,6 +490,7 @@ bail:
6530         return status;
6531  }
6532  
6533 +
6534  long ocfs2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
6535  {
6536         struct inode *inode = filp->f_path.dentry->d_inode;
6537 diff -NurpP --minimal linux-2.6.38.1/fs/ocfs2/namei.c linux-2.6.38.1-vs2.3.0.37-rc9/fs/ocfs2/namei.c
6538 --- linux-2.6.38.1/fs/ocfs2/namei.c     2011-03-15 18:07:33.000000000 +0100
6539 +++ linux-2.6.38.1-vs2.3.0.37-rc9/fs/ocfs2/namei.c      2011-01-29 02:01:07.000000000 +0100
6540 @@ -41,6 +41,7 @@
6541  #include <linux/slab.h>
6542  #include <linux/highmem.h>
6543  #include <linux/quotaops.h>
6544 +#include <linux/vs_tag.h>
6545  
6546  #define MLOG_MASK_PREFIX ML_NAMEI
6547  #include <cluster/masklog.h>
6548 @@ -485,6 +486,7 @@ static int __ocfs2_mknod_locked(struct i
6549         struct ocfs2_dinode *fe = NULL;
6550         struct ocfs2_extent_list *fel;
6551         u16 feat;
6552 +       tag_t tag;
6553  
6554         *new_fe_bh = NULL;
6555  
6556 @@ -522,8 +524,11 @@ static int __ocfs2_mknod_locked(struct i
6557         fe->i_suballoc_loc = cpu_to_le64(suballoc_loc);
6558         fe->i_suballoc_bit = cpu_to_le16(suballoc_bit);
6559         fe->i_suballoc_slot = cpu_to_le16(inode_ac->ac_alloc_slot);
6560 -       fe->i_uid = cpu_to_le32(inode->i_uid);
6561 -       fe->i_gid = cpu_to_le32(inode->i_gid);
6562 +
6563 +       tag = dx_current_fstag(osb->sb);
6564 +       fe->i_uid = cpu_to_le32(TAGINO_UID(DX_TAG(inode), inode->i_uid, tag));
6565 +       fe->i_gid = cpu_to_le32(TAGINO_GID(DX_TAG(inode), inode->i_gid, tag));
6566 +       inode->i_tag = tag;
6567         fe->i_mode = cpu_to_le16(inode->i_mode);
6568         if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode))
6569                 fe->id1.dev1.i_rdev = cpu_to_le64(huge_encode_dev(dev));
6570 diff -NurpP --minimal linux-2.6.38.1/fs/ocfs2/ocfs2.h linux-2.6.38.1-vs2.3.0.37-rc9/fs/ocfs2/ocfs2.h
6571 --- linux-2.6.38.1/fs/ocfs2/ocfs2.h     2011-03-15 18:07:33.000000000 +0100
6572 +++ linux-2.6.38.1-vs2.3.0.37-rc9/fs/ocfs2/ocfs2.h      2011-01-29 02:01:07.000000000 +0100
6573 @@ -267,6 +267,7 @@ enum ocfs2_mount_options
6574                                                      writes */
6575         OCFS2_MOUNT_HB_NONE = 1 << 13, /* No heartbeat */
6576         OCFS2_MOUNT_HB_GLOBAL = 1 << 14, /* Global heartbeat */
6577 +       OCFS2_MOUNT_TAGGED = 1 << 15, /* use tagging */
6578  };
6579  
6580  #define OCFS2_OSB_SOFT_RO                      0x0001
6581 diff -NurpP --minimal linux-2.6.38.1/fs/ocfs2/ocfs2_fs.h linux-2.6.38.1-vs2.3.0.37-rc9/fs/ocfs2/ocfs2_fs.h
6582 --- linux-2.6.38.1/fs/ocfs2/ocfs2_fs.h  2011-01-05 21:50:26.000000000 +0100
6583 +++ linux-2.6.38.1-vs2.3.0.37-rc9/fs/ocfs2/ocfs2_fs.h   2011-01-29 02:01:07.000000000 +0100
6584 @@ -266,6 +266,11 @@
6585  #define OCFS2_TOPDIR_FL                        FS_TOPDIR_FL    /* Top of directory hierarchies*/
6586  #define OCFS2_RESERVED_FL              FS_RESERVED_FL  /* reserved for ext2 lib */
6587  
6588 +#define OCFS2_IXUNLINK_FL              FS_IXUNLINK_FL  /* Immutable invert on unlink */
6589 +
6590 +#define OCFS2_BARRIER_FL               FS_BARRIER_FL   /* Barrier for chroot() */
6591 +#define OCFS2_COW_FL                   FS_COW_FL       /* Copy on Write marker */
6592 +
6593  #define OCFS2_FL_VISIBLE               FS_FL_USER_VISIBLE      /* User visible flags */
6594  #define OCFS2_FL_MODIFIABLE            FS_FL_USER_MODIFIABLE   /* User modifiable flags */
6595  
6596 diff -NurpP --minimal linux-2.6.38.1/fs/ocfs2/super.c linux-2.6.38.1-vs2.3.0.37-rc9/fs/ocfs2/super.c
6597 --- linux-2.6.38.1/fs/ocfs2/super.c     2011-03-15 18:07:33.000000000 +0100
6598 +++ linux-2.6.38.1-vs2.3.0.37-rc9/fs/ocfs2/super.c      2011-03-07 16:53:27.000000000 +0100
6599 @@ -181,6 +181,7 @@ enum {
6600         Opt_coherency_full,
6601         Opt_resv_level,
6602         Opt_dir_resv_level,
6603 +       Opt_tag, Opt_notag, Opt_tagid,
6604         Opt_err,
6605  };
6606  
6607 @@ -212,6 +213,9 @@ static const match_table_t tokens = {
6608         {Opt_coherency_full, "coherency=full"},
6609         {Opt_resv_level, "resv_level=%u"},
6610         {Opt_dir_resv_level, "dir_resv_level=%u"},
6611 +       {Opt_tag, "tag"},
6612 +       {Opt_notag, "notag"},
6613 +       {Opt_tagid, "tagid=%u"},
6614         {Opt_err, NULL}
6615  };
6616  
6617 @@ -666,6 +670,13 @@ static int ocfs2_remount(struct super_bl
6618                 goto out;
6619         }
6620  
6621 +       if ((osb->s_mount_opt & OCFS2_MOUNT_TAGGED) !=
6622 +           (parsed_options.mount_opt & OCFS2_MOUNT_TAGGED)) {
6623 +               ret = -EINVAL;
6624 +               mlog(ML_ERROR, "Cannot change tagging on remount\n");
6625 +               goto out;
6626 +       }
6627 +
6628         /* We're going to/from readonly mode. */
6629         if ((*flags & MS_RDONLY) != (sb->s_flags & MS_RDONLY)) {
6630                 /* Disable quota accounting before remounting RO */
6631 @@ -1183,6 +1194,9 @@ static int ocfs2_fill_super(struct super
6632  
6633         ocfs2_complete_mount_recovery(osb);
6634  
6635 +       if (osb->s_mount_opt & OCFS2_MOUNT_TAGGED)
6636 +               sb->s_flags |= MS_TAGGED;
6637 +
6638         if (ocfs2_mount_local(osb))
6639                 snprintf(nodestr, sizeof(nodestr), "local");
6640         else
6641 @@ -1514,6 +1528,20 @@ static int ocfs2_parse_options(struct su
6642                             option < OCFS2_MAX_RESV_LEVEL)
6643                                 mopt->dir_resv_level = option;
6644                         break;
6645 +#ifndef CONFIG_TAGGING_NONE
6646 +               case Opt_tag:
6647 +                       mopt->mount_opt |= OCFS2_MOUNT_TAGGED;
6648 +                       break;
6649 +               case Opt_notag:
6650 +                       mopt->mount_opt &= ~OCFS2_MOUNT_TAGGED;
6651 +                       break;
6652 +#endif
6653 +#ifdef CONFIG_PROPAGATE
6654 +               case Opt_tagid:
6655 +                       /* use args[0] */
6656 +                       mopt->mount_opt |= OCFS2_MOUNT_TAGGED;
6657 +                       break;
6658 +#endif
6659                 default:
6660                         mlog(ML_ERROR,
6661                              "Unrecognized mount option \"%s\" "
6662 diff -NurpP --minimal linux-2.6.38.1/fs/open.c linux-2.6.38.1-vs2.3.0.37-rc9/fs/open.c
6663 --- linux-2.6.38.1/fs/open.c    2011-03-15 18:07:33.000000000 +0100
6664 +++ linux-2.6.38.1-vs2.3.0.37-rc9/fs/open.c     2011-03-15 18:15:06.000000000 +0100
6665 @@ -30,6 +30,11 @@
6666  #include <linux/fs_struct.h>
6667  #include <linux/ima.h>
6668  #include <linux/dnotify.h>
6669 +#include <linux/vs_base.h>
6670 +#include <linux/vs_limit.h>
6671 +#include <linux/vs_tag.h>
6672 +#include <linux/vs_cowbl.h>
6673 +#include <linux/vserver/dlimit.h>
6674  
6675  #include "internal.h"
6676  
6677 @@ -494,6 +499,12 @@ SYSCALL_DEFINE3(fchmodat, int, dfd, cons
6678         error = user_path_at(dfd, filename, LOOKUP_FOLLOW, &path);
6679         if (error)
6680                 goto out;
6681 +
6682 +#ifdef CONFIG_VSERVER_COWBL
6683 +       error = cow_check_and_break(&path);
6684 +       if (error)
6685 +               goto dput_and_out;
6686 +#endif
6687         inode = path.dentry->d_inode;
6688  
6689         error = mnt_want_write(path.mnt);
6690 @@ -531,11 +542,11 @@ static int chown_common(struct path *pat
6691         newattrs.ia_valid =  ATTR_CTIME;
6692         if (user != (uid_t) -1) {
6693                 newattrs.ia_valid |= ATTR_UID;
6694 -               newattrs.ia_uid = user;
6695 +               newattrs.ia_uid = dx_map_uid(user);
6696         }
6697         if (group != (gid_t) -1) {
6698                 newattrs.ia_valid |= ATTR_GID;
6699 -               newattrs.ia_gid = group;
6700 +               newattrs.ia_gid = dx_map_gid(group);
6701         }
6702         if (!S_ISDIR(inode->i_mode))
6703                 newattrs.ia_valid |=
6704 @@ -560,6 +571,10 @@ SYSCALL_DEFINE3(chown, const char __user
6705         error = mnt_want_write(path.mnt);
6706         if (error)
6707                 goto out_release;
6708 +#ifdef CONFIG_VSERVER_COWBL
6709 +       error = cow_check_and_break(&path);
6710 +       if (!error)
6711 +#endif
6712         error = chown_common(&path, user, group);
6713         mnt_drop_write(path.mnt);
6714  out_release:
6715 @@ -585,6 +600,10 @@ SYSCALL_DEFINE5(fchownat, int, dfd, cons
6716         error = mnt_want_write(path.mnt);
6717         if (error)
6718                 goto out_release;
6719 +#ifdef CONFIG_VSERVER_COWBL
6720 +       error = cow_check_and_break(&path);
6721 +       if (!error)
6722 +#endif
6723         error = chown_common(&path, user, group);
6724         mnt_drop_write(path.mnt);
6725  out_release:
6726 @@ -604,6 +623,10 @@ SYSCALL_DEFINE3(lchown, const char __use
6727         error = mnt_want_write(path.mnt);
6728         if (error)
6729                 goto out_release;
6730 +#ifdef CONFIG_VSERVER_COWBL
6731 +       error = cow_check_and_break(&path);
6732 +       if (!error)
6733 +#endif
6734         error = chown_common(&path, user, group);
6735         mnt_drop_write(path.mnt);
6736  out_release:
6737 @@ -852,6 +875,7 @@ static void __put_unused_fd(struct files
6738         __FD_CLR(fd, fdt->open_fds);
6739         if (fd < files->next_fd)
6740                 files->next_fd = fd;
6741 +       vx_openfd_dec(fd);
6742  }
6743  
6744  void put_unused_fd(unsigned int fd)
6745 diff -NurpP --minimal linux-2.6.38.1/fs/proc/array.c linux-2.6.38.1-vs2.3.0.37-rc9/fs/proc/array.c
6746 --- linux-2.6.38.1/fs/proc/array.c      2011-03-15 18:07:33.000000000 +0100
6747 +++ linux-2.6.38.1-vs2.3.0.37-rc9/fs/proc/array.c       2011-02-17 02:23:41.000000000 +0100
6748 @@ -81,6 +81,8 @@
6749  #include <linux/pid_namespace.h>
6750  #include <linux/ptrace.h>
6751  #include <linux/tracehook.h>
6752 +#include <linux/vs_context.h>
6753 +#include <linux/vs_network.h>
6754  
6755  #include <asm/pgtable.h>
6756  #include <asm/processor.h>
6757 @@ -170,6 +172,9 @@ static inline void task_state(struct seq
6758         rcu_read_lock();
6759         ppid = pid_alive(p) ?
6760                 task_tgid_nr_ns(rcu_dereference(p->real_parent), ns) : 0;
6761 +       if (unlikely(vx_current_initpid(p->pid)))
6762 +               ppid = 0;
6763 +
6764         tpid = 0;
6765         if (pid_alive(p)) {
6766                 struct task_struct *tracer = tracehook_tracer_task(p);
6767 @@ -287,7 +292,7 @@ static inline void task_sig(struct seq_f
6768  }
6769  
6770  static void render_cap_t(struct seq_file *m, const char *header,
6771 -                       kernel_cap_t *a)
6772 +                       struct vx_info *vxi, kernel_cap_t *a)
6773  {
6774         unsigned __capi;
6775  
6776 @@ -312,10 +317,11 @@ static inline void task_cap(struct seq_f
6777         cap_bset        = cred->cap_bset;
6778         rcu_read_unlock();
6779  
6780 -       render_cap_t(m, "CapInh:\t", &cap_inheritable);
6781 -       render_cap_t(m, "CapPrm:\t", &cap_permitted);
6782 -       render_cap_t(m, "CapEff:\t", &cap_effective);
6783 -       render_cap_t(m, "CapBnd:\t", &cap_bset);
6784 +       /* FIXME: maybe move the p->vx_info masking to __task_cred() ? */
6785 +       render_cap_t(m, "CapInh:\t", p->vx_info, &cap_inheritable);
6786 +       render_cap_t(m, "CapPrm:\t", p->vx_info, &cap_permitted);
6787 +       render_cap_t(m, "CapEff:\t", p->vx_info, &cap_effective);
6788 +       render_cap_t(m, "CapBnd:\t", p->vx_info, &cap_bset);
6789  }
6790  
6791  static inline void task_context_switch_counts(struct seq_file *m,
6792 @@ -337,6 +343,42 @@ static void task_cpus_allowed(struct seq
6793         seq_putc(m, '\n');
6794  }
6795  
6796 +int proc_pid_nsproxy(struct seq_file *m, struct pid_namespace *ns,
6797 +                       struct pid *pid, struct task_struct *task)
6798 +{
6799 +       seq_printf(m,   "Proxy:\t%p(%c)\n"
6800 +                       "Count:\t%u\n"
6801 +                       "uts:\t%p(%c)\n"
6802 +                       "ipc:\t%p(%c)\n"
6803 +                       "mnt:\t%p(%c)\n"
6804 +                       "pid:\t%p(%c)\n"
6805 +                       "net:\t%p(%c)\n",
6806 +                       task->nsproxy,
6807 +                       (task->nsproxy == init_task.nsproxy ? 'I' : '-'),
6808 +                       atomic_read(&task->nsproxy->count),
6809 +                       task->nsproxy->uts_ns,
6810 +                       (task->nsproxy->uts_ns == init_task.nsproxy->uts_ns ? 'I' : '-'),
6811 +                       task->nsproxy->ipc_ns,
6812 +                       (task->nsproxy->ipc_ns == init_task.nsproxy->ipc_ns ? 'I' : '-'),
6813 +                       task->nsproxy->mnt_ns,
6814 +                       (task->nsproxy->mnt_ns == init_task.nsproxy->mnt_ns ? 'I' : '-'),
6815 +                       task->nsproxy->pid_ns,
6816 +                       (task->nsproxy->pid_ns == init_task.nsproxy->pid_ns ? 'I' : '-'),
6817 +                       task->nsproxy->net_ns,
6818 +                       (task->nsproxy->net_ns == init_task.nsproxy->net_ns ? 'I' : '-'));
6819 +       return 0;
6820 +}
6821 +
6822 +void task_vs_id(struct seq_file *m, struct task_struct *task)
6823 +{
6824 +       if (task_vx_flags(task, VXF_HIDE_VINFO, 0))
6825 +               return;
6826 +
6827 +       seq_printf(m, "VxID: %d\n", vx_task_xid(task));
6828 +       seq_printf(m, "NxID: %d\n", nx_task_nid(task));
6829 +}
6830 +
6831 +
6832  int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
6833                         struct pid *pid, struct task_struct *task)
6834  {
6835 @@ -353,6 +395,7 @@ int proc_pid_status(struct seq_file *m, 
6836         task_cap(m, task);
6837         task_cpus_allowed(m, task);
6838         cpuset_task_status_allowed(m, task);
6839 +       task_vs_id(m, task);
6840         task_context_switch_counts(m, task);
6841         return 0;
6842  }
6843 @@ -462,6 +505,17 @@ static int do_task_stat(struct seq_file 
6844         /* convert nsec -> ticks */
6845         start_time = nsec_to_clock_t(start_time);
6846  
6847 +       /* fixup start time for virt uptime */
6848 +       if (vx_flags(VXF_VIRT_UPTIME, 0)) {
6849 +               unsigned long long bias =
6850 +                       current->vx_info->cvirt.bias_clock;
6851 +
6852 +               if (start_time > bias)
6853 +                       start_time -= bias;
6854 +               else
6855 +                       start_time = 0;
6856 +       }
6857 +
6858         seq_printf(m, "%d (%s) %c %d %d %d %d %d %u %lu \
6859  %lu %lu %lu %lu %lu %ld %ld %ld %ld %d 0 %llu %lu %ld %lu %lu %lu %lu %lu \
6860  %lu %lu %lu %lu %lu %lu %lu %lu %d %d %u %u %llu %lu %ld\n",
6861 diff -NurpP --minimal linux-2.6.38.1/fs/proc/base.c linux-2.6.38.1-vs2.3.0.37-rc9/fs/proc/base.c
6862 --- linux-2.6.38.1/fs/proc/base.c       2011-03-15 18:07:33.000000000 +0100
6863 +++ linux-2.6.38.1-vs2.3.0.37-rc9/fs/proc/base.c        2011-03-15 18:15:06.000000000 +0100
6864 @@ -83,6 +83,8 @@
6865  #include <linux/pid_namespace.h>
6866  #include <linux/fs_struct.h>
6867  #include <linux/slab.h>
6868 +#include <linux/vs_context.h>
6869 +#include <linux/vs_network.h>
6870  #include "internal.h"
6871  
6872  /* NOTE:
6873 @@ -1043,11 +1045,16 @@ static ssize_t oom_adjust_write(struct f
6874                 goto err_task_lock;
6875         }
6876  
6877 -       if (oom_adjust < task->signal->oom_adj && !capable(CAP_SYS_RESOURCE)) {
6878 +       if (oom_adjust < task->signal->oom_adj &&
6879 +               !vx_capable(CAP_SYS_RESOURCE, VXC_OOM_ADJUST)) {
6880                 err = -EACCES;
6881                 goto err_sighand;
6882         }
6883  
6884 +       /* prevent guest processes from circumventing the oom killer */
6885 +       if (vx_current_xid() && (oom_adjust == OOM_DISABLE))
6886 +               oom_adjust = OOM_ADJUST_MIN;
6887 +
6888         if (oom_adjust != task->signal->oom_adj) {
6889                 if (oom_adjust == OOM_DISABLE)
6890                         atomic_inc(&task->mm->oom_disable_count);
6891 @@ -1216,7 +1223,7 @@ static ssize_t proc_loginuid_write(struc
6892         ssize_t length;
6893         uid_t loginuid;
6894  
6895 -       if (!capable(CAP_AUDIT_CONTROL))
6896 +       if (!vx_capable(CAP_AUDIT_CONTROL, VXC_AUDIT_CONTROL))
6897                 return -EPERM;
6898  
6899         rcu_read_lock();
6900 @@ -1715,6 +1722,8 @@ static struct inode *proc_pid_make_inode
6901                 inode->i_gid = cred->egid;
6902                 rcu_read_unlock();
6903         }
6904 +       /* procfs is xid tagged */
6905 +       inode->i_tag = (tag_t)vx_task_xid(task);
6906         security_task_to_inode(task, inode);
6907  
6908  out:
6909 @@ -1751,6 +1760,8 @@ static int pid_getattr(struct vfsmount *
6910  
6911  /* dentry stuff */
6912  
6913 +static unsigned name_to_int(struct dentry *dentry);
6914 +
6915  /*
6916   *     Exceptional case: normally we are not allowed to unhash a busy
6917   * directory. In this case, however, we can do it - no aliasing problems
6918 @@ -1779,6 +1790,12 @@ static int pid_revalidate(struct dentry 
6919         task = get_proc_task(inode);
6920  
6921         if (task) {
6922 +               unsigned pid = name_to_int(dentry);
6923 +
6924 +               if (pid != ~0U && pid != vx_map_pid(task->pid)) {
6925 +                       put_task_struct(task);
6926 +                       goto drop;
6927 +               }
6928                 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
6929                     task_dumpable(task)) {
6930                         rcu_read_lock();
6931 @@ -1795,6 +1812,7 @@ static int pid_revalidate(struct dentry 
6932                 put_task_struct(task);
6933                 return 1;
6934         }
6935 +drop:
6936         d_drop(dentry);
6937         return 0;
6938  }
6939 @@ -2283,6 +2301,13 @@ static struct dentry *proc_pident_lookup
6940         if (!task)
6941                 goto out_no_task;
6942  
6943 +       /* TODO: maybe we can come up with a generic approach? */
6944 +       if (task_vx_flags(task, VXF_HIDE_VINFO, 0) &&
6945 +               (dentry->d_name.len == 5) &&
6946 +               (!memcmp(dentry->d_name.name, "vinfo", 5) ||
6947 +               !memcmp(dentry->d_name.name, "ninfo", 5)))
6948 +               goto out;
6949 +
6950         /*
6951          * Yes, it does not scale. And it should not. Don't add
6952          * new entries into /proc/<tgid>/ without very good reasons.
6953 @@ -2668,7 +2693,7 @@ out_iput:
6954  static struct dentry *proc_base_lookup(struct inode *dir, struct dentry *dentry)
6955  {
6956         struct dentry *error;
6957 -       struct task_struct *task = get_proc_task(dir);
6958 +       struct task_struct *task = get_proc_task_real(dir);
6959         const struct pid_entry *p, *last;
6960  
6961         error = ERR_PTR(-ENOENT);
6962 @@ -2758,6 +2783,9 @@ static int proc_pid_personality(struct s
6963  static const struct file_operations proc_task_operations;
6964  static const struct inode_operations proc_task_inode_operations;
6965  
6966 +extern int proc_pid_vx_info(struct task_struct *, char *);
6967 +extern int proc_pid_nx_info(struct task_struct *, char *);
6968 +
6969  static const struct pid_entry tgid_base_stuff[] = {
6970         DIR("task",       S_IRUGO|S_IXUGO, proc_task_inode_operations, proc_task_operations),
6971         DIR("fd",         S_IRUSR|S_IXUSR, proc_fd_inode_operations, proc_fd_operations),
6972 @@ -2820,6 +2848,8 @@ static const struct pid_entry tgid_base_
6973  #ifdef CONFIG_CGROUPS
6974         REG("cgroup",  S_IRUGO, proc_cgroup_operations),
6975  #endif
6976 +       INF("vinfo",      S_IRUGO, proc_pid_vx_info),
6977 +       INF("ninfo",      S_IRUGO, proc_pid_nx_info),
6978         INF("oom_score",  S_IRUGO, proc_oom_score),
6979         REG("oom_adj",    S_IRUGO|S_IWUSR, proc_oom_adjust_operations),
6980         REG("oom_score_adj", S_IRUGO|S_IWUSR, proc_oom_score_adj_operations),
6981 @@ -2836,6 +2866,7 @@ static const struct pid_entry tgid_base_
6982  #ifdef CONFIG_TASK_IO_ACCOUNTING
6983         INF("io",       S_IRUGO, proc_tgid_io_accounting),
6984  #endif
6985 +       ONE("nsproxy",  S_IRUGO, proc_pid_nsproxy),
6986  };
6987  
6988  static int proc_tgid_base_readdir(struct file * filp,
6989 @@ -3028,7 +3059,7 @@ retry:
6990         iter.task = NULL;
6991         pid = find_ge_pid(iter.tgid, ns);
6992         if (pid) {
6993 -               iter.tgid = pid_nr_ns(pid, ns);
6994 +               iter.tgid = pid_unmapped_nr_ns(pid, ns);
6995                 iter.task = pid_task(pid, PIDTYPE_PID);
6996                 /* What we to know is if the pid we have find is the
6997                  * pid of a thread_group_leader.  Testing for task
6998 @@ -3058,7 +3089,7 @@ static int proc_pid_fill_cache(struct fi
6999         struct tgid_iter iter)
7000  {
7001         char name[PROC_NUMBUF];
7002 -       int len = snprintf(name, sizeof(name), "%d", iter.tgid);
7003 +       int len = snprintf(name, sizeof(name), "%d", vx_map_tgid(iter.tgid));
7004         return proc_fill_cache(filp, dirent, filldir, name, len,
7005                                 proc_pid_instantiate, iter.task, NULL);
7006  }
7007 @@ -3067,7 +3098,7 @@ static int proc_pid_fill_cache(struct fi
7008  int proc_pid_readdir(struct file * filp, void * dirent, filldir_t filldir)
7009  {
7010         unsigned int nr = filp->f_pos - FIRST_PROCESS_ENTRY;
7011 -       struct task_struct *reaper = get_proc_task(filp->f_path.dentry->d_inode);
7012 +       struct task_struct *reaper = get_proc_task_real(filp->f_path.dentry->d_inode);
7013         struct tgid_iter iter;
7014         struct pid_namespace *ns;
7015  
7016 @@ -3087,6 +3118,8 @@ int proc_pid_readdir(struct file * filp,
7017              iter.task;
7018              iter.tgid += 1, iter = next_tgid(ns, iter)) {
7019                 filp->f_pos = iter.tgid + TGID_OFFSET;
7020 +               if (!vx_proc_task_visible(iter.task))
7021 +                       continue;
7022                 if (proc_pid_fill_cache(filp, dirent, filldir, iter) < 0) {
7023                         put_task_struct(iter.task);
7024                         goto out;
7025 @@ -3236,6 +3269,8 @@ static struct dentry *proc_task_lookup(s
7026         tid = name_to_int(dentry);
7027         if (tid == ~0U)
7028                 goto out;
7029 +       if (vx_current_initpid(tid))
7030 +               goto out;
7031  
7032         ns = dentry->d_sb->s_fs_info;
7033         rcu_read_lock();
7034 diff -NurpP --minimal linux-2.6.38.1/fs/proc/generic.c linux-2.6.38.1-vs2.3.0.37-rc9/fs/proc/generic.c
7035 --- linux-2.6.38.1/fs/proc/generic.c    2011-03-15 18:07:33.000000000 +0100
7036 +++ linux-2.6.38.1-vs2.3.0.37-rc9/fs/proc/generic.c     2011-01-29 02:29:09.000000000 +0100
7037 @@ -22,6 +22,7 @@
7038  #include <linux/bitops.h>
7039  #include <linux/spinlock.h>
7040  #include <linux/completion.h>
7041 +#include <linux/vserver/inode.h>
7042  #include <asm/uaccess.h>
7043  
7044  #include "internal.h"
7045 @@ -424,11 +425,15 @@ struct dentry *proc_lookup_de(struct pro
7046         for (de = de->subdir; de ; de = de->next) {
7047                 if (de->namelen != dentry->d_name.len)
7048                         continue;
7049 +               if (!vx_hide_check(0, de->vx_flags))
7050 +                       continue;
7051                 if (!memcmp(dentry->d_name.name, de->name, de->namelen)) {
7052                         pde_get(de);
7053                         spin_unlock(&proc_subdir_lock);
7054                         error = -EINVAL;
7055                         inode = proc_get_inode(dir->i_sb, de);
7056 +                       /* generic proc entries belong to the host */
7057 +                       inode->i_tag = 0;
7058                         goto out_unlock;
7059                 }
7060         }
7061 @@ -506,6 +511,8 @@ int proc_readdir_de(struct proc_dir_entr
7062  
7063                                 /* filldir passes info to user space */
7064                                 pde_get(de);
7065 +                               if (!vx_hide_check(0, de->vx_flags))
7066 +                                       goto skip;
7067                                 spin_unlock(&proc_subdir_lock);
7068                                 if (filldir(dirent, de->name, de->namelen, filp->f_pos,
7069                                             de->low_ino, de->mode >> 12) < 0) {
7070 @@ -513,6 +520,7 @@ int proc_readdir_de(struct proc_dir_entr
7071                                         goto out;
7072                                 }
7073                                 spin_lock(&proc_subdir_lock);
7074 +                       skip:
7075                                 filp->f_pos++;
7076                                 next = de->next;
7077                                 pde_put(de);
7078 @@ -627,6 +635,7 @@ static struct proc_dir_entry *__proc_cre
7079         ent->nlink = nlink;
7080         atomic_set(&ent->count, 1);
7081         ent->pde_users = 0;
7082 +       ent->vx_flags = IATTR_PROC_DEFAULT;
7083         spin_lock_init(&ent->pde_unload_lock);
7084         ent->pde_unload_completion = NULL;
7085         INIT_LIST_HEAD(&ent->pde_openers);
7086 @@ -650,7 +659,8 @@ struct proc_dir_entry *proc_symlink(cons
7087                                 kfree(ent->data);
7088                                 kfree(ent);
7089                                 ent = NULL;
7090 -                       }
7091 +                       } else
7092 +                               ent->vx_flags = IATTR_PROC_SYMLINK;
7093                 } else {
7094                         kfree(ent);
7095                         ent = NULL;
7096 diff -NurpP --minimal linux-2.6.38.1/fs/proc/inode.c linux-2.6.38.1-vs2.3.0.37-rc9/fs/proc/inode.c
7097 --- linux-2.6.38.1/fs/proc/inode.c      2011-03-15 18:07:33.000000000 +0100
7098 +++ linux-2.6.38.1-vs2.3.0.37-rc9/fs/proc/inode.c       2011-03-15 18:15:06.000000000 +0100
7099 @@ -437,6 +437,8 @@ struct inode *proc_get_inode(struct supe
7100                         inode->i_uid = de->uid;
7101                         inode->i_gid = de->gid;
7102                 }
7103 +               if (de->vx_flags)
7104 +                       PROC_I(inode)->vx_flags = de->vx_flags;
7105                 if (de->size)
7106                         inode->i_size = de->size;
7107                 if (de->nlink)
7108 diff -NurpP --minimal linux-2.6.38.1/fs/proc/internal.h linux-2.6.38.1-vs2.3.0.37-rc9/fs/proc/internal.h
7109 --- linux-2.6.38.1/fs/proc/internal.h   2011-03-15 18:07:33.000000000 +0100
7110 +++ linux-2.6.38.1-vs2.3.0.37-rc9/fs/proc/internal.h    2011-01-29 02:01:07.000000000 +0100
7111 @@ -10,6 +10,7 @@
7112   */
7113  
7114  #include <linux/proc_fs.h>
7115 +#include <linux/vs_pid.h>
7116  
7117  extern struct proc_dir_entry proc_root;
7118  #ifdef CONFIG_PROC_SYSCTL
7119 @@ -51,6 +52,9 @@ extern int proc_pid_status(struct seq_fi
7120                                 struct pid *pid, struct task_struct *task);
7121  extern int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
7122                                 struct pid *pid, struct task_struct *task);
7123 +extern int proc_pid_nsproxy(struct seq_file *m, struct pid_namespace *ns,
7124 +                               struct pid *pid, struct task_struct *task);
7125 +
7126  extern loff_t mem_lseek(struct file *file, loff_t offset, int orig);
7127  
7128  extern const struct file_operations proc_maps_operations;
7129 @@ -68,11 +72,16 @@ static inline struct pid *proc_pid(struc
7130         return PROC_I(inode)->pid;
7131  }
7132  
7133 -static inline struct task_struct *get_proc_task(struct inode *inode)
7134 +static inline struct task_struct *get_proc_task_real(struct inode *inode)
7135  {
7136         return get_pid_task(proc_pid(inode), PIDTYPE_PID);
7137  }
7138  
7139 +static inline struct task_struct *get_proc_task(struct inode *inode)
7140 +{
7141 +       return vx_get_proc_task(inode, proc_pid(inode));
7142 +}
7143 +
7144  static inline int proc_fd(struct inode *inode)
7145  {
7146         return PROC_I(inode)->fd;
7147 diff -NurpP --minimal linux-2.6.38.1/fs/proc/loadavg.c linux-2.6.38.1-vs2.3.0.37-rc9/fs/proc/loadavg.c
7148 --- linux-2.6.38.1/fs/proc/loadavg.c    2009-09-10 15:26:23.000000000 +0200
7149 +++ linux-2.6.38.1-vs2.3.0.37-rc9/fs/proc/loadavg.c     2011-01-29 02:01:07.000000000 +0100
7150 @@ -12,15 +12,27 @@
7151  
7152  static int loadavg_proc_show(struct seq_file *m, void *v)
7153  {
7154 +       unsigned long running;
7155 +       unsigned int threads;
7156         unsigned long avnrun[3];
7157  
7158         get_avenrun(avnrun, FIXED_1/200, 0);
7159  
7160 +       if (vx_flags(VXF_VIRT_LOAD, 0)) {
7161 +               struct vx_info *vxi = current_vx_info();
7162 +
7163 +               running = atomic_read(&vxi->cvirt.nr_running);
7164 +               threads = atomic_read(&vxi->cvirt.nr_threads);
7165 +       } else {
7166 +               running = nr_running();
7167 +               threads = nr_threads;
7168 +       }
7169 +
7170         seq_printf(m, "%lu.%02lu %lu.%02lu %lu.%02lu %ld/%d %d\n",
7171                 LOAD_INT(avnrun[0]), LOAD_FRAC(avnrun[0]),
7172                 LOAD_INT(avnrun[1]), LOAD_FRAC(avnrun[1]),
7173                 LOAD_INT(avnrun[2]), LOAD_FRAC(avnrun[2]),
7174 -               nr_running(), nr_threads,
7175 +               running, threads,
7176                 task_active_pid_ns(current)->last_pid);
7177         return 0;
7178  }
7179 diff -NurpP --minimal linux-2.6.38.1/fs/proc/meminfo.c linux-2.6.38.1-vs2.3.0.37-rc9/fs/proc/meminfo.c
7180 --- linux-2.6.38.1/fs/proc/meminfo.c    2011-03-15 18:07:33.000000000 +0100
7181 +++ linux-2.6.38.1-vs2.3.0.37-rc9/fs/proc/meminfo.c     2011-01-29 02:01:07.000000000 +0100
7182 @@ -39,7 +39,8 @@ static int meminfo_proc_show(struct seq_
7183         allowed = ((totalram_pages - hugetlb_total_pages())
7184                 * sysctl_overcommit_ratio / 100) + total_swap_pages;
7185  
7186 -       cached = global_page_state(NR_FILE_PAGES) -
7187 +       cached = vx_flags(VXF_VIRT_MEM, 0) ?
7188 +               vx_vsi_cached(&i) : global_page_state(NR_FILE_PAGES) -
7189                         total_swapcache_pages - i.bufferram;
7190         if (cached < 0)
7191                 cached = 0;
7192 diff -NurpP --minimal linux-2.6.38.1/fs/proc/root.c linux-2.6.38.1-vs2.3.0.37-rc9/fs/proc/root.c
7193 --- linux-2.6.38.1/fs/proc/root.c       2011-01-05 21:50:26.000000000 +0100
7194 +++ linux-2.6.38.1-vs2.3.0.37-rc9/fs/proc/root.c        2011-01-29 02:01:07.000000000 +0100
7195 @@ -18,9 +18,14 @@
7196  #include <linux/bitops.h>
7197  #include <linux/mount.h>
7198  #include <linux/pid_namespace.h>
7199 +#include <linux/vserver/inode.h>
7200  
7201  #include "internal.h"
7202  
7203 +struct proc_dir_entry *proc_virtual;
7204 +
7205 +extern void proc_vx_init(void);
7206 +
7207  static int proc_test_super(struct super_block *sb, void *data)
7208  {
7209         return sb->s_fs_info == data;
7210 @@ -134,6 +139,7 @@ void __init proc_root_init(void)
7211  #endif
7212         proc_mkdir("bus", NULL);
7213         proc_sys_init();
7214 +       proc_vx_init();
7215  }
7216  
7217  static int proc_root_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat
7218 @@ -202,6 +208,7 @@ struct proc_dir_entry proc_root = {
7219         .proc_iops      = &proc_root_inode_operations, 
7220         .proc_fops      = &proc_root_operations,
7221         .parent         = &proc_root,
7222 +       .vx_flags       = IATTR_ADMIN | IATTR_WATCH,
7223  };
7224  
7225  int pid_ns_prepare_proc(struct pid_namespace *ns)
7226 diff -NurpP --minimal linux-2.6.38.1/fs/proc/uptime.c linux-2.6.38.1-vs2.3.0.37-rc9/fs/proc/uptime.c
7227 --- linux-2.6.38.1/fs/proc/uptime.c     2009-12-03 20:02:53.000000000 +0100
7228 +++ linux-2.6.38.1-vs2.3.0.37-rc9/fs/proc/uptime.c      2011-01-29 02:01:07.000000000 +0100
7229 @@ -4,22 +4,22 @@
7230  #include <linux/sched.h>
7231  #include <linux/seq_file.h>
7232  #include <linux/time.h>
7233 -#include <linux/kernel_stat.h>
7234 +#include <linux/vserver/cvirt.h>
7235  #include <asm/cputime.h>
7236  
7237  static int uptime_proc_show(struct seq_file *m, void *v)
7238  {
7239         struct timespec uptime;
7240         struct timespec idle;
7241 -       int i;
7242 -       cputime_t idletime = cputime_zero;
7243 -
7244 -       for_each_possible_cpu(i)
7245 -               idletime = cputime64_add(idletime, kstat_cpu(i).cpustat.idle);
7246 +       cputime_t idletime = cputime_add(init_task.utime, init_task.stime);
7247  
7248         do_posix_clock_monotonic_gettime(&uptime);
7249         monotonic_to_bootbased(&uptime);
7250         cputime_to_timespec(idletime, &idle);
7251 +
7252 +       if (vx_flags(VXF_VIRT_UPTIME, 0))
7253 +               vx_vsi_uptime(&uptime, &idle);
7254 +
7255         seq_printf(m, "%lu.%02lu %lu.%02lu\n",
7256                         (unsigned long) uptime.tv_sec,
7257                         (uptime.tv_nsec / (NSEC_PER_SEC / 100)),
7258 diff -NurpP --minimal linux-2.6.38.1/fs/quota/dquot.c linux-2.6.38.1-vs2.3.0.37-rc9/fs/quota/dquot.c
7259 --- linux-2.6.38.1/fs/quota/dquot.c     2011-03-15 18:07:33.000000000 +0100
7260 +++ linux-2.6.38.1-vs2.3.0.37-rc9/fs/quota/dquot.c      2011-01-29 02:01:07.000000000 +0100
7261 @@ -1545,6 +1545,9 @@ int __dquot_alloc_space(struct inode *in
7262         int reserve = flags & DQUOT_SPACE_RESERVE;
7263         int nofail = flags & DQUOT_SPACE_NOFAIL;
7264  
7265 +       if ((ret = dl_alloc_space(inode, number)))
7266 +               return ret;
7267 +
7268         /*
7269          * First test before acquiring mutex - solves deadlocks when we
7270          * re-enter the quota code and are already holding the mutex
7271 @@ -1599,6 +1602,9 @@ int dquot_alloc_inode(const struct inode
7272         int cnt, ret = 0;
7273         char warntype[MAXQUOTAS];
7274  
7275 +       if ((ret = dl_alloc_inode(inode)))
7276 +               return ret;
7277 +
7278         /* First test before acquiring mutex - solves deadlocks when we
7279           * re-enter the quota code and are already holding the mutex */
7280         if (!dquot_active(inode))
7281 @@ -1669,6 +1675,8 @@ void __dquot_free_space(struct inode *in
7282         char warntype[MAXQUOTAS];
7283         int reserve = flags & DQUOT_SPACE_RESERVE;
7284  
7285 +       dl_free_space(inode, number);
7286 +
7287         /* First test before acquiring mutex - solves deadlocks when we
7288           * re-enter the quota code and are already holding the mutex */
7289         if (!dquot_active(inode)) {
7290 @@ -1707,6 +1715,8 @@ void dquot_free_inode(const struct inode
7291         unsigned int cnt;
7292         char warntype[MAXQUOTAS];
7293  
7294 +       dl_free_inode(inode);
7295 +
7296         /* First test before acquiring mutex - solves deadlocks when we
7297           * re-enter the quota code and are already holding the mutex */
7298         if (!dquot_active(inode))
7299 diff -NurpP --minimal linux-2.6.38.1/fs/quota/quota.c linux-2.6.38.1-vs2.3.0.37-rc9/fs/quota/quota.c
7300 --- linux-2.6.38.1/fs/quota/quota.c     2011-03-15 18:07:34.000000000 +0100
7301 +++ linux-2.6.38.1-vs2.3.0.37-rc9/fs/quota/quota.c      2011-01-29 02:01:07.000000000 +0100
7302 @@ -8,6 +8,7 @@
7303  #include <linux/fs.h>
7304  #include <linux/namei.h>
7305  #include <linux/slab.h>
7306 +#include <linux/vs_context.h>
7307  #include <asm/current.h>
7308  #include <asm/uaccess.h>
7309  #include <linux/kernel.h>
7310 @@ -38,7 +39,7 @@ static int check_quotactl_permission(str
7311                         break;
7312                 /*FALLTHROUGH*/
7313         default:
7314 -               if (!capable(CAP_SYS_ADMIN))
7315 +               if (!vx_capable(CAP_SYS_ADMIN, VXC_QUOTA_CTL))
7316                         return -EPERM;
7317         }
7318  
7319 @@ -293,6 +294,46 @@ static int do_quotactl(struct super_bloc
7320         }
7321  }
7322  
7323 +#if defined(CONFIG_BLK_DEV_VROOT) || defined(CONFIG_BLK_DEV_VROOT_MODULE)
7324 +
7325 +#include <linux/vroot.h>
7326 +#include <linux/major.h>
7327 +#include <linux/module.h>
7328 +#include <linux/kallsyms.h>
7329 +#include <linux/vserver/debug.h>
7330 +
7331 +static vroot_grb_func *vroot_get_real_bdev = NULL;
7332 +
7333 +static spinlock_t vroot_grb_lock = SPIN_LOCK_UNLOCKED;
7334 +
7335 +int register_vroot_grb(vroot_grb_func *func) {
7336 +       int ret = -EBUSY;
7337 +
7338 +       spin_lock(&vroot_grb_lock);
7339 +       if (!vroot_get_real_bdev) {
7340 +               vroot_get_real_bdev = func;
7341 +               ret = 0;
7342 +       }
7343 +       spin_unlock(&vroot_grb_lock);
7344 +       return ret;
7345 +}
7346 +EXPORT_SYMBOL(register_vroot_grb);
7347 +
7348 +int unregister_vroot_grb(vroot_grb_func *func) {
7349 +       int ret = -EINVAL;
7350 +
7351 +       spin_lock(&vroot_grb_lock);
7352 +       if (vroot_get_real_bdev) {
7353 +               vroot_get_real_bdev = NULL;
7354 +               ret = 0;
7355 +       }
7356 +       spin_unlock(&vroot_grb_lock);
7357 +       return ret;
7358 +}
7359 +EXPORT_SYMBOL(unregister_vroot_grb);
7360 +
7361 +#endif
7362 +
7363  /*
7364   * look up a superblock on which quota ops will be performed
7365   * - use the name of a block device to find the superblock thereon
7366 @@ -310,6 +351,22 @@ static struct super_block *quotactl_bloc
7367         putname(tmp);
7368         if (IS_ERR(bdev))
7369                 return ERR_CAST(bdev);
7370 +#if defined(CONFIG_BLK_DEV_VROOT) || defined(CONFIG_BLK_DEV_VROOT_MODULE)
7371 +       if (bdev && bdev->bd_inode &&
7372 +                       imajor(bdev->bd_inode) == VROOT_MAJOR) {
7373 +               struct block_device *bdnew = (void *)-EINVAL;
7374 +
7375 +               if (vroot_get_real_bdev)
7376 +                       bdnew = vroot_get_real_bdev(bdev);
7377 +               else
7378 +                       vxdprintk(VXD_CBIT(misc, 0),
7379 +                                       "vroot_get_real_bdev not set");
7380 +               bdput(bdev);
7381 +               if (IS_ERR(bdnew))
7382 +                       return ERR_PTR(PTR_ERR(bdnew));
7383 +               bdev = bdnew;
7384 +       }
7385 +#endif
7386         sb = get_super(bdev);
7387         bdput(bdev);
7388         if (!sb)
7389 diff -NurpP --minimal linux-2.6.38.1/fs/reiserfs/file.c linux-2.6.38.1-vs2.3.0.37-rc9/fs/reiserfs/file.c
7390 --- linux-2.6.38.1/fs/reiserfs/file.c   2011-01-05 21:50:26.000000000 +0100
7391 +++ linux-2.6.38.1-vs2.3.0.37-rc9/fs/reiserfs/file.c    2011-01-29 02:01:07.000000000 +0100
7392 @@ -312,4 +312,5 @@ const struct inode_operations reiserfs_f
7393         .listxattr = reiserfs_listxattr,
7394         .removexattr = reiserfs_removexattr,
7395         .permission = reiserfs_permission,
7396 +       .sync_flags = reiserfs_sync_flags,
7397  };
7398 diff -NurpP --minimal linux-2.6.38.1/fs/reiserfs/inode.c linux-2.6.38.1-vs2.3.0.37-rc9/fs/reiserfs/inode.c
7399 --- linux-2.6.38.1/fs/reiserfs/inode.c  2011-01-05 21:50:26.000000000 +0100
7400 +++ linux-2.6.38.1-vs2.3.0.37-rc9/fs/reiserfs/inode.c   2011-01-29 02:01:07.000000000 +0100
7401 @@ -18,6 +18,7 @@
7402  #include <linux/writeback.h>
7403  #include <linux/quotaops.h>
7404  #include <linux/swap.h>
7405 +#include <linux/vs_tag.h>
7406  
7407  int reiserfs_commit_write(struct file *f, struct page *page,
7408                           unsigned from, unsigned to);
7409 @@ -1131,6 +1132,8 @@ static void init_inode(struct inode *ino
7410         struct buffer_head *bh;
7411         struct item_head *ih;
7412         __u32 rdev;
7413 +       uid_t uid;
7414 +       gid_t gid;
7415         //int version = ITEM_VERSION_1;
7416  
7417         bh = PATH_PLAST_BUFFER(path);
7418 @@ -1151,12 +1154,13 @@ static void init_inode(struct inode *ino
7419                     (struct stat_data_v1 *)B_I_PITEM(bh, ih);
7420                 unsigned long blocks;
7421  
7422 +               uid = sd_v1_uid(sd);
7423 +               gid = sd_v1_gid(sd);
7424 +
7425                 set_inode_item_key_version(inode, KEY_FORMAT_3_5);
7426                 set_inode_sd_version(inode, STAT_DATA_V1);
7427                 inode->i_mode = sd_v1_mode(sd);
7428                 inode->i_nlink = sd_v1_nlink(sd);
7429 -               inode->i_uid = sd_v1_uid(sd);
7430 -               inode->i_gid = sd_v1_gid(sd);
7431                 inode->i_size = sd_v1_size(sd);
7432                 inode->i_atime.tv_sec = sd_v1_atime(sd);
7433                 inode->i_mtime.tv_sec = sd_v1_mtime(sd);
7434 @@ -1198,11 +1202,12 @@ static void init_inode(struct inode *ino
7435                 // (directories and symlinks)
7436                 struct stat_data *sd = (struct stat_data *)B_I_PITEM(bh, ih);
7437  
7438 +               uid    = sd_v2_uid(sd);
7439 +               gid    = sd_v2_gid(sd);
7440 +
7441                 inode->i_mode = sd_v2_mode(sd);
7442                 inode->i_nlink = sd_v2_nlink(sd);
7443 -               inode->i_uid = sd_v2_uid(sd);
7444                 inode->i_size = sd_v2_size(sd);
7445 -               inode->i_gid = sd_v2_gid(sd);
7446                 inode->i_mtime.tv_sec = sd_v2_mtime(sd);
7447                 inode->i_atime.tv_sec = sd_v2_atime(sd);
7448                 inode->i_ctime.tv_sec = sd_v2_ctime(sd);
7449 @@ -1232,6 +1237,10 @@ static void init_inode(struct inode *ino
7450                 sd_attrs_to_i_attrs(sd_v2_attrs(sd), inode);
7451         }
7452  
7453 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
7454 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
7455 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid, 0);
7456 +
7457         pathrelse(path);
7458         if (S_ISREG(inode->i_mode)) {
7459                 inode->i_op = &reiserfs_file_inode_operations;
7460 @@ -1254,13 +1263,15 @@ static void init_inode(struct inode *ino
7461  static void inode2sd(void *sd, struct inode *inode, loff_t size)
7462  {
7463         struct stat_data *sd_v2 = (struct stat_data *)sd;
7464 +       uid_t uid = TAGINO_UID(DX_TAG(inode), inode->i_uid, inode->i_tag);
7465 +       gid_t gid = TAGINO_GID(DX_TAG(inode), inode->i_gid, inode->i_tag);
7466         __u16 flags;
7467  
7468 +       set_sd_v2_uid(sd_v2, uid);
7469 +       set_sd_v2_gid(sd_v2, gid);
7470         set_sd_v2_mode(sd_v2, inode->i_mode);
7471         set_sd_v2_nlink(sd_v2, inode->i_nlink);
7472 -       set_sd_v2_uid(sd_v2, inode->i_uid);
7473         set_sd_v2_size(sd_v2, size);
7474 -       set_sd_v2_gid(sd_v2, inode->i_gid);
7475         set_sd_v2_mtime(sd_v2, inode->i_mtime.tv_sec);
7476         set_sd_v2_atime(sd_v2, inode->i_atime.tv_sec);
7477         set_sd_v2_ctime(sd_v2, inode->i_ctime.tv_sec);
7478 @@ -2858,14 +2869,19 @@ int reiserfs_commit_write(struct file *f
7479  void sd_attrs_to_i_attrs(__u16 sd_attrs, struct inode *inode)
7480  {
7481         if (reiserfs_attrs(inode->i_sb)) {
7482 -               if (sd_attrs & REISERFS_SYNC_FL)
7483 -                       inode->i_flags |= S_SYNC;
7484 -               else
7485 -                       inode->i_flags &= ~S_SYNC;
7486                 if (sd_attrs & REISERFS_IMMUTABLE_FL)
7487                         inode->i_flags |= S_IMMUTABLE;
7488                 else
7489                         inode->i_flags &= ~S_IMMUTABLE;
7490 +               if (sd_attrs & REISERFS_IXUNLINK_FL)
7491 +                       inode->i_flags |= S_IXUNLINK;
7492 +               else
7493 +                       inode->i_flags &= ~S_IXUNLINK;
7494 +
7495 +               if (sd_attrs & REISERFS_SYNC_FL)
7496 +                       inode->i_flags |= S_SYNC;
7497 +               else
7498 +                       inode->i_flags &= ~S_SYNC;
7499                 if (sd_attrs & REISERFS_APPEND_FL)
7500                         inode->i_flags |= S_APPEND;
7501                 else
7502 @@ -2878,6 +2894,15 @@ void sd_attrs_to_i_attrs(__u16 sd_attrs,
7503                         REISERFS_I(inode)->i_flags |= i_nopack_mask;
7504                 else
7505                         REISERFS_I(inode)->i_flags &= ~i_nopack_mask;
7506 +
7507 +               if (sd_attrs & REISERFS_BARRIER_FL)
7508 +                       inode->i_vflags |= V_BARRIER;
7509 +               else
7510 +                       inode->i_vflags &= ~V_BARRIER;
7511 +               if (sd_attrs & REISERFS_COW_FL)
7512 +                       inode->i_vflags |= V_COW;
7513 +               else
7514 +                       inode->i_vflags &= ~V_COW;
7515         }
7516  }
7517  
7518 @@ -2888,6 +2913,11 @@ void i_attrs_to_sd_attrs(struct inode *i
7519                         *sd_attrs |= REISERFS_IMMUTABLE_FL;
7520                 else
7521                         *sd_attrs &= ~REISERFS_IMMUTABLE_FL;
7522 +               if (inode->i_flags & S_IXUNLINK)
7523 +                       *sd_attrs |= REISERFS_IXUNLINK_FL;
7524 +               else
7525 +                       *sd_attrs &= ~REISERFS_IXUNLINK_FL;
7526 +
7527                 if (inode->i_flags & S_SYNC)
7528                         *sd_attrs |= REISERFS_SYNC_FL;
7529                 else
7530 @@ -2900,6 +2930,15 @@ void i_attrs_to_sd_attrs(struct inode *i
7531                         *sd_attrs |= REISERFS_NOTAIL_FL;
7532                 else
7533                         *sd_attrs &= ~REISERFS_NOTAIL_FL;
7534 +
7535 +               if (inode->i_vflags & V_BARRIER)
7536 +                       *sd_attrs |= REISERFS_BARRIER_FL;
7537 +               else
7538 +                       *sd_attrs &= ~REISERFS_BARRIER_FL;
7539 +               if (inode->i_vflags & V_COW)
7540 +                       *sd_attrs |= REISERFS_COW_FL;
7541 +               else
7542 +                       *sd_attrs &= ~REISERFS_COW_FL;
7543         }
7544  }
7545  
7546 @@ -3143,7 +3182,8 @@ int reiserfs_setattr(struct dentry *dent
7547         }
7548  
7549         if ((ia_valid & ATTR_UID && attr->ia_uid != inode->i_uid) ||
7550 -           (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid)) {
7551 +           (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid) ||
7552 +           (ia_valid & ATTR_TAG && attr->ia_tag != inode->i_tag)) {
7553                 struct reiserfs_transaction_handle th;
7554                 int jbegin_count =
7555                     2 *
7556 @@ -3172,6 +3212,9 @@ int reiserfs_setattr(struct dentry *dent
7557                         inode->i_uid = attr->ia_uid;
7558                 if (attr->ia_valid & ATTR_GID)
7559                         inode->i_gid = attr->ia_gid;
7560 +                               if ((attr->ia_valid & ATTR_TAG) &&
7561 +                                       IS_TAGGED(inode))
7562 +                                       inode->i_tag = attr->ia_tag;
7563                 mark_inode_dirty(inode);
7564                 error = journal_end(&th, inode->i_sb, jbegin_count);
7565                 if (error)
7566 diff -NurpP --minimal linux-2.6.38.1/fs/reiserfs/ioctl.c linux-2.6.38.1-vs2.3.0.37-rc9/fs/reiserfs/ioctl.c
7567 --- linux-2.6.38.1/fs/reiserfs/ioctl.c  2011-01-05 21:50:26.000000000 +0100
7568 +++ linux-2.6.38.1-vs2.3.0.37-rc9/fs/reiserfs/ioctl.c   2011-01-29 02:01:07.000000000 +0100
7569 @@ -11,6 +11,21 @@
7570  #include <linux/pagemap.h>
7571  #include <linux/compat.h>
7572  
7573 +
7574 +int reiserfs_sync_flags(struct inode *inode, int flags, int vflags)
7575 +{
7576 +       __u16 sd_attrs = 0;
7577 +
7578 +       inode->i_flags = flags;
7579 +       inode->i_vflags = vflags;
7580 +
7581 +       i_attrs_to_sd_attrs(inode, &sd_attrs);
7582 +       REISERFS_I(inode)->i_attrs = sd_attrs;
7583 +       inode->i_ctime = CURRENT_TIME_SEC;
7584 +       mark_inode_dirty(inode);
7585 +       return 0;
7586 +}
7587 +
7588  /*
7589   * reiserfs_ioctl - handler for ioctl for inode
7590   * supported commands:
7591 @@ -22,7 +37,7 @@
7592  long reiserfs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
7593  {
7594         struct inode *inode = filp->f_path.dentry->d_inode;
7595 -       unsigned int flags;
7596 +       unsigned int flags, oldflags;
7597         int err = 0;
7598  
7599         reiserfs_write_lock(inode->i_sb);
7600 @@ -47,6 +62,7 @@ long reiserfs_ioctl(struct file *filp, u
7601  
7602                 flags = REISERFS_I(inode)->i_attrs;
7603                 i_attrs_to_sd_attrs(inode, (__u16 *) & flags);
7604 +               flags &= REISERFS_FL_USER_VISIBLE;
7605                 err = put_user(flags, (int __user *)arg);
7606                 break;
7607         case REISERFS_IOC_SETFLAGS:{
7608 @@ -67,6 +83,10 @@ long reiserfs_ioctl(struct file *filp, u
7609                                 err = -EFAULT;
7610                                 goto setflags_out;
7611                         }
7612 +                       if (IS_BARRIER(inode)) {
7613 +                               vxwprintk_task(1, "messing with the barrier.");
7614 +                               return -EACCES;
7615 +                       }
7616                         /*
7617                          * Is it quota file? Do not allow user to mess with it
7618                          */
7619 @@ -91,6 +111,10 @@ long reiserfs_ioctl(struct file *filp, u
7620                                         goto setflags_out;
7621                                 }
7622                         }
7623 +
7624 +                       oldflags = REISERFS_I(inode)->i_attrs;
7625 +                       flags &= REISERFS_FL_USER_MODIFIABLE;
7626 +                       flags |= oldflags & ~REISERFS_FL_USER_MODIFIABLE;
7627                         sd_attrs_to_i_attrs(flags, inode);
7628                         REISERFS_I(inode)->i_attrs = flags;
7629                         inode->i_ctime = CURRENT_TIME_SEC;
7630 diff -NurpP --minimal linux-2.6.38.1/fs/reiserfs/namei.c linux-2.6.38.1-vs2.3.0.37-rc9/fs/reiserfs/namei.c
7631 --- linux-2.6.38.1/fs/reiserfs/namei.c  2011-03-15 18:07:34.000000000 +0100
7632 +++ linux-2.6.38.1-vs2.3.0.37-rc9/fs/reiserfs/namei.c   2011-03-10 17:21:19.000000000 +0100
7633 @@ -18,6 +18,7 @@
7634  #include <linux/reiserfs_acl.h>
7635  #include <linux/reiserfs_xattr.h>
7636  #include <linux/quotaops.h>
7637 +#include <linux/vs_tag.h>
7638  
7639  #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; }
7640  #define DEC_DIR_INODE_NLINK(i) if (i->i_nlink != 1) drop_nlink(i);
7641 @@ -362,6 +363,7 @@ static struct dentry *reiserfs_lookup(st
7642         if (retval == IO_ERROR) {
7643                 return ERR_PTR(-EIO);
7644         }
7645 +               dx_propagate_tag(nd, inode);
7646  
7647         return d_splice_alias(inode, dentry);
7648  }
7649 @@ -1532,6 +1534,7 @@ const struct inode_operations reiserfs_d
7650         .listxattr = reiserfs_listxattr,
7651         .removexattr = reiserfs_removexattr,
7652         .permission = reiserfs_permission,
7653 +       .sync_flags = reiserfs_sync_flags,
7654  };
7655  
7656  /*
7657 diff -NurpP --minimal linux-2.6.38.1/fs/reiserfs/super.c linux-2.6.38.1-vs2.3.0.37-rc9/fs/reiserfs/super.c
7658 --- linux-2.6.38.1/fs/reiserfs/super.c  2011-03-15 18:07:34.000000000 +0100
7659 +++ linux-2.6.38.1-vs2.3.0.37-rc9/fs/reiserfs/super.c   2011-01-29 02:01:07.000000000 +0100
7660 @@ -899,6 +899,14 @@ static int reiserfs_parse_options(struct
7661                 {"user_xattr",.setmask = 1 << REISERFS_UNSUPPORTED_OPT},
7662                 {"nouser_xattr",.clrmask = 1 << REISERFS_UNSUPPORTED_OPT},
7663  #endif
7664 +#ifndef CONFIG_TAGGING_NONE
7665 +               {"tagxid",.setmask = 1 << REISERFS_TAGGED},
7666 +               {"tag",.setmask = 1 << REISERFS_TAGGED},
7667 +               {"notag",.clrmask = 1 << REISERFS_TAGGED},
7668 +#endif
7669 +#ifdef CONFIG_PROPAGATE
7670 +               {"tag",.arg_required = 'T',.values = NULL},
7671 +#endif
7672  #ifdef CONFIG_REISERFS_FS_POSIX_ACL
7673                 {"acl",.setmask = 1 << REISERFS_POSIXACL},
7674                 {"noacl",.clrmask = 1 << REISERFS_POSIXACL},
7675 @@ -1208,6 +1216,14 @@ static int reiserfs_remount(struct super
7676         handle_quota_files(s, qf_names, &qfmt);
7677  #endif
7678  
7679 +       if ((mount_options & (1 << REISERFS_TAGGED)) &&
7680 +               !(s->s_flags & MS_TAGGED)) {
7681 +               reiserfs_warning(s, "super-vs01",
7682 +                       "reiserfs: tagging not permitted on remount.");
7683 +               err = -EINVAL;
7684 +               goto out_err;
7685 +       }
7686 +
7687         handle_attrs(s);
7688  
7689         /* Add options that are safe here */
7690 @@ -1690,6 +1706,10 @@ static int reiserfs_fill_super(struct su
7691                 goto error;
7692         }
7693  
7694 +       /* map mount option tagxid */
7695 +       if (REISERFS_SB(s)->s_mount_opt & (1 << REISERFS_TAGGED))
7696 +               s->s_flags |= MS_TAGGED;
7697 +
7698         rs = SB_DISK_SUPER_BLOCK(s);
7699         /* Let's do basic sanity check to verify that underlying device is not
7700            smaller than the filesystem. If the check fails then abort and scream,
7701 diff -NurpP --minimal linux-2.6.38.1/fs/reiserfs/xattr.c linux-2.6.38.1-vs2.3.0.37-rc9/fs/reiserfs/xattr.c
7702 --- linux-2.6.38.1/fs/reiserfs/xattr.c  2011-03-15 18:07:34.000000000 +0100
7703 +++ linux-2.6.38.1-vs2.3.0.37-rc9/fs/reiserfs/xattr.c   2011-03-15 18:15:06.000000000 +0100
7704 @@ -40,6 +40,7 @@
7705  #include <linux/errno.h>
7706  #include <linux/gfp.h>
7707  #include <linux/fs.h>
7708 +#include <linux/mount.h>
7709  #include <linux/file.h>
7710  #include <linux/pagemap.h>
7711  #include <linux/xattr.h>
7712 diff -NurpP --minimal linux-2.6.38.1/fs/stat.c linux-2.6.38.1-vs2.3.0.37-rc9/fs/stat.c
7713 --- linux-2.6.38.1/fs/stat.c    2011-03-15 18:07:34.000000000 +0100
7714 +++ linux-2.6.38.1-vs2.3.0.37-rc9/fs/stat.c     2011-01-29 02:01:07.000000000 +0100
7715 @@ -26,6 +26,7 @@ void generic_fillattr(struct inode *inod
7716         stat->nlink = inode->i_nlink;
7717         stat->uid = inode->i_uid;
7718         stat->gid = inode->i_gid;
7719 +       stat->tag = inode->i_tag;
7720         stat->rdev = inode->i_rdev;
7721         stat->atime = inode->i_atime;
7722         stat->mtime = inode->i_mtime;
7723 diff -NurpP --minimal linux-2.6.38.1/fs/statfs.c linux-2.6.38.1-vs2.3.0.37-rc9/fs/statfs.c
7724 --- linux-2.6.38.1/fs/statfs.c  2010-10-21 13:07:51.000000000 +0200
7725 +++ linux-2.6.38.1-vs2.3.0.37-rc9/fs/statfs.c   2011-01-29 02:01:07.000000000 +0100
7726 @@ -7,6 +7,8 @@
7727  #include <linux/statfs.h>
7728  #include <linux/security.h>
7729  #include <linux/uaccess.h>
7730 +#include <linux/vs_base.h>
7731 +#include <linux/vs_dlimit.h>
7732  
7733  static int flags_by_mnt(int mnt_flags)
7734  {
7735 @@ -59,6 +61,8 @@ int statfs_by_dentry(struct dentry *dent
7736         retval = dentry->d_sb->s_op->statfs(dentry, buf);
7737         if (retval == 0 && buf->f_frsize == 0)
7738                 buf->f_frsize = buf->f_bsize;
7739 +       if (!vx_check(0, VS_ADMIN|VS_WATCH))
7740 +               vx_vsi_statfs(dentry->d_sb, buf);
7741         return retval;
7742  }
7743  
7744 diff -NurpP --minimal linux-2.6.38.1/fs/super.c linux-2.6.38.1-vs2.3.0.37-rc9/fs/super.c
7745 --- linux-2.6.38.1/fs/super.c   2011-03-15 18:07:34.000000000 +0100
7746 +++ linux-2.6.38.1-vs2.3.0.37-rc9/fs/super.c    2011-02-17 02:17:50.000000000 +0100
7747 @@ -31,6 +31,9 @@
7748  #include <linux/mutex.h>
7749  #include <linux/backing-dev.h>
7750  #include <linux/rculist_bl.h>
7751 +#include <linux/devpts_fs.h>
7752 +#include <linux/proc_fs.h>
7753 +#include <linux/vs_context.h>
7754  #include "internal.h"
7755  
7756  
7757 @@ -963,6 +966,7 @@ struct vfsmount *
7758  vfs_kern_mount(struct file_system_type *type, int flags, const char *name, void *data)
7759  {
7760         struct vfsmount *mnt;
7761 +       struct super_block *sb;
7762         struct dentry *root;
7763         char *secdata = NULL;
7764         int error;
7765 @@ -970,6 +974,11 @@ vfs_kern_mount(struct file_system_type *
7766         if (!type)
7767                 return ERR_PTR(-ENODEV);
7768  
7769 +       error = -EPERM;
7770 +       if ((type->fs_flags & FS_BINARY_MOUNTDATA) &&
7771 +               !vx_capable(CAP_SYS_ADMIN, VXC_BINARY_MOUNT))
7772 +               goto out;
7773 +
7774         error = -ENOMEM;
7775         mnt = alloc_vfsmnt(name);
7776         if (!mnt)
7777 @@ -1001,11 +1010,19 @@ vfs_kern_mount(struct file_system_type *
7778                 if (error < 0)
7779                         goto out_free_secdata;
7780         }
7781 -       BUG_ON(!mnt->mnt_sb);
7782 -       WARN_ON(!mnt->mnt_sb->s_bdi);
7783 +
7784 +       sb = mnt->mnt_sb;
7785 +       BUG_ON(!sb);
7786 +       WARN_ON(!sb->s_bdi);
7787         mnt->mnt_sb->s_flags |= MS_BORN;
7788  
7789 -       error = security_sb_kern_mount(mnt->mnt_sb, flags, secdata);
7790 +       error = -EPERM;
7791 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_BINARY_MOUNT) && !sb->s_bdev &&
7792 +               (sb->s_magic != PROC_SUPER_MAGIC) &&
7793 +               (sb->s_magic != DEVPTS_SUPER_MAGIC))
7794 +               goto out_sb;
7795 +
7796 +       error = security_sb_kern_mount(sb, flags, secdata);
7797         if (error)
7798                 goto out_sb;
7799  
7800 diff -NurpP --minimal linux-2.6.38.1/fs/sysfs/mount.c linux-2.6.38.1-vs2.3.0.37-rc9/fs/sysfs/mount.c
7801 --- linux-2.6.38.1/fs/sysfs/mount.c     2011-01-05 21:50:27.000000000 +0100
7802 +++ linux-2.6.38.1-vs2.3.0.37-rc9/fs/sysfs/mount.c      2011-01-29 02:01:07.000000000 +0100
7803 @@ -47,7 +47,7 @@ static int sysfs_fill_super(struct super
7804  
7805         sb->s_blocksize = PAGE_CACHE_SIZE;
7806         sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
7807 -       sb->s_magic = SYSFS_MAGIC;
7808 +       sb->s_magic = SYSFS_SUPER_MAGIC;
7809         sb->s_op = &sysfs_ops;
7810         sb->s_time_gran = 1;
7811  
7812 diff -NurpP --minimal linux-2.6.38.1/fs/utimes.c linux-2.6.38.1-vs2.3.0.37-rc9/fs/utimes.c
7813 --- linux-2.6.38.1/fs/utimes.c  2010-10-21 13:07:51.000000000 +0200
7814 +++ linux-2.6.38.1-vs2.3.0.37-rc9/fs/utimes.c   2011-01-29 02:01:07.000000000 +0100
7815 @@ -8,6 +8,8 @@
7816  #include <linux/stat.h>
7817  #include <linux/utime.h>
7818  #include <linux/syscalls.h>
7819 +#include <linux/mount.h>
7820 +#include <linux/vs_cowbl.h>
7821  #include <asm/uaccess.h>
7822  #include <asm/unistd.h>
7823  
7824 @@ -52,12 +54,18 @@ static int utimes_common(struct path *pa
7825  {
7826         int error;
7827         struct iattr newattrs;
7828 -       struct inode *inode = path->dentry->d_inode;
7829 +       struct inode *inode;
7830  
7831         error = mnt_want_write(path->mnt);
7832         if (error)
7833                 goto out;
7834  
7835 +       error = cow_check_and_break(path);
7836 +       if (error)
7837 +               goto mnt_drop_write_and_out;
7838 +
7839 +       inode = path->dentry->d_inode;
7840 +
7841         if (times && times[0].tv_nsec == UTIME_NOW &&
7842                      times[1].tv_nsec == UTIME_NOW)
7843                 times = NULL;
7844 diff -NurpP --minimal linux-2.6.38.1/fs/xattr.c linux-2.6.38.1-vs2.3.0.37-rc9/fs/xattr.c
7845 --- linux-2.6.38.1/fs/xattr.c   2010-08-02 16:52:52.000000000 +0200
7846 +++ linux-2.6.38.1-vs2.3.0.37-rc9/fs/xattr.c    2011-01-29 02:01:07.000000000 +0100
7847 @@ -18,6 +18,7 @@
7848  #include <linux/module.h>
7849  #include <linux/fsnotify.h>
7850  #include <linux/audit.h>
7851 +#include <linux/mount.h>
7852  #include <asm/uaccess.h>
7853  
7854  
7855 @@ -49,7 +50,7 @@ xattr_permission(struct inode *inode, co
7856          * The trusted.* namespace can only be accessed by a privileged user.
7857          */
7858         if (!strncmp(name, XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN))
7859 -               return (capable(CAP_SYS_ADMIN) ? 0 : -EPERM);
7860 +               return (vx_capable(CAP_SYS_ADMIN, VXC_FS_TRUSTED) ? 0 : -EPERM);
7861  
7862         /* In user.* namespace, only regular files and directories can have
7863          * extended attributes. For sticky directories, only the owner and
7864 diff -NurpP --minimal linux-2.6.38.1/fs/xfs/linux-2.6/xfs_ioctl.c linux-2.6.38.1-vs2.3.0.37-rc9/fs/xfs/linux-2.6/xfs_ioctl.c
7865 --- linux-2.6.38.1/fs/xfs/linux-2.6/xfs_ioctl.c 2011-03-15 18:07:34.000000000 +0100
7866 +++ linux-2.6.38.1-vs2.3.0.37-rc9/fs/xfs/linux-2.6/xfs_ioctl.c  2011-03-10 17:21:19.000000000 +0100
7867 @@ -28,7 +28,7 @@
7868  #include "xfs_bmap_btree.h"
7869  #include "xfs_dinode.h"
7870  #include "xfs_inode.h"
7871 -#include "xfs_ioctl.h"
7872 +// #include "xfs_ioctl.h"
7873  #include "xfs_rtalloc.h"
7874  #include "xfs_itable.h"
7875  #include "xfs_error.h"
7876 @@ -744,6 +744,10 @@ xfs_merge_ioc_xflags(
7877                 xflags |= XFS_XFLAG_IMMUTABLE;
7878         else
7879                 xflags &= ~XFS_XFLAG_IMMUTABLE;
7880 +       if (flags & FS_IXUNLINK_FL)
7881 +               xflags |= XFS_XFLAG_IXUNLINK;
7882 +       else
7883 +               xflags &= ~XFS_XFLAG_IXUNLINK;
7884         if (flags & FS_APPEND_FL)
7885                 xflags |= XFS_XFLAG_APPEND;
7886         else
7887 @@ -772,6 +776,8 @@ xfs_di2lxflags(
7888  
7889         if (di_flags & XFS_DIFLAG_IMMUTABLE)
7890                 flags |= FS_IMMUTABLE_FL;
7891 +       if (di_flags & XFS_DIFLAG_IXUNLINK)
7892 +               flags |= FS_IXUNLINK_FL;
7893         if (di_flags & XFS_DIFLAG_APPEND)
7894                 flags |= FS_APPEND_FL;
7895         if (di_flags & XFS_DIFLAG_SYNC)
7896 @@ -832,6 +838,8 @@ xfs_set_diflags(
7897         di_flags = (ip->i_d.di_flags & XFS_DIFLAG_PREALLOC);
7898         if (xflags & XFS_XFLAG_IMMUTABLE)
7899                 di_flags |= XFS_DIFLAG_IMMUTABLE;
7900 +       if (xflags & XFS_XFLAG_IXUNLINK)
7901 +               di_flags |= XFS_DIFLAG_IXUNLINK;
7902         if (xflags & XFS_XFLAG_APPEND)
7903                 di_flags |= XFS_DIFLAG_APPEND;
7904         if (xflags & XFS_XFLAG_SYNC)
7905 @@ -874,6 +882,10 @@ xfs_diflags_to_linux(
7906                 inode->i_flags |= S_IMMUTABLE;
7907         else
7908                 inode->i_flags &= ~S_IMMUTABLE;
7909 +       if (xflags & XFS_XFLAG_IXUNLINK)
7910 +               inode->i_flags |= S_IXUNLINK;
7911 +       else
7912 +               inode->i_flags &= ~S_IXUNLINK;
7913         if (xflags & XFS_XFLAG_APPEND)
7914                 inode->i_flags |= S_APPEND;
7915         else
7916 @@ -1366,10 +1378,18 @@ xfs_file_ioctl(
7917         case XFS_IOC_FSGETXATTRA:
7918                 return xfs_ioc_fsgetxattr(ip, 1, arg);
7919         case XFS_IOC_FSSETXATTR:
7920 +               if (IS_BARRIER(inode)) {
7921 +                       vxwprintk_task(1, "messing with the barrier.");
7922 +                       return -XFS_ERROR(EACCES);
7923 +               }
7924                 return xfs_ioc_fssetxattr(ip, filp, arg);
7925         case XFS_IOC_GETXFLAGS:
7926                 return xfs_ioc_getxflags(ip, arg);
7927         case XFS_IOC_SETXFLAGS:
7928 +               if (IS_BARRIER(inode)) {
7929 +                       vxwprintk_task(1, "messing with the barrier.");
7930 +                       return -XFS_ERROR(EACCES);
7931 +               }
7932                 return xfs_ioc_setxflags(ip, filp, arg);
7933  
7934         case XFS_IOC_FSSETDM: {
7935 diff -NurpP --minimal linux-2.6.38.1/fs/xfs/linux-2.6/xfs_ioctl.h linux-2.6.38.1-vs2.3.0.37-rc9/fs/xfs/linux-2.6/xfs_ioctl.h
7936 --- linux-2.6.38.1/fs/xfs/linux-2.6/xfs_ioctl.h 2010-07-07 18:31:54.000000000 +0200
7937 +++ linux-2.6.38.1-vs2.3.0.37-rc9/fs/xfs/linux-2.6/xfs_ioctl.h  2011-01-29 02:01:07.000000000 +0100
7938 @@ -70,6 +70,12 @@ xfs_handle_to_dentry(
7939         void __user             *uhandle,
7940         u32                     hlen);
7941  
7942 +extern int
7943 +xfs_sync_flags(
7944 +       struct inode            *inode,
7945 +       int                     flags,
7946 +       int                     vflags);
7947 +
7948  extern long
7949  xfs_file_ioctl(
7950         struct file             *filp,
7951 diff -NurpP --minimal linux-2.6.38.1/fs/xfs/linux-2.6/xfs_iops.c linux-2.6.38.1-vs2.3.0.37-rc9/fs/xfs/linux-2.6/xfs_iops.c
7952 --- linux-2.6.38.1/fs/xfs/linux-2.6/xfs_iops.c  2011-03-15 18:07:34.000000000 +0100
7953 +++ linux-2.6.38.1-vs2.3.0.37-rc9/fs/xfs/linux-2.6/xfs_iops.c   2011-01-29 02:01:07.000000000 +0100
7954 @@ -30,6 +30,7 @@
7955  #include "xfs_bmap_btree.h"
7956  #include "xfs_dinode.h"
7957  #include "xfs_inode.h"
7958 +#include "xfs_ioctl.h"
7959  #include "xfs_bmap.h"
7960  #include "xfs_rtalloc.h"
7961  #include "xfs_error.h"
7962 @@ -48,6 +49,7 @@
7963  #include <linux/security.h>
7964  #include <linux/fiemap.h>
7965  #include <linux/slab.h>
7966 +#include <linux/vs_tag.h>
7967  
7968  /*
7969   * Bring the timestamps in the XFS inode uptodate.
7970 @@ -463,6 +465,7 @@ xfs_vn_getattr(
7971         stat->nlink = ip->i_d.di_nlink;
7972         stat->uid = ip->i_d.di_uid;
7973         stat->gid = ip->i_d.di_gid;
7974 +       stat->tag = ip->i_d.di_tag;
7975         stat->ino = ip->i_ino;
7976         stat->atime = inode->i_atime;
7977         stat->mtime = inode->i_mtime;
7978 @@ -598,6 +601,7 @@ static const struct inode_operations xfs
7979         .removexattr            = generic_removexattr,
7980         .listxattr              = xfs_vn_listxattr,
7981         .fiemap                 = xfs_vn_fiemap,
7982 +       .sync_flags             = xfs_sync_flags,
7983  };
7984  
7985  static const struct inode_operations xfs_dir_inode_operations = {
7986 @@ -623,6 +627,7 @@ static const struct inode_operations xfs
7987         .getxattr               = generic_getxattr,
7988         .removexattr            = generic_removexattr,
7989         .listxattr              = xfs_vn_listxattr,
7990 +       .sync_flags             = xfs_sync_flags,
7991  };
7992  
7993  static const struct inode_operations xfs_dir_ci_inode_operations = {
7994 @@ -672,6 +677,10 @@ xfs_diflags_to_iflags(
7995                 inode->i_flags |= S_IMMUTABLE;
7996         else
7997                 inode->i_flags &= ~S_IMMUTABLE;
7998 +       if (ip->i_d.di_flags & XFS_DIFLAG_IXUNLINK)
7999 +               inode->i_flags |= S_IXUNLINK;
8000 +       else
8001 +               inode->i_flags &= ~S_IXUNLINK;
8002         if (ip->i_d.di_flags & XFS_DIFLAG_APPEND)
8003                 inode->i_flags |= S_APPEND;
8004         else
8005 @@ -684,6 +693,15 @@ xfs_diflags_to_iflags(
8006                 inode->i_flags |= S_NOATIME;
8007         else
8008                 inode->i_flags &= ~S_NOATIME;
8009 +
8010 +       if (ip->i_d.di_vflags & XFS_DIVFLAG_BARRIER)
8011 +               inode->i_vflags |= V_BARRIER;
8012 +       else
8013 +               inode->i_vflags &= ~V_BARRIER;
8014 +       if (ip->i_d.di_vflags & XFS_DIVFLAG_COW)
8015 +               inode->i_vflags |= V_COW;
8016 +       else
8017 +               inode->i_vflags &= ~V_COW;
8018  }
8019  
8020  /*
8021 @@ -715,6 +733,7 @@ xfs_setup_inode(
8022         inode->i_nlink  = ip->i_d.di_nlink;
8023         inode->i_uid    = ip->i_d.di_uid;
8024         inode->i_gid    = ip->i_d.di_gid;
8025 +       inode->i_tag    = ip->i_d.di_tag;
8026  
8027         switch (inode->i_mode & S_IFMT) {
8028         case S_IFBLK:
8029 diff -NurpP --minimal linux-2.6.38.1/fs/xfs/linux-2.6/xfs_linux.h linux-2.6.38.1-vs2.3.0.37-rc9/fs/xfs/linux-2.6/xfs_linux.h
8030 --- linux-2.6.38.1/fs/xfs/linux-2.6/xfs_linux.h 2011-03-15 18:07:34.000000000 +0100
8031 +++ linux-2.6.38.1-vs2.3.0.37-rc9/fs/xfs/linux-2.6/xfs_linux.h  2011-01-29 02:01:07.000000000 +0100
8032 @@ -114,6 +114,7 @@
8033  
8034  #define current_cpu()          (raw_smp_processor_id())
8035  #define current_pid()          (current->pid)
8036 +#define current_fstag(vp)      (dx_current_fstag((vp)->i_sb))
8037  #define current_test_flags(f)  (current->flags & (f))
8038  #define current_set_flags_nested(sp, f)                \
8039                 (*(sp) = current->flags, current->flags |= (f))
8040 diff -NurpP --minimal linux-2.6.38.1/fs/xfs/linux-2.6/xfs_super.c linux-2.6.38.1-vs2.3.0.37-rc9/fs/xfs/linux-2.6/xfs_super.c
8041 --- linux-2.6.38.1/fs/xfs/linux-2.6/xfs_super.c 2011-03-15 18:07:34.000000000 +0100
8042 +++ linux-2.6.38.1-vs2.3.0.37-rc9/fs/xfs/linux-2.6/xfs_super.c  2011-01-29 02:01:07.000000000 +0100
8043 @@ -112,6 +112,9 @@ mempool_t *xfs_ioend_pool;
8044  #define MNTOPT_QUOTANOENF  "qnoenforce"        /* same as uqnoenforce */
8045  #define MNTOPT_DELAYLOG   "delaylog"   /* Delayed loging enabled */
8046  #define MNTOPT_NODELAYLOG "nodelaylog" /* Delayed loging disabled */
8047 +#define MNTOPT_TAGXID  "tagxid"        /* context tagging for inodes */
8048 +#define MNTOPT_TAGGED  "tag"           /* context tagging for inodes */
8049 +#define MNTOPT_NOTAGTAG        "notag"         /* do not use context tagging */
8050  
8051  /*
8052   * Table driven mount option parser.
8053 @@ -120,10 +123,14 @@ mempool_t *xfs_ioend_pool;
8054   * in the future, too.
8055   */
8056  enum {
8057 +       Opt_tag, Opt_notag,
8058         Opt_barrier, Opt_nobarrier, Opt_err
8059  };
8060  
8061  static const match_table_t tokens = {
8062 +       {Opt_tag, "tagxid"},
8063 +       {Opt_tag, "tag"},
8064 +       {Opt_notag, "notag"},
8065         {Opt_barrier, "barrier"},
8066         {Opt_nobarrier, "nobarrier"},
8067         {Opt_err, NULL}
8068 @@ -367,6 +374,19 @@ xfs_parseargs(
8069                 } else if (!strcmp(this_char, "irixsgid")) {
8070                         cmn_err(CE_WARN,
8071         "XFS: irixsgid is now a sysctl(2) variable, option is deprecated.");
8072 +#ifndef CONFIG_TAGGING_NONE
8073 +               } else if (!strcmp(this_char, MNTOPT_TAGGED)) {
8074 +                       mp->m_flags |= XFS_MOUNT_TAGGED;
8075 +               } else if (!strcmp(this_char, MNTOPT_NOTAGTAG)) {
8076 +                       mp->m_flags &= ~XFS_MOUNT_TAGGED;
8077 +               } else if (!strcmp(this_char, MNTOPT_TAGXID)) {
8078 +                       mp->m_flags |= XFS_MOUNT_TAGGED;
8079 +#endif
8080 +#ifdef CONFIG_PROPAGATE
8081 +               } else if (!strcmp(this_char, MNTOPT_TAGGED)) {
8082 +                       /* use value */
8083 +                       mp->m_flags |= XFS_MOUNT_TAGGED;
8084 +#endif
8085                 } else {
8086                         cmn_err(CE_WARN,
8087                                 "XFS: unknown mount option [%s].", this_char);
8088 @@ -1327,6 +1347,16 @@ xfs_fs_remount(
8089                 case Opt_nobarrier:
8090                         mp->m_flags &= ~XFS_MOUNT_BARRIER;
8091                         break;
8092 +               case Opt_tag:
8093 +                       if (!(sb->s_flags & MS_TAGGED)) {
8094 +                               printk(KERN_INFO
8095 +                                       "XFS: %s: tagging not permitted on remount.\n",
8096 +                                       sb->s_id);
8097 +                               return -EINVAL;
8098 +                       }
8099 +                       break;
8100 +               case Opt_notag:
8101 +                       break;
8102                 default:
8103                         /*
8104                          * Logically we would return an error here to prevent
8105 @@ -1555,6 +1585,9 @@ xfs_fs_fill_super(
8106         if (error)
8107                 goto out_filestream_unmount;
8108  
8109 +       if (mp->m_flags & XFS_MOUNT_TAGGED)
8110 +               sb->s_flags |= MS_TAGGED;
8111 +
8112         sb->s_magic = XFS_SB_MAGIC;
8113         sb->s_blocksize = mp->m_sb.sb_blocksize;
8114         sb->s_blocksize_bits = ffs(sb->s_blocksize) - 1;
8115 diff -NurpP --minimal linux-2.6.38.1/fs/xfs/xfs_dinode.h linux-2.6.38.1-vs2.3.0.37-rc9/fs/xfs/xfs_dinode.h
8116 --- linux-2.6.38.1/fs/xfs/xfs_dinode.h  2011-01-05 21:50:28.000000000 +0100
8117 +++ linux-2.6.38.1-vs2.3.0.37-rc9/fs/xfs/xfs_dinode.h   2011-01-29 02:01:07.000000000 +0100
8118 @@ -51,7 +51,9 @@ typedef struct xfs_dinode {
8119         __be32          di_nlink;       /* number of links to file */
8120         __be16          di_projid_lo;   /* lower part of owner's project id */
8121         __be16          di_projid_hi;   /* higher part owner's project id */
8122 -       __u8            di_pad[6];      /* unused, zeroed space */
8123 +       __u8            di_pad[2];      /* unused, zeroed space */
8124 +       __be16          di_tag;         /* context tagging */
8125 +       __be16          di_vflags;      /* vserver specific flags */
8126         __be16          di_flushiter;   /* incremented on flush */
8127         xfs_timestamp_t di_atime;       /* time last accessed */
8128         xfs_timestamp_t di_mtime;       /* time last modified */
8129 @@ -184,6 +186,8 @@ static inline void xfs_dinode_put_rdev(s
8130  #define XFS_DIFLAG_EXTSZINHERIT_BIT 12 /* inherit inode extent size */
8131  #define XFS_DIFLAG_NODEFRAG_BIT     13 /* do not reorganize/defragment */
8132  #define XFS_DIFLAG_FILESTREAM_BIT   14  /* use filestream allocator */
8133 +#define XFS_DIFLAG_IXUNLINK_BIT     15 /* Immutable inver on unlink */
8134 +
8135  #define XFS_DIFLAG_REALTIME      (1 << XFS_DIFLAG_REALTIME_BIT)
8136  #define XFS_DIFLAG_PREALLOC      (1 << XFS_DIFLAG_PREALLOC_BIT)
8137  #define XFS_DIFLAG_NEWRTBM       (1 << XFS_DIFLAG_NEWRTBM_BIT)
8138 @@ -199,6 +203,7 @@ static inline void xfs_dinode_put_rdev(s
8139  #define XFS_DIFLAG_EXTSZINHERIT  (1 << XFS_DIFLAG_EXTSZINHERIT_BIT)
8140  #define XFS_DIFLAG_NODEFRAG      (1 << XFS_DIFLAG_NODEFRAG_BIT)
8141  #define XFS_DIFLAG_FILESTREAM    (1 << XFS_DIFLAG_FILESTREAM_BIT)
8142 +#define XFS_DIFLAG_IXUNLINK      (1 << XFS_DIFLAG_IXUNLINK_BIT)
8143  
8144  #ifdef CONFIG_XFS_RT
8145  #define XFS_IS_REALTIME_INODE(ip) ((ip)->i_d.di_flags & XFS_DIFLAG_REALTIME)
8146 @@ -211,6 +216,10 @@ static inline void xfs_dinode_put_rdev(s
8147          XFS_DIFLAG_IMMUTABLE | XFS_DIFLAG_APPEND | XFS_DIFLAG_SYNC | \
8148          XFS_DIFLAG_NOATIME | XFS_DIFLAG_NODUMP | XFS_DIFLAG_RTINHERIT | \
8149          XFS_DIFLAG_PROJINHERIT | XFS_DIFLAG_NOSYMLINKS | XFS_DIFLAG_EXTSIZE | \
8150 -        XFS_DIFLAG_EXTSZINHERIT | XFS_DIFLAG_NODEFRAG | XFS_DIFLAG_FILESTREAM)
8151 +        XFS_DIFLAG_EXTSZINHERIT | XFS_DIFLAG_NODEFRAG | XFS_DIFLAG_FILESTREAM | \
8152 +        XFS_DIFLAG_IXUNLINK)
8153 +
8154 +#define XFS_DIVFLAG_BARRIER    0x01
8155 +#define XFS_DIVFLAG_COW                0x02
8156  
8157  #endif /* __XFS_DINODE_H__ */
8158 diff -NurpP --minimal linux-2.6.38.1/fs/xfs/xfs_fs.h linux-2.6.38.1-vs2.3.0.37-rc9/fs/xfs/xfs_fs.h
8159 --- linux-2.6.38.1/fs/xfs/xfs_fs.h      2011-01-05 21:50:28.000000000 +0100
8160 +++ linux-2.6.38.1-vs2.3.0.37-rc9/fs/xfs/xfs_fs.h       2011-01-29 02:01:07.000000000 +0100
8161 @@ -67,6 +67,9 @@ struct fsxattr {
8162  #define XFS_XFLAG_EXTSZINHERIT 0x00001000      /* inherit inode extent size */
8163  #define XFS_XFLAG_NODEFRAG     0x00002000      /* do not defragment */
8164  #define XFS_XFLAG_FILESTREAM   0x00004000      /* use filestream allocator */
8165 +#define XFS_XFLAG_IXUNLINK     0x00008000      /* immutable invert on unlink */
8166 +#define XFS_XFLAG_BARRIER      0x10000000      /* chroot() barrier */
8167 +#define XFS_XFLAG_COW          0x20000000      /* copy on write mark */
8168  #define XFS_XFLAG_HASATTR      0x80000000      /* no DIFLAG for this   */
8169  
8170  /*
8171 @@ -297,7 +300,8 @@ typedef struct xfs_bstat {
8172  #define        bs_projid       bs_projid_lo    /* (previously just bs_projid)  */
8173         __u16           bs_forkoff;     /* inode fork offset in bytes   */
8174         __u16           bs_projid_hi;   /* higher part of project id    */
8175 -       unsigned char   bs_pad[10];     /* pad space, unused            */
8176 +       unsigned char   bs_pad[8];      /* pad space, unused            */
8177 +       __u16           bs_tag;         /* context tagging              */
8178         __u32           bs_dmevmask;    /* DMIG event mask              */
8179         __u16           bs_dmstate;     /* DMIG state info              */
8180         __u16           bs_aextents;    /* attribute number of extents  */
8181 diff -NurpP --minimal linux-2.6.38.1/fs/xfs/xfs_ialloc.c linux-2.6.38.1-vs2.3.0.37-rc9/fs/xfs/xfs_ialloc.c
8182 --- linux-2.6.38.1/fs/xfs/xfs_ialloc.c  2011-01-05 21:50:28.000000000 +0100
8183 +++ linux-2.6.38.1-vs2.3.0.37-rc9/fs/xfs/xfs_ialloc.c   2011-01-29 02:01:07.000000000 +0100
8184 @@ -37,7 +37,6 @@
8185  #include "xfs_error.h"
8186  #include "xfs_bmap.h"
8187  
8188 -
8189  /*
8190   * Allocation group level functions.
8191   */
8192 diff -NurpP --minimal linux-2.6.38.1/fs/xfs/xfs_inode.c linux-2.6.38.1-vs2.3.0.37-rc9/fs/xfs/xfs_inode.c
8193 --- linux-2.6.38.1/fs/xfs/xfs_inode.c   2011-03-15 18:07:34.000000000 +0100
8194 +++ linux-2.6.38.1-vs2.3.0.37-rc9/fs/xfs/xfs_inode.c    2011-01-29 02:01:07.000000000 +0100
8195 @@ -245,6 +245,7 @@ xfs_inotobp(
8196         return 0;
8197  }
8198  
8199 +#include <linux/vs_tag.h>
8200  
8201  /*
8202   * This routine is called to map an inode to the buffer containing
8203 @@ -650,15 +651,25 @@ xfs_iformat_btree(
8204  STATIC void
8205  xfs_dinode_from_disk(
8206         xfs_icdinode_t          *to,
8207 -       xfs_dinode_t            *from)
8208 +       xfs_dinode_t            *from,
8209 +       int tagged)
8210  {
8211 +       uint32_t uid, gid, tag;
8212 +
8213         to->di_magic = be16_to_cpu(from->di_magic);
8214         to->di_mode = be16_to_cpu(from->di_mode);
8215         to->di_version = from ->di_version;
8216         to->di_format = from->di_format;
8217         to->di_onlink = be16_to_cpu(from->di_onlink);
8218 -       to->di_uid = be32_to_cpu(from->di_uid);
8219 -       to->di_gid = be32_to_cpu(from->di_gid);
8220 +
8221 +       uid = be32_to_cpu(from->di_uid);
8222 +       gid = be32_to_cpu(from->di_gid);
8223 +       tag = be16_to_cpu(from->di_tag);
8224 +
8225 +       to->di_uid = INOTAG_UID(tagged, uid, gid);
8226 +       to->di_gid = INOTAG_GID(tagged, uid, gid);
8227 +       to->di_tag = INOTAG_TAG(tagged, uid, gid, tag);
8228 +
8229         to->di_nlink = be32_to_cpu(from->di_nlink);
8230         to->di_projid_lo = be16_to_cpu(from->di_projid_lo);
8231         to->di_projid_hi = be16_to_cpu(from->di_projid_hi);
8232 @@ -680,21 +691,26 @@ xfs_dinode_from_disk(
8233         to->di_dmevmask = be32_to_cpu(from->di_dmevmask);
8234         to->di_dmstate  = be16_to_cpu(from->di_dmstate);
8235         to->di_flags    = be16_to_cpu(from->di_flags);
8236 +       to->di_vflags   = be16_to_cpu(from->di_vflags);
8237         to->di_gen      = be32_to_cpu(from->di_gen);
8238  }
8239  
8240  void
8241  xfs_dinode_to_disk(
8242         xfs_dinode_t            *to,
8243 -       xfs_icdinode_t          *from)
8244 +       xfs_icdinode_t          *from,
8245 +       int tagged)
8246  {
8247         to->di_magic = cpu_to_be16(from->di_magic);
8248         to->di_mode = cpu_to_be16(from->di_mode);
8249         to->di_version = from ->di_version;
8250         to->di_format = from->di_format;
8251         to->di_onlink = cpu_to_be16(from->di_onlink);
8252 -       to->di_uid = cpu_to_be32(from->di_uid);
8253 -       to->di_gid = cpu_to_be32(from->di_gid);
8254 +
8255 +       to->di_uid = cpu_to_be32(TAGINO_UID(tagged, from->di_uid, from->di_tag));
8256 +       to->di_gid = cpu_to_be32(TAGINO_GID(tagged, from->di_gid, from->di_tag));
8257 +       to->di_tag = cpu_to_be16(TAGINO_TAG(tagged, from->di_tag));
8258 +
8259         to->di_nlink = cpu_to_be32(from->di_nlink);
8260         to->di_projid_lo = cpu_to_be16(from->di_projid_lo);
8261         to->di_projid_hi = cpu_to_be16(from->di_projid_hi);
8262 @@ -716,12 +732,14 @@ xfs_dinode_to_disk(
8263         to->di_dmevmask = cpu_to_be32(from->di_dmevmask);
8264         to->di_dmstate = cpu_to_be16(from->di_dmstate);
8265         to->di_flags = cpu_to_be16(from->di_flags);
8266 +       to->di_vflags = cpu_to_be16(from->di_vflags);
8267         to->di_gen = cpu_to_be32(from->di_gen);
8268  }
8269  
8270  STATIC uint
8271  _xfs_dic2xflags(
8272 -       __uint16_t              di_flags)
8273 +       __uint16_t              di_flags,
8274 +       __uint16_t              di_vflags)
8275  {
8276         uint                    flags = 0;
8277  
8278 @@ -732,6 +750,8 @@ _xfs_dic2xflags(
8279                         flags |= XFS_XFLAG_PREALLOC;
8280                 if (di_flags & XFS_DIFLAG_IMMUTABLE)
8281                         flags |= XFS_XFLAG_IMMUTABLE;
8282 +               if (di_flags & XFS_DIFLAG_IXUNLINK)
8283 +                       flags |= XFS_XFLAG_IXUNLINK;
8284                 if (di_flags & XFS_DIFLAG_APPEND)
8285                         flags |= XFS_XFLAG_APPEND;
8286                 if (di_flags & XFS_DIFLAG_SYNC)
8287 @@ -756,6 +776,10 @@ _xfs_dic2xflags(
8288                         flags |= XFS_XFLAG_FILESTREAM;
8289         }
8290  
8291 +       if (di_vflags & XFS_DIVFLAG_BARRIER)
8292 +               flags |= FS_BARRIER_FL;
8293 +       if (di_vflags & XFS_DIVFLAG_COW)
8294 +               flags |= FS_COW_FL;
8295         return flags;
8296  }
8297  
8298 @@ -765,7 +789,7 @@ xfs_ip2xflags(
8299  {
8300         xfs_icdinode_t          *dic = &ip->i_d;
8301  
8302 -       return _xfs_dic2xflags(dic->di_flags) |
8303 +       return _xfs_dic2xflags(dic->di_flags, dic->di_vflags) |
8304                                 (XFS_IFORK_Q(ip) ? XFS_XFLAG_HASATTR : 0);
8305  }
8306  
8307 @@ -773,7 +797,8 @@ uint
8308  xfs_dic2xflags(
8309         xfs_dinode_t            *dip)
8310  {
8311 -       return _xfs_dic2xflags(be16_to_cpu(dip->di_flags)) |
8312 +       return _xfs_dic2xflags(be16_to_cpu(dip->di_flags),
8313 +                               be16_to_cpu(dip->di_vflags)) |
8314                                 (XFS_DFORK_Q(dip) ? XFS_XFLAG_HASATTR : 0);
8315  }
8316  
8317 @@ -806,7 +831,6 @@ xfs_iread(
8318         if (error)
8319                 return error;
8320         dip = (xfs_dinode_t *)xfs_buf_offset(bp, ip->i_imap.im_boffset);
8321 -
8322         /*
8323          * If we got something that isn't an inode it means someone
8324          * (nfs or dmi) has a stale handle.
8325 @@ -831,7 +855,8 @@ xfs_iread(
8326          * Otherwise, just get the truly permanent information.
8327          */
8328         if (dip->di_mode) {
8329 -               xfs_dinode_from_disk(&ip->i_d, dip);
8330 +               xfs_dinode_from_disk(&ip->i_d, dip,
8331 +                       mp->m_flags & XFS_MOUNT_TAGGED);
8332                 error = xfs_iformat(ip, dip);
8333                 if (error)  {
8334  #ifdef DEBUG
8335 @@ -1028,6 +1053,7 @@ xfs_ialloc(
8336         ASSERT(ip->i_d.di_nlink == nlink);
8337         ip->i_d.di_uid = current_fsuid();
8338         ip->i_d.di_gid = current_fsgid();
8339 +       ip->i_d.di_tag = current_fstag(&ip->i_vnode);
8340         xfs_set_projid(ip, prid);
8341         memset(&(ip->i_d.di_pad[0]), 0, sizeof(ip->i_d.di_pad));
8342  
8343 @@ -1088,6 +1114,7 @@ xfs_ialloc(
8344         ip->i_d.di_dmevmask = 0;
8345         ip->i_d.di_dmstate = 0;
8346         ip->i_d.di_flags = 0;
8347 +       ip->i_d.di_vflags = 0;
8348         flags = XFS_ILOG_CORE;
8349         switch (mode & S_IFMT) {
8350         case S_IFIFO:
8351 @@ -2122,6 +2149,7 @@ xfs_ifree(
8352         }
8353         ip->i_d.di_mode = 0;            /* mark incore inode as free */
8354         ip->i_d.di_flags = 0;
8355 +       ip->i_d.di_vflags = 0;
8356         ip->i_d.di_dmevmask = 0;
8357         ip->i_d.di_forkoff = 0;         /* mark the attr fork not in use */
8358         ip->i_df.if_ext_max =
8359 @@ -3004,7 +3032,8 @@ xfs_iflush_int(
8360          * because if the inode is dirty at all the core must
8361          * be.
8362          */
8363 -       xfs_dinode_to_disk(dip, &ip->i_d);
8364 +       xfs_dinode_to_disk(dip, &ip->i_d,
8365 +               mp->m_flags & XFS_MOUNT_TAGGED);
8366  
8367         /* Wrap, we never let the log put out DI_MAX_FLUSH */
8368         if (ip->i_d.di_flushiter == DI_MAX_FLUSH)
8369 diff -NurpP --minimal linux-2.6.38.1/fs/xfs/xfs_inode.h linux-2.6.38.1-vs2.3.0.37-rc9/fs/xfs/xfs_inode.h
8370 --- linux-2.6.38.1/fs/xfs/xfs_inode.h   2011-03-15 18:07:34.000000000 +0100
8371 +++ linux-2.6.38.1-vs2.3.0.37-rc9/fs/xfs/xfs_inode.h    2011-01-29 02:01:07.000000000 +0100
8372 @@ -136,7 +136,9 @@ typedef struct xfs_icdinode {
8373         __uint32_t      di_nlink;       /* number of links to file */
8374         __uint16_t      di_projid_lo;   /* lower part of owner's project id */
8375         __uint16_t      di_projid_hi;   /* higher part of owner's project id */
8376 -       __uint8_t       di_pad[6];      /* unused, zeroed space */
8377 +       __uint8_t       di_pad[2];      /* unused, zeroed space */
8378 +       __uint16_t      di_tag;         /* context tagging */
8379 +       __uint16_t      di_vflags;      /* vserver specific flags */
8380         __uint16_t      di_flushiter;   /* incremented on flush */
8381         xfs_ictimestamp_t di_atime;     /* time last accessed */
8382         xfs_ictimestamp_t di_mtime;     /* time last modified */
8383 @@ -530,7 +532,7 @@ int         xfs_itobp(struct xfs_mount *, struc
8384  int            xfs_iread(struct xfs_mount *, struct xfs_trans *,
8385                           struct xfs_inode *, uint);
8386  void           xfs_dinode_to_disk(struct xfs_dinode *,
8387 -                                  struct xfs_icdinode *);
8388 +                                  struct xfs_icdinode *, int);
8389  void           xfs_idestroy_fork(struct xfs_inode *, int);
8390  void           xfs_idata_realloc(struct xfs_inode *, int, int);
8391  void           xfs_iroot_realloc(struct xfs_inode *, int, int);
8392 diff -NurpP --minimal linux-2.6.38.1/fs/xfs/xfs_itable.c linux-2.6.38.1-vs2.3.0.37-rc9/fs/xfs/xfs_itable.c
8393 --- linux-2.6.38.1/fs/xfs/xfs_itable.c  2011-01-05 21:50:28.000000000 +0100
8394 +++ linux-2.6.38.1-vs2.3.0.37-rc9/fs/xfs/xfs_itable.c   2011-01-29 02:01:07.000000000 +0100
8395 @@ -98,6 +98,7 @@ xfs_bulkstat_one_int(
8396         buf->bs_mode = dic->di_mode;
8397         buf->bs_uid = dic->di_uid;
8398         buf->bs_gid = dic->di_gid;
8399 +       buf->bs_tag = dic->di_tag;
8400         buf->bs_size = dic->di_size;
8401  
8402         /*
8403 diff -NurpP --minimal linux-2.6.38.1/fs/xfs/xfs_log_recover.c linux-2.6.38.1-vs2.3.0.37-rc9/fs/xfs/xfs_log_recover.c
8404 --- linux-2.6.38.1/fs/xfs/xfs_log_recover.c     2011-03-15 18:07:34.000000000 +0100
8405 +++ linux-2.6.38.1-vs2.3.0.37-rc9/fs/xfs/xfs_log_recover.c      2011-01-29 02:01:07.000000000 +0100
8406 @@ -2317,7 +2317,8 @@ xlog_recover_inode_pass2(
8407         }
8408  
8409         /* The core is in in-core format */
8410 -       xfs_dinode_to_disk(dip, item->ri_buf[1].i_addr);
8411 +       xfs_dinode_to_disk(dip, item->ri_buf[1].i_addr,
8412 +               mp->m_flags & XFS_MOUNT_TAGGED);
8413  
8414         /* the rest is in on-disk format */
8415         if (item->ri_buf[1].i_len > sizeof(struct xfs_icdinode)) {
8416 diff -NurpP --minimal linux-2.6.38.1/fs/xfs/xfs_mount.h linux-2.6.38.1-vs2.3.0.37-rc9/fs/xfs/xfs_mount.h
8417 --- linux-2.6.38.1/fs/xfs/xfs_mount.h   2011-03-15 18:07:34.000000000 +0100
8418 +++ linux-2.6.38.1-vs2.3.0.37-rc9/fs/xfs/xfs_mount.h    2011-01-29 02:01:07.000000000 +0100
8419 @@ -251,6 +251,7 @@ typedef struct xfs_mount {
8420                                                    allocator */
8421  #define XFS_MOUNT_NOATTR2      (1ULL << 25)    /* disable use of attr2 format */
8422  
8423 +#define XFS_MOUNT_TAGGED       (1ULL << 31)    /* context tagging */
8424  
8425  /*
8426   * Default minimum read and write sizes.
8427 diff -NurpP --minimal linux-2.6.38.1/fs/xfs/xfs_vnodeops.c linux-2.6.38.1-vs2.3.0.37-rc9/fs/xfs/xfs_vnodeops.c
8428 --- linux-2.6.38.1/fs/xfs/xfs_vnodeops.c        2011-03-15 18:07:34.000000000 +0100
8429 +++ linux-2.6.38.1-vs2.3.0.37-rc9/fs/xfs/xfs_vnodeops.c 2011-01-29 02:01:07.000000000 +0100
8430 @@ -50,6 +50,78 @@
8431  #include "xfs_vnodeops.h"
8432  #include "xfs_trace.h"
8433  
8434 +
8435 +STATIC void
8436 +xfs_get_inode_flags(
8437 +       xfs_inode_t     *ip)
8438 +{
8439 +       struct inode    *inode = VFS_I(ip);
8440 +       unsigned int    flags = inode->i_flags;
8441 +       unsigned int    vflags = inode->i_vflags;
8442 +
8443 +       if (flags & S_IMMUTABLE)
8444 +               ip->i_d.di_flags |= XFS_DIFLAG_IMMUTABLE;
8445 +       else
8446 +               ip->i_d.di_flags &= ~XFS_DIFLAG_IMMUTABLE;
8447 +       if (flags & S_IXUNLINK)
8448 +               ip->i_d.di_flags |= XFS_DIFLAG_IXUNLINK;
8449 +       else
8450 +               ip->i_d.di_flags &= ~XFS_DIFLAG_IXUNLINK;
8451 +
8452 +       if (vflags & V_BARRIER)
8453 +               ip->i_d.di_vflags |= XFS_DIVFLAG_BARRIER;
8454 +       else
8455 +               ip->i_d.di_vflags &= ~XFS_DIVFLAG_BARRIER;
8456 +       if (vflags & V_COW)
8457 +               ip->i_d.di_vflags |= XFS_DIVFLAG_COW;
8458 +       else
8459 +               ip->i_d.di_vflags &= ~XFS_DIVFLAG_COW;
8460 +}
8461 +
8462 +int
8463 +xfs_sync_flags(
8464 +       struct inode            *inode,
8465 +       int                     flags,
8466 +       int                     vflags)
8467 +{
8468 +       struct xfs_inode        *ip = XFS_I(inode);
8469 +       struct xfs_mount        *mp = ip->i_mount;
8470 +       struct xfs_trans        *tp;
8471 +       unsigned int            lock_flags = 0;
8472 +       int                     code;
8473 +
8474 +       tp = xfs_trans_alloc(mp, XFS_TRANS_SETATTR_NOT_SIZE);
8475 +       code = xfs_trans_reserve(tp, 0, XFS_ICHANGE_LOG_RES(mp), 0, 0, 0);
8476 +       if (code)
8477 +               goto error_out;
8478 +
8479 +       xfs_ilock(ip, XFS_ILOCK_EXCL);
8480 +
8481 +       xfs_trans_ijoin(tp, ip);
8482 +
8483 +       inode->i_flags = flags;
8484 +       inode->i_vflags = vflags;
8485 +       xfs_get_inode_flags(ip);
8486 +
8487 +       xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE);
8488 +       xfs_trans_ichgtime(tp, ip, XFS_ICHGTIME_CHG);
8489 +
8490 +       XFS_STATS_INC(xs_ig_attrchg);
8491 +
8492 +       if (mp->m_flags & XFS_MOUNT_WSYNC)
8493 +               xfs_trans_set_sync(tp);
8494 +       code = xfs_trans_commit(tp, 0);
8495 +       xfs_iunlock(ip, XFS_ILOCK_EXCL);
8496 +       return code;
8497 +
8498 +error_out:
8499 +       xfs_trans_cancel(tp, 0);
8500 +       if (lock_flags)
8501 +               xfs_iunlock(ip, XFS_ILOCK_EXCL);
8502 +       return code;
8503 +}
8504 +
8505 +
8506  int
8507  xfs_setattr(
8508         struct xfs_inode        *ip,
8509 @@ -65,6 +137,7 @@ xfs_setattr(
8510         uint                    commit_flags=0;
8511         uid_t                   uid=0, iuid=0;
8512         gid_t                   gid=0, igid=0;
8513 +       tag_t                   tag=0, itag=0;
8514         struct xfs_dquot        *udqp, *gdqp, *olddquot1, *olddquot2;
8515         int                     need_iolock = 1;
8516  
8517 @@ -147,7 +220,7 @@ xfs_setattr(
8518         /*
8519          * Change file ownership.  Must be the owner or privileged.
8520          */
8521 -       if (mask & (ATTR_UID|ATTR_GID)) {
8522 +       if (mask & (ATTR_UID|ATTR_GID|ATTR_TAG)) {
8523                 /*
8524                  * These IDs could have changed since we last looked at them.
8525                  * But, we're assured that if the ownership did change
8526 @@ -156,8 +229,10 @@ xfs_setattr(
8527                  */
8528                 iuid = ip->i_d.di_uid;
8529                 igid = ip->i_d.di_gid;
8530 +               itag = ip->i_d.di_tag;
8531                 gid = (mask & ATTR_GID) ? iattr->ia_gid : igid;
8532                 uid = (mask & ATTR_UID) ? iattr->ia_uid : iuid;
8533 +               tag = (mask & ATTR_TAG) ? iattr->ia_tag : itag;
8534  
8535                 /*
8536                  * Do a quota reservation only if uid/gid is actually
8537 @@ -165,7 +240,8 @@ xfs_setattr(
8538                  */
8539                 if (XFS_IS_QUOTA_RUNNING(mp) &&
8540                     ((XFS_IS_UQUOTA_ON(mp) && iuid != uid) ||
8541 -                    (XFS_IS_GQUOTA_ON(mp) && igid != gid))) {
8542 +                    (XFS_IS_GQUOTA_ON(mp) && igid != gid) ||
8543 +                    (XFS_IS_GQUOTA_ON(mp) && itag != tag))) {
8544                         ASSERT(tp);
8545                         code = xfs_qm_vop_chown_reserve(tp, ip, udqp, gdqp,
8546                                                 capable(CAP_FOWNER) ?
8547 @@ -329,7 +405,7 @@ xfs_setattr(
8548         /*
8549          * Change file ownership.  Must be the owner or privileged.
8550          */
8551 -       if (mask & (ATTR_UID|ATTR_GID)) {
8552 +       if (mask & (ATTR_UID|ATTR_GID|ATTR_TAG)) {
8553                 /*
8554                  * CAP_FSETID overrides the following restrictions:
8555                  *
8556 @@ -345,6 +421,10 @@ xfs_setattr(
8557                  * Change the ownerships and register quota modifications
8558                  * in the transaction.
8559                  */
8560 +               if (itag != tag) {
8561 +                       ip->i_d.di_tag = tag;
8562 +                       inode->i_tag = tag;
8563 +               }
8564                 if (iuid != uid) {
8565                         if (XFS_IS_QUOTA_RUNNING(mp) && XFS_IS_UQUOTA_ON(mp)) {
8566                                 ASSERT(mask & ATTR_UID);
8567 diff -NurpP --minimal linux-2.6.38.1/fs/xfs/xfs_vnodeops.h linux-2.6.38.1-vs2.3.0.37-rc9/fs/xfs/xfs_vnodeops.h
8568 --- linux-2.6.38.1/fs/xfs/xfs_vnodeops.h        2011-01-05 21:50:28.000000000 +0100
8569 +++ linux-2.6.38.1-vs2.3.0.37-rc9/fs/xfs/xfs_vnodeops.h 2011-01-29 02:01:07.000000000 +0100
8570 @@ -13,6 +13,7 @@ struct xfs_inode;
8571  struct xfs_iomap;
8572  
8573  
8574 +int xfs_sync_xflags(struct xfs_inode *ip);
8575  int xfs_setattr(struct xfs_inode *ip, struct iattr *vap, int flags);
8576  #define        XFS_ATTR_DMI            0x01    /* invocation from a DMI function */
8577  #define        XFS_ATTR_NONBLOCK       0x02    /* return EAGAIN if operation would block */
8578 diff -NurpP --minimal linux-2.6.38.1/include/asm-generic/tlb.h linux-2.6.38.1-vs2.3.0.37-rc9/include/asm-generic/tlb.h
8579 --- linux-2.6.38.1/include/asm-generic/tlb.h    2009-09-10 15:26:24.000000000 +0200
8580 +++ linux-2.6.38.1-vs2.3.0.37-rc9/include/asm-generic/tlb.h     2011-01-29 02:01:07.000000000 +0100
8581 @@ -14,6 +14,7 @@
8582  #define _ASM_GENERIC__TLB_H
8583  
8584  #include <linux/swap.h>
8585 +#include <linux/vs_memory.h>
8586  #include <asm/pgalloc.h>
8587  #include <asm/tlbflush.h>
8588  
8589 diff -NurpP --minimal linux-2.6.38.1/include/linux/Kbuild linux-2.6.38.1-vs2.3.0.37-rc9/include/linux/Kbuild
8590 --- linux-2.6.38.1/include/linux/Kbuild 2011-03-15 18:07:37.000000000 +0100
8591 +++ linux-2.6.38.1-vs2.3.0.37-rc9/include/linux/Kbuild  2011-02-17 02:17:51.000000000 +0100
8592 @@ -16,6 +16,7 @@ header-y += netfilter_bridge/
8593  header-y += netfilter_ipv4/
8594  header-y += netfilter_ipv6/
8595  header-y += usb/
8596 +header-y += vserver/
8597  header-y += wimax/
8598  
8599  objhdr-y += version.h
8600 diff -NurpP --minimal linux-2.6.38.1/include/linux/capability.h linux-2.6.38.1-vs2.3.0.37-rc9/include/linux/capability.h
8601 --- linux-2.6.38.1/include/linux/capability.h   2011-03-15 18:07:37.000000000 +0100
8602 +++ linux-2.6.38.1-vs2.3.0.37-rc9/include/linux/capability.h    2011-01-29 02:01:07.000000000 +0100
8603 @@ -279,6 +279,7 @@ struct cpu_vfs_cap_data {
8604     arbitrary SCSI commands */
8605  /* Allow setting encryption key on loopback filesystem */
8606  /* Allow setting zone reclaim policy */
8607 +/* Allow the selection of a security context */
8608  
8609  #define CAP_SYS_ADMIN        21
8610  
8611 @@ -357,7 +358,12 @@ struct cpu_vfs_cap_data {
8612  
8613  #define CAP_LAST_CAP         CAP_SYSLOG
8614  
8615 -#define cap_valid(x) ((x) >= 0 && (x) <= CAP_LAST_CAP)
8616 +/* Allow context manipulations */
8617 +/* Allow changing context info on files */
8618 +
8619 +#define CAP_CONTEXT         63
8620 +
8621 +#define cap_valid(x) ((x) >= 0 && ((x) <= CAP_LAST_CAP || (x) == CAP_CONTEXT))
8622  
8623  /*
8624   * Bit location of each capability (used by user-space library and kernel)
8625 diff -NurpP --minimal linux-2.6.38.1/include/linux/cred.h linux-2.6.38.1-vs2.3.0.37-rc9/include/linux/cred.h
8626 --- linux-2.6.38.1/include/linux/cred.h 2011-01-05 21:50:29.000000000 +0100
8627 +++ linux-2.6.38.1-vs2.3.0.37-rc9/include/linux/cred.h  2011-01-31 12:03:07.000000000 +0100
8628 @@ -155,6 +155,7 @@ extern void exit_creds(struct task_struc
8629  extern int copy_creds(struct task_struct *, unsigned long);
8630  extern const struct cred *get_task_cred(struct task_struct *);
8631  extern struct cred *cred_alloc_blank(void);
8632 +extern struct cred *__prepare_creds(const struct cred *);
8633  extern struct cred *prepare_creds(void);
8634  extern struct cred *prepare_exec_creds(void);
8635  extern int commit_creds(struct cred *);
8636 @@ -208,6 +209,31 @@ static inline void validate_process_cred
8637  }
8638  #endif
8639  
8640 +static inline void set_cred_subscribers(struct cred *cred, int n)
8641 +{
8642 +#ifdef CONFIG_DEBUG_CREDENTIALS
8643 +       atomic_set(&cred->subscribers, n);
8644 +#endif
8645 +}
8646 +
8647 +static inline int read_cred_subscribers(const struct cred *cred)
8648 +{
8649 +#ifdef CONFIG_DEBUG_CREDENTIALS
8650 +       return atomic_read(&cred->subscribers);
8651 +#else
8652 +       return 0;
8653 +#endif
8654 +}
8655 +
8656 +static inline void alter_cred_subscribers(const struct cred *_cred, int n)
8657 +{
8658 +#ifdef CONFIG_DEBUG_CREDENTIALS
8659 +       struct cred *cred = (struct cred *) _cred;
8660 +
8661 +       atomic_add(n, &cred->subscribers);
8662 +#endif
8663 +}
8664 +
8665  /**
8666   * get_new_cred - Get a reference on a new set of credentials
8667   * @cred: The new credentials to reference
8668 diff -NurpP --minimal linux-2.6.38.1/include/linux/devpts_fs.h linux-2.6.38.1-vs2.3.0.37-rc9/include/linux/devpts_fs.h
8669 --- linux-2.6.38.1/include/linux/devpts_fs.h    2008-12-25 00:26:37.000000000 +0100
8670 +++ linux-2.6.38.1-vs2.3.0.37-rc9/include/linux/devpts_fs.h     2011-01-29 02:01:07.000000000 +0100
8671 @@ -45,5 +45,4 @@ static inline void devpts_pty_kill(struc
8672  
8673  #endif
8674  
8675 -
8676  #endif /* _LINUX_DEVPTS_FS_H */
8677 diff -NurpP --minimal linux-2.6.38.1/include/linux/ext2_fs.h linux-2.6.38.1-vs2.3.0.37-rc9/include/linux/ext2_fs.h
8678 --- linux-2.6.38.1/include/linux/ext2_fs.h      2010-02-25 11:52:07.000000000 +0100
8679 +++ linux-2.6.38.1-vs2.3.0.37-rc9/include/linux/ext2_fs.h       2011-01-29 02:01:07.000000000 +0100
8680 @@ -189,8 +189,12 @@ struct ext2_group_desc
8681  #define EXT2_NOTAIL_FL                 FS_NOTAIL_FL    /* file tail should not be merged */
8682  #define EXT2_DIRSYNC_FL                        FS_DIRSYNC_FL   /* dirsync behaviour (directories only) */
8683  #define EXT2_TOPDIR_FL                 FS_TOPDIR_FL    /* Top of directory hierarchies*/
8684 +#define EXT2_IXUNLINK_FL               FS_IXUNLINK_FL  /* Immutable invert on unlink */
8685  #define EXT2_RESERVED_FL               FS_RESERVED_FL  /* reserved for ext2 lib */
8686  
8687 +#define EXT2_BARRIER_FL                        FS_BARRIER_FL   /* Barrier for chroot() */
8688 +#define EXT2_COW_FL                    FS_COW_FL       /* Copy on Write marker */
8689 +
8690  #define EXT2_FL_USER_VISIBLE           FS_FL_USER_VISIBLE      /* User visible flags */
8691  #define EXT2_FL_USER_MODIFIABLE                FS_FL_USER_MODIFIABLE   /* User modifiable flags */
8692  
8693 @@ -274,7 +278,8 @@ struct ext2_inode {
8694                         __u16   i_pad1;
8695                         __le16  l_i_uid_high;   /* these 2 fields    */
8696                         __le16  l_i_gid_high;   /* were reserved2[0] */
8697 -                       __u32   l_i_reserved2;
8698 +                       __le16  l_i_tag;        /* Context Tag */
8699 +                       __u16   l_i_reserved2;
8700                 } linux2;
8701                 struct {
8702                         __u8    h_i_frag;       /* Fragment number */
8703 @@ -303,6 +308,7 @@ struct ext2_inode {
8704  #define i_gid_low      i_gid
8705  #define i_uid_high     osd2.linux2.l_i_uid_high
8706  #define i_gid_high     osd2.linux2.l_i_gid_high
8707 +#define i_raw_tag      osd2.linux2.l_i_tag
8708  #define i_reserved2    osd2.linux2.l_i_reserved2
8709  #endif
8710  
8711 @@ -347,6 +353,7 @@ struct ext2_inode {
8712  #define EXT2_MOUNT_USRQUOTA            0x020000  /* user quota */
8713  #define EXT2_MOUNT_GRPQUOTA            0x040000  /* group quota */
8714  #define EXT2_MOUNT_RESERVATION         0x080000  /* Preallocation */
8715 +#define EXT2_MOUNT_TAGGED              (1<<24)   /* Enable Context Tags */
8716  
8717  
8718  #define clear_opt(o, opt)              o &= ~EXT2_MOUNT_##opt
8719 diff -NurpP --minimal linux-2.6.38.1/include/linux/ext3_fs.h linux-2.6.38.1-vs2.3.0.37-rc9/include/linux/ext3_fs.h
8720 --- linux-2.6.38.1/include/linux/ext3_fs.h      2011-03-15 18:07:38.000000000 +0100
8721 +++ linux-2.6.38.1-vs2.3.0.37-rc9/include/linux/ext3_fs.h       2011-01-29 02:01:07.000000000 +0100
8722 @@ -173,10 +173,14 @@ struct ext3_group_desc
8723  #define EXT3_NOTAIL_FL                 0x00008000 /* file tail should not be merged */
8724  #define EXT3_DIRSYNC_FL                        0x00010000 /* dirsync behaviour (directories only) */
8725  #define EXT3_TOPDIR_FL                 0x00020000 /* Top of directory hierarchies*/
8726 +#define EXT3_IXUNLINK_FL               0x08000000 /* Immutable invert on unlink */
8727  #define EXT3_RESERVED_FL               0x80000000 /* reserved for ext3 lib */
8728  
8729 -#define EXT3_FL_USER_VISIBLE           0x0003DFFF /* User visible flags */
8730 -#define EXT3_FL_USER_MODIFIABLE                0x000380FF /* User modifiable flags */
8731 +#define EXT3_BARRIER_FL                        0x04000000 /* Barrier for chroot() */
8732 +#define EXT3_COW_FL                    0x20000000 /* Copy on Write marker */
8733 +
8734 +#define EXT3_FL_USER_VISIBLE           0x0103DFFF /* User visible flags */
8735 +#define EXT3_FL_USER_MODIFIABLE                0x010380FF /* User modifiable flags */
8736  
8737  /* Flags that should be inherited by new inodes from their parent. */
8738  #define EXT3_FL_INHERITED (EXT3_SECRM_FL | EXT3_UNRM_FL | EXT3_COMPR_FL |\
8739 @@ -312,7 +316,8 @@ struct ext3_inode {
8740                         __u16   i_pad1;
8741                         __le16  l_i_uid_high;   /* these 2 fields    */
8742                         __le16  l_i_gid_high;   /* were reserved2[0] */
8743 -                       __u32   l_i_reserved2;
8744 +                       __le16  l_i_tag;        /* Context Tag */
8745 +                       __u16   l_i_reserved2;
8746                 } linux2;
8747                 struct {
8748                         __u8    h_i_frag;       /* Fragment number */
8749 @@ -343,6 +348,7 @@ struct ext3_inode {
8750  #define i_gid_low      i_gid
8751  #define i_uid_high     osd2.linux2.l_i_uid_high
8752  #define i_gid_high     osd2.linux2.l_i_gid_high
8753 +#define i_raw_tag      osd2.linux2.l_i_tag
8754  #define i_reserved2    osd2.linux2.l_i_reserved2
8755  
8756  #elif defined(__GNU__)
8757 @@ -405,6 +411,7 @@ struct ext3_inode {
8758  #define EXT3_MOUNT_GRPQUOTA            0x200000 /* "old" group quota */
8759  #define EXT3_MOUNT_DATA_ERR_ABORT      0x400000 /* Abort on file data write
8760                                                   * error in ordered mode */
8761 +#define EXT3_MOUNT_TAGGED              (1<<24) /* Enable Context Tags */
8762  
8763  /* Compatibility, for having both ext2_fs.h and ext3_fs.h included at once */
8764  #ifndef _LINUX_EXT2_FS_H
8765 @@ -918,6 +925,7 @@ extern void ext3_get_inode_flags(struct 
8766  extern void ext3_set_aops(struct inode *inode);
8767  extern int ext3_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
8768                        u64 start, u64 len);
8769 +extern int ext3_sync_flags(struct inode *, int, int);
8770  
8771  /* ioctl.c */
8772  extern long ext3_ioctl(struct file *, unsigned int, unsigned long);
8773 diff -NurpP --minimal linux-2.6.38.1/include/linux/fs.h linux-2.6.38.1-vs2.3.0.37-rc9/include/linux/fs.h
8774 --- linux-2.6.38.1/include/linux/fs.h   2011-03-15 18:07:38.000000000 +0100
8775 +++ linux-2.6.38.1-vs2.3.0.37-rc9/include/linux/fs.h    2011-03-07 16:53:28.000000000 +0100
8776 @@ -214,6 +214,9 @@ struct inodes_stat_t {
8777  #define MS_KERNMOUNT   (1<<22) /* this is a kern_mount call */
8778  #define MS_I_VERSION   (1<<23) /* Update inode I_version field */
8779  #define MS_STRICTATIME (1<<24) /* Always perform atime updates */
8780 +#define MS_TAGGED      (1<<25) /* use generic inode tagging */
8781 +#define MS_TAGID       (1<<26) /* use specific tag for this mount */
8782 +#define MS_NOTAGCHECK  (1<<27) /* don't check tags */
8783  #define MS_BORN                (1<<29)
8784  #define MS_ACTIVE      (1<<30)
8785  #define MS_NOUSER      (1<<31)
8786 @@ -243,6 +246,14 @@ struct inodes_stat_t {
8787  #define S_PRIVATE      512     /* Inode is fs-internal */
8788  #define S_IMA          1024    /* Inode has an associated IMA struct */
8789  #define S_AUTOMOUNT    2048    /* Automount/referral quasi-directory */
8790 +#define S_IXUNLINK     4096    /* Immutable Invert on unlink */
8791 +
8792 +/* Linux-VServer related Inode flags */
8793 +
8794 +#define V_VALID                1
8795 +#define V_XATTR                2
8796 +#define V_BARRIER      4       /* Barrier for chroot() */
8797 +#define V_COW          8       /* Copy on Write */
8798  
8799  /*
8800   * Note that nosuid etc flags are inode-specific: setting some file-system
8801 @@ -265,12 +276,15 @@ struct inodes_stat_t {
8802  #define IS_DIRSYNC(inode)      (__IS_FLG(inode, MS_SYNCHRONOUS|MS_DIRSYNC) || \
8803                                         ((inode)->i_flags & (S_SYNC|S_DIRSYNC)))
8804  #define IS_MANDLOCK(inode)     __IS_FLG(inode, MS_MANDLOCK)
8805 -#define IS_NOATIME(inode)   __IS_FLG(inode, MS_RDONLY|MS_NOATIME)
8806 -#define IS_I_VERSION(inode)   __IS_FLG(inode, MS_I_VERSION)
8807 +#define IS_NOATIME(inode)      __IS_FLG(inode, MS_RDONLY|MS_NOATIME)
8808 +#define IS_I_VERSION(inode)    __IS_FLG(inode, MS_I_VERSION)
8809 +#define IS_TAGGED(inode)       __IS_FLG(inode, MS_TAGGED)
8810  
8811  #define IS_NOQUOTA(inode)      ((inode)->i_flags & S_NOQUOTA)
8812  #define IS_APPEND(inode)       ((inode)->i_flags & S_APPEND)
8813  #define IS_IMMUTABLE(inode)    ((inode)->i_flags & S_IMMUTABLE)
8814 +#define IS_IXUNLINK(inode)     ((inode)->i_flags & S_IXUNLINK)
8815 +#define IS_IXORUNLINK(inode)   ((IS_IXUNLINK(inode) ? S_IMMUTABLE : 0) ^ IS_IMMUTABLE(inode))
8816  #define IS_POSIXACL(inode)     __IS_FLG(inode, MS_POSIXACL)
8817  
8818  #define IS_DEADDIR(inode)      ((inode)->i_flags & S_DEAD)
8819 @@ -280,6 +294,16 @@ struct inodes_stat_t {
8820  #define IS_IMA(inode)          ((inode)->i_flags & S_IMA)
8821  #define IS_AUTOMOUNT(inode)    ((inode)->i_flags & S_AUTOMOUNT)
8822  
8823 +#define IS_BARRIER(inode)      (S_ISDIR((inode)->i_mode) && ((inode)->i_vflags & V_BARRIER))
8824 +
8825 +#ifdef CONFIG_VSERVER_COWBL
8826 +#  define IS_COW(inode)                (IS_IXUNLINK(inode) && IS_IMMUTABLE(inode))
8827 +#  define IS_COW_LINK(inode)   (S_ISREG((inode)->i_mode) && ((inode)->i_nlink > 1))
8828 +#else
8829 +#  define IS_COW(inode)                (0)
8830 +#  define IS_COW_LINK(inode)   (0)
8831 +#endif
8832 +
8833  /* the read-only stuff doesn't really belong here, but any other place is
8834     probably as bad and I don't want to create yet another include file. */
8835  
8836 @@ -364,11 +388,14 @@ struct inodes_stat_t {
8837  #define FS_TOPDIR_FL                   0x00020000 /* Top of directory hierarchies*/
8838  #define FS_EXTENT_FL                   0x00080000 /* Extents */
8839  #define FS_DIRECTIO_FL                 0x00100000 /* Use direct i/o */
8840 +#define FS_IXUNLINK_FL                 0x08000000 /* Immutable invert on unlink */
8841  #define FS_RESERVED_FL                 0x80000000 /* reserved for ext2 lib */
8842  
8843 -#define FS_FL_USER_VISIBLE             0x0003DFFF /* User visible flags */
8844 -#define FS_FL_USER_MODIFIABLE          0x000380FF /* User modifiable flags */
8845 +#define FS_BARRIER_FL                  0x04000000 /* Barrier for chroot() */
8846 +#define FS_COW_FL                      0x20000000 /* Copy on Write marker */
8847  
8848 +#define FS_FL_USER_VISIBLE             0x0103DFFF /* User visible flags */
8849 +#define FS_FL_USER_MODIFIABLE          0x010380FF /* User modifiable flags */
8850  
8851  #define SYNC_FILE_RANGE_WAIT_BEFORE    1
8852  #define SYNC_FILE_RANGE_WRITE          2
8853 @@ -449,6 +476,7 @@ typedef void (dio_iodone_t)(struct kiocb
8854  #define ATTR_KILL_PRIV (1 << 14)
8855  #define ATTR_OPEN      (1 << 15) /* Truncating from open(O_TRUNC) */
8856  #define ATTR_TIMES_SET (1 << 16)
8857 +#define ATTR_TAG       (1 << 17)
8858  
8859  /*
8860   * This is the Inode Attributes structure, used for notify_change().  It
8861 @@ -464,6 +492,7 @@ struct iattr {
8862         umode_t         ia_mode;
8863         uid_t           ia_uid;
8864         gid_t           ia_gid;
8865 +       tag_t           ia_tag;
8866         loff_t          ia_size;
8867         struct timespec ia_atime;
8868         struct timespec ia_mtime;
8869 @@ -477,6 +506,9 @@ struct iattr {
8870         struct file     *ia_file;
8871  };
8872  
8873 +#define ATTR_FLAG_BARRIER      512     /* Barrier for chroot() */
8874 +#define ATTR_FLAG_IXUNLINK     1024    /* Immutable invert on unlink */
8875 +
8876  /*
8877   * Includes for diskquotas.
8878   */
8879 @@ -742,11 +774,13 @@ struct inode {
8880         umode_t                 i_mode;
8881         uid_t                   i_uid;
8882         gid_t                   i_gid;
8883 +       tag_t                   i_tag;
8884         const struct inode_operations   *i_op;
8885         struct super_block      *i_sb;
8886  
8887         spinlock_t              i_lock; /* i_blocks, i_bytes, maybe i_size */
8888 -       unsigned int            i_flags;
8889 +       unsigned short          i_flags;
8890 +       unsigned short          i_vflags;
8891         struct mutex            i_mutex;
8892  
8893         unsigned long           i_state;
8894 @@ -764,6 +798,7 @@ struct inode {
8895         atomic_t                i_count;
8896         unsigned int            i_nlink;
8897         dev_t                   i_rdev;
8898 +       dev_t                   i_mdev;
8899         unsigned int            i_blkbits;
8900         u64                     i_version;
8901         loff_t                  i_size;
8902 @@ -892,12 +927,12 @@ static inline void i_size_write(struct i
8903  
8904  static inline unsigned iminor(const struct inode *inode)
8905  {
8906 -       return MINOR(inode->i_rdev);
8907 +       return MINOR(inode->i_mdev);
8908  }
8909  
8910  static inline unsigned imajor(const struct inode *inode)
8911  {
8912 -       return MAJOR(inode->i_rdev);
8913 +       return MAJOR(inode->i_mdev);
8914  }
8915  
8916  extern struct block_device *I_BDEV(struct inode *inode);
8917 @@ -959,6 +994,7 @@ struct file {
8918         loff_t                  f_pos;
8919         struct fown_struct      f_owner;
8920         const struct cred       *f_cred;
8921 +       xid_t                   f_xid;
8922         struct file_ra_state    f_ra;
8923  
8924         u64                     f_version;
8925 @@ -1096,6 +1132,7 @@ struct file_lock {
8926         struct file *fl_file;
8927         loff_t fl_start;
8928         loff_t fl_end;
8929 +       xid_t fl_xid;
8930  
8931         struct fasync_struct *  fl_fasync; /* for lease break notifications */
8932         unsigned long fl_break_time;    /* for nonblocking lease breaks */
8933 @@ -1584,6 +1621,7 @@ struct inode_operations {
8934         ssize_t (*getxattr) (struct dentry *, const char *, void *, size_t);
8935         ssize_t (*listxattr) (struct dentry *, char *, size_t);
8936         int (*removexattr) (struct dentry *, const char *);
8937 +       int (*sync_flags) (struct inode *, int, int);
8938         void (*truncate_range)(struct inode *, loff_t, loff_t);
8939         int (*fiemap)(struct inode *, struct fiemap_extent_info *, u64 start,
8940                       u64 len);
8941 @@ -1602,6 +1640,7 @@ extern ssize_t vfs_readv(struct file *, 
8942                 unsigned long, loff_t *);
8943  extern ssize_t vfs_writev(struct file *, const struct iovec __user *,
8944                 unsigned long, loff_t *);
8945 +ssize_t vfs_sendfile(struct file *, struct file *, loff_t *, size_t, loff_t);
8946  
8947  struct super_operations {
8948         struct inode *(*alloc_inode)(struct super_block *sb);
8949 @@ -2414,6 +2453,7 @@ extern int dcache_dir_open(struct inode 
8950  extern int dcache_dir_close(struct inode *, struct file *);
8951  extern loff_t dcache_dir_lseek(struct file *, loff_t, int);
8952  extern int dcache_readdir(struct file *, void *, filldir_t);
8953 +extern int dcache_readdir_filter(struct file *, void *, filldir_t, int (*)(struct dentry *));
8954  extern int simple_setattr(struct dentry *, struct iattr *);
8955  extern int simple_getattr(struct vfsmount *, struct dentry *, struct kstat *);
8956  extern int simple_statfs(struct dentry *, struct kstatfs *);
8957 diff -NurpP --minimal linux-2.6.38.1/include/linux/gfs2_ondisk.h linux-2.6.38.1-vs2.3.0.37-rc9/include/linux/gfs2_ondisk.h
8958 --- linux-2.6.38.1/include/linux/gfs2_ondisk.h  2010-07-07 18:31:55.000000000 +0200
8959 +++ linux-2.6.38.1-vs2.3.0.37-rc9/include/linux/gfs2_ondisk.h   2011-01-29 02:01:07.000000000 +0100
8960 @@ -211,6 +211,9 @@ enum {
8961         gfs2fl_NoAtime          = 7,
8962         gfs2fl_Sync             = 8,
8963         gfs2fl_System           = 9,
8964 +       gfs2fl_IXUnlink         = 16,
8965 +       gfs2fl_Barrier          = 17,
8966 +       gfs2fl_Cow              = 18,
8967         gfs2fl_TruncInProg      = 29,
8968         gfs2fl_InheritDirectio  = 30,
8969         gfs2fl_InheritJdata     = 31,
8970 @@ -227,6 +230,9 @@ enum {
8971  #define GFS2_DIF_NOATIME               0x00000080
8972  #define GFS2_DIF_SYNC                  0x00000100
8973  #define GFS2_DIF_SYSTEM                        0x00000200 /* New in gfs2 */
8974 +#define GFS2_DIF_IXUNLINK              0x00010000
8975 +#define GFS2_DIF_BARRIER               0x00020000
8976 +#define GFS2_DIF_COW                   0x00040000
8977  #define GFS2_DIF_TRUNC_IN_PROG         0x20000000 /* New in gfs2 */
8978  #define GFS2_DIF_INHERIT_DIRECTIO      0x40000000
8979  #define GFS2_DIF_INHERIT_JDATA         0x80000000
8980 diff -NurpP --minimal linux-2.6.38.1/include/linux/if_tun.h linux-2.6.38.1-vs2.3.0.37-rc9/include/linux/if_tun.h
8981 --- linux-2.6.38.1/include/linux/if_tun.h       2010-08-02 16:52:54.000000000 +0200
8982 +++ linux-2.6.38.1-vs2.3.0.37-rc9/include/linux/if_tun.h        2011-01-29 02:01:07.000000000 +0100
8983 @@ -53,6 +53,7 @@
8984  #define TUNDETACHFILTER _IOW('T', 214, struct sock_fprog)
8985  #define TUNGETVNETHDRSZ _IOR('T', 215, int)
8986  #define TUNSETVNETHDRSZ _IOW('T', 216, int)
8987 +#define TUNSETNID     _IOW('T', 217, int)
8988  
8989  /* TUNSETIFF ifr flags */
8990  #define IFF_TUN                0x0001
8991 diff -NurpP --minimal linux-2.6.38.1/include/linux/init_task.h linux-2.6.38.1-vs2.3.0.37-rc9/include/linux/init_task.h
8992 --- linux-2.6.38.1/include/linux/init_task.h    2011-03-15 18:07:38.000000000 +0100
8993 +++ linux-2.6.38.1-vs2.3.0.37-rc9/include/linux/init_task.h     2011-01-29 02:01:07.000000000 +0100
8994 @@ -192,6 +192,10 @@ extern struct cred init_cred;
8995         INIT_FTRACE_GRAPH                                               \
8996         INIT_TRACE_RECURSION                                            \
8997         INIT_TASK_RCU_PREEMPT(tsk)                                      \
8998 +       .xid            = 0,                                            \
8999 +       .vx_info        = NULL,                                         \
9000 +       .nid            = 0,                                            \
9001 +       .nx_info        = NULL,                                         \
9002  }
9003  
9004  
9005 diff -NurpP --minimal linux-2.6.38.1/include/linux/ipc.h linux-2.6.38.1-vs2.3.0.37-rc9/include/linux/ipc.h
9006 --- linux-2.6.38.1/include/linux/ipc.h  2009-12-03 20:02:55.000000000 +0100
9007 +++ linux-2.6.38.1-vs2.3.0.37-rc9/include/linux/ipc.h   2011-01-29 02:01:07.000000000 +0100
9008 @@ -91,6 +91,7 @@ struct kern_ipc_perm
9009         key_t           key;
9010         uid_t           uid;
9011         gid_t           gid;
9012 +       xid_t           xid;
9013         uid_t           cuid;
9014         gid_t           cgid;
9015         mode_t          mode; 
9016 diff -NurpP --minimal linux-2.6.38.1/include/linux/loop.h linux-2.6.38.1-vs2.3.0.37-rc9/include/linux/loop.h
9017 --- linux-2.6.38.1/include/linux/loop.h 2009-09-10 15:26:25.000000000 +0200
9018 +++ linux-2.6.38.1-vs2.3.0.37-rc9/include/linux/loop.h  2011-01-29 02:01:07.000000000 +0100
9019 @@ -45,6 +45,7 @@ struct loop_device {
9020         struct loop_func_table *lo_encryption;
9021         __u32           lo_init[2];
9022         uid_t           lo_key_owner;   /* Who set the key */
9023 +       xid_t           lo_xid;
9024         int             (*ioctl)(struct loop_device *, int cmd, 
9025                                  unsigned long arg); 
9026  
9027 diff -NurpP --minimal linux-2.6.38.1/include/linux/magic.h linux-2.6.38.1-vs2.3.0.37-rc9/include/linux/magic.h
9028 --- linux-2.6.38.1/include/linux/magic.h        2011-03-15 18:07:39.000000000 +0100
9029 +++ linux-2.6.38.1-vs2.3.0.37-rc9/include/linux/magic.h 2011-01-29 02:01:07.000000000 +0100
9030 @@ -3,7 +3,7 @@
9031  
9032  #define ADFS_SUPER_MAGIC       0xadf5
9033  #define AFFS_SUPER_MAGIC       0xadff
9034 -#define AFS_SUPER_MAGIC                0x5346414F
9035 +#define AFS_SUPER_MAGIC                0x5346414F
9036  #define AUTOFS_SUPER_MAGIC     0x0187
9037  #define CODA_SUPER_MAGIC       0x73757245
9038  #define CRAMFS_MAGIC           0x28cd3d45      /* some random number */
9039 @@ -39,6 +39,7 @@
9040  #define NFS_SUPER_MAGIC                0x6969
9041  #define OPENPROM_SUPER_MAGIC   0x9fa1
9042  #define PROC_SUPER_MAGIC       0x9fa0
9043 +#define DEVPTS_SUPER_MAGIC     0x1cd1
9044  #define QNX4_SUPER_MAGIC       0x002f          /* qnx4 fs detection */
9045  
9046  #define REISERFS_SUPER_MAGIC   0x52654973      /* used by gcc */
9047 diff -NurpP --minimal linux-2.6.38.1/include/linux/major.h linux-2.6.38.1-vs2.3.0.37-rc9/include/linux/major.h
9048 --- linux-2.6.38.1/include/linux/major.h        2009-09-10 15:26:25.000000000 +0200
9049 +++ linux-2.6.38.1-vs2.3.0.37-rc9/include/linux/major.h 2011-01-29 02:01:07.000000000 +0100
9050 @@ -15,6 +15,7 @@
9051  #define HD_MAJOR               IDE0_MAJOR
9052  #define PTY_SLAVE_MAJOR                3
9053  #define TTY_MAJOR              4
9054 +#define VROOT_MAJOR            4
9055  #define TTYAUX_MAJOR           5
9056  #define LP_MAJOR               6
9057  #define VCS_MAJOR              7
9058 diff -NurpP --minimal linux-2.6.38.1/include/linux/memcontrol.h linux-2.6.38.1-vs2.3.0.37-rc9/include/linux/memcontrol.h
9059 --- linux-2.6.38.1/include/linux/memcontrol.h   2011-03-15 18:07:39.000000000 +0100
9060 +++ linux-2.6.38.1-vs2.3.0.37-rc9/include/linux/memcontrol.h    2011-01-29 02:01:07.000000000 +0100
9061 @@ -82,6 +82,13 @@ int task_in_mem_cgroup(struct task_struc
9062  extern struct mem_cgroup *try_get_mem_cgroup_from_page(struct page *page);
9063  extern struct mem_cgroup *mem_cgroup_from_task(struct task_struct *p);
9064  
9065 +extern u64 mem_cgroup_res_read_u64(struct mem_cgroup *mem, int member);
9066 +extern u64 mem_cgroup_memsw_read_u64(struct mem_cgroup *mem, int member);
9067 +
9068 +extern s64 mem_cgroup_stat_read_cache(struct mem_cgroup *mem);
9069 +extern s64 mem_cgroup_stat_read_anon(struct mem_cgroup *mem);
9070 +extern s64 mem_cgroup_stat_read_mapped(struct mem_cgroup *mem);
9071 +
9072  static inline
9073  int mm_match_cgroup(const struct mm_struct *mm, const struct mem_cgroup *cgroup)
9074  {
9075 diff -NurpP --minimal linux-2.6.38.1/include/linux/mm_types.h linux-2.6.38.1-vs2.3.0.37-rc9/include/linux/mm_types.h
9076 --- linux-2.6.38.1/include/linux/mm_types.h     2011-03-15 18:07:39.000000000 +0100
9077 +++ linux-2.6.38.1-vs2.3.0.37-rc9/include/linux/mm_types.h      2011-01-29 02:01:07.000000000 +0100
9078 @@ -269,6 +269,7 @@ struct mm_struct {
9079  
9080         /* Architecture-specific MM context */
9081         mm_context_t context;
9082 +       struct vx_info *mm_vx_info;
9083  
9084         /* Swap token stuff */
9085         /*
9086 diff -NurpP --minimal linux-2.6.38.1/include/linux/mount.h linux-2.6.38.1-vs2.3.0.37-rc9/include/linux/mount.h
9087 --- linux-2.6.38.1/include/linux/mount.h        2011-03-15 18:07:39.000000000 +0100
9088 +++ linux-2.6.38.1-vs2.3.0.37-rc9/include/linux/mount.h 2011-01-29 03:11:27.000000000 +0100
9089 @@ -52,6 +52,9 @@ struct mnt_pcp {
9090         int mnt_writers;
9091  };
9092  
9093 +#define MNT_TAGID      0x10000
9094 +#define MNT_NOTAG      0x20000
9095 +
9096  struct vfsmount {
9097         struct list_head mnt_hash;
9098         struct vfsmount *mnt_parent;    /* fs we are mounted on */
9099 @@ -86,6 +89,7 @@ struct vfsmount {
9100         int mnt_expiry_mark;            /* true if marked for expiry */
9101         int mnt_pinned;
9102         int mnt_ghosts;
9103 +       tag_t mnt_tag;                  /* tagging used for vfsmount */
9104  };
9105  
9106  struct file; /* forward dec */
9107 diff -NurpP --minimal linux-2.6.38.1/include/linux/net.h linux-2.6.38.1-vs2.3.0.37-rc9/include/linux/net.h
9108 --- linux-2.6.38.1/include/linux/net.h  2011-01-05 21:50:31.000000000 +0100
9109 +++ linux-2.6.38.1-vs2.3.0.37-rc9/include/linux/net.h   2011-01-29 02:01:07.000000000 +0100
9110 @@ -71,6 +71,7 @@ struct net;
9111  #define SOCK_NOSPACE           2
9112  #define SOCK_PASSCRED          3
9113  #define SOCK_PASSSEC           4
9114 +#define SOCK_USER_SOCKET       5
9115  
9116  #ifndef ARCH_HAS_SOCKET_TYPES
9117  /**
9118 diff -NurpP --minimal linux-2.6.38.1/include/linux/nfs_mount.h linux-2.6.38.1-vs2.3.0.37-rc9/include/linux/nfs_mount.h
9119 --- linux-2.6.38.1/include/linux/nfs_mount.h    2011-01-05 21:50:31.000000000 +0100
9120 +++ linux-2.6.38.1-vs2.3.0.37-rc9/include/linux/nfs_mount.h     2011-01-29 02:01:07.000000000 +0100
9121 @@ -63,7 +63,8 @@ struct nfs_mount_data {
9122  #define NFS_MOUNT_SECFLAVOUR   0x2000  /* 5 */
9123  #define NFS_MOUNT_NORDIRPLUS   0x4000  /* 5 */
9124  #define NFS_MOUNT_UNSHARED     0x8000  /* 5 */
9125 -#define NFS_MOUNT_FLAGMASK     0xFFFF
9126 +#define NFS_MOUNT_TAGGED       0x10000 /* context tagging */
9127 +#define NFS_MOUNT_FLAGMASK     0x1FFFF
9128  
9129  /* The following are for internal use only */
9130  #define NFS_MOUNT_LOOKUP_CACHE_NONEG   0x10000
9131 diff -NurpP --minimal linux-2.6.38.1/include/linux/nsproxy.h linux-2.6.38.1-vs2.3.0.37-rc9/include/linux/nsproxy.h
9132 --- linux-2.6.38.1/include/linux/nsproxy.h      2009-06-11 17:13:17.000000000 +0200
9133 +++ linux-2.6.38.1-vs2.3.0.37-rc9/include/linux/nsproxy.h       2011-01-29 02:01:07.000000000 +0100
9134 @@ -3,6 +3,7 @@
9135  
9136  #include <linux/spinlock.h>
9137  #include <linux/sched.h>
9138 +#include <linux/vserver/debug.h>
9139  
9140  struct mnt_namespace;
9141  struct uts_namespace;
9142 @@ -63,22 +64,33 @@ static inline struct nsproxy *task_nspro
9143  }
9144  
9145  int copy_namespaces(unsigned long flags, struct task_struct *tsk);
9146 +struct nsproxy *copy_nsproxy(struct nsproxy *orig);
9147  void exit_task_namespaces(struct task_struct *tsk);
9148  void switch_task_namespaces(struct task_struct *tsk, struct nsproxy *new);
9149  void free_nsproxy(struct nsproxy *ns);
9150  int unshare_nsproxy_namespaces(unsigned long, struct nsproxy **,
9151         struct fs_struct *);
9152  
9153 -static inline void put_nsproxy(struct nsproxy *ns)
9154 +#define        get_nsproxy(n)  __get_nsproxy(n, __FILE__, __LINE__)
9155 +
9156 +static inline void __get_nsproxy(struct nsproxy *ns,
9157 +       const char *_file, int _line)
9158  {
9159 -       if (atomic_dec_and_test(&ns->count)) {
9160 -               free_nsproxy(ns);
9161 -       }
9162 +       vxlprintk(VXD_CBIT(space, 0), "get_nsproxy(%p[%u])",
9163 +               ns, atomic_read(&ns->count), _file, _line);
9164 +       atomic_inc(&ns->count);
9165  }
9166  
9167 -static inline void get_nsproxy(struct nsproxy *ns)
9168 +#define        put_nsproxy(n)  __put_nsproxy(n, __FILE__, __LINE__)
9169 +
9170 +static inline void __put_nsproxy(struct nsproxy *ns,
9171 +       const char *_file, int _line)
9172  {
9173 -       atomic_inc(&ns->count);
9174 +       vxlprintk(VXD_CBIT(space, 0), "put_nsproxy(%p[%u])",
9175 +               ns, atomic_read(&ns->count), _file, _line);
9176 +       if (atomic_dec_and_test(&ns->count)) {
9177 +               free_nsproxy(ns);
9178 +       }
9179  }
9180  
9181  #ifdef CONFIG_CGROUP_NS
9182 diff -NurpP --minimal linux-2.6.38.1/include/linux/pid.h linux-2.6.38.1-vs2.3.0.37-rc9/include/linux/pid.h
9183 --- linux-2.6.38.1/include/linux/pid.h  2009-03-24 14:22:43.000000000 +0100
9184 +++ linux-2.6.38.1-vs2.3.0.37-rc9/include/linux/pid.h   2011-01-29 02:01:07.000000000 +0100
9185 @@ -8,7 +8,8 @@ enum pid_type
9186         PIDTYPE_PID,
9187         PIDTYPE_PGID,
9188         PIDTYPE_SID,
9189 -       PIDTYPE_MAX
9190 +       PIDTYPE_MAX,
9191 +       PIDTYPE_REALPID
9192  };
9193  
9194  /*
9195 @@ -160,6 +161,7 @@ static inline pid_t pid_nr(struct pid *p
9196  }
9197  
9198  pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns);
9199 +pid_t pid_unmapped_nr_ns(struct pid *pid, struct pid_namespace *ns);
9200  pid_t pid_vnr(struct pid *pid);
9201  
9202  #define do_each_pid_task(pid, type, task)                              \
9203 diff -NurpP --minimal linux-2.6.38.1/include/linux/proc_fs.h linux-2.6.38.1-vs2.3.0.37-rc9/include/linux/proc_fs.h
9204 --- linux-2.6.38.1/include/linux/proc_fs.h      2009-12-03 20:02:56.000000000 +0100
9205 +++ linux-2.6.38.1-vs2.3.0.37-rc9/include/linux/proc_fs.h       2011-01-29 02:01:07.000000000 +0100
9206 @@ -56,6 +56,7 @@ struct proc_dir_entry {
9207         nlink_t nlink;
9208         uid_t uid;
9209         gid_t gid;
9210 +       int vx_flags;
9211         loff_t size;
9212         const struct inode_operations *proc_iops;
9213         /*
9214 @@ -250,12 +251,18 @@ kclist_add(struct kcore_list *new, void 
9215  extern void kclist_add(struct kcore_list *, void *, size_t, int type);
9216  #endif
9217  
9218 +struct vx_info;
9219 +struct nx_info;
9220 +
9221  union proc_op {
9222         int (*proc_get_link)(struct inode *, struct path *);
9223         int (*proc_read)(struct task_struct *task, char *page);
9224         int (*proc_show)(struct seq_file *m,
9225                 struct pid_namespace *ns, struct pid *pid,
9226                 struct task_struct *task);
9227 +       int (*proc_vs_read)(char *page);
9228 +       int (*proc_vxi_read)(struct vx_info *vxi, char *page);
9229 +       int (*proc_nxi_read)(struct nx_info *nxi, char *page);
9230  };
9231  
9232  struct ctl_table_header;
9233 @@ -263,6 +270,7 @@ struct ctl_table;
9234  
9235  struct proc_inode {
9236         struct pid *pid;
9237 +       int vx_flags;
9238         int fd;
9239         union proc_op op;
9240         struct proc_dir_entry *pde;
9241 diff -NurpP --minimal linux-2.6.38.1/include/linux/quotaops.h linux-2.6.38.1-vs2.3.0.37-rc9/include/linux/quotaops.h
9242 --- linux-2.6.38.1/include/linux/quotaops.h     2011-03-15 18:07:39.000000000 +0100
9243 +++ linux-2.6.38.1-vs2.3.0.37-rc9/include/linux/quotaops.h      2011-01-29 02:01:07.000000000 +0100
9244 @@ -8,6 +8,7 @@
9245  #define _LINUX_QUOTAOPS_
9246  
9247  #include <linux/fs.h>
9248 +#include <linux/vs_dlimit.h>
9249  
9250  #define DQUOT_SPACE_WARN       0x1
9251  #define DQUOT_SPACE_RESERVE    0x2
9252 @@ -204,11 +205,12 @@ static inline void dquot_drop(struct ino
9253  
9254  static inline int dquot_alloc_inode(const struct inode *inode)
9255  {
9256 -       return 0;
9257 +       return dl_alloc_inode(inode);
9258  }
9259  
9260  static inline void dquot_free_inode(const struct inode *inode)
9261  {
9262 +       dl_free_inode(inode);
9263  }
9264  
9265  static inline int dquot_transfer(struct inode *inode, struct iattr *iattr)
9266 @@ -219,6 +221,10 @@ static inline int dquot_transfer(struct 
9267  static inline int __dquot_alloc_space(struct inode *inode, qsize_t number,
9268                 int flags)
9269  {
9270 +       int ret = 0;
9271 +
9272 +       if ((ret = dl_alloc_space(inode, number)))
9273 +               return ret;
9274         if (!(flags & DQUOT_SPACE_RESERVE))
9275                 inode_add_bytes(inode, number);
9276         return 0;
9277 @@ -229,6 +235,7 @@ static inline void __dquot_free_space(st
9278  {
9279         if (!(flags & DQUOT_SPACE_RESERVE))
9280                 inode_sub_bytes(inode, number);
9281 +       dl_free_space(inode, number);
9282  }
9283  
9284  static inline int dquot_claim_space_nodirty(struct inode *inode, qsize_t number)
9285 diff -NurpP --minimal linux-2.6.38.1/include/linux/reboot.h linux-2.6.38.1-vs2.3.0.37-rc9/include/linux/reboot.h
9286 --- linux-2.6.38.1/include/linux/reboot.h       2010-07-07 18:31:56.000000000 +0200
9287 +++ linux-2.6.38.1-vs2.3.0.37-rc9/include/linux/reboot.h        2011-01-29 02:01:07.000000000 +0100
9288 @@ -33,6 +33,7 @@
9289  #define        LINUX_REBOOT_CMD_RESTART2       0xA1B2C3D4
9290  #define        LINUX_REBOOT_CMD_SW_SUSPEND     0xD000FCE2
9291  #define        LINUX_REBOOT_CMD_KEXEC          0x45584543
9292 +#define        LINUX_REBOOT_CMD_OOM            0xDEADBEEF
9293  
9294  
9295  #ifdef __KERNEL__
9296 diff -NurpP --minimal linux-2.6.38.1/include/linux/reiserfs_fs.h linux-2.6.38.1-vs2.3.0.37-rc9/include/linux/reiserfs_fs.h
9297 --- linux-2.6.38.1/include/linux/reiserfs_fs.h  2011-01-05 21:50:32.000000000 +0100
9298 +++ linux-2.6.38.1-vs2.3.0.37-rc9/include/linux/reiserfs_fs.h   2011-01-29 02:01:07.000000000 +0100
9299 @@ -976,6 +976,11 @@ struct stat_data_v1 {
9300  #define REISERFS_COMPR_FL     FS_COMPR_FL
9301  #define REISERFS_NOTAIL_FL    FS_NOTAIL_FL
9302  
9303 +/* unfortunately reiserfs sdattr is only 16 bit */
9304 +#define REISERFS_IXUNLINK_FL  (FS_IXUNLINK_FL >> 16)
9305 +#define REISERFS_BARRIER_FL   (FS_BARRIER_FL >> 16)
9306 +#define REISERFS_COW_FL       (FS_COW_FL >> 16)
9307 +
9308  /* persistent flags that file inherits from the parent directory */
9309  #define REISERFS_INHERIT_MASK ( REISERFS_IMMUTABLE_FL |        \
9310                                 REISERFS_SYNC_FL |      \
9311 @@ -985,6 +990,9 @@ struct stat_data_v1 {
9312                                 REISERFS_COMPR_FL |     \
9313                                 REISERFS_NOTAIL_FL )
9314  
9315 +#define REISERFS_FL_USER_VISIBLE       0x80FF
9316 +#define REISERFS_FL_USER_MODIFIABLE    0x80FF
9317 +
9318  /* Stat Data on disk (reiserfs version of UFS disk inode minus the
9319     address blocks) */
9320  struct stat_data {
9321 @@ -2070,6 +2078,7 @@ static inline void reiserfs_update_sd(st
9322  void sd_attrs_to_i_attrs(__u16 sd_attrs, struct inode *inode);
9323  void i_attrs_to_sd_attrs(struct inode *inode, __u16 * sd_attrs);
9324  int reiserfs_setattr(struct dentry *dentry, struct iattr *attr);
9325 +int reiserfs_sync_flags(struct inode *inode, int, int);
9326  
9327  int __reiserfs_write_begin(struct page *page, unsigned from, unsigned len);
9328  
9329 diff -NurpP --minimal linux-2.6.38.1/include/linux/reiserfs_fs_sb.h linux-2.6.38.1-vs2.3.0.37-rc9/include/linux/reiserfs_fs_sb.h
9330 --- linux-2.6.38.1/include/linux/reiserfs_fs_sb.h       2010-02-25 11:52:07.000000000 +0100
9331 +++ linux-2.6.38.1-vs2.3.0.37-rc9/include/linux/reiserfs_fs_sb.h        2011-01-29 02:01:07.000000000 +0100
9332 @@ -476,6 +476,7 @@ enum reiserfs_mount_options {
9333         REISERFS_EXPOSE_PRIVROOT,
9334         REISERFS_BARRIER_NONE,
9335         REISERFS_BARRIER_FLUSH,
9336 +       REISERFS_TAGGED,
9337  
9338         /* Actions on error */
9339         REISERFS_ERROR_PANIC,
9340 diff -NurpP --minimal linux-2.6.38.1/include/linux/sched.h linux-2.6.38.1-vs2.3.0.37-rc9/include/linux/sched.h
9341 --- linux-2.6.38.1/include/linux/sched.h        2011-03-15 18:07:39.000000000 +0100
9342 +++ linux-2.6.38.1-vs2.3.0.37-rc9/include/linux/sched.h 2011-03-07 16:53:28.000000000 +0100
9343 @@ -1373,6 +1373,14 @@ struct task_struct {
9344  #endif
9345         seccomp_t seccomp;
9346  
9347 +/* vserver context data */
9348 +       struct vx_info *vx_info;
9349 +       struct nx_info *nx_info;
9350 +
9351 +       xid_t xid;
9352 +       nid_t nid;
9353 +       tag_t tag;
9354 +
9355  /* Thread group tracking */
9356         u32 parent_exec_id;
9357         u32 self_exec_id;
9358 @@ -1607,6 +1615,11 @@ struct pid_namespace;
9359  pid_t __task_pid_nr_ns(struct task_struct *task, enum pid_type type,
9360                         struct pid_namespace *ns);
9361  
9362 +#include <linux/vserver/base.h>
9363 +#include <linux/vserver/context.h>
9364 +#include <linux/vserver/debug.h>
9365 +#include <linux/vserver/pid.h>
9366 +
9367  static inline pid_t task_pid_nr(struct task_struct *tsk)
9368  {
9369         return tsk->pid;
9370 @@ -1620,7 +1633,8 @@ static inline pid_t task_pid_nr_ns(struc
9371  
9372  static inline pid_t task_pid_vnr(struct task_struct *tsk)
9373  {
9374 -       return __task_pid_nr_ns(tsk, PIDTYPE_PID, NULL);
9375 +       // return __task_pid_nr_ns(tsk, PIDTYPE_PID, NULL);
9376 +       return vx_map_pid(__task_pid_nr_ns(tsk, PIDTYPE_PID, NULL));
9377  }
9378  
9379  
9380 @@ -1633,7 +1647,7 @@ pid_t task_tgid_nr_ns(struct task_struct
9381  
9382  static inline pid_t task_tgid_vnr(struct task_struct *tsk)
9383  {
9384 -       return pid_vnr(task_tgid(tsk));
9385 +       return vx_map_tgid(pid_vnr(task_tgid(tsk)));
9386  }
9387  
9388  
9389 diff -NurpP --minimal linux-2.6.38.1/include/linux/shmem_fs.h linux-2.6.38.1-vs2.3.0.37-rc9/include/linux/shmem_fs.h
9390 --- linux-2.6.38.1/include/linux/shmem_fs.h     2010-10-21 13:07:55.000000000 +0200
9391 +++ linux-2.6.38.1-vs2.3.0.37-rc9/include/linux/shmem_fs.h      2011-01-29 02:01:07.000000000 +0100
9392 @@ -9,6 +9,9 @@
9393  
9394  #define SHMEM_NR_DIRECT 16
9395  
9396 +#define TMPFS_SUPER_MAGIC      0x01021994
9397 +
9398 +
9399  struct shmem_inode_info {
9400         spinlock_t              lock;
9401         unsigned long           flags;
9402 diff -NurpP --minimal linux-2.6.38.1/include/linux/stat.h linux-2.6.38.1-vs2.3.0.37-rc9/include/linux/stat.h
9403 --- linux-2.6.38.1/include/linux/stat.h 2008-12-25 00:26:37.000000000 +0100
9404 +++ linux-2.6.38.1-vs2.3.0.37-rc9/include/linux/stat.h  2011-01-29 02:01:07.000000000 +0100
9405 @@ -66,6 +66,7 @@ struct kstat {
9406         unsigned int    nlink;
9407         uid_t           uid;
9408         gid_t           gid;
9409 +       tag_t           tag;
9410         dev_t           rdev;
9411         loff_t          size;
9412         struct timespec  atime;
9413 diff -NurpP --minimal linux-2.6.38.1/include/linux/sunrpc/auth.h linux-2.6.38.1-vs2.3.0.37-rc9/include/linux/sunrpc/auth.h
9414 --- linux-2.6.38.1/include/linux/sunrpc/auth.h  2011-03-15 18:07:39.000000000 +0100
9415 +++ linux-2.6.38.1-vs2.3.0.37-rc9/include/linux/sunrpc/auth.h   2011-01-29 02:01:07.000000000 +0100
9416 @@ -25,6 +25,7 @@
9417  struct auth_cred {
9418         uid_t   uid;
9419         gid_t   gid;
9420 +       tag_t   tag;
9421         struct group_info *group_info;
9422         unsigned char machine_cred : 1;
9423  };
9424 diff -NurpP --minimal linux-2.6.38.1/include/linux/sunrpc/clnt.h linux-2.6.38.1-vs2.3.0.37-rc9/include/linux/sunrpc/clnt.h
9425 --- linux-2.6.38.1/include/linux/sunrpc/clnt.h  2011-03-15 18:07:39.000000000 +0100
9426 +++ linux-2.6.38.1-vs2.3.0.37-rc9/include/linux/sunrpc/clnt.h   2011-01-29 02:01:07.000000000 +0100
9427 @@ -49,7 +49,8 @@ struct rpc_clnt {
9428         unsigned int            cl_softrtry : 1,/* soft timeouts */
9429                                 cl_discrtry : 1,/* disconnect before retry */
9430                                 cl_autobind : 1,/* use getport() */
9431 -                               cl_chatty   : 1;/* be verbose */
9432 +                               cl_chatty   : 1,/* be verbose */
9433 +                               cl_tag      : 1;/* context tagging */
9434  
9435         struct rpc_rtt *        cl_rtt;         /* RTO estimator data */
9436         const struct rpc_timeout *cl_timeout;   /* Timeout strategy */
9437 diff -NurpP --minimal linux-2.6.38.1/include/linux/syscalls.h linux-2.6.38.1-vs2.3.0.37-rc9/include/linux/syscalls.h
9438 --- linux-2.6.38.1/include/linux/syscalls.h     2011-03-15 18:07:39.000000000 +0100
9439 +++ linux-2.6.38.1-vs2.3.0.37-rc9/include/linux/syscalls.h      2011-02-17 02:17:51.000000000 +0100
9440 @@ -478,6 +478,8 @@ asmlinkage long sys_symlink(const char _
9441  asmlinkage long sys_unlink(const char __user *pathname);
9442  asmlinkage long sys_rename(const char __user *oldname,
9443                                 const char __user *newname);
9444 +asmlinkage long sys_copyfile(const char __user *from, const char __user *to,
9445 +                               umode_t mode);
9446  asmlinkage long sys_chmod(const char __user *filename, mode_t mode);
9447  asmlinkage long sys_fchmod(unsigned int fd, mode_t mode);
9448  
9449 diff -NurpP --minimal linux-2.6.38.1/include/linux/sysctl.h linux-2.6.38.1-vs2.3.0.37-rc9/include/linux/sysctl.h
9450 --- linux-2.6.38.1/include/linux/sysctl.h       2011-03-15 18:07:40.000000000 +0100
9451 +++ linux-2.6.38.1-vs2.3.0.37-rc9/include/linux/sysctl.h        2011-03-15 18:15:06.000000000 +0100
9452 @@ -60,6 +60,7 @@ enum
9453         CTL_ABI=9,              /* Binary emulation */
9454         CTL_CPU=10,             /* CPU stuff (speed scaling, etc) */
9455         CTL_ARLAN=254,          /* arlan wireless driver */
9456 +       CTL_VSERVER=4242,       /* Linux-VServer debug */
9457         CTL_S390DBF=5677,       /* s390 debug */
9458         CTL_SUNRPC=7249,        /* sunrpc debug */
9459         CTL_PM=9899,            /* frv power management */
9460 @@ -94,6 +95,7 @@ enum
9461  
9462         KERN_PANIC=15,          /* int: panic timeout */
9463         KERN_REALROOTDEV=16,    /* real root device to mount after initrd */
9464 +       KERN_VSHELPER=17,       /* string: path to vshelper policy agent */
9465  
9466         KERN_SPARC_REBOOT=21,   /* reboot command on Sparc */
9467         KERN_CTLALTDEL=22,      /* int: allow ctl-alt-del to reboot */
9468 diff -NurpP --minimal linux-2.6.38.1/include/linux/sysfs.h linux-2.6.38.1-vs2.3.0.37-rc9/include/linux/sysfs.h
9469 --- linux-2.6.38.1/include/linux/sysfs.h        2011-01-05 21:50:34.000000000 +0100
9470 +++ linux-2.6.38.1-vs2.3.0.37-rc9/include/linux/sysfs.h 2011-01-29 02:01:07.000000000 +0100
9471 @@ -19,6 +19,8 @@
9472  #include <linux/kobject_ns.h>
9473  #include <asm/atomic.h>
9474  
9475 +#define SYSFS_SUPER_MAGIC      0x62656572
9476 +
9477  struct kobject;
9478  struct module;
9479  enum kobj_ns_type;
9480 diff -NurpP --minimal linux-2.6.38.1/include/linux/time.h linux-2.6.38.1-vs2.3.0.37-rc9/include/linux/time.h
9481 --- linux-2.6.38.1/include/linux/time.h 2011-03-15 18:07:40.000000000 +0100
9482 +++ linux-2.6.38.1-vs2.3.0.37-rc9/include/linux/time.h  2011-01-29 02:01:07.000000000 +0100
9483 @@ -254,6 +254,9 @@ static __always_inline void timespec_add
9484         a->tv_sec += __iter_div_u64_rem(a->tv_nsec + ns, NSEC_PER_SEC, &ns);
9485         a->tv_nsec = ns;
9486  }
9487 +
9488 +#include <linux/vs_time.h>
9489 +
9490  #endif /* __KERNEL__ */
9491  
9492  #define NFDBITS                        __NFDBITS
9493 diff -NurpP --minimal linux-2.6.38.1/include/linux/types.h linux-2.6.38.1-vs2.3.0.37-rc9/include/linux/types.h
9494 --- linux-2.6.38.1/include/linux/types.h        2011-01-05 21:50:34.000000000 +0100
9495 +++ linux-2.6.38.1-vs2.3.0.37-rc9/include/linux/types.h 2011-01-29 02:01:07.000000000 +0100
9496 @@ -40,6 +40,9 @@ typedef __kernel_uid32_t      uid_t;
9497  typedef __kernel_gid32_t       gid_t;
9498  typedef __kernel_uid16_t        uid16_t;
9499  typedef __kernel_gid16_t        gid16_t;
9500 +typedef unsigned int           xid_t;
9501 +typedef unsigned int           nid_t;
9502 +typedef unsigned int           tag_t;
9503  
9504  typedef unsigned long          uintptr_t;
9505  
9506 diff -NurpP --minimal linux-2.6.38.1/include/linux/vroot.h linux-2.6.38.1-vs2.3.0.37-rc9/include/linux/vroot.h
9507 --- linux-2.6.38.1/include/linux/vroot.h        1970-01-01 01:00:00.000000000 +0100
9508 +++ linux-2.6.38.1-vs2.3.0.37-rc9/include/linux/vroot.h 2011-01-29 02:01:07.000000000 +0100
9509 @@ -0,0 +1,51 @@
9510 +
9511 +/*
9512 + * include/linux/vroot.h
9513 + *
9514 + * written by Herbert Pötzl, 9/11/2002
9515 + * ported to 2.6 by Herbert Pötzl, 30/12/2004
9516 + *
9517 + * Copyright (C) 2002-2007 by Herbert Pötzl.
9518 + * Redistribution of this file is permitted under the
9519 + * GNU General Public License.
9520 + */
9521 +
9522 +#ifndef _LINUX_VROOT_H
9523 +#define _LINUX_VROOT_H
9524 +
9525 +
9526 +#ifdef __KERNEL__
9527 +
9528 +/* Possible states of device */
9529 +enum {
9530 +       Vr_unbound,
9531 +       Vr_bound,
9532 +};
9533 +
9534 +struct vroot_device {
9535 +       int             vr_number;
9536 +       int             vr_refcnt;
9537 +
9538 +       struct semaphore        vr_ctl_mutex;
9539 +       struct block_device    *vr_device;
9540 +       int                     vr_state;
9541 +};
9542 +
9543 +
9544 +typedef struct block_device *(vroot_grb_func)(struct block_device *);
9545 +
9546 +extern int register_vroot_grb(vroot_grb_func *);
9547 +extern int unregister_vroot_grb(vroot_grb_func *);
9548 +
9549 +#endif /* __KERNEL__ */
9550 +
9551 +#define MAX_VROOT_DEFAULT      8
9552 +
9553 +/*
9554 + * IOCTL commands --- we will commandeer 0x56 ('V')
9555 + */
9556 +
9557 +#define VROOT_SET_DEV          0x5600
9558 +#define VROOT_CLR_DEV          0x5601
9559 +
9560 +#endif /* _LINUX_VROOT_H */
9561 diff -NurpP --minimal linux-2.6.38.1/include/linux/vs_base.h linux-2.6.38.1-vs2.3.0.37-rc9/include/linux/vs_base.h
9562 --- linux-2.6.38.1/include/linux/vs_base.h      1970-01-01 01:00:00.000000000 +0100
9563 +++ linux-2.6.38.1-vs2.3.0.37-rc9/include/linux/vs_base.h       2011-01-29 02:01:07.000000000 +0100
9564 @@ -0,0 +1,10 @@
9565 +#ifndef _VS_BASE_H
9566 +#define _VS_BASE_H
9567 +
9568 +#include "vserver/base.h"
9569 +#include "vserver/check.h"
9570 +#include "vserver/debug.h"
9571 +
9572 +#else
9573 +#warning duplicate inclusion
9574 +#endif
9575 diff -NurpP --minimal linux-2.6.38.1/include/linux/vs_context.h linux-2.6.38.1-vs2.3.0.37-rc9/include/linux/vs_context.h
9576 --- linux-2.6.38.1/include/linux/vs_context.h   1970-01-01 01:00:00.000000000 +0100
9577 +++ linux-2.6.38.1-vs2.3.0.37-rc9/include/linux/vs_context.h    2011-01-29 02:01:07.000000000 +0100
9578 @@ -0,0 +1,242 @@
9579 +#ifndef _VS_CONTEXT_H
9580 +#define _VS_CONTEXT_H
9581 +
9582 +#include "vserver/base.h"
9583 +#include "vserver/check.h"
9584 +#include "vserver/context.h"
9585 +#include "vserver/history.h"
9586 +#include "vserver/debug.h"
9587 +
9588 +#include <linux/sched.h>
9589 +
9590 +
9591 +#define get_vx_info(i) __get_vx_info(i, __FILE__, __LINE__, __HERE__)
9592 +
9593 +static inline struct vx_info *__get_vx_info(struct vx_info *vxi,
9594 +       const char *_file, int _line, void *_here)
9595 +{
9596 +       if (!vxi)
9597 +               return NULL;
9598 +
9599 +       vxlprintk(VXD_CBIT(xid, 2), "get_vx_info(%p[#%d.%d])",
9600 +               vxi, vxi ? vxi->vx_id : 0,
9601 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
9602 +               _file, _line);
9603 +       __vxh_get_vx_info(vxi, _here);
9604 +
9605 +       atomic_inc(&vxi->vx_usecnt);
9606 +       return vxi;
9607 +}
9608 +
9609 +
9610 +extern void free_vx_info(struct vx_info *);
9611 +
9612 +#define put_vx_info(i) __put_vx_info(i, __FILE__, __LINE__, __HERE__)
9613 +
9614 +static inline void __put_vx_info(struct vx_info *vxi,
9615 +       const char *_file, int _line, void *_here)
9616 +{
9617 +       if (!vxi)
9618 +               return;
9619 +
9620 +       vxlprintk(VXD_CBIT(xid, 2), "put_vx_info(%p[#%d.%d])",
9621 +               vxi, vxi ? vxi->vx_id : 0,
9622 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
9623 +               _file, _line);
9624 +       __vxh_put_vx_info(vxi, _here);
9625 +
9626 +       if (atomic_dec_and_test(&vxi->vx_usecnt))
9627 +               free_vx_info(vxi);
9628 +}
9629 +
9630 +
9631 +#define init_vx_info(p, i) \
9632 +       __init_vx_info(p, i, __FILE__, __LINE__, __HERE__)
9633 +
9634 +static inline void __init_vx_info(struct vx_info **vxp, struct vx_info *vxi,
9635 +       const char *_file, int _line, void *_here)
9636 +{
9637 +       if (vxi) {
9638 +               vxlprintk(VXD_CBIT(xid, 3),
9639 +                       "init_vx_info(%p[#%d.%d])",
9640 +                       vxi, vxi ? vxi->vx_id : 0,
9641 +                       vxi ? atomic_read(&vxi->vx_usecnt) : 0,
9642 +                       _file, _line);
9643 +               __vxh_init_vx_info(vxi, vxp, _here);
9644 +
9645 +               atomic_inc(&vxi->vx_usecnt);
9646 +       }
9647 +       *vxp = vxi;
9648 +}
9649 +
9650 +
9651 +#define set_vx_info(p, i) \
9652 +       __set_vx_info(p, i, __FILE__, __LINE__, __HERE__)
9653 +
9654 +static inline void __set_vx_info(struct vx_info **vxp, struct vx_info *vxi,
9655 +       const char *_file, int _line, void *_here)
9656 +{
9657 +       struct vx_info *vxo;
9658 +
9659 +       if (!vxi)
9660 +               return;
9661 +
9662 +       vxlprintk(VXD_CBIT(xid, 3), "set_vx_info(%p[#%d.%d])",
9663 +               vxi, vxi ? vxi->vx_id : 0,
9664 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
9665 +               _file, _line);
9666 +       __vxh_set_vx_info(vxi, vxp, _here);
9667 +
9668 +       atomic_inc(&vxi->vx_usecnt);
9669 +       vxo = xchg(vxp, vxi);
9670 +       BUG_ON(vxo);
9671 +}
9672 +
9673 +
9674 +#define clr_vx_info(p) __clr_vx_info(p, __FILE__, __LINE__, __HERE__)
9675 +
9676 +static inline void __clr_vx_info(struct vx_info **vxp,
9677 +       const char *_file, int _line, void *_here)
9678 +{
9679 +       struct vx_info *vxo;
9680 +
9681 +       vxo = xchg(vxp, NULL);
9682 +       if (!vxo)
9683 +               return;
9684 +
9685 +       vxlprintk(VXD_CBIT(xid, 3), "clr_vx_info(%p[#%d.%d])",
9686 +               vxo, vxo ? vxo->vx_id : 0,
9687 +               vxo ? atomic_read(&vxo->vx_usecnt) : 0,
9688 +               _file, _line);
9689 +       __vxh_clr_vx_info(vxo, vxp, _here);
9690 +
9691 +       if (atomic_dec_and_test(&vxo->vx_usecnt))
9692 +               free_vx_info(vxo);
9693 +}
9694 +
9695 +
9696 +#define claim_vx_info(v, p) \
9697 +       __claim_vx_info(v, p, __FILE__, __LINE__, __HERE__)
9698 +
9699 +static inline void __claim_vx_info(struct vx_info *vxi,
9700 +       struct task_struct *task,
9701 +       const char *_file, int _line, void *_here)
9702 +{
9703 +       vxlprintk(VXD_CBIT(xid, 3), "claim_vx_info(%p[#%d.%d.%d]) %p",
9704 +               vxi, vxi ? vxi->vx_id : 0,
9705 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
9706 +               vxi ? atomic_read(&vxi->vx_tasks) : 0,
9707 +               task, _file, _line);
9708 +       __vxh_claim_vx_info(vxi, task, _here);
9709 +
9710 +       atomic_inc(&vxi->vx_tasks);
9711 +}
9712 +
9713 +
9714 +extern void unhash_vx_info(struct vx_info *);
9715 +
9716 +#define release_vx_info(v, p) \
9717 +       __release_vx_info(v, p, __FILE__, __LINE__, __HERE__)
9718 +
9719 +static inline void __release_vx_info(struct vx_info *vxi,
9720 +       struct task_struct *task,
9721 +       const char *_file, int _line, void *_here)
9722 +{
9723 +       vxlprintk(VXD_CBIT(xid, 3), "release_vx_info(%p[#%d.%d.%d]) %p",
9724 +               vxi, vxi ? vxi->vx_id : 0,
9725 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
9726 +               vxi ? atomic_read(&vxi->vx_tasks) : 0,
9727 +               task, _file, _line);
9728 +       __vxh_release_vx_info(vxi, task, _here);
9729 +
9730 +       might_sleep();
9731 +
9732 +       if (atomic_dec_and_test(&vxi->vx_tasks))
9733 +               unhash_vx_info(vxi);
9734 +}
9735 +
9736 +
9737 +#define task_get_vx_info(p) \
9738 +       __task_get_vx_info(p, __FILE__, __LINE__, __HERE__)
9739 +
9740 +static inline struct vx_info *__task_get_vx_info(struct task_struct *p,
9741 +       const char *_file, int _line, void *_here)
9742 +{
9743 +       struct vx_info *vxi;
9744 +
9745 +       task_lock(p);
9746 +       vxlprintk(VXD_CBIT(xid, 5), "task_get_vx_info(%p)",
9747 +               p, _file, _line);
9748 +       vxi = __get_vx_info(p->vx_info, _file, _line, _here);
9749 +       task_unlock(p);
9750 +       return vxi;
9751 +}
9752 +
9753 +
9754 +static inline void __wakeup_vx_info(struct vx_info *vxi)
9755 +{
9756 +       if (waitqueue_active(&vxi->vx_wait))
9757 +               wake_up_interruptible(&vxi->vx_wait);
9758 +}
9759 +
9760 +
9761 +#define enter_vx_info(v, s) __enter_vx_info(v, s, __FILE__, __LINE__)
9762 +
9763 +static inline void __enter_vx_info(struct vx_info *vxi,
9764 +       struct vx_info_save *vxis, const char *_file, int _line)
9765 +{
9766 +       vxlprintk(VXD_CBIT(xid, 5), "enter_vx_info(%p[#%d],%p) %p[#%d,%p]",
9767 +               vxi, vxi ? vxi->vx_id : 0, vxis, current,
9768 +               current->xid, current->vx_info, _file, _line);
9769 +       vxis->vxi = xchg(&current->vx_info, vxi);
9770 +       vxis->xid = current->xid;
9771 +       current->xid = vxi ? vxi->vx_id : 0;
9772 +}
9773 +
9774 +#define leave_vx_info(s) __leave_vx_info(s, __FILE__, __LINE__)
9775 +
9776 +static inline void __leave_vx_info(struct vx_info_save *vxis,
9777 +       const char *_file, int _line)
9778 +{
9779 +       vxlprintk(VXD_CBIT(xid, 5), "leave_vx_info(%p[#%d,%p]) %p[#%d,%p]",
9780 +               vxis, vxis->xid, vxis->vxi, current,
9781 +               current->xid, current->vx_info, _file, _line);
9782 +       (void)xchg(&current->vx_info, vxis->vxi);
9783 +       current->xid = vxis->xid;
9784 +}
9785 +
9786 +
9787 +static inline void __enter_vx_admin(struct vx_info_save *vxis)
9788 +{
9789 +       vxis->vxi = xchg(&current->vx_info, NULL);
9790 +       vxis->xid = xchg(&current->xid, (xid_t)0);
9791 +}
9792 +
9793 +static inline void __leave_vx_admin(struct vx_info_save *vxis)
9794 +{
9795 +       (void)xchg(&current->xid, vxis->xid);
9796 +       (void)xchg(&current->vx_info, vxis->vxi);
9797 +}
9798 +
9799 +#define task_is_init(p) \
9800 +       __task_is_init(p, __FILE__, __LINE__, __HERE__)
9801 +
9802 +static inline int __task_is_init(struct task_struct *p,
9803 +       const char *_file, int _line, void *_here)
9804 +{
9805 +       int is_init = is_global_init(p);
9806 +
9807 +       task_lock(p);
9808 +       if (p->vx_info)
9809 +               is_init = p->vx_info->vx_initpid == p->pid;
9810 +       task_unlock(p);
9811 +       return is_init;
9812 +}
9813 +
9814 +extern void exit_vx_info(struct task_struct *, int);
9815 +extern void exit_vx_info_early(struct task_struct *, int);
9816 +
9817 +
9818 +#else
9819 +#warning duplicate inclusion
9820 +#endif
9821 diff -NurpP --minimal linux-2.6.38.1/include/linux/vs_cowbl.h linux-2.6.38.1-vs2.3.0.37-rc9/include/linux/vs_cowbl.h
9822 --- linux-2.6.38.1/include/linux/vs_cowbl.h     1970-01-01 01:00:00.000000000 +0100
9823 +++ linux-2.6.38.1-vs2.3.0.37-rc9/include/linux/vs_cowbl.h      2011-01-29 02:01:07.000000000 +0100
9824 @@ -0,0 +1,48 @@
9825 +#ifndef _VS_COWBL_H
9826 +#define _VS_COWBL_H
9827 +
9828 +#include <linux/fs.h>
9829 +#include <linux/dcache.h>
9830 +#include <linux/namei.h>
9831 +#include <linux/slab.h>
9832 +
9833 +extern struct dentry *cow_break_link(const char *pathname);
9834 +
9835 +static inline int cow_check_and_break(struct path *path)
9836 +{
9837 +       struct inode *inode = path->dentry->d_inode;
9838 +       int error = 0;
9839 +
9840 +       /* do we need this check? */
9841 +       if (IS_RDONLY(inode))
9842 +               return -EROFS;
9843 +
9844 +       if (IS_COW(inode)) {
9845 +               if (IS_COW_LINK(inode)) {
9846 +                       struct dentry *new_dentry, *old_dentry = path->dentry;
9847 +                       char *pp, *buf;
9848 +
9849 +                       buf = kmalloc(PATH_MAX, GFP_KERNEL);
9850 +                       if (!buf) {
9851 +                               return -ENOMEM;
9852 +                       }
9853 +                       pp = d_path(path, buf, PATH_MAX);
9854 +                       new_dentry = cow_break_link(pp);
9855 +                       kfree(buf);
9856 +                       if (!IS_ERR(new_dentry)) {
9857 +                               path->dentry = new_dentry;
9858 +                               dput(old_dentry);
9859 +                       } else
9860 +                               error = PTR_ERR(new_dentry);
9861 +               } else {
9862 +                       inode->i_flags &= ~(S_IXUNLINK | S_IMMUTABLE);
9863 +                       inode->i_ctime = CURRENT_TIME;
9864 +                       mark_inode_dirty(inode);
9865 +               }
9866 +       }
9867 +       return error;
9868 +}
9869 +
9870 +#else
9871 +#warning duplicate inclusion
9872 +#endif
9873 diff -NurpP --minimal linux-2.6.38.1/include/linux/vs_cvirt.h linux-2.6.38.1-vs2.3.0.37-rc9/include/linux/vs_cvirt.h
9874 --- linux-2.6.38.1/include/linux/vs_cvirt.h     1970-01-01 01:00:00.000000000 +0100
9875 +++ linux-2.6.38.1-vs2.3.0.37-rc9/include/linux/vs_cvirt.h      2011-01-29 02:01:07.000000000 +0100
9876 @@ -0,0 +1,50 @@
9877 +#ifndef _VS_CVIRT_H
9878 +#define _VS_CVIRT_H
9879 +
9880 +#include "vserver/cvirt.h"
9881 +#include "vserver/context.h"
9882 +#include "vserver/base.h"
9883 +#include "vserver/check.h"
9884 +#include "vserver/debug.h"
9885 +
9886 +
9887 +static inline void vx_activate_task(struct task_struct *p)
9888 +{
9889 +       struct vx_info *vxi;
9890 +
9891 +       if ((vxi = p->vx_info)) {
9892 +               vx_update_load(vxi);
9893 +               atomic_inc(&vxi->cvirt.nr_running);
9894 +       }
9895 +}
9896 +
9897 +static inline void vx_deactivate_task(struct task_struct *p)
9898 +{
9899 +       struct vx_info *vxi;
9900 +
9901 +       if ((vxi = p->vx_info)) {
9902 +               vx_update_load(vxi);
9903 +               atomic_dec(&vxi->cvirt.nr_running);
9904 +       }
9905 +}
9906 +
9907 +static inline void vx_uninterruptible_inc(struct task_struct *p)
9908 +{
9909 +       struct vx_info *vxi;
9910 +
9911 +       if ((vxi = p->vx_info))
9912 +               atomic_inc(&vxi->cvirt.nr_uninterruptible);
9913 +}
9914 +
9915 +static inline void vx_uninterruptible_dec(struct task_struct *p)
9916 +{
9917 +       struct vx_info *vxi;
9918 +
9919 +       if ((vxi = p->vx_info))
9920 +               atomic_dec(&vxi->cvirt.nr_uninterruptible);
9921 +}
9922 +
9923 +
9924 +#else
9925 +#warning duplicate inclusion
9926 +#endif
9927 diff -NurpP --minimal linux-2.6.38.1/include/linux/vs_device.h linux-2.6.38.1-vs2.3.0.37-rc9/include/linux/vs_device.h
9928 --- linux-2.6.38.1/include/linux/vs_device.h    1970-01-01 01:00:00.000000000 +0100
9929 +++ linux-2.6.38.1-vs2.3.0.37-rc9/include/linux/vs_device.h     2011-01-29 02:01:07.000000000 +0100
9930 @@ -0,0 +1,45 @@
9931 +#ifndef _VS_DEVICE_H
9932 +#define _VS_DEVICE_H
9933 +
9934 +#include "vserver/base.h"
9935 +#include "vserver/device.h"
9936 +#include "vserver/debug.h"
9937 +
9938 +
9939 +#ifdef CONFIG_VSERVER_DEVICE
9940 +
9941 +int vs_map_device(struct vx_info *, dev_t, dev_t *, umode_t);
9942 +
9943 +#define vs_device_perm(v, d, m, p) \
9944 +       ((vs_map_device(current_vx_info(), d, NULL, m) & (p)) == (p))
9945 +
9946 +#else
9947 +
9948 +static inline
9949 +int vs_map_device(struct vx_info *vxi,
9950 +       dev_t device, dev_t *target, umode_t mode)
9951 +{
9952 +       if (target)
9953 +               *target = device;
9954 +       return ~0;
9955 +}
9956 +
9957 +#define vs_device_perm(v, d, m, p) ((p) == (p))
9958 +
9959 +#endif
9960 +
9961 +
9962 +#define vs_map_chrdev(d, t, p) \
9963 +       ((vs_map_device(current_vx_info(), d, t, S_IFCHR) & (p)) == (p))
9964 +#define vs_map_blkdev(d, t, p) \
9965 +       ((vs_map_device(current_vx_info(), d, t, S_IFBLK) & (p)) == (p))
9966 +
9967 +#define vs_chrdev_perm(d, p) \
9968 +       vs_device_perm(current_vx_info(), d, S_IFCHR, p)
9969 +#define vs_blkdev_perm(d, p) \
9970 +       vs_device_perm(current_vx_info(), d, S_IFBLK, p)
9971 +
9972 +
9973 +#else
9974 +#warning duplicate inclusion
9975 +#endif
9976 diff -NurpP --minimal linux-2.6.38.1/include/linux/vs_dlimit.h linux-2.6.38.1-vs2.3.0.37-rc9/include/linux/vs_dlimit.h
9977 --- linux-2.6.38.1/include/linux/vs_dlimit.h    1970-01-01 01:00:00.000000000 +0100
9978 +++ linux-2.6.38.1-vs2.3.0.37-rc9/include/linux/vs_dlimit.h     2011-01-29 02:01:07.000000000 +0100
9979 @@ -0,0 +1,215 @@
9980 +#ifndef _VS_DLIMIT_H
9981 +#define _VS_DLIMIT_H
9982 +
9983 +#include <linux/fs.h>
9984 +
9985 +#include "vserver/dlimit.h"
9986 +#include "vserver/base.h"
9987 +#include "vserver/debug.h"
9988 +
9989 +
9990 +#define get_dl_info(i) __get_dl_info(i, __FILE__, __LINE__)
9991 +
9992 +static inline struct dl_info *__get_dl_info(struct dl_info *dli,
9993 +       const char *_file, int _line)
9994 +{
9995 +       if (!dli)
9996 +               return NULL;
9997 +       vxlprintk(VXD_CBIT(dlim, 4), "get_dl_info(%p[#%d.%d])",
9998 +               dli, dli ? dli->dl_tag : 0,
9999 +               dli ? atomic_read(&dli->dl_usecnt) : 0,
10000 +               _file, _line);
10001 +       atomic_inc(&dli->dl_usecnt);
10002 +       return dli;
10003 +}
10004 +
10005 +
10006 +#define free_dl_info(i) \
10007 +       call_rcu(&(i)->dl_rcu, rcu_free_dl_info)
10008 +
10009 +#define put_dl_info(i) __put_dl_info(i, __FILE__, __LINE__)
10010 +
10011 +static inline void __put_dl_info(struct dl_info *dli,
10012 +       const char *_file, int _line)
10013 +{
10014 +       if (!dli)
10015 +               return;
10016 +       vxlprintk(VXD_CBIT(dlim, 4), "put_dl_info(%p[#%d.%d])",
10017 +               dli, dli ? dli->dl_tag : 0,
10018 +               dli ? atomic_read(&dli->dl_usecnt) : 0,
10019 +               _file, _line);
10020 +       if (atomic_dec_and_test(&dli->dl_usecnt))
10021 +               free_dl_info(dli);
10022 +}
10023 +
10024 +
10025 +#define __dlimit_char(d)       ((d) ? '*' : ' ')
10026 +
10027 +static inline int __dl_alloc_space(struct super_block *sb,
10028 +       tag_t tag, dlsize_t nr, const char *file, int line)
10029 +{
10030 +       struct dl_info *dli = NULL;
10031 +       int ret = 0;
10032 +
10033 +       if (nr == 0)
10034 +               goto out;
10035 +       dli = locate_dl_info(sb, tag);
10036 +       if (!dli)
10037 +               goto out;
10038 +
10039 +       spin_lock(&dli->dl_lock);
10040 +       ret = (dli->dl_space_used + nr > dli->dl_space_total);
10041 +       if (!ret)
10042 +               dli->dl_space_used += nr;
10043 +       spin_unlock(&dli->dl_lock);
10044 +       put_dl_info(dli);
10045 +out:
10046 +       vxlprintk(VXD_CBIT(dlim, 1),
10047 +               "ALLOC (%p,#%d)%c %lld bytes (%d)",
10048 +               sb, tag, __dlimit_char(dli), (long long)nr,
10049 +               ret, file, line);
10050 +       return ret ? -ENOSPC : 0;
10051 +}
10052 +
10053 +static inline void __dl_free_space(struct super_block *sb,
10054 +       tag_t tag, dlsize_t nr, const char *_file, int _line)
10055 +{
10056 +       struct dl_info *dli = NULL;
10057 +
10058 +       if (nr == 0)
10059 +               goto out;
10060 +       dli = locate_dl_info(sb, tag);
10061 +       if (!dli)
10062 +               goto out;
10063 +
10064 +       spin_lock(&dli->dl_lock);
10065 +       if (dli->dl_space_used > nr)
10066 +               dli->dl_space_used -= nr;
10067 +       else
10068 +               dli->dl_space_used = 0;
10069 +       spin_unlock(&dli->dl_lock);
10070 +       put_dl_info(dli);
10071 +out:
10072 +       vxlprintk(VXD_CBIT(dlim, 1),
10073 +               "FREE  (%p,#%d)%c %lld bytes",
10074 +               sb, tag, __dlimit_char(dli), (long long)nr,
10075 +               _file, _line);
10076 +}
10077 +
10078 +static inline int __dl_alloc_inode(struct super_block *sb,
10079 +       tag_t tag, const char *_file, int _line)
10080 +{
10081 +       struct dl_info *dli;
10082 +       int ret = 0;
10083 +
10084 +       dli = locate_dl_info(sb, tag);
10085 +       if (!dli)
10086 +               goto out;
10087 +
10088 +       spin_lock(&dli->dl_lock);
10089 +       dli->dl_inodes_used++;
10090 +       ret = (dli->dl_inodes_used > dli->dl_inodes_total);
10091 +       spin_unlock(&dli->dl_lock);
10092 +       put_dl_info(dli);
10093 +out:
10094 +       vxlprintk(VXD_CBIT(dlim, 0),
10095 +               "ALLOC (%p,#%d)%c inode (%d)",
10096 +               sb, tag, __dlimit_char(dli), ret, _file, _line);
10097 +       return ret ? -ENOSPC : 0;
10098 +}
10099 +
10100 +static inline void __dl_free_inode(struct super_block *sb,
10101 +       tag_t tag, const char *_file, int _line)
10102 +{
10103 +       struct dl_info *dli;
10104 +
10105 +       dli = locate_dl_info(sb, tag);
10106 +       if (!dli)
10107 +               goto out;
10108 +
10109 +       spin_lock(&dli->dl_lock);
10110 +       if (dli->dl_inodes_used > 1)
10111 +               dli->dl_inodes_used--;
10112 +       else
10113 +               dli->dl_inodes_used = 0;
10114 +       spin_unlock(&dli->dl_lock);
10115 +       put_dl_info(dli);
10116 +out:
10117 +       vxlprintk(VXD_CBIT(dlim, 0),
10118 +               "FREE  (%p,#%d)%c inode",
10119 +               sb, tag, __dlimit_char(dli), _file, _line);
10120 +}
10121 +
10122 +static inline void __dl_adjust_block(struct super_block *sb, tag_t tag,
10123 +       unsigned long long *free_blocks, unsigned long long *root_blocks,
10124 +       const char *_file, int _line)
10125 +{
10126 +       struct dl_info *dli;
10127 +       uint64_t broot, bfree;
10128 +
10129 +       dli = locate_dl_info(sb, tag);
10130 +       if (!dli)
10131 +               return;
10132 +
10133 +       spin_lock(&dli->dl_lock);
10134 +       broot = (dli->dl_space_total -
10135 +               (dli->dl_space_total >> 10) * dli->dl_nrlmult)
10136 +               >> sb->s_blocksize_bits;
10137 +       bfree = (dli->dl_space_total - dli->dl_space_used)
10138 +                       >> sb->s_blocksize_bits;
10139 +       spin_unlock(&dli->dl_lock);
10140 +
10141 +       vxlprintk(VXD_CBIT(dlim, 2),
10142 +               "ADJUST: %lld,%lld on %lld,%lld [mult=%d]",
10143 +               (long long)bfree, (long long)broot,
10144 +               *free_blocks, *root_blocks, dli->dl_nrlmult,
10145 +               _file, _line);
10146 +       if (free_blocks) {
10147 +               if (*free_blocks > bfree)
10148 +                       *free_blocks = bfree;
10149 +       }
10150 +       if (root_blocks) {
10151 +               if (*root_blocks > broot)
10152 +                       *root_blocks = broot;
10153 +       }
10154 +       put_dl_info(dli);
10155 +}
10156 +
10157 +#define dl_prealloc_space(in, bytes) \
10158 +       __dl_alloc_space((in)->i_sb, (in)->i_tag, (dlsize_t)(bytes), \
10159 +               __FILE__, __LINE__ )
10160 +
10161 +#define dl_alloc_space(in, bytes) \
10162 +       __dl_alloc_space((in)->i_sb, (in)->i_tag, (dlsize_t)(bytes), \
10163 +               __FILE__, __LINE__ )
10164 +
10165 +#define dl_reserve_space(in, bytes) \
10166 +       __dl_alloc_space((in)->i_sb, (in)->i_tag, (dlsize_t)(bytes), \
10167 +               __FILE__, __LINE__ )
10168 +
10169 +#define dl_claim_space(in, bytes) (0)
10170 +
10171 +#define dl_release_space(in, bytes) \
10172 +       __dl_free_space((in)->i_sb, (in)->i_tag, (dlsize_t)(bytes), \
10173 +               __FILE__, __LINE__ )
10174 +
10175 +#define dl_free_space(in, bytes) \
10176 +       __dl_free_space((in)->i_sb, (in)->i_tag, (dlsize_t)(bytes), \
10177 +               __FILE__, __LINE__ )
10178 +
10179 +
10180 +
10181 +#define dl_alloc_inode(in) \
10182 +       __dl_alloc_inode((in)->i_sb, (in)->i_tag, __FILE__, __LINE__ )
10183 +
10184 +#define dl_free_inode(in) \
10185 +       __dl_free_inode((in)->i_sb, (in)->i_tag, __FILE__, __LINE__ )
10186 +
10187 +
10188 +#define dl_adjust_block(sb, tag, fb, rb) \
10189 +       __dl_adjust_block(sb, tag, fb, rb, __FILE__, __LINE__ )
10190 +
10191 +
10192 +#else
10193 +#warning duplicate inclusion
10194 +#endif
10195 diff -NurpP --minimal linux-2.6.38.1/include/linux/vs_inet.h linux-2.6.38.1-vs2.3.0.37-rc9/include/linux/vs_inet.h
10196 --- linux-2.6.38.1/include/linux/vs_inet.h      1970-01-01 01:00:00.000000000 +0100
10197 +++ linux-2.6.38.1-vs2.3.0.37-rc9/include/linux/vs_inet.h       2011-01-29 04:45:50.000000000 +0100
10198 @@ -0,0 +1,351 @@
10199 +#ifndef _VS_INET_H
10200 +#define _VS_INET_H
10201 +
10202 +#include "vserver/base.h"
10203 +#include "vserver/network.h"
10204 +#include "vserver/debug.h"
10205 +
10206 +#define IPI_LOOPBACK   htonl(INADDR_LOOPBACK)
10207 +
10208 +#define NXAV4(a)       NIPQUAD((a)->ip[0]), NIPQUAD((a)->ip[1]), \
10209 +                       NIPQUAD((a)->mask), (a)->type
10210 +#define NXAV4_FMT      "[" NIPQUAD_FMT "-" NIPQUAD_FMT "/" NIPQUAD_FMT ":%04x]"
10211 +
10212 +#define NIPQUAD(addr) \
10213 +       ((unsigned char *)&addr)[0], \
10214 +       ((unsigned char *)&addr)[1], \
10215 +       ((unsigned char *)&addr)[2], \
10216 +       ((unsigned char *)&addr)[3]
10217 +
10218 +#define NIPQUAD_FMT "%u.%u.%u.%u"
10219 +
10220 +
10221 +static inline
10222 +int v4_addr_match(struct nx_addr_v4 *nxa, __be32 addr, uint16_t tmask)
10223 +{
10224 +       __be32 ip = nxa->ip[0].s_addr;
10225 +       __be32 mask = nxa->mask.s_addr;
10226 +       __be32 bcast = ip | ~mask;
10227 +       int ret = 0;
10228 +
10229 +       switch (nxa->type & tmask) {
10230 +       case NXA_TYPE_MASK:
10231 +               ret = (ip == (addr & mask));
10232 +               break;
10233 +       case NXA_TYPE_ADDR:
10234 +               ret = 3;
10235 +               if (addr == ip)
10236 +                       break;
10237 +               /* fall through to broadcast */
10238 +       case NXA_MOD_BCAST:
10239 +               ret = ((tmask & NXA_MOD_BCAST) && (addr == bcast));
10240 +               break;
10241 +       case NXA_TYPE_RANGE:
10242 +               ret = ((nxa->ip[0].s_addr <= addr) &&
10243 +                       (nxa->ip[1].s_addr > addr));
10244 +               break;
10245 +       case NXA_TYPE_ANY:
10246 +               ret = 2;
10247 +               break;
10248 +       }
10249 +
10250 +       vxdprintk(VXD_CBIT(net, 0),
10251 +               "v4_addr_match(%p" NXAV4_FMT "," NIPQUAD_FMT ",%04x) = %d",
10252 +               nxa, NXAV4(nxa), NIPQUAD(addr), tmask, ret);
10253 +       return ret;
10254 +}
10255 +
10256 +static inline
10257 +int v4_addr_in_nx_info(struct nx_info *nxi, __be32 addr, uint16_t tmask)
10258 +{
10259 +       struct nx_addr_v4 *nxa;
10260 +       int ret = 1;
10261 +
10262 +       if (!nxi)
10263 +               goto out;
10264 +
10265 +       ret = 2;
10266 +       /* allow 127.0.0.1 when remapping lback */
10267 +       if ((tmask & NXA_LOOPBACK) &&
10268 +               (addr == IPI_LOOPBACK) &&
10269 +               nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
10270 +               goto out;
10271 +       ret = 3;
10272 +       /* check for lback address */
10273 +       if ((tmask & NXA_MOD_LBACK) &&
10274 +               (nxi->v4_lback.s_addr == addr))
10275 +               goto out;
10276 +       ret = 4;
10277 +       /* check for broadcast address */
10278 +       if ((tmask & NXA_MOD_BCAST) &&
10279 +               (nxi->v4_bcast.s_addr == addr))
10280 +               goto out;
10281 +       ret = 5;
10282 +       /* check for v4 addresses */
10283 +       for (nxa = &nxi->v4; nxa; nxa = nxa->next)
10284 +               if (v4_addr_match(nxa, addr, tmask))
10285 +                       goto out;
10286 +       ret = 0;
10287 +out:
10288 +       vxdprintk(VXD_CBIT(net, 0),
10289 +               "v4_addr_in_nx_info(%p[#%u]," NIPQUAD_FMT ",%04x) = %d",
10290 +               nxi, nxi ? nxi->nx_id : 0, NIPQUAD(addr), tmask, ret);
10291 +       return ret;
10292 +}
10293 +
10294 +static inline
10295 +int v4_nx_addr_match(struct nx_addr_v4 *nxa, struct nx_addr_v4 *addr, uint16_t mask)
10296 +{
10297 +       /* FIXME: needs full range checks */
10298 +       return v4_addr_match(nxa, addr->ip[0].s_addr, mask);
10299 +}
10300 +
10301 +static inline
10302 +int v4_nx_addr_in_nx_info(struct nx_info *nxi, struct nx_addr_v4 *nxa, uint16_t mask)
10303 +{
10304 +       struct nx_addr_v4 *ptr;
10305 +
10306 +       for (ptr = &nxi->v4; ptr; ptr = ptr->next)
10307 +               if (v4_nx_addr_match(ptr, nxa, mask))
10308 +                       return 1;
10309 +       return 0;
10310 +}
10311 +
10312 +#include <net/inet_sock.h>
10313 +
10314 +/*
10315 + *     Check if a given address matches for a socket
10316 + *
10317 + *     nxi:            the socket's nx_info if any
10318 + *     addr:           to be verified address
10319 + */
10320 +static inline
10321 +int v4_sock_addr_match (
10322 +       struct nx_info *nxi,
10323 +       struct inet_sock *inet,
10324 +       __be32 addr)
10325 +{
10326 +       __be32 saddr = inet->inet_rcv_saddr;
10327 +       __be32 bcast = nxi ? nxi->v4_bcast.s_addr : INADDR_BROADCAST;
10328 +
10329 +       if (addr && (saddr == addr || bcast == addr))
10330 +               return 1;
10331 +       if (!saddr)
10332 +               return v4_addr_in_nx_info(nxi, addr, NXA_MASK_BIND);
10333 +       return 0;
10334 +}
10335 +
10336 +
10337 +/* inet related checks and helpers */
10338 +
10339 +
10340 +struct in_ifaddr;
10341 +struct net_device;
10342 +struct sock;
10343 +
10344 +#ifdef CONFIG_INET
10345 +
10346 +#include <linux/netdevice.h>
10347 +#include <linux/inetdevice.h>
10348 +#include <net/inet_sock.h>
10349 +#include <net/inet_timewait_sock.h>
10350 +
10351 +
10352 +int dev_in_nx_info(struct net_device *, struct nx_info *);
10353 +int v4_dev_in_nx_info(struct net_device *, struct nx_info *);
10354 +int nx_v4_addr_conflict(struct nx_info *, struct nx_info *);
10355 +
10356 +
10357 +/*
10358 + *     check if address is covered by socket
10359 + *
10360 + *     sk:     the socket to check against
10361 + *     addr:   the address in question (must be != 0)
10362 + */
10363 +
10364 +static inline
10365 +int __v4_addr_match_socket(const struct sock *sk, struct nx_addr_v4 *nxa)
10366 +{
10367 +       struct nx_info *nxi = sk->sk_nx_info;
10368 +       __be32 saddr = sk_rcv_saddr(sk);
10369 +
10370 +       vxdprintk(VXD_CBIT(net, 5),
10371 +               "__v4_addr_in_socket(%p," NXAV4_FMT ") %p:" NIPQUAD_FMT " %p;%lx",
10372 +               sk, NXAV4(nxa), nxi, NIPQUAD(saddr), sk->sk_socket,
10373 +               (sk->sk_socket?sk->sk_socket->flags:0));
10374 +
10375 +       if (saddr) {            /* direct address match */
10376 +               return v4_addr_match(nxa, saddr, -1);
10377 +       } else if (nxi) {       /* match against nx_info */
10378 +               return v4_nx_addr_in_nx_info(nxi, nxa, -1);
10379 +       } else {                /* unrestricted any socket */
10380 +               return 1;
10381 +       }
10382 +}
10383 +
10384 +
10385 +
10386 +static inline
10387 +int nx_dev_visible(struct nx_info *nxi, struct net_device *dev)
10388 +{
10389 +       vxdprintk(VXD_CBIT(net, 1),
10390 +               "nx_dev_visible(%p[#%u],%p " VS_Q("%s") ") %d",
10391 +               nxi, nxi ? nxi->nx_id : 0, dev, dev->name,
10392 +               nxi ? dev_in_nx_info(dev, nxi) : 0);
10393 +
10394 +       if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
10395 +               return 1;
10396 +       if (dev_in_nx_info(dev, nxi))
10397 +               return 1;
10398 +       return 0;
10399 +}
10400 +
10401 +
10402 +static inline
10403 +int v4_ifa_in_nx_info(struct in_ifaddr *ifa, struct nx_info *nxi)
10404 +{
10405 +       if (!nxi)
10406 +               return 1;
10407 +       if (!ifa)
10408 +               return 0;
10409 +       return v4_addr_in_nx_info(nxi, ifa->ifa_local, NXA_MASK_SHOW);
10410 +}
10411 +
10412 +static inline
10413 +int nx_v4_ifa_visible(struct nx_info *nxi, struct in_ifaddr *ifa)
10414 +{
10415 +       vxdprintk(VXD_CBIT(net, 1), "nx_v4_ifa_visible(%p[#%u],%p) %d",
10416 +               nxi, nxi ? nxi->nx_id : 0, ifa,
10417 +               nxi ? v4_ifa_in_nx_info(ifa, nxi) : 0);
10418 +
10419 +       if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
10420 +               return 1;
10421 +       if (v4_ifa_in_nx_info(ifa, nxi))
10422 +               return 1;
10423 +       return 0;
10424 +}
10425 +
10426 +
10427 +struct nx_v4_sock_addr {
10428 +       __be32 saddr;   /* Address used for validation */
10429 +       __be32 baddr;   /* Address used for socket bind */
10430 +};
10431 +
10432 +static inline
10433 +int v4_map_sock_addr(struct inet_sock *inet, struct sockaddr_in *addr,
10434 +       struct nx_v4_sock_addr *nsa)
10435 +{
10436 +       struct sock *sk = &inet->sk;
10437 +       struct nx_info *nxi = sk->sk_nx_info;
10438 +       __be32 saddr = addr->sin_addr.s_addr;
10439 +       __be32 baddr = saddr;
10440 +
10441 +       vxdprintk(VXD_CBIT(net, 3),
10442 +               "inet_bind(%p)* %p,%p;%lx " NIPQUAD_FMT,
10443 +               sk, sk->sk_nx_info, sk->sk_socket,
10444 +               (sk->sk_socket ? sk->sk_socket->flags : 0),
10445 +               NIPQUAD(saddr));
10446 +
10447 +       if (nxi) {
10448 +               if (saddr == INADDR_ANY) {
10449 +                       if (nx_info_flags(nxi, NXF_SINGLE_IP, 0))
10450 +                               baddr = nxi->v4.ip[0].s_addr;
10451 +               } else if (saddr == IPI_LOOPBACK) {
10452 +                       if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
10453 +                               baddr = nxi->v4_lback.s_addr;
10454 +               } else {        /* normal address bind */
10455 +                       if (!v4_addr_in_nx_info(nxi, saddr, NXA_MASK_BIND))
10456 +                               return -EADDRNOTAVAIL;
10457 +               }
10458 +       }
10459 +
10460 +       vxdprintk(VXD_CBIT(net, 3),
10461 +               "inet_bind(%p) " NIPQUAD_FMT ", " NIPQUAD_FMT,
10462 +               sk, NIPQUAD(saddr), NIPQUAD(baddr));
10463 +
10464 +       nsa->saddr = saddr;
10465 +       nsa->baddr = baddr;
10466 +       return 0;
10467 +}
10468 +
10469 +static inline
10470 +void v4_set_sock_addr(struct inet_sock *inet, struct nx_v4_sock_addr *nsa)
10471 +{
10472 +       inet->inet_saddr = nsa->baddr;
10473 +       inet->inet_rcv_saddr = nsa->baddr;
10474 +}
10475 +
10476 +
10477 +/*
10478 + *      helper to simplify inet_lookup_listener
10479 + *
10480 + *      nxi:   the socket's nx_info if any
10481 + *      addr:  to be verified address
10482 + *      saddr: socket address
10483 + */
10484 +static inline int v4_inet_addr_match (
10485 +       struct nx_info *nxi,
10486 +       __be32 addr,
10487 +       __be32 saddr)
10488 +{
10489 +       if (addr && (saddr == addr))
10490 +               return 1;
10491 +       if (!saddr)
10492 +               return nxi ? v4_addr_in_nx_info(nxi, addr, NXA_MASK_BIND) : 1;
10493 +       return 0;
10494 +}
10495 +
10496 +static inline __be32 nx_map_sock_lback(struct nx_info *nxi, __be32 addr)
10497 +{
10498 +       if (nx_info_flags(nxi, NXF_HIDE_LBACK, 0) &&
10499 +               (addr == nxi->v4_lback.s_addr))
10500 +               return IPI_LOOPBACK;
10501 +       return addr;
10502 +}
10503 +
10504 +static inline
10505 +int nx_info_has_v4(struct nx_info *nxi)
10506 +{
10507 +       if (!nxi)
10508 +               return 1;
10509 +       if (NX_IPV4(nxi))
10510 +               return 1;
10511 +       if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
10512 +               return 1;
10513 +       return 0;
10514 +}
10515 +
10516 +#else /* CONFIG_INET */
10517 +
10518 +static inline
10519 +int nx_dev_visible(struct nx_info *n, struct net_device *d)
10520 +{
10521 +       return 1;
10522 +}
10523 +
10524 +static inline
10525 +int nx_v4_addr_conflict(struct nx_info *n, uint32_t a, const struct sock *s)
10526 +{
10527 +       return 1;
10528 +}
10529 +
10530 +static inline
10531 +int v4_ifa_in_nx_info(struct in_ifaddr *a, struct nx_info *n)
10532 +{
10533 +       return 1;
10534 +}
10535 +
10536 +static inline
10537 +int nx_info_has_v4(struct nx_info *nxi)
10538 +{
10539 +       return 0;
10540 +}
10541 +
10542 +#endif /* CONFIG_INET */
10543 +
10544 +#define current_nx_info_has_v4() \
10545 +       nx_info_has_v4(current_nx_info())
10546 +
10547 +#else
10548 +// #warning duplicate inclusion
10549 +#endif
10550 diff -NurpP --minimal linux-2.6.38.1/include/linux/vs_inet6.h linux-2.6.38.1-vs2.3.0.37-rc9/include/linux/vs_inet6.h
10551 --- linux-2.6.38.1/include/linux/vs_inet6.h     1970-01-01 01:00:00.000000000 +0100
10552 +++ linux-2.6.38.1-vs2.3.0.37-rc9/include/linux/vs_inet6.h      2011-01-29 02:01:07.000000000 +0100
10553 @@ -0,0 +1,246 @@
10554 +#ifndef _VS_INET6_H
10555 +#define _VS_INET6_H
10556 +
10557 +#include "vserver/base.h"
10558 +#include "vserver/network.h"
10559 +#include "vserver/debug.h"
10560 +
10561 +#include <net/ipv6.h>
10562 +
10563 +#define NXAV6(a)       &(a)->ip, &(a)->mask, (a)->prefix, (a)->type
10564 +#define NXAV6_FMT      "[%pI6/%pI6/%d:%04x]"
10565 +
10566 +
10567 +#ifdef CONFIG_IPV6
10568 +
10569 +static inline
10570 +int v6_addr_match(struct nx_addr_v6 *nxa,
10571 +       const struct in6_addr *addr, uint16_t mask)
10572 +{
10573 +       int ret = 0;
10574 +
10575 +       switch (nxa->type & mask) {
10576 +       case NXA_TYPE_MASK:
10577 +               ret = ipv6_masked_addr_cmp(&nxa->ip, &nxa->mask, addr);
10578 +               break;
10579 +       case NXA_TYPE_ADDR:
10580 +               ret = ipv6_addr_equal(&nxa->ip, addr);
10581 +               break;
10582 +       case NXA_TYPE_ANY:
10583 +               ret = 1;
10584 +               break;
10585 +       }
10586 +       vxdprintk(VXD_CBIT(net, 0),
10587 +               "v6_addr_match(%p" NXAV6_FMT ",%pI6,%04x) = %d",
10588 +               nxa, NXAV6(nxa), addr, mask, ret);
10589 +       return ret;
10590 +}
10591 +
10592 +static inline
10593 +int v6_addr_in_nx_info(struct nx_info *nxi,
10594 +       const struct in6_addr *addr, uint16_t mask)
10595 +{
10596 +       struct nx_addr_v6 *nxa;
10597 +       int ret = 1;
10598 +
10599 +       if (!nxi)
10600 +               goto out;
10601 +       for (nxa = &nxi->v6; nxa; nxa = nxa->next)
10602 +               if (v6_addr_match(nxa, addr, mask))
10603 +                       goto out;
10604 +       ret = 0;
10605 +out:
10606 +       vxdprintk(VXD_CBIT(net, 0),
10607 +               "v6_addr_in_nx_info(%p[#%u],%pI6,%04x) = %d",
10608 +               nxi, nxi ? nxi->nx_id : 0, addr, mask, ret);
10609 +       return ret;
10610 +}
10611 +
10612 +static inline
10613 +int v6_nx_addr_match(struct nx_addr_v6 *nxa, struct nx_addr_v6 *addr, uint16_t mask)
10614 +{
10615 +       /* FIXME: needs full range checks */
10616 +       return v6_addr_match(nxa, &addr->ip, mask);
10617 +}
10618 +
10619 +static inline
10620 +int v6_nx_addr_in_nx_info(struct nx_info *nxi, struct nx_addr_v6 *nxa, uint16_t mask)
10621 +{
10622 +       struct nx_addr_v6 *ptr;
10623 +
10624 +       for (ptr = &nxi->v6; ptr; ptr = ptr->next)
10625 +               if (v6_nx_addr_match(ptr, nxa, mask))
10626 +                       return 1;
10627 +       return 0;
10628 +}
10629 +
10630 +
10631 +/*
10632 + *     Check if a given address matches for a socket
10633 + *
10634 + *     nxi:            the socket's nx_info if any
10635 + *     addr:           to be verified address
10636 + */
10637 +static inline
10638 +int v6_sock_addr_match (
10639 +       struct nx_info *nxi,
10640 +       struct inet_sock *inet,
10641 +       struct in6_addr *addr)
10642 +{
10643 +       struct sock *sk = &inet->sk;
10644 +       struct in6_addr *saddr = inet6_rcv_saddr(sk);
10645 +
10646 +       if (!ipv6_addr_any(addr) &&
10647 +               ipv6_addr_equal(saddr, addr))
10648 +               return 1;
10649 +       if (ipv6_addr_any(saddr))
10650 +               return v6_addr_in_nx_info(nxi, addr, -1);
10651 +       return 0;
10652 +}
10653 +
10654 +/*
10655 + *     check if address is covered by socket
10656 + *
10657 + *     sk:     the socket to check against
10658 + *     addr:   the address in question (must be != 0)
10659 + */
10660 +
10661 +static inline
10662 +int __v6_addr_match_socket(const struct sock *sk, struct nx_addr_v6 *nxa)
10663 +{
10664 +       struct nx_info *nxi = sk->sk_nx_info;
10665 +       struct in6_addr *saddr = inet6_rcv_saddr(sk);
10666 +
10667 +       vxdprintk(VXD_CBIT(net, 5),
10668 +               "__v6_addr_in_socket(%p," NXAV6_FMT ") %p:%pI6 %p;%lx",
10669 +               sk, NXAV6(nxa), nxi, saddr, sk->sk_socket,
10670 +               (sk->sk_socket?sk->sk_socket->flags:0));
10671 +
10672 +       if (!ipv6_addr_any(saddr)) {    /* direct address match */
10673 +               return v6_addr_match(nxa, saddr, -1);
10674 +       } else if (nxi) {               /* match against nx_info */
10675 +               return v6_nx_addr_in_nx_info(nxi, nxa, -1);
10676 +       } else {                        /* unrestricted any socket */
10677 +               return 1;
10678 +       }
10679 +}
10680 +
10681 +
10682 +/* inet related checks and helpers */
10683 +
10684 +
10685 +struct in_ifaddr;
10686 +struct net_device;
10687 +struct sock;
10688 +
10689 +
10690 +#include <linux/netdevice.h>
10691 +#include <linux/inetdevice.h>
10692 +#include <net/inet_timewait_sock.h>
10693 +
10694 +
10695 +int dev_in_nx_info(struct net_device *, struct nx_info *);
10696 +int v6_dev_in_nx_info(struct net_device *, struct nx_info *);
10697 +int nx_v6_addr_conflict(struct nx_info *, struct nx_info *);
10698 +
10699 +
10700 +
10701 +static inline
10702 +int v6_ifa_in_nx_info(struct inet6_ifaddr *ifa, struct nx_info *nxi)
10703 +{
10704 +       if (!nxi)
10705 +               return 1;
10706 +       if (!ifa)
10707 +               return 0;
10708 +       return v6_addr_in_nx_info(nxi, &ifa->addr, -1);
10709 +}
10710 +
10711 +static inline
10712 +int nx_v6_ifa_visible(struct nx_info *nxi, struct inet6_ifaddr *ifa)
10713 +{
10714 +       vxdprintk(VXD_CBIT(net, 1), "nx_v6_ifa_visible(%p[#%u],%p) %d",
10715 +               nxi, nxi ? nxi->nx_id : 0, ifa,
10716 +               nxi ? v6_ifa_in_nx_info(ifa, nxi) : 0);
10717 +
10718 +       if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
10719 +               return 1;
10720 +       if (v6_ifa_in_nx_info(ifa, nxi))
10721 +               return 1;
10722 +       return 0;
10723 +}
10724 +
10725 +
10726 +struct nx_v6_sock_addr {
10727 +       struct in6_addr saddr;  /* Address used for validation */
10728 +       struct in6_addr baddr;  /* Address used for socket bind */
10729 +};
10730 +
10731 +static inline
10732 +int v6_map_sock_addr(struct inet_sock *inet, struct sockaddr_in6 *addr,
10733 +       struct nx_v6_sock_addr *nsa)
10734 +{
10735 +       // struct sock *sk = &inet->sk;
10736 +       // struct nx_info *nxi = sk->sk_nx_info;
10737 +       struct in6_addr saddr = addr->sin6_addr;
10738 +       struct in6_addr baddr = saddr;
10739 +
10740 +       nsa->saddr = saddr;
10741 +       nsa->baddr = baddr;
10742 +       return 0;
10743 +}
10744 +
10745 +static inline
10746 +void v6_set_sock_addr(struct inet_sock *inet, struct nx_v6_sock_addr *nsa)
10747 +{
10748 +       // struct sock *sk = &inet->sk;
10749 +       // struct in6_addr *saddr = inet6_rcv_saddr(sk);
10750 +
10751 +       // *saddr = nsa->baddr;
10752 +       // inet->inet_saddr = nsa->baddr;
10753 +}
10754 +
10755 +static inline
10756 +int nx_info_has_v6(struct nx_info *nxi)
10757 +{
10758 +       if (!nxi)
10759 +               return 1;
10760 +       if (NX_IPV6(nxi))
10761 +               return 1;
10762 +       return 0;
10763 +}
10764 +
10765 +#else /* CONFIG_IPV6 */
10766 +
10767 +static inline
10768 +int nx_v6_dev_visible(struct nx_info *n, struct net_device *d)
10769 +{
10770 +       return 1;
10771 +}
10772 +
10773 +
10774 +static inline
10775 +int nx_v6_addr_conflict(struct nx_info *n, uint32_t a, const struct sock *s)
10776 +{
10777 +       return 1;
10778 +}
10779 +
10780 +static inline
10781 +int v6_ifa_in_nx_info(struct in_ifaddr *a, struct nx_info *n)
10782 +{
10783 +       return 1;
10784 +}
10785 +
10786 +static inline
10787 +int nx_info_has_v6(struct nx_info *nxi)
10788 +{
10789 +       return 0;
10790 +}
10791 +
10792 +#endif /* CONFIG_IPV6 */
10793 +
10794 +#define current_nx_info_has_v6() \
10795 +       nx_info_has_v6(current_nx_info())
10796 +
10797 +#else
10798 +#warning duplicate inclusion
10799 +#endif
10800 diff -NurpP --minimal linux-2.6.38.1/include/linux/vs_limit.h linux-2.6.38.1-vs2.3.0.37-rc9/include/linux/vs_limit.h
10801 --- linux-2.6.38.1/include/linux/vs_limit.h     1970-01-01 01:00:00.000000000 +0100
10802 +++ linux-2.6.38.1-vs2.3.0.37-rc9/include/linux/vs_limit.h      2011-01-29 04:59:22.000000000 +0100
10803 @@ -0,0 +1,140 @@
10804 +#ifndef _VS_LIMIT_H
10805 +#define _VS_LIMIT_H
10806 +
10807 +#include "vserver/limit.h"
10808 +#include "vserver/base.h"
10809 +#include "vserver/context.h"
10810 +#include "vserver/debug.h"
10811 +#include "vserver/context.h"
10812 +#include "vserver/limit_int.h"
10813 +
10814 +
10815 +#define vx_acc_cres(v, d, p, r) \
10816 +       __vx_acc_cres(v, r, d, p, __FILE__, __LINE__)
10817 +
10818 +#define vx_acc_cres_cond(x, d, p, r) \
10819 +       __vx_acc_cres(((x) == vx_current_xid()) ? current_vx_info() : 0, \
10820 +       r, d, p, __FILE__, __LINE__)
10821 +
10822 +
10823 +#define vx_add_cres(v, a, p, r) \
10824 +       __vx_add_cres(v, r, a, p, __FILE__, __LINE__)
10825 +#define vx_sub_cres(v, a, p, r)                vx_add_cres(v, -(a), p, r)
10826 +
10827 +#define vx_add_cres_cond(x, a, p, r) \
10828 +       __vx_add_cres(((x) == vx_current_xid()) ? current_vx_info() : 0, \
10829 +       r, a, p, __FILE__, __LINE__)
10830 +#define vx_sub_cres_cond(x, a, p, r)   vx_add_cres_cond(x, -(a), p, r)
10831 +
10832 +
10833 +/* process and file limits */
10834 +
10835 +#define vx_nproc_inc(p) \
10836 +       vx_acc_cres((p)->vx_info, 1, p, RLIMIT_NPROC)
10837 +
10838 +#define vx_nproc_dec(p) \
10839 +       vx_acc_cres((p)->vx_info,-1, p, RLIMIT_NPROC)
10840 +
10841 +#define vx_files_inc(f) \
10842 +       vx_acc_cres_cond((f)->f_xid, 1, f, RLIMIT_NOFILE)
10843 +
10844 +#define vx_files_dec(f) \
10845 +       vx_acc_cres_cond((f)->f_xid,-1, f, RLIMIT_NOFILE)
10846 +
10847 +#define vx_locks_inc(l) \
10848 +       vx_acc_cres_cond((l)->fl_xid, 1, l, RLIMIT_LOCKS)
10849 +
10850 +#define vx_locks_dec(l) \
10851 +       vx_acc_cres_cond((l)->fl_xid,-1, l, RLIMIT_LOCKS)
10852 +
10853 +#define vx_openfd_inc(f) \
10854 +       vx_acc_cres(current_vx_info(), 1, (void *)(long)(f), VLIMIT_OPENFD)
10855 +
10856 +#define vx_openfd_dec(f) \
10857 +       vx_acc_cres(current_vx_info(),-1, (void *)(long)(f), VLIMIT_OPENFD)
10858 +
10859 +
10860 +#define vx_cres_avail(v, n, r) \
10861 +       __vx_cres_avail(v, r, n, __FILE__, __LINE__)
10862 +
10863 +
10864 +#define vx_nproc_avail(n) \
10865 +       vx_cres_avail(current_vx_info(), n, RLIMIT_NPROC)
10866 +
10867 +#define vx_files_avail(n) \
10868 +       vx_cres_avail(current_vx_info(), n, RLIMIT_NOFILE)
10869 +
10870 +#define vx_locks_avail(n) \
10871 +       vx_cres_avail(current_vx_info(), n, RLIMIT_LOCKS)
10872 +
10873 +#define vx_openfd_avail(n) \
10874 +       vx_cres_avail(current_vx_info(), n, VLIMIT_OPENFD)
10875 +
10876 +
10877 +/* dentry limits */
10878 +
10879 +#define vx_dentry_inc(d) do {                                          \
10880 +       if ((d)->d_count == 1)                                          \
10881 +               vx_acc_cres(current_vx_info(), 1, d, VLIMIT_DENTRY);    \
10882 +       } while (0)
10883 +
10884 +#define vx_dentry_dec(d) do {                                          \
10885 +       if ((d)->d_count == 0)                                          \
10886 +               vx_acc_cres(current_vx_info(),-1, d, VLIMIT_DENTRY);    \
10887 +       } while (0)
10888 +
10889 +#define vx_dentry_avail(n) \
10890 +       vx_cres_avail(current_vx_info(), n, VLIMIT_DENTRY)
10891 +
10892 +
10893 +/* socket limits */
10894 +
10895 +#define vx_sock_inc(s) \
10896 +       vx_acc_cres((s)->sk_vx_info, 1, s, VLIMIT_NSOCK)
10897 +
10898 +#define vx_sock_dec(s) \
10899 +       vx_acc_cres((s)->sk_vx_info,-1, s, VLIMIT_NSOCK)
10900 +
10901 +#define vx_sock_avail(n) \
10902 +       vx_cres_avail(current_vx_info(), n, VLIMIT_NSOCK)
10903 +
10904 +
10905 +/* ipc resource limits */
10906 +
10907 +#define vx_ipcmsg_add(v, u, a) \
10908 +       vx_add_cres(v, a, u, RLIMIT_MSGQUEUE)
10909 +
10910 +#define vx_ipcmsg_sub(v, u, a) \
10911 +       vx_sub_cres(v, a, u, RLIMIT_MSGQUEUE)
10912 +
10913 +#define vx_ipcmsg_avail(v, a) \
10914 +       vx_cres_avail(v, a, RLIMIT_MSGQUEUE)
10915 +
10916 +
10917 +#define vx_ipcshm_add(v, k, a) \
10918 +       vx_add_cres(v, a, (void *)(long)(k), VLIMIT_SHMEM)
10919 +
10920 +#define vx_ipcshm_sub(v, k, a) \
10921 +       vx_sub_cres(v, a, (void *)(long)(k), VLIMIT_SHMEM)
10922 +
10923 +#define vx_ipcshm_avail(v, a) \
10924 +       vx_cres_avail(v, a, VLIMIT_SHMEM)
10925 +
10926 +
10927 +#define vx_semary_inc(a) \
10928 +       vx_acc_cres(current_vx_info(), 1, a, VLIMIT_SEMARY)
10929 +
10930 +#define vx_semary_dec(a) \
10931 +       vx_acc_cres(current_vx_info(), -1, a, VLIMIT_SEMARY)
10932 +
10933 +
10934 +#define vx_nsems_add(a,n) \
10935 +       vx_add_cres(current_vx_info(), n, a, VLIMIT_NSEMS)
10936 +
10937 +#define vx_nsems_sub(a,n) \
10938 +       vx_sub_cres(current_vx_info(), n, a, VLIMIT_NSEMS)
10939 +
10940 +
10941 +#else
10942 +#warning duplicate inclusion
10943 +#endif
10944 diff -NurpP --minimal linux-2.6.38.1/include/linux/vs_memory.h linux-2.6.38.1-vs2.3.0.37-rc9/include/linux/vs_memory.h
10945 --- linux-2.6.38.1/include/linux/vs_memory.h    1970-01-01 01:00:00.000000000 +0100
10946 +++ linux-2.6.38.1-vs2.3.0.37-rc9/include/linux/vs_memory.h     2011-01-29 02:01:07.000000000 +0100
10947 @@ -0,0 +1,58 @@
10948 +#ifndef _VS_MEMORY_H
10949 +#define _VS_MEMORY_H
10950 +
10951 +#include "vserver/limit.h"
10952 +#include "vserver/base.h"
10953 +#include "vserver/context.h"
10954 +#include "vserver/debug.h"
10955 +#include "vserver/context.h"
10956 +#include "vserver/limit_int.h"
10957 +
10958 +enum {
10959 +       VXPT_UNKNOWN = 0,
10960 +       VXPT_ANON,
10961 +       VXPT_NONE,
10962 +       VXPT_FILE,
10963 +       VXPT_SWAP,
10964 +       VXPT_WRITE
10965 +};
10966 +
10967 +#if 0
10968 +#define        vx_page_fault(mm, vma, type, ret)
10969 +#else
10970 +
10971 +static inline
10972 +void __vx_page_fault(struct mm_struct *mm,
10973 +       struct vm_area_struct *vma, int type, int ret)
10974 +{
10975 +       struct vx_info *vxi = mm->mm_vx_info;
10976 +       int what;
10977 +/*
10978 +       static char *page_type[6] =
10979 +               { "UNKNOWN", "ANON", "NONE", "FILE", "SWAP", "WRITE" };
10980 +       static char *page_what[4] =
10981 +               { "FAULT_OOM", "FAULT_SIGBUS", "FAULT_MINOR", "FAULT_MAJOR" };
10982 +*/
10983 +
10984 +       if (!vxi)
10985 +               return;
10986 +
10987 +       what = (ret & 0x3);
10988 +
10989 +/*     printk("[%d] page[%d][%d] %2x %s %s\n", vxi->vx_id,
10990 +               type, what, ret, page_type[type], page_what[what]);
10991 +*/
10992 +       if (ret & VM_FAULT_WRITE)
10993 +               what |= 0x4;
10994 +       atomic_inc(&vxi->cacct.page[type][what]);
10995 +}
10996 +
10997 +#define        vx_page_fault(mm, vma, type, ret)       __vx_page_fault(mm, vma, type, ret)
10998 +#endif
10999 +
11000 +
11001 +extern unsigned long vx_badness(struct task_struct *task, struct mm_struct *mm);
11002 +
11003 +#else
11004 +#warning duplicate inclusion
11005 +#endif
11006 diff -NurpP --minimal linux-2.6.38.1/include/linux/vs_network.h linux-2.6.38.1-vs2.3.0.37-rc9/include/linux/vs_network.h
11007 --- linux-2.6.38.1/include/linux/vs_network.h   1970-01-01 01:00:00.000000000 +0100
11008 +++ linux-2.6.38.1-vs2.3.0.37-rc9/include/linux/vs_network.h    2011-01-29 02:01:07.000000000 +0100
11009 @@ -0,0 +1,169 @@
11010 +#ifndef _NX_VS_NETWORK_H
11011 +#define _NX_VS_NETWORK_H
11012 +
11013 +#include "vserver/context.h"
11014 +#include "vserver/network.h"
11015 +#include "vserver/base.h"
11016 +#include "vserver/check.h"
11017 +#include "vserver/debug.h"
11018 +
11019 +#include <linux/sched.h>
11020 +
11021 +
11022 +#define get_nx_info(i) __get_nx_info(i, __FILE__, __LINE__)
11023 +
11024 +static inline struct nx_info *__get_nx_info(struct nx_info *nxi,
11025 +       const char *_file, int _line)
11026 +{
11027 +       if (!nxi)
11028 +               return NULL;
11029 +
11030 +       vxlprintk(VXD_CBIT(nid, 2), "get_nx_info(%p[#%d.%d])",
11031 +               nxi, nxi ? nxi->nx_id : 0,
11032 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
11033 +               _file, _line);
11034 +
11035 +       atomic_inc(&nxi->nx_usecnt);
11036 +       return nxi;
11037 +}
11038 +
11039 +
11040 +extern void free_nx_info(struct nx_info *);
11041 +
11042 +#define put_nx_info(i) __put_nx_info(i, __FILE__, __LINE__)
11043 +
11044 +static inline void __put_nx_info(struct nx_info *nxi, const char *_file, int _line)
11045 +{
11046 +       if (!nxi)
11047 +               return;
11048 +
11049 +       vxlprintk(VXD_CBIT(nid, 2), "put_nx_info(%p[#%d.%d])",
11050 +               nxi, nxi ? nxi->nx_id : 0,
11051 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
11052 +               _file, _line);
11053 +
11054 +       if (atomic_dec_and_test(&nxi->nx_usecnt))
11055 +               free_nx_info(nxi);
11056 +}
11057 +
11058 +
11059 +#define init_nx_info(p, i) __init_nx_info(p, i, __FILE__, __LINE__)
11060 +
11061 +static inline void __init_nx_info(struct nx_info **nxp, struct nx_info *nxi,
11062 +               const char *_file, int _line)
11063 +{
11064 +       if (nxi) {
11065 +               vxlprintk(VXD_CBIT(nid, 3),
11066 +                       "init_nx_info(%p[#%d.%d])",
11067 +                       nxi, nxi ? nxi->nx_id : 0,
11068 +                       nxi ? atomic_read(&nxi->nx_usecnt) : 0,
11069 +                       _file, _line);
11070 +
11071 +               atomic_inc(&nxi->nx_usecnt);
11072 +       }
11073 +       *nxp = nxi;
11074 +}
11075 +
11076 +
11077 +#define set_nx_info(p, i) __set_nx_info(p, i, __FILE__, __LINE__)
11078 +
11079 +static inline void __set_nx_info(struct nx_info **nxp, struct nx_info *nxi,
11080 +       const char *_file, int _line)
11081 +{
11082 +       struct nx_info *nxo;
11083 +
11084 +       if (!nxi)
11085 +               return;
11086 +
11087 +       vxlprintk(VXD_CBIT(nid, 3), "set_nx_info(%p[#%d.%d])",
11088 +               nxi, nxi ? nxi->nx_id : 0,
11089 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
11090 +               _file, _line);
11091 +
11092 +       atomic_inc(&nxi->nx_usecnt);
11093 +       nxo = xchg(nxp, nxi);
11094 +       BUG_ON(nxo);
11095 +}
11096 +
11097 +#define clr_nx_info(p) __clr_nx_info(p, __FILE__, __LINE__)
11098 +
11099 +static inline void __clr_nx_info(struct nx_info **nxp,
11100 +       const char *_file, int _line)
11101 +{
11102 +       struct nx_info *nxo;
11103 +
11104 +       nxo = xchg(nxp, NULL);
11105 +       if (!nxo)
11106 +               return;
11107 +
11108 +       vxlprintk(VXD_CBIT(nid, 3), "clr_nx_info(%p[#%d.%d])",
11109 +               nxo, nxo ? nxo->nx_id : 0,
11110 +               nxo ? atomic_read(&nxo->nx_usecnt) : 0,
11111 +               _file, _line);
11112 +
11113 +       if (atomic_dec_and_test(&nxo->nx_usecnt))
11114 +               free_nx_info(nxo);
11115 +}
11116 +
11117 +
11118 +#define claim_nx_info(v, p) __claim_nx_info(v, p, __FILE__, __LINE__)
11119 +
11120 +static inline void __claim_nx_info(struct nx_info *nxi,
11121 +       struct task_struct *task, const char *_file, int _line)
11122 +{
11123 +       vxlprintk(VXD_CBIT(nid, 3), "claim_nx_info(%p[#%d.%d.%d]) %p",
11124 +               nxi, nxi ? nxi->nx_id : 0,
11125 +               nxi?atomic_read(&nxi->nx_usecnt):0,
11126 +               nxi?atomic_read(&nxi->nx_tasks):0,
11127 +               task, _file, _line);
11128 +
11129 +       atomic_inc(&nxi->nx_tasks);
11130 +}
11131 +
11132 +
11133 +extern void unhash_nx_info(struct nx_info *);
11134 +
11135 +#define release_nx_info(v, p) __release_nx_info(v, p, __FILE__, __LINE__)
11136 +
11137 +static inline void __release_nx_info(struct nx_info *nxi,
11138 +       struct task_struct *task, const char *_file, int _line)
11139 +{
11140 +       vxlprintk(VXD_CBIT(nid, 3), "release_nx_info(%p[#%d.%d.%d]) %p",
11141 +               nxi, nxi ? nxi->nx_id : 0,
11142 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
11143 +               nxi ? atomic_read(&nxi->nx_tasks) : 0,
11144 +               task, _file, _line);
11145 +
11146 +       might_sleep();
11147 +
11148 +       if (atomic_dec_and_test(&nxi->nx_tasks))
11149 +               unhash_nx_info(nxi);
11150 +}
11151 +
11152 +
11153 +#define task_get_nx_info(i)    __task_get_nx_info(i, __FILE__, __LINE__)
11154 +
11155 +static __inline__ struct nx_info *__task_get_nx_info(struct task_struct *p,
11156 +       const char *_file, int _line)
11157 +{
11158 +       struct nx_info *nxi;
11159 +
11160 +       task_lock(p);
11161 +       vxlprintk(VXD_CBIT(nid, 5), "task_get_nx_info(%p)",
11162 +               p, _file, _line);
11163 +       nxi = __get_nx_info(p->nx_info, _file, _line);
11164 +       task_unlock(p);
11165 +       return nxi;
11166 +}
11167 +
11168 +
11169 +static inline void exit_nx_info(struct task_struct *p)
11170 +{
11171 +       if (p->nx_info)
11172 +               release_nx_info(p->nx_info, p);
11173 +}
11174 +
11175 +
11176 +#else
11177 +#warning duplicate inclusion
11178 +#endif
11179 diff -NurpP --minimal linux-2.6.38.1/include/linux/vs_pid.h linux-2.6.38.1-vs2.3.0.37-rc9/include/linux/vs_pid.h
11180 --- linux-2.6.38.1/include/linux/vs_pid.h       1970-01-01 01:00:00.000000000 +0100
11181 +++ linux-2.6.38.1-vs2.3.0.37-rc9/include/linux/vs_pid.h        2011-03-22 17:43:53.000000000 +0100
11182 @@ -0,0 +1,50 @@
11183 +#ifndef _VS_PID_H
11184 +#define _VS_PID_H
11185 +
11186 +#include "vserver/base.h"
11187 +#include "vserver/check.h"
11188 +#include "vserver/context.h"
11189 +#include "vserver/debug.h"
11190 +#include "vserver/pid.h"
11191 +#include <linux/pid_namespace.h>
11192 +
11193 +
11194 +#define VXF_FAKE_INIT  (VXF_INFO_INIT | VXF_STATE_INIT)
11195 +
11196 +static inline
11197 +int vx_proc_task_visible(struct task_struct *task)
11198 +{
11199 +       if ((task->pid == 1) &&
11200 +               !vx_flags(VXF_FAKE_INIT, VXF_FAKE_INIT))
11201 +               /* show a blend through init */
11202 +               goto visible;
11203 +       if (vx_check(vx_task_xid(task), VS_WATCH | VS_IDENT))
11204 +               goto visible;
11205 +       return 0;
11206 +visible:
11207 +       return 1;
11208 +}
11209 +
11210 +#define find_task_by_real_pid(pid) find_task_by_pid_ns(pid, &init_pid_ns)
11211 +
11212 +
11213 +static inline
11214 +struct task_struct *vx_get_proc_task(struct inode *inode, struct pid *pid)
11215 +{
11216 +       struct task_struct *task = get_pid_task(pid, PIDTYPE_PID);
11217 +
11218 +       if (task && !vx_proc_task_visible(task)) {
11219 +               vxdprintk(VXD_CBIT(misc, 6),
11220 +                       "dropping task (get) %p[#%u,%u] for %p[#%u,%u]",
11221 +                       task, task->xid, task->pid,
11222 +                       current, current->xid, current->pid);
11223 +               put_task_struct(task);
11224 +               task = NULL;
11225 +       }
11226 +       return task;
11227 +}
11228 +
11229 +
11230 +#else
11231 +#warning duplicate inclusion
11232 +#endif
11233 diff -NurpP --minimal linux-2.6.38.1/include/linux/vs_sched.h linux-2.6.38.1-vs2.3.0.37-rc9/include/linux/vs_sched.h
11234 --- linux-2.6.38.1/include/linux/vs_sched.h     1970-01-01 01:00:00.000000000 +0100
11235 +++ linux-2.6.38.1-vs2.3.0.37-rc9/include/linux/vs_sched.h      2011-01-29 02:01:07.000000000 +0100
11236 @@ -0,0 +1,40 @@
11237 +#ifndef _VS_SCHED_H
11238 +#define _VS_SCHED_H
11239 +
11240 +#include "vserver/base.h"
11241 +#include "vserver/context.h"
11242 +#include "vserver/sched.h"
11243 +
11244 +
11245 +#define MAX_PRIO_BIAS           20
11246 +#define MIN_PRIO_BIAS          -20
11247 +
11248 +static inline
11249 +int vx_adjust_prio(struct task_struct *p, int prio, int max_user)
11250 +{
11251 +       struct vx_info *vxi = p->vx_info;
11252 +
11253 +       if (vxi)
11254 +               prio += vx_cpu(vxi, sched_pc).prio_bias;
11255 +       return prio;
11256 +}
11257 +
11258 +static inline void vx_account_user(struct vx_info *vxi,
11259 +       cputime_t cputime, int nice)
11260 +{
11261 +       if (!vxi)
11262 +               return;
11263 +       vx_cpu(vxi, sched_pc).user_ticks += cputime;
11264 +}
11265 +
11266 +static inline void vx_account_system(struct vx_info *vxi,
11267 +       cputime_t cputime, int idle)
11268 +{
11269 +       if (!vxi)
11270 +               return;
11271 +       vx_cpu(vxi, sched_pc).sys_ticks += cputime;
11272 +}
11273 +
11274 +#else
11275 +#warning duplicate inclusion
11276 +#endif
11277 diff -NurpP --minimal linux-2.6.38.1/include/linux/vs_socket.h linux-2.6.38.1-vs2.3.0.37-rc9/include/linux/vs_socket.h
11278 --- linux-2.6.38.1/include/linux/vs_socket.h    1970-01-01 01:00:00.000000000 +0100
11279 +++ linux-2.6.38.1-vs2.3.0.37-rc9/include/linux/vs_socket.h     2011-01-29 02:01:07.000000000 +0100
11280 @@ -0,0 +1,67 @@
11281 +#ifndef _VS_SOCKET_H
11282 +#define _VS_SOCKET_H
11283 +
11284 +#include "vserver/debug.h"
11285 +#include "vserver/base.h"
11286 +#include "vserver/cacct.h"
11287 +#include "vserver/context.h"
11288 +#include "vserver/tag.h"
11289 +
11290 +
11291 +/* socket accounting */
11292 +
11293 +#include <linux/socket.h>
11294 +
11295 +static inline int vx_sock_type(int family)
11296 +{
11297 +       switch (family) {
11298 +       case PF_UNSPEC:
11299 +               return VXA_SOCK_UNSPEC;
11300 +       case PF_UNIX:
11301 +               return VXA_SOCK_UNIX;
11302 +       case PF_INET:
11303 +               return VXA_SOCK_INET;
11304 +       case PF_INET6:
11305 +               return VXA_SOCK_INET6;
11306 +       case PF_PACKET:
11307 +               return VXA_SOCK_PACKET;
11308 +       default:
11309 +               return VXA_SOCK_OTHER;
11310 +       }
11311 +}
11312 +
11313 +#define vx_acc_sock(v, f, p, s) \
11314 +       __vx_acc_sock(v, f, p, s, __FILE__, __LINE__)
11315 +
11316 +static inline void __vx_acc_sock(struct vx_info *vxi,
11317 +       int family, int pos, int size, char *file, int line)
11318 +{
11319 +       if (vxi) {
11320 +               int type = vx_sock_type(family);
11321 +
11322 +               atomic_long_inc(&vxi->cacct.sock[type][pos].count);
11323 +               atomic_long_add(size, &vxi->cacct.sock[type][pos].total);
11324 +       }
11325 +}
11326 +
11327 +#define vx_sock_recv(sk, s) \
11328 +       vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 0, s)
11329 +#define vx_sock_send(sk, s) \
11330 +       vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 1, s)
11331 +#define vx_sock_fail(sk, s) \
11332 +       vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 2, s)
11333 +
11334 +
11335 +#define sock_vx_init(s) do {           \
11336 +       (s)->sk_xid = 0;                \
11337 +       (s)->sk_vx_info = NULL;         \
11338 +       } while (0)
11339 +
11340 +#define sock_nx_init(s) do {           \
11341 +       (s)->sk_nid = 0;                \
11342 +       (s)->sk_nx_info = NULL;         \
11343 +       } while (0)
11344 +
11345 +#else
11346 +#warning duplicate inclusion
11347 +#endif
11348 diff -NurpP --minimal linux-2.6.38.1/include/linux/vs_tag.h linux-2.6.38.1-vs2.3.0.37-rc9/include/linux/vs_tag.h
11349 --- linux-2.6.38.1/include/linux/vs_tag.h       1970-01-01 01:00:00.000000000 +0100
11350 +++ linux-2.6.38.1-vs2.3.0.37-rc9/include/linux/vs_tag.h        2011-01-29 02:01:07.000000000 +0100
11351 @@ -0,0 +1,47 @@
11352 +#ifndef _VS_TAG_H
11353 +#define _VS_TAG_H
11354 +
11355 +#include <linux/vserver/tag.h>
11356 +
11357 +/* check conditions */
11358 +
11359 +#define DX_ADMIN       0x0001
11360 +#define DX_WATCH       0x0002
11361 +#define DX_HOSTID      0x0008
11362 +
11363 +#define DX_IDENT       0x0010
11364 +
11365 +#define DX_ARG_MASK    0x0010
11366 +
11367 +
11368 +#define dx_task_tag(t) ((t)->tag)
11369 +
11370 +#define dx_current_tag() dx_task_tag(current)
11371 +
11372 +#define dx_check(c, m) __dx_check(dx_current_tag(), c, m)
11373 +
11374 +#define dx_weak_check(c, m)    ((m) ? dx_check(c, m) : 1)
11375 +
11376 +
11377 +/*
11378 + * check current context for ADMIN/WATCH and
11379 + * optionally against supplied argument
11380 + */
11381 +static inline int __dx_check(tag_t cid, tag_t id, unsigned int mode)
11382 +{
11383 +       if (mode & DX_ARG_MASK) {
11384 +               if ((mode & DX_IDENT) && (id == cid))
11385 +                       return 1;
11386 +       }
11387 +       return (((mode & DX_ADMIN) && (cid == 0)) ||
11388 +               ((mode & DX_WATCH) && (cid == 1)) ||
11389 +               ((mode & DX_HOSTID) && (id == 0)));
11390 +}
11391 +
11392 +struct inode;
11393 +int dx_permission(const struct inode *inode, int mask);
11394 +
11395 +
11396 +#else
11397 +#warning duplicate inclusion
11398 +#endif
11399 diff -NurpP --minimal linux-2.6.38.1/include/linux/vs_time.h linux-2.6.38.1-vs2.3.0.37-rc9/include/linux/vs_time.h
11400 --- linux-2.6.38.1/include/linux/vs_time.h      1970-01-01 01:00:00.000000000 +0100
11401 +++ linux-2.6.38.1-vs2.3.0.37-rc9/include/linux/vs_time.h       2011-01-29 02:01:07.000000000 +0100
11402 @@ -0,0 +1,19 @@
11403 +#ifndef _VS_TIME_H
11404 +#define _VS_TIME_H
11405 +
11406 +
11407 +/* time faking stuff */
11408 +
11409 +#ifdef CONFIG_VSERVER_VTIME
11410 +
11411 +extern void vx_adjust_timespec(struct timespec *ts);
11412 +extern int vx_settimeofday(struct timespec *ts);
11413 +
11414 +#else
11415 +#define        vx_adjust_timespec(t)   do { } while (0)
11416 +#define        vx_settimeofday(t)      do_settimeofday(t)
11417 +#endif
11418 +
11419 +#else
11420 +#warning duplicate inclusion
11421 +#endif
11422 diff -NurpP --minimal linux-2.6.38.1/include/linux/vserver/Kbuild linux-2.6.38.1-vs2.3.0.37-rc9/include/linux/vserver/Kbuild
11423 --- linux-2.6.38.1/include/linux/vserver/Kbuild 1970-01-01 01:00:00.000000000 +0100
11424 +++ linux-2.6.38.1-vs2.3.0.37-rc9/include/linux/vserver/Kbuild  2011-01-29 02:01:07.000000000 +0100
11425 @@ -0,0 +1,8 @@
11426 +
11427 +unifdef-y += context_cmd.h network_cmd.h space_cmd.h \
11428 +       cacct_cmd.h cvirt_cmd.h limit_cmd.h dlimit_cmd.h \
11429 +       inode_cmd.h tag_cmd.h sched_cmd.h signal_cmd.h \
11430 +       debug_cmd.h device_cmd.h
11431 +
11432 +unifdef-y += switch.h network.h monitor.h inode.h device.h
11433 +
11434 diff -NurpP --minimal linux-2.6.38.1/include/linux/vserver/base.h linux-2.6.38.1-vs2.3.0.37-rc9/include/linux/vserver/base.h
11435 --- linux-2.6.38.1/include/linux/vserver/base.h 1970-01-01 01:00:00.000000000 +0100
11436 +++ linux-2.6.38.1-vs2.3.0.37-rc9/include/linux/vserver/base.h  2011-01-29 02:01:07.000000000 +0100
11437 @@ -0,0 +1,170 @@
11438 +#ifndef _VX_BASE_H
11439 +#define _VX_BASE_H
11440 +
11441 +
11442 +/* context state changes */
11443 +
11444 +enum {
11445 +       VSC_STARTUP = 1,
11446 +       VSC_SHUTDOWN,
11447 +
11448 +       VSC_NETUP,
11449 +       VSC_NETDOWN,
11450 +};
11451 +
11452 +
11453 +
11454 +#define vx_task_xid(t) ((t)->xid)
11455 +
11456 +#define vx_current_xid() vx_task_xid(current)
11457 +
11458 +#define current_vx_info() (current->vx_info)
11459 +
11460 +
11461 +#define nx_task_nid(t) ((t)->nid)
11462 +
11463 +#define nx_current_nid() nx_task_nid(current)
11464 +
11465 +#define current_nx_info() (current->nx_info)
11466 +
11467 +
11468 +/* generic flag merging */
11469 +
11470 +#define vs_check_flags(v, m, f)        (((v) & (m)) ^ (f))
11471 +
11472 +#define vs_mask_flags(v, f, m) (((v) & ~(m)) | ((f) & (m)))
11473 +
11474 +#define vs_mask_mask(v, f, m)  (((v) & ~(m)) | ((v) & (f) & (m)))
11475 +
11476 +#define vs_check_bit(v, n)     ((v) & (1LL << (n)))
11477 +
11478 +
11479 +/* context flags */
11480 +
11481 +#define __vx_flags(v)  ((v) ? (v)->vx_flags : 0)
11482 +
11483 +#define vx_current_flags()     __vx_flags(current_vx_info())
11484 +
11485 +#define vx_info_flags(v, m, f) \
11486 +       vs_check_flags(__vx_flags(v), m, f)
11487 +
11488 +#define task_vx_flags(t, m, f) \
11489 +       ((t) && vx_info_flags((t)->vx_info, m, f))
11490 +
11491 +#define vx_flags(m, f) vx_info_flags(current_vx_info(), m, f)
11492 +
11493 +
11494 +/* context caps */
11495 +
11496 +#define __vx_ccaps(v)  ((v) ? (v)->vx_ccaps : 0)
11497 +
11498 +#define vx_current_ccaps()     __vx_ccaps(current_vx_info())
11499 +
11500 +#define vx_info_ccaps(v, c)    (__vx_ccaps(v) & (c))
11501 +
11502 +#define vx_ccaps(c)    vx_info_ccaps(current_vx_info(), (c))
11503 +
11504 +
11505 +
11506 +/* network flags */
11507 +
11508 +#define __nx_flags(n)  ((n) ? (n)->nx_flags : 0)
11509 +
11510 +#define nx_current_flags()     __nx_flags(current_nx_info())
11511 +
11512 +#define nx_info_flags(n, m, f) \
11513 +       vs_check_flags(__nx_flags(n), m, f)
11514 +
11515 +#define task_nx_flags(t, m, f) \
11516 +       ((t) && nx_info_flags((t)->nx_info, m, f))
11517 +
11518 +#define nx_flags(m, f) nx_info_flags(current_nx_info(), m, f)
11519 +
11520 +
11521 +/* network caps */
11522 +
11523 +#define __nx_ncaps(n)  ((n) ? (n)->nx_ncaps : 0)
11524 +
11525 +#define nx_current_ncaps()     __nx_ncaps(current_nx_info())
11526 +
11527 +#define nx_info_ncaps(n, c)    (__nx_ncaps(n) & (c))
11528 +
11529 +#define nx_ncaps(c)    nx_info_ncaps(current_nx_info(), c)
11530 +
11531 +
11532 +/* context mask capabilities */
11533 +
11534 +#define __vx_mcaps(v)  ((v) ? (v)->vx_ccaps >> 32UL : ~0 )
11535 +
11536 +#define vx_info_mcaps(v, c)    (__vx_mcaps(v) & (c))
11537 +
11538 +#define vx_mcaps(c)    vx_info_mcaps(current_vx_info(), c)
11539 +
11540 +
11541 +/* context bcap mask */
11542 +
11543 +#define __vx_bcaps(v)          ((v)->vx_bcaps)
11544 +
11545 +#define vx_current_bcaps()     __vx_bcaps(current_vx_info())
11546 +
11547 +
11548 +/* mask given bcaps */
11549 +
11550 +#define vx_info_mbcaps(v, c)   ((v) ? cap_intersect(__vx_bcaps(v), c) : c)
11551 +
11552 +#define vx_mbcaps(c)           vx_info_mbcaps(current_vx_info(), c)
11553 +
11554 +
11555 +/* masked cap_bset */
11556 +
11557 +#define vx_info_cap_bset(v)    vx_info_mbcaps(v, current->cap_bset)
11558 +
11559 +#define vx_current_cap_bset()  vx_info_cap_bset(current_vx_info())
11560 +
11561 +#if 0
11562 +#define vx_info_mbcap(v, b) \
11563 +       (!vx_info_flags(v, VXF_STATE_SETUP, 0) ? \
11564 +       vx_info_bcaps(v, b) : (b))
11565 +
11566 +#define task_vx_mbcap(t, b) \
11567 +       vx_info_mbcap((t)->vx_info, (t)->b)
11568 +
11569 +#define vx_mbcap(b)    task_vx_mbcap(current, b)
11570 +#endif
11571 +
11572 +#define vx_cap_raised(v, c, f) cap_raised(vx_info_mbcaps(v, c), f)
11573 +
11574 +#define vx_capable(b, c) (capable(b) || \
11575 +       (cap_raised(current_cap(), b) && vx_ccaps(c)))
11576 +
11577 +#define nx_capable(b, c) (capable(b) || \
11578 +       (cap_raised(current_cap(), b) && nx_ncaps(c)))
11579 +
11580 +#define vx_task_initpid(t, n) \
11581 +       ((t)->vx_info && \
11582 +       ((t)->vx_info->vx_initpid == (n)))
11583 +
11584 +#define vx_current_initpid(n)  vx_task_initpid(current, n)
11585 +
11586 +
11587 +/* context unshare mask */
11588 +
11589 +#define __vx_umask(v)          ((v)->vx_umask)
11590 +
11591 +#define vx_current_umask()     __vx_umask(current_vx_info())
11592 +
11593 +#define vx_can_unshare(b, f) (capable(b) || \
11594 +       (cap_raised(current_cap(), b) && \
11595 +       !((f) & ~vx_current_umask())))
11596 +
11597 +
11598 +#define __vx_state(v)  ((v) ? ((v)->vx_state) : 0)
11599 +
11600 +#define vx_info_state(v, m)    (__vx_state(v) & (m))
11601 +
11602 +
11603 +#define __nx_state(n)  ((n) ? ((n)->nx_state) : 0)
11604 +
11605 +#define nx_info_state(n, m)    (__nx_state(n) & (m))
11606 +
11607 +#endif
11608 diff -NurpP --minimal linux-2.6.38.1/include/linux/vserver/cacct.h linux-2.6.38.1-vs2.3.0.37-rc9/include/linux/vserver/cacct.h
11609 --- linux-2.6.38.1/include/linux/vserver/cacct.h        1970-01-01 01:00:00.000000000 +0100
11610 +++ linux-2.6.38.1-vs2.3.0.37-rc9/include/linux/vserver/cacct.h 2011-01-29 02:01:07.000000000 +0100
11611 @@ -0,0 +1,15 @@
11612 +#ifndef _VX_CACCT_H
11613 +#define _VX_CACCT_H
11614 +
11615 +
11616 +enum sock_acc_field {
11617 +       VXA_SOCK_UNSPEC = 0,
11618 +       VXA_SOCK_UNIX,
11619 +       VXA_SOCK_INET,
11620 +       VXA_SOCK_INET6,
11621 +       VXA_SOCK_PACKET,
11622 +       VXA_SOCK_OTHER,
11623 +       VXA_SOCK_SIZE   /* array size */
11624 +};
11625 +
11626 +#endif /* _VX_CACCT_H */
11627 diff -NurpP --minimal linux-2.6.38.1/include/linux/vserver/cacct_cmd.h linux-2.6.38.1-vs2.3.0.37-rc9/include/linux/vserver/cacct_cmd.h
11628 --- linux-2.6.38.1/include/linux/vserver/cacct_cmd.h    1970-01-01 01:00:00.000000000 +0100
11629 +++ linux-2.6.38.1-vs2.3.0.37-rc9/include/linux/vserver/cacct_cmd.h     2011-01-29 02:01:07.000000000 +0100
11630 @@ -0,0 +1,23 @@
11631 +#ifndef _VX_CACCT_CMD_H
11632 +#define _VX_CACCT_CMD_H
11633 +
11634 +
11635 +/* virtual host info name commands */
11636 +
11637 +#define VCMD_sock_stat         VC_CMD(VSTAT, 5, 0)
11638 +
11639 +struct vcmd_sock_stat_v0 {
11640 +       uint32_t field;
11641 +       uint32_t count[3];
11642 +       uint64_t total[3];
11643 +};
11644 +
11645 +
11646 +#ifdef __KERNEL__
11647 +
11648 +#include <linux/compiler.h>
11649 +
11650 +extern int vc_sock_stat(struct vx_info *, void __user *);
11651 +
11652 +#endif /* __KERNEL__ */
11653 +#endif /* _VX_CACCT_CMD_H */
11654 diff -NurpP --minimal linux-2.6.38.1/include/linux/vserver/cacct_def.h linux-2.6.38.1-vs2.3.0.37-rc9/include/linux/vserver/cacct_def.h
11655 --- linux-2.6.38.1/include/linux/vserver/cacct_def.h    1970-01-01 01:00:00.000000000 +0100
11656 +++ linux-2.6.38.1-vs2.3.0.37-rc9/include/linux/vserver/cacct_def.h     2011-01-29 02:01:07.000000000 +0100
11657 @@ -0,0 +1,43 @@
11658 +#ifndef _VX_CACCT_DEF_H
11659 +#define _VX_CACCT_DEF_H
11660 +
11661 +#include <asm/atomic.h>
11662 +#include <linux/vserver/cacct.h>
11663 +
11664 +
11665 +struct _vx_sock_acc {
11666 +       atomic_long_t count;
11667 +       atomic_long_t total;
11668 +};
11669 +
11670 +/* context sub struct */
11671 +
11672 +struct _vx_cacct {
11673 +       struct _vx_sock_acc sock[VXA_SOCK_SIZE][3];
11674 +       atomic_t slab[8];
11675 +       atomic_t page[6][8];
11676 +};
11677 +
11678 +#ifdef CONFIG_VSERVER_DEBUG
11679 +
11680 +static inline void __dump_vx_cacct(struct _vx_cacct *cacct)
11681 +{
11682 +       int i, j;
11683 +
11684 +       printk("\t_vx_cacct:");
11685 +       for (i = 0; i < 6; i++) {
11686 +               struct _vx_sock_acc *ptr = cacct->sock[i];
11687 +
11688 +               printk("\t [%d] =", i);
11689 +               for (j = 0; j < 3; j++) {
11690 +                       printk(" [%d] = %8lu, %8lu", j,
11691 +                               atomic_long_read(&ptr[j].count),
11692 +                               atomic_long_read(&ptr[j].total));
11693 +               }
11694 +               printk("\n");
11695 +       }
11696 +}
11697 +
11698 +#endif
11699 +
11700 +#endif /* _VX_CACCT_DEF_H */
11701 diff -NurpP --minimal linux-2.6.38.1/include/linux/vserver/cacct_int.h linux-2.6.38.1-vs2.3.0.37-rc9/include/linux/vserver/cacct_int.h
11702 --- linux-2.6.38.1/include/linux/vserver/cacct_int.h    1970-01-01 01:00:00.000000000 +0100
11703 +++ linux-2.6.38.1-vs2.3.0.37-rc9/include/linux/vserver/cacct_int.h     2011-01-29 02:01:07.000000000 +0100
11704 @@ -0,0 +1,21 @@
11705 +#ifndef _VX_CACCT_INT_H
11706 +#define _VX_CACCT_INT_H
11707 +
11708 +
11709 +#ifdef __KERNEL__
11710 +
11711 +static inline
11712 +unsigned long vx_sock_count(struct _vx_cacct *cacct, int type, int pos)
11713 +{
11714 +       return atomic_long_read(&cacct->sock[type][pos].count);
11715 +}
11716 +
11717 +
11718 +static inline
11719 +unsigned long vx_sock_total(struct _vx_cacct *cacct, int type, int pos)
11720 +{
11721 +       return atomic_long_read(&cacct->sock[type][pos].total);
11722 +}
11723 +
11724 +#endif /* __KERNEL__ */
11725 +#endif /* _VX_CACCT_INT_H */
11726 diff -NurpP --minimal linux-2.6.38.1/include/linux/vserver/check.h linux-2.6.38.1-vs2.3.0.37-rc9/include/linux/vserver/check.h
11727 --- linux-2.6.38.1/include/linux/vserver/check.h        1970-01-01 01:00:00.000000000 +0100
11728 +++ linux-2.6.38.1-vs2.3.0.37-rc9/include/linux/vserver/check.h 2011-01-29 02:01:07.000000000 +0100
11729 @@ -0,0 +1,89 @@
11730 +#ifndef _VS_CHECK_H
11731 +#define _VS_CHECK_H
11732 +
11733 +
11734 +#define MAX_S_CONTEXT  65535   /* Arbitrary limit */
11735 +
11736 +#ifdef CONFIG_VSERVER_DYNAMIC_IDS
11737 +#define MIN_D_CONTEXT  49152   /* dynamic contexts start here */
11738 +#else
11739 +#define MIN_D_CONTEXT  65536
11740 +#endif
11741 +
11742 +/* check conditions */
11743 +
11744 +#define VS_ADMIN       0x0001
11745 +#define VS_WATCH       0x0002
11746 +#define VS_HIDE                0x0004
11747 +#define VS_HOSTID      0x0008
11748 +
11749 +#define VS_IDENT       0x0010
11750 +#define VS_EQUIV       0x0020
11751 +#define VS_PARENT      0x0040
11752 +#define VS_CHILD       0x0080
11753 +
11754 +#define VS_ARG_MASK    0x00F0
11755 +
11756 +#define VS_DYNAMIC     0x0100
11757 +#define VS_STATIC      0x0200
11758 +
11759 +#define VS_ATR_MASK    0x0F00
11760 +
11761 +#ifdef CONFIG_VSERVER_PRIVACY
11762 +#define VS_ADMIN_P     (0)
11763 +#define VS_WATCH_P     (0)
11764 +#else
11765 +#define VS_ADMIN_P     VS_ADMIN
11766 +#define VS_WATCH_P     VS_WATCH
11767 +#endif
11768 +
11769 +#define VS_HARDIRQ     0x1000
11770 +#define VS_SOFTIRQ     0x2000
11771 +#define VS_IRQ         0x4000
11772 +
11773 +#define VS_IRQ_MASK    0xF000
11774 +
11775 +#include <linux/hardirq.h>
11776 +
11777 +/*
11778 + * check current context for ADMIN/WATCH and
11779 + * optionally against supplied argument
11780 + */
11781 +static inline int __vs_check(int cid, int id, unsigned int mode)
11782 +{
11783 +       if (mode & VS_ARG_MASK) {
11784 +               if ((mode & VS_IDENT) && (id == cid))
11785 +                       return 1;
11786 +       }
11787 +       if (mode & VS_ATR_MASK) {
11788 +               if ((mode & VS_DYNAMIC) &&
11789 +                       (id >= MIN_D_CONTEXT) &&
11790 +                       (id <= MAX_S_CONTEXT))
11791 +                       return 1;
11792 +               if ((mode & VS_STATIC) &&
11793 +                       (id > 1) && (id < MIN_D_CONTEXT))
11794 +                       return 1;
11795 +       }
11796 +       if (mode & VS_IRQ_MASK) {
11797 +               if ((mode & VS_IRQ) && unlikely(in_interrupt()))
11798 +                       return 1;
11799 +               if ((mode & VS_HARDIRQ) && unlikely(in_irq()))
11800 +                       return 1;
11801 +               if ((mode & VS_SOFTIRQ) && unlikely(in_softirq()))
11802 +                       return 1;
11803 +       }
11804 +       return (((mode & VS_ADMIN) && (cid == 0)) ||
11805 +               ((mode & VS_WATCH) && (cid == 1)) ||
11806 +               ((mode & VS_HOSTID) && (id == 0)));
11807 +}
11808 +
11809 +#define vx_check(c, m) __vs_check(vx_current_xid(), c, (m) | VS_IRQ)
11810 +
11811 +#define vx_weak_check(c, m)    ((m) ? vx_check(c, m) : 1)
11812 +
11813 +
11814 +#define nx_check(c, m) __vs_check(nx_current_nid(), c, m)
11815 +
11816 +#define nx_weak_check(c, m)    ((m) ? nx_check(c, m) : 1)
11817 +
11818 +#endif
11819 diff -NurpP --minimal linux-2.6.38.1/include/linux/vserver/context.h linux-2.6.38.1-vs2.3.0.37-rc9/include/linux/vserver/context.h
11820 --- linux-2.6.38.1/include/linux/vserver/context.h      1970-01-01 01:00:00.000000000 +0100
11821 +++ linux-2.6.38.1-vs2.3.0.37-rc9/include/linux/vserver/context.h       2011-01-31 22:46:21.000000000 +0100
11822 @@ -0,0 +1,189 @@
11823 +#ifndef _VX_CONTEXT_H
11824 +#define _VX_CONTEXT_H
11825 +
11826 +#include <linux/types.h>
11827 +#include <linux/capability.h>
11828 +
11829 +
11830 +/* context flags */
11831 +
11832 +#define VXF_INFO_SCHED         0x00000002
11833 +#define VXF_INFO_NPROC         0x00000004
11834 +#define VXF_INFO_PRIVATE       0x00000008
11835 +
11836 +#define VXF_INFO_INIT          0x00000010
11837 +#define VXF_INFO_HIDE          0x00000020
11838 +#define VXF_INFO_ULIMIT                0x00000040
11839 +#define VXF_INFO_NSPACE                0x00000080
11840 +
11841 +#define VXF_SCHED_HARD         0x00000100
11842 +#define VXF_SCHED_PRIO         0x00000200
11843 +#define VXF_SCHED_PAUSE                0x00000400
11844 +
11845 +#define VXF_VIRT_MEM           0x00010000
11846 +#define VXF_VIRT_UPTIME                0x00020000
11847 +#define VXF_VIRT_CPU           0x00040000
11848 +#define VXF_VIRT_LOAD          0x00080000
11849 +#define VXF_VIRT_TIME          0x00100000
11850 +
11851 +#define VXF_HIDE_MOUNT         0x01000000
11852 +/* was VXF_HIDE_NETIF          0x02000000 */
11853 +#define VXF_HIDE_VINFO         0x04000000
11854 +
11855 +#define VXF_STATE_SETUP                (1ULL << 32)
11856 +#define VXF_STATE_INIT         (1ULL << 33)
11857 +#define VXF_STATE_ADMIN                (1ULL << 34)
11858 +
11859 +#define VXF_SC_HELPER          (1ULL << 36)
11860 +#define VXF_REBOOT_KILL                (1ULL << 37)
11861 +#define VXF_PERSISTENT         (1ULL << 38)
11862 +
11863 +#define VXF_FORK_RSS           (1ULL << 48)
11864 +#define VXF_PROLIFIC           (1ULL << 49)
11865 +
11866 +#define VXF_IGNEG_NICE         (1ULL << 52)
11867 +
11868 +#define VXF_ONE_TIME           (0x0007ULL << 32)
11869 +
11870 +#define VXF_INIT_SET           (VXF_STATE_SETUP | VXF_STATE_INIT | VXF_STATE_ADMIN)
11871 +
11872 +
11873 +/* context migration */
11874 +
11875 +#define VXM_SET_INIT           0x00000001
11876 +#define VXM_SET_REAPER         0x00000002
11877 +
11878 +/* context caps */
11879 +
11880 +#define VXC_CAP_MASK           0x00000000
11881 +
11882 +#define VXC_SET_UTSNAME                0x00000001
11883 +#define VXC_SET_RLIMIT         0x00000002
11884 +#define VXC_FS_SECURITY                0x00000004
11885 +#define VXC_FS_TRUSTED         0x00000008
11886 +#define VXC_TIOCSTI            0x00000010
11887 +
11888 +/* was VXC_RAW_ICMP            0x00000100 */
11889 +#define VXC_SYSLOG             0x00001000
11890 +#define VXC_OOM_ADJUST         0x00002000
11891 +#define VXC_AUDIT_CONTROL      0x00004000
11892 +
11893 +#define VXC_SECURE_MOUNT       0x00010000
11894 +#define VXC_SECURE_REMOUNT     0x00020000
11895 +#define VXC_BINARY_MOUNT       0x00040000
11896 +
11897 +#define VXC_QUOTA_CTL          0x00100000
11898 +#define VXC_ADMIN_MAPPER       0x00200000
11899 +#define VXC_ADMIN_CLOOP                0x00400000
11900 +
11901 +#define VXC_KTHREAD            0x01000000
11902 +#define VXC_NAMESPACE          0x02000000
11903 +
11904 +
11905 +#ifdef __KERNEL__
11906 +
11907 +#include <linux/list.h>
11908 +#include <linux/spinlock.h>
11909 +#include <linux/rcupdate.h>
11910 +
11911 +#include "limit_def.h"
11912 +#include "sched_def.h"
11913 +#include "cvirt_def.h"
11914 +#include "cacct_def.h"
11915 +#include "device_def.h"
11916 +
11917 +#define VX_SPACES      2
11918 +
11919 +struct _vx_info_pc {
11920 +       struct _vx_sched_pc sched_pc;
11921 +       struct _vx_cvirt_pc cvirt_pc;
11922 +};
11923 +
11924 +struct _vx_space {
11925 +       unsigned long vx_nsmask;                /* assignment mask */
11926 +       struct nsproxy *vx_nsproxy;             /* private namespaces */
11927 +       struct fs_struct *vx_fs;                /* private namespace fs */
11928 +       const struct cred *vx_cred;             /* task credentials */
11929 +};
11930 +
11931 +struct vx_info {
11932 +       struct hlist_node vx_hlist;             /* linked list of contexts */
11933 +       xid_t vx_id;                            /* context id */
11934 +       atomic_t vx_usecnt;                     /* usage count */
11935 +       atomic_t vx_tasks;                      /* tasks count */
11936 +       struct vx_info *vx_parent;              /* parent context */
11937 +       int vx_state;                           /* context state */
11938 +
11939 +       struct _vx_space space[VX_SPACES];      /* namespace store */
11940 +
11941 +       uint64_t vx_flags;                      /* context flags */
11942 +       uint64_t vx_ccaps;                      /* context caps (vserver) */
11943 +       kernel_cap_t vx_bcaps;                  /* bounding caps (system) */
11944 +       unsigned long vx_umask;                 /* unshare mask (guest) */
11945 +
11946 +       struct task_struct *vx_reaper;          /* guest reaper process */
11947 +       pid_t vx_initpid;                       /* PID of guest init */
11948 +       int64_t vx_badness_bias;                /* OOM points bias */
11949 +
11950 +       struct _vx_limit limit;                 /* vserver limits */
11951 +       struct _vx_sched sched;                 /* vserver scheduler */
11952 +       struct _vx_cvirt cvirt;                 /* virtual/bias stuff */
11953 +       struct _vx_cacct cacct;                 /* context accounting */
11954 +
11955 +       struct _vx_device dmap;                 /* default device map targets */
11956 +
11957 +#ifndef CONFIG_SMP
11958 +       struct _vx_info_pc info_pc;             /* per cpu data */
11959 +#else
11960 +       struct _vx_info_pc *ptr_pc;             /* per cpu array */
11961 +#endif
11962 +
11963 +       wait_queue_head_t vx_wait;              /* context exit waitqueue */
11964 +       int reboot_cmd;                         /* last sys_reboot() cmd */
11965 +       int exit_code;                          /* last process exit code */
11966 +
11967 +       char vx_name[65];                       /* vserver name */
11968 +};
11969 +
11970 +#ifndef CONFIG_SMP
11971 +#define        vx_ptr_pc(vxi)          (&(vxi)->info_pc)
11972 +#define        vx_per_cpu(vxi, v, id)  vx_ptr_pc(vxi)->v
11973 +#else
11974 +#define        vx_ptr_pc(vxi)          ((vxi)->ptr_pc)
11975 +#define        vx_per_cpu(vxi, v, id)  per_cpu_ptr(vx_ptr_pc(vxi), id)->v
11976 +#endif
11977 +
11978 +#define        vx_cpu(vxi, v)          vx_per_cpu(vxi, v, smp_processor_id())
11979 +
11980 +
11981 +struct vx_info_save {
11982 +       struct vx_info *vxi;
11983 +       xid_t xid;
11984 +};
11985 +
11986 +
11987 +/* status flags */
11988 +
11989 +#define VXS_HASHED     0x0001
11990 +#define VXS_PAUSED     0x0010
11991 +#define VXS_SHUTDOWN   0x0100
11992 +#define VXS_HELPER     0x1000
11993 +#define VXS_RELEASED   0x8000
11994 +
11995 +
11996 +extern void claim_vx_info(struct vx_info *, struct task_struct *);
11997 +extern void release_vx_info(struct vx_info *, struct task_struct *);
11998 +
11999 +extern struct vx_info *lookup_vx_info(int);
12000 +extern struct vx_info *lookup_or_create_vx_info(int);
12001 +
12002 +extern int get_xid_list(int, unsigned int *, int);
12003 +extern int xid_is_hashed(xid_t);
12004 +
12005 +extern int vx_migrate_task(struct task_struct *, struct vx_info *, int);
12006 +
12007 +extern long vs_state_change(struct vx_info *, unsigned int);
12008 +
12009 +
12010 +#endif /* __KERNEL__ */
12011 +#endif /* _VX_CONTEXT_H */
12012 diff -NurpP --minimal linux-2.6.38.1/include/linux/vserver/context_cmd.h linux-2.6.38.1-vs2.3.0.37-rc9/include/linux/vserver/context_cmd.h
12013 --- linux-2.6.38.1/include/linux/vserver/context_cmd.h  1970-01-01 01:00:00.000000000 +0100
12014 +++ linux-2.6.38.1-vs2.3.0.37-rc9/include/linux/vserver/context_cmd.h   2011-01-29 02:01:07.000000000 +0100
12015 @@ -0,0 +1,145 @@
12016 +#ifndef _VX_CONTEXT_CMD_H
12017 +#define _VX_CONTEXT_CMD_H
12018 +
12019 +
12020 +/* vinfo commands */
12021 +
12022 +#define VCMD_task_xid          VC_CMD(VINFO, 1, 0)
12023 +
12024 +#ifdef __KERNEL__
12025 +extern int vc_task_xid(uint32_t);
12026 +
12027 +#endif /* __KERNEL__ */
12028 +
12029 +#define VCMD_vx_info           VC_CMD(VINFO, 5, 0)
12030 +
12031 +struct vcmd_vx_info_v0 {
12032 +       uint32_t xid;
12033 +       uint32_t initpid;
12034 +       /* more to come */
12035 +};
12036 +
12037 +#ifdef __KERNEL__
12038 +extern int vc_vx_info(struct vx_info *, void __user *);
12039 +
12040 +#endif /* __KERNEL__ */
12041 +
12042 +#define VCMD_ctx_stat          VC_CMD(VSTAT, 0, 0)
12043 +
12044 +struct vcmd_ctx_stat_v0 {
12045 +       uint32_t usecnt;
12046 +       uint32_t tasks;
12047 +       /* more to come */
12048 +};
12049 +
12050 +#ifdef __KERNEL__
12051 +extern int vc_ctx_stat(struct vx_info *, void __user *);
12052 +
12053 +#endif /* __KERNEL__ */
12054 +
12055 +/* context commands */
12056 +
12057 +#define VCMD_ctx_create_v0     VC_CMD(VPROC, 1, 0)
12058 +#define VCMD_ctx_create                VC_CMD(VPROC, 1, 1)
12059 +
12060 +struct vcmd_ctx_create {
12061 +       uint64_t flagword;
12062 +};
12063 +
12064 +#define VCMD_ctx_migrate_v0    VC_CMD(PROCMIG, 1, 0)
12065 +#define VCMD_ctx_migrate       VC_CMD(PROCMIG, 1, 1)
12066 +
12067 +struct vcmd_ctx_migrate {
12068 +       uint64_t flagword;
12069 +};
12070 +
12071 +#ifdef __KERNEL__
12072 +extern int vc_ctx_create(uint32_t, void __user *);
12073 +extern int vc_ctx_migrate(struct vx_info *, void __user *);
12074 +
12075 +#endif /* __KERNEL__ */
12076 +
12077 +
12078 +/* flag commands */
12079 +
12080 +#define VCMD_get_cflags                VC_CMD(FLAGS, 1, 0)
12081 +#define VCMD_set_cflags                VC_CMD(FLAGS, 2, 0)
12082 +
12083 +struct vcmd_ctx_flags_v0 {
12084 +       uint64_t flagword;
12085 +       uint64_t mask;
12086 +};
12087 +
12088 +#ifdef __KERNEL__
12089 +extern int vc_get_cflags(struct vx_info *, void __user *);
12090 +extern int vc_set_cflags(struct vx_info *, void __user *);
12091 +
12092 +#endif /* __KERNEL__ */
12093 +
12094 +
12095 +/* context caps commands */
12096 +
12097 +#define VCMD_get_ccaps         VC_CMD(FLAGS, 3, 1)
12098 +#define VCMD_set_ccaps         VC_CMD(FLAGS, 4, 1)
12099 +
12100 +struct vcmd_ctx_caps_v1 {
12101 +       uint64_t ccaps;
12102 +       uint64_t cmask;
12103 +};
12104 +
12105 +#ifdef __KERNEL__
12106 +extern int vc_get_ccaps(struct vx_info *, void __user *);
12107 +extern int vc_set_ccaps(struct vx_info *, void __user *);
12108 +
12109 +#endif /* __KERNEL__ */
12110 +
12111 +
12112 +/* bcaps commands */
12113 +
12114 +#define VCMD_get_bcaps         VC_CMD(FLAGS, 9, 0)
12115 +#define VCMD_set_bcaps         VC_CMD(FLAGS, 10, 0)
12116 +
12117 +struct vcmd_bcaps {
12118 +       uint64_t bcaps;
12119 +       uint64_t bmask;
12120 +};
12121 +
12122 +#ifdef __KERNEL__
12123 +extern int vc_get_bcaps(struct vx_info *, void __user *);
12124 +extern int vc_set_bcaps(struct vx_info *, void __user *);
12125 +
12126 +#endif /* __KERNEL__ */
12127 +
12128 +
12129 +/* umask commands */
12130 +
12131 +#define VCMD_get_umask         VC_CMD(FLAGS, 13, 0)
12132 +#define VCMD_set_umask         VC_CMD(FLAGS, 14, 0)
12133 +
12134 +struct vcmd_umask {
12135 +       uint64_t umask;
12136 +       uint64_t mask;
12137 +};
12138 +
12139 +#ifdef __KERNEL__
12140 +extern int vc_get_umask(struct vx_info *, void __user *);
12141 +extern int vc_set_umask(struct vx_info *, void __user *);
12142 +
12143 +#endif /* __KERNEL__ */
12144 +
12145 +
12146 +/* OOM badness */
12147 +
12148 +#define VCMD_get_badness       VC_CMD(MEMCTRL, 5, 0)
12149 +#define VCMD_set_badness       VC_CMD(MEMCTRL, 6, 0)
12150 +
12151 +struct vcmd_badness_v0 {
12152 +       int64_t bias;
12153 +};
12154 +
12155 +#ifdef __KERNEL__
12156 +extern int vc_get_badness(struct vx_info *, void __user *);
12157 +extern int vc_set_badness(struct vx_info *, void __user *);
12158 +
12159 +#endif /* __KERNEL__ */
12160 +#endif /* _VX_CONTEXT_CMD_H */
12161 diff -NurpP --minimal linux-2.6.38.1/include/linux/vserver/cvirt.h linux-2.6.38.1-vs2.3.0.37-rc9/include/linux/vserver/cvirt.h
12162 --- linux-2.6.38.1/include/linux/vserver/cvirt.h        1970-01-01 01:00:00.000000000 +0100
12163 +++ linux-2.6.38.1-vs2.3.0.37-rc9/include/linux/vserver/cvirt.h 2011-01-29 02:01:07.000000000 +0100
12164 @@ -0,0 +1,20 @@
12165 +#ifndef _VX_CVIRT_H
12166 +#define _VX_CVIRT_H
12167 +
12168 +
12169 +#ifdef __KERNEL__
12170 +
12171 +struct timespec;
12172 +
12173 +void vx_vsi_uptime(struct timespec *, struct timespec *);
12174 +
12175 +
12176 +struct vx_info;
12177 +
12178 +void vx_update_load(struct vx_info *);
12179 +
12180 +
12181 +int vx_do_syslog(int, char __user *, int);
12182 +
12183 +#endif /* __KERNEL__ */
12184 +#endif /* _VX_CVIRT_H */
12185 diff -NurpP --minimal linux-2.6.38.1/include/linux/vserver/cvirt_cmd.h linux-2.6.38.1-vs2.3.0.37-rc9/include/linux/vserver/cvirt_cmd.h
12186 --- linux-2.6.38.1/include/linux/vserver/cvirt_cmd.h    1970-01-01 01:00:00.000000000 +0100
12187 +++ linux-2.6.38.1-vs2.3.0.37-rc9/include/linux/vserver/cvirt_cmd.h     2011-01-29 02:01:07.000000000 +0100
12188 @@ -0,0 +1,53 @@
12189 +#ifndef _VX_CVIRT_CMD_H
12190 +#define _VX_CVIRT_CMD_H
12191 +
12192 +
12193 +/* virtual host info name commands */
12194 +
12195 +#define VCMD_set_vhi_name      VC_CMD(VHOST, 1, 0)
12196 +#define VCMD_get_vhi_name      VC_CMD(VHOST, 2, 0)
12197 +
12198 +struct vcmd_vhi_name_v0 {
12199 +       uint32_t field;
12200 +       char name[65];
12201 +};
12202 +
12203 +
12204 +enum vhi_name_field {
12205 +       VHIN_CONTEXT = 0,
12206 +       VHIN_SYSNAME,
12207 +       VHIN_NODENAME,
12208 +       VHIN_RELEASE,
12209 +       VHIN_VERSION,
12210 +       VHIN_MACHINE,
12211 +       VHIN_DOMAINNAME,
12212 +};
12213 +
12214 +
12215 +#ifdef __KERNEL__
12216 +
12217 +#include <linux/compiler.h>
12218 +
12219 +extern int vc_set_vhi_name(struct vx_info *, void __user *);
12220 +extern int vc_get_vhi_name(struct vx_info *, void __user *);
12221 +
12222 +#endif /* __KERNEL__ */
12223 +
12224 +#define VCMD_virt_stat         VC_CMD(VSTAT, 3, 0)
12225 +
12226 +struct vcmd_virt_stat_v0 {
12227 +       uint64_t offset;
12228 +       uint64_t uptime;
12229 +       uint32_t nr_threads;
12230 +       uint32_t nr_running;
12231 +       uint32_t nr_uninterruptible;
12232 +       uint32_t nr_onhold;
12233 +       uint32_t nr_forks;
12234 +       uint32_t load[3];
12235 +};
12236 +
12237 +#ifdef __KERNEL__
12238 +extern int vc_virt_stat(struct vx_info *, void __user *);
12239 +
12240 +#endif /* __KERNEL__ */
12241 +#endif /* _VX_CVIRT_CMD_H */
12242 diff -NurpP --minimal linux-2.6.38.1/include/linux/vserver/cvirt_def.h linux-2.6.38.1-vs2.3.0.37-rc9/include/linux/vserver/cvirt_def.h
12243 --- linux-2.6.38.1/include/linux/vserver/cvirt_def.h    1970-01-01 01:00:00.000000000 +0100
12244 +++ linux-2.6.38.1-vs2.3.0.37-rc9/include/linux/vserver/cvirt_def.h     2011-01-29 02:01:07.000000000 +0100
12245 @@ -0,0 +1,80 @@
12246 +#ifndef _VX_CVIRT_DEF_H
12247 +#define _VX_CVIRT_DEF_H
12248 +
12249 +#include <linux/jiffies.h>
12250 +#include <linux/spinlock.h>
12251 +#include <linux/wait.h>
12252 +#include <linux/time.h>
12253 +#include <asm/atomic.h>
12254 +
12255 +
12256 +struct _vx_usage_stat {
12257 +       uint64_t user;
12258 +       uint64_t nice;
12259 +       uint64_t system;
12260 +       uint64_t softirq;
12261 +       uint64_t irq;
12262 +       uint64_t idle;
12263 +       uint64_t iowait;
12264 +};
12265 +
12266 +struct _vx_syslog {
12267 +       wait_queue_head_t log_wait;
12268 +       spinlock_t logbuf_lock;         /* lock for the log buffer */
12269 +
12270 +       unsigned long log_start;        /* next char to be read by syslog() */
12271 +       unsigned long con_start;        /* next char to be sent to consoles */
12272 +       unsigned long log_end;  /* most-recently-written-char + 1 */
12273 +       unsigned long logged_chars;     /* #chars since last read+clear operation */
12274 +
12275 +       char log_buf[1024];
12276 +};
12277 +
12278 +
12279 +/* context sub struct */
12280 +
12281 +struct _vx_cvirt {
12282 +       atomic_t nr_threads;            /* number of current threads */
12283 +       atomic_t nr_running;            /* number of running threads */
12284 +       atomic_t nr_uninterruptible;    /* number of uninterruptible threads */
12285 +
12286 +       atomic_t nr_onhold;             /* processes on hold */
12287 +       uint32_t onhold_last;           /* jiffies when put on hold */
12288 +
12289 +       struct timespec bias_ts;        /* time offset to the host */
12290 +       struct timespec bias_idle;
12291 +       struct timespec bias_uptime;    /* context creation point */
12292 +       uint64_t bias_clock;            /* offset in clock_t */
12293 +
12294 +       spinlock_t load_lock;           /* lock for the load averages */
12295 +       atomic_t load_updates;          /* nr of load updates done so far */
12296 +       uint32_t load_last;             /* last time load was calculated */
12297 +       uint32_t load[3];               /* load averages 1,5,15 */
12298 +
12299 +       atomic_t total_forks;           /* number of forks so far */
12300 +
12301 +       struct _vx_syslog syslog;
12302 +};
12303 +
12304 +struct _vx_cvirt_pc {
12305 +       struct _vx_usage_stat cpustat;
12306 +};
12307 +
12308 +
12309 +#ifdef CONFIG_VSERVER_DEBUG
12310 +
12311 +static inline void __dump_vx_cvirt(struct _vx_cvirt *cvirt)
12312 +{
12313 +       printk("\t_vx_cvirt:\n");
12314 +       printk("\t threads: %4d, %4d, %4d, %4d\n",
12315 +               atomic_read(&cvirt->nr_threads),
12316 +               atomic_read(&cvirt->nr_running),
12317 +               atomic_read(&cvirt->nr_uninterruptible),
12318 +               atomic_read(&cvirt->nr_onhold));
12319 +       /* add rest here */
12320 +       printk("\t total_forks = %d\n", atomic_read(&cvirt->total_forks));
12321 +}
12322 +
12323 +#endif
12324 +
12325 +#endif /* _VX_CVIRT_DEF_H */
12326 diff -NurpP --minimal linux-2.6.38.1/include/linux/vserver/debug.h linux-2.6.38.1-vs2.3.0.37-rc9/include/linux/vserver/debug.h
12327 --- linux-2.6.38.1/include/linux/vserver/debug.h        1970-01-01 01:00:00.000000000 +0100
12328 +++ linux-2.6.38.1-vs2.3.0.37-rc9/include/linux/vserver/debug.h 2011-01-29 02:01:07.000000000 +0100
12329 @@ -0,0 +1,140 @@
12330 +#ifndef _VX_DEBUG_H
12331 +#define _VX_DEBUG_H
12332 +
12333 +
12334 +#define VXD_CBIT(n, m) (vx_debug_ ## n & (1 << (m)))
12335 +#define VXD_CMIN(n, m) (vx_debug_ ## n > (m))
12336 +#define VXD_MASK(n, m) (vx_debug_ ## n & (m))
12337 +
12338 +#define VXD_DEV(d)     (d), (d)->bd_inode->i_ino,              \
12339 +                       imajor((d)->bd_inode), iminor((d)->bd_inode)
12340 +#define VXF_DEV                "%p[%lu,%d:%d]"
12341 +
12342 +#if    defined(CONFIG_QUOTES_UTF8)
12343 +#define        VS_Q_LQM        "\xc2\xbb"
12344 +#define        VS_Q_RQM        "\xc2\xab"
12345 +#elif  defined(CONFIG_QUOTES_ASCII)
12346 +#define        VS_Q_LQM        "\x27"
12347 +#define        VS_Q_RQM        "\x27"
12348 +#else
12349 +#define        VS_Q_LQM        "\xbb"
12350 +#define        VS_Q_RQM        "\xab"
12351 +#endif
12352 +
12353 +#define        VS_Q(f)         VS_Q_LQM f VS_Q_RQM
12354 +
12355 +
12356 +#define vxd_path(p)                                            \
12357 +       ({ static char _buffer[PATH_MAX];                       \
12358 +          d_path(p, _buffer, sizeof(_buffer)); })
12359 +
12360 +#define vxd_cond_path(n)                                       \
12361 +       ((n) ? vxd_path(&(n)->path) : "<null>" )
12362 +
12363 +
12364 +#ifdef CONFIG_VSERVER_DEBUG
12365 +
12366 +extern unsigned int vx_debug_switch;
12367 +extern unsigned int vx_debug_xid;
12368 +extern unsigned int vx_debug_nid;
12369 +extern unsigned int vx_debug_tag;
12370 +extern unsigned int vx_debug_net;
12371 +extern unsigned int vx_debug_limit;
12372 +extern unsigned int vx_debug_cres;
12373 +extern unsigned int vx_debug_dlim;
12374 +extern unsigned int vx_debug_quota;
12375 +extern unsigned int vx_debug_cvirt;
12376 +extern unsigned int vx_debug_space;
12377 +extern unsigned int vx_debug_misc;
12378 +
12379 +
12380 +#define VX_LOGLEVEL    "vxD: "
12381 +#define VX_PROC_FMT    "%p: "
12382 +#define VX_PROCESS     current
12383 +
12384 +#define vxdprintk(c, f, x...)                                  \
12385 +       do {                                                    \
12386 +               if (c)                                          \
12387 +                       printk(VX_LOGLEVEL VX_PROC_FMT f "\n",  \
12388 +                               VX_PROCESS , ##x);              \
12389 +       } while (0)
12390 +
12391 +#define vxlprintk(c, f, x...)                                  \
12392 +       do {                                                    \
12393 +               if (c)                                          \
12394 +                       printk(VX_LOGLEVEL f " @%s:%d\n", x);   \
12395 +       } while (0)
12396 +
12397 +#define vxfprintk(c, f, x...)                                  \
12398 +       do {                                                    \
12399 +               if (c)                                          \
12400 +                       printk(VX_LOGLEVEL f " %s@%s:%d\n", x); \
12401 +       } while (0)
12402 +
12403 +
12404 +struct vx_info;
12405 +
12406 +void dump_vx_info(struct vx_info *, int);
12407 +void dump_vx_info_inactive(int);
12408 +
12409 +#else  /* CONFIG_VSERVER_DEBUG */
12410 +
12411 +#define vx_debug_switch 0
12412 +#define vx_debug_xid   0
12413 +#define vx_debug_nid   0
12414 +#define vx_debug_tag   0
12415 +#define vx_debug_net   0
12416 +#define vx_debug_limit 0
12417 +#define vx_debug_cres  0
12418 +#define vx_debug_dlim  0
12419 +#define vx_debug_cvirt 0
12420 +
12421 +#define vxdprintk(x...) do { } while (0)
12422 +#define vxlprintk(x...) do { } while (0)
12423 +#define vxfprintk(x...) do { } while (0)
12424 +
12425 +#endif /* CONFIG_VSERVER_DEBUG */
12426 +
12427 +
12428 +#ifdef CONFIG_VSERVER_WARN
12429 +
12430 +#define VX_WARNLEVEL   KERN_WARNING "vxW: "
12431 +#define VX_WARN_TASK   "[" VS_Q("%s") ",%u:#%u|%u|%u] "
12432 +#define VX_WARN_XID    "[xid #%u] "
12433 +#define VX_WARN_NID    "[nid #%u] "
12434 +#define VX_WARN_TAG    "[tag #%u] "
12435 +
12436 +#define vxwprintk(c, f, x...)                                  \
12437 +       do {                                                    \
12438 +               if (c)                                          \
12439 +                       printk(VX_WARNLEVEL f "\n", ##x);       \
12440 +       } while (0)
12441 +
12442 +#else  /* CONFIG_VSERVER_WARN */
12443 +
12444 +#define vxwprintk(x...) do { } while (0)
12445 +
12446 +#endif /* CONFIG_VSERVER_WARN */
12447 +
12448 +#define vxwprintk_task(c, f, x...)                             \
12449 +       vxwprintk(c, VX_WARN_TASK f,                            \
12450 +               current->comm, current->pid,                    \
12451 +               current->xid, current->nid, current->tag, ##x)
12452 +#define vxwprintk_xid(c, f, x...)                              \
12453 +       vxwprintk(c, VX_WARN_XID f, current->xid, x)
12454 +#define vxwprintk_nid(c, f, x...)                              \
12455 +       vxwprintk(c, VX_WARN_NID f, current->nid, x)
12456 +#define vxwprintk_tag(c, f, x...)                              \
12457 +       vxwprintk(c, VX_WARN_TAG f, current->tag, x)
12458 +
12459 +#ifdef CONFIG_VSERVER_DEBUG
12460 +#define vxd_assert_lock(l)     assert_spin_locked(l)
12461 +#define vxd_assert(c, f, x...) vxlprintk(!(c), \
12462 +       "assertion [" f "] failed.", ##x, __FILE__, __LINE__)
12463 +#else
12464 +#define vxd_assert_lock(l)     do { } while (0)
12465 +#define vxd_assert(c, f, x...) do { } while (0)
12466 +#endif
12467 +
12468 +
12469 +#endif /* _VX_DEBUG_H */
12470 diff -NurpP --minimal linux-2.6.38.1/include/linux/vserver/debug_cmd.h linux-2.6.38.1-vs2.3.0.37-rc9/include/linux/vserver/debug_cmd.h
12471 --- linux-2.6.38.1/include/linux/vserver/debug_cmd.h    1970-01-01 01:00:00.000000000 +0100
12472 +++ linux-2.6.38.1-vs2.3.0.37-rc9/include/linux/vserver/debug_cmd.h     2011-01-29 02:01:07.000000000 +0100
12473 @@ -0,0 +1,58 @@
12474 +#ifndef _VX_DEBUG_CMD_H
12475 +#define _VX_DEBUG_CMD_H
12476 +
12477 +
12478 +/* debug commands */
12479 +
12480 +#define VCMD_dump_history      VC_CMD(DEBUG, 1, 0)
12481 +
12482 +#define VCMD_read_history      VC_CMD(DEBUG, 5, 0)
12483 +#define VCMD_read_monitor      VC_CMD(DEBUG, 6, 0)
12484 +
12485 +struct  vcmd_read_history_v0 {
12486 +       uint32_t index;
12487 +       uint32_t count;
12488 +       char __user *data;
12489 +};
12490 +
12491 +struct  vcmd_read_monitor_v0 {
12492 +       uint32_t index;
12493 +       uint32_t count;
12494 +       char __user *data;
12495 +};
12496 +
12497 +
12498 +#ifdef __KERNEL__
12499 +
12500 +#ifdef CONFIG_COMPAT
12501 +
12502 +#include <asm/compat.h>
12503 +
12504 +struct vcmd_read_history_v0_x32 {
12505 +       uint32_t index;
12506 +       uint32_t count;
12507 +       compat_uptr_t data_ptr;
12508 +};
12509 +
12510 +struct vcmd_read_monitor_v0_x32 {
12511 +       uint32_t index;
12512 +       uint32_t count;
12513 +       compat_uptr_t data_ptr;
12514 +};
12515 +
12516 +#endif  /* CONFIG_COMPAT */
12517 +
12518 +extern int vc_dump_history(uint32_t);
12519 +
12520 +extern int vc_read_history(uint32_t, void __user *);
12521 +extern int vc_read_monitor(uint32_t, void __user *);
12522 +
12523 +#ifdef CONFIG_COMPAT
12524 +
12525 +extern int vc_read_history_x32(uint32_t, void __user *);
12526 +extern int vc_read_monitor_x32(uint32_t, void __user *);
12527 +
12528 +#endif  /* CONFIG_COMPAT */
12529 +
12530 +#endif /* __KERNEL__ */
12531 +#endif /* _VX_DEBUG_CMD_H */
12532 diff -NurpP --minimal linux-2.6.38.1/include/linux/vserver/device.h linux-2.6.38.1-vs2.3.0.37-rc9/include/linux/vserver/device.h
12533 --- linux-2.6.38.1/include/linux/vserver/device.h       1970-01-01 01:00:00.000000000 +0100
12534 +++ linux-2.6.38.1-vs2.3.0.37-rc9/include/linux/vserver/device.h        2011-01-29 02:01:07.000000000 +0100
12535 @@ -0,0 +1,15 @@
12536 +#ifndef _VX_DEVICE_H
12537 +#define _VX_DEVICE_H
12538 +
12539 +
12540 +#define DATTR_CREATE   0x00000001
12541 +#define DATTR_OPEN     0x00000002
12542 +
12543 +#define DATTR_REMAP    0x00000010
12544 +
12545 +#define DATTR_MASK     0x00000013
12546 +
12547 +
12548 +#else  /* _VX_DEVICE_H */
12549 +#warning duplicate inclusion
12550 +#endif /* _VX_DEVICE_H */
12551 diff -NurpP --minimal linux-2.6.38.1/include/linux/vserver/device_cmd.h linux-2.6.38.1-vs2.3.0.37-rc9/include/linux/vserver/device_cmd.h
12552 --- linux-2.6.38.1/include/linux/vserver/device_cmd.h   1970-01-01 01:00:00.000000000 +0100
12553 +++ linux-2.6.38.1-vs2.3.0.37-rc9/include/linux/vserver/device_cmd.h    2011-01-29 02:01:07.000000000 +0100
12554 @@ -0,0 +1,44 @@
12555 +#ifndef _VX_DEVICE_CMD_H
12556 +#define _VX_DEVICE_CMD_H
12557 +
12558 +
12559 +/*  device vserver commands */
12560 +
12561 +#define VCMD_set_mapping       VC_CMD(DEVICE, 1, 0)
12562 +#define VCMD_unset_mapping     VC_CMD(DEVICE, 2, 0)
12563 +
12564 +struct vcmd_set_mapping_v0 {
12565 +       const char __user *device;
12566 +       const char __user *target;
12567 +       uint32_t flags;
12568 +};
12569 +
12570 +
12571 +#ifdef __KERNEL__
12572 +
12573 +#ifdef CONFIG_COMPAT
12574 +
12575 +#include <asm/compat.h>
12576 +
12577 +struct vcmd_set_mapping_v0_x32 {
12578 +       compat_uptr_t device_ptr;
12579 +       compat_uptr_t target_ptr;
12580 +       uint32_t flags;
12581 +};
12582 +
12583 +#endif /* CONFIG_COMPAT */
12584 +
12585 +#include <linux/compiler.h>
12586 +
12587 +extern int vc_set_mapping(struct vx_info *, void __user *);
12588 +extern int vc_unset_mapping(struct vx_info *, void __user *);
12589 +
12590 +#ifdef CONFIG_COMPAT
12591 +
12592 +extern int vc_set_mapping_x32(struct vx_info *, void __user *);
12593 +extern int vc_unset_mapping_x32(struct vx_info *, void __user *);
12594 +
12595 +#endif /* CONFIG_COMPAT */
12596 +
12597 +#endif /* __KERNEL__ */
12598 +#endif /* _VX_DEVICE_CMD_H */
12599 diff -NurpP --minimal linux-2.6.38.1/include/linux/vserver/device_def.h linux-2.6.38.1-vs2.3.0.37-rc9/include/linux/vserver/device_def.h
12600 --- linux-2.6.38.1/include/linux/vserver/device_def.h   1970-01-01 01:00:00.000000000 +0100
12601 +++ linux-2.6.38.1-vs2.3.0.37-rc9/include/linux/vserver/device_def.h    2011-01-29 02:01:07.000000000 +0100
12602 @@ -0,0 +1,17 @@
12603 +#ifndef _VX_DEVICE_DEF_H
12604 +#define _VX_DEVICE_DEF_H
12605 +
12606 +#include <linux/types.h>
12607 +
12608 +struct vx_dmap_target {
12609 +       dev_t target;
12610 +       uint32_t flags;
12611 +};
12612 +
12613 +struct _vx_device {
12614 +#ifdef CONFIG_VSERVER_DEVICE
12615 +       struct vx_dmap_target targets[2];
12616 +#endif
12617 +};
12618 +
12619 +#endif /* _VX_DEVICE_DEF_H */
12620 diff -NurpP --minimal linux-2.6.38.1/include/linux/vserver/dlimit.h linux-2.6.38.1-vs2.3.0.37-rc9/include/linux/vserver/dlimit.h
12621 --- linux-2.6.38.1/include/linux/vserver/dlimit.h       1970-01-01 01:00:00.000000000 +0100
12622 +++ linux-2.6.38.1-vs2.3.0.37-rc9/include/linux/vserver/dlimit.h        2011-01-29 02:01:07.000000000 +0100
12623 @@ -0,0 +1,54 @@
12624 +#ifndef _VX_DLIMIT_H
12625 +#define _VX_DLIMIT_H
12626 +
12627 +#include "switch.h"
12628 +
12629 +
12630 +#ifdef __KERNEL__
12631 +
12632 +/*      keep in sync with CDLIM_INFINITY       */
12633 +
12634 +#define DLIM_INFINITY          (~0ULL)
12635 +
12636 +#include <linux/spinlock.h>
12637 +#include <linux/rcupdate.h>
12638 +
12639 +struct super_block;
12640 +
12641 +struct dl_info {
12642 +       struct hlist_node dl_hlist;             /* linked list of contexts */
12643 +       struct rcu_head dl_rcu;                 /* the rcu head */
12644 +       tag_t dl_tag;                           /* context tag */
12645 +       atomic_t dl_usecnt;                     /* usage count */
12646 +       atomic_t dl_refcnt;                     /* reference count */
12647 +
12648 +       struct super_block *dl_sb;              /* associated superblock */
12649 +
12650 +       spinlock_t dl_lock;                     /* protect the values */
12651 +
12652 +       unsigned long long dl_space_used;       /* used space in bytes */
12653 +       unsigned long long dl_space_total;      /* maximum space in bytes */
12654 +       unsigned long dl_inodes_used;           /* used inodes */
12655 +       unsigned long dl_inodes_total;          /* maximum inodes */
12656 +
12657 +       unsigned int dl_nrlmult;                /* non root limit mult */
12658 +};
12659 +
12660 +struct rcu_head;
12661 +
12662 +extern void rcu_free_dl_info(struct rcu_head *);
12663 +extern void unhash_dl_info(struct dl_info *);
12664 +
12665 +extern struct dl_info *locate_dl_info(struct super_block *, tag_t);
12666 +
12667 +
12668 +struct kstatfs;
12669 +
12670 +extern void vx_vsi_statfs(struct super_block *, struct kstatfs *);
12671 +
12672 +typedef uint64_t dlsize_t;
12673 +
12674 +#endif /* __KERNEL__ */
12675 +#else  /* _VX_DLIMIT_H */
12676 +#warning duplicate inclusion
12677 +#endif /* _VX_DLIMIT_H */
12678 diff -NurpP --minimal linux-2.6.38.1/include/linux/vserver/dlimit_cmd.h linux-2.6.38.1-vs2.3.0.37-rc9/include/linux/vserver/dlimit_cmd.h
12679 --- linux-2.6.38.1/include/linux/vserver/dlimit_cmd.h   1970-01-01 01:00:00.000000000 +0100
12680 +++ linux-2.6.38.1-vs2.3.0.37-rc9/include/linux/vserver/dlimit_cmd.h    2011-01-29 02:01:07.000000000 +0100
12681 @@ -0,0 +1,109 @@
12682 +#ifndef _VX_DLIMIT_CMD_H
12683 +#define _VX_DLIMIT_CMD_H
12684 +
12685 +
12686 +/*  dlimit vserver commands */
12687 +
12688 +#define VCMD_add_dlimit                VC_CMD(DLIMIT, 1, 0)
12689 +#define VCMD_rem_dlimit                VC_CMD(DLIMIT, 2, 0)
12690 +
12691 +#define VCMD_set_dlimit                VC_CMD(DLIMIT, 5, 0)
12692 +#define VCMD_get_dlimit                VC_CMD(DLIMIT, 6, 0)
12693 +
12694 +struct vcmd_ctx_dlimit_base_v0 {
12695 +       const char __user *name;
12696 +       uint32_t flags;
12697 +};
12698 +
12699 +struct vcmd_ctx_dlimit_v0 {
12700 +       const char __user *name;
12701 +       uint32_t space_used;                    /* used space in kbytes */
12702 +       uint32_t space_total;                   /* maximum space in kbytes */
12703 +       uint32_t inodes_used;                   /* used inodes */
12704 +       uint32_t inodes_total;                  /* maximum inodes */
12705 +       uint32_t reserved;                      /* reserved for root in % */
12706 +       uint32_t flags;
12707 +};
12708 +
12709 +#define CDLIM_UNSET            ((uint32_t)0UL)
12710 +#define CDLIM_INFINITY         ((uint32_t)~0UL)
12711 +#define CDLIM_KEEP             ((uint32_t)~1UL)
12712 +
12713 +#define DLIME_UNIT     0
12714 +#define DLIME_KILO     1
12715 +#define DLIME_MEGA     2
12716 +#define DLIME_GIGA     3
12717 +
12718 +#define DLIMF_SHIFT    0x10
12719 +
12720 +#define DLIMS_USED     0
12721 +#define DLIMS_TOTAL    2
12722 +
12723 +static inline
12724 +uint64_t dlimit_space_32to64(uint32_t val, uint32_t flags, int shift)
12725 +{
12726 +       int exp = (flags & DLIMF_SHIFT) ?
12727 +               (flags >> shift) & DLIME_GIGA : DLIME_KILO;
12728 +       return ((uint64_t)val) << (10 * exp);
12729 +}
12730 +
12731 +static inline
12732 +uint32_t dlimit_space_64to32(uint64_t val, uint32_t *flags, int shift)
12733 +{
12734 +       int exp = 0;
12735 +
12736 +       if (*flags & DLIMF_SHIFT) {
12737 +               while (val > (1LL << 32) && (exp < 3)) {
12738 +                       val >>= 10;
12739 +                       exp++;
12740 +               }
12741 +               *flags &= ~(DLIME_GIGA << shift);
12742 +               *flags |= exp << shift;
12743 +       } else
12744 +               val >>= 10;
12745 +       return val;
12746 +}
12747 +
12748 +#ifdef __KERNEL__
12749 +
12750 +#ifdef CONFIG_COMPAT
12751 +
12752 +#include <asm/compat.h>
12753 +
12754 +struct vcmd_ctx_dlimit_base_v0_x32 {
12755 +       compat_uptr_t name_ptr;
12756 +       uint32_t flags;
12757 +};
12758 +
12759 +struct vcmd_ctx_dlimit_v0_x32 {
12760 +       compat_uptr_t name_ptr;
12761 +       uint32_t space_used;                    /* used space in kbytes */
12762 +       uint32_t space_total;                   /* maximum space in kbytes */
12763 +       uint32_t inodes_used;                   /* used inodes */
12764 +       uint32_t inodes_total;                  /* maximum inodes */
12765 +       uint32_t reserved;                      /* reserved for root in % */
12766 +       uint32_t flags;
12767 +};
12768 +
12769 +#endif /* CONFIG_COMPAT */
12770 +
12771 +#include <linux/compiler.h>
12772 +
12773 +extern int vc_add_dlimit(uint32_t, void __user *);
12774 +extern int vc_rem_dlimit(uint32_t, void __user *);
12775 +
12776 +extern int vc_set_dlimit(uint32_t, void __user *);
12777 +extern int vc_get_dlimit(uint32_t, void __user *);
12778 +
12779 +#ifdef CONFIG_COMPAT
12780 +
12781 +extern int vc_add_dlimit_x32(uint32_t, void __user *);
12782 +extern int vc_rem_dlimit_x32(uint32_t, void __user *);
12783 +
12784 +extern int vc_set_dlimit_x32(uint32_t, void __user *);
12785 +extern int vc_get_dlimit_x32(uint32_t, void __user *);
12786 +
12787 +#endif /* CONFIG_COMPAT */
12788 +
12789 +#endif /* __KERNEL__ */
12790 +#endif /* _VX_DLIMIT_CMD_H */
12791 diff -NurpP --minimal linux-2.6.38.1/include/linux/vserver/global.h linux-2.6.38.1-vs2.3.0.37-rc9/include/linux/vserver/global.h
12792 --- linux-2.6.38.1/include/linux/vserver/global.h       1970-01-01 01:00:00.000000000 +0100
12793 +++ linux-2.6.38.1-vs2.3.0.37-rc9/include/linux/vserver/global.h        2011-01-29 02:01:07.000000000 +0100
12794 @@ -0,0 +1,19 @@
12795 +#ifndef _VX_GLOBAL_H
12796 +#define _VX_GLOBAL_H
12797 +
12798 +
12799 +extern atomic_t vx_global_ctotal;
12800 +extern atomic_t vx_global_cactive;
12801 +
12802 +extern atomic_t nx_global_ctotal;
12803 +extern atomic_t nx_global_cactive;
12804 +
12805 +extern atomic_t vs_global_nsproxy;
12806 +extern atomic_t vs_global_fs;
12807 +extern atomic_t vs_global_mnt_ns;
12808 +extern atomic_t vs_global_uts_ns;
12809 +extern atomic_t vs_global_user_ns;
12810 +extern atomic_t vs_global_pid_ns;
12811 +
12812 +
12813 +#endif /* _VX_GLOBAL_H */
12814 diff -NurpP --minimal linux-2.6.38.1/include/linux/vserver/history.h linux-2.6.38.1-vs2.3.0.37-rc9/include/linux/vserver/history.h
12815 --- linux-2.6.38.1/include/linux/vserver/history.h      1970-01-01 01:00:00.000000000 +0100
12816 +++ linux-2.6.38.1-vs2.3.0.37-rc9/include/linux/vserver/history.h       2011-01-29 02:01:07.000000000 +0100
12817 @@ -0,0 +1,197 @@
12818 +#ifndef _VX_HISTORY_H
12819 +#define _VX_HISTORY_H
12820 +
12821 +
12822 +enum {
12823 +       VXH_UNUSED = 0,
12824 +       VXH_THROW_OOPS = 1,
12825 +
12826 +       VXH_GET_VX_INFO,
12827 +       VXH_PUT_VX_INFO,
12828 +       VXH_INIT_VX_INFO,
12829 +       VXH_SET_VX_INFO,
12830 +       VXH_CLR_VX_INFO,
12831 +       VXH_CLAIM_VX_INFO,
12832 +       VXH_RELEASE_VX_INFO,
12833 +       VXH_ALLOC_VX_INFO,
12834 +       VXH_DEALLOC_VX_INFO,
12835 +       VXH_HASH_VX_INFO,
12836 +       VXH_UNHASH_VX_INFO,
12837 +       VXH_LOC_VX_INFO,
12838 +       VXH_LOOKUP_VX_INFO,
12839 +       VXH_CREATE_VX_INFO,
12840 +};
12841 +
12842 +struct _vxhe_vxi {
12843 +       struct vx_info *ptr;
12844 +       unsigned xid;
12845 +       unsigned usecnt;
12846 +       unsigned tasks;
12847 +};
12848 +
12849 +struct _vxhe_set_clr {
12850 +       void *data;
12851 +};
12852 +
12853 +struct _vxhe_loc_lookup {
12854 +       unsigned arg;
12855 +};
12856 +
12857 +struct _vx_hist_entry {
12858 +       void *loc;
12859 +       unsigned short seq;
12860 +       unsigned short type;
12861 +       struct _vxhe_vxi vxi;
12862 +       union {
12863 +               struct _vxhe_set_clr sc;
12864 +               struct _vxhe_loc_lookup ll;
12865 +       };
12866 +};
12867 +
12868 +#ifdef CONFIG_VSERVER_HISTORY
12869 +
12870 +extern unsigned volatile int vxh_active;
12871 +
12872 +struct _vx_hist_entry *vxh_advance(void *loc);
12873 +
12874 +
12875 +static inline
12876 +void   __vxh_copy_vxi(struct _vx_hist_entry *entry, struct vx_info *vxi)
12877 +{
12878 +       entry->vxi.ptr = vxi;
12879 +       if (vxi) {
12880 +               entry->vxi.usecnt = atomic_read(&vxi->vx_usecnt);
12881 +               entry->vxi.tasks = atomic_read(&vxi->vx_tasks);
12882 +               entry->vxi.xid = vxi->vx_id;
12883 +       }
12884 +}
12885 +
12886 +
12887 +#define        __HERE__ current_text_addr()
12888 +
12889 +#define __VXH_BODY(__type, __data, __here)     \
12890 +       struct _vx_hist_entry *entry;           \
12891 +                                               \
12892 +       preempt_disable();                      \
12893 +       entry = vxh_advance(__here);            \
12894 +       __data;                                 \
12895 +       entry->type = __type;                   \
12896 +       preempt_enable();
12897 +
12898 +
12899 +       /* pass vxi only */
12900 +
12901 +#define __VXH_SMPL                             \
12902 +       __vxh_copy_vxi(entry, vxi)
12903 +
12904 +static inline
12905 +void   __vxh_smpl(struct vx_info *vxi, int __type, void *__here)
12906 +{
12907 +       __VXH_BODY(__type, __VXH_SMPL, __here)
12908 +}
12909 +
12910 +       /* pass vxi and data (void *) */
12911 +
12912 +#define __VXH_DATA                             \
12913 +       __vxh_copy_vxi(entry, vxi);             \
12914 +       entry->sc.data = data
12915 +
12916 +static inline
12917 +void   __vxh_data(struct vx_info *vxi, void *data,
12918 +                       int __type, void *__here)
12919 +{
12920 +       __VXH_BODY(__type, __VXH_DATA, __here)
12921 +}
12922 +
12923 +       /* pass vxi and arg (long) */
12924 +
12925 +#define __VXH_LONG                             \
12926 +       __vxh_copy_vxi(entry, vxi);             \
12927 +       entry->ll.arg = arg
12928 +
12929 +static inline
12930 +void   __vxh_long(struct vx_info *vxi, long arg,
12931 +                       int __type, void *__here)
12932 +{
12933 +       __VXH_BODY(__type, __VXH_LONG, __here)
12934 +}
12935 +
12936 +
12937 +static inline
12938 +void   __vxh_throw_oops(void *__here)
12939 +{
12940 +       __VXH_BODY(VXH_THROW_OOPS, {}, __here);
12941 +       /* prevent further acquisition */
12942 +       vxh_active = 0;
12943 +}
12944 +
12945 +
12946 +#define vxh_throw_oops()       __vxh_throw_oops(__HERE__);
12947 +
12948 +#define __vxh_get_vx_info(v, h)        __vxh_smpl(v, VXH_GET_VX_INFO, h);
12949 +#define __vxh_put_vx_info(v, h)        __vxh_smpl(v, VXH_PUT_VX_INFO, h);
12950 +
12951 +#define __vxh_init_vx_info(v, d, h) \
12952 +       __vxh_data(v, d, VXH_INIT_VX_INFO, h);
12953 +#define __vxh_set_vx_info(v, d, h) \
12954 +       __vxh_data(v, d, VXH_SET_VX_INFO, h);
12955 +#define __vxh_clr_vx_info(v, d, h) \
12956 +       __vxh_data(v, d, VXH_CLR_VX_INFO, h);
12957 +
12958 +#define __vxh_claim_vx_info(v, d, h) \
12959 +       __vxh_data(v, d, VXH_CLAIM_VX_INFO, h);
12960 +#define __vxh_release_vx_info(v, d, h) \
12961 +       __vxh_data(v, d, VXH_RELEASE_VX_INFO, h);
12962 +
12963 +#define vxh_alloc_vx_info(v) \
12964 +       __vxh_smpl(v, VXH_ALLOC_VX_INFO, __HERE__);
12965 +#define vxh_dealloc_vx_info(v) \
12966 +       __vxh_smpl(v, VXH_DEALLOC_VX_INFO, __HERE__);
12967 +
12968 +#define vxh_hash_vx_info(v) \
12969 +       __vxh_smpl(v, VXH_HASH_VX_INFO, __HERE__);
12970 +#define vxh_unhash_vx_info(v) \
12971 +       __vxh_smpl(v, VXH_UNHASH_VX_INFO, __HERE__);
12972 +
12973 +#define vxh_loc_vx_info(v, l) \
12974 +       __vxh_long(v, l, VXH_LOC_VX_INFO, __HERE__);
12975 +#define vxh_lookup_vx_info(v, l) \
12976 +       __vxh_long(v, l, VXH_LOOKUP_VX_INFO, __HERE__);
12977 +#define vxh_create_vx_info(v, l) \
12978 +       __vxh_long(v, l, VXH_CREATE_VX_INFO, __HERE__);
12979 +
12980 +extern void vxh_dump_history(void);
12981 +
12982 +
12983 +#else  /* CONFIG_VSERVER_HISTORY */
12984 +
12985 +#define        __HERE__        0
12986 +
12987 +#define vxh_throw_oops()               do { } while (0)
12988 +
12989 +#define __vxh_get_vx_info(v, h)                do { } while (0)
12990 +#define __vxh_put_vx_info(v, h)                do { } while (0)
12991 +
12992 +#define __vxh_init_vx_info(v, d, h)    do { } while (0)
12993 +#define __vxh_set_vx_info(v, d, h)     do { } while (0)
12994 +#define __vxh_clr_vx_info(v, d, h)     do { } while (0)
12995 +
12996 +#define __vxh_claim_vx_info(v, d, h)   do { } while (0)
12997 +#define __vxh_release_vx_info(v, d, h) do { } while (0)
12998 +
12999 +#define vxh_alloc_vx_info(v)           do { } while (0)
13000 +#define vxh_dealloc_vx_info(v)         do { } while (0)
13001 +
13002 +#define vxh_hash_vx_info(v)            do { } while (0)
13003 +#define vxh_unhash_vx_info(v)          do { } while (0)
13004 +
13005 +#define vxh_loc_vx_info(v, l)          do { } while (0)
13006 +#define vxh_lookup_vx_info(v, l)       do { } while (0)
13007 +#define vxh_create_vx_info(v, l)       do { } while (0)
13008 +
13009 +#define vxh_dump_history()             do { } while (0)
13010 +
13011 +
13012 +#endif /* CONFIG_VSERVER_HISTORY */
13013 +
13014 +#endif /* _VX_HISTORY_H */
13015 diff -NurpP --minimal linux-2.6.38.1/include/linux/vserver/inode.h linux-2.6.38.1-vs2.3.0.37-rc9/include/linux/vserver/inode.h
13016 --- linux-2.6.38.1/include/linux/vserver/inode.h        1970-01-01 01:00:00.000000000 +0100
13017 +++ linux-2.6.38.1-vs2.3.0.37-rc9/include/linux/vserver/inode.h 2011-01-29 02:01:07.000000000 +0100
13018 @@ -0,0 +1,39 @@
13019 +#ifndef _VX_INODE_H
13020 +#define _VX_INODE_H
13021 +
13022 +
13023 +#define IATTR_TAG      0x01000000
13024 +
13025 +#define IATTR_ADMIN    0x00000001
13026 +#define IATTR_WATCH    0x00000002
13027 +#define IATTR_HIDE     0x00000004
13028 +#define IATTR_FLAGS    0x00000007
13029 +
13030 +#define IATTR_BARRIER  0x00010000
13031 +#define IATTR_IXUNLINK 0x00020000
13032 +#define IATTR_IMMUTABLE 0x00040000
13033 +#define IATTR_COW      0x00080000
13034 +
13035 +#ifdef __KERNEL__
13036 +
13037 +
13038 +#ifdef CONFIG_VSERVER_PROC_SECURE
13039 +#define IATTR_PROC_DEFAULT     ( IATTR_ADMIN | IATTR_HIDE )
13040 +#define IATTR_PROC_SYMLINK     ( IATTR_ADMIN )
13041 +#else
13042 +#define IATTR_PROC_DEFAULT     ( IATTR_ADMIN )
13043 +#define IATTR_PROC_SYMLINK     ( IATTR_ADMIN )
13044 +#endif
13045 +
13046 +#define vx_hide_check(c, m)    (((m) & IATTR_HIDE) ? vx_check(c, m) : 1)
13047 +
13048 +#endif /* __KERNEL__ */
13049 +
13050 +/* inode ioctls */
13051 +
13052 +#define FIOC_GETXFLG   _IOR('x', 5, long)
13053 +#define FIOC_SETXFLG   _IOW('x', 6, long)
13054 +
13055 +#else  /* _VX_INODE_H */
13056 +#warning duplicate inclusion
13057 +#endif /* _VX_INODE_H */
13058 diff -NurpP --minimal linux-2.6.38.1/include/linux/vserver/inode_cmd.h linux-2.6.38.1-vs2.3.0.37-rc9/include/linux/vserver/inode_cmd.h
13059 --- linux-2.6.38.1/include/linux/vserver/inode_cmd.h    1970-01-01 01:00:00.000000000 +0100
13060 +++ linux-2.6.38.1-vs2.3.0.37-rc9/include/linux/vserver/inode_cmd.h     2011-01-29 02:01:07.000000000 +0100
13061 @@ -0,0 +1,59 @@
13062 +#ifndef _VX_INODE_CMD_H
13063 +#define _VX_INODE_CMD_H
13064 +
13065 +
13066 +/*  inode vserver commands */
13067 +
13068 +#define VCMD_get_iattr         VC_CMD(INODE, 1, 1)
13069 +#define VCMD_set_iattr         VC_CMD(INODE, 2, 1)
13070 +
13071 +#define VCMD_fget_iattr                VC_CMD(INODE, 3, 0)
13072 +#define VCMD_fset_iattr                VC_CMD(INODE, 4, 0)
13073 +
13074 +struct vcmd_ctx_iattr_v1 {
13075 +       const char __user *name;
13076 +       uint32_t tag;
13077 +       uint32_t flags;
13078 +       uint32_t mask;
13079 +};
13080 +
13081 +struct vcmd_ctx_fiattr_v0 {
13082 +       uint32_t tag;
13083 +       uint32_t flags;
13084 +       uint32_t mask;
13085 +};
13086 +
13087 +
13088 +#ifdef __KERNEL__
13089 +
13090 +
13091 +#ifdef CONFIG_COMPAT
13092 +
13093 +#include <asm/compat.h>
13094 +
13095 +struct vcmd_ctx_iattr_v1_x32 {
13096 +       compat_uptr_t name_ptr;
13097 +       uint32_t tag;
13098 +       uint32_t flags;
13099 +       uint32_t mask;
13100 +};
13101 +
13102 +#endif /* CONFIG_COMPAT */
13103 +
13104 +#include <linux/compiler.h>
13105 +
13106 +extern int vc_get_iattr(void __user *);
13107 +extern int vc_set_iattr(void __user *);
13108 +
13109 +extern int vc_fget_iattr(uint32_t, void __user *);
13110 +extern int vc_fset_iattr(uint32_t, void __user *);
13111 +
13112 +#ifdef CONFIG_COMPAT
13113 +
13114 +extern int vc_get_iattr_x32(void __user *);
13115 +extern int vc_set_iattr_x32(void __user *);
13116 +
13117 +#endif /* CONFIG_COMPAT */
13118 +
13119 +#endif /* __KERNEL__ */
13120 +#endif /* _VX_INODE_CMD_H */
13121 diff -NurpP --minimal linux-2.6.38.1/include/linux/vserver/limit.h linux-2.6.38.1-vs2.3.0.37-rc9/include/linux/vserver/limit.h
13122 --- linux-2.6.38.1/include/linux/vserver/limit.h        1970-01-01 01:00:00.000000000 +0100
13123 +++ linux-2.6.38.1-vs2.3.0.37-rc9/include/linux/vserver/limit.h 2011-01-29 02:01:07.000000000 +0100
13124 @@ -0,0 +1,71 @@
13125 +#ifndef _VX_LIMIT_H
13126 +#define _VX_LIMIT_H
13127 +
13128 +#define VLIMIT_NSOCK   16
13129 +#define VLIMIT_OPENFD  17
13130 +#define VLIMIT_ANON    18
13131 +#define VLIMIT_SHMEM   19
13132 +#define VLIMIT_SEMARY  20
13133 +#define VLIMIT_NSEMS   21
13134 +#define VLIMIT_DENTRY  22
13135 +#define VLIMIT_MAPPED  23
13136 +
13137 +
13138 +#ifdef __KERNEL__
13139 +
13140 +#define        VLIM_NOCHECK    ((1L << VLIMIT_DENTRY) | (1L << RLIMIT_RSS))
13141 +
13142 +/*     keep in sync with CRLIM_INFINITY */
13143 +
13144 +#define        VLIM_INFINITY   (~0ULL)
13145 +
13146 +#include <asm/atomic.h>
13147 +#include <asm/resource.h>
13148 +
13149 +#ifndef RLIM_INFINITY
13150 +#warning RLIM_INFINITY is undefined
13151 +#endif
13152 +
13153 +#define __rlim_val(l, r, v)    ((l)->res[r].v)
13154 +
13155 +#define __rlim_soft(l, r)      __rlim_val(l, r, soft)
13156 +#define __rlim_hard(l, r)      __rlim_val(l, r, hard)
13157 +
13158 +#define __rlim_rcur(l, r)      __rlim_val(l, r, rcur)
13159 +#define __rlim_rmin(l, r)      __rlim_val(l, r, rmin)
13160 +#define __rlim_rmax(l, r)      __rlim_val(l, r, rmax)
13161 +
13162 +#define __rlim_lhit(l, r)      __rlim_val(l, r, lhit)
13163 +#define __rlim_hit(l, r)       atomic_inc(&__rlim_lhit(l, r))
13164 +
13165 +typedef atomic_long_t rlim_atomic_t;
13166 +typedef unsigned long rlim_t;
13167 +
13168 +#define __rlim_get(l, r)       atomic_long_read(&__rlim_rcur(l, r))
13169 +#define __rlim_set(l, r, v)    atomic_long_set(&__rlim_rcur(l, r), v)
13170 +#define __rlim_inc(l, r)       atomic_long_inc(&__rlim_rcur(l, r))
13171 +#define __rlim_dec(l, r)       atomic_long_dec(&__rlim_rcur(l, r))
13172 +#define __rlim_add(l, r, v)    atomic_long_add(v, &__rlim_rcur(l, r))
13173 +#define __rlim_sub(l, r, v)    atomic_long_sub(v, &__rlim_rcur(l, r))
13174 +
13175 +
13176 +#if    (RLIM_INFINITY == VLIM_INFINITY)
13177 +#define        VX_VLIM(r) ((long long)(long)(r))
13178 +#define        VX_RLIM(v) ((rlim_t)(v))
13179 +#else
13180 +#define        VX_VLIM(r) (((r) == RLIM_INFINITY) \
13181 +               ? VLIM_INFINITY : (long long)(r))
13182 +#define        VX_RLIM(v) (((v) == VLIM_INFINITY) \
13183 +               ? RLIM_INFINITY : (rlim_t)(v))
13184 +#endif
13185 +
13186 +struct sysinfo;
13187 +
13188 +void vx_vsi_meminfo(struct sysinfo *);
13189 +void vx_vsi_swapinfo(struct sysinfo *);
13190 +long vx_vsi_cached(struct sysinfo *);
13191 +
13192 +#define NUM_LIMITS     24
13193 +
13194 +#endif /* __KERNEL__ */
13195 +#endif /* _VX_LIMIT_H */
13196 diff -NurpP --minimal linux-2.6.38.1/include/linux/vserver/limit_cmd.h linux-2.6.38.1-vs2.3.0.37-rc9/include/linux/vserver/limit_cmd.h
13197 --- linux-2.6.38.1/include/linux/vserver/limit_cmd.h    1970-01-01 01:00:00.000000000 +0100
13198 +++ linux-2.6.38.1-vs2.3.0.37-rc9/include/linux/vserver/limit_cmd.h     2011-01-29 02:01:07.000000000 +0100
13199 @@ -0,0 +1,71 @@
13200 +#ifndef _VX_LIMIT_CMD_H
13201 +#define _VX_LIMIT_CMD_H
13202 +
13203 +
13204 +/*  rlimit vserver commands */
13205 +
13206 +#define VCMD_get_rlimit                VC_CMD(RLIMIT, 1, 0)
13207 +#define VCMD_set_rlimit                VC_CMD(RLIMIT, 2, 0)
13208 +#define VCMD_get_rlimit_mask   VC_CMD(RLIMIT, 3, 0)
13209 +#define VCMD_reset_hits                VC_CMD(RLIMIT, 7, 0)
13210 +#define VCMD_reset_minmax      VC_CMD(RLIMIT, 9, 0)
13211 +
13212 +struct vcmd_ctx_rlimit_v0 {
13213 +       uint32_t id;
13214 +       uint64_t minimum;
13215 +       uint64_t softlimit;
13216 +       uint64_t maximum;
13217 +};
13218 +
13219 +struct vcmd_ctx_rlimit_mask_v0 {
13220 +       uint32_t minimum;
13221 +       uint32_t softlimit;
13222 +       uint32_t maximum;
13223 +};
13224 +
13225 +#define VCMD_rlimit_stat       VC_CMD(VSTAT, 1, 0)
13226 +
13227 +struct vcmd_rlimit_stat_v0 {
13228 +       uint32_t id;
13229 +       uint32_t hits;
13230 +       uint64_t value;
13231 +       uint64_t minimum;
13232 +       uint64_t maximum;
13233 +};
13234 +
13235 +#define CRLIM_UNSET            (0ULL)
13236 +#define CRLIM_INFINITY         (~0ULL)
13237 +#define CRLIM_KEEP             (~1ULL)
13238 +
13239 +#ifdef __KERNEL__
13240 +
13241 +#ifdef CONFIG_IA32_EMULATION
13242 +
13243 +struct vcmd_ctx_rlimit_v0_x32 {
13244 +       uint32_t id;
13245 +       uint64_t minimum;
13246 +       uint64_t softlimit;
13247 +       uint64_t maximum;
13248 +} __attribute__ ((packed));
13249 +
13250 +#endif /* CONFIG_IA32_EMULATION */
13251 +
13252 +#include <linux/compiler.h>
13253 +
13254 +extern int vc_get_rlimit_mask(uint32_t, void __user *);
13255 +extern int vc_get_rlimit(struct vx_info *, void __user *);
13256 +extern int vc_set_rlimit(struct vx_info *, void __user *);
13257 +extern int vc_reset_hits(struct vx_info *, void __user *);
13258 +extern int vc_reset_minmax(struct vx_info *, void __user *);
13259 +
13260 +extern int vc_rlimit_stat(struct vx_info *, void __user *);
13261 +
13262 +#ifdef CONFIG_IA32_EMULATION
13263 +
13264 +extern int vc_get_rlimit_x32(struct vx_info *, void __user *);
13265 +extern int vc_set_rlimit_x32(struct vx_info *, void __user *);
13266 +
13267 +#endif /* CONFIG_IA32_EMULATION */
13268 +
13269 +#endif /* __KERNEL__ */
13270 +#endif /* _VX_LIMIT_CMD_H */
13271 diff -NurpP --minimal linux-2.6.38.1/include/linux/vserver/limit_def.h linux-2.6.38.1-vs2.3.0.37-rc9/include/linux/vserver/limit_def.h
13272 --- linux-2.6.38.1/include/linux/vserver/limit_def.h    1970-01-01 01:00:00.000000000 +0100
13273 +++ linux-2.6.38.1-vs2.3.0.37-rc9/include/linux/vserver/limit_def.h     2011-01-29 02:01:07.000000000 +0100
13274 @@ -0,0 +1,47 @@
13275 +#ifndef _VX_LIMIT_DEF_H
13276 +#define _VX_LIMIT_DEF_H
13277 +
13278 +#include <asm/atomic.h>
13279 +#include <asm/resource.h>
13280 +
13281 +#include "limit.h"
13282 +
13283 +
13284 +struct _vx_res_limit {
13285 +       rlim_t soft;            /* Context soft limit */
13286 +       rlim_t hard;            /* Context hard limit */
13287 +
13288 +       rlim_atomic_t rcur;     /* Current value */
13289 +       rlim_t rmin;            /* Context minimum */
13290 +       rlim_t rmax;            /* Context maximum */
13291 +
13292 +       atomic_t lhit;          /* Limit hits */
13293 +};
13294 +
13295 +/* context sub struct */
13296 +
13297 +struct _vx_limit {
13298 +       struct _vx_res_limit res[NUM_LIMITS];
13299 +};
13300 +
13301 +#ifdef CONFIG_VSERVER_DEBUG
13302 +
13303 +static inline void __dump_vx_limit(struct _vx_limit *limit)
13304 +{
13305 +       int i;
13306 +
13307 +       printk("\t_vx_limit:");
13308 +       for (i = 0; i < NUM_LIMITS; i++) {
13309 +               printk("\t [%2d] = %8lu %8lu/%8lu, %8ld/%8ld, %8d\n",
13310 +                       i, (unsigned long)__rlim_get(limit, i),
13311 +                       (unsigned long)__rlim_rmin(limit, i),
13312 +                       (unsigned long)__rlim_rmax(limit, i),
13313 +                       (long)__rlim_soft(limit, i),
13314 +                       (long)__rlim_hard(limit, i),
13315 +                       atomic_read(&__rlim_lhit(limit, i)));
13316 +       }
13317 +}
13318 +
13319 +#endif
13320 +
13321 +#endif /* _VX_LIMIT_DEF_H */
13322 diff -NurpP --minimal linux-2.6.38.1/include/linux/vserver/limit_int.h linux-2.6.38.1-vs2.3.0.37-rc9/include/linux/vserver/limit_int.h
13323 --- linux-2.6.38.1/include/linux/vserver/limit_int.h    1970-01-01 01:00:00.000000000 +0100
13324 +++ linux-2.6.38.1-vs2.3.0.37-rc9/include/linux/vserver/limit_int.h     2011-01-29 02:01:07.000000000 +0100
13325 @@ -0,0 +1,198 @@
13326 +#ifndef _VX_LIMIT_INT_H
13327 +#define _VX_LIMIT_INT_H
13328 +
13329 +#include "context.h"
13330 +
13331 +#ifdef __KERNEL__
13332 +
13333 +#define VXD_RCRES_COND(r)      VXD_CBIT(cres, r)
13334 +#define VXD_RLIMIT_COND(r)     VXD_CBIT(limit, r)
13335 +
13336 +extern const char *vlimit_name[NUM_LIMITS];
13337 +
13338 +static inline void __vx_acc_cres(struct vx_info *vxi,
13339 +       int res, int dir, void *_data, char *_file, int _line)
13340 +{
13341 +       if (VXD_RCRES_COND(res))
13342 +               vxlprintk(1, "vx_acc_cres[%5d,%s,%2d]: %5ld%s (%p)",
13343 +                       (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
13344 +                       (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
13345 +                       (dir > 0) ? "++" : "--", _data, _file, _line);
13346 +       if (!vxi)
13347 +               return;
13348 +
13349 +       if (dir > 0)
13350 +               __rlim_inc(&vxi->limit, res);
13351 +       else
13352 +               __rlim_dec(&vxi->limit, res);
13353 +}
13354 +
13355 +static inline void __vx_add_cres(struct vx_info *vxi,
13356 +       int res, int amount, void *_data, char *_file, int _line)
13357 +{
13358 +       if (VXD_RCRES_COND(res))
13359 +               vxlprintk(1, "vx_add_cres[%5d,%s,%2d]: %5ld += %5d (%p)",
13360 +                       (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
13361 +                       (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
13362 +                       amount, _data, _file, _line);
13363 +       if (amount == 0)
13364 +               return;
13365 +       if (!vxi)
13366 +               return;
13367 +       __rlim_add(&vxi->limit, res, amount);
13368 +}
13369 +
13370 +static inline
13371 +int __vx_cres_adjust_max(struct _vx_limit *limit, int res, rlim_t value)
13372 +{
13373 +       int cond = (value > __rlim_rmax(limit, res));
13374 +
13375 +       if (cond)
13376 +               __rlim_rmax(limit, res) = value;
13377 +       return cond;
13378 +}
13379 +
13380 +static inline
13381 +int __vx_cres_adjust_min(struct _vx_limit *limit, int res, rlim_t value)
13382 +{
13383 +       int cond = (value < __rlim_rmin(limit, res));
13384 +
13385 +       if (cond)
13386 +               __rlim_rmin(limit, res) = value;
13387 +       return cond;
13388 +}
13389 +
13390 +static inline
13391 +void __vx_cres_fixup(struct _vx_limit *limit, int res, rlim_t value)
13392 +{
13393 +       if (!__vx_cres_adjust_max(limit, res, value))
13394 +               __vx_cres_adjust_min(limit, res, value);
13395 +}
13396 +
13397 +
13398 +/*     return values:
13399 +        +1 ... no limit hit
13400 +        -1 ... over soft limit
13401 +         0 ... over hard limit         */
13402 +
13403 +static inline int __vx_cres_avail(struct vx_info *vxi,
13404 +       int res, int num, char *_file, int _line)
13405 +{
13406 +       struct _vx_limit *limit;
13407 +       rlim_t value;
13408 +
13409 +       if (VXD_RLIMIT_COND(res))
13410 +               vxlprintk(1, "vx_cres_avail[%5d,%s,%2d]: %5ld/%5ld > %5ld + %5d",
13411 +                       (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
13412 +                       (vxi ? (long)__rlim_soft(&vxi->limit, res) : -1),
13413 +                       (vxi ? (long)__rlim_hard(&vxi->limit, res) : -1),
13414 +                       (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
13415 +                       num, _file, _line);
13416 +       if (!vxi)
13417 +               return 1;
13418 +
13419 +       limit = &vxi->limit;
13420 +       value = __rlim_get(limit, res);
13421 +
13422 +       if (!__vx_cres_adjust_max(limit, res, value))
13423 +               __vx_cres_adjust_min(limit, res, value);
13424 +
13425 +       if (num == 0)
13426 +               return 1;
13427 +
13428 +       if (__rlim_soft(limit, res) == RLIM_INFINITY)
13429 +               return -1;
13430 +       if (value + num <= __rlim_soft(limit, res))
13431 +               return -1;
13432 +
13433 +       if (__rlim_hard(limit, res) == RLIM_INFINITY)
13434 +               return 1;
13435 +       if (value + num <= __rlim_hard(limit, res))
13436 +               return 1;
13437 +
13438 +       __rlim_hit(limit, res);
13439 +       return 0;
13440 +}
13441 +
13442 +
13443 +static const int VLA_RSS[] = { RLIMIT_RSS, VLIMIT_ANON, VLIMIT_MAPPED, 0 };
13444 +
13445 +static inline
13446 +rlim_t __vx_cres_array_sum(struct _vx_limit *limit, const int *array)
13447 +{
13448 +       rlim_t value, sum = 0;
13449 +       int res;
13450 +
13451 +       while ((res = *array++)) {
13452 +               value = __rlim_get(limit, res);
13453 +               __vx_cres_fixup(limit, res, value);
13454 +               sum += value;
13455 +       }
13456 +       return sum;
13457 +}
13458 +
13459 +static inline
13460 +rlim_t __vx_cres_array_fixup(struct _vx_limit *limit, const int *array)
13461 +{
13462 +       rlim_t value = __vx_cres_array_sum(limit, array + 1);
13463 +       int res = *array;
13464 +
13465 +       if (value == __rlim_get(limit, res))
13466 +               return value;
13467 +
13468 +       __rlim_set(limit, res, value);
13469 +       /* now adjust min/max */
13470 +       if (!__vx_cres_adjust_max(limit, res, value))
13471 +               __vx_cres_adjust_min(limit, res, value);
13472 +
13473 +       return value;
13474 +}
13475 +
13476 +static inline int __vx_cres_array_avail(struct vx_info *vxi,
13477 +       const int *array, int num, char *_file, int _line)
13478 +{
13479 +       struct _vx_limit *limit;
13480 +       rlim_t value = 0;
13481 +       int res;
13482 +
13483 +       if (num == 0)
13484 +               return 1;
13485 +       if (!vxi)
13486 +               return 1;
13487 +
13488 +       limit = &vxi->limit;
13489 +       res = *array;
13490 +       value = __vx_cres_array_sum(limit, array + 1);
13491 +
13492 +       __rlim_set(limit, res, value);
13493 +       __vx_cres_fixup(limit, res, value);
13494 +
13495 +       return __vx_cres_avail(vxi, res, num, _file, _line);
13496 +}
13497 +
13498 +
13499 +static inline void vx_limit_fixup(struct _vx_limit *limit, int id)
13500 +{
13501 +       rlim_t value;
13502 +       int res;
13503 +
13504 +       /* complex resources first */
13505 +       if ((id < 0) || (id == RLIMIT_RSS))
13506 +               __vx_cres_array_fixup(limit, VLA_RSS);
13507 +
13508 +       for (res = 0; res < NUM_LIMITS; res++) {
13509 +               if ((id > 0) && (res != id))
13510 +                       continue;
13511 +
13512 +               value = __rlim_get(limit, res);
13513 +               __vx_cres_fixup(limit, res, value);
13514 +
13515 +               /* not supposed to happen, maybe warn? */
13516 +               if (__rlim_rmax(limit, res) > __rlim_hard(limit, res))
13517 +                       __rlim_rmax(limit, res) = __rlim_hard(limit, res);
13518 +       }
13519 +}
13520 +
13521 +
13522 +#endif /* __KERNEL__ */
13523 +#endif /* _VX_LIMIT_INT_H */
13524 diff -NurpP --minimal linux-2.6.38.1/include/linux/vserver/monitor.h linux-2.6.38.1-vs2.3.0.37-rc9/include/linux/vserver/monitor.h
13525 --- linux-2.6.38.1/include/linux/vserver/monitor.h      1970-01-01 01:00:00.000000000 +0100
13526 +++ linux-2.6.38.1-vs2.3.0.37-rc9/include/linux/vserver/monitor.h       2011-01-29 02:01:07.000000000 +0100
13527 @@ -0,0 +1,96 @@
13528 +#ifndef _VX_MONITOR_H
13529 +#define _VX_MONITOR_H
13530 +
13531 +#include <linux/types.h>
13532 +
13533 +enum {
13534 +       VXM_UNUSED = 0,
13535 +
13536 +       VXM_SYNC = 0x10,
13537 +
13538 +       VXM_UPDATE = 0x20,
13539 +       VXM_UPDATE_1,
13540 +       VXM_UPDATE_2,
13541 +
13542 +       VXM_RQINFO_1 = 0x24,
13543 +       VXM_RQINFO_2,
13544 +
13545 +       VXM_ACTIVATE = 0x40,
13546 +       VXM_DEACTIVATE,
13547 +       VXM_IDLE,
13548 +
13549 +       VXM_HOLD = 0x44,
13550 +       VXM_UNHOLD,
13551 +
13552 +       VXM_MIGRATE = 0x48,
13553 +       VXM_RESCHED,
13554 +
13555 +       /* all other bits are flags */
13556 +       VXM_SCHED = 0x80,
13557 +};
13558 +
13559 +struct _vxm_update_1 {
13560 +       uint32_t tokens_max;
13561 +       uint32_t fill_rate;
13562 +       uint32_t interval;
13563 +};
13564 +
13565 +struct _vxm_update_2 {
13566 +       uint32_t tokens_min;
13567 +       uint32_t fill_rate;
13568 +       uint32_t interval;
13569 +};
13570 +
13571 +struct _vxm_rqinfo_1 {
13572 +       uint16_t running;
13573 +       uint16_t onhold;
13574 +       uint16_t iowait;
13575 +       uint16_t uintr;
13576 +       uint32_t idle_tokens;
13577 +};
13578 +
13579 +struct _vxm_rqinfo_2 {
13580 +       uint32_t norm_time;
13581 +       uint32_t idle_time;
13582 +       uint32_t idle_skip;
13583 +};
13584 +
13585 +struct _vxm_sched {
13586 +       uint32_t tokens;
13587 +       uint32_t norm_time;
13588 +       uint32_t idle_time;
13589 +};
13590 +
13591 +struct _vxm_task {
13592 +       uint16_t pid;
13593 +       uint16_t state;
13594 +};
13595 +
13596 +struct _vxm_event {
13597 +       uint32_t jif;
13598 +       union {
13599 +               uint32_t seq;
13600 +               uint32_t sec;
13601 +       };
13602 +       union {
13603 +               uint32_t tokens;
13604 +               uint32_t nsec;
13605 +               struct _vxm_task tsk;
13606 +       };
13607 +};
13608 +
13609 +struct _vx_mon_entry {
13610 +       uint16_t type;
13611 +       uint16_t xid;
13612 +       union {
13613 +               struct _vxm_event ev;
13614 +               struct _vxm_sched sd;
13615 +               struct _vxm_update_1 u1;
13616 +               struct _vxm_update_2 u2;
13617 +               struct _vxm_rqinfo_1 q1;
13618 +               struct _vxm_rqinfo_2 q2;
13619 +       };
13620 +};
13621 +
13622 +
13623 +#endif /* _VX_MONITOR_H */
13624 diff -NurpP --minimal linux-2.6.38.1/include/linux/vserver/network.h linux-2.6.38.1-vs2.3.0.37-rc9/include/linux/vserver/network.h
13625 --- linux-2.6.38.1/include/linux/vserver/network.h      1970-01-01 01:00:00.000000000 +0100
13626 +++ linux-2.6.38.1-vs2.3.0.37-rc9/include/linux/vserver/network.h       2011-01-29 02:01:07.000000000 +0100
13627 @@ -0,0 +1,146 @@
13628 +#ifndef _VX_NETWORK_H
13629 +#define _VX_NETWORK_H
13630 +
13631 +#include <linux/types.h>
13632 +
13633 +
13634 +#define MAX_N_CONTEXT  65535   /* Arbitrary limit */
13635 +
13636 +
13637 +/* network flags */
13638 +
13639 +#define NXF_INFO_PRIVATE       0x00000008
13640 +
13641 +#define NXF_SINGLE_IP          0x00000100
13642 +#define NXF_LBACK_REMAP                0x00000200
13643 +#define NXF_LBACK_ALLOW                0x00000400
13644 +
13645 +#define NXF_HIDE_NETIF         0x02000000
13646 +#define NXF_HIDE_LBACK         0x04000000
13647 +
13648 +#define NXF_STATE_SETUP                (1ULL << 32)
13649 +#define NXF_STATE_ADMIN                (1ULL << 34)
13650 +
13651 +#define NXF_SC_HELPER          (1ULL << 36)
13652 +#define NXF_PERSISTENT         (1ULL << 38)
13653 +
13654 +#define NXF_ONE_TIME           (0x0005ULL << 32)
13655 +
13656 +
13657 +#define        NXF_INIT_SET            (__nxf_init_set())
13658 +
13659 +static inline uint64_t __nxf_init_set(void) {
13660 +       return    NXF_STATE_ADMIN
13661 +#ifdef CONFIG_VSERVER_AUTO_LBACK
13662 +               | NXF_LBACK_REMAP
13663 +               | NXF_HIDE_LBACK
13664 +#endif
13665 +#ifdef CONFIG_VSERVER_AUTO_SINGLE
13666 +               | NXF_SINGLE_IP
13667 +#endif
13668 +               | NXF_HIDE_NETIF;
13669 +}
13670 +
13671 +
13672 +/* network caps */
13673 +
13674 +#define NXC_TUN_CREATE         0x00000001
13675 +
13676 +#define NXC_RAW_ICMP           0x00000100
13677 +
13678 +
13679 +/* address types */
13680 +
13681 +#define NXA_TYPE_IPV4          0x0001
13682 +#define NXA_TYPE_IPV6          0x0002
13683 +
13684 +#define NXA_TYPE_NONE          0x0000
13685 +#define NXA_TYPE_ANY           0x00FF
13686 +
13687 +#define NXA_TYPE_ADDR          0x0010
13688 +#define NXA_TYPE_MASK          0x0020
13689 +#define NXA_TYPE_RANGE         0x0040
13690 +
13691 +#define NXA_MASK_ALL           (NXA_TYPE_ADDR | NXA_TYPE_MASK | NXA_TYPE_RANGE)
13692 +
13693 +#define NXA_MOD_BCAST          0x0100
13694 +#define NXA_MOD_LBACK          0x0200
13695 +
13696 +#define NXA_LOOPBACK           0x1000
13697 +
13698 +#define NXA_MASK_BIND          (NXA_MASK_ALL | NXA_MOD_BCAST | NXA_MOD_LBACK)
13699 +#define NXA_MASK_SHOW          (NXA_MASK_ALL | NXA_LOOPBACK)
13700 +
13701 +#ifdef __KERNEL__
13702 +
13703 +#include <linux/list.h>
13704 +#include <linux/spinlock.h>
13705 +#include <linux/rcupdate.h>
13706 +#include <linux/in.h>
13707 +#include <linux/in6.h>
13708 +#include <asm/atomic.h>
13709 +
13710 +struct nx_addr_v4 {
13711 +       struct nx_addr_v4 *next;
13712 +       struct in_addr ip[2];
13713 +       struct in_addr mask;
13714 +       uint16_t type;
13715 +       uint16_t flags;
13716 +};
13717 +
13718 +struct nx_addr_v6 {
13719 +       struct nx_addr_v6 *next;
13720 +       struct in6_addr ip;
13721 +       struct in6_addr mask;
13722 +       uint32_t prefix;
13723 +       uint16_t type;
13724 +       uint16_t flags;
13725 +};
13726 +
13727 +struct nx_info {
13728 +       struct hlist_node nx_hlist;     /* linked list of nxinfos */
13729 +       nid_t nx_id;                    /* vnet id */
13730 +       atomic_t nx_usecnt;             /* usage count */
13731 +       atomic_t nx_tasks;              /* tasks count */
13732 +       int nx_state;                   /* context state */
13733 +
13734 +       uint64_t nx_flags;              /* network flag word */
13735 +       uint64_t nx_ncaps;              /* network capabilities */
13736 +
13737 +       struct in_addr v4_lback;        /* Loopback address */
13738 +       struct in_addr v4_bcast;        /* Broadcast address */
13739 +       struct nx_addr_v4 v4;           /* First/Single ipv4 address */
13740 +#ifdef CONFIG_IPV6
13741 +       struct nx_addr_v6 v6;           /* First/Single ipv6 address */
13742 +#endif
13743 +       char nx_name[65];               /* network context name */
13744 +};
13745 +
13746 +
13747 +/* status flags */
13748 +
13749 +#define NXS_HASHED      0x0001
13750 +#define NXS_SHUTDOWN    0x0100
13751 +#define NXS_RELEASED    0x8000
13752 +
13753 +extern struct nx_info *lookup_nx_info(int);
13754 +
13755 +extern int get_nid_list(int, unsigned int *, int);
13756 +extern int nid_is_hashed(nid_t);
13757 +
13758 +extern int nx_migrate_task(struct task_struct *, struct nx_info *);
13759 +
13760 +extern long vs_net_change(struct nx_info *, unsigned int);
13761 +
13762 +struct sock;
13763 +
13764 +
13765 +#define NX_IPV4(n)     ((n)->v4.type != NXA_TYPE_NONE)
13766 +#ifdef  CONFIG_IPV6
13767 +#define NX_IPV6(n)     ((n)->v6.type != NXA_TYPE_NONE)
13768 +#else
13769 +#define NX_IPV6(n)     (0)
13770 +#endif
13771 +
13772 +#endif /* __KERNEL__ */
13773 +#endif /* _VX_NETWORK_H */
13774 diff -NurpP --minimal linux-2.6.38.1/include/linux/vserver/network_cmd.h linux-2.6.38.1-vs2.3.0.37-rc9/include/linux/vserver/network_cmd.h
13775 --- linux-2.6.38.1/include/linux/vserver/network_cmd.h  1970-01-01 01:00:00.000000000 +0100
13776 +++ linux-2.6.38.1-vs2.3.0.37-rc9/include/linux/vserver/network_cmd.h   2011-01-29 02:01:07.000000000 +0100
13777 @@ -0,0 +1,150 @@
13778 +#ifndef _VX_NETWORK_CMD_H
13779 +#define _VX_NETWORK_CMD_H
13780 +
13781 +
13782 +/* vinfo commands */
13783 +
13784 +#define VCMD_task_nid          VC_CMD(VINFO, 2, 0)
13785 +
13786 +#ifdef __KERNEL__
13787 +extern int vc_task_nid(uint32_t);
13788 +
13789 +#endif /* __KERNEL__ */
13790 +
13791 +#define VCMD_nx_info           VC_CMD(VINFO, 6, 0)
13792 +
13793 +struct vcmd_nx_info_v0 {
13794 +       uint32_t nid;
13795 +       /* more to come */
13796 +};
13797 +
13798 +#ifdef __KERNEL__
13799 +extern int vc_nx_info(struct nx_info *, void __user *);
13800 +
13801 +#endif /* __KERNEL__ */
13802 +
13803 +#include <linux/in.h>
13804 +#include <linux/in6.h>
13805 +
13806 +#define VCMD_net_create_v0     VC_CMD(VNET, 1, 0)
13807 +#define VCMD_net_create                VC_CMD(VNET, 1, 1)
13808 +
13809 +struct  vcmd_net_create {
13810 +       uint64_t flagword;
13811 +};
13812 +
13813 +#define VCMD_net_migrate       VC_CMD(NETMIG, 1, 0)
13814 +
13815 +#define VCMD_net_add           VC_CMD(NETALT, 1, 0)
13816 +#define VCMD_net_remove                VC_CMD(NETALT, 2, 0)
13817 +
13818 +struct vcmd_net_addr_v0 {
13819 +       uint16_t type;
13820 +       uint16_t count;
13821 +       struct in_addr ip[4];
13822 +       struct in_addr mask[4];
13823 +};
13824 +
13825 +#define VCMD_net_add_ipv4      VC_CMD(NETALT, 1, 1)
13826 +#define VCMD_net_remove_ipv4   VC_CMD(NETALT, 2, 1)
13827 +
13828 +struct vcmd_net_addr_ipv4_v1 {
13829 +       uint16_t type;
13830 +       uint16_t flags;
13831 +       struct in_addr ip;
13832 +       struct in_addr mask;
13833 +};
13834 +
13835 +#define VCMD_net_add_ipv6      VC_CMD(NETALT, 3, 1)
13836 +#define VCMD_net_remove_ipv6   VC_CMD(NETALT, 4, 1)
13837 +
13838 +struct vcmd_net_addr_ipv6_v1 {
13839 +       uint16_t type;
13840 +       uint16_t flags;
13841 +       uint32_t prefix;
13842 +       struct in6_addr ip;
13843 +       struct in6_addr mask;
13844 +};
13845 +
13846 +#define VCMD_add_match_ipv4    VC_CMD(NETALT, 5, 0)
13847 +#define VCMD_get_match_ipv4    VC_CMD(NETALT, 6, 0)
13848 +
13849 +struct vcmd_match_ipv4_v0 {
13850 +       uint16_t type;
13851 +       uint16_t flags;
13852 +       uint16_t parent;
13853 +       uint16_t prefix;
13854 +       struct in_addr ip;
13855 +       struct in_addr ip2;
13856 +       struct in_addr mask;
13857 +};
13858 +
13859 +#define VCMD_add_match_ipv6    VC_CMD(NETALT, 7, 0)
13860 +#define VCMD_get_match_ipv6    VC_CMD(NETALT, 8, 0)
13861 +
13862 +struct vcmd_match_ipv6_v0 {
13863 +       uint16_t type;
13864 +       uint16_t flags;
13865 +       uint16_t parent;
13866 +       uint16_t prefix;
13867 +       struct in6_addr ip;
13868 +       struct in6_addr ip2;
13869 +       struct in6_addr mask;
13870 +};
13871 +
13872 +
13873 +#ifdef __KERNEL__
13874 +extern int vc_net_create(uint32_t, void __user *);
13875 +extern int vc_net_migrate(struct nx_info *, void __user *);
13876 +
13877 +extern int vc_net_add(struct nx_info *, void __user *);
13878 +extern int vc_net_remove(struct nx_info *, void __user *);
13879 +
13880 +extern int vc_net_add_ipv4(struct nx_info *, void __user *);
13881 +extern int vc_net_remove_ipv4(struct nx_info *, void __user *);
13882 +
13883 +extern int vc_net_add_ipv6(struct nx_info *, void __user *);
13884 +extern int vc_net_remove_ipv6(struct nx_info *, void __user *);
13885 +
13886 +extern int vc_add_match_ipv4(struct nx_info *, void __user *);
13887 +extern int vc_get_match_ipv4(struct nx_info *, void __user *);
13888 +
13889 +extern int vc_add_match_ipv6(struct nx_info *, void __user *);
13890 +extern int vc_get_match_ipv6(struct nx_info *, void __user *);
13891 +
13892 +#endif /* __KERNEL__ */
13893 +
13894 +
13895 +/* flag commands */
13896 +
13897 +#define VCMD_get_nflags                VC_CMD(FLAGS, 5, 0)
13898 +#define VCMD_set_nflags                VC_CMD(FLAGS, 6, 0)
13899 +
13900 +struct vcmd_net_flags_v0 {
13901 +       uint64_t flagword;
13902 +       uint64_t mask;
13903 +};
13904 +
13905 +#ifdef __KERNEL__
13906 +extern int vc_get_nflags(struct nx_info *, void __user *);
13907 +extern int vc_set_nflags(struct nx_info *, void __user *);
13908 +
13909 +#endif /* __KERNEL__ */
13910 +
13911 +
13912 +/* network caps commands */
13913 +
13914 +#define VCMD_get_ncaps         VC_CMD(FLAGS, 7, 0)
13915 +#define VCMD_set_ncaps         VC_CMD(FLAGS, 8, 0)
13916 +
13917 +struct vcmd_net_caps_v0 {
13918 +       uint64_t ncaps;
13919 +       uint64_t cmask;
13920 +};
13921 +
13922 +#ifdef __KERNEL__
13923 +extern int vc_get_ncaps(struct nx_info *, void __user *);
13924 +extern int vc_set_ncaps(struct nx_info *, void __user *);
13925 +
13926 +#endif /* __KERNEL__ */
13927 +#endif /* _VX_CONTEXT_CMD_H */
13928 diff -NurpP --minimal linux-2.6.38.1/include/linux/vserver/percpu.h linux-2.6.38.1-vs2.3.0.37-rc9/include/linux/vserver/percpu.h
13929 --- linux-2.6.38.1/include/linux/vserver/percpu.h       1970-01-01 01:00:00.000000000 +0100
13930 +++ linux-2.6.38.1-vs2.3.0.37-rc9/include/linux/vserver/percpu.h        2011-01-29 02:01:07.000000000 +0100
13931 @@ -0,0 +1,14 @@
13932 +#ifndef _VX_PERCPU_H
13933 +#define _VX_PERCPU_H
13934 +
13935 +#include "cvirt_def.h"
13936 +#include "sched_def.h"
13937 +
13938 +struct _vx_percpu {
13939 +       struct _vx_cvirt_pc cvirt;
13940 +       struct _vx_sched_pc sched;
13941 +};
13942 +
13943 +#define        PERCPU_PERCTX   (sizeof(struct _vx_percpu))
13944 +
13945 +#endif /* _VX_PERCPU_H */
13946 diff -NurpP --minimal linux-2.6.38.1/include/linux/vserver/pid.h linux-2.6.38.1-vs2.3.0.37-rc9/include/linux/vserver/pid.h
13947 --- linux-2.6.38.1/include/linux/vserver/pid.h  1970-01-01 01:00:00.000000000 +0100
13948 +++ linux-2.6.38.1-vs2.3.0.37-rc9/include/linux/vserver/pid.h   2011-01-29 02:01:07.000000000 +0100
13949 @@ -0,0 +1,51 @@
13950 +#ifndef _VSERVER_PID_H
13951 +#define _VSERVER_PID_H
13952 +
13953 +/* pid faking stuff */
13954 +
13955 +#define vx_info_map_pid(v, p) \
13956 +       __vx_info_map_pid((v), (p), __func__, __FILE__, __LINE__)
13957 +#define vx_info_map_tgid(v,p)  vx_info_map_pid(v,p)
13958 +#define vx_map_pid(p) vx_info_map_pid(current_vx_info(), p)
13959 +#define vx_map_tgid(p) vx_map_pid(p)
13960 +
13961 +static inline int __vx_info_map_pid(struct vx_info *vxi, int pid,
13962 +       const char *func, const char *file, int line)
13963 +{
13964 +       if (vx_info_flags(vxi, VXF_INFO_INIT, 0)) {
13965 +               vxfprintk(VXD_CBIT(cvirt, 2),
13966 +                       "vx_map_tgid: %p/%llx: %d -> %d",
13967 +                       vxi, (long long)vxi->vx_flags, pid,
13968 +                       (pid && pid == vxi->vx_initpid) ? 1 : pid,
13969 +                       func, file, line);
13970 +               if (pid == 0)
13971 +                       return 0;
13972 +               if (pid == vxi->vx_initpid)
13973 +                       return 1;
13974 +       }
13975 +       return pid;
13976 +}
13977 +
13978 +#define vx_info_rmap_pid(v, p) \
13979 +       __vx_info_rmap_pid((v), (p), __func__, __FILE__, __LINE__)
13980 +#define vx_rmap_pid(p) vx_info_rmap_pid(current_vx_info(), p)
13981 +#define vx_rmap_tgid(p) vx_rmap_pid(p)
13982 +
13983 +static inline int __vx_info_rmap_pid(struct vx_info *vxi, int pid,
13984 +       const char *func, const char *file, int line)
13985 +{
13986 +       if (vx_info_flags(vxi, VXF_INFO_INIT, 0)) {
13987 +               vxfprintk(VXD_CBIT(cvirt, 2),
13988 +                       "vx_rmap_tgid: %p/%llx: %d -> %d",
13989 +                       vxi, (long long)vxi->vx_flags, pid,
13990 +                       (pid == 1) ? vxi->vx_initpid : pid,
13991 +                       func, file, line);
13992 +               if ((pid == 1) && vxi->vx_initpid)
13993 +                       return vxi->vx_initpid;
13994 +               if (pid == vxi->vx_initpid)
13995 +                       return ~0U;
13996 +       }
13997 +       return pid;
13998 +}
13999 +
14000 +#endif
14001 diff -NurpP --minimal linux-2.6.38.1/include/linux/vserver/sched.h linux-2.6.38.1-vs2.3.0.37-rc9/include/linux/vserver/sched.h
14002 --- linux-2.6.38.1/include/linux/vserver/sched.h        1970-01-01 01:00:00.000000000 +0100
14003 +++ linux-2.6.38.1-vs2.3.0.37-rc9/include/linux/vserver/sched.h 2011-01-29 02:01:07.000000000 +0100
14004 @@ -0,0 +1,23 @@
14005 +#ifndef _VX_SCHED_H
14006 +#define _VX_SCHED_H
14007 +
14008 +
14009 +#ifdef __KERNEL__
14010 +
14011 +struct timespec;
14012 +
14013 +void vx_vsi_uptime(struct timespec *, struct timespec *);
14014 +
14015 +
14016 +struct vx_info;
14017 +
14018 +void vx_update_load(struct vx_info *);
14019 +
14020 +
14021 +void vx_update_sched_param(struct _vx_sched *sched,
14022 +       struct _vx_sched_pc *sched_pc);
14023 +
14024 +#endif /* __KERNEL__ */
14025 +#else  /* _VX_SCHED_H */
14026 +#warning duplicate inclusion
14027 +#endif /* _VX_SCHED_H */
14028 diff -NurpP --minimal linux-2.6.38.1/include/linux/vserver/sched_cmd.h linux-2.6.38.1-vs2.3.0.37-rc9/include/linux/vserver/sched_cmd.h
14029 --- linux-2.6.38.1/include/linux/vserver/sched_cmd.h    1970-01-01 01:00:00.000000000 +0100
14030 +++ linux-2.6.38.1-vs2.3.0.37-rc9/include/linux/vserver/sched_cmd.h     2011-01-29 02:01:07.000000000 +0100
14031 @@ -0,0 +1,21 @@
14032 +#ifndef _VX_SCHED_CMD_H
14033 +#define _VX_SCHED_CMD_H
14034 +
14035 +
14036 +struct vcmd_prio_bias {
14037 +       int32_t cpu_id;
14038 +       int32_t prio_bias;
14039 +};
14040 +
14041 +#define VCMD_set_prio_bias     VC_CMD(SCHED, 4, 0)
14042 +#define VCMD_get_prio_bias     VC_CMD(SCHED, 5, 0)
14043 +
14044 +#ifdef __KERNEL__
14045 +
14046 +#include <linux/compiler.h>
14047 +
14048 +extern int vc_set_prio_bias(struct vx_info *, void __user *);
14049 +extern int vc_get_prio_bias(struct vx_info *, void __user *);
14050 +
14051 +#endif /* __KERNEL__ */
14052 +#endif /* _VX_SCHED_CMD_H */
14053 diff -NurpP --minimal linux-2.6.38.1/include/linux/vserver/sched_def.h linux-2.6.38.1-vs2.3.0.37-rc9/include/linux/vserver/sched_def.h
14054 --- linux-2.6.38.1/include/linux/vserver/sched_def.h    1970-01-01 01:00:00.000000000 +0100
14055 +++ linux-2.6.38.1-vs2.3.0.37-rc9/include/linux/vserver/sched_def.h     2011-01-29 02:01:07.000000000 +0100
14056 @@ -0,0 +1,38 @@
14057 +#ifndef _VX_SCHED_DEF_H
14058 +#define _VX_SCHED_DEF_H
14059 +
14060 +#include <linux/spinlock.h>
14061 +#include <linux/jiffies.h>
14062 +#include <linux/cpumask.h>
14063 +#include <asm/atomic.h>
14064 +#include <asm/param.h>
14065 +
14066 +
14067 +/* context sub struct */
14068 +
14069 +struct _vx_sched {
14070 +       int prio_bias;                  /* bias offset for priority */
14071 +
14072 +       cpumask_t update;               /* CPUs which should update */
14073 +};
14074 +
14075 +struct _vx_sched_pc {
14076 +       int prio_bias;                  /* bias offset for priority */
14077 +
14078 +       uint64_t user_ticks;            /* token tick events */
14079 +       uint64_t sys_ticks;             /* token tick events */
14080 +       uint64_t hold_ticks;            /* token ticks paused */
14081 +};
14082 +
14083 +
14084 +#ifdef CONFIG_VSERVER_DEBUG
14085 +
14086 +static inline void __dump_vx_sched(struct _vx_sched *sched)
14087 +{
14088 +       printk("\t_vx_sched:\n");
14089 +       printk("\t priority = %4d\n", sched->prio_bias);
14090 +}
14091 +
14092 +#endif
14093 +
14094 +#endif /* _VX_SCHED_DEF_H */
14095 diff -NurpP --minimal linux-2.6.38.1/include/linux/vserver/signal.h linux-2.6.38.1-vs2.3.0.37-rc9/include/linux/vserver/signal.h
14096 --- linux-2.6.38.1/include/linux/vserver/signal.h       1970-01-01 01:00:00.000000000 +0100
14097 +++ linux-2.6.38.1-vs2.3.0.37-rc9/include/linux/vserver/signal.h        2011-01-29 02:01:07.000000000 +0100
14098 @@ -0,0 +1,14 @@
14099 +#ifndef _VX_SIGNAL_H
14100 +#define _VX_SIGNAL_H
14101 +
14102 +
14103 +#ifdef __KERNEL__
14104 +
14105 +struct vx_info;
14106 +
14107 +int vx_info_kill(struct vx_info *, int, int);
14108 +
14109 +#endif /* __KERNEL__ */
14110 +#else  /* _VX_SIGNAL_H */
14111 +#warning duplicate inclusion
14112 +#endif /* _VX_SIGNAL_H */
14113 diff -NurpP --minimal linux-2.6.38.1/include/linux/vserver/signal_cmd.h linux-2.6.38.1-vs2.3.0.37-rc9/include/linux/vserver/signal_cmd.h
14114 --- linux-2.6.38.1/include/linux/vserver/signal_cmd.h   1970-01-01 01:00:00.000000000 +0100
14115 +++ linux-2.6.38.1-vs2.3.0.37-rc9/include/linux/vserver/signal_cmd.h    2011-01-29 02:01:07.000000000 +0100
14116 @@ -0,0 +1,43 @@
14117 +#ifndef _VX_SIGNAL_CMD_H
14118 +#define _VX_SIGNAL_CMD_H
14119 +
14120 +
14121 +/*  signalling vserver commands */
14122 +
14123 +#define VCMD_ctx_kill          VC_CMD(PROCTRL, 1, 0)
14124 +#define VCMD_wait_exit         VC_CMD(EVENT, 99, 0)
14125 +
14126 +struct vcmd_ctx_kill_v0 {
14127 +       int32_t pid;
14128 +       int32_t sig;
14129 +};
14130 +
14131 +struct vcmd_wait_exit_v0 {
14132 +       int32_t reboot_cmd;
14133 +       int32_t exit_code;
14134 +};
14135 +
14136 +#ifdef __KERNEL__
14137 +
14138 +extern int vc_ctx_kill(struct vx_info *, void __user *);
14139 +extern int vc_wait_exit(struct vx_info *, void __user *);
14140 +
14141 +#endif /* __KERNEL__ */
14142 +
14143 +/*  process alteration commands */
14144 +
14145 +#define VCMD_get_pflags                VC_CMD(PROCALT, 5, 0)
14146 +#define VCMD_set_pflags                VC_CMD(PROCALT, 6, 0)
14147 +
14148 +struct vcmd_pflags_v0 {
14149 +       uint32_t flagword;
14150 +       uint32_t mask;
14151 +};
14152 +
14153 +#ifdef __KERNEL__
14154 +
14155 +extern int vc_get_pflags(uint32_t pid, void __user *);
14156 +extern int vc_set_pflags(uint32_t pid, void __user *);
14157 +
14158 +#endif /* __KERNEL__ */
14159 +#endif /* _VX_SIGNAL_CMD_H */
14160 diff -NurpP --minimal linux-2.6.38.1/include/linux/vserver/space.h linux-2.6.38.1-vs2.3.0.37-rc9/include/linux/vserver/space.h
14161 --- linux-2.6.38.1/include/linux/vserver/space.h        1970-01-01 01:00:00.000000000 +0100
14162 +++ linux-2.6.38.1-vs2.3.0.37-rc9/include/linux/vserver/space.h 2011-01-29 02:01:07.000000000 +0100
14163 @@ -0,0 +1,12 @@
14164 +#ifndef _VX_SPACE_H
14165 +#define _VX_SPACE_H
14166 +
14167 +#include <linux/types.h>
14168 +
14169 +struct vx_info;
14170 +
14171 +int vx_set_space(struct vx_info *vxi, unsigned long mask, unsigned index);
14172 +
14173 +#else  /* _VX_SPACE_H */
14174 +#warning duplicate inclusion
14175 +#endif /* _VX_SPACE_H */
14176 diff -NurpP --minimal linux-2.6.38.1/include/linux/vserver/space_cmd.h linux-2.6.38.1-vs2.3.0.37-rc9/include/linux/vserver/space_cmd.h
14177 --- linux-2.6.38.1/include/linux/vserver/space_cmd.h    1970-01-01 01:00:00.000000000 +0100
14178 +++ linux-2.6.38.1-vs2.3.0.37-rc9/include/linux/vserver/space_cmd.h     2011-01-29 02:01:07.000000000 +0100
14179 @@ -0,0 +1,38 @@
14180 +#ifndef _VX_SPACE_CMD_H
14181 +#define _VX_SPACE_CMD_H
14182 +
14183 +
14184 +#define VCMD_enter_space_v0    VC_CMD(PROCALT, 1, 0)
14185 +#define VCMD_enter_space_v1    VC_CMD(PROCALT, 1, 1)
14186 +#define VCMD_enter_space       VC_CMD(PROCALT, 1, 2)
14187 +
14188 +#define VCMD_set_space_v0      VC_CMD(PROCALT, 3, 0)
14189 +#define VCMD_set_space_v1      VC_CMD(PROCALT, 3, 1)
14190 +#define VCMD_set_space         VC_CMD(PROCALT, 3, 2)
14191 +
14192 +#define VCMD_get_space_mask_v0 VC_CMD(PROCALT, 4, 0)
14193 +
14194 +#define VCMD_get_space_mask    VC_CMD(VSPACE, 0, 1)
14195 +#define VCMD_get_space_default VC_CMD(VSPACE, 1, 0)
14196 +
14197 +
14198 +struct vcmd_space_mask_v1 {
14199 +       uint64_t mask;
14200 +};
14201 +
14202 +struct vcmd_space_mask_v2 {
14203 +       uint64_t mask;
14204 +       uint32_t index;
14205 +};
14206 +
14207 +
14208 +#ifdef __KERNEL__
14209 +
14210 +extern int vc_enter_space_v1(struct vx_info *, void __user *);
14211 +extern int vc_set_space_v1(struct vx_info *, void __user *);
14212 +extern int vc_enter_space(struct vx_info *, void __user *);
14213 +extern int vc_set_space(struct vx_info *, void __user *);
14214 +extern int vc_get_space_mask(void __user *, int);
14215 +
14216 +#endif /* __KERNEL__ */
14217 +#endif /* _VX_SPACE_CMD_H */
14218 diff -NurpP --minimal linux-2.6.38.1/include/linux/vserver/switch.h linux-2.6.38.1-vs2.3.0.37-rc9/include/linux/vserver/switch.h
14219 --- linux-2.6.38.1/include/linux/vserver/switch.h       1970-01-01 01:00:00.000000000 +0100
14220 +++ linux-2.6.38.1-vs2.3.0.37-rc9/include/linux/vserver/switch.h        2011-01-29 02:01:07.000000000 +0100
14221 @@ -0,0 +1,98 @@
14222 +#ifndef _VX_SWITCH_H
14223 +#define _VX_SWITCH_H
14224 +
14225 +#include <linux/types.h>
14226 +
14227 +
14228 +#define VC_CATEGORY(c)         (((c) >> 24) & 0x3F)
14229 +#define VC_COMMAND(c)          (((c) >> 16) & 0xFF)
14230 +#define VC_VERSION(c)          ((c) & 0xFFF)
14231 +
14232 +#define VC_CMD(c, i, v)                ((((VC_CAT_ ## c) & 0x3F) << 24) \
14233 +                               | (((i) & 0xFF) << 16) | ((v) & 0xFFF))
14234 +
14235 +/*
14236 +
14237 +  Syscall Matrix V2.8
14238 +
14239 +        |VERSION|CREATE |MODIFY |MIGRATE|CONTROL|EXPERIM| |SPECIAL|SPECIAL|
14240 +        |STATS  |DESTROY|ALTER  |CHANGE |LIMIT  |TEST   | |       |       |
14241 +        |INFO   |SETUP  |       |MOVE   |       |       | |       |       |
14242 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
14243 +  SYSTEM |VERSION|VSETUP |VHOST  |       |       |       | |DEVICE |       |
14244 +  HOST   |     00|     01|     02|     03|     04|     05| |     06|     07|
14245 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
14246 +  CPU    |       |VPROC  |PROCALT|PROCMIG|PROCTRL|       | |SCHED. |       |
14247 +  PROCESS|     08|     09|     10|     11|     12|     13| |     14|     15|
14248 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
14249 +  MEMORY |       |       |       |       |MEMCTRL|       | |SWAP   |       |
14250 +        |     16|     17|     18|     19|     20|     21| |     22|     23|
14251 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
14252 +  NETWORK|       |VNET   |NETALT |NETMIG |NETCTL |       | |SERIAL |       |
14253 +        |     24|     25|     26|     27|     28|     29| |     30|     31|
14254 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
14255 +  DISK   |       |       |       |TAGMIG |DLIMIT |       | |INODE  |       |
14256 +  VFS    |     32|     33|     34|     35|     36|     37| |     38|     39|
14257 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
14258 +  OTHER  |VSTAT  |       |       |       |       |       | |VINFO  |       |
14259 +        |     40|     41|     42|     43|     44|     45| |     46|     47|
14260 +  =======+=======+=======+=======+=======+=======+=======+ +=======+=======+
14261 +  SPECIAL|EVENT  |       |       |       |FLAGS  |       | |VSPACE |       |
14262 +        |     48|     49|     50|     51|     52|     53| |     54|     55|
14263 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
14264 +  SPECIAL|DEBUG  |       |       |       |RLIMIT |SYSCALL| |       |COMPAT |
14265 +        |     56|     57|     58|     59|     60|TEST 61| |     62|     63|
14266 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
14267 +
14268 +*/
14269 +
14270 +#define VC_CAT_VERSION         0
14271 +
14272 +#define VC_CAT_VSETUP          1
14273 +#define VC_CAT_VHOST           2
14274 +
14275 +#define VC_CAT_DEVICE          6
14276 +
14277 +#define VC_CAT_VPROC           9
14278 +#define VC_CAT_PROCALT         10
14279 +#define VC_CAT_PROCMIG         11
14280 +#define VC_CAT_PROCTRL         12
14281 +
14282 +#define VC_CAT_SCHED           14
14283 +#define VC_CAT_MEMCTRL         20
14284 +
14285 +#define VC_CAT_VNET            25
14286 +#define VC_CAT_NETALT          26
14287 +#define VC_CAT_NETMIG          27
14288 +#define VC_CAT_NETCTRL         28
14289 +
14290 +#define VC_CAT_TAGMIG          35
14291 +#define VC_CAT_DLIMIT          36
14292 +#define VC_CAT_INODE           38
14293 +
14294 +#define VC_CAT_VSTAT           40
14295 +#define VC_CAT_VINFO           46
14296 +#define VC_CAT_EVENT           48
14297 +
14298 +#define VC_CAT_FLAGS           52
14299 +#define VC_CAT_VSPACE          54
14300 +#define VC_CAT_DEBUG           56
14301 +#define VC_CAT_RLIMIT          60
14302 +
14303 +#define VC_CAT_SYSTEST         61
14304 +#define VC_CAT_COMPAT          63
14305 +
14306 +/*  query version */
14307 +
14308 +#define VCMD_get_version       VC_CMD(VERSION, 0, 0)
14309 +#define VCMD_get_vci           VC_CMD(VERSION, 1, 0)
14310 +
14311 +
14312 +#ifdef __KERNEL__
14313 +
14314 +#include <linux/errno.h>
14315 +
14316 +#endif /* __KERNEL__ */
14317 +
14318 +#endif /* _VX_SWITCH_H */
14319 +
14320 diff -NurpP --minimal linux-2.6.38.1/include/linux/vserver/tag.h linux-2.6.38.1-vs2.3.0.37-rc9/include/linux/vserver/tag.h
14321 --- linux-2.6.38.1/include/linux/vserver/tag.h  1970-01-01 01:00:00.000000000 +0100
14322 +++ linux-2.6.38.1-vs2.3.0.37-rc9/include/linux/vserver/tag.h   2011-01-29 02:01:07.000000000 +0100
14323 @@ -0,0 +1,143 @@
14324 +#ifndef _DX_TAG_H
14325 +#define _DX_TAG_H
14326 +
14327 +#include <linux/types.h>
14328 +
14329 +
14330 +#define DX_TAG(in)     (IS_TAGGED(in))
14331 +
14332 +
14333 +#ifdef CONFIG_TAG_NFSD
14334 +#define DX_TAG_NFSD    1
14335 +#else
14336 +#define DX_TAG_NFSD    0
14337 +#endif
14338 +
14339 +
14340 +#ifdef CONFIG_TAGGING_NONE
14341 +
14342 +#define MAX_UID                0xFFFFFFFF
14343 +#define MAX_GID                0xFFFFFFFF
14344 +
14345 +#define INOTAG_TAG(cond, uid, gid, tag)        (0)
14346 +
14347 +#define TAGINO_UID(cond, uid, tag)     (uid)
14348 +#define TAGINO_GID(cond, gid, tag)     (gid)
14349 +
14350 +#endif
14351 +
14352 +
14353 +#ifdef CONFIG_TAGGING_GID16
14354 +
14355 +#define MAX_UID                0xFFFFFFFF
14356 +#define MAX_GID                0x0000FFFF
14357 +
14358 +#define INOTAG_TAG(cond, uid, gid, tag)        \
14359 +       ((cond) ? (((gid) >> 16) & 0xFFFF) : 0)
14360 +
14361 +#define TAGINO_UID(cond, uid, tag)     (uid)
14362 +#define TAGINO_GID(cond, gid, tag)     \
14363 +       ((cond) ? (((gid) & 0xFFFF) | ((tag) << 16)) : (gid))
14364 +
14365 +#endif
14366 +
14367 +
14368 +#ifdef CONFIG_TAGGING_ID24
14369 +
14370 +#define MAX_UID                0x00FFFFFF
14371 +#define MAX_GID                0x00FFFFFF
14372 +
14373 +#define INOTAG_TAG(cond, uid, gid, tag)        \
14374 +       ((cond) ? ((((uid) >> 16) & 0xFF00) | (((gid) >> 24) & 0xFF)) : 0)
14375 +
14376 +#define TAGINO_UID(cond, uid, tag)     \
14377 +       ((cond) ? (((uid) & 0xFFFFFF) | (((tag) & 0xFF00) << 16)) : (uid))
14378 +#define TAGINO_GID(cond, gid, tag)     \
14379 +       ((cond) ? (((gid) & 0xFFFFFF) | (((tag) & 0x00FF) << 24)) : (gid))
14380 +
14381 +#endif
14382 +
14383 +
14384 +#ifdef CONFIG_TAGGING_UID16
14385 +
14386 +#define MAX_UID                0x0000FFFF
14387 +#define MAX_GID                0xFFFFFFFF
14388 +
14389 +#define INOTAG_TAG(cond, uid, gid, tag)        \
14390 +       ((cond) ? (((uid) >> 16) & 0xFFFF) : 0)
14391 +
14392 +#define TAGINO_UID(cond, uid, tag)     \
14393 +       ((cond) ? (((uid) & 0xFFFF) | ((tag) << 16)) : (uid))
14394 +#define TAGINO_GID(cond, gid, tag)     (gid)
14395 +
14396 +#endif
14397 +
14398 +
14399 +#ifdef CONFIG_TAGGING_INTERN
14400 +
14401 +#define MAX_UID                0xFFFFFFFF
14402 +#define MAX_GID                0xFFFFFFFF
14403 +
14404 +#define INOTAG_TAG(cond, uid, gid, tag)        \
14405 +       ((cond) ? (tag) : 0)
14406 +
14407 +#define TAGINO_UID(cond, uid, tag)     (uid)
14408 +#define TAGINO_GID(cond, gid, tag)     (gid)
14409 +
14410 +#endif
14411 +
14412 +
14413 +#ifndef CONFIG_TAGGING_NONE
14414 +#define dx_current_fstag(sb)   \
14415 +       ((sb)->s_flags & MS_TAGGED ? dx_current_tag() : 0)
14416 +#else
14417 +#define dx_current_fstag(sb)   (0)
14418 +#endif
14419 +
14420 +#ifndef CONFIG_TAGGING_INTERN
14421 +#define TAGINO_TAG(cond, tag)  (0)
14422 +#else
14423 +#define TAGINO_TAG(cond, tag)  ((cond) ? (tag) : 0)
14424 +#endif
14425 +
14426 +#define INOTAG_UID(cond, uid, gid)     \
14427 +       ((cond) ? ((uid) & MAX_UID) : (uid))
14428 +#define INOTAG_GID(cond, uid, gid)     \
14429 +       ((cond) ? ((gid) & MAX_GID) : (gid))
14430 +
14431 +
14432 +static inline uid_t dx_map_uid(uid_t uid)
14433 +{
14434 +       if ((uid > MAX_UID) && (uid != -1))
14435 +               uid = -2;
14436 +       return (uid & MAX_UID);
14437 +}
14438 +
14439 +static inline gid_t dx_map_gid(gid_t gid)
14440 +{
14441 +       if ((gid > MAX_GID) && (gid != -1))
14442 +               gid = -2;
14443 +       return (gid & MAX_GID);
14444 +}
14445 +
14446 +struct peer_tag {
14447 +       int32_t xid;
14448 +       int32_t nid;
14449 +};
14450 +
14451 +#define dx_notagcheck(sb) ((sb) && ((sb)->s_flags & MS_NOTAGCHECK))
14452 +
14453 +int dx_parse_tag(char *string, tag_t *tag, int remove, int *mnt_flags,
14454 +                unsigned long *flags);
14455 +
14456 +#ifdef CONFIG_PROPAGATE
14457 +
14458 +void __dx_propagate_tag(struct nameidata *nd, struct inode *inode);
14459 +
14460 +#define dx_propagate_tag(n, i) __dx_propagate_tag(n, i)
14461 +
14462 +#else
14463 +#define dx_propagate_tag(n, i) do { } while (0)
14464 +#endif
14465 +
14466 +#endif /* _DX_TAG_H */
14467 diff -NurpP --minimal linux-2.6.38.1/include/linux/vserver/tag_cmd.h linux-2.6.38.1-vs2.3.0.37-rc9/include/linux/vserver/tag_cmd.h
14468 --- linux-2.6.38.1/include/linux/vserver/tag_cmd.h      1970-01-01 01:00:00.000000000 +0100
14469 +++ linux-2.6.38.1-vs2.3.0.37-rc9/include/linux/vserver/tag_cmd.h       2011-01-29 02:01:07.000000000 +0100
14470 @@ -0,0 +1,22 @@
14471 +#ifndef _VX_TAG_CMD_H
14472 +#define _VX_TAG_CMD_H
14473 +
14474 +
14475 +/* vinfo commands */
14476 +
14477 +#define VCMD_task_tag          VC_CMD(VINFO, 3, 0)
14478 +
14479 +#ifdef __KERNEL__
14480 +extern int vc_task_tag(uint32_t);
14481 +
14482 +#endif /* __KERNEL__ */
14483 +
14484 +/* context commands */
14485 +
14486 +#define VCMD_tag_migrate       VC_CMD(TAGMIG, 1, 0)
14487 +
14488 +#ifdef __KERNEL__
14489 +extern int vc_tag_migrate(uint32_t);
14490 +
14491 +#endif /* __KERNEL__ */
14492 +#endif /* _VX_TAG_CMD_H */
14493 diff -NurpP --minimal linux-2.6.38.1/include/net/addrconf.h linux-2.6.38.1-vs2.3.0.37-rc9/include/net/addrconf.h
14494 --- linux-2.6.38.1/include/net/addrconf.h       2011-03-15 18:07:40.000000000 +0100
14495 +++ linux-2.6.38.1-vs2.3.0.37-rc9/include/net/addrconf.h        2011-01-29 02:01:07.000000000 +0100
14496 @@ -82,7 +82,8 @@ extern int                    ipv6_dev_get_saddr(struct n
14497                                                struct net_device *dev,
14498                                                const struct in6_addr *daddr,
14499                                                unsigned int srcprefs,
14500 -                                              struct in6_addr *saddr);
14501 +                                              struct in6_addr *saddr,
14502 +                                              struct nx_info *nxi);
14503  extern int                     ipv6_get_lladdr(struct net_device *dev,
14504                                                 struct in6_addr *addr,
14505                                                 unsigned char banned_flags);
14506 diff -NurpP --minimal linux-2.6.38.1/include/net/af_unix.h linux-2.6.38.1-vs2.3.0.37-rc9/include/net/af_unix.h
14507 --- linux-2.6.38.1/include/net/af_unix.h        2011-01-05 21:50:35.000000000 +0100
14508 +++ linux-2.6.38.1-vs2.3.0.37-rc9/include/net/af_unix.h 2011-01-29 02:01:07.000000000 +0100
14509 @@ -4,6 +4,7 @@
14510  #include <linux/socket.h>
14511  #include <linux/un.h>
14512  #include <linux/mutex.h>
14513 +#include <linux/vs_base.h>
14514  #include <net/sock.h>
14515  
14516  extern void unix_inflight(struct file *fp);
14517 diff -NurpP --minimal linux-2.6.38.1/include/net/inet_timewait_sock.h linux-2.6.38.1-vs2.3.0.37-rc9/include/net/inet_timewait_sock.h
14518 --- linux-2.6.38.1/include/net/inet_timewait_sock.h     2011-03-15 18:07:40.000000000 +0100
14519 +++ linux-2.6.38.1-vs2.3.0.37-rc9/include/net/inet_timewait_sock.h      2011-01-29 03:12:58.000000000 +0100
14520 @@ -113,6 +113,10 @@ struct inet_timewait_sock {
14521  #define tw_net                 __tw_common.skc_net
14522  #define tw_daddr               __tw_common.skc_daddr
14523  #define tw_rcv_saddr           __tw_common.skc_rcv_saddr
14524 +#define tw_xid                 __tw_common.skc_xid
14525 +#define tw_vx_info             __tw_common.skc_vx_info
14526 +#define tw_nid                 __tw_common.skc_nid
14527 +#define tw_nx_info             __tw_common.skc_nx_info
14528         int                     tw_timeout;
14529         volatile unsigned char  tw_substate;
14530         unsigned char           tw_rcv_wscale;
14531 diff -NurpP --minimal linux-2.6.38.1/include/net/route.h linux-2.6.38.1-vs2.3.0.37-rc9/include/net/route.h
14532 --- linux-2.6.38.1/include/net/route.h  2011-03-15 18:07:40.000000000 +0100
14533 +++ linux-2.6.38.1-vs2.3.0.37-rc9/include/net/route.h   2011-01-29 02:01:07.000000000 +0100
14534 @@ -153,6 +153,9 @@ static inline void ip_rt_put(struct rtab
14535                 dst_release(&rt->dst);
14536  }
14537  
14538 +#include <linux/vs_base.h>
14539 +#include <linux/vs_inet.h>
14540 +
14541  #define IPTOS_RT_MASK  (IPTOS_TOS_MASK & ~3)
14542  
14543  extern const __u8 ip_tos2prio[16];
14544 @@ -162,6 +165,9 @@ static inline char rt_tos2priority(u8 to
14545         return ip_tos2prio[IPTOS_TOS(tos)>>1];
14546  }
14547  
14548 +extern int ip_v4_find_src(struct net *net, struct nx_info *,
14549 +       struct rtable **, struct flowi *);
14550 +
14551  static inline int ip_route_connect(struct rtable **rp, __be32 dst,
14552                                    __be32 src, u32 tos, int oif, u8 protocol,
14553                                    __be16 sport, __be16 dport, struct sock *sk,
14554 @@ -177,11 +183,24 @@ static inline int ip_route_connect(struc
14555                             .fl_ip_dport = dport };
14556         int err;
14557         struct net *net = sock_net(sk);
14558 +       struct nx_info *nx_info = current_nx_info();
14559  
14560         if (inet_sk(sk)->transparent)
14561                 fl.flags |= FLOWI_FLAG_ANYSRC;
14562  
14563 -       if (!dst || !src) {
14564 +       if (sk)
14565 +               nx_info = sk->sk_nx_info;
14566 +
14567 +       vxdprintk(VXD_CBIT(net, 4),
14568 +               "ip_route_connect(%p) %p,%p;%lx",
14569 +               sk, nx_info, sk->sk_socket,
14570 +               (sk->sk_socket?sk->sk_socket->flags:0));
14571 +
14572 +       err = ip_v4_find_src(net, nx_info, rp, &fl);
14573 +       if (err)
14574 +               return err;
14575 +
14576 +       if (!fl.fl4_dst || !fl.fl4_src) {
14577                 err = __ip_route_output_key(net, rp, &fl);
14578                 if (err)
14579                         return err;
14580 diff -NurpP --minimal linux-2.6.38.1/include/net/sock.h linux-2.6.38.1-vs2.3.0.37-rc9/include/net/sock.h
14581 --- linux-2.6.38.1/include/net/sock.h   2011-03-15 18:07:41.000000000 +0100
14582 +++ linux-2.6.38.1-vs2.3.0.37-rc9/include/net/sock.h    2011-02-17 02:17:51.000000000 +0100
14583 @@ -148,6 +148,10 @@ struct sock_common {
14584  #ifdef CONFIG_NET_NS
14585         struct net              *skc_net;
14586  #endif
14587 +       xid_t                   skc_xid;
14588 +       struct vx_info          *skc_vx_info;
14589 +       nid_t                   skc_nid;
14590 +       struct nx_info          *skc_nx_info;
14591         /*
14592          * fields between dontcopy_begin/dontcopy_end
14593          * are not copied in sock_copy()
14594 @@ -256,6 +260,10 @@ struct sock {
14595  #define sk_bind_node           __sk_common.skc_bind_node
14596  #define sk_prot                        __sk_common.skc_prot
14597  #define sk_net                 __sk_common.skc_net
14598 +#define sk_xid                 __sk_common.skc_xid
14599 +#define sk_vx_info             __sk_common.skc_vx_info
14600 +#define sk_nid                 __sk_common.skc_nid
14601 +#define sk_nx_info             __sk_common.skc_nx_info
14602         socket_lock_t           sk_lock;
14603         struct sk_buff_head     sk_receive_queue;
14604         /*
14605 diff -NurpP --minimal linux-2.6.38.1/init/Kconfig linux-2.6.38.1-vs2.3.0.37-rc9/init/Kconfig
14606 --- linux-2.6.38.1/init/Kconfig 2011-03-15 18:07:41.000000000 +0100
14607 +++ linux-2.6.38.1-vs2.3.0.37-rc9/init/Kconfig  2011-01-29 02:01:07.000000000 +0100
14608 @@ -559,6 +559,7 @@ config HAVE_UNSTABLE_SCHED_CLOCK
14609  menuconfig CGROUPS
14610         boolean "Control Group support"
14611         depends on EVENTFD
14612 +       default y
14613         help
14614           This option adds support for grouping sets of processes together, for
14615           use with process control subsystems such as Cpusets, CFS, memory
14616 @@ -584,6 +585,7 @@ config CGROUP_DEBUG
14617  
14618  config CGROUP_NS
14619         bool "Namespace cgroup subsystem"
14620 +       default n
14621         help
14622           Provides a simple namespace cgroup subsystem to
14623           provide hierarchical naming of sets of namespaces,
14624 diff -NurpP --minimal linux-2.6.38.1/init/main.c linux-2.6.38.1-vs2.3.0.37-rc9/init/main.c
14625 --- linux-2.6.38.1/init/main.c  2011-03-15 18:07:41.000000000 +0100
14626 +++ linux-2.6.38.1-vs2.3.0.37-rc9/init/main.c   2011-01-29 02:21:25.000000000 +0100
14627 @@ -68,6 +68,7 @@
14628  #include <linux/shmem_fs.h>
14629  #include <linux/slab.h>
14630  #include <linux/perf_event.h>
14631 +#include <linux/vserver/percpu.h>
14632  
14633  #include <asm/io.h>
14634  #include <asm/bugs.h>
14635 diff -NurpP --minimal linux-2.6.38.1/ipc/mqueue.c linux-2.6.38.1-vs2.3.0.37-rc9/ipc/mqueue.c
14636 --- linux-2.6.38.1/ipc/mqueue.c 2011-03-15 18:07:41.000000000 +0100
14637 +++ linux-2.6.38.1-vs2.3.0.37-rc9/ipc/mqueue.c  2011-01-29 02:01:07.000000000 +0100
14638 @@ -33,6 +33,8 @@
14639  #include <linux/pid.h>
14640  #include <linux/ipc_namespace.h>
14641  #include <linux/slab.h>
14642 +#include <linux/vs_context.h>
14643 +#include <linux/vs_limit.h>
14644  
14645  #include <net/sock.h>
14646  #include "util.h"
14647 @@ -66,6 +68,7 @@ struct mqueue_inode_info {
14648         struct sigevent notify;
14649         struct pid* notify_owner;
14650         struct user_struct *user;       /* user who created, for accounting */
14651 +       struct vx_info *vxi;
14652         struct sock *notify_sock;
14653         struct sk_buff *notify_cookie;
14654  
14655 @@ -126,6 +129,7 @@ static struct inode *mqueue_get_inode(st
14656                 if (S_ISREG(mode)) {
14657                         struct mqueue_inode_info *info;
14658                         struct task_struct *p = current;
14659 +                       struct vx_info *vxi = p->vx_info;
14660                         unsigned long mq_bytes, mq_msg_tblsz;
14661  
14662                         inode->i_fop = &mqueue_file_operations;
14663 @@ -139,6 +143,7 @@ static struct inode *mqueue_get_inode(st
14664                         info->notify_owner = NULL;
14665                         info->qsize = 0;
14666                         info->user = NULL;      /* set when all is ok */
14667 +                       info->vxi = NULL;
14668                         memset(&info->attr, 0, sizeof(info->attr));
14669                         info->attr.mq_maxmsg = ipc_ns->mq_msg_max;
14670                         info->attr.mq_msgsize = ipc_ns->mq_msgsize_max;
14671 @@ -157,16 +162,19 @@ static struct inode *mqueue_get_inode(st
14672                         spin_lock(&mq_lock);
14673                         if (u->mq_bytes + mq_bytes < u->mq_bytes ||
14674                             u->mq_bytes + mq_bytes >
14675 -                           task_rlimit(p, RLIMIT_MSGQUEUE)) {
14676 +                           task_rlimit(p, RLIMIT_MSGQUEUE) ||
14677 +                           !vx_ipcmsg_avail(vxi, mq_bytes)) {
14678                                 spin_unlock(&mq_lock);
14679                                 /* mqueue_evict_inode() releases info->messages */
14680                                 goto out_inode;
14681                         }
14682                         u->mq_bytes += mq_bytes;
14683 +                       vx_ipcmsg_add(vxi, u, mq_bytes);
14684                         spin_unlock(&mq_lock);
14685  
14686                         /* all is ok */
14687                         info->user = get_uid(u);
14688 +                       info->vxi = get_vx_info(vxi);
14689                 } else if (S_ISDIR(mode)) {
14690                         inc_nlink(inode);
14691                         /* Some things misbehave if size == 0 on a directory */
14692 @@ -275,8 +283,11 @@ static void mqueue_evict_inode(struct in
14693             + info->attr.mq_msgsize);
14694         user = info->user;
14695         if (user) {
14696 +               struct vx_info *vxi = info->vxi;
14697 +
14698                 spin_lock(&mq_lock);
14699                 user->mq_bytes -= mq_bytes;
14700 +               vx_ipcmsg_sub(vxi, user, mq_bytes);
14701                 /*
14702                  * get_ns_from_inode() ensures that the
14703                  * (ipc_ns = sb->s_fs_info) is either a valid ipc_ns
14704 @@ -286,6 +297,7 @@ static void mqueue_evict_inode(struct in
14705                 if (ipc_ns)
14706                         ipc_ns->mq_queues_count--;
14707                 spin_unlock(&mq_lock);
14708 +               put_vx_info(vxi);
14709                 free_uid(user);
14710         }
14711         if (ipc_ns)
14712 diff -NurpP --minimal linux-2.6.38.1/ipc/msg.c linux-2.6.38.1-vs2.3.0.37-rc9/ipc/msg.c
14713 --- linux-2.6.38.1/ipc/msg.c    2010-08-02 16:52:57.000000000 +0200
14714 +++ linux-2.6.38.1-vs2.3.0.37-rc9/ipc/msg.c     2011-01-29 02:01:07.000000000 +0100
14715 @@ -37,6 +37,7 @@
14716  #include <linux/rwsem.h>
14717  #include <linux/nsproxy.h>
14718  #include <linux/ipc_namespace.h>
14719 +#include <linux/vs_base.h>
14720  
14721  #include <asm/current.h>
14722  #include <asm/uaccess.h>
14723 @@ -190,6 +191,7 @@ static int newque(struct ipc_namespace *
14724  
14725         msq->q_perm.mode = msgflg & S_IRWXUGO;
14726         msq->q_perm.key = key;
14727 +       msq->q_perm.xid = vx_current_xid();
14728  
14729         msq->q_perm.security = NULL;
14730         retval = security_msg_queue_alloc(msq);
14731 diff -NurpP --minimal linux-2.6.38.1/ipc/namespace.c linux-2.6.38.1-vs2.3.0.37-rc9/ipc/namespace.c
14732 --- linux-2.6.38.1/ipc/namespace.c      2009-09-10 15:26:27.000000000 +0200
14733 +++ linux-2.6.38.1-vs2.3.0.37-rc9/ipc/namespace.c       2011-01-29 02:01:07.000000000 +0100
14734 @@ -11,6 +11,8 @@
14735  #include <linux/slab.h>
14736  #include <linux/fs.h>
14737  #include <linux/mount.h>
14738 +#include <linux/vs_base.h>
14739 +#include <linux/vserver/global.h>
14740  
14741  #include "util.h"
14742  
14743 diff -NurpP --minimal linux-2.6.38.1/ipc/sem.c linux-2.6.38.1-vs2.3.0.37-rc9/ipc/sem.c
14744 --- linux-2.6.38.1/ipc/sem.c    2010-10-21 13:07:56.000000000 +0200
14745 +++ linux-2.6.38.1-vs2.3.0.37-rc9/ipc/sem.c     2011-01-29 02:01:07.000000000 +0100
14746 @@ -86,6 +86,8 @@
14747  #include <linux/rwsem.h>
14748  #include <linux/nsproxy.h>
14749  #include <linux/ipc_namespace.h>
14750 +#include <linux/vs_base.h>
14751 +#include <linux/vs_limit.h>
14752  
14753  #include <asm/uaccess.h>
14754  #include "util.h"
14755 @@ -260,6 +262,7 @@ static int newary(struct ipc_namespace *
14756  
14757         sma->sem_perm.mode = (semflg & S_IRWXUGO);
14758         sma->sem_perm.key = key;
14759 +       sma->sem_perm.xid = vx_current_xid();
14760  
14761         sma->sem_perm.security = NULL;
14762         retval = security_sem_alloc(sma);
14763 @@ -275,6 +278,9 @@ static int newary(struct ipc_namespace *
14764                 return id;
14765         }
14766         ns->used_sems += nsems;
14767 +       /* FIXME: obsoleted? */
14768 +       vx_semary_inc(sma);
14769 +       vx_nsems_add(sma, nsems);
14770  
14771         sma->sem_base = (struct sem *) &sma[1];
14772  
14773 @@ -730,6 +736,9 @@ static void freeary(struct ipc_namespace
14774  
14775         wake_up_sem_queue_do(&tasks);
14776         ns->used_sems -= sma->sem_nsems;
14777 +       /* FIXME: obsoleted? */
14778 +       vx_nsems_sub(sma, sma->sem_nsems);
14779 +       vx_semary_dec(sma);
14780         security_sem_free(sma);
14781         ipc_rcu_putref(sma);
14782  }
14783 diff -NurpP --minimal linux-2.6.38.1/ipc/shm.c linux-2.6.38.1-vs2.3.0.37-rc9/ipc/shm.c
14784 --- linux-2.6.38.1/ipc/shm.c    2011-01-05 21:50:37.000000000 +0100
14785 +++ linux-2.6.38.1-vs2.3.0.37-rc9/ipc/shm.c     2011-01-29 02:01:07.000000000 +0100
14786 @@ -39,6 +39,8 @@
14787  #include <linux/nsproxy.h>
14788  #include <linux/mount.h>
14789  #include <linux/ipc_namespace.h>
14790 +#include <linux/vs_context.h>
14791 +#include <linux/vs_limit.h>
14792  
14793  #include <asm/uaccess.h>
14794  
14795 @@ -173,7 +175,12 @@ static void shm_open(struct vm_area_stru
14796   */
14797  static void shm_destroy(struct ipc_namespace *ns, struct shmid_kernel *shp)
14798  {
14799 -       ns->shm_tot -= (shp->shm_segsz + PAGE_SIZE - 1) >> PAGE_SHIFT;
14800 +       struct vx_info *vxi = lookup_vx_info(shp->shm_perm.xid);
14801 +       int numpages = (shp->shm_segsz + PAGE_SIZE - 1) >> PAGE_SHIFT;
14802 +
14803 +       vx_ipcshm_sub(vxi, shp, numpages);
14804 +       ns->shm_tot -= numpages;
14805 +
14806         shm_rmid(ns, shp);
14807         shm_unlock(shp);
14808         if (!is_file_hugepages(shp->shm_file))
14809 @@ -183,6 +190,7 @@ static void shm_destroy(struct ipc_names
14810                                                 shp->mlock_user);
14811         fput (shp->shm_file);
14812         security_shm_free(shp);
14813 +       put_vx_info(vxi);
14814         ipc_rcu_putref(shp);
14815  }
14816  
14817 @@ -355,11 +363,15 @@ static int newseg(struct ipc_namespace *
14818         if (ns->shm_tot + numpages > ns->shm_ctlall)
14819                 return -ENOSPC;
14820  
14821 +       if (!vx_ipcshm_avail(current_vx_info(), numpages))
14822 +               return -ENOSPC;
14823 +
14824         shp = ipc_rcu_alloc(sizeof(*shp));
14825         if (!shp)
14826                 return -ENOMEM;
14827  
14828         shp->shm_perm.key = key;
14829 +       shp->shm_perm.xid = vx_current_xid();
14830         shp->shm_perm.mode = (shmflg & S_IRWXUGO);
14831         shp->mlock_user = NULL;
14832  
14833 @@ -413,6 +425,7 @@ static int newseg(struct ipc_namespace *
14834         ns->shm_tot += numpages;
14835         error = shp->shm_perm.id;
14836         shm_unlock(shp);
14837 +       vx_ipcshm_add(current_vx_info(), key, numpages);
14838         return error;
14839  
14840  no_id:
14841 diff -NurpP --minimal linux-2.6.38.1/kernel/Makefile linux-2.6.38.1-vs2.3.0.37-rc9/kernel/Makefile
14842 --- linux-2.6.38.1/kernel/Makefile      2011-03-15 18:07:41.000000000 +0100
14843 +++ linux-2.6.38.1-vs2.3.0.37-rc9/kernel/Makefile       2011-01-29 02:01:07.000000000 +0100
14844 @@ -25,6 +25,7 @@ CFLAGS_REMOVE_perf_event.o = -pg
14845  CFLAGS_REMOVE_irq_work.o = -pg
14846  endif
14847  
14848 +obj-y += vserver/
14849  obj-$(CONFIG_FREEZER) += freezer.o
14850  obj-$(CONFIG_PROFILING) += profile.o
14851  obj-$(CONFIG_SYSCTL_SYSCALL_CHECK) += sysctl_check.o
14852 diff -NurpP --minimal linux-2.6.38.1/kernel/capability.c linux-2.6.38.1-vs2.3.0.37-rc9/kernel/capability.c
14853 --- linux-2.6.38.1/kernel/capability.c  2011-03-15 18:07:41.000000000 +0100
14854 +++ linux-2.6.38.1-vs2.3.0.37-rc9/kernel/capability.c   2011-02-17 02:17:51.000000000 +0100
14855 @@ -14,6 +14,7 @@
14856  #include <linux/security.h>
14857  #include <linux/syscalls.h>
14858  #include <linux/pid_namespace.h>
14859 +#include <linux/vs_context.h>
14860  #include <asm/uaccess.h>
14861  
14862  /*
14863 @@ -119,6 +120,7 @@ static int cap_validate_magic(cap_user_h
14864         return 0;
14865  }
14866  
14867 +
14868  /*
14869   * The only thing that can change the capabilities of the current
14870   * process is the current process. As such, we can't be in this code
14871 @@ -289,6 +291,8 @@ error:
14872         return ret;
14873  }
14874  
14875 +#include <linux/vserver/base.h>
14876 +
14877  /**
14878   * capable - Determine if the current task has a superior capability in effect
14879   * @cap: The capability to be tested for
14880 @@ -301,6 +305,9 @@ error:
14881   */
14882  int capable(int cap)
14883  {
14884 +       /* here for now so we don't require task locking */
14885 +       if (vs_check_bit(VXC_CAP_MASK, cap) && !vx_mcaps(1L << cap))
14886 +               return 0;
14887         if (unlikely(!cap_valid(cap))) {
14888                 printk(KERN_CRIT "capable() called with invalid cap=%u\n", cap);
14889                 BUG();
14890 diff -NurpP --minimal linux-2.6.38.1/kernel/compat.c linux-2.6.38.1-vs2.3.0.37-rc9/kernel/compat.c
14891 --- linux-2.6.38.1/kernel/compat.c      2010-10-21 13:07:56.000000000 +0200
14892 +++ linux-2.6.38.1-vs2.3.0.37-rc9/kernel/compat.c       2011-01-29 02:01:07.000000000 +0100
14893 @@ -914,7 +914,7 @@ asmlinkage long compat_sys_stime(compat_
14894         if (err)
14895                 return err;
14896  
14897 -       do_settimeofday(&tv);
14898 +       vx_settimeofday(&tv);
14899         return 0;
14900  }
14901  
14902 diff -NurpP --minimal linux-2.6.38.1/kernel/cred.c linux-2.6.38.1-vs2.3.0.37-rc9/kernel/cred.c
14903 --- linux-2.6.38.1/kernel/cred.c        2011-03-15 18:07:41.000000000 +0100
14904 +++ linux-2.6.38.1-vs2.3.0.37-rc9/kernel/cred.c 2011-02-17 02:17:51.000000000 +0100
14905 @@ -60,31 +60,6 @@ struct cred init_cred = {
14906  #endif
14907  };
14908  
14909 -static inline void set_cred_subscribers(struct cred *cred, int n)
14910 -{
14911 -#ifdef CONFIG_DEBUG_CREDENTIALS
14912 -       atomic_set(&cred->subscribers, n);
14913 -#endif
14914 -}
14915 -
14916 -static inline int read_cred_subscribers(const struct cred *cred)
14917 -{
14918 -#ifdef CONFIG_DEBUG_CREDENTIALS
14919 -       return atomic_read(&cred->subscribers);
14920 -#else
14921 -       return 0;
14922 -#endif
14923 -}
14924 -
14925 -static inline void alter_cred_subscribers(const struct cred *_cred, int n)
14926 -{
14927 -#ifdef CONFIG_DEBUG_CREDENTIALS
14928 -       struct cred *cred = (struct cred *) _cred;
14929 -
14930 -       atomic_add(n, &cred->subscribers);
14931 -#endif
14932 -}
14933 -
14934  /*
14935   * Dispose of the shared task group credentials
14936   */
14937 @@ -280,21 +255,16 @@ error:
14938   *
14939   * Call commit_creds() or abort_creds() to clean up.
14940   */
14941 -struct cred *prepare_creds(void)
14942 +struct cred *__prepare_creds(const struct cred *old)
14943  {
14944 -       struct task_struct *task = current;
14945 -       const struct cred *old;
14946         struct cred *new;
14947  
14948 -       validate_process_creds();
14949 -
14950         new = kmem_cache_alloc(cred_jar, GFP_KERNEL);
14951         if (!new)
14952                 return NULL;
14953  
14954         kdebug("prepare_creds() alloc %p", new);
14955  
14956 -       old = task->cred;
14957         memcpy(new, old, sizeof(struct cred));
14958  
14959         atomic_set(&new->usage, 1);
14960 @@ -321,6 +291,13 @@ error:
14961         abort_creds(new);
14962         return NULL;
14963  }
14964 +
14965 +struct cred *prepare_creds(void)
14966 +{
14967 +       validate_process_creds();
14968 +
14969 +       return __prepare_creds(current->cred);
14970 +}
14971  EXPORT_SYMBOL(prepare_creds);
14972  
14973  /*
14974 diff -NurpP --minimal linux-2.6.38.1/kernel/exit.c linux-2.6.38.1-vs2.3.0.37-rc9/kernel/exit.c
14975 --- linux-2.6.38.1/kernel/exit.c        2011-03-15 18:07:41.000000000 +0100
14976 +++ linux-2.6.38.1-vs2.3.0.37-rc9/kernel/exit.c 2011-01-29 02:01:07.000000000 +0100
14977 @@ -48,6 +48,10 @@
14978  #include <linux/fs_struct.h>
14979  #include <linux/init_task.h>
14980  #include <linux/perf_event.h>
14981 +#include <linux/vs_limit.h>
14982 +#include <linux/vs_context.h>
14983 +#include <linux/vs_network.h>
14984 +#include <linux/vs_pid.h>
14985  #include <trace/events/sched.h>
14986  #include <linux/hw_breakpoint.h>
14987  #include <linux/oom.h>
14988 @@ -494,9 +498,11 @@ static void close_files(struct files_str
14989                                         filp_close(file, files);
14990                                         cond_resched();
14991                                 }
14992 +                               vx_openfd_dec(i);
14993                         }
14994                         i++;
14995                         set >>= 1;
14996 +                       cond_resched();
14997                 }
14998         }
14999  }
15000 @@ -1047,11 +1053,16 @@ NORET_TYPE void do_exit(long code)
15001  
15002         validate_creds_for_do_exit(tsk);
15003  
15004 +       /* needs to stay after exit_notify() */
15005 +       exit_vx_info(tsk, code);
15006 +       exit_nx_info(tsk);
15007 +
15008         preempt_disable();
15009         exit_rcu();
15010         /* causes final put_task_struct in finish_task_switch(). */
15011         tsk->state = TASK_DEAD;
15012         schedule();
15013 +       printk("bad task: %p [%lx]\n", current, current->state);
15014         BUG();
15015         /* Avoid "noreturn function does return".  */
15016         for (;;)
15017 diff -NurpP --minimal linux-2.6.38.1/kernel/fork.c linux-2.6.38.1-vs2.3.0.37-rc9/kernel/fork.c
15018 --- linux-2.6.38.1/kernel/fork.c        2011-03-15 18:07:41.000000000 +0100
15019 +++ linux-2.6.38.1-vs2.3.0.37-rc9/kernel/fork.c 2011-01-29 03:19:29.000000000 +0100
15020 @@ -67,6 +67,10 @@
15021  #include <linux/user-return-notifier.h>
15022  #include <linux/oom.h>
15023  #include <linux/khugepaged.h>
15024 +#include <linux/vs_context.h>
15025 +#include <linux/vs_network.h>
15026 +#include <linux/vs_limit.h>
15027 +#include <linux/vs_memory.h>
15028  
15029  #include <asm/pgtable.h>
15030  #include <asm/pgalloc.h>
15031 @@ -162,6 +166,8 @@ void free_task(struct task_struct *tsk)
15032         account_kernel_stack(tsk->stack, -1);
15033         free_thread_info(tsk->stack);
15034         rt_mutex_debug_task_free(tsk);
15035 +       clr_vx_info(&tsk->vx_info);
15036 +       clr_nx_info(&tsk->nx_info);
15037         ftrace_graph_exit_task(tsk);
15038         free_task_struct(tsk);
15039  }
15040 @@ -500,6 +506,7 @@ static struct mm_struct * mm_init(struct
15041         if (likely(!mm_alloc_pgd(mm))) {
15042                 mm->def_flags = 0;
15043                 mmu_notifier_mm_init(mm);
15044 +               set_vx_info(&mm->mm_vx_info, p->vx_info);
15045                 return mm;
15046         }
15047  
15048 @@ -536,6 +543,7 @@ void __mmdrop(struct mm_struct *mm)
15049  #ifdef CONFIG_TRANSPARENT_HUGEPAGE
15050         VM_BUG_ON(mm->pmd_huge_pte);
15051  #endif
15052 +       clr_vx_info(&mm->mm_vx_info);
15053         free_mm(mm);
15054  }
15055  EXPORT_SYMBOL_GPL(__mmdrop);
15056 @@ -672,6 +680,7 @@ struct mm_struct *dup_mm(struct task_str
15057                 goto fail_nomem;
15058  
15059         memcpy(mm, oldmm, sizeof(*mm));
15060 +       mm->mm_vx_info = NULL;
15061  
15062         /* Initializing for Swap token stuff */
15063         mm->token_priority = 0;
15064 @@ -714,6 +723,7 @@ fail_nocontext:
15065          * If init_new_context() failed, we cannot use mmput() to free the mm
15066          * because it calls destroy_context()
15067          */
15068 +       clr_vx_info(&mm->mm_vx_info);
15069         mm_free_pgd(mm);
15070         free_mm(mm);
15071         return NULL;
15072 @@ -995,6 +1005,8 @@ static struct task_struct *copy_process(
15073         int retval;
15074         struct task_struct *p;
15075         int cgroup_callbacks_done = 0;
15076 +       struct vx_info *vxi;
15077 +       struct nx_info *nxi;
15078  
15079         if ((clone_flags & (CLONE_NEWNS|CLONE_FS)) == (CLONE_NEWNS|CLONE_FS))
15080                 return ERR_PTR(-EINVAL);
15081 @@ -1041,7 +1053,12 @@ static struct task_struct *copy_process(
15082         DEBUG_LOCKS_WARN_ON(!p->hardirqs_enabled);
15083         DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
15084  #endif
15085 +       init_vx_info(&p->vx_info, current_vx_info());
15086 +       init_nx_info(&p->nx_info, current_nx_info());
15087 +
15088         retval = -EAGAIN;
15089 +       if (!vx_nproc_avail(1))
15090 +               goto bad_fork_free;
15091         if (atomic_read(&p->real_cred->user->processes) >=
15092                         task_rlimit(p, RLIMIT_NPROC)) {
15093                 if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE) &&
15094 @@ -1306,6 +1323,18 @@ static struct task_struct *copy_process(
15095  
15096         total_forks++;
15097         spin_unlock(&current->sighand->siglock);
15098 +
15099 +       /* p is copy of current */
15100 +       vxi = p->vx_info;
15101 +       if (vxi) {
15102 +               claim_vx_info(vxi, p);
15103 +               atomic_inc(&vxi->cvirt.nr_threads);
15104 +               atomic_inc(&vxi->cvirt.total_forks);
15105 +               vx_nproc_inc(p);
15106 +       }
15107 +       nxi = p->nx_info;
15108 +       if (nxi)
15109 +               claim_nx_info(nxi, p);
15110         write_unlock_irq(&tasklist_lock);
15111         proc_fork_connector(p);
15112         cgroup_post_fork(p);
15113 diff -NurpP --minimal linux-2.6.38.1/kernel/kthread.c linux-2.6.38.1-vs2.3.0.37-rc9/kernel/kthread.c
15114 --- linux-2.6.38.1/kernel/kthread.c     2011-03-15 18:07:41.000000000 +0100
15115 +++ linux-2.6.38.1-vs2.3.0.37-rc9/kernel/kthread.c      2011-01-29 02:01:07.000000000 +0100
15116 @@ -16,6 +16,7 @@
15117  #include <linux/mutex.h>
15118  #include <linux/slab.h>
15119  #include <linux/freezer.h>
15120 +#include <linux/vs_pid.h>
15121  #include <trace/events/sched.h>
15122  
15123  static DEFINE_SPINLOCK(kthread_create_lock);
15124 diff -NurpP --minimal linux-2.6.38.1/kernel/nsproxy.c linux-2.6.38.1-vs2.3.0.37-rc9/kernel/nsproxy.c
15125 --- linux-2.6.38.1/kernel/nsproxy.c     2010-07-07 18:31:57.000000000 +0200
15126 +++ linux-2.6.38.1-vs2.3.0.37-rc9/kernel/nsproxy.c      2011-01-29 02:01:07.000000000 +0100
15127 @@ -20,6 +20,8 @@
15128  #include <linux/mnt_namespace.h>
15129  #include <linux/utsname.h>
15130  #include <linux/pid_namespace.h>
15131 +#include <linux/vserver/global.h>
15132 +#include <linux/vserver/debug.h>
15133  #include <net/net_namespace.h>
15134  #include <linux/ipc_namespace.h>
15135  
15136 @@ -43,8 +45,11 @@ static inline struct nsproxy *create_nsp
15137         struct nsproxy *nsproxy;
15138  
15139         nsproxy = kmem_cache_alloc(nsproxy_cachep, GFP_KERNEL);
15140 -       if (nsproxy)
15141 +       if (nsproxy) {
15142                 atomic_set(&nsproxy->count, 1);
15143 +               atomic_inc(&vs_global_nsproxy);
15144 +       }
15145 +       vxdprintk(VXD_CBIT(space, 2), "create_nsproxy = %p[1]", nsproxy);
15146         return nsproxy;
15147  }
15148  
15149 @@ -53,41 +58,52 @@ static inline struct nsproxy *create_nsp
15150   * Return the newly created nsproxy.  Do not attach this to the task,
15151   * leave it to the caller to do proper locking and attach it to task.
15152   */
15153 -static struct nsproxy *create_new_namespaces(unsigned long flags,
15154 -                       struct task_struct *tsk, struct fs_struct *new_fs)
15155 +static struct nsproxy *unshare_namespaces(unsigned long flags,
15156 +                       struct nsproxy *orig, struct fs_struct *new_fs)
15157  {
15158         struct nsproxy *new_nsp;
15159         int err;
15160  
15161 +       vxdprintk(VXD_CBIT(space, 4),
15162 +               "unshare_namespaces(0x%08lx,%p,%p)",
15163 +               flags, orig, new_fs);
15164 +
15165         new_nsp = create_nsproxy();
15166         if (!new_nsp)
15167                 return ERR_PTR(-ENOMEM);
15168  
15169 -       new_nsp->mnt_ns = copy_mnt_ns(flags, tsk->nsproxy->mnt_ns, new_fs);
15170 +       new_nsp->mnt_ns = copy_mnt_ns(flags, orig->mnt_ns, new_fs);
15171         if (IS_ERR(new_nsp->mnt_ns)) {
15172                 err = PTR_ERR(new_nsp->mnt_ns);
15173                 goto out_ns;
15174         }
15175  
15176 -       new_nsp->uts_ns = copy_utsname(flags, tsk->nsproxy->uts_ns);
15177 +       new_nsp->uts_ns = copy_utsname(flags, orig->uts_ns);
15178         if (IS_ERR(new_nsp->uts_ns)) {
15179                 err = PTR_ERR(new_nsp->uts_ns);
15180                 goto out_uts;
15181         }
15182  
15183 -       new_nsp->ipc_ns = copy_ipcs(flags, tsk->nsproxy->ipc_ns);
15184 +       new_nsp->ipc_ns = copy_ipcs(flags, orig->ipc_ns);
15185         if (IS_ERR(new_nsp->ipc_ns)) {
15186                 err = PTR_ERR(new_nsp->ipc_ns);
15187                 goto out_ipc;
15188         }
15189  
15190 -       new_nsp->pid_ns = copy_pid_ns(flags, task_active_pid_ns(tsk));
15191 +       new_nsp->pid_ns = copy_pid_ns(flags, orig->pid_ns);
15192         if (IS_ERR(new_nsp->pid_ns)) {
15193                 err = PTR_ERR(new_nsp->pid_ns);
15194                 goto out_pid;
15195         }
15196  
15197 -       new_nsp->net_ns = copy_net_ns(flags, tsk->nsproxy->net_ns);
15198 +       /* disabled now?
15199 +       new_nsp->user_ns = copy_user_ns(flags, orig->user_ns);
15200 +       if (IS_ERR(new_nsp->user_ns)) {
15201 +               err = PTR_ERR(new_nsp->user_ns);
15202 +               goto out_user;
15203 +       } */
15204 +
15205 +       new_nsp->net_ns = copy_net_ns(flags, orig->net_ns);
15206         if (IS_ERR(new_nsp->net_ns)) {
15207                 err = PTR_ERR(new_nsp->net_ns);
15208                 goto out_net;
15209 @@ -112,6 +128,38 @@ out_ns:
15210         return ERR_PTR(err);
15211  }
15212  
15213 +static struct nsproxy *create_new_namespaces(int flags, struct task_struct *tsk,
15214 +                       struct fs_struct *new_fs)
15215 +{
15216 +       return unshare_namespaces(flags, tsk->nsproxy, new_fs);
15217 +}
15218 +
15219 +/*
15220 + * copies the nsproxy, setting refcount to 1, and grabbing a
15221 + * reference to all contained namespaces.
15222 + */
15223 +struct nsproxy *copy_nsproxy(struct nsproxy *orig)
15224 +{
15225 +       struct nsproxy *ns = create_nsproxy();
15226 +
15227 +       if (ns) {
15228 +               memcpy(ns, orig, sizeof(struct nsproxy));
15229 +               atomic_set(&ns->count, 1);
15230 +
15231 +               if (ns->mnt_ns)
15232 +                       get_mnt_ns(ns->mnt_ns);
15233 +               if (ns->uts_ns)
15234 +                       get_uts_ns(ns->uts_ns);
15235 +               if (ns->ipc_ns)
15236 +                       get_ipc_ns(ns->ipc_ns);
15237 +               if (ns->pid_ns)
15238 +                       get_pid_ns(ns->pid_ns);
15239 +               if (ns->net_ns)
15240 +                       get_net(ns->net_ns);
15241 +       }
15242 +       return ns;
15243 +}
15244 +
15245  /*
15246   * called from clone.  This now handles copy for nsproxy and all
15247   * namespaces therein.
15248 @@ -119,9 +167,12 @@ out_ns:
15249  int copy_namespaces(unsigned long flags, struct task_struct *tsk)
15250  {
15251         struct nsproxy *old_ns = tsk->nsproxy;
15252 -       struct nsproxy *new_ns;
15253 +       struct nsproxy *new_ns = NULL;
15254         int err = 0;
15255  
15256 +       vxdprintk(VXD_CBIT(space, 7), "copy_namespaces(0x%08lx,%p[%p])",
15257 +               flags, tsk, old_ns);
15258 +
15259         if (!old_ns)
15260                 return 0;
15261  
15262 @@ -131,7 +182,7 @@ int copy_namespaces(unsigned long flags,
15263                                 CLONE_NEWPID | CLONE_NEWNET)))
15264                 return 0;
15265  
15266 -       if (!capable(CAP_SYS_ADMIN)) {
15267 +       if (!vx_can_unshare(CAP_SYS_ADMIN, flags)) {
15268                 err = -EPERM;
15269                 goto out;
15270         }
15271 @@ -158,6 +209,9 @@ int copy_namespaces(unsigned long flags,
15272  
15273  out:
15274         put_nsproxy(old_ns);
15275 +       vxdprintk(VXD_CBIT(space, 3),
15276 +               "copy_namespaces(0x%08lx,%p[%p]) = %d [%p]",
15277 +               flags, tsk, old_ns, err, new_ns);
15278         return err;
15279  }
15280  
15281 @@ -171,7 +225,9 @@ void free_nsproxy(struct nsproxy *ns)
15282                 put_ipc_ns(ns->ipc_ns);
15283         if (ns->pid_ns)
15284                 put_pid_ns(ns->pid_ns);
15285 -       put_net(ns->net_ns);
15286 +       if (ns->net_ns)
15287 +               put_net(ns->net_ns);
15288 +       atomic_dec(&vs_global_nsproxy);
15289         kmem_cache_free(nsproxy_cachep, ns);
15290  }
15291  
15292 @@ -184,11 +240,15 @@ int unshare_nsproxy_namespaces(unsigned 
15293  {
15294         int err = 0;
15295  
15296 +       vxdprintk(VXD_CBIT(space, 4),
15297 +               "unshare_nsproxy_namespaces(0x%08lx,[%p])",
15298 +               unshare_flags, current->nsproxy);
15299 +
15300         if (!(unshare_flags & (CLONE_NEWNS | CLONE_NEWUTS | CLONE_NEWIPC |
15301                                CLONE_NEWNET)))
15302                 return 0;
15303  
15304 -       if (!capable(CAP_SYS_ADMIN))
15305 +       if (!vx_can_unshare(CAP_SYS_ADMIN, unshare_flags))
15306                 return -EPERM;
15307  
15308         *new_nsp = create_new_namespaces(unshare_flags, current,
15309 diff -NurpP --minimal linux-2.6.38.1/kernel/pid.c linux-2.6.38.1-vs2.3.0.37-rc9/kernel/pid.c
15310 --- linux-2.6.38.1/kernel/pid.c 2011-01-05 21:50:38.000000000 +0100
15311 +++ linux-2.6.38.1-vs2.3.0.37-rc9/kernel/pid.c  2011-01-29 02:01:07.000000000 +0100
15312 @@ -36,6 +36,7 @@
15313  #include <linux/pid_namespace.h>
15314  #include <linux/init_task.h>
15315  #include <linux/syscalls.h>
15316 +#include <linux/vs_pid.h>
15317  
15318  #define pid_hashfn(nr, ns)     \
15319         hash_long((unsigned long)nr + (unsigned long)ns, pidhash_shift)
15320 @@ -339,7 +340,7 @@ EXPORT_SYMBOL_GPL(find_pid_ns);
15321  
15322  struct pid *find_vpid(int nr)
15323  {
15324 -       return find_pid_ns(nr, current->nsproxy->pid_ns);
15325 +       return find_pid_ns(vx_rmap_pid(nr), current->nsproxy->pid_ns);
15326  }
15327  EXPORT_SYMBOL_GPL(find_vpid);
15328  
15329 @@ -399,6 +400,9 @@ void transfer_pid(struct task_struct *ol
15330  struct task_struct *pid_task(struct pid *pid, enum pid_type type)
15331  {
15332         struct task_struct *result = NULL;
15333 +
15334 +       if (type == PIDTYPE_REALPID)
15335 +               type = PIDTYPE_PID;
15336         if (pid) {
15337                 struct hlist_node *first;
15338                 first = rcu_dereference_check(hlist_first_rcu(&pid->tasks[type]),
15339 @@ -417,7 +421,7 @@ EXPORT_SYMBOL(pid_task);
15340  struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
15341  {
15342         rcu_lockdep_assert(rcu_read_lock_held());
15343 -       return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
15344 +       return pid_task(find_pid_ns(vx_rmap_pid(nr), ns), PIDTYPE_PID);
15345  }
15346  
15347  struct task_struct *find_task_by_vpid(pid_t vnr)
15348 @@ -459,7 +463,7 @@ struct pid *find_get_pid(pid_t nr)
15349  }
15350  EXPORT_SYMBOL_GPL(find_get_pid);
15351  
15352 -pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns)
15353 +pid_t pid_unmapped_nr_ns(struct pid *pid, struct pid_namespace *ns)
15354  {
15355         struct upid *upid;
15356         pid_t nr = 0;
15357 @@ -472,6 +476,11 @@ pid_t pid_nr_ns(struct pid *pid, struct 
15358         return nr;
15359  }
15360  
15361 +pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns)
15362 +{
15363 +       return vx_map_pid(pid_unmapped_nr_ns(pid, ns));
15364 +}
15365 +
15366  pid_t pid_vnr(struct pid *pid)
15367  {
15368         return pid_nr_ns(pid, current->nsproxy->pid_ns);
15369 diff -NurpP --minimal linux-2.6.38.1/kernel/pid_namespace.c linux-2.6.38.1-vs2.3.0.37-rc9/kernel/pid_namespace.c
15370 --- linux-2.6.38.1/kernel/pid_namespace.c       2010-07-07 18:31:57.000000000 +0200
15371 +++ linux-2.6.38.1-vs2.3.0.37-rc9/kernel/pid_namespace.c        2011-01-29 02:01:07.000000000 +0100
15372 @@ -14,6 +14,7 @@
15373  #include <linux/err.h>
15374  #include <linux/acct.h>
15375  #include <linux/slab.h>
15376 +#include <linux/vserver/global.h>
15377  
15378  #define BITS_PER_PAGE          (PAGE_SIZE*8)
15379  
15380 @@ -87,6 +88,7 @@ static struct pid_namespace *create_pid_
15381                 goto out_free_map;
15382  
15383         kref_init(&ns->kref);
15384 +       atomic_inc(&vs_global_pid_ns);
15385         ns->level = level;
15386         ns->parent = get_pid_ns(parent_pid_ns);
15387  
15388 @@ -112,6 +114,7 @@ static void destroy_pid_namespace(struct
15389  
15390         for (i = 0; i < PIDMAP_ENTRIES; i++)
15391                 kfree(ns->pidmap[i].page);
15392 +       atomic_dec(&vs_global_pid_ns);
15393         kmem_cache_free(pid_ns_cachep, ns);
15394  }
15395  
15396 diff -NurpP --minimal linux-2.6.38.1/kernel/posix-timers.c linux-2.6.38.1-vs2.3.0.37-rc9/kernel/posix-timers.c
15397 --- linux-2.6.38.1/kernel/posix-timers.c        2011-03-15 18:07:42.000000000 +0100
15398 +++ linux-2.6.38.1-vs2.3.0.37-rc9/kernel/posix-timers.c 2011-01-29 02:01:07.000000000 +0100
15399 @@ -46,6 +46,7 @@
15400  #include <linux/wait.h>
15401  #include <linux/workqueue.h>
15402  #include <linux/module.h>
15403 +#include <linux/vs_context.h>
15404  
15405  /*
15406   * Management arrays for POSIX timers.  Timers are kept in slab memory
15407 @@ -369,6 +370,7 @@ int posix_timer_event(struct k_itimer *t
15408  {
15409         struct task_struct *task;
15410         int shared, ret = -1;
15411 +
15412         /*
15413          * FIXME: if ->sigq is queued we can race with
15414          * dequeue_signal()->do_schedule_next_timer().
15415 @@ -385,10 +387,18 @@ int posix_timer_event(struct k_itimer *t
15416         rcu_read_lock();
15417         task = pid_task(timr->it_pid, PIDTYPE_PID);
15418         if (task) {
15419 +               struct vx_info_save vxis;
15420 +               struct vx_info *vxi;
15421 +
15422 +               vxi = get_vx_info(task->vx_info);
15423 +               enter_vx_info(vxi, &vxis);
15424                 shared = !(timr->it_sigev_notify & SIGEV_THREAD_ID);
15425                 ret = send_sigqueue(timr->sigq, task, shared);
15426 +               leave_vx_info(&vxis);
15427 +               put_vx_info(vxi);
15428         }
15429         rcu_read_unlock();
15430 +
15431         /* If we failed to send the signal the timer stops. */
15432         return ret > 0;
15433  }
15434 diff -NurpP --minimal linux-2.6.38.1/kernel/printk.c linux-2.6.38.1-vs2.3.0.37-rc9/kernel/printk.c
15435 --- linux-2.6.38.1/kernel/printk.c      2011-03-15 18:07:42.000000000 +0100
15436 +++ linux-2.6.38.1-vs2.3.0.37-rc9/kernel/printk.c       2011-02-17 02:34:59.000000000 +0100
15437 @@ -40,6 +40,7 @@
15438  #include <linux/cpu.h>
15439  #include <linux/notifier.h>
15440  #include <linux/rculist.h>
15441 +#include <linux/vs_cvirt.h>
15442  
15443  #include <asm/uaccess.h>
15444  
15445 @@ -280,7 +281,7 @@ static int check_syslog_permissions(int 
15446                 return 0;
15447  
15448         if (syslog_action_restricted(type)) {
15449 -               if (capable(CAP_SYSLOG))
15450 +               if (vx_capable(CAP_SYSLOG, VXC_SYSLOG))
15451                         return 0;
15452                 /* For historical reasons, accept CAP_SYS_ADMIN too, with a warning */
15453                 if (capable(CAP_SYS_ADMIN)) {
15454 @@ -308,12 +309,9 @@ int do_syslog(int type, char __user *buf
15455         if (error)
15456                 return error;
15457  
15458 -       switch (type) {
15459 -       case SYSLOG_ACTION_CLOSE:       /* Close log */
15460 -               break;
15461 -       case SYSLOG_ACTION_OPEN:        /* Open log */
15462 -               break;
15463 -       case SYSLOG_ACTION_READ:        /* Read from log */
15464 +       if ((type == SYSLOG_ACTION_READ) ||
15465 +           (type == SYSLOG_ACTION_READ_ALL) ||
15466 +           (type == SYSLOG_ACTION_READ_CLEAR)) {
15467                 error = -EINVAL;
15468                 if (!buf || len < 0)
15469                         goto out;
15470 @@ -324,6 +322,16 @@ int do_syslog(int type, char __user *buf
15471                         error = -EFAULT;
15472                         goto out;
15473                 }
15474 +       }
15475 +       if (!vx_check(0, VS_ADMIN|VS_WATCH))
15476 +               return vx_do_syslog(type, buf, len);
15477 +
15478 +       switch (type) {
15479 +       case SYSLOG_ACTION_CLOSE:       /* Close log */
15480 +               break;
15481 +       case SYSLOG_ACTION_OPEN:        /* Open log */
15482 +               break;
15483 +       case SYSLOG_ACTION_READ:        /* Read from log */
15484                 error = wait_event_interruptible(log_wait,
15485                                                         (log_start - log_end));
15486                 if (error)
15487 @@ -350,16 +358,6 @@ int do_syslog(int type, char __user *buf
15488                 /* FALL THRU */
15489         /* Read last kernel messages */
15490         case SYSLOG_ACTION_READ_ALL:
15491 -               error = -EINVAL;
15492 -               if (!buf || len < 0)
15493 -                       goto out;
15494 -               error = 0;
15495 -               if (!len)
15496 -                       goto out;
15497 -               if (!access_ok(VERIFY_WRITE, buf, len)) {
15498 -                       error = -EFAULT;
15499 -                       goto out;
15500 -               }
15501                 count = len;
15502                 if (count > log_buf_len)
15503                         count = log_buf_len;
15504 diff -NurpP --minimal linux-2.6.38.1/kernel/ptrace.c linux-2.6.38.1-vs2.3.0.37-rc9/kernel/ptrace.c
15505 --- linux-2.6.38.1/kernel/ptrace.c      2011-03-15 18:07:42.000000000 +0100
15506 +++ linux-2.6.38.1-vs2.3.0.37-rc9/kernel/ptrace.c       2011-03-10 17:21:19.000000000 +0100
15507 @@ -22,6 +22,7 @@
15508  #include <linux/syscalls.h>
15509  #include <linux/uaccess.h>
15510  #include <linux/regset.h>
15511 +#include <linux/vs_context.h>
15512  
15513  
15514  /*
15515 @@ -150,6 +151,11 @@ int __ptrace_may_access(struct task_stru
15516                 dumpable = get_dumpable(task->mm);
15517         if (!dumpable && !capable(CAP_SYS_PTRACE))
15518                 return -EPERM;
15519 +       if (!vx_check(task->xid, VS_ADMIN_P|VS_WATCH_P|VS_IDENT))
15520 +               return -EPERM;
15521 +       if (!vx_check(task->xid, VS_IDENT) &&
15522 +               !task_vx_flags(task, VXF_STATE_ADMIN, 0))
15523 +               return -EACCES;
15524  
15525         return security_ptrace_access_check(task, mode);
15526  }
15527 @@ -713,6 +719,10 @@ SYSCALL_DEFINE4(ptrace, long, request, l
15528                 goto out;
15529         }
15530  
15531 +       ret = -EPERM;
15532 +       if (!vx_check(vx_task_xid(child), VS_WATCH_P | VS_IDENT))
15533 +               goto out_put_task_struct;
15534 +
15535         if (request == PTRACE_ATTACH) {
15536                 ret = ptrace_attach(child);
15537                 /*
15538 diff -NurpP --minimal linux-2.6.38.1/kernel/sched.c linux-2.6.38.1-vs2.3.0.37-rc9/kernel/sched.c
15539 --- linux-2.6.38.1/kernel/sched.c       2011-03-26 01:10:17.000000000 +0100
15540 +++ linux-2.6.38.1-vs2.3.0.37-rc9/kernel/sched.c        2011-03-25 22:52:15.000000000 +0100
15541 @@ -72,6 +72,8 @@
15542  #include <linux/ctype.h>
15543  #include <linux/ftrace.h>
15544  #include <linux/slab.h>
15545 +#include <linux/vs_sched.h>
15546 +#include <linux/vs_cvirt.h>
15547  
15548  #include <asm/tlb.h>
15549  #include <asm/irq_regs.h>
15550 @@ -3228,9 +3230,17 @@ static void calc_global_nohz(unsigned lo
15551   */
15552  void get_avenrun(unsigned long *loads, unsigned long offset, int shift)
15553  {
15554 -       loads[0] = (avenrun[0] + offset) << shift;
15555 -       loads[1] = (avenrun[1] + offset) << shift;
15556 -       loads[2] = (avenrun[2] + offset) << shift;
15557 +       if (vx_flags(VXF_VIRT_LOAD, 0)) {
15558 +               struct vx_info *vxi = current_vx_info();
15559 +
15560 +               loads[0] = (vxi->cvirt.load[0] + offset) << shift;
15561 +               loads[1] = (vxi->cvirt.load[1] + offset) << shift;
15562 +               loads[2] = (vxi->cvirt.load[2] + offset) << shift;
15563 +       } else {
15564 +               loads[0] = (avenrun[0] + offset) << shift;
15565 +               loads[1] = (avenrun[1] + offset) << shift;
15566 +               loads[2] = (avenrun[2] + offset) << shift;
15567 +       }
15568  }
15569  
15570  /*
15571 @@ -3518,16 +3528,19 @@ void account_user_time(struct task_struc
15572                        cputime_t cputime_scaled)
15573  {
15574         struct cpu_usage_stat *cpustat = &kstat_this_cpu.cpustat;
15575 +       struct vx_info *vxi = p->vx_info;  /* p is _always_ current */
15576         cputime64_t tmp;
15577 +       int nice = (TASK_NICE(p) > 0);
15578  
15579         /* Add user time to process. */
15580         p->utime = cputime_add(p->utime, cputime);
15581         p->utimescaled = cputime_add(p->utimescaled, cputime_scaled);
15582 +       vx_account_user(vxi, cputime, nice);
15583         account_group_user_time(p, cputime);
15584  
15585         /* Add user time to cpustat. */
15586         tmp = cputime_to_cputime64(cputime);
15587 -       if (TASK_NICE(p) > 0)
15588 +       if (nice)
15589                 cpustat->nice = cputime64_add(cpustat->nice, tmp);
15590         else
15591                 cpustat->user = cputime64_add(cpustat->user, tmp);
15592 @@ -3578,6 +3591,7 @@ void account_system_time(struct task_str
15593                          cputime_t cputime, cputime_t cputime_scaled)
15594  {
15595         struct cpu_usage_stat *cpustat = &kstat_this_cpu.cpustat;
15596 +       struct vx_info *vxi = p->vx_info;  /* p is _always_ current */
15597         cputime64_t tmp;
15598  
15599         if ((p->flags & PF_VCPU) && (irq_count() - hardirq_offset == 0)) {
15600 @@ -3588,6 +3602,7 @@ void account_system_time(struct task_str
15601         /* Add system time to process. */
15602         p->stime = cputime_add(p->stime, cputime);
15603         p->stimescaled = cputime_add(p->stimescaled, cputime_scaled);
15604 +       vx_account_system(vxi, cputime, 0 /* do we have idle time? */);
15605         account_group_system_time(p, cputime);
15606  
15607         /* Add system time to cpustat. */
15608 @@ -4672,7 +4687,7 @@ SYSCALL_DEFINE1(nice, int, increment)
15609                 nice = 19;
15610  
15611         if (increment < 0 && !can_nice(current, nice))
15612 -               return -EPERM;
15613 +               return vx_flags(VXF_IGNEG_NICE, 0) ? 0 : -EPERM;
15614  
15615         retval = security_task_setnice(current, nice);
15616         if (retval)
15617 diff -NurpP --minimal linux-2.6.38.1/kernel/sched_fair.c linux-2.6.38.1-vs2.3.0.37-rc9/kernel/sched_fair.c
15618 --- linux-2.6.38.1/kernel/sched_fair.c  2011-03-15 18:07:42.000000000 +0100
15619 +++ linux-2.6.38.1-vs2.3.0.37-rc9/kernel/sched_fair.c   2011-02-02 22:20:27.000000000 +0100
15620 @@ -992,6 +992,8 @@ enqueue_entity(struct cfs_rq *cfs_rq, st
15621                 __enqueue_entity(cfs_rq, se);
15622         se->on_rq = 1;
15623  
15624 +       if (entity_is_task(se))
15625 +               vx_activate_task(task_of(se));
15626         if (cfs_rq->nr_running == 1)
15627                 list_add_leaf_cfs_rq(cfs_rq);
15628  }
15629 @@ -1038,6 +1040,8 @@ dequeue_entity(struct cfs_rq *cfs_rq, st
15630         if (se != cfs_rq->curr)
15631                 __dequeue_entity(cfs_rq, se);
15632         se->on_rq = 0;
15633 +       if (entity_is_task(se))
15634 +               vx_deactivate_task(task_of(se));
15635         update_cfs_load(cfs_rq, 0);
15636         account_entity_dequeue(cfs_rq, se);
15637         update_min_vruntime(cfs_rq);
15638 diff -NurpP --minimal linux-2.6.38.1/kernel/signal.c linux-2.6.38.1-vs2.3.0.37-rc9/kernel/signal.c
15639 --- linux-2.6.38.1/kernel/signal.c      2011-01-05 21:50:38.000000000 +0100
15640 +++ linux-2.6.38.1-vs2.3.0.37-rc9/kernel/signal.c       2011-01-29 02:01:07.000000000 +0100
15641 @@ -28,6 +28,8 @@
15642  #include <linux/freezer.h>
15643  #include <linux/pid_namespace.h>
15644  #include <linux/nsproxy.h>
15645 +#include <linux/vs_context.h>
15646 +#include <linux/vs_pid.h>
15647  #define CREATE_TRACE_POINTS
15648  #include <trace/events/signal.h>
15649  
15650 @@ -646,9 +648,18 @@ static int check_kill_permission(int sig
15651         struct pid *sid;
15652         int error;
15653  
15654 +       vxdprintk(VXD_CBIT(misc, 7),
15655 +               "check_kill_permission(%d,%p,%p[#%u,%u])",
15656 +               sig, info, t, vx_task_xid(t), t->pid);
15657 +
15658         if (!valid_signal(sig))
15659                 return -EINVAL;
15660  
15661 +/*     FIXME: needed? if so, why?
15662 +       if ((info != SEND_SIG_NOINFO) &&
15663 +               (is_si_special(info) || !si_fromuser(info)))
15664 +               goto skip;      */
15665 +
15666         if (!si_fromuser(info))
15667                 return 0;
15668  
15669 @@ -678,6 +689,20 @@ static int check_kill_permission(int sig
15670                 }
15671         }
15672  
15673 +       error = -EPERM;
15674 +       if (t->pid == 1 && current->xid)
15675 +               return error;
15676 +
15677 +       error = -ESRCH;
15678 +       /* FIXME: we shouldn't return ESRCH ever, to avoid
15679 +                 loops, maybe ENOENT or EACCES? */
15680 +       if (!vx_check(vx_task_xid(t), VS_WATCH_P | VS_IDENT)) {
15681 +               vxdprintk(current->xid || VXD_CBIT(misc, 7),
15682 +                       "signal %d[%p] xid mismatch %p[#%u,%u] xid=#%u",
15683 +                       sig, info, t, vx_task_xid(t), t->pid, current->xid);
15684 +               return error;
15685 +       }
15686 +/* skip: */
15687         return security_task_kill(t, info, sig, 0);
15688  }
15689  
15690 @@ -1171,7 +1196,7 @@ int kill_pid_info(int sig, struct siginf
15691         rcu_read_lock();
15692  retry:
15693         p = pid_task(pid, PIDTYPE_PID);
15694 -       if (p) {
15695 +       if (p && vx_check(vx_task_xid(p), VS_IDENT)) {
15696                 error = group_send_sig_info(sig, info, p);
15697                 if (unlikely(error == -ESRCH))
15698                         /*
15699 @@ -1211,7 +1236,7 @@ int kill_pid_info_as_uid(int sig, struct
15700  
15701         rcu_read_lock();
15702         p = pid_task(pid, PIDTYPE_PID);
15703 -       if (!p) {
15704 +       if (!p || !vx_check(vx_task_xid(p), VS_IDENT)) {
15705                 ret = -ESRCH;
15706                 goto out_unlock;
15707         }
15708 @@ -1266,8 +1291,10 @@ static int kill_something_info(int sig, 
15709                 struct task_struct * p;
15710  
15711                 for_each_process(p) {
15712 -                       if (task_pid_vnr(p) > 1 &&
15713 -                                       !same_thread_group(p, current)) {
15714 +                       if (vx_check(vx_task_xid(p), VS_ADMIN|VS_IDENT) &&
15715 +                               task_pid_vnr(p) > 1 &&
15716 +                               !same_thread_group(p, current) &&
15717 +                               !vx_current_initpid(p->pid)) {
15718                                 int err = group_send_sig_info(sig, info, p);
15719                                 ++count;
15720                                 if (err != -EPERM)
15721 @@ -1936,6 +1963,11 @@ relock:
15722                                 !sig_kernel_only(signr))
15723                         continue;
15724  
15725 +               /* virtual init is protected against user signals */
15726 +               if ((info->si_code == SI_USER) &&
15727 +                       vx_current_initpid(current->pid))
15728 +                       continue;
15729 +
15730                 if (sig_kernel_stop(signr)) {
15731                         /*
15732                          * The default action is to stop all threads in
15733 diff -NurpP --minimal linux-2.6.38.1/kernel/softirq.c linux-2.6.38.1-vs2.3.0.37-rc9/kernel/softirq.c
15734 --- linux-2.6.38.1/kernel/softirq.c     2011-03-15 18:07:42.000000000 +0100
15735 +++ linux-2.6.38.1-vs2.3.0.37-rc9/kernel/softirq.c      2011-01-29 02:01:07.000000000 +0100
15736 @@ -24,6 +24,7 @@
15737  #include <linux/ftrace.h>
15738  #include <linux/smp.h>
15739  #include <linux/tick.h>
15740 +#include <linux/vs_context.h>
15741  
15742  #define CREATE_TRACE_POINTS
15743  #include <trace/events/irq.h>
15744 diff -NurpP --minimal linux-2.6.38.1/kernel/sys.c linux-2.6.38.1-vs2.3.0.37-rc9/kernel/sys.c
15745 --- linux-2.6.38.1/kernel/sys.c 2011-03-15 18:07:42.000000000 +0100
15746 +++ linux-2.6.38.1-vs2.3.0.37-rc9/kernel/sys.c  2011-02-02 22:20:27.000000000 +0100
15747 @@ -42,6 +42,7 @@
15748  #include <linux/syscalls.h>
15749  #include <linux/kprobes.h>
15750  #include <linux/user_namespace.h>
15751 +#include <linux/vs_pid.h>
15752  
15753  #include <linux/kmsg_dump.h>
15754  
15755 @@ -133,7 +134,10 @@ static int set_one_prio(struct task_stru
15756                 goto out;
15757         }
15758         if (niceval < task_nice(p) && !can_nice(p, niceval)) {
15759 -               error = -EACCES;
15760 +               if (vx_flags(VXF_IGNEG_NICE, 0))
15761 +                       error = 0;
15762 +               else
15763 +                       error = -EACCES;
15764                 goto out;
15765         }
15766         no_nice = security_task_setnice(p, niceval);
15767 @@ -183,6 +187,8 @@ SYSCALL_DEFINE3(setpriority, int, which,
15768                         else
15769                                 pgrp = task_pgrp(current);
15770                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
15771 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
15772 +                                       continue;
15773                                 error = set_one_prio(p, niceval, error);
15774                         } while_each_pid_thread(pgrp, PIDTYPE_PGID, p);
15775                         break;
15776 @@ -246,6 +252,8 @@ SYSCALL_DEFINE2(getpriority, int, which,
15777                         else
15778                                 pgrp = task_pgrp(current);
15779                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
15780 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
15781 +                                       continue;
15782                                 niceval = 20 - task_nice(p);
15783                                 if (niceval > retval)
15784                                         retval = niceval;
15785 @@ -363,6 +371,8 @@ EXPORT_SYMBOL_GPL(kernel_power_off);
15786  
15787  static DEFINE_MUTEX(reboot_mutex);
15788  
15789 +long vs_reboot(unsigned int, void __user *);
15790 +
15791  /*
15792   * Reboot system call: for obvious reasons only root may call it,
15793   * and even root needs to set up some magic numbers in the registers
15794 @@ -395,6 +405,9 @@ SYSCALL_DEFINE4(reboot, int, magic1, int
15795         if ((cmd == LINUX_REBOOT_CMD_POWER_OFF) && !pm_power_off)
15796                 cmd = LINUX_REBOOT_CMD_HALT;
15797  
15798 +       if (!vx_check(0, VS_ADMIN|VS_WATCH))
15799 +               return vs_reboot(cmd, arg);
15800 +
15801         mutex_lock(&reboot_mutex);
15802         switch (cmd) {
15803         case LINUX_REBOOT_CMD_RESTART:
15804 @@ -1177,7 +1190,7 @@ SYSCALL_DEFINE2(sethostname, char __user
15805         int errno;
15806         char tmp[__NEW_UTS_LEN];
15807  
15808 -       if (!capable(CAP_SYS_ADMIN))
15809 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SET_UTSNAME))
15810                 return -EPERM;
15811         if (len < 0 || len > __NEW_UTS_LEN)
15812                 return -EINVAL;
15813 @@ -1226,7 +1239,7 @@ SYSCALL_DEFINE2(setdomainname, char __us
15814         int errno;
15815         char tmp[__NEW_UTS_LEN];
15816  
15817 -       if (!capable(CAP_SYS_ADMIN))
15818 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SET_UTSNAME))
15819                 return -EPERM;
15820         if (len < 0 || len > __NEW_UTS_LEN)
15821                 return -EINVAL;
15822 @@ -1342,7 +1355,7 @@ int do_prlimit(struct task_struct *tsk, 
15823         task_lock(tsk->group_leader);
15824         if (new_rlim) {
15825                 if (new_rlim->rlim_max > rlim->rlim_max &&
15826 -                               !capable(CAP_SYS_RESOURCE))
15827 +                       !vx_capable(CAP_SYS_RESOURCE, VXC_SET_RLIMIT))
15828                         retval = -EPERM;
15829                 if (!retval)
15830                         retval = security_task_setrlimit(tsk->group_leader,
15831 @@ -1392,7 +1405,7 @@ static int check_prlimit_permission(stru
15832              cred->gid != tcred->egid ||
15833              cred->gid != tcred->sgid ||
15834              cred->gid != tcred->gid) &&
15835 -            !capable(CAP_SYS_RESOURCE)) {
15836 +            !vx_capable(CAP_SYS_RESOURCE, VXC_SET_RLIMIT)) {
15837                 return -EPERM;
15838         }
15839  
15840 diff -NurpP --minimal linux-2.6.38.1/kernel/sysctl.c linux-2.6.38.1-vs2.3.0.37-rc9/kernel/sysctl.c
15841 --- linux-2.6.38.1/kernel/sysctl.c      2011-03-15 18:07:42.000000000 +0100
15842 +++ linux-2.6.38.1-vs2.3.0.37-rc9/kernel/sysctl.c       2011-03-15 18:15:06.000000000 +0100
15843 @@ -74,6 +74,7 @@
15844  #if defined(CONFIG_PROVE_LOCKING) || defined(CONFIG_LOCK_STAT)
15845  #include <linux/lockdep.h>
15846  #endif
15847 +extern char vshelper_path[];
15848  #ifdef CONFIG_CHR_DEV_SG
15849  #include <scsi/sg.h>
15850  #endif
15851 @@ -568,6 +569,13 @@ static struct ctl_table kern_table[] = {
15852                 .proc_handler   = proc_dostring,
15853         },
15854  #endif
15855 +       {
15856 +               .procname       = "vshelper",
15857 +               .data           = &vshelper_path,
15858 +               .maxlen         = 256,
15859 +               .mode           = 0644,
15860 +               .proc_handler   = &proc_dostring,
15861 +       },
15862  #ifdef CONFIG_CHR_DEV_SG
15863         {
15864                 .procname       = "sg-big-buff",
15865 diff -NurpP --minimal linux-2.6.38.1/kernel/sysctl_binary.c linux-2.6.38.1-vs2.3.0.37-rc9/kernel/sysctl_binary.c
15866 --- linux-2.6.38.1/kernel/sysctl_binary.c       2011-03-15 18:07:42.000000000 +0100
15867 +++ linux-2.6.38.1-vs2.3.0.37-rc9/kernel/sysctl_binary.c        2011-01-29 02:01:07.000000000 +0100
15868 @@ -73,6 +73,7 @@ static const struct bin_table bin_kern_t
15869  
15870         { CTL_INT,      KERN_PANIC,                     "panic" },
15871         { CTL_INT,      KERN_REALROOTDEV,               "real-root-dev" },
15872 +       { CTL_STR,      KERN_VSHELPER,                  "vshelper" },
15873  
15874         { CTL_STR,      KERN_SPARC_REBOOT,              "reboot-cmd" },
15875         { CTL_INT,      KERN_CTLALTDEL,                 "ctrl-alt-del" },
15876 diff -NurpP --minimal linux-2.6.38.1/kernel/time/timekeeping.c linux-2.6.38.1-vs2.3.0.37-rc9/kernel/time/timekeeping.c
15877 --- linux-2.6.38.1/kernel/time/timekeeping.c    2011-03-15 18:07:42.000000000 +0100
15878 +++ linux-2.6.38.1-vs2.3.0.37-rc9/kernel/time/timekeeping.c     2011-01-29 02:01:07.000000000 +0100
15879 @@ -233,6 +233,7 @@ void getnstimeofday(struct timespec *ts)
15880         } while (read_seqretry(&xtime_lock, seq));
15881  
15882         timespec_add_ns(ts, nsecs);
15883 +       vx_adjust_timespec(ts);
15884  }
15885  
15886  EXPORT_SYMBOL(getnstimeofday);
15887 diff -NurpP --minimal linux-2.6.38.1/kernel/time.c linux-2.6.38.1-vs2.3.0.37-rc9/kernel/time.c
15888 --- linux-2.6.38.1/kernel/time.c        2011-03-15 18:07:42.000000000 +0100
15889 +++ linux-2.6.38.1-vs2.3.0.37-rc9/kernel/time.c 2011-01-29 02:01:07.000000000 +0100
15890 @@ -92,7 +92,7 @@ SYSCALL_DEFINE1(stime, time_t __user *, 
15891         if (err)
15892                 return err;
15893  
15894 -       do_settimeofday(&tv);
15895 +       vx_settimeofday(&tv);
15896         return 0;
15897  }
15898  
15899 @@ -177,7 +177,7 @@ int do_sys_settimeofday(struct timespec 
15900                 /* SMP safe, again the code in arch/foo/time.c should
15901                  * globally block out interrupts when it runs.
15902                  */
15903 -               return do_settimeofday(tv);
15904 +               return vx_settimeofday(tv);
15905         }
15906         return 0;
15907  }
15908 diff -NurpP --minimal linux-2.6.38.1/kernel/timer.c linux-2.6.38.1-vs2.3.0.37-rc9/kernel/timer.c
15909 --- linux-2.6.38.1/kernel/timer.c       2011-03-15 18:07:42.000000000 +0100
15910 +++ linux-2.6.38.1-vs2.3.0.37-rc9/kernel/timer.c        2011-02-17 02:17:51.000000000 +0100
15911 @@ -40,6 +40,10 @@
15912  #include <linux/irq_work.h>
15913  #include <linux/sched.h>
15914  #include <linux/slab.h>
15915 +#include <linux/vs_base.h>
15916 +#include <linux/vs_cvirt.h>
15917 +#include <linux/vs_pid.h>
15918 +#include <linux/vserver/sched.h>
15919  
15920  #include <asm/uaccess.h>
15921  #include <asm/unistd.h>
15922 @@ -1321,12 +1325,6 @@ SYSCALL_DEFINE1(alarm, unsigned int, sec
15923  
15924  #endif
15925  
15926 -#ifndef __alpha__
15927 -
15928 -/*
15929 - * The Alpha uses getxpid, getxuid, and getxgid instead.  Maybe this
15930 - * should be moved into arch/i386 instead?
15931 - */
15932  
15933  /**
15934   * sys_getpid - return the thread group id of the current process
15935 @@ -1355,10 +1353,23 @@ SYSCALL_DEFINE0(getppid)
15936         rcu_read_lock();
15937         pid = task_tgid_vnr(current->real_parent);
15938         rcu_read_unlock();
15939 +       return vx_map_pid(pid);
15940 +}
15941  
15942 -       return pid;
15943 +#ifdef __alpha__
15944 +
15945 +/*
15946 + * The Alpha uses getxpid, getxuid, and getxgid instead.
15947 + */
15948 +
15949 +asmlinkage long do_getxpid(long *ppid)
15950 +{
15951 +       *ppid = sys_getppid();
15952 +       return sys_getpid();
15953  }
15954  
15955 +#else /* _alpha_ */
15956 +
15957  SYSCALL_DEFINE0(getuid)
15958  {
15959         /* Only we change this so SMP safe */
15960 diff -NurpP --minimal linux-2.6.38.1/kernel/user_namespace.c linux-2.6.38.1-vs2.3.0.37-rc9/kernel/user_namespace.c
15961 --- linux-2.6.38.1/kernel/user_namespace.c      2011-03-15 18:07:42.000000000 +0100
15962 +++ linux-2.6.38.1-vs2.3.0.37-rc9/kernel/user_namespace.c       2011-01-29 02:01:07.000000000 +0100
15963 @@ -11,6 +11,7 @@
15964  #include <linux/user_namespace.h>
15965  #include <linux/highuid.h>
15966  #include <linux/cred.h>
15967 +#include <linux/vserver/global.h>
15968  
15969  static struct kmem_cache *user_ns_cachep __read_mostly;
15970  
15971 @@ -33,6 +34,7 @@ int create_user_ns(struct cred *new)
15972                 return -ENOMEM;
15973  
15974         kref_init(&ns->kref);
15975 +       atomic_inc(&vs_global_user_ns);
15976  
15977         for (n = 0; n < UIDHASH_SZ; ++n)
15978                 INIT_HLIST_HEAD(ns->uidhash_table + n);
15979 @@ -81,6 +83,8 @@ void free_user_ns(struct kref *kref)
15980         struct user_namespace *ns =
15981                 container_of(kref, struct user_namespace, kref);
15982  
15983 +       /* FIXME: maybe move into destroyer? */
15984 +       atomic_dec(&vs_global_user_ns);
15985         INIT_WORK(&ns->destroyer, free_user_ns_work);
15986         schedule_work(&ns->destroyer);
15987  }
15988 diff -NurpP --minimal linux-2.6.38.1/kernel/utsname.c linux-2.6.38.1-vs2.3.0.37-rc9/kernel/utsname.c
15989 --- linux-2.6.38.1/kernel/utsname.c     2009-09-10 15:26:28.000000000 +0200
15990 +++ linux-2.6.38.1-vs2.3.0.37-rc9/kernel/utsname.c      2011-01-29 02:01:07.000000000 +0100
15991 @@ -14,14 +14,17 @@
15992  #include <linux/utsname.h>
15993  #include <linux/err.h>
15994  #include <linux/slab.h>
15995 +#include <linux/vserver/global.h>
15996  
15997  static struct uts_namespace *create_uts_ns(void)
15998  {
15999         struct uts_namespace *uts_ns;
16000  
16001         uts_ns = kmalloc(sizeof(struct uts_namespace), GFP_KERNEL);
16002 -       if (uts_ns)
16003 +       if (uts_ns) {
16004                 kref_init(&uts_ns->kref);
16005 +               atomic_inc(&vs_global_uts_ns);
16006 +       }
16007         return uts_ns;
16008  }
16009  
16010 @@ -71,5 +74,6 @@ void free_uts_ns(struct kref *kref)
16011         struct uts_namespace *ns;
16012  
16013         ns = container_of(kref, struct uts_namespace, kref);
16014 +       atomic_dec(&vs_global_uts_ns);
16015         kfree(ns);
16016  }
16017 diff -NurpP --minimal linux-2.6.38.1/kernel/vserver/Kconfig linux-2.6.38.1-vs2.3.0.37-rc9/kernel/vserver/Kconfig
16018 --- linux-2.6.38.1/kernel/vserver/Kconfig       1970-01-01 01:00:00.000000000 +0100
16019 +++ linux-2.6.38.1-vs2.3.0.37-rc9/kernel/vserver/Kconfig        2011-03-15 21:32:33.000000000 +0100
16020 @@ -0,0 +1,228 @@
16021 +#
16022 +# Linux VServer configuration
16023 +#
16024 +
16025 +menu "Linux VServer"
16026 +
16027 +config VSERVER_AUTO_LBACK
16028 +       bool    "Automatically Assign Loopback IP"
16029 +       default y
16030 +       help
16031 +         Automatically assign a guest specific loopback
16032 +         IP and add it to the kernel network stack on
16033 +         startup.
16034 +
16035 +config VSERVER_AUTO_SINGLE
16036 +       bool    "Automatic Single IP Special Casing"
16037 +       depends on EXPERIMENTAL
16038 +       default y
16039 +       help
16040 +         This allows network contexts with a single IP to
16041 +         automatically remap 0.0.0.0 bindings to that IP,
16042 +         avoiding further network checks and improving
16043 +         performance.
16044 +
16045 +         (note: such guests do not allow to change the ip
16046 +          on the fly and do not show loopback addresses)
16047 +
16048 +config VSERVER_COWBL
16049 +       bool    "Enable COW Immutable Link Breaking"
16050 +       default y
16051 +       help
16052 +         This enables the COW (Copy-On-Write) link break code.
16053 +         It allows you to treat unified files like normal files
16054 +         when writing to them (which will implicitely break the
16055 +         link and create a copy of the unified file)
16056 +
16057 +config VSERVER_VTIME
16058 +       bool    "Enable Virtualized Guest Time"
16059 +       depends on EXPERIMENTAL
16060 +       default n
16061 +       help
16062 +         This enables per guest time offsets to allow for
16063 +         adjusting the system clock individually per guest.
16064 +         this adds some overhead to the time functions and
16065 +         therefore should not be enabled without good reason.
16066 +
16067 +config VSERVER_DEVICE
16068 +       bool    "Enable Guest Device Mapping"
16069 +       depends on EXPERIMENTAL
16070 +       default n
16071 +       help
16072 +         This enables generic device remapping.
16073 +
16074 +config VSERVER_PROC_SECURE
16075 +       bool    "Enable Proc Security"
16076 +       depends on PROC_FS
16077 +       default y
16078 +       help
16079 +         This configures ProcFS security to initially hide
16080 +         non-process entries for all contexts except the main and
16081 +         spectator context (i.e. for all guests), which is a secure
16082 +         default.
16083 +
16084 +         (note: on 1.2x the entries were visible by default)
16085 +
16086 +choice
16087 +       prompt  "Persistent Inode Tagging"
16088 +       default TAGGING_ID24
16089 +       help
16090 +         This adds persistent context information to filesystems
16091 +         mounted with the tagxid option. Tagging is a requirement
16092 +         for per-context disk limits and per-context quota.
16093 +
16094 +
16095 +config TAGGING_NONE
16096 +       bool    "Disabled"
16097 +       help
16098 +         do not store per-context information in inodes.
16099 +
16100 +config TAGGING_UID16
16101 +       bool    "UID16/GID32"
16102 +       help
16103 +         reduces UID to 16 bit, but leaves GID at 32 bit.
16104 +
16105 +config TAGGING_GID16
16106 +       bool    "UID32/GID16"
16107 +       help
16108 +         reduces GID to 16 bit, but leaves UID at 32 bit.
16109 +
16110 +config TAGGING_ID24
16111 +       bool    "UID24/GID24"
16112 +       help
16113 +         uses the upper 8bit from UID and GID for XID tagging
16114 +         which leaves 24bit for UID/GID each, which should be
16115 +         more than sufficient for normal use.
16116 +
16117 +config TAGGING_INTERN
16118 +       bool    "UID32/GID32"
16119 +       help
16120 +         this uses otherwise reserved inode fields in the on
16121 +         disk representation, which limits the use to a few
16122 +         filesystems (currently ext2 and ext3)
16123 +
16124 +endchoice
16125 +
16126 +config TAG_NFSD
16127 +       bool    "Tag NFSD User Auth and Files"
16128 +       default n
16129 +       help
16130 +         Enable this if you do want the in-kernel NFS
16131 +         Server to use the tagging specified above.
16132 +         (will require patched clients too)
16133 +
16134 +config VSERVER_PRIVACY
16135 +       bool    "Honor Privacy Aspects of Guests"
16136 +       default n
16137 +       help
16138 +         When enabled, most context checks will disallow
16139 +         access to structures assigned to a specific context,
16140 +         like ptys or loop devices.
16141 +
16142 +config VSERVER_CONTEXTS
16143 +       int     "Maximum number of Contexts (1-65533)"  if EMBEDDED
16144 +       range 1 65533
16145 +       default "768"   if 64BIT
16146 +       default "256"
16147 +       help
16148 +         This setting will optimize certain data structures
16149 +         and memory allocations according to the expected
16150 +         maximum.
16151 +
16152 +         note: this is not a strict upper limit.
16153 +
16154 +config VSERVER_WARN
16155 +       bool    "VServer Warnings"
16156 +       default y
16157 +       help
16158 +         This enables various runtime warnings, which will
16159 +         notify about potential manipulation attempts or
16160 +         resource shortage. It is generally considered to
16161 +         be a good idea to have that enabled.
16162 +
16163 +config VSERVER_WARN_DEVPTS
16164 +       bool    "VServer DevPTS Warnings"
16165 +       depends on VSERVER_WARN
16166 +       default y
16167 +       help
16168 +         This enables DevPTS related warnings, issued when a
16169 +         process inside a context tries to lookup or access
16170 +         a dynamic pts from the host or a different context.
16171 +
16172 +config VSERVER_DEBUG
16173 +       bool    "VServer Debugging Code"
16174 +       default n
16175 +       help
16176 +         Set this to yes if you want to be able to activate
16177 +         debugging output at runtime. It adds a very small
16178 +         overhead to all vserver related functions and
16179 +         increases the kernel size by about 20k.
16180 +
16181 +config VSERVER_HISTORY
16182 +       bool    "VServer History Tracing"
16183 +       depends on VSERVER_DEBUG
16184 +       default n
16185 +       help
16186 +         Set this to yes if you want to record the history of
16187 +         linux-vserver activities, so they can be replayed in
16188 +         the event of a kernel panic or oops.
16189 +
16190 +config VSERVER_HISTORY_SIZE
16191 +       int     "Per-CPU History Size (32-65536)"
16192 +       depends on VSERVER_HISTORY
16193 +       range 32 65536
16194 +       default 64
16195 +       help
16196 +         This allows you to specify the number of entries in
16197 +         the per-CPU history buffer.
16198 +
16199 +config VSERVER_LEGACY_MEM
16200 +       bool    "Legacy Memory Limits"
16201 +       default n
16202 +       help
16203 +         This provides fake memory limits to keep
16204 +         older tools happy in the face of memory
16205 +         cgroups
16206 +
16207 +choice
16208 +       prompt  "Quotes used in debug and warn messages"
16209 +       default QUOTES_ISO8859
16210 +
16211 +config QUOTES_ISO8859
16212 +       bool    "Extended ASCII (ISO 8859) angle quotes"
16213 +       help
16214 +         This uses the extended ASCII characters \xbb
16215 +         and \xab for quoting file and process names.
16216 +
16217 +config QUOTES_UTF8
16218 +       bool    "UTF-8 angle quotes"
16219 +       help
16220 +         This uses the the UTF-8 sequences for angle
16221 +         quotes to quote file and process names.
16222 +
16223 +config QUOTES_ASCII
16224 +       bool    "ASCII single quotes"
16225 +       help
16226 +         This uses the ASCII single quote character
16227 +         (\x27) to quote file and process names.
16228 +
16229 +endchoice
16230 +
16231 +endmenu
16232 +
16233 +
16234 +config VSERVER
16235 +       bool
16236 +       default y
16237 +       select NAMESPACES
16238 +       select UTS_NS
16239 +       select IPC_NS
16240 +       select USER_NS
16241 +       select SYSVIPC
16242 +
16243 +config VSERVER_SECURITY
16244 +       bool
16245 +       depends on SECURITY
16246 +       default y
16247 +       select SECURITY_CAPABILITIES
16248 +
16249 diff -NurpP --minimal linux-2.6.38.1/kernel/vserver/Makefile linux-2.6.38.1-vs2.3.0.37-rc9/kernel/vserver/Makefile
16250 --- linux-2.6.38.1/kernel/vserver/Makefile      1970-01-01 01:00:00.000000000 +0100
16251 +++ linux-2.6.38.1-vs2.3.0.37-rc9/kernel/vserver/Makefile       2011-01-29 02:01:07.000000000 +0100
16252 @@ -0,0 +1,18 @@
16253 +#
16254 +# Makefile for the Linux vserver routines.
16255 +#
16256 +
16257 +
16258 +obj-y          += vserver.o
16259 +
16260 +vserver-y      := switch.o context.o space.o sched.o network.o inode.o \
16261 +                  limit.o cvirt.o cacct.o signal.o helper.o init.o \
16262 +                  dlimit.o tag.o
16263 +
16264 +vserver-$(CONFIG_INET) += inet.o
16265 +vserver-$(CONFIG_PROC_FS) += proc.o
16266 +vserver-$(CONFIG_VSERVER_DEBUG) += sysctl.o debug.o
16267 +vserver-$(CONFIG_VSERVER_HISTORY) += history.o
16268 +vserver-$(CONFIG_VSERVER_MONITOR) += monitor.o
16269 +vserver-$(CONFIG_VSERVER_DEVICE) += device.o
16270 +
16271 diff -NurpP --minimal linux-2.6.38.1/kernel/vserver/cacct.c linux-2.6.38.1-vs2.3.0.37-rc9/kernel/vserver/cacct.c
16272 --- linux-2.6.38.1/kernel/vserver/cacct.c       1970-01-01 01:00:00.000000000 +0100
16273 +++ linux-2.6.38.1-vs2.3.0.37-rc9/kernel/vserver/cacct.c        2011-01-29 02:01:07.000000000 +0100
16274 @@ -0,0 +1,42 @@
16275 +/*
16276 + *  linux/kernel/vserver/cacct.c
16277 + *
16278 + *  Virtual Server: Context Accounting
16279 + *
16280 + *  Copyright (C) 2006-2007 Herbert Pötzl
16281 + *
16282 + *  V0.01  added accounting stats
16283 + *
16284 + */
16285 +
16286 +#include <linux/types.h>
16287 +#include <linux/vs_context.h>
16288 +#include <linux/vserver/cacct_cmd.h>
16289 +#include <linux/vserver/cacct_int.h>
16290 +
16291 +#include <asm/errno.h>
16292 +#include <asm/uaccess.h>
16293 +
16294 +
16295 +int vc_sock_stat(struct vx_info *vxi, void __user *data)
16296 +{
16297 +       struct vcmd_sock_stat_v0 vc_data;
16298 +       int j, field;
16299 +
16300 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16301 +               return -EFAULT;
16302 +
16303 +       field = vc_data.field;
16304 +       if ((field < 0) || (field >= VXA_SOCK_SIZE))
16305 +               return -EINVAL;
16306 +
16307 +       for (j = 0; j < 3; j++) {
16308 +               vc_data.count[j] = vx_sock_count(&vxi->cacct, field, j);
16309 +               vc_data.total[j] = vx_sock_total(&vxi->cacct, field, j);
16310 +       }
16311 +
16312 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16313 +               return -EFAULT;
16314 +       return 0;
16315 +}
16316 +
16317 diff -NurpP --minimal linux-2.6.38.1/kernel/vserver/cacct_init.h linux-2.6.38.1-vs2.3.0.37-rc9/kernel/vserver/cacct_init.h
16318 --- linux-2.6.38.1/kernel/vserver/cacct_init.h  1970-01-01 01:00:00.000000000 +0100
16319 +++ linux-2.6.38.1-vs2.3.0.37-rc9/kernel/vserver/cacct_init.h   2011-01-29 02:01:07.000000000 +0100
16320 @@ -0,0 +1,25 @@
16321 +
16322 +
16323 +static inline void vx_info_init_cacct(struct _vx_cacct *cacct)
16324 +{
16325 +       int i, j;
16326 +
16327 +
16328 +       for (i = 0; i < VXA_SOCK_SIZE; i++) {
16329 +               for (j = 0; j < 3; j++) {
16330 +                       atomic_long_set(&cacct->sock[i][j].count, 0);
16331 +                       atomic_long_set(&cacct->sock[i][j].total, 0);
16332 +               }
16333 +       }
16334 +       for (i = 0; i < 8; i++)
16335 +               atomic_set(&cacct->slab[i], 0);
16336 +       for (i = 0; i < 5; i++)
16337 +               for (j = 0; j < 4; j++)
16338 +                       atomic_set(&cacct->page[i][j], 0);
16339 +}
16340 +
16341 +static inline void vx_info_exit_cacct(struct _vx_cacct *cacct)
16342 +{
16343 +       return;
16344 +}
16345 +
16346 diff -NurpP --minimal linux-2.6.38.1/kernel/vserver/cacct_proc.h linux-2.6.38.1-vs2.3.0.37-rc9/kernel/vserver/cacct_proc.h
16347 --- linux-2.6.38.1/kernel/vserver/cacct_proc.h  1970-01-01 01:00:00.000000000 +0100
16348 +++ linux-2.6.38.1-vs2.3.0.37-rc9/kernel/vserver/cacct_proc.h   2011-01-29 02:01:07.000000000 +0100
16349 @@ -0,0 +1,53 @@
16350 +#ifndef _VX_CACCT_PROC_H
16351 +#define _VX_CACCT_PROC_H
16352 +
16353 +#include <linux/vserver/cacct_int.h>
16354 +
16355 +
16356 +#define VX_SOCKA_TOP   \
16357 +       "Type\t    recv #/bytes\t\t   send #/bytes\t\t    fail #/bytes\n"
16358 +
16359 +static inline int vx_info_proc_cacct(struct _vx_cacct *cacct, char *buffer)
16360 +{
16361 +       int i, j, length = 0;
16362 +       static char *type[VXA_SOCK_SIZE] = {
16363 +               "UNSPEC", "UNIX", "INET", "INET6", "PACKET", "OTHER"
16364 +       };
16365 +
16366 +       length += sprintf(buffer + length, VX_SOCKA_TOP);
16367 +       for (i = 0; i < VXA_SOCK_SIZE; i++) {
16368 +               length += sprintf(buffer + length, "%s:", type[i]);
16369 +               for (j = 0; j < 3; j++) {
16370 +                       length += sprintf(buffer + length,
16371 +                               "\t%10lu/%-10lu",
16372 +                               vx_sock_count(cacct, i, j),
16373 +                               vx_sock_total(cacct, i, j));
16374 +               }
16375 +               buffer[length++] = '\n';
16376 +       }
16377 +
16378 +       length += sprintf(buffer + length, "\n");
16379 +       length += sprintf(buffer + length,
16380 +               "slab:\t %8u %8u %8u %8u\n",
16381 +               atomic_read(&cacct->slab[1]),
16382 +               atomic_read(&cacct->slab[4]),
16383 +               atomic_read(&cacct->slab[0]),
16384 +               atomic_read(&cacct->slab[2]));
16385 +
16386 +       length += sprintf(buffer + length, "\n");
16387 +       for (i = 0; i < 5; i++) {
16388 +               length += sprintf(buffer + length,
16389 +                       "page[%d]: %8u %8u %8u %8u\t %8u %8u %8u %8u\n", i,
16390 +                       atomic_read(&cacct->page[i][0]),
16391 +                       atomic_read(&cacct->page[i][1]),
16392 +                       atomic_read(&cacct->page[i][2]),
16393 +                       atomic_read(&cacct->page[i][3]),
16394 +                       atomic_read(&cacct->page[i][4]),
16395 +                       atomic_read(&cacct->page[i][5]),
16396 +                       atomic_read(&cacct->page[i][6]),
16397 +                       atomic_read(&cacct->page[i][7]));
16398 +       }
16399 +       return length;
16400 +}
16401 +
16402 +#endif /* _VX_CACCT_PROC_H */
16403 diff -NurpP --minimal linux-2.6.38.1/kernel/vserver/context.c linux-2.6.38.1-vs2.3.0.37-rc9/kernel/vserver/context.c
16404 --- linux-2.6.38.1/kernel/vserver/context.c     1970-01-01 01:00:00.000000000 +0100
16405 +++ linux-2.6.38.1-vs2.3.0.37-rc9/kernel/vserver/context.c      2011-03-22 17:35:46.000000000 +0100
16406 @@ -0,0 +1,1079 @@
16407 +/*
16408 + *  linux/kernel/vserver/context.c
16409 + *
16410 + *  Virtual Server: Context Support
16411 + *
16412 + *  Copyright (C) 2003-2010  Herbert Pötzl
16413 + *
16414 + *  V0.01  context helper
16415 + *  V0.02  vx_ctx_kill syscall command
16416 + *  V0.03  replaced context_info calls
16417 + *  V0.04  redesign of struct (de)alloc
16418 + *  V0.05  rlimit basic implementation
16419 + *  V0.06  task_xid and info commands
16420 + *  V0.07  context flags and caps
16421 + *  V0.08  switch to RCU based hash
16422 + *  V0.09  revert to non RCU for now
16423 + *  V0.10  and back to working RCU hash
16424 + *  V0.11  and back to locking again
16425 + *  V0.12  referenced context store
16426 + *  V0.13  separate per cpu data
16427 + *  V0.14  changed vcmds to vxi arg
16428 + *  V0.15  added context stat
16429 + *  V0.16  have __create claim() the vxi
16430 + *  V0.17  removed older and legacy stuff
16431 + *  V0.18  added user credentials
16432 + *
16433 + */
16434 +
16435 +#include <linux/slab.h>
16436 +#include <linux/types.h>
16437 +#include <linux/security.h>
16438 +#include <linux/pid_namespace.h>
16439 +
16440 +#include <linux/vserver/context.h>
16441 +#include <linux/vserver/network.h>
16442 +#include <linux/vserver/debug.h>
16443 +#include <linux/vserver/limit.h>
16444 +#include <linux/vserver/limit_int.h>
16445 +#include <linux/vserver/space.h>
16446 +#include <linux/init_task.h>
16447 +#include <linux/fs_struct.h>
16448 +#include <linux/cred.h>
16449 +
16450 +#include <linux/vs_context.h>
16451 +#include <linux/vs_limit.h>
16452 +#include <linux/vs_pid.h>
16453 +#include <linux/vserver/context_cmd.h>
16454 +
16455 +#include "cvirt_init.h"
16456 +#include "cacct_init.h"
16457 +#include "limit_init.h"
16458 +#include "sched_init.h"
16459 +
16460 +
16461 +atomic_t vx_global_ctotal      = ATOMIC_INIT(0);
16462 +atomic_t vx_global_cactive     = ATOMIC_INIT(0);
16463 +
16464 +
16465 +/*     now inactive context structures */
16466 +
16467 +static struct hlist_head vx_info_inactive = HLIST_HEAD_INIT;
16468 +
16469 +static spinlock_t vx_info_inactive_lock = SPIN_LOCK_UNLOCKED;
16470 +
16471 +
16472 +/*     __alloc_vx_info()
16473 +
16474 +       * allocate an initialized vx_info struct
16475 +       * doesn't make it visible (hash)                        */
16476 +
16477 +static struct vx_info *__alloc_vx_info(xid_t xid)
16478 +{
16479 +       struct vx_info *new = NULL;
16480 +       int cpu, index;
16481 +
16482 +       vxdprintk(VXD_CBIT(xid, 0), "alloc_vx_info(%d)*", xid);
16483 +
16484 +       /* would this benefit from a slab cache? */
16485 +       new = kmalloc(sizeof(struct vx_info), GFP_KERNEL);
16486 +       if (!new)
16487 +               return 0;
16488 +
16489 +       memset(new, 0, sizeof(struct vx_info));
16490 +#ifdef CONFIG_SMP
16491 +       new->ptr_pc = alloc_percpu(struct _vx_info_pc);
16492 +       if (!new->ptr_pc)
16493 +               goto error;
16494 +#endif
16495 +       new->vx_id = xid;
16496 +       INIT_HLIST_NODE(&new->vx_hlist);
16497 +       atomic_set(&new->vx_usecnt, 0);
16498 +       atomic_set(&new->vx_tasks, 0);
16499 +       new->vx_parent = NULL;
16500 +       new->vx_state = 0;
16501 +       init_waitqueue_head(&new->vx_wait);
16502 +
16503 +       /* prepare reaper */
16504 +       get_task_struct(init_pid_ns.child_reaper);
16505 +       new->vx_reaper = init_pid_ns.child_reaper;
16506 +       new->vx_badness_bias = 0;
16507 +
16508 +       /* rest of init goes here */
16509 +       vx_info_init_limit(&new->limit);
16510 +       vx_info_init_sched(&new->sched);
16511 +       vx_info_init_cvirt(&new->cvirt);
16512 +       vx_info_init_cacct(&new->cacct);
16513 +
16514 +       /* per cpu data structures */
16515 +       for_each_possible_cpu(cpu) {
16516 +               vx_info_init_sched_pc(
16517 +                       &vx_per_cpu(new, sched_pc, cpu), cpu);
16518 +               vx_info_init_cvirt_pc(
16519 +                       &vx_per_cpu(new, cvirt_pc, cpu), cpu);
16520 +       }
16521 +
16522 +       new->vx_flags = VXF_INIT_SET;
16523 +       cap_set_init_eff(new->vx_bcaps);
16524 +       new->vx_ccaps = 0;
16525 +       new->vx_umask = 0;
16526 +
16527 +       new->reboot_cmd = 0;
16528 +       new->exit_code = 0;
16529 +
16530 +       // preconfig spaces
16531 +       for (index = 0; index < VX_SPACES; index++) {
16532 +               struct _vx_space *space = &new->space[index];
16533 +
16534 +               // filesystem
16535 +               spin_lock(&init_fs.lock);
16536 +               init_fs.users++;
16537 +               spin_unlock(&init_fs.lock);
16538 +               space->vx_fs = &init_fs;
16539 +
16540 +               /* FIXME: do we want defaults? */
16541 +               // space->vx_real_cred = 0;
16542 +               // space->vx_cred = 0;
16543 +       }
16544 +
16545 +
16546 +       vxdprintk(VXD_CBIT(xid, 0),
16547 +               "alloc_vx_info(%d) = %p", xid, new);
16548 +       vxh_alloc_vx_info(new);
16549 +       atomic_inc(&vx_global_ctotal);
16550 +       return new;
16551 +#ifdef CONFIG_SMP
16552 +error:
16553 +       kfree(new);
16554 +       return 0;
16555 +#endif
16556 +}
16557 +
16558 +/*     __dealloc_vx_info()
16559 +
16560 +       * final disposal of vx_info                             */
16561 +
16562 +static void __dealloc_vx_info(struct vx_info *vxi)
16563 +{
16564 +#ifdef CONFIG_VSERVER_WARN
16565 +       struct vx_info_save vxis;
16566 +       int cpu;
16567 +#endif
16568 +       vxdprintk(VXD_CBIT(xid, 0),
16569 +               "dealloc_vx_info(%p)", vxi);
16570 +       vxh_dealloc_vx_info(vxi);
16571 +
16572 +#ifdef CONFIG_VSERVER_WARN
16573 +       enter_vx_info(vxi, &vxis);
16574 +       vx_info_exit_limit(&vxi->limit);
16575 +       vx_info_exit_sched(&vxi->sched);
16576 +       vx_info_exit_cvirt(&vxi->cvirt);
16577 +       vx_info_exit_cacct(&vxi->cacct);
16578 +
16579 +       for_each_possible_cpu(cpu) {
16580 +               vx_info_exit_sched_pc(
16581 +                       &vx_per_cpu(vxi, sched_pc, cpu), cpu);
16582 +               vx_info_exit_cvirt_pc(
16583 +                       &vx_per_cpu(vxi, cvirt_pc, cpu), cpu);
16584 +       }
16585 +       leave_vx_info(&vxis);
16586 +#endif
16587 +
16588 +       vxi->vx_id = -1;
16589 +       vxi->vx_state |= VXS_RELEASED;
16590 +
16591 +#ifdef CONFIG_SMP
16592 +       free_percpu(vxi->ptr_pc);
16593 +#endif
16594 +       kfree(vxi);
16595 +       atomic_dec(&vx_global_ctotal);
16596 +}
16597 +
16598 +static void __shutdown_vx_info(struct vx_info *vxi)
16599 +{
16600 +       struct nsproxy *nsproxy;
16601 +       struct fs_struct *fs;
16602 +       struct cred *cred;
16603 +       int index, kill;
16604 +
16605 +       might_sleep();
16606 +
16607 +       vxi->vx_state |= VXS_SHUTDOWN;
16608 +       vs_state_change(vxi, VSC_SHUTDOWN);
16609 +
16610 +       for (index = 0; index < VX_SPACES; index++) {
16611 +               struct _vx_space *space = &vxi->space[index];
16612 +
16613 +               nsproxy = xchg(&space->vx_nsproxy, NULL);
16614 +               if (nsproxy)
16615 +                       put_nsproxy(nsproxy);
16616 +
16617 +               fs = xchg(&space->vx_fs, NULL);
16618 +               spin_lock(&fs->lock);
16619 +               kill = !--fs->users;
16620 +               spin_unlock(&fs->lock);
16621 +               if (kill)
16622 +                       free_fs_struct(fs);
16623 +
16624 +               cred = (struct cred *)xchg(&space->vx_cred, NULL);
16625 +               if (cred)
16626 +                       abort_creds(cred);
16627 +       }
16628 +}
16629 +
16630 +/* exported stuff */
16631 +
16632 +void free_vx_info(struct vx_info *vxi)
16633 +{
16634 +       unsigned long flags;
16635 +       unsigned index;
16636 +
16637 +       /* check for reference counts first */
16638 +       BUG_ON(atomic_read(&vxi->vx_usecnt));
16639 +       BUG_ON(atomic_read(&vxi->vx_tasks));
16640 +
16641 +       /* context must not be hashed */
16642 +       BUG_ON(vx_info_state(vxi, VXS_HASHED));
16643 +
16644 +       /* context shutdown is mandatory */
16645 +       BUG_ON(!vx_info_state(vxi, VXS_SHUTDOWN));
16646 +
16647 +       /* spaces check */
16648 +       for (index = 0; index < VX_SPACES; index++) {
16649 +               struct _vx_space *space = &vxi->space[index];
16650 +
16651 +               BUG_ON(space->vx_nsproxy);
16652 +               BUG_ON(space->vx_fs);
16653 +               // BUG_ON(space->vx_real_cred);
16654 +               // BUG_ON(space->vx_cred);
16655 +       }
16656 +
16657 +       spin_lock_irqsave(&vx_info_inactive_lock, flags);
16658 +       hlist_del(&vxi->vx_hlist);
16659 +       spin_unlock_irqrestore(&vx_info_inactive_lock, flags);
16660 +
16661 +       __dealloc_vx_info(vxi);
16662 +}
16663 +
16664 +
16665 +/*     hash table for vx_info hash */
16666 +
16667 +#define VX_HASH_SIZE   13
16668 +
16669 +static struct hlist_head vx_info_hash[VX_HASH_SIZE] =
16670 +       { [0 ... VX_HASH_SIZE-1] = HLIST_HEAD_INIT };
16671 +
16672 +static spinlock_t vx_info_hash_lock = SPIN_LOCK_UNLOCKED;
16673 +
16674 +
16675 +static inline unsigned int __hashval(xid_t xid)
16676 +{
16677 +       return (xid % VX_HASH_SIZE);
16678 +}
16679 +
16680 +
16681 +
16682 +/*     __hash_vx_info()
16683 +
16684 +       * add the vxi to the global hash table
16685 +       * requires the hash_lock to be held                     */
16686 +
16687 +static inline void __hash_vx_info(struct vx_info *vxi)
16688 +{
16689 +       struct hlist_head *head;
16690 +
16691 +       vxd_assert_lock(&vx_info_hash_lock);
16692 +       vxdprintk(VXD_CBIT(xid, 4),
16693 +               "__hash_vx_info: %p[#%d]", vxi, vxi->vx_id);
16694 +       vxh_hash_vx_info(vxi);
16695 +
16696 +       /* context must not be hashed */
16697 +       BUG_ON(vx_info_state(vxi, VXS_HASHED));
16698 +
16699 +       vxi->vx_state |= VXS_HASHED;
16700 +       head = &vx_info_hash[__hashval(vxi->vx_id)];
16701 +       hlist_add_head(&vxi->vx_hlist, head);
16702 +       atomic_inc(&vx_global_cactive);
16703 +}
16704 +
16705 +/*     __unhash_vx_info()
16706 +
16707 +       * remove the vxi from the global hash table
16708 +       * requires the hash_lock to be held                     */
16709 +
16710 +static inline void __unhash_vx_info(struct vx_info *vxi)
16711 +{
16712 +       unsigned long flags;
16713 +
16714 +       vxd_assert_lock(&vx_info_hash_lock);
16715 +       vxdprintk(VXD_CBIT(xid, 4),
16716 +               "__unhash_vx_info: %p[#%d.%d.%d]", vxi, vxi->vx_id,
16717 +               atomic_read(&vxi->vx_usecnt), atomic_read(&vxi->vx_tasks));
16718 +       vxh_unhash_vx_info(vxi);
16719 +
16720 +       /* context must be hashed */
16721 +       BUG_ON(!vx_info_state(vxi, VXS_HASHED));
16722 +       /* but without tasks */
16723 +       BUG_ON(atomic_read(&vxi->vx_tasks));
16724 +
16725 +       vxi->vx_state &= ~VXS_HASHED;
16726 +       hlist_del_init(&vxi->vx_hlist);
16727 +       spin_lock_irqsave(&vx_info_inactive_lock, flags);
16728 +       hlist_add_head(&vxi->vx_hlist, &vx_info_inactive);
16729 +       spin_unlock_irqrestore(&vx_info_inactive_lock, flags);
16730 +       atomic_dec(&vx_global_cactive);
16731 +}
16732 +
16733 +
16734 +/*     __lookup_vx_info()
16735 +
16736 +       * requires the hash_lock to be held
16737 +       * doesn't increment the vx_refcnt                       */
16738 +
16739 +static inline struct vx_info *__lookup_vx_info(xid_t xid)
16740 +{
16741 +       struct hlist_head *head = &vx_info_hash[__hashval(xid)];
16742 +       struct hlist_node *pos;
16743 +       struct vx_info *vxi;
16744 +
16745 +       vxd_assert_lock(&vx_info_hash_lock);
16746 +       hlist_for_each(pos, head) {
16747 +               vxi = hlist_entry(pos, struct vx_info, vx_hlist);
16748 +
16749 +               if (vxi->vx_id == xid)
16750 +                       goto found;
16751 +       }
16752 +       vxi = NULL;
16753 +found:
16754 +       vxdprintk(VXD_CBIT(xid, 0),
16755 +               "__lookup_vx_info(#%u): %p[#%u]",
16756 +               xid, vxi, vxi ? vxi->vx_id : 0);
16757 +       vxh_lookup_vx_info(vxi, xid);
16758 +       return vxi;
16759 +}
16760 +
16761 +
16762 +/*     __create_vx_info()
16763 +
16764 +       * create the requested context
16765 +       * get(), claim() and hash it                            */
16766 +
16767 +static struct vx_info *__create_vx_info(int id)
16768 +{
16769 +       struct vx_info *new, *vxi = NULL;
16770 +
16771 +       vxdprintk(VXD_CBIT(xid, 1), "create_vx_info(%d)*", id);
16772 +
16773 +       if (!(new = __alloc_vx_info(id)))
16774 +               return ERR_PTR(-ENOMEM);
16775 +
16776 +       /* required to make dynamic xids unique */
16777 +       spin_lock(&vx_info_hash_lock);
16778 +
16779 +       /* static context requested */
16780 +       if ((vxi = __lookup_vx_info(id))) {
16781 +               vxdprintk(VXD_CBIT(xid, 0),
16782 +                       "create_vx_info(%d) = %p (already there)", id, vxi);
16783 +               if (vx_info_flags(vxi, VXF_STATE_SETUP, 0))
16784 +                       vxi = ERR_PTR(-EBUSY);
16785 +               else
16786 +                       vxi = ERR_PTR(-EEXIST);
16787 +               goto out_unlock;
16788 +       }
16789 +       /* new context */
16790 +       vxdprintk(VXD_CBIT(xid, 0),
16791 +               "create_vx_info(%d) = %p (new)", id, new);
16792 +       claim_vx_info(new, NULL);
16793 +       __hash_vx_info(get_vx_info(new));
16794 +       vxi = new, new = NULL;
16795 +
16796 +out_unlock:
16797 +       spin_unlock(&vx_info_hash_lock);
16798 +       vxh_create_vx_info(IS_ERR(vxi) ? NULL : vxi, id);
16799 +       if (new)
16800 +               __dealloc_vx_info(new);
16801 +       return vxi;
16802 +}
16803 +
16804 +
16805 +/*     exported stuff                                          */
16806 +
16807 +
16808 +void unhash_vx_info(struct vx_info *vxi)
16809 +{
16810 +       __shutdown_vx_info(vxi);
16811 +       spin_lock(&vx_info_hash_lock);
16812 +       __unhash_vx_info(vxi);
16813 +       spin_unlock(&vx_info_hash_lock);
16814 +       __wakeup_vx_info(vxi);
16815 +}
16816 +
16817 +
16818 +/*     lookup_vx_info()
16819 +
16820 +       * search for a vx_info and get() it
16821 +       * negative id means current                             */
16822 +
16823 +struct vx_info *lookup_vx_info(int id)
16824 +{
16825 +       struct vx_info *vxi = NULL;
16826 +
16827 +       if (id < 0) {
16828 +               vxi = get_vx_info(current_vx_info());
16829 +       } else if (id > 1) {
16830 +               spin_lock(&vx_info_hash_lock);
16831 +               vxi = get_vx_info(__lookup_vx_info(id));
16832 +               spin_unlock(&vx_info_hash_lock);
16833 +       }
16834 +       return vxi;
16835 +}
16836 +
16837 +/*     xid_is_hashed()
16838 +
16839 +       * verify that xid is still hashed                       */
16840 +
16841 +int xid_is_hashed(xid_t xid)
16842 +{
16843 +       int hashed;
16844 +
16845 +       spin_lock(&vx_info_hash_lock);
16846 +       hashed = (__lookup_vx_info(xid) != NULL);
16847 +       spin_unlock(&vx_info_hash_lock);
16848 +       return hashed;
16849 +}
16850 +
16851 +#ifdef CONFIG_PROC_FS
16852 +
16853 +/*     get_xid_list()
16854 +
16855 +       * get a subset of hashed xids for proc
16856 +       * assumes size is at least one                          */
16857 +
16858 +int get_xid_list(int index, unsigned int *xids, int size)
16859 +{
16860 +       int hindex, nr_xids = 0;
16861 +
16862 +       /* only show current and children */
16863 +       if (!vx_check(0, VS_ADMIN | VS_WATCH)) {
16864 +               if (index > 0)
16865 +                       return 0;
16866 +               xids[nr_xids] = vx_current_xid();
16867 +               return 1;
16868 +       }
16869 +
16870 +       for (hindex = 0; hindex < VX_HASH_SIZE; hindex++) {
16871 +               struct hlist_head *head = &vx_info_hash[hindex];
16872 +               struct hlist_node *pos;
16873 +
16874 +               spin_lock(&vx_info_hash_lock);
16875 +               hlist_for_each(pos, head) {
16876 +                       struct vx_info *vxi;
16877 +
16878 +                       if (--index > 0)
16879 +                               continue;
16880 +
16881 +                       vxi = hlist_entry(pos, struct vx_info, vx_hlist);
16882 +                       xids[nr_xids] = vxi->vx_id;
16883 +                       if (++nr_xids >= size) {
16884 +                               spin_unlock(&vx_info_hash_lock);
16885 +                               goto out;
16886 +                       }
16887 +               }
16888 +               /* keep the lock time short */
16889 +               spin_unlock(&vx_info_hash_lock);
16890 +       }
16891 +out:
16892 +       return nr_xids;
16893 +}
16894 +#endif
16895 +
16896 +#ifdef CONFIG_VSERVER_DEBUG
16897 +
16898 +void   dump_vx_info_inactive(int level)
16899 +{
16900 +       struct hlist_node *entry, *next;
16901 +
16902 +       hlist_for_each_safe(entry, next, &vx_info_inactive) {
16903 +               struct vx_info *vxi =
16904 +                       list_entry(entry, struct vx_info, vx_hlist);
16905 +
16906 +               dump_vx_info(vxi, level);
16907 +       }
16908 +}
16909 +
16910 +#endif
16911 +
16912 +#if 0
16913 +int vx_migrate_user(struct task_struct *p, struct vx_info *vxi)
16914 +{
16915 +       struct user_struct *new_user, *old_user;
16916 +
16917 +       if (!p || !vxi)
16918 +               BUG();
16919 +
16920 +       if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0))
16921 +               return -EACCES;
16922 +
16923 +       new_user = alloc_uid(vxi->vx_id, p->uid);
16924 +       if (!new_user)
16925 +               return -ENOMEM;
16926 +
16927 +       old_user = p->user;
16928 +       if (new_user != old_user) {
16929 +               atomic_inc(&new_user->processes);
16930 +               atomic_dec(&old_user->processes);
16931 +               p->user = new_user;
16932 +       }
16933 +       free_uid(old_user);
16934 +       return 0;
16935 +}
16936 +#endif
16937 +
16938 +#if 0
16939 +void vx_mask_cap_bset(struct vx_info *vxi, struct task_struct *p)
16940 +{
16941 +       // p->cap_effective &= vxi->vx_cap_bset;
16942 +       p->cap_effective =
16943 +               cap_intersect(p->cap_effective, vxi->cap_bset);
16944 +       // p->cap_inheritable &= vxi->vx_cap_bset;
16945 +       p->cap_inheritable =
16946 +               cap_intersect(p->cap_inheritable, vxi->cap_bset);
16947 +       // p->cap_permitted &= vxi->vx_cap_bset;
16948 +       p->cap_permitted =
16949 +               cap_intersect(p->cap_permitted, vxi->cap_bset);
16950 +}
16951 +#endif
16952 +
16953 +
16954 +#include <linux/file.h>
16955 +#include <linux/fdtable.h>
16956 +
16957 +static int vx_openfd_task(struct task_struct *tsk)
16958 +{
16959 +       struct files_struct *files = tsk->files;
16960 +       struct fdtable *fdt;
16961 +       const unsigned long *bptr;
16962 +       int count, total;
16963 +
16964 +       /* no rcu_read_lock() because of spin_lock() */
16965 +       spin_lock(&files->file_lock);
16966 +       fdt = files_fdtable(files);
16967 +       bptr = fdt->open_fds->fds_bits;
16968 +       count = fdt->max_fds / (sizeof(unsigned long) * 8);
16969 +       for (total = 0; count > 0; count--) {
16970 +               if (*bptr)
16971 +                       total += hweight_long(*bptr);
16972 +               bptr++;
16973 +       }
16974 +       spin_unlock(&files->file_lock);
16975 +       return total;
16976 +}
16977 +
16978 +
16979 +/*     for *space compatibility */
16980 +
16981 +asmlinkage long sys_unshare(unsigned long);
16982 +
16983 +/*
16984 + *     migrate task to new context
16985 + *     gets vxi, puts old_vxi on change
16986 + *     optionally unshares namespaces (hack)
16987 + */
16988 +
16989 +int vx_migrate_task(struct task_struct *p, struct vx_info *vxi, int unshare)
16990 +{
16991 +       struct vx_info *old_vxi;
16992 +       int ret = 0;
16993 +
16994 +       if (!p || !vxi)
16995 +               BUG();
16996 +
16997 +       vxdprintk(VXD_CBIT(xid, 5),
16998 +               "vx_migrate_task(%p,%p[#%d.%d])", p, vxi,
16999 +               vxi->vx_id, atomic_read(&vxi->vx_usecnt));
17000 +
17001 +       if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0) &&
17002 +               !vx_info_flags(vxi, VXF_STATE_SETUP, 0))
17003 +               return -EACCES;
17004 +
17005 +       if (vx_info_state(vxi, VXS_SHUTDOWN))
17006 +               return -EFAULT;
17007 +
17008 +       old_vxi = task_get_vx_info(p);
17009 +       if (old_vxi == vxi)
17010 +               goto out;
17011 +
17012 +//     if (!(ret = vx_migrate_user(p, vxi))) {
17013 +       {
17014 +               int openfd;
17015 +
17016 +               task_lock(p);
17017 +               openfd = vx_openfd_task(p);
17018 +
17019 +               if (old_vxi) {
17020 +                       atomic_dec(&old_vxi->cvirt.nr_threads);
17021 +                       atomic_dec(&old_vxi->cvirt.nr_running);
17022 +                       __rlim_dec(&old_vxi->limit, RLIMIT_NPROC);
17023 +                       /* FIXME: what about the struct files here? */
17024 +                       __rlim_sub(&old_vxi->limit, VLIMIT_OPENFD, openfd);
17025 +                       /* account for the executable */
17026 +                       __rlim_dec(&old_vxi->limit, VLIMIT_DENTRY);
17027 +               }
17028 +               atomic_inc(&vxi->cvirt.nr_threads);
17029 +               atomic_inc(&vxi->cvirt.nr_running);
17030 +               __rlim_inc(&vxi->limit, RLIMIT_NPROC);
17031 +               /* FIXME: what about the struct files here? */
17032 +               __rlim_add(&vxi->limit, VLIMIT_OPENFD, openfd);
17033 +               /* account for the executable */
17034 +               __rlim_inc(&vxi->limit, VLIMIT_DENTRY);
17035 +
17036 +               if (old_vxi) {
17037 +                       release_vx_info(old_vxi, p);
17038 +                       clr_vx_info(&p->vx_info);
17039 +               }
17040 +               claim_vx_info(vxi, p);
17041 +               set_vx_info(&p->vx_info, vxi);
17042 +               p->xid = vxi->vx_id;
17043 +
17044 +               vxdprintk(VXD_CBIT(xid, 5),
17045 +                       "moved task %p into vxi:%p[#%d]",
17046 +                       p, vxi, vxi->vx_id);
17047 +
17048 +               // vx_mask_cap_bset(vxi, p);
17049 +               task_unlock(p);
17050 +
17051 +               /* hack for *spaces to provide compatibility */
17052 +               if (unshare) {
17053 +                       struct nsproxy *old_nsp, *new_nsp;
17054 +
17055 +                       ret = unshare_nsproxy_namespaces(
17056 +                               CLONE_NEWUTS | CLONE_NEWIPC | CLONE_NEWUSER,
17057 +                               &new_nsp, NULL);
17058 +                       if (ret)
17059 +                               goto out;
17060 +
17061 +                       old_nsp = xchg(&p->nsproxy, new_nsp);
17062 +                       vx_set_space(vxi,
17063 +                               CLONE_NEWUTS | CLONE_NEWIPC | CLONE_NEWUSER, 0);
17064 +                       put_nsproxy(old_nsp);
17065 +               }
17066 +       }
17067 +out:
17068 +       put_vx_info(old_vxi);
17069 +       return ret;
17070 +}
17071 +
17072 +int vx_set_reaper(struct vx_info *vxi, struct task_struct *p)
17073 +{
17074 +       struct task_struct *old_reaper;
17075 +
17076 +       if (!vxi)
17077 +               return -EINVAL;
17078 +
17079 +       vxdprintk(VXD_CBIT(xid, 6),
17080 +               "vx_set_reaper(%p[#%d],%p[#%d,%d])",
17081 +               vxi, vxi->vx_id, p, p->xid, p->pid);
17082 +
17083 +       old_reaper = vxi->vx_reaper;
17084 +       if (old_reaper == p)
17085 +               return 0;
17086 +
17087 +       /* set new child reaper */
17088 +       get_task_struct(p);
17089 +       vxi->vx_reaper = p;
17090 +       put_task_struct(old_reaper);
17091 +       return 0;
17092 +}
17093 +
17094 +int vx_set_init(struct vx_info *vxi, struct task_struct *p)
17095 +{
17096 +       if (!vxi)
17097 +               return -EINVAL;
17098 +
17099 +       vxdprintk(VXD_CBIT(xid, 6),
17100 +               "vx_set_init(%p[#%d],%p[#%d,%d,%d])",
17101 +               vxi, vxi->vx_id, p, p->xid, p->pid, p->tgid);
17102 +
17103 +       vxi->vx_flags &= ~VXF_STATE_INIT;
17104 +       // vxi->vx_initpid = p->tgid;
17105 +       vxi->vx_initpid = p->pid;
17106 +       return 0;
17107 +}
17108 +
17109 +void vx_exit_init(struct vx_info *vxi, struct task_struct *p, int code)
17110 +{
17111 +       vxdprintk(VXD_CBIT(xid, 6),
17112 +               "vx_exit_init(%p[#%d],%p[#%d,%d,%d])",
17113 +               vxi, vxi->vx_id, p, p->xid, p->pid, p->tgid);
17114 +
17115 +       vxi->exit_code = code;
17116 +       vxi->vx_initpid = 0;
17117 +}
17118 +
17119 +
17120 +void vx_set_persistent(struct vx_info *vxi)
17121 +{
17122 +       vxdprintk(VXD_CBIT(xid, 6),
17123 +               "vx_set_persistent(%p[#%d])", vxi, vxi->vx_id);
17124 +
17125 +       get_vx_info(vxi);
17126 +       claim_vx_info(vxi, NULL);
17127 +}
17128 +
17129 +void vx_clear_persistent(struct vx_info *vxi)
17130 +{
17131 +       vxdprintk(VXD_CBIT(xid, 6),
17132 +               "vx_clear_persistent(%p[#%d])", vxi, vxi->vx_id);
17133 +
17134 +       release_vx_info(vxi, NULL);
17135 +       put_vx_info(vxi);
17136 +}
17137 +
17138 +void vx_update_persistent(struct vx_info *vxi)
17139 +{
17140 +       if (vx_info_flags(vxi, VXF_PERSISTENT, 0))
17141 +               vx_set_persistent(vxi);
17142 +       else
17143 +               vx_clear_persistent(vxi);
17144 +}
17145 +
17146 +
17147 +/*     task must be current or locked          */
17148 +
17149 +void   exit_vx_info(struct task_struct *p, int code)
17150 +{
17151 +       struct vx_info *vxi = p->vx_info;
17152 +
17153 +       if (vxi) {
17154 +               atomic_dec(&vxi->cvirt.nr_threads);
17155 +               vx_nproc_dec(p);
17156 +
17157 +               vxi->exit_code = code;
17158 +               release_vx_info(vxi, p);
17159 +       }
17160 +}
17161 +
17162 +void   exit_vx_info_early(struct task_struct *p, int code)
17163 +{
17164 +       struct vx_info *vxi = p->vx_info;
17165 +
17166 +       if (vxi) {
17167 +               if (vxi->vx_initpid == p->pid)
17168 +                       vx_exit_init(vxi, p, code);
17169 +               if (vxi->vx_reaper == p)
17170 +                       vx_set_reaper(vxi, init_pid_ns.child_reaper);
17171 +       }
17172 +}
17173 +
17174 +
17175 +/* vserver syscall commands below here */
17176 +
17177 +/* taks xid and vx_info functions */
17178 +
17179 +#include <asm/uaccess.h>
17180 +
17181 +
17182 +int vc_task_xid(uint32_t id)
17183 +{
17184 +       xid_t xid;
17185 +
17186 +       if (id) {
17187 +               struct task_struct *tsk;
17188 +
17189 +               rcu_read_lock();
17190 +               tsk = find_task_by_real_pid(id);
17191 +               xid = (tsk) ? tsk->xid : -ESRCH;
17192 +               rcu_read_unlock();
17193 +       } else
17194 +               xid = vx_current_xid();
17195 +       return xid;
17196 +}
17197 +
17198 +
17199 +int vc_vx_info(struct vx_info *vxi, void __user *data)
17200 +{
17201 +       struct vcmd_vx_info_v0 vc_data;
17202 +
17203 +       vc_data.xid = vxi->vx_id;
17204 +       vc_data.initpid = vxi->vx_initpid;
17205 +
17206 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
17207 +               return -EFAULT;
17208 +       return 0;
17209 +}
17210 +
17211 +
17212 +int vc_ctx_stat(struct vx_info *vxi, void __user *data)
17213 +{
17214 +       struct vcmd_ctx_stat_v0 vc_data;
17215 +
17216 +       vc_data.usecnt = atomic_read(&vxi->vx_usecnt);
17217 +       vc_data.tasks = atomic_read(&vxi->vx_tasks);
17218 +
17219 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
17220 +               return -EFAULT;
17221 +       return 0;
17222 +}
17223 +
17224 +
17225 +/* context functions */
17226 +
17227 +int vc_ctx_create(uint32_t xid, void __user *data)
17228 +{
17229 +       struct vcmd_ctx_create vc_data = { .flagword = VXF_INIT_SET };
17230 +       struct vx_info *new_vxi;
17231 +       int ret;
17232 +
17233 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
17234 +               return -EFAULT;
17235 +
17236 +       if ((xid > MAX_S_CONTEXT) || (xid < 2))
17237 +               return -EINVAL;
17238 +
17239 +       new_vxi = __create_vx_info(xid);
17240 +       if (IS_ERR(new_vxi))
17241 +               return PTR_ERR(new_vxi);
17242 +
17243 +       /* initial flags */
17244 +       new_vxi->vx_flags = vc_data.flagword;
17245 +
17246 +       ret = -ENOEXEC;
17247 +       if (vs_state_change(new_vxi, VSC_STARTUP))
17248 +               goto out;
17249 +
17250 +       ret = vx_migrate_task(current, new_vxi, (!data));
17251 +       if (ret)
17252 +               goto out;
17253 +
17254 +       /* return context id on success */
17255 +       ret = new_vxi->vx_id;
17256 +
17257 +       /* get a reference for persistent contexts */
17258 +       if ((vc_data.flagword & VXF_PERSISTENT))
17259 +               vx_set_persistent(new_vxi);
17260 +out:
17261 +       release_vx_info(new_vxi, NULL);
17262 +       put_vx_info(new_vxi);
17263 +       return ret;
17264 +}
17265 +
17266 +
17267 +int vc_ctx_migrate(struct vx_info *vxi, void __user *data)
17268 +{
17269 +       struct vcmd_ctx_migrate vc_data = { .flagword = 0 };
17270 +       int ret;
17271 +
17272 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
17273 +               return -EFAULT;
17274 +
17275 +       ret = vx_migrate_task(current, vxi, 0);
17276 +       if (ret)
17277 +               return ret;
17278 +       if (vc_data.flagword & VXM_SET_INIT)
17279 +               ret = vx_set_init(vxi, current);
17280 +       if (ret)
17281 +               return ret;
17282 +       if (vc_data.flagword & VXM_SET_REAPER)
17283 +               ret = vx_set_reaper(vxi, current);
17284 +       return ret;
17285 +}
17286 +
17287 +
17288 +int vc_get_cflags(struct vx_info *vxi, void __user *data)
17289 +{
17290 +       struct vcmd_ctx_flags_v0 vc_data;
17291 +
17292 +       vc_data.flagword = vxi->vx_flags;
17293 +
17294 +       /* special STATE flag handling */
17295 +       vc_data.mask = vs_mask_flags(~0ULL, vxi->vx_flags, VXF_ONE_TIME);
17296 +
17297 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
17298 +               return -EFAULT;
17299 +       return 0;
17300 +}
17301 +
17302 +int vc_set_cflags(struct vx_info *vxi, void __user *data)
17303 +{
17304 +       struct vcmd_ctx_flags_v0 vc_data;
17305 +       uint64_t mask, trigger;
17306 +
17307 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17308 +               return -EFAULT;
17309 +
17310 +       /* special STATE flag handling */
17311 +       mask = vs_mask_mask(vc_data.mask, vxi->vx_flags, VXF_ONE_TIME);
17312 +       trigger = (mask & vxi->vx_flags) ^ (mask & vc_data.flagword);
17313 +
17314 +       if (vxi == current_vx_info()) {
17315 +               /* if (trigger & VXF_STATE_SETUP)
17316 +                       vx_mask_cap_bset(vxi, current); */
17317 +               if (trigger & VXF_STATE_INIT) {
17318 +                       int ret;
17319 +
17320 +                       ret = vx_set_init(vxi, current);
17321 +                       if (ret)
17322 +                               return ret;
17323 +                       ret = vx_set_reaper(vxi, current);
17324 +                       if (ret)
17325 +                               return ret;
17326 +               }
17327 +       }
17328 +
17329 +       vxi->vx_flags = vs_mask_flags(vxi->vx_flags,
17330 +               vc_data.flagword, mask);
17331 +       if (trigger & VXF_PERSISTENT)
17332 +               vx_update_persistent(vxi);
17333 +
17334 +       return 0;
17335 +}
17336 +
17337 +
17338 +static inline uint64_t caps_from_cap_t(kernel_cap_t c)
17339 +{
17340 +       uint64_t v = c.cap[0] | ((uint64_t)c.cap[1] << 32);
17341 +
17342 +       // printk("caps_from_cap_t(%08x:%08x) = %016llx\n", c.cap[1], c.cap[0], v);
17343 +       return v;
17344 +}
17345 +
17346 +static inline kernel_cap_t cap_t_from_caps(uint64_t v)
17347 +{
17348 +       kernel_cap_t c = __cap_empty_set;
17349 +
17350 +       c.cap[0] = v & 0xFFFFFFFF;
17351 +       c.cap[1] = (v >> 32) & 0xFFFFFFFF;
17352 +
17353 +       // printk("cap_t_from_caps(%016llx) = %08x:%08x\n", v, c.cap[1], c.cap[0]);
17354 +       return c;
17355 +}
17356 +
17357 +
17358 +static int do_get_caps(struct vx_info *vxi, uint64_t *bcaps, uint64_t *ccaps)
17359 +{
17360 +       if (bcaps)
17361 +               *bcaps = caps_from_cap_t(vxi->vx_bcaps);
17362 +       if (ccaps)
17363 +               *ccaps = vxi->vx_ccaps;
17364 +
17365 +       return 0;
17366 +}
17367 +
17368 +int vc_get_ccaps(struct vx_info *vxi, void __user *data)
17369 +{
17370 +       struct vcmd_ctx_caps_v1 vc_data;
17371 +       int ret;
17372 +
17373 +       ret = do_get_caps(vxi, NULL, &vc_data.ccaps);
17374 +       if (ret)
17375 +               return ret;
17376 +       vc_data.cmask = ~0ULL;
17377 +
17378 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
17379 +               return -EFAULT;
17380 +       return 0;
17381 +}
17382 +
17383 +static int do_set_caps(struct vx_info *vxi,
17384 +       uint64_t bcaps, uint64_t bmask, uint64_t ccaps, uint64_t cmask)
17385 +{
17386 +       uint64_t bcold = caps_from_cap_t(vxi->vx_bcaps);
17387 +
17388 +#if 0
17389 +       printk("do_set_caps(%16llx, %16llx, %16llx, %16llx)\n",
17390 +               bcaps, bmask, ccaps, cmask);
17391 +#endif
17392 +       vxi->vx_bcaps = cap_t_from_caps(
17393 +               vs_mask_flags(bcold, bcaps, bmask));
17394 +       vxi->vx_ccaps = vs_mask_flags(vxi->vx_ccaps, ccaps, cmask);
17395 +
17396 +       return 0;
17397 +}
17398 +
17399 +int vc_set_ccaps(struct vx_info *vxi, void __user *data)
17400 +{
17401 +       struct vcmd_ctx_caps_v1 vc_data;
17402 +
17403 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17404 +               return -EFAULT;
17405 +
17406 +       return do_set_caps(vxi, 0, 0, vc_data.ccaps, vc_data.cmask);
17407 +}
17408 +
17409 +int vc_get_bcaps(struct vx_info *vxi, void __user *data)
17410 +{
17411 +       struct vcmd_bcaps vc_data;
17412 +       int ret;
17413 +
17414 +       ret = do_get_caps(vxi, &vc_data.bcaps, NULL);
17415 +       if (ret)
17416 +               return ret;
17417 +       vc_data.bmask = ~0ULL;
17418 +
17419 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
17420 +               return -EFAULT;
17421 +       return 0;
17422 +}
17423 +
17424 +int vc_set_bcaps(struct vx_info *vxi, void __user *data)
17425 +{
17426 +       struct vcmd_bcaps vc_data;
17427 +
17428 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17429 +               return -EFAULT;
17430 +
17431 +       return do_set_caps(vxi, vc_data.bcaps, vc_data.bmask, 0, 0);
17432 +}
17433 +
17434 +
17435 +int vc_get_umask(struct vx_info *vxi, void __user *data)
17436 +{
17437 +       struct vcmd_umask vc_data;
17438 +
17439 +       vc_data.umask = vxi->vx_umask;
17440 +       vc_data.mask = ~0ULL;
17441 +
17442 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
17443 +               return -EFAULT;
17444 +       return 0;
17445 +}
17446 +
17447 +int vc_set_umask(struct vx_info *vxi, void __user *data)
17448 +{
17449 +       struct vcmd_umask vc_data;
17450 +
17451 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17452 +               return -EFAULT;
17453 +
17454 +       vxi->vx_umask = vs_mask_flags(vxi->vx_umask,
17455 +               vc_data.umask, vc_data.mask);
17456 +       return 0;
17457 +}
17458 +
17459 +
17460 +int vc_get_badness(struct vx_info *vxi, void __user *data)
17461 +{
17462 +       struct vcmd_badness_v0 vc_data;
17463 +
17464 +       vc_data.bias = vxi->vx_badness_bias;
17465 +
17466 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
17467 +               return -EFAULT;
17468 +       return 0;
17469 +}
17470 +
17471 +int vc_set_badness(struct vx_info *vxi, void __user *data)
17472 +{
17473 +       struct vcmd_badness_v0 vc_data;
17474 +
17475 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17476 +               return -EFAULT;
17477 +
17478 +       vxi->vx_badness_bias = vc_data.bias;
17479 +       return 0;
17480 +}
17481 +
17482 +#include <linux/module.h>
17483 +
17484 +EXPORT_SYMBOL_GPL(free_vx_info);
17485 +
17486 diff -NurpP --minimal linux-2.6.38.1/kernel/vserver/cvirt.c linux-2.6.38.1-vs2.3.0.37-rc9/kernel/vserver/cvirt.c
17487 --- linux-2.6.38.1/kernel/vserver/cvirt.c       1970-01-01 01:00:00.000000000 +0100
17488 +++ linux-2.6.38.1-vs2.3.0.37-rc9/kernel/vserver/cvirt.c        2011-01-29 02:01:07.000000000 +0100
17489 @@ -0,0 +1,303 @@
17490 +/*
17491 + *  linux/kernel/vserver/cvirt.c
17492 + *
17493 + *  Virtual Server: Context Virtualization
17494 + *
17495 + *  Copyright (C) 2004-2007  Herbert Pötzl
17496 + *
17497 + *  V0.01  broken out from limit.c
17498 + *  V0.02  added utsname stuff
17499 + *  V0.03  changed vcmds to vxi arg
17500 + *
17501 + */
17502 +
17503 +#include <linux/types.h>
17504 +#include <linux/utsname.h>
17505 +#include <linux/vs_cvirt.h>
17506 +#include <linux/vserver/switch.h>
17507 +#include <linux/vserver/cvirt_cmd.h>
17508 +
17509 +#include <asm/uaccess.h>
17510 +
17511 +
17512 +void vx_vsi_uptime(struct timespec *uptime, struct timespec *idle)
17513 +{
17514 +       struct vx_info *vxi = current_vx_info();
17515 +
17516 +       set_normalized_timespec(uptime,
17517 +               uptime->tv_sec - vxi->cvirt.bias_uptime.tv_sec,
17518 +               uptime->tv_nsec - vxi->cvirt.bias_uptime.tv_nsec);
17519 +       if (!idle)
17520 +               return;
17521 +       set_normalized_timespec(idle,
17522 +               idle->tv_sec - vxi->cvirt.bias_idle.tv_sec,
17523 +               idle->tv_nsec - vxi->cvirt.bias_idle.tv_nsec);
17524 +       return;
17525 +}
17526 +
17527 +uint64_t vx_idle_jiffies(void)
17528 +{
17529 +       return init_task.utime + init_task.stime;
17530 +}
17531 +
17532 +
17533 +
17534 +static inline uint32_t __update_loadavg(uint32_t load,
17535 +       int wsize, int delta, int n)
17536 +{
17537 +       unsigned long long calc, prev;
17538 +
17539 +       /* just set it to n */
17540 +       if (unlikely(delta >= wsize))
17541 +               return (n << FSHIFT);
17542 +
17543 +       calc = delta * n;
17544 +       calc <<= FSHIFT;
17545 +       prev = (wsize - delta);
17546 +       prev *= load;
17547 +       calc += prev;
17548 +       do_div(calc, wsize);
17549 +       return calc;
17550 +}
17551 +
17552 +
17553 +void vx_update_load(struct vx_info *vxi)
17554 +{
17555 +       uint32_t now, last, delta;
17556 +       unsigned int nr_running, nr_uninterruptible;
17557 +       unsigned int total;
17558 +       unsigned long flags;
17559 +
17560 +       spin_lock_irqsave(&vxi->cvirt.load_lock, flags);
17561 +
17562 +       now = jiffies;
17563 +       last = vxi->cvirt.load_last;
17564 +       delta = now - last;
17565 +
17566 +       if (delta < 5*HZ)
17567 +               goto out;
17568 +
17569 +       nr_running = atomic_read(&vxi->cvirt.nr_running);
17570 +       nr_uninterruptible = atomic_read(&vxi->cvirt.nr_uninterruptible);
17571 +       total = nr_running + nr_uninterruptible;
17572 +
17573 +       vxi->cvirt.load[0] = __update_loadavg(vxi->cvirt.load[0],
17574 +               60*HZ, delta, total);
17575 +       vxi->cvirt.load[1] = __update_loadavg(vxi->cvirt.load[1],
17576 +               5*60*HZ, delta, total);
17577 +       vxi->cvirt.load[2] = __update_loadavg(vxi->cvirt.load[2],
17578 +               15*60*HZ, delta, total);
17579 +
17580 +       vxi->cvirt.load_last = now;
17581 +out:
17582 +       atomic_inc(&vxi->cvirt.load_updates);
17583 +       spin_unlock_irqrestore(&vxi->cvirt.load_lock, flags);
17584 +}
17585 +
17586 +
17587 +/*
17588 + * Commands to do_syslog:
17589 + *
17590 + *      0 -- Close the log.  Currently a NOP.
17591 + *      1 -- Open the log. Currently a NOP.
17592 + *      2 -- Read from the log.
17593 + *      3 -- Read all messages remaining in the ring buffer.
17594 + *      4 -- Read and clear all messages remaining in the ring buffer
17595 + *      5 -- Clear ring buffer.
17596 + *      6 -- Disable printk's to console
17597 + *      7 -- Enable printk's to console
17598 + *      8 -- Set level of messages printed to console
17599 + *      9 -- Return number of unread characters in the log buffer
17600 + *     10 -- Return size of the log buffer
17601 + */
17602 +int vx_do_syslog(int type, char __user *buf, int len)
17603 +{
17604 +       int error = 0;
17605 +       int do_clear = 0;
17606 +       struct vx_info *vxi = current_vx_info();
17607 +       struct _vx_syslog *log;
17608 +
17609 +       if (!vxi)
17610 +               return -EINVAL;
17611 +       log = &vxi->cvirt.syslog;
17612 +
17613 +       switch (type) {
17614 +       case 0:         /* Close log */
17615 +       case 1:         /* Open log */
17616 +               break;
17617 +       case 2:         /* Read from log */
17618 +               error = wait_event_interruptible(log->log_wait,
17619 +                       (log->log_start - log->log_end));
17620 +               if (error)
17621 +                       break;
17622 +               spin_lock_irq(&log->logbuf_lock);
17623 +               spin_unlock_irq(&log->logbuf_lock);
17624 +               break;
17625 +       case 4:         /* Read/clear last kernel messages */
17626 +               do_clear = 1;
17627 +               /* fall through */
17628 +       case 3:         /* Read last kernel messages */
17629 +               return 0;
17630 +
17631 +       case 5:         /* Clear ring buffer */
17632 +               return 0;
17633 +
17634 +       case 6:         /* Disable logging to console */
17635 +       case 7:         /* Enable logging to console */
17636 +       case 8:         /* Set level of messages printed to console */
17637 +               break;
17638 +
17639 +       case 9:         /* Number of chars in the log buffer */
17640 +               return 0;
17641 +       case 10:        /* Size of the log buffer */
17642 +               return 0;
17643 +       default:
17644 +               error = -EINVAL;
17645 +               break;
17646 +       }
17647 +       return error;
17648 +}
17649 +
17650 +
17651 +/* virtual host info names */
17652 +
17653 +static char *vx_vhi_name(struct vx_info *vxi, int id)
17654 +{
17655 +       struct nsproxy *nsproxy;
17656 +       struct uts_namespace *uts;
17657 +
17658 +       if (id == VHIN_CONTEXT)
17659 +               return vxi->vx_name;
17660 +
17661 +       nsproxy = vxi->space[0].vx_nsproxy;
17662 +       if (!nsproxy)
17663 +               return NULL;
17664 +
17665 +       uts = nsproxy->uts_ns;
17666 +       if (!uts)
17667 +               return NULL;
17668 +
17669 +       switch (id) {
17670 +       case VHIN_SYSNAME:
17671 +               return uts->name.sysname;
17672 +       case VHIN_NODENAME:
17673 +               return uts->name.nodename;
17674 +       case VHIN_RELEASE:
17675 +               return uts->name.release;
17676 +       case VHIN_VERSION:
17677 +               return uts->name.version;
17678 +       case VHIN_MACHINE:
17679 +               return uts->name.machine;
17680 +       case VHIN_DOMAINNAME:
17681 +               return uts->name.domainname;
17682 +       default:
17683 +               return NULL;
17684 +       }
17685 +       return NULL;
17686 +}
17687 +
17688 +int vc_set_vhi_name(struct vx_info *vxi, void __user *data)
17689 +{
17690 +       struct vcmd_vhi_name_v0 vc_data;
17691 +       char *name;
17692 +
17693 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17694 +               return -EFAULT;
17695 +
17696 +       name = vx_vhi_name(vxi, vc_data.field);
17697 +       if (!name)
17698 +               return -EINVAL;
17699 +
17700 +       memcpy(name, vc_data.name, 65);
17701 +       return 0;
17702 +}
17703 +
17704 +int vc_get_vhi_name(struct vx_info *vxi, void __user *data)
17705 +{
17706 +       struct vcmd_vhi_name_v0 vc_data;
17707 +       char *name;
17708 +
17709 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17710 +               return -EFAULT;
17711 +
17712 +       name = vx_vhi_name(vxi, vc_data.field);
17713 +       if (!name)
17714 +               return -EINVAL;
17715 +
17716 +       memcpy(vc_data.name, name, 65);
17717 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
17718 +               return -EFAULT;
17719 +       return 0;
17720 +}
17721 +
17722 +
17723 +int vc_virt_stat(struct vx_info *vxi, void __user *data)
17724 +{
17725 +       struct vcmd_virt_stat_v0 vc_data;
17726 +       struct _vx_cvirt *cvirt = &vxi->cvirt;
17727 +       struct timespec uptime;
17728 +
17729 +       do_posix_clock_monotonic_gettime(&uptime);
17730 +       set_normalized_timespec(&uptime,
17731 +               uptime.tv_sec - cvirt->bias_uptime.tv_sec,
17732 +               uptime.tv_nsec - cvirt->bias_uptime.tv_nsec);
17733 +
17734 +       vc_data.offset = timespec_to_ns(&cvirt->bias_ts);
17735 +       vc_data.uptime = timespec_to_ns(&uptime);
17736 +       vc_data.nr_threads = atomic_read(&cvirt->nr_threads);
17737 +       vc_data.nr_running = atomic_read(&cvirt->nr_running);
17738 +       vc_data.nr_uninterruptible = atomic_read(&cvirt->nr_uninterruptible);
17739 +       vc_data.nr_onhold = atomic_read(&cvirt->nr_onhold);
17740 +       vc_data.nr_forks = atomic_read(&cvirt->total_forks);
17741 +       vc_data.load[0] = cvirt->load[0];
17742 +       vc_data.load[1] = cvirt->load[1];
17743 +       vc_data.load[2] = cvirt->load[2];
17744 +
17745 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
17746 +               return -EFAULT;
17747 +       return 0;
17748 +}
17749 +
17750 +
17751 +#ifdef CONFIG_VSERVER_VTIME
17752 +
17753 +/* virtualized time base */
17754 +
17755 +void vx_adjust_timespec(struct timespec *ts)
17756 +{
17757 +       struct vx_info *vxi;
17758 +
17759 +       if (!vx_flags(VXF_VIRT_TIME, 0))
17760 +               return;
17761 +
17762 +       vxi = current_vx_info();
17763 +       ts->tv_sec += vxi->cvirt.bias_ts.tv_sec;
17764 +       ts->tv_nsec += vxi->cvirt.bias_ts.tv_nsec;
17765 +
17766 +       if (ts->tv_nsec >= NSEC_PER_SEC) {
17767 +               ts->tv_sec++;
17768 +               ts->tv_nsec -= NSEC_PER_SEC;
17769 +       } else if (ts->tv_nsec < 0) {
17770 +               ts->tv_sec--;
17771 +               ts->tv_nsec += NSEC_PER_SEC;
17772 +       }
17773 +}
17774 +
17775 +int vx_settimeofday(struct timespec *ts)
17776 +{
17777 +       struct timespec ats, delta;
17778 +       struct vx_info *vxi;
17779 +
17780 +       if (!vx_flags(VXF_VIRT_TIME, 0))
17781 +               return do_settimeofday(ts);
17782 +
17783 +       getnstimeofday(&ats);
17784 +       delta = timespec_sub(*ts, ats);
17785 +
17786 +       vxi = current_vx_info();
17787 +       vxi->cvirt.bias_ts = timespec_add(vxi->cvirt.bias_ts, delta);
17788 +       return 0;
17789 +}
17790 +
17791 +#endif
17792 +
17793 diff -NurpP --minimal linux-2.6.38.1/kernel/vserver/cvirt_init.h linux-2.6.38.1-vs2.3.0.37-rc9/kernel/vserver/cvirt_init.h
17794 --- linux-2.6.38.1/kernel/vserver/cvirt_init.h  1970-01-01 01:00:00.000000000 +0100
17795 +++ linux-2.6.38.1-vs2.3.0.37-rc9/kernel/vserver/cvirt_init.h   2011-03-21 07:21:38.000000000 +0100
17796 @@ -0,0 +1,70 @@
17797 +
17798 +
17799 +extern uint64_t vx_idle_jiffies(void);
17800 +
17801 +static inline void vx_info_init_cvirt(struct _vx_cvirt *cvirt)
17802 +{
17803 +       uint64_t idle_jiffies = vx_idle_jiffies();
17804 +       uint64_t nsuptime;
17805 +
17806 +       do_posix_clock_monotonic_gettime(&cvirt->bias_uptime);
17807 +       nsuptime = (unsigned long long)cvirt->bias_uptime.tv_sec
17808 +               * NSEC_PER_SEC + cvirt->bias_uptime.tv_nsec;
17809 +       cvirt->bias_clock = nsec_to_clock_t(nsuptime);
17810 +       cvirt->bias_ts.tv_sec = 0;
17811 +       cvirt->bias_ts.tv_nsec = 0;
17812 +
17813 +       jiffies_to_timespec(idle_jiffies, &cvirt->bias_idle);
17814 +       atomic_set(&cvirt->nr_threads, 0);
17815 +       atomic_set(&cvirt->nr_running, 0);
17816 +       atomic_set(&cvirt->nr_uninterruptible, 0);
17817 +       atomic_set(&cvirt->nr_onhold, 0);
17818 +
17819 +       spin_lock_init(&cvirt->load_lock);
17820 +       cvirt->load_last = jiffies;
17821 +       atomic_set(&cvirt->load_updates, 0);
17822 +       cvirt->load[0] = 0;
17823 +       cvirt->load[1] = 0;
17824 +       cvirt->load[2] = 0;
17825 +       atomic_set(&cvirt->total_forks, 0);
17826 +
17827 +       spin_lock_init(&cvirt->syslog.logbuf_lock);
17828 +       init_waitqueue_head(&cvirt->syslog.log_wait);
17829 +       cvirt->syslog.log_start = 0;
17830 +       cvirt->syslog.log_end = 0;
17831 +       cvirt->syslog.con_start = 0;
17832 +       cvirt->syslog.logged_chars = 0;
17833 +}
17834 +
17835 +static inline
17836 +void vx_info_init_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc, int cpu)
17837 +{
17838 +       // cvirt_pc->cpustat = { 0 };
17839 +}
17840 +
17841 +static inline void vx_info_exit_cvirt(struct _vx_cvirt *cvirt)
17842 +{
17843 +#ifdef CONFIG_VSERVER_WARN
17844 +       int value;
17845 +#endif
17846 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_threads)),
17847 +               "!!! cvirt: %p[nr_threads] = %d on exit.",
17848 +               cvirt, value);
17849 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_running)),
17850 +               "!!! cvirt: %p[nr_running] = %d on exit.",
17851 +               cvirt, value);
17852 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_uninterruptible)),
17853 +               "!!! cvirt: %p[nr_uninterruptible] = %d on exit.",
17854 +               cvirt, value);
17855 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_onhold)),
17856 +               "!!! cvirt: %p[nr_onhold] = %d on exit.",
17857 +               cvirt, value);
17858 +       return;
17859 +}
17860 +
17861 +static inline
17862 +void vx_info_exit_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc, int cpu)
17863 +{
17864 +       return;
17865 +}
17866 +
17867 diff -NurpP --minimal linux-2.6.38.1/kernel/vserver/cvirt_proc.h linux-2.6.38.1-vs2.3.0.37-rc9/kernel/vserver/cvirt_proc.h
17868 --- linux-2.6.38.1/kernel/vserver/cvirt_proc.h  1970-01-01 01:00:00.000000000 +0100
17869 +++ linux-2.6.38.1-vs2.3.0.37-rc9/kernel/vserver/cvirt_proc.h   2011-01-29 02:01:07.000000000 +0100
17870 @@ -0,0 +1,135 @@
17871 +#ifndef _VX_CVIRT_PROC_H
17872 +#define _VX_CVIRT_PROC_H
17873 +
17874 +#include <linux/nsproxy.h>
17875 +#include <linux/mnt_namespace.h>
17876 +#include <linux/ipc_namespace.h>
17877 +#include <linux/utsname.h>
17878 +#include <linux/ipc.h>
17879 +
17880 +
17881 +static inline
17882 +int vx_info_proc_nsproxy(struct nsproxy *nsproxy, char *buffer)
17883 +{
17884 +       struct mnt_namespace *ns;
17885 +       struct uts_namespace *uts;
17886 +       struct ipc_namespace *ipc;
17887 +       struct path path;
17888 +       char *pstr, *root;
17889 +       int length = 0;
17890 +
17891 +       if (!nsproxy)
17892 +               goto out;
17893 +
17894 +       length += sprintf(buffer + length,
17895 +               "NSProxy:\t%p [%p,%p,%p]\n",
17896 +               nsproxy, nsproxy->mnt_ns,
17897 +               nsproxy->uts_ns, nsproxy->ipc_ns);
17898 +
17899 +       ns = nsproxy->mnt_ns;
17900 +       if (!ns)
17901 +               goto skip_ns;
17902 +
17903 +       pstr = kmalloc(PATH_MAX, GFP_KERNEL);
17904 +       if (!pstr)
17905 +               goto skip_ns;
17906 +
17907 +       path.mnt = ns->root;
17908 +       path.dentry = ns->root->mnt_root;
17909 +       root = d_path(&path, pstr, PATH_MAX - 2);
17910 +       length += sprintf(buffer + length,
17911 +               "Namespace:\t%p [#%u]\n"
17912 +               "RootPath:\t%s\n",
17913 +               ns, atomic_read(&ns->count),
17914 +               root);
17915 +       kfree(pstr);
17916 +skip_ns:
17917 +
17918 +       uts = nsproxy->uts_ns;
17919 +       if (!uts)
17920 +               goto skip_uts;
17921 +
17922 +       length += sprintf(buffer + length,
17923 +               "SysName:\t%.*s\n"
17924 +               "NodeName:\t%.*s\n"
17925 +               "Release:\t%.*s\n"
17926 +               "Version:\t%.*s\n"
17927 +               "Machine:\t%.*s\n"
17928 +               "DomainName:\t%.*s\n",
17929 +               __NEW_UTS_LEN, uts->name.sysname,
17930 +               __NEW_UTS_LEN, uts->name.nodename,
17931 +               __NEW_UTS_LEN, uts->name.release,
17932 +               __NEW_UTS_LEN, uts->name.version,
17933 +               __NEW_UTS_LEN, uts->name.machine,
17934 +               __NEW_UTS_LEN, uts->name.domainname);
17935 +skip_uts:
17936 +
17937 +       ipc = nsproxy->ipc_ns;
17938 +       if (!ipc)
17939 +               goto skip_ipc;
17940 +
17941 +       length += sprintf(buffer + length,
17942 +               "SEMS:\t\t%d %d %d %d  %d\n"
17943 +               "MSG:\t\t%d %d %d\n"
17944 +               "SHM:\t\t%lu %lu  %d %d\n",
17945 +               ipc->sem_ctls[0], ipc->sem_ctls[1],
17946 +               ipc->sem_ctls[2], ipc->sem_ctls[3],
17947 +               ipc->used_sems,
17948 +               ipc->msg_ctlmax, ipc->msg_ctlmnb, ipc->msg_ctlmni,
17949 +               (unsigned long)ipc->shm_ctlmax,
17950 +               (unsigned long)ipc->shm_ctlall,
17951 +               ipc->shm_ctlmni, ipc->shm_tot);
17952 +skip_ipc:
17953 +out:
17954 +       return length;
17955 +}
17956 +
17957 +
17958 +#include <linux/sched.h>
17959 +
17960 +#define LOAD_INT(x) ((x) >> FSHIFT)
17961 +#define LOAD_FRAC(x) LOAD_INT(((x) & (FIXED_1 - 1)) * 100)
17962 +
17963 +static inline
17964 +int vx_info_proc_cvirt(struct _vx_cvirt *cvirt, char *buffer)
17965 +{
17966 +       int length = 0;
17967 +       int a, b, c;
17968 +
17969 +       length += sprintf(buffer + length,
17970 +               "BiasUptime:\t%lu.%02lu\n",
17971 +               (unsigned long)cvirt->bias_uptime.tv_sec,
17972 +               (cvirt->bias_uptime.tv_nsec / (NSEC_PER_SEC / 100)));
17973 +
17974 +       a = cvirt->load[0] + (FIXED_1 / 200);
17975 +       b = cvirt->load[1] + (FIXED_1 / 200);
17976 +       c = cvirt->load[2] + (FIXED_1 / 200);
17977 +       length += sprintf(buffer + length,
17978 +               "nr_threads:\t%d\n"
17979 +               "nr_running:\t%d\n"
17980 +               "nr_unintr:\t%d\n"
17981 +               "nr_onhold:\t%d\n"
17982 +               "load_updates:\t%d\n"
17983 +               "loadavg:\t%d.%02d %d.%02d %d.%02d\n"
17984 +               "total_forks:\t%d\n",
17985 +               atomic_read(&cvirt->nr_threads),
17986 +               atomic_read(&cvirt->nr_running),
17987 +               atomic_read(&cvirt->nr_uninterruptible),
17988 +               atomic_read(&cvirt->nr_onhold),
17989 +               atomic_read(&cvirt->load_updates),
17990 +               LOAD_INT(a), LOAD_FRAC(a),
17991 +               LOAD_INT(b), LOAD_FRAC(b),
17992 +               LOAD_INT(c), LOAD_FRAC(c),
17993 +               atomic_read(&cvirt->total_forks));
17994 +       return length;
17995 +}
17996 +
17997 +static inline
17998 +int vx_info_proc_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc,
17999 +       char *buffer, int cpu)
18000 +{
18001 +       int length = 0;
18002 +       return length;
18003 +}
18004 +
18005 +#endif /* _VX_CVIRT_PROC_H */
18006 diff -NurpP --minimal linux-2.6.38.1/kernel/vserver/debug.c linux-2.6.38.1-vs2.3.0.37-rc9/kernel/vserver/debug.c
18007 --- linux-2.6.38.1/kernel/vserver/debug.c       1970-01-01 01:00:00.000000000 +0100
18008 +++ linux-2.6.38.1-vs2.3.0.37-rc9/kernel/vserver/debug.c        2011-01-29 02:01:07.000000000 +0100
18009 @@ -0,0 +1,32 @@
18010 +/*
18011 + *  kernel/vserver/debug.c
18012 + *
18013 + *  Copyright (C) 2005-2007 Herbert Pötzl
18014 + *
18015 + *  V0.01  vx_info dump support
18016 + *
18017 + */
18018 +
18019 +#include <linux/module.h>
18020 +
18021 +#include <linux/vserver/context.h>
18022 +
18023 +
18024 +void   dump_vx_info(struct vx_info *vxi, int level)
18025 +{
18026 +       printk("vx_info %p[#%d, %d.%d, %4x]\n", vxi, vxi->vx_id,
18027 +               atomic_read(&vxi->vx_usecnt),
18028 +               atomic_read(&vxi->vx_tasks),
18029 +               vxi->vx_state);
18030 +       if (level > 0) {
18031 +               __dump_vx_limit(&vxi->limit);
18032 +               __dump_vx_sched(&vxi->sched);
18033 +               __dump_vx_cvirt(&vxi->cvirt);
18034 +               __dump_vx_cacct(&vxi->cacct);
18035 +       }
18036 +       printk("---\n");
18037 +}
18038 +
18039 +
18040 +EXPORT_SYMBOL_GPL(dump_vx_info);
18041 +
18042 diff -NurpP --minimal linux-2.6.38.1/kernel/vserver/device.c linux-2.6.38.1-vs2.3.0.37-rc9/kernel/vserver/device.c
18043 --- linux-2.6.38.1/kernel/vserver/device.c      1970-01-01 01:00:00.000000000 +0100
18044 +++ linux-2.6.38.1-vs2.3.0.37-rc9/kernel/vserver/device.c       2011-01-29 02:01:07.000000000 +0100
18045 @@ -0,0 +1,443 @@
18046 +/*
18047 + *  linux/kernel/vserver/device.c
18048 + *
18049 + *  Linux-VServer: Device Support
18050 + *
18051 + *  Copyright (C) 2006  Herbert Pötzl
18052 + *  Copyright (C) 2007  Daniel Hokka Zakrisson
18053 + *
18054 + *  V0.01  device mapping basics
18055 + *  V0.02  added defaults
18056 + *
18057 + */
18058 +
18059 +#include <linux/slab.h>
18060 +#include <linux/rcupdate.h>
18061 +#include <linux/fs.h>
18062 +#include <linux/namei.h>
18063 +#include <linux/hash.h>
18064 +
18065 +#include <asm/errno.h>
18066 +#include <asm/uaccess.h>
18067 +#include <linux/vserver/base.h>
18068 +#include <linux/vserver/debug.h>
18069 +#include <linux/vserver/context.h>
18070 +#include <linux/vserver/device.h>
18071 +#include <linux/vserver/device_cmd.h>
18072 +
18073 +
18074 +#define DMAP_HASH_BITS 4
18075 +
18076 +
18077 +struct vs_mapping {
18078 +       union {
18079 +               struct hlist_node hlist;
18080 +               struct list_head list;
18081 +       } u;
18082 +#define dm_hlist       u.hlist
18083 +#define dm_list                u.list
18084 +       xid_t xid;
18085 +       dev_t device;
18086 +       struct vx_dmap_target target;
18087 +};
18088 +
18089 +
18090 +static struct hlist_head dmap_main_hash[1 << DMAP_HASH_BITS];
18091 +
18092 +static spinlock_t dmap_main_hash_lock = SPIN_LOCK_UNLOCKED;
18093 +
18094 +static struct vx_dmap_target dmap_defaults[2] = {
18095 +       { .flags = DATTR_OPEN },
18096 +       { .flags = DATTR_OPEN },
18097 +};
18098 +
18099 +
18100 +struct kmem_cache *dmap_cachep __read_mostly;
18101 +
18102 +int __init dmap_cache_init(void)
18103 +{
18104 +       dmap_cachep = kmem_cache_create("dmap_cache",
18105 +               sizeof(struct vs_mapping), 0,
18106 +               SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
18107 +       return 0;
18108 +}
18109 +
18110 +__initcall(dmap_cache_init);
18111 +
18112 +
18113 +static inline unsigned int __hashval(dev_t dev, int bits)
18114 +{
18115 +       return hash_long((unsigned long)dev, bits);
18116 +}
18117 +
18118 +
18119 +/*     __hash_mapping()
18120 + *     add the mapping to the hash table
18121 + */
18122 +static inline void __hash_mapping(struct vx_info *vxi, struct vs_mapping *vdm)
18123 +{
18124 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
18125 +       struct hlist_head *head, *hash = dmap_main_hash;
18126 +       int device = vdm->device;
18127 +
18128 +       spin_lock(hash_lock);
18129 +       vxdprintk(VXD_CBIT(misc, 8), "__hash_mapping: %p[#%d] %08x:%08x",
18130 +               vxi, vxi ? vxi->vx_id : 0, device, vdm->target.target);
18131 +
18132 +       head = &hash[__hashval(device, DMAP_HASH_BITS)];
18133 +       hlist_add_head(&vdm->dm_hlist, head);
18134 +       spin_unlock(hash_lock);
18135 +}
18136 +
18137 +
18138 +static inline int __mode_to_default(umode_t mode)
18139 +{
18140 +       switch (mode) {
18141 +       case S_IFBLK:
18142 +               return 0;
18143 +       case S_IFCHR:
18144 +               return 1;
18145 +       default:
18146 +               BUG();
18147 +       }
18148 +}
18149 +
18150 +
18151 +/*     __set_default()
18152 + *     set a default
18153 + */
18154 +static inline void __set_default(struct vx_info *vxi, umode_t mode,
18155 +       struct vx_dmap_target *vdmt)
18156 +{
18157 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
18158 +       spin_lock(hash_lock);
18159 +
18160 +       if (vxi)
18161 +               vxi->dmap.targets[__mode_to_default(mode)] = *vdmt;
18162 +       else
18163 +               dmap_defaults[__mode_to_default(mode)] = *vdmt;
18164 +
18165 +
18166 +       spin_unlock(hash_lock);
18167 +
18168 +       vxdprintk(VXD_CBIT(misc, 8), "__set_default: %p[#%u] %08x %04x",
18169 +                 vxi, vxi ? vxi->vx_id : 0, vdmt->target, vdmt->flags);
18170 +}
18171 +
18172 +
18173 +/*     __remove_default()
18174 + *     remove a default
18175 + */
18176 +static inline int __remove_default(struct vx_info *vxi, umode_t mode)
18177 +{
18178 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
18179 +       spin_lock(hash_lock);
18180 +
18181 +       if (vxi)
18182 +               vxi->dmap.targets[__mode_to_default(mode)].flags = 0;
18183 +       else    /* remove == reset */
18184 +               dmap_defaults[__mode_to_default(mode)].flags = DATTR_OPEN | mode;
18185 +
18186 +       spin_unlock(hash_lock);
18187 +       return 0;
18188 +}
18189 +
18190 +
18191 +/*     __find_mapping()
18192 + *     find a mapping in the hash table
18193 + *
18194 + *     caller must hold hash_lock
18195 + */
18196 +static inline int __find_mapping(xid_t xid, dev_t device, umode_t mode,
18197 +       struct vs_mapping **local, struct vs_mapping **global)
18198 +{
18199 +       struct hlist_head *hash = dmap_main_hash;
18200 +       struct hlist_head *head = &hash[__hashval(device, DMAP_HASH_BITS)];
18201 +       struct hlist_node *pos;
18202 +       struct vs_mapping *vdm;
18203 +
18204 +       *local = NULL;
18205 +       if (global)
18206 +               *global = NULL;
18207 +
18208 +       hlist_for_each(pos, head) {
18209 +               vdm = hlist_entry(pos, struct vs_mapping, dm_hlist);
18210 +
18211 +               if ((vdm->device == device) &&
18212 +                       !((vdm->target.flags ^ mode) & S_IFMT)) {
18213 +                       if (vdm->xid == xid) {
18214 +                               *local = vdm;
18215 +                               return 1;
18216 +                       } else if (global && vdm->xid == 0)
18217 +                               *global = vdm;
18218 +               }
18219 +       }
18220 +
18221 +       if (global && *global)
18222 +               return 0;
18223 +       else
18224 +               return -ENOENT;
18225 +}
18226 +
18227 +
18228 +/*     __lookup_mapping()
18229 + *     find a mapping and store the result in target and flags
18230 + */
18231 +static inline int __lookup_mapping(struct vx_info *vxi,
18232 +       dev_t device, dev_t *target, int *flags, umode_t mode)
18233 +{
18234 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
18235 +       struct vs_mapping *vdm, *global;
18236 +       struct vx_dmap_target *vdmt;
18237 +       int ret = 0;
18238 +       xid_t xid = vxi->vx_id;
18239 +       int index;
18240 +
18241 +       spin_lock(hash_lock);
18242 +       if (__find_mapping(xid, device, mode, &vdm, &global) > 0) {
18243 +               ret = 1;
18244 +               vdmt = &vdm->target;
18245 +               goto found;
18246 +       }
18247 +
18248 +       index = __mode_to_default(mode);
18249 +       if (vxi && vxi->dmap.targets[index].flags) {
18250 +               ret = 2;
18251 +               vdmt = &vxi->dmap.targets[index];
18252 +       } else if (global) {
18253 +               ret = 3;
18254 +               vdmt = &global->target;
18255 +               goto found;
18256 +       } else {
18257 +               ret = 4;
18258 +               vdmt = &dmap_defaults[index];
18259 +       }
18260 +
18261 +found:
18262 +       if (target && (vdmt->flags & DATTR_REMAP))
18263 +               *target = vdmt->target;
18264 +       else if (target)
18265 +               *target = device;
18266 +       if (flags)
18267 +               *flags = vdmt->flags;
18268 +
18269 +       spin_unlock(hash_lock);
18270 +
18271 +       return ret;
18272 +}
18273 +
18274 +
18275 +/*     __remove_mapping()
18276 + *     remove a mapping from the hash table
18277 + */
18278 +static inline int __remove_mapping(struct vx_info *vxi, dev_t device,
18279 +       umode_t mode)
18280 +{
18281 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
18282 +       struct vs_mapping *vdm = NULL;
18283 +       int ret = 0;
18284 +
18285 +       spin_lock(hash_lock);
18286 +
18287 +       ret = __find_mapping((vxi ? vxi->vx_id : 0), device, mode, &vdm,
18288 +               NULL);
18289 +       vxdprintk(VXD_CBIT(misc, 8), "__remove_mapping: %p[#%d] %08x %04x",
18290 +               vxi, vxi ? vxi->vx_id : 0, device, mode);
18291 +       if (ret < 0)
18292 +               goto out;
18293 +       hlist_del(&vdm->dm_hlist);
18294 +
18295 +out:
18296 +       spin_unlock(hash_lock);
18297 +       if (vdm)
18298 +               kmem_cache_free(dmap_cachep, vdm);
18299 +       return ret;
18300 +}
18301 +
18302 +
18303 +
18304 +int vs_map_device(struct vx_info *vxi,
18305 +       dev_t device, dev_t *target, umode_t mode)
18306 +{
18307 +       int ret, flags = DATTR_MASK;
18308 +
18309 +       if (!vxi) {
18310 +               if (target)
18311 +                       *target = device;
18312 +               goto out;
18313 +       }
18314 +       ret = __lookup_mapping(vxi, device, target, &flags, mode);
18315 +       vxdprintk(VXD_CBIT(misc, 8), "vs_map_device: %08x target: %08x flags: %04x mode: %04x mapped=%d",
18316 +               device, target ? *target : 0, flags, mode, ret);
18317 +out:
18318 +       return (flags & DATTR_MASK);
18319 +}
18320 +
18321 +
18322 +
18323 +static int do_set_mapping(struct vx_info *vxi,
18324 +       dev_t device, dev_t target, int flags, umode_t mode)
18325 +{
18326 +       if (device) {
18327 +               struct vs_mapping *new;
18328 +
18329 +               new = kmem_cache_alloc(dmap_cachep, GFP_KERNEL);
18330 +               if (!new)
18331 +                       return -ENOMEM;
18332 +
18333 +               INIT_HLIST_NODE(&new->dm_hlist);
18334 +               new->device = device;
18335 +               new->target.target = target;
18336 +               new->target.flags = flags | mode;
18337 +               new->xid = (vxi ? vxi->vx_id : 0);
18338 +
18339 +               vxdprintk(VXD_CBIT(misc, 8), "do_set_mapping: %08x target: %08x flags: %04x", device, target, flags);
18340 +               __hash_mapping(vxi, new);
18341 +       } else {
18342 +               struct vx_dmap_target new = {
18343 +                       .target = target,
18344 +                       .flags = flags | mode,
18345 +               };
18346 +               __set_default(vxi, mode, &new);
18347 +       }
18348 +       return 0;
18349 +}
18350 +
18351 +
18352 +static int do_unset_mapping(struct vx_info *vxi,
18353 +       dev_t device, dev_t target, int flags, umode_t mode)
18354 +{
18355 +       int ret = -EINVAL;
18356 +
18357 +       if (device) {
18358 +               ret = __remove_mapping(vxi, device, mode);
18359 +               if (ret < 0)
18360 +                       goto out;
18361 +       } else {
18362 +               ret = __remove_default(vxi, mode);
18363 +               if (ret < 0)
18364 +                       goto out;
18365 +       }
18366 +
18367 +out:
18368 +       return ret;
18369 +}
18370 +
18371 +
18372 +static inline int __user_device(const char __user *name, dev_t *dev,
18373 +       umode_t *mode)
18374 +{
18375 +       struct nameidata nd;
18376 +       int ret;
18377 +
18378 +       if (!name) {
18379 +               *dev = 0;
18380 +               return 0;
18381 +       }
18382 +       ret = user_lpath(name, &nd.path);
18383 +       if (ret)
18384 +               return ret;
18385 +       if (nd.path.dentry->d_inode) {
18386 +               *dev = nd.path.dentry->d_inode->i_rdev;
18387 +               *mode = nd.path.dentry->d_inode->i_mode;
18388 +       }
18389 +       path_put(&nd.path);
18390 +       return 0;
18391 +}
18392 +
18393 +static inline int __mapping_mode(dev_t device, dev_t target,
18394 +       umode_t device_mode, umode_t target_mode, umode_t *mode)
18395 +{
18396 +       if (device)
18397 +               *mode = device_mode & S_IFMT;
18398 +       else if (target)
18399 +               *mode = target_mode & S_IFMT;
18400 +       else
18401 +               return -EINVAL;
18402 +
18403 +       /* if both given, device and target mode have to match */
18404 +       if (device && target &&
18405 +               ((device_mode ^ target_mode) & S_IFMT))
18406 +               return -EINVAL;
18407 +       return 0;
18408 +}
18409 +
18410 +
18411 +static inline int do_mapping(struct vx_info *vxi, const char __user *device_path,
18412 +       const char __user *target_path, int flags, int set)
18413 +{
18414 +       dev_t device = ~0, target = ~0;
18415 +       umode_t device_mode = 0, target_mode = 0, mode;
18416 +       int ret;
18417 +
18418 +       ret = __user_device(device_path, &device, &device_mode);
18419 +       if (ret)
18420 +               return ret;
18421 +       ret = __user_device(target_path, &target, &target_mode);
18422 +       if (ret)
18423 +               return ret;
18424 +
18425 +       ret = __mapping_mode(device, target,
18426 +               device_mode, target_mode, &mode);
18427 +       if (ret)
18428 +               return ret;
18429 +
18430 +       if (set)
18431 +               return do_set_mapping(vxi, device, target,
18432 +                       flags, mode);
18433 +       else
18434 +               return do_unset_mapping(vxi, device, target,
18435 +                       flags, mode);
18436 +}
18437 +
18438 +
18439 +int vc_set_mapping(struct vx_info *vxi, void __user *data)
18440 +{
18441 +       struct vcmd_set_mapping_v0 vc_data;
18442 +
18443 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18444 +               return -EFAULT;
18445 +
18446 +       return do_mapping(vxi, vc_data.device, vc_data.target,
18447 +               vc_data.flags, 1);
18448 +}
18449 +
18450 +int vc_unset_mapping(struct vx_info *vxi, void __user *data)
18451 +{
18452 +       struct vcmd_set_mapping_v0 vc_data;
18453 +
18454 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18455 +               return -EFAULT;
18456 +
18457 +       return do_mapping(vxi, vc_data.device, vc_data.target,
18458 +               vc_data.flags, 0);
18459 +}
18460 +
18461 +
18462 +#ifdef CONFIG_COMPAT
18463 +
18464 +int vc_set_mapping_x32(struct vx_info *vxi, void __user *data)
18465 +{
18466 +       struct vcmd_set_mapping_v0_x32 vc_data;
18467 +
18468 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18469 +               return -EFAULT;
18470 +
18471 +       return do_mapping(vxi, compat_ptr(vc_data.device_ptr),
18472 +               compat_ptr(vc_data.target_ptr), vc_data.flags, 1);
18473 +}
18474 +
18475 +int vc_unset_mapping_x32(struct vx_info *vxi, void __user *data)
18476 +{
18477 +       struct vcmd_set_mapping_v0_x32 vc_data;
18478 +
18479 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18480 +               return -EFAULT;
18481 +
18482 +       return do_mapping(vxi, compat_ptr(vc_data.device_ptr),
18483 +               compat_ptr(vc_data.target_ptr), vc_data.flags, 0);
18484 +}
18485 +
18486 +#endif /* CONFIG_COMPAT */
18487 +
18488 +
18489 diff -NurpP --minimal linux-2.6.38.1/kernel/vserver/dlimit.c linux-2.6.38.1-vs2.3.0.37-rc9/kernel/vserver/dlimit.c
18490 --- linux-2.6.38.1/kernel/vserver/dlimit.c      1970-01-01 01:00:00.000000000 +0100
18491 +++ linux-2.6.38.1-vs2.3.0.37-rc9/kernel/vserver/dlimit.c       2011-01-29 02:01:07.000000000 +0100
18492 @@ -0,0 +1,531 @@
18493 +/*
18494 + *  linux/kernel/vserver/dlimit.c
18495 + *
18496 + *  Virtual Server: Context Disk Limits
18497 + *
18498 + *  Copyright (C) 2004-2009  Herbert Pötzl
18499 + *
18500 + *  V0.01  initial version
18501 + *  V0.02  compat32 splitup
18502 + *  V0.03  extended interface
18503 + *
18504 + */
18505 +
18506 +#include <linux/statfs.h>
18507 +#include <linux/sched.h>
18508 +#include <linux/namei.h>
18509 +#include <linux/vs_tag.h>
18510 +#include <linux/vs_dlimit.h>
18511 +#include <linux/vserver/dlimit_cmd.h>
18512 +#include <linux/slab.h>
18513 +// #include <linux/gfp.h>
18514 +
18515 +#include <asm/uaccess.h>
18516 +
18517 +/*     __alloc_dl_info()
18518 +
18519 +       * allocate an initialized dl_info struct
18520 +       * doesn't make it visible (hash)                        */
18521 +
18522 +static struct dl_info *__alloc_dl_info(struct super_block *sb, tag_t tag)
18523 +{
18524 +       struct dl_info *new = NULL;
18525 +
18526 +       vxdprintk(VXD_CBIT(dlim, 5),
18527 +               "alloc_dl_info(%p,%d)*", sb, tag);
18528 +
18529 +       /* would this benefit from a slab cache? */
18530 +       new = kmalloc(sizeof(struct dl_info), GFP_KERNEL);
18531 +       if (!new)
18532 +               return 0;
18533 +
18534 +       memset(new, 0, sizeof(struct dl_info));
18535 +       new->dl_tag = tag;
18536 +       new->dl_sb = sb;
18537 +       // INIT_RCU_HEAD(&new->dl_rcu);
18538 +       INIT_HLIST_NODE(&new->dl_hlist);
18539 +       spin_lock_init(&new->dl_lock);
18540 +       atomic_set(&new->dl_refcnt, 0);
18541 +       atomic_set(&new->dl_usecnt, 0);
18542 +
18543 +       /* rest of init goes here */
18544 +
18545 +       vxdprintk(VXD_CBIT(dlim, 4),
18546 +               "alloc_dl_info(%p,%d) = %p", sb, tag, new);
18547 +       return new;
18548 +}
18549 +
18550 +/*     __dealloc_dl_info()
18551 +
18552 +       * final disposal of dl_info                             */
18553 +
18554 +static void __dealloc_dl_info(struct dl_info *dli)
18555 +{
18556 +       vxdprintk(VXD_CBIT(dlim, 4),
18557 +               "dealloc_dl_info(%p)", dli);
18558 +
18559 +       dli->dl_hlist.next = LIST_POISON1;
18560 +       dli->dl_tag = -1;
18561 +       dli->dl_sb = 0;
18562 +
18563 +       BUG_ON(atomic_read(&dli->dl_usecnt));
18564 +       BUG_ON(atomic_read(&dli->dl_refcnt));
18565 +
18566 +       kfree(dli);
18567 +}
18568 +
18569 +
18570 +/*     hash table for dl_info hash */
18571 +
18572 +#define DL_HASH_SIZE   13
18573 +
18574 +struct hlist_head dl_info_hash[DL_HASH_SIZE];
18575 +
18576 +static spinlock_t dl_info_hash_lock = SPIN_LOCK_UNLOCKED;
18577 +
18578 +
18579 +static inline unsigned int __hashval(struct super_block *sb, tag_t tag)
18580 +{
18581 +       return ((tag ^ (unsigned long)sb) % DL_HASH_SIZE);
18582 +}
18583 +
18584 +
18585 +
18586 +/*     __hash_dl_info()
18587 +
18588 +       * add the dli to the global hash table
18589 +       * requires the hash_lock to be held                     */
18590 +
18591 +static inline void __hash_dl_info(struct dl_info *dli)
18592 +{
18593 +       struct hlist_head *head;
18594 +
18595 +       vxdprintk(VXD_CBIT(dlim, 6),
18596 +               "__hash_dl_info: %p[#%d]", dli, dli->dl_tag);
18597 +       get_dl_info(dli);
18598 +       head = &dl_info_hash[__hashval(dli->dl_sb, dli->dl_tag)];
18599 +       hlist_add_head_rcu(&dli->dl_hlist, head);
18600 +}
18601 +
18602 +/*     __unhash_dl_info()
18603 +
18604 +       * remove the dli from the global hash table
18605 +       * requires the hash_lock to be held                     */
18606 +
18607 +static inline void __unhash_dl_info(struct dl_info *dli)
18608 +{
18609 +       vxdprintk(VXD_CBIT(dlim, 6),
18610 +               "__unhash_dl_info: %p[#%d]", dli, dli->dl_tag);
18611 +       hlist_del_rcu(&dli->dl_hlist);
18612 +       put_dl_info(dli);
18613 +}
18614 +
18615 +
18616 +/*     __lookup_dl_info()
18617 +
18618 +       * requires the rcu_read_lock()
18619 +       * doesn't increment the dl_refcnt                       */
18620 +
18621 +static inline struct dl_info *__lookup_dl_info(struct super_block *sb, tag_t tag)
18622 +{
18623 +       struct hlist_head *head = &dl_info_hash[__hashval(sb, tag)];
18624 +       struct hlist_node *pos;
18625 +       struct dl_info *dli;
18626 +
18627 +       hlist_for_each_entry_rcu(dli, pos, head, dl_hlist) {
18628 +
18629 +               if (dli->dl_tag == tag && dli->dl_sb == sb) {
18630 +                       return dli;
18631 +               }
18632 +       }
18633 +       return NULL;
18634 +}
18635 +
18636 +
18637 +struct dl_info *locate_dl_info(struct super_block *sb, tag_t tag)
18638 +{
18639 +       struct dl_info *dli;
18640 +
18641 +       rcu_read_lock();
18642 +       dli = get_dl_info(__lookup_dl_info(sb, tag));
18643 +       vxdprintk(VXD_CBIT(dlim, 7),
18644 +               "locate_dl_info(%p,#%d) = %p", sb, tag, dli);
18645 +       rcu_read_unlock();
18646 +       return dli;
18647 +}
18648 +
18649 +void rcu_free_dl_info(struct rcu_head *head)
18650 +{
18651 +       struct dl_info *dli = container_of(head, struct dl_info, dl_rcu);
18652 +       int usecnt, refcnt;
18653 +
18654 +       BUG_ON(!dli || !head);
18655 +
18656 +       usecnt = atomic_read(&dli->dl_usecnt);
18657 +       BUG_ON(usecnt < 0);
18658 +
18659 +       refcnt = atomic_read(&dli->dl_refcnt);
18660 +       BUG_ON(refcnt < 0);
18661 +
18662 +       vxdprintk(VXD_CBIT(dlim, 3),
18663 +               "rcu_free_dl_info(%p)", dli);
18664 +       if (!usecnt)
18665 +               __dealloc_dl_info(dli);
18666 +       else
18667 +               printk("!!! rcu didn't free\n");
18668 +}
18669 +
18670 +
18671 +
18672 +
18673 +static int do_addrem_dlimit(uint32_t id, const char __user *name,
18674 +       uint32_t flags, int add)
18675 +{
18676 +       struct path path;
18677 +       int ret;
18678 +
18679 +       ret = user_lpath(name, &path);
18680 +       if (!ret) {
18681 +               struct super_block *sb;
18682 +               struct dl_info *dli;
18683 +
18684 +               ret = -EINVAL;
18685 +               if (!path.dentry->d_inode)
18686 +                       goto out_release;
18687 +               if (!(sb = path.dentry->d_inode->i_sb))
18688 +                       goto out_release;
18689 +
18690 +               if (add) {
18691 +                       dli = __alloc_dl_info(sb, id);
18692 +                       spin_lock(&dl_info_hash_lock);
18693 +
18694 +                       ret = -EEXIST;
18695 +                       if (__lookup_dl_info(sb, id))
18696 +                               goto out_unlock;
18697 +                       __hash_dl_info(dli);
18698 +                       dli = NULL;
18699 +               } else {
18700 +                       spin_lock(&dl_info_hash_lock);
18701 +                       dli = __lookup_dl_info(sb, id);
18702 +
18703 +                       ret = -ESRCH;
18704 +                       if (!dli)
18705 +                               goto out_unlock;
18706 +                       __unhash_dl_info(dli);
18707 +               }
18708 +               ret = 0;
18709 +       out_unlock:
18710 +               spin_unlock(&dl_info_hash_lock);
18711 +               if (add && dli)
18712 +                       __dealloc_dl_info(dli);
18713 +       out_release:
18714 +               path_put(&path);
18715 +       }
18716 +       return ret;
18717 +}
18718 +
18719 +int vc_add_dlimit(uint32_t id, void __user *data)
18720 +{
18721 +       struct vcmd_ctx_dlimit_base_v0 vc_data;
18722 +
18723 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18724 +               return -EFAULT;
18725 +
18726 +       return do_addrem_dlimit(id, vc_data.name, vc_data.flags, 1);
18727 +}
18728 +
18729 +int vc_rem_dlimit(uint32_t id, void __user *data)
18730 +{
18731 +       struct vcmd_ctx_dlimit_base_v0 vc_data;
18732 +
18733 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18734 +               return -EFAULT;
18735 +
18736 +       return do_addrem_dlimit(id, vc_data.name, vc_data.flags, 0);
18737 +}
18738 +
18739 +#ifdef CONFIG_COMPAT
18740 +
18741 +int vc_add_dlimit_x32(uint32_t id, void __user *data)
18742 +{
18743 +       struct vcmd_ctx_dlimit_base_v0_x32 vc_data;
18744 +
18745 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18746 +               return -EFAULT;
18747 +
18748 +       return do_addrem_dlimit(id,
18749 +               compat_ptr(vc_data.name_ptr), vc_data.flags, 1);
18750 +}
18751 +
18752 +int vc_rem_dlimit_x32(uint32_t id, void __user *data)
18753 +{
18754 +       struct vcmd_ctx_dlimit_base_v0_x32 vc_data;
18755 +
18756 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18757 +               return -EFAULT;
18758 +
18759 +       return do_addrem_dlimit(id,
18760 +               compat_ptr(vc_data.name_ptr), vc_data.flags, 0);
18761 +}
18762 +
18763 +#endif /* CONFIG_COMPAT */
18764 +
18765 +
18766 +static inline
18767 +int do_set_dlimit(uint32_t id, const char __user *name,
18768 +       uint32_t space_used, uint32_t space_total,
18769 +       uint32_t inodes_used, uint32_t inodes_total,
18770 +       uint32_t reserved, uint32_t flags)
18771 +{
18772 +       struct path path;
18773 +       int ret;
18774 +
18775 +       ret = user_lpath(name, &path);
18776 +       if (!ret) {
18777 +               struct super_block *sb;
18778 +               struct dl_info *dli;
18779 +
18780 +               ret = -EINVAL;
18781 +               if (!path.dentry->d_inode)
18782 +                       goto out_release;
18783 +               if (!(sb = path.dentry->d_inode->i_sb))
18784 +                       goto out_release;
18785 +
18786 +               /* sanity checks */
18787 +               if ((reserved != CDLIM_KEEP &&
18788 +                       reserved > 100) ||
18789 +                       (inodes_used != CDLIM_KEEP &&
18790 +                       inodes_used > inodes_total) ||
18791 +                       (space_used != CDLIM_KEEP &&
18792 +                       space_used > space_total))
18793 +                       goto out_release;
18794 +
18795 +               ret = -ESRCH;
18796 +               dli = locate_dl_info(sb, id);
18797 +               if (!dli)
18798 +                       goto out_release;
18799 +
18800 +               spin_lock(&dli->dl_lock);
18801 +
18802 +               if (inodes_used != CDLIM_KEEP)
18803 +                       dli->dl_inodes_used = inodes_used;
18804 +               if (inodes_total != CDLIM_KEEP)
18805 +                       dli->dl_inodes_total = inodes_total;
18806 +               if (space_used != CDLIM_KEEP)
18807 +                       dli->dl_space_used = dlimit_space_32to64(
18808 +                               space_used, flags, DLIMS_USED);
18809 +
18810 +               if (space_total == CDLIM_INFINITY)
18811 +                       dli->dl_space_total = DLIM_INFINITY;
18812 +               else if (space_total != CDLIM_KEEP)
18813 +                       dli->dl_space_total = dlimit_space_32to64(
18814 +                               space_total, flags, DLIMS_TOTAL);
18815 +
18816 +               if (reserved != CDLIM_KEEP)
18817 +                       dli->dl_nrlmult = (1 << 10) * (100 - reserved) / 100;
18818 +
18819 +               spin_unlock(&dli->dl_lock);
18820 +
18821 +               put_dl_info(dli);
18822 +               ret = 0;
18823 +
18824 +       out_release:
18825 +               path_put(&path);
18826 +       }
18827 +       return ret;
18828 +}
18829 +
18830 +int vc_set_dlimit(uint32_t id, void __user *data)
18831 +{
18832 +       struct vcmd_ctx_dlimit_v0 vc_data;
18833 +
18834 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18835 +               return -EFAULT;
18836 +
18837 +       return do_set_dlimit(id, vc_data.name,
18838 +               vc_data.space_used, vc_data.space_total,
18839 +               vc_data.inodes_used, vc_data.inodes_total,
18840 +               vc_data.reserved, vc_data.flags);
18841 +}
18842 +
18843 +#ifdef CONFIG_COMPAT
18844 +
18845 +int vc_set_dlimit_x32(uint32_t id, void __user *data)
18846 +{
18847 +       struct vcmd_ctx_dlimit_v0_x32 vc_data;
18848 +
18849 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18850 +               return -EFAULT;
18851 +
18852 +       return do_set_dlimit(id, compat_ptr(vc_data.name_ptr),
18853 +               vc_data.space_used, vc_data.space_total,
18854 +               vc_data.inodes_used, vc_data.inodes_total,
18855 +               vc_data.reserved, vc_data.flags);
18856 +}
18857 +
18858 +#endif /* CONFIG_COMPAT */
18859 +
18860 +
18861 +static inline
18862 +int do_get_dlimit(uint32_t id, const char __user *name,
18863 +       uint32_t *space_used, uint32_t *space_total,
18864 +       uint32_t *inodes_used, uint32_t *inodes_total,
18865 +       uint32_t *reserved, uint32_t *flags)
18866 +{
18867 +       struct path path;
18868 +       int ret;
18869 +
18870 +       ret = user_lpath(name, &path);
18871 +       if (!ret) {
18872 +               struct super_block *sb;
18873 +               struct dl_info *dli;
18874 +
18875 +               ret = -EINVAL;
18876 +               if (!path.dentry->d_inode)
18877 +                       goto out_release;
18878 +               if (!(sb = path.dentry->d_inode->i_sb))
18879 +                       goto out_release;
18880 +
18881 +               ret = -ESRCH;
18882 +               dli = locate_dl_info(sb, id);
18883 +               if (!dli)
18884 +                       goto out_release;
18885 +
18886 +               spin_lock(&dli->dl_lock);
18887 +               *inodes_used = dli->dl_inodes_used;
18888 +               *inodes_total = dli->dl_inodes_total;
18889 +
18890 +               *space_used = dlimit_space_64to32(
18891 +                       dli->dl_space_used, flags, DLIMS_USED);
18892 +
18893 +               if (dli->dl_space_total == DLIM_INFINITY)
18894 +                       *space_total = CDLIM_INFINITY;
18895 +               else
18896 +                       *space_total = dlimit_space_64to32(
18897 +                               dli->dl_space_total, flags, DLIMS_TOTAL);
18898 +
18899 +               *reserved = 100 - ((dli->dl_nrlmult * 100 + 512) >> 10);
18900 +               spin_unlock(&dli->dl_lock);
18901 +
18902 +               put_dl_info(dli);
18903 +               ret = -EFAULT;
18904 +
18905 +               ret = 0;
18906 +       out_release:
18907 +               path_put(&path);
18908 +       }
18909 +       return ret;
18910 +}
18911 +
18912 +
18913 +int vc_get_dlimit(uint32_t id, void __user *data)
18914 +{
18915 +       struct vcmd_ctx_dlimit_v0 vc_data;
18916 +       int ret;
18917 +
18918 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18919 +               return -EFAULT;
18920 +
18921 +       ret = do_get_dlimit(id, vc_data.name,
18922 +               &vc_data.space_used, &vc_data.space_total,
18923 +               &vc_data.inodes_used, &vc_data.inodes_total,
18924 +               &vc_data.reserved, &vc_data.flags);
18925 +       if (ret)
18926 +               return ret;
18927 +
18928 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18929 +               return -EFAULT;
18930 +       return 0;
18931 +}
18932 +
18933 +#ifdef CONFIG_COMPAT
18934 +
18935 +int vc_get_dlimit_x32(uint32_t id, void __user *data)
18936 +{
18937 +       struct vcmd_ctx_dlimit_v0_x32 vc_data;
18938 +       int ret;
18939 +
18940 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18941 +               return -EFAULT;
18942 +
18943 +       ret = do_get_dlimit(id, compat_ptr(vc_data.name_ptr),
18944 +               &vc_data.space_used, &vc_data.space_total,
18945 +               &vc_data.inodes_used, &vc_data.inodes_total,
18946 +               &vc_data.reserved, &vc_data.flags);
18947 +       if (ret)
18948 +               return ret;
18949 +
18950 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18951 +               return -EFAULT;
18952 +       return 0;
18953 +}
18954 +
18955 +#endif /* CONFIG_COMPAT */
18956 +
18957 +
18958 +void vx_vsi_statfs(struct super_block *sb, struct kstatfs *buf)
18959 +{
18960 +       struct dl_info *dli;
18961 +       __u64 blimit, bfree, bavail;
18962 +       __u32 ifree;
18963 +
18964 +       dli = locate_dl_info(sb, dx_current_tag());
18965 +       if (!dli)
18966 +               return;
18967 +
18968 +       spin_lock(&dli->dl_lock);
18969 +       if (dli->dl_inodes_total == (unsigned long)DLIM_INFINITY)
18970 +               goto no_ilim;
18971 +
18972 +       /* reduce max inodes available to limit */
18973 +       if (buf->f_files > dli->dl_inodes_total)
18974 +               buf->f_files = dli->dl_inodes_total;
18975 +
18976 +       ifree = dli->dl_inodes_total - dli->dl_inodes_used;
18977 +       /* reduce free inodes to min */
18978 +       if (ifree < buf->f_ffree)
18979 +               buf->f_ffree = ifree;
18980 +
18981 +no_ilim:
18982 +       if (dli->dl_space_total == DLIM_INFINITY)
18983 +               goto no_blim;
18984 +
18985 +       blimit = dli->dl_space_total >> sb->s_blocksize_bits;
18986 +
18987 +       if (dli->dl_space_total < dli->dl_space_used)
18988 +               bfree = 0;
18989 +       else
18990 +               bfree = (dli->dl_space_total - dli->dl_space_used)
18991 +                       >> sb->s_blocksize_bits;
18992 +
18993 +       bavail = ((dli->dl_space_total >> 10) * dli->dl_nrlmult);
18994 +       if (bavail < dli->dl_space_used)
18995 +               bavail = 0;
18996 +       else
18997 +               bavail = (bavail - dli->dl_space_used)
18998 +                       >> sb->s_blocksize_bits;
18999 +
19000 +       /* reduce max space available to limit */
19001 +       if (buf->f_blocks > blimit)
19002 +               buf->f_blocks = blimit;
19003 +
19004 +       /* reduce free space to min */
19005 +       if (bfree < buf->f_bfree)
19006 +               buf->f_bfree = bfree;
19007 +
19008 +       /* reduce avail space to min */
19009 +       if (bavail < buf->f_bavail)
19010 +               buf->f_bavail = bavail;
19011 +
19012 +no_blim:
19013 +       spin_unlock(&dli->dl_lock);
19014 +       put_dl_info(dli);
19015 +
19016 +       return;
19017 +}
19018 +
19019 +#include <linux/module.h>
19020 +
19021 +EXPORT_SYMBOL_GPL(locate_dl_info);
19022 +EXPORT_SYMBOL_GPL(rcu_free_dl_info);
19023 +
19024 diff -NurpP --minimal linux-2.6.38.1/kernel/vserver/helper.c linux-2.6.38.1-vs2.3.0.37-rc9/kernel/vserver/helper.c
19025 --- linux-2.6.38.1/kernel/vserver/helper.c      1970-01-01 01:00:00.000000000 +0100
19026 +++ linux-2.6.38.1-vs2.3.0.37-rc9/kernel/vserver/helper.c       2011-01-29 02:01:07.000000000 +0100
19027 @@ -0,0 +1,223 @@
19028 +/*
19029 + *  linux/kernel/vserver/helper.c
19030 + *
19031 + *  Virtual Context Support
19032 + *
19033 + *  Copyright (C) 2004-2007  Herbert Pötzl
19034 + *
19035 + *  V0.01  basic helper
19036 + *
19037 + */
19038 +
19039 +#include <linux/kmod.h>
19040 +#include <linux/reboot.h>
19041 +#include <linux/vs_context.h>
19042 +#include <linux/vs_network.h>
19043 +#include <linux/vserver/signal.h>
19044 +
19045 +
19046 +char vshelper_path[255] = "/sbin/vshelper";
19047 +
19048 +
19049 +static int do_vshelper(char *name, char *argv[], char *envp[], int sync)
19050 +{
19051 +       int ret;
19052 +
19053 +       if ((ret = call_usermodehelper(name, argv, envp, sync))) {
19054 +               printk( KERN_WARNING
19055 +                       "%s: (%s %s) returned %s with %d\n",
19056 +                       name, argv[1], argv[2],
19057 +                       sync ? "sync" : "async", ret);
19058 +       }
19059 +       vxdprintk(VXD_CBIT(switch, 4),
19060 +               "%s: (%s %s) returned %s with %d",
19061 +               name, argv[1], argv[2], sync ? "sync" : "async", ret);
19062 +       return ret;
19063 +}
19064 +
19065 +/*
19066 + *      vshelper path is set via /proc/sys
19067 + *      invoked by vserver sys_reboot(), with
19068 + *      the following arguments
19069 + *
19070 + *      argv [0] = vshelper_path;
19071 + *      argv [1] = action: "restart", "halt", "poweroff", ...
19072 + *      argv [2] = context identifier
19073 + *
19074 + *      envp [*] = type-specific parameters
19075 + */
19076 +
19077 +long vs_reboot_helper(struct vx_info *vxi, int cmd, void __user *arg)
19078 +{
19079 +       char id_buf[8], cmd_buf[16];
19080 +       char uid_buf[16], pid_buf[16];
19081 +       int ret;
19082 +
19083 +       char *argv[] = {vshelper_path, NULL, id_buf, 0};
19084 +       char *envp[] = {"HOME=/", "TERM=linux",
19085 +                       "PATH=/sbin:/usr/sbin:/bin:/usr/bin",
19086 +                       uid_buf, pid_buf, cmd_buf, 0};
19087 +
19088 +       if (vx_info_state(vxi, VXS_HELPER))
19089 +               return -EAGAIN;
19090 +       vxi->vx_state |= VXS_HELPER;
19091 +
19092 +       snprintf(id_buf, sizeof(id_buf)-1, "%d", vxi->vx_id);
19093 +
19094 +       snprintf(cmd_buf, sizeof(cmd_buf)-1, "VS_CMD=%08x", cmd);
19095 +       snprintf(uid_buf, sizeof(uid_buf)-1, "VS_UID=%d", current_uid());
19096 +       snprintf(pid_buf, sizeof(pid_buf)-1, "VS_PID=%d", current->pid);
19097 +
19098 +       switch (cmd) {
19099 +       case LINUX_REBOOT_CMD_RESTART:
19100 +               argv[1] = "restart";
19101 +               break;
19102 +
19103 +       case LINUX_REBOOT_CMD_HALT:
19104 +               argv[1] = "halt";
19105 +               break;
19106 +
19107 +       case LINUX_REBOOT_CMD_POWER_OFF:
19108 +               argv[1] = "poweroff";
19109 +               break;
19110 +
19111 +       case LINUX_REBOOT_CMD_SW_SUSPEND:
19112 +               argv[1] = "swsusp";
19113 +               break;
19114 +
19115 +       case LINUX_REBOOT_CMD_OOM:
19116 +               argv[1] = "oom";
19117 +               break;
19118 +
19119 +       default:
19120 +               vxi->vx_state &= ~VXS_HELPER;
19121 +               return 0;
19122 +       }
19123 +
19124 +       ret = do_vshelper(vshelper_path, argv, envp, 0);
19125 +       vxi->vx_state &= ~VXS_HELPER;
19126 +       __wakeup_vx_info(vxi);
19127 +       return (ret) ? -EPERM : 0;
19128 +}
19129 +
19130 +
19131 +long vs_reboot(unsigned int cmd, void __user *arg)
19132 +{
19133 +       struct vx_info *vxi = current_vx_info();
19134 +       long ret = 0;
19135 +
19136 +       vxdprintk(VXD_CBIT(misc, 5),
19137 +               "vs_reboot(%p[#%d],%u)",
19138 +               vxi, vxi ? vxi->vx_id : 0, cmd);
19139 +
19140 +       ret = vs_reboot_helper(vxi, cmd, arg);
19141 +       if (ret)
19142 +               return ret;
19143 +
19144 +       vxi->reboot_cmd = cmd;
19145 +       if (vx_info_flags(vxi, VXF_REBOOT_KILL, 0)) {
19146 +               switch (cmd) {
19147 +               case LINUX_REBOOT_CMD_RESTART:
19148 +               case LINUX_REBOOT_CMD_HALT:
19149 +               case LINUX_REBOOT_CMD_POWER_OFF:
19150 +                       vx_info_kill(vxi, 0, SIGKILL);
19151 +                       vx_info_kill(vxi, 1, SIGKILL);
19152 +               default:
19153 +                       break;
19154 +               }
19155 +       }
19156 +       return 0;
19157 +}
19158 +
19159 +long vs_oom_action(unsigned int cmd)
19160 +{
19161 +       struct vx_info *vxi = current_vx_info();
19162 +       long ret = 0;
19163 +
19164 +       vxdprintk(VXD_CBIT(misc, 5),
19165 +               "vs_oom_action(%p[#%d],%u)",
19166 +               vxi, vxi ? vxi->vx_id : 0, cmd);
19167 +
19168 +       ret = vs_reboot_helper(vxi, cmd, NULL);
19169 +       if (ret)
19170 +               return ret;
19171 +
19172 +       vxi->reboot_cmd = cmd;
19173 +       if (vx_info_flags(vxi, VXF_REBOOT_KILL, 0)) {
19174 +               vx_info_kill(vxi, 0, SIGKILL);
19175 +               vx_info_kill(vxi, 1, SIGKILL);
19176 +       }
19177 +       return 0;
19178 +}
19179 +
19180 +/*
19181 + *      argv [0] = vshelper_path;
19182 + *      argv [1] = action: "startup", "shutdown"
19183 + *      argv [2] = context identifier
19184 + *
19185 + *      envp [*] = type-specific parameters
19186 + */
19187 +
19188 +long vs_state_change(struct vx_info *vxi, unsigned int cmd)
19189 +{
19190 +       char id_buf[8], cmd_buf[16];
19191 +       char *argv[] = {vshelper_path, NULL, id_buf, 0};
19192 +       char *envp[] = {"HOME=/", "TERM=linux",
19193 +                       "PATH=/sbin:/usr/sbin:/bin:/usr/bin", cmd_buf, 0};
19194 +
19195 +       if (!vx_info_flags(vxi, VXF_SC_HELPER, 0))
19196 +               return 0;
19197 +
19198 +       snprintf(id_buf, sizeof(id_buf)-1, "%d", vxi->vx_id);
19199 +       snprintf(cmd_buf, sizeof(cmd_buf)-1, "VS_CMD=%08x", cmd);
19200 +
19201 +       switch (cmd) {
19202 +       case VSC_STARTUP:
19203 +               argv[1] = "startup";
19204 +               break;
19205 +       case VSC_SHUTDOWN:
19206 +               argv[1] = "shutdown";
19207 +               break;
19208 +       default:
19209 +               return 0;
19210 +       }
19211 +
19212 +       return do_vshelper(vshelper_path, argv, envp, 1);
19213 +}
19214 +
19215 +
19216 +/*
19217 + *      argv [0] = vshelper_path;
19218 + *      argv [1] = action: "netup", "netdown"
19219 + *      argv [2] = context identifier
19220 + *
19221 + *      envp [*] = type-specific parameters
19222 + */
19223 +
19224 +long vs_net_change(struct nx_info *nxi, unsigned int cmd)
19225 +{
19226 +       char id_buf[8], cmd_buf[16];
19227 +       char *argv[] = {vshelper_path, NULL, id_buf, 0};
19228 +       char *envp[] = {"HOME=/", "TERM=linux",
19229 +                       "PATH=/sbin:/usr/sbin:/bin:/usr/bin", cmd_buf, 0};
19230 +
19231 +       if (!nx_info_flags(nxi, NXF_SC_HELPER, 0))
19232 +               return 0;
19233 +
19234 +       snprintf(id_buf, sizeof(id_buf)-1, "%d", nxi->nx_id);
19235 +       snprintf(cmd_buf, sizeof(cmd_buf)-1, "VS_CMD=%08x", cmd);
19236 +
19237 +       switch (cmd) {
19238 +       case VSC_NETUP:
19239 +               argv[1] = "netup";
19240 +               break;
19241 +       case VSC_NETDOWN:
19242 +               argv[1] = "netdown";
19243 +               break;
19244 +       default:
19245 +               return 0;
19246 +       }
19247 +
19248 +       return do_vshelper(vshelper_path, argv, envp, 1);
19249 +}
19250 +
19251 diff -NurpP --minimal linux-2.6.38.1/kernel/vserver/history.c linux-2.6.38.1-vs2.3.0.37-rc9/kernel/vserver/history.c
19252 --- linux-2.6.38.1/kernel/vserver/history.c     1970-01-01 01:00:00.000000000 +0100
19253 +++ linux-2.6.38.1-vs2.3.0.37-rc9/kernel/vserver/history.c      2011-01-29 02:01:07.000000000 +0100
19254 @@ -0,0 +1,258 @@
19255 +/*
19256 + *  kernel/vserver/history.c
19257 + *
19258 + *  Virtual Context History Backtrace
19259 + *
19260 + *  Copyright (C) 2004-2007  Herbert Pötzl
19261 + *
19262 + *  V0.01  basic structure
19263 + *  V0.02  hash/unhash and trace
19264 + *  V0.03  preemption fixes
19265 + *
19266 + */
19267 +
19268 +#include <linux/module.h>
19269 +#include <asm/uaccess.h>
19270 +
19271 +#include <linux/vserver/context.h>
19272 +#include <linux/vserver/debug.h>
19273 +#include <linux/vserver/debug_cmd.h>
19274 +#include <linux/vserver/history.h>
19275 +
19276 +
19277 +#ifdef CONFIG_VSERVER_HISTORY
19278 +#define VXH_SIZE       CONFIG_VSERVER_HISTORY_SIZE
19279 +#else
19280 +#define VXH_SIZE       64
19281 +#endif
19282 +
19283 +struct _vx_history {
19284 +       unsigned int counter;
19285 +
19286 +       struct _vx_hist_entry entry[VXH_SIZE + 1];
19287 +};
19288 +
19289 +
19290 +DEFINE_PER_CPU(struct _vx_history, vx_history_buffer);
19291 +
19292 +unsigned volatile int vxh_active = 1;
19293 +
19294 +static atomic_t sequence = ATOMIC_INIT(0);
19295 +
19296 +
19297 +/*     vxh_advance()
19298 +
19299 +       * requires disabled preemption                          */
19300 +
19301 +struct _vx_hist_entry *vxh_advance(void *loc)
19302 +{
19303 +       unsigned int cpu = smp_processor_id();
19304 +       struct _vx_history *hist = &per_cpu(vx_history_buffer, cpu);
19305 +       struct _vx_hist_entry *entry;
19306 +       unsigned int index;
19307 +
19308 +       index = vxh_active ? (hist->counter++ % VXH_SIZE) : VXH_SIZE;
19309 +       entry = &hist->entry[index];
19310 +
19311 +       entry->seq = atomic_inc_return(&sequence);
19312 +       entry->loc = loc;
19313 +       return entry;
19314 +}
19315 +
19316 +EXPORT_SYMBOL_GPL(vxh_advance);
19317 +
19318 +
19319 +#define VXH_LOC_FMTS   "(#%04x,*%d):%p"
19320 +
19321 +#define VXH_LOC_ARGS(e)        (e)->seq, cpu, (e)->loc
19322 +
19323 +
19324 +#define VXH_VXI_FMTS   "%p[#%d,%d.%d]"
19325 +
19326 +#define VXH_VXI_ARGS(e)        (e)->vxi.ptr,                           \
19327 +                       (e)->vxi.ptr ? (e)->vxi.xid : 0,        \
19328 +                       (e)->vxi.ptr ? (e)->vxi.usecnt : 0,     \
19329 +                       (e)->vxi.ptr ? (e)->vxi.tasks : 0
19330 +
19331 +void   vxh_dump_entry(struct _vx_hist_entry *e, unsigned cpu)
19332 +{
19333 +       switch (e->type) {
19334 +       case VXH_THROW_OOPS:
19335 +               printk( VXH_LOC_FMTS " oops \n", VXH_LOC_ARGS(e));
19336 +               break;
19337 +
19338 +       case VXH_GET_VX_INFO:
19339 +       case VXH_PUT_VX_INFO:
19340 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS "\n",
19341 +                       VXH_LOC_ARGS(e),
19342 +                       (e->type == VXH_GET_VX_INFO) ? "get" : "put",
19343 +                       VXH_VXI_ARGS(e));
19344 +               break;
19345 +
19346 +       case VXH_INIT_VX_INFO:
19347 +       case VXH_SET_VX_INFO:
19348 +       case VXH_CLR_VX_INFO:
19349 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS " @%p\n",
19350 +                       VXH_LOC_ARGS(e),
19351 +                       (e->type == VXH_INIT_VX_INFO) ? "init" :
19352 +                       ((e->type == VXH_SET_VX_INFO) ? "set" : "clr"),
19353 +                       VXH_VXI_ARGS(e), e->sc.data);
19354 +               break;
19355 +
19356 +       case VXH_CLAIM_VX_INFO:
19357 +       case VXH_RELEASE_VX_INFO:
19358 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS " @%p\n",
19359 +                       VXH_LOC_ARGS(e),
19360 +                       (e->type == VXH_CLAIM_VX_INFO) ? "claim" : "release",
19361 +                       VXH_VXI_ARGS(e), e->sc.data);
19362 +               break;
19363 +
19364 +       case VXH_ALLOC_VX_INFO:
19365 +       case VXH_DEALLOC_VX_INFO:
19366 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS "\n",
19367 +                       VXH_LOC_ARGS(e),
19368 +                       (e->type == VXH_ALLOC_VX_INFO) ? "alloc" : "dealloc",
19369 +                       VXH_VXI_ARGS(e));
19370 +               break;
19371 +
19372 +       case VXH_HASH_VX_INFO:
19373 +       case VXH_UNHASH_VX_INFO:
19374 +               printk( VXH_LOC_FMTS " __%s_vx_info " VXH_VXI_FMTS "\n",
19375 +                       VXH_LOC_ARGS(e),
19376 +                       (e->type == VXH_HASH_VX_INFO) ? "hash" : "unhash",
19377 +                       VXH_VXI_ARGS(e));
19378 +               break;
19379 +
19380 +       case VXH_LOC_VX_INFO:
19381 +       case VXH_LOOKUP_VX_INFO:
19382 +       case VXH_CREATE_VX_INFO:
19383 +               printk( VXH_LOC_FMTS " __%s_vx_info [#%d] -> " VXH_VXI_FMTS "\n",
19384 +                       VXH_LOC_ARGS(e),
19385 +                       (e->type == VXH_CREATE_VX_INFO) ? "create" :
19386 +                       ((e->type == VXH_LOC_VX_INFO) ? "loc" : "lookup"),
19387 +                       e->ll.arg, VXH_VXI_ARGS(e));
19388 +               break;
19389 +       }
19390 +}
19391 +
19392 +static void __vxh_dump_history(void)
19393 +{
19394 +       unsigned int i, cpu;
19395 +
19396 +       printk("History:\tSEQ: %8x\tNR_CPUS: %d\n",
19397 +               atomic_read(&sequence), NR_CPUS);
19398 +
19399 +       for (i = 0; i < VXH_SIZE; i++) {
19400 +               for_each_online_cpu(cpu) {
19401 +                       struct _vx_history *hist =
19402 +                               &per_cpu(vx_history_buffer, cpu);
19403 +                       unsigned int index = (hist->counter - i) % VXH_SIZE;
19404 +                       struct _vx_hist_entry *entry = &hist->entry[index];
19405 +
19406 +                       vxh_dump_entry(entry, cpu);
19407 +               }
19408 +       }
19409 +}
19410 +
19411 +void   vxh_dump_history(void)
19412 +{
19413 +       vxh_active = 0;
19414 +#ifdef CONFIG_SMP
19415 +       local_irq_enable();
19416 +       smp_send_stop();
19417 +       local_irq_disable();
19418 +#endif
19419 +       __vxh_dump_history();
19420 +}
19421 +
19422 +
19423 +/* vserver syscall commands below here */
19424 +
19425 +
19426 +int vc_dump_history(uint32_t id)
19427 +{
19428 +       vxh_active = 0;
19429 +       __vxh_dump_history();
19430 +       vxh_active = 1;
19431 +
19432 +       return 0;
19433 +}
19434 +
19435 +
19436 +int do_read_history(struct __user _vx_hist_entry *data,
19437 +       int cpu, uint32_t *index, uint32_t *count)
19438 +{
19439 +       int pos, ret = 0;
19440 +       struct _vx_history *hist = &per_cpu(vx_history_buffer, cpu);
19441 +       int end = hist->counter;
19442 +       int start = end - VXH_SIZE + 2;
19443 +       int idx = *index;
19444 +
19445 +       /* special case: get current pos */
19446 +       if (!*count) {
19447 +               *index = end;
19448 +               return 0;
19449 +       }
19450 +
19451 +       /* have we lost some data? */
19452 +       if (idx < start)
19453 +               idx = start;
19454 +
19455 +       for (pos = 0; (pos < *count) && (idx < end); pos++, idx++) {
19456 +               struct _vx_hist_entry *entry =
19457 +                       &hist->entry[idx % VXH_SIZE];
19458 +
19459 +               /* send entry to userspace */
19460 +               ret = copy_to_user(&data[pos], entry, sizeof(*entry));
19461 +               if (ret)
19462 +                       break;
19463 +       }
19464 +       /* save new index and count */
19465 +       *index = idx;
19466 +       *count = pos;
19467 +       return ret ? ret : (*index < end);
19468 +}
19469 +
19470 +int vc_read_history(uint32_t id, void __user *data)
19471 +{
19472 +       struct vcmd_read_history_v0 vc_data;
19473 +       int ret;
19474 +
19475 +       if (id >= NR_CPUS)
19476 +               return -EINVAL;
19477 +
19478 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19479 +               return -EFAULT;
19480 +
19481 +       ret = do_read_history((struct __user _vx_hist_entry *)vc_data.data,
19482 +               id, &vc_data.index, &vc_data.count);
19483 +
19484 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19485 +               return -EFAULT;
19486 +       return ret;
19487 +}
19488 +
19489 +#ifdef CONFIG_COMPAT
19490 +
19491 +int vc_read_history_x32(uint32_t id, void __user *data)
19492 +{
19493 +       struct vcmd_read_history_v0_x32 vc_data;
19494 +       int ret;
19495 +
19496 +       if (id >= NR_CPUS)
19497 +               return -EINVAL;
19498 +
19499 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19500 +               return -EFAULT;
19501 +
19502 +       ret = do_read_history((struct __user _vx_hist_entry *)
19503 +               compat_ptr(vc_data.data_ptr),
19504 +               id, &vc_data.index, &vc_data.count);
19505 +
19506 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19507 +               return -EFAULT;
19508 +       return ret;
19509 +}
19510 +
19511 +#endif /* CONFIG_COMPAT */
19512 +
19513 diff -NurpP --minimal linux-2.6.38.1/kernel/vserver/inet.c linux-2.6.38.1-vs2.3.0.37-rc9/kernel/vserver/inet.c
19514 --- linux-2.6.38.1/kernel/vserver/inet.c        1970-01-01 01:00:00.000000000 +0100
19515 +++ linux-2.6.38.1-vs2.3.0.37-rc9/kernel/vserver/inet.c 2011-01-29 02:01:07.000000000 +0100
19516 @@ -0,0 +1,224 @@
19517 +
19518 +#include <linux/in.h>
19519 +#include <linux/inetdevice.h>
19520 +#include <linux/vs_inet.h>
19521 +#include <linux/vs_inet6.h>
19522 +#include <linux/vserver/debug.h>
19523 +#include <net/route.h>
19524 +#include <net/addrconf.h>
19525 +
19526 +
19527 +int nx_v4_addr_conflict(struct nx_info *nxi1, struct nx_info *nxi2)
19528 +{
19529 +       int ret = 0;
19530 +
19531 +       if (!nxi1 || !nxi2 || nxi1 == nxi2)
19532 +               ret = 1;
19533 +       else {
19534 +               struct nx_addr_v4 *ptr;
19535 +
19536 +               for (ptr = &nxi1->v4; ptr; ptr = ptr->next) {
19537 +                       if (v4_nx_addr_in_nx_info(nxi2, ptr, -1)) {
19538 +                               ret = 1;
19539 +                               break;
19540 +                       }
19541 +               }
19542 +       }
19543 +
19544 +       vxdprintk(VXD_CBIT(net, 2),
19545 +               "nx_v4_addr_conflict(%p,%p): %d",
19546 +               nxi1, nxi2, ret);
19547 +
19548 +       return ret;
19549 +}
19550 +
19551 +
19552 +#ifdef CONFIG_IPV6
19553 +
19554 +int nx_v6_addr_conflict(struct nx_info *nxi1, struct nx_info *nxi2)
19555 +{
19556 +       int ret = 0;
19557 +
19558 +       if (!nxi1 || !nxi2 || nxi1 == nxi2)
19559 +               ret = 1;
19560 +       else {
19561 +               struct nx_addr_v6 *ptr;
19562 +
19563 +               for (ptr = &nxi1->v6; ptr; ptr = ptr->next) {
19564 +                       if (v6_nx_addr_in_nx_info(nxi2, ptr, -1)) {
19565 +                               ret = 1;
19566 +                               break;
19567 +                       }
19568 +               }
19569 +       }
19570 +
19571 +       vxdprintk(VXD_CBIT(net, 2),
19572 +               "nx_v6_addr_conflict(%p,%p): %d",
19573 +               nxi1, nxi2, ret);
19574 +
19575 +       return ret;
19576 +}
19577 +
19578 +#endif
19579 +
19580 +int v4_dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
19581 +{
19582 +       struct in_device *in_dev;
19583 +       struct in_ifaddr **ifap;
19584 +       struct in_ifaddr *ifa;
19585 +       int ret = 0;
19586 +
19587 +       if (!dev)
19588 +               goto out;
19589 +       in_dev = in_dev_get(dev);
19590 +       if (!in_dev)
19591 +               goto out;
19592 +
19593 +       for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
19594 +               ifap = &ifa->ifa_next) {
19595 +               if (v4_addr_in_nx_info(nxi, ifa->ifa_local, NXA_MASK_SHOW)) {
19596 +                       ret = 1;
19597 +                       break;
19598 +               }
19599 +       }
19600 +       in_dev_put(in_dev);
19601 +out:
19602 +       return ret;
19603 +}
19604 +
19605 +
19606 +#ifdef CONFIG_IPV6
19607 +
19608 +int v6_dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
19609 +{
19610 +       struct inet6_dev *in_dev;
19611 +       struct inet6_ifaddr *ifa;
19612 +       int ret = 0;
19613 +
19614 +       if (!dev)
19615 +               goto out;
19616 +       in_dev = in6_dev_get(dev);
19617 +       if (!in_dev)
19618 +               goto out;
19619 +
19620 +       // for (ifap = &in_dev->addr_list; (ifa = *ifap) != NULL;
19621 +       list_for_each_entry(ifa, &in_dev->addr_list, if_list) {
19622 +               if (v6_addr_in_nx_info(nxi, &ifa->addr, -1)) {
19623 +                       ret = 1;
19624 +                       break;
19625 +               }
19626 +       }
19627 +       in6_dev_put(in_dev);
19628 +out:
19629 +       return ret;
19630 +}
19631 +
19632 +#endif
19633 +
19634 +int dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
19635 +{
19636 +       int ret = 1;
19637 +
19638 +       if (!nxi)
19639 +               goto out;
19640 +       if (nxi->v4.type && v4_dev_in_nx_info(dev, nxi))
19641 +               goto out;
19642 +#ifdef CONFIG_IPV6
19643 +       ret = 2;
19644 +       if (nxi->v6.type && v6_dev_in_nx_info(dev, nxi))
19645 +               goto out;
19646 +#endif
19647 +       ret = 0;
19648 +out:
19649 +       vxdprintk(VXD_CBIT(net, 3),
19650 +               "dev_in_nx_info(%p,%p[#%d]) = %d",
19651 +               dev, nxi, nxi ? nxi->nx_id : 0, ret);
19652 +       return ret;
19653 +}
19654 +
19655 +int ip_v4_find_src(struct net *net, struct nx_info *nxi,
19656 +       struct rtable **rp, struct flowi *fl)
19657 +{
19658 +       if (!nxi)
19659 +               return 0;
19660 +
19661 +       /* FIXME: handle lback only case */
19662 +       if (!NX_IPV4(nxi))
19663 +               return -EPERM;
19664 +
19665 +       vxdprintk(VXD_CBIT(net, 4),
19666 +               "ip_v4_find_src(%p[#%u]) " NIPQUAD_FMT " -> " NIPQUAD_FMT,
19667 +               nxi, nxi ? nxi->nx_id : 0,
19668 +               NIPQUAD(fl->fl4_src), NIPQUAD(fl->fl4_dst));
19669 +
19670 +       /* single IP is unconditional */
19671 +       if (nx_info_flags(nxi, NXF_SINGLE_IP, 0) &&
19672 +               (fl->fl4_src == INADDR_ANY))
19673 +               fl->fl4_src = nxi->v4.ip[0].s_addr;
19674 +
19675 +       if (fl->fl4_src == INADDR_ANY) {
19676 +               struct nx_addr_v4 *ptr;
19677 +               __be32 found = 0;
19678 +               int err;
19679 +
19680 +               err = __ip_route_output_key(net, rp, fl);
19681 +               if (!err) {
19682 +                       found = (*rp)->rt_src;
19683 +                       ip_rt_put(*rp);
19684 +                       vxdprintk(VXD_CBIT(net, 4),
19685 +                               "ip_v4_find_src(%p[#%u]) rok[%u]: " NIPQUAD_FMT,
19686 +                               nxi, nxi ? nxi->nx_id : 0, fl->oif, NIPQUAD(found));
19687 +                       if (v4_addr_in_nx_info(nxi, found, NXA_MASK_BIND))
19688 +                               goto found;
19689 +               }
19690 +
19691 +               for (ptr = &nxi->v4; ptr; ptr = ptr->next) {
19692 +                       __be32 primary = ptr->ip[0].s_addr;
19693 +                       __be32 mask = ptr->mask.s_addr;
19694 +                       __be32 neta = primary & mask;
19695 +
19696 +                       vxdprintk(VXD_CBIT(net, 4), "ip_v4_find_src(%p[#%u]) chk: "
19697 +                               NIPQUAD_FMT "/" NIPQUAD_FMT "/" NIPQUAD_FMT,
19698 +                               nxi, nxi ? nxi->nx_id : 0, NIPQUAD(primary),
19699 +                               NIPQUAD(mask), NIPQUAD(neta));
19700 +                       if ((found & mask) != neta)
19701 +                               continue;
19702 +
19703 +                       fl->fl4_src = primary;
19704 +                       err = __ip_route_output_key(net, rp, fl);
19705 +                       vxdprintk(VXD_CBIT(net, 4),
19706 +                               "ip_v4_find_src(%p[#%u]) rok[%u]: " NIPQUAD_FMT,
19707 +                               nxi, nxi ? nxi->nx_id : 0, fl->oif, NIPQUAD(primary));
19708 +                       if (!err) {
19709 +                               found = (*rp)->rt_src;
19710 +                               ip_rt_put(*rp);
19711 +                               if (found == primary)
19712 +                                       goto found;
19713 +                       }
19714 +               }
19715 +               /* still no source ip? */
19716 +               found = ipv4_is_loopback(fl->fl4_dst)
19717 +                       ? IPI_LOOPBACK : nxi->v4.ip[0].s_addr;
19718 +       found:
19719 +               /* assign src ip to flow */
19720 +               fl->fl4_src = found;
19721 +
19722 +       } else {
19723 +               if (!v4_addr_in_nx_info(nxi, fl->fl4_src, NXA_MASK_BIND))
19724 +                       return -EPERM;
19725 +       }
19726 +
19727 +       if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0)) {
19728 +               if (ipv4_is_loopback(fl->fl4_dst))
19729 +                       fl->fl4_dst = nxi->v4_lback.s_addr;
19730 +               if (ipv4_is_loopback(fl->fl4_src))
19731 +                       fl->fl4_src = nxi->v4_lback.s_addr;
19732 +       } else if (ipv4_is_loopback(fl->fl4_dst) &&
19733 +               !nx_info_flags(nxi, NXF_LBACK_ALLOW, 0))
19734 +               return -EPERM;
19735 +
19736 +       return 0;
19737 +}
19738 +
19739 +EXPORT_SYMBOL_GPL(ip_v4_find_src);
19740 +
19741 diff -NurpP --minimal linux-2.6.38.1/kernel/vserver/init.c linux-2.6.38.1-vs2.3.0.37-rc9/kernel/vserver/init.c
19742 --- linux-2.6.38.1/kernel/vserver/init.c        1970-01-01 01:00:00.000000000 +0100
19743 +++ linux-2.6.38.1-vs2.3.0.37-rc9/kernel/vserver/init.c 2011-01-29 02:01:07.000000000 +0100
19744 @@ -0,0 +1,45 @@
19745 +/*
19746 + *  linux/kernel/init.c
19747 + *
19748 + *  Virtual Server Init
19749 + *
19750 + *  Copyright (C) 2004-2007  Herbert Pötzl
19751 + *
19752 + *  V0.01  basic structure
19753 + *
19754 + */
19755 +
19756 +#include <linux/init.h>
19757 +
19758 +int    vserver_register_sysctl(void);
19759 +void   vserver_unregister_sysctl(void);
19760 +
19761 +
19762 +static int __init init_vserver(void)
19763 +{
19764 +       int ret = 0;
19765 +
19766 +#ifdef CONFIG_VSERVER_DEBUG
19767 +       vserver_register_sysctl();
19768 +#endif
19769 +       return ret;
19770 +}
19771 +
19772 +
19773 +static void __exit exit_vserver(void)
19774 +{
19775 +
19776 +#ifdef CONFIG_VSERVER_DEBUG
19777 +       vserver_unregister_sysctl();
19778 +#endif
19779 +       return;
19780 +}
19781 +
19782 +/* FIXME: GFP_ZONETYPES gone
19783 +long vx_slab[GFP_ZONETYPES]; */
19784 +long vx_area;
19785 +
19786 +
19787 +module_init(init_vserver);
19788 +module_exit(exit_vserver);
19789 +
19790 diff -NurpP --minimal linux-2.6.38.1/kernel/vserver/inode.c linux-2.6.38.1-vs2.3.0.37-rc9/kernel/vserver/inode.c
19791 --- linux-2.6.38.1/kernel/vserver/inode.c       1970-01-01 01:00:00.000000000 +0100
19792 +++ linux-2.6.38.1-vs2.3.0.37-rc9/kernel/vserver/inode.c        2011-03-21 07:25:53.000000000 +0100
19793 @@ -0,0 +1,437 @@
19794 +/*
19795 + *  linux/kernel/vserver/inode.c
19796 + *
19797 + *  Virtual Server: File System Support
19798 + *
19799 + *  Copyright (C) 2004-2007  Herbert Pötzl
19800 + *
19801 + *  V0.01  separated from vcontext V0.05
19802 + *  V0.02  moved to tag (instead of xid)
19803 + *
19804 + */
19805 +
19806 +#include <linux/tty.h>
19807 +#include <linux/proc_fs.h>
19808 +#include <linux/devpts_fs.h>
19809 +#include <linux/fs.h>
19810 +#include <linux/file.h>
19811 +#include <linux/mount.h>
19812 +#include <linux/parser.h>
19813 +#include <linux/namei.h>
19814 +#include <linux/vserver/inode.h>
19815 +#include <linux/vserver/inode_cmd.h>
19816 +#include <linux/vs_base.h>
19817 +#include <linux/vs_tag.h>
19818 +
19819 +#include <asm/uaccess.h>
19820 +
19821 +
19822 +static int __vc_get_iattr(struct inode *in, uint32_t *tag, uint32_t *flags, uint32_t *mask)
19823 +{
19824 +       struct proc_dir_entry *entry;
19825 +
19826 +       if (!in || !in->i_sb)
19827 +               return -ESRCH;
19828 +
19829 +       *flags = IATTR_TAG
19830 +               | (IS_IMMUTABLE(in) ? IATTR_IMMUTABLE : 0)
19831 +               | (IS_IXUNLINK(in) ? IATTR_IXUNLINK : 0)
19832 +               | (IS_BARRIER(in) ? IATTR_BARRIER : 0)
19833 +               | (IS_COW(in) ? IATTR_COW : 0);
19834 +       *mask = IATTR_IXUNLINK | IATTR_IMMUTABLE | IATTR_COW;
19835 +
19836 +       if (S_ISDIR(in->i_mode))
19837 +               *mask |= IATTR_BARRIER;
19838 +
19839 +       if (IS_TAGGED(in)) {
19840 +               *tag = in->i_tag;
19841 +               *mask |= IATTR_TAG;
19842 +       }
19843 +
19844 +       switch (in->i_sb->s_magic) {
19845 +       case PROC_SUPER_MAGIC:
19846 +               entry = PROC_I(in)->pde;
19847 +
19848 +               /* check for specific inodes? */
19849 +               if (entry)
19850 +                       *mask |= IATTR_FLAGS;
19851 +               if (entry)
19852 +                       *flags |= (entry->vx_flags & IATTR_FLAGS);
19853 +               else
19854 +                       *flags |= (PROC_I(in)->vx_flags & IATTR_FLAGS);
19855 +               break;
19856 +
19857 +       case DEVPTS_SUPER_MAGIC:
19858 +               *tag = in->i_tag;
19859 +               *mask |= IATTR_TAG;
19860 +               break;
19861 +
19862 +       default:
19863 +               break;
19864 +       }
19865 +       return 0;
19866 +}
19867 +
19868 +int vc_get_iattr(void __user *data)
19869 +{
19870 +       struct path path;
19871 +       struct vcmd_ctx_iattr_v1 vc_data = { .tag = -1 };
19872 +       int ret;
19873 +
19874 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19875 +               return -EFAULT;
19876 +
19877 +       ret = user_lpath(vc_data.name, &path);
19878 +       if (!ret) {
19879 +               ret = __vc_get_iattr(path.dentry->d_inode,
19880 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
19881 +               path_put(&path);
19882 +       }
19883 +       if (ret)
19884 +               return ret;
19885 +
19886 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19887 +               ret = -EFAULT;
19888 +       return ret;
19889 +}
19890 +
19891 +#ifdef CONFIG_COMPAT
19892 +
19893 +int vc_get_iattr_x32(void __user *data)
19894 +{
19895 +       struct path path;
19896 +       struct vcmd_ctx_iattr_v1_x32 vc_data = { .tag = -1 };
19897 +       int ret;
19898 +
19899 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19900 +               return -EFAULT;
19901 +
19902 +       ret = user_lpath(compat_ptr(vc_data.name_ptr), &path);
19903 +       if (!ret) {
19904 +               ret = __vc_get_iattr(path.dentry->d_inode,
19905 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
19906 +               path_put(&path);
19907 +       }
19908 +       if (ret)
19909 +               return ret;
19910 +
19911 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19912 +               ret = -EFAULT;
19913 +       return ret;
19914 +}
19915 +
19916 +#endif /* CONFIG_COMPAT */
19917 +
19918 +
19919 +int vc_fget_iattr(uint32_t fd, void __user *data)
19920 +{
19921 +       struct file *filp;
19922 +       struct vcmd_ctx_fiattr_v0 vc_data = { .tag = -1 };
19923 +       int ret;
19924 +
19925 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19926 +               return -EFAULT;
19927 +
19928 +       filp = fget(fd);
19929 +       if (!filp || !filp->f_dentry || !filp->f_dentry->d_inode)
19930 +               return -EBADF;
19931 +
19932 +       ret = __vc_get_iattr(filp->f_dentry->d_inode,
19933 +               &vc_data.tag, &vc_data.flags, &vc_data.mask);
19934 +
19935 +       fput(filp);
19936 +
19937 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19938 +               ret = -EFAULT;
19939 +       return ret;
19940 +}
19941 +
19942 +
19943 +static int __vc_set_iattr(struct dentry *de, uint32_t *tag, uint32_t *flags, uint32_t *mask)
19944 +{
19945 +       struct inode *in = de->d_inode;
19946 +       int error = 0, is_proc = 0, has_tag = 0;
19947 +       struct iattr attr = { 0 };
19948 +
19949 +       if (!in || !in->i_sb)
19950 +               return -ESRCH;
19951 +
19952 +       is_proc = (in->i_sb->s_magic == PROC_SUPER_MAGIC);
19953 +       if ((*mask & IATTR_FLAGS) && !is_proc)
19954 +               return -EINVAL;
19955 +
19956 +       has_tag = IS_TAGGED(in) ||
19957 +               (in->i_sb->s_magic == DEVPTS_SUPER_MAGIC);
19958 +       if ((*mask & IATTR_TAG) && !has_tag)
19959 +               return -EINVAL;
19960 +
19961 +       mutex_lock(&in->i_mutex);
19962 +       if (*mask & IATTR_TAG) {
19963 +               attr.ia_tag = *tag;
19964 +               attr.ia_valid |= ATTR_TAG;
19965 +       }
19966 +
19967 +       if (*mask & IATTR_FLAGS) {
19968 +               struct proc_dir_entry *entry = PROC_I(in)->pde;
19969 +               unsigned int iflags = PROC_I(in)->vx_flags;
19970 +
19971 +               iflags = (iflags & ~(*mask & IATTR_FLAGS))
19972 +                       | (*flags & IATTR_FLAGS);
19973 +               PROC_I(in)->vx_flags = iflags;
19974 +               if (entry)
19975 +                       entry->vx_flags = iflags;
19976 +       }
19977 +
19978 +       if (*mask & (IATTR_IMMUTABLE | IATTR_IXUNLINK |
19979 +               IATTR_BARRIER | IATTR_COW)) {
19980 +               int iflags = in->i_flags;
19981 +               int vflags = in->i_vflags;
19982 +
19983 +               if (*mask & IATTR_IMMUTABLE) {
19984 +                       if (*flags & IATTR_IMMUTABLE)
19985 +                               iflags |= S_IMMUTABLE;
19986 +                       else
19987 +                               iflags &= ~S_IMMUTABLE;
19988 +               }
19989 +               if (*mask & IATTR_IXUNLINK) {
19990 +                       if (*flags & IATTR_IXUNLINK)
19991 +                               iflags |= S_IXUNLINK;
19992 +                       else
19993 +                               iflags &= ~S_IXUNLINK;
19994 +               }
19995 +               if (S_ISDIR(in->i_mode) && (*mask & IATTR_BARRIER)) {
19996 +                       if (*flags & IATTR_BARRIER)
19997 +                               vflags |= V_BARRIER;
19998 +                       else
19999 +                               vflags &= ~V_BARRIER;
20000 +               }
20001 +               if (S_ISREG(in->i_mode) && (*mask & IATTR_COW)) {
20002 +                       if (*flags & IATTR_COW)
20003 +                               vflags |= V_COW;
20004 +                       else
20005 +                               vflags &= ~V_COW;
20006 +               }
20007 +               if (in->i_op && in->i_op->sync_flags) {
20008 +                       error = in->i_op->sync_flags(in, iflags, vflags);
20009 +                       if (error)
20010 +                               goto out;
20011 +               }
20012 +       }
20013 +
20014 +       if (attr.ia_valid) {
20015 +               if (in->i_op && in->i_op->setattr)
20016 +                       error = in->i_op->setattr(de, &attr);
20017 +               else {
20018 +                       error = inode_change_ok(in, &attr);
20019 +                       if (!error) {
20020 +                               setattr_copy(in, &attr);
20021 +                               mark_inode_dirty(in);
20022 +                       }
20023 +               }
20024 +       }
20025 +
20026 +out:
20027 +       mutex_unlock(&in->i_mutex);
20028 +       return error;
20029 +}
20030 +
20031 +int vc_set_iattr(void __user *data)
20032 +{
20033 +       struct path path;
20034 +       struct vcmd_ctx_iattr_v1 vc_data;
20035 +       int ret;
20036 +
20037 +       if (!capable(CAP_LINUX_IMMUTABLE))
20038 +               return -EPERM;
20039 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20040 +               return -EFAULT;
20041 +
20042 +       ret = user_lpath(vc_data.name, &path);
20043 +       if (!ret) {
20044 +               ret = __vc_set_iattr(path.dentry,
20045 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
20046 +               path_put(&path);
20047 +       }
20048 +
20049 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20050 +               ret = -EFAULT;
20051 +       return ret;
20052 +}
20053 +
20054 +#ifdef CONFIG_COMPAT
20055 +
20056 +int vc_set_iattr_x32(void __user *data)
20057 +{
20058 +       struct path path;
20059 +       struct vcmd_ctx_iattr_v1_x32 vc_data;
20060 +       int ret;
20061 +
20062 +       if (!capable(CAP_LINUX_IMMUTABLE))
20063 +               return -EPERM;
20064 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20065 +               return -EFAULT;
20066 +
20067 +       ret = user_lpath(compat_ptr(vc_data.name_ptr), &path);
20068 +       if (!ret) {
20069 +               ret = __vc_set_iattr(path.dentry,
20070 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
20071 +               path_put(&path);
20072 +       }
20073 +
20074 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20075 +               ret = -EFAULT;
20076 +       return ret;
20077 +}
20078 +
20079 +#endif /* CONFIG_COMPAT */
20080 +
20081 +int vc_fset_iattr(uint32_t fd, void __user *data)
20082 +{
20083 +       struct file *filp;
20084 +       struct vcmd_ctx_fiattr_v0 vc_data;
20085 +       int ret;
20086 +
20087 +       if (!capable(CAP_LINUX_IMMUTABLE))
20088 +               return -EPERM;
20089 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20090 +               return -EFAULT;
20091 +
20092 +       filp = fget(fd);
20093 +       if (!filp || !filp->f_dentry || !filp->f_dentry->d_inode)
20094 +               return -EBADF;
20095 +
20096 +       ret = __vc_set_iattr(filp->f_dentry, &vc_data.tag,
20097 +               &vc_data.flags, &vc_data.mask);
20098 +
20099 +       fput(filp);
20100 +
20101 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20102 +               return -EFAULT;
20103 +       return ret;
20104 +}
20105 +
20106 +
20107 +enum { Opt_notagcheck, Opt_tag, Opt_notag, Opt_tagid, Opt_err };
20108 +
20109 +static match_table_t tokens = {
20110 +       {Opt_notagcheck, "notagcheck"},
20111 +#ifdef CONFIG_PROPAGATE
20112 +       {Opt_notag, "notag"},
20113 +       {Opt_tag, "tag"},
20114 +       {Opt_tagid, "tagid=%u"},
20115 +#endif
20116 +       {Opt_err, NULL}
20117 +};
20118 +
20119 +
20120 +static void __dx_parse_remove(char *string, char *opt)
20121 +{
20122 +       char *p = strstr(string, opt);
20123 +       char *q = p;
20124 +
20125 +       if (p) {
20126 +               while (*q != '\0' && *q != ',')
20127 +                       q++;
20128 +               while (*q)
20129 +                       *p++ = *q++;
20130 +               while (*p)
20131 +                       *p++ = '\0';
20132 +       }
20133 +}
20134 +
20135 +int dx_parse_tag(char *string, tag_t *tag, int remove, int *mnt_flags,
20136 +                unsigned long *flags)
20137 +{
20138 +       int set = 0;
20139 +       substring_t args[MAX_OPT_ARGS];
20140 +       int token;
20141 +       char *s, *p, *opts;
20142 +#if defined(CONFIG_PROPAGATE) || defined(CONFIG_VSERVER_WARN)
20143 +       int option = 0;
20144 +#endif
20145 +
20146 +       if (!string)
20147 +               return 0;
20148 +       s = kstrdup(string, GFP_KERNEL | GFP_ATOMIC);
20149 +       if (!s)
20150 +               return 0;
20151 +
20152 +       opts = s;
20153 +       while ((p = strsep(&opts, ",")) != NULL) {
20154 +               token = match_token(p, tokens, args);
20155 +
20156 +               switch (token) {
20157 +#ifdef CONFIG_PROPAGATE
20158 +               case Opt_tag:
20159 +                       if (tag)
20160 +                               *tag = 0;
20161 +                       if (remove)
20162 +                               __dx_parse_remove(s, "tag");
20163 +                       *mnt_flags |= MNT_TAGID;
20164 +                       set |= MNT_TAGID;
20165 +                       break;
20166 +               case Opt_notag:
20167 +                       if (remove)
20168 +                               __dx_parse_remove(s, "notag");
20169 +                       *mnt_flags |= MNT_NOTAG;
20170 +                       set |= MNT_NOTAG;
20171 +                       break;
20172 +               case Opt_tagid:
20173 +                       if (tag && !match_int(args, &option))
20174 +                               *tag = option;
20175 +                       if (remove)
20176 +                               __dx_parse_remove(s, "tagid");
20177 +                       *mnt_flags |= MNT_TAGID;
20178 +                       set |= MNT_TAGID;
20179 +                       break;
20180 +#endif
20181 +               case Opt_notagcheck:
20182 +                       if (remove)
20183 +                               __dx_parse_remove(s, "notagcheck");
20184 +                       *flags |= MS_NOTAGCHECK;
20185 +                       set |= MS_NOTAGCHECK;
20186 +                       break;
20187 +               }
20188 +               vxdprintk(VXD_CBIT(tag, 7),
20189 +                       "dx_parse_tag(" VS_Q("%s") "): %d:#%d",
20190 +                       p, token, option);
20191 +       }
20192 +       if (set)
20193 +               strcpy(string, s);
20194 +       kfree(s);
20195 +       return set;
20196 +}
20197 +
20198 +#ifdef CONFIG_PROPAGATE
20199 +
20200 +void __dx_propagate_tag(struct nameidata *nd, struct inode *inode)
20201 +{
20202 +       tag_t new_tag = 0;
20203 +       struct vfsmount *mnt;
20204 +       int propagate;
20205 +
20206 +       if (!nd)
20207 +               return;
20208 +       mnt = nd->path.mnt;
20209 +       if (!mnt)
20210 +               return;
20211 +
20212 +       propagate = (mnt->mnt_flags & MNT_TAGID);
20213 +       if (propagate)
20214 +               new_tag = mnt->mnt_tag;
20215 +
20216 +       vxdprintk(VXD_CBIT(tag, 7),
20217 +               "dx_propagate_tag(%p[#%lu.%d]): %d,%d",
20218 +               inode, inode->i_ino, inode->i_tag,
20219 +               new_tag, (propagate) ? 1 : 0);
20220 +
20221 +       if (propagate)
20222 +               inode->i_tag = new_tag;
20223 +}
20224 +
20225 +#include <linux/module.h>
20226 +
20227 +EXPORT_SYMBOL_GPL(__dx_propagate_tag);
20228 +
20229 +#endif /* CONFIG_PROPAGATE */
20230 +
20231 diff -NurpP --minimal linux-2.6.38.1/kernel/vserver/limit.c linux-2.6.38.1-vs2.3.0.37-rc9/kernel/vserver/limit.c
20232 --- linux-2.6.38.1/kernel/vserver/limit.c       1970-01-01 01:00:00.000000000 +0100
20233 +++ linux-2.6.38.1-vs2.3.0.37-rc9/kernel/vserver/limit.c        2011-01-29 02:01:07.000000000 +0100
20234 @@ -0,0 +1,354 @@
20235 +/*
20236 + *  linux/kernel/vserver/limit.c
20237 + *
20238 + *  Virtual Server: Context Limits
20239 + *
20240 + *  Copyright (C) 2004-2010  Herbert Pötzl
20241 + *
20242 + *  V0.01  broken out from vcontext V0.05
20243 + *  V0.02  changed vcmds to vxi arg
20244 + *  V0.03  added memory cgroup support
20245 + *
20246 + */
20247 +
20248 +#include <linux/sched.h>
20249 +#include <linux/module.h>
20250 +#include <linux/memcontrol.h>
20251 +#include <linux/res_counter.h>
20252 +#include <linux/vs_limit.h>
20253 +#include <linux/vserver/limit.h>
20254 +#include <linux/vserver/limit_cmd.h>
20255 +
20256 +#include <asm/uaccess.h>
20257 +
20258 +
20259 +const char *vlimit_name[NUM_LIMITS] = {
20260 +#ifdef CONFIG_VSERVER_LEGACY_MEM
20261 +       [RLIMIT_RSS]            = "RSS",
20262 +       [RLIMIT_AS]             = "VM",
20263 +#endif /* CONFIG_VSERVER_LEGACY_MEM */
20264 +       [RLIMIT_CPU]            = "CPU",
20265 +       [RLIMIT_NPROC]          = "NPROC",
20266 +       [RLIMIT_NOFILE]         = "NOFILE",
20267 +       [RLIMIT_LOCKS]          = "LOCKS",
20268 +       [RLIMIT_SIGPENDING]     = "SIGP",
20269 +       [RLIMIT_MSGQUEUE]       = "MSGQ",
20270 +
20271 +       [VLIMIT_NSOCK]          = "NSOCK",
20272 +       [VLIMIT_OPENFD]         = "OPENFD",
20273 +       [VLIMIT_SHMEM]          = "SHMEM",
20274 +       [VLIMIT_DENTRY]         = "DENTRY",
20275 +};
20276 +
20277 +EXPORT_SYMBOL_GPL(vlimit_name);
20278 +
20279 +#define MASK_ENTRY(x)  (1 << (x))
20280 +
20281 +const struct vcmd_ctx_rlimit_mask_v0 vlimit_mask = {
20282 +               /* minimum */
20283 +       0
20284 +       ,       /* softlimit */
20285 +#ifdef CONFIG_VSERVER_LEGACY_MEM
20286 +       MASK_ENTRY( RLIMIT_RSS          ) |
20287 +#endif /* CONFIG_VSERVER_LEGACY_MEM */
20288 +       0
20289 +       ,       /* maximum */
20290 +#ifdef CONFIG_VSERVER_LEGACY_MEM
20291 +       MASK_ENTRY( RLIMIT_RSS          ) |
20292 +       MASK_ENTRY( RLIMIT_AS           ) |
20293 +#endif /* CONFIG_VSERVER_LEGACY_MEM */
20294 +       MASK_ENTRY( RLIMIT_NPROC        ) |
20295 +       MASK_ENTRY( RLIMIT_NOFILE       ) |
20296 +       MASK_ENTRY( RLIMIT_LOCKS        ) |
20297 +       MASK_ENTRY( RLIMIT_MSGQUEUE     ) |
20298 +
20299 +       MASK_ENTRY( VLIMIT_NSOCK        ) |
20300 +       MASK_ENTRY( VLIMIT_OPENFD       ) |
20301 +       MASK_ENTRY( VLIMIT_SHMEM        ) |
20302 +       MASK_ENTRY( VLIMIT_DENTRY       ) |
20303 +       0
20304 +};
20305 +               /* accounting only */
20306 +uint32_t account_mask =
20307 +       MASK_ENTRY( VLIMIT_SEMARY       ) |
20308 +       MASK_ENTRY( VLIMIT_NSEMS        ) |
20309 +       MASK_ENTRY( VLIMIT_MAPPED       ) |
20310 +       0;
20311 +
20312 +
20313 +static int is_valid_vlimit(int id)
20314 +{
20315 +       uint32_t mask = vlimit_mask.minimum |
20316 +               vlimit_mask.softlimit | vlimit_mask.maximum;
20317 +       return mask & (1 << id);
20318 +}
20319 +
20320 +static int is_accounted_vlimit(int id)
20321 +{
20322 +       if (is_valid_vlimit(id))
20323 +               return 1;
20324 +       return account_mask & (1 << id);
20325 +}
20326 +
20327 +
20328 +static inline uint64_t vc_get_soft(struct vx_info *vxi, int id)
20329 +{
20330 +       rlim_t limit = __rlim_soft(&vxi->limit, id);
20331 +       return VX_VLIM(limit);
20332 +}
20333 +
20334 +static inline uint64_t vc_get_hard(struct vx_info *vxi, int id)
20335 +{
20336 +       rlim_t limit = __rlim_hard(&vxi->limit, id);
20337 +       return VX_VLIM(limit);
20338 +}
20339 +
20340 +static int do_get_rlimit(struct vx_info *vxi, uint32_t id,
20341 +       uint64_t *minimum, uint64_t *softlimit, uint64_t *maximum)
20342 +{
20343 +       if (!is_valid_vlimit(id))
20344 +               return -EINVAL;
20345 +
20346 +       if (minimum)
20347 +               *minimum = CRLIM_UNSET;
20348 +       if (softlimit)
20349 +               *softlimit = vc_get_soft(vxi, id);
20350 +       if (maximum)
20351 +               *maximum = vc_get_hard(vxi, id);
20352 +       return 0;
20353 +}
20354 +
20355 +int vc_get_rlimit(struct vx_info *vxi, void __user *data)
20356 +{
20357 +       struct vcmd_ctx_rlimit_v0 vc_data;
20358 +       int ret;
20359 +
20360 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20361 +               return -EFAULT;
20362 +
20363 +       ret = do_get_rlimit(vxi, vc_data.id,
20364 +               &vc_data.minimum, &vc_data.softlimit, &vc_data.maximum);
20365 +       if (ret)
20366 +               return ret;
20367 +
20368 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20369 +               return -EFAULT;
20370 +       return 0;
20371 +}
20372 +
20373 +static int do_set_rlimit(struct vx_info *vxi, uint32_t id,
20374 +       uint64_t minimum, uint64_t softlimit, uint64_t maximum)
20375 +{
20376 +       if (!is_valid_vlimit(id))
20377 +               return -EINVAL;
20378 +
20379 +       if (maximum != CRLIM_KEEP)
20380 +               __rlim_hard(&vxi->limit, id) = VX_RLIM(maximum);
20381 +       if (softlimit != CRLIM_KEEP)
20382 +               __rlim_soft(&vxi->limit, id) = VX_RLIM(softlimit);
20383 +
20384 +       /* clamp soft limit */
20385 +       if (__rlim_soft(&vxi->limit, id) > __rlim_hard(&vxi->limit, id))
20386 +               __rlim_soft(&vxi->limit, id) = __rlim_hard(&vxi->limit, id);
20387 +
20388 +       return 0;
20389 +}
20390 +
20391 +int vc_set_rlimit(struct vx_info *vxi, void __user *data)
20392 +{
20393 +       struct vcmd_ctx_rlimit_v0 vc_data;
20394 +
20395 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20396 +               return -EFAULT;
20397 +
20398 +       return do_set_rlimit(vxi, vc_data.id,
20399 +               vc_data.minimum, vc_data.softlimit, vc_data.maximum);
20400 +}
20401 +
20402 +#ifdef CONFIG_IA32_EMULATION
20403 +
20404 +int vc_set_rlimit_x32(struct vx_info *vxi, void __user *data)
20405 +{
20406 +       struct vcmd_ctx_rlimit_v0_x32 vc_data;
20407 +
20408 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20409 +               return -EFAULT;
20410 +
20411 +       return do_set_rlimit(vxi, vc_data.id,
20412 +               vc_data.minimum, vc_data.softlimit, vc_data.maximum);
20413 +}
20414 +
20415 +int vc_get_rlimit_x32(struct vx_info *vxi, void __user *data)
20416 +{
20417 +       struct vcmd_ctx_rlimit_v0_x32 vc_data;
20418 +       int ret;
20419 +
20420 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20421 +               return -EFAULT;
20422 +
20423 +       ret = do_get_rlimit(vxi, vc_data.id,
20424 +               &vc_data.minimum, &vc_data.softlimit, &vc_data.maximum);
20425 +       if (ret)
20426 +               return ret;
20427 +
20428 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20429 +               return -EFAULT;
20430 +       return 0;
20431 +}
20432 +
20433 +#endif /* CONFIG_IA32_EMULATION */
20434 +
20435 +
20436 +int vc_get_rlimit_mask(uint32_t id, void __user *data)
20437 +{
20438 +       if (copy_to_user(data, &vlimit_mask, sizeof(vlimit_mask)))
20439 +               return -EFAULT;
20440 +       return 0;
20441 +}
20442 +
20443 +
20444 +static inline void vx_reset_hits(struct _vx_limit *limit)
20445 +{
20446 +       int lim;
20447 +
20448 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
20449 +               atomic_set(&__rlim_lhit(limit, lim), 0);
20450 +       }
20451 +}
20452 +
20453 +int vc_reset_hits(struct vx_info *vxi, void __user *data)
20454 +{
20455 +       vx_reset_hits(&vxi->limit);
20456 +       return 0;
20457 +}
20458 +
20459 +static inline void vx_reset_minmax(struct _vx_limit *limit)
20460 +{
20461 +       rlim_t value;
20462 +       int lim;
20463 +
20464 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
20465 +               value = __rlim_get(limit, lim);
20466 +               __rlim_rmax(limit, lim) = value;
20467 +               __rlim_rmin(limit, lim) = value;
20468 +       }
20469 +}
20470 +
20471 +int vc_reset_minmax(struct vx_info *vxi, void __user *data)
20472 +{
20473 +       vx_reset_minmax(&vxi->limit);
20474 +       return 0;
20475 +}
20476 +
20477 +
20478 +int vc_rlimit_stat(struct vx_info *vxi, void __user *data)
20479 +{
20480 +       struct vcmd_rlimit_stat_v0 vc_data;
20481 +       struct _vx_limit *limit = &vxi->limit;
20482 +       int id;
20483 +
20484 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20485 +               return -EFAULT;
20486 +
20487 +       id = vc_data.id;
20488 +       if (!is_accounted_vlimit(id))
20489 +               return -EINVAL;
20490 +
20491 +       vx_limit_fixup(limit, id);
20492 +       vc_data.hits = atomic_read(&__rlim_lhit(limit, id));
20493 +       vc_data.value = __rlim_get(limit, id);
20494 +       vc_data.minimum = __rlim_rmin(limit, id);
20495 +       vc_data.maximum = __rlim_rmax(limit, id);
20496 +
20497 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20498 +               return -EFAULT;
20499 +       return 0;
20500 +}
20501 +
20502 +
20503 +void vx_vsi_meminfo(struct sysinfo *val)
20504 +{
20505 +#ifdef CONFIG_CGROUP_MEM_RES_CTLR
20506 +       struct mem_cgroup *mcg = mem_cgroup_from_task(current);
20507 +       u64 res_limit, res_usage;
20508 +
20509 +       if (!mcg)
20510 +               return;
20511 +
20512 +       res_limit = mem_cgroup_res_read_u64(mcg, RES_LIMIT);
20513 +       res_usage = mem_cgroup_res_read_u64(mcg, RES_USAGE);
20514 +
20515 +       if (res_limit != RESOURCE_MAX)
20516 +               val->totalram = (res_limit >> PAGE_SHIFT);
20517 +       val->freeram = val->totalram - (res_usage >> PAGE_SHIFT);
20518 +       val->bufferram = 0;
20519 +       val->totalhigh = 0;
20520 +       val->freehigh = 0;
20521 +#endif /* CONFIG_CGROUP_MEM_RES_CTLR */
20522 +       return;
20523 +}
20524 +
20525 +void vx_vsi_swapinfo(struct sysinfo *val)
20526 +{
20527 +#ifdef CONFIG_CGROUP_MEM_RES_CTLR
20528 +#ifdef CONFIG_CGROUP_MEM_RES_CTLR_SWAP
20529 +       struct mem_cgroup *mcg = mem_cgroup_from_task(current);
20530 +       u64 res_limit, res_usage, memsw_limit, memsw_usage;
20531 +       s64 swap_limit, swap_usage;
20532 +
20533 +       if (!mcg)
20534 +               return;
20535 +
20536 +       res_limit = mem_cgroup_res_read_u64(mcg, RES_LIMIT);
20537 +       res_usage = mem_cgroup_res_read_u64(mcg, RES_USAGE);
20538 +       memsw_limit = mem_cgroup_memsw_read_u64(mcg, RES_LIMIT);
20539 +       memsw_usage = mem_cgroup_memsw_read_u64(mcg, RES_USAGE);
20540 +
20541 +       if (res_limit == RESOURCE_MAX)
20542 +               return;
20543 +
20544 +       swap_limit = memsw_limit - res_limit;
20545 +       if (memsw_limit != RESOURCE_MAX)
20546 +               val->totalswap = swap_limit >> PAGE_SHIFT;
20547 +
20548 +       swap_usage = memsw_usage - res_usage;
20549 +       val->freeswap = (swap_usage < swap_limit) ?
20550 +               val->totalswap - (swap_usage >> PAGE_SHIFT) : 0;
20551 +#else  /* !CONFIG_CGROUP_MEM_RES_CTLR_SWAP */
20552 +       val->totalswap = 0;
20553 +       val->freeswap = 0;
20554 +#endif /* !CONFIG_CGROUP_MEM_RES_CTLR_SWAP */
20555 +#endif /* CONFIG_CGROUP_MEM_RES_CTLR */
20556 +       return;
20557 +}
20558 +
20559 +long vx_vsi_cached(struct sysinfo *val)
20560 +{
20561 +#ifdef CONFIG_CGROUP_MEM_RES_CTLR
20562 +       struct mem_cgroup *mcg = mem_cgroup_from_task(current);
20563 +
20564 +       return mem_cgroup_stat_read_cache(mcg);
20565 +#else
20566 +       return 0;
20567 +#endif
20568 +}
20569 +
20570 +
20571 +unsigned long vx_badness(struct task_struct *task, struct mm_struct *mm)
20572 +{
20573 +       struct vx_info *vxi = mm->mm_vx_info;
20574 +       unsigned long points;
20575 +       rlim_t v, w;
20576 +
20577 +       if (!vxi)
20578 +               return 0;
20579 +
20580 +       points = vxi->vx_badness_bias;
20581 +
20582 +       v = __vx_cres_array_fixup(&vxi->limit, VLA_RSS);
20583 +       w = __rlim_soft(&vxi->limit, RLIMIT_RSS);
20584 +       points += (v > w) ? (v - w) : 0;
20585 +
20586 +       return points;
20587 +}
20588 +
20589 diff -NurpP --minimal linux-2.6.38.1/kernel/vserver/limit_init.h linux-2.6.38.1-vs2.3.0.37-rc9/kernel/vserver/limit_init.h
20590 --- linux-2.6.38.1/kernel/vserver/limit_init.h  1970-01-01 01:00:00.000000000 +0100
20591 +++ linux-2.6.38.1-vs2.3.0.37-rc9/kernel/vserver/limit_init.h   2011-01-29 02:01:07.000000000 +0100
20592 @@ -0,0 +1,31 @@
20593 +
20594 +
20595 +static inline void vx_info_init_limit(struct _vx_limit *limit)
20596 +{
20597 +       int lim;
20598 +
20599 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
20600 +               __rlim_soft(limit, lim) = RLIM_INFINITY;
20601 +               __rlim_hard(limit, lim) = RLIM_INFINITY;
20602 +               __rlim_set(limit, lim, 0);
20603 +               atomic_set(&__rlim_lhit(limit, lim), 0);
20604 +               __rlim_rmin(limit, lim) = 0;
20605 +               __rlim_rmax(limit, lim) = 0;
20606 +       }
20607 +}
20608 +
20609 +static inline void vx_info_exit_limit(struct _vx_limit *limit)
20610 +{
20611 +       rlim_t value;
20612 +       int lim;
20613 +
20614 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
20615 +               if ((1 << lim) & VLIM_NOCHECK)
20616 +                       continue;
20617 +               value = __rlim_get(limit, lim);
20618 +               vxwprintk_xid(value,
20619 +                       "!!! limit: %p[%s,%d] = %ld on exit.",
20620 +                       limit, vlimit_name[lim], lim, (long)value);
20621 +       }
20622 +}
20623 +
20624 diff -NurpP --minimal linux-2.6.38.1/kernel/vserver/limit_proc.h linux-2.6.38.1-vs2.3.0.37-rc9/kernel/vserver/limit_proc.h
20625 --- linux-2.6.38.1/kernel/vserver/limit_proc.h  1970-01-01 01:00:00.000000000 +0100
20626 +++ linux-2.6.38.1-vs2.3.0.37-rc9/kernel/vserver/limit_proc.h   2011-01-29 02:01:07.000000000 +0100
20627 @@ -0,0 +1,57 @@
20628 +#ifndef _VX_LIMIT_PROC_H
20629 +#define _VX_LIMIT_PROC_H
20630 +
20631 +#include <linux/vserver/limit_int.h>
20632 +
20633 +
20634 +#define VX_LIMIT_FMT   ":\t%8ld\t%8ld/%8ld\t%8lld/%8lld\t%6d\n"
20635 +#define VX_LIMIT_TOP   \
20636 +       "Limit\t current\t     min/max\t\t    soft/hard\t\thits\n"
20637 +
20638 +#define VX_LIMIT_ARG(r)                                \
20639 +       (unsigned long)__rlim_get(limit, r),    \
20640 +       (unsigned long)__rlim_rmin(limit, r),   \
20641 +       (unsigned long)__rlim_rmax(limit, r),   \
20642 +       VX_VLIM(__rlim_soft(limit, r)),         \
20643 +       VX_VLIM(__rlim_hard(limit, r)),         \
20644 +       atomic_read(&__rlim_lhit(limit, r))
20645 +
20646 +static inline int vx_info_proc_limit(struct _vx_limit *limit, char *buffer)
20647 +{
20648 +       vx_limit_fixup(limit, -1);
20649 +       return sprintf(buffer, VX_LIMIT_TOP
20650 +               "PROC"  VX_LIMIT_FMT
20651 +               "VM"    VX_LIMIT_FMT
20652 +               "VML"   VX_LIMIT_FMT
20653 +               "RSS"   VX_LIMIT_FMT
20654 +               "ANON"  VX_LIMIT_FMT
20655 +               "RMAP"  VX_LIMIT_FMT
20656 +               "FILES" VX_LIMIT_FMT
20657 +               "OFD"   VX_LIMIT_FMT
20658 +               "LOCKS" VX_LIMIT_FMT
20659 +               "SOCK"  VX_LIMIT_FMT
20660 +               "MSGQ"  VX_LIMIT_FMT
20661 +               "SHM"   VX_LIMIT_FMT
20662 +               "SEMA"  VX_LIMIT_FMT
20663 +               "SEMS"  VX_LIMIT_FMT
20664 +               "DENT"  VX_LIMIT_FMT,
20665 +               VX_LIMIT_ARG(RLIMIT_NPROC),
20666 +               VX_LIMIT_ARG(RLIMIT_AS),
20667 +               VX_LIMIT_ARG(RLIMIT_MEMLOCK),
20668 +               VX_LIMIT_ARG(RLIMIT_RSS),
20669 +               VX_LIMIT_ARG(VLIMIT_ANON),
20670 +               VX_LIMIT_ARG(VLIMIT_MAPPED),
20671 +               VX_LIMIT_ARG(RLIMIT_NOFILE),
20672 +               VX_LIMIT_ARG(VLIMIT_OPENFD),
20673 +               VX_LIMIT_ARG(RLIMIT_LOCKS),
20674 +               VX_LIMIT_ARG(VLIMIT_NSOCK),
20675 +               VX_LIMIT_ARG(RLIMIT_MSGQUEUE),
20676 +               VX_LIMIT_ARG(VLIMIT_SHMEM),
20677 +               VX_LIMIT_ARG(VLIMIT_SEMARY),
20678 +               VX_LIMIT_ARG(VLIMIT_NSEMS),
20679 +               VX_LIMIT_ARG(VLIMIT_DENTRY));
20680 +}
20681 +
20682 +#endif /* _VX_LIMIT_PROC_H */
20683 +
20684 +
20685 diff -NurpP --minimal linux-2.6.38.1/kernel/vserver/network.c linux-2.6.38.1-vs2.3.0.37-rc9/kernel/vserver/network.c
20686 --- linux-2.6.38.1/kernel/vserver/network.c     1970-01-01 01:00:00.000000000 +0100
20687 +++ linux-2.6.38.1-vs2.3.0.37-rc9/kernel/vserver/network.c      2011-03-22 17:36:23.000000000 +0100
20688 @@ -0,0 +1,864 @@
20689 +/*
20690 + *  linux/kernel/vserver/network.c
20691 + *
20692 + *  Virtual Server: Network Support
20693 + *
20694 + *  Copyright (C) 2003-2007  Herbert Pötzl
20695 + *
20696 + *  V0.01  broken out from vcontext V0.05
20697 + *  V0.02  cleaned up implementation
20698 + *  V0.03  added equiv nx commands
20699 + *  V0.04  switch to RCU based hash
20700 + *  V0.05  and back to locking again
20701 + *  V0.06  changed vcmds to nxi arg
20702 + *  V0.07  have __create claim() the nxi
20703 + *
20704 + */
20705 +
20706 +#include <linux/err.h>
20707 +#include <linux/slab.h>
20708 +#include <linux/rcupdate.h>
20709 +
20710 +#include <linux/vs_network.h>
20711 +#include <linux/vs_pid.h>
20712 +#include <linux/vserver/network_cmd.h>
20713 +
20714 +
20715 +atomic_t nx_global_ctotal      = ATOMIC_INIT(0);
20716 +atomic_t nx_global_cactive     = ATOMIC_INIT(0);
20717 +
20718 +static struct kmem_cache *nx_addr_v4_cachep = NULL;
20719 +static struct kmem_cache *nx_addr_v6_cachep = NULL;
20720 +
20721 +
20722 +static int __init init_network(void)
20723 +{
20724 +       nx_addr_v4_cachep = kmem_cache_create("nx_v4_addr_cache",
20725 +               sizeof(struct nx_addr_v4), 0,
20726 +               SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
20727 +       nx_addr_v6_cachep = kmem_cache_create("nx_v6_addr_cache",
20728 +               sizeof(struct nx_addr_v6), 0,
20729 +               SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
20730 +       return 0;
20731 +}
20732 +
20733 +
20734 +/*     __alloc_nx_addr_v4()                                    */
20735 +
20736 +static inline struct nx_addr_v4 *__alloc_nx_addr_v4(void)
20737 +{
20738 +       struct nx_addr_v4 *nxa = kmem_cache_alloc(
20739 +               nx_addr_v4_cachep, GFP_KERNEL);
20740 +
20741 +       if (!IS_ERR(nxa))
20742 +               memset(nxa, 0, sizeof(*nxa));
20743 +       return nxa;
20744 +}
20745 +
20746 +/*     __dealloc_nx_addr_v4()                                  */
20747 +
20748 +static inline void __dealloc_nx_addr_v4(struct nx_addr_v4 *nxa)
20749 +{
20750 +       kmem_cache_free(nx_addr_v4_cachep, nxa);
20751 +}
20752 +
20753 +/*     __dealloc_nx_addr_v4_all()                              */
20754 +
20755 +static inline void __dealloc_nx_addr_v4_all(struct nx_addr_v4 *nxa)
20756 +{
20757 +       while (nxa) {
20758 +               struct nx_addr_v4 *next = nxa->next;
20759 +
20760 +               __dealloc_nx_addr_v4(nxa);
20761 +               nxa = next;
20762 +       }
20763 +}
20764 +
20765 +
20766 +#ifdef CONFIG_IPV6
20767 +
20768 +/*     __alloc_nx_addr_v6()                                    */
20769 +
20770 +static inline struct nx_addr_v6 *__alloc_nx_addr_v6(void)
20771 +{
20772 +       struct nx_addr_v6 *nxa = kmem_cache_alloc(
20773 +               nx_addr_v6_cachep, GFP_KERNEL);
20774 +
20775 +       if (!IS_ERR(nxa))
20776 +               memset(nxa, 0, sizeof(*nxa));
20777 +       return nxa;
20778 +}
20779 +
20780 +/*     __dealloc_nx_addr_v6()                                  */
20781 +
20782 +static inline void __dealloc_nx_addr_v6(struct nx_addr_v6 *nxa)
20783 +{
20784 +       kmem_cache_free(nx_addr_v6_cachep, nxa);
20785 +}
20786 +
20787 +/*     __dealloc_nx_addr_v6_all()                              */
20788 +
20789 +static inline void __dealloc_nx_addr_v6_all(struct nx_addr_v6 *nxa)
20790 +{
20791 +       while (nxa) {
20792 +               struct nx_addr_v6 *next = nxa->next;
20793 +
20794 +               __dealloc_nx_addr_v6(nxa);
20795 +               nxa = next;
20796 +       }
20797 +}
20798 +
20799 +#endif /* CONFIG_IPV6 */
20800 +
20801 +/*     __alloc_nx_info()
20802 +
20803 +       * allocate an initialized nx_info struct
20804 +       * doesn't make it visible (hash)                        */
20805 +
20806 +static struct nx_info *__alloc_nx_info(nid_t nid)
20807 +{
20808 +       struct nx_info *new = NULL;
20809 +
20810 +       vxdprintk(VXD_CBIT(nid, 1), "alloc_nx_info(%d)*", nid);
20811 +
20812 +       /* would this benefit from a slab cache? */
20813 +       new = kmalloc(sizeof(struct nx_info), GFP_KERNEL);
20814 +       if (!new)
20815 +               return 0;
20816 +
20817 +       memset(new, 0, sizeof(struct nx_info));
20818 +       new->nx_id = nid;
20819 +       INIT_HLIST_NODE(&new->nx_hlist);
20820 +       atomic_set(&new->nx_usecnt, 0);
20821 +       atomic_set(&new->nx_tasks, 0);
20822 +       new->nx_state = 0;
20823 +
20824 +       new->nx_flags = NXF_INIT_SET;
20825 +
20826 +       /* rest of init goes here */
20827 +
20828 +       new->v4_lback.s_addr = htonl(INADDR_LOOPBACK);
20829 +       new->v4_bcast.s_addr = htonl(INADDR_BROADCAST);
20830 +
20831 +       vxdprintk(VXD_CBIT(nid, 0),
20832 +               "alloc_nx_info(%d) = %p", nid, new);
20833 +       atomic_inc(&nx_global_ctotal);
20834 +       return new;
20835 +}
20836 +
20837 +/*     __dealloc_nx_info()
20838 +
20839 +       * final disposal of nx_info                             */
20840 +
20841 +static void __dealloc_nx_info(struct nx_info *nxi)
20842 +{
20843 +       vxdprintk(VXD_CBIT(nid, 0),
20844 +               "dealloc_nx_info(%p)", nxi);
20845 +
20846 +       nxi->nx_hlist.next = LIST_POISON1;
20847 +       nxi->nx_id = -1;
20848 +
20849 +       BUG_ON(atomic_read(&nxi->nx_usecnt));
20850 +       BUG_ON(atomic_read(&nxi->nx_tasks));
20851 +
20852 +       __dealloc_nx_addr_v4_all(nxi->v4.next);
20853 +
20854 +       nxi->nx_state |= NXS_RELEASED;
20855 +       kfree(nxi);
20856 +       atomic_dec(&nx_global_ctotal);
20857 +}
20858 +
20859 +static void __shutdown_nx_info(struct nx_info *nxi)
20860 +{
20861 +       nxi->nx_state |= NXS_SHUTDOWN;
20862 +       vs_net_change(nxi, VSC_NETDOWN);
20863 +}
20864 +
20865 +/*     exported stuff                                          */
20866 +
20867 +void free_nx_info(struct nx_info *nxi)
20868 +{
20869 +       /* context shutdown is mandatory */
20870 +       BUG_ON(nxi->nx_state != NXS_SHUTDOWN);
20871 +
20872 +       /* context must not be hashed */
20873 +       BUG_ON(nxi->nx_state & NXS_HASHED);
20874 +
20875 +       BUG_ON(atomic_read(&nxi->nx_usecnt));
20876 +       BUG_ON(atomic_read(&nxi->nx_tasks));
20877 +
20878 +       __dealloc_nx_info(nxi);
20879 +}
20880 +
20881 +
20882 +void __nx_set_lback(struct nx_info *nxi)
20883 +{
20884 +       int nid = nxi->nx_id;
20885 +       __be32 lback = htonl(INADDR_LOOPBACK ^ ((nid & 0xFFFF) << 8));
20886 +
20887 +       nxi->v4_lback.s_addr = lback;
20888 +}
20889 +
20890 +extern int __nx_inet_add_lback(__be32 addr);
20891 +extern int __nx_inet_del_lback(__be32 addr);
20892 +
20893 +
20894 +/*     hash table for nx_info hash */
20895 +
20896 +#define NX_HASH_SIZE   13
20897 +
20898 +struct hlist_head nx_info_hash[NX_HASH_SIZE];
20899 +
20900 +static spinlock_t nx_info_hash_lock = SPIN_LOCK_UNLOCKED;
20901 +
20902 +
20903 +static inline unsigned int __hashval(nid_t nid)
20904 +{
20905 +       return (nid % NX_HASH_SIZE);
20906 +}
20907 +
20908 +
20909 +
20910 +/*     __hash_nx_info()
20911 +
20912 +       * add the nxi to the global hash table
20913 +       * requires the hash_lock to be held                     */
20914 +
20915 +static inline void __hash_nx_info(struct nx_info *nxi)
20916 +{
20917 +       struct hlist_head *head;
20918 +
20919 +       vxd_assert_lock(&nx_info_hash_lock);
20920 +       vxdprintk(VXD_CBIT(nid, 4),
20921 +               "__hash_nx_info: %p[#%d]", nxi, nxi->nx_id);
20922 +
20923 +       /* context must not be hashed */
20924 +       BUG_ON(nx_info_state(nxi, NXS_HASHED));
20925 +
20926 +       nxi->nx_state |= NXS_HASHED;
20927 +       head = &nx_info_hash[__hashval(nxi->nx_id)];
20928 +       hlist_add_head(&nxi->nx_hlist, head);
20929 +       atomic_inc(&nx_global_cactive);
20930 +}
20931 +
20932 +/*     __unhash_nx_info()
20933 +
20934 +       * remove the nxi from the global hash table
20935 +       * requires the hash_lock to be held                     */
20936 +
20937 +static inline void __unhash_nx_info(struct nx_info *nxi)
20938 +{
20939 +       vxd_assert_lock(&nx_info_hash_lock);
20940 +       vxdprintk(VXD_CBIT(nid, 4),
20941 +               "__unhash_nx_info: %p[#%d.%d.%d]", nxi, nxi->nx_id,
20942 +               atomic_read(&nxi->nx_usecnt), atomic_read(&nxi->nx_tasks));
20943 +
20944 +       /* context must be hashed */
20945 +       BUG_ON(!nx_info_state(nxi, NXS_HASHED));
20946 +       /* but without tasks */
20947 +       BUG_ON(atomic_read(&nxi->nx_tasks));
20948 +
20949 +       nxi->nx_state &= ~NXS_HASHED;
20950 +       hlist_del(&nxi->nx_hlist);
20951 +       atomic_dec(&nx_global_cactive);
20952 +}
20953 +
20954 +
20955 +/*     __lookup_nx_info()
20956 +
20957 +       * requires the hash_lock to be held
20958 +       * doesn't increment the nx_refcnt                       */
20959 +
20960 +static inline struct nx_info *__lookup_nx_info(nid_t nid)
20961 +{
20962 +       struct hlist_head *head = &nx_info_hash[__hashval(nid)];
20963 +       struct hlist_node *pos;
20964 +       struct nx_info *nxi;
20965 +
20966 +       vxd_assert_lock(&nx_info_hash_lock);
20967 +       hlist_for_each(pos, head) {
20968 +               nxi = hlist_entry(pos, struct nx_info, nx_hlist);
20969 +
20970 +               if (nxi->nx_id == nid)
20971 +                       goto found;
20972 +       }
20973 +       nxi = NULL;
20974 +found:
20975 +       vxdprintk(VXD_CBIT(nid, 0),
20976 +               "__lookup_nx_info(#%u): %p[#%u]",
20977 +               nid, nxi, nxi ? nxi->nx_id : 0);
20978 +       return nxi;
20979 +}
20980 +
20981 +
20982 +/*     __create_nx_info()
20983 +
20984 +       * create the requested context
20985 +       * get(), claim() and hash it                            */
20986 +
20987 +static struct nx_info *__create_nx_info(int id)
20988 +{
20989 +       struct nx_info *new, *nxi = NULL;
20990 +
20991 +       vxdprintk(VXD_CBIT(nid, 1), "create_nx_info(%d)*", id);
20992 +
20993 +       if (!(new = __alloc_nx_info(id)))
20994 +               return ERR_PTR(-ENOMEM);
20995 +
20996 +       /* required to make dynamic xids unique */
20997 +       spin_lock(&nx_info_hash_lock);
20998 +
20999 +       /* static context requested */
21000 +       if ((nxi = __lookup_nx_info(id))) {
21001 +               vxdprintk(VXD_CBIT(nid, 0),
21002 +                       "create_nx_info(%d) = %p (already there)", id, nxi);
21003 +               if (nx_info_flags(nxi, NXF_STATE_SETUP, 0))
21004 +                       nxi = ERR_PTR(-EBUSY);
21005 +               else
21006 +                       nxi = ERR_PTR(-EEXIST);
21007 +               goto out_unlock;
21008 +       }
21009 +       /* new context */
21010 +       vxdprintk(VXD_CBIT(nid, 0),
21011 +               "create_nx_info(%d) = %p (new)", id, new);
21012 +       claim_nx_info(new, NULL);
21013 +       __nx_set_lback(new);
21014 +       __hash_nx_info(get_nx_info(new));
21015 +       nxi = new, new = NULL;
21016 +
21017 +out_unlock:
21018 +       spin_unlock(&nx_info_hash_lock);
21019 +       if (new)
21020 +               __dealloc_nx_info(new);
21021 +       return nxi;
21022 +}
21023 +
21024 +
21025 +
21026 +/*     exported stuff                                          */
21027 +
21028 +
21029 +void unhash_nx_info(struct nx_info *nxi)
21030 +{
21031 +       __shutdown_nx_info(nxi);
21032 +       spin_lock(&nx_info_hash_lock);
21033 +       __unhash_nx_info(nxi);
21034 +       spin_unlock(&nx_info_hash_lock);
21035 +}
21036 +
21037 +/*     lookup_nx_info()
21038 +
21039 +       * search for a nx_info and get() it
21040 +       * negative id means current                             */
21041 +
21042 +struct nx_info *lookup_nx_info(int id)
21043 +{
21044 +       struct nx_info *nxi = NULL;
21045 +
21046 +       if (id < 0) {
21047 +               nxi = get_nx_info(current_nx_info());
21048 +       } else if (id > 1) {
21049 +               spin_lock(&nx_info_hash_lock);
21050 +               nxi = get_nx_info(__lookup_nx_info(id));
21051 +               spin_unlock(&nx_info_hash_lock);
21052 +       }
21053 +       return nxi;
21054 +}
21055 +
21056 +/*     nid_is_hashed()
21057 +
21058 +       * verify that nid is still hashed                       */
21059 +
21060 +int nid_is_hashed(nid_t nid)
21061 +{
21062 +       int hashed;
21063 +
21064 +       spin_lock(&nx_info_hash_lock);
21065 +       hashed = (__lookup_nx_info(nid) != NULL);
21066 +       spin_unlock(&nx_info_hash_lock);
21067 +       return hashed;
21068 +}
21069 +
21070 +
21071 +#ifdef CONFIG_PROC_FS
21072 +
21073 +/*     get_nid_list()
21074 +
21075 +       * get a subset of hashed nids for proc
21076 +       * assumes size is at least one                          */
21077 +
21078 +int get_nid_list(int index, unsigned int *nids, int size)
21079 +{
21080 +       int hindex, nr_nids = 0;
21081 +
21082 +       /* only show current and children */
21083 +       if (!nx_check(0, VS_ADMIN | VS_WATCH)) {
21084 +               if (index > 0)
21085 +                       return 0;
21086 +               nids[nr_nids] = nx_current_nid();
21087 +               return 1;
21088 +       }
21089 +
21090 +       for (hindex = 0; hindex < NX_HASH_SIZE; hindex++) {
21091 +               struct hlist_head *head = &nx_info_hash[hindex];
21092 +               struct hlist_node *pos;
21093 +
21094 +               spin_lock(&nx_info_hash_lock);
21095 +               hlist_for_each(pos, head) {
21096 +                       struct nx_info *nxi;
21097 +
21098 +                       if (--index > 0)
21099 +                               continue;
21100 +
21101 +                       nxi = hlist_entry(pos, struct nx_info, nx_hlist);
21102 +                       nids[nr_nids] = nxi->nx_id;
21103 +                       if (++nr_nids >= size) {
21104 +                               spin_unlock(&nx_info_hash_lock);
21105 +                               goto out;
21106 +                       }
21107 +               }
21108 +               /* keep the lock time short */
21109 +               spin_unlock(&nx_info_hash_lock);
21110 +       }
21111 +out:
21112 +       return nr_nids;
21113 +}
21114 +#endif
21115 +
21116 +
21117 +/*
21118 + *     migrate task to new network
21119 + *     gets nxi, puts old_nxi on change
21120 + */
21121 +
21122 +int nx_migrate_task(struct task_struct *p, struct nx_info *nxi)
21123 +{
21124 +       struct nx_info *old_nxi;
21125 +       int ret = 0;
21126 +
21127 +       if (!p || !nxi)
21128 +               BUG();
21129 +
21130 +       vxdprintk(VXD_CBIT(nid, 5),
21131 +               "nx_migrate_task(%p,%p[#%d.%d.%d])",
21132 +               p, nxi, nxi->nx_id,
21133 +               atomic_read(&nxi->nx_usecnt),
21134 +               atomic_read(&nxi->nx_tasks));
21135 +
21136 +       if (nx_info_flags(nxi, NXF_INFO_PRIVATE, 0) &&
21137 +               !nx_info_flags(nxi, NXF_STATE_SETUP, 0))
21138 +               return -EACCES;
21139 +
21140 +       if (nx_info_state(nxi, NXS_SHUTDOWN))
21141 +               return -EFAULT;
21142 +
21143 +       /* maybe disallow this completely? */
21144 +       old_nxi = task_get_nx_info(p);
21145 +       if (old_nxi == nxi)
21146 +               goto out;
21147 +
21148 +       task_lock(p);
21149 +       if (old_nxi)
21150 +               clr_nx_info(&p->nx_info);
21151 +       claim_nx_info(nxi, p);
21152 +       set_nx_info(&p->nx_info, nxi);
21153 +       p->nid = nxi->nx_id;
21154 +       task_unlock(p);
21155 +
21156 +       vxdprintk(VXD_CBIT(nid, 5),
21157 +               "moved task %p into nxi:%p[#%d]",
21158 +               p, nxi, nxi->nx_id);
21159 +
21160 +       if (old_nxi)
21161 +               release_nx_info(old_nxi, p);
21162 +       ret = 0;
21163 +out:
21164 +       put_nx_info(old_nxi);
21165 +       return ret;
21166 +}
21167 +
21168 +
21169 +void nx_set_persistent(struct nx_info *nxi)
21170 +{
21171 +       vxdprintk(VXD_CBIT(nid, 6),
21172 +               "nx_set_persistent(%p[#%d])", nxi, nxi->nx_id);
21173 +
21174 +       get_nx_info(nxi);
21175 +       claim_nx_info(nxi, NULL);
21176 +}
21177 +
21178 +void nx_clear_persistent(struct nx_info *nxi)
21179 +{
21180 +       vxdprintk(VXD_CBIT(nid, 6),
21181 +               "nx_clear_persistent(%p[#%d])", nxi, nxi->nx_id);
21182 +
21183 +       release_nx_info(nxi, NULL);
21184 +       put_nx_info(nxi);
21185 +}
21186 +
21187 +void nx_update_persistent(struct nx_info *nxi)
21188 +{
21189 +       if (nx_info_flags(nxi, NXF_PERSISTENT, 0))
21190 +               nx_set_persistent(nxi);
21191 +       else
21192 +               nx_clear_persistent(nxi);
21193 +}
21194 +
21195 +/* vserver syscall commands below here */
21196 +
21197 +/* taks nid and nx_info functions */
21198 +
21199 +#include <asm/uaccess.h>
21200 +
21201 +
21202 +int vc_task_nid(uint32_t id)
21203 +{
21204 +       nid_t nid;
21205 +
21206 +       if (id) {
21207 +               struct task_struct *tsk;
21208 +
21209 +               rcu_read_lock();
21210 +               tsk = find_task_by_real_pid(id);
21211 +               nid = (tsk) ? tsk->nid : -ESRCH;
21212 +               rcu_read_unlock();
21213 +       } else
21214 +               nid = nx_current_nid();
21215 +       return nid;
21216 +}
21217 +
21218 +
21219 +int vc_nx_info(struct nx_info *nxi, void __user *data)
21220 +{
21221 +       struct vcmd_nx_info_v0 vc_data;
21222 +
21223 +       vc_data.nid = nxi->nx_id;
21224 +
21225 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21226 +               return -EFAULT;
21227 +       return 0;
21228 +}
21229 +
21230 +
21231 +/* network functions */
21232 +
21233 +int vc_net_create(uint32_t nid, void __user *data)
21234 +{
21235 +       struct vcmd_net_create vc_data = { .flagword = NXF_INIT_SET };
21236 +       struct nx_info *new_nxi;
21237 +       int ret;
21238 +
21239 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
21240 +               return -EFAULT;
21241 +
21242 +       if ((nid > MAX_S_CONTEXT) || (nid < 2))
21243 +               return -EINVAL;
21244 +
21245 +       new_nxi = __create_nx_info(nid);
21246 +       if (IS_ERR(new_nxi))
21247 +               return PTR_ERR(new_nxi);
21248 +
21249 +       /* initial flags */
21250 +       new_nxi->nx_flags = vc_data.flagword;
21251 +
21252 +       ret = -ENOEXEC;
21253 +       if (vs_net_change(new_nxi, VSC_NETUP))
21254 +               goto out;
21255 +
21256 +       ret = nx_migrate_task(current, new_nxi);
21257 +       if (ret)
21258 +               goto out;
21259 +
21260 +       /* return context id on success */
21261 +       ret = new_nxi->nx_id;
21262 +
21263 +       /* get a reference for persistent contexts */
21264 +       if ((vc_data.flagword & NXF_PERSISTENT))
21265 +               nx_set_persistent(new_nxi);
21266 +out:
21267 +       release_nx_info(new_nxi, NULL);
21268 +       put_nx_info(new_nxi);
21269 +       return ret;
21270 +}
21271 +
21272 +
21273 +int vc_net_migrate(struct nx_info *nxi, void __user *data)
21274 +{
21275 +       return nx_migrate_task(current, nxi);
21276 +}
21277 +
21278 +
21279 +
21280 +int do_add_v4_addr(struct nx_info *nxi, __be32 ip, __be32 ip2, __be32 mask,
21281 +       uint16_t type, uint16_t flags)
21282 +{
21283 +       struct nx_addr_v4 *nxa = &nxi->v4;
21284 +
21285 +       if (NX_IPV4(nxi)) {
21286 +               /* locate last entry */
21287 +               for (; nxa->next; nxa = nxa->next);
21288 +               nxa->next = __alloc_nx_addr_v4();
21289 +               nxa = nxa->next;
21290 +
21291 +               if (IS_ERR(nxa))
21292 +                       return PTR_ERR(nxa);
21293 +       }
21294 +
21295 +       if (nxi->v4.next)
21296 +               /* remove single ip for ip list */
21297 +               nxi->nx_flags &= ~NXF_SINGLE_IP;
21298 +
21299 +       nxa->ip[0].s_addr = ip;
21300 +       nxa->ip[1].s_addr = ip2;
21301 +       nxa->mask.s_addr = mask;
21302 +       nxa->type = type;
21303 +       nxa->flags = flags;
21304 +       return 0;
21305 +}
21306 +
21307 +
21308 +int vc_net_add(struct nx_info *nxi, void __user *data)
21309 +{
21310 +       struct vcmd_net_addr_v0 vc_data;
21311 +       int index, ret = 0;
21312 +
21313 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
21314 +               return -EFAULT;
21315 +
21316 +       switch (vc_data.type) {
21317 +       case NXA_TYPE_IPV4:
21318 +               if ((vc_data.count < 1) || (vc_data.count > 4))
21319 +                       return -EINVAL;
21320 +
21321 +               index = 0;
21322 +               while (index < vc_data.count) {
21323 +                       ret = do_add_v4_addr(nxi, vc_data.ip[index].s_addr, 0,
21324 +                               vc_data.mask[index].s_addr, NXA_TYPE_ADDR, 0);
21325 +                       if (ret)
21326 +                               return ret;
21327 +                       index++;
21328 +               }
21329 +               ret = index;
21330 +               break;
21331 +
21332 +       case NXA_TYPE_IPV4|NXA_MOD_BCAST:
21333 +               nxi->v4_bcast = vc_data.ip[0];
21334 +               ret = 1;
21335 +               break;
21336 +
21337 +       case NXA_TYPE_IPV4|NXA_MOD_LBACK:
21338 +               nxi->v4_lback = vc_data.ip[0];
21339 +               ret = 1;
21340 +               break;
21341 +
21342 +       default:
21343 +               ret = -EINVAL;
21344 +               break;
21345 +       }
21346 +       return ret;
21347 +}
21348 +
21349 +int vc_net_remove(struct nx_info *nxi, void __user *data)
21350 +{
21351 +       struct vcmd_net_addr_v0 vc_data;
21352 +
21353 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
21354 +               return -EFAULT;
21355 +
21356 +       switch (vc_data.type) {
21357 +       case NXA_TYPE_ANY:
21358 +               __dealloc_nx_addr_v4_all(xchg(&nxi->v4.next, NULL));
21359 +               memset(&nxi->v4, 0, sizeof(nxi->v4));
21360 +               break;
21361 +
21362 +       default:
21363 +               return -EINVAL;
21364 +       }
21365 +       return 0;
21366 +}
21367 +
21368 +
21369 +int vc_net_add_ipv4(struct nx_info *nxi, void __user *data)
21370 +{
21371 +       struct vcmd_net_addr_ipv4_v1 vc_data;
21372 +
21373 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
21374 +               return -EFAULT;
21375 +
21376 +       switch (vc_data.type) {
21377 +       case NXA_TYPE_ADDR:
21378 +       case NXA_TYPE_RANGE:
21379 +       case NXA_TYPE_MASK:
21380 +               return do_add_v4_addr(nxi, vc_data.ip.s_addr, 0,
21381 +                       vc_data.mask.s_addr, vc_data.type, vc_data.flags);
21382 +
21383 +       case NXA_TYPE_ADDR | NXA_MOD_BCAST:
21384 +               nxi->v4_bcast = vc_data.ip;
21385 +               break;
21386 +
21387 +       case NXA_TYPE_ADDR | NXA_MOD_LBACK:
21388 +               nxi->v4_lback = vc_data.ip;
21389 +               break;
21390 +
21391 +       default:
21392 +               return -EINVAL;
21393 +       }
21394 +       return 0;
21395 +}
21396 +
21397 +int vc_net_remove_ipv4(struct nx_info *nxi, void __user *data)
21398 +{
21399 +       struct vcmd_net_addr_ipv4_v1 vc_data;
21400 +
21401 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
21402 +               return -EFAULT;
21403 +
21404 +       switch (vc_data.type) {
21405 +/*     case NXA_TYPE_ADDR:
21406 +               break;          */
21407 +
21408 +       case NXA_TYPE_ANY:
21409 +               __dealloc_nx_addr_v4_all(xchg(&nxi->v4.next, NULL));
21410 +               memset(&nxi->v4, 0, sizeof(nxi->v4));
21411 +               break;
21412 +
21413 +       default:
21414 +               return -EINVAL;
21415 +       }
21416 +       return 0;
21417 +}
21418 +
21419 +
21420 +#ifdef CONFIG_IPV6
21421 +
21422 +int do_add_v6_addr(struct nx_info *nxi,
21423 +       struct in6_addr *ip, struct in6_addr *mask,
21424 +       uint32_t prefix, uint16_t type, uint16_t flags)
21425 +{
21426 +       struct nx_addr_v6 *nxa = &nxi->v6;
21427 +
21428 +       if (NX_IPV6(nxi)) {
21429 +               /* locate last entry */
21430 +               for (; nxa->next; nxa = nxa->next);
21431 +               nxa->next = __alloc_nx_addr_v6();
21432 +               nxa = nxa->next;
21433 +
21434 +               if (IS_ERR(nxa))
21435 +                       return PTR_ERR(nxa);
21436 +       }
21437 +
21438 +       nxa->ip = *ip;
21439 +       nxa->mask = *mask;
21440 +       nxa->prefix = prefix;
21441 +       nxa->type = type;
21442 +       nxa->flags = flags;
21443 +       return 0;
21444 +}
21445 +
21446 +
21447 +int vc_net_add_ipv6(struct nx_info *nxi, void __user *data)
21448 +{
21449 +       struct vcmd_net_addr_ipv6_v1 vc_data;
21450 +
21451 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
21452 +               return -EFAULT;
21453 +
21454 +       switch (vc_data.type) {
21455 +       case NXA_TYPE_ADDR:
21456 +       case NXA_TYPE_MASK:
21457 +               return do_add_v6_addr(nxi, &vc_data.ip, &vc_data.mask,
21458 +                       vc_data.prefix, vc_data.type, vc_data.flags);
21459 +       default:
21460 +               return -EINVAL;
21461 +       }
21462 +       return 0;
21463 +}
21464 +
21465 +int vc_net_remove_ipv6(struct nx_info *nxi, void __user *data)
21466 +{
21467 +       struct vcmd_net_addr_ipv6_v1 vc_data;
21468 +
21469 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
21470 +               return -EFAULT;
21471 +
21472 +       switch (vc_data.type) {
21473 +       case NXA_TYPE_ANY:
21474 +               __dealloc_nx_addr_v6_all(xchg(&nxi->v6.next, NULL));
21475 +               memset(&nxi->v6, 0, sizeof(nxi->v6));
21476 +               break;
21477 +
21478 +       default:
21479 +               return -EINVAL;
21480 +       }
21481 +       return 0;
21482 +}
21483 +
21484 +#endif /* CONFIG_IPV6 */
21485 +
21486 +
21487 +int vc_get_nflags(struct nx_info *nxi, void __user *data)
21488 +{
21489 +       struct vcmd_net_flags_v0 vc_data;
21490 +
21491 +       vc_data.flagword = nxi->nx_flags;
21492 +
21493 +       /* special STATE flag handling */
21494 +       vc_data.mask = vs_mask_flags(~0ULL, nxi->nx_flags, NXF_ONE_TIME);
21495 +
21496 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21497 +               return -EFAULT;
21498 +       return 0;
21499 +}
21500 +
21501 +int vc_set_nflags(struct nx_info *nxi, void __user *data)
21502 +{
21503 +       struct vcmd_net_flags_v0 vc_data;
21504 +       uint64_t mask, trigger;
21505 +
21506 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21507 +               return -EFAULT;
21508 +
21509 +       /* special STATE flag handling */
21510 +       mask = vs_mask_mask(vc_data.mask, nxi->nx_flags, NXF_ONE_TIME);
21511 +       trigger = (mask & nxi->nx_flags) ^ (mask & vc_data.flagword);
21512 +
21513 +       nxi->nx_flags = vs_mask_flags(nxi->nx_flags,
21514 +               vc_data.flagword, mask);
21515 +       if (trigger & NXF_PERSISTENT)
21516 +               nx_update_persistent(nxi);
21517 +
21518 +       return 0;
21519 +}
21520 +
21521 +int vc_get_ncaps(struct nx_info *nxi, void __user *data)
21522 +{
21523 +       struct vcmd_net_caps_v0 vc_data;
21524 +
21525 +       vc_data.ncaps = nxi->nx_ncaps;
21526 +       vc_data.cmask = ~0ULL;
21527 +
21528 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21529 +               return -EFAULT;
21530 +       return 0;
21531 +}
21532 +
21533 +int vc_set_ncaps(struct nx_info *nxi, void __user *data)
21534 +{
21535 +       struct vcmd_net_caps_v0 vc_data;
21536 +
21537 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21538 +               return -EFAULT;
21539 +
21540 +       nxi->nx_ncaps = vs_mask_flags(nxi->nx_ncaps,
21541 +               vc_data.ncaps, vc_data.cmask);
21542 +       return 0;
21543 +}
21544 +
21545 +
21546 +#include <linux/module.h>
21547 +
21548 +module_init(init_network);
21549 +
21550 +EXPORT_SYMBOL_GPL(free_nx_info);
21551 +EXPORT_SYMBOL_GPL(unhash_nx_info);
21552 +
21553 diff -NurpP --minimal linux-2.6.38.1/kernel/vserver/proc.c linux-2.6.38.1-vs2.3.0.37-rc9/kernel/vserver/proc.c
21554 --- linux-2.6.38.1/kernel/vserver/proc.c        1970-01-01 01:00:00.000000000 +0100
21555 +++ linux-2.6.38.1-vs2.3.0.37-rc9/kernel/vserver/proc.c 2011-01-29 02:01:07.000000000 +0100
21556 @@ -0,0 +1,1098 @@
21557 +/*
21558 + *  linux/kernel/vserver/proc.c
21559 + *
21560 + *  Virtual Context Support
21561 + *
21562 + *  Copyright (C) 2003-2007  Herbert Pötzl
21563 + *
21564 + *  V0.01  basic structure
21565 + *  V0.02  adaptation vs1.3.0
21566 + *  V0.03  proc permissions
21567 + *  V0.04  locking/generic
21568 + *  V0.05  next generation procfs
21569 + *  V0.06  inode validation
21570 + *  V0.07  generic rewrite vid
21571 + *  V0.08  remove inode type
21572 + *
21573 + */
21574 +
21575 +#include <linux/proc_fs.h>
21576 +#include <linux/fs_struct.h>
21577 +#include <linux/mount.h>
21578 +#include <asm/unistd.h>
21579 +
21580 +#include <linux/vs_context.h>
21581 +#include <linux/vs_network.h>
21582 +#include <linux/vs_cvirt.h>
21583 +
21584 +#include <linux/in.h>
21585 +#include <linux/inetdevice.h>
21586 +#include <linux/vs_inet.h>
21587 +#include <linux/vs_inet6.h>
21588 +
21589 +#include <linux/vserver/global.h>
21590 +
21591 +#include "cvirt_proc.h"
21592 +#include "cacct_proc.h"
21593 +#include "limit_proc.h"
21594 +#include "sched_proc.h"
21595 +#include "vci_config.h"
21596 +
21597 +
21598 +static inline char *print_cap_t(char *buffer, kernel_cap_t *c)
21599 +{
21600 +       unsigned __capi;
21601 +
21602 +       CAP_FOR_EACH_U32(__capi) {
21603 +               buffer += sprintf(buffer, "%08x",
21604 +                       c->cap[(_KERNEL_CAPABILITY_U32S-1) - __capi]);
21605 +       }
21606 +       return buffer;
21607 +}
21608 +
21609 +
21610 +static struct proc_dir_entry *proc_virtual;
21611 +
21612 +static struct proc_dir_entry *proc_virtnet;
21613 +
21614 +
21615 +/* first the actual feeds */
21616 +
21617 +
21618 +static int proc_vci(char *buffer)
21619 +{
21620 +       return sprintf(buffer,
21621 +               "VCIVersion:\t%04x:%04x\n"
21622 +               "VCISyscall:\t%d\n"
21623 +               "VCIKernel:\t%08x\n",
21624 +               VCI_VERSION >> 16,
21625 +               VCI_VERSION & 0xFFFF,
21626 +               __NR_vserver,
21627 +               vci_kernel_config());
21628 +}
21629 +
21630 +static int proc_virtual_info(char *buffer)
21631 +{
21632 +       return proc_vci(buffer);
21633 +}
21634 +
21635 +static int proc_virtual_status(char *buffer)
21636 +{
21637 +       return sprintf(buffer,
21638 +               "#CTotal:\t%d\n"
21639 +               "#CActive:\t%d\n"
21640 +               "#NSProxy:\t%d\t%d %d %d %d %d %d\n"
21641 +               "#InitTask:\t%d\t%d %d\n",
21642 +               atomic_read(&vx_global_ctotal),
21643 +               atomic_read(&vx_global_cactive),
21644 +               atomic_read(&vs_global_nsproxy),
21645 +               atomic_read(&vs_global_fs),
21646 +               atomic_read(&vs_global_mnt_ns),
21647 +               atomic_read(&vs_global_uts_ns),
21648 +               atomic_read(&nr_ipc_ns),
21649 +               atomic_read(&vs_global_user_ns),
21650 +               atomic_read(&vs_global_pid_ns),
21651 +               atomic_read(&init_task.usage),
21652 +               atomic_read(&init_task.nsproxy->count),
21653 +               init_task.fs->users);
21654 +}
21655 +
21656 +
21657 +int proc_vxi_info(struct vx_info *vxi, char *buffer)
21658 +{
21659 +       int length;
21660 +
21661 +       length = sprintf(buffer,
21662 +               "ID:\t%d\n"
21663 +               "Info:\t%p\n"
21664 +               "Init:\t%d\n"
21665 +               "OOM:\t%lld\n",
21666 +               vxi->vx_id,
21667 +               vxi,
21668 +               vxi->vx_initpid,
21669 +               vxi->vx_badness_bias);
21670 +       return length;
21671 +}
21672 +
21673 +int proc_vxi_status(struct vx_info *vxi, char *buffer)
21674 +{
21675 +       char *orig = buffer;
21676 +
21677 +       buffer += sprintf(buffer,
21678 +               "UseCnt:\t%d\n"
21679 +               "Tasks:\t%d\n"
21680 +               "Flags:\t%016llx\n",
21681 +               atomic_read(&vxi->vx_usecnt),
21682 +               atomic_read(&vxi->vx_tasks),
21683 +               (unsigned long long)vxi->vx_flags);
21684 +
21685 +       buffer += sprintf(buffer, "BCaps:\t");
21686 +       buffer = print_cap_t(buffer, &vxi->vx_bcaps);
21687 +       buffer += sprintf(buffer, "\n");
21688 +
21689 +       buffer += sprintf(buffer,
21690 +               "CCaps:\t%016llx\n"
21691 +               "Spaces:\t%08lx %08lx\n",
21692 +               (unsigned long long)vxi->vx_ccaps,
21693 +               vxi->space[0].vx_nsmask, vxi->space[1].vx_nsmask);
21694 +       return buffer - orig;
21695 +}
21696 +
21697 +int proc_vxi_limit(struct vx_info *vxi, char *buffer)
21698 +{
21699 +       return vx_info_proc_limit(&vxi->limit, buffer);
21700 +}
21701 +
21702 +int proc_vxi_sched(struct vx_info *vxi, char *buffer)
21703 +{
21704 +       int cpu, length;
21705 +
21706 +       length = vx_info_proc_sched(&vxi->sched, buffer);
21707 +       for_each_online_cpu(cpu) {
21708 +               length += vx_info_proc_sched_pc(
21709 +                       &vx_per_cpu(vxi, sched_pc, cpu),
21710 +                       buffer + length, cpu);
21711 +       }
21712 +       return length;
21713 +}
21714 +
21715 +int proc_vxi_nsproxy0(struct vx_info *vxi, char *buffer)
21716 +{
21717 +       return vx_info_proc_nsproxy(vxi->space[0].vx_nsproxy, buffer);
21718 +}
21719 +
21720 +int proc_vxi_nsproxy1(struct vx_info *vxi, char *buffer)
21721 +{
21722 +       return vx_info_proc_nsproxy(vxi->space[1].vx_nsproxy, buffer);
21723 +}
21724 +
21725 +int proc_vxi_cvirt(struct vx_info *vxi, char *buffer)
21726 +{
21727 +       int cpu, length;
21728 +
21729 +       vx_update_load(vxi);
21730 +       length = vx_info_proc_cvirt(&vxi->cvirt, buffer);
21731 +       for_each_online_cpu(cpu) {
21732 +               length += vx_info_proc_cvirt_pc(
21733 +                       &vx_per_cpu(vxi, cvirt_pc, cpu),
21734 +                       buffer + length, cpu);
21735 +       }
21736 +       return length;
21737 +}
21738 +
21739 +int proc_vxi_cacct(struct vx_info *vxi, char *buffer)
21740 +{
21741 +       return vx_info_proc_cacct(&vxi->cacct, buffer);
21742 +}
21743 +
21744 +
21745 +static int proc_virtnet_info(char *buffer)
21746 +{
21747 +       return proc_vci(buffer);
21748 +}
21749 +
21750 +static int proc_virtnet_status(char *buffer)
21751 +{
21752 +       return sprintf(buffer,
21753 +               "#CTotal:\t%d\n"
21754 +               "#CActive:\t%d\n",
21755 +               atomic_read(&nx_global_ctotal),
21756 +               atomic_read(&nx_global_cactive));
21757 +}
21758 +
21759 +int proc_nxi_info(struct nx_info *nxi, char *buffer)
21760 +{
21761 +       struct nx_addr_v4 *v4a;
21762 +#ifdef CONFIG_IPV6
21763 +       struct nx_addr_v6 *v6a;
21764 +#endif
21765 +       int length, i;
21766 +
21767 +       length = sprintf(buffer,
21768 +               "ID:\t%d\n"
21769 +               "Info:\t%p\n"
21770 +               "Bcast:\t" NIPQUAD_FMT "\n"
21771 +               "Lback:\t" NIPQUAD_FMT "\n",
21772 +               nxi->nx_id,
21773 +               nxi,
21774 +               NIPQUAD(nxi->v4_bcast.s_addr),
21775 +               NIPQUAD(nxi->v4_lback.s_addr));
21776 +
21777 +       if (!NX_IPV4(nxi))
21778 +               goto skip_v4;
21779 +       for (i = 0, v4a = &nxi->v4; v4a; i++, v4a = v4a->next)
21780 +               length += sprintf(buffer + length, "%d:\t" NXAV4_FMT "\n",
21781 +                       i, NXAV4(v4a));
21782 +skip_v4:
21783 +#ifdef CONFIG_IPV6
21784 +       if (!NX_IPV6(nxi))
21785 +               goto skip_v6;
21786 +       for (i = 0, v6a = &nxi->v6; v6a; i++, v6a = v6a->next)
21787 +               length += sprintf(buffer + length, "%d:\t" NXAV6_FMT "\n",
21788 +                       i, NXAV6(v6a));
21789 +skip_v6:
21790 +#endif
21791 +       return length;
21792 +}
21793 +
21794 +int proc_nxi_status(struct nx_info *nxi, char *buffer)
21795 +{
21796 +       int length;
21797 +
21798 +       length = sprintf(buffer,
21799 +               "UseCnt:\t%d\n"
21800 +               "Tasks:\t%d\n"
21801 +               "Flags:\t%016llx\n"
21802 +               "NCaps:\t%016llx\n",
21803 +               atomic_read(&nxi->nx_usecnt),
21804 +               atomic_read(&nxi->nx_tasks),
21805 +               (unsigned long long)nxi->nx_flags,
21806 +               (unsigned long long)nxi->nx_ncaps);
21807 +       return length;
21808 +}
21809 +
21810 +
21811 +
21812 +/* here the inode helpers */
21813 +
21814 +struct vs_entry {
21815 +       int len;
21816 +       char *name;
21817 +       mode_t mode;
21818 +       struct inode_operations *iop;
21819 +       struct file_operations *fop;
21820 +       union proc_op op;
21821 +};
21822 +
21823 +static struct inode *vs_proc_make_inode(struct super_block *sb, struct vs_entry *p)
21824 +{
21825 +       struct inode *inode = new_inode(sb);
21826 +
21827 +       if (!inode)
21828 +               goto out;
21829 +
21830 +       inode->i_mode = p->mode;
21831 +       if (p->iop)
21832 +               inode->i_op = p->iop;
21833 +       if (p->fop)
21834 +               inode->i_fop = p->fop;
21835 +
21836 +       inode->i_nlink = (p->mode & S_IFDIR) ? 2 : 1;
21837 +       inode->i_flags |= S_IMMUTABLE;
21838 +
21839 +       inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
21840 +
21841 +       inode->i_uid = 0;
21842 +       inode->i_gid = 0;
21843 +       inode->i_tag = 0;
21844 +out:
21845 +       return inode;
21846 +}
21847 +
21848 +static struct dentry *vs_proc_instantiate(struct inode *dir,
21849 +       struct dentry *dentry, int id, void *ptr)
21850 +{
21851 +       struct vs_entry *p = ptr;
21852 +       struct inode *inode = vs_proc_make_inode(dir->i_sb, p);
21853 +       struct dentry *error = ERR_PTR(-EINVAL);
21854 +
21855 +       if (!inode)
21856 +               goto out;
21857 +
21858 +       PROC_I(inode)->op = p->op;
21859 +       PROC_I(inode)->fd = id;
21860 +       d_add(dentry, inode);
21861 +       error = NULL;
21862 +out:
21863 +       return error;
21864 +}
21865 +
21866 +/* Lookups */
21867 +
21868 +typedef struct dentry *instantiate_t(struct inode *, struct dentry *, int, void *);
21869 +
21870 +/*
21871 + * Fill a directory entry.
21872 + *
21873 + * If possible create the dcache entry and derive our inode number and
21874 + * file type from dcache entry.
21875 + *
21876 + * Since all of the proc inode numbers are dynamically generated, the inode
21877 + * numbers do not exist until the inode is cache.  This means creating the
21878 + * the dcache entry in readdir is necessary to keep the inode numbers
21879 + * reported by readdir in sync with the inode numbers reported
21880 + * by stat.
21881 + */
21882 +static int proc_fill_cache(struct file *filp, void *dirent, filldir_t filldir,
21883 +       char *name, int len, instantiate_t instantiate, int id, void *ptr)
21884 +{
21885 +       struct dentry *child, *dir = filp->f_dentry;
21886 +       struct inode *inode;
21887 +       struct qstr qname;
21888 +       ino_t ino = 0;
21889 +       unsigned type = DT_UNKNOWN;
21890 +
21891 +       qname.name = name;
21892 +       qname.len  = len;
21893 +       qname.hash = full_name_hash(name, len);
21894 +
21895 +       child = d_lookup(dir, &qname);
21896 +       if (!child) {
21897 +               struct dentry *new;
21898 +               new = d_alloc(dir, &qname);
21899 +               if (new) {
21900 +                       child = instantiate(dir->d_inode, new, id, ptr);
21901 +                       if (child)
21902 +                               dput(new);
21903 +                       else
21904 +                               child = new;
21905 +               }
21906 +       }
21907 +       if (!child || IS_ERR(child) || !child->d_inode)
21908 +               goto end_instantiate;
21909 +       inode = child->d_inode;
21910 +       if (inode) {
21911 +               ino = inode->i_ino;
21912 +               type = inode->i_mode >> 12;
21913 +       }
21914 +       dput(child);
21915 +end_instantiate:
21916 +       if (!ino)
21917 +               ino = find_inode_number(dir, &qname);
21918 +       if (!ino)
21919 +               ino = 1;
21920 +       return filldir(dirent, name, len, filp->f_pos, ino, type);
21921 +}
21922 +
21923 +
21924 +
21925 +/* get and revalidate vx_info/xid */
21926 +
21927 +static inline
21928 +struct vx_info *get_proc_vx_info(struct inode *inode)
21929 +{
21930 +       return lookup_vx_info(PROC_I(inode)->fd);
21931 +}
21932 +
21933 +static int proc_xid_revalidate(struct dentry *dentry, struct nameidata *nd)
21934 +{
21935 +       struct inode *inode = dentry->d_inode;
21936 +       xid_t xid = PROC_I(inode)->fd;
21937 +
21938 +       if (!xid || xid_is_hashed(xid))
21939 +               return 1;
21940 +       d_drop(dentry);
21941 +       return 0;
21942 +}
21943 +
21944 +
21945 +/* get and revalidate nx_info/nid */
21946 +
21947 +static int proc_nid_revalidate(struct dentry *dentry, struct nameidata *nd)
21948 +{
21949 +       struct inode *inode = dentry->d_inode;
21950 +       nid_t nid = PROC_I(inode)->fd;
21951 +
21952 +       if (!nid || nid_is_hashed(nid))
21953 +               return 1;
21954 +       d_drop(dentry);
21955 +       return 0;
21956 +}
21957 +
21958 +
21959 +
21960 +#define PROC_BLOCK_SIZE (PAGE_SIZE - 1024)
21961 +
21962 +static ssize_t proc_vs_info_read(struct file *file, char __user *buf,
21963 +                         size_t count, loff_t *ppos)
21964 +{
21965 +       struct inode *inode = file->f_dentry->d_inode;
21966 +       unsigned long page;
21967 +       ssize_t length = 0;
21968 +
21969 +       if (count > PROC_BLOCK_SIZE)
21970 +               count = PROC_BLOCK_SIZE;
21971 +
21972 +       /* fade that out as soon as stable */
21973 +       WARN_ON(PROC_I(inode)->fd);
21974 +
21975 +       if (!(page = __get_free_page(GFP_KERNEL)))
21976 +               return -ENOMEM;
21977 +
21978 +       BUG_ON(!PROC_I(inode)->op.proc_vs_read);
21979 +       length = PROC_I(inode)->op.proc_vs_read((char *)page);
21980 +
21981 +       if (length >= 0)
21982 +               length = simple_read_from_buffer(buf, count, ppos,
21983 +                       (char *)page, length);
21984 +
21985 +       free_page(page);
21986 +       return length;
21987 +}
21988 +
21989 +static ssize_t proc_vx_info_read(struct file *file, char __user *buf,
21990 +                         size_t count, loff_t *ppos)
21991 +{
21992 +       struct inode *inode = file->f_dentry->d_inode;
21993 +       struct vx_info *vxi = NULL;
21994 +       xid_t xid = PROC_I(inode)->fd;
21995 +       unsigned long page;
21996 +       ssize_t length = 0;
21997 +
21998 +       if (count > PROC_BLOCK_SIZE)
21999 +               count = PROC_BLOCK_SIZE;
22000 +
22001 +       /* fade that out as soon as stable */
22002 +       WARN_ON(!xid);
22003 +       vxi = lookup_vx_info(xid);
22004 +       if (!vxi)
22005 +               goto out;
22006 +
22007 +       length = -ENOMEM;
22008 +       if (!(page = __get_free_page(GFP_KERNEL)))
22009 +               goto out_put;
22010 +
22011 +       BUG_ON(!PROC_I(inode)->op.proc_vxi_read);
22012 +       length = PROC_I(inode)->op.proc_vxi_read(vxi, (char *)page);
22013 +
22014 +       if (length >= 0)
22015 +               length = simple_read_from_buffer(buf, count, ppos,
22016 +                       (char *)page, length);
22017 +
22018 +       free_page(page);
22019 +out_put:
22020 +       put_vx_info(vxi);
22021 +out:
22022 +       return length;
22023 +}
22024 +
22025 +static ssize_t proc_nx_info_read(struct file *file, char __user *buf,
22026 +                         size_t count, loff_t *ppos)
22027 +{
22028 +       struct inode *inode = file->f_dentry->d_inode;
22029 +       struct nx_info *nxi = NULL;
22030 +       nid_t nid = PROC_I(inode)->fd;
22031 +       unsigned long page;
22032 +       ssize_t length = 0;
22033 +
22034 +       if (count > PROC_BLOCK_SIZE)
22035 +               count = PROC_BLOCK_SIZE;
22036 +
22037 +       /* fade that out as soon as stable */
22038 +       WARN_ON(!nid);
22039 +       nxi = lookup_nx_info(nid);
22040 +       if (!nxi)
22041 +               goto out;
22042 +
22043 +       length = -ENOMEM;
22044 +       if (!(page = __get_free_page(GFP_KERNEL)))
22045 +               goto out_put;
22046 +
22047 +       BUG_ON(!PROC_I(inode)->op.proc_nxi_read);
22048 +       length = PROC_I(inode)->op.proc_nxi_read(nxi, (char *)page);
22049 +
22050 +       if (length >= 0)
22051 +               length = simple_read_from_buffer(buf, count, ppos,
22052 +                       (char *)page, length);
22053 +
22054 +       free_page(page);
22055 +out_put:
22056 +       put_nx_info(nxi);
22057 +out:
22058 +       return length;
22059 +}
22060 +
22061 +
22062 +
22063 +/* here comes the lower level */
22064 +
22065 +
22066 +#define NOD(NAME, MODE, IOP, FOP, OP) {        \
22067 +       .len  = sizeof(NAME) - 1,       \
22068 +       .name = (NAME),                 \
22069 +       .mode = MODE,                   \
22070 +       .iop  = IOP,                    \
22071 +       .fop  = FOP,                    \
22072 +       .op   = OP,                     \
22073 +}
22074 +
22075 +
22076 +#define DIR(NAME, MODE, OTYPE)                         \
22077 +       NOD(NAME, (S_IFDIR | (MODE)),                   \
22078 +               &proc_ ## OTYPE ## _inode_operations,   \
22079 +               &proc_ ## OTYPE ## _file_operations, { } )
22080 +
22081 +#define INF(NAME, MODE, OTYPE)                         \
22082 +       NOD(NAME, (S_IFREG | (MODE)), NULL,             \
22083 +               &proc_vs_info_file_operations,          \
22084 +               { .proc_vs_read = &proc_##OTYPE } )
22085 +
22086 +#define VINF(NAME, MODE, OTYPE)                                \
22087 +       NOD(NAME, (S_IFREG | (MODE)), NULL,             \
22088 +               &proc_vx_info_file_operations,          \
22089 +               { .proc_vxi_read = &proc_##OTYPE } )
22090 +
22091 +#define NINF(NAME, MODE, OTYPE)                                \
22092 +       NOD(NAME, (S_IFREG | (MODE)), NULL,             \
22093 +               &proc_nx_info_file_operations,          \
22094 +               { .proc_nxi_read = &proc_##OTYPE } )
22095 +
22096 +
22097 +static struct file_operations proc_vs_info_file_operations = {
22098 +       .read =         proc_vs_info_read,
22099 +};
22100 +
22101 +static struct file_operations proc_vx_info_file_operations = {
22102 +       .read =         proc_vx_info_read,
22103 +};
22104 +
22105 +static struct dentry_operations proc_xid_dentry_operations = {
22106 +       .d_revalidate = proc_xid_revalidate,
22107 +};
22108 +
22109 +static struct vs_entry vx_base_stuff[] = {
22110 +       VINF("info",    S_IRUGO, vxi_info),
22111 +       VINF("status",  S_IRUGO, vxi_status),
22112 +       VINF("limit",   S_IRUGO, vxi_limit),
22113 +       VINF("sched",   S_IRUGO, vxi_sched),
22114 +       VINF("nsproxy", S_IRUGO, vxi_nsproxy0),
22115 +       VINF("nsproxy1",S_IRUGO, vxi_nsproxy1),
22116 +       VINF("cvirt",   S_IRUGO, vxi_cvirt),
22117 +       VINF("cacct",   S_IRUGO, vxi_cacct),
22118 +       {}
22119 +};
22120 +
22121 +
22122 +
22123 +
22124 +static struct dentry *proc_xid_instantiate(struct inode *dir,
22125 +       struct dentry *dentry, int id, void *ptr)
22126 +{
22127 +       dentry->d_op = &proc_xid_dentry_operations;
22128 +       return vs_proc_instantiate(dir, dentry, id, ptr);
22129 +}
22130 +
22131 +static struct dentry *proc_xid_lookup(struct inode *dir,
22132 +       struct dentry *dentry, struct nameidata *nd)
22133 +{
22134 +       struct vs_entry *p = vx_base_stuff;
22135 +       struct dentry *error = ERR_PTR(-ENOENT);
22136 +
22137 +       for (; p->name; p++) {
22138 +               if (p->len != dentry->d_name.len)
22139 +                       continue;
22140 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
22141 +                       break;
22142 +       }
22143 +       if (!p->name)
22144 +               goto out;
22145 +
22146 +       error = proc_xid_instantiate(dir, dentry, PROC_I(dir)->fd, p);
22147 +out:
22148 +       return error;
22149 +}
22150 +
22151 +static int proc_xid_readdir(struct file *filp,
22152 +       void *dirent, filldir_t filldir)
22153 +{
22154 +       struct dentry *dentry = filp->f_dentry;
22155 +       struct inode *inode = dentry->d_inode;
22156 +       struct vs_entry *p = vx_base_stuff;
22157 +       int size = sizeof(vx_base_stuff) / sizeof(struct vs_entry);
22158 +       int pos, index;
22159 +       u64 ino;
22160 +
22161 +       pos = filp->f_pos;
22162 +       switch (pos) {
22163 +       case 0:
22164 +               ino = inode->i_ino;
22165 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
22166 +                       goto out;
22167 +               pos++;
22168 +               /* fall through */
22169 +       case 1:
22170 +               ino = parent_ino(dentry);
22171 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
22172 +                       goto out;
22173 +               pos++;
22174 +               /* fall through */
22175 +       default:
22176 +               index = pos - 2;
22177 +               if (index >= size)
22178 +                       goto out;
22179 +               for (p += index; p->name; p++) {
22180 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
22181 +                               vs_proc_instantiate, PROC_I(inode)->fd, p))
22182 +                               goto out;
22183 +                       pos++;
22184 +               }
22185 +       }
22186 +out:
22187 +       filp->f_pos = pos;
22188 +       return 1;
22189 +}
22190 +
22191 +
22192 +
22193 +static struct file_operations proc_nx_info_file_operations = {
22194 +       .read =         proc_nx_info_read,
22195 +};
22196 +
22197 +static struct dentry_operations proc_nid_dentry_operations = {
22198 +       .d_revalidate = proc_nid_revalidate,
22199 +};
22200 +
22201 +static struct vs_entry nx_base_stuff[] = {
22202 +       NINF("info",    S_IRUGO, nxi_info),
22203 +       NINF("status",  S_IRUGO, nxi_status),
22204 +       {}
22205 +};
22206 +
22207 +
22208 +static struct dentry *proc_nid_instantiate(struct inode *dir,
22209 +       struct dentry *dentry, int id, void *ptr)
22210 +{
22211 +       dentry->d_op = &proc_nid_dentry_operations;
22212 +       return vs_proc_instantiate(dir, dentry, id, ptr);
22213 +}
22214 +
22215 +static struct dentry *proc_nid_lookup(struct inode *dir,
22216 +       struct dentry *dentry, struct nameidata *nd)
22217 +{
22218 +       struct vs_entry *p = nx_base_stuff;
22219 +       struct dentry *error = ERR_PTR(-ENOENT);
22220 +
22221 +       for (; p->name; p++) {
22222 +               if (p->len != dentry->d_name.len)
22223 +                       continue;
22224 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
22225 +                       break;
22226 +       }
22227 +       if (!p->name)
22228 +               goto out;
22229 +
22230 +       error = proc_nid_instantiate(dir, dentry, PROC_I(dir)->fd, p);
22231 +out:
22232 +       return error;
22233 +}
22234 +
22235 +static int proc_nid_readdir(struct file *filp,
22236 +       void *dirent, filldir_t filldir)
22237 +{
22238 +       struct dentry *dentry = filp->f_dentry;
22239 +       struct inode *inode = dentry->d_inode;
22240 +       struct vs_entry *p = nx_base_stuff;
22241 +       int size = sizeof(nx_base_stuff) / sizeof(struct vs_entry);
22242 +       int pos, index;
22243 +       u64 ino;
22244 +
22245 +       pos = filp->f_pos;
22246 +       switch (pos) {
22247 +       case 0:
22248 +               ino = inode->i_ino;
22249 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
22250 +                       goto out;
22251 +               pos++;
22252 +               /* fall through */
22253 +       case 1:
22254 +               ino = parent_ino(dentry);
22255 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
22256 +                       goto out;
22257 +               pos++;
22258 +               /* fall through */
22259 +       default:
22260 +               index = pos - 2;
22261 +               if (index >= size)
22262 +                       goto out;
22263 +               for (p += index; p->name; p++) {
22264 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
22265 +                               vs_proc_instantiate, PROC_I(inode)->fd, p))
22266 +                               goto out;
22267 +                       pos++;
22268 +               }
22269 +       }
22270 +out:
22271 +       filp->f_pos = pos;
22272 +       return 1;
22273 +}
22274 +
22275 +
22276 +#define MAX_MULBY10    ((~0U - 9) / 10)
22277 +
22278 +static inline int atovid(const char *str, int len)
22279 +{
22280 +       int vid, c;
22281 +
22282 +       vid = 0;
22283 +       while (len-- > 0) {
22284 +               c = *str - '0';
22285 +               str++;
22286 +               if (c > 9)
22287 +                       return -1;
22288 +               if (vid >= MAX_MULBY10)
22289 +                       return -1;
22290 +               vid *= 10;
22291 +               vid += c;
22292 +               if (!vid)
22293 +                       return -1;
22294 +       }
22295 +       return vid;
22296 +}
22297 +
22298 +/* now the upper level (virtual) */
22299 +
22300 +
22301 +static struct file_operations proc_xid_file_operations = {
22302 +       .read =         generic_read_dir,
22303 +       .readdir =      proc_xid_readdir,
22304 +};
22305 +
22306 +static struct inode_operations proc_xid_inode_operations = {
22307 +       .lookup =       proc_xid_lookup,
22308 +};
22309 +
22310 +static struct vs_entry vx_virtual_stuff[] = {
22311 +       INF("info",     S_IRUGO, virtual_info),
22312 +       INF("status",   S_IRUGO, virtual_status),
22313 +       DIR(NULL,       S_IRUGO | S_IXUGO, xid),
22314 +};
22315 +
22316 +
22317 +static struct dentry *proc_virtual_lookup(struct inode *dir,
22318 +       struct dentry *dentry, struct nameidata *nd)
22319 +{
22320 +       struct vs_entry *p = vx_virtual_stuff;
22321 +       struct dentry *error = ERR_PTR(-ENOENT);
22322 +       int id = 0;
22323 +
22324 +       for (; p->name; p++) {
22325 +               if (p->len != dentry->d_name.len)
22326 +                       continue;
22327 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
22328 +                       break;
22329 +       }
22330 +       if (p->name)
22331 +               goto instantiate;
22332 +
22333 +       id = atovid(dentry->d_name.name, dentry->d_name.len);
22334 +       if ((id < 0) || !xid_is_hashed(id))
22335 +               goto out;
22336 +
22337 +instantiate:
22338 +       error = proc_xid_instantiate(dir, dentry, id, p);
22339 +out:
22340 +       return error;
22341 +}
22342 +
22343 +static struct file_operations proc_nid_file_operations = {
22344 +       .read =         generic_read_dir,
22345 +       .readdir =      proc_nid_readdir,
22346 +};
22347 +
22348 +static struct inode_operations proc_nid_inode_operations = {
22349 +       .lookup =       proc_nid_lookup,
22350 +};
22351 +
22352 +static struct vs_entry nx_virtnet_stuff[] = {
22353 +       INF("info",     S_IRUGO, virtnet_info),
22354 +       INF("status",   S_IRUGO, virtnet_status),
22355 +       DIR(NULL,       S_IRUGO | S_IXUGO, nid),
22356 +};
22357 +
22358 +
22359 +static struct dentry *proc_virtnet_lookup(struct inode *dir,
22360 +       struct dentry *dentry, struct nameidata *nd)
22361 +{
22362 +       struct vs_entry *p = nx_virtnet_stuff;
22363 +       struct dentry *error = ERR_PTR(-ENOENT);
22364 +       int id = 0;
22365 +
22366 +       for (; p->name; p++) {
22367 +               if (p->len != dentry->d_name.len)
22368 +                       continue;
22369 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
22370 +                       break;
22371 +       }
22372 +       if (p->name)
22373 +               goto instantiate;
22374 +
22375 +       id = atovid(dentry->d_name.name, dentry->d_name.len);
22376 +       if ((id < 0) || !nid_is_hashed(id))
22377 +               goto out;
22378 +
22379 +instantiate:
22380 +       error = proc_nid_instantiate(dir, dentry, id, p);
22381 +out:
22382 +       return error;
22383 +}
22384 +
22385 +
22386 +#define PROC_MAXVIDS 32
22387 +
22388 +int proc_virtual_readdir(struct file *filp,
22389 +       void *dirent, filldir_t filldir)
22390 +{
22391 +       struct dentry *dentry = filp->f_dentry;
22392 +       struct inode *inode = dentry->d_inode;
22393 +       struct vs_entry *p = vx_virtual_stuff;
22394 +       int size = sizeof(vx_virtual_stuff) / sizeof(struct vs_entry);
22395 +       int pos, index;
22396 +       unsigned int xid_array[PROC_MAXVIDS];
22397 +       char buf[PROC_NUMBUF];
22398 +       unsigned int nr_xids, i;
22399 +       u64 ino;
22400 +
22401 +       pos = filp->f_pos;
22402 +       switch (pos) {
22403 +       case 0:
22404 +               ino = inode->i_ino;
22405 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
22406 +                       goto out;
22407 +               pos++;
22408 +               /* fall through */
22409 +       case 1:
22410 +               ino = parent_ino(dentry);
22411 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
22412 +                       goto out;
22413 +               pos++;
22414 +               /* fall through */
22415 +       default:
22416 +               index = pos - 2;
22417 +               if (index >= size)
22418 +                       goto entries;
22419 +               for (p += index; p->name; p++) {
22420 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
22421 +                               vs_proc_instantiate, 0, p))
22422 +                               goto out;
22423 +                       pos++;
22424 +               }
22425 +       entries:
22426 +               index = pos - size;
22427 +               p = &vx_virtual_stuff[size - 1];
22428 +               nr_xids = get_xid_list(index, xid_array, PROC_MAXVIDS);
22429 +               for (i = 0; i < nr_xids; i++) {
22430 +                       int n, xid = xid_array[i];
22431 +                       unsigned int j = PROC_NUMBUF;
22432 +
22433 +                       n = xid;
22434 +                       do
22435 +                               buf[--j] = '0' + (n % 10);
22436 +                       while (n /= 10);
22437 +
22438 +                       if (proc_fill_cache(filp, dirent, filldir,
22439 +                               buf + j, PROC_NUMBUF - j,
22440 +                               vs_proc_instantiate, xid, p))
22441 +                               goto out;
22442 +                       pos++;
22443 +               }
22444 +       }
22445 +out:
22446 +       filp->f_pos = pos;
22447 +       return 0;
22448 +}
22449 +
22450 +static int proc_virtual_getattr(struct vfsmount *mnt,
22451 +       struct dentry *dentry, struct kstat *stat)
22452 +{
22453 +       struct inode *inode = dentry->d_inode;
22454 +
22455 +       generic_fillattr(inode, stat);
22456 +       stat->nlink = 2 + atomic_read(&vx_global_cactive);
22457 +       return 0;
22458 +}
22459 +
22460 +static struct file_operations proc_virtual_dir_operations = {
22461 +       .read =         generic_read_dir,
22462 +       .readdir =      proc_virtual_readdir,
22463 +};
22464 +
22465 +static struct inode_operations proc_virtual_dir_inode_operations = {
22466 +       .getattr =      proc_virtual_getattr,
22467 +       .lookup =       proc_virtual_lookup,
22468 +};
22469 +
22470 +
22471 +
22472 +
22473 +
22474 +int proc_virtnet_readdir(struct file *filp,
22475 +       void *dirent, filldir_t filldir)
22476 +{
22477 +       struct dentry *dentry = filp->f_dentry;
22478 +       struct inode *inode = dentry->d_inode;
22479 +       struct vs_entry *p = nx_virtnet_stuff;
22480 +       int size = sizeof(nx_virtnet_stuff) / sizeof(struct vs_entry);
22481 +       int pos, index;
22482 +       unsigned int nid_array[PROC_MAXVIDS];
22483 +       char buf[PROC_NUMBUF];
22484 +       unsigned int nr_nids, i;
22485 +       u64 ino;
22486 +
22487 +       pos = filp->f_pos;
22488 +       switch (pos) {
22489 +       case 0:
22490 +               ino = inode->i_ino;
22491 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
22492 +                       goto out;
22493 +               pos++;
22494 +               /* fall through */
22495 +       case 1:
22496 +               ino = parent_ino(dentry);
22497 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
22498 +                       goto out;
22499 +               pos++;
22500 +               /* fall through */
22501 +       default:
22502 +               index = pos - 2;
22503 +               if (index >= size)
22504 +                       goto entries;
22505 +               for (p += index; p->name; p++) {
22506 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
22507 +                               vs_proc_instantiate, 0, p))
22508 +                               goto out;
22509 +                       pos++;
22510 +               }
22511 +       entries:
22512 +               index = pos - size;
22513 +               p = &nx_virtnet_stuff[size - 1];
22514 +               nr_nids = get_nid_list(index, nid_array, PROC_MAXVIDS);
22515 +               for (i = 0; i < nr_nids; i++) {
22516 +                       int n, nid = nid_array[i];
22517 +                       unsigned int j = PROC_NUMBUF;
22518 +
22519 +                       n = nid;
22520 +                       do
22521 +                               buf[--j] = '0' + (n % 10);
22522 +                       while (n /= 10);
22523 +
22524 +                       if (proc_fill_cache(filp, dirent, filldir,
22525 +                               buf + j, PROC_NUMBUF - j,
22526 +                               vs_proc_instantiate, nid, p))
22527 +                               goto out;
22528 +                       pos++;
22529 +               }
22530 +       }
22531 +out:
22532 +       filp->f_pos = pos;
22533 +       return 0;
22534 +}
22535 +
22536 +static int proc_virtnet_getattr(struct vfsmount *mnt,
22537 +       struct dentry *dentry, struct kstat *stat)
22538 +{
22539 +       struct inode *inode = dentry->d_inode;
22540 +
22541 +       generic_fillattr(inode, stat);
22542 +       stat->nlink = 2 + atomic_read(&nx_global_cactive);
22543 +       return 0;
22544 +}
22545 +
22546 +static struct file_operations proc_virtnet_dir_operations = {
22547 +       .read =         generic_read_dir,
22548 +       .readdir =      proc_virtnet_readdir,
22549 +};
22550 +
22551 +static struct inode_operations proc_virtnet_dir_inode_operations = {
22552 +       .getattr =      proc_virtnet_getattr,
22553 +       .lookup =       proc_virtnet_lookup,
22554 +};
22555 +
22556 +
22557 +
22558 +void proc_vx_init(void)
22559 +{
22560 +       struct proc_dir_entry *ent;
22561 +
22562 +       ent = proc_mkdir("virtual", 0);
22563 +       if (ent) {
22564 +               ent->proc_fops = &proc_virtual_dir_operations;
22565 +               ent->proc_iops = &proc_virtual_dir_inode_operations;
22566 +       }
22567 +       proc_virtual = ent;
22568 +
22569 +       ent = proc_mkdir("virtnet", 0);
22570 +       if (ent) {
22571 +               ent->proc_fops = &proc_virtnet_dir_operations;
22572 +               ent->proc_iops = &proc_virtnet_dir_inode_operations;
22573 +       }
22574 +       proc_virtnet = ent;
22575 +}
22576 +
22577 +
22578 +
22579 +
22580 +/* per pid info */
22581 +
22582 +
22583 +int proc_pid_vx_info(struct task_struct *p, char *buffer)
22584 +{
22585 +       struct vx_info *vxi;
22586 +       char *orig = buffer;
22587 +
22588 +       buffer += sprintf(buffer, "XID:\t%d\n", vx_task_xid(p));
22589 +
22590 +       vxi = task_get_vx_info(p);
22591 +       if (!vxi)
22592 +               goto out;
22593 +
22594 +       buffer += sprintf(buffer, "BCaps:\t");
22595 +       buffer = print_cap_t(buffer, &vxi->vx_bcaps);
22596 +       buffer += sprintf(buffer, "\n");
22597 +       buffer += sprintf(buffer, "CCaps:\t%016llx\n",
22598 +               (unsigned long long)vxi->vx_ccaps);
22599 +       buffer += sprintf(buffer, "CFlags:\t%016llx\n",
22600 +               (unsigned long long)vxi->vx_flags);
22601 +       buffer += sprintf(buffer, "CIPid:\t%d\n", vxi->vx_initpid);
22602 +
22603 +       put_vx_info(vxi);
22604 +out:
22605 +       return buffer - orig;
22606 +}
22607 +
22608 +
22609 +int proc_pid_nx_info(struct task_struct *p, char *buffer)
22610 +{
22611 +       struct nx_info *nxi;
22612 +       struct nx_addr_v4 *v4a;
22613 +#ifdef CONFIG_IPV6
22614 +       struct nx_addr_v6 *v6a;
22615 +#endif
22616 +       char *orig = buffer;
22617 +       int i;
22618 +
22619 +       buffer += sprintf(buffer, "NID:\t%d\n", nx_task_nid(p));
22620 +
22621 +       nxi = task_get_nx_info(p);
22622 +       if (!nxi)
22623 +               goto out;
22624 +
22625 +       buffer += sprintf(buffer, "NCaps:\t%016llx\n",
22626 +               (unsigned long long)nxi->nx_ncaps);
22627 +       buffer += sprintf(buffer, "NFlags:\t%016llx\n",
22628 +               (unsigned long long)nxi->nx_flags);
22629 +
22630 +       buffer += sprintf(buffer,
22631 +               "V4Root[bcast]:\t" NIPQUAD_FMT "\n",
22632 +               NIPQUAD(nxi->v4_bcast.s_addr));
22633 +       buffer += sprintf (buffer,
22634 +               "V4Root[lback]:\t" NIPQUAD_FMT "\n",
22635 +               NIPQUAD(nxi->v4_lback.s_addr));
22636 +       if (!NX_IPV4(nxi))
22637 +               goto skip_v4;
22638 +       for (i = 0, v4a = &nxi->v4; v4a; i++, v4a = v4a->next)
22639 +               buffer += sprintf(buffer, "V4Root[%d]:\t" NXAV4_FMT "\n",
22640 +                       i, NXAV4(v4a));
22641 +skip_v4:
22642 +#ifdef CONFIG_IPV6
22643 +       if (!NX_IPV6(nxi))
22644 +               goto skip_v6;
22645 +       for (i = 0, v6a = &nxi->v6; v6a; i++, v6a = v6a->next)
22646 +               buffer += sprintf(buffer, "V6Root[%d]:\t" NXAV6_FMT "\n",
22647 +                       i, NXAV6(v6a));
22648 +skip_v6:
22649 +#endif
22650 +       put_nx_info(nxi);
22651 +out:
22652 +       return buffer - orig;
22653 +}
22654 +
22655 diff -NurpP --minimal linux-2.6.38.1/kernel/vserver/sched.c linux-2.6.38.1-vs2.3.0.37-rc9/kernel/vserver/sched.c
22656 --- linux-2.6.38.1/kernel/vserver/sched.c       1970-01-01 01:00:00.000000000 +0100
22657 +++ linux-2.6.38.1-vs2.3.0.37-rc9/kernel/vserver/sched.c        2011-01-29 02:01:07.000000000 +0100
22658 @@ -0,0 +1,82 @@
22659 +/*
22660 + *  linux/kernel/vserver/sched.c
22661 + *
22662 + *  Virtual Server: Scheduler Support
22663 + *
22664 + *  Copyright (C) 2004-2010  Herbert Pötzl
22665 + *
22666 + *  V0.01  adapted Sam Vilains version to 2.6.3
22667 + *  V0.02  removed legacy interface
22668 + *  V0.03  changed vcmds to vxi arg
22669 + *  V0.04  removed older and legacy interfaces
22670 + *  V0.05  removed scheduler code/commands
22671 + *
22672 + */
22673 +
22674 +#include <linux/vs_context.h>
22675 +#include <linux/vs_sched.h>
22676 +#include <linux/vserver/sched_cmd.h>
22677 +
22678 +#include <asm/uaccess.h>
22679 +
22680 +
22681 +void vx_update_sched_param(struct _vx_sched *sched,
22682 +       struct _vx_sched_pc *sched_pc)
22683 +{
22684 +       sched_pc->prio_bias = sched->prio_bias;
22685 +}
22686 +
22687 +static int do_set_prio_bias(struct vx_info *vxi, struct vcmd_prio_bias *data)
22688 +{
22689 +       int cpu;
22690 +
22691 +       if (data->prio_bias > MAX_PRIO_BIAS)
22692 +               data->prio_bias = MAX_PRIO_BIAS;
22693 +       if (data->prio_bias < MIN_PRIO_BIAS)
22694 +               data->prio_bias = MIN_PRIO_BIAS;
22695 +
22696 +       if (data->cpu_id != ~0) {
22697 +               vxi->sched.update = cpumask_of_cpu(data->cpu_id);
22698 +               cpus_and(vxi->sched.update, cpu_online_map,
22699 +                       vxi->sched.update);
22700 +       } else
22701 +               vxi->sched.update = cpu_online_map;
22702 +
22703 +       for_each_cpu_mask(cpu, vxi->sched.update)
22704 +               vx_update_sched_param(&vxi->sched,
22705 +                       &vx_per_cpu(vxi, sched_pc, cpu));
22706 +       return 0;
22707 +}
22708 +
22709 +int vc_set_prio_bias(struct vx_info *vxi, void __user *data)
22710 +{
22711 +       struct vcmd_prio_bias vc_data;
22712 +
22713 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
22714 +               return -EFAULT;
22715 +
22716 +       return do_set_prio_bias(vxi, &vc_data);
22717 +}
22718 +
22719 +int vc_get_prio_bias(struct vx_info *vxi, void __user *data)
22720 +{
22721 +       struct vcmd_prio_bias vc_data;
22722 +       struct _vx_sched_pc *pcd;
22723 +       int cpu;
22724 +
22725 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
22726 +               return -EFAULT;
22727 +
22728 +       cpu = vc_data.cpu_id;
22729 +
22730 +       if (!cpu_possible(cpu))
22731 +               return -EINVAL;
22732 +
22733 +       pcd = &vx_per_cpu(vxi, sched_pc, cpu);
22734 +       vc_data.prio_bias = pcd->prio_bias;
22735 +
22736 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
22737 +               return -EFAULT;
22738 +       return 0;
22739 +}
22740 +
22741 diff -NurpP --minimal linux-2.6.38.1/kernel/vserver/sched_init.h linux-2.6.38.1-vs2.3.0.37-rc9/kernel/vserver/sched_init.h
22742 --- linux-2.6.38.1/kernel/vserver/sched_init.h  1970-01-01 01:00:00.000000000 +0100
22743 +++ linux-2.6.38.1-vs2.3.0.37-rc9/kernel/vserver/sched_init.h   2011-01-29 02:01:07.000000000 +0100
22744 @@ -0,0 +1,27 @@
22745 +
22746 +static inline void vx_info_init_sched(struct _vx_sched *sched)
22747 +{
22748 +       /* scheduling; hard code starting values as constants */
22749 +       sched->prio_bias = 0;
22750 +}
22751 +
22752 +static inline
22753 +void vx_info_init_sched_pc(struct _vx_sched_pc *sched_pc, int cpu)
22754 +{
22755 +       sched_pc->prio_bias = 0;
22756 +
22757 +       sched_pc->user_ticks = 0;
22758 +       sched_pc->sys_ticks = 0;
22759 +       sched_pc->hold_ticks = 0;
22760 +}
22761 +
22762 +static inline void vx_info_exit_sched(struct _vx_sched *sched)
22763 +{
22764 +       return;
22765 +}
22766 +
22767 +static inline
22768 +void vx_info_exit_sched_pc(struct _vx_sched_pc *sched_pc, int cpu)
22769 +{
22770 +       return;
22771 +}
22772 diff -NurpP --minimal linux-2.6.38.1/kernel/vserver/sched_proc.h linux-2.6.38.1-vs2.3.0.37-rc9/kernel/vserver/sched_proc.h
22773 --- linux-2.6.38.1/kernel/vserver/sched_proc.h  1970-01-01 01:00:00.000000000 +0100
22774 +++ linux-2.6.38.1-vs2.3.0.37-rc9/kernel/vserver/sched_proc.h   2011-01-29 02:01:07.000000000 +0100
22775 @@ -0,0 +1,32 @@
22776 +#ifndef _VX_SCHED_PROC_H
22777 +#define _VX_SCHED_PROC_H
22778 +
22779 +
22780 +static inline
22781 +int vx_info_proc_sched(struct _vx_sched *sched, char *buffer)
22782 +{
22783 +       int length = 0;
22784 +
22785 +       length += sprintf(buffer,
22786 +               "PrioBias:\t%8d\n",
22787 +               sched->prio_bias);
22788 +       return length;
22789 +}
22790 +
22791 +static inline
22792 +int vx_info_proc_sched_pc(struct _vx_sched_pc *sched_pc,
22793 +       char *buffer, int cpu)
22794 +{
22795 +       int length = 0;
22796 +
22797 +       length += sprintf(buffer + length,
22798 +               "cpu %d: %lld %lld %lld", cpu,
22799 +               (unsigned long long)sched_pc->user_ticks,
22800 +               (unsigned long long)sched_pc->sys_ticks,
22801 +               (unsigned long long)sched_pc->hold_ticks);
22802 +       length += sprintf(buffer + length,
22803 +               " %d\n", sched_pc->prio_bias);
22804 +       return length;
22805 +}
22806 +
22807 +#endif /* _VX_SCHED_PROC_H */
22808 diff -NurpP --minimal linux-2.6.38.1/kernel/vserver/signal.c linux-2.6.38.1-vs2.3.0.37-rc9/kernel/vserver/signal.c
22809 --- linux-2.6.38.1/kernel/vserver/signal.c      1970-01-01 01:00:00.000000000 +0100
22810 +++ linux-2.6.38.1-vs2.3.0.37-rc9/kernel/vserver/signal.c       2011-03-22 17:37:59.000000000 +0100
22811 @@ -0,0 +1,134 @@
22812 +/*
22813 + *  linux/kernel/vserver/signal.c
22814 + *
22815 + *  Virtual Server: Signal Support
22816 + *
22817 + *  Copyright (C) 2003-2007  Herbert Pötzl
22818 + *
22819 + *  V0.01  broken out from vcontext V0.05
22820 + *  V0.02  changed vcmds to vxi arg
22821 + *  V0.03  adjusted siginfo for kill
22822 + *
22823 + */
22824 +
22825 +#include <asm/uaccess.h>
22826 +
22827 +#include <linux/vs_context.h>
22828 +#include <linux/vs_pid.h>
22829 +#include <linux/vserver/signal_cmd.h>
22830 +
22831 +
22832 +int vx_info_kill(struct vx_info *vxi, int pid, int sig)
22833 +{
22834 +       int retval, count = 0;
22835 +       struct task_struct *p;
22836 +       struct siginfo *sip = SEND_SIG_PRIV;
22837 +
22838 +       retval = -ESRCH;
22839 +       vxdprintk(VXD_CBIT(misc, 4),
22840 +               "vx_info_kill(%p[#%d],%d,%d)*",
22841 +               vxi, vxi->vx_id, pid, sig);
22842 +       read_lock(&tasklist_lock);
22843 +       switch (pid) {
22844 +       case  0:
22845 +       case -1:
22846 +               for_each_process(p) {
22847 +                       int err = 0;
22848 +
22849 +                       if (vx_task_xid(p) != vxi->vx_id || p->pid <= 1 ||
22850 +                               (pid && vxi->vx_initpid == p->pid))
22851 +                               continue;
22852 +
22853 +                       err = group_send_sig_info(sig, sip, p);
22854 +                       ++count;
22855 +                       if (err != -EPERM)
22856 +                               retval = err;
22857 +               }
22858 +               break;
22859 +
22860 +       case 1:
22861 +               if (vxi->vx_initpid) {
22862 +                       pid = vxi->vx_initpid;
22863 +                       /* for now, only SIGINT to private init ... */
22864 +                       if (!vx_info_flags(vxi, VXF_STATE_ADMIN, 0) &&
22865 +                               /* ... as long as there are tasks left */
22866 +                               (atomic_read(&vxi->vx_tasks) > 1))
22867 +                               sig = SIGINT;
22868 +               }
22869 +               /* fallthrough */
22870 +       default:
22871 +               rcu_read_lock();
22872 +               p = find_task_by_real_pid(pid);
22873 +               rcu_read_unlock();
22874 +               if (p) {
22875 +                       if (vx_task_xid(p) == vxi->vx_id)
22876 +                               retval = group_send_sig_info(sig, sip, p);
22877 +               }
22878 +               break;
22879 +       }
22880 +       read_unlock(&tasklist_lock);
22881 +       vxdprintk(VXD_CBIT(misc, 4),
22882 +               "vx_info_kill(%p[#%d],%d,%d,%ld) = %d",
22883 +               vxi, vxi->vx_id, pid, sig, (long)sip, retval);
22884 +       return retval;
22885 +}
22886 +
22887 +int vc_ctx_kill(struct vx_info *vxi, void __user *data)
22888 +{
22889 +       struct vcmd_ctx_kill_v0 vc_data;
22890 +
22891 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
22892 +               return -EFAULT;
22893 +
22894 +       /* special check to allow guest shutdown */
22895 +       if (!vx_info_flags(vxi, VXF_STATE_ADMIN, 0) &&
22896 +               /* forbid killall pid=0 when init is present */
22897 +               (((vc_data.pid < 1) && vxi->vx_initpid) ||
22898 +               (vc_data.pid > 1)))
22899 +               return -EACCES;
22900 +
22901 +       return vx_info_kill(vxi, vc_data.pid, vc_data.sig);
22902 +}
22903 +
22904 +
22905 +static int __wait_exit(struct vx_info *vxi)
22906 +{
22907 +       DECLARE_WAITQUEUE(wait, current);
22908 +       int ret = 0;
22909 +
22910 +       add_wait_queue(&vxi->vx_wait, &wait);
22911 +       set_current_state(TASK_INTERRUPTIBLE);
22912 +
22913 +wait:
22914 +       if (vx_info_state(vxi,
22915 +               VXS_SHUTDOWN | VXS_HASHED | VXS_HELPER) == VXS_SHUTDOWN)
22916 +               goto out;
22917 +       if (signal_pending(current)) {
22918 +               ret = -ERESTARTSYS;
22919 +               goto out;
22920 +       }
22921 +       schedule();
22922 +       goto wait;
22923 +
22924 +out:
22925 +       set_current_state(TASK_RUNNING);
22926 +       remove_wait_queue(&vxi->vx_wait, &wait);
22927 +       return ret;
22928 +}
22929 +
22930 +
22931 +
22932 +int vc_wait_exit(struct vx_info *vxi, void __user *data)
22933 +{
22934 +       struct vcmd_wait_exit_v0 vc_data;
22935 +       int ret;
22936 +
22937 +       ret = __wait_exit(vxi);
22938 +       vc_data.reboot_cmd = vxi->reboot_cmd;
22939 +       vc_data.exit_code = vxi->exit_code;
22940 +
22941 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
22942 +               ret = -EFAULT;
22943 +       return ret;
22944 +}
22945 +
22946 diff -NurpP --minimal linux-2.6.38.1/kernel/vserver/space.c linux-2.6.38.1-vs2.3.0.37-rc9/kernel/vserver/space.c
22947 --- linux-2.6.38.1/kernel/vserver/space.c       1970-01-01 01:00:00.000000000 +0100
22948 +++ linux-2.6.38.1-vs2.3.0.37-rc9/kernel/vserver/space.c        2011-02-01 03:30:46.000000000 +0100
22949 @@ -0,0 +1,417 @@
22950 +/*
22951 + *  linux/kernel/vserver/space.c
22952 + *
22953 + *  Virtual Server: Context Space Support
22954 + *
22955 + *  Copyright (C) 2003-2010  Herbert Pötzl
22956 + *
22957 + *  V0.01  broken out from context.c 0.07
22958 + *  V0.02  added task locking for namespace
22959 + *  V0.03  broken out vx_enter_namespace
22960 + *  V0.04  added *space support and commands
22961 + *  V0.05  added credential support
22962 + *
22963 + */
22964 +
22965 +#include <linux/utsname.h>
22966 +#include <linux/nsproxy.h>
22967 +#include <linux/err.h>
22968 +#include <linux/fs_struct.h>
22969 +#include <linux/cred.h>
22970 +#include <asm/uaccess.h>
22971 +
22972 +#include <linux/vs_context.h>
22973 +#include <linux/vserver/space.h>
22974 +#include <linux/vserver/space_cmd.h>
22975 +
22976 +atomic_t vs_global_nsproxy     = ATOMIC_INIT(0);
22977 +atomic_t vs_global_fs          = ATOMIC_INIT(0);
22978 +atomic_t vs_global_mnt_ns      = ATOMIC_INIT(0);
22979 +atomic_t vs_global_uts_ns      = ATOMIC_INIT(0);
22980 +atomic_t vs_global_user_ns     = ATOMIC_INIT(0);
22981 +atomic_t vs_global_pid_ns      = ATOMIC_INIT(0);
22982 +
22983 +
22984 +/* namespace functions */
22985 +
22986 +#include <linux/mnt_namespace.h>
22987 +#include <linux/user_namespace.h>
22988 +#include <linux/pid_namespace.h>
22989 +#include <linux/ipc_namespace.h>
22990 +#include <net/net_namespace.h>
22991 +
22992 +
22993 +static const struct vcmd_space_mask_v1 space_mask_v0 = {
22994 +       .mask = CLONE_FS |
22995 +               CLONE_NEWNS |
22996 +               CLONE_NEWUTS |
22997 +               CLONE_NEWIPC |
22998 +               CLONE_NEWUSER |
22999 +               0
23000 +};
23001 +
23002 +static const struct vcmd_space_mask_v1 space_mask = {
23003 +       .mask = CLONE_FS |
23004 +               CLONE_NEWNS |
23005 +               CLONE_NEWUTS |
23006 +               CLONE_NEWIPC |
23007 +               CLONE_NEWUSER |
23008 +#ifdef CONFIG_PID_NS
23009 +               CLONE_NEWPID |
23010 +#endif
23011 +#ifdef CONFIG_NET_NS
23012 +               CLONE_NEWNET |
23013 +#endif
23014 +               0
23015 +};
23016 +
23017 +static const struct vcmd_space_mask_v1 default_space_mask = {
23018 +       .mask = CLONE_FS |
23019 +               CLONE_NEWNS |
23020 +               CLONE_NEWUTS |
23021 +               CLONE_NEWIPC |
23022 +               CLONE_NEWUSER |
23023 +#ifdef CONFIG_PID_NS
23024 +//             CLONE_NEWPID |
23025 +#endif
23026 +               0
23027 +};
23028 +
23029 +/*
23030 + *     build a new nsproxy mix
23031 + *      assumes that both proxies are 'const'
23032 + *     does not touch nsproxy refcounts
23033 + *     will hold a reference on the result.
23034 + */
23035 +
23036 +struct nsproxy *vs_mix_nsproxy(struct nsproxy *old_nsproxy,
23037 +       struct nsproxy *new_nsproxy, unsigned long mask)
23038 +{
23039 +       struct mnt_namespace *old_ns;
23040 +       struct uts_namespace *old_uts;
23041 +       struct ipc_namespace *old_ipc;
23042 +#ifdef CONFIG_PID_NS
23043 +       struct pid_namespace *old_pid;
23044 +#endif
23045 +#ifdef CONFIG_NET_NS
23046 +       struct net *old_net;
23047 +#endif
23048 +       struct nsproxy *nsproxy;
23049 +
23050 +       nsproxy = copy_nsproxy(old_nsproxy);
23051 +       if (!nsproxy)
23052 +               goto out;
23053 +
23054 +       if (mask & CLONE_NEWNS) {
23055 +               old_ns = nsproxy->mnt_ns;
23056 +               nsproxy->mnt_ns = new_nsproxy->mnt_ns;
23057 +               if (nsproxy->mnt_ns)
23058 +                       get_mnt_ns(nsproxy->mnt_ns);
23059 +       } else
23060 +               old_ns = NULL;
23061 +
23062 +       if (mask & CLONE_NEWUTS) {
23063 +               old_uts = nsproxy->uts_ns;
23064 +               nsproxy->uts_ns = new_nsproxy->uts_ns;
23065 +               if (nsproxy->uts_ns)
23066 +                       get_uts_ns(nsproxy->uts_ns);
23067 +       } else
23068 +               old_uts = NULL;
23069 +
23070 +       if (mask & CLONE_NEWIPC) {
23071 +               old_ipc = nsproxy->ipc_ns;
23072 +               nsproxy->ipc_ns = new_nsproxy->ipc_ns;
23073 +               if (nsproxy->ipc_ns)
23074 +                       get_ipc_ns(nsproxy->ipc_ns);
23075 +       } else
23076 +               old_ipc = NULL;
23077 +
23078 +#ifdef CONFIG_PID_NS
23079 +       if (mask & CLONE_NEWPID) {
23080 +               old_pid = nsproxy->pid_ns;
23081 +               nsproxy->pid_ns = new_nsproxy->pid_ns;
23082 +               if (nsproxy->pid_ns)
23083 +                       get_pid_ns(nsproxy->pid_ns);
23084 +       } else
23085 +               old_pid = NULL;
23086 +#endif
23087 +#ifdef CONFIG_NET_NS
23088 +       if (mask & CLONE_NEWNET) {
23089 +               old_net = nsproxy->net_ns;
23090 +               nsproxy->net_ns = new_nsproxy->net_ns;
23091 +               if (nsproxy->net_ns)
23092 +                       get_net(nsproxy->net_ns);
23093 +       } else
23094 +               old_net = NULL;
23095 +#endif
23096 +       if (old_ns)
23097 +               put_mnt_ns(old_ns);
23098 +       if (old_uts)
23099 +               put_uts_ns(old_uts);
23100 +       if (old_ipc)
23101 +               put_ipc_ns(old_ipc);
23102 +#ifdef CONFIG_PID_NS
23103 +       if (old_pid)
23104 +               put_pid_ns(old_pid);
23105 +#endif
23106 +#ifdef CONFIG_NET_NS
23107 +       if (old_net)
23108 +               put_net(old_net);
23109 +#endif
23110 +out:
23111 +       return nsproxy;
23112 +}
23113 +
23114 +
23115 +/*
23116 + *     merge two nsproxy structs into a new one.
23117 + *     will hold a reference on the result.
23118 + */
23119 +
23120 +static inline
23121 +struct nsproxy *__vs_merge_nsproxy(struct nsproxy *old,
23122 +       struct nsproxy *proxy, unsigned long mask)
23123 +{
23124 +       struct nsproxy null_proxy = { .mnt_ns = NULL };
23125 +
23126 +       if (!proxy)
23127 +               return NULL;
23128 +
23129 +       if (mask) {
23130 +               /* vs_mix_nsproxy returns with reference */
23131 +               return vs_mix_nsproxy(old ? old : &null_proxy,
23132 +                       proxy, mask);
23133 +       }
23134 +       get_nsproxy(proxy);
23135 +       return proxy;
23136 +}
23137 +
23138 +
23139 +int vx_enter_space(struct vx_info *vxi, unsigned long mask, unsigned index)
23140 +{
23141 +       struct nsproxy *proxy, *proxy_cur, *proxy_new;
23142 +       struct fs_struct *fs_cur, *fs = NULL;
23143 +       struct _vx_space *space;
23144 +       int ret, kill = 0;
23145 +
23146 +       vxdprintk(VXD_CBIT(space, 8), "vx_enter_space(%p[#%u],0x%08lx,%d)",
23147 +               vxi, vxi->vx_id, mask, index);
23148 +
23149 +       if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0))
23150 +               return -EACCES;
23151 +
23152 +       if (index >= VX_SPACES)
23153 +               return -EINVAL;
23154 +
23155 +       space = &vxi->space[index];
23156 +
23157 +       if (!mask)
23158 +               mask = space->vx_nsmask;
23159 +
23160 +       if ((mask & space->vx_nsmask) != mask)
23161 +               return -EINVAL;
23162 +
23163 +       if (mask & CLONE_FS) {
23164 +               fs = copy_fs_struct(space->vx_fs);
23165 +               if (!fs)
23166 +                       return -ENOMEM;
23167 +       }
23168 +       proxy = space->vx_nsproxy;
23169 +
23170 +       vxdprintk(VXD_CBIT(space, 9),
23171 +               "vx_enter_space(%p[#%u],0x%08lx,%d) -> (%p,%p)",
23172 +               vxi, vxi->vx_id, mask, index, proxy, fs);
23173 +
23174 +       task_lock(current);
23175 +       fs_cur = current->fs;
23176 +
23177 +       if (mask & CLONE_FS) {
23178 +               spin_lock(&fs_cur->lock);
23179 +               current->fs = fs;
23180 +               kill = !--fs_cur->users;
23181 +               spin_unlock(&fs_cur->lock);
23182 +       }
23183 +
23184 +       proxy_cur = current->nsproxy;
23185 +       get_nsproxy(proxy_cur);
23186 +       task_unlock(current);
23187 +
23188 +       if (kill)
23189 +               free_fs_struct(fs_cur);
23190 +
23191 +       proxy_new = __vs_merge_nsproxy(proxy_cur, proxy, mask);
23192 +       if (IS_ERR(proxy_new)) {
23193 +               ret = PTR_ERR(proxy_new);
23194 +               goto out_put;
23195 +       }
23196 +
23197 +       proxy_new = xchg(&current->nsproxy, proxy_new);
23198 +
23199 +       if (mask & CLONE_NEWUSER) {
23200 +               struct cred *cred;
23201 +
23202 +               vxdprintk(VXD_CBIT(space, 10),
23203 +                       "vx_enter_space(%p[#%u],%p) cred (%p,%p)",
23204 +                       vxi, vxi->vx_id, space->vx_cred,
23205 +                       current->real_cred, current->cred);
23206 +
23207 +               if (space->vx_cred) {
23208 +                       cred = __prepare_creds(space->vx_cred);
23209 +                       if (cred)
23210 +                               commit_creds(cred);
23211 +               }
23212 +       }
23213 +
23214 +       ret = 0;
23215 +
23216 +       if (proxy_new)
23217 +               put_nsproxy(proxy_new);
23218 +out_put:
23219 +       if (proxy_cur)
23220 +               put_nsproxy(proxy_cur);
23221 +       return ret;
23222 +}
23223 +
23224 +
23225 +int vx_set_space(struct vx_info *vxi, unsigned long mask, unsigned index)
23226 +{
23227 +       struct nsproxy *proxy_vxi, *proxy_cur, *proxy_new;
23228 +       struct fs_struct *fs_vxi, *fs;
23229 +       struct _vx_space *space;
23230 +       int ret, kill = 0;
23231 +
23232 +       vxdprintk(VXD_CBIT(space, 8), "vx_set_space(%p[#%u],0x%08lx,%d)",
23233 +               vxi, vxi->vx_id, mask, index);
23234 +
23235 +       if ((mask & space_mask.mask) != mask)
23236 +               return -EINVAL;
23237 +
23238 +       if (index >= VX_SPACES)
23239 +               return -EINVAL;
23240 +
23241 +       space = &vxi->space[index];
23242 +
23243 +       proxy_vxi = space->vx_nsproxy;
23244 +       fs_vxi = space->vx_fs;
23245 +
23246 +       if (mask & CLONE_FS) {
23247 +               fs = copy_fs_struct(current->fs);
23248 +               if (!fs)
23249 +                       return -ENOMEM;
23250 +       }
23251 +
23252 +       task_lock(current);
23253 +
23254 +       if (mask & CLONE_FS) {
23255 +               spin_lock(&fs_vxi->lock);
23256 +               space->vx_fs = fs;
23257 +               kill = !--fs_vxi->users;
23258 +               spin_unlock(&fs_vxi->lock);
23259 +       }
23260 +
23261 +       proxy_cur = current->nsproxy;
23262 +       get_nsproxy(proxy_cur);
23263 +       task_unlock(current);
23264 +
23265 +       if (kill)
23266 +               free_fs_struct(fs_vxi);
23267 +
23268 +       proxy_new = __vs_merge_nsproxy(proxy_vxi, proxy_cur, mask);
23269 +       if (IS_ERR(proxy_new)) {
23270 +               ret = PTR_ERR(proxy_new);
23271 +               goto out_put;
23272 +       }
23273 +
23274 +       proxy_new = xchg(&space->vx_nsproxy, proxy_new);
23275 +       space->vx_nsmask |= mask;
23276 +
23277 +       if (mask & CLONE_NEWUSER) {
23278 +               struct cred *cred;
23279 +
23280 +               vxdprintk(VXD_CBIT(space, 10),
23281 +                       "vx_set_space(%p[#%u],%p) cred (%p,%p)",
23282 +                       vxi, vxi->vx_id, space->vx_cred,
23283 +                       current->real_cred, current->cred);
23284 +
23285 +               cred = prepare_creds();
23286 +               cred = (struct cred *)xchg(&space->vx_cred, cred);
23287 +               if (cred)
23288 +                       abort_creds(cred);
23289 +       }
23290 +
23291 +       ret = 0;
23292 +
23293 +       if (proxy_new)
23294 +               put_nsproxy(proxy_new);
23295 +out_put:
23296 +       if (proxy_cur)
23297 +               put_nsproxy(proxy_cur);
23298 +       return ret;
23299 +}
23300 +
23301 +
23302 +int vc_enter_space_v1(struct vx_info *vxi, void __user *data)
23303 +{
23304 +       struct vcmd_space_mask_v1 vc_data = { .mask = 0 };
23305 +
23306 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
23307 +               return -EFAULT;
23308 +
23309 +       return vx_enter_space(vxi, vc_data.mask, 0);
23310 +}
23311 +
23312 +int vc_enter_space(struct vx_info *vxi, void __user *data)
23313 +{
23314 +       struct vcmd_space_mask_v2 vc_data = { .mask = 0 };
23315 +
23316 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
23317 +               return -EFAULT;
23318 +
23319 +       if (vc_data.index >= VX_SPACES)
23320 +               return -EINVAL;
23321 +
23322 +       return vx_enter_space(vxi, vc_data.mask, vc_data.index);
23323 +}
23324 +
23325 +int vc_set_space_v1(struct vx_info *vxi, void __user *data)
23326 +{
23327 +       struct vcmd_space_mask_v1 vc_data = { .mask = 0 };
23328 +
23329 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
23330 +               return -EFAULT;
23331 +
23332 +       return vx_set_space(vxi, vc_data.mask, 0);
23333 +}
23334 +
23335 +int vc_set_space(struct vx_info *vxi, void __user *data)
23336 +{
23337 +       struct vcmd_space_mask_v2 vc_data = { .mask = 0 };
23338 +
23339 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
23340 +               return -EFAULT;
23341 +
23342 +       if (vc_data.index >= VX_SPACES)
23343 +               return -EINVAL;
23344 +
23345 +       return vx_set_space(vxi, vc_data.mask, vc_data.index);
23346 +}
23347 +
23348 +int vc_get_space_mask(void __user *data, int type)
23349 +{
23350 +       const struct vcmd_space_mask_v1 *mask;
23351 +
23352 +       if (type == 0)
23353 +               mask = &space_mask_v0;
23354 +       else if (type == 1)
23355 +               mask = &space_mask;
23356 +       else
23357 +               mask = &default_space_mask;
23358 +
23359 +       vxdprintk(VXD_CBIT(space, 10),
23360 +               "vc_get_space_mask(%d) = %08llx", type, mask->mask);
23361 +
23362 +       if (copy_to_user(data, mask, sizeof(*mask)))
23363 +               return -EFAULT;
23364 +       return 0;
23365 +}
23366 +
23367 diff -NurpP --minimal linux-2.6.38.1/kernel/vserver/switch.c linux-2.6.38.1-vs2.3.0.37-rc9/kernel/vserver/switch.c
23368 --- linux-2.6.38.1/kernel/vserver/switch.c      1970-01-01 01:00:00.000000000 +0100
23369 +++ linux-2.6.38.1-vs2.3.0.37-rc9/kernel/vserver/switch.c       2011-01-29 02:01:07.000000000 +0100
23370 @@ -0,0 +1,531 @@
23371 +/*
23372 + *  linux/kernel/vserver/switch.c
23373 + *
23374 + *  Virtual Server: Syscall Switch
23375 + *
23376 + *  Copyright (C) 2003-2007  Herbert Pötzl
23377 + *
23378 + *  V0.01  syscall switch
23379 + *  V0.02  added signal to context
23380 + *  V0.03  added rlimit functions
23381 + *  V0.04  added iattr, task/xid functions
23382 + *  V0.05  added debug/history stuff
23383 + *  V0.06  added compat32 layer
23384 + *  V0.07  vcmd args and perms
23385 + *  V0.08  added status commands
23386 + *  V0.09  added tag commands
23387 + *  V0.10  added oom bias
23388 + *  V0.11  added device commands
23389 + *
23390 + */
23391 +
23392 +#include <linux/vs_context.h>
23393 +#include <linux/vs_network.h>
23394 +#include <linux/vserver/switch.h>
23395 +
23396 +#include "vci_config.h"
23397 +
23398 +
23399 +static inline
23400 +int vc_get_version(uint32_t id)
23401 +{
23402 +       return VCI_VERSION;
23403 +}
23404 +
23405 +static inline
23406 +int vc_get_vci(uint32_t id)
23407 +{
23408 +       return vci_kernel_config();
23409 +}
23410 +
23411 +#include <linux/vserver/context_cmd.h>
23412 +#include <linux/vserver/cvirt_cmd.h>
23413 +#include <linux/vserver/cacct_cmd.h>
23414 +#include <linux/vserver/limit_cmd.h>
23415 +#include <linux/vserver/network_cmd.h>
23416 +#include <linux/vserver/sched_cmd.h>
23417 +#include <linux/vserver/debug_cmd.h>
23418 +#include <linux/vserver/inode_cmd.h>
23419 +#include <linux/vserver/dlimit_cmd.h>
23420 +#include <linux/vserver/signal_cmd.h>
23421 +#include <linux/vserver/space_cmd.h>
23422 +#include <linux/vserver/tag_cmd.h>
23423 +#include <linux/vserver/device_cmd.h>
23424 +
23425 +#include <linux/vserver/inode.h>
23426 +#include <linux/vserver/dlimit.h>
23427 +
23428 +
23429 +#ifdef CONFIG_COMPAT
23430 +#define __COMPAT(name, id, data, compat)       \
23431 +       (compat) ? name ## _x32(id, data) : name(id, data)
23432 +#define __COMPAT_NO_ID(name, data, compat)     \
23433 +       (compat) ? name ## _x32(data) : name(data)
23434 +#else
23435 +#define __COMPAT(name, id, data, compat)       \
23436 +       name(id, data)
23437 +#define __COMPAT_NO_ID(name, data, compat)     \
23438 +       name(data)
23439 +#endif
23440 +
23441 +
23442 +static inline
23443 +long do_vcmd(uint32_t cmd, uint32_t id,
23444 +       struct vx_info *vxi, struct nx_info *nxi,
23445 +       void __user *data, int compat)
23446 +{
23447 +       switch (cmd) {
23448 +
23449 +       case VCMD_get_version:
23450 +               return vc_get_version(id);
23451 +       case VCMD_get_vci:
23452 +               return vc_get_vci(id);
23453 +
23454 +       case VCMD_task_xid:
23455 +               return vc_task_xid(id);
23456 +       case VCMD_vx_info:
23457 +               return vc_vx_info(vxi, data);
23458 +
23459 +       case VCMD_task_nid:
23460 +               return vc_task_nid(id);
23461 +       case VCMD_nx_info:
23462 +               return vc_nx_info(nxi, data);
23463 +
23464 +       case VCMD_task_tag:
23465 +               return vc_task_tag(id);
23466 +
23467 +       case VCMD_set_space_v1:
23468 +               return vc_set_space_v1(vxi, data);
23469 +       /* this is version 2 */
23470 +       case VCMD_set_space:
23471 +               return vc_set_space(vxi, data);
23472 +
23473 +       case VCMD_get_space_mask_v0:
23474 +               return vc_get_space_mask(data, 0);
23475 +       /* this is version 1 */
23476 +       case VCMD_get_space_mask:
23477 +               return vc_get_space_mask(data, 1);
23478 +
23479 +       case VCMD_get_space_default:
23480 +               return vc_get_space_mask(data, -1);
23481 +
23482 +#ifdef CONFIG_IA32_EMULATION
23483 +       case VCMD_get_rlimit:
23484 +               return __COMPAT(vc_get_rlimit, vxi, data, compat);
23485 +       case VCMD_set_rlimit:
23486 +               return __COMPAT(vc_set_rlimit, vxi, data, compat);
23487 +#else
23488 +       case VCMD_get_rlimit:
23489 +               return vc_get_rlimit(vxi, data);
23490 +       case VCMD_set_rlimit:
23491 +               return vc_set_rlimit(vxi, data);
23492 +#endif
23493 +       case VCMD_get_rlimit_mask:
23494 +               return vc_get_rlimit_mask(id, data);
23495 +       case VCMD_reset_hits:
23496 +               return vc_reset_hits(vxi, data);
23497 +       case VCMD_reset_minmax:
23498 +               return vc_reset_minmax(vxi, data);
23499 +
23500 +       case VCMD_get_vhi_name:
23501 +               return vc_get_vhi_name(vxi, data);
23502 +       case VCMD_set_vhi_name:
23503 +               return vc_set_vhi_name(vxi, data);
23504 +
23505 +       case VCMD_ctx_stat:
23506 +               return vc_ctx_stat(vxi, data);
23507 +       case VCMD_virt_stat:
23508 +               return vc_virt_stat(vxi, data);
23509 +       case VCMD_sock_stat:
23510 +               return vc_sock_stat(vxi, data);
23511 +       case VCMD_rlimit_stat:
23512 +               return vc_rlimit_stat(vxi, data);
23513 +
23514 +       case VCMD_set_cflags:
23515 +               return vc_set_cflags(vxi, data);
23516 +       case VCMD_get_cflags:
23517 +               return vc_get_cflags(vxi, data);
23518 +
23519 +       /* this is version 1 */
23520 +       case VCMD_set_ccaps:
23521 +               return vc_set_ccaps(vxi, data);
23522 +       /* this is version 1 */
23523 +       case VCMD_get_ccaps:
23524 +               return vc_get_ccaps(vxi, data);
23525 +       case VCMD_set_bcaps:
23526 +               return vc_set_bcaps(vxi, data);
23527 +       case VCMD_get_bcaps:
23528 +               return vc_get_bcaps(vxi, data);
23529 +
23530 +       case VCMD_set_badness:
23531 +               return vc_set_badness(vxi, data);
23532 +       case VCMD_get_badness:
23533 +               return vc_get_badness(vxi, data);
23534 +
23535 +       case VCMD_set_nflags:
23536 +               return vc_set_nflags(nxi, data);
23537 +       case VCMD_get_nflags:
23538 +               return vc_get_nflags(nxi, data);
23539 +
23540 +       case VCMD_set_ncaps:
23541 +               return vc_set_ncaps(nxi, data);
23542 +       case VCMD_get_ncaps:
23543 +               return vc_get_ncaps(nxi, data);
23544 +
23545 +       case VCMD_set_prio_bias:
23546 +               return vc_set_prio_bias(vxi, data);
23547 +       case VCMD_get_prio_bias:
23548 +               return vc_get_prio_bias(vxi, data);
23549 +       case VCMD_add_dlimit:
23550 +               return __COMPAT(vc_add_dlimit, id, data, compat);
23551 +       case VCMD_rem_dlimit:
23552 +               return __COMPAT(vc_rem_dlimit, id, data, compat);
23553 +       case VCMD_set_dlimit:
23554 +               return __COMPAT(vc_set_dlimit, id, data, compat);
23555 +       case VCMD_get_dlimit:
23556 +               return __COMPAT(vc_get_dlimit, id, data, compat);
23557 +
23558 +       case VCMD_ctx_kill:
23559 +               return vc_ctx_kill(vxi, data);
23560 +
23561 +       case VCMD_wait_exit:
23562 +               return vc_wait_exit(vxi, data);
23563 +
23564 +       case VCMD_get_iattr:
23565 +               return __COMPAT_NO_ID(vc_get_iattr, data, compat);
23566 +       case VCMD_set_iattr:
23567 +               return __COMPAT_NO_ID(vc_set_iattr, data, compat);
23568 +
23569 +       case VCMD_fget_iattr:
23570 +               return vc_fget_iattr(id, data);
23571 +       case VCMD_fset_iattr:
23572 +               return vc_fset_iattr(id, data);
23573 +
23574 +       case VCMD_enter_space_v0:
23575 +               return vc_enter_space_v1(vxi, NULL);
23576 +       case VCMD_enter_space_v1:
23577 +               return vc_enter_space_v1(vxi, data);
23578 +       /* this is version 2 */
23579 +       case VCMD_enter_space:
23580 +               return vc_enter_space(vxi, data);
23581 +
23582 +       case VCMD_ctx_create_v0:
23583 +               return vc_ctx_create(id, NULL);
23584 +       case VCMD_ctx_create:
23585 +               return vc_ctx_create(id, data);
23586 +       case VCMD_ctx_migrate_v0:
23587 +               return vc_ctx_migrate(vxi, NULL);
23588 +       case VCMD_ctx_migrate:
23589 +               return vc_ctx_migrate(vxi, data);
23590 +
23591 +       case VCMD_net_create_v0:
23592 +               return vc_net_create(id, NULL);
23593 +       case VCMD_net_create:
23594 +               return vc_net_create(id, data);
23595 +       case VCMD_net_migrate:
23596 +               return vc_net_migrate(nxi, data);
23597 +
23598 +       case VCMD_tag_migrate:
23599 +               return vc_tag_migrate(id);
23600 +
23601 +       case VCMD_net_add:
23602 +               return vc_net_add(nxi, data);
23603 +       case VCMD_net_remove:
23604 +               return vc_net_remove(nxi, data);
23605 +
23606 +       case VCMD_net_add_ipv4:
23607 +               return vc_net_add_ipv4(nxi, data);
23608 +       case VCMD_net_remove_ipv4:
23609 +               return vc_net_remove_ipv4(nxi, data);
23610 +#ifdef CONFIG_IPV6
23611 +       case VCMD_net_add_ipv6:
23612 +               return vc_net_add_ipv6(nxi, data);
23613 +       case VCMD_net_remove_ipv6:
23614 +               return vc_net_remove_ipv6(nxi, data);
23615 +#endif
23616 +/*     case VCMD_add_match_ipv4:
23617 +               return vc_add_match_ipv4(nxi, data);
23618 +       case VCMD_get_match_ipv4:
23619 +               return vc_get_match_ipv4(nxi, data);
23620 +#ifdef CONFIG_IPV6
23621 +       case VCMD_add_match_ipv6:
23622 +               return vc_add_match_ipv6(nxi, data);
23623 +       case VCMD_get_match_ipv6:
23624 +               return vc_get_match_ipv6(nxi, data);
23625 +#endif */
23626 +
23627 +#ifdef CONFIG_VSERVER_DEVICE
23628 +       case VCMD_set_mapping:
23629 +               return __COMPAT(vc_set_mapping, vxi, data, compat);
23630 +       case VCMD_unset_mapping:
23631 +               return __COMPAT(vc_unset_mapping, vxi, data, compat);
23632 +#endif
23633 +#ifdef CONFIG_VSERVER_HISTORY
23634 +       case VCMD_dump_history:
23635 +               return vc_dump_history(id);
23636 +       case VCMD_read_history:
23637 +               return __COMPAT(vc_read_history, id, data, compat);
23638 +#endif
23639 +       default:
23640 +               vxwprintk_task(1, "unimplemented VCMD_%02d_%d[%d]",
23641 +                       VC_CATEGORY(cmd), VC_COMMAND(cmd), VC_VERSION(cmd));
23642 +       }
23643 +       return -ENOSYS;
23644 +}
23645 +
23646 +
23647 +#define        __VCMD(vcmd, _perm, _args, _flags)              \
23648 +       case VCMD_ ## vcmd: perm = _perm;               \
23649 +               args = _args; flags = _flags; break
23650 +
23651 +
23652 +#define VCA_NONE       0x00
23653 +#define VCA_VXI                0x01
23654 +#define VCA_NXI                0x02
23655 +
23656 +#define VCF_NONE       0x00
23657 +#define VCF_INFO       0x01
23658 +#define VCF_ADMIN      0x02
23659 +#define VCF_ARES       0x06    /* includes admin */
23660 +#define VCF_SETUP      0x08
23661 +
23662 +#define VCF_ZIDOK      0x10    /* zero id okay */
23663 +
23664 +
23665 +static inline
23666 +long do_vserver(uint32_t cmd, uint32_t id, void __user *data, int compat)
23667 +{
23668 +       long ret;
23669 +       int permit = -1, state = 0;
23670 +       int perm = -1, args = 0, flags = 0;
23671 +       struct vx_info *vxi = NULL;
23672 +       struct nx_info *nxi = NULL;
23673 +
23674 +       switch (cmd) {
23675 +       /* unpriviledged commands */
23676 +       __VCMD(get_version,      0, VCA_NONE,   0);
23677 +       __VCMD(get_vci,          0, VCA_NONE,   0);
23678 +       __VCMD(get_rlimit_mask,  0, VCA_NONE,   0);
23679 +       __VCMD(get_space_mask_v0,0, VCA_NONE,   0);
23680 +       __VCMD(get_space_mask,   0, VCA_NONE,   0);
23681 +       __VCMD(get_space_default,0, VCA_NONE,   0);
23682 +
23683 +       /* info commands */
23684 +       __VCMD(task_xid,         2, VCA_NONE,   0);
23685 +       __VCMD(reset_hits,       2, VCA_VXI,    0);
23686 +       __VCMD(reset_minmax,     2, VCA_VXI,    0);
23687 +       __VCMD(vx_info,          3, VCA_VXI,    VCF_INFO);
23688 +       __VCMD(get_bcaps,        3, VCA_VXI,    VCF_INFO);
23689 +       __VCMD(get_ccaps,        3, VCA_VXI,    VCF_INFO);
23690 +       __VCMD(get_cflags,       3, VCA_VXI,    VCF_INFO);
23691 +       __VCMD(get_badness,      3, VCA_VXI,    VCF_INFO);
23692 +       __VCMD(get_vhi_name,     3, VCA_VXI,    VCF_INFO);
23693 +       __VCMD(get_rlimit,       3, VCA_VXI,    VCF_INFO);
23694 +
23695 +       __VCMD(ctx_stat,         3, VCA_VXI,    VCF_INFO);
23696 +       __VCMD(virt_stat,        3, VCA_VXI,    VCF_INFO);
23697 +       __VCMD(sock_stat,        3, VCA_VXI,    VCF_INFO);
23698 +       __VCMD(rlimit_stat,      3, VCA_VXI,    VCF_INFO);
23699 +
23700 +       __VCMD(task_nid,         2, VCA_NONE,   0);
23701 +       __VCMD(nx_info,          3, VCA_NXI,    VCF_INFO);
23702 +       __VCMD(get_ncaps,        3, VCA_NXI,    VCF_INFO);
23703 +       __VCMD(get_nflags,       3, VCA_NXI,    VCF_INFO);
23704 +
23705 +       __VCMD(task_tag,         2, VCA_NONE,   0);
23706 +
23707 +       __VCMD(get_iattr,        2, VCA_NONE,   0);
23708 +       __VCMD(fget_iattr,       2, VCA_NONE,   0);
23709 +       __VCMD(get_dlimit,       3, VCA_NONE,   VCF_INFO);
23710 +       __VCMD(get_prio_bias,    3, VCA_VXI,    VCF_INFO);
23711 +
23712 +       /* lower admin commands */
23713 +       __VCMD(wait_exit,        4, VCA_VXI,    VCF_INFO);
23714 +       __VCMD(ctx_create_v0,    5, VCA_NONE,   0);
23715 +       __VCMD(ctx_create,       5, VCA_NONE,   0);
23716 +       __VCMD(ctx_migrate_v0,   5, VCA_VXI,    VCF_ADMIN);
23717 +       __VCMD(ctx_migrate,      5, VCA_VXI,    VCF_ADMIN);
23718 +       __VCMD(enter_space_v0,   5, VCA_VXI,    VCF_ADMIN);
23719 +       __VCMD(enter_space_v1,   5, VCA_VXI,    VCF_ADMIN);
23720 +       __VCMD(enter_space,      5, VCA_VXI,    VCF_ADMIN);
23721 +
23722 +       __VCMD(net_create_v0,    5, VCA_NONE,   0);
23723 +       __VCMD(net_create,       5, VCA_NONE,   0);
23724 +       __VCMD(net_migrate,      5, VCA_NXI,    VCF_ADMIN);
23725 +
23726 +       __VCMD(tag_migrate,      5, VCA_NONE,   VCF_ADMIN);
23727 +
23728 +       /* higher admin commands */
23729 +       __VCMD(ctx_kill,         6, VCA_VXI,    VCF_ARES);
23730 +       __VCMD(set_space_v1,     7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23731 +       __VCMD(set_space,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23732 +
23733 +       __VCMD(set_ccaps,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23734 +       __VCMD(set_bcaps,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23735 +       __VCMD(set_cflags,       7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23736 +       __VCMD(set_badness,      7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23737 +
23738 +       __VCMD(set_vhi_name,     7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23739 +       __VCMD(set_rlimit,       7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23740 +       __VCMD(set_prio_bias,    7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23741 +
23742 +       __VCMD(set_ncaps,        7, VCA_NXI,    VCF_ARES | VCF_SETUP);
23743 +       __VCMD(set_nflags,       7, VCA_NXI,    VCF_ARES | VCF_SETUP);
23744 +       __VCMD(net_add,          8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23745 +       __VCMD(net_remove,       8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23746 +       __VCMD(net_add_ipv4,     8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23747 +       __VCMD(net_remove_ipv4,  8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23748 +#ifdef CONFIG_IPV6
23749 +       __VCMD(net_add_ipv6,     8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23750 +       __VCMD(net_remove_ipv6,  8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23751 +#endif
23752 +       __VCMD(set_iattr,        7, VCA_NONE,   0);
23753 +       __VCMD(fset_iattr,       7, VCA_NONE,   0);
23754 +       __VCMD(set_dlimit,       7, VCA_NONE,   VCF_ARES);
23755 +       __VCMD(add_dlimit,       8, VCA_NONE,   VCF_ARES);
23756 +       __VCMD(rem_dlimit,       8, VCA_NONE,   VCF_ARES);
23757 +
23758 +#ifdef CONFIG_VSERVER_DEVICE
23759 +       __VCMD(set_mapping,      8, VCA_VXI,    VCF_ARES|VCF_ZIDOK);
23760 +       __VCMD(unset_mapping,    8, VCA_VXI,    VCF_ARES|VCF_ZIDOK);
23761 +#endif
23762 +       /* debug level admin commands */
23763 +#ifdef CONFIG_VSERVER_HISTORY
23764 +       __VCMD(dump_history,     9, VCA_NONE,   0);
23765 +       __VCMD(read_history,     9, VCA_NONE,   0);
23766 +#endif
23767 +
23768 +       default:
23769 +               perm = -1;
23770 +       }
23771 +
23772 +       vxdprintk(VXD_CBIT(switch, 0),
23773 +               "vc: VCMD_%02d_%d[%d], %d,%p [%d,%d,%x,%x]",
23774 +               VC_CATEGORY(cmd), VC_COMMAND(cmd),
23775 +               VC_VERSION(cmd), id, data, compat,
23776 +               perm, args, flags);
23777 +
23778 +       ret = -ENOSYS;
23779 +       if (perm < 0)
23780 +               goto out;
23781 +
23782 +       state = 1;
23783 +       if (!capable(CAP_CONTEXT))
23784 +               goto out;
23785 +
23786 +       state = 2;
23787 +       /* moved here from the individual commands */
23788 +       ret = -EPERM;
23789 +       if ((perm > 1) && !capable(CAP_SYS_ADMIN))
23790 +               goto out;
23791 +
23792 +       state = 3;
23793 +       /* vcmd involves resource management  */
23794 +       ret = -EPERM;
23795 +       if ((flags & VCF_ARES) && !capable(CAP_SYS_RESOURCE))
23796 +               goto out;
23797 +
23798 +       state = 4;
23799 +       /* various legacy exceptions */
23800 +       switch (cmd) {
23801 +       /* will go away when spectator is a cap */
23802 +       case VCMD_ctx_migrate_v0:
23803 +       case VCMD_ctx_migrate:
23804 +               if (id == 1) {
23805 +                       current->xid = 1;
23806 +                       ret = 1;
23807 +                       goto out;
23808 +               }
23809 +               break;
23810 +
23811 +       /* will go away when spectator is a cap */
23812 +       case VCMD_net_migrate:
23813 +               if (id == 1) {
23814 +                       current->nid = 1;
23815 +                       ret = 1;
23816 +                       goto out;
23817 +               }
23818 +               break;
23819 +       }
23820 +
23821 +       /* vcmds are fine by default */
23822 +       permit = 1;
23823 +
23824 +       /* admin type vcmds require admin ... */
23825 +       if (flags & VCF_ADMIN)
23826 +               permit = vx_check(0, VS_ADMIN) ? 1 : 0;
23827 +
23828 +       /* ... but setup type vcmds override that */
23829 +       if (!permit && (flags & VCF_SETUP))
23830 +               permit = vx_flags(VXF_STATE_SETUP, 0) ? 2 : 0;
23831 +
23832 +       state = 5;
23833 +       ret = -EPERM;
23834 +       if (!permit)
23835 +               goto out;
23836 +
23837 +       state = 6;
23838 +       if (!id && (flags & VCF_ZIDOK))
23839 +               goto skip_id;
23840 +
23841 +       ret = -ESRCH;
23842 +       if (args & VCA_VXI) {
23843 +               vxi = lookup_vx_info(id);
23844 +               if (!vxi)
23845 +                       goto out;
23846 +
23847 +               if ((flags & VCF_ADMIN) &&
23848 +                       /* special case kill for shutdown */
23849 +                       (cmd != VCMD_ctx_kill) &&
23850 +                       /* can context be administrated? */
23851 +                       !vx_info_flags(vxi, VXF_STATE_ADMIN, 0)) {
23852 +                       ret = -EACCES;
23853 +                       goto out_vxi;
23854 +               }
23855 +       }
23856 +       state = 7;
23857 +       if (args & VCA_NXI) {
23858 +               nxi = lookup_nx_info(id);
23859 +               if (!nxi)
23860 +                       goto out_vxi;
23861 +
23862 +               if ((flags & VCF_ADMIN) &&
23863 +                       /* can context be administrated? */
23864 +                       !nx_info_flags(nxi, NXF_STATE_ADMIN, 0)) {
23865 +                       ret = -EACCES;
23866 +                       goto out_nxi;
23867 +               }
23868 +       }
23869 +skip_id:
23870 +       state = 8;
23871 +       ret = do_vcmd(cmd, id, vxi, nxi, data, compat);
23872 +
23873 +out_nxi:
23874 +       if ((args & VCA_NXI) && nxi)
23875 +               put_nx_info(nxi);
23876 +out_vxi:
23877 +       if ((args & VCA_VXI) && vxi)
23878 +               put_vx_info(vxi);
23879 +out:
23880 +       vxdprintk(VXD_CBIT(switch, 1),
23881 +               "vc: VCMD_%02d_%d[%d] = %08lx(%ld) [%d,%d]",
23882 +               VC_CATEGORY(cmd), VC_COMMAND(cmd),
23883 +               VC_VERSION(cmd), ret, ret, state, permit);
23884 +       return ret;
23885 +}
23886 +
23887 +asmlinkage long
23888 +sys_vserver(uint32_t cmd, uint32_t id, void __user *data)
23889 +{
23890 +       return do_vserver(cmd, id, data, 0);
23891 +}
23892 +
23893 +#ifdef CONFIG_COMPAT
23894 +
23895 +asmlinkage long
23896 +sys32_vserver(uint32_t cmd, uint32_t id, void __user *data)
23897 +{
23898 +       return do_vserver(cmd, id, data, 1);
23899 +}
23900 +
23901 +#endif /* CONFIG_COMPAT */
23902 diff -NurpP --minimal linux-2.6.38.1/kernel/vserver/sysctl.c linux-2.6.38.1-vs2.3.0.37-rc9/kernel/vserver/sysctl.c
23903 --- linux-2.6.38.1/kernel/vserver/sysctl.c      1970-01-01 01:00:00.000000000 +0100
23904 +++ linux-2.6.38.1-vs2.3.0.37-rc9/kernel/vserver/sysctl.c       2011-01-29 02:01:07.000000000 +0100
23905 @@ -0,0 +1,241 @@
23906 +/*
23907 + *  kernel/vserver/sysctl.c
23908 + *
23909 + *  Virtual Context Support
23910 + *
23911 + *  Copyright (C) 2004-2007  Herbert Pötzl
23912 + *
23913 + *  V0.01  basic structure
23914 + *
23915 + */
23916 +
23917 +#include <linux/module.h>
23918 +#include <linux/ctype.h>
23919 +#include <linux/sysctl.h>
23920 +#include <linux/parser.h>
23921 +#include <asm/uaccess.h>
23922 +
23923 +enum {
23924 +       CTL_DEBUG_ERROR         = 0,
23925 +       CTL_DEBUG_SWITCH        = 1,
23926 +       CTL_DEBUG_XID,
23927 +       CTL_DEBUG_NID,
23928 +       CTL_DEBUG_TAG,
23929 +       CTL_DEBUG_NET,
23930 +       CTL_DEBUG_LIMIT,
23931 +       CTL_DEBUG_CRES,
23932 +       CTL_DEBUG_DLIM,
23933 +       CTL_DEBUG_QUOTA,
23934 +       CTL_DEBUG_CVIRT,
23935 +       CTL_DEBUG_SPACE,
23936 +       CTL_DEBUG_MISC,
23937 +};
23938 +
23939 +
23940 +unsigned int vx_debug_switch   = 0;
23941 +unsigned int vx_debug_xid      = 0;
23942 +unsigned int vx_debug_nid      = 0;
23943 +unsigned int vx_debug_tag      = 0;
23944 +unsigned int vx_debug_net      = 0;
23945 +unsigned int vx_debug_limit    = 0;
23946 +unsigned int vx_debug_cres     = 0;
23947 +unsigned int vx_debug_dlim     = 0;
23948 +unsigned int vx_debug_quota    = 0;
23949 +unsigned int vx_debug_cvirt    = 0;
23950 +unsigned int vx_debug_space    = 0;
23951 +unsigned int vx_debug_misc     = 0;
23952 +
23953 +
23954 +static struct ctl_table_header *vserver_table_header;
23955 +static ctl_table vserver_root_table[];
23956 +
23957 +
23958 +void vserver_register_sysctl(void)
23959 +{
23960 +       if (!vserver_table_header) {
23961 +               vserver_table_header = register_sysctl_table(vserver_root_table);
23962 +       }
23963 +
23964 +}
23965 +
23966 +void vserver_unregister_sysctl(void)
23967 +{
23968 +       if (vserver_table_header) {
23969 +               unregister_sysctl_table(vserver_table_header);
23970 +               vserver_table_header = NULL;
23971 +       }
23972 +}
23973 +
23974 +
23975 +static int proc_dodebug(ctl_table *table, int write,
23976 +       void __user *buffer, size_t *lenp, loff_t *ppos)
23977 +{
23978 +       char            tmpbuf[20], *p, c;
23979 +       unsigned int    value;
23980 +       size_t          left, len;
23981 +
23982 +       if ((*ppos && !write) || !*lenp) {
23983 +               *lenp = 0;
23984 +               return 0;
23985 +       }
23986 +
23987 +       left = *lenp;
23988 +
23989 +       if (write) {
23990 +               if (!access_ok(VERIFY_READ, buffer, left))
23991 +                       return -EFAULT;
23992 +               p = (char *)buffer;
23993 +               while (left && __get_user(c, p) >= 0 && isspace(c))
23994 +                       left--, p++;
23995 +               if (!left)
23996 +                       goto done;
23997 +
23998 +               if (left > sizeof(tmpbuf) - 1)
23999 +                       return -EINVAL;
24000 +               if (copy_from_user(tmpbuf, p, left))
24001 +                       return -EFAULT;
24002 +               tmpbuf[left] = '\0';
24003 +
24004 +               for (p = tmpbuf, value = 0; '0' <= *p && *p <= '9'; p++, left--)
24005 +                       value = 10 * value + (*p - '0');
24006 +               if (*p && !isspace(*p))
24007 +                       return -EINVAL;
24008 +               while (left && isspace(*p))
24009 +                       left--, p++;
24010 +               *(unsigned int *)table->data = value;
24011 +       } else {
24012 +               if (!access_ok(VERIFY_WRITE, buffer, left))
24013 +                       return -EFAULT;
24014 +               len = sprintf(tmpbuf, "%d", *(unsigned int *)table->data);
24015 +               if (len > left)
24016 +                       len = left;
24017 +               if (__copy_to_user(buffer, tmpbuf, len))
24018 +                       return -EFAULT;
24019 +               if ((left -= len) > 0) {
24020 +                       if (put_user('\n', (char *)buffer + len))
24021 +                               return -EFAULT;
24022 +                       left--;
24023 +               }
24024 +       }
24025 +
24026 +done:
24027 +       *lenp -= left;
24028 +       *ppos += *lenp;
24029 +       return 0;
24030 +}
24031 +
24032 +static int zero;
24033 +
24034 +#define        CTL_ENTRY(ctl, name)                            \
24035 +       {                                               \
24036 +               .procname       = #name,                \
24037 +               .data           = &vx_ ## name,         \
24038 +               .maxlen         = sizeof(int),          \
24039 +               .mode           = 0644,                 \
24040 +               .proc_handler   = &proc_dodebug,        \
24041 +               .extra1         = &zero,                \
24042 +               .extra2         = &zero,                \
24043 +       }
24044 +
24045 +static ctl_table vserver_debug_table[] = {
24046 +       CTL_ENTRY(CTL_DEBUG_SWITCH,     debug_switch),
24047 +       CTL_ENTRY(CTL_DEBUG_XID,        debug_xid),
24048 +       CTL_ENTRY(CTL_DEBUG_NID,        debug_nid),
24049 +       CTL_ENTRY(CTL_DEBUG_TAG,        debug_tag),
24050 +       CTL_ENTRY(CTL_DEBUG_NET,        debug_net),
24051 +       CTL_ENTRY(CTL_DEBUG_LIMIT,      debug_limit),
24052 +       CTL_ENTRY(CTL_DEBUG_CRES,       debug_cres),
24053 +       CTL_ENTRY(CTL_DEBUG_DLIM,       debug_dlim),
24054 +       CTL_ENTRY(CTL_DEBUG_QUOTA,      debug_quota),
24055 +       CTL_ENTRY(CTL_DEBUG_CVIRT,      debug_cvirt),
24056 +       CTL_ENTRY(CTL_DEBUG_SPACE,      debug_space),
24057 +       CTL_ENTRY(CTL_DEBUG_MISC,       debug_misc),
24058 +       { 0 }
24059 +};
24060 +
24061 +static ctl_table vserver_root_table[] = {
24062 +       {
24063 +               .procname       = "vserver",
24064 +               .mode           = 0555,
24065 +               .child          = vserver_debug_table
24066 +       },
24067 +       { 0 }
24068 +};
24069 +
24070 +
24071 +static match_table_t tokens = {
24072 +       { CTL_DEBUG_SWITCH,     "switch=%x"     },
24073 +       { CTL_DEBUG_XID,        "xid=%x"        },
24074 +       { CTL_DEBUG_NID,        "nid=%x"        },
24075 +       { CTL_DEBUG_TAG,        "tag=%x"        },
24076 +       { CTL_DEBUG_NET,        "net=%x"        },
24077 +       { CTL_DEBUG_LIMIT,      "limit=%x"      },
24078 +       { CTL_DEBUG_CRES,       "cres=%x"       },
24079 +       { CTL_DEBUG_DLIM,       "dlim=%x"       },
24080 +       { CTL_DEBUG_QUOTA,      "quota=%x"      },
24081 +       { CTL_DEBUG_CVIRT,      "cvirt=%x"      },
24082 +       { CTL_DEBUG_SPACE,      "space=%x"      },
24083 +       { CTL_DEBUG_MISC,       "misc=%x"       },
24084 +       { CTL_DEBUG_ERROR,      NULL            }
24085 +};
24086 +
24087 +#define        HANDLE_CASE(id, name, val)                              \
24088 +       case CTL_DEBUG_ ## id:                                  \
24089 +               vx_debug_ ## name = val;                        \
24090 +               printk("vs_debug_" #name "=0x%x\n", val);       \
24091 +               break
24092 +
24093 +
24094 +static int __init vs_debug_setup(char *str)
24095 +{
24096 +       char *p;
24097 +       int token;
24098 +
24099 +       printk("vs_debug_setup(%s)\n", str);
24100 +       while ((p = strsep(&str, ",")) != NULL) {
24101 +               substring_t args[MAX_OPT_ARGS];
24102 +               unsigned int value;
24103 +
24104 +               if (!*p)
24105 +                       continue;
24106 +
24107 +               token = match_token(p, tokens, args);
24108 +               value = (token > 0) ? simple_strtoul(args[0].from, NULL, 0) : 0;
24109 +
24110 +               switch (token) {
24111 +               HANDLE_CASE(SWITCH, switch, value);
24112 +               HANDLE_CASE(XID,    xid,    value);
24113 +               HANDLE_CASE(NID,    nid,    value);
24114 +               HANDLE_CASE(TAG,    tag,    value);
24115 +               HANDLE_CASE(NET,    net,    value);
24116 +               HANDLE_CASE(LIMIT,  limit,  value);
24117 +               HANDLE_CASE(CRES,   cres,   value);
24118 +               HANDLE_CASE(DLIM,   dlim,   value);
24119 +               HANDLE_CASE(QUOTA,  quota,  value);
24120 +               HANDLE_CASE(CVIRT,  cvirt,  value);
24121 +               HANDLE_CASE(SPACE,  space,  value);
24122 +               HANDLE_CASE(MISC,   misc,   value);
24123 +               default:
24124 +                       return -EINVAL;
24125 +                       break;
24126 +               }
24127 +       }
24128 +       return 1;
24129 +}
24130 +
24131 +__setup("vsdebug=", vs_debug_setup);
24132 +
24133 +
24134 +
24135 +EXPORT_SYMBOL_GPL(vx_debug_switch);
24136 +EXPORT_SYMBOL_GPL(vx_debug_xid);
24137 +EXPORT_SYMBOL_GPL(vx_debug_nid);
24138 +EXPORT_SYMBOL_GPL(vx_debug_net);
24139 +EXPORT_SYMBOL_GPL(vx_debug_limit);
24140 +EXPORT_SYMBOL_GPL(vx_debug_cres);
24141 +EXPORT_SYMBOL_GPL(vx_debug_dlim);
24142 +EXPORT_SYMBOL_GPL(vx_debug_quota);
24143 +EXPORT_SYMBOL_GPL(vx_debug_cvirt);
24144 +EXPORT_SYMBOL_GPL(vx_debug_space);
24145 +EXPORT_SYMBOL_GPL(vx_debug_misc);
24146 +
24147 diff -NurpP --minimal linux-2.6.38.1/kernel/vserver/tag.c linux-2.6.38.1-vs2.3.0.37-rc9/kernel/vserver/tag.c
24148 --- linux-2.6.38.1/kernel/vserver/tag.c 1970-01-01 01:00:00.000000000 +0100
24149 +++ linux-2.6.38.1-vs2.3.0.37-rc9/kernel/vserver/tag.c  2011-03-22 17:43:07.000000000 +0100
24150 @@ -0,0 +1,63 @@
24151 +/*
24152 + *  linux/kernel/vserver/tag.c
24153 + *
24154 + *  Virtual Server: Shallow Tag Space
24155 + *
24156 + *  Copyright (C) 2007  Herbert Pötzl
24157 + *
24158 + *  V0.01  basic implementation
24159 + *
24160 + */
24161 +
24162 +#include <linux/sched.h>
24163 +#include <linux/vserver/debug.h>
24164 +#include <linux/vs_pid.h>
24165 +#include <linux/vs_tag.h>
24166 +
24167 +#include <linux/vserver/tag_cmd.h>
24168 +
24169 +
24170 +int dx_migrate_task(struct task_struct *p, tag_t tag)
24171 +{
24172 +       if (!p)
24173 +               BUG();
24174 +
24175 +       vxdprintk(VXD_CBIT(tag, 5),
24176 +               "dx_migrate_task(%p[#%d],#%d)", p, p->tag, tag);
24177 +
24178 +       task_lock(p);
24179 +       p->tag = tag;
24180 +       task_unlock(p);
24181 +
24182 +       vxdprintk(VXD_CBIT(tag, 5),
24183 +               "moved task %p into [#%d]", p, tag);
24184 +       return 0;
24185 +}
24186 +
24187 +/* vserver syscall commands below here */
24188 +
24189 +/* taks xid and vx_info functions */
24190 +
24191 +
24192 +int vc_task_tag(uint32_t id)
24193 +{
24194 +       tag_t tag;
24195 +
24196 +       if (id) {
24197 +               struct task_struct *tsk;
24198 +               rcu_read_lock();
24199 +               tsk = find_task_by_real_pid(id);
24200 +               tag = (tsk) ? tsk->tag : -ESRCH;
24201 +               rcu_read_unlock();
24202 +       } else
24203 +               tag = dx_current_tag();
24204 +       return tag;
24205 +}
24206 +
24207 +
24208 +int vc_tag_migrate(uint32_t tag)
24209 +{
24210 +       return dx_migrate_task(current, tag & 0xFFFF);
24211 +}
24212 +
24213 +
24214 diff -NurpP --minimal linux-2.6.38.1/kernel/vserver/vci_config.h linux-2.6.38.1-vs2.3.0.37-rc9/kernel/vserver/vci_config.h
24215 --- linux-2.6.38.1/kernel/vserver/vci_config.h  1970-01-01 01:00:00.000000000 +0100
24216 +++ linux-2.6.38.1-vs2.3.0.37-rc9/kernel/vserver/vci_config.h   2011-03-15 21:34:31.000000000 +0100
24217 @@ -0,0 +1,76 @@
24218 +
24219 +/*  interface version */
24220 +
24221 +#define VCI_VERSION            0x00020307
24222 +
24223 +
24224 +enum {
24225 +       VCI_KCBIT_NO_DYNAMIC = 0,
24226 +
24227 +       VCI_KCBIT_PROC_SECURE = 4,
24228 +       /* VCI_KCBIT_HARDCPU = 5, */
24229 +       /* VCI_KCBIT_IDLELIMIT = 6, */
24230 +       /* VCI_KCBIT_IDLETIME = 7, */
24231 +
24232 +       VCI_KCBIT_COWBL = 8,
24233 +       VCI_KCBIT_FULLCOWBL = 9,
24234 +       VCI_KCBIT_SPACES = 10,
24235 +       VCI_KCBIT_NETV2 = 11,
24236 +       VCI_KCBIT_MEMCG = 12,
24237 +
24238 +       VCI_KCBIT_DEBUG = 16,
24239 +       VCI_KCBIT_HISTORY = 20,
24240 +       VCI_KCBIT_TAGGED = 24,
24241 +       VCI_KCBIT_PPTAG = 28,
24242 +
24243 +       VCI_KCBIT_MORE = 31,
24244 +};
24245 +
24246 +
24247 +static inline uint32_t vci_kernel_config(void)
24248 +{
24249 +       return
24250 +       (1 << VCI_KCBIT_NO_DYNAMIC) |
24251 +
24252 +       /* configured features */
24253 +#ifdef CONFIG_VSERVER_PROC_SECURE
24254 +       (1 << VCI_KCBIT_PROC_SECURE) |
24255 +#endif
24256 +#ifdef CONFIG_VSERVER_COWBL
24257 +       (1 << VCI_KCBIT_COWBL) |
24258 +       (1 << VCI_KCBIT_FULLCOWBL) |
24259 +#endif
24260 +       (1 << VCI_KCBIT_SPACES) |
24261 +       (1 << VCI_KCBIT_NETV2) |
24262 +#ifdef CONFIG_CGROUP_MEM_RES_CTLR
24263 +       (1 << VCI_KCBIT_MEMCG) |
24264 +#endif
24265 +
24266 +       /* debug options */
24267 +#ifdef CONFIG_VSERVER_DEBUG
24268 +       (1 << VCI_KCBIT_DEBUG) |
24269 +#endif
24270 +#ifdef CONFIG_VSERVER_HISTORY
24271 +       (1 << VCI_KCBIT_HISTORY) |
24272 +#endif
24273 +
24274 +       /* inode context tagging */
24275 +#if    defined(CONFIG_TAGGING_NONE)
24276 +       (0 << VCI_KCBIT_TAGGED) |
24277 +#elif  defined(CONFIG_TAGGING_UID16)
24278 +       (1 << VCI_KCBIT_TAGGED) |
24279 +#elif  defined(CONFIG_TAGGING_GID16)
24280 +       (2 << VCI_KCBIT_TAGGED) |
24281 +#elif  defined(CONFIG_TAGGING_ID24)
24282 +       (3 << VCI_KCBIT_TAGGED) |
24283 +#elif  defined(CONFIG_TAGGING_INTERN)
24284 +       (4 << VCI_KCBIT_TAGGED) |
24285 +#elif  defined(CONFIG_TAGGING_RUNTIME)
24286 +       (5 << VCI_KCBIT_TAGGED) |
24287 +#else
24288 +       (7 << VCI_KCBIT_TAGGED) |
24289 +#endif
24290 +       (1 << VCI_KCBIT_PPTAG) |
24291 +       0;
24292 +}
24293 +
24294 diff -NurpP --minimal linux-2.6.38.1/mm/filemap_xip.c linux-2.6.38.1-vs2.3.0.37-rc9/mm/filemap_xip.c
24295 --- linux-2.6.38.1/mm/filemap_xip.c     2010-07-07 18:31:58.000000000 +0200
24296 +++ linux-2.6.38.1-vs2.3.0.37-rc9/mm/filemap_xip.c      2011-01-29 02:01:07.000000000 +0100
24297 @@ -18,6 +18,7 @@
24298  #include <linux/seqlock.h>
24299  #include <linux/mutex.h>
24300  #include <linux/gfp.h>
24301 +#include <linux/vs_memory.h>
24302  #include <asm/tlbflush.h>
24303  #include <asm/io.h>
24304  
24305 diff -NurpP --minimal linux-2.6.38.1/mm/fremap.c linux-2.6.38.1-vs2.3.0.37-rc9/mm/fremap.c
24306 --- linux-2.6.38.1/mm/fremap.c  2010-10-21 13:07:57.000000000 +0200
24307 +++ linux-2.6.38.1-vs2.3.0.37-rc9/mm/fremap.c   2011-01-29 02:01:07.000000000 +0100
24308 @@ -16,6 +16,7 @@
24309  #include <linux/module.h>
24310  #include <linux/syscalls.h>
24311  #include <linux/mmu_notifier.h>
24312 +#include <linux/vs_memory.h>
24313  
24314  #include <asm/mmu_context.h>
24315  #include <asm/cacheflush.h>
24316 diff -NurpP --minimal linux-2.6.38.1/mm/hugetlb.c linux-2.6.38.1-vs2.3.0.37-rc9/mm/hugetlb.c
24317 --- linux-2.6.38.1/mm/hugetlb.c 2011-03-15 18:07:42.000000000 +0100
24318 +++ linux-2.6.38.1-vs2.3.0.37-rc9/mm/hugetlb.c  2011-01-29 02:01:07.000000000 +0100
24319 @@ -28,6 +28,7 @@
24320  
24321  #include <linux/hugetlb.h>
24322  #include <linux/node.h>
24323 +#include <linux/vs_memory.h>
24324  #include "internal.h"
24325  
24326  const unsigned long hugetlb_zero = 0, hugetlb_infinity = ~0UL;
24327 diff -NurpP --minimal linux-2.6.38.1/mm/memcontrol.c linux-2.6.38.1-vs2.3.0.37-rc9/mm/memcontrol.c
24328 --- linux-2.6.38.1/mm/memcontrol.c      2011-03-15 18:07:42.000000000 +0100
24329 +++ linux-2.6.38.1-vs2.3.0.37-rc9/mm/memcontrol.c       2011-02-17 02:17:51.000000000 +0100
24330 @@ -681,6 +681,31 @@ struct mem_cgroup *mem_cgroup_from_task(
24331                                 struct mem_cgroup, css);
24332  }
24333  
24334 +u64 mem_cgroup_res_read_u64(struct mem_cgroup *mem, int member)
24335 +{
24336 +       return res_counter_read_u64(&mem->res, member);
24337 +}
24338 +
24339 +u64 mem_cgroup_memsw_read_u64(struct mem_cgroup *mem, int member)
24340 +{
24341 +       return res_counter_read_u64(&mem->memsw, member);
24342 +}
24343 +
24344 +s64 mem_cgroup_stat_read_cache(struct mem_cgroup *mem)
24345 +{
24346 +       return mem_cgroup_read_stat(mem, MEM_CGROUP_STAT_CACHE);
24347 +}
24348 +
24349 +s64 mem_cgroup_stat_read_anon(struct mem_cgroup *mem)
24350 +{
24351 +       return mem_cgroup_read_stat(mem, MEM_CGROUP_STAT_RSS);
24352 +}
24353 +
24354 +s64 mem_cgroup_stat_read_mapped(struct mem_cgroup *mem)
24355 +{
24356 +       return mem_cgroup_read_stat(mem, MEM_CGROUP_STAT_FILE_MAPPED);
24357 +}
24358 +
24359  static struct mem_cgroup *try_get_mem_cgroup_from_mm(struct mm_struct *mm)
24360  {
24361         struct mem_cgroup *mem = NULL;
24362 diff -NurpP --minimal linux-2.6.38.1/mm/memory.c linux-2.6.38.1-vs2.3.0.37-rc9/mm/memory.c
24363 --- linux-2.6.38.1/mm/memory.c  2011-03-15 18:07:42.000000000 +0100
24364 +++ linux-2.6.38.1-vs2.3.0.37-rc9/mm/memory.c   2011-03-07 16:53:28.000000000 +0100
24365 @@ -3225,6 +3225,7 @@ int handle_pte_fault(struct mm_struct *m
24366  {
24367         pte_t entry;
24368         spinlock_t *ptl;
24369 +       int ret = 0, type = VXPT_UNKNOWN;
24370  
24371         entry = *pte;
24372         if (!pte_present(entry)) {
24373 @@ -3249,9 +3250,12 @@ int handle_pte_fault(struct mm_struct *m
24374         if (unlikely(!pte_same(*pte, entry)))
24375                 goto unlock;
24376         if (flags & FAULT_FLAG_WRITE) {
24377 -               if (!pte_write(entry))
24378 -                       return do_wp_page(mm, vma, address,
24379 +               if (!pte_write(entry)) {
24380 +                       ret = do_wp_page(mm, vma, address,
24381                                         pte, pmd, ptl, entry);
24382 +                       type = VXPT_WRITE;
24383 +                       goto out;
24384 +               }
24385                 entry = pte_mkdirty(entry);
24386         }
24387         entry = pte_mkyoung(entry);
24388 @@ -3269,7 +3273,10 @@ int handle_pte_fault(struct mm_struct *m
24389         }
24390  unlock:
24391         pte_unmap_unlock(pte, ptl);
24392 -       return 0;
24393 +       ret = 0;
24394 +out:
24395 +       vx_page_fault(mm, vma, type, ret);
24396 +       return ret;
24397  }
24398  
24399  /*
24400 diff -NurpP --minimal linux-2.6.38.1/mm/mremap.c linux-2.6.38.1-vs2.3.0.37-rc9/mm/mremap.c
24401 --- linux-2.6.38.1/mm/mremap.c  2011-03-15 18:07:42.000000000 +0100
24402 +++ linux-2.6.38.1-vs2.3.0.37-rc9/mm/mremap.c   2011-03-07 16:53:28.000000000 +0100
24403 @@ -19,6 +19,7 @@
24404  #include <linux/security.h>
24405  #include <linux/syscalls.h>
24406  #include <linux/mmu_notifier.h>
24407 +#include <linux/vs_memory.h>
24408  
24409  #include <asm/uaccess.h>
24410  #include <asm/cacheflush.h>
24411 diff -NurpP --minimal linux-2.6.38.1/mm/oom_kill.c linux-2.6.38.1-vs2.3.0.37-rc9/mm/oom_kill.c
24412 --- linux-2.6.38.1/mm/oom_kill.c        2011-01-05 21:50:40.000000000 +0100
24413 +++ linux-2.6.38.1-vs2.3.0.37-rc9/mm/oom_kill.c 2011-01-29 02:01:07.000000000 +0100
24414 @@ -31,6 +31,9 @@
24415  #include <linux/memcontrol.h>
24416  #include <linux/mempolicy.h>
24417  #include <linux/security.h>
24418 +#include <linux/reboot.h>
24419 +#include <linux/vs_memory.h>
24420 +#include <linux/vs_context.h>
24421  
24422  int sysctl_panic_on_oom;
24423  int sysctl_oom_kill_allocating_task;
24424 @@ -124,11 +127,18 @@ struct task_struct *find_lock_task_mm(st
24425  static bool oom_unkillable_task(struct task_struct *p,
24426                 const struct mem_cgroup *mem, const nodemask_t *nodemask)
24427  {
24428 -       if (is_global_init(p))
24429 +       unsigned xid = vx_current_xid();
24430 +
24431 +       /* skip the init task, global and per guest */
24432 +       if (task_is_init(p))
24433                 return true;
24434         if (p->flags & PF_KTHREAD)
24435                 return true;
24436  
24437 +       /* skip other guest and host processes if oom in guest */
24438 +       if (xid && vx_task_xid(p) != xid)
24439 +               return true;
24440 +
24441         /* When mem_cgroup_out_of_memory() and p is not member of the group */
24442         if (mem && !task_in_mem_cgroup(p, mem))
24443                 return true;
24444 @@ -210,6 +220,18 @@ unsigned int oom_badness(struct task_str
24445         points += p->signal->oom_score_adj;
24446  
24447         /*
24448 +        * add points for context badness and
24449 +        * reduce badness for processes belonging to
24450 +        * a different context
24451 +        */
24452 +
24453 +       points += vx_badness(p, p->mm);
24454 +
24455 +       if ((vx_current_xid() > 1) &&
24456 +               vx_current_xid() != vx_task_xid(p))
24457 +               points /= 16;
24458 +
24459 +       /*
24460          * Never return 0 for an eligible task that may be killed since it's
24461          * possible that no single user task uses more than 0.1% of memory and
24462          * no single admin tasks uses more than 3.0%.
24463 @@ -414,8 +436,8 @@ static int oom_kill_task(struct task_str
24464         /* mm cannot be safely dereferenced after task_unlock(p) */
24465         mm = p->mm;
24466  
24467 -       pr_err("Killed process %d (%s) total-vm:%lukB, anon-rss:%lukB, file-rss:%lukB\n",
24468 -               task_pid_nr(p), p->comm, K(p->mm->total_vm),
24469 +       pr_err("Killed process %d:#%u (%s) total-vm:%lukB, anon-rss:%lukB, file-rss:%lukB\n",
24470 +               task_pid_nr(p), p->xid, p->comm, K(p->mm->total_vm),
24471                 K(get_mm_counter(p->mm, MM_ANONPAGES)),
24472                 K(get_mm_counter(p->mm, MM_FILEPAGES)));
24473         task_unlock(p);
24474 @@ -477,8 +499,8 @@ static int oom_kill_process(struct task_
24475         }
24476  
24477         task_lock(p);
24478 -       pr_err("%s: Kill process %d (%s) score %d or sacrifice child\n",
24479 -               message, task_pid_nr(p), p->comm, points);
24480 +       pr_err("%s: Kill process %d:#%u (%s) score %d or sacrifice child\n",
24481 +               message, task_pid_nr(p), p->xid, p->comm, points);
24482         task_unlock(p);
24483  
24484         /*
24485 @@ -567,6 +589,8 @@ int unregister_oom_notifier(struct notif
24486  }
24487  EXPORT_SYMBOL_GPL(unregister_oom_notifier);
24488  
24489 +long vs_oom_action(unsigned int);
24490 +
24491  /*
24492   * Try to acquire the OOM killer lock for the zones in zonelist.  Returns zero
24493   * if a parallel OOM killing is already taking place that includes a zone in
24494 @@ -726,7 +750,12 @@ retry:
24495         if (!p) {
24496                 dump_header(NULL, gfp_mask, order, NULL, mpol_mask);
24497                 read_unlock(&tasklist_lock);
24498 -               panic("Out of memory and no killable processes...\n");
24499 +
24500 +               /* avoid panic for guest OOM */
24501 +               if (current->xid)
24502 +                       vs_oom_action(LINUX_REBOOT_CMD_OOM);
24503 +               else
24504 +                       panic("Out of memory and no killable processes...\n");
24505         }
24506  
24507         if (oom_kill_process(p, gfp_mask, order, points, totalpages, NULL,
24508 diff -NurpP --minimal linux-2.6.38.1/mm/page_alloc.c linux-2.6.38.1-vs2.3.0.37-rc9/mm/page_alloc.c
24509 --- linux-2.6.38.1/mm/page_alloc.c      2011-03-15 18:07:42.000000000 +0100
24510 +++ linux-2.6.38.1-vs2.3.0.37-rc9/mm/page_alloc.c       2011-03-07 16:53:28.000000000 +0100
24511 @@ -53,6 +53,8 @@
24512  #include <linux/compaction.h>
24513  #include <trace/events/kmem.h>
24514  #include <linux/ftrace_event.h>
24515 +#include <linux/vs_base.h>
24516 +#include <linux/vs_limit.h>
24517  
24518  #include <asm/tlbflush.h>
24519  #include <asm/div64.h>
24520 @@ -2388,6 +2390,9 @@ void si_meminfo(struct sysinfo *val)
24521         val->totalhigh = totalhigh_pages;
24522         val->freehigh = nr_free_highpages();
24523         val->mem_unit = PAGE_SIZE;
24524 +
24525 +       if (vx_flags(VXF_VIRT_MEM, 0))
24526 +               vx_vsi_meminfo(val);
24527  }
24528  
24529  EXPORT_SYMBOL(si_meminfo);
24530 @@ -2408,6 +2413,9 @@ void si_meminfo_node(struct sysinfo *val
24531         val->freehigh = 0;
24532  #endif
24533         val->mem_unit = PAGE_SIZE;
24534 +
24535 +       if (vx_flags(VXF_VIRT_MEM, 0))
24536 +               vx_vsi_meminfo(val);
24537  }
24538  #endif
24539  
24540 diff -NurpP --minimal linux-2.6.38.1/mm/pgtable-generic.c linux-2.6.38.1-vs2.3.0.37-rc9/mm/pgtable-generic.c
24541 --- linux-2.6.38.1/mm/pgtable-generic.c 2011-03-15 18:07:42.000000000 +0100
24542 +++ linux-2.6.38.1-vs2.3.0.37-rc9/mm/pgtable-generic.c  2011-02-02 22:20:27.000000000 +0100
24543 @@ -6,6 +6,8 @@
24544   *  Copyright (C) 2010  Linus Torvalds
24545   */
24546  
24547 +#include <linux/mm.h>
24548 +
24549  #include <linux/pagemap.h>
24550  #include <asm/tlb.h>
24551  #include <asm-generic/pgtable.h>
24552 diff -NurpP --minimal linux-2.6.38.1/mm/rmap.c linux-2.6.38.1-vs2.3.0.37-rc9/mm/rmap.c
24553 --- linux-2.6.38.1/mm/rmap.c    2011-03-15 18:07:42.000000000 +0100
24554 +++ linux-2.6.38.1-vs2.3.0.37-rc9/mm/rmap.c     2011-03-15 18:15:06.000000000 +0100
24555 @@ -57,6 +57,7 @@
24556  #include <linux/mmu_notifier.h>
24557  #include <linux/migrate.h>
24558  #include <linux/hugetlb.h>
24559 +#include <linux/vs_memory.h>
24560  
24561  #include <asm/tlbflush.h>
24562  
24563 diff -NurpP --minimal linux-2.6.38.1/mm/shmem.c linux-2.6.38.1-vs2.3.0.37-rc9/mm/shmem.c
24564 --- linux-2.6.38.1/mm/shmem.c   2011-03-15 18:07:42.000000000 +0100
24565 +++ linux-2.6.38.1-vs2.3.0.37-rc9/mm/shmem.c    2011-01-29 02:01:07.000000000 +0100
24566 @@ -1816,7 +1816,7 @@ static int shmem_statfs(struct dentry *d
24567  {
24568         struct shmem_sb_info *sbinfo = SHMEM_SB(dentry->d_sb);
24569  
24570 -       buf->f_type = TMPFS_MAGIC;
24571 +       buf->f_type = TMPFS_SUPER_MAGIC;
24572         buf->f_bsize = PAGE_CACHE_SIZE;
24573         buf->f_namelen = NAME_MAX;
24574         if (sbinfo->max_blocks) {
24575 @@ -2378,7 +2378,7 @@ int shmem_fill_super(struct super_block 
24576         sb->s_maxbytes = SHMEM_MAX_BYTES;
24577         sb->s_blocksize = PAGE_CACHE_SIZE;
24578         sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
24579 -       sb->s_magic = TMPFS_MAGIC;
24580 +       sb->s_magic = TMPFS_SUPER_MAGIC;
24581         sb->s_op = &shmem_ops;
24582         sb->s_time_gran = 1;
24583  #ifdef CONFIG_TMPFS_POSIX_ACL
24584 diff -NurpP --minimal linux-2.6.38.1/mm/slab.c linux-2.6.38.1-vs2.3.0.37-rc9/mm/slab.c
24585 --- linux-2.6.38.1/mm/slab.c    2011-03-15 18:07:42.000000000 +0100
24586 +++ linux-2.6.38.1-vs2.3.0.37-rc9/mm/slab.c     2011-01-29 02:01:07.000000000 +0100
24587 @@ -407,6 +407,8 @@ static void kmem_list3_init(struct kmem_
24588  #define STATS_INC_FREEMISS(x)  do { } while (0)
24589  #endif
24590  
24591 +#include "slab_vs.h"
24592 +
24593  #if DEBUG
24594  
24595  /*
24596 @@ -3346,6 +3348,7 @@ retry:
24597  
24598         obj = slab_get_obj(cachep, slabp, nodeid);
24599         check_slabp(cachep, slabp);
24600 +       vx_slab_alloc(cachep, flags);
24601         l3->free_objects--;
24602         /* move slabp to correct slabp list: */
24603         list_del(&slabp->list);
24604 @@ -3423,6 +3426,7 @@ __cache_alloc_node(struct kmem_cache *ca
24605         /* ___cache_alloc_node can fall back to other nodes */
24606         ptr = ____cache_alloc_node(cachep, flags, nodeid);
24607    out:
24608 +       vx_slab_alloc(cachep, flags);
24609         local_irq_restore(save_flags);
24610         ptr = cache_alloc_debugcheck_after(cachep, flags, ptr, caller);
24611         kmemleak_alloc_recursive(ptr, obj_size(cachep), 1, cachep->flags,
24612 @@ -3609,6 +3613,7 @@ static inline void __cache_free(struct k
24613         check_irq_off();
24614         kmemleak_free_recursive(objp, cachep->flags);
24615         objp = cache_free_debugcheck(cachep, objp, __builtin_return_address(0));
24616 +       vx_slab_free(cachep);
24617  
24618         kmemcheck_slab_free(cachep, objp, obj_size(cachep));
24619  
24620 diff -NurpP --minimal linux-2.6.38.1/mm/slab_vs.h linux-2.6.38.1-vs2.3.0.37-rc9/mm/slab_vs.h
24621 --- linux-2.6.38.1/mm/slab_vs.h 1970-01-01 01:00:00.000000000 +0100
24622 +++ linux-2.6.38.1-vs2.3.0.37-rc9/mm/slab_vs.h  2011-01-29 02:01:07.000000000 +0100
24623 @@ -0,0 +1,29 @@
24624 +
24625 +#include <linux/vserver/context.h>
24626 +
24627 +#include <linux/vs_context.h>
24628 +
24629 +static inline
24630 +void vx_slab_alloc(struct kmem_cache *cachep, gfp_t flags)
24631 +{
24632 +       int what = gfp_zone(cachep->gfpflags);
24633 +       struct vx_info *vxi = current_vx_info();
24634 +
24635 +       if (!vxi)
24636 +               return;
24637 +
24638 +       atomic_add(cachep->buffer_size, &vxi->cacct.slab[what]);
24639 +}
24640 +
24641 +static inline
24642 +void vx_slab_free(struct kmem_cache *cachep)
24643 +{
24644 +       int what = gfp_zone(cachep->gfpflags);
24645 +       struct vx_info *vxi = current_vx_info();
24646 +
24647 +       if (!vxi)
24648 +               return;
24649 +
24650 +       atomic_sub(cachep->buffer_size, &vxi->cacct.slab[what]);
24651 +}
24652 +
24653 diff -NurpP --minimal linux-2.6.38.1/mm/swapfile.c linux-2.6.38.1-vs2.3.0.37-rc9/mm/swapfile.c
24654 --- linux-2.6.38.1/mm/swapfile.c        2011-03-15 18:07:42.000000000 +0100
24655 +++ linux-2.6.38.1-vs2.3.0.37-rc9/mm/swapfile.c 2011-03-07 16:53:28.000000000 +0100
24656 @@ -36,6 +36,8 @@
24657  #include <asm/tlbflush.h>
24658  #include <linux/swapops.h>
24659  #include <linux/page_cgroup.h>
24660 +#include <linux/vs_base.h>
24661 +#include <linux/vs_memory.h>
24662  
24663  static bool swap_count_continued(struct swap_info_struct *, pgoff_t,
24664                                  unsigned char);
24665 @@ -1775,6 +1777,16 @@ static int swap_show(struct seq_file *sw
24666  
24667         if (si == SEQ_START_TOKEN) {
24668                 seq_puts(swap,"Filename\t\t\t\tType\t\tSize\tUsed\tPriority\n");
24669 +               if (vx_flags(VXF_VIRT_MEM, 0)) {
24670 +                       struct sysinfo si;
24671 +
24672 +                       vx_vsi_swapinfo(&si);
24673 +                       if (si.totalswap < (1 << 10))
24674 +                               return 0;
24675 +                       seq_printf(swap, "%s\t\t\t\t\t%s\t%lu\t%lu\t%d\n",
24676 +                               "hdv0", "partition", si.totalswap >> 10,
24677 +                               (si.totalswap - si.freeswap) >> 10, -1);
24678 +               }
24679                 return 0;
24680         }
24681  
24682 @@ -2181,6 +2193,8 @@ void si_swapinfo(struct sysinfo *val)
24683         val->freeswap = nr_swap_pages + nr_to_be_unused;
24684         val->totalswap = total_swap_pages + nr_to_be_unused;
24685         spin_unlock(&swap_lock);
24686 +       if (vx_flags(VXF_VIRT_MEM, 0))
24687 +               vx_vsi_swapinfo(val);
24688  }
24689  
24690  /*
24691 diff -NurpP --minimal linux-2.6.38.1/net/bridge/br_multicast.c linux-2.6.38.1-vs2.3.0.37-rc9/net/bridge/br_multicast.c
24692 --- linux-2.6.38.1/net/bridge/br_multicast.c    2011-03-15 18:07:44.000000000 +0100
24693 +++ linux-2.6.38.1-vs2.3.0.37-rc9/net/bridge/br_multicast.c     2011-03-10 16:51:08.000000000 +0100
24694 @@ -446,7 +446,7 @@ static struct sk_buff *br_ip6_multicast_
24695         ip6h->nexthdr = IPPROTO_HOPOPTS;
24696         ip6h->hop_limit = 1;
24697         ipv6_dev_get_saddr(dev_net(br->dev), br->dev, &ip6h->daddr, 0,
24698 -                          &ip6h->saddr);
24699 +                          &ip6h->saddr, NULL);
24700         ipv6_addr_set(&ip6h->daddr, htonl(0xff020000), 0, 0, htonl(1));
24701         ipv6_eth_mc_map(&ip6h->daddr, eth->h_dest);
24702  
24703 diff -NurpP --minimal linux-2.6.38.1/net/core/dev.c linux-2.6.38.1-vs2.3.0.37-rc9/net/core/dev.c
24704 --- linux-2.6.38.1/net/core/dev.c       2011-03-15 18:07:44.000000000 +0100
24705 +++ linux-2.6.38.1-vs2.3.0.37-rc9/net/core/dev.c        2011-03-15 18:15:06.000000000 +0100
24706 @@ -127,6 +127,7 @@
24707  #include <linux/in.h>
24708  #include <linux/jhash.h>
24709  #include <linux/random.h>
24710 +#include <linux/vs_inet.h>
24711  #include <trace/events/napi.h>
24712  #include <trace/events/net.h>
24713  #include <trace/events/skb.h>
24714 @@ -608,7 +609,8 @@ struct net_device *__dev_get_by_name(str
24715         struct hlist_head *head = dev_name_hash(net, name);
24716  
24717         hlist_for_each_entry(dev, p, head, name_hlist)
24718 -               if (!strncmp(dev->name, name, IFNAMSIZ))
24719 +               if (!strncmp(dev->name, name, IFNAMSIZ) &&
24720 +                   nx_dev_visible(current_nx_info(), dev))
24721                         return dev;
24722  
24723         return NULL;
24724 @@ -634,7 +636,8 @@ struct net_device *dev_get_by_name_rcu(s
24725         struct hlist_head *head = dev_name_hash(net, name);
24726  
24727         hlist_for_each_entry_rcu(dev, p, head, name_hlist)
24728 -               if (!strncmp(dev->name, name, IFNAMSIZ))
24729 +               if (!strncmp(dev->name, name, IFNAMSIZ) &&
24730 +                   nx_dev_visible(current_nx_info(), dev))
24731                         return dev;
24732  
24733         return NULL;
24734 @@ -685,7 +688,8 @@ struct net_device *__dev_get_by_index(st
24735         struct hlist_head *head = dev_index_hash(net, ifindex);
24736  
24737         hlist_for_each_entry(dev, p, head, index_hlist)
24738 -               if (dev->ifindex == ifindex)
24739 +               if ((dev->ifindex == ifindex) &&
24740 +                   nx_dev_visible(current_nx_info(), dev))
24741                         return dev;
24742  
24743         return NULL;
24744 @@ -710,7 +714,8 @@ struct net_device *dev_get_by_index_rcu(
24745         struct hlist_head *head = dev_index_hash(net, ifindex);
24746  
24747         hlist_for_each_entry_rcu(dev, p, head, index_hlist)
24748 -               if (dev->ifindex == ifindex)
24749 +               if ((dev->ifindex == ifindex) &&
24750 +                   nx_dev_visible(current_nx_info(), dev))
24751                         return dev;
24752  
24753         return NULL;
24754 @@ -763,7 +768,8 @@ struct net_device *dev_getbyhwaddr_rcu(s
24755  
24756         for_each_netdev_rcu(net, dev)
24757                 if (dev->type == type &&
24758 -                   !memcmp(dev->dev_addr, ha, dev->addr_len))
24759 +                   !memcmp(dev->dev_addr, ha, dev->addr_len) &&
24760 +                   nx_dev_visible(current_nx_info(), dev))
24761                         return dev;
24762  
24763         return NULL;
24764 @@ -775,9 +781,11 @@ struct net_device *__dev_getfirstbyhwtyp
24765         struct net_device *dev;
24766  
24767         ASSERT_RTNL();
24768 -       for_each_netdev(net, dev)
24769 -               if (dev->type == type)
24770 +       for_each_netdev(net, dev) {
24771 +               if ((dev->type == type) &&
24772 +                   nx_dev_visible(current_nx_info(), dev))
24773                         return dev;
24774 +       }
24775  
24776         return NULL;
24777  }
24778 @@ -895,6 +903,8 @@ static int __dev_alloc_name(struct net *
24779                                 continue;
24780                         if (i < 0 || i >= max_netdevices)
24781                                 continue;
24782 +                       if (!nx_dev_visible(current_nx_info(), d))
24783 +                               continue;
24784  
24785                         /*  avoid cases where sscanf is not exact inverse of printf */
24786                         snprintf(buf, IFNAMSIZ, name, i);
24787 @@ -3873,6 +3883,8 @@ static int dev_ifconf(struct net *net, c
24788  
24789         total = 0;
24790         for_each_netdev(net, dev) {
24791 +               if (!nx_dev_visible(current_nx_info(), dev))
24792 +                       continue;
24793                 for (i = 0; i < NPROTO; i++) {
24794                         if (gifconf_list[i]) {
24795                                 int done;
24796 @@ -3944,6 +3956,10 @@ static void dev_seq_printf_stats(struct 
24797         struct rtnl_link_stats64 temp;
24798         const struct rtnl_link_stats64 *stats = dev_get_stats(dev, &temp);
24799  
24800 +       /* device visible inside network context? */
24801 +       if (!nx_dev_visible(current_nx_info(), dev))
24802 +               return;
24803 +
24804         seq_printf(seq, "%6s: %7llu %7llu %4llu %4llu %4llu %5llu %10llu %9llu "
24805                    "%8llu %7llu %4llu %4llu %4llu %5llu %7llu %10llu\n",
24806                    dev->name, stats->rx_bytes, stats->rx_packets,
24807 diff -NurpP --minimal linux-2.6.38.1/net/core/rtnetlink.c linux-2.6.38.1-vs2.3.0.37-rc9/net/core/rtnetlink.c
24808 --- linux-2.6.38.1/net/core/rtnetlink.c 2011-03-15 18:07:44.000000000 +0100
24809 +++ linux-2.6.38.1-vs2.3.0.37-rc9/net/core/rtnetlink.c  2011-02-17 02:17:52.000000000 +0100
24810 @@ -1012,6 +1012,8 @@ static int rtnl_dump_ifinfo(struct sk_bu
24811                 hlist_for_each_entry(dev, node, head, index_hlist) {
24812                         if (idx < s_idx)
24813                                 goto cont;
24814 +                       if (!nx_dev_visible(skb->sk->sk_nx_info, dev))
24815 +                               continue;
24816                         if (rtnl_fill_ifinfo(skb, dev, RTM_NEWLINK,
24817                                              NETLINK_CB(cb->skb).pid,
24818                                              cb->nlh->nlmsg_seq, 0,
24819 @@ -1771,6 +1773,9 @@ void rtmsg_ifinfo(int type, struct net_d
24820         struct sk_buff *skb;
24821         int err = -ENOBUFS;
24822  
24823 +       if (!nx_dev_visible(current_nx_info(), dev))
24824 +               return;
24825 +
24826         skb = nlmsg_new(if_nlmsg_size(dev), GFP_KERNEL);
24827         if (skb == NULL)
24828                 goto errout;
24829 diff -NurpP --minimal linux-2.6.38.1/net/core/sock.c linux-2.6.38.1-vs2.3.0.37-rc9/net/core/sock.c
24830 --- linux-2.6.38.1/net/core/sock.c      2011-03-15 18:07:44.000000000 +0100
24831 +++ linux-2.6.38.1-vs2.3.0.37-rc9/net/core/sock.c       2011-01-29 02:01:07.000000000 +0100
24832 @@ -127,6 +127,10 @@
24833  #include <net/cls_cgroup.h>
24834  
24835  #include <linux/filter.h>
24836 +#include <linux/vs_socket.h>
24837 +#include <linux/vs_limit.h>
24838 +#include <linux/vs_context.h>
24839 +#include <linux/vs_network.h>
24840  
24841  #ifdef CONFIG_INET
24842  #include <net/tcp.h>
24843 @@ -1070,6 +1074,8 @@ static struct sock *sk_prot_alloc(struct
24844                         goto out_free_sec;
24845                 sk_tx_queue_clear(sk);
24846         }
24847 +               sock_vx_init(sk);
24848 +               sock_nx_init(sk);
24849  
24850         return sk;
24851  
24852 @@ -1169,6 +1175,11 @@ static void __sk_free(struct sock *sk)
24853                 put_cred(sk->sk_peer_cred);
24854         put_pid(sk->sk_peer_pid);
24855         put_net(sock_net(sk));
24856 +       vx_sock_dec(sk);
24857 +       clr_vx_info(&sk->sk_vx_info);
24858 +       sk->sk_xid = -1;
24859 +       clr_nx_info(&sk->sk_nx_info);
24860 +       sk->sk_nid = -1;
24861         sk_prot_free(sk->sk_prot_creator, sk);
24862  }
24863  
24864 @@ -1216,6 +1227,8 @@ struct sock *sk_clone(const struct sock 
24865  
24866                 /* SANITY */
24867                 get_net(sock_net(newsk));
24868 +               sock_vx_init(newsk);
24869 +               sock_nx_init(newsk);
24870                 sk_node_init(&newsk->sk_node);
24871                 sock_lock_init(newsk);
24872                 bh_lock_sock(newsk);
24873 @@ -1271,6 +1284,12 @@ struct sock *sk_clone(const struct sock 
24874                 smp_wmb();
24875                 atomic_set(&newsk->sk_refcnt, 2);
24876  
24877 +               set_vx_info(&newsk->sk_vx_info, sk->sk_vx_info);
24878 +               newsk->sk_xid = sk->sk_xid;
24879 +               vx_sock_inc(newsk);
24880 +               set_nx_info(&newsk->sk_nx_info, sk->sk_nx_info);
24881 +               newsk->sk_nid = sk->sk_nid;
24882 +
24883                 /*
24884                  * Increment the counter in the same struct proto as the master
24885                  * sock (sk_refcnt_debug_inc uses newsk->sk_prot->socks, that
24886 @@ -2017,6 +2036,12 @@ void sock_init_data(struct socket *sock,
24887  
24888         sk->sk_stamp = ktime_set(-1L, 0);
24889  
24890 +       set_vx_info(&sk->sk_vx_info, current_vx_info());
24891 +       sk->sk_xid = vx_current_xid();
24892 +       vx_sock_inc(sk);
24893 +       set_nx_info(&sk->sk_nx_info, current_nx_info());
24894 +       sk->sk_nid = nx_current_nid();
24895 +
24896         /*
24897          * Before updating sk_refcnt, we must commit prior changes to memory
24898          * (Documentation/RCU/rculist_nulls.txt for details)
24899 diff -NurpP --minimal linux-2.6.38.1/net/ipv4/af_inet.c linux-2.6.38.1-vs2.3.0.37-rc9/net/ipv4/af_inet.c
24900 --- linux-2.6.38.1/net/ipv4/af_inet.c   2011-03-15 18:07:45.000000000 +0100
24901 +++ linux-2.6.38.1-vs2.3.0.37-rc9/net/ipv4/af_inet.c    2011-02-17 02:17:52.000000000 +0100
24902 @@ -116,6 +116,7 @@
24903  #ifdef CONFIG_IP_MROUTE
24904  #include <linux/mroute.h>
24905  #endif
24906 +#include <linux/vs_limit.h>
24907  
24908  
24909  /* The inetsw table contains everything that inet_create needs to
24910 @@ -325,9 +326,13 @@ lookup_protocol:
24911         }
24912  
24913         err = -EPERM;
24914 +       if ((protocol == IPPROTO_ICMP) &&
24915 +               nx_capable(CAP_NET_RAW, NXC_RAW_ICMP))
24916 +               goto override;
24917 +
24918         if (sock->type == SOCK_RAW && !kern && !capable(CAP_NET_RAW))
24919                 goto out_rcu_unlock;
24920 -
24921 +override:
24922         err = -EAFNOSUPPORT;
24923         if (!inet_netns_ok(net, protocol))
24924                 goto out_rcu_unlock;
24925 @@ -451,6 +456,7 @@ int inet_bind(struct socket *sock, struc
24926         struct sockaddr_in *addr = (struct sockaddr_in *)uaddr;
24927         struct sock *sk = sock->sk;
24928         struct inet_sock *inet = inet_sk(sk);
24929 +       struct nx_v4_sock_addr nsa;
24930         unsigned short snum;
24931         int chk_addr_ret;
24932         int err;
24933 @@ -464,7 +470,11 @@ int inet_bind(struct socket *sock, struc
24934         if (addr_len < sizeof(struct sockaddr_in))
24935                 goto out;
24936  
24937 -       chk_addr_ret = inet_addr_type(sock_net(sk), addr->sin_addr.s_addr);
24938 +       err = v4_map_sock_addr(inet, addr, &nsa);
24939 +       if (err)
24940 +               goto out;
24941 +
24942 +       chk_addr_ret = inet_addr_type(sock_net(sk), nsa.saddr);
24943  
24944         /* Not specified by any standard per-se, however it breaks too
24945          * many applications when removed.  It is unfortunate since
24946 @@ -476,7 +486,7 @@ int inet_bind(struct socket *sock, struc
24947         err = -EADDRNOTAVAIL;
24948         if (!sysctl_ip_nonlocal_bind &&
24949             !(inet->freebind || inet->transparent) &&
24950 -           addr->sin_addr.s_addr != htonl(INADDR_ANY) &&
24951 +           nsa.saddr != htonl(INADDR_ANY) &&
24952             chk_addr_ret != RTN_LOCAL &&
24953             chk_addr_ret != RTN_MULTICAST &&
24954             chk_addr_ret != RTN_BROADCAST)
24955 @@ -501,7 +511,7 @@ int inet_bind(struct socket *sock, struc
24956         if (sk->sk_state != TCP_CLOSE || inet->inet_num)
24957                 goto out_release_sock;
24958  
24959 -       inet->inet_rcv_saddr = inet->inet_saddr = addr->sin_addr.s_addr;
24960 +       v4_set_sock_addr(inet, &nsa);
24961         if (chk_addr_ret == RTN_MULTICAST || chk_addr_ret == RTN_BROADCAST)
24962                 inet->inet_saddr = 0;  /* Use device */
24963  
24964 @@ -703,11 +713,13 @@ int inet_getname(struct socket *sock, st
24965                      peer == 1))
24966                         return -ENOTCONN;
24967                 sin->sin_port = inet->inet_dport;
24968 -               sin->sin_addr.s_addr = inet->inet_daddr;
24969 +               sin->sin_addr.s_addr =
24970 +                       nx_map_sock_lback(sk->sk_nx_info, inet->inet_daddr);
24971         } else {
24972                 __be32 addr = inet->inet_rcv_saddr;
24973                 if (!addr)
24974                         addr = inet->inet_saddr;
24975 +               addr = nx_map_sock_lback(sk->sk_nx_info, addr);
24976                 sin->sin_port = inet->inet_sport;
24977                 sin->sin_addr.s_addr = addr;
24978         }
24979 diff -NurpP --minimal linux-2.6.38.1/net/ipv4/devinet.c linux-2.6.38.1-vs2.3.0.37-rc9/net/ipv4/devinet.c
24980 --- linux-2.6.38.1/net/ipv4/devinet.c   2011-03-15 18:07:45.000000000 +0100
24981 +++ linux-2.6.38.1-vs2.3.0.37-rc9/net/ipv4/devinet.c    2011-03-15 18:15:06.000000000 +0100
24982 @@ -420,6 +420,7 @@ struct in_device *inetdev_by_index(struc
24983  }
24984  EXPORT_SYMBOL(inetdev_by_index);
24985  
24986 +
24987  /* Called only from RTNL semaphored context. No locks. */
24988  
24989  struct in_ifaddr *inet_ifa_byprefix(struct in_device *in_dev, __be32 prefix,
24990 @@ -660,6 +661,8 @@ int devinet_ioctl(struct net *net, unsig
24991  
24992         in_dev = __in_dev_get_rtnl(dev);
24993         if (in_dev) {
24994 +               struct nx_info *nxi = current_nx_info();
24995 +
24996                 if (tryaddrmatch) {
24997                         /* Matthias Andree */
24998                         /* compare label and address (4.4BSD style) */
24999 @@ -668,6 +671,8 @@ int devinet_ioctl(struct net *net, unsig
25000                            This is checked above. */
25001                         for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
25002                              ifap = &ifa->ifa_next) {
25003 +                               if (!nx_v4_ifa_visible(nxi, ifa))
25004 +                                       continue;
25005                                 if (!strcmp(ifr.ifr_name, ifa->ifa_label) &&
25006                                     sin_orig.sin_addr.s_addr ==
25007                                                         ifa->ifa_local) {
25008 @@ -680,9 +685,12 @@ int devinet_ioctl(struct net *net, unsig
25009                    comparing just the label */
25010                 if (!ifa) {
25011                         for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
25012 -                            ifap = &ifa->ifa_next)
25013 +                            ifap = &ifa->ifa_next) {
25014 +                               if (!nx_v4_ifa_visible(nxi, ifa))
25015 +                                       continue;
25016                                 if (!strcmp(ifr.ifr_name, ifa->ifa_label))
25017                                         break;
25018 +                       }
25019                 }
25020         }
25021  
25022 @@ -834,6 +842,8 @@ static int inet_gifconf(struct net_devic
25023                 goto out;
25024  
25025         for (ifa = in_dev->ifa_list; ifa; ifa = ifa->ifa_next) {
25026 +               if (!nx_v4_ifa_visible(current_nx_info(), ifa))
25027 +                       continue;
25028                 if (!buf) {
25029                         done += sizeof(ifr);
25030                         continue;
25031 @@ -1193,6 +1203,7 @@ static int inet_dump_ifaddr(struct sk_bu
25032         struct net_device *dev;
25033         struct in_device *in_dev;
25034         struct in_ifaddr *ifa;
25035 +       struct sock *sk = skb->sk;
25036         struct hlist_head *head;
25037         struct hlist_node *node;
25038  
25039 @@ -1215,6 +1226,8 @@ static int inet_dump_ifaddr(struct sk_bu
25040  
25041                         for (ifa = in_dev->ifa_list, ip_idx = 0; ifa;
25042                              ifa = ifa->ifa_next, ip_idx++) {
25043 +                       if (sk && !nx_v4_ifa_visible(sk->sk_nx_info, ifa))
25044 +                               continue;
25045                                 if (ip_idx < s_ip_idx)
25046                                         continue;
25047                                 if (inet_fill_ifaddr(skb, ifa,
25048 diff -NurpP --minimal linux-2.6.38.1/net/ipv4/fib_hash.c linux-2.6.38.1-vs2.3.0.37-rc9/net/ipv4/fib_hash.c
25049 --- linux-2.6.38.1/net/ipv4/fib_hash.c  2011-01-05 21:50:41.000000000 +0100
25050 +++ linux-2.6.38.1-vs2.3.0.37-rc9/net/ipv4/fib_hash.c   2011-01-29 02:01:07.000000000 +0100
25051 @@ -1080,7 +1080,7 @@ static int fib_seq_show(struct seq_file 
25052         prefix  = f->fn_key;
25053         mask    = FZ_MASK(iter->zone);
25054         flags   = fib_flag_trans(fa->fa_type, mask, fi);
25055 -       if (fi)
25056 +       if (fi && nx_dev_visible(current_nx_info(), fi->fib_dev))
25057                 seq_printf(seq,
25058                          "%s\t%08X\t%08X\t%04X\t%d\t%u\t%d\t%08X\t%d\t%u\t%u%n",
25059                          fi->fib_dev ? fi->fib_dev->name : "*", prefix,
25060 diff -NurpP --minimal linux-2.6.38.1/net/ipv4/inet_connection_sock.c linux-2.6.38.1-vs2.3.0.37-rc9/net/ipv4/inet_connection_sock.c
25061 --- linux-2.6.38.1/net/ipv4/inet_connection_sock.c      2011-03-15 18:07:45.000000000 +0100
25062 +++ linux-2.6.38.1-vs2.3.0.37-rc9/net/ipv4/inet_connection_sock.c       2011-01-29 05:17:31.000000000 +0100
25063 @@ -52,6 +52,37 @@ void inet_get_local_port_range(int *low,
25064  }
25065  EXPORT_SYMBOL(inet_get_local_port_range);
25066  
25067 +int ipv4_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2)
25068 +{
25069 +       __be32  sk1_rcv_saddr = sk_rcv_saddr(sk1),
25070 +               sk2_rcv_saddr = sk_rcv_saddr(sk2);
25071 +
25072 +       if (inet_v6_ipv6only(sk2))
25073 +               return 0;
25074 +
25075 +       if (sk1_rcv_saddr &&
25076 +           sk2_rcv_saddr &&
25077 +           sk1_rcv_saddr == sk2_rcv_saddr)
25078 +               return 1;
25079 +
25080 +       if (sk1_rcv_saddr &&
25081 +           !sk2_rcv_saddr &&
25082 +           v4_addr_in_nx_info(sk2->sk_nx_info, sk1_rcv_saddr, NXA_MASK_BIND))
25083 +               return 1;
25084 +
25085 +       if (sk2_rcv_saddr &&
25086 +           !sk1_rcv_saddr &&
25087 +           v4_addr_in_nx_info(sk1->sk_nx_info, sk2_rcv_saddr, NXA_MASK_BIND))
25088 +               return 1;
25089 +
25090 +       if (!sk1_rcv_saddr &&
25091 +           !sk2_rcv_saddr &&
25092 +           nx_v4_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info))
25093 +               return 1;
25094 +
25095 +       return 0;
25096 +}
25097 +
25098  int inet_csk_bind_conflict(const struct sock *sk,
25099                            const struct inet_bind_bucket *tb)
25100  {
25101 @@ -74,9 +105,7 @@ int inet_csk_bind_conflict(const struct 
25102                      sk->sk_bound_dev_if == sk2->sk_bound_dev_if)) {
25103                         if (!reuse || !sk2->sk_reuse ||
25104                             ((1 << sk2->sk_state) & (TCPF_LISTEN | TCPF_CLOSE))) {
25105 -                               const __be32 sk2_rcv_saddr = sk_rcv_saddr(sk2);
25106 -                               if (!sk2_rcv_saddr || !sk_rcv_saddr(sk) ||
25107 -                                   sk2_rcv_saddr == sk_rcv_saddr(sk))
25108 +                               if (ipv4_rcv_saddr_equal(sk, sk2))
25109                                         break;
25110                         }
25111                 }
25112 diff -NurpP --minimal linux-2.6.38.1/net/ipv4/inet_diag.c linux-2.6.38.1-vs2.3.0.37-rc9/net/ipv4/inet_diag.c
25113 --- linux-2.6.38.1/net/ipv4/inet_diag.c 2011-01-05 21:50:42.000000000 +0100
25114 +++ linux-2.6.38.1-vs2.3.0.37-rc9/net/ipv4/inet_diag.c  2011-01-29 02:01:07.000000000 +0100
25115 @@ -33,6 +33,8 @@
25116  #include <linux/stddef.h>
25117  
25118  #include <linux/inet_diag.h>
25119 +#include <linux/vs_network.h>
25120 +#include <linux/vs_inet.h>
25121  
25122  static const struct inet_diag_handler **inet_diag_table;
25123  
25124 @@ -119,8 +121,10 @@ static int inet_csk_diag_fill(struct soc
25125  
25126         r->id.idiag_sport = inet->inet_sport;
25127         r->id.idiag_dport = inet->inet_dport;
25128 -       r->id.idiag_src[0] = inet->inet_rcv_saddr;
25129 -       r->id.idiag_dst[0] = inet->inet_daddr;
25130 +       r->id.idiag_src[0] = nx_map_sock_lback(sk->sk_nx_info,
25131 +               inet->inet_rcv_saddr);
25132 +       r->id.idiag_dst[0] = nx_map_sock_lback(sk->sk_nx_info,
25133 +               inet->inet_daddr);
25134  
25135  #if defined(CONFIG_IPV6) || defined (CONFIG_IPV6_MODULE)
25136         if (r->idiag_family == AF_INET6) {
25137 @@ -205,8 +209,8 @@ static int inet_twsk_diag_fill(struct in
25138         r->id.idiag_cookie[1] = (u32)(((unsigned long)tw >> 31) >> 1);
25139         r->id.idiag_sport     = tw->tw_sport;
25140         r->id.idiag_dport     = tw->tw_dport;
25141 -       r->id.idiag_src[0]    = tw->tw_rcv_saddr;
25142 -       r->id.idiag_dst[0]    = tw->tw_daddr;
25143 +       r->id.idiag_src[0]    = nx_map_sock_lback(tw->tw_nx_info, tw->tw_rcv_saddr);
25144 +       r->id.idiag_dst[0]    = nx_map_sock_lback(tw->tw_nx_info, tw->tw_daddr);
25145         r->idiag_state        = tw->tw_substate;
25146         r->idiag_timer        = 3;
25147         r->idiag_expires      = DIV_ROUND_UP(tmo * 1000, HZ);
25148 @@ -263,6 +267,7 @@ static int inet_diag_get_exact(struct sk
25149         err = -EINVAL;
25150  
25151         if (req->idiag_family == AF_INET) {
25152 +               /* TODO: lback */
25153                 sk = inet_lookup(&init_net, hashinfo, req->id.idiag_dst[0],
25154                                  req->id.idiag_dport, req->id.idiag_src[0],
25155                                  req->id.idiag_sport, req->id.idiag_if);
25156 @@ -507,6 +512,7 @@ static int inet_csk_diag_dump(struct soc
25157                 } else
25158  #endif
25159                 {
25160 +                       /* TODO: lback */
25161                         entry.saddr = &inet->inet_rcv_saddr;
25162                         entry.daddr = &inet->inet_daddr;
25163                 }
25164 @@ -545,6 +551,7 @@ static int inet_twsk_diag_dump(struct in
25165                 } else
25166  #endif
25167                 {
25168 +                       /* TODO: lback */
25169                         entry.saddr = &tw->tw_rcv_saddr;
25170                         entry.daddr = &tw->tw_daddr;
25171                 }
25172 @@ -591,8 +598,8 @@ static int inet_diag_fill_req(struct sk_
25173  
25174         r->id.idiag_sport = inet->inet_sport;
25175         r->id.idiag_dport = ireq->rmt_port;
25176 -       r->id.idiag_src[0] = ireq->loc_addr;
25177 -       r->id.idiag_dst[0] = ireq->rmt_addr;
25178 +       r->id.idiag_src[0] = nx_map_sock_lback(sk->sk_nx_info, ireq->loc_addr);
25179 +       r->id.idiag_dst[0] = nx_map_sock_lback(sk->sk_nx_info, ireq->rmt_addr);
25180         r->idiag_expires = jiffies_to_msecs(tmo);
25181         r->idiag_rqueue = 0;
25182         r->idiag_wqueue = 0;
25183 @@ -663,6 +670,7 @@ static int inet_diag_dump_reqs(struct sk
25184                                 continue;
25185  
25186                         if (bc) {
25187 +                               /* TODO: lback */
25188                                 entry.saddr =
25189  #if defined(CONFIG_IPV6) || defined (CONFIG_IPV6_MODULE)
25190                                         (entry.family == AF_INET6) ?
25191 @@ -733,6 +741,8 @@ static int inet_diag_dump(struct sk_buff
25192                         sk_nulls_for_each(sk, node, &ilb->head) {
25193                                 struct inet_sock *inet = inet_sk(sk);
25194  
25195 +                               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
25196 +                                       continue;
25197                                 if (num < s_num) {
25198                                         num++;
25199                                         continue;
25200 @@ -799,6 +809,8 @@ skip_listen_ht:
25201                 sk_nulls_for_each(sk, node, &head->chain) {
25202                         struct inet_sock *inet = inet_sk(sk);
25203  
25204 +                       if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
25205 +                               continue;
25206                         if (num < s_num)
25207                                 goto next_normal;
25208                         if (!(r->idiag_states & (1 << sk->sk_state)))
25209 @@ -823,6 +835,8 @@ next_normal:
25210                         inet_twsk_for_each(tw, node,
25211                                     &head->twchain) {
25212  
25213 +                               if (!nx_check(tw->tw_nid, VS_WATCH_P | VS_IDENT))
25214 +                                       continue;
25215                                 if (num < s_num)
25216                                         goto next_dying;
25217                                 if (r->id.idiag_sport != tw->tw_sport &&
25218 diff -NurpP --minimal linux-2.6.38.1/net/ipv4/inet_hashtables.c linux-2.6.38.1-vs2.3.0.37-rc9/net/ipv4/inet_hashtables.c
25219 --- linux-2.6.38.1/net/ipv4/inet_hashtables.c   2011-01-05 21:50:42.000000000 +0100
25220 +++ linux-2.6.38.1-vs2.3.0.37-rc9/net/ipv4/inet_hashtables.c    2011-01-29 02:01:07.000000000 +0100
25221 @@ -21,6 +21,7 @@
25222  
25223  #include <net/inet_connection_sock.h>
25224  #include <net/inet_hashtables.h>
25225 +#include <net/route.h>
25226  #include <net/ip.h>
25227  
25228  /*
25229 @@ -155,6 +156,11 @@ static inline int compute_score(struct s
25230                         if (rcv_saddr != daddr)
25231                                 return -1;
25232                         score += 2;
25233 +               } else {
25234 +                       /* block non nx_info ips */
25235 +                       if (!v4_addr_in_nx_info(sk->sk_nx_info,
25236 +                               daddr, NXA_MASK_BIND))
25237 +                               return -1;
25238                 }
25239                 if (sk->sk_bound_dev_if) {
25240                         if (sk->sk_bound_dev_if != dif)
25241 @@ -172,7 +178,6 @@ static inline int compute_score(struct s
25242   * wildcarded during the search since they can never be otherwise.
25243   */
25244  
25245 -
25246  struct sock *__inet_lookup_listener(struct net *net,
25247                                     struct inet_hashinfo *hashinfo,
25248                                     const __be32 daddr, const unsigned short hnum,
25249 @@ -195,6 +200,7 @@ begin:
25250                         hiscore = score;
25251                 }
25252         }
25253 +
25254         /*
25255          * if the nulls value we got at the end of this lookup is
25256          * not the expected one, we must restart lookup.
25257 diff -NurpP --minimal linux-2.6.38.1/net/ipv4/netfilter/nf_nat_helper.c linux-2.6.38.1-vs2.3.0.37-rc9/net/ipv4/netfilter/nf_nat_helper.c
25258 --- linux-2.6.38.1/net/ipv4/netfilter/nf_nat_helper.c   2011-01-05 21:50:42.000000000 +0100
25259 +++ linux-2.6.38.1-vs2.3.0.37-rc9/net/ipv4/netfilter/nf_nat_helper.c    2011-01-29 02:01:07.000000000 +0100
25260 @@ -20,6 +20,7 @@
25261  #include <net/route.h>
25262  
25263  #include <linux/netfilter_ipv4.h>
25264 +#include <net/route.h>
25265  #include <net/netfilter/nf_conntrack.h>
25266  #include <net/netfilter/nf_conntrack_helper.h>
25267  #include <net/netfilter/nf_conntrack_ecache.h>
25268 diff -NurpP --minimal linux-2.6.38.1/net/ipv4/netfilter.c linux-2.6.38.1-vs2.3.0.37-rc9/net/ipv4/netfilter.c
25269 --- linux-2.6.38.1/net/ipv4/netfilter.c 2011-03-15 18:07:45.000000000 +0100
25270 +++ linux-2.6.38.1-vs2.3.0.37-rc9/net/ipv4/netfilter.c  2011-01-29 02:01:07.000000000 +0100
25271 @@ -5,7 +5,7 @@
25272  #include <linux/ip.h>
25273  #include <linux/skbuff.h>
25274  #include <linux/gfp.h>
25275 -#include <net/route.h>
25276 +// #include <net/route.h>
25277  #include <net/xfrm.h>
25278  #include <net/ip.h>
25279  #include <net/netfilter/nf_queue.h>
25280 diff -NurpP --minimal linux-2.6.38.1/net/ipv4/raw.c linux-2.6.38.1-vs2.3.0.37-rc9/net/ipv4/raw.c
25281 --- linux-2.6.38.1/net/ipv4/raw.c       2011-03-15 18:07:45.000000000 +0100
25282 +++ linux-2.6.38.1-vs2.3.0.37-rc9/net/ipv4/raw.c        2011-02-17 02:17:52.000000000 +0100
25283 @@ -117,7 +117,7 @@ static struct sock *__raw_v4_lookup(stru
25284  
25285                 if (net_eq(sock_net(sk), net) && inet->inet_num == num  &&
25286                     !(inet->inet_daddr && inet->inet_daddr != raddr)    &&
25287 -                   !(inet->inet_rcv_saddr && inet->inet_rcv_saddr != laddr) &&
25288 +                   v4_sock_addr_match(sk->sk_nx_info, inet, laddr)     &&
25289                     !(sk->sk_bound_dev_if && sk->sk_bound_dev_if != dif))
25290                         goto found; /* gotcha */
25291         }
25292 @@ -384,6 +384,12 @@ static int raw_send_hdrinc(struct sock *
25293                 icmp_out_count(net, ((struct icmphdr *)
25294                         skb_transport_header(skb))->type);
25295  
25296 +       err = -EPERM;
25297 +       if (!nx_check(0, VS_ADMIN) && !capable(CAP_NET_RAW) &&
25298 +               sk->sk_nx_info &&
25299 +               !v4_addr_in_nx_info(sk->sk_nx_info, iph->saddr, NXA_MASK_BIND))
25300 +               goto error_free;
25301 +
25302         err = NF_HOOK(NFPROTO_IPV4, NF_INET_LOCAL_OUT, skb, NULL,
25303                       rt->dst.dev, dst_output);
25304         if (err > 0)
25305 @@ -563,6 +569,13 @@ static int raw_sendmsg(struct kiocb *ioc
25306                 }
25307  
25308                 security_sk_classify_flow(sk, &fl);
25309 +               if (sk->sk_nx_info) {
25310 +                       err = ip_v4_find_src(sock_net(sk),
25311 +                               sk->sk_nx_info, &rt, &fl);
25312 +
25313 +                       if (err)
25314 +                               goto done;
25315 +               }
25316                 err = ip_route_output_flow(sock_net(sk), &rt, &fl, sk, 1);
25317         }
25318         if (err)
25319 @@ -635,17 +648,19 @@ static int raw_bind(struct sock *sk, str
25320  {
25321         struct inet_sock *inet = inet_sk(sk);
25322         struct sockaddr_in *addr = (struct sockaddr_in *) uaddr;
25323 +       struct nx_v4_sock_addr nsa = { 0 };
25324         int ret = -EINVAL;
25325         int chk_addr_ret;
25326  
25327         if (sk->sk_state != TCP_CLOSE || addr_len < sizeof(struct sockaddr_in))
25328                 goto out;
25329 -       chk_addr_ret = inet_addr_type(sock_net(sk), addr->sin_addr.s_addr);
25330 +       v4_map_sock_addr(inet, addr, &nsa);
25331 +       chk_addr_ret = inet_addr_type(sock_net(sk), nsa.saddr);
25332         ret = -EADDRNOTAVAIL;
25333 -       if (addr->sin_addr.s_addr && chk_addr_ret != RTN_LOCAL &&
25334 +       if (nsa.saddr && chk_addr_ret != RTN_LOCAL &&
25335             chk_addr_ret != RTN_MULTICAST && chk_addr_ret != RTN_BROADCAST)
25336                 goto out;
25337 -       inet->inet_rcv_saddr = inet->inet_saddr = addr->sin_addr.s_addr;
25338 +       v4_set_sock_addr(inet, &nsa);
25339         if (chk_addr_ret == RTN_MULTICAST || chk_addr_ret == RTN_BROADCAST)
25340                 inet->inet_saddr = 0;  /* Use device */
25341         sk_dst_reset(sk);
25342 @@ -697,7 +712,8 @@ static int raw_recvmsg(struct kiocb *ioc
25343         /* Copy the address. */
25344         if (sin) {
25345                 sin->sin_family = AF_INET;
25346 -               sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
25347 +               sin->sin_addr.s_addr =
25348 +                       nx_map_sock_lback(sk->sk_nx_info, ip_hdr(skb)->saddr);
25349                 sin->sin_port = 0;
25350                 memset(&sin->sin_zero, 0, sizeof(sin->sin_zero));
25351         }
25352 @@ -893,7 +909,8 @@ static struct sock *raw_get_first(struct
25353                 struct hlist_node *node;
25354  
25355                 sk_for_each(sk, node, &state->h->ht[state->bucket])
25356 -                       if (sock_net(sk) == seq_file_net(seq))
25357 +                       if ((sock_net(sk) == seq_file_net(seq)) &&
25358 +                               nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
25359                                 goto found;
25360         }
25361         sk = NULL;
25362 @@ -909,7 +926,8 @@ static struct sock *raw_get_next(struct 
25363                 sk = sk_next(sk);
25364  try_again:
25365                 ;
25366 -       } while (sk && sock_net(sk) != seq_file_net(seq));
25367 +       } while (sk && ((sock_net(sk) != seq_file_net(seq)) ||
25368 +               !nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT)));
25369  
25370         if (!sk && ++state->bucket < RAW_HTABLE_SIZE) {
25371                 sk = sk_head(&state->h->ht[state->bucket]);
25372 @@ -968,7 +986,10 @@ static void raw_sock_seq_show(struct seq
25373  
25374         seq_printf(seq, "%4d: %08X:%04X %08X:%04X"
25375                 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %lu %d %p %d\n",
25376 -               i, src, srcp, dest, destp, sp->sk_state,
25377 +               i,
25378 +               nx_map_sock_lback(current_nx_info(), src), srcp,
25379 +               nx_map_sock_lback(current_nx_info(), dest), destp,
25380 +               sp->sk_state,
25381                 sk_wmem_alloc_get(sp),
25382                 sk_rmem_alloc_get(sp),
25383                 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
25384 diff -NurpP --minimal linux-2.6.38.1/net/ipv4/tcp.c linux-2.6.38.1-vs2.3.0.37-rc9/net/ipv4/tcp.c
25385 --- linux-2.6.38.1/net/ipv4/tcp.c       2011-03-15 18:07:45.000000000 +0100
25386 +++ linux-2.6.38.1-vs2.3.0.37-rc9/net/ipv4/tcp.c        2011-01-29 02:01:07.000000000 +0100
25387 @@ -266,6 +266,7 @@
25388  #include <linux/crypto.h>
25389  #include <linux/time.h>
25390  #include <linux/slab.h>
25391 +#include <linux/in.h>
25392  
25393  #include <net/icmp.h>
25394  #include <net/tcp.h>
25395 diff -NurpP --minimal linux-2.6.38.1/net/ipv4/tcp_ipv4.c linux-2.6.38.1-vs2.3.0.37-rc9/net/ipv4/tcp_ipv4.c
25396 --- linux-2.6.38.1/net/ipv4/tcp_ipv4.c  2011-03-15 18:07:45.000000000 +0100
25397 +++ linux-2.6.38.1-vs2.3.0.37-rc9/net/ipv4/tcp_ipv4.c   2011-02-02 22:20:27.000000000 +0100
25398 @@ -1988,6 +1988,12 @@ static void *listening_get_next(struct s
25399                 req = req->dl_next;
25400                 while (1) {
25401                         while (req) {
25402 +                               vxdprintk(VXD_CBIT(net, 6),
25403 +                                       "sk,req: %p [#%d] (from %d)", req->sk,
25404 +                                       (req->sk)?req->sk->sk_nid:0, nx_current_nid());
25405 +                               if (req->sk &&
25406 +                                       !nx_check(req->sk->sk_nid, VS_WATCH_P | VS_IDENT))
25407 +                                       continue;
25408                                 if (req->rsk_ops->family == st->family) {
25409                                         cur = req;
25410                                         goto out;
25411 @@ -2012,6 +2018,10 @@ get_req:
25412         }
25413  get_sk:
25414         sk_nulls_for_each_from(sk, node) {
25415 +               vxdprintk(VXD_CBIT(net, 6), "sk: %p [#%d] (from %d)",
25416 +                       sk, sk->sk_nid, nx_current_nid());
25417 +               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
25418 +                       continue;
25419                 if (!net_eq(sock_net(sk), net))
25420                         continue;
25421                 if (sk->sk_family == st->family) {
25422 @@ -2088,6 +2098,11 @@ static void *established_get_first(struc
25423  
25424                 spin_lock_bh(lock);
25425                 sk_nulls_for_each(sk, node, &tcp_hashinfo.ehash[st->bucket].chain) {
25426 +                       vxdprintk(VXD_CBIT(net, 6),
25427 +                               "sk,egf: %p [#%d] (from %d)",
25428 +                               sk, sk->sk_nid, nx_current_nid());
25429 +                       if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
25430 +                               continue;
25431                         if (sk->sk_family != st->family ||
25432                             !net_eq(sock_net(sk), net)) {
25433                                 continue;
25434 @@ -2098,6 +2113,11 @@ static void *established_get_first(struc
25435                 st->state = TCP_SEQ_STATE_TIME_WAIT;
25436                 inet_twsk_for_each(tw, node,
25437                                    &tcp_hashinfo.ehash[st->bucket].twchain) {
25438 +                       vxdprintk(VXD_CBIT(net, 6),
25439 +                               "tw: %p [#%d] (from %d)",
25440 +                               tw, tw->tw_nid, nx_current_nid());
25441 +                       if (!nx_check(tw->tw_nid, VS_WATCH_P | VS_IDENT))
25442 +                               continue;
25443                         if (tw->tw_family != st->family ||
25444                             !net_eq(twsk_net(tw), net)) {
25445                                 continue;
25446 @@ -2127,7 +2147,9 @@ static void *established_get_next(struct
25447                 tw = cur;
25448                 tw = tw_next(tw);
25449  get_tw:
25450 -               while (tw && (tw->tw_family != st->family || !net_eq(twsk_net(tw), net))) {
25451 +               while (tw && (tw->tw_family != st->family ||
25452 +                       !net_eq(twsk_net(tw), net) ||
25453 +                       !nx_check(tw->tw_nid, VS_WATCH_P | VS_IDENT))) {
25454                         tw = tw_next(tw);
25455                 }
25456                 if (tw) {
25457 @@ -2151,6 +2173,11 @@ get_tw:
25458                 sk = sk_nulls_next(sk);
25459  
25460         sk_nulls_for_each_from(sk, node) {
25461 +               vxdprintk(VXD_CBIT(net, 6),
25462 +                       "sk,egn: %p [#%d] (from %d)",
25463 +                       sk, sk->sk_nid, nx_current_nid());
25464 +               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
25465 +                       continue;
25466                 if (sk->sk_family == st->family && net_eq(sock_net(sk), net))
25467                         goto found;
25468         }
25469 @@ -2360,9 +2387,9 @@ static void get_openreq4(struct sock *sk
25470         seq_printf(f, "%4d: %08X:%04X %08X:%04X"
25471                 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %u %d %p%n",
25472                 i,
25473 -               ireq->loc_addr,
25474 +               nx_map_sock_lback(current_nx_info(), ireq->loc_addr),
25475                 ntohs(inet_sk(sk)->inet_sport),
25476 -               ireq->rmt_addr,
25477 +               nx_map_sock_lback(current_nx_info(), ireq->rmt_addr),
25478                 ntohs(ireq->rmt_port),
25479                 TCP_SYN_RECV,
25480                 0, 0, /* could print option size, but that is af dependent. */
25481 @@ -2414,7 +2441,10 @@ static void get_tcp4_sock(struct sock *s
25482  
25483         seq_printf(f, "%4d: %08X:%04X %08X:%04X %02X %08X:%08X %02X:%08lX "
25484                         "%08X %5d %8d %lu %d %p %lu %lu %u %u %d%n",
25485 -               i, src, srcp, dest, destp, sk->sk_state,
25486 +               i,
25487 +               nx_map_sock_lback(current_nx_info(), src), srcp,
25488 +               nx_map_sock_lback(current_nx_info(), dest), destp,
25489 +               sk->sk_state,
25490                 tp->write_seq - tp->snd_una,
25491                 rx_queue,
25492                 timer_active,
25493 @@ -2449,7 +2479,10 @@ static void get_timewait4_sock(struct in
25494  
25495         seq_printf(f, "%4d: %08X:%04X %08X:%04X"
25496                 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %d %d %p%n",
25497 -               i, src, srcp, dest, destp, tw->tw_substate, 0, 0,
25498 +               i,
25499 +               nx_map_sock_lback(current_nx_info(), src), srcp,
25500 +               nx_map_sock_lback(current_nx_info(), dest), destp,
25501 +               tw->tw_substate, 0, 0,
25502                 3, jiffies_to_clock_t(ttd), 0, 0, 0, 0,
25503                 atomic_read(&tw->tw_refcnt), tw, len);
25504  }
25505 diff -NurpP --minimal linux-2.6.38.1/net/ipv4/tcp_minisocks.c linux-2.6.38.1-vs2.3.0.37-rc9/net/ipv4/tcp_minisocks.c
25506 --- linux-2.6.38.1/net/ipv4/tcp_minisocks.c     2011-03-15 18:07:45.000000000 +0100
25507 +++ linux-2.6.38.1-vs2.3.0.37-rc9/net/ipv4/tcp_minisocks.c      2011-01-29 02:01:07.000000000 +0100
25508 @@ -23,6 +23,9 @@
25509  #include <linux/slab.h>
25510  #include <linux/sysctl.h>
25511  #include <linux/workqueue.h>
25512 +#include <linux/vs_limit.h>
25513 +#include <linux/vs_socket.h>
25514 +#include <linux/vs_context.h>
25515  #include <net/tcp.h>
25516  #include <net/inet_common.h>
25517  #include <net/xfrm.h>
25518 @@ -335,6 +338,11 @@ void tcp_time_wait(struct sock *sk, int 
25519                 tcptw->tw_ts_recent     = tp->rx_opt.ts_recent;
25520                 tcptw->tw_ts_recent_stamp = tp->rx_opt.ts_recent_stamp;
25521  
25522 +               tw->tw_xid              = sk->sk_xid;
25523 +               tw->tw_vx_info          = NULL;
25524 +               tw->tw_nid              = sk->sk_nid;
25525 +               tw->tw_nx_info          = NULL;
25526 +
25527  #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
25528                 if (tw->tw_family == PF_INET6) {
25529                         struct ipv6_pinfo *np = inet6_sk(sk);
25530 diff -NurpP --minimal linux-2.6.38.1/net/ipv4/udp.c linux-2.6.38.1-vs2.3.0.37-rc9/net/ipv4/udp.c
25531 --- linux-2.6.38.1/net/ipv4/udp.c       2011-03-15 18:07:45.000000000 +0100
25532 +++ linux-2.6.38.1-vs2.3.0.37-rc9/net/ipv4/udp.c        2011-01-29 02:01:07.000000000 +0100
25533 @@ -296,14 +296,7 @@ fail:
25534  }
25535  EXPORT_SYMBOL(udp_lib_get_port);
25536  
25537 -static int ipv4_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2)
25538 -{
25539 -       struct inet_sock *inet1 = inet_sk(sk1), *inet2 = inet_sk(sk2);
25540 -
25541 -       return  (!ipv6_only_sock(sk2)  &&
25542 -                (!inet1->inet_rcv_saddr || !inet2->inet_rcv_saddr ||
25543 -                  inet1->inet_rcv_saddr == inet2->inet_rcv_saddr));
25544 -}
25545 +extern int ipv4_rcv_saddr_equal(const struct sock *, const struct sock *);
25546  
25547  static unsigned int udp4_portaddr_hash(struct net *net, __be32 saddr,
25548                                        unsigned int port)
25549 @@ -338,6 +331,11 @@ static inline int compute_score(struct s
25550                         if (inet->inet_rcv_saddr != daddr)
25551                                 return -1;
25552                         score += 2;
25553 +               } else {
25554 +                       /* block non nx_info ips */
25555 +                       if (!v4_addr_in_nx_info(sk->sk_nx_info,
25556 +                               daddr, NXA_MASK_BIND))
25557 +                               return -1;
25558                 }
25559                 if (inet->inet_daddr) {
25560                         if (inet->inet_daddr != saddr)
25561 @@ -441,6 +439,7 @@ exact_match:
25562         return result;
25563  }
25564  
25565 +
25566  /* UDP is nearly always wildcards out the wazoo, it makes no sense to try
25567   * harder than this. -DaveM
25568   */
25569 @@ -486,6 +485,11 @@ begin:
25570         sk_nulls_for_each_rcu(sk, node, &hslot->head) {
25571                 score = compute_score(sk, net, saddr, hnum, sport,
25572                                       daddr, dport, dif);
25573 +               /* FIXME: disabled?
25574 +               if (score == 9) {
25575 +                       result = sk;
25576 +                       break;
25577 +               } else */
25578                 if (score > badness) {
25579                         result = sk;
25580                         badness = score;
25581 @@ -499,6 +503,7 @@ begin:
25582         if (get_nulls_value(node) != slot)
25583                 goto begin;
25584  
25585 +
25586         if (result) {
25587                 if (unlikely(!atomic_inc_not_zero_hint(&result->sk_refcnt, 2)))
25588                         result = NULL;
25589 @@ -508,6 +513,7 @@ begin:
25590                         goto begin;
25591                 }
25592         }
25593 +
25594         rcu_read_unlock();
25595         return result;
25596  }
25597 @@ -550,8 +556,7 @@ static inline struct sock *udp_v4_mcast_
25598                     udp_sk(s)->udp_port_hash != hnum ||
25599                     (inet->inet_daddr && inet->inet_daddr != rmt_addr) ||
25600                     (inet->inet_dport != rmt_port && inet->inet_dport) ||
25601 -                   (inet->inet_rcv_saddr &&
25602 -                    inet->inet_rcv_saddr != loc_addr) ||
25603 +                   !v4_sock_addr_match(sk->sk_nx_info, inet, loc_addr) ||
25604                     ipv6_only_sock(s) ||
25605                     (s->sk_bound_dev_if && s->sk_bound_dev_if != dif))
25606                         continue;
25607 @@ -898,8 +903,13 @@ int udp_sendmsg(struct kiocb *iocb, stru
25608                                     .fl_ip_sport = inet->inet_sport,
25609                                     .fl_ip_dport = dport };
25610                 struct net *net = sock_net(sk);
25611 +               struct nx_info *nxi = sk->sk_nx_info;
25612  
25613                 security_sk_classify_flow(sk, &fl);
25614 +               err = ip_v4_find_src(net, nxi, &rt, &fl);
25615 +               if (err)
25616 +                       goto out;
25617 +
25618                 err = ip_route_output_flow(net, &rt, &fl, sk, 1);
25619                 if (err) {
25620                         if (err == -ENETUNREACH)
25621 @@ -1181,7 +1191,8 @@ try_again:
25622         if (sin) {
25623                 sin->sin_family = AF_INET;
25624                 sin->sin_port = udp_hdr(skb)->source;
25625 -               sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
25626 +               sin->sin_addr.s_addr = nx_map_sock_lback(
25627 +                       skb->sk->sk_nx_info, ip_hdr(skb)->saddr);
25628                 memset(sin->sin_zero, 0, sizeof(sin->sin_zero));
25629         }
25630         if (inet->cmsg_flags)
25631 @@ -1922,6 +1933,8 @@ static struct sock *udp_get_first(struct
25632                 sk_nulls_for_each(sk, node, &hslot->head) {
25633                         if (!net_eq(sock_net(sk), net))
25634                                 continue;
25635 +                       if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
25636 +                               continue;
25637                         if (sk->sk_family == state->family)
25638                                 goto found;
25639                 }
25640 @@ -1939,7 +1952,9 @@ static struct sock *udp_get_next(struct 
25641  
25642         do {
25643                 sk = sk_nulls_next(sk);
25644 -       } while (sk && (!net_eq(sock_net(sk), net) || sk->sk_family != state->family));
25645 +       } while (sk && (!net_eq(sock_net(sk), net) ||
25646 +               sk->sk_family != state->family ||
25647 +               !nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT)));
25648  
25649         if (!sk) {
25650                 if (state->bucket <= state->udp_table->mask)
25651 @@ -2046,7 +2061,10 @@ static void udp4_format_sock(struct sock
25652  
25653         seq_printf(f, "%5d: %08X:%04X %08X:%04X"
25654                 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %lu %d %p %d%n",
25655 -               bucket, src, srcp, dest, destp, sp->sk_state,
25656 +               bucket,
25657 +               nx_map_sock_lback(current_nx_info(), src), srcp,
25658 +               nx_map_sock_lback(current_nx_info(), dest), destp,
25659 +               sp->sk_state,
25660                 sk_wmem_alloc_get(sp),
25661                 sk_rmem_alloc_get(sp),
25662                 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
25663 diff -NurpP --minimal linux-2.6.38.1/net/ipv6/Kconfig linux-2.6.38.1-vs2.3.0.37-rc9/net/ipv6/Kconfig
25664 --- linux-2.6.38.1/net/ipv6/Kconfig     2010-08-02 16:52:59.000000000 +0200
25665 +++ linux-2.6.38.1-vs2.3.0.37-rc9/net/ipv6/Kconfig      2011-01-29 02:01:07.000000000 +0100
25666 @@ -4,8 +4,8 @@
25667  
25668  #   IPv6 as module will cause a CRASH if you try to unload it
25669  menuconfig IPV6
25670 -       tristate "The IPv6 protocol"
25671 -       default m
25672 +       bool "The IPv6 protocol"
25673 +       default n
25674         ---help---
25675           This is complemental support for the IP version 6.
25676           You will still be able to do traditional IPv4 networking as well.
25677 diff -NurpP --minimal linux-2.6.38.1/net/ipv6/addrconf.c linux-2.6.38.1-vs2.3.0.37-rc9/net/ipv6/addrconf.c
25678 --- linux-2.6.38.1/net/ipv6/addrconf.c  2011-03-15 18:07:45.000000000 +0100
25679 +++ linux-2.6.38.1-vs2.3.0.37-rc9/net/ipv6/addrconf.c   2011-02-02 22:20:27.000000000 +0100
25680 @@ -87,6 +87,8 @@
25681  
25682  #include <linux/proc_fs.h>
25683  #include <linux/seq_file.h>
25684 +#include <linux/vs_network.h>
25685 +#include <linux/vs_inet6.h>
25686  
25687  /* Set to 3 to get tracing... */
25688  #define ACONF_DEBUG 2
25689 @@ -1121,7 +1123,7 @@ out:
25690  
25691  int ipv6_dev_get_saddr(struct net *net, struct net_device *dst_dev,
25692                        const struct in6_addr *daddr, unsigned int prefs,
25693 -                      struct in6_addr *saddr)
25694 +                      struct in6_addr *saddr, struct nx_info *nxi)
25695  {
25696         struct ipv6_saddr_score scores[2],
25697                                 *score = &scores[0], *hiscore = &scores[1];
25698 @@ -1193,6 +1195,8 @@ int ipv6_dev_get_saddr(struct net *net, 
25699                                                dev->name);
25700                                 continue;
25701                         }
25702 +                       if (!v6_addr_in_nx_info(nxi, &score->ifa->addr, -1))
25703 +                               continue;
25704  
25705                         score->rule = -1;
25706                         bitmap_zero(score->scorebits, IPV6_SADDR_RULE_MAX);
25707 @@ -3061,7 +3065,10 @@ static void if6_seq_stop(struct seq_file
25708  static int if6_seq_show(struct seq_file *seq, void *v)
25709  {
25710         struct inet6_ifaddr *ifp = (struct inet6_ifaddr *)v;
25711 -       seq_printf(seq, "%pi6 %02x %02x %02x %02x %8s\n",
25712 +
25713 +       if (nx_check(0, VS_ADMIN|VS_WATCH) ||
25714 +           v6_addr_in_nx_info(current_nx_info(), &ifp->addr, -1))
25715 +               seq_printf(seq, "%pi6 %02x %02x %02x %02x %8s\n",
25716                    &ifp->addr,
25717                    ifp->idev->dev->ifindex,
25718                    ifp->prefix_len,
25719 @@ -3567,6 +3574,11 @@ static int in6_dump_addrs(struct inet6_d
25720         struct ifacaddr6 *ifaca;
25721         int err = 1;
25722         int ip_idx = *p_ip_idx;
25723 +       struct nx_info *nxi = skb->sk ? skb->sk->sk_nx_info : NULL;
25724 +
25725 +       /* disable ipv6 on non v6 guests */
25726 +       if (nxi && !nx_info_has_v6(nxi))
25727 +               return skb->len;
25728  
25729         read_lock_bh(&idev->lock);
25730         switch (type) {
25731 @@ -3577,6 +3589,8 @@ static int in6_dump_addrs(struct inet6_d
25732                 list_for_each_entry(ifa, &idev->addr_list, if_list) {
25733                         if (++ip_idx < s_ip_idx)
25734                                 continue;
25735 +                               if (!v6_addr_in_nx_info(nxi, &ifa->addr, -1))
25736 +                                       continue;
25737                         err = inet6_fill_ifaddr(skb, ifa,
25738                                                 NETLINK_CB(cb->skb).pid,
25739                                                 cb->nlh->nlmsg_seq,
25740 @@ -3593,6 +3607,8 @@ static int in6_dump_addrs(struct inet6_d
25741                      ifmca = ifmca->next, ip_idx++) {
25742                         if (ip_idx < s_ip_idx)
25743                                 continue;
25744 +                               if (!v6_addr_in_nx_info(nxi, &ifmca->mca_addr, -1))
25745 +                                       continue;
25746                         err = inet6_fill_ifmcaddr(skb, ifmca,
25747                                                   NETLINK_CB(cb->skb).pid,
25748                                                   cb->nlh->nlmsg_seq,
25749 @@ -3608,6 +3624,8 @@ static int in6_dump_addrs(struct inet6_d
25750                      ifaca = ifaca->aca_next, ip_idx++) {
25751                         if (ip_idx < s_ip_idx)
25752                                 continue;
25753 +                               if (!v6_addr_in_nx_info(nxi, &ifaca->aca_addr, -1))
25754 +                                       continue;
25755                         err = inet6_fill_ifacaddr(skb, ifaca,
25756                                                   NETLINK_CB(cb->skb).pid,
25757                                                   cb->nlh->nlmsg_seq,
25758 @@ -3993,6 +4011,11 @@ static int inet6_dump_ifinfo(struct sk_b
25759         struct inet6_dev *idev;
25760         struct hlist_head *head;
25761         struct hlist_node *node;
25762 +       struct nx_info *nxi = skb->sk ? skb->sk->sk_nx_info : NULL;
25763 +
25764 +       /* FIXME: maybe disable ipv6 on non v6 guests?
25765 +       if (skb->sk && skb->sk->sk_vx_info)
25766 +               return skb->len; */
25767  
25768         s_h = cb->args[0];
25769         s_idx = cb->args[1];
25770 @@ -4004,6 +4027,8 @@ static int inet6_dump_ifinfo(struct sk_b
25771                 hlist_for_each_entry_rcu(dev, node, head, index_hlist) {
25772                         if (idx < s_idx)
25773                                 goto cont;
25774 +                       if (!v6_dev_in_nx_info(dev, nxi))
25775 +                               goto cont;
25776                         idev = __in6_dev_get(dev);
25777                         if (!idev)
25778                                 goto cont;
25779 diff -NurpP --minimal linux-2.6.38.1/net/ipv6/af_inet6.c linux-2.6.38.1-vs2.3.0.37-rc9/net/ipv6/af_inet6.c
25780 --- linux-2.6.38.1/net/ipv6/af_inet6.c  2011-03-15 18:07:45.000000000 +0100
25781 +++ linux-2.6.38.1-vs2.3.0.37-rc9/net/ipv6/af_inet6.c   2011-01-29 02:01:07.000000000 +0100
25782 @@ -42,6 +42,8 @@
25783  #include <linux/netdevice.h>
25784  #include <linux/icmpv6.h>
25785  #include <linux/netfilter_ipv6.h>
25786 +#include <linux/vs_inet.h>
25787 +#include <linux/vs_inet6.h>
25788  
25789  #include <net/ip.h>
25790  #include <net/ipv6.h>
25791 @@ -160,9 +162,12 @@ lookup_protocol:
25792         }
25793  
25794         err = -EPERM;
25795 +       if ((protocol == IPPROTO_ICMPV6) &&
25796 +               nx_capable(CAP_NET_RAW, NXC_RAW_ICMP))
25797 +               goto override;
25798         if (sock->type == SOCK_RAW && !kern && !capable(CAP_NET_RAW))
25799                 goto out_rcu_unlock;
25800 -
25801 +override:
25802         sock->ops = answer->ops;
25803         answer_prot = answer->prot;
25804         answer_no_check = answer->no_check;
25805 @@ -261,6 +266,7 @@ int inet6_bind(struct socket *sock, stru
25806         struct inet_sock *inet = inet_sk(sk);
25807         struct ipv6_pinfo *np = inet6_sk(sk);
25808         struct net *net = sock_net(sk);
25809 +       struct nx_v6_sock_addr nsa;
25810         __be32 v4addr = 0;
25811         unsigned short snum;
25812         int addr_type = 0;
25813 @@ -272,6 +278,11 @@ int inet6_bind(struct socket *sock, stru
25814  
25815         if (addr_len < SIN6_LEN_RFC2133)
25816                 return -EINVAL;
25817 +
25818 +       err = v6_map_sock_addr(inet, addr, &nsa);
25819 +       if (err)
25820 +               return err;
25821 +
25822         addr_type = ipv6_addr_type(&addr->sin6_addr);
25823         if ((addr_type & IPV6_ADDR_MULTICAST) && sock->type == SOCK_STREAM)
25824                 return -EINVAL;
25825 @@ -303,6 +314,7 @@ int inet6_bind(struct socket *sock, stru
25826                 /* Reproduce AF_INET checks to make the bindings consistent */
25827                 v4addr = addr->sin6_addr.s6_addr32[3];
25828                 chk_addr_ret = inet_addr_type(net, v4addr);
25829 +
25830                 if (!sysctl_ip_nonlocal_bind &&
25831                     !(inet->freebind || inet->transparent) &&
25832                     v4addr != htonl(INADDR_ANY) &&
25833 @@ -312,6 +324,10 @@ int inet6_bind(struct socket *sock, stru
25834                         err = -EADDRNOTAVAIL;
25835                         goto out;
25836                 }
25837 +               if (!v4_addr_in_nx_info(sk->sk_nx_info, v4addr, NXA_MASK_BIND)) {
25838 +                       err = -EADDRNOTAVAIL;
25839 +                       goto out;
25840 +               }
25841         } else {
25842                 if (addr_type != IPV6_ADDR_ANY) {
25843                         struct net_device *dev = NULL;
25844 @@ -338,6 +354,11 @@ int inet6_bind(struct socket *sock, stru
25845                                 }
25846                         }
25847  
25848 +                       if (!v6_addr_in_nx_info(sk->sk_nx_info, &addr->sin6_addr, -1)) {
25849 +                               err = -EADDRNOTAVAIL;
25850 +                               goto out;
25851 +                       }
25852 +
25853                         /* ipv4 addr of the socket is invalid.  Only the
25854                          * unspecified and mapped address have a v4 equivalent.
25855                          */
25856 @@ -354,6 +375,9 @@ int inet6_bind(struct socket *sock, stru
25857                 }
25858         }
25859  
25860 +       /* what's that for? */
25861 +       v6_set_sock_addr(inet, &nsa);
25862 +
25863         inet->inet_rcv_saddr = v4addr;
25864         inet->inet_saddr = v4addr;
25865  
25866 @@ -455,9 +479,11 @@ int inet6_getname(struct socket *sock, s
25867                         return -ENOTCONN;
25868                 sin->sin6_port = inet->inet_dport;
25869                 ipv6_addr_copy(&sin->sin6_addr, &np->daddr);
25870 +               /* FIXME: remap lback? */
25871                 if (np->sndflow)
25872                         sin->sin6_flowinfo = np->flow_label;
25873         } else {
25874 +               /* FIXME: remap lback? */
25875                 if (ipv6_addr_any(&np->rcv_saddr))
25876                         ipv6_addr_copy(&sin->sin6_addr, &np->saddr);
25877                 else
25878 diff -NurpP --minimal linux-2.6.38.1/net/ipv6/fib6_rules.c linux-2.6.38.1-vs2.3.0.37-rc9/net/ipv6/fib6_rules.c
25879 --- linux-2.6.38.1/net/ipv6/fib6_rules.c        2011-01-05 21:50:42.000000000 +0100
25880 +++ linux-2.6.38.1-vs2.3.0.37-rc9/net/ipv6/fib6_rules.c 2011-01-29 02:01:07.000000000 +0100
25881 @@ -88,7 +88,7 @@ static int fib6_rule_action(struct fib_r
25882                                                ip6_dst_idev(&rt->dst)->dev,
25883                                                &flp->fl6_dst,
25884                                                rt6_flags2srcprefs(flags),
25885 -                                              &saddr))
25886 +                                              &saddr, NULL))
25887                                 goto again;
25888                         if (!ipv6_prefix_equal(&saddr, &r->src.addr,
25889                                                r->src.plen))
25890 diff -NurpP --minimal linux-2.6.38.1/net/ipv6/inet6_hashtables.c linux-2.6.38.1-vs2.3.0.37-rc9/net/ipv6/inet6_hashtables.c
25891 --- linux-2.6.38.1/net/ipv6/inet6_hashtables.c  2010-02-25 11:52:10.000000000 +0100
25892 +++ linux-2.6.38.1-vs2.3.0.37-rc9/net/ipv6/inet6_hashtables.c   2011-01-29 02:01:07.000000000 +0100
25893 @@ -16,6 +16,7 @@
25894  
25895  #include <linux/module.h>
25896  #include <linux/random.h>
25897 +#include <linux/vs_inet6.h>
25898  
25899  #include <net/inet_connection_sock.h>
25900  #include <net/inet_hashtables.h>
25901 @@ -82,7 +83,6 @@ struct sock *__inet6_lookup_established(
25902         unsigned int slot = hash & hashinfo->ehash_mask;
25903         struct inet_ehash_bucket *head = &hashinfo->ehash[slot];
25904  
25905 -
25906         rcu_read_lock();
25907  begin:
25908         sk_nulls_for_each_rcu(sk, node, &head->chain) {
25909 @@ -94,7 +94,7 @@ begin:
25910                                 sock_put(sk);
25911                                 goto begin;
25912                         }
25913 -               goto out;
25914 +                       goto out;
25915                 }
25916         }
25917         if (get_nulls_value(node) != slot)
25918 @@ -140,6 +140,9 @@ static int inline compute_score(struct s
25919                         if (!ipv6_addr_equal(&np->rcv_saddr, daddr))
25920                                 return -1;
25921                         score++;
25922 +               } else {
25923 +                       if (!v6_addr_in_nx_info(sk->sk_nx_info, daddr, -1))
25924 +                               return -1;
25925                 }
25926                 if (sk->sk_bound_dev_if) {
25927                         if (sk->sk_bound_dev_if != dif)
25928 diff -NurpP --minimal linux-2.6.38.1/net/ipv6/ip6_output.c linux-2.6.38.1-vs2.3.0.37-rc9/net/ipv6/ip6_output.c
25929 --- linux-2.6.38.1/net/ipv6/ip6_output.c        2011-03-15 18:07:45.000000000 +0100
25930 +++ linux-2.6.38.1-vs2.3.0.37-rc9/net/ipv6/ip6_output.c 2011-01-29 02:01:07.000000000 +0100
25931 @@ -933,7 +933,7 @@ static int ip6_dst_lookup_tail(struct so
25932                 err = ipv6_dev_get_saddr(net, ip6_dst_idev(*dst)->dev,
25933                                          &fl->fl6_dst,
25934                                          sk ? inet6_sk(sk)->srcprefs : 0,
25935 -                                        &fl->fl6_src);
25936 +                                        &fl->fl6_src, sk->sk_nx_info);
25937                 if (err)
25938                         goto out_err_release;
25939         }
25940 diff -NurpP --minimal linux-2.6.38.1/net/ipv6/ndisc.c linux-2.6.38.1-vs2.3.0.37-rc9/net/ipv6/ndisc.c
25941 --- linux-2.6.38.1/net/ipv6/ndisc.c     2011-03-15 18:07:45.000000000 +0100
25942 +++ linux-2.6.38.1-vs2.3.0.37-rc9/net/ipv6/ndisc.c      2011-03-10 16:52:54.000000000 +0100
25943 @@ -595,7 +595,7 @@ static void ndisc_send_na(struct net_dev
25944         } else {
25945                 if (ipv6_dev_get_saddr(dev_net(dev), dev, daddr,
25946                                        inet6_sk(dev_net(dev)->ipv6.ndisc_sk)->srcprefs,
25947 -                                      &tmpaddr))
25948 +                                      &tmpaddr, NULL))
25949                         return;
25950                 src_addr = &tmpaddr;
25951         }
25952 diff -NurpP --minimal linux-2.6.38.1/net/ipv6/raw.c linux-2.6.38.1-vs2.3.0.37-rc9/net/ipv6/raw.c
25953 --- linux-2.6.38.1/net/ipv6/raw.c       2011-03-15 18:07:45.000000000 +0100
25954 +++ linux-2.6.38.1-vs2.3.0.37-rc9/net/ipv6/raw.c        2011-02-17 02:17:52.000000000 +0100
25955 @@ -30,6 +30,7 @@
25956  #include <linux/icmpv6.h>
25957  #include <linux/netfilter.h>
25958  #include <linux/netfilter_ipv6.h>
25959 +#include <linux/vs_inet6.h>
25960  #include <linux/skbuff.h>
25961  #include <linux/compat.h>
25962  #include <asm/uaccess.h>
25963 @@ -284,6 +285,13 @@ static int rawv6_bind(struct sock *sk, s
25964                                 goto out_unlock;
25965                 }
25966  
25967 +               if (!v6_addr_in_nx_info(sk->sk_nx_info, &addr->sin6_addr, -1)) {
25968 +                       err = -EADDRNOTAVAIL;
25969 +                       if (dev)
25970 +                               dev_put(dev);
25971 +                       goto out;
25972 +               }
25973 +
25974                 /* ipv4 addr of the socket is invalid.  Only the
25975                  * unspecified and mapped address have a v4 equivalent.
25976                  */
25977 diff -NurpP --minimal linux-2.6.38.1/net/ipv6/route.c linux-2.6.38.1-vs2.3.0.37-rc9/net/ipv6/route.c
25978 --- linux-2.6.38.1/net/ipv6/route.c     2011-03-15 18:07:45.000000000 +0100
25979 +++ linux-2.6.38.1-vs2.3.0.37-rc9/net/ipv6/route.c      2011-03-15 18:15:06.000000000 +0100
25980 @@ -2291,7 +2291,8 @@ static int rt6_fill_node(struct net *net
25981                 struct inet6_dev *idev = ip6_dst_idev(&rt->dst);
25982                 struct in6_addr saddr_buf;
25983                 if (ipv6_dev_get_saddr(net, idev ? idev->dev : NULL,
25984 -                                      dst, 0, &saddr_buf) == 0)
25985 +                       dst, 0, &saddr_buf,
25986 +                       (skb->sk ? skb->sk->sk_nx_info : NULL)) == 0)
25987                         NLA_PUT(skb, RTA_PREFSRC, 16, &saddr_buf);
25988         }
25989  
25990 diff -NurpP --minimal linux-2.6.38.1/net/ipv6/tcp_ipv6.c linux-2.6.38.1-vs2.3.0.37-rc9/net/ipv6/tcp_ipv6.c
25991 --- linux-2.6.38.1/net/ipv6/tcp_ipv6.c  2011-03-15 18:07:45.000000000 +0100
25992 +++ linux-2.6.38.1-vs2.3.0.37-rc9/net/ipv6/tcp_ipv6.c   2011-01-29 02:01:07.000000000 +0100
25993 @@ -69,6 +69,7 @@
25994  
25995  #include <linux/crypto.h>
25996  #include <linux/scatterlist.h>
25997 +#include <linux/vs_inet6.h>
25998  
25999  static void    tcp_v6_send_reset(struct sock *sk, struct sk_buff *skb);
26000  static void    tcp_v6_reqsk_send_ack(struct sock *sk, struct sk_buff *skb,
26001 @@ -161,8 +162,15 @@ static int tcp_v6_connect(struct sock *s
26002          *      connect() to INADDR_ANY means loopback (BSD'ism).
26003          */
26004  
26005 -       if(ipv6_addr_any(&usin->sin6_addr))
26006 -               usin->sin6_addr.s6_addr[15] = 0x1;
26007 +       if(ipv6_addr_any(&usin->sin6_addr)) {
26008 +               struct nx_info *nxi =  sk->sk_nx_info;
26009 +
26010 +               if (nxi && nx_info_has_v6(nxi))
26011 +                       /* FIXME: remap lback? */
26012 +                       usin->sin6_addr = nxi->v6.ip;
26013 +               else
26014 +                       usin->sin6_addr.s6_addr[15] = 0x1;
26015 +       }
26016  
26017         addr_type = ipv6_addr_type(&usin->sin6_addr);
26018  
26019 diff -NurpP --minimal linux-2.6.38.1/net/ipv6/udp.c linux-2.6.38.1-vs2.3.0.37-rc9/net/ipv6/udp.c
26020 --- linux-2.6.38.1/net/ipv6/udp.c       2011-03-15 18:07:45.000000000 +0100
26021 +++ linux-2.6.38.1-vs2.3.0.37-rc9/net/ipv6/udp.c        2011-01-29 05:23:17.000000000 +0100
26022 @@ -45,41 +45,67 @@
26023  #include <net/tcp_states.h>
26024  #include <net/ip6_checksum.h>
26025  #include <net/xfrm.h>
26026 +#include <linux/vs_inet6.h>
26027  
26028  #include <linux/proc_fs.h>
26029  #include <linux/seq_file.h>
26030  #include "udp_impl.h"
26031  
26032 -int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
26033 +int ipv6_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2)
26034  {
26035 -       const struct in6_addr *sk_rcv_saddr6 = &inet6_sk(sk)->rcv_saddr;
26036 +       const struct in6_addr *sk1_rcv_saddr6 = &inet6_sk(sk1)->rcv_saddr;
26037         const struct in6_addr *sk2_rcv_saddr6 = inet6_rcv_saddr(sk2);
26038 -       __be32 sk1_rcv_saddr = sk_rcv_saddr(sk);
26039 +       __be32 sk1_rcv_saddr = sk_rcv_saddr(sk1);
26040         __be32 sk2_rcv_saddr = sk_rcv_saddr(sk2);
26041 -       int sk_ipv6only = ipv6_only_sock(sk);
26042 +       int sk1_ipv6only = ipv6_only_sock(sk1);
26043         int sk2_ipv6only = inet_v6_ipv6only(sk2);
26044 -       int addr_type = ipv6_addr_type(sk_rcv_saddr6);
26045 +       int addr_type = ipv6_addr_type(sk1_rcv_saddr6);
26046         int addr_type2 = sk2_rcv_saddr6 ? ipv6_addr_type(sk2_rcv_saddr6) : IPV6_ADDR_MAPPED;
26047  
26048         /* if both are mapped, treat as IPv4 */
26049 -       if (addr_type == IPV6_ADDR_MAPPED && addr_type2 == IPV6_ADDR_MAPPED)
26050 -               return (!sk2_ipv6only &&
26051 +       if (addr_type == IPV6_ADDR_MAPPED && addr_type2 == IPV6_ADDR_MAPPED) {
26052 +               if (!sk2_ipv6only &&
26053                         (!sk1_rcv_saddr || !sk2_rcv_saddr ||
26054 -                         sk1_rcv_saddr == sk2_rcv_saddr));
26055 +                         sk1_rcv_saddr == sk2_rcv_saddr))
26056 +                       goto vs_v4;
26057 +               else
26058 +                       return 0;
26059 +       }
26060  
26061         if (addr_type2 == IPV6_ADDR_ANY &&
26062             !(sk2_ipv6only && addr_type == IPV6_ADDR_MAPPED))
26063 -               return 1;
26064 +               goto vs;
26065  
26066         if (addr_type == IPV6_ADDR_ANY &&
26067 -           !(sk_ipv6only && addr_type2 == IPV6_ADDR_MAPPED))
26068 -               return 1;
26069 +           !(sk1_ipv6only && addr_type2 == IPV6_ADDR_MAPPED))
26070 +               goto vs;
26071  
26072         if (sk2_rcv_saddr6 &&
26073 -           ipv6_addr_equal(sk_rcv_saddr6, sk2_rcv_saddr6))
26074 -               return 1;
26075 +           ipv6_addr_equal(sk1_rcv_saddr6, sk2_rcv_saddr6))
26076 +               goto vs;
26077  
26078         return 0;
26079 +
26080 +vs_v4:
26081 +       if (!sk1_rcv_saddr && !sk2_rcv_saddr)
26082 +               return nx_v4_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info);
26083 +       if (!sk2_rcv_saddr)
26084 +               return v4_addr_in_nx_info(sk1->sk_nx_info, sk2_rcv_saddr, -1);
26085 +       if (!sk1_rcv_saddr)
26086 +               return v4_addr_in_nx_info(sk2->sk_nx_info, sk1_rcv_saddr, -1);
26087 +       return 1;
26088 +vs:
26089 +       if (addr_type2 == IPV6_ADDR_ANY && addr_type == IPV6_ADDR_ANY)
26090 +               return nx_v6_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info);
26091 +       else if (addr_type2 == IPV6_ADDR_ANY)
26092 +               return v6_addr_in_nx_info(sk2->sk_nx_info, sk1_rcv_saddr6, -1);
26093 +       else if (addr_type == IPV6_ADDR_ANY) {
26094 +               if (addr_type2 == IPV6_ADDR_MAPPED)
26095 +                       return nx_v4_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info);
26096 +               else
26097 +                       return v6_addr_in_nx_info(sk1->sk_nx_info, sk2_rcv_saddr6, -1);
26098 +       }
26099 +       return 1;
26100  }
26101  
26102  static unsigned int udp6_portaddr_hash(struct net *net,
26103 @@ -143,6 +169,10 @@ static inline int compute_score(struct s
26104                         if (!ipv6_addr_equal(&np->rcv_saddr, daddr))
26105                                 return -1;
26106                         score++;
26107 +               } else {
26108 +                       /* block non nx_info ips */
26109 +                       if (!v6_addr_in_nx_info(sk->sk_nx_info, daddr, -1))
26110 +                               return -1;
26111                 }
26112                 if (!ipv6_addr_any(&np->daddr)) {
26113                         if (!ipv6_addr_equal(&np->daddr, saddr))
26114 diff -NurpP --minimal linux-2.6.38.1/net/ipv6/xfrm6_policy.c linux-2.6.38.1-vs2.3.0.37-rc9/net/ipv6/xfrm6_policy.c
26115 --- linux-2.6.38.1/net/ipv6/xfrm6_policy.c      2011-03-15 18:07:45.000000000 +0100
26116 +++ linux-2.6.38.1-vs2.3.0.37-rc9/net/ipv6/xfrm6_policy.c       2011-02-02 22:20:27.000000000 +0100
26117 @@ -62,7 +62,7 @@ static int xfrm6_get_saddr(struct net *n
26118         dev = ip6_dst_idev(dst)->dev;
26119         ipv6_dev_get_saddr(dev_net(dev), dev,
26120                            (struct in6_addr *)&daddr->a6, 0,
26121 -                          (struct in6_addr *)&saddr->a6);
26122 +                          (struct in6_addr *)&saddr->a6, NULL);
26123         dst_release(dst);
26124         return 0;
26125  }
26126 diff -NurpP --minimal linux-2.6.38.1/net/netfilter/ipvs/ip_vs_xmit.c linux-2.6.38.1-vs2.3.0.37-rc9/net/netfilter/ipvs/ip_vs_xmit.c
26127 --- linux-2.6.38.1/net/netfilter/ipvs/ip_vs_xmit.c      2011-03-15 18:07:46.000000000 +0100
26128 +++ linux-2.6.38.1-vs2.3.0.37-rc9/net/netfilter/ipvs/ip_vs_xmit.c       2011-01-29 02:01:07.000000000 +0100
26129 @@ -213,7 +213,7 @@ __ip_vs_route_output_v6(struct net *net,
26130                 return dst;
26131         if (ipv6_addr_any(&fl.fl6_src) &&
26132             ipv6_dev_get_saddr(net, ip6_dst_idev(dst)->dev,
26133 -                              &fl.fl6_dst, 0, &fl.fl6_src) < 0)
26134 +                              &fl.fl6_dst, 0, &fl.fl6_src, NULL) < 0)
26135                 goto out_err;
26136         if (do_xfrm && xfrm_lookup(net, &dst, &fl, NULL, 0) < 0)
26137                 goto out_err;
26138 diff -NurpP --minimal linux-2.6.38.1/net/netlink/af_netlink.c linux-2.6.38.1-vs2.3.0.37-rc9/net/netlink/af_netlink.c
26139 --- linux-2.6.38.1/net/netlink/af_netlink.c     2011-03-15 18:07:46.000000000 +0100
26140 +++ linux-2.6.38.1-vs2.3.0.37-rc9/net/netlink/af_netlink.c      2011-03-10 17:21:19.000000000 +0100
26141 @@ -55,6 +55,9 @@
26142  #include <linux/types.h>
26143  #include <linux/audit.h>
26144  #include <linux/mutex.h>
26145 +#include <linux/vs_context.h>
26146 +#include <linux/vs_network.h>
26147 +#include <linux/vs_limit.h>
26148  
26149  #include <net/net_namespace.h>
26150  #include <net/sock.h>
26151 @@ -1922,6 +1925,8 @@ static struct sock *netlink_seq_socket_i
26152                         sk_for_each(s, node, &hash->table[j]) {
26153                                 if (sock_net(s) != seq_file_net(seq))
26154                                         continue;
26155 +                               if (!nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT))
26156 +                                       continue;
26157                                 if (off == pos) {
26158                                         iter->link = i;
26159                                         iter->hash_idx = j;
26160 @@ -1956,7 +1961,8 @@ static void *netlink_seq_next(struct seq
26161         s = v;
26162         do {
26163                 s = sk_next(s);
26164 -       } while (s && sock_net(s) != seq_file_net(seq));
26165 +       } while (s && (sock_net(s) != seq_file_net(seq) ||
26166 +               !nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT)));
26167         if (s)
26168                 return s;
26169  
26170 @@ -1968,7 +1974,8 @@ static void *netlink_seq_next(struct seq
26171  
26172                 for (; j <= hash->mask; j++) {
26173                         s = sk_head(&hash->table[j]);
26174 -                       while (s && sock_net(s) != seq_file_net(seq))
26175 +                       while (s && (sock_net(s) != seq_file_net(seq) ||
26176 +                               !nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT)))
26177                                 s = sk_next(s);
26178                         if (s) {
26179                                 iter->link = i;
26180 diff -NurpP --minimal linux-2.6.38.1/net/sctp/ipv6.c linux-2.6.38.1-vs2.3.0.37-rc9/net/sctp/ipv6.c
26181 --- linux-2.6.38.1/net/sctp/ipv6.c      2011-01-05 21:50:45.000000000 +0100
26182 +++ linux-2.6.38.1-vs2.3.0.37-rc9/net/sctp/ipv6.c       2011-01-29 02:01:07.000000000 +0100
26183 @@ -306,7 +306,8 @@ static void sctp_v6_get_saddr(struct sct
26184                                    dst ? ip6_dst_idev(dst)->dev : NULL,
26185                                    &daddr->v6.sin6_addr,
26186                                    inet6_sk(&sk->inet.sk)->srcprefs,
26187 -                                  &saddr->v6.sin6_addr);
26188 +                                  &saddr->v6.sin6_addr,
26189 +                                  asoc->base.sk->sk_nx_info);
26190                 SCTP_DEBUG_PRINTK("saddr from ipv6_get_saddr: %pI6\n",
26191                                   &saddr->v6.sin6_addr);
26192                 return;
26193 diff -NurpP --minimal linux-2.6.38.1/net/socket.c linux-2.6.38.1-vs2.3.0.37-rc9/net/socket.c
26194 --- linux-2.6.38.1/net/socket.c 2011-03-15 18:07:46.000000000 +0100
26195 +++ linux-2.6.38.1-vs2.3.0.37-rc9/net/socket.c  2011-01-29 02:01:07.000000000 +0100
26196 @@ -98,6 +98,10 @@
26197  
26198  #include <net/sock.h>
26199  #include <linux/netfilter.h>
26200 +#include <linux/vs_base.h>
26201 +#include <linux/vs_socket.h>
26202 +#include <linux/vs_inet.h>
26203 +#include <linux/vs_inet6.h>
26204  
26205  #include <linux/if_tun.h>
26206  #include <linux/ipv6_route.h>
26207 @@ -551,7 +555,7 @@ static inline int __sock_sendmsg(struct 
26208                                  struct msghdr *msg, size_t size)
26209  {
26210         struct sock_iocb *si = kiocb_to_siocb(iocb);
26211 -       int err;
26212 +       int err, len;
26213  
26214         sock_update_classid(sock->sk);
26215  
26216 @@ -564,7 +568,22 @@ static inline int __sock_sendmsg(struct 
26217         if (err)
26218                 return err;
26219  
26220 -       return sock->ops->sendmsg(iocb, sock, msg, size);
26221 +       len = sock->ops->sendmsg(iocb, sock, msg, size);
26222 +       if (sock->sk) {
26223 +               if (len == size)
26224 +                       vx_sock_send(sock->sk, size);
26225 +               else
26226 +                       vx_sock_fail(sock->sk, size);
26227 +       }
26228 +       vxdprintk(VXD_CBIT(net, 7),
26229 +               "__sock_sendmsg: %p[%p,%p,%p;%d/%d]:%d/%d",
26230 +               sock, sock->sk,
26231 +               (sock->sk)?sock->sk->sk_nx_info:0,
26232 +               (sock->sk)?sock->sk->sk_vx_info:0,
26233 +               (sock->sk)?sock->sk->sk_xid:0,
26234 +               (sock->sk)?sock->sk->sk_nid:0,
26235 +               (unsigned int)size, len);
26236 +       return len;
26237  }
26238  
26239  int sock_sendmsg(struct socket *sock, struct msghdr *msg, size_t size)
26240 @@ -682,6 +701,7 @@ static inline int __sock_recvmsg_nosec(s
26241                                        struct msghdr *msg, size_t size, int flags)
26242  {
26243         struct sock_iocb *si = kiocb_to_siocb(iocb);
26244 +       int len;
26245  
26246         sock_update_classid(sock->sk);
26247  
26248 @@ -691,7 +711,18 @@ static inline int __sock_recvmsg_nosec(s
26249         si->size = size;
26250         si->flags = flags;
26251  
26252 -       return sock->ops->recvmsg(iocb, sock, msg, size, flags);
26253 +       len = sock->ops->recvmsg(iocb, sock, msg, size, flags);
26254 +       if ((len >= 0) && sock->sk)
26255 +               vx_sock_recv(sock->sk, len);
26256 +       vxdprintk(VXD_CBIT(net, 7),
26257 +               "__sock_recvmsg: %p[%p,%p,%p;%d/%d]:%d/%d",
26258 +               sock, sock->sk,
26259 +               (sock->sk)?sock->sk->sk_nx_info:0,
26260 +               (sock->sk)?sock->sk->sk_vx_info:0,
26261 +               (sock->sk)?sock->sk->sk_xid:0,
26262 +               (sock->sk)?sock->sk->sk_nid:0,
26263 +               (unsigned int)size, len);
26264 +       return len;
26265  }
26266  
26267  static inline int __sock_recvmsg(struct kiocb *iocb, struct socket *sock,
26268 @@ -1175,6 +1206,13 @@ int __sock_create(struct net *net, int f
26269         if (type < 0 || type >= SOCK_MAX)
26270                 return -EINVAL;
26271  
26272 +       if (!nx_check(0, VS_ADMIN)) {
26273 +               if (family == PF_INET && !current_nx_info_has_v4())
26274 +                       return -EAFNOSUPPORT;
26275 +               if (family == PF_INET6 && !current_nx_info_has_v6())
26276 +                       return -EAFNOSUPPORT;
26277 +       }
26278 +
26279         /* Compatibility.
26280  
26281            This uglymoron is moved from INET layer to here to avoid
26282 @@ -1310,6 +1348,7 @@ SYSCALL_DEFINE3(socket, int, family, int
26283         if (retval < 0)
26284                 goto out;
26285  
26286 +       set_bit(SOCK_USER_SOCKET, &sock->flags);
26287         retval = sock_map_fd(sock, flags & (O_CLOEXEC | O_NONBLOCK));
26288         if (retval < 0)
26289                 goto out_release;
26290 @@ -1351,10 +1390,12 @@ SYSCALL_DEFINE4(socketpair, int, family,
26291         err = sock_create(family, type, protocol, &sock1);
26292         if (err < 0)
26293                 goto out;
26294 +       set_bit(SOCK_USER_SOCKET, &sock1->flags);
26295  
26296         err = sock_create(family, type, protocol, &sock2);
26297         if (err < 0)
26298                 goto out_release_1;
26299 +       set_bit(SOCK_USER_SOCKET, &sock2->flags);
26300  
26301         err = sock1->ops->socketpair(sock1, sock2);
26302         if (err < 0)
26303 diff -NurpP --minimal linux-2.6.38.1/net/sunrpc/auth.c linux-2.6.38.1-vs2.3.0.37-rc9/net/sunrpc/auth.c
26304 --- linux-2.6.38.1/net/sunrpc/auth.c    2011-03-15 18:07:46.000000000 +0100
26305 +++ linux-2.6.38.1-vs2.3.0.37-rc9/net/sunrpc/auth.c     2011-01-29 02:01:07.000000000 +0100
26306 @@ -14,6 +14,7 @@
26307  #include <linux/hash.h>
26308  #include <linux/sunrpc/clnt.h>
26309  #include <linux/spinlock.h>
26310 +#include <linux/vs_tag.h>
26311  
26312  #ifdef RPC_DEBUG
26313  # define RPCDBG_FACILITY       RPCDBG_AUTH
26314 @@ -425,6 +426,7 @@ rpcauth_lookupcred(struct rpc_auth *auth
26315         memset(&acred, 0, sizeof(acred));
26316         acred.uid = cred->fsuid;
26317         acred.gid = cred->fsgid;
26318 +       acred.tag = dx_current_tag();
26319         acred.group_info = get_group_info(((struct cred *)cred)->group_info);
26320  
26321         ret = auth->au_ops->lookup_cred(auth, &acred, flags);
26322 @@ -465,6 +467,7 @@ rpcauth_bind_root_cred(struct rpc_task *
26323         struct auth_cred acred = {
26324                 .uid = 0,
26325                 .gid = 0,
26326 +               .tag = dx_current_tag(),
26327         };
26328  
26329         dprintk("RPC: %5u looking up %s cred\n",
26330 diff -NurpP --minimal linux-2.6.38.1/net/sunrpc/auth_unix.c linux-2.6.38.1-vs2.3.0.37-rc9/net/sunrpc/auth_unix.c
26331 --- linux-2.6.38.1/net/sunrpc/auth_unix.c       2010-10-21 13:08:01.000000000 +0200
26332 +++ linux-2.6.38.1-vs2.3.0.37-rc9/net/sunrpc/auth_unix.c        2011-01-29 02:01:07.000000000 +0100
26333 @@ -12,12 +12,14 @@
26334  #include <linux/module.h>
26335  #include <linux/sunrpc/clnt.h>
26336  #include <linux/sunrpc/auth.h>
26337 +#include <linux/vs_tag.h>
26338  
26339  #define NFS_NGROUPS    16
26340  
26341  struct unx_cred {
26342         struct rpc_cred         uc_base;
26343         gid_t                   uc_gid;
26344 +       tag_t                   uc_tag;
26345         gid_t                   uc_gids[NFS_NGROUPS];
26346  };
26347  #define uc_uid                 uc_base.cr_uid
26348 @@ -78,6 +80,7 @@ unx_create_cred(struct rpc_auth *auth, s
26349                 groups = NFS_NGROUPS;
26350  
26351         cred->uc_gid = acred->gid;
26352 +       cred->uc_tag = acred->tag;
26353         for (i = 0; i < groups; i++)
26354                 cred->uc_gids[i] = GROUP_AT(acred->group_info, i);
26355         if (i < NFS_NGROUPS)
26356 @@ -119,7 +122,9 @@ unx_match(struct auth_cred *acred, struc
26357         unsigned int i;
26358  
26359  
26360 -       if (cred->uc_uid != acred->uid || cred->uc_gid != acred->gid)
26361 +       if (cred->uc_uid != acred->uid ||
26362 +               cred->uc_gid != acred->gid ||
26363 +               cred->uc_tag != acred->tag)
26364                 return 0;
26365  
26366         if (acred->group_info != NULL)
26367 @@ -142,7 +147,7 @@ unx_marshal(struct rpc_task *task, __be3
26368         struct rpc_clnt *clnt = task->tk_client;
26369         struct unx_cred *cred = container_of(task->tk_rqstp->rq_cred, struct unx_cred, uc_base);
26370         __be32          *base, *hold;
26371 -       int             i;
26372 +       int             i, tag;
26373  
26374         *p++ = htonl(RPC_AUTH_UNIX);
26375         base = p++;
26376 @@ -152,9 +157,12 @@ unx_marshal(struct rpc_task *task, __be3
26377          * Copy the UTS nodename captured when the client was created.
26378          */
26379         p = xdr_encode_array(p, clnt->cl_nodename, clnt->cl_nodelen);
26380 +       tag = task->tk_client->cl_tag;
26381  
26382 -       *p++ = htonl((u32) cred->uc_uid);
26383 -       *p++ = htonl((u32) cred->uc_gid);
26384 +       *p++ = htonl((u32) TAGINO_UID(tag,
26385 +               cred->uc_uid, cred->uc_tag));
26386 +       *p++ = htonl((u32) TAGINO_GID(tag,
26387 +               cred->uc_gid, cred->uc_tag));
26388         hold = p++;
26389         for (i = 0; i < 16 && cred->uc_gids[i] != (gid_t) NOGROUP; i++)
26390                 *p++ = htonl((u32) cred->uc_gids[i]);
26391 diff -NurpP --minimal linux-2.6.38.1/net/sunrpc/clnt.c linux-2.6.38.1-vs2.3.0.37-rc9/net/sunrpc/clnt.c
26392 --- linux-2.6.38.1/net/sunrpc/clnt.c    2011-03-26 01:10:17.000000000 +0100
26393 +++ linux-2.6.38.1-vs2.3.0.37-rc9/net/sunrpc/clnt.c     2011-03-25 22:52:15.000000000 +0100
26394 @@ -33,6 +33,7 @@
26395  #include <linux/utsname.h>
26396  #include <linux/workqueue.h>
26397  #include <linux/in6.h>
26398 +#include <linux/vs_cvirt.h>
26399  
26400  #include <linux/sunrpc/clnt.h>
26401  #include <linux/sunrpc/rpc_pipe_fs.h>
26402 @@ -359,6 +360,9 @@ struct rpc_clnt *rpc_create(struct rpc_c
26403         if (!(args->flags & RPC_CLNT_CREATE_QUIET))
26404                 clnt->cl_chatty = 1;
26405  
26406 +       /* TODO: handle RPC_CLNT_CREATE_TAGGED
26407 +       if (args->flags & RPC_CLNT_CREATE_TAGGED)
26408 +               clnt->cl_tag = 1; */
26409         return clnt;
26410  }
26411  EXPORT_SYMBOL_GPL(rpc_create);
26412 diff -NurpP --minimal linux-2.6.38.1/net/unix/af_unix.c linux-2.6.38.1-vs2.3.0.37-rc9/net/unix/af_unix.c
26413 --- linux-2.6.38.1/net/unix/af_unix.c   2011-03-15 18:07:46.000000000 +0100
26414 +++ linux-2.6.38.1-vs2.3.0.37-rc9/net/unix/af_unix.c    2011-03-15 18:15:06.000000000 +0100
26415 @@ -114,6 +114,8 @@
26416  #include <linux/mount.h>
26417  #include <net/checksum.h>
26418  #include <linux/security.h>
26419 +#include <linux/vs_context.h>
26420 +#include <linux/vs_limit.h>
26421  
26422  static struct hlist_head unix_socket_table[UNIX_HASH_SIZE + 1];
26423  static DEFINE_SPINLOCK(unix_table_lock);
26424 @@ -258,6 +260,8 @@ static struct sock *__unix_find_socket_b
26425                 if (!net_eq(sock_net(s), net))
26426                         continue;
26427  
26428 +               if (!nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT))
26429 +                       continue;
26430                 if (u->addr->len == len &&
26431                     !memcmp(u->addr->name, sunname, len))
26432                         goto found;
26433 @@ -2188,6 +2192,8 @@ static struct sock *unix_seq_idx(struct 
26434         for (s = first_unix_socket(&iter->i); s; s = next_unix_socket(&iter->i, s)) {
26435                 if (sock_net(s) != seq_file_net(seq))
26436                         continue;
26437 +               if (!nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT))
26438 +                       continue;
26439                 if (off == pos)
26440                         return s;
26441                 ++off;
26442 @@ -2212,7 +2218,8 @@ static void *unix_seq_next(struct seq_fi
26443                 sk = first_unix_socket(&iter->i);
26444         else
26445                 sk = next_unix_socket(&iter->i, sk);
26446 -       while (sk && (sock_net(sk) != seq_file_net(seq)))
26447 +       while (sk && (sock_net(sk) != seq_file_net(seq) ||
26448 +               !nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT)))
26449                 sk = next_unix_socket(&iter->i, sk);
26450         return sk;
26451  }
26452 diff -NurpP --minimal linux-2.6.38.1/scripts/checksyscalls.sh linux-2.6.38.1-vs2.3.0.37-rc9/scripts/checksyscalls.sh
26453 --- linux-2.6.38.1/scripts/checksyscalls.sh     2011-03-15 18:07:46.000000000 +0100
26454 +++ linux-2.6.38.1-vs2.3.0.37-rc9/scripts/checksyscalls.sh      2011-01-29 02:01:07.000000000 +0100
26455 @@ -193,7 +193,6 @@ cat << EOF
26456  #define __IGNORE_afs_syscall
26457  #define __IGNORE_getpmsg
26458  #define __IGNORE_putpmsg
26459 -#define __IGNORE_vserver
26460  EOF
26461  }
26462  
26463 diff -NurpP --minimal linux-2.6.38.1/security/commoncap.c linux-2.6.38.1-vs2.3.0.37-rc9/security/commoncap.c
26464 --- linux-2.6.38.1/security/commoncap.c 2011-01-05 21:50:47.000000000 +0100
26465 +++ linux-2.6.38.1-vs2.3.0.37-rc9/security/commoncap.c  2011-01-29 02:01:07.000000000 +0100
26466 @@ -27,6 +27,7 @@
26467  #include <linux/sched.h>
26468  #include <linux/prctl.h>
26469  #include <linux/securebits.h>
26470 +// #include <linux/vs_context.h>
26471  
26472  /*
26473   * If a non-root user executes a setuid-root binary in
26474 @@ -52,7 +53,7 @@ static void warn_setuid_and_fcaps_mixed(
26475  
26476  int cap_netlink_send(struct sock *sk, struct sk_buff *skb)
26477  {
26478 -       NETLINK_CB(skb).eff_cap = current_cap();
26479 +       NETLINK_CB(skb).eff_cap = vx_mbcaps(current_cap());
26480         return 0;
26481  }
26482  
26483 @@ -62,6 +63,7 @@ int cap_netlink_recv(struct sk_buff *skb
26484                 return -EPERM;
26485         return 0;
26486  }
26487 +
26488  EXPORT_SYMBOL(cap_netlink_recv);
26489  
26490  /**
26491 @@ -82,7 +84,22 @@ EXPORT_SYMBOL(cap_netlink_recv);
26492  int cap_capable(struct task_struct *tsk, const struct cred *cred, int cap,
26493                 int audit)
26494  {
26495 -       return cap_raised(cred->cap_effective, cap) ? 0 : -EPERM;
26496 +       struct vx_info *vxi = tsk->vx_info;
26497 +
26498 +#if 0
26499 +       printk("cap_capable() VXF_STATE_SETUP = %llx, raised = %x, eff = %08x:%08x\n",
26500 +               vx_info_flags(vxi, VXF_STATE_SETUP, 0),
26501 +               cap_raised(tsk->cap_effective, cap),
26502 +               tsk->cap_effective.cap[1], tsk->cap_effective.cap[0]);
26503 +#endif
26504 +
26505 +       /* special case SETUP */
26506 +       if (vx_info_flags(vxi, VXF_STATE_SETUP, 0) &&
26507 +               /* FIXME: maybe use cred instead? */
26508 +               cap_raised(tsk->cred->cap_effective, cap))
26509 +               return 0;
26510 +
26511 +       return vx_cap_raised(vxi, cred->cap_effective, cap) ? 0 : -EPERM;
26512  }
26513  
26514  /**
26515 @@ -570,7 +587,7 @@ int cap_inode_setxattr(struct dentry *de
26516  
26517         if (!strncmp(name, XATTR_SECURITY_PREFIX,
26518                      sizeof(XATTR_SECURITY_PREFIX) - 1) &&
26519 -           !capable(CAP_SYS_ADMIN))
26520 +               !vx_capable(CAP_SYS_ADMIN, VXC_FS_SECURITY))
26521                 return -EPERM;
26522         return 0;
26523  }
26524 @@ -596,7 +613,7 @@ int cap_inode_removexattr(struct dentry 
26525  
26526         if (!strncmp(name, XATTR_SECURITY_PREFIX,
26527                      sizeof(XATTR_SECURITY_PREFIX) - 1) &&
26528 -           !capable(CAP_SYS_ADMIN))
26529 +               !vx_capable(CAP_SYS_ADMIN, VXC_FS_SECURITY))
26530                 return -EPERM;
26531         return 0;
26532  }
26533 @@ -929,3 +946,4 @@ int cap_file_mmap(struct file *file, uns
26534         }
26535         return ret;
26536  }
26537 +
26538 diff -NurpP --minimal linux-2.6.38.1/security/selinux/hooks.c linux-2.6.38.1-vs2.3.0.37-rc9/security/selinux/hooks.c
26539 --- linux-2.6.38.1/security/selinux/hooks.c     2011-03-15 18:07:47.000000000 +0100
26540 +++ linux-2.6.38.1-vs2.3.0.37-rc9/security/selinux/hooks.c      2011-02-17 02:17:52.000000000 +0100
26541 @@ -64,7 +64,6 @@
26542  #include <linux/dccp.h>
26543  #include <linux/quota.h>
26544  #include <linux/un.h>          /* for Unix socket types */
26545 -#include <net/af_unix.h>       /* for Unix socket types */
26546  #include <linux/parser.h>
26547  #include <linux/nfs_mount.h>
26548  #include <net/ipv6.h>
This page took 2.424263 seconds and 4 git commands to generate.