]> git.pld-linux.org Git - packages/kernel.git/blob - kernel-vserver-2.3.patch
- update vserver to patch-2.6.38-rc8-vs2.3.0.37-rc6.diff; drop TIOCGDEV.patch (merged...
[packages/kernel.git] / kernel-vserver-2.3.patch
1 diff -NurpP --minimal linux-2.6.38-rc8/Documentation/vserver/debug.txt linux-2.6.38-rc8-vs2.3.0.37-rc6/Documentation/vserver/debug.txt
2 --- linux-2.6.38-rc8/Documentation/vserver/debug.txt    1970-01-01 01:00:00.000000000 +0100
3 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/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-rc8/arch/alpha/Kconfig linux-2.6.38-rc8-vs2.3.0.37-rc6/arch/alpha/Kconfig
160 --- linux-2.6.38-rc8/arch/alpha/Kconfig 2011-03-10 17:08:30.000000000 +0100
161 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/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-rc8/arch/alpha/kernel/entry.S linux-2.6.38-rc8-vs2.3.0.37-rc6/arch/alpha/kernel/entry.S
172 --- linux-2.6.38-rc8/arch/alpha/kernel/entry.S  2010-10-21 13:06:45.000000000 +0200
173 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/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-rc8/arch/alpha/kernel/ptrace.c linux-2.6.38-rc8-vs2.3.0.37-rc6/arch/alpha/kernel/ptrace.c
207 --- linux-2.6.38-rc8/arch/alpha/kernel/ptrace.c 2011-01-05 21:48:40.000000000 +0100
208 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/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-rc8/arch/alpha/kernel/systbls.S linux-2.6.38-rc8-vs2.3.0.37-rc6/arch/alpha/kernel/systbls.S
218 --- linux-2.6.38-rc8/arch/alpha/kernel/systbls.S        2010-10-21 13:06:46.000000000 +0200
219 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/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-rc8/arch/alpha/kernel/traps.c linux-2.6.38-rc8-vs2.3.0.37-rc6/arch/alpha/kernel/traps.c
230 --- linux-2.6.38-rc8/arch/alpha/kernel/traps.c  2010-10-21 13:06:46.000000000 +0200
231 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/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-rc8/arch/arm/Kconfig linux-2.6.38-rc8-vs2.3.0.37-rc6/arch/arm/Kconfig
243 --- linux-2.6.38-rc8/arch/arm/Kconfig   2011-03-10 17:08:30.000000000 +0100
244 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/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-rc8/arch/arm/kernel/calls.S linux-2.6.38-rc8-vs2.3.0.37-rc6/arch/arm/kernel/calls.S
255 --- linux-2.6.38-rc8/arch/arm/kernel/calls.S    2010-10-21 13:06:46.000000000 +0200
256 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/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-rc8/arch/arm/kernel/process.c linux-2.6.38-rc8-vs2.3.0.37-rc6/arch/arm/kernel/process.c
267 --- linux-2.6.38-rc8/arch/arm/kernel/process.c  2011-03-10 17:08:31.000000000 +0100
268 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/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-rc8/arch/arm/kernel/traps.c linux-2.6.38-rc8-vs2.3.0.37-rc6/arch/arm/kernel/traps.c
280 --- linux-2.6.38-rc8/arch/arm/kernel/traps.c    2011-03-10 17:08:31.000000000 +0100
281 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/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-rc8/arch/cris/Kconfig linux-2.6.38-rc8-vs2.3.0.37-rc6/arch/cris/Kconfig
294 --- linux-2.6.38-rc8/arch/cris/Kconfig  2011-03-10 17:08:41.000000000 +0100
295 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/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-rc8/arch/frv/kernel/kernel_thread.S linux-2.6.38-rc8-vs2.3.0.37-rc6/arch/frv/kernel/kernel_thread.S
306 --- linux-2.6.38-rc8/arch/frv/kernel/kernel_thread.S    2008-12-25 00:26:37.000000000 +0100
307 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/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-rc8/arch/h8300/Kconfig linux-2.6.38-rc8-vs2.3.0.37-rc6/arch/h8300/Kconfig
318 --- linux-2.6.38-rc8/arch/h8300/Kconfig 2011-03-10 17:08:41.000000000 +0100
319 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/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-rc8/arch/ia64/Kconfig linux-2.6.38-rc8-vs2.3.0.37-rc6/arch/ia64/Kconfig
330 --- linux-2.6.38-rc8/arch/ia64/Kconfig  2011-03-10 17:08:41.000000000 +0100
331 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/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-rc8/arch/ia64/include/asm/tlb.h linux-2.6.38-rc8-vs2.3.0.37-rc6/arch/ia64/include/asm/tlb.h
342 --- linux-2.6.38-rc8/arch/ia64/include/asm/tlb.h        2010-02-25 11:51:26.000000000 +0100
343 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/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-rc8/arch/ia64/kernel/entry.S linux-2.6.38-rc8-vs2.3.0.37-rc6/arch/ia64/kernel/entry.S
353 --- linux-2.6.38-rc8/arch/ia64/kernel/entry.S   2010-10-21 13:06:52.000000000 +0200
354 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/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-rc8/arch/ia64/kernel/perfmon.c linux-2.6.38-rc8-vs2.3.0.37-rc6/arch/ia64/kernel/perfmon.c
365 --- linux-2.6.38-rc8/arch/ia64/kernel/perfmon.c 2011-03-10 17:08:41.000000000 +0100
366 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/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-rc8/arch/ia64/kernel/process.c linux-2.6.38-rc8-vs2.3.0.37-rc6/arch/ia64/kernel/process.c
376 --- linux-2.6.38-rc8/arch/ia64/kernel/process.c 2011-03-10 17:08:41.000000000 +0100
377 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/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-rc8/arch/ia64/kernel/ptrace.c linux-2.6.38-rc8-vs2.3.0.37-rc6/arch/ia64/kernel/ptrace.c
390 --- linux-2.6.38-rc8/arch/ia64/kernel/ptrace.c  2011-01-05 21:48:59.000000000 +0100
391 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/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-rc8/arch/ia64/kernel/traps.c linux-2.6.38-rc8-vs2.3.0.37-rc6/arch/ia64/kernel/traps.c
401 --- linux-2.6.38-rc8/arch/ia64/kernel/traps.c   2010-07-07 18:31:01.000000000 +0200
402 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/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-rc8/arch/ia64/mm/fault.c linux-2.6.38-rc8-vs2.3.0.37-rc6/arch/ia64/mm/fault.c
428 --- linux-2.6.38-rc8/arch/ia64/mm/fault.c       2010-08-02 16:52:04.000000000 +0200
429 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/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-rc8/arch/m32r/kernel/traps.c linux-2.6.38-rc8-vs2.3.0.37-rc6/arch/m32r/kernel/traps.c
439 --- linux-2.6.38-rc8/arch/m32r/kernel/traps.c   2009-12-03 20:01:57.000000000 +0100
440 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/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-rc8/arch/m68k/Kconfig linux-2.6.38-rc8-vs2.3.0.37-rc6/arch/m68k/Kconfig
454 --- linux-2.6.38-rc8/arch/m68k/Kconfig  2011-01-05 21:49:00.000000000 +0100
455 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/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-rc8/arch/m68k/kernel/ptrace.c linux-2.6.38-rc8-vs2.3.0.37-rc6/arch/m68k/kernel/ptrace.c
466 --- linux-2.6.38-rc8/arch/m68k/kernel/ptrace.c  2011-01-05 21:49:01.000000000 +0100
467 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/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-rc8/arch/m68k/kernel/traps.c linux-2.6.38-rc8-vs2.3.0.37-rc6/arch/m68k/kernel/traps.c
486 --- linux-2.6.38-rc8/arch/m68k/kernel/traps.c   2010-08-02 16:52:04.000000000 +0200
487 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/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-rc8/arch/m68knommu/Kconfig linux-2.6.38-rc8-vs2.3.0.37-rc6/arch/m68knommu/Kconfig
500 --- linux-2.6.38-rc8/arch/m68knommu/Kconfig     2011-03-10 17:08:42.000000000 +0100
501 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/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-rc8/arch/m68knommu/kernel/traps.c linux-2.6.38-rc8-vs2.3.0.37-rc6/arch/m68knommu/kernel/traps.c
512 --- linux-2.6.38-rc8/arch/m68knommu/kernel/traps.c      2011-01-05 21:49:01.000000000 +0100
513 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/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-rc8/arch/mips/Kconfig linux-2.6.38-rc8-vs2.3.0.37-rc6/arch/mips/Kconfig
527 --- linux-2.6.38-rc8/arch/mips/Kconfig  2011-03-10 17:08:43.000000000 +0100
528 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/arch/mips/Kconfig   2011-01-29 02:01:07.000000000 +0100
529 @@ -2414,6 +2414,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-rc8/arch/mips/kernel/ptrace.c linux-2.6.38-rc8-vs2.3.0.37-rc6/arch/mips/kernel/ptrace.c
539 --- linux-2.6.38-rc8/arch/mips/kernel/ptrace.c  2011-01-05 21:49:06.000000000 +0100
540 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/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-rc8/arch/mips/kernel/scall32-o32.S linux-2.6.38-rc8-vs2.3.0.37-rc6/arch/mips/kernel/scall32-o32.S
560 --- linux-2.6.38-rc8/arch/mips/kernel/scall32-o32.S     2010-10-21 13:06:54.000000000 +0200
561 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/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-rc8/arch/mips/kernel/scall64-64.S linux-2.6.38-rc8-vs2.3.0.37-rc6/arch/mips/kernel/scall64-64.S
572 --- linux-2.6.38-rc8/arch/mips/kernel/scall64-64.S      2010-10-21 13:06:54.000000000 +0200
573 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/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-rc8/arch/mips/kernel/scall64-n32.S linux-2.6.38-rc8-vs2.3.0.37-rc6/arch/mips/kernel/scall64-n32.S
584 --- linux-2.6.38-rc8/arch/mips/kernel/scall64-n32.S     2010-10-21 13:06:54.000000000 +0200
585 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/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-rc8/arch/mips/kernel/scall64-o32.S linux-2.6.38-rc8-vs2.3.0.37-rc6/arch/mips/kernel/scall64-o32.S
596 --- linux-2.6.38-rc8/arch/mips/kernel/scall64-o32.S     2010-10-21 13:06:54.000000000 +0200
597 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/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-rc8/arch/mips/kernel/traps.c linux-2.6.38-rc8-vs2.3.0.37-rc6/arch/mips/kernel/traps.c
608 --- linux-2.6.38-rc8/arch/mips/kernel/traps.c   2011-03-10 17:08:44.000000000 +0100
609 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/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-rc8/arch/parisc/Kconfig linux-2.6.38-rc8-vs2.3.0.37-rc6/arch/parisc/Kconfig
625 --- linux-2.6.38-rc8/arch/parisc/Kconfig        2011-03-10 17:08:44.000000000 +0100
626 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/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-rc8/arch/parisc/kernel/syscall_table.S linux-2.6.38-rc8-vs2.3.0.37-rc6/arch/parisc/kernel/syscall_table.S
637 --- linux-2.6.38-rc8/arch/parisc/kernel/syscall_table.S 2011-01-05 21:49:09.000000000 +0100
638 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/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-rc8/arch/parisc/kernel/traps.c linux-2.6.38-rc8-vs2.3.0.37-rc6/arch/parisc/kernel/traps.c
649 --- linux-2.6.38-rc8/arch/parisc/kernel/traps.c 2009-09-10 15:25:40.000000000 +0200
650 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/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-rc8/arch/parisc/mm/fault.c linux-2.6.38-rc8-vs2.3.0.37-rc6/arch/parisc/mm/fault.c
675 --- linux-2.6.38-rc8/arch/parisc/mm/fault.c     2010-08-02 16:52:06.000000000 +0200
676 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/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-rc8/arch/powerpc/Kconfig linux-2.6.38-rc8-vs2.3.0.37-rc6/arch/powerpc/Kconfig
690 --- linux-2.6.38-rc8/arch/powerpc/Kconfig       2011-03-10 17:08:44.000000000 +0100
691 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/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-rc8/arch/powerpc/include/asm/unistd.h linux-2.6.38-rc8-vs2.3.0.37-rc6/arch/powerpc/include/asm/unistd.h
702 --- linux-2.6.38-rc8/arch/powerpc/include/asm/unistd.h  2011-01-05 21:49:10.000000000 +0100
703 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/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-rc8/arch/powerpc/kernel/process.c linux-2.6.38-rc8-vs2.3.0.37-rc6/arch/powerpc/kernel/process.c
714 --- linux-2.6.38-rc8/arch/powerpc/kernel/process.c      2011-03-10 17:08:44.000000000 +0100
715 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/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-rc8/arch/powerpc/kernel/traps.c linux-2.6.38-rc8-vs2.3.0.37-rc6/arch/powerpc/kernel/traps.c
729 --- linux-2.6.38-rc8/arch/powerpc/kernel/traps.c        2011-03-10 17:08:44.000000000 +0100
730 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/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-rc8/arch/powerpc/kernel/vdso.c linux-2.6.38-rc8-vs2.3.0.37-rc6/arch/powerpc/kernel/vdso.c
744 --- linux-2.6.38-rc8/arch/powerpc/kernel/vdso.c 2011-01-05 21:49:11.000000000 +0100
745 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/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-rc8/arch/s390/Kconfig linux-2.6.38-rc8-vs2.3.0.37-rc6/arch/s390/Kconfig
755 --- linux-2.6.38-rc8/arch/s390/Kconfig  2011-03-10 17:08:45.000000000 +0100
756 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/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-rc8/arch/s390/include/asm/tlb.h linux-2.6.38-rc8-vs2.3.0.37-rc6/arch/s390/include/asm/tlb.h
767 --- linux-2.6.38-rc8/arch/s390/include/asm/tlb.h        2011-03-10 17:08:45.000000000 +0100
768 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/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-rc8/arch/s390/include/asm/unistd.h linux-2.6.38-rc8-vs2.3.0.37-rc6/arch/s390/include/asm/unistd.h
779 --- linux-2.6.38-rc8/arch/s390/include/asm/unistd.h     2010-10-21 13:06:58.000000000 +0200
780 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/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-rc8/arch/s390/kernel/ptrace.c linux-2.6.38-rc8-vs2.3.0.37-rc6/arch/s390/kernel/ptrace.c
791 --- linux-2.6.38-rc8/arch/s390/kernel/ptrace.c  2011-03-10 17:08:45.000000000 +0100
792 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/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-rc8/arch/s390/kernel/syscalls.S linux-2.6.38-rc8-vs2.3.0.37-rc6/arch/s390/kernel/syscalls.S
802 --- linux-2.6.38-rc8/arch/s390/kernel/syscalls.S        2010-10-21 13:06:58.000000000 +0200
803 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/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-rc8/arch/sh/Kconfig linux-2.6.38-rc8-vs2.3.0.37-rc6/arch/sh/Kconfig
814 --- linux-2.6.38-rc8/arch/sh/Kconfig    2011-03-10 17:08:45.000000000 +0100
815 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/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-rc8/arch/sh/kernel/irq.c linux-2.6.38-rc8-vs2.3.0.37-rc6/arch/sh/kernel/irq.c
826 --- linux-2.6.38-rc8/arch/sh/kernel/irq.c       2011-01-05 21:49:16.000000000 +0100
827 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/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-rc8/arch/sh/kernel/vsyscall/vsyscall.c linux-2.6.38-rc8-vs2.3.0.37-rc6/arch/sh/kernel/vsyscall/vsyscall.c
837 --- linux-2.6.38-rc8/arch/sh/kernel/vsyscall/vsyscall.c 2010-07-07 18:31:10.000000000 +0200
838 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/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-rc8/arch/sparc/Kconfig linux-2.6.38-rc8-vs2.3.0.37-rc6/arch/sparc/Kconfig
848 --- linux-2.6.38-rc8/arch/sparc/Kconfig 2011-03-10 17:08:47.000000000 +0100
849 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/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-rc8/arch/sparc/include/asm/tlb_64.h linux-2.6.38-rc8-vs2.3.0.37-rc6/arch/sparc/include/asm/tlb_64.h
860 --- linux-2.6.38-rc8/arch/sparc/include/asm/tlb_64.h    2009-09-10 15:25:45.000000000 +0200
861 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/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-rc8/arch/sparc/include/asm/unistd.h linux-2.6.38-rc8-vs2.3.0.37-rc6/arch/sparc/include/asm/unistd.h
871 --- linux-2.6.38-rc8/arch/sparc/include/asm/unistd.h    2010-10-21 13:06:58.000000000 +0200
872 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/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-rc8/arch/sparc/kernel/systbls_32.S linux-2.6.38-rc8-vs2.3.0.37-rc6/arch/sparc/kernel/systbls_32.S
883 --- linux-2.6.38-rc8/arch/sparc/kernel/systbls_32.S     2010-10-21 13:06:59.000000000 +0200
884 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/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-rc8/arch/sparc/kernel/systbls_64.S linux-2.6.38-rc8-vs2.3.0.37-rc6/arch/sparc/kernel/systbls_64.S
895 --- linux-2.6.38-rc8/arch/sparc/kernel/systbls_64.S     2010-10-21 13:06:59.000000000 +0200
896 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/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-rc8/arch/um/Kconfig.rest linux-2.6.38-rc8-vs2.3.0.37-rc6/arch/um/Kconfig.rest
916 --- linux-2.6.38-rc8/arch/um/Kconfig.rest       2009-06-11 17:12:19.000000000 +0200
917 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/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-rc8/arch/um/include/asm/tlb.h linux-2.6.38-rc8-vs2.3.0.37-rc6/arch/um/include/asm/tlb.h
928 --- linux-2.6.38-rc8/arch/um/include/asm/tlb.h  2009-09-10 15:25:46.000000000 +0200
929 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/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-rc8/arch/um/include/shared/kern_constants.h linux-2.6.38-rc8-vs2.3.0.37-rc6/arch/um/include/shared/kern_constants.h
939 --- linux-2.6.38-rc8/arch/um/include/shared/kern_constants.h    1970-01-01 01:00:00.000000000 +0100
940 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/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-rc8/arch/um/include/shared/user_constants.h linux-2.6.38-rc8-vs2.3.0.37-rc6/arch/um/include/shared/user_constants.h
944 --- linux-2.6.38-rc8/arch/um/include/shared/user_constants.h    1970-01-01 01:00:00.000000000 +0100
945 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/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-rc8/arch/x86/Kconfig linux-2.6.38-rc8-vs2.3.0.37-rc6/arch/x86/Kconfig
988 --- linux-2.6.38-rc8/arch/x86/Kconfig   2011-03-10 17:08:47.000000000 +0100
989 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/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-rc8/arch/x86/ia32/ia32entry.S linux-2.6.38-rc8-vs2.3.0.37-rc6/arch/x86/ia32/ia32entry.S
1000 --- linux-2.6.38-rc8/arch/x86/ia32/ia32entry.S  2010-10-21 13:06:59.000000000 +0200
1001 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/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-rc8/arch/x86/include/asm/unistd_64.h linux-2.6.38-rc8-vs2.3.0.37-rc6/arch/x86/include/asm/unistd_64.h
1012 --- linux-2.6.38-rc8/arch/x86/include/asm/unistd_64.h   2010-10-21 13:06:59.000000000 +0200
1013 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/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-rc8/arch/x86/kernel/syscall_table_32.S linux-2.6.38-rc8-vs2.3.0.37-rc6/arch/x86/kernel/syscall_table_32.S
1024 --- linux-2.6.38-rc8/arch/x86/kernel/syscall_table_32.S 2010-10-21 13:07:00.000000000 +0200
1025 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/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-rc8/drivers/block/Kconfig linux-2.6.38-rc8-vs2.3.0.37-rc6/drivers/block/Kconfig
1036 --- linux-2.6.38-rc8/drivers/block/Kconfig      2011-03-10 17:08:52.000000000 +0100
1037 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/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-rc8/drivers/block/Makefile linux-2.6.38-rc8-vs2.3.0.37-rc6/drivers/block/Makefile
1053 --- linux-2.6.38-rc8/drivers/block/Makefile     2011-03-10 17:08:52.000000000 +0100
1054 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/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-rc8/drivers/block/loop.c linux-2.6.38-rc8-vs2.3.0.37-rc6/drivers/block/loop.c
1064 --- linux-2.6.38-rc8/drivers/block/loop.c       2011-03-10 17:08:52.000000000 +0100
1065 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/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-rc8/drivers/block/vroot.c linux-2.6.38-rc8-vs2.3.0.37-rc6/drivers/block/vroot.c
1120 --- linux-2.6.38-rc8/drivers/block/vroot.c      1970-01-01 01:00:00.000000000 +0100
1121 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/drivers/block/vroot.c       2011-01-29 02:01:07.000000000 +0100
1122 @@ -0,0 +1,282 @@
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 +struct block_device *__vroot_get_real_bdev(struct block_device *bdev)
1271 +{
1272 +       struct inode *inode = bdev->bd_inode;
1273 +       struct vroot_device *vr;
1274 +       struct block_device *real_bdev;
1275 +       int minor = iminor(inode);
1276 +
1277 +       vr = &vroot_dev[minor];
1278 +       real_bdev = vr->vr_device;
1279 +
1280 +       vxdprintk(VXD_CBIT(misc, 0),
1281 +               "vroot[%d]_get_real_bdev: dev=" VXF_DEV,
1282 +               vr->vr_number, VXD_DEV(real_bdev));
1283 +
1284 +       if (vr->vr_state != Vr_bound)
1285 +               return ERR_PTR(-ENXIO);
1286 +
1287 +       __iget(real_bdev->bd_inode);
1288 +       return real_bdev;
1289 +}
1290 +
1291 +/*
1292 + * And now the modules code and kernel interface.
1293 + */
1294 +
1295 +module_param(max_vroot, int, 0);
1296 +
1297 +MODULE_PARM_DESC(max_vroot, "Maximum number of vroot devices (1-256)");
1298 +MODULE_LICENSE("GPL");
1299 +MODULE_ALIAS_BLOCKDEV_MAJOR(VROOT_MAJOR);
1300 +
1301 +MODULE_AUTHOR ("Herbert Pötzl");
1302 +MODULE_DESCRIPTION ("Virtual Root Device Mapper");
1303 +
1304 +
1305 +int __init vroot_init(void)
1306 +{
1307 +       int err, i;
1308 +
1309 +       if (max_vroot < 1 || max_vroot > 256) {
1310 +               max_vroot = MAX_VROOT_DEFAULT;
1311 +               printk(KERN_WARNING "vroot: invalid max_vroot "
1312 +                       "(must be between 1 and 256), "
1313 +                       "using default (%d)\n", max_vroot);
1314 +       }
1315 +
1316 +       if (register_blkdev(VROOT_MAJOR, "vroot"))
1317 +               return -EIO;
1318 +
1319 +       err = -ENOMEM;
1320 +       vroot_dev = kmalloc(max_vroot * sizeof(struct vroot_device), GFP_KERNEL);
1321 +       if (!vroot_dev)
1322 +               goto out_mem1;
1323 +       memset(vroot_dev, 0, max_vroot * sizeof(struct vroot_device));
1324 +
1325 +       disks = kmalloc(max_vroot * sizeof(struct gendisk *), GFP_KERNEL);
1326 +       if (!disks)
1327 +               goto out_mem2;
1328 +
1329 +       for (i = 0; i < max_vroot; i++) {
1330 +               disks[i] = alloc_disk(1);
1331 +               if (!disks[i])
1332 +                       goto out_mem3;
1333 +               disks[i]->queue = blk_alloc_queue(GFP_KERNEL);
1334 +               if (!disks[i]->queue)
1335 +                       goto out_mem3;
1336 +       }
1337 +
1338 +       for (i = 0; i < max_vroot; i++) {
1339 +               struct vroot_device *vr = &vroot_dev[i];
1340 +               struct gendisk *disk = disks[i];
1341 +
1342 +               memset(vr, 0, sizeof(*vr));
1343 +               sema_init(&vr->vr_ctl_mutex, 1);
1344 +               vr->vr_number = i;
1345 +               disk->major = VROOT_MAJOR;
1346 +               disk->first_minor = i;
1347 +               disk->fops = &vr_fops;
1348 +               sprintf(disk->disk_name, "vroot%d", i);
1349 +               disk->private_data = vr;
1350 +       }
1351 +
1352 +       err = register_vroot_grb(&__vroot_get_real_bdev);
1353 +       if (err)
1354 +               goto out_mem3;
1355 +
1356 +       for (i = 0; i < max_vroot; i++)
1357 +               add_disk(disks[i]);
1358 +       printk(KERN_INFO "vroot: loaded (max %d devices)\n", max_vroot);
1359 +       return 0;
1360 +
1361 +out_mem3:
1362 +       while (i--)
1363 +               put_disk(disks[i]);
1364 +       kfree(disks);
1365 +out_mem2:
1366 +       kfree(vroot_dev);
1367 +out_mem1:
1368 +       unregister_blkdev(VROOT_MAJOR, "vroot");
1369 +       printk(KERN_ERR "vroot: ran out of memory\n");
1370 +       return err;
1371 +}
1372 +
1373 +void vroot_exit(void)
1374 +{
1375 +       int i;
1376 +
1377 +       if (unregister_vroot_grb(&__vroot_get_real_bdev))
1378 +               printk(KERN_WARNING "vroot: cannot unregister grb\n");
1379 +
1380 +       for (i = 0; i < max_vroot; i++) {
1381 +               del_gendisk(disks[i]);
1382 +               put_disk(disks[i]);
1383 +       }
1384 +       unregister_blkdev(VROOT_MAJOR, "vroot");
1385 +
1386 +       kfree(disks);
1387 +       kfree(vroot_dev);
1388 +}
1389 +
1390 +module_init(vroot_init);
1391 +module_exit(vroot_exit);
1392 +
1393 +#ifndef MODULE
1394 +
1395 +static int __init max_vroot_setup(char *str)
1396 +{
1397 +       max_vroot = simple_strtol(str, NULL, 0);
1398 +       return 1;
1399 +}
1400 +
1401 +__setup("max_vroot=", max_vroot_setup);
1402 +
1403 +#endif
1404 +
1405 diff -NurpP --minimal linux-2.6.38-rc8/drivers/gpu/drm/radeon/r100_reg_safe.h linux-2.6.38-rc8-vs2.3.0.37-rc6/drivers/gpu/drm/radeon/r100_reg_safe.h
1406 --- linux-2.6.38-rc8/drivers/gpu/drm/radeon/r100_reg_safe.h     1970-01-01 01:00:00.000000000 +0100
1407 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/drivers/gpu/drm/radeon/r100_reg_safe.h      2011-01-29 02:01:07.000000000 +0100
1408 @@ -0,0 +1,28 @@
1409 +static const unsigned r100_reg_safe_bm[102] = {
1410 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1411 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1412 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1413 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1414 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1415 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1416 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1417 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1418 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1419 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1420 +       0x17FF1FFF, 0xFFFFFFFC, 0xFFFFFFFF, 0xFF30FFBF,
1421 +       0xFFFFFFF8, 0xC3E6FFFF, 0xFFFFF6DF, 0xFFFFFFFF,
1422 +       0xFFFFFFCF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1423 +       0xFFFFFF9F, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1424 +       0x38E7FE1F, 0xFFC3FF8E, 0x7FF8FFFF, 0xFFFF803C,
1425 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1426 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFEFFFF, 0xFFFFFFFF,
1427 +       0x00000000, 0xFFFFFFFD, 0xFFFFFFFF, 0xFFFFFFFF,
1428 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1429 +       0xFFFFFFFF, 0xFFFCFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1430 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1431 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1432 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1433 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1434 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1435 +       0xFFFFFFFF, 0xFFFFFFEF,
1436 +};
1437 diff -NurpP --minimal linux-2.6.38-rc8/drivers/gpu/drm/radeon/r200_reg_safe.h linux-2.6.38-rc8-vs2.3.0.37-rc6/drivers/gpu/drm/radeon/r200_reg_safe.h
1438 --- linux-2.6.38-rc8/drivers/gpu/drm/radeon/r200_reg_safe.h     1970-01-01 01:00:00.000000000 +0100
1439 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/drivers/gpu/drm/radeon/r200_reg_safe.h      2011-01-29 02:01:07.000000000 +0100
1440 @@ -0,0 +1,28 @@
1441 +static const unsigned r200_reg_safe_bm[102] = {
1442 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1443 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1444 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1445 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1446 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1447 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1448 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1449 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1450 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1451 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1452 +       0x17FF1FFF, 0xFFFFFFFC, 0xFFFFFFFF, 0xFF30FFBF,
1453 +       0xFFFFFFF8, 0xC3E6FFFF, 0xFFFFF6DF, 0xFFFFFFFF,
1454 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1455 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1456 +       0xFFE7FE1F, 0xF003FFFF, 0x7EFFFFFF, 0xFFFF803C,
1457 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1458 +       0xFFFFFFFF, 0xFFFFEFCE, 0xFFFEFFFF, 0xFFFFFFFE,
1459 +       0x020E0FF0, 0xFFCC83FD, 0xFFFFFFFF, 0xFFFFFFFF,
1460 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1461 +       0xFFFBFFFF, 0xEFFCFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1462 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1463 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1464 +       0xDFDFDFDF, 0x3FFDDFDF, 0xFFFFFFFF, 0xFFFFFF7F,
1465 +       0xFFFFFFFF, 0x00FFFFFF, 0x00000000, 0x00000000,
1466 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1467 +       0xFFFFFE3F, 0xFFFFFFEF,
1468 +};
1469 diff -NurpP --minimal linux-2.6.38-rc8/drivers/gpu/drm/radeon/r300_reg_safe.h linux-2.6.38-rc8-vs2.3.0.37-rc6/drivers/gpu/drm/radeon/r300_reg_safe.h
1470 --- linux-2.6.38-rc8/drivers/gpu/drm/radeon/r300_reg_safe.h     1970-01-01 01:00:00.000000000 +0100
1471 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/drivers/gpu/drm/radeon/r300_reg_safe.h      2011-01-29 02:01:07.000000000 +0100
1472 @@ -0,0 +1,42 @@
1473 +static const unsigned r300_reg_safe_bm[159] = {
1474 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1475 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1476 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1477 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1478 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1479 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1480 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1481 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1482 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1483 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1484 +       0x17FF1FFF, 0xFFFFFFFC, 0xFFFFFFFF, 0xFF30FFBF,
1485 +       0xFFFFFFF8, 0xC3E6FFFF, 0xFFFFF6DF, 0xFFFFFFFF,
1486 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1487 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1488 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFF03F,
1489 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1490 +       0xFFFFFFFF, 0xFFFFEFCE, 0xF00EBFFF, 0x007C0000,
1491 +       0xF0000078, 0xFF000009, 0xFFFFFFFF, 0xFFFFFFFF,
1492 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1493 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1494 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1495 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1496 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1497 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1498 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1499 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1500 +       0xFFFFF7FF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1501 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1502 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1503 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1504 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1505 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1506 +       0xFFFFFC78, 0xFFFFFFFF, 0xFFFFFFFE, 0xFFFFFFFF,
1507 +       0x38FF8F50, 0xFFF88082, 0xF000000C, 0xFAE009FF,
1508 +       0x0000FFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0x00000000,
1509 +       0x00000000, 0x0000C100, 0x00000000, 0x00000000,
1510 +       0x00000000, 0x00000000, 0x00000000, 0x00000000,
1511 +       0x00000000, 0xFFFF0000, 0xFFFFFFFF, 0xFF80FFFF,
1512 +       0x00000000, 0x00000000, 0x00000000, 0x00000000,
1513 +       0x0003FC01, 0xFFFFFCF8, 0xFF800B19,
1514 +};
1515 diff -NurpP --minimal linux-2.6.38-rc8/drivers/gpu/drm/radeon/r420_reg_safe.h linux-2.6.38-rc8-vs2.3.0.37-rc6/drivers/gpu/drm/radeon/r420_reg_safe.h
1516 --- linux-2.6.38-rc8/drivers/gpu/drm/radeon/r420_reg_safe.h     1970-01-01 01:00:00.000000000 +0100
1517 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/drivers/gpu/drm/radeon/r420_reg_safe.h      2011-01-29 02:01:07.000000000 +0100
1518 @@ -0,0 +1,42 @@
1519 +static const unsigned r420_reg_safe_bm[159] = {
1520 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1521 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1522 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1523 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1524 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1525 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1526 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1527 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1528 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1529 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1530 +       0x17FF1FFF, 0xFFFFFFFC, 0xFFFFFFFF, 0xFF30FFBF,
1531 +       0xFFFFFFF8, 0xC3E6FFFF, 0xFFFFF6DF, 0xFFFFFFFF,
1532 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1533 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1534 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFF03F,
1535 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1536 +       0xFFFFFFFF, 0xFFFFEFCE, 0xF00EBFFF, 0x007C0000,
1537 +       0xF0000078, 0xFF000009, 0xFFFFFFFF, 0xFFFFFFFF,
1538 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1539 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1540 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1541 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1542 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1543 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1544 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1545 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1546 +       0xFFFFF7FF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1547 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1548 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1549 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1550 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1551 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1552 +       0xFFFFFC78, 0xFFFFFFFF, 0xFFFFFFFE, 0xFFFFFFFF,
1553 +       0x38FF8F50, 0xFFF88082, 0xF000000C, 0xFAE009FF,
1554 +       0x0000FFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0x00000000,
1555 +       0x00000000, 0x00000100, 0x00000000, 0x00000000,
1556 +       0x00000000, 0x00000000, 0x00000000, 0x00000000,
1557 +       0x00000000, 0x00000000, 0x00000000, 0xFF800000,
1558 +       0x00000000, 0x00000000, 0x00000000, 0x00000000,
1559 +       0x0003FC01, 0xFFFFFCF8, 0xFF800B19,
1560 +};
1561 diff -NurpP --minimal linux-2.6.38-rc8/drivers/gpu/drm/radeon/rn50_reg_safe.h linux-2.6.38-rc8-vs2.3.0.37-rc6/drivers/gpu/drm/radeon/rn50_reg_safe.h
1562 --- linux-2.6.38-rc8/drivers/gpu/drm/radeon/rn50_reg_safe.h     1970-01-01 01:00:00.000000000 +0100
1563 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/drivers/gpu/drm/radeon/rn50_reg_safe.h      2011-01-29 02:01:07.000000000 +0100
1564 @@ -0,0 +1,28 @@
1565 +static const unsigned rn50_reg_safe_bm[102] = {
1566 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1567 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1568 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1569 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1570 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1571 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1572 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1573 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1574 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1575 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1576 +       0x17FF1FFF, 0xFFFFFFFC, 0xFFFFFFFF, 0xFF30FFBF,
1577 +       0xFFFFFFF8, 0xC3E6FFFF, 0xFFFFF6DF, 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 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1587 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1588 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1589 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1590 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1591 +       0xFFFFFFFF, 0xFFFFFFFF,
1592 +};
1593 diff -NurpP --minimal linux-2.6.38-rc8/drivers/gpu/drm/radeon/rs600_reg_safe.h linux-2.6.38-rc8-vs2.3.0.37-rc6/drivers/gpu/drm/radeon/rs600_reg_safe.h
1594 --- linux-2.6.38-rc8/drivers/gpu/drm/radeon/rs600_reg_safe.h    1970-01-01 01:00:00.000000000 +0100
1595 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/drivers/gpu/drm/radeon/rs600_reg_safe.h     2011-01-29 02:01:07.000000000 +0100
1596 @@ -0,0 +1,57 @@
1597 +static const unsigned rs600_reg_safe_bm[219] = {
1598 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1599 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1600 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1601 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1602 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1603 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1604 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1605 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1606 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1607 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1608 +       0x17FF1FFF, 0xFFFFFFFC, 0xFFFFFFFF, 0xFF30FFBF,
1609 +       0xFFFFFFF8, 0xC3E6FFFF, 0xFFFFF6DF, 0xFFFFFFFF,
1610 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1611 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1612 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFF03F,
1613 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1614 +       0xFFFFFFFF, 0xFFFFEFCE, 0xF00EBFFF, 0x007C0000,
1615 +       0xF0000078, 0xFF000009, 0xFFFFFFFF, 0xFFFFFFFF,
1616 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1617 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1618 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1619 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1620 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1621 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1622 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1623 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1624 +       0xFFFFF7FF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1625 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1626 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1627 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1628 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1629 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1630 +       0xFFFFFC78, 0xFFFFFFFF, 0xFFFFFFFE, 0xFFFFFFFF,
1631 +       0x38FF8F50, 0xFFF88082, 0xF000000C, 0xFAE009FF,
1632 +       0x0000FFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0x00000000,
1633 +       0x00000000, 0x00000100, 0x00000000, 0x00000000,
1634 +       0x00000000, 0x00000000, 0x00000000, 0x00000000,
1635 +       0x00000000, 0x00000000, 0x00000000, 0xFF800000,
1636 +       0x00000000, 0x00000000, 0x00000000, 0x00000000,
1637 +       0x0003FC01, 0xFFFFFCF8, 0xFF800B19, 0xFFFFFFFF,
1638 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1639 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1640 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1641 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1642 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1643 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1644 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1645 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1646 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1647 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 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,
1653 +};
1654 diff -NurpP --minimal linux-2.6.38-rc8/drivers/gpu/drm/radeon/rv515_reg_safe.h linux-2.6.38-rc8-vs2.3.0.37-rc6/drivers/gpu/drm/radeon/rv515_reg_safe.h
1655 --- linux-2.6.38-rc8/drivers/gpu/drm/radeon/rv515_reg_safe.h    1970-01-01 01:00:00.000000000 +0100
1656 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/drivers/gpu/drm/radeon/rv515_reg_safe.h     2011-01-29 02:01:07.000000000 +0100
1657 @@ -0,0 +1,57 @@
1658 +static const unsigned rv515_reg_safe_bm[219] = {
1659 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1660 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1661 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1662 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1663 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1664 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1665 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1666 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1667 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1668 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1669 +       0x17FF1FFF, 0xFFFFFFFC, 0xFFFFFFFF, 0xFF30FFBF,
1670 +       0xFFFFFFF8, 0xC3E6FFFF, 0xFFFFF6DF, 0xFFFFFFFF,
1671 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1672 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1673 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFF03F,
1674 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1675 +       0xFFFFFFFF, 0xFFFFEFCE, 0xF00EBFFF, 0x007C0000,
1676 +       0xF0000038, 0xFF000009, 0xFFFFFFFF, 0xFFFFFFFF,
1677 +       0xFFFFFFFF, 0xFFFFFFFF, 0x00000000, 0xFFFFFFFF,
1678 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1679 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1680 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1681 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1682 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1683 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1684 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1685 +       0xFFFFF7FF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1686 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1687 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1688 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1689 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1690 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1691 +       0x1FFFF878, 0xFFFFE000, 0xFFFFFE1E, 0xFFFFFFFF,
1692 +       0x388F8F50, 0xFFF88082, 0xFF0000FC, 0xFAE009FF,
1693 +       0x0000FFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0x00000000,
1694 +       0xFFFF8CFC, 0xFFFFC1FF, 0xFFFFFFFF, 0xFFFFFFFF,
1695 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1696 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFF80FFFF,
1697 +       0x00000000, 0x00000000, 0x00000000, 0x00000000,
1698 +       0x0003FC01, 0x3FFFFCF8, 0xFF800B19, 0xFFDFFFFF,
1699 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1700 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1701 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1702 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1703 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1704 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1705 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1706 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1707 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1708 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1709 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1710 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1711 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1712 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1713 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1714 +};
1715 diff -NurpP --minimal linux-2.6.38-rc8/drivers/infiniband/core/addr.c linux-2.6.38-rc8-vs2.3.0.37-rc6/drivers/infiniband/core/addr.c
1716 --- linux-2.6.38-rc8/drivers/infiniband/core/addr.c     2011-03-10 17:08:55.000000000 +0100
1717 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/drivers/infiniband/core/addr.c      2011-01-29 02:01:07.000000000 +0100
1718 @@ -252,7 +252,7 @@ static int addr6_resolve(struct sockaddr
1719  
1720         if (ipv6_addr_any(&fl.fl6_src)) {
1721                 ret = ipv6_dev_get_saddr(&init_net, ip6_dst_idev(dst)->dev,
1722 -                                        &fl.fl6_dst, 0, &fl.fl6_src);
1723 +                                        &fl.fl6_dst, 0, &fl.fl6_src, NULL);
1724                 if (ret)
1725                         goto put;
1726  
1727 diff -NurpP --minimal linux-2.6.38-rc8/drivers/infiniband/hw/ipath/ipath_user_pages.c linux-2.6.38-rc8-vs2.3.0.37-rc6/drivers/infiniband/hw/ipath/ipath_user_pages.c
1728 --- linux-2.6.38-rc8/drivers/infiniband/hw/ipath/ipath_user_pages.c     2011-03-10 17:08:55.000000000 +0100
1729 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/drivers/infiniband/hw/ipath/ipath_user_pages.c      2011-01-29 02:01:07.000000000 +0100
1730 @@ -35,6 +35,7 @@
1731  #include <linux/device.h>
1732  #include <linux/slab.h>
1733  #include <linux/sched.h>
1734 +#include <linux/vs_memory.h>
1735  
1736  #include "ipath_kernel.h"
1737  
1738 diff -NurpP --minimal linux-2.6.38-rc8/drivers/md/dm-ioctl.c linux-2.6.38-rc8-vs2.3.0.37-rc6/drivers/md/dm-ioctl.c
1739 --- linux-2.6.38-rc8/drivers/md/dm-ioctl.c      2011-03-10 17:08:57.000000000 +0100
1740 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/drivers/md/dm-ioctl.c       2011-01-29 02:01:07.000000000 +0100
1741 @@ -16,6 +16,7 @@
1742  #include <linux/dm-ioctl.h>
1743  #include <linux/hdreg.h>
1744  #include <linux/compat.h>
1745 +#include <linux/vs_context.h>
1746  
1747  #include <asm/uaccess.h>
1748  
1749 @@ -106,7 +107,8 @@ static struct hash_cell *__get_name_cell
1750         unsigned int h = hash_str(str);
1751  
1752         list_for_each_entry (hc, _name_buckets + h, name_list)
1753 -               if (!strcmp(hc->name, str)) {
1754 +               if (vx_check(dm_get_xid(hc->md), VS_WATCH_P | VS_IDENT) &&
1755 +                       !strcmp(hc->name, str)) {
1756                         dm_get(hc->md);
1757                         return hc;
1758                 }
1759 @@ -120,7 +122,8 @@ static struct hash_cell *__get_uuid_cell
1760         unsigned int h = hash_str(str);
1761  
1762         list_for_each_entry (hc, _uuid_buckets + h, uuid_list)
1763 -               if (!strcmp(hc->uuid, str)) {
1764 +               if (vx_check(dm_get_xid(hc->md), VS_WATCH_P | VS_IDENT) &&
1765 +                       !strcmp(hc->uuid, str)) {
1766                         dm_get(hc->md);
1767                         return hc;
1768                 }
1769 @@ -427,6 +430,9 @@ typedef int (*ioctl_fn)(struct dm_ioctl 
1770  
1771  static int remove_all(struct dm_ioctl *param, size_t param_size)
1772  {
1773 +       if (!vx_check(0, VS_ADMIN))
1774 +               return -EPERM;
1775 +
1776         dm_hash_remove_all(1);
1777         param->data_size = 0;
1778         return 0;
1779 @@ -474,6 +480,8 @@ static int list_devices(struct dm_ioctl 
1780          */
1781         for (i = 0; i < NUM_BUCKETS; i++) {
1782                 list_for_each_entry (hc, _name_buckets + i, name_list) {
1783 +                       if (!vx_check(dm_get_xid(hc->md), VS_WATCH_P | VS_IDENT))
1784 +                               continue;
1785                         needed += sizeof(struct dm_name_list);
1786                         needed += strlen(hc->name) + 1;
1787                         needed += ALIGN_MASK;
1788 @@ -497,6 +505,8 @@ static int list_devices(struct dm_ioctl 
1789          */
1790         for (i = 0; i < NUM_BUCKETS; i++) {
1791                 list_for_each_entry (hc, _name_buckets + i, name_list) {
1792 +                       if (!vx_check(dm_get_xid(hc->md), VS_WATCH_P | VS_IDENT))
1793 +                               continue;
1794                         if (old_nl)
1795                                 old_nl->next = (uint32_t) ((void *) nl -
1796                                                            (void *) old_nl);
1797 @@ -731,10 +741,11 @@ static struct hash_cell *__find_device_h
1798         if (!md)
1799                 goto out;
1800  
1801 -       mdptr = dm_get_mdptr(md);
1802 +       if (vx_check(dm_get_xid(md), VS_WATCH_P | VS_IDENT))
1803 +               mdptr = dm_get_mdptr(md);
1804 +
1805         if (!mdptr)
1806                 dm_put(md);
1807 -
1808  out:
1809         return mdptr;
1810  }
1811 @@ -1566,8 +1577,8 @@ static int ctl_ioctl(uint command, struc
1812         ioctl_fn fn = NULL;
1813         size_t param_size;
1814  
1815 -       /* only root can play with this */
1816 -       if (!capable(CAP_SYS_ADMIN))
1817 +       /* only root and certain contexts can play with this */
1818 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_ADMIN_MAPPER))
1819                 return -EACCES;
1820  
1821         if (_IOC_TYPE(command) != DM_IOCTL)
1822 diff -NurpP --minimal linux-2.6.38-rc8/drivers/md/dm.c linux-2.6.38-rc8-vs2.3.0.37-rc6/drivers/md/dm.c
1823 --- linux-2.6.38-rc8/drivers/md/dm.c    2011-03-10 17:08:57.000000000 +0100
1824 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/drivers/md/dm.c     2011-01-29 03:26:19.000000000 +0100
1825 @@ -20,6 +20,7 @@
1826  #include <linux/idr.h>
1827  #include <linux/hdreg.h>
1828  #include <linux/delay.h>
1829 +#include <linux/vs_base.h>
1830  
1831  #include <trace/events/block.h>
1832  
1833 @@ -119,6 +120,7 @@ struct mapped_device {
1834         rwlock_t map_lock;
1835         atomic_t holders;
1836         atomic_t open_count;
1837 +       xid_t xid;
1838  
1839         unsigned long flags;
1840  
1841 @@ -326,6 +328,7 @@ int dm_deleting_md(struct mapped_device 
1842  static int dm_blk_open(struct block_device *bdev, fmode_t mode)
1843  {
1844         struct mapped_device *md;
1845 +       int ret = -ENXIO;
1846  
1847         spin_lock(&_minor_lock);
1848  
1849 @@ -334,18 +337,19 @@ static int dm_blk_open(struct block_devi
1850                 goto out;
1851  
1852         if (test_bit(DMF_FREEING, &md->flags) ||
1853 -           dm_deleting_md(md)) {
1854 -               md = NULL;
1855 +           dm_deleting_md(md))
1856 +               goto out;
1857 +
1858 +       ret = -EACCES;
1859 +       if (!vx_check(md->xid, VS_IDENT|VS_HOSTID))
1860                 goto out;
1861 -       }
1862  
1863         dm_get(md);
1864         atomic_inc(&md->open_count);
1865 -
1866 +       ret = 0;
1867  out:
1868         spin_unlock(&_minor_lock);
1869 -
1870 -       return md ? 0 : -ENXIO;
1871 +       return ret;
1872  }
1873  
1874  static int dm_blk_close(struct gendisk *disk, fmode_t mode)
1875 @@ -565,6 +569,14 @@ int dm_set_geometry(struct mapped_device
1876         return 0;
1877  }
1878  
1879 +/*
1880 + * Get the xid associated with a dm device
1881 + */
1882 +xid_t dm_get_xid(struct mapped_device *md)
1883 +{
1884 +       return md->xid;
1885 +}
1886 +
1887  /*-----------------------------------------------------------------
1888   * CRUD START:
1889   *   A more elegant soln is in the works that uses the queue
1890 @@ -1860,6 +1872,7 @@ static struct mapped_device *alloc_dev(i
1891         INIT_LIST_HEAD(&md->uevent_list);
1892         spin_lock_init(&md->uevent_lock);
1893  
1894 +       md->xid = vx_current_xid();
1895         md->queue = blk_alloc_queue(GFP_KERNEL);
1896         if (!md->queue)
1897                 goto bad_queue;
1898 diff -NurpP --minimal linux-2.6.38-rc8/drivers/md/dm.h linux-2.6.38-rc8-vs2.3.0.37-rc6/drivers/md/dm.h
1899 --- linux-2.6.38-rc8/drivers/md/dm.h    2010-10-21 13:07:07.000000000 +0200
1900 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/drivers/md/dm.h     2011-01-29 02:01:07.000000000 +0100
1901 @@ -41,6 +41,8 @@ struct dm_dev_internal {
1902  struct dm_table;
1903  struct dm_md_mempools;
1904  
1905 +xid_t dm_get_xid(struct mapped_device *md);
1906 +
1907  /*-----------------------------------------------------------------
1908   * Internal table functions.
1909   *---------------------------------------------------------------*/
1910 diff -NurpP --minimal linux-2.6.38-rc8/drivers/net/tun.c linux-2.6.38-rc8-vs2.3.0.37-rc6/drivers/net/tun.c
1911 --- linux-2.6.38-rc8/drivers/net/tun.c  2011-03-10 17:09:05.000000000 +0100
1912 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/drivers/net/tun.c   2011-01-29 02:01:07.000000000 +0100
1913 @@ -62,6 +62,7 @@
1914  #include <linux/nsproxy.h>
1915  #include <linux/virtio_net.h>
1916  #include <linux/rcupdate.h>
1917 +#include <linux/vs_network.h>
1918  #include <net/net_namespace.h>
1919  #include <net/netns/generic.h>
1920  #include <net/rtnetlink.h>
1921 @@ -103,6 +104,7 @@ struct tun_struct {
1922         unsigned int            flags;
1923         uid_t                   owner;
1924         gid_t                   group;
1925 +       nid_t                   nid;
1926  
1927         struct net_device       *dev;
1928         struct fasync_struct    *fasync;
1929 @@ -853,6 +855,7 @@ static void tun_setup(struct net_device 
1930  
1931         tun->owner = -1;
1932         tun->group = -1;
1933 +       tun->nid = current->nid;
1934  
1935         dev->ethtool_ops = &tun_ethtool_ops;
1936         dev->destructor = tun_free_netdev;
1937 @@ -1003,7 +1006,7 @@ static int tun_set_iff(struct net *net, 
1938  
1939                 if (((tun->owner != -1 && cred->euid != tun->owner) ||
1940                      (tun->group != -1 && !in_egroup_p(tun->group))) &&
1941 -                   !capable(CAP_NET_ADMIN))
1942 +               !cap_raised(current_cap(), CAP_NET_ADMIN))
1943                         return -EPERM;
1944                 err = security_tun_dev_attach(tun->socket.sk);
1945                 if (err < 0)
1946 @@ -1017,7 +1020,7 @@ static int tun_set_iff(struct net *net, 
1947                 char *name;
1948                 unsigned long flags = 0;
1949  
1950 -               if (!capable(CAP_NET_ADMIN))
1951 +               if (!nx_capable(CAP_NET_ADMIN, NXC_TUN_CREATE))
1952                         return -EPERM;
1953                 err = security_tun_dev_create();
1954                 if (err < 0)
1955 @@ -1087,6 +1090,9 @@ static int tun_set_iff(struct net *net, 
1956  
1957                 sk->sk_destruct = tun_sock_destruct;
1958  
1959 +               if (!nx_check(tun->nid, VS_IDENT | VS_HOSTID | VS_ADMIN_P))
1960 +                       return -EPERM;
1961 +
1962                 err = tun_attach(tun, file);
1963                 if (err < 0)
1964                         goto failed;
1965 @@ -1278,6 +1284,16 @@ static long __tun_chr_ioctl(struct file 
1966                 DBG(KERN_INFO "%s: group set to %d\n", tun->dev->name, tun->group);
1967                 break;
1968  
1969 +       case TUNSETNID:
1970 +               if (!capable(CAP_CONTEXT))
1971 +                       return -EPERM;
1972 +
1973 +               /* Set nid owner of the device */
1974 +               tun->nid = (nid_t) arg;
1975 +
1976 +               DBG(KERN_INFO "%s: nid owner set to %u\n", tun->dev->name, tun->nid);
1977 +               break;
1978 +
1979         case TUNSETLINK:
1980                 /* Only allow setting the type when the interface is down */
1981                 if (tun->dev->flags & IFF_UP) {
1982 diff -NurpP --minimal linux-2.6.38-rc8/drivers/tty/sysrq.c linux-2.6.38-rc8-vs2.3.0.37-rc6/drivers/tty/sysrq.c
1983 --- linux-2.6.38-rc8/drivers/tty/sysrq.c        2011-03-10 17:09:16.000000000 +0100
1984 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/drivers/tty/sysrq.c 2011-02-17 02:17:49.000000000 +0100
1985 @@ -41,6 +41,7 @@
1986  #include <linux/oom.h>
1987  #include <linux/slab.h>
1988  #include <linux/input.h>
1989 +#include <linux/vserver/debug.h>
1990  
1991  #include <asm/ptrace.h>
1992  #include <asm/irq_regs.h>
1993 @@ -395,6 +396,21 @@ static struct sysrq_key_op sysrq_unrt_op
1994         .enable_mask    = SYSRQ_ENABLE_RTNICE,
1995  };
1996  
1997 +
1998 +#ifdef CONFIG_VSERVER_DEBUG
1999 +static void sysrq_handle_vxinfo(int key)
2000 +{
2001 +       dump_vx_info_inactive((key == 'x') ? 0 : 1);
2002 +}
2003 +
2004 +static struct sysrq_key_op sysrq_showvxinfo_op = {
2005 +       .handler        = sysrq_handle_vxinfo,
2006 +       .help_msg       = "conteXt",
2007 +       .action_msg     = "Show Context Info",
2008 +       .enable_mask    = SYSRQ_ENABLE_DUMP,
2009 +};
2010 +#endif
2011 +
2012  /* Key Operations table and lock */
2013  static DEFINE_SPINLOCK(sysrq_key_table_lock);
2014  
2015 @@ -449,7 +465,11 @@ static struct sysrq_key_op *sysrq_key_ta
2016         NULL,                           /* v */
2017         &sysrq_showstate_blocked_op,    /* w */
2018         /* x: May be registered on ppc/powerpc for xmon */
2019 +#ifdef CONFIG_VSERVER_DEBUG
2020 +       &sysrq_showvxinfo_op,           /* x */
2021 +#else
2022         NULL,                           /* x */
2023 +#endif
2024         /* y: May be registered on sparc64 for global register dump */
2025         NULL,                           /* y */
2026         &sysrq_ftrace_dump_op,          /* z */
2027 @@ -464,6 +484,8 @@ static int sysrq_key_table_key2index(int
2028                 retval = key - '0';
2029         else if ((key >= 'a') && (key <= 'z'))
2030                 retval = key + 10 - 'a';
2031 +       else if ((key >= 'A') && (key <= 'Z'))
2032 +               retval = key + 10 - 'A';
2033         else
2034                 retval = -1;
2035         return retval;
2036 diff -NurpP --minimal linux-2.6.38-rc8/drivers/tty/tty_io.c linux-2.6.38-rc8-vs2.3.0.37-rc6/drivers/tty/tty_io.c
2037 --- linux-2.6.38-rc8/drivers/tty/tty_io.c       2011-03-10 17:09:16.000000000 +0100
2038 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/drivers/tty/tty_io.c        2011-02-02 22:20:24.000000000 +0100
2039 @@ -107,6 +107,7 @@
2040  
2041  #include <linux/kmod.h>
2042  #include <linux/nsproxy.h>
2043 +#include <linux/vs_pid.h>
2044  
2045  #undef TTY_DEBUG_HANGUP
2046  
2047 @@ -2057,7 +2058,8 @@ static int tiocsti(struct tty_struct *tt
2048         char ch, mbz = 0;
2049         struct tty_ldisc *ld;
2050  
2051 -       if ((current->signal->tty != tty) && !capable(CAP_SYS_ADMIN))
2052 +       if (((current->signal->tty != tty) &&
2053 +               !vx_capable(CAP_SYS_ADMIN, VXC_TIOCSTI)))
2054                 return -EPERM;
2055         if (get_user(ch, p))
2056                 return -EFAULT;
2057 @@ -2345,6 +2347,7 @@ static int tiocspgrp(struct tty_struct *
2058                 return -ENOTTY;
2059         if (get_user(pgrp_nr, p))
2060                 return -EFAULT;
2061 +       pgrp_nr = vx_rmap_pid(pgrp_nr);
2062         if (pgrp_nr < 0)
2063                 return -EINVAL;
2064         rcu_read_lock();
2065 diff -NurpP --minimal linux-2.6.38-rc8/fs/attr.c linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/attr.c
2066 --- linux-2.6.38-rc8/fs/attr.c  2010-10-21 13:07:47.000000000 +0200
2067 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/attr.c   2011-01-29 02:01:07.000000000 +0100
2068 @@ -13,6 +13,9 @@
2069  #include <linux/fsnotify.h>
2070  #include <linux/fcntl.h>
2071  #include <linux/security.h>
2072 +#include <linux/proc_fs.h>
2073 +#include <linux/devpts_fs.h>
2074 +#include <linux/vs_tag.h>
2075  
2076  /**
2077   * inode_change_ok - check if attribute changes to an inode are allowed
2078 @@ -73,6 +76,10 @@ int inode_change_ok(const struct inode *
2079                         return -EPERM;
2080         }
2081  
2082 +       /* check for inode tag permission */
2083 +       if (dx_permission(inode, MAY_WRITE))
2084 +               return -EACCES;
2085 +
2086         return 0;
2087  }
2088  EXPORT_SYMBOL(inode_change_ok);
2089 @@ -143,6 +150,8 @@ void setattr_copy(struct inode *inode, c
2090                 inode->i_uid = attr->ia_uid;
2091         if (ia_valid & ATTR_GID)
2092                 inode->i_gid = attr->ia_gid;
2093 +       if ((ia_valid & ATTR_TAG) && IS_TAGGED(inode))
2094 +               inode->i_tag = attr->ia_tag;
2095         if (ia_valid & ATTR_ATIME)
2096                 inode->i_atime = timespec_trunc(attr->ia_atime,
2097                                                 inode->i_sb->s_time_gran);
2098 @@ -170,7 +179,8 @@ int notify_change(struct dentry * dentry
2099         struct timespec now;
2100         unsigned int ia_valid = attr->ia_valid;
2101  
2102 -       if (ia_valid & (ATTR_MODE | ATTR_UID | ATTR_GID | ATTR_TIMES_SET)) {
2103 +       if (ia_valid & (ATTR_MODE | ATTR_UID | ATTR_GID |
2104 +               ATTR_TAG | ATTR_TIMES_SET)) {
2105                 if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
2106                         return -EPERM;
2107         }
2108 diff -NurpP --minimal linux-2.6.38-rc8/fs/binfmt_aout.c linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/binfmt_aout.c
2109 --- linux-2.6.38-rc8/fs/binfmt_aout.c   2010-10-21 13:07:47.000000000 +0200
2110 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/binfmt_aout.c    2011-01-29 02:01:07.000000000 +0100
2111 @@ -25,6 +25,7 @@
2112  #include <linux/init.h>
2113  #include <linux/coredump.h>
2114  #include <linux/slab.h>
2115 +#include <linux/vs_memory.h>
2116  
2117  #include <asm/system.h>
2118  #include <asm/uaccess.h>
2119 diff -NurpP --minimal linux-2.6.38-rc8/fs/binfmt_elf.c linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/binfmt_elf.c
2120 --- linux-2.6.38-rc8/fs/binfmt_elf.c    2011-03-10 17:09:21.000000000 +0100
2121 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/binfmt_elf.c     2011-01-29 02:01:07.000000000 +0100
2122 @@ -32,6 +32,7 @@
2123  #include <linux/elf.h>
2124  #include <linux/utsname.h>
2125  #include <linux/coredump.h>
2126 +#include <linux/vs_memory.h>
2127  #include <asm/uaccess.h>
2128  #include <asm/param.h>
2129  #include <asm/page.h>
2130 diff -NurpP --minimal linux-2.6.38-rc8/fs/binfmt_flat.c linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/binfmt_flat.c
2131 --- linux-2.6.38-rc8/fs/binfmt_flat.c   2010-08-02 16:52:47.000000000 +0200
2132 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/binfmt_flat.c    2011-01-29 02:01:07.000000000 +0100
2133 @@ -35,6 +35,7 @@
2134  #include <linux/init.h>
2135  #include <linux/flat.h>
2136  #include <linux/syscalls.h>
2137 +#include <linux/vs_memory.h>
2138  
2139  #include <asm/byteorder.h>
2140  #include <asm/system.h>
2141 diff -NurpP --minimal linux-2.6.38-rc8/fs/binfmt_som.c linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/binfmt_som.c
2142 --- linux-2.6.38-rc8/fs/binfmt_som.c    2010-02-25 11:52:04.000000000 +0100
2143 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/binfmt_som.c     2011-01-29 02:01:07.000000000 +0100
2144 @@ -28,6 +28,7 @@
2145  #include <linux/shm.h>
2146  #include <linux/personality.h>
2147  #include <linux/init.h>
2148 +#include <linux/vs_memory.h>
2149  
2150  #include <asm/uaccess.h>
2151  #include <asm/pgtable.h>
2152 diff -NurpP --minimal linux-2.6.38-rc8/fs/block_dev.c linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/block_dev.c
2153 --- linux-2.6.38-rc8/fs/block_dev.c     2011-03-10 17:09:22.000000000 +0100
2154 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/block_dev.c      2011-03-07 16:53:27.000000000 +0100
2155 @@ -25,6 +25,7 @@
2156  #include <linux/namei.h>
2157  #include <linux/log2.h>
2158  #include <linux/kmemleak.h>
2159 +#include <linux/vs_device.h>
2160  #include <asm/uaccess.h>
2161  #include "internal.h"
2162  
2163 @@ -551,6 +552,7 @@ struct block_device *bdget(dev_t dev)
2164                 bdev->bd_invalidated = 0;
2165                 inode->i_mode = S_IFBLK;
2166                 inode->i_rdev = dev;
2167 +               inode->i_mdev = dev;
2168                 inode->i_bdev = bdev;
2169                 inode->i_data.a_ops = &def_blk_aops;
2170                 mapping_set_gfp_mask(&inode->i_data, GFP_USER);
2171 @@ -597,6 +599,11 @@ EXPORT_SYMBOL(bdput);
2172  static struct block_device *bd_acquire(struct inode *inode)
2173  {
2174         struct block_device *bdev;
2175 +       dev_t mdev;
2176 +
2177 +       if (!vs_map_blkdev(inode->i_rdev, &mdev, DATTR_OPEN))
2178 +               return NULL;
2179 +       inode->i_mdev = mdev;
2180  
2181         spin_lock(&bdev_lock);
2182         bdev = inode->i_bdev;
2183 @@ -607,7 +614,7 @@ static struct block_device *bd_acquire(s
2184         }
2185         spin_unlock(&bdev_lock);
2186  
2187 -       bdev = bdget(inode->i_rdev);
2188 +       bdev = bdget(mdev);
2189         if (bdev) {
2190                 spin_lock(&bdev_lock);
2191                 if (!inode->i_bdev) {
2192 diff -NurpP --minimal linux-2.6.38-rc8/fs/btrfs/ctree.h linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/btrfs/ctree.h
2193 --- linux-2.6.38-rc8/fs/btrfs/ctree.h   2011-03-10 17:09:22.000000000 +0100
2194 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/btrfs/ctree.h    2011-03-07 16:53:27.000000000 +0100
2195 @@ -587,11 +587,14 @@ struct btrfs_inode_item {
2196         /* modification sequence number for NFS */
2197         __le64 sequence;
2198  
2199 +       __le16 tag;
2200         /*
2201          * a little future expansion, for more than this we can
2202          * just grow the inode item and version it
2203          */
2204 -       __le64 reserved[4];
2205 +       __le16 reserved16;
2206 +       __le32 reserved32;
2207 +       __le64 reserved[3];
2208         struct btrfs_timespec atime;
2209         struct btrfs_timespec ctime;
2210         struct btrfs_timespec mtime;
2211 @@ -1256,6 +1259,8 @@ struct btrfs_root {
2212  #define BTRFS_MOUNT_USER_SUBVOL_RM_ALLOWED (1 << 14)
2213  #define BTRFS_MOUNT_ENOSPC_DEBUG        (1 << 15)
2214  
2215 +#define BTRFS_MOUNT_TAGGED             (1 << 24)
2216 +
2217  #define btrfs_clear_opt(o, opt)                ((o) &= ~BTRFS_MOUNT_##opt)
2218  #define btrfs_set_opt(o, opt)          ((o) |= BTRFS_MOUNT_##opt)
2219  #define btrfs_test_opt(root, opt)      ((root)->fs_info->mount_opt & \
2220 @@ -1476,6 +1481,7 @@ BTRFS_SETGET_FUNCS(inode_block_group, st
2221  BTRFS_SETGET_FUNCS(inode_nlink, struct btrfs_inode_item, nlink, 32);
2222  BTRFS_SETGET_FUNCS(inode_uid, struct btrfs_inode_item, uid, 32);
2223  BTRFS_SETGET_FUNCS(inode_gid, struct btrfs_inode_item, gid, 32);
2224 +BTRFS_SETGET_FUNCS(inode_tag, struct btrfs_inode_item, tag, 16);
2225  BTRFS_SETGET_FUNCS(inode_mode, struct btrfs_inode_item, mode, 32);
2226  BTRFS_SETGET_FUNCS(inode_rdev, struct btrfs_inode_item, rdev, 64);
2227  BTRFS_SETGET_FUNCS(inode_flags, struct btrfs_inode_item, flags, 64);
2228 @@ -1537,6 +1543,10 @@ BTRFS_SETGET_FUNCS(extent_flags, struct 
2229  
2230  BTRFS_SETGET_FUNCS(extent_refs_v0, struct btrfs_extent_item_v0, refs, 32);
2231  
2232 +#define BTRFS_INODE_IXUNLINK           (1 << 24)
2233 +#define BTRFS_INODE_BARRIER            (1 << 25)
2234 +#define BTRFS_INODE_COW                        (1 << 26)
2235 +
2236  
2237  BTRFS_SETGET_FUNCS(tree_block_level, struct btrfs_tree_block_info, level, 8);
2238  
2239 @@ -2544,6 +2554,7 @@ extern const struct dentry_operations bt
2240  long btrfs_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
2241  void btrfs_update_iflags(struct inode *inode);
2242  void btrfs_inherit_iflags(struct inode *inode, struct inode *dir);
2243 +int btrfs_sync_flags(struct inode *inode, int, int);
2244  
2245  /* file.c */
2246  int btrfs_sync_file(struct file *file, int datasync);
2247 diff -NurpP --minimal linux-2.6.38-rc8/fs/btrfs/disk-io.c linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/btrfs/disk-io.c
2248 --- linux-2.6.38-rc8/fs/btrfs/disk-io.c 2011-03-10 17:09:22.000000000 +0100
2249 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/btrfs/disk-io.c  2011-02-17 02:17:50.000000000 +0100
2250 @@ -1768,6 +1768,9 @@ struct btrfs_root *open_ctree(struct sup
2251                 goto fail_iput;
2252         }
2253  
2254 +       if (btrfs_test_opt(tree_root, TAGGED))
2255 +               sb->s_flags |= MS_TAGGED;
2256 +
2257         features = btrfs_super_incompat_flags(disk_super) &
2258                 ~BTRFS_FEATURE_INCOMPAT_SUPP;
2259         if (features) {
2260 diff -NurpP --minimal linux-2.6.38-rc8/fs/btrfs/inode.c linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/btrfs/inode.c
2261 --- linux-2.6.38-rc8/fs/btrfs/inode.c   2011-03-10 17:09:22.000000000 +0100
2262 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/btrfs/inode.c    2011-03-07 16:53:27.000000000 +0100
2263 @@ -37,6 +37,8 @@
2264  #include <linux/posix_acl.h>
2265  #include <linux/falloc.h>
2266  #include <linux/slab.h>
2267 +#include <linux/vs_tag.h>
2268 +
2269  #include "compat.h"
2270  #include "ctree.h"
2271  #include "disk-io.h"
2272 @@ -2463,6 +2465,8 @@ static void btrfs_read_locked_inode(stru
2273         int maybe_acls;
2274         u64 alloc_group_block;
2275         u32 rdev;
2276 +       uid_t uid;
2277 +       gid_t gid;
2278         int ret;
2279  
2280         path = btrfs_alloc_path();
2281 @@ -2479,8 +2483,13 @@ static void btrfs_read_locked_inode(stru
2282  
2283         inode->i_mode = btrfs_inode_mode(leaf, inode_item);
2284         inode->i_nlink = btrfs_inode_nlink(leaf, inode_item);
2285 -       inode->i_uid = btrfs_inode_uid(leaf, inode_item);
2286 -       inode->i_gid = btrfs_inode_gid(leaf, inode_item);
2287 +
2288 +       uid = btrfs_inode_uid(leaf, inode_item);
2289 +       gid = btrfs_inode_gid(leaf, inode_item);
2290 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
2291 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
2292 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid,
2293 +               btrfs_inode_tag(leaf, inode_item));
2294         btrfs_i_size_write(inode, btrfs_inode_size(leaf, inode_item));
2295  
2296         tspec = btrfs_inode_atime(inode_item);
2297 @@ -2562,8 +2571,15 @@ static void fill_inode_item(struct btrfs
2298                             struct btrfs_inode_item *item,
2299                             struct inode *inode)
2300  {
2301 -       btrfs_set_inode_uid(leaf, item, inode->i_uid);
2302 -       btrfs_set_inode_gid(leaf, item, inode->i_gid);
2303 +       uid_t uid = TAGINO_UID(DX_TAG(inode), inode->i_uid, inode->i_tag);
2304 +       gid_t gid = TAGINO_GID(DX_TAG(inode), inode->i_gid, inode->i_tag);
2305 +
2306 +       btrfs_set_inode_uid(leaf, item, uid);
2307 +       btrfs_set_inode_gid(leaf, item, gid);
2308 +#ifdef CONFIG_TAGGING_INTERN
2309 +       btrfs_set_inode_tag(leaf, item, inode->i_tag);
2310 +#endif
2311 +
2312         btrfs_set_inode_size(leaf, item, BTRFS_I(inode)->disk_i_size);
2313         btrfs_set_inode_mode(leaf, item, inode->i_mode);
2314         btrfs_set_inode_nlink(leaf, item, inode->i_nlink);
2315 @@ -7291,6 +7307,7 @@ static const struct inode_operations btr
2316         .listxattr      = btrfs_listxattr,
2317         .removexattr    = btrfs_removexattr,
2318         .permission     = btrfs_permission,
2319 +       .sync_flags     = btrfs_sync_flags,
2320  };
2321  static const struct inode_operations btrfs_dir_ro_inode_operations = {
2322         .lookup         = btrfs_lookup,
2323 @@ -7365,6 +7382,7 @@ static const struct inode_operations btr
2324         .removexattr    = btrfs_removexattr,
2325         .permission     = btrfs_permission,
2326         .fiemap         = btrfs_fiemap,
2327 +       .sync_flags     = btrfs_sync_flags,
2328  };
2329  static const struct inode_operations btrfs_special_inode_operations = {
2330         .getattr        = btrfs_getattr,
2331 diff -NurpP --minimal linux-2.6.38-rc8/fs/btrfs/ioctl.c linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/btrfs/ioctl.c
2332 --- linux-2.6.38-rc8/fs/btrfs/ioctl.c   2011-03-10 17:09:22.000000000 +0100
2333 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/btrfs/ioctl.c    2011-03-07 16:53:27.000000000 +0100
2334 @@ -68,10 +68,13 @@ static unsigned int btrfs_flags_to_ioctl
2335  {
2336         unsigned int iflags = 0;
2337  
2338 -       if (flags & BTRFS_INODE_SYNC)
2339 -               iflags |= FS_SYNC_FL;
2340         if (flags & BTRFS_INODE_IMMUTABLE)
2341                 iflags |= FS_IMMUTABLE_FL;
2342 +       if (flags & BTRFS_INODE_IXUNLINK)
2343 +               iflags |= FS_IXUNLINK_FL;
2344 +
2345 +       if (flags & BTRFS_INODE_SYNC)
2346 +               iflags |= FS_SYNC_FL;
2347         if (flags & BTRFS_INODE_APPEND)
2348                 iflags |= FS_APPEND_FL;
2349         if (flags & BTRFS_INODE_NODUMP)
2350 @@ -81,28 +84,78 @@ static unsigned int btrfs_flags_to_ioctl
2351         if (flags & BTRFS_INODE_DIRSYNC)
2352                 iflags |= FS_DIRSYNC_FL;
2353  
2354 +       if (flags & BTRFS_INODE_BARRIER)
2355 +               iflags |= FS_BARRIER_FL;
2356 +       if (flags & BTRFS_INODE_COW)
2357 +               iflags |= FS_COW_FL;
2358         return iflags;
2359  }
2360  
2361  /*
2362 - * Update inode->i_flags based on the btrfs internal flags.
2363 + * Update inode->i_(v)flags based on the btrfs internal flags.
2364   */
2365  void btrfs_update_iflags(struct inode *inode)
2366  {
2367         struct btrfs_inode *ip = BTRFS_I(inode);
2368  
2369 -       inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
2370 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
2371 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
2372  
2373 -       if (ip->flags & BTRFS_INODE_SYNC)
2374 -               inode->i_flags |= S_SYNC;
2375         if (ip->flags & BTRFS_INODE_IMMUTABLE)
2376                 inode->i_flags |= S_IMMUTABLE;
2377 +       if (ip->flags & BTRFS_INODE_IXUNLINK)
2378 +               inode->i_flags |= S_IXUNLINK;
2379 +
2380 +       if (ip->flags & BTRFS_INODE_SYNC)
2381 +               inode->i_flags |= S_SYNC;
2382         if (ip->flags & BTRFS_INODE_APPEND)
2383                 inode->i_flags |= S_APPEND;
2384         if (ip->flags & BTRFS_INODE_NOATIME)
2385                 inode->i_flags |= S_NOATIME;
2386         if (ip->flags & BTRFS_INODE_DIRSYNC)
2387                 inode->i_flags |= S_DIRSYNC;
2388 +
2389 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
2390 +
2391 +       if (ip->flags & BTRFS_INODE_BARRIER)
2392 +               inode->i_vflags |= V_BARRIER;
2393 +       if (ip->flags & BTRFS_INODE_COW)
2394 +               inode->i_vflags |= V_COW;
2395 +}
2396 +
2397 +/*
2398 + * Update btrfs internal flags from inode->i_(v)flags.
2399 + */
2400 +void btrfs_update_flags(struct inode *inode)
2401 +{
2402 +       struct btrfs_inode *ip = BTRFS_I(inode);
2403 +
2404 +       unsigned int flags = inode->i_flags;
2405 +       unsigned int vflags = inode->i_vflags;
2406 +
2407 +       ip->flags &= ~(BTRFS_INODE_SYNC | BTRFS_INODE_APPEND |
2408 +                       BTRFS_INODE_IMMUTABLE | BTRFS_INODE_IXUNLINK |
2409 +                       BTRFS_INODE_NOATIME | BTRFS_INODE_DIRSYNC |
2410 +                       BTRFS_INODE_BARRIER | BTRFS_INODE_COW);
2411 +
2412 +       if (flags & S_IMMUTABLE)
2413 +               ip->flags |= BTRFS_INODE_IMMUTABLE;
2414 +       if (flags & S_IXUNLINK)
2415 +               ip->flags |= BTRFS_INODE_IXUNLINK;
2416 +
2417 +       if (flags & S_SYNC)
2418 +               ip->flags |= BTRFS_INODE_SYNC;
2419 +       if (flags & S_APPEND)
2420 +               ip->flags |= BTRFS_INODE_APPEND;
2421 +       if (flags & S_NOATIME)
2422 +               ip->flags |= BTRFS_INODE_NOATIME;
2423 +       if (flags & S_DIRSYNC)
2424 +               ip->flags |= BTRFS_INODE_DIRSYNC;
2425 +
2426 +       if (vflags & V_BARRIER)
2427 +               ip->flags |= BTRFS_INODE_BARRIER;
2428 +       if (vflags & V_COW)
2429 +               ip->flags |= BTRFS_INODE_COW;
2430  }
2431  
2432  /*
2433 @@ -120,7 +173,7 @@ void btrfs_inherit_iflags(struct inode *
2434         flags = BTRFS_I(dir)->flags;
2435  
2436         if (S_ISREG(inode->i_mode))
2437 -               flags &= ~BTRFS_INODE_DIRSYNC;
2438 +               flags &= ~(BTRFS_INODE_DIRSYNC | BTRFS_INODE_BARRIER);
2439         else if (!S_ISDIR(inode->i_mode))
2440                 flags &= (BTRFS_INODE_NODUMP | BTRFS_INODE_NOATIME);
2441  
2442 @@ -128,6 +181,30 @@ void btrfs_inherit_iflags(struct inode *
2443         btrfs_update_iflags(inode);
2444  }
2445  
2446 +int btrfs_sync_flags(struct inode *inode, int flags, int vflags)
2447 +{
2448 +       struct btrfs_inode *ip = BTRFS_I(inode);
2449 +       struct btrfs_root *root = ip->root;
2450 +       struct btrfs_trans_handle *trans;
2451 +       int ret;
2452 +
2453 +       trans = btrfs_join_transaction(root, 1);
2454 +       BUG_ON(!trans);
2455 +
2456 +       inode->i_flags = flags;
2457 +       inode->i_vflags = vflags;
2458 +       btrfs_update_flags(inode);
2459 +
2460 +       ret = btrfs_update_inode(trans, root, inode);
2461 +       BUG_ON(ret);
2462 +
2463 +       btrfs_update_iflags(inode);
2464 +       inode->i_ctime = CURRENT_TIME;
2465 +       btrfs_end_transaction(trans, root);
2466 +
2467 +       return 0;
2468 +}
2469 +
2470  static int btrfs_ioctl_getflags(struct file *file, void __user *arg)
2471  {
2472         struct btrfs_inode *ip = BTRFS_I(file->f_path.dentry->d_inode);
2473 @@ -153,6 +230,7 @@ static int btrfs_ioctl_setflags(struct f
2474         if (copy_from_user(&flags, arg, sizeof(flags)))
2475                 return -EFAULT;
2476  
2477 +       /* maybe add FS_IXUNLINK_FL ? */
2478         if (flags & ~(FS_IMMUTABLE_FL | FS_APPEND_FL | \
2479                       FS_NOATIME_FL | FS_NODUMP_FL | \
2480                       FS_SYNC_FL | FS_DIRSYNC_FL))
2481 @@ -165,7 +243,8 @@ static int btrfs_ioctl_setflags(struct f
2482  
2483         flags = btrfs_mask_flags(inode->i_mode, flags);
2484         oldflags = btrfs_flags_to_ioctl(ip->flags);
2485 -       if ((flags ^ oldflags) & (FS_APPEND_FL | FS_IMMUTABLE_FL)) {
2486 +       if ((flags ^ oldflags) & (FS_APPEND_FL |
2487 +               FS_IMMUTABLE_FL | FS_IXUNLINK_FL)) {
2488                 if (!capable(CAP_LINUX_IMMUTABLE)) {
2489                         ret = -EPERM;
2490                         goto out_unlock;
2491 @@ -176,14 +255,19 @@ static int btrfs_ioctl_setflags(struct f
2492         if (ret)
2493                 goto out_unlock;
2494  
2495 -       if (flags & FS_SYNC_FL)
2496 -               ip->flags |= BTRFS_INODE_SYNC;
2497 -       else
2498 -               ip->flags &= ~BTRFS_INODE_SYNC;
2499         if (flags & FS_IMMUTABLE_FL)
2500                 ip->flags |= BTRFS_INODE_IMMUTABLE;
2501         else
2502                 ip->flags &= ~BTRFS_INODE_IMMUTABLE;
2503 +       if (flags & FS_IXUNLINK_FL)
2504 +               ip->flags |= BTRFS_INODE_IXUNLINK;
2505 +       else
2506 +               ip->flags &= ~BTRFS_INODE_IXUNLINK;
2507 +
2508 +       if (flags & FS_SYNC_FL)
2509 +               ip->flags |= BTRFS_INODE_SYNC;
2510 +       else
2511 +               ip->flags &= ~BTRFS_INODE_SYNC;
2512         if (flags & FS_APPEND_FL)
2513                 ip->flags |= BTRFS_INODE_APPEND;
2514         else
2515 diff -NurpP --minimal linux-2.6.38-rc8/fs/btrfs/super.c linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/btrfs/super.c
2516 --- linux-2.6.38-rc8/fs/btrfs/super.c   2011-03-10 17:09:22.000000000 +0100
2517 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/btrfs/super.c    2011-03-07 17:04:18.000000000 +0100
2518 @@ -155,8 +155,8 @@ enum {
2519         Opt_nossd, Opt_ssd_spread, Opt_thread_pool, Opt_noacl, Opt_compress,
2520         Opt_compress_type, Opt_compress_force, Opt_compress_force_type,
2521         Opt_notreelog, Opt_ratio, Opt_flushoncommit, Opt_discard,
2522 -       Opt_space_cache, Opt_clear_cache, Opt_user_subvol_rm_allowed,
2523 -       Opt_enospc_debug, Opt_err,
2524 +       Opt_space_cache, Opt_clear_cache, Opt_user_subvol_rm_allowed,
2525 +       Opt_enospc_debug, Opt_tag, Opt_notag, Opt_tagid, Opt_err,
2526  };
2527  
2528  static match_table_t tokens = {
2529 @@ -186,6 +186,9 @@ static match_table_t tokens = {
2530         {Opt_clear_cache, "clear_cache"},
2531         {Opt_user_subvol_rm_allowed, "user_subvol_rm_allowed"},
2532         {Opt_enospc_debug, "enospc_debug"},
2533 +       {Opt_tag, "tag"},
2534 +       {Opt_notag, "notag"},
2535 +       {Opt_tagid, "tagid=%u"},
2536         {Opt_err, NULL},
2537  };
2538  
2539 @@ -363,6 +366,22 @@ int btrfs_parse_options(struct btrfs_roo
2540                 case Opt_enospc_debug:
2541                         btrfs_set_opt(info->mount_opt, ENOSPC_DEBUG);
2542                         break;
2543 +#ifndef CONFIG_TAGGING_NONE
2544 +               case Opt_tag:
2545 +                       printk(KERN_INFO "btrfs: use tagging\n");
2546 +                       btrfs_set_opt(info->mount_opt, TAGGED);
2547 +                       break;
2548 +               case Opt_notag:
2549 +                       printk(KERN_INFO "btrfs: disabled tagging\n");
2550 +                       btrfs_clear_opt(info->mount_opt, TAGGED);
2551 +                       break;
2552 +#endif
2553 +#ifdef CONFIG_PROPAGATE
2554 +               case Opt_tagid:
2555 +                       /* use args[0] */
2556 +                       btrfs_set_opt(info->mount_opt, TAGGED);
2557 +                       break;
2558 +#endif
2559                 case Opt_err:
2560                         printk(KERN_INFO "btrfs: unrecognized mount option "
2561                                "'%s'\n", p);
2562 @@ -841,6 +860,12 @@ static int btrfs_remount(struct super_bl
2563         if (ret)
2564                 return -EINVAL;
2565  
2566 +       if (btrfs_test_opt(root, TAGGED) && !(sb->s_flags & MS_TAGGED)) {
2567 +               printk("btrfs: %s: tagging not permitted on remount.\n",
2568 +                       sb->s_id);
2569 +               return -EINVAL;
2570 +       }
2571 +
2572         if ((*flags & MS_RDONLY) == (sb->s_flags & MS_RDONLY))
2573                 return 0;
2574  
2575 diff -NurpP --minimal linux-2.6.38-rc8/fs/char_dev.c linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/char_dev.c
2576 --- linux-2.6.38-rc8/fs/char_dev.c      2011-03-10 17:09:22.000000000 +0100
2577 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/char_dev.c       2011-01-29 02:01:07.000000000 +0100
2578 @@ -21,6 +21,8 @@
2579  #include <linux/mutex.h>
2580  #include <linux/backing-dev.h>
2581  #include <linux/tty.h>
2582 +#include <linux/vs_context.h>
2583 +#include <linux/vs_device.h>
2584  
2585  #include "internal.h"
2586  
2587 @@ -371,14 +373,21 @@ static int chrdev_open(struct inode *ino
2588         struct cdev *p;
2589         struct cdev *new = NULL;
2590         int ret = 0;
2591 +       dev_t mdev;
2592 +
2593 +       if (!vs_map_chrdev(inode->i_rdev, &mdev, DATTR_OPEN))
2594 +               return -EPERM;
2595 +       inode->i_mdev = mdev;
2596  
2597         spin_lock(&cdev_lock);
2598         p = inode->i_cdev;
2599         if (!p) {
2600                 struct kobject *kobj;
2601                 int idx;
2602 +
2603                 spin_unlock(&cdev_lock);
2604 -               kobj = kobj_lookup(cdev_map, inode->i_rdev, &idx);
2605 +
2606 +               kobj = kobj_lookup(cdev_map, mdev, &idx);
2607                 if (!kobj)
2608                         return -ENXIO;
2609                 new = container_of(kobj, struct cdev, kobj);
2610 diff -NurpP --minimal linux-2.6.38-rc8/fs/dcache.c linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/dcache.c
2611 --- linux-2.6.38-rc8/fs/dcache.c        2011-03-10 17:09:22.000000000 +0100
2612 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/dcache.c 2011-02-02 22:20:25.000000000 +0100
2613 @@ -35,6 +35,7 @@
2614  #include <linux/hardirq.h>
2615  #include <linux/bit_spinlock.h>
2616  #include <linux/rculist_bl.h>
2617 +#include <linux/vs_limit.h>
2618  #include "internal.h"
2619  
2620  /*
2621 @@ -496,6 +497,8 @@ int d_invalidate(struct dentry * dentry)
2622                 spin_lock(&dentry->d_lock);
2623         }
2624  
2625 +       vx_dentry_dec(dentry);
2626 +
2627         /*
2628          * Somebody else still using it?
2629          *
2630 @@ -523,6 +526,7 @@ EXPORT_SYMBOL(d_invalidate);
2631  static inline void __dget_dlock(struct dentry *dentry)
2632  {
2633         dentry->d_count++;
2634 +       vx_dentry_inc(dentry);
2635  }
2636  
2637  static inline void __dget(struct dentry *dentry)
2638 @@ -1278,6 +1282,9 @@ struct dentry *d_alloc(struct dentry * p
2639         struct dentry *dentry;
2640         char *dname;
2641  
2642 +       if (!vx_dentry_avail(1))
2643 +               return NULL;
2644 +
2645         dentry = kmem_cache_alloc(dentry_cache, GFP_KERNEL);
2646         if (!dentry)
2647                 return NULL;
2648 @@ -1299,6 +1306,7 @@ struct dentry *d_alloc(struct dentry * p
2649         dname[name->len] = 0;
2650  
2651         dentry->d_count = 1;
2652 +       vx_dentry_inc(dentry);
2653         dentry->d_flags = DCACHE_UNHASHED;
2654         spin_lock_init(&dentry->d_lock);
2655         seqcount_init(&dentry->d_seq);
2656 @@ -1935,6 +1943,7 @@ struct dentry *__d_lookup(struct dentry 
2657                 }
2658  
2659                 dentry->d_count++;
2660 +               vx_dentry_inc(dentry);
2661                 found = dentry;
2662                 spin_unlock(&dentry->d_lock);
2663                 break;
2664 diff -NurpP --minimal linux-2.6.38-rc8/fs/devpts/inode.c linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/devpts/inode.c
2665 --- linux-2.6.38-rc8/fs/devpts/inode.c  2011-01-05 21:50:22.000000000 +0100
2666 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/devpts/inode.c   2011-01-29 05:09:48.000000000 +0100
2667 @@ -25,6 +25,7 @@
2668  #include <linux/parser.h>
2669  #include <linux/fsnotify.h>
2670  #include <linux/seq_file.h>
2671 +#include <linux/vs_base.h>
2672  
2673  #define DEVPTS_DEFAULT_MODE 0600
2674  /*
2675 @@ -36,6 +37,20 @@
2676  #define DEVPTS_DEFAULT_PTMX_MODE 0000
2677  #define PTMX_MINOR     2
2678  
2679 +static int devpts_permission(struct inode *inode, int mask, unsigned int flags)
2680 +{
2681 +       int ret = -EACCES;
2682 +
2683 +       /* devpts is xid tagged */
2684 +       if (vx_check((xid_t)inode->i_tag, VS_WATCH_P | VS_IDENT))
2685 +               ret = generic_permission(inode, mask, flags, NULL);
2686 +       return ret;
2687 +}
2688 +
2689 +static struct inode_operations devpts_file_inode_operations = {
2690 +       .permission     = devpts_permission,
2691 +};
2692 +
2693  extern int pty_limit;                  /* Config limit on Unix98 ptys */
2694  static DEFINE_MUTEX(allocated_ptys_lock);
2695  
2696 @@ -263,6 +278,25 @@ static int devpts_show_options(struct se
2697         return 0;
2698  }
2699  
2700 +static int devpts_filter(struct dentry *de)
2701 +{
2702 +       /* devpts is xid tagged */
2703 +       return vx_check((xid_t)de->d_inode->i_tag, VS_WATCH_P | VS_IDENT);
2704 +}
2705 +
2706 +static int devpts_readdir(struct file * filp, void * dirent, filldir_t filldir)
2707 +{
2708 +       return dcache_readdir_filter(filp, dirent, filldir, devpts_filter);
2709 +}
2710 +
2711 +static struct file_operations devpts_dir_operations = {
2712 +       .open           = dcache_dir_open,
2713 +       .release        = dcache_dir_close,
2714 +       .llseek         = dcache_dir_lseek,
2715 +       .read           = generic_read_dir,
2716 +       .readdir        = devpts_readdir,
2717 +};
2718 +
2719  static const struct super_operations devpts_sops = {
2720         .statfs         = simple_statfs,
2721         .remount_fs     = devpts_remount,
2722 @@ -302,12 +336,15 @@ devpts_fill_super(struct super_block *s,
2723         inode = new_inode(s);
2724         if (!inode)
2725                 goto free_fsi;
2726 +
2727         inode->i_ino = 1;
2728         inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
2729         inode->i_mode = S_IFDIR | S_IRUGO | S_IXUGO | S_IWUSR;
2730         inode->i_op = &simple_dir_inode_operations;
2731 -       inode->i_fop = &simple_dir_operations;
2732 +       inode->i_fop = &devpts_dir_operations;
2733         inode->i_nlink = 2;
2734 +       /* devpts is xid tagged */
2735 +       inode->i_tag = (tag_t)vx_current_xid();
2736  
2737         s->s_root = d_alloc_root(inode);
2738         if (s->s_root)
2739 @@ -493,6 +530,9 @@ int devpts_pty_new(struct inode *ptmx_in
2740         inode->i_gid = opts->setgid ? opts->gid : current_fsgid();
2741         inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
2742         init_special_inode(inode, S_IFCHR|opts->mode, device);
2743 +       /* devpts is xid tagged */
2744 +       inode->i_tag = (tag_t)vx_current_xid();
2745 +       inode->i_op = &devpts_file_inode_operations;
2746         inode->i_private = tty;
2747         tty->driver_data = inode;
2748  
2749 diff -NurpP --minimal linux-2.6.38-rc8/fs/ext2/balloc.c linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/ext2/balloc.c
2750 --- linux-2.6.38-rc8/fs/ext2/balloc.c   2011-01-05 21:50:22.000000000 +0100
2751 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/ext2/balloc.c    2011-01-29 02:01:07.000000000 +0100
2752 @@ -701,7 +701,6 @@ ext2_try_to_allocate(struct super_block 
2753                         start = 0;
2754                 end = EXT2_BLOCKS_PER_GROUP(sb);
2755         }
2756 -
2757         BUG_ON(start > EXT2_BLOCKS_PER_GROUP(sb));
2758  
2759  repeat:
2760 diff -NurpP --minimal linux-2.6.38-rc8/fs/ext2/ext2.h linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/ext2/ext2.h
2761 --- linux-2.6.38-rc8/fs/ext2/ext2.h     2011-01-05 21:50:22.000000000 +0100
2762 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/ext2/ext2.h      2011-01-29 02:01:07.000000000 +0100
2763 @@ -126,6 +126,7 @@ extern void ext2_set_inode_flags(struct 
2764  extern void ext2_get_inode_flags(struct ext2_inode_info *);
2765  extern int ext2_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
2766                        u64 start, u64 len);
2767 +extern int ext2_sync_flags(struct inode *, int, int);
2768  
2769  /* ioctl.c */
2770  extern long ext2_ioctl(struct file *, unsigned int, unsigned long);
2771 diff -NurpP --minimal linux-2.6.38-rc8/fs/ext2/file.c linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/ext2/file.c
2772 --- linux-2.6.38-rc8/fs/ext2/file.c     2010-08-02 16:52:48.000000000 +0200
2773 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/ext2/file.c      2011-01-29 02:01:07.000000000 +0100
2774 @@ -104,4 +104,5 @@ const struct inode_operations ext2_file_
2775         .setattr        = ext2_setattr,
2776         .check_acl      = ext2_check_acl,
2777         .fiemap         = ext2_fiemap,
2778 +       .sync_flags     = ext2_sync_flags,
2779  };
2780 diff -NurpP --minimal linux-2.6.38-rc8/fs/ext2/ialloc.c linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/ext2/ialloc.c
2781 --- linux-2.6.38-rc8/fs/ext2/ialloc.c   2010-10-21 13:07:48.000000000 +0200
2782 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/ext2/ialloc.c    2011-01-29 02:01:07.000000000 +0100
2783 @@ -17,6 +17,7 @@
2784  #include <linux/backing-dev.h>
2785  #include <linux/buffer_head.h>
2786  #include <linux/random.h>
2787 +#include <linux/vs_tag.h>
2788  #include "ext2.h"
2789  #include "xattr.h"
2790  #include "acl.h"
2791 @@ -548,6 +549,7 @@ got:
2792                 inode->i_mode = mode;
2793                 inode->i_uid = current_fsuid();
2794                 inode->i_gid = dir->i_gid;
2795 +               inode->i_tag = dx_current_fstag(sb);
2796         } else
2797                 inode_init_owner(inode, dir, mode);
2798  
2799 diff -NurpP --minimal linux-2.6.38-rc8/fs/ext2/inode.c linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/ext2/inode.c
2800 --- linux-2.6.38-rc8/fs/ext2/inode.c    2011-01-05 21:50:22.000000000 +0100
2801 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/ext2/inode.c     2011-01-29 02:01:07.000000000 +0100
2802 @@ -32,6 +32,7 @@
2803  #include <linux/mpage.h>
2804  #include <linux/fiemap.h>
2805  #include <linux/namei.h>
2806 +#include <linux/vs_tag.h>
2807  #include "ext2.h"
2808  #include "acl.h"
2809  #include "xip.h"
2810 @@ -1169,7 +1170,7 @@ static void ext2_truncate_blocks(struct 
2811                 return;
2812         if (ext2_inode_is_fast_symlink(inode))
2813                 return;
2814 -       if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
2815 +       if (IS_APPEND(inode) || IS_IXORUNLINK(inode))
2816                 return;
2817         __ext2_truncate_blocks(inode, offset);
2818  }
2819 @@ -1258,36 +1259,61 @@ void ext2_set_inode_flags(struct inode *
2820  {
2821         unsigned int flags = EXT2_I(inode)->i_flags;
2822  
2823 -       inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
2824 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
2825 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
2826 +
2827 +
2828 +       if (flags & EXT2_IMMUTABLE_FL)
2829 +               inode->i_flags |= S_IMMUTABLE;
2830 +       if (flags & EXT2_IXUNLINK_FL)
2831 +               inode->i_flags |= S_IXUNLINK;
2832 +
2833         if (flags & EXT2_SYNC_FL)
2834                 inode->i_flags |= S_SYNC;
2835         if (flags & EXT2_APPEND_FL)
2836                 inode->i_flags |= S_APPEND;
2837 -       if (flags & EXT2_IMMUTABLE_FL)
2838 -               inode->i_flags |= S_IMMUTABLE;
2839         if (flags & EXT2_NOATIME_FL)
2840                 inode->i_flags |= S_NOATIME;
2841         if (flags & EXT2_DIRSYNC_FL)
2842                 inode->i_flags |= S_DIRSYNC;
2843 +
2844 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
2845 +
2846 +       if (flags & EXT2_BARRIER_FL)
2847 +               inode->i_vflags |= V_BARRIER;
2848 +       if (flags & EXT2_COW_FL)
2849 +               inode->i_vflags |= V_COW;
2850  }
2851  
2852  /* Propagate flags from i_flags to EXT2_I(inode)->i_flags */
2853  void ext2_get_inode_flags(struct ext2_inode_info *ei)
2854  {
2855         unsigned int flags = ei->vfs_inode.i_flags;
2856 +       unsigned int vflags = ei->vfs_inode.i_vflags;
2857 +
2858 +       ei->i_flags &= ~(EXT2_SYNC_FL | EXT2_APPEND_FL |
2859 +                       EXT2_IMMUTABLE_FL | EXT2_IXUNLINK_FL |
2860 +                       EXT2_NOATIME_FL | EXT2_DIRSYNC_FL |
2861 +                       EXT2_BARRIER_FL | EXT2_COW_FL);
2862 +
2863 +       if (flags & S_IMMUTABLE)
2864 +               ei->i_flags |= EXT2_IMMUTABLE_FL;
2865 +       if (flags & S_IXUNLINK)
2866 +               ei->i_flags |= EXT2_IXUNLINK_FL;
2867  
2868 -       ei->i_flags &= ~(EXT2_SYNC_FL|EXT2_APPEND_FL|
2869 -                       EXT2_IMMUTABLE_FL|EXT2_NOATIME_FL|EXT2_DIRSYNC_FL);
2870         if (flags & S_SYNC)
2871                 ei->i_flags |= EXT2_SYNC_FL;
2872         if (flags & S_APPEND)
2873                 ei->i_flags |= EXT2_APPEND_FL;
2874 -       if (flags & S_IMMUTABLE)
2875 -               ei->i_flags |= EXT2_IMMUTABLE_FL;
2876         if (flags & S_NOATIME)
2877                 ei->i_flags |= EXT2_NOATIME_FL;
2878         if (flags & S_DIRSYNC)
2879                 ei->i_flags |= EXT2_DIRSYNC_FL;
2880 +
2881 +       if (vflags & V_BARRIER)
2882 +               ei->i_flags |= EXT2_BARRIER_FL;
2883 +       if (vflags & V_COW)
2884 +               ei->i_flags |= EXT2_COW_FL;
2885  }
2886  
2887  struct inode *ext2_iget (struct super_block *sb, unsigned long ino)
2888 @@ -1297,6 +1323,8 @@ struct inode *ext2_iget (struct super_bl
2889         struct ext2_inode *raw_inode;
2890         struct inode *inode;
2891         long ret = -EIO;
2892 +       uid_t uid;
2893 +       gid_t gid;
2894         int n;
2895  
2896         inode = iget_locked(sb, ino);
2897 @@ -1315,12 +1343,17 @@ struct inode *ext2_iget (struct super_bl
2898         }
2899  
2900         inode->i_mode = le16_to_cpu(raw_inode->i_mode);
2901 -       inode->i_uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
2902 -       inode->i_gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
2903 +       uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
2904 +       gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
2905         if (!(test_opt (inode->i_sb, NO_UID32))) {
2906 -               inode->i_uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
2907 -               inode->i_gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
2908 +               uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
2909 +               gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
2910         }
2911 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
2912 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
2913 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid,
2914 +               le16_to_cpu(raw_inode->i_raw_tag));
2915 +
2916         inode->i_nlink = le16_to_cpu(raw_inode->i_links_count);
2917         inode->i_size = le32_to_cpu(raw_inode->i_size);
2918         inode->i_atime.tv_sec = (signed)le32_to_cpu(raw_inode->i_atime);
2919 @@ -1418,8 +1451,8 @@ static int __ext2_write_inode(struct ino
2920         struct ext2_inode_info *ei = EXT2_I(inode);
2921         struct super_block *sb = inode->i_sb;
2922         ino_t ino = inode->i_ino;
2923 -       uid_t uid = inode->i_uid;
2924 -       gid_t gid = inode->i_gid;
2925 +       uid_t uid = TAGINO_UID(DX_TAG(inode), inode->i_uid, inode->i_tag);
2926 +       gid_t gid = TAGINO_GID(DX_TAG(inode), inode->i_gid, inode->i_tag);
2927         struct buffer_head * bh;
2928         struct ext2_inode * raw_inode = ext2_get_inode(sb, ino, &bh);
2929         int n;
2930 @@ -1455,6 +1488,9 @@ static int __ext2_write_inode(struct ino
2931                 raw_inode->i_uid_high = 0;
2932                 raw_inode->i_gid_high = 0;
2933         }
2934 +#ifdef CONFIG_TAGGING_INTERN
2935 +       raw_inode->i_raw_tag = cpu_to_le16(inode->i_tag);
2936 +#endif
2937         raw_inode->i_links_count = cpu_to_le16(inode->i_nlink);
2938         raw_inode->i_size = cpu_to_le32(inode->i_size);
2939         raw_inode->i_atime = cpu_to_le32(inode->i_atime.tv_sec);
2940 @@ -1535,7 +1571,8 @@ int ext2_setattr(struct dentry *dentry, 
2941         if (is_quota_modification(inode, iattr))
2942                 dquot_initialize(inode);
2943         if ((iattr->ia_valid & ATTR_UID && iattr->ia_uid != inode->i_uid) ||
2944 -           (iattr->ia_valid & ATTR_GID && iattr->ia_gid != inode->i_gid)) {
2945 +           (iattr->ia_valid & ATTR_GID && iattr->ia_gid != inode->i_gid) ||
2946 +           (iattr->ia_valid & ATTR_TAG && iattr->ia_tag != inode->i_tag)) {
2947                 error = dquot_transfer(inode, iattr);
2948                 if (error)
2949                         return error;
2950 diff -NurpP --minimal linux-2.6.38-rc8/fs/ext2/ioctl.c linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/ext2/ioctl.c
2951 --- linux-2.6.38-rc8/fs/ext2/ioctl.c    2009-09-10 15:26:21.000000000 +0200
2952 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/ext2/ioctl.c     2011-01-29 02:01:07.000000000 +0100
2953 @@ -17,6 +17,16 @@
2954  #include <asm/uaccess.h>
2955  
2956  
2957 +int ext2_sync_flags(struct inode *inode, int flags, int vflags)
2958 +{
2959 +       inode->i_flags = flags;
2960 +       inode->i_vflags = vflags;
2961 +       ext2_get_inode_flags(EXT2_I(inode));
2962 +       inode->i_ctime = CURRENT_TIME_SEC;
2963 +       mark_inode_dirty(inode);
2964 +       return 0;
2965 +}
2966 +
2967  long ext2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
2968  {
2969         struct inode *inode = filp->f_dentry->d_inode;
2970 @@ -51,6 +61,11 @@ long ext2_ioctl(struct file *filp, unsig
2971  
2972                 flags = ext2_mask_flags(inode->i_mode, flags);
2973  
2974 +               if (IS_BARRIER(inode)) {
2975 +                       vxwprintk_task(1, "messing with the barrier.");
2976 +                       return -EACCES;
2977 +               }
2978 +
2979                 mutex_lock(&inode->i_mutex);
2980                 /* Is it quota file? Do not allow user to mess with it */
2981                 if (IS_NOQUOTA(inode)) {
2982 @@ -66,7 +81,9 @@ long ext2_ioctl(struct file *filp, unsig
2983                  *
2984                  * This test looks nicer. Thanks to Pauline Middelink
2985                  */
2986 -               if ((flags ^ oldflags) & (EXT2_APPEND_FL | EXT2_IMMUTABLE_FL)) {
2987 +               if ((oldflags & EXT2_IMMUTABLE_FL) ||
2988 +                       ((flags ^ oldflags) & (EXT2_APPEND_FL |
2989 +                       EXT2_IMMUTABLE_FL | EXT2_IXUNLINK_FL))) {
2990                         if (!capable(CAP_LINUX_IMMUTABLE)) {
2991                                 mutex_unlock(&inode->i_mutex);
2992                                 ret = -EPERM;
2993 @@ -74,7 +91,7 @@ long ext2_ioctl(struct file *filp, unsig
2994                         }
2995                 }
2996  
2997 -               flags = flags & EXT2_FL_USER_MODIFIABLE;
2998 +               flags &= EXT2_FL_USER_MODIFIABLE;
2999                 flags |= oldflags & ~EXT2_FL_USER_MODIFIABLE;
3000                 ei->i_flags = flags;
3001                 mutex_unlock(&inode->i_mutex);
3002 diff -NurpP --minimal linux-2.6.38-rc8/fs/ext2/namei.c linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/ext2/namei.c
3003 --- linux-2.6.38-rc8/fs/ext2/namei.c    2011-03-10 17:09:22.000000000 +0100
3004 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/ext2/namei.c     2011-03-10 17:21:19.000000000 +0100
3005 @@ -32,6 +32,7 @@
3006  
3007  #include <linux/pagemap.h>
3008  #include <linux/quotaops.h>
3009 +#include <linux/vs_tag.h>
3010  #include "ext2.h"
3011  #include "xattr.h"
3012  #include "acl.h"
3013 @@ -75,6 +76,7 @@ static struct dentry *ext2_lookup(struct
3014                                 return ERR_PTR(-EIO);
3015                         } else {
3016                                 return ERR_CAST(inode);
3017 +               dx_propagate_tag(nd, inode);
3018                         }
3019                 }
3020         }
3021 @@ -413,6 +415,7 @@ const struct inode_operations ext2_dir_i
3022  #endif
3023         .setattr        = ext2_setattr,
3024         .check_acl      = ext2_check_acl,
3025 +       .sync_flags     = ext2_sync_flags,
3026  };
3027  
3028  const struct inode_operations ext2_special_inode_operations = {
3029 diff -NurpP --minimal linux-2.6.38-rc8/fs/ext2/super.c linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/ext2/super.c
3030 --- linux-2.6.38-rc8/fs/ext2/super.c    2011-03-10 17:09:22.000000000 +0100
3031 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/ext2/super.c     2011-01-29 02:01:07.000000000 +0100
3032 @@ -394,7 +394,8 @@ enum {
3033         Opt_err_ro, Opt_nouid32, Opt_nocheck, Opt_debug,
3034         Opt_oldalloc, Opt_orlov, Opt_nobh, Opt_user_xattr, Opt_nouser_xattr,
3035         Opt_acl, Opt_noacl, Opt_xip, Opt_ignore, Opt_err, Opt_quota,
3036 -       Opt_usrquota, Opt_grpquota, Opt_reservation, Opt_noreservation
3037 +       Opt_usrquota, Opt_grpquota, Opt_reservation, Opt_noreservation,
3038 +       Opt_tag, Opt_notag, Opt_tagid
3039  };
3040  
3041  static const match_table_t tokens = {
3042 @@ -422,6 +423,9 @@ static const match_table_t tokens = {
3043         {Opt_acl, "acl"},
3044         {Opt_noacl, "noacl"},
3045         {Opt_xip, "xip"},
3046 +       {Opt_tag, "tag"},
3047 +       {Opt_notag, "notag"},
3048 +       {Opt_tagid, "tagid=%u"},
3049         {Opt_grpquota, "grpquota"},
3050         {Opt_ignore, "noquota"},
3051         {Opt_quota, "quota"},
3052 @@ -492,6 +496,20 @@ static int parse_options(char *options, 
3053                 case Opt_nouid32:
3054                         set_opt (sbi->s_mount_opt, NO_UID32);
3055                         break;
3056 +#ifndef CONFIG_TAGGING_NONE
3057 +               case Opt_tag:
3058 +                       set_opt (sbi->s_mount_opt, TAGGED);
3059 +                       break;
3060 +               case Opt_notag:
3061 +                       clear_opt (sbi->s_mount_opt, TAGGED);
3062 +                       break;
3063 +#endif
3064 +#ifdef CONFIG_PROPAGATE
3065 +               case Opt_tagid:
3066 +                       /* use args[0] */
3067 +                       set_opt (sbi->s_mount_opt, TAGGED);
3068 +                       break;
3069 +#endif
3070                 case Opt_nocheck:
3071                         clear_opt (sbi->s_mount_opt, CHECK);
3072                         break;
3073 @@ -850,6 +868,8 @@ static int ext2_fill_super(struct super_
3074         if (!parse_options((char *) data, sb))
3075                 goto failed_mount;
3076  
3077 +       if (EXT2_SB(sb)->s_mount_opt & EXT2_MOUNT_TAGGED)
3078 +               sb->s_flags |= MS_TAGGED;
3079         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
3080                 ((EXT2_SB(sb)->s_mount_opt & EXT2_MOUNT_POSIX_ACL) ?
3081                  MS_POSIXACL : 0);
3082 @@ -1223,6 +1243,14 @@ static int ext2_remount (struct super_bl
3083                 goto restore_opts;
3084         }
3085  
3086 +       if ((sbi->s_mount_opt & EXT2_MOUNT_TAGGED) &&
3087 +               !(sb->s_flags & MS_TAGGED)) {
3088 +               printk("EXT2-fs: %s: tagging not permitted on remount.\n",
3089 +                      sb->s_id);
3090 +               err = -EINVAL;
3091 +               goto restore_opts;
3092 +       }
3093 +
3094         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
3095                 ((sbi->s_mount_opt & EXT2_MOUNT_POSIX_ACL) ? MS_POSIXACL : 0);
3096  
3097 diff -NurpP --minimal linux-2.6.38-rc8/fs/ext3/file.c linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/ext3/file.c
3098 --- linux-2.6.38-rc8/fs/ext3/file.c     2010-07-07 18:31:51.000000000 +0200
3099 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/ext3/file.c      2011-01-29 02:01:07.000000000 +0100
3100 @@ -81,5 +81,6 @@ const struct inode_operations ext3_file_
3101  #endif
3102         .check_acl      = ext3_check_acl,
3103         .fiemap         = ext3_fiemap,
3104 +       .sync_flags     = ext3_sync_flags,
3105  };
3106  
3107 diff -NurpP --minimal linux-2.6.38-rc8/fs/ext3/ialloc.c linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/ext3/ialloc.c
3108 --- linux-2.6.38-rc8/fs/ext3/ialloc.c   2011-01-05 21:50:22.000000000 +0100
3109 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/ext3/ialloc.c    2011-01-29 02:01:07.000000000 +0100
3110 @@ -23,6 +23,7 @@
3111  #include <linux/buffer_head.h>
3112  #include <linux/random.h>
3113  #include <linux/bitops.h>
3114 +#include <linux/vs_tag.h>
3115  
3116  #include <asm/byteorder.h>
3117  
3118 @@ -531,6 +532,7 @@ got:
3119                 inode->i_mode = mode;
3120                 inode->i_uid = current_fsuid();
3121                 inode->i_gid = dir->i_gid;
3122 +               inode->i_tag = dx_current_fstag(sb);
3123         } else
3124                 inode_init_owner(inode, dir, mode);
3125  
3126 diff -NurpP --minimal linux-2.6.38-rc8/fs/ext3/inode.c linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/ext3/inode.c
3127 --- linux-2.6.38-rc8/fs/ext3/inode.c    2011-03-10 17:09:22.000000000 +0100
3128 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/ext3/inode.c     2011-01-29 02:01:07.000000000 +0100
3129 @@ -38,6 +38,7 @@
3130  #include <linux/bio.h>
3131  #include <linux/fiemap.h>
3132  #include <linux/namei.h>
3133 +#include <linux/vs_tag.h>
3134  #include "xattr.h"
3135  #include "acl.h"
3136  
3137 @@ -2394,7 +2395,7 @@ static void ext3_free_branches(handle_t 
3138  
3139  int ext3_can_truncate(struct inode *inode)
3140  {
3141 -       if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
3142 +       if (IS_APPEND(inode) || IS_IXORUNLINK(inode))
3143                 return 0;
3144         if (S_ISREG(inode->i_mode))
3145                 return 1;
3146 @@ -2778,36 +2779,60 @@ void ext3_set_inode_flags(struct inode *
3147  {
3148         unsigned int flags = EXT3_I(inode)->i_flags;
3149  
3150 -       inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
3151 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
3152 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
3153 +
3154 +       if (flags & EXT3_IMMUTABLE_FL)
3155 +               inode->i_flags |= S_IMMUTABLE;
3156 +       if (flags & EXT3_IXUNLINK_FL)
3157 +               inode->i_flags |= S_IXUNLINK;
3158 +
3159         if (flags & EXT3_SYNC_FL)
3160                 inode->i_flags |= S_SYNC;
3161         if (flags & EXT3_APPEND_FL)
3162                 inode->i_flags |= S_APPEND;
3163 -       if (flags & EXT3_IMMUTABLE_FL)
3164 -               inode->i_flags |= S_IMMUTABLE;
3165         if (flags & EXT3_NOATIME_FL)
3166                 inode->i_flags |= S_NOATIME;
3167         if (flags & EXT3_DIRSYNC_FL)
3168                 inode->i_flags |= S_DIRSYNC;
3169 +
3170 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
3171 +
3172 +       if (flags & EXT3_BARRIER_FL)
3173 +               inode->i_vflags |= V_BARRIER;
3174 +       if (flags & EXT3_COW_FL)
3175 +               inode->i_vflags |= V_COW;
3176  }
3177  
3178  /* Propagate flags from i_flags to EXT3_I(inode)->i_flags */
3179  void ext3_get_inode_flags(struct ext3_inode_info *ei)
3180  {
3181         unsigned int flags = ei->vfs_inode.i_flags;
3182 +       unsigned int vflags = ei->vfs_inode.i_vflags;
3183 +
3184 +       ei->i_flags &= ~(EXT3_SYNC_FL | EXT3_APPEND_FL |
3185 +                       EXT3_IMMUTABLE_FL | EXT3_IXUNLINK_FL |
3186 +                       EXT3_NOATIME_FL | EXT3_DIRSYNC_FL |
3187 +                       EXT3_BARRIER_FL | EXT3_COW_FL);
3188 +
3189 +       if (flags & S_IMMUTABLE)
3190 +               ei->i_flags |= EXT3_IMMUTABLE_FL;
3191 +       if (flags & S_IXUNLINK)
3192 +               ei->i_flags |= EXT3_IXUNLINK_FL;
3193  
3194 -       ei->i_flags &= ~(EXT3_SYNC_FL|EXT3_APPEND_FL|
3195 -                       EXT3_IMMUTABLE_FL|EXT3_NOATIME_FL|EXT3_DIRSYNC_FL);
3196         if (flags & S_SYNC)
3197                 ei->i_flags |= EXT3_SYNC_FL;
3198         if (flags & S_APPEND)
3199                 ei->i_flags |= EXT3_APPEND_FL;
3200 -       if (flags & S_IMMUTABLE)
3201 -               ei->i_flags |= EXT3_IMMUTABLE_FL;
3202         if (flags & S_NOATIME)
3203                 ei->i_flags |= EXT3_NOATIME_FL;
3204         if (flags & S_DIRSYNC)
3205                 ei->i_flags |= EXT3_DIRSYNC_FL;
3206 +
3207 +       if (vflags & V_BARRIER)
3208 +               ei->i_flags |= EXT3_BARRIER_FL;
3209 +       if (vflags & V_COW)
3210 +               ei->i_flags |= EXT3_COW_FL;
3211  }
3212  
3213  struct inode *ext3_iget(struct super_block *sb, unsigned long ino)
3214 @@ -2821,6 +2846,8 @@ struct inode *ext3_iget(struct super_blo
3215         transaction_t *transaction;
3216         long ret;
3217         int block;
3218 +       uid_t uid;
3219 +       gid_t gid;
3220  
3221         inode = iget_locked(sb, ino);
3222         if (!inode)
3223 @@ -2837,12 +2864,17 @@ struct inode *ext3_iget(struct super_blo
3224         bh = iloc.bh;
3225         raw_inode = ext3_raw_inode(&iloc);
3226         inode->i_mode = le16_to_cpu(raw_inode->i_mode);
3227 -       inode->i_uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
3228 -       inode->i_gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
3229 +       uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
3230 +       gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
3231         if(!(test_opt (inode->i_sb, NO_UID32))) {
3232 -               inode->i_uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
3233 -               inode->i_gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
3234 +               uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
3235 +               gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
3236         }
3237 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
3238 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
3239 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid,
3240 +               le16_to_cpu(raw_inode->i_raw_tag));
3241 +
3242         inode->i_nlink = le16_to_cpu(raw_inode->i_links_count);
3243         inode->i_size = le32_to_cpu(raw_inode->i_size);
3244         inode->i_atime.tv_sec = (signed)le32_to_cpu(raw_inode->i_atime);
3245 @@ -2997,6 +3029,8 @@ static int ext3_do_update_inode(handle_t
3246         struct ext3_inode *raw_inode = ext3_raw_inode(iloc);
3247         struct ext3_inode_info *ei = EXT3_I(inode);
3248         struct buffer_head *bh = iloc->bh;
3249 +       uid_t uid = TAGINO_UID(DX_TAG(inode), inode->i_uid, inode->i_tag);
3250 +       gid_t gid = TAGINO_GID(DX_TAG(inode), inode->i_gid, inode->i_tag);
3251         int err = 0, rc, block;
3252  
3253  again:
3254 @@ -3011,29 +3045,32 @@ again:
3255         ext3_get_inode_flags(ei);
3256         raw_inode->i_mode = cpu_to_le16(inode->i_mode);
3257         if(!(test_opt(inode->i_sb, NO_UID32))) {
3258 -               raw_inode->i_uid_low = cpu_to_le16(low_16_bits(inode->i_uid));
3259 -               raw_inode->i_gid_low = cpu_to_le16(low_16_bits(inode->i_gid));
3260 +               raw_inode->i_uid_low = cpu_to_le16(low_16_bits(uid));
3261 +               raw_inode->i_gid_low = cpu_to_le16(low_16_bits(gid));
3262  /*
3263   * Fix up interoperability with old kernels. Otherwise, old inodes get
3264   * re-used with the upper 16 bits of the uid/gid intact
3265   */
3266                 if(!ei->i_dtime) {
3267                         raw_inode->i_uid_high =
3268 -                               cpu_to_le16(high_16_bits(inode->i_uid));
3269 +                               cpu_to_le16(high_16_bits(uid));
3270                         raw_inode->i_gid_high =
3271 -                               cpu_to_le16(high_16_bits(inode->i_gid));
3272 +                               cpu_to_le16(high_16_bits(gid));
3273                 } else {
3274                         raw_inode->i_uid_high = 0;
3275                         raw_inode->i_gid_high = 0;
3276                 }
3277         } else {
3278                 raw_inode->i_uid_low =
3279 -                       cpu_to_le16(fs_high2lowuid(inode->i_uid));
3280 +                       cpu_to_le16(fs_high2lowuid(uid));
3281                 raw_inode->i_gid_low =
3282 -                       cpu_to_le16(fs_high2lowgid(inode->i_gid));
3283 +                       cpu_to_le16(fs_high2lowgid(gid));
3284                 raw_inode->i_uid_high = 0;
3285                 raw_inode->i_gid_high = 0;
3286         }
3287 +#ifdef CONFIG_TAGGING_INTERN
3288 +       raw_inode->i_raw_tag = cpu_to_le16(inode->i_tag);
3289 +#endif
3290         raw_inode->i_links_count = cpu_to_le16(inode->i_nlink);
3291         raw_inode->i_size = cpu_to_le32(ei->i_disksize);
3292         raw_inode->i_atime = cpu_to_le32(inode->i_atime.tv_sec);
3293 @@ -3193,7 +3230,8 @@ int ext3_setattr(struct dentry *dentry, 
3294         if (is_quota_modification(inode, attr))
3295                 dquot_initialize(inode);
3296         if ((ia_valid & ATTR_UID && attr->ia_uid != inode->i_uid) ||
3297 -               (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid)) {
3298 +               (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid) ||
3299 +               (ia_valid & ATTR_TAG && attr->ia_tag != inode->i_tag)) {
3300                 handle_t *handle;
3301  
3302                 /* (user+group)*(old+new) structure, inode write (sb,
3303 @@ -3215,6 +3253,8 @@ int ext3_setattr(struct dentry *dentry, 
3304                         inode->i_uid = attr->ia_uid;
3305                 if (attr->ia_valid & ATTR_GID)
3306                         inode->i_gid = attr->ia_gid;
3307 +               if ((attr->ia_valid & ATTR_TAG) && IS_TAGGED(inode))
3308 +                       inode->i_tag = attr->ia_tag;
3309                 error = ext3_mark_inode_dirty(handle, inode);
3310                 ext3_journal_stop(handle);
3311         }
3312 diff -NurpP --minimal linux-2.6.38-rc8/fs/ext3/ioctl.c linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/ext3/ioctl.c
3313 --- linux-2.6.38-rc8/fs/ext3/ioctl.c    2011-03-10 17:09:22.000000000 +0100
3314 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/ext3/ioctl.c     2011-01-29 02:01:07.000000000 +0100
3315 @@ -8,6 +8,7 @@
3316   */
3317  
3318  #include <linux/fs.h>
3319 +#include <linux/mount.h>
3320  #include <linux/jbd.h>
3321  #include <linux/capability.h>
3322  #include <linux/ext3_fs.h>
3323 @@ -17,6 +18,34 @@
3324  #include <linux/compat.h>
3325  #include <asm/uaccess.h>
3326  
3327 +
3328 +int ext3_sync_flags(struct inode *inode, int flags, int vflags)
3329 +{
3330 +       handle_t *handle = NULL;
3331 +       struct ext3_iloc iloc;
3332 +       int err;
3333 +
3334 +       handle = ext3_journal_start(inode, 1);
3335 +       if (IS_ERR(handle))
3336 +               return PTR_ERR(handle);
3337 +
3338 +       if (IS_SYNC(inode))
3339 +               handle->h_sync = 1;
3340 +       err = ext3_reserve_inode_write(handle, inode, &iloc);
3341 +       if (err)
3342 +               goto flags_err;
3343 +
3344 +       inode->i_flags = flags;
3345 +       inode->i_vflags = vflags;
3346 +       ext3_get_inode_flags(EXT3_I(inode));
3347 +       inode->i_ctime = CURRENT_TIME_SEC;
3348 +
3349 +       err = ext3_mark_iloc_dirty(handle, inode, &iloc);
3350 +flags_err:
3351 +       ext3_journal_stop(handle);
3352 +       return err;
3353 +}
3354 +
3355  long ext3_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
3356  {
3357         struct inode *inode = filp->f_dentry->d_inode;
3358 @@ -50,6 +79,11 @@ long ext3_ioctl(struct file *filp, unsig
3359  
3360                 flags = ext3_mask_flags(inode->i_mode, flags);
3361  
3362 +               if (IS_BARRIER(inode)) {
3363 +                       vxwprintk_task(1, "messing with the barrier.");
3364 +                       return -EACCES;
3365 +               }
3366 +
3367                 mutex_lock(&inode->i_mutex);
3368  
3369                 /* Is it quota file? Do not allow user to mess with it */
3370 @@ -68,7 +102,9 @@ long ext3_ioctl(struct file *filp, unsig
3371                  *
3372                  * This test looks nicer. Thanks to Pauline Middelink
3373                  */
3374 -               if ((flags ^ oldflags) & (EXT3_APPEND_FL | EXT3_IMMUTABLE_FL)) {
3375 +               if ((oldflags & EXT3_IMMUTABLE_FL) ||
3376 +                       ((flags ^ oldflags) & (EXT3_APPEND_FL |
3377 +                       EXT3_IMMUTABLE_FL | EXT3_IXUNLINK_FL))) {
3378                         if (!capable(CAP_LINUX_IMMUTABLE))
3379                                 goto flags_out;
3380                 }
3381 @@ -93,7 +129,7 @@ long ext3_ioctl(struct file *filp, unsig
3382                 if (err)
3383                         goto flags_err;
3384  
3385 -               flags = flags & EXT3_FL_USER_MODIFIABLE;
3386 +               flags &= EXT3_FL_USER_MODIFIABLE;
3387                 flags |= oldflags & ~EXT3_FL_USER_MODIFIABLE;
3388                 ei->i_flags = flags;
3389  
3390 diff -NurpP --minimal linux-2.6.38-rc8/fs/ext3/namei.c linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/ext3/namei.c
3391 --- linux-2.6.38-rc8/fs/ext3/namei.c    2011-03-10 17:09:22.000000000 +0100
3392 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/ext3/namei.c     2011-01-29 02:01:07.000000000 +0100
3393 @@ -36,6 +36,7 @@
3394  #include <linux/quotaops.h>
3395  #include <linux/buffer_head.h>
3396  #include <linux/bio.h>
3397 +#include <linux/vs_tag.h>
3398  
3399  #include "namei.h"
3400  #include "xattr.h"
3401 @@ -923,6 +924,7 @@ restart:
3402                                 if (bh)
3403                                         ll_rw_block(READ_META, 1, &bh);
3404                         }
3405 +               dx_propagate_tag(nd, inode);
3406                 }
3407                 if ((bh = bh_use[ra_ptr++]) == NULL)
3408                         goto next;
3409 @@ -2487,6 +2489,7 @@ const struct inode_operations ext3_dir_i
3410         .removexattr    = generic_removexattr,
3411  #endif
3412         .check_acl      = ext3_check_acl,
3413 +       .sync_flags     = ext3_sync_flags,
3414  };
3415  
3416  const struct inode_operations ext3_special_inode_operations = {
3417 diff -NurpP --minimal linux-2.6.38-rc8/fs/ext3/super.c linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/ext3/super.c
3418 --- linux-2.6.38-rc8/fs/ext3/super.c    2011-03-10 17:09:22.000000000 +0100
3419 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/ext3/super.c     2011-01-29 02:01:07.000000000 +0100
3420 @@ -820,7 +820,8 @@ enum {
3421         Opt_usrjquota, Opt_grpjquota, Opt_offusrjquota, Opt_offgrpjquota,
3422         Opt_jqfmt_vfsold, Opt_jqfmt_vfsv0, Opt_jqfmt_vfsv1, Opt_quota,
3423         Opt_noquota, Opt_ignore, Opt_barrier, Opt_nobarrier, Opt_err,
3424 -       Opt_resize, Opt_usrquota, Opt_grpquota
3425 +       Opt_resize, Opt_usrquota, Opt_grpquota,
3426 +       Opt_tag, Opt_notag, Opt_tagid
3427  };
3428  
3429  static const match_table_t tokens = {
3430 @@ -877,6 +878,9 @@ static const match_table_t tokens = {
3431         {Opt_barrier, "barrier"},
3432         {Opt_nobarrier, "nobarrier"},
3433         {Opt_resize, "resize"},
3434 +       {Opt_tag, "tag"},
3435 +       {Opt_notag, "notag"},
3436 +       {Opt_tagid, "tagid=%u"},
3437         {Opt_err, NULL},
3438  };
3439  
3440 @@ -1029,6 +1033,20 @@ static int parse_options (char *options,
3441                 case Opt_nouid32:
3442                         set_opt (sbi->s_mount_opt, NO_UID32);
3443                         break;
3444 +#ifndef CONFIG_TAGGING_NONE
3445 +               case Opt_tag:
3446 +                       set_opt (sbi->s_mount_opt, TAGGED);
3447 +                       break;
3448 +               case Opt_notag:
3449 +                       clear_opt (sbi->s_mount_opt, TAGGED);
3450 +                       break;
3451 +#endif
3452 +#ifdef CONFIG_PROPAGATE
3453 +               case Opt_tagid:
3454 +                       /* use args[0] */
3455 +                       set_opt (sbi->s_mount_opt, TAGGED);
3456 +                       break;
3457 +#endif
3458                 case Opt_nocheck:
3459                         clear_opt (sbi->s_mount_opt, CHECK);
3460                         break;
3461 @@ -1715,6 +1733,9 @@ static int ext3_fill_super (struct super
3462                             NULL, 0))
3463                 goto failed_mount;
3464  
3465 +       if (EXT3_SB(sb)->s_mount_opt & EXT3_MOUNT_TAGGED)
3466 +               sb->s_flags |= MS_TAGGED;
3467 +
3468         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
3469                 (test_opt(sb, POSIX_ACL) ? MS_POSIXACL : 0);
3470  
3471 @@ -2594,6 +2615,14 @@ static int ext3_remount (struct super_bl
3472         if (test_opt(sb, ABORT))
3473                 ext3_abort(sb, __func__, "Abort forced by user");
3474  
3475 +       if ((sbi->s_mount_opt & EXT3_MOUNT_TAGGED) &&
3476 +               !(sb->s_flags & MS_TAGGED)) {
3477 +               printk("EXT3-fs: %s: tagging not permitted on remount.\n",
3478 +                       sb->s_id);
3479 +               err = -EINVAL;
3480 +               goto restore_opts;
3481 +       }
3482 +
3483         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
3484                 (test_opt(sb, POSIX_ACL) ? MS_POSIXACL : 0);
3485  
3486 diff -NurpP --minimal linux-2.6.38-rc8/fs/ext4/ext4.h linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/ext4/ext4.h
3487 --- linux-2.6.38-rc8/fs/ext4/ext4.h     2011-03-10 17:09:22.000000000 +0100
3488 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/ext4/ext4.h      2011-02-17 02:17:50.000000000 +0100
3489 @@ -347,8 +347,12 @@ struct flex_groups {
3490  #define EXT4_EXTENTS_FL                        0x00080000 /* Inode uses extents */
3491  #define EXT4_EA_INODE_FL               0x00200000 /* Inode used for large EA */
3492  #define EXT4_EOFBLOCKS_FL              0x00400000 /* Blocks allocated beyond EOF */
3493 +#define EXT4_IXUNLINK_FL               0x08000000 /* Immutable invert on unlink */
3494  #define EXT4_RESERVED_FL               0x80000000 /* reserved for ext4 lib */
3495  
3496 +#define EXT4_BARRIER_FL                        0x04000000 /* Barrier for chroot() */
3497 +#define EXT4_COW_FL                    0x20000000 /* Copy on Write marker */
3498 +
3499  #define EXT4_FL_USER_VISIBLE           0x004BDFFF /* User visible flags */
3500  #define EXT4_FL_USER_MODIFIABLE                0x004B80FF /* User modifiable flags */
3501  
3502 @@ -601,7 +605,8 @@ struct ext4_inode {
3503                         __le16  l_i_file_acl_high;
3504                         __le16  l_i_uid_high;   /* these 2 fields */
3505                         __le16  l_i_gid_high;   /* were reserved2[0] */
3506 -                       __u32   l_i_reserved2;
3507 +                       __le16  l_i_tag;        /* Context Tag */
3508 +                       __u16   l_i_reserved2;
3509                 } linux2;
3510                 struct {
3511                         __le16  h_i_reserved1;  /* Obsoleted fragment number/size which are removed in ext4 */
3512 @@ -719,6 +724,7 @@ do {                                                                               \
3513  #define i_gid_low      i_gid
3514  #define i_uid_high     osd2.linux2.l_i_uid_high
3515  #define i_gid_high     osd2.linux2.l_i_gid_high
3516 +#define i_raw_tag      osd2.linux2.l_i_tag
3517  #define i_reserved2    osd2.linux2.l_i_reserved2
3518  
3519  #elif defined(__GNU__)
3520 @@ -895,6 +901,7 @@ struct ext4_inode_info {
3521  #define EXT4_MOUNT_POSIX_ACL           0x08000 /* POSIX Access Control Lists */
3522  #define EXT4_MOUNT_NO_AUTO_DA_ALLOC    0x10000 /* No auto delalloc mapping */
3523  #define EXT4_MOUNT_BARRIER             0x20000 /* Use block barriers */
3524 +#define EXT4_MOUNT_TAGGED              0x40000 /* Enable Context Tags */
3525  #define EXT4_MOUNT_QUOTA               0x80000 /* Some quota option set */
3526  #define EXT4_MOUNT_USRQUOTA            0x100000 /* "old" user quota */
3527  #define EXT4_MOUNT_GRPQUOTA            0x200000 /* "old" group quota */
3528 @@ -2074,6 +2081,7 @@ extern int ext4_map_blocks(handle_t *han
3529                            struct ext4_map_blocks *map, int flags);
3530  extern int ext4_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
3531                         __u64 start, __u64 len);
3532 +extern int ext4_sync_flags(struct inode *, int, int);
3533  /* move_extent.c */
3534  extern int ext4_move_extents(struct file *o_filp, struct file *d_filp,
3535                              __u64 start_orig, __u64 start_donor,
3536 diff -NurpP --minimal linux-2.6.38-rc8/fs/ext4/file.c linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/ext4/file.c
3537 --- linux-2.6.38-rc8/fs/ext4/file.c     2011-03-10 17:09:23.000000000 +0100
3538 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/ext4/file.c      2011-02-17 02:17:50.000000000 +0100
3539 @@ -283,5 +283,6 @@ const struct inode_operations ext4_file_
3540  #endif
3541         .check_acl      = ext4_check_acl,
3542         .fiemap         = ext4_fiemap,
3543 +       .sync_flags     = ext4_sync_flags,
3544  };
3545  
3546 diff -NurpP --minimal linux-2.6.38-rc8/fs/ext4/ialloc.c linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/ext4/ialloc.c
3547 --- linux-2.6.38-rc8/fs/ext4/ialloc.c   2011-03-10 17:09:23.000000000 +0100
3548 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/ext4/ialloc.c    2011-01-29 02:01:07.000000000 +0100
3549 @@ -22,6 +22,7 @@
3550  #include <linux/random.h>
3551  #include <linux/bitops.h>
3552  #include <linux/blkdev.h>
3553 +#include <linux/vs_tag.h>
3554  #include <asm/byteorder.h>
3555  
3556  #include "ext4.h"
3557 @@ -991,6 +992,7 @@ got:
3558                 inode->i_mode = mode;
3559                 inode->i_uid = current_fsuid();
3560                 inode->i_gid = dir->i_gid;
3561 +               inode->i_tag = dx_current_fstag(sb);
3562         } else
3563                 inode_init_owner(inode, dir, mode);
3564  
3565 diff -NurpP --minimal linux-2.6.38-rc8/fs/ext4/inode.c linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/ext4/inode.c
3566 --- linux-2.6.38-rc8/fs/ext4/inode.c    2011-03-10 17:09:23.000000000 +0100
3567 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/ext4/inode.c     2011-01-29 02:27:03.000000000 +0100
3568 @@ -42,6 +42,7 @@
3569  #include <linux/printk.h>
3570  #include <linux/slab.h>
3571  #include <linux/ratelimit.h>
3572 +#include <linux/vs_tag.h>
3573  
3574  #include "ext4_jbd2.h"
3575  #include "xattr.h"
3576 @@ -4446,7 +4447,7 @@ static void ext4_free_branches(handle_t 
3577  
3578  int ext4_can_truncate(struct inode *inode)
3579  {
3580 -       if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
3581 +       if (IS_APPEND(inode) || IS_IXORUNLINK(inode))
3582                 return 0;
3583         if (S_ISREG(inode->i_mode))
3584                 return 1;
3585 @@ -4797,41 +4798,64 @@ void ext4_set_inode_flags(struct inode *
3586  {
3587         unsigned int flags = EXT4_I(inode)->i_flags;
3588  
3589 -       inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
3590 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
3591 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
3592 +
3593 +       if (flags & EXT4_IMMUTABLE_FL)
3594 +               inode->i_flags |= S_IMMUTABLE;
3595 +       if (flags & EXT4_IXUNLINK_FL)
3596 +               inode->i_flags |= S_IXUNLINK;
3597 +
3598         if (flags & EXT4_SYNC_FL)
3599                 inode->i_flags |= S_SYNC;
3600         if (flags & EXT4_APPEND_FL)
3601                 inode->i_flags |= S_APPEND;
3602 -       if (flags & EXT4_IMMUTABLE_FL)
3603 -               inode->i_flags |= S_IMMUTABLE;
3604         if (flags & EXT4_NOATIME_FL)
3605                 inode->i_flags |= S_NOATIME;
3606         if (flags & EXT4_DIRSYNC_FL)
3607                 inode->i_flags |= S_DIRSYNC;
3608 +
3609 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
3610 +
3611 +       if (flags & EXT4_BARRIER_FL)
3612 +               inode->i_vflags |= V_BARRIER;
3613 +       if (flags & EXT4_COW_FL)
3614 +               inode->i_vflags |= V_COW;
3615  }
3616  
3617  /* Propagate flags from i_flags to EXT4_I(inode)->i_flags */
3618  void ext4_get_inode_flags(struct ext4_inode_info *ei)
3619  {
3620 -       unsigned int vfs_fl;
3621 +       unsigned int vfs_fl, vfs_vf;
3622         unsigned long old_fl, new_fl;
3623  
3624         do {
3625                 vfs_fl = ei->vfs_inode.i_flags;
3626 +               vfs_vf = ei->vfs_inode.i_vflags;
3627                 old_fl = ei->i_flags;
3628                 new_fl = old_fl & ~(EXT4_SYNC_FL|EXT4_APPEND_FL|
3629                                 EXT4_IMMUTABLE_FL|EXT4_NOATIME_FL|
3630 -                               EXT4_DIRSYNC_FL);
3631 +                               EXT4_DIRSYNC_FL|EXT4_BARRIER_FL|
3632 +                               EXT4_COW_FL);
3633 +
3634 +               if (vfs_fl & S_IMMUTABLE)
3635 +                       new_fl |= EXT4_IMMUTABLE_FL;
3636 +               if (vfs_fl & S_IXUNLINK)
3637 +                       new_fl |= EXT4_IXUNLINK_FL;
3638 +
3639                 if (vfs_fl & S_SYNC)
3640                         new_fl |= EXT4_SYNC_FL;
3641                 if (vfs_fl & S_APPEND)
3642                         new_fl |= EXT4_APPEND_FL;
3643 -               if (vfs_fl & S_IMMUTABLE)
3644 -                       new_fl |= EXT4_IMMUTABLE_FL;
3645                 if (vfs_fl & S_NOATIME)
3646                         new_fl |= EXT4_NOATIME_FL;
3647                 if (vfs_fl & S_DIRSYNC)
3648                         new_fl |= EXT4_DIRSYNC_FL;
3649 +
3650 +               if (vfs_vf & V_BARRIER)
3651 +                       new_fl |= EXT4_BARRIER_FL;
3652 +               if (vfs_vf & V_COW)
3653 +                       new_fl |= EXT4_COW_FL;
3654         } while (cmpxchg(&ei->i_flags, old_fl, new_fl) != old_fl);
3655  }
3656  
3657 @@ -4867,6 +4891,8 @@ struct inode *ext4_iget(struct super_blo
3658         journal_t *journal = EXT4_SB(sb)->s_journal;
3659         long ret;
3660         int block;
3661 +       uid_t uid;
3662 +       gid_t gid;
3663  
3664         inode = iget_locked(sb, ino);
3665         if (!inode)
3666 @@ -4882,12 +4908,16 @@ struct inode *ext4_iget(struct super_blo
3667                 goto bad_inode;
3668         raw_inode = ext4_raw_inode(&iloc);
3669         inode->i_mode = le16_to_cpu(raw_inode->i_mode);
3670 -       inode->i_uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
3671 -       inode->i_gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
3672 +       uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
3673 +       gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
3674         if (!(test_opt(inode->i_sb, NO_UID32))) {
3675 -               inode->i_uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
3676 -               inode->i_gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
3677 +               uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
3678 +               gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
3679         }
3680 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
3681 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
3682 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid,
3683 +               le16_to_cpu(raw_inode->i_raw_tag));
3684         inode->i_nlink = le16_to_cpu(raw_inode->i_links_count);
3685  
3686         ext4_clear_state_flags(ei);     /* Only relevant on 32-bit archs */
3687 @@ -5106,6 +5136,8 @@ static int ext4_do_update_inode(handle_t
3688         struct ext4_inode *raw_inode = ext4_raw_inode(iloc);
3689         struct ext4_inode_info *ei = EXT4_I(inode);
3690         struct buffer_head *bh = iloc->bh;
3691 +       uid_t uid = TAGINO_UID(DX_TAG(inode), inode->i_uid, inode->i_tag);
3692 +       gid_t gid = TAGINO_GID(DX_TAG(inode), inode->i_gid, inode->i_tag);
3693         int err = 0, rc, block;
3694  
3695         /* For fields not not tracking in the in-memory inode,
3696 @@ -5116,29 +5148,32 @@ static int ext4_do_update_inode(handle_t
3697         ext4_get_inode_flags(ei);
3698         raw_inode->i_mode = cpu_to_le16(inode->i_mode);
3699         if (!(test_opt(inode->i_sb, NO_UID32))) {
3700 -               raw_inode->i_uid_low = cpu_to_le16(low_16_bits(inode->i_uid));
3701 -               raw_inode->i_gid_low = cpu_to_le16(low_16_bits(inode->i_gid));
3702 +               raw_inode->i_uid_low = cpu_to_le16(low_16_bits(uid));
3703 +               raw_inode->i_gid_low = cpu_to_le16(low_16_bits(gid));
3704  /*
3705   * Fix up interoperability with old kernels. Otherwise, old inodes get
3706   * re-used with the upper 16 bits of the uid/gid intact
3707   */
3708                 if (!ei->i_dtime) {
3709                         raw_inode->i_uid_high =
3710 -                               cpu_to_le16(high_16_bits(inode->i_uid));
3711 +                               cpu_to_le16(high_16_bits(uid));
3712                         raw_inode->i_gid_high =
3713 -                               cpu_to_le16(high_16_bits(inode->i_gid));
3714 +                               cpu_to_le16(high_16_bits(gid));
3715                 } else {
3716                         raw_inode->i_uid_high = 0;
3717                         raw_inode->i_gid_high = 0;
3718                 }
3719         } else {
3720                 raw_inode->i_uid_low =
3721 -                       cpu_to_le16(fs_high2lowuid(inode->i_uid));
3722 +                       cpu_to_le16(fs_high2lowuid(uid));
3723                 raw_inode->i_gid_low =
3724 -                       cpu_to_le16(fs_high2lowgid(inode->i_gid));
3725 +                       cpu_to_le16(fs_high2lowgid(gid));
3726                 raw_inode->i_uid_high = 0;
3727                 raw_inode->i_gid_high = 0;
3728         }
3729 +#ifdef CONFIG_TAGGING_INTERN
3730 +       raw_inode->i_raw_tag = cpu_to_le16(inode->i_tag);
3731 +#endif
3732         raw_inode->i_links_count = cpu_to_le16(inode->i_nlink);
3733  
3734         EXT4_INODE_SET_XTIME(i_ctime, inode, raw_inode);
3735 @@ -5324,7 +5359,8 @@ int ext4_setattr(struct dentry *dentry, 
3736         if (is_quota_modification(inode, attr))
3737                 dquot_initialize(inode);
3738         if ((ia_valid & ATTR_UID && attr->ia_uid != inode->i_uid) ||
3739 -               (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid)) {
3740 +               (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid) ||
3741 +               (ia_valid & ATTR_TAG && attr->ia_tag != inode->i_tag)) {
3742                 handle_t *handle;
3743  
3744                 /* (user+group)*(old+new) structure, inode write (sb,
3745 @@ -5346,6 +5382,8 @@ int ext4_setattr(struct dentry *dentry, 
3746                         inode->i_uid = attr->ia_uid;
3747                 if (attr->ia_valid & ATTR_GID)
3748                         inode->i_gid = attr->ia_gid;
3749 +               if ((attr->ia_valid & ATTR_TAG) && IS_TAGGED(inode))
3750 +                       inode->i_tag = attr->ia_tag;
3751                 error = ext4_mark_inode_dirty(handle, inode);
3752                 ext4_journal_stop(handle);
3753         }
3754 diff -NurpP --minimal linux-2.6.38-rc8/fs/ext4/ioctl.c linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/ext4/ioctl.c
3755 --- linux-2.6.38-rc8/fs/ext4/ioctl.c    2011-01-05 21:50:23.000000000 +0100
3756 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/ext4/ioctl.c     2011-01-29 02:01:07.000000000 +0100
3757 @@ -14,10 +14,39 @@
3758  #include <linux/compat.h>
3759  #include <linux/mount.h>
3760  #include <linux/file.h>
3761 +#include <linux/vs_tag.h>
3762  #include <asm/uaccess.h>
3763  #include "ext4_jbd2.h"
3764  #include "ext4.h"
3765  
3766 +
3767 +int ext4_sync_flags(struct inode *inode, int flags, int vflags)
3768 +{
3769 +       handle_t *handle = NULL;
3770 +       struct ext4_iloc iloc;
3771 +       int err;
3772 +
3773 +       handle = ext4_journal_start(inode, 1);
3774 +       if (IS_ERR(handle))
3775 +               return PTR_ERR(handle);
3776 +
3777 +       if (IS_SYNC(inode))
3778 +               ext4_handle_sync(handle);
3779 +       err = ext4_reserve_inode_write(handle, inode, &iloc);
3780 +       if (err)
3781 +               goto flags_err;
3782 +
3783 +       inode->i_flags = flags;
3784 +       inode->i_vflags = vflags;
3785 +       ext4_get_inode_flags(EXT4_I(inode));
3786 +       inode->i_ctime = ext4_current_time(inode);
3787 +
3788 +       err = ext4_mark_iloc_dirty(handle, inode, &iloc);
3789 +flags_err:
3790 +       ext4_journal_stop(handle);
3791 +       return err;
3792 +}
3793 +
3794  long ext4_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
3795  {
3796         struct inode *inode = filp->f_dentry->d_inode;
3797 @@ -50,6 +79,11 @@ long ext4_ioctl(struct file *filp, unsig
3798  
3799                 flags = ext4_mask_flags(inode->i_mode, flags);
3800  
3801 +               if (IS_BARRIER(inode)) {
3802 +                       vxwprintk_task(1, "messing with the barrier.");
3803 +                       return -EACCES;
3804 +               }
3805 +
3806                 err = -EPERM;
3807                 mutex_lock(&inode->i_mutex);
3808                 /* Is it quota file? Do not allow user to mess with it */
3809 @@ -67,7 +101,9 @@ long ext4_ioctl(struct file *filp, unsig
3810                  *
3811                  * This test looks nicer. Thanks to Pauline Middelink
3812                  */
3813 -               if ((flags ^ oldflags) & (EXT4_APPEND_FL | EXT4_IMMUTABLE_FL)) {
3814 +               if ((oldflags & EXT4_IMMUTABLE_FL) ||
3815 +                       ((flags ^ oldflags) & (EXT4_APPEND_FL |
3816 +                       EXT4_IMMUTABLE_FL | EXT4_IXUNLINK_FL))) {
3817                         if (!capable(CAP_LINUX_IMMUTABLE))
3818                                 goto flags_out;
3819                 }
3820 diff -NurpP --minimal linux-2.6.38-rc8/fs/ext4/namei.c linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/ext4/namei.c
3821 --- linux-2.6.38-rc8/fs/ext4/namei.c    2011-03-10 17:09:23.000000000 +0100
3822 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/ext4/namei.c     2011-01-29 02:01:07.000000000 +0100
3823 @@ -34,6 +34,7 @@
3824  #include <linux/quotaops.h>
3825  #include <linux/buffer_head.h>
3826  #include <linux/bio.h>
3827 +#include <linux/vs_tag.h>
3828  #include "ext4.h"
3829  #include "ext4_jbd2.h"
3830  
3831 @@ -923,6 +924,7 @@ restart:
3832                                 if (bh)
3833                                         ll_rw_block(READ_META, 1, &bh);
3834                         }
3835 +               dx_propagate_tag(nd, inode);
3836                 }
3837                 if ((bh = bh_use[ra_ptr++]) == NULL)
3838                         goto next;
3839 @@ -2540,6 +2542,7 @@ const struct inode_operations ext4_dir_i
3840  #endif
3841         .check_acl      = ext4_check_acl,
3842         .fiemap         = ext4_fiemap,
3843 +       .sync_flags     = ext4_sync_flags,
3844  };
3845  
3846  const struct inode_operations ext4_special_inode_operations = {
3847 diff -NurpP --minimal linux-2.6.38-rc8/fs/ext4/super.c linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/ext4/super.c
3848 --- linux-2.6.38-rc8/fs/ext4/super.c    2011-03-10 17:09:23.000000000 +0100
3849 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/ext4/super.c     2011-02-17 02:17:50.000000000 +0100
3850 @@ -1262,6 +1262,7 @@ enum {
3851         Opt_dioread_nolock, Opt_dioread_lock,
3852         Opt_discard, Opt_nodiscard,
3853         Opt_init_inode_table, Opt_noinit_inode_table,
3854 +       Opt_tag, Opt_notag, Opt_tagid
3855  };
3856  
3857  static const match_table_t tokens = {
3858 @@ -1337,6 +1338,9 @@ static const match_table_t tokens = {
3859         {Opt_init_inode_table, "init_itable=%u"},
3860         {Opt_init_inode_table, "init_itable"},
3861         {Opt_noinit_inode_table, "noinit_itable"},
3862 +       {Opt_tag, "tag"},
3863 +       {Opt_notag, "notag"},
3864 +       {Opt_tagid, "tagid=%u"},
3865         {Opt_err, NULL},
3866  };
3867  
3868 @@ -1505,6 +1509,20 @@ static int parse_options(char *options, 
3869                 case Opt_nouid32:
3870                         set_opt(sb, NO_UID32);
3871                         break;
3872 +#ifndef CONFIG_TAGGING_NONE
3873 +               case Opt_tag:
3874 +                       set_opt(sb, TAGGED);
3875 +                       break;
3876 +               case Opt_notag:
3877 +                       clear_opt(sb, TAGGED);
3878 +                       break;
3879 +#endif
3880 +#ifdef CONFIG_PROPAGATE
3881 +               case Opt_tagid:
3882 +                       /* use args[0] */
3883 +                       set_opt(sb, TAGGED);
3884 +                       break;
3885 +#endif
3886                 case Opt_debug:
3887                         set_opt(sb, DEBUG);
3888                         break;
3889 @@ -3148,6 +3166,9 @@ static int ext4_fill_super(struct super_
3890                            &journal_ioprio, NULL, 0))
3891                 goto failed_mount;
3892  
3893 +       if (EXT4_SB(sb)->s_mount_opt & EXT4_MOUNT_TAGGED)
3894 +               sb->s_flags |= MS_TAGGED;
3895 +
3896         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
3897                 (test_opt(sb, POSIX_ACL) ? MS_POSIXACL : 0);
3898  
3899 @@ -4235,6 +4256,14 @@ static int ext4_remount(struct super_blo
3900         if (sbi->s_mount_flags & EXT4_MF_FS_ABORTED)
3901                 ext4_abort(sb, "Abort forced by user");
3902  
3903 +       if ((sbi->s_mount_opt & EXT4_MOUNT_TAGGED) &&
3904 +               !(sb->s_flags & MS_TAGGED)) {
3905 +               printk("EXT4-fs: %s: tagging not permitted on remount.\n",
3906 +                       sb->s_id);
3907 +               err = -EINVAL;
3908 +               goto restore_opts;
3909 +       }
3910 +
3911         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
3912                 (test_opt(sb, POSIX_ACL) ? MS_POSIXACL : 0);
3913  
3914 diff -NurpP --minimal linux-2.6.38-rc8/fs/fcntl.c linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/fcntl.c
3915 --- linux-2.6.38-rc8/fs/fcntl.c 2011-03-10 17:09:23.000000000 +0100
3916 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/fcntl.c  2011-02-17 02:17:50.000000000 +0100
3917 @@ -20,6 +20,7 @@
3918  #include <linux/signal.h>
3919  #include <linux/rcupdate.h>
3920  #include <linux/pid_namespace.h>
3921 +#include <linux/vs_limit.h>
3922  
3923  #include <asm/poll.h>
3924  #include <asm/siginfo.h>
3925 @@ -103,6 +104,8 @@ SYSCALL_DEFINE3(dup3, unsigned int, oldf
3926  
3927         if (tofree)
3928                 filp_close(tofree, files);
3929 +       else
3930 +               vx_openfd_inc(newfd);   /* fd was unused */
3931  
3932         return newfd;
3933  
3934 @@ -434,6 +437,8 @@ SYSCALL_DEFINE3(fcntl, unsigned int, fd,
3935         filp = fget(fd);
3936         if (!filp)
3937                 goto out;
3938 +       if (!vx_files_avail(1))
3939 +               goto out;
3940  
3941         err = security_file_fcntl(filp, cmd, arg);
3942         if (err) {
3943 diff -NurpP --minimal linux-2.6.38-rc8/fs/file.c linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/file.c
3944 --- linux-2.6.38-rc8/fs/file.c  2010-10-21 13:07:48.000000000 +0200
3945 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/file.c   2011-01-29 02:01:07.000000000 +0100
3946 @@ -20,6 +20,7 @@
3947  #include <linux/spinlock.h>
3948  #include <linux/rcupdate.h>
3949  #include <linux/workqueue.h>
3950 +#include <linux/vs_limit.h>
3951  
3952  struct fdtable_defer {
3953         spinlock_t lock;
3954 @@ -355,6 +356,8 @@ struct files_struct *dup_fd(struct files
3955                 struct file *f = *old_fds++;
3956                 if (f) {
3957                         get_file(f);
3958 +                       /* TODO: sum it first for check and performance */
3959 +                       vx_openfd_inc(open_files - i);
3960                 } else {
3961                         /*
3962                          * The fd may be claimed in the fd bitmap but not yet
3963 @@ -462,6 +465,7 @@ repeat:
3964         else
3965                 FD_CLR(fd, fdt->close_on_exec);
3966         error = fd;
3967 +       vx_openfd_inc(fd);
3968  #if 1
3969         /* Sanity check */
3970         if (rcu_dereference_raw(fdt->fd[fd]) != NULL) {
3971 diff -NurpP --minimal linux-2.6.38-rc8/fs/file_table.c linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/file_table.c
3972 --- linux-2.6.38-rc8/fs/file_table.c    2011-03-10 17:09:23.000000000 +0100
3973 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/file_table.c     2011-02-17 02:17:50.000000000 +0100
3974 @@ -24,6 +24,8 @@
3975  #include <linux/percpu_counter.h>
3976  #include <linux/percpu.h>
3977  #include <linux/ima.h>
3978 +#include <linux/vs_limit.h>
3979 +#include <linux/vs_context.h>
3980  
3981  #include <asm/atomic.h>
3982  
3983 @@ -135,6 +137,8 @@ struct file *get_empty_filp(void)
3984         spin_lock_init(&f->f_lock);
3985         eventpoll_init_file(f);
3986         /* f->f_version: 0 */
3987 +       f->f_xid = vx_current_xid();
3988 +       vx_files_inc(f);
3989         return f;
3990  
3991  over:
3992 @@ -250,6 +254,8 @@ static void __fput(struct file *file)
3993                 cdev_put(inode->i_cdev);
3994         fops_put(file->f_op);
3995         put_pid(file->f_owner.pid);
3996 +       vx_files_dec(file);
3997 +       file->f_xid = 0;
3998         file_sb_list_del(file);
3999         if (file->f_mode & FMODE_WRITE)
4000                 drop_file_write_access(file);
4001 @@ -333,6 +339,8 @@ void put_filp(struct file *file)
4002  {
4003         if (atomic_long_dec_and_test(&file->f_count)) {
4004                 security_file_free(file);
4005 +               vx_files_dec(file);
4006 +               file->f_xid = 0;
4007                 file_sb_list_del(file);
4008                 file_free(file);
4009         }
4010 diff -NurpP --minimal linux-2.6.38-rc8/fs/fs_struct.c linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/fs_struct.c
4011 --- linux-2.6.38-rc8/fs/fs_struct.c     2011-03-10 17:09:23.000000000 +0100
4012 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/fs_struct.c      2011-01-29 02:35:02.000000000 +0100
4013 @@ -4,6 +4,7 @@
4014  #include <linux/path.h>
4015  #include <linux/slab.h>
4016  #include <linux/fs_struct.h>
4017 +#include <linux/vserver/global.h>
4018  #include "internal.h"
4019  
4020  static inline void path_get_longterm(struct path *path)
4021 @@ -96,6 +97,7 @@ void free_fs_struct(struct fs_struct *fs
4022  {
4023         path_put_longterm(&fs->root);
4024         path_put_longterm(&fs->pwd);
4025 +       atomic_dec(&vs_global_fs);
4026         kmem_cache_free(fs_cachep, fs);
4027  }
4028  
4029 @@ -135,6 +137,7 @@ struct fs_struct *copy_fs_struct(struct 
4030                 fs->pwd = old->pwd;
4031                 path_get_longterm(&fs->pwd);
4032                 spin_unlock(&old->lock);
4033 +               atomic_inc(&vs_global_fs);
4034         }
4035         return fs;
4036  }
4037 diff -NurpP --minimal linux-2.6.38-rc8/fs/gfs2/file.c linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/gfs2/file.c
4038 --- linux-2.6.38-rc8/fs/gfs2/file.c     2011-03-10 17:09:23.000000000 +0100
4039 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/gfs2/file.c      2011-01-29 02:01:07.000000000 +0100
4040 @@ -134,6 +134,9 @@ static const u32 fsflags_to_gfs2[32] = {
4041         [7] = GFS2_DIF_NOATIME,
4042         [12] = GFS2_DIF_EXHASH,
4043         [14] = GFS2_DIF_INHERIT_JDATA,
4044 +       [27] = GFS2_DIF_IXUNLINK,
4045 +       [26] = GFS2_DIF_BARRIER,
4046 +       [29] = GFS2_DIF_COW,
4047  };
4048  
4049  static const u32 gfs2_to_fsflags[32] = {
4050 @@ -143,6 +146,9 @@ static const u32 gfs2_to_fsflags[32] = {
4051         [gfs2fl_NoAtime] = FS_NOATIME_FL,
4052         [gfs2fl_ExHash] = FS_INDEX_FL,
4053         [gfs2fl_InheritJdata] = FS_JOURNAL_DATA_FL,
4054 +       [gfs2fl_IXUnlink] = FS_IXUNLINK_FL,
4055 +       [gfs2fl_Barrier] = FS_BARRIER_FL,
4056 +       [gfs2fl_Cow] = FS_COW_FL,
4057  };
4058  
4059  static int gfs2_get_flags(struct file *filp, u32 __user *ptr)
4060 @@ -173,10 +179,16 @@ void gfs2_set_inode_flags(struct inode *
4061  {
4062         struct gfs2_inode *ip = GFS2_I(inode);
4063         unsigned int flags = inode->i_flags;
4064 +       unsigned int vflags = inode->i_vflags;
4065 +
4066 +       flags &= ~(S_IMMUTABLE | S_IXUNLINK |
4067 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
4068  
4069 -       flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
4070         if (ip->i_diskflags & GFS2_DIF_IMMUTABLE)
4071                 flags |= S_IMMUTABLE;
4072 +       if (ip->i_diskflags & GFS2_DIF_IXUNLINK)
4073 +               flags |= S_IXUNLINK;
4074 +
4075         if (ip->i_diskflags & GFS2_DIF_APPENDONLY)
4076                 flags |= S_APPEND;
4077         if (ip->i_diskflags & GFS2_DIF_NOATIME)
4078 @@ -184,6 +196,43 @@ void gfs2_set_inode_flags(struct inode *
4079         if (ip->i_diskflags & GFS2_DIF_SYNC)
4080                 flags |= S_SYNC;
4081         inode->i_flags = flags;
4082 +
4083 +       vflags &= ~(V_BARRIER | V_COW);
4084 +
4085 +       if (ip->i_diskflags & GFS2_DIF_BARRIER)
4086 +               vflags |= V_BARRIER;
4087 +       if (ip->i_diskflags & GFS2_DIF_COW)
4088 +               vflags |= V_COW;
4089 +       inode->i_vflags = vflags;
4090 +}
4091 +
4092 +void gfs2_get_inode_flags(struct inode *inode)
4093 +{
4094 +       struct gfs2_inode *ip = GFS2_I(inode);
4095 +       unsigned int flags = inode->i_flags;
4096 +       unsigned int vflags = inode->i_vflags;
4097 +
4098 +       ip->i_diskflags &= ~(GFS2_DIF_APPENDONLY |
4099 +                       GFS2_DIF_NOATIME | GFS2_DIF_SYNC |
4100 +                       GFS2_DIF_IMMUTABLE | GFS2_DIF_IXUNLINK |
4101 +                       GFS2_DIF_BARRIER | GFS2_DIF_COW);
4102 +
4103 +       if (flags & S_IMMUTABLE)
4104 +               ip->i_diskflags |= GFS2_DIF_IMMUTABLE;
4105 +       if (flags & S_IXUNLINK)
4106 +               ip->i_diskflags |= GFS2_DIF_IXUNLINK;
4107 +
4108 +       if (flags & S_APPEND)
4109 +               ip->i_diskflags |= GFS2_DIF_APPENDONLY;
4110 +       if (flags & S_NOATIME)
4111 +               ip->i_diskflags |= GFS2_DIF_NOATIME;
4112 +       if (flags & S_SYNC)
4113 +               ip->i_diskflags |= GFS2_DIF_SYNC;
4114 +
4115 +       if (vflags & V_BARRIER)
4116 +               ip->i_diskflags |= GFS2_DIF_BARRIER;
4117 +       if (vflags & V_COW)
4118 +               ip->i_diskflags |= GFS2_DIF_COW;
4119  }
4120  
4121  /* Flags that can be set by user space */
4122 @@ -295,6 +344,37 @@ static int gfs2_set_flags(struct file *f
4123         return do_gfs2_set_flags(filp, gfsflags, ~GFS2_DIF_JDATA);
4124  }
4125  
4126 +int gfs2_sync_flags(struct inode *inode, int flags, int vflags)
4127 +{
4128 +       struct gfs2_inode *ip = GFS2_I(inode);
4129 +       struct gfs2_sbd *sdp = GFS2_SB(inode);
4130 +       struct buffer_head *bh;
4131 +       struct gfs2_holder gh;
4132 +       int error;
4133 +
4134 +       error = gfs2_glock_nq_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &gh);
4135 +       if (error)
4136 +               return error;
4137 +       error = gfs2_trans_begin(sdp, RES_DINODE, 0);
4138 +       if (error)
4139 +               goto out;
4140 +       error = gfs2_meta_inode_buffer(ip, &bh);
4141 +       if (error)
4142 +               goto out_trans_end;
4143 +       gfs2_trans_add_bh(ip->i_gl, bh, 1);
4144 +       inode->i_flags = flags;
4145 +       inode->i_vflags = vflags;
4146 +       gfs2_get_inode_flags(inode);
4147 +       gfs2_dinode_out(ip, bh->b_data);
4148 +       brelse(bh);
4149 +       gfs2_set_aops(inode);
4150 +out_trans_end:
4151 +       gfs2_trans_end(sdp);
4152 +out:
4153 +       gfs2_glock_dq_uninit(&gh);
4154 +       return error;
4155 +}
4156 +
4157  static long gfs2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
4158  {
4159         switch(cmd) {
4160 diff -NurpP --minimal linux-2.6.38-rc8/fs/gfs2/inode.h linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/gfs2/inode.h
4161 --- linux-2.6.38-rc8/fs/gfs2/inode.h    2011-03-10 17:09:23.000000000 +0100
4162 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/gfs2/inode.h     2011-01-29 02:01:07.000000000 +0100
4163 @@ -125,6 +125,7 @@ extern const struct file_operations gfs2
4164  extern const struct file_operations gfs2_dir_fops_nolock;
4165  
4166  extern void gfs2_set_inode_flags(struct inode *inode);
4167 +extern int gfs2_sync_flags(struct inode *inode, int flags, int vflags);
4168   
4169  #ifdef CONFIG_GFS2_FS_LOCKING_DLM
4170  extern const struct file_operations gfs2_file_fops;
4171 diff -NurpP --minimal linux-2.6.38-rc8/fs/gfs2/ops_inode.c linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/gfs2/ops_inode.c
4172 --- linux-2.6.38-rc8/fs/gfs2/ops_inode.c        2011-03-10 17:09:23.000000000 +0100
4173 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/gfs2/ops_inode.c 2011-01-29 02:01:07.000000000 +0100
4174 @@ -1326,6 +1326,8 @@ const struct inode_operations gfs2_dir_i
4175         .listxattr = gfs2_listxattr,
4176         .removexattr = gfs2_removexattr,
4177         .fiemap = gfs2_fiemap,
4178 +       .sync_flags = gfs2_sync_flags,
4179 +       .sync_flags = gfs2_sync_flags,
4180  };
4181  
4182  const struct inode_operations gfs2_symlink_iops = {
4183 diff -NurpP --minimal linux-2.6.38-rc8/fs/inode.c linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/inode.c
4184 --- linux-2.6.38-rc8/fs/inode.c 2011-03-10 17:09:23.000000000 +0100
4185 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/inode.c  2011-03-07 16:53:27.000000000 +0100
4186 @@ -25,6 +25,7 @@
4187  #include <linux/async.h>
4188  #include <linux/posix_acl.h>
4189  #include <linux/ima.h>
4190 +#include <linux/vs_tag.h>
4191  
4192  /*
4193   * This is needed for the following functions:
4194 @@ -164,6 +165,9 @@ int inode_init_always(struct super_block
4195         struct address_space *const mapping = &inode->i_data;
4196  
4197         inode->i_sb = sb;
4198 +
4199 +       /* essential because of inode slab reuse */
4200 +       inode->i_tag = 0;
4201         inode->i_blkbits = sb->s_blocksize_bits;
4202         inode->i_flags = 0;
4203         atomic_set(&inode->i_count, 1);
4204 @@ -184,6 +188,7 @@ int inode_init_always(struct super_block
4205         inode->i_bdev = NULL;
4206         inode->i_cdev = NULL;
4207         inode->i_rdev = 0;
4208 +       inode->i_mdev = 0;
4209         inode->dirtied_when = 0;
4210  
4211         if (security_inode_alloc(inode))
4212 @@ -431,6 +436,8 @@ static void __remove_inode_hash(struct i
4213         hlist_del_init(&inode->i_hash);
4214  }
4215  
4216 +EXPORT_SYMBOL_GPL(__iget);
4217 +
4218  /**
4219   *     remove_inode_hash - remove an inode from the hash
4220   *     @inode: inode to unhash
4221 @@ -1704,9 +1711,11 @@ void init_special_inode(struct inode *in
4222         if (S_ISCHR(mode)) {
4223                 inode->i_fop = &def_chr_fops;
4224                 inode->i_rdev = rdev;
4225 +               inode->i_mdev = rdev;
4226         } else if (S_ISBLK(mode)) {
4227                 inode->i_fop = &def_blk_fops;
4228                 inode->i_rdev = rdev;
4229 +               inode->i_mdev = rdev;
4230         } else if (S_ISFIFO(mode))
4231                 inode->i_fop = &def_fifo_fops;
4232         else if (S_ISSOCK(mode))
4233 @@ -1735,5 +1744,6 @@ void inode_init_owner(struct inode *inod
4234         } else
4235                 inode->i_gid = current_fsgid();
4236         inode->i_mode = mode;
4237 +       inode->i_tag = dx_current_fstag(inode->i_sb);
4238  }
4239  EXPORT_SYMBOL(inode_init_owner);
4240 diff -NurpP --minimal linux-2.6.38-rc8/fs/ioctl.c linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/ioctl.c
4241 --- linux-2.6.38-rc8/fs/ioctl.c 2011-03-10 17:09:23.000000000 +0100
4242 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/ioctl.c  2011-02-17 02:17:50.000000000 +0100
4243 @@ -15,6 +15,9 @@
4244  #include <linux/writeback.h>
4245  #include <linux/buffer_head.h>
4246  #include <linux/falloc.h>
4247 +#include <linux/proc_fs.h>
4248 +#include <linux/vserver/inode.h>
4249 +#include <linux/vs_tag.h>
4250  
4251  #include <asm/ioctls.h>
4252  
4253 diff -NurpP --minimal linux-2.6.38-rc8/fs/ioprio.c linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/ioprio.c
4254 --- linux-2.6.38-rc8/fs/ioprio.c        2011-01-05 21:50:24.000000000 +0100
4255 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/ioprio.c 2011-01-29 02:01:07.000000000 +0100
4256 @@ -27,6 +27,7 @@
4257  #include <linux/syscalls.h>
4258  #include <linux/security.h>
4259  #include <linux/pid_namespace.h>
4260 +#include <linux/vs_base.h>
4261  
4262  int set_task_ioprio(struct task_struct *task, int ioprio)
4263  {
4264 @@ -119,6 +120,8 @@ SYSCALL_DEFINE3(ioprio_set, int, which, 
4265                         else
4266                                 pgrp = find_vpid(who);
4267                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
4268 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
4269 +                                       continue;
4270                                 ret = set_task_ioprio(p, ioprio);
4271                                 if (ret)
4272                                         break;
4273 @@ -208,6 +211,8 @@ SYSCALL_DEFINE2(ioprio_get, int, which, 
4274                         else
4275                                 pgrp = find_vpid(who);
4276                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
4277 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
4278 +                                       continue;
4279                                 tmpio = get_task_ioprio(p);
4280                                 if (tmpio < 0)
4281                                         continue;
4282 diff -NurpP --minimal linux-2.6.38-rc8/fs/jfs/file.c linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/jfs/file.c
4283 --- linux-2.6.38-rc8/fs/jfs/file.c      2010-10-21 13:07:50.000000000 +0200
4284 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/jfs/file.c       2011-01-29 02:01:07.000000000 +0100
4285 @@ -102,7 +102,8 @@ int jfs_setattr(struct dentry *dentry, s
4286         if (is_quota_modification(inode, iattr))
4287                 dquot_initialize(inode);
4288         if ((iattr->ia_valid & ATTR_UID && iattr->ia_uid != inode->i_uid) ||
4289 -           (iattr->ia_valid & ATTR_GID && iattr->ia_gid != inode->i_gid)) {
4290 +           (iattr->ia_valid & ATTR_GID && iattr->ia_gid != inode->i_gid) ||
4291 +           (iattr->ia_valid & ATTR_TAG && iattr->ia_tag != inode->i_tag)) {
4292                 rc = dquot_transfer(inode, iattr);
4293                 if (rc)
4294                         return rc;
4295 @@ -133,6 +134,7 @@ const struct inode_operations jfs_file_i
4296  #ifdef CONFIG_JFS_POSIX_ACL
4297         .check_acl      = jfs_check_acl,
4298  #endif
4299 +       .sync_flags     = jfs_sync_flags,
4300  };
4301  
4302  const struct file_operations jfs_file_operations = {
4303 diff -NurpP --minimal linux-2.6.38-rc8/fs/jfs/ioctl.c linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/jfs/ioctl.c
4304 --- linux-2.6.38-rc8/fs/jfs/ioctl.c     2008-12-25 00:26:37.000000000 +0100
4305 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/jfs/ioctl.c      2011-01-29 02:01:07.000000000 +0100
4306 @@ -11,6 +11,7 @@
4307  #include <linux/mount.h>
4308  #include <linux/time.h>
4309  #include <linux/sched.h>
4310 +#include <linux/mount.h>
4311  #include <asm/current.h>
4312  #include <asm/uaccess.h>
4313  
4314 @@ -52,6 +53,16 @@ static long jfs_map_ext2(unsigned long f
4315  }
4316  
4317  
4318 +int jfs_sync_flags(struct inode *inode, int flags, int vflags)
4319 +{
4320 +       inode->i_flags = flags;
4321 +       inode->i_vflags = vflags;
4322 +       jfs_get_inode_flags(JFS_IP(inode));
4323 +       inode->i_ctime = CURRENT_TIME_SEC;
4324 +       mark_inode_dirty(inode);
4325 +       return 0;
4326 +}
4327 +
4328  long jfs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
4329  {
4330         struct inode *inode = filp->f_dentry->d_inode;
4331 @@ -85,6 +96,11 @@ long jfs_ioctl(struct file *filp, unsign
4332                 if (!S_ISDIR(inode->i_mode))
4333                         flags &= ~JFS_DIRSYNC_FL;
4334  
4335 +               if (IS_BARRIER(inode)) {
4336 +                       vxwprintk_task(1, "messing with the barrier.");
4337 +                       return -EACCES;
4338 +               }
4339 +
4340                 /* Is it quota file? Do not allow user to mess with it */
4341                 if (IS_NOQUOTA(inode)) {
4342                         err = -EPERM;
4343 @@ -102,8 +118,8 @@ long jfs_ioctl(struct file *filp, unsign
4344                  * the relevant capability.
4345                  */
4346                 if ((oldflags & JFS_IMMUTABLE_FL) ||
4347 -                       ((flags ^ oldflags) &
4348 -                       (JFS_APPEND_FL | JFS_IMMUTABLE_FL))) {
4349 +                       ((flags ^ oldflags) & (JFS_APPEND_FL |
4350 +                       JFS_IMMUTABLE_FL | JFS_IXUNLINK_FL))) {
4351                         if (!capable(CAP_LINUX_IMMUTABLE)) {
4352                                 mutex_unlock(&inode->i_mutex);
4353                                 err = -EPERM;
4354 @@ -111,7 +127,7 @@ long jfs_ioctl(struct file *filp, unsign
4355                         }
4356                 }
4357  
4358 -               flags = flags & JFS_FL_USER_MODIFIABLE;
4359 +               flags &= JFS_FL_USER_MODIFIABLE;
4360                 flags |= oldflags & ~JFS_FL_USER_MODIFIABLE;
4361                 jfs_inode->mode2 = flags;
4362  
4363 diff -NurpP --minimal linux-2.6.38-rc8/fs/jfs/jfs_dinode.h linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/jfs/jfs_dinode.h
4364 --- linux-2.6.38-rc8/fs/jfs/jfs_dinode.h        2008-12-25 00:26:37.000000000 +0100
4365 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/jfs/jfs_dinode.h 2011-01-29 02:01:07.000000000 +0100
4366 @@ -161,9 +161,13 @@ struct dinode {
4367  
4368  #define JFS_APPEND_FL          0x01000000 /* writes to file may only append */
4369  #define JFS_IMMUTABLE_FL       0x02000000 /* Immutable file */
4370 +#define JFS_IXUNLINK_FL                0x08000000 /* Immutable invert on unlink */
4371  
4372 -#define JFS_FL_USER_VISIBLE    0x03F80000
4373 -#define JFS_FL_USER_MODIFIABLE 0x03F80000
4374 +#define JFS_BARRIER_FL         0x04000000 /* Barrier for chroot() */
4375 +#define JFS_COW_FL             0x20000000 /* Copy on Write marker */
4376 +
4377 +#define JFS_FL_USER_VISIBLE    0x07F80000
4378 +#define JFS_FL_USER_MODIFIABLE 0x07F80000
4379  #define JFS_FL_INHERIT         0x03C80000
4380  
4381  /* These are identical to EXT[23]_IOC_GETFLAGS/SETFLAGS */
4382 diff -NurpP --minimal linux-2.6.38-rc8/fs/jfs/jfs_filsys.h linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/jfs/jfs_filsys.h
4383 --- linux-2.6.38-rc8/fs/jfs/jfs_filsys.h        2008-12-25 00:26:37.000000000 +0100
4384 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/jfs/jfs_filsys.h 2011-01-29 02:01:07.000000000 +0100
4385 @@ -263,6 +263,7 @@
4386  #define JFS_NAME_MAX   255
4387  #define JFS_PATH_MAX   BPSIZE
4388  
4389 +#define JFS_TAGGED             0x00800000      /* Context Tagging */
4390  
4391  /*
4392   *     file system state (superblock state)
4393 diff -NurpP --minimal linux-2.6.38-rc8/fs/jfs/jfs_imap.c linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/jfs/jfs_imap.c
4394 --- linux-2.6.38-rc8/fs/jfs/jfs_imap.c  2011-01-05 21:50:24.000000000 +0100
4395 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/jfs/jfs_imap.c   2011-01-29 02:01:07.000000000 +0100
4396 @@ -46,6 +46,7 @@
4397  #include <linux/pagemap.h>
4398  #include <linux/quotaops.h>
4399  #include <linux/slab.h>
4400 +#include <linux/vs_tag.h>
4401  
4402  #include "jfs_incore.h"
4403  #include "jfs_inode.h"
4404 @@ -3060,6 +3061,8 @@ static int copy_from_dinode(struct dinod
4405  {
4406         struct jfs_inode_info *jfs_ip = JFS_IP(ip);
4407         struct jfs_sb_info *sbi = JFS_SBI(ip->i_sb);
4408 +       uid_t uid;
4409 +       gid_t gid;
4410  
4411         jfs_ip->fileset = le32_to_cpu(dip->di_fileset);
4412         jfs_ip->mode2 = le32_to_cpu(dip->di_mode);
4413 @@ -3080,14 +3083,18 @@ static int copy_from_dinode(struct dinod
4414         }
4415         ip->i_nlink = le32_to_cpu(dip->di_nlink);
4416  
4417 -       jfs_ip->saved_uid = le32_to_cpu(dip->di_uid);
4418 +       uid = le32_to_cpu(dip->di_uid);
4419 +       gid = le32_to_cpu(dip->di_gid);
4420 +       ip->i_tag = INOTAG_TAG(DX_TAG(ip), uid, gid, 0);
4421 +
4422 +       jfs_ip->saved_uid = INOTAG_UID(DX_TAG(ip), uid, gid);
4423         if (sbi->uid == -1)
4424                 ip->i_uid = jfs_ip->saved_uid;
4425         else {
4426                 ip->i_uid = sbi->uid;
4427         }
4428  
4429 -       jfs_ip->saved_gid = le32_to_cpu(dip->di_gid);
4430 +       jfs_ip->saved_gid = INOTAG_GID(DX_TAG(ip), uid, gid);
4431         if (sbi->gid == -1)
4432                 ip->i_gid = jfs_ip->saved_gid;
4433         else {
4434 @@ -3152,14 +3159,12 @@ static void copy_to_dinode(struct dinode
4435         dip->di_size = cpu_to_le64(ip->i_size);
4436         dip->di_nblocks = cpu_to_le64(PBLK2LBLK(ip->i_sb, ip->i_blocks));
4437         dip->di_nlink = cpu_to_le32(ip->i_nlink);
4438 -       if (sbi->uid == -1)
4439 -               dip->di_uid = cpu_to_le32(ip->i_uid);
4440 -       else
4441 -               dip->di_uid = cpu_to_le32(jfs_ip->saved_uid);
4442 -       if (sbi->gid == -1)
4443 -               dip->di_gid = cpu_to_le32(ip->i_gid);
4444 -       else
4445 -               dip->di_gid = cpu_to_le32(jfs_ip->saved_gid);
4446 +
4447 +       dip->di_uid = cpu_to_le32(TAGINO_UID(DX_TAG(ip),
4448 +               (sbi->uid == -1) ? ip->i_uid : jfs_ip->saved_uid, ip->i_tag));
4449 +       dip->di_gid = cpu_to_le32(TAGINO_GID(DX_TAG(ip),
4450 +               (sbi->gid == -1) ? ip->i_gid : jfs_ip->saved_gid, ip->i_tag));
4451 +
4452         jfs_get_inode_flags(jfs_ip);
4453         /*
4454          * mode2 is only needed for storing the higher order bits.
4455 diff -NurpP --minimal linux-2.6.38-rc8/fs/jfs/jfs_inode.c linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/jfs/jfs_inode.c
4456 --- linux-2.6.38-rc8/fs/jfs/jfs_inode.c 2010-08-02 16:52:49.000000000 +0200
4457 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/jfs/jfs_inode.c  2011-01-29 02:01:07.000000000 +0100
4458 @@ -18,6 +18,7 @@
4459  
4460  #include <linux/fs.h>
4461  #include <linux/quotaops.h>
4462 +#include <linux/vs_tag.h>
4463  #include "jfs_incore.h"
4464  #include "jfs_inode.h"
4465  #include "jfs_filsys.h"
4466 @@ -30,29 +31,46 @@ void jfs_set_inode_flags(struct inode *i
4467  {
4468         unsigned int flags = JFS_IP(inode)->mode2;
4469  
4470 -       inode->i_flags &= ~(S_IMMUTABLE | S_APPEND |
4471 -               S_NOATIME | S_DIRSYNC | S_SYNC);
4472 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
4473 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
4474  
4475         if (flags & JFS_IMMUTABLE_FL)
4476                 inode->i_flags |= S_IMMUTABLE;
4477 +       if (flags & JFS_IXUNLINK_FL)
4478 +               inode->i_flags |= S_IXUNLINK;
4479 +
4480 +       if (flags & JFS_SYNC_FL)
4481 +               inode->i_flags |= S_SYNC;
4482         if (flags & JFS_APPEND_FL)
4483                 inode->i_flags |= S_APPEND;
4484         if (flags & JFS_NOATIME_FL)
4485                 inode->i_flags |= S_NOATIME;
4486         if (flags & JFS_DIRSYNC_FL)
4487                 inode->i_flags |= S_DIRSYNC;
4488 -       if (flags & JFS_SYNC_FL)
4489 -               inode->i_flags |= S_SYNC;
4490 +
4491 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
4492 +
4493 +       if (flags & JFS_BARRIER_FL)
4494 +               inode->i_vflags |= V_BARRIER;
4495 +       if (flags & JFS_COW_FL)
4496 +               inode->i_vflags |= V_COW;
4497  }
4498  
4499  void jfs_get_inode_flags(struct jfs_inode_info *jfs_ip)
4500  {
4501         unsigned int flags = jfs_ip->vfs_inode.i_flags;
4502 +       unsigned int vflags = jfs_ip->vfs_inode.i_vflags;
4503 +
4504 +       jfs_ip->mode2 &= ~(JFS_IMMUTABLE_FL | JFS_IXUNLINK_FL |
4505 +                          JFS_APPEND_FL | JFS_NOATIME_FL |
4506 +                          JFS_DIRSYNC_FL | JFS_SYNC_FL |
4507 +                          JFS_BARRIER_FL | JFS_COW_FL);
4508  
4509 -       jfs_ip->mode2 &= ~(JFS_IMMUTABLE_FL | JFS_APPEND_FL | JFS_NOATIME_FL |
4510 -                          JFS_DIRSYNC_FL | JFS_SYNC_FL);
4511         if (flags & S_IMMUTABLE)
4512                 jfs_ip->mode2 |= JFS_IMMUTABLE_FL;
4513 +       if (flags & S_IXUNLINK)
4514 +               jfs_ip->mode2 |= JFS_IXUNLINK_FL;
4515 +
4516         if (flags & S_APPEND)
4517                 jfs_ip->mode2 |= JFS_APPEND_FL;
4518         if (flags & S_NOATIME)
4519 @@ -61,6 +79,11 @@ void jfs_get_inode_flags(struct jfs_inod
4520                 jfs_ip->mode2 |= JFS_DIRSYNC_FL;
4521         if (flags & S_SYNC)
4522                 jfs_ip->mode2 |= JFS_SYNC_FL;
4523 +
4524 +       if (vflags & V_BARRIER)
4525 +               jfs_ip->mode2 |= JFS_BARRIER_FL;
4526 +       if (vflags & V_COW)
4527 +               jfs_ip->mode2 |= JFS_COW_FL;
4528  }
4529  
4530  /*
4531 diff -NurpP --minimal linux-2.6.38-rc8/fs/jfs/jfs_inode.h linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/jfs/jfs_inode.h
4532 --- linux-2.6.38-rc8/fs/jfs/jfs_inode.h 2010-10-21 13:07:50.000000000 +0200
4533 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/jfs/jfs_inode.h  2011-01-29 02:01:07.000000000 +0100
4534 @@ -39,6 +39,7 @@ extern struct dentry *jfs_fh_to_dentry(s
4535  extern struct dentry *jfs_fh_to_parent(struct super_block *sb, struct fid *fid,
4536         int fh_len, int fh_type);
4537  extern void jfs_set_inode_flags(struct inode *);
4538 +extern int jfs_sync_flags(struct inode *, int, int);
4539  extern int jfs_get_block(struct inode *, sector_t, struct buffer_head *, int);
4540  extern int jfs_setattr(struct dentry *, struct iattr *);
4541  
4542 diff -NurpP --minimal linux-2.6.38-rc8/fs/jfs/namei.c linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/jfs/namei.c
4543 --- linux-2.6.38-rc8/fs/jfs/namei.c     2011-03-10 17:09:23.000000000 +0100
4544 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/jfs/namei.c      2011-01-29 02:49:04.000000000 +0100
4545 @@ -22,6 +22,7 @@
4546  #include <linux/ctype.h>
4547  #include <linux/quotaops.h>
4548  #include <linux/exportfs.h>
4549 +#include <linux/vs_tag.h>
4550  #include "jfs_incore.h"
4551  #include "jfs_superblock.h"
4552  #include "jfs_inode.h"
4553 @@ -1489,6 +1490,7 @@ static struct dentry *jfs_lookup(struct 
4554                 return ERR_CAST(ip);
4555         }
4556  
4557 +       dx_propagate_tag(nd, ip);
4558         return d_splice_alias(ip, dentry);
4559  }
4560  
4561 @@ -1553,6 +1555,7 @@ const struct inode_operations jfs_dir_in
4562  #ifdef CONFIG_JFS_POSIX_ACL
4563         .check_acl      = jfs_check_acl,
4564  #endif
4565 +       .sync_flags     = jfs_sync_flags,
4566  };
4567  
4568  const struct file_operations jfs_dir_operations = {
4569 diff -NurpP --minimal linux-2.6.38-rc8/fs/jfs/super.c linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/jfs/super.c
4570 --- linux-2.6.38-rc8/fs/jfs/super.c     2011-03-10 17:09:23.000000000 +0100
4571 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/jfs/super.c      2011-01-29 02:01:07.000000000 +0100
4572 @@ -198,7 +198,8 @@ static void jfs_put_super(struct super_b
4573  enum {
4574         Opt_integrity, Opt_nointegrity, Opt_iocharset, Opt_resize,
4575         Opt_resize_nosize, Opt_errors, Opt_ignore, Opt_err, Opt_quota,
4576 -       Opt_usrquota, Opt_grpquota, Opt_uid, Opt_gid, Opt_umask
4577 +       Opt_usrquota, Opt_grpquota, Opt_uid, Opt_gid, Opt_umask,
4578 +       Opt_tag, Opt_notag, Opt_tagid
4579  };
4580  
4581  static const match_table_t tokens = {
4582 @@ -208,6 +209,10 @@ static const match_table_t tokens = {
4583         {Opt_resize, "resize=%u"},
4584         {Opt_resize_nosize, "resize"},
4585         {Opt_errors, "errors=%s"},
4586 +       {Opt_tag, "tag"},
4587 +       {Opt_notag, "notag"},
4588 +       {Opt_tagid, "tagid=%u"},
4589 +       {Opt_tag, "tagxid"},
4590         {Opt_ignore, "noquota"},
4591         {Opt_ignore, "quota"},
4592         {Opt_usrquota, "usrquota"},
4593 @@ -342,6 +347,20 @@ static int parse_options(char *options, 
4594                         }
4595                         break;
4596                 }
4597 +#ifndef CONFIG_TAGGING_NONE
4598 +               case Opt_tag:
4599 +                       *flag |= JFS_TAGGED;
4600 +                       break;
4601 +               case Opt_notag:
4602 +                       *flag &= JFS_TAGGED;
4603 +                       break;
4604 +#endif
4605 +#ifdef CONFIG_PROPAGATE
4606 +               case Opt_tagid:
4607 +                       /* use args[0] */
4608 +                       *flag |= JFS_TAGGED;
4609 +                       break;
4610 +#endif
4611                 default:
4612                         printk("jfs: Unrecognized mount option \"%s\" "
4613                                         " or missing value\n", p);
4614 @@ -373,6 +392,12 @@ static int jfs_remount(struct super_bloc
4615                 return -EINVAL;
4616         }
4617  
4618 +       if ((flag & JFS_TAGGED) && !(sb->s_flags & MS_TAGGED)) {
4619 +               printk(KERN_ERR "JFS: %s: tagging not permitted on remount.\n",
4620 +                       sb->s_id);
4621 +               return -EINVAL;
4622 +       }
4623 +
4624         if (newLVSize) {
4625                 if (sb->s_flags & MS_RDONLY) {
4626                         printk(KERN_ERR
4627 @@ -455,6 +480,9 @@ static int jfs_fill_super(struct super_b
4628  #ifdef CONFIG_JFS_POSIX_ACL
4629         sb->s_flags |= MS_POSIXACL;
4630  #endif
4631 +       /* map mount option tagxid */
4632 +       if (sbi->flag & JFS_TAGGED)
4633 +               sb->s_flags |= MS_TAGGED;
4634  
4635         if (newLVSize) {
4636                 printk(KERN_ERR "resize option for remount only\n");
4637 diff -NurpP --minimal linux-2.6.38-rc8/fs/libfs.c linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/libfs.c
4638 --- linux-2.6.38-rc8/fs/libfs.c 2011-03-10 17:09:23.000000000 +0100
4639 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/libfs.c  2011-01-29 05:03:51.000000000 +0100
4640 @@ -133,7 +133,8 @@ static inline unsigned char dt_type(stru
4641   * both impossible due to the lock on directory.
4642   */
4643  
4644 -int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
4645 +static inline int do_dcache_readdir_filter(struct file *filp,
4646 +       void *dirent, filldir_t filldir, int (*filter)(struct dentry *dentry))
4647  {
4648         struct dentry *dentry = filp->f_path.dentry;
4649         struct dentry *cursor = filp->private_data;
4650 @@ -164,6 +165,8 @@ int dcache_readdir(struct file * filp, v
4651                         for (p=q->next; p != &dentry->d_subdirs; p=p->next) {
4652                                 struct dentry *next;
4653                                 next = list_entry(p, struct dentry, d_u.d_child);
4654 +                               if (filter && !filter(next))
4655 +                                       continue;
4656                                 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
4657                                 if (!simple_positive(next)) {
4658                                         spin_unlock(&next->d_lock);
4659 @@ -190,6 +193,17 @@ int dcache_readdir(struct file * filp, v
4660         return 0;
4661  }
4662  
4663 +int dcache_readdir(struct file *filp, void *dirent, filldir_t filldir)
4664 +{
4665 +       return do_dcache_readdir_filter(filp, dirent, filldir, NULL);
4666 +}
4667 +
4668 +int dcache_readdir_filter(struct file *filp, void *dirent, filldir_t filldir,
4669 +       int (*filter)(struct dentry *))
4670 +{
4671 +       return do_dcache_readdir_filter(filp, dirent, filldir, filter);
4672 +}
4673 +
4674  ssize_t generic_read_dir(struct file *filp, char __user *buf, size_t siz, loff_t *ppos)
4675  {
4676         return -EISDIR;
4677 @@ -965,6 +979,7 @@ EXPORT_SYMBOL(dcache_dir_close);
4678  EXPORT_SYMBOL(dcache_dir_lseek);
4679  EXPORT_SYMBOL(dcache_dir_open);
4680  EXPORT_SYMBOL(dcache_readdir);
4681 +EXPORT_SYMBOL(dcache_readdir_filter);
4682  EXPORT_SYMBOL(generic_read_dir);
4683  EXPORT_SYMBOL(mount_pseudo);
4684  EXPORT_SYMBOL(simple_write_begin);
4685 diff -NurpP --minimal linux-2.6.38-rc8/fs/locks.c linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/locks.c
4686 --- linux-2.6.38-rc8/fs/locks.c 2011-03-10 17:09:23.000000000 +0100
4687 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/locks.c  2011-01-29 02:01:07.000000000 +0100
4688 @@ -126,6 +126,8 @@
4689  #include <linux/time.h>
4690  #include <linux/rcupdate.h>
4691  #include <linux/pid_namespace.h>
4692 +#include <linux/vs_base.h>
4693 +#include <linux/vs_limit.h>
4694  
4695  #include <asm/uaccess.h>
4696  
4697 @@ -164,6 +166,8 @@ static struct kmem_cache *filelock_cache
4698  /* Allocate an empty lock structure. */
4699  struct file_lock *locks_alloc_lock(void)
4700  {
4701 +       if (!vx_locks_avail(1))
4702 +               return NULL;
4703         return kmem_cache_alloc(filelock_cache, GFP_KERNEL);
4704  }
4705  EXPORT_SYMBOL_GPL(locks_alloc_lock);
4706 @@ -191,6 +195,7 @@ void locks_free_lock(struct file_lock *f
4707         BUG_ON(!list_empty(&fl->fl_block));
4708         BUG_ON(!list_empty(&fl->fl_link));
4709  
4710 +       vx_locks_dec(fl);
4711         locks_release_private(fl);
4712         kmem_cache_free(filelock_cache, fl);
4713  }
4714 @@ -212,6 +217,7 @@ void locks_init_lock(struct file_lock *f
4715         fl->fl_start = fl->fl_end = 0;
4716         fl->fl_ops = NULL;
4717         fl->fl_lmops = NULL;
4718 +       fl->fl_xid = -1;
4719  }
4720  
4721  EXPORT_SYMBOL(locks_init_lock);
4722 @@ -263,6 +269,7 @@ void locks_copy_lock(struct file_lock *n
4723         new->fl_file = fl->fl_file;
4724         new->fl_ops = fl->fl_ops;
4725         new->fl_lmops = fl->fl_lmops;
4726 +       new->fl_xid = fl->fl_xid;
4727  
4728         locks_copy_private(new, fl);
4729  }
4730 @@ -301,6 +308,11 @@ static int flock_make_lock(struct file *
4731         fl->fl_flags = FL_FLOCK;
4732         fl->fl_type = type;
4733         fl->fl_end = OFFSET_MAX;
4734 +
4735 +       vxd_assert(filp->f_xid == vx_current_xid(),
4736 +               "f_xid(%d) == current(%d)", filp->f_xid, vx_current_xid());
4737 +       fl->fl_xid = filp->f_xid;
4738 +       vx_locks_inc(fl);
4739         
4740         *lock = fl;
4741         return 0;
4742 @@ -460,6 +472,7 @@ static int lease_init(struct file *filp,
4743  
4744         fl->fl_owner = current->files;
4745         fl->fl_pid = current->tgid;
4746 +       fl->fl_xid = vx_current_xid();
4747  
4748         fl->fl_file = filp;
4749         fl->fl_flags = FL_LEASE;
4750 @@ -479,6 +492,11 @@ static struct file_lock *lease_alloc(str
4751         if (fl == NULL)
4752                 return ERR_PTR(error);
4753  
4754 +       fl->fl_xid = vx_current_xid();
4755 +       if (filp)
4756 +               vxd_assert(filp->f_xid == fl->fl_xid,
4757 +                       "f_xid(%d) == fl_xid(%d)", filp->f_xid, fl->fl_xid);
4758 +       vx_locks_inc(fl);
4759         error = lease_init(filp, type, fl);
4760         if (error) {
4761                 locks_free_lock(fl);
4762 @@ -780,6 +798,7 @@ static int flock_lock_file(struct file *
4763                 lock_flocks();
4764         }
4765  
4766 +       new_fl->fl_xid = -1;
4767  find_conflict:
4768         for_each_lock(inode, before) {
4769                 struct file_lock *fl = *before;
4770 @@ -800,6 +819,7 @@ find_conflict:
4771                 goto out;
4772         locks_copy_lock(new_fl, request);
4773         locks_insert_lock(before, new_fl);
4774 +       vx_locks_inc(new_fl);
4775         new_fl = NULL;
4776         error = 0;
4777  
4778 @@ -810,7 +830,8 @@ out:
4779         return error;
4780  }
4781  
4782 -static int __posix_lock_file(struct inode *inode, struct file_lock *request, struct file_lock *conflock)
4783 +static int __posix_lock_file(struct inode *inode, struct file_lock *request,
4784 +       struct file_lock *conflock, xid_t xid)
4785  {
4786         struct file_lock *fl;
4787         struct file_lock *new_fl = NULL;
4788 @@ -820,6 +841,8 @@ static int __posix_lock_file(struct inod
4789         struct file_lock **before;
4790         int error, added = 0;
4791  
4792 +       vxd_assert(xid == vx_current_xid(),
4793 +               "xid(%d) == current(%d)", xid, vx_current_xid());
4794         /*
4795          * We may need two file_lock structures for this operation,
4796          * so we get them in advance to avoid races.
4797 @@ -830,7 +853,11 @@ static int __posix_lock_file(struct inod
4798             (request->fl_type != F_UNLCK ||
4799              request->fl_start != 0 || request->fl_end != OFFSET_MAX)) {
4800                 new_fl = locks_alloc_lock();
4801 +               new_fl->fl_xid = xid;
4802 +               vx_locks_inc(new_fl);
4803                 new_fl2 = locks_alloc_lock();
4804 +               new_fl2->fl_xid = xid;
4805 +               vx_locks_inc(new_fl2);
4806         }
4807  
4808         lock_flocks();
4809 @@ -1029,7 +1056,8 @@ static int __posix_lock_file(struct inod
4810  int posix_lock_file(struct file *filp, struct file_lock *fl,
4811                         struct file_lock *conflock)
4812  {
4813 -       return __posix_lock_file(filp->f_path.dentry->d_inode, fl, conflock);
4814 +       return __posix_lock_file(filp->f_path.dentry->d_inode,
4815 +               fl, conflock, filp->f_xid);
4816  }
4817  EXPORT_SYMBOL(posix_lock_file);
4818  
4819 @@ -1119,7 +1147,7 @@ int locks_mandatory_area(int read_write,
4820         fl.fl_end = offset + count - 1;
4821  
4822         for (;;) {
4823 -               error = __posix_lock_file(inode, &fl, NULL);
4824 +               error = __posix_lock_file(inode, &fl, NULL, filp->f_xid);
4825                 if (error != FILE_LOCK_DEFERRED)
4826                         break;
4827                 error = wait_event_interruptible(fl.fl_wait, !fl.fl_next);
4828 @@ -1432,6 +1460,7 @@ int generic_setlease(struct file *filp, 
4829                 goto out;
4830  
4831         locks_insert_lock(before, lease);
4832 +       vx_locks_inc(lease);
4833         return 0;
4834  
4835  out:
4836 @@ -1816,6 +1845,11 @@ int fcntl_setlk(unsigned int fd, struct 
4837         if (file_lock == NULL)
4838                 return -ENOLCK;
4839  
4840 +       vxd_assert(filp->f_xid == vx_current_xid(),
4841 +               "f_xid(%d) == current(%d)", filp->f_xid, vx_current_xid());
4842 +       file_lock->fl_xid = filp->f_xid;
4843 +       vx_locks_inc(file_lock);
4844 +
4845         /*
4846          * This might block, so we do it before checking the inode.
4847          */
4848 @@ -1934,6 +1968,11 @@ int fcntl_setlk64(unsigned int fd, struc
4849         if (file_lock == NULL)
4850                 return -ENOLCK;
4851  
4852 +       vxd_assert(filp->f_xid == vx_current_xid(),
4853 +               "f_xid(%d) == current(%d)", filp->f_xid, vx_current_xid());
4854 +       file_lock->fl_xid = filp->f_xid;
4855 +       vx_locks_inc(file_lock);
4856 +
4857         /*
4858          * This might block, so we do it before checking the inode.
4859          */
4860 @@ -2199,8 +2238,11 @@ static int locks_show(struct seq_file *f
4861  
4862         lock_get_status(f, fl, *((loff_t *)f->private), "");
4863  
4864 -       list_for_each_entry(bfl, &fl->fl_block, fl_block)
4865 +       list_for_each_entry(bfl, &fl->fl_block, fl_block) {
4866 +               if (!vx_check(fl->fl_xid, VS_WATCH_P | VS_IDENT))
4867 +                       continue;
4868                 lock_get_status(f, bfl, *((loff_t *)f->private), " ->");
4869 +       }
4870  
4871         return 0;
4872  }
4873 diff -NurpP --minimal linux-2.6.38-rc8/fs/namei.c linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/namei.c
4874 --- linux-2.6.38-rc8/fs/namei.c 2011-03-10 17:09:23.000000000 +0100
4875 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/namei.c  2011-03-07 16:53:27.000000000 +0100
4876 @@ -32,6 +32,14 @@
4877  #include <linux/fcntl.h>
4878  #include <linux/device_cgroup.h>
4879  #include <linux/fs_struct.h>
4880 +#include <linux/proc_fs.h>
4881 +#include <linux/vserver/inode.h>
4882 +#include <linux/vs_base.h>
4883 +#include <linux/vs_tag.h>
4884 +#include <linux/vs_cowbl.h>
4885 +#include <linux/vs_device.h>
4886 +#include <linux/vs_context.h>
4887 +#include <linux/pid_namespace.h>
4888  #include <asm/uaccess.h>
4889  
4890  #include "internal.h"
4891 @@ -166,6 +174,84 @@ void putname(const char *name)
4892  EXPORT_SYMBOL(putname);
4893  #endif
4894  
4895 +static inline int dx_barrier(const struct inode *inode)
4896 +{
4897 +       if (IS_BARRIER(inode) && !vx_check(0, VS_ADMIN | VS_WATCH)) {
4898 +               vxwprintk_task(1, "did hit the barrier.");
4899 +               return 1;
4900 +       }
4901 +       return 0;
4902 +}
4903 +
4904 +static int __dx_permission(const struct inode *inode, int mask)
4905 +{
4906 +       if (dx_barrier(inode))
4907 +               return -EACCES;
4908 +
4909 +       if (inode->i_sb->s_magic == DEVPTS_SUPER_MAGIC) {
4910 +               /* devpts is xid tagged */
4911 +               if (S_ISDIR(inode->i_mode) ||
4912 +                   vx_check((xid_t)inode->i_tag, VS_IDENT | VS_WATCH_P))
4913 +                       return 0;
4914 +
4915 +               /* just pretend we didn't find anything */
4916 +               return -ENOENT;
4917 +       }
4918 +       else if (inode->i_sb->s_magic == PROC_SUPER_MAGIC) {
4919 +               struct proc_dir_entry *de = PDE(inode);
4920 +
4921 +               if (de && !vx_hide_check(0, de->vx_flags))
4922 +                       goto out;
4923 +
4924 +               if ((mask & (MAY_WRITE | MAY_APPEND))) {
4925 +                       struct pid *pid;
4926 +                       struct task_struct *tsk;
4927 +
4928 +                       if (vx_check(0, VS_ADMIN | VS_WATCH_P) ||
4929 +                           vx_flags(VXF_STATE_SETUP, 0))
4930 +                               return 0;
4931 +
4932 +                       pid = PROC_I(inode)->pid;
4933 +                       if (!pid)
4934 +                               goto out;
4935 +
4936 +                       tsk = pid_task(pid, PIDTYPE_PID);
4937 +                       vxdprintk(VXD_CBIT(tag, 0), "accessing %p[#%u]",
4938 +                                 tsk, (tsk ? vx_task_xid(tsk) : 0));
4939 +                       if (tsk && vx_check(vx_task_xid(tsk), VS_IDENT | VS_WATCH_P))
4940 +                               return 0;
4941 +               }
4942 +               else {
4943 +                       /* FIXME: Should we block some entries here? */
4944 +                       return 0;
4945 +               }
4946 +       }
4947 +       else {
4948 +               if (dx_notagcheck(inode->i_sb) ||
4949 +                   dx_check(inode->i_tag, DX_HOSTID | DX_ADMIN | DX_WATCH |
4950 +                            DX_IDENT))
4951 +                       return 0;
4952 +       }
4953 +
4954 +out:
4955 +       return -EACCES;
4956 +}
4957 +
4958 +int dx_permission(const struct inode *inode, int mask)
4959 +{
4960 +       int ret = __dx_permission(inode, mask);
4961 +       if (unlikely(ret)) {
4962 +#ifndef        CONFIG_VSERVER_WARN_DEVPTS
4963 +               if (inode->i_sb->s_magic != DEVPTS_SUPER_MAGIC)
4964 +#endif
4965 +                   vxwprintk_task(1,
4966 +                       "denied [0x%x] access to inode %s:%p[#%d,%lu]",
4967 +                       mask, inode->i_sb->s_id, inode, inode->i_tag,
4968 +                       inode->i_ino);
4969 +       }
4970 +       return ret;
4971 +}
4972 +
4973  /*
4974   * This does basic POSIX ACL permission checking
4975   */
4976 @@ -271,10 +357,14 @@ int inode_permission(struct inode *inode
4977                 /*
4978                  * Nobody gets write access to an immutable file.
4979                  */
4980 -               if (IS_IMMUTABLE(inode))
4981 +               if (IS_IMMUTABLE(inode) && !IS_COW(inode))
4982                         return -EACCES;
4983         }
4984  
4985 +       retval = dx_permission(inode, mask);
4986 +       if (retval)
4987 +               return retval;
4988 +
4989         if (inode->i_op->permission)
4990                 retval = inode->i_op->permission(inode, mask, 0);
4991         else
4992 @@ -676,6 +766,9 @@ static inline int exec_permission(struct
4993  {
4994         int ret;
4995  
4996 +       if (dx_barrier(inode))
4997 +               return -EACCES;
4998 +
4999         if (inode->i_op->permission) {
5000                 ret = inode->i_op->permission(inode, MAY_EXEC, flags);
5001         } else {
5002 @@ -1162,7 +1255,8 @@ static void follow_dotdot(struct nameida
5003  
5004                 if (nd->path.dentry == nd->root.dentry &&
5005                     nd->path.mnt == nd->root.mnt) {
5006 -                       break;
5007 +                       /* for sane '/' avoid follow_mount() */
5008 +                       return;
5009                 }
5010                 if (nd->path.dentry != nd->path.mnt->mnt_root) {
5011                         /* rare case of legitimate dget_parent()... */
5012 @@ -1216,7 +1310,7 @@ static int do_lookup(struct nameidata *n
5013  {
5014         struct vfsmount *mnt = nd->path.mnt;
5015         struct dentry *dentry, *parent = nd->path.dentry;
5016 -       struct inode *dir;
5017 +       struct inode *dir, *d_inode;
5018         int err;
5019  
5020         /*
5021 @@ -1277,6 +1371,13 @@ found:
5022                 if (IS_ERR(dentry))
5023                         goto fail;
5024         }
5025 +
5026 +       d_inode = dentry->d_inode;
5027 +       if (!d_inode)
5028 +               goto done;
5029 +
5030 +       if (__dx_permission(d_inode, MAY_ACCESS))
5031 +               goto hidden;
5032  done:
5033         path->mnt = mnt;
5034         path->dentry = dentry;
5035 @@ -1288,6 +1389,18 @@ done:
5036         *inode = path->dentry->d_inode;
5037         return 0;
5038  
5039 +hidden:
5040 +#ifndef        CONFIG_VSERVER_WARN_DEVPTS
5041 +       if (d_inode->i_sb->s_magic != DEVPTS_SUPER_MAGIC)
5042 +#endif
5043 +           vxwprintk_task(1,
5044 +               "did lookup hidden %s:%p[#%d,%lu] " VS_Q("%s/%.*s") ".",
5045 +               d_inode->i_sb->s_id, d_inode, d_inode->i_tag, d_inode->i_ino,
5046 +               vxd_path(&nd->path), name->len, name->name);
5047 +
5048 +       dput(dentry);
5049 +       return -ENOENT;
5050 +
5051  need_lookup:
5052         dir = parent->d_inode;
5053         BUG_ON(nd->inode != dir);
5054 @@ -1981,7 +2094,7 @@ static int may_delete(struct inode *dir,
5055         if (IS_APPEND(dir))
5056                 return -EPERM;
5057         if (check_sticky(dir, victim->d_inode)||IS_APPEND(victim->d_inode)||
5058 -           IS_IMMUTABLE(victim->d_inode) || IS_SWAPFILE(victim->d_inode))
5059 +               IS_IXORUNLINK(victim->d_inode) || IS_SWAPFILE(victim->d_inode))
5060                 return -EPERM;
5061         if (isdir) {
5062                 if (!S_ISDIR(victim->d_inode->i_mode))
5063 @@ -2104,6 +2217,14 @@ int may_open(struct path *path, int acc_
5064                 break;
5065         }
5066  
5067 +#ifdef CONFIG_VSERVER_COWBL
5068 +       if (IS_COW(inode) && (flag & FMODE_WRITE)) {
5069 +               if (IS_COW_LINK(inode))
5070 +                       return -EMLINK;
5071 +               inode->i_flags &= ~(S_IXUNLINK|S_IMMUTABLE);
5072 +               mark_inode_dirty(inode);
5073 +       }
5074 +#endif
5075         error = inode_permission(inode, acc_mode);
5076         if (error)
5077                 return error;
5078 @@ -2214,7 +2335,8 @@ static int open_will_truncate(int flag, 
5079  }
5080  
5081  static struct file *finish_open(struct nameidata *nd,
5082 -                               int open_flag, int acc_mode)
5083 +                               int open_flag, int acc_mode,
5084 +                               const char *pathname)
5085  {
5086         struct file *filp;
5087         int will_truncate;
5088 @@ -2227,6 +2349,23 @@ static struct file *finish_open(struct n
5089                         goto exit;
5090         }
5091         error = may_open(&nd->path, acc_mode, open_flag);
5092 +#ifdef CONFIG_VSERVER_COWBL
5093 +       if (error == -EMLINK) {
5094 +               struct dentry *dentry;
5095 +               dentry = cow_break_link(pathname);
5096 +               if (IS_ERR(dentry)) {
5097 +                       error = PTR_ERR(dentry);
5098 +                       goto exit_cow;
5099 +               }
5100 +               dput(dentry);
5101 +               if (will_truncate)
5102 +                       mnt_drop_write(nd->path.mnt);
5103 +               release_open_intent(nd);
5104 +               path_put(&nd->path);
5105 +               return ERR_PTR(-EMLINK);
5106 +       }
5107 +exit_cow:
5108 +#endif
5109         if (error) {
5110                 if (will_truncate)
5111                         mnt_drop_write(nd->path.mnt);
5112 @@ -2374,7 +2513,7 @@ static struct file *do_last(struct namei
5113         if (S_ISDIR(nd->inode->i_mode))
5114                 goto exit;
5115  ok:
5116 -       filp = finish_open(nd, open_flag, acc_mode);
5117 +       filp = finish_open(nd, open_flag, acc_mode, pathname);
5118         return filp;
5119  
5120  exit_mutex_unlock:
5121 @@ -2401,7 +2540,12 @@ struct file *do_filp_open(int dfd, const
5122         int count = 0;
5123         int flag = open_to_namei_flags(open_flag);
5124         int flags;
5125 +#ifdef CONFIG_VSERVER_COWBL
5126 +       int rflag = flag;
5127 +       int rmode = mode;
5128  
5129 +restart:
5130 +#endif
5131         if (!(open_flag & O_CREAT))
5132                 mode = 0;
5133
5134 @@ -2612,7 +2612,7 @@
5135                         goto out_path2;
5136         }
5137         audit_inode(pathname, nd.path.dentry);
5138 -       filp = finish_open(&nd, open_flag, acc_mode);
5139 +       filp = finish_open(&nd, open_flag, acc_mode, pathname);
5140  out2:
5141         release_open_intent(&nd);
5142         return filp;
5143 @@ -2502,6 +2646,13 @@ reval:
5144          */
5145         nd.flags = flags;
5146         filp = do_last(&nd, &path, open_flag, acc_mode, mode, pathname);
5147 +#ifdef CONFIG_VSERVER_COWBL
5148 +       if (unlikely(IS_ERR(filp) && PTR_ERR(filp) == -EMLINK)) {
5149 +               flag = rflag;
5150 +               mode = rmode;
5151 +               goto restart;
5152 +       }
5153 +#endif
5154         while (unlikely(!filp)) { /* trailing symlink */
5155                 struct path link = path;
5156                 struct inode *linki = link.dentry->d_inode;
5157 @@ -2536,6 +2687,13 @@ reval:
5158                 }
5159                 nd.flags &= ~LOOKUP_PARENT;
5160                 filp = do_last(&nd, &path, open_flag, acc_mode, mode, pathname);
5161 +#ifdef CONFIG_VSERVER_COWBL
5162 +               if (unlikely(IS_ERR(filp) && PTR_ERR(filp) == -EMLINK)) {
5163 +                       flag = rflag;
5164 +                       mode = rmode;
5165 +                       goto restart;
5166 +               }
5167 +#endif
5168                 if (linki->i_op->put_link)
5169                         linki->i_op->put_link(link.dentry, &nd, cookie);
5170                 path_put(&link);
5171 @@ -2634,9 +2792,17 @@ int vfs_mknod(struct inode *dir, struct 
5172         if (error)
5173                 return error;
5174  
5175 -       if ((S_ISCHR(mode) || S_ISBLK(mode)) && !capable(CAP_MKNOD))
5176 +       if (!(S_ISCHR(mode) || S_ISBLK(mode)))
5177 +               goto okay;
5178 +
5179 +       if (!capable(CAP_MKNOD))
5180                 return -EPERM;
5181  
5182 +       if (S_ISCHR(mode) && !vs_chrdev_perm(dev, DATTR_CREATE))
5183 +               return -EPERM;
5184 +       if (S_ISBLK(mode) && !vs_blkdev_perm(dev, DATTR_CREATE))
5185 +               return -EPERM;
5186 +okay:
5187         if (!dir->i_op->mknod)
5188                 return -EPERM;
5189  
5190 @@ -3099,7 +3265,7 @@ int vfs_link(struct dentry *old_dentry, 
5191         /*
5192          * A link to an append-only or immutable file cannot be created.
5193          */
5194 -       if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
5195 +       if (IS_APPEND(inode) || IS_IXORUNLINK(inode))
5196                 return -EPERM;
5197         if (!dir->i_op->link)
5198                 return -EPERM;
5199 @@ -3471,6 +3637,222 @@ int vfs_follow_link(struct nameidata *nd
5200         return __vfs_follow_link(nd, link);
5201  }
5202  
5203 +
5204 +#ifdef CONFIG_VSERVER_COWBL
5205 +
5206 +#include <linux/file.h>
5207 +
5208 +static inline
5209 +long do_cow_splice(struct file *in, struct file *out, size_t len)
5210 +{
5211 +       loff_t ppos = 0;
5212 +
5213 +       return do_splice_direct(in, &ppos, out, len, 0);
5214 +}
5215 +
5216 +struct dentry *cow_break_link(const char *pathname)
5217 +{
5218 +       int ret, mode, pathlen, redo = 0;
5219 +       struct nameidata old_nd, dir_nd;
5220 +       struct path old_path, new_path;
5221 +       struct dentry *dir, *res = NULL;
5222 +       struct file *old_file;
5223 +       struct file *new_file;
5224 +       char *to, *path, pad='\251';
5225 +       loff_t size;
5226 +
5227 +       vxdprintk(VXD_CBIT(misc, 1),
5228 +               "cow_break_link(" VS_Q("%s") ")", pathname);
5229 +       path = kmalloc(PATH_MAX, GFP_KERNEL);
5230 +       ret = -ENOMEM;
5231 +       if (!path)
5232 +               goto out;
5233 +
5234 +       /* old_nd will have refs to dentry and mnt */
5235 +       ret = path_lookup(pathname, LOOKUP_FOLLOW, &old_nd);
5236 +       vxdprintk(VXD_CBIT(misc, 2), "path_lookup(old): %d", ret);
5237 +       if (ret < 0)
5238 +               goto out_free_path;
5239 +
5240 +       old_path = old_nd.path;
5241 +       mode = old_path.dentry->d_inode->i_mode;
5242 +
5243 +       to = d_path(&old_path, path, PATH_MAX-2);
5244 +       pathlen = strlen(to);
5245 +       vxdprintk(VXD_CBIT(misc, 2),
5246 +               "old path " VS_Q("%s") " [" VS_Q("%.*s") ":%d]", to,
5247 +               old_path.dentry->d_name.len, old_path.dentry->d_name.name,
5248 +               old_path.dentry->d_name.len);
5249 +
5250 +       to[pathlen + 1] = 0;
5251 +retry:
5252 +       to[pathlen] = pad--;
5253 +       ret = -EMLINK;
5254 +       if (pad <= '\240')
5255 +               goto out_rel_old;
5256 +
5257 +       vxdprintk(VXD_CBIT(misc, 1), "temp copy " VS_Q("%s"), to);
5258 +       /* dir_nd will have refs to dentry and mnt */
5259 +       ret = path_lookup(to,
5260 +               LOOKUP_PARENT | LOOKUP_OPEN | LOOKUP_CREATE, &dir_nd);
5261 +       vxdprintk(VXD_CBIT(misc, 2),
5262 +               "path_lookup(new): %d", ret);
5263 +       if (ret < 0)
5264 +               goto retry;
5265 +
5266 +       /* this puppy downs the inode mutex */
5267 +       new_path.dentry = lookup_create(&dir_nd, 0);
5268 +       if (!new_path.dentry || IS_ERR(new_path.dentry)) {
5269 +               vxdprintk(VXD_CBIT(misc, 2),
5270 +                       "lookup_create(new): %p", new_path.dentry);
5271 +               mutex_unlock(&dir_nd.path.dentry->d_inode->i_mutex);
5272 +               path_put(&dir_nd.path);
5273 +               goto retry;
5274 +       }
5275 +       vxdprintk(VXD_CBIT(misc, 2),
5276 +               "lookup_create(new): %p [" VS_Q("%.*s") ":%d]",
5277 +               new_path.dentry,
5278 +               new_path.dentry->d_name.len, new_path.dentry->d_name.name,
5279 +               new_path.dentry->d_name.len);
5280 +       dir = dir_nd.path.dentry;
5281 +
5282 +       ret = vfs_create(dir_nd.path.dentry->d_inode, new_path.dentry, mode, &dir_nd);
5283 +       vxdprintk(VXD_CBIT(misc, 2),
5284 +               "vfs_create(new): %d", ret);
5285 +       if (ret == -EEXIST) {
5286 +               mutex_unlock(&dir->d_inode->i_mutex);
5287 +               dput(new_path.dentry);
5288 +               path_put(&dir_nd.path);
5289 +               goto retry;
5290 +       }
5291 +       else if (ret < 0)
5292 +               goto out_unlock_new;
5293 +
5294 +       /* drop out early, ret passes ENOENT */
5295 +       ret = -ENOENT;
5296 +       if ((redo = d_unhashed(old_path.dentry)))
5297 +               goto out_unlock_new;
5298 +
5299 +       new_path.mnt = dir_nd.path.mnt;
5300 +       dget(old_path.dentry);
5301 +       mntget(old_path.mnt);
5302 +       /* this one cleans up the dentry/mnt in case of failure */
5303 +       old_file = dentry_open(old_path.dentry, old_path.mnt,
5304 +               O_RDONLY, current_cred());
5305 +       vxdprintk(VXD_CBIT(misc, 2),
5306 +               "dentry_open(old): %p", old_file);
5307 +       if (!old_file || IS_ERR(old_file)) {
5308 +               res = IS_ERR(old_file) ? (void *) old_file : res;
5309 +               goto out_unlock_new;
5310 +       }
5311 +
5312 +       dget(new_path.dentry);
5313 +       mntget(new_path.mnt);
5314 +       /* this one cleans up the dentry/mnt in case of failure */
5315 +       new_file = dentry_open(new_path.dentry, new_path.mnt,
5316 +               O_WRONLY, current_cred());
5317 +       vxdprintk(VXD_CBIT(misc, 2),
5318 +               "dentry_open(new): %p", new_file);
5319 +
5320 +       ret = IS_ERR(new_file) ? PTR_ERR(new_file) : -ENOENT;
5321 +       if (!new_file || IS_ERR(new_file))
5322 +               goto out_fput_old;
5323 +
5324 +       size = i_size_read(old_file->f_dentry->d_inode);
5325 +       ret = do_cow_splice(old_file, new_file, size);
5326 +       vxdprintk(VXD_CBIT(misc, 2), "do_splice_direct: %d", ret);
5327 +       if (ret < 0) {
5328 +               goto out_fput_both;
5329 +       } else if (ret < size) {
5330 +               ret = -ENOSPC;
5331 +               goto out_fput_both;
5332 +       } else {
5333 +               struct inode *old_inode = old_path.dentry->d_inode;
5334 +               struct inode *new_inode = new_path.dentry->d_inode;
5335 +               struct iattr attr = {
5336 +                       .ia_uid = old_inode->i_uid,
5337 +                       .ia_gid = old_inode->i_gid,
5338 +                       .ia_valid = ATTR_UID | ATTR_GID
5339 +                       };
5340 +
5341 +               setattr_copy(new_inode, &attr);
5342 +               mark_inode_dirty(new_inode);
5343 +       }
5344 +
5345 +       mutex_lock(&old_path.dentry->d_inode->i_sb->s_vfs_rename_mutex);
5346 +
5347 +       /* drop out late */
5348 +       ret = -ENOENT;
5349 +       if ((redo = d_unhashed(old_path.dentry)))
5350 +               goto out_unlock;
5351 +
5352 +       vxdprintk(VXD_CBIT(misc, 2),
5353 +               "vfs_rename: [" VS_Q("%*s") ":%d] -> [" VS_Q("%*s") ":%d]",
5354 +               new_path.dentry->d_name.len, new_path.dentry->d_name.name,
5355 +               new_path.dentry->d_name.len,
5356 +               old_path.dentry->d_name.len, old_path.dentry->d_name.name,
5357 +               old_path.dentry->d_name.len);
5358 +       ret = vfs_rename(dir_nd.path.dentry->d_inode, new_path.dentry,
5359 +               old_nd.path.dentry->d_parent->d_inode, old_path.dentry);
5360 +       vxdprintk(VXD_CBIT(misc, 2), "vfs_rename: %d", ret);
5361 +       res = new_path.dentry;
5362 +
5363 +out_unlock:
5364 +       mutex_unlock(&old_path.dentry->d_inode->i_sb->s_vfs_rename_mutex);
5365 +
5366 +out_fput_both:
5367 +       vxdprintk(VXD_CBIT(misc, 3),
5368 +               "fput(new_file=%p[#%ld])", new_file,
5369 +               atomic_long_read(&new_file->f_count));
5370 +       fput(new_file);
5371 +
5372 +out_fput_old:
5373 +       vxdprintk(VXD_CBIT(misc, 3),
5374 +               "fput(old_file=%p[#%ld])", old_file,
5375 +               atomic_long_read(&old_file->f_count));
5376 +       fput(old_file);
5377 +
5378 +out_unlock_new:
5379 +       mutex_unlock(&dir->d_inode->i_mutex);
5380 +       if (!ret)
5381 +               goto out_redo;
5382 +
5383 +       /* error path cleanup */
5384 +       vfs_unlink(dir->d_inode, new_path.dentry);
5385 +       dput(new_path.dentry);
5386 +
5387 +out_redo:
5388 +       if (!redo)
5389 +               goto out_rel_both;
5390 +       /* lookup dentry once again */
5391 +       path_put(&old_nd.path);
5392 +       ret = path_lookup(pathname, LOOKUP_FOLLOW, &old_nd);
5393 +       if (ret)
5394 +               goto out_rel_both;
5395 +
5396 +       new_path.dentry = old_nd.path.dentry;
5397 +       vxdprintk(VXD_CBIT(misc, 2),
5398 +               "path_lookup(redo): %p [" VS_Q("%.*s") ":%d]",
5399 +               new_path.dentry,
5400 +               new_path.dentry->d_name.len, new_path.dentry->d_name.name,
5401 +               new_path.dentry->d_name.len);
5402 +       dget(new_path.dentry);
5403 +       res = new_path.dentry;
5404 +
5405 +out_rel_both:
5406 +       path_put(&dir_nd.path);
5407 +out_rel_old:
5408 +       path_put(&old_nd.path);
5409 +out_free_path:
5410 +       kfree(path);
5411 +out:
5412 +       if (ret)
5413 +               res = ERR_PTR(ret);
5414 +       return res;
5415 +}
5416 +
5417 +#endif
5418 +
5419  /* get the link contents into pagecache */
5420  static char *page_getlink(struct dentry * dentry, struct page **ppage)
5421  {
5422 diff -NurpP --minimal linux-2.6.38-rc8/fs/namespace.c linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/namespace.c
5423 --- linux-2.6.38-rc8/fs/namespace.c     2011-03-10 17:09:23.000000000 +0100
5424 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/namespace.c      2011-03-07 16:53:27.000000000 +0100
5425 @@ -31,6 +31,11 @@
5426  #include <linux/idr.h>
5427  #include <linux/fs_struct.h>
5428  #include <linux/fsnotify.h>
5429 +#include <linux/vs_base.h>
5430 +#include <linux/vs_context.h>
5431 +#include <linux/vs_tag.h>
5432 +#include <linux/vserver/space.h>
5433 +#include <linux/vserver/global.h>
5434  #include <asm/uaccess.h>
5435  #include <asm/unistd.h>
5436  #include "pnode.h"
5437 @@ -702,6 +707,7 @@ static struct vfsmount *clone_mnt(struct
5438                 mnt->mnt_root = dget(root);
5439                 mnt->mnt_mountpoint = mnt->mnt_root;
5440                 mnt->mnt_parent = mnt;
5441 +               mnt->mnt_tag = old->mnt_tag;
5442  
5443                 if (flag & CL_SLAVE) {
5444                         list_add(&mnt->mnt_slave, &old->mnt_slave_list);
5445 @@ -830,6 +836,31 @@ static inline void mangle(struct seq_fil
5446         seq_escape(m, s, " \t\n\\");
5447  }
5448  
5449 +static int mnt_is_reachable(struct vfsmount *mnt)
5450 +{
5451 +       struct path root;
5452 +       struct dentry *point;
5453 +       int ret;
5454 +
5455 +       if (mnt == mnt->mnt_ns->root)
5456 +               return 1;
5457 +
5458 +       br_read_lock(vfsmount_lock);
5459 +       root = current->fs->root;
5460 +       point = root.dentry;
5461 +
5462 +       while ((mnt != mnt->mnt_parent) && (mnt != root.mnt)) {
5463 +               point = mnt->mnt_mountpoint;
5464 +               mnt = mnt->mnt_parent;
5465 +       }
5466 +
5467 +       ret = (mnt == root.mnt) && is_subdir(point, root.dentry);
5468 +
5469 +       br_read_unlock(vfsmount_lock);
5470 +
5471 +       return ret;
5472 +}
5473 +
5474  /*
5475   * Simple .show_options callback for filesystems which don't want to
5476   * implement more complex mount option showing.
5477 @@ -932,6 +963,8 @@ static int show_sb_opts(struct seq_file 
5478                 { MS_SYNCHRONOUS, ",sync" },
5479                 { MS_DIRSYNC, ",dirsync" },
5480                 { MS_MANDLOCK, ",mand" },
5481 +               { MS_TAGGED, ",tag" },
5482 +               { MS_NOTAGCHECK, ",notagcheck" },
5483                 { 0, NULL }
5484         };
5485         const struct proc_fs_info *fs_infop;
5486 @@ -978,10 +1011,20 @@ static int show_vfsmnt(struct seq_file *
5487         int err = 0;
5488         struct path mnt_path = { .dentry = mnt->mnt_root, .mnt = mnt };
5489  
5490 -       mangle(m, mnt->mnt_devname ? mnt->mnt_devname : "none");
5491 -       seq_putc(m, ' ');
5492 -       seq_path(m, &mnt_path, " \t\n\\");
5493 -       seq_putc(m, ' ');
5494 +       if (vx_flags(VXF_HIDE_MOUNT, 0))
5495 +               return SEQ_SKIP;
5496 +       if (!mnt_is_reachable(mnt) && !vx_check(0, VS_WATCH_P))
5497 +               return SEQ_SKIP;
5498 +
5499 +       if (!vx_check(0, VS_ADMIN|VS_WATCH) &&
5500 +               mnt == current->fs->root.mnt) {
5501 +               seq_puts(m, "/dev/root / ");
5502 +       } else {
5503 +               mangle(m, mnt->mnt_devname ? mnt->mnt_devname : "none");
5504 +               seq_putc(m, ' ');
5505 +               seq_path(m, &mnt_path, " \t\n\\");
5506 +               seq_putc(m, ' ');
5507 +       }
5508         show_type(m, mnt->mnt_sb);
5509         seq_puts(m, __mnt_is_readonly(mnt) ? " ro" : " rw");
5510         err = show_sb_opts(m, mnt->mnt_sb);
5511 @@ -1011,6 +1054,11 @@ static int show_mountinfo(struct seq_fil
5512         struct path root = p->root;
5513         int err = 0;
5514  
5515 +       if (vx_flags(VXF_HIDE_MOUNT, 0))
5516 +               return SEQ_SKIP;
5517 +       if (!mnt_is_reachable(mnt) && !vx_check(0, VS_WATCH_P))
5518 +               return SEQ_SKIP;
5519 +
5520         seq_printf(m, "%i %i %u:%u ", mnt->mnt_id, mnt->mnt_parent->mnt_id,
5521                    MAJOR(sb->s_dev), MINOR(sb->s_dev));
5522         seq_dentry(m, mnt->mnt_root, " \t\n\\");
5523 @@ -1069,17 +1117,27 @@ static int show_vfsstat(struct seq_file 
5524         struct path mnt_path = { .dentry = mnt->mnt_root, .mnt = mnt };
5525         int err = 0;
5526  
5527 -       /* device */
5528 -       if (mnt->mnt_devname) {
5529 -               seq_puts(m, "device ");
5530 -               mangle(m, mnt->mnt_devname);
5531 -       } else
5532 -               seq_puts(m, "no device");
5533 +       if (vx_flags(VXF_HIDE_MOUNT, 0))
5534 +               return SEQ_SKIP;
5535 +       if (!mnt_is_reachable(mnt) && !vx_check(0, VS_WATCH_P))
5536 +               return SEQ_SKIP;
5537  
5538 -       /* mount point */
5539 -       seq_puts(m, " mounted on ");
5540 -       seq_path(m, &mnt_path, " \t\n\\");
5541 -       seq_putc(m, ' ');
5542 +       if (!vx_check(0, VS_ADMIN|VS_WATCH) &&
5543 +               mnt == current->fs->root.mnt) {
5544 +               seq_puts(m, "device /dev/root mounted on / ");
5545 +       } else {
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 +
5553 +               /* mount point */
5554 +               seq_puts(m, " mounted on ");
5555 +               seq_path(m, &mnt_path, " \t\n\\");
5556 +               seq_putc(m, ' ');
5557 +       }
5558  
5559         /* file system type */
5560         seq_puts(m, "with fstype ");
5561 @@ -1337,7 +1395,7 @@ SYSCALL_DEFINE2(umount, char __user *, n
5562                 goto dput_and_out;
5563  
5564         retval = -EPERM;
5565 -       if (!capable(CAP_SYS_ADMIN))
5566 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SECURE_MOUNT))
5567                 goto dput_and_out;
5568  
5569         retval = do_umount(path.mnt, flags);
5570 @@ -1363,7 +1421,7 @@ SYSCALL_DEFINE1(oldumount, char __user *
5571  
5572  static int mount_is_safe(struct path *path)
5573  {
5574 -       if (capable(CAP_SYS_ADMIN))
5575 +       if (vx_capable(CAP_SYS_ADMIN, VXC_SECURE_MOUNT))
5576                 return 0;
5577         return -EPERM;
5578  #ifdef notyet
5579 @@ -1653,7 +1711,7 @@ static int do_change_type(struct path *p
5580         int type;
5581         int err = 0;
5582  
5583 -       if (!capable(CAP_SYS_ADMIN))
5584 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_NAMESPACE))
5585                 return -EPERM;
5586  
5587         if (path->dentry != path->mnt->mnt_root)
5588 @@ -1684,11 +1742,13 @@ static int do_change_type(struct path *p
5589   * do loopback mount.
5590   */
5591  static int do_loopback(struct path *path, char *old_name,
5592 -                               int recurse)
5593 +       tag_t tag, unsigned long flags, int mnt_flags)
5594  {
5595         struct path old_path;
5596         struct vfsmount *mnt = NULL;
5597         int err = mount_is_safe(path);
5598 +       int recurse = flags & MS_REC;
5599 +
5600         if (err)
5601                 return err;
5602         if (!old_name || !*old_name)
5603 @@ -1723,6 +1783,7 @@ static int do_loopback(struct path *path
5604                 br_write_unlock(vfsmount_lock);
5605                 release_mounts(&umount_list);
5606         }
5607 +       mnt->mnt_flags = mnt_flags;
5608  
5609  out:
5610         up_write(&namespace_sem);
5611 @@ -1753,12 +1814,12 @@ static int change_mount_flags(struct vfs
5612   * on it - tough luck.
5613   */
5614  static int do_remount(struct path *path, int flags, int mnt_flags,
5615 -                     void *data)
5616 +       void *data, xid_t xid)
5617  {
5618         int err;
5619         struct super_block *sb = path->mnt->mnt_sb;
5620  
5621 -       if (!capable(CAP_SYS_ADMIN))
5622 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SECURE_REMOUNT))
5623                 return -EPERM;
5624  
5625         if (!check_mnt(path->mnt))
5626 @@ -1802,7 +1863,7 @@ static int do_move_mount(struct path *pa
5627         struct path old_path, parent_path;
5628         struct vfsmount *p;
5629         int err = 0;
5630 -       if (!capable(CAP_SYS_ADMIN))
5631 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SECURE_MOUNT))
5632                 return -EPERM;
5633         if (!old_name || !*old_name)
5634                 return -EINVAL;
5635 @@ -1888,7 +1949,7 @@ static int do_new_mount(struct path *pat
5636                 return -EINVAL;
5637  
5638         /* we need capabilities... */
5639 -       if (!capable(CAP_SYS_ADMIN))
5640 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SECURE_MOUNT))
5641                 return -EPERM;
5642  
5643         mnt = do_kern_mount(type, flags, name, data);
5644 @@ -2194,6 +2255,7 @@ long do_mount(char *dev_name, char *dir_
5645         struct path path;
5646         int retval = 0;
5647         int mnt_flags = 0;
5648 +       tag_t tag = 0;
5649  
5650         /* Discard magic */
5651         if ((flags & MS_MGC_MSK) == MS_MGC_VAL)
5652 @@ -2221,6 +2283,12 @@ long do_mount(char *dev_name, char *dir_
5653         if (!(flags & MS_NOATIME))
5654                 mnt_flags |= MNT_RELATIME;
5655  
5656 +       if (dx_parse_tag(data_page, &tag, 1, &mnt_flags, &flags)) {
5657 +               /* FIXME: bind and re-mounts get the tag flag? */
5658 +               if (flags & (MS_BIND|MS_REMOUNT))
5659 +                       flags |= MS_TAGID;
5660 +       }
5661 +
5662         /* Separate the per-mountpoint flags */
5663         if (flags & MS_NOSUID)
5664                 mnt_flags |= MNT_NOSUID;
5665 @@ -2237,15 +2305,17 @@ long do_mount(char *dev_name, char *dir_
5666         if (flags & MS_RDONLY)
5667                 mnt_flags |= MNT_READONLY;
5668  
5669 +       if (!capable(CAP_SYS_ADMIN))
5670 +               mnt_flags |= MNT_NODEV;
5671         flags &= ~(MS_NOSUID | MS_NOEXEC | MS_NODEV | MS_ACTIVE | MS_BORN |
5672                    MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
5673                    MS_STRICTATIME);
5674  
5675         if (flags & MS_REMOUNT)
5676                 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
5677 -                                   data_page);
5678 +                                   data_page, tag);
5679         else if (flags & MS_BIND)
5680 -               retval = do_loopback(&path, dev_name, flags & MS_REC);
5681 +               retval = do_loopback(&path, dev_name, tag, flags, mnt_flags);
5682         else if (flags & (MS_SHARED | MS_PRIVATE | MS_SLAVE | MS_UNBINDABLE))
5683                 retval = do_change_type(&path, flags);
5684         else if (flags & MS_MOVE)
5685 @@ -2345,6 +2415,7 @@ static struct mnt_namespace *dup_mnt_ns(
5686                 q = next_mnt(q, new_ns->root);
5687         }
5688         up_write(&namespace_sem);
5689 +       atomic_inc(&vs_global_mnt_ns);
5690  
5691         if (rootmnt)
5692                 mntput(rootmnt);
5693 @@ -2487,9 +2558,10 @@ SYSCALL_DEFINE2(pivot_root, const char _
5694         down_write(&namespace_sem);
5695         mutex_lock(&old.dentry->d_inode->i_mutex);
5696         error = -EINVAL;
5697 -       if (IS_MNT_SHARED(old.mnt) ||
5698 +       if ((IS_MNT_SHARED(old.mnt) ||
5699                 IS_MNT_SHARED(new.mnt->mnt_parent) ||
5700 -               IS_MNT_SHARED(root.mnt->mnt_parent))
5701 +               IS_MNT_SHARED(root.mnt->mnt_parent)) &&
5702 +               !vx_flags(VXF_STATE_SETUP, 0))
5703                 goto out2;
5704         if (!check_mnt(root.mnt))
5705                 goto out2;
5706 @@ -2624,6 +2696,7 @@ void put_mnt_ns(struct mnt_namespace *ns
5707         br_write_unlock(vfsmount_lock);
5708         up_write(&namespace_sem);
5709         release_mounts(&umount_list);
5710 +       atomic_dec(&vs_global_mnt_ns);
5711         kfree(ns);
5712  }
5713  EXPORT_SYMBOL(put_mnt_ns);
5714 diff -NurpP --minimal linux-2.6.38-rc8/fs/nfs/client.c linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/nfs/client.c
5715 --- linux-2.6.38-rc8/fs/nfs/client.c    2011-03-10 17:09:23.000000000 +0100
5716 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/nfs/client.c     2011-02-02 22:20:25.000000000 +0100
5717 @@ -761,6 +761,9 @@ static int nfs_init_server_rpcclient(str
5718         if (server->flags & NFS_MOUNT_SOFT)
5719                 server->client->cl_softrtry = 1;
5720  
5721 +       server->client->cl_tag = 0;
5722 +       if (server->flags & NFS_MOUNT_TAGGED)
5723 +               server->client->cl_tag = 1;
5724         return 0;
5725  }
5726  
5727 @@ -934,6 +937,10 @@ static void nfs_server_set_fsinfo(struct
5728                 server->acdirmin = server->acdirmax = 0;
5729         }
5730  
5731 +       /* FIXME: needs fsinfo
5732 +       if (server->flags & NFS_MOUNT_TAGGED)
5733 +               sb->s_flags |= MS_TAGGED;       */
5734 +
5735         server->maxfilesize = fsinfo->maxfilesize;
5736  
5737         server->time_delta = fsinfo->time_delta;
5738 diff -NurpP --minimal linux-2.6.38-rc8/fs/nfs/dir.c linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/nfs/dir.c
5739 --- linux-2.6.38-rc8/fs/nfs/dir.c       2011-03-10 17:09:23.000000000 +0100
5740 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/nfs/dir.c        2011-01-29 02:49:21.000000000 +0100
5741 @@ -35,6 +35,7 @@
5742  #include <linux/sched.h>
5743  #include <linux/kmemleak.h>
5744  #include <linux/xattr.h>
5745 +#include <linux/vs_tag.h>
5746  
5747  #include "delegation.h"
5748  #include "iostat.h"
5749 @@ -1224,6 +1225,7 @@ static struct dentry *nfs_lookup(struct 
5750         if (IS_ERR(res))
5751                 goto out_unblock_sillyrename;
5752  
5753 +       dx_propagate_tag(nd, inode);
5754  no_entry:
5755         res = d_materialise_unique(dentry, inode);
5756         if (res != NULL) {
5757 diff -NurpP --minimal linux-2.6.38-rc8/fs/nfs/inode.c linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/nfs/inode.c
5758 --- linux-2.6.38-rc8/fs/nfs/inode.c     2011-03-10 17:09:23.000000000 +0100
5759 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/nfs/inode.c      2011-02-02 22:20:25.000000000 +0100
5760 @@ -37,6 +37,7 @@
5761  #include <linux/nfs_xdr.h>
5762  #include <linux/slab.h>
5763  #include <linux/compat.h>
5764 +#include <linux/vs_tag.h>
5765  
5766  #include <asm/system.h>
5767  #include <asm/uaccess.h>
5768 @@ -265,6 +266,8 @@ nfs_fhget(struct super_block *sb, struct
5769         if (inode->i_state & I_NEW) {
5770                 struct nfs_inode *nfsi = NFS_I(inode);
5771                 unsigned long now = jiffies;
5772 +               uid_t uid;
5773 +               gid_t gid;
5774  
5775                 /* We set i_ino for the few things that still rely on it,
5776                  * such as stat(2) */
5777 @@ -313,8 +316,8 @@ nfs_fhget(struct super_block *sb, struct
5778                 nfsi->change_attr = 0;
5779                 inode->i_size = 0;
5780                 inode->i_nlink = 0;
5781 -               inode->i_uid = -2;
5782 -               inode->i_gid = -2;
5783 +               uid = -2;
5784 +               gid = -2;
5785                 inode->i_blocks = 0;
5786                 memset(nfsi->cookieverf, 0, sizeof(nfsi->cookieverf));
5787  
5788 @@ -351,13 +354,13 @@ nfs_fhget(struct super_block *sb, struct
5789                 else if (nfs_server_capable(inode, NFS_CAP_NLINK))
5790                         nfsi->cache_validity |= NFS_INO_INVALID_ATTR;
5791                 if (fattr->valid & NFS_ATTR_FATTR_OWNER)
5792 -                       inode->i_uid = fattr->uid;
5793 +                       uid = fattr->uid;
5794                 else if (nfs_server_capable(inode, NFS_CAP_OWNER))
5795                         nfsi->cache_validity |= NFS_INO_INVALID_ATTR
5796                                 | NFS_INO_INVALID_ACCESS
5797                                 | NFS_INO_INVALID_ACL;
5798                 if (fattr->valid & NFS_ATTR_FATTR_GROUP)
5799 -                       inode->i_gid = fattr->gid;
5800 +                       gid = fattr->gid;
5801                 else if (nfs_server_capable(inode, NFS_CAP_OWNER_GROUP))
5802                         nfsi->cache_validity |= NFS_INO_INVALID_ATTR
5803                                 | NFS_INO_INVALID_ACCESS
5804 @@ -370,6 +373,11 @@ nfs_fhget(struct super_block *sb, struct
5805                          */
5806                         inode->i_blocks = nfs_calc_block_size(fattr->du.nfs3.used);
5807                 }
5808 +               inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
5809 +               inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
5810 +               inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid, 0);
5811 +                               /* maybe fattr->xid someday */
5812 +
5813                 nfsi->attrtimeo = NFS_MINATTRTIMEO(inode);
5814                 nfsi->attrtimeo_timestamp = now;
5815                 nfsi->access_cache = RB_ROOT;
5816 @@ -486,6 +494,8 @@ void nfs_setattr_update_inode(struct ino
5817                         inode->i_uid = attr->ia_uid;
5818                 if ((attr->ia_valid & ATTR_GID) != 0)
5819                         inode->i_gid = attr->ia_gid;
5820 +               if ((attr->ia_valid & ATTR_TAG) && IS_TAGGED(inode))
5821 +                       inode->i_tag = attr->ia_tag;
5822                 NFS_I(inode)->cache_validity |= NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL;
5823                 spin_unlock(&inode->i_lock);
5824         }
5825 @@ -934,6 +944,9 @@ static int nfs_check_inode_attributes(st
5826         struct nfs_inode *nfsi = NFS_I(inode);
5827         loff_t cur_size, new_isize;
5828         unsigned long invalid = 0;
5829 +       uid_t uid;
5830 +       gid_t gid;
5831 +       tag_t tag;
5832  
5833  
5834         /* Has the inode gone and changed behind our back? */
5835 @@ -957,13 +970,18 @@ static int nfs_check_inode_attributes(st
5836                         invalid |= NFS_INO_INVALID_ATTR|NFS_INO_REVAL_PAGECACHE;
5837         }
5838  
5839 +       uid = INOTAG_UID(DX_TAG(inode), fattr->uid, fattr->gid);
5840 +       gid = INOTAG_GID(DX_TAG(inode), fattr->uid, fattr->gid);
5841 +       tag = INOTAG_TAG(DX_TAG(inode), fattr->uid, fattr->gid, 0);
5842 +
5843         /* Have any file permissions changed? */
5844         if ((fattr->valid & NFS_ATTR_FATTR_MODE) && (inode->i_mode & S_IALLUGO) != (fattr->mode & S_IALLUGO))
5845                 invalid |= NFS_INO_INVALID_ATTR | NFS_INO_INVALID_ACCESS | NFS_INO_INVALID_ACL;
5846 -       if ((fattr->valid & NFS_ATTR_FATTR_OWNER) && inode->i_uid != fattr->uid)
5847 +       if ((fattr->valid & NFS_ATTR_FATTR_OWNER) && uid != fattr->uid)
5848                 invalid |= NFS_INO_INVALID_ATTR | NFS_INO_INVALID_ACCESS | NFS_INO_INVALID_ACL;
5849 -       if ((fattr->valid & NFS_ATTR_FATTR_GROUP) && inode->i_gid != fattr->gid)
5850 +       if ((fattr->valid & NFS_ATTR_FATTR_GROUP) && gid != fattr->gid)
5851                 invalid |= NFS_INO_INVALID_ATTR | NFS_INO_INVALID_ACCESS | NFS_INO_INVALID_ACL;
5852 +               /* maybe check for tag too? */
5853  
5854         /* Has the link count changed? */
5855         if ((fattr->valid & NFS_ATTR_FATTR_NLINK) && inode->i_nlink != fattr->nlink)
5856 @@ -1198,6 +1216,9 @@ static int nfs_update_inode(struct inode
5857         unsigned long invalid = 0;
5858         unsigned long now = jiffies;
5859         unsigned long save_cache_validity;
5860 +       uid_t uid;
5861 +       gid_t gid;
5862 +       tag_t tag;
5863  
5864         dfprintk(VFS, "NFS: %s(%s/%ld ct=%d info=0x%x)\n",
5865                         __func__, inode->i_sb->s_id, inode->i_ino,
5866 @@ -1300,6 +1321,9 @@ static int nfs_update_inode(struct inode
5867                                 | NFS_INO_REVAL_PAGECACHE
5868                                 | NFS_INO_REVAL_FORCED);
5869  
5870 +       uid = INOTAG_UID(DX_TAG(inode), fattr->uid, fattr->gid);
5871 +       gid = INOTAG_GID(DX_TAG(inode), fattr->uid, fattr->gid);
5872 +       tag = INOTAG_TAG(DX_TAG(inode), fattr->uid, fattr->gid, 0);
5873  
5874         if (fattr->valid & NFS_ATTR_FATTR_ATIME)
5875                 memcpy(&inode->i_atime, &fattr->atime, sizeof(inode->i_atime));
5876 @@ -1321,9 +1345,9 @@ static int nfs_update_inode(struct inode
5877                                 | NFS_INO_REVAL_FORCED);
5878  
5879         if (fattr->valid & NFS_ATTR_FATTR_OWNER) {
5880 -               if (inode->i_uid != fattr->uid) {
5881 +               if (uid != fattr->uid) {
5882                         invalid |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL;
5883 -                       inode->i_uid = fattr->uid;
5884 +                       uid = fattr->uid;
5885                 }
5886         } else if (server->caps & NFS_CAP_OWNER)
5887                 invalid |= save_cache_validity & (NFS_INO_INVALID_ATTR
5888 @@ -1332,9 +1356,9 @@ static int nfs_update_inode(struct inode
5889                                 | NFS_INO_REVAL_FORCED);
5890  
5891         if (fattr->valid & NFS_ATTR_FATTR_GROUP) {
5892 -               if (inode->i_gid != fattr->gid) {
5893 +               if (gid != fattr->gid) {
5894                         invalid |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL;
5895 -                       inode->i_gid = fattr->gid;
5896 +                       gid = fattr->gid;
5897                 }
5898         } else if (server->caps & NFS_CAP_OWNER_GROUP)
5899                 invalid |= save_cache_validity & (NFS_INO_INVALID_ATTR
5900 @@ -1342,6 +1366,10 @@ static int nfs_update_inode(struct inode
5901                                 | NFS_INO_INVALID_ACL
5902                                 | NFS_INO_REVAL_FORCED);
5903  
5904 +       inode->i_uid = uid;
5905 +       inode->i_gid = gid;
5906 +       inode->i_tag = tag;
5907 +
5908         if (fattr->valid & NFS_ATTR_FATTR_NLINK) {
5909                 if (inode->i_nlink != fattr->nlink) {
5910                         invalid |= NFS_INO_INVALID_ATTR;
5911 diff -NurpP --minimal linux-2.6.38-rc8/fs/nfs/nfs3xdr.c linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/nfs/nfs3xdr.c
5912 --- linux-2.6.38-rc8/fs/nfs/nfs3xdr.c   2011-03-10 17:09:23.000000000 +0100
5913 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/nfs/nfs3xdr.c    2011-02-02 22:20:25.000000000 +0100
5914 @@ -20,6 +20,7 @@
5915  #include <linux/nfs3.h>
5916  #include <linux/nfs_fs.h>
5917  #include <linux/nfsacl.h>
5918 +#include <linux/vs_tag.h>
5919  #include "internal.h"
5920  
5921  #define NFSDBG_FACILITY                NFSDBG_XDR
5922 @@ -562,7 +563,8 @@ static __be32 *xdr_decode_nfstime3(__be3
5923   *             set_mtime       mtime;
5924   *     };
5925   */
5926 -static void encode_sattr3(struct xdr_stream *xdr, const struct iattr *attr)
5927 +static void encode_sattr3(struct xdr_stream *xdr,
5928 +       const struct iattr *attr, int tag)
5929  {
5930         u32 nbytes;
5931         __be32 *p;
5932 @@ -594,15 +596,19 @@ static void encode_sattr3(struct xdr_str
5933         } else
5934                 *p++ = xdr_zero;
5935  
5936 -       if (attr->ia_valid & ATTR_UID) {
5937 +       if (attr->ia_valid & ATTR_UID ||
5938 +               (tag && (attr->ia_valid & ATTR_TAG))) {
5939                 *p++ = xdr_one;
5940 -               *p++ = cpu_to_be32(attr->ia_uid);
5941 +               *p++ = cpu_to_be32(TAGINO_UID(tag,
5942 +                       attr->ia_uid, attr->ia_tag));
5943         } else
5944                 *p++ = xdr_zero;
5945  
5946 -       if (attr->ia_valid & ATTR_GID) {
5947 +       if (attr->ia_valid & ATTR_GID ||
5948 +               (tag && (attr->ia_valid & ATTR_TAG))) {
5949                 *p++ = xdr_one;
5950 -               *p++ = cpu_to_be32(attr->ia_gid);
5951 +               *p++ = cpu_to_be32(TAGINO_GID(tag,
5952 +                       attr->ia_gid, attr->ia_tag));
5953         } else
5954                 *p++ = xdr_zero;
5955  
5956 @@ -878,7 +884,7 @@ static void nfs3_xdr_enc_setattr3args(st
5957                                       const struct nfs3_sattrargs *args)
5958  {
5959         encode_nfs_fh3(xdr, args->fh);
5960 -       encode_sattr3(xdr, args->sattr);
5961 +       encode_sattr3(xdr, args->sattr, req->rq_task->tk_client->cl_tag);
5962         encode_sattrguard3(xdr, args);
5963  }
5964  
5965 @@ -1028,13 +1034,13 @@ static void nfs3_xdr_enc_write3args(stru
5966   *     };
5967   */
5968  static void encode_createhow3(struct xdr_stream *xdr,
5969 -                             const struct nfs3_createargs *args)
5970 +       const struct nfs3_createargs *args, int tag)
5971  {
5972         encode_uint32(xdr, args->createmode);
5973         switch (args->createmode) {
5974         case NFS3_CREATE_UNCHECKED:
5975         case NFS3_CREATE_GUARDED:
5976 -               encode_sattr3(xdr, args->sattr);
5977 +               encode_sattr3(xdr, args->sattr, tag);
5978                 break;
5979         case NFS3_CREATE_EXCLUSIVE:
5980                 encode_createverf3(xdr, args->verifier);
5981 @@ -1049,7 +1055,7 @@ static void nfs3_xdr_enc_create3args(str
5982                                      const struct nfs3_createargs *args)
5983  {
5984         encode_diropargs3(xdr, args->fh, args->name, args->len);
5985 -       encode_createhow3(xdr, args);
5986 +       encode_createhow3(xdr, args, req->rq_task->tk_client->cl_tag);
5987  }
5988  
5989  /*
5990 @@ -1065,7 +1071,7 @@ static void nfs3_xdr_enc_mkdir3args(stru
5991                                     const struct nfs3_mkdirargs *args)
5992  {
5993         encode_diropargs3(xdr, args->fh, args->name, args->len);
5994 -       encode_sattr3(xdr, args->sattr);
5995 +       encode_sattr3(xdr, args->sattr, req->rq_task->tk_client->cl_tag);
5996  }
5997  
5998  /*
5999 @@ -1082,9 +1088,9 @@ static void nfs3_xdr_enc_mkdir3args(stru
6000   *     };
6001   */
6002  static void encode_symlinkdata3(struct xdr_stream *xdr,
6003 -                               const struct nfs3_symlinkargs *args)
6004 +       const struct nfs3_symlinkargs *args, int tag)
6005  {
6006 -       encode_sattr3(xdr, args->sattr);
6007 +       encode_sattr3(xdr, args->sattr, tag);
6008         encode_nfspath3(xdr, args->pages, args->pathlen);
6009  }
6010  
6011 @@ -1093,7 +1099,7 @@ static void nfs3_xdr_enc_symlink3args(st
6012                                       const struct nfs3_symlinkargs *args)
6013  {
6014         encode_diropargs3(xdr, args->fromfh, args->fromname, args->fromlen);
6015 -       encode_symlinkdata3(xdr, args);
6016 +       encode_symlinkdata3(xdr, args, req->rq_task->tk_client->cl_tag);
6017  }
6018  
6019  /*
6020 @@ -1121,24 +1127,24 @@ static void nfs3_xdr_enc_symlink3args(st
6021   *     };
6022   */
6023  static void encode_devicedata3(struct xdr_stream *xdr,
6024 -                              const struct nfs3_mknodargs *args)
6025 +       const struct nfs3_mknodargs *args, int tag)
6026  {
6027 -       encode_sattr3(xdr, args->sattr);
6028 +       encode_sattr3(xdr, args->sattr, tag);
6029         encode_specdata3(xdr, args->rdev);
6030  }
6031  
6032  static void encode_mknoddata3(struct xdr_stream *xdr,
6033 -                             const struct nfs3_mknodargs *args)
6034 +       const struct nfs3_mknodargs *args, int tag)
6035  {
6036         encode_ftype3(xdr, args->type);
6037         switch (args->type) {
6038         case NF3CHR:
6039         case NF3BLK:
6040 -               encode_devicedata3(xdr, args);
6041 +               encode_devicedata3(xdr, args, tag);
6042                 break;
6043         case NF3SOCK:
6044         case NF3FIFO:
6045 -               encode_sattr3(xdr, args->sattr);
6046 +               encode_sattr3(xdr, args->sattr, tag);
6047                 break;
6048         case NF3REG:
6049         case NF3DIR:
6050 @@ -1153,7 +1159,7 @@ static void nfs3_xdr_enc_mknod3args(stru
6051                                     const struct nfs3_mknodargs *args)
6052  {
6053         encode_diropargs3(xdr, args->fh, args->name, args->len);
6054 -       encode_mknoddata3(xdr, args);
6055 +       encode_mknoddata3(xdr, args, req->rq_task->tk_client->cl_tag);
6056  }
6057  
6058  /*
6059 diff -NurpP --minimal linux-2.6.38-rc8/fs/nfs/super.c linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/nfs/super.c
6060 --- linux-2.6.38-rc8/fs/nfs/super.c     2011-03-10 17:09:23.000000000 +0100
6061 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/nfs/super.c      2011-01-29 02:01:07.000000000 +0100
6062 @@ -53,6 +53,7 @@
6063  #include <linux/nfs_xdr.h>
6064  #include <linux/magic.h>
6065  #include <linux/parser.h>
6066 +#include <linux/vs_tag.h>
6067  
6068  #include <asm/system.h>
6069  #include <asm/uaccess.h>
6070 @@ -86,6 +87,7 @@ enum {
6071         Opt_sharecache, Opt_nosharecache,
6072         Opt_resvport, Opt_noresvport,
6073         Opt_fscache, Opt_nofscache,
6074 +       Opt_tag, Opt_notag,
6075  
6076         /* Mount options that take integer arguments */
6077         Opt_port,
6078 @@ -99,6 +101,7 @@ enum {
6079         Opt_mountvers,
6080         Opt_nfsvers,
6081         Opt_minorversion,
6082 +       Opt_tagid,
6083  
6084         /* Mount options that take string arguments */
6085         Opt_sec, Opt_proto, Opt_mountproto, Opt_mounthost,
6086 @@ -179,6 +182,10 @@ static const match_table_t nfs_mount_opt
6087         { Opt_fscache_uniq, "fsc=%s" },
6088         { Opt_local_lock, "local_lock=%s" },
6089  
6090 +       { Opt_tag, "tag" },
6091 +       { Opt_notag, "notag" },
6092 +       { Opt_tagid, "tagid=%u" },
6093 +
6094         { Opt_err, NULL }
6095  };
6096  
6097 @@ -642,6 +649,7 @@ static void nfs_show_mount_options(struc
6098                 { NFS_MOUNT_NORDIRPLUS, ",nordirplus", "" },
6099                 { NFS_MOUNT_UNSHARED, ",nosharecache", "" },
6100                 { NFS_MOUNT_NORESVPORT, ",noresvport", "" },
6101 +               { NFS_MOUNT_TAGGED, ",tag", "" },
6102                 { 0, NULL, NULL }
6103         };
6104         const struct proc_nfs_info *nfs_infop;
6105 @@ -1122,6 +1130,14 @@ static int nfs_parse_mount_options(char 
6106                         kfree(mnt->fscache_uniq);
6107                         mnt->fscache_uniq = NULL;
6108                         break;
6109 +#ifndef CONFIG_TAGGING_NONE
6110 +               case Opt_tag:
6111 +                       mnt->flags |= NFS_MOUNT_TAGGED;
6112 +                       break;
6113 +               case Opt_notag:
6114 +                       mnt->flags &= ~NFS_MOUNT_TAGGED;
6115 +                       break;
6116 +#endif
6117  
6118                 /*
6119                  * options that take numeric values
6120 @@ -1306,6 +1322,12 @@ static int nfs_parse_mount_options(char 
6121                                 goto out_invalid_value;
6122                         mnt->minorversion = option;
6123                         break;
6124 +#ifdef CONFIG_PROPAGATE
6125 +               case Opt_tagid:
6126 +                       /* use args[0] */
6127 +                       nfs_data.flags |= NFS_MOUNT_TAGGED;
6128 +                       break;
6129 +#endif
6130  
6131                 /*
6132                  * options that take text values
6133 diff -NurpP --minimal linux-2.6.38-rc8/fs/nfsd/auth.c linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/nfsd/auth.c
6134 --- linux-2.6.38-rc8/fs/nfsd/auth.c     2010-02-25 11:52:05.000000000 +0100
6135 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/nfsd/auth.c      2011-01-29 02:01:07.000000000 +0100
6136 @@ -1,6 +1,7 @@
6137  /* Copyright (C) 1995, 1996 Olaf Kirch <okir@monad.swb.de> */
6138  
6139  #include <linux/sched.h>
6140 +#include <linux/vs_tag.h>
6141  #include "nfsd.h"
6142  #include "auth.h"
6143  
6144 @@ -36,6 +37,9 @@ int nfsd_setuser(struct svc_rqst *rqstp,
6145  
6146         new->fsuid = rqstp->rq_cred.cr_uid;
6147         new->fsgid = rqstp->rq_cred.cr_gid;
6148 +       /* FIXME: this desperately needs a tag :)
6149 +       new->xid = (xid_t)INOTAG_TAG(DX_TAG_NFSD, cred.cr_uid, cred.cr_gid, 0);
6150 +                       */
6151  
6152         rqgi = rqstp->rq_cred.cr_group_info;
6153  
6154 diff -NurpP --minimal linux-2.6.38-rc8/fs/nfsd/nfs3xdr.c linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/nfsd/nfs3xdr.c
6155 --- linux-2.6.38-rc8/fs/nfsd/nfs3xdr.c  2011-01-05 21:50:25.000000000 +0100
6156 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/nfsd/nfs3xdr.c   2011-01-29 02:01:07.000000000 +0100
6157 @@ -7,6 +7,7 @@
6158   */
6159  
6160  #include <linux/namei.h>
6161 +#include <linux/vs_tag.h>
6162  #include "xdr3.h"
6163  #include "auth.h"
6164  
6165 @@ -95,6 +96,8 @@ static __be32 *
6166  decode_sattr3(__be32 *p, struct iattr *iap)
6167  {
6168         u32     tmp;
6169 +       uid_t   uid = 0;
6170 +       gid_t   gid = 0;
6171  
6172         iap->ia_valid = 0;
6173  
6174 @@ -104,12 +107,15 @@ decode_sattr3(__be32 *p, struct iattr *i
6175         }
6176         if (*p++) {
6177                 iap->ia_valid |= ATTR_UID;
6178 -               iap->ia_uid = ntohl(*p++);
6179 +               uid = ntohl(*p++);
6180         }
6181         if (*p++) {
6182                 iap->ia_valid |= ATTR_GID;
6183 -               iap->ia_gid = ntohl(*p++);
6184 +               gid = ntohl(*p++);
6185         }
6186 +       iap->ia_uid = INOTAG_UID(DX_TAG_NFSD, uid, gid);
6187 +       iap->ia_gid = INOTAG_GID(DX_TAG_NFSD, uid, gid);
6188 +       iap->ia_tag = INOTAG_TAG(DX_TAG_NFSD, uid, gid, 0);
6189         if (*p++) {
6190                 u64     newsize;
6191  
6192 @@ -165,8 +171,12 @@ encode_fattr3(struct svc_rqst *rqstp, __
6193         *p++ = htonl(nfs3_ftypes[(stat->mode & S_IFMT) >> 12]);
6194         *p++ = htonl((u32) stat->mode);
6195         *p++ = htonl((u32) stat->nlink);
6196 -       *p++ = htonl((u32) nfsd_ruid(rqstp, stat->uid));
6197 -       *p++ = htonl((u32) nfsd_rgid(rqstp, stat->gid));
6198 +       *p++ = htonl((u32) nfsd_ruid(rqstp,
6199 +               TAGINO_UID(0 /* FIXME: DX_TAG(dentry->d_inode) */,
6200 +               stat->uid, stat->tag)));
6201 +       *p++ = htonl((u32) nfsd_rgid(rqstp,
6202 +               TAGINO_GID(0 /* FIXME: DX_TAG(dentry->d_inode) */,
6203 +               stat->gid, stat->tag)));
6204         if (S_ISLNK(stat->mode) && stat->size > NFS3_MAXPATHLEN) {
6205                 p = xdr_encode_hyper(p, (u64) NFS3_MAXPATHLEN);
6206         } else {
6207 diff -NurpP --minimal linux-2.6.38-rc8/fs/nfsd/nfs4xdr.c linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/nfsd/nfs4xdr.c
6208 --- linux-2.6.38-rc8/fs/nfsd/nfs4xdr.c  2011-03-10 17:09:23.000000000 +0100
6209 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/nfsd/nfs4xdr.c   2011-03-07 16:53:27.000000000 +0100
6210 @@ -45,6 +45,7 @@
6211  #include <linux/statfs.h>
6212  #include <linux/utsname.h>
6213  #include <linux/sunrpc/svcauth_gss.h>
6214 +#include <linux/vs_tag.h>
6215  
6216  #include "idmap.h"
6217  #include "acl.h"
6218 @@ -2098,14 +2099,18 @@ out_acl:
6219                 WRITE32(stat.nlink);
6220         }
6221         if (bmval1 & FATTR4_WORD1_OWNER) {
6222 -               status = nfsd4_encode_user(rqstp, stat.uid, &p, &buflen);
6223 +               status = nfsd4_encode_user(rqstp,
6224 +                       TAGINO_UID(DX_TAG(dentry->d_inode),
6225 +                       stat.uid, stat.tag), &p, &buflen);
6226                 if (status == nfserr_resource)
6227                         goto out_resource;
6228                 if (status)
6229                         goto out;
6230         }
6231         if (bmval1 & FATTR4_WORD1_OWNER_GROUP) {
6232 -               status = nfsd4_encode_group(rqstp, stat.gid, &p, &buflen);
6233 +               status = nfsd4_encode_group(rqstp,
6234 +                       TAGINO_GID(DX_TAG(dentry->d_inode),
6235 +                       stat.gid, stat.tag), &p, &buflen);
6236                 if (status == nfserr_resource)
6237                         goto out_resource;
6238                 if (status)
6239 diff -NurpP --minimal linux-2.6.38-rc8/fs/nfsd/nfsxdr.c linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/nfsd/nfsxdr.c
6240 --- linux-2.6.38-rc8/fs/nfsd/nfsxdr.c   2010-02-25 11:52:05.000000000 +0100
6241 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/nfsd/nfsxdr.c    2011-01-29 02:01:07.000000000 +0100
6242 @@ -6,6 +6,7 @@
6243  
6244  #include "xdr.h"
6245  #include "auth.h"
6246 +#include <linux/vs_tag.h>
6247  
6248  #define NFSDDBG_FACILITY               NFSDDBG_XDR
6249  
6250 @@ -88,6 +89,8 @@ static __be32 *
6251  decode_sattr(__be32 *p, struct iattr *iap)
6252  {
6253         u32     tmp, tmp1;
6254 +       uid_t   uid = 0;
6255 +       gid_t   gid = 0;
6256  
6257         iap->ia_valid = 0;
6258  
6259 @@ -101,12 +104,15 @@ decode_sattr(__be32 *p, struct iattr *ia
6260         }
6261         if ((tmp = ntohl(*p++)) != (u32)-1) {
6262                 iap->ia_valid |= ATTR_UID;
6263 -               iap->ia_uid = tmp;
6264 +               uid = tmp;
6265         }
6266         if ((tmp = ntohl(*p++)) != (u32)-1) {
6267                 iap->ia_valid |= ATTR_GID;
6268 -               iap->ia_gid = tmp;
6269 +               gid = tmp;
6270         }
6271 +       iap->ia_uid = INOTAG_UID(DX_TAG_NFSD, uid, gid);
6272 +       iap->ia_gid = INOTAG_GID(DX_TAG_NFSD, uid, gid);
6273 +       iap->ia_tag = INOTAG_TAG(DX_TAG_NFSD, uid, gid, 0);
6274         if ((tmp = ntohl(*p++)) != (u32)-1) {
6275                 iap->ia_valid |= ATTR_SIZE;
6276                 iap->ia_size = tmp;
6277 @@ -151,8 +157,10 @@ encode_fattr(struct svc_rqst *rqstp, __b
6278         *p++ = htonl(nfs_ftypes[type >> 12]);
6279         *p++ = htonl((u32) stat->mode);
6280         *p++ = htonl((u32) stat->nlink);
6281 -       *p++ = htonl((u32) nfsd_ruid(rqstp, stat->uid));
6282 -       *p++ = htonl((u32) nfsd_rgid(rqstp, stat->gid));
6283 +       *p++ = htonl((u32) nfsd_ruid(rqstp,
6284 +               TAGINO_UID(DX_TAG(dentry->d_inode), stat->uid, stat->tag)));
6285 +       *p++ = htonl((u32) nfsd_rgid(rqstp,
6286 +               TAGINO_GID(DX_TAG(dentry->d_inode), stat->gid, stat->tag)));
6287  
6288         if (S_ISLNK(type) && stat->size > NFS_MAXPATHLEN) {
6289                 *p++ = htonl(NFS_MAXPATHLEN);
6290 diff -NurpP --minimal linux-2.6.38-rc8/fs/ocfs2/dlmglue.c linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/ocfs2/dlmglue.c
6291 --- linux-2.6.38-rc8/fs/ocfs2/dlmglue.c 2011-01-05 21:50:26.000000000 +0100
6292 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/ocfs2/dlmglue.c  2011-01-29 02:01:07.000000000 +0100
6293 @@ -2114,6 +2114,7 @@ static void __ocfs2_stuff_meta_lvb(struc
6294         lvb->lvb_iclusters = cpu_to_be32(oi->ip_clusters);
6295         lvb->lvb_iuid      = cpu_to_be32(inode->i_uid);
6296         lvb->lvb_igid      = cpu_to_be32(inode->i_gid);
6297 +       lvb->lvb_itag      = cpu_to_be16(inode->i_tag);
6298         lvb->lvb_imode     = cpu_to_be16(inode->i_mode);
6299         lvb->lvb_inlink    = cpu_to_be16(inode->i_nlink);
6300         lvb->lvb_iatime_packed  =
6301 @@ -2168,6 +2169,7 @@ static void ocfs2_refresh_inode_from_lvb
6302  
6303         inode->i_uid     = be32_to_cpu(lvb->lvb_iuid);
6304         inode->i_gid     = be32_to_cpu(lvb->lvb_igid);
6305 +       inode->i_tag     = be16_to_cpu(lvb->lvb_itag);
6306         inode->i_mode    = be16_to_cpu(lvb->lvb_imode);
6307         inode->i_nlink   = be16_to_cpu(lvb->lvb_inlink);
6308         ocfs2_unpack_timespec(&inode->i_atime,
6309 diff -NurpP --minimal linux-2.6.38-rc8/fs/ocfs2/dlmglue.h linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/ocfs2/dlmglue.h
6310 --- linux-2.6.38-rc8/fs/ocfs2/dlmglue.h 2010-10-21 13:07:50.000000000 +0200
6311 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/ocfs2/dlmglue.h  2011-01-29 02:01:07.000000000 +0100
6312 @@ -46,7 +46,8 @@ struct ocfs2_meta_lvb {
6313         __be16       lvb_inlink;
6314         __be32       lvb_iattr;
6315         __be32       lvb_igeneration;
6316 -       __be32       lvb_reserved2;
6317 +       __be16       lvb_itag;
6318 +       __be16       lvb_reserved2;
6319  };
6320  
6321  #define OCFS2_QINFO_LVB_VERSION 1
6322 diff -NurpP --minimal linux-2.6.38-rc8/fs/ocfs2/file.c linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/ocfs2/file.c
6323 --- linux-2.6.38-rc8/fs/ocfs2/file.c    2011-03-10 17:09:24.000000000 +0100
6324 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/ocfs2/file.c     2011-01-29 02:01:07.000000000 +0100
6325 @@ -1126,13 +1126,15 @@ int ocfs2_setattr(struct dentry *dentry,
6326                 mlog(0, "uid change: %d\n", attr->ia_uid);
6327         if (attr->ia_valid & ATTR_GID)
6328                 mlog(0, "gid change: %d\n", attr->ia_gid);
6329 +       if (attr->ia_valid & ATTR_TAG)
6330 +               mlog(0, "tag change: %d\n", attr->ia_tag);
6331         if (attr->ia_valid & ATTR_SIZE)
6332                 mlog(0, "size change...\n");
6333         if (attr->ia_valid & (ATTR_ATIME | ATTR_MTIME | ATTR_CTIME))
6334                 mlog(0, "time change...\n");
6335  
6336  #define OCFS2_VALID_ATTRS (ATTR_ATIME | ATTR_MTIME | ATTR_CTIME | ATTR_SIZE \
6337 -                          | ATTR_GID | ATTR_UID | ATTR_MODE)
6338 +                          | ATTR_GID | ATTR_UID | ATTR_TAG | ATTR_MODE)
6339         if (!(attr->ia_valid & OCFS2_VALID_ATTRS)) {
6340                 mlog(0, "can't handle attrs: 0x%x\n", attr->ia_valid);
6341                 return 0;
6342 diff -NurpP --minimal linux-2.6.38-rc8/fs/ocfs2/inode.c linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/ocfs2/inode.c
6343 --- linux-2.6.38-rc8/fs/ocfs2/inode.c   2011-03-10 17:09:24.000000000 +0100
6344 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/ocfs2/inode.c    2011-01-29 02:01:07.000000000 +0100
6345 @@ -28,6 +28,7 @@
6346  #include <linux/highmem.h>
6347  #include <linux/pagemap.h>
6348  #include <linux/quotaops.h>
6349 +#include <linux/vs_tag.h>
6350  
6351  #include <asm/byteorder.h>
6352  
6353 @@ -78,11 +79,13 @@ void ocfs2_set_inode_flags(struct inode 
6354  {
6355         unsigned int flags = OCFS2_I(inode)->ip_attr;
6356  
6357 -       inode->i_flags &= ~(S_IMMUTABLE |
6358 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
6359                 S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
6360  
6361         if (flags & OCFS2_IMMUTABLE_FL)
6362                 inode->i_flags |= S_IMMUTABLE;
6363 +       if (flags & OCFS2_IXUNLINK_FL)
6364 +               inode->i_flags |= S_IXUNLINK;
6365  
6366         if (flags & OCFS2_SYNC_FL)
6367                 inode->i_flags |= S_SYNC;
6368 @@ -92,25 +95,44 @@ void ocfs2_set_inode_flags(struct inode 
6369                 inode->i_flags |= S_NOATIME;
6370         if (flags & OCFS2_DIRSYNC_FL)
6371                 inode->i_flags |= S_DIRSYNC;
6372 +
6373 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
6374 +
6375 +       if (flags & OCFS2_BARRIER_FL)
6376 +               inode->i_vflags |= V_BARRIER;
6377 +       if (flags & OCFS2_COW_FL)
6378 +               inode->i_vflags |= V_COW;
6379  }
6380  
6381  /* Propagate flags from i_flags to OCFS2_I(inode)->ip_attr */
6382  void ocfs2_get_inode_flags(struct ocfs2_inode_info *oi)
6383  {
6384         unsigned int flags = oi->vfs_inode.i_flags;
6385 +       unsigned int vflags = oi->vfs_inode.i_vflags;
6386 +
6387 +       oi->ip_attr &= ~(OCFS2_SYNC_FL | OCFS2_APPEND_FL |
6388 +                       OCFS2_IMMUTABLE_FL | OCFS2_IXUNLINK_FL |
6389 +                       OCFS2_NOATIME_FL | OCFS2_DIRSYNC_FL |
6390 +                       OCFS2_BARRIER_FL | OCFS2_COW_FL);
6391 +
6392 +       if (flags & S_IMMUTABLE)
6393 +               oi->ip_attr |= OCFS2_IMMUTABLE_FL;
6394 +       if (flags & S_IXUNLINK)
6395 +               oi->ip_attr |= OCFS2_IXUNLINK_FL;
6396  
6397 -       oi->ip_attr &= ~(OCFS2_SYNC_FL|OCFS2_APPEND_FL|
6398 -                       OCFS2_IMMUTABLE_FL|OCFS2_NOATIME_FL|OCFS2_DIRSYNC_FL);
6399         if (flags & S_SYNC)
6400                 oi->ip_attr |= OCFS2_SYNC_FL;
6401         if (flags & S_APPEND)
6402                 oi->ip_attr |= OCFS2_APPEND_FL;
6403 -       if (flags & S_IMMUTABLE)
6404 -               oi->ip_attr |= OCFS2_IMMUTABLE_FL;
6405         if (flags & S_NOATIME)
6406                 oi->ip_attr |= OCFS2_NOATIME_FL;
6407         if (flags & S_DIRSYNC)
6408                 oi->ip_attr |= OCFS2_DIRSYNC_FL;
6409 +
6410 +       if (vflags & V_BARRIER)
6411 +               oi->ip_attr |= OCFS2_BARRIER_FL;
6412 +       if (vflags & V_COW)
6413 +               oi->ip_attr |= OCFS2_COW_FL;
6414  }
6415  
6416  struct inode *ocfs2_ilookup(struct super_block *sb, u64 blkno)
6417 @@ -245,6 +267,8 @@ void ocfs2_populate_inode(struct inode *
6418         struct super_block *sb;
6419         struct ocfs2_super *osb;
6420         int use_plocks = 1;
6421 +       uid_t uid;
6422 +       gid_t gid;
6423  
6424         mlog_entry("(0x%p, size:%llu)\n", inode,
6425                    (unsigned long long)le64_to_cpu(fe->i_size));
6426 @@ -276,8 +300,12 @@ void ocfs2_populate_inode(struct inode *
6427         inode->i_generation = le32_to_cpu(fe->i_generation);
6428         inode->i_rdev = huge_decode_dev(le64_to_cpu(fe->id1.dev1.i_rdev));
6429         inode->i_mode = le16_to_cpu(fe->i_mode);
6430 -       inode->i_uid = le32_to_cpu(fe->i_uid);
6431 -       inode->i_gid = le32_to_cpu(fe->i_gid);
6432 +       uid = le32_to_cpu(fe->i_uid);
6433 +       gid = le32_to_cpu(fe->i_gid);
6434 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
6435 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
6436 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid,
6437 +               /* le16_to_cpu(raw_inode->i_raw_tag)i */ 0);
6438  
6439         /* Fast symlinks will have i_size but no allocated clusters. */
6440         if (S_ISLNK(inode->i_mode) && !fe->i_clusters)
6441 diff -NurpP --minimal linux-2.6.38-rc8/fs/ocfs2/inode.h linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/ocfs2/inode.h
6442 --- linux-2.6.38-rc8/fs/ocfs2/inode.h   2011-01-05 21:50:26.000000000 +0100
6443 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/ocfs2/inode.h    2011-01-29 02:01:07.000000000 +0100
6444 @@ -151,6 +151,7 @@ struct buffer_head *ocfs2_bread(struct i
6445  
6446  void ocfs2_set_inode_flags(struct inode *inode);
6447  void ocfs2_get_inode_flags(struct ocfs2_inode_info *oi);
6448 +int ocfs2_sync_flags(struct inode *inode, int, int);
6449  
6450  static inline blkcnt_t ocfs2_inode_sector_count(struct inode *inode)
6451  {
6452 diff -NurpP --minimal linux-2.6.38-rc8/fs/ocfs2/ioctl.c linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/ocfs2/ioctl.c
6453 --- linux-2.6.38-rc8/fs/ocfs2/ioctl.c   2011-01-05 21:50:26.000000000 +0100
6454 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/ocfs2/ioctl.c    2011-01-29 02:01:07.000000000 +0100
6455 @@ -63,7 +63,41 @@ static int ocfs2_get_inode_attr(struct i
6456         return status;
6457  }
6458  
6459 -static int ocfs2_set_inode_attr(struct inode *inode, unsigned flags,
6460 +int ocfs2_sync_flags(struct inode *inode, int flags, int vflags)
6461 +{
6462 +       struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
6463 +       struct buffer_head *bh = NULL;
6464 +       handle_t *handle = NULL;
6465 +       int status;
6466 +
6467 +       status = ocfs2_inode_lock(inode, &bh, 1);
6468 +       if (status < 0) {
6469 +               mlog_errno(status);
6470 +               return status;
6471 +       }
6472 +       handle = ocfs2_start_trans(osb, OCFS2_INODE_UPDATE_CREDITS);
6473 +       if (IS_ERR(handle)) {
6474 +               status = PTR_ERR(handle);
6475 +               mlog_errno(status);
6476 +               goto bail_unlock;
6477 +       }
6478 +
6479 +       inode->i_flags = flags;
6480 +       inode->i_vflags = vflags;
6481 +       ocfs2_get_inode_flags(OCFS2_I(inode));
6482 +
6483 +       status = ocfs2_mark_inode_dirty(handle, inode, bh);
6484 +       if (status < 0)
6485 +               mlog_errno(status);
6486 +
6487 +       ocfs2_commit_trans(osb, handle);
6488 +bail_unlock:
6489 +       ocfs2_inode_unlock(inode, 1);
6490 +       brelse(bh);
6491 +       return status;
6492 +}
6493 +
6494 +int ocfs2_set_inode_attr(struct inode *inode, unsigned flags,
6495                                 unsigned mask)
6496  {
6497         struct ocfs2_inode_info *ocfs2_inode = OCFS2_I(inode);
6498 @@ -88,6 +122,11 @@ static int ocfs2_set_inode_attr(struct i
6499         if (!S_ISDIR(inode->i_mode))
6500                 flags &= ~OCFS2_DIRSYNC_FL;
6501  
6502 +       if (IS_BARRIER(inode)) {
6503 +               vxwprintk_task(1, "messing with the barrier.");
6504 +               goto bail_unlock;
6505 +       }
6506 +
6507         handle = ocfs2_start_trans(osb, OCFS2_INODE_UPDATE_CREDITS);
6508         if (IS_ERR(handle)) {
6509                 status = PTR_ERR(handle);
6510 @@ -451,6 +490,7 @@ bail:
6511         return status;
6512  }
6513  
6514 +
6515  long ocfs2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
6516  {
6517         struct inode *inode = filp->f_path.dentry->d_inode;
6518 diff -NurpP --minimal linux-2.6.38-rc8/fs/ocfs2/namei.c linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/ocfs2/namei.c
6519 --- linux-2.6.38-rc8/fs/ocfs2/namei.c   2011-03-10 17:09:24.000000000 +0100
6520 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/ocfs2/namei.c    2011-01-29 02:01:07.000000000 +0100
6521 @@ -41,6 +41,7 @@
6522  #include <linux/slab.h>
6523  #include <linux/highmem.h>
6524  #include <linux/quotaops.h>
6525 +#include <linux/vs_tag.h>
6526  
6527  #define MLOG_MASK_PREFIX ML_NAMEI
6528  #include <cluster/masklog.h>
6529 @@ -485,6 +486,7 @@ static int __ocfs2_mknod_locked(struct i
6530         struct ocfs2_dinode *fe = NULL;
6531         struct ocfs2_extent_list *fel;
6532         u16 feat;
6533 +       tag_t tag;
6534  
6535         *new_fe_bh = NULL;
6536  
6537 @@ -522,8 +524,11 @@ static int __ocfs2_mknod_locked(struct i
6538         fe->i_suballoc_loc = cpu_to_le64(suballoc_loc);
6539         fe->i_suballoc_bit = cpu_to_le16(suballoc_bit);
6540         fe->i_suballoc_slot = cpu_to_le16(inode_ac->ac_alloc_slot);
6541 -       fe->i_uid = cpu_to_le32(inode->i_uid);
6542 -       fe->i_gid = cpu_to_le32(inode->i_gid);
6543 +
6544 +       tag = dx_current_fstag(osb->sb);
6545 +       fe->i_uid = cpu_to_le32(TAGINO_UID(DX_TAG(inode), inode->i_uid, tag));
6546 +       fe->i_gid = cpu_to_le32(TAGINO_GID(DX_TAG(inode), inode->i_gid, tag));
6547 +       inode->i_tag = tag;
6548         fe->i_mode = cpu_to_le16(inode->i_mode);
6549         if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode))
6550                 fe->id1.dev1.i_rdev = cpu_to_le64(huge_encode_dev(dev));
6551 diff -NurpP --minimal linux-2.6.38-rc8/fs/ocfs2/ocfs2.h linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/ocfs2/ocfs2.h
6552 --- linux-2.6.38-rc8/fs/ocfs2/ocfs2.h   2011-03-10 17:09:24.000000000 +0100
6553 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/ocfs2/ocfs2.h    2011-01-29 02:01:07.000000000 +0100
6554 @@ -267,6 +267,7 @@ enum ocfs2_mount_options
6555                                                      writes */
6556         OCFS2_MOUNT_HB_NONE = 1 << 13, /* No heartbeat */
6557         OCFS2_MOUNT_HB_GLOBAL = 1 << 14, /* Global heartbeat */
6558 +       OCFS2_MOUNT_TAGGED = 1 << 15, /* use tagging */
6559  };
6560  
6561  #define OCFS2_OSB_SOFT_RO                      0x0001
6562 diff -NurpP --minimal linux-2.6.38-rc8/fs/ocfs2/ocfs2_fs.h linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/ocfs2/ocfs2_fs.h
6563 --- linux-2.6.38-rc8/fs/ocfs2/ocfs2_fs.h        2011-01-05 21:50:26.000000000 +0100
6564 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/ocfs2/ocfs2_fs.h 2011-01-29 02:01:07.000000000 +0100
6565 @@ -266,6 +266,11 @@
6566  #define OCFS2_TOPDIR_FL                        FS_TOPDIR_FL    /* Top of directory hierarchies*/
6567  #define OCFS2_RESERVED_FL              FS_RESERVED_FL  /* reserved for ext2 lib */
6568  
6569 +#define OCFS2_IXUNLINK_FL              FS_IXUNLINK_FL  /* Immutable invert on unlink */
6570 +
6571 +#define OCFS2_BARRIER_FL               FS_BARRIER_FL   /* Barrier for chroot() */
6572 +#define OCFS2_COW_FL                   FS_COW_FL       /* Copy on Write marker */
6573 +
6574  #define OCFS2_FL_VISIBLE               FS_FL_USER_VISIBLE      /* User visible flags */
6575  #define OCFS2_FL_MODIFIABLE            FS_FL_USER_MODIFIABLE   /* User modifiable flags */
6576  
6577 diff -NurpP --minimal linux-2.6.38-rc8/fs/ocfs2/super.c linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/ocfs2/super.c
6578 --- linux-2.6.38-rc8/fs/ocfs2/super.c   2011-03-10 17:09:24.000000000 +0100
6579 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/ocfs2/super.c    2011-03-07 16:53:27.000000000 +0100
6580 @@ -181,6 +181,7 @@ enum {
6581         Opt_coherency_full,
6582         Opt_resv_level,
6583         Opt_dir_resv_level,
6584 +       Opt_tag, Opt_notag, Opt_tagid,
6585         Opt_err,
6586  };
6587  
6588 @@ -212,6 +213,9 @@ static const match_table_t tokens = {
6589         {Opt_coherency_full, "coherency=full"},
6590         {Opt_resv_level, "resv_level=%u"},
6591         {Opt_dir_resv_level, "dir_resv_level=%u"},
6592 +       {Opt_tag, "tag"},
6593 +       {Opt_notag, "notag"},
6594 +       {Opt_tagid, "tagid=%u"},
6595         {Opt_err, NULL}
6596  };
6597  
6598 @@ -666,6 +670,13 @@ static int ocfs2_remount(struct super_bl
6599                 goto out;
6600         }
6601  
6602 +       if ((osb->s_mount_opt & OCFS2_MOUNT_TAGGED) !=
6603 +           (parsed_options.mount_opt & OCFS2_MOUNT_TAGGED)) {
6604 +               ret = -EINVAL;
6605 +               mlog(ML_ERROR, "Cannot change tagging on remount\n");
6606 +               goto out;
6607 +       }
6608 +
6609         /* We're going to/from readonly mode. */
6610         if ((*flags & MS_RDONLY) != (sb->s_flags & MS_RDONLY)) {
6611                 /* Disable quota accounting before remounting RO */
6612 @@ -1183,6 +1194,9 @@ static int ocfs2_fill_super(struct super
6613  
6614         ocfs2_complete_mount_recovery(osb);
6615  
6616 +       if (osb->s_mount_opt & OCFS2_MOUNT_TAGGED)
6617 +               sb->s_flags |= MS_TAGGED;
6618 +
6619         if (ocfs2_mount_local(osb))
6620                 snprintf(nodestr, sizeof(nodestr), "local");
6621         else
6622 @@ -1514,6 +1528,20 @@ static int ocfs2_parse_options(struct su
6623                             option < OCFS2_MAX_RESV_LEVEL)
6624                                 mopt->dir_resv_level = option;
6625                         break;
6626 +#ifndef CONFIG_TAGGING_NONE
6627 +               case Opt_tag:
6628 +                       mopt->mount_opt |= OCFS2_MOUNT_TAGGED;
6629 +                       break;
6630 +               case Opt_notag:
6631 +                       mopt->mount_opt &= ~OCFS2_MOUNT_TAGGED;
6632 +                       break;
6633 +#endif
6634 +#ifdef CONFIG_PROPAGATE
6635 +               case Opt_tagid:
6636 +                       /* use args[0] */
6637 +                       mopt->mount_opt |= OCFS2_MOUNT_TAGGED;
6638 +                       break;
6639 +#endif
6640                 default:
6641                         mlog(ML_ERROR,
6642                              "Unrecognized mount option \"%s\" "
6643 diff -NurpP --minimal linux-2.6.38-rc8/fs/open.c linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/open.c
6644 --- linux-2.6.38-rc8/fs/open.c  2011-03-10 17:09:24.000000000 +0100
6645 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/open.c   2011-02-17 02:17:50.000000000 +0100
6646 @@ -30,6 +30,11 @@
6647  #include <linux/fs_struct.h>
6648  #include <linux/ima.h>
6649  #include <linux/dnotify.h>
6650 +#include <linux/vs_base.h>
6651 +#include <linux/vs_limit.h>
6652 +#include <linux/vs_tag.h>
6653 +#include <linux/vs_cowbl.h>
6654 +#include <linux/vserver/dlimit.h>
6655  
6656  #include "internal.h"
6657  
6658 @@ -486,6 +491,12 @@ SYSCALL_DEFINE3(fchmodat, int, dfd, cons
6659         error = user_path_at(dfd, filename, LOOKUP_FOLLOW, &path);
6660         if (error)
6661                 goto out;
6662 +
6663 +#ifdef CONFIG_VSERVER_COWBL
6664 +       error = cow_check_and_break(&path);
6665 +       if (error)
6666 +               goto dput_and_out;
6667 +#endif
6668         inode = path.dentry->d_inode;
6669  
6670         error = mnt_want_write(path.mnt);
6671 @@ -523,11 +534,11 @@ static int chown_common(struct path *pat
6672         newattrs.ia_valid =  ATTR_CTIME;
6673         if (user != (uid_t) -1) {
6674                 newattrs.ia_valid |= ATTR_UID;
6675 -               newattrs.ia_uid = user;
6676 +               newattrs.ia_uid = dx_map_uid(user);
6677         }
6678         if (group != (gid_t) -1) {
6679                 newattrs.ia_valid |= ATTR_GID;
6680 -               newattrs.ia_gid = group;
6681 +               newattrs.ia_gid = dx_map_gid(group);
6682         }
6683         if (!S_ISDIR(inode->i_mode))
6684                 newattrs.ia_valid |=
6685 @@ -552,6 +563,10 @@ SYSCALL_DEFINE3(chown, const char __user
6686         error = mnt_want_write(path.mnt);
6687         if (error)
6688                 goto out_release;
6689 +#ifdef CONFIG_VSERVER_COWBL
6690 +       error = cow_check_and_break(&path);
6691 +       if (!error)
6692 +#endif
6693         error = chown_common(&path, user, group);
6694         mnt_drop_write(path.mnt);
6695  out_release:
6696 @@ -577,6 +592,10 @@ SYSCALL_DEFINE5(fchownat, int, dfd, cons
6697         error = mnt_want_write(path.mnt);
6698         if (error)
6699                 goto out_release;
6700 +#ifdef CONFIG_VSERVER_COWBL
6701 +       error = cow_check_and_break(&path);
6702 +       if (!error)
6703 +#endif
6704         error = chown_common(&path, user, group);
6705         mnt_drop_write(path.mnt);
6706  out_release:
6707 @@ -596,6 +615,10 @@ SYSCALL_DEFINE3(lchown, const char __use
6708         error = mnt_want_write(path.mnt);
6709         if (error)
6710                 goto out_release;
6711 +#ifdef CONFIG_VSERVER_COWBL
6712 +       error = cow_check_and_break(&path);
6713 +       if (!error)
6714 +#endif
6715         error = chown_common(&path, user, group);
6716         mnt_drop_write(path.mnt);
6717  out_release:
6718 @@ -844,6 +867,7 @@ static void __put_unused_fd(struct files
6719         __FD_CLR(fd, fdt->open_fds);
6720         if (fd < files->next_fd)
6721                 files->next_fd = fd;
6722 +       vx_openfd_dec(fd);
6723  }
6724  
6725  void put_unused_fd(unsigned int fd)
6726 diff -NurpP --minimal linux-2.6.38-rc8/fs/proc/array.c linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/proc/array.c
6727 --- linux-2.6.38-rc8/fs/proc/array.c    2011-03-10 17:09:24.000000000 +0100
6728 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/proc/array.c     2011-02-17 02:23:41.000000000 +0100
6729 @@ -81,6 +81,8 @@
6730  #include <linux/pid_namespace.h>
6731  #include <linux/ptrace.h>
6732  #include <linux/tracehook.h>
6733 +#include <linux/vs_context.h>
6734 +#include <linux/vs_network.h>
6735  
6736  #include <asm/pgtable.h>
6737  #include <asm/processor.h>
6738 @@ -170,6 +172,9 @@ static inline void task_state(struct seq
6739         rcu_read_lock();
6740         ppid = pid_alive(p) ?
6741                 task_tgid_nr_ns(rcu_dereference(p->real_parent), ns) : 0;
6742 +       if (unlikely(vx_current_initpid(p->pid)))
6743 +               ppid = 0;
6744 +
6745         tpid = 0;
6746         if (pid_alive(p)) {
6747                 struct task_struct *tracer = tracehook_tracer_task(p);
6748 @@ -287,7 +292,7 @@ static inline void task_sig(struct seq_f
6749  }
6750  
6751  static void render_cap_t(struct seq_file *m, const char *header,
6752 -                       kernel_cap_t *a)
6753 +                       struct vx_info *vxi, kernel_cap_t *a)
6754  {
6755         unsigned __capi;
6756  
6757 @@ -312,10 +317,11 @@ static inline void task_cap(struct seq_f
6758         cap_bset        = cred->cap_bset;
6759         rcu_read_unlock();
6760  
6761 -       render_cap_t(m, "CapInh:\t", &cap_inheritable);
6762 -       render_cap_t(m, "CapPrm:\t", &cap_permitted);
6763 -       render_cap_t(m, "CapEff:\t", &cap_effective);
6764 -       render_cap_t(m, "CapBnd:\t", &cap_bset);
6765 +       /* FIXME: maybe move the p->vx_info masking to __task_cred() ? */
6766 +       render_cap_t(m, "CapInh:\t", p->vx_info, &cap_inheritable);
6767 +       render_cap_t(m, "CapPrm:\t", p->vx_info, &cap_permitted);
6768 +       render_cap_t(m, "CapEff:\t", p->vx_info, &cap_effective);
6769 +       render_cap_t(m, "CapBnd:\t", p->vx_info, &cap_bset);
6770  }
6771  
6772  static inline void task_context_switch_counts(struct seq_file *m,
6773 @@ -337,6 +343,42 @@ static void task_cpus_allowed(struct seq
6774         seq_putc(m, '\n');
6775  }
6776  
6777 +int proc_pid_nsproxy(struct seq_file *m, struct pid_namespace *ns,
6778 +                       struct pid *pid, struct task_struct *task)
6779 +{
6780 +       seq_printf(m,   "Proxy:\t%p(%c)\n"
6781 +                       "Count:\t%u\n"
6782 +                       "uts:\t%p(%c)\n"
6783 +                       "ipc:\t%p(%c)\n"
6784 +                       "mnt:\t%p(%c)\n"
6785 +                       "pid:\t%p(%c)\n"
6786 +                       "net:\t%p(%c)\n",
6787 +                       task->nsproxy,
6788 +                       (task->nsproxy == init_task.nsproxy ? 'I' : '-'),
6789 +                       atomic_read(&task->nsproxy->count),
6790 +                       task->nsproxy->uts_ns,
6791 +                       (task->nsproxy->uts_ns == init_task.nsproxy->uts_ns ? 'I' : '-'),
6792 +                       task->nsproxy->ipc_ns,
6793 +                       (task->nsproxy->ipc_ns == init_task.nsproxy->ipc_ns ? 'I' : '-'),
6794 +                       task->nsproxy->mnt_ns,
6795 +                       (task->nsproxy->mnt_ns == init_task.nsproxy->mnt_ns ? 'I' : '-'),
6796 +                       task->nsproxy->pid_ns,
6797 +                       (task->nsproxy->pid_ns == init_task.nsproxy->pid_ns ? 'I' : '-'),
6798 +                       task->nsproxy->net_ns,
6799 +                       (task->nsproxy->net_ns == init_task.nsproxy->net_ns ? 'I' : '-'));
6800 +       return 0;
6801 +}
6802 +
6803 +void task_vs_id(struct seq_file *m, struct task_struct *task)
6804 +{
6805 +       if (task_vx_flags(task, VXF_HIDE_VINFO, 0))
6806 +               return;
6807 +
6808 +       seq_printf(m, "VxID: %d\n", vx_task_xid(task));
6809 +       seq_printf(m, "NxID: %d\n", nx_task_nid(task));
6810 +}
6811 +
6812 +
6813  int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
6814                         struct pid *pid, struct task_struct *task)
6815  {
6816 @@ -353,6 +395,7 @@ int proc_pid_status(struct seq_file *m, 
6817         task_cap(m, task);
6818         task_cpus_allowed(m, task);
6819         cpuset_task_status_allowed(m, task);
6820 +       task_vs_id(m, task);
6821         task_context_switch_counts(m, task);
6822         return 0;
6823  }
6824 @@ -462,6 +505,17 @@ static int do_task_stat(struct seq_file 
6825         /* convert nsec -> ticks */
6826         start_time = nsec_to_clock_t(start_time);
6827  
6828 +       /* fixup start time for virt uptime */
6829 +       if (vx_flags(VXF_VIRT_UPTIME, 0)) {
6830 +               unsigned long long bias =
6831 +                       current->vx_info->cvirt.bias_clock;
6832 +
6833 +               if (start_time > bias)
6834 +                       start_time -= bias;
6835 +               else
6836 +                       start_time = 0;
6837 +       }
6838 +
6839         seq_printf(m, "%d (%s) %c %d %d %d %d %d %u %lu \
6840  %lu %lu %lu %lu %lu %ld %ld %ld %ld %d 0 %llu %lu %ld %lu %lu %lu %lu %lu \
6841  %lu %lu %lu %lu %lu %lu %lu %lu %d %d %u %u %llu %lu %ld\n",
6842 diff -NurpP --minimal linux-2.6.38-rc8/fs/proc/base.c linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/proc/base.c
6843 --- linux-2.6.38-rc8/fs/proc/base.c     2011-03-10 17:09:24.000000000 +0100
6844 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/proc/base.c      2011-03-07 19:16:17.000000000 +0100
6845 @@ -83,6 +83,8 @@
6846  #include <linux/pid_namespace.h>
6847  #include <linux/fs_struct.h>
6848  #include <linux/slab.h>
6849 +#include <linux/vs_context.h>
6850 +#include <linux/vs_network.h>
6851  #include "internal.h"
6852  
6853  /* NOTE:
6854 @@ -1043,11 +1045,16 @@ static ssize_t oom_adjust_write(struct f
6855                 goto err_task_lock;
6856         }
6857  
6858 -       if (oom_adjust < task->signal->oom_adj && !capable(CAP_SYS_RESOURCE)) {
6859 +       if (oom_adjust < task->signal->oom_adj &&
6860 +               !vx_capable(CAP_SYS_RESOURCE, VXC_OOM_ADJUST)) {
6861                 err = -EACCES;
6862                 goto err_sighand;
6863         }
6864  
6865 +       /* prevent guest processes from circumventing the oom killer */
6866 +       if (vx_current_xid() && (oom_adjust == OOM_DISABLE))
6867 +               oom_adjust = OOM_ADJUST_MIN;
6868 +
6869         if (oom_adjust != task->signal->oom_adj) {
6870                 if (oom_adjust == OOM_DISABLE)
6871                         atomic_inc(&task->mm->oom_disable_count);
6872 @@ -1216,7 +1223,7 @@ static ssize_t proc_loginuid_write(struc
6873         ssize_t length;
6874         uid_t loginuid;
6875  
6876 -       if (!capable(CAP_AUDIT_CONTROL))
6877 +       if (!vx_capable(CAP_AUDIT_CONTROL, VXC_AUDIT_CONTROL))
6878                 return -EPERM;
6879  
6880         rcu_read_lock();
6881 @@ -1715,6 +1722,8 @@ static struct inode *proc_pid_make_inode
6882                 inode->i_gid = cred->egid;
6883                 rcu_read_unlock();
6884         }
6885 +       /* procfs is xid tagged */
6886 +       inode->i_tag = (tag_t)vx_task_xid(task);
6887         security_task_to_inode(task, inode);
6888  
6889  out:
6890 @@ -1751,6 +1760,8 @@ static int pid_getattr(struct vfsmount *
6891  
6892  /* dentry stuff */
6893  
6894 +static unsigned name_to_int(struct dentry *dentry);
6895 +
6896  /*
6897   *     Exceptional case: normally we are not allowed to unhash a busy
6898   * directory. In this case, however, we can do it - no aliasing problems
6899 @@ -1779,6 +1790,12 @@ static int pid_revalidate(struct dentry 
6900         task = get_proc_task(inode);
6901  
6902         if (task) {
6903 +               unsigned pid = name_to_int(dentry);
6904 +
6905 +               if (pid != ~0U && pid != vx_map_pid(task->pid)) {
6906 +                       put_task_struct(task);
6907 +                       goto drop;
6908 +               }
6909                 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
6910                     task_dumpable(task)) {
6911                         rcu_read_lock();
6912 @@ -1795,6 +1812,7 @@ static int pid_revalidate(struct dentry 
6913                 put_task_struct(task);
6914                 return 1;
6915         }
6916 +drop:
6917         d_drop(dentry);
6918         return 0;
6919  }
6920 @@ -2283,6 +2301,13 @@ static struct dentry *proc_pident_lookup
6921         if (!task)
6922                 goto out_no_task;
6923  
6924 +       /* TODO: maybe we can come up with a generic approach? */
6925 +       if (task_vx_flags(task, VXF_HIDE_VINFO, 0) &&
6926 +               (dentry->d_name.len == 5) &&
6927 +               (!memcmp(dentry->d_name.name, "vinfo", 5) ||
6928 +               !memcmp(dentry->d_name.name, "ninfo", 5)))
6929 +               goto out;
6930 +
6931         /*
6932          * Yes, it does not scale. And it should not. Don't add
6933          * new entries into /proc/<tgid>/ without very good reasons.
6934 @@ -2698,7 +2723,7 @@ out_iput:
6935  static struct dentry *proc_base_lookup(struct inode *dir, struct dentry *dentry)
6936  {
6937         struct dentry *error;
6938 -       struct task_struct *task = get_proc_task(dir);
6939 +       struct task_struct *task = get_proc_task_real(dir);
6940         const struct pid_entry *p, *last;
6941  
6942         error = ERR_PTR(-ENOENT);
6943 @@ -2788,6 +2813,9 @@ static int proc_pid_personality(struct s
6944  static const struct file_operations proc_task_operations;
6945  static const struct inode_operations proc_task_inode_operations;
6946  
6947 +extern int proc_pid_vx_info(struct task_struct *, char *);
6948 +extern int proc_pid_nx_info(struct task_struct *, char *);
6949 +
6950  static const struct pid_entry tgid_base_stuff[] = {
6951         DIR("task",       S_IRUGO|S_IXUGO, proc_task_inode_operations, proc_task_operations),
6952         DIR("fd",         S_IRUSR|S_IXUSR, proc_fd_inode_operations, proc_fd_operations),
6953 @@ -2850,6 +2878,8 @@ static const struct pid_entry tgid_base_
6954  #ifdef CONFIG_CGROUPS
6955         REG("cgroup",  S_IRUGO, proc_cgroup_operations),
6956  #endif
6957 +       INF("vinfo",      S_IRUGO, proc_pid_vx_info),
6958 +       INF("ninfo",      S_IRUGO, proc_pid_nx_info),
6959         INF("oom_score",  S_IRUGO, proc_oom_score),
6960         REG("oom_adj",    S_IRUGO|S_IWUSR, proc_oom_adjust_operations),
6961         REG("oom_score_adj", S_IRUGO|S_IWUSR, proc_oom_score_adj_operations),
6962 @@ -2866,6 +2896,7 @@ static const struct pid_entry tgid_base_
6963  #ifdef CONFIG_TASK_IO_ACCOUNTING
6964         INF("io",       S_IRUGO, proc_tgid_io_accounting),
6965  #endif
6966 +       ONE("nsproxy",  S_IRUGO, proc_pid_nsproxy),
6967  };
6968  
6969  static int proc_tgid_base_readdir(struct file * filp,
6970 @@ -3058,7 +3089,7 @@ retry:
6971         iter.task = NULL;
6972         pid = find_ge_pid(iter.tgid, ns);
6973         if (pid) {
6974 -               iter.tgid = pid_nr_ns(pid, ns);
6975 +               iter.tgid = pid_unmapped_nr_ns(pid, ns);
6976                 iter.task = pid_task(pid, PIDTYPE_PID);
6977                 /* What we to know is if the pid we have find is the
6978                  * pid of a thread_group_leader.  Testing for task
6979 @@ -3088,7 +3119,7 @@ static int proc_pid_fill_cache(struct fi
6980         struct tgid_iter iter)
6981  {
6982         char name[PROC_NUMBUF];
6983 -       int len = snprintf(name, sizeof(name), "%d", iter.tgid);
6984 +       int len = snprintf(name, sizeof(name), "%d", vx_map_tgid(iter.tgid));
6985         return proc_fill_cache(filp, dirent, filldir, name, len,
6986                                 proc_pid_instantiate, iter.task, NULL);
6987  }
6988 @@ -3097,7 +3128,7 @@ static int proc_pid_fill_cache(struct fi
6989  int proc_pid_readdir(struct file * filp, void * dirent, filldir_t filldir)
6990  {
6991         unsigned int nr = filp->f_pos - FIRST_PROCESS_ENTRY;
6992 -       struct task_struct *reaper = get_proc_task(filp->f_path.dentry->d_inode);
6993 +       struct task_struct *reaper = get_proc_task_real(filp->f_path.dentry->d_inode);
6994         struct tgid_iter iter;
6995         struct pid_namespace *ns;
6996  
6997 @@ -3117,6 +3148,8 @@ int proc_pid_readdir(struct file * filp,
6998              iter.task;
6999              iter.tgid += 1, iter = next_tgid(ns, iter)) {
7000                 filp->f_pos = iter.tgid + TGID_OFFSET;
7001 +               if (!vx_proc_task_visible(iter.task))
7002 +                       continue;
7003                 if (proc_pid_fill_cache(filp, dirent, filldir, iter) < 0) {
7004                         put_task_struct(iter.task);
7005                         goto out;
7006 @@ -3266,6 +3299,8 @@ static struct dentry *proc_task_lookup(s
7007         tid = name_to_int(dentry);
7008         if (tid == ~0U)
7009                 goto out;
7010 +       if (vx_current_initpid(tid))
7011 +               goto out;
7012  
7013         ns = dentry->d_sb->s_fs_info;
7014         rcu_read_lock();
7015 diff -NurpP --minimal linux-2.6.38-rc8/fs/proc/generic.c linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/proc/generic.c
7016 --- linux-2.6.38-rc8/fs/proc/generic.c  2011-03-10 17:09:24.000000000 +0100
7017 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/proc/generic.c   2011-01-29 02:29:09.000000000 +0100
7018 @@ -22,6 +22,7 @@
7019  #include <linux/bitops.h>
7020  #include <linux/spinlock.h>
7021  #include <linux/completion.h>
7022 +#include <linux/vserver/inode.h>
7023  #include <asm/uaccess.h>
7024  
7025  #include "internal.h"
7026 @@ -424,11 +425,15 @@ struct dentry *proc_lookup_de(struct pro
7027         for (de = de->subdir; de ; de = de->next) {
7028                 if (de->namelen != dentry->d_name.len)
7029                         continue;
7030 +               if (!vx_hide_check(0, de->vx_flags))
7031 +                       continue;
7032                 if (!memcmp(dentry->d_name.name, de->name, de->namelen)) {
7033                         pde_get(de);
7034                         spin_unlock(&proc_subdir_lock);
7035                         error = -EINVAL;
7036                         inode = proc_get_inode(dir->i_sb, de);
7037 +                       /* generic proc entries belong to the host */
7038 +                       inode->i_tag = 0;
7039                         goto out_unlock;
7040                 }
7041         }
7042 @@ -506,6 +511,8 @@ int proc_readdir_de(struct proc_dir_entr
7043  
7044                                 /* filldir passes info to user space */
7045                                 pde_get(de);
7046 +                               if (!vx_hide_check(0, de->vx_flags))
7047 +                                       goto skip;
7048                                 spin_unlock(&proc_subdir_lock);
7049                                 if (filldir(dirent, de->name, de->namelen, filp->f_pos,
7050                                             de->low_ino, de->mode >> 12) < 0) {
7051 @@ -513,6 +520,7 @@ int proc_readdir_de(struct proc_dir_entr
7052                                         goto out;
7053                                 }
7054                                 spin_lock(&proc_subdir_lock);
7055 +                       skip:
7056                                 filp->f_pos++;
7057                                 next = de->next;
7058                                 pde_put(de);
7059 @@ -627,6 +635,7 @@ static struct proc_dir_entry *__proc_cre
7060         ent->nlink = nlink;
7061         atomic_set(&ent->count, 1);
7062         ent->pde_users = 0;
7063 +       ent->vx_flags = IATTR_PROC_DEFAULT;
7064         spin_lock_init(&ent->pde_unload_lock);
7065         ent->pde_unload_completion = NULL;
7066         INIT_LIST_HEAD(&ent->pde_openers);
7067 @@ -650,7 +659,8 @@ struct proc_dir_entry *proc_symlink(cons
7068                                 kfree(ent->data);
7069                                 kfree(ent);
7070                                 ent = NULL;
7071 -                       }
7072 +                       } else
7073 +                               ent->vx_flags = IATTR_PROC_SYMLINK;
7074                 } else {
7075                         kfree(ent);
7076                         ent = NULL;
7077 diff -NurpP --minimal linux-2.6.38-rc8/fs/proc/inode.c linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/proc/inode.c
7078 --- linux-2.6.38-rc8/fs/proc/inode.c    2011-03-10 17:09:24.000000000 +0100
7079 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/proc/inode.c     2011-01-29 02:01:07.000000000 +0100
7080 @@ -433,6 +433,8 @@ struct inode *proc_get_inode(struct supe
7081                         inode->i_uid = de->uid;
7082                         inode->i_gid = de->gid;
7083                 }
7084 +               if (de->vx_flags)
7085 +                       PROC_I(inode)->vx_flags = de->vx_flags;
7086                 if (de->size)
7087                         inode->i_size = de->size;
7088                 if (de->nlink)
7089 diff -NurpP --minimal linux-2.6.38-rc8/fs/proc/internal.h linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/proc/internal.h
7090 --- linux-2.6.38-rc8/fs/proc/internal.h 2011-03-10 17:09:24.000000000 +0100
7091 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/proc/internal.h  2011-01-29 02:01:07.000000000 +0100
7092 @@ -10,6 +10,7 @@
7093   */
7094  
7095  #include <linux/proc_fs.h>
7096 +#include <linux/vs_pid.h>
7097  
7098  extern struct proc_dir_entry proc_root;
7099  #ifdef CONFIG_PROC_SYSCTL
7100 @@ -51,6 +52,9 @@ extern int proc_pid_status(struct seq_fi
7101                                 struct pid *pid, struct task_struct *task);
7102  extern int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
7103                                 struct pid *pid, struct task_struct *task);
7104 +extern int proc_pid_nsproxy(struct seq_file *m, struct pid_namespace *ns,
7105 +                               struct pid *pid, struct task_struct *task);
7106 +
7107  extern loff_t mem_lseek(struct file *file, loff_t offset, int orig);
7108  
7109  extern const struct file_operations proc_maps_operations;
7110 @@ -68,11 +72,16 @@ static inline struct pid *proc_pid(struc
7111         return PROC_I(inode)->pid;
7112  }
7113  
7114 -static inline struct task_struct *get_proc_task(struct inode *inode)
7115 +static inline struct task_struct *get_proc_task_real(struct inode *inode)
7116  {
7117         return get_pid_task(proc_pid(inode), PIDTYPE_PID);
7118  }
7119  
7120 +static inline struct task_struct *get_proc_task(struct inode *inode)
7121 +{
7122 +       return vx_get_proc_task(inode, proc_pid(inode));
7123 +}
7124 +
7125  static inline int proc_fd(struct inode *inode)
7126  {
7127         return PROC_I(inode)->fd;
7128 diff -NurpP --minimal linux-2.6.38-rc8/fs/proc/loadavg.c linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/proc/loadavg.c
7129 --- linux-2.6.38-rc8/fs/proc/loadavg.c  2009-09-10 15:26:23.000000000 +0200
7130 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/proc/loadavg.c   2011-01-29 02:01:07.000000000 +0100
7131 @@ -12,15 +12,27 @@
7132  
7133  static int loadavg_proc_show(struct seq_file *m, void *v)
7134  {
7135 +       unsigned long running;
7136 +       unsigned int threads;
7137         unsigned long avnrun[3];
7138  
7139         get_avenrun(avnrun, FIXED_1/200, 0);
7140  
7141 +       if (vx_flags(VXF_VIRT_LOAD, 0)) {
7142 +               struct vx_info *vxi = current_vx_info();
7143 +
7144 +               running = atomic_read(&vxi->cvirt.nr_running);
7145 +               threads = atomic_read(&vxi->cvirt.nr_threads);
7146 +       } else {
7147 +               running = nr_running();
7148 +               threads = nr_threads;
7149 +       }
7150 +
7151         seq_printf(m, "%lu.%02lu %lu.%02lu %lu.%02lu %ld/%d %d\n",
7152                 LOAD_INT(avnrun[0]), LOAD_FRAC(avnrun[0]),
7153                 LOAD_INT(avnrun[1]), LOAD_FRAC(avnrun[1]),
7154                 LOAD_INT(avnrun[2]), LOAD_FRAC(avnrun[2]),
7155 -               nr_running(), nr_threads,
7156 +               running, threads,
7157                 task_active_pid_ns(current)->last_pid);
7158         return 0;
7159  }
7160 diff -NurpP --minimal linux-2.6.38-rc8/fs/proc/meminfo.c linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/proc/meminfo.c
7161 --- linux-2.6.38-rc8/fs/proc/meminfo.c  2011-03-10 17:09:24.000000000 +0100
7162 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/proc/meminfo.c   2011-01-29 02:01:07.000000000 +0100
7163 @@ -39,7 +39,8 @@ static int meminfo_proc_show(struct seq_
7164         allowed = ((totalram_pages - hugetlb_total_pages())
7165                 * sysctl_overcommit_ratio / 100) + total_swap_pages;
7166  
7167 -       cached = global_page_state(NR_FILE_PAGES) -
7168 +       cached = vx_flags(VXF_VIRT_MEM, 0) ?
7169 +               vx_vsi_cached(&i) : global_page_state(NR_FILE_PAGES) -
7170                         total_swapcache_pages - i.bufferram;
7171         if (cached < 0)
7172                 cached = 0;
7173 diff -NurpP --minimal linux-2.6.38-rc8/fs/proc/root.c linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/proc/root.c
7174 --- linux-2.6.38-rc8/fs/proc/root.c     2011-01-05 21:50:26.000000000 +0100
7175 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/proc/root.c      2011-01-29 02:01:07.000000000 +0100
7176 @@ -18,9 +18,14 @@
7177  #include <linux/bitops.h>
7178  #include <linux/mount.h>
7179  #include <linux/pid_namespace.h>
7180 +#include <linux/vserver/inode.h>
7181  
7182  #include "internal.h"
7183  
7184 +struct proc_dir_entry *proc_virtual;
7185 +
7186 +extern void proc_vx_init(void);
7187 +
7188  static int proc_test_super(struct super_block *sb, void *data)
7189  {
7190         return sb->s_fs_info == data;
7191 @@ -134,6 +139,7 @@ void __init proc_root_init(void)
7192  #endif
7193         proc_mkdir("bus", NULL);
7194         proc_sys_init();
7195 +       proc_vx_init();
7196  }
7197  
7198  static int proc_root_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat
7199 @@ -202,6 +208,7 @@ struct proc_dir_entry proc_root = {
7200         .proc_iops      = &proc_root_inode_operations, 
7201         .proc_fops      = &proc_root_operations,
7202         .parent         = &proc_root,
7203 +       .vx_flags       = IATTR_ADMIN | IATTR_WATCH,
7204  };
7205  
7206  int pid_ns_prepare_proc(struct pid_namespace *ns)
7207 diff -NurpP --minimal linux-2.6.38-rc8/fs/proc/uptime.c linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/proc/uptime.c
7208 --- linux-2.6.38-rc8/fs/proc/uptime.c   2009-12-03 20:02:53.000000000 +0100
7209 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/proc/uptime.c    2011-01-29 02:01:07.000000000 +0100
7210 @@ -4,22 +4,22 @@
7211  #include <linux/sched.h>
7212  #include <linux/seq_file.h>
7213  #include <linux/time.h>
7214 -#include <linux/kernel_stat.h>
7215 +#include <linux/vserver/cvirt.h>
7216  #include <asm/cputime.h>
7217  
7218  static int uptime_proc_show(struct seq_file *m, void *v)
7219  {
7220         struct timespec uptime;
7221         struct timespec idle;
7222 -       int i;
7223 -       cputime_t idletime = cputime_zero;
7224 -
7225 -       for_each_possible_cpu(i)
7226 -               idletime = cputime64_add(idletime, kstat_cpu(i).cpustat.idle);
7227 +       cputime_t idletime = cputime_add(init_task.utime, init_task.stime);
7228  
7229         do_posix_clock_monotonic_gettime(&uptime);
7230         monotonic_to_bootbased(&uptime);
7231         cputime_to_timespec(idletime, &idle);
7232 +
7233 +       if (vx_flags(VXF_VIRT_UPTIME, 0))
7234 +               vx_vsi_uptime(&uptime, &idle);
7235 +
7236         seq_printf(m, "%lu.%02lu %lu.%02lu\n",
7237                         (unsigned long) uptime.tv_sec,
7238                         (uptime.tv_nsec / (NSEC_PER_SEC / 100)),
7239 diff -NurpP --minimal linux-2.6.38-rc8/fs/quota/dquot.c linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/quota/dquot.c
7240 --- linux-2.6.38-rc8/fs/quota/dquot.c   2011-03-10 17:09:24.000000000 +0100
7241 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/quota/dquot.c    2011-01-29 02:01:07.000000000 +0100
7242 @@ -1545,6 +1545,9 @@ int __dquot_alloc_space(struct inode *in
7243         int reserve = flags & DQUOT_SPACE_RESERVE;
7244         int nofail = flags & DQUOT_SPACE_NOFAIL;
7245  
7246 +       if ((ret = dl_alloc_space(inode, number)))
7247 +               return ret;
7248 +
7249         /*
7250          * First test before acquiring mutex - solves deadlocks when we
7251          * re-enter the quota code and are already holding the mutex
7252 @@ -1599,6 +1602,9 @@ int dquot_alloc_inode(const struct inode
7253         int cnt, ret = 0;
7254         char warntype[MAXQUOTAS];
7255  
7256 +       if ((ret = dl_alloc_inode(inode)))
7257 +               return ret;
7258 +
7259         /* First test before acquiring mutex - solves deadlocks when we
7260           * re-enter the quota code and are already holding the mutex */
7261         if (!dquot_active(inode))
7262 @@ -1669,6 +1675,8 @@ void __dquot_free_space(struct inode *in
7263         char warntype[MAXQUOTAS];
7264         int reserve = flags & DQUOT_SPACE_RESERVE;
7265  
7266 +       dl_free_space(inode, number);
7267 +
7268         /* First test before acquiring mutex - solves deadlocks when we
7269           * re-enter the quota code and are already holding the mutex */
7270         if (!dquot_active(inode)) {
7271 @@ -1707,6 +1715,8 @@ void dquot_free_inode(const struct inode
7272         unsigned int cnt;
7273         char warntype[MAXQUOTAS];
7274  
7275 +       dl_free_inode(inode);
7276 +
7277         /* First test before acquiring mutex - solves deadlocks when we
7278           * re-enter the quota code and are already holding the mutex */
7279         if (!dquot_active(inode))
7280 diff -NurpP --minimal linux-2.6.38-rc8/fs/quota/quota.c linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/quota/quota.c
7281 --- linux-2.6.38-rc8/fs/quota/quota.c   2011-03-10 17:09:24.000000000 +0100
7282 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/quota/quota.c    2011-01-29 02:01:07.000000000 +0100
7283 @@ -8,6 +8,7 @@
7284  #include <linux/fs.h>
7285  #include <linux/namei.h>
7286  #include <linux/slab.h>
7287 +#include <linux/vs_context.h>
7288  #include <asm/current.h>
7289  #include <asm/uaccess.h>
7290  #include <linux/kernel.h>
7291 @@ -38,7 +39,7 @@ static int check_quotactl_permission(str
7292                         break;
7293                 /*FALLTHROUGH*/
7294         default:
7295 -               if (!capable(CAP_SYS_ADMIN))
7296 +               if (!vx_capable(CAP_SYS_ADMIN, VXC_QUOTA_CTL))
7297                         return -EPERM;
7298         }
7299  
7300 @@ -293,6 +294,46 @@ static int do_quotactl(struct super_bloc
7301         }
7302  }
7303  
7304 +#if defined(CONFIG_BLK_DEV_VROOT) || defined(CONFIG_BLK_DEV_VROOT_MODULE)
7305 +
7306 +#include <linux/vroot.h>
7307 +#include <linux/major.h>
7308 +#include <linux/module.h>
7309 +#include <linux/kallsyms.h>
7310 +#include <linux/vserver/debug.h>
7311 +
7312 +static vroot_grb_func *vroot_get_real_bdev = NULL;
7313 +
7314 +static spinlock_t vroot_grb_lock = SPIN_LOCK_UNLOCKED;
7315 +
7316 +int register_vroot_grb(vroot_grb_func *func) {
7317 +       int ret = -EBUSY;
7318 +
7319 +       spin_lock(&vroot_grb_lock);
7320 +       if (!vroot_get_real_bdev) {
7321 +               vroot_get_real_bdev = func;
7322 +               ret = 0;
7323 +       }
7324 +       spin_unlock(&vroot_grb_lock);
7325 +       return ret;
7326 +}
7327 +EXPORT_SYMBOL(register_vroot_grb);
7328 +
7329 +int unregister_vroot_grb(vroot_grb_func *func) {
7330 +       int ret = -EINVAL;
7331 +
7332 +       spin_lock(&vroot_grb_lock);
7333 +       if (vroot_get_real_bdev) {
7334 +               vroot_get_real_bdev = NULL;
7335 +               ret = 0;
7336 +       }
7337 +       spin_unlock(&vroot_grb_lock);
7338 +       return ret;
7339 +}
7340 +EXPORT_SYMBOL(unregister_vroot_grb);
7341 +
7342 +#endif
7343 +
7344  /*
7345   * look up a superblock on which quota ops will be performed
7346   * - use the name of a block device to find the superblock thereon
7347 @@ -310,6 +351,22 @@ static struct super_block *quotactl_bloc
7348         putname(tmp);
7349         if (IS_ERR(bdev))
7350                 return ERR_CAST(bdev);
7351 +#if defined(CONFIG_BLK_DEV_VROOT) || defined(CONFIG_BLK_DEV_VROOT_MODULE)
7352 +       if (bdev && bdev->bd_inode &&
7353 +                       imajor(bdev->bd_inode) == VROOT_MAJOR) {
7354 +               struct block_device *bdnew = (void *)-EINVAL;
7355 +
7356 +               if (vroot_get_real_bdev)
7357 +                       bdnew = vroot_get_real_bdev(bdev);
7358 +               else
7359 +                       vxdprintk(VXD_CBIT(misc, 0),
7360 +                                       "vroot_get_real_bdev not set");
7361 +               bdput(bdev);
7362 +               if (IS_ERR(bdnew))
7363 +                       return ERR_PTR(PTR_ERR(bdnew));
7364 +               bdev = bdnew;
7365 +       }
7366 +#endif
7367         sb = get_super(bdev);
7368         bdput(bdev);
7369         if (!sb)
7370 diff -NurpP --minimal linux-2.6.38-rc8/fs/reiserfs/file.c linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/reiserfs/file.c
7371 --- linux-2.6.38-rc8/fs/reiserfs/file.c 2011-01-05 21:50:26.000000000 +0100
7372 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/reiserfs/file.c  2011-01-29 02:01:07.000000000 +0100
7373 @@ -312,4 +312,5 @@ const struct inode_operations reiserfs_f
7374         .listxattr = reiserfs_listxattr,
7375         .removexattr = reiserfs_removexattr,
7376         .permission = reiserfs_permission,
7377 +       .sync_flags = reiserfs_sync_flags,
7378  };
7379 diff -NurpP --minimal linux-2.6.38-rc8/fs/reiserfs/inode.c linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/reiserfs/inode.c
7380 --- linux-2.6.38-rc8/fs/reiserfs/inode.c        2011-01-05 21:50:26.000000000 +0100
7381 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/reiserfs/inode.c 2011-01-29 02:01:07.000000000 +0100
7382 @@ -18,6 +18,7 @@
7383  #include <linux/writeback.h>
7384  #include <linux/quotaops.h>
7385  #include <linux/swap.h>
7386 +#include <linux/vs_tag.h>
7387  
7388  int reiserfs_commit_write(struct file *f, struct page *page,
7389                           unsigned from, unsigned to);
7390 @@ -1131,6 +1132,8 @@ static void init_inode(struct inode *ino
7391         struct buffer_head *bh;
7392         struct item_head *ih;
7393         __u32 rdev;
7394 +       uid_t uid;
7395 +       gid_t gid;
7396         //int version = ITEM_VERSION_1;
7397  
7398         bh = PATH_PLAST_BUFFER(path);
7399 @@ -1151,12 +1154,13 @@ static void init_inode(struct inode *ino
7400                     (struct stat_data_v1 *)B_I_PITEM(bh, ih);
7401                 unsigned long blocks;
7402  
7403 +               uid = sd_v1_uid(sd);
7404 +               gid = sd_v1_gid(sd);
7405 +
7406                 set_inode_item_key_version(inode, KEY_FORMAT_3_5);
7407                 set_inode_sd_version(inode, STAT_DATA_V1);
7408                 inode->i_mode = sd_v1_mode(sd);
7409                 inode->i_nlink = sd_v1_nlink(sd);
7410 -               inode->i_uid = sd_v1_uid(sd);
7411 -               inode->i_gid = sd_v1_gid(sd);
7412                 inode->i_size = sd_v1_size(sd);
7413                 inode->i_atime.tv_sec = sd_v1_atime(sd);
7414                 inode->i_mtime.tv_sec = sd_v1_mtime(sd);
7415 @@ -1198,11 +1202,12 @@ static void init_inode(struct inode *ino
7416                 // (directories and symlinks)
7417                 struct stat_data *sd = (struct stat_data *)B_I_PITEM(bh, ih);
7418  
7419 +               uid    = sd_v2_uid(sd);
7420 +               gid    = sd_v2_gid(sd);
7421 +
7422                 inode->i_mode = sd_v2_mode(sd);
7423                 inode->i_nlink = sd_v2_nlink(sd);
7424 -               inode->i_uid = sd_v2_uid(sd);
7425                 inode->i_size = sd_v2_size(sd);
7426 -               inode->i_gid = sd_v2_gid(sd);
7427                 inode->i_mtime.tv_sec = sd_v2_mtime(sd);
7428                 inode->i_atime.tv_sec = sd_v2_atime(sd);
7429                 inode->i_ctime.tv_sec = sd_v2_ctime(sd);
7430 @@ -1232,6 +1237,10 @@ static void init_inode(struct inode *ino
7431                 sd_attrs_to_i_attrs(sd_v2_attrs(sd), inode);
7432         }
7433  
7434 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
7435 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
7436 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid, 0);
7437 +
7438         pathrelse(path);
7439         if (S_ISREG(inode->i_mode)) {
7440                 inode->i_op = &reiserfs_file_inode_operations;
7441 @@ -1254,13 +1263,15 @@ static void init_inode(struct inode *ino
7442  static void inode2sd(void *sd, struct inode *inode, loff_t size)
7443  {
7444         struct stat_data *sd_v2 = (struct stat_data *)sd;
7445 +       uid_t uid = TAGINO_UID(DX_TAG(inode), inode->i_uid, inode->i_tag);
7446 +       gid_t gid = TAGINO_GID(DX_TAG(inode), inode->i_gid, inode->i_tag);
7447         __u16 flags;
7448  
7449 +       set_sd_v2_uid(sd_v2, uid);
7450 +       set_sd_v2_gid(sd_v2, gid);
7451         set_sd_v2_mode(sd_v2, inode->i_mode);
7452         set_sd_v2_nlink(sd_v2, inode->i_nlink);
7453 -       set_sd_v2_uid(sd_v2, inode->i_uid);
7454         set_sd_v2_size(sd_v2, size);
7455 -       set_sd_v2_gid(sd_v2, inode->i_gid);
7456         set_sd_v2_mtime(sd_v2, inode->i_mtime.tv_sec);
7457         set_sd_v2_atime(sd_v2, inode->i_atime.tv_sec);
7458         set_sd_v2_ctime(sd_v2, inode->i_ctime.tv_sec);
7459 @@ -2858,14 +2869,19 @@ int reiserfs_commit_write(struct file *f
7460  void sd_attrs_to_i_attrs(__u16 sd_attrs, struct inode *inode)
7461  {
7462         if (reiserfs_attrs(inode->i_sb)) {
7463 -               if (sd_attrs & REISERFS_SYNC_FL)
7464 -                       inode->i_flags |= S_SYNC;
7465 -               else
7466 -                       inode->i_flags &= ~S_SYNC;
7467                 if (sd_attrs & REISERFS_IMMUTABLE_FL)
7468                         inode->i_flags |= S_IMMUTABLE;
7469                 else
7470                         inode->i_flags &= ~S_IMMUTABLE;
7471 +               if (sd_attrs & REISERFS_IXUNLINK_FL)
7472 +                       inode->i_flags |= S_IXUNLINK;
7473 +               else
7474 +                       inode->i_flags &= ~S_IXUNLINK;
7475 +
7476 +               if (sd_attrs & REISERFS_SYNC_FL)
7477 +                       inode->i_flags |= S_SYNC;
7478 +               else
7479 +                       inode->i_flags &= ~S_SYNC;
7480                 if (sd_attrs & REISERFS_APPEND_FL)
7481                         inode->i_flags |= S_APPEND;
7482                 else
7483 @@ -2878,6 +2894,15 @@ void sd_attrs_to_i_attrs(__u16 sd_attrs,
7484                         REISERFS_I(inode)->i_flags |= i_nopack_mask;
7485                 else
7486                         REISERFS_I(inode)->i_flags &= ~i_nopack_mask;
7487 +
7488 +               if (sd_attrs & REISERFS_BARRIER_FL)
7489 +                       inode->i_vflags |= V_BARRIER;
7490 +               else
7491 +                       inode->i_vflags &= ~V_BARRIER;
7492 +               if (sd_attrs & REISERFS_COW_FL)
7493 +                       inode->i_vflags |= V_COW;
7494 +               else
7495 +                       inode->i_vflags &= ~V_COW;
7496         }
7497  }
7498  
7499 @@ -2888,6 +2913,11 @@ void i_attrs_to_sd_attrs(struct inode *i
7500                         *sd_attrs |= REISERFS_IMMUTABLE_FL;
7501                 else
7502                         *sd_attrs &= ~REISERFS_IMMUTABLE_FL;
7503 +               if (inode->i_flags & S_IXUNLINK)
7504 +                       *sd_attrs |= REISERFS_IXUNLINK_FL;
7505 +               else
7506 +                       *sd_attrs &= ~REISERFS_IXUNLINK_FL;
7507 +
7508                 if (inode->i_flags & S_SYNC)
7509                         *sd_attrs |= REISERFS_SYNC_FL;
7510                 else
7511 @@ -2900,6 +2930,15 @@ void i_attrs_to_sd_attrs(struct inode *i
7512                         *sd_attrs |= REISERFS_NOTAIL_FL;
7513                 else
7514                         *sd_attrs &= ~REISERFS_NOTAIL_FL;
7515 +
7516 +               if (inode->i_vflags & V_BARRIER)
7517 +                       *sd_attrs |= REISERFS_BARRIER_FL;
7518 +               else
7519 +                       *sd_attrs &= ~REISERFS_BARRIER_FL;
7520 +               if (inode->i_vflags & V_COW)
7521 +                       *sd_attrs |= REISERFS_COW_FL;
7522 +               else
7523 +                       *sd_attrs &= ~REISERFS_COW_FL;
7524         }
7525  }
7526  
7527 @@ -3143,7 +3182,8 @@ int reiserfs_setattr(struct dentry *dent
7528         }
7529  
7530         if ((ia_valid & ATTR_UID && attr->ia_uid != inode->i_uid) ||
7531 -           (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid)) {
7532 +           (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid) ||
7533 +           (ia_valid & ATTR_TAG && attr->ia_tag != inode->i_tag)) {
7534                 struct reiserfs_transaction_handle th;
7535                 int jbegin_count =
7536                     2 *
7537 @@ -3172,6 +3212,9 @@ int reiserfs_setattr(struct dentry *dent
7538                         inode->i_uid = attr->ia_uid;
7539                 if (attr->ia_valid & ATTR_GID)
7540                         inode->i_gid = attr->ia_gid;
7541 +                               if ((attr->ia_valid & ATTR_TAG) &&
7542 +                                       IS_TAGGED(inode))
7543 +                                       inode->i_tag = attr->ia_tag;
7544                 mark_inode_dirty(inode);
7545                 error = journal_end(&th, inode->i_sb, jbegin_count);
7546                 if (error)
7547 diff -NurpP --minimal linux-2.6.38-rc8/fs/reiserfs/ioctl.c linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/reiserfs/ioctl.c
7548 --- linux-2.6.38-rc8/fs/reiserfs/ioctl.c        2011-01-05 21:50:26.000000000 +0100
7549 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/reiserfs/ioctl.c 2011-01-29 02:01:07.000000000 +0100
7550 @@ -11,6 +11,21 @@
7551  #include <linux/pagemap.h>
7552  #include <linux/compat.h>
7553  
7554 +
7555 +int reiserfs_sync_flags(struct inode *inode, int flags, int vflags)
7556 +{
7557 +       __u16 sd_attrs = 0;
7558 +
7559 +       inode->i_flags = flags;
7560 +       inode->i_vflags = vflags;
7561 +
7562 +       i_attrs_to_sd_attrs(inode, &sd_attrs);
7563 +       REISERFS_I(inode)->i_attrs = sd_attrs;
7564 +       inode->i_ctime = CURRENT_TIME_SEC;
7565 +       mark_inode_dirty(inode);
7566 +       return 0;
7567 +}
7568 +
7569  /*
7570   * reiserfs_ioctl - handler for ioctl for inode
7571   * supported commands:
7572 @@ -22,7 +37,7 @@
7573  long reiserfs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
7574  {
7575         struct inode *inode = filp->f_path.dentry->d_inode;
7576 -       unsigned int flags;
7577 +       unsigned int flags, oldflags;
7578         int err = 0;
7579  
7580         reiserfs_write_lock(inode->i_sb);
7581 @@ -47,6 +62,7 @@ long reiserfs_ioctl(struct file *filp, u
7582  
7583                 flags = REISERFS_I(inode)->i_attrs;
7584                 i_attrs_to_sd_attrs(inode, (__u16 *) & flags);
7585 +               flags &= REISERFS_FL_USER_VISIBLE;
7586                 err = put_user(flags, (int __user *)arg);
7587                 break;
7588         case REISERFS_IOC_SETFLAGS:{
7589 @@ -67,6 +83,10 @@ long reiserfs_ioctl(struct file *filp, u
7590                                 err = -EFAULT;
7591                                 goto setflags_out;
7592                         }
7593 +                       if (IS_BARRIER(inode)) {
7594 +                               vxwprintk_task(1, "messing with the barrier.");
7595 +                               return -EACCES;
7596 +                       }
7597                         /*
7598                          * Is it quota file? Do not allow user to mess with it
7599                          */
7600 @@ -91,6 +111,10 @@ long reiserfs_ioctl(struct file *filp, u
7601                                         goto setflags_out;
7602                                 }
7603                         }
7604 +
7605 +                       oldflags = REISERFS_I(inode)->i_attrs;
7606 +                       flags &= REISERFS_FL_USER_MODIFIABLE;
7607 +                       flags |= oldflags & ~REISERFS_FL_USER_MODIFIABLE;
7608                         sd_attrs_to_i_attrs(flags, inode);
7609                         REISERFS_I(inode)->i_attrs = flags;
7610                         inode->i_ctime = CURRENT_TIME_SEC;
7611 diff -NurpP --minimal linux-2.6.38-rc8/fs/reiserfs/namei.c linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/reiserfs/namei.c
7612 --- linux-2.6.38-rc8/fs/reiserfs/namei.c        2011-03-10 17:09:24.000000000 +0100
7613 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/reiserfs/namei.c 2011-03-10 17:21:19.000000000 +0100
7614 @@ -18,6 +18,7 @@
7615  #include <linux/reiserfs_acl.h>
7616  #include <linux/reiserfs_xattr.h>
7617  #include <linux/quotaops.h>
7618 +#include <linux/vs_tag.h>
7619  
7620  #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; }
7621  #define DEC_DIR_INODE_NLINK(i) if (i->i_nlink != 1) drop_nlink(i);
7622 @@ -362,6 +363,7 @@ static struct dentry *reiserfs_lookup(st
7623         if (retval == IO_ERROR) {
7624                 return ERR_PTR(-EIO);
7625         }
7626 +               dx_propagate_tag(nd, inode);
7627  
7628         return d_splice_alias(inode, dentry);
7629  }
7630 @@ -1532,6 +1534,7 @@ const struct inode_operations reiserfs_d
7631         .listxattr = reiserfs_listxattr,
7632         .removexattr = reiserfs_removexattr,
7633         .permission = reiserfs_permission,
7634 +       .sync_flags = reiserfs_sync_flags,
7635  };
7636  
7637  /*
7638 diff -NurpP --minimal linux-2.6.38-rc8/fs/reiserfs/super.c linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/reiserfs/super.c
7639 --- linux-2.6.38-rc8/fs/reiserfs/super.c        2011-03-10 17:09:24.000000000 +0100
7640 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/reiserfs/super.c 2011-01-29 02:01:07.000000000 +0100
7641 @@ -899,6 +899,14 @@ static int reiserfs_parse_options(struct
7642                 {"user_xattr",.setmask = 1 << REISERFS_UNSUPPORTED_OPT},
7643                 {"nouser_xattr",.clrmask = 1 << REISERFS_UNSUPPORTED_OPT},
7644  #endif
7645 +#ifndef CONFIG_TAGGING_NONE
7646 +               {"tagxid",.setmask = 1 << REISERFS_TAGGED},
7647 +               {"tag",.setmask = 1 << REISERFS_TAGGED},
7648 +               {"notag",.clrmask = 1 << REISERFS_TAGGED},
7649 +#endif
7650 +#ifdef CONFIG_PROPAGATE
7651 +               {"tag",.arg_required = 'T',.values = NULL},
7652 +#endif
7653  #ifdef CONFIG_REISERFS_FS_POSIX_ACL
7654                 {"acl",.setmask = 1 << REISERFS_POSIXACL},
7655                 {"noacl",.clrmask = 1 << REISERFS_POSIXACL},
7656 @@ -1208,6 +1216,14 @@ static int reiserfs_remount(struct super
7657         handle_quota_files(s, qf_names, &qfmt);
7658  #endif
7659  
7660 +       if ((mount_options & (1 << REISERFS_TAGGED)) &&
7661 +               !(s->s_flags & MS_TAGGED)) {
7662 +               reiserfs_warning(s, "super-vs01",
7663 +                       "reiserfs: tagging not permitted on remount.");
7664 +               err = -EINVAL;
7665 +               goto out_err;
7666 +       }
7667 +
7668         handle_attrs(s);
7669  
7670         /* Add options that are safe here */
7671 @@ -1690,6 +1706,10 @@ static int reiserfs_fill_super(struct su
7672                 goto error;
7673         }
7674  
7675 +       /* map mount option tagxid */
7676 +       if (REISERFS_SB(s)->s_mount_opt & (1 << REISERFS_TAGGED))
7677 +               s->s_flags |= MS_TAGGED;
7678 +
7679         rs = SB_DISK_SUPER_BLOCK(s);
7680         /* Let's do basic sanity check to verify that underlying device is not
7681            smaller than the filesystem. If the check fails then abort and scream,
7682 diff -NurpP --minimal linux-2.6.38-rc8/fs/reiserfs/xattr.c linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/reiserfs/xattr.c
7683 --- linux-2.6.38-rc8/fs/reiserfs/xattr.c        2011-03-10 17:09:24.000000000 +0100
7684 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/reiserfs/xattr.c 2011-01-29 02:01:07.000000000 +0100
7685 @@ -40,6 +40,7 @@
7686  #include <linux/errno.h>
7687  #include <linux/gfp.h>
7688  #include <linux/fs.h>
7689 +#include <linux/mount.h>
7690  #include <linux/file.h>
7691  #include <linux/pagemap.h>
7692  #include <linux/xattr.h>
7693 diff -NurpP --minimal linux-2.6.38-rc8/fs/stat.c linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/stat.c
7694 --- linux-2.6.38-rc8/fs/stat.c  2011-03-10 17:09:24.000000000 +0100
7695 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/stat.c   2011-01-29 02:01:07.000000000 +0100
7696 @@ -26,6 +26,7 @@ void generic_fillattr(struct inode *inod
7697         stat->nlink = inode->i_nlink;
7698         stat->uid = inode->i_uid;
7699         stat->gid = inode->i_gid;
7700 +       stat->tag = inode->i_tag;
7701         stat->rdev = inode->i_rdev;
7702         stat->atime = inode->i_atime;
7703         stat->mtime = inode->i_mtime;
7704 diff -NurpP --minimal linux-2.6.38-rc8/fs/statfs.c linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/statfs.c
7705 --- linux-2.6.38-rc8/fs/statfs.c        2010-10-21 13:07:51.000000000 +0200
7706 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/statfs.c 2011-01-29 02:01:07.000000000 +0100
7707 @@ -7,6 +7,8 @@
7708  #include <linux/statfs.h>
7709  #include <linux/security.h>
7710  #include <linux/uaccess.h>
7711 +#include <linux/vs_base.h>
7712 +#include <linux/vs_dlimit.h>
7713  
7714  static int flags_by_mnt(int mnt_flags)
7715  {
7716 @@ -59,6 +61,8 @@ int statfs_by_dentry(struct dentry *dent
7717         retval = dentry->d_sb->s_op->statfs(dentry, buf);
7718         if (retval == 0 && buf->f_frsize == 0)
7719                 buf->f_frsize = buf->f_bsize;
7720 +       if (!vx_check(0, VS_ADMIN|VS_WATCH))
7721 +               vx_vsi_statfs(dentry->d_sb, buf);
7722         return retval;
7723  }
7724  
7725 diff -NurpP --minimal linux-2.6.38-rc8/fs/super.c linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/super.c
7726 --- linux-2.6.38-rc8/fs/super.c 2011-03-10 17:09:24.000000000 +0100
7727 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/super.c  2011-02-17 02:17:50.000000000 +0100
7728 @@ -31,6 +31,9 @@
7729  #include <linux/mutex.h>
7730  #include <linux/backing-dev.h>
7731  #include <linux/rculist_bl.h>
7732 +#include <linux/devpts_fs.h>
7733 +#include <linux/proc_fs.h>
7734 +#include <linux/vs_context.h>
7735  #include "internal.h"
7736  
7737  
7738 @@ -963,6 +966,7 @@ struct vfsmount *
7739  vfs_kern_mount(struct file_system_type *type, int flags, const char *name, void *data)
7740  {
7741         struct vfsmount *mnt;
7742 +       struct super_block *sb;
7743         struct dentry *root;
7744         char *secdata = NULL;
7745         int error;
7746 @@ -970,6 +974,11 @@ vfs_kern_mount(struct file_system_type *
7747         if (!type)
7748                 return ERR_PTR(-ENODEV);
7749  
7750 +       error = -EPERM;
7751 +       if ((type->fs_flags & FS_BINARY_MOUNTDATA) &&
7752 +               !vx_capable(CAP_SYS_ADMIN, VXC_BINARY_MOUNT))
7753 +               goto out;
7754 +
7755         error = -ENOMEM;
7756         mnt = alloc_vfsmnt(name);
7757         if (!mnt)
7758 @@ -1001,11 +1010,19 @@ vfs_kern_mount(struct file_system_type *
7759                 if (error < 0)
7760                         goto out_free_secdata;
7761         }
7762 -       BUG_ON(!mnt->mnt_sb);
7763 -       WARN_ON(!mnt->mnt_sb->s_bdi);
7764 +
7765 +       sb = mnt->mnt_sb;
7766 +       BUG_ON(!sb);
7767 +       WARN_ON(!sb->s_bdi);
7768         mnt->mnt_sb->s_flags |= MS_BORN;
7769  
7770 -       error = security_sb_kern_mount(mnt->mnt_sb, flags, secdata);
7771 +       error = -EPERM;
7772 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_BINARY_MOUNT) && !sb->s_bdev &&
7773 +               (sb->s_magic != PROC_SUPER_MAGIC) &&
7774 +               (sb->s_magic != DEVPTS_SUPER_MAGIC))
7775 +               goto out_sb;
7776 +
7777 +       error = security_sb_kern_mount(sb, flags, secdata);
7778         if (error)
7779                 goto out_sb;
7780  
7781 diff -NurpP --minimal linux-2.6.38-rc8/fs/sysfs/mount.c linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/sysfs/mount.c
7782 --- linux-2.6.38-rc8/fs/sysfs/mount.c   2011-01-05 21:50:27.000000000 +0100
7783 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/sysfs/mount.c    2011-01-29 02:01:07.000000000 +0100
7784 @@ -47,7 +47,7 @@ static int sysfs_fill_super(struct super
7785  
7786         sb->s_blocksize = PAGE_CACHE_SIZE;
7787         sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
7788 -       sb->s_magic = SYSFS_MAGIC;
7789 +       sb->s_magic = SYSFS_SUPER_MAGIC;
7790         sb->s_op = &sysfs_ops;
7791         sb->s_time_gran = 1;
7792  
7793 diff -NurpP --minimal linux-2.6.38-rc8/fs/utimes.c linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/utimes.c
7794 --- linux-2.6.38-rc8/fs/utimes.c        2010-10-21 13:07:51.000000000 +0200
7795 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/utimes.c 2011-01-29 02:01:07.000000000 +0100
7796 @@ -8,6 +8,8 @@
7797  #include <linux/stat.h>
7798  #include <linux/utime.h>
7799  #include <linux/syscalls.h>
7800 +#include <linux/mount.h>
7801 +#include <linux/vs_cowbl.h>
7802  #include <asm/uaccess.h>
7803  #include <asm/unistd.h>
7804  
7805 @@ -52,12 +54,18 @@ static int utimes_common(struct path *pa
7806  {
7807         int error;
7808         struct iattr newattrs;
7809 -       struct inode *inode = path->dentry->d_inode;
7810 +       struct inode *inode;
7811  
7812         error = mnt_want_write(path->mnt);
7813         if (error)
7814                 goto out;
7815  
7816 +       error = cow_check_and_break(path);
7817 +       if (error)
7818 +               goto mnt_drop_write_and_out;
7819 +
7820 +       inode = path->dentry->d_inode;
7821 +
7822         if (times && times[0].tv_nsec == UTIME_NOW &&
7823                      times[1].tv_nsec == UTIME_NOW)
7824                 times = NULL;
7825 diff -NurpP --minimal linux-2.6.38-rc8/fs/xattr.c linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/xattr.c
7826 --- linux-2.6.38-rc8/fs/xattr.c 2010-08-02 16:52:52.000000000 +0200
7827 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/xattr.c  2011-01-29 02:01:07.000000000 +0100
7828 @@ -18,6 +18,7 @@
7829  #include <linux/module.h>
7830  #include <linux/fsnotify.h>
7831  #include <linux/audit.h>
7832 +#include <linux/mount.h>
7833  #include <asm/uaccess.h>
7834  
7835  
7836 @@ -49,7 +50,7 @@ xattr_permission(struct inode *inode, co
7837          * The trusted.* namespace can only be accessed by a privileged user.
7838          */
7839         if (!strncmp(name, XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN))
7840 -               return (capable(CAP_SYS_ADMIN) ? 0 : -EPERM);
7841 +               return (vx_capable(CAP_SYS_ADMIN, VXC_FS_TRUSTED) ? 0 : -EPERM);
7842  
7843         /* In user.* namespace, only regular files and directories can have
7844          * extended attributes. For sticky directories, only the owner and
7845 diff -NurpP --minimal linux-2.6.38-rc8/fs/xfs/linux-2.6/xfs_ioctl.c linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/xfs/linux-2.6/xfs_ioctl.c
7846 --- linux-2.6.38-rc8/fs/xfs/linux-2.6/xfs_ioctl.c       2011-03-10 17:09:24.000000000 +0100
7847 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/xfs/linux-2.6/xfs_ioctl.c        2011-03-10 17:21:19.000000000 +0100
7848 @@ -28,7 +28,7 @@
7849  #include "xfs_bmap_btree.h"
7850  #include "xfs_dinode.h"
7851  #include "xfs_inode.h"
7852 -#include "xfs_ioctl.h"
7853 +// #include "xfs_ioctl.h"
7854  #include "xfs_rtalloc.h"
7855  #include "xfs_itable.h"
7856  #include "xfs_error.h"
7857 @@ -744,6 +744,10 @@ xfs_merge_ioc_xflags(
7858                 xflags |= XFS_XFLAG_IMMUTABLE;
7859         else
7860                 xflags &= ~XFS_XFLAG_IMMUTABLE;
7861 +       if (flags & FS_IXUNLINK_FL)
7862 +               xflags |= XFS_XFLAG_IXUNLINK;
7863 +       else
7864 +               xflags &= ~XFS_XFLAG_IXUNLINK;
7865         if (flags & FS_APPEND_FL)
7866                 xflags |= XFS_XFLAG_APPEND;
7867         else
7868 @@ -772,6 +776,8 @@ xfs_di2lxflags(
7869  
7870         if (di_flags & XFS_DIFLAG_IMMUTABLE)
7871                 flags |= FS_IMMUTABLE_FL;
7872 +       if (di_flags & XFS_DIFLAG_IXUNLINK)
7873 +               flags |= FS_IXUNLINK_FL;
7874         if (di_flags & XFS_DIFLAG_APPEND)
7875                 flags |= FS_APPEND_FL;
7876         if (di_flags & XFS_DIFLAG_SYNC)
7877 @@ -832,6 +838,8 @@ xfs_set_diflags(
7878         di_flags = (ip->i_d.di_flags & XFS_DIFLAG_PREALLOC);
7879         if (xflags & XFS_XFLAG_IMMUTABLE)
7880                 di_flags |= XFS_DIFLAG_IMMUTABLE;
7881 +       if (xflags & XFS_XFLAG_IXUNLINK)
7882 +               di_flags |= XFS_DIFLAG_IXUNLINK;
7883         if (xflags & XFS_XFLAG_APPEND)
7884                 di_flags |= XFS_DIFLAG_APPEND;
7885         if (xflags & XFS_XFLAG_SYNC)
7886 @@ -874,6 +882,10 @@ xfs_diflags_to_linux(
7887                 inode->i_flags |= S_IMMUTABLE;
7888         else
7889                 inode->i_flags &= ~S_IMMUTABLE;
7890 +       if (xflags & XFS_XFLAG_IXUNLINK)
7891 +               inode->i_flags |= S_IXUNLINK;
7892 +       else
7893 +               inode->i_flags &= ~S_IXUNLINK;
7894         if (xflags & XFS_XFLAG_APPEND)
7895                 inode->i_flags |= S_APPEND;
7896         else
7897 @@ -1366,10 +1378,18 @@ xfs_file_ioctl(
7898         case XFS_IOC_FSGETXATTRA:
7899                 return xfs_ioc_fsgetxattr(ip, 1, arg);
7900         case XFS_IOC_FSSETXATTR:
7901 +               if (IS_BARRIER(inode)) {
7902 +                       vxwprintk_task(1, "messing with the barrier.");
7903 +                       return -XFS_ERROR(EACCES);
7904 +               }
7905                 return xfs_ioc_fssetxattr(ip, filp, arg);
7906         case XFS_IOC_GETXFLAGS:
7907                 return xfs_ioc_getxflags(ip, arg);
7908         case XFS_IOC_SETXFLAGS:
7909 +               if (IS_BARRIER(inode)) {
7910 +                       vxwprintk_task(1, "messing with the barrier.");
7911 +                       return -XFS_ERROR(EACCES);
7912 +               }
7913                 return xfs_ioc_setxflags(ip, filp, arg);
7914  
7915         case XFS_IOC_FSSETDM: {
7916 diff -NurpP --minimal linux-2.6.38-rc8/fs/xfs/linux-2.6/xfs_ioctl.h linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/xfs/linux-2.6/xfs_ioctl.h
7917 --- linux-2.6.38-rc8/fs/xfs/linux-2.6/xfs_ioctl.h       2010-07-07 18:31:54.000000000 +0200
7918 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/xfs/linux-2.6/xfs_ioctl.h        2011-01-29 02:01:07.000000000 +0100
7919 @@ -70,6 +70,12 @@ xfs_handle_to_dentry(
7920         void __user             *uhandle,
7921         u32                     hlen);
7922  
7923 +extern int
7924 +xfs_sync_flags(
7925 +       struct inode            *inode,
7926 +       int                     flags,
7927 +       int                     vflags);
7928 +
7929  extern long
7930  xfs_file_ioctl(
7931         struct file             *filp,
7932 diff -NurpP --minimal linux-2.6.38-rc8/fs/xfs/linux-2.6/xfs_iops.c linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/xfs/linux-2.6/xfs_iops.c
7933 --- linux-2.6.38-rc8/fs/xfs/linux-2.6/xfs_iops.c        2011-03-10 17:09:24.000000000 +0100
7934 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/xfs/linux-2.6/xfs_iops.c 2011-01-29 02:01:07.000000000 +0100
7935 @@ -30,6 +30,7 @@
7936  #include "xfs_bmap_btree.h"
7937  #include "xfs_dinode.h"
7938  #include "xfs_inode.h"
7939 +#include "xfs_ioctl.h"
7940  #include "xfs_bmap.h"
7941  #include "xfs_rtalloc.h"
7942  #include "xfs_error.h"
7943 @@ -48,6 +49,7 @@
7944  #include <linux/security.h>
7945  #include <linux/fiemap.h>
7946  #include <linux/slab.h>
7947 +#include <linux/vs_tag.h>
7948  
7949  /*
7950   * Bring the timestamps in the XFS inode uptodate.
7951 @@ -463,6 +465,7 @@ xfs_vn_getattr(
7952         stat->nlink = ip->i_d.di_nlink;
7953         stat->uid = ip->i_d.di_uid;
7954         stat->gid = ip->i_d.di_gid;
7955 +       stat->tag = ip->i_d.di_tag;
7956         stat->ino = ip->i_ino;
7957         stat->atime = inode->i_atime;
7958         stat->mtime = inode->i_mtime;
7959 @@ -598,6 +601,7 @@ static const struct inode_operations xfs
7960         .removexattr            = generic_removexattr,
7961         .listxattr              = xfs_vn_listxattr,
7962         .fiemap                 = xfs_vn_fiemap,
7963 +       .sync_flags             = xfs_sync_flags,
7964  };
7965  
7966  static const struct inode_operations xfs_dir_inode_operations = {
7967 @@ -623,6 +627,7 @@ static const struct inode_operations xfs
7968         .getxattr               = generic_getxattr,
7969         .removexattr            = generic_removexattr,
7970         .listxattr              = xfs_vn_listxattr,
7971 +       .sync_flags             = xfs_sync_flags,
7972  };
7973  
7974  static const struct inode_operations xfs_dir_ci_inode_operations = {
7975 @@ -672,6 +677,10 @@ xfs_diflags_to_iflags(
7976                 inode->i_flags |= S_IMMUTABLE;
7977         else
7978                 inode->i_flags &= ~S_IMMUTABLE;
7979 +       if (ip->i_d.di_flags & XFS_DIFLAG_IXUNLINK)
7980 +               inode->i_flags |= S_IXUNLINK;
7981 +       else
7982 +               inode->i_flags &= ~S_IXUNLINK;
7983         if (ip->i_d.di_flags & XFS_DIFLAG_APPEND)
7984                 inode->i_flags |= S_APPEND;
7985         else
7986 @@ -684,6 +693,15 @@ xfs_diflags_to_iflags(
7987                 inode->i_flags |= S_NOATIME;
7988         else
7989                 inode->i_flags &= ~S_NOATIME;
7990 +
7991 +       if (ip->i_d.di_vflags & XFS_DIVFLAG_BARRIER)
7992 +               inode->i_vflags |= V_BARRIER;
7993 +       else
7994 +               inode->i_vflags &= ~V_BARRIER;
7995 +       if (ip->i_d.di_vflags & XFS_DIVFLAG_COW)
7996 +               inode->i_vflags |= V_COW;
7997 +       else
7998 +               inode->i_vflags &= ~V_COW;
7999  }
8000  
8001  /*
8002 @@ -715,6 +733,7 @@ xfs_setup_inode(
8003         inode->i_nlink  = ip->i_d.di_nlink;
8004         inode->i_uid    = ip->i_d.di_uid;
8005         inode->i_gid    = ip->i_d.di_gid;
8006 +       inode->i_tag    = ip->i_d.di_tag;
8007  
8008         switch (inode->i_mode & S_IFMT) {
8009         case S_IFBLK:
8010 diff -NurpP --minimal linux-2.6.38-rc8/fs/xfs/linux-2.6/xfs_linux.h linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/xfs/linux-2.6/xfs_linux.h
8011 --- linux-2.6.38-rc8/fs/xfs/linux-2.6/xfs_linux.h       2011-03-10 17:09:24.000000000 +0100
8012 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/xfs/linux-2.6/xfs_linux.h        2011-01-29 02:01:07.000000000 +0100
8013 @@ -114,6 +114,7 @@
8014  
8015  #define current_cpu()          (raw_smp_processor_id())
8016  #define current_pid()          (current->pid)
8017 +#define current_fstag(vp)      (dx_current_fstag((vp)->i_sb))
8018  #define current_test_flags(f)  (current->flags & (f))
8019  #define current_set_flags_nested(sp, f)                \
8020                 (*(sp) = current->flags, current->flags |= (f))
8021 diff -NurpP --minimal linux-2.6.38-rc8/fs/xfs/linux-2.6/xfs_super.c linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/xfs/linux-2.6/xfs_super.c
8022 --- linux-2.6.38-rc8/fs/xfs/linux-2.6/xfs_super.c       2011-03-10 17:09:24.000000000 +0100
8023 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/xfs/linux-2.6/xfs_super.c        2011-01-29 02:01:07.000000000 +0100
8024 @@ -112,6 +112,9 @@ mempool_t *xfs_ioend_pool;
8025  #define MNTOPT_QUOTANOENF  "qnoenforce"        /* same as uqnoenforce */
8026  #define MNTOPT_DELAYLOG   "delaylog"   /* Delayed loging enabled */
8027  #define MNTOPT_NODELAYLOG "nodelaylog" /* Delayed loging disabled */
8028 +#define MNTOPT_TAGXID  "tagxid"        /* context tagging for inodes */
8029 +#define MNTOPT_TAGGED  "tag"           /* context tagging for inodes */
8030 +#define MNTOPT_NOTAGTAG        "notag"         /* do not use context tagging */
8031  
8032  /*
8033   * Table driven mount option parser.
8034 @@ -120,10 +123,14 @@ mempool_t *xfs_ioend_pool;
8035   * in the future, too.
8036   */
8037  enum {
8038 +       Opt_tag, Opt_notag,
8039         Opt_barrier, Opt_nobarrier, Opt_err
8040  };
8041  
8042  static const match_table_t tokens = {
8043 +       {Opt_tag, "tagxid"},
8044 +       {Opt_tag, "tag"},
8045 +       {Opt_notag, "notag"},
8046         {Opt_barrier, "barrier"},
8047         {Opt_nobarrier, "nobarrier"},
8048         {Opt_err, NULL}
8049 @@ -367,6 +374,19 @@ xfs_parseargs(
8050                 } else if (!strcmp(this_char, "irixsgid")) {
8051                         cmn_err(CE_WARN,
8052         "XFS: irixsgid is now a sysctl(2) variable, option is deprecated.");
8053 +#ifndef CONFIG_TAGGING_NONE
8054 +               } else if (!strcmp(this_char, MNTOPT_TAGGED)) {
8055 +                       mp->m_flags |= XFS_MOUNT_TAGGED;
8056 +               } else if (!strcmp(this_char, MNTOPT_NOTAGTAG)) {
8057 +                       mp->m_flags &= ~XFS_MOUNT_TAGGED;
8058 +               } else if (!strcmp(this_char, MNTOPT_TAGXID)) {
8059 +                       mp->m_flags |= XFS_MOUNT_TAGGED;
8060 +#endif
8061 +#ifdef CONFIG_PROPAGATE
8062 +               } else if (!strcmp(this_char, MNTOPT_TAGGED)) {
8063 +                       /* use value */
8064 +                       mp->m_flags |= XFS_MOUNT_TAGGED;
8065 +#endif
8066                 } else {
8067                         cmn_err(CE_WARN,
8068                                 "XFS: unknown mount option [%s].", this_char);
8069 @@ -1327,6 +1347,16 @@ xfs_fs_remount(
8070                 case Opt_nobarrier:
8071                         mp->m_flags &= ~XFS_MOUNT_BARRIER;
8072                         break;
8073 +               case Opt_tag:
8074 +                       if (!(sb->s_flags & MS_TAGGED)) {
8075 +                               printk(KERN_INFO
8076 +                                       "XFS: %s: tagging not permitted on remount.\n",
8077 +                                       sb->s_id);
8078 +                               return -EINVAL;
8079 +                       }
8080 +                       break;
8081 +               case Opt_notag:
8082 +                       break;
8083                 default:
8084                         /*
8085                          * Logically we would return an error here to prevent
8086 @@ -1555,6 +1585,9 @@ xfs_fs_fill_super(
8087         if (error)
8088                 goto out_filestream_unmount;
8089  
8090 +       if (mp->m_flags & XFS_MOUNT_TAGGED)
8091 +               sb->s_flags |= MS_TAGGED;
8092 +
8093         sb->s_magic = XFS_SB_MAGIC;
8094         sb->s_blocksize = mp->m_sb.sb_blocksize;
8095         sb->s_blocksize_bits = ffs(sb->s_blocksize) - 1;
8096 diff -NurpP --minimal linux-2.6.38-rc8/fs/xfs/xfs_dinode.h linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/xfs/xfs_dinode.h
8097 --- linux-2.6.38-rc8/fs/xfs/xfs_dinode.h        2011-01-05 21:50:28.000000000 +0100
8098 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/xfs/xfs_dinode.h 2011-01-29 02:01:07.000000000 +0100
8099 @@ -51,7 +51,9 @@ typedef struct xfs_dinode {
8100         __be32          di_nlink;       /* number of links to file */
8101         __be16          di_projid_lo;   /* lower part of owner's project id */
8102         __be16          di_projid_hi;   /* higher part owner's project id */
8103 -       __u8            di_pad[6];      /* unused, zeroed space */
8104 +       __u8            di_pad[2];      /* unused, zeroed space */
8105 +       __be16          di_tag;         /* context tagging */
8106 +       __be16          di_vflags;      /* vserver specific flags */
8107         __be16          di_flushiter;   /* incremented on flush */
8108         xfs_timestamp_t di_atime;       /* time last accessed */
8109         xfs_timestamp_t di_mtime;       /* time last modified */
8110 @@ -184,6 +186,8 @@ static inline void xfs_dinode_put_rdev(s
8111  #define XFS_DIFLAG_EXTSZINHERIT_BIT 12 /* inherit inode extent size */
8112  #define XFS_DIFLAG_NODEFRAG_BIT     13 /* do not reorganize/defragment */
8113  #define XFS_DIFLAG_FILESTREAM_BIT   14  /* use filestream allocator */
8114 +#define XFS_DIFLAG_IXUNLINK_BIT     15 /* Immutable inver on unlink */
8115 +
8116  #define XFS_DIFLAG_REALTIME      (1 << XFS_DIFLAG_REALTIME_BIT)
8117  #define XFS_DIFLAG_PREALLOC      (1 << XFS_DIFLAG_PREALLOC_BIT)
8118  #define XFS_DIFLAG_NEWRTBM       (1 << XFS_DIFLAG_NEWRTBM_BIT)
8119 @@ -199,6 +203,7 @@ static inline void xfs_dinode_put_rdev(s
8120  #define XFS_DIFLAG_EXTSZINHERIT  (1 << XFS_DIFLAG_EXTSZINHERIT_BIT)
8121  #define XFS_DIFLAG_NODEFRAG      (1 << XFS_DIFLAG_NODEFRAG_BIT)
8122  #define XFS_DIFLAG_FILESTREAM    (1 << XFS_DIFLAG_FILESTREAM_BIT)
8123 +#define XFS_DIFLAG_IXUNLINK      (1 << XFS_DIFLAG_IXUNLINK_BIT)
8124  
8125  #ifdef CONFIG_XFS_RT
8126  #define XFS_IS_REALTIME_INODE(ip) ((ip)->i_d.di_flags & XFS_DIFLAG_REALTIME)
8127 @@ -211,6 +216,10 @@ static inline void xfs_dinode_put_rdev(s
8128          XFS_DIFLAG_IMMUTABLE | XFS_DIFLAG_APPEND | XFS_DIFLAG_SYNC | \
8129          XFS_DIFLAG_NOATIME | XFS_DIFLAG_NODUMP | XFS_DIFLAG_RTINHERIT | \
8130          XFS_DIFLAG_PROJINHERIT | XFS_DIFLAG_NOSYMLINKS | XFS_DIFLAG_EXTSIZE | \
8131 -        XFS_DIFLAG_EXTSZINHERIT | XFS_DIFLAG_NODEFRAG | XFS_DIFLAG_FILESTREAM)
8132 +        XFS_DIFLAG_EXTSZINHERIT | XFS_DIFLAG_NODEFRAG | XFS_DIFLAG_FILESTREAM | \
8133 +        XFS_DIFLAG_IXUNLINK)
8134 +
8135 +#define XFS_DIVFLAG_BARRIER    0x01
8136 +#define XFS_DIVFLAG_COW                0x02
8137  
8138  #endif /* __XFS_DINODE_H__ */
8139 diff -NurpP --minimal linux-2.6.38-rc8/fs/xfs/xfs_fs.h linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/xfs/xfs_fs.h
8140 --- linux-2.6.38-rc8/fs/xfs/xfs_fs.h    2011-01-05 21:50:28.000000000 +0100
8141 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/xfs/xfs_fs.h     2011-01-29 02:01:07.000000000 +0100
8142 @@ -67,6 +67,9 @@ struct fsxattr {
8143  #define XFS_XFLAG_EXTSZINHERIT 0x00001000      /* inherit inode extent size */
8144  #define XFS_XFLAG_NODEFRAG     0x00002000      /* do not defragment */
8145  #define XFS_XFLAG_FILESTREAM   0x00004000      /* use filestream allocator */
8146 +#define XFS_XFLAG_IXUNLINK     0x00008000      /* immutable invert on unlink */
8147 +#define XFS_XFLAG_BARRIER      0x10000000      /* chroot() barrier */
8148 +#define XFS_XFLAG_COW          0x20000000      /* copy on write mark */
8149  #define XFS_XFLAG_HASATTR      0x80000000      /* no DIFLAG for this   */
8150  
8151  /*
8152 @@ -297,7 +300,8 @@ typedef struct xfs_bstat {
8153  #define        bs_projid       bs_projid_lo    /* (previously just bs_projid)  */
8154         __u16           bs_forkoff;     /* inode fork offset in bytes   */
8155         __u16           bs_projid_hi;   /* higher part of project id    */
8156 -       unsigned char   bs_pad[10];     /* pad space, unused            */
8157 +       unsigned char   bs_pad[8];      /* pad space, unused            */
8158 +       __u16           bs_tag;         /* context tagging              */
8159         __u32           bs_dmevmask;    /* DMIG event mask              */
8160         __u16           bs_dmstate;     /* DMIG state info              */
8161         __u16           bs_aextents;    /* attribute number of extents  */
8162 diff -NurpP --minimal linux-2.6.38-rc8/fs/xfs/xfs_ialloc.c linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/xfs/xfs_ialloc.c
8163 --- linux-2.6.38-rc8/fs/xfs/xfs_ialloc.c        2011-01-05 21:50:28.000000000 +0100
8164 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/xfs/xfs_ialloc.c 2011-01-29 02:01:07.000000000 +0100
8165 @@ -37,7 +37,6 @@
8166  #include "xfs_error.h"
8167  #include "xfs_bmap.h"
8168  
8169 -
8170  /*
8171   * Allocation group level functions.
8172   */
8173 diff -NurpP --minimal linux-2.6.38-rc8/fs/xfs/xfs_inode.c linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/xfs/xfs_inode.c
8174 --- linux-2.6.38-rc8/fs/xfs/xfs_inode.c 2011-03-10 17:09:24.000000000 +0100
8175 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/xfs/xfs_inode.c  2011-01-29 02:01:07.000000000 +0100
8176 @@ -245,6 +245,7 @@ xfs_inotobp(
8177         return 0;
8178  }
8179  
8180 +#include <linux/vs_tag.h>
8181  
8182  /*
8183   * This routine is called to map an inode to the buffer containing
8184 @@ -650,15 +651,25 @@ xfs_iformat_btree(
8185  STATIC void
8186  xfs_dinode_from_disk(
8187         xfs_icdinode_t          *to,
8188 -       xfs_dinode_t            *from)
8189 +       xfs_dinode_t            *from,
8190 +       int tagged)
8191  {
8192 +       uint32_t uid, gid, tag;
8193 +
8194         to->di_magic = be16_to_cpu(from->di_magic);
8195         to->di_mode = be16_to_cpu(from->di_mode);
8196         to->di_version = from ->di_version;
8197         to->di_format = from->di_format;
8198         to->di_onlink = be16_to_cpu(from->di_onlink);
8199 -       to->di_uid = be32_to_cpu(from->di_uid);
8200 -       to->di_gid = be32_to_cpu(from->di_gid);
8201 +
8202 +       uid = be32_to_cpu(from->di_uid);
8203 +       gid = be32_to_cpu(from->di_gid);
8204 +       tag = be16_to_cpu(from->di_tag);
8205 +
8206 +       to->di_uid = INOTAG_UID(tagged, uid, gid);
8207 +       to->di_gid = INOTAG_GID(tagged, uid, gid);
8208 +       to->di_tag = INOTAG_TAG(tagged, uid, gid, tag);
8209 +
8210         to->di_nlink = be32_to_cpu(from->di_nlink);
8211         to->di_projid_lo = be16_to_cpu(from->di_projid_lo);
8212         to->di_projid_hi = be16_to_cpu(from->di_projid_hi);
8213 @@ -680,21 +691,26 @@ xfs_dinode_from_disk(
8214         to->di_dmevmask = be32_to_cpu(from->di_dmevmask);
8215         to->di_dmstate  = be16_to_cpu(from->di_dmstate);
8216         to->di_flags    = be16_to_cpu(from->di_flags);
8217 +       to->di_vflags   = be16_to_cpu(from->di_vflags);
8218         to->di_gen      = be32_to_cpu(from->di_gen);
8219  }
8220  
8221  void
8222  xfs_dinode_to_disk(
8223         xfs_dinode_t            *to,
8224 -       xfs_icdinode_t          *from)
8225 +       xfs_icdinode_t          *from,
8226 +       int tagged)
8227  {
8228         to->di_magic = cpu_to_be16(from->di_magic);
8229         to->di_mode = cpu_to_be16(from->di_mode);
8230         to->di_version = from ->di_version;
8231         to->di_format = from->di_format;
8232         to->di_onlink = cpu_to_be16(from->di_onlink);
8233 -       to->di_uid = cpu_to_be32(from->di_uid);
8234 -       to->di_gid = cpu_to_be32(from->di_gid);
8235 +
8236 +       to->di_uid = cpu_to_be32(TAGINO_UID(tagged, from->di_uid, from->di_tag));
8237 +       to->di_gid = cpu_to_be32(TAGINO_GID(tagged, from->di_gid, from->di_tag));
8238 +       to->di_tag = cpu_to_be16(TAGINO_TAG(tagged, from->di_tag));
8239 +
8240         to->di_nlink = cpu_to_be32(from->di_nlink);
8241         to->di_projid_lo = cpu_to_be16(from->di_projid_lo);
8242         to->di_projid_hi = cpu_to_be16(from->di_projid_hi);
8243 @@ -716,12 +732,14 @@ xfs_dinode_to_disk(
8244         to->di_dmevmask = cpu_to_be32(from->di_dmevmask);
8245         to->di_dmstate = cpu_to_be16(from->di_dmstate);
8246         to->di_flags = cpu_to_be16(from->di_flags);
8247 +       to->di_vflags = cpu_to_be16(from->di_vflags);
8248         to->di_gen = cpu_to_be32(from->di_gen);
8249  }
8250  
8251  STATIC uint
8252  _xfs_dic2xflags(
8253 -       __uint16_t              di_flags)
8254 +       __uint16_t              di_flags,
8255 +       __uint16_t              di_vflags)
8256  {
8257         uint                    flags = 0;
8258  
8259 @@ -732,6 +750,8 @@ _xfs_dic2xflags(
8260                         flags |= XFS_XFLAG_PREALLOC;
8261                 if (di_flags & XFS_DIFLAG_IMMUTABLE)
8262                         flags |= XFS_XFLAG_IMMUTABLE;
8263 +               if (di_flags & XFS_DIFLAG_IXUNLINK)
8264 +                       flags |= XFS_XFLAG_IXUNLINK;
8265                 if (di_flags & XFS_DIFLAG_APPEND)
8266                         flags |= XFS_XFLAG_APPEND;
8267                 if (di_flags & XFS_DIFLAG_SYNC)
8268 @@ -756,6 +776,10 @@ _xfs_dic2xflags(
8269                         flags |= XFS_XFLAG_FILESTREAM;
8270         }
8271  
8272 +       if (di_vflags & XFS_DIVFLAG_BARRIER)
8273 +               flags |= FS_BARRIER_FL;
8274 +       if (di_vflags & XFS_DIVFLAG_COW)
8275 +               flags |= FS_COW_FL;
8276         return flags;
8277  }
8278  
8279 @@ -765,7 +789,7 @@ xfs_ip2xflags(
8280  {
8281         xfs_icdinode_t          *dic = &ip->i_d;
8282  
8283 -       return _xfs_dic2xflags(dic->di_flags) |
8284 +       return _xfs_dic2xflags(dic->di_flags, dic->di_vflags) |
8285                                 (XFS_IFORK_Q(ip) ? XFS_XFLAG_HASATTR : 0);
8286  }
8287  
8288 @@ -773,7 +797,8 @@ uint
8289  xfs_dic2xflags(
8290         xfs_dinode_t            *dip)
8291  {
8292 -       return _xfs_dic2xflags(be16_to_cpu(dip->di_flags)) |
8293 +       return _xfs_dic2xflags(be16_to_cpu(dip->di_flags),
8294 +                               be16_to_cpu(dip->di_vflags)) |
8295                                 (XFS_DFORK_Q(dip) ? XFS_XFLAG_HASATTR : 0);
8296  }
8297  
8298 @@ -806,7 +831,6 @@ xfs_iread(
8299         if (error)
8300                 return error;
8301         dip = (xfs_dinode_t *)xfs_buf_offset(bp, ip->i_imap.im_boffset);
8302 -
8303         /*
8304          * If we got something that isn't an inode it means someone
8305          * (nfs or dmi) has a stale handle.
8306 @@ -831,7 +855,8 @@ xfs_iread(
8307          * Otherwise, just get the truly permanent information.
8308          */
8309         if (dip->di_mode) {
8310 -               xfs_dinode_from_disk(&ip->i_d, dip);
8311 +               xfs_dinode_from_disk(&ip->i_d, dip,
8312 +                       mp->m_flags & XFS_MOUNT_TAGGED);
8313                 error = xfs_iformat(ip, dip);
8314                 if (error)  {
8315  #ifdef DEBUG
8316 @@ -1028,6 +1053,7 @@ xfs_ialloc(
8317         ASSERT(ip->i_d.di_nlink == nlink);
8318         ip->i_d.di_uid = current_fsuid();
8319         ip->i_d.di_gid = current_fsgid();
8320 +       ip->i_d.di_tag = current_fstag(&ip->i_vnode);
8321         xfs_set_projid(ip, prid);
8322         memset(&(ip->i_d.di_pad[0]), 0, sizeof(ip->i_d.di_pad));
8323  
8324 @@ -1088,6 +1114,7 @@ xfs_ialloc(
8325         ip->i_d.di_dmevmask = 0;
8326         ip->i_d.di_dmstate = 0;
8327         ip->i_d.di_flags = 0;
8328 +       ip->i_d.di_vflags = 0;
8329         flags = XFS_ILOG_CORE;
8330         switch (mode & S_IFMT) {
8331         case S_IFIFO:
8332 @@ -2122,6 +2149,7 @@ xfs_ifree(
8333         }
8334         ip->i_d.di_mode = 0;            /* mark incore inode as free */
8335         ip->i_d.di_flags = 0;
8336 +       ip->i_d.di_vflags = 0;
8337         ip->i_d.di_dmevmask = 0;
8338         ip->i_d.di_forkoff = 0;         /* mark the attr fork not in use */
8339         ip->i_df.if_ext_max =
8340 @@ -3004,7 +3032,8 @@ xfs_iflush_int(
8341          * because if the inode is dirty at all the core must
8342          * be.
8343          */
8344 -       xfs_dinode_to_disk(dip, &ip->i_d);
8345 +       xfs_dinode_to_disk(dip, &ip->i_d,
8346 +               mp->m_flags & XFS_MOUNT_TAGGED);
8347  
8348         /* Wrap, we never let the log put out DI_MAX_FLUSH */
8349         if (ip->i_d.di_flushiter == DI_MAX_FLUSH)
8350 diff -NurpP --minimal linux-2.6.38-rc8/fs/xfs/xfs_inode.h linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/xfs/xfs_inode.h
8351 --- linux-2.6.38-rc8/fs/xfs/xfs_inode.h 2011-03-10 17:09:24.000000000 +0100
8352 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/xfs/xfs_inode.h  2011-01-29 02:01:07.000000000 +0100
8353 @@ -136,7 +136,9 @@ typedef struct xfs_icdinode {
8354         __uint32_t      di_nlink;       /* number of links to file */
8355         __uint16_t      di_projid_lo;   /* lower part of owner's project id */
8356         __uint16_t      di_projid_hi;   /* higher part of owner's project id */
8357 -       __uint8_t       di_pad[6];      /* unused, zeroed space */
8358 +       __uint8_t       di_pad[2];      /* unused, zeroed space */
8359 +       __uint16_t      di_tag;         /* context tagging */
8360 +       __uint16_t      di_vflags;      /* vserver specific flags */
8361         __uint16_t      di_flushiter;   /* incremented on flush */
8362         xfs_ictimestamp_t di_atime;     /* time last accessed */
8363         xfs_ictimestamp_t di_mtime;     /* time last modified */
8364 @@ -530,7 +532,7 @@ int         xfs_itobp(struct xfs_mount *, struc
8365  int            xfs_iread(struct xfs_mount *, struct xfs_trans *,
8366                           struct xfs_inode *, uint);
8367  void           xfs_dinode_to_disk(struct xfs_dinode *,
8368 -                                  struct xfs_icdinode *);
8369 +                                  struct xfs_icdinode *, int);
8370  void           xfs_idestroy_fork(struct xfs_inode *, int);
8371  void           xfs_idata_realloc(struct xfs_inode *, int, int);
8372  void           xfs_iroot_realloc(struct xfs_inode *, int, int);
8373 diff -NurpP --minimal linux-2.6.38-rc8/fs/xfs/xfs_itable.c linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/xfs/xfs_itable.c
8374 --- linux-2.6.38-rc8/fs/xfs/xfs_itable.c        2011-01-05 21:50:28.000000000 +0100
8375 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/xfs/xfs_itable.c 2011-01-29 02:01:07.000000000 +0100
8376 @@ -98,6 +98,7 @@ xfs_bulkstat_one_int(
8377         buf->bs_mode = dic->di_mode;
8378         buf->bs_uid = dic->di_uid;
8379         buf->bs_gid = dic->di_gid;
8380 +       buf->bs_tag = dic->di_tag;
8381         buf->bs_size = dic->di_size;
8382  
8383         /*
8384 diff -NurpP --minimal linux-2.6.38-rc8/fs/xfs/xfs_log_recover.c linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/xfs/xfs_log_recover.c
8385 --- linux-2.6.38-rc8/fs/xfs/xfs_log_recover.c   2011-03-10 17:09:24.000000000 +0100
8386 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/xfs/xfs_log_recover.c    2011-01-29 02:01:07.000000000 +0100
8387 @@ -2317,7 +2317,8 @@ xlog_recover_inode_pass2(
8388         }
8389  
8390         /* The core is in in-core format */
8391 -       xfs_dinode_to_disk(dip, item->ri_buf[1].i_addr);
8392 +       xfs_dinode_to_disk(dip, item->ri_buf[1].i_addr,
8393 +               mp->m_flags & XFS_MOUNT_TAGGED);
8394  
8395         /* the rest is in on-disk format */
8396         if (item->ri_buf[1].i_len > sizeof(struct xfs_icdinode)) {
8397 diff -NurpP --minimal linux-2.6.38-rc8/fs/xfs/xfs_mount.h linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/xfs/xfs_mount.h
8398 --- linux-2.6.38-rc8/fs/xfs/xfs_mount.h 2011-03-10 17:09:24.000000000 +0100
8399 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/xfs/xfs_mount.h  2011-01-29 02:01:07.000000000 +0100
8400 @@ -251,6 +251,7 @@ typedef struct xfs_mount {
8401                                                    allocator */
8402  #define XFS_MOUNT_NOATTR2      (1ULL << 25)    /* disable use of attr2 format */
8403  
8404 +#define XFS_MOUNT_TAGGED       (1ULL << 31)    /* context tagging */
8405  
8406  /*
8407   * Default minimum read and write sizes.
8408 diff -NurpP --minimal linux-2.6.38-rc8/fs/xfs/xfs_vnodeops.c linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/xfs/xfs_vnodeops.c
8409 --- linux-2.6.38-rc8/fs/xfs/xfs_vnodeops.c      2011-03-10 17:09:24.000000000 +0100
8410 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/xfs/xfs_vnodeops.c       2011-01-29 02:01:07.000000000 +0100
8411 @@ -50,6 +50,78 @@
8412  #include "xfs_vnodeops.h"
8413  #include "xfs_trace.h"
8414  
8415 +
8416 +STATIC void
8417 +xfs_get_inode_flags(
8418 +       xfs_inode_t     *ip)
8419 +{
8420 +       struct inode    *inode = VFS_I(ip);
8421 +       unsigned int    flags = inode->i_flags;
8422 +       unsigned int    vflags = inode->i_vflags;
8423 +
8424 +       if (flags & S_IMMUTABLE)
8425 +               ip->i_d.di_flags |= XFS_DIFLAG_IMMUTABLE;
8426 +       else
8427 +               ip->i_d.di_flags &= ~XFS_DIFLAG_IMMUTABLE;
8428 +       if (flags & S_IXUNLINK)
8429 +               ip->i_d.di_flags |= XFS_DIFLAG_IXUNLINK;
8430 +       else
8431 +               ip->i_d.di_flags &= ~XFS_DIFLAG_IXUNLINK;
8432 +
8433 +       if (vflags & V_BARRIER)
8434 +               ip->i_d.di_vflags |= XFS_DIVFLAG_BARRIER;
8435 +       else
8436 +               ip->i_d.di_vflags &= ~XFS_DIVFLAG_BARRIER;
8437 +       if (vflags & V_COW)
8438 +               ip->i_d.di_vflags |= XFS_DIVFLAG_COW;
8439 +       else
8440 +               ip->i_d.di_vflags &= ~XFS_DIVFLAG_COW;
8441 +}
8442 +
8443 +int
8444 +xfs_sync_flags(
8445 +       struct inode            *inode,
8446 +       int                     flags,
8447 +       int                     vflags)
8448 +{
8449 +       struct xfs_inode        *ip = XFS_I(inode);
8450 +       struct xfs_mount        *mp = ip->i_mount;
8451 +       struct xfs_trans        *tp;
8452 +       unsigned int            lock_flags = 0;
8453 +       int                     code;
8454 +
8455 +       tp = xfs_trans_alloc(mp, XFS_TRANS_SETATTR_NOT_SIZE);
8456 +       code = xfs_trans_reserve(tp, 0, XFS_ICHANGE_LOG_RES(mp), 0, 0, 0);
8457 +       if (code)
8458 +               goto error_out;
8459 +
8460 +       xfs_ilock(ip, XFS_ILOCK_EXCL);
8461 +
8462 +       xfs_trans_ijoin(tp, ip);
8463 +
8464 +       inode->i_flags = flags;
8465 +       inode->i_vflags = vflags;
8466 +       xfs_get_inode_flags(ip);
8467 +
8468 +       xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE);
8469 +       xfs_trans_ichgtime(tp, ip, XFS_ICHGTIME_CHG);
8470 +
8471 +       XFS_STATS_INC(xs_ig_attrchg);
8472 +
8473 +       if (mp->m_flags & XFS_MOUNT_WSYNC)
8474 +               xfs_trans_set_sync(tp);
8475 +       code = xfs_trans_commit(tp, 0);
8476 +       xfs_iunlock(ip, XFS_ILOCK_EXCL);
8477 +       return code;
8478 +
8479 +error_out:
8480 +       xfs_trans_cancel(tp, 0);
8481 +       if (lock_flags)
8482 +               xfs_iunlock(ip, XFS_ILOCK_EXCL);
8483 +       return code;
8484 +}
8485 +
8486 +
8487  int
8488  xfs_setattr(
8489         struct xfs_inode        *ip,
8490 @@ -65,6 +137,7 @@ xfs_setattr(
8491         uint                    commit_flags=0;
8492         uid_t                   uid=0, iuid=0;
8493         gid_t                   gid=0, igid=0;
8494 +       tag_t                   tag=0, itag=0;
8495         struct xfs_dquot        *udqp, *gdqp, *olddquot1, *olddquot2;
8496         int                     need_iolock = 1;
8497  
8498 @@ -147,7 +220,7 @@ xfs_setattr(
8499         /*
8500          * Change file ownership.  Must be the owner or privileged.
8501          */
8502 -       if (mask & (ATTR_UID|ATTR_GID)) {
8503 +       if (mask & (ATTR_UID|ATTR_GID|ATTR_TAG)) {
8504                 /*
8505                  * These IDs could have changed since we last looked at them.
8506                  * But, we're assured that if the ownership did change
8507 @@ -156,8 +229,10 @@ xfs_setattr(
8508                  */
8509                 iuid = ip->i_d.di_uid;
8510                 igid = ip->i_d.di_gid;
8511 +               itag = ip->i_d.di_tag;
8512                 gid = (mask & ATTR_GID) ? iattr->ia_gid : igid;
8513                 uid = (mask & ATTR_UID) ? iattr->ia_uid : iuid;
8514 +               tag = (mask & ATTR_TAG) ? iattr->ia_tag : itag;
8515  
8516                 /*
8517                  * Do a quota reservation only if uid/gid is actually
8518 @@ -165,7 +240,8 @@ xfs_setattr(
8519                  */
8520                 if (XFS_IS_QUOTA_RUNNING(mp) &&
8521                     ((XFS_IS_UQUOTA_ON(mp) && iuid != uid) ||
8522 -                    (XFS_IS_GQUOTA_ON(mp) && igid != gid))) {
8523 +                    (XFS_IS_GQUOTA_ON(mp) && igid != gid) ||
8524 +                    (XFS_IS_GQUOTA_ON(mp) && itag != tag))) {
8525                         ASSERT(tp);
8526                         code = xfs_qm_vop_chown_reserve(tp, ip, udqp, gdqp,
8527                                                 capable(CAP_FOWNER) ?
8528 @@ -329,7 +405,7 @@ xfs_setattr(
8529         /*
8530          * Change file ownership.  Must be the owner or privileged.
8531          */
8532 -       if (mask & (ATTR_UID|ATTR_GID)) {
8533 +       if (mask & (ATTR_UID|ATTR_GID|ATTR_TAG)) {
8534                 /*
8535                  * CAP_FSETID overrides the following restrictions:
8536                  *
8537 @@ -345,6 +421,10 @@ xfs_setattr(
8538                  * Change the ownerships and register quota modifications
8539                  * in the transaction.
8540                  */
8541 +               if (itag != tag) {
8542 +                       ip->i_d.di_tag = tag;
8543 +                       inode->i_tag = tag;
8544 +               }
8545                 if (iuid != uid) {
8546                         if (XFS_IS_QUOTA_RUNNING(mp) && XFS_IS_UQUOTA_ON(mp)) {
8547                                 ASSERT(mask & ATTR_UID);
8548 diff -NurpP --minimal linux-2.6.38-rc8/fs/xfs/xfs_vnodeops.h linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/xfs/xfs_vnodeops.h
8549 --- linux-2.6.38-rc8/fs/xfs/xfs_vnodeops.h      2011-01-05 21:50:28.000000000 +0100
8550 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/fs/xfs/xfs_vnodeops.h       2011-01-29 02:01:07.000000000 +0100
8551 @@ -13,6 +13,7 @@ struct xfs_inode;
8552  struct xfs_iomap;
8553  
8554  
8555 +int xfs_sync_xflags(struct xfs_inode *ip);
8556  int xfs_setattr(struct xfs_inode *ip, struct iattr *vap, int flags);
8557  #define        XFS_ATTR_DMI            0x01    /* invocation from a DMI function */
8558  #define        XFS_ATTR_NONBLOCK       0x02    /* return EAGAIN if operation would block */
8559 diff -NurpP --minimal linux-2.6.38-rc8/include/asm-generic/tlb.h linux-2.6.38-rc8-vs2.3.0.37-rc6/include/asm-generic/tlb.h
8560 --- linux-2.6.38-rc8/include/asm-generic/tlb.h  2009-09-10 15:26:24.000000000 +0200
8561 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/include/asm-generic/tlb.h   2011-01-29 02:01:07.000000000 +0100
8562 @@ -14,6 +14,7 @@
8563  #define _ASM_GENERIC__TLB_H
8564  
8565  #include <linux/swap.h>
8566 +#include <linux/vs_memory.h>
8567  #include <asm/pgalloc.h>
8568  #include <asm/tlbflush.h>
8569  
8570 diff -NurpP --minimal linux-2.6.38-rc8/include/linux/Kbuild linux-2.6.38-rc8-vs2.3.0.37-rc6/include/linux/Kbuild
8571 --- linux-2.6.38-rc8/include/linux/Kbuild       2011-03-10 17:09:25.000000000 +0100
8572 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/include/linux/Kbuild        2011-02-17 02:17:51.000000000 +0100
8573 @@ -16,6 +16,7 @@ header-y += netfilter_bridge/
8574  header-y += netfilter_ipv4/
8575  header-y += netfilter_ipv6/
8576  header-y += usb/
8577 +header-y += vserver/
8578  header-y += wimax/
8579  
8580  objhdr-y += version.h
8581 diff -NurpP --minimal linux-2.6.38-rc8/include/linux/capability.h linux-2.6.38-rc8-vs2.3.0.37-rc6/include/linux/capability.h
8582 --- linux-2.6.38-rc8/include/linux/capability.h 2011-03-10 17:09:25.000000000 +0100
8583 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/include/linux/capability.h  2011-01-29 02:01:07.000000000 +0100
8584 @@ -279,6 +279,7 @@ struct cpu_vfs_cap_data {
8585     arbitrary SCSI commands */
8586  /* Allow setting encryption key on loopback filesystem */
8587  /* Allow setting zone reclaim policy */
8588 +/* Allow the selection of a security context */
8589  
8590  #define CAP_SYS_ADMIN        21
8591  
8592 @@ -357,7 +358,12 @@ struct cpu_vfs_cap_data {
8593  
8594  #define CAP_LAST_CAP         CAP_SYSLOG
8595  
8596 -#define cap_valid(x) ((x) >= 0 && (x) <= CAP_LAST_CAP)
8597 +/* Allow context manipulations */
8598 +/* Allow changing context info on files */
8599 +
8600 +#define CAP_CONTEXT         63
8601 +
8602 +#define cap_valid(x) ((x) >= 0 && ((x) <= CAP_LAST_CAP || (x) == CAP_CONTEXT))
8603  
8604  /*
8605   * Bit location of each capability (used by user-space library and kernel)
8606 diff -NurpP --minimal linux-2.6.38-rc8/include/linux/cred.h linux-2.6.38-rc8-vs2.3.0.37-rc6/include/linux/cred.h
8607 --- linux-2.6.38-rc8/include/linux/cred.h       2011-01-05 21:50:29.000000000 +0100
8608 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/include/linux/cred.h        2011-01-31 12:03:07.000000000 +0100
8609 @@ -155,6 +155,7 @@ extern void exit_creds(struct task_struc
8610  extern int copy_creds(struct task_struct *, unsigned long);
8611  extern const struct cred *get_task_cred(struct task_struct *);
8612  extern struct cred *cred_alloc_blank(void);
8613 +extern struct cred *__prepare_creds(const struct cred *);
8614  extern struct cred *prepare_creds(void);
8615  extern struct cred *prepare_exec_creds(void);
8616  extern int commit_creds(struct cred *);
8617 @@ -208,6 +209,31 @@ static inline void validate_process_cred
8618  }
8619  #endif
8620  
8621 +static inline void set_cred_subscribers(struct cred *cred, int n)
8622 +{
8623 +#ifdef CONFIG_DEBUG_CREDENTIALS
8624 +       atomic_set(&cred->subscribers, n);
8625 +#endif
8626 +}
8627 +
8628 +static inline int read_cred_subscribers(const struct cred *cred)
8629 +{
8630 +#ifdef CONFIG_DEBUG_CREDENTIALS
8631 +       return atomic_read(&cred->subscribers);
8632 +#else
8633 +       return 0;
8634 +#endif
8635 +}
8636 +
8637 +static inline void alter_cred_subscribers(const struct cred *_cred, int n)
8638 +{
8639 +#ifdef CONFIG_DEBUG_CREDENTIALS
8640 +       struct cred *cred = (struct cred *) _cred;
8641 +
8642 +       atomic_add(n, &cred->subscribers);
8643 +#endif
8644 +}
8645 +
8646  /**
8647   * get_new_cred - Get a reference on a new set of credentials
8648   * @cred: The new credentials to reference
8649 diff -NurpP --minimal linux-2.6.38-rc8/include/linux/devpts_fs.h linux-2.6.38-rc8-vs2.3.0.37-rc6/include/linux/devpts_fs.h
8650 --- linux-2.6.38-rc8/include/linux/devpts_fs.h  2008-12-25 00:26:37.000000000 +0100
8651 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/include/linux/devpts_fs.h   2011-01-29 02:01:07.000000000 +0100
8652 @@ -45,5 +45,4 @@ static inline void devpts_pty_kill(struc
8653  
8654  #endif
8655  
8656 -
8657  #endif /* _LINUX_DEVPTS_FS_H */
8658 diff -NurpP --minimal linux-2.6.38-rc8/include/linux/ext2_fs.h linux-2.6.38-rc8-vs2.3.0.37-rc6/include/linux/ext2_fs.h
8659 --- linux-2.6.38-rc8/include/linux/ext2_fs.h    2010-02-25 11:52:07.000000000 +0100
8660 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/include/linux/ext2_fs.h     2011-01-29 02:01:07.000000000 +0100
8661 @@ -189,8 +189,12 @@ struct ext2_group_desc
8662  #define EXT2_NOTAIL_FL                 FS_NOTAIL_FL    /* file tail should not be merged */
8663  #define EXT2_DIRSYNC_FL                        FS_DIRSYNC_FL   /* dirsync behaviour (directories only) */
8664  #define EXT2_TOPDIR_FL                 FS_TOPDIR_FL    /* Top of directory hierarchies*/
8665 +#define EXT2_IXUNLINK_FL               FS_IXUNLINK_FL  /* Immutable invert on unlink */
8666  #define EXT2_RESERVED_FL               FS_RESERVED_FL  /* reserved for ext2 lib */
8667  
8668 +#define EXT2_BARRIER_FL                        FS_BARRIER_FL   /* Barrier for chroot() */
8669 +#define EXT2_COW_FL                    FS_COW_FL       /* Copy on Write marker */
8670 +
8671  #define EXT2_FL_USER_VISIBLE           FS_FL_USER_VISIBLE      /* User visible flags */
8672  #define EXT2_FL_USER_MODIFIABLE                FS_FL_USER_MODIFIABLE   /* User modifiable flags */
8673  
8674 @@ -274,7 +278,8 @@ struct ext2_inode {
8675                         __u16   i_pad1;
8676                         __le16  l_i_uid_high;   /* these 2 fields    */
8677                         __le16  l_i_gid_high;   /* were reserved2[0] */
8678 -                       __u32   l_i_reserved2;
8679 +                       __le16  l_i_tag;        /* Context Tag */
8680 +                       __u16   l_i_reserved2;
8681                 } linux2;
8682                 struct {
8683                         __u8    h_i_frag;       /* Fragment number */
8684 @@ -303,6 +308,7 @@ struct ext2_inode {
8685  #define i_gid_low      i_gid
8686  #define i_uid_high     osd2.linux2.l_i_uid_high
8687  #define i_gid_high     osd2.linux2.l_i_gid_high
8688 +#define i_raw_tag      osd2.linux2.l_i_tag
8689  #define i_reserved2    osd2.linux2.l_i_reserved2
8690  #endif
8691  
8692 @@ -347,6 +353,7 @@ struct ext2_inode {
8693  #define EXT2_MOUNT_USRQUOTA            0x020000  /* user quota */
8694  #define EXT2_MOUNT_GRPQUOTA            0x040000  /* group quota */
8695  #define EXT2_MOUNT_RESERVATION         0x080000  /* Preallocation */
8696 +#define EXT2_MOUNT_TAGGED              (1<<24)   /* Enable Context Tags */
8697  
8698  
8699  #define clear_opt(o, opt)              o &= ~EXT2_MOUNT_##opt
8700 diff -NurpP --minimal linux-2.6.38-rc8/include/linux/ext3_fs.h linux-2.6.38-rc8-vs2.3.0.37-rc6/include/linux/ext3_fs.h
8701 --- linux-2.6.38-rc8/include/linux/ext3_fs.h    2011-03-10 17:09:25.000000000 +0100
8702 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/include/linux/ext3_fs.h     2011-01-29 02:01:07.000000000 +0100
8703 @@ -173,10 +173,14 @@ struct ext3_group_desc
8704  #define EXT3_NOTAIL_FL                 0x00008000 /* file tail should not be merged */
8705  #define EXT3_DIRSYNC_FL                        0x00010000 /* dirsync behaviour (directories only) */
8706  #define EXT3_TOPDIR_FL                 0x00020000 /* Top of directory hierarchies*/
8707 +#define EXT3_IXUNLINK_FL               0x08000000 /* Immutable invert on unlink */
8708  #define EXT3_RESERVED_FL               0x80000000 /* reserved for ext3 lib */
8709  
8710 -#define EXT3_FL_USER_VISIBLE           0x0003DFFF /* User visible flags */
8711 -#define EXT3_FL_USER_MODIFIABLE                0x000380FF /* User modifiable flags */
8712 +#define EXT3_BARRIER_FL                        0x04000000 /* Barrier for chroot() */
8713 +#define EXT3_COW_FL                    0x20000000 /* Copy on Write marker */
8714 +
8715 +#define EXT3_FL_USER_VISIBLE           0x0103DFFF /* User visible flags */
8716 +#define EXT3_FL_USER_MODIFIABLE                0x010380FF /* User modifiable flags */
8717  
8718  /* Flags that should be inherited by new inodes from their parent. */
8719  #define EXT3_FL_INHERITED (EXT3_SECRM_FL | EXT3_UNRM_FL | EXT3_COMPR_FL |\
8720 @@ -312,7 +316,8 @@ struct ext3_inode {
8721                         __u16   i_pad1;
8722                         __le16  l_i_uid_high;   /* these 2 fields    */
8723                         __le16  l_i_gid_high;   /* were reserved2[0] */
8724 -                       __u32   l_i_reserved2;
8725 +                       __le16  l_i_tag;        /* Context Tag */
8726 +                       __u16   l_i_reserved2;
8727                 } linux2;
8728                 struct {
8729                         __u8    h_i_frag;       /* Fragment number */
8730 @@ -343,6 +348,7 @@ struct ext3_inode {
8731  #define i_gid_low      i_gid
8732  #define i_uid_high     osd2.linux2.l_i_uid_high
8733  #define i_gid_high     osd2.linux2.l_i_gid_high
8734 +#define i_raw_tag      osd2.linux2.l_i_tag
8735  #define i_reserved2    osd2.linux2.l_i_reserved2
8736  
8737  #elif defined(__GNU__)
8738 @@ -405,6 +411,7 @@ struct ext3_inode {
8739  #define EXT3_MOUNT_GRPQUOTA            0x200000 /* "old" group quota */
8740  #define EXT3_MOUNT_DATA_ERR_ABORT      0x400000 /* Abort on file data write
8741                                                   * error in ordered mode */
8742 +#define EXT3_MOUNT_TAGGED              (1<<24) /* Enable Context Tags */
8743  
8744  /* Compatibility, for having both ext2_fs.h and ext3_fs.h included at once */
8745  #ifndef _LINUX_EXT2_FS_H
8746 @@ -918,6 +925,7 @@ extern void ext3_get_inode_flags(struct 
8747  extern void ext3_set_aops(struct inode *inode);
8748  extern int ext3_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
8749                        u64 start, u64 len);
8750 +extern int ext3_sync_flags(struct inode *, int, int);
8751  
8752  /* ioctl.c */
8753  extern long ext3_ioctl(struct file *, unsigned int, unsigned long);
8754 diff -NurpP --minimal linux-2.6.38-rc8/include/linux/fs.h linux-2.6.38-rc8-vs2.3.0.37-rc6/include/linux/fs.h
8755 --- linux-2.6.38-rc8/include/linux/fs.h 2011-03-10 17:09:25.000000000 +0100
8756 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/include/linux/fs.h  2011-03-07 16:53:28.000000000 +0100
8757 @@ -214,6 +214,9 @@ struct inodes_stat_t {
8758  #define MS_KERNMOUNT   (1<<22) /* this is a kern_mount call */
8759  #define MS_I_VERSION   (1<<23) /* Update inode I_version field */
8760  #define MS_STRICTATIME (1<<24) /* Always perform atime updates */
8761 +#define MS_TAGGED      (1<<25) /* use generic inode tagging */
8762 +#define MS_TAGID       (1<<26) /* use specific tag for this mount */
8763 +#define MS_NOTAGCHECK  (1<<27) /* don't check tags */
8764  #define MS_BORN                (1<<29)
8765  #define MS_ACTIVE      (1<<30)
8766  #define MS_NOUSER      (1<<31)
8767 @@ -243,6 +246,14 @@ struct inodes_stat_t {
8768  #define S_PRIVATE      512     /* Inode is fs-internal */
8769  #define S_IMA          1024    /* Inode has an associated IMA struct */
8770  #define S_AUTOMOUNT    2048    /* Automount/referral quasi-directory */
8771 +#define S_IXUNLINK     4096    /* Immutable Invert on unlink */
8772 +
8773 +/* Linux-VServer related Inode flags */
8774 +
8775 +#define V_VALID                1
8776 +#define V_XATTR                2
8777 +#define V_BARRIER      4       /* Barrier for chroot() */
8778 +#define V_COW          8       /* Copy on Write */
8779  
8780  /*
8781   * Note that nosuid etc flags are inode-specific: setting some file-system
8782 @@ -265,12 +276,15 @@ struct inodes_stat_t {
8783  #define IS_DIRSYNC(inode)      (__IS_FLG(inode, MS_SYNCHRONOUS|MS_DIRSYNC) || \
8784                                         ((inode)->i_flags & (S_SYNC|S_DIRSYNC)))
8785  #define IS_MANDLOCK(inode)     __IS_FLG(inode, MS_MANDLOCK)
8786 -#define IS_NOATIME(inode)   __IS_FLG(inode, MS_RDONLY|MS_NOATIME)
8787 -#define IS_I_VERSION(inode)   __IS_FLG(inode, MS_I_VERSION)
8788 +#define IS_NOATIME(inode)      __IS_FLG(inode, MS_RDONLY|MS_NOATIME)
8789 +#define IS_I_VERSION(inode)    __IS_FLG(inode, MS_I_VERSION)
8790 +#define IS_TAGGED(inode)       __IS_FLG(inode, MS_TAGGED)
8791  
8792  #define IS_NOQUOTA(inode)      ((inode)->i_flags & S_NOQUOTA)
8793  #define IS_APPEND(inode)       ((inode)->i_flags & S_APPEND)
8794  #define IS_IMMUTABLE(inode)    ((inode)->i_flags & S_IMMUTABLE)
8795 +#define IS_IXUNLINK(inode)     ((inode)->i_flags & S_IXUNLINK)
8796 +#define IS_IXORUNLINK(inode)   ((IS_IXUNLINK(inode) ? S_IMMUTABLE : 0) ^ IS_IMMUTABLE(inode))
8797  #define IS_POSIXACL(inode)     __IS_FLG(inode, MS_POSIXACL)
8798  
8799  #define IS_DEADDIR(inode)      ((inode)->i_flags & S_DEAD)
8800 @@ -280,6 +294,16 @@ struct inodes_stat_t {
8801  #define IS_IMA(inode)          ((inode)->i_flags & S_IMA)
8802  #define IS_AUTOMOUNT(inode)    ((inode)->i_flags & S_AUTOMOUNT)
8803  
8804 +#define IS_BARRIER(inode)      (S_ISDIR((inode)->i_mode) && ((inode)->i_vflags & V_BARRIER))
8805 +
8806 +#ifdef CONFIG_VSERVER_COWBL
8807 +#  define IS_COW(inode)                (IS_IXUNLINK(inode) && IS_IMMUTABLE(inode))
8808 +#  define IS_COW_LINK(inode)   (S_ISREG((inode)->i_mode) && ((inode)->i_nlink > 1))
8809 +#else
8810 +#  define IS_COW(inode)                (0)
8811 +#  define IS_COW_LINK(inode)   (0)
8812 +#endif
8813 +
8814  /* the read-only stuff doesn't really belong here, but any other place is
8815     probably as bad and I don't want to create yet another include file. */
8816  
8817 @@ -364,11 +388,14 @@ struct inodes_stat_t {
8818  #define FS_TOPDIR_FL                   0x00020000 /* Top of directory hierarchies*/
8819  #define FS_EXTENT_FL                   0x00080000 /* Extents */
8820  #define FS_DIRECTIO_FL                 0x00100000 /* Use direct i/o */
8821 +#define FS_IXUNLINK_FL                 0x08000000 /* Immutable invert on unlink */
8822  #define FS_RESERVED_FL                 0x80000000 /* reserved for ext2 lib */
8823  
8824 -#define FS_FL_USER_VISIBLE             0x0003DFFF /* User visible flags */
8825 -#define FS_FL_USER_MODIFIABLE          0x000380FF /* User modifiable flags */
8826 +#define FS_BARRIER_FL                  0x04000000 /* Barrier for chroot() */
8827 +#define FS_COW_FL                      0x20000000 /* Copy on Write marker */
8828  
8829 +#define FS_FL_USER_VISIBLE             0x0103DFFF /* User visible flags */
8830 +#define FS_FL_USER_MODIFIABLE          0x010380FF /* User modifiable flags */
8831  
8832  #define SYNC_FILE_RANGE_WAIT_BEFORE    1
8833  #define SYNC_FILE_RANGE_WRITE          2
8834 @@ -449,6 +476,7 @@ typedef void (dio_iodone_t)(struct kiocb
8835  #define ATTR_KILL_PRIV (1 << 14)
8836  #define ATTR_OPEN      (1 << 15) /* Truncating from open(O_TRUNC) */
8837  #define ATTR_TIMES_SET (1 << 16)
8838 +#define ATTR_TAG       (1 << 17)
8839  
8840  /*
8841   * This is the Inode Attributes structure, used for notify_change().  It
8842 @@ -464,6 +492,7 @@ struct iattr {
8843         umode_t         ia_mode;
8844         uid_t           ia_uid;
8845         gid_t           ia_gid;
8846 +       tag_t           ia_tag;
8847         loff_t          ia_size;
8848         struct timespec ia_atime;
8849         struct timespec ia_mtime;
8850 @@ -477,6 +506,9 @@ struct iattr {
8851         struct file     *ia_file;
8852  };
8853  
8854 +#define ATTR_FLAG_BARRIER      512     /* Barrier for chroot() */
8855 +#define ATTR_FLAG_IXUNLINK     1024    /* Immutable invert on unlink */
8856 +
8857  /*
8858   * Includes for diskquotas.
8859   */
8860 @@ -742,11 +774,13 @@ struct inode {
8861         umode_t                 i_mode;
8862         uid_t                   i_uid;
8863         gid_t                   i_gid;
8864 +       tag_t                   i_tag;
8865         const struct inode_operations   *i_op;
8866         struct super_block      *i_sb;
8867  
8868         spinlock_t              i_lock; /* i_blocks, i_bytes, maybe i_size */
8869 -       unsigned int            i_flags;
8870 +       unsigned short          i_flags;
8871 +       unsigned short          i_vflags;
8872         struct mutex            i_mutex;
8873  
8874         unsigned long           i_state;
8875 @@ -764,6 +798,7 @@ struct inode {
8876         atomic_t                i_count;
8877         unsigned int            i_nlink;
8878         dev_t                   i_rdev;
8879 +       dev_t                   i_mdev;
8880         unsigned int            i_blkbits;
8881         u64                     i_version;
8882         loff_t                  i_size;
8883 @@ -892,12 +927,12 @@ static inline void i_size_write(struct i
8884  
8885  static inline unsigned iminor(const struct inode *inode)
8886  {
8887 -       return MINOR(inode->i_rdev);
8888 +       return MINOR(inode->i_mdev);
8889  }
8890  
8891  static inline unsigned imajor(const struct inode *inode)
8892  {
8893 -       return MAJOR(inode->i_rdev);
8894 +       return MAJOR(inode->i_mdev);
8895  }
8896  
8897  extern struct block_device *I_BDEV(struct inode *inode);
8898 @@ -959,6 +994,7 @@ struct file {
8899         loff_t                  f_pos;
8900         struct fown_struct      f_owner;
8901         const struct cred       *f_cred;
8902 +       xid_t                   f_xid;
8903         struct file_ra_state    f_ra;
8904  
8905         u64                     f_version;
8906 @@ -1096,6 +1132,7 @@ struct file_lock {
8907         struct file *fl_file;
8908         loff_t fl_start;
8909         loff_t fl_end;
8910 +       xid_t fl_xid;
8911  
8912         struct fasync_struct *  fl_fasync; /* for lease break notifications */
8913         unsigned long fl_break_time;    /* for nonblocking lease breaks */
8914 @@ -1584,6 +1621,7 @@ struct inode_operations {
8915         ssize_t (*getxattr) (struct dentry *, const char *, void *, size_t);
8916         ssize_t (*listxattr) (struct dentry *, char *, size_t);
8917         int (*removexattr) (struct dentry *, const char *);
8918 +       int (*sync_flags) (struct inode *, int, int);
8919         void (*truncate_range)(struct inode *, loff_t, loff_t);
8920         int (*fiemap)(struct inode *, struct fiemap_extent_info *, u64 start,
8921                       u64 len);
8922 @@ -1602,6 +1640,7 @@ extern ssize_t vfs_readv(struct file *, 
8923                 unsigned long, loff_t *);
8924  extern ssize_t vfs_writev(struct file *, const struct iovec __user *,
8925                 unsigned long, loff_t *);
8926 +ssize_t vfs_sendfile(struct file *, struct file *, loff_t *, size_t, loff_t);
8927  
8928  struct super_operations {
8929         struct inode *(*alloc_inode)(struct super_block *sb);
8930 @@ -2414,6 +2453,7 @@ extern int dcache_dir_open(struct inode 
8931  extern int dcache_dir_close(struct inode *, struct file *);
8932  extern loff_t dcache_dir_lseek(struct file *, loff_t, int);
8933  extern int dcache_readdir(struct file *, void *, filldir_t);
8934 +extern int dcache_readdir_filter(struct file *, void *, filldir_t, int (*)(struct dentry *));
8935  extern int simple_setattr(struct dentry *, struct iattr *);
8936  extern int simple_getattr(struct vfsmount *, struct dentry *, struct kstat *);
8937  extern int simple_statfs(struct dentry *, struct kstatfs *);
8938 diff -NurpP --minimal linux-2.6.38-rc8/include/linux/gfs2_ondisk.h linux-2.6.38-rc8-vs2.3.0.37-rc6/include/linux/gfs2_ondisk.h
8939 --- linux-2.6.38-rc8/include/linux/gfs2_ondisk.h        2010-07-07 18:31:55.000000000 +0200
8940 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/include/linux/gfs2_ondisk.h 2011-01-29 02:01:07.000000000 +0100
8941 @@ -211,6 +211,9 @@ enum {
8942         gfs2fl_NoAtime          = 7,
8943         gfs2fl_Sync             = 8,
8944         gfs2fl_System           = 9,
8945 +       gfs2fl_IXUnlink         = 16,
8946 +       gfs2fl_Barrier          = 17,
8947 +       gfs2fl_Cow              = 18,
8948         gfs2fl_TruncInProg      = 29,
8949         gfs2fl_InheritDirectio  = 30,
8950         gfs2fl_InheritJdata     = 31,
8951 @@ -227,6 +230,9 @@ enum {
8952  #define GFS2_DIF_NOATIME               0x00000080
8953  #define GFS2_DIF_SYNC                  0x00000100
8954  #define GFS2_DIF_SYSTEM                        0x00000200 /* New in gfs2 */
8955 +#define GFS2_DIF_IXUNLINK              0x00010000
8956 +#define GFS2_DIF_BARRIER               0x00020000
8957 +#define GFS2_DIF_COW                   0x00040000
8958  #define GFS2_DIF_TRUNC_IN_PROG         0x20000000 /* New in gfs2 */
8959  #define GFS2_DIF_INHERIT_DIRECTIO      0x40000000
8960  #define GFS2_DIF_INHERIT_JDATA         0x80000000
8961 diff -NurpP --minimal linux-2.6.38-rc8/include/linux/if_tun.h linux-2.6.38-rc8-vs2.3.0.37-rc6/include/linux/if_tun.h
8962 --- linux-2.6.38-rc8/include/linux/if_tun.h     2010-08-02 16:52:54.000000000 +0200
8963 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/include/linux/if_tun.h      2011-01-29 02:01:07.000000000 +0100
8964 @@ -53,6 +53,7 @@
8965  #define TUNDETACHFILTER _IOW('T', 214, struct sock_fprog)
8966  #define TUNGETVNETHDRSZ _IOR('T', 215, int)
8967  #define TUNSETVNETHDRSZ _IOW('T', 216, int)
8968 +#define TUNSETNID     _IOW('T', 217, int)
8969  
8970  /* TUNSETIFF ifr flags */
8971  #define IFF_TUN                0x0001
8972 diff -NurpP --minimal linux-2.6.38-rc8/include/linux/init_task.h linux-2.6.38-rc8-vs2.3.0.37-rc6/include/linux/init_task.h
8973 --- linux-2.6.38-rc8/include/linux/init_task.h  2011-03-10 17:09:25.000000000 +0100
8974 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/include/linux/init_task.h   2011-01-29 02:01:07.000000000 +0100
8975 @@ -192,6 +192,10 @@ extern struct cred init_cred;
8976         INIT_FTRACE_GRAPH                                               \
8977         INIT_TRACE_RECURSION                                            \
8978         INIT_TASK_RCU_PREEMPT(tsk)                                      \
8979 +       .xid            = 0,                                            \
8980 +       .vx_info        = NULL,                                         \
8981 +       .nid            = 0,                                            \
8982 +       .nx_info        = NULL,                                         \
8983  }
8984  
8985  
8986 diff -NurpP --minimal linux-2.6.38-rc8/include/linux/ipc.h linux-2.6.38-rc8-vs2.3.0.37-rc6/include/linux/ipc.h
8987 --- linux-2.6.38-rc8/include/linux/ipc.h        2009-12-03 20:02:55.000000000 +0100
8988 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/include/linux/ipc.h 2011-01-29 02:01:07.000000000 +0100
8989 @@ -91,6 +91,7 @@ struct kern_ipc_perm
8990         key_t           key;
8991         uid_t           uid;
8992         gid_t           gid;
8993 +       xid_t           xid;
8994         uid_t           cuid;
8995         gid_t           cgid;
8996         mode_t          mode; 
8997 diff -NurpP --minimal linux-2.6.38-rc8/include/linux/loop.h linux-2.6.38-rc8-vs2.3.0.37-rc6/include/linux/loop.h
8998 --- linux-2.6.38-rc8/include/linux/loop.h       2009-09-10 15:26:25.000000000 +0200
8999 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/include/linux/loop.h        2011-01-29 02:01:07.000000000 +0100
9000 @@ -45,6 +45,7 @@ struct loop_device {
9001         struct loop_func_table *lo_encryption;
9002         __u32           lo_init[2];
9003         uid_t           lo_key_owner;   /* Who set the key */
9004 +       xid_t           lo_xid;
9005         int             (*ioctl)(struct loop_device *, int cmd, 
9006                                  unsigned long arg); 
9007  
9008 diff -NurpP --minimal linux-2.6.38-rc8/include/linux/magic.h linux-2.6.38-rc8-vs2.3.0.37-rc6/include/linux/magic.h
9009 --- linux-2.6.38-rc8/include/linux/magic.h      2011-03-10 17:09:25.000000000 +0100
9010 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/include/linux/magic.h       2011-01-29 02:01:07.000000000 +0100
9011 @@ -3,7 +3,7 @@
9012  
9013  #define ADFS_SUPER_MAGIC       0xadf5
9014  #define AFFS_SUPER_MAGIC       0xadff
9015 -#define AFS_SUPER_MAGIC                0x5346414F
9016 +#define AFS_SUPER_MAGIC                0x5346414F
9017  #define AUTOFS_SUPER_MAGIC     0x0187
9018  #define CODA_SUPER_MAGIC       0x73757245
9019  #define CRAMFS_MAGIC           0x28cd3d45      /* some random number */
9020 @@ -39,6 +39,7 @@
9021  #define NFS_SUPER_MAGIC                0x6969
9022  #define OPENPROM_SUPER_MAGIC   0x9fa1
9023  #define PROC_SUPER_MAGIC       0x9fa0
9024 +#define DEVPTS_SUPER_MAGIC     0x1cd1
9025  #define QNX4_SUPER_MAGIC       0x002f          /* qnx4 fs detection */
9026  
9027  #define REISERFS_SUPER_MAGIC   0x52654973      /* used by gcc */
9028 diff -NurpP --minimal linux-2.6.38-rc8/include/linux/major.h linux-2.6.38-rc8-vs2.3.0.37-rc6/include/linux/major.h
9029 --- linux-2.6.38-rc8/include/linux/major.h      2009-09-10 15:26:25.000000000 +0200
9030 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/include/linux/major.h       2011-01-29 02:01:07.000000000 +0100
9031 @@ -15,6 +15,7 @@
9032  #define HD_MAJOR               IDE0_MAJOR
9033  #define PTY_SLAVE_MAJOR                3
9034  #define TTY_MAJOR              4
9035 +#define VROOT_MAJOR            4
9036  #define TTYAUX_MAJOR           5
9037  #define LP_MAJOR               6
9038  #define VCS_MAJOR              7
9039 diff -NurpP --minimal linux-2.6.38-rc8/include/linux/memcontrol.h linux-2.6.38-rc8-vs2.3.0.37-rc6/include/linux/memcontrol.h
9040 --- linux-2.6.38-rc8/include/linux/memcontrol.h 2011-03-10 17:09:25.000000000 +0100
9041 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/include/linux/memcontrol.h  2011-01-29 02:01:07.000000000 +0100
9042 @@ -82,6 +82,13 @@ int task_in_mem_cgroup(struct task_struc
9043  extern struct mem_cgroup *try_get_mem_cgroup_from_page(struct page *page);
9044  extern struct mem_cgroup *mem_cgroup_from_task(struct task_struct *p);
9045  
9046 +extern u64 mem_cgroup_res_read_u64(struct mem_cgroup *mem, int member);
9047 +extern u64 mem_cgroup_memsw_read_u64(struct mem_cgroup *mem, int member);
9048 +
9049 +extern s64 mem_cgroup_stat_read_cache(struct mem_cgroup *mem);
9050 +extern s64 mem_cgroup_stat_read_anon(struct mem_cgroup *mem);
9051 +extern s64 mem_cgroup_stat_read_mapped(struct mem_cgroup *mem);
9052 +
9053  static inline
9054  int mm_match_cgroup(const struct mm_struct *mm, const struct mem_cgroup *cgroup)
9055  {
9056 diff -NurpP --minimal linux-2.6.38-rc8/include/linux/mm_types.h linux-2.6.38-rc8-vs2.3.0.37-rc6/include/linux/mm_types.h
9057 --- linux-2.6.38-rc8/include/linux/mm_types.h   2011-03-10 17:09:25.000000000 +0100
9058 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/include/linux/mm_types.h    2011-01-29 02:01:07.000000000 +0100
9059 @@ -269,6 +269,7 @@ struct mm_struct {
9060  
9061         /* Architecture-specific MM context */
9062         mm_context_t context;
9063 +       struct vx_info *mm_vx_info;
9064  
9065         /* Swap token stuff */
9066         /*
9067 diff -NurpP --minimal linux-2.6.38-rc8/include/linux/mount.h linux-2.6.38-rc8-vs2.3.0.37-rc6/include/linux/mount.h
9068 --- linux-2.6.38-rc8/include/linux/mount.h      2011-03-10 17:09:25.000000000 +0100
9069 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/include/linux/mount.h       2011-01-29 03:11:27.000000000 +0100
9070 @@ -52,6 +52,9 @@ struct mnt_pcp {
9071         int mnt_writers;
9072  };
9073  
9074 +#define MNT_TAGID      0x10000
9075 +#define MNT_NOTAG      0x20000
9076 +
9077  struct vfsmount {
9078         struct list_head mnt_hash;
9079         struct vfsmount *mnt_parent;    /* fs we are mounted on */
9080 @@ -86,6 +89,7 @@ struct vfsmount {
9081         int mnt_expiry_mark;            /* true if marked for expiry */
9082         int mnt_pinned;
9083         int mnt_ghosts;
9084 +       tag_t mnt_tag;                  /* tagging used for vfsmount */
9085  };
9086  
9087  struct file; /* forward dec */
9088 diff -NurpP --minimal linux-2.6.38-rc8/include/linux/net.h linux-2.6.38-rc8-vs2.3.0.37-rc6/include/linux/net.h
9089 --- linux-2.6.38-rc8/include/linux/net.h        2011-01-05 21:50:31.000000000 +0100
9090 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/include/linux/net.h 2011-01-29 02:01:07.000000000 +0100
9091 @@ -71,6 +71,7 @@ struct net;
9092  #define SOCK_NOSPACE           2
9093  #define SOCK_PASSCRED          3
9094  #define SOCK_PASSSEC           4
9095 +#define SOCK_USER_SOCKET       5
9096  
9097  #ifndef ARCH_HAS_SOCKET_TYPES
9098  /**
9099 diff -NurpP --minimal linux-2.6.38-rc8/include/linux/nfs_mount.h linux-2.6.38-rc8-vs2.3.0.37-rc6/include/linux/nfs_mount.h
9100 --- linux-2.6.38-rc8/include/linux/nfs_mount.h  2011-01-05 21:50:31.000000000 +0100
9101 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/include/linux/nfs_mount.h   2011-01-29 02:01:07.000000000 +0100
9102 @@ -63,7 +63,8 @@ struct nfs_mount_data {
9103  #define NFS_MOUNT_SECFLAVOUR   0x2000  /* 5 */
9104  #define NFS_MOUNT_NORDIRPLUS   0x4000  /* 5 */
9105  #define NFS_MOUNT_UNSHARED     0x8000  /* 5 */
9106 -#define NFS_MOUNT_FLAGMASK     0xFFFF
9107 +#define NFS_MOUNT_TAGGED       0x10000 /* context tagging */
9108 +#define NFS_MOUNT_FLAGMASK     0x1FFFF
9109  
9110  /* The following are for internal use only */
9111  #define NFS_MOUNT_LOOKUP_CACHE_NONEG   0x10000
9112 diff -NurpP --minimal linux-2.6.38-rc8/include/linux/nsproxy.h linux-2.6.38-rc8-vs2.3.0.37-rc6/include/linux/nsproxy.h
9113 --- linux-2.6.38-rc8/include/linux/nsproxy.h    2009-06-11 17:13:17.000000000 +0200
9114 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/include/linux/nsproxy.h     2011-01-29 02:01:07.000000000 +0100
9115 @@ -3,6 +3,7 @@
9116  
9117  #include <linux/spinlock.h>
9118  #include <linux/sched.h>
9119 +#include <linux/vserver/debug.h>
9120  
9121  struct mnt_namespace;
9122  struct uts_namespace;
9123 @@ -63,22 +64,33 @@ static inline struct nsproxy *task_nspro
9124  }
9125  
9126  int copy_namespaces(unsigned long flags, struct task_struct *tsk);
9127 +struct nsproxy *copy_nsproxy(struct nsproxy *orig);
9128  void exit_task_namespaces(struct task_struct *tsk);
9129  void switch_task_namespaces(struct task_struct *tsk, struct nsproxy *new);
9130  void free_nsproxy(struct nsproxy *ns);
9131  int unshare_nsproxy_namespaces(unsigned long, struct nsproxy **,
9132         struct fs_struct *);
9133  
9134 -static inline void put_nsproxy(struct nsproxy *ns)
9135 +#define        get_nsproxy(n)  __get_nsproxy(n, __FILE__, __LINE__)
9136 +
9137 +static inline void __get_nsproxy(struct nsproxy *ns,
9138 +       const char *_file, int _line)
9139  {
9140 -       if (atomic_dec_and_test(&ns->count)) {
9141 -               free_nsproxy(ns);
9142 -       }
9143 +       vxlprintk(VXD_CBIT(space, 0), "get_nsproxy(%p[%u])",
9144 +               ns, atomic_read(&ns->count), _file, _line);
9145 +       atomic_inc(&ns->count);
9146  }
9147  
9148 -static inline void get_nsproxy(struct nsproxy *ns)
9149 +#define        put_nsproxy(n)  __put_nsproxy(n, __FILE__, __LINE__)
9150 +
9151 +static inline void __put_nsproxy(struct nsproxy *ns,
9152 +       const char *_file, int _line)
9153  {
9154 -       atomic_inc(&ns->count);
9155 +       vxlprintk(VXD_CBIT(space, 0), "put_nsproxy(%p[%u])",
9156 +               ns, atomic_read(&ns->count), _file, _line);
9157 +       if (atomic_dec_and_test(&ns->count)) {
9158 +               free_nsproxy(ns);
9159 +       }
9160  }
9161  
9162  #ifdef CONFIG_CGROUP_NS
9163 diff -NurpP --minimal linux-2.6.38-rc8/include/linux/pid.h linux-2.6.38-rc8-vs2.3.0.37-rc6/include/linux/pid.h
9164 --- linux-2.6.38-rc8/include/linux/pid.h        2009-03-24 14:22:43.000000000 +0100
9165 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/include/linux/pid.h 2011-01-29 02:01:07.000000000 +0100
9166 @@ -8,7 +8,8 @@ enum pid_type
9167         PIDTYPE_PID,
9168         PIDTYPE_PGID,
9169         PIDTYPE_SID,
9170 -       PIDTYPE_MAX
9171 +       PIDTYPE_MAX,
9172 +       PIDTYPE_REALPID
9173  };
9174  
9175  /*
9176 @@ -160,6 +161,7 @@ static inline pid_t pid_nr(struct pid *p
9177  }
9178  
9179  pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns);
9180 +pid_t pid_unmapped_nr_ns(struct pid *pid, struct pid_namespace *ns);
9181  pid_t pid_vnr(struct pid *pid);
9182  
9183  #define do_each_pid_task(pid, type, task)                              \
9184 diff -NurpP --minimal linux-2.6.38-rc8/include/linux/proc_fs.h linux-2.6.38-rc8-vs2.3.0.37-rc6/include/linux/proc_fs.h
9185 --- linux-2.6.38-rc8/include/linux/proc_fs.h    2009-12-03 20:02:56.000000000 +0100
9186 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/include/linux/proc_fs.h     2011-01-29 02:01:07.000000000 +0100
9187 @@ -56,6 +56,7 @@ struct proc_dir_entry {
9188         nlink_t nlink;
9189         uid_t uid;
9190         gid_t gid;
9191 +       int vx_flags;
9192         loff_t size;
9193         const struct inode_operations *proc_iops;
9194         /*
9195 @@ -250,12 +251,18 @@ kclist_add(struct kcore_list *new, void 
9196  extern void kclist_add(struct kcore_list *, void *, size_t, int type);
9197  #endif
9198  
9199 +struct vx_info;
9200 +struct nx_info;
9201 +
9202  union proc_op {
9203         int (*proc_get_link)(struct inode *, struct path *);
9204         int (*proc_read)(struct task_struct *task, char *page);
9205         int (*proc_show)(struct seq_file *m,
9206                 struct pid_namespace *ns, struct pid *pid,
9207                 struct task_struct *task);
9208 +       int (*proc_vs_read)(char *page);
9209 +       int (*proc_vxi_read)(struct vx_info *vxi, char *page);
9210 +       int (*proc_nxi_read)(struct nx_info *nxi, char *page);
9211  };
9212  
9213  struct ctl_table_header;
9214 @@ -263,6 +270,7 @@ struct ctl_table;
9215  
9216  struct proc_inode {
9217         struct pid *pid;
9218 +       int vx_flags;
9219         int fd;
9220         union proc_op op;
9221         struct proc_dir_entry *pde;
9222 diff -NurpP --minimal linux-2.6.38-rc8/include/linux/quotaops.h linux-2.6.38-rc8-vs2.3.0.37-rc6/include/linux/quotaops.h
9223 --- linux-2.6.38-rc8/include/linux/quotaops.h   2011-03-10 17:09:25.000000000 +0100
9224 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/include/linux/quotaops.h    2011-01-29 02:01:07.000000000 +0100
9225 @@ -8,6 +8,7 @@
9226  #define _LINUX_QUOTAOPS_
9227  
9228  #include <linux/fs.h>
9229 +#include <linux/vs_dlimit.h>
9230  
9231  #define DQUOT_SPACE_WARN       0x1
9232  #define DQUOT_SPACE_RESERVE    0x2
9233 @@ -204,11 +205,12 @@ static inline void dquot_drop(struct ino
9234  
9235  static inline int dquot_alloc_inode(const struct inode *inode)
9236  {
9237 -       return 0;
9238 +       return dl_alloc_inode(inode);
9239  }
9240  
9241  static inline void dquot_free_inode(const struct inode *inode)
9242  {
9243 +       dl_free_inode(inode);
9244  }
9245  
9246  static inline int dquot_transfer(struct inode *inode, struct iattr *iattr)
9247 @@ -219,6 +221,10 @@ static inline int dquot_transfer(struct 
9248  static inline int __dquot_alloc_space(struct inode *inode, qsize_t number,
9249                 int flags)
9250  {
9251 +       int ret = 0;
9252 +
9253 +       if ((ret = dl_alloc_space(inode, number)))
9254 +               return ret;
9255         if (!(flags & DQUOT_SPACE_RESERVE))
9256                 inode_add_bytes(inode, number);
9257         return 0;
9258 @@ -229,6 +235,7 @@ static inline void __dquot_free_space(st
9259  {
9260         if (!(flags & DQUOT_SPACE_RESERVE))
9261                 inode_sub_bytes(inode, number);
9262 +       dl_free_space(inode, number);
9263  }
9264  
9265  static inline int dquot_claim_space_nodirty(struct inode *inode, qsize_t number)
9266 diff -NurpP --minimal linux-2.6.38-rc8/include/linux/reboot.h linux-2.6.38-rc8-vs2.3.0.37-rc6/include/linux/reboot.h
9267 --- linux-2.6.38-rc8/include/linux/reboot.h     2010-07-07 18:31:56.000000000 +0200
9268 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/include/linux/reboot.h      2011-01-29 02:01:07.000000000 +0100
9269 @@ -33,6 +33,7 @@
9270  #define        LINUX_REBOOT_CMD_RESTART2       0xA1B2C3D4
9271  #define        LINUX_REBOOT_CMD_SW_SUSPEND     0xD000FCE2
9272  #define        LINUX_REBOOT_CMD_KEXEC          0x45584543
9273 +#define        LINUX_REBOOT_CMD_OOM            0xDEADBEEF
9274  
9275  
9276  #ifdef __KERNEL__
9277 diff -NurpP --minimal linux-2.6.38-rc8/include/linux/reiserfs_fs.h linux-2.6.38-rc8-vs2.3.0.37-rc6/include/linux/reiserfs_fs.h
9278 --- linux-2.6.38-rc8/include/linux/reiserfs_fs.h        2011-01-05 21:50:32.000000000 +0100
9279 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/include/linux/reiserfs_fs.h 2011-01-29 02:01:07.000000000 +0100
9280 @@ -976,6 +976,11 @@ struct stat_data_v1 {
9281  #define REISERFS_COMPR_FL     FS_COMPR_FL
9282  #define REISERFS_NOTAIL_FL    FS_NOTAIL_FL
9283  
9284 +/* unfortunately reiserfs sdattr is only 16 bit */
9285 +#define REISERFS_IXUNLINK_FL  (FS_IXUNLINK_FL >> 16)
9286 +#define REISERFS_BARRIER_FL   (FS_BARRIER_FL >> 16)
9287 +#define REISERFS_COW_FL       (FS_COW_FL >> 16)
9288 +
9289  /* persistent flags that file inherits from the parent directory */
9290  #define REISERFS_INHERIT_MASK ( REISERFS_IMMUTABLE_FL |        \
9291                                 REISERFS_SYNC_FL |      \
9292 @@ -985,6 +990,9 @@ struct stat_data_v1 {
9293                                 REISERFS_COMPR_FL |     \
9294                                 REISERFS_NOTAIL_FL )
9295  
9296 +#define REISERFS_FL_USER_VISIBLE       0x80FF
9297 +#define REISERFS_FL_USER_MODIFIABLE    0x80FF
9298 +
9299  /* Stat Data on disk (reiserfs version of UFS disk inode minus the
9300     address blocks) */
9301  struct stat_data {
9302 @@ -2070,6 +2078,7 @@ static inline void reiserfs_update_sd(st
9303  void sd_attrs_to_i_attrs(__u16 sd_attrs, struct inode *inode);
9304  void i_attrs_to_sd_attrs(struct inode *inode, __u16 * sd_attrs);
9305  int reiserfs_setattr(struct dentry *dentry, struct iattr *attr);
9306 +int reiserfs_sync_flags(struct inode *inode, int, int);
9307  
9308  int __reiserfs_write_begin(struct page *page, unsigned from, unsigned len);
9309  
9310 diff -NurpP --minimal linux-2.6.38-rc8/include/linux/reiserfs_fs_sb.h linux-2.6.38-rc8-vs2.3.0.37-rc6/include/linux/reiserfs_fs_sb.h
9311 --- linux-2.6.38-rc8/include/linux/reiserfs_fs_sb.h     2010-02-25 11:52:07.000000000 +0100
9312 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/include/linux/reiserfs_fs_sb.h      2011-01-29 02:01:07.000000000 +0100
9313 @@ -476,6 +476,7 @@ enum reiserfs_mount_options {
9314         REISERFS_EXPOSE_PRIVROOT,
9315         REISERFS_BARRIER_NONE,
9316         REISERFS_BARRIER_FLUSH,
9317 +       REISERFS_TAGGED,
9318  
9319         /* Actions on error */
9320         REISERFS_ERROR_PANIC,
9321 diff -NurpP --minimal linux-2.6.38-rc8/include/linux/sched.h linux-2.6.38-rc8-vs2.3.0.37-rc6/include/linux/sched.h
9322 --- linux-2.6.38-rc8/include/linux/sched.h      2011-03-10 17:09:25.000000000 +0100
9323 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/include/linux/sched.h       2011-03-07 16:53:28.000000000 +0100
9324 @@ -1373,6 +1373,14 @@ struct task_struct {
9325  #endif
9326         seccomp_t seccomp;
9327  
9328 +/* vserver context data */
9329 +       struct vx_info *vx_info;
9330 +       struct nx_info *nx_info;
9331 +
9332 +       xid_t xid;
9333 +       nid_t nid;
9334 +       tag_t tag;
9335 +
9336  /* Thread group tracking */
9337         u32 parent_exec_id;
9338         u32 self_exec_id;
9339 @@ -1607,6 +1615,11 @@ struct pid_namespace;
9340  pid_t __task_pid_nr_ns(struct task_struct *task, enum pid_type type,
9341                         struct pid_namespace *ns);
9342  
9343 +#include <linux/vserver/base.h>
9344 +#include <linux/vserver/context.h>
9345 +#include <linux/vserver/debug.h>
9346 +#include <linux/vserver/pid.h>
9347 +
9348  static inline pid_t task_pid_nr(struct task_struct *tsk)
9349  {
9350         return tsk->pid;
9351 @@ -1620,7 +1633,8 @@ static inline pid_t task_pid_nr_ns(struc
9352  
9353  static inline pid_t task_pid_vnr(struct task_struct *tsk)
9354  {
9355 -       return __task_pid_nr_ns(tsk, PIDTYPE_PID, NULL);
9356 +       // return __task_pid_nr_ns(tsk, PIDTYPE_PID, NULL);
9357 +       return vx_map_pid(__task_pid_nr_ns(tsk, PIDTYPE_PID, NULL));
9358  }
9359  
9360  
9361 @@ -1633,7 +1647,7 @@ pid_t task_tgid_nr_ns(struct task_struct
9362  
9363  static inline pid_t task_tgid_vnr(struct task_struct *tsk)
9364  {
9365 -       return pid_vnr(task_tgid(tsk));
9366 +       return vx_map_tgid(pid_vnr(task_tgid(tsk)));
9367  }
9368  
9369  
9370 diff -NurpP --minimal linux-2.6.38-rc8/include/linux/shmem_fs.h linux-2.6.38-rc8-vs2.3.0.37-rc6/include/linux/shmem_fs.h
9371 --- linux-2.6.38-rc8/include/linux/shmem_fs.h   2010-10-21 13:07:55.000000000 +0200
9372 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/include/linux/shmem_fs.h    2011-01-29 02:01:07.000000000 +0100
9373 @@ -9,6 +9,9 @@
9374  
9375  #define SHMEM_NR_DIRECT 16
9376  
9377 +#define TMPFS_SUPER_MAGIC      0x01021994
9378 +
9379 +
9380  struct shmem_inode_info {
9381         spinlock_t              lock;
9382         unsigned long           flags;
9383 diff -NurpP --minimal linux-2.6.38-rc8/include/linux/stat.h linux-2.6.38-rc8-vs2.3.0.37-rc6/include/linux/stat.h
9384 --- linux-2.6.38-rc8/include/linux/stat.h       2008-12-25 00:26:37.000000000 +0100
9385 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/include/linux/stat.h        2011-01-29 02:01:07.000000000 +0100
9386 @@ -66,6 +66,7 @@ struct kstat {
9387         unsigned int    nlink;
9388         uid_t           uid;
9389         gid_t           gid;
9390 +       tag_t           tag;
9391         dev_t           rdev;
9392         loff_t          size;
9393         struct timespec  atime;
9394 diff -NurpP --minimal linux-2.6.38-rc8/include/linux/sunrpc/auth.h linux-2.6.38-rc8-vs2.3.0.37-rc6/include/linux/sunrpc/auth.h
9395 --- linux-2.6.38-rc8/include/linux/sunrpc/auth.h        2011-03-10 17:09:26.000000000 +0100
9396 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/include/linux/sunrpc/auth.h 2011-01-29 02:01:07.000000000 +0100
9397 @@ -25,6 +25,7 @@
9398  struct auth_cred {
9399         uid_t   uid;
9400         gid_t   gid;
9401 +       tag_t   tag;
9402         struct group_info *group_info;
9403         unsigned char machine_cred : 1;
9404  };
9405 diff -NurpP --minimal linux-2.6.38-rc8/include/linux/sunrpc/clnt.h linux-2.6.38-rc8-vs2.3.0.37-rc6/include/linux/sunrpc/clnt.h
9406 --- linux-2.6.38-rc8/include/linux/sunrpc/clnt.h        2011-03-10 17:09:26.000000000 +0100
9407 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/include/linux/sunrpc/clnt.h 2011-01-29 02:01:07.000000000 +0100
9408 @@ -49,7 +49,8 @@ struct rpc_clnt {
9409         unsigned int            cl_softrtry : 1,/* soft timeouts */
9410                                 cl_discrtry : 1,/* disconnect before retry */
9411                                 cl_autobind : 1,/* use getport() */
9412 -                               cl_chatty   : 1;/* be verbose */
9413 +                               cl_chatty   : 1,/* be verbose */
9414 +                               cl_tag      : 1;/* context tagging */
9415  
9416         struct rpc_rtt *        cl_rtt;         /* RTO estimator data */
9417         const struct rpc_timeout *cl_timeout;   /* Timeout strategy */
9418 diff -NurpP --minimal linux-2.6.38-rc8/include/linux/syscalls.h linux-2.6.38-rc8-vs2.3.0.37-rc6/include/linux/syscalls.h
9419 --- linux-2.6.38-rc8/include/linux/syscalls.h   2011-03-10 17:09:26.000000000 +0100
9420 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/include/linux/syscalls.h    2011-02-17 02:17:51.000000000 +0100
9421 @@ -478,6 +478,8 @@ asmlinkage long sys_symlink(const char _
9422  asmlinkage long sys_unlink(const char __user *pathname);
9423  asmlinkage long sys_rename(const char __user *oldname,
9424                                 const char __user *newname);
9425 +asmlinkage long sys_copyfile(const char __user *from, const char __user *to,
9426 +                               umode_t mode);
9427  asmlinkage long sys_chmod(const char __user *filename, mode_t mode);
9428  asmlinkage long sys_fchmod(unsigned int fd, mode_t mode);
9429  
9430 diff -NurpP --minimal linux-2.6.38-rc8/include/linux/sysctl.h linux-2.6.38-rc8-vs2.3.0.37-rc6/include/linux/sysctl.h
9431 --- linux-2.6.38-rc8/include/linux/sysctl.h     2010-08-02 16:52:56.000000000 +0200
9432 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/include/linux/sysctl.h      2011-01-29 02:01:07.000000000 +0100
9433 @@ -60,6 +60,7 @@ enum
9434         CTL_ABI=9,              /* Binary emulation */
9435         CTL_CPU=10,             /* CPU stuff (speed scaling, etc) */
9436         CTL_ARLAN=254,          /* arlan wireless driver */
9437 +       CTL_VSERVER=4242,       /* Linux-VServer debug */
9438         CTL_S390DBF=5677,       /* s390 debug */
9439         CTL_SUNRPC=7249,        /* sunrpc debug */
9440         CTL_PM=9899,            /* frv power management */
9441 @@ -94,6 +95,7 @@ enum
9442  
9443         KERN_PANIC=15,          /* int: panic timeout */
9444         KERN_REALROOTDEV=16,    /* real root device to mount after initrd */
9445 +       KERN_VSHELPER=17,       /* string: path to vshelper policy agent */
9446  
9447         KERN_SPARC_REBOOT=21,   /* reboot command on Sparc */
9448         KERN_CTLALTDEL=22,      /* int: allow ctl-alt-del to reboot */
9449 diff -NurpP --minimal linux-2.6.38-rc8/include/linux/sysfs.h linux-2.6.38-rc8-vs2.3.0.37-rc6/include/linux/sysfs.h
9450 --- linux-2.6.38-rc8/include/linux/sysfs.h      2011-01-05 21:50:34.000000000 +0100
9451 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/include/linux/sysfs.h       2011-01-29 02:01:07.000000000 +0100
9452 @@ -19,6 +19,8 @@
9453  #include <linux/kobject_ns.h>
9454  #include <asm/atomic.h>
9455  
9456 +#define SYSFS_SUPER_MAGIC      0x62656572
9457 +
9458  struct kobject;
9459  struct module;
9460  enum kobj_ns_type;
9461 diff -NurpP --minimal linux-2.6.38-rc8/include/linux/time.h linux-2.6.38-rc8-vs2.3.0.37-rc6/include/linux/time.h
9462 --- linux-2.6.38-rc8/include/linux/time.h       2011-03-10 17:09:26.000000000 +0100
9463 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/include/linux/time.h        2011-01-29 02:01:07.000000000 +0100
9464 @@ -254,6 +254,9 @@ static __always_inline void timespec_add
9465         a->tv_sec += __iter_div_u64_rem(a->tv_nsec + ns, NSEC_PER_SEC, &ns);
9466         a->tv_nsec = ns;
9467  }
9468 +
9469 +#include <linux/vs_time.h>
9470 +
9471  #endif /* __KERNEL__ */
9472  
9473  #define NFDBITS                        __NFDBITS
9474 diff -NurpP --minimal linux-2.6.38-rc8/include/linux/types.h linux-2.6.38-rc8-vs2.3.0.37-rc6/include/linux/types.h
9475 --- linux-2.6.38-rc8/include/linux/types.h      2011-01-05 21:50:34.000000000 +0100
9476 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/include/linux/types.h       2011-01-29 02:01:07.000000000 +0100
9477 @@ -40,6 +40,9 @@ typedef __kernel_uid32_t      uid_t;
9478  typedef __kernel_gid32_t       gid_t;
9479  typedef __kernel_uid16_t        uid16_t;
9480  typedef __kernel_gid16_t        gid16_t;
9481 +typedef unsigned int           xid_t;
9482 +typedef unsigned int           nid_t;
9483 +typedef unsigned int           tag_t;
9484  
9485  typedef unsigned long          uintptr_t;
9486  
9487 diff -NurpP --minimal linux-2.6.38-rc8/include/linux/vroot.h linux-2.6.38-rc8-vs2.3.0.37-rc6/include/linux/vroot.h
9488 --- linux-2.6.38-rc8/include/linux/vroot.h      1970-01-01 01:00:00.000000000 +0100
9489 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/include/linux/vroot.h       2011-01-29 02:01:07.000000000 +0100
9490 @@ -0,0 +1,51 @@
9491 +
9492 +/*
9493 + * include/linux/vroot.h
9494 + *
9495 + * written by Herbert Pötzl, 9/11/2002
9496 + * ported to 2.6 by Herbert Pötzl, 30/12/2004
9497 + *
9498 + * Copyright (C) 2002-2007 by Herbert Pötzl.
9499 + * Redistribution of this file is permitted under the
9500 + * GNU General Public License.
9501 + */
9502 +
9503 +#ifndef _LINUX_VROOT_H
9504 +#define _LINUX_VROOT_H
9505 +
9506 +
9507 +#ifdef __KERNEL__
9508 +
9509 +/* Possible states of device */
9510 +enum {
9511 +       Vr_unbound,
9512 +       Vr_bound,
9513 +};
9514 +
9515 +struct vroot_device {
9516 +       int             vr_number;
9517 +       int             vr_refcnt;
9518 +
9519 +       struct semaphore        vr_ctl_mutex;
9520 +       struct block_device    *vr_device;
9521 +       int                     vr_state;
9522 +};
9523 +
9524 +
9525 +typedef struct block_device *(vroot_grb_func)(struct block_device *);
9526 +
9527 +extern int register_vroot_grb(vroot_grb_func *);
9528 +extern int unregister_vroot_grb(vroot_grb_func *);
9529 +
9530 +#endif /* __KERNEL__ */
9531 +
9532 +#define MAX_VROOT_DEFAULT      8
9533 +
9534 +/*
9535 + * IOCTL commands --- we will commandeer 0x56 ('V')
9536 + */
9537 +
9538 +#define VROOT_SET_DEV          0x5600
9539 +#define VROOT_CLR_DEV          0x5601
9540 +
9541 +#endif /* _LINUX_VROOT_H */
9542 diff -NurpP --minimal linux-2.6.38-rc8/include/linux/vs_base.h linux-2.6.38-rc8-vs2.3.0.37-rc6/include/linux/vs_base.h
9543 --- linux-2.6.38-rc8/include/linux/vs_base.h    1970-01-01 01:00:00.000000000 +0100
9544 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/include/linux/vs_base.h     2011-01-29 02:01:07.000000000 +0100
9545 @@ -0,0 +1,10 @@
9546 +#ifndef _VS_BASE_H
9547 +#define _VS_BASE_H
9548 +
9549 +#include "vserver/base.h"
9550 +#include "vserver/check.h"
9551 +#include "vserver/debug.h"
9552 +
9553 +#else
9554 +#warning duplicate inclusion
9555 +#endif
9556 diff -NurpP --minimal linux-2.6.38-rc8/include/linux/vs_context.h linux-2.6.38-rc8-vs2.3.0.37-rc6/include/linux/vs_context.h
9557 --- linux-2.6.38-rc8/include/linux/vs_context.h 1970-01-01 01:00:00.000000000 +0100
9558 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/include/linux/vs_context.h  2011-01-29 02:01:07.000000000 +0100
9559 @@ -0,0 +1,242 @@
9560 +#ifndef _VS_CONTEXT_H
9561 +#define _VS_CONTEXT_H
9562 +
9563 +#include "vserver/base.h"
9564 +#include "vserver/check.h"
9565 +#include "vserver/context.h"
9566 +#include "vserver/history.h"
9567 +#include "vserver/debug.h"
9568 +
9569 +#include <linux/sched.h>
9570 +
9571 +
9572 +#define get_vx_info(i) __get_vx_info(i, __FILE__, __LINE__, __HERE__)
9573 +
9574 +static inline struct vx_info *__get_vx_info(struct vx_info *vxi,
9575 +       const char *_file, int _line, void *_here)
9576 +{
9577 +       if (!vxi)
9578 +               return NULL;
9579 +
9580 +       vxlprintk(VXD_CBIT(xid, 2), "get_vx_info(%p[#%d.%d])",
9581 +               vxi, vxi ? vxi->vx_id : 0,
9582 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
9583 +               _file, _line);
9584 +       __vxh_get_vx_info(vxi, _here);
9585 +
9586 +       atomic_inc(&vxi->vx_usecnt);
9587 +       return vxi;
9588 +}
9589 +
9590 +
9591 +extern void free_vx_info(struct vx_info *);
9592 +
9593 +#define put_vx_info(i) __put_vx_info(i, __FILE__, __LINE__, __HERE__)
9594 +
9595 +static inline void __put_vx_info(struct vx_info *vxi,
9596 +       const char *_file, int _line, void *_here)
9597 +{
9598 +       if (!vxi)
9599 +               return;
9600 +
9601 +       vxlprintk(VXD_CBIT(xid, 2), "put_vx_info(%p[#%d.%d])",
9602 +               vxi, vxi ? vxi->vx_id : 0,
9603 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
9604 +               _file, _line);
9605 +       __vxh_put_vx_info(vxi, _here);
9606 +
9607 +       if (atomic_dec_and_test(&vxi->vx_usecnt))
9608 +               free_vx_info(vxi);
9609 +}
9610 +
9611 +
9612 +#define init_vx_info(p, i) \
9613 +       __init_vx_info(p, i, __FILE__, __LINE__, __HERE__)
9614 +
9615 +static inline void __init_vx_info(struct vx_info **vxp, struct vx_info *vxi,
9616 +       const char *_file, int _line, void *_here)
9617 +{
9618 +       if (vxi) {
9619 +               vxlprintk(VXD_CBIT(xid, 3),
9620 +                       "init_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_init_vx_info(vxi, vxp, _here);
9625 +
9626 +               atomic_inc(&vxi->vx_usecnt);
9627 +       }
9628 +       *vxp = vxi;
9629 +}
9630 +
9631 +
9632 +#define set_vx_info(p, i) \
9633 +       __set_vx_info(p, i, __FILE__, __LINE__, __HERE__)
9634 +
9635 +static inline void __set_vx_info(struct vx_info **vxp, struct vx_info *vxi,
9636 +       const char *_file, int _line, void *_here)
9637 +{
9638 +       struct vx_info *vxo;
9639 +
9640 +       if (!vxi)
9641 +               return;
9642 +
9643 +       vxlprintk(VXD_CBIT(xid, 3), "set_vx_info(%p[#%d.%d])",
9644 +               vxi, vxi ? vxi->vx_id : 0,
9645 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
9646 +               _file, _line);
9647 +       __vxh_set_vx_info(vxi, vxp, _here);
9648 +
9649 +       atomic_inc(&vxi->vx_usecnt);
9650 +       vxo = xchg(vxp, vxi);
9651 +       BUG_ON(vxo);
9652 +}
9653 +
9654 +
9655 +#define clr_vx_info(p) __clr_vx_info(p, __FILE__, __LINE__, __HERE__)
9656 +
9657 +static inline void __clr_vx_info(struct vx_info **vxp,
9658 +       const char *_file, int _line, void *_here)
9659 +{
9660 +       struct vx_info *vxo;
9661 +
9662 +       vxo = xchg(vxp, NULL);
9663 +       if (!vxo)
9664 +               return;
9665 +
9666 +       vxlprintk(VXD_CBIT(xid, 3), "clr_vx_info(%p[#%d.%d])",
9667 +               vxo, vxo ? vxo->vx_id : 0,
9668 +               vxo ? atomic_read(&vxo->vx_usecnt) : 0,
9669 +               _file, _line);
9670 +       __vxh_clr_vx_info(vxo, vxp, _here);
9671 +
9672 +       if (atomic_dec_and_test(&vxo->vx_usecnt))
9673 +               free_vx_info(vxo);
9674 +}
9675 +
9676 +
9677 +#define claim_vx_info(v, p) \
9678 +       __claim_vx_info(v, p, __FILE__, __LINE__, __HERE__)
9679 +
9680 +static inline void __claim_vx_info(struct vx_info *vxi,
9681 +       struct task_struct *task,
9682 +       const char *_file, int _line, void *_here)
9683 +{
9684 +       vxlprintk(VXD_CBIT(xid, 3), "claim_vx_info(%p[#%d.%d.%d]) %p",
9685 +               vxi, vxi ? vxi->vx_id : 0,
9686 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
9687 +               vxi ? atomic_read(&vxi->vx_tasks) : 0,
9688 +               task, _file, _line);
9689 +       __vxh_claim_vx_info(vxi, task, _here);
9690 +
9691 +       atomic_inc(&vxi->vx_tasks);
9692 +}
9693 +
9694 +
9695 +extern void unhash_vx_info(struct vx_info *);
9696 +
9697 +#define release_vx_info(v, p) \
9698 +       __release_vx_info(v, p, __FILE__, __LINE__, __HERE__)
9699 +
9700 +static inline void __release_vx_info(struct vx_info *vxi,
9701 +       struct task_struct *task,
9702 +       const char *_file, int _line, void *_here)
9703 +{
9704 +       vxlprintk(VXD_CBIT(xid, 3), "release_vx_info(%p[#%d.%d.%d]) %p",
9705 +               vxi, vxi ? vxi->vx_id : 0,
9706 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
9707 +               vxi ? atomic_read(&vxi->vx_tasks) : 0,
9708 +               task, _file, _line);
9709 +       __vxh_release_vx_info(vxi, task, _here);
9710 +
9711 +       might_sleep();
9712 +
9713 +       if (atomic_dec_and_test(&vxi->vx_tasks))
9714 +               unhash_vx_info(vxi);
9715 +}
9716 +
9717 +
9718 +#define task_get_vx_info(p) \
9719 +       __task_get_vx_info(p, __FILE__, __LINE__, __HERE__)
9720 +
9721 +static inline struct vx_info *__task_get_vx_info(struct task_struct *p,
9722 +       const char *_file, int _line, void *_here)
9723 +{
9724 +       struct vx_info *vxi;
9725 +
9726 +       task_lock(p);
9727 +       vxlprintk(VXD_CBIT(xid, 5), "task_get_vx_info(%p)",
9728 +               p, _file, _line);
9729 +       vxi = __get_vx_info(p->vx_info, _file, _line, _here);
9730 +       task_unlock(p);
9731 +       return vxi;
9732 +}
9733 +
9734 +
9735 +static inline void __wakeup_vx_info(struct vx_info *vxi)
9736 +{
9737 +       if (waitqueue_active(&vxi->vx_wait))
9738 +               wake_up_interruptible(&vxi->vx_wait);
9739 +}
9740 +
9741 +
9742 +#define enter_vx_info(v, s) __enter_vx_info(v, s, __FILE__, __LINE__)
9743 +
9744 +static inline void __enter_vx_info(struct vx_info *vxi,
9745 +       struct vx_info_save *vxis, const char *_file, int _line)
9746 +{
9747 +       vxlprintk(VXD_CBIT(xid, 5), "enter_vx_info(%p[#%d],%p) %p[#%d,%p]",
9748 +               vxi, vxi ? vxi->vx_id : 0, vxis, current,
9749 +               current->xid, current->vx_info, _file, _line);
9750 +       vxis->vxi = xchg(&current->vx_info, vxi);
9751 +       vxis->xid = current->xid;
9752 +       current->xid = vxi ? vxi->vx_id : 0;
9753 +}
9754 +
9755 +#define leave_vx_info(s) __leave_vx_info(s, __FILE__, __LINE__)
9756 +
9757 +static inline void __leave_vx_info(struct vx_info_save *vxis,
9758 +       const char *_file, int _line)
9759 +{
9760 +       vxlprintk(VXD_CBIT(xid, 5), "leave_vx_info(%p[#%d,%p]) %p[#%d,%p]",
9761 +               vxis, vxis->xid, vxis->vxi, current,
9762 +               current->xid, current->vx_info, _file, _line);
9763 +       (void)xchg(&current->vx_info, vxis->vxi);
9764 +       current->xid = vxis->xid;
9765 +}
9766 +
9767 +
9768 +static inline void __enter_vx_admin(struct vx_info_save *vxis)
9769 +{
9770 +       vxis->vxi = xchg(&current->vx_info, NULL);
9771 +       vxis->xid = xchg(&current->xid, (xid_t)0);
9772 +}
9773 +
9774 +static inline void __leave_vx_admin(struct vx_info_save *vxis)
9775 +{
9776 +       (void)xchg(&current->xid, vxis->xid);
9777 +       (void)xchg(&current->vx_info, vxis->vxi);
9778 +}
9779 +
9780 +#define task_is_init(p) \
9781 +       __task_is_init(p, __FILE__, __LINE__, __HERE__)
9782 +
9783 +static inline int __task_is_init(struct task_struct *p,
9784 +       const char *_file, int _line, void *_here)
9785 +{
9786 +       int is_init = is_global_init(p);
9787 +
9788 +       task_lock(p);
9789 +       if (p->vx_info)
9790 +               is_init = p->vx_info->vx_initpid == p->pid;
9791 +       task_unlock(p);
9792 +       return is_init;
9793 +}
9794 +
9795 +extern void exit_vx_info(struct task_struct *, int);
9796 +extern void exit_vx_info_early(struct task_struct *, int);
9797 +
9798 +
9799 +#else
9800 +#warning duplicate inclusion
9801 +#endif
9802 diff -NurpP --minimal linux-2.6.38-rc8/include/linux/vs_cowbl.h linux-2.6.38-rc8-vs2.3.0.37-rc6/include/linux/vs_cowbl.h
9803 --- linux-2.6.38-rc8/include/linux/vs_cowbl.h   1970-01-01 01:00:00.000000000 +0100
9804 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/include/linux/vs_cowbl.h    2011-01-29 02:01:07.000000000 +0100
9805 @@ -0,0 +1,48 @@
9806 +#ifndef _VS_COWBL_H
9807 +#define _VS_COWBL_H
9808 +
9809 +#include <linux/fs.h>
9810 +#include <linux/dcache.h>
9811 +#include <linux/namei.h>
9812 +#include <linux/slab.h>
9813 +
9814 +extern struct dentry *cow_break_link(const char *pathname);
9815 +
9816 +static inline int cow_check_and_break(struct path *path)
9817 +{
9818 +       struct inode *inode = path->dentry->d_inode;
9819 +       int error = 0;
9820 +
9821 +       /* do we need this check? */
9822 +       if (IS_RDONLY(inode))
9823 +               return -EROFS;
9824 +
9825 +       if (IS_COW(inode)) {
9826 +               if (IS_COW_LINK(inode)) {
9827 +                       struct dentry *new_dentry, *old_dentry = path->dentry;
9828 +                       char *pp, *buf;
9829 +
9830 +                       buf = kmalloc(PATH_MAX, GFP_KERNEL);
9831 +                       if (!buf) {
9832 +                               return -ENOMEM;
9833 +                       }
9834 +                       pp = d_path(path, buf, PATH_MAX);
9835 +                       new_dentry = cow_break_link(pp);
9836 +                       kfree(buf);
9837 +                       if (!IS_ERR(new_dentry)) {
9838 +                               path->dentry = new_dentry;
9839 +                               dput(old_dentry);
9840 +                       } else
9841 +                               error = PTR_ERR(new_dentry);
9842 +               } else {
9843 +                       inode->i_flags &= ~(S_IXUNLINK | S_IMMUTABLE);
9844 +                       inode->i_ctime = CURRENT_TIME;
9845 +                       mark_inode_dirty(inode);
9846 +               }
9847 +       }
9848 +       return error;
9849 +}
9850 +
9851 +#else
9852 +#warning duplicate inclusion
9853 +#endif
9854 diff -NurpP --minimal linux-2.6.38-rc8/include/linux/vs_cvirt.h linux-2.6.38-rc8-vs2.3.0.37-rc6/include/linux/vs_cvirt.h
9855 --- linux-2.6.38-rc8/include/linux/vs_cvirt.h   1970-01-01 01:00:00.000000000 +0100
9856 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/include/linux/vs_cvirt.h    2011-01-29 02:01:07.000000000 +0100
9857 @@ -0,0 +1,50 @@
9858 +#ifndef _VS_CVIRT_H
9859 +#define _VS_CVIRT_H
9860 +
9861 +#include "vserver/cvirt.h"
9862 +#include "vserver/context.h"
9863 +#include "vserver/base.h"
9864 +#include "vserver/check.h"
9865 +#include "vserver/debug.h"
9866 +
9867 +
9868 +static inline void vx_activate_task(struct task_struct *p)
9869 +{
9870 +       struct vx_info *vxi;
9871 +
9872 +       if ((vxi = p->vx_info)) {
9873 +               vx_update_load(vxi);
9874 +               atomic_inc(&vxi->cvirt.nr_running);
9875 +       }
9876 +}
9877 +
9878 +static inline void vx_deactivate_task(struct task_struct *p)
9879 +{
9880 +       struct vx_info *vxi;
9881 +
9882 +       if ((vxi = p->vx_info)) {
9883 +               vx_update_load(vxi);
9884 +               atomic_dec(&vxi->cvirt.nr_running);
9885 +       }
9886 +}
9887 +
9888 +static inline void vx_uninterruptible_inc(struct task_struct *p)
9889 +{
9890 +       struct vx_info *vxi;
9891 +
9892 +       if ((vxi = p->vx_info))
9893 +               atomic_inc(&vxi->cvirt.nr_uninterruptible);
9894 +}
9895 +
9896 +static inline void vx_uninterruptible_dec(struct task_struct *p)
9897 +{
9898 +       struct vx_info *vxi;
9899 +
9900 +       if ((vxi = p->vx_info))
9901 +               atomic_dec(&vxi->cvirt.nr_uninterruptible);
9902 +}
9903 +
9904 +
9905 +#else
9906 +#warning duplicate inclusion
9907 +#endif
9908 diff -NurpP --minimal linux-2.6.38-rc8/include/linux/vs_device.h linux-2.6.38-rc8-vs2.3.0.37-rc6/include/linux/vs_device.h
9909 --- linux-2.6.38-rc8/include/linux/vs_device.h  1970-01-01 01:00:00.000000000 +0100
9910 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/include/linux/vs_device.h   2011-01-29 02:01:07.000000000 +0100
9911 @@ -0,0 +1,45 @@
9912 +#ifndef _VS_DEVICE_H
9913 +#define _VS_DEVICE_H
9914 +
9915 +#include "vserver/base.h"
9916 +#include "vserver/device.h"
9917 +#include "vserver/debug.h"
9918 +
9919 +
9920 +#ifdef CONFIG_VSERVER_DEVICE
9921 +
9922 +int vs_map_device(struct vx_info *, dev_t, dev_t *, umode_t);
9923 +
9924 +#define vs_device_perm(v, d, m, p) \
9925 +       ((vs_map_device(current_vx_info(), d, NULL, m) & (p)) == (p))
9926 +
9927 +#else
9928 +
9929 +static inline
9930 +int vs_map_device(struct vx_info *vxi,
9931 +       dev_t device, dev_t *target, umode_t mode)
9932 +{
9933 +       if (target)
9934 +               *target = device;
9935 +       return ~0;
9936 +}
9937 +
9938 +#define vs_device_perm(v, d, m, p) ((p) == (p))
9939 +
9940 +#endif
9941 +
9942 +
9943 +#define vs_map_chrdev(d, t, p) \
9944 +       ((vs_map_device(current_vx_info(), d, t, S_IFCHR) & (p)) == (p))
9945 +#define vs_map_blkdev(d, t, p) \
9946 +       ((vs_map_device(current_vx_info(), d, t, S_IFBLK) & (p)) == (p))
9947 +
9948 +#define vs_chrdev_perm(d, p) \
9949 +       vs_device_perm(current_vx_info(), d, S_IFCHR, p)
9950 +#define vs_blkdev_perm(d, p) \
9951 +       vs_device_perm(current_vx_info(), d, S_IFBLK, p)
9952 +
9953 +
9954 +#else
9955 +#warning duplicate inclusion
9956 +#endif
9957 diff -NurpP --minimal linux-2.6.38-rc8/include/linux/vs_dlimit.h linux-2.6.38-rc8-vs2.3.0.37-rc6/include/linux/vs_dlimit.h
9958 --- linux-2.6.38-rc8/include/linux/vs_dlimit.h  1970-01-01 01:00:00.000000000 +0100
9959 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/include/linux/vs_dlimit.h   2011-01-29 02:01:07.000000000 +0100
9960 @@ -0,0 +1,215 @@
9961 +#ifndef _VS_DLIMIT_H
9962 +#define _VS_DLIMIT_H
9963 +
9964 +#include <linux/fs.h>
9965 +
9966 +#include "vserver/dlimit.h"
9967 +#include "vserver/base.h"
9968 +#include "vserver/debug.h"
9969 +
9970 +
9971 +#define get_dl_info(i) __get_dl_info(i, __FILE__, __LINE__)
9972 +
9973 +static inline struct dl_info *__get_dl_info(struct dl_info *dli,
9974 +       const char *_file, int _line)
9975 +{
9976 +       if (!dli)
9977 +               return NULL;
9978 +       vxlprintk(VXD_CBIT(dlim, 4), "get_dl_info(%p[#%d.%d])",
9979 +               dli, dli ? dli->dl_tag : 0,
9980 +               dli ? atomic_read(&dli->dl_usecnt) : 0,
9981 +               _file, _line);
9982 +       atomic_inc(&dli->dl_usecnt);
9983 +       return dli;
9984 +}
9985 +
9986 +
9987 +#define free_dl_info(i) \
9988 +       call_rcu(&(i)->dl_rcu, rcu_free_dl_info)
9989 +
9990 +#define put_dl_info(i) __put_dl_info(i, __FILE__, __LINE__)
9991 +
9992 +static inline void __put_dl_info(struct dl_info *dli,
9993 +       const char *_file, int _line)
9994 +{
9995 +       if (!dli)
9996 +               return;
9997 +       vxlprintk(VXD_CBIT(dlim, 4), "put_dl_info(%p[#%d.%d])",
9998 +               dli, dli ? dli->dl_tag : 0,
9999 +               dli ? atomic_read(&dli->dl_usecnt) : 0,
10000 +               _file, _line);
10001 +       if (atomic_dec_and_test(&dli->dl_usecnt))
10002 +               free_dl_info(dli);
10003 +}
10004 +
10005 +
10006 +#define __dlimit_char(d)       ((d) ? '*' : ' ')
10007 +
10008 +static inline int __dl_alloc_space(struct super_block *sb,
10009 +       tag_t tag, dlsize_t nr, const char *file, int line)
10010 +{
10011 +       struct dl_info *dli = NULL;
10012 +       int ret = 0;
10013 +
10014 +       if (nr == 0)
10015 +               goto out;
10016 +       dli = locate_dl_info(sb, tag);
10017 +       if (!dli)
10018 +               goto out;
10019 +
10020 +       spin_lock(&dli->dl_lock);
10021 +       ret = (dli->dl_space_used + nr > dli->dl_space_total);
10022 +       if (!ret)
10023 +               dli->dl_space_used += nr;
10024 +       spin_unlock(&dli->dl_lock);
10025 +       put_dl_info(dli);
10026 +out:
10027 +       vxlprintk(VXD_CBIT(dlim, 1),
10028 +               "ALLOC (%p,#%d)%c %lld bytes (%d)",
10029 +               sb, tag, __dlimit_char(dli), (long long)nr,
10030 +               ret, file, line);
10031 +       return ret ? -ENOSPC : 0;
10032 +}
10033 +
10034 +static inline void __dl_free_space(struct super_block *sb,
10035 +       tag_t tag, dlsize_t nr, const char *_file, int _line)
10036 +{
10037 +       struct dl_info *dli = NULL;
10038 +
10039 +       if (nr == 0)
10040 +               goto out;
10041 +       dli = locate_dl_info(sb, tag);
10042 +       if (!dli)
10043 +               goto out;
10044 +
10045 +       spin_lock(&dli->dl_lock);
10046 +       if (dli->dl_space_used > nr)
10047 +               dli->dl_space_used -= nr;
10048 +       else
10049 +               dli->dl_space_used = 0;
10050 +       spin_unlock(&dli->dl_lock);
10051 +       put_dl_info(dli);
10052 +out:
10053 +       vxlprintk(VXD_CBIT(dlim, 1),
10054 +               "FREE  (%p,#%d)%c %lld bytes",
10055 +               sb, tag, __dlimit_char(dli), (long long)nr,
10056 +               _file, _line);
10057 +}
10058 +
10059 +static inline int __dl_alloc_inode(struct super_block *sb,
10060 +       tag_t tag, const char *_file, int _line)
10061 +{
10062 +       struct dl_info *dli;
10063 +       int ret = 0;
10064 +
10065 +       dli = locate_dl_info(sb, tag);
10066 +       if (!dli)
10067 +               goto out;
10068 +
10069 +       spin_lock(&dli->dl_lock);
10070 +       dli->dl_inodes_used++;
10071 +       ret = (dli->dl_inodes_used > dli->dl_inodes_total);
10072 +       spin_unlock(&dli->dl_lock);
10073 +       put_dl_info(dli);
10074 +out:
10075 +       vxlprintk(VXD_CBIT(dlim, 0),
10076 +               "ALLOC (%p,#%d)%c inode (%d)",
10077 +               sb, tag, __dlimit_char(dli), ret, _file, _line);
10078 +       return ret ? -ENOSPC : 0;
10079 +}
10080 +
10081 +static inline void __dl_free_inode(struct super_block *sb,
10082 +       tag_t tag, const char *_file, int _line)
10083 +{
10084 +       struct dl_info *dli;
10085 +
10086 +       dli = locate_dl_info(sb, tag);
10087 +       if (!dli)
10088 +               goto out;
10089 +
10090 +       spin_lock(&dli->dl_lock);
10091 +       if (dli->dl_inodes_used > 1)
10092 +               dli->dl_inodes_used--;
10093 +       else
10094 +               dli->dl_inodes_used = 0;
10095 +       spin_unlock(&dli->dl_lock);
10096 +       put_dl_info(dli);
10097 +out:
10098 +       vxlprintk(VXD_CBIT(dlim, 0),
10099 +               "FREE  (%p,#%d)%c inode",
10100 +               sb, tag, __dlimit_char(dli), _file, _line);
10101 +}
10102 +
10103 +static inline void __dl_adjust_block(struct super_block *sb, tag_t tag,
10104 +       unsigned long long *free_blocks, unsigned long long *root_blocks,
10105 +       const char *_file, int _line)
10106 +{
10107 +       struct dl_info *dli;
10108 +       uint64_t broot, bfree;
10109 +
10110 +       dli = locate_dl_info(sb, tag);
10111 +       if (!dli)
10112 +               return;
10113 +
10114 +       spin_lock(&dli->dl_lock);
10115 +       broot = (dli->dl_space_total -
10116 +               (dli->dl_space_total >> 10) * dli->dl_nrlmult)
10117 +               >> sb->s_blocksize_bits;
10118 +       bfree = (dli->dl_space_total - dli->dl_space_used)
10119 +                       >> sb->s_blocksize_bits;
10120 +       spin_unlock(&dli->dl_lock);
10121 +
10122 +       vxlprintk(VXD_CBIT(dlim, 2),
10123 +               "ADJUST: %lld,%lld on %lld,%lld [mult=%d]",
10124 +               (long long)bfree, (long long)broot,
10125 +               *free_blocks, *root_blocks, dli->dl_nrlmult,
10126 +               _file, _line);
10127 +       if (free_blocks) {
10128 +               if (*free_blocks > bfree)
10129 +                       *free_blocks = bfree;
10130 +       }
10131 +       if (root_blocks) {
10132 +               if (*root_blocks > broot)
10133 +                       *root_blocks = broot;
10134 +       }
10135 +       put_dl_info(dli);
10136 +}
10137 +
10138 +#define dl_prealloc_space(in, bytes) \
10139 +       __dl_alloc_space((in)->i_sb, (in)->i_tag, (dlsize_t)(bytes), \
10140 +               __FILE__, __LINE__ )
10141 +
10142 +#define dl_alloc_space(in, bytes) \
10143 +       __dl_alloc_space((in)->i_sb, (in)->i_tag, (dlsize_t)(bytes), \
10144 +               __FILE__, __LINE__ )
10145 +
10146 +#define dl_reserve_space(in, bytes) \
10147 +       __dl_alloc_space((in)->i_sb, (in)->i_tag, (dlsize_t)(bytes), \
10148 +               __FILE__, __LINE__ )
10149 +
10150 +#define dl_claim_space(in, bytes) (0)
10151 +
10152 +#define dl_release_space(in, bytes) \
10153 +       __dl_free_space((in)->i_sb, (in)->i_tag, (dlsize_t)(bytes), \
10154 +               __FILE__, __LINE__ )
10155 +
10156 +#define dl_free_space(in, bytes) \
10157 +       __dl_free_space((in)->i_sb, (in)->i_tag, (dlsize_t)(bytes), \
10158 +               __FILE__, __LINE__ )
10159 +
10160 +
10161 +
10162 +#define dl_alloc_inode(in) \
10163 +       __dl_alloc_inode((in)->i_sb, (in)->i_tag, __FILE__, __LINE__ )
10164 +
10165 +#define dl_free_inode(in) \
10166 +       __dl_free_inode((in)->i_sb, (in)->i_tag, __FILE__, __LINE__ )
10167 +
10168 +
10169 +#define dl_adjust_block(sb, tag, fb, rb) \
10170 +       __dl_adjust_block(sb, tag, fb, rb, __FILE__, __LINE__ )
10171 +
10172 +
10173 +#else
10174 +#warning duplicate inclusion
10175 +#endif
10176 diff -NurpP --minimal linux-2.6.38-rc8/include/linux/vs_inet.h linux-2.6.38-rc8-vs2.3.0.37-rc6/include/linux/vs_inet.h
10177 --- linux-2.6.38-rc8/include/linux/vs_inet.h    1970-01-01 01:00:00.000000000 +0100
10178 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/include/linux/vs_inet.h     2011-01-29 04:45:50.000000000 +0100
10179 @@ -0,0 +1,351 @@
10180 +#ifndef _VS_INET_H
10181 +#define _VS_INET_H
10182 +
10183 +#include "vserver/base.h"
10184 +#include "vserver/network.h"
10185 +#include "vserver/debug.h"
10186 +
10187 +#define IPI_LOOPBACK   htonl(INADDR_LOOPBACK)
10188 +
10189 +#define NXAV4(a)       NIPQUAD((a)->ip[0]), NIPQUAD((a)->ip[1]), \
10190 +                       NIPQUAD((a)->mask), (a)->type
10191 +#define NXAV4_FMT      "[" NIPQUAD_FMT "-" NIPQUAD_FMT "/" NIPQUAD_FMT ":%04x]"
10192 +
10193 +#define NIPQUAD(addr) \
10194 +       ((unsigned char *)&addr)[0], \
10195 +       ((unsigned char *)&addr)[1], \
10196 +       ((unsigned char *)&addr)[2], \
10197 +       ((unsigned char *)&addr)[3]
10198 +
10199 +#define NIPQUAD_FMT "%u.%u.%u.%u"
10200 +
10201 +
10202 +static inline
10203 +int v4_addr_match(struct nx_addr_v4 *nxa, __be32 addr, uint16_t tmask)
10204 +{
10205 +       __be32 ip = nxa->ip[0].s_addr;
10206 +       __be32 mask = nxa->mask.s_addr;
10207 +       __be32 bcast = ip | ~mask;
10208 +       int ret = 0;
10209 +
10210 +       switch (nxa->type & tmask) {
10211 +       case NXA_TYPE_MASK:
10212 +               ret = (ip == (addr & mask));
10213 +               break;
10214 +       case NXA_TYPE_ADDR:
10215 +               ret = 3;
10216 +               if (addr == ip)
10217 +                       break;
10218 +               /* fall through to broadcast */
10219 +       case NXA_MOD_BCAST:
10220 +               ret = ((tmask & NXA_MOD_BCAST) && (addr == bcast));
10221 +               break;
10222 +       case NXA_TYPE_RANGE:
10223 +               ret = ((nxa->ip[0].s_addr <= addr) &&
10224 +                       (nxa->ip[1].s_addr > addr));
10225 +               break;
10226 +       case NXA_TYPE_ANY:
10227 +               ret = 2;
10228 +               break;
10229 +       }
10230 +
10231 +       vxdprintk(VXD_CBIT(net, 0),
10232 +               "v4_addr_match(%p" NXAV4_FMT "," NIPQUAD_FMT ",%04x) = %d",
10233 +               nxa, NXAV4(nxa), NIPQUAD(addr), tmask, ret);
10234 +       return ret;
10235 +}
10236 +
10237 +static inline
10238 +int v4_addr_in_nx_info(struct nx_info *nxi, __be32 addr, uint16_t tmask)
10239 +{
10240 +       struct nx_addr_v4 *nxa;
10241 +       int ret = 1;
10242 +
10243 +       if (!nxi)
10244 +               goto out;
10245 +
10246 +       ret = 2;
10247 +       /* allow 127.0.0.1 when remapping lback */
10248 +       if ((tmask & NXA_LOOPBACK) &&
10249 +               (addr == IPI_LOOPBACK) &&
10250 +               nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
10251 +               goto out;
10252 +       ret = 3;
10253 +       /* check for lback address */
10254 +       if ((tmask & NXA_MOD_LBACK) &&
10255 +               (nxi->v4_lback.s_addr == addr))
10256 +               goto out;
10257 +       ret = 4;
10258 +       /* check for broadcast address */
10259 +       if ((tmask & NXA_MOD_BCAST) &&
10260 +               (nxi->v4_bcast.s_addr == addr))
10261 +               goto out;
10262 +       ret = 5;
10263 +       /* check for v4 addresses */
10264 +       for (nxa = &nxi->v4; nxa; nxa = nxa->next)
10265 +               if (v4_addr_match(nxa, addr, tmask))
10266 +                       goto out;
10267 +       ret = 0;
10268 +out:
10269 +       vxdprintk(VXD_CBIT(net, 0),
10270 +               "v4_addr_in_nx_info(%p[#%u]," NIPQUAD_FMT ",%04x) = %d",
10271 +               nxi, nxi ? nxi->nx_id : 0, NIPQUAD(addr), tmask, ret);
10272 +       return ret;
10273 +}
10274 +
10275 +static inline
10276 +int v4_nx_addr_match(struct nx_addr_v4 *nxa, struct nx_addr_v4 *addr, uint16_t mask)
10277 +{
10278 +       /* FIXME: needs full range checks */
10279 +       return v4_addr_match(nxa, addr->ip[0].s_addr, mask);
10280 +}
10281 +
10282 +static inline
10283 +int v4_nx_addr_in_nx_info(struct nx_info *nxi, struct nx_addr_v4 *nxa, uint16_t mask)
10284 +{
10285 +       struct nx_addr_v4 *ptr;
10286 +
10287 +       for (ptr = &nxi->v4; ptr; ptr = ptr->next)
10288 +               if (v4_nx_addr_match(ptr, nxa, mask))
10289 +                       return 1;
10290 +       return 0;
10291 +}
10292 +
10293 +#include <net/inet_sock.h>
10294 +
10295 +/*
10296 + *     Check if a given address matches for a socket
10297 + *
10298 + *     nxi:            the socket's nx_info if any
10299 + *     addr:           to be verified address
10300 + */
10301 +static inline
10302 +int v4_sock_addr_match (
10303 +       struct nx_info *nxi,
10304 +       struct inet_sock *inet,
10305 +       __be32 addr)
10306 +{
10307 +       __be32 saddr = inet->inet_rcv_saddr;
10308 +       __be32 bcast = nxi ? nxi->v4_bcast.s_addr : INADDR_BROADCAST;
10309 +
10310 +       if (addr && (saddr == addr || bcast == addr))
10311 +               return 1;
10312 +       if (!saddr)
10313 +               return v4_addr_in_nx_info(nxi, addr, NXA_MASK_BIND);
10314 +       return 0;
10315 +}
10316 +
10317 +
10318 +/* inet related checks and helpers */
10319 +
10320 +
10321 +struct in_ifaddr;
10322 +struct net_device;
10323 +struct sock;
10324 +
10325 +#ifdef CONFIG_INET
10326 +
10327 +#include <linux/netdevice.h>
10328 +#include <linux/inetdevice.h>
10329 +#include <net/inet_sock.h>
10330 +#include <net/inet_timewait_sock.h>
10331 +
10332 +
10333 +int dev_in_nx_info(struct net_device *, struct nx_info *);
10334 +int v4_dev_in_nx_info(struct net_device *, struct nx_info *);
10335 +int nx_v4_addr_conflict(struct nx_info *, struct nx_info *);
10336 +
10337 +
10338 +/*
10339 + *     check if address is covered by socket
10340 + *
10341 + *     sk:     the socket to check against
10342 + *     addr:   the address in question (must be != 0)
10343 + */
10344 +
10345 +static inline
10346 +int __v4_addr_match_socket(const struct sock *sk, struct nx_addr_v4 *nxa)
10347 +{
10348 +       struct nx_info *nxi = sk->sk_nx_info;
10349 +       __be32 saddr = sk_rcv_saddr(sk);
10350 +
10351 +       vxdprintk(VXD_CBIT(net, 5),
10352 +               "__v4_addr_in_socket(%p," NXAV4_FMT ") %p:" NIPQUAD_FMT " %p;%lx",
10353 +               sk, NXAV4(nxa), nxi, NIPQUAD(saddr), sk->sk_socket,
10354 +               (sk->sk_socket?sk->sk_socket->flags:0));
10355 +
10356 +       if (saddr) {            /* direct address match */
10357 +               return v4_addr_match(nxa, saddr, -1);
10358 +       } else if (nxi) {       /* match against nx_info */
10359 +               return v4_nx_addr_in_nx_info(nxi, nxa, -1);
10360 +       } else {                /* unrestricted any socket */
10361 +               return 1;
10362 +       }
10363 +}
10364 +
10365 +
10366 +
10367 +static inline
10368 +int nx_dev_visible(struct nx_info *nxi, struct net_device *dev)
10369 +{
10370 +       vxdprintk(VXD_CBIT(net, 1),
10371 +               "nx_dev_visible(%p[#%u],%p " VS_Q("%s") ") %d",
10372 +               nxi, nxi ? nxi->nx_id : 0, dev, dev->name,
10373 +               nxi ? dev_in_nx_info(dev, nxi) : 0);
10374 +
10375 +       if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
10376 +               return 1;
10377 +       if (dev_in_nx_info(dev, nxi))
10378 +               return 1;
10379 +       return 0;
10380 +}
10381 +
10382 +
10383 +static inline
10384 +int v4_ifa_in_nx_info(struct in_ifaddr *ifa, struct nx_info *nxi)
10385 +{
10386 +       if (!nxi)
10387 +               return 1;
10388 +       if (!ifa)
10389 +               return 0;
10390 +       return v4_addr_in_nx_info(nxi, ifa->ifa_local, NXA_MASK_SHOW);
10391 +}
10392 +
10393 +static inline
10394 +int nx_v4_ifa_visible(struct nx_info *nxi, struct in_ifaddr *ifa)
10395 +{
10396 +       vxdprintk(VXD_CBIT(net, 1), "nx_v4_ifa_visible(%p[#%u],%p) %d",
10397 +               nxi, nxi ? nxi->nx_id : 0, ifa,
10398 +               nxi ? v4_ifa_in_nx_info(ifa, nxi) : 0);
10399 +
10400 +       if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
10401 +               return 1;
10402 +       if (v4_ifa_in_nx_info(ifa, nxi))
10403 +               return 1;
10404 +       return 0;
10405 +}
10406 +
10407 +
10408 +struct nx_v4_sock_addr {
10409 +       __be32 saddr;   /* Address used for validation */
10410 +       __be32 baddr;   /* Address used for socket bind */
10411 +};
10412 +
10413 +static inline
10414 +int v4_map_sock_addr(struct inet_sock *inet, struct sockaddr_in *addr,
10415 +       struct nx_v4_sock_addr *nsa)
10416 +{
10417 +       struct sock *sk = &inet->sk;
10418 +       struct nx_info *nxi = sk->sk_nx_info;
10419 +       __be32 saddr = addr->sin_addr.s_addr;
10420 +       __be32 baddr = saddr;
10421 +
10422 +       vxdprintk(VXD_CBIT(net, 3),
10423 +               "inet_bind(%p)* %p,%p;%lx " NIPQUAD_FMT,
10424 +               sk, sk->sk_nx_info, sk->sk_socket,
10425 +               (sk->sk_socket ? sk->sk_socket->flags : 0),
10426 +               NIPQUAD(saddr));
10427 +
10428 +       if (nxi) {
10429 +               if (saddr == INADDR_ANY) {
10430 +                       if (nx_info_flags(nxi, NXF_SINGLE_IP, 0))
10431 +                               baddr = nxi->v4.ip[0].s_addr;
10432 +               } else if (saddr == IPI_LOOPBACK) {
10433 +                       if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
10434 +                               baddr = nxi->v4_lback.s_addr;
10435 +               } else {        /* normal address bind */
10436 +                       if (!v4_addr_in_nx_info(nxi, saddr, NXA_MASK_BIND))
10437 +                               return -EADDRNOTAVAIL;
10438 +               }
10439 +       }
10440 +
10441 +       vxdprintk(VXD_CBIT(net, 3),
10442 +               "inet_bind(%p) " NIPQUAD_FMT ", " NIPQUAD_FMT,
10443 +               sk, NIPQUAD(saddr), NIPQUAD(baddr));
10444 +
10445 +       nsa->saddr = saddr;
10446 +       nsa->baddr = baddr;
10447 +       return 0;
10448 +}
10449 +
10450 +static inline
10451 +void v4_set_sock_addr(struct inet_sock *inet, struct nx_v4_sock_addr *nsa)
10452 +{
10453 +       inet->inet_saddr = nsa->baddr;
10454 +       inet->inet_rcv_saddr = nsa->baddr;
10455 +}
10456 +
10457 +
10458 +/*
10459 + *      helper to simplify inet_lookup_listener
10460 + *
10461 + *      nxi:   the socket's nx_info if any
10462 + *      addr:  to be verified address
10463 + *      saddr: socket address
10464 + */
10465 +static inline int v4_inet_addr_match (
10466 +       struct nx_info *nxi,
10467 +       __be32 addr,
10468 +       __be32 saddr)
10469 +{
10470 +       if (addr && (saddr == addr))
10471 +               return 1;
10472 +       if (!saddr)
10473 +               return nxi ? v4_addr_in_nx_info(nxi, addr, NXA_MASK_BIND) : 1;
10474 +       return 0;
10475 +}
10476 +
10477 +static inline __be32 nx_map_sock_lback(struct nx_info *nxi, __be32 addr)
10478 +{
10479 +       if (nx_info_flags(nxi, NXF_HIDE_LBACK, 0) &&
10480 +               (addr == nxi->v4_lback.s_addr))
10481 +               return IPI_LOOPBACK;
10482 +       return addr;
10483 +}
10484 +
10485 +static inline
10486 +int nx_info_has_v4(struct nx_info *nxi)
10487 +{
10488 +       if (!nxi)
10489 +               return 1;
10490 +       if (NX_IPV4(nxi))
10491 +               return 1;
10492 +       if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
10493 +               return 1;
10494 +       return 0;
10495 +}
10496 +
10497 +#else /* CONFIG_INET */
10498 +
10499 +static inline
10500 +int nx_dev_visible(struct nx_info *n, struct net_device *d)
10501 +{
10502 +       return 1;
10503 +}
10504 +
10505 +static inline
10506 +int nx_v4_addr_conflict(struct nx_info *n, uint32_t a, const struct sock *s)
10507 +{
10508 +       return 1;
10509 +}
10510 +
10511 +static inline
10512 +int v4_ifa_in_nx_info(struct in_ifaddr *a, struct nx_info *n)
10513 +{
10514 +       return 1;
10515 +}
10516 +
10517 +static inline
10518 +int nx_info_has_v4(struct nx_info *nxi)
10519 +{
10520 +       return 0;
10521 +}
10522 +
10523 +#endif /* CONFIG_INET */
10524 +
10525 +#define current_nx_info_has_v4() \
10526 +       nx_info_has_v4(current_nx_info())
10527 +
10528 +#else
10529 +// #warning duplicate inclusion
10530 +#endif
10531 diff -NurpP --minimal linux-2.6.38-rc8/include/linux/vs_inet6.h linux-2.6.38-rc8-vs2.3.0.37-rc6/include/linux/vs_inet6.h
10532 --- linux-2.6.38-rc8/include/linux/vs_inet6.h   1970-01-01 01:00:00.000000000 +0100
10533 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/include/linux/vs_inet6.h    2011-01-29 02:01:07.000000000 +0100
10534 @@ -0,0 +1,246 @@
10535 +#ifndef _VS_INET6_H
10536 +#define _VS_INET6_H
10537 +
10538 +#include "vserver/base.h"
10539 +#include "vserver/network.h"
10540 +#include "vserver/debug.h"
10541 +
10542 +#include <net/ipv6.h>
10543 +
10544 +#define NXAV6(a)       &(a)->ip, &(a)->mask, (a)->prefix, (a)->type
10545 +#define NXAV6_FMT      "[%pI6/%pI6/%d:%04x]"
10546 +
10547 +
10548 +#ifdef CONFIG_IPV6
10549 +
10550 +static inline
10551 +int v6_addr_match(struct nx_addr_v6 *nxa,
10552 +       const struct in6_addr *addr, uint16_t mask)
10553 +{
10554 +       int ret = 0;
10555 +
10556 +       switch (nxa->type & mask) {
10557 +       case NXA_TYPE_MASK:
10558 +               ret = ipv6_masked_addr_cmp(&nxa->ip, &nxa->mask, addr);
10559 +               break;
10560 +       case NXA_TYPE_ADDR:
10561 +               ret = ipv6_addr_equal(&nxa->ip, addr);
10562 +               break;
10563 +       case NXA_TYPE_ANY:
10564 +               ret = 1;
10565 +               break;
10566 +       }
10567 +       vxdprintk(VXD_CBIT(net, 0),
10568 +               "v6_addr_match(%p" NXAV6_FMT ",%pI6,%04x) = %d",
10569 +               nxa, NXAV6(nxa), addr, mask, ret);
10570 +       return ret;
10571 +}
10572 +
10573 +static inline
10574 +int v6_addr_in_nx_info(struct nx_info *nxi,
10575 +       const struct in6_addr *addr, uint16_t mask)
10576 +{
10577 +       struct nx_addr_v6 *nxa;
10578 +       int ret = 1;
10579 +
10580 +       if (!nxi)
10581 +               goto out;
10582 +       for (nxa = &nxi->v6; nxa; nxa = nxa->next)
10583 +               if (v6_addr_match(nxa, addr, mask))
10584 +                       goto out;
10585 +       ret = 0;
10586 +out:
10587 +       vxdprintk(VXD_CBIT(net, 0),
10588 +               "v6_addr_in_nx_info(%p[#%u],%pI6,%04x) = %d",
10589 +               nxi, nxi ? nxi->nx_id : 0, addr, mask, ret);
10590 +       return ret;
10591 +}
10592 +
10593 +static inline
10594 +int v6_nx_addr_match(struct nx_addr_v6 *nxa, struct nx_addr_v6 *addr, uint16_t mask)
10595 +{
10596 +       /* FIXME: needs full range checks */
10597 +       return v6_addr_match(nxa, &addr->ip, mask);
10598 +}
10599 +
10600 +static inline
10601 +int v6_nx_addr_in_nx_info(struct nx_info *nxi, struct nx_addr_v6 *nxa, uint16_t mask)
10602 +{
10603 +       struct nx_addr_v6 *ptr;
10604 +
10605 +       for (ptr = &nxi->v6; ptr; ptr = ptr->next)
10606 +               if (v6_nx_addr_match(ptr, nxa, mask))
10607 +                       return 1;
10608 +       return 0;
10609 +}
10610 +
10611 +
10612 +/*
10613 + *     Check if a given address matches for a socket
10614 + *
10615 + *     nxi:            the socket's nx_info if any
10616 + *     addr:           to be verified address
10617 + */
10618 +static inline
10619 +int v6_sock_addr_match (
10620 +       struct nx_info *nxi,
10621 +       struct inet_sock *inet,
10622 +       struct in6_addr *addr)
10623 +{
10624 +       struct sock *sk = &inet->sk;
10625 +       struct in6_addr *saddr = inet6_rcv_saddr(sk);
10626 +
10627 +       if (!ipv6_addr_any(addr) &&
10628 +               ipv6_addr_equal(saddr, addr))
10629 +               return 1;
10630 +       if (ipv6_addr_any(saddr))
10631 +               return v6_addr_in_nx_info(nxi, addr, -1);
10632 +       return 0;
10633 +}
10634 +
10635 +/*
10636 + *     check if address is covered by socket
10637 + *
10638 + *     sk:     the socket to check against
10639 + *     addr:   the address in question (must be != 0)
10640 + */
10641 +
10642 +static inline
10643 +int __v6_addr_match_socket(const struct sock *sk, struct nx_addr_v6 *nxa)
10644 +{
10645 +       struct nx_info *nxi = sk->sk_nx_info;
10646 +       struct in6_addr *saddr = inet6_rcv_saddr(sk);
10647 +
10648 +       vxdprintk(VXD_CBIT(net, 5),
10649 +               "__v6_addr_in_socket(%p," NXAV6_FMT ") %p:%pI6 %p;%lx",
10650 +               sk, NXAV6(nxa), nxi, saddr, sk->sk_socket,
10651 +               (sk->sk_socket?sk->sk_socket->flags:0));
10652 +
10653 +       if (!ipv6_addr_any(saddr)) {    /* direct address match */
10654 +               return v6_addr_match(nxa, saddr, -1);
10655 +       } else if (nxi) {               /* match against nx_info */
10656 +               return v6_nx_addr_in_nx_info(nxi, nxa, -1);
10657 +       } else {                        /* unrestricted any socket */
10658 +               return 1;
10659 +       }
10660 +}
10661 +
10662 +
10663 +/* inet related checks and helpers */
10664 +
10665 +
10666 +struct in_ifaddr;
10667 +struct net_device;
10668 +struct sock;
10669 +
10670 +
10671 +#include <linux/netdevice.h>
10672 +#include <linux/inetdevice.h>
10673 +#include <net/inet_timewait_sock.h>
10674 +
10675 +
10676 +int dev_in_nx_info(struct net_device *, struct nx_info *);
10677 +int v6_dev_in_nx_info(struct net_device *, struct nx_info *);
10678 +int nx_v6_addr_conflict(struct nx_info *, struct nx_info *);
10679 +
10680 +
10681 +
10682 +static inline
10683 +int v6_ifa_in_nx_info(struct inet6_ifaddr *ifa, struct nx_info *nxi)
10684 +{
10685 +       if (!nxi)
10686 +               return 1;
10687 +       if (!ifa)
10688 +               return 0;
10689 +       return v6_addr_in_nx_info(nxi, &ifa->addr, -1);
10690 +}
10691 +
10692 +static inline
10693 +int nx_v6_ifa_visible(struct nx_info *nxi, struct inet6_ifaddr *ifa)
10694 +{
10695 +       vxdprintk(VXD_CBIT(net, 1), "nx_v6_ifa_visible(%p[#%u],%p) %d",
10696 +               nxi, nxi ? nxi->nx_id : 0, ifa,
10697 +               nxi ? v6_ifa_in_nx_info(ifa, nxi) : 0);
10698 +
10699 +       if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
10700 +               return 1;
10701 +       if (v6_ifa_in_nx_info(ifa, nxi))
10702 +               return 1;
10703 +       return 0;
10704 +}
10705 +
10706 +
10707 +struct nx_v6_sock_addr {
10708 +       struct in6_addr saddr;  /* Address used for validation */
10709 +       struct in6_addr baddr;  /* Address used for socket bind */
10710 +};
10711 +
10712 +static inline
10713 +int v6_map_sock_addr(struct inet_sock *inet, struct sockaddr_in6 *addr,
10714 +       struct nx_v6_sock_addr *nsa)
10715 +{
10716 +       // struct sock *sk = &inet->sk;
10717 +       // struct nx_info *nxi = sk->sk_nx_info;
10718 +       struct in6_addr saddr = addr->sin6_addr;
10719 +       struct in6_addr baddr = saddr;
10720 +
10721 +       nsa->saddr = saddr;
10722 +       nsa->baddr = baddr;
10723 +       return 0;
10724 +}
10725 +
10726 +static inline
10727 +void v6_set_sock_addr(struct inet_sock *inet, struct nx_v6_sock_addr *nsa)
10728 +{
10729 +       // struct sock *sk = &inet->sk;
10730 +       // struct in6_addr *saddr = inet6_rcv_saddr(sk);
10731 +
10732 +       // *saddr = nsa->baddr;
10733 +       // inet->inet_saddr = nsa->baddr;
10734 +}
10735 +
10736 +static inline
10737 +int nx_info_has_v6(struct nx_info *nxi)
10738 +{
10739 +       if (!nxi)
10740 +               return 1;
10741 +       if (NX_IPV6(nxi))
10742 +               return 1;
10743 +       return 0;
10744 +}
10745 +
10746 +#else /* CONFIG_IPV6 */
10747 +
10748 +static inline
10749 +int nx_v6_dev_visible(struct nx_info *n, struct net_device *d)
10750 +{
10751 +       return 1;
10752 +}
10753 +
10754 +
10755 +static inline
10756 +int nx_v6_addr_conflict(struct nx_info *n, uint32_t a, const struct sock *s)
10757 +{
10758 +       return 1;
10759 +}
10760 +
10761 +static inline
10762 +int v6_ifa_in_nx_info(struct in_ifaddr *a, struct nx_info *n)
10763 +{
10764 +       return 1;
10765 +}
10766 +
10767 +static inline
10768 +int nx_info_has_v6(struct nx_info *nxi)
10769 +{
10770 +       return 0;
10771 +}
10772 +
10773 +#endif /* CONFIG_IPV6 */
10774 +
10775 +#define current_nx_info_has_v6() \
10776 +       nx_info_has_v6(current_nx_info())
10777 +
10778 +#else
10779 +#warning duplicate inclusion
10780 +#endif
10781 diff -NurpP --minimal linux-2.6.38-rc8/include/linux/vs_limit.h linux-2.6.38-rc8-vs2.3.0.37-rc6/include/linux/vs_limit.h
10782 --- linux-2.6.38-rc8/include/linux/vs_limit.h   1970-01-01 01:00:00.000000000 +0100
10783 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/include/linux/vs_limit.h    2011-01-29 04:59:22.000000000 +0100
10784 @@ -0,0 +1,140 @@
10785 +#ifndef _VS_LIMIT_H
10786 +#define _VS_LIMIT_H
10787 +
10788 +#include "vserver/limit.h"
10789 +#include "vserver/base.h"
10790 +#include "vserver/context.h"
10791 +#include "vserver/debug.h"
10792 +#include "vserver/context.h"
10793 +#include "vserver/limit_int.h"
10794 +
10795 +
10796 +#define vx_acc_cres(v, d, p, r) \
10797 +       __vx_acc_cres(v, r, d, p, __FILE__, __LINE__)
10798 +
10799 +#define vx_acc_cres_cond(x, d, p, r) \
10800 +       __vx_acc_cres(((x) == vx_current_xid()) ? current_vx_info() : 0, \
10801 +       r, d, p, __FILE__, __LINE__)
10802 +
10803 +
10804 +#define vx_add_cres(v, a, p, r) \
10805 +       __vx_add_cres(v, r, a, p, __FILE__, __LINE__)
10806 +#define vx_sub_cres(v, a, p, r)                vx_add_cres(v, -(a), p, r)
10807 +
10808 +#define vx_add_cres_cond(x, a, p, r) \
10809 +       __vx_add_cres(((x) == vx_current_xid()) ? current_vx_info() : 0, \
10810 +       r, a, p, __FILE__, __LINE__)
10811 +#define vx_sub_cres_cond(x, a, p, r)   vx_add_cres_cond(x, -(a), p, r)
10812 +
10813 +
10814 +/* process and file limits */
10815 +
10816 +#define vx_nproc_inc(p) \
10817 +       vx_acc_cres((p)->vx_info, 1, p, RLIMIT_NPROC)
10818 +
10819 +#define vx_nproc_dec(p) \
10820 +       vx_acc_cres((p)->vx_info,-1, p, RLIMIT_NPROC)
10821 +
10822 +#define vx_files_inc(f) \
10823 +       vx_acc_cres_cond((f)->f_xid, 1, f, RLIMIT_NOFILE)
10824 +
10825 +#define vx_files_dec(f) \
10826 +       vx_acc_cres_cond((f)->f_xid,-1, f, RLIMIT_NOFILE)
10827 +
10828 +#define vx_locks_inc(l) \
10829 +       vx_acc_cres_cond((l)->fl_xid, 1, l, RLIMIT_LOCKS)
10830 +
10831 +#define vx_locks_dec(l) \
10832 +       vx_acc_cres_cond((l)->fl_xid,-1, l, RLIMIT_LOCKS)
10833 +
10834 +#define vx_openfd_inc(f) \
10835 +       vx_acc_cres(current_vx_info(), 1, (void *)(long)(f), VLIMIT_OPENFD)
10836 +
10837 +#define vx_openfd_dec(f) \
10838 +       vx_acc_cres(current_vx_info(),-1, (void *)(long)(f), VLIMIT_OPENFD)
10839 +
10840 +
10841 +#define vx_cres_avail(v, n, r) \
10842 +       __vx_cres_avail(v, r, n, __FILE__, __LINE__)
10843 +
10844 +
10845 +#define vx_nproc_avail(n) \
10846 +       vx_cres_avail(current_vx_info(), n, RLIMIT_NPROC)
10847 +
10848 +#define vx_files_avail(n) \
10849 +       vx_cres_avail(current_vx_info(), n, RLIMIT_NOFILE)
10850 +
10851 +#define vx_locks_avail(n) \
10852 +       vx_cres_avail(current_vx_info(), n, RLIMIT_LOCKS)
10853 +
10854 +#define vx_openfd_avail(n) \
10855 +       vx_cres_avail(current_vx_info(), n, VLIMIT_OPENFD)
10856 +
10857 +
10858 +/* dentry limits */
10859 +
10860 +#define vx_dentry_inc(d) do {                                          \
10861 +       if ((d)->d_count == 1)                                          \
10862 +               vx_acc_cres(current_vx_info(), 1, d, VLIMIT_DENTRY);    \
10863 +       } while (0)
10864 +
10865 +#define vx_dentry_dec(d) do {                                          \
10866 +       if ((d)->d_count == 0)                                          \
10867 +               vx_acc_cres(current_vx_info(),-1, d, VLIMIT_DENTRY);    \
10868 +       } while (0)
10869 +
10870 +#define vx_dentry_avail(n) \
10871 +       vx_cres_avail(current_vx_info(), n, VLIMIT_DENTRY)
10872 +
10873 +
10874 +/* socket limits */
10875 +
10876 +#define vx_sock_inc(s) \
10877 +       vx_acc_cres((s)->sk_vx_info, 1, s, VLIMIT_NSOCK)
10878 +
10879 +#define vx_sock_dec(s) \
10880 +       vx_acc_cres((s)->sk_vx_info,-1, s, VLIMIT_NSOCK)
10881 +
10882 +#define vx_sock_avail(n) \
10883 +       vx_cres_avail(current_vx_info(), n, VLIMIT_NSOCK)
10884 +
10885 +
10886 +/* ipc resource limits */
10887 +
10888 +#define vx_ipcmsg_add(v, u, a) \
10889 +       vx_add_cres(v, a, u, RLIMIT_MSGQUEUE)
10890 +
10891 +#define vx_ipcmsg_sub(v, u, a) \
10892 +       vx_sub_cres(v, a, u, RLIMIT_MSGQUEUE)
10893 +
10894 +#define vx_ipcmsg_avail(v, a) \
10895 +       vx_cres_avail(v, a, RLIMIT_MSGQUEUE)
10896 +
10897 +
10898 +#define vx_ipcshm_add(v, k, a) \
10899 +       vx_add_cres(v, a, (void *)(long)(k), VLIMIT_SHMEM)
10900 +
10901 +#define vx_ipcshm_sub(v, k, a) \
10902 +       vx_sub_cres(v, a, (void *)(long)(k), VLIMIT_SHMEM)
10903 +
10904 +#define vx_ipcshm_avail(v, a) \
10905 +       vx_cres_avail(v, a, VLIMIT_SHMEM)
10906 +
10907 +
10908 +#define vx_semary_inc(a) \
10909 +       vx_acc_cres(current_vx_info(), 1, a, VLIMIT_SEMARY)
10910 +
10911 +#define vx_semary_dec(a) \
10912 +       vx_acc_cres(current_vx_info(), -1, a, VLIMIT_SEMARY)
10913 +
10914 +
10915 +#define vx_nsems_add(a,n) \
10916 +       vx_add_cres(current_vx_info(), n, a, VLIMIT_NSEMS)
10917 +
10918 +#define vx_nsems_sub(a,n) \
10919 +       vx_sub_cres(current_vx_info(), n, a, VLIMIT_NSEMS)
10920 +
10921 +
10922 +#else
10923 +#warning duplicate inclusion
10924 +#endif
10925 diff -NurpP --minimal linux-2.6.38-rc8/include/linux/vs_memory.h linux-2.6.38-rc8-vs2.3.0.37-rc6/include/linux/vs_memory.h
10926 --- linux-2.6.38-rc8/include/linux/vs_memory.h  1970-01-01 01:00:00.000000000 +0100
10927 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/include/linux/vs_memory.h   2011-01-29 02:01:07.000000000 +0100
10928 @@ -0,0 +1,58 @@
10929 +#ifndef _VS_MEMORY_H
10930 +#define _VS_MEMORY_H
10931 +
10932 +#include "vserver/limit.h"
10933 +#include "vserver/base.h"
10934 +#include "vserver/context.h"
10935 +#include "vserver/debug.h"
10936 +#include "vserver/context.h"
10937 +#include "vserver/limit_int.h"
10938 +
10939 +enum {
10940 +       VXPT_UNKNOWN = 0,
10941 +       VXPT_ANON,
10942 +       VXPT_NONE,
10943 +       VXPT_FILE,
10944 +       VXPT_SWAP,
10945 +       VXPT_WRITE
10946 +};
10947 +
10948 +#if 0
10949 +#define        vx_page_fault(mm, vma, type, ret)
10950 +#else
10951 +
10952 +static inline
10953 +void __vx_page_fault(struct mm_struct *mm,
10954 +       struct vm_area_struct *vma, int type, int ret)
10955 +{
10956 +       struct vx_info *vxi = mm->mm_vx_info;
10957 +       int what;
10958 +/*
10959 +       static char *page_type[6] =
10960 +               { "UNKNOWN", "ANON", "NONE", "FILE", "SWAP", "WRITE" };
10961 +       static char *page_what[4] =
10962 +               { "FAULT_OOM", "FAULT_SIGBUS", "FAULT_MINOR", "FAULT_MAJOR" };
10963 +*/
10964 +
10965 +       if (!vxi)
10966 +               return;
10967 +
10968 +       what = (ret & 0x3);
10969 +
10970 +/*     printk("[%d] page[%d][%d] %2x %s %s\n", vxi->vx_id,
10971 +               type, what, ret, page_type[type], page_what[what]);
10972 +*/
10973 +       if (ret & VM_FAULT_WRITE)
10974 +               what |= 0x4;
10975 +       atomic_inc(&vxi->cacct.page[type][what]);
10976 +}
10977 +
10978 +#define        vx_page_fault(mm, vma, type, ret)       __vx_page_fault(mm, vma, type, ret)
10979 +#endif
10980 +
10981 +
10982 +extern unsigned long vx_badness(struct task_struct *task, struct mm_struct *mm);
10983 +
10984 +#else
10985 +#warning duplicate inclusion
10986 +#endif
10987 diff -NurpP --minimal linux-2.6.38-rc8/include/linux/vs_network.h linux-2.6.38-rc8-vs2.3.0.37-rc6/include/linux/vs_network.h
10988 --- linux-2.6.38-rc8/include/linux/vs_network.h 1970-01-01 01:00:00.000000000 +0100
10989 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/include/linux/vs_network.h  2011-01-29 02:01:07.000000000 +0100
10990 @@ -0,0 +1,169 @@
10991 +#ifndef _NX_VS_NETWORK_H
10992 +#define _NX_VS_NETWORK_H
10993 +
10994 +#include "vserver/context.h"
10995 +#include "vserver/network.h"
10996 +#include "vserver/base.h"
10997 +#include "vserver/check.h"
10998 +#include "vserver/debug.h"
10999 +
11000 +#include <linux/sched.h>
11001 +
11002 +
11003 +#define get_nx_info(i) __get_nx_info(i, __FILE__, __LINE__)
11004 +
11005 +static inline struct nx_info *__get_nx_info(struct nx_info *nxi,
11006 +       const char *_file, int _line)
11007 +{
11008 +       if (!nxi)
11009 +               return NULL;
11010 +
11011 +       vxlprintk(VXD_CBIT(nid, 2), "get_nx_info(%p[#%d.%d])",
11012 +               nxi, nxi ? nxi->nx_id : 0,
11013 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
11014 +               _file, _line);
11015 +
11016 +       atomic_inc(&nxi->nx_usecnt);
11017 +       return nxi;
11018 +}
11019 +
11020 +
11021 +extern void free_nx_info(struct nx_info *);
11022 +
11023 +#define put_nx_info(i) __put_nx_info(i, __FILE__, __LINE__)
11024 +
11025 +static inline void __put_nx_info(struct nx_info *nxi, const char *_file, int _line)
11026 +{
11027 +       if (!nxi)
11028 +               return;
11029 +
11030 +       vxlprintk(VXD_CBIT(nid, 2), "put_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 +       if (atomic_dec_and_test(&nxi->nx_usecnt))
11036 +               free_nx_info(nxi);
11037 +}
11038 +
11039 +
11040 +#define init_nx_info(p, i) __init_nx_info(p, i, __FILE__, __LINE__)
11041 +
11042 +static inline void __init_nx_info(struct nx_info **nxp, struct nx_info *nxi,
11043 +               const char *_file, int _line)
11044 +{
11045 +       if (nxi) {
11046 +               vxlprintk(VXD_CBIT(nid, 3),
11047 +                       "init_nx_info(%p[#%d.%d])",
11048 +                       nxi, nxi ? nxi->nx_id : 0,
11049 +                       nxi ? atomic_read(&nxi->nx_usecnt) : 0,
11050 +                       _file, _line);
11051 +
11052 +               atomic_inc(&nxi->nx_usecnt);
11053 +       }
11054 +       *nxp = nxi;
11055 +}
11056 +
11057 +
11058 +#define set_nx_info(p, i) __set_nx_info(p, i, __FILE__, __LINE__)
11059 +
11060 +static inline void __set_nx_info(struct nx_info **nxp, struct nx_info *nxi,
11061 +       const char *_file, int _line)
11062 +{
11063 +       struct nx_info *nxo;
11064 +
11065 +       if (!nxi)
11066 +               return;
11067 +
11068 +       vxlprintk(VXD_CBIT(nid, 3), "set_nx_info(%p[#%d.%d])",
11069 +               nxi, nxi ? nxi->nx_id : 0,
11070 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
11071 +               _file, _line);
11072 +
11073 +       atomic_inc(&nxi->nx_usecnt);
11074 +       nxo = xchg(nxp, nxi);
11075 +       BUG_ON(nxo);
11076 +}
11077 +
11078 +#define clr_nx_info(p) __clr_nx_info(p, __FILE__, __LINE__)
11079 +
11080 +static inline void __clr_nx_info(struct nx_info **nxp,
11081 +       const char *_file, int _line)
11082 +{
11083 +       struct nx_info *nxo;
11084 +
11085 +       nxo = xchg(nxp, NULL);
11086 +       if (!nxo)
11087 +               return;
11088 +
11089 +       vxlprintk(VXD_CBIT(nid, 3), "clr_nx_info(%p[#%d.%d])",
11090 +               nxo, nxo ? nxo->nx_id : 0,
11091 +               nxo ? atomic_read(&nxo->nx_usecnt) : 0,
11092 +               _file, _line);
11093 +
11094 +       if (atomic_dec_and_test(&nxo->nx_usecnt))
11095 +               free_nx_info(nxo);
11096 +}
11097 +
11098 +
11099 +#define claim_nx_info(v, p) __claim_nx_info(v, p, __FILE__, __LINE__)
11100 +
11101 +static inline void __claim_nx_info(struct nx_info *nxi,
11102 +       struct task_struct *task, const char *_file, int _line)
11103 +{
11104 +       vxlprintk(VXD_CBIT(nid, 3), "claim_nx_info(%p[#%d.%d.%d]) %p",
11105 +               nxi, nxi ? nxi->nx_id : 0,
11106 +               nxi?atomic_read(&nxi->nx_usecnt):0,
11107 +               nxi?atomic_read(&nxi->nx_tasks):0,
11108 +               task, _file, _line);
11109 +
11110 +       atomic_inc(&nxi->nx_tasks);
11111 +}
11112 +
11113 +
11114 +extern void unhash_nx_info(struct nx_info *);
11115 +
11116 +#define release_nx_info(v, p) __release_nx_info(v, p, __FILE__, __LINE__)
11117 +
11118 +static inline void __release_nx_info(struct nx_info *nxi,
11119 +       struct task_struct *task, const char *_file, int _line)
11120 +{
11121 +       vxlprintk(VXD_CBIT(nid, 3), "release_nx_info(%p[#%d.%d.%d]) %p",
11122 +               nxi, nxi ? nxi->nx_id : 0,
11123 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
11124 +               nxi ? atomic_read(&nxi->nx_tasks) : 0,
11125 +               task, _file, _line);
11126 +
11127 +       might_sleep();
11128 +
11129 +       if (atomic_dec_and_test(&nxi->nx_tasks))
11130 +               unhash_nx_info(nxi);
11131 +}
11132 +
11133 +
11134 +#define task_get_nx_info(i)    __task_get_nx_info(i, __FILE__, __LINE__)
11135 +
11136 +static __inline__ struct nx_info *__task_get_nx_info(struct task_struct *p,
11137 +       const char *_file, int _line)
11138 +{
11139 +       struct nx_info *nxi;
11140 +
11141 +       task_lock(p);
11142 +       vxlprintk(VXD_CBIT(nid, 5), "task_get_nx_info(%p)",
11143 +               p, _file, _line);
11144 +       nxi = __get_nx_info(p->nx_info, _file, _line);
11145 +       task_unlock(p);
11146 +       return nxi;
11147 +}
11148 +
11149 +
11150 +static inline void exit_nx_info(struct task_struct *p)
11151 +{
11152 +       if (p->nx_info)
11153 +               release_nx_info(p->nx_info, p);
11154 +}
11155 +
11156 +
11157 +#else
11158 +#warning duplicate inclusion
11159 +#endif
11160 diff -NurpP --minimal linux-2.6.38-rc8/include/linux/vs_pid.h linux-2.6.38-rc8-vs2.3.0.37-rc6/include/linux/vs_pid.h
11161 --- linux-2.6.38-rc8/include/linux/vs_pid.h     1970-01-01 01:00:00.000000000 +0100
11162 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/include/linux/vs_pid.h      2011-01-29 02:01:07.000000000 +0100
11163 @@ -0,0 +1,95 @@
11164 +#ifndef _VS_PID_H
11165 +#define _VS_PID_H
11166 +
11167 +#include "vserver/base.h"
11168 +#include "vserver/check.h"
11169 +#include "vserver/context.h"
11170 +#include "vserver/debug.h"
11171 +#include "vserver/pid.h"
11172 +#include <linux/pid_namespace.h>
11173 +
11174 +
11175 +#define VXF_FAKE_INIT  (VXF_INFO_INIT | VXF_STATE_INIT)
11176 +
11177 +static inline
11178 +int vx_proc_task_visible(struct task_struct *task)
11179 +{
11180 +       if ((task->pid == 1) &&
11181 +               !vx_flags(VXF_FAKE_INIT, VXF_FAKE_INIT))
11182 +               /* show a blend through init */
11183 +               goto visible;
11184 +       if (vx_check(vx_task_xid(task), VS_WATCH | VS_IDENT))
11185 +               goto visible;
11186 +       return 0;
11187 +visible:
11188 +       return 1;
11189 +}
11190 +
11191 +#define find_task_by_real_pid(pid) find_task_by_pid_ns(pid, &init_pid_ns)
11192 +
11193 +#if 0
11194 +
11195 +static inline
11196 +struct task_struct *vx_find_proc_task_by_pid(int pid)
11197 +{
11198 +       struct task_struct *task = find_task_by_real_pid(pid);
11199 +
11200 +       if (task && !vx_proc_task_visible(task)) {
11201 +               vxdprintk(VXD_CBIT(misc, 6),
11202 +                       "dropping task (find) %p[#%u,%u] for %p[#%u,%u]",
11203 +                       task, task->xid, task->pid,
11204 +                       current, current->xid, current->pid);
11205 +               task = NULL;
11206 +       }
11207 +       return task;
11208 +}
11209 +
11210 +#endif
11211 +
11212 +static inline
11213 +struct task_struct *vx_get_proc_task(struct inode *inode, struct pid *pid)
11214 +{
11215 +       struct task_struct *task = get_pid_task(pid, PIDTYPE_PID);
11216 +
11217 +       if (task && !vx_proc_task_visible(task)) {
11218 +               vxdprintk(VXD_CBIT(misc, 6),
11219 +                       "dropping task (get) %p[#%u,%u] for %p[#%u,%u]",
11220 +                       task, task->xid, task->pid,
11221 +                       current, current->xid, current->pid);
11222 +               put_task_struct(task);
11223 +               task = NULL;
11224 +       }
11225 +       return task;
11226 +}
11227 +
11228 +#if 0
11229 +
11230 +static inline
11231 +struct task_struct *vx_child_reaper(struct task_struct *p)
11232 +{
11233 +       struct vx_info *vxi = p->vx_info;
11234 +       struct task_struct *reaper = child_reaper(p);
11235 +
11236 +       if (!vxi)
11237 +               goto out;
11238 +
11239 +       BUG_ON(!p->vx_info->vx_reaper);
11240 +
11241 +       /* child reaper for the guest reaper */
11242 +       if (vxi->vx_reaper == p)
11243 +               goto out;
11244 +
11245 +       reaper = vxi->vx_reaper;
11246 +out:
11247 +       vxdprintk(VXD_CBIT(xid, 7),
11248 +               "vx_child_reaper(%p[#%u,%u]) = %p[#%u,%u]",
11249 +               p, p->xid, p->pid, reaper, reaper->xid, reaper->pid);
11250 +       return reaper;
11251 +}
11252 +
11253 +#endif
11254 +
11255 +
11256 +#else
11257 +#warning duplicate inclusion
11258 +#endif
11259 diff -NurpP --minimal linux-2.6.38-rc8/include/linux/vs_sched.h linux-2.6.38-rc8-vs2.3.0.37-rc6/include/linux/vs_sched.h
11260 --- linux-2.6.38-rc8/include/linux/vs_sched.h   1970-01-01 01:00:00.000000000 +0100
11261 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/include/linux/vs_sched.h    2011-01-29 02:01:07.000000000 +0100
11262 @@ -0,0 +1,40 @@
11263 +#ifndef _VS_SCHED_H
11264 +#define _VS_SCHED_H
11265 +
11266 +#include "vserver/base.h"
11267 +#include "vserver/context.h"
11268 +#include "vserver/sched.h"
11269 +
11270 +
11271 +#define MAX_PRIO_BIAS           20
11272 +#define MIN_PRIO_BIAS          -20
11273 +
11274 +static inline
11275 +int vx_adjust_prio(struct task_struct *p, int prio, int max_user)
11276 +{
11277 +       struct vx_info *vxi = p->vx_info;
11278 +
11279 +       if (vxi)
11280 +               prio += vx_cpu(vxi, sched_pc).prio_bias;
11281 +       return prio;
11282 +}
11283 +
11284 +static inline void vx_account_user(struct vx_info *vxi,
11285 +       cputime_t cputime, int nice)
11286 +{
11287 +       if (!vxi)
11288 +               return;
11289 +       vx_cpu(vxi, sched_pc).user_ticks += cputime;
11290 +}
11291 +
11292 +static inline void vx_account_system(struct vx_info *vxi,
11293 +       cputime_t cputime, int idle)
11294 +{
11295 +       if (!vxi)
11296 +               return;
11297 +       vx_cpu(vxi, sched_pc).sys_ticks += cputime;
11298 +}
11299 +
11300 +#else
11301 +#warning duplicate inclusion
11302 +#endif
11303 diff -NurpP --minimal linux-2.6.38-rc8/include/linux/vs_socket.h linux-2.6.38-rc8-vs2.3.0.37-rc6/include/linux/vs_socket.h
11304 --- linux-2.6.38-rc8/include/linux/vs_socket.h  1970-01-01 01:00:00.000000000 +0100
11305 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/include/linux/vs_socket.h   2011-01-29 02:01:07.000000000 +0100
11306 @@ -0,0 +1,67 @@
11307 +#ifndef _VS_SOCKET_H
11308 +#define _VS_SOCKET_H
11309 +
11310 +#include "vserver/debug.h"
11311 +#include "vserver/base.h"
11312 +#include "vserver/cacct.h"
11313 +#include "vserver/context.h"
11314 +#include "vserver/tag.h"
11315 +
11316 +
11317 +/* socket accounting */
11318 +
11319 +#include <linux/socket.h>
11320 +
11321 +static inline int vx_sock_type(int family)
11322 +{
11323 +       switch (family) {
11324 +       case PF_UNSPEC:
11325 +               return VXA_SOCK_UNSPEC;
11326 +       case PF_UNIX:
11327 +               return VXA_SOCK_UNIX;
11328 +       case PF_INET:
11329 +               return VXA_SOCK_INET;
11330 +       case PF_INET6:
11331 +               return VXA_SOCK_INET6;
11332 +       case PF_PACKET:
11333 +               return VXA_SOCK_PACKET;
11334 +       default:
11335 +               return VXA_SOCK_OTHER;
11336 +       }
11337 +}
11338 +
11339 +#define vx_acc_sock(v, f, p, s) \
11340 +       __vx_acc_sock(v, f, p, s, __FILE__, __LINE__)
11341 +
11342 +static inline void __vx_acc_sock(struct vx_info *vxi,
11343 +       int family, int pos, int size, char *file, int line)
11344 +{
11345 +       if (vxi) {
11346 +               int type = vx_sock_type(family);
11347 +
11348 +               atomic_long_inc(&vxi->cacct.sock[type][pos].count);
11349 +               atomic_long_add(size, &vxi->cacct.sock[type][pos].total);
11350 +       }
11351 +}
11352 +
11353 +#define vx_sock_recv(sk, s) \
11354 +       vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 0, s)
11355 +#define vx_sock_send(sk, s) \
11356 +       vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 1, s)
11357 +#define vx_sock_fail(sk, s) \
11358 +       vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 2, s)
11359 +
11360 +
11361 +#define sock_vx_init(s) do {           \
11362 +       (s)->sk_xid = 0;                \
11363 +       (s)->sk_vx_info = NULL;         \
11364 +       } while (0)
11365 +
11366 +#define sock_nx_init(s) do {           \
11367 +       (s)->sk_nid = 0;                \
11368 +       (s)->sk_nx_info = NULL;         \
11369 +       } while (0)
11370 +
11371 +#else
11372 +#warning duplicate inclusion
11373 +#endif
11374 diff -NurpP --minimal linux-2.6.38-rc8/include/linux/vs_tag.h linux-2.6.38-rc8-vs2.3.0.37-rc6/include/linux/vs_tag.h
11375 --- linux-2.6.38-rc8/include/linux/vs_tag.h     1970-01-01 01:00:00.000000000 +0100
11376 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/include/linux/vs_tag.h      2011-01-29 02:01:07.000000000 +0100
11377 @@ -0,0 +1,47 @@
11378 +#ifndef _VS_TAG_H
11379 +#define _VS_TAG_H
11380 +
11381 +#include <linux/vserver/tag.h>
11382 +
11383 +/* check conditions */
11384 +
11385 +#define DX_ADMIN       0x0001
11386 +#define DX_WATCH       0x0002
11387 +#define DX_HOSTID      0x0008
11388 +
11389 +#define DX_IDENT       0x0010
11390 +
11391 +#define DX_ARG_MASK    0x0010
11392 +
11393 +
11394 +#define dx_task_tag(t) ((t)->tag)
11395 +
11396 +#define dx_current_tag() dx_task_tag(current)
11397 +
11398 +#define dx_check(c, m) __dx_check(dx_current_tag(), c, m)
11399 +
11400 +#define dx_weak_check(c, m)    ((m) ? dx_check(c, m) : 1)
11401 +
11402 +
11403 +/*
11404 + * check current context for ADMIN/WATCH and
11405 + * optionally against supplied argument
11406 + */
11407 +static inline int __dx_check(tag_t cid, tag_t id, unsigned int mode)
11408 +{
11409 +       if (mode & DX_ARG_MASK) {
11410 +               if ((mode & DX_IDENT) && (id == cid))
11411 +                       return 1;
11412 +       }
11413 +       return (((mode & DX_ADMIN) && (cid == 0)) ||
11414 +               ((mode & DX_WATCH) && (cid == 1)) ||
11415 +               ((mode & DX_HOSTID) && (id == 0)));
11416 +}
11417 +
11418 +struct inode;
11419 +int dx_permission(const struct inode *inode, int mask);
11420 +
11421 +
11422 +#else
11423 +#warning duplicate inclusion
11424 +#endif
11425 diff -NurpP --minimal linux-2.6.38-rc8/include/linux/vs_time.h linux-2.6.38-rc8-vs2.3.0.37-rc6/include/linux/vs_time.h
11426 --- linux-2.6.38-rc8/include/linux/vs_time.h    1970-01-01 01:00:00.000000000 +0100
11427 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/include/linux/vs_time.h     2011-01-29 02:01:07.000000000 +0100
11428 @@ -0,0 +1,19 @@
11429 +#ifndef _VS_TIME_H
11430 +#define _VS_TIME_H
11431 +
11432 +
11433 +/* time faking stuff */
11434 +
11435 +#ifdef CONFIG_VSERVER_VTIME
11436 +
11437 +extern void vx_adjust_timespec(struct timespec *ts);
11438 +extern int vx_settimeofday(struct timespec *ts);
11439 +
11440 +#else
11441 +#define        vx_adjust_timespec(t)   do { } while (0)
11442 +#define        vx_settimeofday(t)      do_settimeofday(t)
11443 +#endif
11444 +
11445 +#else
11446 +#warning duplicate inclusion
11447 +#endif
11448 diff -NurpP --minimal linux-2.6.38-rc8/include/linux/vserver/Kbuild linux-2.6.38-rc8-vs2.3.0.37-rc6/include/linux/vserver/Kbuild
11449 --- linux-2.6.38-rc8/include/linux/vserver/Kbuild       1970-01-01 01:00:00.000000000 +0100
11450 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/include/linux/vserver/Kbuild        2011-01-29 02:01:07.000000000 +0100
11451 @@ -0,0 +1,8 @@
11452 +
11453 +unifdef-y += context_cmd.h network_cmd.h space_cmd.h \
11454 +       cacct_cmd.h cvirt_cmd.h limit_cmd.h dlimit_cmd.h \
11455 +       inode_cmd.h tag_cmd.h sched_cmd.h signal_cmd.h \
11456 +       debug_cmd.h device_cmd.h
11457 +
11458 +unifdef-y += switch.h network.h monitor.h inode.h device.h
11459 +
11460 diff -NurpP --minimal linux-2.6.38-rc8/include/linux/vserver/base.h linux-2.6.38-rc8-vs2.3.0.37-rc6/include/linux/vserver/base.h
11461 --- linux-2.6.38-rc8/include/linux/vserver/base.h       1970-01-01 01:00:00.000000000 +0100
11462 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/include/linux/vserver/base.h        2011-01-29 02:01:07.000000000 +0100
11463 @@ -0,0 +1,170 @@
11464 +#ifndef _VX_BASE_H
11465 +#define _VX_BASE_H
11466 +
11467 +
11468 +/* context state changes */
11469 +
11470 +enum {
11471 +       VSC_STARTUP = 1,
11472 +       VSC_SHUTDOWN,
11473 +
11474 +       VSC_NETUP,
11475 +       VSC_NETDOWN,
11476 +};
11477 +
11478 +
11479 +
11480 +#define vx_task_xid(t) ((t)->xid)
11481 +
11482 +#define vx_current_xid() vx_task_xid(current)
11483 +
11484 +#define current_vx_info() (current->vx_info)
11485 +
11486 +
11487 +#define nx_task_nid(t) ((t)->nid)
11488 +
11489 +#define nx_current_nid() nx_task_nid(current)
11490 +
11491 +#define current_nx_info() (current->nx_info)
11492 +
11493 +
11494 +/* generic flag merging */
11495 +
11496 +#define vs_check_flags(v, m, f)        (((v) & (m)) ^ (f))
11497 +
11498 +#define vs_mask_flags(v, f, m) (((v) & ~(m)) | ((f) & (m)))
11499 +
11500 +#define vs_mask_mask(v, f, m)  (((v) & ~(m)) | ((v) & (f) & (m)))
11501 +
11502 +#define vs_check_bit(v, n)     ((v) & (1LL << (n)))
11503 +
11504 +
11505 +/* context flags */
11506 +
11507 +#define __vx_flags(v)  ((v) ? (v)->vx_flags : 0)
11508 +
11509 +#define vx_current_flags()     __vx_flags(current_vx_info())
11510 +
11511 +#define vx_info_flags(v, m, f) \
11512 +       vs_check_flags(__vx_flags(v), m, f)
11513 +
11514 +#define task_vx_flags(t, m, f) \
11515 +       ((t) && vx_info_flags((t)->vx_info, m, f))
11516 +
11517 +#define vx_flags(m, f) vx_info_flags(current_vx_info(), m, f)
11518 +
11519 +
11520 +/* context caps */
11521 +
11522 +#define __vx_ccaps(v)  ((v) ? (v)->vx_ccaps : 0)
11523 +
11524 +#define vx_current_ccaps()     __vx_ccaps(current_vx_info())
11525 +
11526 +#define vx_info_ccaps(v, c)    (__vx_ccaps(v) & (c))
11527 +
11528 +#define vx_ccaps(c)    vx_info_ccaps(current_vx_info(), (c))
11529 +
11530 +
11531 +
11532 +/* network flags */
11533 +
11534 +#define __nx_flags(n)  ((n) ? (n)->nx_flags : 0)
11535 +
11536 +#define nx_current_flags()     __nx_flags(current_nx_info())
11537 +
11538 +#define nx_info_flags(n, m, f) \
11539 +       vs_check_flags(__nx_flags(n), m, f)
11540 +
11541 +#define task_nx_flags(t, m, f) \
11542 +       ((t) && nx_info_flags((t)->nx_info, m, f))
11543 +
11544 +#define nx_flags(m, f) nx_info_flags(current_nx_info(), m, f)
11545 +
11546 +
11547 +/* network caps */
11548 +
11549 +#define __nx_ncaps(n)  ((n) ? (n)->nx_ncaps : 0)
11550 +
11551 +#define nx_current_ncaps()     __nx_ncaps(current_nx_info())
11552 +
11553 +#define nx_info_ncaps(n, c)    (__nx_ncaps(n) & (c))
11554 +
11555 +#define nx_ncaps(c)    nx_info_ncaps(current_nx_info(), c)
11556 +
11557 +
11558 +/* context mask capabilities */
11559 +
11560 +#define __vx_mcaps(v)  ((v) ? (v)->vx_ccaps >> 32UL : ~0 )
11561 +
11562 +#define vx_info_mcaps(v, c)    (__vx_mcaps(v) & (c))
11563 +
11564 +#define vx_mcaps(c)    vx_info_mcaps(current_vx_info(), c)
11565 +
11566 +
11567 +/* context bcap mask */
11568 +
11569 +#define __vx_bcaps(v)          ((v)->vx_bcaps)
11570 +
11571 +#define vx_current_bcaps()     __vx_bcaps(current_vx_info())
11572 +
11573 +
11574 +/* mask given bcaps */
11575 +
11576 +#define vx_info_mbcaps(v, c)   ((v) ? cap_intersect(__vx_bcaps(v), c) : c)
11577 +
11578 +#define vx_mbcaps(c)           vx_info_mbcaps(current_vx_info(), c)
11579 +
11580 +
11581 +/* masked cap_bset */
11582 +
11583 +#define vx_info_cap_bset(v)    vx_info_mbcaps(v, current->cap_bset)
11584 +
11585 +#define vx_current_cap_bset()  vx_info_cap_bset(current_vx_info())
11586 +
11587 +#if 0
11588 +#define vx_info_mbcap(v, b) \
11589 +       (!vx_info_flags(v, VXF_STATE_SETUP, 0) ? \
11590 +       vx_info_bcaps(v, b) : (b))
11591 +
11592 +#define task_vx_mbcap(t, b) \
11593 +       vx_info_mbcap((t)->vx_info, (t)->b)
11594 +
11595 +#define vx_mbcap(b)    task_vx_mbcap(current, b)
11596 +#endif
11597 +
11598 +#define vx_cap_raised(v, c, f) cap_raised(vx_info_mbcaps(v, c), f)
11599 +
11600 +#define vx_capable(b, c) (capable(b) || \
11601 +       (cap_raised(current_cap(), b) && vx_ccaps(c)))
11602 +
11603 +#define nx_capable(b, c) (capable(b) || \
11604 +       (cap_raised(current_cap(), b) && nx_ncaps(c)))
11605 +
11606 +#define vx_task_initpid(t, n) \
11607 +       ((t)->vx_info && \
11608 +       ((t)->vx_info->vx_initpid == (n)))
11609 +
11610 +#define vx_current_initpid(n)  vx_task_initpid(current, n)
11611 +
11612 +
11613 +/* context unshare mask */
11614 +
11615 +#define __vx_umask(v)          ((v)->vx_umask)
11616 +
11617 +#define vx_current_umask()     __vx_umask(current_vx_info())
11618 +
11619 +#define vx_can_unshare(b, f) (capable(b) || \
11620 +       (cap_raised(current_cap(), b) && \
11621 +       !((f) & ~vx_current_umask())))
11622 +
11623 +
11624 +#define __vx_state(v)  ((v) ? ((v)->vx_state) : 0)
11625 +
11626 +#define vx_info_state(v, m)    (__vx_state(v) & (m))
11627 +
11628 +
11629 +#define __nx_state(n)  ((n) ? ((n)->nx_state) : 0)
11630 +
11631 +#define nx_info_state(n, m)    (__nx_state(n) & (m))
11632 +
11633 +#endif
11634 diff -NurpP --minimal linux-2.6.38-rc8/include/linux/vserver/cacct.h linux-2.6.38-rc8-vs2.3.0.37-rc6/include/linux/vserver/cacct.h
11635 --- linux-2.6.38-rc8/include/linux/vserver/cacct.h      1970-01-01 01:00:00.000000000 +0100
11636 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/include/linux/vserver/cacct.h       2011-01-29 02:01:07.000000000 +0100
11637 @@ -0,0 +1,15 @@
11638 +#ifndef _VX_CACCT_H
11639 +#define _VX_CACCT_H
11640 +
11641 +
11642 +enum sock_acc_field {
11643 +       VXA_SOCK_UNSPEC = 0,
11644 +       VXA_SOCK_UNIX,
11645 +       VXA_SOCK_INET,
11646 +       VXA_SOCK_INET6,
11647 +       VXA_SOCK_PACKET,
11648 +       VXA_SOCK_OTHER,
11649 +       VXA_SOCK_SIZE   /* array size */
11650 +};
11651 +
11652 +#endif /* _VX_CACCT_H */
11653 diff -NurpP --minimal linux-2.6.38-rc8/include/linux/vserver/cacct_cmd.h linux-2.6.38-rc8-vs2.3.0.37-rc6/include/linux/vserver/cacct_cmd.h
11654 --- linux-2.6.38-rc8/include/linux/vserver/cacct_cmd.h  1970-01-01 01:00:00.000000000 +0100
11655 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/include/linux/vserver/cacct_cmd.h   2011-01-29 02:01:07.000000000 +0100
11656 @@ -0,0 +1,23 @@
11657 +#ifndef _VX_CACCT_CMD_H
11658 +#define _VX_CACCT_CMD_H
11659 +
11660 +
11661 +/* virtual host info name commands */
11662 +
11663 +#define VCMD_sock_stat         VC_CMD(VSTAT, 5, 0)
11664 +
11665 +struct vcmd_sock_stat_v0 {
11666 +       uint32_t field;
11667 +       uint32_t count[3];
11668 +       uint64_t total[3];
11669 +};
11670 +
11671 +
11672 +#ifdef __KERNEL__
11673 +
11674 +#include <linux/compiler.h>
11675 +
11676 +extern int vc_sock_stat(struct vx_info *, void __user *);
11677 +
11678 +#endif /* __KERNEL__ */
11679 +#endif /* _VX_CACCT_CMD_H */
11680 diff -NurpP --minimal linux-2.6.38-rc8/include/linux/vserver/cacct_def.h linux-2.6.38-rc8-vs2.3.0.37-rc6/include/linux/vserver/cacct_def.h
11681 --- linux-2.6.38-rc8/include/linux/vserver/cacct_def.h  1970-01-01 01:00:00.000000000 +0100
11682 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/include/linux/vserver/cacct_def.h   2011-01-29 02:01:07.000000000 +0100
11683 @@ -0,0 +1,43 @@
11684 +#ifndef _VX_CACCT_DEF_H
11685 +#define _VX_CACCT_DEF_H
11686 +
11687 +#include <asm/atomic.h>
11688 +#include <linux/vserver/cacct.h>
11689 +
11690 +
11691 +struct _vx_sock_acc {
11692 +       atomic_long_t count;
11693 +       atomic_long_t total;
11694 +};
11695 +
11696 +/* context sub struct */
11697 +
11698 +struct _vx_cacct {
11699 +       struct _vx_sock_acc sock[VXA_SOCK_SIZE][3];
11700 +       atomic_t slab[8];
11701 +       atomic_t page[6][8];
11702 +};
11703 +
11704 +#ifdef CONFIG_VSERVER_DEBUG
11705 +
11706 +static inline void __dump_vx_cacct(struct _vx_cacct *cacct)
11707 +{
11708 +       int i, j;
11709 +
11710 +       printk("\t_vx_cacct:");
11711 +       for (i = 0; i < 6; i++) {
11712 +               struct _vx_sock_acc *ptr = cacct->sock[i];
11713 +
11714 +               printk("\t [%d] =", i);
11715 +               for (j = 0; j < 3; j++) {
11716 +                       printk(" [%d] = %8lu, %8lu", j,
11717 +                               atomic_long_read(&ptr[j].count),
11718 +                               atomic_long_read(&ptr[j].total));
11719 +               }
11720 +               printk("\n");
11721 +       }
11722 +}
11723 +
11724 +#endif
11725 +
11726 +#endif /* _VX_CACCT_DEF_H */
11727 diff -NurpP --minimal linux-2.6.38-rc8/include/linux/vserver/cacct_int.h linux-2.6.38-rc8-vs2.3.0.37-rc6/include/linux/vserver/cacct_int.h
11728 --- linux-2.6.38-rc8/include/linux/vserver/cacct_int.h  1970-01-01 01:00:00.000000000 +0100
11729 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/include/linux/vserver/cacct_int.h   2011-01-29 02:01:07.000000000 +0100
11730 @@ -0,0 +1,21 @@
11731 +#ifndef _VX_CACCT_INT_H
11732 +#define _VX_CACCT_INT_H
11733 +
11734 +
11735 +#ifdef __KERNEL__
11736 +
11737 +static inline
11738 +unsigned long vx_sock_count(struct _vx_cacct *cacct, int type, int pos)
11739 +{
11740 +       return atomic_long_read(&cacct->sock[type][pos].count);
11741 +}
11742 +
11743 +
11744 +static inline
11745 +unsigned long vx_sock_total(struct _vx_cacct *cacct, int type, int pos)
11746 +{
11747 +       return atomic_long_read(&cacct->sock[type][pos].total);
11748 +}
11749 +
11750 +#endif /* __KERNEL__ */
11751 +#endif /* _VX_CACCT_INT_H */
11752 diff -NurpP --minimal linux-2.6.38-rc8/include/linux/vserver/check.h linux-2.6.38-rc8-vs2.3.0.37-rc6/include/linux/vserver/check.h
11753 --- linux-2.6.38-rc8/include/linux/vserver/check.h      1970-01-01 01:00:00.000000000 +0100
11754 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/include/linux/vserver/check.h       2011-01-29 02:01:07.000000000 +0100
11755 @@ -0,0 +1,89 @@
11756 +#ifndef _VS_CHECK_H
11757 +#define _VS_CHECK_H
11758 +
11759 +
11760 +#define MAX_S_CONTEXT  65535   /* Arbitrary limit */
11761 +
11762 +#ifdef CONFIG_VSERVER_DYNAMIC_IDS
11763 +#define MIN_D_CONTEXT  49152   /* dynamic contexts start here */
11764 +#else
11765 +#define MIN_D_CONTEXT  65536
11766 +#endif
11767 +
11768 +/* check conditions */
11769 +
11770 +#define VS_ADMIN       0x0001
11771 +#define VS_WATCH       0x0002
11772 +#define VS_HIDE                0x0004
11773 +#define VS_HOSTID      0x0008
11774 +
11775 +#define VS_IDENT       0x0010
11776 +#define VS_EQUIV       0x0020
11777 +#define VS_PARENT      0x0040
11778 +#define VS_CHILD       0x0080
11779 +
11780 +#define VS_ARG_MASK    0x00F0
11781 +
11782 +#define VS_DYNAMIC     0x0100
11783 +#define VS_STATIC      0x0200
11784 +
11785 +#define VS_ATR_MASK    0x0F00
11786 +
11787 +#ifdef CONFIG_VSERVER_PRIVACY
11788 +#define VS_ADMIN_P     (0)
11789 +#define VS_WATCH_P     (0)
11790 +#else
11791 +#define VS_ADMIN_P     VS_ADMIN
11792 +#define VS_WATCH_P     VS_WATCH
11793 +#endif
11794 +
11795 +#define VS_HARDIRQ     0x1000
11796 +#define VS_SOFTIRQ     0x2000
11797 +#define VS_IRQ         0x4000
11798 +
11799 +#define VS_IRQ_MASK    0xF000
11800 +
11801 +#include <linux/hardirq.h>
11802 +
11803 +/*
11804 + * check current context for ADMIN/WATCH and
11805 + * optionally against supplied argument
11806 + */
11807 +static inline int __vs_check(int cid, int id, unsigned int mode)
11808 +{
11809 +       if (mode & VS_ARG_MASK) {
11810 +               if ((mode & VS_IDENT) && (id == cid))
11811 +                       return 1;
11812 +       }
11813 +       if (mode & VS_ATR_MASK) {
11814 +               if ((mode & VS_DYNAMIC) &&
11815 +                       (id >= MIN_D_CONTEXT) &&
11816 +                       (id <= MAX_S_CONTEXT))
11817 +                       return 1;
11818 +               if ((mode & VS_STATIC) &&
11819 +                       (id > 1) && (id < MIN_D_CONTEXT))
11820 +                       return 1;
11821 +       }
11822 +       if (mode & VS_IRQ_MASK) {
11823 +               if ((mode & VS_IRQ) && unlikely(in_interrupt()))
11824 +                       return 1;
11825 +               if ((mode & VS_HARDIRQ) && unlikely(in_irq()))
11826 +                       return 1;
11827 +               if ((mode & VS_SOFTIRQ) && unlikely(in_softirq()))
11828 +                       return 1;
11829 +       }
11830 +       return (((mode & VS_ADMIN) && (cid == 0)) ||
11831 +               ((mode & VS_WATCH) && (cid == 1)) ||
11832 +               ((mode & VS_HOSTID) && (id == 0)));
11833 +}
11834 +
11835 +#define vx_check(c, m) __vs_check(vx_current_xid(), c, (m) | VS_IRQ)
11836 +
11837 +#define vx_weak_check(c, m)    ((m) ? vx_check(c, m) : 1)
11838 +
11839 +
11840 +#define nx_check(c, m) __vs_check(nx_current_nid(), c, m)
11841 +
11842 +#define nx_weak_check(c, m)    ((m) ? nx_check(c, m) : 1)
11843 +
11844 +#endif
11845 diff -NurpP --minimal linux-2.6.38-rc8/include/linux/vserver/context.h linux-2.6.38-rc8-vs2.3.0.37-rc6/include/linux/vserver/context.h
11846 --- linux-2.6.38-rc8/include/linux/vserver/context.h    1970-01-01 01:00:00.000000000 +0100
11847 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/include/linux/vserver/context.h     2011-01-31 22:46:21.000000000 +0100
11848 @@ -0,0 +1,189 @@
11849 +#ifndef _VX_CONTEXT_H
11850 +#define _VX_CONTEXT_H
11851 +
11852 +#include <linux/types.h>
11853 +#include <linux/capability.h>
11854 +
11855 +
11856 +/* context flags */
11857 +
11858 +#define VXF_INFO_SCHED         0x00000002
11859 +#define VXF_INFO_NPROC         0x00000004
11860 +#define VXF_INFO_PRIVATE       0x00000008
11861 +
11862 +#define VXF_INFO_INIT          0x00000010
11863 +#define VXF_INFO_HIDE          0x00000020
11864 +#define VXF_INFO_ULIMIT                0x00000040
11865 +#define VXF_INFO_NSPACE                0x00000080
11866 +
11867 +#define VXF_SCHED_HARD         0x00000100
11868 +#define VXF_SCHED_PRIO         0x00000200
11869 +#define VXF_SCHED_PAUSE                0x00000400
11870 +
11871 +#define VXF_VIRT_MEM           0x00010000
11872 +#define VXF_VIRT_UPTIME                0x00020000
11873 +#define VXF_VIRT_CPU           0x00040000
11874 +#define VXF_VIRT_LOAD          0x00080000
11875 +#define VXF_VIRT_TIME          0x00100000
11876 +
11877 +#define VXF_HIDE_MOUNT         0x01000000
11878 +/* was VXF_HIDE_NETIF          0x02000000 */
11879 +#define VXF_HIDE_VINFO         0x04000000
11880 +
11881 +#define VXF_STATE_SETUP                (1ULL << 32)
11882 +#define VXF_STATE_INIT         (1ULL << 33)
11883 +#define VXF_STATE_ADMIN                (1ULL << 34)
11884 +
11885 +#define VXF_SC_HELPER          (1ULL << 36)
11886 +#define VXF_REBOOT_KILL                (1ULL << 37)
11887 +#define VXF_PERSISTENT         (1ULL << 38)
11888 +
11889 +#define VXF_FORK_RSS           (1ULL << 48)
11890 +#define VXF_PROLIFIC           (1ULL << 49)
11891 +
11892 +#define VXF_IGNEG_NICE         (1ULL << 52)
11893 +
11894 +#define VXF_ONE_TIME           (0x0007ULL << 32)
11895 +
11896 +#define VXF_INIT_SET           (VXF_STATE_SETUP | VXF_STATE_INIT | VXF_STATE_ADMIN)
11897 +
11898 +
11899 +/* context migration */
11900 +
11901 +#define VXM_SET_INIT           0x00000001
11902 +#define VXM_SET_REAPER         0x00000002
11903 +
11904 +/* context caps */
11905 +
11906 +#define VXC_CAP_MASK           0x00000000
11907 +
11908 +#define VXC_SET_UTSNAME                0x00000001
11909 +#define VXC_SET_RLIMIT         0x00000002
11910 +#define VXC_FS_SECURITY                0x00000004
11911 +#define VXC_FS_TRUSTED         0x00000008
11912 +#define VXC_TIOCSTI            0x00000010
11913 +
11914 +/* was VXC_RAW_ICMP            0x00000100 */
11915 +#define VXC_SYSLOG             0x00001000
11916 +#define VXC_OOM_ADJUST         0x00002000
11917 +#define VXC_AUDIT_CONTROL      0x00004000
11918 +
11919 +#define VXC_SECURE_MOUNT       0x00010000
11920 +#define VXC_SECURE_REMOUNT     0x00020000
11921 +#define VXC_BINARY_MOUNT       0x00040000
11922 +
11923 +#define VXC_QUOTA_CTL          0x00100000
11924 +#define VXC_ADMIN_MAPPER       0x00200000
11925 +#define VXC_ADMIN_CLOOP                0x00400000
11926 +
11927 +#define VXC_KTHREAD            0x01000000
11928 +#define VXC_NAMESPACE          0x02000000
11929 +
11930 +
11931 +#ifdef __KERNEL__
11932 +
11933 +#include <linux/list.h>
11934 +#include <linux/spinlock.h>
11935 +#include <linux/rcupdate.h>
11936 +
11937 +#include "limit_def.h"
11938 +#include "sched_def.h"
11939 +#include "cvirt_def.h"
11940 +#include "cacct_def.h"
11941 +#include "device_def.h"
11942 +
11943 +#define VX_SPACES      2
11944 +
11945 +struct _vx_info_pc {
11946 +       struct _vx_sched_pc sched_pc;
11947 +       struct _vx_cvirt_pc cvirt_pc;
11948 +};
11949 +
11950 +struct _vx_space {
11951 +       unsigned long vx_nsmask;                /* assignment mask */
11952 +       struct nsproxy *vx_nsproxy;             /* private namespaces */
11953 +       struct fs_struct *vx_fs;                /* private namespace fs */
11954 +       const struct cred *vx_cred;             /* task credentials */
11955 +};
11956 +
11957 +struct vx_info {
11958 +       struct hlist_node vx_hlist;             /* linked list of contexts */
11959 +       xid_t vx_id;                            /* context id */
11960 +       atomic_t vx_usecnt;                     /* usage count */
11961 +       atomic_t vx_tasks;                      /* tasks count */
11962 +       struct vx_info *vx_parent;              /* parent context */
11963 +       int vx_state;                           /* context state */
11964 +
11965 +       struct _vx_space space[VX_SPACES];      /* namespace store */
11966 +
11967 +       uint64_t vx_flags;                      /* context flags */
11968 +       uint64_t vx_ccaps;                      /* context caps (vserver) */
11969 +       kernel_cap_t vx_bcaps;                  /* bounding caps (system) */
11970 +       unsigned long vx_umask;                 /* unshare mask (guest) */
11971 +
11972 +       struct task_struct *vx_reaper;          /* guest reaper process */
11973 +       pid_t vx_initpid;                       /* PID of guest init */
11974 +       int64_t vx_badness_bias;                /* OOM points bias */
11975 +
11976 +       struct _vx_limit limit;                 /* vserver limits */
11977 +       struct _vx_sched sched;                 /* vserver scheduler */
11978 +       struct _vx_cvirt cvirt;                 /* virtual/bias stuff */
11979 +       struct _vx_cacct cacct;                 /* context accounting */
11980 +
11981 +       struct _vx_device dmap;                 /* default device map targets */
11982 +
11983 +#ifndef CONFIG_SMP
11984 +       struct _vx_info_pc info_pc;             /* per cpu data */
11985 +#else
11986 +       struct _vx_info_pc *ptr_pc;             /* per cpu array */
11987 +#endif
11988 +
11989 +       wait_queue_head_t vx_wait;              /* context exit waitqueue */
11990 +       int reboot_cmd;                         /* last sys_reboot() cmd */
11991 +       int exit_code;                          /* last process exit code */
11992 +
11993 +       char vx_name[65];                       /* vserver name */
11994 +};
11995 +
11996 +#ifndef CONFIG_SMP
11997 +#define        vx_ptr_pc(vxi)          (&(vxi)->info_pc)
11998 +#define        vx_per_cpu(vxi, v, id)  vx_ptr_pc(vxi)->v
11999 +#else
12000 +#define        vx_ptr_pc(vxi)          ((vxi)->ptr_pc)
12001 +#define        vx_per_cpu(vxi, v, id)  per_cpu_ptr(vx_ptr_pc(vxi), id)->v
12002 +#endif
12003 +
12004 +#define        vx_cpu(vxi, v)          vx_per_cpu(vxi, v, smp_processor_id())
12005 +
12006 +
12007 +struct vx_info_save {
12008 +       struct vx_info *vxi;
12009 +       xid_t xid;
12010 +};
12011 +
12012 +
12013 +/* status flags */
12014 +
12015 +#define VXS_HASHED     0x0001
12016 +#define VXS_PAUSED     0x0010
12017 +#define VXS_SHUTDOWN   0x0100
12018 +#define VXS_HELPER     0x1000
12019 +#define VXS_RELEASED   0x8000
12020 +
12021 +
12022 +extern void claim_vx_info(struct vx_info *, struct task_struct *);
12023 +extern void release_vx_info(struct vx_info *, struct task_struct *);
12024 +
12025 +extern struct vx_info *lookup_vx_info(int);
12026 +extern struct vx_info *lookup_or_create_vx_info(int);
12027 +
12028 +extern int get_xid_list(int, unsigned int *, int);
12029 +extern int xid_is_hashed(xid_t);
12030 +
12031 +extern int vx_migrate_task(struct task_struct *, struct vx_info *, int);
12032 +
12033 +extern long vs_state_change(struct vx_info *, unsigned int);
12034 +
12035 +
12036 +#endif /* __KERNEL__ */
12037 +#endif /* _VX_CONTEXT_H */
12038 diff -NurpP --minimal linux-2.6.38-rc8/include/linux/vserver/context_cmd.h linux-2.6.38-rc8-vs2.3.0.37-rc6/include/linux/vserver/context_cmd.h
12039 --- linux-2.6.38-rc8/include/linux/vserver/context_cmd.h        1970-01-01 01:00:00.000000000 +0100
12040 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/include/linux/vserver/context_cmd.h 2011-01-29 02:01:07.000000000 +0100
12041 @@ -0,0 +1,145 @@
12042 +#ifndef _VX_CONTEXT_CMD_H
12043 +#define _VX_CONTEXT_CMD_H
12044 +
12045 +
12046 +/* vinfo commands */
12047 +
12048 +#define VCMD_task_xid          VC_CMD(VINFO, 1, 0)
12049 +
12050 +#ifdef __KERNEL__
12051 +extern int vc_task_xid(uint32_t);
12052 +
12053 +#endif /* __KERNEL__ */
12054 +
12055 +#define VCMD_vx_info           VC_CMD(VINFO, 5, 0)
12056 +
12057 +struct vcmd_vx_info_v0 {
12058 +       uint32_t xid;
12059 +       uint32_t initpid;
12060 +       /* more to come */
12061 +};
12062 +
12063 +#ifdef __KERNEL__
12064 +extern int vc_vx_info(struct vx_info *, void __user *);
12065 +
12066 +#endif /* __KERNEL__ */
12067 +
12068 +#define VCMD_ctx_stat          VC_CMD(VSTAT, 0, 0)
12069 +
12070 +struct vcmd_ctx_stat_v0 {
12071 +       uint32_t usecnt;
12072 +       uint32_t tasks;
12073 +       /* more to come */
12074 +};
12075 +
12076 +#ifdef __KERNEL__
12077 +extern int vc_ctx_stat(struct vx_info *, void __user *);
12078 +
12079 +#endif /* __KERNEL__ */
12080 +
12081 +/* context commands */
12082 +
12083 +#define VCMD_ctx_create_v0     VC_CMD(VPROC, 1, 0)
12084 +#define VCMD_ctx_create                VC_CMD(VPROC, 1, 1)
12085 +
12086 +struct vcmd_ctx_create {
12087 +       uint64_t flagword;
12088 +};
12089 +
12090 +#define VCMD_ctx_migrate_v0    VC_CMD(PROCMIG, 1, 0)
12091 +#define VCMD_ctx_migrate       VC_CMD(PROCMIG, 1, 1)
12092 +
12093 +struct vcmd_ctx_migrate {
12094 +       uint64_t flagword;
12095 +};
12096 +
12097 +#ifdef __KERNEL__
12098 +extern int vc_ctx_create(uint32_t, void __user *);
12099 +extern int vc_ctx_migrate(struct vx_info *, void __user *);
12100 +
12101 +#endif /* __KERNEL__ */
12102 +
12103 +
12104 +/* flag commands */
12105 +
12106 +#define VCMD_get_cflags                VC_CMD(FLAGS, 1, 0)
12107 +#define VCMD_set_cflags                VC_CMD(FLAGS, 2, 0)
12108 +
12109 +struct vcmd_ctx_flags_v0 {
12110 +       uint64_t flagword;
12111 +       uint64_t mask;
12112 +};
12113 +
12114 +#ifdef __KERNEL__
12115 +extern int vc_get_cflags(struct vx_info *, void __user *);
12116 +extern int vc_set_cflags(struct vx_info *, void __user *);
12117 +
12118 +#endif /* __KERNEL__ */
12119 +
12120 +
12121 +/* context caps commands */
12122 +
12123 +#define VCMD_get_ccaps         VC_CMD(FLAGS, 3, 1)
12124 +#define VCMD_set_ccaps         VC_CMD(FLAGS, 4, 1)
12125 +
12126 +struct vcmd_ctx_caps_v1 {
12127 +       uint64_t ccaps;
12128 +       uint64_t cmask;
12129 +};
12130 +
12131 +#ifdef __KERNEL__
12132 +extern int vc_get_ccaps(struct vx_info *, void __user *);
12133 +extern int vc_set_ccaps(struct vx_info *, void __user *);
12134 +
12135 +#endif /* __KERNEL__ */
12136 +
12137 +
12138 +/* bcaps commands */
12139 +
12140 +#define VCMD_get_bcaps         VC_CMD(FLAGS, 9, 0)
12141 +#define VCMD_set_bcaps         VC_CMD(FLAGS, 10, 0)
12142 +
12143 +struct vcmd_bcaps {
12144 +       uint64_t bcaps;
12145 +       uint64_t bmask;
12146 +};
12147 +
12148 +#ifdef __KERNEL__
12149 +extern int vc_get_bcaps(struct vx_info *, void __user *);
12150 +extern int vc_set_bcaps(struct vx_info *, void __user *);
12151 +
12152 +#endif /* __KERNEL__ */
12153 +
12154 +
12155 +/* umask commands */
12156 +
12157 +#define VCMD_get_umask         VC_CMD(FLAGS, 13, 0)
12158 +#define VCMD_set_umask         VC_CMD(FLAGS, 14, 0)
12159 +
12160 +struct vcmd_umask {
12161 +       uint64_t umask;
12162 +       uint64_t mask;
12163 +};
12164 +
12165 +#ifdef __KERNEL__
12166 +extern int vc_get_umask(struct vx_info *, void __user *);
12167 +extern int vc_set_umask(struct vx_info *, void __user *);
12168 +
12169 +#endif /* __KERNEL__ */
12170 +
12171 +
12172 +/* OOM badness */
12173 +
12174 +#define VCMD_get_badness       VC_CMD(MEMCTRL, 5, 0)
12175 +#define VCMD_set_badness       VC_CMD(MEMCTRL, 6, 0)
12176 +
12177 +struct vcmd_badness_v0 {
12178 +       int64_t bias;
12179 +};
12180 +
12181 +#ifdef __KERNEL__
12182 +extern int vc_get_badness(struct vx_info *, void __user *);
12183 +extern int vc_set_badness(struct vx_info *, void __user *);
12184 +
12185 +#endif /* __KERNEL__ */
12186 +#endif /* _VX_CONTEXT_CMD_H */
12187 diff -NurpP --minimal linux-2.6.38-rc8/include/linux/vserver/cvirt.h linux-2.6.38-rc8-vs2.3.0.37-rc6/include/linux/vserver/cvirt.h
12188 --- linux-2.6.38-rc8/include/linux/vserver/cvirt.h      1970-01-01 01:00:00.000000000 +0100
12189 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/include/linux/vserver/cvirt.h       2011-01-29 02:01:07.000000000 +0100
12190 @@ -0,0 +1,20 @@
12191 +#ifndef _VX_CVIRT_H
12192 +#define _VX_CVIRT_H
12193 +
12194 +
12195 +#ifdef __KERNEL__
12196 +
12197 +struct timespec;
12198 +
12199 +void vx_vsi_uptime(struct timespec *, struct timespec *);
12200 +
12201 +
12202 +struct vx_info;
12203 +
12204 +void vx_update_load(struct vx_info *);
12205 +
12206 +
12207 +int vx_do_syslog(int, char __user *, int);
12208 +
12209 +#endif /* __KERNEL__ */
12210 +#endif /* _VX_CVIRT_H */
12211 diff -NurpP --minimal linux-2.6.38-rc8/include/linux/vserver/cvirt_cmd.h linux-2.6.38-rc8-vs2.3.0.37-rc6/include/linux/vserver/cvirt_cmd.h
12212 --- linux-2.6.38-rc8/include/linux/vserver/cvirt_cmd.h  1970-01-01 01:00:00.000000000 +0100
12213 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/include/linux/vserver/cvirt_cmd.h   2011-01-29 02:01:07.000000000 +0100
12214 @@ -0,0 +1,53 @@
12215 +#ifndef _VX_CVIRT_CMD_H
12216 +#define _VX_CVIRT_CMD_H
12217 +
12218 +
12219 +/* virtual host info name commands */
12220 +
12221 +#define VCMD_set_vhi_name      VC_CMD(VHOST, 1, 0)
12222 +#define VCMD_get_vhi_name      VC_CMD(VHOST, 2, 0)
12223 +
12224 +struct vcmd_vhi_name_v0 {
12225 +       uint32_t field;
12226 +       char name[65];
12227 +};
12228 +
12229 +
12230 +enum vhi_name_field {
12231 +       VHIN_CONTEXT = 0,
12232 +       VHIN_SYSNAME,
12233 +       VHIN_NODENAME,
12234 +       VHIN_RELEASE,
12235 +       VHIN_VERSION,
12236 +       VHIN_MACHINE,
12237 +       VHIN_DOMAINNAME,
12238 +};
12239 +
12240 +
12241 +#ifdef __KERNEL__
12242 +
12243 +#include <linux/compiler.h>
12244 +
12245 +extern int vc_set_vhi_name(struct vx_info *, void __user *);
12246 +extern int vc_get_vhi_name(struct vx_info *, void __user *);
12247 +
12248 +#endif /* __KERNEL__ */
12249 +
12250 +#define VCMD_virt_stat         VC_CMD(VSTAT, 3, 0)
12251 +
12252 +struct vcmd_virt_stat_v0 {
12253 +       uint64_t offset;
12254 +       uint64_t uptime;
12255 +       uint32_t nr_threads;
12256 +       uint32_t nr_running;
12257 +       uint32_t nr_uninterruptible;
12258 +       uint32_t nr_onhold;
12259 +       uint32_t nr_forks;
12260 +       uint32_t load[3];
12261 +};
12262 +
12263 +#ifdef __KERNEL__
12264 +extern int vc_virt_stat(struct vx_info *, void __user *);
12265 +
12266 +#endif /* __KERNEL__ */
12267 +#endif /* _VX_CVIRT_CMD_H */
12268 diff -NurpP --minimal linux-2.6.38-rc8/include/linux/vserver/cvirt_def.h linux-2.6.38-rc8-vs2.3.0.37-rc6/include/linux/vserver/cvirt_def.h
12269 --- linux-2.6.38-rc8/include/linux/vserver/cvirt_def.h  1970-01-01 01:00:00.000000000 +0100
12270 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/include/linux/vserver/cvirt_def.h   2011-01-29 02:01:07.000000000 +0100
12271 @@ -0,0 +1,80 @@
12272 +#ifndef _VX_CVIRT_DEF_H
12273 +#define _VX_CVIRT_DEF_H
12274 +
12275 +#include <linux/jiffies.h>
12276 +#include <linux/spinlock.h>
12277 +#include <linux/wait.h>
12278 +#include <linux/time.h>
12279 +#include <asm/atomic.h>
12280 +
12281 +
12282 +struct _vx_usage_stat {
12283 +       uint64_t user;
12284 +       uint64_t nice;
12285 +       uint64_t system;
12286 +       uint64_t softirq;
12287 +       uint64_t irq;
12288 +       uint64_t idle;
12289 +       uint64_t iowait;
12290 +};
12291 +
12292 +struct _vx_syslog {
12293 +       wait_queue_head_t log_wait;
12294 +       spinlock_t logbuf_lock;         /* lock for the log buffer */
12295 +
12296 +       unsigned long log_start;        /* next char to be read by syslog() */
12297 +       unsigned long con_start;        /* next char to be sent to consoles */
12298 +       unsigned long log_end;  /* most-recently-written-char + 1 */
12299 +       unsigned long logged_chars;     /* #chars since last read+clear operation */
12300 +
12301 +       char log_buf[1024];
12302 +};
12303 +
12304 +
12305 +/* context sub struct */
12306 +
12307 +struct _vx_cvirt {
12308 +       atomic_t nr_threads;            /* number of current threads */
12309 +       atomic_t nr_running;            /* number of running threads */
12310 +       atomic_t nr_uninterruptible;    /* number of uninterruptible threads */
12311 +
12312 +       atomic_t nr_onhold;             /* processes on hold */
12313 +       uint32_t onhold_last;           /* jiffies when put on hold */
12314 +
12315 +       struct timespec bias_ts;        /* time offset to the host */
12316 +       struct timespec bias_idle;
12317 +       struct timespec bias_uptime;    /* context creation point */
12318 +       uint64_t bias_clock;            /* offset in clock_t */
12319 +
12320 +       spinlock_t load_lock;           /* lock for the load averages */
12321 +       atomic_t load_updates;          /* nr of load updates done so far */
12322 +       uint32_t load_last;             /* last time load was calculated */
12323 +       uint32_t load[3];               /* load averages 1,5,15 */
12324 +
12325 +       atomic_t total_forks;           /* number of forks so far */
12326 +
12327 +       struct _vx_syslog syslog;
12328 +};
12329 +
12330 +struct _vx_cvirt_pc {
12331 +       struct _vx_usage_stat cpustat;
12332 +};
12333 +
12334 +
12335 +#ifdef CONFIG_VSERVER_DEBUG
12336 +
12337 +static inline void __dump_vx_cvirt(struct _vx_cvirt *cvirt)
12338 +{
12339 +       printk("\t_vx_cvirt:\n");
12340 +       printk("\t threads: %4d, %4d, %4d, %4d\n",
12341 +               atomic_read(&cvirt->nr_threads),
12342 +               atomic_read(&cvirt->nr_running),
12343 +               atomic_read(&cvirt->nr_uninterruptible),
12344 +               atomic_read(&cvirt->nr_onhold));
12345 +       /* add rest here */
12346 +       printk("\t total_forks = %d\n", atomic_read(&cvirt->total_forks));
12347 +}
12348 +
12349 +#endif
12350 +
12351 +#endif /* _VX_CVIRT_DEF_H */
12352 diff -NurpP --minimal linux-2.6.38-rc8/include/linux/vserver/debug.h linux-2.6.38-rc8-vs2.3.0.37-rc6/include/linux/vserver/debug.h
12353 --- linux-2.6.38-rc8/include/linux/vserver/debug.h      1970-01-01 01:00:00.000000000 +0100
12354 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/include/linux/vserver/debug.h       2011-01-29 02:01:07.000000000 +0100
12355 @@ -0,0 +1,140 @@
12356 +#ifndef _VX_DEBUG_H
12357 +#define _VX_DEBUG_H
12358 +
12359 +
12360 +#define VXD_CBIT(n, m) (vx_debug_ ## n & (1 << (m)))
12361 +#define VXD_CMIN(n, m) (vx_debug_ ## n > (m))
12362 +#define VXD_MASK(n, m) (vx_debug_ ## n & (m))
12363 +
12364 +#define VXD_DEV(d)     (d), (d)->bd_inode->i_ino,              \
12365 +                       imajor((d)->bd_inode), iminor((d)->bd_inode)
12366 +#define VXF_DEV                "%p[%lu,%d:%d]"
12367 +
12368 +#if    defined(CONFIG_QUOTES_UTF8)
12369 +#define        VS_Q_LQM        "\xc2\xbb"
12370 +#define        VS_Q_RQM        "\xc2\xab"
12371 +#elif  defined(CONFIG_QUOTES_ASCII)
12372 +#define        VS_Q_LQM        "\x27"
12373 +#define        VS_Q_RQM        "\x27"
12374 +#else
12375 +#define        VS_Q_LQM        "\xbb"
12376 +#define        VS_Q_RQM        "\xab"
12377 +#endif
12378 +
12379 +#define        VS_Q(f)         VS_Q_LQM f VS_Q_RQM
12380 +
12381 +
12382 +#define vxd_path(p)                                            \
12383 +       ({ static char _buffer[PATH_MAX];                       \
12384 +          d_path(p, _buffer, sizeof(_buffer)); })
12385 +
12386 +#define vxd_cond_path(n)                                       \
12387 +       ((n) ? vxd_path(&(n)->path) : "<null>" )
12388 +
12389 +
12390 +#ifdef CONFIG_VSERVER_DEBUG
12391 +
12392 +extern unsigned int vx_debug_switch;
12393 +extern unsigned int vx_debug_xid;
12394 +extern unsigned int vx_debug_nid;
12395 +extern unsigned int vx_debug_tag;
12396 +extern unsigned int vx_debug_net;
12397 +extern unsigned int vx_debug_limit;
12398 +extern unsigned int vx_debug_cres;
12399 +extern unsigned int vx_debug_dlim;
12400 +extern unsigned int vx_debug_quota;
12401 +extern unsigned int vx_debug_cvirt;
12402 +extern unsigned int vx_debug_space;
12403 +extern unsigned int vx_debug_misc;
12404 +
12405 +
12406 +#define VX_LOGLEVEL    "vxD: "
12407 +#define VX_PROC_FMT    "%p: "
12408 +#define VX_PROCESS     current
12409 +
12410 +#define vxdprintk(c, f, x...)                                  \
12411 +       do {                                                    \
12412 +               if (c)                                          \
12413 +                       printk(VX_LOGLEVEL VX_PROC_FMT f "\n",  \
12414 +                               VX_PROCESS , ##x);              \
12415 +       } while (0)
12416 +
12417 +#define vxlprintk(c, f, x...)                                  \
12418 +       do {                                                    \
12419 +               if (c)                                          \
12420 +                       printk(VX_LOGLEVEL f " @%s:%d\n", x);   \
12421 +       } while (0)
12422 +
12423 +#define vxfprintk(c, f, x...)                                  \
12424 +       do {                                                    \
12425 +               if (c)                                          \
12426 +                       printk(VX_LOGLEVEL f " %s@%s:%d\n", x); \
12427 +       } while (0)
12428 +
12429 +
12430 +struct vx_info;
12431 +
12432 +void dump_vx_info(struct vx_info *, int);
12433 +void dump_vx_info_inactive(int);
12434 +
12435 +#else  /* CONFIG_VSERVER_DEBUG */
12436 +
12437 +#define vx_debug_switch 0
12438 +#define vx_debug_xid   0
12439 +#define vx_debug_nid   0
12440 +#define vx_debug_tag   0
12441 +#define vx_debug_net   0
12442 +#define vx_debug_limit 0
12443 +#define vx_debug_cres  0
12444 +#define vx_debug_dlim  0
12445 +#define vx_debug_cvirt 0
12446 +
12447 +#define vxdprintk(x...) do { } while (0)
12448 +#define vxlprintk(x...) do { } while (0)
12449 +#define vxfprintk(x...) do { } while (0)
12450 +
12451 +#endif /* CONFIG_VSERVER_DEBUG */
12452 +
12453 +
12454 +#ifdef CONFIG_VSERVER_WARN
12455 +
12456 +#define VX_WARNLEVEL   KERN_WARNING "vxW: "
12457 +#define VX_WARN_TASK   "[" VS_Q("%s") ",%u:#%u|%u|%u] "
12458 +#define VX_WARN_XID    "[xid #%u] "
12459 +#define VX_WARN_NID    "[nid #%u] "
12460 +#define VX_WARN_TAG    "[tag #%u] "
12461 +
12462 +#define vxwprintk(c, f, x...)                                  \
12463 +       do {                                                    \
12464 +               if (c)                                          \
12465 +                       printk(VX_WARNLEVEL f "\n", ##x);       \
12466 +       } while (0)
12467 +
12468 +#else  /* CONFIG_VSERVER_WARN */
12469 +
12470 +#define vxwprintk(x...) do { } while (0)
12471 +
12472 +#endif /* CONFIG_VSERVER_WARN */
12473 +
12474 +#define vxwprintk_task(c, f, x...)                             \
12475 +       vxwprintk(c, VX_WARN_TASK f,                            \
12476 +               current->comm, current->pid,                    \
12477 +               current->xid, current->nid, current->tag, ##x)
12478 +#define vxwprintk_xid(c, f, x...)                              \
12479 +       vxwprintk(c, VX_WARN_XID f, current->xid, x)
12480 +#define vxwprintk_nid(c, f, x...)                              \
12481 +       vxwprintk(c, VX_WARN_NID f, current->nid, x)
12482 +#define vxwprintk_tag(c, f, x...)                              \
12483 +       vxwprintk(c, VX_WARN_TAG f, current->tag, x)
12484 +
12485 +#ifdef CONFIG_VSERVER_DEBUG
12486 +#define vxd_assert_lock(l)     assert_spin_locked(l)
12487 +#define vxd_assert(c, f, x...) vxlprintk(!(c), \
12488 +       "assertion [" f "] failed.", ##x, __FILE__, __LINE__)
12489 +#else
12490 +#define vxd_assert_lock(l)     do { } while (0)
12491 +#define vxd_assert(c, f, x...) do { } while (0)
12492 +#endif
12493 +
12494 +
12495 +#endif /* _VX_DEBUG_H */
12496 diff -NurpP --minimal linux-2.6.38-rc8/include/linux/vserver/debug_cmd.h linux-2.6.38-rc8-vs2.3.0.37-rc6/include/linux/vserver/debug_cmd.h
12497 --- linux-2.6.38-rc8/include/linux/vserver/debug_cmd.h  1970-01-01 01:00:00.000000000 +0100
12498 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/include/linux/vserver/debug_cmd.h   2011-01-29 02:01:07.000000000 +0100
12499 @@ -0,0 +1,58 @@
12500 +#ifndef _VX_DEBUG_CMD_H
12501 +#define _VX_DEBUG_CMD_H
12502 +
12503 +
12504 +/* debug commands */
12505 +
12506 +#define VCMD_dump_history      VC_CMD(DEBUG, 1, 0)
12507 +
12508 +#define VCMD_read_history      VC_CMD(DEBUG, 5, 0)
12509 +#define VCMD_read_monitor      VC_CMD(DEBUG, 6, 0)
12510 +
12511 +struct  vcmd_read_history_v0 {
12512 +       uint32_t index;
12513 +       uint32_t count;
12514 +       char __user *data;
12515 +};
12516 +
12517 +struct  vcmd_read_monitor_v0 {
12518 +       uint32_t index;
12519 +       uint32_t count;
12520 +       char __user *data;
12521 +};
12522 +
12523 +
12524 +#ifdef __KERNEL__
12525 +
12526 +#ifdef CONFIG_COMPAT
12527 +
12528 +#include <asm/compat.h>
12529 +
12530 +struct vcmd_read_history_v0_x32 {
12531 +       uint32_t index;
12532 +       uint32_t count;
12533 +       compat_uptr_t data_ptr;
12534 +};
12535 +
12536 +struct vcmd_read_monitor_v0_x32 {
12537 +       uint32_t index;
12538 +       uint32_t count;
12539 +       compat_uptr_t data_ptr;
12540 +};
12541 +
12542 +#endif  /* CONFIG_COMPAT */
12543 +
12544 +extern int vc_dump_history(uint32_t);
12545 +
12546 +extern int vc_read_history(uint32_t, void __user *);
12547 +extern int vc_read_monitor(uint32_t, void __user *);
12548 +
12549 +#ifdef CONFIG_COMPAT
12550 +
12551 +extern int vc_read_history_x32(uint32_t, void __user *);
12552 +extern int vc_read_monitor_x32(uint32_t, void __user *);
12553 +
12554 +#endif  /* CONFIG_COMPAT */
12555 +
12556 +#endif /* __KERNEL__ */
12557 +#endif /* _VX_DEBUG_CMD_H */
12558 diff -NurpP --minimal linux-2.6.38-rc8/include/linux/vserver/device.h linux-2.6.38-rc8-vs2.3.0.37-rc6/include/linux/vserver/device.h
12559 --- linux-2.6.38-rc8/include/linux/vserver/device.h     1970-01-01 01:00:00.000000000 +0100
12560 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/include/linux/vserver/device.h      2011-01-29 02:01:07.000000000 +0100
12561 @@ -0,0 +1,15 @@
12562 +#ifndef _VX_DEVICE_H
12563 +#define _VX_DEVICE_H
12564 +
12565 +
12566 +#define DATTR_CREATE   0x00000001
12567 +#define DATTR_OPEN     0x00000002
12568 +
12569 +#define DATTR_REMAP    0x00000010
12570 +
12571 +#define DATTR_MASK     0x00000013
12572 +
12573 +
12574 +#else  /* _VX_DEVICE_H */
12575 +#warning duplicate inclusion
12576 +#endif /* _VX_DEVICE_H */
12577 diff -NurpP --minimal linux-2.6.38-rc8/include/linux/vserver/device_cmd.h linux-2.6.38-rc8-vs2.3.0.37-rc6/include/linux/vserver/device_cmd.h
12578 --- linux-2.6.38-rc8/include/linux/vserver/device_cmd.h 1970-01-01 01:00:00.000000000 +0100
12579 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/include/linux/vserver/device_cmd.h  2011-01-29 02:01:07.000000000 +0100
12580 @@ -0,0 +1,44 @@
12581 +#ifndef _VX_DEVICE_CMD_H
12582 +#define _VX_DEVICE_CMD_H
12583 +
12584 +
12585 +/*  device vserver commands */
12586 +
12587 +#define VCMD_set_mapping       VC_CMD(DEVICE, 1, 0)
12588 +#define VCMD_unset_mapping     VC_CMD(DEVICE, 2, 0)
12589 +
12590 +struct vcmd_set_mapping_v0 {
12591 +       const char __user *device;
12592 +       const char __user *target;
12593 +       uint32_t flags;
12594 +};
12595 +
12596 +
12597 +#ifdef __KERNEL__
12598 +
12599 +#ifdef CONFIG_COMPAT
12600 +
12601 +#include <asm/compat.h>
12602 +
12603 +struct vcmd_set_mapping_v0_x32 {
12604 +       compat_uptr_t device_ptr;
12605 +       compat_uptr_t target_ptr;
12606 +       uint32_t flags;
12607 +};
12608 +
12609 +#endif /* CONFIG_COMPAT */
12610 +
12611 +#include <linux/compiler.h>
12612 +
12613 +extern int vc_set_mapping(struct vx_info *, void __user *);
12614 +extern int vc_unset_mapping(struct vx_info *, void __user *);
12615 +
12616 +#ifdef CONFIG_COMPAT
12617 +
12618 +extern int vc_set_mapping_x32(struct vx_info *, void __user *);
12619 +extern int vc_unset_mapping_x32(struct vx_info *, void __user *);
12620 +
12621 +#endif /* CONFIG_COMPAT */
12622 +
12623 +#endif /* __KERNEL__ */
12624 +#endif /* _VX_DEVICE_CMD_H */
12625 diff -NurpP --minimal linux-2.6.38-rc8/include/linux/vserver/device_def.h linux-2.6.38-rc8-vs2.3.0.37-rc6/include/linux/vserver/device_def.h
12626 --- linux-2.6.38-rc8/include/linux/vserver/device_def.h 1970-01-01 01:00:00.000000000 +0100
12627 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/include/linux/vserver/device_def.h  2011-01-29 02:01:07.000000000 +0100
12628 @@ -0,0 +1,17 @@
12629 +#ifndef _VX_DEVICE_DEF_H
12630 +#define _VX_DEVICE_DEF_H
12631 +
12632 +#include <linux/types.h>
12633 +
12634 +struct vx_dmap_target {
12635 +       dev_t target;
12636 +       uint32_t flags;
12637 +};
12638 +
12639 +struct _vx_device {
12640 +#ifdef CONFIG_VSERVER_DEVICE
12641 +       struct vx_dmap_target targets[2];
12642 +#endif
12643 +};
12644 +
12645 +#endif /* _VX_DEVICE_DEF_H */
12646 diff -NurpP --minimal linux-2.6.38-rc8/include/linux/vserver/dlimit.h linux-2.6.38-rc8-vs2.3.0.37-rc6/include/linux/vserver/dlimit.h
12647 --- linux-2.6.38-rc8/include/linux/vserver/dlimit.h     1970-01-01 01:00:00.000000000 +0100
12648 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/include/linux/vserver/dlimit.h      2011-01-29 02:01:07.000000000 +0100
12649 @@ -0,0 +1,54 @@
12650 +#ifndef _VX_DLIMIT_H
12651 +#define _VX_DLIMIT_H
12652 +
12653 +#include "switch.h"
12654 +
12655 +
12656 +#ifdef __KERNEL__
12657 +
12658 +/*      keep in sync with CDLIM_INFINITY       */
12659 +
12660 +#define DLIM_INFINITY          (~0ULL)
12661 +
12662 +#include <linux/spinlock.h>
12663 +#include <linux/rcupdate.h>
12664 +
12665 +struct super_block;
12666 +
12667 +struct dl_info {
12668 +       struct hlist_node dl_hlist;             /* linked list of contexts */
12669 +       struct rcu_head dl_rcu;                 /* the rcu head */
12670 +       tag_t dl_tag;                           /* context tag */
12671 +       atomic_t dl_usecnt;                     /* usage count */
12672 +       atomic_t dl_refcnt;                     /* reference count */
12673 +
12674 +       struct super_block *dl_sb;              /* associated superblock */
12675 +
12676 +       spinlock_t dl_lock;                     /* protect the values */
12677 +
12678 +       unsigned long long dl_space_used;       /* used space in bytes */
12679 +       unsigned long long dl_space_total;      /* maximum space in bytes */
12680 +       unsigned long dl_inodes_used;           /* used inodes */
12681 +       unsigned long dl_inodes_total;          /* maximum inodes */
12682 +
12683 +       unsigned int dl_nrlmult;                /* non root limit mult */
12684 +};
12685 +
12686 +struct rcu_head;
12687 +
12688 +extern void rcu_free_dl_info(struct rcu_head *);
12689 +extern void unhash_dl_info(struct dl_info *);
12690 +
12691 +extern struct dl_info *locate_dl_info(struct super_block *, tag_t);
12692 +
12693 +
12694 +struct kstatfs;
12695 +
12696 +extern void vx_vsi_statfs(struct super_block *, struct kstatfs *);
12697 +
12698 +typedef uint64_t dlsize_t;
12699 +
12700 +#endif /* __KERNEL__ */
12701 +#else  /* _VX_DLIMIT_H */
12702 +#warning duplicate inclusion
12703 +#endif /* _VX_DLIMIT_H */
12704 diff -NurpP --minimal linux-2.6.38-rc8/include/linux/vserver/dlimit_cmd.h linux-2.6.38-rc8-vs2.3.0.37-rc6/include/linux/vserver/dlimit_cmd.h
12705 --- linux-2.6.38-rc8/include/linux/vserver/dlimit_cmd.h 1970-01-01 01:00:00.000000000 +0100
12706 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/include/linux/vserver/dlimit_cmd.h  2011-01-29 02:01:07.000000000 +0100
12707 @@ -0,0 +1,109 @@
12708 +#ifndef _VX_DLIMIT_CMD_H
12709 +#define _VX_DLIMIT_CMD_H
12710 +
12711 +
12712 +/*  dlimit vserver commands */
12713 +
12714 +#define VCMD_add_dlimit                VC_CMD(DLIMIT, 1, 0)
12715 +#define VCMD_rem_dlimit                VC_CMD(DLIMIT, 2, 0)
12716 +
12717 +#define VCMD_set_dlimit                VC_CMD(DLIMIT, 5, 0)
12718 +#define VCMD_get_dlimit                VC_CMD(DLIMIT, 6, 0)
12719 +
12720 +struct vcmd_ctx_dlimit_base_v0 {
12721 +       const char __user *name;
12722 +       uint32_t flags;
12723 +};
12724 +
12725 +struct vcmd_ctx_dlimit_v0 {
12726 +       const char __user *name;
12727 +       uint32_t space_used;                    /* used space in kbytes */
12728 +       uint32_t space_total;                   /* maximum space in kbytes */
12729 +       uint32_t inodes_used;                   /* used inodes */
12730 +       uint32_t inodes_total;                  /* maximum inodes */
12731 +       uint32_t reserved;                      /* reserved for root in % */
12732 +       uint32_t flags;
12733 +};
12734 +
12735 +#define CDLIM_UNSET            ((uint32_t)0UL)
12736 +#define CDLIM_INFINITY         ((uint32_t)~0UL)
12737 +#define CDLIM_KEEP             ((uint32_t)~1UL)
12738 +
12739 +#define DLIME_UNIT     0
12740 +#define DLIME_KILO     1
12741 +#define DLIME_MEGA     2
12742 +#define DLIME_GIGA     3
12743 +
12744 +#define DLIMF_SHIFT    0x10
12745 +
12746 +#define DLIMS_USED     0
12747 +#define DLIMS_TOTAL    2
12748 +
12749 +static inline
12750 +uint64_t dlimit_space_32to64(uint32_t val, uint32_t flags, int shift)
12751 +{
12752 +       int exp = (flags & DLIMF_SHIFT) ?
12753 +               (flags >> shift) & DLIME_GIGA : DLIME_KILO;
12754 +       return ((uint64_t)val) << (10 * exp);
12755 +}
12756 +
12757 +static inline
12758 +uint32_t dlimit_space_64to32(uint64_t val, uint32_t *flags, int shift)
12759 +{
12760 +       int exp = 0;
12761 +
12762 +       if (*flags & DLIMF_SHIFT) {
12763 +               while (val > (1LL << 32) && (exp < 3)) {
12764 +                       val >>= 10;
12765 +                       exp++;
12766 +               }
12767 +               *flags &= ~(DLIME_GIGA << shift);
12768 +               *flags |= exp << shift;
12769 +       } else
12770 +               val >>= 10;
12771 +       return val;
12772 +}
12773 +
12774 +#ifdef __KERNEL__
12775 +
12776 +#ifdef CONFIG_COMPAT
12777 +
12778 +#include <asm/compat.h>
12779 +
12780 +struct vcmd_ctx_dlimit_base_v0_x32 {
12781 +       compat_uptr_t name_ptr;
12782 +       uint32_t flags;
12783 +};
12784 +
12785 +struct vcmd_ctx_dlimit_v0_x32 {
12786 +       compat_uptr_t name_ptr;
12787 +       uint32_t space_used;                    /* used space in kbytes */
12788 +       uint32_t space_total;                   /* maximum space in kbytes */
12789 +       uint32_t inodes_used;                   /* used inodes */
12790 +       uint32_t inodes_total;                  /* maximum inodes */
12791 +       uint32_t reserved;                      /* reserved for root in % */
12792 +       uint32_t flags;
12793 +};
12794 +
12795 +#endif /* CONFIG_COMPAT */
12796 +
12797 +#include <linux/compiler.h>
12798 +
12799 +extern int vc_add_dlimit(uint32_t, void __user *);
12800 +extern int vc_rem_dlimit(uint32_t, void __user *);
12801 +
12802 +extern int vc_set_dlimit(uint32_t, void __user *);
12803 +extern int vc_get_dlimit(uint32_t, void __user *);
12804 +
12805 +#ifdef CONFIG_COMPAT
12806 +
12807 +extern int vc_add_dlimit_x32(uint32_t, void __user *);
12808 +extern int vc_rem_dlimit_x32(uint32_t, void __user *);
12809 +
12810 +extern int vc_set_dlimit_x32(uint32_t, void __user *);
12811 +extern int vc_get_dlimit_x32(uint32_t, void __user *);
12812 +
12813 +#endif /* CONFIG_COMPAT */
12814 +
12815 +#endif /* __KERNEL__ */
12816 +#endif /* _VX_DLIMIT_CMD_H */
12817 diff -NurpP --minimal linux-2.6.38-rc8/include/linux/vserver/global.h linux-2.6.38-rc8-vs2.3.0.37-rc6/include/linux/vserver/global.h
12818 --- linux-2.6.38-rc8/include/linux/vserver/global.h     1970-01-01 01:00:00.000000000 +0100
12819 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/include/linux/vserver/global.h      2011-01-29 02:01:07.000000000 +0100
12820 @@ -0,0 +1,19 @@
12821 +#ifndef _VX_GLOBAL_H
12822 +#define _VX_GLOBAL_H
12823 +
12824 +
12825 +extern atomic_t vx_global_ctotal;
12826 +extern atomic_t vx_global_cactive;
12827 +
12828 +extern atomic_t nx_global_ctotal;
12829 +extern atomic_t nx_global_cactive;
12830 +
12831 +extern atomic_t vs_global_nsproxy;
12832 +extern atomic_t vs_global_fs;
12833 +extern atomic_t vs_global_mnt_ns;
12834 +extern atomic_t vs_global_uts_ns;
12835 +extern atomic_t vs_global_user_ns;
12836 +extern atomic_t vs_global_pid_ns;
12837 +
12838 +
12839 +#endif /* _VX_GLOBAL_H */
12840 diff -NurpP --minimal linux-2.6.38-rc8/include/linux/vserver/history.h linux-2.6.38-rc8-vs2.3.0.37-rc6/include/linux/vserver/history.h
12841 --- linux-2.6.38-rc8/include/linux/vserver/history.h    1970-01-01 01:00:00.000000000 +0100
12842 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/include/linux/vserver/history.h     2011-01-29 02:01:07.000000000 +0100
12843 @@ -0,0 +1,197 @@
12844 +#ifndef _VX_HISTORY_H
12845 +#define _VX_HISTORY_H
12846 +
12847 +
12848 +enum {
12849 +       VXH_UNUSED = 0,
12850 +       VXH_THROW_OOPS = 1,
12851 +
12852 +       VXH_GET_VX_INFO,
12853 +       VXH_PUT_VX_INFO,
12854 +       VXH_INIT_VX_INFO,
12855 +       VXH_SET_VX_INFO,
12856 +       VXH_CLR_VX_INFO,
12857 +       VXH_CLAIM_VX_INFO,
12858 +       VXH_RELEASE_VX_INFO,
12859 +       VXH_ALLOC_VX_INFO,
12860 +       VXH_DEALLOC_VX_INFO,
12861 +       VXH_HASH_VX_INFO,
12862 +       VXH_UNHASH_VX_INFO,
12863 +       VXH_LOC_VX_INFO,
12864 +       VXH_LOOKUP_VX_INFO,
12865 +       VXH_CREATE_VX_INFO,
12866 +};
12867 +
12868 +struct _vxhe_vxi {
12869 +       struct vx_info *ptr;
12870 +       unsigned xid;
12871 +       unsigned usecnt;
12872 +       unsigned tasks;
12873 +};
12874 +
12875 +struct _vxhe_set_clr {
12876 +       void *data;
12877 +};
12878 +
12879 +struct _vxhe_loc_lookup {
12880 +       unsigned arg;
12881 +};
12882 +
12883 +struct _vx_hist_entry {
12884 +       void *loc;
12885 +       unsigned short seq;
12886 +       unsigned short type;
12887 +       struct _vxhe_vxi vxi;
12888 +       union {
12889 +               struct _vxhe_set_clr sc;
12890 +               struct _vxhe_loc_lookup ll;
12891 +       };
12892 +};
12893 +
12894 +#ifdef CONFIG_VSERVER_HISTORY
12895 +
12896 +extern unsigned volatile int vxh_active;
12897 +
12898 +struct _vx_hist_entry *vxh_advance(void *loc);
12899 +
12900 +
12901 +static inline
12902 +void   __vxh_copy_vxi(struct _vx_hist_entry *entry, struct vx_info *vxi)
12903 +{
12904 +       entry->vxi.ptr = vxi;
12905 +       if (vxi) {
12906 +               entry->vxi.usecnt = atomic_read(&vxi->vx_usecnt);
12907 +               entry->vxi.tasks = atomic_read(&vxi->vx_tasks);
12908 +               entry->vxi.xid = vxi->vx_id;
12909 +       }
12910 +}
12911 +
12912 +
12913 +#define        __HERE__ current_text_addr()
12914 +
12915 +#define __VXH_BODY(__type, __data, __here)     \
12916 +       struct _vx_hist_entry *entry;           \
12917 +                                               \
12918 +       preempt_disable();                      \
12919 +       entry = vxh_advance(__here);            \
12920 +       __data;                                 \
12921 +       entry->type = __type;                   \
12922 +       preempt_enable();
12923 +
12924 +
12925 +       /* pass vxi only */
12926 +
12927 +#define __VXH_SMPL                             \
12928 +       __vxh_copy_vxi(entry, vxi)
12929 +
12930 +static inline
12931 +void   __vxh_smpl(struct vx_info *vxi, int __type, void *__here)
12932 +{
12933 +       __VXH_BODY(__type, __VXH_SMPL, __here)
12934 +}
12935 +
12936 +       /* pass vxi and data (void *) */
12937 +
12938 +#define __VXH_DATA                             \
12939 +       __vxh_copy_vxi(entry, vxi);             \
12940 +       entry->sc.data = data
12941 +
12942 +static inline
12943 +void   __vxh_data(struct vx_info *vxi, void *data,
12944 +                       int __type, void *__here)
12945 +{
12946 +       __VXH_BODY(__type, __VXH_DATA, __here)
12947 +}
12948 +
12949 +       /* pass vxi and arg (long) */
12950 +
12951 +#define __VXH_LONG                             \
12952 +       __vxh_copy_vxi(entry, vxi);             \
12953 +       entry->ll.arg = arg
12954 +
12955 +static inline
12956 +void   __vxh_long(struct vx_info *vxi, long arg,
12957 +                       int __type, void *__here)
12958 +{
12959 +       __VXH_BODY(__type, __VXH_LONG, __here)
12960 +}
12961 +
12962 +
12963 +static inline
12964 +void   __vxh_throw_oops(void *__here)
12965 +{
12966 +       __VXH_BODY(VXH_THROW_OOPS, {}, __here);
12967 +       /* prevent further acquisition */
12968 +       vxh_active = 0;
12969 +}
12970 +
12971 +
12972 +#define vxh_throw_oops()       __vxh_throw_oops(__HERE__);
12973 +
12974 +#define __vxh_get_vx_info(v, h)        __vxh_smpl(v, VXH_GET_VX_INFO, h);
12975 +#define __vxh_put_vx_info(v, h)        __vxh_smpl(v, VXH_PUT_VX_INFO, h);
12976 +
12977 +#define __vxh_init_vx_info(v, d, h) \
12978 +       __vxh_data(v, d, VXH_INIT_VX_INFO, h);
12979 +#define __vxh_set_vx_info(v, d, h) \
12980 +       __vxh_data(v, d, VXH_SET_VX_INFO, h);
12981 +#define __vxh_clr_vx_info(v, d, h) \
12982 +       __vxh_data(v, d, VXH_CLR_VX_INFO, h);
12983 +
12984 +#define __vxh_claim_vx_info(v, d, h) \
12985 +       __vxh_data(v, d, VXH_CLAIM_VX_INFO, h);
12986 +#define __vxh_release_vx_info(v, d, h) \
12987 +       __vxh_data(v, d, VXH_RELEASE_VX_INFO, h);
12988 +
12989 +#define vxh_alloc_vx_info(v) \
12990 +       __vxh_smpl(v, VXH_ALLOC_VX_INFO, __HERE__);
12991 +#define vxh_dealloc_vx_info(v) \
12992 +       __vxh_smpl(v, VXH_DEALLOC_VX_INFO, __HERE__);
12993 +
12994 +#define vxh_hash_vx_info(v) \
12995 +       __vxh_smpl(v, VXH_HASH_VX_INFO, __HERE__);
12996 +#define vxh_unhash_vx_info(v) \
12997 +       __vxh_smpl(v, VXH_UNHASH_VX_INFO, __HERE__);
12998 +
12999 +#define vxh_loc_vx_info(v, l) \
13000 +       __vxh_long(v, l, VXH_LOC_VX_INFO, __HERE__);
13001 +#define vxh_lookup_vx_info(v, l) \
13002 +       __vxh_long(v, l, VXH_LOOKUP_VX_INFO, __HERE__);
13003 +#define vxh_create_vx_info(v, l) \
13004 +       __vxh_long(v, l, VXH_CREATE_VX_INFO, __HERE__);
13005 +
13006 +extern void vxh_dump_history(void);
13007 +
13008 +
13009 +#else  /* CONFIG_VSERVER_HISTORY */
13010 +
13011 +#define        __HERE__        0
13012 +
13013 +#define vxh_throw_oops()               do { } while (0)
13014 +
13015 +#define __vxh_get_vx_info(v, h)                do { } while (0)
13016 +#define __vxh_put_vx_info(v, h)                do { } while (0)
13017 +
13018 +#define __vxh_init_vx_info(v, d, h)    do { } while (0)
13019 +#define __vxh_set_vx_info(v, d, h)     do { } while (0)
13020 +#define __vxh_clr_vx_info(v, d, h)     do { } while (0)
13021 +
13022 +#define __vxh_claim_vx_info(v, d, h)   do { } while (0)
13023 +#define __vxh_release_vx_info(v, d, h) do { } while (0)
13024 +
13025 +#define vxh_alloc_vx_info(v)           do { } while (0)
13026 +#define vxh_dealloc_vx_info(v)         do { } while (0)
13027 +
13028 +#define vxh_hash_vx_info(v)            do { } while (0)
13029 +#define vxh_unhash_vx_info(v)          do { } while (0)
13030 +
13031 +#define vxh_loc_vx_info(v, l)          do { } while (0)
13032 +#define vxh_lookup_vx_info(v, l)       do { } while (0)
13033 +#define vxh_create_vx_info(v, l)       do { } while (0)
13034 +
13035 +#define vxh_dump_history()             do { } while (0)
13036 +
13037 +
13038 +#endif /* CONFIG_VSERVER_HISTORY */
13039 +
13040 +#endif /* _VX_HISTORY_H */
13041 diff -NurpP --minimal linux-2.6.38-rc8/include/linux/vserver/inode.h linux-2.6.38-rc8-vs2.3.0.37-rc6/include/linux/vserver/inode.h
13042 --- linux-2.6.38-rc8/include/linux/vserver/inode.h      1970-01-01 01:00:00.000000000 +0100
13043 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/include/linux/vserver/inode.h       2011-01-29 02:01:07.000000000 +0100
13044 @@ -0,0 +1,39 @@
13045 +#ifndef _VX_INODE_H
13046 +#define _VX_INODE_H
13047 +
13048 +
13049 +#define IATTR_TAG      0x01000000
13050 +
13051 +#define IATTR_ADMIN    0x00000001
13052 +#define IATTR_WATCH    0x00000002
13053 +#define IATTR_HIDE     0x00000004
13054 +#define IATTR_FLAGS    0x00000007
13055 +
13056 +#define IATTR_BARRIER  0x00010000
13057 +#define IATTR_IXUNLINK 0x00020000
13058 +#define IATTR_IMMUTABLE 0x00040000
13059 +#define IATTR_COW      0x00080000
13060 +
13061 +#ifdef __KERNEL__
13062 +
13063 +
13064 +#ifdef CONFIG_VSERVER_PROC_SECURE
13065 +#define IATTR_PROC_DEFAULT     ( IATTR_ADMIN | IATTR_HIDE )
13066 +#define IATTR_PROC_SYMLINK     ( IATTR_ADMIN )
13067 +#else
13068 +#define IATTR_PROC_DEFAULT     ( IATTR_ADMIN )
13069 +#define IATTR_PROC_SYMLINK     ( IATTR_ADMIN )
13070 +#endif
13071 +
13072 +#define vx_hide_check(c, m)    (((m) & IATTR_HIDE) ? vx_check(c, m) : 1)
13073 +
13074 +#endif /* __KERNEL__ */
13075 +
13076 +/* inode ioctls */
13077 +
13078 +#define FIOC_GETXFLG   _IOR('x', 5, long)
13079 +#define FIOC_SETXFLG   _IOW('x', 6, long)
13080 +
13081 +#else  /* _VX_INODE_H */
13082 +#warning duplicate inclusion
13083 +#endif /* _VX_INODE_H */
13084 diff -NurpP --minimal linux-2.6.38-rc8/include/linux/vserver/inode_cmd.h linux-2.6.38-rc8-vs2.3.0.37-rc6/include/linux/vserver/inode_cmd.h
13085 --- linux-2.6.38-rc8/include/linux/vserver/inode_cmd.h  1970-01-01 01:00:00.000000000 +0100
13086 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/include/linux/vserver/inode_cmd.h   2011-01-29 02:01:07.000000000 +0100
13087 @@ -0,0 +1,59 @@
13088 +#ifndef _VX_INODE_CMD_H
13089 +#define _VX_INODE_CMD_H
13090 +
13091 +
13092 +/*  inode vserver commands */
13093 +
13094 +#define VCMD_get_iattr         VC_CMD(INODE, 1, 1)
13095 +#define VCMD_set_iattr         VC_CMD(INODE, 2, 1)
13096 +
13097 +#define VCMD_fget_iattr                VC_CMD(INODE, 3, 0)
13098 +#define VCMD_fset_iattr                VC_CMD(INODE, 4, 0)
13099 +
13100 +struct vcmd_ctx_iattr_v1 {
13101 +       const char __user *name;
13102 +       uint32_t tag;
13103 +       uint32_t flags;
13104 +       uint32_t mask;
13105 +};
13106 +
13107 +struct vcmd_ctx_fiattr_v0 {
13108 +       uint32_t tag;
13109 +       uint32_t flags;
13110 +       uint32_t mask;
13111 +};
13112 +
13113 +
13114 +#ifdef __KERNEL__
13115 +
13116 +
13117 +#ifdef CONFIG_COMPAT
13118 +
13119 +#include <asm/compat.h>
13120 +
13121 +struct vcmd_ctx_iattr_v1_x32 {
13122 +       compat_uptr_t name_ptr;
13123 +       uint32_t tag;
13124 +       uint32_t flags;
13125 +       uint32_t mask;
13126 +};
13127 +
13128 +#endif /* CONFIG_COMPAT */
13129 +
13130 +#include <linux/compiler.h>
13131 +
13132 +extern int vc_get_iattr(void __user *);
13133 +extern int vc_set_iattr(void __user *);
13134 +
13135 +extern int vc_fget_iattr(uint32_t, void __user *);
13136 +extern int vc_fset_iattr(uint32_t, void __user *);
13137 +
13138 +#ifdef CONFIG_COMPAT
13139 +
13140 +extern int vc_get_iattr_x32(void __user *);
13141 +extern int vc_set_iattr_x32(void __user *);
13142 +
13143 +#endif /* CONFIG_COMPAT */
13144 +
13145 +#endif /* __KERNEL__ */
13146 +#endif /* _VX_INODE_CMD_H */
13147 diff -NurpP --minimal linux-2.6.38-rc8/include/linux/vserver/limit.h linux-2.6.38-rc8-vs2.3.0.37-rc6/include/linux/vserver/limit.h
13148 --- linux-2.6.38-rc8/include/linux/vserver/limit.h      1970-01-01 01:00:00.000000000 +0100
13149 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/include/linux/vserver/limit.h       2011-01-29 02:01:07.000000000 +0100
13150 @@ -0,0 +1,71 @@
13151 +#ifndef _VX_LIMIT_H
13152 +#define _VX_LIMIT_H
13153 +
13154 +#define VLIMIT_NSOCK   16
13155 +#define VLIMIT_OPENFD  17
13156 +#define VLIMIT_ANON    18
13157 +#define VLIMIT_SHMEM   19
13158 +#define VLIMIT_SEMARY  20
13159 +#define VLIMIT_NSEMS   21
13160 +#define VLIMIT_DENTRY  22
13161 +#define VLIMIT_MAPPED  23
13162 +
13163 +
13164 +#ifdef __KERNEL__
13165 +
13166 +#define        VLIM_NOCHECK    ((1L << VLIMIT_DENTRY) | (1L << RLIMIT_RSS))
13167 +
13168 +/*     keep in sync with CRLIM_INFINITY */
13169 +
13170 +#define        VLIM_INFINITY   (~0ULL)
13171 +
13172 +#include <asm/atomic.h>
13173 +#include <asm/resource.h>
13174 +
13175 +#ifndef RLIM_INFINITY
13176 +#warning RLIM_INFINITY is undefined
13177 +#endif
13178 +
13179 +#define __rlim_val(l, r, v)    ((l)->res[r].v)
13180 +
13181 +#define __rlim_soft(l, r)      __rlim_val(l, r, soft)
13182 +#define __rlim_hard(l, r)      __rlim_val(l, r, hard)
13183 +
13184 +#define __rlim_rcur(l, r)      __rlim_val(l, r, rcur)
13185 +#define __rlim_rmin(l, r)      __rlim_val(l, r, rmin)
13186 +#define __rlim_rmax(l, r)      __rlim_val(l, r, rmax)
13187 +
13188 +#define __rlim_lhit(l, r)      __rlim_val(l, r, lhit)
13189 +#define __rlim_hit(l, r)       atomic_inc(&__rlim_lhit(l, r))
13190 +
13191 +typedef atomic_long_t rlim_atomic_t;
13192 +typedef unsigned long rlim_t;
13193 +
13194 +#define __rlim_get(l, r)       atomic_long_read(&__rlim_rcur(l, r))
13195 +#define __rlim_set(l, r, v)    atomic_long_set(&__rlim_rcur(l, r), v)
13196 +#define __rlim_inc(l, r)       atomic_long_inc(&__rlim_rcur(l, r))
13197 +#define __rlim_dec(l, r)       atomic_long_dec(&__rlim_rcur(l, r))
13198 +#define __rlim_add(l, r, v)    atomic_long_add(v, &__rlim_rcur(l, r))
13199 +#define __rlim_sub(l, r, v)    atomic_long_sub(v, &__rlim_rcur(l, r))
13200 +
13201 +
13202 +#if    (RLIM_INFINITY == VLIM_INFINITY)
13203 +#define        VX_VLIM(r) ((long long)(long)(r))
13204 +#define        VX_RLIM(v) ((rlim_t)(v))
13205 +#else
13206 +#define        VX_VLIM(r) (((r) == RLIM_INFINITY) \
13207 +               ? VLIM_INFINITY : (long long)(r))
13208 +#define        VX_RLIM(v) (((v) == VLIM_INFINITY) \
13209 +               ? RLIM_INFINITY : (rlim_t)(v))
13210 +#endif
13211 +
13212 +struct sysinfo;
13213 +
13214 +void vx_vsi_meminfo(struct sysinfo *);
13215 +void vx_vsi_swapinfo(struct sysinfo *);
13216 +long vx_vsi_cached(struct sysinfo *);
13217 +
13218 +#define NUM_LIMITS     24
13219 +
13220 +#endif /* __KERNEL__ */
13221 +#endif /* _VX_LIMIT_H */
13222 diff -NurpP --minimal linux-2.6.38-rc8/include/linux/vserver/limit_cmd.h linux-2.6.38-rc8-vs2.3.0.37-rc6/include/linux/vserver/limit_cmd.h
13223 --- linux-2.6.38-rc8/include/linux/vserver/limit_cmd.h  1970-01-01 01:00:00.000000000 +0100
13224 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/include/linux/vserver/limit_cmd.h   2011-01-29 02:01:07.000000000 +0100
13225 @@ -0,0 +1,71 @@
13226 +#ifndef _VX_LIMIT_CMD_H
13227 +#define _VX_LIMIT_CMD_H
13228 +
13229 +
13230 +/*  rlimit vserver commands */
13231 +
13232 +#define VCMD_get_rlimit                VC_CMD(RLIMIT, 1, 0)
13233 +#define VCMD_set_rlimit                VC_CMD(RLIMIT, 2, 0)
13234 +#define VCMD_get_rlimit_mask   VC_CMD(RLIMIT, 3, 0)
13235 +#define VCMD_reset_hits                VC_CMD(RLIMIT, 7, 0)
13236 +#define VCMD_reset_minmax      VC_CMD(RLIMIT, 9, 0)
13237 +
13238 +struct vcmd_ctx_rlimit_v0 {
13239 +       uint32_t id;
13240 +       uint64_t minimum;
13241 +       uint64_t softlimit;
13242 +       uint64_t maximum;
13243 +};
13244 +
13245 +struct vcmd_ctx_rlimit_mask_v0 {
13246 +       uint32_t minimum;
13247 +       uint32_t softlimit;
13248 +       uint32_t maximum;
13249 +};
13250 +
13251 +#define VCMD_rlimit_stat       VC_CMD(VSTAT, 1, 0)
13252 +
13253 +struct vcmd_rlimit_stat_v0 {
13254 +       uint32_t id;
13255 +       uint32_t hits;
13256 +       uint64_t value;
13257 +       uint64_t minimum;
13258 +       uint64_t maximum;
13259 +};
13260 +
13261 +#define CRLIM_UNSET            (0ULL)
13262 +#define CRLIM_INFINITY         (~0ULL)
13263 +#define CRLIM_KEEP             (~1ULL)
13264 +
13265 +#ifdef __KERNEL__
13266 +
13267 +#ifdef CONFIG_IA32_EMULATION
13268 +
13269 +struct vcmd_ctx_rlimit_v0_x32 {
13270 +       uint32_t id;
13271 +       uint64_t minimum;
13272 +       uint64_t softlimit;
13273 +       uint64_t maximum;
13274 +} __attribute__ ((packed));
13275 +
13276 +#endif /* CONFIG_IA32_EMULATION */
13277 +
13278 +#include <linux/compiler.h>
13279 +
13280 +extern int vc_get_rlimit_mask(uint32_t, void __user *);
13281 +extern int vc_get_rlimit(struct vx_info *, void __user *);
13282 +extern int vc_set_rlimit(struct vx_info *, void __user *);
13283 +extern int vc_reset_hits(struct vx_info *, void __user *);
13284 +extern int vc_reset_minmax(struct vx_info *, void __user *);
13285 +
13286 +extern int vc_rlimit_stat(struct vx_info *, void __user *);
13287 +
13288 +#ifdef CONFIG_IA32_EMULATION
13289 +
13290 +extern int vc_get_rlimit_x32(struct vx_info *, void __user *);
13291 +extern int vc_set_rlimit_x32(struct vx_info *, void __user *);
13292 +
13293 +#endif /* CONFIG_IA32_EMULATION */
13294 +
13295 +#endif /* __KERNEL__ */
13296 +#endif /* _VX_LIMIT_CMD_H */
13297 diff -NurpP --minimal linux-2.6.38-rc8/include/linux/vserver/limit_def.h linux-2.6.38-rc8-vs2.3.0.37-rc6/include/linux/vserver/limit_def.h
13298 --- linux-2.6.38-rc8/include/linux/vserver/limit_def.h  1970-01-01 01:00:00.000000000 +0100
13299 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/include/linux/vserver/limit_def.h   2011-01-29 02:01:07.000000000 +0100
13300 @@ -0,0 +1,47 @@
13301 +#ifndef _VX_LIMIT_DEF_H
13302 +#define _VX_LIMIT_DEF_H
13303 +
13304 +#include <asm/atomic.h>
13305 +#include <asm/resource.h>
13306 +
13307 +#include "limit.h"
13308 +
13309 +
13310 +struct _vx_res_limit {
13311 +       rlim_t soft;            /* Context soft limit */
13312 +       rlim_t hard;            /* Context hard limit */
13313 +
13314 +       rlim_atomic_t rcur;     /* Current value */
13315 +       rlim_t rmin;            /* Context minimum */
13316 +       rlim_t rmax;            /* Context maximum */
13317 +
13318 +       atomic_t lhit;          /* Limit hits */
13319 +};
13320 +
13321 +/* context sub struct */
13322 +
13323 +struct _vx_limit {
13324 +       struct _vx_res_limit res[NUM_LIMITS];
13325 +};
13326 +
13327 +#ifdef CONFIG_VSERVER_DEBUG
13328 +
13329 +static inline void __dump_vx_limit(struct _vx_limit *limit)
13330 +{
13331 +       int i;
13332 +
13333 +       printk("\t_vx_limit:");
13334 +       for (i = 0; i < NUM_LIMITS; i++) {
13335 +               printk("\t [%2d] = %8lu %8lu/%8lu, %8ld/%8ld, %8d\n",
13336 +                       i, (unsigned long)__rlim_get(limit, i),
13337 +                       (unsigned long)__rlim_rmin(limit, i),
13338 +                       (unsigned long)__rlim_rmax(limit, i),
13339 +                       (long)__rlim_soft(limit, i),
13340 +                       (long)__rlim_hard(limit, i),
13341 +                       atomic_read(&__rlim_lhit(limit, i)));
13342 +       }
13343 +}
13344 +
13345 +#endif
13346 +
13347 +#endif /* _VX_LIMIT_DEF_H */
13348 diff -NurpP --minimal linux-2.6.38-rc8/include/linux/vserver/limit_int.h linux-2.6.38-rc8-vs2.3.0.37-rc6/include/linux/vserver/limit_int.h
13349 --- linux-2.6.38-rc8/include/linux/vserver/limit_int.h  1970-01-01 01:00:00.000000000 +0100
13350 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/include/linux/vserver/limit_int.h   2011-01-29 02:01:07.000000000 +0100
13351 @@ -0,0 +1,198 @@
13352 +#ifndef _VX_LIMIT_INT_H
13353 +#define _VX_LIMIT_INT_H
13354 +
13355 +#include "context.h"
13356 +
13357 +#ifdef __KERNEL__
13358 +
13359 +#define VXD_RCRES_COND(r)      VXD_CBIT(cres, r)
13360 +#define VXD_RLIMIT_COND(r)     VXD_CBIT(limit, r)
13361 +
13362 +extern const char *vlimit_name[NUM_LIMITS];
13363 +
13364 +static inline void __vx_acc_cres(struct vx_info *vxi,
13365 +       int res, int dir, void *_data, char *_file, int _line)
13366 +{
13367 +       if (VXD_RCRES_COND(res))
13368 +               vxlprintk(1, "vx_acc_cres[%5d,%s,%2d]: %5ld%s (%p)",
13369 +                       (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
13370 +                       (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
13371 +                       (dir > 0) ? "++" : "--", _data, _file, _line);
13372 +       if (!vxi)
13373 +               return;
13374 +
13375 +       if (dir > 0)
13376 +               __rlim_inc(&vxi->limit, res);
13377 +       else
13378 +               __rlim_dec(&vxi->limit, res);
13379 +}
13380 +
13381 +static inline void __vx_add_cres(struct vx_info *vxi,
13382 +       int res, int amount, void *_data, char *_file, int _line)
13383 +{
13384 +       if (VXD_RCRES_COND(res))
13385 +               vxlprintk(1, "vx_add_cres[%5d,%s,%2d]: %5ld += %5d (%p)",
13386 +                       (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
13387 +                       (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
13388 +                       amount, _data, _file, _line);
13389 +       if (amount == 0)
13390 +               return;
13391 +       if (!vxi)
13392 +               return;
13393 +       __rlim_add(&vxi->limit, res, amount);
13394 +}
13395 +
13396 +static inline
13397 +int __vx_cres_adjust_max(struct _vx_limit *limit, int res, rlim_t value)
13398 +{
13399 +       int cond = (value > __rlim_rmax(limit, res));
13400 +
13401 +       if (cond)
13402 +               __rlim_rmax(limit, res) = value;
13403 +       return cond;
13404 +}
13405 +
13406 +static inline
13407 +int __vx_cres_adjust_min(struct _vx_limit *limit, int res, rlim_t value)
13408 +{
13409 +       int cond = (value < __rlim_rmin(limit, res));
13410 +
13411 +       if (cond)
13412 +               __rlim_rmin(limit, res) = value;
13413 +       return cond;
13414 +}
13415 +
13416 +static inline
13417 +void __vx_cres_fixup(struct _vx_limit *limit, int res, rlim_t value)
13418 +{
13419 +       if (!__vx_cres_adjust_max(limit, res, value))
13420 +               __vx_cres_adjust_min(limit, res, value);
13421 +}
13422 +
13423 +
13424 +/*     return values:
13425 +        +1 ... no limit hit
13426 +        -1 ... over soft limit
13427 +         0 ... over hard limit         */
13428 +
13429 +static inline int __vx_cres_avail(struct vx_info *vxi,
13430 +       int res, int num, char *_file, int _line)
13431 +{
13432 +       struct _vx_limit *limit;
13433 +       rlim_t value;
13434 +
13435 +       if (VXD_RLIMIT_COND(res))
13436 +               vxlprintk(1, "vx_cres_avail[%5d,%s,%2d]: %5ld/%5ld > %5ld + %5d",
13437 +                       (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
13438 +                       (vxi ? (long)__rlim_soft(&vxi->limit, res) : -1),
13439 +                       (vxi ? (long)__rlim_hard(&vxi->limit, res) : -1),
13440 +                       (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
13441 +                       num, _file, _line);
13442 +       if (!vxi)
13443 +               return 1;
13444 +
13445 +       limit = &vxi->limit;
13446 +       value = __rlim_get(limit, res);
13447 +
13448 +       if (!__vx_cres_adjust_max(limit, res, value))
13449 +               __vx_cres_adjust_min(limit, res, value);
13450 +
13451 +       if (num == 0)
13452 +               return 1;
13453 +
13454 +       if (__rlim_soft(limit, res) == RLIM_INFINITY)
13455 +               return -1;
13456 +       if (value + num <= __rlim_soft(limit, res))
13457 +               return -1;
13458 +
13459 +       if (__rlim_hard(limit, res) == RLIM_INFINITY)
13460 +               return 1;
13461 +       if (value + num <= __rlim_hard(limit, res))
13462 +               return 1;
13463 +
13464 +       __rlim_hit(limit, res);
13465 +       return 0;
13466 +}
13467 +
13468 +
13469 +static const int VLA_RSS[] = { RLIMIT_RSS, VLIMIT_ANON, VLIMIT_MAPPED, 0 };
13470 +
13471 +static inline
13472 +rlim_t __vx_cres_array_sum(struct _vx_limit *limit, const int *array)
13473 +{
13474 +       rlim_t value, sum = 0;
13475 +       int res;
13476 +
13477 +       while ((res = *array++)) {
13478 +               value = __rlim_get(limit, res);
13479 +               __vx_cres_fixup(limit, res, value);
13480 +               sum += value;
13481 +       }
13482 +       return sum;
13483 +}
13484 +
13485 +static inline
13486 +rlim_t __vx_cres_array_fixup(struct _vx_limit *limit, const int *array)
13487 +{
13488 +       rlim_t value = __vx_cres_array_sum(limit, array + 1);
13489 +       int res = *array;
13490 +
13491 +       if (value == __rlim_get(limit, res))
13492 +               return value;
13493 +
13494 +       __rlim_set(limit, res, value);
13495 +       /* now adjust min/max */
13496 +       if (!__vx_cres_adjust_max(limit, res, value))
13497 +               __vx_cres_adjust_min(limit, res, value);
13498 +
13499 +       return value;
13500 +}
13501 +
13502 +static inline int __vx_cres_array_avail(struct vx_info *vxi,
13503 +       const int *array, int num, char *_file, int _line)
13504 +{
13505 +       struct _vx_limit *limit;
13506 +       rlim_t value = 0;
13507 +       int res;
13508 +
13509 +       if (num == 0)
13510 +               return 1;
13511 +       if (!vxi)
13512 +               return 1;
13513 +
13514 +       limit = &vxi->limit;
13515 +       res = *array;
13516 +       value = __vx_cres_array_sum(limit, array + 1);
13517 +
13518 +       __rlim_set(limit, res, value);
13519 +       __vx_cres_fixup(limit, res, value);
13520 +
13521 +       return __vx_cres_avail(vxi, res, num, _file, _line);
13522 +}
13523 +
13524 +
13525 +static inline void vx_limit_fixup(struct _vx_limit *limit, int id)
13526 +{
13527 +       rlim_t value;
13528 +       int res;
13529 +
13530 +       /* complex resources first */
13531 +       if ((id < 0) || (id == RLIMIT_RSS))
13532 +               __vx_cres_array_fixup(limit, VLA_RSS);
13533 +
13534 +       for (res = 0; res < NUM_LIMITS; res++) {
13535 +               if ((id > 0) && (res != id))
13536 +                       continue;
13537 +
13538 +               value = __rlim_get(limit, res);
13539 +               __vx_cres_fixup(limit, res, value);
13540 +
13541 +               /* not supposed to happen, maybe warn? */
13542 +               if (__rlim_rmax(limit, res) > __rlim_hard(limit, res))
13543 +                       __rlim_rmax(limit, res) = __rlim_hard(limit, res);
13544 +       }
13545 +}
13546 +
13547 +
13548 +#endif /* __KERNEL__ */
13549 +#endif /* _VX_LIMIT_INT_H */
13550 diff -NurpP --minimal linux-2.6.38-rc8/include/linux/vserver/monitor.h linux-2.6.38-rc8-vs2.3.0.37-rc6/include/linux/vserver/monitor.h
13551 --- linux-2.6.38-rc8/include/linux/vserver/monitor.h    1970-01-01 01:00:00.000000000 +0100
13552 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/include/linux/vserver/monitor.h     2011-01-29 02:01:07.000000000 +0100
13553 @@ -0,0 +1,96 @@
13554 +#ifndef _VX_MONITOR_H
13555 +#define _VX_MONITOR_H
13556 +
13557 +#include <linux/types.h>
13558 +
13559 +enum {
13560 +       VXM_UNUSED = 0,
13561 +
13562 +       VXM_SYNC = 0x10,
13563 +
13564 +       VXM_UPDATE = 0x20,
13565 +       VXM_UPDATE_1,
13566 +       VXM_UPDATE_2,
13567 +
13568 +       VXM_RQINFO_1 = 0x24,
13569 +       VXM_RQINFO_2,
13570 +
13571 +       VXM_ACTIVATE = 0x40,
13572 +       VXM_DEACTIVATE,
13573 +       VXM_IDLE,
13574 +
13575 +       VXM_HOLD = 0x44,
13576 +       VXM_UNHOLD,
13577 +
13578 +       VXM_MIGRATE = 0x48,
13579 +       VXM_RESCHED,
13580 +
13581 +       /* all other bits are flags */
13582 +       VXM_SCHED = 0x80,
13583 +};
13584 +
13585 +struct _vxm_update_1 {
13586 +       uint32_t tokens_max;
13587 +       uint32_t fill_rate;
13588 +       uint32_t interval;
13589 +};
13590 +
13591 +struct _vxm_update_2 {
13592 +       uint32_t tokens_min;
13593 +       uint32_t fill_rate;
13594 +       uint32_t interval;
13595 +};
13596 +
13597 +struct _vxm_rqinfo_1 {
13598 +       uint16_t running;
13599 +       uint16_t onhold;
13600 +       uint16_t iowait;
13601 +       uint16_t uintr;
13602 +       uint32_t idle_tokens;
13603 +};
13604 +
13605 +struct _vxm_rqinfo_2 {
13606 +       uint32_t norm_time;
13607 +       uint32_t idle_time;
13608 +       uint32_t idle_skip;
13609 +};
13610 +
13611 +struct _vxm_sched {
13612 +       uint32_t tokens;
13613 +       uint32_t norm_time;
13614 +       uint32_t idle_time;
13615 +};
13616 +
13617 +struct _vxm_task {
13618 +       uint16_t pid;
13619 +       uint16_t state;
13620 +};
13621 +
13622 +struct _vxm_event {
13623 +       uint32_t jif;
13624 +       union {
13625 +               uint32_t seq;
13626 +               uint32_t sec;
13627 +       };
13628 +       union {
13629 +               uint32_t tokens;
13630 +               uint32_t nsec;
13631 +               struct _vxm_task tsk;
13632 +       };
13633 +};
13634 +
13635 +struct _vx_mon_entry {
13636 +       uint16_t type;
13637 +       uint16_t xid;
13638 +       union {
13639 +               struct _vxm_event ev;
13640 +               struct _vxm_sched sd;
13641 +               struct _vxm_update_1 u1;
13642 +               struct _vxm_update_2 u2;
13643 +               struct _vxm_rqinfo_1 q1;
13644 +               struct _vxm_rqinfo_2 q2;
13645 +       };
13646 +};
13647 +
13648 +
13649 +#endif /* _VX_MONITOR_H */
13650 diff -NurpP --minimal linux-2.6.38-rc8/include/linux/vserver/network.h linux-2.6.38-rc8-vs2.3.0.37-rc6/include/linux/vserver/network.h
13651 --- linux-2.6.38-rc8/include/linux/vserver/network.h    1970-01-01 01:00:00.000000000 +0100
13652 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/include/linux/vserver/network.h     2011-01-29 02:01:07.000000000 +0100
13653 @@ -0,0 +1,146 @@
13654 +#ifndef _VX_NETWORK_H
13655 +#define _VX_NETWORK_H
13656 +
13657 +#include <linux/types.h>
13658 +
13659 +
13660 +#define MAX_N_CONTEXT  65535   /* Arbitrary limit */
13661 +
13662 +
13663 +/* network flags */
13664 +
13665 +#define NXF_INFO_PRIVATE       0x00000008
13666 +
13667 +#define NXF_SINGLE_IP          0x00000100
13668 +#define NXF_LBACK_REMAP                0x00000200
13669 +#define NXF_LBACK_ALLOW                0x00000400
13670 +
13671 +#define NXF_HIDE_NETIF         0x02000000
13672 +#define NXF_HIDE_LBACK         0x04000000
13673 +
13674 +#define NXF_STATE_SETUP                (1ULL << 32)
13675 +#define NXF_STATE_ADMIN                (1ULL << 34)
13676 +
13677 +#define NXF_SC_HELPER          (1ULL << 36)
13678 +#define NXF_PERSISTENT         (1ULL << 38)
13679 +
13680 +#define NXF_ONE_TIME           (0x0005ULL << 32)
13681 +
13682 +
13683 +#define        NXF_INIT_SET            (__nxf_init_set())
13684 +
13685 +static inline uint64_t __nxf_init_set(void) {
13686 +       return    NXF_STATE_ADMIN
13687 +#ifdef CONFIG_VSERVER_AUTO_LBACK
13688 +               | NXF_LBACK_REMAP
13689 +               | NXF_HIDE_LBACK
13690 +#endif
13691 +#ifdef CONFIG_VSERVER_AUTO_SINGLE
13692 +               | NXF_SINGLE_IP
13693 +#endif
13694 +               | NXF_HIDE_NETIF;
13695 +}
13696 +
13697 +
13698 +/* network caps */
13699 +
13700 +#define NXC_TUN_CREATE         0x00000001
13701 +
13702 +#define NXC_RAW_ICMP           0x00000100
13703 +
13704 +
13705 +/* address types */
13706 +
13707 +#define NXA_TYPE_IPV4          0x0001
13708 +#define NXA_TYPE_IPV6          0x0002
13709 +
13710 +#define NXA_TYPE_NONE          0x0000
13711 +#define NXA_TYPE_ANY           0x00FF
13712 +
13713 +#define NXA_TYPE_ADDR          0x0010
13714 +#define NXA_TYPE_MASK          0x0020
13715 +#define NXA_TYPE_RANGE         0x0040
13716 +
13717 +#define NXA_MASK_ALL           (NXA_TYPE_ADDR | NXA_TYPE_MASK | NXA_TYPE_RANGE)
13718 +
13719 +#define NXA_MOD_BCAST          0x0100
13720 +#define NXA_MOD_LBACK          0x0200
13721 +
13722 +#define NXA_LOOPBACK           0x1000
13723 +
13724 +#define NXA_MASK_BIND          (NXA_MASK_ALL | NXA_MOD_BCAST | NXA_MOD_LBACK)
13725 +#define NXA_MASK_SHOW          (NXA_MASK_ALL | NXA_LOOPBACK)
13726 +
13727 +#ifdef __KERNEL__
13728 +
13729 +#include <linux/list.h>
13730 +#include <linux/spinlock.h>
13731 +#include <linux/rcupdate.h>
13732 +#include <linux/in.h>
13733 +#include <linux/in6.h>
13734 +#include <asm/atomic.h>
13735 +
13736 +struct nx_addr_v4 {
13737 +       struct nx_addr_v4 *next;
13738 +       struct in_addr ip[2];
13739 +       struct in_addr mask;
13740 +       uint16_t type;
13741 +       uint16_t flags;
13742 +};
13743 +
13744 +struct nx_addr_v6 {
13745 +       struct nx_addr_v6 *next;
13746 +       struct in6_addr ip;
13747 +       struct in6_addr mask;
13748 +       uint32_t prefix;
13749 +       uint16_t type;
13750 +       uint16_t flags;
13751 +};
13752 +
13753 +struct nx_info {
13754 +       struct hlist_node nx_hlist;     /* linked list of nxinfos */
13755 +       nid_t nx_id;                    /* vnet id */
13756 +       atomic_t nx_usecnt;             /* usage count */
13757 +       atomic_t nx_tasks;              /* tasks count */
13758 +       int nx_state;                   /* context state */
13759 +
13760 +       uint64_t nx_flags;              /* network flag word */
13761 +       uint64_t nx_ncaps;              /* network capabilities */
13762 +
13763 +       struct in_addr v4_lback;        /* Loopback address */
13764 +       struct in_addr v4_bcast;        /* Broadcast address */
13765 +       struct nx_addr_v4 v4;           /* First/Single ipv4 address */
13766 +#ifdef CONFIG_IPV6
13767 +       struct nx_addr_v6 v6;           /* First/Single ipv6 address */
13768 +#endif
13769 +       char nx_name[65];               /* network context name */
13770 +};
13771 +
13772 +
13773 +/* status flags */
13774 +
13775 +#define NXS_HASHED      0x0001
13776 +#define NXS_SHUTDOWN    0x0100
13777 +#define NXS_RELEASED    0x8000
13778 +
13779 +extern struct nx_info *lookup_nx_info(int);
13780 +
13781 +extern int get_nid_list(int, unsigned int *, int);
13782 +extern int nid_is_hashed(nid_t);
13783 +
13784 +extern int nx_migrate_task(struct task_struct *, struct nx_info *);
13785 +
13786 +extern long vs_net_change(struct nx_info *, unsigned int);
13787 +
13788 +struct sock;
13789 +
13790 +
13791 +#define NX_IPV4(n)     ((n)->v4.type != NXA_TYPE_NONE)
13792 +#ifdef  CONFIG_IPV6
13793 +#define NX_IPV6(n)     ((n)->v6.type != NXA_TYPE_NONE)
13794 +#else
13795 +#define NX_IPV6(n)     (0)
13796 +#endif
13797 +
13798 +#endif /* __KERNEL__ */
13799 +#endif /* _VX_NETWORK_H */
13800 diff -NurpP --minimal linux-2.6.38-rc8/include/linux/vserver/network_cmd.h linux-2.6.38-rc8-vs2.3.0.37-rc6/include/linux/vserver/network_cmd.h
13801 --- linux-2.6.38-rc8/include/linux/vserver/network_cmd.h        1970-01-01 01:00:00.000000000 +0100
13802 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/include/linux/vserver/network_cmd.h 2011-01-29 02:01:07.000000000 +0100
13803 @@ -0,0 +1,150 @@
13804 +#ifndef _VX_NETWORK_CMD_H
13805 +#define _VX_NETWORK_CMD_H
13806 +
13807 +
13808 +/* vinfo commands */
13809 +
13810 +#define VCMD_task_nid          VC_CMD(VINFO, 2, 0)
13811 +
13812 +#ifdef __KERNEL__
13813 +extern int vc_task_nid(uint32_t);
13814 +
13815 +#endif /* __KERNEL__ */
13816 +
13817 +#define VCMD_nx_info           VC_CMD(VINFO, 6, 0)
13818 +
13819 +struct vcmd_nx_info_v0 {
13820 +       uint32_t nid;
13821 +       /* more to come */
13822 +};
13823 +
13824 +#ifdef __KERNEL__
13825 +extern int vc_nx_info(struct nx_info *, void __user *);
13826 +
13827 +#endif /* __KERNEL__ */
13828 +
13829 +#include <linux/in.h>
13830 +#include <linux/in6.h>
13831 +
13832 +#define VCMD_net_create_v0     VC_CMD(VNET, 1, 0)
13833 +#define VCMD_net_create                VC_CMD(VNET, 1, 1)
13834 +
13835 +struct  vcmd_net_create {
13836 +       uint64_t flagword;
13837 +};
13838 +
13839 +#define VCMD_net_migrate       VC_CMD(NETMIG, 1, 0)
13840 +
13841 +#define VCMD_net_add           VC_CMD(NETALT, 1, 0)
13842 +#define VCMD_net_remove                VC_CMD(NETALT, 2, 0)
13843 +
13844 +struct vcmd_net_addr_v0 {
13845 +       uint16_t type;
13846 +       uint16_t count;
13847 +       struct in_addr ip[4];
13848 +       struct in_addr mask[4];
13849 +};
13850 +
13851 +#define VCMD_net_add_ipv4      VC_CMD(NETALT, 1, 1)
13852 +#define VCMD_net_remove_ipv4   VC_CMD(NETALT, 2, 1)
13853 +
13854 +struct vcmd_net_addr_ipv4_v1 {
13855 +       uint16_t type;
13856 +       uint16_t flags;
13857 +       struct in_addr ip;
13858 +       struct in_addr mask;
13859 +};
13860 +
13861 +#define VCMD_net_add_ipv6      VC_CMD(NETALT, 3, 1)
13862 +#define VCMD_net_remove_ipv6   VC_CMD(NETALT, 4, 1)
13863 +
13864 +struct vcmd_net_addr_ipv6_v1 {
13865 +       uint16_t type;
13866 +       uint16_t flags;
13867 +       uint32_t prefix;
13868 +       struct in6_addr ip;
13869 +       struct in6_addr mask;
13870 +};
13871 +
13872 +#define VCMD_add_match_ipv4    VC_CMD(NETALT, 5, 0)
13873 +#define VCMD_get_match_ipv4    VC_CMD(NETALT, 6, 0)
13874 +
13875 +struct vcmd_match_ipv4_v0 {
13876 +       uint16_t type;
13877 +       uint16_t flags;
13878 +       uint16_t parent;
13879 +       uint16_t prefix;
13880 +       struct in_addr ip;
13881 +       struct in_addr ip2;
13882 +       struct in_addr mask;
13883 +};
13884 +
13885 +#define VCMD_add_match_ipv6    VC_CMD(NETALT, 7, 0)
13886 +#define VCMD_get_match_ipv6    VC_CMD(NETALT, 8, 0)
13887 +
13888 +struct vcmd_match_ipv6_v0 {
13889 +       uint16_t type;
13890 +       uint16_t flags;
13891 +       uint16_t parent;
13892 +       uint16_t prefix;
13893 +       struct in6_addr ip;
13894 +       struct in6_addr ip2;
13895 +       struct in6_addr mask;
13896 +};
13897 +
13898 +
13899 +#ifdef __KERNEL__
13900 +extern int vc_net_create(uint32_t, void __user *);
13901 +extern int vc_net_migrate(struct nx_info *, void __user *);
13902 +
13903 +extern int vc_net_add(struct nx_info *, void __user *);
13904 +extern int vc_net_remove(struct nx_info *, void __user *);
13905 +
13906 +extern int vc_net_add_ipv4(struct nx_info *, void __user *);
13907 +extern int vc_net_remove_ipv4(struct nx_info *, void __user *);
13908 +
13909 +extern int vc_net_add_ipv6(struct nx_info *, void __user *);
13910 +extern int vc_net_remove_ipv6(struct nx_info *, void __user *);
13911 +
13912 +extern int vc_add_match_ipv4(struct nx_info *, void __user *);
13913 +extern int vc_get_match_ipv4(struct nx_info *, void __user *);
13914 +
13915 +extern int vc_add_match_ipv6(struct nx_info *, void __user *);
13916 +extern int vc_get_match_ipv6(struct nx_info *, void __user *);
13917 +
13918 +#endif /* __KERNEL__ */
13919 +
13920 +
13921 +/* flag commands */
13922 +
13923 +#define VCMD_get_nflags                VC_CMD(FLAGS, 5, 0)
13924 +#define VCMD_set_nflags                VC_CMD(FLAGS, 6, 0)
13925 +
13926 +struct vcmd_net_flags_v0 {
13927 +       uint64_t flagword;
13928 +       uint64_t mask;
13929 +};
13930 +
13931 +#ifdef __KERNEL__
13932 +extern int vc_get_nflags(struct nx_info *, void __user *);
13933 +extern int vc_set_nflags(struct nx_info *, void __user *);
13934 +
13935 +#endif /* __KERNEL__ */
13936 +
13937 +
13938 +/* network caps commands */
13939 +
13940 +#define VCMD_get_ncaps         VC_CMD(FLAGS, 7, 0)
13941 +#define VCMD_set_ncaps         VC_CMD(FLAGS, 8, 0)
13942 +
13943 +struct vcmd_net_caps_v0 {
13944 +       uint64_t ncaps;
13945 +       uint64_t cmask;
13946 +};
13947 +
13948 +#ifdef __KERNEL__
13949 +extern int vc_get_ncaps(struct nx_info *, void __user *);
13950 +extern int vc_set_ncaps(struct nx_info *, void __user *);
13951 +
13952 +#endif /* __KERNEL__ */
13953 +#endif /* _VX_CONTEXT_CMD_H */
13954 diff -NurpP --minimal linux-2.6.38-rc8/include/linux/vserver/percpu.h linux-2.6.38-rc8-vs2.3.0.37-rc6/include/linux/vserver/percpu.h
13955 --- linux-2.6.38-rc8/include/linux/vserver/percpu.h     1970-01-01 01:00:00.000000000 +0100
13956 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/include/linux/vserver/percpu.h      2011-01-29 02:01:07.000000000 +0100
13957 @@ -0,0 +1,14 @@
13958 +#ifndef _VX_PERCPU_H
13959 +#define _VX_PERCPU_H
13960 +
13961 +#include "cvirt_def.h"
13962 +#include "sched_def.h"
13963 +
13964 +struct _vx_percpu {
13965 +       struct _vx_cvirt_pc cvirt;
13966 +       struct _vx_sched_pc sched;
13967 +};
13968 +
13969 +#define        PERCPU_PERCTX   (sizeof(struct _vx_percpu))
13970 +
13971 +#endif /* _VX_PERCPU_H */
13972 diff -NurpP --minimal linux-2.6.38-rc8/include/linux/vserver/pid.h linux-2.6.38-rc8-vs2.3.0.37-rc6/include/linux/vserver/pid.h
13973 --- linux-2.6.38-rc8/include/linux/vserver/pid.h        1970-01-01 01:00:00.000000000 +0100
13974 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/include/linux/vserver/pid.h 2011-01-29 02:01:07.000000000 +0100
13975 @@ -0,0 +1,51 @@
13976 +#ifndef _VSERVER_PID_H
13977 +#define _VSERVER_PID_H
13978 +
13979 +/* pid faking stuff */
13980 +
13981 +#define vx_info_map_pid(v, p) \
13982 +       __vx_info_map_pid((v), (p), __func__, __FILE__, __LINE__)
13983 +#define vx_info_map_tgid(v,p)  vx_info_map_pid(v,p)
13984 +#define vx_map_pid(p) vx_info_map_pid(current_vx_info(), p)
13985 +#define vx_map_tgid(p) vx_map_pid(p)
13986 +
13987 +static inline int __vx_info_map_pid(struct vx_info *vxi, int pid,
13988 +       const char *func, const char *file, int line)
13989 +{
13990 +       if (vx_info_flags(vxi, VXF_INFO_INIT, 0)) {
13991 +               vxfprintk(VXD_CBIT(cvirt, 2),
13992 +                       "vx_map_tgid: %p/%llx: %d -> %d",
13993 +                       vxi, (long long)vxi->vx_flags, pid,
13994 +                       (pid && pid == vxi->vx_initpid) ? 1 : pid,
13995 +                       func, file, line);
13996 +               if (pid == 0)
13997 +                       return 0;
13998 +               if (pid == vxi->vx_initpid)
13999 +                       return 1;
14000 +       }
14001 +       return pid;
14002 +}
14003 +
14004 +#define vx_info_rmap_pid(v, p) \
14005 +       __vx_info_rmap_pid((v), (p), __func__, __FILE__, __LINE__)
14006 +#define vx_rmap_pid(p) vx_info_rmap_pid(current_vx_info(), p)
14007 +#define vx_rmap_tgid(p) vx_rmap_pid(p)
14008 +
14009 +static inline int __vx_info_rmap_pid(struct vx_info *vxi, int pid,
14010 +       const char *func, const char *file, int line)
14011 +{
14012 +       if (vx_info_flags(vxi, VXF_INFO_INIT, 0)) {
14013 +               vxfprintk(VXD_CBIT(cvirt, 2),
14014 +                       "vx_rmap_tgid: %p/%llx: %d -> %d",
14015 +                       vxi, (long long)vxi->vx_flags, pid,
14016 +                       (pid == 1) ? vxi->vx_initpid : pid,
14017 +                       func, file, line);
14018 +               if ((pid == 1) && vxi->vx_initpid)
14019 +                       return vxi->vx_initpid;
14020 +               if (pid == vxi->vx_initpid)
14021 +                       return ~0U;
14022 +       }
14023 +       return pid;
14024 +}
14025 +
14026 +#endif
14027 diff -NurpP --minimal linux-2.6.38-rc8/include/linux/vserver/sched.h linux-2.6.38-rc8-vs2.3.0.37-rc6/include/linux/vserver/sched.h
14028 --- linux-2.6.38-rc8/include/linux/vserver/sched.h      1970-01-01 01:00:00.000000000 +0100
14029 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/include/linux/vserver/sched.h       2011-01-29 02:01:07.000000000 +0100
14030 @@ -0,0 +1,23 @@
14031 +#ifndef _VX_SCHED_H
14032 +#define _VX_SCHED_H
14033 +
14034 +
14035 +#ifdef __KERNEL__
14036 +
14037 +struct timespec;
14038 +
14039 +void vx_vsi_uptime(struct timespec *, struct timespec *);
14040 +
14041 +
14042 +struct vx_info;
14043 +
14044 +void vx_update_load(struct vx_info *);
14045 +
14046 +
14047 +void vx_update_sched_param(struct _vx_sched *sched,
14048 +       struct _vx_sched_pc *sched_pc);
14049 +
14050 +#endif /* __KERNEL__ */
14051 +#else  /* _VX_SCHED_H */
14052 +#warning duplicate inclusion
14053 +#endif /* _VX_SCHED_H */
14054 diff -NurpP --minimal linux-2.6.38-rc8/include/linux/vserver/sched_cmd.h linux-2.6.38-rc8-vs2.3.0.37-rc6/include/linux/vserver/sched_cmd.h
14055 --- linux-2.6.38-rc8/include/linux/vserver/sched_cmd.h  1970-01-01 01:00:00.000000000 +0100
14056 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/include/linux/vserver/sched_cmd.h   2011-01-29 02:01:07.000000000 +0100
14057 @@ -0,0 +1,21 @@
14058 +#ifndef _VX_SCHED_CMD_H
14059 +#define _VX_SCHED_CMD_H
14060 +
14061 +
14062 +struct vcmd_prio_bias {
14063 +       int32_t cpu_id;
14064 +       int32_t prio_bias;
14065 +};
14066 +
14067 +#define VCMD_set_prio_bias     VC_CMD(SCHED, 4, 0)
14068 +#define VCMD_get_prio_bias     VC_CMD(SCHED, 5, 0)
14069 +
14070 +#ifdef __KERNEL__
14071 +
14072 +#include <linux/compiler.h>
14073 +
14074 +extern int vc_set_prio_bias(struct vx_info *, void __user *);
14075 +extern int vc_get_prio_bias(struct vx_info *, void __user *);
14076 +
14077 +#endif /* __KERNEL__ */
14078 +#endif /* _VX_SCHED_CMD_H */
14079 diff -NurpP --minimal linux-2.6.38-rc8/include/linux/vserver/sched_def.h linux-2.6.38-rc8-vs2.3.0.37-rc6/include/linux/vserver/sched_def.h
14080 --- linux-2.6.38-rc8/include/linux/vserver/sched_def.h  1970-01-01 01:00:00.000000000 +0100
14081 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/include/linux/vserver/sched_def.h   2011-01-29 02:01:07.000000000 +0100
14082 @@ -0,0 +1,38 @@
14083 +#ifndef _VX_SCHED_DEF_H
14084 +#define _VX_SCHED_DEF_H
14085 +
14086 +#include <linux/spinlock.h>
14087 +#include <linux/jiffies.h>
14088 +#include <linux/cpumask.h>
14089 +#include <asm/atomic.h>
14090 +#include <asm/param.h>
14091 +
14092 +
14093 +/* context sub struct */
14094 +
14095 +struct _vx_sched {
14096 +       int prio_bias;                  /* bias offset for priority */
14097 +
14098 +       cpumask_t update;               /* CPUs which should update */
14099 +};
14100 +
14101 +struct _vx_sched_pc {
14102 +       int prio_bias;                  /* bias offset for priority */
14103 +
14104 +       uint64_t user_ticks;            /* token tick events */
14105 +       uint64_t sys_ticks;             /* token tick events */
14106 +       uint64_t hold_ticks;            /* token ticks paused */
14107 +};
14108 +
14109 +
14110 +#ifdef CONFIG_VSERVER_DEBUG
14111 +
14112 +static inline void __dump_vx_sched(struct _vx_sched *sched)
14113 +{
14114 +       printk("\t_vx_sched:\n");
14115 +       printk("\t priority = %4d\n", sched->prio_bias);
14116 +}
14117 +
14118 +#endif
14119 +
14120 +#endif /* _VX_SCHED_DEF_H */
14121 diff -NurpP --minimal linux-2.6.38-rc8/include/linux/vserver/signal.h linux-2.6.38-rc8-vs2.3.0.37-rc6/include/linux/vserver/signal.h
14122 --- linux-2.6.38-rc8/include/linux/vserver/signal.h     1970-01-01 01:00:00.000000000 +0100
14123 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/include/linux/vserver/signal.h      2011-01-29 02:01:07.000000000 +0100
14124 @@ -0,0 +1,14 @@
14125 +#ifndef _VX_SIGNAL_H
14126 +#define _VX_SIGNAL_H
14127 +
14128 +
14129 +#ifdef __KERNEL__
14130 +
14131 +struct vx_info;
14132 +
14133 +int vx_info_kill(struct vx_info *, int, int);
14134 +
14135 +#endif /* __KERNEL__ */
14136 +#else  /* _VX_SIGNAL_H */
14137 +#warning duplicate inclusion
14138 +#endif /* _VX_SIGNAL_H */
14139 diff -NurpP --minimal linux-2.6.38-rc8/include/linux/vserver/signal_cmd.h linux-2.6.38-rc8-vs2.3.0.37-rc6/include/linux/vserver/signal_cmd.h
14140 --- linux-2.6.38-rc8/include/linux/vserver/signal_cmd.h 1970-01-01 01:00:00.000000000 +0100
14141 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/include/linux/vserver/signal_cmd.h  2011-01-29 02:01:07.000000000 +0100
14142 @@ -0,0 +1,43 @@
14143 +#ifndef _VX_SIGNAL_CMD_H
14144 +#define _VX_SIGNAL_CMD_H
14145 +
14146 +
14147 +/*  signalling vserver commands */
14148 +
14149 +#define VCMD_ctx_kill          VC_CMD(PROCTRL, 1, 0)
14150 +#define VCMD_wait_exit         VC_CMD(EVENT, 99, 0)
14151 +
14152 +struct vcmd_ctx_kill_v0 {
14153 +       int32_t pid;
14154 +       int32_t sig;
14155 +};
14156 +
14157 +struct vcmd_wait_exit_v0 {
14158 +       int32_t reboot_cmd;
14159 +       int32_t exit_code;
14160 +};
14161 +
14162 +#ifdef __KERNEL__
14163 +
14164 +extern int vc_ctx_kill(struct vx_info *, void __user *);
14165 +extern int vc_wait_exit(struct vx_info *, void __user *);
14166 +
14167 +#endif /* __KERNEL__ */
14168 +
14169 +/*  process alteration commands */
14170 +
14171 +#define VCMD_get_pflags                VC_CMD(PROCALT, 5, 0)
14172 +#define VCMD_set_pflags                VC_CMD(PROCALT, 6, 0)
14173 +
14174 +struct vcmd_pflags_v0 {
14175 +       uint32_t flagword;
14176 +       uint32_t mask;
14177 +};
14178 +
14179 +#ifdef __KERNEL__
14180 +
14181 +extern int vc_get_pflags(uint32_t pid, void __user *);
14182 +extern int vc_set_pflags(uint32_t pid, void __user *);
14183 +
14184 +#endif /* __KERNEL__ */
14185 +#endif /* _VX_SIGNAL_CMD_H */
14186 diff -NurpP --minimal linux-2.6.38-rc8/include/linux/vserver/space.h linux-2.6.38-rc8-vs2.3.0.37-rc6/include/linux/vserver/space.h
14187 --- linux-2.6.38-rc8/include/linux/vserver/space.h      1970-01-01 01:00:00.000000000 +0100
14188 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/include/linux/vserver/space.h       2011-01-29 02:01:07.000000000 +0100
14189 @@ -0,0 +1,12 @@
14190 +#ifndef _VX_SPACE_H
14191 +#define _VX_SPACE_H
14192 +
14193 +#include <linux/types.h>
14194 +
14195 +struct vx_info;
14196 +
14197 +int vx_set_space(struct vx_info *vxi, unsigned long mask, unsigned index);
14198 +
14199 +#else  /* _VX_SPACE_H */
14200 +#warning duplicate inclusion
14201 +#endif /* _VX_SPACE_H */
14202 diff -NurpP --minimal linux-2.6.38-rc8/include/linux/vserver/space_cmd.h linux-2.6.38-rc8-vs2.3.0.37-rc6/include/linux/vserver/space_cmd.h
14203 --- linux-2.6.38-rc8/include/linux/vserver/space_cmd.h  1970-01-01 01:00:00.000000000 +0100
14204 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/include/linux/vserver/space_cmd.h   2011-01-29 02:01:07.000000000 +0100
14205 @@ -0,0 +1,38 @@
14206 +#ifndef _VX_SPACE_CMD_H
14207 +#define _VX_SPACE_CMD_H
14208 +
14209 +
14210 +#define VCMD_enter_space_v0    VC_CMD(PROCALT, 1, 0)
14211 +#define VCMD_enter_space_v1    VC_CMD(PROCALT, 1, 1)
14212 +#define VCMD_enter_space       VC_CMD(PROCALT, 1, 2)
14213 +
14214 +#define VCMD_set_space_v0      VC_CMD(PROCALT, 3, 0)
14215 +#define VCMD_set_space_v1      VC_CMD(PROCALT, 3, 1)
14216 +#define VCMD_set_space         VC_CMD(PROCALT, 3, 2)
14217 +
14218 +#define VCMD_get_space_mask_v0 VC_CMD(PROCALT, 4, 0)
14219 +
14220 +#define VCMD_get_space_mask    VC_CMD(VSPACE, 0, 1)
14221 +#define VCMD_get_space_default VC_CMD(VSPACE, 1, 0)
14222 +
14223 +
14224 +struct vcmd_space_mask_v1 {
14225 +       uint64_t mask;
14226 +};
14227 +
14228 +struct vcmd_space_mask_v2 {
14229 +       uint64_t mask;
14230 +       uint32_t index;
14231 +};
14232 +
14233 +
14234 +#ifdef __KERNEL__
14235 +
14236 +extern int vc_enter_space_v1(struct vx_info *, void __user *);
14237 +extern int vc_set_space_v1(struct vx_info *, void __user *);
14238 +extern int vc_enter_space(struct vx_info *, void __user *);
14239 +extern int vc_set_space(struct vx_info *, void __user *);
14240 +extern int vc_get_space_mask(void __user *, int);
14241 +
14242 +#endif /* __KERNEL__ */
14243 +#endif /* _VX_SPACE_CMD_H */
14244 diff -NurpP --minimal linux-2.6.38-rc8/include/linux/vserver/switch.h linux-2.6.38-rc8-vs2.3.0.37-rc6/include/linux/vserver/switch.h
14245 --- linux-2.6.38-rc8/include/linux/vserver/switch.h     1970-01-01 01:00:00.000000000 +0100
14246 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/include/linux/vserver/switch.h      2011-01-29 02:01:07.000000000 +0100
14247 @@ -0,0 +1,98 @@
14248 +#ifndef _VX_SWITCH_H
14249 +#define _VX_SWITCH_H
14250 +
14251 +#include <linux/types.h>
14252 +
14253 +
14254 +#define VC_CATEGORY(c)         (((c) >> 24) & 0x3F)
14255 +#define VC_COMMAND(c)          (((c) >> 16) & 0xFF)
14256 +#define VC_VERSION(c)          ((c) & 0xFFF)
14257 +
14258 +#define VC_CMD(c, i, v)                ((((VC_CAT_ ## c) & 0x3F) << 24) \
14259 +                               | (((i) & 0xFF) << 16) | ((v) & 0xFFF))
14260 +
14261 +/*
14262 +
14263 +  Syscall Matrix V2.8
14264 +
14265 +        |VERSION|CREATE |MODIFY |MIGRATE|CONTROL|EXPERIM| |SPECIAL|SPECIAL|
14266 +        |STATS  |DESTROY|ALTER  |CHANGE |LIMIT  |TEST   | |       |       |
14267 +        |INFO   |SETUP  |       |MOVE   |       |       | |       |       |
14268 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
14269 +  SYSTEM |VERSION|VSETUP |VHOST  |       |       |       | |DEVICE |       |
14270 +  HOST   |     00|     01|     02|     03|     04|     05| |     06|     07|
14271 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
14272 +  CPU    |       |VPROC  |PROCALT|PROCMIG|PROCTRL|       | |SCHED. |       |
14273 +  PROCESS|     08|     09|     10|     11|     12|     13| |     14|     15|
14274 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
14275 +  MEMORY |       |       |       |       |MEMCTRL|       | |SWAP   |       |
14276 +        |     16|     17|     18|     19|     20|     21| |     22|     23|
14277 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
14278 +  NETWORK|       |VNET   |NETALT |NETMIG |NETCTL |       | |SERIAL |       |
14279 +        |     24|     25|     26|     27|     28|     29| |     30|     31|
14280 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
14281 +  DISK   |       |       |       |TAGMIG |DLIMIT |       | |INODE  |       |
14282 +  VFS    |     32|     33|     34|     35|     36|     37| |     38|     39|
14283 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
14284 +  OTHER  |VSTAT  |       |       |       |       |       | |VINFO  |       |
14285 +        |     40|     41|     42|     43|     44|     45| |     46|     47|
14286 +  =======+=======+=======+=======+=======+=======+=======+ +=======+=======+
14287 +  SPECIAL|EVENT  |       |       |       |FLAGS  |       | |VSPACE |       |
14288 +        |     48|     49|     50|     51|     52|     53| |     54|     55|
14289 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
14290 +  SPECIAL|DEBUG  |       |       |       |RLIMIT |SYSCALL| |       |COMPAT |
14291 +        |     56|     57|     58|     59|     60|TEST 61| |     62|     63|
14292 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
14293 +
14294 +*/
14295 +
14296 +#define VC_CAT_VERSION         0
14297 +
14298 +#define VC_CAT_VSETUP          1
14299 +#define VC_CAT_VHOST           2
14300 +
14301 +#define VC_CAT_DEVICE          6
14302 +
14303 +#define VC_CAT_VPROC           9
14304 +#define VC_CAT_PROCALT         10
14305 +#define VC_CAT_PROCMIG         11
14306 +#define VC_CAT_PROCTRL         12
14307 +
14308 +#define VC_CAT_SCHED           14
14309 +#define VC_CAT_MEMCTRL         20
14310 +
14311 +#define VC_CAT_VNET            25
14312 +#define VC_CAT_NETALT          26
14313 +#define VC_CAT_NETMIG          27
14314 +#define VC_CAT_NETCTRL         28
14315 +
14316 +#define VC_CAT_TAGMIG          35
14317 +#define VC_CAT_DLIMIT          36
14318 +#define VC_CAT_INODE           38
14319 +
14320 +#define VC_CAT_VSTAT           40
14321 +#define VC_CAT_VINFO           46
14322 +#define VC_CAT_EVENT           48
14323 +
14324 +#define VC_CAT_FLAGS           52
14325 +#define VC_CAT_VSPACE          54
14326 +#define VC_CAT_DEBUG           56
14327 +#define VC_CAT_RLIMIT          60
14328 +
14329 +#define VC_CAT_SYSTEST         61
14330 +#define VC_CAT_COMPAT          63
14331 +
14332 +/*  query version */
14333 +
14334 +#define VCMD_get_version       VC_CMD(VERSION, 0, 0)
14335 +#define VCMD_get_vci           VC_CMD(VERSION, 1, 0)
14336 +
14337 +
14338 +#ifdef __KERNEL__
14339 +
14340 +#include <linux/errno.h>
14341 +
14342 +#endif /* __KERNEL__ */
14343 +
14344 +#endif /* _VX_SWITCH_H */
14345 +
14346 diff -NurpP --minimal linux-2.6.38-rc8/include/linux/vserver/tag.h linux-2.6.38-rc8-vs2.3.0.37-rc6/include/linux/vserver/tag.h
14347 --- linux-2.6.38-rc8/include/linux/vserver/tag.h        1970-01-01 01:00:00.000000000 +0100
14348 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/include/linux/vserver/tag.h 2011-01-29 02:01:07.000000000 +0100
14349 @@ -0,0 +1,143 @@
14350 +#ifndef _DX_TAG_H
14351 +#define _DX_TAG_H
14352 +
14353 +#include <linux/types.h>
14354 +
14355 +
14356 +#define DX_TAG(in)     (IS_TAGGED(in))
14357 +
14358 +
14359 +#ifdef CONFIG_TAG_NFSD
14360 +#define DX_TAG_NFSD    1
14361 +#else
14362 +#define DX_TAG_NFSD    0
14363 +#endif
14364 +
14365 +
14366 +#ifdef CONFIG_TAGGING_NONE
14367 +
14368 +#define MAX_UID                0xFFFFFFFF
14369 +#define MAX_GID                0xFFFFFFFF
14370 +
14371 +#define INOTAG_TAG(cond, uid, gid, tag)        (0)
14372 +
14373 +#define TAGINO_UID(cond, uid, tag)     (uid)
14374 +#define TAGINO_GID(cond, gid, tag)     (gid)
14375 +
14376 +#endif
14377 +
14378 +
14379 +#ifdef CONFIG_TAGGING_GID16
14380 +
14381 +#define MAX_UID                0xFFFFFFFF
14382 +#define MAX_GID                0x0000FFFF
14383 +
14384 +#define INOTAG_TAG(cond, uid, gid, tag)        \
14385 +       ((cond) ? (((gid) >> 16) & 0xFFFF) : 0)
14386 +
14387 +#define TAGINO_UID(cond, uid, tag)     (uid)
14388 +#define TAGINO_GID(cond, gid, tag)     \
14389 +       ((cond) ? (((gid) & 0xFFFF) | ((tag) << 16)) : (gid))
14390 +
14391 +#endif
14392 +
14393 +
14394 +#ifdef CONFIG_TAGGING_ID24
14395 +
14396 +#define MAX_UID                0x00FFFFFF
14397 +#define MAX_GID                0x00FFFFFF
14398 +
14399 +#define INOTAG_TAG(cond, uid, gid, tag)        \
14400 +       ((cond) ? ((((uid) >> 16) & 0xFF00) | (((gid) >> 24) & 0xFF)) : 0)
14401 +
14402 +#define TAGINO_UID(cond, uid, tag)     \
14403 +       ((cond) ? (((uid) & 0xFFFFFF) | (((tag) & 0xFF00) << 16)) : (uid))
14404 +#define TAGINO_GID(cond, gid, tag)     \
14405 +       ((cond) ? (((gid) & 0xFFFFFF) | (((tag) & 0x00FF) << 24)) : (gid))
14406 +
14407 +#endif
14408 +
14409 +
14410 +#ifdef CONFIG_TAGGING_UID16
14411 +
14412 +#define MAX_UID                0x0000FFFF
14413 +#define MAX_GID                0xFFFFFFFF
14414 +
14415 +#define INOTAG_TAG(cond, uid, gid, tag)        \
14416 +       ((cond) ? (((uid) >> 16) & 0xFFFF) : 0)
14417 +
14418 +#define TAGINO_UID(cond, uid, tag)     \
14419 +       ((cond) ? (((uid) & 0xFFFF) | ((tag) << 16)) : (uid))
14420 +#define TAGINO_GID(cond, gid, tag)     (gid)
14421 +
14422 +#endif
14423 +
14424 +
14425 +#ifdef CONFIG_TAGGING_INTERN
14426 +
14427 +#define MAX_UID                0xFFFFFFFF
14428 +#define MAX_GID                0xFFFFFFFF
14429 +
14430 +#define INOTAG_TAG(cond, uid, gid, tag)        \
14431 +       ((cond) ? (tag) : 0)
14432 +
14433 +#define TAGINO_UID(cond, uid, tag)     (uid)
14434 +#define TAGINO_GID(cond, gid, tag)     (gid)
14435 +
14436 +#endif
14437 +
14438 +
14439 +#ifndef CONFIG_TAGGING_NONE
14440 +#define dx_current_fstag(sb)   \
14441 +       ((sb)->s_flags & MS_TAGGED ? dx_current_tag() : 0)
14442 +#else
14443 +#define dx_current_fstag(sb)   (0)
14444 +#endif
14445 +
14446 +#ifndef CONFIG_TAGGING_INTERN
14447 +#define TAGINO_TAG(cond, tag)  (0)
14448 +#else
14449 +#define TAGINO_TAG(cond, tag)  ((cond) ? (tag) : 0)
14450 +#endif
14451 +
14452 +#define INOTAG_UID(cond, uid, gid)     \
14453 +       ((cond) ? ((uid) & MAX_UID) : (uid))
14454 +#define INOTAG_GID(cond, uid, gid)     \
14455 +       ((cond) ? ((gid) & MAX_GID) : (gid))
14456 +
14457 +
14458 +static inline uid_t dx_map_uid(uid_t uid)
14459 +{
14460 +       if ((uid > MAX_UID) && (uid != -1))
14461 +               uid = -2;
14462 +       return (uid & MAX_UID);
14463 +}
14464 +
14465 +static inline gid_t dx_map_gid(gid_t gid)
14466 +{
14467 +       if ((gid > MAX_GID) && (gid != -1))
14468 +               gid = -2;
14469 +       return (gid & MAX_GID);
14470 +}
14471 +
14472 +struct peer_tag {
14473 +       int32_t xid;
14474 +       int32_t nid;
14475 +};
14476 +
14477 +#define dx_notagcheck(sb) ((sb) && ((sb)->s_flags & MS_NOTAGCHECK))
14478 +
14479 +int dx_parse_tag(char *string, tag_t *tag, int remove, int *mnt_flags,
14480 +                unsigned long *flags);
14481 +
14482 +#ifdef CONFIG_PROPAGATE
14483 +
14484 +void __dx_propagate_tag(struct nameidata *nd, struct inode *inode);
14485 +
14486 +#define dx_propagate_tag(n, i) __dx_propagate_tag(n, i)
14487 +
14488 +#else
14489 +#define dx_propagate_tag(n, i) do { } while (0)
14490 +#endif
14491 +
14492 +#endif /* _DX_TAG_H */
14493 diff -NurpP --minimal linux-2.6.38-rc8/include/linux/vserver/tag_cmd.h linux-2.6.38-rc8-vs2.3.0.37-rc6/include/linux/vserver/tag_cmd.h
14494 --- linux-2.6.38-rc8/include/linux/vserver/tag_cmd.h    1970-01-01 01:00:00.000000000 +0100
14495 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/include/linux/vserver/tag_cmd.h     2011-01-29 02:01:07.000000000 +0100
14496 @@ -0,0 +1,22 @@
14497 +#ifndef _VX_TAG_CMD_H
14498 +#define _VX_TAG_CMD_H
14499 +
14500 +
14501 +/* vinfo commands */
14502 +
14503 +#define VCMD_task_tag          VC_CMD(VINFO, 3, 0)
14504 +
14505 +#ifdef __KERNEL__
14506 +extern int vc_task_tag(uint32_t);
14507 +
14508 +#endif /* __KERNEL__ */
14509 +
14510 +/* context commands */
14511 +
14512 +#define VCMD_tag_migrate       VC_CMD(TAGMIG, 1, 0)
14513 +
14514 +#ifdef __KERNEL__
14515 +extern int vc_tag_migrate(uint32_t);
14516 +
14517 +#endif /* __KERNEL__ */
14518 +#endif /* _VX_TAG_CMD_H */
14519 diff -NurpP --minimal linux-2.6.38-rc8/include/net/addrconf.h linux-2.6.38-rc8-vs2.3.0.37-rc6/include/net/addrconf.h
14520 --- linux-2.6.38-rc8/include/net/addrconf.h     2011-03-10 17:09:26.000000000 +0100
14521 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/include/net/addrconf.h      2011-01-29 02:01:07.000000000 +0100
14522 @@ -82,7 +82,8 @@ extern int                    ipv6_dev_get_saddr(struct n
14523                                                struct net_device *dev,
14524                                                const struct in6_addr *daddr,
14525                                                unsigned int srcprefs,
14526 -                                              struct in6_addr *saddr);
14527 +                                              struct in6_addr *saddr,
14528 +                                              struct nx_info *nxi);
14529  extern int                     ipv6_get_lladdr(struct net_device *dev,
14530                                                 struct in6_addr *addr,
14531                                                 unsigned char banned_flags);
14532 diff -NurpP --minimal linux-2.6.38-rc8/include/net/af_unix.h linux-2.6.38-rc8-vs2.3.0.37-rc6/include/net/af_unix.h
14533 --- linux-2.6.38-rc8/include/net/af_unix.h      2011-01-05 21:50:35.000000000 +0100
14534 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/include/net/af_unix.h       2011-01-29 02:01:07.000000000 +0100
14535 @@ -4,6 +4,7 @@
14536  #include <linux/socket.h>
14537  #include <linux/un.h>
14538  #include <linux/mutex.h>
14539 +#include <linux/vs_base.h>
14540  #include <net/sock.h>
14541  
14542  extern void unix_inflight(struct file *fp);
14543 diff -NurpP --minimal linux-2.6.38-rc8/include/net/inet_timewait_sock.h linux-2.6.38-rc8-vs2.3.0.37-rc6/include/net/inet_timewait_sock.h
14544 --- linux-2.6.38-rc8/include/net/inet_timewait_sock.h   2011-03-10 17:09:26.000000000 +0100
14545 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/include/net/inet_timewait_sock.h    2011-01-29 03:12:58.000000000 +0100
14546 @@ -113,6 +113,10 @@ struct inet_timewait_sock {
14547  #define tw_net                 __tw_common.skc_net
14548  #define tw_daddr               __tw_common.skc_daddr
14549  #define tw_rcv_saddr           __tw_common.skc_rcv_saddr
14550 +#define tw_xid                 __tw_common.skc_xid
14551 +#define tw_vx_info             __tw_common.skc_vx_info
14552 +#define tw_nid                 __tw_common.skc_nid
14553 +#define tw_nx_info             __tw_common.skc_nx_info
14554         int                     tw_timeout;
14555         volatile unsigned char  tw_substate;
14556         unsigned char           tw_rcv_wscale;
14557 diff -NurpP --minimal linux-2.6.38-rc8/include/net/route.h linux-2.6.38-rc8-vs2.3.0.37-rc6/include/net/route.h
14558 --- linux-2.6.38-rc8/include/net/route.h        2011-03-10 17:09:26.000000000 +0100
14559 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/include/net/route.h 2011-01-29 02:01:07.000000000 +0100
14560 @@ -153,6 +153,9 @@ static inline void ip_rt_put(struct rtab
14561                 dst_release(&rt->dst);
14562  }
14563  
14564 +#include <linux/vs_base.h>
14565 +#include <linux/vs_inet.h>
14566 +
14567  #define IPTOS_RT_MASK  (IPTOS_TOS_MASK & ~3)
14568  
14569  extern const __u8 ip_tos2prio[16];
14570 @@ -162,6 +165,9 @@ static inline char rt_tos2priority(u8 to
14571         return ip_tos2prio[IPTOS_TOS(tos)>>1];
14572  }
14573  
14574 +extern int ip_v4_find_src(struct net *net, struct nx_info *,
14575 +       struct rtable **, struct flowi *);
14576 +
14577  static inline int ip_route_connect(struct rtable **rp, __be32 dst,
14578                                    __be32 src, u32 tos, int oif, u8 protocol,
14579                                    __be16 sport, __be16 dport, struct sock *sk,
14580 @@ -177,11 +183,24 @@ static inline int ip_route_connect(struc
14581                             .fl_ip_dport = dport };
14582         int err;
14583         struct net *net = sock_net(sk);
14584 +       struct nx_info *nx_info = current_nx_info();
14585  
14586         if (inet_sk(sk)->transparent)
14587                 fl.flags |= FLOWI_FLAG_ANYSRC;
14588  
14589 -       if (!dst || !src) {
14590 +       if (sk)
14591 +               nx_info = sk->sk_nx_info;
14592 +
14593 +       vxdprintk(VXD_CBIT(net, 4),
14594 +               "ip_route_connect(%p) %p,%p;%lx",
14595 +               sk, nx_info, sk->sk_socket,
14596 +               (sk->sk_socket?sk->sk_socket->flags:0));
14597 +
14598 +       err = ip_v4_find_src(net, nx_info, rp, &fl);
14599 +       if (err)
14600 +               return err;
14601 +
14602 +       if (!fl.fl4_dst || !fl.fl4_src) {
14603                 err = __ip_route_output_key(net, rp, &fl);
14604                 if (err)
14605                         return err;
14606 diff -NurpP --minimal linux-2.6.38-rc8/include/net/sock.h linux-2.6.38-rc8-vs2.3.0.37-rc6/include/net/sock.h
14607 --- linux-2.6.38-rc8/include/net/sock.h 2011-03-10 17:09:26.000000000 +0100
14608 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/include/net/sock.h  2011-02-17 02:17:51.000000000 +0100
14609 @@ -148,6 +148,10 @@ struct sock_common {
14610  #ifdef CONFIG_NET_NS
14611         struct net              *skc_net;
14612  #endif
14613 +       xid_t                   skc_xid;
14614 +       struct vx_info          *skc_vx_info;
14615 +       nid_t                   skc_nid;
14616 +       struct nx_info          *skc_nx_info;
14617         /*
14618          * fields between dontcopy_begin/dontcopy_end
14619          * are not copied in sock_copy()
14620 @@ -256,6 +260,10 @@ struct sock {
14621  #define sk_bind_node           __sk_common.skc_bind_node
14622  #define sk_prot                        __sk_common.skc_prot
14623  #define sk_net                 __sk_common.skc_net
14624 +#define sk_xid                 __sk_common.skc_xid
14625 +#define sk_vx_info             __sk_common.skc_vx_info
14626 +#define sk_nid                 __sk_common.skc_nid
14627 +#define sk_nx_info             __sk_common.skc_nx_info
14628         socket_lock_t           sk_lock;
14629         struct sk_buff_head     sk_receive_queue;
14630         /*
14631 diff -NurpP --minimal linux-2.6.38-rc8/init/Kconfig linux-2.6.38-rc8-vs2.3.0.37-rc6/init/Kconfig
14632 --- linux-2.6.38-rc8/init/Kconfig       2011-03-10 17:09:27.000000000 +0100
14633 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/init/Kconfig        2011-01-29 02:01:07.000000000 +0100
14634 @@ -559,6 +559,7 @@ config HAVE_UNSTABLE_SCHED_CLOCK
14635  menuconfig CGROUPS
14636         boolean "Control Group support"
14637         depends on EVENTFD
14638 +       default y
14639         help
14640           This option adds support for grouping sets of processes together, for
14641           use with process control subsystems such as Cpusets, CFS, memory
14642 @@ -584,6 +585,7 @@ config CGROUP_DEBUG
14643  
14644  config CGROUP_NS
14645         bool "Namespace cgroup subsystem"
14646 +       default n
14647         help
14648           Provides a simple namespace cgroup subsystem to
14649           provide hierarchical naming of sets of namespaces,
14650 diff -NurpP --minimal linux-2.6.38-rc8/init/main.c linux-2.6.38-rc8-vs2.3.0.37-rc6/init/main.c
14651 --- linux-2.6.38-rc8/init/main.c        2011-03-10 17:09:27.000000000 +0100
14652 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/init/main.c 2011-01-29 02:21:25.000000000 +0100
14653 @@ -68,6 +68,7 @@
14654  #include <linux/shmem_fs.h>
14655  #include <linux/slab.h>
14656  #include <linux/perf_event.h>
14657 +#include <linux/vserver/percpu.h>
14658  
14659  #include <asm/io.h>
14660  #include <asm/bugs.h>
14661 diff -NurpP --minimal linux-2.6.38-rc8/ipc/mqueue.c linux-2.6.38-rc8-vs2.3.0.37-rc6/ipc/mqueue.c
14662 --- linux-2.6.38-rc8/ipc/mqueue.c       2011-03-10 17:09:27.000000000 +0100
14663 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/ipc/mqueue.c        2011-01-29 02:01:07.000000000 +0100
14664 @@ -33,6 +33,8 @@
14665  #include <linux/pid.h>
14666  #include <linux/ipc_namespace.h>
14667  #include <linux/slab.h>
14668 +#include <linux/vs_context.h>
14669 +#include <linux/vs_limit.h>
14670  
14671  #include <net/sock.h>
14672  #include "util.h"
14673 @@ -66,6 +68,7 @@ struct mqueue_inode_info {
14674         struct sigevent notify;
14675         struct pid* notify_owner;
14676         struct user_struct *user;       /* user who created, for accounting */
14677 +       struct vx_info *vxi;
14678         struct sock *notify_sock;
14679         struct sk_buff *notify_cookie;
14680  
14681 @@ -126,6 +129,7 @@ static struct inode *mqueue_get_inode(st
14682                 if (S_ISREG(mode)) {
14683                         struct mqueue_inode_info *info;
14684                         struct task_struct *p = current;
14685 +                       struct vx_info *vxi = p->vx_info;
14686                         unsigned long mq_bytes, mq_msg_tblsz;
14687  
14688                         inode->i_fop = &mqueue_file_operations;
14689 @@ -139,6 +143,7 @@ static struct inode *mqueue_get_inode(st
14690                         info->notify_owner = NULL;
14691                         info->qsize = 0;
14692                         info->user = NULL;      /* set when all is ok */
14693 +                       info->vxi = NULL;
14694                         memset(&info->attr, 0, sizeof(info->attr));
14695                         info->attr.mq_maxmsg = ipc_ns->mq_msg_max;
14696                         info->attr.mq_msgsize = ipc_ns->mq_msgsize_max;
14697 @@ -157,16 +162,19 @@ static struct inode *mqueue_get_inode(st
14698                         spin_lock(&mq_lock);
14699                         if (u->mq_bytes + mq_bytes < u->mq_bytes ||
14700                             u->mq_bytes + mq_bytes >
14701 -                           task_rlimit(p, RLIMIT_MSGQUEUE)) {
14702 +                           task_rlimit(p, RLIMIT_MSGQUEUE) ||
14703 +                           !vx_ipcmsg_avail(vxi, mq_bytes)) {
14704                                 spin_unlock(&mq_lock);
14705                                 /* mqueue_evict_inode() releases info->messages */
14706                                 goto out_inode;
14707                         }
14708                         u->mq_bytes += mq_bytes;
14709 +                       vx_ipcmsg_add(vxi, u, mq_bytes);
14710                         spin_unlock(&mq_lock);
14711  
14712                         /* all is ok */
14713                         info->user = get_uid(u);
14714 +                       info->vxi = get_vx_info(vxi);
14715                 } else if (S_ISDIR(mode)) {
14716                         inc_nlink(inode);
14717                         /* Some things misbehave if size == 0 on a directory */
14718 @@ -275,8 +283,11 @@ static void mqueue_evict_inode(struct in
14719             + info->attr.mq_msgsize);
14720         user = info->user;
14721         if (user) {
14722 +               struct vx_info *vxi = info->vxi;
14723 +
14724                 spin_lock(&mq_lock);
14725                 user->mq_bytes -= mq_bytes;
14726 +               vx_ipcmsg_sub(vxi, user, mq_bytes);
14727                 /*
14728                  * get_ns_from_inode() ensures that the
14729                  * (ipc_ns = sb->s_fs_info) is either a valid ipc_ns
14730 @@ -286,6 +297,7 @@ static void mqueue_evict_inode(struct in
14731                 if (ipc_ns)
14732                         ipc_ns->mq_queues_count--;
14733                 spin_unlock(&mq_lock);
14734 +               put_vx_info(vxi);
14735                 free_uid(user);
14736         }
14737         if (ipc_ns)
14738 diff -NurpP --minimal linux-2.6.38-rc8/ipc/msg.c linux-2.6.38-rc8-vs2.3.0.37-rc6/ipc/msg.c
14739 --- linux-2.6.38-rc8/ipc/msg.c  2010-08-02 16:52:57.000000000 +0200
14740 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/ipc/msg.c   2011-01-29 02:01:07.000000000 +0100
14741 @@ -37,6 +37,7 @@
14742  #include <linux/rwsem.h>
14743  #include <linux/nsproxy.h>
14744  #include <linux/ipc_namespace.h>
14745 +#include <linux/vs_base.h>
14746  
14747  #include <asm/current.h>
14748  #include <asm/uaccess.h>
14749 @@ -190,6 +191,7 @@ static int newque(struct ipc_namespace *
14750  
14751         msq->q_perm.mode = msgflg & S_IRWXUGO;
14752         msq->q_perm.key = key;
14753 +       msq->q_perm.xid = vx_current_xid();
14754  
14755         msq->q_perm.security = NULL;
14756         retval = security_msg_queue_alloc(msq);
14757 diff -NurpP --minimal linux-2.6.38-rc8/ipc/namespace.c linux-2.6.38-rc8-vs2.3.0.37-rc6/ipc/namespace.c
14758 --- linux-2.6.38-rc8/ipc/namespace.c    2009-09-10 15:26:27.000000000 +0200
14759 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/ipc/namespace.c     2011-01-29 02:01:07.000000000 +0100
14760 @@ -11,6 +11,8 @@
14761  #include <linux/slab.h>
14762  #include <linux/fs.h>
14763  #include <linux/mount.h>
14764 +#include <linux/vs_base.h>
14765 +#include <linux/vserver/global.h>
14766  
14767  #include "util.h"
14768  
14769 diff -NurpP --minimal linux-2.6.38-rc8/ipc/sem.c linux-2.6.38-rc8-vs2.3.0.37-rc6/ipc/sem.c
14770 --- linux-2.6.38-rc8/ipc/sem.c  2010-10-21 13:07:56.000000000 +0200
14771 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/ipc/sem.c   2011-01-29 02:01:07.000000000 +0100
14772 @@ -86,6 +86,8 @@
14773  #include <linux/rwsem.h>
14774  #include <linux/nsproxy.h>
14775  #include <linux/ipc_namespace.h>
14776 +#include <linux/vs_base.h>
14777 +#include <linux/vs_limit.h>
14778  
14779  #include <asm/uaccess.h>
14780  #include "util.h"
14781 @@ -260,6 +262,7 @@ static int newary(struct ipc_namespace *
14782  
14783         sma->sem_perm.mode = (semflg & S_IRWXUGO);
14784         sma->sem_perm.key = key;
14785 +       sma->sem_perm.xid = vx_current_xid();
14786  
14787         sma->sem_perm.security = NULL;
14788         retval = security_sem_alloc(sma);
14789 @@ -275,6 +278,9 @@ static int newary(struct ipc_namespace *
14790                 return id;
14791         }
14792         ns->used_sems += nsems;
14793 +       /* FIXME: obsoleted? */
14794 +       vx_semary_inc(sma);
14795 +       vx_nsems_add(sma, nsems);
14796  
14797         sma->sem_base = (struct sem *) &sma[1];
14798  
14799 @@ -730,6 +736,9 @@ static void freeary(struct ipc_namespace
14800  
14801         wake_up_sem_queue_do(&tasks);
14802         ns->used_sems -= sma->sem_nsems;
14803 +       /* FIXME: obsoleted? */
14804 +       vx_nsems_sub(sma, sma->sem_nsems);
14805 +       vx_semary_dec(sma);
14806         security_sem_free(sma);
14807         ipc_rcu_putref(sma);
14808  }
14809 diff -NurpP --minimal linux-2.6.38-rc8/ipc/shm.c linux-2.6.38-rc8-vs2.3.0.37-rc6/ipc/shm.c
14810 --- linux-2.6.38-rc8/ipc/shm.c  2011-01-05 21:50:37.000000000 +0100
14811 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/ipc/shm.c   2011-01-29 02:01:07.000000000 +0100
14812 @@ -39,6 +39,8 @@
14813  #include <linux/nsproxy.h>
14814  #include <linux/mount.h>
14815  #include <linux/ipc_namespace.h>
14816 +#include <linux/vs_context.h>
14817 +#include <linux/vs_limit.h>
14818  
14819  #include <asm/uaccess.h>
14820  
14821 @@ -173,7 +175,12 @@ static void shm_open(struct vm_area_stru
14822   */
14823  static void shm_destroy(struct ipc_namespace *ns, struct shmid_kernel *shp)
14824  {
14825 -       ns->shm_tot -= (shp->shm_segsz + PAGE_SIZE - 1) >> PAGE_SHIFT;
14826 +       struct vx_info *vxi = lookup_vx_info(shp->shm_perm.xid);
14827 +       int numpages = (shp->shm_segsz + PAGE_SIZE - 1) >> PAGE_SHIFT;
14828 +
14829 +       vx_ipcshm_sub(vxi, shp, numpages);
14830 +       ns->shm_tot -= numpages;
14831 +
14832         shm_rmid(ns, shp);
14833         shm_unlock(shp);
14834         if (!is_file_hugepages(shp->shm_file))
14835 @@ -183,6 +190,7 @@ static void shm_destroy(struct ipc_names
14836                                                 shp->mlock_user);
14837         fput (shp->shm_file);
14838         security_shm_free(shp);
14839 +       put_vx_info(vxi);
14840         ipc_rcu_putref(shp);
14841  }
14842  
14843 @@ -355,11 +363,15 @@ static int newseg(struct ipc_namespace *
14844         if (ns->shm_tot + numpages > ns->shm_ctlall)
14845                 return -ENOSPC;
14846  
14847 +       if (!vx_ipcshm_avail(current_vx_info(), numpages))
14848 +               return -ENOSPC;
14849 +
14850         shp = ipc_rcu_alloc(sizeof(*shp));
14851         if (!shp)
14852                 return -ENOMEM;
14853  
14854         shp->shm_perm.key = key;
14855 +       shp->shm_perm.xid = vx_current_xid();
14856         shp->shm_perm.mode = (shmflg & S_IRWXUGO);
14857         shp->mlock_user = NULL;
14858  
14859 @@ -413,6 +425,7 @@ static int newseg(struct ipc_namespace *
14860         ns->shm_tot += numpages;
14861         error = shp->shm_perm.id;
14862         shm_unlock(shp);
14863 +       vx_ipcshm_add(current_vx_info(), key, numpages);
14864         return error;
14865  
14866  no_id:
14867 diff -NurpP --minimal linux-2.6.38-rc8/kernel/Makefile linux-2.6.38-rc8-vs2.3.0.37-rc6/kernel/Makefile
14868 --- linux-2.6.38-rc8/kernel/Makefile    2011-03-10 17:09:27.000000000 +0100
14869 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/kernel/Makefile     2011-01-29 02:01:07.000000000 +0100
14870 @@ -25,6 +25,7 @@ CFLAGS_REMOVE_perf_event.o = -pg
14871  CFLAGS_REMOVE_irq_work.o = -pg
14872  endif
14873  
14874 +obj-y += vserver/
14875  obj-$(CONFIG_FREEZER) += freezer.o
14876  obj-$(CONFIG_PROFILING) += profile.o
14877  obj-$(CONFIG_SYSCTL_SYSCALL_CHECK) += sysctl_check.o
14878 diff -NurpP --minimal linux-2.6.38-rc8/kernel/capability.c linux-2.6.38-rc8-vs2.3.0.37-rc6/kernel/capability.c
14879 --- linux-2.6.38-rc8/kernel/capability.c        2011-03-10 17:09:27.000000000 +0100
14880 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/kernel/capability.c 2011-02-17 02:17:51.000000000 +0100
14881 @@ -14,6 +14,7 @@
14882  #include <linux/security.h>
14883  #include <linux/syscalls.h>
14884  #include <linux/pid_namespace.h>
14885 +#include <linux/vs_context.h>
14886  #include <asm/uaccess.h>
14887  
14888  /*
14889 @@ -119,6 +120,7 @@ static int cap_validate_magic(cap_user_h
14890         return 0;
14891  }
14892  
14893 +
14894  /*
14895   * The only thing that can change the capabilities of the current
14896   * process is the current process. As such, we can't be in this code
14897 @@ -289,6 +291,8 @@ error:
14898         return ret;
14899  }
14900  
14901 +#include <linux/vserver/base.h>
14902 +
14903  /**
14904   * capable - Determine if the current task has a superior capability in effect
14905   * @cap: The capability to be tested for
14906 @@ -301,6 +305,9 @@ error:
14907   */
14908  int capable(int cap)
14909  {
14910 +       /* here for now so we don't require task locking */
14911 +       if (vs_check_bit(VXC_CAP_MASK, cap) && !vx_mcaps(1L << cap))
14912 +               return 0;
14913         if (unlikely(!cap_valid(cap))) {
14914                 printk(KERN_CRIT "capable() called with invalid cap=%u\n", cap);
14915                 BUG();
14916 diff -NurpP --minimal linux-2.6.38-rc8/kernel/compat.c linux-2.6.38-rc8-vs2.3.0.37-rc6/kernel/compat.c
14917 --- linux-2.6.38-rc8/kernel/compat.c    2010-10-21 13:07:56.000000000 +0200
14918 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/kernel/compat.c     2011-01-29 02:01:07.000000000 +0100
14919 @@ -914,7 +914,7 @@ asmlinkage long compat_sys_stime(compat_
14920         if (err)
14921                 return err;
14922  
14923 -       do_settimeofday(&tv);
14924 +       vx_settimeofday(&tv);
14925         return 0;
14926  }
14927  
14928 diff -NurpP --minimal linux-2.6.38-rc8/kernel/cred.c linux-2.6.38-rc8-vs2.3.0.37-rc6/kernel/cred.c
14929 --- linux-2.6.38-rc8/kernel/cred.c      2011-03-10 17:09:27.000000000 +0100
14930 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/kernel/cred.c       2011-02-17 02:17:51.000000000 +0100
14931 @@ -60,31 +60,6 @@ struct cred init_cred = {
14932  #endif
14933  };
14934  
14935 -static inline void set_cred_subscribers(struct cred *cred, int n)
14936 -{
14937 -#ifdef CONFIG_DEBUG_CREDENTIALS
14938 -       atomic_set(&cred->subscribers, n);
14939 -#endif
14940 -}
14941 -
14942 -static inline int read_cred_subscribers(const struct cred *cred)
14943 -{
14944 -#ifdef CONFIG_DEBUG_CREDENTIALS
14945 -       return atomic_read(&cred->subscribers);
14946 -#else
14947 -       return 0;
14948 -#endif
14949 -}
14950 -
14951 -static inline void alter_cred_subscribers(const struct cred *_cred, int n)
14952 -{
14953 -#ifdef CONFIG_DEBUG_CREDENTIALS
14954 -       struct cred *cred = (struct cred *) _cred;
14955 -
14956 -       atomic_add(n, &cred->subscribers);
14957 -#endif
14958 -}
14959 -
14960  /*
14961   * Dispose of the shared task group credentials
14962   */
14963 @@ -280,21 +255,16 @@ error:
14964   *
14965   * Call commit_creds() or abort_creds() to clean up.
14966   */
14967 -struct cred *prepare_creds(void)
14968 +struct cred *__prepare_creds(const struct cred *old)
14969  {
14970 -       struct task_struct *task = current;
14971 -       const struct cred *old;
14972         struct cred *new;
14973  
14974 -       validate_process_creds();
14975 -
14976         new = kmem_cache_alloc(cred_jar, GFP_KERNEL);
14977         if (!new)
14978                 return NULL;
14979  
14980         kdebug("prepare_creds() alloc %p", new);
14981  
14982 -       old = task->cred;
14983         memcpy(new, old, sizeof(struct cred));
14984  
14985         atomic_set(&new->usage, 1);
14986 @@ -321,6 +291,13 @@ error:
14987         abort_creds(new);
14988         return NULL;
14989  }
14990 +
14991 +struct cred *prepare_creds(void)
14992 +{
14993 +       validate_process_creds();
14994 +
14995 +       return __prepare_creds(current->cred);
14996 +}
14997  EXPORT_SYMBOL(prepare_creds);
14998  
14999  /*
15000 diff -NurpP --minimal linux-2.6.38-rc8/kernel/exit.c linux-2.6.38-rc8-vs2.3.0.37-rc6/kernel/exit.c
15001 --- linux-2.6.38-rc8/kernel/exit.c      2011-03-10 17:09:27.000000000 +0100
15002 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/kernel/exit.c       2011-01-29 02:01:07.000000000 +0100
15003 @@ -48,6 +48,10 @@
15004  #include <linux/fs_struct.h>
15005  #include <linux/init_task.h>
15006  #include <linux/perf_event.h>
15007 +#include <linux/vs_limit.h>
15008 +#include <linux/vs_context.h>
15009 +#include <linux/vs_network.h>
15010 +#include <linux/vs_pid.h>
15011  #include <trace/events/sched.h>
15012  #include <linux/hw_breakpoint.h>
15013  #include <linux/oom.h>
15014 @@ -494,9 +498,11 @@ static void close_files(struct files_str
15015                                         filp_close(file, files);
15016                                         cond_resched();
15017                                 }
15018 +                               vx_openfd_dec(i);
15019                         }
15020                         i++;
15021                         set >>= 1;
15022 +                       cond_resched();
15023                 }
15024         }
15025  }
15026 @@ -1047,11 +1053,16 @@ NORET_TYPE void do_exit(long code)
15027  
15028         validate_creds_for_do_exit(tsk);
15029  
15030 +       /* needs to stay after exit_notify() */
15031 +       exit_vx_info(tsk, code);
15032 +       exit_nx_info(tsk);
15033 +
15034         preempt_disable();
15035         exit_rcu();
15036         /* causes final put_task_struct in finish_task_switch(). */
15037         tsk->state = TASK_DEAD;
15038         schedule();
15039 +       printk("bad task: %p [%lx]\n", current, current->state);
15040         BUG();
15041         /* Avoid "noreturn function does return".  */
15042         for (;;)
15043 diff -NurpP --minimal linux-2.6.38-rc8/kernel/fork.c linux-2.6.38-rc8-vs2.3.0.37-rc6/kernel/fork.c
15044 --- linux-2.6.38-rc8/kernel/fork.c      2011-03-10 17:09:27.000000000 +0100
15045 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/kernel/fork.c       2011-01-29 03:19:29.000000000 +0100
15046 @@ -67,6 +67,10 @@
15047  #include <linux/user-return-notifier.h>
15048  #include <linux/oom.h>
15049  #include <linux/khugepaged.h>
15050 +#include <linux/vs_context.h>
15051 +#include <linux/vs_network.h>
15052 +#include <linux/vs_limit.h>
15053 +#include <linux/vs_memory.h>
15054  
15055  #include <asm/pgtable.h>
15056  #include <asm/pgalloc.h>
15057 @@ -162,6 +166,8 @@ void free_task(struct task_struct *tsk)
15058         account_kernel_stack(tsk->stack, -1);
15059         free_thread_info(tsk->stack);
15060         rt_mutex_debug_task_free(tsk);
15061 +       clr_vx_info(&tsk->vx_info);
15062 +       clr_nx_info(&tsk->nx_info);
15063         ftrace_graph_exit_task(tsk);
15064         free_task_struct(tsk);
15065  }
15066 @@ -500,6 +506,7 @@ static struct mm_struct * mm_init(struct
15067         if (likely(!mm_alloc_pgd(mm))) {
15068                 mm->def_flags = 0;
15069                 mmu_notifier_mm_init(mm);
15070 +               set_vx_info(&mm->mm_vx_info, p->vx_info);
15071                 return mm;
15072         }
15073  
15074 @@ -536,6 +543,7 @@ void __mmdrop(struct mm_struct *mm)
15075  #ifdef CONFIG_TRANSPARENT_HUGEPAGE
15076         VM_BUG_ON(mm->pmd_huge_pte);
15077  #endif
15078 +       clr_vx_info(&mm->mm_vx_info);
15079         free_mm(mm);
15080  }
15081  EXPORT_SYMBOL_GPL(__mmdrop);
15082 @@ -672,6 +680,7 @@ struct mm_struct *dup_mm(struct task_str
15083                 goto fail_nomem;
15084  
15085         memcpy(mm, oldmm, sizeof(*mm));
15086 +       mm->mm_vx_info = NULL;
15087  
15088         /* Initializing for Swap token stuff */
15089         mm->token_priority = 0;
15090 @@ -714,6 +723,7 @@ fail_nocontext:
15091          * If init_new_context() failed, we cannot use mmput() to free the mm
15092          * because it calls destroy_context()
15093          */
15094 +       clr_vx_info(&mm->mm_vx_info);
15095         mm_free_pgd(mm);
15096         free_mm(mm);
15097         return NULL;
15098 @@ -995,6 +1005,8 @@ static struct task_struct *copy_process(
15099         int retval;
15100         struct task_struct *p;
15101         int cgroup_callbacks_done = 0;
15102 +       struct vx_info *vxi;
15103 +       struct nx_info *nxi;
15104  
15105         if ((clone_flags & (CLONE_NEWNS|CLONE_FS)) == (CLONE_NEWNS|CLONE_FS))
15106                 return ERR_PTR(-EINVAL);
15107 @@ -1041,7 +1053,12 @@ static struct task_struct *copy_process(
15108         DEBUG_LOCKS_WARN_ON(!p->hardirqs_enabled);
15109         DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
15110  #endif
15111 +       init_vx_info(&p->vx_info, current_vx_info());
15112 +       init_nx_info(&p->nx_info, current_nx_info());
15113 +
15114         retval = -EAGAIN;
15115 +       if (!vx_nproc_avail(1))
15116 +               goto bad_fork_free;
15117         if (atomic_read(&p->real_cred->user->processes) >=
15118                         task_rlimit(p, RLIMIT_NPROC)) {
15119                 if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE) &&
15120 @@ -1306,6 +1323,18 @@ static struct task_struct *copy_process(
15121  
15122         total_forks++;
15123         spin_unlock(&current->sighand->siglock);
15124 +
15125 +       /* p is copy of current */
15126 +       vxi = p->vx_info;
15127 +       if (vxi) {
15128 +               claim_vx_info(vxi, p);
15129 +               atomic_inc(&vxi->cvirt.nr_threads);
15130 +               atomic_inc(&vxi->cvirt.total_forks);
15131 +               vx_nproc_inc(p);
15132 +       }
15133 +       nxi = p->nx_info;
15134 +       if (nxi)
15135 +               claim_nx_info(nxi, p);
15136         write_unlock_irq(&tasklist_lock);
15137         proc_fork_connector(p);
15138         cgroup_post_fork(p);
15139 diff -NurpP --minimal linux-2.6.38-rc8/kernel/kthread.c linux-2.6.38-rc8-vs2.3.0.37-rc6/kernel/kthread.c
15140 --- linux-2.6.38-rc8/kernel/kthread.c   2011-03-10 17:09:27.000000000 +0100
15141 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/kernel/kthread.c    2011-01-29 02:01:07.000000000 +0100
15142 @@ -16,6 +16,7 @@
15143  #include <linux/mutex.h>
15144  #include <linux/slab.h>
15145  #include <linux/freezer.h>
15146 +#include <linux/vs_pid.h>
15147  #include <trace/events/sched.h>
15148  
15149  static DEFINE_SPINLOCK(kthread_create_lock);
15150 diff -NurpP --minimal linux-2.6.38-rc8/kernel/nsproxy.c linux-2.6.38-rc8-vs2.3.0.37-rc6/kernel/nsproxy.c
15151 --- linux-2.6.38-rc8/kernel/nsproxy.c   2010-07-07 18:31:57.000000000 +0200
15152 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/kernel/nsproxy.c    2011-01-29 02:01:07.000000000 +0100
15153 @@ -20,6 +20,8 @@
15154  #include <linux/mnt_namespace.h>
15155  #include <linux/utsname.h>
15156  #include <linux/pid_namespace.h>
15157 +#include <linux/vserver/global.h>
15158 +#include <linux/vserver/debug.h>
15159  #include <net/net_namespace.h>
15160  #include <linux/ipc_namespace.h>
15161  
15162 @@ -43,8 +45,11 @@ static inline struct nsproxy *create_nsp
15163         struct nsproxy *nsproxy;
15164  
15165         nsproxy = kmem_cache_alloc(nsproxy_cachep, GFP_KERNEL);
15166 -       if (nsproxy)
15167 +       if (nsproxy) {
15168                 atomic_set(&nsproxy->count, 1);
15169 +               atomic_inc(&vs_global_nsproxy);
15170 +       }
15171 +       vxdprintk(VXD_CBIT(space, 2), "create_nsproxy = %p[1]", nsproxy);
15172         return nsproxy;
15173  }
15174  
15175 @@ -53,41 +58,52 @@ static inline struct nsproxy *create_nsp
15176   * Return the newly created nsproxy.  Do not attach this to the task,
15177   * leave it to the caller to do proper locking and attach it to task.
15178   */
15179 -static struct nsproxy *create_new_namespaces(unsigned long flags,
15180 -                       struct task_struct *tsk, struct fs_struct *new_fs)
15181 +static struct nsproxy *unshare_namespaces(unsigned long flags,
15182 +                       struct nsproxy *orig, struct fs_struct *new_fs)
15183  {
15184         struct nsproxy *new_nsp;
15185         int err;
15186  
15187 +       vxdprintk(VXD_CBIT(space, 4),
15188 +               "unshare_namespaces(0x%08lx,%p,%p)",
15189 +               flags, orig, new_fs);
15190 +
15191         new_nsp = create_nsproxy();
15192         if (!new_nsp)
15193                 return ERR_PTR(-ENOMEM);
15194  
15195 -       new_nsp->mnt_ns = copy_mnt_ns(flags, tsk->nsproxy->mnt_ns, new_fs);
15196 +       new_nsp->mnt_ns = copy_mnt_ns(flags, orig->mnt_ns, new_fs);
15197         if (IS_ERR(new_nsp->mnt_ns)) {
15198                 err = PTR_ERR(new_nsp->mnt_ns);
15199                 goto out_ns;
15200         }
15201  
15202 -       new_nsp->uts_ns = copy_utsname(flags, tsk->nsproxy->uts_ns);
15203 +       new_nsp->uts_ns = copy_utsname(flags, orig->uts_ns);
15204         if (IS_ERR(new_nsp->uts_ns)) {
15205                 err = PTR_ERR(new_nsp->uts_ns);
15206                 goto out_uts;
15207         }
15208  
15209 -       new_nsp->ipc_ns = copy_ipcs(flags, tsk->nsproxy->ipc_ns);
15210 +       new_nsp->ipc_ns = copy_ipcs(flags, orig->ipc_ns);
15211         if (IS_ERR(new_nsp->ipc_ns)) {
15212                 err = PTR_ERR(new_nsp->ipc_ns);
15213                 goto out_ipc;
15214         }
15215  
15216 -       new_nsp->pid_ns = copy_pid_ns(flags, task_active_pid_ns(tsk));
15217 +       new_nsp->pid_ns = copy_pid_ns(flags, orig->pid_ns);
15218         if (IS_ERR(new_nsp->pid_ns)) {
15219                 err = PTR_ERR(new_nsp->pid_ns);
15220                 goto out_pid;
15221         }
15222  
15223 -       new_nsp->net_ns = copy_net_ns(flags, tsk->nsproxy->net_ns);
15224 +       /* disabled now?
15225 +       new_nsp->user_ns = copy_user_ns(flags, orig->user_ns);
15226 +       if (IS_ERR(new_nsp->user_ns)) {
15227 +               err = PTR_ERR(new_nsp->user_ns);
15228 +               goto out_user;
15229 +       } */
15230 +
15231 +       new_nsp->net_ns = copy_net_ns(flags, orig->net_ns);
15232         if (IS_ERR(new_nsp->net_ns)) {
15233                 err = PTR_ERR(new_nsp->net_ns);
15234                 goto out_net;
15235 @@ -112,6 +128,38 @@ out_ns:
15236         return ERR_PTR(err);
15237  }
15238  
15239 +static struct nsproxy *create_new_namespaces(int flags, struct task_struct *tsk,
15240 +                       struct fs_struct *new_fs)
15241 +{
15242 +       return unshare_namespaces(flags, tsk->nsproxy, new_fs);
15243 +}
15244 +
15245 +/*
15246 + * copies the nsproxy, setting refcount to 1, and grabbing a
15247 + * reference to all contained namespaces.
15248 + */
15249 +struct nsproxy *copy_nsproxy(struct nsproxy *orig)
15250 +{
15251 +       struct nsproxy *ns = create_nsproxy();
15252 +
15253 +       if (ns) {
15254 +               memcpy(ns, orig, sizeof(struct nsproxy));
15255 +               atomic_set(&ns->count, 1);
15256 +
15257 +               if (ns->mnt_ns)
15258 +                       get_mnt_ns(ns->mnt_ns);
15259 +               if (ns->uts_ns)
15260 +                       get_uts_ns(ns->uts_ns);
15261 +               if (ns->ipc_ns)
15262 +                       get_ipc_ns(ns->ipc_ns);
15263 +               if (ns->pid_ns)
15264 +                       get_pid_ns(ns->pid_ns);
15265 +               if (ns->net_ns)
15266 +                       get_net(ns->net_ns);
15267 +       }
15268 +       return ns;
15269 +}
15270 +
15271  /*
15272   * called from clone.  This now handles copy for nsproxy and all
15273   * namespaces therein.
15274 @@ -119,9 +167,12 @@ out_ns:
15275  int copy_namespaces(unsigned long flags, struct task_struct *tsk)
15276  {
15277         struct nsproxy *old_ns = tsk->nsproxy;
15278 -       struct nsproxy *new_ns;
15279 +       struct nsproxy *new_ns = NULL;
15280         int err = 0;
15281  
15282 +       vxdprintk(VXD_CBIT(space, 7), "copy_namespaces(0x%08lx,%p[%p])",
15283 +               flags, tsk, old_ns);
15284 +
15285         if (!old_ns)
15286                 return 0;
15287  
15288 @@ -131,7 +182,7 @@ int copy_namespaces(unsigned long flags,
15289                                 CLONE_NEWPID | CLONE_NEWNET)))
15290                 return 0;
15291  
15292 -       if (!capable(CAP_SYS_ADMIN)) {
15293 +       if (!vx_can_unshare(CAP_SYS_ADMIN, flags)) {
15294                 err = -EPERM;
15295                 goto out;
15296         }
15297 @@ -158,6 +209,9 @@ int copy_namespaces(unsigned long flags,
15298  
15299  out:
15300         put_nsproxy(old_ns);
15301 +       vxdprintk(VXD_CBIT(space, 3),
15302 +               "copy_namespaces(0x%08lx,%p[%p]) = %d [%p]",
15303 +               flags, tsk, old_ns, err, new_ns);
15304         return err;
15305  }
15306  
15307 @@ -171,7 +225,9 @@ void free_nsproxy(struct nsproxy *ns)
15308                 put_ipc_ns(ns->ipc_ns);
15309         if (ns->pid_ns)
15310                 put_pid_ns(ns->pid_ns);
15311 -       put_net(ns->net_ns);
15312 +       if (ns->net_ns)
15313 +               put_net(ns->net_ns);
15314 +       atomic_dec(&vs_global_nsproxy);
15315         kmem_cache_free(nsproxy_cachep, ns);
15316  }
15317  
15318 @@ -184,11 +240,15 @@ int unshare_nsproxy_namespaces(unsigned 
15319  {
15320         int err = 0;
15321  
15322 +       vxdprintk(VXD_CBIT(space, 4),
15323 +               "unshare_nsproxy_namespaces(0x%08lx,[%p])",
15324 +               unshare_flags, current->nsproxy);
15325 +
15326         if (!(unshare_flags & (CLONE_NEWNS | CLONE_NEWUTS | CLONE_NEWIPC |
15327                                CLONE_NEWNET)))
15328                 return 0;
15329  
15330 -       if (!capable(CAP_SYS_ADMIN))
15331 +       if (!vx_can_unshare(CAP_SYS_ADMIN, unshare_flags))
15332                 return -EPERM;
15333  
15334         *new_nsp = create_new_namespaces(unshare_flags, current,
15335 diff -NurpP --minimal linux-2.6.38-rc8/kernel/pid.c linux-2.6.38-rc8-vs2.3.0.37-rc6/kernel/pid.c
15336 --- linux-2.6.38-rc8/kernel/pid.c       2011-01-05 21:50:38.000000000 +0100
15337 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/kernel/pid.c        2011-01-29 02:01:07.000000000 +0100
15338 @@ -36,6 +36,7 @@
15339  #include <linux/pid_namespace.h>
15340  #include <linux/init_task.h>
15341  #include <linux/syscalls.h>
15342 +#include <linux/vs_pid.h>
15343  
15344  #define pid_hashfn(nr, ns)     \
15345         hash_long((unsigned long)nr + (unsigned long)ns, pidhash_shift)
15346 @@ -339,7 +340,7 @@ EXPORT_SYMBOL_GPL(find_pid_ns);
15347  
15348  struct pid *find_vpid(int nr)
15349  {
15350 -       return find_pid_ns(nr, current->nsproxy->pid_ns);
15351 +       return find_pid_ns(vx_rmap_pid(nr), current->nsproxy->pid_ns);
15352  }
15353  EXPORT_SYMBOL_GPL(find_vpid);
15354  
15355 @@ -399,6 +400,9 @@ void transfer_pid(struct task_struct *ol
15356  struct task_struct *pid_task(struct pid *pid, enum pid_type type)
15357  {
15358         struct task_struct *result = NULL;
15359 +
15360 +       if (type == PIDTYPE_REALPID)
15361 +               type = PIDTYPE_PID;
15362         if (pid) {
15363                 struct hlist_node *first;
15364                 first = rcu_dereference_check(hlist_first_rcu(&pid->tasks[type]),
15365 @@ -417,7 +421,7 @@ EXPORT_SYMBOL(pid_task);
15366  struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
15367  {
15368         rcu_lockdep_assert(rcu_read_lock_held());
15369 -       return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
15370 +       return pid_task(find_pid_ns(vx_rmap_pid(nr), ns), PIDTYPE_PID);
15371  }
15372  
15373  struct task_struct *find_task_by_vpid(pid_t vnr)
15374 @@ -459,7 +463,7 @@ struct pid *find_get_pid(pid_t nr)
15375  }
15376  EXPORT_SYMBOL_GPL(find_get_pid);
15377  
15378 -pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns)
15379 +pid_t pid_unmapped_nr_ns(struct pid *pid, struct pid_namespace *ns)
15380  {
15381         struct upid *upid;
15382         pid_t nr = 0;
15383 @@ -472,6 +476,11 @@ pid_t pid_nr_ns(struct pid *pid, struct 
15384         return nr;
15385  }
15386  
15387 +pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns)
15388 +{
15389 +       return vx_map_pid(pid_unmapped_nr_ns(pid, ns));
15390 +}
15391 +
15392  pid_t pid_vnr(struct pid *pid)
15393  {
15394         return pid_nr_ns(pid, current->nsproxy->pid_ns);
15395 diff -NurpP --minimal linux-2.6.38-rc8/kernel/pid_namespace.c linux-2.6.38-rc8-vs2.3.0.37-rc6/kernel/pid_namespace.c
15396 --- linux-2.6.38-rc8/kernel/pid_namespace.c     2010-07-07 18:31:57.000000000 +0200
15397 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/kernel/pid_namespace.c      2011-01-29 02:01:07.000000000 +0100
15398 @@ -14,6 +14,7 @@
15399  #include <linux/err.h>
15400  #include <linux/acct.h>
15401  #include <linux/slab.h>
15402 +#include <linux/vserver/global.h>
15403  
15404  #define BITS_PER_PAGE          (PAGE_SIZE*8)
15405  
15406 @@ -87,6 +88,7 @@ static struct pid_namespace *create_pid_
15407                 goto out_free_map;
15408  
15409         kref_init(&ns->kref);
15410 +       atomic_inc(&vs_global_pid_ns);
15411         ns->level = level;
15412         ns->parent = get_pid_ns(parent_pid_ns);
15413  
15414 @@ -112,6 +114,7 @@ static void destroy_pid_namespace(struct
15415  
15416         for (i = 0; i < PIDMAP_ENTRIES; i++)
15417                 kfree(ns->pidmap[i].page);
15418 +       atomic_dec(&vs_global_pid_ns);
15419         kmem_cache_free(pid_ns_cachep, ns);
15420  }
15421  
15422 diff -NurpP --minimal linux-2.6.38-rc8/kernel/posix-timers.c linux-2.6.38-rc8-vs2.3.0.37-rc6/kernel/posix-timers.c
15423 --- linux-2.6.38-rc8/kernel/posix-timers.c      2011-03-10 17:09:27.000000000 +0100
15424 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/kernel/posix-timers.c       2011-01-29 02:01:07.000000000 +0100
15425 @@ -46,6 +46,7 @@
15426  #include <linux/wait.h>
15427  #include <linux/workqueue.h>
15428  #include <linux/module.h>
15429 +#include <linux/vs_context.h>
15430  
15431  /*
15432   * Management arrays for POSIX timers.  Timers are kept in slab memory
15433 @@ -369,6 +370,7 @@ int posix_timer_event(struct k_itimer *t
15434  {
15435         struct task_struct *task;
15436         int shared, ret = -1;
15437 +
15438         /*
15439          * FIXME: if ->sigq is queued we can race with
15440          * dequeue_signal()->do_schedule_next_timer().
15441 @@ -385,10 +387,18 @@ int posix_timer_event(struct k_itimer *t
15442         rcu_read_lock();
15443         task = pid_task(timr->it_pid, PIDTYPE_PID);
15444         if (task) {
15445 +               struct vx_info_save vxis;
15446 +               struct vx_info *vxi;
15447 +
15448 +               vxi = get_vx_info(task->vx_info);
15449 +               enter_vx_info(vxi, &vxis);
15450                 shared = !(timr->it_sigev_notify & SIGEV_THREAD_ID);
15451                 ret = send_sigqueue(timr->sigq, task, shared);
15452 +               leave_vx_info(&vxis);
15453 +               put_vx_info(vxi);
15454         }
15455         rcu_read_unlock();
15456 +
15457         /* If we failed to send the signal the timer stops. */
15458         return ret > 0;
15459  }
15460 diff -NurpP --minimal linux-2.6.38-rc8/kernel/printk.c linux-2.6.38-rc8-vs2.3.0.37-rc6/kernel/printk.c
15461 --- linux-2.6.38-rc8/kernel/printk.c    2011-03-10 17:09:28.000000000 +0100
15462 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/kernel/printk.c     2011-02-17 02:34:59.000000000 +0100
15463 @@ -40,6 +40,7 @@
15464  #include <linux/cpu.h>
15465  #include <linux/notifier.h>
15466  #include <linux/rculist.h>
15467 +#include <linux/vs_cvirt.h>
15468  
15469  #include <asm/uaccess.h>
15470  
15471 @@ -280,7 +281,7 @@ static int check_syslog_permissions(int 
15472                 return 0;
15473  
15474         if (syslog_action_restricted(type)) {
15475 -               if (capable(CAP_SYSLOG))
15476 +               if (vx_capable(CAP_SYSLOG, VXC_SYSLOG))
15477                         return 0;
15478                 /* For historical reasons, accept CAP_SYS_ADMIN too, with a warning */
15479                 if (capable(CAP_SYS_ADMIN)) {
15480 @@ -308,12 +309,9 @@ int do_syslog(int type, char __user *buf
15481         if (error)
15482                 return error;
15483  
15484 -       switch (type) {
15485 -       case SYSLOG_ACTION_CLOSE:       /* Close log */
15486 -               break;
15487 -       case SYSLOG_ACTION_OPEN:        /* Open log */
15488 -               break;
15489 -       case SYSLOG_ACTION_READ:        /* Read from log */
15490 +       if ((type == SYSLOG_ACTION_READ) ||
15491 +           (type == SYSLOG_ACTION_READ_ALL) ||
15492 +           (type == SYSLOG_ACTION_READ_CLEAR)) {
15493                 error = -EINVAL;
15494                 if (!buf || len < 0)
15495                         goto out;
15496 @@ -324,6 +322,16 @@ int do_syslog(int type, char __user *buf
15497                         error = -EFAULT;
15498                         goto out;
15499                 }
15500 +       }
15501 +       if (!vx_check(0, VS_ADMIN|VS_WATCH))
15502 +               return vx_do_syslog(type, buf, len);
15503 +
15504 +       switch (type) {
15505 +       case SYSLOG_ACTION_CLOSE:       /* Close log */
15506 +               break;
15507 +       case SYSLOG_ACTION_OPEN:        /* Open log */
15508 +               break;
15509 +       case SYSLOG_ACTION_READ:        /* Read from log */
15510                 error = wait_event_interruptible(log_wait,
15511                                                         (log_start - log_end));
15512                 if (error)
15513 @@ -350,16 +358,6 @@ int do_syslog(int type, char __user *buf
15514                 /* FALL THRU */
15515         /* Read last kernel messages */
15516         case SYSLOG_ACTION_READ_ALL:
15517 -               error = -EINVAL;
15518 -               if (!buf || len < 0)
15519 -                       goto out;
15520 -               error = 0;
15521 -               if (!len)
15522 -                       goto out;
15523 -               if (!access_ok(VERIFY_WRITE, buf, len)) {
15524 -                       error = -EFAULT;
15525 -                       goto out;
15526 -               }
15527                 count = len;
15528                 if (count > log_buf_len)
15529                         count = log_buf_len;
15530 diff -NurpP --minimal linux-2.6.38-rc8/kernel/ptrace.c linux-2.6.38-rc8-vs2.3.0.37-rc6/kernel/ptrace.c
15531 --- linux-2.6.38-rc8/kernel/ptrace.c    2011-03-10 17:09:28.000000000 +0100
15532 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/kernel/ptrace.c     2011-03-10 17:21:19.000000000 +0100
15533 @@ -22,6 +22,7 @@
15534  #include <linux/syscalls.h>
15535  #include <linux/uaccess.h>
15536  #include <linux/regset.h>
15537 +#include <linux/vs_context.h>
15538  
15539  
15540  /*
15541 @@ -150,6 +151,11 @@ int __ptrace_may_access(struct task_stru
15542                 dumpable = get_dumpable(task->mm);
15543         if (!dumpable && !capable(CAP_SYS_PTRACE))
15544                 return -EPERM;
15545 +       if (!vx_check(task->xid, VS_ADMIN_P|VS_WATCH_P|VS_IDENT))
15546 +               return -EPERM;
15547 +       if (!vx_check(task->xid, VS_IDENT) &&
15548 +               !task_vx_flags(task, VXF_STATE_ADMIN, 0))
15549 +               return -EACCES;
15550  
15551         return security_ptrace_access_check(task, mode);
15552  }
15553 @@ -713,6 +719,10 @@ SYSCALL_DEFINE4(ptrace, long, request, l
15554                 goto out;
15555         }
15556  
15557 +       ret = -EPERM;
15558 +       if (!vx_check(vx_task_xid(child), VS_WATCH_P | VS_IDENT))
15559 +               goto out_put_task_struct;
15560 +
15561         if (request == PTRACE_ATTACH) {
15562                 ret = ptrace_attach(child);
15563                 /*
15564 diff -NurpP --minimal linux-2.6.38-rc8/kernel/sched.c linux-2.6.38-rc8-vs2.3.0.37-rc6/kernel/sched.c
15565 --- linux-2.6.38-rc8/kernel/sched.c     2011-03-10 17:09:28.000000000 +0100
15566 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/kernel/sched.c      2011-01-29 02:01:07.000000000 +0100
15567 @@ -72,6 +72,8 @@
15568  #include <linux/ctype.h>
15569  #include <linux/ftrace.h>
15570  #include <linux/slab.h>
15571 +#include <linux/vs_sched.h>
15572 +#include <linux/vs_cvirt.h>
15573  
15574  #include <asm/tlb.h>
15575  #include <asm/irq_regs.h>
15576 @@ -3228,9 +3230,17 @@ static void calc_global_nohz(unsigned lo
15577   */
15578  void get_avenrun(unsigned long *loads, unsigned long offset, int shift)
15579  {
15580 -       loads[0] = (avenrun[0] + offset) << shift;
15581 -       loads[1] = (avenrun[1] + offset) << shift;
15582 -       loads[2] = (avenrun[2] + offset) << shift;
15583 +       if (vx_flags(VXF_VIRT_LOAD, 0)) {
15584 +               struct vx_info *vxi = current_vx_info();
15585 +
15586 +               loads[0] = (vxi->cvirt.load[0] + offset) << shift;
15587 +               loads[1] = (vxi->cvirt.load[1] + offset) << shift;
15588 +               loads[2] = (vxi->cvirt.load[2] + offset) << shift;
15589 +       } else {
15590 +               loads[0] = (avenrun[0] + offset) << shift;
15591 +               loads[1] = (avenrun[1] + offset) << shift;
15592 +               loads[2] = (avenrun[2] + offset) << shift;
15593 +       }
15594  }
15595  
15596  /*
15597 @@ -3518,16 +3528,19 @@ void account_user_time(struct task_struc
15598                        cputime_t cputime_scaled)
15599  {
15600         struct cpu_usage_stat *cpustat = &kstat_this_cpu.cpustat;
15601 +       struct vx_info *vxi = p->vx_info;  /* p is _always_ current */
15602         cputime64_t tmp;
15603 +       int nice = (TASK_NICE(p) > 0);
15604  
15605         /* Add user time to process. */
15606         p->utime = cputime_add(p->utime, cputime);
15607         p->utimescaled = cputime_add(p->utimescaled, cputime_scaled);
15608 +       vx_account_user(vxi, cputime, nice);
15609         account_group_user_time(p, cputime);
15610  
15611         /* Add user time to cpustat. */
15612         tmp = cputime_to_cputime64(cputime);
15613 -       if (TASK_NICE(p) > 0)
15614 +       if (nice)
15615                 cpustat->nice = cputime64_add(cpustat->nice, tmp);
15616         else
15617                 cpustat->user = cputime64_add(cpustat->user, tmp);
15618 @@ -3578,6 +3591,7 @@ void account_system_time(struct task_str
15619                          cputime_t cputime, cputime_t cputime_scaled)
15620  {
15621         struct cpu_usage_stat *cpustat = &kstat_this_cpu.cpustat;
15622 +       struct vx_info *vxi = p->vx_info;  /* p is _always_ current */
15623         cputime64_t tmp;
15624  
15625         if ((p->flags & PF_VCPU) && (irq_count() - hardirq_offset == 0)) {
15626 @@ -3588,6 +3602,7 @@ void account_system_time(struct task_str
15627         /* Add system time to process. */
15628         p->stime = cputime_add(p->stime, cputime);
15629         p->stimescaled = cputime_add(p->stimescaled, cputime_scaled);
15630 +       vx_account_system(vxi, cputime, 0 /* do we have idle time? */);
15631         account_group_system_time(p, cputime);
15632  
15633         /* Add system time to cpustat. */
15634 @@ -4671,7 +4686,7 @@ SYSCALL_DEFINE1(nice, int, increment)
15635                 nice = 19;
15636  
15637         if (increment < 0 && !can_nice(current, nice))
15638 -               return -EPERM;
15639 +               return vx_flags(VXF_IGNEG_NICE, 0) ? 0 : -EPERM;
15640  
15641         retval = security_task_setnice(current, nice);
15642         if (retval)
15643 diff -NurpP --minimal linux-2.6.38-rc8/kernel/sched_fair.c linux-2.6.38-rc8-vs2.3.0.37-rc6/kernel/sched_fair.c
15644 --- linux-2.6.38-rc8/kernel/sched_fair.c        2011-03-10 17:09:28.000000000 +0100
15645 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/kernel/sched_fair.c 2011-02-02 22:20:27.000000000 +0100
15646 @@ -992,6 +992,8 @@ enqueue_entity(struct cfs_rq *cfs_rq, st
15647                 __enqueue_entity(cfs_rq, se);
15648         se->on_rq = 1;
15649  
15650 +       if (entity_is_task(se))
15651 +               vx_activate_task(task_of(se));
15652         if (cfs_rq->nr_running == 1)
15653                 list_add_leaf_cfs_rq(cfs_rq);
15654  }
15655 @@ -1038,6 +1040,8 @@ dequeue_entity(struct cfs_rq *cfs_rq, st
15656         if (se != cfs_rq->curr)
15657                 __dequeue_entity(cfs_rq, se);
15658         se->on_rq = 0;
15659 +       if (entity_is_task(se))
15660 +               vx_deactivate_task(task_of(se));
15661         update_cfs_load(cfs_rq, 0);
15662         account_entity_dequeue(cfs_rq, se);
15663         update_min_vruntime(cfs_rq);
15664 diff -NurpP --minimal linux-2.6.38-rc8/kernel/signal.c linux-2.6.38-rc8-vs2.3.0.37-rc6/kernel/signal.c
15665 --- linux-2.6.38-rc8/kernel/signal.c    2011-01-05 21:50:38.000000000 +0100
15666 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/kernel/signal.c     2011-01-29 02:01:07.000000000 +0100
15667 @@ -28,6 +28,8 @@
15668  #include <linux/freezer.h>
15669  #include <linux/pid_namespace.h>
15670  #include <linux/nsproxy.h>
15671 +#include <linux/vs_context.h>
15672 +#include <linux/vs_pid.h>
15673  #define CREATE_TRACE_POINTS
15674  #include <trace/events/signal.h>
15675  
15676 @@ -646,9 +648,18 @@ static int check_kill_permission(int sig
15677         struct pid *sid;
15678         int error;
15679  
15680 +       vxdprintk(VXD_CBIT(misc, 7),
15681 +               "check_kill_permission(%d,%p,%p[#%u,%u])",
15682 +               sig, info, t, vx_task_xid(t), t->pid);
15683 +
15684         if (!valid_signal(sig))
15685                 return -EINVAL;
15686  
15687 +/*     FIXME: needed? if so, why?
15688 +       if ((info != SEND_SIG_NOINFO) &&
15689 +               (is_si_special(info) || !si_fromuser(info)))
15690 +               goto skip;      */
15691 +
15692         if (!si_fromuser(info))
15693                 return 0;
15694  
15695 @@ -678,6 +689,20 @@ static int check_kill_permission(int sig
15696                 }
15697         }
15698  
15699 +       error = -EPERM;
15700 +       if (t->pid == 1 && current->xid)
15701 +               return error;
15702 +
15703 +       error = -ESRCH;
15704 +       /* FIXME: we shouldn't return ESRCH ever, to avoid
15705 +                 loops, maybe ENOENT or EACCES? */
15706 +       if (!vx_check(vx_task_xid(t), VS_WATCH_P | VS_IDENT)) {
15707 +               vxdprintk(current->xid || VXD_CBIT(misc, 7),
15708 +                       "signal %d[%p] xid mismatch %p[#%u,%u] xid=#%u",
15709 +                       sig, info, t, vx_task_xid(t), t->pid, current->xid);
15710 +               return error;
15711 +       }
15712 +/* skip: */
15713         return security_task_kill(t, info, sig, 0);
15714  }
15715  
15716 @@ -1171,7 +1196,7 @@ int kill_pid_info(int sig, struct siginf
15717         rcu_read_lock();
15718  retry:
15719         p = pid_task(pid, PIDTYPE_PID);
15720 -       if (p) {
15721 +       if (p && vx_check(vx_task_xid(p), VS_IDENT)) {
15722                 error = group_send_sig_info(sig, info, p);
15723                 if (unlikely(error == -ESRCH))
15724                         /*
15725 @@ -1211,7 +1236,7 @@ int kill_pid_info_as_uid(int sig, struct
15726  
15727         rcu_read_lock();
15728         p = pid_task(pid, PIDTYPE_PID);
15729 -       if (!p) {
15730 +       if (!p || !vx_check(vx_task_xid(p), VS_IDENT)) {
15731                 ret = -ESRCH;
15732                 goto out_unlock;
15733         }
15734 @@ -1266,8 +1291,10 @@ static int kill_something_info(int sig, 
15735                 struct task_struct * p;
15736  
15737                 for_each_process(p) {
15738 -                       if (task_pid_vnr(p) > 1 &&
15739 -                                       !same_thread_group(p, current)) {
15740 +                       if (vx_check(vx_task_xid(p), VS_ADMIN|VS_IDENT) &&
15741 +                               task_pid_vnr(p) > 1 &&
15742 +                               !same_thread_group(p, current) &&
15743 +                               !vx_current_initpid(p->pid)) {
15744                                 int err = group_send_sig_info(sig, info, p);
15745                                 ++count;
15746                                 if (err != -EPERM)
15747 @@ -1936,6 +1963,11 @@ relock:
15748                                 !sig_kernel_only(signr))
15749                         continue;
15750  
15751 +               /* virtual init is protected against user signals */
15752 +               if ((info->si_code == SI_USER) &&
15753 +                       vx_current_initpid(current->pid))
15754 +                       continue;
15755 +
15756                 if (sig_kernel_stop(signr)) {
15757                         /*
15758                          * The default action is to stop all threads in
15759 diff -NurpP --minimal linux-2.6.38-rc8/kernel/softirq.c linux-2.6.38-rc8-vs2.3.0.37-rc6/kernel/softirq.c
15760 --- linux-2.6.38-rc8/kernel/softirq.c   2011-03-10 17:09:28.000000000 +0100
15761 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/kernel/softirq.c    2011-01-29 02:01:07.000000000 +0100
15762 @@ -24,6 +24,7 @@
15763  #include <linux/ftrace.h>
15764  #include <linux/smp.h>
15765  #include <linux/tick.h>
15766 +#include <linux/vs_context.h>
15767  
15768  #define CREATE_TRACE_POINTS
15769  #include <trace/events/irq.h>
15770 diff -NurpP --minimal linux-2.6.38-rc8/kernel/sys.c linux-2.6.38-rc8-vs2.3.0.37-rc6/kernel/sys.c
15771 --- linux-2.6.38-rc8/kernel/sys.c       2011-03-10 17:09:28.000000000 +0100
15772 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/kernel/sys.c        2011-02-02 22:20:27.000000000 +0100
15773 @@ -42,6 +42,7 @@
15774  #include <linux/syscalls.h>
15775  #include <linux/kprobes.h>
15776  #include <linux/user_namespace.h>
15777 +#include <linux/vs_pid.h>
15778  
15779  #include <linux/kmsg_dump.h>
15780  
15781 @@ -133,7 +134,10 @@ static int set_one_prio(struct task_stru
15782                 goto out;
15783         }
15784         if (niceval < task_nice(p) && !can_nice(p, niceval)) {
15785 -               error = -EACCES;
15786 +               if (vx_flags(VXF_IGNEG_NICE, 0))
15787 +                       error = 0;
15788 +               else
15789 +                       error = -EACCES;
15790                 goto out;
15791         }
15792         no_nice = security_task_setnice(p, niceval);
15793 @@ -183,6 +187,8 @@ SYSCALL_DEFINE3(setpriority, int, which,
15794                         else
15795                                 pgrp = task_pgrp(current);
15796                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
15797 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
15798 +                                       continue;
15799                                 error = set_one_prio(p, niceval, error);
15800                         } while_each_pid_thread(pgrp, PIDTYPE_PGID, p);
15801                         break;
15802 @@ -246,6 +252,8 @@ SYSCALL_DEFINE2(getpriority, int, which,
15803                         else
15804                                 pgrp = task_pgrp(current);
15805                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
15806 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
15807 +                                       continue;
15808                                 niceval = 20 - task_nice(p);
15809                                 if (niceval > retval)
15810                                         retval = niceval;
15811 @@ -363,6 +371,8 @@ EXPORT_SYMBOL_GPL(kernel_power_off);
15812  
15813  static DEFINE_MUTEX(reboot_mutex);
15814  
15815 +long vs_reboot(unsigned int, void __user *);
15816 +
15817  /*
15818   * Reboot system call: for obvious reasons only root may call it,
15819   * and even root needs to set up some magic numbers in the registers
15820 @@ -395,6 +405,9 @@ SYSCALL_DEFINE4(reboot, int, magic1, int
15821         if ((cmd == LINUX_REBOOT_CMD_POWER_OFF) && !pm_power_off)
15822                 cmd = LINUX_REBOOT_CMD_HALT;
15823  
15824 +       if (!vx_check(0, VS_ADMIN|VS_WATCH))
15825 +               return vs_reboot(cmd, arg);
15826 +
15827         mutex_lock(&reboot_mutex);
15828         switch (cmd) {
15829         case LINUX_REBOOT_CMD_RESTART:
15830 @@ -1177,7 +1190,7 @@ SYSCALL_DEFINE2(sethostname, char __user
15831         int errno;
15832         char tmp[__NEW_UTS_LEN];
15833  
15834 -       if (!capable(CAP_SYS_ADMIN))
15835 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SET_UTSNAME))
15836                 return -EPERM;
15837         if (len < 0 || len > __NEW_UTS_LEN)
15838                 return -EINVAL;
15839 @@ -1226,7 +1239,7 @@ SYSCALL_DEFINE2(setdomainname, char __us
15840         int errno;
15841         char tmp[__NEW_UTS_LEN];
15842  
15843 -       if (!capable(CAP_SYS_ADMIN))
15844 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SET_UTSNAME))
15845                 return -EPERM;
15846         if (len < 0 || len > __NEW_UTS_LEN)
15847                 return -EINVAL;
15848 @@ -1342,7 +1355,7 @@ int do_prlimit(struct task_struct *tsk, 
15849         task_lock(tsk->group_leader);
15850         if (new_rlim) {
15851                 if (new_rlim->rlim_max > rlim->rlim_max &&
15852 -                               !capable(CAP_SYS_RESOURCE))
15853 +                       !vx_capable(CAP_SYS_RESOURCE, VXC_SET_RLIMIT))
15854                         retval = -EPERM;
15855                 if (!retval)
15856                         retval = security_task_setrlimit(tsk->group_leader,
15857 @@ -1392,7 +1405,7 @@ static int check_prlimit_permission(stru
15858              cred->gid != tcred->egid ||
15859              cred->gid != tcred->sgid ||
15860              cred->gid != tcred->gid) &&
15861 -            !capable(CAP_SYS_RESOURCE)) {
15862 +            !vx_capable(CAP_SYS_RESOURCE, VXC_SET_RLIMIT)) {
15863                 return -EPERM;
15864         }
15865  
15866 diff -NurpP --minimal linux-2.6.38-rc8/kernel/sysctl.c linux-2.6.38-rc8-vs2.3.0.37-rc6/kernel/sysctl.c
15867 --- linux-2.6.38-rc8/kernel/sysctl.c    2011-03-10 17:09:28.000000000 +0100
15868 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/kernel/sysctl.c     2011-02-02 22:20:27.000000000 +0100
15869 @@ -74,6 +74,7 @@
15870  #if defined(CONFIG_PROVE_LOCKING) || defined(CONFIG_LOCK_STAT)
15871  #include <linux/lockdep.h>
15872  #endif
15873 +extern char vshelper_path[];
15874  #ifdef CONFIG_CHR_DEV_SG
15875  #include <scsi/sg.h>
15876  #endif
15877 @@ -568,6 +569,13 @@ static struct ctl_table kern_table[] = {
15878                 .proc_handler   = proc_dostring,
15879         },
15880  #endif
15881 +       {
15882 +               .procname       = "vshelper",
15883 +               .data           = &vshelper_path,
15884 +               .maxlen         = 256,
15885 +               .mode           = 0644,
15886 +               .proc_handler   = &proc_dostring,
15887 +       },
15888  #ifdef CONFIG_CHR_DEV_SG
15889         {
15890                 .procname       = "sg-big-buff",
15891 diff -NurpP --minimal linux-2.6.38-rc8/kernel/sysctl_binary.c linux-2.6.38-rc8-vs2.3.0.37-rc6/kernel/sysctl_binary.c
15892 --- linux-2.6.38-rc8/kernel/sysctl_binary.c     2011-03-10 17:09:29.000000000 +0100
15893 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/kernel/sysctl_binary.c      2011-01-29 02:01:07.000000000 +0100
15894 @@ -73,6 +73,7 @@ static const struct bin_table bin_kern_t
15895  
15896         { CTL_INT,      KERN_PANIC,                     "panic" },
15897         { CTL_INT,      KERN_REALROOTDEV,               "real-root-dev" },
15898 +       { CTL_STR,      KERN_VSHELPER,                  "vshelper" },
15899  
15900         { CTL_STR,      KERN_SPARC_REBOOT,              "reboot-cmd" },
15901         { CTL_INT,      KERN_CTLALTDEL,                 "ctrl-alt-del" },
15902 diff -NurpP --minimal linux-2.6.38-rc8/kernel/time/timekeeping.c linux-2.6.38-rc8-vs2.3.0.37-rc6/kernel/time/timekeeping.c
15903 --- linux-2.6.38-rc8/kernel/time/timekeeping.c  2011-03-10 17:09:29.000000000 +0100
15904 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/kernel/time/timekeeping.c   2011-01-29 02:01:07.000000000 +0100
15905 @@ -233,6 +233,7 @@ void getnstimeofday(struct timespec *ts)
15906         } while (read_seqretry(&xtime_lock, seq));
15907  
15908         timespec_add_ns(ts, nsecs);
15909 +       vx_adjust_timespec(ts);
15910  }
15911  
15912  EXPORT_SYMBOL(getnstimeofday);
15913 diff -NurpP --minimal linux-2.6.38-rc8/kernel/time.c linux-2.6.38-rc8-vs2.3.0.37-rc6/kernel/time.c
15914 --- linux-2.6.38-rc8/kernel/time.c      2011-03-10 17:09:29.000000000 +0100
15915 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/kernel/time.c       2011-01-29 02:01:07.000000000 +0100
15916 @@ -92,7 +92,7 @@ SYSCALL_DEFINE1(stime, time_t __user *, 
15917         if (err)
15918                 return err;
15919  
15920 -       do_settimeofday(&tv);
15921 +       vx_settimeofday(&tv);
15922         return 0;
15923  }
15924  
15925 @@ -177,7 +177,7 @@ int do_sys_settimeofday(struct timespec 
15926                 /* SMP safe, again the code in arch/foo/time.c should
15927                  * globally block out interrupts when it runs.
15928                  */
15929 -               return do_settimeofday(tv);
15930 +               return vx_settimeofday(tv);
15931         }
15932         return 0;
15933  }
15934 diff -NurpP --minimal linux-2.6.38-rc8/kernel/timer.c linux-2.6.38-rc8-vs2.3.0.37-rc6/kernel/timer.c
15935 --- linux-2.6.38-rc8/kernel/timer.c     2011-03-10 17:09:29.000000000 +0100
15936 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/kernel/timer.c      2011-02-17 02:17:51.000000000 +0100
15937 @@ -40,6 +40,10 @@
15938  #include <linux/irq_work.h>
15939  #include <linux/sched.h>
15940  #include <linux/slab.h>
15941 +#include <linux/vs_base.h>
15942 +#include <linux/vs_cvirt.h>
15943 +#include <linux/vs_pid.h>
15944 +#include <linux/vserver/sched.h>
15945  
15946  #include <asm/uaccess.h>
15947  #include <asm/unistd.h>
15948 @@ -1321,12 +1325,6 @@ SYSCALL_DEFINE1(alarm, unsigned int, sec
15949  
15950  #endif
15951  
15952 -#ifndef __alpha__
15953 -
15954 -/*
15955 - * The Alpha uses getxpid, getxuid, and getxgid instead.  Maybe this
15956 - * should be moved into arch/i386 instead?
15957 - */
15958  
15959  /**
15960   * sys_getpid - return the thread group id of the current process
15961 @@ -1355,10 +1353,23 @@ SYSCALL_DEFINE0(getppid)
15962         rcu_read_lock();
15963         pid = task_tgid_vnr(current->real_parent);
15964         rcu_read_unlock();
15965 +       return vx_map_pid(pid);
15966 +}
15967  
15968 -       return pid;
15969 +#ifdef __alpha__
15970 +
15971 +/*
15972 + * The Alpha uses getxpid, getxuid, and getxgid instead.
15973 + */
15974 +
15975 +asmlinkage long do_getxpid(long *ppid)
15976 +{
15977 +       *ppid = sys_getppid();
15978 +       return sys_getpid();
15979  }
15980  
15981 +#else /* _alpha_ */
15982 +
15983  SYSCALL_DEFINE0(getuid)
15984  {
15985         /* Only we change this so SMP safe */
15986 diff -NurpP --minimal linux-2.6.38-rc8/kernel/user_namespace.c linux-2.6.38-rc8-vs2.3.0.37-rc6/kernel/user_namespace.c
15987 --- linux-2.6.38-rc8/kernel/user_namespace.c    2011-03-10 17:09:29.000000000 +0100
15988 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/kernel/user_namespace.c     2011-01-29 02:01:07.000000000 +0100
15989 @@ -11,6 +11,7 @@
15990  #include <linux/user_namespace.h>
15991  #include <linux/highuid.h>
15992  #include <linux/cred.h>
15993 +#include <linux/vserver/global.h>
15994  
15995  static struct kmem_cache *user_ns_cachep __read_mostly;
15996  
15997 @@ -33,6 +34,7 @@ int create_user_ns(struct cred *new)
15998                 return -ENOMEM;
15999  
16000         kref_init(&ns->kref);
16001 +       atomic_inc(&vs_global_user_ns);
16002  
16003         for (n = 0; n < UIDHASH_SZ; ++n)
16004                 INIT_HLIST_HEAD(ns->uidhash_table + n);
16005 @@ -81,6 +83,8 @@ void free_user_ns(struct kref *kref)
16006         struct user_namespace *ns =
16007                 container_of(kref, struct user_namespace, kref);
16008  
16009 +       /* FIXME: maybe move into destroyer? */
16010 +       atomic_dec(&vs_global_user_ns);
16011         INIT_WORK(&ns->destroyer, free_user_ns_work);
16012         schedule_work(&ns->destroyer);
16013  }
16014 diff -NurpP --minimal linux-2.6.38-rc8/kernel/utsname.c linux-2.6.38-rc8-vs2.3.0.37-rc6/kernel/utsname.c
16015 --- linux-2.6.38-rc8/kernel/utsname.c   2009-09-10 15:26:28.000000000 +0200
16016 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/kernel/utsname.c    2011-01-29 02:01:07.000000000 +0100
16017 @@ -14,14 +14,17 @@
16018  #include <linux/utsname.h>
16019  #include <linux/err.h>
16020  #include <linux/slab.h>
16021 +#include <linux/vserver/global.h>
16022  
16023  static struct uts_namespace *create_uts_ns(void)
16024  {
16025         struct uts_namespace *uts_ns;
16026  
16027         uts_ns = kmalloc(sizeof(struct uts_namespace), GFP_KERNEL);
16028 -       if (uts_ns)
16029 +       if (uts_ns) {
16030                 kref_init(&uts_ns->kref);
16031 +               atomic_inc(&vs_global_uts_ns);
16032 +       }
16033         return uts_ns;
16034  }
16035  
16036 @@ -71,5 +74,6 @@ void free_uts_ns(struct kref *kref)
16037         struct uts_namespace *ns;
16038  
16039         ns = container_of(kref, struct uts_namespace, kref);
16040 +       atomic_dec(&vs_global_uts_ns);
16041         kfree(ns);
16042  }
16043 diff -NurpP --minimal linux-2.6.38-rc8/kernel/vserver/Kconfig linux-2.6.38-rc8-vs2.3.0.37-rc6/kernel/vserver/Kconfig
16044 --- linux-2.6.38-rc8/kernel/vserver/Kconfig     1970-01-01 01:00:00.000000000 +0100
16045 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/kernel/vserver/Kconfig      2011-01-29 02:01:07.000000000 +0100
16046 @@ -0,0 +1,265 @@
16047 +#
16048 +# Linux VServer configuration
16049 +#
16050 +
16051 +menu "Linux VServer"
16052 +
16053 +config VSERVER_AUTO_LBACK
16054 +       bool    "Automatically Assign Loopback IP"
16055 +       default y
16056 +       help
16057 +         Automatically assign a guest specific loopback
16058 +         IP and add it to the kernel network stack on
16059 +         startup.
16060 +
16061 +config VSERVER_AUTO_SINGLE
16062 +       bool    "Automatic Single IP Special Casing"
16063 +       depends on EXPERIMENTAL
16064 +       default y
16065 +       help
16066 +         This allows network contexts with a single IP to
16067 +         automatically remap 0.0.0.0 bindings to that IP,
16068 +         avoiding further network checks and improving
16069 +         performance.
16070 +
16071 +         (note: such guests do not allow to change the ip
16072 +          on the fly and do not show loopback addresses)
16073 +
16074 +config VSERVER_COWBL
16075 +       bool    "Enable COW Immutable Link Breaking"
16076 +       default y
16077 +       help
16078 +         This enables the COW (Copy-On-Write) link break code.
16079 +         It allows you to treat unified files like normal files
16080 +         when writing to them (which will implicitely break the
16081 +         link and create a copy of the unified file)
16082 +
16083 +config VSERVER_VTIME
16084 +       bool    "Enable Virtualized Guest Time"
16085 +       depends on EXPERIMENTAL
16086 +       default n
16087 +       help
16088 +         This enables per guest time offsets to allow for
16089 +         adjusting the system clock individually per guest.
16090 +         this adds some overhead to the time functions and
16091 +         therefore should not be enabled without good reason.
16092 +
16093 +config VSERVER_DEVICE
16094 +       bool    "Enable Guest Device Mapping"
16095 +       depends on EXPERIMENTAL
16096 +       default n
16097 +       help
16098 +         This enables generic device remapping.
16099 +
16100 +config VSERVER_PROC_SECURE
16101 +       bool    "Enable Proc Security"
16102 +       depends on PROC_FS
16103 +       default y
16104 +       help
16105 +         This configures ProcFS security to initially hide
16106 +         non-process entries for all contexts except the main and
16107 +         spectator context (i.e. for all guests), which is a secure
16108 +         default.
16109 +
16110 +         (note: on 1.2x the entries were visible by default)
16111 +
16112 +config VSERVER_HARDCPU
16113 +       bool    "Enable Hard CPU Limits"
16114 +       default y
16115 +       help
16116 +         Activate the Hard CPU Limits
16117 +
16118 +         This will compile in code that allows the Token Bucket
16119 +         Scheduler to put processes on hold when a context's
16120 +         tokens are depleted (provided that its per-context
16121 +         sched_hard flag is set).
16122 +
16123 +         Processes belonging to that context will not be able
16124 +         to consume CPU resources again until a per-context
16125 +         configured minimum of tokens has been reached.
16126 +
16127 +config VSERVER_IDLETIME
16128 +       bool    "Avoid idle CPUs by skipping Time"
16129 +       depends on VSERVER_HARDCPU
16130 +       default y
16131 +       help
16132 +         This option allows the scheduler to artificially
16133 +         advance time (per cpu) when otherwise the idle
16134 +         task would be scheduled, thus keeping the cpu
16135 +         busy and sharing the available resources among
16136 +         certain contexts.
16137 +
16138 +config VSERVER_IDLELIMIT
16139 +       bool    "Limit the IDLE task"
16140 +       depends on VSERVER_HARDCPU
16141 +       default n
16142 +       help
16143 +         Limit the idle slices, so the the next context
16144 +         will be scheduled as soon as possible.
16145 +
16146 +         This might improve interactivity and latency, but
16147 +         will also marginally increase scheduling overhead.
16148 +
16149 +choice
16150 +       prompt  "Persistent Inode Tagging"
16151 +       default TAGGING_ID24
16152 +       help
16153 +         This adds persistent context information to filesystems
16154 +         mounted with the tagxid option. Tagging is a requirement
16155 +         for per-context disk limits and per-context quota.
16156 +
16157 +
16158 +config TAGGING_NONE
16159 +       bool    "Disabled"
16160 +       help
16161 +         do not store per-context information in inodes.
16162 +
16163 +config TAGGING_UID16
16164 +       bool    "UID16/GID32"
16165 +       help
16166 +         reduces UID to 16 bit, but leaves GID at 32 bit.
16167 +
16168 +config TAGGING_GID16
16169 +       bool    "UID32/GID16"
16170 +       help
16171 +         reduces GID to 16 bit, but leaves UID at 32 bit.
16172 +
16173 +config TAGGING_ID24
16174 +       bool    "UID24/GID24"
16175 +       help
16176 +         uses the upper 8bit from UID and GID for XID tagging
16177 +         which leaves 24bit for UID/GID each, which should be
16178 +         more than sufficient for normal use.
16179 +
16180 +config TAGGING_INTERN
16181 +       bool    "UID32/GID32"
16182 +       help
16183 +         this uses otherwise reserved inode fields in the on
16184 +         disk representation, which limits the use to a few
16185 +         filesystems (currently ext2 and ext3)
16186 +
16187 +endchoice
16188 +
16189 +config TAG_NFSD
16190 +       bool    "Tag NFSD User Auth and Files"
16191 +       default n
16192 +       help
16193 +         Enable this if you do want the in-kernel NFS
16194 +         Server to use the tagging specified above.
16195 +         (will require patched clients too)
16196 +
16197 +config VSERVER_PRIVACY
16198 +       bool    "Honor Privacy Aspects of Guests"
16199 +       default n
16200 +       help
16201 +         When enabled, most context checks will disallow
16202 +         access to structures assigned to a specific context,
16203 +         like ptys or loop devices.
16204 +
16205 +config VSERVER_CONTEXTS
16206 +       int     "Maximum number of Contexts (1-65533)"  if EMBEDDED
16207 +       range 1 65533
16208 +       default "768"   if 64BIT
16209 +       default "256"
16210 +       help
16211 +         This setting will optimize certain data structures
16212 +         and memory allocations according to the expected
16213 +         maximum.
16214 +
16215 +         note: this is not a strict upper limit.
16216 +
16217 +config VSERVER_WARN
16218 +       bool    "VServer Warnings"
16219 +       default y
16220 +       help
16221 +         This enables various runtime warnings, which will
16222 +         notify about potential manipulation attempts or
16223 +         resource shortage. It is generally considered to
16224 +         be a good idea to have that enabled.
16225 +
16226 +config VSERVER_WARN_DEVPTS
16227 +       bool    "VServer DevPTS Warnings"
16228 +       depends on VSERVER_WARN
16229 +       default y
16230 +       help
16231 +         This enables DevPTS related warnings, issued when a
16232 +         process inside a context tries to lookup or access
16233 +         a dynamic pts from the host or a different context.
16234 +
16235 +config VSERVER_DEBUG
16236 +       bool    "VServer Debugging Code"
16237 +       default n
16238 +       help
16239 +         Set this to yes if you want to be able to activate
16240 +         debugging output at runtime. It adds a very small
16241 +         overhead to all vserver related functions and
16242 +         increases the kernel size by about 20k.
16243 +
16244 +config VSERVER_HISTORY
16245 +       bool    "VServer History Tracing"
16246 +       depends on VSERVER_DEBUG
16247 +       default n
16248 +       help
16249 +         Set this to yes if you want to record the history of
16250 +         linux-vserver activities, so they can be replayed in
16251 +         the event of a kernel panic or oops.
16252 +
16253 +config VSERVER_HISTORY_SIZE
16254 +       int     "Per-CPU History Size (32-65536)"
16255 +       depends on VSERVER_HISTORY
16256 +       range 32 65536
16257 +       default 64
16258 +       help
16259 +         This allows you to specify the number of entries in
16260 +         the per-CPU history buffer.
16261 +
16262 +config VSERVER_LEGACY_MEM
16263 +       bool    "Legacy Memory Limits"
16264 +       default n
16265 +       help
16266 +         This provides fake memory limits to keep
16267 +         older tools happy in the face of memory
16268 +         cgroups
16269 +
16270 +choice
16271 +       prompt  "Quotes used in debug and warn messages"
16272 +       default QUOTES_ISO8859
16273 +
16274 +config QUOTES_ISO8859
16275 +       bool    "Extended ASCII (ISO 8859) angle quotes"
16276 +       help
16277 +         This uses the extended ASCII characters \xbb
16278 +         and \xab for quoting file and process names.
16279 +
16280 +config QUOTES_UTF8
16281 +       bool    "UTF-8 angle quotes"
16282 +       help
16283 +         This uses the the UTF-8 sequences for angle
16284 +         quotes to quote file and process names.
16285 +
16286 +config QUOTES_ASCII
16287 +       bool    "ASCII single quotes"
16288 +       help
16289 +         This uses the ASCII single quote character
16290 +         (\x27) to quote file and process names.
16291 +
16292 +endchoice
16293 +
16294 +endmenu
16295 +
16296 +
16297 +config VSERVER
16298 +       bool
16299 +       default y
16300 +       select NAMESPACES
16301 +       select UTS_NS
16302 +       select IPC_NS
16303 +       select USER_NS
16304 +       select SYSVIPC
16305 +
16306 +config VSERVER_SECURITY
16307 +       bool
16308 +       depends on SECURITY
16309 +       default y
16310 +       select SECURITY_CAPABILITIES
16311 +
16312 diff -NurpP --minimal linux-2.6.38-rc8/kernel/vserver/Makefile linux-2.6.38-rc8-vs2.3.0.37-rc6/kernel/vserver/Makefile
16313 --- linux-2.6.38-rc8/kernel/vserver/Makefile    1970-01-01 01:00:00.000000000 +0100
16314 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/kernel/vserver/Makefile     2011-01-29 02:01:07.000000000 +0100
16315 @@ -0,0 +1,18 @@
16316 +#
16317 +# Makefile for the Linux vserver routines.
16318 +#
16319 +
16320 +
16321 +obj-y          += vserver.o
16322 +
16323 +vserver-y      := switch.o context.o space.o sched.o network.o inode.o \
16324 +                  limit.o cvirt.o cacct.o signal.o helper.o init.o \
16325 +                  dlimit.o tag.o
16326 +
16327 +vserver-$(CONFIG_INET) += inet.o
16328 +vserver-$(CONFIG_PROC_FS) += proc.o
16329 +vserver-$(CONFIG_VSERVER_DEBUG) += sysctl.o debug.o
16330 +vserver-$(CONFIG_VSERVER_HISTORY) += history.o
16331 +vserver-$(CONFIG_VSERVER_MONITOR) += monitor.o
16332 +vserver-$(CONFIG_VSERVER_DEVICE) += device.o
16333 +
16334 diff -NurpP --minimal linux-2.6.38-rc8/kernel/vserver/cacct.c linux-2.6.38-rc8-vs2.3.0.37-rc6/kernel/vserver/cacct.c
16335 --- linux-2.6.38-rc8/kernel/vserver/cacct.c     1970-01-01 01:00:00.000000000 +0100
16336 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/kernel/vserver/cacct.c      2011-01-29 02:01:07.000000000 +0100
16337 @@ -0,0 +1,42 @@
16338 +/*
16339 + *  linux/kernel/vserver/cacct.c
16340 + *
16341 + *  Virtual Server: Context Accounting
16342 + *
16343 + *  Copyright (C) 2006-2007 Herbert Pötzl
16344 + *
16345 + *  V0.01  added accounting stats
16346 + *
16347 + */
16348 +
16349 +#include <linux/types.h>
16350 +#include <linux/vs_context.h>
16351 +#include <linux/vserver/cacct_cmd.h>
16352 +#include <linux/vserver/cacct_int.h>
16353 +
16354 +#include <asm/errno.h>
16355 +#include <asm/uaccess.h>
16356 +
16357 +
16358 +int vc_sock_stat(struct vx_info *vxi, void __user *data)
16359 +{
16360 +       struct vcmd_sock_stat_v0 vc_data;
16361 +       int j, field;
16362 +
16363 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16364 +               return -EFAULT;
16365 +
16366 +       field = vc_data.field;
16367 +       if ((field < 0) || (field >= VXA_SOCK_SIZE))
16368 +               return -EINVAL;
16369 +
16370 +       for (j = 0; j < 3; j++) {
16371 +               vc_data.count[j] = vx_sock_count(&vxi->cacct, field, j);
16372 +               vc_data.total[j] = vx_sock_total(&vxi->cacct, field, j);
16373 +       }
16374 +
16375 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16376 +               return -EFAULT;
16377 +       return 0;
16378 +}
16379 +
16380 diff -NurpP --minimal linux-2.6.38-rc8/kernel/vserver/cacct_init.h linux-2.6.38-rc8-vs2.3.0.37-rc6/kernel/vserver/cacct_init.h
16381 --- linux-2.6.38-rc8/kernel/vserver/cacct_init.h        1970-01-01 01:00:00.000000000 +0100
16382 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/kernel/vserver/cacct_init.h 2011-01-29 02:01:07.000000000 +0100
16383 @@ -0,0 +1,25 @@
16384 +
16385 +
16386 +static inline void vx_info_init_cacct(struct _vx_cacct *cacct)
16387 +{
16388 +       int i, j;
16389 +
16390 +
16391 +       for (i = 0; i < VXA_SOCK_SIZE; i++) {
16392 +               for (j = 0; j < 3; j++) {
16393 +                       atomic_long_set(&cacct->sock[i][j].count, 0);
16394 +                       atomic_long_set(&cacct->sock[i][j].total, 0);
16395 +               }
16396 +       }
16397 +       for (i = 0; i < 8; i++)
16398 +               atomic_set(&cacct->slab[i], 0);
16399 +       for (i = 0; i < 5; i++)
16400 +               for (j = 0; j < 4; j++)
16401 +                       atomic_set(&cacct->page[i][j], 0);
16402 +}
16403 +
16404 +static inline void vx_info_exit_cacct(struct _vx_cacct *cacct)
16405 +{
16406 +       return;
16407 +}
16408 +
16409 diff -NurpP --minimal linux-2.6.38-rc8/kernel/vserver/cacct_proc.h linux-2.6.38-rc8-vs2.3.0.37-rc6/kernel/vserver/cacct_proc.h
16410 --- linux-2.6.38-rc8/kernel/vserver/cacct_proc.h        1970-01-01 01:00:00.000000000 +0100
16411 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/kernel/vserver/cacct_proc.h 2011-01-29 02:01:07.000000000 +0100
16412 @@ -0,0 +1,53 @@
16413 +#ifndef _VX_CACCT_PROC_H
16414 +#define _VX_CACCT_PROC_H
16415 +
16416 +#include <linux/vserver/cacct_int.h>
16417 +
16418 +
16419 +#define VX_SOCKA_TOP   \
16420 +       "Type\t    recv #/bytes\t\t   send #/bytes\t\t    fail #/bytes\n"
16421 +
16422 +static inline int vx_info_proc_cacct(struct _vx_cacct *cacct, char *buffer)
16423 +{
16424 +       int i, j, length = 0;
16425 +       static char *type[VXA_SOCK_SIZE] = {
16426 +               "UNSPEC", "UNIX", "INET", "INET6", "PACKET", "OTHER"
16427 +       };
16428 +
16429 +       length += sprintf(buffer + length, VX_SOCKA_TOP);
16430 +       for (i = 0; i < VXA_SOCK_SIZE; i++) {
16431 +               length += sprintf(buffer + length, "%s:", type[i]);
16432 +               for (j = 0; j < 3; j++) {
16433 +                       length += sprintf(buffer + length,
16434 +                               "\t%10lu/%-10lu",
16435 +                               vx_sock_count(cacct, i, j),
16436 +                               vx_sock_total(cacct, i, j));
16437 +               }
16438 +               buffer[length++] = '\n';
16439 +       }
16440 +
16441 +       length += sprintf(buffer + length, "\n");
16442 +       length += sprintf(buffer + length,
16443 +               "slab:\t %8u %8u %8u %8u\n",
16444 +               atomic_read(&cacct->slab[1]),
16445 +               atomic_read(&cacct->slab[4]),
16446 +               atomic_read(&cacct->slab[0]),
16447 +               atomic_read(&cacct->slab[2]));
16448 +
16449 +       length += sprintf(buffer + length, "\n");
16450 +       for (i = 0; i < 5; i++) {
16451 +               length += sprintf(buffer + length,
16452 +                       "page[%d]: %8u %8u %8u %8u\t %8u %8u %8u %8u\n", i,
16453 +                       atomic_read(&cacct->page[i][0]),
16454 +                       atomic_read(&cacct->page[i][1]),
16455 +                       atomic_read(&cacct->page[i][2]),
16456 +                       atomic_read(&cacct->page[i][3]),
16457 +                       atomic_read(&cacct->page[i][4]),
16458 +                       atomic_read(&cacct->page[i][5]),
16459 +                       atomic_read(&cacct->page[i][6]),
16460 +                       atomic_read(&cacct->page[i][7]));
16461 +       }
16462 +       return length;
16463 +}
16464 +
16465 +#endif /* _VX_CACCT_PROC_H */
16466 diff -NurpP --minimal linux-2.6.38-rc8/kernel/vserver/context.c linux-2.6.38-rc8-vs2.3.0.37-rc6/kernel/vserver/context.c
16467 --- linux-2.6.38-rc8/kernel/vserver/context.c   1970-01-01 01:00:00.000000000 +0100
16468 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/kernel/vserver/context.c    2011-01-31 22:46:59.000000000 +0100
16469 @@ -0,0 +1,1079 @@
16470 +/*
16471 + *  linux/kernel/vserver/context.c
16472 + *
16473 + *  Virtual Server: Context Support
16474 + *
16475 + *  Copyright (C) 2003-2010  Herbert Pötzl
16476 + *
16477 + *  V0.01  context helper
16478 + *  V0.02  vx_ctx_kill syscall command
16479 + *  V0.03  replaced context_info calls
16480 + *  V0.04  redesign of struct (de)alloc
16481 + *  V0.05  rlimit basic implementation
16482 + *  V0.06  task_xid and info commands
16483 + *  V0.07  context flags and caps
16484 + *  V0.08  switch to RCU based hash
16485 + *  V0.09  revert to non RCU for now
16486 + *  V0.10  and back to working RCU hash
16487 + *  V0.11  and back to locking again
16488 + *  V0.12  referenced context store
16489 + *  V0.13  separate per cpu data
16490 + *  V0.14  changed vcmds to vxi arg
16491 + *  V0.15  added context stat
16492 + *  V0.16  have __create claim() the vxi
16493 + *  V0.17  removed older and legacy stuff
16494 + *  V0.18  added user credentials
16495 + *
16496 + */
16497 +
16498 +#include <linux/slab.h>
16499 +#include <linux/types.h>
16500 +#include <linux/security.h>
16501 +#include <linux/pid_namespace.h>
16502 +
16503 +#include <linux/vserver/context.h>
16504 +#include <linux/vserver/network.h>
16505 +#include <linux/vserver/debug.h>
16506 +#include <linux/vserver/limit.h>
16507 +#include <linux/vserver/limit_int.h>
16508 +#include <linux/vserver/space.h>
16509 +#include <linux/init_task.h>
16510 +#include <linux/fs_struct.h>
16511 +#include <linux/cred.h>
16512 +
16513 +#include <linux/vs_context.h>
16514 +#include <linux/vs_limit.h>
16515 +#include <linux/vs_pid.h>
16516 +#include <linux/vserver/context_cmd.h>
16517 +
16518 +#include "cvirt_init.h"
16519 +#include "cacct_init.h"
16520 +#include "limit_init.h"
16521 +#include "sched_init.h"
16522 +
16523 +
16524 +atomic_t vx_global_ctotal      = ATOMIC_INIT(0);
16525 +atomic_t vx_global_cactive     = ATOMIC_INIT(0);
16526 +
16527 +
16528 +/*     now inactive context structures */
16529 +
16530 +static struct hlist_head vx_info_inactive = HLIST_HEAD_INIT;
16531 +
16532 +static spinlock_t vx_info_inactive_lock = SPIN_LOCK_UNLOCKED;
16533 +
16534 +
16535 +/*     __alloc_vx_info()
16536 +
16537 +       * allocate an initialized vx_info struct
16538 +       * doesn't make it visible (hash)                        */
16539 +
16540 +static struct vx_info *__alloc_vx_info(xid_t xid)
16541 +{
16542 +       struct vx_info *new = NULL;
16543 +       int cpu, index;
16544 +
16545 +       vxdprintk(VXD_CBIT(xid, 0), "alloc_vx_info(%d)*", xid);
16546 +
16547 +       /* would this benefit from a slab cache? */
16548 +       new = kmalloc(sizeof(struct vx_info), GFP_KERNEL);
16549 +       if (!new)
16550 +               return 0;
16551 +
16552 +       memset(new, 0, sizeof(struct vx_info));
16553 +#ifdef CONFIG_SMP
16554 +       new->ptr_pc = alloc_percpu(struct _vx_info_pc);
16555 +       if (!new->ptr_pc)
16556 +               goto error;
16557 +#endif
16558 +       new->vx_id = xid;
16559 +       INIT_HLIST_NODE(&new->vx_hlist);
16560 +       atomic_set(&new->vx_usecnt, 0);
16561 +       atomic_set(&new->vx_tasks, 0);
16562 +       new->vx_parent = NULL;
16563 +       new->vx_state = 0;
16564 +       init_waitqueue_head(&new->vx_wait);
16565 +
16566 +       /* prepare reaper */
16567 +       get_task_struct(init_pid_ns.child_reaper);
16568 +       new->vx_reaper = init_pid_ns.child_reaper;
16569 +       new->vx_badness_bias = 0;
16570 +
16571 +       /* rest of init goes here */
16572 +       vx_info_init_limit(&new->limit);
16573 +       vx_info_init_sched(&new->sched);
16574 +       vx_info_init_cvirt(&new->cvirt);
16575 +       vx_info_init_cacct(&new->cacct);
16576 +
16577 +       /* per cpu data structures */
16578 +       for_each_possible_cpu(cpu) {
16579 +               vx_info_init_sched_pc(
16580 +                       &vx_per_cpu(new, sched_pc, cpu), cpu);
16581 +               vx_info_init_cvirt_pc(
16582 +                       &vx_per_cpu(new, cvirt_pc, cpu), cpu);
16583 +       }
16584 +
16585 +       new->vx_flags = VXF_INIT_SET;
16586 +       cap_set_init_eff(new->vx_bcaps);
16587 +       new->vx_ccaps = 0;
16588 +       new->vx_umask = 0;
16589 +
16590 +       new->reboot_cmd = 0;
16591 +       new->exit_code = 0;
16592 +
16593 +       // preconfig spaces
16594 +       for (index = 0; index < VX_SPACES; index++) {
16595 +               struct _vx_space *space = &new->space[index];
16596 +
16597 +               // filesystem
16598 +               spin_lock(&init_fs.lock);
16599 +               init_fs.users++;
16600 +               spin_unlock(&init_fs.lock);
16601 +               space->vx_fs = &init_fs;
16602 +
16603 +               /* FIXME: do we want defaults? */
16604 +               // space->vx_real_cred = 0;
16605 +               // space->vx_cred = 0;
16606 +       }
16607 +
16608 +
16609 +       vxdprintk(VXD_CBIT(xid, 0),
16610 +               "alloc_vx_info(%d) = %p", xid, new);
16611 +       vxh_alloc_vx_info(new);
16612 +       atomic_inc(&vx_global_ctotal);
16613 +       return new;
16614 +#ifdef CONFIG_SMP
16615 +error:
16616 +       kfree(new);
16617 +       return 0;
16618 +#endif
16619 +}
16620 +
16621 +/*     __dealloc_vx_info()
16622 +
16623 +       * final disposal of vx_info                             */
16624 +
16625 +static void __dealloc_vx_info(struct vx_info *vxi)
16626 +{
16627 +#ifdef CONFIG_VSERVER_WARN
16628 +       struct vx_info_save vxis;
16629 +       int cpu;
16630 +#endif
16631 +       vxdprintk(VXD_CBIT(xid, 0),
16632 +               "dealloc_vx_info(%p)", vxi);
16633 +       vxh_dealloc_vx_info(vxi);
16634 +
16635 +#ifdef CONFIG_VSERVER_WARN
16636 +       enter_vx_info(vxi, &vxis);
16637 +       vx_info_exit_limit(&vxi->limit);
16638 +       vx_info_exit_sched(&vxi->sched);
16639 +       vx_info_exit_cvirt(&vxi->cvirt);
16640 +       vx_info_exit_cacct(&vxi->cacct);
16641 +
16642 +       for_each_possible_cpu(cpu) {
16643 +               vx_info_exit_sched_pc(
16644 +                       &vx_per_cpu(vxi, sched_pc, cpu), cpu);
16645 +               vx_info_exit_cvirt_pc(
16646 +                       &vx_per_cpu(vxi, cvirt_pc, cpu), cpu);
16647 +       }
16648 +       leave_vx_info(&vxis);
16649 +#endif
16650 +
16651 +       vxi->vx_id = -1;
16652 +       vxi->vx_state |= VXS_RELEASED;
16653 +
16654 +#ifdef CONFIG_SMP
16655 +       free_percpu(vxi->ptr_pc);
16656 +#endif
16657 +       kfree(vxi);
16658 +       atomic_dec(&vx_global_ctotal);
16659 +}
16660 +
16661 +static void __shutdown_vx_info(struct vx_info *vxi)
16662 +{
16663 +       struct nsproxy *nsproxy;
16664 +       struct fs_struct *fs;
16665 +       struct cred *cred;
16666 +       int index, kill;
16667 +
16668 +       might_sleep();
16669 +
16670 +       vxi->vx_state |= VXS_SHUTDOWN;
16671 +       vs_state_change(vxi, VSC_SHUTDOWN);
16672 +
16673 +       for (index = 0; index < VX_SPACES; index++) {
16674 +               struct _vx_space *space = &vxi->space[index];
16675 +
16676 +               nsproxy = xchg(&space->vx_nsproxy, NULL);
16677 +               if (nsproxy)
16678 +                       put_nsproxy(nsproxy);
16679 +
16680 +               fs = xchg(&space->vx_fs, NULL);
16681 +               spin_lock(&fs->lock);
16682 +               kill = !--fs->users;
16683 +               spin_unlock(&fs->lock);
16684 +               if (kill)
16685 +                       free_fs_struct(fs);
16686 +
16687 +               cred = (struct cred *)xchg(&space->vx_cred, NULL);
16688 +               if (cred)
16689 +                       abort_creds(cred);
16690 +       }
16691 +}
16692 +
16693 +/* exported stuff */
16694 +
16695 +void free_vx_info(struct vx_info *vxi)
16696 +{
16697 +       unsigned long flags;
16698 +       unsigned index;
16699 +
16700 +       /* check for reference counts first */
16701 +       BUG_ON(atomic_read(&vxi->vx_usecnt));
16702 +       BUG_ON(atomic_read(&vxi->vx_tasks));
16703 +
16704 +       /* context must not be hashed */
16705 +       BUG_ON(vx_info_state(vxi, VXS_HASHED));
16706 +
16707 +       /* context shutdown is mandatory */
16708 +       BUG_ON(!vx_info_state(vxi, VXS_SHUTDOWN));
16709 +
16710 +       /* spaces check */
16711 +       for (index = 0; index < VX_SPACES; index++) {
16712 +               struct _vx_space *space = &vxi->space[index];
16713 +
16714 +               BUG_ON(space->vx_nsproxy);
16715 +               BUG_ON(space->vx_fs);
16716 +               // BUG_ON(space->vx_real_cred);
16717 +               // BUG_ON(space->vx_cred);
16718 +       }
16719 +
16720 +       spin_lock_irqsave(&vx_info_inactive_lock, flags);
16721 +       hlist_del(&vxi->vx_hlist);
16722 +       spin_unlock_irqrestore(&vx_info_inactive_lock, flags);
16723 +
16724 +       __dealloc_vx_info(vxi);
16725 +}
16726 +
16727 +
16728 +/*     hash table for vx_info hash */
16729 +
16730 +#define VX_HASH_SIZE   13
16731 +
16732 +static struct hlist_head vx_info_hash[VX_HASH_SIZE] =
16733 +       { [0 ... VX_HASH_SIZE-1] = HLIST_HEAD_INIT };
16734 +
16735 +static spinlock_t vx_info_hash_lock = SPIN_LOCK_UNLOCKED;
16736 +
16737 +
16738 +static inline unsigned int __hashval(xid_t xid)
16739 +{
16740 +       return (xid % VX_HASH_SIZE);
16741 +}
16742 +
16743 +
16744 +
16745 +/*     __hash_vx_info()
16746 +
16747 +       * add the vxi to the global hash table
16748 +       * requires the hash_lock to be held                     */
16749 +
16750 +static inline void __hash_vx_info(struct vx_info *vxi)
16751 +{
16752 +       struct hlist_head *head;
16753 +
16754 +       vxd_assert_lock(&vx_info_hash_lock);
16755 +       vxdprintk(VXD_CBIT(xid, 4),
16756 +               "__hash_vx_info: %p[#%d]", vxi, vxi->vx_id);
16757 +       vxh_hash_vx_info(vxi);
16758 +
16759 +       /* context must not be hashed */
16760 +       BUG_ON(vx_info_state(vxi, VXS_HASHED));
16761 +
16762 +       vxi->vx_state |= VXS_HASHED;
16763 +       head = &vx_info_hash[__hashval(vxi->vx_id)];
16764 +       hlist_add_head(&vxi->vx_hlist, head);
16765 +       atomic_inc(&vx_global_cactive);
16766 +}
16767 +
16768 +/*     __unhash_vx_info()
16769 +
16770 +       * remove the vxi from the global hash table
16771 +       * requires the hash_lock to be held                     */
16772 +
16773 +static inline void __unhash_vx_info(struct vx_info *vxi)
16774 +{
16775 +       unsigned long flags;
16776 +
16777 +       vxd_assert_lock(&vx_info_hash_lock);
16778 +       vxdprintk(VXD_CBIT(xid, 4),
16779 +               "__unhash_vx_info: %p[#%d.%d.%d]", vxi, vxi->vx_id,
16780 +               atomic_read(&vxi->vx_usecnt), atomic_read(&vxi->vx_tasks));
16781 +       vxh_unhash_vx_info(vxi);
16782 +
16783 +       /* context must be hashed */
16784 +       BUG_ON(!vx_info_state(vxi, VXS_HASHED));
16785 +       /* but without tasks */
16786 +       BUG_ON(atomic_read(&vxi->vx_tasks));
16787 +
16788 +       vxi->vx_state &= ~VXS_HASHED;
16789 +       hlist_del_init(&vxi->vx_hlist);
16790 +       spin_lock_irqsave(&vx_info_inactive_lock, flags);
16791 +       hlist_add_head(&vxi->vx_hlist, &vx_info_inactive);
16792 +       spin_unlock_irqrestore(&vx_info_inactive_lock, flags);
16793 +       atomic_dec(&vx_global_cactive);
16794 +}
16795 +
16796 +
16797 +/*     __lookup_vx_info()
16798 +
16799 +       * requires the hash_lock to be held
16800 +       * doesn't increment the vx_refcnt                       */
16801 +
16802 +static inline struct vx_info *__lookup_vx_info(xid_t xid)
16803 +{
16804 +       struct hlist_head *head = &vx_info_hash[__hashval(xid)];
16805 +       struct hlist_node *pos;
16806 +       struct vx_info *vxi;
16807 +
16808 +       vxd_assert_lock(&vx_info_hash_lock);
16809 +       hlist_for_each(pos, head) {
16810 +               vxi = hlist_entry(pos, struct vx_info, vx_hlist);
16811 +
16812 +               if (vxi->vx_id == xid)
16813 +                       goto found;
16814 +       }
16815 +       vxi = NULL;
16816 +found:
16817 +       vxdprintk(VXD_CBIT(xid, 0),
16818 +               "__lookup_vx_info(#%u): %p[#%u]",
16819 +               xid, vxi, vxi ? vxi->vx_id : 0);
16820 +       vxh_lookup_vx_info(vxi, xid);
16821 +       return vxi;
16822 +}
16823 +
16824 +
16825 +/*     __create_vx_info()
16826 +
16827 +       * create the requested context
16828 +       * get(), claim() and hash it                            */
16829 +
16830 +static struct vx_info *__create_vx_info(int id)
16831 +{
16832 +       struct vx_info *new, *vxi = NULL;
16833 +
16834 +       vxdprintk(VXD_CBIT(xid, 1), "create_vx_info(%d)*", id);
16835 +
16836 +       if (!(new = __alloc_vx_info(id)))
16837 +               return ERR_PTR(-ENOMEM);
16838 +
16839 +       /* required to make dynamic xids unique */
16840 +       spin_lock(&vx_info_hash_lock);
16841 +
16842 +       /* static context requested */
16843 +       if ((vxi = __lookup_vx_info(id))) {
16844 +               vxdprintk(VXD_CBIT(xid, 0),
16845 +                       "create_vx_info(%d) = %p (already there)", id, vxi);
16846 +               if (vx_info_flags(vxi, VXF_STATE_SETUP, 0))
16847 +                       vxi = ERR_PTR(-EBUSY);
16848 +               else
16849 +                       vxi = ERR_PTR(-EEXIST);
16850 +               goto out_unlock;
16851 +       }
16852 +       /* new context */
16853 +       vxdprintk(VXD_CBIT(xid, 0),
16854 +               "create_vx_info(%d) = %p (new)", id, new);
16855 +       claim_vx_info(new, NULL);
16856 +       __hash_vx_info(get_vx_info(new));
16857 +       vxi = new, new = NULL;
16858 +
16859 +out_unlock:
16860 +       spin_unlock(&vx_info_hash_lock);
16861 +       vxh_create_vx_info(IS_ERR(vxi) ? NULL : vxi, id);
16862 +       if (new)
16863 +               __dealloc_vx_info(new);
16864 +       return vxi;
16865 +}
16866 +
16867 +
16868 +/*     exported stuff                                          */
16869 +
16870 +
16871 +void unhash_vx_info(struct vx_info *vxi)
16872 +{
16873 +       __shutdown_vx_info(vxi);
16874 +       spin_lock(&vx_info_hash_lock);
16875 +       __unhash_vx_info(vxi);
16876 +       spin_unlock(&vx_info_hash_lock);
16877 +       __wakeup_vx_info(vxi);
16878 +}
16879 +
16880 +
16881 +/*     lookup_vx_info()
16882 +
16883 +       * search for a vx_info and get() it
16884 +       * negative id means current                             */
16885 +
16886 +struct vx_info *lookup_vx_info(int id)
16887 +{
16888 +       struct vx_info *vxi = NULL;
16889 +
16890 +       if (id < 0) {
16891 +               vxi = get_vx_info(current_vx_info());
16892 +       } else if (id > 1) {
16893 +               spin_lock(&vx_info_hash_lock);
16894 +               vxi = get_vx_info(__lookup_vx_info(id));
16895 +               spin_unlock(&vx_info_hash_lock);
16896 +       }
16897 +       return vxi;
16898 +}
16899 +
16900 +/*     xid_is_hashed()
16901 +
16902 +       * verify that xid is still hashed                       */
16903 +
16904 +int xid_is_hashed(xid_t xid)
16905 +{
16906 +       int hashed;
16907 +
16908 +       spin_lock(&vx_info_hash_lock);
16909 +       hashed = (__lookup_vx_info(xid) != NULL);
16910 +       spin_unlock(&vx_info_hash_lock);
16911 +       return hashed;
16912 +}
16913 +
16914 +#ifdef CONFIG_PROC_FS
16915 +
16916 +/*     get_xid_list()
16917 +
16918 +       * get a subset of hashed xids for proc
16919 +       * assumes size is at least one                          */
16920 +
16921 +int get_xid_list(int index, unsigned int *xids, int size)
16922 +{
16923 +       int hindex, nr_xids = 0;
16924 +
16925 +       /* only show current and children */
16926 +       if (!vx_check(0, VS_ADMIN | VS_WATCH)) {
16927 +               if (index > 0)
16928 +                       return 0;
16929 +               xids[nr_xids] = vx_current_xid();
16930 +               return 1;
16931 +       }
16932 +
16933 +       for (hindex = 0; hindex < VX_HASH_SIZE; hindex++) {
16934 +               struct hlist_head *head = &vx_info_hash[hindex];
16935 +               struct hlist_node *pos;
16936 +
16937 +               spin_lock(&vx_info_hash_lock);
16938 +               hlist_for_each(pos, head) {
16939 +                       struct vx_info *vxi;
16940 +
16941 +                       if (--index > 0)
16942 +                               continue;
16943 +
16944 +                       vxi = hlist_entry(pos, struct vx_info, vx_hlist);
16945 +                       xids[nr_xids] = vxi->vx_id;
16946 +                       if (++nr_xids >= size) {
16947 +                               spin_unlock(&vx_info_hash_lock);
16948 +                               goto out;
16949 +                       }
16950 +               }
16951 +               /* keep the lock time short */
16952 +               spin_unlock(&vx_info_hash_lock);
16953 +       }
16954 +out:
16955 +       return nr_xids;
16956 +}
16957 +#endif
16958 +
16959 +#ifdef CONFIG_VSERVER_DEBUG
16960 +
16961 +void   dump_vx_info_inactive(int level)
16962 +{
16963 +       struct hlist_node *entry, *next;
16964 +
16965 +       hlist_for_each_safe(entry, next, &vx_info_inactive) {
16966 +               struct vx_info *vxi =
16967 +                       list_entry(entry, struct vx_info, vx_hlist);
16968 +
16969 +               dump_vx_info(vxi, level);
16970 +       }
16971 +}
16972 +
16973 +#endif
16974 +
16975 +#if 0
16976 +int vx_migrate_user(struct task_struct *p, struct vx_info *vxi)
16977 +{
16978 +       struct user_struct *new_user, *old_user;
16979 +
16980 +       if (!p || !vxi)
16981 +               BUG();
16982 +
16983 +       if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0))
16984 +               return -EACCES;
16985 +
16986 +       new_user = alloc_uid(vxi->vx_id, p->uid);
16987 +       if (!new_user)
16988 +               return -ENOMEM;
16989 +
16990 +       old_user = p->user;
16991 +       if (new_user != old_user) {
16992 +               atomic_inc(&new_user->processes);
16993 +               atomic_dec(&old_user->processes);
16994 +               p->user = new_user;
16995 +       }
16996 +       free_uid(old_user);
16997 +       return 0;
16998 +}
16999 +#endif
17000 +
17001 +#if 0
17002 +void vx_mask_cap_bset(struct vx_info *vxi, struct task_struct *p)
17003 +{
17004 +       // p->cap_effective &= vxi->vx_cap_bset;
17005 +       p->cap_effective =
17006 +               cap_intersect(p->cap_effective, vxi->cap_bset);
17007 +       // p->cap_inheritable &= vxi->vx_cap_bset;
17008 +       p->cap_inheritable =
17009 +               cap_intersect(p->cap_inheritable, vxi->cap_bset);
17010 +       // p->cap_permitted &= vxi->vx_cap_bset;
17011 +       p->cap_permitted =
17012 +               cap_intersect(p->cap_permitted, vxi->cap_bset);
17013 +}
17014 +#endif
17015 +
17016 +
17017 +#include <linux/file.h>
17018 +#include <linux/fdtable.h>
17019 +
17020 +static int vx_openfd_task(struct task_struct *tsk)
17021 +{
17022 +       struct files_struct *files = tsk->files;
17023 +       struct fdtable *fdt;
17024 +       const unsigned long *bptr;
17025 +       int count, total;
17026 +
17027 +       /* no rcu_read_lock() because of spin_lock() */
17028 +       spin_lock(&files->file_lock);
17029 +       fdt = files_fdtable(files);
17030 +       bptr = fdt->open_fds->fds_bits;
17031 +       count = fdt->max_fds / (sizeof(unsigned long) * 8);
17032 +       for (total = 0; count > 0; count--) {
17033 +               if (*bptr)
17034 +                       total += hweight_long(*bptr);
17035 +               bptr++;
17036 +       }
17037 +       spin_unlock(&files->file_lock);
17038 +       return total;
17039 +}
17040 +
17041 +
17042 +/*     for *space compatibility */
17043 +
17044 +asmlinkage long sys_unshare(unsigned long);
17045 +
17046 +/*
17047 + *     migrate task to new context
17048 + *     gets vxi, puts old_vxi on change
17049 + *     optionally unshares namespaces (hack)
17050 + */
17051 +
17052 +int vx_migrate_task(struct task_struct *p, struct vx_info *vxi, int unshare)
17053 +{
17054 +       struct vx_info *old_vxi;
17055 +       int ret = 0;
17056 +
17057 +       if (!p || !vxi)
17058 +               BUG();
17059 +
17060 +       vxdprintk(VXD_CBIT(xid, 5),
17061 +               "vx_migrate_task(%p,%p[#%d.%d])", p, vxi,
17062 +               vxi->vx_id, atomic_read(&vxi->vx_usecnt));
17063 +
17064 +       if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0) &&
17065 +               !vx_info_flags(vxi, VXF_STATE_SETUP, 0))
17066 +               return -EACCES;
17067 +
17068 +       if (vx_info_state(vxi, VXS_SHUTDOWN))
17069 +               return -EFAULT;
17070 +
17071 +       old_vxi = task_get_vx_info(p);
17072 +       if (old_vxi == vxi)
17073 +               goto out;
17074 +
17075 +//     if (!(ret = vx_migrate_user(p, vxi))) {
17076 +       {
17077 +               int openfd;
17078 +
17079 +               task_lock(p);
17080 +               openfd = vx_openfd_task(p);
17081 +
17082 +               if (old_vxi) {
17083 +                       atomic_dec(&old_vxi->cvirt.nr_threads);
17084 +                       atomic_dec(&old_vxi->cvirt.nr_running);
17085 +                       __rlim_dec(&old_vxi->limit, RLIMIT_NPROC);
17086 +                       /* FIXME: what about the struct files here? */
17087 +                       __rlim_sub(&old_vxi->limit, VLIMIT_OPENFD, openfd);
17088 +                       /* account for the executable */
17089 +                       __rlim_dec(&old_vxi->limit, VLIMIT_DENTRY);
17090 +               }
17091 +               atomic_inc(&vxi->cvirt.nr_threads);
17092 +               atomic_inc(&vxi->cvirt.nr_running);
17093 +               __rlim_inc(&vxi->limit, RLIMIT_NPROC);
17094 +               /* FIXME: what about the struct files here? */
17095 +               __rlim_add(&vxi->limit, VLIMIT_OPENFD, openfd);
17096 +               /* account for the executable */
17097 +               __rlim_inc(&vxi->limit, VLIMIT_DENTRY);
17098 +
17099 +               if (old_vxi) {
17100 +                       release_vx_info(old_vxi, p);
17101 +                       clr_vx_info(&p->vx_info);
17102 +               }
17103 +               claim_vx_info(vxi, p);
17104 +               set_vx_info(&p->vx_info, vxi);
17105 +               p->xid = vxi->vx_id;
17106 +
17107 +               vxdprintk(VXD_CBIT(xid, 5),
17108 +                       "moved task %p into vxi:%p[#%d]",
17109 +                       p, vxi, vxi->vx_id);
17110 +
17111 +               // vx_mask_cap_bset(vxi, p);
17112 +               task_unlock(p);
17113 +
17114 +               /* hack for *spaces to provide compatibility */
17115 +               if (unshare) {
17116 +                       struct nsproxy *old_nsp, *new_nsp;
17117 +
17118 +                       ret = unshare_nsproxy_namespaces(
17119 +                               CLONE_NEWUTS | CLONE_NEWIPC | CLONE_NEWUSER,
17120 +                               &new_nsp, NULL);
17121 +                       if (ret)
17122 +                               goto out;
17123 +
17124 +                       old_nsp = xchg(&p->nsproxy, new_nsp);
17125 +                       vx_set_space(vxi,
17126 +                               CLONE_NEWUTS | CLONE_NEWIPC | CLONE_NEWUSER, 0);
17127 +                       put_nsproxy(old_nsp);
17128 +               }
17129 +       }
17130 +out:
17131 +       put_vx_info(old_vxi);
17132 +       return ret;
17133 +}
17134 +
17135 +int vx_set_reaper(struct vx_info *vxi, struct task_struct *p)
17136 +{
17137 +       struct task_struct *old_reaper;
17138 +
17139 +       if (!vxi)
17140 +               return -EINVAL;
17141 +
17142 +       vxdprintk(VXD_CBIT(xid, 6),
17143 +               "vx_set_reaper(%p[#%d],%p[#%d,%d])",
17144 +               vxi, vxi->vx_id, p, p->xid, p->pid);
17145 +
17146 +       old_reaper = vxi->vx_reaper;
17147 +       if (old_reaper == p)
17148 +               return 0;
17149 +
17150 +       /* set new child reaper */
17151 +       get_task_struct(p);
17152 +       vxi->vx_reaper = p;
17153 +       put_task_struct(old_reaper);
17154 +       return 0;
17155 +}
17156 +
17157 +int vx_set_init(struct vx_info *vxi, struct task_struct *p)
17158 +{
17159 +       if (!vxi)
17160 +               return -EINVAL;
17161 +
17162 +       vxdprintk(VXD_CBIT(xid, 6),
17163 +               "vx_set_init(%p[#%d],%p[#%d,%d,%d])",
17164 +               vxi, vxi->vx_id, p, p->xid, p->pid, p->tgid);
17165 +
17166 +       vxi->vx_flags &= ~VXF_STATE_INIT;
17167 +       // vxi->vx_initpid = p->tgid;
17168 +       vxi->vx_initpid = p->pid;
17169 +       return 0;
17170 +}
17171 +
17172 +void vx_exit_init(struct vx_info *vxi, struct task_struct *p, int code)
17173 +{
17174 +       vxdprintk(VXD_CBIT(xid, 6),
17175 +               "vx_exit_init(%p[#%d],%p[#%d,%d,%d])",
17176 +               vxi, vxi->vx_id, p, p->xid, p->pid, p->tgid);
17177 +
17178 +       vxi->exit_code = code;
17179 +       vxi->vx_initpid = 0;
17180 +}
17181 +
17182 +
17183 +void vx_set_persistent(struct vx_info *vxi)
17184 +{
17185 +       vxdprintk(VXD_CBIT(xid, 6),
17186 +               "vx_set_persistent(%p[#%d])", vxi, vxi->vx_id);
17187 +
17188 +       get_vx_info(vxi);
17189 +       claim_vx_info(vxi, NULL);
17190 +}
17191 +
17192 +void vx_clear_persistent(struct vx_info *vxi)
17193 +{
17194 +       vxdprintk(VXD_CBIT(xid, 6),
17195 +               "vx_clear_persistent(%p[#%d])", vxi, vxi->vx_id);
17196 +
17197 +       release_vx_info(vxi, NULL);
17198 +       put_vx_info(vxi);
17199 +}
17200 +
17201 +void vx_update_persistent(struct vx_info *vxi)
17202 +{
17203 +       if (vx_info_flags(vxi, VXF_PERSISTENT, 0))
17204 +               vx_set_persistent(vxi);
17205 +       else
17206 +               vx_clear_persistent(vxi);
17207 +}
17208 +
17209 +
17210 +/*     task must be current or locked          */
17211 +
17212 +void   exit_vx_info(struct task_struct *p, int code)
17213 +{
17214 +       struct vx_info *vxi = p->vx_info;
17215 +
17216 +       if (vxi) {
17217 +               atomic_dec(&vxi->cvirt.nr_threads);
17218 +               vx_nproc_dec(p);
17219 +
17220 +               vxi->exit_code = code;
17221 +               release_vx_info(vxi, p);
17222 +       }
17223 +}
17224 +
17225 +void   exit_vx_info_early(struct task_struct *p, int code)
17226 +{
17227 +       struct vx_info *vxi = p->vx_info;
17228 +
17229 +       if (vxi) {
17230 +               if (vxi->vx_initpid == p->pid)
17231 +                       vx_exit_init(vxi, p, code);
17232 +               if (vxi->vx_reaper == p)
17233 +                       vx_set_reaper(vxi, init_pid_ns.child_reaper);
17234 +       }
17235 +}
17236 +
17237 +
17238 +/* vserver syscall commands below here */
17239 +
17240 +/* taks xid and vx_info functions */
17241 +
17242 +#include <asm/uaccess.h>
17243 +
17244 +
17245 +int vc_task_xid(uint32_t id)
17246 +{
17247 +       xid_t xid;
17248 +
17249 +       if (id) {
17250 +               struct task_struct *tsk;
17251 +
17252 +               read_lock(&tasklist_lock);
17253 +               tsk = find_task_by_real_pid(id);
17254 +               xid = (tsk) ? tsk->xid : -ESRCH;
17255 +               read_unlock(&tasklist_lock);
17256 +       } else
17257 +               xid = vx_current_xid();
17258 +       return xid;
17259 +}
17260 +
17261 +
17262 +int vc_vx_info(struct vx_info *vxi, void __user *data)
17263 +{
17264 +       struct vcmd_vx_info_v0 vc_data;
17265 +
17266 +       vc_data.xid = vxi->vx_id;
17267 +       vc_data.initpid = vxi->vx_initpid;
17268 +
17269 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
17270 +               return -EFAULT;
17271 +       return 0;
17272 +}
17273 +
17274 +
17275 +int vc_ctx_stat(struct vx_info *vxi, void __user *data)
17276 +{
17277 +       struct vcmd_ctx_stat_v0 vc_data;
17278 +
17279 +       vc_data.usecnt = atomic_read(&vxi->vx_usecnt);
17280 +       vc_data.tasks = atomic_read(&vxi->vx_tasks);
17281 +
17282 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
17283 +               return -EFAULT;
17284 +       return 0;
17285 +}
17286 +
17287 +
17288 +/* context functions */
17289 +
17290 +int vc_ctx_create(uint32_t xid, void __user *data)
17291 +{
17292 +       struct vcmd_ctx_create vc_data = { .flagword = VXF_INIT_SET };
17293 +       struct vx_info *new_vxi;
17294 +       int ret;
17295 +
17296 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
17297 +               return -EFAULT;
17298 +
17299 +       if ((xid > MAX_S_CONTEXT) || (xid < 2))
17300 +               return -EINVAL;
17301 +
17302 +       new_vxi = __create_vx_info(xid);
17303 +       if (IS_ERR(new_vxi))
17304 +               return PTR_ERR(new_vxi);
17305 +
17306 +       /* initial flags */
17307 +       new_vxi->vx_flags = vc_data.flagword;
17308 +
17309 +       ret = -ENOEXEC;
17310 +       if (vs_state_change(new_vxi, VSC_STARTUP))
17311 +               goto out;
17312 +
17313 +       ret = vx_migrate_task(current, new_vxi, (!data));
17314 +       if (ret)
17315 +               goto out;
17316 +
17317 +       /* return context id on success */
17318 +       ret = new_vxi->vx_id;
17319 +
17320 +       /* get a reference for persistent contexts */
17321 +       if ((vc_data.flagword & VXF_PERSISTENT))
17322 +               vx_set_persistent(new_vxi);
17323 +out:
17324 +       release_vx_info(new_vxi, NULL);
17325 +       put_vx_info(new_vxi);
17326 +       return ret;
17327 +}
17328 +
17329 +
17330 +int vc_ctx_migrate(struct vx_info *vxi, void __user *data)
17331 +{
17332 +       struct vcmd_ctx_migrate vc_data = { .flagword = 0 };
17333 +       int ret;
17334 +
17335 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
17336 +               return -EFAULT;
17337 +
17338 +       ret = vx_migrate_task(current, vxi, 0);
17339 +       if (ret)
17340 +               return ret;
17341 +       if (vc_data.flagword & VXM_SET_INIT)
17342 +               ret = vx_set_init(vxi, current);
17343 +       if (ret)
17344 +               return ret;
17345 +       if (vc_data.flagword & VXM_SET_REAPER)
17346 +               ret = vx_set_reaper(vxi, current);
17347 +       return ret;
17348 +}
17349 +
17350 +
17351 +int vc_get_cflags(struct vx_info *vxi, void __user *data)
17352 +{
17353 +       struct vcmd_ctx_flags_v0 vc_data;
17354 +
17355 +       vc_data.flagword = vxi->vx_flags;
17356 +
17357 +       /* special STATE flag handling */
17358 +       vc_data.mask = vs_mask_flags(~0ULL, vxi->vx_flags, VXF_ONE_TIME);
17359 +
17360 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
17361 +               return -EFAULT;
17362 +       return 0;
17363 +}
17364 +
17365 +int vc_set_cflags(struct vx_info *vxi, void __user *data)
17366 +{
17367 +       struct vcmd_ctx_flags_v0 vc_data;
17368 +       uint64_t mask, trigger;
17369 +
17370 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17371 +               return -EFAULT;
17372 +
17373 +       /* special STATE flag handling */
17374 +       mask = vs_mask_mask(vc_data.mask, vxi->vx_flags, VXF_ONE_TIME);
17375 +       trigger = (mask & vxi->vx_flags) ^ (mask & vc_data.flagword);
17376 +
17377 +       if (vxi == current_vx_info()) {
17378 +               /* if (trigger & VXF_STATE_SETUP)
17379 +                       vx_mask_cap_bset(vxi, current); */
17380 +               if (trigger & VXF_STATE_INIT) {
17381 +                       int ret;
17382 +
17383 +                       ret = vx_set_init(vxi, current);
17384 +                       if (ret)
17385 +                               return ret;
17386 +                       ret = vx_set_reaper(vxi, current);
17387 +                       if (ret)
17388 +                               return ret;
17389 +               }
17390 +       }
17391 +
17392 +       vxi->vx_flags = vs_mask_flags(vxi->vx_flags,
17393 +               vc_data.flagword, mask);
17394 +       if (trigger & VXF_PERSISTENT)
17395 +               vx_update_persistent(vxi);
17396 +
17397 +       return 0;
17398 +}
17399 +
17400 +
17401 +static inline uint64_t caps_from_cap_t(kernel_cap_t c)
17402 +{
17403 +       uint64_t v = c.cap[0] | ((uint64_t)c.cap[1] << 32);
17404 +
17405 +       // printk("caps_from_cap_t(%08x:%08x) = %016llx\n", c.cap[1], c.cap[0], v);
17406 +       return v;
17407 +}
17408 +
17409 +static inline kernel_cap_t cap_t_from_caps(uint64_t v)
17410 +{
17411 +       kernel_cap_t c = __cap_empty_set;
17412 +
17413 +       c.cap[0] = v & 0xFFFFFFFF;
17414 +       c.cap[1] = (v >> 32) & 0xFFFFFFFF;
17415 +
17416 +       // printk("cap_t_from_caps(%016llx) = %08x:%08x\n", v, c.cap[1], c.cap[0]);
17417 +       return c;
17418 +}
17419 +
17420 +
17421 +static int do_get_caps(struct vx_info *vxi, uint64_t *bcaps, uint64_t *ccaps)
17422 +{
17423 +       if (bcaps)
17424 +               *bcaps = caps_from_cap_t(vxi->vx_bcaps);
17425 +       if (ccaps)
17426 +               *ccaps = vxi->vx_ccaps;
17427 +
17428 +       return 0;
17429 +}
17430 +
17431 +int vc_get_ccaps(struct vx_info *vxi, void __user *data)
17432 +{
17433 +       struct vcmd_ctx_caps_v1 vc_data;
17434 +       int ret;
17435 +
17436 +       ret = do_get_caps(vxi, NULL, &vc_data.ccaps);
17437 +       if (ret)
17438 +               return ret;
17439 +       vc_data.cmask = ~0ULL;
17440 +
17441 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
17442 +               return -EFAULT;
17443 +       return 0;
17444 +}
17445 +
17446 +static int do_set_caps(struct vx_info *vxi,
17447 +       uint64_t bcaps, uint64_t bmask, uint64_t ccaps, uint64_t cmask)
17448 +{
17449 +       uint64_t bcold = caps_from_cap_t(vxi->vx_bcaps);
17450 +
17451 +#if 0
17452 +       printk("do_set_caps(%16llx, %16llx, %16llx, %16llx)\n",
17453 +               bcaps, bmask, ccaps, cmask);
17454 +#endif
17455 +       vxi->vx_bcaps = cap_t_from_caps(
17456 +               vs_mask_flags(bcold, bcaps, bmask));
17457 +       vxi->vx_ccaps = vs_mask_flags(vxi->vx_ccaps, ccaps, cmask);
17458 +
17459 +       return 0;
17460 +}
17461 +
17462 +int vc_set_ccaps(struct vx_info *vxi, void __user *data)
17463 +{
17464 +       struct vcmd_ctx_caps_v1 vc_data;
17465 +
17466 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17467 +               return -EFAULT;
17468 +
17469 +       return do_set_caps(vxi, 0, 0, vc_data.ccaps, vc_data.cmask);
17470 +}
17471 +
17472 +int vc_get_bcaps(struct vx_info *vxi, void __user *data)
17473 +{
17474 +       struct vcmd_bcaps vc_data;
17475 +       int ret;
17476 +
17477 +       ret = do_get_caps(vxi, &vc_data.bcaps, NULL);
17478 +       if (ret)
17479 +               return ret;
17480 +       vc_data.bmask = ~0ULL;
17481 +
17482 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
17483 +               return -EFAULT;
17484 +       return 0;
17485 +}
17486 +
17487 +int vc_set_bcaps(struct vx_info *vxi, void __user *data)
17488 +{
17489 +       struct vcmd_bcaps vc_data;
17490 +
17491 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17492 +               return -EFAULT;
17493 +
17494 +       return do_set_caps(vxi, vc_data.bcaps, vc_data.bmask, 0, 0);
17495 +}
17496 +
17497 +
17498 +int vc_get_umask(struct vx_info *vxi, void __user *data)
17499 +{
17500 +       struct vcmd_umask vc_data;
17501 +
17502 +       vc_data.umask = vxi->vx_umask;
17503 +       vc_data.mask = ~0ULL;
17504 +
17505 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
17506 +               return -EFAULT;
17507 +       return 0;
17508 +}
17509 +
17510 +int vc_set_umask(struct vx_info *vxi, void __user *data)
17511 +{
17512 +       struct vcmd_umask vc_data;
17513 +
17514 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17515 +               return -EFAULT;
17516 +
17517 +       vxi->vx_umask = vs_mask_flags(vxi->vx_umask,
17518 +               vc_data.umask, vc_data.mask);
17519 +       return 0;
17520 +}
17521 +
17522 +
17523 +int vc_get_badness(struct vx_info *vxi, void __user *data)
17524 +{
17525 +       struct vcmd_badness_v0 vc_data;
17526 +
17527 +       vc_data.bias = vxi->vx_badness_bias;
17528 +
17529 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
17530 +               return -EFAULT;
17531 +       return 0;
17532 +}
17533 +
17534 +int vc_set_badness(struct vx_info *vxi, void __user *data)
17535 +{
17536 +       struct vcmd_badness_v0 vc_data;
17537 +
17538 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17539 +               return -EFAULT;
17540 +
17541 +       vxi->vx_badness_bias = vc_data.bias;
17542 +       return 0;
17543 +}
17544 +
17545 +#include <linux/module.h>
17546 +
17547 +EXPORT_SYMBOL_GPL(free_vx_info);
17548 +
17549 diff -NurpP --minimal linux-2.6.38-rc8/kernel/vserver/cvirt.c linux-2.6.38-rc8-vs2.3.0.37-rc6/kernel/vserver/cvirt.c
17550 --- linux-2.6.38-rc8/kernel/vserver/cvirt.c     1970-01-01 01:00:00.000000000 +0100
17551 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/kernel/vserver/cvirt.c      2011-01-29 02:01:07.000000000 +0100
17552 @@ -0,0 +1,303 @@
17553 +/*
17554 + *  linux/kernel/vserver/cvirt.c
17555 + *
17556 + *  Virtual Server: Context Virtualization
17557 + *
17558 + *  Copyright (C) 2004-2007  Herbert Pötzl
17559 + *
17560 + *  V0.01  broken out from limit.c
17561 + *  V0.02  added utsname stuff
17562 + *  V0.03  changed vcmds to vxi arg
17563 + *
17564 + */
17565 +
17566 +#include <linux/types.h>
17567 +#include <linux/utsname.h>
17568 +#include <linux/vs_cvirt.h>
17569 +#include <linux/vserver/switch.h>
17570 +#include <linux/vserver/cvirt_cmd.h>
17571 +
17572 +#include <asm/uaccess.h>
17573 +
17574 +
17575 +void vx_vsi_uptime(struct timespec *uptime, struct timespec *idle)
17576 +{
17577 +       struct vx_info *vxi = current_vx_info();
17578 +
17579 +       set_normalized_timespec(uptime,
17580 +               uptime->tv_sec - vxi->cvirt.bias_uptime.tv_sec,
17581 +               uptime->tv_nsec - vxi->cvirt.bias_uptime.tv_nsec);
17582 +       if (!idle)
17583 +               return;
17584 +       set_normalized_timespec(idle,
17585 +               idle->tv_sec - vxi->cvirt.bias_idle.tv_sec,
17586 +               idle->tv_nsec - vxi->cvirt.bias_idle.tv_nsec);
17587 +       return;
17588 +}
17589 +
17590 +uint64_t vx_idle_jiffies(void)
17591 +{
17592 +       return init_task.utime + init_task.stime;
17593 +}
17594 +
17595 +
17596 +
17597 +static inline uint32_t __update_loadavg(uint32_t load,
17598 +       int wsize, int delta, int n)
17599 +{
17600 +       unsigned long long calc, prev;
17601 +
17602 +       /* just set it to n */
17603 +       if (unlikely(delta >= wsize))
17604 +               return (n << FSHIFT);
17605 +
17606 +       calc = delta * n;
17607 +       calc <<= FSHIFT;
17608 +       prev = (wsize - delta);
17609 +       prev *= load;
17610 +       calc += prev;
17611 +       do_div(calc, wsize);
17612 +       return calc;
17613 +}
17614 +
17615 +
17616 +void vx_update_load(struct vx_info *vxi)
17617 +{
17618 +       uint32_t now, last, delta;
17619 +       unsigned int nr_running, nr_uninterruptible;
17620 +       unsigned int total;
17621 +       unsigned long flags;
17622 +
17623 +       spin_lock_irqsave(&vxi->cvirt.load_lock, flags);
17624 +
17625 +       now = jiffies;
17626 +       last = vxi->cvirt.load_last;
17627 +       delta = now - last;
17628 +
17629 +       if (delta < 5*HZ)
17630 +               goto out;
17631 +
17632 +       nr_running = atomic_read(&vxi->cvirt.nr_running);
17633 +       nr_uninterruptible = atomic_read(&vxi->cvirt.nr_uninterruptible);
17634 +       total = nr_running + nr_uninterruptible;
17635 +
17636 +       vxi->cvirt.load[0] = __update_loadavg(vxi->cvirt.load[0],
17637 +               60*HZ, delta, total);
17638 +       vxi->cvirt.load[1] = __update_loadavg(vxi->cvirt.load[1],
17639 +               5*60*HZ, delta, total);
17640 +       vxi->cvirt.load[2] = __update_loadavg(vxi->cvirt.load[2],
17641 +               15*60*HZ, delta, total);
17642 +
17643 +       vxi->cvirt.load_last = now;
17644 +out:
17645 +       atomic_inc(&vxi->cvirt.load_updates);
17646 +       spin_unlock_irqrestore(&vxi->cvirt.load_lock, flags);
17647 +}
17648 +
17649 +
17650 +/*
17651 + * Commands to do_syslog:
17652 + *
17653 + *      0 -- Close the log.  Currently a NOP.
17654 + *      1 -- Open the log. Currently a NOP.
17655 + *      2 -- Read from the log.
17656 + *      3 -- Read all messages remaining in the ring buffer.
17657 + *      4 -- Read and clear all messages remaining in the ring buffer
17658 + *      5 -- Clear ring buffer.
17659 + *      6 -- Disable printk's to console
17660 + *      7 -- Enable printk's to console
17661 + *      8 -- Set level of messages printed to console
17662 + *      9 -- Return number of unread characters in the log buffer
17663 + *     10 -- Return size of the log buffer
17664 + */
17665 +int vx_do_syslog(int type, char __user *buf, int len)
17666 +{
17667 +       int error = 0;
17668 +       int do_clear = 0;
17669 +       struct vx_info *vxi = current_vx_info();
17670 +       struct _vx_syslog *log;
17671 +
17672 +       if (!vxi)
17673 +               return -EINVAL;
17674 +       log = &vxi->cvirt.syslog;
17675 +
17676 +       switch (type) {
17677 +       case 0:         /* Close log */
17678 +       case 1:         /* Open log */
17679 +               break;
17680 +       case 2:         /* Read from log */
17681 +               error = wait_event_interruptible(log->log_wait,
17682 +                       (log->log_start - log->log_end));
17683 +               if (error)
17684 +                       break;
17685 +               spin_lock_irq(&log->logbuf_lock);
17686 +               spin_unlock_irq(&log->logbuf_lock);
17687 +               break;
17688 +       case 4:         /* Read/clear last kernel messages */
17689 +               do_clear = 1;
17690 +               /* fall through */
17691 +       case 3:         /* Read last kernel messages */
17692 +               return 0;
17693 +
17694 +       case 5:         /* Clear ring buffer */
17695 +               return 0;
17696 +
17697 +       case 6:         /* Disable logging to console */
17698 +       case 7:         /* Enable logging to console */
17699 +       case 8:         /* Set level of messages printed to console */
17700 +               break;
17701 +
17702 +       case 9:         /* Number of chars in the log buffer */
17703 +               return 0;
17704 +       case 10:        /* Size of the log buffer */
17705 +               return 0;
17706 +       default:
17707 +               error = -EINVAL;
17708 +               break;
17709 +       }
17710 +       return error;
17711 +}
17712 +
17713 +
17714 +/* virtual host info names */
17715 +
17716 +static char *vx_vhi_name(struct vx_info *vxi, int id)
17717 +{
17718 +       struct nsproxy *nsproxy;
17719 +       struct uts_namespace *uts;
17720 +
17721 +       if (id == VHIN_CONTEXT)
17722 +               return vxi->vx_name;
17723 +
17724 +       nsproxy = vxi->space[0].vx_nsproxy;
17725 +       if (!nsproxy)
17726 +               return NULL;
17727 +
17728 +       uts = nsproxy->uts_ns;
17729 +       if (!uts)
17730 +               return NULL;
17731 +
17732 +       switch (id) {
17733 +       case VHIN_SYSNAME:
17734 +               return uts->name.sysname;
17735 +       case VHIN_NODENAME:
17736 +               return uts->name.nodename;
17737 +       case VHIN_RELEASE:
17738 +               return uts->name.release;
17739 +       case VHIN_VERSION:
17740 +               return uts->name.version;
17741 +       case VHIN_MACHINE:
17742 +               return uts->name.machine;
17743 +       case VHIN_DOMAINNAME:
17744 +               return uts->name.domainname;
17745 +       default:
17746 +               return NULL;
17747 +       }
17748 +       return NULL;
17749 +}
17750 +
17751 +int vc_set_vhi_name(struct vx_info *vxi, void __user *data)
17752 +{
17753 +       struct vcmd_vhi_name_v0 vc_data;
17754 +       char *name;
17755 +
17756 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17757 +               return -EFAULT;
17758 +
17759 +       name = vx_vhi_name(vxi, vc_data.field);
17760 +       if (!name)
17761 +               return -EINVAL;
17762 +
17763 +       memcpy(name, vc_data.name, 65);
17764 +       return 0;
17765 +}
17766 +
17767 +int vc_get_vhi_name(struct vx_info *vxi, void __user *data)
17768 +{
17769 +       struct vcmd_vhi_name_v0 vc_data;
17770 +       char *name;
17771 +
17772 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17773 +               return -EFAULT;
17774 +
17775 +       name = vx_vhi_name(vxi, vc_data.field);
17776 +       if (!name)
17777 +               return -EINVAL;
17778 +
17779 +       memcpy(vc_data.name, name, 65);
17780 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
17781 +               return -EFAULT;
17782 +       return 0;
17783 +}
17784 +
17785 +
17786 +int vc_virt_stat(struct vx_info *vxi, void __user *data)
17787 +{
17788 +       struct vcmd_virt_stat_v0 vc_data;
17789 +       struct _vx_cvirt *cvirt = &vxi->cvirt;
17790 +       struct timespec uptime;
17791 +
17792 +       do_posix_clock_monotonic_gettime(&uptime);
17793 +       set_normalized_timespec(&uptime,
17794 +               uptime.tv_sec - cvirt->bias_uptime.tv_sec,
17795 +               uptime.tv_nsec - cvirt->bias_uptime.tv_nsec);
17796 +
17797 +       vc_data.offset = timespec_to_ns(&cvirt->bias_ts);
17798 +       vc_data.uptime = timespec_to_ns(&uptime);
17799 +       vc_data.nr_threads = atomic_read(&cvirt->nr_threads);
17800 +       vc_data.nr_running = atomic_read(&cvirt->nr_running);
17801 +       vc_data.nr_uninterruptible = atomic_read(&cvirt->nr_uninterruptible);
17802 +       vc_data.nr_onhold = atomic_read(&cvirt->nr_onhold);
17803 +       vc_data.nr_forks = atomic_read(&cvirt->total_forks);
17804 +       vc_data.load[0] = cvirt->load[0];
17805 +       vc_data.load[1] = cvirt->load[1];
17806 +       vc_data.load[2] = cvirt->load[2];
17807 +
17808 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
17809 +               return -EFAULT;
17810 +       return 0;
17811 +}
17812 +
17813 +
17814 +#ifdef CONFIG_VSERVER_VTIME
17815 +
17816 +/* virtualized time base */
17817 +
17818 +void vx_adjust_timespec(struct timespec *ts)
17819 +{
17820 +       struct vx_info *vxi;
17821 +
17822 +       if (!vx_flags(VXF_VIRT_TIME, 0))
17823 +               return;
17824 +
17825 +       vxi = current_vx_info();
17826 +       ts->tv_sec += vxi->cvirt.bias_ts.tv_sec;
17827 +       ts->tv_nsec += vxi->cvirt.bias_ts.tv_nsec;
17828 +
17829 +       if (ts->tv_nsec >= NSEC_PER_SEC) {
17830 +               ts->tv_sec++;
17831 +               ts->tv_nsec -= NSEC_PER_SEC;
17832 +       } else if (ts->tv_nsec < 0) {
17833 +               ts->tv_sec--;
17834 +               ts->tv_nsec += NSEC_PER_SEC;
17835 +       }
17836 +}
17837 +
17838 +int vx_settimeofday(struct timespec *ts)
17839 +{
17840 +       struct timespec ats, delta;
17841 +       struct vx_info *vxi;
17842 +
17843 +       if (!vx_flags(VXF_VIRT_TIME, 0))
17844 +               return do_settimeofday(ts);
17845 +
17846 +       getnstimeofday(&ats);
17847 +       delta = timespec_sub(*ts, ats);
17848 +
17849 +       vxi = current_vx_info();
17850 +       vxi->cvirt.bias_ts = timespec_add(vxi->cvirt.bias_ts, delta);
17851 +       return 0;
17852 +}
17853 +
17854 +#endif
17855 +
17856 diff -NurpP --minimal linux-2.6.38-rc8/kernel/vserver/cvirt_init.h linux-2.6.38-rc8-vs2.3.0.37-rc6/kernel/vserver/cvirt_init.h
17857 --- linux-2.6.38-rc8/kernel/vserver/cvirt_init.h        1970-01-01 01:00:00.000000000 +0100
17858 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/kernel/vserver/cvirt_init.h 2011-01-29 02:01:07.000000000 +0100
17859 @@ -0,0 +1,69 @@
17860 +
17861 +
17862 +extern uint64_t vx_idle_jiffies(void);
17863 +
17864 +static inline void vx_info_init_cvirt(struct _vx_cvirt *cvirt)
17865 +{
17866 +       uint64_t idle_jiffies = vx_idle_jiffies();
17867 +       uint64_t nsuptime;
17868 +
17869 +       do_posix_clock_monotonic_gettime(&cvirt->bias_uptime);
17870 +       nsuptime = (unsigned long long)cvirt->bias_uptime.tv_sec
17871 +               * NSEC_PER_SEC + cvirt->bias_uptime.tv_nsec;
17872 +       cvirt->bias_clock = nsec_to_clock_t(nsuptime);
17873 +       cvirt->bias_ts.tv_sec = 0;
17874 +       cvirt->bias_ts.tv_nsec = 0;
17875 +
17876 +       jiffies_to_timespec(idle_jiffies, &cvirt->bias_idle);
17877 +       atomic_set(&cvirt->nr_threads, 0);
17878 +       atomic_set(&cvirt->nr_running, 0);
17879 +       atomic_set(&cvirt->nr_uninterruptible, 0);
17880 +       atomic_set(&cvirt->nr_onhold, 0);
17881 +
17882 +       spin_lock_init(&cvirt->load_lock);
17883 +       cvirt->load_last = jiffies;
17884 +       atomic_set(&cvirt->load_updates, 0);
17885 +       cvirt->load[0] = 0;
17886 +       cvirt->load[1] = 0;
17887 +       cvirt->load[2] = 0;
17888 +       atomic_set(&cvirt->total_forks, 0);
17889 +
17890 +       spin_lock_init(&cvirt->syslog.logbuf_lock);
17891 +       init_waitqueue_head(&cvirt->syslog.log_wait);
17892 +       cvirt->syslog.log_start = 0;
17893 +       cvirt->syslog.log_end = 0;
17894 +       cvirt->syslog.con_start = 0;
17895 +       cvirt->syslog.logged_chars = 0;
17896 +}
17897 +
17898 +static inline
17899 +void vx_info_init_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc, int cpu)
17900 +{
17901 +       // cvirt_pc->cpustat = { 0 };
17902 +}
17903 +
17904 +static inline void vx_info_exit_cvirt(struct _vx_cvirt *cvirt)
17905 +{
17906 +       int value;
17907 +
17908 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_threads)),
17909 +               "!!! cvirt: %p[nr_threads] = %d on exit.",
17910 +               cvirt, value);
17911 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_running)),
17912 +               "!!! cvirt: %p[nr_running] = %d on exit.",
17913 +               cvirt, value);
17914 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_uninterruptible)),
17915 +               "!!! cvirt: %p[nr_uninterruptible] = %d on exit.",
17916 +               cvirt, value);
17917 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_onhold)),
17918 +               "!!! cvirt: %p[nr_onhold] = %d on exit.",
17919 +               cvirt, value);
17920 +       return;
17921 +}
17922 +
17923 +static inline
17924 +void vx_info_exit_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc, int cpu)
17925 +{
17926 +       return;
17927 +}
17928 +
17929 diff -NurpP --minimal linux-2.6.38-rc8/kernel/vserver/cvirt_proc.h linux-2.6.38-rc8-vs2.3.0.37-rc6/kernel/vserver/cvirt_proc.h
17930 --- linux-2.6.38-rc8/kernel/vserver/cvirt_proc.h        1970-01-01 01:00:00.000000000 +0100
17931 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/kernel/vserver/cvirt_proc.h 2011-01-29 02:01:07.000000000 +0100
17932 @@ -0,0 +1,135 @@
17933 +#ifndef _VX_CVIRT_PROC_H
17934 +#define _VX_CVIRT_PROC_H
17935 +
17936 +#include <linux/nsproxy.h>
17937 +#include <linux/mnt_namespace.h>
17938 +#include <linux/ipc_namespace.h>
17939 +#include <linux/utsname.h>
17940 +#include <linux/ipc.h>
17941 +
17942 +
17943 +static inline
17944 +int vx_info_proc_nsproxy(struct nsproxy *nsproxy, char *buffer)
17945 +{
17946 +       struct mnt_namespace *ns;
17947 +       struct uts_namespace *uts;
17948 +       struct ipc_namespace *ipc;
17949 +       struct path path;
17950 +       char *pstr, *root;
17951 +       int length = 0;
17952 +
17953 +       if (!nsproxy)
17954 +               goto out;
17955 +
17956 +       length += sprintf(buffer + length,
17957 +               "NSProxy:\t%p [%p,%p,%p]\n",
17958 +               nsproxy, nsproxy->mnt_ns,
17959 +               nsproxy->uts_ns, nsproxy->ipc_ns);
17960 +
17961 +       ns = nsproxy->mnt_ns;
17962 +       if (!ns)
17963 +               goto skip_ns;
17964 +
17965 +       pstr = kmalloc(PATH_MAX, GFP_KERNEL);
17966 +       if (!pstr)
17967 +               goto skip_ns;
17968 +
17969 +       path.mnt = ns->root;
17970 +       path.dentry = ns->root->mnt_root;
17971 +       root = d_path(&path, pstr, PATH_MAX - 2);
17972 +       length += sprintf(buffer + length,
17973 +               "Namespace:\t%p [#%u]\n"
17974 +               "RootPath:\t%s\n",
17975 +               ns, atomic_read(&ns->count),
17976 +               root);
17977 +       kfree(pstr);
17978 +skip_ns:
17979 +
17980 +       uts = nsproxy->uts_ns;
17981 +       if (!uts)
17982 +               goto skip_uts;
17983 +
17984 +       length += sprintf(buffer + length,
17985 +               "SysName:\t%.*s\n"
17986 +               "NodeName:\t%.*s\n"
17987 +               "Release:\t%.*s\n"
17988 +               "Version:\t%.*s\n"
17989 +               "Machine:\t%.*s\n"
17990 +               "DomainName:\t%.*s\n",
17991 +               __NEW_UTS_LEN, uts->name.sysname,
17992 +               __NEW_UTS_LEN, uts->name.nodename,
17993 +               __NEW_UTS_LEN, uts->name.release,
17994 +               __NEW_UTS_LEN, uts->name.version,
17995 +               __NEW_UTS_LEN, uts->name.machine,
17996 +               __NEW_UTS_LEN, uts->name.domainname);
17997 +skip_uts:
17998 +
17999 +       ipc = nsproxy->ipc_ns;
18000 +       if (!ipc)
18001 +               goto skip_ipc;
18002 +
18003 +       length += sprintf(buffer + length,
18004 +               "SEMS:\t\t%d %d %d %d  %d\n"
18005 +               "MSG:\t\t%d %d %d\n"
18006 +               "SHM:\t\t%lu %lu  %d %d\n",
18007 +               ipc->sem_ctls[0], ipc->sem_ctls[1],
18008 +               ipc->sem_ctls[2], ipc->sem_ctls[3],
18009 +               ipc->used_sems,
18010 +               ipc->msg_ctlmax, ipc->msg_ctlmnb, ipc->msg_ctlmni,
18011 +               (unsigned long)ipc->shm_ctlmax,
18012 +               (unsigned long)ipc->shm_ctlall,
18013 +               ipc->shm_ctlmni, ipc->shm_tot);
18014 +skip_ipc:
18015 +out:
18016 +       return length;
18017 +}
18018 +
18019 +
18020 +#include <linux/sched.h>
18021 +
18022 +#define LOAD_INT(x) ((x) >> FSHIFT)
18023 +#define LOAD_FRAC(x) LOAD_INT(((x) & (FIXED_1 - 1)) * 100)
18024 +
18025 +static inline
18026 +int vx_info_proc_cvirt(struct _vx_cvirt *cvirt, char *buffer)
18027 +{
18028 +       int length = 0;
18029 +       int a, b, c;
18030 +
18031 +       length += sprintf(buffer + length,
18032 +               "BiasUptime:\t%lu.%02lu\n",
18033 +               (unsigned long)cvirt->bias_uptime.tv_sec,
18034 +               (cvirt->bias_uptime.tv_nsec / (NSEC_PER_SEC / 100)));
18035 +
18036 +       a = cvirt->load[0] + (FIXED_1 / 200);
18037 +       b = cvirt->load[1] + (FIXED_1 / 200);
18038 +       c = cvirt->load[2] + (FIXED_1 / 200);
18039 +       length += sprintf(buffer + length,
18040 +               "nr_threads:\t%d\n"
18041 +               "nr_running:\t%d\n"
18042 +               "nr_unintr:\t%d\n"
18043 +               "nr_onhold:\t%d\n"
18044 +               "load_updates:\t%d\n"
18045 +               "loadavg:\t%d.%02d %d.%02d %d.%02d\n"
18046 +               "total_forks:\t%d\n",
18047 +               atomic_read(&cvirt->nr_threads),
18048 +               atomic_read(&cvirt->nr_running),
18049 +               atomic_read(&cvirt->nr_uninterruptible),
18050 +               atomic_read(&cvirt->nr_onhold),
18051 +               atomic_read(&cvirt->load_updates),
18052 +               LOAD_INT(a), LOAD_FRAC(a),
18053 +               LOAD_INT(b), LOAD_FRAC(b),
18054 +               LOAD_INT(c), LOAD_FRAC(c),
18055 +               atomic_read(&cvirt->total_forks));
18056 +       return length;
18057 +}
18058 +
18059 +static inline
18060 +int vx_info_proc_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc,
18061 +       char *buffer, int cpu)
18062 +{
18063 +       int length = 0;
18064 +       return length;
18065 +}
18066 +
18067 +#endif /* _VX_CVIRT_PROC_H */
18068 diff -NurpP --minimal linux-2.6.38-rc8/kernel/vserver/debug.c linux-2.6.38-rc8-vs2.3.0.37-rc6/kernel/vserver/debug.c
18069 --- linux-2.6.38-rc8/kernel/vserver/debug.c     1970-01-01 01:00:00.000000000 +0100
18070 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/kernel/vserver/debug.c      2011-01-29 02:01:07.000000000 +0100
18071 @@ -0,0 +1,32 @@
18072 +/*
18073 + *  kernel/vserver/debug.c
18074 + *
18075 + *  Copyright (C) 2005-2007 Herbert Pötzl
18076 + *
18077 + *  V0.01  vx_info dump support
18078 + *
18079 + */
18080 +
18081 +#include <linux/module.h>
18082 +
18083 +#include <linux/vserver/context.h>
18084 +
18085 +
18086 +void   dump_vx_info(struct vx_info *vxi, int level)
18087 +{
18088 +       printk("vx_info %p[#%d, %d.%d, %4x]\n", vxi, vxi->vx_id,
18089 +               atomic_read(&vxi->vx_usecnt),
18090 +               atomic_read(&vxi->vx_tasks),
18091 +               vxi->vx_state);
18092 +       if (level > 0) {
18093 +               __dump_vx_limit(&vxi->limit);
18094 +               __dump_vx_sched(&vxi->sched);
18095 +               __dump_vx_cvirt(&vxi->cvirt);
18096 +               __dump_vx_cacct(&vxi->cacct);
18097 +       }
18098 +       printk("---\n");
18099 +}
18100 +
18101 +
18102 +EXPORT_SYMBOL_GPL(dump_vx_info);
18103 +
18104 diff -NurpP --minimal linux-2.6.38-rc8/kernel/vserver/device.c linux-2.6.38-rc8-vs2.3.0.37-rc6/kernel/vserver/device.c
18105 --- linux-2.6.38-rc8/kernel/vserver/device.c    1970-01-01 01:00:00.000000000 +0100
18106 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/kernel/vserver/device.c     2011-01-29 02:01:07.000000000 +0100
18107 @@ -0,0 +1,443 @@
18108 +/*
18109 + *  linux/kernel/vserver/device.c
18110 + *
18111 + *  Linux-VServer: Device Support
18112 + *
18113 + *  Copyright (C) 2006  Herbert Pötzl
18114 + *  Copyright (C) 2007  Daniel Hokka Zakrisson
18115 + *
18116 + *  V0.01  device mapping basics
18117 + *  V0.02  added defaults
18118 + *
18119 + */
18120 +
18121 +#include <linux/slab.h>
18122 +#include <linux/rcupdate.h>
18123 +#include <linux/fs.h>
18124 +#include <linux/namei.h>
18125 +#include <linux/hash.h>
18126 +
18127 +#include <asm/errno.h>
18128 +#include <asm/uaccess.h>
18129 +#include <linux/vserver/base.h>
18130 +#include <linux/vserver/debug.h>
18131 +#include <linux/vserver/context.h>
18132 +#include <linux/vserver/device.h>
18133 +#include <linux/vserver/device_cmd.h>
18134 +
18135 +
18136 +#define DMAP_HASH_BITS 4
18137 +
18138 +
18139 +struct vs_mapping {
18140 +       union {
18141 +               struct hlist_node hlist;
18142 +               struct list_head list;
18143 +       } u;
18144 +#define dm_hlist       u.hlist
18145 +#define dm_list                u.list
18146 +       xid_t xid;
18147 +       dev_t device;
18148 +       struct vx_dmap_target target;
18149 +};
18150 +
18151 +
18152 +static struct hlist_head dmap_main_hash[1 << DMAP_HASH_BITS];
18153 +
18154 +static spinlock_t dmap_main_hash_lock = SPIN_LOCK_UNLOCKED;
18155 +
18156 +static struct vx_dmap_target dmap_defaults[2] = {
18157 +       { .flags = DATTR_OPEN },
18158 +       { .flags = DATTR_OPEN },
18159 +};
18160 +
18161 +
18162 +struct kmem_cache *dmap_cachep __read_mostly;
18163 +
18164 +int __init dmap_cache_init(void)
18165 +{
18166 +       dmap_cachep = kmem_cache_create("dmap_cache",
18167 +               sizeof(struct vs_mapping), 0,
18168 +               SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
18169 +       return 0;
18170 +}
18171 +
18172 +__initcall(dmap_cache_init);
18173 +
18174 +
18175 +static inline unsigned int __hashval(dev_t dev, int bits)
18176 +{
18177 +       return hash_long((unsigned long)dev, bits);
18178 +}
18179 +
18180 +
18181 +/*     __hash_mapping()
18182 + *     add the mapping to the hash table
18183 + */
18184 +static inline void __hash_mapping(struct vx_info *vxi, struct vs_mapping *vdm)
18185 +{
18186 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
18187 +       struct hlist_head *head, *hash = dmap_main_hash;
18188 +       int device = vdm->device;
18189 +
18190 +       spin_lock(hash_lock);
18191 +       vxdprintk(VXD_CBIT(misc, 8), "__hash_mapping: %p[#%d] %08x:%08x",
18192 +               vxi, vxi ? vxi->vx_id : 0, device, vdm->target.target);
18193 +
18194 +       head = &hash[__hashval(device, DMAP_HASH_BITS)];
18195 +       hlist_add_head(&vdm->dm_hlist, head);
18196 +       spin_unlock(hash_lock);
18197 +}
18198 +
18199 +
18200 +static inline int __mode_to_default(umode_t mode)
18201 +{
18202 +       switch (mode) {
18203 +       case S_IFBLK:
18204 +               return 0;
18205 +       case S_IFCHR:
18206 +               return 1;
18207 +       default:
18208 +               BUG();
18209 +       }
18210 +}
18211 +
18212 +
18213 +/*     __set_default()
18214 + *     set a default
18215 + */
18216 +static inline void __set_default(struct vx_info *vxi, umode_t mode,
18217 +       struct vx_dmap_target *vdmt)
18218 +{
18219 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
18220 +       spin_lock(hash_lock);
18221 +
18222 +       if (vxi)
18223 +               vxi->dmap.targets[__mode_to_default(mode)] = *vdmt;
18224 +       else
18225 +               dmap_defaults[__mode_to_default(mode)] = *vdmt;
18226 +
18227 +
18228 +       spin_unlock(hash_lock);
18229 +
18230 +       vxdprintk(VXD_CBIT(misc, 8), "__set_default: %p[#%u] %08x %04x",
18231 +                 vxi, vxi ? vxi->vx_id : 0, vdmt->target, vdmt->flags);
18232 +}
18233 +
18234 +
18235 +/*     __remove_default()
18236 + *     remove a default
18237 + */
18238 +static inline int __remove_default(struct vx_info *vxi, umode_t mode)
18239 +{
18240 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
18241 +       spin_lock(hash_lock);
18242 +
18243 +       if (vxi)
18244 +               vxi->dmap.targets[__mode_to_default(mode)].flags = 0;
18245 +       else    /* remove == reset */
18246 +               dmap_defaults[__mode_to_default(mode)].flags = DATTR_OPEN | mode;
18247 +
18248 +       spin_unlock(hash_lock);
18249 +       return 0;
18250 +}
18251 +
18252 +
18253 +/*     __find_mapping()
18254 + *     find a mapping in the hash table
18255 + *
18256 + *     caller must hold hash_lock
18257 + */
18258 +static inline int __find_mapping(xid_t xid, dev_t device, umode_t mode,
18259 +       struct vs_mapping **local, struct vs_mapping **global)
18260 +{
18261 +       struct hlist_head *hash = dmap_main_hash;
18262 +       struct hlist_head *head = &hash[__hashval(device, DMAP_HASH_BITS)];
18263 +       struct hlist_node *pos;
18264 +       struct vs_mapping *vdm;
18265 +
18266 +       *local = NULL;
18267 +       if (global)
18268 +               *global = NULL;
18269 +
18270 +       hlist_for_each(pos, head) {
18271 +               vdm = hlist_entry(pos, struct vs_mapping, dm_hlist);
18272 +
18273 +               if ((vdm->device == device) &&
18274 +                       !((vdm->target.flags ^ mode) & S_IFMT)) {
18275 +                       if (vdm->xid == xid) {
18276 +                               *local = vdm;
18277 +                               return 1;
18278 +                       } else if (global && vdm->xid == 0)
18279 +                               *global = vdm;
18280 +               }
18281 +       }
18282 +
18283 +       if (global && *global)
18284 +               return 0;
18285 +       else
18286 +               return -ENOENT;
18287 +}
18288 +
18289 +
18290 +/*     __lookup_mapping()
18291 + *     find a mapping and store the result in target and flags
18292 + */
18293 +static inline int __lookup_mapping(struct vx_info *vxi,
18294 +       dev_t device, dev_t *target, int *flags, umode_t mode)
18295 +{
18296 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
18297 +       struct vs_mapping *vdm, *global;
18298 +       struct vx_dmap_target *vdmt;
18299 +       int ret = 0;
18300 +       xid_t xid = vxi->vx_id;
18301 +       int index;
18302 +
18303 +       spin_lock(hash_lock);
18304 +       if (__find_mapping(xid, device, mode, &vdm, &global) > 0) {
18305 +               ret = 1;
18306 +               vdmt = &vdm->target;
18307 +               goto found;
18308 +       }
18309 +
18310 +       index = __mode_to_default(mode);
18311 +       if (vxi && vxi->dmap.targets[index].flags) {
18312 +               ret = 2;
18313 +               vdmt = &vxi->dmap.targets[index];
18314 +       } else if (global) {
18315 +               ret = 3;
18316 +               vdmt = &global->target;
18317 +               goto found;
18318 +       } else {
18319 +               ret = 4;
18320 +               vdmt = &dmap_defaults[index];
18321 +       }
18322 +
18323 +found:
18324 +       if (target && (vdmt->flags & DATTR_REMAP))
18325 +               *target = vdmt->target;
18326 +       else if (target)
18327 +               *target = device;
18328 +       if (flags)
18329 +               *flags = vdmt->flags;
18330 +
18331 +       spin_unlock(hash_lock);
18332 +
18333 +       return ret;
18334 +}
18335 +
18336 +
18337 +/*     __remove_mapping()
18338 + *     remove a mapping from the hash table
18339 + */
18340 +static inline int __remove_mapping(struct vx_info *vxi, dev_t device,
18341 +       umode_t mode)
18342 +{
18343 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
18344 +       struct vs_mapping *vdm = NULL;
18345 +       int ret = 0;
18346 +
18347 +       spin_lock(hash_lock);
18348 +
18349 +       ret = __find_mapping((vxi ? vxi->vx_id : 0), device, mode, &vdm,
18350 +               NULL);
18351 +       vxdprintk(VXD_CBIT(misc, 8), "__remove_mapping: %p[#%d] %08x %04x",
18352 +               vxi, vxi ? vxi->vx_id : 0, device, mode);
18353 +       if (ret < 0)
18354 +               goto out;
18355 +       hlist_del(&vdm->dm_hlist);
18356 +
18357 +out:
18358 +       spin_unlock(hash_lock);
18359 +       if (vdm)
18360 +               kmem_cache_free(dmap_cachep, vdm);
18361 +       return ret;
18362 +}
18363 +
18364 +
18365 +
18366 +int vs_map_device(struct vx_info *vxi,
18367 +       dev_t device, dev_t *target, umode_t mode)
18368 +{
18369 +       int ret, flags = DATTR_MASK;
18370 +
18371 +       if (!vxi) {
18372 +               if (target)
18373 +                       *target = device;
18374 +               goto out;
18375 +       }
18376 +       ret = __lookup_mapping(vxi, device, target, &flags, mode);
18377 +       vxdprintk(VXD_CBIT(misc, 8), "vs_map_device: %08x target: %08x flags: %04x mode: %04x mapped=%d",
18378 +               device, target ? *target : 0, flags, mode, ret);
18379 +out:
18380 +       return (flags & DATTR_MASK);
18381 +}
18382 +
18383 +
18384 +
18385 +static int do_set_mapping(struct vx_info *vxi,
18386 +       dev_t device, dev_t target, int flags, umode_t mode)
18387 +{
18388 +       if (device) {
18389 +               struct vs_mapping *new;
18390 +
18391 +               new = kmem_cache_alloc(dmap_cachep, GFP_KERNEL);
18392 +               if (!new)
18393 +                       return -ENOMEM;
18394 +
18395 +               INIT_HLIST_NODE(&new->dm_hlist);
18396 +               new->device = device;
18397 +               new->target.target = target;
18398 +               new->target.flags = flags | mode;
18399 +               new->xid = (vxi ? vxi->vx_id : 0);
18400 +
18401 +               vxdprintk(VXD_CBIT(misc, 8), "do_set_mapping: %08x target: %08x flags: %04x", device, target, flags);
18402 +               __hash_mapping(vxi, new);
18403 +       } else {
18404 +               struct vx_dmap_target new = {
18405 +                       .target = target,
18406 +                       .flags = flags | mode,
18407 +               };
18408 +               __set_default(vxi, mode, &new);
18409 +       }
18410 +       return 0;
18411 +}
18412 +
18413 +
18414 +static int do_unset_mapping(struct vx_info *vxi,
18415 +       dev_t device, dev_t target, int flags, umode_t mode)
18416 +{
18417 +       int ret = -EINVAL;
18418 +
18419 +       if (device) {
18420 +               ret = __remove_mapping(vxi, device, mode);
18421 +               if (ret < 0)
18422 +                       goto out;
18423 +       } else {
18424 +               ret = __remove_default(vxi, mode);
18425 +               if (ret < 0)
18426 +                       goto out;
18427 +       }
18428 +
18429 +out:
18430 +       return ret;
18431 +}
18432 +
18433 +
18434 +static inline int __user_device(const char __user *name, dev_t *dev,
18435 +       umode_t *mode)
18436 +{
18437 +       struct nameidata nd;
18438 +       int ret;
18439 +
18440 +       if (!name) {
18441 +               *dev = 0;
18442 +               return 0;
18443 +       }
18444 +       ret = user_lpath(name, &nd.path);
18445 +       if (ret)
18446 +               return ret;
18447 +       if (nd.path.dentry->d_inode) {
18448 +               *dev = nd.path.dentry->d_inode->i_rdev;
18449 +               *mode = nd.path.dentry->d_inode->i_mode;
18450 +       }
18451 +       path_put(&nd.path);
18452 +       return 0;
18453 +}
18454 +
18455 +static inline int __mapping_mode(dev_t device, dev_t target,
18456 +       umode_t device_mode, umode_t target_mode, umode_t *mode)
18457 +{
18458 +       if (device)
18459 +               *mode = device_mode & S_IFMT;
18460 +       else if (target)
18461 +               *mode = target_mode & S_IFMT;
18462 +       else
18463 +               return -EINVAL;
18464 +
18465 +       /* if both given, device and target mode have to match */
18466 +       if (device && target &&
18467 +               ((device_mode ^ target_mode) & S_IFMT))
18468 +               return -EINVAL;
18469 +       return 0;
18470 +}
18471 +
18472 +
18473 +static inline int do_mapping(struct vx_info *vxi, const char __user *device_path,
18474 +       const char __user *target_path, int flags, int set)
18475 +{
18476 +       dev_t device = ~0, target = ~0;
18477 +       umode_t device_mode = 0, target_mode = 0, mode;
18478 +       int ret;
18479 +
18480 +       ret = __user_device(device_path, &device, &device_mode);
18481 +       if (ret)
18482 +               return ret;
18483 +       ret = __user_device(target_path, &target, &target_mode);
18484 +       if (ret)
18485 +               return ret;
18486 +
18487 +       ret = __mapping_mode(device, target,
18488 +               device_mode, target_mode, &mode);
18489 +       if (ret)
18490 +               return ret;
18491 +
18492 +       if (set)
18493 +               return do_set_mapping(vxi, device, target,
18494 +                       flags, mode);
18495 +       else
18496 +               return do_unset_mapping(vxi, device, target,
18497 +                       flags, mode);
18498 +}
18499 +
18500 +
18501 +int vc_set_mapping(struct vx_info *vxi, void __user *data)
18502 +{
18503 +       struct vcmd_set_mapping_v0 vc_data;
18504 +
18505 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18506 +               return -EFAULT;
18507 +
18508 +       return do_mapping(vxi, vc_data.device, vc_data.target,
18509 +               vc_data.flags, 1);
18510 +}
18511 +
18512 +int vc_unset_mapping(struct vx_info *vxi, void __user *data)
18513 +{
18514 +       struct vcmd_set_mapping_v0 vc_data;
18515 +
18516 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18517 +               return -EFAULT;
18518 +
18519 +       return do_mapping(vxi, vc_data.device, vc_data.target,
18520 +               vc_data.flags, 0);
18521 +}
18522 +
18523 +
18524 +#ifdef CONFIG_COMPAT
18525 +
18526 +int vc_set_mapping_x32(struct vx_info *vxi, void __user *data)
18527 +{
18528 +       struct vcmd_set_mapping_v0_x32 vc_data;
18529 +
18530 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18531 +               return -EFAULT;
18532 +
18533 +       return do_mapping(vxi, compat_ptr(vc_data.device_ptr),
18534 +               compat_ptr(vc_data.target_ptr), vc_data.flags, 1);
18535 +}
18536 +
18537 +int vc_unset_mapping_x32(struct vx_info *vxi, void __user *data)
18538 +{
18539 +       struct vcmd_set_mapping_v0_x32 vc_data;
18540 +
18541 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18542 +               return -EFAULT;
18543 +
18544 +       return do_mapping(vxi, compat_ptr(vc_data.device_ptr),
18545 +               compat_ptr(vc_data.target_ptr), vc_data.flags, 0);
18546 +}
18547 +
18548 +#endif /* CONFIG_COMPAT */
18549 +
18550 +
18551 diff -NurpP --minimal linux-2.6.38-rc8/kernel/vserver/dlimit.c linux-2.6.38-rc8-vs2.3.0.37-rc6/kernel/vserver/dlimit.c
18552 --- linux-2.6.38-rc8/kernel/vserver/dlimit.c    1970-01-01 01:00:00.000000000 +0100
18553 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/kernel/vserver/dlimit.c     2011-01-29 02:01:07.000000000 +0100
18554 @@ -0,0 +1,531 @@
18555 +/*
18556 + *  linux/kernel/vserver/dlimit.c
18557 + *
18558 + *  Virtual Server: Context Disk Limits
18559 + *
18560 + *  Copyright (C) 2004-2009  Herbert Pötzl
18561 + *
18562 + *  V0.01  initial version
18563 + *  V0.02  compat32 splitup
18564 + *  V0.03  extended interface
18565 + *
18566 + */
18567 +
18568 +#include <linux/statfs.h>
18569 +#include <linux/sched.h>
18570 +#include <linux/namei.h>
18571 +#include <linux/vs_tag.h>
18572 +#include <linux/vs_dlimit.h>
18573 +#include <linux/vserver/dlimit_cmd.h>
18574 +#include <linux/slab.h>
18575 +// #include <linux/gfp.h>
18576 +
18577 +#include <asm/uaccess.h>
18578 +
18579 +/*     __alloc_dl_info()
18580 +
18581 +       * allocate an initialized dl_info struct
18582 +       * doesn't make it visible (hash)                        */
18583 +
18584 +static struct dl_info *__alloc_dl_info(struct super_block *sb, tag_t tag)
18585 +{
18586 +       struct dl_info *new = NULL;
18587 +
18588 +       vxdprintk(VXD_CBIT(dlim, 5),
18589 +               "alloc_dl_info(%p,%d)*", sb, tag);
18590 +
18591 +       /* would this benefit from a slab cache? */
18592 +       new = kmalloc(sizeof(struct dl_info), GFP_KERNEL);
18593 +       if (!new)
18594 +               return 0;
18595 +
18596 +       memset(new, 0, sizeof(struct dl_info));
18597 +       new->dl_tag = tag;
18598 +       new->dl_sb = sb;
18599 +       // INIT_RCU_HEAD(&new->dl_rcu);
18600 +       INIT_HLIST_NODE(&new->dl_hlist);
18601 +       spin_lock_init(&new->dl_lock);
18602 +       atomic_set(&new->dl_refcnt, 0);
18603 +       atomic_set(&new->dl_usecnt, 0);
18604 +
18605 +       /* rest of init goes here */
18606 +
18607 +       vxdprintk(VXD_CBIT(dlim, 4),
18608 +               "alloc_dl_info(%p,%d) = %p", sb, tag, new);
18609 +       return new;
18610 +}
18611 +
18612 +/*     __dealloc_dl_info()
18613 +
18614 +       * final disposal of dl_info                             */
18615 +
18616 +static void __dealloc_dl_info(struct dl_info *dli)
18617 +{
18618 +       vxdprintk(VXD_CBIT(dlim, 4),
18619 +               "dealloc_dl_info(%p)", dli);
18620 +
18621 +       dli->dl_hlist.next = LIST_POISON1;
18622 +       dli->dl_tag = -1;
18623 +       dli->dl_sb = 0;
18624 +
18625 +       BUG_ON(atomic_read(&dli->dl_usecnt));
18626 +       BUG_ON(atomic_read(&dli->dl_refcnt));
18627 +
18628 +       kfree(dli);
18629 +}
18630 +
18631 +
18632 +/*     hash table for dl_info hash */
18633 +
18634 +#define DL_HASH_SIZE   13
18635 +
18636 +struct hlist_head dl_info_hash[DL_HASH_SIZE];
18637 +
18638 +static spinlock_t dl_info_hash_lock = SPIN_LOCK_UNLOCKED;
18639 +
18640 +
18641 +static inline unsigned int __hashval(struct super_block *sb, tag_t tag)
18642 +{
18643 +       return ((tag ^ (unsigned long)sb) % DL_HASH_SIZE);
18644 +}
18645 +
18646 +
18647 +
18648 +/*     __hash_dl_info()
18649 +
18650 +       * add the dli to the global hash table
18651 +       * requires the hash_lock to be held                     */
18652 +
18653 +static inline void __hash_dl_info(struct dl_info *dli)
18654 +{
18655 +       struct hlist_head *head;
18656 +
18657 +       vxdprintk(VXD_CBIT(dlim, 6),
18658 +               "__hash_dl_info: %p[#%d]", dli, dli->dl_tag);
18659 +       get_dl_info(dli);
18660 +       head = &dl_info_hash[__hashval(dli->dl_sb, dli->dl_tag)];
18661 +       hlist_add_head_rcu(&dli->dl_hlist, head);
18662 +}
18663 +
18664 +/*     __unhash_dl_info()
18665 +
18666 +       * remove the dli from the global hash table
18667 +       * requires the hash_lock to be held                     */
18668 +
18669 +static inline void __unhash_dl_info(struct dl_info *dli)
18670 +{
18671 +       vxdprintk(VXD_CBIT(dlim, 6),
18672 +               "__unhash_dl_info: %p[#%d]", dli, dli->dl_tag);
18673 +       hlist_del_rcu(&dli->dl_hlist);
18674 +       put_dl_info(dli);
18675 +}
18676 +
18677 +
18678 +/*     __lookup_dl_info()
18679 +
18680 +       * requires the rcu_read_lock()
18681 +       * doesn't increment the dl_refcnt                       */
18682 +
18683 +static inline struct dl_info *__lookup_dl_info(struct super_block *sb, tag_t tag)
18684 +{
18685 +       struct hlist_head *head = &dl_info_hash[__hashval(sb, tag)];
18686 +       struct hlist_node *pos;
18687 +       struct dl_info *dli;
18688 +
18689 +       hlist_for_each_entry_rcu(dli, pos, head, dl_hlist) {
18690 +
18691 +               if (dli->dl_tag == tag && dli->dl_sb == sb) {
18692 +                       return dli;
18693 +               }
18694 +       }
18695 +       return NULL;
18696 +}
18697 +
18698 +
18699 +struct dl_info *locate_dl_info(struct super_block *sb, tag_t tag)
18700 +{
18701 +       struct dl_info *dli;
18702 +
18703 +       rcu_read_lock();
18704 +       dli = get_dl_info(__lookup_dl_info(sb, tag));
18705 +       vxdprintk(VXD_CBIT(dlim, 7),
18706 +               "locate_dl_info(%p,#%d) = %p", sb, tag, dli);
18707 +       rcu_read_unlock();
18708 +       return dli;
18709 +}
18710 +
18711 +void rcu_free_dl_info(struct rcu_head *head)
18712 +{
18713 +       struct dl_info *dli = container_of(head, struct dl_info, dl_rcu);
18714 +       int usecnt, refcnt;
18715 +
18716 +       BUG_ON(!dli || !head);
18717 +
18718 +       usecnt = atomic_read(&dli->dl_usecnt);
18719 +       BUG_ON(usecnt < 0);
18720 +
18721 +       refcnt = atomic_read(&dli->dl_refcnt);
18722 +       BUG_ON(refcnt < 0);
18723 +
18724 +       vxdprintk(VXD_CBIT(dlim, 3),
18725 +               "rcu_free_dl_info(%p)", dli);
18726 +       if (!usecnt)
18727 +               __dealloc_dl_info(dli);
18728 +       else
18729 +               printk("!!! rcu didn't free\n");
18730 +}
18731 +
18732 +
18733 +
18734 +
18735 +static int do_addrem_dlimit(uint32_t id, const char __user *name,
18736 +       uint32_t flags, int add)
18737 +{
18738 +       struct path path;
18739 +       int ret;
18740 +
18741 +       ret = user_lpath(name, &path);
18742 +       if (!ret) {
18743 +               struct super_block *sb;
18744 +               struct dl_info *dli;
18745 +
18746 +               ret = -EINVAL;
18747 +               if (!path.dentry->d_inode)
18748 +                       goto out_release;
18749 +               if (!(sb = path.dentry->d_inode->i_sb))
18750 +                       goto out_release;
18751 +
18752 +               if (add) {
18753 +                       dli = __alloc_dl_info(sb, id);
18754 +                       spin_lock(&dl_info_hash_lock);
18755 +
18756 +                       ret = -EEXIST;
18757 +                       if (__lookup_dl_info(sb, id))
18758 +                               goto out_unlock;
18759 +                       __hash_dl_info(dli);
18760 +                       dli = NULL;
18761 +               } else {
18762 +                       spin_lock(&dl_info_hash_lock);
18763 +                       dli = __lookup_dl_info(sb, id);
18764 +
18765 +                       ret = -ESRCH;
18766 +                       if (!dli)
18767 +                               goto out_unlock;
18768 +                       __unhash_dl_info(dli);
18769 +               }
18770 +               ret = 0;
18771 +       out_unlock:
18772 +               spin_unlock(&dl_info_hash_lock);
18773 +               if (add && dli)
18774 +                       __dealloc_dl_info(dli);
18775 +       out_release:
18776 +               path_put(&path);
18777 +       }
18778 +       return ret;
18779 +}
18780 +
18781 +int vc_add_dlimit(uint32_t id, void __user *data)
18782 +{
18783 +       struct vcmd_ctx_dlimit_base_v0 vc_data;
18784 +
18785 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18786 +               return -EFAULT;
18787 +
18788 +       return do_addrem_dlimit(id, vc_data.name, vc_data.flags, 1);
18789 +}
18790 +
18791 +int vc_rem_dlimit(uint32_t id, void __user *data)
18792 +{
18793 +       struct vcmd_ctx_dlimit_base_v0 vc_data;
18794 +
18795 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18796 +               return -EFAULT;
18797 +
18798 +       return do_addrem_dlimit(id, vc_data.name, vc_data.flags, 0);
18799 +}
18800 +
18801 +#ifdef CONFIG_COMPAT
18802 +
18803 +int vc_add_dlimit_x32(uint32_t id, void __user *data)
18804 +{
18805 +       struct vcmd_ctx_dlimit_base_v0_x32 vc_data;
18806 +
18807 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18808 +               return -EFAULT;
18809 +
18810 +       return do_addrem_dlimit(id,
18811 +               compat_ptr(vc_data.name_ptr), vc_data.flags, 1);
18812 +}
18813 +
18814 +int vc_rem_dlimit_x32(uint32_t id, void __user *data)
18815 +{
18816 +       struct vcmd_ctx_dlimit_base_v0_x32 vc_data;
18817 +
18818 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18819 +               return -EFAULT;
18820 +
18821 +       return do_addrem_dlimit(id,
18822 +               compat_ptr(vc_data.name_ptr), vc_data.flags, 0);
18823 +}
18824 +
18825 +#endif /* CONFIG_COMPAT */
18826 +
18827 +
18828 +static inline
18829 +int do_set_dlimit(uint32_t id, const char __user *name,
18830 +       uint32_t space_used, uint32_t space_total,
18831 +       uint32_t inodes_used, uint32_t inodes_total,
18832 +       uint32_t reserved, uint32_t flags)
18833 +{
18834 +       struct path path;
18835 +       int ret;
18836 +
18837 +       ret = user_lpath(name, &path);
18838 +       if (!ret) {
18839 +               struct super_block *sb;
18840 +               struct dl_info *dli;
18841 +
18842 +               ret = -EINVAL;
18843 +               if (!path.dentry->d_inode)
18844 +                       goto out_release;
18845 +               if (!(sb = path.dentry->d_inode->i_sb))
18846 +                       goto out_release;
18847 +
18848 +               /* sanity checks */
18849 +               if ((reserved != CDLIM_KEEP &&
18850 +                       reserved > 100) ||
18851 +                       (inodes_used != CDLIM_KEEP &&
18852 +                       inodes_used > inodes_total) ||
18853 +                       (space_used != CDLIM_KEEP &&
18854 +                       space_used > space_total))
18855 +                       goto out_release;
18856 +
18857 +               ret = -ESRCH;
18858 +               dli = locate_dl_info(sb, id);
18859 +               if (!dli)
18860 +                       goto out_release;
18861 +
18862 +               spin_lock(&dli->dl_lock);
18863 +
18864 +               if (inodes_used != CDLIM_KEEP)
18865 +                       dli->dl_inodes_used = inodes_used;
18866 +               if (inodes_total != CDLIM_KEEP)
18867 +                       dli->dl_inodes_total = inodes_total;
18868 +               if (space_used != CDLIM_KEEP)
18869 +                       dli->dl_space_used = dlimit_space_32to64(
18870 +                               space_used, flags, DLIMS_USED);
18871 +
18872 +               if (space_total == CDLIM_INFINITY)
18873 +                       dli->dl_space_total = DLIM_INFINITY;
18874 +               else if (space_total != CDLIM_KEEP)
18875 +                       dli->dl_space_total = dlimit_space_32to64(
18876 +                               space_total, flags, DLIMS_TOTAL);
18877 +
18878 +               if (reserved != CDLIM_KEEP)
18879 +                       dli->dl_nrlmult = (1 << 10) * (100 - reserved) / 100;
18880 +
18881 +               spin_unlock(&dli->dl_lock);
18882 +
18883 +               put_dl_info(dli);
18884 +               ret = 0;
18885 +
18886 +       out_release:
18887 +               path_put(&path);
18888 +       }
18889 +       return ret;
18890 +}
18891 +
18892 +int vc_set_dlimit(uint32_t id, void __user *data)
18893 +{
18894 +       struct vcmd_ctx_dlimit_v0 vc_data;
18895 +
18896 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18897 +               return -EFAULT;
18898 +
18899 +       return do_set_dlimit(id, vc_data.name,
18900 +               vc_data.space_used, vc_data.space_total,
18901 +               vc_data.inodes_used, vc_data.inodes_total,
18902 +               vc_data.reserved, vc_data.flags);
18903 +}
18904 +
18905 +#ifdef CONFIG_COMPAT
18906 +
18907 +int vc_set_dlimit_x32(uint32_t id, void __user *data)
18908 +{
18909 +       struct vcmd_ctx_dlimit_v0_x32 vc_data;
18910 +
18911 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18912 +               return -EFAULT;
18913 +
18914 +       return do_set_dlimit(id, compat_ptr(vc_data.name_ptr),
18915 +               vc_data.space_used, vc_data.space_total,
18916 +               vc_data.inodes_used, vc_data.inodes_total,
18917 +               vc_data.reserved, vc_data.flags);
18918 +}
18919 +
18920 +#endif /* CONFIG_COMPAT */
18921 +
18922 +
18923 +static inline
18924 +int do_get_dlimit(uint32_t id, const char __user *name,
18925 +       uint32_t *space_used, uint32_t *space_total,
18926 +       uint32_t *inodes_used, uint32_t *inodes_total,
18927 +       uint32_t *reserved, uint32_t *flags)
18928 +{
18929 +       struct path path;
18930 +       int ret;
18931 +
18932 +       ret = user_lpath(name, &path);
18933 +       if (!ret) {
18934 +               struct super_block *sb;
18935 +               struct dl_info *dli;
18936 +
18937 +               ret = -EINVAL;
18938 +               if (!path.dentry->d_inode)
18939 +                       goto out_release;
18940 +               if (!(sb = path.dentry->d_inode->i_sb))
18941 +                       goto out_release;
18942 +
18943 +               ret = -ESRCH;
18944 +               dli = locate_dl_info(sb, id);
18945 +               if (!dli)
18946 +                       goto out_release;
18947 +
18948 +               spin_lock(&dli->dl_lock);
18949 +               *inodes_used = dli->dl_inodes_used;
18950 +               *inodes_total = dli->dl_inodes_total;
18951 +
18952 +               *space_used = dlimit_space_64to32(
18953 +                       dli->dl_space_used, flags, DLIMS_USED);
18954 +
18955 +               if (dli->dl_space_total == DLIM_INFINITY)
18956 +                       *space_total = CDLIM_INFINITY;
18957 +               else
18958 +                       *space_total = dlimit_space_64to32(
18959 +                               dli->dl_space_total, flags, DLIMS_TOTAL);
18960 +
18961 +               *reserved = 100 - ((dli->dl_nrlmult * 100 + 512) >> 10);
18962 +               spin_unlock(&dli->dl_lock);
18963 +
18964 +               put_dl_info(dli);
18965 +               ret = -EFAULT;
18966 +
18967 +               ret = 0;
18968 +       out_release:
18969 +               path_put(&path);
18970 +       }
18971 +       return ret;
18972 +}
18973 +
18974 +
18975 +int vc_get_dlimit(uint32_t id, void __user *data)
18976 +{
18977 +       struct vcmd_ctx_dlimit_v0 vc_data;
18978 +       int ret;
18979 +
18980 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18981 +               return -EFAULT;
18982 +
18983 +       ret = do_get_dlimit(id, vc_data.name,
18984 +               &vc_data.space_used, &vc_data.space_total,
18985 +               &vc_data.inodes_used, &vc_data.inodes_total,
18986 +               &vc_data.reserved, &vc_data.flags);
18987 +       if (ret)
18988 +               return ret;
18989 +
18990 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18991 +               return -EFAULT;
18992 +       return 0;
18993 +}
18994 +
18995 +#ifdef CONFIG_COMPAT
18996 +
18997 +int vc_get_dlimit_x32(uint32_t id, void __user *data)
18998 +{
18999 +       struct vcmd_ctx_dlimit_v0_x32 vc_data;
19000 +       int ret;
19001 +
19002 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19003 +               return -EFAULT;
19004 +
19005 +       ret = do_get_dlimit(id, compat_ptr(vc_data.name_ptr),
19006 +               &vc_data.space_used, &vc_data.space_total,
19007 +               &vc_data.inodes_used, &vc_data.inodes_total,
19008 +               &vc_data.reserved, &vc_data.flags);
19009 +       if (ret)
19010 +               return ret;
19011 +
19012 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19013 +               return -EFAULT;
19014 +       return 0;
19015 +}
19016 +
19017 +#endif /* CONFIG_COMPAT */
19018 +
19019 +
19020 +void vx_vsi_statfs(struct super_block *sb, struct kstatfs *buf)
19021 +{
19022 +       struct dl_info *dli;
19023 +       __u64 blimit, bfree, bavail;
19024 +       __u32 ifree;
19025 +
19026 +       dli = locate_dl_info(sb, dx_current_tag());
19027 +       if (!dli)
19028 +               return;
19029 +
19030 +       spin_lock(&dli->dl_lock);
19031 +       if (dli->dl_inodes_total == (unsigned long)DLIM_INFINITY)
19032 +               goto no_ilim;
19033 +
19034 +       /* reduce max inodes available to limit */
19035 +       if (buf->f_files > dli->dl_inodes_total)
19036 +               buf->f_files = dli->dl_inodes_total;
19037 +
19038 +       ifree = dli->dl_inodes_total - dli->dl_inodes_used;
19039 +       /* reduce free inodes to min */
19040 +       if (ifree < buf->f_ffree)
19041 +               buf->f_ffree = ifree;
19042 +
19043 +no_ilim:
19044 +       if (dli->dl_space_total == DLIM_INFINITY)
19045 +               goto no_blim;
19046 +
19047 +       blimit = dli->dl_space_total >> sb->s_blocksize_bits;
19048 +
19049 +       if (dli->dl_space_total < dli->dl_space_used)
19050 +               bfree = 0;
19051 +       else
19052 +               bfree = (dli->dl_space_total - dli->dl_space_used)
19053 +                       >> sb->s_blocksize_bits;
19054 +
19055 +       bavail = ((dli->dl_space_total >> 10) * dli->dl_nrlmult);
19056 +       if (bavail < dli->dl_space_used)
19057 +               bavail = 0;
19058 +       else
19059 +               bavail = (bavail - dli->dl_space_used)
19060 +                       >> sb->s_blocksize_bits;
19061 +
19062 +       /* reduce max space available to limit */
19063 +       if (buf->f_blocks > blimit)
19064 +               buf->f_blocks = blimit;
19065 +
19066 +       /* reduce free space to min */
19067 +       if (bfree < buf->f_bfree)
19068 +               buf->f_bfree = bfree;
19069 +
19070 +       /* reduce avail space to min */
19071 +       if (bavail < buf->f_bavail)
19072 +               buf->f_bavail = bavail;
19073 +
19074 +no_blim:
19075 +       spin_unlock(&dli->dl_lock);
19076 +       put_dl_info(dli);
19077 +
19078 +       return;
19079 +}
19080 +
19081 +#include <linux/module.h>
19082 +
19083 +EXPORT_SYMBOL_GPL(locate_dl_info);
19084 +EXPORT_SYMBOL_GPL(rcu_free_dl_info);
19085 +
19086 diff -NurpP --minimal linux-2.6.38-rc8/kernel/vserver/helper.c linux-2.6.38-rc8-vs2.3.0.37-rc6/kernel/vserver/helper.c
19087 --- linux-2.6.38-rc8/kernel/vserver/helper.c    1970-01-01 01:00:00.000000000 +0100
19088 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/kernel/vserver/helper.c     2011-01-29 02:01:07.000000000 +0100
19089 @@ -0,0 +1,223 @@
19090 +/*
19091 + *  linux/kernel/vserver/helper.c
19092 + *
19093 + *  Virtual Context Support
19094 + *
19095 + *  Copyright (C) 2004-2007  Herbert Pötzl
19096 + *
19097 + *  V0.01  basic helper
19098 + *
19099 + */
19100 +
19101 +#include <linux/kmod.h>
19102 +#include <linux/reboot.h>
19103 +#include <linux/vs_context.h>
19104 +#include <linux/vs_network.h>
19105 +#include <linux/vserver/signal.h>
19106 +
19107 +
19108 +char vshelper_path[255] = "/sbin/vshelper";
19109 +
19110 +
19111 +static int do_vshelper(char *name, char *argv[], char *envp[], int sync)
19112 +{
19113 +       int ret;
19114 +
19115 +       if ((ret = call_usermodehelper(name, argv, envp, sync))) {
19116 +               printk( KERN_WARNING
19117 +                       "%s: (%s %s) returned %s with %d\n",
19118 +                       name, argv[1], argv[2],
19119 +                       sync ? "sync" : "async", ret);
19120 +       }
19121 +       vxdprintk(VXD_CBIT(switch, 4),
19122 +               "%s: (%s %s) returned %s with %d",
19123 +               name, argv[1], argv[2], sync ? "sync" : "async", ret);
19124 +       return ret;
19125 +}
19126 +
19127 +/*
19128 + *      vshelper path is set via /proc/sys
19129 + *      invoked by vserver sys_reboot(), with
19130 + *      the following arguments
19131 + *
19132 + *      argv [0] = vshelper_path;
19133 + *      argv [1] = action: "restart", "halt", "poweroff", ...
19134 + *      argv [2] = context identifier
19135 + *
19136 + *      envp [*] = type-specific parameters
19137 + */
19138 +
19139 +long vs_reboot_helper(struct vx_info *vxi, int cmd, void __user *arg)
19140 +{
19141 +       char id_buf[8], cmd_buf[16];
19142 +       char uid_buf[16], pid_buf[16];
19143 +       int ret;
19144 +
19145 +       char *argv[] = {vshelper_path, NULL, id_buf, 0};
19146 +       char *envp[] = {"HOME=/", "TERM=linux",
19147 +                       "PATH=/sbin:/usr/sbin:/bin:/usr/bin",
19148 +                       uid_buf, pid_buf, cmd_buf, 0};
19149 +
19150 +       if (vx_info_state(vxi, VXS_HELPER))
19151 +               return -EAGAIN;
19152 +       vxi->vx_state |= VXS_HELPER;
19153 +
19154 +       snprintf(id_buf, sizeof(id_buf)-1, "%d", vxi->vx_id);
19155 +
19156 +       snprintf(cmd_buf, sizeof(cmd_buf)-1, "VS_CMD=%08x", cmd);
19157 +       snprintf(uid_buf, sizeof(uid_buf)-1, "VS_UID=%d", current_uid());
19158 +       snprintf(pid_buf, sizeof(pid_buf)-1, "VS_PID=%d", current->pid);
19159 +
19160 +       switch (cmd) {
19161 +       case LINUX_REBOOT_CMD_RESTART:
19162 +               argv[1] = "restart";
19163 +               break;
19164 +
19165 +       case LINUX_REBOOT_CMD_HALT:
19166 +               argv[1] = "halt";
19167 +               break;
19168 +
19169 +       case LINUX_REBOOT_CMD_POWER_OFF:
19170 +               argv[1] = "poweroff";
19171 +               break;
19172 +
19173 +       case LINUX_REBOOT_CMD_SW_SUSPEND:
19174 +               argv[1] = "swsusp";
19175 +               break;
19176 +
19177 +       case LINUX_REBOOT_CMD_OOM:
19178 +               argv[1] = "oom";
19179 +               break;
19180 +
19181 +       default:
19182 +               vxi->vx_state &= ~VXS_HELPER;
19183 +               return 0;
19184 +       }
19185 +
19186 +       ret = do_vshelper(vshelper_path, argv, envp, 0);
19187 +       vxi->vx_state &= ~VXS_HELPER;
19188 +       __wakeup_vx_info(vxi);
19189 +       return (ret) ? -EPERM : 0;
19190 +}
19191 +
19192 +
19193 +long vs_reboot(unsigned int cmd, void __user *arg)
19194 +{
19195 +       struct vx_info *vxi = current_vx_info();
19196 +       long ret = 0;
19197 +
19198 +       vxdprintk(VXD_CBIT(misc, 5),
19199 +               "vs_reboot(%p[#%d],%u)",
19200 +               vxi, vxi ? vxi->vx_id : 0, cmd);
19201 +
19202 +       ret = vs_reboot_helper(vxi, cmd, arg);
19203 +       if (ret)
19204 +               return ret;
19205 +
19206 +       vxi->reboot_cmd = cmd;
19207 +       if (vx_info_flags(vxi, VXF_REBOOT_KILL, 0)) {
19208 +               switch (cmd) {
19209 +               case LINUX_REBOOT_CMD_RESTART:
19210 +               case LINUX_REBOOT_CMD_HALT:
19211 +               case LINUX_REBOOT_CMD_POWER_OFF:
19212 +                       vx_info_kill(vxi, 0, SIGKILL);
19213 +                       vx_info_kill(vxi, 1, SIGKILL);
19214 +               default:
19215 +                       break;
19216 +               }
19217 +       }
19218 +       return 0;
19219 +}
19220 +
19221 +long vs_oom_action(unsigned int cmd)
19222 +{
19223 +       struct vx_info *vxi = current_vx_info();
19224 +       long ret = 0;
19225 +
19226 +       vxdprintk(VXD_CBIT(misc, 5),
19227 +               "vs_oom_action(%p[#%d],%u)",
19228 +               vxi, vxi ? vxi->vx_id : 0, cmd);
19229 +
19230 +       ret = vs_reboot_helper(vxi, cmd, NULL);
19231 +       if (ret)
19232 +               return ret;
19233 +
19234 +       vxi->reboot_cmd = cmd;
19235 +       if (vx_info_flags(vxi, VXF_REBOOT_KILL, 0)) {
19236 +               vx_info_kill(vxi, 0, SIGKILL);
19237 +               vx_info_kill(vxi, 1, SIGKILL);
19238 +       }
19239 +       return 0;
19240 +}
19241 +
19242 +/*
19243 + *      argv [0] = vshelper_path;
19244 + *      argv [1] = action: "startup", "shutdown"
19245 + *      argv [2] = context identifier
19246 + *
19247 + *      envp [*] = type-specific parameters
19248 + */
19249 +
19250 +long vs_state_change(struct vx_info *vxi, unsigned int cmd)
19251 +{
19252 +       char id_buf[8], cmd_buf[16];
19253 +       char *argv[] = {vshelper_path, NULL, id_buf, 0};
19254 +       char *envp[] = {"HOME=/", "TERM=linux",
19255 +                       "PATH=/sbin:/usr/sbin:/bin:/usr/bin", cmd_buf, 0};
19256 +
19257 +       if (!vx_info_flags(vxi, VXF_SC_HELPER, 0))
19258 +               return 0;
19259 +
19260 +       snprintf(id_buf, sizeof(id_buf)-1, "%d", vxi->vx_id);
19261 +       snprintf(cmd_buf, sizeof(cmd_buf)-1, "VS_CMD=%08x", cmd);
19262 +
19263 +       switch (cmd) {
19264 +       case VSC_STARTUP:
19265 +               argv[1] = "startup";
19266 +               break;
19267 +       case VSC_SHUTDOWN:
19268 +               argv[1] = "shutdown";
19269 +               break;
19270 +       default:
19271 +               return 0;
19272 +       }
19273 +
19274 +       return do_vshelper(vshelper_path, argv, envp, 1);
19275 +}
19276 +
19277 +
19278 +/*
19279 + *      argv [0] = vshelper_path;
19280 + *      argv [1] = action: "netup", "netdown"
19281 + *      argv [2] = context identifier
19282 + *
19283 + *      envp [*] = type-specific parameters
19284 + */
19285 +
19286 +long vs_net_change(struct nx_info *nxi, unsigned int cmd)
19287 +{
19288 +       char id_buf[8], cmd_buf[16];
19289 +       char *argv[] = {vshelper_path, NULL, id_buf, 0};
19290 +       char *envp[] = {"HOME=/", "TERM=linux",
19291 +                       "PATH=/sbin:/usr/sbin:/bin:/usr/bin", cmd_buf, 0};
19292 +
19293 +       if (!nx_info_flags(nxi, NXF_SC_HELPER, 0))
19294 +               return 0;
19295 +
19296 +       snprintf(id_buf, sizeof(id_buf)-1, "%d", nxi->nx_id);
19297 +       snprintf(cmd_buf, sizeof(cmd_buf)-1, "VS_CMD=%08x", cmd);
19298 +
19299 +       switch (cmd) {
19300 +       case VSC_NETUP:
19301 +               argv[1] = "netup";
19302 +               break;
19303 +       case VSC_NETDOWN:
19304 +               argv[1] = "netdown";
19305 +               break;
19306 +       default:
19307 +               return 0;
19308 +       }
19309 +
19310 +       return do_vshelper(vshelper_path, argv, envp, 1);
19311 +}
19312 +
19313 diff -NurpP --minimal linux-2.6.38-rc8/kernel/vserver/history.c linux-2.6.38-rc8-vs2.3.0.37-rc6/kernel/vserver/history.c
19314 --- linux-2.6.38-rc8/kernel/vserver/history.c   1970-01-01 01:00:00.000000000 +0100
19315 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/kernel/vserver/history.c    2011-01-29 02:01:07.000000000 +0100
19316 @@ -0,0 +1,258 @@
19317 +/*
19318 + *  kernel/vserver/history.c
19319 + *
19320 + *  Virtual Context History Backtrace
19321 + *
19322 + *  Copyright (C) 2004-2007  Herbert Pötzl
19323 + *
19324 + *  V0.01  basic structure
19325 + *  V0.02  hash/unhash and trace
19326 + *  V0.03  preemption fixes
19327 + *
19328 + */
19329 +
19330 +#include <linux/module.h>
19331 +#include <asm/uaccess.h>
19332 +
19333 +#include <linux/vserver/context.h>
19334 +#include <linux/vserver/debug.h>
19335 +#include <linux/vserver/debug_cmd.h>
19336 +#include <linux/vserver/history.h>
19337 +
19338 +
19339 +#ifdef CONFIG_VSERVER_HISTORY
19340 +#define VXH_SIZE       CONFIG_VSERVER_HISTORY_SIZE
19341 +#else
19342 +#define VXH_SIZE       64
19343 +#endif
19344 +
19345 +struct _vx_history {
19346 +       unsigned int counter;
19347 +
19348 +       struct _vx_hist_entry entry[VXH_SIZE + 1];
19349 +};
19350 +
19351 +
19352 +DEFINE_PER_CPU(struct _vx_history, vx_history_buffer);
19353 +
19354 +unsigned volatile int vxh_active = 1;
19355 +
19356 +static atomic_t sequence = ATOMIC_INIT(0);
19357 +
19358 +
19359 +/*     vxh_advance()
19360 +
19361 +       * requires disabled preemption                          */
19362 +
19363 +struct _vx_hist_entry *vxh_advance(void *loc)
19364 +{
19365 +       unsigned int cpu = smp_processor_id();
19366 +       struct _vx_history *hist = &per_cpu(vx_history_buffer, cpu);
19367 +       struct _vx_hist_entry *entry;
19368 +       unsigned int index;
19369 +
19370 +       index = vxh_active ? (hist->counter++ % VXH_SIZE) : VXH_SIZE;
19371 +       entry = &hist->entry[index];
19372 +
19373 +       entry->seq = atomic_inc_return(&sequence);
19374 +       entry->loc = loc;
19375 +       return entry;
19376 +}
19377 +
19378 +EXPORT_SYMBOL_GPL(vxh_advance);
19379 +
19380 +
19381 +#define VXH_LOC_FMTS   "(#%04x,*%d):%p"
19382 +
19383 +#define VXH_LOC_ARGS(e)        (e)->seq, cpu, (e)->loc
19384 +
19385 +
19386 +#define VXH_VXI_FMTS   "%p[#%d,%d.%d]"
19387 +
19388 +#define VXH_VXI_ARGS(e)        (e)->vxi.ptr,                           \
19389 +                       (e)->vxi.ptr ? (e)->vxi.xid : 0,        \
19390 +                       (e)->vxi.ptr ? (e)->vxi.usecnt : 0,     \
19391 +                       (e)->vxi.ptr ? (e)->vxi.tasks : 0
19392 +
19393 +void   vxh_dump_entry(struct _vx_hist_entry *e, unsigned cpu)
19394 +{
19395 +       switch (e->type) {
19396 +       case VXH_THROW_OOPS:
19397 +               printk( VXH_LOC_FMTS " oops \n", VXH_LOC_ARGS(e));
19398 +               break;
19399 +
19400 +       case VXH_GET_VX_INFO:
19401 +       case VXH_PUT_VX_INFO:
19402 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS "\n",
19403 +                       VXH_LOC_ARGS(e),
19404 +                       (e->type == VXH_GET_VX_INFO) ? "get" : "put",
19405 +                       VXH_VXI_ARGS(e));
19406 +               break;
19407 +
19408 +       case VXH_INIT_VX_INFO:
19409 +       case VXH_SET_VX_INFO:
19410 +       case VXH_CLR_VX_INFO:
19411 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS " @%p\n",
19412 +                       VXH_LOC_ARGS(e),
19413 +                       (e->type == VXH_INIT_VX_INFO) ? "init" :
19414 +                       ((e->type == VXH_SET_VX_INFO) ? "set" : "clr"),
19415 +                       VXH_VXI_ARGS(e), e->sc.data);
19416 +               break;
19417 +
19418 +       case VXH_CLAIM_VX_INFO:
19419 +       case VXH_RELEASE_VX_INFO:
19420 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS " @%p\n",
19421 +                       VXH_LOC_ARGS(e),
19422 +                       (e->type == VXH_CLAIM_VX_INFO) ? "claim" : "release",
19423 +                       VXH_VXI_ARGS(e), e->sc.data);
19424 +               break;
19425 +
19426 +       case VXH_ALLOC_VX_INFO:
19427 +       case VXH_DEALLOC_VX_INFO:
19428 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS "\n",
19429 +                       VXH_LOC_ARGS(e),
19430 +                       (e->type == VXH_ALLOC_VX_INFO) ? "alloc" : "dealloc",
19431 +                       VXH_VXI_ARGS(e));
19432 +               break;
19433 +
19434 +       case VXH_HASH_VX_INFO:
19435 +       case VXH_UNHASH_VX_INFO:
19436 +               printk( VXH_LOC_FMTS " __%s_vx_info " VXH_VXI_FMTS "\n",
19437 +                       VXH_LOC_ARGS(e),
19438 +                       (e->type == VXH_HASH_VX_INFO) ? "hash" : "unhash",
19439 +                       VXH_VXI_ARGS(e));
19440 +               break;
19441 +
19442 +       case VXH_LOC_VX_INFO:
19443 +       case VXH_LOOKUP_VX_INFO:
19444 +       case VXH_CREATE_VX_INFO:
19445 +               printk( VXH_LOC_FMTS " __%s_vx_info [#%d] -> " VXH_VXI_FMTS "\n",
19446 +                       VXH_LOC_ARGS(e),
19447 +                       (e->type == VXH_CREATE_VX_INFO) ? "create" :
19448 +                       ((e->type == VXH_LOC_VX_INFO) ? "loc" : "lookup"),
19449 +                       e->ll.arg, VXH_VXI_ARGS(e));
19450 +               break;
19451 +       }
19452 +}
19453 +
19454 +static void __vxh_dump_history(void)
19455 +{
19456 +       unsigned int i, cpu;
19457 +
19458 +       printk("History:\tSEQ: %8x\tNR_CPUS: %d\n",
19459 +               atomic_read(&sequence), NR_CPUS);
19460 +
19461 +       for (i = 0; i < VXH_SIZE; i++) {
19462 +               for_each_online_cpu(cpu) {
19463 +                       struct _vx_history *hist =
19464 +                               &per_cpu(vx_history_buffer, cpu);
19465 +                       unsigned int index = (hist->counter - i) % VXH_SIZE;
19466 +                       struct _vx_hist_entry *entry = &hist->entry[index];
19467 +
19468 +                       vxh_dump_entry(entry, cpu);
19469 +               }
19470 +       }
19471 +}
19472 +
19473 +void   vxh_dump_history(void)
19474 +{
19475 +       vxh_active = 0;
19476 +#ifdef CONFIG_SMP
19477 +       local_irq_enable();
19478 +       smp_send_stop();
19479 +       local_irq_disable();
19480 +#endif
19481 +       __vxh_dump_history();
19482 +}
19483 +
19484 +
19485 +/* vserver syscall commands below here */
19486 +
19487 +
19488 +int vc_dump_history(uint32_t id)
19489 +{
19490 +       vxh_active = 0;
19491 +       __vxh_dump_history();
19492 +       vxh_active = 1;
19493 +
19494 +       return 0;
19495 +}
19496 +
19497 +
19498 +int do_read_history(struct __user _vx_hist_entry *data,
19499 +       int cpu, uint32_t *index, uint32_t *count)
19500 +{
19501 +       int pos, ret = 0;
19502 +       struct _vx_history *hist = &per_cpu(vx_history_buffer, cpu);
19503 +       int end = hist->counter;
19504 +       int start = end - VXH_SIZE + 2;
19505 +       int idx = *index;
19506 +
19507 +       /* special case: get current pos */
19508 +       if (!*count) {
19509 +               *index = end;
19510 +               return 0;
19511 +       }
19512 +
19513 +       /* have we lost some data? */
19514 +       if (idx < start)
19515 +               idx = start;
19516 +
19517 +       for (pos = 0; (pos < *count) && (idx < end); pos++, idx++) {
19518 +               struct _vx_hist_entry *entry =
19519 +                       &hist->entry[idx % VXH_SIZE];
19520 +
19521 +               /* send entry to userspace */
19522 +               ret = copy_to_user(&data[pos], entry, sizeof(*entry));
19523 +               if (ret)
19524 +                       break;
19525 +       }
19526 +       /* save new index and count */
19527 +       *index = idx;
19528 +       *count = pos;
19529 +       return ret ? ret : (*index < end);
19530 +}
19531 +
19532 +int vc_read_history(uint32_t id, void __user *data)
19533 +{
19534 +       struct vcmd_read_history_v0 vc_data;
19535 +       int ret;
19536 +
19537 +       if (id >= NR_CPUS)
19538 +               return -EINVAL;
19539 +
19540 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19541 +               return -EFAULT;
19542 +
19543 +       ret = do_read_history((struct __user _vx_hist_entry *)vc_data.data,
19544 +               id, &vc_data.index, &vc_data.count);
19545 +
19546 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19547 +               return -EFAULT;
19548 +       return ret;
19549 +}
19550 +
19551 +#ifdef CONFIG_COMPAT
19552 +
19553 +int vc_read_history_x32(uint32_t id, void __user *data)
19554 +{
19555 +       struct vcmd_read_history_v0_x32 vc_data;
19556 +       int ret;
19557 +
19558 +       if (id >= NR_CPUS)
19559 +               return -EINVAL;
19560 +
19561 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19562 +               return -EFAULT;
19563 +
19564 +       ret = do_read_history((struct __user _vx_hist_entry *)
19565 +               compat_ptr(vc_data.data_ptr),
19566 +               id, &vc_data.index, &vc_data.count);
19567 +
19568 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19569 +               return -EFAULT;
19570 +       return ret;
19571 +}
19572 +
19573 +#endif /* CONFIG_COMPAT */
19574 +
19575 diff -NurpP --minimal linux-2.6.38-rc8/kernel/vserver/inet.c linux-2.6.38-rc8-vs2.3.0.37-rc6/kernel/vserver/inet.c
19576 --- linux-2.6.38-rc8/kernel/vserver/inet.c      1970-01-01 01:00:00.000000000 +0100
19577 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/kernel/vserver/inet.c       2011-01-29 02:01:07.000000000 +0100
19578 @@ -0,0 +1,224 @@
19579 +
19580 +#include <linux/in.h>
19581 +#include <linux/inetdevice.h>
19582 +#include <linux/vs_inet.h>
19583 +#include <linux/vs_inet6.h>
19584 +#include <linux/vserver/debug.h>
19585 +#include <net/route.h>
19586 +#include <net/addrconf.h>
19587 +
19588 +
19589 +int nx_v4_addr_conflict(struct nx_info *nxi1, struct nx_info *nxi2)
19590 +{
19591 +       int ret = 0;
19592 +
19593 +       if (!nxi1 || !nxi2 || nxi1 == nxi2)
19594 +               ret = 1;
19595 +       else {
19596 +               struct nx_addr_v4 *ptr;
19597 +
19598 +               for (ptr = &nxi1->v4; ptr; ptr = ptr->next) {
19599 +                       if (v4_nx_addr_in_nx_info(nxi2, ptr, -1)) {
19600 +                               ret = 1;
19601 +                               break;
19602 +                       }
19603 +               }
19604 +       }
19605 +
19606 +       vxdprintk(VXD_CBIT(net, 2),
19607 +               "nx_v4_addr_conflict(%p,%p): %d",
19608 +               nxi1, nxi2, ret);
19609 +
19610 +       return ret;
19611 +}
19612 +
19613 +
19614 +#ifdef CONFIG_IPV6
19615 +
19616 +int nx_v6_addr_conflict(struct nx_info *nxi1, struct nx_info *nxi2)
19617 +{
19618 +       int ret = 0;
19619 +
19620 +       if (!nxi1 || !nxi2 || nxi1 == nxi2)
19621 +               ret = 1;
19622 +       else {
19623 +               struct nx_addr_v6 *ptr;
19624 +
19625 +               for (ptr = &nxi1->v6; ptr; ptr = ptr->next) {
19626 +                       if (v6_nx_addr_in_nx_info(nxi2, ptr, -1)) {
19627 +                               ret = 1;
19628 +                               break;
19629 +                       }
19630 +               }
19631 +       }
19632 +
19633 +       vxdprintk(VXD_CBIT(net, 2),
19634 +               "nx_v6_addr_conflict(%p,%p): %d",
19635 +               nxi1, nxi2, ret);
19636 +
19637 +       return ret;
19638 +}
19639 +
19640 +#endif
19641 +
19642 +int v4_dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
19643 +{
19644 +       struct in_device *in_dev;
19645 +       struct in_ifaddr **ifap;
19646 +       struct in_ifaddr *ifa;
19647 +       int ret = 0;
19648 +
19649 +       if (!dev)
19650 +               goto out;
19651 +       in_dev = in_dev_get(dev);
19652 +       if (!in_dev)
19653 +               goto out;
19654 +
19655 +       for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
19656 +               ifap = &ifa->ifa_next) {
19657 +               if (v4_addr_in_nx_info(nxi, ifa->ifa_local, NXA_MASK_SHOW)) {
19658 +                       ret = 1;
19659 +                       break;
19660 +               }
19661 +       }
19662 +       in_dev_put(in_dev);
19663 +out:
19664 +       return ret;
19665 +}
19666 +
19667 +
19668 +#ifdef CONFIG_IPV6
19669 +
19670 +int v6_dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
19671 +{
19672 +       struct inet6_dev *in_dev;
19673 +       struct inet6_ifaddr *ifa;
19674 +       int ret = 0;
19675 +
19676 +       if (!dev)
19677 +               goto out;
19678 +       in_dev = in6_dev_get(dev);
19679 +       if (!in_dev)
19680 +               goto out;
19681 +
19682 +       // for (ifap = &in_dev->addr_list; (ifa = *ifap) != NULL;
19683 +       list_for_each_entry(ifa, &in_dev->addr_list, if_list) {
19684 +               if (v6_addr_in_nx_info(nxi, &ifa->addr, -1)) {
19685 +                       ret = 1;
19686 +                       break;
19687 +               }
19688 +       }
19689 +       in6_dev_put(in_dev);
19690 +out:
19691 +       return ret;
19692 +}
19693 +
19694 +#endif
19695 +
19696 +int dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
19697 +{
19698 +       int ret = 1;
19699 +
19700 +       if (!nxi)
19701 +               goto out;
19702 +       if (nxi->v4.type && v4_dev_in_nx_info(dev, nxi))
19703 +               goto out;
19704 +#ifdef CONFIG_IPV6
19705 +       ret = 2;
19706 +       if (nxi->v6.type && v6_dev_in_nx_info(dev, nxi))
19707 +               goto out;
19708 +#endif
19709 +       ret = 0;
19710 +out:
19711 +       vxdprintk(VXD_CBIT(net, 3),
19712 +               "dev_in_nx_info(%p,%p[#%d]) = %d",
19713 +               dev, nxi, nxi ? nxi->nx_id : 0, ret);
19714 +       return ret;
19715 +}
19716 +
19717 +int ip_v4_find_src(struct net *net, struct nx_info *nxi,
19718 +       struct rtable **rp, struct flowi *fl)
19719 +{
19720 +       if (!nxi)
19721 +               return 0;
19722 +
19723 +       /* FIXME: handle lback only case */
19724 +       if (!NX_IPV4(nxi))
19725 +               return -EPERM;
19726 +
19727 +       vxdprintk(VXD_CBIT(net, 4),
19728 +               "ip_v4_find_src(%p[#%u]) " NIPQUAD_FMT " -> " NIPQUAD_FMT,
19729 +               nxi, nxi ? nxi->nx_id : 0,
19730 +               NIPQUAD(fl->fl4_src), NIPQUAD(fl->fl4_dst));
19731 +
19732 +       /* single IP is unconditional */
19733 +       if (nx_info_flags(nxi, NXF_SINGLE_IP, 0) &&
19734 +               (fl->fl4_src == INADDR_ANY))
19735 +               fl->fl4_src = nxi->v4.ip[0].s_addr;
19736 +
19737 +       if (fl->fl4_src == INADDR_ANY) {
19738 +               struct nx_addr_v4 *ptr;
19739 +               __be32 found = 0;
19740 +               int err;
19741 +
19742 +               err = __ip_route_output_key(net, rp, fl);
19743 +               if (!err) {
19744 +                       found = (*rp)->rt_src;
19745 +                       ip_rt_put(*rp);
19746 +                       vxdprintk(VXD_CBIT(net, 4),
19747 +                               "ip_v4_find_src(%p[#%u]) rok[%u]: " NIPQUAD_FMT,
19748 +                               nxi, nxi ? nxi->nx_id : 0, fl->oif, NIPQUAD(found));
19749 +                       if (v4_addr_in_nx_info(nxi, found, NXA_MASK_BIND))
19750 +                               goto found;
19751 +               }
19752 +
19753 +               for (ptr = &nxi->v4; ptr; ptr = ptr->next) {
19754 +                       __be32 primary = ptr->ip[0].s_addr;
19755 +                       __be32 mask = ptr->mask.s_addr;
19756 +                       __be32 neta = primary & mask;
19757 +
19758 +                       vxdprintk(VXD_CBIT(net, 4), "ip_v4_find_src(%p[#%u]) chk: "
19759 +                               NIPQUAD_FMT "/" NIPQUAD_FMT "/" NIPQUAD_FMT,
19760 +                               nxi, nxi ? nxi->nx_id : 0, NIPQUAD(primary),
19761 +                               NIPQUAD(mask), NIPQUAD(neta));
19762 +                       if ((found & mask) != neta)
19763 +                               continue;
19764 +
19765 +                       fl->fl4_src = primary;
19766 +                       err = __ip_route_output_key(net, rp, fl);
19767 +                       vxdprintk(VXD_CBIT(net, 4),
19768 +                               "ip_v4_find_src(%p[#%u]) rok[%u]: " NIPQUAD_FMT,
19769 +                               nxi, nxi ? nxi->nx_id : 0, fl->oif, NIPQUAD(primary));
19770 +                       if (!err) {
19771 +                               found = (*rp)->rt_src;
19772 +                               ip_rt_put(*rp);
19773 +                               if (found == primary)
19774 +                                       goto found;
19775 +                       }
19776 +               }
19777 +               /* still no source ip? */
19778 +               found = ipv4_is_loopback(fl->fl4_dst)
19779 +                       ? IPI_LOOPBACK : nxi->v4.ip[0].s_addr;
19780 +       found:
19781 +               /* assign src ip to flow */
19782 +               fl->fl4_src = found;
19783 +
19784 +       } else {
19785 +               if (!v4_addr_in_nx_info(nxi, fl->fl4_src, NXA_MASK_BIND))
19786 +                       return -EPERM;
19787 +       }
19788 +
19789 +       if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0)) {
19790 +               if (ipv4_is_loopback(fl->fl4_dst))
19791 +                       fl->fl4_dst = nxi->v4_lback.s_addr;
19792 +               if (ipv4_is_loopback(fl->fl4_src))
19793 +                       fl->fl4_src = nxi->v4_lback.s_addr;
19794 +       } else if (ipv4_is_loopback(fl->fl4_dst) &&
19795 +               !nx_info_flags(nxi, NXF_LBACK_ALLOW, 0))
19796 +               return -EPERM;
19797 +
19798 +       return 0;
19799 +}
19800 +
19801 +EXPORT_SYMBOL_GPL(ip_v4_find_src);
19802 +
19803 diff -NurpP --minimal linux-2.6.38-rc8/kernel/vserver/init.c linux-2.6.38-rc8-vs2.3.0.37-rc6/kernel/vserver/init.c
19804 --- linux-2.6.38-rc8/kernel/vserver/init.c      1970-01-01 01:00:00.000000000 +0100
19805 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/kernel/vserver/init.c       2011-01-29 02:01:07.000000000 +0100
19806 @@ -0,0 +1,45 @@
19807 +/*
19808 + *  linux/kernel/init.c
19809 + *
19810 + *  Virtual Server Init
19811 + *
19812 + *  Copyright (C) 2004-2007  Herbert Pötzl
19813 + *
19814 + *  V0.01  basic structure
19815 + *
19816 + */
19817 +
19818 +#include <linux/init.h>
19819 +
19820 +int    vserver_register_sysctl(void);
19821 +void   vserver_unregister_sysctl(void);
19822 +
19823 +
19824 +static int __init init_vserver(void)
19825 +{
19826 +       int ret = 0;
19827 +
19828 +#ifdef CONFIG_VSERVER_DEBUG
19829 +       vserver_register_sysctl();
19830 +#endif
19831 +       return ret;
19832 +}
19833 +
19834 +
19835 +static void __exit exit_vserver(void)
19836 +{
19837 +
19838 +#ifdef CONFIG_VSERVER_DEBUG
19839 +       vserver_unregister_sysctl();
19840 +#endif
19841 +       return;
19842 +}
19843 +
19844 +/* FIXME: GFP_ZONETYPES gone
19845 +long vx_slab[GFP_ZONETYPES]; */
19846 +long vx_area;
19847 +
19848 +
19849 +module_init(init_vserver);
19850 +module_exit(exit_vserver);
19851 +
19852 diff -NurpP --minimal linux-2.6.38-rc8/kernel/vserver/inode.c linux-2.6.38-rc8-vs2.3.0.37-rc6/kernel/vserver/inode.c
19853 --- linux-2.6.38-rc8/kernel/vserver/inode.c     1970-01-01 01:00:00.000000000 +0100
19854 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/kernel/vserver/inode.c      2011-01-29 02:01:07.000000000 +0100
19855 @@ -0,0 +1,435 @@
19856 +/*
19857 + *  linux/kernel/vserver/inode.c
19858 + *
19859 + *  Virtual Server: File System Support
19860 + *
19861 + *  Copyright (C) 2004-2007  Herbert Pötzl
19862 + *
19863 + *  V0.01  separated from vcontext V0.05
19864 + *  V0.02  moved to tag (instead of xid)
19865 + *
19866 + */
19867 +
19868 +#include <linux/tty.h>
19869 +#include <linux/proc_fs.h>
19870 +#include <linux/devpts_fs.h>
19871 +#include <linux/fs.h>
19872 +#include <linux/file.h>
19873 +#include <linux/mount.h>
19874 +#include <linux/parser.h>
19875 +#include <linux/namei.h>
19876 +#include <linux/vserver/inode.h>
19877 +#include <linux/vserver/inode_cmd.h>
19878 +#include <linux/vs_base.h>
19879 +#include <linux/vs_tag.h>
19880 +
19881 +#include <asm/uaccess.h>
19882 +
19883 +
19884 +static int __vc_get_iattr(struct inode *in, uint32_t *tag, uint32_t *flags, uint32_t *mask)
19885 +{
19886 +       struct proc_dir_entry *entry;
19887 +
19888 +       if (!in || !in->i_sb)
19889 +               return -ESRCH;
19890 +
19891 +       *flags = IATTR_TAG
19892 +               | (IS_IMMUTABLE(in) ? IATTR_IMMUTABLE : 0)
19893 +               | (IS_IXUNLINK(in) ? IATTR_IXUNLINK : 0)
19894 +               | (IS_BARRIER(in) ? IATTR_BARRIER : 0)
19895 +               | (IS_COW(in) ? IATTR_COW : 0);
19896 +       *mask = IATTR_IXUNLINK | IATTR_IMMUTABLE | IATTR_COW;
19897 +
19898 +       if (S_ISDIR(in->i_mode))
19899 +               *mask |= IATTR_BARRIER;
19900 +
19901 +       if (IS_TAGGED(in)) {
19902 +               *tag = in->i_tag;
19903 +               *mask |= IATTR_TAG;
19904 +       }
19905 +
19906 +       switch (in->i_sb->s_magic) {
19907 +       case PROC_SUPER_MAGIC:
19908 +               entry = PROC_I(in)->pde;
19909 +
19910 +               /* check for specific inodes? */
19911 +               if (entry)
19912 +                       *mask |= IATTR_FLAGS;
19913 +               if (entry)
19914 +                       *flags |= (entry->vx_flags & IATTR_FLAGS);
19915 +               else
19916 +                       *flags |= (PROC_I(in)->vx_flags & IATTR_FLAGS);
19917 +               break;
19918 +
19919 +       case DEVPTS_SUPER_MAGIC:
19920 +               *tag = in->i_tag;
19921 +               *mask |= IATTR_TAG;
19922 +               break;
19923 +
19924 +       default:
19925 +               break;
19926 +       }
19927 +       return 0;
19928 +}
19929 +
19930 +int vc_get_iattr(void __user *data)
19931 +{
19932 +       struct path path;
19933 +       struct vcmd_ctx_iattr_v1 vc_data = { .tag = -1 };
19934 +       int ret;
19935 +
19936 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19937 +               return -EFAULT;
19938 +
19939 +       ret = user_lpath(vc_data.name, &path);
19940 +       if (!ret) {
19941 +               ret = __vc_get_iattr(path.dentry->d_inode,
19942 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
19943 +               path_put(&path);
19944 +       }
19945 +       if (ret)
19946 +               return ret;
19947 +
19948 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19949 +               ret = -EFAULT;
19950 +       return ret;
19951 +}
19952 +
19953 +#ifdef CONFIG_COMPAT
19954 +
19955 +int vc_get_iattr_x32(void __user *data)
19956 +{
19957 +       struct path path;
19958 +       struct vcmd_ctx_iattr_v1_x32 vc_data = { .tag = -1 };
19959 +       int ret;
19960 +
19961 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19962 +               return -EFAULT;
19963 +
19964 +       ret = user_lpath(compat_ptr(vc_data.name_ptr), &path);
19965 +       if (!ret) {
19966 +               ret = __vc_get_iattr(path.dentry->d_inode,
19967 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
19968 +               path_put(&path);
19969 +       }
19970 +       if (ret)
19971 +               return ret;
19972 +
19973 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19974 +               ret = -EFAULT;
19975 +       return ret;
19976 +}
19977 +
19978 +#endif /* CONFIG_COMPAT */
19979 +
19980 +
19981 +int vc_fget_iattr(uint32_t fd, void __user *data)
19982 +{
19983 +       struct file *filp;
19984 +       struct vcmd_ctx_fiattr_v0 vc_data = { .tag = -1 };
19985 +       int ret;
19986 +
19987 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19988 +               return -EFAULT;
19989 +
19990 +       filp = fget(fd);
19991 +       if (!filp || !filp->f_dentry || !filp->f_dentry->d_inode)
19992 +               return -EBADF;
19993 +
19994 +       ret = __vc_get_iattr(filp->f_dentry->d_inode,
19995 +               &vc_data.tag, &vc_data.flags, &vc_data.mask);
19996 +
19997 +       fput(filp);
19998 +
19999 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20000 +               ret = -EFAULT;
20001 +       return ret;
20002 +}
20003 +
20004 +
20005 +static int __vc_set_iattr(struct dentry *de, uint32_t *tag, uint32_t *flags, uint32_t *mask)
20006 +{
20007 +       struct inode *in = de->d_inode;
20008 +       int error = 0, is_proc = 0, has_tag = 0;
20009 +       struct iattr attr = { 0 };
20010 +
20011 +       if (!in || !in->i_sb)
20012 +               return -ESRCH;
20013 +
20014 +       is_proc = (in->i_sb->s_magic == PROC_SUPER_MAGIC);
20015 +       if ((*mask & IATTR_FLAGS) && !is_proc)
20016 +               return -EINVAL;
20017 +
20018 +       has_tag = IS_TAGGED(in) ||
20019 +               (in->i_sb->s_magic == DEVPTS_SUPER_MAGIC);
20020 +       if ((*mask & IATTR_TAG) && !has_tag)
20021 +               return -EINVAL;
20022 +
20023 +       mutex_lock(&in->i_mutex);
20024 +       if (*mask & IATTR_TAG) {
20025 +               attr.ia_tag = *tag;
20026 +               attr.ia_valid |= ATTR_TAG;
20027 +       }
20028 +
20029 +       if (*mask & IATTR_FLAGS) {
20030 +               struct proc_dir_entry *entry = PROC_I(in)->pde;
20031 +               unsigned int iflags = PROC_I(in)->vx_flags;
20032 +
20033 +               iflags = (iflags & ~(*mask & IATTR_FLAGS))
20034 +                       | (*flags & IATTR_FLAGS);
20035 +               PROC_I(in)->vx_flags = iflags;
20036 +               if (entry)
20037 +                       entry->vx_flags = iflags;
20038 +       }
20039 +
20040 +       if (*mask & (IATTR_IMMUTABLE | IATTR_IXUNLINK |
20041 +               IATTR_BARRIER | IATTR_COW)) {
20042 +               int iflags = in->i_flags;
20043 +               int vflags = in->i_vflags;
20044 +
20045 +               if (*mask & IATTR_IMMUTABLE) {
20046 +                       if (*flags & IATTR_IMMUTABLE)
20047 +                               iflags |= S_IMMUTABLE;
20048 +                       else
20049 +                               iflags &= ~S_IMMUTABLE;
20050 +               }
20051 +               if (*mask & IATTR_IXUNLINK) {
20052 +                       if (*flags & IATTR_IXUNLINK)
20053 +                               iflags |= S_IXUNLINK;
20054 +                       else
20055 +                               iflags &= ~S_IXUNLINK;
20056 +               }
20057 +               if (S_ISDIR(in->i_mode) && (*mask & IATTR_BARRIER)) {
20058 +                       if (*flags & IATTR_BARRIER)
20059 +                               vflags |= V_BARRIER;
20060 +                       else
20061 +                               vflags &= ~V_BARRIER;
20062 +               }
20063 +               if (S_ISREG(in->i_mode) && (*mask & IATTR_COW)) {
20064 +                       if (*flags & IATTR_COW)
20065 +                               vflags |= V_COW;
20066 +                       else
20067 +                               vflags &= ~V_COW;
20068 +               }
20069 +               if (in->i_op && in->i_op->sync_flags) {
20070 +                       error = in->i_op->sync_flags(in, iflags, vflags);
20071 +                       if (error)
20072 +                               goto out;
20073 +               }
20074 +       }
20075 +
20076 +       if (attr.ia_valid) {
20077 +               if (in->i_op && in->i_op->setattr)
20078 +                       error = in->i_op->setattr(de, &attr);
20079 +               else {
20080 +                       error = inode_change_ok(in, &attr);
20081 +                       if (!error) {
20082 +                               setattr_copy(in, &attr);
20083 +                               mark_inode_dirty(in);
20084 +                       }
20085 +               }
20086 +       }
20087 +
20088 +out:
20089 +       mutex_unlock(&in->i_mutex);
20090 +       return error;
20091 +}
20092 +
20093 +int vc_set_iattr(void __user *data)
20094 +{
20095 +       struct path path;
20096 +       struct vcmd_ctx_iattr_v1 vc_data;
20097 +       int ret;
20098 +
20099 +       if (!capable(CAP_LINUX_IMMUTABLE))
20100 +               return -EPERM;
20101 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20102 +               return -EFAULT;
20103 +
20104 +       ret = user_lpath(vc_data.name, &path);
20105 +       if (!ret) {
20106 +               ret = __vc_set_iattr(path.dentry,
20107 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
20108 +               path_put(&path);
20109 +       }
20110 +
20111 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20112 +               ret = -EFAULT;
20113 +       return ret;
20114 +}
20115 +
20116 +#ifdef CONFIG_COMPAT
20117 +
20118 +int vc_set_iattr_x32(void __user *data)
20119 +{
20120 +       struct path path;
20121 +       struct vcmd_ctx_iattr_v1_x32 vc_data;
20122 +       int ret;
20123 +
20124 +       if (!capable(CAP_LINUX_IMMUTABLE))
20125 +               return -EPERM;
20126 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20127 +               return -EFAULT;
20128 +
20129 +       ret = user_lpath(compat_ptr(vc_data.name_ptr), &path);
20130 +       if (!ret) {
20131 +               ret = __vc_set_iattr(path.dentry,
20132 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
20133 +               path_put(&path);
20134 +       }
20135 +
20136 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20137 +               ret = -EFAULT;
20138 +       return ret;
20139 +}
20140 +
20141 +#endif /* CONFIG_COMPAT */
20142 +
20143 +int vc_fset_iattr(uint32_t fd, void __user *data)
20144 +{
20145 +       struct file *filp;
20146 +       struct vcmd_ctx_fiattr_v0 vc_data;
20147 +       int ret;
20148 +
20149 +       if (!capable(CAP_LINUX_IMMUTABLE))
20150 +               return -EPERM;
20151 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20152 +               return -EFAULT;
20153 +
20154 +       filp = fget(fd);
20155 +       if (!filp || !filp->f_dentry || !filp->f_dentry->d_inode)
20156 +               return -EBADF;
20157 +
20158 +       ret = __vc_set_iattr(filp->f_dentry, &vc_data.tag,
20159 +               &vc_data.flags, &vc_data.mask);
20160 +
20161 +       fput(filp);
20162 +
20163 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20164 +               return -EFAULT;
20165 +       return ret;
20166 +}
20167 +
20168 +
20169 +enum { Opt_notagcheck, Opt_tag, Opt_notag, Opt_tagid, Opt_err };
20170 +
20171 +static match_table_t tokens = {
20172 +       {Opt_notagcheck, "notagcheck"},
20173 +#ifdef CONFIG_PROPAGATE
20174 +       {Opt_notag, "notag"},
20175 +       {Opt_tag, "tag"},
20176 +       {Opt_tagid, "tagid=%u"},
20177 +#endif
20178 +       {Opt_err, NULL}
20179 +};
20180 +
20181 +
20182 +static void __dx_parse_remove(char *string, char *opt)
20183 +{
20184 +       char *p = strstr(string, opt);
20185 +       char *q = p;
20186 +
20187 +       if (p) {
20188 +               while (*q != '\0' && *q != ',')
20189 +                       q++;
20190 +               while (*q)
20191 +                       *p++ = *q++;
20192 +               while (*p)
20193 +                       *p++ = '\0';
20194 +       }
20195 +}
20196 +
20197 +int dx_parse_tag(char *string, tag_t *tag, int remove, int *mnt_flags,
20198 +                unsigned long *flags)
20199 +{
20200 +       int set = 0;
20201 +       substring_t args[MAX_OPT_ARGS];
20202 +       int token, option = 0;
20203 +       char *s, *p, *opts;
20204 +
20205 +       if (!string)
20206 +               return 0;
20207 +       s = kstrdup(string, GFP_KERNEL | GFP_ATOMIC);
20208 +       if (!s)
20209 +               return 0;
20210 +
20211 +       opts = s;
20212 +       while ((p = strsep(&opts, ",")) != NULL) {
20213 +               token = match_token(p, tokens, args);
20214 +
20215 +               vxdprintk(VXD_CBIT(tag, 7),
20216 +                       "dx_parse_tag(" VS_Q("%s") "): %d:#%d",
20217 +                       p, token, option);
20218 +
20219 +               switch (token) {
20220 +#ifdef CONFIG_PROPAGATE
20221 +               case Opt_tag:
20222 +                       if (tag)
20223 +                               *tag = 0;
20224 +                       if (remove)
20225 +                               __dx_parse_remove(s, "tag");
20226 +                       *mnt_flags |= MNT_TAGID;
20227 +                       set |= MNT_TAGID;
20228 +                       break;
20229 +               case Opt_notag:
20230 +                       if (remove)
20231 +                               __dx_parse_remove(s, "notag");
20232 +                       *mnt_flags |= MNT_NOTAG;
20233 +                       set |= MNT_NOTAG;
20234 +                       break;
20235 +               case Opt_tagid:
20236 +                       if (tag && !match_int(args, &option))
20237 +                               *tag = option;
20238 +                       if (remove)
20239 +                               __dx_parse_remove(s, "tagid");
20240 +                       *mnt_flags |= MNT_TAGID;
20241 +                       set |= MNT_TAGID;
20242 +                       break;
20243 +#endif
20244 +               case Opt_notagcheck:
20245 +                       if (remove)
20246 +                               __dx_parse_remove(s, "notagcheck");
20247 +                       *flags |= MS_NOTAGCHECK;
20248 +                       set |= MS_NOTAGCHECK;
20249 +                       break;
20250 +               }
20251 +       }
20252 +       if (set)
20253 +               strcpy(string, s);
20254 +       kfree(s);
20255 +       return set;
20256 +}
20257 +
20258 +#ifdef CONFIG_PROPAGATE
20259 +
20260 +void __dx_propagate_tag(struct nameidata *nd, struct inode *inode)
20261 +{
20262 +       tag_t new_tag = 0;
20263 +       struct vfsmount *mnt;
20264 +       int propagate;
20265 +
20266 +       if (!nd)
20267 +               return;
20268 +       mnt = nd->path.mnt;
20269 +       if (!mnt)
20270 +               return;
20271 +
20272 +       propagate = (mnt->mnt_flags & MNT_TAGID);
20273 +       if (propagate)
20274 +               new_tag = mnt->mnt_tag;
20275 +
20276 +       vxdprintk(VXD_CBIT(tag, 7),
20277 +               "dx_propagate_tag(%p[#%lu.%d]): %d,%d",
20278 +               inode, inode->i_ino, inode->i_tag,
20279 +               new_tag, (propagate) ? 1 : 0);
20280 +
20281 +       if (propagate)
20282 +               inode->i_tag = new_tag;
20283 +}
20284 +
20285 +#include <linux/module.h>
20286 +
20287 +EXPORT_SYMBOL_GPL(__dx_propagate_tag);
20288 +
20289 +#endif /* CONFIG_PROPAGATE */
20290 +
20291 diff -NurpP --minimal linux-2.6.38-rc8/kernel/vserver/limit.c linux-2.6.38-rc8-vs2.3.0.37-rc6/kernel/vserver/limit.c
20292 --- linux-2.6.38-rc8/kernel/vserver/limit.c     1970-01-01 01:00:00.000000000 +0100
20293 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/kernel/vserver/limit.c      2011-01-29 02:01:07.000000000 +0100
20294 @@ -0,0 +1,354 @@
20295 +/*
20296 + *  linux/kernel/vserver/limit.c
20297 + *
20298 + *  Virtual Server: Context Limits
20299 + *
20300 + *  Copyright (C) 2004-2010  Herbert Pötzl
20301 + *
20302 + *  V0.01  broken out from vcontext V0.05
20303 + *  V0.02  changed vcmds to vxi arg
20304 + *  V0.03  added memory cgroup support
20305 + *
20306 + */
20307 +
20308 +#include <linux/sched.h>
20309 +#include <linux/module.h>
20310 +#include <linux/memcontrol.h>
20311 +#include <linux/res_counter.h>
20312 +#include <linux/vs_limit.h>
20313 +#include <linux/vserver/limit.h>
20314 +#include <linux/vserver/limit_cmd.h>
20315 +
20316 +#include <asm/uaccess.h>
20317 +
20318 +
20319 +const char *vlimit_name[NUM_LIMITS] = {
20320 +#ifdef CONFIG_VSERVER_LEGACY_MEM
20321 +       [RLIMIT_RSS]            = "RSS",
20322 +       [RLIMIT_AS]             = "VM",
20323 +#endif /* CONFIG_VSERVER_LEGACY_MEM */
20324 +       [RLIMIT_CPU]            = "CPU",
20325 +       [RLIMIT_NPROC]          = "NPROC",
20326 +       [RLIMIT_NOFILE]         = "NOFILE",
20327 +       [RLIMIT_LOCKS]          = "LOCKS",
20328 +       [RLIMIT_SIGPENDING]     = "SIGP",
20329 +       [RLIMIT_MSGQUEUE]       = "MSGQ",
20330 +
20331 +       [VLIMIT_NSOCK]          = "NSOCK",
20332 +       [VLIMIT_OPENFD]         = "OPENFD",
20333 +       [VLIMIT_SHMEM]          = "SHMEM",
20334 +       [VLIMIT_DENTRY]         = "DENTRY",
20335 +};
20336 +
20337 +EXPORT_SYMBOL_GPL(vlimit_name);
20338 +
20339 +#define MASK_ENTRY(x)  (1 << (x))
20340 +
20341 +const struct vcmd_ctx_rlimit_mask_v0 vlimit_mask = {
20342 +               /* minimum */
20343 +       0
20344 +       ,       /* softlimit */
20345 +#ifdef CONFIG_VSERVER_LEGACY_MEM
20346 +       MASK_ENTRY( RLIMIT_RSS          ) |
20347 +#endif /* CONFIG_VSERVER_LEGACY_MEM */
20348 +       0
20349 +       ,       /* maximum */
20350 +#ifdef CONFIG_VSERVER_LEGACY_MEM
20351 +       MASK_ENTRY( RLIMIT_RSS          ) |
20352 +       MASK_ENTRY( RLIMIT_AS           ) |
20353 +#endif /* CONFIG_VSERVER_LEGACY_MEM */
20354 +       MASK_ENTRY( RLIMIT_NPROC        ) |
20355 +       MASK_ENTRY( RLIMIT_NOFILE       ) |
20356 +       MASK_ENTRY( RLIMIT_LOCKS        ) |
20357 +       MASK_ENTRY( RLIMIT_MSGQUEUE     ) |
20358 +
20359 +       MASK_ENTRY( VLIMIT_NSOCK        ) |
20360 +       MASK_ENTRY( VLIMIT_OPENFD       ) |
20361 +       MASK_ENTRY( VLIMIT_SHMEM        ) |
20362 +       MASK_ENTRY( VLIMIT_DENTRY       ) |
20363 +       0
20364 +};
20365 +               /* accounting only */
20366 +uint32_t account_mask =
20367 +       MASK_ENTRY( VLIMIT_SEMARY       ) |
20368 +       MASK_ENTRY( VLIMIT_NSEMS        ) |
20369 +       MASK_ENTRY( VLIMIT_MAPPED       ) |
20370 +       0;
20371 +
20372 +
20373 +static int is_valid_vlimit(int id)
20374 +{
20375 +       uint32_t mask = vlimit_mask.minimum |
20376 +               vlimit_mask.softlimit | vlimit_mask.maximum;
20377 +       return mask & (1 << id);
20378 +}
20379 +
20380 +static int is_accounted_vlimit(int id)
20381 +{
20382 +       if (is_valid_vlimit(id))
20383 +               return 1;
20384 +       return account_mask & (1 << id);
20385 +}
20386 +
20387 +
20388 +static inline uint64_t vc_get_soft(struct vx_info *vxi, int id)
20389 +{
20390 +       rlim_t limit = __rlim_soft(&vxi->limit, id);
20391 +       return VX_VLIM(limit);
20392 +}
20393 +
20394 +static inline uint64_t vc_get_hard(struct vx_info *vxi, int id)
20395 +{
20396 +       rlim_t limit = __rlim_hard(&vxi->limit, id);
20397 +       return VX_VLIM(limit);
20398 +}
20399 +
20400 +static int do_get_rlimit(struct vx_info *vxi, uint32_t id,
20401 +       uint64_t *minimum, uint64_t *softlimit, uint64_t *maximum)
20402 +{
20403 +       if (!is_valid_vlimit(id))
20404 +               return -EINVAL;
20405 +
20406 +       if (minimum)
20407 +               *minimum = CRLIM_UNSET;
20408 +       if (softlimit)
20409 +               *softlimit = vc_get_soft(vxi, id);
20410 +       if (maximum)
20411 +               *maximum = vc_get_hard(vxi, id);
20412 +       return 0;
20413 +}
20414 +
20415 +int vc_get_rlimit(struct vx_info *vxi, void __user *data)
20416 +{
20417 +       struct vcmd_ctx_rlimit_v0 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 +static int do_set_rlimit(struct vx_info *vxi, uint32_t id,
20434 +       uint64_t minimum, uint64_t softlimit, uint64_t maximum)
20435 +{
20436 +       if (!is_valid_vlimit(id))
20437 +               return -EINVAL;
20438 +
20439 +       if (maximum != CRLIM_KEEP)
20440 +               __rlim_hard(&vxi->limit, id) = VX_RLIM(maximum);
20441 +       if (softlimit != CRLIM_KEEP)
20442 +               __rlim_soft(&vxi->limit, id) = VX_RLIM(softlimit);
20443 +
20444 +       /* clamp soft limit */
20445 +       if (__rlim_soft(&vxi->limit, id) > __rlim_hard(&vxi->limit, id))
20446 +               __rlim_soft(&vxi->limit, id) = __rlim_hard(&vxi->limit, id);
20447 +
20448 +       return 0;
20449 +}
20450 +
20451 +int vc_set_rlimit(struct vx_info *vxi, void __user *data)
20452 +{
20453 +       struct vcmd_ctx_rlimit_v0 vc_data;
20454 +
20455 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20456 +               return -EFAULT;
20457 +
20458 +       return do_set_rlimit(vxi, vc_data.id,
20459 +               vc_data.minimum, vc_data.softlimit, vc_data.maximum);
20460 +}
20461 +
20462 +#ifdef CONFIG_IA32_EMULATION
20463 +
20464 +int vc_set_rlimit_x32(struct vx_info *vxi, void __user *data)
20465 +{
20466 +       struct vcmd_ctx_rlimit_v0_x32 vc_data;
20467 +
20468 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20469 +               return -EFAULT;
20470 +
20471 +       return do_set_rlimit(vxi, vc_data.id,
20472 +               vc_data.minimum, vc_data.softlimit, vc_data.maximum);
20473 +}
20474 +
20475 +int vc_get_rlimit_x32(struct vx_info *vxi, void __user *data)
20476 +{
20477 +       struct vcmd_ctx_rlimit_v0_x32 vc_data;
20478 +       int ret;
20479 +
20480 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20481 +               return -EFAULT;
20482 +
20483 +       ret = do_get_rlimit(vxi, vc_data.id,
20484 +               &vc_data.minimum, &vc_data.softlimit, &vc_data.maximum);
20485 +       if (ret)
20486 +               return ret;
20487 +
20488 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20489 +               return -EFAULT;
20490 +       return 0;
20491 +}
20492 +
20493 +#endif /* CONFIG_IA32_EMULATION */
20494 +
20495 +
20496 +int vc_get_rlimit_mask(uint32_t id, void __user *data)
20497 +{
20498 +       if (copy_to_user(data, &vlimit_mask, sizeof(vlimit_mask)))
20499 +               return -EFAULT;
20500 +       return 0;
20501 +}
20502 +
20503 +
20504 +static inline void vx_reset_hits(struct _vx_limit *limit)
20505 +{
20506 +       int lim;
20507 +
20508 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
20509 +               atomic_set(&__rlim_lhit(limit, lim), 0);
20510 +       }
20511 +}
20512 +
20513 +int vc_reset_hits(struct vx_info *vxi, void __user *data)
20514 +{
20515 +       vx_reset_hits(&vxi->limit);
20516 +       return 0;
20517 +}
20518 +
20519 +static inline void vx_reset_minmax(struct _vx_limit *limit)
20520 +{
20521 +       rlim_t value;
20522 +       int lim;
20523 +
20524 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
20525 +               value = __rlim_get(limit, lim);
20526 +               __rlim_rmax(limit, lim) = value;
20527 +               __rlim_rmin(limit, lim) = value;
20528 +       }
20529 +}
20530 +
20531 +int vc_reset_minmax(struct vx_info *vxi, void __user *data)
20532 +{
20533 +       vx_reset_minmax(&vxi->limit);
20534 +       return 0;
20535 +}
20536 +
20537 +
20538 +int vc_rlimit_stat(struct vx_info *vxi, void __user *data)
20539 +{
20540 +       struct vcmd_rlimit_stat_v0 vc_data;
20541 +       struct _vx_limit *limit = &vxi->limit;
20542 +       int id;
20543 +
20544 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20545 +               return -EFAULT;
20546 +
20547 +       id = vc_data.id;
20548 +       if (!is_accounted_vlimit(id))
20549 +               return -EINVAL;
20550 +
20551 +       vx_limit_fixup(limit, id);
20552 +       vc_data.hits = atomic_read(&__rlim_lhit(limit, id));
20553 +       vc_data.value = __rlim_get(limit, id);
20554 +       vc_data.minimum = __rlim_rmin(limit, id);
20555 +       vc_data.maximum = __rlim_rmax(limit, id);
20556 +
20557 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20558 +               return -EFAULT;
20559 +       return 0;
20560 +}
20561 +
20562 +
20563 +void vx_vsi_meminfo(struct sysinfo *val)
20564 +{
20565 +#ifdef CONFIG_CGROUP_MEM_RES_CTLR
20566 +       struct mem_cgroup *mcg = mem_cgroup_from_task(current);
20567 +       u64 res_limit, res_usage;
20568 +
20569 +       if (!mcg)
20570 +               return;
20571 +
20572 +       res_limit = mem_cgroup_res_read_u64(mcg, RES_LIMIT);
20573 +       res_usage = mem_cgroup_res_read_u64(mcg, RES_USAGE);
20574 +
20575 +       if (res_limit != RESOURCE_MAX)
20576 +               val->totalram = (res_limit >> PAGE_SHIFT);
20577 +       val->freeram = val->totalram - (res_usage >> PAGE_SHIFT);
20578 +       val->bufferram = 0;
20579 +       val->totalhigh = 0;
20580 +       val->freehigh = 0;
20581 +#endif /* CONFIG_CGROUP_MEM_RES_CTLR */
20582 +       return;
20583 +}
20584 +
20585 +void vx_vsi_swapinfo(struct sysinfo *val)
20586 +{
20587 +#ifdef CONFIG_CGROUP_MEM_RES_CTLR
20588 +#ifdef CONFIG_CGROUP_MEM_RES_CTLR_SWAP
20589 +       struct mem_cgroup *mcg = mem_cgroup_from_task(current);
20590 +       u64 res_limit, res_usage, memsw_limit, memsw_usage;
20591 +       s64 swap_limit, swap_usage;
20592 +
20593 +       if (!mcg)
20594 +               return;
20595 +
20596 +       res_limit = mem_cgroup_res_read_u64(mcg, RES_LIMIT);
20597 +       res_usage = mem_cgroup_res_read_u64(mcg, RES_USAGE);
20598 +       memsw_limit = mem_cgroup_memsw_read_u64(mcg, RES_LIMIT);
20599 +       memsw_usage = mem_cgroup_memsw_read_u64(mcg, RES_USAGE);
20600 +
20601 +       if (res_limit == RESOURCE_MAX)
20602 +               return;
20603 +
20604 +       swap_limit = memsw_limit - res_limit;
20605 +       if (memsw_limit != RESOURCE_MAX)
20606 +               val->totalswap = swap_limit >> PAGE_SHIFT;
20607 +
20608 +       swap_usage = memsw_usage - res_usage;
20609 +       val->freeswap = (swap_usage < swap_limit) ?
20610 +               val->totalswap - (swap_usage >> PAGE_SHIFT) : 0;
20611 +#else  /* !CONFIG_CGROUP_MEM_RES_CTLR_SWAP */
20612 +       val->totalswap = 0;
20613 +       val->freeswap = 0;
20614 +#endif /* !CONFIG_CGROUP_MEM_RES_CTLR_SWAP */
20615 +#endif /* CONFIG_CGROUP_MEM_RES_CTLR */
20616 +       return;
20617 +}
20618 +
20619 +long vx_vsi_cached(struct sysinfo *val)
20620 +{
20621 +#ifdef CONFIG_CGROUP_MEM_RES_CTLR
20622 +       struct mem_cgroup *mcg = mem_cgroup_from_task(current);
20623 +
20624 +       return mem_cgroup_stat_read_cache(mcg);
20625 +#else
20626 +       return 0;
20627 +#endif
20628 +}
20629 +
20630 +
20631 +unsigned long vx_badness(struct task_struct *task, struct mm_struct *mm)
20632 +{
20633 +       struct vx_info *vxi = mm->mm_vx_info;
20634 +       unsigned long points;
20635 +       rlim_t v, w;
20636 +
20637 +       if (!vxi)
20638 +               return 0;
20639 +
20640 +       points = vxi->vx_badness_bias;
20641 +
20642 +       v = __vx_cres_array_fixup(&vxi->limit, VLA_RSS);
20643 +       w = __rlim_soft(&vxi->limit, RLIMIT_RSS);
20644 +       points += (v > w) ? (v - w) : 0;
20645 +
20646 +       return points;
20647 +}
20648 +
20649 diff -NurpP --minimal linux-2.6.38-rc8/kernel/vserver/limit_init.h linux-2.6.38-rc8-vs2.3.0.37-rc6/kernel/vserver/limit_init.h
20650 --- linux-2.6.38-rc8/kernel/vserver/limit_init.h        1970-01-01 01:00:00.000000000 +0100
20651 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/kernel/vserver/limit_init.h 2011-01-29 02:01:07.000000000 +0100
20652 @@ -0,0 +1,31 @@
20653 +
20654 +
20655 +static inline void vx_info_init_limit(struct _vx_limit *limit)
20656 +{
20657 +       int lim;
20658 +
20659 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
20660 +               __rlim_soft(limit, lim) = RLIM_INFINITY;
20661 +               __rlim_hard(limit, lim) = RLIM_INFINITY;
20662 +               __rlim_set(limit, lim, 0);
20663 +               atomic_set(&__rlim_lhit(limit, lim), 0);
20664 +               __rlim_rmin(limit, lim) = 0;
20665 +               __rlim_rmax(limit, lim) = 0;
20666 +       }
20667 +}
20668 +
20669 +static inline void vx_info_exit_limit(struct _vx_limit *limit)
20670 +{
20671 +       rlim_t value;
20672 +       int lim;
20673 +
20674 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
20675 +               if ((1 << lim) & VLIM_NOCHECK)
20676 +                       continue;
20677 +               value = __rlim_get(limit, lim);
20678 +               vxwprintk_xid(value,
20679 +                       "!!! limit: %p[%s,%d] = %ld on exit.",
20680 +                       limit, vlimit_name[lim], lim, (long)value);
20681 +       }
20682 +}
20683 +
20684 diff -NurpP --minimal linux-2.6.38-rc8/kernel/vserver/limit_proc.h linux-2.6.38-rc8-vs2.3.0.37-rc6/kernel/vserver/limit_proc.h
20685 --- linux-2.6.38-rc8/kernel/vserver/limit_proc.h        1970-01-01 01:00:00.000000000 +0100
20686 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/kernel/vserver/limit_proc.h 2011-01-29 02:01:07.000000000 +0100
20687 @@ -0,0 +1,57 @@
20688 +#ifndef _VX_LIMIT_PROC_H
20689 +#define _VX_LIMIT_PROC_H
20690 +
20691 +#include <linux/vserver/limit_int.h>
20692 +
20693 +
20694 +#define VX_LIMIT_FMT   ":\t%8ld\t%8ld/%8ld\t%8lld/%8lld\t%6d\n"
20695 +#define VX_LIMIT_TOP   \
20696 +       "Limit\t current\t     min/max\t\t    soft/hard\t\thits\n"
20697 +
20698 +#define VX_LIMIT_ARG(r)                                \
20699 +       (unsigned long)__rlim_get(limit, r),    \
20700 +       (unsigned long)__rlim_rmin(limit, r),   \
20701 +       (unsigned long)__rlim_rmax(limit, r),   \
20702 +       VX_VLIM(__rlim_soft(limit, r)),         \
20703 +       VX_VLIM(__rlim_hard(limit, r)),         \
20704 +       atomic_read(&__rlim_lhit(limit, r))
20705 +
20706 +static inline int vx_info_proc_limit(struct _vx_limit *limit, char *buffer)
20707 +{
20708 +       vx_limit_fixup(limit, -1);
20709 +       return sprintf(buffer, VX_LIMIT_TOP
20710 +               "PROC"  VX_LIMIT_FMT
20711 +               "VM"    VX_LIMIT_FMT
20712 +               "VML"   VX_LIMIT_FMT
20713 +               "RSS"   VX_LIMIT_FMT
20714 +               "ANON"  VX_LIMIT_FMT
20715 +               "RMAP"  VX_LIMIT_FMT
20716 +               "FILES" VX_LIMIT_FMT
20717 +               "OFD"   VX_LIMIT_FMT
20718 +               "LOCKS" VX_LIMIT_FMT
20719 +               "SOCK"  VX_LIMIT_FMT
20720 +               "MSGQ"  VX_LIMIT_FMT
20721 +               "SHM"   VX_LIMIT_FMT
20722 +               "SEMA"  VX_LIMIT_FMT
20723 +               "SEMS"  VX_LIMIT_FMT
20724 +               "DENT"  VX_LIMIT_FMT,
20725 +               VX_LIMIT_ARG(RLIMIT_NPROC),
20726 +               VX_LIMIT_ARG(RLIMIT_AS),
20727 +               VX_LIMIT_ARG(RLIMIT_MEMLOCK),
20728 +               VX_LIMIT_ARG(RLIMIT_RSS),
20729 +               VX_LIMIT_ARG(VLIMIT_ANON),
20730 +               VX_LIMIT_ARG(VLIMIT_MAPPED),
20731 +               VX_LIMIT_ARG(RLIMIT_NOFILE),
20732 +               VX_LIMIT_ARG(VLIMIT_OPENFD),
20733 +               VX_LIMIT_ARG(RLIMIT_LOCKS),
20734 +               VX_LIMIT_ARG(VLIMIT_NSOCK),
20735 +               VX_LIMIT_ARG(RLIMIT_MSGQUEUE),
20736 +               VX_LIMIT_ARG(VLIMIT_SHMEM),
20737 +               VX_LIMIT_ARG(VLIMIT_SEMARY),
20738 +               VX_LIMIT_ARG(VLIMIT_NSEMS),
20739 +               VX_LIMIT_ARG(VLIMIT_DENTRY));
20740 +}
20741 +
20742 +#endif /* _VX_LIMIT_PROC_H */
20743 +
20744 +
20745 diff -NurpP --minimal linux-2.6.38-rc8/kernel/vserver/network.c linux-2.6.38-rc8-vs2.3.0.37-rc6/kernel/vserver/network.c
20746 --- linux-2.6.38-rc8/kernel/vserver/network.c   1970-01-01 01:00:00.000000000 +0100
20747 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/kernel/vserver/network.c    2011-01-29 02:01:07.000000000 +0100
20748 @@ -0,0 +1,864 @@
20749 +/*
20750 + *  linux/kernel/vserver/network.c
20751 + *
20752 + *  Virtual Server: Network Support
20753 + *
20754 + *  Copyright (C) 2003-2007  Herbert Pötzl
20755 + *
20756 + *  V0.01  broken out from vcontext V0.05
20757 + *  V0.02  cleaned up implementation
20758 + *  V0.03  added equiv nx commands
20759 + *  V0.04  switch to RCU based hash
20760 + *  V0.05  and back to locking again
20761 + *  V0.06  changed vcmds to nxi arg
20762 + *  V0.07  have __create claim() the nxi
20763 + *
20764 + */
20765 +
20766 +#include <linux/err.h>
20767 +#include <linux/slab.h>
20768 +#include <linux/rcupdate.h>
20769 +
20770 +#include <linux/vs_network.h>
20771 +#include <linux/vs_pid.h>
20772 +#include <linux/vserver/network_cmd.h>
20773 +
20774 +
20775 +atomic_t nx_global_ctotal      = ATOMIC_INIT(0);
20776 +atomic_t nx_global_cactive     = ATOMIC_INIT(0);
20777 +
20778 +static struct kmem_cache *nx_addr_v4_cachep = NULL;
20779 +static struct kmem_cache *nx_addr_v6_cachep = NULL;
20780 +
20781 +
20782 +static int __init init_network(void)
20783 +{
20784 +       nx_addr_v4_cachep = kmem_cache_create("nx_v4_addr_cache",
20785 +               sizeof(struct nx_addr_v4), 0,
20786 +               SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
20787 +       nx_addr_v6_cachep = kmem_cache_create("nx_v6_addr_cache",
20788 +               sizeof(struct nx_addr_v6), 0,
20789 +               SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
20790 +       return 0;
20791 +}
20792 +
20793 +
20794 +/*     __alloc_nx_addr_v4()                                    */
20795 +
20796 +static inline struct nx_addr_v4 *__alloc_nx_addr_v4(void)
20797 +{
20798 +       struct nx_addr_v4 *nxa = kmem_cache_alloc(
20799 +               nx_addr_v4_cachep, GFP_KERNEL);
20800 +
20801 +       if (!IS_ERR(nxa))
20802 +               memset(nxa, 0, sizeof(*nxa));
20803 +       return nxa;
20804 +}
20805 +
20806 +/*     __dealloc_nx_addr_v4()                                  */
20807 +
20808 +static inline void __dealloc_nx_addr_v4(struct nx_addr_v4 *nxa)
20809 +{
20810 +       kmem_cache_free(nx_addr_v4_cachep, nxa);
20811 +}
20812 +
20813 +/*     __dealloc_nx_addr_v4_all()                              */
20814 +
20815 +static inline void __dealloc_nx_addr_v4_all(struct nx_addr_v4 *nxa)
20816 +{
20817 +       while (nxa) {
20818 +               struct nx_addr_v4 *next = nxa->next;
20819 +
20820 +               __dealloc_nx_addr_v4(nxa);
20821 +               nxa = next;
20822 +       }
20823 +}
20824 +
20825 +
20826 +#ifdef CONFIG_IPV6
20827 +
20828 +/*     __alloc_nx_addr_v6()                                    */
20829 +
20830 +static inline struct nx_addr_v6 *__alloc_nx_addr_v6(void)
20831 +{
20832 +       struct nx_addr_v6 *nxa = kmem_cache_alloc(
20833 +               nx_addr_v6_cachep, GFP_KERNEL);
20834 +
20835 +       if (!IS_ERR(nxa))
20836 +               memset(nxa, 0, sizeof(*nxa));
20837 +       return nxa;
20838 +}
20839 +
20840 +/*     __dealloc_nx_addr_v6()                                  */
20841 +
20842 +static inline void __dealloc_nx_addr_v6(struct nx_addr_v6 *nxa)
20843 +{
20844 +       kmem_cache_free(nx_addr_v6_cachep, nxa);
20845 +}
20846 +
20847 +/*     __dealloc_nx_addr_v6_all()                              */
20848 +
20849 +static inline void __dealloc_nx_addr_v6_all(struct nx_addr_v6 *nxa)
20850 +{
20851 +       while (nxa) {
20852 +               struct nx_addr_v6 *next = nxa->next;
20853 +
20854 +               __dealloc_nx_addr_v6(nxa);
20855 +               nxa = next;
20856 +       }
20857 +}
20858 +
20859 +#endif /* CONFIG_IPV6 */
20860 +
20861 +/*     __alloc_nx_info()
20862 +
20863 +       * allocate an initialized nx_info struct
20864 +       * doesn't make it visible (hash)                        */
20865 +
20866 +static struct nx_info *__alloc_nx_info(nid_t nid)
20867 +{
20868 +       struct nx_info *new = NULL;
20869 +
20870 +       vxdprintk(VXD_CBIT(nid, 1), "alloc_nx_info(%d)*", nid);
20871 +
20872 +       /* would this benefit from a slab cache? */
20873 +       new = kmalloc(sizeof(struct nx_info), GFP_KERNEL);
20874 +       if (!new)
20875 +               return 0;
20876 +
20877 +       memset(new, 0, sizeof(struct nx_info));
20878 +       new->nx_id = nid;
20879 +       INIT_HLIST_NODE(&new->nx_hlist);
20880 +       atomic_set(&new->nx_usecnt, 0);
20881 +       atomic_set(&new->nx_tasks, 0);
20882 +       new->nx_state = 0;
20883 +
20884 +       new->nx_flags = NXF_INIT_SET;
20885 +
20886 +       /* rest of init goes here */
20887 +
20888 +       new->v4_lback.s_addr = htonl(INADDR_LOOPBACK);
20889 +       new->v4_bcast.s_addr = htonl(INADDR_BROADCAST);
20890 +
20891 +       vxdprintk(VXD_CBIT(nid, 0),
20892 +               "alloc_nx_info(%d) = %p", nid, new);
20893 +       atomic_inc(&nx_global_ctotal);
20894 +       return new;
20895 +}
20896 +
20897 +/*     __dealloc_nx_info()
20898 +
20899 +       * final disposal of nx_info                             */
20900 +
20901 +static void __dealloc_nx_info(struct nx_info *nxi)
20902 +{
20903 +       vxdprintk(VXD_CBIT(nid, 0),
20904 +               "dealloc_nx_info(%p)", nxi);
20905 +
20906 +       nxi->nx_hlist.next = LIST_POISON1;
20907 +       nxi->nx_id = -1;
20908 +
20909 +       BUG_ON(atomic_read(&nxi->nx_usecnt));
20910 +       BUG_ON(atomic_read(&nxi->nx_tasks));
20911 +
20912 +       __dealloc_nx_addr_v4_all(nxi->v4.next);
20913 +
20914 +       nxi->nx_state |= NXS_RELEASED;
20915 +       kfree(nxi);
20916 +       atomic_dec(&nx_global_ctotal);
20917 +}
20918 +
20919 +static void __shutdown_nx_info(struct nx_info *nxi)
20920 +{
20921 +       nxi->nx_state |= NXS_SHUTDOWN;
20922 +       vs_net_change(nxi, VSC_NETDOWN);
20923 +}
20924 +
20925 +/*     exported stuff                                          */
20926 +
20927 +void free_nx_info(struct nx_info *nxi)
20928 +{
20929 +       /* context shutdown is mandatory */
20930 +       BUG_ON(nxi->nx_state != NXS_SHUTDOWN);
20931 +
20932 +       /* context must not be hashed */
20933 +       BUG_ON(nxi->nx_state & NXS_HASHED);
20934 +
20935 +       BUG_ON(atomic_read(&nxi->nx_usecnt));
20936 +       BUG_ON(atomic_read(&nxi->nx_tasks));
20937 +
20938 +       __dealloc_nx_info(nxi);
20939 +}
20940 +
20941 +
20942 +void __nx_set_lback(struct nx_info *nxi)
20943 +{
20944 +       int nid = nxi->nx_id;
20945 +       __be32 lback = htonl(INADDR_LOOPBACK ^ ((nid & 0xFFFF) << 8));
20946 +
20947 +       nxi->v4_lback.s_addr = lback;
20948 +}
20949 +
20950 +extern int __nx_inet_add_lback(__be32 addr);
20951 +extern int __nx_inet_del_lback(__be32 addr);
20952 +
20953 +
20954 +/*     hash table for nx_info hash */
20955 +
20956 +#define NX_HASH_SIZE   13
20957 +
20958 +struct hlist_head nx_info_hash[NX_HASH_SIZE];
20959 +
20960 +static spinlock_t nx_info_hash_lock = SPIN_LOCK_UNLOCKED;
20961 +
20962 +
20963 +static inline unsigned int __hashval(nid_t nid)
20964 +{
20965 +       return (nid % NX_HASH_SIZE);
20966 +}
20967 +
20968 +
20969 +
20970 +/*     __hash_nx_info()
20971 +
20972 +       * add the nxi to the global hash table
20973 +       * requires the hash_lock to be held                     */
20974 +
20975 +static inline void __hash_nx_info(struct nx_info *nxi)
20976 +{
20977 +       struct hlist_head *head;
20978 +
20979 +       vxd_assert_lock(&nx_info_hash_lock);
20980 +       vxdprintk(VXD_CBIT(nid, 4),
20981 +               "__hash_nx_info: %p[#%d]", nxi, nxi->nx_id);
20982 +
20983 +       /* context must not be hashed */
20984 +       BUG_ON(nx_info_state(nxi, NXS_HASHED));
20985 +
20986 +       nxi->nx_state |= NXS_HASHED;
20987 +       head = &nx_info_hash[__hashval(nxi->nx_id)];
20988 +       hlist_add_head(&nxi->nx_hlist, head);
20989 +       atomic_inc(&nx_global_cactive);
20990 +}
20991 +
20992 +/*     __unhash_nx_info()
20993 +
20994 +       * remove the nxi from the global hash table
20995 +       * requires the hash_lock to be held                     */
20996 +
20997 +static inline void __unhash_nx_info(struct nx_info *nxi)
20998 +{
20999 +       vxd_assert_lock(&nx_info_hash_lock);
21000 +       vxdprintk(VXD_CBIT(nid, 4),
21001 +               "__unhash_nx_info: %p[#%d.%d.%d]", nxi, nxi->nx_id,
21002 +               atomic_read(&nxi->nx_usecnt), atomic_read(&nxi->nx_tasks));
21003 +
21004 +       /* context must be hashed */
21005 +       BUG_ON(!nx_info_state(nxi, NXS_HASHED));
21006 +       /* but without tasks */
21007 +       BUG_ON(atomic_read(&nxi->nx_tasks));
21008 +
21009 +       nxi->nx_state &= ~NXS_HASHED;
21010 +       hlist_del(&nxi->nx_hlist);
21011 +       atomic_dec(&nx_global_cactive);
21012 +}
21013 +
21014 +
21015 +/*     __lookup_nx_info()
21016 +
21017 +       * requires the hash_lock to be held
21018 +       * doesn't increment the nx_refcnt                       */
21019 +
21020 +static inline struct nx_info *__lookup_nx_info(nid_t nid)
21021 +{
21022 +       struct hlist_head *head = &nx_info_hash[__hashval(nid)];
21023 +       struct hlist_node *pos;
21024 +       struct nx_info *nxi;
21025 +
21026 +       vxd_assert_lock(&nx_info_hash_lock);
21027 +       hlist_for_each(pos, head) {
21028 +               nxi = hlist_entry(pos, struct nx_info, nx_hlist);
21029 +
21030 +               if (nxi->nx_id == nid)
21031 +                       goto found;
21032 +       }
21033 +       nxi = NULL;
21034 +found:
21035 +       vxdprintk(VXD_CBIT(nid, 0),
21036 +               "__lookup_nx_info(#%u): %p[#%u]",
21037 +               nid, nxi, nxi ? nxi->nx_id : 0);
21038 +       return nxi;
21039 +}
21040 +
21041 +
21042 +/*     __create_nx_info()
21043 +
21044 +       * create the requested context
21045 +       * get(), claim() and hash it                            */
21046 +
21047 +static struct nx_info *__create_nx_info(int id)
21048 +{
21049 +       struct nx_info *new, *nxi = NULL;
21050 +
21051 +       vxdprintk(VXD_CBIT(nid, 1), "create_nx_info(%d)*", id);
21052 +
21053 +       if (!(new = __alloc_nx_info(id)))
21054 +               return ERR_PTR(-ENOMEM);
21055 +
21056 +       /* required to make dynamic xids unique */
21057 +       spin_lock(&nx_info_hash_lock);
21058 +
21059 +       /* static context requested */
21060 +       if ((nxi = __lookup_nx_info(id))) {
21061 +               vxdprintk(VXD_CBIT(nid, 0),
21062 +                       "create_nx_info(%d) = %p (already there)", id, nxi);
21063 +               if (nx_info_flags(nxi, NXF_STATE_SETUP, 0))
21064 +                       nxi = ERR_PTR(-EBUSY);
21065 +               else
21066 +                       nxi = ERR_PTR(-EEXIST);
21067 +               goto out_unlock;
21068 +       }
21069 +       /* new context */
21070 +       vxdprintk(VXD_CBIT(nid, 0),
21071 +               "create_nx_info(%d) = %p (new)", id, new);
21072 +       claim_nx_info(new, NULL);
21073 +       __nx_set_lback(new);
21074 +       __hash_nx_info(get_nx_info(new));
21075 +       nxi = new, new = NULL;
21076 +
21077 +out_unlock:
21078 +       spin_unlock(&nx_info_hash_lock);
21079 +       if (new)
21080 +               __dealloc_nx_info(new);
21081 +       return nxi;
21082 +}
21083 +
21084 +
21085 +
21086 +/*     exported stuff                                          */
21087 +
21088 +
21089 +void unhash_nx_info(struct nx_info *nxi)
21090 +{
21091 +       __shutdown_nx_info(nxi);
21092 +       spin_lock(&nx_info_hash_lock);
21093 +       __unhash_nx_info(nxi);
21094 +       spin_unlock(&nx_info_hash_lock);
21095 +}
21096 +
21097 +/*     lookup_nx_info()
21098 +
21099 +       * search for a nx_info and get() it
21100 +       * negative id means current                             */
21101 +
21102 +struct nx_info *lookup_nx_info(int id)
21103 +{
21104 +       struct nx_info *nxi = NULL;
21105 +
21106 +       if (id < 0) {
21107 +               nxi = get_nx_info(current_nx_info());
21108 +       } else if (id > 1) {
21109 +               spin_lock(&nx_info_hash_lock);
21110 +               nxi = get_nx_info(__lookup_nx_info(id));
21111 +               spin_unlock(&nx_info_hash_lock);
21112 +       }
21113 +       return nxi;
21114 +}
21115 +
21116 +/*     nid_is_hashed()
21117 +
21118 +       * verify that nid is still hashed                       */
21119 +
21120 +int nid_is_hashed(nid_t nid)
21121 +{
21122 +       int hashed;
21123 +
21124 +       spin_lock(&nx_info_hash_lock);
21125 +       hashed = (__lookup_nx_info(nid) != NULL);
21126 +       spin_unlock(&nx_info_hash_lock);
21127 +       return hashed;
21128 +}
21129 +
21130 +
21131 +#ifdef CONFIG_PROC_FS
21132 +
21133 +/*     get_nid_list()
21134 +
21135 +       * get a subset of hashed nids for proc
21136 +       * assumes size is at least one                          */
21137 +
21138 +int get_nid_list(int index, unsigned int *nids, int size)
21139 +{
21140 +       int hindex, nr_nids = 0;
21141 +
21142 +       /* only show current and children */
21143 +       if (!nx_check(0, VS_ADMIN | VS_WATCH)) {
21144 +               if (index > 0)
21145 +                       return 0;
21146 +               nids[nr_nids] = nx_current_nid();
21147 +               return 1;
21148 +       }
21149 +
21150 +       for (hindex = 0; hindex < NX_HASH_SIZE; hindex++) {
21151 +               struct hlist_head *head = &nx_info_hash[hindex];
21152 +               struct hlist_node *pos;
21153 +
21154 +               spin_lock(&nx_info_hash_lock);
21155 +               hlist_for_each(pos, head) {
21156 +                       struct nx_info *nxi;
21157 +
21158 +                       if (--index > 0)
21159 +                               continue;
21160 +
21161 +                       nxi = hlist_entry(pos, struct nx_info, nx_hlist);
21162 +                       nids[nr_nids] = nxi->nx_id;
21163 +                       if (++nr_nids >= size) {
21164 +                               spin_unlock(&nx_info_hash_lock);
21165 +                               goto out;
21166 +                       }
21167 +               }
21168 +               /* keep the lock time short */
21169 +               spin_unlock(&nx_info_hash_lock);
21170 +       }
21171 +out:
21172 +       return nr_nids;
21173 +}
21174 +#endif
21175 +
21176 +
21177 +/*
21178 + *     migrate task to new network
21179 + *     gets nxi, puts old_nxi on change
21180 + */
21181 +
21182 +int nx_migrate_task(struct task_struct *p, struct nx_info *nxi)
21183 +{
21184 +       struct nx_info *old_nxi;
21185 +       int ret = 0;
21186 +
21187 +       if (!p || !nxi)
21188 +               BUG();
21189 +
21190 +       vxdprintk(VXD_CBIT(nid, 5),
21191 +               "nx_migrate_task(%p,%p[#%d.%d.%d])",
21192 +               p, nxi, nxi->nx_id,
21193 +               atomic_read(&nxi->nx_usecnt),
21194 +               atomic_read(&nxi->nx_tasks));
21195 +
21196 +       if (nx_info_flags(nxi, NXF_INFO_PRIVATE, 0) &&
21197 +               !nx_info_flags(nxi, NXF_STATE_SETUP, 0))
21198 +               return -EACCES;
21199 +
21200 +       if (nx_info_state(nxi, NXS_SHUTDOWN))
21201 +               return -EFAULT;
21202 +
21203 +       /* maybe disallow this completely? */
21204 +       old_nxi = task_get_nx_info(p);
21205 +       if (old_nxi == nxi)
21206 +               goto out;
21207 +
21208 +       task_lock(p);
21209 +       if (old_nxi)
21210 +               clr_nx_info(&p->nx_info);
21211 +       claim_nx_info(nxi, p);
21212 +       set_nx_info(&p->nx_info, nxi);
21213 +       p->nid = nxi->nx_id;
21214 +       task_unlock(p);
21215 +
21216 +       vxdprintk(VXD_CBIT(nid, 5),
21217 +               "moved task %p into nxi:%p[#%d]",
21218 +               p, nxi, nxi->nx_id);
21219 +
21220 +       if (old_nxi)
21221 +               release_nx_info(old_nxi, p);
21222 +       ret = 0;
21223 +out:
21224 +       put_nx_info(old_nxi);
21225 +       return ret;
21226 +}
21227 +
21228 +
21229 +void nx_set_persistent(struct nx_info *nxi)
21230 +{
21231 +       vxdprintk(VXD_CBIT(nid, 6),
21232 +               "nx_set_persistent(%p[#%d])", nxi, nxi->nx_id);
21233 +
21234 +       get_nx_info(nxi);
21235 +       claim_nx_info(nxi, NULL);
21236 +}
21237 +
21238 +void nx_clear_persistent(struct nx_info *nxi)
21239 +{
21240 +       vxdprintk(VXD_CBIT(nid, 6),
21241 +               "nx_clear_persistent(%p[#%d])", nxi, nxi->nx_id);
21242 +
21243 +       release_nx_info(nxi, NULL);
21244 +       put_nx_info(nxi);
21245 +}
21246 +
21247 +void nx_update_persistent(struct nx_info *nxi)
21248 +{
21249 +       if (nx_info_flags(nxi, NXF_PERSISTENT, 0))
21250 +               nx_set_persistent(nxi);
21251 +       else
21252 +               nx_clear_persistent(nxi);
21253 +}
21254 +
21255 +/* vserver syscall commands below here */
21256 +
21257 +/* taks nid and nx_info functions */
21258 +
21259 +#include <asm/uaccess.h>
21260 +
21261 +
21262 +int vc_task_nid(uint32_t id)
21263 +{
21264 +       nid_t nid;
21265 +
21266 +       if (id) {
21267 +               struct task_struct *tsk;
21268 +
21269 +               read_lock(&tasklist_lock);
21270 +               tsk = find_task_by_real_pid(id);
21271 +               nid = (tsk) ? tsk->nid : -ESRCH;
21272 +               read_unlock(&tasklist_lock);
21273 +       } else
21274 +               nid = nx_current_nid();
21275 +       return nid;
21276 +}
21277 +
21278 +
21279 +int vc_nx_info(struct nx_info *nxi, void __user *data)
21280 +{
21281 +       struct vcmd_nx_info_v0 vc_data;
21282 +
21283 +       vc_data.nid = nxi->nx_id;
21284 +
21285 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21286 +               return -EFAULT;
21287 +       return 0;
21288 +}
21289 +
21290 +
21291 +/* network functions */
21292 +
21293 +int vc_net_create(uint32_t nid, void __user *data)
21294 +{
21295 +       struct vcmd_net_create vc_data = { .flagword = NXF_INIT_SET };
21296 +       struct nx_info *new_nxi;
21297 +       int ret;
21298 +
21299 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
21300 +               return -EFAULT;
21301 +
21302 +       if ((nid > MAX_S_CONTEXT) || (nid < 2))
21303 +               return -EINVAL;
21304 +
21305 +       new_nxi = __create_nx_info(nid);
21306 +       if (IS_ERR(new_nxi))
21307 +               return PTR_ERR(new_nxi);
21308 +
21309 +       /* initial flags */
21310 +       new_nxi->nx_flags = vc_data.flagword;
21311 +
21312 +       ret = -ENOEXEC;
21313 +       if (vs_net_change(new_nxi, VSC_NETUP))
21314 +               goto out;
21315 +
21316 +       ret = nx_migrate_task(current, new_nxi);
21317 +       if (ret)
21318 +               goto out;
21319 +
21320 +       /* return context id on success */
21321 +       ret = new_nxi->nx_id;
21322 +
21323 +       /* get a reference for persistent contexts */
21324 +       if ((vc_data.flagword & NXF_PERSISTENT))
21325 +               nx_set_persistent(new_nxi);
21326 +out:
21327 +       release_nx_info(new_nxi, NULL);
21328 +       put_nx_info(new_nxi);
21329 +       return ret;
21330 +}
21331 +
21332 +
21333 +int vc_net_migrate(struct nx_info *nxi, void __user *data)
21334 +{
21335 +       return nx_migrate_task(current, nxi);
21336 +}
21337 +
21338 +
21339 +
21340 +int do_add_v4_addr(struct nx_info *nxi, __be32 ip, __be32 ip2, __be32 mask,
21341 +       uint16_t type, uint16_t flags)
21342 +{
21343 +       struct nx_addr_v4 *nxa = &nxi->v4;
21344 +
21345 +       if (NX_IPV4(nxi)) {
21346 +               /* locate last entry */
21347 +               for (; nxa->next; nxa = nxa->next);
21348 +               nxa->next = __alloc_nx_addr_v4();
21349 +               nxa = nxa->next;
21350 +
21351 +               if (IS_ERR(nxa))
21352 +                       return PTR_ERR(nxa);
21353 +       }
21354 +
21355 +       if (nxi->v4.next)
21356 +               /* remove single ip for ip list */
21357 +               nxi->nx_flags &= ~NXF_SINGLE_IP;
21358 +
21359 +       nxa->ip[0].s_addr = ip;
21360 +       nxa->ip[1].s_addr = ip2;
21361 +       nxa->mask.s_addr = mask;
21362 +       nxa->type = type;
21363 +       nxa->flags = flags;
21364 +       return 0;
21365 +}
21366 +
21367 +
21368 +int vc_net_add(struct nx_info *nxi, void __user *data)
21369 +{
21370 +       struct vcmd_net_addr_v0 vc_data;
21371 +       int index, ret = 0;
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_IPV4:
21378 +               if ((vc_data.count < 1) || (vc_data.count > 4))
21379 +                       return -EINVAL;
21380 +
21381 +               index = 0;
21382 +               while (index < vc_data.count) {
21383 +                       ret = do_add_v4_addr(nxi, vc_data.ip[index].s_addr, 0,
21384 +                               vc_data.mask[index].s_addr, NXA_TYPE_ADDR, 0);
21385 +                       if (ret)
21386 +                               return ret;
21387 +                       index++;
21388 +               }
21389 +               ret = index;
21390 +               break;
21391 +
21392 +       case NXA_TYPE_IPV4|NXA_MOD_BCAST:
21393 +               nxi->v4_bcast = vc_data.ip[0];
21394 +               ret = 1;
21395 +               break;
21396 +
21397 +       case NXA_TYPE_IPV4|NXA_MOD_LBACK:
21398 +               nxi->v4_lback = vc_data.ip[0];
21399 +               ret = 1;
21400 +               break;
21401 +
21402 +       default:
21403 +               ret = -EINVAL;
21404 +               break;
21405 +       }
21406 +       return ret;
21407 +}
21408 +
21409 +int vc_net_remove(struct nx_info *nxi, void __user *data)
21410 +{
21411 +       struct vcmd_net_addr_v0 vc_data;
21412 +
21413 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
21414 +               return -EFAULT;
21415 +
21416 +       switch (vc_data.type) {
21417 +       case NXA_TYPE_ANY:
21418 +               __dealloc_nx_addr_v4_all(xchg(&nxi->v4.next, NULL));
21419 +               memset(&nxi->v4, 0, sizeof(nxi->v4));
21420 +               break;
21421 +
21422 +       default:
21423 +               return -EINVAL;
21424 +       }
21425 +       return 0;
21426 +}
21427 +
21428 +
21429 +int vc_net_add_ipv4(struct nx_info *nxi, void __user *data)
21430 +{
21431 +       struct vcmd_net_addr_ipv4_v1 vc_data;
21432 +
21433 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
21434 +               return -EFAULT;
21435 +
21436 +       switch (vc_data.type) {
21437 +       case NXA_TYPE_ADDR:
21438 +       case NXA_TYPE_RANGE:
21439 +       case NXA_TYPE_MASK:
21440 +               return do_add_v4_addr(nxi, vc_data.ip.s_addr, 0,
21441 +                       vc_data.mask.s_addr, vc_data.type, vc_data.flags);
21442 +
21443 +       case NXA_TYPE_ADDR | NXA_MOD_BCAST:
21444 +               nxi->v4_bcast = vc_data.ip;
21445 +               break;
21446 +
21447 +       case NXA_TYPE_ADDR | NXA_MOD_LBACK:
21448 +               nxi->v4_lback = vc_data.ip;
21449 +               break;
21450 +
21451 +       default:
21452 +               return -EINVAL;
21453 +       }
21454 +       return 0;
21455 +}
21456 +
21457 +int vc_net_remove_ipv4(struct nx_info *nxi, void __user *data)
21458 +{
21459 +       struct vcmd_net_addr_ipv4_v1 vc_data;
21460 +
21461 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
21462 +               return -EFAULT;
21463 +
21464 +       switch (vc_data.type) {
21465 +/*     case NXA_TYPE_ADDR:
21466 +               break;          */
21467 +
21468 +       case NXA_TYPE_ANY:
21469 +               __dealloc_nx_addr_v4_all(xchg(&nxi->v4.next, NULL));
21470 +               memset(&nxi->v4, 0, sizeof(nxi->v4));
21471 +               break;
21472 +
21473 +       default:
21474 +               return -EINVAL;
21475 +       }
21476 +       return 0;
21477 +}
21478 +
21479 +
21480 +#ifdef CONFIG_IPV6
21481 +
21482 +int do_add_v6_addr(struct nx_info *nxi,
21483 +       struct in6_addr *ip, struct in6_addr *mask,
21484 +       uint32_t prefix, uint16_t type, uint16_t flags)
21485 +{
21486 +       struct nx_addr_v6 *nxa = &nxi->v6;
21487 +
21488 +       if (NX_IPV6(nxi)) {
21489 +               /* locate last entry */
21490 +               for (; nxa->next; nxa = nxa->next);
21491 +               nxa->next = __alloc_nx_addr_v6();
21492 +               nxa = nxa->next;
21493 +
21494 +               if (IS_ERR(nxa))
21495 +                       return PTR_ERR(nxa);
21496 +       }
21497 +
21498 +       nxa->ip = *ip;
21499 +       nxa->mask = *mask;
21500 +       nxa->prefix = prefix;
21501 +       nxa->type = type;
21502 +       nxa->flags = flags;
21503 +       return 0;
21504 +}
21505 +
21506 +
21507 +int vc_net_add_ipv6(struct nx_info *nxi, void __user *data)
21508 +{
21509 +       struct vcmd_net_addr_ipv6_v1 vc_data;
21510 +
21511 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
21512 +               return -EFAULT;
21513 +
21514 +       switch (vc_data.type) {
21515 +       case NXA_TYPE_ADDR:
21516 +       case NXA_TYPE_MASK:
21517 +               return do_add_v6_addr(nxi, &vc_data.ip, &vc_data.mask,
21518 +                       vc_data.prefix, vc_data.type, vc_data.flags);
21519 +       default:
21520 +               return -EINVAL;
21521 +       }
21522 +       return 0;
21523 +}
21524 +
21525 +int vc_net_remove_ipv6(struct nx_info *nxi, void __user *data)
21526 +{
21527 +       struct vcmd_net_addr_ipv6_v1 vc_data;
21528 +
21529 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
21530 +               return -EFAULT;
21531 +
21532 +       switch (vc_data.type) {
21533 +       case NXA_TYPE_ANY:
21534 +               __dealloc_nx_addr_v6_all(xchg(&nxi->v6.next, NULL));
21535 +               memset(&nxi->v6, 0, sizeof(nxi->v6));
21536 +               break;
21537 +
21538 +       default:
21539 +               return -EINVAL;
21540 +       }
21541 +       return 0;
21542 +}
21543 +
21544 +#endif /* CONFIG_IPV6 */
21545 +
21546 +
21547 +int vc_get_nflags(struct nx_info *nxi, void __user *data)
21548 +{
21549 +       struct vcmd_net_flags_v0 vc_data;
21550 +
21551 +       vc_data.flagword = nxi->nx_flags;
21552 +
21553 +       /* special STATE flag handling */
21554 +       vc_data.mask = vs_mask_flags(~0ULL, nxi->nx_flags, NXF_ONE_TIME);
21555 +
21556 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21557 +               return -EFAULT;
21558 +       return 0;
21559 +}
21560 +
21561 +int vc_set_nflags(struct nx_info *nxi, void __user *data)
21562 +{
21563 +       struct vcmd_net_flags_v0 vc_data;
21564 +       uint64_t mask, trigger;
21565 +
21566 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21567 +               return -EFAULT;
21568 +
21569 +       /* special STATE flag handling */
21570 +       mask = vs_mask_mask(vc_data.mask, nxi->nx_flags, NXF_ONE_TIME);
21571 +       trigger = (mask & nxi->nx_flags) ^ (mask & vc_data.flagword);
21572 +
21573 +       nxi->nx_flags = vs_mask_flags(nxi->nx_flags,
21574 +               vc_data.flagword, mask);
21575 +       if (trigger & NXF_PERSISTENT)
21576 +               nx_update_persistent(nxi);
21577 +
21578 +       return 0;
21579 +}
21580 +
21581 +int vc_get_ncaps(struct nx_info *nxi, void __user *data)
21582 +{
21583 +       struct vcmd_net_caps_v0 vc_data;
21584 +
21585 +       vc_data.ncaps = nxi->nx_ncaps;
21586 +       vc_data.cmask = ~0ULL;
21587 +
21588 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21589 +               return -EFAULT;
21590 +       return 0;
21591 +}
21592 +
21593 +int vc_set_ncaps(struct nx_info *nxi, void __user *data)
21594 +{
21595 +       struct vcmd_net_caps_v0 vc_data;
21596 +
21597 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21598 +               return -EFAULT;
21599 +
21600 +       nxi->nx_ncaps = vs_mask_flags(nxi->nx_ncaps,
21601 +               vc_data.ncaps, vc_data.cmask);
21602 +       return 0;
21603 +}
21604 +
21605 +
21606 +#include <linux/module.h>
21607 +
21608 +module_init(init_network);
21609 +
21610 +EXPORT_SYMBOL_GPL(free_nx_info);
21611 +EXPORT_SYMBOL_GPL(unhash_nx_info);
21612 +
21613 diff -NurpP --minimal linux-2.6.38-rc8/kernel/vserver/proc.c linux-2.6.38-rc8-vs2.3.0.37-rc6/kernel/vserver/proc.c
21614 --- linux-2.6.38-rc8/kernel/vserver/proc.c      1970-01-01 01:00:00.000000000 +0100
21615 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/kernel/vserver/proc.c       2011-01-29 02:01:07.000000000 +0100
21616 @@ -0,0 +1,1098 @@
21617 +/*
21618 + *  linux/kernel/vserver/proc.c
21619 + *
21620 + *  Virtual Context Support
21621 + *
21622 + *  Copyright (C) 2003-2007  Herbert Pötzl
21623 + *
21624 + *  V0.01  basic structure
21625 + *  V0.02  adaptation vs1.3.0
21626 + *  V0.03  proc permissions
21627 + *  V0.04  locking/generic
21628 + *  V0.05  next generation procfs
21629 + *  V0.06  inode validation
21630 + *  V0.07  generic rewrite vid
21631 + *  V0.08  remove inode type
21632 + *
21633 + */
21634 +
21635 +#include <linux/proc_fs.h>
21636 +#include <linux/fs_struct.h>
21637 +#include <linux/mount.h>
21638 +#include <asm/unistd.h>
21639 +
21640 +#include <linux/vs_context.h>
21641 +#include <linux/vs_network.h>
21642 +#include <linux/vs_cvirt.h>
21643 +
21644 +#include <linux/in.h>
21645 +#include <linux/inetdevice.h>
21646 +#include <linux/vs_inet.h>
21647 +#include <linux/vs_inet6.h>
21648 +
21649 +#include <linux/vserver/global.h>
21650 +
21651 +#include "cvirt_proc.h"
21652 +#include "cacct_proc.h"
21653 +#include "limit_proc.h"
21654 +#include "sched_proc.h"
21655 +#include "vci_config.h"
21656 +
21657 +
21658 +static inline char *print_cap_t(char *buffer, kernel_cap_t *c)
21659 +{
21660 +       unsigned __capi;
21661 +
21662 +       CAP_FOR_EACH_U32(__capi) {
21663 +               buffer += sprintf(buffer, "%08x",
21664 +                       c->cap[(_KERNEL_CAPABILITY_U32S-1) - __capi]);
21665 +       }
21666 +       return buffer;
21667 +}
21668 +
21669 +
21670 +static struct proc_dir_entry *proc_virtual;
21671 +
21672 +static struct proc_dir_entry *proc_virtnet;
21673 +
21674 +
21675 +/* first the actual feeds */
21676 +
21677 +
21678 +static int proc_vci(char *buffer)
21679 +{
21680 +       return sprintf(buffer,
21681 +               "VCIVersion:\t%04x:%04x\n"
21682 +               "VCISyscall:\t%d\n"
21683 +               "VCIKernel:\t%08x\n",
21684 +               VCI_VERSION >> 16,
21685 +               VCI_VERSION & 0xFFFF,
21686 +               __NR_vserver,
21687 +               vci_kernel_config());
21688 +}
21689 +
21690 +static int proc_virtual_info(char *buffer)
21691 +{
21692 +       return proc_vci(buffer);
21693 +}
21694 +
21695 +static int proc_virtual_status(char *buffer)
21696 +{
21697 +       return sprintf(buffer,
21698 +               "#CTotal:\t%d\n"
21699 +               "#CActive:\t%d\n"
21700 +               "#NSProxy:\t%d\t%d %d %d %d %d %d\n"
21701 +               "#InitTask:\t%d\t%d %d\n",
21702 +               atomic_read(&vx_global_ctotal),
21703 +               atomic_read(&vx_global_cactive),
21704 +               atomic_read(&vs_global_nsproxy),
21705 +               atomic_read(&vs_global_fs),
21706 +               atomic_read(&vs_global_mnt_ns),
21707 +               atomic_read(&vs_global_uts_ns),
21708 +               atomic_read(&nr_ipc_ns),
21709 +               atomic_read(&vs_global_user_ns),
21710 +               atomic_read(&vs_global_pid_ns),
21711 +               atomic_read(&init_task.usage),
21712 +               atomic_read(&init_task.nsproxy->count),
21713 +               init_task.fs->users);
21714 +}
21715 +
21716 +
21717 +int proc_vxi_info(struct vx_info *vxi, char *buffer)
21718 +{
21719 +       int length;
21720 +
21721 +       length = sprintf(buffer,
21722 +               "ID:\t%d\n"
21723 +               "Info:\t%p\n"
21724 +               "Init:\t%d\n"
21725 +               "OOM:\t%lld\n",
21726 +               vxi->vx_id,
21727 +               vxi,
21728 +               vxi->vx_initpid,
21729 +               vxi->vx_badness_bias);
21730 +       return length;
21731 +}
21732 +
21733 +int proc_vxi_status(struct vx_info *vxi, char *buffer)
21734 +{
21735 +       char *orig = buffer;
21736 +
21737 +       buffer += sprintf(buffer,
21738 +               "UseCnt:\t%d\n"
21739 +               "Tasks:\t%d\n"
21740 +               "Flags:\t%016llx\n",
21741 +               atomic_read(&vxi->vx_usecnt),
21742 +               atomic_read(&vxi->vx_tasks),
21743 +               (unsigned long long)vxi->vx_flags);
21744 +
21745 +       buffer += sprintf(buffer, "BCaps:\t");
21746 +       buffer = print_cap_t(buffer, &vxi->vx_bcaps);
21747 +       buffer += sprintf(buffer, "\n");
21748 +
21749 +       buffer += sprintf(buffer,
21750 +               "CCaps:\t%016llx\n"
21751 +               "Spaces:\t%08lx %08lx\n",
21752 +               (unsigned long long)vxi->vx_ccaps,
21753 +               vxi->space[0].vx_nsmask, vxi->space[1].vx_nsmask);
21754 +       return buffer - orig;
21755 +}
21756 +
21757 +int proc_vxi_limit(struct vx_info *vxi, char *buffer)
21758 +{
21759 +       return vx_info_proc_limit(&vxi->limit, buffer);
21760 +}
21761 +
21762 +int proc_vxi_sched(struct vx_info *vxi, char *buffer)
21763 +{
21764 +       int cpu, length;
21765 +
21766 +       length = vx_info_proc_sched(&vxi->sched, buffer);
21767 +       for_each_online_cpu(cpu) {
21768 +               length += vx_info_proc_sched_pc(
21769 +                       &vx_per_cpu(vxi, sched_pc, cpu),
21770 +                       buffer + length, cpu);
21771 +       }
21772 +       return length;
21773 +}
21774 +
21775 +int proc_vxi_nsproxy0(struct vx_info *vxi, char *buffer)
21776 +{
21777 +       return vx_info_proc_nsproxy(vxi->space[0].vx_nsproxy, buffer);
21778 +}
21779 +
21780 +int proc_vxi_nsproxy1(struct vx_info *vxi, char *buffer)
21781 +{
21782 +       return vx_info_proc_nsproxy(vxi->space[1].vx_nsproxy, buffer);
21783 +}
21784 +
21785 +int proc_vxi_cvirt(struct vx_info *vxi, char *buffer)
21786 +{
21787 +       int cpu, length;
21788 +
21789 +       vx_update_load(vxi);
21790 +       length = vx_info_proc_cvirt(&vxi->cvirt, buffer);
21791 +       for_each_online_cpu(cpu) {
21792 +               length += vx_info_proc_cvirt_pc(
21793 +                       &vx_per_cpu(vxi, cvirt_pc, cpu),
21794 +                       buffer + length, cpu);
21795 +       }
21796 +       return length;
21797 +}
21798 +
21799 +int proc_vxi_cacct(struct vx_info *vxi, char *buffer)
21800 +{
21801 +       return vx_info_proc_cacct(&vxi->cacct, buffer);
21802 +}
21803 +
21804 +
21805 +static int proc_virtnet_info(char *buffer)
21806 +{
21807 +       return proc_vci(buffer);
21808 +}
21809 +
21810 +static int proc_virtnet_status(char *buffer)
21811 +{
21812 +       return sprintf(buffer,
21813 +               "#CTotal:\t%d\n"
21814 +               "#CActive:\t%d\n",
21815 +               atomic_read(&nx_global_ctotal),
21816 +               atomic_read(&nx_global_cactive));
21817 +}
21818 +
21819 +int proc_nxi_info(struct nx_info *nxi, char *buffer)
21820 +{
21821 +       struct nx_addr_v4 *v4a;
21822 +#ifdef CONFIG_IPV6
21823 +       struct nx_addr_v6 *v6a;
21824 +#endif
21825 +       int length, i;
21826 +
21827 +       length = sprintf(buffer,
21828 +               "ID:\t%d\n"
21829 +               "Info:\t%p\n"
21830 +               "Bcast:\t" NIPQUAD_FMT "\n"
21831 +               "Lback:\t" NIPQUAD_FMT "\n",
21832 +               nxi->nx_id,
21833 +               nxi,
21834 +               NIPQUAD(nxi->v4_bcast.s_addr),
21835 +               NIPQUAD(nxi->v4_lback.s_addr));
21836 +
21837 +       if (!NX_IPV4(nxi))
21838 +               goto skip_v4;
21839 +       for (i = 0, v4a = &nxi->v4; v4a; i++, v4a = v4a->next)
21840 +               length += sprintf(buffer + length, "%d:\t" NXAV4_FMT "\n",
21841 +                       i, NXAV4(v4a));
21842 +skip_v4:
21843 +#ifdef CONFIG_IPV6
21844 +       if (!NX_IPV6(nxi))
21845 +               goto skip_v6;
21846 +       for (i = 0, v6a = &nxi->v6; v6a; i++, v6a = v6a->next)
21847 +               length += sprintf(buffer + length, "%d:\t" NXAV6_FMT "\n",
21848 +                       i, NXAV6(v6a));
21849 +skip_v6:
21850 +#endif
21851 +       return length;
21852 +}
21853 +
21854 +int proc_nxi_status(struct nx_info *nxi, char *buffer)
21855 +{
21856 +       int length;
21857 +
21858 +       length = sprintf(buffer,
21859 +               "UseCnt:\t%d\n"
21860 +               "Tasks:\t%d\n"
21861 +               "Flags:\t%016llx\n"
21862 +               "NCaps:\t%016llx\n",
21863 +               atomic_read(&nxi->nx_usecnt),
21864 +               atomic_read(&nxi->nx_tasks),
21865 +               (unsigned long long)nxi->nx_flags,
21866 +               (unsigned long long)nxi->nx_ncaps);
21867 +       return length;
21868 +}
21869 +
21870 +
21871 +
21872 +/* here the inode helpers */
21873 +
21874 +struct vs_entry {
21875 +       int len;
21876 +       char *name;
21877 +       mode_t mode;
21878 +       struct inode_operations *iop;
21879 +       struct file_operations *fop;
21880 +       union proc_op op;
21881 +};
21882 +
21883 +static struct inode *vs_proc_make_inode(struct super_block *sb, struct vs_entry *p)
21884 +{
21885 +       struct inode *inode = new_inode(sb);
21886 +
21887 +       if (!inode)
21888 +               goto out;
21889 +
21890 +       inode->i_mode = p->mode;
21891 +       if (p->iop)
21892 +               inode->i_op = p->iop;
21893 +       if (p->fop)
21894 +               inode->i_fop = p->fop;
21895 +
21896 +       inode->i_nlink = (p->mode & S_IFDIR) ? 2 : 1;
21897 +       inode->i_flags |= S_IMMUTABLE;
21898 +
21899 +       inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
21900 +
21901 +       inode->i_uid = 0;
21902 +       inode->i_gid = 0;
21903 +       inode->i_tag = 0;
21904 +out:
21905 +       return inode;
21906 +}
21907 +
21908 +static struct dentry *vs_proc_instantiate(struct inode *dir,
21909 +       struct dentry *dentry, int id, void *ptr)
21910 +{
21911 +       struct vs_entry *p = ptr;
21912 +       struct inode *inode = vs_proc_make_inode(dir->i_sb, p);
21913 +       struct dentry *error = ERR_PTR(-EINVAL);
21914 +
21915 +       if (!inode)
21916 +               goto out;
21917 +
21918 +       PROC_I(inode)->op = p->op;
21919 +       PROC_I(inode)->fd = id;
21920 +       d_add(dentry, inode);
21921 +       error = NULL;
21922 +out:
21923 +       return error;
21924 +}
21925 +
21926 +/* Lookups */
21927 +
21928 +typedef struct dentry *instantiate_t(struct inode *, struct dentry *, int, void *);
21929 +
21930 +/*
21931 + * Fill a directory entry.
21932 + *
21933 + * If possible create the dcache entry and derive our inode number and
21934 + * file type from dcache entry.
21935 + *
21936 + * Since all of the proc inode numbers are dynamically generated, the inode
21937 + * numbers do not exist until the inode is cache.  This means creating the
21938 + * the dcache entry in readdir is necessary to keep the inode numbers
21939 + * reported by readdir in sync with the inode numbers reported
21940 + * by stat.
21941 + */
21942 +static int proc_fill_cache(struct file *filp, void *dirent, filldir_t filldir,
21943 +       char *name, int len, instantiate_t instantiate, int id, void *ptr)
21944 +{
21945 +       struct dentry *child, *dir = filp->f_dentry;
21946 +       struct inode *inode;
21947 +       struct qstr qname;
21948 +       ino_t ino = 0;
21949 +       unsigned type = DT_UNKNOWN;
21950 +
21951 +       qname.name = name;
21952 +       qname.len  = len;
21953 +       qname.hash = full_name_hash(name, len);
21954 +
21955 +       child = d_lookup(dir, &qname);
21956 +       if (!child) {
21957 +               struct dentry *new;
21958 +               new = d_alloc(dir, &qname);
21959 +               if (new) {
21960 +                       child = instantiate(dir->d_inode, new, id, ptr);
21961 +                       if (child)
21962 +                               dput(new);
21963 +                       else
21964 +                               child = new;
21965 +               }
21966 +       }
21967 +       if (!child || IS_ERR(child) || !child->d_inode)
21968 +               goto end_instantiate;
21969 +       inode = child->d_inode;
21970 +       if (inode) {
21971 +               ino = inode->i_ino;
21972 +               type = inode->i_mode >> 12;
21973 +       }
21974 +       dput(child);
21975 +end_instantiate:
21976 +       if (!ino)
21977 +               ino = find_inode_number(dir, &qname);
21978 +       if (!ino)
21979 +               ino = 1;
21980 +       return filldir(dirent, name, len, filp->f_pos, ino, type);
21981 +}
21982 +
21983 +
21984 +
21985 +/* get and revalidate vx_info/xid */
21986 +
21987 +static inline
21988 +struct vx_info *get_proc_vx_info(struct inode *inode)
21989 +{
21990 +       return lookup_vx_info(PROC_I(inode)->fd);
21991 +}
21992 +
21993 +static int proc_xid_revalidate(struct dentry *dentry, struct nameidata *nd)
21994 +{
21995 +       struct inode *inode = dentry->d_inode;
21996 +       xid_t xid = PROC_I(inode)->fd;
21997 +
21998 +       if (!xid || xid_is_hashed(xid))
21999 +               return 1;
22000 +       d_drop(dentry);
22001 +       return 0;
22002 +}
22003 +
22004 +
22005 +/* get and revalidate nx_info/nid */
22006 +
22007 +static int proc_nid_revalidate(struct dentry *dentry, struct nameidata *nd)
22008 +{
22009 +       struct inode *inode = dentry->d_inode;
22010 +       nid_t nid = PROC_I(inode)->fd;
22011 +
22012 +       if (!nid || nid_is_hashed(nid))
22013 +               return 1;
22014 +       d_drop(dentry);
22015 +       return 0;
22016 +}
22017 +
22018 +
22019 +
22020 +#define PROC_BLOCK_SIZE (PAGE_SIZE - 1024)
22021 +
22022 +static ssize_t proc_vs_info_read(struct file *file, char __user *buf,
22023 +                         size_t count, loff_t *ppos)
22024 +{
22025 +       struct inode *inode = file->f_dentry->d_inode;
22026 +       unsigned long page;
22027 +       ssize_t length = 0;
22028 +
22029 +       if (count > PROC_BLOCK_SIZE)
22030 +               count = PROC_BLOCK_SIZE;
22031 +
22032 +       /* fade that out as soon as stable */
22033 +       WARN_ON(PROC_I(inode)->fd);
22034 +
22035 +       if (!(page = __get_free_page(GFP_KERNEL)))
22036 +               return -ENOMEM;
22037 +
22038 +       BUG_ON(!PROC_I(inode)->op.proc_vs_read);
22039 +       length = PROC_I(inode)->op.proc_vs_read((char *)page);
22040 +
22041 +       if (length >= 0)
22042 +               length = simple_read_from_buffer(buf, count, ppos,
22043 +                       (char *)page, length);
22044 +
22045 +       free_page(page);
22046 +       return length;
22047 +}
22048 +
22049 +static ssize_t proc_vx_info_read(struct file *file, char __user *buf,
22050 +                         size_t count, loff_t *ppos)
22051 +{
22052 +       struct inode *inode = file->f_dentry->d_inode;
22053 +       struct vx_info *vxi = NULL;
22054 +       xid_t xid = PROC_I(inode)->fd;
22055 +       unsigned long page;
22056 +       ssize_t length = 0;
22057 +
22058 +       if (count > PROC_BLOCK_SIZE)
22059 +               count = PROC_BLOCK_SIZE;
22060 +
22061 +       /* fade that out as soon as stable */
22062 +       WARN_ON(!xid);
22063 +       vxi = lookup_vx_info(xid);
22064 +       if (!vxi)
22065 +               goto out;
22066 +
22067 +       length = -ENOMEM;
22068 +       if (!(page = __get_free_page(GFP_KERNEL)))
22069 +               goto out_put;
22070 +
22071 +       BUG_ON(!PROC_I(inode)->op.proc_vxi_read);
22072 +       length = PROC_I(inode)->op.proc_vxi_read(vxi, (char *)page);
22073 +
22074 +       if (length >= 0)
22075 +               length = simple_read_from_buffer(buf, count, ppos,
22076 +                       (char *)page, length);
22077 +
22078 +       free_page(page);
22079 +out_put:
22080 +       put_vx_info(vxi);
22081 +out:
22082 +       return length;
22083 +}
22084 +
22085 +static ssize_t proc_nx_info_read(struct file *file, char __user *buf,
22086 +                         size_t count, loff_t *ppos)
22087 +{
22088 +       struct inode *inode = file->f_dentry->d_inode;
22089 +       struct nx_info *nxi = NULL;
22090 +       nid_t nid = PROC_I(inode)->fd;
22091 +       unsigned long page;
22092 +       ssize_t length = 0;
22093 +
22094 +       if (count > PROC_BLOCK_SIZE)
22095 +               count = PROC_BLOCK_SIZE;
22096 +
22097 +       /* fade that out as soon as stable */
22098 +       WARN_ON(!nid);
22099 +       nxi = lookup_nx_info(nid);
22100 +       if (!nxi)
22101 +               goto out;
22102 +
22103 +       length = -ENOMEM;
22104 +       if (!(page = __get_free_page(GFP_KERNEL)))
22105 +               goto out_put;
22106 +
22107 +       BUG_ON(!PROC_I(inode)->op.proc_nxi_read);
22108 +       length = PROC_I(inode)->op.proc_nxi_read(nxi, (char *)page);
22109 +
22110 +       if (length >= 0)
22111 +               length = simple_read_from_buffer(buf, count, ppos,
22112 +                       (char *)page, length);
22113 +
22114 +       free_page(page);
22115 +out_put:
22116 +       put_nx_info(nxi);
22117 +out:
22118 +       return length;
22119 +}
22120 +
22121 +
22122 +
22123 +/* here comes the lower level */
22124 +
22125 +
22126 +#define NOD(NAME, MODE, IOP, FOP, OP) {        \
22127 +       .len  = sizeof(NAME) - 1,       \
22128 +       .name = (NAME),                 \
22129 +       .mode = MODE,                   \
22130 +       .iop  = IOP,                    \
22131 +       .fop  = FOP,                    \
22132 +       .op   = OP,                     \
22133 +}
22134 +
22135 +
22136 +#define DIR(NAME, MODE, OTYPE)                         \
22137 +       NOD(NAME, (S_IFDIR | (MODE)),                   \
22138 +               &proc_ ## OTYPE ## _inode_operations,   \
22139 +               &proc_ ## OTYPE ## _file_operations, { } )
22140 +
22141 +#define INF(NAME, MODE, OTYPE)                         \
22142 +       NOD(NAME, (S_IFREG | (MODE)), NULL,             \
22143 +               &proc_vs_info_file_operations,          \
22144 +               { .proc_vs_read = &proc_##OTYPE } )
22145 +
22146 +#define VINF(NAME, MODE, OTYPE)                                \
22147 +       NOD(NAME, (S_IFREG | (MODE)), NULL,             \
22148 +               &proc_vx_info_file_operations,          \
22149 +               { .proc_vxi_read = &proc_##OTYPE } )
22150 +
22151 +#define NINF(NAME, MODE, OTYPE)                                \
22152 +       NOD(NAME, (S_IFREG | (MODE)), NULL,             \
22153 +               &proc_nx_info_file_operations,          \
22154 +               { .proc_nxi_read = &proc_##OTYPE } )
22155 +
22156 +
22157 +static struct file_operations proc_vs_info_file_operations = {
22158 +       .read =         proc_vs_info_read,
22159 +};
22160 +
22161 +static struct file_operations proc_vx_info_file_operations = {
22162 +       .read =         proc_vx_info_read,
22163 +};
22164 +
22165 +static struct dentry_operations proc_xid_dentry_operations = {
22166 +       .d_revalidate = proc_xid_revalidate,
22167 +};
22168 +
22169 +static struct vs_entry vx_base_stuff[] = {
22170 +       VINF("info",    S_IRUGO, vxi_info),
22171 +       VINF("status",  S_IRUGO, vxi_status),
22172 +       VINF("limit",   S_IRUGO, vxi_limit),
22173 +       VINF("sched",   S_IRUGO, vxi_sched),
22174 +       VINF("nsproxy", S_IRUGO, vxi_nsproxy0),
22175 +       VINF("nsproxy1",S_IRUGO, vxi_nsproxy1),
22176 +       VINF("cvirt",   S_IRUGO, vxi_cvirt),
22177 +       VINF("cacct",   S_IRUGO, vxi_cacct),
22178 +       {}
22179 +};
22180 +
22181 +
22182 +
22183 +
22184 +static struct dentry *proc_xid_instantiate(struct inode *dir,
22185 +       struct dentry *dentry, int id, void *ptr)
22186 +{
22187 +       dentry->d_op = &proc_xid_dentry_operations;
22188 +       return vs_proc_instantiate(dir, dentry, id, ptr);
22189 +}
22190 +
22191 +static struct dentry *proc_xid_lookup(struct inode *dir,
22192 +       struct dentry *dentry, struct nameidata *nd)
22193 +{
22194 +       struct vs_entry *p = vx_base_stuff;
22195 +       struct dentry *error = ERR_PTR(-ENOENT);
22196 +
22197 +       for (; p->name; p++) {
22198 +               if (p->len != dentry->d_name.len)
22199 +                       continue;
22200 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
22201 +                       break;
22202 +       }
22203 +       if (!p->name)
22204 +               goto out;
22205 +
22206 +       error = proc_xid_instantiate(dir, dentry, PROC_I(dir)->fd, p);
22207 +out:
22208 +       return error;
22209 +}
22210 +
22211 +static int proc_xid_readdir(struct file *filp,
22212 +       void *dirent, filldir_t filldir)
22213 +{
22214 +       struct dentry *dentry = filp->f_dentry;
22215 +       struct inode *inode = dentry->d_inode;
22216 +       struct vs_entry *p = vx_base_stuff;
22217 +       int size = sizeof(vx_base_stuff) / sizeof(struct vs_entry);
22218 +       int pos, index;
22219 +       u64 ino;
22220 +
22221 +       pos = filp->f_pos;
22222 +       switch (pos) {
22223 +       case 0:
22224 +               ino = inode->i_ino;
22225 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
22226 +                       goto out;
22227 +               pos++;
22228 +               /* fall through */
22229 +       case 1:
22230 +               ino = parent_ino(dentry);
22231 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
22232 +                       goto out;
22233 +               pos++;
22234 +               /* fall through */
22235 +       default:
22236 +               index = pos - 2;
22237 +               if (index >= size)
22238 +                       goto out;
22239 +               for (p += index; p->name; p++) {
22240 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
22241 +                               vs_proc_instantiate, PROC_I(inode)->fd, p))
22242 +                               goto out;
22243 +                       pos++;
22244 +               }
22245 +       }
22246 +out:
22247 +       filp->f_pos = pos;
22248 +       return 1;
22249 +}
22250 +
22251 +
22252 +
22253 +static struct file_operations proc_nx_info_file_operations = {
22254 +       .read =         proc_nx_info_read,
22255 +};
22256 +
22257 +static struct dentry_operations proc_nid_dentry_operations = {
22258 +       .d_revalidate = proc_nid_revalidate,
22259 +};
22260 +
22261 +static struct vs_entry nx_base_stuff[] = {
22262 +       NINF("info",    S_IRUGO, nxi_info),
22263 +       NINF("status",  S_IRUGO, nxi_status),
22264 +       {}
22265 +};
22266 +
22267 +
22268 +static struct dentry *proc_nid_instantiate(struct inode *dir,
22269 +       struct dentry *dentry, int id, void *ptr)
22270 +{
22271 +       dentry->d_op = &proc_nid_dentry_operations;
22272 +       return vs_proc_instantiate(dir, dentry, id, ptr);
22273 +}
22274 +
22275 +static struct dentry *proc_nid_lookup(struct inode *dir,
22276 +       struct dentry *dentry, struct nameidata *nd)
22277 +{
22278 +       struct vs_entry *p = nx_base_stuff;
22279 +       struct dentry *error = ERR_PTR(-ENOENT);
22280 +
22281 +       for (; p->name; p++) {
22282 +               if (p->len != dentry->d_name.len)
22283 +                       continue;
22284 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
22285 +                       break;
22286 +       }
22287 +       if (!p->name)
22288 +               goto out;
22289 +
22290 +       error = proc_nid_instantiate(dir, dentry, PROC_I(dir)->fd, p);
22291 +out:
22292 +       return error;
22293 +}
22294 +
22295 +static int proc_nid_readdir(struct file *filp,
22296 +       void *dirent, filldir_t filldir)
22297 +{
22298 +       struct dentry *dentry = filp->f_dentry;
22299 +       struct inode *inode = dentry->d_inode;
22300 +       struct vs_entry *p = nx_base_stuff;
22301 +       int size = sizeof(nx_base_stuff) / sizeof(struct vs_entry);
22302 +       int pos, index;
22303 +       u64 ino;
22304 +
22305 +       pos = filp->f_pos;
22306 +       switch (pos) {
22307 +       case 0:
22308 +               ino = inode->i_ino;
22309 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
22310 +                       goto out;
22311 +               pos++;
22312 +               /* fall through */
22313 +       case 1:
22314 +               ino = parent_ino(dentry);
22315 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
22316 +                       goto out;
22317 +               pos++;
22318 +               /* fall through */
22319 +       default:
22320 +               index = pos - 2;
22321 +               if (index >= size)
22322 +                       goto out;
22323 +               for (p += index; p->name; p++) {
22324 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
22325 +                               vs_proc_instantiate, PROC_I(inode)->fd, p))
22326 +                               goto out;
22327 +                       pos++;
22328 +               }
22329 +       }
22330 +out:
22331 +       filp->f_pos = pos;
22332 +       return 1;
22333 +}
22334 +
22335 +
22336 +#define MAX_MULBY10    ((~0U - 9) / 10)
22337 +
22338 +static inline int atovid(const char *str, int len)
22339 +{
22340 +       int vid, c;
22341 +
22342 +       vid = 0;
22343 +       while (len-- > 0) {
22344 +               c = *str - '0';
22345 +               str++;
22346 +               if (c > 9)
22347 +                       return -1;
22348 +               if (vid >= MAX_MULBY10)
22349 +                       return -1;
22350 +               vid *= 10;
22351 +               vid += c;
22352 +               if (!vid)
22353 +                       return -1;
22354 +       }
22355 +       return vid;
22356 +}
22357 +
22358 +/* now the upper level (virtual) */
22359 +
22360 +
22361 +static struct file_operations proc_xid_file_operations = {
22362 +       .read =         generic_read_dir,
22363 +       .readdir =      proc_xid_readdir,
22364 +};
22365 +
22366 +static struct inode_operations proc_xid_inode_operations = {
22367 +       .lookup =       proc_xid_lookup,
22368 +};
22369 +
22370 +static struct vs_entry vx_virtual_stuff[] = {
22371 +       INF("info",     S_IRUGO, virtual_info),
22372 +       INF("status",   S_IRUGO, virtual_status),
22373 +       DIR(NULL,       S_IRUGO | S_IXUGO, xid),
22374 +};
22375 +
22376 +
22377 +static struct dentry *proc_virtual_lookup(struct inode *dir,
22378 +       struct dentry *dentry, struct nameidata *nd)
22379 +{
22380 +       struct vs_entry *p = vx_virtual_stuff;
22381 +       struct dentry *error = ERR_PTR(-ENOENT);
22382 +       int id = 0;
22383 +
22384 +       for (; p->name; p++) {
22385 +               if (p->len != dentry->d_name.len)
22386 +                       continue;
22387 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
22388 +                       break;
22389 +       }
22390 +       if (p->name)
22391 +               goto instantiate;
22392 +
22393 +       id = atovid(dentry->d_name.name, dentry->d_name.len);
22394 +       if ((id < 0) || !xid_is_hashed(id))
22395 +               goto out;
22396 +
22397 +instantiate:
22398 +       error = proc_xid_instantiate(dir, dentry, id, p);
22399 +out:
22400 +       return error;
22401 +}
22402 +
22403 +static struct file_operations proc_nid_file_operations = {
22404 +       .read =         generic_read_dir,
22405 +       .readdir =      proc_nid_readdir,
22406 +};
22407 +
22408 +static struct inode_operations proc_nid_inode_operations = {
22409 +       .lookup =       proc_nid_lookup,
22410 +};
22411 +
22412 +static struct vs_entry nx_virtnet_stuff[] = {
22413 +       INF("info",     S_IRUGO, virtnet_info),
22414 +       INF("status",   S_IRUGO, virtnet_status),
22415 +       DIR(NULL,       S_IRUGO | S_IXUGO, nid),
22416 +};
22417 +
22418 +
22419 +static struct dentry *proc_virtnet_lookup(struct inode *dir,
22420 +       struct dentry *dentry, struct nameidata *nd)
22421 +{
22422 +       struct vs_entry *p = nx_virtnet_stuff;
22423 +       struct dentry *error = ERR_PTR(-ENOENT);
22424 +       int id = 0;
22425 +
22426 +       for (; p->name; p++) {
22427 +               if (p->len != dentry->d_name.len)
22428 +                       continue;
22429 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
22430 +                       break;
22431 +       }
22432 +       if (p->name)
22433 +               goto instantiate;
22434 +
22435 +       id = atovid(dentry->d_name.name, dentry->d_name.len);
22436 +       if ((id < 0) || !nid_is_hashed(id))
22437 +               goto out;
22438 +
22439 +instantiate:
22440 +       error = proc_nid_instantiate(dir, dentry, id, p);
22441 +out:
22442 +       return error;
22443 +}
22444 +
22445 +
22446 +#define PROC_MAXVIDS 32
22447 +
22448 +int proc_virtual_readdir(struct file *filp,
22449 +       void *dirent, filldir_t filldir)
22450 +{
22451 +       struct dentry *dentry = filp->f_dentry;
22452 +       struct inode *inode = dentry->d_inode;
22453 +       struct vs_entry *p = vx_virtual_stuff;
22454 +       int size = sizeof(vx_virtual_stuff) / sizeof(struct vs_entry);
22455 +       int pos, index;
22456 +       unsigned int xid_array[PROC_MAXVIDS];
22457 +       char buf[PROC_NUMBUF];
22458 +       unsigned int nr_xids, i;
22459 +       u64 ino;
22460 +
22461 +       pos = filp->f_pos;
22462 +       switch (pos) {
22463 +       case 0:
22464 +               ino = inode->i_ino;
22465 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
22466 +                       goto out;
22467 +               pos++;
22468 +               /* fall through */
22469 +       case 1:
22470 +               ino = parent_ino(dentry);
22471 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
22472 +                       goto out;
22473 +               pos++;
22474 +               /* fall through */
22475 +       default:
22476 +               index = pos - 2;
22477 +               if (index >= size)
22478 +                       goto entries;
22479 +               for (p += index; p->name; p++) {
22480 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
22481 +                               vs_proc_instantiate, 0, p))
22482 +                               goto out;
22483 +                       pos++;
22484 +               }
22485 +       entries:
22486 +               index = pos - size;
22487 +               p = &vx_virtual_stuff[size - 1];
22488 +               nr_xids = get_xid_list(index, xid_array, PROC_MAXVIDS);
22489 +               for (i = 0; i < nr_xids; i++) {
22490 +                       int n, xid = xid_array[i];
22491 +                       unsigned int j = PROC_NUMBUF;
22492 +
22493 +                       n = xid;
22494 +                       do
22495 +                               buf[--j] = '0' + (n % 10);
22496 +                       while (n /= 10);
22497 +
22498 +                       if (proc_fill_cache(filp, dirent, filldir,
22499 +                               buf + j, PROC_NUMBUF - j,
22500 +                               vs_proc_instantiate, xid, p))
22501 +                               goto out;
22502 +                       pos++;
22503 +               }
22504 +       }
22505 +out:
22506 +       filp->f_pos = pos;
22507 +       return 0;
22508 +}
22509 +
22510 +static int proc_virtual_getattr(struct vfsmount *mnt,
22511 +       struct dentry *dentry, struct kstat *stat)
22512 +{
22513 +       struct inode *inode = dentry->d_inode;
22514 +
22515 +       generic_fillattr(inode, stat);
22516 +       stat->nlink = 2 + atomic_read(&vx_global_cactive);
22517 +       return 0;
22518 +}
22519 +
22520 +static struct file_operations proc_virtual_dir_operations = {
22521 +       .read =         generic_read_dir,
22522 +       .readdir =      proc_virtual_readdir,
22523 +};
22524 +
22525 +static struct inode_operations proc_virtual_dir_inode_operations = {
22526 +       .getattr =      proc_virtual_getattr,
22527 +       .lookup =       proc_virtual_lookup,
22528 +};
22529 +
22530 +
22531 +
22532 +
22533 +
22534 +int proc_virtnet_readdir(struct file *filp,
22535 +       void *dirent, filldir_t filldir)
22536 +{
22537 +       struct dentry *dentry = filp->f_dentry;
22538 +       struct inode *inode = dentry->d_inode;
22539 +       struct vs_entry *p = nx_virtnet_stuff;
22540 +       int size = sizeof(nx_virtnet_stuff) / sizeof(struct vs_entry);
22541 +       int pos, index;
22542 +       unsigned int nid_array[PROC_MAXVIDS];
22543 +       char buf[PROC_NUMBUF];
22544 +       unsigned int nr_nids, i;
22545 +       u64 ino;
22546 +
22547 +       pos = filp->f_pos;
22548 +       switch (pos) {
22549 +       case 0:
22550 +               ino = inode->i_ino;
22551 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
22552 +                       goto out;
22553 +               pos++;
22554 +               /* fall through */
22555 +       case 1:
22556 +               ino = parent_ino(dentry);
22557 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
22558 +                       goto out;
22559 +               pos++;
22560 +               /* fall through */
22561 +       default:
22562 +               index = pos - 2;
22563 +               if (index >= size)
22564 +                       goto entries;
22565 +               for (p += index; p->name; p++) {
22566 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
22567 +                               vs_proc_instantiate, 0, p))
22568 +                               goto out;
22569 +                       pos++;
22570 +               }
22571 +       entries:
22572 +               index = pos - size;
22573 +               p = &nx_virtnet_stuff[size - 1];
22574 +               nr_nids = get_nid_list(index, nid_array, PROC_MAXVIDS);
22575 +               for (i = 0; i < nr_nids; i++) {
22576 +                       int n, nid = nid_array[i];
22577 +                       unsigned int j = PROC_NUMBUF;
22578 +
22579 +                       n = nid;
22580 +                       do
22581 +                               buf[--j] = '0' + (n % 10);
22582 +                       while (n /= 10);
22583 +
22584 +                       if (proc_fill_cache(filp, dirent, filldir,
22585 +                               buf + j, PROC_NUMBUF - j,
22586 +                               vs_proc_instantiate, nid, p))
22587 +                               goto out;
22588 +                       pos++;
22589 +               }
22590 +       }
22591 +out:
22592 +       filp->f_pos = pos;
22593 +       return 0;
22594 +}
22595 +
22596 +static int proc_virtnet_getattr(struct vfsmount *mnt,
22597 +       struct dentry *dentry, struct kstat *stat)
22598 +{
22599 +       struct inode *inode = dentry->d_inode;
22600 +
22601 +       generic_fillattr(inode, stat);
22602 +       stat->nlink = 2 + atomic_read(&nx_global_cactive);
22603 +       return 0;
22604 +}
22605 +
22606 +static struct file_operations proc_virtnet_dir_operations = {
22607 +       .read =         generic_read_dir,
22608 +       .readdir =      proc_virtnet_readdir,
22609 +};
22610 +
22611 +static struct inode_operations proc_virtnet_dir_inode_operations = {
22612 +       .getattr =      proc_virtnet_getattr,
22613 +       .lookup =       proc_virtnet_lookup,
22614 +};
22615 +
22616 +
22617 +
22618 +void proc_vx_init(void)
22619 +{
22620 +       struct proc_dir_entry *ent;
22621 +
22622 +       ent = proc_mkdir("virtual", 0);
22623 +       if (ent) {
22624 +               ent->proc_fops = &proc_virtual_dir_operations;
22625 +               ent->proc_iops = &proc_virtual_dir_inode_operations;
22626 +       }
22627 +       proc_virtual = ent;
22628 +
22629 +       ent = proc_mkdir("virtnet", 0);
22630 +       if (ent) {
22631 +               ent->proc_fops = &proc_virtnet_dir_operations;
22632 +               ent->proc_iops = &proc_virtnet_dir_inode_operations;
22633 +       }
22634 +       proc_virtnet = ent;
22635 +}
22636 +
22637 +
22638 +
22639 +
22640 +/* per pid info */
22641 +
22642 +
22643 +int proc_pid_vx_info(struct task_struct *p, char *buffer)
22644 +{
22645 +       struct vx_info *vxi;
22646 +       char *orig = buffer;
22647 +
22648 +       buffer += sprintf(buffer, "XID:\t%d\n", vx_task_xid(p));
22649 +
22650 +       vxi = task_get_vx_info(p);
22651 +       if (!vxi)
22652 +               goto out;
22653 +
22654 +       buffer += sprintf(buffer, "BCaps:\t");
22655 +       buffer = print_cap_t(buffer, &vxi->vx_bcaps);
22656 +       buffer += sprintf(buffer, "\n");
22657 +       buffer += sprintf(buffer, "CCaps:\t%016llx\n",
22658 +               (unsigned long long)vxi->vx_ccaps);
22659 +       buffer += sprintf(buffer, "CFlags:\t%016llx\n",
22660 +               (unsigned long long)vxi->vx_flags);
22661 +       buffer += sprintf(buffer, "CIPid:\t%d\n", vxi->vx_initpid);
22662 +
22663 +       put_vx_info(vxi);
22664 +out:
22665 +       return buffer - orig;
22666 +}
22667 +
22668 +
22669 +int proc_pid_nx_info(struct task_struct *p, char *buffer)
22670 +{
22671 +       struct nx_info *nxi;
22672 +       struct nx_addr_v4 *v4a;
22673 +#ifdef CONFIG_IPV6
22674 +       struct nx_addr_v6 *v6a;
22675 +#endif
22676 +       char *orig = buffer;
22677 +       int i;
22678 +
22679 +       buffer += sprintf(buffer, "NID:\t%d\n", nx_task_nid(p));
22680 +
22681 +       nxi = task_get_nx_info(p);
22682 +       if (!nxi)
22683 +               goto out;
22684 +
22685 +       buffer += sprintf(buffer, "NCaps:\t%016llx\n",
22686 +               (unsigned long long)nxi->nx_ncaps);
22687 +       buffer += sprintf(buffer, "NFlags:\t%016llx\n",
22688 +               (unsigned long long)nxi->nx_flags);
22689 +
22690 +       buffer += sprintf(buffer,
22691 +               "V4Root[bcast]:\t" NIPQUAD_FMT "\n",
22692 +               NIPQUAD(nxi->v4_bcast.s_addr));
22693 +       buffer += sprintf (buffer,
22694 +               "V4Root[lback]:\t" NIPQUAD_FMT "\n",
22695 +               NIPQUAD(nxi->v4_lback.s_addr));
22696 +       if (!NX_IPV4(nxi))
22697 +               goto skip_v4;
22698 +       for (i = 0, v4a = &nxi->v4; v4a; i++, v4a = v4a->next)
22699 +               buffer += sprintf(buffer, "V4Root[%d]:\t" NXAV4_FMT "\n",
22700 +                       i, NXAV4(v4a));
22701 +skip_v4:
22702 +#ifdef CONFIG_IPV6
22703 +       if (!NX_IPV6(nxi))
22704 +               goto skip_v6;
22705 +       for (i = 0, v6a = &nxi->v6; v6a; i++, v6a = v6a->next)
22706 +               buffer += sprintf(buffer, "V6Root[%d]:\t" NXAV6_FMT "\n",
22707 +                       i, NXAV6(v6a));
22708 +skip_v6:
22709 +#endif
22710 +       put_nx_info(nxi);
22711 +out:
22712 +       return buffer - orig;
22713 +}
22714 +
22715 diff -NurpP --minimal linux-2.6.38-rc8/kernel/vserver/sched.c linux-2.6.38-rc8-vs2.3.0.37-rc6/kernel/vserver/sched.c
22716 --- linux-2.6.38-rc8/kernel/vserver/sched.c     1970-01-01 01:00:00.000000000 +0100
22717 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/kernel/vserver/sched.c      2011-01-29 02:01:07.000000000 +0100
22718 @@ -0,0 +1,82 @@
22719 +/*
22720 + *  linux/kernel/vserver/sched.c
22721 + *
22722 + *  Virtual Server: Scheduler Support
22723 + *
22724 + *  Copyright (C) 2004-2010  Herbert Pötzl
22725 + *
22726 + *  V0.01  adapted Sam Vilains version to 2.6.3
22727 + *  V0.02  removed legacy interface
22728 + *  V0.03  changed vcmds to vxi arg
22729 + *  V0.04  removed older and legacy interfaces
22730 + *  V0.05  removed scheduler code/commands
22731 + *
22732 + */
22733 +
22734 +#include <linux/vs_context.h>
22735 +#include <linux/vs_sched.h>
22736 +#include <linux/vserver/sched_cmd.h>
22737 +
22738 +#include <asm/uaccess.h>
22739 +
22740 +
22741 +void vx_update_sched_param(struct _vx_sched *sched,
22742 +       struct _vx_sched_pc *sched_pc)
22743 +{
22744 +       sched_pc->prio_bias = sched->prio_bias;
22745 +}
22746 +
22747 +static int do_set_prio_bias(struct vx_info *vxi, struct vcmd_prio_bias *data)
22748 +{
22749 +       int cpu;
22750 +
22751 +       if (data->prio_bias > MAX_PRIO_BIAS)
22752 +               data->prio_bias = MAX_PRIO_BIAS;
22753 +       if (data->prio_bias < MIN_PRIO_BIAS)
22754 +               data->prio_bias = MIN_PRIO_BIAS;
22755 +
22756 +       if (data->cpu_id != ~0) {
22757 +               vxi->sched.update = cpumask_of_cpu(data->cpu_id);
22758 +               cpus_and(vxi->sched.update, cpu_online_map,
22759 +                       vxi->sched.update);
22760 +       } else
22761 +               vxi->sched.update = cpu_online_map;
22762 +
22763 +       for_each_cpu_mask(cpu, vxi->sched.update)
22764 +               vx_update_sched_param(&vxi->sched,
22765 +                       &vx_per_cpu(vxi, sched_pc, cpu));
22766 +       return 0;
22767 +}
22768 +
22769 +int vc_set_prio_bias(struct vx_info *vxi, void __user *data)
22770 +{
22771 +       struct vcmd_prio_bias vc_data;
22772 +
22773 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
22774 +               return -EFAULT;
22775 +
22776 +       return do_set_prio_bias(vxi, &vc_data);
22777 +}
22778 +
22779 +int vc_get_prio_bias(struct vx_info *vxi, void __user *data)
22780 +{
22781 +       struct vcmd_prio_bias vc_data;
22782 +       struct _vx_sched_pc *pcd;
22783 +       int cpu;
22784 +
22785 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
22786 +               return -EFAULT;
22787 +
22788 +       cpu = vc_data.cpu_id;
22789 +
22790 +       if (!cpu_possible(cpu))
22791 +               return -EINVAL;
22792 +
22793 +       pcd = &vx_per_cpu(vxi, sched_pc, cpu);
22794 +       vc_data.prio_bias = pcd->prio_bias;
22795 +
22796 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
22797 +               return -EFAULT;
22798 +       return 0;
22799 +}
22800 +
22801 diff -NurpP --minimal linux-2.6.38-rc8/kernel/vserver/sched_init.h linux-2.6.38-rc8-vs2.3.0.37-rc6/kernel/vserver/sched_init.h
22802 --- linux-2.6.38-rc8/kernel/vserver/sched_init.h        1970-01-01 01:00:00.000000000 +0100
22803 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/kernel/vserver/sched_init.h 2011-01-29 02:01:07.000000000 +0100
22804 @@ -0,0 +1,27 @@
22805 +
22806 +static inline void vx_info_init_sched(struct _vx_sched *sched)
22807 +{
22808 +       /* scheduling; hard code starting values as constants */
22809 +       sched->prio_bias = 0;
22810 +}
22811 +
22812 +static inline
22813 +void vx_info_init_sched_pc(struct _vx_sched_pc *sched_pc, int cpu)
22814 +{
22815 +       sched_pc->prio_bias = 0;
22816 +
22817 +       sched_pc->user_ticks = 0;
22818 +       sched_pc->sys_ticks = 0;
22819 +       sched_pc->hold_ticks = 0;
22820 +}
22821 +
22822 +static inline void vx_info_exit_sched(struct _vx_sched *sched)
22823 +{
22824 +       return;
22825 +}
22826 +
22827 +static inline
22828 +void vx_info_exit_sched_pc(struct _vx_sched_pc *sched_pc, int cpu)
22829 +{
22830 +       return;
22831 +}
22832 diff -NurpP --minimal linux-2.6.38-rc8/kernel/vserver/sched_proc.h linux-2.6.38-rc8-vs2.3.0.37-rc6/kernel/vserver/sched_proc.h
22833 --- linux-2.6.38-rc8/kernel/vserver/sched_proc.h        1970-01-01 01:00:00.000000000 +0100
22834 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/kernel/vserver/sched_proc.h 2011-01-29 02:01:07.000000000 +0100
22835 @@ -0,0 +1,32 @@
22836 +#ifndef _VX_SCHED_PROC_H
22837 +#define _VX_SCHED_PROC_H
22838 +
22839 +
22840 +static inline
22841 +int vx_info_proc_sched(struct _vx_sched *sched, char *buffer)
22842 +{
22843 +       int length = 0;
22844 +
22845 +       length += sprintf(buffer,
22846 +               "PrioBias:\t%8d\n",
22847 +               sched->prio_bias);
22848 +       return length;
22849 +}
22850 +
22851 +static inline
22852 +int vx_info_proc_sched_pc(struct _vx_sched_pc *sched_pc,
22853 +       char *buffer, int cpu)
22854 +{
22855 +       int length = 0;
22856 +
22857 +       length += sprintf(buffer + length,
22858 +               "cpu %d: %lld %lld %lld", cpu,
22859 +               (unsigned long long)sched_pc->user_ticks,
22860 +               (unsigned long long)sched_pc->sys_ticks,
22861 +               (unsigned long long)sched_pc->hold_ticks);
22862 +       length += sprintf(buffer + length,
22863 +               " %d\n", sched_pc->prio_bias);
22864 +       return length;
22865 +}
22866 +
22867 +#endif /* _VX_SCHED_PROC_H */
22868 diff -NurpP --minimal linux-2.6.38-rc8/kernel/vserver/signal.c linux-2.6.38-rc8-vs2.3.0.37-rc6/kernel/vserver/signal.c
22869 --- linux-2.6.38-rc8/kernel/vserver/signal.c    1970-01-01 01:00:00.000000000 +0100
22870 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/kernel/vserver/signal.c     2011-01-29 02:01:07.000000000 +0100
22871 @@ -0,0 +1,132 @@
22872 +/*
22873 + *  linux/kernel/vserver/signal.c
22874 + *
22875 + *  Virtual Server: Signal Support
22876 + *
22877 + *  Copyright (C) 2003-2007  Herbert Pötzl
22878 + *
22879 + *  V0.01  broken out from vcontext V0.05
22880 + *  V0.02  changed vcmds to vxi arg
22881 + *  V0.03  adjusted siginfo for kill
22882 + *
22883 + */
22884 +
22885 +#include <asm/uaccess.h>
22886 +
22887 +#include <linux/vs_context.h>
22888 +#include <linux/vs_pid.h>
22889 +#include <linux/vserver/signal_cmd.h>
22890 +
22891 +
22892 +int vx_info_kill(struct vx_info *vxi, int pid, int sig)
22893 +{
22894 +       int retval, count = 0;
22895 +       struct task_struct *p;
22896 +       struct siginfo *sip = SEND_SIG_PRIV;
22897 +
22898 +       retval = -ESRCH;
22899 +       vxdprintk(VXD_CBIT(misc, 4),
22900 +               "vx_info_kill(%p[#%d],%d,%d)*",
22901 +               vxi, vxi->vx_id, pid, sig);
22902 +       read_lock(&tasklist_lock);
22903 +       switch (pid) {
22904 +       case  0:
22905 +       case -1:
22906 +               for_each_process(p) {
22907 +                       int err = 0;
22908 +
22909 +                       if (vx_task_xid(p) != vxi->vx_id || p->pid <= 1 ||
22910 +                               (pid && vxi->vx_initpid == p->pid))
22911 +                               continue;
22912 +
22913 +                       err = group_send_sig_info(sig, sip, p);
22914 +                       ++count;
22915 +                       if (err != -EPERM)
22916 +                               retval = err;
22917 +               }
22918 +               break;
22919 +
22920 +       case 1:
22921 +               if (vxi->vx_initpid) {
22922 +                       pid = vxi->vx_initpid;
22923 +                       /* for now, only SIGINT to private init ... */
22924 +                       if (!vx_info_flags(vxi, VXF_STATE_ADMIN, 0) &&
22925 +                               /* ... as long as there are tasks left */
22926 +                               (atomic_read(&vxi->vx_tasks) > 1))
22927 +                               sig = SIGINT;
22928 +               }
22929 +               /* fallthrough */
22930 +       default:
22931 +               p = find_task_by_real_pid(pid);
22932 +               if (p) {
22933 +                       if (vx_task_xid(p) == vxi->vx_id)
22934 +                               retval = group_send_sig_info(sig, sip, p);
22935 +               }
22936 +               break;
22937 +       }
22938 +       read_unlock(&tasklist_lock);
22939 +       vxdprintk(VXD_CBIT(misc, 4),
22940 +               "vx_info_kill(%p[#%d],%d,%d,%ld) = %d",
22941 +               vxi, vxi->vx_id, pid, sig, (long)sip, retval);
22942 +       return retval;
22943 +}
22944 +
22945 +int vc_ctx_kill(struct vx_info *vxi, void __user *data)
22946 +{
22947 +       struct vcmd_ctx_kill_v0 vc_data;
22948 +
22949 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
22950 +               return -EFAULT;
22951 +
22952 +       /* special check to allow guest shutdown */
22953 +       if (!vx_info_flags(vxi, VXF_STATE_ADMIN, 0) &&
22954 +               /* forbid killall pid=0 when init is present */
22955 +               (((vc_data.pid < 1) && vxi->vx_initpid) ||
22956 +               (vc_data.pid > 1)))
22957 +               return -EACCES;
22958 +
22959 +       return vx_info_kill(vxi, vc_data.pid, vc_data.sig);
22960 +}
22961 +
22962 +
22963 +static int __wait_exit(struct vx_info *vxi)
22964 +{
22965 +       DECLARE_WAITQUEUE(wait, current);
22966 +       int ret = 0;
22967 +
22968 +       add_wait_queue(&vxi->vx_wait, &wait);
22969 +       set_current_state(TASK_INTERRUPTIBLE);
22970 +
22971 +wait:
22972 +       if (vx_info_state(vxi,
22973 +               VXS_SHUTDOWN | VXS_HASHED | VXS_HELPER) == VXS_SHUTDOWN)
22974 +               goto out;
22975 +       if (signal_pending(current)) {
22976 +               ret = -ERESTARTSYS;
22977 +               goto out;
22978 +       }
22979 +       schedule();
22980 +       goto wait;
22981 +
22982 +out:
22983 +       set_current_state(TASK_RUNNING);
22984 +       remove_wait_queue(&vxi->vx_wait, &wait);
22985 +       return ret;
22986 +}
22987 +
22988 +
22989 +
22990 +int vc_wait_exit(struct vx_info *vxi, void __user *data)
22991 +{
22992 +       struct vcmd_wait_exit_v0 vc_data;
22993 +       int ret;
22994 +
22995 +       ret = __wait_exit(vxi);
22996 +       vc_data.reboot_cmd = vxi->reboot_cmd;
22997 +       vc_data.exit_code = vxi->exit_code;
22998 +
22999 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
23000 +               ret = -EFAULT;
23001 +       return ret;
23002 +}
23003 +
23004 diff -NurpP --minimal linux-2.6.38-rc8/kernel/vserver/space.c linux-2.6.38-rc8-vs2.3.0.37-rc6/kernel/vserver/space.c
23005 --- linux-2.6.38-rc8/kernel/vserver/space.c     1970-01-01 01:00:00.000000000 +0100
23006 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/kernel/vserver/space.c      2011-02-01 03:30:46.000000000 +0100
23007 @@ -0,0 +1,417 @@
23008 +/*
23009 + *  linux/kernel/vserver/space.c
23010 + *
23011 + *  Virtual Server: Context Space Support
23012 + *
23013 + *  Copyright (C) 2003-2010  Herbert Pötzl
23014 + *
23015 + *  V0.01  broken out from context.c 0.07
23016 + *  V0.02  added task locking for namespace
23017 + *  V0.03  broken out vx_enter_namespace
23018 + *  V0.04  added *space support and commands
23019 + *  V0.05  added credential support
23020 + *
23021 + */
23022 +
23023 +#include <linux/utsname.h>
23024 +#include <linux/nsproxy.h>
23025 +#include <linux/err.h>
23026 +#include <linux/fs_struct.h>
23027 +#include <linux/cred.h>
23028 +#include <asm/uaccess.h>
23029 +
23030 +#include <linux/vs_context.h>
23031 +#include <linux/vserver/space.h>
23032 +#include <linux/vserver/space_cmd.h>
23033 +
23034 +atomic_t vs_global_nsproxy     = ATOMIC_INIT(0);
23035 +atomic_t vs_global_fs          = ATOMIC_INIT(0);
23036 +atomic_t vs_global_mnt_ns      = ATOMIC_INIT(0);
23037 +atomic_t vs_global_uts_ns      = ATOMIC_INIT(0);
23038 +atomic_t vs_global_user_ns     = ATOMIC_INIT(0);
23039 +atomic_t vs_global_pid_ns      = ATOMIC_INIT(0);
23040 +
23041 +
23042 +/* namespace functions */
23043 +
23044 +#include <linux/mnt_namespace.h>
23045 +#include <linux/user_namespace.h>
23046 +#include <linux/pid_namespace.h>
23047 +#include <linux/ipc_namespace.h>
23048 +#include <net/net_namespace.h>
23049 +
23050 +
23051 +static const struct vcmd_space_mask_v1 space_mask_v0 = {
23052 +       .mask = CLONE_FS |
23053 +               CLONE_NEWNS |
23054 +               CLONE_NEWUTS |
23055 +               CLONE_NEWIPC |
23056 +               CLONE_NEWUSER |
23057 +               0
23058 +};
23059 +
23060 +static const struct vcmd_space_mask_v1 space_mask = {
23061 +       .mask = CLONE_FS |
23062 +               CLONE_NEWNS |
23063 +               CLONE_NEWUTS |
23064 +               CLONE_NEWIPC |
23065 +               CLONE_NEWUSER |
23066 +#ifdef CONFIG_PID_NS
23067 +               CLONE_NEWPID |
23068 +#endif
23069 +#ifdef CONFIG_NET_NS
23070 +               CLONE_NEWNET |
23071 +#endif
23072 +               0
23073 +};
23074 +
23075 +static const struct vcmd_space_mask_v1 default_space_mask = {
23076 +       .mask = CLONE_FS |
23077 +               CLONE_NEWNS |
23078 +               CLONE_NEWUTS |
23079 +               CLONE_NEWIPC |
23080 +               CLONE_NEWUSER |
23081 +#ifdef CONFIG_PID_NS
23082 +//             CLONE_NEWPID |
23083 +#endif
23084 +               0
23085 +};
23086 +
23087 +/*
23088 + *     build a new nsproxy mix
23089 + *      assumes that both proxies are 'const'
23090 + *     does not touch nsproxy refcounts
23091 + *     will hold a reference on the result.
23092 + */
23093 +
23094 +struct nsproxy *vs_mix_nsproxy(struct nsproxy *old_nsproxy,
23095 +       struct nsproxy *new_nsproxy, unsigned long mask)
23096 +{
23097 +       struct mnt_namespace *old_ns;
23098 +       struct uts_namespace *old_uts;
23099 +       struct ipc_namespace *old_ipc;
23100 +#ifdef CONFIG_PID_NS
23101 +       struct pid_namespace *old_pid;
23102 +#endif
23103 +#ifdef CONFIG_NET_NS
23104 +       struct net *old_net;
23105 +#endif
23106 +       struct nsproxy *nsproxy;
23107 +
23108 +       nsproxy = copy_nsproxy(old_nsproxy);
23109 +       if (!nsproxy)
23110 +               goto out;
23111 +
23112 +       if (mask & CLONE_NEWNS) {
23113 +               old_ns = nsproxy->mnt_ns;
23114 +               nsproxy->mnt_ns = new_nsproxy->mnt_ns;
23115 +               if (nsproxy->mnt_ns)
23116 +                       get_mnt_ns(nsproxy->mnt_ns);
23117 +       } else
23118 +               old_ns = NULL;
23119 +
23120 +       if (mask & CLONE_NEWUTS) {
23121 +               old_uts = nsproxy->uts_ns;
23122 +               nsproxy->uts_ns = new_nsproxy->uts_ns;
23123 +               if (nsproxy->uts_ns)
23124 +                       get_uts_ns(nsproxy->uts_ns);
23125 +       } else
23126 +               old_uts = NULL;
23127 +
23128 +       if (mask & CLONE_NEWIPC) {
23129 +               old_ipc = nsproxy->ipc_ns;
23130 +               nsproxy->ipc_ns = new_nsproxy->ipc_ns;
23131 +               if (nsproxy->ipc_ns)
23132 +                       get_ipc_ns(nsproxy->ipc_ns);
23133 +       } else
23134 +               old_ipc = NULL;
23135 +
23136 +#ifdef CONFIG_PID_NS
23137 +       if (mask & CLONE_NEWPID) {
23138 +               old_pid = nsproxy->pid_ns;
23139 +               nsproxy->pid_ns = new_nsproxy->pid_ns;
23140 +               if (nsproxy->pid_ns)
23141 +                       get_pid_ns(nsproxy->pid_ns);
23142 +       } else
23143 +               old_pid = NULL;
23144 +#endif
23145 +#ifdef CONFIG_NET_NS
23146 +       if (mask & CLONE_NEWNET) {
23147 +               old_net = nsproxy->net_ns;
23148 +               nsproxy->net_ns = new_nsproxy->net_ns;
23149 +               if (nsproxy->net_ns)
23150 +                       get_net(nsproxy->net_ns);
23151 +       } else
23152 +               old_net = NULL;
23153 +#endif
23154 +       if (old_ns)
23155 +               put_mnt_ns(old_ns);
23156 +       if (old_uts)
23157 +               put_uts_ns(old_uts);
23158 +       if (old_ipc)
23159 +               put_ipc_ns(old_ipc);
23160 +#ifdef CONFIG_PID_NS
23161 +       if (old_pid)
23162 +               put_pid_ns(old_pid);
23163 +#endif
23164 +#ifdef CONFIG_NET_NS
23165 +       if (old_net)
23166 +               put_net(old_net);
23167 +#endif
23168 +out:
23169 +       return nsproxy;
23170 +}
23171 +
23172 +
23173 +/*
23174 + *     merge two nsproxy structs into a new one.
23175 + *     will hold a reference on the result.
23176 + */
23177 +
23178 +static inline
23179 +struct nsproxy *__vs_merge_nsproxy(struct nsproxy *old,
23180 +       struct nsproxy *proxy, unsigned long mask)
23181 +{
23182 +       struct nsproxy null_proxy = { .mnt_ns = NULL };
23183 +
23184 +       if (!proxy)
23185 +               return NULL;
23186 +
23187 +       if (mask) {
23188 +               /* vs_mix_nsproxy returns with reference */
23189 +               return vs_mix_nsproxy(old ? old : &null_proxy,
23190 +                       proxy, mask);
23191 +       }
23192 +       get_nsproxy(proxy);
23193 +       return proxy;
23194 +}
23195 +
23196 +
23197 +int vx_enter_space(struct vx_info *vxi, unsigned long mask, unsigned index)
23198 +{
23199 +       struct nsproxy *proxy, *proxy_cur, *proxy_new;
23200 +       struct fs_struct *fs_cur, *fs = NULL;
23201 +       struct _vx_space *space;
23202 +       int ret, kill = 0;
23203 +
23204 +       vxdprintk(VXD_CBIT(space, 8), "vx_enter_space(%p[#%u],0x%08lx,%d)",
23205 +               vxi, vxi->vx_id, mask, index);
23206 +
23207 +       if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0))
23208 +               return -EACCES;
23209 +
23210 +       if (index >= VX_SPACES)
23211 +               return -EINVAL;
23212 +
23213 +       space = &vxi->space[index];
23214 +
23215 +       if (!mask)
23216 +               mask = space->vx_nsmask;
23217 +
23218 +       if ((mask & space->vx_nsmask) != mask)
23219 +               return -EINVAL;
23220 +
23221 +       if (mask & CLONE_FS) {
23222 +               fs = copy_fs_struct(space->vx_fs);
23223 +               if (!fs)
23224 +                       return -ENOMEM;
23225 +       }
23226 +       proxy = space->vx_nsproxy;
23227 +
23228 +       vxdprintk(VXD_CBIT(space, 9),
23229 +               "vx_enter_space(%p[#%u],0x%08lx,%d) -> (%p,%p)",
23230 +               vxi, vxi->vx_id, mask, index, proxy, fs);
23231 +
23232 +       task_lock(current);
23233 +       fs_cur = current->fs;
23234 +
23235 +       if (mask & CLONE_FS) {
23236 +               spin_lock(&fs_cur->lock);
23237 +               current->fs = fs;
23238 +               kill = !--fs_cur->users;
23239 +               spin_unlock(&fs_cur->lock);
23240 +       }
23241 +
23242 +       proxy_cur = current->nsproxy;
23243 +       get_nsproxy(proxy_cur);
23244 +       task_unlock(current);
23245 +
23246 +       if (kill)
23247 +               free_fs_struct(fs_cur);
23248 +
23249 +       proxy_new = __vs_merge_nsproxy(proxy_cur, proxy, mask);
23250 +       if (IS_ERR(proxy_new)) {
23251 +               ret = PTR_ERR(proxy_new);
23252 +               goto out_put;
23253 +       }
23254 +
23255 +       proxy_new = xchg(&current->nsproxy, proxy_new);
23256 +
23257 +       if (mask & CLONE_NEWUSER) {
23258 +               struct cred *cred;
23259 +
23260 +               vxdprintk(VXD_CBIT(space, 10),
23261 +                       "vx_enter_space(%p[#%u],%p) cred (%p,%p)",
23262 +                       vxi, vxi->vx_id, space->vx_cred,
23263 +                       current->real_cred, current->cred);
23264 +
23265 +               if (space->vx_cred) {
23266 +                       cred = __prepare_creds(space->vx_cred);
23267 +                       if (cred)
23268 +                               commit_creds(cred);
23269 +               }
23270 +       }
23271 +
23272 +       ret = 0;
23273 +
23274 +       if (proxy_new)
23275 +               put_nsproxy(proxy_new);
23276 +out_put:
23277 +       if (proxy_cur)
23278 +               put_nsproxy(proxy_cur);
23279 +       return ret;
23280 +}
23281 +
23282 +
23283 +int vx_set_space(struct vx_info *vxi, unsigned long mask, unsigned index)
23284 +{
23285 +       struct nsproxy *proxy_vxi, *proxy_cur, *proxy_new;
23286 +       struct fs_struct *fs_vxi, *fs;
23287 +       struct _vx_space *space;
23288 +       int ret, kill = 0;
23289 +
23290 +       vxdprintk(VXD_CBIT(space, 8), "vx_set_space(%p[#%u],0x%08lx,%d)",
23291 +               vxi, vxi->vx_id, mask, index);
23292 +
23293 +       if ((mask & space_mask.mask) != mask)
23294 +               return -EINVAL;
23295 +
23296 +       if (index >= VX_SPACES)
23297 +               return -EINVAL;
23298 +
23299 +       space = &vxi->space[index];
23300 +
23301 +       proxy_vxi = space->vx_nsproxy;
23302 +       fs_vxi = space->vx_fs;
23303 +
23304 +       if (mask & CLONE_FS) {
23305 +               fs = copy_fs_struct(current->fs);
23306 +               if (!fs)
23307 +                       return -ENOMEM;
23308 +       }
23309 +
23310 +       task_lock(current);
23311 +
23312 +       if (mask & CLONE_FS) {
23313 +               spin_lock(&fs_vxi->lock);
23314 +               space->vx_fs = fs;
23315 +               kill = !--fs_vxi->users;
23316 +               spin_unlock(&fs_vxi->lock);
23317 +       }
23318 +
23319 +       proxy_cur = current->nsproxy;
23320 +       get_nsproxy(proxy_cur);
23321 +       task_unlock(current);
23322 +
23323 +       if (kill)
23324 +               free_fs_struct(fs_vxi);
23325 +
23326 +       proxy_new = __vs_merge_nsproxy(proxy_vxi, proxy_cur, mask);
23327 +       if (IS_ERR(proxy_new)) {
23328 +               ret = PTR_ERR(proxy_new);
23329 +               goto out_put;
23330 +       }
23331 +
23332 +       proxy_new = xchg(&space->vx_nsproxy, proxy_new);
23333 +       space->vx_nsmask |= mask;
23334 +
23335 +       if (mask & CLONE_NEWUSER) {
23336 +               struct cred *cred;
23337 +
23338 +               vxdprintk(VXD_CBIT(space, 10),
23339 +                       "vx_set_space(%p[#%u],%p) cred (%p,%p)",
23340 +                       vxi, vxi->vx_id, space->vx_cred,
23341 +                       current->real_cred, current->cred);
23342 +
23343 +               cred = prepare_creds();
23344 +               cred = (struct cred *)xchg(&space->vx_cred, cred);
23345 +               if (cred)
23346 +                       abort_creds(cred);
23347 +       }
23348 +
23349 +       ret = 0;
23350 +
23351 +       if (proxy_new)
23352 +               put_nsproxy(proxy_new);
23353 +out_put:
23354 +       if (proxy_cur)
23355 +               put_nsproxy(proxy_cur);
23356 +       return ret;
23357 +}
23358 +
23359 +
23360 +int vc_enter_space_v1(struct vx_info *vxi, void __user *data)
23361 +{
23362 +       struct vcmd_space_mask_v1 vc_data = { .mask = 0 };
23363 +
23364 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
23365 +               return -EFAULT;
23366 +
23367 +       return vx_enter_space(vxi, vc_data.mask, 0);
23368 +}
23369 +
23370 +int vc_enter_space(struct vx_info *vxi, void __user *data)
23371 +{
23372 +       struct vcmd_space_mask_v2 vc_data = { .mask = 0 };
23373 +
23374 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
23375 +               return -EFAULT;
23376 +
23377 +       if (vc_data.index >= VX_SPACES)
23378 +               return -EINVAL;
23379 +
23380 +       return vx_enter_space(vxi, vc_data.mask, vc_data.index);
23381 +}
23382 +
23383 +int vc_set_space_v1(struct vx_info *vxi, void __user *data)
23384 +{
23385 +       struct vcmd_space_mask_v1 vc_data = { .mask = 0 };
23386 +
23387 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
23388 +               return -EFAULT;
23389 +
23390 +       return vx_set_space(vxi, vc_data.mask, 0);
23391 +}
23392 +
23393 +int vc_set_space(struct vx_info *vxi, void __user *data)
23394 +{
23395 +       struct vcmd_space_mask_v2 vc_data = { .mask = 0 };
23396 +
23397 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
23398 +               return -EFAULT;
23399 +
23400 +       if (vc_data.index >= VX_SPACES)
23401 +               return -EINVAL;
23402 +
23403 +       return vx_set_space(vxi, vc_data.mask, vc_data.index);
23404 +}
23405 +
23406 +int vc_get_space_mask(void __user *data, int type)
23407 +{
23408 +       const struct vcmd_space_mask_v1 *mask;
23409 +
23410 +       if (type == 0)
23411 +               mask = &space_mask_v0;
23412 +       else if (type == 1)
23413 +               mask = &space_mask;
23414 +       else
23415 +               mask = &default_space_mask;
23416 +
23417 +       vxdprintk(VXD_CBIT(space, 10),
23418 +               "vc_get_space_mask(%d) = %08llx", type, mask->mask);
23419 +
23420 +       if (copy_to_user(data, mask, sizeof(*mask)))
23421 +               return -EFAULT;
23422 +       return 0;
23423 +}
23424 +
23425 diff -NurpP --minimal linux-2.6.38-rc8/kernel/vserver/switch.c linux-2.6.38-rc8-vs2.3.0.37-rc6/kernel/vserver/switch.c
23426 --- linux-2.6.38-rc8/kernel/vserver/switch.c    1970-01-01 01:00:00.000000000 +0100
23427 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/kernel/vserver/switch.c     2011-01-29 02:01:07.000000000 +0100
23428 @@ -0,0 +1,531 @@
23429 +/*
23430 + *  linux/kernel/vserver/switch.c
23431 + *
23432 + *  Virtual Server: Syscall Switch
23433 + *
23434 + *  Copyright (C) 2003-2007  Herbert Pötzl
23435 + *
23436 + *  V0.01  syscall switch
23437 + *  V0.02  added signal to context
23438 + *  V0.03  added rlimit functions
23439 + *  V0.04  added iattr, task/xid functions
23440 + *  V0.05  added debug/history stuff
23441 + *  V0.06  added compat32 layer
23442 + *  V0.07  vcmd args and perms
23443 + *  V0.08  added status commands
23444 + *  V0.09  added tag commands
23445 + *  V0.10  added oom bias
23446 + *  V0.11  added device commands
23447 + *
23448 + */
23449 +
23450 +#include <linux/vs_context.h>
23451 +#include <linux/vs_network.h>
23452 +#include <linux/vserver/switch.h>
23453 +
23454 +#include "vci_config.h"
23455 +
23456 +
23457 +static inline
23458 +int vc_get_version(uint32_t id)
23459 +{
23460 +       return VCI_VERSION;
23461 +}
23462 +
23463 +static inline
23464 +int vc_get_vci(uint32_t id)
23465 +{
23466 +       return vci_kernel_config();
23467 +}
23468 +
23469 +#include <linux/vserver/context_cmd.h>
23470 +#include <linux/vserver/cvirt_cmd.h>
23471 +#include <linux/vserver/cacct_cmd.h>
23472 +#include <linux/vserver/limit_cmd.h>
23473 +#include <linux/vserver/network_cmd.h>
23474 +#include <linux/vserver/sched_cmd.h>
23475 +#include <linux/vserver/debug_cmd.h>
23476 +#include <linux/vserver/inode_cmd.h>
23477 +#include <linux/vserver/dlimit_cmd.h>
23478 +#include <linux/vserver/signal_cmd.h>
23479 +#include <linux/vserver/space_cmd.h>
23480 +#include <linux/vserver/tag_cmd.h>
23481 +#include <linux/vserver/device_cmd.h>
23482 +
23483 +#include <linux/vserver/inode.h>
23484 +#include <linux/vserver/dlimit.h>
23485 +
23486 +
23487 +#ifdef CONFIG_COMPAT
23488 +#define __COMPAT(name, id, data, compat)       \
23489 +       (compat) ? name ## _x32(id, data) : name(id, data)
23490 +#define __COMPAT_NO_ID(name, data, compat)     \
23491 +       (compat) ? name ## _x32(data) : name(data)
23492 +#else
23493 +#define __COMPAT(name, id, data, compat)       \
23494 +       name(id, data)
23495 +#define __COMPAT_NO_ID(name, data, compat)     \
23496 +       name(data)
23497 +#endif
23498 +
23499 +
23500 +static inline
23501 +long do_vcmd(uint32_t cmd, uint32_t id,
23502 +       struct vx_info *vxi, struct nx_info *nxi,
23503 +       void __user *data, int compat)
23504 +{
23505 +       switch (cmd) {
23506 +
23507 +       case VCMD_get_version:
23508 +               return vc_get_version(id);
23509 +       case VCMD_get_vci:
23510 +               return vc_get_vci(id);
23511 +
23512 +       case VCMD_task_xid:
23513 +               return vc_task_xid(id);
23514 +       case VCMD_vx_info:
23515 +               return vc_vx_info(vxi, data);
23516 +
23517 +       case VCMD_task_nid:
23518 +               return vc_task_nid(id);
23519 +       case VCMD_nx_info:
23520 +               return vc_nx_info(nxi, data);
23521 +
23522 +       case VCMD_task_tag:
23523 +               return vc_task_tag(id);
23524 +
23525 +       case VCMD_set_space_v1:
23526 +               return vc_set_space_v1(vxi, data);
23527 +       /* this is version 2 */
23528 +       case VCMD_set_space:
23529 +               return vc_set_space(vxi, data);
23530 +
23531 +       case VCMD_get_space_mask_v0:
23532 +               return vc_get_space_mask(data, 0);
23533 +       /* this is version 1 */
23534 +       case VCMD_get_space_mask:
23535 +               return vc_get_space_mask(data, 1);
23536 +
23537 +       case VCMD_get_space_default:
23538 +               return vc_get_space_mask(data, -1);
23539 +
23540 +#ifdef CONFIG_IA32_EMULATION
23541 +       case VCMD_get_rlimit:
23542 +               return __COMPAT(vc_get_rlimit, vxi, data, compat);
23543 +       case VCMD_set_rlimit:
23544 +               return __COMPAT(vc_set_rlimit, vxi, data, compat);
23545 +#else
23546 +       case VCMD_get_rlimit:
23547 +               return vc_get_rlimit(vxi, data);
23548 +       case VCMD_set_rlimit:
23549 +               return vc_set_rlimit(vxi, data);
23550 +#endif
23551 +       case VCMD_get_rlimit_mask:
23552 +               return vc_get_rlimit_mask(id, data);
23553 +       case VCMD_reset_hits:
23554 +               return vc_reset_hits(vxi, data);
23555 +       case VCMD_reset_minmax:
23556 +               return vc_reset_minmax(vxi, data);
23557 +
23558 +       case VCMD_get_vhi_name:
23559 +               return vc_get_vhi_name(vxi, data);
23560 +       case VCMD_set_vhi_name:
23561 +               return vc_set_vhi_name(vxi, data);
23562 +
23563 +       case VCMD_ctx_stat:
23564 +               return vc_ctx_stat(vxi, data);
23565 +       case VCMD_virt_stat:
23566 +               return vc_virt_stat(vxi, data);
23567 +       case VCMD_sock_stat:
23568 +               return vc_sock_stat(vxi, data);
23569 +       case VCMD_rlimit_stat:
23570 +               return vc_rlimit_stat(vxi, data);
23571 +
23572 +       case VCMD_set_cflags:
23573 +               return vc_set_cflags(vxi, data);
23574 +       case VCMD_get_cflags:
23575 +               return vc_get_cflags(vxi, data);
23576 +
23577 +       /* this is version 1 */
23578 +       case VCMD_set_ccaps:
23579 +               return vc_set_ccaps(vxi, data);
23580 +       /* this is version 1 */
23581 +       case VCMD_get_ccaps:
23582 +               return vc_get_ccaps(vxi, data);
23583 +       case VCMD_set_bcaps:
23584 +               return vc_set_bcaps(vxi, data);
23585 +       case VCMD_get_bcaps:
23586 +               return vc_get_bcaps(vxi, data);
23587 +
23588 +       case VCMD_set_badness:
23589 +               return vc_set_badness(vxi, data);
23590 +       case VCMD_get_badness:
23591 +               return vc_get_badness(vxi, data);
23592 +
23593 +       case VCMD_set_nflags:
23594 +               return vc_set_nflags(nxi, data);
23595 +       case VCMD_get_nflags:
23596 +               return vc_get_nflags(nxi, data);
23597 +
23598 +       case VCMD_set_ncaps:
23599 +               return vc_set_ncaps(nxi, data);
23600 +       case VCMD_get_ncaps:
23601 +               return vc_get_ncaps(nxi, data);
23602 +
23603 +       case VCMD_set_prio_bias:
23604 +               return vc_set_prio_bias(vxi, data);
23605 +       case VCMD_get_prio_bias:
23606 +               return vc_get_prio_bias(vxi, data);
23607 +       case VCMD_add_dlimit:
23608 +               return __COMPAT(vc_add_dlimit, id, data, compat);
23609 +       case VCMD_rem_dlimit:
23610 +               return __COMPAT(vc_rem_dlimit, id, data, compat);
23611 +       case VCMD_set_dlimit:
23612 +               return __COMPAT(vc_set_dlimit, id, data, compat);
23613 +       case VCMD_get_dlimit:
23614 +               return __COMPAT(vc_get_dlimit, id, data, compat);
23615 +
23616 +       case VCMD_ctx_kill:
23617 +               return vc_ctx_kill(vxi, data);
23618 +
23619 +       case VCMD_wait_exit:
23620 +               return vc_wait_exit(vxi, data);
23621 +
23622 +       case VCMD_get_iattr:
23623 +               return __COMPAT_NO_ID(vc_get_iattr, data, compat);
23624 +       case VCMD_set_iattr:
23625 +               return __COMPAT_NO_ID(vc_set_iattr, data, compat);
23626 +
23627 +       case VCMD_fget_iattr:
23628 +               return vc_fget_iattr(id, data);
23629 +       case VCMD_fset_iattr:
23630 +               return vc_fset_iattr(id, data);
23631 +
23632 +       case VCMD_enter_space_v0:
23633 +               return vc_enter_space_v1(vxi, NULL);
23634 +       case VCMD_enter_space_v1:
23635 +               return vc_enter_space_v1(vxi, data);
23636 +       /* this is version 2 */
23637 +       case VCMD_enter_space:
23638 +               return vc_enter_space(vxi, data);
23639 +
23640 +       case VCMD_ctx_create_v0:
23641 +               return vc_ctx_create(id, NULL);
23642 +       case VCMD_ctx_create:
23643 +               return vc_ctx_create(id, data);
23644 +       case VCMD_ctx_migrate_v0:
23645 +               return vc_ctx_migrate(vxi, NULL);
23646 +       case VCMD_ctx_migrate:
23647 +               return vc_ctx_migrate(vxi, data);
23648 +
23649 +       case VCMD_net_create_v0:
23650 +               return vc_net_create(id, NULL);
23651 +       case VCMD_net_create:
23652 +               return vc_net_create(id, data);
23653 +       case VCMD_net_migrate:
23654 +               return vc_net_migrate(nxi, data);
23655 +
23656 +       case VCMD_tag_migrate:
23657 +               return vc_tag_migrate(id);
23658 +
23659 +       case VCMD_net_add:
23660 +               return vc_net_add(nxi, data);
23661 +       case VCMD_net_remove:
23662 +               return vc_net_remove(nxi, data);
23663 +
23664 +       case VCMD_net_add_ipv4:
23665 +               return vc_net_add_ipv4(nxi, data);
23666 +       case VCMD_net_remove_ipv4:
23667 +               return vc_net_remove_ipv4(nxi, data);
23668 +#ifdef CONFIG_IPV6
23669 +       case VCMD_net_add_ipv6:
23670 +               return vc_net_add_ipv6(nxi, data);
23671 +       case VCMD_net_remove_ipv6:
23672 +               return vc_net_remove_ipv6(nxi, data);
23673 +#endif
23674 +/*     case VCMD_add_match_ipv4:
23675 +               return vc_add_match_ipv4(nxi, data);
23676 +       case VCMD_get_match_ipv4:
23677 +               return vc_get_match_ipv4(nxi, data);
23678 +#ifdef CONFIG_IPV6
23679 +       case VCMD_add_match_ipv6:
23680 +               return vc_add_match_ipv6(nxi, data);
23681 +       case VCMD_get_match_ipv6:
23682 +               return vc_get_match_ipv6(nxi, data);
23683 +#endif */
23684 +
23685 +#ifdef CONFIG_VSERVER_DEVICE
23686 +       case VCMD_set_mapping:
23687 +               return __COMPAT(vc_set_mapping, vxi, data, compat);
23688 +       case VCMD_unset_mapping:
23689 +               return __COMPAT(vc_unset_mapping, vxi, data, compat);
23690 +#endif
23691 +#ifdef CONFIG_VSERVER_HISTORY
23692 +       case VCMD_dump_history:
23693 +               return vc_dump_history(id);
23694 +       case VCMD_read_history:
23695 +               return __COMPAT(vc_read_history, id, data, compat);
23696 +#endif
23697 +       default:
23698 +               vxwprintk_task(1, "unimplemented VCMD_%02d_%d[%d]",
23699 +                       VC_CATEGORY(cmd), VC_COMMAND(cmd), VC_VERSION(cmd));
23700 +       }
23701 +       return -ENOSYS;
23702 +}
23703 +
23704 +
23705 +#define        __VCMD(vcmd, _perm, _args, _flags)              \
23706 +       case VCMD_ ## vcmd: perm = _perm;               \
23707 +               args = _args; flags = _flags; break
23708 +
23709 +
23710 +#define VCA_NONE       0x00
23711 +#define VCA_VXI                0x01
23712 +#define VCA_NXI                0x02
23713 +
23714 +#define VCF_NONE       0x00
23715 +#define VCF_INFO       0x01
23716 +#define VCF_ADMIN      0x02
23717 +#define VCF_ARES       0x06    /* includes admin */
23718 +#define VCF_SETUP      0x08
23719 +
23720 +#define VCF_ZIDOK      0x10    /* zero id okay */
23721 +
23722 +
23723 +static inline
23724 +long do_vserver(uint32_t cmd, uint32_t id, void __user *data, int compat)
23725 +{
23726 +       long ret;
23727 +       int permit = -1, state = 0;
23728 +       int perm = -1, args = 0, flags = 0;
23729 +       struct vx_info *vxi = NULL;
23730 +       struct nx_info *nxi = NULL;
23731 +
23732 +       switch (cmd) {
23733 +       /* unpriviledged commands */
23734 +       __VCMD(get_version,      0, VCA_NONE,   0);
23735 +       __VCMD(get_vci,          0, VCA_NONE,   0);
23736 +       __VCMD(get_rlimit_mask,  0, VCA_NONE,   0);
23737 +       __VCMD(get_space_mask_v0,0, VCA_NONE,   0);
23738 +       __VCMD(get_space_mask,   0, VCA_NONE,   0);
23739 +       __VCMD(get_space_default,0, VCA_NONE,   0);
23740 +
23741 +       /* info commands */
23742 +       __VCMD(task_xid,         2, VCA_NONE,   0);
23743 +       __VCMD(reset_hits,       2, VCA_VXI,    0);
23744 +       __VCMD(reset_minmax,     2, VCA_VXI,    0);
23745 +       __VCMD(vx_info,          3, VCA_VXI,    VCF_INFO);
23746 +       __VCMD(get_bcaps,        3, VCA_VXI,    VCF_INFO);
23747 +       __VCMD(get_ccaps,        3, VCA_VXI,    VCF_INFO);
23748 +       __VCMD(get_cflags,       3, VCA_VXI,    VCF_INFO);
23749 +       __VCMD(get_badness,      3, VCA_VXI,    VCF_INFO);
23750 +       __VCMD(get_vhi_name,     3, VCA_VXI,    VCF_INFO);
23751 +       __VCMD(get_rlimit,       3, VCA_VXI,    VCF_INFO);
23752 +
23753 +       __VCMD(ctx_stat,         3, VCA_VXI,    VCF_INFO);
23754 +       __VCMD(virt_stat,        3, VCA_VXI,    VCF_INFO);
23755 +       __VCMD(sock_stat,        3, VCA_VXI,    VCF_INFO);
23756 +       __VCMD(rlimit_stat,      3, VCA_VXI,    VCF_INFO);
23757 +
23758 +       __VCMD(task_nid,         2, VCA_NONE,   0);
23759 +       __VCMD(nx_info,          3, VCA_NXI,    VCF_INFO);
23760 +       __VCMD(get_ncaps,        3, VCA_NXI,    VCF_INFO);
23761 +       __VCMD(get_nflags,       3, VCA_NXI,    VCF_INFO);
23762 +
23763 +       __VCMD(task_tag,         2, VCA_NONE,   0);
23764 +
23765 +       __VCMD(get_iattr,        2, VCA_NONE,   0);
23766 +       __VCMD(fget_iattr,       2, VCA_NONE,   0);
23767 +       __VCMD(get_dlimit,       3, VCA_NONE,   VCF_INFO);
23768 +       __VCMD(get_prio_bias,    3, VCA_VXI,    VCF_INFO);
23769 +
23770 +       /* lower admin commands */
23771 +       __VCMD(wait_exit,        4, VCA_VXI,    VCF_INFO);
23772 +       __VCMD(ctx_create_v0,    5, VCA_NONE,   0);
23773 +       __VCMD(ctx_create,       5, VCA_NONE,   0);
23774 +       __VCMD(ctx_migrate_v0,   5, VCA_VXI,    VCF_ADMIN);
23775 +       __VCMD(ctx_migrate,      5, VCA_VXI,    VCF_ADMIN);
23776 +       __VCMD(enter_space_v0,   5, VCA_VXI,    VCF_ADMIN);
23777 +       __VCMD(enter_space_v1,   5, VCA_VXI,    VCF_ADMIN);
23778 +       __VCMD(enter_space,      5, VCA_VXI,    VCF_ADMIN);
23779 +
23780 +       __VCMD(net_create_v0,    5, VCA_NONE,   0);
23781 +       __VCMD(net_create,       5, VCA_NONE,   0);
23782 +       __VCMD(net_migrate,      5, VCA_NXI,    VCF_ADMIN);
23783 +
23784 +       __VCMD(tag_migrate,      5, VCA_NONE,   VCF_ADMIN);
23785 +
23786 +       /* higher admin commands */
23787 +       __VCMD(ctx_kill,         6, VCA_VXI,    VCF_ARES);
23788 +       __VCMD(set_space_v1,     7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23789 +       __VCMD(set_space,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23790 +
23791 +       __VCMD(set_ccaps,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23792 +       __VCMD(set_bcaps,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23793 +       __VCMD(set_cflags,       7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23794 +       __VCMD(set_badness,      7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23795 +
23796 +       __VCMD(set_vhi_name,     7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23797 +       __VCMD(set_rlimit,       7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23798 +       __VCMD(set_prio_bias,    7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23799 +
23800 +       __VCMD(set_ncaps,        7, VCA_NXI,    VCF_ARES | VCF_SETUP);
23801 +       __VCMD(set_nflags,       7, VCA_NXI,    VCF_ARES | VCF_SETUP);
23802 +       __VCMD(net_add,          8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23803 +       __VCMD(net_remove,       8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23804 +       __VCMD(net_add_ipv4,     8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23805 +       __VCMD(net_remove_ipv4,  8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23806 +#ifdef CONFIG_IPV6
23807 +       __VCMD(net_add_ipv6,     8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23808 +       __VCMD(net_remove_ipv6,  8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23809 +#endif
23810 +       __VCMD(set_iattr,        7, VCA_NONE,   0);
23811 +       __VCMD(fset_iattr,       7, VCA_NONE,   0);
23812 +       __VCMD(set_dlimit,       7, VCA_NONE,   VCF_ARES);
23813 +       __VCMD(add_dlimit,       8, VCA_NONE,   VCF_ARES);
23814 +       __VCMD(rem_dlimit,       8, VCA_NONE,   VCF_ARES);
23815 +
23816 +#ifdef CONFIG_VSERVER_DEVICE
23817 +       __VCMD(set_mapping,      8, VCA_VXI,    VCF_ARES|VCF_ZIDOK);
23818 +       __VCMD(unset_mapping,    8, VCA_VXI,    VCF_ARES|VCF_ZIDOK);
23819 +#endif
23820 +       /* debug level admin commands */
23821 +#ifdef CONFIG_VSERVER_HISTORY
23822 +       __VCMD(dump_history,     9, VCA_NONE,   0);
23823 +       __VCMD(read_history,     9, VCA_NONE,   0);
23824 +#endif
23825 +
23826 +       default:
23827 +               perm = -1;
23828 +       }
23829 +
23830 +       vxdprintk(VXD_CBIT(switch, 0),
23831 +               "vc: VCMD_%02d_%d[%d], %d,%p [%d,%d,%x,%x]",
23832 +               VC_CATEGORY(cmd), VC_COMMAND(cmd),
23833 +               VC_VERSION(cmd), id, data, compat,
23834 +               perm, args, flags);
23835 +
23836 +       ret = -ENOSYS;
23837 +       if (perm < 0)
23838 +               goto out;
23839 +
23840 +       state = 1;
23841 +       if (!capable(CAP_CONTEXT))
23842 +               goto out;
23843 +
23844 +       state = 2;
23845 +       /* moved here from the individual commands */
23846 +       ret = -EPERM;
23847 +       if ((perm > 1) && !capable(CAP_SYS_ADMIN))
23848 +               goto out;
23849 +
23850 +       state = 3;
23851 +       /* vcmd involves resource management  */
23852 +       ret = -EPERM;
23853 +       if ((flags & VCF_ARES) && !capable(CAP_SYS_RESOURCE))
23854 +               goto out;
23855 +
23856 +       state = 4;
23857 +       /* various legacy exceptions */
23858 +       switch (cmd) {
23859 +       /* will go away when spectator is a cap */
23860 +       case VCMD_ctx_migrate_v0:
23861 +       case VCMD_ctx_migrate:
23862 +               if (id == 1) {
23863 +                       current->xid = 1;
23864 +                       ret = 1;
23865 +                       goto out;
23866 +               }
23867 +               break;
23868 +
23869 +       /* will go away when spectator is a cap */
23870 +       case VCMD_net_migrate:
23871 +               if (id == 1) {
23872 +                       current->nid = 1;
23873 +                       ret = 1;
23874 +                       goto out;
23875 +               }
23876 +               break;
23877 +       }
23878 +
23879 +       /* vcmds are fine by default */
23880 +       permit = 1;
23881 +
23882 +       /* admin type vcmds require admin ... */
23883 +       if (flags & VCF_ADMIN)
23884 +               permit = vx_check(0, VS_ADMIN) ? 1 : 0;
23885 +
23886 +       /* ... but setup type vcmds override that */
23887 +       if (!permit && (flags & VCF_SETUP))
23888 +               permit = vx_flags(VXF_STATE_SETUP, 0) ? 2 : 0;
23889 +
23890 +       state = 5;
23891 +       ret = -EPERM;
23892 +       if (!permit)
23893 +               goto out;
23894 +
23895 +       state = 6;
23896 +       if (!id && (flags & VCF_ZIDOK))
23897 +               goto skip_id;
23898 +
23899 +       ret = -ESRCH;
23900 +       if (args & VCA_VXI) {
23901 +               vxi = lookup_vx_info(id);
23902 +               if (!vxi)
23903 +                       goto out;
23904 +
23905 +               if ((flags & VCF_ADMIN) &&
23906 +                       /* special case kill for shutdown */
23907 +                       (cmd != VCMD_ctx_kill) &&
23908 +                       /* can context be administrated? */
23909 +                       !vx_info_flags(vxi, VXF_STATE_ADMIN, 0)) {
23910 +                       ret = -EACCES;
23911 +                       goto out_vxi;
23912 +               }
23913 +       }
23914 +       state = 7;
23915 +       if (args & VCA_NXI) {
23916 +               nxi = lookup_nx_info(id);
23917 +               if (!nxi)
23918 +                       goto out_vxi;
23919 +
23920 +               if ((flags & VCF_ADMIN) &&
23921 +                       /* can context be administrated? */
23922 +                       !nx_info_flags(nxi, NXF_STATE_ADMIN, 0)) {
23923 +                       ret = -EACCES;
23924 +                       goto out_nxi;
23925 +               }
23926 +       }
23927 +skip_id:
23928 +       state = 8;
23929 +       ret = do_vcmd(cmd, id, vxi, nxi, data, compat);
23930 +
23931 +out_nxi:
23932 +       if ((args & VCA_NXI) && nxi)
23933 +               put_nx_info(nxi);
23934 +out_vxi:
23935 +       if ((args & VCA_VXI) && vxi)
23936 +               put_vx_info(vxi);
23937 +out:
23938 +       vxdprintk(VXD_CBIT(switch, 1),
23939 +               "vc: VCMD_%02d_%d[%d] = %08lx(%ld) [%d,%d]",
23940 +               VC_CATEGORY(cmd), VC_COMMAND(cmd),
23941 +               VC_VERSION(cmd), ret, ret, state, permit);
23942 +       return ret;
23943 +}
23944 +
23945 +asmlinkage long
23946 +sys_vserver(uint32_t cmd, uint32_t id, void __user *data)
23947 +{
23948 +       return do_vserver(cmd, id, data, 0);
23949 +}
23950 +
23951 +#ifdef CONFIG_COMPAT
23952 +
23953 +asmlinkage long
23954 +sys32_vserver(uint32_t cmd, uint32_t id, void __user *data)
23955 +{
23956 +       return do_vserver(cmd, id, data, 1);
23957 +}
23958 +
23959 +#endif /* CONFIG_COMPAT */
23960 diff -NurpP --minimal linux-2.6.38-rc8/kernel/vserver/sysctl.c linux-2.6.38-rc8-vs2.3.0.37-rc6/kernel/vserver/sysctl.c
23961 --- linux-2.6.38-rc8/kernel/vserver/sysctl.c    1970-01-01 01:00:00.000000000 +0100
23962 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/kernel/vserver/sysctl.c     2011-01-29 02:01:07.000000000 +0100
23963 @@ -0,0 +1,241 @@
23964 +/*
23965 + *  kernel/vserver/sysctl.c
23966 + *
23967 + *  Virtual Context Support
23968 + *
23969 + *  Copyright (C) 2004-2007  Herbert Pötzl
23970 + *
23971 + *  V0.01  basic structure
23972 + *
23973 + */
23974 +
23975 +#include <linux/module.h>
23976 +#include <linux/ctype.h>
23977 +#include <linux/sysctl.h>
23978 +#include <linux/parser.h>
23979 +#include <asm/uaccess.h>
23980 +
23981 +enum {
23982 +       CTL_DEBUG_ERROR         = 0,
23983 +       CTL_DEBUG_SWITCH        = 1,
23984 +       CTL_DEBUG_XID,
23985 +       CTL_DEBUG_NID,
23986 +       CTL_DEBUG_TAG,
23987 +       CTL_DEBUG_NET,
23988 +       CTL_DEBUG_LIMIT,
23989 +       CTL_DEBUG_CRES,
23990 +       CTL_DEBUG_DLIM,
23991 +       CTL_DEBUG_QUOTA,
23992 +       CTL_DEBUG_CVIRT,
23993 +       CTL_DEBUG_SPACE,
23994 +       CTL_DEBUG_MISC,
23995 +};
23996 +
23997 +
23998 +unsigned int vx_debug_switch   = 0;
23999 +unsigned int vx_debug_xid      = 0;
24000 +unsigned int vx_debug_nid      = 0;
24001 +unsigned int vx_debug_tag      = 0;
24002 +unsigned int vx_debug_net      = 0;
24003 +unsigned int vx_debug_limit    = 0;
24004 +unsigned int vx_debug_cres     = 0;
24005 +unsigned int vx_debug_dlim     = 0;
24006 +unsigned int vx_debug_quota    = 0;
24007 +unsigned int vx_debug_cvirt    = 0;
24008 +unsigned int vx_debug_space    = 0;
24009 +unsigned int vx_debug_misc     = 0;
24010 +
24011 +
24012 +static struct ctl_table_header *vserver_table_header;
24013 +static ctl_table vserver_root_table[];
24014 +
24015 +
24016 +void vserver_register_sysctl(void)
24017 +{
24018 +       if (!vserver_table_header) {
24019 +               vserver_table_header = register_sysctl_table(vserver_root_table);
24020 +       }
24021 +
24022 +}
24023 +
24024 +void vserver_unregister_sysctl(void)
24025 +{
24026 +       if (vserver_table_header) {
24027 +               unregister_sysctl_table(vserver_table_header);
24028 +               vserver_table_header = NULL;
24029 +       }
24030 +}
24031 +
24032 +
24033 +static int proc_dodebug(ctl_table *table, int write,
24034 +       void __user *buffer, size_t *lenp, loff_t *ppos)
24035 +{
24036 +       char            tmpbuf[20], *p, c;
24037 +       unsigned int    value;
24038 +       size_t          left, len;
24039 +
24040 +       if ((*ppos && !write) || !*lenp) {
24041 +               *lenp = 0;
24042 +               return 0;
24043 +       }
24044 +
24045 +       left = *lenp;
24046 +
24047 +       if (write) {
24048 +               if (!access_ok(VERIFY_READ, buffer, left))
24049 +                       return -EFAULT;
24050 +               p = (char *)buffer;
24051 +               while (left && __get_user(c, p) >= 0 && isspace(c))
24052 +                       left--, p++;
24053 +               if (!left)
24054 +                       goto done;
24055 +
24056 +               if (left > sizeof(tmpbuf) - 1)
24057 +                       return -EINVAL;
24058 +               if (copy_from_user(tmpbuf, p, left))
24059 +                       return -EFAULT;
24060 +               tmpbuf[left] = '\0';
24061 +
24062 +               for (p = tmpbuf, value = 0; '0' <= *p && *p <= '9'; p++, left--)
24063 +                       value = 10 * value + (*p - '0');
24064 +               if (*p && !isspace(*p))
24065 +                       return -EINVAL;
24066 +               while (left && isspace(*p))
24067 +                       left--, p++;
24068 +               *(unsigned int *)table->data = value;
24069 +       } else {
24070 +               if (!access_ok(VERIFY_WRITE, buffer, left))
24071 +                       return -EFAULT;
24072 +               len = sprintf(tmpbuf, "%d", *(unsigned int *)table->data);
24073 +               if (len > left)
24074 +                       len = left;
24075 +               if (__copy_to_user(buffer, tmpbuf, len))
24076 +                       return -EFAULT;
24077 +               if ((left -= len) > 0) {
24078 +                       if (put_user('\n', (char *)buffer + len))
24079 +                               return -EFAULT;
24080 +                       left--;
24081 +               }
24082 +       }
24083 +
24084 +done:
24085 +       *lenp -= left;
24086 +       *ppos += *lenp;
24087 +       return 0;
24088 +}
24089 +
24090 +static int zero;
24091 +
24092 +#define        CTL_ENTRY(ctl, name)                            \
24093 +       {                                               \
24094 +               .procname       = #name,                \
24095 +               .data           = &vx_ ## name,         \
24096 +               .maxlen         = sizeof(int),          \
24097 +               .mode           = 0644,                 \
24098 +               .proc_handler   = &proc_dodebug,        \
24099 +               .extra1         = &zero,                \
24100 +               .extra2         = &zero,                \
24101 +       }
24102 +
24103 +static ctl_table vserver_debug_table[] = {
24104 +       CTL_ENTRY(CTL_DEBUG_SWITCH,     debug_switch),
24105 +       CTL_ENTRY(CTL_DEBUG_XID,        debug_xid),
24106 +       CTL_ENTRY(CTL_DEBUG_NID,        debug_nid),
24107 +       CTL_ENTRY(CTL_DEBUG_TAG,        debug_tag),
24108 +       CTL_ENTRY(CTL_DEBUG_NET,        debug_net),
24109 +       CTL_ENTRY(CTL_DEBUG_LIMIT,      debug_limit),
24110 +       CTL_ENTRY(CTL_DEBUG_CRES,       debug_cres),
24111 +       CTL_ENTRY(CTL_DEBUG_DLIM,       debug_dlim),
24112 +       CTL_ENTRY(CTL_DEBUG_QUOTA,      debug_quota),
24113 +       CTL_ENTRY(CTL_DEBUG_CVIRT,      debug_cvirt),
24114 +       CTL_ENTRY(CTL_DEBUG_SPACE,      debug_space),
24115 +       CTL_ENTRY(CTL_DEBUG_MISC,       debug_misc),
24116 +       { 0 }
24117 +};
24118 +
24119 +static ctl_table vserver_root_table[] = {
24120 +       {
24121 +               .procname       = "vserver",
24122 +               .mode           = 0555,
24123 +               .child          = vserver_debug_table
24124 +       },
24125 +       { 0 }
24126 +};
24127 +
24128 +
24129 +static match_table_t tokens = {
24130 +       { CTL_DEBUG_SWITCH,     "switch=%x"     },
24131 +       { CTL_DEBUG_XID,        "xid=%x"        },
24132 +       { CTL_DEBUG_NID,        "nid=%x"        },
24133 +       { CTL_DEBUG_TAG,        "tag=%x"        },
24134 +       { CTL_DEBUG_NET,        "net=%x"        },
24135 +       { CTL_DEBUG_LIMIT,      "limit=%x"      },
24136 +       { CTL_DEBUG_CRES,       "cres=%x"       },
24137 +       { CTL_DEBUG_DLIM,       "dlim=%x"       },
24138 +       { CTL_DEBUG_QUOTA,      "quota=%x"      },
24139 +       { CTL_DEBUG_CVIRT,      "cvirt=%x"      },
24140 +       { CTL_DEBUG_SPACE,      "space=%x"      },
24141 +       { CTL_DEBUG_MISC,       "misc=%x"       },
24142 +       { CTL_DEBUG_ERROR,      NULL            }
24143 +};
24144 +
24145 +#define        HANDLE_CASE(id, name, val)                              \
24146 +       case CTL_DEBUG_ ## id:                                  \
24147 +               vx_debug_ ## name = val;                        \
24148 +               printk("vs_debug_" #name "=0x%x\n", val);       \
24149 +               break
24150 +
24151 +
24152 +static int __init vs_debug_setup(char *str)
24153 +{
24154 +       char *p;
24155 +       int token;
24156 +
24157 +       printk("vs_debug_setup(%s)\n", str);
24158 +       while ((p = strsep(&str, ",")) != NULL) {
24159 +               substring_t args[MAX_OPT_ARGS];
24160 +               unsigned int value;
24161 +
24162 +               if (!*p)
24163 +                       continue;
24164 +
24165 +               token = match_token(p, tokens, args);
24166 +               value = (token > 0) ? simple_strtoul(args[0].from, NULL, 0) : 0;
24167 +
24168 +               switch (token) {
24169 +               HANDLE_CASE(SWITCH, switch, value);
24170 +               HANDLE_CASE(XID,    xid,    value);
24171 +               HANDLE_CASE(NID,    nid,    value);
24172 +               HANDLE_CASE(TAG,    tag,    value);
24173 +               HANDLE_CASE(NET,    net,    value);
24174 +               HANDLE_CASE(LIMIT,  limit,  value);
24175 +               HANDLE_CASE(CRES,   cres,   value);
24176 +               HANDLE_CASE(DLIM,   dlim,   value);
24177 +               HANDLE_CASE(QUOTA,  quota,  value);
24178 +               HANDLE_CASE(CVIRT,  cvirt,  value);
24179 +               HANDLE_CASE(SPACE,  space,  value);
24180 +               HANDLE_CASE(MISC,   misc,   value);
24181 +               default:
24182 +                       return -EINVAL;
24183 +                       break;
24184 +               }
24185 +       }
24186 +       return 1;
24187 +}
24188 +
24189 +__setup("vsdebug=", vs_debug_setup);
24190 +
24191 +
24192 +
24193 +EXPORT_SYMBOL_GPL(vx_debug_switch);
24194 +EXPORT_SYMBOL_GPL(vx_debug_xid);
24195 +EXPORT_SYMBOL_GPL(vx_debug_nid);
24196 +EXPORT_SYMBOL_GPL(vx_debug_net);
24197 +EXPORT_SYMBOL_GPL(vx_debug_limit);
24198 +EXPORT_SYMBOL_GPL(vx_debug_cres);
24199 +EXPORT_SYMBOL_GPL(vx_debug_dlim);
24200 +EXPORT_SYMBOL_GPL(vx_debug_quota);
24201 +EXPORT_SYMBOL_GPL(vx_debug_cvirt);
24202 +EXPORT_SYMBOL_GPL(vx_debug_space);
24203 +EXPORT_SYMBOL_GPL(vx_debug_misc);
24204 +
24205 diff -NurpP --minimal linux-2.6.38-rc8/kernel/vserver/tag.c linux-2.6.38-rc8-vs2.3.0.37-rc6/kernel/vserver/tag.c
24206 --- linux-2.6.38-rc8/kernel/vserver/tag.c       1970-01-01 01:00:00.000000000 +0100
24207 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/kernel/vserver/tag.c        2011-01-29 02:01:07.000000000 +0100
24208 @@ -0,0 +1,63 @@
24209 +/*
24210 + *  linux/kernel/vserver/tag.c
24211 + *
24212 + *  Virtual Server: Shallow Tag Space
24213 + *
24214 + *  Copyright (C) 2007  Herbert Pötzl
24215 + *
24216 + *  V0.01  basic implementation
24217 + *
24218 + */
24219 +
24220 +#include <linux/sched.h>
24221 +#include <linux/vserver/debug.h>
24222 +#include <linux/vs_pid.h>
24223 +#include <linux/vs_tag.h>
24224 +
24225 +#include <linux/vserver/tag_cmd.h>
24226 +
24227 +
24228 +int dx_migrate_task(struct task_struct *p, tag_t tag)
24229 +{
24230 +       if (!p)
24231 +               BUG();
24232 +
24233 +       vxdprintk(VXD_CBIT(tag, 5),
24234 +               "dx_migrate_task(%p[#%d],#%d)", p, p->tag, tag);
24235 +
24236 +       task_lock(p);
24237 +       p->tag = tag;
24238 +       task_unlock(p);
24239 +
24240 +       vxdprintk(VXD_CBIT(tag, 5),
24241 +               "moved task %p into [#%d]", p, tag);
24242 +       return 0;
24243 +}
24244 +
24245 +/* vserver syscall commands below here */
24246 +
24247 +/* taks xid and vx_info functions */
24248 +
24249 +
24250 +int vc_task_tag(uint32_t id)
24251 +{
24252 +       tag_t tag;
24253 +
24254 +       if (id) {
24255 +               struct task_struct *tsk;
24256 +               read_lock(&tasklist_lock);
24257 +               tsk = find_task_by_real_pid(id);
24258 +               tag = (tsk) ? tsk->tag : -ESRCH;
24259 +               read_unlock(&tasklist_lock);
24260 +       } else
24261 +               tag = dx_current_tag();
24262 +       return tag;
24263 +}
24264 +
24265 +
24266 +int vc_tag_migrate(uint32_t tag)
24267 +{
24268 +       return dx_migrate_task(current, tag & 0xFFFF);
24269 +}
24270 +
24271 +
24272 diff -NurpP --minimal linux-2.6.38-rc8/kernel/vserver/vci_config.h linux-2.6.38-rc8-vs2.3.0.37-rc6/kernel/vserver/vci_config.h
24273 --- linux-2.6.38-rc8/kernel/vserver/vci_config.h        1970-01-01 01:00:00.000000000 +0100
24274 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/kernel/vserver/vci_config.h 2011-01-29 02:01:07.000000000 +0100
24275 @@ -0,0 +1,82 @@
24276 +
24277 +/*  interface version */
24278 +
24279 +#define VCI_VERSION            0x00020307
24280 +
24281 +
24282 +enum {
24283 +       VCI_KCBIT_NO_DYNAMIC = 0,
24284 +
24285 +       VCI_KCBIT_PROC_SECURE = 4,
24286 +       VCI_KCBIT_HARDCPU = 5,
24287 +       VCI_KCBIT_IDLELIMIT = 6,
24288 +       VCI_KCBIT_IDLETIME = 7,
24289 +
24290 +       VCI_KCBIT_COWBL = 8,
24291 +       VCI_KCBIT_FULLCOWBL = 9,
24292 +       VCI_KCBIT_SPACES = 10,
24293 +       VCI_KCBIT_NETV2 = 11,
24294 +       VCI_KCBIT_MEMCG = 12,
24295 +
24296 +       VCI_KCBIT_DEBUG = 16,
24297 +       VCI_KCBIT_HISTORY = 20,
24298 +       VCI_KCBIT_TAGGED = 24,
24299 +       VCI_KCBIT_PPTAG = 28,
24300 +
24301 +       VCI_KCBIT_MORE = 31,
24302 +};
24303 +
24304 +
24305 +static inline uint32_t vci_kernel_config(void)
24306 +{
24307 +       return
24308 +       (1 << VCI_KCBIT_NO_DYNAMIC) |
24309 +
24310 +       /* configured features */
24311 +#ifdef CONFIG_VSERVER_PROC_SECURE
24312 +       (1 << VCI_KCBIT_PROC_SECURE) |
24313 +#endif
24314 +#ifdef CONFIG_VSERVER_IDLELIMIT
24315 +       (1 << VCI_KCBIT_IDLELIMIT) |
24316 +#endif
24317 +#ifdef CONFIG_VSERVER_IDLETIME
24318 +       (1 << VCI_KCBIT_IDLETIME) |
24319 +#endif
24320 +#ifdef CONFIG_VSERVER_COWBL
24321 +       (1 << VCI_KCBIT_COWBL) |
24322 +       (1 << VCI_KCBIT_FULLCOWBL) |
24323 +#endif
24324 +       (1 << VCI_KCBIT_SPACES) |
24325 +       (1 << VCI_KCBIT_NETV2) |
24326 +#ifdef CONFIG_CGROUP_MEM_RES_CTLR
24327 +       (1 << VCI_KCBIT_MEMCG) |
24328 +#endif
24329 +
24330 +       /* debug options */
24331 +#ifdef CONFIG_VSERVER_DEBUG
24332 +       (1 << VCI_KCBIT_DEBUG) |
24333 +#endif
24334 +#ifdef CONFIG_VSERVER_HISTORY
24335 +       (1 << VCI_KCBIT_HISTORY) |
24336 +#endif
24337 +
24338 +       /* inode context tagging */
24339 +#if    defined(CONFIG_TAGGING_NONE)
24340 +       (0 << VCI_KCBIT_TAGGED) |
24341 +#elif  defined(CONFIG_TAGGING_UID16)
24342 +       (1 << VCI_KCBIT_TAGGED) |
24343 +#elif  defined(CONFIG_TAGGING_GID16)
24344 +       (2 << VCI_KCBIT_TAGGED) |
24345 +#elif  defined(CONFIG_TAGGING_ID24)
24346 +       (3 << VCI_KCBIT_TAGGED) |
24347 +#elif  defined(CONFIG_TAGGING_INTERN)
24348 +       (4 << VCI_KCBIT_TAGGED) |
24349 +#elif  defined(CONFIG_TAGGING_RUNTIME)
24350 +       (5 << VCI_KCBIT_TAGGED) |
24351 +#else
24352 +       (7 << VCI_KCBIT_TAGGED) |
24353 +#endif
24354 +       (1 << VCI_KCBIT_PPTAG) |
24355 +       0;
24356 +}
24357 +
24358 diff -NurpP --minimal linux-2.6.38-rc8/mm/filemap_xip.c linux-2.6.38-rc8-vs2.3.0.37-rc6/mm/filemap_xip.c
24359 --- linux-2.6.38-rc8/mm/filemap_xip.c   2010-07-07 18:31:58.000000000 +0200
24360 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/mm/filemap_xip.c    2011-01-29 02:01:07.000000000 +0100
24361 @@ -18,6 +18,7 @@
24362  #include <linux/seqlock.h>
24363  #include <linux/mutex.h>
24364  #include <linux/gfp.h>
24365 +#include <linux/vs_memory.h>
24366  #include <asm/tlbflush.h>
24367  #include <asm/io.h>
24368  
24369 diff -NurpP --minimal linux-2.6.38-rc8/mm/fremap.c linux-2.6.38-rc8-vs2.3.0.37-rc6/mm/fremap.c
24370 --- linux-2.6.38-rc8/mm/fremap.c        2010-10-21 13:07:57.000000000 +0200
24371 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/mm/fremap.c 2011-01-29 02:01:07.000000000 +0100
24372 @@ -16,6 +16,7 @@
24373  #include <linux/module.h>
24374  #include <linux/syscalls.h>
24375  #include <linux/mmu_notifier.h>
24376 +#include <linux/vs_memory.h>
24377  
24378  #include <asm/mmu_context.h>
24379  #include <asm/cacheflush.h>
24380 diff -NurpP --minimal linux-2.6.38-rc8/mm/hugetlb.c linux-2.6.38-rc8-vs2.3.0.37-rc6/mm/hugetlb.c
24381 --- linux-2.6.38-rc8/mm/hugetlb.c       2011-03-10 17:09:29.000000000 +0100
24382 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/mm/hugetlb.c        2011-01-29 02:01:07.000000000 +0100
24383 @@ -28,6 +28,7 @@
24384  
24385  #include <linux/hugetlb.h>
24386  #include <linux/node.h>
24387 +#include <linux/vs_memory.h>
24388  #include "internal.h"
24389  
24390  const unsigned long hugetlb_zero = 0, hugetlb_infinity = ~0UL;
24391 diff -NurpP --minimal linux-2.6.38-rc8/mm/memcontrol.c linux-2.6.38-rc8-vs2.3.0.37-rc6/mm/memcontrol.c
24392 --- linux-2.6.38-rc8/mm/memcontrol.c    2011-03-10 17:09:29.000000000 +0100
24393 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/mm/memcontrol.c     2011-02-17 02:17:51.000000000 +0100
24394 @@ -681,6 +681,31 @@ struct mem_cgroup *mem_cgroup_from_task(
24395                                 struct mem_cgroup, css);
24396  }
24397  
24398 +u64 mem_cgroup_res_read_u64(struct mem_cgroup *mem, int member)
24399 +{
24400 +       return res_counter_read_u64(&mem->res, member);
24401 +}
24402 +
24403 +u64 mem_cgroup_memsw_read_u64(struct mem_cgroup *mem, int member)
24404 +{
24405 +       return res_counter_read_u64(&mem->memsw, member);
24406 +}
24407 +
24408 +s64 mem_cgroup_stat_read_cache(struct mem_cgroup *mem)
24409 +{
24410 +       return mem_cgroup_read_stat(mem, MEM_CGROUP_STAT_CACHE);
24411 +}
24412 +
24413 +s64 mem_cgroup_stat_read_anon(struct mem_cgroup *mem)
24414 +{
24415 +       return mem_cgroup_read_stat(mem, MEM_CGROUP_STAT_RSS);
24416 +}
24417 +
24418 +s64 mem_cgroup_stat_read_mapped(struct mem_cgroup *mem)
24419 +{
24420 +       return mem_cgroup_read_stat(mem, MEM_CGROUP_STAT_FILE_MAPPED);
24421 +}
24422 +
24423  static struct mem_cgroup *try_get_mem_cgroup_from_mm(struct mm_struct *mm)
24424  {
24425         struct mem_cgroup *mem = NULL;
24426 diff -NurpP --minimal linux-2.6.38-rc8/mm/memory.c linux-2.6.38-rc8-vs2.3.0.37-rc6/mm/memory.c
24427 --- linux-2.6.38-rc8/mm/memory.c        2011-03-10 17:09:29.000000000 +0100
24428 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/mm/memory.c 2011-03-07 16:53:28.000000000 +0100
24429 @@ -3225,6 +3225,7 @@ int handle_pte_fault(struct mm_struct *m
24430  {
24431         pte_t entry;
24432         spinlock_t *ptl;
24433 +       int ret = 0, type = VXPT_UNKNOWN;
24434  
24435         entry = *pte;
24436         if (!pte_present(entry)) {
24437 @@ -3249,9 +3250,12 @@ int handle_pte_fault(struct mm_struct *m
24438         if (unlikely(!pte_same(*pte, entry)))
24439                 goto unlock;
24440         if (flags & FAULT_FLAG_WRITE) {
24441 -               if (!pte_write(entry))
24442 -                       return do_wp_page(mm, vma, address,
24443 +               if (!pte_write(entry)) {
24444 +                       ret = do_wp_page(mm, vma, address,
24445                                         pte, pmd, ptl, entry);
24446 +                       type = VXPT_WRITE;
24447 +                       goto out;
24448 +               }
24449                 entry = pte_mkdirty(entry);
24450         }
24451         entry = pte_mkyoung(entry);
24452 @@ -3269,7 +3273,10 @@ int handle_pte_fault(struct mm_struct *m
24453         }
24454  unlock:
24455         pte_unmap_unlock(pte, ptl);
24456 -       return 0;
24457 +       ret = 0;
24458 +out:
24459 +       vx_page_fault(mm, vma, type, ret);
24460 +       return ret;
24461  }
24462  
24463  /*
24464 diff -NurpP --minimal linux-2.6.38-rc8/mm/mremap.c linux-2.6.38-rc8-vs2.3.0.37-rc6/mm/mremap.c
24465 --- linux-2.6.38-rc8/mm/mremap.c        2011-03-10 17:09:29.000000000 +0100
24466 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/mm/mremap.c 2011-03-07 16:53:28.000000000 +0100
24467 @@ -19,6 +19,7 @@
24468  #include <linux/security.h>
24469  #include <linux/syscalls.h>
24470  #include <linux/mmu_notifier.h>
24471 +#include <linux/vs_memory.h>
24472  
24473  #include <asm/uaccess.h>
24474  #include <asm/cacheflush.h>
24475 diff -NurpP --minimal linux-2.6.38-rc8/mm/oom_kill.c linux-2.6.38-rc8-vs2.3.0.37-rc6/mm/oom_kill.c
24476 --- linux-2.6.38-rc8/mm/oom_kill.c      2011-01-05 21:50:40.000000000 +0100
24477 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/mm/oom_kill.c       2011-01-29 02:01:07.000000000 +0100
24478 @@ -31,6 +31,9 @@
24479  #include <linux/memcontrol.h>
24480  #include <linux/mempolicy.h>
24481  #include <linux/security.h>
24482 +#include <linux/reboot.h>
24483 +#include <linux/vs_memory.h>
24484 +#include <linux/vs_context.h>
24485  
24486  int sysctl_panic_on_oom;
24487  int sysctl_oom_kill_allocating_task;
24488 @@ -124,11 +127,18 @@ struct task_struct *find_lock_task_mm(st
24489  static bool oom_unkillable_task(struct task_struct *p,
24490                 const struct mem_cgroup *mem, const nodemask_t *nodemask)
24491  {
24492 -       if (is_global_init(p))
24493 +       unsigned xid = vx_current_xid();
24494 +
24495 +       /* skip the init task, global and per guest */
24496 +       if (task_is_init(p))
24497                 return true;
24498         if (p->flags & PF_KTHREAD)
24499                 return true;
24500  
24501 +       /* skip other guest and host processes if oom in guest */
24502 +       if (xid && vx_task_xid(p) != xid)
24503 +               return true;
24504 +
24505         /* When mem_cgroup_out_of_memory() and p is not member of the group */
24506         if (mem && !task_in_mem_cgroup(p, mem))
24507                 return true;
24508 @@ -210,6 +220,18 @@ unsigned int oom_badness(struct task_str
24509         points += p->signal->oom_score_adj;
24510  
24511         /*
24512 +        * add points for context badness and
24513 +        * reduce badness for processes belonging to
24514 +        * a different context
24515 +        */
24516 +
24517 +       points += vx_badness(p, p->mm);
24518 +
24519 +       if ((vx_current_xid() > 1) &&
24520 +               vx_current_xid() != vx_task_xid(p))
24521 +               points /= 16;
24522 +
24523 +       /*
24524          * Never return 0 for an eligible task that may be killed since it's
24525          * possible that no single user task uses more than 0.1% of memory and
24526          * no single admin tasks uses more than 3.0%.
24527 @@ -414,8 +436,8 @@ static int oom_kill_task(struct task_str
24528         /* mm cannot be safely dereferenced after task_unlock(p) */
24529         mm = p->mm;
24530  
24531 -       pr_err("Killed process %d (%s) total-vm:%lukB, anon-rss:%lukB, file-rss:%lukB\n",
24532 -               task_pid_nr(p), p->comm, K(p->mm->total_vm),
24533 +       pr_err("Killed process %d:#%u (%s) total-vm:%lukB, anon-rss:%lukB, file-rss:%lukB\n",
24534 +               task_pid_nr(p), p->xid, p->comm, K(p->mm->total_vm),
24535                 K(get_mm_counter(p->mm, MM_ANONPAGES)),
24536                 K(get_mm_counter(p->mm, MM_FILEPAGES)));
24537         task_unlock(p);
24538 @@ -477,8 +499,8 @@ static int oom_kill_process(struct task_
24539         }
24540  
24541         task_lock(p);
24542 -       pr_err("%s: Kill process %d (%s) score %d or sacrifice child\n",
24543 -               message, task_pid_nr(p), p->comm, points);
24544 +       pr_err("%s: Kill process %d:#%u (%s) score %d or sacrifice child\n",
24545 +               message, task_pid_nr(p), p->xid, p->comm, points);
24546         task_unlock(p);
24547  
24548         /*
24549 @@ -567,6 +589,8 @@ int unregister_oom_notifier(struct notif
24550  }
24551  EXPORT_SYMBOL_GPL(unregister_oom_notifier);
24552  
24553 +long vs_oom_action(unsigned int);
24554 +
24555  /*
24556   * Try to acquire the OOM killer lock for the zones in zonelist.  Returns zero
24557   * if a parallel OOM killing is already taking place that includes a zone in
24558 @@ -726,7 +750,12 @@ retry:
24559         if (!p) {
24560                 dump_header(NULL, gfp_mask, order, NULL, mpol_mask);
24561                 read_unlock(&tasklist_lock);
24562 -               panic("Out of memory and no killable processes...\n");
24563 +
24564 +               /* avoid panic for guest OOM */
24565 +               if (current->xid)
24566 +                       vs_oom_action(LINUX_REBOOT_CMD_OOM);
24567 +               else
24568 +                       panic("Out of memory and no killable processes...\n");
24569         }
24570  
24571         if (oom_kill_process(p, gfp_mask, order, points, totalpages, NULL,
24572 diff -NurpP --minimal linux-2.6.38-rc8/mm/page_alloc.c linux-2.6.38-rc8-vs2.3.0.37-rc6/mm/page_alloc.c
24573 --- linux-2.6.38-rc8/mm/page_alloc.c    2011-03-10 17:09:30.000000000 +0100
24574 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/mm/page_alloc.c     2011-03-07 16:53:28.000000000 +0100
24575 @@ -53,6 +53,8 @@
24576  #include <linux/compaction.h>
24577  #include <trace/events/kmem.h>
24578  #include <linux/ftrace_event.h>
24579 +#include <linux/vs_base.h>
24580 +#include <linux/vs_limit.h>
24581  
24582  #include <asm/tlbflush.h>
24583  #include <asm/div64.h>
24584 @@ -2388,6 +2390,9 @@ void si_meminfo(struct sysinfo *val)
24585         val->totalhigh = totalhigh_pages;
24586         val->freehigh = nr_free_highpages();
24587         val->mem_unit = PAGE_SIZE;
24588 +
24589 +       if (vx_flags(VXF_VIRT_MEM, 0))
24590 +               vx_vsi_meminfo(val);
24591  }
24592  
24593  EXPORT_SYMBOL(si_meminfo);
24594 @@ -2408,6 +2413,9 @@ void si_meminfo_node(struct sysinfo *val
24595         val->freehigh = 0;
24596  #endif
24597         val->mem_unit = PAGE_SIZE;
24598 +
24599 +       if (vx_flags(VXF_VIRT_MEM, 0))
24600 +               vx_vsi_meminfo(val);
24601  }
24602  #endif
24603  
24604 diff -NurpP --minimal linux-2.6.38-rc8/mm/pgtable-generic.c linux-2.6.38-rc8-vs2.3.0.37-rc6/mm/pgtable-generic.c
24605 --- linux-2.6.38-rc8/mm/pgtable-generic.c       2011-03-10 17:09:30.000000000 +0100
24606 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/mm/pgtable-generic.c        2011-02-02 22:20:27.000000000 +0100
24607 @@ -6,6 +6,8 @@
24608   *  Copyright (C) 2010  Linus Torvalds
24609   */
24610  
24611 +#include <linux/mm.h>
24612 +
24613  #include <linux/pagemap.h>
24614  #include <asm/tlb.h>
24615  #include <asm-generic/pgtable.h>
24616 diff -NurpP --minimal linux-2.6.38-rc8/mm/rmap.c linux-2.6.38-rc8-vs2.3.0.37-rc6/mm/rmap.c
24617 --- linux-2.6.38-rc8/mm/rmap.c  2011-03-10 17:09:30.000000000 +0100
24618 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/mm/rmap.c   2011-01-29 02:01:07.000000000 +0100
24619 @@ -57,6 +57,7 @@
24620  #include <linux/mmu_notifier.h>
24621  #include <linux/migrate.h>
24622  #include <linux/hugetlb.h>
24623 +#include <linux/vs_memory.h>
24624  
24625  #include <asm/tlbflush.h>
24626  
24627 diff -NurpP --minimal linux-2.6.38-rc8/mm/shmem.c linux-2.6.38-rc8-vs2.3.0.37-rc6/mm/shmem.c
24628 --- linux-2.6.38-rc8/mm/shmem.c 2011-03-10 17:09:30.000000000 +0100
24629 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/mm/shmem.c  2011-01-29 02:01:07.000000000 +0100
24630 @@ -1816,7 +1816,7 @@ static int shmem_statfs(struct dentry *d
24631  {
24632         struct shmem_sb_info *sbinfo = SHMEM_SB(dentry->d_sb);
24633  
24634 -       buf->f_type = TMPFS_MAGIC;
24635 +       buf->f_type = TMPFS_SUPER_MAGIC;
24636         buf->f_bsize = PAGE_CACHE_SIZE;
24637         buf->f_namelen = NAME_MAX;
24638         if (sbinfo->max_blocks) {
24639 @@ -2378,7 +2378,7 @@ int shmem_fill_super(struct super_block 
24640         sb->s_maxbytes = SHMEM_MAX_BYTES;
24641         sb->s_blocksize = PAGE_CACHE_SIZE;
24642         sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
24643 -       sb->s_magic = TMPFS_MAGIC;
24644 +       sb->s_magic = TMPFS_SUPER_MAGIC;
24645         sb->s_op = &shmem_ops;
24646         sb->s_time_gran = 1;
24647  #ifdef CONFIG_TMPFS_POSIX_ACL
24648 diff -NurpP --minimal linux-2.6.38-rc8/mm/slab.c linux-2.6.38-rc8-vs2.3.0.37-rc6/mm/slab.c
24649 --- linux-2.6.38-rc8/mm/slab.c  2011-03-10 17:09:30.000000000 +0100
24650 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/mm/slab.c   2011-01-29 02:01:07.000000000 +0100
24651 @@ -407,6 +407,8 @@ static void kmem_list3_init(struct kmem_
24652  #define STATS_INC_FREEMISS(x)  do { } while (0)
24653  #endif
24654  
24655 +#include "slab_vs.h"
24656 +
24657  #if DEBUG
24658  
24659  /*
24660 @@ -3346,6 +3348,7 @@ retry:
24661  
24662         obj = slab_get_obj(cachep, slabp, nodeid);
24663         check_slabp(cachep, slabp);
24664 +       vx_slab_alloc(cachep, flags);
24665         l3->free_objects--;
24666         /* move slabp to correct slabp list: */
24667         list_del(&slabp->list);
24668 @@ -3423,6 +3426,7 @@ __cache_alloc_node(struct kmem_cache *ca
24669         /* ___cache_alloc_node can fall back to other nodes */
24670         ptr = ____cache_alloc_node(cachep, flags, nodeid);
24671    out:
24672 +       vx_slab_alloc(cachep, flags);
24673         local_irq_restore(save_flags);
24674         ptr = cache_alloc_debugcheck_after(cachep, flags, ptr, caller);
24675         kmemleak_alloc_recursive(ptr, obj_size(cachep), 1, cachep->flags,
24676 @@ -3609,6 +3613,7 @@ static inline void __cache_free(struct k
24677         check_irq_off();
24678         kmemleak_free_recursive(objp, cachep->flags);
24679         objp = cache_free_debugcheck(cachep, objp, __builtin_return_address(0));
24680 +       vx_slab_free(cachep);
24681  
24682         kmemcheck_slab_free(cachep, objp, obj_size(cachep));
24683  
24684 diff -NurpP --minimal linux-2.6.38-rc8/mm/slab_vs.h linux-2.6.38-rc8-vs2.3.0.37-rc6/mm/slab_vs.h
24685 --- linux-2.6.38-rc8/mm/slab_vs.h       1970-01-01 01:00:00.000000000 +0100
24686 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/mm/slab_vs.h        2011-01-29 02:01:07.000000000 +0100
24687 @@ -0,0 +1,29 @@
24688 +
24689 +#include <linux/vserver/context.h>
24690 +
24691 +#include <linux/vs_context.h>
24692 +
24693 +static inline
24694 +void vx_slab_alloc(struct kmem_cache *cachep, gfp_t flags)
24695 +{
24696 +       int what = gfp_zone(cachep->gfpflags);
24697 +       struct vx_info *vxi = current_vx_info();
24698 +
24699 +       if (!vxi)
24700 +               return;
24701 +
24702 +       atomic_add(cachep->buffer_size, &vxi->cacct.slab[what]);
24703 +}
24704 +
24705 +static inline
24706 +void vx_slab_free(struct kmem_cache *cachep)
24707 +{
24708 +       int what = gfp_zone(cachep->gfpflags);
24709 +       struct vx_info *vxi = current_vx_info();
24710 +
24711 +       if (!vxi)
24712 +               return;
24713 +
24714 +       atomic_sub(cachep->buffer_size, &vxi->cacct.slab[what]);
24715 +}
24716 +
24717 diff -NurpP --minimal linux-2.6.38-rc8/mm/swapfile.c linux-2.6.38-rc8-vs2.3.0.37-rc6/mm/swapfile.c
24718 --- linux-2.6.38-rc8/mm/swapfile.c      2011-03-10 17:09:30.000000000 +0100
24719 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/mm/swapfile.c       2011-03-07 16:53:28.000000000 +0100
24720 @@ -36,6 +36,8 @@
24721  #include <asm/tlbflush.h>
24722  #include <linux/swapops.h>
24723  #include <linux/page_cgroup.h>
24724 +#include <linux/vs_base.h>
24725 +#include <linux/vs_memory.h>
24726  
24727  static bool swap_count_continued(struct swap_info_struct *, pgoff_t,
24728                                  unsigned char);
24729 @@ -1775,6 +1777,16 @@ static int swap_show(struct seq_file *sw
24730  
24731         if (si == SEQ_START_TOKEN) {
24732                 seq_puts(swap,"Filename\t\t\t\tType\t\tSize\tUsed\tPriority\n");
24733 +               if (vx_flags(VXF_VIRT_MEM, 0)) {
24734 +                       struct sysinfo si;
24735 +
24736 +                       vx_vsi_swapinfo(&si);
24737 +                       if (si.totalswap < (1 << 10))
24738 +                               return 0;
24739 +                       seq_printf(swap, "%s\t\t\t\t\t%s\t%lu\t%lu\t%d\n",
24740 +                               "hdv0", "partition", si.totalswap >> 10,
24741 +                               (si.totalswap - si.freeswap) >> 10, -1);
24742 +               }
24743                 return 0;
24744         }
24745  
24746 @@ -2181,6 +2193,8 @@ void si_swapinfo(struct sysinfo *val)
24747         val->freeswap = nr_swap_pages + nr_to_be_unused;
24748         val->totalswap = total_swap_pages + nr_to_be_unused;
24749         spin_unlock(&swap_lock);
24750 +       if (vx_flags(VXF_VIRT_MEM, 0))
24751 +               vx_vsi_swapinfo(val);
24752  }
24753  
24754  /*
24755 diff -NurpP --minimal linux-2.6.38-rc8/net/bridge/br_multicast.c linux-2.6.38-rc8-vs2.3.0.37-rc6/net/bridge/br_multicast.c
24756 --- linux-2.6.38-rc8/net/bridge/br_multicast.c  2011-03-10 17:09:30.000000000 +0100
24757 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/net/bridge/br_multicast.c   2011-03-10 16:51:08.000000000 +0100
24758 @@ -446,7 +446,7 @@ static struct sk_buff *br_ip6_multicast_
24759         ip6h->nexthdr = IPPROTO_HOPOPTS;
24760         ip6h->hop_limit = 1;
24761         ipv6_dev_get_saddr(dev_net(br->dev), br->dev, &ip6h->daddr, 0,
24762 -                          &ip6h->saddr);
24763 +                          &ip6h->saddr, NULL);
24764         ipv6_addr_set(&ip6h->daddr, htonl(0xff020000), 0, 0, htonl(1));
24765         ipv6_eth_mc_map(&ip6h->daddr, eth->h_dest);
24766  
24767 diff -NurpP --minimal linux-2.6.38-rc8/net/core/dev.c linux-2.6.38-rc8-vs2.3.0.37-rc6/net/core/dev.c
24768 --- linux-2.6.38-rc8/net/core/dev.c     2011-03-10 17:09:30.000000000 +0100
24769 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/net/core/dev.c      2011-03-07 16:53:28.000000000 +0100
24770 @@ -127,6 +127,7 @@
24771  #include <linux/in.h>
24772  #include <linux/jhash.h>
24773  #include <linux/random.h>
24774 +#include <linux/vs_inet.h>
24775  #include <trace/events/napi.h>
24776  #include <trace/events/net.h>
24777  #include <trace/events/skb.h>
24778 @@ -608,7 +609,8 @@ struct net_device *__dev_get_by_name(str
24779         struct hlist_head *head = dev_name_hash(net, name);
24780  
24781         hlist_for_each_entry(dev, p, head, name_hlist)
24782 -               if (!strncmp(dev->name, name, IFNAMSIZ))
24783 +               if (!strncmp(dev->name, name, IFNAMSIZ) &&
24784 +                   nx_dev_visible(current_nx_info(), dev))
24785                         return dev;
24786  
24787         return NULL;
24788 @@ -634,7 +636,8 @@ struct net_device *dev_get_by_name_rcu(s
24789         struct hlist_head *head = dev_name_hash(net, name);
24790  
24791         hlist_for_each_entry_rcu(dev, p, head, name_hlist)
24792 -               if (!strncmp(dev->name, name, IFNAMSIZ))
24793 +               if (!strncmp(dev->name, name, IFNAMSIZ) &&
24794 +                   nx_dev_visible(current_nx_info(), dev))
24795                         return dev;
24796  
24797         return NULL;
24798 @@ -685,7 +688,8 @@ struct net_device *__dev_get_by_index(st
24799         struct hlist_head *head = dev_index_hash(net, ifindex);
24800  
24801         hlist_for_each_entry(dev, p, head, index_hlist)
24802 -               if (dev->ifindex == ifindex)
24803 +               if ((dev->ifindex == ifindex) &&
24804 +                   nx_dev_visible(current_nx_info(), dev))
24805                         return dev;
24806  
24807         return NULL;
24808 @@ -710,7 +714,8 @@ struct net_device *dev_get_by_index_rcu(
24809         struct hlist_head *head = dev_index_hash(net, ifindex);
24810  
24811         hlist_for_each_entry_rcu(dev, p, head, index_hlist)
24812 -               if (dev->ifindex == ifindex)
24813 +               if ((dev->ifindex == ifindex) &&
24814 +                   nx_dev_visible(current_nx_info(), dev))
24815                         return dev;
24816  
24817         return NULL;
24818 @@ -763,7 +768,8 @@ struct net_device *dev_getbyhwaddr_rcu(s
24819  
24820         for_each_netdev_rcu(net, dev)
24821                 if (dev->type == type &&
24822 -                   !memcmp(dev->dev_addr, ha, dev->addr_len))
24823 +                   !memcmp(dev->dev_addr, ha, dev->addr_len) &&
24824 +                   nx_dev_visible(current_nx_info(), dev))
24825                         return dev;
24826  
24827         return NULL;
24828 @@ -775,9 +781,11 @@ struct net_device *__dev_getfirstbyhwtyp
24829         struct net_device *dev;
24830  
24831         ASSERT_RTNL();
24832 -       for_each_netdev(net, dev)
24833 -               if (dev->type == type)
24834 +       for_each_netdev(net, dev) {
24835 +               if ((dev->type == type) &&
24836 +                   nx_dev_visible(current_nx_info(), dev))
24837                         return dev;
24838 +       }
24839  
24840         return NULL;
24841  }
24842 @@ -895,6 +903,8 @@ static int __dev_alloc_name(struct net *
24843                                 continue;
24844                         if (i < 0 || i >= max_netdevices)
24845                                 continue;
24846 +                       if (!nx_dev_visible(current_nx_info(), d))
24847 +                               continue;
24848  
24849                         /*  avoid cases where sscanf is not exact inverse of printf */
24850                         snprintf(buf, IFNAMSIZ, name, i);
24851 @@ -3865,6 +3875,8 @@ static int dev_ifconf(struct net *net, c
24852  
24853         total = 0;
24854         for_each_netdev(net, dev) {
24855 +               if (!nx_dev_visible(current_nx_info(), dev))
24856 +                       continue;
24857                 for (i = 0; i < NPROTO; i++) {
24858                         if (gifconf_list[i]) {
24859                                 int done;
24860 @@ -3936,6 +3948,10 @@ static void dev_seq_printf_stats(struct 
24861         struct rtnl_link_stats64 temp;
24862         const struct rtnl_link_stats64 *stats = dev_get_stats(dev, &temp);
24863  
24864 +       /* device visible inside network context? */
24865 +       if (!nx_dev_visible(current_nx_info(), dev))
24866 +               return;
24867 +
24868         seq_printf(seq, "%6s: %7llu %7llu %4llu %4llu %4llu %5llu %10llu %9llu "
24869                    "%8llu %7llu %4llu %4llu %4llu %5llu %7llu %10llu\n",
24870                    dev->name, stats->rx_bytes, stats->rx_packets,
24871 diff -NurpP --minimal linux-2.6.38-rc8/net/core/rtnetlink.c linux-2.6.38-rc8-vs2.3.0.37-rc6/net/core/rtnetlink.c
24872 --- linux-2.6.38-rc8/net/core/rtnetlink.c       2011-03-10 17:09:30.000000000 +0100
24873 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/net/core/rtnetlink.c        2011-02-17 02:17:52.000000000 +0100
24874 @@ -1012,6 +1012,8 @@ static int rtnl_dump_ifinfo(struct sk_bu
24875                 hlist_for_each_entry(dev, node, head, index_hlist) {
24876                         if (idx < s_idx)
24877                                 goto cont;
24878 +                       if (!nx_dev_visible(skb->sk->sk_nx_info, dev))
24879 +                               continue;
24880                         if (rtnl_fill_ifinfo(skb, dev, RTM_NEWLINK,
24881                                              NETLINK_CB(cb->skb).pid,
24882                                              cb->nlh->nlmsg_seq, 0,
24883 @@ -1771,6 +1773,9 @@ void rtmsg_ifinfo(int type, struct net_d
24884         struct sk_buff *skb;
24885         int err = -ENOBUFS;
24886  
24887 +       if (!nx_dev_visible(current_nx_info(), dev))
24888 +               return;
24889 +
24890         skb = nlmsg_new(if_nlmsg_size(dev), GFP_KERNEL);
24891         if (skb == NULL)
24892                 goto errout;
24893 diff -NurpP --minimal linux-2.6.38-rc8/net/core/sock.c linux-2.6.38-rc8-vs2.3.0.37-rc6/net/core/sock.c
24894 --- linux-2.6.38-rc8/net/core/sock.c    2011-03-10 17:09:30.000000000 +0100
24895 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/net/core/sock.c     2011-01-29 02:01:07.000000000 +0100
24896 @@ -127,6 +127,10 @@
24897  #include <net/cls_cgroup.h>
24898  
24899  #include <linux/filter.h>
24900 +#include <linux/vs_socket.h>
24901 +#include <linux/vs_limit.h>
24902 +#include <linux/vs_context.h>
24903 +#include <linux/vs_network.h>
24904  
24905  #ifdef CONFIG_INET
24906  #include <net/tcp.h>
24907 @@ -1070,6 +1074,8 @@ static struct sock *sk_prot_alloc(struct
24908                         goto out_free_sec;
24909                 sk_tx_queue_clear(sk);
24910         }
24911 +               sock_vx_init(sk);
24912 +               sock_nx_init(sk);
24913  
24914         return sk;
24915  
24916 @@ -1169,6 +1175,11 @@ static void __sk_free(struct sock *sk)
24917                 put_cred(sk->sk_peer_cred);
24918         put_pid(sk->sk_peer_pid);
24919         put_net(sock_net(sk));
24920 +       vx_sock_dec(sk);
24921 +       clr_vx_info(&sk->sk_vx_info);
24922 +       sk->sk_xid = -1;
24923 +       clr_nx_info(&sk->sk_nx_info);
24924 +       sk->sk_nid = -1;
24925         sk_prot_free(sk->sk_prot_creator, sk);
24926  }
24927  
24928 @@ -1216,6 +1227,8 @@ struct sock *sk_clone(const struct sock 
24929  
24930                 /* SANITY */
24931                 get_net(sock_net(newsk));
24932 +               sock_vx_init(newsk);
24933 +               sock_nx_init(newsk);
24934                 sk_node_init(&newsk->sk_node);
24935                 sock_lock_init(newsk);
24936                 bh_lock_sock(newsk);
24937 @@ -1271,6 +1284,12 @@ struct sock *sk_clone(const struct sock 
24938                 smp_wmb();
24939                 atomic_set(&newsk->sk_refcnt, 2);
24940  
24941 +               set_vx_info(&newsk->sk_vx_info, sk->sk_vx_info);
24942 +               newsk->sk_xid = sk->sk_xid;
24943 +               vx_sock_inc(newsk);
24944 +               set_nx_info(&newsk->sk_nx_info, sk->sk_nx_info);
24945 +               newsk->sk_nid = sk->sk_nid;
24946 +
24947                 /*
24948                  * Increment the counter in the same struct proto as the master
24949                  * sock (sk_refcnt_debug_inc uses newsk->sk_prot->socks, that
24950 @@ -2017,6 +2036,12 @@ void sock_init_data(struct socket *sock,
24951  
24952         sk->sk_stamp = ktime_set(-1L, 0);
24953  
24954 +       set_vx_info(&sk->sk_vx_info, current_vx_info());
24955 +       sk->sk_xid = vx_current_xid();
24956 +       vx_sock_inc(sk);
24957 +       set_nx_info(&sk->sk_nx_info, current_nx_info());
24958 +       sk->sk_nid = nx_current_nid();
24959 +
24960         /*
24961          * Before updating sk_refcnt, we must commit prior changes to memory
24962          * (Documentation/RCU/rculist_nulls.txt for details)
24963 diff -NurpP --minimal linux-2.6.38-rc8/net/ipv4/af_inet.c linux-2.6.38-rc8-vs2.3.0.37-rc6/net/ipv4/af_inet.c
24964 --- linux-2.6.38-rc8/net/ipv4/af_inet.c 2011-03-10 17:09:30.000000000 +0100
24965 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/net/ipv4/af_inet.c  2011-02-17 02:17:52.000000000 +0100
24966 @@ -116,6 +116,7 @@
24967  #ifdef CONFIG_IP_MROUTE
24968  #include <linux/mroute.h>
24969  #endif
24970 +#include <linux/vs_limit.h>
24971  
24972  
24973  /* The inetsw table contains everything that inet_create needs to
24974 @@ -325,9 +326,13 @@ lookup_protocol:
24975         }
24976  
24977         err = -EPERM;
24978 +       if ((protocol == IPPROTO_ICMP) &&
24979 +               nx_capable(CAP_NET_RAW, NXC_RAW_ICMP))
24980 +               goto override;
24981 +
24982         if (sock->type == SOCK_RAW && !kern && !capable(CAP_NET_RAW))
24983                 goto out_rcu_unlock;
24984 -
24985 +override:
24986         err = -EAFNOSUPPORT;
24987         if (!inet_netns_ok(net, protocol))
24988                 goto out_rcu_unlock;
24989 @@ -451,6 +456,7 @@ int inet_bind(struct socket *sock, struc
24990         struct sockaddr_in *addr = (struct sockaddr_in *)uaddr;
24991         struct sock *sk = sock->sk;
24992         struct inet_sock *inet = inet_sk(sk);
24993 +       struct nx_v4_sock_addr nsa;
24994         unsigned short snum;
24995         int chk_addr_ret;
24996         int err;
24997 @@ -464,7 +470,11 @@ int inet_bind(struct socket *sock, struc
24998         if (addr_len < sizeof(struct sockaddr_in))
24999                 goto out;
25000  
25001 -       chk_addr_ret = inet_addr_type(sock_net(sk), addr->sin_addr.s_addr);
25002 +       err = v4_map_sock_addr(inet, addr, &nsa);
25003 +       if (err)
25004 +               goto out;
25005 +
25006 +       chk_addr_ret = inet_addr_type(sock_net(sk), nsa.saddr);
25007  
25008         /* Not specified by any standard per-se, however it breaks too
25009          * many applications when removed.  It is unfortunate since
25010 @@ -476,7 +486,7 @@ int inet_bind(struct socket *sock, struc
25011         err = -EADDRNOTAVAIL;
25012         if (!sysctl_ip_nonlocal_bind &&
25013             !(inet->freebind || inet->transparent) &&
25014 -           addr->sin_addr.s_addr != htonl(INADDR_ANY) &&
25015 +           nsa.saddr != htonl(INADDR_ANY) &&
25016             chk_addr_ret != RTN_LOCAL &&
25017             chk_addr_ret != RTN_MULTICAST &&
25018             chk_addr_ret != RTN_BROADCAST)
25019 @@ -501,7 +511,7 @@ int inet_bind(struct socket *sock, struc
25020         if (sk->sk_state != TCP_CLOSE || inet->inet_num)
25021                 goto out_release_sock;
25022  
25023 -       inet->inet_rcv_saddr = inet->inet_saddr = addr->sin_addr.s_addr;
25024 +       v4_set_sock_addr(inet, &nsa);
25025         if (chk_addr_ret == RTN_MULTICAST || chk_addr_ret == RTN_BROADCAST)
25026                 inet->inet_saddr = 0;  /* Use device */
25027  
25028 @@ -703,11 +713,13 @@ int inet_getname(struct socket *sock, st
25029                      peer == 1))
25030                         return -ENOTCONN;
25031                 sin->sin_port = inet->inet_dport;
25032 -               sin->sin_addr.s_addr = inet->inet_daddr;
25033 +               sin->sin_addr.s_addr =
25034 +                       nx_map_sock_lback(sk->sk_nx_info, inet->inet_daddr);
25035         } else {
25036                 __be32 addr = inet->inet_rcv_saddr;
25037                 if (!addr)
25038                         addr = inet->inet_saddr;
25039 +               addr = nx_map_sock_lback(sk->sk_nx_info, addr);
25040                 sin->sin_port = inet->inet_sport;
25041                 sin->sin_addr.s_addr = addr;
25042         }
25043 diff -NurpP --minimal linux-2.6.38-rc8/net/ipv4/devinet.c linux-2.6.38-rc8-vs2.3.0.37-rc6/net/ipv4/devinet.c
25044 --- linux-2.6.38-rc8/net/ipv4/devinet.c 2011-03-10 17:09:30.000000000 +0100
25045 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/net/ipv4/devinet.c  2011-03-07 16:53:28.000000000 +0100
25046 @@ -420,6 +420,7 @@ struct in_device *inetdev_by_index(struc
25047  }
25048  EXPORT_SYMBOL(inetdev_by_index);
25049  
25050 +
25051  /* Called only from RTNL semaphored context. No locks. */
25052  
25053  struct in_ifaddr *inet_ifa_byprefix(struct in_device *in_dev, __be32 prefix,
25054 @@ -660,6 +661,8 @@ int devinet_ioctl(struct net *net, unsig
25055  
25056         in_dev = __in_dev_get_rtnl(dev);
25057         if (in_dev) {
25058 +               struct nx_info *nxi = current_nx_info();
25059 +
25060                 if (tryaddrmatch) {
25061                         /* Matthias Andree */
25062                         /* compare label and address (4.4BSD style) */
25063 @@ -668,6 +671,8 @@ int devinet_ioctl(struct net *net, unsig
25064                            This is checked above. */
25065                         for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
25066                              ifap = &ifa->ifa_next) {
25067 +                               if (!nx_v4_ifa_visible(nxi, ifa))
25068 +                                       continue;
25069                                 if (!strcmp(ifr.ifr_name, ifa->ifa_label) &&
25070                                     sin_orig.sin_addr.s_addr ==
25071                                                         ifa->ifa_address) {
25072 @@ -680,9 +685,12 @@ int devinet_ioctl(struct net *net, unsig
25073                    comparing just the label */
25074                 if (!ifa) {
25075                         for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
25076 -                            ifap = &ifa->ifa_next)
25077 +                            ifap = &ifa->ifa_next) {
25078 +                               if (!nx_v4_ifa_visible(nxi, ifa))
25079 +                                       continue;
25080                                 if (!strcmp(ifr.ifr_name, ifa->ifa_label))
25081                                         break;
25082 +                       }
25083                 }
25084         }
25085  
25086 @@ -834,6 +842,8 @@ static int inet_gifconf(struct net_devic
25087                 goto out;
25088  
25089         for (ifa = in_dev->ifa_list; ifa; ifa = ifa->ifa_next) {
25090 +               if (!nx_v4_ifa_visible(current_nx_info(), ifa))
25091 +                       continue;
25092                 if (!buf) {
25093                         done += sizeof(ifr);
25094                         continue;
25095 @@ -1193,6 +1203,7 @@ static int inet_dump_ifaddr(struct sk_bu
25096         struct net_device *dev;
25097         struct in_device *in_dev;
25098         struct in_ifaddr *ifa;
25099 +       struct sock *sk = skb->sk;
25100         struct hlist_head *head;
25101         struct hlist_node *node;
25102  
25103 @@ -1215,6 +1226,8 @@ static int inet_dump_ifaddr(struct sk_bu
25104  
25105                         for (ifa = in_dev->ifa_list, ip_idx = 0; ifa;
25106                              ifa = ifa->ifa_next, ip_idx++) {
25107 +                       if (sk && !nx_v4_ifa_visible(sk->sk_nx_info, ifa))
25108 +                               continue;
25109                                 if (ip_idx < s_ip_idx)
25110                                         continue;
25111                                 if (inet_fill_ifaddr(skb, ifa,
25112 diff -NurpP --minimal linux-2.6.38-rc8/net/ipv4/fib_hash.c linux-2.6.38-rc8-vs2.3.0.37-rc6/net/ipv4/fib_hash.c
25113 --- linux-2.6.38-rc8/net/ipv4/fib_hash.c        2011-01-05 21:50:41.000000000 +0100
25114 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/net/ipv4/fib_hash.c 2011-01-29 02:01:07.000000000 +0100
25115 @@ -1080,7 +1080,7 @@ static int fib_seq_show(struct seq_file 
25116         prefix  = f->fn_key;
25117         mask    = FZ_MASK(iter->zone);
25118         flags   = fib_flag_trans(fa->fa_type, mask, fi);
25119 -       if (fi)
25120 +       if (fi && nx_dev_visible(current_nx_info(), fi->fib_dev))
25121                 seq_printf(seq,
25122                          "%s\t%08X\t%08X\t%04X\t%d\t%u\t%d\t%08X\t%d\t%u\t%u%n",
25123                          fi->fib_dev ? fi->fib_dev->name : "*", prefix,
25124 diff -NurpP --minimal linux-2.6.38-rc8/net/ipv4/inet_connection_sock.c linux-2.6.38-rc8-vs2.3.0.37-rc6/net/ipv4/inet_connection_sock.c
25125 --- linux-2.6.38-rc8/net/ipv4/inet_connection_sock.c    2011-03-10 17:09:30.000000000 +0100
25126 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/net/ipv4/inet_connection_sock.c     2011-01-29 05:17:31.000000000 +0100
25127 @@ -52,6 +52,37 @@ void inet_get_local_port_range(int *low,
25128  }
25129  EXPORT_SYMBOL(inet_get_local_port_range);
25130  
25131 +int ipv4_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2)
25132 +{
25133 +       __be32  sk1_rcv_saddr = sk_rcv_saddr(sk1),
25134 +               sk2_rcv_saddr = sk_rcv_saddr(sk2);
25135 +
25136 +       if (inet_v6_ipv6only(sk2))
25137 +               return 0;
25138 +
25139 +       if (sk1_rcv_saddr &&
25140 +           sk2_rcv_saddr &&
25141 +           sk1_rcv_saddr == sk2_rcv_saddr)
25142 +               return 1;
25143 +
25144 +       if (sk1_rcv_saddr &&
25145 +           !sk2_rcv_saddr &&
25146 +           v4_addr_in_nx_info(sk2->sk_nx_info, sk1_rcv_saddr, NXA_MASK_BIND))
25147 +               return 1;
25148 +
25149 +       if (sk2_rcv_saddr &&
25150 +           !sk1_rcv_saddr &&
25151 +           v4_addr_in_nx_info(sk1->sk_nx_info, sk2_rcv_saddr, NXA_MASK_BIND))
25152 +               return 1;
25153 +
25154 +       if (!sk1_rcv_saddr &&
25155 +           !sk2_rcv_saddr &&
25156 +           nx_v4_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info))
25157 +               return 1;
25158 +
25159 +       return 0;
25160 +}
25161 +
25162  int inet_csk_bind_conflict(const struct sock *sk,
25163                            const struct inet_bind_bucket *tb)
25164  {
25165 @@ -74,9 +105,7 @@ int inet_csk_bind_conflict(const struct 
25166                      sk->sk_bound_dev_if == sk2->sk_bound_dev_if)) {
25167                         if (!reuse || !sk2->sk_reuse ||
25168                             ((1 << sk2->sk_state) & (TCPF_LISTEN | TCPF_CLOSE))) {
25169 -                               const __be32 sk2_rcv_saddr = sk_rcv_saddr(sk2);
25170 -                               if (!sk2_rcv_saddr || !sk_rcv_saddr(sk) ||
25171 -                                   sk2_rcv_saddr == sk_rcv_saddr(sk))
25172 +                               if (ipv4_rcv_saddr_equal(sk, sk2))
25173                                         break;
25174                         }
25175                 }
25176 diff -NurpP --minimal linux-2.6.38-rc8/net/ipv4/inet_diag.c linux-2.6.38-rc8-vs2.3.0.37-rc6/net/ipv4/inet_diag.c
25177 --- linux-2.6.38-rc8/net/ipv4/inet_diag.c       2011-01-05 21:50:42.000000000 +0100
25178 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/net/ipv4/inet_diag.c        2011-01-29 02:01:07.000000000 +0100
25179 @@ -33,6 +33,8 @@
25180  #include <linux/stddef.h>
25181  
25182  #include <linux/inet_diag.h>
25183 +#include <linux/vs_network.h>
25184 +#include <linux/vs_inet.h>
25185  
25186  static const struct inet_diag_handler **inet_diag_table;
25187  
25188 @@ -119,8 +121,10 @@ static int inet_csk_diag_fill(struct soc
25189  
25190         r->id.idiag_sport = inet->inet_sport;
25191         r->id.idiag_dport = inet->inet_dport;
25192 -       r->id.idiag_src[0] = inet->inet_rcv_saddr;
25193 -       r->id.idiag_dst[0] = inet->inet_daddr;
25194 +       r->id.idiag_src[0] = nx_map_sock_lback(sk->sk_nx_info,
25195 +               inet->inet_rcv_saddr);
25196 +       r->id.idiag_dst[0] = nx_map_sock_lback(sk->sk_nx_info,
25197 +               inet->inet_daddr);
25198  
25199  #if defined(CONFIG_IPV6) || defined (CONFIG_IPV6_MODULE)
25200         if (r->idiag_family == AF_INET6) {
25201 @@ -205,8 +209,8 @@ static int inet_twsk_diag_fill(struct in
25202         r->id.idiag_cookie[1] = (u32)(((unsigned long)tw >> 31) >> 1);
25203         r->id.idiag_sport     = tw->tw_sport;
25204         r->id.idiag_dport     = tw->tw_dport;
25205 -       r->id.idiag_src[0]    = tw->tw_rcv_saddr;
25206 -       r->id.idiag_dst[0]    = tw->tw_daddr;
25207 +       r->id.idiag_src[0]    = nx_map_sock_lback(tw->tw_nx_info, tw->tw_rcv_saddr);
25208 +       r->id.idiag_dst[0]    = nx_map_sock_lback(tw->tw_nx_info, tw->tw_daddr);
25209         r->idiag_state        = tw->tw_substate;
25210         r->idiag_timer        = 3;
25211         r->idiag_expires      = DIV_ROUND_UP(tmo * 1000, HZ);
25212 @@ -263,6 +267,7 @@ static int inet_diag_get_exact(struct sk
25213         err = -EINVAL;
25214  
25215         if (req->idiag_family == AF_INET) {
25216 +               /* TODO: lback */
25217                 sk = inet_lookup(&init_net, hashinfo, req->id.idiag_dst[0],
25218                                  req->id.idiag_dport, req->id.idiag_src[0],
25219                                  req->id.idiag_sport, req->id.idiag_if);
25220 @@ -507,6 +512,7 @@ static int inet_csk_diag_dump(struct soc
25221                 } else
25222  #endif
25223                 {
25224 +                       /* TODO: lback */
25225                         entry.saddr = &inet->inet_rcv_saddr;
25226                         entry.daddr = &inet->inet_daddr;
25227                 }
25228 @@ -545,6 +551,7 @@ static int inet_twsk_diag_dump(struct in
25229                 } else
25230  #endif
25231                 {
25232 +                       /* TODO: lback */
25233                         entry.saddr = &tw->tw_rcv_saddr;
25234                         entry.daddr = &tw->tw_daddr;
25235                 }
25236 @@ -591,8 +598,8 @@ static int inet_diag_fill_req(struct sk_
25237  
25238         r->id.idiag_sport = inet->inet_sport;
25239         r->id.idiag_dport = ireq->rmt_port;
25240 -       r->id.idiag_src[0] = ireq->loc_addr;
25241 -       r->id.idiag_dst[0] = ireq->rmt_addr;
25242 +       r->id.idiag_src[0] = nx_map_sock_lback(sk->sk_nx_info, ireq->loc_addr);
25243 +       r->id.idiag_dst[0] = nx_map_sock_lback(sk->sk_nx_info, ireq->rmt_addr);
25244         r->idiag_expires = jiffies_to_msecs(tmo);
25245         r->idiag_rqueue = 0;
25246         r->idiag_wqueue = 0;
25247 @@ -663,6 +670,7 @@ static int inet_diag_dump_reqs(struct sk
25248                                 continue;
25249  
25250                         if (bc) {
25251 +                               /* TODO: lback */
25252                                 entry.saddr =
25253  #if defined(CONFIG_IPV6) || defined (CONFIG_IPV6_MODULE)
25254                                         (entry.family == AF_INET6) ?
25255 @@ -733,6 +741,8 @@ static int inet_diag_dump(struct sk_buff
25256                         sk_nulls_for_each(sk, node, &ilb->head) {
25257                                 struct inet_sock *inet = inet_sk(sk);
25258  
25259 +                               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
25260 +                                       continue;
25261                                 if (num < s_num) {
25262                                         num++;
25263                                         continue;
25264 @@ -799,6 +809,8 @@ skip_listen_ht:
25265                 sk_nulls_for_each(sk, node, &head->chain) {
25266                         struct inet_sock *inet = inet_sk(sk);
25267  
25268 +                       if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
25269 +                               continue;
25270                         if (num < s_num)
25271                                 goto next_normal;
25272                         if (!(r->idiag_states & (1 << sk->sk_state)))
25273 @@ -823,6 +835,8 @@ next_normal:
25274                         inet_twsk_for_each(tw, node,
25275                                     &head->twchain) {
25276  
25277 +                               if (!nx_check(tw->tw_nid, VS_WATCH_P | VS_IDENT))
25278 +                                       continue;
25279                                 if (num < s_num)
25280                                         goto next_dying;
25281                                 if (r->id.idiag_sport != tw->tw_sport &&
25282 diff -NurpP --minimal linux-2.6.38-rc8/net/ipv4/inet_hashtables.c linux-2.6.38-rc8-vs2.3.0.37-rc6/net/ipv4/inet_hashtables.c
25283 --- linux-2.6.38-rc8/net/ipv4/inet_hashtables.c 2011-01-05 21:50:42.000000000 +0100
25284 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/net/ipv4/inet_hashtables.c  2011-01-29 02:01:07.000000000 +0100
25285 @@ -21,6 +21,7 @@
25286  
25287  #include <net/inet_connection_sock.h>
25288  #include <net/inet_hashtables.h>
25289 +#include <net/route.h>
25290  #include <net/ip.h>
25291  
25292  /*
25293 @@ -155,6 +156,11 @@ static inline int compute_score(struct s
25294                         if (rcv_saddr != daddr)
25295                                 return -1;
25296                         score += 2;
25297 +               } else {
25298 +                       /* block non nx_info ips */
25299 +                       if (!v4_addr_in_nx_info(sk->sk_nx_info,
25300 +                               daddr, NXA_MASK_BIND))
25301 +                               return -1;
25302                 }
25303                 if (sk->sk_bound_dev_if) {
25304                         if (sk->sk_bound_dev_if != dif)
25305 @@ -172,7 +178,6 @@ static inline int compute_score(struct s
25306   * wildcarded during the search since they can never be otherwise.
25307   */
25308  
25309 -
25310  struct sock *__inet_lookup_listener(struct net *net,
25311                                     struct inet_hashinfo *hashinfo,
25312                                     const __be32 daddr, const unsigned short hnum,
25313 @@ -195,6 +200,7 @@ begin:
25314                         hiscore = score;
25315                 }
25316         }
25317 +
25318         /*
25319          * if the nulls value we got at the end of this lookup is
25320          * not the expected one, we must restart lookup.
25321 diff -NurpP --minimal linux-2.6.38-rc8/net/ipv4/netfilter/nf_nat_helper.c linux-2.6.38-rc8-vs2.3.0.37-rc6/net/ipv4/netfilter/nf_nat_helper.c
25322 --- linux-2.6.38-rc8/net/ipv4/netfilter/nf_nat_helper.c 2011-01-05 21:50:42.000000000 +0100
25323 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/net/ipv4/netfilter/nf_nat_helper.c  2011-01-29 02:01:07.000000000 +0100
25324 @@ -20,6 +20,7 @@
25325  #include <net/route.h>
25326  
25327  #include <linux/netfilter_ipv4.h>
25328 +#include <net/route.h>
25329  #include <net/netfilter/nf_conntrack.h>
25330  #include <net/netfilter/nf_conntrack_helper.h>
25331  #include <net/netfilter/nf_conntrack_ecache.h>
25332 diff -NurpP --minimal linux-2.6.38-rc8/net/ipv4/netfilter.c linux-2.6.38-rc8-vs2.3.0.37-rc6/net/ipv4/netfilter.c
25333 --- linux-2.6.38-rc8/net/ipv4/netfilter.c       2011-03-10 17:09:30.000000000 +0100
25334 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/net/ipv4/netfilter.c        2011-01-29 02:01:07.000000000 +0100
25335 @@ -5,7 +5,7 @@
25336  #include <linux/ip.h>
25337  #include <linux/skbuff.h>
25338  #include <linux/gfp.h>
25339 -#include <net/route.h>
25340 +// #include <net/route.h>
25341  #include <net/xfrm.h>
25342  #include <net/ip.h>
25343  #include <net/netfilter/nf_queue.h>
25344 diff -NurpP --minimal linux-2.6.38-rc8/net/ipv4/raw.c linux-2.6.38-rc8-vs2.3.0.37-rc6/net/ipv4/raw.c
25345 --- linux-2.6.38-rc8/net/ipv4/raw.c     2011-03-10 17:09:30.000000000 +0100
25346 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/net/ipv4/raw.c      2011-02-17 02:17:52.000000000 +0100
25347 @@ -117,7 +117,7 @@ static struct sock *__raw_v4_lookup(stru
25348  
25349                 if (net_eq(sock_net(sk), net) && inet->inet_num == num  &&
25350                     !(inet->inet_daddr && inet->inet_daddr != raddr)    &&
25351 -                   !(inet->inet_rcv_saddr && inet->inet_rcv_saddr != laddr) &&
25352 +                   v4_sock_addr_match(sk->sk_nx_info, inet, laddr)     &&
25353                     !(sk->sk_bound_dev_if && sk->sk_bound_dev_if != dif))
25354                         goto found; /* gotcha */
25355         }
25356 @@ -384,6 +384,12 @@ static int raw_send_hdrinc(struct sock *
25357                 icmp_out_count(net, ((struct icmphdr *)
25358                         skb_transport_header(skb))->type);
25359  
25360 +       err = -EPERM;
25361 +       if (!nx_check(0, VS_ADMIN) && !capable(CAP_NET_RAW) &&
25362 +               sk->sk_nx_info &&
25363 +               !v4_addr_in_nx_info(sk->sk_nx_info, iph->saddr, NXA_MASK_BIND))
25364 +               goto error_free;
25365 +
25366         err = NF_HOOK(NFPROTO_IPV4, NF_INET_LOCAL_OUT, skb, NULL,
25367                       rt->dst.dev, dst_output);
25368         if (err > 0)
25369 @@ -563,6 +569,13 @@ static int raw_sendmsg(struct kiocb *ioc
25370                 }
25371  
25372                 security_sk_classify_flow(sk, &fl);
25373 +               if (sk->sk_nx_info) {
25374 +                       err = ip_v4_find_src(sock_net(sk),
25375 +                               sk->sk_nx_info, &rt, &fl);
25376 +
25377 +                       if (err)
25378 +                               goto done;
25379 +               }
25380                 err = ip_route_output_flow(sock_net(sk), &rt, &fl, sk, 1);
25381         }
25382         if (err)
25383 @@ -635,17 +648,19 @@ static int raw_bind(struct sock *sk, str
25384  {
25385         struct inet_sock *inet = inet_sk(sk);
25386         struct sockaddr_in *addr = (struct sockaddr_in *) uaddr;
25387 +       struct nx_v4_sock_addr nsa = { 0 };
25388         int ret = -EINVAL;
25389         int chk_addr_ret;
25390  
25391         if (sk->sk_state != TCP_CLOSE || addr_len < sizeof(struct sockaddr_in))
25392                 goto out;
25393 -       chk_addr_ret = inet_addr_type(sock_net(sk), addr->sin_addr.s_addr);
25394 +       v4_map_sock_addr(inet, addr, &nsa);
25395 +       chk_addr_ret = inet_addr_type(sock_net(sk), nsa.saddr);
25396         ret = -EADDRNOTAVAIL;
25397 -       if (addr->sin_addr.s_addr && chk_addr_ret != RTN_LOCAL &&
25398 +       if (nsa.saddr && chk_addr_ret != RTN_LOCAL &&
25399             chk_addr_ret != RTN_MULTICAST && chk_addr_ret != RTN_BROADCAST)
25400                 goto out;
25401 -       inet->inet_rcv_saddr = inet->inet_saddr = addr->sin_addr.s_addr;
25402 +       v4_set_sock_addr(inet, &nsa);
25403         if (chk_addr_ret == RTN_MULTICAST || chk_addr_ret == RTN_BROADCAST)
25404                 inet->inet_saddr = 0;  /* Use device */
25405         sk_dst_reset(sk);
25406 @@ -697,7 +712,8 @@ static int raw_recvmsg(struct kiocb *ioc
25407         /* Copy the address. */
25408         if (sin) {
25409                 sin->sin_family = AF_INET;
25410 -               sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
25411 +               sin->sin_addr.s_addr =
25412 +                       nx_map_sock_lback(sk->sk_nx_info, ip_hdr(skb)->saddr);
25413                 sin->sin_port = 0;
25414                 memset(&sin->sin_zero, 0, sizeof(sin->sin_zero));
25415         }
25416 @@ -893,7 +909,8 @@ static struct sock *raw_get_first(struct
25417                 struct hlist_node *node;
25418  
25419                 sk_for_each(sk, node, &state->h->ht[state->bucket])
25420 -                       if (sock_net(sk) == seq_file_net(seq))
25421 +                       if ((sock_net(sk) == seq_file_net(seq)) &&
25422 +                               nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
25423                                 goto found;
25424         }
25425         sk = NULL;
25426 @@ -909,7 +926,8 @@ static struct sock *raw_get_next(struct 
25427                 sk = sk_next(sk);
25428  try_again:
25429                 ;
25430 -       } while (sk && sock_net(sk) != seq_file_net(seq));
25431 +       } while (sk && ((sock_net(sk) != seq_file_net(seq)) ||
25432 +               !nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT)));
25433  
25434         if (!sk && ++state->bucket < RAW_HTABLE_SIZE) {
25435                 sk = sk_head(&state->h->ht[state->bucket]);
25436 @@ -968,7 +986,10 @@ static void raw_sock_seq_show(struct seq
25437  
25438         seq_printf(seq, "%4d: %08X:%04X %08X:%04X"
25439                 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %lu %d %p %d\n",
25440 -               i, src, srcp, dest, destp, sp->sk_state,
25441 +               i,
25442 +               nx_map_sock_lback(current_nx_info(), src), srcp,
25443 +               nx_map_sock_lback(current_nx_info(), dest), destp,
25444 +               sp->sk_state,
25445                 sk_wmem_alloc_get(sp),
25446                 sk_rmem_alloc_get(sp),
25447                 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
25448 diff -NurpP --minimal linux-2.6.38-rc8/net/ipv4/tcp.c linux-2.6.38-rc8-vs2.3.0.37-rc6/net/ipv4/tcp.c
25449 --- linux-2.6.38-rc8/net/ipv4/tcp.c     2011-03-10 17:09:30.000000000 +0100
25450 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/net/ipv4/tcp.c      2011-01-29 02:01:07.000000000 +0100
25451 @@ -266,6 +266,7 @@
25452  #include <linux/crypto.h>
25453  #include <linux/time.h>
25454  #include <linux/slab.h>
25455 +#include <linux/in.h>
25456  
25457  #include <net/icmp.h>
25458  #include <net/tcp.h>
25459 diff -NurpP --minimal linux-2.6.38-rc8/net/ipv4/tcp_ipv4.c linux-2.6.38-rc8-vs2.3.0.37-rc6/net/ipv4/tcp_ipv4.c
25460 --- linux-2.6.38-rc8/net/ipv4/tcp_ipv4.c        2011-03-10 17:09:30.000000000 +0100
25461 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/net/ipv4/tcp_ipv4.c 2011-02-02 22:20:27.000000000 +0100
25462 @@ -1988,6 +1988,12 @@ static void *listening_get_next(struct s
25463                 req = req->dl_next;
25464                 while (1) {
25465                         while (req) {
25466 +                               vxdprintk(VXD_CBIT(net, 6),
25467 +                                       "sk,req: %p [#%d] (from %d)", req->sk,
25468 +                                       (req->sk)?req->sk->sk_nid:0, nx_current_nid());
25469 +                               if (req->sk &&
25470 +                                       !nx_check(req->sk->sk_nid, VS_WATCH_P | VS_IDENT))
25471 +                                       continue;
25472                                 if (req->rsk_ops->family == st->family) {
25473                                         cur = req;
25474                                         goto out;
25475 @@ -2012,6 +2018,10 @@ get_req:
25476         }
25477  get_sk:
25478         sk_nulls_for_each_from(sk, node) {
25479 +               vxdprintk(VXD_CBIT(net, 6), "sk: %p [#%d] (from %d)",
25480 +                       sk, sk->sk_nid, nx_current_nid());
25481 +               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
25482 +                       continue;
25483                 if (!net_eq(sock_net(sk), net))
25484                         continue;
25485                 if (sk->sk_family == st->family) {
25486 @@ -2088,6 +2098,11 @@ static void *established_get_first(struc
25487  
25488                 spin_lock_bh(lock);
25489                 sk_nulls_for_each(sk, node, &tcp_hashinfo.ehash[st->bucket].chain) {
25490 +                       vxdprintk(VXD_CBIT(net, 6),
25491 +                               "sk,egf: %p [#%d] (from %d)",
25492 +                               sk, sk->sk_nid, nx_current_nid());
25493 +                       if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
25494 +                               continue;
25495                         if (sk->sk_family != st->family ||
25496                             !net_eq(sock_net(sk), net)) {
25497                                 continue;
25498 @@ -2098,6 +2113,11 @@ static void *established_get_first(struc
25499                 st->state = TCP_SEQ_STATE_TIME_WAIT;
25500                 inet_twsk_for_each(tw, node,
25501                                    &tcp_hashinfo.ehash[st->bucket].twchain) {
25502 +                       vxdprintk(VXD_CBIT(net, 6),
25503 +                               "tw: %p [#%d] (from %d)",
25504 +                               tw, tw->tw_nid, nx_current_nid());
25505 +                       if (!nx_check(tw->tw_nid, VS_WATCH_P | VS_IDENT))
25506 +                               continue;
25507                         if (tw->tw_family != st->family ||
25508                             !net_eq(twsk_net(tw), net)) {
25509                                 continue;
25510 @@ -2127,7 +2147,9 @@ static void *established_get_next(struct
25511                 tw = cur;
25512                 tw = tw_next(tw);
25513  get_tw:
25514 -               while (tw && (tw->tw_family != st->family || !net_eq(twsk_net(tw), net))) {
25515 +               while (tw && (tw->tw_family != st->family ||
25516 +                       !net_eq(twsk_net(tw), net) ||
25517 +                       !nx_check(tw->tw_nid, VS_WATCH_P | VS_IDENT))) {
25518                         tw = tw_next(tw);
25519                 }
25520                 if (tw) {
25521 @@ -2151,6 +2173,11 @@ get_tw:
25522                 sk = sk_nulls_next(sk);
25523  
25524         sk_nulls_for_each_from(sk, node) {
25525 +               vxdprintk(VXD_CBIT(net, 6),
25526 +                       "sk,egn: %p [#%d] (from %d)",
25527 +                       sk, sk->sk_nid, nx_current_nid());
25528 +               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
25529 +                       continue;
25530                 if (sk->sk_family == st->family && net_eq(sock_net(sk), net))
25531                         goto found;
25532         }
25533 @@ -2360,9 +2387,9 @@ static void get_openreq4(struct sock *sk
25534         seq_printf(f, "%4d: %08X:%04X %08X:%04X"
25535                 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %u %d %p%n",
25536                 i,
25537 -               ireq->loc_addr,
25538 +               nx_map_sock_lback(current_nx_info(), ireq->loc_addr),
25539                 ntohs(inet_sk(sk)->inet_sport),
25540 -               ireq->rmt_addr,
25541 +               nx_map_sock_lback(current_nx_info(), ireq->rmt_addr),
25542                 ntohs(ireq->rmt_port),
25543                 TCP_SYN_RECV,
25544                 0, 0, /* could print option size, but that is af dependent. */
25545 @@ -2414,7 +2441,10 @@ static void get_tcp4_sock(struct sock *s
25546  
25547         seq_printf(f, "%4d: %08X:%04X %08X:%04X %02X %08X:%08X %02X:%08lX "
25548                         "%08X %5d %8d %lu %d %p %lu %lu %u %u %d%n",
25549 -               i, src, srcp, dest, destp, sk->sk_state,
25550 +               i,
25551 +               nx_map_sock_lback(current_nx_info(), src), srcp,
25552 +               nx_map_sock_lback(current_nx_info(), dest), destp,
25553 +               sk->sk_state,
25554                 tp->write_seq - tp->snd_una,
25555                 rx_queue,
25556                 timer_active,
25557 @@ -2449,7 +2479,10 @@ static void get_timewait4_sock(struct in
25558  
25559         seq_printf(f, "%4d: %08X:%04X %08X:%04X"
25560                 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %d %d %p%n",
25561 -               i, src, srcp, dest, destp, tw->tw_substate, 0, 0,
25562 +               i,
25563 +               nx_map_sock_lback(current_nx_info(), src), srcp,
25564 +               nx_map_sock_lback(current_nx_info(), dest), destp,
25565 +               tw->tw_substate, 0, 0,
25566                 3, jiffies_to_clock_t(ttd), 0, 0, 0, 0,
25567                 atomic_read(&tw->tw_refcnt), tw, len);
25568  }
25569 diff -NurpP --minimal linux-2.6.38-rc8/net/ipv4/tcp_minisocks.c linux-2.6.38-rc8-vs2.3.0.37-rc6/net/ipv4/tcp_minisocks.c
25570 --- linux-2.6.38-rc8/net/ipv4/tcp_minisocks.c   2011-03-10 17:09:30.000000000 +0100
25571 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/net/ipv4/tcp_minisocks.c    2011-01-29 02:01:07.000000000 +0100
25572 @@ -23,6 +23,9 @@
25573  #include <linux/slab.h>
25574  #include <linux/sysctl.h>
25575  #include <linux/workqueue.h>
25576 +#include <linux/vs_limit.h>
25577 +#include <linux/vs_socket.h>
25578 +#include <linux/vs_context.h>
25579  #include <net/tcp.h>
25580  #include <net/inet_common.h>
25581  #include <net/xfrm.h>
25582 @@ -335,6 +338,11 @@ void tcp_time_wait(struct sock *sk, int 
25583                 tcptw->tw_ts_recent     = tp->rx_opt.ts_recent;
25584                 tcptw->tw_ts_recent_stamp = tp->rx_opt.ts_recent_stamp;
25585  
25586 +               tw->tw_xid              = sk->sk_xid;
25587 +               tw->tw_vx_info          = NULL;
25588 +               tw->tw_nid              = sk->sk_nid;
25589 +               tw->tw_nx_info          = NULL;
25590 +
25591  #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
25592                 if (tw->tw_family == PF_INET6) {
25593                         struct ipv6_pinfo *np = inet6_sk(sk);
25594 diff -NurpP --minimal linux-2.6.38-rc8/net/ipv4/udp.c linux-2.6.38-rc8-vs2.3.0.37-rc6/net/ipv4/udp.c
25595 --- linux-2.6.38-rc8/net/ipv4/udp.c     2011-03-10 17:09:30.000000000 +0100
25596 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/net/ipv4/udp.c      2011-01-29 02:01:07.000000000 +0100
25597 @@ -296,14 +296,7 @@ fail:
25598  }
25599  EXPORT_SYMBOL(udp_lib_get_port);
25600  
25601 -static int ipv4_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2)
25602 -{
25603 -       struct inet_sock *inet1 = inet_sk(sk1), *inet2 = inet_sk(sk2);
25604 -
25605 -       return  (!ipv6_only_sock(sk2)  &&
25606 -                (!inet1->inet_rcv_saddr || !inet2->inet_rcv_saddr ||
25607 -                  inet1->inet_rcv_saddr == inet2->inet_rcv_saddr));
25608 -}
25609 +extern int ipv4_rcv_saddr_equal(const struct sock *, const struct sock *);
25610  
25611  static unsigned int udp4_portaddr_hash(struct net *net, __be32 saddr,
25612                                        unsigned int port)
25613 @@ -338,6 +331,11 @@ static inline int compute_score(struct s
25614                         if (inet->inet_rcv_saddr != daddr)
25615                                 return -1;
25616                         score += 2;
25617 +               } else {
25618 +                       /* block non nx_info ips */
25619 +                       if (!v4_addr_in_nx_info(sk->sk_nx_info,
25620 +                               daddr, NXA_MASK_BIND))
25621 +                               return -1;
25622                 }
25623                 if (inet->inet_daddr) {
25624                         if (inet->inet_daddr != saddr)
25625 @@ -441,6 +439,7 @@ exact_match:
25626         return result;
25627  }
25628  
25629 +
25630  /* UDP is nearly always wildcards out the wazoo, it makes no sense to try
25631   * harder than this. -DaveM
25632   */
25633 @@ -486,6 +485,11 @@ begin:
25634         sk_nulls_for_each_rcu(sk, node, &hslot->head) {
25635                 score = compute_score(sk, net, saddr, hnum, sport,
25636                                       daddr, dport, dif);
25637 +               /* FIXME: disabled?
25638 +               if (score == 9) {
25639 +                       result = sk;
25640 +                       break;
25641 +               } else */
25642                 if (score > badness) {
25643                         result = sk;
25644                         badness = score;
25645 @@ -499,6 +503,7 @@ begin:
25646         if (get_nulls_value(node) != slot)
25647                 goto begin;
25648  
25649 +
25650         if (result) {
25651                 if (unlikely(!atomic_inc_not_zero_hint(&result->sk_refcnt, 2)))
25652                         result = NULL;
25653 @@ -508,6 +513,7 @@ begin:
25654                         goto begin;
25655                 }
25656         }
25657 +
25658         rcu_read_unlock();
25659         return result;
25660  }
25661 @@ -550,8 +556,7 @@ static inline struct sock *udp_v4_mcast_
25662                     udp_sk(s)->udp_port_hash != hnum ||
25663                     (inet->inet_daddr && inet->inet_daddr != rmt_addr) ||
25664                     (inet->inet_dport != rmt_port && inet->inet_dport) ||
25665 -                   (inet->inet_rcv_saddr &&
25666 -                    inet->inet_rcv_saddr != loc_addr) ||
25667 +                   !v4_sock_addr_match(sk->sk_nx_info, inet, loc_addr) ||
25668                     ipv6_only_sock(s) ||
25669                     (s->sk_bound_dev_if && s->sk_bound_dev_if != dif))
25670                         continue;
25671 @@ -898,8 +903,13 @@ int udp_sendmsg(struct kiocb *iocb, stru
25672                                     .fl_ip_sport = inet->inet_sport,
25673                                     .fl_ip_dport = dport };
25674                 struct net *net = sock_net(sk);
25675 +               struct nx_info *nxi = sk->sk_nx_info;
25676  
25677                 security_sk_classify_flow(sk, &fl);
25678 +               err = ip_v4_find_src(net, nxi, &rt, &fl);
25679 +               if (err)
25680 +                       goto out;
25681 +
25682                 err = ip_route_output_flow(net, &rt, &fl, sk, 1);
25683                 if (err) {
25684                         if (err == -ENETUNREACH)
25685 @@ -1181,7 +1191,8 @@ try_again:
25686         if (sin) {
25687                 sin->sin_family = AF_INET;
25688                 sin->sin_port = udp_hdr(skb)->source;
25689 -               sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
25690 +               sin->sin_addr.s_addr = nx_map_sock_lback(
25691 +                       skb->sk->sk_nx_info, ip_hdr(skb)->saddr);
25692                 memset(sin->sin_zero, 0, sizeof(sin->sin_zero));
25693         }
25694         if (inet->cmsg_flags)
25695 @@ -1922,6 +1933,8 @@ static struct sock *udp_get_first(struct
25696                 sk_nulls_for_each(sk, node, &hslot->head) {
25697                         if (!net_eq(sock_net(sk), net))
25698                                 continue;
25699 +                       if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
25700 +                               continue;
25701                         if (sk->sk_family == state->family)
25702                                 goto found;
25703                 }
25704 @@ -1939,7 +1952,9 @@ static struct sock *udp_get_next(struct 
25705  
25706         do {
25707                 sk = sk_nulls_next(sk);
25708 -       } while (sk && (!net_eq(sock_net(sk), net) || sk->sk_family != state->family));
25709 +       } while (sk && (!net_eq(sock_net(sk), net) ||
25710 +               sk->sk_family != state->family ||
25711 +               !nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT)));
25712  
25713         if (!sk) {
25714                 if (state->bucket <= state->udp_table->mask)
25715 @@ -2046,7 +2061,10 @@ static void udp4_format_sock(struct sock
25716  
25717         seq_printf(f, "%5d: %08X:%04X %08X:%04X"
25718                 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %lu %d %p %d%n",
25719 -               bucket, src, srcp, dest, destp, sp->sk_state,
25720 +               bucket,
25721 +               nx_map_sock_lback(current_nx_info(), src), srcp,
25722 +               nx_map_sock_lback(current_nx_info(), dest), destp,
25723 +               sp->sk_state,
25724                 sk_wmem_alloc_get(sp),
25725                 sk_rmem_alloc_get(sp),
25726                 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
25727 diff -NurpP --minimal linux-2.6.38-rc8/net/ipv6/Kconfig linux-2.6.38-rc8-vs2.3.0.37-rc6/net/ipv6/Kconfig
25728 --- linux-2.6.38-rc8/net/ipv6/Kconfig   2010-08-02 16:52:59.000000000 +0200
25729 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/net/ipv6/Kconfig    2011-01-29 02:01:07.000000000 +0100
25730 @@ -4,8 +4,8 @@
25731  
25732  #   IPv6 as module will cause a CRASH if you try to unload it
25733  menuconfig IPV6
25734 -       tristate "The IPv6 protocol"
25735 -       default m
25736 +       bool "The IPv6 protocol"
25737 +       default n
25738         ---help---
25739           This is complemental support for the IP version 6.
25740           You will still be able to do traditional IPv4 networking as well.
25741 diff -NurpP --minimal linux-2.6.38-rc8/net/ipv6/addrconf.c linux-2.6.38-rc8-vs2.3.0.37-rc6/net/ipv6/addrconf.c
25742 --- linux-2.6.38-rc8/net/ipv6/addrconf.c        2011-03-10 17:09:30.000000000 +0100
25743 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/net/ipv6/addrconf.c 2011-02-02 22:20:27.000000000 +0100
25744 @@ -87,6 +87,8 @@
25745  
25746  #include <linux/proc_fs.h>
25747  #include <linux/seq_file.h>
25748 +#include <linux/vs_network.h>
25749 +#include <linux/vs_inet6.h>
25750  
25751  /* Set to 3 to get tracing... */
25752  #define ACONF_DEBUG 2
25753 @@ -1121,7 +1123,7 @@ out:
25754  
25755  int ipv6_dev_get_saddr(struct net *net, struct net_device *dst_dev,
25756                        const struct in6_addr *daddr, unsigned int prefs,
25757 -                      struct in6_addr *saddr)
25758 +                      struct in6_addr *saddr, struct nx_info *nxi)
25759  {
25760         struct ipv6_saddr_score scores[2],
25761                                 *score = &scores[0], *hiscore = &scores[1];
25762 @@ -1193,6 +1195,8 @@ int ipv6_dev_get_saddr(struct net *net, 
25763                                                dev->name);
25764                                 continue;
25765                         }
25766 +                       if (!v6_addr_in_nx_info(nxi, &score->ifa->addr, -1))
25767 +                               continue;
25768  
25769                         score->rule = -1;
25770                         bitmap_zero(score->scorebits, IPV6_SADDR_RULE_MAX);
25771 @@ -3061,7 +3065,10 @@ static void if6_seq_stop(struct seq_file
25772  static int if6_seq_show(struct seq_file *seq, void *v)
25773  {
25774         struct inet6_ifaddr *ifp = (struct inet6_ifaddr *)v;
25775 -       seq_printf(seq, "%pi6 %02x %02x %02x %02x %8s\n",
25776 +
25777 +       if (nx_check(0, VS_ADMIN|VS_WATCH) ||
25778 +           v6_addr_in_nx_info(current_nx_info(), &ifp->addr, -1))
25779 +               seq_printf(seq, "%pi6 %02x %02x %02x %02x %8s\n",
25780                    &ifp->addr,
25781                    ifp->idev->dev->ifindex,
25782                    ifp->prefix_len,
25783 @@ -3567,6 +3574,11 @@ static int in6_dump_addrs(struct inet6_d
25784         struct ifacaddr6 *ifaca;
25785         int err = 1;
25786         int ip_idx = *p_ip_idx;
25787 +       struct nx_info *nxi = skb->sk ? skb->sk->sk_nx_info : NULL;
25788 +
25789 +       /* disable ipv6 on non v6 guests */
25790 +       if (nxi && !nx_info_has_v6(nxi))
25791 +               return skb->len;
25792  
25793         read_lock_bh(&idev->lock);
25794         switch (type) {
25795 @@ -3577,6 +3589,8 @@ static int in6_dump_addrs(struct inet6_d
25796                 list_for_each_entry(ifa, &idev->addr_list, if_list) {
25797                         if (++ip_idx < s_ip_idx)
25798                                 continue;
25799 +                               if (!v6_addr_in_nx_info(nxi, &ifa->addr, -1))
25800 +                                       continue;
25801                         err = inet6_fill_ifaddr(skb, ifa,
25802                                                 NETLINK_CB(cb->skb).pid,
25803                                                 cb->nlh->nlmsg_seq,
25804 @@ -3593,6 +3607,8 @@ static int in6_dump_addrs(struct inet6_d
25805                      ifmca = ifmca->next, ip_idx++) {
25806                         if (ip_idx < s_ip_idx)
25807                                 continue;
25808 +                               if (!v6_addr_in_nx_info(nxi, &ifmca->mca_addr, -1))
25809 +                                       continue;
25810                         err = inet6_fill_ifmcaddr(skb, ifmca,
25811                                                   NETLINK_CB(cb->skb).pid,
25812                                                   cb->nlh->nlmsg_seq,
25813 @@ -3608,6 +3624,8 @@ static int in6_dump_addrs(struct inet6_d
25814                      ifaca = ifaca->aca_next, ip_idx++) {
25815                         if (ip_idx < s_ip_idx)
25816                                 continue;
25817 +                               if (!v6_addr_in_nx_info(nxi, &ifaca->aca_addr, -1))
25818 +                                       continue;
25819                         err = inet6_fill_ifacaddr(skb, ifaca,
25820                                                   NETLINK_CB(cb->skb).pid,
25821                                                   cb->nlh->nlmsg_seq,
25822 @@ -3993,6 +4011,11 @@ static int inet6_dump_ifinfo(struct sk_b
25823         struct inet6_dev *idev;
25824         struct hlist_head *head;
25825         struct hlist_node *node;
25826 +       struct nx_info *nxi = skb->sk ? skb->sk->sk_nx_info : NULL;
25827 +
25828 +       /* FIXME: maybe disable ipv6 on non v6 guests?
25829 +       if (skb->sk && skb->sk->sk_vx_info)
25830 +               return skb->len; */
25831  
25832         s_h = cb->args[0];
25833         s_idx = cb->args[1];
25834 @@ -4004,6 +4027,8 @@ static int inet6_dump_ifinfo(struct sk_b
25835                 hlist_for_each_entry_rcu(dev, node, head, index_hlist) {
25836                         if (idx < s_idx)
25837                                 goto cont;
25838 +                       if (!v6_dev_in_nx_info(dev, nxi))
25839 +                               goto cont;
25840                         idev = __in6_dev_get(dev);
25841                         if (!idev)
25842                                 goto cont;
25843 diff -NurpP --minimal linux-2.6.38-rc8/net/ipv6/af_inet6.c linux-2.6.38-rc8-vs2.3.0.37-rc6/net/ipv6/af_inet6.c
25844 --- linux-2.6.38-rc8/net/ipv6/af_inet6.c        2011-03-10 17:09:30.000000000 +0100
25845 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/net/ipv6/af_inet6.c 2011-01-29 02:01:07.000000000 +0100
25846 @@ -42,6 +42,8 @@
25847  #include <linux/netdevice.h>
25848  #include <linux/icmpv6.h>
25849  #include <linux/netfilter_ipv6.h>
25850 +#include <linux/vs_inet.h>
25851 +#include <linux/vs_inet6.h>
25852  
25853  #include <net/ip.h>
25854  #include <net/ipv6.h>
25855 @@ -160,9 +162,12 @@ lookup_protocol:
25856         }
25857  
25858         err = -EPERM;
25859 +       if ((protocol == IPPROTO_ICMPV6) &&
25860 +               nx_capable(CAP_NET_RAW, NXC_RAW_ICMP))
25861 +               goto override;
25862         if (sock->type == SOCK_RAW && !kern && !capable(CAP_NET_RAW))
25863                 goto out_rcu_unlock;
25864 -
25865 +override:
25866         sock->ops = answer->ops;
25867         answer_prot = answer->prot;
25868         answer_no_check = answer->no_check;
25869 @@ -261,6 +266,7 @@ int inet6_bind(struct socket *sock, stru
25870         struct inet_sock *inet = inet_sk(sk);
25871         struct ipv6_pinfo *np = inet6_sk(sk);
25872         struct net *net = sock_net(sk);
25873 +       struct nx_v6_sock_addr nsa;
25874         __be32 v4addr = 0;
25875         unsigned short snum;
25876         int addr_type = 0;
25877 @@ -272,6 +278,11 @@ int inet6_bind(struct socket *sock, stru
25878  
25879         if (addr_len < SIN6_LEN_RFC2133)
25880                 return -EINVAL;
25881 +
25882 +       err = v6_map_sock_addr(inet, addr, &nsa);
25883 +       if (err)
25884 +               return err;
25885 +
25886         addr_type = ipv6_addr_type(&addr->sin6_addr);
25887         if ((addr_type & IPV6_ADDR_MULTICAST) && sock->type == SOCK_STREAM)
25888                 return -EINVAL;
25889 @@ -303,6 +314,7 @@ int inet6_bind(struct socket *sock, stru
25890                 /* Reproduce AF_INET checks to make the bindings consistent */
25891                 v4addr = addr->sin6_addr.s6_addr32[3];
25892                 chk_addr_ret = inet_addr_type(net, v4addr);
25893 +
25894                 if (!sysctl_ip_nonlocal_bind &&
25895                     !(inet->freebind || inet->transparent) &&
25896                     v4addr != htonl(INADDR_ANY) &&
25897 @@ -312,6 +324,10 @@ int inet6_bind(struct socket *sock, stru
25898                         err = -EADDRNOTAVAIL;
25899                         goto out;
25900                 }
25901 +               if (!v4_addr_in_nx_info(sk->sk_nx_info, v4addr, NXA_MASK_BIND)) {
25902 +                       err = -EADDRNOTAVAIL;
25903 +                       goto out;
25904 +               }
25905         } else {
25906                 if (addr_type != IPV6_ADDR_ANY) {
25907                         struct net_device *dev = NULL;
25908 @@ -338,6 +354,11 @@ int inet6_bind(struct socket *sock, stru
25909                                 }
25910                         }
25911  
25912 +                       if (!v6_addr_in_nx_info(sk->sk_nx_info, &addr->sin6_addr, -1)) {
25913 +                               err = -EADDRNOTAVAIL;
25914 +                               goto out;
25915 +                       }
25916 +
25917                         /* ipv4 addr of the socket is invalid.  Only the
25918                          * unspecified and mapped address have a v4 equivalent.
25919                          */
25920 @@ -354,6 +375,9 @@ int inet6_bind(struct socket *sock, stru
25921                 }
25922         }
25923  
25924 +       /* what's that for? */
25925 +       v6_set_sock_addr(inet, &nsa);
25926 +
25927         inet->inet_rcv_saddr = v4addr;
25928         inet->inet_saddr = v4addr;
25929  
25930 @@ -455,9 +479,11 @@ int inet6_getname(struct socket *sock, s
25931                         return -ENOTCONN;
25932                 sin->sin6_port = inet->inet_dport;
25933                 ipv6_addr_copy(&sin->sin6_addr, &np->daddr);
25934 +               /* FIXME: remap lback? */
25935                 if (np->sndflow)
25936                         sin->sin6_flowinfo = np->flow_label;
25937         } else {
25938 +               /* FIXME: remap lback? */
25939                 if (ipv6_addr_any(&np->rcv_saddr))
25940                         ipv6_addr_copy(&sin->sin6_addr, &np->saddr);
25941                 else
25942 diff -NurpP --minimal linux-2.6.38-rc8/net/ipv6/fib6_rules.c linux-2.6.38-rc8-vs2.3.0.37-rc6/net/ipv6/fib6_rules.c
25943 --- linux-2.6.38-rc8/net/ipv6/fib6_rules.c      2011-01-05 21:50:42.000000000 +0100
25944 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/net/ipv6/fib6_rules.c       2011-01-29 02:01:07.000000000 +0100
25945 @@ -88,7 +88,7 @@ static int fib6_rule_action(struct fib_r
25946                                                ip6_dst_idev(&rt->dst)->dev,
25947                                                &flp->fl6_dst,
25948                                                rt6_flags2srcprefs(flags),
25949 -                                              &saddr))
25950 +                                              &saddr, NULL))
25951                                 goto again;
25952                         if (!ipv6_prefix_equal(&saddr, &r->src.addr,
25953                                                r->src.plen))
25954 diff -NurpP --minimal linux-2.6.38-rc8/net/ipv6/inet6_hashtables.c linux-2.6.38-rc8-vs2.3.0.37-rc6/net/ipv6/inet6_hashtables.c
25955 --- linux-2.6.38-rc8/net/ipv6/inet6_hashtables.c        2010-02-25 11:52:10.000000000 +0100
25956 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/net/ipv6/inet6_hashtables.c 2011-01-29 02:01:07.000000000 +0100
25957 @@ -16,6 +16,7 @@
25958  
25959  #include <linux/module.h>
25960  #include <linux/random.h>
25961 +#include <linux/vs_inet6.h>
25962  
25963  #include <net/inet_connection_sock.h>
25964  #include <net/inet_hashtables.h>
25965 @@ -82,7 +83,6 @@ struct sock *__inet6_lookup_established(
25966         unsigned int slot = hash & hashinfo->ehash_mask;
25967         struct inet_ehash_bucket *head = &hashinfo->ehash[slot];
25968  
25969 -
25970         rcu_read_lock();
25971  begin:
25972         sk_nulls_for_each_rcu(sk, node, &head->chain) {
25973 @@ -94,7 +94,7 @@ begin:
25974                                 sock_put(sk);
25975                                 goto begin;
25976                         }
25977 -               goto out;
25978 +                       goto out;
25979                 }
25980         }
25981         if (get_nulls_value(node) != slot)
25982 @@ -140,6 +140,9 @@ static int inline compute_score(struct s
25983                         if (!ipv6_addr_equal(&np->rcv_saddr, daddr))
25984                                 return -1;
25985                         score++;
25986 +               } else {
25987 +                       if (!v6_addr_in_nx_info(sk->sk_nx_info, daddr, -1))
25988 +                               return -1;
25989                 }
25990                 if (sk->sk_bound_dev_if) {
25991                         if (sk->sk_bound_dev_if != dif)
25992 diff -NurpP --minimal linux-2.6.38-rc8/net/ipv6/ip6_output.c linux-2.6.38-rc8-vs2.3.0.37-rc6/net/ipv6/ip6_output.c
25993 --- linux-2.6.38-rc8/net/ipv6/ip6_output.c      2011-03-10 17:09:30.000000000 +0100
25994 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/net/ipv6/ip6_output.c       2011-01-29 02:01:07.000000000 +0100
25995 @@ -933,7 +933,7 @@ static int ip6_dst_lookup_tail(struct so
25996                 err = ipv6_dev_get_saddr(net, ip6_dst_idev(*dst)->dev,
25997                                          &fl->fl6_dst,
25998                                          sk ? inet6_sk(sk)->srcprefs : 0,
25999 -                                        &fl->fl6_src);
26000 +                                        &fl->fl6_src, sk->sk_nx_info);
26001                 if (err)
26002                         goto out_err_release;
26003         }
26004 diff -NurpP --minimal linux-2.6.38-rc8/net/ipv6/ndisc.c linux-2.6.38-rc8-vs2.3.0.37-rc6/net/ipv6/ndisc.c
26005 --- linux-2.6.38-rc8/net/ipv6/ndisc.c   2011-03-10 17:09:30.000000000 +0100
26006 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/net/ipv6/ndisc.c    2011-03-10 16:52:54.000000000 +0100
26007 @@ -595,7 +595,7 @@ static void ndisc_send_na(struct net_dev
26008         } else {
26009                 if (ipv6_dev_get_saddr(dev_net(dev), dev, daddr,
26010                                        inet6_sk(dev_net(dev)->ipv6.ndisc_sk)->srcprefs,
26011 -                                      &tmpaddr))
26012 +                                      &tmpaddr, NULL))
26013                         return;
26014                 src_addr = &tmpaddr;
26015         }
26016 diff -NurpP --minimal linux-2.6.38-rc8/net/ipv6/raw.c linux-2.6.38-rc8-vs2.3.0.37-rc6/net/ipv6/raw.c
26017 --- linux-2.6.38-rc8/net/ipv6/raw.c     2011-03-10 17:09:30.000000000 +0100
26018 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/net/ipv6/raw.c      2011-02-17 02:17:52.000000000 +0100
26019 @@ -30,6 +30,7 @@
26020  #include <linux/icmpv6.h>
26021  #include <linux/netfilter.h>
26022  #include <linux/netfilter_ipv6.h>
26023 +#include <linux/vs_inet6.h>
26024  #include <linux/skbuff.h>
26025  #include <linux/compat.h>
26026  #include <asm/uaccess.h>
26027 @@ -284,6 +285,13 @@ static int rawv6_bind(struct sock *sk, s
26028                                 goto out_unlock;
26029                 }
26030  
26031 +               if (!v6_addr_in_nx_info(sk->sk_nx_info, &addr->sin6_addr, -1)) {
26032 +                       err = -EADDRNOTAVAIL;
26033 +                       if (dev)
26034 +                               dev_put(dev);
26035 +                       goto out;
26036 +               }
26037 +
26038                 /* ipv4 addr of the socket is invalid.  Only the
26039                  * unspecified and mapped address have a v4 equivalent.
26040                  */
26041 diff -NurpP --minimal linux-2.6.38-rc8/net/ipv6/route.c linux-2.6.38-rc8-vs2.3.0.37-rc6/net/ipv6/route.c
26042 --- linux-2.6.38-rc8/net/ipv6/route.c   2011-03-10 17:09:30.000000000 +0100
26043 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/net/ipv6/route.c    2011-03-10 17:21:19.000000000 +0100
26044 @@ -2289,7 +2289,8 @@ static int rt6_fill_node(struct net *net
26045                 struct inet6_dev *idev = ip6_dst_idev(&rt->dst);
26046                 struct in6_addr saddr_buf;
26047                 if (ipv6_dev_get_saddr(net, idev ? idev->dev : NULL,
26048 -                                      dst, 0, &saddr_buf) == 0)
26049 +                       dst, 0, &saddr_buf,
26050 +                       (skb->sk ? skb->sk->sk_nx_info : NULL)) == 0)
26051                         NLA_PUT(skb, RTA_PREFSRC, 16, &saddr_buf);
26052         }
26053  
26054 diff -NurpP --minimal linux-2.6.38-rc8/net/ipv6/tcp_ipv6.c linux-2.6.38-rc8-vs2.3.0.37-rc6/net/ipv6/tcp_ipv6.c
26055 --- linux-2.6.38-rc8/net/ipv6/tcp_ipv6.c        2011-03-10 17:09:30.000000000 +0100
26056 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/net/ipv6/tcp_ipv6.c 2011-01-29 02:01:07.000000000 +0100
26057 @@ -69,6 +69,7 @@
26058  
26059  #include <linux/crypto.h>
26060  #include <linux/scatterlist.h>
26061 +#include <linux/vs_inet6.h>
26062  
26063  static void    tcp_v6_send_reset(struct sock *sk, struct sk_buff *skb);
26064  static void    tcp_v6_reqsk_send_ack(struct sock *sk, struct sk_buff *skb,
26065 @@ -161,8 +162,15 @@ static int tcp_v6_connect(struct sock *s
26066          *      connect() to INADDR_ANY means loopback (BSD'ism).
26067          */
26068  
26069 -       if(ipv6_addr_any(&usin->sin6_addr))
26070 -               usin->sin6_addr.s6_addr[15] = 0x1;
26071 +       if(ipv6_addr_any(&usin->sin6_addr)) {
26072 +               struct nx_info *nxi =  sk->sk_nx_info;
26073 +
26074 +               if (nxi && nx_info_has_v6(nxi))
26075 +                       /* FIXME: remap lback? */
26076 +                       usin->sin6_addr = nxi->v6.ip;
26077 +               else
26078 +                       usin->sin6_addr.s6_addr[15] = 0x1;
26079 +       }
26080  
26081         addr_type = ipv6_addr_type(&usin->sin6_addr);
26082  
26083 diff -NurpP --minimal linux-2.6.38-rc8/net/ipv6/udp.c linux-2.6.38-rc8-vs2.3.0.37-rc6/net/ipv6/udp.c
26084 --- linux-2.6.38-rc8/net/ipv6/udp.c     2011-03-10 17:09:30.000000000 +0100
26085 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/net/ipv6/udp.c      2011-01-29 05:23:17.000000000 +0100
26086 @@ -45,41 +45,67 @@
26087  #include <net/tcp_states.h>
26088  #include <net/ip6_checksum.h>
26089  #include <net/xfrm.h>
26090 +#include <linux/vs_inet6.h>
26091  
26092  #include <linux/proc_fs.h>
26093  #include <linux/seq_file.h>
26094  #include "udp_impl.h"
26095  
26096 -int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
26097 +int ipv6_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2)
26098  {
26099 -       const struct in6_addr *sk_rcv_saddr6 = &inet6_sk(sk)->rcv_saddr;
26100 +       const struct in6_addr *sk1_rcv_saddr6 = &inet6_sk(sk1)->rcv_saddr;
26101         const struct in6_addr *sk2_rcv_saddr6 = inet6_rcv_saddr(sk2);
26102 -       __be32 sk1_rcv_saddr = sk_rcv_saddr(sk);
26103 +       __be32 sk1_rcv_saddr = sk_rcv_saddr(sk1);
26104         __be32 sk2_rcv_saddr = sk_rcv_saddr(sk2);
26105 -       int sk_ipv6only = ipv6_only_sock(sk);
26106 +       int sk1_ipv6only = ipv6_only_sock(sk1);
26107         int sk2_ipv6only = inet_v6_ipv6only(sk2);
26108 -       int addr_type = ipv6_addr_type(sk_rcv_saddr6);
26109 +       int addr_type = ipv6_addr_type(sk1_rcv_saddr6);
26110         int addr_type2 = sk2_rcv_saddr6 ? ipv6_addr_type(sk2_rcv_saddr6) : IPV6_ADDR_MAPPED;
26111  
26112         /* if both are mapped, treat as IPv4 */
26113 -       if (addr_type == IPV6_ADDR_MAPPED && addr_type2 == IPV6_ADDR_MAPPED)
26114 -               return (!sk2_ipv6only &&
26115 +       if (addr_type == IPV6_ADDR_MAPPED && addr_type2 == IPV6_ADDR_MAPPED) {
26116 +               if (!sk2_ipv6only &&
26117                         (!sk1_rcv_saddr || !sk2_rcv_saddr ||
26118 -                         sk1_rcv_saddr == sk2_rcv_saddr));
26119 +                         sk1_rcv_saddr == sk2_rcv_saddr))
26120 +                       goto vs_v4;
26121 +               else
26122 +                       return 0;
26123 +       }
26124  
26125         if (addr_type2 == IPV6_ADDR_ANY &&
26126             !(sk2_ipv6only && addr_type == IPV6_ADDR_MAPPED))
26127 -               return 1;
26128 +               goto vs;
26129  
26130         if (addr_type == IPV6_ADDR_ANY &&
26131 -           !(sk_ipv6only && addr_type2 == IPV6_ADDR_MAPPED))
26132 -               return 1;
26133 +           !(sk1_ipv6only && addr_type2 == IPV6_ADDR_MAPPED))
26134 +               goto vs;
26135  
26136         if (sk2_rcv_saddr6 &&
26137 -           ipv6_addr_equal(sk_rcv_saddr6, sk2_rcv_saddr6))
26138 -               return 1;
26139 +           ipv6_addr_equal(sk1_rcv_saddr6, sk2_rcv_saddr6))
26140 +               goto vs;
26141  
26142         return 0;
26143 +
26144 +vs_v4:
26145 +       if (!sk1_rcv_saddr && !sk2_rcv_saddr)
26146 +               return nx_v4_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info);
26147 +       if (!sk2_rcv_saddr)
26148 +               return v4_addr_in_nx_info(sk1->sk_nx_info, sk2_rcv_saddr, -1);
26149 +       if (!sk1_rcv_saddr)
26150 +               return v4_addr_in_nx_info(sk2->sk_nx_info, sk1_rcv_saddr, -1);
26151 +       return 1;
26152 +vs:
26153 +       if (addr_type2 == IPV6_ADDR_ANY && addr_type == IPV6_ADDR_ANY)
26154 +               return nx_v6_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info);
26155 +       else if (addr_type2 == IPV6_ADDR_ANY)
26156 +               return v6_addr_in_nx_info(sk2->sk_nx_info, sk1_rcv_saddr6, -1);
26157 +       else if (addr_type == IPV6_ADDR_ANY) {
26158 +               if (addr_type2 == IPV6_ADDR_MAPPED)
26159 +                       return nx_v4_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info);
26160 +               else
26161 +                       return v6_addr_in_nx_info(sk1->sk_nx_info, sk2_rcv_saddr6, -1);
26162 +       }
26163 +       return 1;
26164  }
26165  
26166  static unsigned int udp6_portaddr_hash(struct net *net,
26167 @@ -143,6 +169,10 @@ static inline int compute_score(struct s
26168                         if (!ipv6_addr_equal(&np->rcv_saddr, daddr))
26169                                 return -1;
26170                         score++;
26171 +               } else {
26172 +                       /* block non nx_info ips */
26173 +                       if (!v6_addr_in_nx_info(sk->sk_nx_info, daddr, -1))
26174 +                               return -1;
26175                 }
26176                 if (!ipv6_addr_any(&np->daddr)) {
26177                         if (!ipv6_addr_equal(&np->daddr, saddr))
26178 diff -NurpP --minimal linux-2.6.38-rc8/net/ipv6/xfrm6_policy.c linux-2.6.38-rc8-vs2.3.0.37-rc6/net/ipv6/xfrm6_policy.c
26179 --- linux-2.6.38-rc8/net/ipv6/xfrm6_policy.c    2011-03-10 17:09:30.000000000 +0100
26180 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/net/ipv6/xfrm6_policy.c     2011-02-02 22:20:27.000000000 +0100
26181 @@ -62,7 +62,7 @@ static int xfrm6_get_saddr(struct net *n
26182         dev = ip6_dst_idev(dst)->dev;
26183         ipv6_dev_get_saddr(dev_net(dev), dev,
26184                            (struct in6_addr *)&daddr->a6, 0,
26185 -                          (struct in6_addr *)&saddr->a6);
26186 +                          (struct in6_addr *)&saddr->a6, NULL);
26187         dst_release(dst);
26188         return 0;
26189  }
26190 diff -NurpP --minimal linux-2.6.38-rc8/net/netfilter/ipvs/ip_vs_xmit.c linux-2.6.38-rc8-vs2.3.0.37-rc6/net/netfilter/ipvs/ip_vs_xmit.c
26191 --- linux-2.6.38-rc8/net/netfilter/ipvs/ip_vs_xmit.c    2011-03-10 17:09:31.000000000 +0100
26192 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/net/netfilter/ipvs/ip_vs_xmit.c     2011-01-29 02:01:07.000000000 +0100
26193 @@ -213,7 +213,7 @@ __ip_vs_route_output_v6(struct net *net,
26194                 return dst;
26195         if (ipv6_addr_any(&fl.fl6_src) &&
26196             ipv6_dev_get_saddr(net, ip6_dst_idev(dst)->dev,
26197 -                              &fl.fl6_dst, 0, &fl.fl6_src) < 0)
26198 +                              &fl.fl6_dst, 0, &fl.fl6_src, NULL) < 0)
26199                 goto out_err;
26200         if (do_xfrm && xfrm_lookup(net, &dst, &fl, NULL, 0) < 0)
26201                 goto out_err;
26202 diff -NurpP --minimal linux-2.6.38-rc8/net/netlink/af_netlink.c linux-2.6.38-rc8-vs2.3.0.37-rc6/net/netlink/af_netlink.c
26203 --- linux-2.6.38-rc8/net/netlink/af_netlink.c   2011-03-10 17:09:31.000000000 +0100
26204 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/net/netlink/af_netlink.c    2011-03-10 17:21:19.000000000 +0100
26205 @@ -55,6 +55,9 @@
26206  #include <linux/types.h>
26207  #include <linux/audit.h>
26208  #include <linux/mutex.h>
26209 +#include <linux/vs_context.h>
26210 +#include <linux/vs_network.h>
26211 +#include <linux/vs_limit.h>
26212  
26213  #include <net/net_namespace.h>
26214  #include <net/sock.h>
26215 @@ -1922,6 +1925,8 @@ static struct sock *netlink_seq_socket_i
26216                         sk_for_each(s, node, &hash->table[j]) {
26217                                 if (sock_net(s) != seq_file_net(seq))
26218                                         continue;
26219 +                               if (!nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT))
26220 +                                       continue;
26221                                 if (off == pos) {
26222                                         iter->link = i;
26223                                         iter->hash_idx = j;
26224 @@ -1956,7 +1961,8 @@ static void *netlink_seq_next(struct seq
26225         s = v;
26226         do {
26227                 s = sk_next(s);
26228 -       } while (s && sock_net(s) != seq_file_net(seq));
26229 +       } while (s && (sock_net(s) != seq_file_net(seq) ||
26230 +               !nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT)));
26231         if (s)
26232                 return s;
26233  
26234 @@ -1968,7 +1974,8 @@ static void *netlink_seq_next(struct seq
26235  
26236                 for (; j <= hash->mask; j++) {
26237                         s = sk_head(&hash->table[j]);
26238 -                       while (s && sock_net(s) != seq_file_net(seq))
26239 +                       while (s && (sock_net(s) != seq_file_net(seq) ||
26240 +                               !nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT)))
26241                                 s = sk_next(s);
26242                         if (s) {
26243                                 iter->link = i;
26244 diff -NurpP --minimal linux-2.6.38-rc8/net/sctp/ipv6.c linux-2.6.38-rc8-vs2.3.0.37-rc6/net/sctp/ipv6.c
26245 --- linux-2.6.38-rc8/net/sctp/ipv6.c    2011-01-05 21:50:45.000000000 +0100
26246 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/net/sctp/ipv6.c     2011-01-29 02:01:07.000000000 +0100
26247 @@ -306,7 +306,8 @@ static void sctp_v6_get_saddr(struct sct
26248                                    dst ? ip6_dst_idev(dst)->dev : NULL,
26249                                    &daddr->v6.sin6_addr,
26250                                    inet6_sk(&sk->inet.sk)->srcprefs,
26251 -                                  &saddr->v6.sin6_addr);
26252 +                                  &saddr->v6.sin6_addr,
26253 +                                  asoc->base.sk->sk_nx_info);
26254                 SCTP_DEBUG_PRINTK("saddr from ipv6_get_saddr: %pI6\n",
26255                                   &saddr->v6.sin6_addr);
26256                 return;
26257 diff -NurpP --minimal linux-2.6.38-rc8/net/socket.c linux-2.6.38-rc8-vs2.3.0.37-rc6/net/socket.c
26258 --- linux-2.6.38-rc8/net/socket.c       2011-03-10 17:09:31.000000000 +0100
26259 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/net/socket.c        2011-01-29 02:01:07.000000000 +0100
26260 @@ -98,6 +98,10 @@
26261  
26262  #include <net/sock.h>
26263  #include <linux/netfilter.h>
26264 +#include <linux/vs_base.h>
26265 +#include <linux/vs_socket.h>
26266 +#include <linux/vs_inet.h>
26267 +#include <linux/vs_inet6.h>
26268  
26269  #include <linux/if_tun.h>
26270  #include <linux/ipv6_route.h>
26271 @@ -551,7 +555,7 @@ static inline int __sock_sendmsg(struct 
26272                                  struct msghdr *msg, size_t size)
26273  {
26274         struct sock_iocb *si = kiocb_to_siocb(iocb);
26275 -       int err;
26276 +       int err, len;
26277  
26278         sock_update_classid(sock->sk);
26279  
26280 @@ -564,7 +568,22 @@ static inline int __sock_sendmsg(struct 
26281         if (err)
26282                 return err;
26283  
26284 -       return sock->ops->sendmsg(iocb, sock, msg, size);
26285 +       len = sock->ops->sendmsg(iocb, sock, msg, size);
26286 +       if (sock->sk) {
26287 +               if (len == size)
26288 +                       vx_sock_send(sock->sk, size);
26289 +               else
26290 +                       vx_sock_fail(sock->sk, size);
26291 +       }
26292 +       vxdprintk(VXD_CBIT(net, 7),
26293 +               "__sock_sendmsg: %p[%p,%p,%p;%d/%d]:%d/%d",
26294 +               sock, sock->sk,
26295 +               (sock->sk)?sock->sk->sk_nx_info:0,
26296 +               (sock->sk)?sock->sk->sk_vx_info:0,
26297 +               (sock->sk)?sock->sk->sk_xid:0,
26298 +               (sock->sk)?sock->sk->sk_nid:0,
26299 +               (unsigned int)size, len);
26300 +       return len;
26301  }
26302  
26303  int sock_sendmsg(struct socket *sock, struct msghdr *msg, size_t size)
26304 @@ -682,6 +701,7 @@ static inline int __sock_recvmsg_nosec(s
26305                                        struct msghdr *msg, size_t size, int flags)
26306  {
26307         struct sock_iocb *si = kiocb_to_siocb(iocb);
26308 +       int len;
26309  
26310         sock_update_classid(sock->sk);
26311  
26312 @@ -691,7 +711,18 @@ static inline int __sock_recvmsg_nosec(s
26313         si->size = size;
26314         si->flags = flags;
26315  
26316 -       return sock->ops->recvmsg(iocb, sock, msg, size, flags);
26317 +       len = sock->ops->recvmsg(iocb, sock, msg, size, flags);
26318 +       if ((len >= 0) && sock->sk)
26319 +               vx_sock_recv(sock->sk, len);
26320 +       vxdprintk(VXD_CBIT(net, 7),
26321 +               "__sock_recvmsg: %p[%p,%p,%p;%d/%d]:%d/%d",
26322 +               sock, sock->sk,
26323 +               (sock->sk)?sock->sk->sk_nx_info:0,
26324 +               (sock->sk)?sock->sk->sk_vx_info:0,
26325 +               (sock->sk)?sock->sk->sk_xid:0,
26326 +               (sock->sk)?sock->sk->sk_nid:0,
26327 +               (unsigned int)size, len);
26328 +       return len;
26329  }
26330  
26331  static inline int __sock_recvmsg(struct kiocb *iocb, struct socket *sock,
26332 @@ -1175,6 +1206,13 @@ int __sock_create(struct net *net, int f
26333         if (type < 0 || type >= SOCK_MAX)
26334                 return -EINVAL;
26335  
26336 +       if (!nx_check(0, VS_ADMIN)) {
26337 +               if (family == PF_INET && !current_nx_info_has_v4())
26338 +                       return -EAFNOSUPPORT;
26339 +               if (family == PF_INET6 && !current_nx_info_has_v6())
26340 +                       return -EAFNOSUPPORT;
26341 +       }
26342 +
26343         /* Compatibility.
26344  
26345            This uglymoron is moved from INET layer to here to avoid
26346 @@ -1310,6 +1348,7 @@ SYSCALL_DEFINE3(socket, int, family, int
26347         if (retval < 0)
26348                 goto out;
26349  
26350 +       set_bit(SOCK_USER_SOCKET, &sock->flags);
26351         retval = sock_map_fd(sock, flags & (O_CLOEXEC | O_NONBLOCK));
26352         if (retval < 0)
26353                 goto out_release;
26354 @@ -1351,10 +1390,12 @@ SYSCALL_DEFINE4(socketpair, int, family,
26355         err = sock_create(family, type, protocol, &sock1);
26356         if (err < 0)
26357                 goto out;
26358 +       set_bit(SOCK_USER_SOCKET, &sock1->flags);
26359  
26360         err = sock_create(family, type, protocol, &sock2);
26361         if (err < 0)
26362                 goto out_release_1;
26363 +       set_bit(SOCK_USER_SOCKET, &sock2->flags);
26364  
26365         err = sock1->ops->socketpair(sock1, sock2);
26366         if (err < 0)
26367 diff -NurpP --minimal linux-2.6.38-rc8/net/sunrpc/auth.c linux-2.6.38-rc8-vs2.3.0.37-rc6/net/sunrpc/auth.c
26368 --- linux-2.6.38-rc8/net/sunrpc/auth.c  2011-03-10 17:09:31.000000000 +0100
26369 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/net/sunrpc/auth.c   2011-01-29 02:01:07.000000000 +0100
26370 @@ -14,6 +14,7 @@
26371  #include <linux/hash.h>
26372  #include <linux/sunrpc/clnt.h>
26373  #include <linux/spinlock.h>
26374 +#include <linux/vs_tag.h>
26375  
26376  #ifdef RPC_DEBUG
26377  # define RPCDBG_FACILITY       RPCDBG_AUTH
26378 @@ -425,6 +426,7 @@ rpcauth_lookupcred(struct rpc_auth *auth
26379         memset(&acred, 0, sizeof(acred));
26380         acred.uid = cred->fsuid;
26381         acred.gid = cred->fsgid;
26382 +       acred.tag = dx_current_tag();
26383         acred.group_info = get_group_info(((struct cred *)cred)->group_info);
26384  
26385         ret = auth->au_ops->lookup_cred(auth, &acred, flags);
26386 @@ -465,6 +467,7 @@ rpcauth_bind_root_cred(struct rpc_task *
26387         struct auth_cred acred = {
26388                 .uid = 0,
26389                 .gid = 0,
26390 +               .tag = dx_current_tag(),
26391         };
26392  
26393         dprintk("RPC: %5u looking up %s cred\n",
26394 diff -NurpP --minimal linux-2.6.38-rc8/net/sunrpc/auth_unix.c linux-2.6.38-rc8-vs2.3.0.37-rc6/net/sunrpc/auth_unix.c
26395 --- linux-2.6.38-rc8/net/sunrpc/auth_unix.c     2010-10-21 13:08:01.000000000 +0200
26396 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/net/sunrpc/auth_unix.c      2011-01-29 02:01:07.000000000 +0100
26397 @@ -12,12 +12,14 @@
26398  #include <linux/module.h>
26399  #include <linux/sunrpc/clnt.h>
26400  #include <linux/sunrpc/auth.h>
26401 +#include <linux/vs_tag.h>
26402  
26403  #define NFS_NGROUPS    16
26404  
26405  struct unx_cred {
26406         struct rpc_cred         uc_base;
26407         gid_t                   uc_gid;
26408 +       tag_t                   uc_tag;
26409         gid_t                   uc_gids[NFS_NGROUPS];
26410  };
26411  #define uc_uid                 uc_base.cr_uid
26412 @@ -78,6 +80,7 @@ unx_create_cred(struct rpc_auth *auth, s
26413                 groups = NFS_NGROUPS;
26414  
26415         cred->uc_gid = acred->gid;
26416 +       cred->uc_tag = acred->tag;
26417         for (i = 0; i < groups; i++)
26418                 cred->uc_gids[i] = GROUP_AT(acred->group_info, i);
26419         if (i < NFS_NGROUPS)
26420 @@ -119,7 +122,9 @@ unx_match(struct auth_cred *acred, struc
26421         unsigned int i;
26422  
26423  
26424 -       if (cred->uc_uid != acred->uid || cred->uc_gid != acred->gid)
26425 +       if (cred->uc_uid != acred->uid ||
26426 +               cred->uc_gid != acred->gid ||
26427 +               cred->uc_tag != acred->tag)
26428                 return 0;
26429  
26430         if (acred->group_info != NULL)
26431 @@ -142,7 +147,7 @@ unx_marshal(struct rpc_task *task, __be3
26432         struct rpc_clnt *clnt = task->tk_client;
26433         struct unx_cred *cred = container_of(task->tk_rqstp->rq_cred, struct unx_cred, uc_base);
26434         __be32          *base, *hold;
26435 -       int             i;
26436 +       int             i, tag;
26437  
26438         *p++ = htonl(RPC_AUTH_UNIX);
26439         base = p++;
26440 @@ -152,9 +157,12 @@ unx_marshal(struct rpc_task *task, __be3
26441          * Copy the UTS nodename captured when the client was created.
26442          */
26443         p = xdr_encode_array(p, clnt->cl_nodename, clnt->cl_nodelen);
26444 +       tag = task->tk_client->cl_tag;
26445  
26446 -       *p++ = htonl((u32) cred->uc_uid);
26447 -       *p++ = htonl((u32) cred->uc_gid);
26448 +       *p++ = htonl((u32) TAGINO_UID(tag,
26449 +               cred->uc_uid, cred->uc_tag));
26450 +       *p++ = htonl((u32) TAGINO_GID(tag,
26451 +               cred->uc_gid, cred->uc_tag));
26452         hold = p++;
26453         for (i = 0; i < 16 && cred->uc_gids[i] != (gid_t) NOGROUP; i++)
26454                 *p++ = htonl((u32) cred->uc_gids[i]);
26455 diff -NurpP --minimal linux-2.6.38-rc8/net/sunrpc/clnt.c linux-2.6.38-rc8-vs2.3.0.37-rc6/net/sunrpc/clnt.c
26456 --- linux-2.6.38-rc8/net/sunrpc/clnt.c  2011-03-10 17:09:31.000000000 +0100
26457 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/net/sunrpc/clnt.c   2011-01-29 02:01:07.000000000 +0100
26458 @@ -33,6 +33,7 @@
26459  #include <linux/utsname.h>
26460  #include <linux/workqueue.h>
26461  #include <linux/in6.h>
26462 +#include <linux/vs_cvirt.h>
26463  
26464  #include <linux/sunrpc/clnt.h>
26465  #include <linux/sunrpc/rpc_pipe_fs.h>
26466 @@ -359,6 +360,9 @@ struct rpc_clnt *rpc_create(struct rpc_c
26467         if (!(args->flags & RPC_CLNT_CREATE_QUIET))
26468                 clnt->cl_chatty = 1;
26469  
26470 +       /* TODO: handle RPC_CLNT_CREATE_TAGGED
26471 +       if (args->flags & RPC_CLNT_CREATE_TAGGED)
26472 +               clnt->cl_tag = 1; */
26473         return clnt;
26474  }
26475  EXPORT_SYMBOL_GPL(rpc_create);
26476 diff -NurpP --minimal linux-2.6.38-rc8/net/unix/af_unix.c linux-2.6.38-rc8-vs2.3.0.37-rc6/net/unix/af_unix.c
26477 --- linux-2.6.38-rc8/net/unix/af_unix.c 2011-03-10 17:09:31.000000000 +0100
26478 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/net/unix/af_unix.c  2011-01-29 02:01:07.000000000 +0100
26479 @@ -114,6 +114,8 @@
26480  #include <linux/mount.h>
26481  #include <net/checksum.h>
26482  #include <linux/security.h>
26483 +#include <linux/vs_context.h>
26484 +#include <linux/vs_limit.h>
26485  
26486  static struct hlist_head unix_socket_table[UNIX_HASH_SIZE + 1];
26487  static DEFINE_SPINLOCK(unix_table_lock);
26488 @@ -258,6 +260,8 @@ static struct sock *__unix_find_socket_b
26489                 if (!net_eq(sock_net(s), net))
26490                         continue;
26491  
26492 +               if (!nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT))
26493 +                       continue;
26494                 if (u->addr->len == len &&
26495                     !memcmp(u->addr->name, sunname, len))
26496                         goto found;
26497 @@ -2179,6 +2183,8 @@ static struct sock *unix_seq_idx(struct 
26498         for (s = first_unix_socket(&iter->i); s; s = next_unix_socket(&iter->i, s)) {
26499                 if (sock_net(s) != seq_file_net(seq))
26500                         continue;
26501 +               if (!nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT))
26502 +                       continue;
26503                 if (off == pos)
26504                         return s;
26505                 ++off;
26506 @@ -2203,7 +2209,8 @@ static void *unix_seq_next(struct seq_fi
26507                 sk = first_unix_socket(&iter->i);
26508         else
26509                 sk = next_unix_socket(&iter->i, sk);
26510 -       while (sk && (sock_net(sk) != seq_file_net(seq)))
26511 +       while (sk && (sock_net(sk) != seq_file_net(seq) ||
26512 +               !nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT)))
26513                 sk = next_unix_socket(&iter->i, sk);
26514         return sk;
26515  }
26516 diff -NurpP --minimal linux-2.6.38-rc8/scripts/checksyscalls.sh linux-2.6.38-rc8-vs2.3.0.37-rc6/scripts/checksyscalls.sh
26517 --- linux-2.6.38-rc8/scripts/checksyscalls.sh   2011-03-10 17:09:31.000000000 +0100
26518 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/scripts/checksyscalls.sh    2011-01-29 02:01:07.000000000 +0100
26519 @@ -193,7 +193,6 @@ cat << EOF
26520  #define __IGNORE_afs_syscall
26521  #define __IGNORE_getpmsg
26522  #define __IGNORE_putpmsg
26523 -#define __IGNORE_vserver
26524  EOF
26525  }
26526  
26527 diff -NurpP --minimal linux-2.6.38-rc8/security/commoncap.c linux-2.6.38-rc8-vs2.3.0.37-rc6/security/commoncap.c
26528 --- linux-2.6.38-rc8/security/commoncap.c       2011-01-05 21:50:47.000000000 +0100
26529 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/security/commoncap.c        2011-01-29 02:01:07.000000000 +0100
26530 @@ -27,6 +27,7 @@
26531  #include <linux/sched.h>
26532  #include <linux/prctl.h>
26533  #include <linux/securebits.h>
26534 +// #include <linux/vs_context.h>
26535  
26536  /*
26537   * If a non-root user executes a setuid-root binary in
26538 @@ -52,7 +53,7 @@ static void warn_setuid_and_fcaps_mixed(
26539  
26540  int cap_netlink_send(struct sock *sk, struct sk_buff *skb)
26541  {
26542 -       NETLINK_CB(skb).eff_cap = current_cap();
26543 +       NETLINK_CB(skb).eff_cap = vx_mbcaps(current_cap());
26544         return 0;
26545  }
26546  
26547 @@ -62,6 +63,7 @@ int cap_netlink_recv(struct sk_buff *skb
26548                 return -EPERM;
26549         return 0;
26550  }
26551 +
26552  EXPORT_SYMBOL(cap_netlink_recv);
26553  
26554  /**
26555 @@ -82,7 +84,22 @@ EXPORT_SYMBOL(cap_netlink_recv);
26556  int cap_capable(struct task_struct *tsk, const struct cred *cred, int cap,
26557                 int audit)
26558  {
26559 -       return cap_raised(cred->cap_effective, cap) ? 0 : -EPERM;
26560 +       struct vx_info *vxi = tsk->vx_info;
26561 +
26562 +#if 0
26563 +       printk("cap_capable() VXF_STATE_SETUP = %llx, raised = %x, eff = %08x:%08x\n",
26564 +               vx_info_flags(vxi, VXF_STATE_SETUP, 0),
26565 +               cap_raised(tsk->cap_effective, cap),
26566 +               tsk->cap_effective.cap[1], tsk->cap_effective.cap[0]);
26567 +#endif
26568 +
26569 +       /* special case SETUP */
26570 +       if (vx_info_flags(vxi, VXF_STATE_SETUP, 0) &&
26571 +               /* FIXME: maybe use cred instead? */
26572 +               cap_raised(tsk->cred->cap_effective, cap))
26573 +               return 0;
26574 +
26575 +       return vx_cap_raised(vxi, cred->cap_effective, cap) ? 0 : -EPERM;
26576  }
26577  
26578  /**
26579 @@ -570,7 +587,7 @@ int cap_inode_setxattr(struct dentry *de
26580  
26581         if (!strncmp(name, XATTR_SECURITY_PREFIX,
26582                      sizeof(XATTR_SECURITY_PREFIX) - 1) &&
26583 -           !capable(CAP_SYS_ADMIN))
26584 +               !vx_capable(CAP_SYS_ADMIN, VXC_FS_SECURITY))
26585                 return -EPERM;
26586         return 0;
26587  }
26588 @@ -596,7 +613,7 @@ int cap_inode_removexattr(struct dentry 
26589  
26590         if (!strncmp(name, XATTR_SECURITY_PREFIX,
26591                      sizeof(XATTR_SECURITY_PREFIX) - 1) &&
26592 -           !capable(CAP_SYS_ADMIN))
26593 +               !vx_capable(CAP_SYS_ADMIN, VXC_FS_SECURITY))
26594                 return -EPERM;
26595         return 0;
26596  }
26597 @@ -929,3 +946,4 @@ int cap_file_mmap(struct file *file, uns
26598         }
26599         return ret;
26600  }
26601 +
26602 diff -NurpP --minimal linux-2.6.38-rc8/security/selinux/hooks.c linux-2.6.38-rc8-vs2.3.0.37-rc6/security/selinux/hooks.c
26603 --- linux-2.6.38-rc8/security/selinux/hooks.c   2011-03-10 17:09:32.000000000 +0100
26604 +++ linux-2.6.38-rc8-vs2.3.0.37-rc6/security/selinux/hooks.c    2011-02-17 02:17:52.000000000 +0100
26605 @@ -64,7 +64,6 @@
26606  #include <linux/dccp.h>
26607  #include <linux/quota.h>
26608  #include <linux/un.h>          /* for Unix socket types */
26609 -#include <net/af_unix.h>       /* for Unix socket types */
26610  #include <linux/parser.h>
26611  #include <linux/nfs_mount.h>
26612  #include <net/ipv6.h>
This page took 2.174439 seconds and 4 git commands to generate.