]> git.pld-linux.org Git - packages/kernel.git/blob - kernel-vserver-2.3.patch
- updated to 2.6.38.4
[packages/kernel.git] / kernel-vserver-2.3.patch
1 diff -NurpP --minimal linux-2.6.38.3/Documentation/vserver/debug.txt linux-2.6.38.3-vs2.3.0.37-rc14/Documentation/vserver/debug.txt
2 --- linux-2.6.38.3/Documentation/vserver/debug.txt      1970-01-01 01:00:00.000000000 +0100
3 +++ linux-2.6.38.3-vs2.3.0.37-rc14/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.3/arch/alpha/Kconfig linux-2.6.38.3-vs2.3.0.37-rc14/arch/alpha/Kconfig
160 --- linux-2.6.38.3/arch/alpha/Kconfig   2011-03-15 18:06:23.000000000 +0100
161 +++ linux-2.6.38.3-vs2.3.0.37-rc14/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.3/arch/alpha/kernel/entry.S linux-2.6.38.3-vs2.3.0.37-rc14/arch/alpha/kernel/entry.S
172 --- linux-2.6.38.3/arch/alpha/kernel/entry.S    2010-10-21 13:06:45.000000000 +0200
173 +++ linux-2.6.38.3-vs2.3.0.37-rc14/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.3/arch/alpha/kernel/ptrace.c linux-2.6.38.3-vs2.3.0.37-rc14/arch/alpha/kernel/ptrace.c
207 --- linux-2.6.38.3/arch/alpha/kernel/ptrace.c   2011-01-05 21:48:40.000000000 +0100
208 +++ linux-2.6.38.3-vs2.3.0.37-rc14/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.3/arch/alpha/kernel/systbls.S linux-2.6.38.3-vs2.3.0.37-rc14/arch/alpha/kernel/systbls.S
218 --- linux-2.6.38.3/arch/alpha/kernel/systbls.S  2010-10-21 13:06:46.000000000 +0200
219 +++ linux-2.6.38.3-vs2.3.0.37-rc14/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.3/arch/alpha/kernel/traps.c linux-2.6.38.3-vs2.3.0.37-rc14/arch/alpha/kernel/traps.c
230 --- linux-2.6.38.3/arch/alpha/kernel/traps.c    2010-10-21 13:06:46.000000000 +0200
231 +++ linux-2.6.38.3-vs2.3.0.37-rc14/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.3/arch/arm/Kconfig linux-2.6.38.3-vs2.3.0.37-rc14/arch/arm/Kconfig
243 --- linux-2.6.38.3/arch/arm/Kconfig     2011-03-15 18:06:23.000000000 +0100
244 +++ linux-2.6.38.3-vs2.3.0.37-rc14/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.3/arch/arm/kernel/calls.S linux-2.6.38.3-vs2.3.0.37-rc14/arch/arm/kernel/calls.S
255 --- linux-2.6.38.3/arch/arm/kernel/calls.S      2010-10-21 13:06:46.000000000 +0200
256 +++ linux-2.6.38.3-vs2.3.0.37-rc14/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.3/arch/arm/kernel/process.c linux-2.6.38.3-vs2.3.0.37-rc14/arch/arm/kernel/process.c
267 --- linux-2.6.38.3/arch/arm/kernel/process.c    2011-03-15 18:06:25.000000000 +0100
268 +++ linux-2.6.38.3-vs2.3.0.37-rc14/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.3/arch/arm/kernel/traps.c linux-2.6.38.3-vs2.3.0.37-rc14/arch/arm/kernel/traps.c
280 --- linux-2.6.38.3/arch/arm/kernel/traps.c      2011-03-15 18:06:25.000000000 +0100
281 +++ linux-2.6.38.3-vs2.3.0.37-rc14/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.3/arch/cris/Kconfig linux-2.6.38.3-vs2.3.0.37-rc14/arch/cris/Kconfig
294 --- linux-2.6.38.3/arch/cris/Kconfig    2011-03-15 18:06:38.000000000 +0100
295 +++ linux-2.6.38.3-vs2.3.0.37-rc14/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.3/arch/frv/kernel/kernel_thread.S linux-2.6.38.3-vs2.3.0.37-rc14/arch/frv/kernel/kernel_thread.S
306 --- linux-2.6.38.3/arch/frv/kernel/kernel_thread.S      2008-12-25 00:26:37.000000000 +0100
307 +++ linux-2.6.38.3-vs2.3.0.37-rc14/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.3/arch/h8300/Kconfig linux-2.6.38.3-vs2.3.0.37-rc14/arch/h8300/Kconfig
318 --- linux-2.6.38.3/arch/h8300/Kconfig   2011-03-15 18:06:38.000000000 +0100
319 +++ linux-2.6.38.3-vs2.3.0.37-rc14/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.3/arch/ia64/Kconfig linux-2.6.38.3-vs2.3.0.37-rc14/arch/ia64/Kconfig
330 --- linux-2.6.38.3/arch/ia64/Kconfig    2011-03-15 18:06:38.000000000 +0100
331 +++ linux-2.6.38.3-vs2.3.0.37-rc14/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.3/arch/ia64/include/asm/tlb.h linux-2.6.38.3-vs2.3.0.37-rc14/arch/ia64/include/asm/tlb.h
342 --- linux-2.6.38.3/arch/ia64/include/asm/tlb.h  2010-02-25 11:51:26.000000000 +0100
343 +++ linux-2.6.38.3-vs2.3.0.37-rc14/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.3/arch/ia64/kernel/entry.S linux-2.6.38.3-vs2.3.0.37-rc14/arch/ia64/kernel/entry.S
353 --- linux-2.6.38.3/arch/ia64/kernel/entry.S     2010-10-21 13:06:52.000000000 +0200
354 +++ linux-2.6.38.3-vs2.3.0.37-rc14/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.3/arch/ia64/kernel/perfmon.c linux-2.6.38.3-vs2.3.0.37-rc14/arch/ia64/kernel/perfmon.c
365 --- linux-2.6.38.3/arch/ia64/kernel/perfmon.c   2011-03-15 18:06:39.000000000 +0100
366 +++ linux-2.6.38.3-vs2.3.0.37-rc14/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.3/arch/ia64/kernel/process.c linux-2.6.38.3-vs2.3.0.37-rc14/arch/ia64/kernel/process.c
376 --- linux-2.6.38.3/arch/ia64/kernel/process.c   2011-03-15 18:06:39.000000000 +0100
377 +++ linux-2.6.38.3-vs2.3.0.37-rc14/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.3/arch/ia64/kernel/ptrace.c linux-2.6.38.3-vs2.3.0.37-rc14/arch/ia64/kernel/ptrace.c
390 --- linux-2.6.38.3/arch/ia64/kernel/ptrace.c    2011-01-05 21:48:59.000000000 +0100
391 +++ linux-2.6.38.3-vs2.3.0.37-rc14/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.3/arch/ia64/kernel/traps.c linux-2.6.38.3-vs2.3.0.37-rc14/arch/ia64/kernel/traps.c
401 --- linux-2.6.38.3/arch/ia64/kernel/traps.c     2010-07-07 18:31:01.000000000 +0200
402 +++ linux-2.6.38.3-vs2.3.0.37-rc14/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.3/arch/ia64/mm/fault.c linux-2.6.38.3-vs2.3.0.37-rc14/arch/ia64/mm/fault.c
428 --- linux-2.6.38.3/arch/ia64/mm/fault.c 2010-08-02 16:52:04.000000000 +0200
429 +++ linux-2.6.38.3-vs2.3.0.37-rc14/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.3/arch/m32r/kernel/traps.c linux-2.6.38.3-vs2.3.0.37-rc14/arch/m32r/kernel/traps.c
439 --- linux-2.6.38.3/arch/m32r/kernel/traps.c     2009-12-03 20:01:57.000000000 +0100
440 +++ linux-2.6.38.3-vs2.3.0.37-rc14/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.3/arch/m68k/Kconfig linux-2.6.38.3-vs2.3.0.37-rc14/arch/m68k/Kconfig
454 --- linux-2.6.38.3/arch/m68k/Kconfig    2011-01-05 21:49:00.000000000 +0100
455 +++ linux-2.6.38.3-vs2.3.0.37-rc14/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.3/arch/m68k/kernel/ptrace.c linux-2.6.38.3-vs2.3.0.37-rc14/arch/m68k/kernel/ptrace.c
466 --- linux-2.6.38.3/arch/m68k/kernel/ptrace.c    2011-01-05 21:49:01.000000000 +0100
467 +++ linux-2.6.38.3-vs2.3.0.37-rc14/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.3/arch/m68k/kernel/traps.c linux-2.6.38.3-vs2.3.0.37-rc14/arch/m68k/kernel/traps.c
486 --- linux-2.6.38.3/arch/m68k/kernel/traps.c     2010-08-02 16:52:04.000000000 +0200
487 +++ linux-2.6.38.3-vs2.3.0.37-rc14/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.3/arch/m68knommu/Kconfig linux-2.6.38.3-vs2.3.0.37-rc14/arch/m68knommu/Kconfig
500 --- linux-2.6.38.3/arch/m68knommu/Kconfig       2011-03-15 18:06:41.000000000 +0100
501 +++ linux-2.6.38.3-vs2.3.0.37-rc14/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.3/arch/m68knommu/kernel/traps.c linux-2.6.38.3-vs2.3.0.37-rc14/arch/m68knommu/kernel/traps.c
512 --- linux-2.6.38.3/arch/m68knommu/kernel/traps.c        2011-01-05 21:49:01.000000000 +0100
513 +++ linux-2.6.38.3-vs2.3.0.37-rc14/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.3/arch/mips/Kconfig linux-2.6.38.3-vs2.3.0.37-rc14/arch/mips/Kconfig
527 --- linux-2.6.38.3/arch/mips/Kconfig    2011-03-15 18:06:42.000000000 +0100
528 +++ linux-2.6.38.3-vs2.3.0.37-rc14/arch/mips/Kconfig    2011-03-15 18:15:06.000000000 +0100
529 @@ -2418,6 +2418,8 @@ source "fs/Kconfig"
530  
531  source "arch/mips/Kconfig.debug"
532  
533 +source "kernel/vserver/Kconfig"
534 +
535  source "security/Kconfig"
536  
537  source "crypto/Kconfig"
538 diff -NurpP --minimal linux-2.6.38.3/arch/mips/kernel/ptrace.c linux-2.6.38.3-vs2.3.0.37-rc14/arch/mips/kernel/ptrace.c
539 --- linux-2.6.38.3/arch/mips/kernel/ptrace.c    2011-01-05 21:49:06.000000000 +0100
540 +++ linux-2.6.38.3-vs2.3.0.37-rc14/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.3/arch/mips/kernel/scall32-o32.S linux-2.6.38.3-vs2.3.0.37-rc14/arch/mips/kernel/scall32-o32.S
560 --- linux-2.6.38.3/arch/mips/kernel/scall32-o32.S       2010-10-21 13:06:54.000000000 +0200
561 +++ linux-2.6.38.3-vs2.3.0.37-rc14/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.3/arch/mips/kernel/scall64-64.S linux-2.6.38.3-vs2.3.0.37-rc14/arch/mips/kernel/scall64-64.S
572 --- linux-2.6.38.3/arch/mips/kernel/scall64-64.S        2010-10-21 13:06:54.000000000 +0200
573 +++ linux-2.6.38.3-vs2.3.0.37-rc14/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.3/arch/mips/kernel/scall64-n32.S linux-2.6.38.3-vs2.3.0.37-rc14/arch/mips/kernel/scall64-n32.S
584 --- linux-2.6.38.3/arch/mips/kernel/scall64-n32.S       2010-10-21 13:06:54.000000000 +0200
585 +++ linux-2.6.38.3-vs2.3.0.37-rc14/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.3/arch/mips/kernel/scall64-o32.S linux-2.6.38.3-vs2.3.0.37-rc14/arch/mips/kernel/scall64-o32.S
596 --- linux-2.6.38.3/arch/mips/kernel/scall64-o32.S       2010-10-21 13:06:54.000000000 +0200
597 +++ linux-2.6.38.3-vs2.3.0.37-rc14/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.3/arch/mips/kernel/traps.c linux-2.6.38.3-vs2.3.0.37-rc14/arch/mips/kernel/traps.c
608 --- linux-2.6.38.3/arch/mips/kernel/traps.c     2011-03-15 18:06:42.000000000 +0100
609 +++ linux-2.6.38.3-vs2.3.0.37-rc14/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.3/arch/parisc/Kconfig linux-2.6.38.3-vs2.3.0.37-rc14/arch/parisc/Kconfig
625 --- linux-2.6.38.3/arch/parisc/Kconfig  2011-03-15 18:06:43.000000000 +0100
626 +++ linux-2.6.38.3-vs2.3.0.37-rc14/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.3/arch/parisc/kernel/syscall_table.S linux-2.6.38.3-vs2.3.0.37-rc14/arch/parisc/kernel/syscall_table.S
637 --- linux-2.6.38.3/arch/parisc/kernel/syscall_table.S   2011-01-05 21:49:09.000000000 +0100
638 +++ linux-2.6.38.3-vs2.3.0.37-rc14/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.3/arch/parisc/kernel/traps.c linux-2.6.38.3-vs2.3.0.37-rc14/arch/parisc/kernel/traps.c
649 --- linux-2.6.38.3/arch/parisc/kernel/traps.c   2009-09-10 15:25:40.000000000 +0200
650 +++ linux-2.6.38.3-vs2.3.0.37-rc14/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.3/arch/parisc/mm/fault.c linux-2.6.38.3-vs2.3.0.37-rc14/arch/parisc/mm/fault.c
675 --- linux-2.6.38.3/arch/parisc/mm/fault.c       2010-08-02 16:52:06.000000000 +0200
676 +++ linux-2.6.38.3-vs2.3.0.37-rc14/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.3/arch/powerpc/Kconfig linux-2.6.38.3-vs2.3.0.37-rc14/arch/powerpc/Kconfig
690 --- linux-2.6.38.3/arch/powerpc/Kconfig 2011-03-15 18:06:43.000000000 +0100
691 +++ linux-2.6.38.3-vs2.3.0.37-rc14/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.3/arch/powerpc/include/asm/unistd.h linux-2.6.38.3-vs2.3.0.37-rc14/arch/powerpc/include/asm/unistd.h
702 --- linux-2.6.38.3/arch/powerpc/include/asm/unistd.h    2011-01-05 21:49:10.000000000 +0100
703 +++ linux-2.6.38.3-vs2.3.0.37-rc14/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.3/arch/powerpc/kernel/process.c linux-2.6.38.3-vs2.3.0.37-rc14/arch/powerpc/kernel/process.c
714 --- linux-2.6.38.3/arch/powerpc/kernel/process.c        2011-03-15 18:06:44.000000000 +0100
715 +++ linux-2.6.38.3-vs2.3.0.37-rc14/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.3/arch/powerpc/kernel/traps.c linux-2.6.38.3-vs2.3.0.37-rc14/arch/powerpc/kernel/traps.c
729 --- linux-2.6.38.3/arch/powerpc/kernel/traps.c  2011-03-15 18:06:44.000000000 +0100
730 +++ linux-2.6.38.3-vs2.3.0.37-rc14/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.3/arch/powerpc/kernel/vdso.c linux-2.6.38.3-vs2.3.0.37-rc14/arch/powerpc/kernel/vdso.c
744 --- linux-2.6.38.3/arch/powerpc/kernel/vdso.c   2011-01-05 21:49:11.000000000 +0100
745 +++ linux-2.6.38.3-vs2.3.0.37-rc14/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.3/arch/s390/Kconfig linux-2.6.38.3-vs2.3.0.37-rc14/arch/s390/Kconfig
755 --- linux-2.6.38.3/arch/s390/Kconfig    2011-03-15 18:06:45.000000000 +0100
756 +++ linux-2.6.38.3-vs2.3.0.37-rc14/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.3/arch/s390/include/asm/tlb.h linux-2.6.38.3-vs2.3.0.37-rc14/arch/s390/include/asm/tlb.h
767 --- linux-2.6.38.3/arch/s390/include/asm/tlb.h  2011-03-15 18:06:45.000000000 +0100
768 +++ linux-2.6.38.3-vs2.3.0.37-rc14/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.3/arch/s390/include/asm/unistd.h linux-2.6.38.3-vs2.3.0.37-rc14/arch/s390/include/asm/unistd.h
779 --- linux-2.6.38.3/arch/s390/include/asm/unistd.h       2010-10-21 13:06:58.000000000 +0200
780 +++ linux-2.6.38.3-vs2.3.0.37-rc14/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.3/arch/s390/kernel/ptrace.c linux-2.6.38.3-vs2.3.0.37-rc14/arch/s390/kernel/ptrace.c
791 --- linux-2.6.38.3/arch/s390/kernel/ptrace.c    2011-03-15 18:06:45.000000000 +0100
792 +++ linux-2.6.38.3-vs2.3.0.37-rc14/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.3/arch/s390/kernel/syscalls.S linux-2.6.38.3-vs2.3.0.37-rc14/arch/s390/kernel/syscalls.S
802 --- linux-2.6.38.3/arch/s390/kernel/syscalls.S  2010-10-21 13:06:58.000000000 +0200
803 +++ linux-2.6.38.3-vs2.3.0.37-rc14/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.3/arch/sh/Kconfig linux-2.6.38.3-vs2.3.0.37-rc14/arch/sh/Kconfig
814 --- linux-2.6.38.3/arch/sh/Kconfig      2011-03-15 18:06:46.000000000 +0100
815 +++ linux-2.6.38.3-vs2.3.0.37-rc14/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.3/arch/sh/kernel/irq.c linux-2.6.38.3-vs2.3.0.37-rc14/arch/sh/kernel/irq.c
826 --- linux-2.6.38.3/arch/sh/kernel/irq.c 2011-01-05 21:49:16.000000000 +0100
827 +++ linux-2.6.38.3-vs2.3.0.37-rc14/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.3/arch/sh/kernel/vsyscall/vsyscall.c linux-2.6.38.3-vs2.3.0.37-rc14/arch/sh/kernel/vsyscall/vsyscall.c
837 --- linux-2.6.38.3/arch/sh/kernel/vsyscall/vsyscall.c   2010-07-07 18:31:10.000000000 +0200
838 +++ linux-2.6.38.3-vs2.3.0.37-rc14/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.3/arch/sparc/Kconfig linux-2.6.38.3-vs2.3.0.37-rc14/arch/sparc/Kconfig
848 --- linux-2.6.38.3/arch/sparc/Kconfig   2011-03-15 18:06:47.000000000 +0100
849 +++ linux-2.6.38.3-vs2.3.0.37-rc14/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.3/arch/sparc/include/asm/tlb_64.h linux-2.6.38.3-vs2.3.0.37-rc14/arch/sparc/include/asm/tlb_64.h
860 --- linux-2.6.38.3/arch/sparc/include/asm/tlb_64.h      2009-09-10 15:25:45.000000000 +0200
861 +++ linux-2.6.38.3-vs2.3.0.37-rc14/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.3/arch/sparc/include/asm/unistd.h linux-2.6.38.3-vs2.3.0.37-rc14/arch/sparc/include/asm/unistd.h
871 --- linux-2.6.38.3/arch/sparc/include/asm/unistd.h      2010-10-21 13:06:58.000000000 +0200
872 +++ linux-2.6.38.3-vs2.3.0.37-rc14/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.3/arch/sparc/kernel/systbls_32.S linux-2.6.38.3-vs2.3.0.37-rc14/arch/sparc/kernel/systbls_32.S
883 --- linux-2.6.38.3/arch/sparc/kernel/systbls_32.S       2010-10-21 13:06:59.000000000 +0200
884 +++ linux-2.6.38.3-vs2.3.0.37-rc14/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.3/arch/sparc/kernel/systbls_64.S linux-2.6.38.3-vs2.3.0.37-rc14/arch/sparc/kernel/systbls_64.S
895 --- linux-2.6.38.3/arch/sparc/kernel/systbls_64.S       2010-10-21 13:06:59.000000000 +0200
896 +++ linux-2.6.38.3-vs2.3.0.37-rc14/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.3/arch/um/Kconfig.rest linux-2.6.38.3-vs2.3.0.37-rc14/arch/um/Kconfig.rest
916 --- linux-2.6.38.3/arch/um/Kconfig.rest 2009-06-11 17:12:19.000000000 +0200
917 +++ linux-2.6.38.3-vs2.3.0.37-rc14/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.3/arch/um/include/asm/tlb.h linux-2.6.38.3-vs2.3.0.37-rc14/arch/um/include/asm/tlb.h
928 --- linux-2.6.38.3/arch/um/include/asm/tlb.h    2009-09-10 15:25:46.000000000 +0200
929 +++ linux-2.6.38.3-vs2.3.0.37-rc14/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.3/arch/um/include/shared/kern_constants.h linux-2.6.38.3-vs2.3.0.37-rc14/arch/um/include/shared/kern_constants.h
939 --- linux-2.6.38.3/arch/um/include/shared/kern_constants.h      1970-01-01 01:00:00.000000000 +0100
940 +++ linux-2.6.38.3-vs2.3.0.37-rc14/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.3/arch/um/include/shared/user_constants.h linux-2.6.38.3-vs2.3.0.37-rc14/arch/um/include/shared/user_constants.h
944 --- linux-2.6.38.3/arch/um/include/shared/user_constants.h      1970-01-01 01:00:00.000000000 +0100
945 +++ linux-2.6.38.3-vs2.3.0.37-rc14/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.3/arch/x86/Kconfig linux-2.6.38.3-vs2.3.0.37-rc14/arch/x86/Kconfig
988 --- linux-2.6.38.3/arch/x86/Kconfig     2011-03-15 18:06:48.000000000 +0100
989 +++ linux-2.6.38.3-vs2.3.0.37-rc14/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.3/arch/x86/ia32/ia32entry.S linux-2.6.38.3-vs2.3.0.37-rc14/arch/x86/ia32/ia32entry.S
1000 --- linux-2.6.38.3/arch/x86/ia32/ia32entry.S    2010-10-21 13:06:59.000000000 +0200
1001 +++ linux-2.6.38.3-vs2.3.0.37-rc14/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.3/arch/x86/include/asm/unistd_64.h linux-2.6.38.3-vs2.3.0.37-rc14/arch/x86/include/asm/unistd_64.h
1012 --- linux-2.6.38.3/arch/x86/include/asm/unistd_64.h     2010-10-21 13:06:59.000000000 +0200
1013 +++ linux-2.6.38.3-vs2.3.0.37-rc14/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.3/arch/x86/kernel/syscall_table_32.S linux-2.6.38.3-vs2.3.0.37-rc14/arch/x86/kernel/syscall_table_32.S
1024 --- linux-2.6.38.3/arch/x86/kernel/syscall_table_32.S   2010-10-21 13:07:00.000000000 +0200
1025 +++ linux-2.6.38.3-vs2.3.0.37-rc14/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.3/block/genhd.c linux-2.6.38.3-vs2.3.0.37-rc14/block/genhd.c
1036 --- linux-2.6.38.3/block/genhd.c        2011-03-15 18:06:52.000000000 +0100
1037 +++ linux-2.6.38.3-vs2.3.0.37-rc14/block/genhd.c        2011-04-14 03:36:35.000000000 +0200
1038 @@ -1154,17 +1154,17 @@ static int diskstats_show(struct seq_fil
1039                 cpu = part_stat_lock();
1040                 part_round_stats(cpu, hd);
1041                 part_stat_unlock();
1042 -               seq_printf(seqf, "%4d %7d %s %lu %lu %llu "
1043 -                          "%u %lu %lu %llu %u %u %u %u\n",
1044 +               seq_printf(seqf, "%4d %7d %s %lu %lu %lu "
1045 +                          "%u %lu %lu %lu %u %u %u %u\n",
1046                            MAJOR(part_devt(hd)), MINOR(part_devt(hd)),
1047                            disk_name(gp, hd->partno, buf),
1048                            part_stat_read(hd, ios[0]),
1049                            part_stat_read(hd, merges[0]),
1050 -                          (unsigned long long)part_stat_read(hd, sectors[0]),
1051 +                          part_stat_read(hd, sectors[0]),
1052                            jiffies_to_msecs(part_stat_read(hd, ticks[0])),
1053                            part_stat_read(hd, ios[1]),
1054                            part_stat_read(hd, merges[1]),
1055 -                          (unsigned long long)part_stat_read(hd, sectors[1]),
1056 +                          part_stat_read(hd, sectors[1]),
1057                            jiffies_to_msecs(part_stat_read(hd, ticks[1])),
1058                            part_in_flight(hd),
1059                            jiffies_to_msecs(part_stat_read(hd, io_ticks)),
1060 diff -NurpP --minimal linux-2.6.38.3/drivers/block/Kconfig linux-2.6.38.3-vs2.3.0.37-rc14/drivers/block/Kconfig
1061 --- linux-2.6.38.3/drivers/block/Kconfig        2011-03-15 18:06:54.000000000 +0100
1062 +++ linux-2.6.38.3-vs2.3.0.37-rc14/drivers/block/Kconfig        2011-01-29 02:01:07.000000000 +0100
1063 @@ -273,6 +273,13 @@ config BLK_DEV_CRYPTOLOOP
1064  
1065  source "drivers/block/drbd/Kconfig"
1066  
1067 +config BLK_DEV_VROOT
1068 +       tristate "Virtual Root device support"
1069 +       depends on QUOTACTL
1070 +       ---help---
1071 +         Saying Y here will allow you to use quota/fs ioctls on a shared
1072 +         partition within a virtual server without compromising security.
1073 +
1074  config BLK_DEV_NBD
1075         tristate "Network block device support"
1076         depends on NET
1077 diff -NurpP --minimal linux-2.6.38.3/drivers/block/Makefile linux-2.6.38.3-vs2.3.0.37-rc14/drivers/block/Makefile
1078 --- linux-2.6.38.3/drivers/block/Makefile       2011-03-15 18:06:54.000000000 +0100
1079 +++ linux-2.6.38.3-vs2.3.0.37-rc14/drivers/block/Makefile       2011-02-17 02:17:45.000000000 +0100
1080 @@ -34,6 +34,7 @@ obj-$(CONFIG_VIODASD)         += viodasd.o
1081  obj-$(CONFIG_BLK_DEV_SX8)      += sx8.o
1082  obj-$(CONFIG_BLK_DEV_UB)       += ub.o
1083  obj-$(CONFIG_BLK_DEV_HD)       += hd.o
1084 +obj-$(CONFIG_BLK_DEV_VROOT)    += vroot.o
1085  
1086  obj-$(CONFIG_XEN_BLKDEV_FRONTEND)      += xen-blkfront.o
1087  obj-$(CONFIG_BLK_DEV_DRBD)     += drbd/
1088 diff -NurpP --minimal linux-2.6.38.3/drivers/block/loop.c linux-2.6.38.3-vs2.3.0.37-rc14/drivers/block/loop.c
1089 --- linux-2.6.38.3/drivers/block/loop.c 2011-03-15 18:06:54.000000000 +0100
1090 +++ linux-2.6.38.3-vs2.3.0.37-rc14/drivers/block/loop.c 2011-03-10 17:21:19.000000000 +0100
1091 @@ -75,6 +75,7 @@
1092  #include <linux/kthread.h>
1093  #include <linux/splice.h>
1094  #include <linux/sysfs.h>
1095 +#include <linux/vs_context.h>
1096  
1097  #include <asm/uaccess.h>
1098  
1099 @@ -902,6 +903,7 @@ static int loop_set_fd(struct loop_devic
1100         lo->lo_blocksize = lo_blocksize;
1101         lo->lo_device = bdev;
1102         lo->lo_flags = lo_flags;
1103 +       lo->lo_xid = vx_current_xid();
1104         lo->lo_backing_file = file;
1105         lo->transfer = transfer_none;
1106         lo->ioctl = NULL;
1107 @@ -1032,6 +1034,7 @@ static int loop_clr_fd(struct loop_devic
1108         lo->lo_encrypt_key_size = 0;
1109         lo->lo_flags = 0;
1110         lo->lo_thread = NULL;
1111 +       lo->lo_xid = 0;
1112         memset(lo->lo_encrypt_key, 0, LO_KEY_SIZE);
1113         memset(lo->lo_crypt_name, 0, LO_NAME_SIZE);
1114         memset(lo->lo_file_name, 0, LO_NAME_SIZE);
1115 @@ -1070,7 +1073,7 @@ loop_set_status(struct loop_device *lo, 
1116  
1117         if (lo->lo_encrypt_key_size &&
1118             lo->lo_key_owner != uid &&
1119 -           !capable(CAP_SYS_ADMIN))
1120 +           !vx_capable(CAP_SYS_ADMIN, VXC_ADMIN_CLOOP))
1121                 return -EPERM;
1122         if (lo->lo_state != Lo_bound)
1123                 return -ENXIO;
1124 @@ -1154,7 +1157,8 @@ loop_get_status(struct loop_device *lo, 
1125         memcpy(info->lo_crypt_name, lo->lo_crypt_name, LO_NAME_SIZE);
1126         info->lo_encrypt_type =
1127                 lo->lo_encryption ? lo->lo_encryption->number : 0;
1128 -       if (lo->lo_encrypt_key_size && capable(CAP_SYS_ADMIN)) {
1129 +       if (lo->lo_encrypt_key_size &&
1130 +               vx_capable(CAP_SYS_ADMIN, VXC_ADMIN_CLOOP)) {
1131                 info->lo_encrypt_key_size = lo->lo_encrypt_key_size;
1132                 memcpy(info->lo_encrypt_key, lo->lo_encrypt_key,
1133                        lo->lo_encrypt_key_size);
1134 @@ -1500,6 +1504,9 @@ static int lo_open(struct block_device *
1135  {
1136         struct loop_device *lo = bdev->bd_disk->private_data;
1137  
1138 +       if (!vx_check(lo->lo_xid, VS_IDENT|VS_HOSTID|VS_ADMIN_P))
1139 +               return -EACCES;
1140 +
1141         mutex_lock(&lo->lo_ctl_mutex);
1142         lo->lo_refcnt++;
1143         mutex_unlock(&lo->lo_ctl_mutex);
1144 diff -NurpP --minimal linux-2.6.38.3/drivers/block/vroot.c linux-2.6.38.3-vs2.3.0.37-rc14/drivers/block/vroot.c
1145 --- linux-2.6.38.3/drivers/block/vroot.c        1970-01-01 01:00:00.000000000 +0100
1146 +++ linux-2.6.38.3-vs2.3.0.37-rc14/drivers/block/vroot.c        2011-03-17 18:14:05.000000000 +0100
1147 @@ -0,0 +1,292 @@
1148 +/*
1149 + *  linux/drivers/block/vroot.c
1150 + *
1151 + *  written by Herbert Pötzl, 9/11/2002
1152 + *  ported to 2.6.10 by Herbert Pötzl, 30/12/2004
1153 + *
1154 + *  based on the loop.c code by Theodore Ts'o.
1155 + *
1156 + * Copyright (C) 2002-2007 by Herbert Pötzl.
1157 + * Redistribution of this file is permitted under the
1158 + * GNU General Public License.
1159 + *
1160 + */
1161 +
1162 +#include <linux/module.h>
1163 +#include <linux/moduleparam.h>
1164 +#include <linux/file.h>
1165 +#include <linux/major.h>
1166 +#include <linux/blkdev.h>
1167 +#include <linux/slab.h>
1168 +
1169 +#include <linux/vroot.h>
1170 +#include <linux/vs_context.h>
1171 +
1172 +
1173 +static int max_vroot = 8;
1174 +
1175 +static struct vroot_device *vroot_dev;
1176 +static struct gendisk **disks;
1177 +
1178 +
1179 +static int vroot_set_dev(
1180 +       struct vroot_device *vr,
1181 +       struct block_device *bdev,
1182 +       unsigned int arg)
1183 +{
1184 +       struct block_device *real_bdev;
1185 +       struct file *file;
1186 +       struct inode *inode;
1187 +       int error;
1188 +
1189 +       error = -EBUSY;
1190 +       if (vr->vr_state != Vr_unbound)
1191 +               goto out;
1192 +
1193 +       error = -EBADF;
1194 +       file = fget(arg);
1195 +       if (!file)
1196 +               goto out;
1197 +
1198 +       error = -EINVAL;
1199 +       inode = file->f_dentry->d_inode;
1200 +
1201 +
1202 +       if (S_ISBLK(inode->i_mode)) {
1203 +               real_bdev = inode->i_bdev;
1204 +               vr->vr_device = real_bdev;
1205 +               __iget(real_bdev->bd_inode);
1206 +       } else
1207 +               goto out_fput;
1208 +
1209 +       vxdprintk(VXD_CBIT(misc, 0),
1210 +               "vroot[%d]_set_dev: dev=" VXF_DEV,
1211 +               vr->vr_number, VXD_DEV(real_bdev));
1212 +
1213 +       vr->vr_state = Vr_bound;
1214 +       error = 0;
1215 +
1216 + out_fput:
1217 +       fput(file);
1218 + out:
1219 +       return error;
1220 +}
1221 +
1222 +static int vroot_clr_dev(
1223 +       struct vroot_device *vr,
1224 +       struct block_device *bdev)
1225 +{
1226 +       struct block_device *real_bdev;
1227 +
1228 +       if (vr->vr_state != Vr_bound)
1229 +               return -ENXIO;
1230 +       if (vr->vr_refcnt > 1)  /* we needed one fd for the ioctl */
1231 +               return -EBUSY;
1232 +
1233 +       real_bdev = vr->vr_device;
1234 +
1235 +       vxdprintk(VXD_CBIT(misc, 0),
1236 +               "vroot[%d]_clr_dev: dev=" VXF_DEV,
1237 +               vr->vr_number, VXD_DEV(real_bdev));
1238 +
1239 +       bdput(real_bdev);
1240 +       vr->vr_state = Vr_unbound;
1241 +       vr->vr_device = NULL;
1242 +       return 0;
1243 +}
1244 +
1245 +
1246 +static int vr_ioctl(struct block_device *bdev, fmode_t mode,
1247 +       unsigned int cmd, unsigned long arg)
1248 +{
1249 +       struct vroot_device *vr = bdev->bd_disk->private_data;
1250 +       int err;
1251 +
1252 +       down(&vr->vr_ctl_mutex);
1253 +       switch (cmd) {
1254 +       case VROOT_SET_DEV:
1255 +               err = vroot_set_dev(vr, bdev, arg);
1256 +               break;
1257 +       case VROOT_CLR_DEV:
1258 +               err = vroot_clr_dev(vr, bdev);
1259 +               break;
1260 +       default:
1261 +               err = -EINVAL;
1262 +               break;
1263 +       }
1264 +       up(&vr->vr_ctl_mutex);
1265 +       return err;
1266 +}
1267 +
1268 +static int vr_open(struct block_device *bdev, fmode_t mode)
1269 +{
1270 +       struct vroot_device *vr = bdev->bd_disk->private_data;
1271 +
1272 +       down(&vr->vr_ctl_mutex);
1273 +       vr->vr_refcnt++;
1274 +       up(&vr->vr_ctl_mutex);
1275 +       return 0;
1276 +}
1277 +
1278 +static int vr_release(struct gendisk *disk, fmode_t mode)
1279 +{
1280 +       struct vroot_device *vr = disk->private_data;
1281 +
1282 +       down(&vr->vr_ctl_mutex);
1283 +       --vr->vr_refcnt;
1284 +       up(&vr->vr_ctl_mutex);
1285 +       return 0;
1286 +}
1287 +
1288 +static struct block_device_operations vr_fops = {
1289 +       .owner =        THIS_MODULE,
1290 +       .open =         vr_open,
1291 +       .release =      vr_release,
1292 +       .ioctl =        vr_ioctl,
1293 +};
1294 +
1295 +static int vroot_make_request(struct request_queue *q, struct bio *bio)
1296 +{
1297 +       printk("vroot_make_request %p, %p\n", q, bio);
1298 +       bio_io_error(bio);
1299 +       return 0;
1300 +}
1301 +
1302 +struct block_device *__vroot_get_real_bdev(struct block_device *bdev)
1303 +{
1304 +       struct inode *inode = bdev->bd_inode;
1305 +       struct vroot_device *vr;
1306 +       struct block_device *real_bdev;
1307 +       int minor = iminor(inode);
1308 +
1309 +       vr = &vroot_dev[minor];
1310 +       real_bdev = vr->vr_device;
1311 +
1312 +       vxdprintk(VXD_CBIT(misc, 0),
1313 +               "vroot[%d]_get_real_bdev: dev=" VXF_DEV,
1314 +               vr->vr_number, VXD_DEV(real_bdev));
1315 +
1316 +       if (vr->vr_state != Vr_bound)
1317 +               return ERR_PTR(-ENXIO);
1318 +
1319 +       __iget(real_bdev->bd_inode);
1320 +       return real_bdev;
1321 +}
1322 +
1323 +
1324 +
1325 +/*
1326 + * And now the modules code and kernel interface.
1327 + */
1328 +
1329 +module_param(max_vroot, int, 0);
1330 +
1331 +MODULE_PARM_DESC(max_vroot, "Maximum number of vroot devices (1-256)");
1332 +MODULE_LICENSE("GPL");
1333 +MODULE_ALIAS_BLOCKDEV_MAJOR(VROOT_MAJOR);
1334 +
1335 +MODULE_AUTHOR ("Herbert Pötzl");
1336 +MODULE_DESCRIPTION ("Virtual Root Device Mapper");
1337 +
1338 +
1339 +int __init vroot_init(void)
1340 +{
1341 +       int err, i;
1342 +
1343 +       if (max_vroot < 1 || max_vroot > 256) {
1344 +               max_vroot = MAX_VROOT_DEFAULT;
1345 +               printk(KERN_WARNING "vroot: invalid max_vroot "
1346 +                       "(must be between 1 and 256), "
1347 +                       "using default (%d)\n", max_vroot);
1348 +       }
1349 +
1350 +       if (register_blkdev(VROOT_MAJOR, "vroot"))
1351 +               return -EIO;
1352 +
1353 +       err = -ENOMEM;
1354 +       vroot_dev = kmalloc(max_vroot * sizeof(struct vroot_device), GFP_KERNEL);
1355 +       if (!vroot_dev)
1356 +               goto out_mem1;
1357 +       memset(vroot_dev, 0, max_vroot * sizeof(struct vroot_device));
1358 +
1359 +       disks = kmalloc(max_vroot * sizeof(struct gendisk *), GFP_KERNEL);
1360 +       if (!disks)
1361 +               goto out_mem2;
1362 +
1363 +       for (i = 0; i < max_vroot; i++) {
1364 +               disks[i] = alloc_disk(1);
1365 +               if (!disks[i])
1366 +                       goto out_mem3;
1367 +               disks[i]->queue = blk_alloc_queue(GFP_KERNEL);
1368 +               if (!disks[i]->queue)
1369 +                       goto out_mem3;
1370 +               blk_queue_make_request(disks[i]->queue, vroot_make_request);
1371 +       }
1372 +
1373 +       for (i = 0; i < max_vroot; i++) {
1374 +               struct vroot_device *vr = &vroot_dev[i];
1375 +               struct gendisk *disk = disks[i];
1376 +
1377 +               memset(vr, 0, sizeof(*vr));
1378 +               sema_init(&vr->vr_ctl_mutex, 1);
1379 +               vr->vr_number = i;
1380 +               disk->major = VROOT_MAJOR;
1381 +               disk->first_minor = i;
1382 +               disk->fops = &vr_fops;
1383 +               sprintf(disk->disk_name, "vroot%d", i);
1384 +               disk->private_data = vr;
1385 +       }
1386 +
1387 +       err = register_vroot_grb(&__vroot_get_real_bdev);
1388 +       if (err)
1389 +               goto out_mem3;
1390 +
1391 +       for (i = 0; i < max_vroot; i++)
1392 +               add_disk(disks[i]);
1393 +       printk(KERN_INFO "vroot: loaded (max %d devices)\n", max_vroot);
1394 +       return 0;
1395 +
1396 +out_mem3:
1397 +       while (i--)
1398 +               put_disk(disks[i]);
1399 +       kfree(disks);
1400 +out_mem2:
1401 +       kfree(vroot_dev);
1402 +out_mem1:
1403 +       unregister_blkdev(VROOT_MAJOR, "vroot");
1404 +       printk(KERN_ERR "vroot: ran out of memory\n");
1405 +       return err;
1406 +}
1407 +
1408 +void vroot_exit(void)
1409 +{
1410 +       int i;
1411 +
1412 +       if (unregister_vroot_grb(&__vroot_get_real_bdev))
1413 +               printk(KERN_WARNING "vroot: cannot unregister grb\n");
1414 +
1415 +       for (i = 0; i < max_vroot; i++) {
1416 +               del_gendisk(disks[i]);
1417 +               put_disk(disks[i]);
1418 +       }
1419 +       unregister_blkdev(VROOT_MAJOR, "vroot");
1420 +
1421 +       kfree(disks);
1422 +       kfree(vroot_dev);
1423 +}
1424 +
1425 +module_init(vroot_init);
1426 +module_exit(vroot_exit);
1427 +
1428 +#ifndef MODULE
1429 +
1430 +static int __init max_vroot_setup(char *str)
1431 +{
1432 +       max_vroot = simple_strtol(str, NULL, 0);
1433 +       return 1;
1434 +}
1435 +
1436 +__setup("max_vroot=", max_vroot_setup);
1437 +
1438 +#endif
1439 +
1440 diff -NurpP --minimal linux-2.6.38.3/drivers/gpu/drm/radeon/r100_reg_safe.h linux-2.6.38.3-vs2.3.0.37-rc14/drivers/gpu/drm/radeon/r100_reg_safe.h
1441 --- linux-2.6.38.3/drivers/gpu/drm/radeon/r100_reg_safe.h       1970-01-01 01:00:00.000000000 +0100
1442 +++ linux-2.6.38.3-vs2.3.0.37-rc14/drivers/gpu/drm/radeon/r100_reg_safe.h       2011-01-29 02:01:07.000000000 +0100
1443 @@ -0,0 +1,28 @@
1444 +static const unsigned r100_reg_safe_bm[102] = {
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 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1453 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1454 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1455 +       0x17FF1FFF, 0xFFFFFFFC, 0xFFFFFFFF, 0xFF30FFBF,
1456 +       0xFFFFFFF8, 0xC3E6FFFF, 0xFFFFF6DF, 0xFFFFFFFF,
1457 +       0xFFFFFFCF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1458 +       0xFFFFFF9F, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1459 +       0x38E7FE1F, 0xFFC3FF8E, 0x7FF8FFFF, 0xFFFF803C,
1460 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1461 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFEFFFF, 0xFFFFFFFF,
1462 +       0x00000000, 0xFFFFFFFD, 0xFFFFFFFF, 0xFFFFFFFF,
1463 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1464 +       0xFFFFFFFF, 0xFFFCFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1465 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1466 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1467 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1468 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1469 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1470 +       0xFFFFFFFF, 0xFFFFFFEF,
1471 +};
1472 diff -NurpP --minimal linux-2.6.38.3/drivers/gpu/drm/radeon/r200_reg_safe.h linux-2.6.38.3-vs2.3.0.37-rc14/drivers/gpu/drm/radeon/r200_reg_safe.h
1473 --- linux-2.6.38.3/drivers/gpu/drm/radeon/r200_reg_safe.h       1970-01-01 01:00:00.000000000 +0100
1474 +++ linux-2.6.38.3-vs2.3.0.37-rc14/drivers/gpu/drm/radeon/r200_reg_safe.h       2011-01-29 02:01:07.000000000 +0100
1475 @@ -0,0 +1,28 @@
1476 +static const unsigned r200_reg_safe_bm[102] = {
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 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1485 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1486 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1487 +       0x17FF1FFF, 0xFFFFFFFC, 0xFFFFFFFF, 0xFF30FFBF,
1488 +       0xFFFFFFF8, 0xC3E6FFFF, 0xFFFFF6DF, 0xFFFFFFFF,
1489 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1490 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1491 +       0xFFE7FE1F, 0xF003FFFF, 0x7EFFFFFF, 0xFFFF803C,
1492 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1493 +       0xFFFFFFFF, 0xFFFFEFCE, 0xFFFEFFFF, 0xFFFFFFFE,
1494 +       0x020E0FF0, 0xFFCC83FD, 0xFFFFFFFF, 0xFFFFFFFF,
1495 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1496 +       0xFFFBFFFF, 0xEFFCFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1497 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1498 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1499 +       0xDFDFDFDF, 0x3FFDDFDF, 0xFFFFFFFF, 0xFFFFFF7F,
1500 +       0xFFFFFFFF, 0x00FFFFFF, 0x00000000, 0x00000000,
1501 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1502 +       0xFFFFFE3F, 0xFFFFFFEF,
1503 +};
1504 diff -NurpP --minimal linux-2.6.38.3/drivers/gpu/drm/radeon/r300_reg_safe.h linux-2.6.38.3-vs2.3.0.37-rc14/drivers/gpu/drm/radeon/r300_reg_safe.h
1505 --- linux-2.6.38.3/drivers/gpu/drm/radeon/r300_reg_safe.h       1970-01-01 01:00:00.000000000 +0100
1506 +++ linux-2.6.38.3-vs2.3.0.37-rc14/drivers/gpu/drm/radeon/r300_reg_safe.h       2011-01-29 02:01:07.000000000 +0100
1507 @@ -0,0 +1,42 @@
1508 +static const unsigned r300_reg_safe_bm[159] = {
1509 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1510 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1511 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1512 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1513 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1514 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1515 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1516 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1517 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1518 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1519 +       0x17FF1FFF, 0xFFFFFFFC, 0xFFFFFFFF, 0xFF30FFBF,
1520 +       0xFFFFFFF8, 0xC3E6FFFF, 0xFFFFF6DF, 0xFFFFFFFF,
1521 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1522 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1523 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFF03F,
1524 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1525 +       0xFFFFFFFF, 0xFFFFEFCE, 0xF00EBFFF, 0x007C0000,
1526 +       0xF0000078, 0xFF000009, 0xFFFFFFFF, 0xFFFFFFFF,
1527 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1528 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1529 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1530 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1531 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1532 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1533 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1534 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1535 +       0xFFFFF7FF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1536 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1537 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1538 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1539 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1540 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1541 +       0xFFFFFC78, 0xFFFFFFFF, 0xFFFFFFFE, 0xFFFFFFFF,
1542 +       0x38FF8F50, 0xFFF88082, 0xF000000C, 0xFAE009FF,
1543 +       0x0000FFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0x00000000,
1544 +       0x00000000, 0x0000C100, 0x00000000, 0x00000000,
1545 +       0x00000000, 0x00000000, 0x00000000, 0x00000000,
1546 +       0x00000000, 0xFFFF0000, 0xFFFFFFFF, 0xFF80FFFF,
1547 +       0x00000000, 0x00000000, 0x00000000, 0x00000000,
1548 +       0x0003FC01, 0xFFFFFCF8, 0xFF800B19,
1549 +};
1550 diff -NurpP --minimal linux-2.6.38.3/drivers/gpu/drm/radeon/r420_reg_safe.h linux-2.6.38.3-vs2.3.0.37-rc14/drivers/gpu/drm/radeon/r420_reg_safe.h
1551 --- linux-2.6.38.3/drivers/gpu/drm/radeon/r420_reg_safe.h       1970-01-01 01:00:00.000000000 +0100
1552 +++ linux-2.6.38.3-vs2.3.0.37-rc14/drivers/gpu/drm/radeon/r420_reg_safe.h       2011-01-29 02:01:07.000000000 +0100
1553 @@ -0,0 +1,42 @@
1554 +static const unsigned r420_reg_safe_bm[159] = {
1555 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1556 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1557 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1558 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1559 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1560 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1561 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1562 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1563 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1564 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1565 +       0x17FF1FFF, 0xFFFFFFFC, 0xFFFFFFFF, 0xFF30FFBF,
1566 +       0xFFFFFFF8, 0xC3E6FFFF, 0xFFFFF6DF, 0xFFFFFFFF,
1567 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1568 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1569 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFF03F,
1570 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1571 +       0xFFFFFFFF, 0xFFFFEFCE, 0xF00EBFFF, 0x007C0000,
1572 +       0xF0000078, 0xFF000009, 0xFFFFFFFF, 0xFFFFFFFF,
1573 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1574 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1575 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1576 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1577 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1578 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1579 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1580 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1581 +       0xFFFFF7FF, 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 +       0xFFFFFC78, 0xFFFFFFFF, 0xFFFFFFFE, 0xFFFFFFFF,
1588 +       0x38FF8F50, 0xFFF88082, 0xF000000C, 0xFAE009FF,
1589 +       0x0000FFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0x00000000,
1590 +       0x00000000, 0x00000100, 0x00000000, 0x00000000,
1591 +       0x00000000, 0x00000000, 0x00000000, 0x00000000,
1592 +       0x00000000, 0x00000000, 0x00000000, 0xFF800000,
1593 +       0x00000000, 0x00000000, 0x00000000, 0x00000000,
1594 +       0x0003FC01, 0xFFFFFCF8, 0xFF800B19,
1595 +};
1596 diff -NurpP --minimal linux-2.6.38.3/drivers/gpu/drm/radeon/rn50_reg_safe.h linux-2.6.38.3-vs2.3.0.37-rc14/drivers/gpu/drm/radeon/rn50_reg_safe.h
1597 --- linux-2.6.38.3/drivers/gpu/drm/radeon/rn50_reg_safe.h       1970-01-01 01:00:00.000000000 +0100
1598 +++ linux-2.6.38.3-vs2.3.0.37-rc14/drivers/gpu/drm/radeon/rn50_reg_safe.h       2011-01-29 02:01:07.000000000 +0100
1599 @@ -0,0 +1,28 @@
1600 +static const unsigned rn50_reg_safe_bm[102] = {
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 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1609 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1610 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1611 +       0x17FF1FFF, 0xFFFFFFFC, 0xFFFFFFFF, 0xFF30FFBF,
1612 +       0xFFFFFFF8, 0xC3E6FFFF, 0xFFFFF6DF, 0xFFFFFFFF,
1613 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1614 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1615 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1616 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1617 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1618 +       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 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1625 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1626 +       0xFFFFFFFF, 0xFFFFFFFF,
1627 +};
1628 diff -NurpP --minimal linux-2.6.38.3/drivers/gpu/drm/radeon/rs600_reg_safe.h linux-2.6.38.3-vs2.3.0.37-rc14/drivers/gpu/drm/radeon/rs600_reg_safe.h
1629 --- linux-2.6.38.3/drivers/gpu/drm/radeon/rs600_reg_safe.h      1970-01-01 01:00:00.000000000 +0100
1630 +++ linux-2.6.38.3-vs2.3.0.37-rc14/drivers/gpu/drm/radeon/rs600_reg_safe.h      2011-01-29 02:01:07.000000000 +0100
1631 @@ -0,0 +1,57 @@
1632 +static const unsigned rs600_reg_safe_bm[219] = {
1633 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1634 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1635 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1636 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1637 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1638 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1639 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1640 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1641 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1642 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1643 +       0x17FF1FFF, 0xFFFFFFFC, 0xFFFFFFFF, 0xFF30FFBF,
1644 +       0xFFFFFFF8, 0xC3E6FFFF, 0xFFFFF6DF, 0xFFFFFFFF,
1645 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1646 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1647 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFF03F,
1648 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1649 +       0xFFFFFFFF, 0xFFFFEFCE, 0xF00EBFFF, 0x007C0000,
1650 +       0xF0000078, 0xFF000009, 0xFFFFFFFF, 0xFFFFFFFF,
1651 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1652 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1653 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1654 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1655 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1656 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1657 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1658 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1659 +       0xFFFFF7FF, 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 +       0xFFFFFC78, 0xFFFFFFFF, 0xFFFFFFFE, 0xFFFFFFFF,
1666 +       0x38FF8F50, 0xFFF88082, 0xF000000C, 0xFAE009FF,
1667 +       0x0000FFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0x00000000,
1668 +       0x00000000, 0x00000100, 0x00000000, 0x00000000,
1669 +       0x00000000, 0x00000000, 0x00000000, 0x00000000,
1670 +       0x00000000, 0x00000000, 0x00000000, 0xFF800000,
1671 +       0x00000000, 0x00000000, 0x00000000, 0x00000000,
1672 +       0x0003FC01, 0xFFFFFCF8, 0xFF800B19, 0xFFFFFFFF,
1673 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1674 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1675 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1676 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1677 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1678 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1679 +       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 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1686 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1687 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1688 +};
1689 diff -NurpP --minimal linux-2.6.38.3/drivers/gpu/drm/radeon/rv515_reg_safe.h linux-2.6.38.3-vs2.3.0.37-rc14/drivers/gpu/drm/radeon/rv515_reg_safe.h
1690 --- linux-2.6.38.3/drivers/gpu/drm/radeon/rv515_reg_safe.h      1970-01-01 01:00:00.000000000 +0100
1691 +++ linux-2.6.38.3-vs2.3.0.37-rc14/drivers/gpu/drm/radeon/rv515_reg_safe.h      2011-01-29 02:01:07.000000000 +0100
1692 @@ -0,0 +1,57 @@
1693 +static const unsigned rv515_reg_safe_bm[219] = {
1694 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1695 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1696 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1697 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1698 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1699 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1700 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1701 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1702 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1703 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1704 +       0x17FF1FFF, 0xFFFFFFFC, 0xFFFFFFFF, 0xFF30FFBF,
1705 +       0xFFFFFFF8, 0xC3E6FFFF, 0xFFFFF6DF, 0xFFFFFFFF,
1706 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1707 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1708 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFF03F,
1709 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1710 +       0xFFFFFFFF, 0xFFFFEFCE, 0xF00EBFFF, 0x007C0000,
1711 +       0xF0000038, 0xFF000009, 0xFFFFFFFF, 0xFFFFFFFF,
1712 +       0xFFFFFFFF, 0xFFFFFFFF, 0x00000000, 0xFFFFFFFF,
1713 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1714 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1715 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1716 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1717 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1718 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1719 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1720 +       0xFFFFF7FF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1721 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1722 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1723 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1724 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1725 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1726 +       0x1FFFF878, 0xFFFFE000, 0xFFFFFE1E, 0xFFFFFFFF,
1727 +       0x388F8F50, 0xFFF88082, 0xFF0000FC, 0xFAE009FF,
1728 +       0x0000FFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0x00000000,
1729 +       0xFFFF8CFC, 0xFFFFC1FF, 0xFFFFFFFF, 0xFFFFFFFF,
1730 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1731 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFF80FFFF,
1732 +       0x00000000, 0x00000000, 0x00000000, 0x00000000,
1733 +       0x0003FC01, 0x3FFFFCF8, 0xFF800B19, 0xFFDFFFFF,
1734 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1735 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1736 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1737 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1738 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1739 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1740 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1741 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1742 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1743 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1744 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1745 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1746 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1747 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1748 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1749 +};
1750 diff -NurpP --minimal linux-2.6.38.3/drivers/infiniband/core/addr.c linux-2.6.38.3-vs2.3.0.37-rc14/drivers/infiniband/core/addr.c
1751 --- linux-2.6.38.3/drivers/infiniband/core/addr.c       2011-03-15 18:06:57.000000000 +0100
1752 +++ linux-2.6.38.3-vs2.3.0.37-rc14/drivers/infiniband/core/addr.c       2011-01-29 02:01:07.000000000 +0100
1753 @@ -252,7 +252,7 @@ static int addr6_resolve(struct sockaddr
1754  
1755         if (ipv6_addr_any(&fl.fl6_src)) {
1756                 ret = ipv6_dev_get_saddr(&init_net, ip6_dst_idev(dst)->dev,
1757 -                                        &fl.fl6_dst, 0, &fl.fl6_src);
1758 +                                        &fl.fl6_dst, 0, &fl.fl6_src, NULL);
1759                 if (ret)
1760                         goto put;
1761  
1762 diff -NurpP --minimal linux-2.6.38.3/drivers/infiniband/hw/ipath/ipath_user_pages.c linux-2.6.38.3-vs2.3.0.37-rc14/drivers/infiniband/hw/ipath/ipath_user_pages.c
1763 --- linux-2.6.38.3/drivers/infiniband/hw/ipath/ipath_user_pages.c       2011-03-15 18:06:58.000000000 +0100
1764 +++ linux-2.6.38.3-vs2.3.0.37-rc14/drivers/infiniband/hw/ipath/ipath_user_pages.c       2011-01-29 02:01:07.000000000 +0100
1765 @@ -35,6 +35,7 @@
1766  #include <linux/device.h>
1767  #include <linux/slab.h>
1768  #include <linux/sched.h>
1769 +#include <linux/vs_memory.h>
1770  
1771  #include "ipath_kernel.h"
1772  
1773 diff -NurpP --minimal linux-2.6.38.3/drivers/md/dm-ioctl.c linux-2.6.38.3-vs2.3.0.37-rc14/drivers/md/dm-ioctl.c
1774 --- linux-2.6.38.3/drivers/md/dm-ioctl.c        2011-03-15 18:07:02.000000000 +0100
1775 +++ linux-2.6.38.3-vs2.3.0.37-rc14/drivers/md/dm-ioctl.c        2011-01-29 02:01:07.000000000 +0100
1776 @@ -16,6 +16,7 @@
1777  #include <linux/dm-ioctl.h>
1778  #include <linux/hdreg.h>
1779  #include <linux/compat.h>
1780 +#include <linux/vs_context.h>
1781  
1782  #include <asm/uaccess.h>
1783  
1784 @@ -106,7 +107,8 @@ static struct hash_cell *__get_name_cell
1785         unsigned int h = hash_str(str);
1786  
1787         list_for_each_entry (hc, _name_buckets + h, name_list)
1788 -               if (!strcmp(hc->name, str)) {
1789 +               if (vx_check(dm_get_xid(hc->md), VS_WATCH_P | VS_IDENT) &&
1790 +                       !strcmp(hc->name, str)) {
1791                         dm_get(hc->md);
1792                         return hc;
1793                 }
1794 @@ -120,7 +122,8 @@ static struct hash_cell *__get_uuid_cell
1795         unsigned int h = hash_str(str);
1796  
1797         list_for_each_entry (hc, _uuid_buckets + h, uuid_list)
1798 -               if (!strcmp(hc->uuid, str)) {
1799 +               if (vx_check(dm_get_xid(hc->md), VS_WATCH_P | VS_IDENT) &&
1800 +                       !strcmp(hc->uuid, str)) {
1801                         dm_get(hc->md);
1802                         return hc;
1803                 }
1804 @@ -427,6 +430,9 @@ typedef int (*ioctl_fn)(struct dm_ioctl 
1805  
1806  static int remove_all(struct dm_ioctl *param, size_t param_size)
1807  {
1808 +       if (!vx_check(0, VS_ADMIN))
1809 +               return -EPERM;
1810 +
1811         dm_hash_remove_all(1);
1812         param->data_size = 0;
1813         return 0;
1814 @@ -474,6 +480,8 @@ static int list_devices(struct dm_ioctl 
1815          */
1816         for (i = 0; i < NUM_BUCKETS; i++) {
1817                 list_for_each_entry (hc, _name_buckets + i, name_list) {
1818 +                       if (!vx_check(dm_get_xid(hc->md), VS_WATCH_P | VS_IDENT))
1819 +                               continue;
1820                         needed += sizeof(struct dm_name_list);
1821                         needed += strlen(hc->name) + 1;
1822                         needed += ALIGN_MASK;
1823 @@ -497,6 +505,8 @@ static int list_devices(struct dm_ioctl 
1824          */
1825         for (i = 0; i < NUM_BUCKETS; i++) {
1826                 list_for_each_entry (hc, _name_buckets + i, name_list) {
1827 +                       if (!vx_check(dm_get_xid(hc->md), VS_WATCH_P | VS_IDENT))
1828 +                               continue;
1829                         if (old_nl)
1830                                 old_nl->next = (uint32_t) ((void *) nl -
1831                                                            (void *) old_nl);
1832 @@ -731,10 +741,11 @@ static struct hash_cell *__find_device_h
1833         if (!md)
1834                 goto out;
1835  
1836 -       mdptr = dm_get_mdptr(md);
1837 +       if (vx_check(dm_get_xid(md), VS_WATCH_P | VS_IDENT))
1838 +               mdptr = dm_get_mdptr(md);
1839 +
1840         if (!mdptr)
1841                 dm_put(md);
1842 -
1843  out:
1844         return mdptr;
1845  }
1846 @@ -1566,8 +1577,8 @@ static int ctl_ioctl(uint command, struc
1847         ioctl_fn fn = NULL;
1848         size_t param_size;
1849  
1850 -       /* only root can play with this */
1851 -       if (!capable(CAP_SYS_ADMIN))
1852 +       /* only root and certain contexts can play with this */
1853 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_ADMIN_MAPPER))
1854                 return -EACCES;
1855  
1856         if (_IOC_TYPE(command) != DM_IOCTL)
1857 diff -NurpP --minimal linux-2.6.38.3/drivers/md/dm.c linux-2.6.38.3-vs2.3.0.37-rc14/drivers/md/dm.c
1858 --- linux-2.6.38.3/drivers/md/dm.c      2011-03-15 18:07:02.000000000 +0100
1859 +++ linux-2.6.38.3-vs2.3.0.37-rc14/drivers/md/dm.c      2011-01-29 03:26:19.000000000 +0100
1860 @@ -20,6 +20,7 @@
1861  #include <linux/idr.h>
1862  #include <linux/hdreg.h>
1863  #include <linux/delay.h>
1864 +#include <linux/vs_base.h>
1865  
1866  #include <trace/events/block.h>
1867  
1868 @@ -119,6 +120,7 @@ struct mapped_device {
1869         rwlock_t map_lock;
1870         atomic_t holders;
1871         atomic_t open_count;
1872 +       xid_t xid;
1873  
1874         unsigned long flags;
1875  
1876 @@ -326,6 +328,7 @@ int dm_deleting_md(struct mapped_device 
1877  static int dm_blk_open(struct block_device *bdev, fmode_t mode)
1878  {
1879         struct mapped_device *md;
1880 +       int ret = -ENXIO;
1881  
1882         spin_lock(&_minor_lock);
1883  
1884 @@ -334,18 +337,19 @@ static int dm_blk_open(struct block_devi
1885                 goto out;
1886  
1887         if (test_bit(DMF_FREEING, &md->flags) ||
1888 -           dm_deleting_md(md)) {
1889 -               md = NULL;
1890 +           dm_deleting_md(md))
1891 +               goto out;
1892 +
1893 +       ret = -EACCES;
1894 +       if (!vx_check(md->xid, VS_IDENT|VS_HOSTID))
1895                 goto out;
1896 -       }
1897  
1898         dm_get(md);
1899         atomic_inc(&md->open_count);
1900 -
1901 +       ret = 0;
1902  out:
1903         spin_unlock(&_minor_lock);
1904 -
1905 -       return md ? 0 : -ENXIO;
1906 +       return ret;
1907  }
1908  
1909  static int dm_blk_close(struct gendisk *disk, fmode_t mode)
1910 @@ -565,6 +569,14 @@ int dm_set_geometry(struct mapped_device
1911         return 0;
1912  }
1913  
1914 +/*
1915 + * Get the xid associated with a dm device
1916 + */
1917 +xid_t dm_get_xid(struct mapped_device *md)
1918 +{
1919 +       return md->xid;
1920 +}
1921 +
1922  /*-----------------------------------------------------------------
1923   * CRUD START:
1924   *   A more elegant soln is in the works that uses the queue
1925 @@ -1860,6 +1872,7 @@ static struct mapped_device *alloc_dev(i
1926         INIT_LIST_HEAD(&md->uevent_list);
1927         spin_lock_init(&md->uevent_lock);
1928  
1929 +       md->xid = vx_current_xid();
1930         md->queue = blk_alloc_queue(GFP_KERNEL);
1931         if (!md->queue)
1932                 goto bad_queue;
1933 diff -NurpP --minimal linux-2.6.38.3/drivers/md/dm.h linux-2.6.38.3-vs2.3.0.37-rc14/drivers/md/dm.h
1934 --- linux-2.6.38.3/drivers/md/dm.h      2010-10-21 13:07:07.000000000 +0200
1935 +++ linux-2.6.38.3-vs2.3.0.37-rc14/drivers/md/dm.h      2011-01-29 02:01:07.000000000 +0100
1936 @@ -41,6 +41,8 @@ struct dm_dev_internal {
1937  struct dm_table;
1938  struct dm_md_mempools;
1939  
1940 +xid_t dm_get_xid(struct mapped_device *md);
1941 +
1942  /*-----------------------------------------------------------------
1943   * Internal table functions.
1944   *---------------------------------------------------------------*/
1945 diff -NurpP --minimal linux-2.6.38.3/drivers/net/tun.c linux-2.6.38.3-vs2.3.0.37-rc14/drivers/net/tun.c
1946 --- linux-2.6.38.3/drivers/net/tun.c    2011-03-15 18:07:12.000000000 +0100
1947 +++ linux-2.6.38.3-vs2.3.0.37-rc14/drivers/net/tun.c    2011-01-29 02:01:07.000000000 +0100
1948 @@ -62,6 +62,7 @@
1949  #include <linux/nsproxy.h>
1950  #include <linux/virtio_net.h>
1951  #include <linux/rcupdate.h>
1952 +#include <linux/vs_network.h>
1953  #include <net/net_namespace.h>
1954  #include <net/netns/generic.h>
1955  #include <net/rtnetlink.h>
1956 @@ -103,6 +104,7 @@ struct tun_struct {
1957         unsigned int            flags;
1958         uid_t                   owner;
1959         gid_t                   group;
1960 +       nid_t                   nid;
1961  
1962         struct net_device       *dev;
1963         struct fasync_struct    *fasync;
1964 @@ -853,6 +855,7 @@ static void tun_setup(struct net_device 
1965  
1966         tun->owner = -1;
1967         tun->group = -1;
1968 +       tun->nid = current->nid;
1969  
1970         dev->ethtool_ops = &tun_ethtool_ops;
1971         dev->destructor = tun_free_netdev;
1972 @@ -1003,7 +1006,7 @@ static int tun_set_iff(struct net *net, 
1973  
1974                 if (((tun->owner != -1 && cred->euid != tun->owner) ||
1975                      (tun->group != -1 && !in_egroup_p(tun->group))) &&
1976 -                   !capable(CAP_NET_ADMIN))
1977 +               !cap_raised(current_cap(), CAP_NET_ADMIN))
1978                         return -EPERM;
1979                 err = security_tun_dev_attach(tun->socket.sk);
1980                 if (err < 0)
1981 @@ -1017,7 +1020,7 @@ static int tun_set_iff(struct net *net, 
1982                 char *name;
1983                 unsigned long flags = 0;
1984  
1985 -               if (!capable(CAP_NET_ADMIN))
1986 +               if (!nx_capable(CAP_NET_ADMIN, NXC_TUN_CREATE))
1987                         return -EPERM;
1988                 err = security_tun_dev_create();
1989                 if (err < 0)
1990 @@ -1087,6 +1090,9 @@ static int tun_set_iff(struct net *net, 
1991  
1992                 sk->sk_destruct = tun_sock_destruct;
1993  
1994 +               if (!nx_check(tun->nid, VS_IDENT | VS_HOSTID | VS_ADMIN_P))
1995 +                       return -EPERM;
1996 +
1997                 err = tun_attach(tun, file);
1998                 if (err < 0)
1999                         goto failed;
2000 @@ -1278,6 +1284,16 @@ static long __tun_chr_ioctl(struct file 
2001                 DBG(KERN_INFO "%s: group set to %d\n", tun->dev->name, tun->group);
2002                 break;
2003  
2004 +       case TUNSETNID:
2005 +               if (!capable(CAP_CONTEXT))
2006 +                       return -EPERM;
2007 +
2008 +               /* Set nid owner of the device */
2009 +               tun->nid = (nid_t) arg;
2010 +
2011 +               DBG(KERN_INFO "%s: nid owner set to %u\n", tun->dev->name, tun->nid);
2012 +               break;
2013 +
2014         case TUNSETLINK:
2015                 /* Only allow setting the type when the interface is down */
2016                 if (tun->dev->flags & IFF_UP) {
2017 diff -NurpP --minimal linux-2.6.38.3/drivers/tty/sysrq.c linux-2.6.38.3-vs2.3.0.37-rc14/drivers/tty/sysrq.c
2018 --- linux-2.6.38.3/drivers/tty/sysrq.c  2011-03-15 18:07:26.000000000 +0100
2019 +++ linux-2.6.38.3-vs2.3.0.37-rc14/drivers/tty/sysrq.c  2011-02-17 02:17:49.000000000 +0100
2020 @@ -41,6 +41,7 @@
2021  #include <linux/oom.h>
2022  #include <linux/slab.h>
2023  #include <linux/input.h>
2024 +#include <linux/vserver/debug.h>
2025  
2026  #include <asm/ptrace.h>
2027  #include <asm/irq_regs.h>
2028 @@ -395,6 +396,21 @@ static struct sysrq_key_op sysrq_unrt_op
2029         .enable_mask    = SYSRQ_ENABLE_RTNICE,
2030  };
2031  
2032 +
2033 +#ifdef CONFIG_VSERVER_DEBUG
2034 +static void sysrq_handle_vxinfo(int key)
2035 +{
2036 +       dump_vx_info_inactive((key == 'x') ? 0 : 1);
2037 +}
2038 +
2039 +static struct sysrq_key_op sysrq_showvxinfo_op = {
2040 +       .handler        = sysrq_handle_vxinfo,
2041 +       .help_msg       = "conteXt",
2042 +       .action_msg     = "Show Context Info",
2043 +       .enable_mask    = SYSRQ_ENABLE_DUMP,
2044 +};
2045 +#endif
2046 +
2047  /* Key Operations table and lock */
2048  static DEFINE_SPINLOCK(sysrq_key_table_lock);
2049  
2050 @@ -449,7 +465,11 @@ static struct sysrq_key_op *sysrq_key_ta
2051         NULL,                           /* v */
2052         &sysrq_showstate_blocked_op,    /* w */
2053         /* x: May be registered on ppc/powerpc for xmon */
2054 +#ifdef CONFIG_VSERVER_DEBUG
2055 +       &sysrq_showvxinfo_op,           /* x */
2056 +#else
2057         NULL,                           /* x */
2058 +#endif
2059         /* y: May be registered on sparc64 for global register dump */
2060         NULL,                           /* y */
2061         &sysrq_ftrace_dump_op,          /* z */
2062 @@ -464,6 +484,8 @@ static int sysrq_key_table_key2index(int
2063                 retval = key - '0';
2064         else if ((key >= 'a') && (key <= 'z'))
2065                 retval = key + 10 - 'a';
2066 +       else if ((key >= 'A') && (key <= 'Z'))
2067 +               retval = key + 10 - 'A';
2068         else
2069                 retval = -1;
2070         return retval;
2071 diff -NurpP --minimal linux-2.6.38.3/drivers/tty/tty_io.c linux-2.6.38.3-vs2.3.0.37-rc14/drivers/tty/tty_io.c
2072 --- linux-2.6.38.3/drivers/tty/tty_io.c 2011-03-15 18:07:26.000000000 +0100
2073 +++ linux-2.6.38.3-vs2.3.0.37-rc14/drivers/tty/tty_io.c 2011-02-02 22:20:24.000000000 +0100
2074 @@ -107,6 +107,7 @@
2075  
2076  #include <linux/kmod.h>
2077  #include <linux/nsproxy.h>
2078 +#include <linux/vs_pid.h>
2079  
2080  #undef TTY_DEBUG_HANGUP
2081  
2082 @@ -2057,7 +2058,8 @@ static int tiocsti(struct tty_struct *tt
2083         char ch, mbz = 0;
2084         struct tty_ldisc *ld;
2085  
2086 -       if ((current->signal->tty != tty) && !capable(CAP_SYS_ADMIN))
2087 +       if (((current->signal->tty != tty) &&
2088 +               !vx_capable(CAP_SYS_ADMIN, VXC_TIOCSTI)))
2089                 return -EPERM;
2090         if (get_user(ch, p))
2091                 return -EFAULT;
2092 @@ -2345,6 +2347,7 @@ static int tiocspgrp(struct tty_struct *
2093                 return -ENOTTY;
2094         if (get_user(pgrp_nr, p))
2095                 return -EFAULT;
2096 +       pgrp_nr = vx_rmap_pid(pgrp_nr);
2097         if (pgrp_nr < 0)
2098                 return -EINVAL;
2099         rcu_read_lock();
2100 diff -NurpP --minimal linux-2.6.38.3/fs/attr.c linux-2.6.38.3-vs2.3.0.37-rc14/fs/attr.c
2101 --- linux-2.6.38.3/fs/attr.c    2010-10-21 13:07:47.000000000 +0200
2102 +++ linux-2.6.38.3-vs2.3.0.37-rc14/fs/attr.c    2011-01-29 02:01:07.000000000 +0100
2103 @@ -13,6 +13,9 @@
2104  #include <linux/fsnotify.h>
2105  #include <linux/fcntl.h>
2106  #include <linux/security.h>
2107 +#include <linux/proc_fs.h>
2108 +#include <linux/devpts_fs.h>
2109 +#include <linux/vs_tag.h>
2110  
2111  /**
2112   * inode_change_ok - check if attribute changes to an inode are allowed
2113 @@ -73,6 +76,10 @@ int inode_change_ok(const struct inode *
2114                         return -EPERM;
2115         }
2116  
2117 +       /* check for inode tag permission */
2118 +       if (dx_permission(inode, MAY_WRITE))
2119 +               return -EACCES;
2120 +
2121         return 0;
2122  }
2123  EXPORT_SYMBOL(inode_change_ok);
2124 @@ -143,6 +150,8 @@ void setattr_copy(struct inode *inode, c
2125                 inode->i_uid = attr->ia_uid;
2126         if (ia_valid & ATTR_GID)
2127                 inode->i_gid = attr->ia_gid;
2128 +       if ((ia_valid & ATTR_TAG) && IS_TAGGED(inode))
2129 +               inode->i_tag = attr->ia_tag;
2130         if (ia_valid & ATTR_ATIME)
2131                 inode->i_atime = timespec_trunc(attr->ia_atime,
2132                                                 inode->i_sb->s_time_gran);
2133 @@ -170,7 +179,8 @@ int notify_change(struct dentry * dentry
2134         struct timespec now;
2135         unsigned int ia_valid = attr->ia_valid;
2136  
2137 -       if (ia_valid & (ATTR_MODE | ATTR_UID | ATTR_GID | ATTR_TIMES_SET)) {
2138 +       if (ia_valid & (ATTR_MODE | ATTR_UID | ATTR_GID |
2139 +               ATTR_TAG | ATTR_TIMES_SET)) {
2140                 if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
2141                         return -EPERM;
2142         }
2143 diff -NurpP --minimal linux-2.6.38.3/fs/binfmt_aout.c linux-2.6.38.3-vs2.3.0.37-rc14/fs/binfmt_aout.c
2144 --- linux-2.6.38.3/fs/binfmt_aout.c     2010-10-21 13:07:47.000000000 +0200
2145 +++ linux-2.6.38.3-vs2.3.0.37-rc14/fs/binfmt_aout.c     2011-01-29 02:01:07.000000000 +0100
2146 @@ -25,6 +25,7 @@
2147  #include <linux/init.h>
2148  #include <linux/coredump.h>
2149  #include <linux/slab.h>
2150 +#include <linux/vs_memory.h>
2151  
2152  #include <asm/system.h>
2153  #include <asm/uaccess.h>
2154 diff -NurpP --minimal linux-2.6.38.3/fs/binfmt_elf.c linux-2.6.38.3-vs2.3.0.37-rc14/fs/binfmt_elf.c
2155 --- linux-2.6.38.3/fs/binfmt_elf.c      2011-03-15 18:07:31.000000000 +0100
2156 +++ linux-2.6.38.3-vs2.3.0.37-rc14/fs/binfmt_elf.c      2011-01-29 02:01:07.000000000 +0100
2157 @@ -32,6 +32,7 @@
2158  #include <linux/elf.h>
2159  #include <linux/utsname.h>
2160  #include <linux/coredump.h>
2161 +#include <linux/vs_memory.h>
2162  #include <asm/uaccess.h>
2163  #include <asm/param.h>
2164  #include <asm/page.h>
2165 diff -NurpP --minimal linux-2.6.38.3/fs/binfmt_flat.c linux-2.6.38.3-vs2.3.0.37-rc14/fs/binfmt_flat.c
2166 --- linux-2.6.38.3/fs/binfmt_flat.c     2010-08-02 16:52:47.000000000 +0200
2167 +++ linux-2.6.38.3-vs2.3.0.37-rc14/fs/binfmt_flat.c     2011-01-29 02:01:07.000000000 +0100
2168 @@ -35,6 +35,7 @@
2169  #include <linux/init.h>
2170  #include <linux/flat.h>
2171  #include <linux/syscalls.h>
2172 +#include <linux/vs_memory.h>
2173  
2174  #include <asm/byteorder.h>
2175  #include <asm/system.h>
2176 diff -NurpP --minimal linux-2.6.38.3/fs/binfmt_som.c linux-2.6.38.3-vs2.3.0.37-rc14/fs/binfmt_som.c
2177 --- linux-2.6.38.3/fs/binfmt_som.c      2010-02-25 11:52:04.000000000 +0100
2178 +++ linux-2.6.38.3-vs2.3.0.37-rc14/fs/binfmt_som.c      2011-01-29 02:01:07.000000000 +0100
2179 @@ -28,6 +28,7 @@
2180  #include <linux/shm.h>
2181  #include <linux/personality.h>
2182  #include <linux/init.h>
2183 +#include <linux/vs_memory.h>
2184  
2185  #include <asm/uaccess.h>
2186  #include <asm/pgtable.h>
2187 diff -NurpP --minimal linux-2.6.38.3/fs/block_dev.c linux-2.6.38.3-vs2.3.0.37-rc14/fs/block_dev.c
2188 --- linux-2.6.38.3/fs/block_dev.c       2011-03-15 18:07:31.000000000 +0100
2189 +++ linux-2.6.38.3-vs2.3.0.37-rc14/fs/block_dev.c       2011-03-07 16:53:27.000000000 +0100
2190 @@ -25,6 +25,7 @@
2191  #include <linux/namei.h>
2192  #include <linux/log2.h>
2193  #include <linux/kmemleak.h>
2194 +#include <linux/vs_device.h>
2195  #include <asm/uaccess.h>
2196  #include "internal.h"
2197  
2198 @@ -551,6 +552,7 @@ struct block_device *bdget(dev_t dev)
2199                 bdev->bd_invalidated = 0;
2200                 inode->i_mode = S_IFBLK;
2201                 inode->i_rdev = dev;
2202 +               inode->i_mdev = dev;
2203                 inode->i_bdev = bdev;
2204                 inode->i_data.a_ops = &def_blk_aops;
2205                 mapping_set_gfp_mask(&inode->i_data, GFP_USER);
2206 @@ -597,6 +599,11 @@ EXPORT_SYMBOL(bdput);
2207  static struct block_device *bd_acquire(struct inode *inode)
2208  {
2209         struct block_device *bdev;
2210 +       dev_t mdev;
2211 +
2212 +       if (!vs_map_blkdev(inode->i_rdev, &mdev, DATTR_OPEN))
2213 +               return NULL;
2214 +       inode->i_mdev = mdev;
2215  
2216         spin_lock(&bdev_lock);
2217         bdev = inode->i_bdev;
2218 @@ -607,7 +614,7 @@ static struct block_device *bd_acquire(s
2219         }
2220         spin_unlock(&bdev_lock);
2221  
2222 -       bdev = bdget(inode->i_rdev);
2223 +       bdev = bdget(mdev);
2224         if (bdev) {
2225                 spin_lock(&bdev_lock);
2226                 if (!inode->i_bdev) {
2227 diff -NurpP --minimal linux-2.6.38.3/fs/btrfs/ctree.h linux-2.6.38.3-vs2.3.0.37-rc14/fs/btrfs/ctree.h
2228 --- linux-2.6.38.3/fs/btrfs/ctree.h     2011-04-15 10:30:30.000000000 +0200
2229 +++ linux-2.6.38.3-vs2.3.0.37-rc14/fs/btrfs/ctree.h     2011-04-15 10:33:41.000000000 +0200
2230 @@ -587,11 +587,14 @@ struct btrfs_inode_item {
2231         /* modification sequence number for NFS */
2232         __le64 sequence;
2233  
2234 +       __le16 tag;
2235         /*
2236          * a little future expansion, for more than this we can
2237          * just grow the inode item and version it
2238          */
2239 -       __le64 reserved[4];
2240 +       __le16 reserved16;
2241 +       __le32 reserved32;
2242 +       __le64 reserved[3];
2243         struct btrfs_timespec atime;
2244         struct btrfs_timespec ctime;
2245         struct btrfs_timespec mtime;
2246 @@ -1265,6 +1268,8 @@ struct btrfs_root {
2247  #define BTRFS_MOUNT_USER_SUBVOL_RM_ALLOWED (1 << 14)
2248  #define BTRFS_MOUNT_ENOSPC_DEBUG        (1 << 15)
2249  
2250 +#define BTRFS_MOUNT_TAGGED             (1 << 24)
2251 +
2252  #define btrfs_clear_opt(o, opt)                ((o) &= ~BTRFS_MOUNT_##opt)
2253  #define btrfs_set_opt(o, opt)          ((o) |= BTRFS_MOUNT_##opt)
2254  #define btrfs_test_opt(root, opt)      ((root)->fs_info->mount_opt & \
2255 @@ -1487,6 +1492,7 @@ BTRFS_SETGET_FUNCS(inode_block_group, st
2256  BTRFS_SETGET_FUNCS(inode_nlink, struct btrfs_inode_item, nlink, 32);
2257  BTRFS_SETGET_FUNCS(inode_uid, struct btrfs_inode_item, uid, 32);
2258  BTRFS_SETGET_FUNCS(inode_gid, struct btrfs_inode_item, gid, 32);
2259 +BTRFS_SETGET_FUNCS(inode_tag, struct btrfs_inode_item, tag, 16);
2260  BTRFS_SETGET_FUNCS(inode_mode, struct btrfs_inode_item, mode, 32);
2261  BTRFS_SETGET_FUNCS(inode_rdev, struct btrfs_inode_item, rdev, 64);
2262  BTRFS_SETGET_FUNCS(inode_flags, struct btrfs_inode_item, flags, 64);
2263 @@ -1548,6 +1554,10 @@ BTRFS_SETGET_FUNCS(extent_flags, struct 
2264  
2265  BTRFS_SETGET_FUNCS(extent_refs_v0, struct btrfs_extent_item_v0, refs, 32);
2266  
2267 +#define BTRFS_INODE_IXUNLINK           (1 << 24)
2268 +#define BTRFS_INODE_BARRIER            (1 << 25)
2269 +#define BTRFS_INODE_COW                        (1 << 26)
2270 +
2271  
2272  BTRFS_SETGET_FUNCS(tree_block_level, struct btrfs_tree_block_info, level, 8);
2273  
2274 @@ -2557,6 +2567,7 @@ extern const struct dentry_operations bt
2275  long btrfs_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
2276  void btrfs_update_iflags(struct inode *inode);
2277  void btrfs_inherit_iflags(struct inode *inode, struct inode *dir);
2278 +int btrfs_sync_flags(struct inode *inode, int, int);
2279  
2280  /* file.c */
2281  int btrfs_sync_file(struct file *file, int datasync);
2282 diff -NurpP --minimal linux-2.6.38.3/fs/btrfs/disk-io.c linux-2.6.38.3-vs2.3.0.37-rc14/fs/btrfs/disk-io.c
2283 --- linux-2.6.38.3/fs/btrfs/disk-io.c   2011-04-15 10:30:30.000000000 +0200
2284 +++ linux-2.6.38.3-vs2.3.0.37-rc14/fs/btrfs/disk-io.c   2011-04-15 10:33:41.000000000 +0200
2285 @@ -1770,6 +1770,9 @@ struct btrfs_root *open_ctree(struct sup
2286                 goto fail_iput;
2287         }
2288  
2289 +       if (btrfs_test_opt(tree_root, TAGGED))
2290 +               sb->s_flags |= MS_TAGGED;
2291 +
2292         features = btrfs_super_incompat_flags(disk_super) &
2293                 ~BTRFS_FEATURE_INCOMPAT_SUPP;
2294         if (features) {
2295 diff -NurpP --minimal linux-2.6.38.3/fs/btrfs/inode.c linux-2.6.38.3-vs2.3.0.37-rc14/fs/btrfs/inode.c
2296 --- linux-2.6.38.3/fs/btrfs/inode.c     2011-03-15 18:07:31.000000000 +0100
2297 +++ linux-2.6.38.3-vs2.3.0.37-rc14/fs/btrfs/inode.c     2011-03-15 18:15:06.000000000 +0100
2298 @@ -37,6 +37,8 @@
2299  #include <linux/posix_acl.h>
2300  #include <linux/falloc.h>
2301  #include <linux/slab.h>
2302 +#include <linux/vs_tag.h>
2303 +
2304  #include "compat.h"
2305  #include "ctree.h"
2306  #include "disk-io.h"
2307 @@ -2463,6 +2465,8 @@ static void btrfs_read_locked_inode(stru
2308         int maybe_acls;
2309         u64 alloc_group_block;
2310         u32 rdev;
2311 +       uid_t uid;
2312 +       gid_t gid;
2313         int ret;
2314  
2315         path = btrfs_alloc_path();
2316 @@ -2479,8 +2483,13 @@ static void btrfs_read_locked_inode(stru
2317  
2318         inode->i_mode = btrfs_inode_mode(leaf, inode_item);
2319         inode->i_nlink = btrfs_inode_nlink(leaf, inode_item);
2320 -       inode->i_uid = btrfs_inode_uid(leaf, inode_item);
2321 -       inode->i_gid = btrfs_inode_gid(leaf, inode_item);
2322 +
2323 +       uid = btrfs_inode_uid(leaf, inode_item);
2324 +       gid = btrfs_inode_gid(leaf, inode_item);
2325 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
2326 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
2327 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid,
2328 +               btrfs_inode_tag(leaf, inode_item));
2329         btrfs_i_size_write(inode, btrfs_inode_size(leaf, inode_item));
2330  
2331         tspec = btrfs_inode_atime(inode_item);
2332 @@ -2562,8 +2571,15 @@ static void fill_inode_item(struct btrfs
2333                             struct btrfs_inode_item *item,
2334                             struct inode *inode)
2335  {
2336 -       btrfs_set_inode_uid(leaf, item, inode->i_uid);
2337 -       btrfs_set_inode_gid(leaf, item, inode->i_gid);
2338 +       uid_t uid = TAGINO_UID(DX_TAG(inode), inode->i_uid, inode->i_tag);
2339 +       gid_t gid = TAGINO_GID(DX_TAG(inode), inode->i_gid, inode->i_tag);
2340 +
2341 +       btrfs_set_inode_uid(leaf, item, uid);
2342 +       btrfs_set_inode_gid(leaf, item, gid);
2343 +#ifdef CONFIG_TAGGING_INTERN
2344 +       btrfs_set_inode_tag(leaf, item, inode->i_tag);
2345 +#endif
2346 +
2347         btrfs_set_inode_size(leaf, item, BTRFS_I(inode)->disk_i_size);
2348         btrfs_set_inode_mode(leaf, item, inode->i_mode);
2349         btrfs_set_inode_nlink(leaf, item, inode->i_nlink);
2350 @@ -7293,6 +7309,7 @@ static const struct inode_operations btr
2351         .listxattr      = btrfs_listxattr,
2352         .removexattr    = btrfs_removexattr,
2353         .permission     = btrfs_permission,
2354 +       .sync_flags     = btrfs_sync_flags,
2355  };
2356  static const struct inode_operations btrfs_dir_ro_inode_operations = {
2357         .lookup         = btrfs_lookup,
2358 @@ -7367,6 +7384,7 @@ static const struct inode_operations btr
2359         .removexattr    = btrfs_removexattr,
2360         .permission     = btrfs_permission,
2361         .fiemap         = btrfs_fiemap,
2362 +       .sync_flags     = btrfs_sync_flags,
2363  };
2364  static const struct inode_operations btrfs_special_inode_operations = {
2365         .getattr        = btrfs_getattr,
2366 diff -NurpP --minimal linux-2.6.38.3/fs/btrfs/ioctl.c linux-2.6.38.3-vs2.3.0.37-rc14/fs/btrfs/ioctl.c
2367 --- linux-2.6.38.3/fs/btrfs/ioctl.c     2011-04-15 10:30:30.000000000 +0200
2368 +++ linux-2.6.38.3-vs2.3.0.37-rc14/fs/btrfs/ioctl.c     2011-04-15 10:33:41.000000000 +0200
2369 @@ -68,10 +68,13 @@ static unsigned int btrfs_flags_to_ioctl
2370  {
2371         unsigned int iflags = 0;
2372  
2373 -       if (flags & BTRFS_INODE_SYNC)
2374 -               iflags |= FS_SYNC_FL;
2375         if (flags & BTRFS_INODE_IMMUTABLE)
2376                 iflags |= FS_IMMUTABLE_FL;
2377 +       if (flags & BTRFS_INODE_IXUNLINK)
2378 +               iflags |= FS_IXUNLINK_FL;
2379 +
2380 +       if (flags & BTRFS_INODE_SYNC)
2381 +               iflags |= FS_SYNC_FL;
2382         if (flags & BTRFS_INODE_APPEND)
2383                 iflags |= FS_APPEND_FL;
2384         if (flags & BTRFS_INODE_NODUMP)
2385 @@ -81,28 +84,78 @@ static unsigned int btrfs_flags_to_ioctl
2386         if (flags & BTRFS_INODE_DIRSYNC)
2387                 iflags |= FS_DIRSYNC_FL;
2388  
2389 +       if (flags & BTRFS_INODE_BARRIER)
2390 +               iflags |= FS_BARRIER_FL;
2391 +       if (flags & BTRFS_INODE_COW)
2392 +               iflags |= FS_COW_FL;
2393         return iflags;
2394  }
2395  
2396  /*
2397 - * Update inode->i_flags based on the btrfs internal flags.
2398 + * Update inode->i_(v)flags based on the btrfs internal flags.
2399   */
2400  void btrfs_update_iflags(struct inode *inode)
2401  {
2402         struct btrfs_inode *ip = BTRFS_I(inode);
2403  
2404 -       inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
2405 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
2406 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
2407  
2408 -       if (ip->flags & BTRFS_INODE_SYNC)
2409 -               inode->i_flags |= S_SYNC;
2410         if (ip->flags & BTRFS_INODE_IMMUTABLE)
2411                 inode->i_flags |= S_IMMUTABLE;
2412 +       if (ip->flags & BTRFS_INODE_IXUNLINK)
2413 +               inode->i_flags |= S_IXUNLINK;
2414 +
2415 +       if (ip->flags & BTRFS_INODE_SYNC)
2416 +               inode->i_flags |= S_SYNC;
2417         if (ip->flags & BTRFS_INODE_APPEND)
2418                 inode->i_flags |= S_APPEND;
2419         if (ip->flags & BTRFS_INODE_NOATIME)
2420                 inode->i_flags |= S_NOATIME;
2421         if (ip->flags & BTRFS_INODE_DIRSYNC)
2422                 inode->i_flags |= S_DIRSYNC;
2423 +
2424 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
2425 +
2426 +       if (ip->flags & BTRFS_INODE_BARRIER)
2427 +               inode->i_vflags |= V_BARRIER;
2428 +       if (ip->flags & BTRFS_INODE_COW)
2429 +               inode->i_vflags |= V_COW;
2430 +}
2431 +
2432 +/*
2433 + * Update btrfs internal flags from inode->i_(v)flags.
2434 + */
2435 +void btrfs_update_flags(struct inode *inode)
2436 +{
2437 +       struct btrfs_inode *ip = BTRFS_I(inode);
2438 +
2439 +       unsigned int flags = inode->i_flags;
2440 +       unsigned int vflags = inode->i_vflags;
2441 +
2442 +       ip->flags &= ~(BTRFS_INODE_SYNC | BTRFS_INODE_APPEND |
2443 +                       BTRFS_INODE_IMMUTABLE | BTRFS_INODE_IXUNLINK |
2444 +                       BTRFS_INODE_NOATIME | BTRFS_INODE_DIRSYNC |
2445 +                       BTRFS_INODE_BARRIER | BTRFS_INODE_COW);
2446 +
2447 +       if (flags & S_IMMUTABLE)
2448 +               ip->flags |= BTRFS_INODE_IMMUTABLE;
2449 +       if (flags & S_IXUNLINK)
2450 +               ip->flags |= BTRFS_INODE_IXUNLINK;
2451 +
2452 +       if (flags & S_SYNC)
2453 +               ip->flags |= BTRFS_INODE_SYNC;
2454 +       if (flags & S_APPEND)
2455 +               ip->flags |= BTRFS_INODE_APPEND;
2456 +       if (flags & S_NOATIME)
2457 +               ip->flags |= BTRFS_INODE_NOATIME;
2458 +       if (flags & S_DIRSYNC)
2459 +               ip->flags |= BTRFS_INODE_DIRSYNC;
2460 +
2461 +       if (vflags & V_BARRIER)
2462 +               ip->flags |= BTRFS_INODE_BARRIER;
2463 +       if (vflags & V_COW)
2464 +               ip->flags |= BTRFS_INODE_COW;
2465  }
2466  
2467  /*
2468 @@ -120,7 +173,7 @@ void btrfs_inherit_iflags(struct inode *
2469         flags = BTRFS_I(dir)->flags;
2470  
2471         if (S_ISREG(inode->i_mode))
2472 -               flags &= ~BTRFS_INODE_DIRSYNC;
2473 +               flags &= ~(BTRFS_INODE_DIRSYNC | BTRFS_INODE_BARRIER);
2474         else if (!S_ISDIR(inode->i_mode))
2475                 flags &= (BTRFS_INODE_NODUMP | BTRFS_INODE_NOATIME);
2476  
2477 @@ -128,6 +181,30 @@ void btrfs_inherit_iflags(struct inode *
2478         btrfs_update_iflags(inode);
2479  }
2480  
2481 +int btrfs_sync_flags(struct inode *inode, int flags, int vflags)
2482 +{
2483 +       struct btrfs_inode *ip = BTRFS_I(inode);
2484 +       struct btrfs_root *root = ip->root;
2485 +       struct btrfs_trans_handle *trans;
2486 +       int ret;
2487 +
2488 +       trans = btrfs_join_transaction(root, 1);
2489 +       BUG_ON(!trans);
2490 +
2491 +       inode->i_flags = flags;
2492 +       inode->i_vflags = vflags;
2493 +       btrfs_update_flags(inode);
2494 +
2495 +       ret = btrfs_update_inode(trans, root, inode);
2496 +       BUG_ON(ret);
2497 +
2498 +       btrfs_update_iflags(inode);
2499 +       inode->i_ctime = CURRENT_TIME;
2500 +       btrfs_end_transaction(trans, root);
2501 +
2502 +       return 0;
2503 +}
2504 +
2505  static int btrfs_ioctl_getflags(struct file *file, void __user *arg)
2506  {
2507         struct btrfs_inode *ip = BTRFS_I(file->f_path.dentry->d_inode);
2508 @@ -153,6 +230,7 @@ static int btrfs_ioctl_setflags(struct f
2509         if (copy_from_user(&flags, arg, sizeof(flags)))
2510                 return -EFAULT;
2511  
2512 +       /* maybe add FS_IXUNLINK_FL ? */
2513         if (flags & ~(FS_IMMUTABLE_FL | FS_APPEND_FL | \
2514                       FS_NOATIME_FL | FS_NODUMP_FL | \
2515                       FS_SYNC_FL | FS_DIRSYNC_FL))
2516 @@ -165,7 +243,8 @@ static int btrfs_ioctl_setflags(struct f
2517  
2518         flags = btrfs_mask_flags(inode->i_mode, flags);
2519         oldflags = btrfs_flags_to_ioctl(ip->flags);
2520 -       if ((flags ^ oldflags) & (FS_APPEND_FL | FS_IMMUTABLE_FL)) {
2521 +       if ((flags ^ oldflags) & (FS_APPEND_FL |
2522 +               FS_IMMUTABLE_FL | FS_IXUNLINK_FL)) {
2523                 if (!capable(CAP_LINUX_IMMUTABLE)) {
2524                         ret = -EPERM;
2525                         goto out_unlock;
2526 @@ -176,14 +255,19 @@ static int btrfs_ioctl_setflags(struct f
2527         if (ret)
2528                 goto out_unlock;
2529  
2530 -       if (flags & FS_SYNC_FL)
2531 -               ip->flags |= BTRFS_INODE_SYNC;
2532 -       else
2533 -               ip->flags &= ~BTRFS_INODE_SYNC;
2534         if (flags & FS_IMMUTABLE_FL)
2535                 ip->flags |= BTRFS_INODE_IMMUTABLE;
2536         else
2537                 ip->flags &= ~BTRFS_INODE_IMMUTABLE;
2538 +       if (flags & FS_IXUNLINK_FL)
2539 +               ip->flags |= BTRFS_INODE_IXUNLINK;
2540 +       else
2541 +               ip->flags &= ~BTRFS_INODE_IXUNLINK;
2542 +
2543 +       if (flags & FS_SYNC_FL)
2544 +               ip->flags |= BTRFS_INODE_SYNC;
2545 +       else
2546 +               ip->flags &= ~BTRFS_INODE_SYNC;
2547         if (flags & FS_APPEND_FL)
2548                 ip->flags |= BTRFS_INODE_APPEND;
2549         else
2550 diff -NurpP --minimal linux-2.6.38.3/fs/btrfs/super.c linux-2.6.38.3-vs2.3.0.37-rc14/fs/btrfs/super.c
2551 --- linux-2.6.38.3/fs/btrfs/super.c     2011-03-15 18:07:31.000000000 +0100
2552 +++ linux-2.6.38.3-vs2.3.0.37-rc14/fs/btrfs/super.c     2011-03-07 17:04:18.000000000 +0100
2553 @@ -155,8 +155,8 @@ enum {
2554         Opt_nossd, Opt_ssd_spread, Opt_thread_pool, Opt_noacl, Opt_compress,
2555         Opt_compress_type, Opt_compress_force, Opt_compress_force_type,
2556         Opt_notreelog, Opt_ratio, Opt_flushoncommit, Opt_discard,
2557 -       Opt_space_cache, Opt_clear_cache, Opt_user_subvol_rm_allowed,
2558 -       Opt_enospc_debug, Opt_err,
2559 +       Opt_space_cache, Opt_clear_cache, Opt_user_subvol_rm_allowed,
2560 +       Opt_enospc_debug, Opt_tag, Opt_notag, Opt_tagid, Opt_err,
2561  };
2562  
2563  static match_table_t tokens = {
2564 @@ -186,6 +186,9 @@ static match_table_t tokens = {
2565         {Opt_clear_cache, "clear_cache"},
2566         {Opt_user_subvol_rm_allowed, "user_subvol_rm_allowed"},
2567         {Opt_enospc_debug, "enospc_debug"},
2568 +       {Opt_tag, "tag"},
2569 +       {Opt_notag, "notag"},
2570 +       {Opt_tagid, "tagid=%u"},
2571         {Opt_err, NULL},
2572  };
2573  
2574 @@ -363,6 +366,22 @@ int btrfs_parse_options(struct btrfs_roo
2575                 case Opt_enospc_debug:
2576                         btrfs_set_opt(info->mount_opt, ENOSPC_DEBUG);
2577                         break;
2578 +#ifndef CONFIG_TAGGING_NONE
2579 +               case Opt_tag:
2580 +                       printk(KERN_INFO "btrfs: use tagging\n");
2581 +                       btrfs_set_opt(info->mount_opt, TAGGED);
2582 +                       break;
2583 +               case Opt_notag:
2584 +                       printk(KERN_INFO "btrfs: disabled tagging\n");
2585 +                       btrfs_clear_opt(info->mount_opt, TAGGED);
2586 +                       break;
2587 +#endif
2588 +#ifdef CONFIG_PROPAGATE
2589 +               case Opt_tagid:
2590 +                       /* use args[0] */
2591 +                       btrfs_set_opt(info->mount_opt, TAGGED);
2592 +                       break;
2593 +#endif
2594                 case Opt_err:
2595                         printk(KERN_INFO "btrfs: unrecognized mount option "
2596                                "'%s'\n", p);
2597 @@ -841,6 +860,12 @@ static int btrfs_remount(struct super_bl
2598         if (ret)
2599                 return -EINVAL;
2600  
2601 +       if (btrfs_test_opt(root, TAGGED) && !(sb->s_flags & MS_TAGGED)) {
2602 +               printk("btrfs: %s: tagging not permitted on remount.\n",
2603 +                       sb->s_id);
2604 +               return -EINVAL;
2605 +       }
2606 +
2607         if ((*flags & MS_RDONLY) == (sb->s_flags & MS_RDONLY))
2608                 return 0;
2609  
2610 diff -NurpP --minimal linux-2.6.38.3/fs/char_dev.c linux-2.6.38.3-vs2.3.0.37-rc14/fs/char_dev.c
2611 --- linux-2.6.38.3/fs/char_dev.c        2011-03-15 18:07:31.000000000 +0100
2612 +++ linux-2.6.38.3-vs2.3.0.37-rc14/fs/char_dev.c        2011-01-29 02:01:07.000000000 +0100
2613 @@ -21,6 +21,8 @@
2614  #include <linux/mutex.h>
2615  #include <linux/backing-dev.h>
2616  #include <linux/tty.h>
2617 +#include <linux/vs_context.h>
2618 +#include <linux/vs_device.h>
2619  
2620  #include "internal.h"
2621  
2622 @@ -371,14 +373,21 @@ static int chrdev_open(struct inode *ino
2623         struct cdev *p;
2624         struct cdev *new = NULL;
2625         int ret = 0;
2626 +       dev_t mdev;
2627 +
2628 +       if (!vs_map_chrdev(inode->i_rdev, &mdev, DATTR_OPEN))
2629 +               return -EPERM;
2630 +       inode->i_mdev = mdev;
2631  
2632         spin_lock(&cdev_lock);
2633         p = inode->i_cdev;
2634         if (!p) {
2635                 struct kobject *kobj;
2636                 int idx;
2637 +
2638                 spin_unlock(&cdev_lock);
2639 -               kobj = kobj_lookup(cdev_map, inode->i_rdev, &idx);
2640 +
2641 +               kobj = kobj_lookup(cdev_map, mdev, &idx);
2642                 if (!kobj)
2643                         return -ENXIO;
2644                 new = container_of(kobj, struct cdev, kobj);
2645 diff -NurpP --minimal linux-2.6.38.3/fs/dcache.c linux-2.6.38.3-vs2.3.0.37-rc14/fs/dcache.c
2646 --- linux-2.6.38.3/fs/dcache.c  2011-04-15 10:30:30.000000000 +0200
2647 +++ linux-2.6.38.3-vs2.3.0.37-rc14/fs/dcache.c  2011-03-28 15:00:13.000000000 +0200
2648 @@ -35,6 +35,7 @@
2649  #include <linux/hardirq.h>
2650  #include <linux/bit_spinlock.h>
2651  #include <linux/rculist_bl.h>
2652 +#include <linux/vs_limit.h>
2653  #include "internal.h"
2654  
2655  /*
2656 @@ -500,6 +501,8 @@ int d_invalidate(struct dentry * dentry)
2657                 spin_lock(&dentry->d_lock);
2658         }
2659  
2660 +       vx_dentry_dec(dentry);
2661 +
2662         /*
2663          * Somebody else still using it?
2664          *
2665 @@ -527,6 +530,7 @@ EXPORT_SYMBOL(d_invalidate);
2666  static inline void __dget_dlock(struct dentry *dentry)
2667  {
2668         dentry->d_count++;
2669 +       vx_dentry_inc(dentry);
2670  }
2671  
2672  static inline void __dget(struct dentry *dentry)
2673 @@ -1283,6 +1287,9 @@ struct dentry *d_alloc(struct dentry * p
2674         struct dentry *dentry;
2675         char *dname;
2676  
2677 +       if (!vx_dentry_avail(1))
2678 +               return NULL;
2679 +
2680         dentry = kmem_cache_alloc(dentry_cache, GFP_KERNEL);
2681         if (!dentry)
2682                 return NULL;
2683 @@ -1304,6 +1311,7 @@ struct dentry *d_alloc(struct dentry * p
2684         dname[name->len] = 0;
2685  
2686         dentry->d_count = 1;
2687 +       vx_dentry_inc(dentry);
2688         dentry->d_flags = DCACHE_UNHASHED;
2689         spin_lock_init(&dentry->d_lock);
2690         seqcount_init(&dentry->d_seq);
2691 @@ -1965,6 +1973,7 @@ struct dentry *__d_lookup(struct dentry 
2692                 }
2693  
2694                 dentry->d_count++;
2695 +               vx_dentry_inc(dentry);
2696                 found = dentry;
2697                 spin_unlock(&dentry->d_lock);
2698                 break;
2699 diff -NurpP --minimal linux-2.6.38.3/fs/devpts/inode.c linux-2.6.38.3-vs2.3.0.37-rc14/fs/devpts/inode.c
2700 --- linux-2.6.38.3/fs/devpts/inode.c    2011-01-05 21:50:22.000000000 +0100
2701 +++ linux-2.6.38.3-vs2.3.0.37-rc14/fs/devpts/inode.c    2011-03-17 02:17:19.000000000 +0100
2702 @@ -25,6 +25,7 @@
2703  #include <linux/parser.h>
2704  #include <linux/fsnotify.h>
2705  #include <linux/seq_file.h>
2706 +#include <linux/vs_base.h>
2707  
2708  #define DEVPTS_DEFAULT_MODE 0600
2709  /*
2710 @@ -36,6 +37,20 @@
2711  #define DEVPTS_DEFAULT_PTMX_MODE 0000
2712  #define PTMX_MINOR     2
2713  
2714 +static int devpts_permission(struct inode *inode, int mask, unsigned int flags)
2715 +{
2716 +       int ret = -EACCES;
2717 +
2718 +       /* devpts is xid tagged */
2719 +       if (vx_check((xid_t)inode->i_tag, VS_WATCH_P | VS_IDENT))
2720 +               ret = generic_permission(inode, mask, flags, NULL);
2721 +       return ret;
2722 +}
2723 +
2724 +static struct inode_operations devpts_file_inode_operations = {
2725 +       .permission     = devpts_permission,
2726 +};
2727 +
2728  extern int pty_limit;                  /* Config limit on Unix98 ptys */
2729  static DEFINE_MUTEX(allocated_ptys_lock);
2730  
2731 @@ -263,6 +278,34 @@ static int devpts_show_options(struct se
2732         return 0;
2733  }
2734  
2735 +static int devpts_filter(struct dentry *de)
2736 +{
2737 +       xid_t xid = 0;
2738 +
2739 +       /* devpts is xid tagged */
2740 +       if (de && de->d_inode)
2741 +               xid = (xid_t)de->d_inode->i_tag;
2742 +#ifdef CONFIG_VSERVER_WARN_DEVPTS
2743 +       else
2744 +               vxwprintk_task(1, "devpts " VS_Q("%.*s") " without inode.",
2745 +                       de->d_name.len, de->d_name.name);
2746 +#endif
2747 +       return vx_check(xid, VS_WATCH_P | VS_IDENT);
2748 +}
2749 +
2750 +static int devpts_readdir(struct file * filp, void * dirent, filldir_t filldir)
2751 +{
2752 +       return dcache_readdir_filter(filp, dirent, filldir, devpts_filter);
2753 +}
2754 +
2755 +static struct file_operations devpts_dir_operations = {
2756 +       .open           = dcache_dir_open,
2757 +       .release        = dcache_dir_close,
2758 +       .llseek         = dcache_dir_lseek,
2759 +       .read           = generic_read_dir,
2760 +       .readdir        = devpts_readdir,
2761 +};
2762 +
2763  static const struct super_operations devpts_sops = {
2764         .statfs         = simple_statfs,
2765         .remount_fs     = devpts_remount,
2766 @@ -302,12 +345,15 @@ devpts_fill_super(struct super_block *s,
2767         inode = new_inode(s);
2768         if (!inode)
2769                 goto free_fsi;
2770 +
2771         inode->i_ino = 1;
2772         inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
2773         inode->i_mode = S_IFDIR | S_IRUGO | S_IXUGO | S_IWUSR;
2774         inode->i_op = &simple_dir_inode_operations;
2775 -       inode->i_fop = &simple_dir_operations;
2776 +       inode->i_fop = &devpts_dir_operations;
2777         inode->i_nlink = 2;
2778 +       /* devpts is xid tagged */
2779 +       inode->i_tag = (tag_t)vx_current_xid();
2780  
2781         s->s_root = d_alloc_root(inode);
2782         if (s->s_root)
2783 @@ -493,6 +539,9 @@ int devpts_pty_new(struct inode *ptmx_in
2784         inode->i_gid = opts->setgid ? opts->gid : current_fsgid();
2785         inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
2786         init_special_inode(inode, S_IFCHR|opts->mode, device);
2787 +       /* devpts is xid tagged */
2788 +       inode->i_tag = (tag_t)vx_current_xid();
2789 +       inode->i_op = &devpts_file_inode_operations;
2790         inode->i_private = tty;
2791         tty->driver_data = inode;
2792  
2793 diff -NurpP --minimal linux-2.6.38.3/fs/ext2/balloc.c linux-2.6.38.3-vs2.3.0.37-rc14/fs/ext2/balloc.c
2794 --- linux-2.6.38.3/fs/ext2/balloc.c     2011-01-05 21:50:22.000000000 +0100
2795 +++ linux-2.6.38.3-vs2.3.0.37-rc14/fs/ext2/balloc.c     2011-01-29 02:01:07.000000000 +0100
2796 @@ -701,7 +701,6 @@ ext2_try_to_allocate(struct super_block 
2797                         start = 0;
2798                 end = EXT2_BLOCKS_PER_GROUP(sb);
2799         }
2800 -
2801         BUG_ON(start > EXT2_BLOCKS_PER_GROUP(sb));
2802  
2803  repeat:
2804 diff -NurpP --minimal linux-2.6.38.3/fs/ext2/ext2.h linux-2.6.38.3-vs2.3.0.37-rc14/fs/ext2/ext2.h
2805 --- linux-2.6.38.3/fs/ext2/ext2.h       2011-01-05 21:50:22.000000000 +0100
2806 +++ linux-2.6.38.3-vs2.3.0.37-rc14/fs/ext2/ext2.h       2011-01-29 02:01:07.000000000 +0100
2807 @@ -126,6 +126,7 @@ extern void ext2_set_inode_flags(struct 
2808  extern void ext2_get_inode_flags(struct ext2_inode_info *);
2809  extern int ext2_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
2810                        u64 start, u64 len);
2811 +extern int ext2_sync_flags(struct inode *, int, int);
2812  
2813  /* ioctl.c */
2814  extern long ext2_ioctl(struct file *, unsigned int, unsigned long);
2815 diff -NurpP --minimal linux-2.6.38.3/fs/ext2/file.c linux-2.6.38.3-vs2.3.0.37-rc14/fs/ext2/file.c
2816 --- linux-2.6.38.3/fs/ext2/file.c       2010-08-02 16:52:48.000000000 +0200
2817 +++ linux-2.6.38.3-vs2.3.0.37-rc14/fs/ext2/file.c       2011-01-29 02:01:07.000000000 +0100
2818 @@ -104,4 +104,5 @@ const struct inode_operations ext2_file_
2819         .setattr        = ext2_setattr,
2820         .check_acl      = ext2_check_acl,
2821         .fiemap         = ext2_fiemap,
2822 +       .sync_flags     = ext2_sync_flags,
2823  };
2824 diff -NurpP --minimal linux-2.6.38.3/fs/ext2/ialloc.c linux-2.6.38.3-vs2.3.0.37-rc14/fs/ext2/ialloc.c
2825 --- linux-2.6.38.3/fs/ext2/ialloc.c     2010-10-21 13:07:48.000000000 +0200
2826 +++ linux-2.6.38.3-vs2.3.0.37-rc14/fs/ext2/ialloc.c     2011-01-29 02:01:07.000000000 +0100
2827 @@ -17,6 +17,7 @@
2828  #include <linux/backing-dev.h>
2829  #include <linux/buffer_head.h>
2830  #include <linux/random.h>
2831 +#include <linux/vs_tag.h>
2832  #include "ext2.h"
2833  #include "xattr.h"
2834  #include "acl.h"
2835 @@ -548,6 +549,7 @@ got:
2836                 inode->i_mode = mode;
2837                 inode->i_uid = current_fsuid();
2838                 inode->i_gid = dir->i_gid;
2839 +               inode->i_tag = dx_current_fstag(sb);
2840         } else
2841                 inode_init_owner(inode, dir, mode);
2842  
2843 diff -NurpP --minimal linux-2.6.38.3/fs/ext2/inode.c linux-2.6.38.3-vs2.3.0.37-rc14/fs/ext2/inode.c
2844 --- linux-2.6.38.3/fs/ext2/inode.c      2011-01-05 21:50:22.000000000 +0100
2845 +++ linux-2.6.38.3-vs2.3.0.37-rc14/fs/ext2/inode.c      2011-01-29 02:01:07.000000000 +0100
2846 @@ -32,6 +32,7 @@
2847  #include <linux/mpage.h>
2848  #include <linux/fiemap.h>
2849  #include <linux/namei.h>
2850 +#include <linux/vs_tag.h>
2851  #include "ext2.h"
2852  #include "acl.h"
2853  #include "xip.h"
2854 @@ -1169,7 +1170,7 @@ static void ext2_truncate_blocks(struct 
2855                 return;
2856         if (ext2_inode_is_fast_symlink(inode))
2857                 return;
2858 -       if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
2859 +       if (IS_APPEND(inode) || IS_IXORUNLINK(inode))
2860                 return;
2861         __ext2_truncate_blocks(inode, offset);
2862  }
2863 @@ -1258,36 +1259,61 @@ void ext2_set_inode_flags(struct inode *
2864  {
2865         unsigned int flags = EXT2_I(inode)->i_flags;
2866  
2867 -       inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
2868 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
2869 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
2870 +
2871 +
2872 +       if (flags & EXT2_IMMUTABLE_FL)
2873 +               inode->i_flags |= S_IMMUTABLE;
2874 +       if (flags & EXT2_IXUNLINK_FL)
2875 +               inode->i_flags |= S_IXUNLINK;
2876 +
2877         if (flags & EXT2_SYNC_FL)
2878                 inode->i_flags |= S_SYNC;
2879         if (flags & EXT2_APPEND_FL)
2880                 inode->i_flags |= S_APPEND;
2881 -       if (flags & EXT2_IMMUTABLE_FL)
2882 -               inode->i_flags |= S_IMMUTABLE;
2883         if (flags & EXT2_NOATIME_FL)
2884                 inode->i_flags |= S_NOATIME;
2885         if (flags & EXT2_DIRSYNC_FL)
2886                 inode->i_flags |= S_DIRSYNC;
2887 +
2888 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
2889 +
2890 +       if (flags & EXT2_BARRIER_FL)
2891 +               inode->i_vflags |= V_BARRIER;
2892 +       if (flags & EXT2_COW_FL)
2893 +               inode->i_vflags |= V_COW;
2894  }
2895  
2896  /* Propagate flags from i_flags to EXT2_I(inode)->i_flags */
2897  void ext2_get_inode_flags(struct ext2_inode_info *ei)
2898  {
2899         unsigned int flags = ei->vfs_inode.i_flags;
2900 +       unsigned int vflags = ei->vfs_inode.i_vflags;
2901 +
2902 +       ei->i_flags &= ~(EXT2_SYNC_FL | EXT2_APPEND_FL |
2903 +                       EXT2_IMMUTABLE_FL | EXT2_IXUNLINK_FL |
2904 +                       EXT2_NOATIME_FL | EXT2_DIRSYNC_FL |
2905 +                       EXT2_BARRIER_FL | EXT2_COW_FL);
2906 +
2907 +       if (flags & S_IMMUTABLE)
2908 +               ei->i_flags |= EXT2_IMMUTABLE_FL;
2909 +       if (flags & S_IXUNLINK)
2910 +               ei->i_flags |= EXT2_IXUNLINK_FL;
2911  
2912 -       ei->i_flags &= ~(EXT2_SYNC_FL|EXT2_APPEND_FL|
2913 -                       EXT2_IMMUTABLE_FL|EXT2_NOATIME_FL|EXT2_DIRSYNC_FL);
2914         if (flags & S_SYNC)
2915                 ei->i_flags |= EXT2_SYNC_FL;
2916         if (flags & S_APPEND)
2917                 ei->i_flags |= EXT2_APPEND_FL;
2918 -       if (flags & S_IMMUTABLE)
2919 -               ei->i_flags |= EXT2_IMMUTABLE_FL;
2920         if (flags & S_NOATIME)
2921                 ei->i_flags |= EXT2_NOATIME_FL;
2922         if (flags & S_DIRSYNC)
2923                 ei->i_flags |= EXT2_DIRSYNC_FL;
2924 +
2925 +       if (vflags & V_BARRIER)
2926 +               ei->i_flags |= EXT2_BARRIER_FL;
2927 +       if (vflags & V_COW)
2928 +               ei->i_flags |= EXT2_COW_FL;
2929  }
2930  
2931  struct inode *ext2_iget (struct super_block *sb, unsigned long ino)
2932 @@ -1297,6 +1323,8 @@ struct inode *ext2_iget (struct super_bl
2933         struct ext2_inode *raw_inode;
2934         struct inode *inode;
2935         long ret = -EIO;
2936 +       uid_t uid;
2937 +       gid_t gid;
2938         int n;
2939  
2940         inode = iget_locked(sb, ino);
2941 @@ -1315,12 +1343,17 @@ struct inode *ext2_iget (struct super_bl
2942         }
2943  
2944         inode->i_mode = le16_to_cpu(raw_inode->i_mode);
2945 -       inode->i_uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
2946 -       inode->i_gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
2947 +       uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
2948 +       gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
2949         if (!(test_opt (inode->i_sb, NO_UID32))) {
2950 -               inode->i_uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
2951 -               inode->i_gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
2952 +               uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
2953 +               gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
2954         }
2955 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
2956 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
2957 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid,
2958 +               le16_to_cpu(raw_inode->i_raw_tag));
2959 +
2960         inode->i_nlink = le16_to_cpu(raw_inode->i_links_count);
2961         inode->i_size = le32_to_cpu(raw_inode->i_size);
2962         inode->i_atime.tv_sec = (signed)le32_to_cpu(raw_inode->i_atime);
2963 @@ -1418,8 +1451,8 @@ static int __ext2_write_inode(struct ino
2964         struct ext2_inode_info *ei = EXT2_I(inode);
2965         struct super_block *sb = inode->i_sb;
2966         ino_t ino = inode->i_ino;
2967 -       uid_t uid = inode->i_uid;
2968 -       gid_t gid = inode->i_gid;
2969 +       uid_t uid = TAGINO_UID(DX_TAG(inode), inode->i_uid, inode->i_tag);
2970 +       gid_t gid = TAGINO_GID(DX_TAG(inode), inode->i_gid, inode->i_tag);
2971         struct buffer_head * bh;
2972         struct ext2_inode * raw_inode = ext2_get_inode(sb, ino, &bh);
2973         int n;
2974 @@ -1455,6 +1488,9 @@ static int __ext2_write_inode(struct ino
2975                 raw_inode->i_uid_high = 0;
2976                 raw_inode->i_gid_high = 0;
2977         }
2978 +#ifdef CONFIG_TAGGING_INTERN
2979 +       raw_inode->i_raw_tag = cpu_to_le16(inode->i_tag);
2980 +#endif
2981         raw_inode->i_links_count = cpu_to_le16(inode->i_nlink);
2982         raw_inode->i_size = cpu_to_le32(inode->i_size);
2983         raw_inode->i_atime = cpu_to_le32(inode->i_atime.tv_sec);
2984 @@ -1535,7 +1571,8 @@ int ext2_setattr(struct dentry *dentry, 
2985         if (is_quota_modification(inode, iattr))
2986                 dquot_initialize(inode);
2987         if ((iattr->ia_valid & ATTR_UID && iattr->ia_uid != inode->i_uid) ||
2988 -           (iattr->ia_valid & ATTR_GID && iattr->ia_gid != inode->i_gid)) {
2989 +           (iattr->ia_valid & ATTR_GID && iattr->ia_gid != inode->i_gid) ||
2990 +           (iattr->ia_valid & ATTR_TAG && iattr->ia_tag != inode->i_tag)) {
2991                 error = dquot_transfer(inode, iattr);
2992                 if (error)
2993                         return error;
2994 diff -NurpP --minimal linux-2.6.38.3/fs/ext2/ioctl.c linux-2.6.38.3-vs2.3.0.37-rc14/fs/ext2/ioctl.c
2995 --- linux-2.6.38.3/fs/ext2/ioctl.c      2009-09-10 15:26:21.000000000 +0200
2996 +++ linux-2.6.38.3-vs2.3.0.37-rc14/fs/ext2/ioctl.c      2011-01-29 02:01:07.000000000 +0100
2997 @@ -17,6 +17,16 @@
2998  #include <asm/uaccess.h>
2999  
3000  
3001 +int ext2_sync_flags(struct inode *inode, int flags, int vflags)
3002 +{
3003 +       inode->i_flags = flags;
3004 +       inode->i_vflags = vflags;
3005 +       ext2_get_inode_flags(EXT2_I(inode));
3006 +       inode->i_ctime = CURRENT_TIME_SEC;
3007 +       mark_inode_dirty(inode);
3008 +       return 0;
3009 +}
3010 +
3011  long ext2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
3012  {
3013         struct inode *inode = filp->f_dentry->d_inode;
3014 @@ -51,6 +61,11 @@ long ext2_ioctl(struct file *filp, unsig
3015  
3016                 flags = ext2_mask_flags(inode->i_mode, flags);
3017  
3018 +               if (IS_BARRIER(inode)) {
3019 +                       vxwprintk_task(1, "messing with the barrier.");
3020 +                       return -EACCES;
3021 +               }
3022 +
3023                 mutex_lock(&inode->i_mutex);
3024                 /* Is it quota file? Do not allow user to mess with it */
3025                 if (IS_NOQUOTA(inode)) {
3026 @@ -66,7 +81,9 @@ long ext2_ioctl(struct file *filp, unsig
3027                  *
3028                  * This test looks nicer. Thanks to Pauline Middelink
3029                  */
3030 -               if ((flags ^ oldflags) & (EXT2_APPEND_FL | EXT2_IMMUTABLE_FL)) {
3031 +               if ((oldflags & EXT2_IMMUTABLE_FL) ||
3032 +                       ((flags ^ oldflags) & (EXT2_APPEND_FL |
3033 +                       EXT2_IMMUTABLE_FL | EXT2_IXUNLINK_FL))) {
3034                         if (!capable(CAP_LINUX_IMMUTABLE)) {
3035                                 mutex_unlock(&inode->i_mutex);
3036                                 ret = -EPERM;
3037 @@ -74,7 +91,7 @@ long ext2_ioctl(struct file *filp, unsig
3038                         }
3039                 }
3040  
3041 -               flags = flags & EXT2_FL_USER_MODIFIABLE;
3042 +               flags &= EXT2_FL_USER_MODIFIABLE;
3043                 flags |= oldflags & ~EXT2_FL_USER_MODIFIABLE;
3044                 ei->i_flags = flags;
3045                 mutex_unlock(&inode->i_mutex);
3046 diff -NurpP --minimal linux-2.6.38.3/fs/ext2/namei.c linux-2.6.38.3-vs2.3.0.37-rc14/fs/ext2/namei.c
3047 --- linux-2.6.38.3/fs/ext2/namei.c      2011-03-15 18:07:31.000000000 +0100
3048 +++ linux-2.6.38.3-vs2.3.0.37-rc14/fs/ext2/namei.c      2011-03-10 17:21:19.000000000 +0100
3049 @@ -32,6 +32,7 @@
3050  
3051  #include <linux/pagemap.h>
3052  #include <linux/quotaops.h>
3053 +#include <linux/vs_tag.h>
3054  #include "ext2.h"
3055  #include "xattr.h"
3056  #include "acl.h"
3057 @@ -75,6 +76,7 @@ static struct dentry *ext2_lookup(struct
3058                                 return ERR_PTR(-EIO);
3059                         } else {
3060                                 return ERR_CAST(inode);
3061 +               dx_propagate_tag(nd, inode);
3062                         }
3063                 }
3064         }
3065 @@ -413,6 +415,7 @@ const struct inode_operations ext2_dir_i
3066  #endif
3067         .setattr        = ext2_setattr,
3068         .check_acl      = ext2_check_acl,
3069 +       .sync_flags     = ext2_sync_flags,
3070  };
3071  
3072  const struct inode_operations ext2_special_inode_operations = {
3073 diff -NurpP --minimal linux-2.6.38.3/fs/ext2/super.c linux-2.6.38.3-vs2.3.0.37-rc14/fs/ext2/super.c
3074 --- linux-2.6.38.3/fs/ext2/super.c      2011-03-15 18:07:31.000000000 +0100
3075 +++ linux-2.6.38.3-vs2.3.0.37-rc14/fs/ext2/super.c      2011-01-29 02:01:07.000000000 +0100
3076 @@ -394,7 +394,8 @@ enum {
3077         Opt_err_ro, Opt_nouid32, Opt_nocheck, Opt_debug,
3078         Opt_oldalloc, Opt_orlov, Opt_nobh, Opt_user_xattr, Opt_nouser_xattr,
3079         Opt_acl, Opt_noacl, Opt_xip, Opt_ignore, Opt_err, Opt_quota,
3080 -       Opt_usrquota, Opt_grpquota, Opt_reservation, Opt_noreservation
3081 +       Opt_usrquota, Opt_grpquota, Opt_reservation, Opt_noreservation,
3082 +       Opt_tag, Opt_notag, Opt_tagid
3083  };
3084  
3085  static const match_table_t tokens = {
3086 @@ -422,6 +423,9 @@ static const match_table_t tokens = {
3087         {Opt_acl, "acl"},
3088         {Opt_noacl, "noacl"},
3089         {Opt_xip, "xip"},
3090 +       {Opt_tag, "tag"},
3091 +       {Opt_notag, "notag"},
3092 +       {Opt_tagid, "tagid=%u"},
3093         {Opt_grpquota, "grpquota"},
3094         {Opt_ignore, "noquota"},
3095         {Opt_quota, "quota"},
3096 @@ -492,6 +496,20 @@ static int parse_options(char *options, 
3097                 case Opt_nouid32:
3098                         set_opt (sbi->s_mount_opt, NO_UID32);
3099                         break;
3100 +#ifndef CONFIG_TAGGING_NONE
3101 +               case Opt_tag:
3102 +                       set_opt (sbi->s_mount_opt, TAGGED);
3103 +                       break;
3104 +               case Opt_notag:
3105 +                       clear_opt (sbi->s_mount_opt, TAGGED);
3106 +                       break;
3107 +#endif
3108 +#ifdef CONFIG_PROPAGATE
3109 +               case Opt_tagid:
3110 +                       /* use args[0] */
3111 +                       set_opt (sbi->s_mount_opt, TAGGED);
3112 +                       break;
3113 +#endif
3114                 case Opt_nocheck:
3115                         clear_opt (sbi->s_mount_opt, CHECK);
3116                         break;
3117 @@ -850,6 +868,8 @@ static int ext2_fill_super(struct super_
3118         if (!parse_options((char *) data, sb))
3119                 goto failed_mount;
3120  
3121 +       if (EXT2_SB(sb)->s_mount_opt & EXT2_MOUNT_TAGGED)
3122 +               sb->s_flags |= MS_TAGGED;
3123         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
3124                 ((EXT2_SB(sb)->s_mount_opt & EXT2_MOUNT_POSIX_ACL) ?
3125                  MS_POSIXACL : 0);
3126 @@ -1223,6 +1243,14 @@ static int ext2_remount (struct super_bl
3127                 goto restore_opts;
3128         }
3129  
3130 +       if ((sbi->s_mount_opt & EXT2_MOUNT_TAGGED) &&
3131 +               !(sb->s_flags & MS_TAGGED)) {
3132 +               printk("EXT2-fs: %s: tagging not permitted on remount.\n",
3133 +                      sb->s_id);
3134 +               err = -EINVAL;
3135 +               goto restore_opts;
3136 +       }
3137 +
3138         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
3139                 ((sbi->s_mount_opt & EXT2_MOUNT_POSIX_ACL) ? MS_POSIXACL : 0);
3140  
3141 diff -NurpP --minimal linux-2.6.38.3/fs/ext3/file.c linux-2.6.38.3-vs2.3.0.37-rc14/fs/ext3/file.c
3142 --- linux-2.6.38.3/fs/ext3/file.c       2010-07-07 18:31:51.000000000 +0200
3143 +++ linux-2.6.38.3-vs2.3.0.37-rc14/fs/ext3/file.c       2011-01-29 02:01:07.000000000 +0100
3144 @@ -81,5 +81,6 @@ const struct inode_operations ext3_file_
3145  #endif
3146         .check_acl      = ext3_check_acl,
3147         .fiemap         = ext3_fiemap,
3148 +       .sync_flags     = ext3_sync_flags,
3149  };
3150  
3151 diff -NurpP --minimal linux-2.6.38.3/fs/ext3/ialloc.c linux-2.6.38.3-vs2.3.0.37-rc14/fs/ext3/ialloc.c
3152 --- linux-2.6.38.3/fs/ext3/ialloc.c     2011-01-05 21:50:22.000000000 +0100
3153 +++ linux-2.6.38.3-vs2.3.0.37-rc14/fs/ext3/ialloc.c     2011-01-29 02:01:07.000000000 +0100
3154 @@ -23,6 +23,7 @@
3155  #include <linux/buffer_head.h>
3156  #include <linux/random.h>
3157  #include <linux/bitops.h>
3158 +#include <linux/vs_tag.h>
3159  
3160  #include <asm/byteorder.h>
3161  
3162 @@ -531,6 +532,7 @@ got:
3163                 inode->i_mode = mode;
3164                 inode->i_uid = current_fsuid();
3165                 inode->i_gid = dir->i_gid;
3166 +               inode->i_tag = dx_current_fstag(sb);
3167         } else
3168                 inode_init_owner(inode, dir, mode);
3169  
3170 diff -NurpP --minimal linux-2.6.38.3/fs/ext3/inode.c linux-2.6.38.3-vs2.3.0.37-rc14/fs/ext3/inode.c
3171 --- linux-2.6.38.3/fs/ext3/inode.c      2011-03-15 18:07:31.000000000 +0100
3172 +++ linux-2.6.38.3-vs2.3.0.37-rc14/fs/ext3/inode.c      2011-01-29 02:01:07.000000000 +0100
3173 @@ -38,6 +38,7 @@
3174  #include <linux/bio.h>
3175  #include <linux/fiemap.h>
3176  #include <linux/namei.h>
3177 +#include <linux/vs_tag.h>
3178  #include "xattr.h"
3179  #include "acl.h"
3180  
3181 @@ -2394,7 +2395,7 @@ static void ext3_free_branches(handle_t 
3182  
3183  int ext3_can_truncate(struct inode *inode)
3184  {
3185 -       if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
3186 +       if (IS_APPEND(inode) || IS_IXORUNLINK(inode))
3187                 return 0;
3188         if (S_ISREG(inode->i_mode))
3189                 return 1;
3190 @@ -2778,36 +2779,60 @@ void ext3_set_inode_flags(struct inode *
3191  {
3192         unsigned int flags = EXT3_I(inode)->i_flags;
3193  
3194 -       inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
3195 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
3196 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
3197 +
3198 +       if (flags & EXT3_IMMUTABLE_FL)
3199 +               inode->i_flags |= S_IMMUTABLE;
3200 +       if (flags & EXT3_IXUNLINK_FL)
3201 +               inode->i_flags |= S_IXUNLINK;
3202 +
3203         if (flags & EXT3_SYNC_FL)
3204                 inode->i_flags |= S_SYNC;
3205         if (flags & EXT3_APPEND_FL)
3206                 inode->i_flags |= S_APPEND;
3207 -       if (flags & EXT3_IMMUTABLE_FL)
3208 -               inode->i_flags |= S_IMMUTABLE;
3209         if (flags & EXT3_NOATIME_FL)
3210                 inode->i_flags |= S_NOATIME;
3211         if (flags & EXT3_DIRSYNC_FL)
3212                 inode->i_flags |= S_DIRSYNC;
3213 +
3214 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
3215 +
3216 +       if (flags & EXT3_BARRIER_FL)
3217 +               inode->i_vflags |= V_BARRIER;
3218 +       if (flags & EXT3_COW_FL)
3219 +               inode->i_vflags |= V_COW;
3220  }
3221  
3222  /* Propagate flags from i_flags to EXT3_I(inode)->i_flags */
3223  void ext3_get_inode_flags(struct ext3_inode_info *ei)
3224  {
3225         unsigned int flags = ei->vfs_inode.i_flags;
3226 +       unsigned int vflags = ei->vfs_inode.i_vflags;
3227 +
3228 +       ei->i_flags &= ~(EXT3_SYNC_FL | EXT3_APPEND_FL |
3229 +                       EXT3_IMMUTABLE_FL | EXT3_IXUNLINK_FL |
3230 +                       EXT3_NOATIME_FL | EXT3_DIRSYNC_FL |
3231 +                       EXT3_BARRIER_FL | EXT3_COW_FL);
3232 +
3233 +       if (flags & S_IMMUTABLE)
3234 +               ei->i_flags |= EXT3_IMMUTABLE_FL;
3235 +       if (flags & S_IXUNLINK)
3236 +               ei->i_flags |= EXT3_IXUNLINK_FL;
3237  
3238 -       ei->i_flags &= ~(EXT3_SYNC_FL|EXT3_APPEND_FL|
3239 -                       EXT3_IMMUTABLE_FL|EXT3_NOATIME_FL|EXT3_DIRSYNC_FL);
3240         if (flags & S_SYNC)
3241                 ei->i_flags |= EXT3_SYNC_FL;
3242         if (flags & S_APPEND)
3243                 ei->i_flags |= EXT3_APPEND_FL;
3244 -       if (flags & S_IMMUTABLE)
3245 -               ei->i_flags |= EXT3_IMMUTABLE_FL;
3246         if (flags & S_NOATIME)
3247                 ei->i_flags |= EXT3_NOATIME_FL;
3248         if (flags & S_DIRSYNC)
3249                 ei->i_flags |= EXT3_DIRSYNC_FL;
3250 +
3251 +       if (vflags & V_BARRIER)
3252 +               ei->i_flags |= EXT3_BARRIER_FL;
3253 +       if (vflags & V_COW)
3254 +               ei->i_flags |= EXT3_COW_FL;
3255  }
3256  
3257  struct inode *ext3_iget(struct super_block *sb, unsigned long ino)
3258 @@ -2821,6 +2846,8 @@ struct inode *ext3_iget(struct super_blo
3259         transaction_t *transaction;
3260         long ret;
3261         int block;
3262 +       uid_t uid;
3263 +       gid_t gid;
3264  
3265         inode = iget_locked(sb, ino);
3266         if (!inode)
3267 @@ -2837,12 +2864,17 @@ struct inode *ext3_iget(struct super_blo
3268         bh = iloc.bh;
3269         raw_inode = ext3_raw_inode(&iloc);
3270         inode->i_mode = le16_to_cpu(raw_inode->i_mode);
3271 -       inode->i_uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
3272 -       inode->i_gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
3273 +       uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
3274 +       gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
3275         if(!(test_opt (inode->i_sb, NO_UID32))) {
3276 -               inode->i_uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
3277 -               inode->i_gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
3278 +               uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
3279 +               gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
3280         }
3281 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
3282 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
3283 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid,
3284 +               le16_to_cpu(raw_inode->i_raw_tag));
3285 +
3286         inode->i_nlink = le16_to_cpu(raw_inode->i_links_count);
3287         inode->i_size = le32_to_cpu(raw_inode->i_size);
3288         inode->i_atime.tv_sec = (signed)le32_to_cpu(raw_inode->i_atime);
3289 @@ -2997,6 +3029,8 @@ static int ext3_do_update_inode(handle_t
3290         struct ext3_inode *raw_inode = ext3_raw_inode(iloc);
3291         struct ext3_inode_info *ei = EXT3_I(inode);
3292         struct buffer_head *bh = iloc->bh;
3293 +       uid_t uid = TAGINO_UID(DX_TAG(inode), inode->i_uid, inode->i_tag);
3294 +       gid_t gid = TAGINO_GID(DX_TAG(inode), inode->i_gid, inode->i_tag);
3295         int err = 0, rc, block;
3296  
3297  again:
3298 @@ -3011,29 +3045,32 @@ again:
3299         ext3_get_inode_flags(ei);
3300         raw_inode->i_mode = cpu_to_le16(inode->i_mode);
3301         if(!(test_opt(inode->i_sb, NO_UID32))) {
3302 -               raw_inode->i_uid_low = cpu_to_le16(low_16_bits(inode->i_uid));
3303 -               raw_inode->i_gid_low = cpu_to_le16(low_16_bits(inode->i_gid));
3304 +               raw_inode->i_uid_low = cpu_to_le16(low_16_bits(uid));
3305 +               raw_inode->i_gid_low = cpu_to_le16(low_16_bits(gid));
3306  /*
3307   * Fix up interoperability with old kernels. Otherwise, old inodes get
3308   * re-used with the upper 16 bits of the uid/gid intact
3309   */
3310                 if(!ei->i_dtime) {
3311                         raw_inode->i_uid_high =
3312 -                               cpu_to_le16(high_16_bits(inode->i_uid));
3313 +                               cpu_to_le16(high_16_bits(uid));
3314                         raw_inode->i_gid_high =
3315 -                               cpu_to_le16(high_16_bits(inode->i_gid));
3316 +                               cpu_to_le16(high_16_bits(gid));
3317                 } else {
3318                         raw_inode->i_uid_high = 0;
3319                         raw_inode->i_gid_high = 0;
3320                 }
3321         } else {
3322                 raw_inode->i_uid_low =
3323 -                       cpu_to_le16(fs_high2lowuid(inode->i_uid));
3324 +                       cpu_to_le16(fs_high2lowuid(uid));
3325                 raw_inode->i_gid_low =
3326 -                       cpu_to_le16(fs_high2lowgid(inode->i_gid));
3327 +                       cpu_to_le16(fs_high2lowgid(gid));
3328                 raw_inode->i_uid_high = 0;
3329                 raw_inode->i_gid_high = 0;
3330         }
3331 +#ifdef CONFIG_TAGGING_INTERN
3332 +       raw_inode->i_raw_tag = cpu_to_le16(inode->i_tag);
3333 +#endif
3334         raw_inode->i_links_count = cpu_to_le16(inode->i_nlink);
3335         raw_inode->i_size = cpu_to_le32(ei->i_disksize);
3336         raw_inode->i_atime = cpu_to_le32(inode->i_atime.tv_sec);
3337 @@ -3193,7 +3230,8 @@ int ext3_setattr(struct dentry *dentry, 
3338         if (is_quota_modification(inode, attr))
3339                 dquot_initialize(inode);
3340         if ((ia_valid & ATTR_UID && attr->ia_uid != inode->i_uid) ||
3341 -               (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid)) {
3342 +               (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid) ||
3343 +               (ia_valid & ATTR_TAG && attr->ia_tag != inode->i_tag)) {
3344                 handle_t *handle;
3345  
3346                 /* (user+group)*(old+new) structure, inode write (sb,
3347 @@ -3215,6 +3253,8 @@ int ext3_setattr(struct dentry *dentry, 
3348                         inode->i_uid = attr->ia_uid;
3349                 if (attr->ia_valid & ATTR_GID)
3350                         inode->i_gid = attr->ia_gid;
3351 +               if ((attr->ia_valid & ATTR_TAG) && IS_TAGGED(inode))
3352 +                       inode->i_tag = attr->ia_tag;
3353                 error = ext3_mark_inode_dirty(handle, inode);
3354                 ext3_journal_stop(handle);
3355         }
3356 diff -NurpP --minimal linux-2.6.38.3/fs/ext3/ioctl.c linux-2.6.38.3-vs2.3.0.37-rc14/fs/ext3/ioctl.c
3357 --- linux-2.6.38.3/fs/ext3/ioctl.c      2011-03-15 18:07:31.000000000 +0100
3358 +++ linux-2.6.38.3-vs2.3.0.37-rc14/fs/ext3/ioctl.c      2011-01-29 02:01:07.000000000 +0100
3359 @@ -8,6 +8,7 @@
3360   */
3361  
3362  #include <linux/fs.h>
3363 +#include <linux/mount.h>
3364  #include <linux/jbd.h>
3365  #include <linux/capability.h>
3366  #include <linux/ext3_fs.h>
3367 @@ -17,6 +18,34 @@
3368  #include <linux/compat.h>
3369  #include <asm/uaccess.h>
3370  
3371 +
3372 +int ext3_sync_flags(struct inode *inode, int flags, int vflags)
3373 +{
3374 +       handle_t *handle = NULL;
3375 +       struct ext3_iloc iloc;
3376 +       int err;
3377 +
3378 +       handle = ext3_journal_start(inode, 1);
3379 +       if (IS_ERR(handle))
3380 +               return PTR_ERR(handle);
3381 +
3382 +       if (IS_SYNC(inode))
3383 +               handle->h_sync = 1;
3384 +       err = ext3_reserve_inode_write(handle, inode, &iloc);
3385 +       if (err)
3386 +               goto flags_err;
3387 +
3388 +       inode->i_flags = flags;
3389 +       inode->i_vflags = vflags;
3390 +       ext3_get_inode_flags(EXT3_I(inode));
3391 +       inode->i_ctime = CURRENT_TIME_SEC;
3392 +
3393 +       err = ext3_mark_iloc_dirty(handle, inode, &iloc);
3394 +flags_err:
3395 +       ext3_journal_stop(handle);
3396 +       return err;
3397 +}
3398 +
3399  long ext3_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
3400  {
3401         struct inode *inode = filp->f_dentry->d_inode;
3402 @@ -50,6 +79,11 @@ long ext3_ioctl(struct file *filp, unsig
3403  
3404                 flags = ext3_mask_flags(inode->i_mode, flags);
3405  
3406 +               if (IS_BARRIER(inode)) {
3407 +                       vxwprintk_task(1, "messing with the barrier.");
3408 +                       return -EACCES;
3409 +               }
3410 +
3411                 mutex_lock(&inode->i_mutex);
3412  
3413                 /* Is it quota file? Do not allow user to mess with it */
3414 @@ -68,7 +102,9 @@ long ext3_ioctl(struct file *filp, unsig
3415                  *
3416                  * This test looks nicer. Thanks to Pauline Middelink
3417                  */
3418 -               if ((flags ^ oldflags) & (EXT3_APPEND_FL | EXT3_IMMUTABLE_FL)) {
3419 +               if ((oldflags & EXT3_IMMUTABLE_FL) ||
3420 +                       ((flags ^ oldflags) & (EXT3_APPEND_FL |
3421 +                       EXT3_IMMUTABLE_FL | EXT3_IXUNLINK_FL))) {
3422                         if (!capable(CAP_LINUX_IMMUTABLE))
3423                                 goto flags_out;
3424                 }
3425 @@ -93,7 +129,7 @@ long ext3_ioctl(struct file *filp, unsig
3426                 if (err)
3427                         goto flags_err;
3428  
3429 -               flags = flags & EXT3_FL_USER_MODIFIABLE;
3430 +               flags &= EXT3_FL_USER_MODIFIABLE;
3431                 flags |= oldflags & ~EXT3_FL_USER_MODIFIABLE;
3432                 ei->i_flags = flags;
3433  
3434 diff -NurpP --minimal linux-2.6.38.3/fs/ext3/namei.c linux-2.6.38.3-vs2.3.0.37-rc14/fs/ext3/namei.c
3435 --- linux-2.6.38.3/fs/ext3/namei.c      2011-04-15 10:30:30.000000000 +0200
3436 +++ linux-2.6.38.3-vs2.3.0.37-rc14/fs/ext3/namei.c      2011-03-25 22:52:15.000000000 +0100
3437 @@ -36,6 +36,7 @@
3438  #include <linux/quotaops.h>
3439  #include <linux/buffer_head.h>
3440  #include <linux/bio.h>
3441 +#include <linux/vs_tag.h>
3442  
3443  #include "namei.h"
3444  #include "xattr.h"
3445 @@ -923,6 +924,7 @@ restart:
3446                                 if (bh)
3447                                         ll_rw_block(READ_META, 1, &bh);
3448                         }
3449 +               dx_propagate_tag(nd, inode);
3450                 }
3451                 if ((bh = bh_use[ra_ptr++]) == NULL)
3452                         goto next;
3453 @@ -2487,6 +2489,7 @@ const struct inode_operations ext3_dir_i
3454         .removexattr    = generic_removexattr,
3455  #endif
3456         .check_acl      = ext3_check_acl,
3457 +       .sync_flags     = ext3_sync_flags,
3458  };
3459  
3460  const struct inode_operations ext3_special_inode_operations = {
3461 diff -NurpP --minimal linux-2.6.38.3/fs/ext3/super.c linux-2.6.38.3-vs2.3.0.37-rc14/fs/ext3/super.c
3462 --- linux-2.6.38.3/fs/ext3/super.c      2011-04-15 10:30:30.000000000 +0200
3463 +++ linux-2.6.38.3-vs2.3.0.37-rc14/fs/ext3/super.c      2011-03-28 15:00:13.000000000 +0200
3464 @@ -820,7 +820,8 @@ enum {
3465         Opt_usrjquota, Opt_grpjquota, Opt_offusrjquota, Opt_offgrpjquota,
3466         Opt_jqfmt_vfsold, Opt_jqfmt_vfsv0, Opt_jqfmt_vfsv1, Opt_quota,
3467         Opt_noquota, Opt_ignore, Opt_barrier, Opt_nobarrier, Opt_err,
3468 -       Opt_resize, Opt_usrquota, Opt_grpquota
3469 +       Opt_resize, Opt_usrquota, Opt_grpquota,
3470 +       Opt_tag, Opt_notag, Opt_tagid
3471  };
3472  
3473  static const match_table_t tokens = {
3474 @@ -877,6 +878,9 @@ static const match_table_t tokens = {
3475         {Opt_barrier, "barrier"},
3476         {Opt_nobarrier, "nobarrier"},
3477         {Opt_resize, "resize"},
3478 +       {Opt_tag, "tag"},
3479 +       {Opt_notag, "notag"},
3480 +       {Opt_tagid, "tagid=%u"},
3481         {Opt_err, NULL},
3482  };
3483  
3484 @@ -1029,6 +1033,20 @@ static int parse_options (char *options,
3485                 case Opt_nouid32:
3486                         set_opt (sbi->s_mount_opt, NO_UID32);
3487                         break;
3488 +#ifndef CONFIG_TAGGING_NONE
3489 +               case Opt_tag:
3490 +                       set_opt (sbi->s_mount_opt, TAGGED);
3491 +                       break;
3492 +               case Opt_notag:
3493 +                       clear_opt (sbi->s_mount_opt, TAGGED);
3494 +                       break;
3495 +#endif
3496 +#ifdef CONFIG_PROPAGATE
3497 +               case Opt_tagid:
3498 +                       /* use args[0] */
3499 +                       set_opt (sbi->s_mount_opt, TAGGED);
3500 +                       break;
3501 +#endif
3502                 case Opt_nocheck:
3503                         clear_opt (sbi->s_mount_opt, CHECK);
3504                         break;
3505 @@ -1722,6 +1740,9 @@ static int ext3_fill_super (struct super
3506                             NULL, 0))
3507                 goto failed_mount;
3508  
3509 +       if (EXT3_SB(sb)->s_mount_opt & EXT3_MOUNT_TAGGED)
3510 +               sb->s_flags |= MS_TAGGED;
3511 +
3512         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
3513                 (test_opt(sb, POSIX_ACL) ? MS_POSIXACL : 0);
3514  
3515 @@ -2601,6 +2622,14 @@ static int ext3_remount (struct super_bl
3516         if (test_opt(sb, ABORT))
3517                 ext3_abort(sb, __func__, "Abort forced by user");
3518  
3519 +       if ((sbi->s_mount_opt & EXT3_MOUNT_TAGGED) &&
3520 +               !(sb->s_flags & MS_TAGGED)) {
3521 +               printk("EXT3-fs: %s: tagging not permitted on remount.\n",
3522 +                       sb->s_id);
3523 +               err = -EINVAL;
3524 +               goto restore_opts;
3525 +       }
3526 +
3527         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
3528                 (test_opt(sb, POSIX_ACL) ? MS_POSIXACL : 0);
3529  
3530 diff -NurpP --minimal linux-2.6.38.3/fs/ext4/ext4.h linux-2.6.38.3-vs2.3.0.37-rc14/fs/ext4/ext4.h
3531 --- linux-2.6.38.3/fs/ext4/ext4.h       2011-03-15 18:07:31.000000000 +0100
3532 +++ linux-2.6.38.3-vs2.3.0.37-rc14/fs/ext4/ext4.h       2011-02-17 02:17:50.000000000 +0100
3533 @@ -347,8 +347,12 @@ struct flex_groups {
3534  #define EXT4_EXTENTS_FL                        0x00080000 /* Inode uses extents */
3535  #define EXT4_EA_INODE_FL               0x00200000 /* Inode used for large EA */
3536  #define EXT4_EOFBLOCKS_FL              0x00400000 /* Blocks allocated beyond EOF */
3537 +#define EXT4_IXUNLINK_FL               0x08000000 /* Immutable invert on unlink */
3538  #define EXT4_RESERVED_FL               0x80000000 /* reserved for ext4 lib */
3539  
3540 +#define EXT4_BARRIER_FL                        0x04000000 /* Barrier for chroot() */
3541 +#define EXT4_COW_FL                    0x20000000 /* Copy on Write marker */
3542 +
3543  #define EXT4_FL_USER_VISIBLE           0x004BDFFF /* User visible flags */
3544  #define EXT4_FL_USER_MODIFIABLE                0x004B80FF /* User modifiable flags */
3545  
3546 @@ -601,7 +605,8 @@ struct ext4_inode {
3547                         __le16  l_i_file_acl_high;
3548                         __le16  l_i_uid_high;   /* these 2 fields */
3549                         __le16  l_i_gid_high;   /* were reserved2[0] */
3550 -                       __u32   l_i_reserved2;
3551 +                       __le16  l_i_tag;        /* Context Tag */
3552 +                       __u16   l_i_reserved2;
3553                 } linux2;
3554                 struct {
3555                         __le16  h_i_reserved1;  /* Obsoleted fragment number/size which are removed in ext4 */
3556 @@ -719,6 +724,7 @@ do {                                                                               \
3557  #define i_gid_low      i_gid
3558  #define i_uid_high     osd2.linux2.l_i_uid_high
3559  #define i_gid_high     osd2.linux2.l_i_gid_high
3560 +#define i_raw_tag      osd2.linux2.l_i_tag
3561  #define i_reserved2    osd2.linux2.l_i_reserved2
3562  
3563  #elif defined(__GNU__)
3564 @@ -895,6 +901,7 @@ struct ext4_inode_info {
3565  #define EXT4_MOUNT_POSIX_ACL           0x08000 /* POSIX Access Control Lists */
3566  #define EXT4_MOUNT_NO_AUTO_DA_ALLOC    0x10000 /* No auto delalloc mapping */
3567  #define EXT4_MOUNT_BARRIER             0x20000 /* Use block barriers */
3568 +#define EXT4_MOUNT_TAGGED              0x40000 /* Enable Context Tags */
3569  #define EXT4_MOUNT_QUOTA               0x80000 /* Some quota option set */
3570  #define EXT4_MOUNT_USRQUOTA            0x100000 /* "old" user quota */
3571  #define EXT4_MOUNT_GRPQUOTA            0x200000 /* "old" group quota */
3572 @@ -2074,6 +2081,7 @@ extern int ext4_map_blocks(handle_t *han
3573                            struct ext4_map_blocks *map, int flags);
3574  extern int ext4_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
3575                         __u64 start, __u64 len);
3576 +extern int ext4_sync_flags(struct inode *, int, int);
3577  /* move_extent.c */
3578  extern int ext4_move_extents(struct file *o_filp, struct file *d_filp,
3579                              __u64 start_orig, __u64 start_donor,
3580 diff -NurpP --minimal linux-2.6.38.3/fs/ext4/file.c linux-2.6.38.3-vs2.3.0.37-rc14/fs/ext4/file.c
3581 --- linux-2.6.38.3/fs/ext4/file.c       2011-03-15 18:07:31.000000000 +0100
3582 +++ linux-2.6.38.3-vs2.3.0.37-rc14/fs/ext4/file.c       2011-02-17 02:17:50.000000000 +0100
3583 @@ -283,5 +283,6 @@ const struct inode_operations ext4_file_
3584  #endif
3585         .check_acl      = ext4_check_acl,
3586         .fiemap         = ext4_fiemap,
3587 +       .sync_flags     = ext4_sync_flags,
3588  };
3589  
3590 diff -NurpP --minimal linux-2.6.38.3/fs/ext4/ialloc.c linux-2.6.38.3-vs2.3.0.37-rc14/fs/ext4/ialloc.c
3591 --- linux-2.6.38.3/fs/ext4/ialloc.c     2011-03-15 18:07:31.000000000 +0100
3592 +++ linux-2.6.38.3-vs2.3.0.37-rc14/fs/ext4/ialloc.c     2011-01-29 02:01:07.000000000 +0100
3593 @@ -22,6 +22,7 @@
3594  #include <linux/random.h>
3595  #include <linux/bitops.h>
3596  #include <linux/blkdev.h>
3597 +#include <linux/vs_tag.h>
3598  #include <asm/byteorder.h>
3599  
3600  #include "ext4.h"
3601 @@ -991,6 +992,7 @@ got:
3602                 inode->i_mode = mode;
3603                 inode->i_uid = current_fsuid();
3604                 inode->i_gid = dir->i_gid;
3605 +               inode->i_tag = dx_current_fstag(sb);
3606         } else
3607                 inode_init_owner(inode, dir, mode);
3608  
3609 diff -NurpP --minimal linux-2.6.38.3/fs/ext4/inode.c linux-2.6.38.3-vs2.3.0.37-rc14/fs/ext4/inode.c
3610 --- linux-2.6.38.3/fs/ext4/inode.c      2011-04-15 10:30:30.000000000 +0200
3611 +++ linux-2.6.38.3-vs2.3.0.37-rc14/fs/ext4/inode.c      2011-04-15 10:33:41.000000000 +0200
3612 @@ -42,6 +42,7 @@
3613  #include <linux/printk.h>
3614  #include <linux/slab.h>
3615  #include <linux/ratelimit.h>
3616 +#include <linux/vs_tag.h>
3617  
3618  #include "ext4_jbd2.h"
3619  #include "xattr.h"
3620 @@ -4446,7 +4447,7 @@ static void ext4_free_branches(handle_t 
3621  
3622  int ext4_can_truncate(struct inode *inode)
3623  {
3624 -       if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
3625 +       if (IS_APPEND(inode) || IS_IXORUNLINK(inode))
3626                 return 0;
3627         if (S_ISREG(inode->i_mode))
3628                 return 1;
3629 @@ -4797,41 +4798,64 @@ void ext4_set_inode_flags(struct inode *
3630  {
3631         unsigned int flags = EXT4_I(inode)->i_flags;
3632  
3633 -       inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
3634 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
3635 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
3636 +
3637 +       if (flags & EXT4_IMMUTABLE_FL)
3638 +               inode->i_flags |= S_IMMUTABLE;
3639 +       if (flags & EXT4_IXUNLINK_FL)
3640 +               inode->i_flags |= S_IXUNLINK;
3641 +
3642         if (flags & EXT4_SYNC_FL)
3643                 inode->i_flags |= S_SYNC;
3644         if (flags & EXT4_APPEND_FL)
3645                 inode->i_flags |= S_APPEND;
3646 -       if (flags & EXT4_IMMUTABLE_FL)
3647 -               inode->i_flags |= S_IMMUTABLE;
3648         if (flags & EXT4_NOATIME_FL)
3649                 inode->i_flags |= S_NOATIME;
3650         if (flags & EXT4_DIRSYNC_FL)
3651                 inode->i_flags |= S_DIRSYNC;
3652 +
3653 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
3654 +
3655 +       if (flags & EXT4_BARRIER_FL)
3656 +               inode->i_vflags |= V_BARRIER;
3657 +       if (flags & EXT4_COW_FL)
3658 +               inode->i_vflags |= V_COW;
3659  }
3660  
3661  /* Propagate flags from i_flags to EXT4_I(inode)->i_flags */
3662  void ext4_get_inode_flags(struct ext4_inode_info *ei)
3663  {
3664 -       unsigned int vfs_fl;
3665 +       unsigned int vfs_fl, vfs_vf;
3666         unsigned long old_fl, new_fl;
3667  
3668         do {
3669                 vfs_fl = ei->vfs_inode.i_flags;
3670 +               vfs_vf = ei->vfs_inode.i_vflags;
3671                 old_fl = ei->i_flags;
3672                 new_fl = old_fl & ~(EXT4_SYNC_FL|EXT4_APPEND_FL|
3673                                 EXT4_IMMUTABLE_FL|EXT4_NOATIME_FL|
3674 -                               EXT4_DIRSYNC_FL);
3675 +                               EXT4_DIRSYNC_FL|EXT4_BARRIER_FL|
3676 +                               EXT4_COW_FL);
3677 +
3678 +               if (vfs_fl & S_IMMUTABLE)
3679 +                       new_fl |= EXT4_IMMUTABLE_FL;
3680 +               if (vfs_fl & S_IXUNLINK)
3681 +                       new_fl |= EXT4_IXUNLINK_FL;
3682 +
3683                 if (vfs_fl & S_SYNC)
3684                         new_fl |= EXT4_SYNC_FL;
3685                 if (vfs_fl & S_APPEND)
3686                         new_fl |= EXT4_APPEND_FL;
3687 -               if (vfs_fl & S_IMMUTABLE)
3688 -                       new_fl |= EXT4_IMMUTABLE_FL;
3689                 if (vfs_fl & S_NOATIME)
3690                         new_fl |= EXT4_NOATIME_FL;
3691                 if (vfs_fl & S_DIRSYNC)
3692                         new_fl |= EXT4_DIRSYNC_FL;
3693 +
3694 +               if (vfs_vf & V_BARRIER)
3695 +                       new_fl |= EXT4_BARRIER_FL;
3696 +               if (vfs_vf & V_COW)
3697 +                       new_fl |= EXT4_COW_FL;
3698         } while (cmpxchg(&ei->i_flags, old_fl, new_fl) != old_fl);
3699  }
3700  
3701 @@ -4867,6 +4891,8 @@ struct inode *ext4_iget(struct super_blo
3702         journal_t *journal = EXT4_SB(sb)->s_journal;
3703         long ret;
3704         int block;
3705 +       uid_t uid;
3706 +       gid_t gid;
3707  
3708         inode = iget_locked(sb, ino);
3709         if (!inode)
3710 @@ -4882,12 +4908,16 @@ struct inode *ext4_iget(struct super_blo
3711                 goto bad_inode;
3712         raw_inode = ext4_raw_inode(&iloc);
3713         inode->i_mode = le16_to_cpu(raw_inode->i_mode);
3714 -       inode->i_uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
3715 -       inode->i_gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
3716 +       uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
3717 +       gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
3718         if (!(test_opt(inode->i_sb, NO_UID32))) {
3719 -               inode->i_uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
3720 -               inode->i_gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
3721 +               uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
3722 +               gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
3723         }
3724 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
3725 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
3726 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid,
3727 +               le16_to_cpu(raw_inode->i_raw_tag));
3728         inode->i_nlink = le16_to_cpu(raw_inode->i_links_count);
3729  
3730         ext4_clear_state_flags(ei);     /* Only relevant on 32-bit archs */
3731 @@ -5106,6 +5136,8 @@ static int ext4_do_update_inode(handle_t
3732         struct ext4_inode *raw_inode = ext4_raw_inode(iloc);
3733         struct ext4_inode_info *ei = EXT4_I(inode);
3734         struct buffer_head *bh = iloc->bh;
3735 +       uid_t uid = TAGINO_UID(DX_TAG(inode), inode->i_uid, inode->i_tag);
3736 +       gid_t gid = TAGINO_GID(DX_TAG(inode), inode->i_gid, inode->i_tag);
3737         int err = 0, rc, block;
3738  
3739         /* For fields not not tracking in the in-memory inode,
3740 @@ -5116,29 +5148,32 @@ static int ext4_do_update_inode(handle_t
3741         ext4_get_inode_flags(ei);
3742         raw_inode->i_mode = cpu_to_le16(inode->i_mode);
3743         if (!(test_opt(inode->i_sb, NO_UID32))) {
3744 -               raw_inode->i_uid_low = cpu_to_le16(low_16_bits(inode->i_uid));
3745 -               raw_inode->i_gid_low = cpu_to_le16(low_16_bits(inode->i_gid));
3746 +               raw_inode->i_uid_low = cpu_to_le16(low_16_bits(uid));
3747 +               raw_inode->i_gid_low = cpu_to_le16(low_16_bits(gid));
3748  /*
3749   * Fix up interoperability with old kernels. Otherwise, old inodes get
3750   * re-used with the upper 16 bits of the uid/gid intact
3751   */
3752                 if (!ei->i_dtime) {
3753                         raw_inode->i_uid_high =
3754 -                               cpu_to_le16(high_16_bits(inode->i_uid));
3755 +                               cpu_to_le16(high_16_bits(uid));
3756                         raw_inode->i_gid_high =
3757 -                               cpu_to_le16(high_16_bits(inode->i_gid));
3758 +                               cpu_to_le16(high_16_bits(gid));
3759                 } else {
3760                         raw_inode->i_uid_high = 0;
3761                         raw_inode->i_gid_high = 0;
3762                 }
3763         } else {
3764                 raw_inode->i_uid_low =
3765 -                       cpu_to_le16(fs_high2lowuid(inode->i_uid));
3766 +                       cpu_to_le16(fs_high2lowuid(uid));
3767                 raw_inode->i_gid_low =
3768 -                       cpu_to_le16(fs_high2lowgid(inode->i_gid));
3769 +                       cpu_to_le16(fs_high2lowgid(gid));
3770                 raw_inode->i_uid_high = 0;
3771                 raw_inode->i_gid_high = 0;
3772         }
3773 +#ifdef CONFIG_TAGGING_INTERN
3774 +       raw_inode->i_raw_tag = cpu_to_le16(inode->i_tag);
3775 +#endif
3776         raw_inode->i_links_count = cpu_to_le16(inode->i_nlink);
3777  
3778         EXT4_INODE_SET_XTIME(i_ctime, inode, raw_inode);
3779 @@ -5324,7 +5359,8 @@ int ext4_setattr(struct dentry *dentry, 
3780         if (is_quota_modification(inode, attr))
3781                 dquot_initialize(inode);
3782         if ((ia_valid & ATTR_UID && attr->ia_uid != inode->i_uid) ||
3783 -               (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid)) {
3784 +               (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid) ||
3785 +               (ia_valid & ATTR_TAG && attr->ia_tag != inode->i_tag)) {
3786                 handle_t *handle;
3787  
3788                 /* (user+group)*(old+new) structure, inode write (sb,
3789 @@ -5346,6 +5382,8 @@ int ext4_setattr(struct dentry *dentry, 
3790                         inode->i_uid = attr->ia_uid;
3791                 if (attr->ia_valid & ATTR_GID)
3792                         inode->i_gid = attr->ia_gid;
3793 +               if ((attr->ia_valid & ATTR_TAG) && IS_TAGGED(inode))
3794 +                       inode->i_tag = attr->ia_tag;
3795                 error = ext4_mark_inode_dirty(handle, inode);
3796                 ext4_journal_stop(handle);
3797         }
3798 diff -NurpP --minimal linux-2.6.38.3/fs/ext4/ioctl.c linux-2.6.38.3-vs2.3.0.37-rc14/fs/ext4/ioctl.c
3799 --- linux-2.6.38.3/fs/ext4/ioctl.c      2011-01-05 21:50:23.000000000 +0100
3800 +++ linux-2.6.38.3-vs2.3.0.37-rc14/fs/ext4/ioctl.c      2011-01-29 02:01:07.000000000 +0100
3801 @@ -14,10 +14,39 @@
3802  #include <linux/compat.h>
3803  #include <linux/mount.h>
3804  #include <linux/file.h>
3805 +#include <linux/vs_tag.h>
3806  #include <asm/uaccess.h>
3807  #include "ext4_jbd2.h"
3808  #include "ext4.h"
3809  
3810 +
3811 +int ext4_sync_flags(struct inode *inode, int flags, int vflags)
3812 +{
3813 +       handle_t *handle = NULL;
3814 +       struct ext4_iloc iloc;
3815 +       int err;
3816 +
3817 +       handle = ext4_journal_start(inode, 1);
3818 +       if (IS_ERR(handle))
3819 +               return PTR_ERR(handle);
3820 +
3821 +       if (IS_SYNC(inode))
3822 +               ext4_handle_sync(handle);
3823 +       err = ext4_reserve_inode_write(handle, inode, &iloc);
3824 +       if (err)
3825 +               goto flags_err;
3826 +
3827 +       inode->i_flags = flags;
3828 +       inode->i_vflags = vflags;
3829 +       ext4_get_inode_flags(EXT4_I(inode));
3830 +       inode->i_ctime = ext4_current_time(inode);
3831 +
3832 +       err = ext4_mark_iloc_dirty(handle, inode, &iloc);
3833 +flags_err:
3834 +       ext4_journal_stop(handle);
3835 +       return err;
3836 +}
3837 +
3838  long ext4_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
3839  {
3840         struct inode *inode = filp->f_dentry->d_inode;
3841 @@ -50,6 +79,11 @@ long ext4_ioctl(struct file *filp, unsig
3842  
3843                 flags = ext4_mask_flags(inode->i_mode, flags);
3844  
3845 +               if (IS_BARRIER(inode)) {
3846 +                       vxwprintk_task(1, "messing with the barrier.");
3847 +                       return -EACCES;
3848 +               }
3849 +
3850                 err = -EPERM;
3851                 mutex_lock(&inode->i_mutex);
3852                 /* Is it quota file? Do not allow user to mess with it */
3853 @@ -67,7 +101,9 @@ long ext4_ioctl(struct file *filp, unsig
3854                  *
3855                  * This test looks nicer. Thanks to Pauline Middelink
3856                  */
3857 -               if ((flags ^ oldflags) & (EXT4_APPEND_FL | EXT4_IMMUTABLE_FL)) {
3858 +               if ((oldflags & EXT4_IMMUTABLE_FL) ||
3859 +                       ((flags ^ oldflags) & (EXT4_APPEND_FL |
3860 +                       EXT4_IMMUTABLE_FL | EXT4_IXUNLINK_FL))) {
3861                         if (!capable(CAP_LINUX_IMMUTABLE))
3862                                 goto flags_out;
3863                 }
3864 diff -NurpP --minimal linux-2.6.38.3/fs/ext4/namei.c linux-2.6.38.3-vs2.3.0.37-rc14/fs/ext4/namei.c
3865 --- linux-2.6.38.3/fs/ext4/namei.c      2011-03-15 18:07:31.000000000 +0100
3866 +++ linux-2.6.38.3-vs2.3.0.37-rc14/fs/ext4/namei.c      2011-01-29 02:01:07.000000000 +0100
3867 @@ -34,6 +34,7 @@
3868  #include <linux/quotaops.h>
3869  #include <linux/buffer_head.h>
3870  #include <linux/bio.h>
3871 +#include <linux/vs_tag.h>
3872  #include "ext4.h"
3873  #include "ext4_jbd2.h"
3874  
3875 @@ -923,6 +924,7 @@ restart:
3876                                 if (bh)
3877                                         ll_rw_block(READ_META, 1, &bh);
3878                         }
3879 +               dx_propagate_tag(nd, inode);
3880                 }
3881                 if ((bh = bh_use[ra_ptr++]) == NULL)
3882                         goto next;
3883 @@ -2540,6 +2542,7 @@ const struct inode_operations ext4_dir_i
3884  #endif
3885         .check_acl      = ext4_check_acl,
3886         .fiemap         = ext4_fiemap,
3887 +       .sync_flags     = ext4_sync_flags,
3888  };
3889  
3890  const struct inode_operations ext4_special_inode_operations = {
3891 diff -NurpP --minimal linux-2.6.38.3/fs/ext4/super.c linux-2.6.38.3-vs2.3.0.37-rc14/fs/ext4/super.c
3892 --- linux-2.6.38.3/fs/ext4/super.c      2011-04-15 10:30:30.000000000 +0200
3893 +++ linux-2.6.38.3-vs2.3.0.37-rc14/fs/ext4/super.c      2011-04-15 10:33:41.000000000 +0200
3894 @@ -1263,6 +1263,7 @@ enum {
3895         Opt_dioread_nolock, Opt_dioread_lock,
3896         Opt_discard, Opt_nodiscard,
3897         Opt_init_inode_table, Opt_noinit_inode_table,
3898 +       Opt_tag, Opt_notag, Opt_tagid
3899  };
3900  
3901  static const match_table_t tokens = {
3902 @@ -1338,6 +1339,9 @@ static const match_table_t tokens = {
3903         {Opt_init_inode_table, "init_itable=%u"},
3904         {Opt_init_inode_table, "init_itable"},
3905         {Opt_noinit_inode_table, "noinit_itable"},
3906 +       {Opt_tag, "tag"},
3907 +       {Opt_notag, "notag"},
3908 +       {Opt_tagid, "tagid=%u"},
3909         {Opt_err, NULL},
3910  };
3911  
3912 @@ -1506,6 +1510,20 @@ static int parse_options(char *options, 
3913                 case Opt_nouid32:
3914                         set_opt(sb, NO_UID32);
3915                         break;
3916 +#ifndef CONFIG_TAGGING_NONE
3917 +               case Opt_tag:
3918 +                       set_opt(sb, TAGGED);
3919 +                       break;
3920 +               case Opt_notag:
3921 +                       clear_opt(sb, TAGGED);
3922 +                       break;
3923 +#endif
3924 +#ifdef CONFIG_PROPAGATE
3925 +               case Opt_tagid:
3926 +                       /* use args[0] */
3927 +                       set_opt(sb, TAGGED);
3928 +                       break;
3929 +#endif
3930                 case Opt_debug:
3931                         set_opt(sb, DEBUG);
3932                         break;
3933 @@ -3162,6 +3180,9 @@ static int ext4_fill_super(struct super_
3934                            &journal_ioprio, NULL, 0))
3935                 goto failed_mount;
3936  
3937 +       if (EXT4_SB(sb)->s_mount_opt & EXT4_MOUNT_TAGGED)
3938 +               sb->s_flags |= MS_TAGGED;
3939 +
3940         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
3941                 (test_opt(sb, POSIX_ACL) ? MS_POSIXACL : 0);
3942  
3943 @@ -4249,6 +4270,14 @@ static int ext4_remount(struct super_blo
3944         if (sbi->s_mount_flags & EXT4_MF_FS_ABORTED)
3945                 ext4_abort(sb, "Abort forced by user");
3946  
3947 +       if ((sbi->s_mount_opt & EXT4_MOUNT_TAGGED) &&
3948 +               !(sb->s_flags & MS_TAGGED)) {
3949 +               printk("EXT4-fs: %s: tagging not permitted on remount.\n",
3950 +                       sb->s_id);
3951 +               err = -EINVAL;
3952 +               goto restore_opts;
3953 +       }
3954 +
3955         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
3956                 (test_opt(sb, POSIX_ACL) ? MS_POSIXACL : 0);
3957  
3958 diff -NurpP --minimal linux-2.6.38.3/fs/fcntl.c linux-2.6.38.3-vs2.3.0.37-rc14/fs/fcntl.c
3959 --- linux-2.6.38.3/fs/fcntl.c   2011-03-15 18:07:31.000000000 +0100
3960 +++ linux-2.6.38.3-vs2.3.0.37-rc14/fs/fcntl.c   2011-02-17 02:17:50.000000000 +0100
3961 @@ -20,6 +20,7 @@
3962  #include <linux/signal.h>
3963  #include <linux/rcupdate.h>
3964  #include <linux/pid_namespace.h>
3965 +#include <linux/vs_limit.h>
3966  
3967  #include <asm/poll.h>
3968  #include <asm/siginfo.h>
3969 @@ -103,6 +104,8 @@ SYSCALL_DEFINE3(dup3, unsigned int, oldf
3970  
3971         if (tofree)
3972                 filp_close(tofree, files);
3973 +       else
3974 +               vx_openfd_inc(newfd);   /* fd was unused */
3975  
3976         return newfd;
3977  
3978 @@ -434,6 +437,8 @@ SYSCALL_DEFINE3(fcntl, unsigned int, fd,
3979         filp = fget(fd);
3980         if (!filp)
3981                 goto out;
3982 +       if (!vx_files_avail(1))
3983 +               goto out;
3984  
3985         err = security_file_fcntl(filp, cmd, arg);
3986         if (err) {
3987 diff -NurpP --minimal linux-2.6.38.3/fs/file.c linux-2.6.38.3-vs2.3.0.37-rc14/fs/file.c
3988 --- linux-2.6.38.3/fs/file.c    2010-10-21 13:07:48.000000000 +0200
3989 +++ linux-2.6.38.3-vs2.3.0.37-rc14/fs/file.c    2011-01-29 02:01:07.000000000 +0100
3990 @@ -20,6 +20,7 @@
3991  #include <linux/spinlock.h>
3992  #include <linux/rcupdate.h>
3993  #include <linux/workqueue.h>
3994 +#include <linux/vs_limit.h>
3995  
3996  struct fdtable_defer {
3997         spinlock_t lock;
3998 @@ -355,6 +356,8 @@ struct files_struct *dup_fd(struct files
3999                 struct file *f = *old_fds++;
4000                 if (f) {
4001                         get_file(f);
4002 +                       /* TODO: sum it first for check and performance */
4003 +                       vx_openfd_inc(open_files - i);
4004                 } else {
4005                         /*
4006                          * The fd may be claimed in the fd bitmap but not yet
4007 @@ -462,6 +465,7 @@ repeat:
4008         else
4009                 FD_CLR(fd, fdt->close_on_exec);
4010         error = fd;
4011 +       vx_openfd_inc(fd);
4012  #if 1
4013         /* Sanity check */
4014         if (rcu_dereference_raw(fdt->fd[fd]) != NULL) {
4015 diff -NurpP --minimal linux-2.6.38.3/fs/file_table.c linux-2.6.38.3-vs2.3.0.37-rc14/fs/file_table.c
4016 --- linux-2.6.38.3/fs/file_table.c      2011-03-15 18:07:31.000000000 +0100
4017 +++ linux-2.6.38.3-vs2.3.0.37-rc14/fs/file_table.c      2011-02-17 02:17:50.000000000 +0100
4018 @@ -24,6 +24,8 @@
4019  #include <linux/percpu_counter.h>
4020  #include <linux/percpu.h>
4021  #include <linux/ima.h>
4022 +#include <linux/vs_limit.h>
4023 +#include <linux/vs_context.h>
4024  
4025  #include <asm/atomic.h>
4026  
4027 @@ -135,6 +137,8 @@ struct file *get_empty_filp(void)
4028         spin_lock_init(&f->f_lock);
4029         eventpoll_init_file(f);
4030         /* f->f_version: 0 */
4031 +       f->f_xid = vx_current_xid();
4032 +       vx_files_inc(f);
4033         return f;
4034  
4035  over:
4036 @@ -250,6 +254,8 @@ static void __fput(struct file *file)
4037                 cdev_put(inode->i_cdev);
4038         fops_put(file->f_op);
4039         put_pid(file->f_owner.pid);
4040 +       vx_files_dec(file);
4041 +       file->f_xid = 0;
4042         file_sb_list_del(file);
4043         if (file->f_mode & FMODE_WRITE)
4044                 drop_file_write_access(file);
4045 @@ -333,6 +339,8 @@ void put_filp(struct file *file)
4046  {
4047         if (atomic_long_dec_and_test(&file->f_count)) {
4048                 security_file_free(file);
4049 +               vx_files_dec(file);
4050 +               file->f_xid = 0;
4051                 file_sb_list_del(file);
4052                 file_free(file);
4053         }
4054 diff -NurpP --minimal linux-2.6.38.3/fs/fs_struct.c linux-2.6.38.3-vs2.3.0.37-rc14/fs/fs_struct.c
4055 --- linux-2.6.38.3/fs/fs_struct.c       2011-03-15 18:07:31.000000000 +0100
4056 +++ linux-2.6.38.3-vs2.3.0.37-rc14/fs/fs_struct.c       2011-01-29 02:35:02.000000000 +0100
4057 @@ -4,6 +4,7 @@
4058  #include <linux/path.h>
4059  #include <linux/slab.h>
4060  #include <linux/fs_struct.h>
4061 +#include <linux/vserver/global.h>
4062  #include "internal.h"
4063  
4064  static inline void path_get_longterm(struct path *path)
4065 @@ -96,6 +97,7 @@ void free_fs_struct(struct fs_struct *fs
4066  {
4067         path_put_longterm(&fs->root);
4068         path_put_longterm(&fs->pwd);
4069 +       atomic_dec(&vs_global_fs);
4070         kmem_cache_free(fs_cachep, fs);
4071  }
4072  
4073 @@ -135,6 +137,7 @@ struct fs_struct *copy_fs_struct(struct 
4074                 fs->pwd = old->pwd;
4075                 path_get_longterm(&fs->pwd);
4076                 spin_unlock(&old->lock);
4077 +               atomic_inc(&vs_global_fs);
4078         }
4079         return fs;
4080  }
4081 diff -NurpP --minimal linux-2.6.38.3/fs/gfs2/file.c linux-2.6.38.3-vs2.3.0.37-rc14/fs/gfs2/file.c
4082 --- linux-2.6.38.3/fs/gfs2/file.c       2011-03-15 18:07:32.000000000 +0100
4083 +++ linux-2.6.38.3-vs2.3.0.37-rc14/fs/gfs2/file.c       2011-01-29 02:01:07.000000000 +0100
4084 @@ -134,6 +134,9 @@ static const u32 fsflags_to_gfs2[32] = {
4085         [7] = GFS2_DIF_NOATIME,
4086         [12] = GFS2_DIF_EXHASH,
4087         [14] = GFS2_DIF_INHERIT_JDATA,
4088 +       [27] = GFS2_DIF_IXUNLINK,
4089 +       [26] = GFS2_DIF_BARRIER,
4090 +       [29] = GFS2_DIF_COW,
4091  };
4092  
4093  static const u32 gfs2_to_fsflags[32] = {
4094 @@ -143,6 +146,9 @@ static const u32 gfs2_to_fsflags[32] = {
4095         [gfs2fl_NoAtime] = FS_NOATIME_FL,
4096         [gfs2fl_ExHash] = FS_INDEX_FL,
4097         [gfs2fl_InheritJdata] = FS_JOURNAL_DATA_FL,
4098 +       [gfs2fl_IXUnlink] = FS_IXUNLINK_FL,
4099 +       [gfs2fl_Barrier] = FS_BARRIER_FL,
4100 +       [gfs2fl_Cow] = FS_COW_FL,
4101  };
4102  
4103  static int gfs2_get_flags(struct file *filp, u32 __user *ptr)
4104 @@ -173,10 +179,16 @@ void gfs2_set_inode_flags(struct inode *
4105  {
4106         struct gfs2_inode *ip = GFS2_I(inode);
4107         unsigned int flags = inode->i_flags;
4108 +       unsigned int vflags = inode->i_vflags;
4109 +
4110 +       flags &= ~(S_IMMUTABLE | S_IXUNLINK |
4111 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
4112  
4113 -       flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
4114         if (ip->i_diskflags & GFS2_DIF_IMMUTABLE)
4115                 flags |= S_IMMUTABLE;
4116 +       if (ip->i_diskflags & GFS2_DIF_IXUNLINK)
4117 +               flags |= S_IXUNLINK;
4118 +
4119         if (ip->i_diskflags & GFS2_DIF_APPENDONLY)
4120                 flags |= S_APPEND;
4121         if (ip->i_diskflags & GFS2_DIF_NOATIME)
4122 @@ -184,6 +196,43 @@ void gfs2_set_inode_flags(struct inode *
4123         if (ip->i_diskflags & GFS2_DIF_SYNC)
4124                 flags |= S_SYNC;
4125         inode->i_flags = flags;
4126 +
4127 +       vflags &= ~(V_BARRIER | V_COW);
4128 +
4129 +       if (ip->i_diskflags & GFS2_DIF_BARRIER)
4130 +               vflags |= V_BARRIER;
4131 +       if (ip->i_diskflags & GFS2_DIF_COW)
4132 +               vflags |= V_COW;
4133 +       inode->i_vflags = vflags;
4134 +}
4135 +
4136 +void gfs2_get_inode_flags(struct inode *inode)
4137 +{
4138 +       struct gfs2_inode *ip = GFS2_I(inode);
4139 +       unsigned int flags = inode->i_flags;
4140 +       unsigned int vflags = inode->i_vflags;
4141 +
4142 +       ip->i_diskflags &= ~(GFS2_DIF_APPENDONLY |
4143 +                       GFS2_DIF_NOATIME | GFS2_DIF_SYNC |
4144 +                       GFS2_DIF_IMMUTABLE | GFS2_DIF_IXUNLINK |
4145 +                       GFS2_DIF_BARRIER | GFS2_DIF_COW);
4146 +
4147 +       if (flags & S_IMMUTABLE)
4148 +               ip->i_diskflags |= GFS2_DIF_IMMUTABLE;
4149 +       if (flags & S_IXUNLINK)
4150 +               ip->i_diskflags |= GFS2_DIF_IXUNLINK;
4151 +
4152 +       if (flags & S_APPEND)
4153 +               ip->i_diskflags |= GFS2_DIF_APPENDONLY;
4154 +       if (flags & S_NOATIME)
4155 +               ip->i_diskflags |= GFS2_DIF_NOATIME;
4156 +       if (flags & S_SYNC)
4157 +               ip->i_diskflags |= GFS2_DIF_SYNC;
4158 +
4159 +       if (vflags & V_BARRIER)
4160 +               ip->i_diskflags |= GFS2_DIF_BARRIER;
4161 +       if (vflags & V_COW)
4162 +               ip->i_diskflags |= GFS2_DIF_COW;
4163  }
4164  
4165  /* Flags that can be set by user space */
4166 @@ -295,6 +344,37 @@ static int gfs2_set_flags(struct file *f
4167         return do_gfs2_set_flags(filp, gfsflags, ~GFS2_DIF_JDATA);
4168  }
4169  
4170 +int gfs2_sync_flags(struct inode *inode, int flags, int vflags)
4171 +{
4172 +       struct gfs2_inode *ip = GFS2_I(inode);
4173 +       struct gfs2_sbd *sdp = GFS2_SB(inode);
4174 +       struct buffer_head *bh;
4175 +       struct gfs2_holder gh;
4176 +       int error;
4177 +
4178 +       error = gfs2_glock_nq_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &gh);
4179 +       if (error)
4180 +               return error;
4181 +       error = gfs2_trans_begin(sdp, RES_DINODE, 0);
4182 +       if (error)
4183 +               goto out;
4184 +       error = gfs2_meta_inode_buffer(ip, &bh);
4185 +       if (error)
4186 +               goto out_trans_end;
4187 +       gfs2_trans_add_bh(ip->i_gl, bh, 1);
4188 +       inode->i_flags = flags;
4189 +       inode->i_vflags = vflags;
4190 +       gfs2_get_inode_flags(inode);
4191 +       gfs2_dinode_out(ip, bh->b_data);
4192 +       brelse(bh);
4193 +       gfs2_set_aops(inode);
4194 +out_trans_end:
4195 +       gfs2_trans_end(sdp);
4196 +out:
4197 +       gfs2_glock_dq_uninit(&gh);
4198 +       return error;
4199 +}
4200 +
4201  static long gfs2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
4202  {
4203         switch(cmd) {
4204 diff -NurpP --minimal linux-2.6.38.3/fs/gfs2/inode.h linux-2.6.38.3-vs2.3.0.37-rc14/fs/gfs2/inode.h
4205 --- linux-2.6.38.3/fs/gfs2/inode.h      2011-03-15 18:07:32.000000000 +0100
4206 +++ linux-2.6.38.3-vs2.3.0.37-rc14/fs/gfs2/inode.h      2011-01-29 02:01:07.000000000 +0100
4207 @@ -125,6 +125,7 @@ extern const struct file_operations gfs2
4208  extern const struct file_operations gfs2_dir_fops_nolock;
4209  
4210  extern void gfs2_set_inode_flags(struct inode *inode);
4211 +extern int gfs2_sync_flags(struct inode *inode, int flags, int vflags);
4212   
4213  #ifdef CONFIG_GFS2_FS_LOCKING_DLM
4214  extern const struct file_operations gfs2_file_fops;
4215 diff -NurpP --minimal linux-2.6.38.3/fs/gfs2/ops_inode.c linux-2.6.38.3-vs2.3.0.37-rc14/fs/gfs2/ops_inode.c
4216 --- linux-2.6.38.3/fs/gfs2/ops_inode.c  2011-03-15 18:07:32.000000000 +0100
4217 +++ linux-2.6.38.3-vs2.3.0.37-rc14/fs/gfs2/ops_inode.c  2011-01-29 02:01:07.000000000 +0100
4218 @@ -1326,6 +1326,8 @@ const struct inode_operations gfs2_dir_i
4219         .listxattr = gfs2_listxattr,
4220         .removexattr = gfs2_removexattr,
4221         .fiemap = gfs2_fiemap,
4222 +       .sync_flags = gfs2_sync_flags,
4223 +       .sync_flags = gfs2_sync_flags,
4224  };
4225  
4226  const struct inode_operations gfs2_symlink_iops = {
4227 diff -NurpP --minimal linux-2.6.38.3/fs/inode.c linux-2.6.38.3-vs2.3.0.37-rc14/fs/inode.c
4228 --- linux-2.6.38.3/fs/inode.c   2011-03-15 18:07:32.000000000 +0100
4229 +++ linux-2.6.38.3-vs2.3.0.37-rc14/fs/inode.c   2011-03-07 16:53:27.000000000 +0100
4230 @@ -25,6 +25,7 @@
4231  #include <linux/async.h>
4232  #include <linux/posix_acl.h>
4233  #include <linux/ima.h>
4234 +#include <linux/vs_tag.h>
4235  
4236  /*
4237   * This is needed for the following functions:
4238 @@ -164,6 +165,9 @@ int inode_init_always(struct super_block
4239         struct address_space *const mapping = &inode->i_data;
4240  
4241         inode->i_sb = sb;
4242 +
4243 +       /* essential because of inode slab reuse */
4244 +       inode->i_tag = 0;
4245         inode->i_blkbits = sb->s_blocksize_bits;
4246         inode->i_flags = 0;
4247         atomic_set(&inode->i_count, 1);
4248 @@ -184,6 +188,7 @@ int inode_init_always(struct super_block
4249         inode->i_bdev = NULL;
4250         inode->i_cdev = NULL;
4251         inode->i_rdev = 0;
4252 +       inode->i_mdev = 0;
4253         inode->dirtied_when = 0;
4254  
4255         if (security_inode_alloc(inode))
4256 @@ -431,6 +436,8 @@ static void __remove_inode_hash(struct i
4257         hlist_del_init(&inode->i_hash);
4258  }
4259  
4260 +EXPORT_SYMBOL_GPL(__iget);
4261 +
4262  /**
4263   *     remove_inode_hash - remove an inode from the hash
4264   *     @inode: inode to unhash
4265 @@ -1704,9 +1711,11 @@ void init_special_inode(struct inode *in
4266         if (S_ISCHR(mode)) {
4267                 inode->i_fop = &def_chr_fops;
4268                 inode->i_rdev = rdev;
4269 +               inode->i_mdev = rdev;
4270         } else if (S_ISBLK(mode)) {
4271                 inode->i_fop = &def_blk_fops;
4272                 inode->i_rdev = rdev;
4273 +               inode->i_mdev = rdev;
4274         } else if (S_ISFIFO(mode))
4275                 inode->i_fop = &def_fifo_fops;
4276         else if (S_ISSOCK(mode))
4277 @@ -1735,5 +1744,6 @@ void inode_init_owner(struct inode *inod
4278         } else
4279                 inode->i_gid = current_fsgid();
4280         inode->i_mode = mode;
4281 +       inode->i_tag = dx_current_fstag(inode->i_sb);
4282  }
4283  EXPORT_SYMBOL(inode_init_owner);
4284 diff -NurpP --minimal linux-2.6.38.3/fs/ioctl.c linux-2.6.38.3-vs2.3.0.37-rc14/fs/ioctl.c
4285 --- linux-2.6.38.3/fs/ioctl.c   2011-03-15 18:07:32.000000000 +0100
4286 +++ linux-2.6.38.3-vs2.3.0.37-rc14/fs/ioctl.c   2011-02-17 02:17:50.000000000 +0100
4287 @@ -15,6 +15,9 @@
4288  #include <linux/writeback.h>
4289  #include <linux/buffer_head.h>
4290  #include <linux/falloc.h>
4291 +#include <linux/proc_fs.h>
4292 +#include <linux/vserver/inode.h>
4293 +#include <linux/vs_tag.h>
4294  
4295  #include <asm/ioctls.h>
4296  
4297 diff -NurpP --minimal linux-2.6.38.3/fs/ioprio.c linux-2.6.38.3-vs2.3.0.37-rc14/fs/ioprio.c
4298 --- linux-2.6.38.3/fs/ioprio.c  2011-01-05 21:50:24.000000000 +0100
4299 +++ linux-2.6.38.3-vs2.3.0.37-rc14/fs/ioprio.c  2011-01-29 02:01:07.000000000 +0100
4300 @@ -27,6 +27,7 @@
4301  #include <linux/syscalls.h>
4302  #include <linux/security.h>
4303  #include <linux/pid_namespace.h>
4304 +#include <linux/vs_base.h>
4305  
4306  int set_task_ioprio(struct task_struct *task, int ioprio)
4307  {
4308 @@ -119,6 +120,8 @@ SYSCALL_DEFINE3(ioprio_set, int, which, 
4309                         else
4310                                 pgrp = find_vpid(who);
4311                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
4312 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
4313 +                                       continue;
4314                                 ret = set_task_ioprio(p, ioprio);
4315                                 if (ret)
4316                                         break;
4317 @@ -208,6 +211,8 @@ SYSCALL_DEFINE2(ioprio_get, int, which, 
4318                         else
4319                                 pgrp = find_vpid(who);
4320                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
4321 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
4322 +                                       continue;
4323                                 tmpio = get_task_ioprio(p);
4324                                 if (tmpio < 0)
4325                                         continue;
4326 diff -NurpP --minimal linux-2.6.38.3/fs/jfs/file.c linux-2.6.38.3-vs2.3.0.37-rc14/fs/jfs/file.c
4327 --- linux-2.6.38.3/fs/jfs/file.c        2010-10-21 13:07:50.000000000 +0200
4328 +++ linux-2.6.38.3-vs2.3.0.37-rc14/fs/jfs/file.c        2011-01-29 02:01:07.000000000 +0100
4329 @@ -102,7 +102,8 @@ int jfs_setattr(struct dentry *dentry, s
4330         if (is_quota_modification(inode, iattr))
4331                 dquot_initialize(inode);
4332         if ((iattr->ia_valid & ATTR_UID && iattr->ia_uid != inode->i_uid) ||
4333 -           (iattr->ia_valid & ATTR_GID && iattr->ia_gid != inode->i_gid)) {
4334 +           (iattr->ia_valid & ATTR_GID && iattr->ia_gid != inode->i_gid) ||
4335 +           (iattr->ia_valid & ATTR_TAG && iattr->ia_tag != inode->i_tag)) {
4336                 rc = dquot_transfer(inode, iattr);
4337                 if (rc)
4338                         return rc;
4339 @@ -133,6 +134,7 @@ const struct inode_operations jfs_file_i
4340  #ifdef CONFIG_JFS_POSIX_ACL
4341         .check_acl      = jfs_check_acl,
4342  #endif
4343 +       .sync_flags     = jfs_sync_flags,
4344  };
4345  
4346  const struct file_operations jfs_file_operations = {
4347 diff -NurpP --minimal linux-2.6.38.3/fs/jfs/ioctl.c linux-2.6.38.3-vs2.3.0.37-rc14/fs/jfs/ioctl.c
4348 --- linux-2.6.38.3/fs/jfs/ioctl.c       2008-12-25 00:26:37.000000000 +0100
4349 +++ linux-2.6.38.3-vs2.3.0.37-rc14/fs/jfs/ioctl.c       2011-01-29 02:01:07.000000000 +0100
4350 @@ -11,6 +11,7 @@
4351  #include <linux/mount.h>
4352  #include <linux/time.h>
4353  #include <linux/sched.h>
4354 +#include <linux/mount.h>
4355  #include <asm/current.h>
4356  #include <asm/uaccess.h>
4357  
4358 @@ -52,6 +53,16 @@ static long jfs_map_ext2(unsigned long f
4359  }
4360  
4361  
4362 +int jfs_sync_flags(struct inode *inode, int flags, int vflags)
4363 +{
4364 +       inode->i_flags = flags;
4365 +       inode->i_vflags = vflags;
4366 +       jfs_get_inode_flags(JFS_IP(inode));
4367 +       inode->i_ctime = CURRENT_TIME_SEC;
4368 +       mark_inode_dirty(inode);
4369 +       return 0;
4370 +}
4371 +
4372  long jfs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
4373  {
4374         struct inode *inode = filp->f_dentry->d_inode;
4375 @@ -85,6 +96,11 @@ long jfs_ioctl(struct file *filp, unsign
4376                 if (!S_ISDIR(inode->i_mode))
4377                         flags &= ~JFS_DIRSYNC_FL;
4378  
4379 +               if (IS_BARRIER(inode)) {
4380 +                       vxwprintk_task(1, "messing with the barrier.");
4381 +                       return -EACCES;
4382 +               }
4383 +
4384                 /* Is it quota file? Do not allow user to mess with it */
4385                 if (IS_NOQUOTA(inode)) {
4386                         err = -EPERM;
4387 @@ -102,8 +118,8 @@ long jfs_ioctl(struct file *filp, unsign
4388                  * the relevant capability.
4389                  */
4390                 if ((oldflags & JFS_IMMUTABLE_FL) ||
4391 -                       ((flags ^ oldflags) &
4392 -                       (JFS_APPEND_FL | JFS_IMMUTABLE_FL))) {
4393 +                       ((flags ^ oldflags) & (JFS_APPEND_FL |
4394 +                       JFS_IMMUTABLE_FL | JFS_IXUNLINK_FL))) {
4395                         if (!capable(CAP_LINUX_IMMUTABLE)) {
4396                                 mutex_unlock(&inode->i_mutex);
4397                                 err = -EPERM;
4398 @@ -111,7 +127,7 @@ long jfs_ioctl(struct file *filp, unsign
4399                         }
4400                 }
4401  
4402 -               flags = flags & JFS_FL_USER_MODIFIABLE;
4403 +               flags &= JFS_FL_USER_MODIFIABLE;
4404                 flags |= oldflags & ~JFS_FL_USER_MODIFIABLE;
4405                 jfs_inode->mode2 = flags;
4406  
4407 diff -NurpP --minimal linux-2.6.38.3/fs/jfs/jfs_dinode.h linux-2.6.38.3-vs2.3.0.37-rc14/fs/jfs/jfs_dinode.h
4408 --- linux-2.6.38.3/fs/jfs/jfs_dinode.h  2008-12-25 00:26:37.000000000 +0100
4409 +++ linux-2.6.38.3-vs2.3.0.37-rc14/fs/jfs/jfs_dinode.h  2011-01-29 02:01:07.000000000 +0100
4410 @@ -161,9 +161,13 @@ struct dinode {
4411  
4412  #define JFS_APPEND_FL          0x01000000 /* writes to file may only append */
4413  #define JFS_IMMUTABLE_FL       0x02000000 /* Immutable file */
4414 +#define JFS_IXUNLINK_FL                0x08000000 /* Immutable invert on unlink */
4415  
4416 -#define JFS_FL_USER_VISIBLE    0x03F80000
4417 -#define JFS_FL_USER_MODIFIABLE 0x03F80000
4418 +#define JFS_BARRIER_FL         0x04000000 /* Barrier for chroot() */
4419 +#define JFS_COW_FL             0x20000000 /* Copy on Write marker */
4420 +
4421 +#define JFS_FL_USER_VISIBLE    0x07F80000
4422 +#define JFS_FL_USER_MODIFIABLE 0x07F80000
4423  #define JFS_FL_INHERIT         0x03C80000
4424  
4425  /* These are identical to EXT[23]_IOC_GETFLAGS/SETFLAGS */
4426 diff -NurpP --minimal linux-2.6.38.3/fs/jfs/jfs_filsys.h linux-2.6.38.3-vs2.3.0.37-rc14/fs/jfs/jfs_filsys.h
4427 --- linux-2.6.38.3/fs/jfs/jfs_filsys.h  2008-12-25 00:26:37.000000000 +0100
4428 +++ linux-2.6.38.3-vs2.3.0.37-rc14/fs/jfs/jfs_filsys.h  2011-01-29 02:01:07.000000000 +0100
4429 @@ -263,6 +263,7 @@
4430  #define JFS_NAME_MAX   255
4431  #define JFS_PATH_MAX   BPSIZE
4432  
4433 +#define JFS_TAGGED             0x00800000      /* Context Tagging */
4434  
4435  /*
4436   *     file system state (superblock state)
4437 diff -NurpP --minimal linux-2.6.38.3/fs/jfs/jfs_imap.c linux-2.6.38.3-vs2.3.0.37-rc14/fs/jfs/jfs_imap.c
4438 --- linux-2.6.38.3/fs/jfs/jfs_imap.c    2011-01-05 21:50:24.000000000 +0100
4439 +++ linux-2.6.38.3-vs2.3.0.37-rc14/fs/jfs/jfs_imap.c    2011-01-29 02:01:07.000000000 +0100
4440 @@ -46,6 +46,7 @@
4441  #include <linux/pagemap.h>
4442  #include <linux/quotaops.h>
4443  #include <linux/slab.h>
4444 +#include <linux/vs_tag.h>
4445  
4446  #include "jfs_incore.h"
4447  #include "jfs_inode.h"
4448 @@ -3060,6 +3061,8 @@ static int copy_from_dinode(struct dinod
4449  {
4450         struct jfs_inode_info *jfs_ip = JFS_IP(ip);
4451         struct jfs_sb_info *sbi = JFS_SBI(ip->i_sb);
4452 +       uid_t uid;
4453 +       gid_t gid;
4454  
4455         jfs_ip->fileset = le32_to_cpu(dip->di_fileset);
4456         jfs_ip->mode2 = le32_to_cpu(dip->di_mode);
4457 @@ -3080,14 +3083,18 @@ static int copy_from_dinode(struct dinod
4458         }
4459         ip->i_nlink = le32_to_cpu(dip->di_nlink);
4460  
4461 -       jfs_ip->saved_uid = le32_to_cpu(dip->di_uid);
4462 +       uid = le32_to_cpu(dip->di_uid);
4463 +       gid = le32_to_cpu(dip->di_gid);
4464 +       ip->i_tag = INOTAG_TAG(DX_TAG(ip), uid, gid, 0);
4465 +
4466 +       jfs_ip->saved_uid = INOTAG_UID(DX_TAG(ip), uid, gid);
4467         if (sbi->uid == -1)
4468                 ip->i_uid = jfs_ip->saved_uid;
4469         else {
4470                 ip->i_uid = sbi->uid;
4471         }
4472  
4473 -       jfs_ip->saved_gid = le32_to_cpu(dip->di_gid);
4474 +       jfs_ip->saved_gid = INOTAG_GID(DX_TAG(ip), uid, gid);
4475         if (sbi->gid == -1)
4476                 ip->i_gid = jfs_ip->saved_gid;
4477         else {
4478 @@ -3152,14 +3159,12 @@ static void copy_to_dinode(struct dinode
4479         dip->di_size = cpu_to_le64(ip->i_size);
4480         dip->di_nblocks = cpu_to_le64(PBLK2LBLK(ip->i_sb, ip->i_blocks));
4481         dip->di_nlink = cpu_to_le32(ip->i_nlink);
4482 -       if (sbi->uid == -1)
4483 -               dip->di_uid = cpu_to_le32(ip->i_uid);
4484 -       else
4485 -               dip->di_uid = cpu_to_le32(jfs_ip->saved_uid);
4486 -       if (sbi->gid == -1)
4487 -               dip->di_gid = cpu_to_le32(ip->i_gid);
4488 -       else
4489 -               dip->di_gid = cpu_to_le32(jfs_ip->saved_gid);
4490 +
4491 +       dip->di_uid = cpu_to_le32(TAGINO_UID(DX_TAG(ip),
4492 +               (sbi->uid == -1) ? ip->i_uid : jfs_ip->saved_uid, ip->i_tag));
4493 +       dip->di_gid = cpu_to_le32(TAGINO_GID(DX_TAG(ip),
4494 +               (sbi->gid == -1) ? ip->i_gid : jfs_ip->saved_gid, ip->i_tag));
4495 +
4496         jfs_get_inode_flags(jfs_ip);
4497         /*
4498          * mode2 is only needed for storing the higher order bits.
4499 diff -NurpP --minimal linux-2.6.38.3/fs/jfs/jfs_inode.c linux-2.6.38.3-vs2.3.0.37-rc14/fs/jfs/jfs_inode.c
4500 --- linux-2.6.38.3/fs/jfs/jfs_inode.c   2010-08-02 16:52:49.000000000 +0200
4501 +++ linux-2.6.38.3-vs2.3.0.37-rc14/fs/jfs/jfs_inode.c   2011-01-29 02:01:07.000000000 +0100
4502 @@ -18,6 +18,7 @@
4503  
4504  #include <linux/fs.h>
4505  #include <linux/quotaops.h>
4506 +#include <linux/vs_tag.h>
4507  #include "jfs_incore.h"
4508  #include "jfs_inode.h"
4509  #include "jfs_filsys.h"
4510 @@ -30,29 +31,46 @@ void jfs_set_inode_flags(struct inode *i
4511  {
4512         unsigned int flags = JFS_IP(inode)->mode2;
4513  
4514 -       inode->i_flags &= ~(S_IMMUTABLE | S_APPEND |
4515 -               S_NOATIME | S_DIRSYNC | S_SYNC);
4516 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
4517 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
4518  
4519         if (flags & JFS_IMMUTABLE_FL)
4520                 inode->i_flags |= S_IMMUTABLE;
4521 +       if (flags & JFS_IXUNLINK_FL)
4522 +               inode->i_flags |= S_IXUNLINK;
4523 +
4524 +       if (flags & JFS_SYNC_FL)
4525 +               inode->i_flags |= S_SYNC;
4526         if (flags & JFS_APPEND_FL)
4527                 inode->i_flags |= S_APPEND;
4528         if (flags & JFS_NOATIME_FL)
4529                 inode->i_flags |= S_NOATIME;
4530         if (flags & JFS_DIRSYNC_FL)
4531                 inode->i_flags |= S_DIRSYNC;
4532 -       if (flags & JFS_SYNC_FL)
4533 -               inode->i_flags |= S_SYNC;
4534 +
4535 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
4536 +
4537 +       if (flags & JFS_BARRIER_FL)
4538 +               inode->i_vflags |= V_BARRIER;
4539 +       if (flags & JFS_COW_FL)
4540 +               inode->i_vflags |= V_COW;
4541  }
4542  
4543  void jfs_get_inode_flags(struct jfs_inode_info *jfs_ip)
4544  {
4545         unsigned int flags = jfs_ip->vfs_inode.i_flags;
4546 +       unsigned int vflags = jfs_ip->vfs_inode.i_vflags;
4547 +
4548 +       jfs_ip->mode2 &= ~(JFS_IMMUTABLE_FL | JFS_IXUNLINK_FL |
4549 +                          JFS_APPEND_FL | JFS_NOATIME_FL |
4550 +                          JFS_DIRSYNC_FL | JFS_SYNC_FL |
4551 +                          JFS_BARRIER_FL | JFS_COW_FL);
4552  
4553 -       jfs_ip->mode2 &= ~(JFS_IMMUTABLE_FL | JFS_APPEND_FL | JFS_NOATIME_FL |
4554 -                          JFS_DIRSYNC_FL | JFS_SYNC_FL);
4555         if (flags & S_IMMUTABLE)
4556                 jfs_ip->mode2 |= JFS_IMMUTABLE_FL;
4557 +       if (flags & S_IXUNLINK)
4558 +               jfs_ip->mode2 |= JFS_IXUNLINK_FL;
4559 +
4560         if (flags & S_APPEND)
4561                 jfs_ip->mode2 |= JFS_APPEND_FL;
4562         if (flags & S_NOATIME)
4563 @@ -61,6 +79,11 @@ void jfs_get_inode_flags(struct jfs_inod
4564                 jfs_ip->mode2 |= JFS_DIRSYNC_FL;
4565         if (flags & S_SYNC)
4566                 jfs_ip->mode2 |= JFS_SYNC_FL;
4567 +
4568 +       if (vflags & V_BARRIER)
4569 +               jfs_ip->mode2 |= JFS_BARRIER_FL;
4570 +       if (vflags & V_COW)
4571 +               jfs_ip->mode2 |= JFS_COW_FL;
4572  }
4573  
4574  /*
4575 diff -NurpP --minimal linux-2.6.38.3/fs/jfs/jfs_inode.h linux-2.6.38.3-vs2.3.0.37-rc14/fs/jfs/jfs_inode.h
4576 --- linux-2.6.38.3/fs/jfs/jfs_inode.h   2010-10-21 13:07:50.000000000 +0200
4577 +++ linux-2.6.38.3-vs2.3.0.37-rc14/fs/jfs/jfs_inode.h   2011-01-29 02:01:07.000000000 +0100
4578 @@ -39,6 +39,7 @@ extern struct dentry *jfs_fh_to_dentry(s
4579  extern struct dentry *jfs_fh_to_parent(struct super_block *sb, struct fid *fid,
4580         int fh_len, int fh_type);
4581  extern void jfs_set_inode_flags(struct inode *);
4582 +extern int jfs_sync_flags(struct inode *, int, int);
4583  extern int jfs_get_block(struct inode *, sector_t, struct buffer_head *, int);
4584  extern int jfs_setattr(struct dentry *, struct iattr *);
4585  
4586 diff -NurpP --minimal linux-2.6.38.3/fs/jfs/namei.c linux-2.6.38.3-vs2.3.0.37-rc14/fs/jfs/namei.c
4587 --- linux-2.6.38.3/fs/jfs/namei.c       2011-03-15 18:07:32.000000000 +0100
4588 +++ linux-2.6.38.3-vs2.3.0.37-rc14/fs/jfs/namei.c       2011-03-15 18:15:06.000000000 +0100
4589 @@ -22,6 +22,7 @@
4590  #include <linux/ctype.h>
4591  #include <linux/quotaops.h>
4592  #include <linux/exportfs.h>
4593 +#include <linux/vs_tag.h>
4594  #include "jfs_incore.h"
4595  #include "jfs_superblock.h"
4596  #include "jfs_inode.h"
4597 @@ -1489,6 +1490,7 @@ static struct dentry *jfs_lookup(struct 
4598                 return ERR_CAST(ip);
4599         }
4600  
4601 +       dx_propagate_tag(nd, ip);
4602         return d_splice_alias(ip, dentry);
4603  }
4604  
4605 @@ -1553,6 +1555,7 @@ const struct inode_operations jfs_dir_in
4606  #ifdef CONFIG_JFS_POSIX_ACL
4607         .check_acl      = jfs_check_acl,
4608  #endif
4609 +       .sync_flags     = jfs_sync_flags,
4610  };
4611  
4612  const struct file_operations jfs_dir_operations = {
4613 diff -NurpP --minimal linux-2.6.38.3/fs/jfs/super.c linux-2.6.38.3-vs2.3.0.37-rc14/fs/jfs/super.c
4614 --- linux-2.6.38.3/fs/jfs/super.c       2011-03-15 18:07:32.000000000 +0100
4615 +++ linux-2.6.38.3-vs2.3.0.37-rc14/fs/jfs/super.c       2011-01-29 02:01:07.000000000 +0100
4616 @@ -198,7 +198,8 @@ static void jfs_put_super(struct super_b
4617  enum {
4618         Opt_integrity, Opt_nointegrity, Opt_iocharset, Opt_resize,
4619         Opt_resize_nosize, Opt_errors, Opt_ignore, Opt_err, Opt_quota,
4620 -       Opt_usrquota, Opt_grpquota, Opt_uid, Opt_gid, Opt_umask
4621 +       Opt_usrquota, Opt_grpquota, Opt_uid, Opt_gid, Opt_umask,
4622 +       Opt_tag, Opt_notag, Opt_tagid
4623  };
4624  
4625  static const match_table_t tokens = {
4626 @@ -208,6 +209,10 @@ static const match_table_t tokens = {
4627         {Opt_resize, "resize=%u"},
4628         {Opt_resize_nosize, "resize"},
4629         {Opt_errors, "errors=%s"},
4630 +       {Opt_tag, "tag"},
4631 +       {Opt_notag, "notag"},
4632 +       {Opt_tagid, "tagid=%u"},
4633 +       {Opt_tag, "tagxid"},
4634         {Opt_ignore, "noquota"},
4635         {Opt_ignore, "quota"},
4636         {Opt_usrquota, "usrquota"},
4637 @@ -342,6 +347,20 @@ static int parse_options(char *options, 
4638                         }
4639                         break;
4640                 }
4641 +#ifndef CONFIG_TAGGING_NONE
4642 +               case Opt_tag:
4643 +                       *flag |= JFS_TAGGED;
4644 +                       break;
4645 +               case Opt_notag:
4646 +                       *flag &= JFS_TAGGED;
4647 +                       break;
4648 +#endif
4649 +#ifdef CONFIG_PROPAGATE
4650 +               case Opt_tagid:
4651 +                       /* use args[0] */
4652 +                       *flag |= JFS_TAGGED;
4653 +                       break;
4654 +#endif
4655                 default:
4656                         printk("jfs: Unrecognized mount option \"%s\" "
4657                                         " or missing value\n", p);
4658 @@ -373,6 +392,12 @@ static int jfs_remount(struct super_bloc
4659                 return -EINVAL;
4660         }
4661  
4662 +       if ((flag & JFS_TAGGED) && !(sb->s_flags & MS_TAGGED)) {
4663 +               printk(KERN_ERR "JFS: %s: tagging not permitted on remount.\n",
4664 +                       sb->s_id);
4665 +               return -EINVAL;
4666 +       }
4667 +
4668         if (newLVSize) {
4669                 if (sb->s_flags & MS_RDONLY) {
4670                         printk(KERN_ERR
4671 @@ -455,6 +480,9 @@ static int jfs_fill_super(struct super_b
4672  #ifdef CONFIG_JFS_POSIX_ACL
4673         sb->s_flags |= MS_POSIXACL;
4674  #endif
4675 +       /* map mount option tagxid */
4676 +       if (sbi->flag & JFS_TAGGED)
4677 +               sb->s_flags |= MS_TAGGED;
4678  
4679         if (newLVSize) {
4680                 printk(KERN_ERR "resize option for remount only\n");
4681 diff -NurpP --minimal linux-2.6.38.3/fs/libfs.c linux-2.6.38.3-vs2.3.0.37-rc14/fs/libfs.c
4682 --- linux-2.6.38.3/fs/libfs.c   2011-03-15 18:07:32.000000000 +0100
4683 +++ linux-2.6.38.3-vs2.3.0.37-rc14/fs/libfs.c   2011-01-29 05:03:51.000000000 +0100
4684 @@ -133,7 +133,8 @@ static inline unsigned char dt_type(stru
4685   * both impossible due to the lock on directory.
4686   */
4687  
4688 -int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
4689 +static inline int do_dcache_readdir_filter(struct file *filp,
4690 +       void *dirent, filldir_t filldir, int (*filter)(struct dentry *dentry))
4691  {
4692         struct dentry *dentry = filp->f_path.dentry;
4693         struct dentry *cursor = filp->private_data;
4694 @@ -164,6 +165,8 @@ int dcache_readdir(struct file * filp, v
4695                         for (p=q->next; p != &dentry->d_subdirs; p=p->next) {
4696                                 struct dentry *next;
4697                                 next = list_entry(p, struct dentry, d_u.d_child);
4698 +                               if (filter && !filter(next))
4699 +                                       continue;
4700                                 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
4701                                 if (!simple_positive(next)) {
4702                                         spin_unlock(&next->d_lock);
4703 @@ -190,6 +193,17 @@ int dcache_readdir(struct file * filp, v
4704         return 0;
4705  }
4706  
4707 +int dcache_readdir(struct file *filp, void *dirent, filldir_t filldir)
4708 +{
4709 +       return do_dcache_readdir_filter(filp, dirent, filldir, NULL);
4710 +}
4711 +
4712 +int dcache_readdir_filter(struct file *filp, void *dirent, filldir_t filldir,
4713 +       int (*filter)(struct dentry *))
4714 +{
4715 +       return do_dcache_readdir_filter(filp, dirent, filldir, filter);
4716 +}
4717 +
4718  ssize_t generic_read_dir(struct file *filp, char __user *buf, size_t siz, loff_t *ppos)
4719  {
4720         return -EISDIR;
4721 @@ -965,6 +979,7 @@ EXPORT_SYMBOL(dcache_dir_close);
4722  EXPORT_SYMBOL(dcache_dir_lseek);
4723  EXPORT_SYMBOL(dcache_dir_open);
4724  EXPORT_SYMBOL(dcache_readdir);
4725 +EXPORT_SYMBOL(dcache_readdir_filter);
4726  EXPORT_SYMBOL(generic_read_dir);
4727  EXPORT_SYMBOL(mount_pseudo);
4728  EXPORT_SYMBOL(simple_write_begin);
4729 diff -NurpP --minimal linux-2.6.38.3/fs/locks.c linux-2.6.38.3-vs2.3.0.37-rc14/fs/locks.c
4730 --- linux-2.6.38.3/fs/locks.c   2011-03-15 18:07:32.000000000 +0100
4731 +++ linux-2.6.38.3-vs2.3.0.37-rc14/fs/locks.c   2011-01-29 02:01:07.000000000 +0100
4732 @@ -126,6 +126,8 @@
4733  #include <linux/time.h>
4734  #include <linux/rcupdate.h>
4735  #include <linux/pid_namespace.h>
4736 +#include <linux/vs_base.h>
4737 +#include <linux/vs_limit.h>
4738  
4739  #include <asm/uaccess.h>
4740  
4741 @@ -164,6 +166,8 @@ static struct kmem_cache *filelock_cache
4742  /* Allocate an empty lock structure. */
4743  struct file_lock *locks_alloc_lock(void)
4744  {
4745 +       if (!vx_locks_avail(1))
4746 +               return NULL;
4747         return kmem_cache_alloc(filelock_cache, GFP_KERNEL);
4748  }
4749  EXPORT_SYMBOL_GPL(locks_alloc_lock);
4750 @@ -191,6 +195,7 @@ void locks_free_lock(struct file_lock *f
4751         BUG_ON(!list_empty(&fl->fl_block));
4752         BUG_ON(!list_empty(&fl->fl_link));
4753  
4754 +       vx_locks_dec(fl);
4755         locks_release_private(fl);
4756         kmem_cache_free(filelock_cache, fl);
4757  }
4758 @@ -212,6 +217,7 @@ void locks_init_lock(struct file_lock *f
4759         fl->fl_start = fl->fl_end = 0;
4760         fl->fl_ops = NULL;
4761         fl->fl_lmops = NULL;
4762 +       fl->fl_xid = -1;
4763  }
4764  
4765  EXPORT_SYMBOL(locks_init_lock);
4766 @@ -263,6 +269,7 @@ void locks_copy_lock(struct file_lock *n
4767         new->fl_file = fl->fl_file;
4768         new->fl_ops = fl->fl_ops;
4769         new->fl_lmops = fl->fl_lmops;
4770 +       new->fl_xid = fl->fl_xid;
4771  
4772         locks_copy_private(new, fl);
4773  }
4774 @@ -301,6 +308,11 @@ static int flock_make_lock(struct file *
4775         fl->fl_flags = FL_FLOCK;
4776         fl->fl_type = type;
4777         fl->fl_end = OFFSET_MAX;
4778 +
4779 +       vxd_assert(filp->f_xid == vx_current_xid(),
4780 +               "f_xid(%d) == current(%d)", filp->f_xid, vx_current_xid());
4781 +       fl->fl_xid = filp->f_xid;
4782 +       vx_locks_inc(fl);
4783         
4784         *lock = fl;
4785         return 0;
4786 @@ -460,6 +472,7 @@ static int lease_init(struct file *filp,
4787  
4788         fl->fl_owner = current->files;
4789         fl->fl_pid = current->tgid;
4790 +       fl->fl_xid = vx_current_xid();
4791  
4792         fl->fl_file = filp;
4793         fl->fl_flags = FL_LEASE;
4794 @@ -479,6 +492,11 @@ static struct file_lock *lease_alloc(str
4795         if (fl == NULL)
4796                 return ERR_PTR(error);
4797  
4798 +       fl->fl_xid = vx_current_xid();
4799 +       if (filp)
4800 +               vxd_assert(filp->f_xid == fl->fl_xid,
4801 +                       "f_xid(%d) == fl_xid(%d)", filp->f_xid, fl->fl_xid);
4802 +       vx_locks_inc(fl);
4803         error = lease_init(filp, type, fl);
4804         if (error) {
4805                 locks_free_lock(fl);
4806 @@ -780,6 +798,7 @@ static int flock_lock_file(struct file *
4807                 lock_flocks();
4808         }
4809  
4810 +       new_fl->fl_xid = -1;
4811  find_conflict:
4812         for_each_lock(inode, before) {
4813                 struct file_lock *fl = *before;
4814 @@ -800,6 +819,7 @@ find_conflict:
4815                 goto out;
4816         locks_copy_lock(new_fl, request);
4817         locks_insert_lock(before, new_fl);
4818 +       vx_locks_inc(new_fl);
4819         new_fl = NULL;
4820         error = 0;
4821  
4822 @@ -810,7 +830,8 @@ out:
4823         return error;
4824  }
4825  
4826 -static int __posix_lock_file(struct inode *inode, struct file_lock *request, struct file_lock *conflock)
4827 +static int __posix_lock_file(struct inode *inode, struct file_lock *request,
4828 +       struct file_lock *conflock, xid_t xid)
4829  {
4830         struct file_lock *fl;
4831         struct file_lock *new_fl = NULL;
4832 @@ -820,6 +841,8 @@ static int __posix_lock_file(struct inod
4833         struct file_lock **before;
4834         int error, added = 0;
4835  
4836 +       vxd_assert(xid == vx_current_xid(),
4837 +               "xid(%d) == current(%d)", xid, vx_current_xid());
4838         /*
4839          * We may need two file_lock structures for this operation,
4840          * so we get them in advance to avoid races.
4841 @@ -830,7 +853,11 @@ static int __posix_lock_file(struct inod
4842             (request->fl_type != F_UNLCK ||
4843              request->fl_start != 0 || request->fl_end != OFFSET_MAX)) {
4844                 new_fl = locks_alloc_lock();
4845 +               new_fl->fl_xid = xid;
4846 +               vx_locks_inc(new_fl);
4847                 new_fl2 = locks_alloc_lock();
4848 +               new_fl2->fl_xid = xid;
4849 +               vx_locks_inc(new_fl2);
4850         }
4851  
4852         lock_flocks();
4853 @@ -1029,7 +1056,8 @@ static int __posix_lock_file(struct inod
4854  int posix_lock_file(struct file *filp, struct file_lock *fl,
4855                         struct file_lock *conflock)
4856  {
4857 -       return __posix_lock_file(filp->f_path.dentry->d_inode, fl, conflock);
4858 +       return __posix_lock_file(filp->f_path.dentry->d_inode,
4859 +               fl, conflock, filp->f_xid);
4860  }
4861  EXPORT_SYMBOL(posix_lock_file);
4862  
4863 @@ -1119,7 +1147,7 @@ int locks_mandatory_area(int read_write,
4864         fl.fl_end = offset + count - 1;
4865  
4866         for (;;) {
4867 -               error = __posix_lock_file(inode, &fl, NULL);
4868 +               error = __posix_lock_file(inode, &fl, NULL, filp->f_xid);
4869                 if (error != FILE_LOCK_DEFERRED)
4870                         break;
4871                 error = wait_event_interruptible(fl.fl_wait, !fl.fl_next);
4872 @@ -1432,6 +1460,7 @@ int generic_setlease(struct file *filp, 
4873                 goto out;
4874  
4875         locks_insert_lock(before, lease);
4876 +       vx_locks_inc(lease);
4877         return 0;
4878  
4879  out:
4880 @@ -1816,6 +1845,11 @@ int fcntl_setlk(unsigned int fd, struct 
4881         if (file_lock == NULL)
4882                 return -ENOLCK;
4883  
4884 +       vxd_assert(filp->f_xid == vx_current_xid(),
4885 +               "f_xid(%d) == current(%d)", filp->f_xid, vx_current_xid());
4886 +       file_lock->fl_xid = filp->f_xid;
4887 +       vx_locks_inc(file_lock);
4888 +
4889         /*
4890          * This might block, so we do it before checking the inode.
4891          */
4892 @@ -1934,6 +1968,11 @@ int fcntl_setlk64(unsigned int fd, struc
4893         if (file_lock == NULL)
4894                 return -ENOLCK;
4895  
4896 +       vxd_assert(filp->f_xid == vx_current_xid(),
4897 +               "f_xid(%d) == current(%d)", filp->f_xid, vx_current_xid());
4898 +       file_lock->fl_xid = filp->f_xid;
4899 +       vx_locks_inc(file_lock);
4900 +
4901         /*
4902          * This might block, so we do it before checking the inode.
4903          */
4904 @@ -2199,8 +2238,11 @@ static int locks_show(struct seq_file *f
4905  
4906         lock_get_status(f, fl, *((loff_t *)f->private), "");
4907  
4908 -       list_for_each_entry(bfl, &fl->fl_block, fl_block)
4909 +       list_for_each_entry(bfl, &fl->fl_block, fl_block) {
4910 +               if (!vx_check(fl->fl_xid, VS_WATCH_P | VS_IDENT))
4911 +                       continue;
4912                 lock_get_status(f, bfl, *((loff_t *)f->private), " ->");
4913 +       }
4914  
4915         return 0;
4916  }
4917 diff -NurpP --minimal linux-2.6.38.3/fs/namei.c linux-2.6.38.3-vs2.3.0.37-rc14/fs/namei.c
4918 --- linux-2.6.38.3/fs/namei.c   2011-03-15 18:07:32.000000000 +0100
4919 +++ linux-2.6.38.3-vs2.3.0.37-rc14/fs/namei.c   2011-03-15 18:17:37.000000000 +0100
4920 @@ -32,6 +32,14 @@
4921  #include <linux/fcntl.h>
4922  #include <linux/device_cgroup.h>
4923  #include <linux/fs_struct.h>
4924 +#include <linux/proc_fs.h>
4925 +#include <linux/vserver/inode.h>
4926 +#include <linux/vs_base.h>
4927 +#include <linux/vs_tag.h>
4928 +#include <linux/vs_cowbl.h>
4929 +#include <linux/vs_device.h>
4930 +#include <linux/vs_context.h>
4931 +#include <linux/pid_namespace.h>
4932  #include <asm/uaccess.h>
4933  
4934  #include "internal.h"
4935 @@ -166,6 +174,84 @@ void putname(const char *name)
4936  EXPORT_SYMBOL(putname);
4937  #endif
4938  
4939 +static inline int dx_barrier(const struct inode *inode)
4940 +{
4941 +       if (IS_BARRIER(inode) && !vx_check(0, VS_ADMIN | VS_WATCH)) {
4942 +               vxwprintk_task(1, "did hit the barrier.");
4943 +               return 1;
4944 +       }
4945 +       return 0;
4946 +}
4947 +
4948 +static int __dx_permission(const struct inode *inode, int mask)
4949 +{
4950 +       if (dx_barrier(inode))
4951 +               return -EACCES;
4952 +
4953 +       if (inode->i_sb->s_magic == DEVPTS_SUPER_MAGIC) {
4954 +               /* devpts is xid tagged */
4955 +               if (S_ISDIR(inode->i_mode) ||
4956 +                   vx_check((xid_t)inode->i_tag, VS_IDENT | VS_WATCH_P))
4957 +                       return 0;
4958 +
4959 +               /* just pretend we didn't find anything */
4960 +               return -ENOENT;
4961 +       }
4962 +       else if (inode->i_sb->s_magic == PROC_SUPER_MAGIC) {
4963 +               struct proc_dir_entry *de = PDE(inode);
4964 +
4965 +               if (de && !vx_hide_check(0, de->vx_flags))
4966 +                       goto out;
4967 +
4968 +               if ((mask & (MAY_WRITE | MAY_APPEND))) {
4969 +                       struct pid *pid;
4970 +                       struct task_struct *tsk;
4971 +
4972 +                       if (vx_check(0, VS_ADMIN | VS_WATCH_P) ||
4973 +                           vx_flags(VXF_STATE_SETUP, 0))
4974 +                               return 0;
4975 +
4976 +                       pid = PROC_I(inode)->pid;
4977 +                       if (!pid)
4978 +                               goto out;
4979 +
4980 +                       tsk = pid_task(pid, PIDTYPE_PID);
4981 +                       vxdprintk(VXD_CBIT(tag, 0), "accessing %p[#%u]",
4982 +                                 tsk, (tsk ? vx_task_xid(tsk) : 0));
4983 +                       if (tsk && vx_check(vx_task_xid(tsk), VS_IDENT | VS_WATCH_P))
4984 +                               return 0;
4985 +               }
4986 +               else {
4987 +                       /* FIXME: Should we block some entries here? */
4988 +                       return 0;
4989 +               }
4990 +       }
4991 +       else {
4992 +               if (dx_notagcheck(inode->i_sb) ||
4993 +                   dx_check(inode->i_tag, DX_HOSTID | DX_ADMIN | DX_WATCH |
4994 +                            DX_IDENT))
4995 +                       return 0;
4996 +       }
4997 +
4998 +out:
4999 +       return -EACCES;
5000 +}
5001 +
5002 +int dx_permission(const struct inode *inode, int mask)
5003 +{
5004 +       int ret = __dx_permission(inode, mask);
5005 +       if (unlikely(ret)) {
5006 +#ifndef        CONFIG_VSERVER_WARN_DEVPTS
5007 +               if (inode->i_sb->s_magic != DEVPTS_SUPER_MAGIC)
5008 +#endif
5009 +                   vxwprintk_task(1,
5010 +                       "denied [0x%x] access to inode %s:%p[#%d,%lu]",
5011 +                       mask, inode->i_sb->s_id, inode, inode->i_tag,
5012 +                       inode->i_ino);
5013 +       }
5014 +       return ret;
5015 +}
5016 +
5017  /*
5018   * This does basic POSIX ACL permission checking
5019   */
5020 @@ -271,10 +357,14 @@ int inode_permission(struct inode *inode
5021                 /*
5022                  * Nobody gets write access to an immutable file.
5023                  */
5024 -               if (IS_IMMUTABLE(inode))
5025 +               if (IS_IMMUTABLE(inode) && !IS_COW(inode))
5026                         return -EACCES;
5027         }
5028  
5029 +       retval = dx_permission(inode, mask);
5030 +       if (retval)
5031 +               return retval;
5032 +
5033         if (inode->i_op->permission)
5034                 retval = inode->i_op->permission(inode, mask, 0);
5035         else
5036 @@ -676,6 +766,9 @@ static inline int exec_permission(struct
5037  {
5038         int ret;
5039  
5040 +       if (dx_barrier(inode))
5041 +               return -EACCES;
5042 +
5043         if (inode->i_op->permission) {
5044                 ret = inode->i_op->permission(inode, MAY_EXEC, flags);
5045         } else {
5046 @@ -1162,7 +1255,8 @@ static void follow_dotdot(struct nameida
5047  
5048                 if (nd->path.dentry == nd->root.dentry &&
5049                     nd->path.mnt == nd->root.mnt) {
5050 -                       break;
5051 +                       /* for sane '/' avoid follow_mount() */
5052 +                       return;
5053                 }
5054                 if (nd->path.dentry != nd->path.mnt->mnt_root) {
5055                         /* rare case of legitimate dget_parent()... */
5056 @@ -1216,7 +1310,7 @@ static int do_lookup(struct nameidata *n
5057  {
5058         struct vfsmount *mnt = nd->path.mnt;
5059         struct dentry *dentry, *parent = nd->path.dentry;
5060 -       struct inode *dir;
5061 +       struct inode *dir, *d_inode;
5062         int err;
5063  
5064         /*
5065 @@ -1277,6 +1371,13 @@ found:
5066                 if (IS_ERR(dentry))
5067                         goto fail;
5068         }
5069 +
5070 +       d_inode = dentry->d_inode;
5071 +       if (!d_inode)
5072 +               goto done;
5073 +
5074 +       if (__dx_permission(d_inode, MAY_ACCESS))
5075 +               goto hidden;
5076  done:
5077         path->mnt = mnt;
5078         path->dentry = dentry;
5079 @@ -1288,6 +1389,18 @@ done:
5080         *inode = path->dentry->d_inode;
5081         return 0;
5082  
5083 +hidden:
5084 +#ifndef        CONFIG_VSERVER_WARN_DEVPTS
5085 +       if (d_inode->i_sb->s_magic != DEVPTS_SUPER_MAGIC)
5086 +#endif
5087 +           vxwprintk_task(1,
5088 +               "did lookup hidden %s:%p[#%d,%lu] " VS_Q("%s/%.*s") ".",
5089 +               d_inode->i_sb->s_id, d_inode, d_inode->i_tag, d_inode->i_ino,
5090 +               vxd_path(&nd->path), name->len, name->name);
5091 +
5092 +       dput(dentry);
5093 +       return -ENOENT;
5094 +
5095  need_lookup:
5096         dir = parent->d_inode;
5097         BUG_ON(nd->inode != dir);
5098 @@ -1982,7 +2095,7 @@ static int may_delete(struct inode *dir,
5099         if (IS_APPEND(dir))
5100                 return -EPERM;
5101         if (check_sticky(dir, victim->d_inode)||IS_APPEND(victim->d_inode)||
5102 -           IS_IMMUTABLE(victim->d_inode) || IS_SWAPFILE(victim->d_inode))
5103 +               IS_IXORUNLINK(victim->d_inode) || IS_SWAPFILE(victim->d_inode))
5104                 return -EPERM;
5105         if (isdir) {
5106                 if (!S_ISDIR(victim->d_inode->i_mode))
5107 @@ -2105,6 +2218,14 @@ int may_open(struct path *path, int acc_
5108                 break;
5109         }
5110  
5111 +#ifdef CONFIG_VSERVER_COWBL
5112 +       if (IS_COW(inode) && (flag & FMODE_WRITE)) {
5113 +               if (IS_COW_LINK(inode))
5114 +                       return -EMLINK;
5115 +               inode->i_flags &= ~(S_IXUNLINK|S_IMMUTABLE);
5116 +               mark_inode_dirty(inode);
5117 +       }
5118 +#endif
5119         error = inode_permission(inode, acc_mode);
5120         if (error)
5121                 return error;
5122 @@ -2215,7 +2336,8 @@ static int open_will_truncate(int flag, 
5123  }
5124  
5125  static struct file *finish_open(struct nameidata *nd,
5126 -                               int open_flag, int acc_mode)
5127 +                               int open_flag, int acc_mode,
5128 +                               const char *pathname)
5129  {
5130         struct file *filp;
5131         int will_truncate;
5132 @@ -2228,6 +2350,23 @@ static struct file *finish_open(struct n
5133                         goto exit;
5134         }
5135         error = may_open(&nd->path, acc_mode, open_flag);
5136 +#ifdef CONFIG_VSERVER_COWBL
5137 +       if (error == -EMLINK) {
5138 +               struct dentry *dentry;
5139 +               dentry = cow_break_link(pathname);
5140 +               if (IS_ERR(dentry)) {
5141 +                       error = PTR_ERR(dentry);
5142 +                       goto exit_cow;
5143 +               }
5144 +               dput(dentry);
5145 +               if (will_truncate)
5146 +                       mnt_drop_write(nd->path.mnt);
5147 +               release_open_intent(nd);
5148 +               path_put(&nd->path);
5149 +               return ERR_PTR(-EMLINK);
5150 +       }
5151 +exit_cow:
5152 +#endif
5153         if (error) {
5154                 if (will_truncate)
5155                         mnt_drop_write(nd->path.mnt);
5156 @@ -2375,7 +2514,7 @@ static struct file *do_last(struct namei
5157         if (S_ISDIR(nd->inode->i_mode))
5158                 goto exit;
5159  ok:
5160 -       filp = finish_open(nd, open_flag, acc_mode);
5161 +       filp = finish_open(nd, open_flag, acc_mode, pathname);
5162         return filp;
5163  
5164  exit_mutex_unlock:
5165 @@ -2402,7 +2541,12 @@ struct file *do_filp_open(int dfd, const
5166         int count = 0;
5167         int flag = open_to_namei_flags(open_flag);
5168         int flags;
5169 +#ifdef CONFIG_VSERVER_COWBL
5170 +       int rflag = flag;
5171 +       int rmode = mode;
5172  
5173 +restart:
5174 +#endif
5175         if (!(open_flag & O_CREAT))
5176                 mode = 0;
5177  
5178 @@ -2468,7 +2612,7 @@ struct file *do_filp_open(int dfd, const
5179                         goto out_path2;
5180         }
5181         audit_inode(pathname, nd.path.dentry);
5182 -       filp = finish_open(&nd, open_flag, acc_mode);
5183 +       filp = finish_open(&nd, open_flag, acc_mode, pathname);
5184  out2:
5185         release_open_intent(&nd);
5186         return filp;
5187 @@ -2510,6 +2654,13 @@ reval:
5188          */
5189         nd.flags = flags;
5190         filp = do_last(&nd, &path, open_flag, acc_mode, mode, pathname);
5191 +#ifdef CONFIG_VSERVER_COWBL
5192 +       if (unlikely(IS_ERR(filp) && PTR_ERR(filp) == -EMLINK)) {
5193 +               flag = rflag;
5194 +               mode = rmode;
5195 +               goto restart;
5196 +       }
5197 +#endif
5198         while (unlikely(!filp)) { /* trailing symlink */
5199                 struct path link = path;
5200                 struct inode *linki = link.dentry->d_inode;
5201 @@ -2544,6 +2695,13 @@ reval:
5202                 }
5203                 nd.flags &= ~LOOKUP_PARENT;
5204                 filp = do_last(&nd, &path, open_flag, acc_mode, mode, pathname);
5205 +#ifdef CONFIG_VSERVER_COWBL
5206 +               if (unlikely(IS_ERR(filp) && PTR_ERR(filp) == -EMLINK)) {
5207 +                       flag = rflag;
5208 +                       mode = rmode;
5209 +                       goto restart;
5210 +               }
5211 +#endif
5212                 if (linki->i_op->put_link)
5213                         linki->i_op->put_link(link.dentry, &nd, cookie);
5214                 path_put(&link);
5215 @@ -2642,9 +2800,17 @@ int vfs_mknod(struct inode *dir, struct 
5216         if (error)
5217                 return error;
5218  
5219 -       if ((S_ISCHR(mode) || S_ISBLK(mode)) && !capable(CAP_MKNOD))
5220 +       if (!(S_ISCHR(mode) || S_ISBLK(mode)))
5221 +               goto okay;
5222 +
5223 +       if (!capable(CAP_MKNOD))
5224                 return -EPERM;
5225  
5226 +       if (S_ISCHR(mode) && !vs_chrdev_perm(dev, DATTR_CREATE))
5227 +               return -EPERM;
5228 +       if (S_ISBLK(mode) && !vs_blkdev_perm(dev, DATTR_CREATE))
5229 +               return -EPERM;
5230 +okay:
5231         if (!dir->i_op->mknod)
5232                 return -EPERM;
5233  
5234 @@ -3107,7 +3273,7 @@ int vfs_link(struct dentry *old_dentry, 
5235         /*
5236          * A link to an append-only or immutable file cannot be created.
5237          */
5238 -       if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
5239 +       if (IS_APPEND(inode) || IS_IXORUNLINK(inode))
5240                 return -EPERM;
5241         if (!dir->i_op->link)
5242                 return -EPERM;
5243 @@ -3479,6 +3645,222 @@ int vfs_follow_link(struct nameidata *nd
5244         return __vfs_follow_link(nd, link);
5245  }
5246  
5247 +
5248 +#ifdef CONFIG_VSERVER_COWBL
5249 +
5250 +#include <linux/file.h>
5251 +
5252 +static inline
5253 +long do_cow_splice(struct file *in, struct file *out, size_t len)
5254 +{
5255 +       loff_t ppos = 0;
5256 +
5257 +       return do_splice_direct(in, &ppos, out, len, 0);
5258 +}
5259 +
5260 +struct dentry *cow_break_link(const char *pathname)
5261 +{
5262 +       int ret, mode, pathlen, redo = 0;
5263 +       struct nameidata old_nd, dir_nd;
5264 +       struct path old_path, new_path;
5265 +       struct dentry *dir, *res = NULL;
5266 +       struct file *old_file;
5267 +       struct file *new_file;
5268 +       char *to, *path, pad='\251';
5269 +       loff_t size;
5270 +
5271 +       vxdprintk(VXD_CBIT(misc, 1),
5272 +               "cow_break_link(" VS_Q("%s") ")", pathname);
5273 +       path = kmalloc(PATH_MAX, GFP_KERNEL);
5274 +       ret = -ENOMEM;
5275 +       if (!path)
5276 +               goto out;
5277 +
5278 +       /* old_nd will have refs to dentry and mnt */
5279 +       ret = path_lookup(pathname, LOOKUP_FOLLOW, &old_nd);
5280 +       vxdprintk(VXD_CBIT(misc, 2), "path_lookup(old): %d", ret);
5281 +       if (ret < 0)
5282 +               goto out_free_path;
5283 +
5284 +       old_path = old_nd.path;
5285 +       mode = old_path.dentry->d_inode->i_mode;
5286 +
5287 +       to = d_path(&old_path, path, PATH_MAX-2);
5288 +       pathlen = strlen(to);
5289 +       vxdprintk(VXD_CBIT(misc, 2),
5290 +               "old path " VS_Q("%s") " [" VS_Q("%.*s") ":%d]", to,
5291 +               old_path.dentry->d_name.len, old_path.dentry->d_name.name,
5292 +               old_path.dentry->d_name.len);
5293 +
5294 +       to[pathlen + 1] = 0;
5295 +retry:
5296 +       to[pathlen] = pad--;
5297 +       ret = -EMLINK;
5298 +       if (pad <= '\240')
5299 +               goto out_rel_old;
5300 +
5301 +       vxdprintk(VXD_CBIT(misc, 1), "temp copy " VS_Q("%s"), to);
5302 +       /* dir_nd will have refs to dentry and mnt */
5303 +       ret = path_lookup(to,
5304 +               LOOKUP_PARENT | LOOKUP_OPEN | LOOKUP_CREATE, &dir_nd);
5305 +       vxdprintk(VXD_CBIT(misc, 2),
5306 +               "path_lookup(new): %d", ret);
5307 +       if (ret < 0)
5308 +               goto retry;
5309 +
5310 +       /* this puppy downs the inode mutex */
5311 +       new_path.dentry = lookup_create(&dir_nd, 0);
5312 +       if (!new_path.dentry || IS_ERR(new_path.dentry)) {
5313 +               vxdprintk(VXD_CBIT(misc, 2),
5314 +                       "lookup_create(new): %p", new_path.dentry);
5315 +               mutex_unlock(&dir_nd.path.dentry->d_inode->i_mutex);
5316 +               path_put(&dir_nd.path);
5317 +               goto retry;
5318 +       }
5319 +       vxdprintk(VXD_CBIT(misc, 2),
5320 +               "lookup_create(new): %p [" VS_Q("%.*s") ":%d]",
5321 +               new_path.dentry,
5322 +               new_path.dentry->d_name.len, new_path.dentry->d_name.name,
5323 +               new_path.dentry->d_name.len);
5324 +       dir = dir_nd.path.dentry;
5325 +
5326 +       ret = vfs_create(dir_nd.path.dentry->d_inode, new_path.dentry, mode, &dir_nd);
5327 +       vxdprintk(VXD_CBIT(misc, 2),
5328 +               "vfs_create(new): %d", ret);
5329 +       if (ret == -EEXIST) {
5330 +               mutex_unlock(&dir->d_inode->i_mutex);
5331 +               dput(new_path.dentry);
5332 +               path_put(&dir_nd.path);
5333 +               goto retry;
5334 +       }
5335 +       else if (ret < 0)
5336 +               goto out_unlock_new;
5337 +
5338 +       /* drop out early, ret passes ENOENT */
5339 +       ret = -ENOENT;
5340 +       if ((redo = d_unhashed(old_path.dentry)))
5341 +               goto out_unlock_new;
5342 +
5343 +       new_path.mnt = dir_nd.path.mnt;
5344 +       dget(old_path.dentry);
5345 +       mntget(old_path.mnt);
5346 +       /* this one cleans up the dentry/mnt in case of failure */
5347 +       old_file = dentry_open(old_path.dentry, old_path.mnt,
5348 +               O_RDONLY, current_cred());
5349 +       vxdprintk(VXD_CBIT(misc, 2),
5350 +               "dentry_open(old): %p", old_file);
5351 +       if (!old_file || IS_ERR(old_file)) {
5352 +               res = IS_ERR(old_file) ? (void *) old_file : res;
5353 +               goto out_unlock_new;
5354 +       }
5355 +
5356 +       dget(new_path.dentry);
5357 +       mntget(new_path.mnt);
5358 +       /* this one cleans up the dentry/mnt in case of failure */
5359 +       new_file = dentry_open(new_path.dentry, new_path.mnt,
5360 +               O_WRONLY, current_cred());
5361 +       vxdprintk(VXD_CBIT(misc, 2),
5362 +               "dentry_open(new): %p", new_file);
5363 +
5364 +       ret = IS_ERR(new_file) ? PTR_ERR(new_file) : -ENOENT;
5365 +       if (!new_file || IS_ERR(new_file))
5366 +               goto out_fput_old;
5367 +
5368 +       size = i_size_read(old_file->f_dentry->d_inode);
5369 +       ret = do_cow_splice(old_file, new_file, size);
5370 +       vxdprintk(VXD_CBIT(misc, 2), "do_splice_direct: %d", ret);
5371 +       if (ret < 0) {
5372 +               goto out_fput_both;
5373 +       } else if (ret < size) {
5374 +               ret = -ENOSPC;
5375 +               goto out_fput_both;
5376 +       } else {
5377 +               struct inode *old_inode = old_path.dentry->d_inode;
5378 +               struct inode *new_inode = new_path.dentry->d_inode;
5379 +               struct iattr attr = {
5380 +                       .ia_uid = old_inode->i_uid,
5381 +                       .ia_gid = old_inode->i_gid,
5382 +                       .ia_valid = ATTR_UID | ATTR_GID
5383 +                       };
5384 +
5385 +               setattr_copy(new_inode, &attr);
5386 +               mark_inode_dirty(new_inode);
5387 +       }
5388 +
5389 +       mutex_lock(&old_path.dentry->d_inode->i_sb->s_vfs_rename_mutex);
5390 +
5391 +       /* drop out late */
5392 +       ret = -ENOENT;
5393 +       if ((redo = d_unhashed(old_path.dentry)))
5394 +               goto out_unlock;
5395 +
5396 +       vxdprintk(VXD_CBIT(misc, 2),
5397 +               "vfs_rename: [" VS_Q("%*s") ":%d] -> [" VS_Q("%*s") ":%d]",
5398 +               new_path.dentry->d_name.len, new_path.dentry->d_name.name,
5399 +               new_path.dentry->d_name.len,
5400 +               old_path.dentry->d_name.len, old_path.dentry->d_name.name,
5401 +               old_path.dentry->d_name.len);
5402 +       ret = vfs_rename(dir_nd.path.dentry->d_inode, new_path.dentry,
5403 +               old_nd.path.dentry->d_parent->d_inode, old_path.dentry);
5404 +       vxdprintk(VXD_CBIT(misc, 2), "vfs_rename: %d", ret);
5405 +       res = new_path.dentry;
5406 +
5407 +out_unlock:
5408 +       mutex_unlock(&old_path.dentry->d_inode->i_sb->s_vfs_rename_mutex);
5409 +
5410 +out_fput_both:
5411 +       vxdprintk(VXD_CBIT(misc, 3),
5412 +               "fput(new_file=%p[#%ld])", new_file,
5413 +               atomic_long_read(&new_file->f_count));
5414 +       fput(new_file);
5415 +
5416 +out_fput_old:
5417 +       vxdprintk(VXD_CBIT(misc, 3),
5418 +               "fput(old_file=%p[#%ld])", old_file,
5419 +               atomic_long_read(&old_file->f_count));
5420 +       fput(old_file);
5421 +
5422 +out_unlock_new:
5423 +       mutex_unlock(&dir->d_inode->i_mutex);
5424 +       if (!ret)
5425 +               goto out_redo;
5426 +
5427 +       /* error path cleanup */
5428 +       vfs_unlink(dir->d_inode, new_path.dentry);
5429 +       dput(new_path.dentry);
5430 +
5431 +out_redo:
5432 +       if (!redo)
5433 +               goto out_rel_both;
5434 +       /* lookup dentry once again */
5435 +       path_put(&old_nd.path);
5436 +       ret = path_lookup(pathname, LOOKUP_FOLLOW, &old_nd);
5437 +       if (ret)
5438 +               goto out_rel_both;
5439 +
5440 +       new_path.dentry = old_nd.path.dentry;
5441 +       vxdprintk(VXD_CBIT(misc, 2),
5442 +               "path_lookup(redo): %p [" VS_Q("%.*s") ":%d]",
5443 +               new_path.dentry,
5444 +               new_path.dentry->d_name.len, new_path.dentry->d_name.name,
5445 +               new_path.dentry->d_name.len);
5446 +       dget(new_path.dentry);
5447 +       res = new_path.dentry;
5448 +
5449 +out_rel_both:
5450 +       path_put(&dir_nd.path);
5451 +out_rel_old:
5452 +       path_put(&old_nd.path);
5453 +out_free_path:
5454 +       kfree(path);
5455 +out:
5456 +       if (ret)
5457 +               res = ERR_PTR(ret);
5458 +       return res;
5459 +}
5460 +
5461 +#endif
5462 +
5463  /* get the link contents into pagecache */
5464  static char *page_getlink(struct dentry * dentry, struct page **ppage)
5465  {
5466 diff -NurpP --minimal linux-2.6.38.3/fs/namespace.c linux-2.6.38.3-vs2.3.0.37-rc14/fs/namespace.c
5467 --- linux-2.6.38.3/fs/namespace.c       2011-04-15 10:30:30.000000000 +0200
5468 +++ linux-2.6.38.3-vs2.3.0.37-rc14/fs/namespace.c       2011-03-28 15:00:13.000000000 +0200
5469 @@ -31,6 +31,11 @@
5470  #include <linux/idr.h>
5471  #include <linux/fs_struct.h>
5472  #include <linux/fsnotify.h>
5473 +#include <linux/vs_base.h>
5474 +#include <linux/vs_context.h>
5475 +#include <linux/vs_tag.h>
5476 +#include <linux/vserver/space.h>
5477 +#include <linux/vserver/global.h>
5478  #include <asm/uaccess.h>
5479  #include <asm/unistd.h>
5480  #include "pnode.h"
5481 @@ -702,6 +707,7 @@ static struct vfsmount *clone_mnt(struct
5482                 mnt->mnt_root = dget(root);
5483                 mnt->mnt_mountpoint = mnt->mnt_root;
5484                 mnt->mnt_parent = mnt;
5485 +               mnt->mnt_tag = old->mnt_tag;
5486  
5487                 if (flag & CL_SLAVE) {
5488                         list_add(&mnt->mnt_slave, &old->mnt_slave_list);
5489 @@ -830,6 +836,31 @@ static inline void mangle(struct seq_fil
5490         seq_escape(m, s, " \t\n\\");
5491  }
5492  
5493 +static int mnt_is_reachable(struct vfsmount *mnt)
5494 +{
5495 +       struct path root;
5496 +       struct dentry *point;
5497 +       int ret;
5498 +
5499 +       if (mnt == mnt->mnt_ns->root)
5500 +               return 1;
5501 +
5502 +       br_read_lock(vfsmount_lock);
5503 +       root = current->fs->root;
5504 +       point = root.dentry;
5505 +
5506 +       while ((mnt != mnt->mnt_parent) && (mnt != root.mnt)) {
5507 +               point = mnt->mnt_mountpoint;
5508 +               mnt = mnt->mnt_parent;
5509 +       }
5510 +
5511 +       ret = (mnt == root.mnt) && is_subdir(point, root.dentry);
5512 +
5513 +       br_read_unlock(vfsmount_lock);
5514 +
5515 +       return ret;
5516 +}
5517 +
5518  /*
5519   * Simple .show_options callback for filesystems which don't want to
5520   * implement more complex mount option showing.
5521 @@ -932,6 +963,8 @@ static int show_sb_opts(struct seq_file 
5522                 { MS_SYNCHRONOUS, ",sync" },
5523                 { MS_DIRSYNC, ",dirsync" },
5524                 { MS_MANDLOCK, ",mand" },
5525 +               { MS_TAGGED, ",tag" },
5526 +               { MS_NOTAGCHECK, ",notagcheck" },
5527                 { 0, NULL }
5528         };
5529         const struct proc_fs_info *fs_infop;
5530 @@ -978,10 +1011,20 @@ static int show_vfsmnt(struct seq_file *
5531         int err = 0;
5532         struct path mnt_path = { .dentry = mnt->mnt_root, .mnt = mnt };
5533  
5534 -       mangle(m, mnt->mnt_devname ? mnt->mnt_devname : "none");
5535 -       seq_putc(m, ' ');
5536 -       seq_path(m, &mnt_path, " \t\n\\");
5537 -       seq_putc(m, ' ');
5538 +       if (vx_flags(VXF_HIDE_MOUNT, 0))
5539 +               return SEQ_SKIP;
5540 +       if (!mnt_is_reachable(mnt) && !vx_check(0, VS_WATCH_P))
5541 +               return SEQ_SKIP;
5542 +
5543 +       if (!vx_check(0, VS_ADMIN|VS_WATCH) &&
5544 +               mnt == current->fs->root.mnt) {
5545 +               seq_puts(m, "/dev/root / ");
5546 +       } else {
5547 +               mangle(m, mnt->mnt_devname ? mnt->mnt_devname : "none");
5548 +               seq_putc(m, ' ');
5549 +               seq_path(m, &mnt_path, " \t\n\\");
5550 +               seq_putc(m, ' ');
5551 +       }
5552         show_type(m, mnt->mnt_sb);
5553         seq_puts(m, __mnt_is_readonly(mnt) ? " ro" : " rw");
5554         err = show_sb_opts(m, mnt->mnt_sb);
5555 @@ -1011,6 +1054,11 @@ static int show_mountinfo(struct seq_fil
5556         struct path root = p->root;
5557         int err = 0;
5558  
5559 +       if (vx_flags(VXF_HIDE_MOUNT, 0))
5560 +               return SEQ_SKIP;
5561 +       if (!mnt_is_reachable(mnt) && !vx_check(0, VS_WATCH_P))
5562 +               return SEQ_SKIP;
5563 +
5564         seq_printf(m, "%i %i %u:%u ", mnt->mnt_id, mnt->mnt_parent->mnt_id,
5565                    MAJOR(sb->s_dev), MINOR(sb->s_dev));
5566         seq_dentry(m, mnt->mnt_root, " \t\n\\");
5567 @@ -1069,17 +1117,27 @@ static int show_vfsstat(struct seq_file 
5568         struct path mnt_path = { .dentry = mnt->mnt_root, .mnt = mnt };
5569         int err = 0;
5570  
5571 -       /* device */
5572 -       if (mnt->mnt_devname) {
5573 -               seq_puts(m, "device ");
5574 -               mangle(m, mnt->mnt_devname);
5575 -       } else
5576 -               seq_puts(m, "no device");
5577 +       if (vx_flags(VXF_HIDE_MOUNT, 0))
5578 +               return SEQ_SKIP;
5579 +       if (!mnt_is_reachable(mnt) && !vx_check(0, VS_WATCH_P))
5580 +               return SEQ_SKIP;
5581  
5582 -       /* mount point */
5583 -       seq_puts(m, " mounted on ");
5584 -       seq_path(m, &mnt_path, " \t\n\\");
5585 -       seq_putc(m, ' ');
5586 +       if (!vx_check(0, VS_ADMIN|VS_WATCH) &&
5587 +               mnt == current->fs->root.mnt) {
5588 +               seq_puts(m, "device /dev/root mounted on / ");
5589 +       } else {
5590 +               /* device */
5591 +               if (mnt->mnt_devname) {
5592 +                       seq_puts(m, "device ");
5593 +                       mangle(m, mnt->mnt_devname);
5594 +               } else
5595 +                       seq_puts(m, "no device");
5596 +
5597 +               /* mount point */
5598 +               seq_puts(m, " mounted on ");
5599 +               seq_path(m, &mnt_path, " \t\n\\");
5600 +               seq_putc(m, ' ');
5601 +       }
5602  
5603         /* file system type */
5604         seq_puts(m, "with fstype ");
5605 @@ -1337,7 +1395,7 @@ SYSCALL_DEFINE2(umount, char __user *, n
5606                 goto dput_and_out;
5607  
5608         retval = -EPERM;
5609 -       if (!capable(CAP_SYS_ADMIN))
5610 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SECURE_MOUNT))
5611                 goto dput_and_out;
5612  
5613         retval = do_umount(path.mnt, flags);
5614 @@ -1363,7 +1421,7 @@ SYSCALL_DEFINE1(oldumount, char __user *
5615  
5616  static int mount_is_safe(struct path *path)
5617  {
5618 -       if (capable(CAP_SYS_ADMIN))
5619 +       if (vx_capable(CAP_SYS_ADMIN, VXC_SECURE_MOUNT))
5620                 return 0;
5621         return -EPERM;
5622  #ifdef notyet
5623 @@ -1653,7 +1711,7 @@ static int do_change_type(struct path *p
5624         int type;
5625         int err = 0;
5626  
5627 -       if (!capable(CAP_SYS_ADMIN))
5628 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_NAMESPACE))
5629                 return -EPERM;
5630  
5631         if (path->dentry != path->mnt->mnt_root)
5632 @@ -1684,11 +1742,13 @@ static int do_change_type(struct path *p
5633   * do loopback mount.
5634   */
5635  static int do_loopback(struct path *path, char *old_name,
5636 -                               int recurse)
5637 +       tag_t tag, unsigned long flags, int mnt_flags)
5638  {
5639         struct path old_path;
5640         struct vfsmount *mnt = NULL;
5641         int err = mount_is_safe(path);
5642 +       int recurse = flags & MS_REC;
5643 +
5644         if (err)
5645                 return err;
5646         if (!old_name || !*old_name)
5647 @@ -1723,6 +1783,7 @@ static int do_loopback(struct path *path
5648                 br_write_unlock(vfsmount_lock);
5649                 release_mounts(&umount_list);
5650         }
5651 +       mnt->mnt_flags = mnt_flags;
5652  
5653  out:
5654         up_write(&namespace_sem);
5655 @@ -1753,12 +1814,12 @@ static int change_mount_flags(struct vfs
5656   * on it - tough luck.
5657   */
5658  static int do_remount(struct path *path, int flags, int mnt_flags,
5659 -                     void *data)
5660 +       void *data, xid_t xid)
5661  {
5662         int err;
5663         struct super_block *sb = path->mnt->mnt_sb;
5664  
5665 -       if (!capable(CAP_SYS_ADMIN))
5666 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SECURE_REMOUNT))
5667                 return -EPERM;
5668  
5669         if (!check_mnt(path->mnt))
5670 @@ -1802,7 +1863,7 @@ static int do_move_mount(struct path *pa
5671         struct path old_path, parent_path;
5672         struct vfsmount *p;
5673         int err = 0;
5674 -       if (!capable(CAP_SYS_ADMIN))
5675 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SECURE_MOUNT))
5676                 return -EPERM;
5677         if (!old_name || !*old_name)
5678                 return -EINVAL;
5679 @@ -1888,7 +1949,7 @@ static int do_new_mount(struct path *pat
5680                 return -EINVAL;
5681  
5682         /* we need capabilities... */
5683 -       if (!capable(CAP_SYS_ADMIN))
5684 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SECURE_MOUNT))
5685                 return -EPERM;
5686  
5687         mnt = do_kern_mount(type, flags, name, data);
5688 @@ -2194,6 +2255,7 @@ long do_mount(char *dev_name, char *dir_
5689         struct path path;
5690         int retval = 0;
5691         int mnt_flags = 0;
5692 +       tag_t tag = 0;
5693  
5694         /* Discard magic */
5695         if ((flags & MS_MGC_MSK) == MS_MGC_VAL)
5696 @@ -2221,6 +2283,12 @@ long do_mount(char *dev_name, char *dir_
5697         if (!(flags & MS_NOATIME))
5698                 mnt_flags |= MNT_RELATIME;
5699  
5700 +       if (dx_parse_tag(data_page, &tag, 1, &mnt_flags, &flags)) {
5701 +               /* FIXME: bind and re-mounts get the tag flag? */
5702 +               if (flags & (MS_BIND|MS_REMOUNT))
5703 +                       flags |= MS_TAGID;
5704 +       }
5705 +
5706         /* Separate the per-mountpoint flags */
5707         if (flags & MS_NOSUID)
5708                 mnt_flags |= MNT_NOSUID;
5709 @@ -2237,15 +2305,17 @@ long do_mount(char *dev_name, char *dir_
5710         if (flags & MS_RDONLY)
5711                 mnt_flags |= MNT_READONLY;
5712  
5713 +       if (!capable(CAP_SYS_ADMIN))
5714 +               mnt_flags |= MNT_NODEV;
5715         flags &= ~(MS_NOSUID | MS_NOEXEC | MS_NODEV | MS_ACTIVE | MS_BORN |
5716                    MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
5717                    MS_STRICTATIME);
5718  
5719         if (flags & MS_REMOUNT)
5720                 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
5721 -                                   data_page);
5722 +                                   data_page, tag);
5723         else if (flags & MS_BIND)
5724 -               retval = do_loopback(&path, dev_name, flags & MS_REC);
5725 +               retval = do_loopback(&path, dev_name, tag, flags, mnt_flags);
5726         else if (flags & (MS_SHARED | MS_PRIVATE | MS_SLAVE | MS_UNBINDABLE))
5727                 retval = do_change_type(&path, flags);
5728         else if (flags & MS_MOVE)
5729 @@ -2345,6 +2415,7 @@ static struct mnt_namespace *dup_mnt_ns(
5730                 q = next_mnt(q, new_ns->root);
5731         }
5732         up_write(&namespace_sem);
5733 +       atomic_inc(&vs_global_mnt_ns);
5734  
5735         if (rootmnt)
5736                 mntput(rootmnt);
5737 @@ -2484,9 +2555,10 @@ SYSCALL_DEFINE2(pivot_root, const char _
5738         down_write(&namespace_sem);
5739         mutex_lock(&old.dentry->d_inode->i_mutex);
5740         error = -EINVAL;
5741 -       if (IS_MNT_SHARED(old.mnt) ||
5742 +       if ((IS_MNT_SHARED(old.mnt) ||
5743                 IS_MNT_SHARED(new.mnt->mnt_parent) ||
5744 -               IS_MNT_SHARED(root.mnt->mnt_parent))
5745 +               IS_MNT_SHARED(root.mnt->mnt_parent)) &&
5746 +               !vx_flags(VXF_STATE_SETUP, 0))
5747                 goto out2;
5748         if (!check_mnt(root.mnt) || !check_mnt(new.mnt))
5749                 goto out2;
5750 @@ -2618,6 +2690,7 @@ void put_mnt_ns(struct mnt_namespace *ns
5751         br_write_unlock(vfsmount_lock);
5752         up_write(&namespace_sem);
5753         release_mounts(&umount_list);
5754 +       atomic_dec(&vs_global_mnt_ns);
5755         kfree(ns);
5756  }
5757  EXPORT_SYMBOL(put_mnt_ns);
5758 diff -NurpP --minimal linux-2.6.38.3/fs/nfs/client.c linux-2.6.38.3-vs2.3.0.37-rc14/fs/nfs/client.c
5759 --- linux-2.6.38.3/fs/nfs/client.c      2011-03-15 18:07:32.000000000 +0100
5760 +++ linux-2.6.38.3-vs2.3.0.37-rc14/fs/nfs/client.c      2011-02-02 22:20:25.000000000 +0100
5761 @@ -761,6 +761,9 @@ static int nfs_init_server_rpcclient(str
5762         if (server->flags & NFS_MOUNT_SOFT)
5763                 server->client->cl_softrtry = 1;
5764  
5765 +       server->client->cl_tag = 0;
5766 +       if (server->flags & NFS_MOUNT_TAGGED)
5767 +               server->client->cl_tag = 1;
5768         return 0;
5769  }
5770  
5771 @@ -934,6 +937,10 @@ static void nfs_server_set_fsinfo(struct
5772                 server->acdirmin = server->acdirmax = 0;
5773         }
5774  
5775 +       /* FIXME: needs fsinfo
5776 +       if (server->flags & NFS_MOUNT_TAGGED)
5777 +               sb->s_flags |= MS_TAGGED;       */
5778 +
5779         server->maxfilesize = fsinfo->maxfilesize;
5780  
5781         server->time_delta = fsinfo->time_delta;
5782 diff -NurpP --minimal linux-2.6.38.3/fs/nfs/dir.c linux-2.6.38.3-vs2.3.0.37-rc14/fs/nfs/dir.c
5783 --- linux-2.6.38.3/fs/nfs/dir.c 2011-03-15 18:07:32.000000000 +0100
5784 +++ linux-2.6.38.3-vs2.3.0.37-rc14/fs/nfs/dir.c 2011-01-29 02:49:21.000000000 +0100
5785 @@ -35,6 +35,7 @@
5786  #include <linux/sched.h>
5787  #include <linux/kmemleak.h>
5788  #include <linux/xattr.h>
5789 +#include <linux/vs_tag.h>
5790  
5791  #include "delegation.h"
5792  #include "iostat.h"
5793 @@ -1224,6 +1225,7 @@ static struct dentry *nfs_lookup(struct 
5794         if (IS_ERR(res))
5795                 goto out_unblock_sillyrename;
5796  
5797 +       dx_propagate_tag(nd, inode);
5798  no_entry:
5799         res = d_materialise_unique(dentry, inode);
5800         if (res != NULL) {
5801 diff -NurpP --minimal linux-2.6.38.3/fs/nfs/inode.c linux-2.6.38.3-vs2.3.0.37-rc14/fs/nfs/inode.c
5802 --- linux-2.6.38.3/fs/nfs/inode.c       2011-03-15 18:07:32.000000000 +0100
5803 +++ linux-2.6.38.3-vs2.3.0.37-rc14/fs/nfs/inode.c       2011-03-15 18:17:58.000000000 +0100
5804 @@ -38,6 +38,7 @@
5805  #include <linux/nfs_xdr.h>
5806  #include <linux/slab.h>
5807  #include <linux/compat.h>
5808 +#include <linux/vs_tag.h>
5809  
5810  #include <asm/system.h>
5811  #include <asm/uaccess.h>
5812 @@ -270,6 +271,8 @@ nfs_fhget(struct super_block *sb, struct
5813         if (inode->i_state & I_NEW) {
5814                 struct nfs_inode *nfsi = NFS_I(inode);
5815                 unsigned long now = jiffies;
5816 +               uid_t uid;
5817 +               gid_t gid;
5818  
5819                 /* We set i_ino for the few things that still rely on it,
5820                  * such as stat(2) */
5821 @@ -318,8 +321,8 @@ nfs_fhget(struct super_block *sb, struct
5822                 nfsi->change_attr = 0;
5823                 inode->i_size = 0;
5824                 inode->i_nlink = 0;
5825 -               inode->i_uid = -2;
5826 -               inode->i_gid = -2;
5827 +               uid = -2;
5828 +               gid = -2;
5829                 inode->i_blocks = 0;
5830                 memset(nfsi->cookieverf, 0, sizeof(nfsi->cookieverf));
5831  
5832 @@ -356,13 +359,13 @@ nfs_fhget(struct super_block *sb, struct
5833                 else if (nfs_server_capable(inode, NFS_CAP_NLINK))
5834                         nfsi->cache_validity |= NFS_INO_INVALID_ATTR;
5835                 if (fattr->valid & NFS_ATTR_FATTR_OWNER)
5836 -                       inode->i_uid = fattr->uid;
5837 +                       uid = fattr->uid;
5838                 else if (nfs_server_capable(inode, NFS_CAP_OWNER))
5839                         nfsi->cache_validity |= NFS_INO_INVALID_ATTR
5840                                 | NFS_INO_INVALID_ACCESS
5841                                 | NFS_INO_INVALID_ACL;
5842                 if (fattr->valid & NFS_ATTR_FATTR_GROUP)
5843 -                       inode->i_gid = fattr->gid;
5844 +                       gid = fattr->gid;
5845                 else if (nfs_server_capable(inode, NFS_CAP_OWNER_GROUP))
5846                         nfsi->cache_validity |= NFS_INO_INVALID_ATTR
5847                                 | NFS_INO_INVALID_ACCESS
5848 @@ -375,6 +378,11 @@ nfs_fhget(struct super_block *sb, struct
5849                          */
5850                         inode->i_blocks = nfs_calc_block_size(fattr->du.nfs3.used);
5851                 }
5852 +               inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
5853 +               inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
5854 +               inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid, 0);
5855 +                               /* maybe fattr->xid someday */
5856 +
5857                 nfsi->attrtimeo = NFS_MINATTRTIMEO(inode);
5858                 nfsi->attrtimeo_timestamp = now;
5859                 nfsi->access_cache = RB_ROOT;
5860 @@ -491,6 +499,8 @@ void nfs_setattr_update_inode(struct ino
5861                         inode->i_uid = attr->ia_uid;
5862                 if ((attr->ia_valid & ATTR_GID) != 0)
5863                         inode->i_gid = attr->ia_gid;
5864 +               if ((attr->ia_valid & ATTR_TAG) && IS_TAGGED(inode))
5865 +                       inode->i_tag = attr->ia_tag;
5866                 NFS_I(inode)->cache_validity |= NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL;
5867                 spin_unlock(&inode->i_lock);
5868         }
5869 @@ -939,6 +949,9 @@ static int nfs_check_inode_attributes(st
5870         struct nfs_inode *nfsi = NFS_I(inode);
5871         loff_t cur_size, new_isize;
5872         unsigned long invalid = 0;
5873 +       uid_t uid;
5874 +       gid_t gid;
5875 +       tag_t tag;
5876  
5877  
5878         /* Has the inode gone and changed behind our back? */
5879 @@ -962,13 +975,18 @@ static int nfs_check_inode_attributes(st
5880                         invalid |= NFS_INO_INVALID_ATTR|NFS_INO_REVAL_PAGECACHE;
5881         }
5882  
5883 +       uid = INOTAG_UID(DX_TAG(inode), fattr->uid, fattr->gid);
5884 +       gid = INOTAG_GID(DX_TAG(inode), fattr->uid, fattr->gid);
5885 +       tag = INOTAG_TAG(DX_TAG(inode), fattr->uid, fattr->gid, 0);
5886 +
5887         /* Have any file permissions changed? */
5888         if ((fattr->valid & NFS_ATTR_FATTR_MODE) && (inode->i_mode & S_IALLUGO) != (fattr->mode & S_IALLUGO))
5889                 invalid |= NFS_INO_INVALID_ATTR | NFS_INO_INVALID_ACCESS | NFS_INO_INVALID_ACL;
5890 -       if ((fattr->valid & NFS_ATTR_FATTR_OWNER) && inode->i_uid != fattr->uid)
5891 +       if ((fattr->valid & NFS_ATTR_FATTR_OWNER) && uid != fattr->uid)
5892                 invalid |= NFS_INO_INVALID_ATTR | NFS_INO_INVALID_ACCESS | NFS_INO_INVALID_ACL;
5893 -       if ((fattr->valid & NFS_ATTR_FATTR_GROUP) && inode->i_gid != fattr->gid)
5894 +       if ((fattr->valid & NFS_ATTR_FATTR_GROUP) && gid != fattr->gid)
5895                 invalid |= NFS_INO_INVALID_ATTR | NFS_INO_INVALID_ACCESS | NFS_INO_INVALID_ACL;
5896 +               /* maybe check for tag too? */
5897  
5898         /* Has the link count changed? */
5899         if ((fattr->valid & NFS_ATTR_FATTR_NLINK) && inode->i_nlink != fattr->nlink)
5900 @@ -1203,6 +1221,9 @@ static int nfs_update_inode(struct inode
5901         unsigned long invalid = 0;
5902         unsigned long now = jiffies;
5903         unsigned long save_cache_validity;
5904 +       uid_t uid;
5905 +       gid_t gid;
5906 +       tag_t tag;
5907  
5908         dfprintk(VFS, "NFS: %s(%s/%ld ct=%d info=0x%x)\n",
5909                         __func__, inode->i_sb->s_id, inode->i_ino,
5910 @@ -1305,6 +1326,9 @@ static int nfs_update_inode(struct inode
5911                                 | NFS_INO_REVAL_PAGECACHE
5912                                 | NFS_INO_REVAL_FORCED);
5913  
5914 +       uid = INOTAG_UID(DX_TAG(inode), fattr->uid, fattr->gid);
5915 +       gid = INOTAG_GID(DX_TAG(inode), fattr->uid, fattr->gid);
5916 +       tag = INOTAG_TAG(DX_TAG(inode), fattr->uid, fattr->gid, 0);
5917  
5918         if (fattr->valid & NFS_ATTR_FATTR_ATIME)
5919                 memcpy(&inode->i_atime, &fattr->atime, sizeof(inode->i_atime));
5920 @@ -1326,9 +1350,9 @@ static int nfs_update_inode(struct inode
5921                                 | NFS_INO_REVAL_FORCED);
5922  
5923         if (fattr->valid & NFS_ATTR_FATTR_OWNER) {
5924 -               if (inode->i_uid != fattr->uid) {
5925 +               if (uid != fattr->uid) {
5926                         invalid |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL;
5927 -                       inode->i_uid = fattr->uid;
5928 +                       uid = fattr->uid;
5929                 }
5930         } else if (server->caps & NFS_CAP_OWNER)
5931                 invalid |= save_cache_validity & (NFS_INO_INVALID_ATTR
5932 @@ -1337,9 +1361,9 @@ static int nfs_update_inode(struct inode
5933                                 | NFS_INO_REVAL_FORCED);
5934  
5935         if (fattr->valid & NFS_ATTR_FATTR_GROUP) {
5936 -               if (inode->i_gid != fattr->gid) {
5937 +               if (gid != fattr->gid) {
5938                         invalid |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL;
5939 -                       inode->i_gid = fattr->gid;
5940 +                       gid = fattr->gid;
5941                 }
5942         } else if (server->caps & NFS_CAP_OWNER_GROUP)
5943                 invalid |= save_cache_validity & (NFS_INO_INVALID_ATTR
5944 @@ -1347,6 +1371,10 @@ static int nfs_update_inode(struct inode
5945                                 | NFS_INO_INVALID_ACL
5946                                 | NFS_INO_REVAL_FORCED);
5947  
5948 +       inode->i_uid = uid;
5949 +       inode->i_gid = gid;
5950 +       inode->i_tag = tag;
5951 +
5952         if (fattr->valid & NFS_ATTR_FATTR_NLINK) {
5953                 if (inode->i_nlink != fattr->nlink) {
5954                         invalid |= NFS_INO_INVALID_ATTR;
5955 diff -NurpP --minimal linux-2.6.38.3/fs/nfs/nfs3xdr.c linux-2.6.38.3-vs2.3.0.37-rc14/fs/nfs/nfs3xdr.c
5956 --- linux-2.6.38.3/fs/nfs/nfs3xdr.c     2011-03-15 18:07:32.000000000 +0100
5957 +++ linux-2.6.38.3-vs2.3.0.37-rc14/fs/nfs/nfs3xdr.c     2011-02-02 22:20:25.000000000 +0100
5958 @@ -20,6 +20,7 @@
5959  #include <linux/nfs3.h>
5960  #include <linux/nfs_fs.h>
5961  #include <linux/nfsacl.h>
5962 +#include <linux/vs_tag.h>
5963  #include "internal.h"
5964  
5965  #define NFSDBG_FACILITY                NFSDBG_XDR
5966 @@ -562,7 +563,8 @@ static __be32 *xdr_decode_nfstime3(__be3
5967   *             set_mtime       mtime;
5968   *     };
5969   */
5970 -static void encode_sattr3(struct xdr_stream *xdr, const struct iattr *attr)
5971 +static void encode_sattr3(struct xdr_stream *xdr,
5972 +       const struct iattr *attr, int tag)
5973  {
5974         u32 nbytes;
5975         __be32 *p;
5976 @@ -594,15 +596,19 @@ static void encode_sattr3(struct xdr_str
5977         } else
5978                 *p++ = xdr_zero;
5979  
5980 -       if (attr->ia_valid & ATTR_UID) {
5981 +       if (attr->ia_valid & ATTR_UID ||
5982 +               (tag && (attr->ia_valid & ATTR_TAG))) {
5983                 *p++ = xdr_one;
5984 -               *p++ = cpu_to_be32(attr->ia_uid);
5985 +               *p++ = cpu_to_be32(TAGINO_UID(tag,
5986 +                       attr->ia_uid, attr->ia_tag));
5987         } else
5988                 *p++ = xdr_zero;
5989  
5990 -       if (attr->ia_valid & ATTR_GID) {
5991 +       if (attr->ia_valid & ATTR_GID ||
5992 +               (tag && (attr->ia_valid & ATTR_TAG))) {
5993                 *p++ = xdr_one;
5994 -               *p++ = cpu_to_be32(attr->ia_gid);
5995 +               *p++ = cpu_to_be32(TAGINO_GID(tag,
5996 +                       attr->ia_gid, attr->ia_tag));
5997         } else
5998                 *p++ = xdr_zero;
5999  
6000 @@ -878,7 +884,7 @@ static void nfs3_xdr_enc_setattr3args(st
6001                                       const struct nfs3_sattrargs *args)
6002  {
6003         encode_nfs_fh3(xdr, args->fh);
6004 -       encode_sattr3(xdr, args->sattr);
6005 +       encode_sattr3(xdr, args->sattr, req->rq_task->tk_client->cl_tag);
6006         encode_sattrguard3(xdr, args);
6007  }
6008  
6009 @@ -1028,13 +1034,13 @@ static void nfs3_xdr_enc_write3args(stru
6010   *     };
6011   */
6012  static void encode_createhow3(struct xdr_stream *xdr,
6013 -                             const struct nfs3_createargs *args)
6014 +       const struct nfs3_createargs *args, int tag)
6015  {
6016         encode_uint32(xdr, args->createmode);
6017         switch (args->createmode) {
6018         case NFS3_CREATE_UNCHECKED:
6019         case NFS3_CREATE_GUARDED:
6020 -               encode_sattr3(xdr, args->sattr);
6021 +               encode_sattr3(xdr, args->sattr, tag);
6022                 break;
6023         case NFS3_CREATE_EXCLUSIVE:
6024                 encode_createverf3(xdr, args->verifier);
6025 @@ -1049,7 +1055,7 @@ static void nfs3_xdr_enc_create3args(str
6026                                      const struct nfs3_createargs *args)
6027  {
6028         encode_diropargs3(xdr, args->fh, args->name, args->len);
6029 -       encode_createhow3(xdr, args);
6030 +       encode_createhow3(xdr, args, req->rq_task->tk_client->cl_tag);
6031  }
6032  
6033  /*
6034 @@ -1065,7 +1071,7 @@ static void nfs3_xdr_enc_mkdir3args(stru
6035                                     const struct nfs3_mkdirargs *args)
6036  {
6037         encode_diropargs3(xdr, args->fh, args->name, args->len);
6038 -       encode_sattr3(xdr, args->sattr);
6039 +       encode_sattr3(xdr, args->sattr, req->rq_task->tk_client->cl_tag);
6040  }
6041  
6042  /*
6043 @@ -1082,9 +1088,9 @@ static void nfs3_xdr_enc_mkdir3args(stru
6044   *     };
6045   */
6046  static void encode_symlinkdata3(struct xdr_stream *xdr,
6047 -                               const struct nfs3_symlinkargs *args)
6048 +       const struct nfs3_symlinkargs *args, int tag)
6049  {
6050 -       encode_sattr3(xdr, args->sattr);
6051 +       encode_sattr3(xdr, args->sattr, tag);
6052         encode_nfspath3(xdr, args->pages, args->pathlen);
6053  }
6054  
6055 @@ -1093,7 +1099,7 @@ static void nfs3_xdr_enc_symlink3args(st
6056                                       const struct nfs3_symlinkargs *args)
6057  {
6058         encode_diropargs3(xdr, args->fromfh, args->fromname, args->fromlen);
6059 -       encode_symlinkdata3(xdr, args);
6060 +       encode_symlinkdata3(xdr, args, req->rq_task->tk_client->cl_tag);
6061  }
6062  
6063  /*
6064 @@ -1121,24 +1127,24 @@ static void nfs3_xdr_enc_symlink3args(st
6065   *     };
6066   */
6067  static void encode_devicedata3(struct xdr_stream *xdr,
6068 -                              const struct nfs3_mknodargs *args)
6069 +       const struct nfs3_mknodargs *args, int tag)
6070  {
6071 -       encode_sattr3(xdr, args->sattr);
6072 +       encode_sattr3(xdr, args->sattr, tag);
6073         encode_specdata3(xdr, args->rdev);
6074  }
6075  
6076  static void encode_mknoddata3(struct xdr_stream *xdr,
6077 -                             const struct nfs3_mknodargs *args)
6078 +       const struct nfs3_mknodargs *args, int tag)
6079  {
6080         encode_ftype3(xdr, args->type);
6081         switch (args->type) {
6082         case NF3CHR:
6083         case NF3BLK:
6084 -               encode_devicedata3(xdr, args);
6085 +               encode_devicedata3(xdr, args, tag);
6086                 break;
6087         case NF3SOCK:
6088         case NF3FIFO:
6089 -               encode_sattr3(xdr, args->sattr);
6090 +               encode_sattr3(xdr, args->sattr, tag);
6091                 break;
6092         case NF3REG:
6093         case NF3DIR:
6094 @@ -1153,7 +1159,7 @@ static void nfs3_xdr_enc_mknod3args(stru
6095                                     const struct nfs3_mknodargs *args)
6096  {
6097         encode_diropargs3(xdr, args->fh, args->name, args->len);
6098 -       encode_mknoddata3(xdr, args);
6099 +       encode_mknoddata3(xdr, args, req->rq_task->tk_client->cl_tag);
6100  }
6101  
6102  /*
6103 diff -NurpP --minimal linux-2.6.38.3/fs/nfs/super.c linux-2.6.38.3-vs2.3.0.37-rc14/fs/nfs/super.c
6104 --- linux-2.6.38.3/fs/nfs/super.c       2011-03-15 18:07:32.000000000 +0100
6105 +++ linux-2.6.38.3-vs2.3.0.37-rc14/fs/nfs/super.c       2011-01-29 02:01:07.000000000 +0100
6106 @@ -53,6 +53,7 @@
6107  #include <linux/nfs_xdr.h>
6108  #include <linux/magic.h>
6109  #include <linux/parser.h>
6110 +#include <linux/vs_tag.h>
6111  
6112  #include <asm/system.h>
6113  #include <asm/uaccess.h>
6114 @@ -86,6 +87,7 @@ enum {
6115         Opt_sharecache, Opt_nosharecache,
6116         Opt_resvport, Opt_noresvport,
6117         Opt_fscache, Opt_nofscache,
6118 +       Opt_tag, Opt_notag,
6119  
6120         /* Mount options that take integer arguments */
6121         Opt_port,
6122 @@ -99,6 +101,7 @@ enum {
6123         Opt_mountvers,
6124         Opt_nfsvers,
6125         Opt_minorversion,
6126 +       Opt_tagid,
6127  
6128         /* Mount options that take string arguments */
6129         Opt_sec, Opt_proto, Opt_mountproto, Opt_mounthost,
6130 @@ -179,6 +182,10 @@ static const match_table_t nfs_mount_opt
6131         { Opt_fscache_uniq, "fsc=%s" },
6132         { Opt_local_lock, "local_lock=%s" },
6133  
6134 +       { Opt_tag, "tag" },
6135 +       { Opt_notag, "notag" },
6136 +       { Opt_tagid, "tagid=%u" },
6137 +
6138         { Opt_err, NULL }
6139  };
6140  
6141 @@ -642,6 +649,7 @@ static void nfs_show_mount_options(struc
6142                 { NFS_MOUNT_NORDIRPLUS, ",nordirplus", "" },
6143                 { NFS_MOUNT_UNSHARED, ",nosharecache", "" },
6144                 { NFS_MOUNT_NORESVPORT, ",noresvport", "" },
6145 +               { NFS_MOUNT_TAGGED, ",tag", "" },
6146                 { 0, NULL, NULL }
6147         };
6148         const struct proc_nfs_info *nfs_infop;
6149 @@ -1122,6 +1130,14 @@ static int nfs_parse_mount_options(char 
6150                         kfree(mnt->fscache_uniq);
6151                         mnt->fscache_uniq = NULL;
6152                         break;
6153 +#ifndef CONFIG_TAGGING_NONE
6154 +               case Opt_tag:
6155 +                       mnt->flags |= NFS_MOUNT_TAGGED;
6156 +                       break;
6157 +               case Opt_notag:
6158 +                       mnt->flags &= ~NFS_MOUNT_TAGGED;
6159 +                       break;
6160 +#endif
6161  
6162                 /*
6163                  * options that take numeric values
6164 @@ -1306,6 +1322,12 @@ static int nfs_parse_mount_options(char 
6165                                 goto out_invalid_value;
6166                         mnt->minorversion = option;
6167                         break;
6168 +#ifdef CONFIG_PROPAGATE
6169 +               case Opt_tagid:
6170 +                       /* use args[0] */
6171 +                       nfs_data.flags |= NFS_MOUNT_TAGGED;
6172 +                       break;
6173 +#endif
6174  
6175                 /*
6176                  * options that take text values
6177 diff -NurpP --minimal linux-2.6.38.3/fs/nfsd/auth.c linux-2.6.38.3-vs2.3.0.37-rc14/fs/nfsd/auth.c
6178 --- linux-2.6.38.3/fs/nfsd/auth.c       2010-02-25 11:52:05.000000000 +0100
6179 +++ linux-2.6.38.3-vs2.3.0.37-rc14/fs/nfsd/auth.c       2011-01-29 02:01:07.000000000 +0100
6180 @@ -1,6 +1,7 @@
6181  /* Copyright (C) 1995, 1996 Olaf Kirch <okir@monad.swb.de> */
6182  
6183  #include <linux/sched.h>
6184 +#include <linux/vs_tag.h>
6185  #include "nfsd.h"
6186  #include "auth.h"
6187  
6188 @@ -36,6 +37,9 @@ int nfsd_setuser(struct svc_rqst *rqstp,
6189  
6190         new->fsuid = rqstp->rq_cred.cr_uid;
6191         new->fsgid = rqstp->rq_cred.cr_gid;
6192 +       /* FIXME: this desperately needs a tag :)
6193 +       new->xid = (xid_t)INOTAG_TAG(DX_TAG_NFSD, cred.cr_uid, cred.cr_gid, 0);
6194 +                       */
6195  
6196         rqgi = rqstp->rq_cred.cr_group_info;
6197  
6198 diff -NurpP --minimal linux-2.6.38.3/fs/nfsd/nfs3xdr.c linux-2.6.38.3-vs2.3.0.37-rc14/fs/nfsd/nfs3xdr.c
6199 --- linux-2.6.38.3/fs/nfsd/nfs3xdr.c    2011-01-05 21:50:25.000000000 +0100
6200 +++ linux-2.6.38.3-vs2.3.0.37-rc14/fs/nfsd/nfs3xdr.c    2011-01-29 02:01:07.000000000 +0100
6201 @@ -7,6 +7,7 @@
6202   */
6203  
6204  #include <linux/namei.h>
6205 +#include <linux/vs_tag.h>
6206  #include "xdr3.h"
6207  #include "auth.h"
6208  
6209 @@ -95,6 +96,8 @@ static __be32 *
6210  decode_sattr3(__be32 *p, struct iattr *iap)
6211  {
6212         u32     tmp;
6213 +       uid_t   uid = 0;
6214 +       gid_t   gid = 0;
6215  
6216         iap->ia_valid = 0;
6217  
6218 @@ -104,12 +107,15 @@ decode_sattr3(__be32 *p, struct iattr *i
6219         }
6220         if (*p++) {
6221                 iap->ia_valid |= ATTR_UID;
6222 -               iap->ia_uid = ntohl(*p++);
6223 +               uid = ntohl(*p++);
6224         }
6225         if (*p++) {
6226                 iap->ia_valid |= ATTR_GID;
6227 -               iap->ia_gid = ntohl(*p++);
6228 +               gid = ntohl(*p++);
6229         }
6230 +       iap->ia_uid = INOTAG_UID(DX_TAG_NFSD, uid, gid);
6231 +       iap->ia_gid = INOTAG_GID(DX_TAG_NFSD, uid, gid);
6232 +       iap->ia_tag = INOTAG_TAG(DX_TAG_NFSD, uid, gid, 0);
6233         if (*p++) {
6234                 u64     newsize;
6235  
6236 @@ -165,8 +171,12 @@ encode_fattr3(struct svc_rqst *rqstp, __
6237         *p++ = htonl(nfs3_ftypes[(stat->mode & S_IFMT) >> 12]);
6238         *p++ = htonl((u32) stat->mode);
6239         *p++ = htonl((u32) stat->nlink);
6240 -       *p++ = htonl((u32) nfsd_ruid(rqstp, stat->uid));
6241 -       *p++ = htonl((u32) nfsd_rgid(rqstp, stat->gid));
6242 +       *p++ = htonl((u32) nfsd_ruid(rqstp,
6243 +               TAGINO_UID(0 /* FIXME: DX_TAG(dentry->d_inode) */,
6244 +               stat->uid, stat->tag)));
6245 +       *p++ = htonl((u32) nfsd_rgid(rqstp,
6246 +               TAGINO_GID(0 /* FIXME: DX_TAG(dentry->d_inode) */,
6247 +               stat->gid, stat->tag)));
6248         if (S_ISLNK(stat->mode) && stat->size > NFS3_MAXPATHLEN) {
6249                 p = xdr_encode_hyper(p, (u64) NFS3_MAXPATHLEN);
6250         } else {
6251 diff -NurpP --minimal linux-2.6.38.3/fs/nfsd/nfs4xdr.c linux-2.6.38.3-vs2.3.0.37-rc14/fs/nfsd/nfs4xdr.c
6252 --- linux-2.6.38.3/fs/nfsd/nfs4xdr.c    2011-04-15 10:30:30.000000000 +0200
6253 +++ linux-2.6.38.3-vs2.3.0.37-rc14/fs/nfsd/nfs4xdr.c    2011-03-28 15:00:13.000000000 +0200
6254 @@ -45,6 +45,7 @@
6255  #include <linux/statfs.h>
6256  #include <linux/utsname.h>
6257  #include <linux/sunrpc/svcauth_gss.h>
6258 +#include <linux/vs_tag.h>
6259  
6260  #include "idmap.h"
6261  #include "acl.h"
6262 @@ -2095,14 +2096,18 @@ out_acl:
6263                 WRITE32(stat.nlink);
6264         }
6265         if (bmval1 & FATTR4_WORD1_OWNER) {
6266 -               status = nfsd4_encode_user(rqstp, stat.uid, &p, &buflen);
6267 +               status = nfsd4_encode_user(rqstp,
6268 +                       TAGINO_UID(DX_TAG(dentry->d_inode),
6269 +                       stat.uid, stat.tag), &p, &buflen);
6270                 if (status == nfserr_resource)
6271                         goto out_resource;
6272                 if (status)
6273                         goto out;
6274         }
6275         if (bmval1 & FATTR4_WORD1_OWNER_GROUP) {
6276 -               status = nfsd4_encode_group(rqstp, stat.gid, &p, &buflen);
6277 +               status = nfsd4_encode_group(rqstp,
6278 +                       TAGINO_GID(DX_TAG(dentry->d_inode),
6279 +                       stat.gid, stat.tag), &p, &buflen);
6280                 if (status == nfserr_resource)
6281                         goto out_resource;
6282                 if (status)
6283 diff -NurpP --minimal linux-2.6.38.3/fs/nfsd/nfsxdr.c linux-2.6.38.3-vs2.3.0.37-rc14/fs/nfsd/nfsxdr.c
6284 --- linux-2.6.38.3/fs/nfsd/nfsxdr.c     2010-02-25 11:52:05.000000000 +0100
6285 +++ linux-2.6.38.3-vs2.3.0.37-rc14/fs/nfsd/nfsxdr.c     2011-01-29 02:01:07.000000000 +0100
6286 @@ -6,6 +6,7 @@
6287  
6288  #include "xdr.h"
6289  #include "auth.h"
6290 +#include <linux/vs_tag.h>
6291  
6292  #define NFSDDBG_FACILITY               NFSDDBG_XDR
6293  
6294 @@ -88,6 +89,8 @@ static __be32 *
6295  decode_sattr(__be32 *p, struct iattr *iap)
6296  {
6297         u32     tmp, tmp1;
6298 +       uid_t   uid = 0;
6299 +       gid_t   gid = 0;
6300  
6301         iap->ia_valid = 0;
6302  
6303 @@ -101,12 +104,15 @@ decode_sattr(__be32 *p, struct iattr *ia
6304         }
6305         if ((tmp = ntohl(*p++)) != (u32)-1) {
6306                 iap->ia_valid |= ATTR_UID;
6307 -               iap->ia_uid = tmp;
6308 +               uid = tmp;
6309         }
6310         if ((tmp = ntohl(*p++)) != (u32)-1) {
6311                 iap->ia_valid |= ATTR_GID;
6312 -               iap->ia_gid = tmp;
6313 +               gid = tmp;
6314         }
6315 +       iap->ia_uid = INOTAG_UID(DX_TAG_NFSD, uid, gid);
6316 +       iap->ia_gid = INOTAG_GID(DX_TAG_NFSD, uid, gid);
6317 +       iap->ia_tag = INOTAG_TAG(DX_TAG_NFSD, uid, gid, 0);
6318         if ((tmp = ntohl(*p++)) != (u32)-1) {
6319                 iap->ia_valid |= ATTR_SIZE;
6320                 iap->ia_size = tmp;
6321 @@ -151,8 +157,10 @@ encode_fattr(struct svc_rqst *rqstp, __b
6322         *p++ = htonl(nfs_ftypes[type >> 12]);
6323         *p++ = htonl((u32) stat->mode);
6324         *p++ = htonl((u32) stat->nlink);
6325 -       *p++ = htonl((u32) nfsd_ruid(rqstp, stat->uid));
6326 -       *p++ = htonl((u32) nfsd_rgid(rqstp, stat->gid));
6327 +       *p++ = htonl((u32) nfsd_ruid(rqstp,
6328 +               TAGINO_UID(DX_TAG(dentry->d_inode), stat->uid, stat->tag)));
6329 +       *p++ = htonl((u32) nfsd_rgid(rqstp,
6330 +               TAGINO_GID(DX_TAG(dentry->d_inode), stat->gid, stat->tag)));
6331  
6332         if (S_ISLNK(type) && stat->size > NFS_MAXPATHLEN) {
6333                 *p++ = htonl(NFS_MAXPATHLEN);
6334 diff -NurpP --minimal linux-2.6.38.3/fs/ocfs2/dlmglue.c linux-2.6.38.3-vs2.3.0.37-rc14/fs/ocfs2/dlmglue.c
6335 --- linux-2.6.38.3/fs/ocfs2/dlmglue.c   2011-01-05 21:50:26.000000000 +0100
6336 +++ linux-2.6.38.3-vs2.3.0.37-rc14/fs/ocfs2/dlmglue.c   2011-01-29 02:01:07.000000000 +0100
6337 @@ -2114,6 +2114,7 @@ static void __ocfs2_stuff_meta_lvb(struc
6338         lvb->lvb_iclusters = cpu_to_be32(oi->ip_clusters);
6339         lvb->lvb_iuid      = cpu_to_be32(inode->i_uid);
6340         lvb->lvb_igid      = cpu_to_be32(inode->i_gid);
6341 +       lvb->lvb_itag      = cpu_to_be16(inode->i_tag);
6342         lvb->lvb_imode     = cpu_to_be16(inode->i_mode);
6343         lvb->lvb_inlink    = cpu_to_be16(inode->i_nlink);
6344         lvb->lvb_iatime_packed  =
6345 @@ -2168,6 +2169,7 @@ static void ocfs2_refresh_inode_from_lvb
6346  
6347         inode->i_uid     = be32_to_cpu(lvb->lvb_iuid);
6348         inode->i_gid     = be32_to_cpu(lvb->lvb_igid);
6349 +       inode->i_tag     = be16_to_cpu(lvb->lvb_itag);
6350         inode->i_mode    = be16_to_cpu(lvb->lvb_imode);
6351         inode->i_nlink   = be16_to_cpu(lvb->lvb_inlink);
6352         ocfs2_unpack_timespec(&inode->i_atime,
6353 diff -NurpP --minimal linux-2.6.38.3/fs/ocfs2/dlmglue.h linux-2.6.38.3-vs2.3.0.37-rc14/fs/ocfs2/dlmglue.h
6354 --- linux-2.6.38.3/fs/ocfs2/dlmglue.h   2010-10-21 13:07:50.000000000 +0200
6355 +++ linux-2.6.38.3-vs2.3.0.37-rc14/fs/ocfs2/dlmglue.h   2011-01-29 02:01:07.000000000 +0100
6356 @@ -46,7 +46,8 @@ struct ocfs2_meta_lvb {
6357         __be16       lvb_inlink;
6358         __be32       lvb_iattr;
6359         __be32       lvb_igeneration;
6360 -       __be32       lvb_reserved2;
6361 +       __be16       lvb_itag;
6362 +       __be16       lvb_reserved2;
6363  };
6364  
6365  #define OCFS2_QINFO_LVB_VERSION 1
6366 diff -NurpP --minimal linux-2.6.38.3/fs/ocfs2/file.c linux-2.6.38.3-vs2.3.0.37-rc14/fs/ocfs2/file.c
6367 --- linux-2.6.38.3/fs/ocfs2/file.c      2011-03-15 18:07:33.000000000 +0100
6368 +++ linux-2.6.38.3-vs2.3.0.37-rc14/fs/ocfs2/file.c      2011-01-29 02:01:07.000000000 +0100
6369 @@ -1126,13 +1126,15 @@ int ocfs2_setattr(struct dentry *dentry,
6370                 mlog(0, "uid change: %d\n", attr->ia_uid);
6371         if (attr->ia_valid & ATTR_GID)
6372                 mlog(0, "gid change: %d\n", attr->ia_gid);
6373 +       if (attr->ia_valid & ATTR_TAG)
6374 +               mlog(0, "tag change: %d\n", attr->ia_tag);
6375         if (attr->ia_valid & ATTR_SIZE)
6376                 mlog(0, "size change...\n");
6377         if (attr->ia_valid & (ATTR_ATIME | ATTR_MTIME | ATTR_CTIME))
6378                 mlog(0, "time change...\n");
6379  
6380  #define OCFS2_VALID_ATTRS (ATTR_ATIME | ATTR_MTIME | ATTR_CTIME | ATTR_SIZE \
6381 -                          | ATTR_GID | ATTR_UID | ATTR_MODE)
6382 +                          | ATTR_GID | ATTR_UID | ATTR_TAG | ATTR_MODE)
6383         if (!(attr->ia_valid & OCFS2_VALID_ATTRS)) {
6384                 mlog(0, "can't handle attrs: 0x%x\n", attr->ia_valid);
6385                 return 0;
6386 diff -NurpP --minimal linux-2.6.38.3/fs/ocfs2/inode.c linux-2.6.38.3-vs2.3.0.37-rc14/fs/ocfs2/inode.c
6387 --- linux-2.6.38.3/fs/ocfs2/inode.c     2011-03-15 18:07:33.000000000 +0100
6388 +++ linux-2.6.38.3-vs2.3.0.37-rc14/fs/ocfs2/inode.c     2011-01-29 02:01:07.000000000 +0100
6389 @@ -28,6 +28,7 @@
6390  #include <linux/highmem.h>
6391  #include <linux/pagemap.h>
6392  #include <linux/quotaops.h>
6393 +#include <linux/vs_tag.h>
6394  
6395  #include <asm/byteorder.h>
6396  
6397 @@ -78,11 +79,13 @@ void ocfs2_set_inode_flags(struct inode 
6398  {
6399         unsigned int flags = OCFS2_I(inode)->ip_attr;
6400  
6401 -       inode->i_flags &= ~(S_IMMUTABLE |
6402 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
6403                 S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
6404  
6405         if (flags & OCFS2_IMMUTABLE_FL)
6406                 inode->i_flags |= S_IMMUTABLE;
6407 +       if (flags & OCFS2_IXUNLINK_FL)
6408 +               inode->i_flags |= S_IXUNLINK;
6409  
6410         if (flags & OCFS2_SYNC_FL)
6411                 inode->i_flags |= S_SYNC;
6412 @@ -92,25 +95,44 @@ void ocfs2_set_inode_flags(struct inode 
6413                 inode->i_flags |= S_NOATIME;
6414         if (flags & OCFS2_DIRSYNC_FL)
6415                 inode->i_flags |= S_DIRSYNC;
6416 +
6417 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
6418 +
6419 +       if (flags & OCFS2_BARRIER_FL)
6420 +               inode->i_vflags |= V_BARRIER;
6421 +       if (flags & OCFS2_COW_FL)
6422 +               inode->i_vflags |= V_COW;
6423  }
6424  
6425  /* Propagate flags from i_flags to OCFS2_I(inode)->ip_attr */
6426  void ocfs2_get_inode_flags(struct ocfs2_inode_info *oi)
6427  {
6428         unsigned int flags = oi->vfs_inode.i_flags;
6429 +       unsigned int vflags = oi->vfs_inode.i_vflags;
6430 +
6431 +       oi->ip_attr &= ~(OCFS2_SYNC_FL | OCFS2_APPEND_FL |
6432 +                       OCFS2_IMMUTABLE_FL | OCFS2_IXUNLINK_FL |
6433 +                       OCFS2_NOATIME_FL | OCFS2_DIRSYNC_FL |
6434 +                       OCFS2_BARRIER_FL | OCFS2_COW_FL);
6435 +
6436 +       if (flags & S_IMMUTABLE)
6437 +               oi->ip_attr |= OCFS2_IMMUTABLE_FL;
6438 +       if (flags & S_IXUNLINK)
6439 +               oi->ip_attr |= OCFS2_IXUNLINK_FL;
6440  
6441 -       oi->ip_attr &= ~(OCFS2_SYNC_FL|OCFS2_APPEND_FL|
6442 -                       OCFS2_IMMUTABLE_FL|OCFS2_NOATIME_FL|OCFS2_DIRSYNC_FL);
6443         if (flags & S_SYNC)
6444                 oi->ip_attr |= OCFS2_SYNC_FL;
6445         if (flags & S_APPEND)
6446                 oi->ip_attr |= OCFS2_APPEND_FL;
6447 -       if (flags & S_IMMUTABLE)
6448 -               oi->ip_attr |= OCFS2_IMMUTABLE_FL;
6449         if (flags & S_NOATIME)
6450                 oi->ip_attr |= OCFS2_NOATIME_FL;
6451         if (flags & S_DIRSYNC)
6452                 oi->ip_attr |= OCFS2_DIRSYNC_FL;
6453 +
6454 +       if (vflags & V_BARRIER)
6455 +               oi->ip_attr |= OCFS2_BARRIER_FL;
6456 +       if (vflags & V_COW)
6457 +               oi->ip_attr |= OCFS2_COW_FL;
6458  }
6459  
6460  struct inode *ocfs2_ilookup(struct super_block *sb, u64 blkno)
6461 @@ -245,6 +267,8 @@ void ocfs2_populate_inode(struct inode *
6462         struct super_block *sb;
6463         struct ocfs2_super *osb;
6464         int use_plocks = 1;
6465 +       uid_t uid;
6466 +       gid_t gid;
6467  
6468         mlog_entry("(0x%p, size:%llu)\n", inode,
6469                    (unsigned long long)le64_to_cpu(fe->i_size));
6470 @@ -276,8 +300,12 @@ void ocfs2_populate_inode(struct inode *
6471         inode->i_generation = le32_to_cpu(fe->i_generation);
6472         inode->i_rdev = huge_decode_dev(le64_to_cpu(fe->id1.dev1.i_rdev));
6473         inode->i_mode = le16_to_cpu(fe->i_mode);
6474 -       inode->i_uid = le32_to_cpu(fe->i_uid);
6475 -       inode->i_gid = le32_to_cpu(fe->i_gid);
6476 +       uid = le32_to_cpu(fe->i_uid);
6477 +       gid = le32_to_cpu(fe->i_gid);
6478 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
6479 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
6480 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid,
6481 +               /* le16_to_cpu(raw_inode->i_raw_tag)i */ 0);
6482  
6483         /* Fast symlinks will have i_size but no allocated clusters. */
6484         if (S_ISLNK(inode->i_mode) && !fe->i_clusters)
6485 diff -NurpP --minimal linux-2.6.38.3/fs/ocfs2/inode.h linux-2.6.38.3-vs2.3.0.37-rc14/fs/ocfs2/inode.h
6486 --- linux-2.6.38.3/fs/ocfs2/inode.h     2011-01-05 21:50:26.000000000 +0100
6487 +++ linux-2.6.38.3-vs2.3.0.37-rc14/fs/ocfs2/inode.h     2011-01-29 02:01:07.000000000 +0100
6488 @@ -151,6 +151,7 @@ struct buffer_head *ocfs2_bread(struct i
6489  
6490  void ocfs2_set_inode_flags(struct inode *inode);
6491  void ocfs2_get_inode_flags(struct ocfs2_inode_info *oi);
6492 +int ocfs2_sync_flags(struct inode *inode, int, int);
6493  
6494  static inline blkcnt_t ocfs2_inode_sector_count(struct inode *inode)
6495  {
6496 diff -NurpP --minimal linux-2.6.38.3/fs/ocfs2/ioctl.c linux-2.6.38.3-vs2.3.0.37-rc14/fs/ocfs2/ioctl.c
6497 --- linux-2.6.38.3/fs/ocfs2/ioctl.c     2011-01-05 21:50:26.000000000 +0100
6498 +++ linux-2.6.38.3-vs2.3.0.37-rc14/fs/ocfs2/ioctl.c     2011-01-29 02:01:07.000000000 +0100
6499 @@ -63,7 +63,41 @@ static int ocfs2_get_inode_attr(struct i
6500         return status;
6501  }
6502  
6503 -static int ocfs2_set_inode_attr(struct inode *inode, unsigned flags,
6504 +int ocfs2_sync_flags(struct inode *inode, int flags, int vflags)
6505 +{
6506 +       struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
6507 +       struct buffer_head *bh = NULL;
6508 +       handle_t *handle = NULL;
6509 +       int status;
6510 +
6511 +       status = ocfs2_inode_lock(inode, &bh, 1);
6512 +       if (status < 0) {
6513 +               mlog_errno(status);
6514 +               return status;
6515 +       }
6516 +       handle = ocfs2_start_trans(osb, OCFS2_INODE_UPDATE_CREDITS);
6517 +       if (IS_ERR(handle)) {
6518 +               status = PTR_ERR(handle);
6519 +               mlog_errno(status);
6520 +               goto bail_unlock;
6521 +       }
6522 +
6523 +       inode->i_flags = flags;
6524 +       inode->i_vflags = vflags;
6525 +       ocfs2_get_inode_flags(OCFS2_I(inode));
6526 +
6527 +       status = ocfs2_mark_inode_dirty(handle, inode, bh);
6528 +       if (status < 0)
6529 +               mlog_errno(status);
6530 +
6531 +       ocfs2_commit_trans(osb, handle);
6532 +bail_unlock:
6533 +       ocfs2_inode_unlock(inode, 1);
6534 +       brelse(bh);
6535 +       return status;
6536 +}
6537 +
6538 +int ocfs2_set_inode_attr(struct inode *inode, unsigned flags,
6539                                 unsigned mask)
6540  {
6541         struct ocfs2_inode_info *ocfs2_inode = OCFS2_I(inode);
6542 @@ -88,6 +122,11 @@ static int ocfs2_set_inode_attr(struct i
6543         if (!S_ISDIR(inode->i_mode))
6544                 flags &= ~OCFS2_DIRSYNC_FL;
6545  
6546 +       if (IS_BARRIER(inode)) {
6547 +               vxwprintk_task(1, "messing with the barrier.");
6548 +               goto bail_unlock;
6549 +       }
6550 +
6551         handle = ocfs2_start_trans(osb, OCFS2_INODE_UPDATE_CREDITS);
6552         if (IS_ERR(handle)) {
6553                 status = PTR_ERR(handle);
6554 @@ -451,6 +490,7 @@ bail:
6555         return status;
6556  }
6557  
6558 +
6559  long ocfs2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
6560  {
6561         struct inode *inode = filp->f_path.dentry->d_inode;
6562 diff -NurpP --minimal linux-2.6.38.3/fs/ocfs2/namei.c linux-2.6.38.3-vs2.3.0.37-rc14/fs/ocfs2/namei.c
6563 --- linux-2.6.38.3/fs/ocfs2/namei.c     2011-03-15 18:07:33.000000000 +0100
6564 +++ linux-2.6.38.3-vs2.3.0.37-rc14/fs/ocfs2/namei.c     2011-01-29 02:01:07.000000000 +0100
6565 @@ -41,6 +41,7 @@
6566  #include <linux/slab.h>
6567  #include <linux/highmem.h>
6568  #include <linux/quotaops.h>
6569 +#include <linux/vs_tag.h>
6570  
6571  #define MLOG_MASK_PREFIX ML_NAMEI
6572  #include <cluster/masklog.h>
6573 @@ -485,6 +486,7 @@ static int __ocfs2_mknod_locked(struct i
6574         struct ocfs2_dinode *fe = NULL;
6575         struct ocfs2_extent_list *fel;
6576         u16 feat;
6577 +       tag_t tag;
6578  
6579         *new_fe_bh = NULL;
6580  
6581 @@ -522,8 +524,11 @@ static int __ocfs2_mknod_locked(struct i
6582         fe->i_suballoc_loc = cpu_to_le64(suballoc_loc);
6583         fe->i_suballoc_bit = cpu_to_le16(suballoc_bit);
6584         fe->i_suballoc_slot = cpu_to_le16(inode_ac->ac_alloc_slot);
6585 -       fe->i_uid = cpu_to_le32(inode->i_uid);
6586 -       fe->i_gid = cpu_to_le32(inode->i_gid);
6587 +
6588 +       tag = dx_current_fstag(osb->sb);
6589 +       fe->i_uid = cpu_to_le32(TAGINO_UID(DX_TAG(inode), inode->i_uid, tag));
6590 +       fe->i_gid = cpu_to_le32(TAGINO_GID(DX_TAG(inode), inode->i_gid, tag));
6591 +       inode->i_tag = tag;
6592         fe->i_mode = cpu_to_le16(inode->i_mode);
6593         if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode))
6594                 fe->id1.dev1.i_rdev = cpu_to_le64(huge_encode_dev(dev));
6595 diff -NurpP --minimal linux-2.6.38.3/fs/ocfs2/ocfs2.h linux-2.6.38.3-vs2.3.0.37-rc14/fs/ocfs2/ocfs2.h
6596 --- linux-2.6.38.3/fs/ocfs2/ocfs2.h     2011-03-15 18:07:33.000000000 +0100
6597 +++ linux-2.6.38.3-vs2.3.0.37-rc14/fs/ocfs2/ocfs2.h     2011-01-29 02:01:07.000000000 +0100
6598 @@ -267,6 +267,7 @@ enum ocfs2_mount_options
6599                                                      writes */
6600         OCFS2_MOUNT_HB_NONE = 1 << 13, /* No heartbeat */
6601         OCFS2_MOUNT_HB_GLOBAL = 1 << 14, /* Global heartbeat */
6602 +       OCFS2_MOUNT_TAGGED = 1 << 15, /* use tagging */
6603  };
6604  
6605  #define OCFS2_OSB_SOFT_RO                      0x0001
6606 diff -NurpP --minimal linux-2.6.38.3/fs/ocfs2/ocfs2_fs.h linux-2.6.38.3-vs2.3.0.37-rc14/fs/ocfs2/ocfs2_fs.h
6607 --- linux-2.6.38.3/fs/ocfs2/ocfs2_fs.h  2011-01-05 21:50:26.000000000 +0100
6608 +++ linux-2.6.38.3-vs2.3.0.37-rc14/fs/ocfs2/ocfs2_fs.h  2011-01-29 02:01:07.000000000 +0100
6609 @@ -266,6 +266,11 @@
6610  #define OCFS2_TOPDIR_FL                        FS_TOPDIR_FL    /* Top of directory hierarchies*/
6611  #define OCFS2_RESERVED_FL              FS_RESERVED_FL  /* reserved for ext2 lib */
6612  
6613 +#define OCFS2_IXUNLINK_FL              FS_IXUNLINK_FL  /* Immutable invert on unlink */
6614 +
6615 +#define OCFS2_BARRIER_FL               FS_BARRIER_FL   /* Barrier for chroot() */
6616 +#define OCFS2_COW_FL                   FS_COW_FL       /* Copy on Write marker */
6617 +
6618  #define OCFS2_FL_VISIBLE               FS_FL_USER_VISIBLE      /* User visible flags */
6619  #define OCFS2_FL_MODIFIABLE            FS_FL_USER_MODIFIABLE   /* User modifiable flags */
6620  
6621 diff -NurpP --minimal linux-2.6.38.3/fs/ocfs2/super.c linux-2.6.38.3-vs2.3.0.37-rc14/fs/ocfs2/super.c
6622 --- linux-2.6.38.3/fs/ocfs2/super.c     2011-03-15 18:07:33.000000000 +0100
6623 +++ linux-2.6.38.3-vs2.3.0.37-rc14/fs/ocfs2/super.c     2011-03-07 16:53:27.000000000 +0100
6624 @@ -181,6 +181,7 @@ enum {
6625         Opt_coherency_full,
6626         Opt_resv_level,
6627         Opt_dir_resv_level,
6628 +       Opt_tag, Opt_notag, Opt_tagid,
6629         Opt_err,
6630  };
6631  
6632 @@ -212,6 +213,9 @@ static const match_table_t tokens = {
6633         {Opt_coherency_full, "coherency=full"},
6634         {Opt_resv_level, "resv_level=%u"},
6635         {Opt_dir_resv_level, "dir_resv_level=%u"},
6636 +       {Opt_tag, "tag"},
6637 +       {Opt_notag, "notag"},
6638 +       {Opt_tagid, "tagid=%u"},
6639         {Opt_err, NULL}
6640  };
6641  
6642 @@ -666,6 +670,13 @@ static int ocfs2_remount(struct super_bl
6643                 goto out;
6644         }
6645  
6646 +       if ((osb->s_mount_opt & OCFS2_MOUNT_TAGGED) !=
6647 +           (parsed_options.mount_opt & OCFS2_MOUNT_TAGGED)) {
6648 +               ret = -EINVAL;
6649 +               mlog(ML_ERROR, "Cannot change tagging on remount\n");
6650 +               goto out;
6651 +       }
6652 +
6653         /* We're going to/from readonly mode. */
6654         if ((*flags & MS_RDONLY) != (sb->s_flags & MS_RDONLY)) {
6655                 /* Disable quota accounting before remounting RO */
6656 @@ -1183,6 +1194,9 @@ static int ocfs2_fill_super(struct super
6657  
6658         ocfs2_complete_mount_recovery(osb);
6659  
6660 +       if (osb->s_mount_opt & OCFS2_MOUNT_TAGGED)
6661 +               sb->s_flags |= MS_TAGGED;
6662 +
6663         if (ocfs2_mount_local(osb))
6664                 snprintf(nodestr, sizeof(nodestr), "local");
6665         else
6666 @@ -1514,6 +1528,20 @@ static int ocfs2_parse_options(struct su
6667                             option < OCFS2_MAX_RESV_LEVEL)
6668                                 mopt->dir_resv_level = option;
6669                         break;
6670 +#ifndef CONFIG_TAGGING_NONE
6671 +               case Opt_tag:
6672 +                       mopt->mount_opt |= OCFS2_MOUNT_TAGGED;
6673 +                       break;
6674 +               case Opt_notag:
6675 +                       mopt->mount_opt &= ~OCFS2_MOUNT_TAGGED;
6676 +                       break;
6677 +#endif
6678 +#ifdef CONFIG_PROPAGATE
6679 +               case Opt_tagid:
6680 +                       /* use args[0] */
6681 +                       mopt->mount_opt |= OCFS2_MOUNT_TAGGED;
6682 +                       break;
6683 +#endif
6684                 default:
6685                         mlog(ML_ERROR,
6686                              "Unrecognized mount option \"%s\" "
6687 diff -NurpP --minimal linux-2.6.38.3/fs/open.c linux-2.6.38.3-vs2.3.0.37-rc14/fs/open.c
6688 --- linux-2.6.38.3/fs/open.c    2011-03-15 18:07:33.000000000 +0100
6689 +++ linux-2.6.38.3-vs2.3.0.37-rc14/fs/open.c    2011-03-15 18:15:06.000000000 +0100
6690 @@ -30,6 +30,11 @@
6691  #include <linux/fs_struct.h>
6692  #include <linux/ima.h>
6693  #include <linux/dnotify.h>
6694 +#include <linux/vs_base.h>
6695 +#include <linux/vs_limit.h>
6696 +#include <linux/vs_tag.h>
6697 +#include <linux/vs_cowbl.h>
6698 +#include <linux/vserver/dlimit.h>
6699  
6700  #include "internal.h"
6701  
6702 @@ -494,6 +499,12 @@ SYSCALL_DEFINE3(fchmodat, int, dfd, cons
6703         error = user_path_at(dfd, filename, LOOKUP_FOLLOW, &path);
6704         if (error)
6705                 goto out;
6706 +
6707 +#ifdef CONFIG_VSERVER_COWBL
6708 +       error = cow_check_and_break(&path);
6709 +       if (error)
6710 +               goto dput_and_out;
6711 +#endif
6712         inode = path.dentry->d_inode;
6713  
6714         error = mnt_want_write(path.mnt);
6715 @@ -531,11 +542,11 @@ static int chown_common(struct path *pat
6716         newattrs.ia_valid =  ATTR_CTIME;
6717         if (user != (uid_t) -1) {
6718                 newattrs.ia_valid |= ATTR_UID;
6719 -               newattrs.ia_uid = user;
6720 +               newattrs.ia_uid = dx_map_uid(user);
6721         }
6722         if (group != (gid_t) -1) {
6723                 newattrs.ia_valid |= ATTR_GID;
6724 -               newattrs.ia_gid = group;
6725 +               newattrs.ia_gid = dx_map_gid(group);
6726         }
6727         if (!S_ISDIR(inode->i_mode))
6728                 newattrs.ia_valid |=
6729 @@ -560,6 +571,10 @@ SYSCALL_DEFINE3(chown, const char __user
6730         error = mnt_want_write(path.mnt);
6731         if (error)
6732                 goto out_release;
6733 +#ifdef CONFIG_VSERVER_COWBL
6734 +       error = cow_check_and_break(&path);
6735 +       if (!error)
6736 +#endif
6737         error = chown_common(&path, user, group);
6738         mnt_drop_write(path.mnt);
6739  out_release:
6740 @@ -585,6 +600,10 @@ SYSCALL_DEFINE5(fchownat, int, dfd, cons
6741         error = mnt_want_write(path.mnt);
6742         if (error)
6743                 goto out_release;
6744 +#ifdef CONFIG_VSERVER_COWBL
6745 +       error = cow_check_and_break(&path);
6746 +       if (!error)
6747 +#endif
6748         error = chown_common(&path, user, group);
6749         mnt_drop_write(path.mnt);
6750  out_release:
6751 @@ -604,6 +623,10 @@ SYSCALL_DEFINE3(lchown, const char __use
6752         error = mnt_want_write(path.mnt);
6753         if (error)
6754                 goto out_release;
6755 +#ifdef CONFIG_VSERVER_COWBL
6756 +       error = cow_check_and_break(&path);
6757 +       if (!error)
6758 +#endif
6759         error = chown_common(&path, user, group);
6760         mnt_drop_write(path.mnt);
6761  out_release:
6762 @@ -852,6 +875,7 @@ static void __put_unused_fd(struct files
6763         __FD_CLR(fd, fdt->open_fds);
6764         if (fd < files->next_fd)
6765                 files->next_fd = fd;
6766 +       vx_openfd_dec(fd);
6767  }
6768  
6769  void put_unused_fd(unsigned int fd)
6770 diff -NurpP --minimal linux-2.6.38.3/fs/proc/array.c linux-2.6.38.3-vs2.3.0.37-rc14/fs/proc/array.c
6771 --- linux-2.6.38.3/fs/proc/array.c      2011-04-15 10:30:30.000000000 +0200
6772 +++ linux-2.6.38.3-vs2.3.0.37-rc14/fs/proc/array.c      2011-03-28 15:00:13.000000000 +0200
6773 @@ -81,6 +81,8 @@
6774  #include <linux/pid_namespace.h>
6775  #include <linux/ptrace.h>
6776  #include <linux/tracehook.h>
6777 +#include <linux/vs_context.h>
6778 +#include <linux/vs_network.h>
6779  
6780  #include <asm/pgtable.h>
6781  #include <asm/processor.h>
6782 @@ -170,6 +172,9 @@ static inline void task_state(struct seq
6783         rcu_read_lock();
6784         ppid = pid_alive(p) ?
6785                 task_tgid_nr_ns(rcu_dereference(p->real_parent), ns) : 0;
6786 +       if (unlikely(vx_current_initpid(p->pid)))
6787 +               ppid = 0;
6788 +
6789         tpid = 0;
6790         if (pid_alive(p)) {
6791                 struct task_struct *tracer = tracehook_tracer_task(p);
6792 @@ -287,7 +292,7 @@ static inline void task_sig(struct seq_f
6793  }
6794  
6795  static void render_cap_t(struct seq_file *m, const char *header,
6796 -                       kernel_cap_t *a)
6797 +                       struct vx_info *vxi, kernel_cap_t *a)
6798  {
6799         unsigned __capi;
6800  
6801 @@ -312,10 +317,11 @@ static inline void task_cap(struct seq_f
6802         cap_bset        = cred->cap_bset;
6803         rcu_read_unlock();
6804  
6805 -       render_cap_t(m, "CapInh:\t", &cap_inheritable);
6806 -       render_cap_t(m, "CapPrm:\t", &cap_permitted);
6807 -       render_cap_t(m, "CapEff:\t", &cap_effective);
6808 -       render_cap_t(m, "CapBnd:\t", &cap_bset);
6809 +       /* FIXME: maybe move the p->vx_info masking to __task_cred() ? */
6810 +       render_cap_t(m, "CapInh:\t", p->vx_info, &cap_inheritable);
6811 +       render_cap_t(m, "CapPrm:\t", p->vx_info, &cap_permitted);
6812 +       render_cap_t(m, "CapEff:\t", p->vx_info, &cap_effective);
6813 +       render_cap_t(m, "CapBnd:\t", p->vx_info, &cap_bset);
6814  }
6815  
6816  static inline void task_context_switch_counts(struct seq_file *m,
6817 @@ -337,6 +343,42 @@ static void task_cpus_allowed(struct seq
6818         seq_putc(m, '\n');
6819  }
6820  
6821 +int proc_pid_nsproxy(struct seq_file *m, struct pid_namespace *ns,
6822 +                       struct pid *pid, struct task_struct *task)
6823 +{
6824 +       seq_printf(m,   "Proxy:\t%p(%c)\n"
6825 +                       "Count:\t%u\n"
6826 +                       "uts:\t%p(%c)\n"
6827 +                       "ipc:\t%p(%c)\n"
6828 +                       "mnt:\t%p(%c)\n"
6829 +                       "pid:\t%p(%c)\n"
6830 +                       "net:\t%p(%c)\n",
6831 +                       task->nsproxy,
6832 +                       (task->nsproxy == init_task.nsproxy ? 'I' : '-'),
6833 +                       atomic_read(&task->nsproxy->count),
6834 +                       task->nsproxy->uts_ns,
6835 +                       (task->nsproxy->uts_ns == init_task.nsproxy->uts_ns ? 'I' : '-'),
6836 +                       task->nsproxy->ipc_ns,
6837 +                       (task->nsproxy->ipc_ns == init_task.nsproxy->ipc_ns ? 'I' : '-'),
6838 +                       task->nsproxy->mnt_ns,
6839 +                       (task->nsproxy->mnt_ns == init_task.nsproxy->mnt_ns ? 'I' : '-'),
6840 +                       task->nsproxy->pid_ns,
6841 +                       (task->nsproxy->pid_ns == init_task.nsproxy->pid_ns ? 'I' : '-'),
6842 +                       task->nsproxy->net_ns,
6843 +                       (task->nsproxy->net_ns == init_task.nsproxy->net_ns ? 'I' : '-'));
6844 +       return 0;
6845 +}
6846 +
6847 +void task_vs_id(struct seq_file *m, struct task_struct *task)
6848 +{
6849 +       if (task_vx_flags(task, VXF_HIDE_VINFO, 0))
6850 +               return;
6851 +
6852 +       seq_printf(m, "VxID: %d\n", vx_task_xid(task));
6853 +       seq_printf(m, "NxID: %d\n", nx_task_nid(task));
6854 +}
6855 +
6856 +
6857  int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
6858                         struct pid *pid, struct task_struct *task)
6859  {
6860 @@ -353,6 +395,7 @@ int proc_pid_status(struct seq_file *m, 
6861         task_cap(m, task);
6862         task_cpus_allowed(m, task);
6863         cpuset_task_status_allowed(m, task);
6864 +       task_vs_id(m, task);
6865         task_context_switch_counts(m, task);
6866         return 0;
6867  }
6868 @@ -462,6 +505,17 @@ static int do_task_stat(struct seq_file 
6869         /* convert nsec -> ticks */
6870         start_time = nsec_to_clock_t(start_time);
6871  
6872 +       /* fixup start time for virt uptime */
6873 +       if (vx_flags(VXF_VIRT_UPTIME, 0)) {
6874 +               unsigned long long bias =
6875 +                       current->vx_info->cvirt.bias_clock;
6876 +
6877 +               if (start_time > bias)
6878 +                       start_time -= bias;
6879 +               else
6880 +                       start_time = 0;
6881 +       }
6882 +
6883         seq_printf(m, "%d (%s) %c %d %d %d %d %d %u %lu \
6884  %lu %lu %lu %lu %lu %ld %ld %ld %ld %d 0 %llu %lu %ld %lu %lu %lu %lu %lu \
6885  %lu %lu %lu %lu %lu %lu %lu %lu %d %d %u %u %llu %lu %ld\n",
6886 diff -NurpP --minimal linux-2.6.38.3/fs/proc/base.c linux-2.6.38.3-vs2.3.0.37-rc14/fs/proc/base.c
6887 --- linux-2.6.38.3/fs/proc/base.c       2011-03-15 18:07:33.000000000 +0100
6888 +++ linux-2.6.38.3-vs2.3.0.37-rc14/fs/proc/base.c       2011-03-15 18:15:06.000000000 +0100
6889 @@ -83,6 +83,8 @@
6890  #include <linux/pid_namespace.h>
6891  #include <linux/fs_struct.h>
6892  #include <linux/slab.h>
6893 +#include <linux/vs_context.h>
6894 +#include <linux/vs_network.h>
6895  #include "internal.h"
6896  
6897  /* NOTE:
6898 @@ -1043,11 +1045,16 @@ static ssize_t oom_adjust_write(struct f
6899                 goto err_task_lock;
6900         }
6901  
6902 -       if (oom_adjust < task->signal->oom_adj && !capable(CAP_SYS_RESOURCE)) {
6903 +       if (oom_adjust < task->signal->oom_adj &&
6904 +               !vx_capable(CAP_SYS_RESOURCE, VXC_OOM_ADJUST)) {
6905                 err = -EACCES;
6906                 goto err_sighand;
6907         }
6908  
6909 +       /* prevent guest processes from circumventing the oom killer */
6910 +       if (vx_current_xid() && (oom_adjust == OOM_DISABLE))
6911 +               oom_adjust = OOM_ADJUST_MIN;
6912 +
6913         if (oom_adjust != task->signal->oom_adj) {
6914                 if (oom_adjust == OOM_DISABLE)
6915                         atomic_inc(&task->mm->oom_disable_count);
6916 @@ -1216,7 +1223,7 @@ static ssize_t proc_loginuid_write(struc
6917         ssize_t length;
6918         uid_t loginuid;
6919  
6920 -       if (!capable(CAP_AUDIT_CONTROL))
6921 +       if (!vx_capable(CAP_AUDIT_CONTROL, VXC_AUDIT_CONTROL))
6922                 return -EPERM;
6923  
6924         rcu_read_lock();
6925 @@ -1715,6 +1722,8 @@ static struct inode *proc_pid_make_inode
6926                 inode->i_gid = cred->egid;
6927                 rcu_read_unlock();
6928         }
6929 +       /* procfs is xid tagged */
6930 +       inode->i_tag = (tag_t)vx_task_xid(task);
6931         security_task_to_inode(task, inode);
6932  
6933  out:
6934 @@ -1751,6 +1760,8 @@ static int pid_getattr(struct vfsmount *
6935  
6936  /* dentry stuff */
6937  
6938 +static unsigned name_to_int(struct dentry *dentry);
6939 +
6940  /*
6941   *     Exceptional case: normally we are not allowed to unhash a busy
6942   * directory. In this case, however, we can do it - no aliasing problems
6943 @@ -1779,6 +1790,12 @@ static int pid_revalidate(struct dentry 
6944         task = get_proc_task(inode);
6945  
6946         if (task) {
6947 +               unsigned pid = name_to_int(dentry);
6948 +
6949 +               if (pid != ~0U && pid != vx_map_pid(task->pid)) {
6950 +                       put_task_struct(task);
6951 +                       goto drop;
6952 +               }
6953                 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
6954                     task_dumpable(task)) {
6955                         rcu_read_lock();
6956 @@ -1795,6 +1812,7 @@ static int pid_revalidate(struct dentry 
6957                 put_task_struct(task);
6958                 return 1;
6959         }
6960 +drop:
6961         d_drop(dentry);
6962         return 0;
6963  }
6964 @@ -2283,6 +2301,13 @@ static struct dentry *proc_pident_lookup
6965         if (!task)
6966                 goto out_no_task;
6967  
6968 +       /* TODO: maybe we can come up with a generic approach? */
6969 +       if (task_vx_flags(task, VXF_HIDE_VINFO, 0) &&
6970 +               (dentry->d_name.len == 5) &&
6971 +               (!memcmp(dentry->d_name.name, "vinfo", 5) ||
6972 +               !memcmp(dentry->d_name.name, "ninfo", 5)))
6973 +               goto out;
6974 +
6975         /*
6976          * Yes, it does not scale. And it should not. Don't add
6977          * new entries into /proc/<tgid>/ without very good reasons.
6978 @@ -2668,7 +2693,7 @@ out_iput:
6979  static struct dentry *proc_base_lookup(struct inode *dir, struct dentry *dentry)
6980  {
6981         struct dentry *error;
6982 -       struct task_struct *task = get_proc_task(dir);
6983 +       struct task_struct *task = get_proc_task_real(dir);
6984         const struct pid_entry *p, *last;
6985  
6986         error = ERR_PTR(-ENOENT);
6987 @@ -2758,6 +2783,9 @@ static int proc_pid_personality(struct s
6988  static const struct file_operations proc_task_operations;
6989  static const struct inode_operations proc_task_inode_operations;
6990  
6991 +extern int proc_pid_vx_info(struct task_struct *, char *);
6992 +extern int proc_pid_nx_info(struct task_struct *, char *);
6993 +
6994  static const struct pid_entry tgid_base_stuff[] = {
6995         DIR("task",       S_IRUGO|S_IXUGO, proc_task_inode_operations, proc_task_operations),
6996         DIR("fd",         S_IRUSR|S_IXUSR, proc_fd_inode_operations, proc_fd_operations),
6997 @@ -2820,6 +2848,8 @@ static const struct pid_entry tgid_base_
6998  #ifdef CONFIG_CGROUPS
6999         REG("cgroup",  S_IRUGO, proc_cgroup_operations),
7000  #endif
7001 +       INF("vinfo",      S_IRUGO, proc_pid_vx_info),
7002 +       INF("ninfo",      S_IRUGO, proc_pid_nx_info),
7003         INF("oom_score",  S_IRUGO, proc_oom_score),
7004         REG("oom_adj",    S_IRUGO|S_IWUSR, proc_oom_adjust_operations),
7005         REG("oom_score_adj", S_IRUGO|S_IWUSR, proc_oom_score_adj_operations),
7006 @@ -2836,6 +2866,7 @@ static const struct pid_entry tgid_base_
7007  #ifdef CONFIG_TASK_IO_ACCOUNTING
7008         INF("io",       S_IRUGO, proc_tgid_io_accounting),
7009  #endif
7010 +       ONE("nsproxy",  S_IRUGO, proc_pid_nsproxy),
7011  };
7012  
7013  static int proc_tgid_base_readdir(struct file * filp,
7014 @@ -3028,7 +3059,7 @@ retry:
7015         iter.task = NULL;
7016         pid = find_ge_pid(iter.tgid, ns);
7017         if (pid) {
7018 -               iter.tgid = pid_nr_ns(pid, ns);
7019 +               iter.tgid = pid_unmapped_nr_ns(pid, ns);
7020                 iter.task = pid_task(pid, PIDTYPE_PID);
7021                 /* What we to know is if the pid we have find is the
7022                  * pid of a thread_group_leader.  Testing for task
7023 @@ -3058,7 +3089,7 @@ static int proc_pid_fill_cache(struct fi
7024         struct tgid_iter iter)
7025  {
7026         char name[PROC_NUMBUF];
7027 -       int len = snprintf(name, sizeof(name), "%d", iter.tgid);
7028 +       int len = snprintf(name, sizeof(name), "%d", vx_map_tgid(iter.tgid));
7029         return proc_fill_cache(filp, dirent, filldir, name, len,
7030                                 proc_pid_instantiate, iter.task, NULL);
7031  }
7032 @@ -3067,7 +3098,7 @@ static int proc_pid_fill_cache(struct fi
7033                 goto out_no_task;
7034         nr = filp->f_pos - FIRST_PROCESS_ENTRY;
7035  
7036 -       reaper = get_proc_task(filp->f_path.dentry->d_inode);
7037 +       reaper = get_proc_task_real(filp->f_path.dentry->d_inode);
7038         if (!reaper)
7039                 goto out_no_task;
7040  
7041 @@ -3087,6 +3118,8 @@ int proc_pid_readdir(struct file * filp,
7042              iter.task;
7043              iter.tgid += 1, iter = next_tgid(ns, iter)) {
7044                 filp->f_pos = iter.tgid + TGID_OFFSET;
7045 +               if (!vx_proc_task_visible(iter.task))
7046 +                       continue;
7047                 if (proc_pid_fill_cache(filp, dirent, filldir, iter) < 0) {
7048                         put_task_struct(iter.task);
7049                         goto out;
7050 @@ -3236,6 +3269,8 @@ static struct dentry *proc_task_lookup(s
7051         tid = name_to_int(dentry);
7052         if (tid == ~0U)
7053                 goto out;
7054 +       if (vx_current_initpid(tid))
7055 +               goto out;
7056  
7057         ns = dentry->d_sb->s_fs_info;
7058         rcu_read_lock();
7059 diff -NurpP --minimal linux-2.6.38.3/fs/proc/generic.c linux-2.6.38.3-vs2.3.0.37-rc14/fs/proc/generic.c
7060 --- linux-2.6.38.3/fs/proc/generic.c    2011-03-15 18:07:33.000000000 +0100
7061 +++ linux-2.6.38.3-vs2.3.0.37-rc14/fs/proc/generic.c    2011-01-29 02:29:09.000000000 +0100
7062 @@ -22,6 +22,7 @@
7063  #include <linux/bitops.h>
7064  #include <linux/spinlock.h>
7065  #include <linux/completion.h>
7066 +#include <linux/vserver/inode.h>
7067  #include <asm/uaccess.h>
7068  
7069  #include "internal.h"
7070 @@ -424,11 +425,15 @@ struct dentry *proc_lookup_de(struct pro
7071         for (de = de->subdir; de ; de = de->next) {
7072                 if (de->namelen != dentry->d_name.len)
7073                         continue;
7074 +               if (!vx_hide_check(0, de->vx_flags))
7075 +                       continue;
7076                 if (!memcmp(dentry->d_name.name, de->name, de->namelen)) {
7077                         pde_get(de);
7078                         spin_unlock(&proc_subdir_lock);
7079                         error = -EINVAL;
7080                         inode = proc_get_inode(dir->i_sb, de);
7081 +                       /* generic proc entries belong to the host */
7082 +                       inode->i_tag = 0;
7083                         goto out_unlock;
7084                 }
7085         }
7086 @@ -506,6 +511,8 @@ int proc_readdir_de(struct proc_dir_entr
7087  
7088                                 /* filldir passes info to user space */
7089                                 pde_get(de);
7090 +                               if (!vx_hide_check(0, de->vx_flags))
7091 +                                       goto skip;
7092                                 spin_unlock(&proc_subdir_lock);
7093                                 if (filldir(dirent, de->name, de->namelen, filp->f_pos,
7094                                             de->low_ino, de->mode >> 12) < 0) {
7095 @@ -513,6 +520,7 @@ int proc_readdir_de(struct proc_dir_entr
7096                                         goto out;
7097                                 }
7098                                 spin_lock(&proc_subdir_lock);
7099 +                       skip:
7100                                 filp->f_pos++;
7101                                 next = de->next;
7102                                 pde_put(de);
7103 @@ -627,6 +635,7 @@ static struct proc_dir_entry *__proc_cre
7104         ent->nlink = nlink;
7105         atomic_set(&ent->count, 1);
7106         ent->pde_users = 0;
7107 +       ent->vx_flags = IATTR_PROC_DEFAULT;
7108         spin_lock_init(&ent->pde_unload_lock);
7109         ent->pde_unload_completion = NULL;
7110         INIT_LIST_HEAD(&ent->pde_openers);
7111 @@ -650,7 +659,8 @@ struct proc_dir_entry *proc_symlink(cons
7112                                 kfree(ent->data);
7113                                 kfree(ent);
7114                                 ent = NULL;
7115 -                       }
7116 +                       } else
7117 +                               ent->vx_flags = IATTR_PROC_SYMLINK;
7118                 } else {
7119                         kfree(ent);
7120                         ent = NULL;
7121 diff -NurpP --minimal linux-2.6.38.3/fs/proc/inode.c linux-2.6.38.3-vs2.3.0.37-rc14/fs/proc/inode.c
7122 --- linux-2.6.38.3/fs/proc/inode.c      2011-03-15 18:07:33.000000000 +0100
7123 +++ linux-2.6.38.3-vs2.3.0.37-rc14/fs/proc/inode.c      2011-03-15 18:15:06.000000000 +0100
7124 @@ -437,6 +437,8 @@ struct inode *proc_get_inode(struct supe
7125                         inode->i_uid = de->uid;
7126                         inode->i_gid = de->gid;
7127                 }
7128 +               if (de->vx_flags)
7129 +                       PROC_I(inode)->vx_flags = de->vx_flags;
7130                 if (de->size)
7131                         inode->i_size = de->size;
7132                 if (de->nlink)
7133 diff -NurpP --minimal linux-2.6.38.3/fs/proc/internal.h linux-2.6.38.3-vs2.3.0.37-rc14/fs/proc/internal.h
7134 --- linux-2.6.38.3/fs/proc/internal.h   2011-03-15 18:07:33.000000000 +0100
7135 +++ linux-2.6.38.3-vs2.3.0.37-rc14/fs/proc/internal.h   2011-01-29 02:01:07.000000000 +0100
7136 @@ -10,6 +10,7 @@
7137   */
7138  
7139  #include <linux/proc_fs.h>
7140 +#include <linux/vs_pid.h>
7141  
7142  extern struct proc_dir_entry proc_root;
7143  #ifdef CONFIG_PROC_SYSCTL
7144 @@ -51,6 +52,9 @@ extern int proc_pid_status(struct seq_fi
7145                                 struct pid *pid, struct task_struct *task);
7146  extern int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
7147                                 struct pid *pid, struct task_struct *task);
7148 +extern int proc_pid_nsproxy(struct seq_file *m, struct pid_namespace *ns,
7149 +                               struct pid *pid, struct task_struct *task);
7150 +
7151  extern loff_t mem_lseek(struct file *file, loff_t offset, int orig);
7152  
7153  extern const struct file_operations proc_maps_operations;
7154 @@ -68,11 +72,16 @@ static inline struct pid *proc_pid(struc
7155         return PROC_I(inode)->pid;
7156  }
7157  
7158 -static inline struct task_struct *get_proc_task(struct inode *inode)
7159 +static inline struct task_struct *get_proc_task_real(struct inode *inode)
7160  {
7161         return get_pid_task(proc_pid(inode), PIDTYPE_PID);
7162  }
7163  
7164 +static inline struct task_struct *get_proc_task(struct inode *inode)
7165 +{
7166 +       return vx_get_proc_task(inode, proc_pid(inode));
7167 +}
7168 +
7169  static inline int proc_fd(struct inode *inode)
7170  {
7171         return PROC_I(inode)->fd;
7172 diff -NurpP --minimal linux-2.6.38.3/fs/proc/loadavg.c linux-2.6.38.3-vs2.3.0.37-rc14/fs/proc/loadavg.c
7173 --- linux-2.6.38.3/fs/proc/loadavg.c    2009-09-10 15:26:23.000000000 +0200
7174 +++ linux-2.6.38.3-vs2.3.0.37-rc14/fs/proc/loadavg.c    2011-01-29 02:01:07.000000000 +0100
7175 @@ -12,15 +12,27 @@
7176  
7177  static int loadavg_proc_show(struct seq_file *m, void *v)
7178  {
7179 +       unsigned long running;
7180 +       unsigned int threads;
7181         unsigned long avnrun[3];
7182  
7183         get_avenrun(avnrun, FIXED_1/200, 0);
7184  
7185 +       if (vx_flags(VXF_VIRT_LOAD, 0)) {
7186 +               struct vx_info *vxi = current_vx_info();
7187 +
7188 +               running = atomic_read(&vxi->cvirt.nr_running);
7189 +               threads = atomic_read(&vxi->cvirt.nr_threads);
7190 +       } else {
7191 +               running = nr_running();
7192 +               threads = nr_threads;
7193 +       }
7194 +
7195         seq_printf(m, "%lu.%02lu %lu.%02lu %lu.%02lu %ld/%d %d\n",
7196                 LOAD_INT(avnrun[0]), LOAD_FRAC(avnrun[0]),
7197                 LOAD_INT(avnrun[1]), LOAD_FRAC(avnrun[1]),
7198                 LOAD_INT(avnrun[2]), LOAD_FRAC(avnrun[2]),
7199 -               nr_running(), nr_threads,
7200 +               running, threads,
7201                 task_active_pid_ns(current)->last_pid);
7202         return 0;
7203  }
7204 diff -NurpP --minimal linux-2.6.38.3/fs/proc/meminfo.c linux-2.6.38.3-vs2.3.0.37-rc14/fs/proc/meminfo.c
7205 --- linux-2.6.38.3/fs/proc/meminfo.c    2011-03-15 18:07:33.000000000 +0100
7206 +++ linux-2.6.38.3-vs2.3.0.37-rc14/fs/proc/meminfo.c    2011-01-29 02:01:07.000000000 +0100
7207 @@ -39,7 +39,8 @@ static int meminfo_proc_show(struct seq_
7208         allowed = ((totalram_pages - hugetlb_total_pages())
7209                 * sysctl_overcommit_ratio / 100) + total_swap_pages;
7210  
7211 -       cached = global_page_state(NR_FILE_PAGES) -
7212 +       cached = vx_flags(VXF_VIRT_MEM, 0) ?
7213 +               vx_vsi_cached(&i) : global_page_state(NR_FILE_PAGES) -
7214                         total_swapcache_pages - i.bufferram;
7215         if (cached < 0)
7216                 cached = 0;
7217 diff -NurpP --minimal linux-2.6.38.3/fs/proc/root.c linux-2.6.38.3-vs2.3.0.37-rc14/fs/proc/root.c
7218 --- linux-2.6.38.3/fs/proc/root.c       2011-01-05 21:50:26.000000000 +0100
7219 +++ linux-2.6.38.3-vs2.3.0.37-rc14/fs/proc/root.c       2011-01-29 02:01:07.000000000 +0100
7220 @@ -18,9 +18,14 @@
7221  #include <linux/bitops.h>
7222  #include <linux/mount.h>
7223  #include <linux/pid_namespace.h>
7224 +#include <linux/vserver/inode.h>
7225  
7226  #include "internal.h"
7227  
7228 +struct proc_dir_entry *proc_virtual;
7229 +
7230 +extern void proc_vx_init(void);
7231 +
7232  static int proc_test_super(struct super_block *sb, void *data)
7233  {
7234         return sb->s_fs_info == data;
7235 @@ -134,6 +139,7 @@ void __init proc_root_init(void)
7236  #endif
7237         proc_mkdir("bus", NULL);
7238         proc_sys_init();
7239 +       proc_vx_init();
7240  }
7241  
7242  static int proc_root_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat
7243 @@ -202,6 +208,7 @@ struct proc_dir_entry proc_root = {
7244         .proc_iops      = &proc_root_inode_operations, 
7245         .proc_fops      = &proc_root_operations,
7246         .parent         = &proc_root,
7247 +       .vx_flags       = IATTR_ADMIN | IATTR_WATCH,
7248  };
7249  
7250  int pid_ns_prepare_proc(struct pid_namespace *ns)
7251 diff -NurpP --minimal linux-2.6.38.3/fs/proc/uptime.c linux-2.6.38.3-vs2.3.0.37-rc14/fs/proc/uptime.c
7252 --- linux-2.6.38.3/fs/proc/uptime.c     2009-12-03 20:02:53.000000000 +0100
7253 +++ linux-2.6.38.3-vs2.3.0.37-rc14/fs/proc/uptime.c     2011-01-29 02:01:07.000000000 +0100
7254 @@ -4,22 +4,22 @@
7255  #include <linux/sched.h>
7256  #include <linux/seq_file.h>
7257  #include <linux/time.h>
7258 -#include <linux/kernel_stat.h>
7259 +#include <linux/vserver/cvirt.h>
7260  #include <asm/cputime.h>
7261  
7262  static int uptime_proc_show(struct seq_file *m, void *v)
7263  {
7264         struct timespec uptime;
7265         struct timespec idle;
7266 -       int i;
7267 -       cputime_t idletime = cputime_zero;
7268 -
7269 -       for_each_possible_cpu(i)
7270 -               idletime = cputime64_add(idletime, kstat_cpu(i).cpustat.idle);
7271 +       cputime_t idletime = cputime_add(init_task.utime, init_task.stime);
7272  
7273         do_posix_clock_monotonic_gettime(&uptime);
7274         monotonic_to_bootbased(&uptime);
7275         cputime_to_timespec(idletime, &idle);
7276 +
7277 +       if (vx_flags(VXF_VIRT_UPTIME, 0))
7278 +               vx_vsi_uptime(&uptime, &idle);
7279 +
7280         seq_printf(m, "%lu.%02lu %lu.%02lu\n",
7281                         (unsigned long) uptime.tv_sec,
7282                         (uptime.tv_nsec / (NSEC_PER_SEC / 100)),
7283 diff -NurpP --minimal linux-2.6.38.3/fs/quota/dquot.c linux-2.6.38.3-vs2.3.0.37-rc14/fs/quota/dquot.c
7284 --- linux-2.6.38.3/fs/quota/dquot.c     2011-04-15 10:30:30.000000000 +0200
7285 +++ linux-2.6.38.3-vs2.3.0.37-rc14/fs/quota/dquot.c     2011-04-15 10:33:41.000000000 +0200
7286 @@ -1540,6 +1540,9 @@ int __dquot_alloc_space(struct inode *in
7287         int reserve = flags & DQUOT_SPACE_RESERVE;
7288         int nofail = flags & DQUOT_SPACE_NOFAIL;
7289  
7290 +       if ((ret = dl_alloc_space(inode, number)))
7291 +               return ret;
7292 +
7293         /*
7294          * First test before acquiring mutex - solves deadlocks when we
7295          * re-enter the quota code and are already holding the mutex
7296 @@ -1594,6 +1597,9 @@ int dquot_alloc_inode(const struct inode
7297         int cnt, ret = 0;
7298         char warntype[MAXQUOTAS];
7299  
7300 +       if ((ret = dl_alloc_inode(inode)))
7301 +               return ret;
7302 +
7303         /* First test before acquiring mutex - solves deadlocks when we
7304           * re-enter the quota code and are already holding the mutex */
7305         if (!dquot_active(inode))
7306 @@ -1664,6 +1670,8 @@ void __dquot_free_space(struct inode *in
7307         char warntype[MAXQUOTAS];
7308         int reserve = flags & DQUOT_SPACE_RESERVE;
7309  
7310 +       dl_free_space(inode, number);
7311 +
7312         /* First test before acquiring mutex - solves deadlocks when we
7313           * re-enter the quota code and are already holding the mutex */
7314         if (!dquot_active(inode)) {
7315 @@ -1702,6 +1710,8 @@ void dquot_free_inode(const struct inode
7316         unsigned int cnt;
7317         char warntype[MAXQUOTAS];
7318  
7319 +       dl_free_inode(inode);
7320 +
7321         /* First test before acquiring mutex - solves deadlocks when we
7322           * re-enter the quota code and are already holding the mutex */
7323         if (!dquot_active(inode))
7324 diff -NurpP --minimal linux-2.6.38.3/fs/quota/quota.c linux-2.6.38.3-vs2.3.0.37-rc14/fs/quota/quota.c
7325 --- linux-2.6.38.3/fs/quota/quota.c     2011-03-15 18:07:34.000000000 +0100
7326 +++ linux-2.6.38.3-vs2.3.0.37-rc14/fs/quota/quota.c     2011-01-29 02:01:07.000000000 +0100
7327 @@ -8,6 +8,7 @@
7328  #include <linux/fs.h>
7329  #include <linux/namei.h>
7330  #include <linux/slab.h>
7331 +#include <linux/vs_context.h>
7332  #include <asm/current.h>
7333  #include <asm/uaccess.h>
7334  #include <linux/kernel.h>
7335 @@ -38,7 +39,7 @@ static int check_quotactl_permission(str
7336                         break;
7337                 /*FALLTHROUGH*/
7338         default:
7339 -               if (!capable(CAP_SYS_ADMIN))
7340 +               if (!vx_capable(CAP_SYS_ADMIN, VXC_QUOTA_CTL))
7341                         return -EPERM;
7342         }
7343  
7344 @@ -293,6 +294,46 @@ static int do_quotactl(struct super_bloc
7345         }
7346  }
7347  
7348 +#if defined(CONFIG_BLK_DEV_VROOT) || defined(CONFIG_BLK_DEV_VROOT_MODULE)
7349 +
7350 +#include <linux/vroot.h>
7351 +#include <linux/major.h>
7352 +#include <linux/module.h>
7353 +#include <linux/kallsyms.h>
7354 +#include <linux/vserver/debug.h>
7355 +
7356 +static vroot_grb_func *vroot_get_real_bdev = NULL;
7357 +
7358 +static spinlock_t vroot_grb_lock = SPIN_LOCK_UNLOCKED;
7359 +
7360 +int register_vroot_grb(vroot_grb_func *func) {
7361 +       int ret = -EBUSY;
7362 +
7363 +       spin_lock(&vroot_grb_lock);
7364 +       if (!vroot_get_real_bdev) {
7365 +               vroot_get_real_bdev = func;
7366 +               ret = 0;
7367 +       }
7368 +       spin_unlock(&vroot_grb_lock);
7369 +       return ret;
7370 +}
7371 +EXPORT_SYMBOL(register_vroot_grb);
7372 +
7373 +int unregister_vroot_grb(vroot_grb_func *func) {
7374 +       int ret = -EINVAL;
7375 +
7376 +       spin_lock(&vroot_grb_lock);
7377 +       if (vroot_get_real_bdev) {
7378 +               vroot_get_real_bdev = NULL;
7379 +               ret = 0;
7380 +       }
7381 +       spin_unlock(&vroot_grb_lock);
7382 +       return ret;
7383 +}
7384 +EXPORT_SYMBOL(unregister_vroot_grb);
7385 +
7386 +#endif
7387 +
7388  /*
7389   * look up a superblock on which quota ops will be performed
7390   * - use the name of a block device to find the superblock thereon
7391 @@ -310,6 +351,22 @@ static struct super_block *quotactl_bloc
7392         putname(tmp);
7393         if (IS_ERR(bdev))
7394                 return ERR_CAST(bdev);
7395 +#if defined(CONFIG_BLK_DEV_VROOT) || defined(CONFIG_BLK_DEV_VROOT_MODULE)
7396 +       if (bdev && bdev->bd_inode &&
7397 +                       imajor(bdev->bd_inode) == VROOT_MAJOR) {
7398 +               struct block_device *bdnew = (void *)-EINVAL;
7399 +
7400 +               if (vroot_get_real_bdev)
7401 +                       bdnew = vroot_get_real_bdev(bdev);
7402 +               else
7403 +                       vxdprintk(VXD_CBIT(misc, 0),
7404 +                                       "vroot_get_real_bdev not set");
7405 +               bdput(bdev);
7406 +               if (IS_ERR(bdnew))
7407 +                       return ERR_PTR(PTR_ERR(bdnew));
7408 +               bdev = bdnew;
7409 +       }
7410 +#endif
7411         sb = get_super(bdev);
7412         bdput(bdev);
7413         if (!sb)
7414 diff -NurpP --minimal linux-2.6.38.3/fs/reiserfs/file.c linux-2.6.38.3-vs2.3.0.37-rc14/fs/reiserfs/file.c
7415 --- linux-2.6.38.3/fs/reiserfs/file.c   2011-01-05 21:50:26.000000000 +0100
7416 +++ linux-2.6.38.3-vs2.3.0.37-rc14/fs/reiserfs/file.c   2011-01-29 02:01:07.000000000 +0100
7417 @@ -312,4 +312,5 @@ const struct inode_operations reiserfs_f
7418         .listxattr = reiserfs_listxattr,
7419         .removexattr = reiserfs_removexattr,
7420         .permission = reiserfs_permission,
7421 +       .sync_flags = reiserfs_sync_flags,
7422  };
7423 diff -NurpP --minimal linux-2.6.38.3/fs/reiserfs/inode.c linux-2.6.38.3-vs2.3.0.37-rc14/fs/reiserfs/inode.c
7424 --- linux-2.6.38.3/fs/reiserfs/inode.c  2011-01-05 21:50:26.000000000 +0100
7425 +++ linux-2.6.38.3-vs2.3.0.37-rc14/fs/reiserfs/inode.c  2011-01-29 02:01:07.000000000 +0100
7426 @@ -18,6 +18,7 @@
7427  #include <linux/writeback.h>
7428  #include <linux/quotaops.h>
7429  #include <linux/swap.h>
7430 +#include <linux/vs_tag.h>
7431  
7432  int reiserfs_commit_write(struct file *f, struct page *page,
7433                           unsigned from, unsigned to);
7434 @@ -1131,6 +1132,8 @@ static void init_inode(struct inode *ino
7435         struct buffer_head *bh;
7436         struct item_head *ih;
7437         __u32 rdev;
7438 +       uid_t uid;
7439 +       gid_t gid;
7440         //int version = ITEM_VERSION_1;
7441  
7442         bh = PATH_PLAST_BUFFER(path);
7443 @@ -1151,12 +1154,13 @@ static void init_inode(struct inode *ino
7444                     (struct stat_data_v1 *)B_I_PITEM(bh, ih);
7445                 unsigned long blocks;
7446  
7447 +               uid = sd_v1_uid(sd);
7448 +               gid = sd_v1_gid(sd);
7449 +
7450                 set_inode_item_key_version(inode, KEY_FORMAT_3_5);
7451                 set_inode_sd_version(inode, STAT_DATA_V1);
7452                 inode->i_mode = sd_v1_mode(sd);
7453                 inode->i_nlink = sd_v1_nlink(sd);
7454 -               inode->i_uid = sd_v1_uid(sd);
7455 -               inode->i_gid = sd_v1_gid(sd);
7456                 inode->i_size = sd_v1_size(sd);
7457                 inode->i_atime.tv_sec = sd_v1_atime(sd);
7458                 inode->i_mtime.tv_sec = sd_v1_mtime(sd);
7459 @@ -1198,11 +1202,12 @@ static void init_inode(struct inode *ino
7460                 // (directories and symlinks)
7461                 struct stat_data *sd = (struct stat_data *)B_I_PITEM(bh, ih);
7462  
7463 +               uid    = sd_v2_uid(sd);
7464 +               gid    = sd_v2_gid(sd);
7465 +
7466                 inode->i_mode = sd_v2_mode(sd);
7467                 inode->i_nlink = sd_v2_nlink(sd);
7468 -               inode->i_uid = sd_v2_uid(sd);
7469                 inode->i_size = sd_v2_size(sd);
7470 -               inode->i_gid = sd_v2_gid(sd);
7471                 inode->i_mtime.tv_sec = sd_v2_mtime(sd);
7472                 inode->i_atime.tv_sec = sd_v2_atime(sd);
7473                 inode->i_ctime.tv_sec = sd_v2_ctime(sd);
7474 @@ -1232,6 +1237,10 @@ static void init_inode(struct inode *ino
7475                 sd_attrs_to_i_attrs(sd_v2_attrs(sd), inode);
7476         }
7477  
7478 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
7479 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
7480 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid, 0);
7481 +
7482         pathrelse(path);
7483         if (S_ISREG(inode->i_mode)) {
7484                 inode->i_op = &reiserfs_file_inode_operations;
7485 @@ -1254,13 +1263,15 @@ static void init_inode(struct inode *ino
7486  static void inode2sd(void *sd, struct inode *inode, loff_t size)
7487  {
7488         struct stat_data *sd_v2 = (struct stat_data *)sd;
7489 +       uid_t uid = TAGINO_UID(DX_TAG(inode), inode->i_uid, inode->i_tag);
7490 +       gid_t gid = TAGINO_GID(DX_TAG(inode), inode->i_gid, inode->i_tag);
7491         __u16 flags;
7492  
7493 +       set_sd_v2_uid(sd_v2, uid);
7494 +       set_sd_v2_gid(sd_v2, gid);
7495         set_sd_v2_mode(sd_v2, inode->i_mode);
7496         set_sd_v2_nlink(sd_v2, inode->i_nlink);
7497 -       set_sd_v2_uid(sd_v2, inode->i_uid);
7498         set_sd_v2_size(sd_v2, size);
7499 -       set_sd_v2_gid(sd_v2, inode->i_gid);
7500         set_sd_v2_mtime(sd_v2, inode->i_mtime.tv_sec);
7501         set_sd_v2_atime(sd_v2, inode->i_atime.tv_sec);
7502         set_sd_v2_ctime(sd_v2, inode->i_ctime.tv_sec);
7503 @@ -2858,14 +2869,19 @@ int reiserfs_commit_write(struct file *f
7504  void sd_attrs_to_i_attrs(__u16 sd_attrs, struct inode *inode)
7505  {
7506         if (reiserfs_attrs(inode->i_sb)) {
7507 -               if (sd_attrs & REISERFS_SYNC_FL)
7508 -                       inode->i_flags |= S_SYNC;
7509 -               else
7510 -                       inode->i_flags &= ~S_SYNC;
7511                 if (sd_attrs & REISERFS_IMMUTABLE_FL)
7512                         inode->i_flags |= S_IMMUTABLE;
7513                 else
7514                         inode->i_flags &= ~S_IMMUTABLE;
7515 +               if (sd_attrs & REISERFS_IXUNLINK_FL)
7516 +                       inode->i_flags |= S_IXUNLINK;
7517 +               else
7518 +                       inode->i_flags &= ~S_IXUNLINK;
7519 +
7520 +               if (sd_attrs & REISERFS_SYNC_FL)
7521 +                       inode->i_flags |= S_SYNC;
7522 +               else
7523 +                       inode->i_flags &= ~S_SYNC;
7524                 if (sd_attrs & REISERFS_APPEND_FL)
7525                         inode->i_flags |= S_APPEND;
7526                 else
7527 @@ -2878,6 +2894,15 @@ void sd_attrs_to_i_attrs(__u16 sd_attrs,
7528                         REISERFS_I(inode)->i_flags |= i_nopack_mask;
7529                 else
7530                         REISERFS_I(inode)->i_flags &= ~i_nopack_mask;
7531 +
7532 +               if (sd_attrs & REISERFS_BARRIER_FL)
7533 +                       inode->i_vflags |= V_BARRIER;
7534 +               else
7535 +                       inode->i_vflags &= ~V_BARRIER;
7536 +               if (sd_attrs & REISERFS_COW_FL)
7537 +                       inode->i_vflags |= V_COW;
7538 +               else
7539 +                       inode->i_vflags &= ~V_COW;
7540         }
7541  }
7542  
7543 @@ -2888,6 +2913,11 @@ void i_attrs_to_sd_attrs(struct inode *i
7544                         *sd_attrs |= REISERFS_IMMUTABLE_FL;
7545                 else
7546                         *sd_attrs &= ~REISERFS_IMMUTABLE_FL;
7547 +               if (inode->i_flags & S_IXUNLINK)
7548 +                       *sd_attrs |= REISERFS_IXUNLINK_FL;
7549 +               else
7550 +                       *sd_attrs &= ~REISERFS_IXUNLINK_FL;
7551 +
7552                 if (inode->i_flags & S_SYNC)
7553                         *sd_attrs |= REISERFS_SYNC_FL;
7554                 else
7555 @@ -2900,6 +2930,15 @@ void i_attrs_to_sd_attrs(struct inode *i
7556                         *sd_attrs |= REISERFS_NOTAIL_FL;
7557                 else
7558                         *sd_attrs &= ~REISERFS_NOTAIL_FL;
7559 +
7560 +               if (inode->i_vflags & V_BARRIER)
7561 +                       *sd_attrs |= REISERFS_BARRIER_FL;
7562 +               else
7563 +                       *sd_attrs &= ~REISERFS_BARRIER_FL;
7564 +               if (inode->i_vflags & V_COW)
7565 +                       *sd_attrs |= REISERFS_COW_FL;
7566 +               else
7567 +                       *sd_attrs &= ~REISERFS_COW_FL;
7568         }
7569  }
7570  
7571 @@ -3143,7 +3182,8 @@ int reiserfs_setattr(struct dentry *dent
7572         }
7573  
7574         if ((ia_valid & ATTR_UID && attr->ia_uid != inode->i_uid) ||
7575 -           (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid)) {
7576 +           (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid) ||
7577 +           (ia_valid & ATTR_TAG && attr->ia_tag != inode->i_tag)) {
7578                 struct reiserfs_transaction_handle th;
7579                 int jbegin_count =
7580                     2 *
7581 @@ -3172,6 +3212,9 @@ int reiserfs_setattr(struct dentry *dent
7582                         inode->i_uid = attr->ia_uid;
7583                 if (attr->ia_valid & ATTR_GID)
7584                         inode->i_gid = attr->ia_gid;
7585 +                               if ((attr->ia_valid & ATTR_TAG) &&
7586 +                                       IS_TAGGED(inode))
7587 +                                       inode->i_tag = attr->ia_tag;
7588                 mark_inode_dirty(inode);
7589                 error = journal_end(&th, inode->i_sb, jbegin_count);
7590                 if (error)
7591 diff -NurpP --minimal linux-2.6.38.3/fs/reiserfs/ioctl.c linux-2.6.38.3-vs2.3.0.37-rc14/fs/reiserfs/ioctl.c
7592 --- linux-2.6.38.3/fs/reiserfs/ioctl.c  2011-01-05 21:50:26.000000000 +0100
7593 +++ linux-2.6.38.3-vs2.3.0.37-rc14/fs/reiserfs/ioctl.c  2011-01-29 02:01:07.000000000 +0100
7594 @@ -11,6 +11,21 @@
7595  #include <linux/pagemap.h>
7596  #include <linux/compat.h>
7597  
7598 +
7599 +int reiserfs_sync_flags(struct inode *inode, int flags, int vflags)
7600 +{
7601 +       __u16 sd_attrs = 0;
7602 +
7603 +       inode->i_flags = flags;
7604 +       inode->i_vflags = vflags;
7605 +
7606 +       i_attrs_to_sd_attrs(inode, &sd_attrs);
7607 +       REISERFS_I(inode)->i_attrs = sd_attrs;
7608 +       inode->i_ctime = CURRENT_TIME_SEC;
7609 +       mark_inode_dirty(inode);
7610 +       return 0;
7611 +}
7612 +
7613  /*
7614   * reiserfs_ioctl - handler for ioctl for inode
7615   * supported commands:
7616 @@ -22,7 +37,7 @@
7617  long reiserfs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
7618  {
7619         struct inode *inode = filp->f_path.dentry->d_inode;
7620 -       unsigned int flags;
7621 +       unsigned int flags, oldflags;
7622         int err = 0;
7623  
7624         reiserfs_write_lock(inode->i_sb);
7625 @@ -47,6 +62,7 @@ long reiserfs_ioctl(struct file *filp, u
7626  
7627                 flags = REISERFS_I(inode)->i_attrs;
7628                 i_attrs_to_sd_attrs(inode, (__u16 *) & flags);
7629 +               flags &= REISERFS_FL_USER_VISIBLE;
7630                 err = put_user(flags, (int __user *)arg);
7631                 break;
7632         case REISERFS_IOC_SETFLAGS:{
7633 @@ -67,6 +83,10 @@ long reiserfs_ioctl(struct file *filp, u
7634                                 err = -EFAULT;
7635                                 goto setflags_out;
7636                         }
7637 +                       if (IS_BARRIER(inode)) {
7638 +                               vxwprintk_task(1, "messing with the barrier.");
7639 +                               return -EACCES;
7640 +                       }
7641                         /*
7642                          * Is it quota file? Do not allow user to mess with it
7643                          */
7644 @@ -91,6 +111,10 @@ long reiserfs_ioctl(struct file *filp, u
7645                                         goto setflags_out;
7646                                 }
7647                         }
7648 +
7649 +                       oldflags = REISERFS_I(inode)->i_attrs;
7650 +                       flags &= REISERFS_FL_USER_MODIFIABLE;
7651 +                       flags |= oldflags & ~REISERFS_FL_USER_MODIFIABLE;
7652                         sd_attrs_to_i_attrs(flags, inode);
7653                         REISERFS_I(inode)->i_attrs = flags;
7654                         inode->i_ctime = CURRENT_TIME_SEC;
7655 diff -NurpP --minimal linux-2.6.38.3/fs/reiserfs/namei.c linux-2.6.38.3-vs2.3.0.37-rc14/fs/reiserfs/namei.c
7656 --- linux-2.6.38.3/fs/reiserfs/namei.c  2011-03-15 18:07:34.000000000 +0100
7657 +++ linux-2.6.38.3-vs2.3.0.37-rc14/fs/reiserfs/namei.c  2011-03-10 17:21:19.000000000 +0100
7658 @@ -18,6 +18,7 @@
7659  #include <linux/reiserfs_acl.h>
7660  #include <linux/reiserfs_xattr.h>
7661  #include <linux/quotaops.h>
7662 +#include <linux/vs_tag.h>
7663  
7664  #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; }
7665  #define DEC_DIR_INODE_NLINK(i) if (i->i_nlink != 1) drop_nlink(i);
7666 @@ -362,6 +363,7 @@ static struct dentry *reiserfs_lookup(st
7667         if (retval == IO_ERROR) {
7668                 return ERR_PTR(-EIO);
7669         }
7670 +               dx_propagate_tag(nd, inode);
7671  
7672         return d_splice_alias(inode, dentry);
7673  }
7674 @@ -1532,6 +1534,7 @@ const struct inode_operations reiserfs_d
7675         .listxattr = reiserfs_listxattr,
7676         .removexattr = reiserfs_removexattr,
7677         .permission = reiserfs_permission,
7678 +       .sync_flags = reiserfs_sync_flags,
7679  };
7680  
7681  /*
7682 diff -NurpP --minimal linux-2.6.38.3/fs/reiserfs/super.c linux-2.6.38.3-vs2.3.0.37-rc14/fs/reiserfs/super.c
7683 --- linux-2.6.38.3/fs/reiserfs/super.c  2011-03-15 18:07:34.000000000 +0100
7684 +++ linux-2.6.38.3-vs2.3.0.37-rc14/fs/reiserfs/super.c  2011-01-29 02:01:07.000000000 +0100
7685 @@ -899,6 +899,14 @@ static int reiserfs_parse_options(struct
7686                 {"user_xattr",.setmask = 1 << REISERFS_UNSUPPORTED_OPT},
7687                 {"nouser_xattr",.clrmask = 1 << REISERFS_UNSUPPORTED_OPT},
7688  #endif
7689 +#ifndef CONFIG_TAGGING_NONE
7690 +               {"tagxid",.setmask = 1 << REISERFS_TAGGED},
7691 +               {"tag",.setmask = 1 << REISERFS_TAGGED},
7692 +               {"notag",.clrmask = 1 << REISERFS_TAGGED},
7693 +#endif
7694 +#ifdef CONFIG_PROPAGATE
7695 +               {"tag",.arg_required = 'T',.values = NULL},
7696 +#endif
7697  #ifdef CONFIG_REISERFS_FS_POSIX_ACL
7698                 {"acl",.setmask = 1 << REISERFS_POSIXACL},
7699                 {"noacl",.clrmask = 1 << REISERFS_POSIXACL},
7700 @@ -1208,6 +1216,14 @@ static int reiserfs_remount(struct super
7701         handle_quota_files(s, qf_names, &qfmt);
7702  #endif
7703  
7704 +       if ((mount_options & (1 << REISERFS_TAGGED)) &&
7705 +               !(s->s_flags & MS_TAGGED)) {
7706 +               reiserfs_warning(s, "super-vs01",
7707 +                       "reiserfs: tagging not permitted on remount.");
7708 +               err = -EINVAL;
7709 +               goto out_err;
7710 +       }
7711 +
7712         handle_attrs(s);
7713  
7714         /* Add options that are safe here */
7715 @@ -1690,6 +1706,10 @@ static int reiserfs_fill_super(struct su
7716                 goto error;
7717         }
7718  
7719 +       /* map mount option tagxid */
7720 +       if (REISERFS_SB(s)->s_mount_opt & (1 << REISERFS_TAGGED))
7721 +               s->s_flags |= MS_TAGGED;
7722 +
7723         rs = SB_DISK_SUPER_BLOCK(s);
7724         /* Let's do basic sanity check to verify that underlying device is not
7725            smaller than the filesystem. If the check fails then abort and scream,
7726 diff -NurpP --minimal linux-2.6.38.3/fs/reiserfs/xattr.c linux-2.6.38.3-vs2.3.0.37-rc14/fs/reiserfs/xattr.c
7727 --- linux-2.6.38.3/fs/reiserfs/xattr.c  2011-03-15 18:07:34.000000000 +0100
7728 +++ linux-2.6.38.3-vs2.3.0.37-rc14/fs/reiserfs/xattr.c  2011-03-15 18:15:06.000000000 +0100
7729 @@ -40,6 +40,7 @@
7730  #include <linux/errno.h>
7731  #include <linux/gfp.h>
7732  #include <linux/fs.h>
7733 +#include <linux/mount.h>
7734  #include <linux/file.h>
7735  #include <linux/pagemap.h>
7736  #include <linux/xattr.h>
7737 diff -NurpP --minimal linux-2.6.38.3/fs/stat.c linux-2.6.38.3-vs2.3.0.37-rc14/fs/stat.c
7738 --- linux-2.6.38.3/fs/stat.c    2011-03-15 18:07:34.000000000 +0100
7739 +++ linux-2.6.38.3-vs2.3.0.37-rc14/fs/stat.c    2011-01-29 02:01:07.000000000 +0100
7740 @@ -26,6 +26,7 @@ void generic_fillattr(struct inode *inod
7741         stat->nlink = inode->i_nlink;
7742         stat->uid = inode->i_uid;
7743         stat->gid = inode->i_gid;
7744 +       stat->tag = inode->i_tag;
7745         stat->rdev = inode->i_rdev;
7746         stat->atime = inode->i_atime;
7747         stat->mtime = inode->i_mtime;
7748 diff -NurpP --minimal linux-2.6.38.3/fs/statfs.c linux-2.6.38.3-vs2.3.0.37-rc14/fs/statfs.c
7749 --- linux-2.6.38.3/fs/statfs.c  2010-10-21 13:07:51.000000000 +0200
7750 +++ linux-2.6.38.3-vs2.3.0.37-rc14/fs/statfs.c  2011-01-29 02:01:07.000000000 +0100
7751 @@ -7,6 +7,8 @@
7752  #include <linux/statfs.h>
7753  #include <linux/security.h>
7754  #include <linux/uaccess.h>
7755 +#include <linux/vs_base.h>
7756 +#include <linux/vs_dlimit.h>
7757  
7758  static int flags_by_mnt(int mnt_flags)
7759  {
7760 @@ -59,6 +61,8 @@ int statfs_by_dentry(struct dentry *dent
7761         retval = dentry->d_sb->s_op->statfs(dentry, buf);
7762         if (retval == 0 && buf->f_frsize == 0)
7763                 buf->f_frsize = buf->f_bsize;
7764 +       if (!vx_check(0, VS_ADMIN|VS_WATCH))
7765 +               vx_vsi_statfs(dentry->d_sb, buf);
7766         return retval;
7767  }
7768  
7769 diff -NurpP --minimal linux-2.6.38.3/fs/super.c linux-2.6.38.3-vs2.3.0.37-rc14/fs/super.c
7770 --- linux-2.6.38.3/fs/super.c   2011-04-15 10:30:30.000000000 +0200
7771 +++ linux-2.6.38.3-vs2.3.0.37-rc14/fs/super.c   2011-03-28 15:01:33.000000000 +0200
7772 @@ -31,6 +31,9 @@
7773  #include <linux/mutex.h>
7774  #include <linux/backing-dev.h>
7775  #include <linux/rculist_bl.h>
7776 +#include <linux/devpts_fs.h>
7777 +#include <linux/proc_fs.h>
7778 +#include <linux/vs_context.h>
7779  #include "internal.h"
7780  
7781  
7782 @@ -964,6 +967,7 @@ struct vfsmount *
7783  vfs_kern_mount(struct file_system_type *type, int flags, const char *name, void *data)
7784  {
7785         struct vfsmount *mnt;
7786 +       struct super_block *sb;
7787         struct dentry *root;
7788         char *secdata = NULL;
7789         int error;
7790 @@ -971,6 +975,11 @@ vfs_kern_mount(struct file_system_type *
7791         if (!type)
7792                 return ERR_PTR(-ENODEV);
7793  
7794 +       error = -EPERM;
7795 +       if ((type->fs_flags & FS_BINARY_MOUNTDATA) &&
7796 +               !vx_capable(CAP_SYS_ADMIN, VXC_BINARY_MOUNT))
7797 +               goto out;
7798 +
7799         error = -ENOMEM;
7800         mnt = alloc_vfsmnt(name);
7801         if (!mnt)
7802 @@ -1002,12 +1011,20 @@ vfs_kern_mount(struct file_system_type *
7803                 if (error < 0)
7804                         goto out_free_secdata;
7805         }
7806 -       BUG_ON(!mnt->mnt_sb);
7807 -       WARN_ON(!mnt->mnt_sb->s_bdi);
7808 +
7809 +       sb = mnt->mnt_sb;
7810 +       BUG_ON(!sb);
7811 +       WARN_ON(!sb->s_bdi);
7812         WARN_ON(mnt->mnt_sb->s_bdi == &default_backing_dev_info);
7813         mnt->mnt_sb->s_flags |= MS_BORN;
7814  
7815 -       error = security_sb_kern_mount(mnt->mnt_sb, flags, secdata);
7816 +       error = -EPERM;
7817 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_BINARY_MOUNT) && !sb->s_bdev &&
7818 +               (sb->s_magic != PROC_SUPER_MAGIC) &&
7819 +               (sb->s_magic != DEVPTS_SUPER_MAGIC))
7820 +               goto out_sb;
7821 +
7822 +       error = security_sb_kern_mount(sb, flags, secdata);
7823         if (error)
7824                 goto out_sb;
7825  
7826 diff -NurpP --minimal linux-2.6.38.3/fs/sysfs/mount.c linux-2.6.38.3-vs2.3.0.37-rc14/fs/sysfs/mount.c
7827 --- linux-2.6.38.3/fs/sysfs/mount.c     2011-01-05 21:50:27.000000000 +0100
7828 +++ linux-2.6.38.3-vs2.3.0.37-rc14/fs/sysfs/mount.c     2011-01-29 02:01:07.000000000 +0100
7829 @@ -47,7 +47,7 @@ static int sysfs_fill_super(struct super
7830  
7831         sb->s_blocksize = PAGE_CACHE_SIZE;
7832         sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
7833 -       sb->s_magic = SYSFS_MAGIC;
7834 +       sb->s_magic = SYSFS_SUPER_MAGIC;
7835         sb->s_op = &sysfs_ops;
7836         sb->s_time_gran = 1;
7837  
7838 diff -NurpP --minimal linux-2.6.38.3/fs/utimes.c linux-2.6.38.3-vs2.3.0.37-rc14/fs/utimes.c
7839 --- linux-2.6.38.3/fs/utimes.c  2010-10-21 13:07:51.000000000 +0200
7840 +++ linux-2.6.38.3-vs2.3.0.37-rc14/fs/utimes.c  2011-01-29 02:01:07.000000000 +0100
7841 @@ -8,6 +8,8 @@
7842  #include <linux/stat.h>
7843  #include <linux/utime.h>
7844  #include <linux/syscalls.h>
7845 +#include <linux/mount.h>
7846 +#include <linux/vs_cowbl.h>
7847  #include <asm/uaccess.h>
7848  #include <asm/unistd.h>
7849  
7850 @@ -52,12 +54,18 @@ static int utimes_common(struct path *pa
7851  {
7852         int error;
7853         struct iattr newattrs;
7854 -       struct inode *inode = path->dentry->d_inode;
7855 +       struct inode *inode;
7856  
7857         error = mnt_want_write(path->mnt);
7858         if (error)
7859                 goto out;
7860  
7861 +       error = cow_check_and_break(path);
7862 +       if (error)
7863 +               goto mnt_drop_write_and_out;
7864 +
7865 +       inode = path->dentry->d_inode;
7866 +
7867         if (times && times[0].tv_nsec == UTIME_NOW &&
7868                      times[1].tv_nsec == UTIME_NOW)
7869                 times = NULL;
7870 diff -NurpP --minimal linux-2.6.38.3/fs/xattr.c linux-2.6.38.3-vs2.3.0.37-rc14/fs/xattr.c
7871 --- linux-2.6.38.3/fs/xattr.c   2010-08-02 16:52:52.000000000 +0200
7872 +++ linux-2.6.38.3-vs2.3.0.37-rc14/fs/xattr.c   2011-01-29 02:01:07.000000000 +0100
7873 @@ -18,6 +18,7 @@
7874  #include <linux/module.h>
7875  #include <linux/fsnotify.h>
7876  #include <linux/audit.h>
7877 +#include <linux/mount.h>
7878  #include <asm/uaccess.h>
7879  
7880  
7881 @@ -49,7 +50,7 @@ xattr_permission(struct inode *inode, co
7882          * The trusted.* namespace can only be accessed by a privileged user.
7883          */
7884         if (!strncmp(name, XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN))
7885 -               return (capable(CAP_SYS_ADMIN) ? 0 : -EPERM);
7886 +               return (vx_capable(CAP_SYS_ADMIN, VXC_FS_TRUSTED) ? 0 : -EPERM);
7887  
7888         /* In user.* namespace, only regular files and directories can have
7889          * extended attributes. For sticky directories, only the owner and
7890 diff -NurpP --minimal linux-2.6.38.3/fs/xfs/linux-2.6/xfs_ioctl.c linux-2.6.38.3-vs2.3.0.37-rc14/fs/xfs/linux-2.6/xfs_ioctl.c
7891 --- linux-2.6.38.3/fs/xfs/linux-2.6/xfs_ioctl.c 2011-03-15 18:07:34.000000000 +0100
7892 +++ linux-2.6.38.3-vs2.3.0.37-rc14/fs/xfs/linux-2.6/xfs_ioctl.c 2011-03-10 17:21:19.000000000 +0100
7893 @@ -28,7 +28,7 @@
7894  #include "xfs_bmap_btree.h"
7895  #include "xfs_dinode.h"
7896  #include "xfs_inode.h"
7897 -#include "xfs_ioctl.h"
7898 +// #include "xfs_ioctl.h"
7899  #include "xfs_rtalloc.h"
7900  #include "xfs_itable.h"
7901  #include "xfs_error.h"
7902 @@ -744,6 +744,10 @@ xfs_merge_ioc_xflags(
7903                 xflags |= XFS_XFLAG_IMMUTABLE;
7904         else
7905                 xflags &= ~XFS_XFLAG_IMMUTABLE;
7906 +       if (flags & FS_IXUNLINK_FL)
7907 +               xflags |= XFS_XFLAG_IXUNLINK;
7908 +       else
7909 +               xflags &= ~XFS_XFLAG_IXUNLINK;
7910         if (flags & FS_APPEND_FL)
7911                 xflags |= XFS_XFLAG_APPEND;
7912         else
7913 @@ -772,6 +776,8 @@ xfs_di2lxflags(
7914  
7915         if (di_flags & XFS_DIFLAG_IMMUTABLE)
7916                 flags |= FS_IMMUTABLE_FL;
7917 +       if (di_flags & XFS_DIFLAG_IXUNLINK)
7918 +               flags |= FS_IXUNLINK_FL;
7919         if (di_flags & XFS_DIFLAG_APPEND)
7920                 flags |= FS_APPEND_FL;
7921         if (di_flags & XFS_DIFLAG_SYNC)
7922 @@ -832,6 +838,8 @@ xfs_set_diflags(
7923         di_flags = (ip->i_d.di_flags & XFS_DIFLAG_PREALLOC);
7924         if (xflags & XFS_XFLAG_IMMUTABLE)
7925                 di_flags |= XFS_DIFLAG_IMMUTABLE;
7926 +       if (xflags & XFS_XFLAG_IXUNLINK)
7927 +               di_flags |= XFS_DIFLAG_IXUNLINK;
7928         if (xflags & XFS_XFLAG_APPEND)
7929                 di_flags |= XFS_DIFLAG_APPEND;
7930         if (xflags & XFS_XFLAG_SYNC)
7931 @@ -874,6 +882,10 @@ xfs_diflags_to_linux(
7932                 inode->i_flags |= S_IMMUTABLE;
7933         else
7934                 inode->i_flags &= ~S_IMMUTABLE;
7935 +       if (xflags & XFS_XFLAG_IXUNLINK)
7936 +               inode->i_flags |= S_IXUNLINK;
7937 +       else
7938 +               inode->i_flags &= ~S_IXUNLINK;
7939         if (xflags & XFS_XFLAG_APPEND)
7940                 inode->i_flags |= S_APPEND;
7941         else
7942 @@ -1366,10 +1378,18 @@ xfs_file_ioctl(
7943         case XFS_IOC_FSGETXATTRA:
7944                 return xfs_ioc_fsgetxattr(ip, 1, arg);
7945         case XFS_IOC_FSSETXATTR:
7946 +               if (IS_BARRIER(inode)) {
7947 +                       vxwprintk_task(1, "messing with the barrier.");
7948 +                       return -XFS_ERROR(EACCES);
7949 +               }
7950                 return xfs_ioc_fssetxattr(ip, filp, arg);
7951         case XFS_IOC_GETXFLAGS:
7952                 return xfs_ioc_getxflags(ip, arg);
7953         case XFS_IOC_SETXFLAGS:
7954 +               if (IS_BARRIER(inode)) {
7955 +                       vxwprintk_task(1, "messing with the barrier.");
7956 +                       return -XFS_ERROR(EACCES);
7957 +               }
7958                 return xfs_ioc_setxflags(ip, filp, arg);
7959  
7960         case XFS_IOC_FSSETDM: {
7961 diff -NurpP --minimal linux-2.6.38.3/fs/xfs/linux-2.6/xfs_ioctl.h linux-2.6.38.3-vs2.3.0.37-rc14/fs/xfs/linux-2.6/xfs_ioctl.h
7962 --- linux-2.6.38.3/fs/xfs/linux-2.6/xfs_ioctl.h 2010-07-07 18:31:54.000000000 +0200
7963 +++ linux-2.6.38.3-vs2.3.0.37-rc14/fs/xfs/linux-2.6/xfs_ioctl.h 2011-01-29 02:01:07.000000000 +0100
7964 @@ -70,6 +70,12 @@ xfs_handle_to_dentry(
7965         void __user             *uhandle,
7966         u32                     hlen);
7967  
7968 +extern int
7969 +xfs_sync_flags(
7970 +       struct inode            *inode,
7971 +       int                     flags,
7972 +       int                     vflags);
7973 +
7974  extern long
7975  xfs_file_ioctl(
7976         struct file             *filp,
7977 diff -NurpP --minimal linux-2.6.38.3/fs/xfs/linux-2.6/xfs_iops.c linux-2.6.38.3-vs2.3.0.37-rc14/fs/xfs/linux-2.6/xfs_iops.c
7978 --- linux-2.6.38.3/fs/xfs/linux-2.6/xfs_iops.c  2011-03-15 18:07:34.000000000 +0100
7979 +++ linux-2.6.38.3-vs2.3.0.37-rc14/fs/xfs/linux-2.6/xfs_iops.c  2011-01-29 02:01:07.000000000 +0100
7980 @@ -30,6 +30,7 @@
7981  #include "xfs_bmap_btree.h"
7982  #include "xfs_dinode.h"
7983  #include "xfs_inode.h"
7984 +#include "xfs_ioctl.h"
7985  #include "xfs_bmap.h"
7986  #include "xfs_rtalloc.h"
7987  #include "xfs_error.h"
7988 @@ -48,6 +49,7 @@
7989  #include <linux/security.h>
7990  #include <linux/fiemap.h>
7991  #include <linux/slab.h>
7992 +#include <linux/vs_tag.h>
7993  
7994  /*
7995   * Bring the timestamps in the XFS inode uptodate.
7996 @@ -463,6 +465,7 @@ xfs_vn_getattr(
7997         stat->nlink = ip->i_d.di_nlink;
7998         stat->uid = ip->i_d.di_uid;
7999         stat->gid = ip->i_d.di_gid;
8000 +       stat->tag = ip->i_d.di_tag;
8001         stat->ino = ip->i_ino;
8002         stat->atime = inode->i_atime;
8003         stat->mtime = inode->i_mtime;
8004 @@ -598,6 +601,7 @@ static const struct inode_operations xfs
8005         .removexattr            = generic_removexattr,
8006         .listxattr              = xfs_vn_listxattr,
8007         .fiemap                 = xfs_vn_fiemap,
8008 +       .sync_flags             = xfs_sync_flags,
8009  };
8010  
8011  static const struct inode_operations xfs_dir_inode_operations = {
8012 @@ -623,6 +627,7 @@ static const struct inode_operations xfs
8013         .getxattr               = generic_getxattr,
8014         .removexattr            = generic_removexattr,
8015         .listxattr              = xfs_vn_listxattr,
8016 +       .sync_flags             = xfs_sync_flags,
8017  };
8018  
8019  static const struct inode_operations xfs_dir_ci_inode_operations = {
8020 @@ -672,6 +677,10 @@ xfs_diflags_to_iflags(
8021                 inode->i_flags |= S_IMMUTABLE;
8022         else
8023                 inode->i_flags &= ~S_IMMUTABLE;
8024 +       if (ip->i_d.di_flags & XFS_DIFLAG_IXUNLINK)
8025 +               inode->i_flags |= S_IXUNLINK;
8026 +       else
8027 +               inode->i_flags &= ~S_IXUNLINK;
8028         if (ip->i_d.di_flags & XFS_DIFLAG_APPEND)
8029                 inode->i_flags |= S_APPEND;
8030         else
8031 @@ -684,6 +693,15 @@ xfs_diflags_to_iflags(
8032                 inode->i_flags |= S_NOATIME;
8033         else
8034                 inode->i_flags &= ~S_NOATIME;
8035 +
8036 +       if (ip->i_d.di_vflags & XFS_DIVFLAG_BARRIER)
8037 +               inode->i_vflags |= V_BARRIER;
8038 +       else
8039 +               inode->i_vflags &= ~V_BARRIER;
8040 +       if (ip->i_d.di_vflags & XFS_DIVFLAG_COW)
8041 +               inode->i_vflags |= V_COW;
8042 +       else
8043 +               inode->i_vflags &= ~V_COW;
8044  }
8045  
8046  /*
8047 @@ -715,6 +733,7 @@ xfs_setup_inode(
8048         inode->i_nlink  = ip->i_d.di_nlink;
8049         inode->i_uid    = ip->i_d.di_uid;
8050         inode->i_gid    = ip->i_d.di_gid;
8051 +       inode->i_tag    = ip->i_d.di_tag;
8052  
8053         switch (inode->i_mode & S_IFMT) {
8054         case S_IFBLK:
8055 diff -NurpP --minimal linux-2.6.38.3/fs/xfs/linux-2.6/xfs_linux.h linux-2.6.38.3-vs2.3.0.37-rc14/fs/xfs/linux-2.6/xfs_linux.h
8056 --- linux-2.6.38.3/fs/xfs/linux-2.6/xfs_linux.h 2011-03-15 18:07:34.000000000 +0100
8057 +++ linux-2.6.38.3-vs2.3.0.37-rc14/fs/xfs/linux-2.6/xfs_linux.h 2011-01-29 02:01:07.000000000 +0100
8058 @@ -114,6 +114,7 @@
8059  
8060  #define current_cpu()          (raw_smp_processor_id())
8061  #define current_pid()          (current->pid)
8062 +#define current_fstag(vp)      (dx_current_fstag((vp)->i_sb))
8063  #define current_test_flags(f)  (current->flags & (f))
8064  #define current_set_flags_nested(sp, f)                \
8065                 (*(sp) = current->flags, current->flags |= (f))
8066 diff -NurpP --minimal linux-2.6.38.3/fs/xfs/linux-2.6/xfs_super.c linux-2.6.38.3-vs2.3.0.37-rc14/fs/xfs/linux-2.6/xfs_super.c
8067 --- linux-2.6.38.3/fs/xfs/linux-2.6/xfs_super.c 2011-04-15 10:30:30.000000000 +0200
8068 +++ linux-2.6.38.3-vs2.3.0.37-rc14/fs/xfs/linux-2.6/xfs_super.c 2011-04-15 10:35:15.000000000 +0200
8069 @@ -112,6 +112,9 @@ mempool_t *xfs_ioend_pool;
8070  #define MNTOPT_QUOTANOENF  "qnoenforce"        /* same as uqnoenforce */
8071  #define MNTOPT_DELAYLOG   "delaylog"   /* Delayed loging enabled */
8072  #define MNTOPT_NODELAYLOG "nodelaylog" /* Delayed loging disabled */
8073 +#define MNTOPT_TAGXID  "tagxid"        /* context tagging for inodes */
8074 +#define MNTOPT_TAGGED  "tag"           /* context tagging for inodes */
8075 +#define MNTOPT_NOTAGTAG        "notag"         /* do not use context tagging */
8076  
8077  /*
8078   * Table driven mount option parser.
8079 @@ -120,10 +123,14 @@ mempool_t *xfs_ioend_pool;
8080   * in the future, too.
8081   */
8082  enum {
8083 +       Opt_tag, Opt_notag,
8084         Opt_barrier, Opt_nobarrier, Opt_err
8085  };
8086  
8087  static const match_table_t tokens = {
8088 +       {Opt_tag, "tagxid"},
8089 +       {Opt_tag, "tag"},
8090 +       {Opt_notag, "notag"},
8091         {Opt_barrier, "barrier"},
8092         {Opt_nobarrier, "nobarrier"},
8093         {Opt_err, NULL}
8094 @@ -367,6 +374,19 @@ xfs_parseargs(
8095                 } else if (!strcmp(this_char, "irixsgid")) {
8096                         cmn_err(CE_WARN,
8097         "XFS: irixsgid is now a sysctl(2) variable, option is deprecated.");
8098 +#ifndef CONFIG_TAGGING_NONE
8099 +               } else if (!strcmp(this_char, MNTOPT_TAGGED)) {
8100 +                       mp->m_flags |= XFS_MOUNT_TAGGED;
8101 +               } else if (!strcmp(this_char, MNTOPT_NOTAGTAG)) {
8102 +                       mp->m_flags &= ~XFS_MOUNT_TAGGED;
8103 +               } else if (!strcmp(this_char, MNTOPT_TAGXID)) {
8104 +                       mp->m_flags |= XFS_MOUNT_TAGGED;
8105 +#endif
8106 +#ifdef CONFIG_PROPAGATE
8107 +               } else if (!strcmp(this_char, MNTOPT_TAGGED)) {
8108 +                       /* use value */
8109 +                       mp->m_flags |= XFS_MOUNT_TAGGED;
8110 +#endif
8111                 } else {
8112                         cmn_err(CE_WARN,
8113                                 "XFS: unknown mount option [%s].", this_char);
8114 @@ -1327,6 +1347,16 @@ xfs_fs_remount(
8115                 case Opt_nobarrier:
8116                         mp->m_flags &= ~XFS_MOUNT_BARRIER;
8117                         break;
8118 +               case Opt_tag:
8119 +                       if (!(sb->s_flags & MS_TAGGED)) {
8120 +                               printk(KERN_INFO
8121 +                                       "XFS: %s: tagging not permitted on remount.\n",
8122 +                                       sb->s_id);
8123 +                               return -EINVAL;
8124 +                       }
8125 +                       break;
8126 +               case Opt_notag:
8127 +                       break;
8128                 default:
8129                         /*
8130                          * Logically we would return an error here to prevent
8131 @@ -1551,6 +1581,9 @@ xfs_fs_fill_super(
8132         if (error)
8133                 goto out_free_sb;
8134  
8135 +       if (mp->m_flags & XFS_MOUNT_TAGGED)
8136 +               sb->s_flags |= MS_TAGGED;
8137 +
8138         /*
8139          * we must configure the block size in the superblock before we run the
8140          * full mount process as the mount process can lookup and cache inodes.
8141 diff -NurpP --minimal linux-2.6.38.3/fs/xfs/xfs_dinode.h linux-2.6.38.3-vs2.3.0.37-rc14/fs/xfs/xfs_dinode.h
8142 --- linux-2.6.38.3/fs/xfs/xfs_dinode.h  2011-01-05 21:50:28.000000000 +0100
8143 +++ linux-2.6.38.3-vs2.3.0.37-rc14/fs/xfs/xfs_dinode.h  2011-01-29 02:01:07.000000000 +0100
8144 @@ -51,7 +51,9 @@ typedef struct xfs_dinode {
8145         __be32          di_nlink;       /* number of links to file */
8146         __be16          di_projid_lo;   /* lower part of owner's project id */
8147         __be16          di_projid_hi;   /* higher part owner's project id */
8148 -       __u8            di_pad[6];      /* unused, zeroed space */
8149 +       __u8            di_pad[2];      /* unused, zeroed space */
8150 +       __be16          di_tag;         /* context tagging */
8151 +       __be16          di_vflags;      /* vserver specific flags */
8152         __be16          di_flushiter;   /* incremented on flush */
8153         xfs_timestamp_t di_atime;       /* time last accessed */
8154         xfs_timestamp_t di_mtime;       /* time last modified */
8155 @@ -184,6 +186,8 @@ static inline void xfs_dinode_put_rdev(s
8156  #define XFS_DIFLAG_EXTSZINHERIT_BIT 12 /* inherit inode extent size */
8157  #define XFS_DIFLAG_NODEFRAG_BIT     13 /* do not reorganize/defragment */
8158  #define XFS_DIFLAG_FILESTREAM_BIT   14  /* use filestream allocator */
8159 +#define XFS_DIFLAG_IXUNLINK_BIT     15 /* Immutable inver on unlink */
8160 +
8161  #define XFS_DIFLAG_REALTIME      (1 << XFS_DIFLAG_REALTIME_BIT)
8162  #define XFS_DIFLAG_PREALLOC      (1 << XFS_DIFLAG_PREALLOC_BIT)
8163  #define XFS_DIFLAG_NEWRTBM       (1 << XFS_DIFLAG_NEWRTBM_BIT)
8164 @@ -199,6 +203,7 @@ static inline void xfs_dinode_put_rdev(s
8165  #define XFS_DIFLAG_EXTSZINHERIT  (1 << XFS_DIFLAG_EXTSZINHERIT_BIT)
8166  #define XFS_DIFLAG_NODEFRAG      (1 << XFS_DIFLAG_NODEFRAG_BIT)
8167  #define XFS_DIFLAG_FILESTREAM    (1 << XFS_DIFLAG_FILESTREAM_BIT)
8168 +#define XFS_DIFLAG_IXUNLINK      (1 << XFS_DIFLAG_IXUNLINK_BIT)
8169  
8170  #ifdef CONFIG_XFS_RT
8171  #define XFS_IS_REALTIME_INODE(ip) ((ip)->i_d.di_flags & XFS_DIFLAG_REALTIME)
8172 @@ -211,6 +216,10 @@ static inline void xfs_dinode_put_rdev(s
8173          XFS_DIFLAG_IMMUTABLE | XFS_DIFLAG_APPEND | XFS_DIFLAG_SYNC | \
8174          XFS_DIFLAG_NOATIME | XFS_DIFLAG_NODUMP | XFS_DIFLAG_RTINHERIT | \
8175          XFS_DIFLAG_PROJINHERIT | XFS_DIFLAG_NOSYMLINKS | XFS_DIFLAG_EXTSIZE | \
8176 -        XFS_DIFLAG_EXTSZINHERIT | XFS_DIFLAG_NODEFRAG | XFS_DIFLAG_FILESTREAM)
8177 +        XFS_DIFLAG_EXTSZINHERIT | XFS_DIFLAG_NODEFRAG | XFS_DIFLAG_FILESTREAM | \
8178 +        XFS_DIFLAG_IXUNLINK)
8179 +
8180 +#define XFS_DIVFLAG_BARRIER    0x01
8181 +#define XFS_DIVFLAG_COW                0x02
8182  
8183  #endif /* __XFS_DINODE_H__ */
8184 diff -NurpP --minimal linux-2.6.38.3/fs/xfs/xfs_fs.h linux-2.6.38.3-vs2.3.0.37-rc14/fs/xfs/xfs_fs.h
8185 --- linux-2.6.38.3/fs/xfs/xfs_fs.h      2011-01-05 21:50:28.000000000 +0100
8186 +++ linux-2.6.38.3-vs2.3.0.37-rc14/fs/xfs/xfs_fs.h      2011-01-29 02:01:07.000000000 +0100
8187 @@ -67,6 +67,9 @@ struct fsxattr {
8188  #define XFS_XFLAG_EXTSZINHERIT 0x00001000      /* inherit inode extent size */
8189  #define XFS_XFLAG_NODEFRAG     0x00002000      /* do not defragment */
8190  #define XFS_XFLAG_FILESTREAM   0x00004000      /* use filestream allocator */
8191 +#define XFS_XFLAG_IXUNLINK     0x00008000      /* immutable invert on unlink */
8192 +#define XFS_XFLAG_BARRIER      0x10000000      /* chroot() barrier */
8193 +#define XFS_XFLAG_COW          0x20000000      /* copy on write mark */
8194  #define XFS_XFLAG_HASATTR      0x80000000      /* no DIFLAG for this   */
8195  
8196  /*
8197 @@ -297,7 +300,8 @@ typedef struct xfs_bstat {
8198  #define        bs_projid       bs_projid_lo    /* (previously just bs_projid)  */
8199         __u16           bs_forkoff;     /* inode fork offset in bytes   */
8200         __u16           bs_projid_hi;   /* higher part of project id    */
8201 -       unsigned char   bs_pad[10];     /* pad space, unused            */
8202 +       unsigned char   bs_pad[8];      /* pad space, unused            */
8203 +       __u16           bs_tag;         /* context tagging              */
8204         __u32           bs_dmevmask;    /* DMIG event mask              */
8205         __u16           bs_dmstate;     /* DMIG state info              */
8206         __u16           bs_aextents;    /* attribute number of extents  */
8207 diff -NurpP --minimal linux-2.6.38.3/fs/xfs/xfs_ialloc.c linux-2.6.38.3-vs2.3.0.37-rc14/fs/xfs/xfs_ialloc.c
8208 --- linux-2.6.38.3/fs/xfs/xfs_ialloc.c  2011-01-05 21:50:28.000000000 +0100
8209 +++ linux-2.6.38.3-vs2.3.0.37-rc14/fs/xfs/xfs_ialloc.c  2011-01-29 02:01:07.000000000 +0100
8210 @@ -37,7 +37,6 @@
8211  #include "xfs_error.h"
8212  #include "xfs_bmap.h"
8213  
8214 -
8215  /*
8216   * Allocation group level functions.
8217   */
8218 diff -NurpP --minimal linux-2.6.38.3/fs/xfs/xfs_inode.c linux-2.6.38.3-vs2.3.0.37-rc14/fs/xfs/xfs_inode.c
8219 --- linux-2.6.38.3/fs/xfs/xfs_inode.c   2011-03-15 18:07:34.000000000 +0100
8220 +++ linux-2.6.38.3-vs2.3.0.37-rc14/fs/xfs/xfs_inode.c   2011-01-29 02:01:07.000000000 +0100
8221 @@ -245,6 +245,7 @@ xfs_inotobp(
8222         return 0;
8223  }
8224  
8225 +#include <linux/vs_tag.h>
8226  
8227  /*
8228   * This routine is called to map an inode to the buffer containing
8229 @@ -650,15 +651,25 @@ xfs_iformat_btree(
8230  STATIC void
8231  xfs_dinode_from_disk(
8232         xfs_icdinode_t          *to,
8233 -       xfs_dinode_t            *from)
8234 +       xfs_dinode_t            *from,
8235 +       int tagged)
8236  {
8237 +       uint32_t uid, gid, tag;
8238 +
8239         to->di_magic = be16_to_cpu(from->di_magic);
8240         to->di_mode = be16_to_cpu(from->di_mode);
8241         to->di_version = from ->di_version;
8242         to->di_format = from->di_format;
8243         to->di_onlink = be16_to_cpu(from->di_onlink);
8244 -       to->di_uid = be32_to_cpu(from->di_uid);
8245 -       to->di_gid = be32_to_cpu(from->di_gid);
8246 +
8247 +       uid = be32_to_cpu(from->di_uid);
8248 +       gid = be32_to_cpu(from->di_gid);
8249 +       tag = be16_to_cpu(from->di_tag);
8250 +
8251 +       to->di_uid = INOTAG_UID(tagged, uid, gid);
8252 +       to->di_gid = INOTAG_GID(tagged, uid, gid);
8253 +       to->di_tag = INOTAG_TAG(tagged, uid, gid, tag);
8254 +
8255         to->di_nlink = be32_to_cpu(from->di_nlink);
8256         to->di_projid_lo = be16_to_cpu(from->di_projid_lo);
8257         to->di_projid_hi = be16_to_cpu(from->di_projid_hi);
8258 @@ -680,21 +691,26 @@ xfs_dinode_from_disk(
8259         to->di_dmevmask = be32_to_cpu(from->di_dmevmask);
8260         to->di_dmstate  = be16_to_cpu(from->di_dmstate);
8261         to->di_flags    = be16_to_cpu(from->di_flags);
8262 +       to->di_vflags   = be16_to_cpu(from->di_vflags);
8263         to->di_gen      = be32_to_cpu(from->di_gen);
8264  }
8265  
8266  void
8267  xfs_dinode_to_disk(
8268         xfs_dinode_t            *to,
8269 -       xfs_icdinode_t          *from)
8270 +       xfs_icdinode_t          *from,
8271 +       int tagged)
8272  {
8273         to->di_magic = cpu_to_be16(from->di_magic);
8274         to->di_mode = cpu_to_be16(from->di_mode);
8275         to->di_version = from ->di_version;
8276         to->di_format = from->di_format;
8277         to->di_onlink = cpu_to_be16(from->di_onlink);
8278 -       to->di_uid = cpu_to_be32(from->di_uid);
8279 -       to->di_gid = cpu_to_be32(from->di_gid);
8280 +
8281 +       to->di_uid = cpu_to_be32(TAGINO_UID(tagged, from->di_uid, from->di_tag));
8282 +       to->di_gid = cpu_to_be32(TAGINO_GID(tagged, from->di_gid, from->di_tag));
8283 +       to->di_tag = cpu_to_be16(TAGINO_TAG(tagged, from->di_tag));
8284 +
8285         to->di_nlink = cpu_to_be32(from->di_nlink);
8286         to->di_projid_lo = cpu_to_be16(from->di_projid_lo);
8287         to->di_projid_hi = cpu_to_be16(from->di_projid_hi);
8288 @@ -716,12 +732,14 @@ xfs_dinode_to_disk(
8289         to->di_dmevmask = cpu_to_be32(from->di_dmevmask);
8290         to->di_dmstate = cpu_to_be16(from->di_dmstate);
8291         to->di_flags = cpu_to_be16(from->di_flags);
8292 +       to->di_vflags = cpu_to_be16(from->di_vflags);
8293         to->di_gen = cpu_to_be32(from->di_gen);
8294  }
8295  
8296  STATIC uint
8297  _xfs_dic2xflags(
8298 -       __uint16_t              di_flags)
8299 +       __uint16_t              di_flags,
8300 +       __uint16_t              di_vflags)
8301  {
8302         uint                    flags = 0;
8303  
8304 @@ -732,6 +750,8 @@ _xfs_dic2xflags(
8305                         flags |= XFS_XFLAG_PREALLOC;
8306                 if (di_flags & XFS_DIFLAG_IMMUTABLE)
8307                         flags |= XFS_XFLAG_IMMUTABLE;
8308 +               if (di_flags & XFS_DIFLAG_IXUNLINK)
8309 +                       flags |= XFS_XFLAG_IXUNLINK;
8310                 if (di_flags & XFS_DIFLAG_APPEND)
8311                         flags |= XFS_XFLAG_APPEND;
8312                 if (di_flags & XFS_DIFLAG_SYNC)
8313 @@ -756,6 +776,10 @@ _xfs_dic2xflags(
8314                         flags |= XFS_XFLAG_FILESTREAM;
8315         }
8316  
8317 +       if (di_vflags & XFS_DIVFLAG_BARRIER)
8318 +               flags |= FS_BARRIER_FL;
8319 +       if (di_vflags & XFS_DIVFLAG_COW)
8320 +               flags |= FS_COW_FL;
8321         return flags;
8322  }
8323  
8324 @@ -765,7 +789,7 @@ xfs_ip2xflags(
8325  {
8326         xfs_icdinode_t          *dic = &ip->i_d;
8327  
8328 -       return _xfs_dic2xflags(dic->di_flags) |
8329 +       return _xfs_dic2xflags(dic->di_flags, dic->di_vflags) |
8330                                 (XFS_IFORK_Q(ip) ? XFS_XFLAG_HASATTR : 0);
8331  }
8332  
8333 @@ -773,7 +797,8 @@ uint
8334  xfs_dic2xflags(
8335         xfs_dinode_t            *dip)
8336  {
8337 -       return _xfs_dic2xflags(be16_to_cpu(dip->di_flags)) |
8338 +       return _xfs_dic2xflags(be16_to_cpu(dip->di_flags),
8339 +                               be16_to_cpu(dip->di_vflags)) |
8340                                 (XFS_DFORK_Q(dip) ? XFS_XFLAG_HASATTR : 0);
8341  }
8342  
8343 @@ -806,7 +831,6 @@ xfs_iread(
8344         if (error)
8345                 return error;
8346         dip = (xfs_dinode_t *)xfs_buf_offset(bp, ip->i_imap.im_boffset);
8347 -
8348         /*
8349          * If we got something that isn't an inode it means someone
8350          * (nfs or dmi) has a stale handle.
8351 @@ -831,7 +855,8 @@ xfs_iread(
8352          * Otherwise, just get the truly permanent information.
8353          */
8354         if (dip->di_mode) {
8355 -               xfs_dinode_from_disk(&ip->i_d, dip);
8356 +               xfs_dinode_from_disk(&ip->i_d, dip,
8357 +                       mp->m_flags & XFS_MOUNT_TAGGED);
8358                 error = xfs_iformat(ip, dip);
8359                 if (error)  {
8360  #ifdef DEBUG
8361 @@ -1028,6 +1053,7 @@ xfs_ialloc(
8362         ASSERT(ip->i_d.di_nlink == nlink);
8363         ip->i_d.di_uid = current_fsuid();
8364         ip->i_d.di_gid = current_fsgid();
8365 +       ip->i_d.di_tag = current_fstag(&ip->i_vnode);
8366         xfs_set_projid(ip, prid);
8367         memset(&(ip->i_d.di_pad[0]), 0, sizeof(ip->i_d.di_pad));
8368  
8369 @@ -1088,6 +1114,7 @@ xfs_ialloc(
8370         ip->i_d.di_dmevmask = 0;
8371         ip->i_d.di_dmstate = 0;
8372         ip->i_d.di_flags = 0;
8373 +       ip->i_d.di_vflags = 0;
8374         flags = XFS_ILOG_CORE;
8375         switch (mode & S_IFMT) {
8376         case S_IFIFO:
8377 @@ -2122,6 +2149,7 @@ xfs_ifree(
8378         }
8379         ip->i_d.di_mode = 0;            /* mark incore inode as free */
8380         ip->i_d.di_flags = 0;
8381 +       ip->i_d.di_vflags = 0;
8382         ip->i_d.di_dmevmask = 0;
8383         ip->i_d.di_forkoff = 0;         /* mark the attr fork not in use */
8384         ip->i_df.if_ext_max =
8385 @@ -3004,7 +3032,8 @@ xfs_iflush_int(
8386          * because if the inode is dirty at all the core must
8387          * be.
8388          */
8389 -       xfs_dinode_to_disk(dip, &ip->i_d);
8390 +       xfs_dinode_to_disk(dip, &ip->i_d,
8391 +               mp->m_flags & XFS_MOUNT_TAGGED);
8392  
8393         /* Wrap, we never let the log put out DI_MAX_FLUSH */
8394         if (ip->i_d.di_flushiter == DI_MAX_FLUSH)
8395 diff -NurpP --minimal linux-2.6.38.3/fs/xfs/xfs_inode.h linux-2.6.38.3-vs2.3.0.37-rc14/fs/xfs/xfs_inode.h
8396 --- linux-2.6.38.3/fs/xfs/xfs_inode.h   2011-03-15 18:07:34.000000000 +0100
8397 +++ linux-2.6.38.3-vs2.3.0.37-rc14/fs/xfs/xfs_inode.h   2011-01-29 02:01:07.000000000 +0100
8398 @@ -136,7 +136,9 @@ typedef struct xfs_icdinode {
8399         __uint32_t      di_nlink;       /* number of links to file */
8400         __uint16_t      di_projid_lo;   /* lower part of owner's project id */
8401         __uint16_t      di_projid_hi;   /* higher part of owner's project id */
8402 -       __uint8_t       di_pad[6];      /* unused, zeroed space */
8403 +       __uint8_t       di_pad[2];      /* unused, zeroed space */
8404 +       __uint16_t      di_tag;         /* context tagging */
8405 +       __uint16_t      di_vflags;      /* vserver specific flags */
8406         __uint16_t      di_flushiter;   /* incremented on flush */
8407         xfs_ictimestamp_t di_atime;     /* time last accessed */
8408         xfs_ictimestamp_t di_mtime;     /* time last modified */
8409 @@ -530,7 +532,7 @@ int         xfs_itobp(struct xfs_mount *, struc
8410  int            xfs_iread(struct xfs_mount *, struct xfs_trans *,
8411                           struct xfs_inode *, uint);
8412  void           xfs_dinode_to_disk(struct xfs_dinode *,
8413 -                                  struct xfs_icdinode *);
8414 +                                  struct xfs_icdinode *, int);
8415  void           xfs_idestroy_fork(struct xfs_inode *, int);
8416  void           xfs_idata_realloc(struct xfs_inode *, int, int);
8417  void           xfs_iroot_realloc(struct xfs_inode *, int, int);
8418 diff -NurpP --minimal linux-2.6.38.3/fs/xfs/xfs_itable.c linux-2.6.38.3-vs2.3.0.37-rc14/fs/xfs/xfs_itable.c
8419 --- linux-2.6.38.3/fs/xfs/xfs_itable.c  2011-01-05 21:50:28.000000000 +0100
8420 +++ linux-2.6.38.3-vs2.3.0.37-rc14/fs/xfs/xfs_itable.c  2011-01-29 02:01:07.000000000 +0100
8421 @@ -98,6 +98,7 @@ xfs_bulkstat_one_int(
8422         buf->bs_mode = dic->di_mode;
8423         buf->bs_uid = dic->di_uid;
8424         buf->bs_gid = dic->di_gid;
8425 +       buf->bs_tag = dic->di_tag;
8426         buf->bs_size = dic->di_size;
8427  
8428         /*
8429 diff -NurpP --minimal linux-2.6.38.3/fs/xfs/xfs_log_recover.c linux-2.6.38.3-vs2.3.0.37-rc14/fs/xfs/xfs_log_recover.c
8430 --- linux-2.6.38.3/fs/xfs/xfs_log_recover.c     2011-03-15 18:07:34.000000000 +0100
8431 +++ linux-2.6.38.3-vs2.3.0.37-rc14/fs/xfs/xfs_log_recover.c     2011-01-29 02:01:07.000000000 +0100
8432 @@ -2317,7 +2317,8 @@ xlog_recover_inode_pass2(
8433         }
8434  
8435         /* The core is in in-core format */
8436 -       xfs_dinode_to_disk(dip, item->ri_buf[1].i_addr);
8437 +       xfs_dinode_to_disk(dip, item->ri_buf[1].i_addr,
8438 +               mp->m_flags & XFS_MOUNT_TAGGED);
8439  
8440         /* the rest is in on-disk format */
8441         if (item->ri_buf[1].i_len > sizeof(struct xfs_icdinode)) {
8442 diff -NurpP --minimal linux-2.6.38.3/fs/xfs/xfs_mount.h linux-2.6.38.3-vs2.3.0.37-rc14/fs/xfs/xfs_mount.h
8443 --- linux-2.6.38.3/fs/xfs/xfs_mount.h   2011-03-15 18:07:34.000000000 +0100
8444 +++ linux-2.6.38.3-vs2.3.0.37-rc14/fs/xfs/xfs_mount.h   2011-01-29 02:01:07.000000000 +0100
8445 @@ -251,6 +251,7 @@ typedef struct xfs_mount {
8446                                                    allocator */
8447  #define XFS_MOUNT_NOATTR2      (1ULL << 25)    /* disable use of attr2 format */
8448  
8449 +#define XFS_MOUNT_TAGGED       (1ULL << 31)    /* context tagging */
8450  
8451  /*
8452   * Default minimum read and write sizes.
8453 diff -NurpP --minimal linux-2.6.38.3/fs/xfs/xfs_vnodeops.c linux-2.6.38.3-vs2.3.0.37-rc14/fs/xfs/xfs_vnodeops.c
8454 --- linux-2.6.38.3/fs/xfs/xfs_vnodeops.c        2011-03-15 18:07:34.000000000 +0100
8455 +++ linux-2.6.38.3-vs2.3.0.37-rc14/fs/xfs/xfs_vnodeops.c        2011-01-29 02:01:07.000000000 +0100
8456 @@ -50,6 +50,78 @@
8457  #include "xfs_vnodeops.h"
8458  #include "xfs_trace.h"
8459  
8460 +
8461 +STATIC void
8462 +xfs_get_inode_flags(
8463 +       xfs_inode_t     *ip)
8464 +{
8465 +       struct inode    *inode = VFS_I(ip);
8466 +       unsigned int    flags = inode->i_flags;
8467 +       unsigned int    vflags = inode->i_vflags;
8468 +
8469 +       if (flags & S_IMMUTABLE)
8470 +               ip->i_d.di_flags |= XFS_DIFLAG_IMMUTABLE;
8471 +       else
8472 +               ip->i_d.di_flags &= ~XFS_DIFLAG_IMMUTABLE;
8473 +       if (flags & S_IXUNLINK)
8474 +               ip->i_d.di_flags |= XFS_DIFLAG_IXUNLINK;
8475 +       else
8476 +               ip->i_d.di_flags &= ~XFS_DIFLAG_IXUNLINK;
8477 +
8478 +       if (vflags & V_BARRIER)
8479 +               ip->i_d.di_vflags |= XFS_DIVFLAG_BARRIER;
8480 +       else
8481 +               ip->i_d.di_vflags &= ~XFS_DIVFLAG_BARRIER;
8482 +       if (vflags & V_COW)
8483 +               ip->i_d.di_vflags |= XFS_DIVFLAG_COW;
8484 +       else
8485 +               ip->i_d.di_vflags &= ~XFS_DIVFLAG_COW;
8486 +}
8487 +
8488 +int
8489 +xfs_sync_flags(
8490 +       struct inode            *inode,
8491 +       int                     flags,
8492 +       int                     vflags)
8493 +{
8494 +       struct xfs_inode        *ip = XFS_I(inode);
8495 +       struct xfs_mount        *mp = ip->i_mount;
8496 +       struct xfs_trans        *tp;
8497 +       unsigned int            lock_flags = 0;
8498 +       int                     code;
8499 +
8500 +       tp = xfs_trans_alloc(mp, XFS_TRANS_SETATTR_NOT_SIZE);
8501 +       code = xfs_trans_reserve(tp, 0, XFS_ICHANGE_LOG_RES(mp), 0, 0, 0);
8502 +       if (code)
8503 +               goto error_out;
8504 +
8505 +       xfs_ilock(ip, XFS_ILOCK_EXCL);
8506 +
8507 +       xfs_trans_ijoin(tp, ip);
8508 +
8509 +       inode->i_flags = flags;
8510 +       inode->i_vflags = vflags;
8511 +       xfs_get_inode_flags(ip);
8512 +
8513 +       xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE);
8514 +       xfs_trans_ichgtime(tp, ip, XFS_ICHGTIME_CHG);
8515 +
8516 +       XFS_STATS_INC(xs_ig_attrchg);
8517 +
8518 +       if (mp->m_flags & XFS_MOUNT_WSYNC)
8519 +               xfs_trans_set_sync(tp);
8520 +       code = xfs_trans_commit(tp, 0);
8521 +       xfs_iunlock(ip, XFS_ILOCK_EXCL);
8522 +       return code;
8523 +
8524 +error_out:
8525 +       xfs_trans_cancel(tp, 0);
8526 +       if (lock_flags)
8527 +               xfs_iunlock(ip, XFS_ILOCK_EXCL);
8528 +       return code;
8529 +}
8530 +
8531 +
8532  int
8533  xfs_setattr(
8534         struct xfs_inode        *ip,
8535 @@ -65,6 +137,7 @@ xfs_setattr(
8536         uint                    commit_flags=0;
8537         uid_t                   uid=0, iuid=0;
8538         gid_t                   gid=0, igid=0;
8539 +       tag_t                   tag=0, itag=0;
8540         struct xfs_dquot        *udqp, *gdqp, *olddquot1, *olddquot2;
8541         int                     need_iolock = 1;
8542  
8543 @@ -147,7 +220,7 @@ xfs_setattr(
8544         /*
8545          * Change file ownership.  Must be the owner or privileged.
8546          */
8547 -       if (mask & (ATTR_UID|ATTR_GID)) {
8548 +       if (mask & (ATTR_UID|ATTR_GID|ATTR_TAG)) {
8549                 /*
8550                  * These IDs could have changed since we last looked at them.
8551                  * But, we're assured that if the ownership did change
8552 @@ -156,8 +229,10 @@ xfs_setattr(
8553                  */
8554                 iuid = ip->i_d.di_uid;
8555                 igid = ip->i_d.di_gid;
8556 +               itag = ip->i_d.di_tag;
8557                 gid = (mask & ATTR_GID) ? iattr->ia_gid : igid;
8558                 uid = (mask & ATTR_UID) ? iattr->ia_uid : iuid;
8559 +               tag = (mask & ATTR_TAG) ? iattr->ia_tag : itag;
8560  
8561                 /*
8562                  * Do a quota reservation only if uid/gid is actually
8563 @@ -165,7 +240,8 @@ xfs_setattr(
8564                  */
8565                 if (XFS_IS_QUOTA_RUNNING(mp) &&
8566                     ((XFS_IS_UQUOTA_ON(mp) && iuid != uid) ||
8567 -                    (XFS_IS_GQUOTA_ON(mp) && igid != gid))) {
8568 +                    (XFS_IS_GQUOTA_ON(mp) && igid != gid) ||
8569 +                    (XFS_IS_GQUOTA_ON(mp) && itag != tag))) {
8570                         ASSERT(tp);
8571                         code = xfs_qm_vop_chown_reserve(tp, ip, udqp, gdqp,
8572                                                 capable(CAP_FOWNER) ?
8573 @@ -329,7 +405,7 @@ xfs_setattr(
8574         /*
8575          * Change file ownership.  Must be the owner or privileged.
8576          */
8577 -       if (mask & (ATTR_UID|ATTR_GID)) {
8578 +       if (mask & (ATTR_UID|ATTR_GID|ATTR_TAG)) {
8579                 /*
8580                  * CAP_FSETID overrides the following restrictions:
8581                  *
8582 @@ -345,6 +421,10 @@ xfs_setattr(
8583                  * Change the ownerships and register quota modifications
8584                  * in the transaction.
8585                  */
8586 +               if (itag != tag) {
8587 +                       ip->i_d.di_tag = tag;
8588 +                       inode->i_tag = tag;
8589 +               }
8590                 if (iuid != uid) {
8591                         if (XFS_IS_QUOTA_RUNNING(mp) && XFS_IS_UQUOTA_ON(mp)) {
8592                                 ASSERT(mask & ATTR_UID);
8593 diff -NurpP --minimal linux-2.6.38.3/fs/xfs/xfs_vnodeops.h linux-2.6.38.3-vs2.3.0.37-rc14/fs/xfs/xfs_vnodeops.h
8594 --- linux-2.6.38.3/fs/xfs/xfs_vnodeops.h        2011-01-05 21:50:28.000000000 +0100
8595 +++ linux-2.6.38.3-vs2.3.0.37-rc14/fs/xfs/xfs_vnodeops.h        2011-01-29 02:01:07.000000000 +0100
8596 @@ -13,6 +13,7 @@ struct xfs_inode;
8597  struct xfs_iomap;
8598  
8599  
8600 +int xfs_sync_xflags(struct xfs_inode *ip);
8601  int xfs_setattr(struct xfs_inode *ip, struct iattr *vap, int flags);
8602  #define        XFS_ATTR_DMI            0x01    /* invocation from a DMI function */
8603  #define        XFS_ATTR_NONBLOCK       0x02    /* return EAGAIN if operation would block */
8604 diff -NurpP --minimal linux-2.6.38.3/include/asm-generic/tlb.h linux-2.6.38.3-vs2.3.0.37-rc14/include/asm-generic/tlb.h
8605 --- linux-2.6.38.3/include/asm-generic/tlb.h    2009-09-10 15:26:24.000000000 +0200
8606 +++ linux-2.6.38.3-vs2.3.0.37-rc14/include/asm-generic/tlb.h    2011-01-29 02:01:07.000000000 +0100
8607 @@ -14,6 +14,7 @@
8608  #define _ASM_GENERIC__TLB_H
8609  
8610  #include <linux/swap.h>
8611 +#include <linux/vs_memory.h>
8612  #include <asm/pgalloc.h>
8613  #include <asm/tlbflush.h>
8614  
8615 diff -NurpP --minimal linux-2.6.38.3/include/linux/Kbuild linux-2.6.38.3-vs2.3.0.37-rc14/include/linux/Kbuild
8616 --- linux-2.6.38.3/include/linux/Kbuild 2011-03-15 18:07:37.000000000 +0100
8617 +++ linux-2.6.38.3-vs2.3.0.37-rc14/include/linux/Kbuild 2011-02-17 02:17:51.000000000 +0100
8618 @@ -16,6 +16,7 @@ header-y += netfilter_bridge/
8619  header-y += netfilter_ipv4/
8620  header-y += netfilter_ipv6/
8621  header-y += usb/
8622 +header-y += vserver/
8623  header-y += wimax/
8624  
8625  objhdr-y += version.h
8626 diff -NurpP --minimal linux-2.6.38.3/include/linux/capability.h linux-2.6.38.3-vs2.3.0.37-rc14/include/linux/capability.h
8627 --- linux-2.6.38.3/include/linux/capability.h   2011-03-15 18:07:37.000000000 +0100
8628 +++ linux-2.6.38.3-vs2.3.0.37-rc14/include/linux/capability.h   2011-01-29 02:01:07.000000000 +0100
8629 @@ -279,6 +279,7 @@ struct cpu_vfs_cap_data {
8630     arbitrary SCSI commands */
8631  /* Allow setting encryption key on loopback filesystem */
8632  /* Allow setting zone reclaim policy */
8633 +/* Allow the selection of a security context */
8634  
8635  #define CAP_SYS_ADMIN        21
8636  
8637 @@ -357,7 +358,12 @@ struct cpu_vfs_cap_data {
8638  
8639  #define CAP_LAST_CAP         CAP_SYSLOG
8640  
8641 -#define cap_valid(x) ((x) >= 0 && (x) <= CAP_LAST_CAP)
8642 +/* Allow context manipulations */
8643 +/* Allow changing context info on files */
8644 +
8645 +#define CAP_CONTEXT         63
8646 +
8647 +#define cap_valid(x) ((x) >= 0 && ((x) <= CAP_LAST_CAP || (x) == CAP_CONTEXT))
8648  
8649  /*
8650   * Bit location of each capability (used by user-space library and kernel)
8651 diff -NurpP --minimal linux-2.6.38.3/include/linux/cred.h linux-2.6.38.3-vs2.3.0.37-rc14/include/linux/cred.h
8652 --- linux-2.6.38.3/include/linux/cred.h 2011-01-05 21:50:29.000000000 +0100
8653 +++ linux-2.6.38.3-vs2.3.0.37-rc14/include/linux/cred.h 2011-01-31 12:03:07.000000000 +0100
8654 @@ -155,6 +155,7 @@ extern void exit_creds(struct task_struc
8655  extern int copy_creds(struct task_struct *, unsigned long);
8656  extern const struct cred *get_task_cred(struct task_struct *);
8657  extern struct cred *cred_alloc_blank(void);
8658 +extern struct cred *__prepare_creds(const struct cred *);
8659  extern struct cred *prepare_creds(void);
8660  extern struct cred *prepare_exec_creds(void);
8661  extern int commit_creds(struct cred *);
8662 @@ -208,6 +209,31 @@ static inline void validate_process_cred
8663  }
8664  #endif
8665  
8666 +static inline void set_cred_subscribers(struct cred *cred, int n)
8667 +{
8668 +#ifdef CONFIG_DEBUG_CREDENTIALS
8669 +       atomic_set(&cred->subscribers, n);
8670 +#endif
8671 +}
8672 +
8673 +static inline int read_cred_subscribers(const struct cred *cred)
8674 +{
8675 +#ifdef CONFIG_DEBUG_CREDENTIALS
8676 +       return atomic_read(&cred->subscribers);
8677 +#else
8678 +       return 0;
8679 +#endif
8680 +}
8681 +
8682 +static inline void alter_cred_subscribers(const struct cred *_cred, int n)
8683 +{
8684 +#ifdef CONFIG_DEBUG_CREDENTIALS
8685 +       struct cred *cred = (struct cred *) _cred;
8686 +
8687 +       atomic_add(n, &cred->subscribers);
8688 +#endif
8689 +}
8690 +
8691  /**
8692   * get_new_cred - Get a reference on a new set of credentials
8693   * @cred: The new credentials to reference
8694 diff -NurpP --minimal linux-2.6.38.3/include/linux/devpts_fs.h linux-2.6.38.3-vs2.3.0.37-rc14/include/linux/devpts_fs.h
8695 --- linux-2.6.38.3/include/linux/devpts_fs.h    2008-12-25 00:26:37.000000000 +0100
8696 +++ linux-2.6.38.3-vs2.3.0.37-rc14/include/linux/devpts_fs.h    2011-01-29 02:01:07.000000000 +0100
8697 @@ -45,5 +45,4 @@ static inline void devpts_pty_kill(struc
8698  
8699  #endif
8700  
8701 -
8702  #endif /* _LINUX_DEVPTS_FS_H */
8703 diff -NurpP --minimal linux-2.6.38.3/include/linux/ext2_fs.h linux-2.6.38.3-vs2.3.0.37-rc14/include/linux/ext2_fs.h
8704 --- linux-2.6.38.3/include/linux/ext2_fs.h      2010-02-25 11:52:07.000000000 +0100
8705 +++ linux-2.6.38.3-vs2.3.0.37-rc14/include/linux/ext2_fs.h      2011-01-29 02:01:07.000000000 +0100
8706 @@ -189,8 +189,12 @@ struct ext2_group_desc
8707  #define EXT2_NOTAIL_FL                 FS_NOTAIL_FL    /* file tail should not be merged */
8708  #define EXT2_DIRSYNC_FL                        FS_DIRSYNC_FL   /* dirsync behaviour (directories only) */
8709  #define EXT2_TOPDIR_FL                 FS_TOPDIR_FL    /* Top of directory hierarchies*/
8710 +#define EXT2_IXUNLINK_FL               FS_IXUNLINK_FL  /* Immutable invert on unlink */
8711  #define EXT2_RESERVED_FL               FS_RESERVED_FL  /* reserved for ext2 lib */
8712  
8713 +#define EXT2_BARRIER_FL                        FS_BARRIER_FL   /* Barrier for chroot() */
8714 +#define EXT2_COW_FL                    FS_COW_FL       /* Copy on Write marker */
8715 +
8716  #define EXT2_FL_USER_VISIBLE           FS_FL_USER_VISIBLE      /* User visible flags */
8717  #define EXT2_FL_USER_MODIFIABLE                FS_FL_USER_MODIFIABLE   /* User modifiable flags */
8718  
8719 @@ -274,7 +278,8 @@ struct ext2_inode {
8720                         __u16   i_pad1;
8721                         __le16  l_i_uid_high;   /* these 2 fields    */
8722                         __le16  l_i_gid_high;   /* were reserved2[0] */
8723 -                       __u32   l_i_reserved2;
8724 +                       __le16  l_i_tag;        /* Context Tag */
8725 +                       __u16   l_i_reserved2;
8726                 } linux2;
8727                 struct {
8728                         __u8    h_i_frag;       /* Fragment number */
8729 @@ -303,6 +308,7 @@ struct ext2_inode {
8730  #define i_gid_low      i_gid
8731  #define i_uid_high     osd2.linux2.l_i_uid_high
8732  #define i_gid_high     osd2.linux2.l_i_gid_high
8733 +#define i_raw_tag      osd2.linux2.l_i_tag
8734  #define i_reserved2    osd2.linux2.l_i_reserved2
8735  #endif
8736  
8737 @@ -347,6 +353,7 @@ struct ext2_inode {
8738  #define EXT2_MOUNT_USRQUOTA            0x020000  /* user quota */
8739  #define EXT2_MOUNT_GRPQUOTA            0x040000  /* group quota */
8740  #define EXT2_MOUNT_RESERVATION         0x080000  /* Preallocation */
8741 +#define EXT2_MOUNT_TAGGED              (1<<24)   /* Enable Context Tags */
8742  
8743  
8744  #define clear_opt(o, opt)              o &= ~EXT2_MOUNT_##opt
8745 diff -NurpP --minimal linux-2.6.38.3/include/linux/ext3_fs.h linux-2.6.38.3-vs2.3.0.37-rc14/include/linux/ext3_fs.h
8746 --- linux-2.6.38.3/include/linux/ext3_fs.h      2011-03-15 18:07:38.000000000 +0100
8747 +++ linux-2.6.38.3-vs2.3.0.37-rc14/include/linux/ext3_fs.h      2011-01-29 02:01:07.000000000 +0100
8748 @@ -173,10 +173,14 @@ struct ext3_group_desc
8749  #define EXT3_NOTAIL_FL                 0x00008000 /* file tail should not be merged */
8750  #define EXT3_DIRSYNC_FL                        0x00010000 /* dirsync behaviour (directories only) */
8751  #define EXT3_TOPDIR_FL                 0x00020000 /* Top of directory hierarchies*/
8752 +#define EXT3_IXUNLINK_FL               0x08000000 /* Immutable invert on unlink */
8753  #define EXT3_RESERVED_FL               0x80000000 /* reserved for ext3 lib */
8754  
8755 -#define EXT3_FL_USER_VISIBLE           0x0003DFFF /* User visible flags */
8756 -#define EXT3_FL_USER_MODIFIABLE                0x000380FF /* User modifiable flags */
8757 +#define EXT3_BARRIER_FL                        0x04000000 /* Barrier for chroot() */
8758 +#define EXT3_COW_FL                    0x20000000 /* Copy on Write marker */
8759 +
8760 +#define EXT3_FL_USER_VISIBLE           0x0103DFFF /* User visible flags */
8761 +#define EXT3_FL_USER_MODIFIABLE                0x010380FF /* User modifiable flags */
8762  
8763  /* Flags that should be inherited by new inodes from their parent. */
8764  #define EXT3_FL_INHERITED (EXT3_SECRM_FL | EXT3_UNRM_FL | EXT3_COMPR_FL |\
8765 @@ -312,7 +316,8 @@ struct ext3_inode {
8766                         __u16   i_pad1;
8767                         __le16  l_i_uid_high;   /* these 2 fields    */
8768                         __le16  l_i_gid_high;   /* were reserved2[0] */
8769 -                       __u32   l_i_reserved2;
8770 +                       __le16  l_i_tag;        /* Context Tag */
8771 +                       __u16   l_i_reserved2;
8772                 } linux2;
8773                 struct {
8774                         __u8    h_i_frag;       /* Fragment number */
8775 @@ -343,6 +348,7 @@ struct ext3_inode {
8776  #define i_gid_low      i_gid
8777  #define i_uid_high     osd2.linux2.l_i_uid_high
8778  #define i_gid_high     osd2.linux2.l_i_gid_high
8779 +#define i_raw_tag      osd2.linux2.l_i_tag
8780  #define i_reserved2    osd2.linux2.l_i_reserved2
8781  
8782  #elif defined(__GNU__)
8783 @@ -405,6 +411,7 @@ struct ext3_inode {
8784  #define EXT3_MOUNT_GRPQUOTA            0x200000 /* "old" group quota */
8785  #define EXT3_MOUNT_DATA_ERR_ABORT      0x400000 /* Abort on file data write
8786                                                   * error in ordered mode */
8787 +#define EXT3_MOUNT_TAGGED              (1<<24) /* Enable Context Tags */
8788  
8789  /* Compatibility, for having both ext2_fs.h and ext3_fs.h included at once */
8790  #ifndef _LINUX_EXT2_FS_H
8791 @@ -918,6 +925,7 @@ extern void ext3_get_inode_flags(struct 
8792  extern void ext3_set_aops(struct inode *inode);
8793  extern int ext3_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
8794                        u64 start, u64 len);
8795 +extern int ext3_sync_flags(struct inode *, int, int);
8796  
8797  /* ioctl.c */
8798  extern long ext3_ioctl(struct file *, unsigned int, unsigned long);
8799 diff -NurpP --minimal linux-2.6.38.3/include/linux/fs.h linux-2.6.38.3-vs2.3.0.37-rc14/include/linux/fs.h
8800 --- linux-2.6.38.3/include/linux/fs.h   2011-03-15 18:07:38.000000000 +0100
8801 +++ linux-2.6.38.3-vs2.3.0.37-rc14/include/linux/fs.h   2011-03-07 16:53:28.000000000 +0100
8802 @@ -214,6 +214,9 @@ struct inodes_stat_t {
8803  #define MS_KERNMOUNT   (1<<22) /* this is a kern_mount call */
8804  #define MS_I_VERSION   (1<<23) /* Update inode I_version field */
8805  #define MS_STRICTATIME (1<<24) /* Always perform atime updates */
8806 +#define MS_TAGGED      (1<<25) /* use generic inode tagging */
8807 +#define MS_TAGID       (1<<26) /* use specific tag for this mount */
8808 +#define MS_NOTAGCHECK  (1<<27) /* don't check tags */
8809  #define MS_BORN                (1<<29)
8810  #define MS_ACTIVE      (1<<30)
8811  #define MS_NOUSER      (1<<31)
8812 @@ -243,6 +246,14 @@ struct inodes_stat_t {
8813  #define S_PRIVATE      512     /* Inode is fs-internal */
8814  #define S_IMA          1024    /* Inode has an associated IMA struct */
8815  #define S_AUTOMOUNT    2048    /* Automount/referral quasi-directory */
8816 +#define S_IXUNLINK     4096    /* Immutable Invert on unlink */
8817 +
8818 +/* Linux-VServer related Inode flags */
8819 +
8820 +#define V_VALID                1
8821 +#define V_XATTR                2
8822 +#define V_BARRIER      4       /* Barrier for chroot() */
8823 +#define V_COW          8       /* Copy on Write */
8824  
8825  /*
8826   * Note that nosuid etc flags are inode-specific: setting some file-system
8827 @@ -265,12 +276,15 @@ struct inodes_stat_t {
8828  #define IS_DIRSYNC(inode)      (__IS_FLG(inode, MS_SYNCHRONOUS|MS_DIRSYNC) || \
8829                                         ((inode)->i_flags & (S_SYNC|S_DIRSYNC)))
8830  #define IS_MANDLOCK(inode)     __IS_FLG(inode, MS_MANDLOCK)
8831 -#define IS_NOATIME(inode)   __IS_FLG(inode, MS_RDONLY|MS_NOATIME)
8832 -#define IS_I_VERSION(inode)   __IS_FLG(inode, MS_I_VERSION)
8833 +#define IS_NOATIME(inode)      __IS_FLG(inode, MS_RDONLY|MS_NOATIME)
8834 +#define IS_I_VERSION(inode)    __IS_FLG(inode, MS_I_VERSION)
8835 +#define IS_TAGGED(inode)       __IS_FLG(inode, MS_TAGGED)
8836  
8837  #define IS_NOQUOTA(inode)      ((inode)->i_flags & S_NOQUOTA)
8838  #define IS_APPEND(inode)       ((inode)->i_flags & S_APPEND)
8839  #define IS_IMMUTABLE(inode)    ((inode)->i_flags & S_IMMUTABLE)
8840 +#define IS_IXUNLINK(inode)     ((inode)->i_flags & S_IXUNLINK)
8841 +#define IS_IXORUNLINK(inode)   ((IS_IXUNLINK(inode) ? S_IMMUTABLE : 0) ^ IS_IMMUTABLE(inode))
8842  #define IS_POSIXACL(inode)     __IS_FLG(inode, MS_POSIXACL)
8843  
8844  #define IS_DEADDIR(inode)      ((inode)->i_flags & S_DEAD)
8845 @@ -280,6 +294,16 @@ struct inodes_stat_t {
8846  #define IS_IMA(inode)          ((inode)->i_flags & S_IMA)
8847  #define IS_AUTOMOUNT(inode)    ((inode)->i_flags & S_AUTOMOUNT)
8848  
8849 +#define IS_BARRIER(inode)      (S_ISDIR((inode)->i_mode) && ((inode)->i_vflags & V_BARRIER))
8850 +
8851 +#ifdef CONFIG_VSERVER_COWBL
8852 +#  define IS_COW(inode)                (IS_IXUNLINK(inode) && IS_IMMUTABLE(inode))
8853 +#  define IS_COW_LINK(inode)   (S_ISREG((inode)->i_mode) && ((inode)->i_nlink > 1))
8854 +#else
8855 +#  define IS_COW(inode)                (0)
8856 +#  define IS_COW_LINK(inode)   (0)
8857 +#endif
8858 +
8859  /* the read-only stuff doesn't really belong here, but any other place is
8860     probably as bad and I don't want to create yet another include file. */
8861  
8862 @@ -364,11 +388,14 @@ struct inodes_stat_t {
8863  #define FS_TOPDIR_FL                   0x00020000 /* Top of directory hierarchies*/
8864  #define FS_EXTENT_FL                   0x00080000 /* Extents */
8865  #define FS_DIRECTIO_FL                 0x00100000 /* Use direct i/o */
8866 +#define FS_IXUNLINK_FL                 0x08000000 /* Immutable invert on unlink */
8867  #define FS_RESERVED_FL                 0x80000000 /* reserved for ext2 lib */
8868  
8869 -#define FS_FL_USER_VISIBLE             0x0003DFFF /* User visible flags */
8870 -#define FS_FL_USER_MODIFIABLE          0x000380FF /* User modifiable flags */
8871 +#define FS_BARRIER_FL                  0x04000000 /* Barrier for chroot() */
8872 +#define FS_COW_FL                      0x20000000 /* Copy on Write marker */
8873  
8874 +#define FS_FL_USER_VISIBLE             0x0103DFFF /* User visible flags */
8875 +#define FS_FL_USER_MODIFIABLE          0x010380FF /* User modifiable flags */
8876  
8877  #define SYNC_FILE_RANGE_WAIT_BEFORE    1
8878  #define SYNC_FILE_RANGE_WRITE          2
8879 @@ -449,6 +476,7 @@ typedef void (dio_iodone_t)(struct kiocb
8880  #define ATTR_KILL_PRIV (1 << 14)
8881  #define ATTR_OPEN      (1 << 15) /* Truncating from open(O_TRUNC) */
8882  #define ATTR_TIMES_SET (1 << 16)
8883 +#define ATTR_TAG       (1 << 17)
8884  
8885  /*
8886   * This is the Inode Attributes structure, used for notify_change().  It
8887 @@ -464,6 +492,7 @@ struct iattr {
8888         umode_t         ia_mode;
8889         uid_t           ia_uid;
8890         gid_t           ia_gid;
8891 +       tag_t           ia_tag;
8892         loff_t          ia_size;
8893         struct timespec ia_atime;
8894         struct timespec ia_mtime;
8895 @@ -477,6 +506,9 @@ struct iattr {
8896         struct file     *ia_file;
8897  };
8898  
8899 +#define ATTR_FLAG_BARRIER      512     /* Barrier for chroot() */
8900 +#define ATTR_FLAG_IXUNLINK     1024    /* Immutable invert on unlink */
8901 +
8902  /*
8903   * Includes for diskquotas.
8904   */
8905 @@ -742,11 +774,13 @@ struct inode {
8906         umode_t                 i_mode;
8907         uid_t                   i_uid;
8908         gid_t                   i_gid;
8909 +       tag_t                   i_tag;
8910         const struct inode_operations   *i_op;
8911         struct super_block      *i_sb;
8912  
8913         spinlock_t              i_lock; /* i_blocks, i_bytes, maybe i_size */
8914 -       unsigned int            i_flags;
8915 +       unsigned short          i_flags;
8916 +       unsigned short          i_vflags;
8917         struct mutex            i_mutex;
8918  
8919         unsigned long           i_state;
8920 @@ -764,6 +798,7 @@ struct inode {
8921         atomic_t                i_count;
8922         unsigned int            i_nlink;
8923         dev_t                   i_rdev;
8924 +       dev_t                   i_mdev;
8925         unsigned int            i_blkbits;
8926         u64                     i_version;
8927         loff_t                  i_size;
8928 @@ -892,12 +927,12 @@ static inline void i_size_write(struct i
8929  
8930  static inline unsigned iminor(const struct inode *inode)
8931  {
8932 -       return MINOR(inode->i_rdev);
8933 +       return MINOR(inode->i_mdev);
8934  }
8935  
8936  static inline unsigned imajor(const struct inode *inode)
8937  {
8938 -       return MAJOR(inode->i_rdev);
8939 +       return MAJOR(inode->i_mdev);
8940  }
8941  
8942  extern struct block_device *I_BDEV(struct inode *inode);
8943 @@ -959,6 +994,7 @@ struct file {
8944         loff_t                  f_pos;
8945         struct fown_struct      f_owner;
8946         const struct cred       *f_cred;
8947 +       xid_t                   f_xid;
8948         struct file_ra_state    f_ra;
8949  
8950         u64                     f_version;
8951 @@ -1096,6 +1132,7 @@ struct file_lock {
8952         struct file *fl_file;
8953         loff_t fl_start;
8954         loff_t fl_end;
8955 +       xid_t fl_xid;
8956  
8957         struct fasync_struct *  fl_fasync; /* for lease break notifications */
8958         unsigned long fl_break_time;    /* for nonblocking lease breaks */
8959 @@ -1584,6 +1621,7 @@ struct inode_operations {
8960         ssize_t (*getxattr) (struct dentry *, const char *, void *, size_t);
8961         ssize_t (*listxattr) (struct dentry *, char *, size_t);
8962         int (*removexattr) (struct dentry *, const char *);
8963 +       int (*sync_flags) (struct inode *, int, int);
8964         void (*truncate_range)(struct inode *, loff_t, loff_t);
8965         int (*fiemap)(struct inode *, struct fiemap_extent_info *, u64 start,
8966                       u64 len);
8967 @@ -1602,6 +1640,7 @@ extern ssize_t vfs_readv(struct file *, 
8968                 unsigned long, loff_t *);
8969  extern ssize_t vfs_writev(struct file *, const struct iovec __user *,
8970                 unsigned long, loff_t *);
8971 +ssize_t vfs_sendfile(struct file *, struct file *, loff_t *, size_t, loff_t);
8972  
8973  struct super_operations {
8974         struct inode *(*alloc_inode)(struct super_block *sb);
8975 @@ -2414,6 +2453,7 @@ extern int dcache_dir_open(struct inode 
8976  extern int dcache_dir_close(struct inode *, struct file *);
8977  extern loff_t dcache_dir_lseek(struct file *, loff_t, int);
8978  extern int dcache_readdir(struct file *, void *, filldir_t);
8979 +extern int dcache_readdir_filter(struct file *, void *, filldir_t, int (*)(struct dentry *));
8980  extern int simple_setattr(struct dentry *, struct iattr *);
8981  extern int simple_getattr(struct vfsmount *, struct dentry *, struct kstat *);
8982  extern int simple_statfs(struct dentry *, struct kstatfs *);
8983 diff -NurpP --minimal linux-2.6.38.3/include/linux/gfs2_ondisk.h linux-2.6.38.3-vs2.3.0.37-rc14/include/linux/gfs2_ondisk.h
8984 --- linux-2.6.38.3/include/linux/gfs2_ondisk.h  2010-07-07 18:31:55.000000000 +0200
8985 +++ linux-2.6.38.3-vs2.3.0.37-rc14/include/linux/gfs2_ondisk.h  2011-01-29 02:01:07.000000000 +0100
8986 @@ -211,6 +211,9 @@ enum {
8987         gfs2fl_NoAtime          = 7,
8988         gfs2fl_Sync             = 8,
8989         gfs2fl_System           = 9,
8990 +       gfs2fl_IXUnlink         = 16,
8991 +       gfs2fl_Barrier          = 17,
8992 +       gfs2fl_Cow              = 18,
8993         gfs2fl_TruncInProg      = 29,
8994         gfs2fl_InheritDirectio  = 30,
8995         gfs2fl_InheritJdata     = 31,
8996 @@ -227,6 +230,9 @@ enum {
8997  #define GFS2_DIF_NOATIME               0x00000080
8998  #define GFS2_DIF_SYNC                  0x00000100
8999  #define GFS2_DIF_SYSTEM                        0x00000200 /* New in gfs2 */
9000 +#define GFS2_DIF_IXUNLINK              0x00010000
9001 +#define GFS2_DIF_BARRIER               0x00020000
9002 +#define GFS2_DIF_COW                   0x00040000
9003  #define GFS2_DIF_TRUNC_IN_PROG         0x20000000 /* New in gfs2 */
9004  #define GFS2_DIF_INHERIT_DIRECTIO      0x40000000
9005  #define GFS2_DIF_INHERIT_JDATA         0x80000000
9006 diff -NurpP --minimal linux-2.6.38.3/include/linux/if_tun.h linux-2.6.38.3-vs2.3.0.37-rc14/include/linux/if_tun.h
9007 --- linux-2.6.38.3/include/linux/if_tun.h       2010-08-02 16:52:54.000000000 +0200
9008 +++ linux-2.6.38.3-vs2.3.0.37-rc14/include/linux/if_tun.h       2011-01-29 02:01:07.000000000 +0100
9009 @@ -53,6 +53,7 @@
9010  #define TUNDETACHFILTER _IOW('T', 214, struct sock_fprog)
9011  #define TUNGETVNETHDRSZ _IOR('T', 215, int)
9012  #define TUNSETVNETHDRSZ _IOW('T', 216, int)
9013 +#define TUNSETNID     _IOW('T', 217, int)
9014  
9015  /* TUNSETIFF ifr flags */
9016  #define IFF_TUN                0x0001
9017 diff -NurpP --minimal linux-2.6.38.3/include/linux/init_task.h linux-2.6.38.3-vs2.3.0.37-rc14/include/linux/init_task.h
9018 --- linux-2.6.38.3/include/linux/init_task.h    2011-03-15 18:07:38.000000000 +0100
9019 +++ linux-2.6.38.3-vs2.3.0.37-rc14/include/linux/init_task.h    2011-01-29 02:01:07.000000000 +0100
9020 @@ -192,6 +192,10 @@ extern struct cred init_cred;
9021         INIT_FTRACE_GRAPH                                               \
9022         INIT_TRACE_RECURSION                                            \
9023         INIT_TASK_RCU_PREEMPT(tsk)                                      \
9024 +       .xid            = 0,                                            \
9025 +       .vx_info        = NULL,                                         \
9026 +       .nid            = 0,                                            \
9027 +       .nx_info        = NULL,                                         \
9028  }
9029  
9030  
9031 diff -NurpP --minimal linux-2.6.38.3/include/linux/ipc.h linux-2.6.38.3-vs2.3.0.37-rc14/include/linux/ipc.h
9032 --- linux-2.6.38.3/include/linux/ipc.h  2009-12-03 20:02:55.000000000 +0100
9033 +++ linux-2.6.38.3-vs2.3.0.37-rc14/include/linux/ipc.h  2011-01-29 02:01:07.000000000 +0100
9034 @@ -91,6 +91,7 @@ struct kern_ipc_perm
9035         key_t           key;
9036         uid_t           uid;
9037         gid_t           gid;
9038 +       xid_t           xid;
9039         uid_t           cuid;
9040         gid_t           cgid;
9041         mode_t          mode; 
9042 diff -NurpP --minimal linux-2.6.38.3/include/linux/loop.h linux-2.6.38.3-vs2.3.0.37-rc14/include/linux/loop.h
9043 --- linux-2.6.38.3/include/linux/loop.h 2009-09-10 15:26:25.000000000 +0200
9044 +++ linux-2.6.38.3-vs2.3.0.37-rc14/include/linux/loop.h 2011-01-29 02:01:07.000000000 +0100
9045 @@ -45,6 +45,7 @@ struct loop_device {
9046         struct loop_func_table *lo_encryption;
9047         __u32           lo_init[2];
9048         uid_t           lo_key_owner;   /* Who set the key */
9049 +       xid_t           lo_xid;
9050         int             (*ioctl)(struct loop_device *, int cmd, 
9051                                  unsigned long arg); 
9052  
9053 diff -NurpP --minimal linux-2.6.38.3/include/linux/magic.h linux-2.6.38.3-vs2.3.0.37-rc14/include/linux/magic.h
9054 --- linux-2.6.38.3/include/linux/magic.h        2011-03-15 18:07:39.000000000 +0100
9055 +++ linux-2.6.38.3-vs2.3.0.37-rc14/include/linux/magic.h        2011-01-29 02:01:07.000000000 +0100
9056 @@ -3,7 +3,7 @@
9057  
9058  #define ADFS_SUPER_MAGIC       0xadf5
9059  #define AFFS_SUPER_MAGIC       0xadff
9060 -#define AFS_SUPER_MAGIC                0x5346414F
9061 +#define AFS_SUPER_MAGIC                0x5346414F
9062  #define AUTOFS_SUPER_MAGIC     0x0187
9063  #define CODA_SUPER_MAGIC       0x73757245
9064  #define CRAMFS_MAGIC           0x28cd3d45      /* some random number */
9065 @@ -39,6 +39,7 @@
9066  #define NFS_SUPER_MAGIC                0x6969
9067  #define OPENPROM_SUPER_MAGIC   0x9fa1
9068  #define PROC_SUPER_MAGIC       0x9fa0
9069 +#define DEVPTS_SUPER_MAGIC     0x1cd1
9070  #define QNX4_SUPER_MAGIC       0x002f          /* qnx4 fs detection */
9071  
9072  #define REISERFS_SUPER_MAGIC   0x52654973      /* used by gcc */
9073 diff -NurpP --minimal linux-2.6.38.3/include/linux/major.h linux-2.6.38.3-vs2.3.0.37-rc14/include/linux/major.h
9074 --- linux-2.6.38.3/include/linux/major.h        2009-09-10 15:26:25.000000000 +0200
9075 +++ linux-2.6.38.3-vs2.3.0.37-rc14/include/linux/major.h        2011-01-29 02:01:07.000000000 +0100
9076 @@ -15,6 +15,7 @@
9077  #define HD_MAJOR               IDE0_MAJOR
9078  #define PTY_SLAVE_MAJOR                3
9079  #define TTY_MAJOR              4
9080 +#define VROOT_MAJOR            4
9081  #define TTYAUX_MAJOR           5
9082  #define LP_MAJOR               6
9083  #define VCS_MAJOR              7
9084 diff -NurpP --minimal linux-2.6.38.3/include/linux/memcontrol.h linux-2.6.38.3-vs2.3.0.37-rc14/include/linux/memcontrol.h
9085 --- linux-2.6.38.3/include/linux/memcontrol.h   2011-03-15 18:07:39.000000000 +0100
9086 +++ linux-2.6.38.3-vs2.3.0.37-rc14/include/linux/memcontrol.h   2011-01-29 02:01:07.000000000 +0100
9087 @@ -82,6 +82,13 @@ int task_in_mem_cgroup(struct task_struc
9088  extern struct mem_cgroup *try_get_mem_cgroup_from_page(struct page *page);
9089  extern struct mem_cgroup *mem_cgroup_from_task(struct task_struct *p);
9090  
9091 +extern u64 mem_cgroup_res_read_u64(struct mem_cgroup *mem, int member);
9092 +extern u64 mem_cgroup_memsw_read_u64(struct mem_cgroup *mem, int member);
9093 +
9094 +extern s64 mem_cgroup_stat_read_cache(struct mem_cgroup *mem);
9095 +extern s64 mem_cgroup_stat_read_anon(struct mem_cgroup *mem);
9096 +extern s64 mem_cgroup_stat_read_mapped(struct mem_cgroup *mem);
9097 +
9098  static inline
9099  int mm_match_cgroup(const struct mm_struct *mm, const struct mem_cgroup *cgroup)
9100  {
9101 diff -NurpP --minimal linux-2.6.38.3/include/linux/mm_types.h linux-2.6.38.3-vs2.3.0.37-rc14/include/linux/mm_types.h
9102 --- linux-2.6.38.3/include/linux/mm_types.h     2011-03-15 18:07:39.000000000 +0100
9103 +++ linux-2.6.38.3-vs2.3.0.37-rc14/include/linux/mm_types.h     2011-01-29 02:01:07.000000000 +0100
9104 @@ -269,6 +269,7 @@ struct mm_struct {
9105  
9106         /* Architecture-specific MM context */
9107         mm_context_t context;
9108 +       struct vx_info *mm_vx_info;
9109  
9110         /* Swap token stuff */
9111         /*
9112 diff -NurpP --minimal linux-2.6.38.3/include/linux/mount.h linux-2.6.38.3-vs2.3.0.37-rc14/include/linux/mount.h
9113 --- linux-2.6.38.3/include/linux/mount.h        2011-03-15 18:07:39.000000000 +0100
9114 +++ linux-2.6.38.3-vs2.3.0.37-rc14/include/linux/mount.h        2011-01-29 03:11:27.000000000 +0100
9115 @@ -52,6 +52,9 @@ struct mnt_pcp {
9116         int mnt_writers;
9117  };
9118  
9119 +#define MNT_TAGID      0x10000
9120 +#define MNT_NOTAG      0x20000
9121 +
9122  struct vfsmount {
9123         struct list_head mnt_hash;
9124         struct vfsmount *mnt_parent;    /* fs we are mounted on */
9125 @@ -86,6 +89,7 @@ struct vfsmount {
9126         int mnt_expiry_mark;            /* true if marked for expiry */
9127         int mnt_pinned;
9128         int mnt_ghosts;
9129 +       tag_t mnt_tag;                  /* tagging used for vfsmount */
9130  };
9131  
9132  struct file; /* forward dec */
9133 diff -NurpP --minimal linux-2.6.38.3/include/linux/net.h linux-2.6.38.3-vs2.3.0.37-rc14/include/linux/net.h
9134 --- linux-2.6.38.3/include/linux/net.h  2011-01-05 21:50:31.000000000 +0100
9135 +++ linux-2.6.38.3-vs2.3.0.37-rc14/include/linux/net.h  2011-01-29 02:01:07.000000000 +0100
9136 @@ -71,6 +71,7 @@ struct net;
9137  #define SOCK_NOSPACE           2
9138  #define SOCK_PASSCRED          3
9139  #define SOCK_PASSSEC           4
9140 +#define SOCK_USER_SOCKET       5
9141  
9142  #ifndef ARCH_HAS_SOCKET_TYPES
9143  /**
9144 diff -NurpP --minimal linux-2.6.38.3/include/linux/nfs_mount.h linux-2.6.38.3-vs2.3.0.37-rc14/include/linux/nfs_mount.h
9145 --- linux-2.6.38.3/include/linux/nfs_mount.h    2011-01-05 21:50:31.000000000 +0100
9146 +++ linux-2.6.38.3-vs2.3.0.37-rc14/include/linux/nfs_mount.h    2011-01-29 02:01:07.000000000 +0100
9147 @@ -63,7 +63,8 @@ struct nfs_mount_data {
9148  #define NFS_MOUNT_SECFLAVOUR   0x2000  /* 5 */
9149  #define NFS_MOUNT_NORDIRPLUS   0x4000  /* 5 */
9150  #define NFS_MOUNT_UNSHARED     0x8000  /* 5 */
9151 -#define NFS_MOUNT_FLAGMASK     0xFFFF
9152 +#define NFS_MOUNT_TAGGED       0x10000 /* context tagging */
9153 +#define NFS_MOUNT_FLAGMASK     0x1FFFF
9154  
9155  /* The following are for internal use only */
9156  #define NFS_MOUNT_LOOKUP_CACHE_NONEG   0x10000
9157 diff -NurpP --minimal linux-2.6.38.3/include/linux/nsproxy.h linux-2.6.38.3-vs2.3.0.37-rc14/include/linux/nsproxy.h
9158 --- linux-2.6.38.3/include/linux/nsproxy.h      2009-06-11 17:13:17.000000000 +0200
9159 +++ linux-2.6.38.3-vs2.3.0.37-rc14/include/linux/nsproxy.h      2011-01-29 02:01:07.000000000 +0100
9160 @@ -3,6 +3,7 @@
9161  
9162  #include <linux/spinlock.h>
9163  #include <linux/sched.h>
9164 +#include <linux/vserver/debug.h>
9165  
9166  struct mnt_namespace;
9167  struct uts_namespace;
9168 @@ -63,22 +64,33 @@ static inline struct nsproxy *task_nspro
9169  }
9170  
9171  int copy_namespaces(unsigned long flags, struct task_struct *tsk);
9172 +struct nsproxy *copy_nsproxy(struct nsproxy *orig);
9173  void exit_task_namespaces(struct task_struct *tsk);
9174  void switch_task_namespaces(struct task_struct *tsk, struct nsproxy *new);
9175  void free_nsproxy(struct nsproxy *ns);
9176  int unshare_nsproxy_namespaces(unsigned long, struct nsproxy **,
9177         struct fs_struct *);
9178  
9179 -static inline void put_nsproxy(struct nsproxy *ns)
9180 +#define        get_nsproxy(n)  __get_nsproxy(n, __FILE__, __LINE__)
9181 +
9182 +static inline void __get_nsproxy(struct nsproxy *ns,
9183 +       const char *_file, int _line)
9184  {
9185 -       if (atomic_dec_and_test(&ns->count)) {
9186 -               free_nsproxy(ns);
9187 -       }
9188 +       vxlprintk(VXD_CBIT(space, 0), "get_nsproxy(%p[%u])",
9189 +               ns, atomic_read(&ns->count), _file, _line);
9190 +       atomic_inc(&ns->count);
9191  }
9192  
9193 -static inline void get_nsproxy(struct nsproxy *ns)
9194 +#define        put_nsproxy(n)  __put_nsproxy(n, __FILE__, __LINE__)
9195 +
9196 +static inline void __put_nsproxy(struct nsproxy *ns,
9197 +       const char *_file, int _line)
9198  {
9199 -       atomic_inc(&ns->count);
9200 +       vxlprintk(VXD_CBIT(space, 0), "put_nsproxy(%p[%u])",
9201 +               ns, atomic_read(&ns->count), _file, _line);
9202 +       if (atomic_dec_and_test(&ns->count)) {
9203 +               free_nsproxy(ns);
9204 +       }
9205  }
9206  
9207  #ifdef CONFIG_CGROUP_NS
9208 diff -NurpP --minimal linux-2.6.38.3/include/linux/pid.h linux-2.6.38.3-vs2.3.0.37-rc14/include/linux/pid.h
9209 --- linux-2.6.38.3/include/linux/pid.h  2009-03-24 14:22:43.000000000 +0100
9210 +++ linux-2.6.38.3-vs2.3.0.37-rc14/include/linux/pid.h  2011-01-29 02:01:07.000000000 +0100
9211 @@ -8,7 +8,8 @@ enum pid_type
9212         PIDTYPE_PID,
9213         PIDTYPE_PGID,
9214         PIDTYPE_SID,
9215 -       PIDTYPE_MAX
9216 +       PIDTYPE_MAX,
9217 +       PIDTYPE_REALPID
9218  };
9219  
9220  /*
9221 @@ -160,6 +161,7 @@ static inline pid_t pid_nr(struct pid *p
9222  }
9223  
9224  pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns);
9225 +pid_t pid_unmapped_nr_ns(struct pid *pid, struct pid_namespace *ns);
9226  pid_t pid_vnr(struct pid *pid);
9227  
9228  #define do_each_pid_task(pid, type, task)                              \
9229 diff -NurpP --minimal linux-2.6.38.3/include/linux/proc_fs.h linux-2.6.38.3-vs2.3.0.37-rc14/include/linux/proc_fs.h
9230 --- linux-2.6.38.3/include/linux/proc_fs.h      2009-12-03 20:02:56.000000000 +0100
9231 +++ linux-2.6.38.3-vs2.3.0.37-rc14/include/linux/proc_fs.h      2011-01-29 02:01:07.000000000 +0100
9232 @@ -56,6 +56,7 @@ struct proc_dir_entry {
9233         nlink_t nlink;
9234         uid_t uid;
9235         gid_t gid;
9236 +       int vx_flags;
9237         loff_t size;
9238         const struct inode_operations *proc_iops;
9239         /*
9240 @@ -250,12 +251,18 @@ kclist_add(struct kcore_list *new, void 
9241  extern void kclist_add(struct kcore_list *, void *, size_t, int type);
9242  #endif
9243  
9244 +struct vx_info;
9245 +struct nx_info;
9246 +
9247  union proc_op {
9248         int (*proc_get_link)(struct inode *, struct path *);
9249         int (*proc_read)(struct task_struct *task, char *page);
9250         int (*proc_show)(struct seq_file *m,
9251                 struct pid_namespace *ns, struct pid *pid,
9252                 struct task_struct *task);
9253 +       int (*proc_vs_read)(char *page);
9254 +       int (*proc_vxi_read)(struct vx_info *vxi, char *page);
9255 +       int (*proc_nxi_read)(struct nx_info *nxi, char *page);
9256  };
9257  
9258  struct ctl_table_header;
9259 @@ -263,6 +270,7 @@ struct ctl_table;
9260  
9261  struct proc_inode {
9262         struct pid *pid;
9263 +       int vx_flags;
9264         int fd;
9265         union proc_op op;
9266         struct proc_dir_entry *pde;
9267 diff -NurpP --minimal linux-2.6.38.3/include/linux/quotaops.h linux-2.6.38.3-vs2.3.0.37-rc14/include/linux/quotaops.h
9268 --- linux-2.6.38.3/include/linux/quotaops.h     2011-03-15 18:07:39.000000000 +0100
9269 +++ linux-2.6.38.3-vs2.3.0.37-rc14/include/linux/quotaops.h     2011-01-29 02:01:07.000000000 +0100
9270 @@ -8,6 +8,7 @@
9271  #define _LINUX_QUOTAOPS_
9272  
9273  #include <linux/fs.h>
9274 +#include <linux/vs_dlimit.h>
9275  
9276  #define DQUOT_SPACE_WARN       0x1
9277  #define DQUOT_SPACE_RESERVE    0x2
9278 @@ -204,11 +205,12 @@ static inline void dquot_drop(struct ino
9279  
9280  static inline int dquot_alloc_inode(const struct inode *inode)
9281  {
9282 -       return 0;
9283 +       return dl_alloc_inode(inode);
9284  }
9285  
9286  static inline void dquot_free_inode(const struct inode *inode)
9287  {
9288 +       dl_free_inode(inode);
9289  }
9290  
9291  static inline int dquot_transfer(struct inode *inode, struct iattr *iattr)
9292 @@ -219,6 +221,10 @@ static inline int dquot_transfer(struct 
9293  static inline int __dquot_alloc_space(struct inode *inode, qsize_t number,
9294                 int flags)
9295  {
9296 +       int ret = 0;
9297 +
9298 +       if ((ret = dl_alloc_space(inode, number)))
9299 +               return ret;
9300         if (!(flags & DQUOT_SPACE_RESERVE))
9301                 inode_add_bytes(inode, number);
9302         return 0;
9303 @@ -229,6 +235,7 @@ static inline void __dquot_free_space(st
9304  {
9305         if (!(flags & DQUOT_SPACE_RESERVE))
9306                 inode_sub_bytes(inode, number);
9307 +       dl_free_space(inode, number);
9308  }
9309  
9310  static inline int dquot_claim_space_nodirty(struct inode *inode, qsize_t number)
9311 diff -NurpP --minimal linux-2.6.38.3/include/linux/reboot.h linux-2.6.38.3-vs2.3.0.37-rc14/include/linux/reboot.h
9312 --- linux-2.6.38.3/include/linux/reboot.h       2010-07-07 18:31:56.000000000 +0200
9313 +++ linux-2.6.38.3-vs2.3.0.37-rc14/include/linux/reboot.h       2011-01-29 02:01:07.000000000 +0100
9314 @@ -33,6 +33,7 @@
9315  #define        LINUX_REBOOT_CMD_RESTART2       0xA1B2C3D4
9316  #define        LINUX_REBOOT_CMD_SW_SUSPEND     0xD000FCE2
9317  #define        LINUX_REBOOT_CMD_KEXEC          0x45584543
9318 +#define        LINUX_REBOOT_CMD_OOM            0xDEADBEEF
9319  
9320  
9321  #ifdef __KERNEL__
9322 diff -NurpP --minimal linux-2.6.38.3/include/linux/reiserfs_fs.h linux-2.6.38.3-vs2.3.0.37-rc14/include/linux/reiserfs_fs.h
9323 --- linux-2.6.38.3/include/linux/reiserfs_fs.h  2011-01-05 21:50:32.000000000 +0100
9324 +++ linux-2.6.38.3-vs2.3.0.37-rc14/include/linux/reiserfs_fs.h  2011-01-29 02:01:07.000000000 +0100
9325 @@ -976,6 +976,11 @@ struct stat_data_v1 {
9326  #define REISERFS_COMPR_FL     FS_COMPR_FL
9327  #define REISERFS_NOTAIL_FL    FS_NOTAIL_FL
9328  
9329 +/* unfortunately reiserfs sdattr is only 16 bit */
9330 +#define REISERFS_IXUNLINK_FL  (FS_IXUNLINK_FL >> 16)
9331 +#define REISERFS_BARRIER_FL   (FS_BARRIER_FL >> 16)
9332 +#define REISERFS_COW_FL       (FS_COW_FL >> 16)
9333 +
9334  /* persistent flags that file inherits from the parent directory */
9335  #define REISERFS_INHERIT_MASK ( REISERFS_IMMUTABLE_FL |        \
9336                                 REISERFS_SYNC_FL |      \
9337 @@ -985,6 +990,9 @@ struct stat_data_v1 {
9338                                 REISERFS_COMPR_FL |     \
9339                                 REISERFS_NOTAIL_FL )
9340  
9341 +#define REISERFS_FL_USER_VISIBLE       0x80FF
9342 +#define REISERFS_FL_USER_MODIFIABLE    0x80FF
9343 +
9344  /* Stat Data on disk (reiserfs version of UFS disk inode minus the
9345     address blocks) */
9346  struct stat_data {
9347 @@ -2070,6 +2078,7 @@ static inline void reiserfs_update_sd(st
9348  void sd_attrs_to_i_attrs(__u16 sd_attrs, struct inode *inode);
9349  void i_attrs_to_sd_attrs(struct inode *inode, __u16 * sd_attrs);
9350  int reiserfs_setattr(struct dentry *dentry, struct iattr *attr);
9351 +int reiserfs_sync_flags(struct inode *inode, int, int);
9352  
9353  int __reiserfs_write_begin(struct page *page, unsigned from, unsigned len);
9354  
9355 diff -NurpP --minimal linux-2.6.38.3/include/linux/reiserfs_fs_sb.h linux-2.6.38.3-vs2.3.0.37-rc14/include/linux/reiserfs_fs_sb.h
9356 --- linux-2.6.38.3/include/linux/reiserfs_fs_sb.h       2010-02-25 11:52:07.000000000 +0100
9357 +++ linux-2.6.38.3-vs2.3.0.37-rc14/include/linux/reiserfs_fs_sb.h       2011-01-29 02:01:07.000000000 +0100
9358 @@ -476,6 +476,7 @@ enum reiserfs_mount_options {
9359         REISERFS_EXPOSE_PRIVROOT,
9360         REISERFS_BARRIER_NONE,
9361         REISERFS_BARRIER_FLUSH,
9362 +       REISERFS_TAGGED,
9363  
9364         /* Actions on error */
9365         REISERFS_ERROR_PANIC,
9366 diff -NurpP --minimal linux-2.6.38.3/include/linux/sched.h linux-2.6.38.3-vs2.3.0.37-rc14/include/linux/sched.h
9367 --- linux-2.6.38.3/include/linux/sched.h        2011-03-15 18:07:39.000000000 +0100
9368 +++ linux-2.6.38.3-vs2.3.0.37-rc14/include/linux/sched.h        2011-03-07 16:53:28.000000000 +0100
9369 @@ -1373,6 +1373,14 @@ struct task_struct {
9370  #endif
9371         seccomp_t seccomp;
9372  
9373 +/* vserver context data */
9374 +       struct vx_info *vx_info;
9375 +       struct nx_info *nx_info;
9376 +
9377 +       xid_t xid;
9378 +       nid_t nid;
9379 +       tag_t tag;
9380 +
9381  /* Thread group tracking */
9382         u32 parent_exec_id;
9383         u32 self_exec_id;
9384 @@ -1607,6 +1615,11 @@ struct pid_namespace;
9385  pid_t __task_pid_nr_ns(struct task_struct *task, enum pid_type type,
9386                         struct pid_namespace *ns);
9387  
9388 +#include <linux/vserver/base.h>
9389 +#include <linux/vserver/context.h>
9390 +#include <linux/vserver/debug.h>
9391 +#include <linux/vserver/pid.h>
9392 +
9393  static inline pid_t task_pid_nr(struct task_struct *tsk)
9394  {
9395         return tsk->pid;
9396 @@ -1620,7 +1633,8 @@ static inline pid_t task_pid_nr_ns(struc
9397  
9398  static inline pid_t task_pid_vnr(struct task_struct *tsk)
9399  {
9400 -       return __task_pid_nr_ns(tsk, PIDTYPE_PID, NULL);
9401 +       // return __task_pid_nr_ns(tsk, PIDTYPE_PID, NULL);
9402 +       return vx_map_pid(__task_pid_nr_ns(tsk, PIDTYPE_PID, NULL));
9403  }
9404  
9405  
9406 @@ -1633,7 +1647,7 @@ pid_t task_tgid_nr_ns(struct task_struct
9407  
9408  static inline pid_t task_tgid_vnr(struct task_struct *tsk)
9409  {
9410 -       return pid_vnr(task_tgid(tsk));
9411 +       return vx_map_tgid(pid_vnr(task_tgid(tsk)));
9412  }
9413  
9414  
9415 diff -NurpP --minimal linux-2.6.38.3/include/linux/shmem_fs.h linux-2.6.38.3-vs2.3.0.37-rc14/include/linux/shmem_fs.h
9416 --- linux-2.6.38.3/include/linux/shmem_fs.h     2010-10-21 13:07:55.000000000 +0200
9417 +++ linux-2.6.38.3-vs2.3.0.37-rc14/include/linux/shmem_fs.h     2011-01-29 02:01:07.000000000 +0100
9418 @@ -9,6 +9,9 @@
9419  
9420  #define SHMEM_NR_DIRECT 16
9421  
9422 +#define TMPFS_SUPER_MAGIC      0x01021994
9423 +
9424 +
9425  struct shmem_inode_info {
9426         spinlock_t              lock;
9427         unsigned long           flags;
9428 diff -NurpP --minimal linux-2.6.38.3/include/linux/stat.h linux-2.6.38.3-vs2.3.0.37-rc14/include/linux/stat.h
9429 --- linux-2.6.38.3/include/linux/stat.h 2008-12-25 00:26:37.000000000 +0100
9430 +++ linux-2.6.38.3-vs2.3.0.37-rc14/include/linux/stat.h 2011-01-29 02:01:07.000000000 +0100
9431 @@ -66,6 +66,7 @@ struct kstat {
9432         unsigned int    nlink;
9433         uid_t           uid;
9434         gid_t           gid;
9435 +       tag_t           tag;
9436         dev_t           rdev;
9437         loff_t          size;
9438         struct timespec  atime;
9439 diff -NurpP --minimal linux-2.6.38.3/include/linux/sunrpc/auth.h linux-2.6.38.3-vs2.3.0.37-rc14/include/linux/sunrpc/auth.h
9440 --- linux-2.6.38.3/include/linux/sunrpc/auth.h  2011-03-15 18:07:39.000000000 +0100
9441 +++ linux-2.6.38.3-vs2.3.0.37-rc14/include/linux/sunrpc/auth.h  2011-01-29 02:01:07.000000000 +0100
9442 @@ -25,6 +25,7 @@
9443  struct auth_cred {
9444         uid_t   uid;
9445         gid_t   gid;
9446 +       tag_t   tag;
9447         struct group_info *group_info;
9448         unsigned char machine_cred : 1;
9449  };
9450 diff -NurpP --minimal linux-2.6.38.3/include/linux/sunrpc/clnt.h linux-2.6.38.3-vs2.3.0.37-rc14/include/linux/sunrpc/clnt.h
9451 --- linux-2.6.38.3/include/linux/sunrpc/clnt.h  2011-03-15 18:07:39.000000000 +0100
9452 +++ linux-2.6.38.3-vs2.3.0.37-rc14/include/linux/sunrpc/clnt.h  2011-01-29 02:01:07.000000000 +0100
9453 @@ -49,7 +49,8 @@ struct rpc_clnt {
9454         unsigned int            cl_softrtry : 1,/* soft timeouts */
9455                                 cl_discrtry : 1,/* disconnect before retry */
9456                                 cl_autobind : 1,/* use getport() */
9457 -                               cl_chatty   : 1;/* be verbose */
9458 +                               cl_chatty   : 1,/* be verbose */
9459 +                               cl_tag      : 1;/* context tagging */
9460  
9461         struct rpc_rtt *        cl_rtt;         /* RTO estimator data */
9462         const struct rpc_timeout *cl_timeout;   /* Timeout strategy */
9463 diff -NurpP --minimal linux-2.6.38.3/include/linux/syscalls.h linux-2.6.38.3-vs2.3.0.37-rc14/include/linux/syscalls.h
9464 --- linux-2.6.38.3/include/linux/syscalls.h     2011-03-15 18:07:39.000000000 +0100
9465 +++ linux-2.6.38.3-vs2.3.0.37-rc14/include/linux/syscalls.h     2011-02-17 02:17:51.000000000 +0100
9466 @@ -478,6 +478,8 @@ asmlinkage long sys_symlink(const char _
9467  asmlinkage long sys_unlink(const char __user *pathname);
9468  asmlinkage long sys_rename(const char __user *oldname,
9469                                 const char __user *newname);
9470 +asmlinkage long sys_copyfile(const char __user *from, const char __user *to,
9471 +                               umode_t mode);
9472  asmlinkage long sys_chmod(const char __user *filename, mode_t mode);
9473  asmlinkage long sys_fchmod(unsigned int fd, mode_t mode);
9474  
9475 diff -NurpP --minimal linux-2.6.38.3/include/linux/sysctl.h linux-2.6.38.3-vs2.3.0.37-rc14/include/linux/sysctl.h
9476 --- linux-2.6.38.3/include/linux/sysctl.h       2011-03-15 18:07:40.000000000 +0100
9477 +++ linux-2.6.38.3-vs2.3.0.37-rc14/include/linux/sysctl.h       2011-03-15 18:15:06.000000000 +0100
9478 @@ -60,6 +60,7 @@ enum
9479         CTL_ABI=9,              /* Binary emulation */
9480         CTL_CPU=10,             /* CPU stuff (speed scaling, etc) */
9481         CTL_ARLAN=254,          /* arlan wireless driver */
9482 +       CTL_VSERVER=4242,       /* Linux-VServer debug */
9483         CTL_S390DBF=5677,       /* s390 debug */
9484         CTL_SUNRPC=7249,        /* sunrpc debug */
9485         CTL_PM=9899,            /* frv power management */
9486 @@ -94,6 +95,7 @@ enum
9487  
9488         KERN_PANIC=15,          /* int: panic timeout */
9489         KERN_REALROOTDEV=16,    /* real root device to mount after initrd */
9490 +       KERN_VSHELPER=17,       /* string: path to vshelper policy agent */
9491  
9492         KERN_SPARC_REBOOT=21,   /* reboot command on Sparc */
9493         KERN_CTLALTDEL=22,      /* int: allow ctl-alt-del to reboot */
9494 diff -NurpP --minimal linux-2.6.38.3/include/linux/sysfs.h linux-2.6.38.3-vs2.3.0.37-rc14/include/linux/sysfs.h
9495 --- linux-2.6.38.3/include/linux/sysfs.h        2011-01-05 21:50:34.000000000 +0100
9496 +++ linux-2.6.38.3-vs2.3.0.37-rc14/include/linux/sysfs.h        2011-01-29 02:01:07.000000000 +0100
9497 @@ -19,6 +19,8 @@
9498  #include <linux/kobject_ns.h>
9499  #include <asm/atomic.h>
9500  
9501 +#define SYSFS_SUPER_MAGIC      0x62656572
9502 +
9503  struct kobject;
9504  struct module;
9505  enum kobj_ns_type;
9506 diff -NurpP --minimal linux-2.6.38.3/include/linux/time.h linux-2.6.38.3-vs2.3.0.37-rc14/include/linux/time.h
9507 --- linux-2.6.38.3/include/linux/time.h 2011-03-15 18:07:40.000000000 +0100
9508 +++ linux-2.6.38.3-vs2.3.0.37-rc14/include/linux/time.h 2011-01-29 02:01:07.000000000 +0100
9509 @@ -254,6 +254,9 @@ static __always_inline void timespec_add
9510         a->tv_sec += __iter_div_u64_rem(a->tv_nsec + ns, NSEC_PER_SEC, &ns);
9511         a->tv_nsec = ns;
9512  }
9513 +
9514 +#include <linux/vs_time.h>
9515 +
9516  #endif /* __KERNEL__ */
9517  
9518  #define NFDBITS                        __NFDBITS
9519 diff -NurpP --minimal linux-2.6.38.3/include/linux/types.h linux-2.6.38.3-vs2.3.0.37-rc14/include/linux/types.h
9520 --- linux-2.6.38.3/include/linux/types.h        2011-01-05 21:50:34.000000000 +0100
9521 +++ linux-2.6.38.3-vs2.3.0.37-rc14/include/linux/types.h        2011-01-29 02:01:07.000000000 +0100
9522 @@ -40,6 +40,9 @@ typedef __kernel_uid32_t      uid_t;
9523  typedef __kernel_gid32_t       gid_t;
9524  typedef __kernel_uid16_t        uid16_t;
9525  typedef __kernel_gid16_t        gid16_t;
9526 +typedef unsigned int           xid_t;
9527 +typedef unsigned int           nid_t;
9528 +typedef unsigned int           tag_t;
9529  
9530  typedef unsigned long          uintptr_t;
9531  
9532 diff -NurpP --minimal linux-2.6.38.3/include/linux/vroot.h linux-2.6.38.3-vs2.3.0.37-rc14/include/linux/vroot.h
9533 --- linux-2.6.38.3/include/linux/vroot.h        1970-01-01 01:00:00.000000000 +0100
9534 +++ linux-2.6.38.3-vs2.3.0.37-rc14/include/linux/vroot.h        2011-01-29 02:01:07.000000000 +0100
9535 @@ -0,0 +1,51 @@
9536 +
9537 +/*
9538 + * include/linux/vroot.h
9539 + *
9540 + * written by Herbert Pötzl, 9/11/2002
9541 + * ported to 2.6 by Herbert Pötzl, 30/12/2004
9542 + *
9543 + * Copyright (C) 2002-2007 by Herbert Pötzl.
9544 + * Redistribution of this file is permitted under the
9545 + * GNU General Public License.
9546 + */
9547 +
9548 +#ifndef _LINUX_VROOT_H
9549 +#define _LINUX_VROOT_H
9550 +
9551 +
9552 +#ifdef __KERNEL__
9553 +
9554 +/* Possible states of device */
9555 +enum {
9556 +       Vr_unbound,
9557 +       Vr_bound,
9558 +};
9559 +
9560 +struct vroot_device {
9561 +       int             vr_number;
9562 +       int             vr_refcnt;
9563 +
9564 +       struct semaphore        vr_ctl_mutex;
9565 +       struct block_device    *vr_device;
9566 +       int                     vr_state;
9567 +};
9568 +
9569 +
9570 +typedef struct block_device *(vroot_grb_func)(struct block_device *);
9571 +
9572 +extern int register_vroot_grb(vroot_grb_func *);
9573 +extern int unregister_vroot_grb(vroot_grb_func *);
9574 +
9575 +#endif /* __KERNEL__ */
9576 +
9577 +#define MAX_VROOT_DEFAULT      8
9578 +
9579 +/*
9580 + * IOCTL commands --- we will commandeer 0x56 ('V')
9581 + */
9582 +
9583 +#define VROOT_SET_DEV          0x5600
9584 +#define VROOT_CLR_DEV          0x5601
9585 +
9586 +#endif /* _LINUX_VROOT_H */
9587 diff -NurpP --minimal linux-2.6.38.3/include/linux/vs_base.h linux-2.6.38.3-vs2.3.0.37-rc14/include/linux/vs_base.h
9588 --- linux-2.6.38.3/include/linux/vs_base.h      1970-01-01 01:00:00.000000000 +0100
9589 +++ linux-2.6.38.3-vs2.3.0.37-rc14/include/linux/vs_base.h      2011-01-29 02:01:07.000000000 +0100
9590 @@ -0,0 +1,10 @@
9591 +#ifndef _VS_BASE_H
9592 +#define _VS_BASE_H
9593 +
9594 +#include "vserver/base.h"
9595 +#include "vserver/check.h"
9596 +#include "vserver/debug.h"
9597 +
9598 +#else
9599 +#warning duplicate inclusion
9600 +#endif
9601 diff -NurpP --minimal linux-2.6.38.3/include/linux/vs_context.h linux-2.6.38.3-vs2.3.0.37-rc14/include/linux/vs_context.h
9602 --- linux-2.6.38.3/include/linux/vs_context.h   1970-01-01 01:00:00.000000000 +0100
9603 +++ linux-2.6.38.3-vs2.3.0.37-rc14/include/linux/vs_context.h   2011-01-29 02:01:07.000000000 +0100
9604 @@ -0,0 +1,242 @@
9605 +#ifndef _VS_CONTEXT_H
9606 +#define _VS_CONTEXT_H
9607 +
9608 +#include "vserver/base.h"
9609 +#include "vserver/check.h"
9610 +#include "vserver/context.h"
9611 +#include "vserver/history.h"
9612 +#include "vserver/debug.h"
9613 +
9614 +#include <linux/sched.h>
9615 +
9616 +
9617 +#define get_vx_info(i) __get_vx_info(i, __FILE__, __LINE__, __HERE__)
9618 +
9619 +static inline struct vx_info *__get_vx_info(struct vx_info *vxi,
9620 +       const char *_file, int _line, void *_here)
9621 +{
9622 +       if (!vxi)
9623 +               return NULL;
9624 +
9625 +       vxlprintk(VXD_CBIT(xid, 2), "get_vx_info(%p[#%d.%d])",
9626 +               vxi, vxi ? vxi->vx_id : 0,
9627 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
9628 +               _file, _line);
9629 +       __vxh_get_vx_info(vxi, _here);
9630 +
9631 +       atomic_inc(&vxi->vx_usecnt);
9632 +       return vxi;
9633 +}
9634 +
9635 +
9636 +extern void free_vx_info(struct vx_info *);
9637 +
9638 +#define put_vx_info(i) __put_vx_info(i, __FILE__, __LINE__, __HERE__)
9639 +
9640 +static inline void __put_vx_info(struct vx_info *vxi,
9641 +       const char *_file, int _line, void *_here)
9642 +{
9643 +       if (!vxi)
9644 +               return;
9645 +
9646 +       vxlprintk(VXD_CBIT(xid, 2), "put_vx_info(%p[#%d.%d])",
9647 +               vxi, vxi ? vxi->vx_id : 0,
9648 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
9649 +               _file, _line);
9650 +       __vxh_put_vx_info(vxi, _here);
9651 +
9652 +       if (atomic_dec_and_test(&vxi->vx_usecnt))
9653 +               free_vx_info(vxi);
9654 +}
9655 +
9656 +
9657 +#define init_vx_info(p, i) \
9658 +       __init_vx_info(p, i, __FILE__, __LINE__, __HERE__)
9659 +
9660 +static inline void __init_vx_info(struct vx_info **vxp, struct vx_info *vxi,
9661 +       const char *_file, int _line, void *_here)
9662 +{
9663 +       if (vxi) {
9664 +               vxlprintk(VXD_CBIT(xid, 3),
9665 +                       "init_vx_info(%p[#%d.%d])",
9666 +                       vxi, vxi ? vxi->vx_id : 0,
9667 +                       vxi ? atomic_read(&vxi->vx_usecnt) : 0,
9668 +                       _file, _line);
9669 +               __vxh_init_vx_info(vxi, vxp, _here);
9670 +
9671 +               atomic_inc(&vxi->vx_usecnt);
9672 +       }
9673 +       *vxp = vxi;
9674 +}
9675 +
9676 +
9677 +#define set_vx_info(p, i) \
9678 +       __set_vx_info(p, i, __FILE__, __LINE__, __HERE__)
9679 +
9680 +static inline void __set_vx_info(struct vx_info **vxp, struct vx_info *vxi,
9681 +       const char *_file, int _line, void *_here)
9682 +{
9683 +       struct vx_info *vxo;
9684 +
9685 +       if (!vxi)
9686 +               return;
9687 +
9688 +       vxlprintk(VXD_CBIT(xid, 3), "set_vx_info(%p[#%d.%d])",
9689 +               vxi, vxi ? vxi->vx_id : 0,
9690 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
9691 +               _file, _line);
9692 +       __vxh_set_vx_info(vxi, vxp, _here);
9693 +
9694 +       atomic_inc(&vxi->vx_usecnt);
9695 +       vxo = xchg(vxp, vxi);
9696 +       BUG_ON(vxo);
9697 +}
9698 +
9699 +
9700 +#define clr_vx_info(p) __clr_vx_info(p, __FILE__, __LINE__, __HERE__)
9701 +
9702 +static inline void __clr_vx_info(struct vx_info **vxp,
9703 +       const char *_file, int _line, void *_here)
9704 +{
9705 +       struct vx_info *vxo;
9706 +
9707 +       vxo = xchg(vxp, NULL);
9708 +       if (!vxo)
9709 +               return;
9710 +
9711 +       vxlprintk(VXD_CBIT(xid, 3), "clr_vx_info(%p[#%d.%d])",
9712 +               vxo, vxo ? vxo->vx_id : 0,
9713 +               vxo ? atomic_read(&vxo->vx_usecnt) : 0,
9714 +               _file, _line);
9715 +       __vxh_clr_vx_info(vxo, vxp, _here);
9716 +
9717 +       if (atomic_dec_and_test(&vxo->vx_usecnt))
9718 +               free_vx_info(vxo);
9719 +}
9720 +
9721 +
9722 +#define claim_vx_info(v, p) \
9723 +       __claim_vx_info(v, p, __FILE__, __LINE__, __HERE__)
9724 +
9725 +static inline void __claim_vx_info(struct vx_info *vxi,
9726 +       struct task_struct *task,
9727 +       const char *_file, int _line, void *_here)
9728 +{
9729 +       vxlprintk(VXD_CBIT(xid, 3), "claim_vx_info(%p[#%d.%d.%d]) %p",
9730 +               vxi, vxi ? vxi->vx_id : 0,
9731 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
9732 +               vxi ? atomic_read(&vxi->vx_tasks) : 0,
9733 +               task, _file, _line);
9734 +       __vxh_claim_vx_info(vxi, task, _here);
9735 +
9736 +       atomic_inc(&vxi->vx_tasks);
9737 +}
9738 +
9739 +
9740 +extern void unhash_vx_info(struct vx_info *);
9741 +
9742 +#define release_vx_info(v, p) \
9743 +       __release_vx_info(v, p, __FILE__, __LINE__, __HERE__)
9744 +
9745 +static inline void __release_vx_info(struct vx_info *vxi,
9746 +       struct task_struct *task,
9747 +       const char *_file, int _line, void *_here)
9748 +{
9749 +       vxlprintk(VXD_CBIT(xid, 3), "release_vx_info(%p[#%d.%d.%d]) %p",
9750 +               vxi, vxi ? vxi->vx_id : 0,
9751 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
9752 +               vxi ? atomic_read(&vxi->vx_tasks) : 0,
9753 +               task, _file, _line);
9754 +       __vxh_release_vx_info(vxi, task, _here);
9755 +
9756 +       might_sleep();
9757 +
9758 +       if (atomic_dec_and_test(&vxi->vx_tasks))
9759 +               unhash_vx_info(vxi);
9760 +}
9761 +
9762 +
9763 +#define task_get_vx_info(p) \
9764 +       __task_get_vx_info(p, __FILE__, __LINE__, __HERE__)
9765 +
9766 +static inline struct vx_info *__task_get_vx_info(struct task_struct *p,
9767 +       const char *_file, int _line, void *_here)
9768 +{
9769 +       struct vx_info *vxi;
9770 +
9771 +       task_lock(p);
9772 +       vxlprintk(VXD_CBIT(xid, 5), "task_get_vx_info(%p)",
9773 +               p, _file, _line);
9774 +       vxi = __get_vx_info(p->vx_info, _file, _line, _here);
9775 +       task_unlock(p);
9776 +       return vxi;
9777 +}
9778 +
9779 +
9780 +static inline void __wakeup_vx_info(struct vx_info *vxi)
9781 +{
9782 +       if (waitqueue_active(&vxi->vx_wait))
9783 +               wake_up_interruptible(&vxi->vx_wait);
9784 +}
9785 +
9786 +
9787 +#define enter_vx_info(v, s) __enter_vx_info(v, s, __FILE__, __LINE__)
9788 +
9789 +static inline void __enter_vx_info(struct vx_info *vxi,
9790 +       struct vx_info_save *vxis, const char *_file, int _line)
9791 +{
9792 +       vxlprintk(VXD_CBIT(xid, 5), "enter_vx_info(%p[#%d],%p) %p[#%d,%p]",
9793 +               vxi, vxi ? vxi->vx_id : 0, vxis, current,
9794 +               current->xid, current->vx_info, _file, _line);
9795 +       vxis->vxi = xchg(&current->vx_info, vxi);
9796 +       vxis->xid = current->xid;
9797 +       current->xid = vxi ? vxi->vx_id : 0;
9798 +}
9799 +
9800 +#define leave_vx_info(s) __leave_vx_info(s, __FILE__, __LINE__)
9801 +
9802 +static inline void __leave_vx_info(struct vx_info_save *vxis,
9803 +       const char *_file, int _line)
9804 +{
9805 +       vxlprintk(VXD_CBIT(xid, 5), "leave_vx_info(%p[#%d,%p]) %p[#%d,%p]",
9806 +               vxis, vxis->xid, vxis->vxi, current,
9807 +               current->xid, current->vx_info, _file, _line);
9808 +       (void)xchg(&current->vx_info, vxis->vxi);
9809 +       current->xid = vxis->xid;
9810 +}
9811 +
9812 +
9813 +static inline void __enter_vx_admin(struct vx_info_save *vxis)
9814 +{
9815 +       vxis->vxi = xchg(&current->vx_info, NULL);
9816 +       vxis->xid = xchg(&current->xid, (xid_t)0);
9817 +}
9818 +
9819 +static inline void __leave_vx_admin(struct vx_info_save *vxis)
9820 +{
9821 +       (void)xchg(&current->xid, vxis->xid);
9822 +       (void)xchg(&current->vx_info, vxis->vxi);
9823 +}
9824 +
9825 +#define task_is_init(p) \
9826 +       __task_is_init(p, __FILE__, __LINE__, __HERE__)
9827 +
9828 +static inline int __task_is_init(struct task_struct *p,
9829 +       const char *_file, int _line, void *_here)
9830 +{
9831 +       int is_init = is_global_init(p);
9832 +
9833 +       task_lock(p);
9834 +       if (p->vx_info)
9835 +               is_init = p->vx_info->vx_initpid == p->pid;
9836 +       task_unlock(p);
9837 +       return is_init;
9838 +}
9839 +
9840 +extern void exit_vx_info(struct task_struct *, int);
9841 +extern void exit_vx_info_early(struct task_struct *, int);
9842 +
9843 +
9844 +#else
9845 +#warning duplicate inclusion
9846 +#endif
9847 diff -NurpP --minimal linux-2.6.38.3/include/linux/vs_cowbl.h linux-2.6.38.3-vs2.3.0.37-rc14/include/linux/vs_cowbl.h
9848 --- linux-2.6.38.3/include/linux/vs_cowbl.h     1970-01-01 01:00:00.000000000 +0100
9849 +++ linux-2.6.38.3-vs2.3.0.37-rc14/include/linux/vs_cowbl.h     2011-01-29 02:01:07.000000000 +0100
9850 @@ -0,0 +1,48 @@
9851 +#ifndef _VS_COWBL_H
9852 +#define _VS_COWBL_H
9853 +
9854 +#include <linux/fs.h>
9855 +#include <linux/dcache.h>
9856 +#include <linux/namei.h>
9857 +#include <linux/slab.h>
9858 +
9859 +extern struct dentry *cow_break_link(const char *pathname);
9860 +
9861 +static inline int cow_check_and_break(struct path *path)
9862 +{
9863 +       struct inode *inode = path->dentry->d_inode;
9864 +       int error = 0;
9865 +
9866 +       /* do we need this check? */
9867 +       if (IS_RDONLY(inode))
9868 +               return -EROFS;
9869 +
9870 +       if (IS_COW(inode)) {
9871 +               if (IS_COW_LINK(inode)) {
9872 +                       struct dentry *new_dentry, *old_dentry = path->dentry;
9873 +                       char *pp, *buf;
9874 +
9875 +                       buf = kmalloc(PATH_MAX, GFP_KERNEL);
9876 +                       if (!buf) {
9877 +                               return -ENOMEM;
9878 +                       }
9879 +                       pp = d_path(path, buf, PATH_MAX);
9880 +                       new_dentry = cow_break_link(pp);
9881 +                       kfree(buf);
9882 +                       if (!IS_ERR(new_dentry)) {
9883 +                               path->dentry = new_dentry;
9884 +                               dput(old_dentry);
9885 +                       } else
9886 +                               error = PTR_ERR(new_dentry);
9887 +               } else {
9888 +                       inode->i_flags &= ~(S_IXUNLINK | S_IMMUTABLE);
9889 +                       inode->i_ctime = CURRENT_TIME;
9890 +                       mark_inode_dirty(inode);
9891 +               }
9892 +       }
9893 +       return error;
9894 +}
9895 +
9896 +#else
9897 +#warning duplicate inclusion
9898 +#endif
9899 diff -NurpP --minimal linux-2.6.38.3/include/linux/vs_cvirt.h linux-2.6.38.3-vs2.3.0.37-rc14/include/linux/vs_cvirt.h
9900 --- linux-2.6.38.3/include/linux/vs_cvirt.h     1970-01-01 01:00:00.000000000 +0100
9901 +++ linux-2.6.38.3-vs2.3.0.37-rc14/include/linux/vs_cvirt.h     2011-01-29 02:01:07.000000000 +0100
9902 @@ -0,0 +1,50 @@
9903 +#ifndef _VS_CVIRT_H
9904 +#define _VS_CVIRT_H
9905 +
9906 +#include "vserver/cvirt.h"
9907 +#include "vserver/context.h"
9908 +#include "vserver/base.h"
9909 +#include "vserver/check.h"
9910 +#include "vserver/debug.h"
9911 +
9912 +
9913 +static inline void vx_activate_task(struct task_struct *p)
9914 +{
9915 +       struct vx_info *vxi;
9916 +
9917 +       if ((vxi = p->vx_info)) {
9918 +               vx_update_load(vxi);
9919 +               atomic_inc(&vxi->cvirt.nr_running);
9920 +       }
9921 +}
9922 +
9923 +static inline void vx_deactivate_task(struct task_struct *p)
9924 +{
9925 +       struct vx_info *vxi;
9926 +
9927 +       if ((vxi = p->vx_info)) {
9928 +               vx_update_load(vxi);
9929 +               atomic_dec(&vxi->cvirt.nr_running);
9930 +       }
9931 +}
9932 +
9933 +static inline void vx_uninterruptible_inc(struct task_struct *p)
9934 +{
9935 +       struct vx_info *vxi;
9936 +
9937 +       if ((vxi = p->vx_info))
9938 +               atomic_inc(&vxi->cvirt.nr_uninterruptible);
9939 +}
9940 +
9941 +static inline void vx_uninterruptible_dec(struct task_struct *p)
9942 +{
9943 +       struct vx_info *vxi;
9944 +
9945 +       if ((vxi = p->vx_info))
9946 +               atomic_dec(&vxi->cvirt.nr_uninterruptible);
9947 +}
9948 +
9949 +
9950 +#else
9951 +#warning duplicate inclusion
9952 +#endif
9953 diff -NurpP --minimal linux-2.6.38.3/include/linux/vs_device.h linux-2.6.38.3-vs2.3.0.37-rc14/include/linux/vs_device.h
9954 --- linux-2.6.38.3/include/linux/vs_device.h    1970-01-01 01:00:00.000000000 +0100
9955 +++ linux-2.6.38.3-vs2.3.0.37-rc14/include/linux/vs_device.h    2011-01-29 02:01:07.000000000 +0100
9956 @@ -0,0 +1,45 @@
9957 +#ifndef _VS_DEVICE_H
9958 +#define _VS_DEVICE_H
9959 +
9960 +#include "vserver/base.h"
9961 +#include "vserver/device.h"
9962 +#include "vserver/debug.h"
9963 +
9964 +
9965 +#ifdef CONFIG_VSERVER_DEVICE
9966 +
9967 +int vs_map_device(struct vx_info *, dev_t, dev_t *, umode_t);
9968 +
9969 +#define vs_device_perm(v, d, m, p) \
9970 +       ((vs_map_device(current_vx_info(), d, NULL, m) & (p)) == (p))
9971 +
9972 +#else
9973 +
9974 +static inline
9975 +int vs_map_device(struct vx_info *vxi,
9976 +       dev_t device, dev_t *target, umode_t mode)
9977 +{
9978 +       if (target)
9979 +               *target = device;
9980 +       return ~0;
9981 +}
9982 +
9983 +#define vs_device_perm(v, d, m, p) ((p) == (p))
9984 +
9985 +#endif
9986 +
9987 +
9988 +#define vs_map_chrdev(d, t, p) \
9989 +       ((vs_map_device(current_vx_info(), d, t, S_IFCHR) & (p)) == (p))
9990 +#define vs_map_blkdev(d, t, p) \
9991 +       ((vs_map_device(current_vx_info(), d, t, S_IFBLK) & (p)) == (p))
9992 +
9993 +#define vs_chrdev_perm(d, p) \
9994 +       vs_device_perm(current_vx_info(), d, S_IFCHR, p)
9995 +#define vs_blkdev_perm(d, p) \
9996 +       vs_device_perm(current_vx_info(), d, S_IFBLK, p)
9997 +
9998 +
9999 +#else
10000 +#warning duplicate inclusion
10001 +#endif
10002 diff -NurpP --minimal linux-2.6.38.3/include/linux/vs_dlimit.h linux-2.6.38.3-vs2.3.0.37-rc14/include/linux/vs_dlimit.h
10003 --- linux-2.6.38.3/include/linux/vs_dlimit.h    1970-01-01 01:00:00.000000000 +0100
10004 +++ linux-2.6.38.3-vs2.3.0.37-rc14/include/linux/vs_dlimit.h    2011-01-29 02:01:07.000000000 +0100
10005 @@ -0,0 +1,215 @@
10006 +#ifndef _VS_DLIMIT_H
10007 +#define _VS_DLIMIT_H
10008 +
10009 +#include <linux/fs.h>
10010 +
10011 +#include "vserver/dlimit.h"
10012 +#include "vserver/base.h"
10013 +#include "vserver/debug.h"
10014 +
10015 +
10016 +#define get_dl_info(i) __get_dl_info(i, __FILE__, __LINE__)
10017 +
10018 +static inline struct dl_info *__get_dl_info(struct dl_info *dli,
10019 +       const char *_file, int _line)
10020 +{
10021 +       if (!dli)
10022 +               return NULL;
10023 +       vxlprintk(VXD_CBIT(dlim, 4), "get_dl_info(%p[#%d.%d])",
10024 +               dli, dli ? dli->dl_tag : 0,
10025 +               dli ? atomic_read(&dli->dl_usecnt) : 0,
10026 +               _file, _line);
10027 +       atomic_inc(&dli->dl_usecnt);
10028 +       return dli;
10029 +}
10030 +
10031 +
10032 +#define free_dl_info(i) \
10033 +       call_rcu(&(i)->dl_rcu, rcu_free_dl_info)
10034 +
10035 +#define put_dl_info(i) __put_dl_info(i, __FILE__, __LINE__)
10036 +
10037 +static inline void __put_dl_info(struct dl_info *dli,
10038 +       const char *_file, int _line)
10039 +{
10040 +       if (!dli)
10041 +               return;
10042 +       vxlprintk(VXD_CBIT(dlim, 4), "put_dl_info(%p[#%d.%d])",
10043 +               dli, dli ? dli->dl_tag : 0,
10044 +               dli ? atomic_read(&dli->dl_usecnt) : 0,
10045 +               _file, _line);
10046 +       if (atomic_dec_and_test(&dli->dl_usecnt))
10047 +               free_dl_info(dli);
10048 +}
10049 +
10050 +
10051 +#define __dlimit_char(d)       ((d) ? '*' : ' ')
10052 +
10053 +static inline int __dl_alloc_space(struct super_block *sb,
10054 +       tag_t tag, dlsize_t nr, const char *file, int line)
10055 +{
10056 +       struct dl_info *dli = NULL;
10057 +       int ret = 0;
10058 +
10059 +       if (nr == 0)
10060 +               goto out;
10061 +       dli = locate_dl_info(sb, tag);
10062 +       if (!dli)
10063 +               goto out;
10064 +
10065 +       spin_lock(&dli->dl_lock);
10066 +       ret = (dli->dl_space_used + nr > dli->dl_space_total);
10067 +       if (!ret)
10068 +               dli->dl_space_used += nr;
10069 +       spin_unlock(&dli->dl_lock);
10070 +       put_dl_info(dli);
10071 +out:
10072 +       vxlprintk(VXD_CBIT(dlim, 1),
10073 +               "ALLOC (%p,#%d)%c %lld bytes (%d)",
10074 +               sb, tag, __dlimit_char(dli), (long long)nr,
10075 +               ret, file, line);
10076 +       return ret ? -ENOSPC : 0;
10077 +}
10078 +
10079 +static inline void __dl_free_space(struct super_block *sb,
10080 +       tag_t tag, dlsize_t nr, const char *_file, int _line)
10081 +{
10082 +       struct dl_info *dli = NULL;
10083 +
10084 +       if (nr == 0)
10085 +               goto out;
10086 +       dli = locate_dl_info(sb, tag);
10087 +       if (!dli)
10088 +               goto out;
10089 +
10090 +       spin_lock(&dli->dl_lock);
10091 +       if (dli->dl_space_used > nr)
10092 +               dli->dl_space_used -= nr;
10093 +       else
10094 +               dli->dl_space_used = 0;
10095 +       spin_unlock(&dli->dl_lock);
10096 +       put_dl_info(dli);
10097 +out:
10098 +       vxlprintk(VXD_CBIT(dlim, 1),
10099 +               "FREE  (%p,#%d)%c %lld bytes",
10100 +               sb, tag, __dlimit_char(dli), (long long)nr,
10101 +               _file, _line);
10102 +}
10103 +
10104 +static inline int __dl_alloc_inode(struct super_block *sb,
10105 +       tag_t tag, const char *_file, int _line)
10106 +{
10107 +       struct dl_info *dli;
10108 +       int ret = 0;
10109 +
10110 +       dli = locate_dl_info(sb, tag);
10111 +       if (!dli)
10112 +               goto out;
10113 +
10114 +       spin_lock(&dli->dl_lock);
10115 +       dli->dl_inodes_used++;
10116 +       ret = (dli->dl_inodes_used > dli->dl_inodes_total);
10117 +       spin_unlock(&dli->dl_lock);
10118 +       put_dl_info(dli);
10119 +out:
10120 +       vxlprintk(VXD_CBIT(dlim, 0),
10121 +               "ALLOC (%p,#%d)%c inode (%d)",
10122 +               sb, tag, __dlimit_char(dli), ret, _file, _line);
10123 +       return ret ? -ENOSPC : 0;
10124 +}
10125 +
10126 +static inline void __dl_free_inode(struct super_block *sb,
10127 +       tag_t tag, const char *_file, int _line)
10128 +{
10129 +       struct dl_info *dli;
10130 +
10131 +       dli = locate_dl_info(sb, tag);
10132 +       if (!dli)
10133 +               goto out;
10134 +
10135 +       spin_lock(&dli->dl_lock);
10136 +       if (dli->dl_inodes_used > 1)
10137 +               dli->dl_inodes_used--;
10138 +       else
10139 +               dli->dl_inodes_used = 0;
10140 +       spin_unlock(&dli->dl_lock);
10141 +       put_dl_info(dli);
10142 +out:
10143 +       vxlprintk(VXD_CBIT(dlim, 0),
10144 +               "FREE  (%p,#%d)%c inode",
10145 +               sb, tag, __dlimit_char(dli), _file, _line);
10146 +}
10147 +
10148 +static inline void __dl_adjust_block(struct super_block *sb, tag_t tag,
10149 +       unsigned long long *free_blocks, unsigned long long *root_blocks,
10150 +       const char *_file, int _line)
10151 +{
10152 +       struct dl_info *dli;
10153 +       uint64_t broot, bfree;
10154 +
10155 +       dli = locate_dl_info(sb, tag);
10156 +       if (!dli)
10157 +               return;
10158 +
10159 +       spin_lock(&dli->dl_lock);
10160 +       broot = (dli->dl_space_total -
10161 +               (dli->dl_space_total >> 10) * dli->dl_nrlmult)
10162 +               >> sb->s_blocksize_bits;
10163 +       bfree = (dli->dl_space_total - dli->dl_space_used)
10164 +                       >> sb->s_blocksize_bits;
10165 +       spin_unlock(&dli->dl_lock);
10166 +
10167 +       vxlprintk(VXD_CBIT(dlim, 2),
10168 +               "ADJUST: %lld,%lld on %lld,%lld [mult=%d]",
10169 +               (long long)bfree, (long long)broot,
10170 +               *free_blocks, *root_blocks, dli->dl_nrlmult,
10171 +               _file, _line);
10172 +       if (free_blocks) {
10173 +               if (*free_blocks > bfree)
10174 +                       *free_blocks = bfree;
10175 +       }
10176 +       if (root_blocks) {
10177 +               if (*root_blocks > broot)
10178 +                       *root_blocks = broot;
10179 +       }
10180 +       put_dl_info(dli);
10181 +}
10182 +
10183 +#define dl_prealloc_space(in, bytes) \
10184 +       __dl_alloc_space((in)->i_sb, (in)->i_tag, (dlsize_t)(bytes), \
10185 +               __FILE__, __LINE__ )
10186 +
10187 +#define dl_alloc_space(in, bytes) \
10188 +       __dl_alloc_space((in)->i_sb, (in)->i_tag, (dlsize_t)(bytes), \
10189 +               __FILE__, __LINE__ )
10190 +
10191 +#define dl_reserve_space(in, bytes) \
10192 +       __dl_alloc_space((in)->i_sb, (in)->i_tag, (dlsize_t)(bytes), \
10193 +               __FILE__, __LINE__ )
10194 +
10195 +#define dl_claim_space(in, bytes) (0)
10196 +
10197 +#define dl_release_space(in, bytes) \
10198 +       __dl_free_space((in)->i_sb, (in)->i_tag, (dlsize_t)(bytes), \
10199 +               __FILE__, __LINE__ )
10200 +
10201 +#define dl_free_space(in, bytes) \
10202 +       __dl_free_space((in)->i_sb, (in)->i_tag, (dlsize_t)(bytes), \
10203 +               __FILE__, __LINE__ )
10204 +
10205 +
10206 +
10207 +#define dl_alloc_inode(in) \
10208 +       __dl_alloc_inode((in)->i_sb, (in)->i_tag, __FILE__, __LINE__ )
10209 +
10210 +#define dl_free_inode(in) \
10211 +       __dl_free_inode((in)->i_sb, (in)->i_tag, __FILE__, __LINE__ )
10212 +
10213 +
10214 +#define dl_adjust_block(sb, tag, fb, rb) \
10215 +       __dl_adjust_block(sb, tag, fb, rb, __FILE__, __LINE__ )
10216 +
10217 +
10218 +#else
10219 +#warning duplicate inclusion
10220 +#endif
10221 diff -NurpP --minimal linux-2.6.38.3/include/linux/vs_inet.h linux-2.6.38.3-vs2.3.0.37-rc14/include/linux/vs_inet.h
10222 --- linux-2.6.38.3/include/linux/vs_inet.h      1970-01-01 01:00:00.000000000 +0100
10223 +++ linux-2.6.38.3-vs2.3.0.37-rc14/include/linux/vs_inet.h      2011-01-29 04:45:50.000000000 +0100
10224 @@ -0,0 +1,351 @@
10225 +#ifndef _VS_INET_H
10226 +#define _VS_INET_H
10227 +
10228 +#include "vserver/base.h"
10229 +#include "vserver/network.h"
10230 +#include "vserver/debug.h"
10231 +
10232 +#define IPI_LOOPBACK   htonl(INADDR_LOOPBACK)
10233 +
10234 +#define NXAV4(a)       NIPQUAD((a)->ip[0]), NIPQUAD((a)->ip[1]), \
10235 +                       NIPQUAD((a)->mask), (a)->type
10236 +#define NXAV4_FMT      "[" NIPQUAD_FMT "-" NIPQUAD_FMT "/" NIPQUAD_FMT ":%04x]"
10237 +
10238 +#define NIPQUAD(addr) \
10239 +       ((unsigned char *)&addr)[0], \
10240 +       ((unsigned char *)&addr)[1], \
10241 +       ((unsigned char *)&addr)[2], \
10242 +       ((unsigned char *)&addr)[3]
10243 +
10244 +#define NIPQUAD_FMT "%u.%u.%u.%u"
10245 +
10246 +
10247 +static inline
10248 +int v4_addr_match(struct nx_addr_v4 *nxa, __be32 addr, uint16_t tmask)
10249 +{
10250 +       __be32 ip = nxa->ip[0].s_addr;
10251 +       __be32 mask = nxa->mask.s_addr;
10252 +       __be32 bcast = ip | ~mask;
10253 +       int ret = 0;
10254 +
10255 +       switch (nxa->type & tmask) {
10256 +       case NXA_TYPE_MASK:
10257 +               ret = (ip == (addr & mask));
10258 +               break;
10259 +       case NXA_TYPE_ADDR:
10260 +               ret = 3;
10261 +               if (addr == ip)
10262 +                       break;
10263 +               /* fall through to broadcast */
10264 +       case NXA_MOD_BCAST:
10265 +               ret = ((tmask & NXA_MOD_BCAST) && (addr == bcast));
10266 +               break;
10267 +       case NXA_TYPE_RANGE:
10268 +               ret = ((nxa->ip[0].s_addr <= addr) &&
10269 +                       (nxa->ip[1].s_addr > addr));
10270 +               break;
10271 +       case NXA_TYPE_ANY:
10272 +               ret = 2;
10273 +               break;
10274 +       }
10275 +
10276 +       vxdprintk(VXD_CBIT(net, 0),
10277 +               "v4_addr_match(%p" NXAV4_FMT "," NIPQUAD_FMT ",%04x) = %d",
10278 +               nxa, NXAV4(nxa), NIPQUAD(addr), tmask, ret);
10279 +       return ret;
10280 +}
10281 +
10282 +static inline
10283 +int v4_addr_in_nx_info(struct nx_info *nxi, __be32 addr, uint16_t tmask)
10284 +{
10285 +       struct nx_addr_v4 *nxa;
10286 +       int ret = 1;
10287 +
10288 +       if (!nxi)
10289 +               goto out;
10290 +
10291 +       ret = 2;
10292 +       /* allow 127.0.0.1 when remapping lback */
10293 +       if ((tmask & NXA_LOOPBACK) &&
10294 +               (addr == IPI_LOOPBACK) &&
10295 +               nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
10296 +               goto out;
10297 +       ret = 3;
10298 +       /* check for lback address */
10299 +       if ((tmask & NXA_MOD_LBACK) &&
10300 +               (nxi->v4_lback.s_addr == addr))
10301 +               goto out;
10302 +       ret = 4;
10303 +       /* check for broadcast address */
10304 +       if ((tmask & NXA_MOD_BCAST) &&
10305 +               (nxi->v4_bcast.s_addr == addr))
10306 +               goto out;
10307 +       ret = 5;
10308 +       /* check for v4 addresses */
10309 +       for (nxa = &nxi->v4; nxa; nxa = nxa->next)
10310 +               if (v4_addr_match(nxa, addr, tmask))
10311 +                       goto out;
10312 +       ret = 0;
10313 +out:
10314 +       vxdprintk(VXD_CBIT(net, 0),
10315 +               "v4_addr_in_nx_info(%p[#%u]," NIPQUAD_FMT ",%04x) = %d",
10316 +               nxi, nxi ? nxi->nx_id : 0, NIPQUAD(addr), tmask, ret);
10317 +       return ret;
10318 +}
10319 +
10320 +static inline
10321 +int v4_nx_addr_match(struct nx_addr_v4 *nxa, struct nx_addr_v4 *addr, uint16_t mask)
10322 +{
10323 +       /* FIXME: needs full range checks */
10324 +       return v4_addr_match(nxa, addr->ip[0].s_addr, mask);
10325 +}
10326 +
10327 +static inline
10328 +int v4_nx_addr_in_nx_info(struct nx_info *nxi, struct nx_addr_v4 *nxa, uint16_t mask)
10329 +{
10330 +       struct nx_addr_v4 *ptr;
10331 +
10332 +       for (ptr = &nxi->v4; ptr; ptr = ptr->next)
10333 +               if (v4_nx_addr_match(ptr, nxa, mask))
10334 +                       return 1;
10335 +       return 0;
10336 +}
10337 +
10338 +#include <net/inet_sock.h>
10339 +
10340 +/*
10341 + *     Check if a given address matches for a socket
10342 + *
10343 + *     nxi:            the socket's nx_info if any
10344 + *     addr:           to be verified address
10345 + */
10346 +static inline
10347 +int v4_sock_addr_match (
10348 +       struct nx_info *nxi,
10349 +       struct inet_sock *inet,
10350 +       __be32 addr)
10351 +{
10352 +       __be32 saddr = inet->inet_rcv_saddr;
10353 +       __be32 bcast = nxi ? nxi->v4_bcast.s_addr : INADDR_BROADCAST;
10354 +
10355 +       if (addr && (saddr == addr || bcast == addr))
10356 +               return 1;
10357 +       if (!saddr)
10358 +               return v4_addr_in_nx_info(nxi, addr, NXA_MASK_BIND);
10359 +       return 0;
10360 +}
10361 +
10362 +
10363 +/* inet related checks and helpers */
10364 +
10365 +
10366 +struct in_ifaddr;
10367 +struct net_device;
10368 +struct sock;
10369 +
10370 +#ifdef CONFIG_INET
10371 +
10372 +#include <linux/netdevice.h>
10373 +#include <linux/inetdevice.h>
10374 +#include <net/inet_sock.h>
10375 +#include <net/inet_timewait_sock.h>
10376 +
10377 +
10378 +int dev_in_nx_info(struct net_device *, struct nx_info *);
10379 +int v4_dev_in_nx_info(struct net_device *, struct nx_info *);
10380 +int nx_v4_addr_conflict(struct nx_info *, struct nx_info *);
10381 +
10382 +
10383 +/*
10384 + *     check if address is covered by socket
10385 + *
10386 + *     sk:     the socket to check against
10387 + *     addr:   the address in question (must be != 0)
10388 + */
10389 +
10390 +static inline
10391 +int __v4_addr_match_socket(const struct sock *sk, struct nx_addr_v4 *nxa)
10392 +{
10393 +       struct nx_info *nxi = sk->sk_nx_info;
10394 +       __be32 saddr = sk_rcv_saddr(sk);
10395 +
10396 +       vxdprintk(VXD_CBIT(net, 5),
10397 +               "__v4_addr_in_socket(%p," NXAV4_FMT ") %p:" NIPQUAD_FMT " %p;%lx",
10398 +               sk, NXAV4(nxa), nxi, NIPQUAD(saddr), sk->sk_socket,
10399 +               (sk->sk_socket?sk->sk_socket->flags:0));
10400 +
10401 +       if (saddr) {            /* direct address match */
10402 +               return v4_addr_match(nxa, saddr, -1);
10403 +       } else if (nxi) {       /* match against nx_info */
10404 +               return v4_nx_addr_in_nx_info(nxi, nxa, -1);
10405 +       } else {                /* unrestricted any socket */
10406 +               return 1;
10407 +       }
10408 +}
10409 +
10410 +
10411 +
10412 +static inline
10413 +int nx_dev_visible(struct nx_info *nxi, struct net_device *dev)
10414 +{
10415 +       vxdprintk(VXD_CBIT(net, 1),
10416 +               "nx_dev_visible(%p[#%u],%p " VS_Q("%s") ") %d",
10417 +               nxi, nxi ? nxi->nx_id : 0, dev, dev->name,
10418 +               nxi ? dev_in_nx_info(dev, nxi) : 0);
10419 +
10420 +       if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
10421 +               return 1;
10422 +       if (dev_in_nx_info(dev, nxi))
10423 +               return 1;
10424 +       return 0;
10425 +}
10426 +
10427 +
10428 +static inline
10429 +int v4_ifa_in_nx_info(struct in_ifaddr *ifa, struct nx_info *nxi)
10430 +{
10431 +       if (!nxi)
10432 +               return 1;
10433 +       if (!ifa)
10434 +               return 0;
10435 +       return v4_addr_in_nx_info(nxi, ifa->ifa_local, NXA_MASK_SHOW);
10436 +}
10437 +
10438 +static inline
10439 +int nx_v4_ifa_visible(struct nx_info *nxi, struct in_ifaddr *ifa)
10440 +{
10441 +       vxdprintk(VXD_CBIT(net, 1), "nx_v4_ifa_visible(%p[#%u],%p) %d",
10442 +               nxi, nxi ? nxi->nx_id : 0, ifa,
10443 +               nxi ? v4_ifa_in_nx_info(ifa, nxi) : 0);
10444 +
10445 +       if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
10446 +               return 1;
10447 +       if (v4_ifa_in_nx_info(ifa, nxi))
10448 +               return 1;
10449 +       return 0;
10450 +}
10451 +
10452 +
10453 +struct nx_v4_sock_addr {
10454 +       __be32 saddr;   /* Address used for validation */
10455 +       __be32 baddr;   /* Address used for socket bind */
10456 +};
10457 +
10458 +static inline
10459 +int v4_map_sock_addr(struct inet_sock *inet, struct sockaddr_in *addr,
10460 +       struct nx_v4_sock_addr *nsa)
10461 +{
10462 +       struct sock *sk = &inet->sk;
10463 +       struct nx_info *nxi = sk->sk_nx_info;
10464 +       __be32 saddr = addr->sin_addr.s_addr;
10465 +       __be32 baddr = saddr;
10466 +
10467 +       vxdprintk(VXD_CBIT(net, 3),
10468 +               "inet_bind(%p)* %p,%p;%lx " NIPQUAD_FMT,
10469 +               sk, sk->sk_nx_info, sk->sk_socket,
10470 +               (sk->sk_socket ? sk->sk_socket->flags : 0),
10471 +               NIPQUAD(saddr));
10472 +
10473 +       if (nxi) {
10474 +               if (saddr == INADDR_ANY) {
10475 +                       if (nx_info_flags(nxi, NXF_SINGLE_IP, 0))
10476 +                               baddr = nxi->v4.ip[0].s_addr;
10477 +               } else if (saddr == IPI_LOOPBACK) {
10478 +                       if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
10479 +                               baddr = nxi->v4_lback.s_addr;
10480 +               } else {        /* normal address bind */
10481 +                       if (!v4_addr_in_nx_info(nxi, saddr, NXA_MASK_BIND))
10482 +                               return -EADDRNOTAVAIL;
10483 +               }
10484 +       }
10485 +
10486 +       vxdprintk(VXD_CBIT(net, 3),
10487 +               "inet_bind(%p) " NIPQUAD_FMT ", " NIPQUAD_FMT,
10488 +               sk, NIPQUAD(saddr), NIPQUAD(baddr));
10489 +
10490 +       nsa->saddr = saddr;
10491 +       nsa->baddr = baddr;
10492 +       return 0;
10493 +}
10494 +
10495 +static inline
10496 +void v4_set_sock_addr(struct inet_sock *inet, struct nx_v4_sock_addr *nsa)
10497 +{
10498 +       inet->inet_saddr = nsa->baddr;
10499 +       inet->inet_rcv_saddr = nsa->baddr;
10500 +}
10501 +
10502 +
10503 +/*
10504 + *      helper to simplify inet_lookup_listener
10505 + *
10506 + *      nxi:   the socket's nx_info if any
10507 + *      addr:  to be verified address
10508 + *      saddr: socket address
10509 + */
10510 +static inline int v4_inet_addr_match (
10511 +       struct nx_info *nxi,
10512 +       __be32 addr,
10513 +       __be32 saddr)
10514 +{
10515 +       if (addr && (saddr == addr))
10516 +               return 1;
10517 +       if (!saddr)
10518 +               return nxi ? v4_addr_in_nx_info(nxi, addr, NXA_MASK_BIND) : 1;
10519 +       return 0;
10520 +}
10521 +
10522 +static inline __be32 nx_map_sock_lback(struct nx_info *nxi, __be32 addr)
10523 +{
10524 +       if (nx_info_flags(nxi, NXF_HIDE_LBACK, 0) &&
10525 +               (addr == nxi->v4_lback.s_addr))
10526 +               return IPI_LOOPBACK;
10527 +       return addr;
10528 +}
10529 +
10530 +static inline
10531 +int nx_info_has_v4(struct nx_info *nxi)
10532 +{
10533 +       if (!nxi)
10534 +               return 1;
10535 +       if (NX_IPV4(nxi))
10536 +               return 1;
10537 +       if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
10538 +               return 1;
10539 +       return 0;
10540 +}
10541 +
10542 +#else /* CONFIG_INET */
10543 +
10544 +static inline
10545 +int nx_dev_visible(struct nx_info *n, struct net_device *d)
10546 +{
10547 +       return 1;
10548 +}
10549 +
10550 +static inline
10551 +int nx_v4_addr_conflict(struct nx_info *n, uint32_t a, const struct sock *s)
10552 +{
10553 +       return 1;
10554 +}
10555 +
10556 +static inline
10557 +int v4_ifa_in_nx_info(struct in_ifaddr *a, struct nx_info *n)
10558 +{
10559 +       return 1;
10560 +}
10561 +
10562 +static inline
10563 +int nx_info_has_v4(struct nx_info *nxi)
10564 +{
10565 +       return 0;
10566 +}
10567 +
10568 +#endif /* CONFIG_INET */
10569 +
10570 +#define current_nx_info_has_v4() \
10571 +       nx_info_has_v4(current_nx_info())
10572 +
10573 +#else
10574 +// #warning duplicate inclusion
10575 +#endif
10576 diff -NurpP --minimal linux-2.6.38.3/include/linux/vs_inet6.h linux-2.6.38.3-vs2.3.0.37-rc14/include/linux/vs_inet6.h
10577 --- linux-2.6.38.3/include/linux/vs_inet6.h     1970-01-01 01:00:00.000000000 +0100
10578 +++ linux-2.6.38.3-vs2.3.0.37-rc14/include/linux/vs_inet6.h     2011-01-29 02:01:07.000000000 +0100
10579 @@ -0,0 +1,246 @@
10580 +#ifndef _VS_INET6_H
10581 +#define _VS_INET6_H
10582 +
10583 +#include "vserver/base.h"
10584 +#include "vserver/network.h"
10585 +#include "vserver/debug.h"
10586 +
10587 +#include <net/ipv6.h>
10588 +
10589 +#define NXAV6(a)       &(a)->ip, &(a)->mask, (a)->prefix, (a)->type
10590 +#define NXAV6_FMT      "[%pI6/%pI6/%d:%04x]"
10591 +
10592 +
10593 +#ifdef CONFIG_IPV6
10594 +
10595 +static inline
10596 +int v6_addr_match(struct nx_addr_v6 *nxa,
10597 +       const struct in6_addr *addr, uint16_t mask)
10598 +{
10599 +       int ret = 0;
10600 +
10601 +       switch (nxa->type & mask) {
10602 +       case NXA_TYPE_MASK:
10603 +               ret = ipv6_masked_addr_cmp(&nxa->ip, &nxa->mask, addr);
10604 +               break;
10605 +       case NXA_TYPE_ADDR:
10606 +               ret = ipv6_addr_equal(&nxa->ip, addr);
10607 +               break;
10608 +       case NXA_TYPE_ANY:
10609 +               ret = 1;
10610 +               break;
10611 +       }
10612 +       vxdprintk(VXD_CBIT(net, 0),
10613 +               "v6_addr_match(%p" NXAV6_FMT ",%pI6,%04x) = %d",
10614 +               nxa, NXAV6(nxa), addr, mask, ret);
10615 +       return ret;
10616 +}
10617 +
10618 +static inline
10619 +int v6_addr_in_nx_info(struct nx_info *nxi,
10620 +       const struct in6_addr *addr, uint16_t mask)
10621 +{
10622 +       struct nx_addr_v6 *nxa;
10623 +       int ret = 1;
10624 +
10625 +       if (!nxi)
10626 +               goto out;
10627 +       for (nxa = &nxi->v6; nxa; nxa = nxa->next)
10628 +               if (v6_addr_match(nxa, addr, mask))
10629 +                       goto out;
10630 +       ret = 0;
10631 +out:
10632 +       vxdprintk(VXD_CBIT(net, 0),
10633 +               "v6_addr_in_nx_info(%p[#%u],%pI6,%04x) = %d",
10634 +               nxi, nxi ? nxi->nx_id : 0, addr, mask, ret);
10635 +       return ret;
10636 +}
10637 +
10638 +static inline
10639 +int v6_nx_addr_match(struct nx_addr_v6 *nxa, struct nx_addr_v6 *addr, uint16_t mask)
10640 +{
10641 +       /* FIXME: needs full range checks */
10642 +       return v6_addr_match(nxa, &addr->ip, mask);
10643 +}
10644 +
10645 +static inline
10646 +int v6_nx_addr_in_nx_info(struct nx_info *nxi, struct nx_addr_v6 *nxa, uint16_t mask)
10647 +{
10648 +       struct nx_addr_v6 *ptr;
10649 +
10650 +       for (ptr = &nxi->v6; ptr; ptr = ptr->next)
10651 +               if (v6_nx_addr_match(ptr, nxa, mask))
10652 +                       return 1;
10653 +       return 0;
10654 +}
10655 +
10656 +
10657 +/*
10658 + *     Check if a given address matches for a socket
10659 + *
10660 + *     nxi:            the socket's nx_info if any
10661 + *     addr:           to be verified address
10662 + */
10663 +static inline
10664 +int v6_sock_addr_match (
10665 +       struct nx_info *nxi,
10666 +       struct inet_sock *inet,
10667 +       struct in6_addr *addr)
10668 +{
10669 +       struct sock *sk = &inet->sk;
10670 +       struct in6_addr *saddr = inet6_rcv_saddr(sk);
10671 +
10672 +       if (!ipv6_addr_any(addr) &&
10673 +               ipv6_addr_equal(saddr, addr))
10674 +               return 1;
10675 +       if (ipv6_addr_any(saddr))
10676 +               return v6_addr_in_nx_info(nxi, addr, -1);
10677 +       return 0;
10678 +}
10679 +
10680 +/*
10681 + *     check if address is covered by socket
10682 + *
10683 + *     sk:     the socket to check against
10684 + *     addr:   the address in question (must be != 0)
10685 + */
10686 +
10687 +static inline
10688 +int __v6_addr_match_socket(const struct sock *sk, struct nx_addr_v6 *nxa)
10689 +{
10690 +       struct nx_info *nxi = sk->sk_nx_info;
10691 +       struct in6_addr *saddr = inet6_rcv_saddr(sk);
10692 +
10693 +       vxdprintk(VXD_CBIT(net, 5),
10694 +               "__v6_addr_in_socket(%p," NXAV6_FMT ") %p:%pI6 %p;%lx",
10695 +               sk, NXAV6(nxa), nxi, saddr, sk->sk_socket,
10696 +               (sk->sk_socket?sk->sk_socket->flags:0));
10697 +
10698 +       if (!ipv6_addr_any(saddr)) {    /* direct address match */
10699 +               return v6_addr_match(nxa, saddr, -1);
10700 +       } else if (nxi) {               /* match against nx_info */
10701 +               return v6_nx_addr_in_nx_info(nxi, nxa, -1);
10702 +       } else {                        /* unrestricted any socket */
10703 +               return 1;
10704 +       }
10705 +}
10706 +
10707 +
10708 +/* inet related checks and helpers */
10709 +
10710 +
10711 +struct in_ifaddr;
10712 +struct net_device;
10713 +struct sock;
10714 +
10715 +
10716 +#include <linux/netdevice.h>
10717 +#include <linux/inetdevice.h>
10718 +#include <net/inet_timewait_sock.h>
10719 +
10720 +
10721 +int dev_in_nx_info(struct net_device *, struct nx_info *);
10722 +int v6_dev_in_nx_info(struct net_device *, struct nx_info *);
10723 +int nx_v6_addr_conflict(struct nx_info *, struct nx_info *);
10724 +
10725 +
10726 +
10727 +static inline
10728 +int v6_ifa_in_nx_info(struct inet6_ifaddr *ifa, struct nx_info *nxi)
10729 +{
10730 +       if (!nxi)
10731 +               return 1;
10732 +       if (!ifa)
10733 +               return 0;
10734 +       return v6_addr_in_nx_info(nxi, &ifa->addr, -1);
10735 +}
10736 +
10737 +static inline
10738 +int nx_v6_ifa_visible(struct nx_info *nxi, struct inet6_ifaddr *ifa)
10739 +{
10740 +       vxdprintk(VXD_CBIT(net, 1), "nx_v6_ifa_visible(%p[#%u],%p) %d",
10741 +               nxi, nxi ? nxi->nx_id : 0, ifa,
10742 +               nxi ? v6_ifa_in_nx_info(ifa, nxi) : 0);
10743 +
10744 +       if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
10745 +               return 1;
10746 +       if (v6_ifa_in_nx_info(ifa, nxi))
10747 +               return 1;
10748 +       return 0;
10749 +}
10750 +
10751 +
10752 +struct nx_v6_sock_addr {
10753 +       struct in6_addr saddr;  /* Address used for validation */
10754 +       struct in6_addr baddr;  /* Address used for socket bind */
10755 +};
10756 +
10757 +static inline
10758 +int v6_map_sock_addr(struct inet_sock *inet, struct sockaddr_in6 *addr,
10759 +       struct nx_v6_sock_addr *nsa)
10760 +{
10761 +       // struct sock *sk = &inet->sk;
10762 +       // struct nx_info *nxi = sk->sk_nx_info;
10763 +       struct in6_addr saddr = addr->sin6_addr;
10764 +       struct in6_addr baddr = saddr;
10765 +
10766 +       nsa->saddr = saddr;
10767 +       nsa->baddr = baddr;
10768 +       return 0;
10769 +}
10770 +
10771 +static inline
10772 +void v6_set_sock_addr(struct inet_sock *inet, struct nx_v6_sock_addr *nsa)
10773 +{
10774 +       // struct sock *sk = &inet->sk;
10775 +       // struct in6_addr *saddr = inet6_rcv_saddr(sk);
10776 +
10777 +       // *saddr = nsa->baddr;
10778 +       // inet->inet_saddr = nsa->baddr;
10779 +}
10780 +
10781 +static inline
10782 +int nx_info_has_v6(struct nx_info *nxi)
10783 +{
10784 +       if (!nxi)
10785 +               return 1;
10786 +       if (NX_IPV6(nxi))
10787 +               return 1;
10788 +       return 0;
10789 +}
10790 +
10791 +#else /* CONFIG_IPV6 */
10792 +
10793 +static inline
10794 +int nx_v6_dev_visible(struct nx_info *n, struct net_device *d)
10795 +{
10796 +       return 1;
10797 +}
10798 +
10799 +
10800 +static inline
10801 +int nx_v6_addr_conflict(struct nx_info *n, uint32_t a, const struct sock *s)
10802 +{
10803 +       return 1;
10804 +}
10805 +
10806 +static inline
10807 +int v6_ifa_in_nx_info(struct in_ifaddr *a, struct nx_info *n)
10808 +{
10809 +       return 1;
10810 +}
10811 +
10812 +static inline
10813 +int nx_info_has_v6(struct nx_info *nxi)
10814 +{
10815 +       return 0;
10816 +}
10817 +
10818 +#endif /* CONFIG_IPV6 */
10819 +
10820 +#define current_nx_info_has_v6() \
10821 +       nx_info_has_v6(current_nx_info())
10822 +
10823 +#else
10824 +#warning duplicate inclusion
10825 +#endif
10826 diff -NurpP --minimal linux-2.6.38.3/include/linux/vs_limit.h linux-2.6.38.3-vs2.3.0.37-rc14/include/linux/vs_limit.h
10827 --- linux-2.6.38.3/include/linux/vs_limit.h     1970-01-01 01:00:00.000000000 +0100
10828 +++ linux-2.6.38.3-vs2.3.0.37-rc14/include/linux/vs_limit.h     2011-01-29 04:59:22.000000000 +0100
10829 @@ -0,0 +1,140 @@
10830 +#ifndef _VS_LIMIT_H
10831 +#define _VS_LIMIT_H
10832 +
10833 +#include "vserver/limit.h"
10834 +#include "vserver/base.h"
10835 +#include "vserver/context.h"
10836 +#include "vserver/debug.h"
10837 +#include "vserver/context.h"
10838 +#include "vserver/limit_int.h"
10839 +
10840 +
10841 +#define vx_acc_cres(v, d, p, r) \
10842 +       __vx_acc_cres(v, r, d, p, __FILE__, __LINE__)
10843 +
10844 +#define vx_acc_cres_cond(x, d, p, r) \
10845 +       __vx_acc_cres(((x) == vx_current_xid()) ? current_vx_info() : 0, \
10846 +       r, d, p, __FILE__, __LINE__)
10847 +
10848 +
10849 +#define vx_add_cres(v, a, p, r) \
10850 +       __vx_add_cres(v, r, a, p, __FILE__, __LINE__)
10851 +#define vx_sub_cres(v, a, p, r)                vx_add_cres(v, -(a), p, r)
10852 +
10853 +#define vx_add_cres_cond(x, a, p, r) \
10854 +       __vx_add_cres(((x) == vx_current_xid()) ? current_vx_info() : 0, \
10855 +       r, a, p, __FILE__, __LINE__)
10856 +#define vx_sub_cres_cond(x, a, p, r)   vx_add_cres_cond(x, -(a), p, r)
10857 +
10858 +
10859 +/* process and file limits */
10860 +
10861 +#define vx_nproc_inc(p) \
10862 +       vx_acc_cres((p)->vx_info, 1, p, RLIMIT_NPROC)
10863 +
10864 +#define vx_nproc_dec(p) \
10865 +       vx_acc_cres((p)->vx_info,-1, p, RLIMIT_NPROC)
10866 +
10867 +#define vx_files_inc(f) \
10868 +       vx_acc_cres_cond((f)->f_xid, 1, f, RLIMIT_NOFILE)
10869 +
10870 +#define vx_files_dec(f) \
10871 +       vx_acc_cres_cond((f)->f_xid,-1, f, RLIMIT_NOFILE)
10872 +
10873 +#define vx_locks_inc(l) \
10874 +       vx_acc_cres_cond((l)->fl_xid, 1, l, RLIMIT_LOCKS)
10875 +
10876 +#define vx_locks_dec(l) \
10877 +       vx_acc_cres_cond((l)->fl_xid,-1, l, RLIMIT_LOCKS)
10878 +
10879 +#define vx_openfd_inc(f) \
10880 +       vx_acc_cres(current_vx_info(), 1, (void *)(long)(f), VLIMIT_OPENFD)
10881 +
10882 +#define vx_openfd_dec(f) \
10883 +       vx_acc_cres(current_vx_info(),-1, (void *)(long)(f), VLIMIT_OPENFD)
10884 +
10885 +
10886 +#define vx_cres_avail(v, n, r) \
10887 +       __vx_cres_avail(v, r, n, __FILE__, __LINE__)
10888 +
10889 +
10890 +#define vx_nproc_avail(n) \
10891 +       vx_cres_avail(current_vx_info(), n, RLIMIT_NPROC)
10892 +
10893 +#define vx_files_avail(n) \
10894 +       vx_cres_avail(current_vx_info(), n, RLIMIT_NOFILE)
10895 +
10896 +#define vx_locks_avail(n) \
10897 +       vx_cres_avail(current_vx_info(), n, RLIMIT_LOCKS)
10898 +
10899 +#define vx_openfd_avail(n) \
10900 +       vx_cres_avail(current_vx_info(), n, VLIMIT_OPENFD)
10901 +
10902 +
10903 +/* dentry limits */
10904 +
10905 +#define vx_dentry_inc(d) do {                                          \
10906 +       if ((d)->d_count == 1)                                          \
10907 +               vx_acc_cres(current_vx_info(), 1, d, VLIMIT_DENTRY);    \
10908 +       } while (0)
10909 +
10910 +#define vx_dentry_dec(d) do {                                          \
10911 +       if ((d)->d_count == 0)                                          \
10912 +               vx_acc_cres(current_vx_info(),-1, d, VLIMIT_DENTRY);    \
10913 +       } while (0)
10914 +
10915 +#define vx_dentry_avail(n) \
10916 +       vx_cres_avail(current_vx_info(), n, VLIMIT_DENTRY)
10917 +
10918 +
10919 +/* socket limits */
10920 +
10921 +#define vx_sock_inc(s) \
10922 +       vx_acc_cres((s)->sk_vx_info, 1, s, VLIMIT_NSOCK)
10923 +
10924 +#define vx_sock_dec(s) \
10925 +       vx_acc_cres((s)->sk_vx_info,-1, s, VLIMIT_NSOCK)
10926 +
10927 +#define vx_sock_avail(n) \
10928 +       vx_cres_avail(current_vx_info(), n, VLIMIT_NSOCK)
10929 +
10930 +
10931 +/* ipc resource limits */
10932 +
10933 +#define vx_ipcmsg_add(v, u, a) \
10934 +       vx_add_cres(v, a, u, RLIMIT_MSGQUEUE)
10935 +
10936 +#define vx_ipcmsg_sub(v, u, a) \
10937 +       vx_sub_cres(v, a, u, RLIMIT_MSGQUEUE)
10938 +
10939 +#define vx_ipcmsg_avail(v, a) \
10940 +       vx_cres_avail(v, a, RLIMIT_MSGQUEUE)
10941 +
10942 +
10943 +#define vx_ipcshm_add(v, k, a) \
10944 +       vx_add_cres(v, a, (void *)(long)(k), VLIMIT_SHMEM)
10945 +
10946 +#define vx_ipcshm_sub(v, k, a) \
10947 +       vx_sub_cres(v, a, (void *)(long)(k), VLIMIT_SHMEM)
10948 +
10949 +#define vx_ipcshm_avail(v, a) \
10950 +       vx_cres_avail(v, a, VLIMIT_SHMEM)
10951 +
10952 +
10953 +#define vx_semary_inc(a) \
10954 +       vx_acc_cres(current_vx_info(), 1, a, VLIMIT_SEMARY)
10955 +
10956 +#define vx_semary_dec(a) \
10957 +       vx_acc_cres(current_vx_info(), -1, a, VLIMIT_SEMARY)
10958 +
10959 +
10960 +#define vx_nsems_add(a,n) \
10961 +       vx_add_cres(current_vx_info(), n, a, VLIMIT_NSEMS)
10962 +
10963 +#define vx_nsems_sub(a,n) \
10964 +       vx_sub_cres(current_vx_info(), n, a, VLIMIT_NSEMS)
10965 +
10966 +
10967 +#else
10968 +#warning duplicate inclusion
10969 +#endif
10970 diff -NurpP --minimal linux-2.6.38.3/include/linux/vs_memory.h linux-2.6.38.3-vs2.3.0.37-rc14/include/linux/vs_memory.h
10971 --- linux-2.6.38.3/include/linux/vs_memory.h    1970-01-01 01:00:00.000000000 +0100
10972 +++ linux-2.6.38.3-vs2.3.0.37-rc14/include/linux/vs_memory.h    2011-01-29 02:01:07.000000000 +0100
10973 @@ -0,0 +1,58 @@
10974 +#ifndef _VS_MEMORY_H
10975 +#define _VS_MEMORY_H
10976 +
10977 +#include "vserver/limit.h"
10978 +#include "vserver/base.h"
10979 +#include "vserver/context.h"
10980 +#include "vserver/debug.h"
10981 +#include "vserver/context.h"
10982 +#include "vserver/limit_int.h"
10983 +
10984 +enum {
10985 +       VXPT_UNKNOWN = 0,
10986 +       VXPT_ANON,
10987 +       VXPT_NONE,
10988 +       VXPT_FILE,
10989 +       VXPT_SWAP,
10990 +       VXPT_WRITE
10991 +};
10992 +
10993 +#if 0
10994 +#define        vx_page_fault(mm, vma, type, ret)
10995 +#else
10996 +
10997 +static inline
10998 +void __vx_page_fault(struct mm_struct *mm,
10999 +       struct vm_area_struct *vma, int type, int ret)
11000 +{
11001 +       struct vx_info *vxi = mm->mm_vx_info;
11002 +       int what;
11003 +/*
11004 +       static char *page_type[6] =
11005 +               { "UNKNOWN", "ANON", "NONE", "FILE", "SWAP", "WRITE" };
11006 +       static char *page_what[4] =
11007 +               { "FAULT_OOM", "FAULT_SIGBUS", "FAULT_MINOR", "FAULT_MAJOR" };
11008 +*/
11009 +
11010 +       if (!vxi)
11011 +               return;
11012 +
11013 +       what = (ret & 0x3);
11014 +
11015 +/*     printk("[%d] page[%d][%d] %2x %s %s\n", vxi->vx_id,
11016 +               type, what, ret, page_type[type], page_what[what]);
11017 +*/
11018 +       if (ret & VM_FAULT_WRITE)
11019 +               what |= 0x4;
11020 +       atomic_inc(&vxi->cacct.page[type][what]);
11021 +}
11022 +
11023 +#define        vx_page_fault(mm, vma, type, ret)       __vx_page_fault(mm, vma, type, ret)
11024 +#endif
11025 +
11026 +
11027 +extern unsigned long vx_badness(struct task_struct *task, struct mm_struct *mm);
11028 +
11029 +#else
11030 +#warning duplicate inclusion
11031 +#endif
11032 diff -NurpP --minimal linux-2.6.38.3/include/linux/vs_network.h linux-2.6.38.3-vs2.3.0.37-rc14/include/linux/vs_network.h
11033 --- linux-2.6.38.3/include/linux/vs_network.h   1970-01-01 01:00:00.000000000 +0100
11034 +++ linux-2.6.38.3-vs2.3.0.37-rc14/include/linux/vs_network.h   2011-01-29 02:01:07.000000000 +0100
11035 @@ -0,0 +1,169 @@
11036 +#ifndef _NX_VS_NETWORK_H
11037 +#define _NX_VS_NETWORK_H
11038 +
11039 +#include "vserver/context.h"
11040 +#include "vserver/network.h"
11041 +#include "vserver/base.h"
11042 +#include "vserver/check.h"
11043 +#include "vserver/debug.h"
11044 +
11045 +#include <linux/sched.h>
11046 +
11047 +
11048 +#define get_nx_info(i) __get_nx_info(i, __FILE__, __LINE__)
11049 +
11050 +static inline struct nx_info *__get_nx_info(struct nx_info *nxi,
11051 +       const char *_file, int _line)
11052 +{
11053 +       if (!nxi)
11054 +               return NULL;
11055 +
11056 +       vxlprintk(VXD_CBIT(nid, 2), "get_nx_info(%p[#%d.%d])",
11057 +               nxi, nxi ? nxi->nx_id : 0,
11058 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
11059 +               _file, _line);
11060 +
11061 +       atomic_inc(&nxi->nx_usecnt);
11062 +       return nxi;
11063 +}
11064 +
11065 +
11066 +extern void free_nx_info(struct nx_info *);
11067 +
11068 +#define put_nx_info(i) __put_nx_info(i, __FILE__, __LINE__)
11069 +
11070 +static inline void __put_nx_info(struct nx_info *nxi, const char *_file, int _line)
11071 +{
11072 +       if (!nxi)
11073 +               return;
11074 +
11075 +       vxlprintk(VXD_CBIT(nid, 2), "put_nx_info(%p[#%d.%d])",
11076 +               nxi, nxi ? nxi->nx_id : 0,
11077 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
11078 +               _file, _line);
11079 +
11080 +       if (atomic_dec_and_test(&nxi->nx_usecnt))
11081 +               free_nx_info(nxi);
11082 +}
11083 +
11084 +
11085 +#define init_nx_info(p, i) __init_nx_info(p, i, __FILE__, __LINE__)
11086 +
11087 +static inline void __init_nx_info(struct nx_info **nxp, struct nx_info *nxi,
11088 +               const char *_file, int _line)
11089 +{
11090 +       if (nxi) {
11091 +               vxlprintk(VXD_CBIT(nid, 3),
11092 +                       "init_nx_info(%p[#%d.%d])",
11093 +                       nxi, nxi ? nxi->nx_id : 0,
11094 +                       nxi ? atomic_read(&nxi->nx_usecnt) : 0,
11095 +                       _file, _line);
11096 +
11097 +               atomic_inc(&nxi->nx_usecnt);
11098 +       }
11099 +       *nxp = nxi;
11100 +}
11101 +
11102 +
11103 +#define set_nx_info(p, i) __set_nx_info(p, i, __FILE__, __LINE__)
11104 +
11105 +static inline void __set_nx_info(struct nx_info **nxp, struct nx_info *nxi,
11106 +       const char *_file, int _line)
11107 +{
11108 +       struct nx_info *nxo;
11109 +
11110 +       if (!nxi)
11111 +               return;
11112 +
11113 +       vxlprintk(VXD_CBIT(nid, 3), "set_nx_info(%p[#%d.%d])",
11114 +               nxi, nxi ? nxi->nx_id : 0,
11115 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
11116 +               _file, _line);
11117 +
11118 +       atomic_inc(&nxi->nx_usecnt);
11119 +       nxo = xchg(nxp, nxi);
11120 +       BUG_ON(nxo);
11121 +}
11122 +
11123 +#define clr_nx_info(p) __clr_nx_info(p, __FILE__, __LINE__)
11124 +
11125 +static inline void __clr_nx_info(struct nx_info **nxp,
11126 +       const char *_file, int _line)
11127 +{
11128 +       struct nx_info *nxo;
11129 +
11130 +       nxo = xchg(nxp, NULL);
11131 +       if (!nxo)
11132 +               return;
11133 +
11134 +       vxlprintk(VXD_CBIT(nid, 3), "clr_nx_info(%p[#%d.%d])",
11135 +               nxo, nxo ? nxo->nx_id : 0,
11136 +               nxo ? atomic_read(&nxo->nx_usecnt) : 0,
11137 +               _file, _line);
11138 +
11139 +       if (atomic_dec_and_test(&nxo->nx_usecnt))
11140 +               free_nx_info(nxo);
11141 +}
11142 +
11143 +
11144 +#define claim_nx_info(v, p) __claim_nx_info(v, p, __FILE__, __LINE__)
11145 +
11146 +static inline void __claim_nx_info(struct nx_info *nxi,
11147 +       struct task_struct *task, const char *_file, int _line)
11148 +{
11149 +       vxlprintk(VXD_CBIT(nid, 3), "claim_nx_info(%p[#%d.%d.%d]) %p",
11150 +               nxi, nxi ? nxi->nx_id : 0,
11151 +               nxi?atomic_read(&nxi->nx_usecnt):0,
11152 +               nxi?atomic_read(&nxi->nx_tasks):0,
11153 +               task, _file, _line);
11154 +
11155 +       atomic_inc(&nxi->nx_tasks);
11156 +}
11157 +
11158 +
11159 +extern void unhash_nx_info(struct nx_info *);
11160 +
11161 +#define release_nx_info(v, p) __release_nx_info(v, p, __FILE__, __LINE__)
11162 +
11163 +static inline void __release_nx_info(struct nx_info *nxi,
11164 +       struct task_struct *task, const char *_file, int _line)
11165 +{
11166 +       vxlprintk(VXD_CBIT(nid, 3), "release_nx_info(%p[#%d.%d.%d]) %p",
11167 +               nxi, nxi ? nxi->nx_id : 0,
11168 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
11169 +               nxi ? atomic_read(&nxi->nx_tasks) : 0,
11170 +               task, _file, _line);
11171 +
11172 +       might_sleep();
11173 +
11174 +       if (atomic_dec_and_test(&nxi->nx_tasks))
11175 +               unhash_nx_info(nxi);
11176 +}
11177 +
11178 +
11179 +#define task_get_nx_info(i)    __task_get_nx_info(i, __FILE__, __LINE__)
11180 +
11181 +static __inline__ struct nx_info *__task_get_nx_info(struct task_struct *p,
11182 +       const char *_file, int _line)
11183 +{
11184 +       struct nx_info *nxi;
11185 +
11186 +       task_lock(p);
11187 +       vxlprintk(VXD_CBIT(nid, 5), "task_get_nx_info(%p)",
11188 +               p, _file, _line);
11189 +       nxi = __get_nx_info(p->nx_info, _file, _line);
11190 +       task_unlock(p);
11191 +       return nxi;
11192 +}
11193 +
11194 +
11195 +static inline void exit_nx_info(struct task_struct *p)
11196 +{
11197 +       if (p->nx_info)
11198 +               release_nx_info(p->nx_info, p);
11199 +}
11200 +
11201 +
11202 +#else
11203 +#warning duplicate inclusion
11204 +#endif
11205 diff -NurpP --minimal linux-2.6.38.3/include/linux/vs_pid.h linux-2.6.38.3-vs2.3.0.37-rc14/include/linux/vs_pid.h
11206 --- linux-2.6.38.3/include/linux/vs_pid.h       1970-01-01 01:00:00.000000000 +0100
11207 +++ linux-2.6.38.3-vs2.3.0.37-rc14/include/linux/vs_pid.h       2011-03-22 17:43:53.000000000 +0100
11208 @@ -0,0 +1,50 @@
11209 +#ifndef _VS_PID_H
11210 +#define _VS_PID_H
11211 +
11212 +#include "vserver/base.h"
11213 +#include "vserver/check.h"
11214 +#include "vserver/context.h"
11215 +#include "vserver/debug.h"
11216 +#include "vserver/pid.h"
11217 +#include <linux/pid_namespace.h>
11218 +
11219 +
11220 +#define VXF_FAKE_INIT  (VXF_INFO_INIT | VXF_STATE_INIT)
11221 +
11222 +static inline
11223 +int vx_proc_task_visible(struct task_struct *task)
11224 +{
11225 +       if ((task->pid == 1) &&
11226 +               !vx_flags(VXF_FAKE_INIT, VXF_FAKE_INIT))
11227 +               /* show a blend through init */
11228 +               goto visible;
11229 +       if (vx_check(vx_task_xid(task), VS_WATCH | VS_IDENT))
11230 +               goto visible;
11231 +       return 0;
11232 +visible:
11233 +       return 1;
11234 +}
11235 +
11236 +#define find_task_by_real_pid(pid) find_task_by_pid_ns(pid, &init_pid_ns)
11237 +
11238 +
11239 +static inline
11240 +struct task_struct *vx_get_proc_task(struct inode *inode, struct pid *pid)
11241 +{
11242 +       struct task_struct *task = get_pid_task(pid, PIDTYPE_PID);
11243 +
11244 +       if (task && !vx_proc_task_visible(task)) {
11245 +               vxdprintk(VXD_CBIT(misc, 6),
11246 +                       "dropping task (get) %p[#%u,%u] for %p[#%u,%u]",
11247 +                       task, task->xid, task->pid,
11248 +                       current, current->xid, current->pid);
11249 +               put_task_struct(task);
11250 +               task = NULL;
11251 +       }
11252 +       return task;
11253 +}
11254 +
11255 +
11256 +#else
11257 +#warning duplicate inclusion
11258 +#endif
11259 diff -NurpP --minimal linux-2.6.38.3/include/linux/vs_sched.h linux-2.6.38.3-vs2.3.0.37-rc14/include/linux/vs_sched.h
11260 --- linux-2.6.38.3/include/linux/vs_sched.h     1970-01-01 01:00:00.000000000 +0100
11261 +++ linux-2.6.38.3-vs2.3.0.37-rc14/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.3/include/linux/vs_socket.h linux-2.6.38.3-vs2.3.0.37-rc14/include/linux/vs_socket.h
11304 --- linux-2.6.38.3/include/linux/vs_socket.h    1970-01-01 01:00:00.000000000 +0100
11305 +++ linux-2.6.38.3-vs2.3.0.37-rc14/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.3/include/linux/vs_tag.h linux-2.6.38.3-vs2.3.0.37-rc14/include/linux/vs_tag.h
11375 --- linux-2.6.38.3/include/linux/vs_tag.h       1970-01-01 01:00:00.000000000 +0100
11376 +++ linux-2.6.38.3-vs2.3.0.37-rc14/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.3/include/linux/vs_time.h linux-2.6.38.3-vs2.3.0.37-rc14/include/linux/vs_time.h
11426 --- linux-2.6.38.3/include/linux/vs_time.h      1970-01-01 01:00:00.000000000 +0100
11427 +++ linux-2.6.38.3-vs2.3.0.37-rc14/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.3/include/linux/vserver/Kbuild linux-2.6.38.3-vs2.3.0.37-rc14/include/linux/vserver/Kbuild
11449 --- linux-2.6.38.3/include/linux/vserver/Kbuild 1970-01-01 01:00:00.000000000 +0100
11450 +++ linux-2.6.38.3-vs2.3.0.37-rc14/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.3/include/linux/vserver/base.h linux-2.6.38.3-vs2.3.0.37-rc14/include/linux/vserver/base.h
11461 --- linux-2.6.38.3/include/linux/vserver/base.h 1970-01-01 01:00:00.000000000 +0100
11462 +++ linux-2.6.38.3-vs2.3.0.37-rc14/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.3/include/linux/vserver/cacct.h linux-2.6.38.3-vs2.3.0.37-rc14/include/linux/vserver/cacct.h
11635 --- linux-2.6.38.3/include/linux/vserver/cacct.h        1970-01-01 01:00:00.000000000 +0100
11636 +++ linux-2.6.38.3-vs2.3.0.37-rc14/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.3/include/linux/vserver/cacct_cmd.h linux-2.6.38.3-vs2.3.0.37-rc14/include/linux/vserver/cacct_cmd.h
11654 --- linux-2.6.38.3/include/linux/vserver/cacct_cmd.h    1970-01-01 01:00:00.000000000 +0100
11655 +++ linux-2.6.38.3-vs2.3.0.37-rc14/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.3/include/linux/vserver/cacct_def.h linux-2.6.38.3-vs2.3.0.37-rc14/include/linux/vserver/cacct_def.h
11681 --- linux-2.6.38.3/include/linux/vserver/cacct_def.h    1970-01-01 01:00:00.000000000 +0100
11682 +++ linux-2.6.38.3-vs2.3.0.37-rc14/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.3/include/linux/vserver/cacct_int.h linux-2.6.38.3-vs2.3.0.37-rc14/include/linux/vserver/cacct_int.h
11728 --- linux-2.6.38.3/include/linux/vserver/cacct_int.h    1970-01-01 01:00:00.000000000 +0100
11729 +++ linux-2.6.38.3-vs2.3.0.37-rc14/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.3/include/linux/vserver/check.h linux-2.6.38.3-vs2.3.0.37-rc14/include/linux/vserver/check.h
11753 --- linux-2.6.38.3/include/linux/vserver/check.h        1970-01-01 01:00:00.000000000 +0100
11754 +++ linux-2.6.38.3-vs2.3.0.37-rc14/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.3/include/linux/vserver/context.h linux-2.6.38.3-vs2.3.0.37-rc14/include/linux/vserver/context.h
11846 --- linux-2.6.38.3/include/linux/vserver/context.h      1970-01-01 01:00:00.000000000 +0100
11847 +++ linux-2.6.38.3-vs2.3.0.37-rc14/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.3/include/linux/vserver/context_cmd.h linux-2.6.38.3-vs2.3.0.37-rc14/include/linux/vserver/context_cmd.h
12039 --- linux-2.6.38.3/include/linux/vserver/context_cmd.h  1970-01-01 01:00:00.000000000 +0100
12040 +++ linux-2.6.38.3-vs2.3.0.37-rc14/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.3/include/linux/vserver/cvirt.h linux-2.6.38.3-vs2.3.0.37-rc14/include/linux/vserver/cvirt.h
12188 --- linux-2.6.38.3/include/linux/vserver/cvirt.h        1970-01-01 01:00:00.000000000 +0100
12189 +++ linux-2.6.38.3-vs2.3.0.37-rc14/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.3/include/linux/vserver/cvirt_cmd.h linux-2.6.38.3-vs2.3.0.37-rc14/include/linux/vserver/cvirt_cmd.h
12212 --- linux-2.6.38.3/include/linux/vserver/cvirt_cmd.h    1970-01-01 01:00:00.000000000 +0100
12213 +++ linux-2.6.38.3-vs2.3.0.37-rc14/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.3/include/linux/vserver/cvirt_def.h linux-2.6.38.3-vs2.3.0.37-rc14/include/linux/vserver/cvirt_def.h
12269 --- linux-2.6.38.3/include/linux/vserver/cvirt_def.h    1970-01-01 01:00:00.000000000 +0100
12270 +++ linux-2.6.38.3-vs2.3.0.37-rc14/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.3/include/linux/vserver/debug.h linux-2.6.38.3-vs2.3.0.37-rc14/include/linux/vserver/debug.h
12353 --- linux-2.6.38.3/include/linux/vserver/debug.h        1970-01-01 01:00:00.000000000 +0100
12354 +++ linux-2.6.38.3-vs2.3.0.37-rc14/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.3/include/linux/vserver/debug_cmd.h linux-2.6.38.3-vs2.3.0.37-rc14/include/linux/vserver/debug_cmd.h
12497 --- linux-2.6.38.3/include/linux/vserver/debug_cmd.h    1970-01-01 01:00:00.000000000 +0100
12498 +++ linux-2.6.38.3-vs2.3.0.37-rc14/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.3/include/linux/vserver/device.h linux-2.6.38.3-vs2.3.0.37-rc14/include/linux/vserver/device.h
12559 --- linux-2.6.38.3/include/linux/vserver/device.h       1970-01-01 01:00:00.000000000 +0100
12560 +++ linux-2.6.38.3-vs2.3.0.37-rc14/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.3/include/linux/vserver/device_cmd.h linux-2.6.38.3-vs2.3.0.37-rc14/include/linux/vserver/device_cmd.h
12578 --- linux-2.6.38.3/include/linux/vserver/device_cmd.h   1970-01-01 01:00:00.000000000 +0100
12579 +++ linux-2.6.38.3-vs2.3.0.37-rc14/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.3/include/linux/vserver/device_def.h linux-2.6.38.3-vs2.3.0.37-rc14/include/linux/vserver/device_def.h
12626 --- linux-2.6.38.3/include/linux/vserver/device_def.h   1970-01-01 01:00:00.000000000 +0100
12627 +++ linux-2.6.38.3-vs2.3.0.37-rc14/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.3/include/linux/vserver/dlimit.h linux-2.6.38.3-vs2.3.0.37-rc14/include/linux/vserver/dlimit.h
12647 --- linux-2.6.38.3/include/linux/vserver/dlimit.h       1970-01-01 01:00:00.000000000 +0100
12648 +++ linux-2.6.38.3-vs2.3.0.37-rc14/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.3/include/linux/vserver/dlimit_cmd.h linux-2.6.38.3-vs2.3.0.37-rc14/include/linux/vserver/dlimit_cmd.h
12705 --- linux-2.6.38.3/include/linux/vserver/dlimit_cmd.h   1970-01-01 01:00:00.000000000 +0100
12706 +++ linux-2.6.38.3-vs2.3.0.37-rc14/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.3/include/linux/vserver/global.h linux-2.6.38.3-vs2.3.0.37-rc14/include/linux/vserver/global.h
12818 --- linux-2.6.38.3/include/linux/vserver/global.h       1970-01-01 01:00:00.000000000 +0100
12819 +++ linux-2.6.38.3-vs2.3.0.37-rc14/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.3/include/linux/vserver/history.h linux-2.6.38.3-vs2.3.0.37-rc14/include/linux/vserver/history.h
12841 --- linux-2.6.38.3/include/linux/vserver/history.h      1970-01-01 01:00:00.000000000 +0100
12842 +++ linux-2.6.38.3-vs2.3.0.37-rc14/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.3/include/linux/vserver/inode.h linux-2.6.38.3-vs2.3.0.37-rc14/include/linux/vserver/inode.h
13042 --- linux-2.6.38.3/include/linux/vserver/inode.h        1970-01-01 01:00:00.000000000 +0100
13043 +++ linux-2.6.38.3-vs2.3.0.37-rc14/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.3/include/linux/vserver/inode_cmd.h linux-2.6.38.3-vs2.3.0.37-rc14/include/linux/vserver/inode_cmd.h
13085 --- linux-2.6.38.3/include/linux/vserver/inode_cmd.h    1970-01-01 01:00:00.000000000 +0100
13086 +++ linux-2.6.38.3-vs2.3.0.37-rc14/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.3/include/linux/vserver/limit.h linux-2.6.38.3-vs2.3.0.37-rc14/include/linux/vserver/limit.h
13148 --- linux-2.6.38.3/include/linux/vserver/limit.h        1970-01-01 01:00:00.000000000 +0100
13149 +++ linux-2.6.38.3-vs2.3.0.37-rc14/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.3/include/linux/vserver/limit_cmd.h linux-2.6.38.3-vs2.3.0.37-rc14/include/linux/vserver/limit_cmd.h
13223 --- linux-2.6.38.3/include/linux/vserver/limit_cmd.h    1970-01-01 01:00:00.000000000 +0100
13224 +++ linux-2.6.38.3-vs2.3.0.37-rc14/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.3/include/linux/vserver/limit_def.h linux-2.6.38.3-vs2.3.0.37-rc14/include/linux/vserver/limit_def.h
13298 --- linux-2.6.38.3/include/linux/vserver/limit_def.h    1970-01-01 01:00:00.000000000 +0100
13299 +++ linux-2.6.38.3-vs2.3.0.37-rc14/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.3/include/linux/vserver/limit_int.h linux-2.6.38.3-vs2.3.0.37-rc14/include/linux/vserver/limit_int.h
13349 --- linux-2.6.38.3/include/linux/vserver/limit_int.h    1970-01-01 01:00:00.000000000 +0100
13350 +++ linux-2.6.38.3-vs2.3.0.37-rc14/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.3/include/linux/vserver/monitor.h linux-2.6.38.3-vs2.3.0.37-rc14/include/linux/vserver/monitor.h
13551 --- linux-2.6.38.3/include/linux/vserver/monitor.h      1970-01-01 01:00:00.000000000 +0100
13552 +++ linux-2.6.38.3-vs2.3.0.37-rc14/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.3/include/linux/vserver/network.h linux-2.6.38.3-vs2.3.0.37-rc14/include/linux/vserver/network.h
13651 --- linux-2.6.38.3/include/linux/vserver/network.h      1970-01-01 01:00:00.000000000 +0100
13652 +++ linux-2.6.38.3-vs2.3.0.37-rc14/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.3/include/linux/vserver/network_cmd.h linux-2.6.38.3-vs2.3.0.37-rc14/include/linux/vserver/network_cmd.h
13801 --- linux-2.6.38.3/include/linux/vserver/network_cmd.h  1970-01-01 01:00:00.000000000 +0100
13802 +++ linux-2.6.38.3-vs2.3.0.37-rc14/include/linux/vserver/network_cmd.h  2011-04-15 16:09:57.000000000 +0200
13803 @@ -0,0 +1,164 @@
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_v1   VC_CMD(NETALT, 1, 1)
13852 +#define VCMD_net_rem_ipv4_v1   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_ipv4      VC_CMD(NETALT, 1, 2)
13862 +#define VCMD_net_rem_ipv4      VC_CMD(NETALT, 2, 2)
13863 +
13864 +struct vcmd_net_addr_ipv4_v2 {
13865 +       uint16_t type;
13866 +       uint16_t flags;
13867 +       struct in_addr ip;
13868 +       struct in_addr ip2;
13869 +       struct in_addr mask;
13870 +};
13871 +
13872 +#define VCMD_net_add_ipv6      VC_CMD(NETALT, 3, 1)
13873 +#define VCMD_net_remove_ipv6   VC_CMD(NETALT, 4, 1)
13874 +
13875 +struct vcmd_net_addr_ipv6_v1 {
13876 +       uint16_t type;
13877 +       uint16_t flags;
13878 +       uint32_t prefix;
13879 +       struct in6_addr ip;
13880 +       struct in6_addr mask;
13881 +};
13882 +
13883 +#define VCMD_add_match_ipv4    VC_CMD(NETALT, 5, 0)
13884 +#define VCMD_get_match_ipv4    VC_CMD(NETALT, 6, 0)
13885 +
13886 +struct vcmd_match_ipv4_v0 {
13887 +       uint16_t type;
13888 +       uint16_t flags;
13889 +       uint16_t parent;
13890 +       uint16_t prefix;
13891 +       struct in_addr ip;
13892 +       struct in_addr ip2;
13893 +       struct in_addr mask;
13894 +};
13895 +
13896 +#define VCMD_add_match_ipv6    VC_CMD(NETALT, 7, 0)
13897 +#define VCMD_get_match_ipv6    VC_CMD(NETALT, 8, 0)
13898 +
13899 +struct vcmd_match_ipv6_v0 {
13900 +       uint16_t type;
13901 +       uint16_t flags;
13902 +       uint16_t parent;
13903 +       uint16_t prefix;
13904 +       struct in6_addr ip;
13905 +       struct in6_addr ip2;
13906 +       struct in6_addr mask;
13907 +};
13908 +
13909 +
13910 +#ifdef __KERNEL__
13911 +extern int vc_net_create(uint32_t, void __user *);
13912 +extern int vc_net_migrate(struct nx_info *, void __user *);
13913 +
13914 +extern int vc_net_add(struct nx_info *, void __user *);
13915 +extern int vc_net_remove(struct nx_info *, void __user *);
13916 +
13917 +extern int vc_net_add_ipv4_v1(struct nx_info *, void __user *);
13918 +extern int vc_net_add_ipv4(struct nx_info *, void __user *);
13919 +
13920 +extern int vc_net_rem_ipv4_v1(struct nx_info *, void __user *);
13921 +extern int vc_net_rem_ipv4(struct nx_info *, void __user *);
13922 +
13923 +extern int vc_net_add_ipv6(struct nx_info *, void __user *);
13924 +extern int vc_net_remove_ipv6(struct nx_info *, void __user *);
13925 +
13926 +extern int vc_add_match_ipv4(struct nx_info *, void __user *);
13927 +extern int vc_get_match_ipv4(struct nx_info *, void __user *);
13928 +
13929 +extern int vc_add_match_ipv6(struct nx_info *, void __user *);
13930 +extern int vc_get_match_ipv6(struct nx_info *, void __user *);
13931 +
13932 +#endif /* __KERNEL__ */
13933 +
13934 +
13935 +/* flag commands */
13936 +
13937 +#define VCMD_get_nflags                VC_CMD(FLAGS, 5, 0)
13938 +#define VCMD_set_nflags                VC_CMD(FLAGS, 6, 0)
13939 +
13940 +struct vcmd_net_flags_v0 {
13941 +       uint64_t flagword;
13942 +       uint64_t mask;
13943 +};
13944 +
13945 +#ifdef __KERNEL__
13946 +extern int vc_get_nflags(struct nx_info *, void __user *);
13947 +extern int vc_set_nflags(struct nx_info *, void __user *);
13948 +
13949 +#endif /* __KERNEL__ */
13950 +
13951 +
13952 +/* network caps commands */
13953 +
13954 +#define VCMD_get_ncaps         VC_CMD(FLAGS, 7, 0)
13955 +#define VCMD_set_ncaps         VC_CMD(FLAGS, 8, 0)
13956 +
13957 +struct vcmd_net_caps_v0 {
13958 +       uint64_t ncaps;
13959 +       uint64_t cmask;
13960 +};
13961 +
13962 +#ifdef __KERNEL__
13963 +extern int vc_get_ncaps(struct nx_info *, void __user *);
13964 +extern int vc_set_ncaps(struct nx_info *, void __user *);
13965 +
13966 +#endif /* __KERNEL__ */
13967 +#endif /* _VX_CONTEXT_CMD_H */
13968 diff -NurpP --minimal linux-2.6.38.3/include/linux/vserver/percpu.h linux-2.6.38.3-vs2.3.0.37-rc14/include/linux/vserver/percpu.h
13969 --- linux-2.6.38.3/include/linux/vserver/percpu.h       1970-01-01 01:00:00.000000000 +0100
13970 +++ linux-2.6.38.3-vs2.3.0.37-rc14/include/linux/vserver/percpu.h       2011-01-29 02:01:07.000000000 +0100
13971 @@ -0,0 +1,14 @@
13972 +#ifndef _VX_PERCPU_H
13973 +#define _VX_PERCPU_H
13974 +
13975 +#include "cvirt_def.h"
13976 +#include "sched_def.h"
13977 +
13978 +struct _vx_percpu {
13979 +       struct _vx_cvirt_pc cvirt;
13980 +       struct _vx_sched_pc sched;
13981 +};
13982 +
13983 +#define        PERCPU_PERCTX   (sizeof(struct _vx_percpu))
13984 +
13985 +#endif /* _VX_PERCPU_H */
13986 diff -NurpP --minimal linux-2.6.38.3/include/linux/vserver/pid.h linux-2.6.38.3-vs2.3.0.37-rc14/include/linux/vserver/pid.h
13987 --- linux-2.6.38.3/include/linux/vserver/pid.h  1970-01-01 01:00:00.000000000 +0100
13988 +++ linux-2.6.38.3-vs2.3.0.37-rc14/include/linux/vserver/pid.h  2011-01-29 02:01:07.000000000 +0100
13989 @@ -0,0 +1,51 @@
13990 +#ifndef _VSERVER_PID_H
13991 +#define _VSERVER_PID_H
13992 +
13993 +/* pid faking stuff */
13994 +
13995 +#define vx_info_map_pid(v, p) \
13996 +       __vx_info_map_pid((v), (p), __func__, __FILE__, __LINE__)
13997 +#define vx_info_map_tgid(v,p)  vx_info_map_pid(v,p)
13998 +#define vx_map_pid(p) vx_info_map_pid(current_vx_info(), p)
13999 +#define vx_map_tgid(p) vx_map_pid(p)
14000 +
14001 +static inline int __vx_info_map_pid(struct vx_info *vxi, int pid,
14002 +       const char *func, const char *file, int line)
14003 +{
14004 +       if (vx_info_flags(vxi, VXF_INFO_INIT, 0)) {
14005 +               vxfprintk(VXD_CBIT(cvirt, 2),
14006 +                       "vx_map_tgid: %p/%llx: %d -> %d",
14007 +                       vxi, (long long)vxi->vx_flags, pid,
14008 +                       (pid && pid == vxi->vx_initpid) ? 1 : pid,
14009 +                       func, file, line);
14010 +               if (pid == 0)
14011 +                       return 0;
14012 +               if (pid == vxi->vx_initpid)
14013 +                       return 1;
14014 +       }
14015 +       return pid;
14016 +}
14017 +
14018 +#define vx_info_rmap_pid(v, p) \
14019 +       __vx_info_rmap_pid((v), (p), __func__, __FILE__, __LINE__)
14020 +#define vx_rmap_pid(p) vx_info_rmap_pid(current_vx_info(), p)
14021 +#define vx_rmap_tgid(p) vx_rmap_pid(p)
14022 +
14023 +static inline int __vx_info_rmap_pid(struct vx_info *vxi, int pid,
14024 +       const char *func, const char *file, int line)
14025 +{
14026 +       if (vx_info_flags(vxi, VXF_INFO_INIT, 0)) {
14027 +               vxfprintk(VXD_CBIT(cvirt, 2),
14028 +                       "vx_rmap_tgid: %p/%llx: %d -> %d",
14029 +                       vxi, (long long)vxi->vx_flags, pid,
14030 +                       (pid == 1) ? vxi->vx_initpid : pid,
14031 +                       func, file, line);
14032 +               if ((pid == 1) && vxi->vx_initpid)
14033 +                       return vxi->vx_initpid;
14034 +               if (pid == vxi->vx_initpid)
14035 +                       return ~0U;
14036 +       }
14037 +       return pid;
14038 +}
14039 +
14040 +#endif
14041 diff -NurpP --minimal linux-2.6.38.3/include/linux/vserver/sched.h linux-2.6.38.3-vs2.3.0.37-rc14/include/linux/vserver/sched.h
14042 --- linux-2.6.38.3/include/linux/vserver/sched.h        1970-01-01 01:00:00.000000000 +0100
14043 +++ linux-2.6.38.3-vs2.3.0.37-rc14/include/linux/vserver/sched.h        2011-01-29 02:01:07.000000000 +0100
14044 @@ -0,0 +1,23 @@
14045 +#ifndef _VX_SCHED_H
14046 +#define _VX_SCHED_H
14047 +
14048 +
14049 +#ifdef __KERNEL__
14050 +
14051 +struct timespec;
14052 +
14053 +void vx_vsi_uptime(struct timespec *, struct timespec *);
14054 +
14055 +
14056 +struct vx_info;
14057 +
14058 +void vx_update_load(struct vx_info *);
14059 +
14060 +
14061 +void vx_update_sched_param(struct _vx_sched *sched,
14062 +       struct _vx_sched_pc *sched_pc);
14063 +
14064 +#endif /* __KERNEL__ */
14065 +#else  /* _VX_SCHED_H */
14066 +#warning duplicate inclusion
14067 +#endif /* _VX_SCHED_H */
14068 diff -NurpP --minimal linux-2.6.38.3/include/linux/vserver/sched_cmd.h linux-2.6.38.3-vs2.3.0.37-rc14/include/linux/vserver/sched_cmd.h
14069 --- linux-2.6.38.3/include/linux/vserver/sched_cmd.h    1970-01-01 01:00:00.000000000 +0100
14070 +++ linux-2.6.38.3-vs2.3.0.37-rc14/include/linux/vserver/sched_cmd.h    2011-01-29 02:01:07.000000000 +0100
14071 @@ -0,0 +1,21 @@
14072 +#ifndef _VX_SCHED_CMD_H
14073 +#define _VX_SCHED_CMD_H
14074 +
14075 +
14076 +struct vcmd_prio_bias {
14077 +       int32_t cpu_id;
14078 +       int32_t prio_bias;
14079 +};
14080 +
14081 +#define VCMD_set_prio_bias     VC_CMD(SCHED, 4, 0)
14082 +#define VCMD_get_prio_bias     VC_CMD(SCHED, 5, 0)
14083 +
14084 +#ifdef __KERNEL__
14085 +
14086 +#include <linux/compiler.h>
14087 +
14088 +extern int vc_set_prio_bias(struct vx_info *, void __user *);
14089 +extern int vc_get_prio_bias(struct vx_info *, void __user *);
14090 +
14091 +#endif /* __KERNEL__ */
14092 +#endif /* _VX_SCHED_CMD_H */
14093 diff -NurpP --minimal linux-2.6.38.3/include/linux/vserver/sched_def.h linux-2.6.38.3-vs2.3.0.37-rc14/include/linux/vserver/sched_def.h
14094 --- linux-2.6.38.3/include/linux/vserver/sched_def.h    1970-01-01 01:00:00.000000000 +0100
14095 +++ linux-2.6.38.3-vs2.3.0.37-rc14/include/linux/vserver/sched_def.h    2011-01-29 02:01:07.000000000 +0100
14096 @@ -0,0 +1,38 @@
14097 +#ifndef _VX_SCHED_DEF_H
14098 +#define _VX_SCHED_DEF_H
14099 +
14100 +#include <linux/spinlock.h>
14101 +#include <linux/jiffies.h>
14102 +#include <linux/cpumask.h>
14103 +#include <asm/atomic.h>
14104 +#include <asm/param.h>
14105 +
14106 +
14107 +/* context sub struct */
14108 +
14109 +struct _vx_sched {
14110 +       int prio_bias;                  /* bias offset for priority */
14111 +
14112 +       cpumask_t update;               /* CPUs which should update */
14113 +};
14114 +
14115 +struct _vx_sched_pc {
14116 +       int prio_bias;                  /* bias offset for priority */
14117 +
14118 +       uint64_t user_ticks;            /* token tick events */
14119 +       uint64_t sys_ticks;             /* token tick events */
14120 +       uint64_t hold_ticks;            /* token ticks paused */
14121 +};
14122 +
14123 +
14124 +#ifdef CONFIG_VSERVER_DEBUG
14125 +
14126 +static inline void __dump_vx_sched(struct _vx_sched *sched)
14127 +{
14128 +       printk("\t_vx_sched:\n");
14129 +       printk("\t priority = %4d\n", sched->prio_bias);
14130 +}
14131 +
14132 +#endif
14133 +
14134 +#endif /* _VX_SCHED_DEF_H */
14135 diff -NurpP --minimal linux-2.6.38.3/include/linux/vserver/signal.h linux-2.6.38.3-vs2.3.0.37-rc14/include/linux/vserver/signal.h
14136 --- linux-2.6.38.3/include/linux/vserver/signal.h       1970-01-01 01:00:00.000000000 +0100
14137 +++ linux-2.6.38.3-vs2.3.0.37-rc14/include/linux/vserver/signal.h       2011-01-29 02:01:07.000000000 +0100
14138 @@ -0,0 +1,14 @@
14139 +#ifndef _VX_SIGNAL_H
14140 +#define _VX_SIGNAL_H
14141 +
14142 +
14143 +#ifdef __KERNEL__
14144 +
14145 +struct vx_info;
14146 +
14147 +int vx_info_kill(struct vx_info *, int, int);
14148 +
14149 +#endif /* __KERNEL__ */
14150 +#else  /* _VX_SIGNAL_H */
14151 +#warning duplicate inclusion
14152 +#endif /* _VX_SIGNAL_H */
14153 diff -NurpP --minimal linux-2.6.38.3/include/linux/vserver/signal_cmd.h linux-2.6.38.3-vs2.3.0.37-rc14/include/linux/vserver/signal_cmd.h
14154 --- linux-2.6.38.3/include/linux/vserver/signal_cmd.h   1970-01-01 01:00:00.000000000 +0100
14155 +++ linux-2.6.38.3-vs2.3.0.37-rc14/include/linux/vserver/signal_cmd.h   2011-01-29 02:01:07.000000000 +0100
14156 @@ -0,0 +1,43 @@
14157 +#ifndef _VX_SIGNAL_CMD_H
14158 +#define _VX_SIGNAL_CMD_H
14159 +
14160 +
14161 +/*  signalling vserver commands */
14162 +
14163 +#define VCMD_ctx_kill          VC_CMD(PROCTRL, 1, 0)
14164 +#define VCMD_wait_exit         VC_CMD(EVENT, 99, 0)
14165 +
14166 +struct vcmd_ctx_kill_v0 {
14167 +       int32_t pid;
14168 +       int32_t sig;
14169 +};
14170 +
14171 +struct vcmd_wait_exit_v0 {
14172 +       int32_t reboot_cmd;
14173 +       int32_t exit_code;
14174 +};
14175 +
14176 +#ifdef __KERNEL__
14177 +
14178 +extern int vc_ctx_kill(struct vx_info *, void __user *);
14179 +extern int vc_wait_exit(struct vx_info *, void __user *);
14180 +
14181 +#endif /* __KERNEL__ */
14182 +
14183 +/*  process alteration commands */
14184 +
14185 +#define VCMD_get_pflags                VC_CMD(PROCALT, 5, 0)
14186 +#define VCMD_set_pflags                VC_CMD(PROCALT, 6, 0)
14187 +
14188 +struct vcmd_pflags_v0 {
14189 +       uint32_t flagword;
14190 +       uint32_t mask;
14191 +};
14192 +
14193 +#ifdef __KERNEL__
14194 +
14195 +extern int vc_get_pflags(uint32_t pid, void __user *);
14196 +extern int vc_set_pflags(uint32_t pid, void __user *);
14197 +
14198 +#endif /* __KERNEL__ */
14199 +#endif /* _VX_SIGNAL_CMD_H */
14200 diff -NurpP --minimal linux-2.6.38.3/include/linux/vserver/space.h linux-2.6.38.3-vs2.3.0.37-rc14/include/linux/vserver/space.h
14201 --- linux-2.6.38.3/include/linux/vserver/space.h        1970-01-01 01:00:00.000000000 +0100
14202 +++ linux-2.6.38.3-vs2.3.0.37-rc14/include/linux/vserver/space.h        2011-01-29 02:01:07.000000000 +0100
14203 @@ -0,0 +1,12 @@
14204 +#ifndef _VX_SPACE_H
14205 +#define _VX_SPACE_H
14206 +
14207 +#include <linux/types.h>
14208 +
14209 +struct vx_info;
14210 +
14211 +int vx_set_space(struct vx_info *vxi, unsigned long mask, unsigned index);
14212 +
14213 +#else  /* _VX_SPACE_H */
14214 +#warning duplicate inclusion
14215 +#endif /* _VX_SPACE_H */
14216 diff -NurpP --minimal linux-2.6.38.3/include/linux/vserver/space_cmd.h linux-2.6.38.3-vs2.3.0.37-rc14/include/linux/vserver/space_cmd.h
14217 --- linux-2.6.38.3/include/linux/vserver/space_cmd.h    1970-01-01 01:00:00.000000000 +0100
14218 +++ linux-2.6.38.3-vs2.3.0.37-rc14/include/linux/vserver/space_cmd.h    2011-01-29 02:01:07.000000000 +0100
14219 @@ -0,0 +1,38 @@
14220 +#ifndef _VX_SPACE_CMD_H
14221 +#define _VX_SPACE_CMD_H
14222 +
14223 +
14224 +#define VCMD_enter_space_v0    VC_CMD(PROCALT, 1, 0)
14225 +#define VCMD_enter_space_v1    VC_CMD(PROCALT, 1, 1)
14226 +#define VCMD_enter_space       VC_CMD(PROCALT, 1, 2)
14227 +
14228 +#define VCMD_set_space_v0      VC_CMD(PROCALT, 3, 0)
14229 +#define VCMD_set_space_v1      VC_CMD(PROCALT, 3, 1)
14230 +#define VCMD_set_space         VC_CMD(PROCALT, 3, 2)
14231 +
14232 +#define VCMD_get_space_mask_v0 VC_CMD(PROCALT, 4, 0)
14233 +
14234 +#define VCMD_get_space_mask    VC_CMD(VSPACE, 0, 1)
14235 +#define VCMD_get_space_default VC_CMD(VSPACE, 1, 0)
14236 +
14237 +
14238 +struct vcmd_space_mask_v1 {
14239 +       uint64_t mask;
14240 +};
14241 +
14242 +struct vcmd_space_mask_v2 {
14243 +       uint64_t mask;
14244 +       uint32_t index;
14245 +};
14246 +
14247 +
14248 +#ifdef __KERNEL__
14249 +
14250 +extern int vc_enter_space_v1(struct vx_info *, void __user *);
14251 +extern int vc_set_space_v1(struct vx_info *, void __user *);
14252 +extern int vc_enter_space(struct vx_info *, void __user *);
14253 +extern int vc_set_space(struct vx_info *, void __user *);
14254 +extern int vc_get_space_mask(void __user *, int);
14255 +
14256 +#endif /* __KERNEL__ */
14257 +#endif /* _VX_SPACE_CMD_H */
14258 diff -NurpP --minimal linux-2.6.38.3/include/linux/vserver/switch.h linux-2.6.38.3-vs2.3.0.37-rc14/include/linux/vserver/switch.h
14259 --- linux-2.6.38.3/include/linux/vserver/switch.h       1970-01-01 01:00:00.000000000 +0100
14260 +++ linux-2.6.38.3-vs2.3.0.37-rc14/include/linux/vserver/switch.h       2011-01-29 02:01:07.000000000 +0100
14261 @@ -0,0 +1,98 @@
14262 +#ifndef _VX_SWITCH_H
14263 +#define _VX_SWITCH_H
14264 +
14265 +#include <linux/types.h>
14266 +
14267 +
14268 +#define VC_CATEGORY(c)         (((c) >> 24) & 0x3F)
14269 +#define VC_COMMAND(c)          (((c) >> 16) & 0xFF)
14270 +#define VC_VERSION(c)          ((c) & 0xFFF)
14271 +
14272 +#define VC_CMD(c, i, v)                ((((VC_CAT_ ## c) & 0x3F) << 24) \
14273 +                               | (((i) & 0xFF) << 16) | ((v) & 0xFFF))
14274 +
14275 +/*
14276 +
14277 +  Syscall Matrix V2.8
14278 +
14279 +        |VERSION|CREATE |MODIFY |MIGRATE|CONTROL|EXPERIM| |SPECIAL|SPECIAL|
14280 +        |STATS  |DESTROY|ALTER  |CHANGE |LIMIT  |TEST   | |       |       |
14281 +        |INFO   |SETUP  |       |MOVE   |       |       | |       |       |
14282 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
14283 +  SYSTEM |VERSION|VSETUP |VHOST  |       |       |       | |DEVICE |       |
14284 +  HOST   |     00|     01|     02|     03|     04|     05| |     06|     07|
14285 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
14286 +  CPU    |       |VPROC  |PROCALT|PROCMIG|PROCTRL|       | |SCHED. |       |
14287 +  PROCESS|     08|     09|     10|     11|     12|     13| |     14|     15|
14288 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
14289 +  MEMORY |       |       |       |       |MEMCTRL|       | |SWAP   |       |
14290 +        |     16|     17|     18|     19|     20|     21| |     22|     23|
14291 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
14292 +  NETWORK|       |VNET   |NETALT |NETMIG |NETCTL |       | |SERIAL |       |
14293 +        |     24|     25|     26|     27|     28|     29| |     30|     31|
14294 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
14295 +  DISK   |       |       |       |TAGMIG |DLIMIT |       | |INODE  |       |
14296 +  VFS    |     32|     33|     34|     35|     36|     37| |     38|     39|
14297 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
14298 +  OTHER  |VSTAT  |       |       |       |       |       | |VINFO  |       |
14299 +        |     40|     41|     42|     43|     44|     45| |     46|     47|
14300 +  =======+=======+=======+=======+=======+=======+=======+ +=======+=======+
14301 +  SPECIAL|EVENT  |       |       |       |FLAGS  |       | |VSPACE |       |
14302 +        |     48|     49|     50|     51|     52|     53| |     54|     55|
14303 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
14304 +  SPECIAL|DEBUG  |       |       |       |RLIMIT |SYSCALL| |       |COMPAT |
14305 +        |     56|     57|     58|     59|     60|TEST 61| |     62|     63|
14306 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
14307 +
14308 +*/
14309 +
14310 +#define VC_CAT_VERSION         0
14311 +
14312 +#define VC_CAT_VSETUP          1
14313 +#define VC_CAT_VHOST           2
14314 +
14315 +#define VC_CAT_DEVICE          6
14316 +
14317 +#define VC_CAT_VPROC           9
14318 +#define VC_CAT_PROCALT         10
14319 +#define VC_CAT_PROCMIG         11
14320 +#define VC_CAT_PROCTRL         12
14321 +
14322 +#define VC_CAT_SCHED           14
14323 +#define VC_CAT_MEMCTRL         20
14324 +
14325 +#define VC_CAT_VNET            25
14326 +#define VC_CAT_NETALT          26
14327 +#define VC_CAT_NETMIG          27
14328 +#define VC_CAT_NETCTRL         28
14329 +
14330 +#define VC_CAT_TAGMIG          35
14331 +#define VC_CAT_DLIMIT          36
14332 +#define VC_CAT_INODE           38
14333 +
14334 +#define VC_CAT_VSTAT           40
14335 +#define VC_CAT_VINFO           46
14336 +#define VC_CAT_EVENT           48
14337 +
14338 +#define VC_CAT_FLAGS           52
14339 +#define VC_CAT_VSPACE          54
14340 +#define VC_CAT_DEBUG           56
14341 +#define VC_CAT_RLIMIT          60
14342 +
14343 +#define VC_CAT_SYSTEST         61
14344 +#define VC_CAT_COMPAT          63
14345 +
14346 +/*  query version */
14347 +
14348 +#define VCMD_get_version       VC_CMD(VERSION, 0, 0)
14349 +#define VCMD_get_vci           VC_CMD(VERSION, 1, 0)
14350 +
14351 +
14352 +#ifdef __KERNEL__
14353 +
14354 +#include <linux/errno.h>
14355 +
14356 +#endif /* __KERNEL__ */
14357 +
14358 +#endif /* _VX_SWITCH_H */
14359 +
14360 diff -NurpP --minimal linux-2.6.38.3/include/linux/vserver/tag.h linux-2.6.38.3-vs2.3.0.37-rc14/include/linux/vserver/tag.h
14361 --- linux-2.6.38.3/include/linux/vserver/tag.h  1970-01-01 01:00:00.000000000 +0100
14362 +++ linux-2.6.38.3-vs2.3.0.37-rc14/include/linux/vserver/tag.h  2011-01-29 02:01:07.000000000 +0100
14363 @@ -0,0 +1,143 @@
14364 +#ifndef _DX_TAG_H
14365 +#define _DX_TAG_H
14366 +
14367 +#include <linux/types.h>
14368 +
14369 +
14370 +#define DX_TAG(in)     (IS_TAGGED(in))
14371 +
14372 +
14373 +#ifdef CONFIG_TAG_NFSD
14374 +#define DX_TAG_NFSD    1
14375 +#else
14376 +#define DX_TAG_NFSD    0
14377 +#endif
14378 +
14379 +
14380 +#ifdef CONFIG_TAGGING_NONE
14381 +
14382 +#define MAX_UID                0xFFFFFFFF
14383 +#define MAX_GID                0xFFFFFFFF
14384 +
14385 +#define INOTAG_TAG(cond, uid, gid, tag)        (0)
14386 +
14387 +#define TAGINO_UID(cond, uid, tag)     (uid)
14388 +#define TAGINO_GID(cond, gid, tag)     (gid)
14389 +
14390 +#endif
14391 +
14392 +
14393 +#ifdef CONFIG_TAGGING_GID16
14394 +
14395 +#define MAX_UID                0xFFFFFFFF
14396 +#define MAX_GID                0x0000FFFF
14397 +
14398 +#define INOTAG_TAG(cond, uid, gid, tag)        \
14399 +       ((cond) ? (((gid) >> 16) & 0xFFFF) : 0)
14400 +
14401 +#define TAGINO_UID(cond, uid, tag)     (uid)
14402 +#define TAGINO_GID(cond, gid, tag)     \
14403 +       ((cond) ? (((gid) & 0xFFFF) | ((tag) << 16)) : (gid))
14404 +
14405 +#endif
14406 +
14407 +
14408 +#ifdef CONFIG_TAGGING_ID24
14409 +
14410 +#define MAX_UID                0x00FFFFFF
14411 +#define MAX_GID                0x00FFFFFF
14412 +
14413 +#define INOTAG_TAG(cond, uid, gid, tag)        \
14414 +       ((cond) ? ((((uid) >> 16) & 0xFF00) | (((gid) >> 24) & 0xFF)) : 0)
14415 +
14416 +#define TAGINO_UID(cond, uid, tag)     \
14417 +       ((cond) ? (((uid) & 0xFFFFFF) | (((tag) & 0xFF00) << 16)) : (uid))
14418 +#define TAGINO_GID(cond, gid, tag)     \
14419 +       ((cond) ? (((gid) & 0xFFFFFF) | (((tag) & 0x00FF) << 24)) : (gid))
14420 +
14421 +#endif
14422 +
14423 +
14424 +#ifdef CONFIG_TAGGING_UID16
14425 +
14426 +#define MAX_UID                0x0000FFFF
14427 +#define MAX_GID                0xFFFFFFFF
14428 +
14429 +#define INOTAG_TAG(cond, uid, gid, tag)        \
14430 +       ((cond) ? (((uid) >> 16) & 0xFFFF) : 0)
14431 +
14432 +#define TAGINO_UID(cond, uid, tag)     \
14433 +       ((cond) ? (((uid) & 0xFFFF) | ((tag) << 16)) : (uid))
14434 +#define TAGINO_GID(cond, gid, tag)     (gid)
14435 +
14436 +#endif
14437 +
14438 +
14439 +#ifdef CONFIG_TAGGING_INTERN
14440 +
14441 +#define MAX_UID                0xFFFFFFFF
14442 +#define MAX_GID                0xFFFFFFFF
14443 +
14444 +#define INOTAG_TAG(cond, uid, gid, tag)        \
14445 +       ((cond) ? (tag) : 0)
14446 +
14447 +#define TAGINO_UID(cond, uid, tag)     (uid)
14448 +#define TAGINO_GID(cond, gid, tag)     (gid)
14449 +
14450 +#endif
14451 +
14452 +
14453 +#ifndef CONFIG_TAGGING_NONE
14454 +#define dx_current_fstag(sb)   \
14455 +       ((sb)->s_flags & MS_TAGGED ? dx_current_tag() : 0)
14456 +#else
14457 +#define dx_current_fstag(sb)   (0)
14458 +#endif
14459 +
14460 +#ifndef CONFIG_TAGGING_INTERN
14461 +#define TAGINO_TAG(cond, tag)  (0)
14462 +#else
14463 +#define TAGINO_TAG(cond, tag)  ((cond) ? (tag) : 0)
14464 +#endif
14465 +
14466 +#define INOTAG_UID(cond, uid, gid)     \
14467 +       ((cond) ? ((uid) & MAX_UID) : (uid))
14468 +#define INOTAG_GID(cond, uid, gid)     \
14469 +       ((cond) ? ((gid) & MAX_GID) : (gid))
14470 +
14471 +
14472 +static inline uid_t dx_map_uid(uid_t uid)
14473 +{
14474 +       if ((uid > MAX_UID) && (uid != -1))
14475 +               uid = -2;
14476 +       return (uid & MAX_UID);
14477 +}
14478 +
14479 +static inline gid_t dx_map_gid(gid_t gid)
14480 +{
14481 +       if ((gid > MAX_GID) && (gid != -1))
14482 +               gid = -2;
14483 +       return (gid & MAX_GID);
14484 +}
14485 +
14486 +struct peer_tag {
14487 +       int32_t xid;
14488 +       int32_t nid;
14489 +};
14490 +
14491 +#define dx_notagcheck(sb) ((sb) && ((sb)->s_flags & MS_NOTAGCHECK))
14492 +
14493 +int dx_parse_tag(char *string, tag_t *tag, int remove, int *mnt_flags,
14494 +                unsigned long *flags);
14495 +
14496 +#ifdef CONFIG_PROPAGATE
14497 +
14498 +void __dx_propagate_tag(struct nameidata *nd, struct inode *inode);
14499 +
14500 +#define dx_propagate_tag(n, i) __dx_propagate_tag(n, i)
14501 +
14502 +#else
14503 +#define dx_propagate_tag(n, i) do { } while (0)
14504 +#endif
14505 +
14506 +#endif /* _DX_TAG_H */
14507 diff -NurpP --minimal linux-2.6.38.3/include/linux/vserver/tag_cmd.h linux-2.6.38.3-vs2.3.0.37-rc14/include/linux/vserver/tag_cmd.h
14508 --- linux-2.6.38.3/include/linux/vserver/tag_cmd.h      1970-01-01 01:00:00.000000000 +0100
14509 +++ linux-2.6.38.3-vs2.3.0.37-rc14/include/linux/vserver/tag_cmd.h      2011-01-29 02:01:07.000000000 +0100
14510 @@ -0,0 +1,22 @@
14511 +#ifndef _VX_TAG_CMD_H
14512 +#define _VX_TAG_CMD_H
14513 +
14514 +
14515 +/* vinfo commands */
14516 +
14517 +#define VCMD_task_tag          VC_CMD(VINFO, 3, 0)
14518 +
14519 +#ifdef __KERNEL__
14520 +extern int vc_task_tag(uint32_t);
14521 +
14522 +#endif /* __KERNEL__ */
14523 +
14524 +/* context commands */
14525 +
14526 +#define VCMD_tag_migrate       VC_CMD(TAGMIG, 1, 0)
14527 +
14528 +#ifdef __KERNEL__
14529 +extern int vc_tag_migrate(uint32_t);
14530 +
14531 +#endif /* __KERNEL__ */
14532 +#endif /* _VX_TAG_CMD_H */
14533 diff -NurpP --minimal linux-2.6.38.3/include/net/addrconf.h linux-2.6.38.3-vs2.3.0.37-rc14/include/net/addrconf.h
14534 --- linux-2.6.38.3/include/net/addrconf.h       2011-03-15 18:07:40.000000000 +0100
14535 +++ linux-2.6.38.3-vs2.3.0.37-rc14/include/net/addrconf.h       2011-01-29 02:01:07.000000000 +0100
14536 @@ -82,7 +82,8 @@ extern int                    ipv6_dev_get_saddr(struct n
14537                                                struct net_device *dev,
14538                                                const struct in6_addr *daddr,
14539                                                unsigned int srcprefs,
14540 -                                              struct in6_addr *saddr);
14541 +                                              struct in6_addr *saddr,
14542 +                                              struct nx_info *nxi);
14543  extern int                     ipv6_get_lladdr(struct net_device *dev,
14544                                                 struct in6_addr *addr,
14545                                                 unsigned char banned_flags);
14546 diff -NurpP --minimal linux-2.6.38.3/include/net/af_unix.h linux-2.6.38.3-vs2.3.0.37-rc14/include/net/af_unix.h
14547 --- linux-2.6.38.3/include/net/af_unix.h        2011-01-05 21:50:35.000000000 +0100
14548 +++ linux-2.6.38.3-vs2.3.0.37-rc14/include/net/af_unix.h        2011-01-29 02:01:07.000000000 +0100
14549 @@ -4,6 +4,7 @@
14550  #include <linux/socket.h>
14551  #include <linux/un.h>
14552  #include <linux/mutex.h>
14553 +#include <linux/vs_base.h>
14554  #include <net/sock.h>
14555  
14556  extern void unix_inflight(struct file *fp);
14557 diff -NurpP --minimal linux-2.6.38.3/include/net/inet_timewait_sock.h linux-2.6.38.3-vs2.3.0.37-rc14/include/net/inet_timewait_sock.h
14558 --- linux-2.6.38.3/include/net/inet_timewait_sock.h     2011-03-15 18:07:40.000000000 +0100
14559 +++ linux-2.6.38.3-vs2.3.0.37-rc14/include/net/inet_timewait_sock.h     2011-01-29 03:12:58.000000000 +0100
14560 @@ -113,6 +113,10 @@ struct inet_timewait_sock {
14561  #define tw_net                 __tw_common.skc_net
14562  #define tw_daddr               __tw_common.skc_daddr
14563  #define tw_rcv_saddr           __tw_common.skc_rcv_saddr
14564 +#define tw_xid                 __tw_common.skc_xid
14565 +#define tw_vx_info             __tw_common.skc_vx_info
14566 +#define tw_nid                 __tw_common.skc_nid
14567 +#define tw_nx_info             __tw_common.skc_nx_info
14568         int                     tw_timeout;
14569         volatile unsigned char  tw_substate;
14570         unsigned char           tw_rcv_wscale;
14571 diff -NurpP --minimal linux-2.6.38.3/include/net/route.h linux-2.6.38.3-vs2.3.0.37-rc14/include/net/route.h
14572 --- linux-2.6.38.3/include/net/route.h  2011-03-15 18:07:40.000000000 +0100
14573 +++ linux-2.6.38.3-vs2.3.0.37-rc14/include/net/route.h  2011-01-29 02:01:07.000000000 +0100
14574 @@ -153,6 +153,9 @@ static inline void ip_rt_put(struct rtab
14575                 dst_release(&rt->dst);
14576  }
14577  
14578 +#include <linux/vs_base.h>
14579 +#include <linux/vs_inet.h>
14580 +
14581  #define IPTOS_RT_MASK  (IPTOS_TOS_MASK & ~3)
14582  
14583  extern const __u8 ip_tos2prio[16];
14584 @@ -162,6 +165,9 @@ static inline char rt_tos2priority(u8 to
14585         return ip_tos2prio[IPTOS_TOS(tos)>>1];
14586  }
14587  
14588 +extern int ip_v4_find_src(struct net *net, struct nx_info *,
14589 +       struct rtable **, struct flowi *);
14590 +
14591  static inline int ip_route_connect(struct rtable **rp, __be32 dst,
14592                                    __be32 src, u32 tos, int oif, u8 protocol,
14593                                    __be16 sport, __be16 dport, struct sock *sk,
14594 @@ -177,11 +183,24 @@ static inline int ip_route_connect(struc
14595                             .fl_ip_dport = dport };
14596         int err;
14597         struct net *net = sock_net(sk);
14598 +       struct nx_info *nx_info = current_nx_info();
14599  
14600         if (inet_sk(sk)->transparent)
14601                 fl.flags |= FLOWI_FLAG_ANYSRC;
14602  
14603 -       if (!dst || !src) {
14604 +       if (sk)
14605 +               nx_info = sk->sk_nx_info;
14606 +
14607 +       vxdprintk(VXD_CBIT(net, 4),
14608 +               "ip_route_connect(%p) %p,%p;%lx",
14609 +               sk, nx_info, sk->sk_socket,
14610 +               (sk->sk_socket?sk->sk_socket->flags:0));
14611 +
14612 +       err = ip_v4_find_src(net, nx_info, rp, &fl);
14613 +       if (err)
14614 +               return err;
14615 +
14616 +       if (!fl.fl4_dst || !fl.fl4_src) {
14617                 err = __ip_route_output_key(net, rp, &fl);
14618                 if (err)
14619                         return err;
14620 diff -NurpP --minimal linux-2.6.38.3/include/net/sock.h linux-2.6.38.3-vs2.3.0.37-rc14/include/net/sock.h
14621 --- linux-2.6.38.3/include/net/sock.h   2011-03-15 18:07:41.000000000 +0100
14622 +++ linux-2.6.38.3-vs2.3.0.37-rc14/include/net/sock.h   2011-02-17 02:17:51.000000000 +0100
14623 @@ -148,6 +148,10 @@ struct sock_common {
14624  #ifdef CONFIG_NET_NS
14625         struct net              *skc_net;
14626  #endif
14627 +       xid_t                   skc_xid;
14628 +       struct vx_info          *skc_vx_info;
14629 +       nid_t                   skc_nid;
14630 +       struct nx_info          *skc_nx_info;
14631         /*
14632          * fields between dontcopy_begin/dontcopy_end
14633          * are not copied in sock_copy()
14634 @@ -256,6 +260,10 @@ struct sock {
14635  #define sk_bind_node           __sk_common.skc_bind_node
14636  #define sk_prot                        __sk_common.skc_prot
14637  #define sk_net                 __sk_common.skc_net
14638 +#define sk_xid                 __sk_common.skc_xid
14639 +#define sk_vx_info             __sk_common.skc_vx_info
14640 +#define sk_nid                 __sk_common.skc_nid
14641 +#define sk_nx_info             __sk_common.skc_nx_info
14642         socket_lock_t           sk_lock;
14643         struct sk_buff_head     sk_receive_queue;
14644         /*
14645 diff -NurpP --minimal linux-2.6.38.3/init/Kconfig linux-2.6.38.3-vs2.3.0.37-rc14/init/Kconfig
14646 --- linux-2.6.38.3/init/Kconfig 2011-03-15 18:07:41.000000000 +0100
14647 +++ linux-2.6.38.3-vs2.3.0.37-rc14/init/Kconfig 2011-01-29 02:01:07.000000000 +0100
14648 @@ -559,6 +559,7 @@ config HAVE_UNSTABLE_SCHED_CLOCK
14649  menuconfig CGROUPS
14650         boolean "Control Group support"
14651         depends on EVENTFD
14652 +       default y
14653         help
14654           This option adds support for grouping sets of processes together, for
14655           use with process control subsystems such as Cpusets, CFS, memory
14656 @@ -584,6 +585,7 @@ config CGROUP_DEBUG
14657  
14658  config CGROUP_NS
14659         bool "Namespace cgroup subsystem"
14660 +       default n
14661         help
14662           Provides a simple namespace cgroup subsystem to
14663           provide hierarchical naming of sets of namespaces,
14664 diff -NurpP --minimal linux-2.6.38.3/init/main.c linux-2.6.38.3-vs2.3.0.37-rc14/init/main.c
14665 --- linux-2.6.38.3/init/main.c  2011-03-15 18:07:41.000000000 +0100
14666 +++ linux-2.6.38.3-vs2.3.0.37-rc14/init/main.c  2011-01-29 02:21:25.000000000 +0100
14667 @@ -68,6 +68,7 @@
14668  #include <linux/shmem_fs.h>
14669  #include <linux/slab.h>
14670  #include <linux/perf_event.h>
14671 +#include <linux/vserver/percpu.h>
14672  
14673  #include <asm/io.h>
14674  #include <asm/bugs.h>
14675 diff -NurpP --minimal linux-2.6.38.3/ipc/mqueue.c linux-2.6.38.3-vs2.3.0.37-rc14/ipc/mqueue.c
14676 --- linux-2.6.38.3/ipc/mqueue.c 2011-03-15 18:07:41.000000000 +0100
14677 +++ linux-2.6.38.3-vs2.3.0.37-rc14/ipc/mqueue.c 2011-01-29 02:01:07.000000000 +0100
14678 @@ -33,6 +33,8 @@
14679  #include <linux/pid.h>
14680  #include <linux/ipc_namespace.h>
14681  #include <linux/slab.h>
14682 +#include <linux/vs_context.h>
14683 +#include <linux/vs_limit.h>
14684  
14685  #include <net/sock.h>
14686  #include "util.h"
14687 @@ -66,6 +68,7 @@ struct mqueue_inode_info {
14688         struct sigevent notify;
14689         struct pid* notify_owner;
14690         struct user_struct *user;       /* user who created, for accounting */
14691 +       struct vx_info *vxi;
14692         struct sock *notify_sock;
14693         struct sk_buff *notify_cookie;
14694  
14695 @@ -126,6 +129,7 @@ static struct inode *mqueue_get_inode(st
14696                 if (S_ISREG(mode)) {
14697                         struct mqueue_inode_info *info;
14698                         struct task_struct *p = current;
14699 +                       struct vx_info *vxi = p->vx_info;
14700                         unsigned long mq_bytes, mq_msg_tblsz;
14701  
14702                         inode->i_fop = &mqueue_file_operations;
14703 @@ -139,6 +143,7 @@ static struct inode *mqueue_get_inode(st
14704                         info->notify_owner = NULL;
14705                         info->qsize = 0;
14706                         info->user = NULL;      /* set when all is ok */
14707 +                       info->vxi = NULL;
14708                         memset(&info->attr, 0, sizeof(info->attr));
14709                         info->attr.mq_maxmsg = ipc_ns->mq_msg_max;
14710                         info->attr.mq_msgsize = ipc_ns->mq_msgsize_max;
14711 @@ -157,16 +162,19 @@ static struct inode *mqueue_get_inode(st
14712                         spin_lock(&mq_lock);
14713                         if (u->mq_bytes + mq_bytes < u->mq_bytes ||
14714                             u->mq_bytes + mq_bytes >
14715 -                           task_rlimit(p, RLIMIT_MSGQUEUE)) {
14716 +                           task_rlimit(p, RLIMIT_MSGQUEUE) ||
14717 +                           !vx_ipcmsg_avail(vxi, mq_bytes)) {
14718                                 spin_unlock(&mq_lock);
14719                                 /* mqueue_evict_inode() releases info->messages */
14720                                 goto out_inode;
14721                         }
14722                         u->mq_bytes += mq_bytes;
14723 +                       vx_ipcmsg_add(vxi, u, mq_bytes);
14724                         spin_unlock(&mq_lock);
14725  
14726                         /* all is ok */
14727                         info->user = get_uid(u);
14728 +                       info->vxi = get_vx_info(vxi);
14729                 } else if (S_ISDIR(mode)) {
14730                         inc_nlink(inode);
14731                         /* Some things misbehave if size == 0 on a directory */
14732 @@ -275,8 +283,11 @@ static void mqueue_evict_inode(struct in
14733             + info->attr.mq_msgsize);
14734         user = info->user;
14735         if (user) {
14736 +               struct vx_info *vxi = info->vxi;
14737 +
14738                 spin_lock(&mq_lock);
14739                 user->mq_bytes -= mq_bytes;
14740 +               vx_ipcmsg_sub(vxi, user, mq_bytes);
14741                 /*
14742                  * get_ns_from_inode() ensures that the
14743                  * (ipc_ns = sb->s_fs_info) is either a valid ipc_ns
14744 @@ -286,6 +297,7 @@ static void mqueue_evict_inode(struct in
14745                 if (ipc_ns)
14746                         ipc_ns->mq_queues_count--;
14747                 spin_unlock(&mq_lock);
14748 +               put_vx_info(vxi);
14749                 free_uid(user);
14750         }
14751         if (ipc_ns)
14752 diff -NurpP --minimal linux-2.6.38.3/ipc/msg.c linux-2.6.38.3-vs2.3.0.37-rc14/ipc/msg.c
14753 --- linux-2.6.38.3/ipc/msg.c    2010-08-02 16:52:57.000000000 +0200
14754 +++ linux-2.6.38.3-vs2.3.0.37-rc14/ipc/msg.c    2011-01-29 02:01:07.000000000 +0100
14755 @@ -37,6 +37,7 @@
14756  #include <linux/rwsem.h>
14757  #include <linux/nsproxy.h>
14758  #include <linux/ipc_namespace.h>
14759 +#include <linux/vs_base.h>
14760  
14761  #include <asm/current.h>
14762  #include <asm/uaccess.h>
14763 @@ -190,6 +191,7 @@ static int newque(struct ipc_namespace *
14764  
14765         msq->q_perm.mode = msgflg & S_IRWXUGO;
14766         msq->q_perm.key = key;
14767 +       msq->q_perm.xid = vx_current_xid();
14768  
14769         msq->q_perm.security = NULL;
14770         retval = security_msg_queue_alloc(msq);
14771 diff -NurpP --minimal linux-2.6.38.3/ipc/namespace.c linux-2.6.38.3-vs2.3.0.37-rc14/ipc/namespace.c
14772 --- linux-2.6.38.3/ipc/namespace.c      2009-09-10 15:26:27.000000000 +0200
14773 +++ linux-2.6.38.3-vs2.3.0.37-rc14/ipc/namespace.c      2011-01-29 02:01:07.000000000 +0100
14774 @@ -11,6 +11,8 @@
14775  #include <linux/slab.h>
14776  #include <linux/fs.h>
14777  #include <linux/mount.h>
14778 +#include <linux/vs_base.h>
14779 +#include <linux/vserver/global.h>
14780  
14781  #include "util.h"
14782  
14783 diff -NurpP --minimal linux-2.6.38.3/ipc/sem.c linux-2.6.38.3-vs2.3.0.37-rc14/ipc/sem.c
14784 --- linux-2.6.38.3/ipc/sem.c    2010-10-21 13:07:56.000000000 +0200
14785 +++ linux-2.6.38.3-vs2.3.0.37-rc14/ipc/sem.c    2011-01-29 02:01:07.000000000 +0100
14786 @@ -86,6 +86,8 @@
14787  #include <linux/rwsem.h>
14788  #include <linux/nsproxy.h>
14789  #include <linux/ipc_namespace.h>
14790 +#include <linux/vs_base.h>
14791 +#include <linux/vs_limit.h>
14792  
14793  #include <asm/uaccess.h>
14794  #include "util.h"
14795 @@ -260,6 +262,7 @@ static int newary(struct ipc_namespace *
14796  
14797         sma->sem_perm.mode = (semflg & S_IRWXUGO);
14798         sma->sem_perm.key = key;
14799 +       sma->sem_perm.xid = vx_current_xid();
14800  
14801         sma->sem_perm.security = NULL;
14802         retval = security_sem_alloc(sma);
14803 @@ -275,6 +278,9 @@ static int newary(struct ipc_namespace *
14804                 return id;
14805         }
14806         ns->used_sems += nsems;
14807 +       /* FIXME: obsoleted? */
14808 +       vx_semary_inc(sma);
14809 +       vx_nsems_add(sma, nsems);
14810  
14811         sma->sem_base = (struct sem *) &sma[1];
14812  
14813 @@ -730,6 +736,9 @@ static void freeary(struct ipc_namespace
14814  
14815         wake_up_sem_queue_do(&tasks);
14816         ns->used_sems -= sma->sem_nsems;
14817 +       /* FIXME: obsoleted? */
14818 +       vx_nsems_sub(sma, sma->sem_nsems);
14819 +       vx_semary_dec(sma);
14820         security_sem_free(sma);
14821         ipc_rcu_putref(sma);
14822  }
14823 diff -NurpP --minimal linux-2.6.38.3/ipc/shm.c linux-2.6.38.3-vs2.3.0.37-rc14/ipc/shm.c
14824 --- linux-2.6.38.3/ipc/shm.c    2011-01-05 21:50:37.000000000 +0100
14825 +++ linux-2.6.38.3-vs2.3.0.37-rc14/ipc/shm.c    2011-01-29 02:01:07.000000000 +0100
14826 @@ -39,6 +39,8 @@
14827  #include <linux/nsproxy.h>
14828  #include <linux/mount.h>
14829  #include <linux/ipc_namespace.h>
14830 +#include <linux/vs_context.h>
14831 +#include <linux/vs_limit.h>
14832  
14833  #include <asm/uaccess.h>
14834  
14835 @@ -173,7 +175,12 @@ static void shm_open(struct vm_area_stru
14836   */
14837  static void shm_destroy(struct ipc_namespace *ns, struct shmid_kernel *shp)
14838  {
14839 -       ns->shm_tot -= (shp->shm_segsz + PAGE_SIZE - 1) >> PAGE_SHIFT;
14840 +       struct vx_info *vxi = lookup_vx_info(shp->shm_perm.xid);
14841 +       int numpages = (shp->shm_segsz + PAGE_SIZE - 1) >> PAGE_SHIFT;
14842 +
14843 +       vx_ipcshm_sub(vxi, shp, numpages);
14844 +       ns->shm_tot -= numpages;
14845 +
14846         shm_rmid(ns, shp);
14847         shm_unlock(shp);
14848         if (!is_file_hugepages(shp->shm_file))
14849 @@ -183,6 +190,7 @@ static void shm_destroy(struct ipc_names
14850                                                 shp->mlock_user);
14851         fput (shp->shm_file);
14852         security_shm_free(shp);
14853 +       put_vx_info(vxi);
14854         ipc_rcu_putref(shp);
14855  }
14856  
14857 @@ -355,11 +363,15 @@ static int newseg(struct ipc_namespace *
14858         if (ns->shm_tot + numpages > ns->shm_ctlall)
14859                 return -ENOSPC;
14860  
14861 +       if (!vx_ipcshm_avail(current_vx_info(), numpages))
14862 +               return -ENOSPC;
14863 +
14864         shp = ipc_rcu_alloc(sizeof(*shp));
14865         if (!shp)
14866                 return -ENOMEM;
14867  
14868         shp->shm_perm.key = key;
14869 +       shp->shm_perm.xid = vx_current_xid();
14870         shp->shm_perm.mode = (shmflg & S_IRWXUGO);
14871         shp->mlock_user = NULL;
14872  
14873 @@ -413,6 +425,7 @@ static int newseg(struct ipc_namespace *
14874         ns->shm_tot += numpages;
14875         error = shp->shm_perm.id;
14876         shm_unlock(shp);
14877 +       vx_ipcshm_add(current_vx_info(), key, numpages);
14878         return error;
14879  
14880  no_id:
14881 diff -NurpP --minimal linux-2.6.38.3/kernel/Makefile linux-2.6.38.3-vs2.3.0.37-rc14/kernel/Makefile
14882 --- linux-2.6.38.3/kernel/Makefile      2011-03-15 18:07:41.000000000 +0100
14883 +++ linux-2.6.38.3-vs2.3.0.37-rc14/kernel/Makefile      2011-01-29 02:01:07.000000000 +0100
14884 @@ -25,6 +25,7 @@ CFLAGS_REMOVE_perf_event.o = -pg
14885  CFLAGS_REMOVE_irq_work.o = -pg
14886  endif
14887  
14888 +obj-y += vserver/
14889  obj-$(CONFIG_FREEZER) += freezer.o
14890  obj-$(CONFIG_PROFILING) += profile.o
14891  obj-$(CONFIG_SYSCTL_SYSCALL_CHECK) += sysctl_check.o
14892 diff -NurpP --minimal linux-2.6.38.3/kernel/capability.c linux-2.6.38.3-vs2.3.0.37-rc14/kernel/capability.c
14893 --- linux-2.6.38.3/kernel/capability.c  2011-03-15 18:07:41.000000000 +0100
14894 +++ linux-2.6.38.3-vs2.3.0.37-rc14/kernel/capability.c  2011-02-17 02:17:51.000000000 +0100
14895 @@ -14,6 +14,7 @@
14896  #include <linux/security.h>
14897  #include <linux/syscalls.h>
14898  #include <linux/pid_namespace.h>
14899 +#include <linux/vs_context.h>
14900  #include <asm/uaccess.h>
14901  
14902  /*
14903 @@ -119,6 +120,7 @@ static int cap_validate_magic(cap_user_h
14904         return 0;
14905  }
14906  
14907 +
14908  /*
14909   * The only thing that can change the capabilities of the current
14910   * process is the current process. As such, we can't be in this code
14911 @@ -289,6 +291,8 @@ error:
14912         return ret;
14913  }
14914  
14915 +#include <linux/vserver/base.h>
14916 +
14917  /**
14918   * capable - Determine if the current task has a superior capability in effect
14919   * @cap: The capability to be tested for
14920 @@ -301,6 +305,9 @@ error:
14921   */
14922  int capable(int cap)
14923  {
14924 +       /* here for now so we don't require task locking */
14925 +       if (vs_check_bit(VXC_CAP_MASK, cap) && !vx_mcaps(1L << cap))
14926 +               return 0;
14927         if (unlikely(!cap_valid(cap))) {
14928                 printk(KERN_CRIT "capable() called with invalid cap=%u\n", cap);
14929                 BUG();
14930 diff -NurpP --minimal linux-2.6.38.3/kernel/compat.c linux-2.6.38.3-vs2.3.0.37-rc14/kernel/compat.c
14931 --- linux-2.6.38.3/kernel/compat.c      2010-10-21 13:07:56.000000000 +0200
14932 +++ linux-2.6.38.3-vs2.3.0.37-rc14/kernel/compat.c      2011-01-29 02:01:07.000000000 +0100
14933 @@ -914,7 +914,7 @@ asmlinkage long compat_sys_stime(compat_
14934         if (err)
14935                 return err;
14936  
14937 -       do_settimeofday(&tv);
14938 +       vx_settimeofday(&tv);
14939         return 0;
14940  }
14941  
14942 diff -NurpP --minimal linux-2.6.38.3/kernel/cred.c linux-2.6.38.3-vs2.3.0.37-rc14/kernel/cred.c
14943 --- linux-2.6.38.3/kernel/cred.c        2011-03-15 18:07:41.000000000 +0100
14944 +++ linux-2.6.38.3-vs2.3.0.37-rc14/kernel/cred.c        2011-02-17 02:17:51.000000000 +0100
14945 @@ -60,31 +60,6 @@ struct cred init_cred = {
14946  #endif
14947  };
14948  
14949 -static inline void set_cred_subscribers(struct cred *cred, int n)
14950 -{
14951 -#ifdef CONFIG_DEBUG_CREDENTIALS
14952 -       atomic_set(&cred->subscribers, n);
14953 -#endif
14954 -}
14955 -
14956 -static inline int read_cred_subscribers(const struct cred *cred)
14957 -{
14958 -#ifdef CONFIG_DEBUG_CREDENTIALS
14959 -       return atomic_read(&cred->subscribers);
14960 -#else
14961 -       return 0;
14962 -#endif
14963 -}
14964 -
14965 -static inline void alter_cred_subscribers(const struct cred *_cred, int n)
14966 -{
14967 -#ifdef CONFIG_DEBUG_CREDENTIALS
14968 -       struct cred *cred = (struct cred *) _cred;
14969 -
14970 -       atomic_add(n, &cred->subscribers);
14971 -#endif
14972 -}
14973 -
14974  /*
14975   * Dispose of the shared task group credentials
14976   */
14977 @@ -280,21 +255,16 @@ error:
14978   *
14979   * Call commit_creds() or abort_creds() to clean up.
14980   */
14981 -struct cred *prepare_creds(void)
14982 +struct cred *__prepare_creds(const struct cred *old)
14983  {
14984 -       struct task_struct *task = current;
14985 -       const struct cred *old;
14986         struct cred *new;
14987  
14988 -       validate_process_creds();
14989 -
14990         new = kmem_cache_alloc(cred_jar, GFP_KERNEL);
14991         if (!new)
14992                 return NULL;
14993  
14994         kdebug("prepare_creds() alloc %p", new);
14995  
14996 -       old = task->cred;
14997         memcpy(new, old, sizeof(struct cred));
14998  
14999         atomic_set(&new->usage, 1);
15000 @@ -321,6 +291,13 @@ error:
15001         abort_creds(new);
15002         return NULL;
15003  }
15004 +
15005 +struct cred *prepare_creds(void)
15006 +{
15007 +       validate_process_creds();
15008 +
15009 +       return __prepare_creds(current->cred);
15010 +}
15011  EXPORT_SYMBOL(prepare_creds);
15012  
15013  /*
15014 diff -NurpP --minimal linux-2.6.38.3/kernel/exit.c linux-2.6.38.3-vs2.3.0.37-rc14/kernel/exit.c
15015 --- linux-2.6.38.3/kernel/exit.c        2011-03-15 18:07:41.000000000 +0100
15016 +++ linux-2.6.38.3-vs2.3.0.37-rc14/kernel/exit.c        2011-01-29 02:01:07.000000000 +0100
15017 @@ -48,6 +48,10 @@
15018  #include <linux/fs_struct.h>
15019  #include <linux/init_task.h>
15020  #include <linux/perf_event.h>
15021 +#include <linux/vs_limit.h>
15022 +#include <linux/vs_context.h>
15023 +#include <linux/vs_network.h>
15024 +#include <linux/vs_pid.h>
15025  #include <trace/events/sched.h>
15026  #include <linux/hw_breakpoint.h>
15027  #include <linux/oom.h>
15028 @@ -494,9 +498,11 @@ static void close_files(struct files_str
15029                                         filp_close(file, files);
15030                                         cond_resched();
15031                                 }
15032 +                               vx_openfd_dec(i);
15033                         }
15034                         i++;
15035                         set >>= 1;
15036 +                       cond_resched();
15037                 }
15038         }
15039  }
15040 @@ -1047,11 +1053,16 @@ NORET_TYPE void do_exit(long code)
15041  
15042         validate_creds_for_do_exit(tsk);
15043  
15044 +       /* needs to stay after exit_notify() */
15045 +       exit_vx_info(tsk, code);
15046 +       exit_nx_info(tsk);
15047 +
15048         preempt_disable();
15049         exit_rcu();
15050         /* causes final put_task_struct in finish_task_switch(). */
15051         tsk->state = TASK_DEAD;
15052         schedule();
15053 +       printk("bad task: %p [%lx]\n", current, current->state);
15054         BUG();
15055         /* Avoid "noreturn function does return".  */
15056         for (;;)
15057 diff -NurpP --minimal linux-2.6.38.3/kernel/fork.c linux-2.6.38.3-vs2.3.0.37-rc14/kernel/fork.c
15058 --- linux-2.6.38.3/kernel/fork.c        2011-03-15 18:07:41.000000000 +0100
15059 +++ linux-2.6.38.3-vs2.3.0.37-rc14/kernel/fork.c        2011-01-29 03:19:29.000000000 +0100
15060 @@ -67,6 +67,10 @@
15061  #include <linux/user-return-notifier.h>
15062  #include <linux/oom.h>
15063  #include <linux/khugepaged.h>
15064 +#include <linux/vs_context.h>
15065 +#include <linux/vs_network.h>
15066 +#include <linux/vs_limit.h>
15067 +#include <linux/vs_memory.h>
15068  
15069  #include <asm/pgtable.h>
15070  #include <asm/pgalloc.h>
15071 @@ -162,6 +166,8 @@ void free_task(struct task_struct *tsk)
15072         account_kernel_stack(tsk->stack, -1);
15073         free_thread_info(tsk->stack);
15074         rt_mutex_debug_task_free(tsk);
15075 +       clr_vx_info(&tsk->vx_info);
15076 +       clr_nx_info(&tsk->nx_info);
15077         ftrace_graph_exit_task(tsk);
15078         free_task_struct(tsk);
15079  }
15080 @@ -500,6 +506,7 @@ static struct mm_struct * mm_init(struct
15081         if (likely(!mm_alloc_pgd(mm))) {
15082                 mm->def_flags = 0;
15083                 mmu_notifier_mm_init(mm);
15084 +               set_vx_info(&mm->mm_vx_info, p->vx_info);
15085                 return mm;
15086         }
15087  
15088 @@ -536,6 +543,7 @@ void __mmdrop(struct mm_struct *mm)
15089  #ifdef CONFIG_TRANSPARENT_HUGEPAGE
15090         VM_BUG_ON(mm->pmd_huge_pte);
15091  #endif
15092 +       clr_vx_info(&mm->mm_vx_info);
15093         free_mm(mm);
15094  }
15095  EXPORT_SYMBOL_GPL(__mmdrop);
15096 @@ -672,6 +680,7 @@ struct mm_struct *dup_mm(struct task_str
15097                 goto fail_nomem;
15098  
15099         memcpy(mm, oldmm, sizeof(*mm));
15100 +       mm->mm_vx_info = NULL;
15101  
15102         /* Initializing for Swap token stuff */
15103         mm->token_priority = 0;
15104 @@ -714,6 +723,7 @@ fail_nocontext:
15105          * If init_new_context() failed, we cannot use mmput() to free the mm
15106          * because it calls destroy_context()
15107          */
15108 +       clr_vx_info(&mm->mm_vx_info);
15109         mm_free_pgd(mm);
15110         free_mm(mm);
15111         return NULL;
15112 @@ -995,6 +1005,8 @@ static struct task_struct *copy_process(
15113         int retval;
15114         struct task_struct *p;
15115         int cgroup_callbacks_done = 0;
15116 +       struct vx_info *vxi;
15117 +       struct nx_info *nxi;
15118  
15119         if ((clone_flags & (CLONE_NEWNS|CLONE_FS)) == (CLONE_NEWNS|CLONE_FS))
15120                 return ERR_PTR(-EINVAL);
15121 @@ -1041,7 +1053,12 @@ static struct task_struct *copy_process(
15122         DEBUG_LOCKS_WARN_ON(!p->hardirqs_enabled);
15123         DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
15124  #endif
15125 +       init_vx_info(&p->vx_info, current_vx_info());
15126 +       init_nx_info(&p->nx_info, current_nx_info());
15127 +
15128         retval = -EAGAIN;
15129 +       if (!vx_nproc_avail(1))
15130 +               goto bad_fork_free;
15131         if (atomic_read(&p->real_cred->user->processes) >=
15132                         task_rlimit(p, RLIMIT_NPROC)) {
15133                 if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE) &&
15134 @@ -1306,6 +1323,18 @@ static struct task_struct *copy_process(
15135  
15136         total_forks++;
15137         spin_unlock(&current->sighand->siglock);
15138 +
15139 +       /* p is copy of current */
15140 +       vxi = p->vx_info;
15141 +       if (vxi) {
15142 +               claim_vx_info(vxi, p);
15143 +               atomic_inc(&vxi->cvirt.nr_threads);
15144 +               atomic_inc(&vxi->cvirt.total_forks);
15145 +               vx_nproc_inc(p);
15146 +       }
15147 +       nxi = p->nx_info;
15148 +       if (nxi)
15149 +               claim_nx_info(nxi, p);
15150         write_unlock_irq(&tasklist_lock);
15151         proc_fork_connector(p);
15152         cgroup_post_fork(p);
15153 diff -NurpP --minimal linux-2.6.38.3/kernel/kthread.c linux-2.6.38.3-vs2.3.0.37-rc14/kernel/kthread.c
15154 --- linux-2.6.38.3/kernel/kthread.c     2011-03-15 18:07:41.000000000 +0100
15155 +++ linux-2.6.38.3-vs2.3.0.37-rc14/kernel/kthread.c     2011-01-29 02:01:07.000000000 +0100
15156 @@ -16,6 +16,7 @@
15157  #include <linux/mutex.h>
15158  #include <linux/slab.h>
15159  #include <linux/freezer.h>
15160 +#include <linux/vs_pid.h>
15161  #include <trace/events/sched.h>
15162  
15163  static DEFINE_SPINLOCK(kthread_create_lock);
15164 diff -NurpP --minimal linux-2.6.38.3/kernel/nsproxy.c linux-2.6.38.3-vs2.3.0.37-rc14/kernel/nsproxy.c
15165 --- linux-2.6.38.3/kernel/nsproxy.c     2010-07-07 18:31:57.000000000 +0200
15166 +++ linux-2.6.38.3-vs2.3.0.37-rc14/kernel/nsproxy.c     2011-01-29 02:01:07.000000000 +0100
15167 @@ -20,6 +20,8 @@
15168  #include <linux/mnt_namespace.h>
15169  #include <linux/utsname.h>
15170  #include <linux/pid_namespace.h>
15171 +#include <linux/vserver/global.h>
15172 +#include <linux/vserver/debug.h>
15173  #include <net/net_namespace.h>
15174  #include <linux/ipc_namespace.h>
15175  
15176 @@ -43,8 +45,11 @@ static inline struct nsproxy *create_nsp
15177         struct nsproxy *nsproxy;
15178  
15179         nsproxy = kmem_cache_alloc(nsproxy_cachep, GFP_KERNEL);
15180 -       if (nsproxy)
15181 +       if (nsproxy) {
15182                 atomic_set(&nsproxy->count, 1);
15183 +               atomic_inc(&vs_global_nsproxy);
15184 +       }
15185 +       vxdprintk(VXD_CBIT(space, 2), "create_nsproxy = %p[1]", nsproxy);
15186         return nsproxy;
15187  }
15188  
15189 @@ -53,41 +58,52 @@ static inline struct nsproxy *create_nsp
15190   * Return the newly created nsproxy.  Do not attach this to the task,
15191   * leave it to the caller to do proper locking and attach it to task.
15192   */
15193 -static struct nsproxy *create_new_namespaces(unsigned long flags,
15194 -                       struct task_struct *tsk, struct fs_struct *new_fs)
15195 +static struct nsproxy *unshare_namespaces(unsigned long flags,
15196 +                       struct nsproxy *orig, struct fs_struct *new_fs)
15197  {
15198         struct nsproxy *new_nsp;
15199         int err;
15200  
15201 +       vxdprintk(VXD_CBIT(space, 4),
15202 +               "unshare_namespaces(0x%08lx,%p,%p)",
15203 +               flags, orig, new_fs);
15204 +
15205         new_nsp = create_nsproxy();
15206         if (!new_nsp)
15207                 return ERR_PTR(-ENOMEM);
15208  
15209 -       new_nsp->mnt_ns = copy_mnt_ns(flags, tsk->nsproxy->mnt_ns, new_fs);
15210 +       new_nsp->mnt_ns = copy_mnt_ns(flags, orig->mnt_ns, new_fs);
15211         if (IS_ERR(new_nsp->mnt_ns)) {
15212                 err = PTR_ERR(new_nsp->mnt_ns);
15213                 goto out_ns;
15214         }
15215  
15216 -       new_nsp->uts_ns = copy_utsname(flags, tsk->nsproxy->uts_ns);
15217 +       new_nsp->uts_ns = copy_utsname(flags, orig->uts_ns);
15218         if (IS_ERR(new_nsp->uts_ns)) {
15219                 err = PTR_ERR(new_nsp->uts_ns);
15220                 goto out_uts;
15221         }
15222  
15223 -       new_nsp->ipc_ns = copy_ipcs(flags, tsk->nsproxy->ipc_ns);
15224 +       new_nsp->ipc_ns = copy_ipcs(flags, orig->ipc_ns);
15225         if (IS_ERR(new_nsp->ipc_ns)) {
15226                 err = PTR_ERR(new_nsp->ipc_ns);
15227                 goto out_ipc;
15228         }
15229  
15230 -       new_nsp->pid_ns = copy_pid_ns(flags, task_active_pid_ns(tsk));
15231 +       new_nsp->pid_ns = copy_pid_ns(flags, orig->pid_ns);
15232         if (IS_ERR(new_nsp->pid_ns)) {
15233                 err = PTR_ERR(new_nsp->pid_ns);
15234                 goto out_pid;
15235         }
15236  
15237 -       new_nsp->net_ns = copy_net_ns(flags, tsk->nsproxy->net_ns);
15238 +       /* disabled now?
15239 +       new_nsp->user_ns = copy_user_ns(flags, orig->user_ns);
15240 +       if (IS_ERR(new_nsp->user_ns)) {
15241 +               err = PTR_ERR(new_nsp->user_ns);
15242 +               goto out_user;
15243 +       } */
15244 +
15245 +       new_nsp->net_ns = copy_net_ns(flags, orig->net_ns);
15246         if (IS_ERR(new_nsp->net_ns)) {
15247                 err = PTR_ERR(new_nsp->net_ns);
15248                 goto out_net;
15249 @@ -112,6 +128,38 @@ out_ns:
15250         return ERR_PTR(err);
15251  }
15252  
15253 +static struct nsproxy *create_new_namespaces(int flags, struct task_struct *tsk,
15254 +                       struct fs_struct *new_fs)
15255 +{
15256 +       return unshare_namespaces(flags, tsk->nsproxy, new_fs);
15257 +}
15258 +
15259 +/*
15260 + * copies the nsproxy, setting refcount to 1, and grabbing a
15261 + * reference to all contained namespaces.
15262 + */
15263 +struct nsproxy *copy_nsproxy(struct nsproxy *orig)
15264 +{
15265 +       struct nsproxy *ns = create_nsproxy();
15266 +
15267 +       if (ns) {
15268 +               memcpy(ns, orig, sizeof(struct nsproxy));
15269 +               atomic_set(&ns->count, 1);
15270 +
15271 +               if (ns->mnt_ns)
15272 +                       get_mnt_ns(ns->mnt_ns);
15273 +               if (ns->uts_ns)
15274 +                       get_uts_ns(ns->uts_ns);
15275 +               if (ns->ipc_ns)
15276 +                       get_ipc_ns(ns->ipc_ns);
15277 +               if (ns->pid_ns)
15278 +                       get_pid_ns(ns->pid_ns);
15279 +               if (ns->net_ns)
15280 +                       get_net(ns->net_ns);
15281 +       }
15282 +       return ns;
15283 +}
15284 +
15285  /*
15286   * called from clone.  This now handles copy for nsproxy and all
15287   * namespaces therein.
15288 @@ -119,9 +167,12 @@ out_ns:
15289  int copy_namespaces(unsigned long flags, struct task_struct *tsk)
15290  {
15291         struct nsproxy *old_ns = tsk->nsproxy;
15292 -       struct nsproxy *new_ns;
15293 +       struct nsproxy *new_ns = NULL;
15294         int err = 0;
15295  
15296 +       vxdprintk(VXD_CBIT(space, 7), "copy_namespaces(0x%08lx,%p[%p])",
15297 +               flags, tsk, old_ns);
15298 +
15299         if (!old_ns)
15300                 return 0;
15301  
15302 @@ -131,7 +182,7 @@ int copy_namespaces(unsigned long flags,
15303                                 CLONE_NEWPID | CLONE_NEWNET)))
15304                 return 0;
15305  
15306 -       if (!capable(CAP_SYS_ADMIN)) {
15307 +       if (!vx_can_unshare(CAP_SYS_ADMIN, flags)) {
15308                 err = -EPERM;
15309                 goto out;
15310         }
15311 @@ -158,6 +209,9 @@ int copy_namespaces(unsigned long flags,
15312  
15313  out:
15314         put_nsproxy(old_ns);
15315 +       vxdprintk(VXD_CBIT(space, 3),
15316 +               "copy_namespaces(0x%08lx,%p[%p]) = %d [%p]",
15317 +               flags, tsk, old_ns, err, new_ns);
15318         return err;
15319  }
15320  
15321 @@ -171,7 +225,9 @@ void free_nsproxy(struct nsproxy *ns)
15322                 put_ipc_ns(ns->ipc_ns);
15323         if (ns->pid_ns)
15324                 put_pid_ns(ns->pid_ns);
15325 -       put_net(ns->net_ns);
15326 +       if (ns->net_ns)
15327 +               put_net(ns->net_ns);
15328 +       atomic_dec(&vs_global_nsproxy);
15329         kmem_cache_free(nsproxy_cachep, ns);
15330  }
15331  
15332 @@ -184,11 +240,15 @@ int unshare_nsproxy_namespaces(unsigned 
15333  {
15334         int err = 0;
15335  
15336 +       vxdprintk(VXD_CBIT(space, 4),
15337 +               "unshare_nsproxy_namespaces(0x%08lx,[%p])",
15338 +               unshare_flags, current->nsproxy);
15339 +
15340         if (!(unshare_flags & (CLONE_NEWNS | CLONE_NEWUTS | CLONE_NEWIPC |
15341                                CLONE_NEWNET)))
15342                 return 0;
15343  
15344 -       if (!capable(CAP_SYS_ADMIN))
15345 +       if (!vx_can_unshare(CAP_SYS_ADMIN, unshare_flags))
15346                 return -EPERM;
15347  
15348         *new_nsp = create_new_namespaces(unshare_flags, current,
15349 diff -NurpP --minimal linux-2.6.38.3/kernel/pid.c linux-2.6.38.3-vs2.3.0.37-rc14/kernel/pid.c
15350 --- linux-2.6.38.3/kernel/pid.c 2011-01-05 21:50:38.000000000 +0100
15351 +++ linux-2.6.38.3-vs2.3.0.37-rc14/kernel/pid.c 2011-01-29 02:01:07.000000000 +0100
15352 @@ -36,6 +36,7 @@
15353  #include <linux/pid_namespace.h>
15354  #include <linux/init_task.h>
15355  #include <linux/syscalls.h>
15356 +#include <linux/vs_pid.h>
15357  
15358  #define pid_hashfn(nr, ns)     \
15359         hash_long((unsigned long)nr + (unsigned long)ns, pidhash_shift)
15360 @@ -339,7 +340,7 @@ EXPORT_SYMBOL_GPL(find_pid_ns);
15361  
15362  struct pid *find_vpid(int nr)
15363  {
15364 -       return find_pid_ns(nr, current->nsproxy->pid_ns);
15365 +       return find_pid_ns(vx_rmap_pid(nr), current->nsproxy->pid_ns);
15366  }
15367  EXPORT_SYMBOL_GPL(find_vpid);
15368  
15369 @@ -399,6 +400,9 @@ void transfer_pid(struct task_struct *ol
15370  struct task_struct *pid_task(struct pid *pid, enum pid_type type)
15371  {
15372         struct task_struct *result = NULL;
15373 +
15374 +       if (type == PIDTYPE_REALPID)
15375 +               type = PIDTYPE_PID;
15376         if (pid) {
15377                 struct hlist_node *first;
15378                 first = rcu_dereference_check(hlist_first_rcu(&pid->tasks[type]),
15379 @@ -417,7 +421,7 @@ EXPORT_SYMBOL(pid_task);
15380  struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
15381  {
15382         rcu_lockdep_assert(rcu_read_lock_held());
15383 -       return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
15384 +       return pid_task(find_pid_ns(vx_rmap_pid(nr), ns), PIDTYPE_PID);
15385  }
15386  
15387  struct task_struct *find_task_by_vpid(pid_t vnr)
15388 @@ -459,7 +463,7 @@ struct pid *find_get_pid(pid_t nr)
15389  }
15390  EXPORT_SYMBOL_GPL(find_get_pid);
15391  
15392 -pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns)
15393 +pid_t pid_unmapped_nr_ns(struct pid *pid, struct pid_namespace *ns)
15394  {
15395         struct upid *upid;
15396         pid_t nr = 0;
15397 @@ -472,6 +476,11 @@ pid_t pid_nr_ns(struct pid *pid, struct 
15398         return nr;
15399  }
15400  
15401 +pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns)
15402 +{
15403 +       return vx_map_pid(pid_unmapped_nr_ns(pid, ns));
15404 +}
15405 +
15406  pid_t pid_vnr(struct pid *pid)
15407  {
15408         return pid_nr_ns(pid, current->nsproxy->pid_ns);
15409 diff -NurpP --minimal linux-2.6.38.3/kernel/pid_namespace.c linux-2.6.38.3-vs2.3.0.37-rc14/kernel/pid_namespace.c
15410 --- linux-2.6.38.3/kernel/pid_namespace.c       2010-07-07 18:31:57.000000000 +0200
15411 +++ linux-2.6.38.3-vs2.3.0.37-rc14/kernel/pid_namespace.c       2011-01-29 02:01:07.000000000 +0100
15412 @@ -14,6 +14,7 @@
15413  #include <linux/err.h>
15414  #include <linux/acct.h>
15415  #include <linux/slab.h>
15416 +#include <linux/vserver/global.h>
15417  
15418  #define BITS_PER_PAGE          (PAGE_SIZE*8)
15419  
15420 @@ -87,6 +88,7 @@ static struct pid_namespace *create_pid_
15421                 goto out_free_map;
15422  
15423         kref_init(&ns->kref);
15424 +       atomic_inc(&vs_global_pid_ns);
15425         ns->level = level;
15426         ns->parent = get_pid_ns(parent_pid_ns);
15427  
15428 @@ -112,6 +114,7 @@ static void destroy_pid_namespace(struct
15429  
15430         for (i = 0; i < PIDMAP_ENTRIES; i++)
15431                 kfree(ns->pidmap[i].page);
15432 +       atomic_dec(&vs_global_pid_ns);
15433         kmem_cache_free(pid_ns_cachep, ns);
15434  }
15435  
15436 diff -NurpP --minimal linux-2.6.38.3/kernel/posix-timers.c linux-2.6.38.3-vs2.3.0.37-rc14/kernel/posix-timers.c
15437 --- linux-2.6.38.3/kernel/posix-timers.c        2011-03-15 18:07:42.000000000 +0100
15438 +++ linux-2.6.38.3-vs2.3.0.37-rc14/kernel/posix-timers.c        2011-01-29 02:01:07.000000000 +0100
15439 @@ -46,6 +46,7 @@
15440  #include <linux/wait.h>
15441  #include <linux/workqueue.h>
15442  #include <linux/module.h>
15443 +#include <linux/vs_context.h>
15444  
15445  /*
15446   * Management arrays for POSIX timers.  Timers are kept in slab memory
15447 @@ -369,6 +370,7 @@ int posix_timer_event(struct k_itimer *t
15448  {
15449         struct task_struct *task;
15450         int shared, ret = -1;
15451 +
15452         /*
15453          * FIXME: if ->sigq is queued we can race with
15454          * dequeue_signal()->do_schedule_next_timer().
15455 @@ -385,10 +387,18 @@ int posix_timer_event(struct k_itimer *t
15456         rcu_read_lock();
15457         task = pid_task(timr->it_pid, PIDTYPE_PID);
15458         if (task) {
15459 +               struct vx_info_save vxis;
15460 +               struct vx_info *vxi;
15461 +
15462 +               vxi = get_vx_info(task->vx_info);
15463 +               enter_vx_info(vxi, &vxis);
15464                 shared = !(timr->it_sigev_notify & SIGEV_THREAD_ID);
15465                 ret = send_sigqueue(timr->sigq, task, shared);
15466 +               leave_vx_info(&vxis);
15467 +               put_vx_info(vxi);
15468         }
15469         rcu_read_unlock();
15470 +
15471         /* If we failed to send the signal the timer stops. */
15472         return ret > 0;
15473  }
15474 diff -NurpP --minimal linux-2.6.38.3/kernel/printk.c linux-2.6.38.3-vs2.3.0.37-rc14/kernel/printk.c
15475 --- linux-2.6.38.3/kernel/printk.c      2011-03-15 18:07:42.000000000 +0100
15476 +++ linux-2.6.38.3-vs2.3.0.37-rc14/kernel/printk.c      2011-02-17 02:34:59.000000000 +0100
15477 @@ -40,6 +40,7 @@
15478  #include <linux/cpu.h>
15479  #include <linux/notifier.h>
15480  #include <linux/rculist.h>
15481 +#include <linux/vs_cvirt.h>
15482  
15483  #include <asm/uaccess.h>
15484  
15485 @@ -280,7 +281,7 @@ static int check_syslog_permissions(int 
15486                 return 0;
15487  
15488         if (syslog_action_restricted(type)) {
15489 -               if (capable(CAP_SYSLOG))
15490 +               if (vx_capable(CAP_SYSLOG, VXC_SYSLOG))
15491                         return 0;
15492                 /* For historical reasons, accept CAP_SYS_ADMIN too, with a warning */
15493                 if (capable(CAP_SYS_ADMIN)) {
15494 @@ -308,12 +309,9 @@ int do_syslog(int type, char __user *buf
15495         if (error)
15496                 return error;
15497  
15498 -       switch (type) {
15499 -       case SYSLOG_ACTION_CLOSE:       /* Close log */
15500 -               break;
15501 -       case SYSLOG_ACTION_OPEN:        /* Open log */
15502 -               break;
15503 -       case SYSLOG_ACTION_READ:        /* Read from log */
15504 +       if ((type == SYSLOG_ACTION_READ) ||
15505 +           (type == SYSLOG_ACTION_READ_ALL) ||
15506 +           (type == SYSLOG_ACTION_READ_CLEAR)) {
15507                 error = -EINVAL;
15508                 if (!buf || len < 0)
15509                         goto out;
15510 @@ -324,6 +322,16 @@ int do_syslog(int type, char __user *buf
15511                         error = -EFAULT;
15512                         goto out;
15513                 }
15514 +       }
15515 +       if (!vx_check(0, VS_ADMIN|VS_WATCH))
15516 +               return vx_do_syslog(type, buf, len);
15517 +
15518 +       switch (type) {
15519 +       case SYSLOG_ACTION_CLOSE:       /* Close log */
15520 +               break;
15521 +       case SYSLOG_ACTION_OPEN:        /* Open log */
15522 +               break;
15523 +       case SYSLOG_ACTION_READ:        /* Read from log */
15524                 error = wait_event_interruptible(log_wait,
15525                                                         (log_start - log_end));
15526                 if (error)
15527 @@ -350,16 +358,6 @@ int do_syslog(int type, char __user *buf
15528                 /* FALL THRU */
15529         /* Read last kernel messages */
15530         case SYSLOG_ACTION_READ_ALL:
15531 -               error = -EINVAL;
15532 -               if (!buf || len < 0)
15533 -                       goto out;
15534 -               error = 0;
15535 -               if (!len)
15536 -                       goto out;
15537 -               if (!access_ok(VERIFY_WRITE, buf, len)) {
15538 -                       error = -EFAULT;
15539 -                       goto out;
15540 -               }
15541                 count = len;
15542                 if (count > log_buf_len)
15543                         count = log_buf_len;
15544 diff -NurpP --minimal linux-2.6.38.3/kernel/ptrace.c linux-2.6.38.3-vs2.3.0.37-rc14/kernel/ptrace.c
15545 --- linux-2.6.38.3/kernel/ptrace.c      2011-03-15 18:07:42.000000000 +0100
15546 +++ linux-2.6.38.3-vs2.3.0.37-rc14/kernel/ptrace.c      2011-03-31 19:40:13.000000000 +0200
15547 @@ -22,6 +22,7 @@
15548  #include <linux/syscalls.h>
15549  #include <linux/uaccess.h>
15550  #include <linux/regset.h>
15551 +#include <linux/vs_context.h>
15552  
15553  
15554  /*
15555 @@ -150,6 +151,11 @@ int __ptrace_may_access(struct task_stru
15556                 dumpable = get_dumpable(task->mm);
15557         if (!dumpable && !capable(CAP_SYS_PTRACE))
15558                 return -EPERM;
15559 +       if (!vx_check(task->xid, VS_ADMIN_P|VS_WATCH_P|VS_IDENT))
15560 +               return -EPERM;
15561 +       if (!vx_check(task->xid, VS_IDENT) &&
15562 +               !task_vx_flags(task, VXF_STATE_ADMIN, 0))
15563 +               return -EACCES;
15564  
15565         return security_ptrace_access_check(task, mode);
15566  }
15567 diff -NurpP --minimal linux-2.6.38.3/kernel/sched.c linux-2.6.38.3-vs2.3.0.37-rc14/kernel/sched.c
15568 --- linux-2.6.38.3/kernel/sched.c       2011-04-15 10:30:30.000000000 +0200
15569 +++ linux-2.6.38.3-vs2.3.0.37-rc14/kernel/sched.c       2011-03-25 22:52:15.000000000 +0100
15570 @@ -72,6 +72,8 @@
15571  #include <linux/ctype.h>
15572  #include <linux/ftrace.h>
15573  #include <linux/slab.h>
15574 +#include <linux/vs_sched.h>
15575 +#include <linux/vs_cvirt.h>
15576  
15577  #include <asm/tlb.h>
15578  #include <asm/irq_regs.h>
15579 @@ -3228,9 +3230,17 @@ static void calc_global_nohz(unsigned lo
15580   */
15581  void get_avenrun(unsigned long *loads, unsigned long offset, int shift)
15582  {
15583 -       loads[0] = (avenrun[0] + offset) << shift;
15584 -       loads[1] = (avenrun[1] + offset) << shift;
15585 -       loads[2] = (avenrun[2] + offset) << shift;
15586 +       if (vx_flags(VXF_VIRT_LOAD, 0)) {
15587 +               struct vx_info *vxi = current_vx_info();
15588 +
15589 +               loads[0] = (vxi->cvirt.load[0] + offset) << shift;
15590 +               loads[1] = (vxi->cvirt.load[1] + offset) << shift;
15591 +               loads[2] = (vxi->cvirt.load[2] + offset) << shift;
15592 +       } else {
15593 +               loads[0] = (avenrun[0] + offset) << shift;
15594 +               loads[1] = (avenrun[1] + offset) << shift;
15595 +               loads[2] = (avenrun[2] + offset) << shift;
15596 +       }
15597  }
15598  
15599  /*
15600 @@ -3518,16 +3528,19 @@ void account_user_time(struct task_struc
15601                        cputime_t cputime_scaled)
15602  {
15603         struct cpu_usage_stat *cpustat = &kstat_this_cpu.cpustat;
15604 +       struct vx_info *vxi = p->vx_info;  /* p is _always_ current */
15605         cputime64_t tmp;
15606 +       int nice = (TASK_NICE(p) > 0);
15607  
15608         /* Add user time to process. */
15609         p->utime = cputime_add(p->utime, cputime);
15610         p->utimescaled = cputime_add(p->utimescaled, cputime_scaled);
15611 +       vx_account_user(vxi, cputime, nice);
15612         account_group_user_time(p, cputime);
15613  
15614         /* Add user time to cpustat. */
15615         tmp = cputime_to_cputime64(cputime);
15616 -       if (TASK_NICE(p) > 0)
15617 +       if (nice)
15618                 cpustat->nice = cputime64_add(cpustat->nice, tmp);
15619         else
15620                 cpustat->user = cputime64_add(cpustat->user, tmp);
15621 @@ -3578,6 +3591,7 @@ void account_system_time(struct task_str
15622                          cputime_t cputime, cputime_t cputime_scaled)
15623  {
15624         struct cpu_usage_stat *cpustat = &kstat_this_cpu.cpustat;
15625 +       struct vx_info *vxi = p->vx_info;  /* p is _always_ current */
15626         cputime64_t tmp;
15627  
15628         if ((p->flags & PF_VCPU) && (irq_count() - hardirq_offset == 0)) {
15629 @@ -3588,6 +3602,7 @@ void account_system_time(struct task_str
15630         /* Add system time to process. */
15631         p->stime = cputime_add(p->stime, cputime);
15632         p->stimescaled = cputime_add(p->stimescaled, cputime_scaled);
15633 +       vx_account_system(vxi, cputime, 0 /* do we have idle time? */);
15634         account_group_system_time(p, cputime);
15635  
15636         /* Add system time to cpustat. */
15637 @@ -4672,7 +4687,7 @@ SYSCALL_DEFINE1(nice, int, increment)
15638                 nice = 19;
15639  
15640         if (increment < 0 && !can_nice(current, nice))
15641 -               return -EPERM;
15642 +               return vx_flags(VXF_IGNEG_NICE, 0) ? 0 : -EPERM;
15643  
15644         retval = security_task_setnice(current, nice);
15645         if (retval)
15646 diff -NurpP --minimal linux-2.6.38.3/kernel/sched_fair.c linux-2.6.38.3-vs2.3.0.37-rc14/kernel/sched_fair.c
15647 --- linux-2.6.38.3/kernel/sched_fair.c  2011-03-15 18:07:42.000000000 +0100
15648 +++ linux-2.6.38.3-vs2.3.0.37-rc14/kernel/sched_fair.c  2011-02-02 22:20:27.000000000 +0100
15649 @@ -992,6 +992,8 @@ enqueue_entity(struct cfs_rq *cfs_rq, st
15650                 __enqueue_entity(cfs_rq, se);
15651         se->on_rq = 1;
15652  
15653 +       if (entity_is_task(se))
15654 +               vx_activate_task(task_of(se));
15655         if (cfs_rq->nr_running == 1)
15656                 list_add_leaf_cfs_rq(cfs_rq);
15657  }
15658 @@ -1038,6 +1040,8 @@ dequeue_entity(struct cfs_rq *cfs_rq, st
15659         if (se != cfs_rq->curr)
15660                 __dequeue_entity(cfs_rq, se);
15661         se->on_rq = 0;
15662 +       if (entity_is_task(se))
15663 +               vx_deactivate_task(task_of(se));
15664         update_cfs_load(cfs_rq, 0);
15665         account_entity_dequeue(cfs_rq, se);
15666         update_min_vruntime(cfs_rq);
15667 diff -NurpP --minimal linux-2.6.38.3/kernel/signal.c linux-2.6.38.3-vs2.3.0.37-rc14/kernel/signal.c
15668 --- linux-2.6.38.3/kernel/signal.c      2011-04-15 10:30:30.000000000 +0200
15669 +++ linux-2.6.38.3-vs2.3.0.37-rc14/kernel/signal.c      2011-04-15 10:33:41.000000000 +0200
15670 @@ -28,6 +28,8 @@
15671  #include <linux/freezer.h>
15672  #include <linux/pid_namespace.h>
15673  #include <linux/nsproxy.h>
15674 +#include <linux/vs_context.h>
15675 +#include <linux/vs_pid.h>
15676  #define CREATE_TRACE_POINTS
15677  #include <trace/events/signal.h>
15678  
15679 @@ -646,9 +648,18 @@ static int check_kill_permission(int sig
15680         struct pid *sid;
15681         int error;
15682  
15683 +       vxdprintk(VXD_CBIT(misc, 7),
15684 +               "check_kill_permission(%d,%p,%p[#%u,%u])",
15685 +               sig, info, t, vx_task_xid(t), t->pid);
15686 +
15687         if (!valid_signal(sig))
15688                 return -EINVAL;
15689  
15690 +/*     FIXME: needed? if so, why?
15691 +       if ((info != SEND_SIG_NOINFO) &&
15692 +               (is_si_special(info) || !si_fromuser(info)))
15693 +               goto skip;      */
15694 +
15695         if (!si_fromuser(info))
15696                 return 0;
15697  
15698 @@ -678,6 +689,20 @@ static int check_kill_permission(int sig
15699                 }
15700         }
15701  
15702 +       error = -EPERM;
15703 +       if (t->pid == 1 && current->xid)
15704 +               return error;
15705 +
15706 +       error = -ESRCH;
15707 +       /* FIXME: we shouldn't return ESRCH ever, to avoid
15708 +                 loops, maybe ENOENT or EACCES? */
15709 +       if (!vx_check(vx_task_xid(t), VS_WATCH_P | VS_IDENT)) {
15710 +               vxdprintk(current->xid || VXD_CBIT(misc, 7),
15711 +                       "signal %d[%p] xid mismatch %p[#%u,%u] xid=#%u",
15712 +                       sig, info, t, vx_task_xid(t), t->pid, current->xid);
15713 +               return error;
15714 +       }
15715 +/* skip: */
15716         return security_task_kill(t, info, sig, 0);
15717  }
15718  
15719 @@ -1171,7 +1196,7 @@ int kill_pid_info(int sig, struct siginf
15720         rcu_read_lock();
15721  retry:
15722         p = pid_task(pid, PIDTYPE_PID);
15723 -       if (p) {
15724 +       if (p && vx_check(vx_task_xid(p), VS_IDENT)) {
15725                 error = group_send_sig_info(sig, info, p);
15726                 if (unlikely(error == -ESRCH))
15727                         /*
15728 @@ -1211,7 +1236,7 @@ int kill_pid_info_as_uid(int sig, struct
15729  
15730         rcu_read_lock();
15731         p = pid_task(pid, PIDTYPE_PID);
15732 -       if (!p) {
15733 +       if (!p || !vx_check(vx_task_xid(p), VS_IDENT)) {
15734                 ret = -ESRCH;
15735                 goto out_unlock;
15736         }
15737 @@ -1266,8 +1291,10 @@ static int kill_something_info(int sig, 
15738                 struct task_struct * p;
15739  
15740                 for_each_process(p) {
15741 -                       if (task_pid_vnr(p) > 1 &&
15742 -                                       !same_thread_group(p, current)) {
15743 +                       if (vx_check(vx_task_xid(p), VS_ADMIN|VS_IDENT) &&
15744 +                               task_pid_vnr(p) > 1 &&
15745 +                               !same_thread_group(p, current) &&
15746 +                               !vx_current_initpid(p->pid)) {
15747                                 int err = group_send_sig_info(sig, info, p);
15748                                 ++count;
15749                                 if (err != -EPERM)
15750 @@ -1936,6 +1963,11 @@ relock:
15751                                 !sig_kernel_only(signr))
15752                         continue;
15753  
15754 +               /* virtual init is protected against user signals */
15755 +               if ((info->si_code == SI_USER) &&
15756 +                       vx_current_initpid(current->pid))
15757 +                       continue;
15758 +
15759                 if (sig_kernel_stop(signr)) {
15760                         /*
15761                          * The default action is to stop all threads in
15762 diff -NurpP --minimal linux-2.6.38.3/kernel/softirq.c linux-2.6.38.3-vs2.3.0.37-rc14/kernel/softirq.c
15763 --- linux-2.6.38.3/kernel/softirq.c     2011-03-15 18:07:42.000000000 +0100
15764 +++ linux-2.6.38.3-vs2.3.0.37-rc14/kernel/softirq.c     2011-01-29 02:01:07.000000000 +0100
15765 @@ -24,6 +24,7 @@
15766  #include <linux/ftrace.h>
15767  #include <linux/smp.h>
15768  #include <linux/tick.h>
15769 +#include <linux/vs_context.h>
15770  
15771  #define CREATE_TRACE_POINTS
15772  #include <trace/events/irq.h>
15773 diff -NurpP --minimal linux-2.6.38.3/kernel/sys.c linux-2.6.38.3-vs2.3.0.37-rc14/kernel/sys.c
15774 --- linux-2.6.38.3/kernel/sys.c 2011-03-15 18:07:42.000000000 +0100
15775 +++ linux-2.6.38.3-vs2.3.0.37-rc14/kernel/sys.c 2011-02-02 22:20:27.000000000 +0100
15776 @@ -42,6 +42,7 @@
15777  #include <linux/syscalls.h>
15778  #include <linux/kprobes.h>
15779  #include <linux/user_namespace.h>
15780 +#include <linux/vs_pid.h>
15781  
15782  #include <linux/kmsg_dump.h>
15783  
15784 @@ -133,7 +134,10 @@ static int set_one_prio(struct task_stru
15785                 goto out;
15786         }
15787         if (niceval < task_nice(p) && !can_nice(p, niceval)) {
15788 -               error = -EACCES;
15789 +               if (vx_flags(VXF_IGNEG_NICE, 0))
15790 +                       error = 0;
15791 +               else
15792 +                       error = -EACCES;
15793                 goto out;
15794         }
15795         no_nice = security_task_setnice(p, niceval);
15796 @@ -183,6 +187,8 @@ SYSCALL_DEFINE3(setpriority, int, which,
15797                         else
15798                                 pgrp = task_pgrp(current);
15799                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
15800 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
15801 +                                       continue;
15802                                 error = set_one_prio(p, niceval, error);
15803                         } while_each_pid_thread(pgrp, PIDTYPE_PGID, p);
15804                         break;
15805 @@ -246,6 +252,8 @@ SYSCALL_DEFINE2(getpriority, int, which,
15806                         else
15807                                 pgrp = task_pgrp(current);
15808                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
15809 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
15810 +                                       continue;
15811                                 niceval = 20 - task_nice(p);
15812                                 if (niceval > retval)
15813                                         retval = niceval;
15814 @@ -363,6 +371,8 @@ EXPORT_SYMBOL_GPL(kernel_power_off);
15815  
15816  static DEFINE_MUTEX(reboot_mutex);
15817  
15818 +long vs_reboot(unsigned int, void __user *);
15819 +
15820  /*
15821   * Reboot system call: for obvious reasons only root may call it,
15822   * and even root needs to set up some magic numbers in the registers
15823 @@ -395,6 +405,9 @@ SYSCALL_DEFINE4(reboot, int, magic1, int
15824         if ((cmd == LINUX_REBOOT_CMD_POWER_OFF) && !pm_power_off)
15825                 cmd = LINUX_REBOOT_CMD_HALT;
15826  
15827 +       if (!vx_check(0, VS_ADMIN|VS_WATCH))
15828 +               return vs_reboot(cmd, arg);
15829 +
15830         mutex_lock(&reboot_mutex);
15831         switch (cmd) {
15832         case LINUX_REBOOT_CMD_RESTART:
15833 @@ -1177,7 +1190,7 @@ SYSCALL_DEFINE2(sethostname, char __user
15834         int errno;
15835         char tmp[__NEW_UTS_LEN];
15836  
15837 -       if (!capable(CAP_SYS_ADMIN))
15838 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SET_UTSNAME))
15839                 return -EPERM;
15840         if (len < 0 || len > __NEW_UTS_LEN)
15841                 return -EINVAL;
15842 @@ -1226,7 +1239,7 @@ SYSCALL_DEFINE2(setdomainname, char __us
15843         int errno;
15844         char tmp[__NEW_UTS_LEN];
15845  
15846 -       if (!capable(CAP_SYS_ADMIN))
15847 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SET_UTSNAME))
15848                 return -EPERM;
15849         if (len < 0 || len > __NEW_UTS_LEN)
15850                 return -EINVAL;
15851 @@ -1342,7 +1355,7 @@ int do_prlimit(struct task_struct *tsk, 
15852         task_lock(tsk->group_leader);
15853         if (new_rlim) {
15854                 if (new_rlim->rlim_max > rlim->rlim_max &&
15855 -                               !capable(CAP_SYS_RESOURCE))
15856 +                       !vx_capable(CAP_SYS_RESOURCE, VXC_SET_RLIMIT))
15857                         retval = -EPERM;
15858                 if (!retval)
15859                         retval = security_task_setrlimit(tsk->group_leader,
15860 @@ -1392,7 +1405,7 @@ static int check_prlimit_permission(stru
15861              cred->gid != tcred->egid ||
15862              cred->gid != tcred->sgid ||
15863              cred->gid != tcred->gid) &&
15864 -            !capable(CAP_SYS_RESOURCE)) {
15865 +            !vx_capable(CAP_SYS_RESOURCE, VXC_SET_RLIMIT)) {
15866                 return -EPERM;
15867         }
15868  
15869 diff -NurpP --minimal linux-2.6.38.3/kernel/sysctl.c linux-2.6.38.3-vs2.3.0.37-rc14/kernel/sysctl.c
15870 --- linux-2.6.38.3/kernel/sysctl.c      2011-04-15 10:30:30.000000000 +0200
15871 +++ linux-2.6.38.3-vs2.3.0.37-rc14/kernel/sysctl.c      2011-03-28 15:00:14.000000000 +0200
15872 @@ -74,6 +74,7 @@
15873  #if defined(CONFIG_PROVE_LOCKING) || defined(CONFIG_LOCK_STAT)
15874  #include <linux/lockdep.h>
15875  #endif
15876 +extern char vshelper_path[];
15877  #ifdef CONFIG_CHR_DEV_SG
15878  #include <scsi/sg.h>
15879  #endif
15880 @@ -573,6 +574,13 @@ static struct ctl_table kern_table[] = {
15881                 .proc_handler   = proc_dostring,
15882         },
15883  #endif
15884 +       {
15885 +               .procname       = "vshelper",
15886 +               .data           = &vshelper_path,
15887 +               .maxlen         = 256,
15888 +               .mode           = 0644,
15889 +               .proc_handler   = &proc_dostring,
15890 +       },
15891  #ifdef CONFIG_CHR_DEV_SG
15892         {
15893                 .procname       = "sg-big-buff",
15894 diff -NurpP --minimal linux-2.6.38.3/kernel/sysctl_binary.c linux-2.6.38.3-vs2.3.0.37-rc14/kernel/sysctl_binary.c
15895 --- linux-2.6.38.3/kernel/sysctl_binary.c       2011-03-15 18:07:42.000000000 +0100
15896 +++ linux-2.6.38.3-vs2.3.0.37-rc14/kernel/sysctl_binary.c       2011-01-29 02:01:07.000000000 +0100
15897 @@ -73,6 +73,7 @@ static const struct bin_table bin_kern_t
15898  
15899         { CTL_INT,      KERN_PANIC,                     "panic" },
15900         { CTL_INT,      KERN_REALROOTDEV,               "real-root-dev" },
15901 +       { CTL_STR,      KERN_VSHELPER,                  "vshelper" },
15902  
15903         { CTL_STR,      KERN_SPARC_REBOOT,              "reboot-cmd" },
15904         { CTL_INT,      KERN_CTLALTDEL,                 "ctrl-alt-del" },
15905 diff -NurpP --minimal linux-2.6.38.3/kernel/time/timekeeping.c linux-2.6.38.3-vs2.3.0.37-rc14/kernel/time/timekeeping.c
15906 --- linux-2.6.38.3/kernel/time/timekeeping.c    2011-03-15 18:07:42.000000000 +0100
15907 +++ linux-2.6.38.3-vs2.3.0.37-rc14/kernel/time/timekeeping.c    2011-01-29 02:01:07.000000000 +0100
15908 @@ -233,6 +233,7 @@ void getnstimeofday(struct timespec *ts)
15909         } while (read_seqretry(&xtime_lock, seq));
15910  
15911         timespec_add_ns(ts, nsecs);
15912 +       vx_adjust_timespec(ts);
15913  }
15914  
15915  EXPORT_SYMBOL(getnstimeofday);
15916 diff -NurpP --minimal linux-2.6.38.3/kernel/time.c linux-2.6.38.3-vs2.3.0.37-rc14/kernel/time.c
15917 --- linux-2.6.38.3/kernel/time.c        2011-03-15 18:07:42.000000000 +0100
15918 +++ linux-2.6.38.3-vs2.3.0.37-rc14/kernel/time.c        2011-01-29 02:01:07.000000000 +0100
15919 @@ -92,7 +92,7 @@ SYSCALL_DEFINE1(stime, time_t __user *, 
15920         if (err)
15921                 return err;
15922  
15923 -       do_settimeofday(&tv);
15924 +       vx_settimeofday(&tv);
15925         return 0;
15926  }
15927  
15928 @@ -177,7 +177,7 @@ int do_sys_settimeofday(struct timespec 
15929                 /* SMP safe, again the code in arch/foo/time.c should
15930                  * globally block out interrupts when it runs.
15931                  */
15932 -               return do_settimeofday(tv);
15933 +               return vx_settimeofday(tv);
15934         }
15935         return 0;
15936  }
15937 diff -NurpP --minimal linux-2.6.38.3/kernel/timer.c linux-2.6.38.3-vs2.3.0.37-rc14/kernel/timer.c
15938 --- linux-2.6.38.3/kernel/timer.c       2011-03-15 18:07:42.000000000 +0100
15939 +++ linux-2.6.38.3-vs2.3.0.37-rc14/kernel/timer.c       2011-02-17 02:17:51.000000000 +0100
15940 @@ -40,6 +40,10 @@
15941  #include <linux/irq_work.h>
15942  #include <linux/sched.h>
15943  #include <linux/slab.h>
15944 +#include <linux/vs_base.h>
15945 +#include <linux/vs_cvirt.h>
15946 +#include <linux/vs_pid.h>
15947 +#include <linux/vserver/sched.h>
15948  
15949  #include <asm/uaccess.h>
15950  #include <asm/unistd.h>
15951 @@ -1321,12 +1325,6 @@ SYSCALL_DEFINE1(alarm, unsigned int, sec
15952  
15953  #endif
15954  
15955 -#ifndef __alpha__
15956 -
15957 -/*
15958 - * The Alpha uses getxpid, getxuid, and getxgid instead.  Maybe this
15959 - * should be moved into arch/i386 instead?
15960 - */
15961  
15962  /**
15963   * sys_getpid - return the thread group id of the current process
15964 @@ -1355,10 +1353,23 @@ SYSCALL_DEFINE0(getppid)
15965         rcu_read_lock();
15966         pid = task_tgid_vnr(current->real_parent);
15967         rcu_read_unlock();
15968 +       return vx_map_pid(pid);
15969 +}
15970  
15971 -       return pid;
15972 +#ifdef __alpha__
15973 +
15974 +/*
15975 + * The Alpha uses getxpid, getxuid, and getxgid instead.
15976 + */
15977 +
15978 +asmlinkage long do_getxpid(long *ppid)
15979 +{
15980 +       *ppid = sys_getppid();
15981 +       return sys_getpid();
15982  }
15983  
15984 +#else /* _alpha_ */
15985 +
15986  SYSCALL_DEFINE0(getuid)
15987  {
15988         /* Only we change this so SMP safe */
15989 diff -NurpP --minimal linux-2.6.38.3/kernel/user_namespace.c linux-2.6.38.3-vs2.3.0.37-rc14/kernel/user_namespace.c
15990 --- linux-2.6.38.3/kernel/user_namespace.c      2011-03-15 18:07:42.000000000 +0100
15991 +++ linux-2.6.38.3-vs2.3.0.37-rc14/kernel/user_namespace.c      2011-01-29 02:01:07.000000000 +0100
15992 @@ -11,6 +11,7 @@
15993  #include <linux/user_namespace.h>
15994  #include <linux/highuid.h>
15995  #include <linux/cred.h>
15996 +#include <linux/vserver/global.h>
15997  
15998  static struct kmem_cache *user_ns_cachep __read_mostly;
15999  
16000 @@ -33,6 +34,7 @@ int create_user_ns(struct cred *new)
16001                 return -ENOMEM;
16002  
16003         kref_init(&ns->kref);
16004 +       atomic_inc(&vs_global_user_ns);
16005  
16006         for (n = 0; n < UIDHASH_SZ; ++n)
16007                 INIT_HLIST_HEAD(ns->uidhash_table + n);
16008 @@ -81,6 +83,8 @@ void free_user_ns(struct kref *kref)
16009         struct user_namespace *ns =
16010                 container_of(kref, struct user_namespace, kref);
16011  
16012 +       /* FIXME: maybe move into destroyer? */
16013 +       atomic_dec(&vs_global_user_ns);
16014         INIT_WORK(&ns->destroyer, free_user_ns_work);
16015         schedule_work(&ns->destroyer);
16016  }
16017 diff -NurpP --minimal linux-2.6.38.3/kernel/utsname.c linux-2.6.38.3-vs2.3.0.37-rc14/kernel/utsname.c
16018 --- linux-2.6.38.3/kernel/utsname.c     2009-09-10 15:26:28.000000000 +0200
16019 +++ linux-2.6.38.3-vs2.3.0.37-rc14/kernel/utsname.c     2011-01-29 02:01:07.000000000 +0100
16020 @@ -14,14 +14,17 @@
16021  #include <linux/utsname.h>
16022  #include <linux/err.h>
16023  #include <linux/slab.h>
16024 +#include <linux/vserver/global.h>
16025  
16026  static struct uts_namespace *create_uts_ns(void)
16027  {
16028         struct uts_namespace *uts_ns;
16029  
16030         uts_ns = kmalloc(sizeof(struct uts_namespace), GFP_KERNEL);
16031 -       if (uts_ns)
16032 +       if (uts_ns) {
16033                 kref_init(&uts_ns->kref);
16034 +               atomic_inc(&vs_global_uts_ns);
16035 +       }
16036         return uts_ns;
16037  }
16038  
16039 @@ -71,5 +74,6 @@ void free_uts_ns(struct kref *kref)
16040         struct uts_namespace *ns;
16041  
16042         ns = container_of(kref, struct uts_namespace, kref);
16043 +       atomic_dec(&vs_global_uts_ns);
16044         kfree(ns);
16045  }
16046 diff -NurpP --minimal linux-2.6.38.3/kernel/vserver/Kconfig linux-2.6.38.3-vs2.3.0.37-rc14/kernel/vserver/Kconfig
16047 --- linux-2.6.38.3/kernel/vserver/Kconfig       1970-01-01 01:00:00.000000000 +0100
16048 +++ linux-2.6.38.3-vs2.3.0.37-rc14/kernel/vserver/Kconfig       2011-03-15 21:32:33.000000000 +0100
16049 @@ -0,0 +1,228 @@
16050 +#
16051 +# Linux VServer configuration
16052 +#
16053 +
16054 +menu "Linux VServer"
16055 +
16056 +config VSERVER_AUTO_LBACK
16057 +       bool    "Automatically Assign Loopback IP"
16058 +       default y
16059 +       help
16060 +         Automatically assign a guest specific loopback
16061 +         IP and add it to the kernel network stack on
16062 +         startup.
16063 +
16064 +config VSERVER_AUTO_SINGLE
16065 +       bool    "Automatic Single IP Special Casing"
16066 +       depends on EXPERIMENTAL
16067 +       default y
16068 +       help
16069 +         This allows network contexts with a single IP to
16070 +         automatically remap 0.0.0.0 bindings to that IP,
16071 +         avoiding further network checks and improving
16072 +         performance.
16073 +
16074 +         (note: such guests do not allow to change the ip
16075 +          on the fly and do not show loopback addresses)
16076 +
16077 +config VSERVER_COWBL
16078 +       bool    "Enable COW Immutable Link Breaking"
16079 +       default y
16080 +       help
16081 +         This enables the COW (Copy-On-Write) link break code.
16082 +         It allows you to treat unified files like normal files
16083 +         when writing to them (which will implicitely break the
16084 +         link and create a copy of the unified file)
16085 +
16086 +config VSERVER_VTIME
16087 +       bool    "Enable Virtualized Guest Time"
16088 +       depends on EXPERIMENTAL
16089 +       default n
16090 +       help
16091 +         This enables per guest time offsets to allow for
16092 +         adjusting the system clock individually per guest.
16093 +         this adds some overhead to the time functions and
16094 +         therefore should not be enabled without good reason.
16095 +
16096 +config VSERVER_DEVICE
16097 +       bool    "Enable Guest Device Mapping"
16098 +       depends on EXPERIMENTAL
16099 +       default n
16100 +       help
16101 +         This enables generic device remapping.
16102 +
16103 +config VSERVER_PROC_SECURE
16104 +       bool    "Enable Proc Security"
16105 +       depends on PROC_FS
16106 +       default y
16107 +       help
16108 +         This configures ProcFS security to initially hide
16109 +         non-process entries for all contexts except the main and
16110 +         spectator context (i.e. for all guests), which is a secure
16111 +         default.
16112 +
16113 +         (note: on 1.2x the entries were visible by default)
16114 +
16115 +choice
16116 +       prompt  "Persistent Inode Tagging"
16117 +       default TAGGING_ID24
16118 +       help
16119 +         This adds persistent context information to filesystems
16120 +         mounted with the tagxid option. Tagging is a requirement
16121 +         for per-context disk limits and per-context quota.
16122 +
16123 +
16124 +config TAGGING_NONE
16125 +       bool    "Disabled"
16126 +       help
16127 +         do not store per-context information in inodes.
16128 +
16129 +config TAGGING_UID16
16130 +       bool    "UID16/GID32"
16131 +       help
16132 +         reduces UID to 16 bit, but leaves GID at 32 bit.
16133 +
16134 +config TAGGING_GID16
16135 +       bool    "UID32/GID16"
16136 +       help
16137 +         reduces GID to 16 bit, but leaves UID at 32 bit.
16138 +
16139 +config TAGGING_ID24
16140 +       bool    "UID24/GID24"
16141 +       help
16142 +         uses the upper 8bit from UID and GID for XID tagging
16143 +         which leaves 24bit for UID/GID each, which should be
16144 +         more than sufficient for normal use.
16145 +
16146 +config TAGGING_INTERN
16147 +       bool    "UID32/GID32"
16148 +       help
16149 +         this uses otherwise reserved inode fields in the on
16150 +         disk representation, which limits the use to a few
16151 +         filesystems (currently ext2 and ext3)
16152 +
16153 +endchoice
16154 +
16155 +config TAG_NFSD
16156 +       bool    "Tag NFSD User Auth and Files"
16157 +       default n
16158 +       help
16159 +         Enable this if you do want the in-kernel NFS
16160 +         Server to use the tagging specified above.
16161 +         (will require patched clients too)
16162 +
16163 +config VSERVER_PRIVACY
16164 +       bool    "Honor Privacy Aspects of Guests"
16165 +       default n
16166 +       help
16167 +         When enabled, most context checks will disallow
16168 +         access to structures assigned to a specific context,
16169 +         like ptys or loop devices.
16170 +
16171 +config VSERVER_CONTEXTS
16172 +       int     "Maximum number of Contexts (1-65533)"  if EMBEDDED
16173 +       range 1 65533
16174 +       default "768"   if 64BIT
16175 +       default "256"
16176 +       help
16177 +         This setting will optimize certain data structures
16178 +         and memory allocations according to the expected
16179 +         maximum.
16180 +
16181 +         note: this is not a strict upper limit.
16182 +
16183 +config VSERVER_WARN
16184 +       bool    "VServer Warnings"
16185 +       default y
16186 +       help
16187 +         This enables various runtime warnings, which will
16188 +         notify about potential manipulation attempts or
16189 +         resource shortage. It is generally considered to
16190 +         be a good idea to have that enabled.
16191 +
16192 +config VSERVER_WARN_DEVPTS
16193 +       bool    "VServer DevPTS Warnings"
16194 +       depends on VSERVER_WARN
16195 +       default y
16196 +       help
16197 +         This enables DevPTS related warnings, issued when a
16198 +         process inside a context tries to lookup or access
16199 +         a dynamic pts from the host or a different context.
16200 +
16201 +config VSERVER_DEBUG
16202 +       bool    "VServer Debugging Code"
16203 +       default n
16204 +       help
16205 +         Set this to yes if you want to be able to activate
16206 +         debugging output at runtime. It adds a very small
16207 +         overhead to all vserver related functions and
16208 +         increases the kernel size by about 20k.
16209 +
16210 +config VSERVER_HISTORY
16211 +       bool    "VServer History Tracing"
16212 +       depends on VSERVER_DEBUG
16213 +       default n
16214 +       help
16215 +         Set this to yes if you want to record the history of
16216 +         linux-vserver activities, so they can be replayed in
16217 +         the event of a kernel panic or oops.
16218 +
16219 +config VSERVER_HISTORY_SIZE
16220 +       int     "Per-CPU History Size (32-65536)"
16221 +       depends on VSERVER_HISTORY
16222 +       range 32 65536
16223 +       default 64
16224 +       help
16225 +         This allows you to specify the number of entries in
16226 +         the per-CPU history buffer.
16227 +
16228 +config VSERVER_LEGACY_MEM
16229 +       bool    "Legacy Memory Limits"
16230 +       default n
16231 +       help
16232 +         This provides fake memory limits to keep
16233 +         older tools happy in the face of memory
16234 +         cgroups
16235 +
16236 +choice
16237 +       prompt  "Quotes used in debug and warn messages"
16238 +       default QUOTES_ISO8859
16239 +
16240 +config QUOTES_ISO8859
16241 +       bool    "Extended ASCII (ISO 8859) angle quotes"
16242 +       help
16243 +         This uses the extended ASCII characters \xbb
16244 +         and \xab for quoting file and process names.
16245 +
16246 +config QUOTES_UTF8
16247 +       bool    "UTF-8 angle quotes"
16248 +       help
16249 +         This uses the the UTF-8 sequences for angle
16250 +         quotes to quote file and process names.
16251 +
16252 +config QUOTES_ASCII
16253 +       bool    "ASCII single quotes"
16254 +       help
16255 +         This uses the ASCII single quote character
16256 +         (\x27) to quote file and process names.
16257 +
16258 +endchoice
16259 +
16260 +endmenu
16261 +
16262 +
16263 +config VSERVER
16264 +       bool
16265 +       default y
16266 +       select NAMESPACES
16267 +       select UTS_NS
16268 +       select IPC_NS
16269 +       select USER_NS
16270 +       select SYSVIPC
16271 +
16272 +config VSERVER_SECURITY
16273 +       bool
16274 +       depends on SECURITY
16275 +       default y
16276 +       select SECURITY_CAPABILITIES
16277 +
16278 diff -NurpP --minimal linux-2.6.38.3/kernel/vserver/Makefile linux-2.6.38.3-vs2.3.0.37-rc14/kernel/vserver/Makefile
16279 --- linux-2.6.38.3/kernel/vserver/Makefile      1970-01-01 01:00:00.000000000 +0100
16280 +++ linux-2.6.38.3-vs2.3.0.37-rc14/kernel/vserver/Makefile      2011-01-29 02:01:07.000000000 +0100
16281 @@ -0,0 +1,18 @@
16282 +#
16283 +# Makefile for the Linux vserver routines.
16284 +#
16285 +
16286 +
16287 +obj-y          += vserver.o
16288 +
16289 +vserver-y      := switch.o context.o space.o sched.o network.o inode.o \
16290 +                  limit.o cvirt.o cacct.o signal.o helper.o init.o \
16291 +                  dlimit.o tag.o
16292 +
16293 +vserver-$(CONFIG_INET) += inet.o
16294 +vserver-$(CONFIG_PROC_FS) += proc.o
16295 +vserver-$(CONFIG_VSERVER_DEBUG) += sysctl.o debug.o
16296 +vserver-$(CONFIG_VSERVER_HISTORY) += history.o
16297 +vserver-$(CONFIG_VSERVER_MONITOR) += monitor.o
16298 +vserver-$(CONFIG_VSERVER_DEVICE) += device.o
16299 +
16300 diff -NurpP --minimal linux-2.6.38.3/kernel/vserver/cacct.c linux-2.6.38.3-vs2.3.0.37-rc14/kernel/vserver/cacct.c
16301 --- linux-2.6.38.3/kernel/vserver/cacct.c       1970-01-01 01:00:00.000000000 +0100
16302 +++ linux-2.6.38.3-vs2.3.0.37-rc14/kernel/vserver/cacct.c       2011-01-29 02:01:07.000000000 +0100
16303 @@ -0,0 +1,42 @@
16304 +/*
16305 + *  linux/kernel/vserver/cacct.c
16306 + *
16307 + *  Virtual Server: Context Accounting
16308 + *
16309 + *  Copyright (C) 2006-2007 Herbert Pötzl
16310 + *
16311 + *  V0.01  added accounting stats
16312 + *
16313 + */
16314 +
16315 +#include <linux/types.h>
16316 +#include <linux/vs_context.h>
16317 +#include <linux/vserver/cacct_cmd.h>
16318 +#include <linux/vserver/cacct_int.h>
16319 +
16320 +#include <asm/errno.h>
16321 +#include <asm/uaccess.h>
16322 +
16323 +
16324 +int vc_sock_stat(struct vx_info *vxi, void __user *data)
16325 +{
16326 +       struct vcmd_sock_stat_v0 vc_data;
16327 +       int j, field;
16328 +
16329 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16330 +               return -EFAULT;
16331 +
16332 +       field = vc_data.field;
16333 +       if ((field < 0) || (field >= VXA_SOCK_SIZE))
16334 +               return -EINVAL;
16335 +
16336 +       for (j = 0; j < 3; j++) {
16337 +               vc_data.count[j] = vx_sock_count(&vxi->cacct, field, j);
16338 +               vc_data.total[j] = vx_sock_total(&vxi->cacct, field, j);
16339 +       }
16340 +
16341 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16342 +               return -EFAULT;
16343 +       return 0;
16344 +}
16345 +
16346 diff -NurpP --minimal linux-2.6.38.3/kernel/vserver/cacct_init.h linux-2.6.38.3-vs2.3.0.37-rc14/kernel/vserver/cacct_init.h
16347 --- linux-2.6.38.3/kernel/vserver/cacct_init.h  1970-01-01 01:00:00.000000000 +0100
16348 +++ linux-2.6.38.3-vs2.3.0.37-rc14/kernel/vserver/cacct_init.h  2011-01-29 02:01:07.000000000 +0100
16349 @@ -0,0 +1,25 @@
16350 +
16351 +
16352 +static inline void vx_info_init_cacct(struct _vx_cacct *cacct)
16353 +{
16354 +       int i, j;
16355 +
16356 +
16357 +       for (i = 0; i < VXA_SOCK_SIZE; i++) {
16358 +               for (j = 0; j < 3; j++) {
16359 +                       atomic_long_set(&cacct->sock[i][j].count, 0);
16360 +                       atomic_long_set(&cacct->sock[i][j].total, 0);
16361 +               }
16362 +       }
16363 +       for (i = 0; i < 8; i++)
16364 +               atomic_set(&cacct->slab[i], 0);
16365 +       for (i = 0; i < 5; i++)
16366 +               for (j = 0; j < 4; j++)
16367 +                       atomic_set(&cacct->page[i][j], 0);
16368 +}
16369 +
16370 +static inline void vx_info_exit_cacct(struct _vx_cacct *cacct)
16371 +{
16372 +       return;
16373 +}
16374 +
16375 diff -NurpP --minimal linux-2.6.38.3/kernel/vserver/cacct_proc.h linux-2.6.38.3-vs2.3.0.37-rc14/kernel/vserver/cacct_proc.h
16376 --- linux-2.6.38.3/kernel/vserver/cacct_proc.h  1970-01-01 01:00:00.000000000 +0100
16377 +++ linux-2.6.38.3-vs2.3.0.37-rc14/kernel/vserver/cacct_proc.h  2011-01-29 02:01:07.000000000 +0100
16378 @@ -0,0 +1,53 @@
16379 +#ifndef _VX_CACCT_PROC_H
16380 +#define _VX_CACCT_PROC_H
16381 +
16382 +#include <linux/vserver/cacct_int.h>
16383 +
16384 +
16385 +#define VX_SOCKA_TOP   \
16386 +       "Type\t    recv #/bytes\t\t   send #/bytes\t\t    fail #/bytes\n"
16387 +
16388 +static inline int vx_info_proc_cacct(struct _vx_cacct *cacct, char *buffer)
16389 +{
16390 +       int i, j, length = 0;
16391 +       static char *type[VXA_SOCK_SIZE] = {
16392 +               "UNSPEC", "UNIX", "INET", "INET6", "PACKET", "OTHER"
16393 +       };
16394 +
16395 +       length += sprintf(buffer + length, VX_SOCKA_TOP);
16396 +       for (i = 0; i < VXA_SOCK_SIZE; i++) {
16397 +               length += sprintf(buffer + length, "%s:", type[i]);
16398 +               for (j = 0; j < 3; j++) {
16399 +                       length += sprintf(buffer + length,
16400 +                               "\t%10lu/%-10lu",
16401 +                               vx_sock_count(cacct, i, j),
16402 +                               vx_sock_total(cacct, i, j));
16403 +               }
16404 +               buffer[length++] = '\n';
16405 +       }
16406 +
16407 +       length += sprintf(buffer + length, "\n");
16408 +       length += sprintf(buffer + length,
16409 +               "slab:\t %8u %8u %8u %8u\n",
16410 +               atomic_read(&cacct->slab[1]),
16411 +               atomic_read(&cacct->slab[4]),
16412 +               atomic_read(&cacct->slab[0]),
16413 +               atomic_read(&cacct->slab[2]));
16414 +
16415 +       length += sprintf(buffer + length, "\n");
16416 +       for (i = 0; i < 5; i++) {
16417 +               length += sprintf(buffer + length,
16418 +                       "page[%d]: %8u %8u %8u %8u\t %8u %8u %8u %8u\n", i,
16419 +                       atomic_read(&cacct->page[i][0]),
16420 +                       atomic_read(&cacct->page[i][1]),
16421 +                       atomic_read(&cacct->page[i][2]),
16422 +                       atomic_read(&cacct->page[i][3]),
16423 +                       atomic_read(&cacct->page[i][4]),
16424 +                       atomic_read(&cacct->page[i][5]),
16425 +                       atomic_read(&cacct->page[i][6]),
16426 +                       atomic_read(&cacct->page[i][7]));
16427 +       }
16428 +       return length;
16429 +}
16430 +
16431 +#endif /* _VX_CACCT_PROC_H */
16432 diff -NurpP --minimal linux-2.6.38.3/kernel/vserver/context.c linux-2.6.38.3-vs2.3.0.37-rc14/kernel/vserver/context.c
16433 --- linux-2.6.38.3/kernel/vserver/context.c     1970-01-01 01:00:00.000000000 +0100
16434 +++ linux-2.6.38.3-vs2.3.0.37-rc14/kernel/vserver/context.c     2011-03-22 17:35:46.000000000 +0100
16435 @@ -0,0 +1,1079 @@
16436 +/*
16437 + *  linux/kernel/vserver/context.c
16438 + *
16439 + *  Virtual Server: Context Support
16440 + *
16441 + *  Copyright (C) 2003-2010  Herbert Pötzl
16442 + *
16443 + *  V0.01  context helper
16444 + *  V0.02  vx_ctx_kill syscall command
16445 + *  V0.03  replaced context_info calls
16446 + *  V0.04  redesign of struct (de)alloc
16447 + *  V0.05  rlimit basic implementation
16448 + *  V0.06  task_xid and info commands
16449 + *  V0.07  context flags and caps
16450 + *  V0.08  switch to RCU based hash
16451 + *  V0.09  revert to non RCU for now
16452 + *  V0.10  and back to working RCU hash
16453 + *  V0.11  and back to locking again
16454 + *  V0.12  referenced context store
16455 + *  V0.13  separate per cpu data
16456 + *  V0.14  changed vcmds to vxi arg
16457 + *  V0.15  added context stat
16458 + *  V0.16  have __create claim() the vxi
16459 + *  V0.17  removed older and legacy stuff
16460 + *  V0.18  added user credentials
16461 + *
16462 + */
16463 +
16464 +#include <linux/slab.h>
16465 +#include <linux/types.h>
16466 +#include <linux/security.h>
16467 +#include <linux/pid_namespace.h>
16468 +
16469 +#include <linux/vserver/context.h>
16470 +#include <linux/vserver/network.h>
16471 +#include <linux/vserver/debug.h>
16472 +#include <linux/vserver/limit.h>
16473 +#include <linux/vserver/limit_int.h>
16474 +#include <linux/vserver/space.h>
16475 +#include <linux/init_task.h>
16476 +#include <linux/fs_struct.h>
16477 +#include <linux/cred.h>
16478 +
16479 +#include <linux/vs_context.h>
16480 +#include <linux/vs_limit.h>
16481 +#include <linux/vs_pid.h>
16482 +#include <linux/vserver/context_cmd.h>
16483 +
16484 +#include "cvirt_init.h"
16485 +#include "cacct_init.h"
16486 +#include "limit_init.h"
16487 +#include "sched_init.h"
16488 +
16489 +
16490 +atomic_t vx_global_ctotal      = ATOMIC_INIT(0);
16491 +atomic_t vx_global_cactive     = ATOMIC_INIT(0);
16492 +
16493 +
16494 +/*     now inactive context structures */
16495 +
16496 +static struct hlist_head vx_info_inactive = HLIST_HEAD_INIT;
16497 +
16498 +static spinlock_t vx_info_inactive_lock = SPIN_LOCK_UNLOCKED;
16499 +
16500 +
16501 +/*     __alloc_vx_info()
16502 +
16503 +       * allocate an initialized vx_info struct
16504 +       * doesn't make it visible (hash)                        */
16505 +
16506 +static struct vx_info *__alloc_vx_info(xid_t xid)
16507 +{
16508 +       struct vx_info *new = NULL;
16509 +       int cpu, index;
16510 +
16511 +       vxdprintk(VXD_CBIT(xid, 0), "alloc_vx_info(%d)*", xid);
16512 +
16513 +       /* would this benefit from a slab cache? */
16514 +       new = kmalloc(sizeof(struct vx_info), GFP_KERNEL);
16515 +       if (!new)
16516 +               return 0;
16517 +
16518 +       memset(new, 0, sizeof(struct vx_info));
16519 +#ifdef CONFIG_SMP
16520 +       new->ptr_pc = alloc_percpu(struct _vx_info_pc);
16521 +       if (!new->ptr_pc)
16522 +               goto error;
16523 +#endif
16524 +       new->vx_id = xid;
16525 +       INIT_HLIST_NODE(&new->vx_hlist);
16526 +       atomic_set(&new->vx_usecnt, 0);
16527 +       atomic_set(&new->vx_tasks, 0);
16528 +       new->vx_parent = NULL;
16529 +       new->vx_state = 0;
16530 +       init_waitqueue_head(&new->vx_wait);
16531 +
16532 +       /* prepare reaper */
16533 +       get_task_struct(init_pid_ns.child_reaper);
16534 +       new->vx_reaper = init_pid_ns.child_reaper;
16535 +       new->vx_badness_bias = 0;
16536 +
16537 +       /* rest of init goes here */
16538 +       vx_info_init_limit(&new->limit);
16539 +       vx_info_init_sched(&new->sched);
16540 +       vx_info_init_cvirt(&new->cvirt);
16541 +       vx_info_init_cacct(&new->cacct);
16542 +
16543 +       /* per cpu data structures */
16544 +       for_each_possible_cpu(cpu) {
16545 +               vx_info_init_sched_pc(
16546 +                       &vx_per_cpu(new, sched_pc, cpu), cpu);
16547 +               vx_info_init_cvirt_pc(
16548 +                       &vx_per_cpu(new, cvirt_pc, cpu), cpu);
16549 +       }
16550 +
16551 +       new->vx_flags = VXF_INIT_SET;
16552 +       cap_set_init_eff(new->vx_bcaps);
16553 +       new->vx_ccaps = 0;
16554 +       new->vx_umask = 0;
16555 +
16556 +       new->reboot_cmd = 0;
16557 +       new->exit_code = 0;
16558 +
16559 +       // preconfig spaces
16560 +       for (index = 0; index < VX_SPACES; index++) {
16561 +               struct _vx_space *space = &new->space[index];
16562 +
16563 +               // filesystem
16564 +               spin_lock(&init_fs.lock);
16565 +               init_fs.users++;
16566 +               spin_unlock(&init_fs.lock);
16567 +               space->vx_fs = &init_fs;
16568 +
16569 +               /* FIXME: do we want defaults? */
16570 +               // space->vx_real_cred = 0;
16571 +               // space->vx_cred = 0;
16572 +       }
16573 +
16574 +
16575 +       vxdprintk(VXD_CBIT(xid, 0),
16576 +               "alloc_vx_info(%d) = %p", xid, new);
16577 +       vxh_alloc_vx_info(new);
16578 +       atomic_inc(&vx_global_ctotal);
16579 +       return new;
16580 +#ifdef CONFIG_SMP
16581 +error:
16582 +       kfree(new);
16583 +       return 0;
16584 +#endif
16585 +}
16586 +
16587 +/*     __dealloc_vx_info()
16588 +
16589 +       * final disposal of vx_info                             */
16590 +
16591 +static void __dealloc_vx_info(struct vx_info *vxi)
16592 +{
16593 +#ifdef CONFIG_VSERVER_WARN
16594 +       struct vx_info_save vxis;
16595 +       int cpu;
16596 +#endif
16597 +       vxdprintk(VXD_CBIT(xid, 0),
16598 +               "dealloc_vx_info(%p)", vxi);
16599 +       vxh_dealloc_vx_info(vxi);
16600 +
16601 +#ifdef CONFIG_VSERVER_WARN
16602 +       enter_vx_info(vxi, &vxis);
16603 +       vx_info_exit_limit(&vxi->limit);
16604 +       vx_info_exit_sched(&vxi->sched);
16605 +       vx_info_exit_cvirt(&vxi->cvirt);
16606 +       vx_info_exit_cacct(&vxi->cacct);
16607 +
16608 +       for_each_possible_cpu(cpu) {
16609 +               vx_info_exit_sched_pc(
16610 +                       &vx_per_cpu(vxi, sched_pc, cpu), cpu);
16611 +               vx_info_exit_cvirt_pc(
16612 +                       &vx_per_cpu(vxi, cvirt_pc, cpu), cpu);
16613 +       }
16614 +       leave_vx_info(&vxis);
16615 +#endif
16616 +
16617 +       vxi->vx_id = -1;
16618 +       vxi->vx_state |= VXS_RELEASED;
16619 +
16620 +#ifdef CONFIG_SMP
16621 +       free_percpu(vxi->ptr_pc);
16622 +#endif
16623 +       kfree(vxi);
16624 +       atomic_dec(&vx_global_ctotal);
16625 +}
16626 +
16627 +static void __shutdown_vx_info(struct vx_info *vxi)
16628 +{
16629 +       struct nsproxy *nsproxy;
16630 +       struct fs_struct *fs;
16631 +       struct cred *cred;
16632 +       int index, kill;
16633 +
16634 +       might_sleep();
16635 +
16636 +       vxi->vx_state |= VXS_SHUTDOWN;
16637 +       vs_state_change(vxi, VSC_SHUTDOWN);
16638 +
16639 +       for (index = 0; index < VX_SPACES; index++) {
16640 +               struct _vx_space *space = &vxi->space[index];
16641 +
16642 +               nsproxy = xchg(&space->vx_nsproxy, NULL);
16643 +               if (nsproxy)
16644 +                       put_nsproxy(nsproxy);
16645 +
16646 +               fs = xchg(&space->vx_fs, NULL);
16647 +               spin_lock(&fs->lock);
16648 +               kill = !--fs->users;
16649 +               spin_unlock(&fs->lock);
16650 +               if (kill)
16651 +                       free_fs_struct(fs);
16652 +
16653 +               cred = (struct cred *)xchg(&space->vx_cred, NULL);
16654 +               if (cred)
16655 +                       abort_creds(cred);
16656 +       }
16657 +}
16658 +
16659 +/* exported stuff */
16660 +
16661 +void free_vx_info(struct vx_info *vxi)
16662 +{
16663 +       unsigned long flags;
16664 +       unsigned index;
16665 +
16666 +       /* check for reference counts first */
16667 +       BUG_ON(atomic_read(&vxi->vx_usecnt));
16668 +       BUG_ON(atomic_read(&vxi->vx_tasks));
16669 +
16670 +       /* context must not be hashed */
16671 +       BUG_ON(vx_info_state(vxi, VXS_HASHED));
16672 +
16673 +       /* context shutdown is mandatory */
16674 +       BUG_ON(!vx_info_state(vxi, VXS_SHUTDOWN));
16675 +
16676 +       /* spaces check */
16677 +       for (index = 0; index < VX_SPACES; index++) {
16678 +               struct _vx_space *space = &vxi->space[index];
16679 +
16680 +               BUG_ON(space->vx_nsproxy);
16681 +               BUG_ON(space->vx_fs);
16682 +               // BUG_ON(space->vx_real_cred);
16683 +               // BUG_ON(space->vx_cred);
16684 +       }
16685 +
16686 +       spin_lock_irqsave(&vx_info_inactive_lock, flags);
16687 +       hlist_del(&vxi->vx_hlist);
16688 +       spin_unlock_irqrestore(&vx_info_inactive_lock, flags);
16689 +
16690 +       __dealloc_vx_info(vxi);
16691 +}
16692 +
16693 +
16694 +/*     hash table for vx_info hash */
16695 +
16696 +#define VX_HASH_SIZE   13
16697 +
16698 +static struct hlist_head vx_info_hash[VX_HASH_SIZE] =
16699 +       { [0 ... VX_HASH_SIZE-1] = HLIST_HEAD_INIT };
16700 +
16701 +static spinlock_t vx_info_hash_lock = SPIN_LOCK_UNLOCKED;
16702 +
16703 +
16704 +static inline unsigned int __hashval(xid_t xid)
16705 +{
16706 +       return (xid % VX_HASH_SIZE);
16707 +}
16708 +
16709 +
16710 +
16711 +/*     __hash_vx_info()
16712 +
16713 +       * add the vxi to the global hash table
16714 +       * requires the hash_lock to be held                     */
16715 +
16716 +static inline void __hash_vx_info(struct vx_info *vxi)
16717 +{
16718 +       struct hlist_head *head;
16719 +
16720 +       vxd_assert_lock(&vx_info_hash_lock);
16721 +       vxdprintk(VXD_CBIT(xid, 4),
16722 +               "__hash_vx_info: %p[#%d]", vxi, vxi->vx_id);
16723 +       vxh_hash_vx_info(vxi);
16724 +
16725 +       /* context must not be hashed */
16726 +       BUG_ON(vx_info_state(vxi, VXS_HASHED));
16727 +
16728 +       vxi->vx_state |= VXS_HASHED;
16729 +       head = &vx_info_hash[__hashval(vxi->vx_id)];
16730 +       hlist_add_head(&vxi->vx_hlist, head);
16731 +       atomic_inc(&vx_global_cactive);
16732 +}
16733 +
16734 +/*     __unhash_vx_info()
16735 +
16736 +       * remove the vxi from the global hash table
16737 +       * requires the hash_lock to be held                     */
16738 +
16739 +static inline void __unhash_vx_info(struct vx_info *vxi)
16740 +{
16741 +       unsigned long flags;
16742 +
16743 +       vxd_assert_lock(&vx_info_hash_lock);
16744 +       vxdprintk(VXD_CBIT(xid, 4),
16745 +               "__unhash_vx_info: %p[#%d.%d.%d]", vxi, vxi->vx_id,
16746 +               atomic_read(&vxi->vx_usecnt), atomic_read(&vxi->vx_tasks));
16747 +       vxh_unhash_vx_info(vxi);
16748 +
16749 +       /* context must be hashed */
16750 +       BUG_ON(!vx_info_state(vxi, VXS_HASHED));
16751 +       /* but without tasks */
16752 +       BUG_ON(atomic_read(&vxi->vx_tasks));
16753 +
16754 +       vxi->vx_state &= ~VXS_HASHED;
16755 +       hlist_del_init(&vxi->vx_hlist);
16756 +       spin_lock_irqsave(&vx_info_inactive_lock, flags);
16757 +       hlist_add_head(&vxi->vx_hlist, &vx_info_inactive);
16758 +       spin_unlock_irqrestore(&vx_info_inactive_lock, flags);
16759 +       atomic_dec(&vx_global_cactive);
16760 +}
16761 +
16762 +
16763 +/*     __lookup_vx_info()
16764 +
16765 +       * requires the hash_lock to be held
16766 +       * doesn't increment the vx_refcnt                       */
16767 +
16768 +static inline struct vx_info *__lookup_vx_info(xid_t xid)
16769 +{
16770 +       struct hlist_head *head = &vx_info_hash[__hashval(xid)];
16771 +       struct hlist_node *pos;
16772 +       struct vx_info *vxi;
16773 +
16774 +       vxd_assert_lock(&vx_info_hash_lock);
16775 +       hlist_for_each(pos, head) {
16776 +               vxi = hlist_entry(pos, struct vx_info, vx_hlist);
16777 +
16778 +               if (vxi->vx_id == xid)
16779 +                       goto found;
16780 +       }
16781 +       vxi = NULL;
16782 +found:
16783 +       vxdprintk(VXD_CBIT(xid, 0),
16784 +               "__lookup_vx_info(#%u): %p[#%u]",
16785 +               xid, vxi, vxi ? vxi->vx_id : 0);
16786 +       vxh_lookup_vx_info(vxi, xid);
16787 +       return vxi;
16788 +}
16789 +
16790 +
16791 +/*     __create_vx_info()
16792 +
16793 +       * create the requested context
16794 +       * get(), claim() and hash it                            */
16795 +
16796 +static struct vx_info *__create_vx_info(int id)
16797 +{
16798 +       struct vx_info *new, *vxi = NULL;
16799 +
16800 +       vxdprintk(VXD_CBIT(xid, 1), "create_vx_info(%d)*", id);
16801 +
16802 +       if (!(new = __alloc_vx_info(id)))
16803 +               return ERR_PTR(-ENOMEM);
16804 +
16805 +       /* required to make dynamic xids unique */
16806 +       spin_lock(&vx_info_hash_lock);
16807 +
16808 +       /* static context requested */
16809 +       if ((vxi = __lookup_vx_info(id))) {
16810 +               vxdprintk(VXD_CBIT(xid, 0),
16811 +                       "create_vx_info(%d) = %p (already there)", id, vxi);
16812 +               if (vx_info_flags(vxi, VXF_STATE_SETUP, 0))
16813 +                       vxi = ERR_PTR(-EBUSY);
16814 +               else
16815 +                       vxi = ERR_PTR(-EEXIST);
16816 +               goto out_unlock;
16817 +       }
16818 +       /* new context */
16819 +       vxdprintk(VXD_CBIT(xid, 0),
16820 +               "create_vx_info(%d) = %p (new)", id, new);
16821 +       claim_vx_info(new, NULL);
16822 +       __hash_vx_info(get_vx_info(new));
16823 +       vxi = new, new = NULL;
16824 +
16825 +out_unlock:
16826 +       spin_unlock(&vx_info_hash_lock);
16827 +       vxh_create_vx_info(IS_ERR(vxi) ? NULL : vxi, id);
16828 +       if (new)
16829 +               __dealloc_vx_info(new);
16830 +       return vxi;
16831 +}
16832 +
16833 +
16834 +/*     exported stuff                                          */
16835 +
16836 +
16837 +void unhash_vx_info(struct vx_info *vxi)
16838 +{
16839 +       __shutdown_vx_info(vxi);
16840 +       spin_lock(&vx_info_hash_lock);
16841 +       __unhash_vx_info(vxi);
16842 +       spin_unlock(&vx_info_hash_lock);
16843 +       __wakeup_vx_info(vxi);
16844 +}
16845 +
16846 +
16847 +/*     lookup_vx_info()
16848 +
16849 +       * search for a vx_info and get() it
16850 +       * negative id means current                             */
16851 +
16852 +struct vx_info *lookup_vx_info(int id)
16853 +{
16854 +       struct vx_info *vxi = NULL;
16855 +
16856 +       if (id < 0) {
16857 +               vxi = get_vx_info(current_vx_info());
16858 +       } else if (id > 1) {
16859 +               spin_lock(&vx_info_hash_lock);
16860 +               vxi = get_vx_info(__lookup_vx_info(id));
16861 +               spin_unlock(&vx_info_hash_lock);
16862 +       }
16863 +       return vxi;
16864 +}
16865 +
16866 +/*     xid_is_hashed()
16867 +
16868 +       * verify that xid is still hashed                       */
16869 +
16870 +int xid_is_hashed(xid_t xid)
16871 +{
16872 +       int hashed;
16873 +
16874 +       spin_lock(&vx_info_hash_lock);
16875 +       hashed = (__lookup_vx_info(xid) != NULL);
16876 +       spin_unlock(&vx_info_hash_lock);
16877 +       return hashed;
16878 +}
16879 +
16880 +#ifdef CONFIG_PROC_FS
16881 +
16882 +/*     get_xid_list()
16883 +
16884 +       * get a subset of hashed xids for proc
16885 +       * assumes size is at least one                          */
16886 +
16887 +int get_xid_list(int index, unsigned int *xids, int size)
16888 +{
16889 +       int hindex, nr_xids = 0;
16890 +
16891 +       /* only show current and children */
16892 +       if (!vx_check(0, VS_ADMIN | VS_WATCH)) {
16893 +               if (index > 0)
16894 +                       return 0;
16895 +               xids[nr_xids] = vx_current_xid();
16896 +               return 1;
16897 +       }
16898 +
16899 +       for (hindex = 0; hindex < VX_HASH_SIZE; hindex++) {
16900 +               struct hlist_head *head = &vx_info_hash[hindex];
16901 +               struct hlist_node *pos;
16902 +
16903 +               spin_lock(&vx_info_hash_lock);
16904 +               hlist_for_each(pos, head) {
16905 +                       struct vx_info *vxi;
16906 +
16907 +                       if (--index > 0)
16908 +                               continue;
16909 +
16910 +                       vxi = hlist_entry(pos, struct vx_info, vx_hlist);
16911 +                       xids[nr_xids] = vxi->vx_id;
16912 +                       if (++nr_xids >= size) {
16913 +                               spin_unlock(&vx_info_hash_lock);
16914 +                               goto out;
16915 +                       }
16916 +               }
16917 +               /* keep the lock time short */
16918 +               spin_unlock(&vx_info_hash_lock);
16919 +       }
16920 +out:
16921 +       return nr_xids;
16922 +}
16923 +#endif
16924 +
16925 +#ifdef CONFIG_VSERVER_DEBUG
16926 +
16927 +void   dump_vx_info_inactive(int level)
16928 +{
16929 +       struct hlist_node *entry, *next;
16930 +
16931 +       hlist_for_each_safe(entry, next, &vx_info_inactive) {
16932 +               struct vx_info *vxi =
16933 +                       list_entry(entry, struct vx_info, vx_hlist);
16934 +
16935 +               dump_vx_info(vxi, level);
16936 +       }
16937 +}
16938 +
16939 +#endif
16940 +
16941 +#if 0
16942 +int vx_migrate_user(struct task_struct *p, struct vx_info *vxi)
16943 +{
16944 +       struct user_struct *new_user, *old_user;
16945 +
16946 +       if (!p || !vxi)
16947 +               BUG();
16948 +
16949 +       if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0))
16950 +               return -EACCES;
16951 +
16952 +       new_user = alloc_uid(vxi->vx_id, p->uid);
16953 +       if (!new_user)
16954 +               return -ENOMEM;
16955 +
16956 +       old_user = p->user;
16957 +       if (new_user != old_user) {
16958 +               atomic_inc(&new_user->processes);
16959 +               atomic_dec(&old_user->processes);
16960 +               p->user = new_user;
16961 +       }
16962 +       free_uid(old_user);
16963 +       return 0;
16964 +}
16965 +#endif
16966 +
16967 +#if 0
16968 +void vx_mask_cap_bset(struct vx_info *vxi, struct task_struct *p)
16969 +{
16970 +       // p->cap_effective &= vxi->vx_cap_bset;
16971 +       p->cap_effective =
16972 +               cap_intersect(p->cap_effective, vxi->cap_bset);
16973 +       // p->cap_inheritable &= vxi->vx_cap_bset;
16974 +       p->cap_inheritable =
16975 +               cap_intersect(p->cap_inheritable, vxi->cap_bset);
16976 +       // p->cap_permitted &= vxi->vx_cap_bset;
16977 +       p->cap_permitted =
16978 +               cap_intersect(p->cap_permitted, vxi->cap_bset);
16979 +}
16980 +#endif
16981 +
16982 +
16983 +#include <linux/file.h>
16984 +#include <linux/fdtable.h>
16985 +
16986 +static int vx_openfd_task(struct task_struct *tsk)
16987 +{
16988 +       struct files_struct *files = tsk->files;
16989 +       struct fdtable *fdt;
16990 +       const unsigned long *bptr;
16991 +       int count, total;
16992 +
16993 +       /* no rcu_read_lock() because of spin_lock() */
16994 +       spin_lock(&files->file_lock);
16995 +       fdt = files_fdtable(files);
16996 +       bptr = fdt->open_fds->fds_bits;
16997 +       count = fdt->max_fds / (sizeof(unsigned long) * 8);
16998 +       for (total = 0; count > 0; count--) {
16999 +               if (*bptr)
17000 +                       total += hweight_long(*bptr);
17001 +               bptr++;
17002 +       }
17003 +       spin_unlock(&files->file_lock);
17004 +       return total;
17005 +}
17006 +
17007 +
17008 +/*     for *space compatibility */
17009 +
17010 +asmlinkage long sys_unshare(unsigned long);
17011 +
17012 +/*
17013 + *     migrate task to new context
17014 + *     gets vxi, puts old_vxi on change
17015 + *     optionally unshares namespaces (hack)
17016 + */
17017 +
17018 +int vx_migrate_task(struct task_struct *p, struct vx_info *vxi, int unshare)
17019 +{
17020 +       struct vx_info *old_vxi;
17021 +       int ret = 0;
17022 +
17023 +       if (!p || !vxi)
17024 +               BUG();
17025 +
17026 +       vxdprintk(VXD_CBIT(xid, 5),
17027 +               "vx_migrate_task(%p,%p[#%d.%d])", p, vxi,
17028 +               vxi->vx_id, atomic_read(&vxi->vx_usecnt));
17029 +
17030 +       if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0) &&
17031 +               !vx_info_flags(vxi, VXF_STATE_SETUP, 0))
17032 +               return -EACCES;
17033 +
17034 +       if (vx_info_state(vxi, VXS_SHUTDOWN))
17035 +               return -EFAULT;
17036 +
17037 +       old_vxi = task_get_vx_info(p);
17038 +       if (old_vxi == vxi)
17039 +               goto out;
17040 +
17041 +//     if (!(ret = vx_migrate_user(p, vxi))) {
17042 +       {
17043 +               int openfd;
17044 +
17045 +               task_lock(p);
17046 +               openfd = vx_openfd_task(p);
17047 +
17048 +               if (old_vxi) {
17049 +                       atomic_dec(&old_vxi->cvirt.nr_threads);
17050 +                       atomic_dec(&old_vxi->cvirt.nr_running);
17051 +                       __rlim_dec(&old_vxi->limit, RLIMIT_NPROC);
17052 +                       /* FIXME: what about the struct files here? */
17053 +                       __rlim_sub(&old_vxi->limit, VLIMIT_OPENFD, openfd);
17054 +                       /* account for the executable */
17055 +                       __rlim_dec(&old_vxi->limit, VLIMIT_DENTRY);
17056 +               }
17057 +               atomic_inc(&vxi->cvirt.nr_threads);
17058 +               atomic_inc(&vxi->cvirt.nr_running);
17059 +               __rlim_inc(&vxi->limit, RLIMIT_NPROC);
17060 +               /* FIXME: what about the struct files here? */
17061 +               __rlim_add(&vxi->limit, VLIMIT_OPENFD, openfd);
17062 +               /* account for the executable */
17063 +               __rlim_inc(&vxi->limit, VLIMIT_DENTRY);
17064 +
17065 +               if (old_vxi) {
17066 +                       release_vx_info(old_vxi, p);
17067 +                       clr_vx_info(&p->vx_info);
17068 +               }
17069 +               claim_vx_info(vxi, p);
17070 +               set_vx_info(&p->vx_info, vxi);
17071 +               p->xid = vxi->vx_id;
17072 +
17073 +               vxdprintk(VXD_CBIT(xid, 5),
17074 +                       "moved task %p into vxi:%p[#%d]",
17075 +                       p, vxi, vxi->vx_id);
17076 +
17077 +               // vx_mask_cap_bset(vxi, p);
17078 +               task_unlock(p);
17079 +
17080 +               /* hack for *spaces to provide compatibility */
17081 +               if (unshare) {
17082 +                       struct nsproxy *old_nsp, *new_nsp;
17083 +
17084 +                       ret = unshare_nsproxy_namespaces(
17085 +                               CLONE_NEWUTS | CLONE_NEWIPC | CLONE_NEWUSER,
17086 +                               &new_nsp, NULL);
17087 +                       if (ret)
17088 +                               goto out;
17089 +
17090 +                       old_nsp = xchg(&p->nsproxy, new_nsp);
17091 +                       vx_set_space(vxi,
17092 +                               CLONE_NEWUTS | CLONE_NEWIPC | CLONE_NEWUSER, 0);
17093 +                       put_nsproxy(old_nsp);
17094 +               }
17095 +       }
17096 +out:
17097 +       put_vx_info(old_vxi);
17098 +       return ret;
17099 +}
17100 +
17101 +int vx_set_reaper(struct vx_info *vxi, struct task_struct *p)
17102 +{
17103 +       struct task_struct *old_reaper;
17104 +
17105 +       if (!vxi)
17106 +               return -EINVAL;
17107 +
17108 +       vxdprintk(VXD_CBIT(xid, 6),
17109 +               "vx_set_reaper(%p[#%d],%p[#%d,%d])",
17110 +               vxi, vxi->vx_id, p, p->xid, p->pid);
17111 +
17112 +       old_reaper = vxi->vx_reaper;
17113 +       if (old_reaper == p)
17114 +               return 0;
17115 +
17116 +       /* set new child reaper */
17117 +       get_task_struct(p);
17118 +       vxi->vx_reaper = p;
17119 +       put_task_struct(old_reaper);
17120 +       return 0;
17121 +}
17122 +
17123 +int vx_set_init(struct vx_info *vxi, struct task_struct *p)
17124 +{
17125 +       if (!vxi)
17126 +               return -EINVAL;
17127 +
17128 +       vxdprintk(VXD_CBIT(xid, 6),
17129 +               "vx_set_init(%p[#%d],%p[#%d,%d,%d])",
17130 +               vxi, vxi->vx_id, p, p->xid, p->pid, p->tgid);
17131 +
17132 +       vxi->vx_flags &= ~VXF_STATE_INIT;
17133 +       // vxi->vx_initpid = p->tgid;
17134 +       vxi->vx_initpid = p->pid;
17135 +       return 0;
17136 +}
17137 +
17138 +void vx_exit_init(struct vx_info *vxi, struct task_struct *p, int code)
17139 +{
17140 +       vxdprintk(VXD_CBIT(xid, 6),
17141 +               "vx_exit_init(%p[#%d],%p[#%d,%d,%d])",
17142 +               vxi, vxi->vx_id, p, p->xid, p->pid, p->tgid);
17143 +
17144 +       vxi->exit_code = code;
17145 +       vxi->vx_initpid = 0;
17146 +}
17147 +
17148 +
17149 +void vx_set_persistent(struct vx_info *vxi)
17150 +{
17151 +       vxdprintk(VXD_CBIT(xid, 6),
17152 +               "vx_set_persistent(%p[#%d])", vxi, vxi->vx_id);
17153 +
17154 +       get_vx_info(vxi);
17155 +       claim_vx_info(vxi, NULL);
17156 +}
17157 +
17158 +void vx_clear_persistent(struct vx_info *vxi)
17159 +{
17160 +       vxdprintk(VXD_CBIT(xid, 6),
17161 +               "vx_clear_persistent(%p[#%d])", vxi, vxi->vx_id);
17162 +
17163 +       release_vx_info(vxi, NULL);
17164 +       put_vx_info(vxi);
17165 +}
17166 +
17167 +void vx_update_persistent(struct vx_info *vxi)
17168 +{
17169 +       if (vx_info_flags(vxi, VXF_PERSISTENT, 0))
17170 +               vx_set_persistent(vxi);
17171 +       else
17172 +               vx_clear_persistent(vxi);
17173 +}
17174 +
17175 +
17176 +/*     task must be current or locked          */
17177 +
17178 +void   exit_vx_info(struct task_struct *p, int code)
17179 +{
17180 +       struct vx_info *vxi = p->vx_info;
17181 +
17182 +       if (vxi) {
17183 +               atomic_dec(&vxi->cvirt.nr_threads);
17184 +               vx_nproc_dec(p);
17185 +
17186 +               vxi->exit_code = code;
17187 +               release_vx_info(vxi, p);
17188 +       }
17189 +}
17190 +
17191 +void   exit_vx_info_early(struct task_struct *p, int code)
17192 +{
17193 +       struct vx_info *vxi = p->vx_info;
17194 +
17195 +       if (vxi) {
17196 +               if (vxi->vx_initpid == p->pid)
17197 +                       vx_exit_init(vxi, p, code);
17198 +               if (vxi->vx_reaper == p)
17199 +                       vx_set_reaper(vxi, init_pid_ns.child_reaper);
17200 +       }
17201 +}
17202 +
17203 +
17204 +/* vserver syscall commands below here */
17205 +
17206 +/* taks xid and vx_info functions */
17207 +
17208 +#include <asm/uaccess.h>
17209 +
17210 +
17211 +int vc_task_xid(uint32_t id)
17212 +{
17213 +       xid_t xid;
17214 +
17215 +       if (id) {
17216 +               struct task_struct *tsk;
17217 +
17218 +               rcu_read_lock();
17219 +               tsk = find_task_by_real_pid(id);
17220 +               xid = (tsk) ? tsk->xid : -ESRCH;
17221 +               rcu_read_unlock();
17222 +       } else
17223 +               xid = vx_current_xid();
17224 +       return xid;
17225 +}
17226 +
17227 +
17228 +int vc_vx_info(struct vx_info *vxi, void __user *data)
17229 +{
17230 +       struct vcmd_vx_info_v0 vc_data;
17231 +
17232 +       vc_data.xid = vxi->vx_id;
17233 +       vc_data.initpid = vxi->vx_initpid;
17234 +
17235 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
17236 +               return -EFAULT;
17237 +       return 0;
17238 +}
17239 +
17240 +
17241 +int vc_ctx_stat(struct vx_info *vxi, void __user *data)
17242 +{
17243 +       struct vcmd_ctx_stat_v0 vc_data;
17244 +
17245 +       vc_data.usecnt = atomic_read(&vxi->vx_usecnt);
17246 +       vc_data.tasks = atomic_read(&vxi->vx_tasks);
17247 +
17248 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
17249 +               return -EFAULT;
17250 +       return 0;
17251 +}
17252 +
17253 +
17254 +/* context functions */
17255 +
17256 +int vc_ctx_create(uint32_t xid, void __user *data)
17257 +{
17258 +       struct vcmd_ctx_create vc_data = { .flagword = VXF_INIT_SET };
17259 +       struct vx_info *new_vxi;
17260 +       int ret;
17261 +
17262 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
17263 +               return -EFAULT;
17264 +
17265 +       if ((xid > MAX_S_CONTEXT) || (xid < 2))
17266 +               return -EINVAL;
17267 +
17268 +       new_vxi = __create_vx_info(xid);
17269 +       if (IS_ERR(new_vxi))
17270 +               return PTR_ERR(new_vxi);
17271 +
17272 +       /* initial flags */
17273 +       new_vxi->vx_flags = vc_data.flagword;
17274 +
17275 +       ret = -ENOEXEC;
17276 +       if (vs_state_change(new_vxi, VSC_STARTUP))
17277 +               goto out;
17278 +
17279 +       ret = vx_migrate_task(current, new_vxi, (!data));
17280 +       if (ret)
17281 +               goto out;
17282 +
17283 +       /* return context id on success */
17284 +       ret = new_vxi->vx_id;
17285 +
17286 +       /* get a reference for persistent contexts */
17287 +       if ((vc_data.flagword & VXF_PERSISTENT))
17288 +               vx_set_persistent(new_vxi);
17289 +out:
17290 +       release_vx_info(new_vxi, NULL);
17291 +       put_vx_info(new_vxi);
17292 +       return ret;
17293 +}
17294 +
17295 +
17296 +int vc_ctx_migrate(struct vx_info *vxi, void __user *data)
17297 +{
17298 +       struct vcmd_ctx_migrate vc_data = { .flagword = 0 };
17299 +       int ret;
17300 +
17301 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
17302 +               return -EFAULT;
17303 +
17304 +       ret = vx_migrate_task(current, vxi, 0);
17305 +       if (ret)
17306 +               return ret;
17307 +       if (vc_data.flagword & VXM_SET_INIT)
17308 +               ret = vx_set_init(vxi, current);
17309 +       if (ret)
17310 +               return ret;
17311 +       if (vc_data.flagword & VXM_SET_REAPER)
17312 +               ret = vx_set_reaper(vxi, current);
17313 +       return ret;
17314 +}
17315 +
17316 +
17317 +int vc_get_cflags(struct vx_info *vxi, void __user *data)
17318 +{
17319 +       struct vcmd_ctx_flags_v0 vc_data;
17320 +
17321 +       vc_data.flagword = vxi->vx_flags;
17322 +
17323 +       /* special STATE flag handling */
17324 +       vc_data.mask = vs_mask_flags(~0ULL, vxi->vx_flags, VXF_ONE_TIME);
17325 +
17326 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
17327 +               return -EFAULT;
17328 +       return 0;
17329 +}
17330 +
17331 +int vc_set_cflags(struct vx_info *vxi, void __user *data)
17332 +{
17333 +       struct vcmd_ctx_flags_v0 vc_data;
17334 +       uint64_t mask, trigger;
17335 +
17336 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17337 +               return -EFAULT;
17338 +
17339 +       /* special STATE flag handling */
17340 +       mask = vs_mask_mask(vc_data.mask, vxi->vx_flags, VXF_ONE_TIME);
17341 +       trigger = (mask & vxi->vx_flags) ^ (mask & vc_data.flagword);
17342 +
17343 +       if (vxi == current_vx_info()) {
17344 +               /* if (trigger & VXF_STATE_SETUP)
17345 +                       vx_mask_cap_bset(vxi, current); */
17346 +               if (trigger & VXF_STATE_INIT) {
17347 +                       int ret;
17348 +
17349 +                       ret = vx_set_init(vxi, current);
17350 +                       if (ret)
17351 +                               return ret;
17352 +                       ret = vx_set_reaper(vxi, current);
17353 +                       if (ret)
17354 +                               return ret;
17355 +               }
17356 +       }
17357 +
17358 +       vxi->vx_flags = vs_mask_flags(vxi->vx_flags,
17359 +               vc_data.flagword, mask);
17360 +       if (trigger & VXF_PERSISTENT)
17361 +               vx_update_persistent(vxi);
17362 +
17363 +       return 0;
17364 +}
17365 +
17366 +
17367 +static inline uint64_t caps_from_cap_t(kernel_cap_t c)
17368 +{
17369 +       uint64_t v = c.cap[0] | ((uint64_t)c.cap[1] << 32);
17370 +
17371 +       // printk("caps_from_cap_t(%08x:%08x) = %016llx\n", c.cap[1], c.cap[0], v);
17372 +       return v;
17373 +}
17374 +
17375 +static inline kernel_cap_t cap_t_from_caps(uint64_t v)
17376 +{
17377 +       kernel_cap_t c = __cap_empty_set;
17378 +
17379 +       c.cap[0] = v & 0xFFFFFFFF;
17380 +       c.cap[1] = (v >> 32) & 0xFFFFFFFF;
17381 +
17382 +       // printk("cap_t_from_caps(%016llx) = %08x:%08x\n", v, c.cap[1], c.cap[0]);
17383 +       return c;
17384 +}
17385 +
17386 +
17387 +static int do_get_caps(struct vx_info *vxi, uint64_t *bcaps, uint64_t *ccaps)
17388 +{
17389 +       if (bcaps)
17390 +               *bcaps = caps_from_cap_t(vxi->vx_bcaps);
17391 +       if (ccaps)
17392 +               *ccaps = vxi->vx_ccaps;
17393 +
17394 +       return 0;
17395 +}
17396 +
17397 +int vc_get_ccaps(struct vx_info *vxi, void __user *data)
17398 +{
17399 +       struct vcmd_ctx_caps_v1 vc_data;
17400 +       int ret;
17401 +
17402 +       ret = do_get_caps(vxi, NULL, &vc_data.ccaps);
17403 +       if (ret)
17404 +               return ret;
17405 +       vc_data.cmask = ~0ULL;
17406 +
17407 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
17408 +               return -EFAULT;
17409 +       return 0;
17410 +}
17411 +
17412 +static int do_set_caps(struct vx_info *vxi,
17413 +       uint64_t bcaps, uint64_t bmask, uint64_t ccaps, uint64_t cmask)
17414 +{
17415 +       uint64_t bcold = caps_from_cap_t(vxi->vx_bcaps);
17416 +
17417 +#if 0
17418 +       printk("do_set_caps(%16llx, %16llx, %16llx, %16llx)\n",
17419 +               bcaps, bmask, ccaps, cmask);
17420 +#endif
17421 +       vxi->vx_bcaps = cap_t_from_caps(
17422 +               vs_mask_flags(bcold, bcaps, bmask));
17423 +       vxi->vx_ccaps = vs_mask_flags(vxi->vx_ccaps, ccaps, cmask);
17424 +
17425 +       return 0;
17426 +}
17427 +
17428 +int vc_set_ccaps(struct vx_info *vxi, void __user *data)
17429 +{
17430 +       struct vcmd_ctx_caps_v1 vc_data;
17431 +
17432 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17433 +               return -EFAULT;
17434 +
17435 +       return do_set_caps(vxi, 0, 0, vc_data.ccaps, vc_data.cmask);
17436 +}
17437 +
17438 +int vc_get_bcaps(struct vx_info *vxi, void __user *data)
17439 +{
17440 +       struct vcmd_bcaps vc_data;
17441 +       int ret;
17442 +
17443 +       ret = do_get_caps(vxi, &vc_data.bcaps, NULL);
17444 +       if (ret)
17445 +               return ret;
17446 +       vc_data.bmask = ~0ULL;
17447 +
17448 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
17449 +               return -EFAULT;
17450 +       return 0;
17451 +}
17452 +
17453 +int vc_set_bcaps(struct vx_info *vxi, void __user *data)
17454 +{
17455 +       struct vcmd_bcaps vc_data;
17456 +
17457 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17458 +               return -EFAULT;
17459 +
17460 +       return do_set_caps(vxi, vc_data.bcaps, vc_data.bmask, 0, 0);
17461 +}
17462 +
17463 +
17464 +int vc_get_umask(struct vx_info *vxi, void __user *data)
17465 +{
17466 +       struct vcmd_umask vc_data;
17467 +
17468 +       vc_data.umask = vxi->vx_umask;
17469 +       vc_data.mask = ~0ULL;
17470 +
17471 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
17472 +               return -EFAULT;
17473 +       return 0;
17474 +}
17475 +
17476 +int vc_set_umask(struct vx_info *vxi, void __user *data)
17477 +{
17478 +       struct vcmd_umask vc_data;
17479 +
17480 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17481 +               return -EFAULT;
17482 +
17483 +       vxi->vx_umask = vs_mask_flags(vxi->vx_umask,
17484 +               vc_data.umask, vc_data.mask);
17485 +       return 0;
17486 +}
17487 +
17488 +
17489 +int vc_get_badness(struct vx_info *vxi, void __user *data)
17490 +{
17491 +       struct vcmd_badness_v0 vc_data;
17492 +
17493 +       vc_data.bias = vxi->vx_badness_bias;
17494 +
17495 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
17496 +               return -EFAULT;
17497 +       return 0;
17498 +}
17499 +
17500 +int vc_set_badness(struct vx_info *vxi, void __user *data)
17501 +{
17502 +       struct vcmd_badness_v0 vc_data;
17503 +
17504 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17505 +               return -EFAULT;
17506 +
17507 +       vxi->vx_badness_bias = vc_data.bias;
17508 +       return 0;
17509 +}
17510 +
17511 +#include <linux/module.h>
17512 +
17513 +EXPORT_SYMBOL_GPL(free_vx_info);
17514 +
17515 diff -NurpP --minimal linux-2.6.38.3/kernel/vserver/cvirt.c linux-2.6.38.3-vs2.3.0.37-rc14/kernel/vserver/cvirt.c
17516 --- linux-2.6.38.3/kernel/vserver/cvirt.c       1970-01-01 01:00:00.000000000 +0100
17517 +++ linux-2.6.38.3-vs2.3.0.37-rc14/kernel/vserver/cvirt.c       2011-01-29 02:01:07.000000000 +0100
17518 @@ -0,0 +1,303 @@
17519 +/*
17520 + *  linux/kernel/vserver/cvirt.c
17521 + *
17522 + *  Virtual Server: Context Virtualization
17523 + *
17524 + *  Copyright (C) 2004-2007  Herbert Pötzl
17525 + *
17526 + *  V0.01  broken out from limit.c
17527 + *  V0.02  added utsname stuff
17528 + *  V0.03  changed vcmds to vxi arg
17529 + *
17530 + */
17531 +
17532 +#include <linux/types.h>
17533 +#include <linux/utsname.h>
17534 +#include <linux/vs_cvirt.h>
17535 +#include <linux/vserver/switch.h>
17536 +#include <linux/vserver/cvirt_cmd.h>
17537 +
17538 +#include <asm/uaccess.h>
17539 +
17540 +
17541 +void vx_vsi_uptime(struct timespec *uptime, struct timespec *idle)
17542 +{
17543 +       struct vx_info *vxi = current_vx_info();
17544 +
17545 +       set_normalized_timespec(uptime,
17546 +               uptime->tv_sec - vxi->cvirt.bias_uptime.tv_sec,
17547 +               uptime->tv_nsec - vxi->cvirt.bias_uptime.tv_nsec);
17548 +       if (!idle)
17549 +               return;
17550 +       set_normalized_timespec(idle,
17551 +               idle->tv_sec - vxi->cvirt.bias_idle.tv_sec,
17552 +               idle->tv_nsec - vxi->cvirt.bias_idle.tv_nsec);
17553 +       return;
17554 +}
17555 +
17556 +uint64_t vx_idle_jiffies(void)
17557 +{
17558 +       return init_task.utime + init_task.stime;
17559 +}
17560 +
17561 +
17562 +
17563 +static inline uint32_t __update_loadavg(uint32_t load,
17564 +       int wsize, int delta, int n)
17565 +{
17566 +       unsigned long long calc, prev;
17567 +
17568 +       /* just set it to n */
17569 +       if (unlikely(delta >= wsize))
17570 +               return (n << FSHIFT);
17571 +
17572 +       calc = delta * n;
17573 +       calc <<= FSHIFT;
17574 +       prev = (wsize - delta);
17575 +       prev *= load;
17576 +       calc += prev;
17577 +       do_div(calc, wsize);
17578 +       return calc;
17579 +}
17580 +
17581 +
17582 +void vx_update_load(struct vx_info *vxi)
17583 +{
17584 +       uint32_t now, last, delta;
17585 +       unsigned int nr_running, nr_uninterruptible;
17586 +       unsigned int total;
17587 +       unsigned long flags;
17588 +
17589 +       spin_lock_irqsave(&vxi->cvirt.load_lock, flags);
17590 +
17591 +       now = jiffies;
17592 +       last = vxi->cvirt.load_last;
17593 +       delta = now - last;
17594 +
17595 +       if (delta < 5*HZ)
17596 +               goto out;
17597 +
17598 +       nr_running = atomic_read(&vxi->cvirt.nr_running);
17599 +       nr_uninterruptible = atomic_read(&vxi->cvirt.nr_uninterruptible);
17600 +       total = nr_running + nr_uninterruptible;
17601 +
17602 +       vxi->cvirt.load[0] = __update_loadavg(vxi->cvirt.load[0],
17603 +               60*HZ, delta, total);
17604 +       vxi->cvirt.load[1] = __update_loadavg(vxi->cvirt.load[1],
17605 +               5*60*HZ, delta, total);
17606 +       vxi->cvirt.load[2] = __update_loadavg(vxi->cvirt.load[2],
17607 +               15*60*HZ, delta, total);
17608 +
17609 +       vxi->cvirt.load_last = now;
17610 +out:
17611 +       atomic_inc(&vxi->cvirt.load_updates);
17612 +       spin_unlock_irqrestore(&vxi->cvirt.load_lock, flags);
17613 +}
17614 +
17615 +
17616 +/*
17617 + * Commands to do_syslog:
17618 + *
17619 + *      0 -- Close the log.  Currently a NOP.
17620 + *      1 -- Open the log. Currently a NOP.
17621 + *      2 -- Read from the log.
17622 + *      3 -- Read all messages remaining in the ring buffer.
17623 + *      4 -- Read and clear all messages remaining in the ring buffer
17624 + *      5 -- Clear ring buffer.
17625 + *      6 -- Disable printk's to console
17626 + *      7 -- Enable printk's to console
17627 + *      8 -- Set level of messages printed to console
17628 + *      9 -- Return number of unread characters in the log buffer
17629 + *     10 -- Return size of the log buffer
17630 + */
17631 +int vx_do_syslog(int type, char __user *buf, int len)
17632 +{
17633 +       int error = 0;
17634 +       int do_clear = 0;
17635 +       struct vx_info *vxi = current_vx_info();
17636 +       struct _vx_syslog *log;
17637 +
17638 +       if (!vxi)
17639 +               return -EINVAL;
17640 +       log = &vxi->cvirt.syslog;
17641 +
17642 +       switch (type) {
17643 +       case 0:         /* Close log */
17644 +       case 1:         /* Open log */
17645 +               break;
17646 +       case 2:         /* Read from log */
17647 +               error = wait_event_interruptible(log->log_wait,
17648 +                       (log->log_start - log->log_end));
17649 +               if (error)
17650 +                       break;
17651 +               spin_lock_irq(&log->logbuf_lock);
17652 +               spin_unlock_irq(&log->logbuf_lock);
17653 +               break;
17654 +       case 4:         /* Read/clear last kernel messages */
17655 +               do_clear = 1;
17656 +               /* fall through */
17657 +       case 3:         /* Read last kernel messages */
17658 +               return 0;
17659 +
17660 +       case 5:         /* Clear ring buffer */
17661 +               return 0;
17662 +
17663 +       case 6:         /* Disable logging to console */
17664 +       case 7:         /* Enable logging to console */
17665 +       case 8:         /* Set level of messages printed to console */
17666 +               break;
17667 +
17668 +       case 9:         /* Number of chars in the log buffer */
17669 +               return 0;
17670 +       case 10:        /* Size of the log buffer */
17671 +               return 0;
17672 +       default:
17673 +               error = -EINVAL;
17674 +               break;
17675 +       }
17676 +       return error;
17677 +}
17678 +
17679 +
17680 +/* virtual host info names */
17681 +
17682 +static char *vx_vhi_name(struct vx_info *vxi, int id)
17683 +{
17684 +       struct nsproxy *nsproxy;
17685 +       struct uts_namespace *uts;
17686 +
17687 +       if (id == VHIN_CONTEXT)
17688 +               return vxi->vx_name;
17689 +
17690 +       nsproxy = vxi->space[0].vx_nsproxy;
17691 +       if (!nsproxy)
17692 +               return NULL;
17693 +
17694 +       uts = nsproxy->uts_ns;
17695 +       if (!uts)
17696 +               return NULL;
17697 +
17698 +       switch (id) {
17699 +       case VHIN_SYSNAME:
17700 +               return uts->name.sysname;
17701 +       case VHIN_NODENAME:
17702 +               return uts->name.nodename;
17703 +       case VHIN_RELEASE:
17704 +               return uts->name.release;
17705 +       case VHIN_VERSION:
17706 +               return uts->name.version;
17707 +       case VHIN_MACHINE:
17708 +               return uts->name.machine;
17709 +       case VHIN_DOMAINNAME:
17710 +               return uts->name.domainname;
17711 +       default:
17712 +               return NULL;
17713 +       }
17714 +       return NULL;
17715 +}
17716 +
17717 +int vc_set_vhi_name(struct vx_info *vxi, void __user *data)
17718 +{
17719 +       struct vcmd_vhi_name_v0 vc_data;
17720 +       char *name;
17721 +
17722 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17723 +               return -EFAULT;
17724 +
17725 +       name = vx_vhi_name(vxi, vc_data.field);
17726 +       if (!name)
17727 +               return -EINVAL;
17728 +
17729 +       memcpy(name, vc_data.name, 65);
17730 +       return 0;
17731 +}
17732 +
17733 +int vc_get_vhi_name(struct vx_info *vxi, void __user *data)
17734 +{
17735 +       struct vcmd_vhi_name_v0 vc_data;
17736 +       char *name;
17737 +
17738 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17739 +               return -EFAULT;
17740 +
17741 +       name = vx_vhi_name(vxi, vc_data.field);
17742 +       if (!name)
17743 +               return -EINVAL;
17744 +
17745 +       memcpy(vc_data.name, name, 65);
17746 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
17747 +               return -EFAULT;
17748 +       return 0;
17749 +}
17750 +
17751 +
17752 +int vc_virt_stat(struct vx_info *vxi, void __user *data)
17753 +{
17754 +       struct vcmd_virt_stat_v0 vc_data;
17755 +       struct _vx_cvirt *cvirt = &vxi->cvirt;
17756 +       struct timespec uptime;
17757 +
17758 +       do_posix_clock_monotonic_gettime(&uptime);
17759 +       set_normalized_timespec(&uptime,
17760 +               uptime.tv_sec - cvirt->bias_uptime.tv_sec,
17761 +               uptime.tv_nsec - cvirt->bias_uptime.tv_nsec);
17762 +
17763 +       vc_data.offset = timespec_to_ns(&cvirt->bias_ts);
17764 +       vc_data.uptime = timespec_to_ns(&uptime);
17765 +       vc_data.nr_threads = atomic_read(&cvirt->nr_threads);
17766 +       vc_data.nr_running = atomic_read(&cvirt->nr_running);
17767 +       vc_data.nr_uninterruptible = atomic_read(&cvirt->nr_uninterruptible);
17768 +       vc_data.nr_onhold = atomic_read(&cvirt->nr_onhold);
17769 +       vc_data.nr_forks = atomic_read(&cvirt->total_forks);
17770 +       vc_data.load[0] = cvirt->load[0];
17771 +       vc_data.load[1] = cvirt->load[1];
17772 +       vc_data.load[2] = cvirt->load[2];
17773 +
17774 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
17775 +               return -EFAULT;
17776 +       return 0;
17777 +}
17778 +
17779 +
17780 +#ifdef CONFIG_VSERVER_VTIME
17781 +
17782 +/* virtualized time base */
17783 +
17784 +void vx_adjust_timespec(struct timespec *ts)
17785 +{
17786 +       struct vx_info *vxi;
17787 +
17788 +       if (!vx_flags(VXF_VIRT_TIME, 0))
17789 +               return;
17790 +
17791 +       vxi = current_vx_info();
17792 +       ts->tv_sec += vxi->cvirt.bias_ts.tv_sec;
17793 +       ts->tv_nsec += vxi->cvirt.bias_ts.tv_nsec;
17794 +
17795 +       if (ts->tv_nsec >= NSEC_PER_SEC) {
17796 +               ts->tv_sec++;
17797 +               ts->tv_nsec -= NSEC_PER_SEC;
17798 +       } else if (ts->tv_nsec < 0) {
17799 +               ts->tv_sec--;
17800 +               ts->tv_nsec += NSEC_PER_SEC;
17801 +       }
17802 +}
17803 +
17804 +int vx_settimeofday(struct timespec *ts)
17805 +{
17806 +       struct timespec ats, delta;
17807 +       struct vx_info *vxi;
17808 +
17809 +       if (!vx_flags(VXF_VIRT_TIME, 0))
17810 +               return do_settimeofday(ts);
17811 +
17812 +       getnstimeofday(&ats);
17813 +       delta = timespec_sub(*ts, ats);
17814 +
17815 +       vxi = current_vx_info();
17816 +       vxi->cvirt.bias_ts = timespec_add(vxi->cvirt.bias_ts, delta);
17817 +       return 0;
17818 +}
17819 +
17820 +#endif
17821 +
17822 diff -NurpP --minimal linux-2.6.38.3/kernel/vserver/cvirt_init.h linux-2.6.38.3-vs2.3.0.37-rc14/kernel/vserver/cvirt_init.h
17823 --- linux-2.6.38.3/kernel/vserver/cvirt_init.h  1970-01-01 01:00:00.000000000 +0100
17824 +++ linux-2.6.38.3-vs2.3.0.37-rc14/kernel/vserver/cvirt_init.h  2011-03-21 07:21:38.000000000 +0100
17825 @@ -0,0 +1,70 @@
17826 +
17827 +
17828 +extern uint64_t vx_idle_jiffies(void);
17829 +
17830 +static inline void vx_info_init_cvirt(struct _vx_cvirt *cvirt)
17831 +{
17832 +       uint64_t idle_jiffies = vx_idle_jiffies();
17833 +       uint64_t nsuptime;
17834 +
17835 +       do_posix_clock_monotonic_gettime(&cvirt->bias_uptime);
17836 +       nsuptime = (unsigned long long)cvirt->bias_uptime.tv_sec
17837 +               * NSEC_PER_SEC + cvirt->bias_uptime.tv_nsec;
17838 +       cvirt->bias_clock = nsec_to_clock_t(nsuptime);
17839 +       cvirt->bias_ts.tv_sec = 0;
17840 +       cvirt->bias_ts.tv_nsec = 0;
17841 +
17842 +       jiffies_to_timespec(idle_jiffies, &cvirt->bias_idle);
17843 +       atomic_set(&cvirt->nr_threads, 0);
17844 +       atomic_set(&cvirt->nr_running, 0);
17845 +       atomic_set(&cvirt->nr_uninterruptible, 0);
17846 +       atomic_set(&cvirt->nr_onhold, 0);
17847 +
17848 +       spin_lock_init(&cvirt->load_lock);
17849 +       cvirt->load_last = jiffies;
17850 +       atomic_set(&cvirt->load_updates, 0);
17851 +       cvirt->load[0] = 0;
17852 +       cvirt->load[1] = 0;
17853 +       cvirt->load[2] = 0;
17854 +       atomic_set(&cvirt->total_forks, 0);
17855 +
17856 +       spin_lock_init(&cvirt->syslog.logbuf_lock);
17857 +       init_waitqueue_head(&cvirt->syslog.log_wait);
17858 +       cvirt->syslog.log_start = 0;
17859 +       cvirt->syslog.log_end = 0;
17860 +       cvirt->syslog.con_start = 0;
17861 +       cvirt->syslog.logged_chars = 0;
17862 +}
17863 +
17864 +static inline
17865 +void vx_info_init_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc, int cpu)
17866 +{
17867 +       // cvirt_pc->cpustat = { 0 };
17868 +}
17869 +
17870 +static inline void vx_info_exit_cvirt(struct _vx_cvirt *cvirt)
17871 +{
17872 +#ifdef CONFIG_VSERVER_WARN
17873 +       int value;
17874 +#endif
17875 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_threads)),
17876 +               "!!! cvirt: %p[nr_threads] = %d on exit.",
17877 +               cvirt, value);
17878 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_running)),
17879 +               "!!! cvirt: %p[nr_running] = %d on exit.",
17880 +               cvirt, value);
17881 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_uninterruptible)),
17882 +               "!!! cvirt: %p[nr_uninterruptible] = %d on exit.",
17883 +               cvirt, value);
17884 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_onhold)),
17885 +               "!!! cvirt: %p[nr_onhold] = %d on exit.",
17886 +               cvirt, value);
17887 +       return;
17888 +}
17889 +
17890 +static inline
17891 +void vx_info_exit_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc, int cpu)
17892 +{
17893 +       return;
17894 +}
17895 +
17896 diff -NurpP --minimal linux-2.6.38.3/kernel/vserver/cvirt_proc.h linux-2.6.38.3-vs2.3.0.37-rc14/kernel/vserver/cvirt_proc.h
17897 --- linux-2.6.38.3/kernel/vserver/cvirt_proc.h  1970-01-01 01:00:00.000000000 +0100
17898 +++ linux-2.6.38.3-vs2.3.0.37-rc14/kernel/vserver/cvirt_proc.h  2011-01-29 02:01:07.000000000 +0100
17899 @@ -0,0 +1,135 @@
17900 +#ifndef _VX_CVIRT_PROC_H
17901 +#define _VX_CVIRT_PROC_H
17902 +
17903 +#include <linux/nsproxy.h>
17904 +#include <linux/mnt_namespace.h>
17905 +#include <linux/ipc_namespace.h>
17906 +#include <linux/utsname.h>
17907 +#include <linux/ipc.h>
17908 +
17909 +
17910 +static inline
17911 +int vx_info_proc_nsproxy(struct nsproxy *nsproxy, char *buffer)
17912 +{
17913 +       struct mnt_namespace *ns;
17914 +       struct uts_namespace *uts;
17915 +       struct ipc_namespace *ipc;
17916 +       struct path path;
17917 +       char *pstr, *root;
17918 +       int length = 0;
17919 +
17920 +       if (!nsproxy)
17921 +               goto out;
17922 +
17923 +       length += sprintf(buffer + length,
17924 +               "NSProxy:\t%p [%p,%p,%p]\n",
17925 +               nsproxy, nsproxy->mnt_ns,
17926 +               nsproxy->uts_ns, nsproxy->ipc_ns);
17927 +
17928 +       ns = nsproxy->mnt_ns;
17929 +       if (!ns)
17930 +               goto skip_ns;
17931 +
17932 +       pstr = kmalloc(PATH_MAX, GFP_KERNEL);
17933 +       if (!pstr)
17934 +               goto skip_ns;
17935 +
17936 +       path.mnt = ns->root;
17937 +       path.dentry = ns->root->mnt_root;
17938 +       root = d_path(&path, pstr, PATH_MAX - 2);
17939 +       length += sprintf(buffer + length,
17940 +               "Namespace:\t%p [#%u]\n"
17941 +               "RootPath:\t%s\n",
17942 +               ns, atomic_read(&ns->count),
17943 +               root);
17944 +       kfree(pstr);
17945 +skip_ns:
17946 +
17947 +       uts = nsproxy->uts_ns;
17948 +       if (!uts)
17949 +               goto skip_uts;
17950 +
17951 +       length += sprintf(buffer + length,
17952 +               "SysName:\t%.*s\n"
17953 +               "NodeName:\t%.*s\n"
17954 +               "Release:\t%.*s\n"
17955 +               "Version:\t%.*s\n"
17956 +               "Machine:\t%.*s\n"
17957 +               "DomainName:\t%.*s\n",
17958 +               __NEW_UTS_LEN, uts->name.sysname,
17959 +               __NEW_UTS_LEN, uts->name.nodename,
17960 +               __NEW_UTS_LEN, uts->name.release,
17961 +               __NEW_UTS_LEN, uts->name.version,
17962 +               __NEW_UTS_LEN, uts->name.machine,
17963 +               __NEW_UTS_LEN, uts->name.domainname);
17964 +skip_uts:
17965 +
17966 +       ipc = nsproxy->ipc_ns;
17967 +       if (!ipc)
17968 +               goto skip_ipc;
17969 +
17970 +       length += sprintf(buffer + length,
17971 +               "SEMS:\t\t%d %d %d %d  %d\n"
17972 +               "MSG:\t\t%d %d %d\n"
17973 +               "SHM:\t\t%lu %lu  %d %d\n",
17974 +               ipc->sem_ctls[0], ipc->sem_ctls[1],
17975 +               ipc->sem_ctls[2], ipc->sem_ctls[3],
17976 +               ipc->used_sems,
17977 +               ipc->msg_ctlmax, ipc->msg_ctlmnb, ipc->msg_ctlmni,
17978 +               (unsigned long)ipc->shm_ctlmax,
17979 +               (unsigned long)ipc->shm_ctlall,
17980 +               ipc->shm_ctlmni, ipc->shm_tot);
17981 +skip_ipc:
17982 +out:
17983 +       return length;
17984 +}
17985 +
17986 +
17987 +#include <linux/sched.h>
17988 +
17989 +#define LOAD_INT(x) ((x) >> FSHIFT)
17990 +#define LOAD_FRAC(x) LOAD_INT(((x) & (FIXED_1 - 1)) * 100)
17991 +
17992 +static inline
17993 +int vx_info_proc_cvirt(struct _vx_cvirt *cvirt, char *buffer)
17994 +{
17995 +       int length = 0;
17996 +       int a, b, c;
17997 +
17998 +       length += sprintf(buffer + length,
17999 +               "BiasUptime:\t%lu.%02lu\n",
18000 +               (unsigned long)cvirt->bias_uptime.tv_sec,
18001 +               (cvirt->bias_uptime.tv_nsec / (NSEC_PER_SEC / 100)));
18002 +
18003 +       a = cvirt->load[0] + (FIXED_1 / 200);
18004 +       b = cvirt->load[1] + (FIXED_1 / 200);
18005 +       c = cvirt->load[2] + (FIXED_1 / 200);
18006 +       length += sprintf(buffer + length,
18007 +               "nr_threads:\t%d\n"
18008 +               "nr_running:\t%d\n"
18009 +               "nr_unintr:\t%d\n"
18010 +               "nr_onhold:\t%d\n"
18011 +               "load_updates:\t%d\n"
18012 +               "loadavg:\t%d.%02d %d.%02d %d.%02d\n"
18013 +               "total_forks:\t%d\n",
18014 +               atomic_read(&cvirt->nr_threads),
18015 +               atomic_read(&cvirt->nr_running),
18016 +               atomic_read(&cvirt->nr_uninterruptible),
18017 +               atomic_read(&cvirt->nr_onhold),
18018 +               atomic_read(&cvirt->load_updates),
18019 +               LOAD_INT(a), LOAD_FRAC(a),
18020 +               LOAD_INT(b), LOAD_FRAC(b),
18021 +               LOAD_INT(c), LOAD_FRAC(c),
18022 +               atomic_read(&cvirt->total_forks));
18023 +       return length;
18024 +}
18025 +
18026 +static inline
18027 +int vx_info_proc_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc,
18028 +       char *buffer, int cpu)
18029 +{
18030 +       int length = 0;
18031 +       return length;
18032 +}
18033 +
18034 +#endif /* _VX_CVIRT_PROC_H */
18035 diff -NurpP --minimal linux-2.6.38.3/kernel/vserver/debug.c linux-2.6.38.3-vs2.3.0.37-rc14/kernel/vserver/debug.c
18036 --- linux-2.6.38.3/kernel/vserver/debug.c       1970-01-01 01:00:00.000000000 +0100
18037 +++ linux-2.6.38.3-vs2.3.0.37-rc14/kernel/vserver/debug.c       2011-01-29 02:01:07.000000000 +0100
18038 @@ -0,0 +1,32 @@
18039 +/*
18040 + *  kernel/vserver/debug.c
18041 + *
18042 + *  Copyright (C) 2005-2007 Herbert Pötzl
18043 + *
18044 + *  V0.01  vx_info dump support
18045 + *
18046 + */
18047 +
18048 +#include <linux/module.h>
18049 +
18050 +#include <linux/vserver/context.h>
18051 +
18052 +
18053 +void   dump_vx_info(struct vx_info *vxi, int level)
18054 +{
18055 +       printk("vx_info %p[#%d, %d.%d, %4x]\n", vxi, vxi->vx_id,
18056 +               atomic_read(&vxi->vx_usecnt),
18057 +               atomic_read(&vxi->vx_tasks),
18058 +               vxi->vx_state);
18059 +       if (level > 0) {
18060 +               __dump_vx_limit(&vxi->limit);
18061 +               __dump_vx_sched(&vxi->sched);
18062 +               __dump_vx_cvirt(&vxi->cvirt);
18063 +               __dump_vx_cacct(&vxi->cacct);
18064 +       }
18065 +       printk("---\n");
18066 +}
18067 +
18068 +
18069 +EXPORT_SYMBOL_GPL(dump_vx_info);
18070 +
18071 diff -NurpP --minimal linux-2.6.38.3/kernel/vserver/device.c linux-2.6.38.3-vs2.3.0.37-rc14/kernel/vserver/device.c
18072 --- linux-2.6.38.3/kernel/vserver/device.c      1970-01-01 01:00:00.000000000 +0100
18073 +++ linux-2.6.38.3-vs2.3.0.37-rc14/kernel/vserver/device.c      2011-01-29 02:01:07.000000000 +0100
18074 @@ -0,0 +1,443 @@
18075 +/*
18076 + *  linux/kernel/vserver/device.c
18077 + *
18078 + *  Linux-VServer: Device Support
18079 + *
18080 + *  Copyright (C) 2006  Herbert Pötzl
18081 + *  Copyright (C) 2007  Daniel Hokka Zakrisson
18082 + *
18083 + *  V0.01  device mapping basics
18084 + *  V0.02  added defaults
18085 + *
18086 + */
18087 +
18088 +#include <linux/slab.h>
18089 +#include <linux/rcupdate.h>
18090 +#include <linux/fs.h>
18091 +#include <linux/namei.h>
18092 +#include <linux/hash.h>
18093 +
18094 +#include <asm/errno.h>
18095 +#include <asm/uaccess.h>
18096 +#include <linux/vserver/base.h>
18097 +#include <linux/vserver/debug.h>
18098 +#include <linux/vserver/context.h>
18099 +#include <linux/vserver/device.h>
18100 +#include <linux/vserver/device_cmd.h>
18101 +
18102 +
18103 +#define DMAP_HASH_BITS 4
18104 +
18105 +
18106 +struct vs_mapping {
18107 +       union {
18108 +               struct hlist_node hlist;
18109 +               struct list_head list;
18110 +       } u;
18111 +#define dm_hlist       u.hlist
18112 +#define dm_list                u.list
18113 +       xid_t xid;
18114 +       dev_t device;
18115 +       struct vx_dmap_target target;
18116 +};
18117 +
18118 +
18119 +static struct hlist_head dmap_main_hash[1 << DMAP_HASH_BITS];
18120 +
18121 +static spinlock_t dmap_main_hash_lock = SPIN_LOCK_UNLOCKED;
18122 +
18123 +static struct vx_dmap_target dmap_defaults[2] = {
18124 +       { .flags = DATTR_OPEN },
18125 +       { .flags = DATTR_OPEN },
18126 +};
18127 +
18128 +
18129 +struct kmem_cache *dmap_cachep __read_mostly;
18130 +
18131 +int __init dmap_cache_init(void)
18132 +{
18133 +       dmap_cachep = kmem_cache_create("dmap_cache",
18134 +               sizeof(struct vs_mapping), 0,
18135 +               SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
18136 +       return 0;
18137 +}
18138 +
18139 +__initcall(dmap_cache_init);
18140 +
18141 +
18142 +static inline unsigned int __hashval(dev_t dev, int bits)
18143 +{
18144 +       return hash_long((unsigned long)dev, bits);
18145 +}
18146 +
18147 +
18148 +/*     __hash_mapping()
18149 + *     add the mapping to the hash table
18150 + */
18151 +static inline void __hash_mapping(struct vx_info *vxi, struct vs_mapping *vdm)
18152 +{
18153 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
18154 +       struct hlist_head *head, *hash = dmap_main_hash;
18155 +       int device = vdm->device;
18156 +
18157 +       spin_lock(hash_lock);
18158 +       vxdprintk(VXD_CBIT(misc, 8), "__hash_mapping: %p[#%d] %08x:%08x",
18159 +               vxi, vxi ? vxi->vx_id : 0, device, vdm->target.target);
18160 +
18161 +       head = &hash[__hashval(device, DMAP_HASH_BITS)];
18162 +       hlist_add_head(&vdm->dm_hlist, head);
18163 +       spin_unlock(hash_lock);
18164 +}
18165 +
18166 +
18167 +static inline int __mode_to_default(umode_t mode)
18168 +{
18169 +       switch (mode) {
18170 +       case S_IFBLK:
18171 +               return 0;
18172 +       case S_IFCHR:
18173 +               return 1;
18174 +       default:
18175 +               BUG();
18176 +       }
18177 +}
18178 +
18179 +
18180 +/*     __set_default()
18181 + *     set a default
18182 + */
18183 +static inline void __set_default(struct vx_info *vxi, umode_t mode,
18184 +       struct vx_dmap_target *vdmt)
18185 +{
18186 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
18187 +       spin_lock(hash_lock);
18188 +
18189 +       if (vxi)
18190 +               vxi->dmap.targets[__mode_to_default(mode)] = *vdmt;
18191 +       else
18192 +               dmap_defaults[__mode_to_default(mode)] = *vdmt;
18193 +
18194 +
18195 +       spin_unlock(hash_lock);
18196 +
18197 +       vxdprintk(VXD_CBIT(misc, 8), "__set_default: %p[#%u] %08x %04x",
18198 +                 vxi, vxi ? vxi->vx_id : 0, vdmt->target, vdmt->flags);
18199 +}
18200 +
18201 +
18202 +/*     __remove_default()
18203 + *     remove a default
18204 + */
18205 +static inline int __remove_default(struct vx_info *vxi, umode_t mode)
18206 +{
18207 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
18208 +       spin_lock(hash_lock);
18209 +
18210 +       if (vxi)
18211 +               vxi->dmap.targets[__mode_to_default(mode)].flags = 0;
18212 +       else    /* remove == reset */
18213 +               dmap_defaults[__mode_to_default(mode)].flags = DATTR_OPEN | mode;
18214 +
18215 +       spin_unlock(hash_lock);
18216 +       return 0;
18217 +}
18218 +
18219 +
18220 +/*     __find_mapping()
18221 + *     find a mapping in the hash table
18222 + *
18223 + *     caller must hold hash_lock
18224 + */
18225 +static inline int __find_mapping(xid_t xid, dev_t device, umode_t mode,
18226 +       struct vs_mapping **local, struct vs_mapping **global)
18227 +{
18228 +       struct hlist_head *hash = dmap_main_hash;
18229 +       struct hlist_head *head = &hash[__hashval(device, DMAP_HASH_BITS)];
18230 +       struct hlist_node *pos;
18231 +       struct vs_mapping *vdm;
18232 +
18233 +       *local = NULL;
18234 +       if (global)
18235 +               *global = NULL;
18236 +
18237 +       hlist_for_each(pos, head) {
18238 +               vdm = hlist_entry(pos, struct vs_mapping, dm_hlist);
18239 +
18240 +               if ((vdm->device == device) &&
18241 +                       !((vdm->target.flags ^ mode) & S_IFMT)) {
18242 +                       if (vdm->xid == xid) {
18243 +                               *local = vdm;
18244 +                               return 1;
18245 +                       } else if (global && vdm->xid == 0)
18246 +                               *global = vdm;
18247 +               }
18248 +       }
18249 +
18250 +       if (global && *global)
18251 +               return 0;
18252 +       else
18253 +               return -ENOENT;
18254 +}
18255 +
18256 +
18257 +/*     __lookup_mapping()
18258 + *     find a mapping and store the result in target and flags
18259 + */
18260 +static inline int __lookup_mapping(struct vx_info *vxi,
18261 +       dev_t device, dev_t *target, int *flags, umode_t mode)
18262 +{
18263 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
18264 +       struct vs_mapping *vdm, *global;
18265 +       struct vx_dmap_target *vdmt;
18266 +       int ret = 0;
18267 +       xid_t xid = vxi->vx_id;
18268 +       int index;
18269 +
18270 +       spin_lock(hash_lock);
18271 +       if (__find_mapping(xid, device, mode, &vdm, &global) > 0) {
18272 +               ret = 1;
18273 +               vdmt = &vdm->target;
18274 +               goto found;
18275 +       }
18276 +
18277 +       index = __mode_to_default(mode);
18278 +       if (vxi && vxi->dmap.targets[index].flags) {
18279 +               ret = 2;
18280 +               vdmt = &vxi->dmap.targets[index];
18281 +       } else if (global) {
18282 +               ret = 3;
18283 +               vdmt = &global->target;
18284 +               goto found;
18285 +       } else {
18286 +               ret = 4;
18287 +               vdmt = &dmap_defaults[index];
18288 +       }
18289 +
18290 +found:
18291 +       if (target && (vdmt->flags & DATTR_REMAP))
18292 +               *target = vdmt->target;
18293 +       else if (target)
18294 +               *target = device;
18295 +       if (flags)
18296 +               *flags = vdmt->flags;
18297 +
18298 +       spin_unlock(hash_lock);
18299 +
18300 +       return ret;
18301 +}
18302 +
18303 +
18304 +/*     __remove_mapping()
18305 + *     remove a mapping from the hash table
18306 + */
18307 +static inline int __remove_mapping(struct vx_info *vxi, dev_t device,
18308 +       umode_t mode)
18309 +{
18310 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
18311 +       struct vs_mapping *vdm = NULL;
18312 +       int ret = 0;
18313 +
18314 +       spin_lock(hash_lock);
18315 +
18316 +       ret = __find_mapping((vxi ? vxi->vx_id : 0), device, mode, &vdm,
18317 +               NULL);
18318 +       vxdprintk(VXD_CBIT(misc, 8), "__remove_mapping: %p[#%d] %08x %04x",
18319 +               vxi, vxi ? vxi->vx_id : 0, device, mode);
18320 +       if (ret < 0)
18321 +               goto out;
18322 +       hlist_del(&vdm->dm_hlist);
18323 +
18324 +out:
18325 +       spin_unlock(hash_lock);
18326 +       if (vdm)
18327 +               kmem_cache_free(dmap_cachep, vdm);
18328 +       return ret;
18329 +}
18330 +
18331 +
18332 +
18333 +int vs_map_device(struct vx_info *vxi,
18334 +       dev_t device, dev_t *target, umode_t mode)
18335 +{
18336 +       int ret, flags = DATTR_MASK;
18337 +
18338 +       if (!vxi) {
18339 +               if (target)
18340 +                       *target = device;
18341 +               goto out;
18342 +       }
18343 +       ret = __lookup_mapping(vxi, device, target, &flags, mode);
18344 +       vxdprintk(VXD_CBIT(misc, 8), "vs_map_device: %08x target: %08x flags: %04x mode: %04x mapped=%d",
18345 +               device, target ? *target : 0, flags, mode, ret);
18346 +out:
18347 +       return (flags & DATTR_MASK);
18348 +}
18349 +
18350 +
18351 +
18352 +static int do_set_mapping(struct vx_info *vxi,
18353 +       dev_t device, dev_t target, int flags, umode_t mode)
18354 +{
18355 +       if (device) {
18356 +               struct vs_mapping *new;
18357 +
18358 +               new = kmem_cache_alloc(dmap_cachep, GFP_KERNEL);
18359 +               if (!new)
18360 +                       return -ENOMEM;
18361 +
18362 +               INIT_HLIST_NODE(&new->dm_hlist);
18363 +               new->device = device;
18364 +               new->target.target = target;
18365 +               new->target.flags = flags | mode;
18366 +               new->xid = (vxi ? vxi->vx_id : 0);
18367 +
18368 +               vxdprintk(VXD_CBIT(misc, 8), "do_set_mapping: %08x target: %08x flags: %04x", device, target, flags);
18369 +               __hash_mapping(vxi, new);
18370 +       } else {
18371 +               struct vx_dmap_target new = {
18372 +                       .target = target,
18373 +                       .flags = flags | mode,
18374 +               };
18375 +               __set_default(vxi, mode, &new);
18376 +       }
18377 +       return 0;
18378 +}
18379 +
18380 +
18381 +static int do_unset_mapping(struct vx_info *vxi,
18382 +       dev_t device, dev_t target, int flags, umode_t mode)
18383 +{
18384 +       int ret = -EINVAL;
18385 +
18386 +       if (device) {
18387 +               ret = __remove_mapping(vxi, device, mode);
18388 +               if (ret < 0)
18389 +                       goto out;
18390 +       } else {
18391 +               ret = __remove_default(vxi, mode);
18392 +               if (ret < 0)
18393 +                       goto out;
18394 +       }
18395 +
18396 +out:
18397 +       return ret;
18398 +}
18399 +
18400 +
18401 +static inline int __user_device(const char __user *name, dev_t *dev,
18402 +       umode_t *mode)
18403 +{
18404 +       struct nameidata nd;
18405 +       int ret;
18406 +
18407 +       if (!name) {
18408 +               *dev = 0;
18409 +               return 0;
18410 +       }
18411 +       ret = user_lpath(name, &nd.path);
18412 +       if (ret)
18413 +               return ret;
18414 +       if (nd.path.dentry->d_inode) {
18415 +               *dev = nd.path.dentry->d_inode->i_rdev;
18416 +               *mode = nd.path.dentry->d_inode->i_mode;
18417 +       }
18418 +       path_put(&nd.path);
18419 +       return 0;
18420 +}
18421 +
18422 +static inline int __mapping_mode(dev_t device, dev_t target,
18423 +       umode_t device_mode, umode_t target_mode, umode_t *mode)
18424 +{
18425 +       if (device)
18426 +               *mode = device_mode & S_IFMT;
18427 +       else if (target)
18428 +               *mode = target_mode & S_IFMT;
18429 +       else
18430 +               return -EINVAL;
18431 +
18432 +       /* if both given, device and target mode have to match */
18433 +       if (device && target &&
18434 +               ((device_mode ^ target_mode) & S_IFMT))
18435 +               return -EINVAL;
18436 +       return 0;
18437 +}
18438 +
18439 +
18440 +static inline int do_mapping(struct vx_info *vxi, const char __user *device_path,
18441 +       const char __user *target_path, int flags, int set)
18442 +{
18443 +       dev_t device = ~0, target = ~0;
18444 +       umode_t device_mode = 0, target_mode = 0, mode;
18445 +       int ret;
18446 +
18447 +       ret = __user_device(device_path, &device, &device_mode);
18448 +       if (ret)
18449 +               return ret;
18450 +       ret = __user_device(target_path, &target, &target_mode);
18451 +       if (ret)
18452 +               return ret;
18453 +
18454 +       ret = __mapping_mode(device, target,
18455 +               device_mode, target_mode, &mode);
18456 +       if (ret)
18457 +               return ret;
18458 +
18459 +       if (set)
18460 +               return do_set_mapping(vxi, device, target,
18461 +                       flags, mode);
18462 +       else
18463 +               return do_unset_mapping(vxi, device, target,
18464 +                       flags, mode);
18465 +}
18466 +
18467 +
18468 +int vc_set_mapping(struct vx_info *vxi, void __user *data)
18469 +{
18470 +       struct vcmd_set_mapping_v0 vc_data;
18471 +
18472 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18473 +               return -EFAULT;
18474 +
18475 +       return do_mapping(vxi, vc_data.device, vc_data.target,
18476 +               vc_data.flags, 1);
18477 +}
18478 +
18479 +int vc_unset_mapping(struct vx_info *vxi, void __user *data)
18480 +{
18481 +       struct vcmd_set_mapping_v0 vc_data;
18482 +
18483 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18484 +               return -EFAULT;
18485 +
18486 +       return do_mapping(vxi, vc_data.device, vc_data.target,
18487 +               vc_data.flags, 0);
18488 +}
18489 +
18490 +
18491 +#ifdef CONFIG_COMPAT
18492 +
18493 +int vc_set_mapping_x32(struct vx_info *vxi, void __user *data)
18494 +{
18495 +       struct vcmd_set_mapping_v0_x32 vc_data;
18496 +
18497 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18498 +               return -EFAULT;
18499 +
18500 +       return do_mapping(vxi, compat_ptr(vc_data.device_ptr),
18501 +               compat_ptr(vc_data.target_ptr), vc_data.flags, 1);
18502 +}
18503 +
18504 +int vc_unset_mapping_x32(struct vx_info *vxi, void __user *data)
18505 +{
18506 +       struct vcmd_set_mapping_v0_x32 vc_data;
18507 +
18508 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18509 +               return -EFAULT;
18510 +
18511 +       return do_mapping(vxi, compat_ptr(vc_data.device_ptr),
18512 +               compat_ptr(vc_data.target_ptr), vc_data.flags, 0);
18513 +}
18514 +
18515 +#endif /* CONFIG_COMPAT */
18516 +
18517 +
18518 diff -NurpP --minimal linux-2.6.38.3/kernel/vserver/dlimit.c linux-2.6.38.3-vs2.3.0.37-rc14/kernel/vserver/dlimit.c
18519 --- linux-2.6.38.3/kernel/vserver/dlimit.c      1970-01-01 01:00:00.000000000 +0100
18520 +++ linux-2.6.38.3-vs2.3.0.37-rc14/kernel/vserver/dlimit.c      2011-01-29 02:01:07.000000000 +0100
18521 @@ -0,0 +1,531 @@
18522 +/*
18523 + *  linux/kernel/vserver/dlimit.c
18524 + *
18525 + *  Virtual Server: Context Disk Limits
18526 + *
18527 + *  Copyright (C) 2004-2009  Herbert Pötzl
18528 + *
18529 + *  V0.01  initial version
18530 + *  V0.02  compat32 splitup
18531 + *  V0.03  extended interface
18532 + *
18533 + */
18534 +
18535 +#include <linux/statfs.h>
18536 +#include <linux/sched.h>
18537 +#include <linux/namei.h>
18538 +#include <linux/vs_tag.h>
18539 +#include <linux/vs_dlimit.h>
18540 +#include <linux/vserver/dlimit_cmd.h>
18541 +#include <linux/slab.h>
18542 +// #include <linux/gfp.h>
18543 +
18544 +#include <asm/uaccess.h>
18545 +
18546 +/*     __alloc_dl_info()
18547 +
18548 +       * allocate an initialized dl_info struct
18549 +       * doesn't make it visible (hash)                        */
18550 +
18551 +static struct dl_info *__alloc_dl_info(struct super_block *sb, tag_t tag)
18552 +{
18553 +       struct dl_info *new = NULL;
18554 +
18555 +       vxdprintk(VXD_CBIT(dlim, 5),
18556 +               "alloc_dl_info(%p,%d)*", sb, tag);
18557 +
18558 +       /* would this benefit from a slab cache? */
18559 +       new = kmalloc(sizeof(struct dl_info), GFP_KERNEL);
18560 +       if (!new)
18561 +               return 0;
18562 +
18563 +       memset(new, 0, sizeof(struct dl_info));
18564 +       new->dl_tag = tag;
18565 +       new->dl_sb = sb;
18566 +       // INIT_RCU_HEAD(&new->dl_rcu);
18567 +       INIT_HLIST_NODE(&new->dl_hlist);
18568 +       spin_lock_init(&new->dl_lock);
18569 +       atomic_set(&new->dl_refcnt, 0);
18570 +       atomic_set(&new->dl_usecnt, 0);
18571 +
18572 +       /* rest of init goes here */
18573 +
18574 +       vxdprintk(VXD_CBIT(dlim, 4),
18575 +               "alloc_dl_info(%p,%d) = %p", sb, tag, new);
18576 +       return new;
18577 +}
18578 +
18579 +/*     __dealloc_dl_info()
18580 +
18581 +       * final disposal of dl_info                             */
18582 +
18583 +static void __dealloc_dl_info(struct dl_info *dli)
18584 +{
18585 +       vxdprintk(VXD_CBIT(dlim, 4),
18586 +               "dealloc_dl_info(%p)", dli);
18587 +
18588 +       dli->dl_hlist.next = LIST_POISON1;
18589 +       dli->dl_tag = -1;
18590 +       dli->dl_sb = 0;
18591 +
18592 +       BUG_ON(atomic_read(&dli->dl_usecnt));
18593 +       BUG_ON(atomic_read(&dli->dl_refcnt));
18594 +
18595 +       kfree(dli);
18596 +}
18597 +
18598 +
18599 +/*     hash table for dl_info hash */
18600 +
18601 +#define DL_HASH_SIZE   13
18602 +
18603 +struct hlist_head dl_info_hash[DL_HASH_SIZE];
18604 +
18605 +static spinlock_t dl_info_hash_lock = SPIN_LOCK_UNLOCKED;
18606 +
18607 +
18608 +static inline unsigned int __hashval(struct super_block *sb, tag_t tag)
18609 +{
18610 +       return ((tag ^ (unsigned long)sb) % DL_HASH_SIZE);
18611 +}
18612 +
18613 +
18614 +
18615 +/*     __hash_dl_info()
18616 +
18617 +       * add the dli to the global hash table
18618 +       * requires the hash_lock to be held                     */
18619 +
18620 +static inline void __hash_dl_info(struct dl_info *dli)
18621 +{
18622 +       struct hlist_head *head;
18623 +
18624 +       vxdprintk(VXD_CBIT(dlim, 6),
18625 +               "__hash_dl_info: %p[#%d]", dli, dli->dl_tag);
18626 +       get_dl_info(dli);
18627 +       head = &dl_info_hash[__hashval(dli->dl_sb, dli->dl_tag)];
18628 +       hlist_add_head_rcu(&dli->dl_hlist, head);
18629 +}
18630 +
18631 +/*     __unhash_dl_info()
18632 +
18633 +       * remove the dli from the global hash table
18634 +       * requires the hash_lock to be held                     */
18635 +
18636 +static inline void __unhash_dl_info(struct dl_info *dli)
18637 +{
18638 +       vxdprintk(VXD_CBIT(dlim, 6),
18639 +               "__unhash_dl_info: %p[#%d]", dli, dli->dl_tag);
18640 +       hlist_del_rcu(&dli->dl_hlist);
18641 +       put_dl_info(dli);
18642 +}
18643 +
18644 +
18645 +/*     __lookup_dl_info()
18646 +
18647 +       * requires the rcu_read_lock()
18648 +       * doesn't increment the dl_refcnt                       */
18649 +
18650 +static inline struct dl_info *__lookup_dl_info(struct super_block *sb, tag_t tag)
18651 +{
18652 +       struct hlist_head *head = &dl_info_hash[__hashval(sb, tag)];
18653 +       struct hlist_node *pos;
18654 +       struct dl_info *dli;
18655 +
18656 +       hlist_for_each_entry_rcu(dli, pos, head, dl_hlist) {
18657 +
18658 +               if (dli->dl_tag == tag && dli->dl_sb == sb) {
18659 +                       return dli;
18660 +               }
18661 +       }
18662 +       return NULL;
18663 +}
18664 +
18665 +
18666 +struct dl_info *locate_dl_info(struct super_block *sb, tag_t tag)
18667 +{
18668 +       struct dl_info *dli;
18669 +
18670 +       rcu_read_lock();
18671 +       dli = get_dl_info(__lookup_dl_info(sb, tag));
18672 +       vxdprintk(VXD_CBIT(dlim, 7),
18673 +               "locate_dl_info(%p,#%d) = %p", sb, tag, dli);
18674 +       rcu_read_unlock();
18675 +       return dli;
18676 +}
18677 +
18678 +void rcu_free_dl_info(struct rcu_head *head)
18679 +{
18680 +       struct dl_info *dli = container_of(head, struct dl_info, dl_rcu);
18681 +       int usecnt, refcnt;
18682 +
18683 +       BUG_ON(!dli || !head);
18684 +
18685 +       usecnt = atomic_read(&dli->dl_usecnt);
18686 +       BUG_ON(usecnt < 0);
18687 +
18688 +       refcnt = atomic_read(&dli->dl_refcnt);
18689 +       BUG_ON(refcnt < 0);
18690 +
18691 +       vxdprintk(VXD_CBIT(dlim, 3),
18692 +               "rcu_free_dl_info(%p)", dli);
18693 +       if (!usecnt)
18694 +               __dealloc_dl_info(dli);
18695 +       else
18696 +               printk("!!! rcu didn't free\n");
18697 +}
18698 +
18699 +
18700 +
18701 +
18702 +static int do_addrem_dlimit(uint32_t id, const char __user *name,
18703 +       uint32_t flags, int add)
18704 +{
18705 +       struct path path;
18706 +       int ret;
18707 +
18708 +       ret = user_lpath(name, &path);
18709 +       if (!ret) {
18710 +               struct super_block *sb;
18711 +               struct dl_info *dli;
18712 +
18713 +               ret = -EINVAL;
18714 +               if (!path.dentry->d_inode)
18715 +                       goto out_release;
18716 +               if (!(sb = path.dentry->d_inode->i_sb))
18717 +                       goto out_release;
18718 +
18719 +               if (add) {
18720 +                       dli = __alloc_dl_info(sb, id);
18721 +                       spin_lock(&dl_info_hash_lock);
18722 +
18723 +                       ret = -EEXIST;
18724 +                       if (__lookup_dl_info(sb, id))
18725 +                               goto out_unlock;
18726 +                       __hash_dl_info(dli);
18727 +                       dli = NULL;
18728 +               } else {
18729 +                       spin_lock(&dl_info_hash_lock);
18730 +                       dli = __lookup_dl_info(sb, id);
18731 +
18732 +                       ret = -ESRCH;
18733 +                       if (!dli)
18734 +                               goto out_unlock;
18735 +                       __unhash_dl_info(dli);
18736 +               }
18737 +               ret = 0;
18738 +       out_unlock:
18739 +               spin_unlock(&dl_info_hash_lock);
18740 +               if (add && dli)
18741 +                       __dealloc_dl_info(dli);
18742 +       out_release:
18743 +               path_put(&path);
18744 +       }
18745 +       return ret;
18746 +}
18747 +
18748 +int vc_add_dlimit(uint32_t id, void __user *data)
18749 +{
18750 +       struct vcmd_ctx_dlimit_base_v0 vc_data;
18751 +
18752 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18753 +               return -EFAULT;
18754 +
18755 +       return do_addrem_dlimit(id, vc_data.name, vc_data.flags, 1);
18756 +}
18757 +
18758 +int vc_rem_dlimit(uint32_t id, void __user *data)
18759 +{
18760 +       struct vcmd_ctx_dlimit_base_v0 vc_data;
18761 +
18762 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18763 +               return -EFAULT;
18764 +
18765 +       return do_addrem_dlimit(id, vc_data.name, vc_data.flags, 0);
18766 +}
18767 +
18768 +#ifdef CONFIG_COMPAT
18769 +
18770 +int vc_add_dlimit_x32(uint32_t id, void __user *data)
18771 +{
18772 +       struct vcmd_ctx_dlimit_base_v0_x32 vc_data;
18773 +
18774 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18775 +               return -EFAULT;
18776 +
18777 +       return do_addrem_dlimit(id,
18778 +               compat_ptr(vc_data.name_ptr), vc_data.flags, 1);
18779 +}
18780 +
18781 +int vc_rem_dlimit_x32(uint32_t id, void __user *data)
18782 +{
18783 +       struct vcmd_ctx_dlimit_base_v0_x32 vc_data;
18784 +
18785 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18786 +               return -EFAULT;
18787 +
18788 +       return do_addrem_dlimit(id,
18789 +               compat_ptr(vc_data.name_ptr), vc_data.flags, 0);
18790 +}
18791 +
18792 +#endif /* CONFIG_COMPAT */
18793 +
18794 +
18795 +static inline
18796 +int do_set_dlimit(uint32_t id, const char __user *name,
18797 +       uint32_t space_used, uint32_t space_total,
18798 +       uint32_t inodes_used, uint32_t inodes_total,
18799 +       uint32_t reserved, uint32_t flags)
18800 +{
18801 +       struct path path;
18802 +       int ret;
18803 +
18804 +       ret = user_lpath(name, &path);
18805 +       if (!ret) {
18806 +               struct super_block *sb;
18807 +               struct dl_info *dli;
18808 +
18809 +               ret = -EINVAL;
18810 +               if (!path.dentry->d_inode)
18811 +                       goto out_release;
18812 +               if (!(sb = path.dentry->d_inode->i_sb))
18813 +                       goto out_release;
18814 +
18815 +               /* sanity checks */
18816 +               if ((reserved != CDLIM_KEEP &&
18817 +                       reserved > 100) ||
18818 +                       (inodes_used != CDLIM_KEEP &&
18819 +                       inodes_used > inodes_total) ||
18820 +                       (space_used != CDLIM_KEEP &&
18821 +                       space_used > space_total))
18822 +                       goto out_release;
18823 +
18824 +               ret = -ESRCH;
18825 +               dli = locate_dl_info(sb, id);
18826 +               if (!dli)
18827 +                       goto out_release;
18828 +
18829 +               spin_lock(&dli->dl_lock);
18830 +
18831 +               if (inodes_used != CDLIM_KEEP)
18832 +                       dli->dl_inodes_used = inodes_used;
18833 +               if (inodes_total != CDLIM_KEEP)
18834 +                       dli->dl_inodes_total = inodes_total;
18835 +               if (space_used != CDLIM_KEEP)
18836 +                       dli->dl_space_used = dlimit_space_32to64(
18837 +                               space_used, flags, DLIMS_USED);
18838 +
18839 +               if (space_total == CDLIM_INFINITY)
18840 +                       dli->dl_space_total = DLIM_INFINITY;
18841 +               else if (space_total != CDLIM_KEEP)
18842 +                       dli->dl_space_total = dlimit_space_32to64(
18843 +                               space_total, flags, DLIMS_TOTAL);
18844 +
18845 +               if (reserved != CDLIM_KEEP)
18846 +                       dli->dl_nrlmult = (1 << 10) * (100 - reserved) / 100;
18847 +
18848 +               spin_unlock(&dli->dl_lock);
18849 +
18850 +               put_dl_info(dli);
18851 +               ret = 0;
18852 +
18853 +       out_release:
18854 +               path_put(&path);
18855 +       }
18856 +       return ret;
18857 +}
18858 +
18859 +int vc_set_dlimit(uint32_t id, void __user *data)
18860 +{
18861 +       struct vcmd_ctx_dlimit_v0 vc_data;
18862 +
18863 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18864 +               return -EFAULT;
18865 +
18866 +       return do_set_dlimit(id, vc_data.name,
18867 +               vc_data.space_used, vc_data.space_total,
18868 +               vc_data.inodes_used, vc_data.inodes_total,
18869 +               vc_data.reserved, vc_data.flags);
18870 +}
18871 +
18872 +#ifdef CONFIG_COMPAT
18873 +
18874 +int vc_set_dlimit_x32(uint32_t id, void __user *data)
18875 +{
18876 +       struct vcmd_ctx_dlimit_v0_x32 vc_data;
18877 +
18878 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18879 +               return -EFAULT;
18880 +
18881 +       return do_set_dlimit(id, compat_ptr(vc_data.name_ptr),
18882 +               vc_data.space_used, vc_data.space_total,
18883 +               vc_data.inodes_used, vc_data.inodes_total,
18884 +               vc_data.reserved, vc_data.flags);
18885 +}
18886 +
18887 +#endif /* CONFIG_COMPAT */
18888 +
18889 +
18890 +static inline
18891 +int do_get_dlimit(uint32_t id, const char __user *name,
18892 +       uint32_t *space_used, uint32_t *space_total,
18893 +       uint32_t *inodes_used, uint32_t *inodes_total,
18894 +       uint32_t *reserved, uint32_t *flags)
18895 +{
18896 +       struct path path;
18897 +       int ret;
18898 +
18899 +       ret = user_lpath(name, &path);
18900 +       if (!ret) {
18901 +               struct super_block *sb;
18902 +               struct dl_info *dli;
18903 +
18904 +               ret = -EINVAL;
18905 +               if (!path.dentry->d_inode)
18906 +                       goto out_release;
18907 +               if (!(sb = path.dentry->d_inode->i_sb))
18908 +                       goto out_release;
18909 +
18910 +               ret = -ESRCH;
18911 +               dli = locate_dl_info(sb, id);
18912 +               if (!dli)
18913 +                       goto out_release;
18914 +
18915 +               spin_lock(&dli->dl_lock);
18916 +               *inodes_used = dli->dl_inodes_used;
18917 +               *inodes_total = dli->dl_inodes_total;
18918 +
18919 +               *space_used = dlimit_space_64to32(
18920 +                       dli->dl_space_used, flags, DLIMS_USED);
18921 +
18922 +               if (dli->dl_space_total == DLIM_INFINITY)
18923 +                       *space_total = CDLIM_INFINITY;
18924 +               else
18925 +                       *space_total = dlimit_space_64to32(
18926 +                               dli->dl_space_total, flags, DLIMS_TOTAL);
18927 +
18928 +               *reserved = 100 - ((dli->dl_nrlmult * 100 + 512) >> 10);
18929 +               spin_unlock(&dli->dl_lock);
18930 +
18931 +               put_dl_info(dli);
18932 +               ret = -EFAULT;
18933 +
18934 +               ret = 0;
18935 +       out_release:
18936 +               path_put(&path);
18937 +       }
18938 +       return ret;
18939 +}
18940 +
18941 +
18942 +int vc_get_dlimit(uint32_t id, void __user *data)
18943 +{
18944 +       struct vcmd_ctx_dlimit_v0 vc_data;
18945 +       int ret;
18946 +
18947 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18948 +               return -EFAULT;
18949 +
18950 +       ret = do_get_dlimit(id, vc_data.name,
18951 +               &vc_data.space_used, &vc_data.space_total,
18952 +               &vc_data.inodes_used, &vc_data.inodes_total,
18953 +               &vc_data.reserved, &vc_data.flags);
18954 +       if (ret)
18955 +               return ret;
18956 +
18957 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18958 +               return -EFAULT;
18959 +       return 0;
18960 +}
18961 +
18962 +#ifdef CONFIG_COMPAT
18963 +
18964 +int vc_get_dlimit_x32(uint32_t id, void __user *data)
18965 +{
18966 +       struct vcmd_ctx_dlimit_v0_x32 vc_data;
18967 +       int ret;
18968 +
18969 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18970 +               return -EFAULT;
18971 +
18972 +       ret = do_get_dlimit(id, compat_ptr(vc_data.name_ptr),
18973 +               &vc_data.space_used, &vc_data.space_total,
18974 +               &vc_data.inodes_used, &vc_data.inodes_total,
18975 +               &vc_data.reserved, &vc_data.flags);
18976 +       if (ret)
18977 +               return ret;
18978 +
18979 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18980 +               return -EFAULT;
18981 +       return 0;
18982 +}
18983 +
18984 +#endif /* CONFIG_COMPAT */
18985 +
18986 +
18987 +void vx_vsi_statfs(struct super_block *sb, struct kstatfs *buf)
18988 +{
18989 +       struct dl_info *dli;
18990 +       __u64 blimit, bfree, bavail;
18991 +       __u32 ifree;
18992 +
18993 +       dli = locate_dl_info(sb, dx_current_tag());
18994 +       if (!dli)
18995 +               return;
18996 +
18997 +       spin_lock(&dli->dl_lock);
18998 +       if (dli->dl_inodes_total == (unsigned long)DLIM_INFINITY)
18999 +               goto no_ilim;
19000 +
19001 +       /* reduce max inodes available to limit */
19002 +       if (buf->f_files > dli->dl_inodes_total)
19003 +               buf->f_files = dli->dl_inodes_total;
19004 +
19005 +       ifree = dli->dl_inodes_total - dli->dl_inodes_used;
19006 +       /* reduce free inodes to min */
19007 +       if (ifree < buf->f_ffree)
19008 +               buf->f_ffree = ifree;
19009 +
19010 +no_ilim:
19011 +       if (dli->dl_space_total == DLIM_INFINITY)
19012 +               goto no_blim;
19013 +
19014 +       blimit = dli->dl_space_total >> sb->s_blocksize_bits;
19015 +
19016 +       if (dli->dl_space_total < dli->dl_space_used)
19017 +               bfree = 0;
19018 +       else
19019 +               bfree = (dli->dl_space_total - dli->dl_space_used)
19020 +                       >> sb->s_blocksize_bits;
19021 +
19022 +       bavail = ((dli->dl_space_total >> 10) * dli->dl_nrlmult);
19023 +       if (bavail < dli->dl_space_used)
19024 +               bavail = 0;
19025 +       else
19026 +               bavail = (bavail - dli->dl_space_used)
19027 +                       >> sb->s_blocksize_bits;
19028 +
19029 +       /* reduce max space available to limit */
19030 +       if (buf->f_blocks > blimit)
19031 +               buf->f_blocks = blimit;
19032 +
19033 +       /* reduce free space to min */
19034 +       if (bfree < buf->f_bfree)
19035 +               buf->f_bfree = bfree;
19036 +
19037 +       /* reduce avail space to min */
19038 +       if (bavail < buf->f_bavail)
19039 +               buf->f_bavail = bavail;
19040 +
19041 +no_blim:
19042 +       spin_unlock(&dli->dl_lock);
19043 +       put_dl_info(dli);
19044 +
19045 +       return;
19046 +}
19047 +
19048 +#include <linux/module.h>
19049 +
19050 +EXPORT_SYMBOL_GPL(locate_dl_info);
19051 +EXPORT_SYMBOL_GPL(rcu_free_dl_info);
19052 +
19053 diff -NurpP --minimal linux-2.6.38.3/kernel/vserver/helper.c linux-2.6.38.3-vs2.3.0.37-rc14/kernel/vserver/helper.c
19054 --- linux-2.6.38.3/kernel/vserver/helper.c      1970-01-01 01:00:00.000000000 +0100
19055 +++ linux-2.6.38.3-vs2.3.0.37-rc14/kernel/vserver/helper.c      2011-01-29 02:01:07.000000000 +0100
19056 @@ -0,0 +1,223 @@
19057 +/*
19058 + *  linux/kernel/vserver/helper.c
19059 + *
19060 + *  Virtual Context Support
19061 + *
19062 + *  Copyright (C) 2004-2007  Herbert Pötzl
19063 + *
19064 + *  V0.01  basic helper
19065 + *
19066 + */
19067 +
19068 +#include <linux/kmod.h>
19069 +#include <linux/reboot.h>
19070 +#include <linux/vs_context.h>
19071 +#include <linux/vs_network.h>
19072 +#include <linux/vserver/signal.h>
19073 +
19074 +
19075 +char vshelper_path[255] = "/sbin/vshelper";
19076 +
19077 +
19078 +static int do_vshelper(char *name, char *argv[], char *envp[], int sync)
19079 +{
19080 +       int ret;
19081 +
19082 +       if ((ret = call_usermodehelper(name, argv, envp, sync))) {
19083 +               printk( KERN_WARNING
19084 +                       "%s: (%s %s) returned %s with %d\n",
19085 +                       name, argv[1], argv[2],
19086 +                       sync ? "sync" : "async", ret);
19087 +       }
19088 +       vxdprintk(VXD_CBIT(switch, 4),
19089 +               "%s: (%s %s) returned %s with %d",
19090 +               name, argv[1], argv[2], sync ? "sync" : "async", ret);
19091 +       return ret;
19092 +}
19093 +
19094 +/*
19095 + *      vshelper path is set via /proc/sys
19096 + *      invoked by vserver sys_reboot(), with
19097 + *      the following arguments
19098 + *
19099 + *      argv [0] = vshelper_path;
19100 + *      argv [1] = action: "restart", "halt", "poweroff", ...
19101 + *      argv [2] = context identifier
19102 + *
19103 + *      envp [*] = type-specific parameters
19104 + */
19105 +
19106 +long vs_reboot_helper(struct vx_info *vxi, int cmd, void __user *arg)
19107 +{
19108 +       char id_buf[8], cmd_buf[16];
19109 +       char uid_buf[16], pid_buf[16];
19110 +       int ret;
19111 +
19112 +       char *argv[] = {vshelper_path, NULL, id_buf, 0};
19113 +       char *envp[] = {"HOME=/", "TERM=linux",
19114 +                       "PATH=/sbin:/usr/sbin:/bin:/usr/bin",
19115 +                       uid_buf, pid_buf, cmd_buf, 0};
19116 +
19117 +       if (vx_info_state(vxi, VXS_HELPER))
19118 +               return -EAGAIN;
19119 +       vxi->vx_state |= VXS_HELPER;
19120 +
19121 +       snprintf(id_buf, sizeof(id_buf)-1, "%d", vxi->vx_id);
19122 +
19123 +       snprintf(cmd_buf, sizeof(cmd_buf)-1, "VS_CMD=%08x", cmd);
19124 +       snprintf(uid_buf, sizeof(uid_buf)-1, "VS_UID=%d", current_uid());
19125 +       snprintf(pid_buf, sizeof(pid_buf)-1, "VS_PID=%d", current->pid);
19126 +
19127 +       switch (cmd) {
19128 +       case LINUX_REBOOT_CMD_RESTART:
19129 +               argv[1] = "restart";
19130 +               break;
19131 +
19132 +       case LINUX_REBOOT_CMD_HALT:
19133 +               argv[1] = "halt";
19134 +               break;
19135 +
19136 +       case LINUX_REBOOT_CMD_POWER_OFF:
19137 +               argv[1] = "poweroff";
19138 +               break;
19139 +
19140 +       case LINUX_REBOOT_CMD_SW_SUSPEND:
19141 +               argv[1] = "swsusp";
19142 +               break;
19143 +
19144 +       case LINUX_REBOOT_CMD_OOM:
19145 +               argv[1] = "oom";
19146 +               break;
19147 +
19148 +       default:
19149 +               vxi->vx_state &= ~VXS_HELPER;
19150 +               return 0;
19151 +       }
19152 +
19153 +       ret = do_vshelper(vshelper_path, argv, envp, 0);
19154 +       vxi->vx_state &= ~VXS_HELPER;
19155 +       __wakeup_vx_info(vxi);
19156 +       return (ret) ? -EPERM : 0;
19157 +}
19158 +
19159 +
19160 +long vs_reboot(unsigned int cmd, void __user *arg)
19161 +{
19162 +       struct vx_info *vxi = current_vx_info();
19163 +       long ret = 0;
19164 +
19165 +       vxdprintk(VXD_CBIT(misc, 5),
19166 +               "vs_reboot(%p[#%d],%u)",
19167 +               vxi, vxi ? vxi->vx_id : 0, cmd);
19168 +
19169 +       ret = vs_reboot_helper(vxi, cmd, arg);
19170 +       if (ret)
19171 +               return ret;
19172 +
19173 +       vxi->reboot_cmd = cmd;
19174 +       if (vx_info_flags(vxi, VXF_REBOOT_KILL, 0)) {
19175 +               switch (cmd) {
19176 +               case LINUX_REBOOT_CMD_RESTART:
19177 +               case LINUX_REBOOT_CMD_HALT:
19178 +               case LINUX_REBOOT_CMD_POWER_OFF:
19179 +                       vx_info_kill(vxi, 0, SIGKILL);
19180 +                       vx_info_kill(vxi, 1, SIGKILL);
19181 +               default:
19182 +                       break;
19183 +               }
19184 +       }
19185 +       return 0;
19186 +}
19187 +
19188 +long vs_oom_action(unsigned int cmd)
19189 +{
19190 +       struct vx_info *vxi = current_vx_info();
19191 +       long ret = 0;
19192 +
19193 +       vxdprintk(VXD_CBIT(misc, 5),
19194 +               "vs_oom_action(%p[#%d],%u)",
19195 +               vxi, vxi ? vxi->vx_id : 0, cmd);
19196 +
19197 +       ret = vs_reboot_helper(vxi, cmd, NULL);
19198 +       if (ret)
19199 +               return ret;
19200 +
19201 +       vxi->reboot_cmd = cmd;
19202 +       if (vx_info_flags(vxi, VXF_REBOOT_KILL, 0)) {
19203 +               vx_info_kill(vxi, 0, SIGKILL);
19204 +               vx_info_kill(vxi, 1, SIGKILL);
19205 +       }
19206 +       return 0;
19207 +}
19208 +
19209 +/*
19210 + *      argv [0] = vshelper_path;
19211 + *      argv [1] = action: "startup", "shutdown"
19212 + *      argv [2] = context identifier
19213 + *
19214 + *      envp [*] = type-specific parameters
19215 + */
19216 +
19217 +long vs_state_change(struct vx_info *vxi, unsigned int cmd)
19218 +{
19219 +       char id_buf[8], cmd_buf[16];
19220 +       char *argv[] = {vshelper_path, NULL, id_buf, 0};
19221 +       char *envp[] = {"HOME=/", "TERM=linux",
19222 +                       "PATH=/sbin:/usr/sbin:/bin:/usr/bin", cmd_buf, 0};
19223 +
19224 +       if (!vx_info_flags(vxi, VXF_SC_HELPER, 0))
19225 +               return 0;
19226 +
19227 +       snprintf(id_buf, sizeof(id_buf)-1, "%d", vxi->vx_id);
19228 +       snprintf(cmd_buf, sizeof(cmd_buf)-1, "VS_CMD=%08x", cmd);
19229 +
19230 +       switch (cmd) {
19231 +       case VSC_STARTUP:
19232 +               argv[1] = "startup";
19233 +               break;
19234 +       case VSC_SHUTDOWN:
19235 +               argv[1] = "shutdown";
19236 +               break;
19237 +       default:
19238 +               return 0;
19239 +       }
19240 +
19241 +       return do_vshelper(vshelper_path, argv, envp, 1);
19242 +}
19243 +
19244 +
19245 +/*
19246 + *      argv [0] = vshelper_path;
19247 + *      argv [1] = action: "netup", "netdown"
19248 + *      argv [2] = context identifier
19249 + *
19250 + *      envp [*] = type-specific parameters
19251 + */
19252 +
19253 +long vs_net_change(struct nx_info *nxi, unsigned int cmd)
19254 +{
19255 +       char id_buf[8], cmd_buf[16];
19256 +       char *argv[] = {vshelper_path, NULL, id_buf, 0};
19257 +       char *envp[] = {"HOME=/", "TERM=linux",
19258 +                       "PATH=/sbin:/usr/sbin:/bin:/usr/bin", cmd_buf, 0};
19259 +
19260 +       if (!nx_info_flags(nxi, NXF_SC_HELPER, 0))
19261 +               return 0;
19262 +
19263 +       snprintf(id_buf, sizeof(id_buf)-1, "%d", nxi->nx_id);
19264 +       snprintf(cmd_buf, sizeof(cmd_buf)-1, "VS_CMD=%08x", cmd);
19265 +
19266 +       switch (cmd) {
19267 +       case VSC_NETUP:
19268 +               argv[1] = "netup";
19269 +               break;
19270 +       case VSC_NETDOWN:
19271 +               argv[1] = "netdown";
19272 +               break;
19273 +       default:
19274 +               return 0;
19275 +       }
19276 +
19277 +       return do_vshelper(vshelper_path, argv, envp, 1);
19278 +}
19279 +
19280 diff -NurpP --minimal linux-2.6.38.3/kernel/vserver/history.c linux-2.6.38.3-vs2.3.0.37-rc14/kernel/vserver/history.c
19281 --- linux-2.6.38.3/kernel/vserver/history.c     1970-01-01 01:00:00.000000000 +0100
19282 +++ linux-2.6.38.3-vs2.3.0.37-rc14/kernel/vserver/history.c     2011-01-29 02:01:07.000000000 +0100
19283 @@ -0,0 +1,258 @@
19284 +/*
19285 + *  kernel/vserver/history.c
19286 + *
19287 + *  Virtual Context History Backtrace
19288 + *
19289 + *  Copyright (C) 2004-2007  Herbert Pötzl
19290 + *
19291 + *  V0.01  basic structure
19292 + *  V0.02  hash/unhash and trace
19293 + *  V0.03  preemption fixes
19294 + *
19295 + */
19296 +
19297 +#include <linux/module.h>
19298 +#include <asm/uaccess.h>
19299 +
19300 +#include <linux/vserver/context.h>
19301 +#include <linux/vserver/debug.h>
19302 +#include <linux/vserver/debug_cmd.h>
19303 +#include <linux/vserver/history.h>
19304 +
19305 +
19306 +#ifdef CONFIG_VSERVER_HISTORY
19307 +#define VXH_SIZE       CONFIG_VSERVER_HISTORY_SIZE
19308 +#else
19309 +#define VXH_SIZE       64
19310 +#endif
19311 +
19312 +struct _vx_history {
19313 +       unsigned int counter;
19314 +
19315 +       struct _vx_hist_entry entry[VXH_SIZE + 1];
19316 +};
19317 +
19318 +
19319 +DEFINE_PER_CPU(struct _vx_history, vx_history_buffer);
19320 +
19321 +unsigned volatile int vxh_active = 1;
19322 +
19323 +static atomic_t sequence = ATOMIC_INIT(0);
19324 +
19325 +
19326 +/*     vxh_advance()
19327 +
19328 +       * requires disabled preemption                          */
19329 +
19330 +struct _vx_hist_entry *vxh_advance(void *loc)
19331 +{
19332 +       unsigned int cpu = smp_processor_id();
19333 +       struct _vx_history *hist = &per_cpu(vx_history_buffer, cpu);
19334 +       struct _vx_hist_entry *entry;
19335 +       unsigned int index;
19336 +
19337 +       index = vxh_active ? (hist->counter++ % VXH_SIZE) : VXH_SIZE;
19338 +       entry = &hist->entry[index];
19339 +
19340 +       entry->seq = atomic_inc_return(&sequence);
19341 +       entry->loc = loc;
19342 +       return entry;
19343 +}
19344 +
19345 +EXPORT_SYMBOL_GPL(vxh_advance);
19346 +
19347 +
19348 +#define VXH_LOC_FMTS   "(#%04x,*%d):%p"
19349 +
19350 +#define VXH_LOC_ARGS(e)        (e)->seq, cpu, (e)->loc
19351 +
19352 +
19353 +#define VXH_VXI_FMTS   "%p[#%d,%d.%d]"
19354 +
19355 +#define VXH_VXI_ARGS(e)        (e)->vxi.ptr,                           \
19356 +                       (e)->vxi.ptr ? (e)->vxi.xid : 0,        \
19357 +                       (e)->vxi.ptr ? (e)->vxi.usecnt : 0,     \
19358 +                       (e)->vxi.ptr ? (e)->vxi.tasks : 0
19359 +
19360 +void   vxh_dump_entry(struct _vx_hist_entry *e, unsigned cpu)
19361 +{
19362 +       switch (e->type) {
19363 +       case VXH_THROW_OOPS:
19364 +               printk( VXH_LOC_FMTS " oops \n", VXH_LOC_ARGS(e));
19365 +               break;
19366 +
19367 +       case VXH_GET_VX_INFO:
19368 +       case VXH_PUT_VX_INFO:
19369 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS "\n",
19370 +                       VXH_LOC_ARGS(e),
19371 +                       (e->type == VXH_GET_VX_INFO) ? "get" : "put",
19372 +                       VXH_VXI_ARGS(e));
19373 +               break;
19374 +
19375 +       case VXH_INIT_VX_INFO:
19376 +       case VXH_SET_VX_INFO:
19377 +       case VXH_CLR_VX_INFO:
19378 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS " @%p\n",
19379 +                       VXH_LOC_ARGS(e),
19380 +                       (e->type == VXH_INIT_VX_INFO) ? "init" :
19381 +                       ((e->type == VXH_SET_VX_INFO) ? "set" : "clr"),
19382 +                       VXH_VXI_ARGS(e), e->sc.data);
19383 +               break;
19384 +
19385 +       case VXH_CLAIM_VX_INFO:
19386 +       case VXH_RELEASE_VX_INFO:
19387 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS " @%p\n",
19388 +                       VXH_LOC_ARGS(e),
19389 +                       (e->type == VXH_CLAIM_VX_INFO) ? "claim" : "release",
19390 +                       VXH_VXI_ARGS(e), e->sc.data);
19391 +               break;
19392 +
19393 +       case VXH_ALLOC_VX_INFO:
19394 +       case VXH_DEALLOC_VX_INFO:
19395 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS "\n",
19396 +                       VXH_LOC_ARGS(e),
19397 +                       (e->type == VXH_ALLOC_VX_INFO) ? "alloc" : "dealloc",
19398 +                       VXH_VXI_ARGS(e));
19399 +               break;
19400 +
19401 +       case VXH_HASH_VX_INFO:
19402 +       case VXH_UNHASH_VX_INFO:
19403 +               printk( VXH_LOC_FMTS " __%s_vx_info " VXH_VXI_FMTS "\n",
19404 +                       VXH_LOC_ARGS(e),
19405 +                       (e->type == VXH_HASH_VX_INFO) ? "hash" : "unhash",
19406 +                       VXH_VXI_ARGS(e));
19407 +               break;
19408 +
19409 +       case VXH_LOC_VX_INFO:
19410 +       case VXH_LOOKUP_VX_INFO:
19411 +       case VXH_CREATE_VX_INFO:
19412 +               printk( VXH_LOC_FMTS " __%s_vx_info [#%d] -> " VXH_VXI_FMTS "\n",
19413 +                       VXH_LOC_ARGS(e),
19414 +                       (e->type == VXH_CREATE_VX_INFO) ? "create" :
19415 +                       ((e->type == VXH_LOC_VX_INFO) ? "loc" : "lookup"),
19416 +                       e->ll.arg, VXH_VXI_ARGS(e));
19417 +               break;
19418 +       }
19419 +}
19420 +
19421 +static void __vxh_dump_history(void)
19422 +{
19423 +       unsigned int i, cpu;
19424 +
19425 +       printk("History:\tSEQ: %8x\tNR_CPUS: %d\n",
19426 +               atomic_read(&sequence), NR_CPUS);
19427 +
19428 +       for (i = 0; i < VXH_SIZE; i++) {
19429 +               for_each_online_cpu(cpu) {
19430 +                       struct _vx_history *hist =
19431 +                               &per_cpu(vx_history_buffer, cpu);
19432 +                       unsigned int index = (hist->counter - i) % VXH_SIZE;
19433 +                       struct _vx_hist_entry *entry = &hist->entry[index];
19434 +
19435 +                       vxh_dump_entry(entry, cpu);
19436 +               }
19437 +       }
19438 +}
19439 +
19440 +void   vxh_dump_history(void)
19441 +{
19442 +       vxh_active = 0;
19443 +#ifdef CONFIG_SMP
19444 +       local_irq_enable();
19445 +       smp_send_stop();
19446 +       local_irq_disable();
19447 +#endif
19448 +       __vxh_dump_history();
19449 +}
19450 +
19451 +
19452 +/* vserver syscall commands below here */
19453 +
19454 +
19455 +int vc_dump_history(uint32_t id)
19456 +{
19457 +       vxh_active = 0;
19458 +       __vxh_dump_history();
19459 +       vxh_active = 1;
19460 +
19461 +       return 0;
19462 +}
19463 +
19464 +
19465 +int do_read_history(struct __user _vx_hist_entry *data,
19466 +       int cpu, uint32_t *index, uint32_t *count)
19467 +{
19468 +       int pos, ret = 0;
19469 +       struct _vx_history *hist = &per_cpu(vx_history_buffer, cpu);
19470 +       int end = hist->counter;
19471 +       int start = end - VXH_SIZE + 2;
19472 +       int idx = *index;
19473 +
19474 +       /* special case: get current pos */
19475 +       if (!*count) {
19476 +               *index = end;
19477 +               return 0;
19478 +       }
19479 +
19480 +       /* have we lost some data? */
19481 +       if (idx < start)
19482 +               idx = start;
19483 +
19484 +       for (pos = 0; (pos < *count) && (idx < end); pos++, idx++) {
19485 +               struct _vx_hist_entry *entry =
19486 +                       &hist->entry[idx % VXH_SIZE];
19487 +
19488 +               /* send entry to userspace */
19489 +               ret = copy_to_user(&data[pos], entry, sizeof(*entry));
19490 +               if (ret)
19491 +                       break;
19492 +       }
19493 +       /* save new index and count */
19494 +       *index = idx;
19495 +       *count = pos;
19496 +       return ret ? ret : (*index < end);
19497 +}
19498 +
19499 +int vc_read_history(uint32_t id, void __user *data)
19500 +{
19501 +       struct vcmd_read_history_v0 vc_data;
19502 +       int ret;
19503 +
19504 +       if (id >= NR_CPUS)
19505 +               return -EINVAL;
19506 +
19507 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19508 +               return -EFAULT;
19509 +
19510 +       ret = do_read_history((struct __user _vx_hist_entry *)vc_data.data,
19511 +               id, &vc_data.index, &vc_data.count);
19512 +
19513 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19514 +               return -EFAULT;
19515 +       return ret;
19516 +}
19517 +
19518 +#ifdef CONFIG_COMPAT
19519 +
19520 +int vc_read_history_x32(uint32_t id, void __user *data)
19521 +{
19522 +       struct vcmd_read_history_v0_x32 vc_data;
19523 +       int ret;
19524 +
19525 +       if (id >= NR_CPUS)
19526 +               return -EINVAL;
19527 +
19528 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19529 +               return -EFAULT;
19530 +
19531 +       ret = do_read_history((struct __user _vx_hist_entry *)
19532 +               compat_ptr(vc_data.data_ptr),
19533 +               id, &vc_data.index, &vc_data.count);
19534 +
19535 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19536 +               return -EFAULT;
19537 +       return ret;
19538 +}
19539 +
19540 +#endif /* CONFIG_COMPAT */
19541 +
19542 diff -NurpP --minimal linux-2.6.38.3/kernel/vserver/inet.c linux-2.6.38.3-vs2.3.0.37-rc14/kernel/vserver/inet.c
19543 --- linux-2.6.38.3/kernel/vserver/inet.c        1970-01-01 01:00:00.000000000 +0100
19544 +++ linux-2.6.38.3-vs2.3.0.37-rc14/kernel/vserver/inet.c        2011-01-29 02:01:07.000000000 +0100
19545 @@ -0,0 +1,224 @@
19546 +
19547 +#include <linux/in.h>
19548 +#include <linux/inetdevice.h>
19549 +#include <linux/vs_inet.h>
19550 +#include <linux/vs_inet6.h>
19551 +#include <linux/vserver/debug.h>
19552 +#include <net/route.h>
19553 +#include <net/addrconf.h>
19554 +
19555 +
19556 +int nx_v4_addr_conflict(struct nx_info *nxi1, struct nx_info *nxi2)
19557 +{
19558 +       int ret = 0;
19559 +
19560 +       if (!nxi1 || !nxi2 || nxi1 == nxi2)
19561 +               ret = 1;
19562 +       else {
19563 +               struct nx_addr_v4 *ptr;
19564 +
19565 +               for (ptr = &nxi1->v4; ptr; ptr = ptr->next) {
19566 +                       if (v4_nx_addr_in_nx_info(nxi2, ptr, -1)) {
19567 +                               ret = 1;
19568 +                               break;
19569 +                       }
19570 +               }
19571 +       }
19572 +
19573 +       vxdprintk(VXD_CBIT(net, 2),
19574 +               "nx_v4_addr_conflict(%p,%p): %d",
19575 +               nxi1, nxi2, ret);
19576 +
19577 +       return ret;
19578 +}
19579 +
19580 +
19581 +#ifdef CONFIG_IPV6
19582 +
19583 +int nx_v6_addr_conflict(struct nx_info *nxi1, struct nx_info *nxi2)
19584 +{
19585 +       int ret = 0;
19586 +
19587 +       if (!nxi1 || !nxi2 || nxi1 == nxi2)
19588 +               ret = 1;
19589 +       else {
19590 +               struct nx_addr_v6 *ptr;
19591 +
19592 +               for (ptr = &nxi1->v6; ptr; ptr = ptr->next) {
19593 +                       if (v6_nx_addr_in_nx_info(nxi2, ptr, -1)) {
19594 +                               ret = 1;
19595 +                               break;
19596 +                       }
19597 +               }
19598 +       }
19599 +
19600 +       vxdprintk(VXD_CBIT(net, 2),
19601 +               "nx_v6_addr_conflict(%p,%p): %d",
19602 +               nxi1, nxi2, ret);
19603 +
19604 +       return ret;
19605 +}
19606 +
19607 +#endif
19608 +
19609 +int v4_dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
19610 +{
19611 +       struct in_device *in_dev;
19612 +       struct in_ifaddr **ifap;
19613 +       struct in_ifaddr *ifa;
19614 +       int ret = 0;
19615 +
19616 +       if (!dev)
19617 +               goto out;
19618 +       in_dev = in_dev_get(dev);
19619 +       if (!in_dev)
19620 +               goto out;
19621 +
19622 +       for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
19623 +               ifap = &ifa->ifa_next) {
19624 +               if (v4_addr_in_nx_info(nxi, ifa->ifa_local, NXA_MASK_SHOW)) {
19625 +                       ret = 1;
19626 +                       break;
19627 +               }
19628 +       }
19629 +       in_dev_put(in_dev);
19630 +out:
19631 +       return ret;
19632 +}
19633 +
19634 +
19635 +#ifdef CONFIG_IPV6
19636 +
19637 +int v6_dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
19638 +{
19639 +       struct inet6_dev *in_dev;
19640 +       struct inet6_ifaddr *ifa;
19641 +       int ret = 0;
19642 +
19643 +       if (!dev)
19644 +               goto out;
19645 +       in_dev = in6_dev_get(dev);
19646 +       if (!in_dev)
19647 +               goto out;
19648 +
19649 +       // for (ifap = &in_dev->addr_list; (ifa = *ifap) != NULL;
19650 +       list_for_each_entry(ifa, &in_dev->addr_list, if_list) {
19651 +               if (v6_addr_in_nx_info(nxi, &ifa->addr, -1)) {
19652 +                       ret = 1;
19653 +                       break;
19654 +               }
19655 +       }
19656 +       in6_dev_put(in_dev);
19657 +out:
19658 +       return ret;
19659 +}
19660 +
19661 +#endif
19662 +
19663 +int dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
19664 +{
19665 +       int ret = 1;
19666 +
19667 +       if (!nxi)
19668 +               goto out;
19669 +       if (nxi->v4.type && v4_dev_in_nx_info(dev, nxi))
19670 +               goto out;
19671 +#ifdef CONFIG_IPV6
19672 +       ret = 2;
19673 +       if (nxi->v6.type && v6_dev_in_nx_info(dev, nxi))
19674 +               goto out;
19675 +#endif
19676 +       ret = 0;
19677 +out:
19678 +       vxdprintk(VXD_CBIT(net, 3),
19679 +               "dev_in_nx_info(%p,%p[#%d]) = %d",
19680 +               dev, nxi, nxi ? nxi->nx_id : 0, ret);
19681 +       return ret;
19682 +}
19683 +
19684 +int ip_v4_find_src(struct net *net, struct nx_info *nxi,
19685 +       struct rtable **rp, struct flowi *fl)
19686 +{
19687 +       if (!nxi)
19688 +               return 0;
19689 +
19690 +       /* FIXME: handle lback only case */
19691 +       if (!NX_IPV4(nxi))
19692 +               return -EPERM;
19693 +
19694 +       vxdprintk(VXD_CBIT(net, 4),
19695 +               "ip_v4_find_src(%p[#%u]) " NIPQUAD_FMT " -> " NIPQUAD_FMT,
19696 +               nxi, nxi ? nxi->nx_id : 0,
19697 +               NIPQUAD(fl->fl4_src), NIPQUAD(fl->fl4_dst));
19698 +
19699 +       /* single IP is unconditional */
19700 +       if (nx_info_flags(nxi, NXF_SINGLE_IP, 0) &&
19701 +               (fl->fl4_src == INADDR_ANY))
19702 +               fl->fl4_src = nxi->v4.ip[0].s_addr;
19703 +
19704 +       if (fl->fl4_src == INADDR_ANY) {
19705 +               struct nx_addr_v4 *ptr;
19706 +               __be32 found = 0;
19707 +               int err;
19708 +
19709 +               err = __ip_route_output_key(net, rp, fl);
19710 +               if (!err) {
19711 +                       found = (*rp)->rt_src;
19712 +                       ip_rt_put(*rp);
19713 +                       vxdprintk(VXD_CBIT(net, 4),
19714 +                               "ip_v4_find_src(%p[#%u]) rok[%u]: " NIPQUAD_FMT,
19715 +                               nxi, nxi ? nxi->nx_id : 0, fl->oif, NIPQUAD(found));
19716 +                       if (v4_addr_in_nx_info(nxi, found, NXA_MASK_BIND))
19717 +                               goto found;
19718 +               }
19719 +
19720 +               for (ptr = &nxi->v4; ptr; ptr = ptr->next) {
19721 +                       __be32 primary = ptr->ip[0].s_addr;
19722 +                       __be32 mask = ptr->mask.s_addr;
19723 +                       __be32 neta = primary & mask;
19724 +
19725 +                       vxdprintk(VXD_CBIT(net, 4), "ip_v4_find_src(%p[#%u]) chk: "
19726 +                               NIPQUAD_FMT "/" NIPQUAD_FMT "/" NIPQUAD_FMT,
19727 +                               nxi, nxi ? nxi->nx_id : 0, NIPQUAD(primary),
19728 +                               NIPQUAD(mask), NIPQUAD(neta));
19729 +                       if ((found & mask) != neta)
19730 +                               continue;
19731 +
19732 +                       fl->fl4_src = primary;
19733 +                       err = __ip_route_output_key(net, rp, fl);
19734 +                       vxdprintk(VXD_CBIT(net, 4),
19735 +                               "ip_v4_find_src(%p[#%u]) rok[%u]: " NIPQUAD_FMT,
19736 +                               nxi, nxi ? nxi->nx_id : 0, fl->oif, NIPQUAD(primary));
19737 +                       if (!err) {
19738 +                               found = (*rp)->rt_src;
19739 +                               ip_rt_put(*rp);
19740 +                               if (found == primary)
19741 +                                       goto found;
19742 +                       }
19743 +               }
19744 +               /* still no source ip? */
19745 +               found = ipv4_is_loopback(fl->fl4_dst)
19746 +                       ? IPI_LOOPBACK : nxi->v4.ip[0].s_addr;
19747 +       found:
19748 +               /* assign src ip to flow */
19749 +               fl->fl4_src = found;
19750 +
19751 +       } else {
19752 +               if (!v4_addr_in_nx_info(nxi, fl->fl4_src, NXA_MASK_BIND))
19753 +                       return -EPERM;
19754 +       }
19755 +
19756 +       if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0)) {
19757 +               if (ipv4_is_loopback(fl->fl4_dst))
19758 +                       fl->fl4_dst = nxi->v4_lback.s_addr;
19759 +               if (ipv4_is_loopback(fl->fl4_src))
19760 +                       fl->fl4_src = nxi->v4_lback.s_addr;
19761 +       } else if (ipv4_is_loopback(fl->fl4_dst) &&
19762 +               !nx_info_flags(nxi, NXF_LBACK_ALLOW, 0))
19763 +               return -EPERM;
19764 +
19765 +       return 0;
19766 +}
19767 +
19768 +EXPORT_SYMBOL_GPL(ip_v4_find_src);
19769 +
19770 diff -NurpP --minimal linux-2.6.38.3/kernel/vserver/init.c linux-2.6.38.3-vs2.3.0.37-rc14/kernel/vserver/init.c
19771 --- linux-2.6.38.3/kernel/vserver/init.c        1970-01-01 01:00:00.000000000 +0100
19772 +++ linux-2.6.38.3-vs2.3.0.37-rc14/kernel/vserver/init.c        2011-01-29 02:01:07.000000000 +0100
19773 @@ -0,0 +1,45 @@
19774 +/*
19775 + *  linux/kernel/init.c
19776 + *
19777 + *  Virtual Server Init
19778 + *
19779 + *  Copyright (C) 2004-2007  Herbert Pötzl
19780 + *
19781 + *  V0.01  basic structure
19782 + *
19783 + */
19784 +
19785 +#include <linux/init.h>
19786 +
19787 +int    vserver_register_sysctl(void);
19788 +void   vserver_unregister_sysctl(void);
19789 +
19790 +
19791 +static int __init init_vserver(void)
19792 +{
19793 +       int ret = 0;
19794 +
19795 +#ifdef CONFIG_VSERVER_DEBUG
19796 +       vserver_register_sysctl();
19797 +#endif
19798 +       return ret;
19799 +}
19800 +
19801 +
19802 +static void __exit exit_vserver(void)
19803 +{
19804 +
19805 +#ifdef CONFIG_VSERVER_DEBUG
19806 +       vserver_unregister_sysctl();
19807 +#endif
19808 +       return;
19809 +}
19810 +
19811 +/* FIXME: GFP_ZONETYPES gone
19812 +long vx_slab[GFP_ZONETYPES]; */
19813 +long vx_area;
19814 +
19815 +
19816 +module_init(init_vserver);
19817 +module_exit(exit_vserver);
19818 +
19819 diff -NurpP --minimal linux-2.6.38.3/kernel/vserver/inode.c linux-2.6.38.3-vs2.3.0.37-rc14/kernel/vserver/inode.c
19820 --- linux-2.6.38.3/kernel/vserver/inode.c       1970-01-01 01:00:00.000000000 +0100
19821 +++ linux-2.6.38.3-vs2.3.0.37-rc14/kernel/vserver/inode.c       2011-03-21 07:25:53.000000000 +0100
19822 @@ -0,0 +1,437 @@
19823 +/*
19824 + *  linux/kernel/vserver/inode.c
19825 + *
19826 + *  Virtual Server: File System Support
19827 + *
19828 + *  Copyright (C) 2004-2007  Herbert Pötzl
19829 + *
19830 + *  V0.01  separated from vcontext V0.05
19831 + *  V0.02  moved to tag (instead of xid)
19832 + *
19833 + */
19834 +
19835 +#include <linux/tty.h>
19836 +#include <linux/proc_fs.h>
19837 +#include <linux/devpts_fs.h>
19838 +#include <linux/fs.h>
19839 +#include <linux/file.h>
19840 +#include <linux/mount.h>
19841 +#include <linux/parser.h>
19842 +#include <linux/namei.h>
19843 +#include <linux/vserver/inode.h>
19844 +#include <linux/vserver/inode_cmd.h>
19845 +#include <linux/vs_base.h>
19846 +#include <linux/vs_tag.h>
19847 +
19848 +#include <asm/uaccess.h>
19849 +
19850 +
19851 +static int __vc_get_iattr(struct inode *in, uint32_t *tag, uint32_t *flags, uint32_t *mask)
19852 +{
19853 +       struct proc_dir_entry *entry;
19854 +
19855 +       if (!in || !in->i_sb)
19856 +               return -ESRCH;
19857 +
19858 +       *flags = IATTR_TAG
19859 +               | (IS_IMMUTABLE(in) ? IATTR_IMMUTABLE : 0)
19860 +               | (IS_IXUNLINK(in) ? IATTR_IXUNLINK : 0)
19861 +               | (IS_BARRIER(in) ? IATTR_BARRIER : 0)
19862 +               | (IS_COW(in) ? IATTR_COW : 0);
19863 +       *mask = IATTR_IXUNLINK | IATTR_IMMUTABLE | IATTR_COW;
19864 +
19865 +       if (S_ISDIR(in->i_mode))
19866 +               *mask |= IATTR_BARRIER;
19867 +
19868 +       if (IS_TAGGED(in)) {
19869 +               *tag = in->i_tag;
19870 +               *mask |= IATTR_TAG;
19871 +       }
19872 +
19873 +       switch (in->i_sb->s_magic) {
19874 +       case PROC_SUPER_MAGIC:
19875 +               entry = PROC_I(in)->pde;
19876 +
19877 +               /* check for specific inodes? */
19878 +               if (entry)
19879 +                       *mask |= IATTR_FLAGS;
19880 +               if (entry)
19881 +                       *flags |= (entry->vx_flags & IATTR_FLAGS);
19882 +               else
19883 +                       *flags |= (PROC_I(in)->vx_flags & IATTR_FLAGS);
19884 +               break;
19885 +
19886 +       case DEVPTS_SUPER_MAGIC:
19887 +               *tag = in->i_tag;
19888 +               *mask |= IATTR_TAG;
19889 +               break;
19890 +
19891 +       default:
19892 +               break;
19893 +       }
19894 +       return 0;
19895 +}
19896 +
19897 +int vc_get_iattr(void __user *data)
19898 +{
19899 +       struct path path;
19900 +       struct vcmd_ctx_iattr_v1 vc_data = { .tag = -1 };
19901 +       int ret;
19902 +
19903 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19904 +               return -EFAULT;
19905 +
19906 +       ret = user_lpath(vc_data.name, &path);
19907 +       if (!ret) {
19908 +               ret = __vc_get_iattr(path.dentry->d_inode,
19909 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
19910 +               path_put(&path);
19911 +       }
19912 +       if (ret)
19913 +               return ret;
19914 +
19915 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19916 +               ret = -EFAULT;
19917 +       return ret;
19918 +}
19919 +
19920 +#ifdef CONFIG_COMPAT
19921 +
19922 +int vc_get_iattr_x32(void __user *data)
19923 +{
19924 +       struct path path;
19925 +       struct vcmd_ctx_iattr_v1_x32 vc_data = { .tag = -1 };
19926 +       int ret;
19927 +
19928 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19929 +               return -EFAULT;
19930 +
19931 +       ret = user_lpath(compat_ptr(vc_data.name_ptr), &path);
19932 +       if (!ret) {
19933 +               ret = __vc_get_iattr(path.dentry->d_inode,
19934 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
19935 +               path_put(&path);
19936 +       }
19937 +       if (ret)
19938 +               return ret;
19939 +
19940 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19941 +               ret = -EFAULT;
19942 +       return ret;
19943 +}
19944 +
19945 +#endif /* CONFIG_COMPAT */
19946 +
19947 +
19948 +int vc_fget_iattr(uint32_t fd, void __user *data)
19949 +{
19950 +       struct file *filp;
19951 +       struct vcmd_ctx_fiattr_v0 vc_data = { .tag = -1 };
19952 +       int ret;
19953 +
19954 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19955 +               return -EFAULT;
19956 +
19957 +       filp = fget(fd);
19958 +       if (!filp || !filp->f_dentry || !filp->f_dentry->d_inode)
19959 +               return -EBADF;
19960 +
19961 +       ret = __vc_get_iattr(filp->f_dentry->d_inode,
19962 +               &vc_data.tag, &vc_data.flags, &vc_data.mask);
19963 +
19964 +       fput(filp);
19965 +
19966 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19967 +               ret = -EFAULT;
19968 +       return ret;
19969 +}
19970 +
19971 +
19972 +static int __vc_set_iattr(struct dentry *de, uint32_t *tag, uint32_t *flags, uint32_t *mask)
19973 +{
19974 +       struct inode *in = de->d_inode;
19975 +       int error = 0, is_proc = 0, has_tag = 0;
19976 +       struct iattr attr = { 0 };
19977 +
19978 +       if (!in || !in->i_sb)
19979 +               return -ESRCH;
19980 +
19981 +       is_proc = (in->i_sb->s_magic == PROC_SUPER_MAGIC);
19982 +       if ((*mask & IATTR_FLAGS) && !is_proc)
19983 +               return -EINVAL;
19984 +
19985 +       has_tag = IS_TAGGED(in) ||
19986 +               (in->i_sb->s_magic == DEVPTS_SUPER_MAGIC);
19987 +       if ((*mask & IATTR_TAG) && !has_tag)
19988 +               return -EINVAL;
19989 +
19990 +       mutex_lock(&in->i_mutex);
19991 +       if (*mask & IATTR_TAG) {
19992 +               attr.ia_tag = *tag;
19993 +               attr.ia_valid |= ATTR_TAG;
19994 +       }
19995 +
19996 +       if (*mask & IATTR_FLAGS) {
19997 +               struct proc_dir_entry *entry = PROC_I(in)->pde;
19998 +               unsigned int iflags = PROC_I(in)->vx_flags;
19999 +
20000 +               iflags = (iflags & ~(*mask & IATTR_FLAGS))
20001 +                       | (*flags & IATTR_FLAGS);
20002 +               PROC_I(in)->vx_flags = iflags;
20003 +               if (entry)
20004 +                       entry->vx_flags = iflags;
20005 +       }
20006 +
20007 +       if (*mask & (IATTR_IMMUTABLE | IATTR_IXUNLINK |
20008 +               IATTR_BARRIER | IATTR_COW)) {
20009 +               int iflags = in->i_flags;
20010 +               int vflags = in->i_vflags;
20011 +
20012 +               if (*mask & IATTR_IMMUTABLE) {
20013 +                       if (*flags & IATTR_IMMUTABLE)
20014 +                               iflags |= S_IMMUTABLE;
20015 +                       else
20016 +                               iflags &= ~S_IMMUTABLE;
20017 +               }
20018 +               if (*mask & IATTR_IXUNLINK) {
20019 +                       if (*flags & IATTR_IXUNLINK)
20020 +                               iflags |= S_IXUNLINK;
20021 +                       else
20022 +                               iflags &= ~S_IXUNLINK;
20023 +               }
20024 +               if (S_ISDIR(in->i_mode) && (*mask & IATTR_BARRIER)) {
20025 +                       if (*flags & IATTR_BARRIER)
20026 +                               vflags |= V_BARRIER;
20027 +                       else
20028 +                               vflags &= ~V_BARRIER;
20029 +               }
20030 +               if (S_ISREG(in->i_mode) && (*mask & IATTR_COW)) {
20031 +                       if (*flags & IATTR_COW)
20032 +                               vflags |= V_COW;
20033 +                       else
20034 +                               vflags &= ~V_COW;
20035 +               }
20036 +               if (in->i_op && in->i_op->sync_flags) {
20037 +                       error = in->i_op->sync_flags(in, iflags, vflags);
20038 +                       if (error)
20039 +                               goto out;
20040 +               }
20041 +       }
20042 +
20043 +       if (attr.ia_valid) {
20044 +               if (in->i_op && in->i_op->setattr)
20045 +                       error = in->i_op->setattr(de, &attr);
20046 +               else {
20047 +                       error = inode_change_ok(in, &attr);
20048 +                       if (!error) {
20049 +                               setattr_copy(in, &attr);
20050 +                               mark_inode_dirty(in);
20051 +                       }
20052 +               }
20053 +       }
20054 +
20055 +out:
20056 +       mutex_unlock(&in->i_mutex);
20057 +       return error;
20058 +}
20059 +
20060 +int vc_set_iattr(void __user *data)
20061 +{
20062 +       struct path path;
20063 +       struct vcmd_ctx_iattr_v1 vc_data;
20064 +       int ret;
20065 +
20066 +       if (!capable(CAP_LINUX_IMMUTABLE))
20067 +               return -EPERM;
20068 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20069 +               return -EFAULT;
20070 +
20071 +       ret = user_lpath(vc_data.name, &path);
20072 +       if (!ret) {
20073 +               ret = __vc_set_iattr(path.dentry,
20074 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
20075 +               path_put(&path);
20076 +       }
20077 +
20078 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20079 +               ret = -EFAULT;
20080 +       return ret;
20081 +}
20082 +
20083 +#ifdef CONFIG_COMPAT
20084 +
20085 +int vc_set_iattr_x32(void __user *data)
20086 +{
20087 +       struct path path;
20088 +       struct vcmd_ctx_iattr_v1_x32 vc_data;
20089 +       int ret;
20090 +
20091 +       if (!capable(CAP_LINUX_IMMUTABLE))
20092 +               return -EPERM;
20093 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20094 +               return -EFAULT;
20095 +
20096 +       ret = user_lpath(compat_ptr(vc_data.name_ptr), &path);
20097 +       if (!ret) {
20098 +               ret = __vc_set_iattr(path.dentry,
20099 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
20100 +               path_put(&path);
20101 +       }
20102 +
20103 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20104 +               ret = -EFAULT;
20105 +       return ret;
20106 +}
20107 +
20108 +#endif /* CONFIG_COMPAT */
20109 +
20110 +int vc_fset_iattr(uint32_t fd, void __user *data)
20111 +{
20112 +       struct file *filp;
20113 +       struct vcmd_ctx_fiattr_v0 vc_data;
20114 +       int ret;
20115 +
20116 +       if (!capable(CAP_LINUX_IMMUTABLE))
20117 +               return -EPERM;
20118 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20119 +               return -EFAULT;
20120 +
20121 +       filp = fget(fd);
20122 +       if (!filp || !filp->f_dentry || !filp->f_dentry->d_inode)
20123 +               return -EBADF;
20124 +
20125 +       ret = __vc_set_iattr(filp->f_dentry, &vc_data.tag,
20126 +               &vc_data.flags, &vc_data.mask);
20127 +
20128 +       fput(filp);
20129 +
20130 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20131 +               return -EFAULT;
20132 +       return ret;
20133 +}
20134 +
20135 +
20136 +enum { Opt_notagcheck, Opt_tag, Opt_notag, Opt_tagid, Opt_err };
20137 +
20138 +static match_table_t tokens = {
20139 +       {Opt_notagcheck, "notagcheck"},
20140 +#ifdef CONFIG_PROPAGATE
20141 +       {Opt_notag, "notag"},
20142 +       {Opt_tag, "tag"},
20143 +       {Opt_tagid, "tagid=%u"},
20144 +#endif
20145 +       {Opt_err, NULL}
20146 +};
20147 +
20148 +
20149 +static void __dx_parse_remove(char *string, char *opt)
20150 +{
20151 +       char *p = strstr(string, opt);
20152 +       char *q = p;
20153 +
20154 +       if (p) {
20155 +               while (*q != '\0' && *q != ',')
20156 +                       q++;
20157 +               while (*q)
20158 +                       *p++ = *q++;
20159 +               while (*p)
20160 +                       *p++ = '\0';
20161 +       }
20162 +}
20163 +
20164 +int dx_parse_tag(char *string, tag_t *tag, int remove, int *mnt_flags,
20165 +                unsigned long *flags)
20166 +{
20167 +       int set = 0;
20168 +       substring_t args[MAX_OPT_ARGS];
20169 +       int token;
20170 +       char *s, *p, *opts;
20171 +#if defined(CONFIG_PROPAGATE) || defined(CONFIG_VSERVER_WARN)
20172 +       int option = 0;
20173 +#endif
20174 +
20175 +       if (!string)
20176 +               return 0;
20177 +       s = kstrdup(string, GFP_KERNEL | GFP_ATOMIC);
20178 +       if (!s)
20179 +               return 0;
20180 +
20181 +       opts = s;
20182 +       while ((p = strsep(&opts, ",")) != NULL) {
20183 +               token = match_token(p, tokens, args);
20184 +
20185 +               switch (token) {
20186 +#ifdef CONFIG_PROPAGATE
20187 +               case Opt_tag:
20188 +                       if (tag)
20189 +                               *tag = 0;
20190 +                       if (remove)
20191 +                               __dx_parse_remove(s, "tag");
20192 +                       *mnt_flags |= MNT_TAGID;
20193 +                       set |= MNT_TAGID;
20194 +                       break;
20195 +               case Opt_notag:
20196 +                       if (remove)
20197 +                               __dx_parse_remove(s, "notag");
20198 +                       *mnt_flags |= MNT_NOTAG;
20199 +                       set |= MNT_NOTAG;
20200 +                       break;
20201 +               case Opt_tagid:
20202 +                       if (tag && !match_int(args, &option))
20203 +                               *tag = option;
20204 +                       if (remove)
20205 +                               __dx_parse_remove(s, "tagid");
20206 +                       *mnt_flags |= MNT_TAGID;
20207 +                       set |= MNT_TAGID;
20208 +                       break;
20209 +#endif
20210 +               case Opt_notagcheck:
20211 +                       if (remove)
20212 +                               __dx_parse_remove(s, "notagcheck");
20213 +                       *flags |= MS_NOTAGCHECK;
20214 +                       set |= MS_NOTAGCHECK;
20215 +                       break;
20216 +               }
20217 +               vxdprintk(VXD_CBIT(tag, 7),
20218 +                       "dx_parse_tag(" VS_Q("%s") "): %d:#%d",
20219 +                       p, token, option);
20220 +       }
20221 +       if (set)
20222 +               strcpy(string, s);
20223 +       kfree(s);
20224 +       return set;
20225 +}
20226 +
20227 +#ifdef CONFIG_PROPAGATE
20228 +
20229 +void __dx_propagate_tag(struct nameidata *nd, struct inode *inode)
20230 +{
20231 +       tag_t new_tag = 0;
20232 +       struct vfsmount *mnt;
20233 +       int propagate;
20234 +
20235 +       if (!nd)
20236 +               return;
20237 +       mnt = nd->path.mnt;
20238 +       if (!mnt)
20239 +               return;
20240 +
20241 +       propagate = (mnt->mnt_flags & MNT_TAGID);
20242 +       if (propagate)
20243 +               new_tag = mnt->mnt_tag;
20244 +
20245 +       vxdprintk(VXD_CBIT(tag, 7),
20246 +               "dx_propagate_tag(%p[#%lu.%d]): %d,%d",
20247 +               inode, inode->i_ino, inode->i_tag,
20248 +               new_tag, (propagate) ? 1 : 0);
20249 +
20250 +       if (propagate)
20251 +               inode->i_tag = new_tag;
20252 +}
20253 +
20254 +#include <linux/module.h>
20255 +
20256 +EXPORT_SYMBOL_GPL(__dx_propagate_tag);
20257 +
20258 +#endif /* CONFIG_PROPAGATE */
20259 +
20260 diff -NurpP --minimal linux-2.6.38.3/kernel/vserver/limit.c linux-2.6.38.3-vs2.3.0.37-rc14/kernel/vserver/limit.c
20261 --- linux-2.6.38.3/kernel/vserver/limit.c       1970-01-01 01:00:00.000000000 +0100
20262 +++ linux-2.6.38.3-vs2.3.0.37-rc14/kernel/vserver/limit.c       2011-01-29 02:01:07.000000000 +0100
20263 @@ -0,0 +1,354 @@
20264 +/*
20265 + *  linux/kernel/vserver/limit.c
20266 + *
20267 + *  Virtual Server: Context Limits
20268 + *
20269 + *  Copyright (C) 2004-2010  Herbert Pötzl
20270 + *
20271 + *  V0.01  broken out from vcontext V0.05
20272 + *  V0.02  changed vcmds to vxi arg
20273 + *  V0.03  added memory cgroup support
20274 + *
20275 + */
20276 +
20277 +#include <linux/sched.h>
20278 +#include <linux/module.h>
20279 +#include <linux/memcontrol.h>
20280 +#include <linux/res_counter.h>
20281 +#include <linux/vs_limit.h>
20282 +#include <linux/vserver/limit.h>
20283 +#include <linux/vserver/limit_cmd.h>
20284 +
20285 +#include <asm/uaccess.h>
20286 +
20287 +
20288 +const char *vlimit_name[NUM_LIMITS] = {
20289 +#ifdef CONFIG_VSERVER_LEGACY_MEM
20290 +       [RLIMIT_RSS]            = "RSS",
20291 +       [RLIMIT_AS]             = "VM",
20292 +#endif /* CONFIG_VSERVER_LEGACY_MEM */
20293 +       [RLIMIT_CPU]            = "CPU",
20294 +       [RLIMIT_NPROC]          = "NPROC",
20295 +       [RLIMIT_NOFILE]         = "NOFILE",
20296 +       [RLIMIT_LOCKS]          = "LOCKS",
20297 +       [RLIMIT_SIGPENDING]     = "SIGP",
20298 +       [RLIMIT_MSGQUEUE]       = "MSGQ",
20299 +
20300 +       [VLIMIT_NSOCK]          = "NSOCK",
20301 +       [VLIMIT_OPENFD]         = "OPENFD",
20302 +       [VLIMIT_SHMEM]          = "SHMEM",
20303 +       [VLIMIT_DENTRY]         = "DENTRY",
20304 +};
20305 +
20306 +EXPORT_SYMBOL_GPL(vlimit_name);
20307 +
20308 +#define MASK_ENTRY(x)  (1 << (x))
20309 +
20310 +const struct vcmd_ctx_rlimit_mask_v0 vlimit_mask = {
20311 +               /* minimum */
20312 +       0
20313 +       ,       /* softlimit */
20314 +#ifdef CONFIG_VSERVER_LEGACY_MEM
20315 +       MASK_ENTRY( RLIMIT_RSS          ) |
20316 +#endif /* CONFIG_VSERVER_LEGACY_MEM */
20317 +       0
20318 +       ,       /* maximum */
20319 +#ifdef CONFIG_VSERVER_LEGACY_MEM
20320 +       MASK_ENTRY( RLIMIT_RSS          ) |
20321 +       MASK_ENTRY( RLIMIT_AS           ) |
20322 +#endif /* CONFIG_VSERVER_LEGACY_MEM */
20323 +       MASK_ENTRY( RLIMIT_NPROC        ) |
20324 +       MASK_ENTRY( RLIMIT_NOFILE       ) |
20325 +       MASK_ENTRY( RLIMIT_LOCKS        ) |
20326 +       MASK_ENTRY( RLIMIT_MSGQUEUE     ) |
20327 +
20328 +       MASK_ENTRY( VLIMIT_NSOCK        ) |
20329 +       MASK_ENTRY( VLIMIT_OPENFD       ) |
20330 +       MASK_ENTRY( VLIMIT_SHMEM        ) |
20331 +       MASK_ENTRY( VLIMIT_DENTRY       ) |
20332 +       0
20333 +};
20334 +               /* accounting only */
20335 +uint32_t account_mask =
20336 +       MASK_ENTRY( VLIMIT_SEMARY       ) |
20337 +       MASK_ENTRY( VLIMIT_NSEMS        ) |
20338 +       MASK_ENTRY( VLIMIT_MAPPED       ) |
20339 +       0;
20340 +
20341 +
20342 +static int is_valid_vlimit(int id)
20343 +{
20344 +       uint32_t mask = vlimit_mask.minimum |
20345 +               vlimit_mask.softlimit | vlimit_mask.maximum;
20346 +       return mask & (1 << id);
20347 +}
20348 +
20349 +static int is_accounted_vlimit(int id)
20350 +{
20351 +       if (is_valid_vlimit(id))
20352 +               return 1;
20353 +       return account_mask & (1 << id);
20354 +}
20355 +
20356 +
20357 +static inline uint64_t vc_get_soft(struct vx_info *vxi, int id)
20358 +{
20359 +       rlim_t limit = __rlim_soft(&vxi->limit, id);
20360 +       return VX_VLIM(limit);
20361 +}
20362 +
20363 +static inline uint64_t vc_get_hard(struct vx_info *vxi, int id)
20364 +{
20365 +       rlim_t limit = __rlim_hard(&vxi->limit, id);
20366 +       return VX_VLIM(limit);
20367 +}
20368 +
20369 +static int do_get_rlimit(struct vx_info *vxi, uint32_t id,
20370 +       uint64_t *minimum, uint64_t *softlimit, uint64_t *maximum)
20371 +{
20372 +       if (!is_valid_vlimit(id))
20373 +               return -EINVAL;
20374 +
20375 +       if (minimum)
20376 +               *minimum = CRLIM_UNSET;
20377 +       if (softlimit)
20378 +               *softlimit = vc_get_soft(vxi, id);
20379 +       if (maximum)
20380 +               *maximum = vc_get_hard(vxi, id);
20381 +       return 0;
20382 +}
20383 +
20384 +int vc_get_rlimit(struct vx_info *vxi, void __user *data)
20385 +{
20386 +       struct vcmd_ctx_rlimit_v0 vc_data;
20387 +       int ret;
20388 +
20389 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20390 +               return -EFAULT;
20391 +
20392 +       ret = do_get_rlimit(vxi, vc_data.id,
20393 +               &vc_data.minimum, &vc_data.softlimit, &vc_data.maximum);
20394 +       if (ret)
20395 +               return ret;
20396 +
20397 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20398 +               return -EFAULT;
20399 +       return 0;
20400 +}
20401 +
20402 +static int do_set_rlimit(struct vx_info *vxi, uint32_t id,
20403 +       uint64_t minimum, uint64_t softlimit, uint64_t maximum)
20404 +{
20405 +       if (!is_valid_vlimit(id))
20406 +               return -EINVAL;
20407 +
20408 +       if (maximum != CRLIM_KEEP)
20409 +               __rlim_hard(&vxi->limit, id) = VX_RLIM(maximum);
20410 +       if (softlimit != CRLIM_KEEP)
20411 +               __rlim_soft(&vxi->limit, id) = VX_RLIM(softlimit);
20412 +
20413 +       /* clamp soft limit */
20414 +       if (__rlim_soft(&vxi->limit, id) > __rlim_hard(&vxi->limit, id))
20415 +               __rlim_soft(&vxi->limit, id) = __rlim_hard(&vxi->limit, id);
20416 +
20417 +       return 0;
20418 +}
20419 +
20420 +int vc_set_rlimit(struct vx_info *vxi, void __user *data)
20421 +{
20422 +       struct vcmd_ctx_rlimit_v0 vc_data;
20423 +
20424 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20425 +               return -EFAULT;
20426 +
20427 +       return do_set_rlimit(vxi, vc_data.id,
20428 +               vc_data.minimum, vc_data.softlimit, vc_data.maximum);
20429 +}
20430 +
20431 +#ifdef CONFIG_IA32_EMULATION
20432 +
20433 +int vc_set_rlimit_x32(struct vx_info *vxi, void __user *data)
20434 +{
20435 +       struct vcmd_ctx_rlimit_v0_x32 vc_data;
20436 +
20437 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20438 +               return -EFAULT;
20439 +
20440 +       return do_set_rlimit(vxi, vc_data.id,
20441 +               vc_data.minimum, vc_data.softlimit, vc_data.maximum);
20442 +}
20443 +
20444 +int vc_get_rlimit_x32(struct vx_info *vxi, void __user *data)
20445 +{
20446 +       struct vcmd_ctx_rlimit_v0_x32 vc_data;
20447 +       int ret;
20448 +
20449 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20450 +               return -EFAULT;
20451 +
20452 +       ret = do_get_rlimit(vxi, vc_data.id,
20453 +               &vc_data.minimum, &vc_data.softlimit, &vc_data.maximum);
20454 +       if (ret)
20455 +               return ret;
20456 +
20457 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20458 +               return -EFAULT;
20459 +       return 0;
20460 +}
20461 +
20462 +#endif /* CONFIG_IA32_EMULATION */
20463 +
20464 +
20465 +int vc_get_rlimit_mask(uint32_t id, void __user *data)
20466 +{
20467 +       if (copy_to_user(data, &vlimit_mask, sizeof(vlimit_mask)))
20468 +               return -EFAULT;
20469 +       return 0;
20470 +}
20471 +
20472 +
20473 +static inline void vx_reset_hits(struct _vx_limit *limit)
20474 +{
20475 +       int lim;
20476 +
20477 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
20478 +               atomic_set(&__rlim_lhit(limit, lim), 0);
20479 +       }
20480 +}
20481 +
20482 +int vc_reset_hits(struct vx_info *vxi, void __user *data)
20483 +{
20484 +       vx_reset_hits(&vxi->limit);
20485 +       return 0;
20486 +}
20487 +
20488 +static inline void vx_reset_minmax(struct _vx_limit *limit)
20489 +{
20490 +       rlim_t value;
20491 +       int lim;
20492 +
20493 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
20494 +               value = __rlim_get(limit, lim);
20495 +               __rlim_rmax(limit, lim) = value;
20496 +               __rlim_rmin(limit, lim) = value;
20497 +       }
20498 +}
20499 +
20500 +int vc_reset_minmax(struct vx_info *vxi, void __user *data)
20501 +{
20502 +       vx_reset_minmax(&vxi->limit);
20503 +       return 0;
20504 +}
20505 +
20506 +
20507 +int vc_rlimit_stat(struct vx_info *vxi, void __user *data)
20508 +{
20509 +       struct vcmd_rlimit_stat_v0 vc_data;
20510 +       struct _vx_limit *limit = &vxi->limit;
20511 +       int id;
20512 +
20513 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20514 +               return -EFAULT;
20515 +
20516 +       id = vc_data.id;
20517 +       if (!is_accounted_vlimit(id))
20518 +               return -EINVAL;
20519 +
20520 +       vx_limit_fixup(limit, id);
20521 +       vc_data.hits = atomic_read(&__rlim_lhit(limit, id));
20522 +       vc_data.value = __rlim_get(limit, id);
20523 +       vc_data.minimum = __rlim_rmin(limit, id);
20524 +       vc_data.maximum = __rlim_rmax(limit, id);
20525 +
20526 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20527 +               return -EFAULT;
20528 +       return 0;
20529 +}
20530 +
20531 +
20532 +void vx_vsi_meminfo(struct sysinfo *val)
20533 +{
20534 +#ifdef CONFIG_CGROUP_MEM_RES_CTLR
20535 +       struct mem_cgroup *mcg = mem_cgroup_from_task(current);
20536 +       u64 res_limit, res_usage;
20537 +
20538 +       if (!mcg)
20539 +               return;
20540 +
20541 +       res_limit = mem_cgroup_res_read_u64(mcg, RES_LIMIT);
20542 +       res_usage = mem_cgroup_res_read_u64(mcg, RES_USAGE);
20543 +
20544 +       if (res_limit != RESOURCE_MAX)
20545 +               val->totalram = (res_limit >> PAGE_SHIFT);
20546 +       val->freeram = val->totalram - (res_usage >> PAGE_SHIFT);
20547 +       val->bufferram = 0;
20548 +       val->totalhigh = 0;
20549 +       val->freehigh = 0;
20550 +#endif /* CONFIG_CGROUP_MEM_RES_CTLR */
20551 +       return;
20552 +}
20553 +
20554 +void vx_vsi_swapinfo(struct sysinfo *val)
20555 +{
20556 +#ifdef CONFIG_CGROUP_MEM_RES_CTLR
20557 +#ifdef CONFIG_CGROUP_MEM_RES_CTLR_SWAP
20558 +       struct mem_cgroup *mcg = mem_cgroup_from_task(current);
20559 +       u64 res_limit, res_usage, memsw_limit, memsw_usage;
20560 +       s64 swap_limit, swap_usage;
20561 +
20562 +       if (!mcg)
20563 +               return;
20564 +
20565 +       res_limit = mem_cgroup_res_read_u64(mcg, RES_LIMIT);
20566 +       res_usage = mem_cgroup_res_read_u64(mcg, RES_USAGE);
20567 +       memsw_limit = mem_cgroup_memsw_read_u64(mcg, RES_LIMIT);
20568 +       memsw_usage = mem_cgroup_memsw_read_u64(mcg, RES_USAGE);
20569 +
20570 +       if (res_limit == RESOURCE_MAX)
20571 +               return;
20572 +
20573 +       swap_limit = memsw_limit - res_limit;
20574 +       if (memsw_limit != RESOURCE_MAX)
20575 +               val->totalswap = swap_limit >> PAGE_SHIFT;
20576 +
20577 +       swap_usage = memsw_usage - res_usage;
20578 +       val->freeswap = (swap_usage < swap_limit) ?
20579 +               val->totalswap - (swap_usage >> PAGE_SHIFT) : 0;
20580 +#else  /* !CONFIG_CGROUP_MEM_RES_CTLR_SWAP */
20581 +       val->totalswap = 0;
20582 +       val->freeswap = 0;
20583 +#endif /* !CONFIG_CGROUP_MEM_RES_CTLR_SWAP */
20584 +#endif /* CONFIG_CGROUP_MEM_RES_CTLR */
20585 +       return;
20586 +}
20587 +
20588 +long vx_vsi_cached(struct sysinfo *val)
20589 +{
20590 +#ifdef CONFIG_CGROUP_MEM_RES_CTLR
20591 +       struct mem_cgroup *mcg = mem_cgroup_from_task(current);
20592 +
20593 +       return mem_cgroup_stat_read_cache(mcg);
20594 +#else
20595 +       return 0;
20596 +#endif
20597 +}
20598 +
20599 +
20600 +unsigned long vx_badness(struct task_struct *task, struct mm_struct *mm)
20601 +{
20602 +       struct vx_info *vxi = mm->mm_vx_info;
20603 +       unsigned long points;
20604 +       rlim_t v, w;
20605 +
20606 +       if (!vxi)
20607 +               return 0;
20608 +
20609 +       points = vxi->vx_badness_bias;
20610 +
20611 +       v = __vx_cres_array_fixup(&vxi->limit, VLA_RSS);
20612 +       w = __rlim_soft(&vxi->limit, RLIMIT_RSS);
20613 +       points += (v > w) ? (v - w) : 0;
20614 +
20615 +       return points;
20616 +}
20617 +
20618 diff -NurpP --minimal linux-2.6.38.3/kernel/vserver/limit_init.h linux-2.6.38.3-vs2.3.0.37-rc14/kernel/vserver/limit_init.h
20619 --- linux-2.6.38.3/kernel/vserver/limit_init.h  1970-01-01 01:00:00.000000000 +0100
20620 +++ linux-2.6.38.3-vs2.3.0.37-rc14/kernel/vserver/limit_init.h  2011-01-29 02:01:07.000000000 +0100
20621 @@ -0,0 +1,31 @@
20622 +
20623 +
20624 +static inline void vx_info_init_limit(struct _vx_limit *limit)
20625 +{
20626 +       int lim;
20627 +
20628 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
20629 +               __rlim_soft(limit, lim) = RLIM_INFINITY;
20630 +               __rlim_hard(limit, lim) = RLIM_INFINITY;
20631 +               __rlim_set(limit, lim, 0);
20632 +               atomic_set(&__rlim_lhit(limit, lim), 0);
20633 +               __rlim_rmin(limit, lim) = 0;
20634 +               __rlim_rmax(limit, lim) = 0;
20635 +       }
20636 +}
20637 +
20638 +static inline void vx_info_exit_limit(struct _vx_limit *limit)
20639 +{
20640 +       rlim_t value;
20641 +       int lim;
20642 +
20643 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
20644 +               if ((1 << lim) & VLIM_NOCHECK)
20645 +                       continue;
20646 +               value = __rlim_get(limit, lim);
20647 +               vxwprintk_xid(value,
20648 +                       "!!! limit: %p[%s,%d] = %ld on exit.",
20649 +                       limit, vlimit_name[lim], lim, (long)value);
20650 +       }
20651 +}
20652 +
20653 diff -NurpP --minimal linux-2.6.38.3/kernel/vserver/limit_proc.h linux-2.6.38.3-vs2.3.0.37-rc14/kernel/vserver/limit_proc.h
20654 --- linux-2.6.38.3/kernel/vserver/limit_proc.h  1970-01-01 01:00:00.000000000 +0100
20655 +++ linux-2.6.38.3-vs2.3.0.37-rc14/kernel/vserver/limit_proc.h  2011-01-29 02:01:07.000000000 +0100
20656 @@ -0,0 +1,57 @@
20657 +#ifndef _VX_LIMIT_PROC_H
20658 +#define _VX_LIMIT_PROC_H
20659 +
20660 +#include <linux/vserver/limit_int.h>
20661 +
20662 +
20663 +#define VX_LIMIT_FMT   ":\t%8ld\t%8ld/%8ld\t%8lld/%8lld\t%6d\n"
20664 +#define VX_LIMIT_TOP   \
20665 +       "Limit\t current\t     min/max\t\t    soft/hard\t\thits\n"
20666 +
20667 +#define VX_LIMIT_ARG(r)                                \
20668 +       (unsigned long)__rlim_get(limit, r),    \
20669 +       (unsigned long)__rlim_rmin(limit, r),   \
20670 +       (unsigned long)__rlim_rmax(limit, r),   \
20671 +       VX_VLIM(__rlim_soft(limit, r)),         \
20672 +       VX_VLIM(__rlim_hard(limit, r)),         \
20673 +       atomic_read(&__rlim_lhit(limit, r))
20674 +
20675 +static inline int vx_info_proc_limit(struct _vx_limit *limit, char *buffer)
20676 +{
20677 +       vx_limit_fixup(limit, -1);
20678 +       return sprintf(buffer, VX_LIMIT_TOP
20679 +               "PROC"  VX_LIMIT_FMT
20680 +               "VM"    VX_LIMIT_FMT
20681 +               "VML"   VX_LIMIT_FMT
20682 +               "RSS"   VX_LIMIT_FMT
20683 +               "ANON"  VX_LIMIT_FMT
20684 +               "RMAP"  VX_LIMIT_FMT
20685 +               "FILES" VX_LIMIT_FMT
20686 +               "OFD"   VX_LIMIT_FMT
20687 +               "LOCKS" VX_LIMIT_FMT
20688 +               "SOCK"  VX_LIMIT_FMT
20689 +               "MSGQ"  VX_LIMIT_FMT
20690 +               "SHM"   VX_LIMIT_FMT
20691 +               "SEMA"  VX_LIMIT_FMT
20692 +               "SEMS"  VX_LIMIT_FMT
20693 +               "DENT"  VX_LIMIT_FMT,
20694 +               VX_LIMIT_ARG(RLIMIT_NPROC),
20695 +               VX_LIMIT_ARG(RLIMIT_AS),
20696 +               VX_LIMIT_ARG(RLIMIT_MEMLOCK),
20697 +               VX_LIMIT_ARG(RLIMIT_RSS),
20698 +               VX_LIMIT_ARG(VLIMIT_ANON),
20699 +               VX_LIMIT_ARG(VLIMIT_MAPPED),
20700 +               VX_LIMIT_ARG(RLIMIT_NOFILE),
20701 +               VX_LIMIT_ARG(VLIMIT_OPENFD),
20702 +               VX_LIMIT_ARG(RLIMIT_LOCKS),
20703 +               VX_LIMIT_ARG(VLIMIT_NSOCK),
20704 +               VX_LIMIT_ARG(RLIMIT_MSGQUEUE),
20705 +               VX_LIMIT_ARG(VLIMIT_SHMEM),
20706 +               VX_LIMIT_ARG(VLIMIT_SEMARY),
20707 +               VX_LIMIT_ARG(VLIMIT_NSEMS),
20708 +               VX_LIMIT_ARG(VLIMIT_DENTRY));
20709 +}
20710 +
20711 +#endif /* _VX_LIMIT_PROC_H */
20712 +
20713 +
20714 diff -NurpP --minimal linux-2.6.38.3/kernel/vserver/network.c linux-2.6.38.3-vs2.3.0.37-rc14/kernel/vserver/network.c
20715 --- linux-2.6.38.3/kernel/vserver/network.c     1970-01-01 01:00:00.000000000 +0100
20716 +++ linux-2.6.38.3-vs2.3.0.37-rc14/kernel/vserver/network.c     2011-04-15 16:07:48.000000000 +0200
20717 @@ -0,0 +1,914 @@
20718 +/*
20719 + *  linux/kernel/vserver/network.c
20720 + *
20721 + *  Virtual Server: Network Support
20722 + *
20723 + *  Copyright (C) 2003-2007  Herbert Pötzl
20724 + *
20725 + *  V0.01  broken out from vcontext V0.05
20726 + *  V0.02  cleaned up implementation
20727 + *  V0.03  added equiv nx commands
20728 + *  V0.04  switch to RCU based hash
20729 + *  V0.05  and back to locking again
20730 + *  V0.06  changed vcmds to nxi arg
20731 + *  V0.07  have __create claim() the nxi
20732 + *
20733 + */
20734 +
20735 +#include <linux/err.h>
20736 +#include <linux/slab.h>
20737 +#include <linux/rcupdate.h>
20738 +
20739 +#include <linux/vs_network.h>
20740 +#include <linux/vs_pid.h>
20741 +#include <linux/vserver/network_cmd.h>
20742 +
20743 +
20744 +atomic_t nx_global_ctotal      = ATOMIC_INIT(0);
20745 +atomic_t nx_global_cactive     = ATOMIC_INIT(0);
20746 +
20747 +static struct kmem_cache *nx_addr_v4_cachep = NULL;
20748 +static struct kmem_cache *nx_addr_v6_cachep = NULL;
20749 +
20750 +
20751 +static int __init init_network(void)
20752 +{
20753 +       nx_addr_v4_cachep = kmem_cache_create("nx_v4_addr_cache",
20754 +               sizeof(struct nx_addr_v4), 0,
20755 +               SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
20756 +       nx_addr_v6_cachep = kmem_cache_create("nx_v6_addr_cache",
20757 +               sizeof(struct nx_addr_v6), 0,
20758 +               SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
20759 +       return 0;
20760 +}
20761 +
20762 +
20763 +/*     __alloc_nx_addr_v4()                                    */
20764 +
20765 +static inline struct nx_addr_v4 *__alloc_nx_addr_v4(void)
20766 +{
20767 +       struct nx_addr_v4 *nxa = kmem_cache_alloc(
20768 +               nx_addr_v4_cachep, GFP_KERNEL);
20769 +
20770 +       if (!IS_ERR(nxa))
20771 +               memset(nxa, 0, sizeof(*nxa));
20772 +       return nxa;
20773 +}
20774 +
20775 +/*     __dealloc_nx_addr_v4()                                  */
20776 +
20777 +static inline void __dealloc_nx_addr_v4(struct nx_addr_v4 *nxa)
20778 +{
20779 +       kmem_cache_free(nx_addr_v4_cachep, nxa);
20780 +}
20781 +
20782 +/*     __dealloc_nx_addr_v4_all()                              */
20783 +
20784 +static inline void __dealloc_nx_addr_v4_all(struct nx_addr_v4 *nxa)
20785 +{
20786 +       while (nxa) {
20787 +               struct nx_addr_v4 *next = nxa->next;
20788 +
20789 +               __dealloc_nx_addr_v4(nxa);
20790 +               nxa = next;
20791 +       }
20792 +}
20793 +
20794 +
20795 +#ifdef CONFIG_IPV6
20796 +
20797 +/*     __alloc_nx_addr_v6()                                    */
20798 +
20799 +static inline struct nx_addr_v6 *__alloc_nx_addr_v6(void)
20800 +{
20801 +       struct nx_addr_v6 *nxa = kmem_cache_alloc(
20802 +               nx_addr_v6_cachep, GFP_KERNEL);
20803 +
20804 +       if (!IS_ERR(nxa))
20805 +               memset(nxa, 0, sizeof(*nxa));
20806 +       return nxa;
20807 +}
20808 +
20809 +/*     __dealloc_nx_addr_v6()                                  */
20810 +
20811 +static inline void __dealloc_nx_addr_v6(struct nx_addr_v6 *nxa)
20812 +{
20813 +       kmem_cache_free(nx_addr_v6_cachep, nxa);
20814 +}
20815 +
20816 +/*     __dealloc_nx_addr_v6_all()                              */
20817 +
20818 +static inline void __dealloc_nx_addr_v6_all(struct nx_addr_v6 *nxa)
20819 +{
20820 +       while (nxa) {
20821 +               struct nx_addr_v6 *next = nxa->next;
20822 +
20823 +               __dealloc_nx_addr_v6(nxa);
20824 +               nxa = next;
20825 +       }
20826 +}
20827 +
20828 +#endif /* CONFIG_IPV6 */
20829 +
20830 +/*     __alloc_nx_info()
20831 +
20832 +       * allocate an initialized nx_info struct
20833 +       * doesn't make it visible (hash)                        */
20834 +
20835 +static struct nx_info *__alloc_nx_info(nid_t nid)
20836 +{
20837 +       struct nx_info *new = NULL;
20838 +
20839 +       vxdprintk(VXD_CBIT(nid, 1), "alloc_nx_info(%d)*", nid);
20840 +
20841 +       /* would this benefit from a slab cache? */
20842 +       new = kmalloc(sizeof(struct nx_info), GFP_KERNEL);
20843 +       if (!new)
20844 +               return 0;
20845 +
20846 +       memset(new, 0, sizeof(struct nx_info));
20847 +       new->nx_id = nid;
20848 +       INIT_HLIST_NODE(&new->nx_hlist);
20849 +       atomic_set(&new->nx_usecnt, 0);
20850 +       atomic_set(&new->nx_tasks, 0);
20851 +       new->nx_state = 0;
20852 +
20853 +       new->nx_flags = NXF_INIT_SET;
20854 +
20855 +       /* rest of init goes here */
20856 +
20857 +       new->v4_lback.s_addr = htonl(INADDR_LOOPBACK);
20858 +       new->v4_bcast.s_addr = htonl(INADDR_BROADCAST);
20859 +
20860 +       vxdprintk(VXD_CBIT(nid, 0),
20861 +               "alloc_nx_info(%d) = %p", nid, new);
20862 +       atomic_inc(&nx_global_ctotal);
20863 +       return new;
20864 +}
20865 +
20866 +/*     __dealloc_nx_info()
20867 +
20868 +       * final disposal of nx_info                             */
20869 +
20870 +static void __dealloc_nx_info(struct nx_info *nxi)
20871 +{
20872 +       vxdprintk(VXD_CBIT(nid, 0),
20873 +               "dealloc_nx_info(%p)", nxi);
20874 +
20875 +       nxi->nx_hlist.next = LIST_POISON1;
20876 +       nxi->nx_id = -1;
20877 +
20878 +       BUG_ON(atomic_read(&nxi->nx_usecnt));
20879 +       BUG_ON(atomic_read(&nxi->nx_tasks));
20880 +
20881 +       __dealloc_nx_addr_v4_all(nxi->v4.next);
20882 +
20883 +       nxi->nx_state |= NXS_RELEASED;
20884 +       kfree(nxi);
20885 +       atomic_dec(&nx_global_ctotal);
20886 +}
20887 +
20888 +static void __shutdown_nx_info(struct nx_info *nxi)
20889 +{
20890 +       nxi->nx_state |= NXS_SHUTDOWN;
20891 +       vs_net_change(nxi, VSC_NETDOWN);
20892 +}
20893 +
20894 +/*     exported stuff                                          */
20895 +
20896 +void free_nx_info(struct nx_info *nxi)
20897 +{
20898 +       /* context shutdown is mandatory */
20899 +       BUG_ON(nxi->nx_state != NXS_SHUTDOWN);
20900 +
20901 +       /* context must not be hashed */
20902 +       BUG_ON(nxi->nx_state & NXS_HASHED);
20903 +
20904 +       BUG_ON(atomic_read(&nxi->nx_usecnt));
20905 +       BUG_ON(atomic_read(&nxi->nx_tasks));
20906 +
20907 +       __dealloc_nx_info(nxi);
20908 +}
20909 +
20910 +
20911 +void __nx_set_lback(struct nx_info *nxi)
20912 +{
20913 +       int nid = nxi->nx_id;
20914 +       __be32 lback = htonl(INADDR_LOOPBACK ^ ((nid & 0xFFFF) << 8));
20915 +
20916 +       nxi->v4_lback.s_addr = lback;
20917 +}
20918 +
20919 +extern int __nx_inet_add_lback(__be32 addr);
20920 +extern int __nx_inet_del_lback(__be32 addr);
20921 +
20922 +
20923 +/*     hash table for nx_info hash */
20924 +
20925 +#define NX_HASH_SIZE   13
20926 +
20927 +struct hlist_head nx_info_hash[NX_HASH_SIZE];
20928 +
20929 +static spinlock_t nx_info_hash_lock = SPIN_LOCK_UNLOCKED;
20930 +
20931 +
20932 +static inline unsigned int __hashval(nid_t nid)
20933 +{
20934 +       return (nid % NX_HASH_SIZE);
20935 +}
20936 +
20937 +
20938 +
20939 +/*     __hash_nx_info()
20940 +
20941 +       * add the nxi to the global hash table
20942 +       * requires the hash_lock to be held                     */
20943 +
20944 +static inline void __hash_nx_info(struct nx_info *nxi)
20945 +{
20946 +       struct hlist_head *head;
20947 +
20948 +       vxd_assert_lock(&nx_info_hash_lock);
20949 +       vxdprintk(VXD_CBIT(nid, 4),
20950 +               "__hash_nx_info: %p[#%d]", nxi, nxi->nx_id);
20951 +
20952 +       /* context must not be hashed */
20953 +       BUG_ON(nx_info_state(nxi, NXS_HASHED));
20954 +
20955 +       nxi->nx_state |= NXS_HASHED;
20956 +       head = &nx_info_hash[__hashval(nxi->nx_id)];
20957 +       hlist_add_head(&nxi->nx_hlist, head);
20958 +       atomic_inc(&nx_global_cactive);
20959 +}
20960 +
20961 +/*     __unhash_nx_info()
20962 +
20963 +       * remove the nxi from the global hash table
20964 +       * requires the hash_lock to be held                     */
20965 +
20966 +static inline void __unhash_nx_info(struct nx_info *nxi)
20967 +{
20968 +       vxd_assert_lock(&nx_info_hash_lock);
20969 +       vxdprintk(VXD_CBIT(nid, 4),
20970 +               "__unhash_nx_info: %p[#%d.%d.%d]", nxi, nxi->nx_id,
20971 +               atomic_read(&nxi->nx_usecnt), atomic_read(&nxi->nx_tasks));
20972 +
20973 +       /* context must be hashed */
20974 +       BUG_ON(!nx_info_state(nxi, NXS_HASHED));
20975 +       /* but without tasks */
20976 +       BUG_ON(atomic_read(&nxi->nx_tasks));
20977 +
20978 +       nxi->nx_state &= ~NXS_HASHED;
20979 +       hlist_del(&nxi->nx_hlist);
20980 +       atomic_dec(&nx_global_cactive);
20981 +}
20982 +
20983 +
20984 +/*     __lookup_nx_info()
20985 +
20986 +       * requires the hash_lock to be held
20987 +       * doesn't increment the nx_refcnt                       */
20988 +
20989 +static inline struct nx_info *__lookup_nx_info(nid_t nid)
20990 +{
20991 +       struct hlist_head *head = &nx_info_hash[__hashval(nid)];
20992 +       struct hlist_node *pos;
20993 +       struct nx_info *nxi;
20994 +
20995 +       vxd_assert_lock(&nx_info_hash_lock);
20996 +       hlist_for_each(pos, head) {
20997 +               nxi = hlist_entry(pos, struct nx_info, nx_hlist);
20998 +
20999 +               if (nxi->nx_id == nid)
21000 +                       goto found;
21001 +       }
21002 +       nxi = NULL;
21003 +found:
21004 +       vxdprintk(VXD_CBIT(nid, 0),
21005 +               "__lookup_nx_info(#%u): %p[#%u]",
21006 +               nid, nxi, nxi ? nxi->nx_id : 0);
21007 +       return nxi;
21008 +}
21009 +
21010 +
21011 +/*     __create_nx_info()
21012 +
21013 +       * create the requested context
21014 +       * get(), claim() and hash it                            */
21015 +
21016 +static struct nx_info *__create_nx_info(int id)
21017 +{
21018 +       struct nx_info *new, *nxi = NULL;
21019 +
21020 +       vxdprintk(VXD_CBIT(nid, 1), "create_nx_info(%d)*", id);
21021 +
21022 +       if (!(new = __alloc_nx_info(id)))
21023 +               return ERR_PTR(-ENOMEM);
21024 +
21025 +       /* required to make dynamic xids unique */
21026 +       spin_lock(&nx_info_hash_lock);
21027 +
21028 +       /* static context requested */
21029 +       if ((nxi = __lookup_nx_info(id))) {
21030 +               vxdprintk(VXD_CBIT(nid, 0),
21031 +                       "create_nx_info(%d) = %p (already there)", id, nxi);
21032 +               if (nx_info_flags(nxi, NXF_STATE_SETUP, 0))
21033 +                       nxi = ERR_PTR(-EBUSY);
21034 +               else
21035 +                       nxi = ERR_PTR(-EEXIST);
21036 +               goto out_unlock;
21037 +       }
21038 +       /* new context */
21039 +       vxdprintk(VXD_CBIT(nid, 0),
21040 +               "create_nx_info(%d) = %p (new)", id, new);
21041 +       claim_nx_info(new, NULL);
21042 +       __nx_set_lback(new);
21043 +       __hash_nx_info(get_nx_info(new));
21044 +       nxi = new, new = NULL;
21045 +
21046 +out_unlock:
21047 +       spin_unlock(&nx_info_hash_lock);
21048 +       if (new)
21049 +               __dealloc_nx_info(new);
21050 +       return nxi;
21051 +}
21052 +
21053 +
21054 +
21055 +/*     exported stuff                                          */
21056 +
21057 +
21058 +void unhash_nx_info(struct nx_info *nxi)
21059 +{
21060 +       __shutdown_nx_info(nxi);
21061 +       spin_lock(&nx_info_hash_lock);
21062 +       __unhash_nx_info(nxi);
21063 +       spin_unlock(&nx_info_hash_lock);
21064 +}
21065 +
21066 +/*     lookup_nx_info()
21067 +
21068 +       * search for a nx_info and get() it
21069 +       * negative id means current                             */
21070 +
21071 +struct nx_info *lookup_nx_info(int id)
21072 +{
21073 +       struct nx_info *nxi = NULL;
21074 +
21075 +       if (id < 0) {
21076 +               nxi = get_nx_info(current_nx_info());
21077 +       } else if (id > 1) {
21078 +               spin_lock(&nx_info_hash_lock);
21079 +               nxi = get_nx_info(__lookup_nx_info(id));
21080 +               spin_unlock(&nx_info_hash_lock);
21081 +       }
21082 +       return nxi;
21083 +}
21084 +
21085 +/*     nid_is_hashed()
21086 +
21087 +       * verify that nid is still hashed                       */
21088 +
21089 +int nid_is_hashed(nid_t nid)
21090 +{
21091 +       int hashed;
21092 +
21093 +       spin_lock(&nx_info_hash_lock);
21094 +       hashed = (__lookup_nx_info(nid) != NULL);
21095 +       spin_unlock(&nx_info_hash_lock);
21096 +       return hashed;
21097 +}
21098 +
21099 +
21100 +#ifdef CONFIG_PROC_FS
21101 +
21102 +/*     get_nid_list()
21103 +
21104 +       * get a subset of hashed nids for proc
21105 +       * assumes size is at least one                          */
21106 +
21107 +int get_nid_list(int index, unsigned int *nids, int size)
21108 +{
21109 +       int hindex, nr_nids = 0;
21110 +
21111 +       /* only show current and children */
21112 +       if (!nx_check(0, VS_ADMIN | VS_WATCH)) {
21113 +               if (index > 0)
21114 +                       return 0;
21115 +               nids[nr_nids] = nx_current_nid();
21116 +               return 1;
21117 +       }
21118 +
21119 +       for (hindex = 0; hindex < NX_HASH_SIZE; hindex++) {
21120 +               struct hlist_head *head = &nx_info_hash[hindex];
21121 +               struct hlist_node *pos;
21122 +
21123 +               spin_lock(&nx_info_hash_lock);
21124 +               hlist_for_each(pos, head) {
21125 +                       struct nx_info *nxi;
21126 +
21127 +                       if (--index > 0)
21128 +                               continue;
21129 +
21130 +                       nxi = hlist_entry(pos, struct nx_info, nx_hlist);
21131 +                       nids[nr_nids] = nxi->nx_id;
21132 +                       if (++nr_nids >= size) {
21133 +                               spin_unlock(&nx_info_hash_lock);
21134 +                               goto out;
21135 +                       }
21136 +               }
21137 +               /* keep the lock time short */
21138 +               spin_unlock(&nx_info_hash_lock);
21139 +       }
21140 +out:
21141 +       return nr_nids;
21142 +}
21143 +#endif
21144 +
21145 +
21146 +/*
21147 + *     migrate task to new network
21148 + *     gets nxi, puts old_nxi on change
21149 + */
21150 +
21151 +int nx_migrate_task(struct task_struct *p, struct nx_info *nxi)
21152 +{
21153 +       struct nx_info *old_nxi;
21154 +       int ret = 0;
21155 +
21156 +       if (!p || !nxi)
21157 +               BUG();
21158 +
21159 +       vxdprintk(VXD_CBIT(nid, 5),
21160 +               "nx_migrate_task(%p,%p[#%d.%d.%d])",
21161 +               p, nxi, nxi->nx_id,
21162 +               atomic_read(&nxi->nx_usecnt),
21163 +               atomic_read(&nxi->nx_tasks));
21164 +
21165 +       if (nx_info_flags(nxi, NXF_INFO_PRIVATE, 0) &&
21166 +               !nx_info_flags(nxi, NXF_STATE_SETUP, 0))
21167 +               return -EACCES;
21168 +
21169 +       if (nx_info_state(nxi, NXS_SHUTDOWN))
21170 +               return -EFAULT;
21171 +
21172 +       /* maybe disallow this completely? */
21173 +       old_nxi = task_get_nx_info(p);
21174 +       if (old_nxi == nxi)
21175 +               goto out;
21176 +
21177 +       task_lock(p);
21178 +       if (old_nxi)
21179 +               clr_nx_info(&p->nx_info);
21180 +       claim_nx_info(nxi, p);
21181 +       set_nx_info(&p->nx_info, nxi);
21182 +       p->nid = nxi->nx_id;
21183 +       task_unlock(p);
21184 +
21185 +       vxdprintk(VXD_CBIT(nid, 5),
21186 +               "moved task %p into nxi:%p[#%d]",
21187 +               p, nxi, nxi->nx_id);
21188 +
21189 +       if (old_nxi)
21190 +               release_nx_info(old_nxi, p);
21191 +       ret = 0;
21192 +out:
21193 +       put_nx_info(old_nxi);
21194 +       return ret;
21195 +}
21196 +
21197 +
21198 +void nx_set_persistent(struct nx_info *nxi)
21199 +{
21200 +       vxdprintk(VXD_CBIT(nid, 6),
21201 +               "nx_set_persistent(%p[#%d])", nxi, nxi->nx_id);
21202 +
21203 +       get_nx_info(nxi);
21204 +       claim_nx_info(nxi, NULL);
21205 +}
21206 +
21207 +void nx_clear_persistent(struct nx_info *nxi)
21208 +{
21209 +       vxdprintk(VXD_CBIT(nid, 6),
21210 +               "nx_clear_persistent(%p[#%d])", nxi, nxi->nx_id);
21211 +
21212 +       release_nx_info(nxi, NULL);
21213 +       put_nx_info(nxi);
21214 +}
21215 +
21216 +void nx_update_persistent(struct nx_info *nxi)
21217 +{
21218 +       if (nx_info_flags(nxi, NXF_PERSISTENT, 0))
21219 +               nx_set_persistent(nxi);
21220 +       else
21221 +               nx_clear_persistent(nxi);
21222 +}
21223 +
21224 +/* vserver syscall commands below here */
21225 +
21226 +/* taks nid and nx_info functions */
21227 +
21228 +#include <asm/uaccess.h>
21229 +
21230 +
21231 +int vc_task_nid(uint32_t id)
21232 +{
21233 +       nid_t nid;
21234 +
21235 +       if (id) {
21236 +               struct task_struct *tsk;
21237 +
21238 +               rcu_read_lock();
21239 +               tsk = find_task_by_real_pid(id);
21240 +               nid = (tsk) ? tsk->nid : -ESRCH;
21241 +               rcu_read_unlock();
21242 +       } else
21243 +               nid = nx_current_nid();
21244 +       return nid;
21245 +}
21246 +
21247 +
21248 +int vc_nx_info(struct nx_info *nxi, void __user *data)
21249 +{
21250 +       struct vcmd_nx_info_v0 vc_data;
21251 +
21252 +       vc_data.nid = nxi->nx_id;
21253 +
21254 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21255 +               return -EFAULT;
21256 +       return 0;
21257 +}
21258 +
21259 +
21260 +/* network functions */
21261 +
21262 +int vc_net_create(uint32_t nid, void __user *data)
21263 +{
21264 +       struct vcmd_net_create vc_data = { .flagword = NXF_INIT_SET };
21265 +       struct nx_info *new_nxi;
21266 +       int ret;
21267 +
21268 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
21269 +               return -EFAULT;
21270 +
21271 +       if ((nid > MAX_S_CONTEXT) || (nid < 2))
21272 +               return -EINVAL;
21273 +
21274 +       new_nxi = __create_nx_info(nid);
21275 +       if (IS_ERR(new_nxi))
21276 +               return PTR_ERR(new_nxi);
21277 +
21278 +       /* initial flags */
21279 +       new_nxi->nx_flags = vc_data.flagword;
21280 +
21281 +       ret = -ENOEXEC;
21282 +       if (vs_net_change(new_nxi, VSC_NETUP))
21283 +               goto out;
21284 +
21285 +       ret = nx_migrate_task(current, new_nxi);
21286 +       if (ret)
21287 +               goto out;
21288 +
21289 +       /* return context id on success */
21290 +       ret = new_nxi->nx_id;
21291 +
21292 +       /* get a reference for persistent contexts */
21293 +       if ((vc_data.flagword & NXF_PERSISTENT))
21294 +               nx_set_persistent(new_nxi);
21295 +out:
21296 +       release_nx_info(new_nxi, NULL);
21297 +       put_nx_info(new_nxi);
21298 +       return ret;
21299 +}
21300 +
21301 +
21302 +int vc_net_migrate(struct nx_info *nxi, void __user *data)
21303 +{
21304 +       return nx_migrate_task(current, nxi);
21305 +}
21306 +
21307 +
21308 +
21309 +int do_add_v4_addr(struct nx_info *nxi, __be32 ip, __be32 ip2, __be32 mask,
21310 +       uint16_t type, uint16_t flags)
21311 +{
21312 +       struct nx_addr_v4 *nxa = &nxi->v4;
21313 +
21314 +       if (NX_IPV4(nxi)) {
21315 +               /* locate last entry */
21316 +               for (; nxa->next; nxa = nxa->next);
21317 +               nxa->next = __alloc_nx_addr_v4();
21318 +               nxa = nxa->next;
21319 +
21320 +               if (IS_ERR(nxa))
21321 +                       return PTR_ERR(nxa);
21322 +       }
21323 +
21324 +       if (nxi->v4.next)
21325 +               /* remove single ip for ip list */
21326 +               nxi->nx_flags &= ~NXF_SINGLE_IP;
21327 +
21328 +       nxa->ip[0].s_addr = ip;
21329 +       nxa->ip[1].s_addr = ip2;
21330 +       nxa->mask.s_addr = mask;
21331 +       nxa->type = type;
21332 +       nxa->flags = flags;
21333 +       return 0;
21334 +}
21335 +
21336 +int do_remove_v4_addr(struct nx_info *nxi, __be32 ip, __be32 ip2, __be32 mask,
21337 +       uint16_t type, uint16_t flags)
21338 +{
21339 +       struct nx_addr_v4 *nxa = &nxi->v4;
21340 +
21341 +       switch (type) {
21342 +/*     case NXA_TYPE_ADDR:
21343 +               break;          */
21344 +
21345 +       case NXA_TYPE_ANY:
21346 +               __dealloc_nx_addr_v4_all(xchg(&nxa->next, NULL));
21347 +               memset(nxa, 0, sizeof(*nxa));
21348 +               break;
21349 +
21350 +       default:
21351 +               return -EINVAL;
21352 +       }
21353 +       return 0;
21354 +}
21355 +
21356 +
21357 +int vc_net_add(struct nx_info *nxi, void __user *data)
21358 +{
21359 +       struct vcmd_net_addr_v0 vc_data;
21360 +       int index, ret = 0;
21361 +
21362 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
21363 +               return -EFAULT;
21364 +
21365 +       switch (vc_data.type) {
21366 +       case NXA_TYPE_IPV4:
21367 +               if ((vc_data.count < 1) || (vc_data.count > 4))
21368 +                       return -EINVAL;
21369 +
21370 +               index = 0;
21371 +               while (index < vc_data.count) {
21372 +                       ret = do_add_v4_addr(nxi, vc_data.ip[index].s_addr, 0,
21373 +                               vc_data.mask[index].s_addr, NXA_TYPE_ADDR, 0);
21374 +                       if (ret)
21375 +                               return ret;
21376 +                       index++;
21377 +               }
21378 +               ret = index;
21379 +               break;
21380 +
21381 +       case NXA_TYPE_IPV4|NXA_MOD_BCAST:
21382 +               nxi->v4_bcast = vc_data.ip[0];
21383 +               ret = 1;
21384 +               break;
21385 +
21386 +       case NXA_TYPE_IPV4|NXA_MOD_LBACK:
21387 +               nxi->v4_lback = vc_data.ip[0];
21388 +               ret = 1;
21389 +               break;
21390 +
21391 +       default:
21392 +               ret = -EINVAL;
21393 +               break;
21394 +       }
21395 +       return ret;
21396 +}
21397 +
21398 +int vc_net_remove(struct nx_info *nxi, void __user *data)
21399 +{
21400 +       struct vcmd_net_addr_v0 vc_data;
21401 +
21402 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
21403 +               return -EFAULT;
21404 +
21405 +       switch (vc_data.type) {
21406 +       case NXA_TYPE_ANY:
21407 +               __dealloc_nx_addr_v4_all(xchg(&nxi->v4.next, NULL));
21408 +               memset(&nxi->v4, 0, sizeof(nxi->v4));
21409 +               break;
21410 +
21411 +       default:
21412 +               return -EINVAL;
21413 +       }
21414 +       return 0;
21415 +}
21416 +
21417 +
21418 +int vc_net_add_ipv4_v1(struct nx_info *nxi, void __user *data)
21419 +{
21420 +       struct vcmd_net_addr_ipv4_v1 vc_data;
21421 +
21422 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
21423 +               return -EFAULT;
21424 +
21425 +       switch (vc_data.type) {
21426 +       case NXA_TYPE_ADDR:
21427 +               vc_data.mask.s_addr = ~0;
21428 +               /* fallthrough */
21429 +       case NXA_TYPE_MASK:
21430 +               return do_add_v4_addr(nxi, vc_data.ip.s_addr, 0,
21431 +                       vc_data.mask.s_addr, vc_data.type, vc_data.flags);
21432 +
21433 +       case NXA_TYPE_ADDR | NXA_MOD_BCAST:
21434 +               nxi->v4_bcast = vc_data.ip;
21435 +               break;
21436 +
21437 +       case NXA_TYPE_ADDR | NXA_MOD_LBACK:
21438 +               nxi->v4_lback = vc_data.ip;
21439 +               break;
21440 +
21441 +       default:
21442 +               return -EINVAL;
21443 +       }
21444 +       return 0;
21445 +}
21446 +
21447 +int vc_net_add_ipv4(struct nx_info *nxi, void __user *data)
21448 +{
21449 +       struct vcmd_net_addr_ipv4_v2 vc_data;
21450 +
21451 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
21452 +               return -EFAULT;
21453 +
21454 +       switch (vc_data.type) {
21455 +       case NXA_TYPE_ADDR:
21456 +       case NXA_TYPE_MASK:
21457 +       case NXA_TYPE_RANGE:
21458 +               return do_add_v4_addr(nxi, vc_data.ip.s_addr, vc_data.ip2.s_addr,
21459 +                       vc_data.mask.s_addr, vc_data.type, vc_data.flags);
21460 +
21461 +       case NXA_TYPE_ADDR | NXA_MOD_BCAST:
21462 +               nxi->v4_bcast = vc_data.ip;
21463 +               break;
21464 +
21465 +       case NXA_TYPE_ADDR | NXA_MOD_LBACK:
21466 +               nxi->v4_lback = vc_data.ip;
21467 +               break;
21468 +
21469 +       default:
21470 +               return -EINVAL;
21471 +       }
21472 +       return 0;
21473 +}
21474 +
21475 +int vc_net_rem_ipv4_v1(struct nx_info *nxi, void __user *data)
21476 +{
21477 +       struct vcmd_net_addr_ipv4_v1 vc_data;
21478 +
21479 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
21480 +               return -EFAULT;
21481 +
21482 +       return do_remove_v4_addr(nxi, vc_data.ip.s_addr, 0,
21483 +               vc_data.mask.s_addr, vc_data.type, vc_data.flags);
21484 +}
21485 +
21486 +int vc_net_rem_ipv4(struct nx_info *nxi, void __user *data)
21487 +{
21488 +       struct vcmd_net_addr_ipv4_v2 vc_data;
21489 +
21490 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
21491 +               return -EFAULT;
21492 +
21493 +       return do_remove_v4_addr(nxi, vc_data.ip.s_addr, vc_data.ip2.s_addr,
21494 +               vc_data.mask.s_addr, vc_data.type, vc_data.flags);
21495 +}
21496 +
21497 +#ifdef CONFIG_IPV6
21498 +
21499 +int do_add_v6_addr(struct nx_info *nxi,
21500 +       struct in6_addr *ip, struct in6_addr *mask,
21501 +       uint32_t prefix, uint16_t type, uint16_t flags)
21502 +{
21503 +       struct nx_addr_v6 *nxa = &nxi->v6;
21504 +
21505 +       if (NX_IPV6(nxi)) {
21506 +               /* locate last entry */
21507 +               for (; nxa->next; nxa = nxa->next);
21508 +               nxa->next = __alloc_nx_addr_v6();
21509 +               nxa = nxa->next;
21510 +
21511 +               if (IS_ERR(nxa))
21512 +                       return PTR_ERR(nxa);
21513 +       }
21514 +
21515 +       nxa->ip = *ip;
21516 +       nxa->mask = *mask;
21517 +       nxa->prefix = prefix;
21518 +       nxa->type = type;
21519 +       nxa->flags = flags;
21520 +       return 0;
21521 +}
21522 +
21523 +
21524 +int vc_net_add_ipv6(struct nx_info *nxi, void __user *data)
21525 +{
21526 +       struct vcmd_net_addr_ipv6_v1 vc_data;
21527 +
21528 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
21529 +               return -EFAULT;
21530 +
21531 +       switch (vc_data.type) {
21532 +       case NXA_TYPE_ADDR:
21533 +               memset(&vc_data.mask, ~0, sizeof(vc_data.mask));
21534 +               /* fallthrough */
21535 +       case NXA_TYPE_MASK:
21536 +               return do_add_v6_addr(nxi, &vc_data.ip, &vc_data.mask,
21537 +                       vc_data.prefix, vc_data.type, vc_data.flags);
21538 +       default:
21539 +               return -EINVAL;
21540 +       }
21541 +       return 0;
21542 +}
21543 +
21544 +int vc_net_remove_ipv6(struct nx_info *nxi, void __user *data)
21545 +{
21546 +       struct vcmd_net_addr_ipv6_v1 vc_data;
21547 +
21548 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
21549 +               return -EFAULT;
21550 +
21551 +       switch (vc_data.type) {
21552 +       case NXA_TYPE_ANY:
21553 +               __dealloc_nx_addr_v6_all(xchg(&nxi->v6.next, NULL));
21554 +               memset(&nxi->v6, 0, sizeof(nxi->v6));
21555 +               break;
21556 +
21557 +       default:
21558 +               return -EINVAL;
21559 +       }
21560 +       return 0;
21561 +}
21562 +
21563 +#endif /* CONFIG_IPV6 */
21564 +
21565 +
21566 +int vc_get_nflags(struct nx_info *nxi, void __user *data)
21567 +{
21568 +       struct vcmd_net_flags_v0 vc_data;
21569 +
21570 +       vc_data.flagword = nxi->nx_flags;
21571 +
21572 +       /* special STATE flag handling */
21573 +       vc_data.mask = vs_mask_flags(~0ULL, nxi->nx_flags, NXF_ONE_TIME);
21574 +
21575 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21576 +               return -EFAULT;
21577 +       return 0;
21578 +}
21579 +
21580 +int vc_set_nflags(struct nx_info *nxi, void __user *data)
21581 +{
21582 +       struct vcmd_net_flags_v0 vc_data;
21583 +       uint64_t mask, trigger;
21584 +
21585 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21586 +               return -EFAULT;
21587 +
21588 +       /* special STATE flag handling */
21589 +       mask = vs_mask_mask(vc_data.mask, nxi->nx_flags, NXF_ONE_TIME);
21590 +       trigger = (mask & nxi->nx_flags) ^ (mask & vc_data.flagword);
21591 +
21592 +       nxi->nx_flags = vs_mask_flags(nxi->nx_flags,
21593 +               vc_data.flagword, mask);
21594 +       if (trigger & NXF_PERSISTENT)
21595 +               nx_update_persistent(nxi);
21596 +
21597 +       return 0;
21598 +}
21599 +
21600 +int vc_get_ncaps(struct nx_info *nxi, void __user *data)
21601 +{
21602 +       struct vcmd_net_caps_v0 vc_data;
21603 +
21604 +       vc_data.ncaps = nxi->nx_ncaps;
21605 +       vc_data.cmask = ~0ULL;
21606 +
21607 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21608 +               return -EFAULT;
21609 +       return 0;
21610 +}
21611 +
21612 +int vc_set_ncaps(struct nx_info *nxi, void __user *data)
21613 +{
21614 +       struct vcmd_net_caps_v0 vc_data;
21615 +
21616 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21617 +               return -EFAULT;
21618 +
21619 +       nxi->nx_ncaps = vs_mask_flags(nxi->nx_ncaps,
21620 +               vc_data.ncaps, vc_data.cmask);
21621 +       return 0;
21622 +}
21623 +
21624 +
21625 +#include <linux/module.h>
21626 +
21627 +module_init(init_network);
21628 +
21629 +EXPORT_SYMBOL_GPL(free_nx_info);
21630 +EXPORT_SYMBOL_GPL(unhash_nx_info);
21631 +
21632 diff -NurpP --minimal linux-2.6.38.3/kernel/vserver/proc.c linux-2.6.38.3-vs2.3.0.37-rc14/kernel/vserver/proc.c
21633 --- linux-2.6.38.3/kernel/vserver/proc.c        1970-01-01 01:00:00.000000000 +0100
21634 +++ linux-2.6.38.3-vs2.3.0.37-rc14/kernel/vserver/proc.c        2011-01-29 02:01:07.000000000 +0100
21635 @@ -0,0 +1,1098 @@
21636 +/*
21637 + *  linux/kernel/vserver/proc.c
21638 + *
21639 + *  Virtual Context Support
21640 + *
21641 + *  Copyright (C) 2003-2007  Herbert Pötzl
21642 + *
21643 + *  V0.01  basic structure
21644 + *  V0.02  adaptation vs1.3.0
21645 + *  V0.03  proc permissions
21646 + *  V0.04  locking/generic
21647 + *  V0.05  next generation procfs
21648 + *  V0.06  inode validation
21649 + *  V0.07  generic rewrite vid
21650 + *  V0.08  remove inode type
21651 + *
21652 + */
21653 +
21654 +#include <linux/proc_fs.h>
21655 +#include <linux/fs_struct.h>
21656 +#include <linux/mount.h>
21657 +#include <asm/unistd.h>
21658 +
21659 +#include <linux/vs_context.h>
21660 +#include <linux/vs_network.h>
21661 +#include <linux/vs_cvirt.h>
21662 +
21663 +#include <linux/in.h>
21664 +#include <linux/inetdevice.h>
21665 +#include <linux/vs_inet.h>
21666 +#include <linux/vs_inet6.h>
21667 +
21668 +#include <linux/vserver/global.h>
21669 +
21670 +#include "cvirt_proc.h"
21671 +#include "cacct_proc.h"
21672 +#include "limit_proc.h"
21673 +#include "sched_proc.h"
21674 +#include "vci_config.h"
21675 +
21676 +
21677 +static inline char *print_cap_t(char *buffer, kernel_cap_t *c)
21678 +{
21679 +       unsigned __capi;
21680 +
21681 +       CAP_FOR_EACH_U32(__capi) {
21682 +               buffer += sprintf(buffer, "%08x",
21683 +                       c->cap[(_KERNEL_CAPABILITY_U32S-1) - __capi]);
21684 +       }
21685 +       return buffer;
21686 +}
21687 +
21688 +
21689 +static struct proc_dir_entry *proc_virtual;
21690 +
21691 +static struct proc_dir_entry *proc_virtnet;
21692 +
21693 +
21694 +/* first the actual feeds */
21695 +
21696 +
21697 +static int proc_vci(char *buffer)
21698 +{
21699 +       return sprintf(buffer,
21700 +               "VCIVersion:\t%04x:%04x\n"
21701 +               "VCISyscall:\t%d\n"
21702 +               "VCIKernel:\t%08x\n",
21703 +               VCI_VERSION >> 16,
21704 +               VCI_VERSION & 0xFFFF,
21705 +               __NR_vserver,
21706 +               vci_kernel_config());
21707 +}
21708 +
21709 +static int proc_virtual_info(char *buffer)
21710 +{
21711 +       return proc_vci(buffer);
21712 +}
21713 +
21714 +static int proc_virtual_status(char *buffer)
21715 +{
21716 +       return sprintf(buffer,
21717 +               "#CTotal:\t%d\n"
21718 +               "#CActive:\t%d\n"
21719 +               "#NSProxy:\t%d\t%d %d %d %d %d %d\n"
21720 +               "#InitTask:\t%d\t%d %d\n",
21721 +               atomic_read(&vx_global_ctotal),
21722 +               atomic_read(&vx_global_cactive),
21723 +               atomic_read(&vs_global_nsproxy),
21724 +               atomic_read(&vs_global_fs),
21725 +               atomic_read(&vs_global_mnt_ns),
21726 +               atomic_read(&vs_global_uts_ns),
21727 +               atomic_read(&nr_ipc_ns),
21728 +               atomic_read(&vs_global_user_ns),
21729 +               atomic_read(&vs_global_pid_ns),
21730 +               atomic_read(&init_task.usage),
21731 +               atomic_read(&init_task.nsproxy->count),
21732 +               init_task.fs->users);
21733 +}
21734 +
21735 +
21736 +int proc_vxi_info(struct vx_info *vxi, char *buffer)
21737 +{
21738 +       int length;
21739 +
21740 +       length = sprintf(buffer,
21741 +               "ID:\t%d\n"
21742 +               "Info:\t%p\n"
21743 +               "Init:\t%d\n"
21744 +               "OOM:\t%lld\n",
21745 +               vxi->vx_id,
21746 +               vxi,
21747 +               vxi->vx_initpid,
21748 +               vxi->vx_badness_bias);
21749 +       return length;
21750 +}
21751 +
21752 +int proc_vxi_status(struct vx_info *vxi, char *buffer)
21753 +{
21754 +       char *orig = buffer;
21755 +
21756 +       buffer += sprintf(buffer,
21757 +               "UseCnt:\t%d\n"
21758 +               "Tasks:\t%d\n"
21759 +               "Flags:\t%016llx\n",
21760 +               atomic_read(&vxi->vx_usecnt),
21761 +               atomic_read(&vxi->vx_tasks),
21762 +               (unsigned long long)vxi->vx_flags);
21763 +
21764 +       buffer += sprintf(buffer, "BCaps:\t");
21765 +       buffer = print_cap_t(buffer, &vxi->vx_bcaps);
21766 +       buffer += sprintf(buffer, "\n");
21767 +
21768 +       buffer += sprintf(buffer,
21769 +               "CCaps:\t%016llx\n"
21770 +               "Spaces:\t%08lx %08lx\n",
21771 +               (unsigned long long)vxi->vx_ccaps,
21772 +               vxi->space[0].vx_nsmask, vxi->space[1].vx_nsmask);
21773 +       return buffer - orig;
21774 +}
21775 +
21776 +int proc_vxi_limit(struct vx_info *vxi, char *buffer)
21777 +{
21778 +       return vx_info_proc_limit(&vxi->limit, buffer);
21779 +}
21780 +
21781 +int proc_vxi_sched(struct vx_info *vxi, char *buffer)
21782 +{
21783 +       int cpu, length;
21784 +
21785 +       length = vx_info_proc_sched(&vxi->sched, buffer);
21786 +       for_each_online_cpu(cpu) {
21787 +               length += vx_info_proc_sched_pc(
21788 +                       &vx_per_cpu(vxi, sched_pc, cpu),
21789 +                       buffer + length, cpu);
21790 +       }
21791 +       return length;
21792 +}
21793 +
21794 +int proc_vxi_nsproxy0(struct vx_info *vxi, char *buffer)
21795 +{
21796 +       return vx_info_proc_nsproxy(vxi->space[0].vx_nsproxy, buffer);
21797 +}
21798 +
21799 +int proc_vxi_nsproxy1(struct vx_info *vxi, char *buffer)
21800 +{
21801 +       return vx_info_proc_nsproxy(vxi->space[1].vx_nsproxy, buffer);
21802 +}
21803 +
21804 +int proc_vxi_cvirt(struct vx_info *vxi, char *buffer)
21805 +{
21806 +       int cpu, length;
21807 +
21808 +       vx_update_load(vxi);
21809 +       length = vx_info_proc_cvirt(&vxi->cvirt, buffer);
21810 +       for_each_online_cpu(cpu) {
21811 +               length += vx_info_proc_cvirt_pc(
21812 +                       &vx_per_cpu(vxi, cvirt_pc, cpu),
21813 +                       buffer + length, cpu);
21814 +       }
21815 +       return length;
21816 +}
21817 +
21818 +int proc_vxi_cacct(struct vx_info *vxi, char *buffer)
21819 +{
21820 +       return vx_info_proc_cacct(&vxi->cacct, buffer);
21821 +}
21822 +
21823 +
21824 +static int proc_virtnet_info(char *buffer)
21825 +{
21826 +       return proc_vci(buffer);
21827 +}
21828 +
21829 +static int proc_virtnet_status(char *buffer)
21830 +{
21831 +       return sprintf(buffer,
21832 +               "#CTotal:\t%d\n"
21833 +               "#CActive:\t%d\n",
21834 +               atomic_read(&nx_global_ctotal),
21835 +               atomic_read(&nx_global_cactive));
21836 +}
21837 +
21838 +int proc_nxi_info(struct nx_info *nxi, char *buffer)
21839 +{
21840 +       struct nx_addr_v4 *v4a;
21841 +#ifdef CONFIG_IPV6
21842 +       struct nx_addr_v6 *v6a;
21843 +#endif
21844 +       int length, i;
21845 +
21846 +       length = sprintf(buffer,
21847 +               "ID:\t%d\n"
21848 +               "Info:\t%p\n"
21849 +               "Bcast:\t" NIPQUAD_FMT "\n"
21850 +               "Lback:\t" NIPQUAD_FMT "\n",
21851 +               nxi->nx_id,
21852 +               nxi,
21853 +               NIPQUAD(nxi->v4_bcast.s_addr),
21854 +               NIPQUAD(nxi->v4_lback.s_addr));
21855 +
21856 +       if (!NX_IPV4(nxi))
21857 +               goto skip_v4;
21858 +       for (i = 0, v4a = &nxi->v4; v4a; i++, v4a = v4a->next)
21859 +               length += sprintf(buffer + length, "%d:\t" NXAV4_FMT "\n",
21860 +                       i, NXAV4(v4a));
21861 +skip_v4:
21862 +#ifdef CONFIG_IPV6
21863 +       if (!NX_IPV6(nxi))
21864 +               goto skip_v6;
21865 +       for (i = 0, v6a = &nxi->v6; v6a; i++, v6a = v6a->next)
21866 +               length += sprintf(buffer + length, "%d:\t" NXAV6_FMT "\n",
21867 +                       i, NXAV6(v6a));
21868 +skip_v6:
21869 +#endif
21870 +       return length;
21871 +}
21872 +
21873 +int proc_nxi_status(struct nx_info *nxi, char *buffer)
21874 +{
21875 +       int length;
21876 +
21877 +       length = sprintf(buffer,
21878 +               "UseCnt:\t%d\n"
21879 +               "Tasks:\t%d\n"
21880 +               "Flags:\t%016llx\n"
21881 +               "NCaps:\t%016llx\n",
21882 +               atomic_read(&nxi->nx_usecnt),
21883 +               atomic_read(&nxi->nx_tasks),
21884 +               (unsigned long long)nxi->nx_flags,
21885 +               (unsigned long long)nxi->nx_ncaps);
21886 +       return length;
21887 +}
21888 +
21889 +
21890 +
21891 +/* here the inode helpers */
21892 +
21893 +struct vs_entry {
21894 +       int len;
21895 +       char *name;
21896 +       mode_t mode;
21897 +       struct inode_operations *iop;
21898 +       struct file_operations *fop;
21899 +       union proc_op op;
21900 +};
21901 +
21902 +static struct inode *vs_proc_make_inode(struct super_block *sb, struct vs_entry *p)
21903 +{
21904 +       struct inode *inode = new_inode(sb);
21905 +
21906 +       if (!inode)
21907 +               goto out;
21908 +
21909 +       inode->i_mode = p->mode;
21910 +       if (p->iop)
21911 +               inode->i_op = p->iop;
21912 +       if (p->fop)
21913 +               inode->i_fop = p->fop;
21914 +
21915 +       inode->i_nlink = (p->mode & S_IFDIR) ? 2 : 1;
21916 +       inode->i_flags |= S_IMMUTABLE;
21917 +
21918 +       inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
21919 +
21920 +       inode->i_uid = 0;
21921 +       inode->i_gid = 0;
21922 +       inode->i_tag = 0;
21923 +out:
21924 +       return inode;
21925 +}
21926 +
21927 +static struct dentry *vs_proc_instantiate(struct inode *dir,
21928 +       struct dentry *dentry, int id, void *ptr)
21929 +{
21930 +       struct vs_entry *p = ptr;
21931 +       struct inode *inode = vs_proc_make_inode(dir->i_sb, p);
21932 +       struct dentry *error = ERR_PTR(-EINVAL);
21933 +
21934 +       if (!inode)
21935 +               goto out;
21936 +
21937 +       PROC_I(inode)->op = p->op;
21938 +       PROC_I(inode)->fd = id;
21939 +       d_add(dentry, inode);
21940 +       error = NULL;
21941 +out:
21942 +       return error;
21943 +}
21944 +
21945 +/* Lookups */
21946 +
21947 +typedef struct dentry *instantiate_t(struct inode *, struct dentry *, int, void *);
21948 +
21949 +/*
21950 + * Fill a directory entry.
21951 + *
21952 + * If possible create the dcache entry and derive our inode number and
21953 + * file type from dcache entry.
21954 + *
21955 + * Since all of the proc inode numbers are dynamically generated, the inode
21956 + * numbers do not exist until the inode is cache.  This means creating the
21957 + * the dcache entry in readdir is necessary to keep the inode numbers
21958 + * reported by readdir in sync with the inode numbers reported
21959 + * by stat.
21960 + */
21961 +static int proc_fill_cache(struct file *filp, void *dirent, filldir_t filldir,
21962 +       char *name, int len, instantiate_t instantiate, int id, void *ptr)
21963 +{
21964 +       struct dentry *child, *dir = filp->f_dentry;
21965 +       struct inode *inode;
21966 +       struct qstr qname;
21967 +       ino_t ino = 0;
21968 +       unsigned type = DT_UNKNOWN;
21969 +
21970 +       qname.name = name;
21971 +       qname.len  = len;
21972 +       qname.hash = full_name_hash(name, len);
21973 +
21974 +       child = d_lookup(dir, &qname);
21975 +       if (!child) {
21976 +               struct dentry *new;
21977 +               new = d_alloc(dir, &qname);
21978 +               if (new) {
21979 +                       child = instantiate(dir->d_inode, new, id, ptr);
21980 +                       if (child)
21981 +                               dput(new);
21982 +                       else
21983 +                               child = new;
21984 +               }
21985 +       }
21986 +       if (!child || IS_ERR(child) || !child->d_inode)
21987 +               goto end_instantiate;
21988 +       inode = child->d_inode;
21989 +       if (inode) {
21990 +               ino = inode->i_ino;
21991 +               type = inode->i_mode >> 12;
21992 +       }
21993 +       dput(child);
21994 +end_instantiate:
21995 +       if (!ino)
21996 +               ino = find_inode_number(dir, &qname);
21997 +       if (!ino)
21998 +               ino = 1;
21999 +       return filldir(dirent, name, len, filp->f_pos, ino, type);
22000 +}
22001 +
22002 +
22003 +
22004 +/* get and revalidate vx_info/xid */
22005 +
22006 +static inline
22007 +struct vx_info *get_proc_vx_info(struct inode *inode)
22008 +{
22009 +       return lookup_vx_info(PROC_I(inode)->fd);
22010 +}
22011 +
22012 +static int proc_xid_revalidate(struct dentry *dentry, struct nameidata *nd)
22013 +{
22014 +       struct inode *inode = dentry->d_inode;
22015 +       xid_t xid = PROC_I(inode)->fd;
22016 +
22017 +       if (!xid || xid_is_hashed(xid))
22018 +               return 1;
22019 +       d_drop(dentry);
22020 +       return 0;
22021 +}
22022 +
22023 +
22024 +/* get and revalidate nx_info/nid */
22025 +
22026 +static int proc_nid_revalidate(struct dentry *dentry, struct nameidata *nd)
22027 +{
22028 +       struct inode *inode = dentry->d_inode;
22029 +       nid_t nid = PROC_I(inode)->fd;
22030 +
22031 +       if (!nid || nid_is_hashed(nid))
22032 +               return 1;
22033 +       d_drop(dentry);
22034 +       return 0;
22035 +}
22036 +
22037 +
22038 +
22039 +#define PROC_BLOCK_SIZE (PAGE_SIZE - 1024)
22040 +
22041 +static ssize_t proc_vs_info_read(struct file *file, char __user *buf,
22042 +                         size_t count, loff_t *ppos)
22043 +{
22044 +       struct inode *inode = file->f_dentry->d_inode;
22045 +       unsigned long page;
22046 +       ssize_t length = 0;
22047 +
22048 +       if (count > PROC_BLOCK_SIZE)
22049 +               count = PROC_BLOCK_SIZE;
22050 +
22051 +       /* fade that out as soon as stable */
22052 +       WARN_ON(PROC_I(inode)->fd);
22053 +
22054 +       if (!(page = __get_free_page(GFP_KERNEL)))
22055 +               return -ENOMEM;
22056 +
22057 +       BUG_ON(!PROC_I(inode)->op.proc_vs_read);
22058 +       length = PROC_I(inode)->op.proc_vs_read((char *)page);
22059 +
22060 +       if (length >= 0)
22061 +               length = simple_read_from_buffer(buf, count, ppos,
22062 +                       (char *)page, length);
22063 +
22064 +       free_page(page);
22065 +       return length;
22066 +}
22067 +
22068 +static ssize_t proc_vx_info_read(struct file *file, char __user *buf,
22069 +                         size_t count, loff_t *ppos)
22070 +{
22071 +       struct inode *inode = file->f_dentry->d_inode;
22072 +       struct vx_info *vxi = NULL;
22073 +       xid_t xid = PROC_I(inode)->fd;
22074 +       unsigned long page;
22075 +       ssize_t length = 0;
22076 +
22077 +       if (count > PROC_BLOCK_SIZE)
22078 +               count = PROC_BLOCK_SIZE;
22079 +
22080 +       /* fade that out as soon as stable */
22081 +       WARN_ON(!xid);
22082 +       vxi = lookup_vx_info(xid);
22083 +       if (!vxi)
22084 +               goto out;
22085 +
22086 +       length = -ENOMEM;
22087 +       if (!(page = __get_free_page(GFP_KERNEL)))
22088 +               goto out_put;
22089 +
22090 +       BUG_ON(!PROC_I(inode)->op.proc_vxi_read);
22091 +       length = PROC_I(inode)->op.proc_vxi_read(vxi, (char *)page);
22092 +
22093 +       if (length >= 0)
22094 +               length = simple_read_from_buffer(buf, count, ppos,
22095 +                       (char *)page, length);
22096 +
22097 +       free_page(page);
22098 +out_put:
22099 +       put_vx_info(vxi);
22100 +out:
22101 +       return length;
22102 +}
22103 +
22104 +static ssize_t proc_nx_info_read(struct file *file, char __user *buf,
22105 +                         size_t count, loff_t *ppos)
22106 +{
22107 +       struct inode *inode = file->f_dentry->d_inode;
22108 +       struct nx_info *nxi = NULL;
22109 +       nid_t nid = PROC_I(inode)->fd;
22110 +       unsigned long page;
22111 +       ssize_t length = 0;
22112 +
22113 +       if (count > PROC_BLOCK_SIZE)
22114 +               count = PROC_BLOCK_SIZE;
22115 +
22116 +       /* fade that out as soon as stable */
22117 +       WARN_ON(!nid);
22118 +       nxi = lookup_nx_info(nid);
22119 +       if (!nxi)
22120 +               goto out;
22121 +
22122 +       length = -ENOMEM;
22123 +       if (!(page = __get_free_page(GFP_KERNEL)))
22124 +               goto out_put;
22125 +
22126 +       BUG_ON(!PROC_I(inode)->op.proc_nxi_read);
22127 +       length = PROC_I(inode)->op.proc_nxi_read(nxi, (char *)page);
22128 +
22129 +       if (length >= 0)
22130 +               length = simple_read_from_buffer(buf, count, ppos,
22131 +                       (char *)page, length);
22132 +
22133 +       free_page(page);
22134 +out_put:
22135 +       put_nx_info(nxi);
22136 +out:
22137 +       return length;
22138 +}
22139 +
22140 +
22141 +
22142 +/* here comes the lower level */
22143 +
22144 +
22145 +#define NOD(NAME, MODE, IOP, FOP, OP) {        \
22146 +       .len  = sizeof(NAME) - 1,       \
22147 +       .name = (NAME),                 \
22148 +       .mode = MODE,                   \
22149 +       .iop  = IOP,                    \
22150 +       .fop  = FOP,                    \
22151 +       .op   = OP,                     \
22152 +}
22153 +
22154 +
22155 +#define DIR(NAME, MODE, OTYPE)                         \
22156 +       NOD(NAME, (S_IFDIR | (MODE)),                   \
22157 +               &proc_ ## OTYPE ## _inode_operations,   \
22158 +               &proc_ ## OTYPE ## _file_operations, { } )
22159 +
22160 +#define INF(NAME, MODE, OTYPE)                         \
22161 +       NOD(NAME, (S_IFREG | (MODE)), NULL,             \
22162 +               &proc_vs_info_file_operations,          \
22163 +               { .proc_vs_read = &proc_##OTYPE } )
22164 +
22165 +#define VINF(NAME, MODE, OTYPE)                                \
22166 +       NOD(NAME, (S_IFREG | (MODE)), NULL,             \
22167 +               &proc_vx_info_file_operations,          \
22168 +               { .proc_vxi_read = &proc_##OTYPE } )
22169 +
22170 +#define NINF(NAME, MODE, OTYPE)                                \
22171 +       NOD(NAME, (S_IFREG | (MODE)), NULL,             \
22172 +               &proc_nx_info_file_operations,          \
22173 +               { .proc_nxi_read = &proc_##OTYPE } )
22174 +
22175 +
22176 +static struct file_operations proc_vs_info_file_operations = {
22177 +       .read =         proc_vs_info_read,
22178 +};
22179 +
22180 +static struct file_operations proc_vx_info_file_operations = {
22181 +       .read =         proc_vx_info_read,
22182 +};
22183 +
22184 +static struct dentry_operations proc_xid_dentry_operations = {
22185 +       .d_revalidate = proc_xid_revalidate,
22186 +};
22187 +
22188 +static struct vs_entry vx_base_stuff[] = {
22189 +       VINF("info",    S_IRUGO, vxi_info),
22190 +       VINF("status",  S_IRUGO, vxi_status),
22191 +       VINF("limit",   S_IRUGO, vxi_limit),
22192 +       VINF("sched",   S_IRUGO, vxi_sched),
22193 +       VINF("nsproxy", S_IRUGO, vxi_nsproxy0),
22194 +       VINF("nsproxy1",S_IRUGO, vxi_nsproxy1),
22195 +       VINF("cvirt",   S_IRUGO, vxi_cvirt),
22196 +       VINF("cacct",   S_IRUGO, vxi_cacct),
22197 +       {}
22198 +};
22199 +
22200 +
22201 +
22202 +
22203 +static struct dentry *proc_xid_instantiate(struct inode *dir,
22204 +       struct dentry *dentry, int id, void *ptr)
22205 +{
22206 +       dentry->d_op = &proc_xid_dentry_operations;
22207 +       return vs_proc_instantiate(dir, dentry, id, ptr);
22208 +}
22209 +
22210 +static struct dentry *proc_xid_lookup(struct inode *dir,
22211 +       struct dentry *dentry, struct nameidata *nd)
22212 +{
22213 +       struct vs_entry *p = vx_base_stuff;
22214 +       struct dentry *error = ERR_PTR(-ENOENT);
22215 +
22216 +       for (; p->name; p++) {
22217 +               if (p->len != dentry->d_name.len)
22218 +                       continue;
22219 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
22220 +                       break;
22221 +       }
22222 +       if (!p->name)
22223 +               goto out;
22224 +
22225 +       error = proc_xid_instantiate(dir, dentry, PROC_I(dir)->fd, p);
22226 +out:
22227 +       return error;
22228 +}
22229 +
22230 +static int proc_xid_readdir(struct file *filp,
22231 +       void *dirent, filldir_t filldir)
22232 +{
22233 +       struct dentry *dentry = filp->f_dentry;
22234 +       struct inode *inode = dentry->d_inode;
22235 +       struct vs_entry *p = vx_base_stuff;
22236 +       int size = sizeof(vx_base_stuff) / sizeof(struct vs_entry);
22237 +       int pos, index;
22238 +       u64 ino;
22239 +
22240 +       pos = filp->f_pos;
22241 +       switch (pos) {
22242 +       case 0:
22243 +               ino = inode->i_ino;
22244 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
22245 +                       goto out;
22246 +               pos++;
22247 +               /* fall through */
22248 +       case 1:
22249 +               ino = parent_ino(dentry);
22250 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
22251 +                       goto out;
22252 +               pos++;
22253 +               /* fall through */
22254 +       default:
22255 +               index = pos - 2;
22256 +               if (index >= size)
22257 +                       goto out;
22258 +               for (p += index; p->name; p++) {
22259 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
22260 +                               vs_proc_instantiate, PROC_I(inode)->fd, p))
22261 +                               goto out;
22262 +                       pos++;
22263 +               }
22264 +       }
22265 +out:
22266 +       filp->f_pos = pos;
22267 +       return 1;
22268 +}
22269 +
22270 +
22271 +
22272 +static struct file_operations proc_nx_info_file_operations = {
22273 +       .read =         proc_nx_info_read,
22274 +};
22275 +
22276 +static struct dentry_operations proc_nid_dentry_operations = {
22277 +       .d_revalidate = proc_nid_revalidate,
22278 +};
22279 +
22280 +static struct vs_entry nx_base_stuff[] = {
22281 +       NINF("info",    S_IRUGO, nxi_info),
22282 +       NINF("status",  S_IRUGO, nxi_status),
22283 +       {}
22284 +};
22285 +
22286 +
22287 +static struct dentry *proc_nid_instantiate(struct inode *dir,
22288 +       struct dentry *dentry, int id, void *ptr)
22289 +{
22290 +       dentry->d_op = &proc_nid_dentry_operations;
22291 +       return vs_proc_instantiate(dir, dentry, id, ptr);
22292 +}
22293 +
22294 +static struct dentry *proc_nid_lookup(struct inode *dir,
22295 +       struct dentry *dentry, struct nameidata *nd)
22296 +{
22297 +       struct vs_entry *p = nx_base_stuff;
22298 +       struct dentry *error = ERR_PTR(-ENOENT);
22299 +
22300 +       for (; p->name; p++) {
22301 +               if (p->len != dentry->d_name.len)
22302 +                       continue;
22303 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
22304 +                       break;
22305 +       }
22306 +       if (!p->name)
22307 +               goto out;
22308 +
22309 +       error = proc_nid_instantiate(dir, dentry, PROC_I(dir)->fd, p);
22310 +out:
22311 +       return error;
22312 +}
22313 +
22314 +static int proc_nid_readdir(struct file *filp,
22315 +       void *dirent, filldir_t filldir)
22316 +{
22317 +       struct dentry *dentry = filp->f_dentry;
22318 +       struct inode *inode = dentry->d_inode;
22319 +       struct vs_entry *p = nx_base_stuff;
22320 +       int size = sizeof(nx_base_stuff) / sizeof(struct vs_entry);
22321 +       int pos, index;
22322 +       u64 ino;
22323 +
22324 +       pos = filp->f_pos;
22325 +       switch (pos) {
22326 +       case 0:
22327 +               ino = inode->i_ino;
22328 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
22329 +                       goto out;
22330 +               pos++;
22331 +               /* fall through */
22332 +       case 1:
22333 +               ino = parent_ino(dentry);
22334 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
22335 +                       goto out;
22336 +               pos++;
22337 +               /* fall through */
22338 +       default:
22339 +               index = pos - 2;
22340 +               if (index >= size)
22341 +                       goto out;
22342 +               for (p += index; p->name; p++) {
22343 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
22344 +                               vs_proc_instantiate, PROC_I(inode)->fd, p))
22345 +                               goto out;
22346 +                       pos++;
22347 +               }
22348 +       }
22349 +out:
22350 +       filp->f_pos = pos;
22351 +       return 1;
22352 +}
22353 +
22354 +
22355 +#define MAX_MULBY10    ((~0U - 9) / 10)
22356 +
22357 +static inline int atovid(const char *str, int len)
22358 +{
22359 +       int vid, c;
22360 +
22361 +       vid = 0;
22362 +       while (len-- > 0) {
22363 +               c = *str - '0';
22364 +               str++;
22365 +               if (c > 9)
22366 +                       return -1;
22367 +               if (vid >= MAX_MULBY10)
22368 +                       return -1;
22369 +               vid *= 10;
22370 +               vid += c;
22371 +               if (!vid)
22372 +                       return -1;
22373 +       }
22374 +       return vid;
22375 +}
22376 +
22377 +/* now the upper level (virtual) */
22378 +
22379 +
22380 +static struct file_operations proc_xid_file_operations = {
22381 +       .read =         generic_read_dir,
22382 +       .readdir =      proc_xid_readdir,
22383 +};
22384 +
22385 +static struct inode_operations proc_xid_inode_operations = {
22386 +       .lookup =       proc_xid_lookup,
22387 +};
22388 +
22389 +static struct vs_entry vx_virtual_stuff[] = {
22390 +       INF("info",     S_IRUGO, virtual_info),
22391 +       INF("status",   S_IRUGO, virtual_status),
22392 +       DIR(NULL,       S_IRUGO | S_IXUGO, xid),
22393 +};
22394 +
22395 +
22396 +static struct dentry *proc_virtual_lookup(struct inode *dir,
22397 +       struct dentry *dentry, struct nameidata *nd)
22398 +{
22399 +       struct vs_entry *p = vx_virtual_stuff;
22400 +       struct dentry *error = ERR_PTR(-ENOENT);
22401 +       int id = 0;
22402 +
22403 +       for (; p->name; p++) {
22404 +               if (p->len != dentry->d_name.len)
22405 +                       continue;
22406 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
22407 +                       break;
22408 +       }
22409 +       if (p->name)
22410 +               goto instantiate;
22411 +
22412 +       id = atovid(dentry->d_name.name, dentry->d_name.len);
22413 +       if ((id < 0) || !xid_is_hashed(id))
22414 +               goto out;
22415 +
22416 +instantiate:
22417 +       error = proc_xid_instantiate(dir, dentry, id, p);
22418 +out:
22419 +       return error;
22420 +}
22421 +
22422 +static struct file_operations proc_nid_file_operations = {
22423 +       .read =         generic_read_dir,
22424 +       .readdir =      proc_nid_readdir,
22425 +};
22426 +
22427 +static struct inode_operations proc_nid_inode_operations = {
22428 +       .lookup =       proc_nid_lookup,
22429 +};
22430 +
22431 +static struct vs_entry nx_virtnet_stuff[] = {
22432 +       INF("info",     S_IRUGO, virtnet_info),
22433 +       INF("status",   S_IRUGO, virtnet_status),
22434 +       DIR(NULL,       S_IRUGO | S_IXUGO, nid),
22435 +};
22436 +
22437 +
22438 +static struct dentry *proc_virtnet_lookup(struct inode *dir,
22439 +       struct dentry *dentry, struct nameidata *nd)
22440 +{
22441 +       struct vs_entry *p = nx_virtnet_stuff;
22442 +       struct dentry *error = ERR_PTR(-ENOENT);
22443 +       int id = 0;
22444 +
22445 +       for (; p->name; p++) {
22446 +               if (p->len != dentry->d_name.len)
22447 +                       continue;
22448 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
22449 +                       break;
22450 +       }
22451 +       if (p->name)
22452 +               goto instantiate;
22453 +
22454 +       id = atovid(dentry->d_name.name, dentry->d_name.len);
22455 +       if ((id < 0) || !nid_is_hashed(id))
22456 +               goto out;
22457 +
22458 +instantiate:
22459 +       error = proc_nid_instantiate(dir, dentry, id, p);
22460 +out:
22461 +       return error;
22462 +}
22463 +
22464 +
22465 +#define PROC_MAXVIDS 32
22466 +
22467 +int proc_virtual_readdir(struct file *filp,
22468 +       void *dirent, filldir_t filldir)
22469 +{
22470 +       struct dentry *dentry = filp->f_dentry;
22471 +       struct inode *inode = dentry->d_inode;
22472 +       struct vs_entry *p = vx_virtual_stuff;
22473 +       int size = sizeof(vx_virtual_stuff) / sizeof(struct vs_entry);
22474 +       int pos, index;
22475 +       unsigned int xid_array[PROC_MAXVIDS];
22476 +       char buf[PROC_NUMBUF];
22477 +       unsigned int nr_xids, i;
22478 +       u64 ino;
22479 +
22480 +       pos = filp->f_pos;
22481 +       switch (pos) {
22482 +       case 0:
22483 +               ino = inode->i_ino;
22484 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
22485 +                       goto out;
22486 +               pos++;
22487 +               /* fall through */
22488 +       case 1:
22489 +               ino = parent_ino(dentry);
22490 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
22491 +                       goto out;
22492 +               pos++;
22493 +               /* fall through */
22494 +       default:
22495 +               index = pos - 2;
22496 +               if (index >= size)
22497 +                       goto entries;
22498 +               for (p += index; p->name; p++) {
22499 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
22500 +                               vs_proc_instantiate, 0, p))
22501 +                               goto out;
22502 +                       pos++;
22503 +               }
22504 +       entries:
22505 +               index = pos - size;
22506 +               p = &vx_virtual_stuff[size - 1];
22507 +               nr_xids = get_xid_list(index, xid_array, PROC_MAXVIDS);
22508 +               for (i = 0; i < nr_xids; i++) {
22509 +                       int n, xid = xid_array[i];
22510 +                       unsigned int j = PROC_NUMBUF;
22511 +
22512 +                       n = xid;
22513 +                       do
22514 +                               buf[--j] = '0' + (n % 10);
22515 +                       while (n /= 10);
22516 +
22517 +                       if (proc_fill_cache(filp, dirent, filldir,
22518 +                               buf + j, PROC_NUMBUF - j,
22519 +                               vs_proc_instantiate, xid, p))
22520 +                               goto out;
22521 +                       pos++;
22522 +               }
22523 +       }
22524 +out:
22525 +       filp->f_pos = pos;
22526 +       return 0;
22527 +}
22528 +
22529 +static int proc_virtual_getattr(struct vfsmount *mnt,
22530 +       struct dentry *dentry, struct kstat *stat)
22531 +{
22532 +       struct inode *inode = dentry->d_inode;
22533 +
22534 +       generic_fillattr(inode, stat);
22535 +       stat->nlink = 2 + atomic_read(&vx_global_cactive);
22536 +       return 0;
22537 +}
22538 +
22539 +static struct file_operations proc_virtual_dir_operations = {
22540 +       .read =         generic_read_dir,
22541 +       .readdir =      proc_virtual_readdir,
22542 +};
22543 +
22544 +static struct inode_operations proc_virtual_dir_inode_operations = {
22545 +       .getattr =      proc_virtual_getattr,
22546 +       .lookup =       proc_virtual_lookup,
22547 +};
22548 +
22549 +
22550 +
22551 +
22552 +
22553 +int proc_virtnet_readdir(struct file *filp,
22554 +       void *dirent, filldir_t filldir)
22555 +{
22556 +       struct dentry *dentry = filp->f_dentry;
22557 +       struct inode *inode = dentry->d_inode;
22558 +       struct vs_entry *p = nx_virtnet_stuff;
22559 +       int size = sizeof(nx_virtnet_stuff) / sizeof(struct vs_entry);
22560 +       int pos, index;
22561 +       unsigned int nid_array[PROC_MAXVIDS];
22562 +       char buf[PROC_NUMBUF];
22563 +       unsigned int nr_nids, i;
22564 +       u64 ino;
22565 +
22566 +       pos = filp->f_pos;
22567 +       switch (pos) {
22568 +       case 0:
22569 +               ino = inode->i_ino;
22570 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
22571 +                       goto out;
22572 +               pos++;
22573 +               /* fall through */
22574 +       case 1:
22575 +               ino = parent_ino(dentry);
22576 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
22577 +                       goto out;
22578 +               pos++;
22579 +               /* fall through */
22580 +       default:
22581 +               index = pos - 2;
22582 +               if (index >= size)
22583 +                       goto entries;
22584 +               for (p += index; p->name; p++) {
22585 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
22586 +                               vs_proc_instantiate, 0, p))
22587 +                               goto out;
22588 +                       pos++;
22589 +               }
22590 +       entries:
22591 +               index = pos - size;
22592 +               p = &nx_virtnet_stuff[size - 1];
22593 +               nr_nids = get_nid_list(index, nid_array, PROC_MAXVIDS);
22594 +               for (i = 0; i < nr_nids; i++) {
22595 +                       int n, nid = nid_array[i];
22596 +                       unsigned int j = PROC_NUMBUF;
22597 +
22598 +                       n = nid;
22599 +                       do
22600 +                               buf[--j] = '0' + (n % 10);
22601 +                       while (n /= 10);
22602 +
22603 +                       if (proc_fill_cache(filp, dirent, filldir,
22604 +                               buf + j, PROC_NUMBUF - j,
22605 +                               vs_proc_instantiate, nid, p))
22606 +                               goto out;
22607 +                       pos++;
22608 +               }
22609 +       }
22610 +out:
22611 +       filp->f_pos = pos;
22612 +       return 0;
22613 +}
22614 +
22615 +static int proc_virtnet_getattr(struct vfsmount *mnt,
22616 +       struct dentry *dentry, struct kstat *stat)
22617 +{
22618 +       struct inode *inode = dentry->d_inode;
22619 +
22620 +       generic_fillattr(inode, stat);
22621 +       stat->nlink = 2 + atomic_read(&nx_global_cactive);
22622 +       return 0;
22623 +}
22624 +
22625 +static struct file_operations proc_virtnet_dir_operations = {
22626 +       .read =         generic_read_dir,
22627 +       .readdir =      proc_virtnet_readdir,
22628 +};
22629 +
22630 +static struct inode_operations proc_virtnet_dir_inode_operations = {
22631 +       .getattr =      proc_virtnet_getattr,
22632 +       .lookup =       proc_virtnet_lookup,
22633 +};
22634 +
22635 +
22636 +
22637 +void proc_vx_init(void)
22638 +{
22639 +       struct proc_dir_entry *ent;
22640 +
22641 +       ent = proc_mkdir("virtual", 0);
22642 +       if (ent) {
22643 +               ent->proc_fops = &proc_virtual_dir_operations;
22644 +               ent->proc_iops = &proc_virtual_dir_inode_operations;
22645 +       }
22646 +       proc_virtual = ent;
22647 +
22648 +       ent = proc_mkdir("virtnet", 0);
22649 +       if (ent) {
22650 +               ent->proc_fops = &proc_virtnet_dir_operations;
22651 +               ent->proc_iops = &proc_virtnet_dir_inode_operations;
22652 +       }
22653 +       proc_virtnet = ent;
22654 +}
22655 +
22656 +
22657 +
22658 +
22659 +/* per pid info */
22660 +
22661 +
22662 +int proc_pid_vx_info(struct task_struct *p, char *buffer)
22663 +{
22664 +       struct vx_info *vxi;
22665 +       char *orig = buffer;
22666 +
22667 +       buffer += sprintf(buffer, "XID:\t%d\n", vx_task_xid(p));
22668 +
22669 +       vxi = task_get_vx_info(p);
22670 +       if (!vxi)
22671 +               goto out;
22672 +
22673 +       buffer += sprintf(buffer, "BCaps:\t");
22674 +       buffer = print_cap_t(buffer, &vxi->vx_bcaps);
22675 +       buffer += sprintf(buffer, "\n");
22676 +       buffer += sprintf(buffer, "CCaps:\t%016llx\n",
22677 +               (unsigned long long)vxi->vx_ccaps);
22678 +       buffer += sprintf(buffer, "CFlags:\t%016llx\n",
22679 +               (unsigned long long)vxi->vx_flags);
22680 +       buffer += sprintf(buffer, "CIPid:\t%d\n", vxi->vx_initpid);
22681 +
22682 +       put_vx_info(vxi);
22683 +out:
22684 +       return buffer - orig;
22685 +}
22686 +
22687 +
22688 +int proc_pid_nx_info(struct task_struct *p, char *buffer)
22689 +{
22690 +       struct nx_info *nxi;
22691 +       struct nx_addr_v4 *v4a;
22692 +#ifdef CONFIG_IPV6
22693 +       struct nx_addr_v6 *v6a;
22694 +#endif
22695 +       char *orig = buffer;
22696 +       int i;
22697 +
22698 +       buffer += sprintf(buffer, "NID:\t%d\n", nx_task_nid(p));
22699 +
22700 +       nxi = task_get_nx_info(p);
22701 +       if (!nxi)
22702 +               goto out;
22703 +
22704 +       buffer += sprintf(buffer, "NCaps:\t%016llx\n",
22705 +               (unsigned long long)nxi->nx_ncaps);
22706 +       buffer += sprintf(buffer, "NFlags:\t%016llx\n",
22707 +               (unsigned long long)nxi->nx_flags);
22708 +
22709 +       buffer += sprintf(buffer,
22710 +               "V4Root[bcast]:\t" NIPQUAD_FMT "\n",
22711 +               NIPQUAD(nxi->v4_bcast.s_addr));
22712 +       buffer += sprintf (buffer,
22713 +               "V4Root[lback]:\t" NIPQUAD_FMT "\n",
22714 +               NIPQUAD(nxi->v4_lback.s_addr));
22715 +       if (!NX_IPV4(nxi))
22716 +               goto skip_v4;
22717 +       for (i = 0, v4a = &nxi->v4; v4a; i++, v4a = v4a->next)
22718 +               buffer += sprintf(buffer, "V4Root[%d]:\t" NXAV4_FMT "\n",
22719 +                       i, NXAV4(v4a));
22720 +skip_v4:
22721 +#ifdef CONFIG_IPV6
22722 +       if (!NX_IPV6(nxi))
22723 +               goto skip_v6;
22724 +       for (i = 0, v6a = &nxi->v6; v6a; i++, v6a = v6a->next)
22725 +               buffer += sprintf(buffer, "V6Root[%d]:\t" NXAV6_FMT "\n",
22726 +                       i, NXAV6(v6a));
22727 +skip_v6:
22728 +#endif
22729 +       put_nx_info(nxi);
22730 +out:
22731 +       return buffer - orig;
22732 +}
22733 +
22734 diff -NurpP --minimal linux-2.6.38.3/kernel/vserver/sched.c linux-2.6.38.3-vs2.3.0.37-rc14/kernel/vserver/sched.c
22735 --- linux-2.6.38.3/kernel/vserver/sched.c       1970-01-01 01:00:00.000000000 +0100
22736 +++ linux-2.6.38.3-vs2.3.0.37-rc14/kernel/vserver/sched.c       2011-01-29 02:01:07.000000000 +0100
22737 @@ -0,0 +1,82 @@
22738 +/*
22739 + *  linux/kernel/vserver/sched.c
22740 + *
22741 + *  Virtual Server: Scheduler Support
22742 + *
22743 + *  Copyright (C) 2004-2010  Herbert Pötzl
22744 + *
22745 + *  V0.01  adapted Sam Vilains version to 2.6.3
22746 + *  V0.02  removed legacy interface
22747 + *  V0.03  changed vcmds to vxi arg
22748 + *  V0.04  removed older and legacy interfaces
22749 + *  V0.05  removed scheduler code/commands
22750 + *
22751 + */
22752 +
22753 +#include <linux/vs_context.h>
22754 +#include <linux/vs_sched.h>
22755 +#include <linux/vserver/sched_cmd.h>
22756 +
22757 +#include <asm/uaccess.h>
22758 +
22759 +
22760 +void vx_update_sched_param(struct _vx_sched *sched,
22761 +       struct _vx_sched_pc *sched_pc)
22762 +{
22763 +       sched_pc->prio_bias = sched->prio_bias;
22764 +}
22765 +
22766 +static int do_set_prio_bias(struct vx_info *vxi, struct vcmd_prio_bias *data)
22767 +{
22768 +       int cpu;
22769 +
22770 +       if (data->prio_bias > MAX_PRIO_BIAS)
22771 +               data->prio_bias = MAX_PRIO_BIAS;
22772 +       if (data->prio_bias < MIN_PRIO_BIAS)
22773 +               data->prio_bias = MIN_PRIO_BIAS;
22774 +
22775 +       if (data->cpu_id != ~0) {
22776 +               vxi->sched.update = cpumask_of_cpu(data->cpu_id);
22777 +               cpus_and(vxi->sched.update, cpu_online_map,
22778 +                       vxi->sched.update);
22779 +       } else
22780 +               vxi->sched.update = cpu_online_map;
22781 +
22782 +       for_each_cpu_mask(cpu, vxi->sched.update)
22783 +               vx_update_sched_param(&vxi->sched,
22784 +                       &vx_per_cpu(vxi, sched_pc, cpu));
22785 +       return 0;
22786 +}
22787 +
22788 +int vc_set_prio_bias(struct vx_info *vxi, void __user *data)
22789 +{
22790 +       struct vcmd_prio_bias vc_data;
22791 +
22792 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
22793 +               return -EFAULT;
22794 +
22795 +       return do_set_prio_bias(vxi, &vc_data);
22796 +}
22797 +
22798 +int vc_get_prio_bias(struct vx_info *vxi, void __user *data)
22799 +{
22800 +       struct vcmd_prio_bias vc_data;
22801 +       struct _vx_sched_pc *pcd;
22802 +       int cpu;
22803 +
22804 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
22805 +               return -EFAULT;
22806 +
22807 +       cpu = vc_data.cpu_id;
22808 +
22809 +       if (!cpu_possible(cpu))
22810 +               return -EINVAL;
22811 +
22812 +       pcd = &vx_per_cpu(vxi, sched_pc, cpu);
22813 +       vc_data.prio_bias = pcd->prio_bias;
22814 +
22815 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
22816 +               return -EFAULT;
22817 +       return 0;
22818 +}
22819 +
22820 diff -NurpP --minimal linux-2.6.38.3/kernel/vserver/sched_init.h linux-2.6.38.3-vs2.3.0.37-rc14/kernel/vserver/sched_init.h
22821 --- linux-2.6.38.3/kernel/vserver/sched_init.h  1970-01-01 01:00:00.000000000 +0100
22822 +++ linux-2.6.38.3-vs2.3.0.37-rc14/kernel/vserver/sched_init.h  2011-01-29 02:01:07.000000000 +0100
22823 @@ -0,0 +1,27 @@
22824 +
22825 +static inline void vx_info_init_sched(struct _vx_sched *sched)
22826 +{
22827 +       /* scheduling; hard code starting values as constants */
22828 +       sched->prio_bias = 0;
22829 +}
22830 +
22831 +static inline
22832 +void vx_info_init_sched_pc(struct _vx_sched_pc *sched_pc, int cpu)
22833 +{
22834 +       sched_pc->prio_bias = 0;
22835 +
22836 +       sched_pc->user_ticks = 0;
22837 +       sched_pc->sys_ticks = 0;
22838 +       sched_pc->hold_ticks = 0;
22839 +}
22840 +
22841 +static inline void vx_info_exit_sched(struct _vx_sched *sched)
22842 +{
22843 +       return;
22844 +}
22845 +
22846 +static inline
22847 +void vx_info_exit_sched_pc(struct _vx_sched_pc *sched_pc, int cpu)
22848 +{
22849 +       return;
22850 +}
22851 diff -NurpP --minimal linux-2.6.38.3/kernel/vserver/sched_proc.h linux-2.6.38.3-vs2.3.0.37-rc14/kernel/vserver/sched_proc.h
22852 --- linux-2.6.38.3/kernel/vserver/sched_proc.h  1970-01-01 01:00:00.000000000 +0100
22853 +++ linux-2.6.38.3-vs2.3.0.37-rc14/kernel/vserver/sched_proc.h  2011-01-29 02:01:07.000000000 +0100
22854 @@ -0,0 +1,32 @@
22855 +#ifndef _VX_SCHED_PROC_H
22856 +#define _VX_SCHED_PROC_H
22857 +
22858 +
22859 +static inline
22860 +int vx_info_proc_sched(struct _vx_sched *sched, char *buffer)
22861 +{
22862 +       int length = 0;
22863 +
22864 +       length += sprintf(buffer,
22865 +               "PrioBias:\t%8d\n",
22866 +               sched->prio_bias);
22867 +       return length;
22868 +}
22869 +
22870 +static inline
22871 +int vx_info_proc_sched_pc(struct _vx_sched_pc *sched_pc,
22872 +       char *buffer, int cpu)
22873 +{
22874 +       int length = 0;
22875 +
22876 +       length += sprintf(buffer + length,
22877 +               "cpu %d: %lld %lld %lld", cpu,
22878 +               (unsigned long long)sched_pc->user_ticks,
22879 +               (unsigned long long)sched_pc->sys_ticks,
22880 +               (unsigned long long)sched_pc->hold_ticks);
22881 +       length += sprintf(buffer + length,
22882 +               " %d\n", sched_pc->prio_bias);
22883 +       return length;
22884 +}
22885 +
22886 +#endif /* _VX_SCHED_PROC_H */
22887 diff -NurpP --minimal linux-2.6.38.3/kernel/vserver/signal.c linux-2.6.38.3-vs2.3.0.37-rc14/kernel/vserver/signal.c
22888 --- linux-2.6.38.3/kernel/vserver/signal.c      1970-01-01 01:00:00.000000000 +0100
22889 +++ linux-2.6.38.3-vs2.3.0.37-rc14/kernel/vserver/signal.c      2011-03-22 17:37:59.000000000 +0100
22890 @@ -0,0 +1,134 @@
22891 +/*
22892 + *  linux/kernel/vserver/signal.c
22893 + *
22894 + *  Virtual Server: Signal Support
22895 + *
22896 + *  Copyright (C) 2003-2007  Herbert Pötzl
22897 + *
22898 + *  V0.01  broken out from vcontext V0.05
22899 + *  V0.02  changed vcmds to vxi arg
22900 + *  V0.03  adjusted siginfo for kill
22901 + *
22902 + */
22903 +
22904 +#include <asm/uaccess.h>
22905 +
22906 +#include <linux/vs_context.h>
22907 +#include <linux/vs_pid.h>
22908 +#include <linux/vserver/signal_cmd.h>
22909 +
22910 +
22911 +int vx_info_kill(struct vx_info *vxi, int pid, int sig)
22912 +{
22913 +       int retval, count = 0;
22914 +       struct task_struct *p;
22915 +       struct siginfo *sip = SEND_SIG_PRIV;
22916 +
22917 +       retval = -ESRCH;
22918 +       vxdprintk(VXD_CBIT(misc, 4),
22919 +               "vx_info_kill(%p[#%d],%d,%d)*",
22920 +               vxi, vxi->vx_id, pid, sig);
22921 +       read_lock(&tasklist_lock);
22922 +       switch (pid) {
22923 +       case  0:
22924 +       case -1:
22925 +               for_each_process(p) {
22926 +                       int err = 0;
22927 +
22928 +                       if (vx_task_xid(p) != vxi->vx_id || p->pid <= 1 ||
22929 +                               (pid && vxi->vx_initpid == p->pid))
22930 +                               continue;
22931 +
22932 +                       err = group_send_sig_info(sig, sip, p);
22933 +                       ++count;
22934 +                       if (err != -EPERM)
22935 +                               retval = err;
22936 +               }
22937 +               break;
22938 +
22939 +       case 1:
22940 +               if (vxi->vx_initpid) {
22941 +                       pid = vxi->vx_initpid;
22942 +                       /* for now, only SIGINT to private init ... */
22943 +                       if (!vx_info_flags(vxi, VXF_STATE_ADMIN, 0) &&
22944 +                               /* ... as long as there are tasks left */
22945 +                               (atomic_read(&vxi->vx_tasks) > 1))
22946 +                               sig = SIGINT;
22947 +               }
22948 +               /* fallthrough */
22949 +       default:
22950 +               rcu_read_lock();
22951 +               p = find_task_by_real_pid(pid);
22952 +               rcu_read_unlock();
22953 +               if (p) {
22954 +                       if (vx_task_xid(p) == vxi->vx_id)
22955 +                               retval = group_send_sig_info(sig, sip, p);
22956 +               }
22957 +               break;
22958 +       }
22959 +       read_unlock(&tasklist_lock);
22960 +       vxdprintk(VXD_CBIT(misc, 4),
22961 +               "vx_info_kill(%p[#%d],%d,%d,%ld) = %d",
22962 +               vxi, vxi->vx_id, pid, sig, (long)sip, retval);
22963 +       return retval;
22964 +}
22965 +
22966 +int vc_ctx_kill(struct vx_info *vxi, void __user *data)
22967 +{
22968 +       struct vcmd_ctx_kill_v0 vc_data;
22969 +
22970 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
22971 +               return -EFAULT;
22972 +
22973 +       /* special check to allow guest shutdown */
22974 +       if (!vx_info_flags(vxi, VXF_STATE_ADMIN, 0) &&
22975 +               /* forbid killall pid=0 when init is present */
22976 +               (((vc_data.pid < 1) && vxi->vx_initpid) ||
22977 +               (vc_data.pid > 1)))
22978 +               return -EACCES;
22979 +
22980 +       return vx_info_kill(vxi, vc_data.pid, vc_data.sig);
22981 +}
22982 +
22983 +
22984 +static int __wait_exit(struct vx_info *vxi)
22985 +{
22986 +       DECLARE_WAITQUEUE(wait, current);
22987 +       int ret = 0;
22988 +
22989 +       add_wait_queue(&vxi->vx_wait, &wait);
22990 +       set_current_state(TASK_INTERRUPTIBLE);
22991 +
22992 +wait:
22993 +       if (vx_info_state(vxi,
22994 +               VXS_SHUTDOWN | VXS_HASHED | VXS_HELPER) == VXS_SHUTDOWN)
22995 +               goto out;
22996 +       if (signal_pending(current)) {
22997 +               ret = -ERESTARTSYS;
22998 +               goto out;
22999 +       }
23000 +       schedule();
23001 +       goto wait;
23002 +
23003 +out:
23004 +       set_current_state(TASK_RUNNING);
23005 +       remove_wait_queue(&vxi->vx_wait, &wait);
23006 +       return ret;
23007 +}
23008 +
23009 +
23010 +
23011 +int vc_wait_exit(struct vx_info *vxi, void __user *data)
23012 +{
23013 +       struct vcmd_wait_exit_v0 vc_data;
23014 +       int ret;
23015 +
23016 +       ret = __wait_exit(vxi);
23017 +       vc_data.reboot_cmd = vxi->reboot_cmd;
23018 +       vc_data.exit_code = vxi->exit_code;
23019 +
23020 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
23021 +               ret = -EFAULT;
23022 +       return ret;
23023 +}
23024 +
23025 diff -NurpP --minimal linux-2.6.38.3/kernel/vserver/space.c linux-2.6.38.3-vs2.3.0.37-rc14/kernel/vserver/space.c
23026 --- linux-2.6.38.3/kernel/vserver/space.c       1970-01-01 01:00:00.000000000 +0100
23027 +++ linux-2.6.38.3-vs2.3.0.37-rc14/kernel/vserver/space.c       2011-02-01 03:30:46.000000000 +0100
23028 @@ -0,0 +1,417 @@
23029 +/*
23030 + *  linux/kernel/vserver/space.c
23031 + *
23032 + *  Virtual Server: Context Space Support
23033 + *
23034 + *  Copyright (C) 2003-2010  Herbert Pötzl
23035 + *
23036 + *  V0.01  broken out from context.c 0.07
23037 + *  V0.02  added task locking for namespace
23038 + *  V0.03  broken out vx_enter_namespace
23039 + *  V0.04  added *space support and commands
23040 + *  V0.05  added credential support
23041 + *
23042 + */
23043 +
23044 +#include <linux/utsname.h>
23045 +#include <linux/nsproxy.h>
23046 +#include <linux/err.h>
23047 +#include <linux/fs_struct.h>
23048 +#include <linux/cred.h>
23049 +#include <asm/uaccess.h>
23050 +
23051 +#include <linux/vs_context.h>
23052 +#include <linux/vserver/space.h>
23053 +#include <linux/vserver/space_cmd.h>
23054 +
23055 +atomic_t vs_global_nsproxy     = ATOMIC_INIT(0);
23056 +atomic_t vs_global_fs          = ATOMIC_INIT(0);
23057 +atomic_t vs_global_mnt_ns      = ATOMIC_INIT(0);
23058 +atomic_t vs_global_uts_ns      = ATOMIC_INIT(0);
23059 +atomic_t vs_global_user_ns     = ATOMIC_INIT(0);
23060 +atomic_t vs_global_pid_ns      = ATOMIC_INIT(0);
23061 +
23062 +
23063 +/* namespace functions */
23064 +
23065 +#include <linux/mnt_namespace.h>
23066 +#include <linux/user_namespace.h>
23067 +#include <linux/pid_namespace.h>
23068 +#include <linux/ipc_namespace.h>
23069 +#include <net/net_namespace.h>
23070 +
23071 +
23072 +static const struct vcmd_space_mask_v1 space_mask_v0 = {
23073 +       .mask = CLONE_FS |
23074 +               CLONE_NEWNS |
23075 +               CLONE_NEWUTS |
23076 +               CLONE_NEWIPC |
23077 +               CLONE_NEWUSER |
23078 +               0
23079 +};
23080 +
23081 +static const struct vcmd_space_mask_v1 space_mask = {
23082 +       .mask = CLONE_FS |
23083 +               CLONE_NEWNS |
23084 +               CLONE_NEWUTS |
23085 +               CLONE_NEWIPC |
23086 +               CLONE_NEWUSER |
23087 +#ifdef CONFIG_PID_NS
23088 +               CLONE_NEWPID |
23089 +#endif
23090 +#ifdef CONFIG_NET_NS
23091 +               CLONE_NEWNET |
23092 +#endif
23093 +               0
23094 +};
23095 +
23096 +static const struct vcmd_space_mask_v1 default_space_mask = {
23097 +       .mask = CLONE_FS |
23098 +               CLONE_NEWNS |
23099 +               CLONE_NEWUTS |
23100 +               CLONE_NEWIPC |
23101 +               CLONE_NEWUSER |
23102 +#ifdef CONFIG_PID_NS
23103 +//             CLONE_NEWPID |
23104 +#endif
23105 +               0
23106 +};
23107 +
23108 +/*
23109 + *     build a new nsproxy mix
23110 + *      assumes that both proxies are 'const'
23111 + *     does not touch nsproxy refcounts
23112 + *     will hold a reference on the result.
23113 + */
23114 +
23115 +struct nsproxy *vs_mix_nsproxy(struct nsproxy *old_nsproxy,
23116 +       struct nsproxy *new_nsproxy, unsigned long mask)
23117 +{
23118 +       struct mnt_namespace *old_ns;
23119 +       struct uts_namespace *old_uts;
23120 +       struct ipc_namespace *old_ipc;
23121 +#ifdef CONFIG_PID_NS
23122 +       struct pid_namespace *old_pid;
23123 +#endif
23124 +#ifdef CONFIG_NET_NS
23125 +       struct net *old_net;
23126 +#endif
23127 +       struct nsproxy *nsproxy;
23128 +
23129 +       nsproxy = copy_nsproxy(old_nsproxy);
23130 +       if (!nsproxy)
23131 +               goto out;
23132 +
23133 +       if (mask & CLONE_NEWNS) {
23134 +               old_ns = nsproxy->mnt_ns;
23135 +               nsproxy->mnt_ns = new_nsproxy->mnt_ns;
23136 +               if (nsproxy->mnt_ns)
23137 +                       get_mnt_ns(nsproxy->mnt_ns);
23138 +       } else
23139 +               old_ns = NULL;
23140 +
23141 +       if (mask & CLONE_NEWUTS) {
23142 +               old_uts = nsproxy->uts_ns;
23143 +               nsproxy->uts_ns = new_nsproxy->uts_ns;
23144 +               if (nsproxy->uts_ns)
23145 +                       get_uts_ns(nsproxy->uts_ns);
23146 +       } else
23147 +               old_uts = NULL;
23148 +
23149 +       if (mask & CLONE_NEWIPC) {
23150 +               old_ipc = nsproxy->ipc_ns;
23151 +               nsproxy->ipc_ns = new_nsproxy->ipc_ns;
23152 +               if (nsproxy->ipc_ns)
23153 +                       get_ipc_ns(nsproxy->ipc_ns);
23154 +       } else
23155 +               old_ipc = NULL;
23156 +
23157 +#ifdef CONFIG_PID_NS
23158 +       if (mask & CLONE_NEWPID) {
23159 +               old_pid = nsproxy->pid_ns;
23160 +               nsproxy->pid_ns = new_nsproxy->pid_ns;
23161 +               if (nsproxy->pid_ns)
23162 +                       get_pid_ns(nsproxy->pid_ns);
23163 +       } else
23164 +               old_pid = NULL;
23165 +#endif
23166 +#ifdef CONFIG_NET_NS
23167 +       if (mask & CLONE_NEWNET) {
23168 +               old_net = nsproxy->net_ns;
23169 +               nsproxy->net_ns = new_nsproxy->net_ns;
23170 +               if (nsproxy->net_ns)
23171 +                       get_net(nsproxy->net_ns);
23172 +       } else
23173 +               old_net = NULL;
23174 +#endif
23175 +       if (old_ns)
23176 +               put_mnt_ns(old_ns);
23177 +       if (old_uts)
23178 +               put_uts_ns(old_uts);
23179 +       if (old_ipc)
23180 +               put_ipc_ns(old_ipc);
23181 +#ifdef CONFIG_PID_NS
23182 +       if (old_pid)
23183 +               put_pid_ns(old_pid);
23184 +#endif
23185 +#ifdef CONFIG_NET_NS
23186 +       if (old_net)
23187 +               put_net(old_net);
23188 +#endif
23189 +out:
23190 +       return nsproxy;
23191 +}
23192 +
23193 +
23194 +/*
23195 + *     merge two nsproxy structs into a new one.
23196 + *     will hold a reference on the result.
23197 + */
23198 +
23199 +static inline
23200 +struct nsproxy *__vs_merge_nsproxy(struct nsproxy *old,
23201 +       struct nsproxy *proxy, unsigned long mask)
23202 +{
23203 +       struct nsproxy null_proxy = { .mnt_ns = NULL };
23204 +
23205 +       if (!proxy)
23206 +               return NULL;
23207 +
23208 +       if (mask) {
23209 +               /* vs_mix_nsproxy returns with reference */
23210 +               return vs_mix_nsproxy(old ? old : &null_proxy,
23211 +                       proxy, mask);
23212 +       }
23213 +       get_nsproxy(proxy);
23214 +       return proxy;
23215 +}
23216 +
23217 +
23218 +int vx_enter_space(struct vx_info *vxi, unsigned long mask, unsigned index)
23219 +{
23220 +       struct nsproxy *proxy, *proxy_cur, *proxy_new;
23221 +       struct fs_struct *fs_cur, *fs = NULL;
23222 +       struct _vx_space *space;
23223 +       int ret, kill = 0;
23224 +
23225 +       vxdprintk(VXD_CBIT(space, 8), "vx_enter_space(%p[#%u],0x%08lx,%d)",
23226 +               vxi, vxi->vx_id, mask, index);
23227 +
23228 +       if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0))
23229 +               return -EACCES;
23230 +
23231 +       if (index >= VX_SPACES)
23232 +               return -EINVAL;
23233 +
23234 +       space = &vxi->space[index];
23235 +
23236 +       if (!mask)
23237 +               mask = space->vx_nsmask;
23238 +
23239 +       if ((mask & space->vx_nsmask) != mask)
23240 +               return -EINVAL;
23241 +
23242 +       if (mask & CLONE_FS) {
23243 +               fs = copy_fs_struct(space->vx_fs);
23244 +               if (!fs)
23245 +                       return -ENOMEM;
23246 +       }
23247 +       proxy = space->vx_nsproxy;
23248 +
23249 +       vxdprintk(VXD_CBIT(space, 9),
23250 +               "vx_enter_space(%p[#%u],0x%08lx,%d) -> (%p,%p)",
23251 +               vxi, vxi->vx_id, mask, index, proxy, fs);
23252 +
23253 +       task_lock(current);
23254 +       fs_cur = current->fs;
23255 +
23256 +       if (mask & CLONE_FS) {
23257 +               spin_lock(&fs_cur->lock);
23258 +               current->fs = fs;
23259 +               kill = !--fs_cur->users;
23260 +               spin_unlock(&fs_cur->lock);
23261 +       }
23262 +
23263 +       proxy_cur = current->nsproxy;
23264 +       get_nsproxy(proxy_cur);
23265 +       task_unlock(current);
23266 +
23267 +       if (kill)
23268 +               free_fs_struct(fs_cur);
23269 +
23270 +       proxy_new = __vs_merge_nsproxy(proxy_cur, proxy, mask);
23271 +       if (IS_ERR(proxy_new)) {
23272 +               ret = PTR_ERR(proxy_new);
23273 +               goto out_put;
23274 +       }
23275 +
23276 +       proxy_new = xchg(&current->nsproxy, proxy_new);
23277 +
23278 +       if (mask & CLONE_NEWUSER) {
23279 +               struct cred *cred;
23280 +
23281 +               vxdprintk(VXD_CBIT(space, 10),
23282 +                       "vx_enter_space(%p[#%u],%p) cred (%p,%p)",
23283 +                       vxi, vxi->vx_id, space->vx_cred,
23284 +                       current->real_cred, current->cred);
23285 +
23286 +               if (space->vx_cred) {
23287 +                       cred = __prepare_creds(space->vx_cred);
23288 +                       if (cred)
23289 +                               commit_creds(cred);
23290 +               }
23291 +       }
23292 +
23293 +       ret = 0;
23294 +
23295 +       if (proxy_new)
23296 +               put_nsproxy(proxy_new);
23297 +out_put:
23298 +       if (proxy_cur)
23299 +               put_nsproxy(proxy_cur);
23300 +       return ret;
23301 +}
23302 +
23303 +
23304 +int vx_set_space(struct vx_info *vxi, unsigned long mask, unsigned index)
23305 +{
23306 +       struct nsproxy *proxy_vxi, *proxy_cur, *proxy_new;
23307 +       struct fs_struct *fs_vxi, *fs;
23308 +       struct _vx_space *space;
23309 +       int ret, kill = 0;
23310 +
23311 +       vxdprintk(VXD_CBIT(space, 8), "vx_set_space(%p[#%u],0x%08lx,%d)",
23312 +               vxi, vxi->vx_id, mask, index);
23313 +
23314 +       if ((mask & space_mask.mask) != mask)
23315 +               return -EINVAL;
23316 +
23317 +       if (index >= VX_SPACES)
23318 +               return -EINVAL;
23319 +
23320 +       space = &vxi->space[index];
23321 +
23322 +       proxy_vxi = space->vx_nsproxy;
23323 +       fs_vxi = space->vx_fs;
23324 +
23325 +       if (mask & CLONE_FS) {
23326 +               fs = copy_fs_struct(current->fs);
23327 +               if (!fs)
23328 +                       return -ENOMEM;
23329 +       }
23330 +
23331 +       task_lock(current);
23332 +
23333 +       if (mask & CLONE_FS) {
23334 +               spin_lock(&fs_vxi->lock);
23335 +               space->vx_fs = fs;
23336 +               kill = !--fs_vxi->users;
23337 +               spin_unlock(&fs_vxi->lock);
23338 +       }
23339 +
23340 +       proxy_cur = current->nsproxy;
23341 +       get_nsproxy(proxy_cur);
23342 +       task_unlock(current);
23343 +
23344 +       if (kill)
23345 +               free_fs_struct(fs_vxi);
23346 +
23347 +       proxy_new = __vs_merge_nsproxy(proxy_vxi, proxy_cur, mask);
23348 +       if (IS_ERR(proxy_new)) {
23349 +               ret = PTR_ERR(proxy_new);
23350 +               goto out_put;
23351 +       }
23352 +
23353 +       proxy_new = xchg(&space->vx_nsproxy, proxy_new);
23354 +       space->vx_nsmask |= mask;
23355 +
23356 +       if (mask & CLONE_NEWUSER) {
23357 +               struct cred *cred;
23358 +
23359 +               vxdprintk(VXD_CBIT(space, 10),
23360 +                       "vx_set_space(%p[#%u],%p) cred (%p,%p)",
23361 +                       vxi, vxi->vx_id, space->vx_cred,
23362 +                       current->real_cred, current->cred);
23363 +
23364 +               cred = prepare_creds();
23365 +               cred = (struct cred *)xchg(&space->vx_cred, cred);
23366 +               if (cred)
23367 +                       abort_creds(cred);
23368 +       }
23369 +
23370 +       ret = 0;
23371 +
23372 +       if (proxy_new)
23373 +               put_nsproxy(proxy_new);
23374 +out_put:
23375 +       if (proxy_cur)
23376 +               put_nsproxy(proxy_cur);
23377 +       return ret;
23378 +}
23379 +
23380 +
23381 +int vc_enter_space_v1(struct vx_info *vxi, void __user *data)
23382 +{
23383 +       struct vcmd_space_mask_v1 vc_data = { .mask = 0 };
23384 +
23385 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
23386 +               return -EFAULT;
23387 +
23388 +       return vx_enter_space(vxi, vc_data.mask, 0);
23389 +}
23390 +
23391 +int vc_enter_space(struct vx_info *vxi, void __user *data)
23392 +{
23393 +       struct vcmd_space_mask_v2 vc_data = { .mask = 0 };
23394 +
23395 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
23396 +               return -EFAULT;
23397 +
23398 +       if (vc_data.index >= VX_SPACES)
23399 +               return -EINVAL;
23400 +
23401 +       return vx_enter_space(vxi, vc_data.mask, vc_data.index);
23402 +}
23403 +
23404 +int vc_set_space_v1(struct vx_info *vxi, void __user *data)
23405 +{
23406 +       struct vcmd_space_mask_v1 vc_data = { .mask = 0 };
23407 +
23408 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
23409 +               return -EFAULT;
23410 +
23411 +       return vx_set_space(vxi, vc_data.mask, 0);
23412 +}
23413 +
23414 +int vc_set_space(struct vx_info *vxi, void __user *data)
23415 +{
23416 +       struct vcmd_space_mask_v2 vc_data = { .mask = 0 };
23417 +
23418 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
23419 +               return -EFAULT;
23420 +
23421 +       if (vc_data.index >= VX_SPACES)
23422 +               return -EINVAL;
23423 +
23424 +       return vx_set_space(vxi, vc_data.mask, vc_data.index);
23425 +}
23426 +
23427 +int vc_get_space_mask(void __user *data, int type)
23428 +{
23429 +       const struct vcmd_space_mask_v1 *mask;
23430 +
23431 +       if (type == 0)
23432 +               mask = &space_mask_v0;
23433 +       else if (type == 1)
23434 +               mask = &space_mask;
23435 +       else
23436 +               mask = &default_space_mask;
23437 +
23438 +       vxdprintk(VXD_CBIT(space, 10),
23439 +               "vc_get_space_mask(%d) = %08llx", type, mask->mask);
23440 +
23441 +       if (copy_to_user(data, mask, sizeof(*mask)))
23442 +               return -EFAULT;
23443 +       return 0;
23444 +}
23445 +
23446 diff -NurpP --minimal linux-2.6.38.3/kernel/vserver/switch.c linux-2.6.38.3-vs2.3.0.37-rc14/kernel/vserver/switch.c
23447 --- linux-2.6.38.3/kernel/vserver/switch.c      1970-01-01 01:00:00.000000000 +0100
23448 +++ linux-2.6.38.3-vs2.3.0.37-rc14/kernel/vserver/switch.c      2011-04-15 16:09:19.000000000 +0200
23449 @@ -0,0 +1,540 @@
23450 +/*
23451 + *  linux/kernel/vserver/switch.c
23452 + *
23453 + *  Virtual Server: Syscall Switch
23454 + *
23455 + *  Copyright (C) 2003-2007  Herbert Pötzl
23456 + *
23457 + *  V0.01  syscall switch
23458 + *  V0.02  added signal to context
23459 + *  V0.03  added rlimit functions
23460 + *  V0.04  added iattr, task/xid functions
23461 + *  V0.05  added debug/history stuff
23462 + *  V0.06  added compat32 layer
23463 + *  V0.07  vcmd args and perms
23464 + *  V0.08  added status commands
23465 + *  V0.09  added tag commands
23466 + *  V0.10  added oom bias
23467 + *  V0.11  added device commands
23468 + *
23469 + */
23470 +
23471 +#include <linux/vs_context.h>
23472 +#include <linux/vs_network.h>
23473 +#include <linux/vserver/switch.h>
23474 +
23475 +#include "vci_config.h"
23476 +
23477 +
23478 +static inline
23479 +int vc_get_version(uint32_t id)
23480 +{
23481 +       return VCI_VERSION;
23482 +}
23483 +
23484 +static inline
23485 +int vc_get_vci(uint32_t id)
23486 +{
23487 +       return vci_kernel_config();
23488 +}
23489 +
23490 +#include <linux/vserver/context_cmd.h>
23491 +#include <linux/vserver/cvirt_cmd.h>
23492 +#include <linux/vserver/cacct_cmd.h>
23493 +#include <linux/vserver/limit_cmd.h>
23494 +#include <linux/vserver/network_cmd.h>
23495 +#include <linux/vserver/sched_cmd.h>
23496 +#include <linux/vserver/debug_cmd.h>
23497 +#include <linux/vserver/inode_cmd.h>
23498 +#include <linux/vserver/dlimit_cmd.h>
23499 +#include <linux/vserver/signal_cmd.h>
23500 +#include <linux/vserver/space_cmd.h>
23501 +#include <linux/vserver/tag_cmd.h>
23502 +#include <linux/vserver/device_cmd.h>
23503 +
23504 +#include <linux/vserver/inode.h>
23505 +#include <linux/vserver/dlimit.h>
23506 +
23507 +
23508 +#ifdef CONFIG_COMPAT
23509 +#define __COMPAT(name, id, data, compat)       \
23510 +       (compat) ? name ## _x32(id, data) : name(id, data)
23511 +#define __COMPAT_NO_ID(name, data, compat)     \
23512 +       (compat) ? name ## _x32(data) : name(data)
23513 +#else
23514 +#define __COMPAT(name, id, data, compat)       \
23515 +       name(id, data)
23516 +#define __COMPAT_NO_ID(name, data, compat)     \
23517 +       name(data)
23518 +#endif
23519 +
23520 +
23521 +static inline
23522 +long do_vcmd(uint32_t cmd, uint32_t id,
23523 +       struct vx_info *vxi, struct nx_info *nxi,
23524 +       void __user *data, int compat)
23525 +{
23526 +       switch (cmd) {
23527 +
23528 +       case VCMD_get_version:
23529 +               return vc_get_version(id);
23530 +       case VCMD_get_vci:
23531 +               return vc_get_vci(id);
23532 +
23533 +       case VCMD_task_xid:
23534 +               return vc_task_xid(id);
23535 +       case VCMD_vx_info:
23536 +               return vc_vx_info(vxi, data);
23537 +
23538 +       case VCMD_task_nid:
23539 +               return vc_task_nid(id);
23540 +       case VCMD_nx_info:
23541 +               return vc_nx_info(nxi, data);
23542 +
23543 +       case VCMD_task_tag:
23544 +               return vc_task_tag(id);
23545 +
23546 +       case VCMD_set_space_v1:
23547 +               return vc_set_space_v1(vxi, data);
23548 +       /* this is version 2 */
23549 +       case VCMD_set_space:
23550 +               return vc_set_space(vxi, data);
23551 +
23552 +       case VCMD_get_space_mask_v0:
23553 +               return vc_get_space_mask(data, 0);
23554 +       /* this is version 1 */
23555 +       case VCMD_get_space_mask:
23556 +               return vc_get_space_mask(data, 1);
23557 +
23558 +       case VCMD_get_space_default:
23559 +               return vc_get_space_mask(data, -1);
23560 +
23561 +#ifdef CONFIG_IA32_EMULATION
23562 +       case VCMD_get_rlimit:
23563 +               return __COMPAT(vc_get_rlimit, vxi, data, compat);
23564 +       case VCMD_set_rlimit:
23565 +               return __COMPAT(vc_set_rlimit, vxi, data, compat);
23566 +#else
23567 +       case VCMD_get_rlimit:
23568 +               return vc_get_rlimit(vxi, data);
23569 +       case VCMD_set_rlimit:
23570 +               return vc_set_rlimit(vxi, data);
23571 +#endif
23572 +       case VCMD_get_rlimit_mask:
23573 +               return vc_get_rlimit_mask(id, data);
23574 +       case VCMD_reset_hits:
23575 +               return vc_reset_hits(vxi, data);
23576 +       case VCMD_reset_minmax:
23577 +               return vc_reset_minmax(vxi, data);
23578 +
23579 +       case VCMD_get_vhi_name:
23580 +               return vc_get_vhi_name(vxi, data);
23581 +       case VCMD_set_vhi_name:
23582 +               return vc_set_vhi_name(vxi, data);
23583 +
23584 +       case VCMD_ctx_stat:
23585 +               return vc_ctx_stat(vxi, data);
23586 +       case VCMD_virt_stat:
23587 +               return vc_virt_stat(vxi, data);
23588 +       case VCMD_sock_stat:
23589 +               return vc_sock_stat(vxi, data);
23590 +       case VCMD_rlimit_stat:
23591 +               return vc_rlimit_stat(vxi, data);
23592 +
23593 +       case VCMD_set_cflags:
23594 +               return vc_set_cflags(vxi, data);
23595 +       case VCMD_get_cflags:
23596 +               return vc_get_cflags(vxi, data);
23597 +
23598 +       /* this is version 1 */
23599 +       case VCMD_set_ccaps:
23600 +               return vc_set_ccaps(vxi, data);
23601 +       /* this is version 1 */
23602 +       case VCMD_get_ccaps:
23603 +               return vc_get_ccaps(vxi, data);
23604 +       case VCMD_set_bcaps:
23605 +               return vc_set_bcaps(vxi, data);
23606 +       case VCMD_get_bcaps:
23607 +               return vc_get_bcaps(vxi, data);
23608 +
23609 +       case VCMD_set_badness:
23610 +               return vc_set_badness(vxi, data);
23611 +       case VCMD_get_badness:
23612 +               return vc_get_badness(vxi, data);
23613 +
23614 +       case VCMD_set_nflags:
23615 +               return vc_set_nflags(nxi, data);
23616 +       case VCMD_get_nflags:
23617 +               return vc_get_nflags(nxi, data);
23618 +
23619 +       case VCMD_set_ncaps:
23620 +               return vc_set_ncaps(nxi, data);
23621 +       case VCMD_get_ncaps:
23622 +               return vc_get_ncaps(nxi, data);
23623 +
23624 +       case VCMD_set_prio_bias:
23625 +               return vc_set_prio_bias(vxi, data);
23626 +       case VCMD_get_prio_bias:
23627 +               return vc_get_prio_bias(vxi, data);
23628 +       case VCMD_add_dlimit:
23629 +               return __COMPAT(vc_add_dlimit, id, data, compat);
23630 +       case VCMD_rem_dlimit:
23631 +               return __COMPAT(vc_rem_dlimit, id, data, compat);
23632 +       case VCMD_set_dlimit:
23633 +               return __COMPAT(vc_set_dlimit, id, data, compat);
23634 +       case VCMD_get_dlimit:
23635 +               return __COMPAT(vc_get_dlimit, id, data, compat);
23636 +
23637 +       case VCMD_ctx_kill:
23638 +               return vc_ctx_kill(vxi, data);
23639 +
23640 +       case VCMD_wait_exit:
23641 +               return vc_wait_exit(vxi, data);
23642 +
23643 +       case VCMD_get_iattr:
23644 +               return __COMPAT_NO_ID(vc_get_iattr, data, compat);
23645 +       case VCMD_set_iattr:
23646 +               return __COMPAT_NO_ID(vc_set_iattr, data, compat);
23647 +
23648 +       case VCMD_fget_iattr:
23649 +               return vc_fget_iattr(id, data);
23650 +       case VCMD_fset_iattr:
23651 +               return vc_fset_iattr(id, data);
23652 +
23653 +       case VCMD_enter_space_v0:
23654 +               return vc_enter_space_v1(vxi, NULL);
23655 +       case VCMD_enter_space_v1:
23656 +               return vc_enter_space_v1(vxi, data);
23657 +       /* this is version 2 */
23658 +       case VCMD_enter_space:
23659 +               return vc_enter_space(vxi, data);
23660 +
23661 +       case VCMD_ctx_create_v0:
23662 +               return vc_ctx_create(id, NULL);
23663 +       case VCMD_ctx_create:
23664 +               return vc_ctx_create(id, data);
23665 +       case VCMD_ctx_migrate_v0:
23666 +               return vc_ctx_migrate(vxi, NULL);
23667 +       case VCMD_ctx_migrate:
23668 +               return vc_ctx_migrate(vxi, data);
23669 +
23670 +       case VCMD_net_create_v0:
23671 +               return vc_net_create(id, NULL);
23672 +       case VCMD_net_create:
23673 +               return vc_net_create(id, data);
23674 +       case VCMD_net_migrate:
23675 +               return vc_net_migrate(nxi, data);
23676 +
23677 +       case VCMD_tag_migrate:
23678 +               return vc_tag_migrate(id);
23679 +
23680 +       case VCMD_net_add:
23681 +               return vc_net_add(nxi, data);
23682 +       case VCMD_net_remove:
23683 +               return vc_net_remove(nxi, data);
23684 +
23685 +       case VCMD_net_add_ipv4_v1:
23686 +               return vc_net_add_ipv4_v1(nxi, data);
23687 +       /* this is version 2 */
23688 +       case VCMD_net_add_ipv4:
23689 +               return vc_net_add_ipv4(nxi, data);
23690 +
23691 +       case VCMD_net_rem_ipv4_v1:
23692 +               return vc_net_rem_ipv4_v1(nxi, data);
23693 +       /* this is version 2 */
23694 +       case VCMD_net_rem_ipv4:
23695 +               return vc_net_rem_ipv4(nxi, data);
23696 +#ifdef CONFIG_IPV6
23697 +       case VCMD_net_add_ipv6:
23698 +               return vc_net_add_ipv6(nxi, data);
23699 +       case VCMD_net_remove_ipv6:
23700 +               return vc_net_remove_ipv6(nxi, data);
23701 +#endif
23702 +/*     case VCMD_add_match_ipv4:
23703 +               return vc_add_match_ipv4(nxi, data);
23704 +       case VCMD_get_match_ipv4:
23705 +               return vc_get_match_ipv4(nxi, data);
23706 +#ifdef CONFIG_IPV6
23707 +       case VCMD_add_match_ipv6:
23708 +               return vc_add_match_ipv6(nxi, data);
23709 +       case VCMD_get_match_ipv6:
23710 +               return vc_get_match_ipv6(nxi, data);
23711 +#endif */
23712 +
23713 +#ifdef CONFIG_VSERVER_DEVICE
23714 +       case VCMD_set_mapping:
23715 +               return __COMPAT(vc_set_mapping, vxi, data, compat);
23716 +       case VCMD_unset_mapping:
23717 +               return __COMPAT(vc_unset_mapping, vxi, data, compat);
23718 +#endif
23719 +#ifdef CONFIG_VSERVER_HISTORY
23720 +       case VCMD_dump_history:
23721 +               return vc_dump_history(id);
23722 +       case VCMD_read_history:
23723 +               return __COMPAT(vc_read_history, id, data, compat);
23724 +#endif
23725 +       default:
23726 +               vxwprintk_task(1, "unimplemented VCMD_%02d_%d[%d]",
23727 +                       VC_CATEGORY(cmd), VC_COMMAND(cmd), VC_VERSION(cmd));
23728 +       }
23729 +       return -ENOSYS;
23730 +}
23731 +
23732 +
23733 +#define        __VCMD(vcmd, _perm, _args, _flags)              \
23734 +       case VCMD_ ## vcmd: perm = _perm;               \
23735 +               args = _args; flags = _flags; break
23736 +
23737 +
23738 +#define VCA_NONE       0x00
23739 +#define VCA_VXI                0x01
23740 +#define VCA_NXI                0x02
23741 +
23742 +#define VCF_NONE       0x00
23743 +#define VCF_INFO       0x01
23744 +#define VCF_ADMIN      0x02
23745 +#define VCF_ARES       0x06    /* includes admin */
23746 +#define VCF_SETUP      0x08
23747 +
23748 +#define VCF_ZIDOK      0x10    /* zero id okay */
23749 +
23750 +
23751 +static inline
23752 +long do_vserver(uint32_t cmd, uint32_t id, void __user *data, int compat)
23753 +{
23754 +       long ret;
23755 +       int permit = -1, state = 0;
23756 +       int perm = -1, args = 0, flags = 0;
23757 +       struct vx_info *vxi = NULL;
23758 +       struct nx_info *nxi = NULL;
23759 +
23760 +       switch (cmd) {
23761 +       /* unpriviledged commands */
23762 +       __VCMD(get_version,      0, VCA_NONE,   0);
23763 +       __VCMD(get_vci,          0, VCA_NONE,   0);
23764 +       __VCMD(get_rlimit_mask,  0, VCA_NONE,   0);
23765 +       __VCMD(get_space_mask_v0,0, VCA_NONE,   0);
23766 +       __VCMD(get_space_mask,   0, VCA_NONE,   0);
23767 +       __VCMD(get_space_default,0, VCA_NONE,   0);
23768 +
23769 +       /* info commands */
23770 +       __VCMD(task_xid,         2, VCA_NONE,   0);
23771 +       __VCMD(reset_hits,       2, VCA_VXI,    0);
23772 +       __VCMD(reset_minmax,     2, VCA_VXI,    0);
23773 +       __VCMD(vx_info,          3, VCA_VXI,    VCF_INFO);
23774 +       __VCMD(get_bcaps,        3, VCA_VXI,    VCF_INFO);
23775 +       __VCMD(get_ccaps,        3, VCA_VXI,    VCF_INFO);
23776 +       __VCMD(get_cflags,       3, VCA_VXI,    VCF_INFO);
23777 +       __VCMD(get_badness,      3, VCA_VXI,    VCF_INFO);
23778 +       __VCMD(get_vhi_name,     3, VCA_VXI,    VCF_INFO);
23779 +       __VCMD(get_rlimit,       3, VCA_VXI,    VCF_INFO);
23780 +
23781 +       __VCMD(ctx_stat,         3, VCA_VXI,    VCF_INFO);
23782 +       __VCMD(virt_stat,        3, VCA_VXI,    VCF_INFO);
23783 +       __VCMD(sock_stat,        3, VCA_VXI,    VCF_INFO);
23784 +       __VCMD(rlimit_stat,      3, VCA_VXI,    VCF_INFO);
23785 +
23786 +       __VCMD(task_nid,         2, VCA_NONE,   0);
23787 +       __VCMD(nx_info,          3, VCA_NXI,    VCF_INFO);
23788 +       __VCMD(get_ncaps,        3, VCA_NXI,    VCF_INFO);
23789 +       __VCMD(get_nflags,       3, VCA_NXI,    VCF_INFO);
23790 +
23791 +       __VCMD(task_tag,         2, VCA_NONE,   0);
23792 +
23793 +       __VCMD(get_iattr,        2, VCA_NONE,   0);
23794 +       __VCMD(fget_iattr,       2, VCA_NONE,   0);
23795 +       __VCMD(get_dlimit,       3, VCA_NONE,   VCF_INFO);
23796 +       __VCMD(get_prio_bias,    3, VCA_VXI,    VCF_INFO);
23797 +
23798 +       /* lower admin commands */
23799 +       __VCMD(wait_exit,        4, VCA_VXI,    VCF_INFO);
23800 +       __VCMD(ctx_create_v0,    5, VCA_NONE,   0);
23801 +       __VCMD(ctx_create,       5, VCA_NONE,   0);
23802 +       __VCMD(ctx_migrate_v0,   5, VCA_VXI,    VCF_ADMIN);
23803 +       __VCMD(ctx_migrate,      5, VCA_VXI,    VCF_ADMIN);
23804 +       __VCMD(enter_space_v0,   5, VCA_VXI,    VCF_ADMIN);
23805 +       __VCMD(enter_space_v1,   5, VCA_VXI,    VCF_ADMIN);
23806 +       __VCMD(enter_space,      5, VCA_VXI,    VCF_ADMIN);
23807 +
23808 +       __VCMD(net_create_v0,    5, VCA_NONE,   0);
23809 +       __VCMD(net_create,       5, VCA_NONE,   0);
23810 +       __VCMD(net_migrate,      5, VCA_NXI,    VCF_ADMIN);
23811 +
23812 +       __VCMD(tag_migrate,      5, VCA_NONE,   VCF_ADMIN);
23813 +
23814 +       /* higher admin commands */
23815 +       __VCMD(ctx_kill,         6, VCA_VXI,    VCF_ARES);
23816 +       __VCMD(set_space_v1,     7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23817 +       __VCMD(set_space,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23818 +
23819 +       __VCMD(set_ccaps,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23820 +       __VCMD(set_bcaps,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23821 +       __VCMD(set_cflags,       7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23822 +       __VCMD(set_badness,      7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23823 +
23824 +       __VCMD(set_vhi_name,     7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23825 +       __VCMD(set_rlimit,       7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23826 +       __VCMD(set_prio_bias,    7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23827 +
23828 +       __VCMD(set_ncaps,        7, VCA_NXI,    VCF_ARES | VCF_SETUP);
23829 +       __VCMD(set_nflags,       7, VCA_NXI,    VCF_ARES | VCF_SETUP);
23830 +       __VCMD(net_add,          8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23831 +       __VCMD(net_remove,       8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23832 +       __VCMD(net_add_ipv4_v1,  8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23833 +       __VCMD(net_rem_ipv4_v1,  8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23834 +       __VCMD(net_add_ipv4,     8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23835 +       __VCMD(net_rem_ipv4,     8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23836 +#ifdef CONFIG_IPV6
23837 +       __VCMD(net_add_ipv6,     8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23838 +       __VCMD(net_remove_ipv6,  8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23839 +#endif
23840 +       __VCMD(set_iattr,        7, VCA_NONE,   0);
23841 +       __VCMD(fset_iattr,       7, VCA_NONE,   0);
23842 +       __VCMD(set_dlimit,       7, VCA_NONE,   VCF_ARES);
23843 +       __VCMD(add_dlimit,       8, VCA_NONE,   VCF_ARES);
23844 +       __VCMD(rem_dlimit,       8, VCA_NONE,   VCF_ARES);
23845 +
23846 +#ifdef CONFIG_VSERVER_DEVICE
23847 +       __VCMD(set_mapping,      8, VCA_VXI,    VCF_ARES|VCF_ZIDOK);
23848 +       __VCMD(unset_mapping,    8, VCA_VXI,    VCF_ARES|VCF_ZIDOK);
23849 +#endif
23850 +       /* debug level admin commands */
23851 +#ifdef CONFIG_VSERVER_HISTORY
23852 +       __VCMD(dump_history,     9, VCA_NONE,   0);
23853 +       __VCMD(read_history,     9, VCA_NONE,   0);
23854 +#endif
23855 +
23856 +       default:
23857 +               perm = -1;
23858 +       }
23859 +
23860 +       vxdprintk(VXD_CBIT(switch, 0),
23861 +               "vc: VCMD_%02d_%d[%d], %d,%p [%d,%d,%x,%x]",
23862 +               VC_CATEGORY(cmd), VC_COMMAND(cmd),
23863 +               VC_VERSION(cmd), id, data, compat,
23864 +               perm, args, flags);
23865 +
23866 +       ret = -ENOSYS;
23867 +       if (perm < 0)
23868 +               goto out;
23869 +
23870 +       state = 1;
23871 +       if (!capable(CAP_CONTEXT))
23872 +               goto out;
23873 +
23874 +       state = 2;
23875 +       /* moved here from the individual commands */
23876 +       ret = -EPERM;
23877 +       if ((perm > 1) && !capable(CAP_SYS_ADMIN))
23878 +               goto out;
23879 +
23880 +       state = 3;
23881 +       /* vcmd involves resource management  */
23882 +       ret = -EPERM;
23883 +       if ((flags & VCF_ARES) && !capable(CAP_SYS_RESOURCE))
23884 +               goto out;
23885 +
23886 +       state = 4;
23887 +       /* various legacy exceptions */
23888 +       switch (cmd) {
23889 +       /* will go away when spectator is a cap */
23890 +       case VCMD_ctx_migrate_v0:
23891 +       case VCMD_ctx_migrate:
23892 +               if (id == 1) {
23893 +                       current->xid = 1;
23894 +                       ret = 1;
23895 +                       goto out;
23896 +               }
23897 +               break;
23898 +
23899 +       /* will go away when spectator is a cap */
23900 +       case VCMD_net_migrate:
23901 +               if (id == 1) {
23902 +                       current->nid = 1;
23903 +                       ret = 1;
23904 +                       goto out;
23905 +               }
23906 +               break;
23907 +       }
23908 +
23909 +       /* vcmds are fine by default */
23910 +       permit = 1;
23911 +
23912 +       /* admin type vcmds require admin ... */
23913 +       if (flags & VCF_ADMIN)
23914 +               permit = vx_check(0, VS_ADMIN) ? 1 : 0;
23915 +
23916 +       /* ... but setup type vcmds override that */
23917 +       if (!permit && (flags & VCF_SETUP))
23918 +               permit = vx_flags(VXF_STATE_SETUP, 0) ? 2 : 0;
23919 +
23920 +       state = 5;
23921 +       ret = -EPERM;
23922 +       if (!permit)
23923 +               goto out;
23924 +
23925 +       state = 6;
23926 +       if (!id && (flags & VCF_ZIDOK))
23927 +               goto skip_id;
23928 +
23929 +       ret = -ESRCH;
23930 +       if (args & VCA_VXI) {
23931 +               vxi = lookup_vx_info(id);
23932 +               if (!vxi)
23933 +                       goto out;
23934 +
23935 +               if ((flags & VCF_ADMIN) &&
23936 +                       /* special case kill for shutdown */
23937 +                       (cmd != VCMD_ctx_kill) &&
23938 +                       /* can context be administrated? */
23939 +                       !vx_info_flags(vxi, VXF_STATE_ADMIN, 0)) {
23940 +                       ret = -EACCES;
23941 +                       goto out_vxi;
23942 +               }
23943 +       }
23944 +       state = 7;
23945 +       if (args & VCA_NXI) {
23946 +               nxi = lookup_nx_info(id);
23947 +               if (!nxi)
23948 +                       goto out_vxi;
23949 +
23950 +               if ((flags & VCF_ADMIN) &&
23951 +                       /* can context be administrated? */
23952 +                       !nx_info_flags(nxi, NXF_STATE_ADMIN, 0)) {
23953 +                       ret = -EACCES;
23954 +                       goto out_nxi;
23955 +               }
23956 +       }
23957 +skip_id:
23958 +       state = 8;
23959 +       ret = do_vcmd(cmd, id, vxi, nxi, data, compat);
23960 +
23961 +out_nxi:
23962 +       if ((args & VCA_NXI) && nxi)
23963 +               put_nx_info(nxi);
23964 +out_vxi:
23965 +       if ((args & VCA_VXI) && vxi)
23966 +               put_vx_info(vxi);
23967 +out:
23968 +       vxdprintk(VXD_CBIT(switch, 1),
23969 +               "vc: VCMD_%02d_%d[%d] = %08lx(%ld) [%d,%d]",
23970 +               VC_CATEGORY(cmd), VC_COMMAND(cmd),
23971 +               VC_VERSION(cmd), ret, ret, state, permit);
23972 +       return ret;
23973 +}
23974 +
23975 +asmlinkage long
23976 +sys_vserver(uint32_t cmd, uint32_t id, void __user *data)
23977 +{
23978 +       return do_vserver(cmd, id, data, 0);
23979 +}
23980 +
23981 +#ifdef CONFIG_COMPAT
23982 +
23983 +asmlinkage long
23984 +sys32_vserver(uint32_t cmd, uint32_t id, void __user *data)
23985 +{
23986 +       return do_vserver(cmd, id, data, 1);
23987 +}
23988 +
23989 +#endif /* CONFIG_COMPAT */
23990 diff -NurpP --minimal linux-2.6.38.3/kernel/vserver/sysctl.c linux-2.6.38.3-vs2.3.0.37-rc14/kernel/vserver/sysctl.c
23991 --- linux-2.6.38.3/kernel/vserver/sysctl.c      1970-01-01 01:00:00.000000000 +0100
23992 +++ linux-2.6.38.3-vs2.3.0.37-rc14/kernel/vserver/sysctl.c      2011-01-29 02:01:07.000000000 +0100
23993 @@ -0,0 +1,241 @@
23994 +/*
23995 + *  kernel/vserver/sysctl.c
23996 + *
23997 + *  Virtual Context Support
23998 + *
23999 + *  Copyright (C) 2004-2007  Herbert Pötzl
24000 + *
24001 + *  V0.01  basic structure
24002 + *
24003 + */
24004 +
24005 +#include <linux/module.h>
24006 +#include <linux/ctype.h>
24007 +#include <linux/sysctl.h>
24008 +#include <linux/parser.h>
24009 +#include <asm/uaccess.h>
24010 +
24011 +enum {
24012 +       CTL_DEBUG_ERROR         = 0,
24013 +       CTL_DEBUG_SWITCH        = 1,
24014 +       CTL_DEBUG_XID,
24015 +       CTL_DEBUG_NID,
24016 +       CTL_DEBUG_TAG,
24017 +       CTL_DEBUG_NET,
24018 +       CTL_DEBUG_LIMIT,
24019 +       CTL_DEBUG_CRES,
24020 +       CTL_DEBUG_DLIM,
24021 +       CTL_DEBUG_QUOTA,
24022 +       CTL_DEBUG_CVIRT,
24023 +       CTL_DEBUG_SPACE,
24024 +       CTL_DEBUG_MISC,
24025 +};
24026 +
24027 +
24028 +unsigned int vx_debug_switch   = 0;
24029 +unsigned int vx_debug_xid      = 0;
24030 +unsigned int vx_debug_nid      = 0;
24031 +unsigned int vx_debug_tag      = 0;
24032 +unsigned int vx_debug_net      = 0;
24033 +unsigned int vx_debug_limit    = 0;
24034 +unsigned int vx_debug_cres     = 0;
24035 +unsigned int vx_debug_dlim     = 0;
24036 +unsigned int vx_debug_quota    = 0;
24037 +unsigned int vx_debug_cvirt    = 0;
24038 +unsigned int vx_debug_space    = 0;
24039 +unsigned int vx_debug_misc     = 0;
24040 +
24041 +
24042 +static struct ctl_table_header *vserver_table_header;
24043 +static ctl_table vserver_root_table[];
24044 +
24045 +
24046 +void vserver_register_sysctl(void)
24047 +{
24048 +       if (!vserver_table_header) {
24049 +               vserver_table_header = register_sysctl_table(vserver_root_table);
24050 +       }
24051 +
24052 +}
24053 +
24054 +void vserver_unregister_sysctl(void)
24055 +{
24056 +       if (vserver_table_header) {
24057 +               unregister_sysctl_table(vserver_table_header);
24058 +               vserver_table_header = NULL;
24059 +       }
24060 +}
24061 +
24062 +
24063 +static int proc_dodebug(ctl_table *table, int write,
24064 +       void __user *buffer, size_t *lenp, loff_t *ppos)
24065 +{
24066 +       char            tmpbuf[20], *p, c;
24067 +       unsigned int    value;
24068 +       size_t          left, len;
24069 +
24070 +       if ((*ppos && !write) || !*lenp) {
24071 +               *lenp = 0;
24072 +               return 0;
24073 +       }
24074 +
24075 +       left = *lenp;
24076 +
24077 +       if (write) {
24078 +               if (!access_ok(VERIFY_READ, buffer, left))
24079 +                       return -EFAULT;
24080 +               p = (char *)buffer;
24081 +               while (left && __get_user(c, p) >= 0 && isspace(c))
24082 +                       left--, p++;
24083 +               if (!left)
24084 +                       goto done;
24085 +
24086 +               if (left > sizeof(tmpbuf) - 1)
24087 +                       return -EINVAL;
24088 +               if (copy_from_user(tmpbuf, p, left))
24089 +                       return -EFAULT;
24090 +               tmpbuf[left] = '\0';
24091 +
24092 +               for (p = tmpbuf, value = 0; '0' <= *p && *p <= '9'; p++, left--)
24093 +                       value = 10 * value + (*p - '0');
24094 +               if (*p && !isspace(*p))
24095 +                       return -EINVAL;
24096 +               while (left && isspace(*p))
24097 +                       left--, p++;
24098 +               *(unsigned int *)table->data = value;
24099 +       } else {
24100 +               if (!access_ok(VERIFY_WRITE, buffer, left))
24101 +                       return -EFAULT;
24102 +               len = sprintf(tmpbuf, "%d", *(unsigned int *)table->data);
24103 +               if (len > left)
24104 +                       len = left;
24105 +               if (__copy_to_user(buffer, tmpbuf, len))
24106 +                       return -EFAULT;
24107 +               if ((left -= len) > 0) {
24108 +                       if (put_user('\n', (char *)buffer + len))
24109 +                               return -EFAULT;
24110 +                       left--;
24111 +               }
24112 +       }
24113 +
24114 +done:
24115 +       *lenp -= left;
24116 +       *ppos += *lenp;
24117 +       return 0;
24118 +}
24119 +
24120 +static int zero;
24121 +
24122 +#define        CTL_ENTRY(ctl, name)                            \
24123 +       {                                               \
24124 +               .procname       = #name,                \
24125 +               .data           = &vx_ ## name,         \
24126 +               .maxlen         = sizeof(int),          \
24127 +               .mode           = 0644,                 \
24128 +               .proc_handler   = &proc_dodebug,        \
24129 +               .extra1         = &zero,                \
24130 +               .extra2         = &zero,                \
24131 +       }
24132 +
24133 +static ctl_table vserver_debug_table[] = {
24134 +       CTL_ENTRY(CTL_DEBUG_SWITCH,     debug_switch),
24135 +       CTL_ENTRY(CTL_DEBUG_XID,        debug_xid),
24136 +       CTL_ENTRY(CTL_DEBUG_NID,        debug_nid),
24137 +       CTL_ENTRY(CTL_DEBUG_TAG,        debug_tag),
24138 +       CTL_ENTRY(CTL_DEBUG_NET,        debug_net),
24139 +       CTL_ENTRY(CTL_DEBUG_LIMIT,      debug_limit),
24140 +       CTL_ENTRY(CTL_DEBUG_CRES,       debug_cres),
24141 +       CTL_ENTRY(CTL_DEBUG_DLIM,       debug_dlim),
24142 +       CTL_ENTRY(CTL_DEBUG_QUOTA,      debug_quota),
24143 +       CTL_ENTRY(CTL_DEBUG_CVIRT,      debug_cvirt),
24144 +       CTL_ENTRY(CTL_DEBUG_SPACE,      debug_space),
24145 +       CTL_ENTRY(CTL_DEBUG_MISC,       debug_misc),
24146 +       { 0 }
24147 +};
24148 +
24149 +static ctl_table vserver_root_table[] = {
24150 +       {
24151 +               .procname       = "vserver",
24152 +               .mode           = 0555,
24153 +               .child          = vserver_debug_table
24154 +       },
24155 +       { 0 }
24156 +};
24157 +
24158 +
24159 +static match_table_t tokens = {
24160 +       { CTL_DEBUG_SWITCH,     "switch=%x"     },
24161 +       { CTL_DEBUG_XID,        "xid=%x"        },
24162 +       { CTL_DEBUG_NID,        "nid=%x"        },
24163 +       { CTL_DEBUG_TAG,        "tag=%x"        },
24164 +       { CTL_DEBUG_NET,        "net=%x"        },
24165 +       { CTL_DEBUG_LIMIT,      "limit=%x"      },
24166 +       { CTL_DEBUG_CRES,       "cres=%x"       },
24167 +       { CTL_DEBUG_DLIM,       "dlim=%x"       },
24168 +       { CTL_DEBUG_QUOTA,      "quota=%x"      },
24169 +       { CTL_DEBUG_CVIRT,      "cvirt=%x"      },
24170 +       { CTL_DEBUG_SPACE,      "space=%x"      },
24171 +       { CTL_DEBUG_MISC,       "misc=%x"       },
24172 +       { CTL_DEBUG_ERROR,      NULL            }
24173 +};
24174 +
24175 +#define        HANDLE_CASE(id, name, val)                              \
24176 +       case CTL_DEBUG_ ## id:                                  \
24177 +               vx_debug_ ## name = val;                        \
24178 +               printk("vs_debug_" #name "=0x%x\n", val);       \
24179 +               break
24180 +
24181 +
24182 +static int __init vs_debug_setup(char *str)
24183 +{
24184 +       char *p;
24185 +       int token;
24186 +
24187 +       printk("vs_debug_setup(%s)\n", str);
24188 +       while ((p = strsep(&str, ",")) != NULL) {
24189 +               substring_t args[MAX_OPT_ARGS];
24190 +               unsigned int value;
24191 +
24192 +               if (!*p)
24193 +                       continue;
24194 +
24195 +               token = match_token(p, tokens, args);
24196 +               value = (token > 0) ? simple_strtoul(args[0].from, NULL, 0) : 0;
24197 +
24198 +               switch (token) {
24199 +               HANDLE_CASE(SWITCH, switch, value);
24200 +               HANDLE_CASE(XID,    xid,    value);
24201 +               HANDLE_CASE(NID,    nid,    value);
24202 +               HANDLE_CASE(TAG,    tag,    value);
24203 +               HANDLE_CASE(NET,    net,    value);
24204 +               HANDLE_CASE(LIMIT,  limit,  value);
24205 +               HANDLE_CASE(CRES,   cres,   value);
24206 +               HANDLE_CASE(DLIM,   dlim,   value);
24207 +               HANDLE_CASE(QUOTA,  quota,  value);
24208 +               HANDLE_CASE(CVIRT,  cvirt,  value);
24209 +               HANDLE_CASE(SPACE,  space,  value);
24210 +               HANDLE_CASE(MISC,   misc,   value);
24211 +               default:
24212 +                       return -EINVAL;
24213 +                       break;
24214 +               }
24215 +       }
24216 +       return 1;
24217 +}
24218 +
24219 +__setup("vsdebug=", vs_debug_setup);
24220 +
24221 +
24222 +
24223 +EXPORT_SYMBOL_GPL(vx_debug_switch);
24224 +EXPORT_SYMBOL_GPL(vx_debug_xid);
24225 +EXPORT_SYMBOL_GPL(vx_debug_nid);
24226 +EXPORT_SYMBOL_GPL(vx_debug_net);
24227 +EXPORT_SYMBOL_GPL(vx_debug_limit);
24228 +EXPORT_SYMBOL_GPL(vx_debug_cres);
24229 +EXPORT_SYMBOL_GPL(vx_debug_dlim);
24230 +EXPORT_SYMBOL_GPL(vx_debug_quota);
24231 +EXPORT_SYMBOL_GPL(vx_debug_cvirt);
24232 +EXPORT_SYMBOL_GPL(vx_debug_space);
24233 +EXPORT_SYMBOL_GPL(vx_debug_misc);
24234 +
24235 diff -NurpP --minimal linux-2.6.38.3/kernel/vserver/tag.c linux-2.6.38.3-vs2.3.0.37-rc14/kernel/vserver/tag.c
24236 --- linux-2.6.38.3/kernel/vserver/tag.c 1970-01-01 01:00:00.000000000 +0100
24237 +++ linux-2.6.38.3-vs2.3.0.37-rc14/kernel/vserver/tag.c 2011-03-22 17:43:07.000000000 +0100
24238 @@ -0,0 +1,63 @@
24239 +/*
24240 + *  linux/kernel/vserver/tag.c
24241 + *
24242 + *  Virtual Server: Shallow Tag Space
24243 + *
24244 + *  Copyright (C) 2007  Herbert Pötzl
24245 + *
24246 + *  V0.01  basic implementation
24247 + *
24248 + */
24249 +
24250 +#include <linux/sched.h>
24251 +#include <linux/vserver/debug.h>
24252 +#include <linux/vs_pid.h>
24253 +#include <linux/vs_tag.h>
24254 +
24255 +#include <linux/vserver/tag_cmd.h>
24256 +
24257 +
24258 +int dx_migrate_task(struct task_struct *p, tag_t tag)
24259 +{
24260 +       if (!p)
24261 +               BUG();
24262 +
24263 +       vxdprintk(VXD_CBIT(tag, 5),
24264 +               "dx_migrate_task(%p[#%d],#%d)", p, p->tag, tag);
24265 +
24266 +       task_lock(p);
24267 +       p->tag = tag;
24268 +       task_unlock(p);
24269 +
24270 +       vxdprintk(VXD_CBIT(tag, 5),
24271 +               "moved task %p into [#%d]", p, tag);
24272 +       return 0;
24273 +}
24274 +
24275 +/* vserver syscall commands below here */
24276 +
24277 +/* taks xid and vx_info functions */
24278 +
24279 +
24280 +int vc_task_tag(uint32_t id)
24281 +{
24282 +       tag_t tag;
24283 +
24284 +       if (id) {
24285 +               struct task_struct *tsk;
24286 +               rcu_read_lock();
24287 +               tsk = find_task_by_real_pid(id);
24288 +               tag = (tsk) ? tsk->tag : -ESRCH;
24289 +               rcu_read_unlock();
24290 +       } else
24291 +               tag = dx_current_tag();
24292 +       return tag;
24293 +}
24294 +
24295 +
24296 +int vc_tag_migrate(uint32_t tag)
24297 +{
24298 +       return dx_migrate_task(current, tag & 0xFFFF);
24299 +}
24300 +
24301 +
24302 diff -NurpP --minimal linux-2.6.38.3/kernel/vserver/vci_config.h linux-2.6.38.3-vs2.3.0.37-rc14/kernel/vserver/vci_config.h
24303 --- linux-2.6.38.3/kernel/vserver/vci_config.h  1970-01-01 01:00:00.000000000 +0100
24304 +++ linux-2.6.38.3-vs2.3.0.37-rc14/kernel/vserver/vci_config.h  2011-04-15 16:25:52.000000000 +0200
24305 @@ -0,0 +1,76 @@
24306 +
24307 +/*  interface version */
24308 +
24309 +#define VCI_VERSION            0x00020308
24310 +
24311 +
24312 +enum {
24313 +       VCI_KCBIT_NO_DYNAMIC = 0,
24314 +
24315 +       VCI_KCBIT_PROC_SECURE = 4,
24316 +       /* VCI_KCBIT_HARDCPU = 5, */
24317 +       /* VCI_KCBIT_IDLELIMIT = 6, */
24318 +       /* VCI_KCBIT_IDLETIME = 7, */
24319 +
24320 +       VCI_KCBIT_COWBL = 8,
24321 +       VCI_KCBIT_FULLCOWBL = 9,
24322 +       VCI_KCBIT_SPACES = 10,
24323 +       VCI_KCBIT_NETV2 = 11,
24324 +       VCI_KCBIT_MEMCG = 12,
24325 +
24326 +       VCI_KCBIT_DEBUG = 16,
24327 +       VCI_KCBIT_HISTORY = 20,
24328 +       VCI_KCBIT_TAGGED = 24,
24329 +       VCI_KCBIT_PPTAG = 28,
24330 +
24331 +       VCI_KCBIT_MORE = 31,
24332 +};
24333 +
24334 +
24335 +static inline uint32_t vci_kernel_config(void)
24336 +{
24337 +       return
24338 +       (1 << VCI_KCBIT_NO_DYNAMIC) |
24339 +
24340 +       /* configured features */
24341 +#ifdef CONFIG_VSERVER_PROC_SECURE
24342 +       (1 << VCI_KCBIT_PROC_SECURE) |
24343 +#endif
24344 +#ifdef CONFIG_VSERVER_COWBL
24345 +       (1 << VCI_KCBIT_COWBL) |
24346 +       (1 << VCI_KCBIT_FULLCOWBL) |
24347 +#endif
24348 +       (1 << VCI_KCBIT_SPACES) |
24349 +       (1 << VCI_KCBIT_NETV2) |
24350 +#ifdef CONFIG_CGROUP_MEM_RES_CTLR
24351 +       (1 << VCI_KCBIT_MEMCG) |
24352 +#endif
24353 +
24354 +       /* debug options */
24355 +#ifdef CONFIG_VSERVER_DEBUG
24356 +       (1 << VCI_KCBIT_DEBUG) |
24357 +#endif
24358 +#ifdef CONFIG_VSERVER_HISTORY
24359 +       (1 << VCI_KCBIT_HISTORY) |
24360 +#endif
24361 +
24362 +       /* inode context tagging */
24363 +#if    defined(CONFIG_TAGGING_NONE)
24364 +       (0 << VCI_KCBIT_TAGGED) |
24365 +#elif  defined(CONFIG_TAGGING_UID16)
24366 +       (1 << VCI_KCBIT_TAGGED) |
24367 +#elif  defined(CONFIG_TAGGING_GID16)
24368 +       (2 << VCI_KCBIT_TAGGED) |
24369 +#elif  defined(CONFIG_TAGGING_ID24)
24370 +       (3 << VCI_KCBIT_TAGGED) |
24371 +#elif  defined(CONFIG_TAGGING_INTERN)
24372 +       (4 << VCI_KCBIT_TAGGED) |
24373 +#elif  defined(CONFIG_TAGGING_RUNTIME)
24374 +       (5 << VCI_KCBIT_TAGGED) |
24375 +#else
24376 +       (7 << VCI_KCBIT_TAGGED) |
24377 +#endif
24378 +       (1 << VCI_KCBIT_PPTAG) |
24379 +       0;
24380 +}
24381 +
24382 diff -NurpP --minimal linux-2.6.38.3/mm/filemap_xip.c linux-2.6.38.3-vs2.3.0.37-rc14/mm/filemap_xip.c
24383 --- linux-2.6.38.3/mm/filemap_xip.c     2010-07-07 18:31:58.000000000 +0200
24384 +++ linux-2.6.38.3-vs2.3.0.37-rc14/mm/filemap_xip.c     2011-01-29 02:01:07.000000000 +0100
24385 @@ -18,6 +18,7 @@
24386  #include <linux/seqlock.h>
24387  #include <linux/mutex.h>
24388  #include <linux/gfp.h>
24389 +#include <linux/vs_memory.h>
24390  #include <asm/tlbflush.h>
24391  #include <asm/io.h>
24392  
24393 diff -NurpP --minimal linux-2.6.38.3/mm/fremap.c linux-2.6.38.3-vs2.3.0.37-rc14/mm/fremap.c
24394 --- linux-2.6.38.3/mm/fremap.c  2010-10-21 13:07:57.000000000 +0200
24395 +++ linux-2.6.38.3-vs2.3.0.37-rc14/mm/fremap.c  2011-01-29 02:01:07.000000000 +0100
24396 @@ -16,6 +16,7 @@
24397  #include <linux/module.h>
24398  #include <linux/syscalls.h>
24399  #include <linux/mmu_notifier.h>
24400 +#include <linux/vs_memory.h>
24401  
24402  #include <asm/mmu_context.h>
24403  #include <asm/cacheflush.h>
24404 diff -NurpP --minimal linux-2.6.38.3/mm/hugetlb.c linux-2.6.38.3-vs2.3.0.37-rc14/mm/hugetlb.c
24405 --- linux-2.6.38.3/mm/hugetlb.c 2011-03-15 18:07:42.000000000 +0100
24406 +++ linux-2.6.38.3-vs2.3.0.37-rc14/mm/hugetlb.c 2011-01-29 02:01:07.000000000 +0100
24407 @@ -28,6 +28,7 @@
24408  
24409  #include <linux/hugetlb.h>
24410  #include <linux/node.h>
24411 +#include <linux/vs_memory.h>
24412  #include "internal.h"
24413  
24414  const unsigned long hugetlb_zero = 0, hugetlb_infinity = ~0UL;
24415 diff -NurpP --minimal linux-2.6.38.3/mm/memcontrol.c linux-2.6.38.3-vs2.3.0.37-rc14/mm/memcontrol.c
24416 --- linux-2.6.38.3/mm/memcontrol.c      2011-03-15 18:07:42.000000000 +0100
24417 +++ linux-2.6.38.3-vs2.3.0.37-rc14/mm/memcontrol.c      2011-02-17 02:17:51.000000000 +0100
24418 @@ -681,6 +681,31 @@ struct mem_cgroup *mem_cgroup_from_task(
24419                                 struct mem_cgroup, css);
24420  }
24421  
24422 +u64 mem_cgroup_res_read_u64(struct mem_cgroup *mem, int member)
24423 +{
24424 +       return res_counter_read_u64(&mem->res, member);
24425 +}
24426 +
24427 +u64 mem_cgroup_memsw_read_u64(struct mem_cgroup *mem, int member)
24428 +{
24429 +       return res_counter_read_u64(&mem->memsw, member);
24430 +}
24431 +
24432 +s64 mem_cgroup_stat_read_cache(struct mem_cgroup *mem)
24433 +{
24434 +       return mem_cgroup_read_stat(mem, MEM_CGROUP_STAT_CACHE);
24435 +}
24436 +
24437 +s64 mem_cgroup_stat_read_anon(struct mem_cgroup *mem)
24438 +{
24439 +       return mem_cgroup_read_stat(mem, MEM_CGROUP_STAT_RSS);
24440 +}
24441 +
24442 +s64 mem_cgroup_stat_read_mapped(struct mem_cgroup *mem)
24443 +{
24444 +       return mem_cgroup_read_stat(mem, MEM_CGROUP_STAT_FILE_MAPPED);
24445 +}
24446 +
24447  static struct mem_cgroup *try_get_mem_cgroup_from_mm(struct mm_struct *mm)
24448  {
24449         struct mem_cgroup *mem = NULL;
24450 diff -NurpP --minimal linux-2.6.38.3/mm/memory.c linux-2.6.38.3-vs2.3.0.37-rc14/mm/memory.c
24451 --- linux-2.6.38.3/mm/memory.c  2011-03-15 18:07:42.000000000 +0100
24452 +++ linux-2.6.38.3-vs2.3.0.37-rc14/mm/memory.c  2011-03-07 16:53:28.000000000 +0100
24453 @@ -3225,6 +3225,7 @@ int handle_pte_fault(struct mm_struct *m
24454  {
24455         pte_t entry;
24456         spinlock_t *ptl;
24457 +       int ret = 0, type = VXPT_UNKNOWN;
24458  
24459         entry = *pte;
24460         if (!pte_present(entry)) {
24461 @@ -3249,9 +3250,12 @@ int handle_pte_fault(struct mm_struct *m
24462         if (unlikely(!pte_same(*pte, entry)))
24463                 goto unlock;
24464         if (flags & FAULT_FLAG_WRITE) {
24465 -               if (!pte_write(entry))
24466 -                       return do_wp_page(mm, vma, address,
24467 +               if (!pte_write(entry)) {
24468 +                       ret = do_wp_page(mm, vma, address,
24469                                         pte, pmd, ptl, entry);
24470 +                       type = VXPT_WRITE;
24471 +                       goto out;
24472 +               }
24473                 entry = pte_mkdirty(entry);
24474         }
24475         entry = pte_mkyoung(entry);
24476 @@ -3269,7 +3273,10 @@ int handle_pte_fault(struct mm_struct *m
24477         }
24478  unlock:
24479         pte_unmap_unlock(pte, ptl);
24480 -       return 0;
24481 +       ret = 0;
24482 +out:
24483 +       vx_page_fault(mm, vma, type, ret);
24484 +       return ret;
24485  }
24486  
24487  /*
24488 diff -NurpP --minimal linux-2.6.38.3/mm/mremap.c linux-2.6.38.3-vs2.3.0.37-rc14/mm/mremap.c
24489 --- linux-2.6.38.3/mm/mremap.c  2011-04-15 10:30:30.000000000 +0200
24490 +++ linux-2.6.38.3-vs2.3.0.37-rc14/mm/mremap.c  2011-04-15 10:33:41.000000000 +0200
24491 @@ -19,6 +19,7 @@
24492  #include <linux/security.h>
24493  #include <linux/syscalls.h>
24494  #include <linux/mmu_notifier.h>
24495 +#include <linux/vs_memory.h>
24496  
24497  #include <asm/uaccess.h>
24498  #include <asm/cacheflush.h>
24499 diff -NurpP --minimal linux-2.6.38.3/mm/oom_kill.c linux-2.6.38.3-vs2.3.0.37-rc14/mm/oom_kill.c
24500 --- linux-2.6.38.3/mm/oom_kill.c        2011-04-15 10:30:30.000000000 +0200
24501 +++ linux-2.6.38.3-vs2.3.0.37-rc14/mm/oom_kill.c        2011-03-28 15:00:55.000000000 +0200
24502 @@ -32,6 +32,9 @@
24503  #include <linux/mempolicy.h>
24504  #include <linux/security.h>
24505  #include <linux/ptrace.h>
24506 +#include <linux/reboot.h>
24507 +#include <linux/vs_memory.h>
24508 +#include <linux/vs_context.h>
24509  
24510  int sysctl_panic_on_oom;
24511  int sysctl_oom_kill_allocating_task;
24512 @@ -125,11 +128,18 @@ struct task_struct *find_lock_task_mm(st
24513  static bool oom_unkillable_task(struct task_struct *p,
24514                 const struct mem_cgroup *mem, const nodemask_t *nodemask)
24515  {
24516 -       if (is_global_init(p))
24517 +       unsigned xid = vx_current_xid();
24518 +
24519 +       /* skip the init task, global and per guest */
24520 +       if (task_is_init(p))
24521                 return true;
24522         if (p->flags & PF_KTHREAD)
24523                 return true;
24524  
24525 +       /* skip other guest and host processes if oom in guest */
24526 +       if (xid && vx_task_xid(p) != xid)
24527 +               return true;
24528 +
24529         /* When mem_cgroup_out_of_memory() and p is not member of the group */
24530         if (mem && !task_in_mem_cgroup(p, mem))
24531                 return true;
24532 @@ -211,6 +221,18 @@ unsigned int oom_badness(struct task_str
24533         points += p->signal->oom_score_adj;
24534  
24535         /*
24536 +        * add points for context badness and
24537 +        * reduce badness for processes belonging to
24538 +        * a different context
24539 +        */
24540 +
24541 +       points += vx_badness(p, p->mm);
24542 +
24543 +       if ((vx_current_xid() > 1) &&
24544 +               vx_current_xid() != vx_task_xid(p))
24545 +               points /= 16;
24546 +
24547 +       /*
24548          * Never return 0 for an eligible task that may be killed since it's
24549          * possible that no single user task uses more than 0.1% of memory and
24550          * no single admin tasks uses more than 3.0%.
24551 @@ -424,8 +446,8 @@ static int oom_kill_task(struct task_str
24552         /* mm cannot be safely dereferenced after task_unlock(p) */
24553         mm = p->mm;
24554  
24555 -       pr_err("Killed process %d (%s) total-vm:%lukB, anon-rss:%lukB, file-rss:%lukB\n",
24556 -               task_pid_nr(p), p->comm, K(p->mm->total_vm),
24557 +       pr_err("Killed process %d:#%u (%s) total-vm:%lukB, anon-rss:%lukB, file-rss:%lukB\n",
24558 +               task_pid_nr(p), p->xid, p->comm, K(p->mm->total_vm),
24559                 K(get_mm_counter(p->mm, MM_ANONPAGES)),
24560                 K(get_mm_counter(p->mm, MM_FILEPAGES)));
24561         task_unlock(p);
24562 @@ -487,8 +509,8 @@ static int oom_kill_process(struct task_
24563         }
24564  
24565         task_lock(p);
24566 -       pr_err("%s: Kill process %d (%s) score %d or sacrifice child\n",
24567 -               message, task_pid_nr(p), p->comm, points);
24568 +       pr_err("%s: Kill process %d:#%u (%s) score %d or sacrifice child\n",
24569 +               message, task_pid_nr(p), p->xid, p->comm, points);
24570         task_unlock(p);
24571  
24572         /*
24573 @@ -579,6 +601,8 @@ int unregister_oom_notifier(struct notif
24574  }
24575  EXPORT_SYMBOL_GPL(unregister_oom_notifier);
24576  
24577 +long vs_oom_action(unsigned int);
24578 +
24579  /*
24580   * Try to acquire the OOM killer lock for the zones in zonelist.  Returns zero
24581   * if a parallel OOM killing is already taking place that includes a zone in
24582 @@ -738,7 +762,12 @@ retry:
24583         if (!p) {
24584                 dump_header(NULL, gfp_mask, order, NULL, mpol_mask);
24585                 read_unlock(&tasklist_lock);
24586 -               panic("Out of memory and no killable processes...\n");
24587 +
24588 +               /* avoid panic for guest OOM */
24589 +               if (current->xid)
24590 +                       vs_oom_action(LINUX_REBOOT_CMD_OOM);
24591 +               else
24592 +                       panic("Out of memory and no killable processes...\n");
24593         }
24594  
24595         if (oom_kill_process(p, gfp_mask, order, points, totalpages, NULL,
24596 diff -NurpP --minimal linux-2.6.38.3/mm/page_alloc.c linux-2.6.38.3-vs2.3.0.37-rc14/mm/page_alloc.c
24597 --- linux-2.6.38.3/mm/page_alloc.c      2011-04-15 10:30:30.000000000 +0200
24598 +++ linux-2.6.38.3-vs2.3.0.37-rc14/mm/page_alloc.c      2011-03-28 15:00:14.000000000 +0200
24599 @@ -53,6 +53,8 @@
24600  #include <linux/compaction.h>
24601  #include <trace/events/kmem.h>
24602  #include <linux/ftrace_event.h>
24603 +#include <linux/vs_base.h>
24604 +#include <linux/vs_limit.h>
24605  
24606  #include <asm/tlbflush.h>
24607  #include <asm/div64.h>
24608 @@ -2388,6 +2390,9 @@ void si_meminfo(struct sysinfo *val)
24609         val->totalhigh = totalhigh_pages;
24610         val->freehigh = nr_free_highpages();
24611         val->mem_unit = PAGE_SIZE;
24612 +
24613 +       if (vx_flags(VXF_VIRT_MEM, 0))
24614 +               vx_vsi_meminfo(val);
24615  }
24616  
24617  EXPORT_SYMBOL(si_meminfo);
24618 @@ -2408,6 +2413,9 @@ void si_meminfo_node(struct sysinfo *val
24619         val->freehigh = 0;
24620  #endif
24621         val->mem_unit = PAGE_SIZE;
24622 +
24623 +       if (vx_flags(VXF_VIRT_MEM, 0))
24624 +               vx_vsi_meminfo(val);
24625  }
24626  #endif
24627  
24628 diff -NurpP --minimal linux-2.6.38.3/mm/pgtable-generic.c linux-2.6.38.3-vs2.3.0.37-rc14/mm/pgtable-generic.c
24629 --- linux-2.6.38.3/mm/pgtable-generic.c 2011-03-15 18:07:42.000000000 +0100
24630 +++ linux-2.6.38.3-vs2.3.0.37-rc14/mm/pgtable-generic.c 2011-02-02 22:20:27.000000000 +0100
24631 @@ -6,6 +6,8 @@
24632   *  Copyright (C) 2010  Linus Torvalds
24633   */
24634  
24635 +#include <linux/mm.h>
24636 +
24637  #include <linux/pagemap.h>
24638  #include <asm/tlb.h>
24639  #include <asm-generic/pgtable.h>
24640 diff -NurpP --minimal linux-2.6.38.3/mm/rmap.c linux-2.6.38.3-vs2.3.0.37-rc14/mm/rmap.c
24641 --- linux-2.6.38.3/mm/rmap.c    2011-03-15 18:07:42.000000000 +0100
24642 +++ linux-2.6.38.3-vs2.3.0.37-rc14/mm/rmap.c    2011-03-15 18:15:06.000000000 +0100
24643 @@ -57,6 +57,7 @@
24644  #include <linux/mmu_notifier.h>
24645  #include <linux/migrate.h>
24646  #include <linux/hugetlb.h>
24647 +#include <linux/vs_memory.h>
24648  
24649  #include <asm/tlbflush.h>
24650  
24651 diff -NurpP --minimal linux-2.6.38.3/mm/shmem.c linux-2.6.38.3-vs2.3.0.37-rc14/mm/shmem.c
24652 --- linux-2.6.38.3/mm/shmem.c   2011-04-15 10:30:30.000000000 +0200
24653 +++ linux-2.6.38.3-vs2.3.0.37-rc14/mm/shmem.c   2011-03-28 15:00:14.000000000 +0200
24654 @@ -1816,7 +1816,7 @@ static int shmem_statfs(struct dentry *d
24655  {
24656         struct shmem_sb_info *sbinfo = SHMEM_SB(dentry->d_sb);
24657  
24658 -       buf->f_type = TMPFS_MAGIC;
24659 +       buf->f_type = TMPFS_SUPER_MAGIC;
24660         buf->f_bsize = PAGE_CACHE_SIZE;
24661         buf->f_namelen = NAME_MAX;
24662         if (sbinfo->max_blocks) {
24663 @@ -2378,7 +2378,7 @@ int shmem_fill_super(struct super_block 
24664         sb->s_maxbytes = SHMEM_MAX_BYTES;
24665         sb->s_blocksize = PAGE_CACHE_SIZE;
24666         sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
24667 -       sb->s_magic = TMPFS_MAGIC;
24668 +       sb->s_magic = TMPFS_SUPER_MAGIC;
24669         sb->s_op = &shmem_ops;
24670         sb->s_time_gran = 1;
24671  #ifdef CONFIG_TMPFS_POSIX_ACL
24672 diff -NurpP --minimal linux-2.6.38.3/mm/slab.c linux-2.6.38.3-vs2.3.0.37-rc14/mm/slab.c
24673 --- linux-2.6.38.3/mm/slab.c    2011-04-15 10:30:30.000000000 +0200
24674 +++ linux-2.6.38.3-vs2.3.0.37-rc14/mm/slab.c    2011-03-28 15:00:14.000000000 +0200
24675 @@ -407,6 +407,8 @@ static void kmem_list3_init(struct kmem_
24676  #define STATS_INC_FREEMISS(x)  do { } while (0)
24677  #endif
24678  
24679 +#include "slab_vs.h"
24680 +
24681  #if DEBUG
24682  
24683  /*
24684 @@ -3346,6 +3348,7 @@ retry:
24685  
24686         obj = slab_get_obj(cachep, slabp, nodeid);
24687         check_slabp(cachep, slabp);
24688 +       vx_slab_alloc(cachep, flags);
24689         l3->free_objects--;
24690         /* move slabp to correct slabp list: */
24691         list_del(&slabp->list);
24692 @@ -3423,6 +3426,7 @@ __cache_alloc_node(struct kmem_cache *ca
24693         /* ___cache_alloc_node can fall back to other nodes */
24694         ptr = ____cache_alloc_node(cachep, flags, nodeid);
24695    out:
24696 +       vx_slab_alloc(cachep, flags);
24697         local_irq_restore(save_flags);
24698         ptr = cache_alloc_debugcheck_after(cachep, flags, ptr, caller);
24699         kmemleak_alloc_recursive(ptr, obj_size(cachep), 1, cachep->flags,
24700 @@ -3609,6 +3613,7 @@ static inline void __cache_free(struct k
24701         check_irq_off();
24702         kmemleak_free_recursive(objp, cachep->flags);
24703         objp = cache_free_debugcheck(cachep, objp, __builtin_return_address(0));
24704 +       vx_slab_free(cachep);
24705  
24706         kmemcheck_slab_free(cachep, objp, obj_size(cachep));
24707  
24708 diff -NurpP --minimal linux-2.6.38.3/mm/slab_vs.h linux-2.6.38.3-vs2.3.0.37-rc14/mm/slab_vs.h
24709 --- linux-2.6.38.3/mm/slab_vs.h 1970-01-01 01:00:00.000000000 +0100
24710 +++ linux-2.6.38.3-vs2.3.0.37-rc14/mm/slab_vs.h 2011-01-29 02:01:07.000000000 +0100
24711 @@ -0,0 +1,29 @@
24712 +
24713 +#include <linux/vserver/context.h>
24714 +
24715 +#include <linux/vs_context.h>
24716 +
24717 +static inline
24718 +void vx_slab_alloc(struct kmem_cache *cachep, gfp_t flags)
24719 +{
24720 +       int what = gfp_zone(cachep->gfpflags);
24721 +       struct vx_info *vxi = current_vx_info();
24722 +
24723 +       if (!vxi)
24724 +               return;
24725 +
24726 +       atomic_add(cachep->buffer_size, &vxi->cacct.slab[what]);
24727 +}
24728 +
24729 +static inline
24730 +void vx_slab_free(struct kmem_cache *cachep)
24731 +{
24732 +       int what = gfp_zone(cachep->gfpflags);
24733 +       struct vx_info *vxi = current_vx_info();
24734 +
24735 +       if (!vxi)
24736 +               return;
24737 +
24738 +       atomic_sub(cachep->buffer_size, &vxi->cacct.slab[what]);
24739 +}
24740 +
24741 diff -NurpP --minimal linux-2.6.38.3/mm/swapfile.c linux-2.6.38.3-vs2.3.0.37-rc14/mm/swapfile.c
24742 --- linux-2.6.38.3/mm/swapfile.c        2011-04-15 10:30:30.000000000 +0200
24743 +++ linux-2.6.38.3-vs2.3.0.37-rc14/mm/swapfile.c        2011-03-28 15:00:14.000000000 +0200
24744 @@ -36,6 +36,8 @@
24745  #include <asm/tlbflush.h>
24746  #include <linux/swapops.h>
24747  #include <linux/page_cgroup.h>
24748 +#include <linux/vs_base.h>
24749 +#include <linux/vs_memory.h>
24750  
24751  static bool swap_count_continued(struct swap_info_struct *, pgoff_t,
24752                                  unsigned char);
24753 @@ -1775,6 +1777,16 @@ static int swap_show(struct seq_file *sw
24754  
24755         if (si == SEQ_START_TOKEN) {
24756                 seq_puts(swap,"Filename\t\t\t\tType\t\tSize\tUsed\tPriority\n");
24757 +               if (vx_flags(VXF_VIRT_MEM, 0)) {
24758 +                       struct sysinfo si;
24759 +
24760 +                       vx_vsi_swapinfo(&si);
24761 +                       if (si.totalswap < (1 << 10))
24762 +                               return 0;
24763 +                       seq_printf(swap, "%s\t\t\t\t\t%s\t%lu\t%lu\t%d\n",
24764 +                               "hdv0", "partition", si.totalswap >> 10,
24765 +                               (si.totalswap - si.freeswap) >> 10, -1);
24766 +               }
24767                 return 0;
24768         }
24769  
24770 @@ -2186,6 +2198,8 @@ void si_swapinfo(struct sysinfo *val)
24771         val->freeswap = nr_swap_pages + nr_to_be_unused;
24772         val->totalswap = total_swap_pages + nr_to_be_unused;
24773         spin_unlock(&swap_lock);
24774 +       if (vx_flags(VXF_VIRT_MEM, 0))
24775 +               vx_vsi_swapinfo(val);
24776  }
24777  
24778  /*
24779 diff -NurpP --minimal linux-2.6.38.3/net/bridge/br_multicast.c linux-2.6.38.3-vs2.3.0.37-rc14/net/bridge/br_multicast.c
24780 --- linux-2.6.38.3/net/bridge/br_multicast.c    2011-03-15 18:07:44.000000000 +0100
24781 +++ linux-2.6.38.3-vs2.3.0.37-rc14/net/bridge/br_multicast.c    2011-03-10 16:51:08.000000000 +0100
24782 @@ -446,7 +446,7 @@ static struct sk_buff *br_ip6_multicast_
24783         ip6h->hop_limit = 1;
24784         ipv6_addr_set(&ip6h->daddr, htonl(0xff020000), 0, 0, htonl(1));
24785         ipv6_dev_get_saddr(dev_net(br->dev), br->dev, &ip6h->daddr, 0,
24786 -                          &ip6h->saddr);
24787 +                          &ip6h->saddr, NULL);
24788         ipv6_eth_mc_map(&ip6h->daddr, eth->h_dest);
24789  
24790         hopopt = (u8 *)(ip6h + 1);
24791 diff -NurpP --minimal linux-2.6.38.3/net/core/dev.c linux-2.6.38.3-vs2.3.0.37-rc14/net/core/dev.c
24792 --- linux-2.6.38.3/net/core/dev.c       2011-03-15 18:07:44.000000000 +0100
24793 +++ linux-2.6.38.3-vs2.3.0.37-rc14/net/core/dev.c       2011-03-15 18:15:06.000000000 +0100
24794 @@ -127,6 +127,7 @@
24795  #include <linux/in.h>
24796  #include <linux/jhash.h>
24797  #include <linux/random.h>
24798 +#include <linux/vs_inet.h>
24799  #include <trace/events/napi.h>
24800  #include <trace/events/net.h>
24801  #include <trace/events/skb.h>
24802 @@ -608,7 +609,8 @@ struct net_device *__dev_get_by_name(str
24803         struct hlist_head *head = dev_name_hash(net, name);
24804  
24805         hlist_for_each_entry(dev, p, head, name_hlist)
24806 -               if (!strncmp(dev->name, name, IFNAMSIZ))
24807 +               if (!strncmp(dev->name, name, IFNAMSIZ) &&
24808 +                   nx_dev_visible(current_nx_info(), dev))
24809                         return dev;
24810  
24811         return NULL;
24812 @@ -634,7 +636,8 @@ struct net_device *dev_get_by_name_rcu(s
24813         struct hlist_head *head = dev_name_hash(net, name);
24814  
24815         hlist_for_each_entry_rcu(dev, p, head, name_hlist)
24816 -               if (!strncmp(dev->name, name, IFNAMSIZ))
24817 +               if (!strncmp(dev->name, name, IFNAMSIZ) &&
24818 +                   nx_dev_visible(current_nx_info(), dev))
24819                         return dev;
24820  
24821         return NULL;
24822 @@ -685,7 +688,8 @@ struct net_device *__dev_get_by_index(st
24823         struct hlist_head *head = dev_index_hash(net, ifindex);
24824  
24825         hlist_for_each_entry(dev, p, head, index_hlist)
24826 -               if (dev->ifindex == ifindex)
24827 +               if ((dev->ifindex == ifindex) &&
24828 +                   nx_dev_visible(current_nx_info(), dev))
24829                         return dev;
24830  
24831         return NULL;
24832 @@ -710,7 +714,8 @@ struct net_device *dev_get_by_index_rcu(
24833         struct hlist_head *head = dev_index_hash(net, ifindex);
24834  
24835         hlist_for_each_entry_rcu(dev, p, head, index_hlist)
24836 -               if (dev->ifindex == ifindex)
24837 +               if ((dev->ifindex == ifindex) &&
24838 +                   nx_dev_visible(current_nx_info(), dev))
24839                         return dev;
24840  
24841         return NULL;
24842 @@ -763,7 +768,8 @@ struct net_device *dev_getbyhwaddr_rcu(s
24843  
24844         for_each_netdev_rcu(net, dev)
24845                 if (dev->type == type &&
24846 -                   !memcmp(dev->dev_addr, ha, dev->addr_len))
24847 +                   !memcmp(dev->dev_addr, ha, dev->addr_len) &&
24848 +                   nx_dev_visible(current_nx_info(), dev))
24849                         return dev;
24850  
24851         return NULL;
24852 @@ -775,9 +781,11 @@ struct net_device *__dev_getfirstbyhwtyp
24853         struct net_device *dev;
24854  
24855         ASSERT_RTNL();
24856 -       for_each_netdev(net, dev)
24857 -               if (dev->type == type)
24858 +       for_each_netdev(net, dev) {
24859 +               if ((dev->type == type) &&
24860 +                   nx_dev_visible(current_nx_info(), dev))
24861                         return dev;
24862 +       }
24863  
24864         return NULL;
24865  }
24866 @@ -895,6 +903,8 @@ static int __dev_alloc_name(struct net *
24867                                 continue;
24868                         if (i < 0 || i >= max_netdevices)
24869                                 continue;
24870 +                       if (!nx_dev_visible(current_nx_info(), d))
24871 +                               continue;
24872  
24873                         /*  avoid cases where sscanf is not exact inverse of printf */
24874                         snprintf(buf, IFNAMSIZ, name, i);
24875 @@ -3873,6 +3883,8 @@ static int dev_ifconf(struct net *net, c
24876  
24877         total = 0;
24878         for_each_netdev(net, dev) {
24879 +               if (!nx_dev_visible(current_nx_info(), dev))
24880 +                       continue;
24881                 for (i = 0; i < NPROTO; i++) {
24882                         if (gifconf_list[i]) {
24883                                 int done;
24884 @@ -3944,6 +3956,10 @@ static void dev_seq_printf_stats(struct 
24885         struct rtnl_link_stats64 temp;
24886         const struct rtnl_link_stats64 *stats = dev_get_stats(dev, &temp);
24887  
24888 +       /* device visible inside network context? */
24889 +       if (!nx_dev_visible(current_nx_info(), dev))
24890 +               return;
24891 +
24892         seq_printf(seq, "%6s: %7llu %7llu %4llu %4llu %4llu %5llu %10llu %9llu "
24893                    "%8llu %7llu %4llu %4llu %4llu %5llu %7llu %10llu\n",
24894                    dev->name, stats->rx_bytes, stats->rx_packets,
24895 diff -NurpP --minimal linux-2.6.38.3/net/core/rtnetlink.c linux-2.6.38.3-vs2.3.0.37-rc14/net/core/rtnetlink.c
24896 --- linux-2.6.38.3/net/core/rtnetlink.c 2011-03-15 18:07:44.000000000 +0100
24897 +++ linux-2.6.38.3-vs2.3.0.37-rc14/net/core/rtnetlink.c 2011-02-17 02:17:52.000000000 +0100
24898 @@ -1012,6 +1012,8 @@ static int rtnl_dump_ifinfo(struct sk_bu
24899                 hlist_for_each_entry(dev, node, head, index_hlist) {
24900                         if (idx < s_idx)
24901                                 goto cont;
24902 +                       if (!nx_dev_visible(skb->sk->sk_nx_info, dev))
24903 +                               continue;
24904                         if (rtnl_fill_ifinfo(skb, dev, RTM_NEWLINK,
24905                                              NETLINK_CB(cb->skb).pid,
24906                                              cb->nlh->nlmsg_seq, 0,
24907 @@ -1771,6 +1773,9 @@ void rtmsg_ifinfo(int type, struct net_d
24908         struct sk_buff *skb;
24909         int err = -ENOBUFS;
24910  
24911 +       if (!nx_dev_visible(current_nx_info(), dev))
24912 +               return;
24913 +
24914         skb = nlmsg_new(if_nlmsg_size(dev), GFP_KERNEL);
24915         if (skb == NULL)
24916                 goto errout;
24917 diff -NurpP --minimal linux-2.6.38.3/net/core/sock.c linux-2.6.38.3-vs2.3.0.37-rc14/net/core/sock.c
24918 --- linux-2.6.38.3/net/core/sock.c      2011-03-15 18:07:44.000000000 +0100
24919 +++ linux-2.6.38.3-vs2.3.0.37-rc14/net/core/sock.c      2011-01-29 02:01:07.000000000 +0100
24920 @@ -127,6 +127,10 @@
24921  #include <net/cls_cgroup.h>
24922  
24923  #include <linux/filter.h>
24924 +#include <linux/vs_socket.h>
24925 +#include <linux/vs_limit.h>
24926 +#include <linux/vs_context.h>
24927 +#include <linux/vs_network.h>
24928  
24929  #ifdef CONFIG_INET
24930  #include <net/tcp.h>
24931 @@ -1070,6 +1074,8 @@ static struct sock *sk_prot_alloc(struct
24932                         goto out_free_sec;
24933                 sk_tx_queue_clear(sk);
24934         }
24935 +               sock_vx_init(sk);
24936 +               sock_nx_init(sk);
24937  
24938         return sk;
24939  
24940 @@ -1169,6 +1175,11 @@ static void __sk_free(struct sock *sk)
24941                 put_cred(sk->sk_peer_cred);
24942         put_pid(sk->sk_peer_pid);
24943         put_net(sock_net(sk));
24944 +       vx_sock_dec(sk);
24945 +       clr_vx_info(&sk->sk_vx_info);
24946 +       sk->sk_xid = -1;
24947 +       clr_nx_info(&sk->sk_nx_info);
24948 +       sk->sk_nid = -1;
24949         sk_prot_free(sk->sk_prot_creator, sk);
24950  }
24951  
24952 @@ -1216,6 +1227,8 @@ struct sock *sk_clone(const struct sock 
24953  
24954                 /* SANITY */
24955                 get_net(sock_net(newsk));
24956 +               sock_vx_init(newsk);
24957 +               sock_nx_init(newsk);
24958                 sk_node_init(&newsk->sk_node);
24959                 sock_lock_init(newsk);
24960                 bh_lock_sock(newsk);
24961 @@ -1271,6 +1284,12 @@ struct sock *sk_clone(const struct sock 
24962                 smp_wmb();
24963                 atomic_set(&newsk->sk_refcnt, 2);
24964  
24965 +               set_vx_info(&newsk->sk_vx_info, sk->sk_vx_info);
24966 +               newsk->sk_xid = sk->sk_xid;
24967 +               vx_sock_inc(newsk);
24968 +               set_nx_info(&newsk->sk_nx_info, sk->sk_nx_info);
24969 +               newsk->sk_nid = sk->sk_nid;
24970 +
24971                 /*
24972                  * Increment the counter in the same struct proto as the master
24973                  * sock (sk_refcnt_debug_inc uses newsk->sk_prot->socks, that
24974 @@ -2017,6 +2036,12 @@ void sock_init_data(struct socket *sock,
24975  
24976         sk->sk_stamp = ktime_set(-1L, 0);
24977  
24978 +       set_vx_info(&sk->sk_vx_info, current_vx_info());
24979 +       sk->sk_xid = vx_current_xid();
24980 +       vx_sock_inc(sk);
24981 +       set_nx_info(&sk->sk_nx_info, current_nx_info());
24982 +       sk->sk_nid = nx_current_nid();
24983 +
24984         /*
24985          * Before updating sk_refcnt, we must commit prior changes to memory
24986          * (Documentation/RCU/rculist_nulls.txt for details)
24987 diff -NurpP --minimal linux-2.6.38.3/net/ipv4/af_inet.c linux-2.6.38.3-vs2.3.0.37-rc14/net/ipv4/af_inet.c
24988 --- linux-2.6.38.3/net/ipv4/af_inet.c   2011-03-15 18:07:45.000000000 +0100
24989 +++ linux-2.6.38.3-vs2.3.0.37-rc14/net/ipv4/af_inet.c   2011-02-17 02:17:52.000000000 +0100
24990 @@ -116,6 +116,7 @@
24991  #ifdef CONFIG_IP_MROUTE
24992  #include <linux/mroute.h>
24993  #endif
24994 +#include <linux/vs_limit.h>
24995  
24996  
24997  /* The inetsw table contains everything that inet_create needs to
24998 @@ -325,9 +326,13 @@ lookup_protocol:
24999         }
25000  
25001         err = -EPERM;
25002 +       if ((protocol == IPPROTO_ICMP) &&
25003 +               nx_capable(CAP_NET_RAW, NXC_RAW_ICMP))
25004 +               goto override;
25005 +
25006         if (sock->type == SOCK_RAW && !kern && !capable(CAP_NET_RAW))
25007                 goto out_rcu_unlock;
25008 -
25009 +override:
25010         err = -EAFNOSUPPORT;
25011         if (!inet_netns_ok(net, protocol))
25012                 goto out_rcu_unlock;
25013 @@ -451,6 +456,7 @@ int inet_bind(struct socket *sock, struc
25014         struct sockaddr_in *addr = (struct sockaddr_in *)uaddr;
25015         struct sock *sk = sock->sk;
25016         struct inet_sock *inet = inet_sk(sk);
25017 +       struct nx_v4_sock_addr nsa;
25018         unsigned short snum;
25019         int chk_addr_ret;
25020         int err;
25021 @@ -464,7 +470,11 @@ int inet_bind(struct socket *sock, struc
25022         if (addr_len < sizeof(struct sockaddr_in))
25023                 goto out;
25024  
25025 -       chk_addr_ret = inet_addr_type(sock_net(sk), addr->sin_addr.s_addr);
25026 +       err = v4_map_sock_addr(inet, addr, &nsa);
25027 +       if (err)
25028 +               goto out;
25029 +
25030 +       chk_addr_ret = inet_addr_type(sock_net(sk), nsa.saddr);
25031  
25032         /* Not specified by any standard per-se, however it breaks too
25033          * many applications when removed.  It is unfortunate since
25034 @@ -476,7 +486,7 @@ int inet_bind(struct socket *sock, struc
25035         err = -EADDRNOTAVAIL;
25036         if (!sysctl_ip_nonlocal_bind &&
25037             !(inet->freebind || inet->transparent) &&
25038 -           addr->sin_addr.s_addr != htonl(INADDR_ANY) &&
25039 +           nsa.saddr != htonl(INADDR_ANY) &&
25040             chk_addr_ret != RTN_LOCAL &&
25041             chk_addr_ret != RTN_MULTICAST &&
25042             chk_addr_ret != RTN_BROADCAST)
25043 @@ -501,7 +511,7 @@ int inet_bind(struct socket *sock, struc
25044         if (sk->sk_state != TCP_CLOSE || inet->inet_num)
25045                 goto out_release_sock;
25046  
25047 -       inet->inet_rcv_saddr = inet->inet_saddr = addr->sin_addr.s_addr;
25048 +       v4_set_sock_addr(inet, &nsa);
25049         if (chk_addr_ret == RTN_MULTICAST || chk_addr_ret == RTN_BROADCAST)
25050                 inet->inet_saddr = 0;  /* Use device */
25051  
25052 @@ -703,11 +713,13 @@ int inet_getname(struct socket *sock, st
25053                      peer == 1))
25054                         return -ENOTCONN;
25055                 sin->sin_port = inet->inet_dport;
25056 -               sin->sin_addr.s_addr = inet->inet_daddr;
25057 +               sin->sin_addr.s_addr =
25058 +                       nx_map_sock_lback(sk->sk_nx_info, inet->inet_daddr);
25059         } else {
25060                 __be32 addr = inet->inet_rcv_saddr;
25061                 if (!addr)
25062                         addr = inet->inet_saddr;
25063 +               addr = nx_map_sock_lback(sk->sk_nx_info, addr);
25064                 sin->sin_port = inet->inet_sport;
25065                 sin->sin_addr.s_addr = addr;
25066         }
25067 diff -NurpP --minimal linux-2.6.38.3/net/ipv4/devinet.c linux-2.6.38.3-vs2.3.0.37-rc14/net/ipv4/devinet.c
25068 --- linux-2.6.38.3/net/ipv4/devinet.c   2011-03-15 18:07:45.000000000 +0100
25069 +++ linux-2.6.38.3-vs2.3.0.37-rc14/net/ipv4/devinet.c   2011-03-15 18:15:06.000000000 +0100
25070 @@ -420,6 +420,7 @@ struct in_device *inetdev_by_index(struc
25071  }
25072  EXPORT_SYMBOL(inetdev_by_index);
25073  
25074 +
25075  /* Called only from RTNL semaphored context. No locks. */
25076  
25077  struct in_ifaddr *inet_ifa_byprefix(struct in_device *in_dev, __be32 prefix,
25078 @@ -660,6 +661,8 @@ int devinet_ioctl(struct net *net, unsig
25079  
25080         in_dev = __in_dev_get_rtnl(dev);
25081         if (in_dev) {
25082 +               struct nx_info *nxi = current_nx_info();
25083 +
25084                 if (tryaddrmatch) {
25085                         /* Matthias Andree */
25086                         /* compare label and address (4.4BSD style) */
25087 @@ -668,6 +671,8 @@ int devinet_ioctl(struct net *net, unsig
25088                            This is checked above. */
25089                         for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
25090                              ifap = &ifa->ifa_next) {
25091 +                               if (!nx_v4_ifa_visible(nxi, ifa))
25092 +                                       continue;
25093                                 if (!strcmp(ifr.ifr_name, ifa->ifa_label) &&
25094                                     sin_orig.sin_addr.s_addr ==
25095                                                         ifa->ifa_local) {
25096 @@ -680,9 +685,12 @@ int devinet_ioctl(struct net *net, unsig
25097                    comparing just the label */
25098                 if (!ifa) {
25099                         for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
25100 -                            ifap = &ifa->ifa_next)
25101 +                            ifap = &ifa->ifa_next) {
25102 +                               if (!nx_v4_ifa_visible(nxi, ifa))
25103 +                                       continue;
25104                                 if (!strcmp(ifr.ifr_name, ifa->ifa_label))
25105                                         break;
25106 +                       }
25107                 }
25108         }
25109  
25110 @@ -834,6 +842,8 @@ static int inet_gifconf(struct net_devic
25111                 goto out;
25112  
25113         for (ifa = in_dev->ifa_list; ifa; ifa = ifa->ifa_next) {
25114 +               if (!nx_v4_ifa_visible(current_nx_info(), ifa))
25115 +                       continue;
25116                 if (!buf) {
25117                         done += sizeof(ifr);
25118                         continue;
25119 @@ -1193,6 +1203,7 @@ static int inet_dump_ifaddr(struct sk_bu
25120         struct net_device *dev;
25121         struct in_device *in_dev;
25122         struct in_ifaddr *ifa;
25123 +       struct sock *sk = skb->sk;
25124         struct hlist_head *head;
25125         struct hlist_node *node;
25126  
25127 @@ -1215,6 +1226,8 @@ static int inet_dump_ifaddr(struct sk_bu
25128  
25129                         for (ifa = in_dev->ifa_list, ip_idx = 0; ifa;
25130                              ifa = ifa->ifa_next, ip_idx++) {
25131 +                       if (sk && !nx_v4_ifa_visible(sk->sk_nx_info, ifa))
25132 +                               continue;
25133                                 if (ip_idx < s_ip_idx)
25134                                         continue;
25135                                 if (inet_fill_ifaddr(skb, ifa,
25136 diff -NurpP --minimal linux-2.6.38.3/net/ipv4/fib_hash.c linux-2.6.38.3-vs2.3.0.37-rc14/net/ipv4/fib_hash.c
25137 --- linux-2.6.38.3/net/ipv4/fib_hash.c  2011-01-05 21:50:41.000000000 +0100
25138 +++ linux-2.6.38.3-vs2.3.0.37-rc14/net/ipv4/fib_hash.c  2011-01-29 02:01:07.000000000 +0100
25139 @@ -1080,7 +1080,7 @@ static int fib_seq_show(struct seq_file 
25140         prefix  = f->fn_key;
25141         mask    = FZ_MASK(iter->zone);
25142         flags   = fib_flag_trans(fa->fa_type, mask, fi);
25143 -       if (fi)
25144 +       if (fi && nx_dev_visible(current_nx_info(), fi->fib_dev))
25145                 seq_printf(seq,
25146                          "%s\t%08X\t%08X\t%04X\t%d\t%u\t%d\t%08X\t%d\t%u\t%u%n",
25147                          fi->fib_dev ? fi->fib_dev->name : "*", prefix,
25148 diff -NurpP --minimal linux-2.6.38.3/net/ipv4/inet_connection_sock.c linux-2.6.38.3-vs2.3.0.37-rc14/net/ipv4/inet_connection_sock.c
25149 --- linux-2.6.38.3/net/ipv4/inet_connection_sock.c      2011-03-15 18:07:45.000000000 +0100
25150 +++ linux-2.6.38.3-vs2.3.0.37-rc14/net/ipv4/inet_connection_sock.c      2011-01-29 05:17:31.000000000 +0100
25151 @@ -52,6 +52,37 @@ void inet_get_local_port_range(int *low,
25152  }
25153  EXPORT_SYMBOL(inet_get_local_port_range);
25154  
25155 +int ipv4_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2)
25156 +{
25157 +       __be32  sk1_rcv_saddr = sk_rcv_saddr(sk1),
25158 +               sk2_rcv_saddr = sk_rcv_saddr(sk2);
25159 +
25160 +       if (inet_v6_ipv6only(sk2))
25161 +               return 0;
25162 +
25163 +       if (sk1_rcv_saddr &&
25164 +           sk2_rcv_saddr &&
25165 +           sk1_rcv_saddr == sk2_rcv_saddr)
25166 +               return 1;
25167 +
25168 +       if (sk1_rcv_saddr &&
25169 +           !sk2_rcv_saddr &&
25170 +           v4_addr_in_nx_info(sk2->sk_nx_info, sk1_rcv_saddr, NXA_MASK_BIND))
25171 +               return 1;
25172 +
25173 +       if (sk2_rcv_saddr &&
25174 +           !sk1_rcv_saddr &&
25175 +           v4_addr_in_nx_info(sk1->sk_nx_info, sk2_rcv_saddr, NXA_MASK_BIND))
25176 +               return 1;
25177 +
25178 +       if (!sk1_rcv_saddr &&
25179 +           !sk2_rcv_saddr &&
25180 +           nx_v4_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info))
25181 +               return 1;
25182 +
25183 +       return 0;
25184 +}
25185 +
25186  int inet_csk_bind_conflict(const struct sock *sk,
25187                            const struct inet_bind_bucket *tb)
25188  {
25189 @@ -74,9 +105,7 @@ int inet_csk_bind_conflict(const struct 
25190                      sk->sk_bound_dev_if == sk2->sk_bound_dev_if)) {
25191                         if (!reuse || !sk2->sk_reuse ||
25192                             ((1 << sk2->sk_state) & (TCPF_LISTEN | TCPF_CLOSE))) {
25193 -                               const __be32 sk2_rcv_saddr = sk_rcv_saddr(sk2);
25194 -                               if (!sk2_rcv_saddr || !sk_rcv_saddr(sk) ||
25195 -                                   sk2_rcv_saddr == sk_rcv_saddr(sk))
25196 +                               if (ipv4_rcv_saddr_equal(sk, sk2))
25197                                         break;
25198                         }
25199                 }
25200 diff -NurpP --minimal linux-2.6.38.3/net/ipv4/inet_diag.c linux-2.6.38.3-vs2.3.0.37-rc14/net/ipv4/inet_diag.c
25201 --- linux-2.6.38.3/net/ipv4/inet_diag.c 2011-01-05 21:50:42.000000000 +0100
25202 +++ linux-2.6.38.3-vs2.3.0.37-rc14/net/ipv4/inet_diag.c 2011-01-29 02:01:07.000000000 +0100
25203 @@ -33,6 +33,8 @@
25204  #include <linux/stddef.h>
25205  
25206  #include <linux/inet_diag.h>
25207 +#include <linux/vs_network.h>
25208 +#include <linux/vs_inet.h>
25209  
25210  static const struct inet_diag_handler **inet_diag_table;
25211  
25212 @@ -119,8 +121,10 @@ static int inet_csk_diag_fill(struct soc
25213  
25214         r->id.idiag_sport = inet->inet_sport;
25215         r->id.idiag_dport = inet->inet_dport;
25216 -       r->id.idiag_src[0] = inet->inet_rcv_saddr;
25217 -       r->id.idiag_dst[0] = inet->inet_daddr;
25218 +       r->id.idiag_src[0] = nx_map_sock_lback(sk->sk_nx_info,
25219 +               inet->inet_rcv_saddr);
25220 +       r->id.idiag_dst[0] = nx_map_sock_lback(sk->sk_nx_info,
25221 +               inet->inet_daddr);
25222  
25223  #if defined(CONFIG_IPV6) || defined (CONFIG_IPV6_MODULE)
25224         if (r->idiag_family == AF_INET6) {
25225 @@ -205,8 +209,8 @@ static int inet_twsk_diag_fill(struct in
25226         r->id.idiag_cookie[1] = (u32)(((unsigned long)tw >> 31) >> 1);
25227         r->id.idiag_sport     = tw->tw_sport;
25228         r->id.idiag_dport     = tw->tw_dport;
25229 -       r->id.idiag_src[0]    = tw->tw_rcv_saddr;
25230 -       r->id.idiag_dst[0]    = tw->tw_daddr;
25231 +       r->id.idiag_src[0]    = nx_map_sock_lback(tw->tw_nx_info, tw->tw_rcv_saddr);
25232 +       r->id.idiag_dst[0]    = nx_map_sock_lback(tw->tw_nx_info, tw->tw_daddr);
25233         r->idiag_state        = tw->tw_substate;
25234         r->idiag_timer        = 3;
25235         r->idiag_expires      = DIV_ROUND_UP(tmo * 1000, HZ);
25236 @@ -263,6 +267,7 @@ static int inet_diag_get_exact(struct sk
25237         err = -EINVAL;
25238  
25239         if (req->idiag_family == AF_INET) {
25240 +               /* TODO: lback */
25241                 sk = inet_lookup(&init_net, hashinfo, req->id.idiag_dst[0],
25242                                  req->id.idiag_dport, req->id.idiag_src[0],
25243                                  req->id.idiag_sport, req->id.idiag_if);
25244 @@ -507,6 +512,7 @@ static int inet_csk_diag_dump(struct soc
25245                 } else
25246  #endif
25247                 {
25248 +                       /* TODO: lback */
25249                         entry.saddr = &inet->inet_rcv_saddr;
25250                         entry.daddr = &inet->inet_daddr;
25251                 }
25252 @@ -545,6 +551,7 @@ static int inet_twsk_diag_dump(struct in
25253                 } else
25254  #endif
25255                 {
25256 +                       /* TODO: lback */
25257                         entry.saddr = &tw->tw_rcv_saddr;
25258                         entry.daddr = &tw->tw_daddr;
25259                 }
25260 @@ -591,8 +598,8 @@ static int inet_diag_fill_req(struct sk_
25261  
25262         r->id.idiag_sport = inet->inet_sport;
25263         r->id.idiag_dport = ireq->rmt_port;
25264 -       r->id.idiag_src[0] = ireq->loc_addr;
25265 -       r->id.idiag_dst[0] = ireq->rmt_addr;
25266 +       r->id.idiag_src[0] = nx_map_sock_lback(sk->sk_nx_info, ireq->loc_addr);
25267 +       r->id.idiag_dst[0] = nx_map_sock_lback(sk->sk_nx_info, ireq->rmt_addr);
25268         r->idiag_expires = jiffies_to_msecs(tmo);
25269         r->idiag_rqueue = 0;
25270         r->idiag_wqueue = 0;
25271 @@ -663,6 +670,7 @@ static int inet_diag_dump_reqs(struct sk
25272                                 continue;
25273  
25274                         if (bc) {
25275 +                               /* TODO: lback */
25276                                 entry.saddr =
25277  #if defined(CONFIG_IPV6) || defined (CONFIG_IPV6_MODULE)
25278                                         (entry.family == AF_INET6) ?
25279 @@ -733,6 +741,8 @@ static int inet_diag_dump(struct sk_buff
25280                         sk_nulls_for_each(sk, node, &ilb->head) {
25281                                 struct inet_sock *inet = inet_sk(sk);
25282  
25283 +                               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
25284 +                                       continue;
25285                                 if (num < s_num) {
25286                                         num++;
25287                                         continue;
25288 @@ -799,6 +809,8 @@ skip_listen_ht:
25289                 sk_nulls_for_each(sk, node, &head->chain) {
25290                         struct inet_sock *inet = inet_sk(sk);
25291  
25292 +                       if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
25293 +                               continue;
25294                         if (num < s_num)
25295                                 goto next_normal;
25296                         if (!(r->idiag_states & (1 << sk->sk_state)))
25297 @@ -823,6 +835,8 @@ next_normal:
25298                         inet_twsk_for_each(tw, node,
25299                                     &head->twchain) {
25300  
25301 +                               if (!nx_check(tw->tw_nid, VS_WATCH_P | VS_IDENT))
25302 +                                       continue;
25303                                 if (num < s_num)
25304                                         goto next_dying;
25305                                 if (r->id.idiag_sport != tw->tw_sport &&
25306 diff -NurpP --minimal linux-2.6.38.3/net/ipv4/inet_hashtables.c linux-2.6.38.3-vs2.3.0.37-rc14/net/ipv4/inet_hashtables.c
25307 --- linux-2.6.38.3/net/ipv4/inet_hashtables.c   2011-01-05 21:50:42.000000000 +0100
25308 +++ linux-2.6.38.3-vs2.3.0.37-rc14/net/ipv4/inet_hashtables.c   2011-01-29 02:01:07.000000000 +0100
25309 @@ -21,6 +21,7 @@
25310  
25311  #include <net/inet_connection_sock.h>
25312  #include <net/inet_hashtables.h>
25313 +#include <net/route.h>
25314  #include <net/ip.h>
25315  
25316  /*
25317 @@ -155,6 +156,11 @@ static inline int compute_score(struct s
25318                         if (rcv_saddr != daddr)
25319                                 return -1;
25320                         score += 2;
25321 +               } else {
25322 +                       /* block non nx_info ips */
25323 +                       if (!v4_addr_in_nx_info(sk->sk_nx_info,
25324 +                               daddr, NXA_MASK_BIND))
25325 +                               return -1;
25326                 }
25327                 if (sk->sk_bound_dev_if) {
25328                         if (sk->sk_bound_dev_if != dif)
25329 @@ -172,7 +178,6 @@ static inline int compute_score(struct s
25330   * wildcarded during the search since they can never be otherwise.
25331   */
25332  
25333 -
25334  struct sock *__inet_lookup_listener(struct net *net,
25335                                     struct inet_hashinfo *hashinfo,
25336                                     const __be32 daddr, const unsigned short hnum,
25337 @@ -195,6 +200,7 @@ begin:
25338                         hiscore = score;
25339                 }
25340         }
25341 +
25342         /*
25343          * if the nulls value we got at the end of this lookup is
25344          * not the expected one, we must restart lookup.
25345 diff -NurpP --minimal linux-2.6.38.3/net/ipv4/netfilter/nf_nat_helper.c linux-2.6.38.3-vs2.3.0.37-rc14/net/ipv4/netfilter/nf_nat_helper.c
25346 --- linux-2.6.38.3/net/ipv4/netfilter/nf_nat_helper.c   2011-01-05 21:50:42.000000000 +0100
25347 +++ linux-2.6.38.3-vs2.3.0.37-rc14/net/ipv4/netfilter/nf_nat_helper.c   2011-01-29 02:01:07.000000000 +0100
25348 @@ -20,6 +20,7 @@
25349  #include <net/route.h>
25350  
25351  #include <linux/netfilter_ipv4.h>
25352 +#include <net/route.h>
25353  #include <net/netfilter/nf_conntrack.h>
25354  #include <net/netfilter/nf_conntrack_helper.h>
25355  #include <net/netfilter/nf_conntrack_ecache.h>
25356 diff -NurpP --minimal linux-2.6.38.3/net/ipv4/netfilter.c linux-2.6.38.3-vs2.3.0.37-rc14/net/ipv4/netfilter.c
25357 --- linux-2.6.38.3/net/ipv4/netfilter.c 2011-03-15 18:07:45.000000000 +0100
25358 +++ linux-2.6.38.3-vs2.3.0.37-rc14/net/ipv4/netfilter.c 2011-01-29 02:01:07.000000000 +0100
25359 @@ -5,7 +5,7 @@
25360  #include <linux/ip.h>
25361  #include <linux/skbuff.h>
25362  #include <linux/gfp.h>
25363 -#include <net/route.h>
25364 +// #include <net/route.h>
25365  #include <net/xfrm.h>
25366  #include <net/ip.h>
25367  #include <net/netfilter/nf_queue.h>
25368 diff -NurpP --minimal linux-2.6.38.3/net/ipv4/raw.c linux-2.6.38.3-vs2.3.0.37-rc14/net/ipv4/raw.c
25369 --- linux-2.6.38.3/net/ipv4/raw.c       2011-03-15 18:07:45.000000000 +0100
25370 +++ linux-2.6.38.3-vs2.3.0.37-rc14/net/ipv4/raw.c       2011-02-17 02:17:52.000000000 +0100
25371 @@ -117,7 +117,7 @@ static struct sock *__raw_v4_lookup(stru
25372  
25373                 if (net_eq(sock_net(sk), net) && inet->inet_num == num  &&
25374                     !(inet->inet_daddr && inet->inet_daddr != raddr)    &&
25375 -                   !(inet->inet_rcv_saddr && inet->inet_rcv_saddr != laddr) &&
25376 +                   v4_sock_addr_match(sk->sk_nx_info, inet, laddr)     &&
25377                     !(sk->sk_bound_dev_if && sk->sk_bound_dev_if != dif))
25378                         goto found; /* gotcha */
25379         }
25380 @@ -384,6 +384,12 @@ static int raw_send_hdrinc(struct sock *
25381                 icmp_out_count(net, ((struct icmphdr *)
25382                         skb_transport_header(skb))->type);
25383  
25384 +       err = -EPERM;
25385 +       if (!nx_check(0, VS_ADMIN) && !capable(CAP_NET_RAW) &&
25386 +               sk->sk_nx_info &&
25387 +               !v4_addr_in_nx_info(sk->sk_nx_info, iph->saddr, NXA_MASK_BIND))
25388 +               goto error_free;
25389 +
25390         err = NF_HOOK(NFPROTO_IPV4, NF_INET_LOCAL_OUT, skb, NULL,
25391                       rt->dst.dev, dst_output);
25392         if (err > 0)
25393 @@ -563,6 +569,13 @@ static int raw_sendmsg(struct kiocb *ioc
25394                 }
25395  
25396                 security_sk_classify_flow(sk, &fl);
25397 +               if (sk->sk_nx_info) {
25398 +                       err = ip_v4_find_src(sock_net(sk),
25399 +                               sk->sk_nx_info, &rt, &fl);
25400 +
25401 +                       if (err)
25402 +                               goto done;
25403 +               }
25404                 err = ip_route_output_flow(sock_net(sk), &rt, &fl, sk, 1);
25405         }
25406         if (err)
25407 @@ -635,17 +648,19 @@ static int raw_bind(struct sock *sk, str
25408  {
25409         struct inet_sock *inet = inet_sk(sk);
25410         struct sockaddr_in *addr = (struct sockaddr_in *) uaddr;
25411 +       struct nx_v4_sock_addr nsa = { 0 };
25412         int ret = -EINVAL;
25413         int chk_addr_ret;
25414  
25415         if (sk->sk_state != TCP_CLOSE || addr_len < sizeof(struct sockaddr_in))
25416                 goto out;
25417 -       chk_addr_ret = inet_addr_type(sock_net(sk), addr->sin_addr.s_addr);
25418 +       v4_map_sock_addr(inet, addr, &nsa);
25419 +       chk_addr_ret = inet_addr_type(sock_net(sk), nsa.saddr);
25420         ret = -EADDRNOTAVAIL;
25421 -       if (addr->sin_addr.s_addr && chk_addr_ret != RTN_LOCAL &&
25422 +       if (nsa.saddr && chk_addr_ret != RTN_LOCAL &&
25423             chk_addr_ret != RTN_MULTICAST && chk_addr_ret != RTN_BROADCAST)
25424                 goto out;
25425 -       inet->inet_rcv_saddr = inet->inet_saddr = addr->sin_addr.s_addr;
25426 +       v4_set_sock_addr(inet, &nsa);
25427         if (chk_addr_ret == RTN_MULTICAST || chk_addr_ret == RTN_BROADCAST)
25428                 inet->inet_saddr = 0;  /* Use device */
25429         sk_dst_reset(sk);
25430 @@ -697,7 +712,8 @@ static int raw_recvmsg(struct kiocb *ioc
25431         /* Copy the address. */
25432         if (sin) {
25433                 sin->sin_family = AF_INET;
25434 -               sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
25435 +               sin->sin_addr.s_addr =
25436 +                       nx_map_sock_lback(sk->sk_nx_info, ip_hdr(skb)->saddr);
25437                 sin->sin_port = 0;
25438                 memset(&sin->sin_zero, 0, sizeof(sin->sin_zero));
25439         }
25440 @@ -893,7 +909,8 @@ static struct sock *raw_get_first(struct
25441                 struct hlist_node *node;
25442  
25443                 sk_for_each(sk, node, &state->h->ht[state->bucket])
25444 -                       if (sock_net(sk) == seq_file_net(seq))
25445 +                       if ((sock_net(sk) == seq_file_net(seq)) &&
25446 +                               nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
25447                                 goto found;
25448         }
25449         sk = NULL;
25450 @@ -909,7 +926,8 @@ static struct sock *raw_get_next(struct 
25451                 sk = sk_next(sk);
25452  try_again:
25453                 ;
25454 -       } while (sk && sock_net(sk) != seq_file_net(seq));
25455 +       } while (sk && ((sock_net(sk) != seq_file_net(seq)) ||
25456 +               !nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT)));
25457  
25458         if (!sk && ++state->bucket < RAW_HTABLE_SIZE) {
25459                 sk = sk_head(&state->h->ht[state->bucket]);
25460 @@ -968,7 +986,10 @@ static void raw_sock_seq_show(struct seq
25461  
25462         seq_printf(seq, "%4d: %08X:%04X %08X:%04X"
25463                 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %lu %d %p %d\n",
25464 -               i, src, srcp, dest, destp, sp->sk_state,
25465 +               i,
25466 +               nx_map_sock_lback(current_nx_info(), src), srcp,
25467 +               nx_map_sock_lback(current_nx_info(), dest), destp,
25468 +               sp->sk_state,
25469                 sk_wmem_alloc_get(sp),
25470                 sk_rmem_alloc_get(sp),
25471                 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
25472 diff -NurpP --minimal linux-2.6.38.3/net/ipv4/tcp.c linux-2.6.38.3-vs2.3.0.37-rc14/net/ipv4/tcp.c
25473 --- linux-2.6.38.3/net/ipv4/tcp.c       2011-03-15 18:07:45.000000000 +0100
25474 +++ linux-2.6.38.3-vs2.3.0.37-rc14/net/ipv4/tcp.c       2011-01-29 02:01:07.000000000 +0100
25475 @@ -266,6 +266,7 @@
25476  #include <linux/crypto.h>
25477  #include <linux/time.h>
25478  #include <linux/slab.h>
25479 +#include <linux/in.h>
25480  
25481  #include <net/icmp.h>
25482  #include <net/tcp.h>
25483 diff -NurpP --minimal linux-2.6.38.3/net/ipv4/tcp_ipv4.c linux-2.6.38.3-vs2.3.0.37-rc14/net/ipv4/tcp_ipv4.c
25484 --- linux-2.6.38.3/net/ipv4/tcp_ipv4.c  2011-03-15 18:07:45.000000000 +0100
25485 +++ linux-2.6.38.3-vs2.3.0.37-rc14/net/ipv4/tcp_ipv4.c  2011-02-02 22:20:27.000000000 +0100
25486 @@ -1988,6 +1988,12 @@ static void *listening_get_next(struct s
25487                 req = req->dl_next;
25488                 while (1) {
25489                         while (req) {
25490 +                               vxdprintk(VXD_CBIT(net, 6),
25491 +                                       "sk,req: %p [#%d] (from %d)", req->sk,
25492 +                                       (req->sk)?req->sk->sk_nid:0, nx_current_nid());
25493 +                               if (req->sk &&
25494 +                                       !nx_check(req->sk->sk_nid, VS_WATCH_P | VS_IDENT))
25495 +                                       continue;
25496                                 if (req->rsk_ops->family == st->family) {
25497                                         cur = req;
25498                                         goto out;
25499 @@ -2012,6 +2018,10 @@ get_req:
25500         }
25501  get_sk:
25502         sk_nulls_for_each_from(sk, node) {
25503 +               vxdprintk(VXD_CBIT(net, 6), "sk: %p [#%d] (from %d)",
25504 +                       sk, sk->sk_nid, nx_current_nid());
25505 +               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
25506 +                       continue;
25507                 if (!net_eq(sock_net(sk), net))
25508                         continue;
25509                 if (sk->sk_family == st->family) {
25510 @@ -2088,6 +2098,11 @@ static void *established_get_first(struc
25511  
25512                 spin_lock_bh(lock);
25513                 sk_nulls_for_each(sk, node, &tcp_hashinfo.ehash[st->bucket].chain) {
25514 +                       vxdprintk(VXD_CBIT(net, 6),
25515 +                               "sk,egf: %p [#%d] (from %d)",
25516 +                               sk, sk->sk_nid, nx_current_nid());
25517 +                       if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
25518 +                               continue;
25519                         if (sk->sk_family != st->family ||
25520                             !net_eq(sock_net(sk), net)) {
25521                                 continue;
25522 @@ -2098,6 +2113,11 @@ static void *established_get_first(struc
25523                 st->state = TCP_SEQ_STATE_TIME_WAIT;
25524                 inet_twsk_for_each(tw, node,
25525                                    &tcp_hashinfo.ehash[st->bucket].twchain) {
25526 +                       vxdprintk(VXD_CBIT(net, 6),
25527 +                               "tw: %p [#%d] (from %d)",
25528 +                               tw, tw->tw_nid, nx_current_nid());
25529 +                       if (!nx_check(tw->tw_nid, VS_WATCH_P | VS_IDENT))
25530 +                               continue;
25531                         if (tw->tw_family != st->family ||
25532                             !net_eq(twsk_net(tw), net)) {
25533                                 continue;
25534 @@ -2127,7 +2147,9 @@ static void *established_get_next(struct
25535                 tw = cur;
25536                 tw = tw_next(tw);
25537  get_tw:
25538 -               while (tw && (tw->tw_family != st->family || !net_eq(twsk_net(tw), net))) {
25539 +               while (tw && (tw->tw_family != st->family ||
25540 +                       !net_eq(twsk_net(tw), net) ||
25541 +                       !nx_check(tw->tw_nid, VS_WATCH_P | VS_IDENT))) {
25542                         tw = tw_next(tw);
25543                 }
25544                 if (tw) {
25545 @@ -2151,6 +2173,11 @@ get_tw:
25546                 sk = sk_nulls_next(sk);
25547  
25548         sk_nulls_for_each_from(sk, node) {
25549 +               vxdprintk(VXD_CBIT(net, 6),
25550 +                       "sk,egn: %p [#%d] (from %d)",
25551 +                       sk, sk->sk_nid, nx_current_nid());
25552 +               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
25553 +                       continue;
25554                 if (sk->sk_family == st->family && net_eq(sock_net(sk), net))
25555                         goto found;
25556         }
25557 @@ -2360,9 +2387,9 @@ static void get_openreq4(struct sock *sk
25558         seq_printf(f, "%4d: %08X:%04X %08X:%04X"
25559                 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %u %d %p%n",
25560                 i,
25561 -               ireq->loc_addr,
25562 +               nx_map_sock_lback(current_nx_info(), ireq->loc_addr),
25563                 ntohs(inet_sk(sk)->inet_sport),
25564 -               ireq->rmt_addr,
25565 +               nx_map_sock_lback(current_nx_info(), ireq->rmt_addr),
25566                 ntohs(ireq->rmt_port),
25567                 TCP_SYN_RECV,
25568                 0, 0, /* could print option size, but that is af dependent. */
25569 @@ -2414,7 +2441,10 @@ static void get_tcp4_sock(struct sock *s
25570  
25571         seq_printf(f, "%4d: %08X:%04X %08X:%04X %02X %08X:%08X %02X:%08lX "
25572                         "%08X %5d %8d %lu %d %p %lu %lu %u %u %d%n",
25573 -               i, src, srcp, dest, destp, sk->sk_state,
25574 +               i,
25575 +               nx_map_sock_lback(current_nx_info(), src), srcp,
25576 +               nx_map_sock_lback(current_nx_info(), dest), destp,
25577 +               sk->sk_state,
25578                 tp->write_seq - tp->snd_una,
25579                 rx_queue,
25580                 timer_active,
25581 @@ -2449,7 +2479,10 @@ static void get_timewait4_sock(struct in
25582  
25583         seq_printf(f, "%4d: %08X:%04X %08X:%04X"
25584                 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %d %d %p%n",
25585 -               i, src, srcp, dest, destp, tw->tw_substate, 0, 0,
25586 +               i,
25587 +               nx_map_sock_lback(current_nx_info(), src), srcp,
25588 +               nx_map_sock_lback(current_nx_info(), dest), destp,
25589 +               tw->tw_substate, 0, 0,
25590                 3, jiffies_to_clock_t(ttd), 0, 0, 0, 0,
25591                 atomic_read(&tw->tw_refcnt), tw, len);
25592  }
25593 diff -NurpP --minimal linux-2.6.38.3/net/ipv4/tcp_minisocks.c linux-2.6.38.3-vs2.3.0.37-rc14/net/ipv4/tcp_minisocks.c
25594 --- linux-2.6.38.3/net/ipv4/tcp_minisocks.c     2011-03-15 18:07:45.000000000 +0100
25595 +++ linux-2.6.38.3-vs2.3.0.37-rc14/net/ipv4/tcp_minisocks.c     2011-01-29 02:01:07.000000000 +0100
25596 @@ -23,6 +23,9 @@
25597  #include <linux/slab.h>
25598  #include <linux/sysctl.h>
25599  #include <linux/workqueue.h>
25600 +#include <linux/vs_limit.h>
25601 +#include <linux/vs_socket.h>
25602 +#include <linux/vs_context.h>
25603  #include <net/tcp.h>
25604  #include <net/inet_common.h>
25605  #include <net/xfrm.h>
25606 @@ -335,6 +338,11 @@ void tcp_time_wait(struct sock *sk, int 
25607                 tcptw->tw_ts_recent     = tp->rx_opt.ts_recent;
25608                 tcptw->tw_ts_recent_stamp = tp->rx_opt.ts_recent_stamp;
25609  
25610 +               tw->tw_xid              = sk->sk_xid;
25611 +               tw->tw_vx_info          = NULL;
25612 +               tw->tw_nid              = sk->sk_nid;
25613 +               tw->tw_nx_info          = NULL;
25614 +
25615  #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
25616                 if (tw->tw_family == PF_INET6) {
25617                         struct ipv6_pinfo *np = inet6_sk(sk);
25618 diff -NurpP --minimal linux-2.6.38.3/net/ipv4/udp.c linux-2.6.38.3-vs2.3.0.37-rc14/net/ipv4/udp.c
25619 --- linux-2.6.38.3/net/ipv4/udp.c       2011-03-15 18:07:45.000000000 +0100
25620 +++ linux-2.6.38.3-vs2.3.0.37-rc14/net/ipv4/udp.c       2011-01-29 02:01:07.000000000 +0100
25621 @@ -296,14 +296,7 @@ fail:
25622  }
25623  EXPORT_SYMBOL(udp_lib_get_port);
25624  
25625 -static int ipv4_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2)
25626 -{
25627 -       struct inet_sock *inet1 = inet_sk(sk1), *inet2 = inet_sk(sk2);
25628 -
25629 -       return  (!ipv6_only_sock(sk2)  &&
25630 -                (!inet1->inet_rcv_saddr || !inet2->inet_rcv_saddr ||
25631 -                  inet1->inet_rcv_saddr == inet2->inet_rcv_saddr));
25632 -}
25633 +extern int ipv4_rcv_saddr_equal(const struct sock *, const struct sock *);
25634  
25635  static unsigned int udp4_portaddr_hash(struct net *net, __be32 saddr,
25636                                        unsigned int port)
25637 @@ -338,6 +331,11 @@ static inline int compute_score(struct s
25638                         if (inet->inet_rcv_saddr != daddr)
25639                                 return -1;
25640                         score += 2;
25641 +               } else {
25642 +                       /* block non nx_info ips */
25643 +                       if (!v4_addr_in_nx_info(sk->sk_nx_info,
25644 +                               daddr, NXA_MASK_BIND))
25645 +                               return -1;
25646                 }
25647                 if (inet->inet_daddr) {
25648                         if (inet->inet_daddr != saddr)
25649 @@ -441,6 +439,7 @@ exact_match:
25650         return result;
25651  }
25652  
25653 +
25654  /* UDP is nearly always wildcards out the wazoo, it makes no sense to try
25655   * harder than this. -DaveM
25656   */
25657 @@ -486,6 +485,11 @@ begin:
25658         sk_nulls_for_each_rcu(sk, node, &hslot->head) {
25659                 score = compute_score(sk, net, saddr, hnum, sport,
25660                                       daddr, dport, dif);
25661 +               /* FIXME: disabled?
25662 +               if (score == 9) {
25663 +                       result = sk;
25664 +                       break;
25665 +               } else */
25666                 if (score > badness) {
25667                         result = sk;
25668                         badness = score;
25669 @@ -499,6 +503,7 @@ begin:
25670         if (get_nulls_value(node) != slot)
25671                 goto begin;
25672  
25673 +
25674         if (result) {
25675                 if (unlikely(!atomic_inc_not_zero_hint(&result->sk_refcnt, 2)))
25676                         result = NULL;
25677 @@ -508,6 +513,7 @@ begin:
25678                         goto begin;
25679                 }
25680         }
25681 +
25682         rcu_read_unlock();
25683         return result;
25684  }
25685 @@ -550,8 +556,7 @@ static inline struct sock *udp_v4_mcast_
25686                     udp_sk(s)->udp_port_hash != hnum ||
25687                     (inet->inet_daddr && inet->inet_daddr != rmt_addr) ||
25688                     (inet->inet_dport != rmt_port && inet->inet_dport) ||
25689 -                   (inet->inet_rcv_saddr &&
25690 -                    inet->inet_rcv_saddr != loc_addr) ||
25691 +                   !v4_sock_addr_match(sk->sk_nx_info, inet, loc_addr) ||
25692                     ipv6_only_sock(s) ||
25693                     (s->sk_bound_dev_if && s->sk_bound_dev_if != dif))
25694                         continue;
25695 @@ -898,8 +903,13 @@ int udp_sendmsg(struct kiocb *iocb, stru
25696                                     .fl_ip_sport = inet->inet_sport,
25697                                     .fl_ip_dport = dport };
25698                 struct net *net = sock_net(sk);
25699 +               struct nx_info *nxi = sk->sk_nx_info;
25700  
25701                 security_sk_classify_flow(sk, &fl);
25702 +               err = ip_v4_find_src(net, nxi, &rt, &fl);
25703 +               if (err)
25704 +                       goto out;
25705 +
25706                 err = ip_route_output_flow(net, &rt, &fl, sk, 1);
25707                 if (err) {
25708                         if (err == -ENETUNREACH)
25709 @@ -1181,7 +1191,8 @@ try_again:
25710         if (sin) {
25711                 sin->sin_family = AF_INET;
25712                 sin->sin_port = udp_hdr(skb)->source;
25713 -               sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
25714 +               sin->sin_addr.s_addr = nx_map_sock_lback(
25715 +                       skb->sk->sk_nx_info, ip_hdr(skb)->saddr);
25716                 memset(sin->sin_zero, 0, sizeof(sin->sin_zero));
25717         }
25718         if (inet->cmsg_flags)
25719 @@ -1922,6 +1933,8 @@ static struct sock *udp_get_first(struct
25720                 sk_nulls_for_each(sk, node, &hslot->head) {
25721                         if (!net_eq(sock_net(sk), net))
25722                                 continue;
25723 +                       if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
25724 +                               continue;
25725                         if (sk->sk_family == state->family)
25726                                 goto found;
25727                 }
25728 @@ -1939,7 +1952,9 @@ static struct sock *udp_get_next(struct 
25729  
25730         do {
25731                 sk = sk_nulls_next(sk);
25732 -       } while (sk && (!net_eq(sock_net(sk), net) || sk->sk_family != state->family));
25733 +       } while (sk && (!net_eq(sock_net(sk), net) ||
25734 +               sk->sk_family != state->family ||
25735 +               !nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT)));
25736  
25737         if (!sk) {
25738                 if (state->bucket <= state->udp_table->mask)
25739 @@ -2046,7 +2061,10 @@ static void udp4_format_sock(struct sock
25740  
25741         seq_printf(f, "%5d: %08X:%04X %08X:%04X"
25742                 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %lu %d %p %d%n",
25743 -               bucket, src, srcp, dest, destp, sp->sk_state,
25744 +               bucket,
25745 +               nx_map_sock_lback(current_nx_info(), src), srcp,
25746 +               nx_map_sock_lback(current_nx_info(), dest), destp,
25747 +               sp->sk_state,
25748                 sk_wmem_alloc_get(sp),
25749                 sk_rmem_alloc_get(sp),
25750                 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
25751 diff -NurpP --minimal linux-2.6.38.3/net/ipv6/Kconfig linux-2.6.38.3-vs2.3.0.37-rc14/net/ipv6/Kconfig
25752 --- linux-2.6.38.3/net/ipv6/Kconfig     2010-08-02 16:52:59.000000000 +0200
25753 +++ linux-2.6.38.3-vs2.3.0.37-rc14/net/ipv6/Kconfig     2011-01-29 02:01:07.000000000 +0100
25754 @@ -4,8 +4,8 @@
25755  
25756  #   IPv6 as module will cause a CRASH if you try to unload it
25757  menuconfig IPV6
25758 -       tristate "The IPv6 protocol"
25759 -       default m
25760 +       bool "The IPv6 protocol"
25761 +       default n
25762         ---help---
25763           This is complemental support for the IP version 6.
25764           You will still be able to do traditional IPv4 networking as well.
25765 diff -NurpP --minimal linux-2.6.38.3/net/ipv6/addrconf.c linux-2.6.38.3-vs2.3.0.37-rc14/net/ipv6/addrconf.c
25766 --- linux-2.6.38.3/net/ipv6/addrconf.c  2011-03-15 18:07:45.000000000 +0100
25767 +++ linux-2.6.38.3-vs2.3.0.37-rc14/net/ipv6/addrconf.c  2011-02-02 22:20:27.000000000 +0100
25768 @@ -87,6 +87,8 @@
25769  
25770  #include <linux/proc_fs.h>
25771  #include <linux/seq_file.h>
25772 +#include <linux/vs_network.h>
25773 +#include <linux/vs_inet6.h>
25774  
25775  /* Set to 3 to get tracing... */
25776  #define ACONF_DEBUG 2
25777 @@ -1121,7 +1123,7 @@ out:
25778  
25779  int ipv6_dev_get_saddr(struct net *net, struct net_device *dst_dev,
25780                        const struct in6_addr *daddr, unsigned int prefs,
25781 -                      struct in6_addr *saddr)
25782 +                      struct in6_addr *saddr, struct nx_info *nxi)
25783  {
25784         struct ipv6_saddr_score scores[2],
25785                                 *score = &scores[0], *hiscore = &scores[1];
25786 @@ -1193,6 +1195,8 @@ int ipv6_dev_get_saddr(struct net *net, 
25787                                                dev->name);
25788                                 continue;
25789                         }
25790 +                       if (!v6_addr_in_nx_info(nxi, &score->ifa->addr, -1))
25791 +                               continue;
25792  
25793                         score->rule = -1;
25794                         bitmap_zero(score->scorebits, IPV6_SADDR_RULE_MAX);
25795 @@ -3061,7 +3065,10 @@ static void if6_seq_stop(struct seq_file
25796  static int if6_seq_show(struct seq_file *seq, void *v)
25797  {
25798         struct inet6_ifaddr *ifp = (struct inet6_ifaddr *)v;
25799 -       seq_printf(seq, "%pi6 %02x %02x %02x %02x %8s\n",
25800 +
25801 +       if (nx_check(0, VS_ADMIN|VS_WATCH) ||
25802 +           v6_addr_in_nx_info(current_nx_info(), &ifp->addr, -1))
25803 +               seq_printf(seq, "%pi6 %02x %02x %02x %02x %8s\n",
25804                    &ifp->addr,
25805                    ifp->idev->dev->ifindex,
25806                    ifp->prefix_len,
25807 @@ -3567,6 +3574,11 @@ static int in6_dump_addrs(struct inet6_d
25808         struct ifacaddr6 *ifaca;
25809         int err = 1;
25810         int ip_idx = *p_ip_idx;
25811 +       struct nx_info *nxi = skb->sk ? skb->sk->sk_nx_info : NULL;
25812 +
25813 +       /* disable ipv6 on non v6 guests */
25814 +       if (nxi && !nx_info_has_v6(nxi))
25815 +               return skb->len;
25816  
25817         read_lock_bh(&idev->lock);
25818         switch (type) {
25819 @@ -3577,6 +3589,8 @@ static int in6_dump_addrs(struct inet6_d
25820                 list_for_each_entry(ifa, &idev->addr_list, if_list) {
25821                         if (++ip_idx < s_ip_idx)
25822                                 continue;
25823 +                               if (!v6_addr_in_nx_info(nxi, &ifa->addr, -1))
25824 +                                       continue;
25825                         err = inet6_fill_ifaddr(skb, ifa,
25826                                                 NETLINK_CB(cb->skb).pid,
25827                                                 cb->nlh->nlmsg_seq,
25828 @@ -3593,6 +3607,8 @@ static int in6_dump_addrs(struct inet6_d
25829                      ifmca = ifmca->next, ip_idx++) {
25830                         if (ip_idx < s_ip_idx)
25831                                 continue;
25832 +                               if (!v6_addr_in_nx_info(nxi, &ifmca->mca_addr, -1))
25833 +                                       continue;
25834                         err = inet6_fill_ifmcaddr(skb, ifmca,
25835                                                   NETLINK_CB(cb->skb).pid,
25836                                                   cb->nlh->nlmsg_seq,
25837 @@ -3608,6 +3624,8 @@ static int in6_dump_addrs(struct inet6_d
25838                      ifaca = ifaca->aca_next, ip_idx++) {
25839                         if (ip_idx < s_ip_idx)
25840                                 continue;
25841 +                               if (!v6_addr_in_nx_info(nxi, &ifaca->aca_addr, -1))
25842 +                                       continue;
25843                         err = inet6_fill_ifacaddr(skb, ifaca,
25844                                                   NETLINK_CB(cb->skb).pid,
25845                                                   cb->nlh->nlmsg_seq,
25846 @@ -3993,6 +4011,11 @@ static int inet6_dump_ifinfo(struct sk_b
25847         struct inet6_dev *idev;
25848         struct hlist_head *head;
25849         struct hlist_node *node;
25850 +       struct nx_info *nxi = skb->sk ? skb->sk->sk_nx_info : NULL;
25851 +
25852 +       /* FIXME: maybe disable ipv6 on non v6 guests?
25853 +       if (skb->sk && skb->sk->sk_vx_info)
25854 +               return skb->len; */
25855  
25856         s_h = cb->args[0];
25857         s_idx = cb->args[1];
25858 @@ -4004,6 +4027,8 @@ static int inet6_dump_ifinfo(struct sk_b
25859                 hlist_for_each_entry_rcu(dev, node, head, index_hlist) {
25860                         if (idx < s_idx)
25861                                 goto cont;
25862 +                       if (!v6_dev_in_nx_info(dev, nxi))
25863 +                               goto cont;
25864                         idev = __in6_dev_get(dev);
25865                         if (!idev)
25866                                 goto cont;
25867 diff -NurpP --minimal linux-2.6.38.3/net/ipv6/af_inet6.c linux-2.6.38.3-vs2.3.0.37-rc14/net/ipv6/af_inet6.c
25868 --- linux-2.6.38.3/net/ipv6/af_inet6.c  2011-03-15 18:07:45.000000000 +0100
25869 +++ linux-2.6.38.3-vs2.3.0.37-rc14/net/ipv6/af_inet6.c  2011-01-29 02:01:07.000000000 +0100
25870 @@ -42,6 +42,8 @@
25871  #include <linux/netdevice.h>
25872  #include <linux/icmpv6.h>
25873  #include <linux/netfilter_ipv6.h>
25874 +#include <linux/vs_inet.h>
25875 +#include <linux/vs_inet6.h>
25876  
25877  #include <net/ip.h>
25878  #include <net/ipv6.h>
25879 @@ -160,9 +162,12 @@ lookup_protocol:
25880         }
25881  
25882         err = -EPERM;
25883 +       if ((protocol == IPPROTO_ICMPV6) &&
25884 +               nx_capable(CAP_NET_RAW, NXC_RAW_ICMP))
25885 +               goto override;
25886         if (sock->type == SOCK_RAW && !kern && !capable(CAP_NET_RAW))
25887                 goto out_rcu_unlock;
25888 -
25889 +override:
25890         sock->ops = answer->ops;
25891         answer_prot = answer->prot;
25892         answer_no_check = answer->no_check;
25893 @@ -261,6 +266,7 @@ int inet6_bind(struct socket *sock, stru
25894         struct inet_sock *inet = inet_sk(sk);
25895         struct ipv6_pinfo *np = inet6_sk(sk);
25896         struct net *net = sock_net(sk);
25897 +       struct nx_v6_sock_addr nsa;
25898         __be32 v4addr = 0;
25899         unsigned short snum;
25900         int addr_type = 0;
25901 @@ -272,6 +278,11 @@ int inet6_bind(struct socket *sock, stru
25902  
25903         if (addr_len < SIN6_LEN_RFC2133)
25904                 return -EINVAL;
25905 +
25906 +       err = v6_map_sock_addr(inet, addr, &nsa);
25907 +       if (err)
25908 +               return err;
25909 +
25910         addr_type = ipv6_addr_type(&addr->sin6_addr);
25911         if ((addr_type & IPV6_ADDR_MULTICAST) && sock->type == SOCK_STREAM)
25912                 return -EINVAL;
25913 @@ -303,6 +314,7 @@ int inet6_bind(struct socket *sock, stru
25914                 /* Reproduce AF_INET checks to make the bindings consistent */
25915                 v4addr = addr->sin6_addr.s6_addr32[3];
25916                 chk_addr_ret = inet_addr_type(net, v4addr);
25917 +
25918                 if (!sysctl_ip_nonlocal_bind &&
25919                     !(inet->freebind || inet->transparent) &&
25920                     v4addr != htonl(INADDR_ANY) &&
25921 @@ -312,6 +324,10 @@ int inet6_bind(struct socket *sock, stru
25922                         err = -EADDRNOTAVAIL;
25923                         goto out;
25924                 }
25925 +               if (!v4_addr_in_nx_info(sk->sk_nx_info, v4addr, NXA_MASK_BIND)) {
25926 +                       err = -EADDRNOTAVAIL;
25927 +                       goto out;
25928 +               }
25929         } else {
25930                 if (addr_type != IPV6_ADDR_ANY) {
25931                         struct net_device *dev = NULL;
25932 @@ -338,6 +354,11 @@ int inet6_bind(struct socket *sock, stru
25933                                 }
25934                         }
25935  
25936 +                       if (!v6_addr_in_nx_info(sk->sk_nx_info, &addr->sin6_addr, -1)) {
25937 +                               err = -EADDRNOTAVAIL;
25938 +                               goto out;
25939 +                       }
25940 +
25941                         /* ipv4 addr of the socket is invalid.  Only the
25942                          * unspecified and mapped address have a v4 equivalent.
25943                          */
25944 @@ -354,6 +375,9 @@ int inet6_bind(struct socket *sock, stru
25945                 }
25946         }
25947  
25948 +       /* what's that for? */
25949 +       v6_set_sock_addr(inet, &nsa);
25950 +
25951         inet->inet_rcv_saddr = v4addr;
25952         inet->inet_saddr = v4addr;
25953  
25954 @@ -455,9 +479,11 @@ int inet6_getname(struct socket *sock, s
25955                         return -ENOTCONN;
25956                 sin->sin6_port = inet->inet_dport;
25957                 ipv6_addr_copy(&sin->sin6_addr, &np->daddr);
25958 +               /* FIXME: remap lback? */
25959                 if (np->sndflow)
25960                         sin->sin6_flowinfo = np->flow_label;
25961         } else {
25962 +               /* FIXME: remap lback? */
25963                 if (ipv6_addr_any(&np->rcv_saddr))
25964                         ipv6_addr_copy(&sin->sin6_addr, &np->saddr);
25965                 else
25966 diff -NurpP --minimal linux-2.6.38.3/net/ipv6/fib6_rules.c linux-2.6.38.3-vs2.3.0.37-rc14/net/ipv6/fib6_rules.c
25967 --- linux-2.6.38.3/net/ipv6/fib6_rules.c        2011-01-05 21:50:42.000000000 +0100
25968 +++ linux-2.6.38.3-vs2.3.0.37-rc14/net/ipv6/fib6_rules.c        2011-01-29 02:01:07.000000000 +0100
25969 @@ -88,7 +88,7 @@ static int fib6_rule_action(struct fib_r
25970                                                ip6_dst_idev(&rt->dst)->dev,
25971                                                &flp->fl6_dst,
25972                                                rt6_flags2srcprefs(flags),
25973 -                                              &saddr))
25974 +                                              &saddr, NULL))
25975                                 goto again;
25976                         if (!ipv6_prefix_equal(&saddr, &r->src.addr,
25977                                                r->src.plen))
25978 diff -NurpP --minimal linux-2.6.38.3/net/ipv6/inet6_hashtables.c linux-2.6.38.3-vs2.3.0.37-rc14/net/ipv6/inet6_hashtables.c
25979 --- linux-2.6.38.3/net/ipv6/inet6_hashtables.c  2010-02-25 11:52:10.000000000 +0100
25980 +++ linux-2.6.38.3-vs2.3.0.37-rc14/net/ipv6/inet6_hashtables.c  2011-01-29 02:01:07.000000000 +0100
25981 @@ -16,6 +16,7 @@
25982  
25983  #include <linux/module.h>
25984  #include <linux/random.h>
25985 +#include <linux/vs_inet6.h>
25986  
25987  #include <net/inet_connection_sock.h>
25988  #include <net/inet_hashtables.h>
25989 @@ -82,7 +83,6 @@ struct sock *__inet6_lookup_established(
25990         unsigned int slot = hash & hashinfo->ehash_mask;
25991         struct inet_ehash_bucket *head = &hashinfo->ehash[slot];
25992  
25993 -
25994         rcu_read_lock();
25995  begin:
25996         sk_nulls_for_each_rcu(sk, node, &head->chain) {
25997 @@ -94,7 +94,7 @@ begin:
25998                                 sock_put(sk);
25999                                 goto begin;
26000                         }
26001 -               goto out;
26002 +                       goto out;
26003                 }
26004         }
26005         if (get_nulls_value(node) != slot)
26006 @@ -140,6 +140,9 @@ static int inline compute_score(struct s
26007                         if (!ipv6_addr_equal(&np->rcv_saddr, daddr))
26008                                 return -1;
26009                         score++;
26010 +               } else {
26011 +                       if (!v6_addr_in_nx_info(sk->sk_nx_info, daddr, -1))
26012 +                               return -1;
26013                 }
26014                 if (sk->sk_bound_dev_if) {
26015                         if (sk->sk_bound_dev_if != dif)
26016 diff -NurpP --minimal linux-2.6.38.3/net/ipv6/ip6_output.c linux-2.6.38.3-vs2.3.0.37-rc14/net/ipv6/ip6_output.c
26017 --- linux-2.6.38.3/net/ipv6/ip6_output.c        2011-03-15 18:07:45.000000000 +0100
26018 +++ linux-2.6.38.3-vs2.3.0.37-rc14/net/ipv6/ip6_output.c        2011-01-29 02:01:07.000000000 +0100
26019 @@ -933,7 +933,7 @@ static int ip6_dst_lookup_tail(struct so
26020                 err = ipv6_dev_get_saddr(net, ip6_dst_idev(*dst)->dev,
26021                                          &fl->fl6_dst,
26022                                          sk ? inet6_sk(sk)->srcprefs : 0,
26023 -                                        &fl->fl6_src);
26024 +                                        &fl->fl6_src, sk->sk_nx_info);
26025                 if (err)
26026                         goto out_err_release;
26027         }
26028 diff -NurpP --minimal linux-2.6.38.3/net/ipv6/ndisc.c linux-2.6.38.3-vs2.3.0.37-rc14/net/ipv6/ndisc.c
26029 --- linux-2.6.38.3/net/ipv6/ndisc.c     2011-03-15 18:07:45.000000000 +0100
26030 +++ linux-2.6.38.3-vs2.3.0.37-rc14/net/ipv6/ndisc.c     2011-03-10 16:52:54.000000000 +0100
26031 @@ -595,7 +595,7 @@ static void ndisc_send_na(struct net_dev
26032         } else {
26033                 if (ipv6_dev_get_saddr(dev_net(dev), dev, daddr,
26034                                        inet6_sk(dev_net(dev)->ipv6.ndisc_sk)->srcprefs,
26035 -                                      &tmpaddr))
26036 +                                      &tmpaddr, NULL))
26037                         return;
26038                 src_addr = &tmpaddr;
26039         }
26040 diff -NurpP --minimal linux-2.6.38.3/net/ipv6/raw.c linux-2.6.38.3-vs2.3.0.37-rc14/net/ipv6/raw.c
26041 --- linux-2.6.38.3/net/ipv6/raw.c       2011-03-15 18:07:45.000000000 +0100
26042 +++ linux-2.6.38.3-vs2.3.0.37-rc14/net/ipv6/raw.c       2011-02-17 02:17:52.000000000 +0100
26043 @@ -30,6 +30,7 @@
26044  #include <linux/icmpv6.h>
26045  #include <linux/netfilter.h>
26046  #include <linux/netfilter_ipv6.h>
26047 +#include <linux/vs_inet6.h>
26048  #include <linux/skbuff.h>
26049  #include <linux/compat.h>
26050  #include <asm/uaccess.h>
26051 @@ -284,6 +285,13 @@ static int rawv6_bind(struct sock *sk, s
26052                                 goto out_unlock;
26053                 }
26054  
26055 +               if (!v6_addr_in_nx_info(sk->sk_nx_info, &addr->sin6_addr, -1)) {
26056 +                       err = -EADDRNOTAVAIL;
26057 +                       if (dev)
26058 +                               dev_put(dev);
26059 +                       goto out;
26060 +               }
26061 +
26062                 /* ipv4 addr of the socket is invalid.  Only the
26063                  * unspecified and mapped address have a v4 equivalent.
26064                  */
26065 diff -NurpP --minimal linux-2.6.38.3/net/ipv6/route.c linux-2.6.38.3-vs2.3.0.37-rc14/net/ipv6/route.c
26066 --- linux-2.6.38.3/net/ipv6/route.c     2011-03-15 18:07:45.000000000 +0100
26067 +++ linux-2.6.38.3-vs2.3.0.37-rc14/net/ipv6/route.c     2011-03-15 18:15:06.000000000 +0100
26068 @@ -2291,7 +2291,8 @@ static int rt6_fill_node(struct net *net
26069                 struct inet6_dev *idev = ip6_dst_idev(&rt->dst);
26070                 struct in6_addr saddr_buf;
26071                 if (ipv6_dev_get_saddr(net, idev ? idev->dev : NULL,
26072 -                                      dst, 0, &saddr_buf) == 0)
26073 +                       dst, 0, &saddr_buf,
26074 +                       (skb->sk ? skb->sk->sk_nx_info : NULL)) == 0)
26075                         NLA_PUT(skb, RTA_PREFSRC, 16, &saddr_buf);
26076         }
26077  
26078 diff -NurpP --minimal linux-2.6.38.3/net/ipv6/tcp_ipv6.c linux-2.6.38.3-vs2.3.0.37-rc14/net/ipv6/tcp_ipv6.c
26079 --- linux-2.6.38.3/net/ipv6/tcp_ipv6.c  2011-03-15 18:07:45.000000000 +0100
26080 +++ linux-2.6.38.3-vs2.3.0.37-rc14/net/ipv6/tcp_ipv6.c  2011-01-29 02:01:07.000000000 +0100
26081 @@ -69,6 +69,7 @@
26082  
26083  #include <linux/crypto.h>
26084  #include <linux/scatterlist.h>
26085 +#include <linux/vs_inet6.h>
26086  
26087  static void    tcp_v6_send_reset(struct sock *sk, struct sk_buff *skb);
26088  static void    tcp_v6_reqsk_send_ack(struct sock *sk, struct sk_buff *skb,
26089 @@ -161,8 +162,15 @@ static int tcp_v6_connect(struct sock *s
26090          *      connect() to INADDR_ANY means loopback (BSD'ism).
26091          */
26092  
26093 -       if(ipv6_addr_any(&usin->sin6_addr))
26094 -               usin->sin6_addr.s6_addr[15] = 0x1;
26095 +       if(ipv6_addr_any(&usin->sin6_addr)) {
26096 +               struct nx_info *nxi =  sk->sk_nx_info;
26097 +
26098 +               if (nxi && nx_info_has_v6(nxi))
26099 +                       /* FIXME: remap lback? */
26100 +                       usin->sin6_addr = nxi->v6.ip;
26101 +               else
26102 +                       usin->sin6_addr.s6_addr[15] = 0x1;
26103 +       }
26104  
26105         addr_type = ipv6_addr_type(&usin->sin6_addr);
26106  
26107 diff -NurpP --minimal linux-2.6.38.3/net/ipv6/udp.c linux-2.6.38.3-vs2.3.0.37-rc14/net/ipv6/udp.c
26108 --- linux-2.6.38.3/net/ipv6/udp.c       2011-03-15 18:07:45.000000000 +0100
26109 +++ linux-2.6.38.3-vs2.3.0.37-rc14/net/ipv6/udp.c       2011-01-29 05:23:17.000000000 +0100
26110 @@ -45,41 +45,67 @@
26111  #include <net/tcp_states.h>
26112  #include <net/ip6_checksum.h>
26113  #include <net/xfrm.h>
26114 +#include <linux/vs_inet6.h>
26115  
26116  #include <linux/proc_fs.h>
26117  #include <linux/seq_file.h>
26118  #include "udp_impl.h"
26119  
26120 -int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
26121 +int ipv6_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2)
26122  {
26123 -       const struct in6_addr *sk_rcv_saddr6 = &inet6_sk(sk)->rcv_saddr;
26124 +       const struct in6_addr *sk1_rcv_saddr6 = &inet6_sk(sk1)->rcv_saddr;
26125         const struct in6_addr *sk2_rcv_saddr6 = inet6_rcv_saddr(sk2);
26126 -       __be32 sk1_rcv_saddr = sk_rcv_saddr(sk);
26127 +       __be32 sk1_rcv_saddr = sk_rcv_saddr(sk1);
26128         __be32 sk2_rcv_saddr = sk_rcv_saddr(sk2);
26129 -       int sk_ipv6only = ipv6_only_sock(sk);
26130 +       int sk1_ipv6only = ipv6_only_sock(sk1);
26131         int sk2_ipv6only = inet_v6_ipv6only(sk2);
26132 -       int addr_type = ipv6_addr_type(sk_rcv_saddr6);
26133 +       int addr_type = ipv6_addr_type(sk1_rcv_saddr6);
26134         int addr_type2 = sk2_rcv_saddr6 ? ipv6_addr_type(sk2_rcv_saddr6) : IPV6_ADDR_MAPPED;
26135  
26136         /* if both are mapped, treat as IPv4 */
26137 -       if (addr_type == IPV6_ADDR_MAPPED && addr_type2 == IPV6_ADDR_MAPPED)
26138 -               return (!sk2_ipv6only &&
26139 +       if (addr_type == IPV6_ADDR_MAPPED && addr_type2 == IPV6_ADDR_MAPPED) {
26140 +               if (!sk2_ipv6only &&
26141                         (!sk1_rcv_saddr || !sk2_rcv_saddr ||
26142 -                         sk1_rcv_saddr == sk2_rcv_saddr));
26143 +                         sk1_rcv_saddr == sk2_rcv_saddr))
26144 +                       goto vs_v4;
26145 +               else
26146 +                       return 0;
26147 +       }
26148  
26149         if (addr_type2 == IPV6_ADDR_ANY &&
26150             !(sk2_ipv6only && addr_type == IPV6_ADDR_MAPPED))
26151 -               return 1;
26152 +               goto vs;
26153  
26154         if (addr_type == IPV6_ADDR_ANY &&
26155 -           !(sk_ipv6only && addr_type2 == IPV6_ADDR_MAPPED))
26156 -               return 1;
26157 +           !(sk1_ipv6only && addr_type2 == IPV6_ADDR_MAPPED))
26158 +               goto vs;
26159  
26160         if (sk2_rcv_saddr6 &&
26161 -           ipv6_addr_equal(sk_rcv_saddr6, sk2_rcv_saddr6))
26162 -               return 1;
26163 +           ipv6_addr_equal(sk1_rcv_saddr6, sk2_rcv_saddr6))
26164 +               goto vs;
26165  
26166         return 0;
26167 +
26168 +vs_v4:
26169 +       if (!sk1_rcv_saddr && !sk2_rcv_saddr)
26170 +               return nx_v4_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info);
26171 +       if (!sk2_rcv_saddr)
26172 +               return v4_addr_in_nx_info(sk1->sk_nx_info, sk2_rcv_saddr, -1);
26173 +       if (!sk1_rcv_saddr)
26174 +               return v4_addr_in_nx_info(sk2->sk_nx_info, sk1_rcv_saddr, -1);
26175 +       return 1;
26176 +vs:
26177 +       if (addr_type2 == IPV6_ADDR_ANY && addr_type == IPV6_ADDR_ANY)
26178 +               return nx_v6_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info);
26179 +       else if (addr_type2 == IPV6_ADDR_ANY)
26180 +               return v6_addr_in_nx_info(sk2->sk_nx_info, sk1_rcv_saddr6, -1);
26181 +       else if (addr_type == IPV6_ADDR_ANY) {
26182 +               if (addr_type2 == IPV6_ADDR_MAPPED)
26183 +                       return nx_v4_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info);
26184 +               else
26185 +                       return v6_addr_in_nx_info(sk1->sk_nx_info, sk2_rcv_saddr6, -1);
26186 +       }
26187 +       return 1;
26188  }
26189  
26190  static unsigned int udp6_portaddr_hash(struct net *net,
26191 @@ -143,6 +169,10 @@ static inline int compute_score(struct s
26192                         if (!ipv6_addr_equal(&np->rcv_saddr, daddr))
26193                                 return -1;
26194                         score++;
26195 +               } else {
26196 +                       /* block non nx_info ips */
26197 +                       if (!v6_addr_in_nx_info(sk->sk_nx_info, daddr, -1))
26198 +                               return -1;
26199                 }
26200                 if (!ipv6_addr_any(&np->daddr)) {
26201                         if (!ipv6_addr_equal(&np->daddr, saddr))
26202 diff -NurpP --minimal linux-2.6.38.3/net/ipv6/xfrm6_policy.c linux-2.6.38.3-vs2.3.0.37-rc14/net/ipv6/xfrm6_policy.c
26203 --- linux-2.6.38.3/net/ipv6/xfrm6_policy.c      2011-03-15 18:07:45.000000000 +0100
26204 +++ linux-2.6.38.3-vs2.3.0.37-rc14/net/ipv6/xfrm6_policy.c      2011-02-02 22:20:27.000000000 +0100
26205 @@ -62,7 +62,7 @@ static int xfrm6_get_saddr(struct net *n
26206         dev = ip6_dst_idev(dst)->dev;
26207         ipv6_dev_get_saddr(dev_net(dev), dev,
26208                            (struct in6_addr *)&daddr->a6, 0,
26209 -                          (struct in6_addr *)&saddr->a6);
26210 +                          (struct in6_addr *)&saddr->a6, NULL);
26211         dst_release(dst);
26212         return 0;
26213  }
26214 diff -NurpP --minimal linux-2.6.38.3/net/netfilter/ipvs/ip_vs_xmit.c linux-2.6.38.3-vs2.3.0.37-rc14/net/netfilter/ipvs/ip_vs_xmit.c
26215 --- linux-2.6.38.3/net/netfilter/ipvs/ip_vs_xmit.c      2011-03-15 18:07:46.000000000 +0100
26216 +++ linux-2.6.38.3-vs2.3.0.37-rc14/net/netfilter/ipvs/ip_vs_xmit.c      2011-01-29 02:01:07.000000000 +0100
26217 @@ -213,7 +213,7 @@ __ip_vs_route_output_v6(struct net *net,
26218                 return dst;
26219         if (ipv6_addr_any(&fl.fl6_src) &&
26220             ipv6_dev_get_saddr(net, ip6_dst_idev(dst)->dev,
26221 -                              &fl.fl6_dst, 0, &fl.fl6_src) < 0)
26222 +                              &fl.fl6_dst, 0, &fl.fl6_src, NULL) < 0)
26223                 goto out_err;
26224         if (do_xfrm && xfrm_lookup(net, &dst, &fl, NULL, 0) < 0)
26225                 goto out_err;
26226 diff -NurpP --minimal linux-2.6.38.3/net/netlink/af_netlink.c linux-2.6.38.3-vs2.3.0.37-rc14/net/netlink/af_netlink.c
26227 --- linux-2.6.38.3/net/netlink/af_netlink.c     2011-03-15 18:07:46.000000000 +0100
26228 +++ linux-2.6.38.3-vs2.3.0.37-rc14/net/netlink/af_netlink.c     2011-03-10 17:21:19.000000000 +0100
26229 @@ -55,6 +55,9 @@
26230  #include <linux/types.h>
26231  #include <linux/audit.h>
26232  #include <linux/mutex.h>
26233 +#include <linux/vs_context.h>
26234 +#include <linux/vs_network.h>
26235 +#include <linux/vs_limit.h>
26236  
26237  #include <net/net_namespace.h>
26238  #include <net/sock.h>
26239 @@ -1922,6 +1925,8 @@ static struct sock *netlink_seq_socket_i
26240                         sk_for_each(s, node, &hash->table[j]) {
26241                                 if (sock_net(s) != seq_file_net(seq))
26242                                         continue;
26243 +                               if (!nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT))
26244 +                                       continue;
26245                                 if (off == pos) {
26246                                         iter->link = i;
26247                                         iter->hash_idx = j;
26248 @@ -1956,7 +1961,8 @@ static void *netlink_seq_next(struct seq
26249         s = v;
26250         do {
26251                 s = sk_next(s);
26252 -       } while (s && sock_net(s) != seq_file_net(seq));
26253 +       } while (s && (sock_net(s) != seq_file_net(seq) ||
26254 +               !nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT)));
26255         if (s)
26256                 return s;
26257  
26258 @@ -1968,7 +1974,8 @@ static void *netlink_seq_next(struct seq
26259  
26260                 for (; j <= hash->mask; j++) {
26261                         s = sk_head(&hash->table[j]);
26262 -                       while (s && sock_net(s) != seq_file_net(seq))
26263 +                       while (s && (sock_net(s) != seq_file_net(seq) ||
26264 +                               !nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT)))
26265                                 s = sk_next(s);
26266                         if (s) {
26267                                 iter->link = i;
26268 diff -NurpP --minimal linux-2.6.38.3/net/sctp/ipv6.c linux-2.6.38.3-vs2.3.0.37-rc14/net/sctp/ipv6.c
26269 --- linux-2.6.38.3/net/sctp/ipv6.c      2011-01-05 21:50:45.000000000 +0100
26270 +++ linux-2.6.38.3-vs2.3.0.37-rc14/net/sctp/ipv6.c      2011-01-29 02:01:07.000000000 +0100
26271 @@ -306,7 +306,8 @@ static void sctp_v6_get_saddr(struct sct
26272                                    dst ? ip6_dst_idev(dst)->dev : NULL,
26273                                    &daddr->v6.sin6_addr,
26274                                    inet6_sk(&sk->inet.sk)->srcprefs,
26275 -                                  &saddr->v6.sin6_addr);
26276 +                                  &saddr->v6.sin6_addr,
26277 +                                  asoc->base.sk->sk_nx_info);
26278                 SCTP_DEBUG_PRINTK("saddr from ipv6_get_saddr: %pI6\n",
26279                                   &saddr->v6.sin6_addr);
26280                 return;
26281 diff -NurpP --minimal linux-2.6.38.3/net/socket.c linux-2.6.38.3-vs2.3.0.37-rc14/net/socket.c
26282 --- linux-2.6.38.3/net/socket.c 2011-04-15 10:30:30.000000000 +0200
26283 +++ linux-2.6.38.3-vs2.3.0.37-rc14/net/socket.c 2011-03-28 15:00:14.000000000 +0200
26284 @@ -98,6 +98,10 @@
26285  
26286  #include <net/sock.h>
26287  #include <linux/netfilter.h>
26288 +#include <linux/vs_base.h>
26289 +#include <linux/vs_socket.h>
26290 +#include <linux/vs_inet.h>
26291 +#include <linux/vs_inet6.h>
26292  
26293  #include <linux/if_tun.h>
26294  #include <linux/ipv6_route.h>
26295 @@ -551,7 +555,7 @@ static inline int __sock_sendmsg(struct 
26296                                  struct msghdr *msg, size_t size)
26297  {
26298         struct sock_iocb *si = kiocb_to_siocb(iocb);
26299 -       int err;
26300 +       int err, len;
26301  
26302         sock_update_classid(sock->sk);
26303  
26304 @@ -564,7 +568,22 @@ static inline int __sock_sendmsg(struct 
26305         if (err)
26306                 return err;
26307  
26308 -       return sock->ops->sendmsg(iocb, sock, msg, size);
26309 +       len = sock->ops->sendmsg(iocb, sock, msg, size);
26310 +       if (sock->sk) {
26311 +               if (len == size)
26312 +                       vx_sock_send(sock->sk, size);
26313 +               else
26314 +                       vx_sock_fail(sock->sk, size);
26315 +       }
26316 +       vxdprintk(VXD_CBIT(net, 7),
26317 +               "__sock_sendmsg: %p[%p,%p,%p;%d/%d]:%d/%d",
26318 +               sock, sock->sk,
26319 +               (sock->sk)?sock->sk->sk_nx_info:0,
26320 +               (sock->sk)?sock->sk->sk_vx_info:0,
26321 +               (sock->sk)?sock->sk->sk_xid:0,
26322 +               (sock->sk)?sock->sk->sk_nid:0,
26323 +               (unsigned int)size, len);
26324 +       return len;
26325  }
26326  
26327  int sock_sendmsg(struct socket *sock, struct msghdr *msg, size_t size)
26328 @@ -682,6 +701,7 @@ static inline int __sock_recvmsg_nosec(s
26329                                        struct msghdr *msg, size_t size, int flags)
26330  {
26331         struct sock_iocb *si = kiocb_to_siocb(iocb);
26332 +       int len;
26333  
26334         sock_update_classid(sock->sk);
26335  
26336 @@ -691,7 +711,18 @@ static inline int __sock_recvmsg_nosec(s
26337         si->size = size;
26338         si->flags = flags;
26339  
26340 -       return sock->ops->recvmsg(iocb, sock, msg, size, flags);
26341 +       len = sock->ops->recvmsg(iocb, sock, msg, size, flags);
26342 +       if ((len >= 0) && sock->sk)
26343 +               vx_sock_recv(sock->sk, len);
26344 +       vxdprintk(VXD_CBIT(net, 7),
26345 +               "__sock_recvmsg: %p[%p,%p,%p;%d/%d]:%d/%d",
26346 +               sock, sock->sk,
26347 +               (sock->sk)?sock->sk->sk_nx_info:0,
26348 +               (sock->sk)?sock->sk->sk_vx_info:0,
26349 +               (sock->sk)?sock->sk->sk_xid:0,
26350 +               (sock->sk)?sock->sk->sk_nid:0,
26351 +               (unsigned int)size, len);
26352 +       return len;
26353  }
26354  
26355  static inline int __sock_recvmsg(struct kiocb *iocb, struct socket *sock,
26356 @@ -1175,6 +1206,13 @@ int __sock_create(struct net *net, int f
26357         if (type < 0 || type >= SOCK_MAX)
26358                 return -EINVAL;
26359  
26360 +       if (!nx_check(0, VS_ADMIN)) {
26361 +               if (family == PF_INET && !current_nx_info_has_v4())
26362 +                       return -EAFNOSUPPORT;
26363 +               if (family == PF_INET6 && !current_nx_info_has_v6())
26364 +                       return -EAFNOSUPPORT;
26365 +       }
26366 +
26367         /* Compatibility.
26368  
26369            This uglymoron is moved from INET layer to here to avoid
26370 @@ -1310,6 +1348,7 @@ SYSCALL_DEFINE3(socket, int, family, int
26371         if (retval < 0)
26372                 goto out;
26373  
26374 +       set_bit(SOCK_USER_SOCKET, &sock->flags);
26375         retval = sock_map_fd(sock, flags & (O_CLOEXEC | O_NONBLOCK));
26376         if (retval < 0)
26377                 goto out_release;
26378 @@ -1351,10 +1390,12 @@ SYSCALL_DEFINE4(socketpair, int, family,
26379         err = sock_create(family, type, protocol, &sock1);
26380         if (err < 0)
26381                 goto out;
26382 +       set_bit(SOCK_USER_SOCKET, &sock1->flags);
26383  
26384         err = sock_create(family, type, protocol, &sock2);
26385         if (err < 0)
26386                 goto out_release_1;
26387 +       set_bit(SOCK_USER_SOCKET, &sock2->flags);
26388  
26389         err = sock1->ops->socketpair(sock1, sock2);
26390         if (err < 0)
26391 diff -NurpP --minimal linux-2.6.38.3/net/sunrpc/auth.c linux-2.6.38.3-vs2.3.0.37-rc14/net/sunrpc/auth.c
26392 --- linux-2.6.38.3/net/sunrpc/auth.c    2011-03-15 18:07:46.000000000 +0100
26393 +++ linux-2.6.38.3-vs2.3.0.37-rc14/net/sunrpc/auth.c    2011-01-29 02:01:07.000000000 +0100
26394 @@ -14,6 +14,7 @@
26395  #include <linux/hash.h>
26396  #include <linux/sunrpc/clnt.h>
26397  #include <linux/spinlock.h>
26398 +#include <linux/vs_tag.h>
26399  
26400  #ifdef RPC_DEBUG
26401  # define RPCDBG_FACILITY       RPCDBG_AUTH
26402 @@ -425,6 +426,7 @@ rpcauth_lookupcred(struct rpc_auth *auth
26403         memset(&acred, 0, sizeof(acred));
26404         acred.uid = cred->fsuid;
26405         acred.gid = cred->fsgid;
26406 +       acred.tag = dx_current_tag();
26407         acred.group_info = get_group_info(((struct cred *)cred)->group_info);
26408  
26409         ret = auth->au_ops->lookup_cred(auth, &acred, flags);
26410 @@ -465,6 +467,7 @@ rpcauth_bind_root_cred(struct rpc_task *
26411         struct auth_cred acred = {
26412                 .uid = 0,
26413                 .gid = 0,
26414 +               .tag = dx_current_tag(),
26415         };
26416  
26417         dprintk("RPC: %5u looking up %s cred\n",
26418 diff -NurpP --minimal linux-2.6.38.3/net/sunrpc/auth_unix.c linux-2.6.38.3-vs2.3.0.37-rc14/net/sunrpc/auth_unix.c
26419 --- linux-2.6.38.3/net/sunrpc/auth_unix.c       2010-10-21 13:08:01.000000000 +0200
26420 +++ linux-2.6.38.3-vs2.3.0.37-rc14/net/sunrpc/auth_unix.c       2011-01-29 02:01:07.000000000 +0100
26421 @@ -12,12 +12,14 @@
26422  #include <linux/module.h>
26423  #include <linux/sunrpc/clnt.h>
26424  #include <linux/sunrpc/auth.h>
26425 +#include <linux/vs_tag.h>
26426  
26427  #define NFS_NGROUPS    16
26428  
26429  struct unx_cred {
26430         struct rpc_cred         uc_base;
26431         gid_t                   uc_gid;
26432 +       tag_t                   uc_tag;
26433         gid_t                   uc_gids[NFS_NGROUPS];
26434  };
26435  #define uc_uid                 uc_base.cr_uid
26436 @@ -78,6 +80,7 @@ unx_create_cred(struct rpc_auth *auth, s
26437                 groups = NFS_NGROUPS;
26438  
26439         cred->uc_gid = acred->gid;
26440 +       cred->uc_tag = acred->tag;
26441         for (i = 0; i < groups; i++)
26442                 cred->uc_gids[i] = GROUP_AT(acred->group_info, i);
26443         if (i < NFS_NGROUPS)
26444 @@ -119,7 +122,9 @@ unx_match(struct auth_cred *acred, struc
26445         unsigned int i;
26446  
26447  
26448 -       if (cred->uc_uid != acred->uid || cred->uc_gid != acred->gid)
26449 +       if (cred->uc_uid != acred->uid ||
26450 +               cred->uc_gid != acred->gid ||
26451 +               cred->uc_tag != acred->tag)
26452                 return 0;
26453  
26454         if (acred->group_info != NULL)
26455 @@ -142,7 +147,7 @@ unx_marshal(struct rpc_task *task, __be3
26456         struct rpc_clnt *clnt = task->tk_client;
26457         struct unx_cred *cred = container_of(task->tk_rqstp->rq_cred, struct unx_cred, uc_base);
26458         __be32          *base, *hold;
26459 -       int             i;
26460 +       int             i, tag;
26461  
26462         *p++ = htonl(RPC_AUTH_UNIX);
26463         base = p++;
26464 @@ -152,9 +157,12 @@ unx_marshal(struct rpc_task *task, __be3
26465          * Copy the UTS nodename captured when the client was created.
26466          */
26467         p = xdr_encode_array(p, clnt->cl_nodename, clnt->cl_nodelen);
26468 +       tag = task->tk_client->cl_tag;
26469  
26470 -       *p++ = htonl((u32) cred->uc_uid);
26471 -       *p++ = htonl((u32) cred->uc_gid);
26472 +       *p++ = htonl((u32) TAGINO_UID(tag,
26473 +               cred->uc_uid, cred->uc_tag));
26474 +       *p++ = htonl((u32) TAGINO_GID(tag,
26475 +               cred->uc_gid, cred->uc_tag));
26476         hold = p++;
26477         for (i = 0; i < 16 && cred->uc_gids[i] != (gid_t) NOGROUP; i++)
26478                 *p++ = htonl((u32) cred->uc_gids[i]);
26479 diff -NurpP --minimal linux-2.6.38.3/net/sunrpc/clnt.c linux-2.6.38.3-vs2.3.0.37-rc14/net/sunrpc/clnt.c
26480 --- linux-2.6.38.3/net/sunrpc/clnt.c    2011-04-15 10:30:30.000000000 +0200
26481 +++ linux-2.6.38.3-vs2.3.0.37-rc14/net/sunrpc/clnt.c    2011-03-25 22:52:15.000000000 +0100
26482 @@ -33,6 +33,7 @@
26483  #include <linux/utsname.h>
26484  #include <linux/workqueue.h>
26485  #include <linux/in6.h>
26486 +#include <linux/vs_cvirt.h>
26487  
26488  #include <linux/sunrpc/clnt.h>
26489  #include <linux/sunrpc/rpc_pipe_fs.h>
26490 @@ -359,6 +360,9 @@ struct rpc_clnt *rpc_create(struct rpc_c
26491         if (!(args->flags & RPC_CLNT_CREATE_QUIET))
26492                 clnt->cl_chatty = 1;
26493  
26494 +       /* TODO: handle RPC_CLNT_CREATE_TAGGED
26495 +       if (args->flags & RPC_CLNT_CREATE_TAGGED)
26496 +               clnt->cl_tag = 1; */
26497         return clnt;
26498  }
26499  EXPORT_SYMBOL_GPL(rpc_create);
26500 diff -NurpP --minimal linux-2.6.38.3/net/unix/af_unix.c linux-2.6.38.3-vs2.3.0.37-rc14/net/unix/af_unix.c
26501 --- linux-2.6.38.3/net/unix/af_unix.c   2011-03-15 18:07:46.000000000 +0100
26502 +++ linux-2.6.38.3-vs2.3.0.37-rc14/net/unix/af_unix.c   2011-03-15 18:15:06.000000000 +0100
26503 @@ -114,6 +114,8 @@
26504  #include <linux/mount.h>
26505  #include <net/checksum.h>
26506  #include <linux/security.h>
26507 +#include <linux/vs_context.h>
26508 +#include <linux/vs_limit.h>
26509  
26510  static struct hlist_head unix_socket_table[UNIX_HASH_SIZE + 1];
26511  static DEFINE_SPINLOCK(unix_table_lock);
26512 @@ -258,6 +260,8 @@ static struct sock *__unix_find_socket_b
26513                 if (!net_eq(sock_net(s), net))
26514                         continue;
26515  
26516 +               if (!nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT))
26517 +                       continue;
26518                 if (u->addr->len == len &&
26519                     !memcmp(u->addr->name, sunname, len))
26520                         goto found;
26521 @@ -2188,6 +2192,8 @@ static struct sock *unix_seq_idx(struct 
26522         for (s = first_unix_socket(&iter->i); s; s = next_unix_socket(&iter->i, s)) {
26523                 if (sock_net(s) != seq_file_net(seq))
26524                         continue;
26525 +               if (!nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT))
26526 +                       continue;
26527                 if (off == pos)
26528                         return s;
26529                 ++off;
26530 @@ -2212,7 +2218,8 @@ static void *unix_seq_next(struct seq_fi
26531                 sk = first_unix_socket(&iter->i);
26532         else
26533                 sk = next_unix_socket(&iter->i, sk);
26534 -       while (sk && (sock_net(sk) != seq_file_net(seq)))
26535 +       while (sk && (sock_net(sk) != seq_file_net(seq) ||
26536 +               !nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT)))
26537                 sk = next_unix_socket(&iter->i, sk);
26538         return sk;
26539  }
26540 diff -NurpP --minimal linux-2.6.38.3/scripts/checksyscalls.sh linux-2.6.38.3-vs2.3.0.37-rc14/scripts/checksyscalls.sh
26541 --- linux-2.6.38.3/scripts/checksyscalls.sh     2011-03-15 18:07:46.000000000 +0100
26542 +++ linux-2.6.38.3-vs2.3.0.37-rc14/scripts/checksyscalls.sh     2011-01-29 02:01:07.000000000 +0100
26543 @@ -193,7 +193,6 @@ cat << EOF
26544  #define __IGNORE_afs_syscall
26545  #define __IGNORE_getpmsg
26546  #define __IGNORE_putpmsg
26547 -#define __IGNORE_vserver
26548  EOF
26549  }
26550  
26551 diff -NurpP --minimal linux-2.6.38.3/security/commoncap.c linux-2.6.38.3-vs2.3.0.37-rc14/security/commoncap.c
26552 --- linux-2.6.38.3/security/commoncap.c 2011-01-05 21:50:47.000000000 +0100
26553 +++ linux-2.6.38.3-vs2.3.0.37-rc14/security/commoncap.c 2011-01-29 02:01:07.000000000 +0100
26554 @@ -27,6 +27,7 @@
26555  #include <linux/sched.h>
26556  #include <linux/prctl.h>
26557  #include <linux/securebits.h>
26558 +// #include <linux/vs_context.h>
26559  
26560  /*
26561   * If a non-root user executes a setuid-root binary in
26562 @@ -52,7 +53,7 @@ static void warn_setuid_and_fcaps_mixed(
26563  
26564  int cap_netlink_send(struct sock *sk, struct sk_buff *skb)
26565  {
26566 -       NETLINK_CB(skb).eff_cap = current_cap();
26567 +       NETLINK_CB(skb).eff_cap = vx_mbcaps(current_cap());
26568         return 0;
26569  }
26570  
26571 @@ -62,6 +63,7 @@ int cap_netlink_recv(struct sk_buff *skb
26572                 return -EPERM;
26573         return 0;
26574  }
26575 +
26576  EXPORT_SYMBOL(cap_netlink_recv);
26577  
26578  /**
26579 @@ -82,7 +84,22 @@ EXPORT_SYMBOL(cap_netlink_recv);
26580  int cap_capable(struct task_struct *tsk, const struct cred *cred, int cap,
26581                 int audit)
26582  {
26583 -       return cap_raised(cred->cap_effective, cap) ? 0 : -EPERM;
26584 +       struct vx_info *vxi = tsk->vx_info;
26585 +
26586 +#if 0
26587 +       printk("cap_capable() VXF_STATE_SETUP = %llx, raised = %x, eff = %08x:%08x\n",
26588 +               vx_info_flags(vxi, VXF_STATE_SETUP, 0),
26589 +               cap_raised(tsk->cap_effective, cap),
26590 +               tsk->cap_effective.cap[1], tsk->cap_effective.cap[0]);
26591 +#endif
26592 +
26593 +       /* special case SETUP */
26594 +       if (vx_info_flags(vxi, VXF_STATE_SETUP, 0) &&
26595 +               /* FIXME: maybe use cred instead? */
26596 +               cap_raised(tsk->cred->cap_effective, cap))
26597 +               return 0;
26598 +
26599 +       return vx_cap_raised(vxi, cred->cap_effective, cap) ? 0 : -EPERM;
26600  }
26601  
26602  /**
26603 @@ -570,7 +587,7 @@ int cap_inode_setxattr(struct dentry *de
26604  
26605         if (!strncmp(name, XATTR_SECURITY_PREFIX,
26606                      sizeof(XATTR_SECURITY_PREFIX) - 1) &&
26607 -           !capable(CAP_SYS_ADMIN))
26608 +               !vx_capable(CAP_SYS_ADMIN, VXC_FS_SECURITY))
26609                 return -EPERM;
26610         return 0;
26611  }
26612 @@ -596,7 +613,7 @@ int cap_inode_removexattr(struct dentry 
26613  
26614         if (!strncmp(name, XATTR_SECURITY_PREFIX,
26615                      sizeof(XATTR_SECURITY_PREFIX) - 1) &&
26616 -           !capable(CAP_SYS_ADMIN))
26617 +               !vx_capable(CAP_SYS_ADMIN, VXC_FS_SECURITY))
26618                 return -EPERM;
26619         return 0;
26620  }
26621 @@ -929,3 +946,4 @@ int cap_file_mmap(struct file *file, uns
26622         }
26623         return ret;
26624  }
26625 +
26626 diff -NurpP --minimal linux-2.6.38.3/security/selinux/hooks.c linux-2.6.38.3-vs2.3.0.37-rc14/security/selinux/hooks.c
26627 --- linux-2.6.38.3/security/selinux/hooks.c     2011-03-15 18:07:47.000000000 +0100
26628 +++ linux-2.6.38.3-vs2.3.0.37-rc14/security/selinux/hooks.c     2011-02-17 02:17:52.000000000 +0100
26629 @@ -64,7 +64,6 @@
26630  #include <linux/dccp.h>
26631  #include <linux/quota.h>
26632  #include <linux/un.h>          /* for Unix socket types */
26633 -#include <net/af_unix.h>       /* for Unix socket types */
26634  #include <linux/parser.h>
26635  #include <linux/nfs_mount.h>
26636  #include <net/ipv6.h>
This page took 2.032773 seconds and 4 git commands to generate.